Pārlūkot izejas kodu

return endpoints with createsessionrequest. conformance tests are running now!

Julius Pfrommer 10 gadi atpakaļ
vecāks
revīzija
5b2e1c5319

+ 3 - 3
examples/opcuaServer.c

@@ -54,10 +54,10 @@ int main(int argc, char** argv) {
 
 	UA_Server server;
 	UA_String endpointUrl;
-	UA_String_copycstring("no endpoint url",&endpointUrl);
-	UA_Server_init(&server, &endpointUrl);
+	UA_String_copycstring("opc.tcp://192.168.56.101:16664",&endpointUrl);
+    UA_ByteString certificate = loadCertificate();
+	UA_Server_init(&server, &endpointUrl, &certificate);
 	Logger_Stdout_init(&server.logger);
-    server.serverCertificate = loadCertificate();
 
     UA_Int32 myInteger = 42;
     UA_String myIntegerName;

+ 5 - 2
include/ua_server.h

@@ -42,18 +42,21 @@ typedef struct UA_NodeStore UA_NodeStore;
 
 typedef struct UA_Server {
     UA_ApplicationDescription description;
+    UA_Int32 endpointDescriptionsSize;
+    UA_EndpointDescription *endpointDescriptions;
+    UA_ByteString serverCertificate;
+    
     UA_SecureChannelManager *secureChannelManager;
     UA_SessionManager *sessionManager;
     UA_NodeStore *nodestore;
     UA_Logger logger;
-    UA_ByteString serverCertificate;
 
     // todo: move these somewhere sane
     UA_ExpandedNodeId objectsNodeId;
     UA_NodeId hasComponentReferenceTypeId;
 } UA_Server;
 
-void UA_EXPORT UA_Server_init(UA_Server *server, UA_String *endpointUrl);
+void UA_EXPORT UA_Server_init(UA_Server *server, UA_String *endpointUrl, UA_ByteString *serverCertificate);
 UA_StatusCode UA_EXPORT UA_Server_deleteMembers(UA_Server *server);
 void UA_EXPORT UA_Server_processBinaryMessage(UA_Server *server, UA_Connection *connection, const UA_ByteString *msg);
 

+ 32 - 3
src/server/ua_server.c

@@ -15,15 +15,46 @@ UA_StatusCode UA_Server_deleteMembers(UA_Server *server) {
     return UA_STATUSCODE_GOOD;
 }
 
-void UA_Server_init(UA_Server *server, UA_String *endpointUrl) {
+void UA_Server_init(UA_Server *server, UA_String *endpointUrl, UA_ByteString *serverCertificate) {
     UA_ExpandedNodeId_init(&server->objectsNodeId);
     server->objectsNodeId.nodeId.identifier.numeric = 85;
 
     UA_NodeId_init(&server->hasComponentReferenceTypeId);
     server->hasComponentReferenceTypeId.identifier.numeric = 47;
     
+    // mockup application description
     UA_ApplicationDescription_init(&server->description);
+    UA_String_copycstring("urn:servername:open62541:application", &server->description.productUri);
+    UA_String_copycstring("http://open62541.info/applications/4711", &server->description.applicationUri);
+    UA_LocalizedText_copycstring("The open62541 application", &server->description.applicationName);
+    server->description.applicationType = UA_APPLICATIONTYPE_SERVER;
+
     UA_ByteString_init(&server->serverCertificate);
+    if(serverCertificate)
+        UA_ByteString_copy(serverCertificate, &server->serverCertificate);
+
+    // mockup endpoint description
+    server->endpointDescriptionsSize = 1;
+    UA_EndpointDescription *endpoint = UA_alloc(sizeof(UA_EndpointDescription)); // todo: check return code
+
+    endpoint->securityMode = UA_MESSAGESECURITYMODE_NONE;
+    UA_String_copycstring("http://opcfoundation.org/UA/SecurityPolicy#None", &endpoint->securityPolicyUri);
+    UA_String_copycstring("http://opcfoundation.org/UA-Profile/Transport/uatcp-uasc-uabinary", &endpoint->transportProfileUri);
+
+    endpoint->userIdentityTokensSize = 1;
+    endpoint->userIdentityTokens = UA_alloc(sizeof(UA_UserTokenPolicy));
+    UA_UserTokenPolicy_init(endpoint->userIdentityTokens);
+    UA_String_copycstring("my-anonymous-policy", &endpoint->userIdentityTokens->policyId); // defined per server
+    endpoint->userIdentityTokens->tokenType = UA_USERTOKENTYPE_ANONYMOUS;
+
+    UA_String_copy(endpointUrl, &endpoint->endpointUrl);
+    /* The standard says "the HostName specified in the Server Certificate is the
+       same as the HostName contained in the endpointUrl provided in the
+       EndpointDescription */
+    UA_String_copy(&server->serverCertificate, &endpoint->serverCertificate);
+    UA_ApplicationDescription_copy(&server->description, &endpoint->server);
+    server->endpointDescriptions = endpoint;
+
 #define MAXCHANNELCOUNT 100
 #define STARTCHANNELID 1
 #define TOKENLIFETIME 10000
@@ -38,8 +69,6 @@ void UA_Server_init(UA_Server *server, UA_String *endpointUrl) {
                           STARTSESSIONID);
 
     UA_NodeStore_new(&server->nodestore);
-    //ns0: C2UA_STRING("http://opcfoundation.org/UA/"));
-    //ns1: C2UA_STRING("http://localhost:16664/open62541/"));
 
     /**************/
     /* References */

+ 10 - 31
src/server/ua_services_discovery.c

@@ -1,40 +1,19 @@
 #include "ua_services.h"
 #include "ua_namespace_0.h"
+#include "ua_util.h"
 
 void Service_GetEndpoints(UA_Server                    *server,
                           const UA_GetEndpointsRequest *request,
                           UA_GetEndpointsResponse      *response) {
     UA_GetEndpointsResponse_init(response);
     response->endpointsSize = 1;
-    UA_Array_new((void **)&response->endpoints, response->endpointsSize, &UA_[UA_ENDPOINTDESCRIPTION]);
-
-    // security policy
-    response->endpoints[0].securityMode = UA_MESSAGESECURITYMODE_NONE;
-    UA_String_copycstring("http://opcfoundation.org/UA/SecurityPolicy#None",
-                          &response->endpoints[0].securityPolicyUri);
-    UA_String_copycstring("http://opcfoundation.org/UA-Profile/Transport/uatcp-uasc-uabinary",
-                          &response->endpoints[0].transportProfileUri);
-
-    // usertoken policy
-    response->endpoints[0].userIdentityTokensSize = 1;
-    UA_Array_new((void **)&response->endpoints[0].userIdentityTokens,
-                 response->endpoints[0].userIdentityTokensSize, &UA_[UA_USERTOKENPOLICY]);
-    UA_UserTokenPolicy *token = &response->endpoints[0].userIdentityTokens[0];
-    UA_UserTokenPolicy_init(token);
-    UA_String_copycstring("my-anonymous-policy", &token->policyId); // defined per server
-    token->tokenType         = UA_USERTOKENTYPE_ANONYMOUS;
-
-    // server description
-    UA_String_copy(&request->endpointUrl, &response->endpoints[0].endpointUrl);
-    /* The standard says "the HostName specified in the Server Certificate is the
-       same as the HostName contained in the endpointUrl provided in the
-       EndpointDescription */
-    UA_String_copy(&server->serverCertificate, &response->endpoints[0].serverCertificate);
-    UA_String_copycstring("http://open62541.info/product/release", &(response->endpoints[0].server.productUri));
-    // FIXME: This information should be provided by the application, preferably in the address space
-    UA_String_copycstring("http://open62541.info/applications/4711",
-                          &(response->endpoints[0].server.applicationUri));
-    UA_LocalizedText_copycstring("The open62541 application", &(response->endpoints[0].server.applicationName));
-    // FIXME: This should be a feature of the application and an enum
-    response->endpoints[0].server.applicationType = UA_APPLICATIONTYPE_SERVER;
+    response->endpoints = UA_alloc(sizeof(UA_EndpointDescription));
+    if(!response->endpoints) {
+        response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
+        return;
+    }
+    if(UA_EndpointDescription_copy(server->endpointDescriptions, response->endpoints) != UA_STATUSCODE_GOOD) {
+        UA_free(response->endpoints);
+        response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
+    }
 }

+ 6 - 1
src/server/ua_services_session.c

@@ -22,7 +22,12 @@ void Service_CreateSession(UA_Server *server, UA_SecureChannel *channel,
     response->sessionId = newSession->sessionId;
     response->revisedSessionTimeout = newSession->timeout;
     response->authenticationToken = newSession->authenticationToken;
-    //channel->session = newSession;
+    UA_ByteString_copy(&server->serverCertificate, &response->serverCertificate);
+
+    response->serverEndpointsSize = 1;
+    response->serverEndpoints = UA_alloc(sizeof(UA_EndpointDescription));
+    UA_EndpointDescription_copy(server->endpointDescriptions, response->serverEndpoints);
+    
 }
 
 void Service_ActivateSession(UA_Server *server,UA_SecureChannel *channel,