Browse Source

Discovery Get Endpoints tests work now

Stasik0 8 years ago
parent
commit
46c2be5d5e

+ 1 - 1
plugins/ua_config_standard.c

@@ -28,7 +28,7 @@ const UA_ServerConfig UA_ServerConfig_standard = {
     .applicationDescription = {
         .applicationUri = UA_STRING_STATIC(APPLICATION_URI),
         .productUri = UA_STRING_STATIC(PRODUCT_URI),
-        .applicationName = { .locale = UA_STRING_STATIC(""),
+        .applicationName = { .locale = UA_STRING_STATIC("en"),
                              .text = UA_STRING_STATIC(APPLICATION_NAME) },
         .applicationType = UA_APPLICATIONTYPE_SERVER,
         .gatewayServerUri = UA_STRING_STATIC_NULL,

+ 9 - 6
src/server/ua_server_binary.c

@@ -434,12 +434,15 @@ processRequest(UA_SecureChannel *channel, UA_Server *server, UA_UInt32 requestId
     /* Test if the session is valid */
     UA_Session anonymousSession;
     if(!session) {
-        if(sessionRequired || !UA_NodeId_equal(&requestHeader->authenticationToken, &UA_NODEID_NULL)) {
-            UA_LOG_INFO_CHANNEL(server->config.logger, channel, "Service request %i without a valid session",
-                                requestTypeId.identifier.numeric - UA_ENCODINGOFFSET_BINARY);
-            sendError(channel, msg, requestPos, responseType, requestId, UA_STATUSCODE_BADSESSIONIDINVALID);
-            UA_deleteMembers(request, requestType);
-            return;
+        //allow calling getendpoint service with invalid authenticationToken
+        if(requestType != &UA_TYPES[UA_TYPES_GETENDPOINTSREQUEST]){
+            if(sessionRequired || !UA_NodeId_equal(&requestHeader->authenticationToken, &UA_NODEID_NULL)) {
+                UA_LOG_INFO_CHANNEL(server->config.logger, channel, "Service request %i without a valid session",
+                                    requestTypeId.identifier.numeric - UA_ENCODINGOFFSET_BINARY);
+                sendError(channel, msg, requestPos, responseType, requestId, UA_STATUSCODE_BADSESSIONIDINVALID);
+                UA_deleteMembers(request, requestType);
+                return;
+            }
         }
 
         /* Set an anonymous, inactive session for services that need no session */

+ 5 - 2
src/server/ua_services_discovery.c

@@ -99,8 +99,11 @@ void Service_GetEndpoints(UA_Server *server, UA_Session *session, const UA_GetEn
         retval = UA_EndpointDescription_copy(&server->endpointDescriptions[j], &response->endpoints[k]);
         if(retval != UA_STATUSCODE_GOOD)
             break;
-        UA_String_deleteMembers(&response->endpoints[k].endpointUrl);
-        retval = UA_String_copy(&request->endpointUrl, &response->endpoints[k].endpointUrl);
+        /* replace endpoint's URL to the requested one if provided */
+        if(request->endpointUrl.length > 0){
+            UA_String_deleteMembers(&response->endpoints[k].endpointUrl);
+            retval = UA_String_copy(&request->endpointUrl, &response->endpoints[k].endpointUrl);
+        }
         k++;
     }