Quellcode durchsuchen

implemented handling CloseSessionRequests, no error message by UaExpert anymore, relates to #129

Stasik0 vor 10 Jahren
Ursprung
Commit
3c58c6c04f
4 geänderte Dateien mit 38 neuen und 16 gelöschten Zeilen
  1. 4 0
      include/ua_server.h
  2. 16 6
      src/server/ua_server_binary.c
  3. 1 2
      src/server/ua_services.h
  4. 17 8
      src/server/ua_services_session.c

+ 4 - 0
include/ua_server.h

@@ -27,6 +27,10 @@ extern "C" {
 
 /** @defgroup server Server */
 
+//identifier numbers are different for XML and binary, so we have to substract an offset for comparison
+#define UA_ENCODINGOFFSET_XML 1
+#define UA_ENCODINGOFFSET_BINARY 2
+
 struct UA_SecureChannelManager;
 typedef struct UA_SecureChannelManager UA_SecureChannelManager;
 

+ 16 - 6
src/server/ua_server_binary.c

@@ -181,9 +181,9 @@ static void processMessage(UA_Connection *connection, UA_Server *server, const U
     UA_ByteString *header = &responseBufs[0];
     UA_ByteString *message = &responseBufs[1];
 
-    //subtract 2 for binary encoding
     UA_UInt32 sendOffset = 0;
-    switch(requestType.nodeId.identifier.numeric - 2) {
+    //subtract UA_ENCODINGOFFSET_BINARY for binary encoding
+    switch(requestType.nodeId.identifier.numeric - UA_ENCODINGOFFSET_BINARY) {
     case UA_GETENDPOINTSREQUEST_NS0: {
         UA_GetEndpointsRequest  p;
         UA_GetEndpointsResponse r;
@@ -230,12 +230,22 @@ static void processMessage(UA_Connection *connection, UA_Server *server, const U
     }
         break;
 
-    //FIXME: Sten handle closeseesionrequests
-    //being curious: our constant gives 471 while clients query for 473
-    /** case UA_CLOSESESSIONREQUEST_NS0: {
+    case UA_CLOSESESSIONREQUEST_NS0: {
+        UA_CloseSessionRequest  p;
+        UA_CloseSessionResponse r;
+        CHECK_PROCESS(UA_CloseSessionRequest_decodeBinary(msg, pos, &p),; );
+        UA_CloseSessionResponse_init(&r);
+        init_response_header(&p.requestHeader, &r.responseHeader);
+
+        Service_CloseSession(server, &p, &r);
+        UA_ByteString_newMembers(message, UA_CloseSessionResponse_calcSizeBinary(&r));
+        UA_CloseSessionResponse_encodeBinary(&r, message, &sendOffset);
+        UA_CloseSessionRequest_deleteMembers(&p);
+        UA_CloseSessionResponse_deleteMembers(&r);
+        responseType = requestType.nodeId.identifier.numeric + 3;
     }
     break;
-    **/
+
 
     case UA_READREQUEST_NS0:
         INVOKE_SERVICE(Read);

+ 1 - 2
src/server/ua_services.h

@@ -87,8 +87,7 @@ void Service_ActivateSession(UA_Server *server, UA_SecureChannel *channel,
 /**
  * @brief This Service is used to terminate a Session.
  */
-void Service_CloseSession(UA_Server *server, UA_Session *session,
-                          const UA_CloseSessionRequest *request, UA_CloseSessionResponse *response);
+void Service_CloseSession(UA_Server *server, const UA_CloseSessionRequest *request, UA_CloseSessionResponse *response);
 // Service_Cancel
 /** @} */
 

+ 17 - 8
src/server/ua_services_session.c

@@ -39,14 +39,23 @@ void Service_ActivateSession(UA_Server *server,UA_SecureChannel *channel,
         channel->session = foundSession;
 }
 
-void Service_CloseSession(UA_Server *server, UA_Session *session,
-                              const UA_CloseSessionRequest *request,
+void Service_CloseSession(UA_Server *server, const UA_CloseSessionRequest *request,
                               UA_CloseSessionResponse *response) {
-    session->channel->session = UA_NULL;
-    UA_SessionManager_removeSession(server->sessionManager, &session->sessionId);
-    /* UA_NodeId sessionId; */
-    /* UA_Session_getId(session,&sessionId); */
+	UA_Session *foundSession;
+	UA_SessionManager_getSessionByToken(server->sessionManager,
+			(UA_NodeId*)&request->requestHeader.authenticationToken,
+			&foundSession);
+
+	if(foundSession == UA_NULL){
+		response->responseHeader.serviceResult = UA_STATUSCODE_BADIDENTITYTOKENINVALID;
+		return;
+	}
+
 
-    /* UA_SessionManager_removeSession(&sessionId); */
-    // FIXME: set response
+	if(UA_SessionManager_removeSession(server->sessionManager, &foundSession->sessionId) == UA_SUCCESS){
+		response->responseHeader.serviceResult = UA_STATUSCODE_GOOD;
+	}else{
+		//FIXME: this is probably not the correct statuscode -> look up in the standard
+		response->responseHeader.serviceResult = UA_STATUSCODE_BADIDENTITYTOKENINVALID;
+	}
 }