diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b9363721d2..dd7135a0109 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -256,6 +256,7 @@ set(exported_headers ${PROJECT_BINARY_DIR}/src_generated/ua_config.h ${PROJECT_SOURCE_DIR}/include/ua_plugin_network.h ${PROJECT_SOURCE_DIR}/include/ua_plugin_log.h ${PROJECT_SOURCE_DIR}/include/ua_plugin_access_control.h + ${PROJECT_SOURCE_DIR}/include/ua_plugin_securitypolicy.h ${PROJECT_SOURCE_DIR}/include/ua_server.h ${PROJECT_SOURCE_DIR}/include/ua_client.h ${PROJECT_SOURCE_DIR}/include/ua_client_highlevel.h @@ -328,7 +329,6 @@ set(lib_sources ${PROJECT_SOURCE_DIR}/src/ua_types.c ${PROJECT_SOURCE_DIR}/src/client/ua_client_discovery.c ${PROJECT_SOURCE_DIR}/src/client/ua_client_highlevel.c ${PROJECT_SOURCE_DIR}/src/client/ua_client_highlevel_subscriptions.c - # dependencies ${PROJECT_SOURCE_DIR}/deps/libc_time.c ${PROJECT_SOURCE_DIR}/deps/pcg_basic.c) @@ -338,6 +338,7 @@ set(default_plugin_sources ${PROJECT_SOURCE_DIR}/plugins/ua_network_tcp.c ${PROJECT_SOURCE_DIR}/plugins/ua_log_stdout.c ${PROJECT_SOURCE_DIR}/plugins/ua_accesscontrol_default.c ${PROJECT_SOURCE_DIR}/plugins/ua_config_standard.c) + if(UA_DEBUG_DUMP_PKGS) list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/plugins/ua_debug_dump_pkgs.c) endif() @@ -677,5 +678,5 @@ set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "_CmakePredifinedTargets" set_target_properties(open62541 PROPERTIES FOLDER "open62541/lib") set_target_properties(open62541-object PROPERTIES FOLDER "open62541/lib") set_target_properties(lint PROPERTIES FOLDER "CodeAnalysis") -set_target_properties(open62541_amalgamation_header PROPERTIES FOLDER "open62541/lib") -set_target_properties(open62541_amalgamation_source PROPERTIES FOLDER "open62541/lib") +set_target_properties(open62541-amalgamation-header PROPERTIES FOLDER "open62541/lib") +set_target_properties(open62541-amalgamation-source PROPERTIES FOLDER "open62541/lib") diff --git a/README.md b/README.md index c94e81d59d0..fa4eae3b479 100644 --- a/README.md +++ b/README.md @@ -81,11 +81,8 @@ int main(int argc, char** argv) { signal(SIGINT, signalHandler); /* catch ctrl-c */ - /* Create a server with one network layer listening on port 4840 */ - UA_ServerConfig config = UA_ServerConfig_standard; - UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 4840); - config.networkLayers = &nl; - config.networkLayersSize = 1; + /* Create a server listening on port 4840 */ + UA_ServerConfig *config = UA_ServerConfig_new_default(); UA_Server *server = UA_Server_new(config); /* Add a variable node */ @@ -109,7 +106,7 @@ int main(int argc, char** argv) /* Run the server loop */ UA_StatusCode status = UA_Server_run(server, &running); UA_Server_delete(server); - nl.deleteMembers(&nl); + UA_ServerConfig_delete(config); return status; } ``` @@ -122,7 +119,7 @@ int main(int argc, char** argv) int main(int argc, char *argv[]) { /* Create a client and connect */ - UA_Client *client = UA_Client_new(UA_ClientConfig_standard); + UA_Client *client = UA_Client_new(UA_ClientConfig_default); UA_StatusCode status = UA_Client_connect(client, "opc.tcp://localhost:4840"); if(status != UA_STATUSCODE_GOOD) { UA_Client_delete(client); diff --git a/examples/client.c b/examples/client.c index c7ab9fe5cea..235846fa896 100644 --- a/examples/client.c +++ b/examples/client.c @@ -24,12 +24,12 @@ nodeIter(UA_NodeId childId, UA_Boolean isInverse, UA_NodeId referenceTypeId, voi } int main(int argc, char *argv[]) { - UA_Client *client = UA_Client_new(UA_ClientConfig_standard); + UA_Client *client = UA_Client_new(UA_ClientConfig_default); /* Listing endpoints */ UA_EndpointDescription* endpointArray = NULL; size_t endpointArraySize = 0; - UA_StatusCode retval = UA_Client_getEndpoints(client, "opc.tcp://localhost:16664", + UA_StatusCode retval = UA_Client_getEndpoints(client, "opc.tcp://localhost:4840", &endpointArraySize, &endpointArray); if(retval != UA_STATUSCODE_GOOD) { UA_Array_delete(endpointArray, endpointArraySize, &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]); @@ -45,8 +45,8 @@ int main(int argc, char *argv[]) { UA_Array_delete(endpointArray,endpointArraySize, &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]); /* Connect to a server */ - /* anonymous connect would be: retval = UA_Client_connect(client, "opc.tcp://localhost:16664"); */ - retval = UA_Client_connect_username(client, "opc.tcp://localhost:16664", "user1", "password"); + /* anonymous connect would be: retval = UA_Client_connect(client, "opc.tcp://localhost:4840"); */ + retval = UA_Client_connect_username(client, "opc.tcp://localhost:4840", "user1", "password"); if(retval != UA_STATUSCODE_GOOD) { UA_Client_delete(client); return (int)retval; @@ -94,7 +94,7 @@ int main(int argc, char *argv[]) { #ifdef UA_ENABLE_SUBSCRIPTIONS /* Create a subscription */ UA_UInt32 subId = 0; - UA_Client_Subscriptions_new(client, UA_SubscriptionSettings_standard, &subId); + UA_Client_Subscriptions_new(client, UA_SubscriptionSettings_default, &subId); if(subId) printf("Create subscription succeeded, id %u\n", subId); /* Add a MonitoredItem */ diff --git a/examples/discovery/client_find_servers.c b/examples/discovery/client_find_servers.c index 7ef2919c6fe..3feba09d752 100644 --- a/examples/discovery/client_find_servers.c +++ b/examples/discovery/client_find_servers.c @@ -23,11 +23,13 @@ int main(void) { UA_ServerOnNetwork *serverOnNetwork = NULL; size_t serverOnNetworkSize = 0; - UA_Client *client = UA_Client_new(UA_ClientConfig_standard); + UA_Client *client = UA_Client_new(UA_ClientConfig_default); UA_StatusCode retval = UA_Client_findServersOnNetwork(client, DISCOVERY_SERVER_ENDPOINT, 0, 0, 0, NULL, &serverOnNetworkSize, &serverOnNetwork); if (retval != UA_STATUSCODE_GOOD) { - UA_LOG_ERROR(logger, UA_LOGCATEGORY_SERVER, "Could not call FindServersOnNetwork service. Is the discovery server started? StatusCode %s", + UA_LOG_ERROR(logger, UA_LOGCATEGORY_SERVER, + "Could not call FindServersOnNetwork service. " + "Is the discovery server started? StatusCode %s", UA_StatusCode_name(retval)); UA_Client_delete(client); return (int) retval; @@ -36,30 +38,30 @@ int main(void) { // output all the returned/registered servers for (size_t i = 0; i < serverOnNetworkSize; i++) { UA_ServerOnNetwork *server = &serverOnNetwork[i]; - printf("Server[%lu]: %.*s", (unsigned long) i, (int) server->serverName.length, server->serverName.data); + printf("Server[%lu]: %.*s", (unsigned long) i, + (int) server->serverName.length, server->serverName.data); printf("\n\tRecordID: %d", server->recordId); - printf("\n\tDiscovery URL: %.*s", (int) server->discoveryUrl.length, server->discoveryUrl.data); + printf("\n\tDiscovery URL: %.*s", (int) server->discoveryUrl.length, + server->discoveryUrl.data); printf("\n\tCapabilities: "); for (size_t j = 0; j < server->serverCapabilitiesSize; j++) { - printf("%.*s,", (int) server->serverCapabilities[j].length, server->serverCapabilities[j].data); + printf("%.*s,", (int) server->serverCapabilities[j].length, + server->serverCapabilities[j].data); } printf("\n\n"); } - UA_Array_delete(serverOnNetwork, serverOnNetworkSize, &UA_TYPES[UA_TYPES_SERVERONNETWORK]); + UA_Array_delete(serverOnNetwork, serverOnNetworkSize, + &UA_TYPES[UA_TYPES_SERVERONNETWORK]); } - /* - * Example for calling FindServers - */ - - + /* Example for calling FindServers */ UA_ApplicationDescription *applicationDescriptionArray = NULL; size_t applicationDescriptionArraySize = 0; UA_StatusCode retval; { - UA_Client *client = UA_Client_new(UA_ClientConfig_standard); + UA_Client *client = UA_Client_new(UA_ClientConfig_default); retval = UA_Client_findServers(client, DISCOVERY_SERVER_ENDPOINT, 0, NULL, 0, NULL, &applicationDescriptionArraySize, &applicationDescriptionArray); UA_Client_delete(client); @@ -126,7 +128,7 @@ int main(void) { printf("\nEndpoints for Server[%lu]: %.*s\n", (unsigned long) i, (int) description->applicationUri.length, description->applicationUri.data); - UA_Client *client = UA_Client_new(UA_ClientConfig_standard); + UA_Client *client = UA_Client_new(UA_ClientConfig_default); char *discoveryUrl = (char *) UA_malloc(sizeof(char) * description->discoveryUrls[0].length + 1); memcpy(discoveryUrl, description->discoveryUrls[0].data, description->discoveryUrls[0].length); diff --git a/examples/discovery/server_lds.c b/examples/discovery/server_lds.c index 96fbc55b75f..c7552c5658a 100644 --- a/examples/discovery/server_lds.c +++ b/examples/discovery/server_lds.c @@ -19,16 +19,17 @@ int main(void) { signal(SIGINT, stopHandler); signal(SIGTERM, stopHandler); - UA_ServerConfig config = UA_ServerConfig_standard; - config.applicationDescription.applicationType = UA_APPLICATIONTYPE_DISCOVERYSERVER; - config.applicationDescription.applicationUri = + UA_ServerConfig *config = UA_ServerConfig_new_default(); + config->applicationDescription.applicationType = UA_APPLICATIONTYPE_DISCOVERYSERVER; + UA_String_deleteMembers(&config->applicationDescription.applicationUri); + config->applicationDescription.applicationUri = UA_String_fromChars("urn:open62541.example.local_discovery_server"); - config.mdnsServerName = UA_String_fromChars("LDS"); + config->mdnsServerName = UA_String_fromChars("LDS"); // See http://www.opcfoundation.org/UA/schemas/1.03/ServerCapabilities.csv - config.serverCapabilitiesSize = 1; + config->serverCapabilitiesSize = 1; UA_String *caps = UA_String_new(); *caps = UA_String_fromChars("LDS"); - config.serverCapabilities = caps; + config->serverCapabilities = caps; /* timeout in seconds when to automatically remove a registered server from * the list, if it doesn't re-register within the given time frame. A value * of 0 disables automatic removal. Default is 60 Minutes (60*60). Must be @@ -36,16 +37,10 @@ int main(void) { * ervery 10 seconds. The server will still be removed depending on the * state of the semaphore file. */ // config.discoveryCleanupTimeout = 60*60; - UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 4840); - config.networkLayers = &nl; - config.networkLayersSize = 1; UA_Server *server = UA_Server_new(config); UA_StatusCode retval = UA_Server_run(server, &running); - UA_String_deleteMembers(&config.applicationDescription.applicationUri); - UA_Array_delete(config.serverCapabilities, config.serverCapabilitiesSize, &UA_TYPES[UA_TYPES_STRING]); - UA_String_deleteMembers(&config.mdnsServerName); UA_Server_delete(server); - nl.deleteMembers(&nl); - return (int) retval; + UA_ServerConfig_delete(config); + return (int)retval; } diff --git a/examples/discovery/server_multicast.c b/examples/discovery/server_multicast.c index a8eb51fbb49..132bac23927 100644 --- a/examples/discovery/server_multicast.c +++ b/examples/discovery/server_multicast.c @@ -86,21 +86,19 @@ int main(int argc, char **argv) { signal(SIGINT, stopHandler); /* catches ctrl-c */ signal(SIGTERM, stopHandler); - UA_ServerConfig config = UA_ServerConfig_standard; + UA_ServerConfig *config = UA_ServerConfig_new_default(); // To enable mDNS discovery, set application type to discovery server. - config.applicationDescription.applicationType = UA_APPLICATIONTYPE_DISCOVERYSERVER; - config.applicationDescription.applicationUri = + config->applicationDescription.applicationType = UA_APPLICATIONTYPE_DISCOVERYSERVER; + UA_String_deleteMembers(&config->applicationDescription.applicationUri); + config->applicationDescription.applicationUri = UA_String_fromChars("urn:open62541.example.server_multicast"); - config.mdnsServerName = UA_String_fromChars("Sample Multicast Server"); + config->mdnsServerName = UA_String_fromChars("Sample Multicast Server"); // See http://www.opcfoundation.org/UA/schemas/1.03/ServerCapabilities.csv //config.serverCapabilitiesSize = 1; //UA_String caps = UA_String_fromChars("LDS"); //config.serverCapabilities = ∩︀ - UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16665); - config.networkLayers = &nl; - config.networkLayersSize = 1; UA_Server *server = UA_Server_new(config); - self_discovery_url = &nl.discoveryUrl; + self_discovery_url = &config->networkLayers[0].discoveryUrl; /* add a variable node to the address space */ UA_Int32 myInteger = 42; @@ -129,9 +127,8 @@ int main(int argc, char **argv) { UA_LOG_ERROR(logger, UA_LOGCATEGORY_SERVER, "Could not start the server. StatusCode %s", UA_StatusCode_name(retval)); - UA_String_deleteMembers(&config.applicationDescription.applicationUri); UA_Server_delete(server); - nl.deleteMembers(&nl); + UA_ServerConfig_delete(config); UA_free(discovery_url); return 1; } @@ -140,9 +137,8 @@ int main(int argc, char **argv) { while (running && discovery_url == NULL) UA_Server_run_iterate(server, true); if (!running) { - UA_String_deleteMembers(&config.applicationDescription.applicationUri); UA_Server_delete(server); - nl.deleteMembers(&nl); + UA_ServerConfig_delete(config); UA_free(discovery_url); return 1; } @@ -155,10 +151,8 @@ int main(int argc, char **argv) { UA_LOG_ERROR(logger, UA_LOGCATEGORY_SERVER, "Could not create periodic job for server register. StatusCode %s", UA_StatusCode_name(retval)); - UA_String_deleteMembers(&config.applicationDescription.applicationUri); UA_Server_delete(server); - nl.deleteMembers(&nl); - UA_free(discovery_url); + UA_ServerConfig_delete(config); return 1; } @@ -170,23 +164,13 @@ int main(int argc, char **argv) { // UNregister the server from the discovery server. retval = UA_Server_unregister_discovery(server, discovery_url); //retval = UA_Server_unregister_discovery(server, "opc.tcp://localhost:4840" ); - if (retval != UA_STATUSCODE_GOOD) { + if(retval != UA_STATUSCODE_GOOD) UA_LOG_ERROR(logger, UA_LOGCATEGORY_SERVER, "Could not unregister server from discovery server. " "StatusCode %s", UA_StatusCode_name(retval)); - UA_String_deleteMembers(&config.applicationDescription.applicationUri); - UA_Server_delete(server); - nl.deleteMembers(&nl); - UA_free(discovery_url); - return (int) retval; - } - UA_String_deleteMembers(&config.applicationDescription.applicationUri); - UA_String_deleteMembers(&config.mdnsServerName); - //UA_Array_delete(config.serverCapabilities, config.serverCapabilitiesSize, &UA_TYPES[UA_TYPES_STRING]); UA_Server_delete(server); - nl.deleteMembers(&nl); + UA_ServerConfig_delete(config); UA_free(discovery_url); - - return (int) retval; + return (int)retval; } diff --git a/examples/discovery/server_register.c b/examples/discovery/server_register.c index 210246ccc2b..7017a83ad77 100644 --- a/examples/discovery/server_register.c +++ b/examples/discovery/server_register.c @@ -50,16 +50,16 @@ int main(int argc, char **argv) { signal(SIGINT, stopHandler); /* catches ctrl-c */ signal(SIGTERM, stopHandler); - UA_ServerConfig config = UA_ServerConfig_standard; - config.applicationDescription.applicationUri = UA_String_fromChars("urn:open62541.example.server_register"); - config.mdnsServerName = UA_String_fromChars("Sample Server"); + UA_ServerConfig *config = UA_ServerConfig_new_default(); + UA_String_deleteMembers(&config->applicationDescription.applicationUri); + config->applicationDescription.applicationUri = + UA_String_fromChars("urn:open62541.example.server_register"); + config->mdnsServerName = UA_String_fromChars("Sample Server"); // See http://www.opcfoundation.org/UA/schemas/1.03/ServerCapabilities.csv //config.serverCapabilitiesSize = 1; //UA_String caps = UA_String_fromChars("LDS"); //config.serverCapabilities = ∩︀ - UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664); - config.networkLayers = &nl; - config.networkLayersSize = 1; + UA_Server *server = UA_Server_new(config); /* add a variable node to the address space */ @@ -91,10 +91,9 @@ int main(int argc, char **argv) { UA_LOG_ERROR(logger, UA_LOGCATEGORY_SERVER, "Could not create periodic job for server register. StatusCode %s", UA_StatusCode_name(retval)); - UA_String_deleteMembers(&config.applicationDescription.applicationUri); UA_Server_delete(server); - nl.deleteMembers(&nl); - return (int) retval; + UA_ServerConfig_delete(config); + return (int)retval; } retval = UA_Server_run(server, &running); @@ -102,30 +101,20 @@ int main(int argc, char **argv) { UA_LOG_ERROR(logger, UA_LOGCATEGORY_SERVER, "Could not start the server. StatusCode %s", UA_StatusCode_name(retval)); - UA_String_deleteMembers(&config.applicationDescription.applicationUri); UA_Server_delete(server); - nl.deleteMembers(&nl); - return (int) retval; + UA_ServerConfig_delete(config); + return (int)retval; } // UNregister the server from the discovery server. retval = UA_Server_unregister_discovery(server, DISCOVERY_SERVER_ENDPOINT); //retval = UA_Server_unregister_discovery(server, "opc.tcp://localhost:4840" ); - if (retval != UA_STATUSCODE_GOOD) { + if(retval != UA_STATUSCODE_GOOD) UA_LOG_ERROR(logger, UA_LOGCATEGORY_SERVER, "Could not unregister server from discovery server. StatusCode %s", UA_StatusCode_name(retval)); - UA_String_deleteMembers(&config.applicationDescription.applicationUri); - UA_Server_delete(server); - nl.deleteMembers(&nl); - return (int) retval; - } - UA_String_deleteMembers(&config.applicationDescription.applicationUri); - UA_String_deleteMembers(&config.mdnsServerName); - //UA_Array_delete(config.serverCapabilities, config.serverCapabilitiesSize, &UA_TYPES[UA_TYPES_STRING]); UA_Server_delete(server); - nl.deleteMembers(&nl); - - return (int) retval; + UA_ServerConfig_delete(config); + return (int)retval; } diff --git a/examples/server.c b/examples/server.c index f85ec0a10be..67fc7b476c0 100644 --- a/examples/server.c +++ b/examples/server.c @@ -107,14 +107,10 @@ outargMethod(void *methodHandle, const UA_NodeId *objectId, int main(int argc, char** argv) { signal(SIGINT, stopHandler); /* catches ctrl-c */ - UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664); - UA_ServerConfig config = UA_ServerConfig_standard; - config.networkLayers = &nl; - config.networkLayersSize = 1; - - /* load certificate */ - config.serverCertificate = loadCertificate(); - + UA_ByteString certificate = loadCertificate(); + UA_ServerConfig *config = + UA_ServerConfig_new_minimal(4840, &certificate); + UA_ByteString_deleteMembers(&certificate); UA_Server *server = UA_Server_new(config); /* add a static variable node to the server */ @@ -391,12 +387,8 @@ int main(int argc, char** argv) { #endif /* run server */ - UA_StatusCode retval = UA_Server_run(server, &running); /* run until ctrl-c is received */ - - /* deallocate certificate's memory */ - UA_ByteString_deleteMembers(&config.serverCertificate); - + UA_StatusCode retval = UA_Server_run(server, &running); UA_Server_delete(server); - nl.deleteMembers(&nl); + UA_ServerConfig_delete(config); return (int)retval; } diff --git a/examples/server.cpp b/examples/server.cpp index c5ccefdcb26..cbf48f6c788 100644 --- a/examples/server.cpp +++ b/examples/server.cpp @@ -21,12 +21,10 @@ static void stopHandler(int sign) { } int main() { - signal(SIGINT, stopHandler); /* catches ctrl-c */ + signal(SIGINT, stopHandler); + signal(SIGTERM, stopHandler); - UA_ServerConfig config = UA_ServerConfig_standard; - UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664); - config.networkLayers = &nl; - config.networkLayersSize = 1; + UA_ServerConfig *config = UA_ServerConfig_new_default(); UA_Server *server = UA_Server_new(config); // add a variable node to the adresspace @@ -51,7 +49,6 @@ int main() { UA_StatusCode retval = UA_Server_run(server, &running); UA_Server_delete(server); - nl.deleteMembers(&nl); - + UA_ServerConfig_delete(config); return retval; } diff --git a/examples/server_inheritance.c b/examples/server_inheritance.c index 5a540fb5040..b641fd3510a 100644 --- a/examples/server_inheritance.c +++ b/examples/server_inheritance.c @@ -13,13 +13,9 @@ int main(void) { signal(SIGINT, stopHandler); signal(SIGTERM, stopHandler); - UA_ServerConfig config = UA_ServerConfig_standard; - UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664); - config.networkLayers = &nl; - config.networkLayersSize = 1; + UA_ServerConfig *config = UA_ServerConfig_new_default(); UA_Server *server = UA_Server_new(config); - /* Create a rudimentary objectType * * Type: @@ -43,7 +39,8 @@ int main(void) { otAttr.description = UA_LOCALIZEDTEXT("en_US", "A mamal"); otAttr.displayName = UA_LOCALIZEDTEXT("en_US", "MamalType"); UA_Server_addObjectTypeNode(server, UA_NODEID_NUMERIC(1, 10000), - UA_NODEID_NUMERIC(0, UA_NS0ID_BASEOBJECTTYPE), UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE), + UA_NODEID_NUMERIC(0, UA_NS0ID_BASEOBJECTTYPE), + UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE), UA_QUALIFIEDNAME(1, "MamalType"), otAttr, NULL, NULL); UA_VariableAttributes vAttr; @@ -51,17 +48,21 @@ int main(void) { vAttr.description = UA_LOCALIZEDTEXT("en_US", "This mamals class"); vAttr.displayName = UA_LOCALIZEDTEXT("en_US", "Class"); UA_String classVar = UA_STRING("mamalia"); - UA_Variant_setScalarCopy(&vAttr.value, &classVar, &UA_TYPES[UA_TYPES_STRING]); + UA_Variant_setScalar(&vAttr.value, &classVar, &UA_TYPES[UA_TYPES_STRING]); UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, 10001), - UA_NODEID_NUMERIC(1, 10000), UA_NODEID_NUMERIC(0, UA_NS0ID_HASPROPERTY), - UA_QUALIFIEDNAME(1, "Class"), UA_NODEID_NULL, vAttr, NULL, NULL); + UA_NODEID_NUMERIC(1, 10000), + UA_NODEID_NUMERIC(0, UA_NS0ID_HASPROPERTY), + UA_QUALIFIEDNAME(1, "Class"), UA_NODEID_NULL, + vAttr, NULL, NULL); UA_VariableAttributes_init(&vAttr); vAttr.description = UA_LOCALIZEDTEXT("en_US", "This mamals species"); vAttr.displayName = UA_LOCALIZEDTEXT("en_US", "Species"); UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, 10002), - UA_NODEID_NUMERIC(1, 10000), UA_NODEID_NUMERIC(0, UA_NS0ID_HASPROPERTY), - UA_QUALIFIEDNAME(1, "Species"), UA_NODEID_NULL, vAttr, NULL, NULL); + UA_NODEID_NUMERIC(1, 10000), + UA_NODEID_NUMERIC(0, UA_NS0ID_HASPROPERTY), + UA_QUALIFIEDNAME(1, "Species"), UA_NODEID_NULL, + vAttr, NULL, NULL); @@ -69,26 +70,31 @@ int main(void) { otAttr.description = UA_LOCALIZEDTEXT("en_US", "A dog, subtype of mamal"); otAttr.displayName = UA_LOCALIZEDTEXT("en_US", "DogType"); UA_Server_addObjectTypeNode(server, UA_NODEID_NUMERIC(1, 20000), - UA_NODEID_NUMERIC(1, 10000), UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE), + UA_NODEID_NUMERIC(1, 10000), + UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE), UA_QUALIFIEDNAME(1, "DogType"), otAttr, NULL, NULL); UA_VariableAttributes_init(&vAttr); vAttr.description = UA_LOCALIZEDTEXT("en_US", "This dogs species"); vAttr.displayName = UA_LOCALIZEDTEXT("en_US", "Species"); UA_String defaultSpecies = UA_STRING("Canis"); - UA_Variant_setScalarCopy(&vAttr.value, &defaultSpecies, &UA_TYPES[UA_TYPES_STRING]); + UA_Variant_setScalar(&vAttr.value, &defaultSpecies, &UA_TYPES[UA_TYPES_STRING]); UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, 20001), - UA_NODEID_NUMERIC(1, 20000), UA_NODEID_NUMERIC(0, UA_NS0ID_HASPROPERTY), - UA_QUALIFIEDNAME(1, "Species"), UA_NODEID_NULL, vAttr, NULL, NULL); + UA_NODEID_NUMERIC(1, 20000), + UA_NODEID_NUMERIC(0, UA_NS0ID_HASPROPERTY), + UA_QUALIFIEDNAME(1, "Species"), UA_NODEID_NULL, + vAttr, NULL, NULL); UA_VariableAttributes_init(&vAttr); vAttr.description = UA_LOCALIZEDTEXT("en_US", "This dogs name"); vAttr.displayName = UA_LOCALIZEDTEXT("en_US", "Name"); UA_String defaultName = UA_STRING("unnamed dog"); - UA_Variant_setScalarCopy(&vAttr.value, &defaultName, &UA_TYPES[UA_TYPES_STRING]); + UA_Variant_setScalar(&vAttr.value, &defaultName, &UA_TYPES[UA_TYPES_STRING]); UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, 20002), - UA_NODEID_NUMERIC(1, 20000), UA_NODEID_NUMERIC(0, UA_NS0ID_HASPROPERTY), - UA_QUALIFIEDNAME(1, "Name"), UA_NODEID_NULL, vAttr, NULL, NULL); + UA_NODEID_NUMERIC(1, 20000), + UA_NODEID_NUMERIC(0, UA_NS0ID_HASPROPERTY), + UA_QUALIFIEDNAME(1, "Name"), UA_NODEID_NULL, + vAttr, NULL, NULL); /* Instatiate a dog named bello: @@ -103,28 +109,32 @@ int main(void) { oAttr.description = UA_LOCALIZEDTEXT("en_US", "A dog named Bello"); oAttr.displayName = UA_LOCALIZEDTEXT("en_US", "Bello"); UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, 0), - UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER), UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT), - UA_QUALIFIEDNAME(1, "Bello"), UA_NODEID_NUMERIC(1, 20000), oAttr, NULL, NULL); - + UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER), + UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT), + UA_QUALIFIEDNAME(1, "Bello"), UA_NODEID_NUMERIC(1, 20000), + oAttr, NULL, NULL); UA_ObjectAttributes_init(&oAttr); oAttr.description = UA_LOCALIZEDTEXT("en_US", "Another dog"); oAttr.displayName = UA_LOCALIZEDTEXT("en_US", "Dog2"); UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, 0), - UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER), UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT), - UA_QUALIFIEDNAME(1, "Dog2"), UA_NODEID_NUMERIC(1, 20000), oAttr, NULL, NULL); - + UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER), + UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT), + UA_QUALIFIEDNAME(1, "Dog2"), UA_NODEID_NUMERIC(1, 20000), + oAttr, NULL, NULL); UA_ObjectAttributes_init(&oAttr); oAttr.description = UA_LOCALIZEDTEXT("en_US", "A mamal"); oAttr.displayName = UA_LOCALIZEDTEXT("en_US", "Mamal1"); UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, 0), - UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER), UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT), - UA_QUALIFIEDNAME(1, "Mamal1"), UA_NODEID_NUMERIC(1, 10000), oAttr, NULL, NULL); - + UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER), + UA_NODEID_NUMERIC(0, UA_NS0ID_HASCOMPONENT), + UA_QUALIFIEDNAME(1, "Mamal1"), UA_NODEID_NUMERIC(1, 10000), + oAttr, NULL, NULL); + /* Run the server */ retval = UA_Server_run(server, &running); UA_Server_delete(server); - nl.deleteMembers(&nl); + UA_ServerConfig_delete(config); return (int)retval; } diff --git a/examples/server_instantiation.c b/examples/server_instantiation.c index 09bad8bc9bb..56fc61ef0c1 100644 --- a/examples/server_instantiation.c +++ b/examples/server_instantiation.c @@ -13,10 +13,7 @@ int main(void) { signal(SIGINT, stopHandler); signal(SIGTERM, stopHandler); - UA_ServerConfig config = UA_ServerConfig_standard; - UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664); - config.networkLayers = &nl; - config.networkLayersSize = 1; + UA_ServerConfig *config = UA_ServerConfig_new_default(); UA_Server *server = UA_Server_new(config); /* Create a rudimentary objectType @@ -42,7 +39,7 @@ int main(void) { vAttr.description = UA_LOCALIZEDTEXT("en_US", "This mamals Age in months"); vAttr.displayName = UA_LOCALIZEDTEXT("en_US", "Age"); UA_UInt32 ageVar = 0; - UA_Variant_setScalarCopy(&vAttr.value, &ageVar, &UA_TYPES[UA_TYPES_UINT32]); + UA_Variant_setScalar(&vAttr.value, &ageVar, &UA_TYPES[UA_TYPES_UINT32]); UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, 10001), UA_NODEID_NUMERIC(1, 10000), UA_NODEID_NUMERIC(0, UA_NS0ID_HASPROPERTY), UA_QUALIFIEDNAME(1, "Age"), UA_NODEID_NULL, vAttr, NULL, NULL); @@ -58,7 +55,7 @@ int main(void) { vAttr.description = UA_LOCALIZEDTEXT("en_US", "This mamals Age in months"); vAttr.displayName = UA_LOCALIZEDTEXT("en_US", "Name"); UA_String defaultName = UA_STRING("unnamed dog"); - UA_Variant_setScalarCopy(&vAttr.value, &defaultName, &UA_TYPES[UA_TYPES_STRING]); + UA_Variant_setScalar(&vAttr.value, &defaultName, &UA_TYPES[UA_TYPES_STRING]); UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, 10003), UA_NODEID_NUMERIC(1, 10002), UA_NODEID_NUMERIC(0, UA_NS0ID_HASPROPERTY), UA_QUALIFIEDNAME(1, "Name"), UA_NODEID_NULL, vAttr, NULL, NULL); @@ -81,6 +78,6 @@ int main(void) { retval = UA_Server_run(server, &running); UA_Server_delete(server); - nl.deleteMembers(&nl); + UA_ServerConfig_delete(config); return (int)retval; } diff --git a/examples/server_mainloop.c b/examples/server_mainloop.c index 43752d33027..20634295272 100644 --- a/examples/server_mainloop.c +++ b/examples/server_mainloop.c @@ -21,12 +21,10 @@ static void stopHandler(int sign) { can be for example the event-loop used in GUI toolkits, such as Qt or GTK. */ int main(int argc, char** argv) { - signal(SIGINT, stopHandler); /* catches ctrl-c */ + signal(SIGINT, stopHandler); + signal(SIGTERM, stopHandler); - UA_ServerConfig config = UA_ServerConfig_standard; - UA_ServerNetworkLayer nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664); - config.networkLayers = &nl; - config.networkLayersSize = 1; + UA_ServerConfig *config = UA_ServerConfig_new_default(); UA_Server *server = UA_Server_new(config); /* Should the server networklayer block (with a timeout) until a message @@ -59,6 +57,6 @@ int main(int argc, char** argv) { cleanup: UA_Server_delete(server); - nl.deleteMembers(&nl); + UA_ServerConfig_delete(config); return (int)retval; } diff --git a/examples/server_repeated_job.c b/examples/server_repeated_job.c index 85121dc735f..56dd8f4da4c 100644 --- a/examples/server_repeated_job.c +++ b/examples/server_repeated_job.c @@ -19,18 +19,14 @@ int main(void) { signal(SIGINT, stopHandler); signal(SIGTERM, stopHandler); - UA_ServerConfig config = UA_ServerConfig_standard; - UA_ServerNetworkLayer nl = - UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664); - config.networkLayers = &nl; - config.networkLayersSize = 1; + UA_ServerConfig *config = UA_ServerConfig_new_default(); UA_Server *server = UA_Server_new(config); /* Add a repeated callback to the server */ UA_Server_addRepeatedCallback(server, testCallback, NULL, 2000, NULL); /* call every 2 sec */ - UA_Server_run(server, &running); + UA_StatusCode retval = UA_Server_run(server, &running); UA_Server_delete(server); - nl.deleteMembers(&nl); - return 0; + UA_ServerConfig_delete(config); + return (int)retval; } diff --git a/examples/tutorial_client_firststeps.c b/examples/tutorial_client_firststeps.c index bbe1ed84b75..a1e4f53b53f 100644 --- a/examples/tutorial_client_firststeps.c +++ b/examples/tutorial_client_firststeps.c @@ -12,7 +12,7 @@ #include "open62541.h" int main(void) { - UA_Client *client = UA_Client_new(UA_ClientConfig_standard); + UA_Client *client = UA_Client_new(UA_ClientConfig_default); UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:4840"); if(retval != UA_STATUSCODE_GOOD) { UA_Client_delete(client); diff --git a/examples/tutorial_server_datasource.c b/examples/tutorial_server_datasource.c index f1e85de8c81..810579b922d 100644 --- a/examples/tutorial_server_datasource.c +++ b/examples/tutorial_server_datasource.c @@ -157,21 +157,17 @@ int main(void) { signal(SIGINT, stopHandler); signal(SIGTERM, stopHandler); - UA_ServerConfig config = UA_ServerConfig_standard; - UA_ServerNetworkLayer nl = - UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664); - config.networkLayers = &nl; - config.networkLayersSize = 1; + UA_ServerConfig *config = UA_ServerConfig_new_default(); UA_Server *server = UA_Server_new(config); addCurrentTimeVariable(server); addValueCallbackToCurrentTimeVariable(server); addCurrentTimeDataSourceVariable(server); - UA_Server_run(server, &running); + UA_StatusCode retval = UA_Server_run(server, &running); UA_Server_delete(server); - nl.deleteMembers(&nl); - return 0; + UA_ServerConfig_delete(config); + return (int)retval; } /** diff --git a/examples/tutorial_server_firststeps.c b/examples/tutorial_server_firststeps.c index 288dfb616a3..afa64dbf7aa 100644 --- a/examples/tutorial_server_firststeps.c +++ b/examples/tutorial_server_firststeps.c @@ -33,18 +33,13 @@ int main(void) { signal(SIGINT, stopHandler); signal(SIGTERM, stopHandler); - UA_ServerConfig config = UA_ServerConfig_standard; - UA_ServerNetworkLayer nl = - UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 4840); - config.networkLayers = &nl; - config.networkLayersSize = 1; + UA_ServerConfig *config = UA_ServerConfig_new_default(); UA_Server *server = UA_Server_new(config); - UA_Server_run(server, &running); - + UA_StatusCode retval = UA_Server_run(server, &running); UA_Server_delete(server); - nl.deleteMembers(&nl); - return 0; + UA_ServerConfig_delete(config); + return (int)retval; } /** diff --git a/examples/tutorial_server_method.c b/examples/tutorial_server_method.c index f7ee85f975b..fd5f354acc5 100644 --- a/examples/tutorial_server_method.c +++ b/examples/tutorial_server_method.c @@ -67,8 +67,7 @@ addHellWorldMethod(UA_Server *server) { outputArgument.dataType = UA_TYPES[UA_TYPES_STRING].typeId; outputArgument.valueRank = -1; /* scalar */ - UA_MethodAttributes helloAttr; - UA_MethodAttributes_init(&helloAttr); + UA_MethodAttributes helloAttr = UA_MethodAttributes_default; helloAttr.description = UA_LOCALIZEDTEXT("en_US","Say `Hello World`"); helloAttr.displayName = UA_LOCALIZEDTEXT("en_US","Hello World"); helloAttr.executable = true; @@ -140,8 +139,7 @@ addIncInt32ArrayMethod(UA_Server *server) { outputArgument.arrayDimensions = &pOutputDimension; /* Add the method node */ - UA_MethodAttributes incAttr; - UA_MethodAttributes_init(&incAttr); + UA_MethodAttributes incAttr = UA_MethodAttributes_default; incAttr.description = UA_LOCALIZEDTEXT("en_US", "IncInt32ArrayValues"); incAttr.displayName = UA_LOCALIZEDTEXT("en_US", "IncInt32ArrayValues"); incAttr.executable = true; @@ -166,18 +164,14 @@ int main(void) { signal(SIGINT, stopHandler); signal(SIGTERM, stopHandler); - UA_ServerConfig config = UA_ServerConfig_standard; - UA_ServerNetworkLayer nl = - UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664); - config.networkLayers = &nl; - config.networkLayersSize = 1; + UA_ServerConfig *config = UA_ServerConfig_new_default(); UA_Server *server = UA_Server_new(config); addHellWorldMethod(server); addIncInt32ArrayMethod(server); - UA_Server_run(server, &running); + UA_StatusCode retval = UA_Server_run(server, &running); UA_Server_delete(server); - nl.deleteMembers(&nl); - return 0; + UA_ServerConfig_delete(config); + return (int)retval; } diff --git a/examples/tutorial_server_object.c b/examples/tutorial_server_object.c index e52a44cfd4c..dabbbfc62d8 100644 --- a/examples/tutorial_server_object.c +++ b/examples/tutorial_server_object.c @@ -314,11 +314,7 @@ int main(void) { signal(SIGINT, stopHandler); signal(SIGTERM, stopHandler); - UA_ServerConfig config = UA_ServerConfig_standard; - UA_ServerNetworkLayer nl = - UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664); - config.networkLayers = &nl; - config.networkLayersSize = 1; + UA_ServerConfig *config = UA_ServerConfig_new_default(); UA_Server *server = UA_Server_new(config); s = server; /* required for the constructor */ @@ -330,8 +326,8 @@ int main(void) { addPumpObjectInstance(server, "pump4"); addPumpObjectInstance(server, "pump5"); - UA_Server_run(server, &running); + UA_StatusCode retval = UA_Server_run(server, &running); UA_Server_delete(server); - nl.deleteMembers(&nl); - return 0; + UA_ServerConfig_delete(config); + return (int)retval; } diff --git a/examples/tutorial_server_variable.c b/examples/tutorial_server_variable.c index dd07dd90c44..d1476c0a817 100644 --- a/examples/tutorial_server_variable.c +++ b/examples/tutorial_server_variable.c @@ -102,19 +102,15 @@ int main(void) { signal(SIGINT, stopHandler); signal(SIGTERM, stopHandler); - UA_ServerConfig config = UA_ServerConfig_standard; - UA_ServerNetworkLayer nl = - UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664); - config.networkLayers = &nl; - config.networkLayersSize = 1; + UA_ServerConfig *config = UA_ServerConfig_new_default(); UA_Server *server = UA_Server_new(config); addVariable(server); writeVariable(server); writeWrongVariable(server); - UA_Server_run(server, &running); + UA_StatusCode retval = UA_Server_run(server, &running); UA_Server_delete(server); - nl.deleteMembers(&nl); - return 0; + UA_ServerConfig_delete(config); + return (int)retval; } diff --git a/examples/tutorial_server_variabletype.c b/examples/tutorial_server_variabletype.c index 14bf1ba1ed9..294bb3147c9 100644 --- a/examples/tutorial_server_variabletype.c +++ b/examples/tutorial_server_variabletype.c @@ -122,11 +122,7 @@ int main(void) { signal(SIGINT, stopHandler); signal(SIGTERM, stopHandler); - UA_ServerConfig config = UA_ServerConfig_standard; - UA_ServerNetworkLayer nl = - UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664); - config.networkLayers = &nl; - config.networkLayersSize = 1; + UA_ServerConfig *config = UA_ServerConfig_new_default(); UA_Server *server = UA_Server_new(config); addVariableType2DPoint(server); @@ -134,8 +130,8 @@ int main(void) { addVariableFail(server); writeVariable(server); - UA_Server_run(server, &running); + UA_StatusCode retval = UA_Server_run(server, &running); UA_Server_delete(server); - nl.deleteMembers(&nl); - return 0; + UA_ServerConfig_delete(config); + return (int)retval; } diff --git a/include/ua_client.h b/include/ua_client.h index f93bfcf35b9..6e1b8115e8f 100644 --- a/include/ua_client.h +++ b/include/ua_client.h @@ -70,7 +70,7 @@ typedef struct UA_Client UA_Client; /* Create a new client * - * @param config for the new client. You can use UA_ClientConfig_standard + * @param config for the new client. You can use UA_ClientConfig_default * which has sane defaults * @param logger function pointer to a logger function. See * examples/logger_stdout.c for a simple implementation diff --git a/include/ua_client_highlevel.h b/include/ua_client_highlevel.h index 566d7e0afa4..6f8944bec94 100644 --- a/include/ua_client_highlevel.h +++ b/include/ua_client_highlevel.h @@ -575,7 +575,7 @@ typedef struct { UA_Byte priority; } UA_SubscriptionSettings; -extern const UA_EXPORT UA_SubscriptionSettings UA_SubscriptionSettings_standard; +extern const UA_EXPORT UA_SubscriptionSettings UA_SubscriptionSettings_default; UA_StatusCode UA_EXPORT UA_Client_Subscriptions_new(UA_Client *client, UA_SubscriptionSettings settings, diff --git a/include/ua_plugin_network.h b/include/ua_plugin_network.h index 382fbb6bf96..2b3864547c1 100644 --- a/include/ua_plugin_network.h +++ b/include/ua_plugin_network.h @@ -53,7 +53,7 @@ typedef enum { * is not done */ UA_CONNECTION_ESTABLISHED, /* The socket is open and the connection * configured */ - UA_CONNECTION_CLOSED /* The socket has been closed and the connection + UA_CONNECTION_CLOSED /* The socket has been closed and the connection * will be deleted */ } UA_ConnectionState; diff --git a/include/ua_plugin_securitypolicy.h b/include/ua_plugin_securitypolicy.h new file mode 100644 index 00000000000..38e1cd1e008 --- /dev/null +++ b/include/ua_plugin_securitypolicy.h @@ -0,0 +1,38 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef UA_PLUGIN_SECURITYPOLICY_H_ +#define UA_PLUGIN_SECURITYPOLICY_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ua_types.h" +#include "ua_plugin_log.h" +#include "ua_types_generated.h" + +extern const UA_ByteString UA_SECURITY_POLICY_NONE_URI; + +struct UA_SecurityPolicy; +typedef struct UA_SecurityPolicy UA_SecurityPolicy; + +/* Holds an endpoint description and the corresponding security policy + * Also holds the context for the endpoint. */ +typedef struct { + UA_SecurityPolicy *securityPolicy; + void *securityContext; + UA_EndpointDescription endpointDescription; +} UA_Endpoint; + +typedef struct { + size_t count; + UA_Endpoint *endpoints; +} UA_Endpoints; + +#ifdef __cplusplus +} +#endif + +#endif /* UA_PLUGIN_SECURITYPOLICY_H_ */ diff --git a/include/ua_server.h b/include/ua_server.h index d78ab461999..d6add2c20a0 100644 --- a/include/ua_server.h +++ b/include/ua_server.h @@ -15,6 +15,7 @@ extern "C" { #include "ua_plugin_log.h" #include "ua_plugin_network.h" #include "ua_plugin_access_control.h" +#include "ua_plugin_securitypolicy.h" /** * .. _server: @@ -43,7 +44,6 @@ typedef struct { /* Server Description */ UA_BuildInfo buildInfo; UA_ApplicationDescription applicationDescription; - UA_ByteString serverCertificate; #ifdef UA_ENABLE_DISCOVERY UA_String mdnsServerName; size_t serverCapabilitiesSize; @@ -52,12 +52,15 @@ typedef struct { /* Custom DataTypes */ size_t customDataTypesSize; - const UA_DataType *customDataTypes; + UA_DataType *customDataTypes; /* Networking */ size_t networkLayersSize; UA_ServerNetworkLayer *networkLayers; + /* Available endpoints */ + UA_Endpoints endpoints; + /* Access Control */ UA_AccessControl accessControl; @@ -97,7 +100,7 @@ typedef struct { * * Server Lifecycle * ---------------- */ -UA_Server UA_EXPORT * UA_Server_new(const UA_ServerConfig config); +UA_Server UA_EXPORT * UA_Server_new(const UA_ServerConfig *config); void UA_EXPORT UA_Server_delete(UA_Server *server); /* Runs the main loop of the server. In each iteration, this calls into the diff --git a/plugins/ua_config_standard.c b/plugins/ua_config_standard.c index 69909b07ab4..8b1004b23b2 100644 --- a/plugins/ua_config_standard.c +++ b/plugins/ua_config_standard.c @@ -5,12 +5,32 @@ #include "ua_log_stdout.h" #include "ua_network_tcp.h" #include "ua_accesscontrol_default.h" +#include "ua_types_generated.h" +#include "ua_types.h" -/*******************************/ -/* Default Connection Settings */ -/*******************************/ +#define ANONYMOUS_POLICY "open62541-anonymous-policy" +#define USERNAME_POLICY "open62541-username-policy" -const UA_EXPORT UA_ConnectionConfig UA_ConnectionConfig_standard = { +/* Struct initialization works across ANSI C/C99/C++ if it is done when the + * variable is first declared. Assigning values to existing structs is + * heterogeneous across the three. */ +static UA_INLINE UA_UInt32Range +UA_UINT32RANGE(UA_UInt32 min, UA_UInt32 max) { + UA_UInt32Range range = {min, max}; + return range; +} + +static UA_INLINE UA_DoubleRange +UA_DOUBLERANGE(UA_Double min, UA_Double max) { + UA_DoubleRange range = {min, max}; + return range; +} + + /*******************************/ + /* Default Connection Settings */ + /*******************************/ + +const UA_ConnectionConfig UA_ConnectionConfig_default = { 0, /* .protocolVersion */ 65535, /* .sendBufferSize, 64k per chunk */ 65535, /* .recvBufferSize, 64k per chunk */ @@ -28,92 +48,228 @@ const UA_EXPORT UA_ConnectionConfig UA_ConnectionConfig_standard = { #define APPLICATION_NAME "open62541-based OPC UA Application" #define APPLICATION_URI "urn:unconfigured:application" -#define UA_STRING_STATIC(s) {sizeof(s)-1, (UA_Byte*)s} -#define UA_STRING_STATIC_NULL {0, NULL} #define STRINGIFY(arg) #arg #define VERSION(MAJOR, MINOR, PATCH, LABEL) \ STRINGIFY(MAJOR) "." STRINGIFY(MINOR) "." STRINGIFY(PATCH) LABEL -const UA_EXPORT UA_ServerConfig UA_ServerConfig_standard = { - 1, /* .nThreads */ - UA_Log_Stdout, /* .logger */ +static UA_StatusCode +createSecurityPolicyNoneEndpoint(UA_ServerConfig *conf, UA_Endpoint *endpoint, + const UA_ByteString *cert) { + UA_EndpointDescription_init(&endpoint->endpointDescription); + + endpoint->securityPolicy = NULL; + endpoint->endpointDescription.securityMode = UA_MESSAGESECURITYMODE_NONE; + endpoint->endpointDescription.securityPolicyUri = + UA_STRING_ALLOC("http://opcfoundation.org/UA/SecurityPolicy#None"); + endpoint->endpointDescription.transportProfileUri = + UA_STRING_ALLOC("http://opcfoundation.org/UA-Profile/Transport/uatcp-uasc-uabinary"); + + /* enable anonymous and username/password */ + size_t policies = 2; + endpoint->endpointDescription.userIdentityTokens = (UA_UserTokenPolicy*) + UA_Array_new(policies, &UA_TYPES[UA_TYPES_USERTOKENPOLICY]); + if(!endpoint->endpointDescription.userIdentityTokens) + return UA_STATUSCODE_BADOUTOFMEMORY; + endpoint->endpointDescription.userIdentityTokensSize = policies; + + endpoint->endpointDescription.userIdentityTokens[0].tokenType = + UA_USERTOKENTYPE_ANONYMOUS; + endpoint->endpointDescription.userIdentityTokens[0].policyId = + UA_STRING_ALLOC(ANONYMOUS_POLICY); + + endpoint->endpointDescription.userIdentityTokens[1].tokenType = + UA_USERTOKENTYPE_USERNAME; + endpoint->endpointDescription.userIdentityTokens[1].policyId = + UA_STRING_ALLOC(USERNAME_POLICY); + + if(cert) + UA_String_copy(cert, &endpoint->endpointDescription.serverCertificate); + + UA_ApplicationDescription_copy(&conf->applicationDescription, + &endpoint->endpointDescription.server); + + return UA_STATUSCODE_GOOD; +} + +UA_ServerConfig * +UA_ServerConfig_new_minimal(UA_UInt16 portNumber, + const UA_ByteString *certificate) { + UA_ServerConfig *conf = (UA_ServerConfig*)UA_malloc(sizeof(UA_ServerConfig)); + if(!conf) + return NULL; + + /* Zero out.. All members have a valid initial value */ + memset(conf, 0, sizeof(UA_ServerConfig)); + + /* --> Start setting the default static config <-- */ + conf->nThreads = 1; + conf->logger = UA_Log_Stdout; /* Server Description */ - {UA_STRING_STATIC(PRODUCT_URI), - UA_STRING_STATIC(MANUFACTURER_NAME), - UA_STRING_STATIC(PRODUCT_NAME), - UA_STRING_STATIC(VERSION(UA_OPEN62541_VER_MAJOR, UA_OPEN62541_VER_MINOR, - UA_OPEN62541_VER_PATCH, UA_OPEN62541_VER_LABEL)), - UA_STRING_STATIC(__DATE__ " " __TIME__), 0 }, /* .buildInfo */ - - {UA_STRING_STATIC(APPLICATION_URI), - UA_STRING_STATIC(PRODUCT_URI), - {UA_STRING_STATIC("en"),UA_STRING_STATIC(APPLICATION_NAME) }, - UA_APPLICATIONTYPE_SERVER, - UA_STRING_STATIC_NULL, - UA_STRING_STATIC_NULL, - 0, NULL }, /* .applicationDescription */ - UA_STRING_STATIC_NULL, /* .serverCertificate */ + conf->buildInfo.productUri = UA_STRING_ALLOC(PRODUCT_URI); + conf->buildInfo.manufacturerName = UA_STRING_ALLOC(MANUFACTURER_NAME); + conf->buildInfo.productName = UA_STRING_ALLOC(PRODUCT_NAME); + conf->buildInfo.softwareVersion = + UA_STRING_ALLOC(VERSION(UA_OPEN62541_VER_MAJOR, UA_OPEN62541_VER_MINOR, + UA_OPEN62541_VER_PATCH, UA_OPEN62541_VER_LABEL)); + conf->buildInfo.buildNumber = UA_STRING_ALLOC(__DATE__ " " __TIME__); + conf->buildInfo.buildDate = 0; + + conf->applicationDescription.applicationUri = UA_STRING_ALLOC(APPLICATION_URI); + conf->applicationDescription.productUri = UA_STRING_ALLOC(PRODUCT_URI); + conf->applicationDescription.applicationName = + UA_LOCALIZEDTEXT_ALLOC("en", APPLICATION_NAME); + conf->applicationDescription.applicationType = UA_APPLICATIONTYPE_SERVER; + /* conf->applicationDescription.gatewayServerUri = UA_STRING_NULL; */ + /* conf->applicationDescription.discoveryProfileUri = UA_STRING_NULL; */ + /* conf->applicationDescription.discoveryUrlsSize = 0; */ + /* conf->applicationDescription.discoveryUrls = NULL; */ + #ifdef UA_ENABLE_DISCOVERY - UA_STRING_STATIC_NULL, /* mdnsServerName */ - 0, /* serverCapabilitiesSize */ - NULL, /* serverCapabilities */ + /* conf->mdnsServerName = UA_STRING_NULL; */ + /* conf->serverCapabilitiesSize = 0; */ + /* conf->serverCapabilities = NULL; */ #endif /* Custom DataTypes */ - 0, /* .customDataTypesSize */ - NULL, /* .customDataTypes */ + /* conf->customDataTypesSize = 0; */ + /* conf->customDataTypes = NULL; */ /* Networking */ - 0, /* .networkLayersSize */ - NULL, /* .networkLayers */ + /* conf->networkLayersSize = 0; */ + /* conf->networkLayers = NULL; */ + + /* Endpoints */ + /* conf->endpoints = {0, NULL}; */ /* Access Control */ - {true, true, - activateSession_default, closeSession_default, - getUserRightsMask_default, getUserAccessLevel_default, - getUserExecutable_default, getUserExecutableOnObject_default, - allowAddNode_default, allowAddReference_default, - allowDeleteNode_default, allowDeleteReference_default}, + conf->accessControl.enableAnonymousLogin = true; + conf->accessControl.enableUsernamePasswordLogin = true; + conf->accessControl.activateSession = activateSession_default; + conf->accessControl.closeSession = closeSession_default; + conf->accessControl.getUserRightsMask = getUserRightsMask_default; + conf->accessControl.getUserAccessLevel = getUserAccessLevel_default; + conf->accessControl.getUserExecutable = getUserExecutable_default; + conf->accessControl.getUserExecutableOnObject = getUserExecutableOnObject_default; + conf->accessControl.allowAddNode = allowAddNode_default; + conf->accessControl.allowAddReference = allowAddReference_default; + conf->accessControl.allowDeleteNode = allowDeleteNode_default; + conf->accessControl.allowDeleteReference = allowDeleteReference_default; /* Limits for SecureChannels */ - 40, /* .maxSecureChannels */ - 10 * 60 * 1000, /* .maxSecurityTokenLifetime, 10 minutes */ + conf->maxSecureChannels = 40; + conf->maxSecurityTokenLifetime = 10 * 60 * 1000; /* 10 minutes */ /* Limits for Sessions */ - 100, /* .maxSessions */ - 60.0 * 60.0 * 1000.0, /* .maxSessionTimeout, 1h */ + conf->maxSessions = 100; + conf->maxSessionTimeout = 60.0 * 60.0 * 1000.0; /* 1h */ /* Limits for Subscriptions */ - {100.0,3600.0 * 1000.0 }, /* .publishingIntervalLimits */ - {3, 15000 }, /* .lifeTimeCountLimits */ - {1,100}, /* .keepAliveCountLimits */ - 1000, /* .maxNotificationsPerPublish */ - 0, /* .maxRetransmissionQueueSize, unlimited */ + conf->publishingIntervalLimits = UA_DOUBLERANGE(100.0, 3600.0 * 1000.0); + conf->lifeTimeCountLimits = UA_UINT32RANGE(3, 15000); + conf->keepAliveCountLimits = UA_UINT32RANGE(1, 100); + conf->maxNotificationsPerPublish = 1000; + conf->maxRetransmissionQueueSize = 0; /* unlimited */ /* Limits for MonitoredItems */ - {50.0, 24.0 * 3600.0 * 1000.0 }, /* .samplingIntervalLimits */ - {1,100} /* .queueSizeLimits */ + conf->samplingIntervalLimits = UA_DOUBLERANGE(50.0, 24.0 * 3600.0 * 1000.0); + conf->queueSizeLimits = UA_UINT32RANGE(1, 100); #ifdef UA_ENABLE_DISCOVERY - , 60*60 /* .discoveryCleanupTimeout */ + conf->discoveryCleanupTimeout = 60 * 60; #endif -}; + + /* --> Finish setting the default static config <-- */ + + /* Add a network layer */ + conf->networkLayers = (UA_ServerNetworkLayer*) + UA_malloc(sizeof(UA_ServerNetworkLayer)); + if(!conf->networkLayers) { + UA_free(conf); + return NULL; + } + conf->networkLayers[0] = + UA_ServerNetworkLayerTCP(UA_ConnectionConfig_default, portNumber); + conf->networkLayersSize = 1; + + /* Allocate the endpoint */ + conf->endpoints.endpoints = (UA_Endpoint*)UA_malloc(sizeof(UA_Endpoint)); + if(!conf->endpoints.endpoints) { + conf->networkLayers[0].deleteMembers(&conf->networkLayers[0]); + UA_free(conf->networkLayers); + UA_free(conf); + return NULL; + } + conf->endpoints.count = 1; + + /* Populate the endpoint */ + UA_StatusCode retval = + createSecurityPolicyNoneEndpoint(conf, &conf->endpoints.endpoints[0], + certificate); + if(retval != UA_STATUSCODE_GOOD) { + conf->networkLayers[0].deleteMembers(&conf->networkLayers[0]); + UA_free(conf->networkLayers); + UA_free(conf->endpoints.endpoints); + UA_free(conf); + return NULL; + } + + return conf; +} + +void +UA_ServerConfig_delete(UA_ServerConfig *config) { + if(!config) + return; + + /* Server Description */ + UA_BuildInfo_deleteMembers(&config->buildInfo); + UA_ApplicationDescription_deleteMembers(&config->applicationDescription); +#ifdef UA_ENABLE_DISCOVERY + UA_String_deleteMembers(&config->mdnsServerName); + UA_Array_delete(config->serverCapabilities, config->serverCapabilitiesSize, + &UA_TYPES[UA_TYPES_STRING]); + /* config->serverCapabilities = NULL; */ + /* config->serverCapabilitiesSize = 0; */ +#endif + + /* Custom DataTypes */ + for(size_t i = 0; i < config->customDataTypesSize; ++i) + UA_free(config->customDataTypes[i].members); + UA_free(config->customDataTypes); + /* config->customDataTypes = NULL; */ + /* config0>customDataTypesSize = 0; */ + + /* Networking */ + for(size_t i = 0; i < config->networkLayersSize; ++i) + config->networkLayers[i].deleteMembers(&config->networkLayers[i]); + UA_free(config->networkLayers); + /* config->networkLayers = NULL; */ + /* config->networkLayersSize = 0; */ + + for(size_t i = 0; i < config->endpoints.count; ++i) + UA_EndpointDescription_deleteMembers(&config->endpoints.endpoints[i].endpointDescription); + UA_free(config->endpoints.endpoints); + /* config->endpoints.endpoints = NULL; */ + /* config->endpoints.count = 0; */ + + UA_free(config); +} /***************************/ /* Default Client Settings */ /***************************/ -const UA_EXPORT UA_ClientConfig UA_ClientConfig_standard = { +const UA_ClientConfig UA_ClientConfig_default = { 5000, /* .timeout, 5 seconds */ 10 * 60 * 1000, /* .secureChannelLifeTime, 10 minutes */ UA_Log_Stdout, /* .logger */ /* .localConnectionConfig */ {0, /* .protocolVersion */ - 65535, /* .sendBufferSize, 64k per chunk */ - 65535, /* .recvBufferSize, 64k per chunk */ - 0, /* .maxMessageSize, 0 -> unlimited */ - 0 }, /* .maxChunkCount, 0 -> unlimited */ + 65535, /* .sendBufferSize, 64k per chunk */ + 65535, /* .recvBufferSize, 64k per chunk */ + 0, /* .maxMessageSize, 0 -> unlimited */ + 0}, /* .maxChunkCount, 0 -> unlimited */ UA_ClientConnectionTCP, /* .connectionFunc */ 0, /* .customDataTypesSize */ @@ -126,7 +282,7 @@ const UA_EXPORT UA_ClientConfig UA_ClientConfig_standard = { #ifdef UA_ENABLE_SUBSCRIPTIONS -const UA_SubscriptionSettings UA_SubscriptionSettings_standard = { +const UA_SubscriptionSettings UA_SubscriptionSettings_default = { 500.0, /* .requestedPublishingInterval */ 10000, /* .requestedLifetimeCount */ 1, /* .requestedMaxKeepAliveCount */ diff --git a/plugins/ua_config_standard.h b/plugins/ua_config_standard.h index dbc66962fd2..36bcb7d1c55 100644 --- a/plugins/ua_config_standard.h +++ b/plugins/ua_config_standard.h @@ -12,9 +12,45 @@ extern "C" { #include "ua_client.h" #include "ua_client_highlevel.h" -extern const UA_EXPORT UA_ConnectionConfig UA_ConnectionConfig_standard; -extern const UA_EXPORT UA_ServerConfig UA_ServerConfig_standard; -extern const UA_EXPORT UA_ClientConfig UA_ClientConfig_standard; +/**********************/ +/* Default Connection */ +/**********************/ + +extern const UA_EXPORT UA_ConnectionConfig UA_ConnectionConfig_default; + +/*************************/ +/* Default Server Config */ +/*************************/ + +/* Creates a new server config with one endpoint. + * + * The config will set the tcp network layer to the given port and adds a single + * endpoint with the security policy ``SecurityPolicy#None`` to the server. A + * server certificate may be supplied but is optional. + * + * @param portNumber The port number for the tcp network layer + * @param certificate Optional certificate for the server endpoint. Can be + * ``NULL``. */ +UA_EXPORT UA_ServerConfig * +UA_ServerConfig_new_minimal(UA_UInt16 portNumber, + const UA_ByteString *certificate); + +/* Creates a server config on the standard port 4840 with no server + * certificate. */ +static UA_INLINE UA_ServerConfig * +UA_ServerConfig_new_default(void) { + return UA_ServerConfig_new_minimal(4840, NULL); +} + +/* Frees allocated memory in the server config */ +UA_EXPORT void +UA_ServerConfig_delete(UA_ServerConfig *config); + +/*************************/ +/* Default Client Config */ +/*************************/ + +extern const UA_EXPORT UA_ClientConfig UA_ClientConfig_default; #ifdef __cplusplus } diff --git a/src/server/ua_server.c b/src/server/ua_server.c index e1457ad403d..e7d5745409a 100644 --- a/src/server/ua_server.c +++ b/src/server/ua_server.c @@ -8,6 +8,8 @@ #include "ua_session_manager.h" #include "ua_util.h" #include "ua_services.h" +#include "ua_types_generated.h" +#include "ua_types_generated_handling.h" #ifdef UA_ENABLE_GENERATE_NAMESPACE0 #include "ua_namespaceinit_generated.h" @@ -30,7 +32,7 @@ UA_UInt16 addNamespace(UA_Server *server, const UA_String name) { /* Make the array bigger */ UA_String *newNS = (UA_String*)UA_realloc(server->namespaces, - sizeof(UA_String) * (server->namespacesSize + 1)); + sizeof(UA_String) * (server->namespacesSize + 1)); if(!newNS) return 0; server->namespaces = newNS; @@ -70,14 +72,14 @@ UA_Server_forEachChildNodeCall(UA_Server *server, UA_NodeId parentNodeId, UA_ReferenceNode *refs = NULL; size_t refssize = parent->referencesSize; UA_StatusCode retval = UA_Array_copy(parent->references, parent->referencesSize, - (void**)&refs, &UA_TYPES[UA_TYPES_REFERENCENODE]); + (void**)&refs, &UA_TYPES[UA_TYPES_REFERENCENODE]); if(retval != UA_STATUSCODE_GOOD) { UA_RCU_UNLOCK(); return retval; } for(size_t i = parent->referencesSize; i > 0; --i) { - UA_ReferenceNode *ref = &refs[i-1]; + UA_ReferenceNode *ref = &refs[i - 1]; retval |= callback(ref->targetId.nodeId, ref->isInverse, ref->referenceTypeId, handle); } @@ -100,8 +102,6 @@ void UA_Server_delete(UA_Server *server) { UA_NodeStore_delete(server->nodestore); UA_RCU_UNLOCK(); UA_Array_delete(server->namespaces, server->namespacesSize, &UA_TYPES[UA_TYPES_STRING]); - UA_Array_delete(server->endpointDescriptions, server->endpointDescriptionsSize, - &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]); #ifdef UA_ENABLE_DISCOVERY registeredServer_list_entry *rs, *rs_tmp; @@ -161,62 +161,21 @@ UA_Server_cleanup(UA_Server *server, void *_) { #endif } -/* Create endpoints w/o endpointurl. It is added from the networklayers at startup */ -static void -addEndpointDefinitions(UA_Server *server) { - server->endpointDescriptions = - (UA_EndpointDescription*)UA_Array_new(server->config.networkLayersSize, - &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]); - server->endpointDescriptionsSize = server->config.networkLayersSize; - - for(size_t i = 0; i < server->config.networkLayersSize; ++i) { - UA_EndpointDescription *endpoint = &server->endpointDescriptions[i]; - endpoint->securityMode = UA_MESSAGESECURITYMODE_NONE; - endpoint->securityPolicyUri = - UA_STRING_ALLOC("http://opcfoundation.org/UA/SecurityPolicy#None"); - endpoint->transportProfileUri = - UA_STRING_ALLOC("http://opcfoundation.org/UA-Profile/Transport/uatcp-uasc-uabinary"); - - size_t policies = 0; - if(server->config.accessControl.enableAnonymousLogin) - ++policies; - if(server->config.accessControl.enableUsernamePasswordLogin) - ++policies; - endpoint->userIdentityTokensSize = policies; - endpoint->userIdentityTokens = - (UA_UserTokenPolicy*)UA_Array_new(policies, &UA_TYPES[UA_TYPES_USERTOKENPOLICY]); - - size_t currentIndex = 0; - if(server->config.accessControl.enableAnonymousLogin) { - UA_UserTokenPolicy_init(&endpoint->userIdentityTokens[currentIndex]); - endpoint->userIdentityTokens[currentIndex].tokenType = UA_USERTOKENTYPE_ANONYMOUS; - endpoint->userIdentityTokens[currentIndex].policyId = UA_STRING_ALLOC(ANONYMOUS_POLICY); - ++currentIndex; - } - if(server->config.accessControl.enableUsernamePasswordLogin) { - UA_UserTokenPolicy_init(&endpoint->userIdentityTokens[currentIndex]); - endpoint->userIdentityTokens[currentIndex].tokenType = UA_USERTOKENTYPE_USERNAME; - endpoint->userIdentityTokens[currentIndex].policyId = UA_STRING_ALLOC(USERNAME_POLICY); - } - - /* 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->config.serverCertificate, &endpoint->serverCertificate); - UA_ApplicationDescription_copy(&server->config.applicationDescription, &endpoint->server); - - /* copy the discovery url only once the networlayer has been started */ - // UA_String_copy(&server->config.networkLayers[i].discoveryUrl, &endpoint->endpointUrl); - } -} - UA_Server * -UA_Server_new(const UA_ServerConfig config) { +UA_Server_new(const UA_ServerConfig *config) { UA_Server *server = (UA_Server *)UA_calloc(1, sizeof(UA_Server)); if(!server) return NULL; - server->config = config; + if(config->endpoints.count == 0) { + UA_LOG_FATAL(config->logger, + UA_LOGCATEGORY_SERVER, + "There has to be at least one endpoint."); + UA_free(server); + return NULL; + } + + server->config = *config; server->startTime = UA_DateTime_now(); server->nodestore = UA_NodeStore_new(); @@ -245,9 +204,6 @@ UA_Server_new(const UA_ServerConfig config) { UA_String_copy(&server->config.applicationDescription.applicationUri, &server->namespaces[1]); server->namespacesSize = 2; - /* Create Endpoint Definitions */ - addEndpointDefinitions(server); - /* Initialized SecureChannel and Session managers */ UA_SecureChannelManager_init(&server->secureChannelManager, server); UA_SessionManager_init(&server->sessionManager, server); diff --git a/src/server/ua_server_discovery.c b/src/server/ua_server_discovery.c index d24efa5271d..08d682f5d5c 100644 --- a/src/server/ua_server_discovery.c +++ b/src/server/ua_server_discovery.c @@ -20,7 +20,7 @@ register_server_with_discovery_server(UA_Server *server, } /* Create the client */ - UA_Client *client = UA_Client_new(UA_ClientConfig_standard); + UA_Client *client = UA_Client_new(UA_ClientConfig_default); if(!client) return UA_STATUSCODE_BADOUTOFMEMORY; diff --git a/src/server/ua_server_internal.h b/src/server/ua_server_internal.h index e18ad0cc3a6..37bdad33950 100644 --- a/src/server/ua_server_internal.h +++ b/src/server/ua_server_internal.h @@ -21,9 +21,6 @@ extern "C" { #include "mdnsd/libmdnsd/mdnsd.h" #endif -#define ANONYMOUS_POLICY "open62541-anonymous-policy" -#define USERNAME_POLICY "open62541-username-policy" - /* The general idea of RCU is to delay freeing nodes (or any callback invoked * with call_rcu) until all threads have left their critical section. Thus we * can delete nodes safely in concurrent operations. The macros UA_RCU_LOCK and @@ -100,8 +97,6 @@ typedef struct serverOnNetwork_hash_entry { struct UA_Server { /* Meta */ UA_DateTime startTime; - size_t endpointDescriptionsSize; - UA_EndpointDescription *endpointDescriptions; /* Security */ UA_SecureChannelManager secureChannelManager; diff --git a/src/server/ua_services_discovery.c b/src/server/ua_services_discovery.c index ee5d4c3eb1a..d43c5c3ccb1 100644 --- a/src/server/ua_services_discovery.c +++ b/src/server/ua_services_discovery.c @@ -246,19 +246,19 @@ void Service_GetEndpoints(UA_Server *server, UA_Session *session, } /* test if the supported binary profile shall be returned */ - size_t reSize = sizeof(UA_Boolean) * server->endpointDescriptionsSize; + size_t reSize = sizeof(UA_Boolean) * server->config.endpoints.count; UA_Boolean *relevant_endpoints = (UA_Boolean *)UA_alloca(reSize); - memset(relevant_endpoints, 0, sizeof(UA_Boolean) * server->endpointDescriptionsSize); + memset(relevant_endpoints, 0, sizeof(UA_Boolean) * server->config.endpoints.count); size_t relevant_count = 0; if(request->profileUrisSize == 0) { - for(size_t j = 0; j < server->endpointDescriptionsSize; ++j) + for(size_t j = 0; j < server->config.endpoints.count; ++j) relevant_endpoints[j] = true; - relevant_count = server->endpointDescriptionsSize; + relevant_count = server->config.endpoints.count; } else { - for(size_t j = 0; j < server->endpointDescriptionsSize; ++j) { + for(size_t j = 0; j < server->config.endpoints.count; ++j) { for(size_t i = 0; i < request->profileUrisSize; ++i) { if(!UA_String_equal(&request->profileUris[i], - &server->endpointDescriptions[j].transportProfileUri)) + &server->config.endpoints.endpoints[j].endpointDescription.transportProfileUri)) continue; relevant_endpoints[j] = true; ++relevant_count; @@ -294,10 +294,10 @@ void Service_GetEndpoints(UA_Server *server, UA_Session *session, for(size_t i = 0; i < clone_times; ++i) { if(nl_endpointurl) endpointUrl = &server->config.networkLayers[i].discoveryUrl; - for(size_t j = 0; j < server->endpointDescriptionsSize; ++j) { + for(size_t j = 0; j < server->config.endpoints.count; ++j) { if(!relevant_endpoints[j]) continue; - retval |= UA_EndpointDescription_copy(&server->endpointDescriptions[j], + retval |= UA_EndpointDescription_copy(&server->config.endpoints.endpoints[j].endpointDescription, &response->endpoints[k]); retval |= UA_String_copy(endpointUrl, &response->endpoints[k].endpointUrl); ++k; diff --git a/src/server/ua_services_session.c b/src/server/ua_services_session.c index a181895c451..d576922bdab 100644 --- a/src/server/ua_services_session.c +++ b/src/server/ua_services_session.c @@ -16,20 +16,28 @@ void Service_CreateSession(UA_Server *server, UA_SecureChannel *channel, return; } - /* Copy the server's endpoint into the response */ - response->responseHeader.serviceResult = - UA_Array_copy(server->endpointDescriptions, - server->endpointDescriptionsSize, - (void**)&response->serverEndpoints, - &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]); - if(response->responseHeader.serviceResult != UA_STATUSCODE_GOOD) + /* Allocate the response */ + response->serverEndpoints = (UA_EndpointDescription*) + UA_Array_new(server->config.endpoints.count, + &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]); + if(!response->serverEndpoints) { + response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY; return; - response->serverEndpointsSize = server->endpointDescriptionsSize; + } + response->serverEndpointsSize = server->config.endpoints.count; + + /* Copy the server's endpointdescriptions into the response */ + for(size_t i = 0; i < server->config.endpoints.count; ++i) + response->responseHeader.serviceResult |= + UA_EndpointDescription_copy(&server->config.endpoints.endpoints[0].endpointDescription, + &response->serverEndpoints[i]); /* Mirror back the endpointUrl */ - for(size_t i = 0; i < response->serverEndpointsSize; ++i) + for(size_t i = 0; i < response->serverEndpointsSize; ++i) { + UA_String_deleteMembers(&response->serverEndpoints[i].endpointUrl); UA_String_copy(&request->endpointUrl, &response->serverEndpoints[i].endpointUrl); + } UA_Session *newSession; response->responseHeader.serviceResult = @@ -55,9 +63,9 @@ void Service_CreateSession(UA_Server *server, UA_SecureChannel *channel, response->authenticationToken = newSession->authenticationToken; response->responseHeader.serviceResult = UA_String_copy(&request->sessionName, &newSession->sessionName); - if(server->endpointDescriptionsSize > 0) + if(server->config.endpoints.count > 0) response->responseHeader.serviceResult |= - UA_ByteString_copy(&server->endpointDescriptions->serverCertificate, + UA_ByteString_copy(&server->config.endpoints.endpoints[0].endpointDescription.serverCertificate, &response->serverCertificate); /* Failure -> remove the session */ diff --git a/tests/check_client.c b/tests/check_client.c index 0a50fdbbc09..3f7724cc4c1 100644 --- a/tests/check_client.c +++ b/tests/check_client.c @@ -14,6 +14,7 @@ #include "check.h" UA_Server *server; +UA_ServerConfig *config; UA_Boolean *running; UA_ServerNetworkLayer nl; pthread_t server_thread; @@ -21,8 +22,7 @@ pthread_t server_thread; static void addVariable(size_t size) { /* Define the attribute of the myInteger variable node */ - UA_VariableAttributes attr; - UA_VariableAttributes_init(&attr); + UA_VariableAttributes attr = UA_VariableAttributes_default; UA_Int32* array = (UA_Int32*)UA_malloc(size * sizeof(UA_Int32)); memset(array, 0, size * sizeof(UA_Int32)); UA_Variant_setArray(&attr.value, array, size, &UA_TYPES[UA_TYPES_INT32]); @@ -53,10 +53,7 @@ static void * serverloop(void *_) { static void setup(void) { running = UA_Boolean_new(); *running = true; - UA_ServerConfig config = UA_ServerConfig_standard; - nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664); - config.networkLayers = &nl; - config.networkLayersSize = 1; + config = UA_ServerConfig_new_default(); server = UA_Server_new(config); UA_Server_run_startup(server); addVariable(16366); @@ -69,12 +66,12 @@ static void teardown(void) { UA_Server_run_shutdown(server); UA_Boolean_delete(running); UA_Server_delete(server); - nl.deleteMembers(&nl); + UA_ServerConfig_delete(config); } START_TEST(Client_connect) { - UA_Client *client = UA_Client_new(UA_ClientConfig_standard); - UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:16664"); + UA_Client *client = UA_Client_new(UA_ClientConfig_default); + UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:4840"); ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD); @@ -84,8 +81,8 @@ START_TEST(Client_connect) { END_TEST START_TEST(Client_read) { - UA_Client *client = UA_Client_new(UA_ClientConfig_standard); - UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:16664"); + UA_Client *client = UA_Client_new(UA_ClientConfig_default); + UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:4840"); ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD); UA_Variant val; diff --git a/tests/check_client_async.c b/tests/check_client_async.c index 4c1377d870e..9be15414db6 100644 --- a/tests/check_client_async.c +++ b/tests/check_client_async.c @@ -15,6 +15,7 @@ #include "testing_clock.h" UA_Server *server; +UA_ServerConfig *config; UA_Boolean running; UA_ServerNetworkLayer nl; pthread_t server_thread; @@ -27,10 +28,7 @@ static void * serverloop(void *_) { static void setup(void) { running = true; - UA_ServerConfig config = UA_ServerConfig_standard; - nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664); - config.networkLayers = &nl; - config.networkLayersSize = 1; + config = UA_ServerConfig_new_default(); server = UA_Server_new(config); UA_Server_run_startup(server); pthread_create(&server_thread, NULL, serverloop, NULL); @@ -41,7 +39,7 @@ static void teardown(void) { pthread_join(server_thread, NULL); UA_Server_run_shutdown(server); UA_Server_delete(server); - nl.deleteMembers(&nl); + UA_ServerConfig_delete(config); } static void @@ -53,8 +51,8 @@ asyncReadCallback(UA_Client *client, void *userdata, } START_TEST(Client_read_async) { - UA_Client *client = UA_Client_new(UA_ClientConfig_standard); - UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:16664"); + UA_Client *client = UA_Client_new(UA_ClientConfig_default); + UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:4840"); ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD); UA_UInt16 asyncCounter = 0; diff --git a/tests/check_client_highlevel.c b/tests/check_client_highlevel.c index 394b709ca15..a6a18d3bb5d 100644 --- a/tests/check_client_highlevel.c +++ b/tests/check_client_highlevel.c @@ -14,6 +14,7 @@ #include "check.h" UA_Server *server; +UA_ServerConfig *config; UA_Boolean *running; UA_ServerNetworkLayer nl; pthread_t server_thread; @@ -32,10 +33,7 @@ static void *serverloop(void *_) { static void setup(void) { running = UA_Boolean_new(); *running = true; - UA_ServerConfig config = UA_ServerConfig_standard; - nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664); - config.networkLayers = &nl; - config.networkLayersSize = 1; + config = UA_ServerConfig_new_default(); server = UA_Server_new(config); ck_assert_uint_eq(2, UA_Server_addNamespace(server, CUSTOM_NS)); @@ -43,9 +41,8 @@ static void setup(void) { UA_Server_run_startup(server); pthread_create(&server_thread, NULL, serverloop, NULL); - client = UA_Client_new(UA_ClientConfig_standard); - UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:16664"); - + client = UA_Client_new(UA_ClientConfig_default); + UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:4840"); ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD); } @@ -57,7 +54,7 @@ static void teardown(void) { UA_Server_run_shutdown(server); UA_Boolean_delete(running); UA_Server_delete(server); - nl.deleteMembers(&nl); + UA_ServerConfig_delete(config); } START_TEST(Misc_State) { diff --git a/tests/check_client_subscriptions.c b/tests/check_client_subscriptions.c index 91e79ef09a9..83da20fd1e5 100644 --- a/tests/check_client_subscriptions.c +++ b/tests/check_client_subscriptions.c @@ -17,6 +17,7 @@ #include "testing_clock.h" UA_Server *server; +UA_ServerConfig *config; UA_Boolean *running; UA_ServerNetworkLayer nl; pthread_t server_thread; @@ -30,10 +31,7 @@ static void * serverloop(void *_) { static void setup(void) { running = UA_Boolean_new(); *running = true; - UA_ServerConfig config = UA_ServerConfig_standard; - nl = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664); - config.networkLayers = &nl; - config.networkLayersSize = 1; + config = UA_ServerConfig_new_default(); server = UA_Server_new(config); UA_Server_run_startup(server); pthread_create(&server_thread, NULL, serverloop, NULL); @@ -45,7 +43,7 @@ static void teardown(void) { UA_Server_run_shutdown(server); UA_Boolean_delete(running); UA_Server_delete(server); - nl.deleteMembers(&nl); + UA_ServerConfig_delete(config); } UA_Boolean notificationReceived; @@ -55,21 +53,22 @@ static void monitoredItemHandler(UA_UInt32 monId, UA_DataValue *value, void *con } START_TEST(Client_subscription) { - UA_Client *client = UA_Client_new(UA_ClientConfig_standard); - UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:16664"); + UA_Client *client = UA_Client_new(UA_ClientConfig_default); + UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:4840"); ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD); UA_UInt32 subId; - retval = UA_Client_Subscriptions_new(client, UA_SubscriptionSettings_standard, &subId); + retval = UA_Client_Subscriptions_new(client, UA_SubscriptionSettings_default, &subId); ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD); /* monitor the server state */ UA_UInt32 monId; retval = UA_Client_Subscriptions_addMonitoredItem(client, subId, UA_NODEID_NUMERIC(0, 2259), - UA_ATTRIBUTEID_VALUE, monitoredItemHandler, NULL, &monId); + UA_ATTRIBUTEID_VALUE, monitoredItemHandler, + NULL, &monId); ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD); - UA_sleep((UA_UInt32)UA_SubscriptionSettings_standard.requestedPublishingInterval + 1); + UA_sleep((UA_UInt32)UA_SubscriptionSettings_default.requestedPublishingInterval + 1); notificationReceived = false; retval = UA_Client_Subscriptions_manuallySendPublishRequest(client); @@ -82,12 +81,12 @@ START_TEST(Client_subscription) { END_TEST START_TEST(Client_methodcall) { - UA_Client *client = UA_Client_new(UA_ClientConfig_standard); - UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:16664"); + UA_Client *client = UA_Client_new(UA_ClientConfig_default); + UA_StatusCode retval = UA_Client_connect(client, "opc.tcp://localhost:4840"); ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD); UA_UInt32 subId; - retval = UA_Client_Subscriptions_new(client, UA_SubscriptionSettings_standard, &subId); + retval = UA_Client_Subscriptions_new(client, UA_SubscriptionSettings_default, &subId); ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD); /* monitor the server state */ diff --git a/tests/check_discovery.c b/tests/check_discovery.c index bde47b06eb8..c47d673458e 100644 --- a/tests/check_discovery.c +++ b/tests/check_discovery.c @@ -37,8 +37,8 @@ #define checkWait registerTimeout + 11 UA_Server *server_lds; +UA_ServerConfig *config_lds; UA_Boolean *running_lds; -UA_ServerNetworkLayer nl_lds; pthread_t server_thread_lds; static void * serverloop_lds(void *_) { @@ -51,24 +51,24 @@ static void setup_lds(void) { // start LDS server running_lds = UA_Boolean_new(); *running_lds = true; - UA_ServerConfig config_lds = UA_ServerConfig_standard; - config_lds.applicationDescription.applicationType = UA_APPLICATIONTYPE_DISCOVERYSERVER; - config_lds.applicationDescription.applicationUri = - UA_String_fromChars("urn:open62541.test.local_discovery_server"); - config_lds.applicationDescription.applicationName.locale = UA_String_fromChars("en"); - config_lds.applicationDescription.applicationName.text = UA_String_fromChars("LDS Server"); - config_lds.mdnsServerName = UA_String_fromChars("LDS_test"); - config_lds.serverCapabilitiesSize = 1; + config_lds = UA_ServerConfig_new_default(); + config_lds->applicationDescription.applicationType = UA_APPLICATIONTYPE_DISCOVERYSERVER; + UA_String_deleteMembers(&config_lds->applicationDescription.applicationUri); + config_lds->applicationDescription.applicationUri = + UA_STRING_ALLOC("urn:open62541.test.local_discovery_server"); + UA_LocalizedText_deleteMembers(&config_lds->applicationDescription.applicationName); + config_lds->applicationDescription.applicationName + = UA_LOCALIZEDTEXT_ALLOC("en", "LDS Server"); + config_lds->mdnsServerName = UA_String_fromChars("LDS_test"); + config_lds->serverCapabilitiesSize = 1; UA_String *caps = UA_String_new(); *caps = UA_String_fromChars("LDS"); - config_lds.serverCapabilities = caps; - config_lds.discoveryCleanupTimeout = registerTimeout; - nl_lds = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 4840); - config_lds.networkLayers = &nl_lds; - config_lds.networkLayersSize = 1; + config_lds->serverCapabilities = caps; + config_lds->discoveryCleanupTimeout = registerTimeout; server_lds = UA_Server_new(config_lds); UA_Server_run_startup(server_lds); pthread_create(&server_thread_lds, NULL, serverloop_lds, NULL); + // wait until LDS started UA_sleep(1000); sleep(1); @@ -79,19 +79,13 @@ static void teardown_lds(void) { pthread_join(server_thread_lds, NULL); UA_Server_run_shutdown(server_lds); UA_Boolean_delete(running_lds); - UA_String_deleteMembers(&server_lds->config.applicationDescription.applicationUri); - UA_LocalizedText_deleteMembers(&server_lds->config.applicationDescription.applicationName); - UA_String_deleteMembers(&server_lds->config.mdnsServerName); - UA_Array_delete(server_lds->config.serverCapabilities, - server_lds->config.serverCapabilitiesSize, - &UA_TYPES[UA_TYPES_STRING]); UA_Server_delete(server_lds); - nl_lds.deleteMembers(&nl_lds); + UA_ServerConfig_delete(config_lds); } UA_Server *server_register; +UA_ServerConfig *config_register; UA_Boolean *running_register; -UA_ServerNetworkLayer nl_register; pthread_t server_thread_register; UA_UInt64 periodicRegisterCallbackId; @@ -106,15 +100,14 @@ static void setup_register(void) { // start register server running_register = UA_Boolean_new(); *running_register = true; - UA_ServerConfig config_register = UA_ServerConfig_standard; - config_register.applicationDescription.applicationUri = + config_register = UA_ServerConfig_new_minimal(16664, NULL); + UA_String_deleteMembers(&config_register->applicationDescription.applicationUri); + config_register->applicationDescription.applicationUri = UA_String_fromChars("urn:open62541.test.server_register"); - config_register.applicationDescription.applicationName.locale = UA_String_fromChars("de"); - config_register.applicationDescription.applicationName.text = UA_String_fromChars("Anmeldungsserver"); - config_register.mdnsServerName = UA_String_fromChars("Register_test"); - nl_register = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664); - config_register.networkLayers = &nl_register; - config_register.networkLayersSize = 1; + UA_LocalizedText_deleteMembers(&config_register->applicationDescription.applicationName); + config_register->applicationDescription.applicationName = + UA_LOCALIZEDTEXT_ALLOC("de", "Anmeldungsserver"); + config_register->mdnsServerName = UA_String_fromChars("Register_test"); server_register = UA_Server_new(config_register); UA_Server_run_startup(server_register); pthread_create(&server_thread_register, NULL, serverloop_register, NULL); @@ -125,11 +118,8 @@ static void teardown_register(void) { pthread_join(server_thread_register, NULL); UA_Server_run_shutdown(server_register); UA_Boolean_delete(running_register); - UA_String_deleteMembers(&server_register->config.applicationDescription.applicationUri); - UA_LocalizedText_deleteMembers(&server_register->config.applicationDescription.applicationName); - UA_String_deleteMembers(&server_register->config.mdnsServerName); UA_Server_delete(server_register); - nl_register.deleteMembers(&nl_register); + UA_ServerConfig_delete(config_register); } START_TEST(Server_register) { @@ -191,7 +181,7 @@ FindAndCheck(const UA_String expectedUris[], size_t expectedUrisSize, const UA_String expectedNames[], const char *filterUri, const char *filterLocale) { - UA_Client *client = UA_Client_new(UA_ClientConfig_standard); + UA_Client *client = UA_Client_new(UA_ClientConfig_default); UA_ApplicationDescription* applicationDescriptionArray = NULL; size_t applicationDescriptionArraySize = 0; @@ -257,7 +247,7 @@ static void FindOnNetworkAndCheck(UA_String expectedServerNames[], size_t expectedServerNamesSize, const char *filterUri, const char *filterLocale, const char** filterCapabilities, size_t filterCapabilitiesSize) { - UA_Client *client = UA_Client_new(UA_ClientConfig_standard); + UA_Client *client = UA_Client_new(UA_ClientConfig_default); UA_ServerOnNetwork* serverOnNetwork = NULL; size_t serverOnNetworkSize = 0; @@ -346,7 +336,7 @@ GetEndpoints(UA_Client *client, const UA_String* endpointUrl, static void GetEndpointsAndCheck(const char* discoveryUrl, const char* filterTransportProfileUri, const UA_String expectedEndpointUrls[], size_t expectedEndpointUrlsSize) { - UA_Client *client = UA_Client_new(UA_ClientConfig_standard); + UA_Client *client = UA_Client_new(UA_ClientConfig_default); ck_assert_uint_eq(UA_Client_connect(client, discoveryUrl), UA_STATUSCODE_GOOD); diff --git a/tests/check_server_binary_messages.c b/tests/check_server_binary_messages.c index 55533b3435a..d08cb1a1e3f 100644 --- a/tests/check_server_binary_messages.c +++ b/tests/check_server_binary_messages.c @@ -35,8 +35,7 @@ static UA_ByteString readFile(char *filename) { START_TEST(processMessage) { UA_Connection c = createDummyConnection(); - UA_ServerConfig config = UA_ServerConfig_standard; - config.logger = UA_Log_Stdout; + UA_ServerConfig *config = UA_ServerConfig_new_default(); UA_Server *server = UA_Server_new(config); for(size_t i = 0; i < files; i++) { UA_ByteString msg = readFile(filenames[i]); @@ -47,6 +46,7 @@ START_TEST(processMessage) { UA_ByteString_deleteMembers(&msg); } UA_Server_delete(server); + UA_ServerConfig_delete(config); UA_Connection_deleteMembers(&c); } END_TEST diff --git a/tests/check_server_jobs.c b/tests/check_server_jobs.c index 8e9f053c4a3..13a46b4c4c4 100644 --- a/tests/check_server_jobs.c +++ b/tests/check_server_jobs.c @@ -10,15 +10,18 @@ #include "testing_clock.h" UA_Server *server = NULL; +UA_ServerConfig *config = NULL; static void setup(void) { - server = UA_Server_new(UA_ServerConfig_standard); + config = UA_ServerConfig_new_default(); + server = UA_Server_new(config); UA_Server_run_startup(server); } static void teardown(void) { UA_Server_run_shutdown(server); UA_Server_delete(server); + UA_ServerConfig_delete(config); } UA_Boolean *executed; diff --git a/tests/check_server_readspeed.c b/tests/check_server_readspeed.c index a52014cd8b5..be643105a53 100644 --- a/tests/check_server_readspeed.c +++ b/tests/check_server_readspeed.c @@ -13,7 +13,7 @@ #include "ua_types_encoding_binary.h" int main(int argc, char** argv) { - UA_ServerConfig config = UA_ServerConfig_standard; + UA_ServerConfig *config = UA_ServerConfig_new_default(); UA_Server *server = UA_Server_new(config); /* add a variable node to the address space */ @@ -80,5 +80,6 @@ int main(int argc, char** argv) { UA_ByteString_deleteMembers(&request_msg); UA_ByteString_deleteMembers(&response_msg); UA_Server_delete(server); + UA_ServerConfig_delete(config); return (int)retval; } diff --git a/tests/check_server_userspace.c b/tests/check_server_userspace.c index dcbd1f6e736..b2297cd8d6a 100644 --- a/tests/check_server_userspace.c +++ b/tests/check_server_userspace.c @@ -15,9 +15,8 @@ #pragma clang diagnostic ignored "-Wincompatible-pointer-types-discards-qualifiers" #endif -START_TEST(Server_addNamespace_ShallWork) -{ - UA_ServerConfig config = UA_ServerConfig_standard; +START_TEST(Server_addNamespace_ShallWork) { + UA_ServerConfig *config = UA_ServerConfig_new_default(); UA_Server *server = UA_Server_new(config); UA_UInt16 a = UA_Server_addNamespace(server, "http://nameOfNamespace"); @@ -29,12 +28,12 @@ START_TEST(Server_addNamespace_ShallWork) ck_assert_uint_ne(a,c); UA_Server_delete(server); + UA_ServerConfig_delete(config); } END_TEST -START_TEST(Server_addNamespace_writeService) -{ - UA_ServerConfig config = UA_ServerConfig_standard; +START_TEST(Server_addNamespace_writeService) { + UA_ServerConfig *config = UA_ServerConfig_new_default(); UA_Server *server = UA_Server_new(config); UA_Variant namespaces; @@ -63,6 +62,7 @@ START_TEST(Server_addNamespace_writeService) UA_Variant_deleteMembers(&namespaces); UA_Server_delete(server); + UA_ServerConfig_delete(config); } END_TEST diff --git a/tests/check_services_attributes.c b/tests/check_services_attributes.c index 277f9cf85d5..ad06c1237b3 100644 --- a/tests/check_services_attributes.c +++ b/tests/check_services_attributes.c @@ -20,6 +20,9 @@ #pragma clang diagnostic ignored "-Wincompatible-pointer-types-discards-qualifiers" #endif +static UA_Server *server = NULL; +static UA_ServerConfig *config = NULL; + static UA_StatusCode readCPUTemperature(void *handle, const UA_NodeId nodeid, UA_Boolean sourceTimeStamp, const UA_NumericRange *range, UA_DataValue *dataValue) { @@ -29,9 +32,14 @@ readCPUTemperature(void *handle, const UA_NodeId nodeid, UA_Boolean sourceTimeSt return UA_STATUSCODE_GOOD; } -static UA_Server * -makeTestSequence(void) { - UA_Server * server = UA_Server_new(UA_ServerConfig_standard); +static void teardown(void) { + UA_Server_delete(server); + UA_ServerConfig_delete(config); +} + +static void setup(void) { + config = UA_ServerConfig_new_default(); + server = UA_Server_new(config); UA_StatusCode retval = UA_STATUSCODE_GOOD; /* VariableNode */ @@ -119,8 +127,6 @@ makeTestSequence(void) { NULL, NULL, 0, NULL, 0, NULL, NULL); ck_assert_int_eq(retval, UA_STATUSCODE_GOOD); #endif - - return server; } static UA_VariableNode* makeCompareSequence(void) { @@ -144,8 +150,6 @@ static UA_VariableNode* makeCompareSequence(void) { } START_TEST(ReadSingleAttributeValueWithoutTimestamp) { - UA_Server *server = makeTestSequence(); - UA_ReadValueId rvi; UA_ReadValueId_init(&rvi); rvi.nodeId = UA_NODEID_STRING(1, "the.answer"); @@ -157,13 +161,10 @@ START_TEST(ReadSingleAttributeValueWithoutTimestamp) { ck_assert_int_eq(0, resp.value.arrayLength); ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_INT32], resp.value.type); ck_assert_int_eq(42, *(UA_Int32* )resp.value.data); - UA_Server_delete(server); UA_DataValue_deleteMembers(&resp); } END_TEST START_TEST(ReadSingleAttributeValueRangeWithoutTimestamp) { - UA_Server *server = makeTestSequence(); - UA_ReadValueId rvi; UA_ReadValueId_init(&rvi); rvi.nodeId = UA_NODEID_STRING(1, "myarray"); @@ -174,13 +175,10 @@ START_TEST(ReadSingleAttributeValueRangeWithoutTimestamp) { ck_assert_int_eq(4, resp.value.arrayLength); ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_INT32], resp.value.type); - UA_Server_delete(server); UA_DataValue_deleteMembers(&resp); } END_TEST START_TEST(ReadSingleAttributeNodeIdWithoutTimestamp) { - UA_Server *server = makeTestSequence(); - UA_ReadValueId rvi; UA_ReadValueId_init(&rvi); rvi.nodeId = UA_NODEID_STRING(1, "the.answer"); @@ -195,12 +193,9 @@ START_TEST(ReadSingleAttributeNodeIdWithoutTimestamp) { ck_assert_int_eq(1, respval->namespaceIndex); ck_assert(UA_String_equal(&myIntegerNodeId.identifier.string, &respval->identifier.string)); UA_DataValue_deleteMembers(&resp); - UA_Server_delete(server); } END_TEST START_TEST(ReadSingleAttributeNodeClassWithoutTimestamp) { - UA_Server *server = makeTestSequence(); - UA_ReadValueId rvi; UA_ReadValueId_init(&rvi); rvi.nodeId = UA_NODEID_STRING(1, "the.answer"); @@ -212,12 +207,9 @@ START_TEST(ReadSingleAttributeNodeClassWithoutTimestamp) { ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_NODECLASS],resp.value.type); ck_assert_int_eq(*(UA_Int32*)resp.value.data,UA_NODECLASS_VARIABLE); UA_DataValue_deleteMembers(&resp); - UA_Server_delete(server); } END_TEST START_TEST(ReadSingleAttributeBrowseNameWithoutTimestamp) { - UA_Server *server = makeTestSequence(); - UA_ReadValueId rvi; UA_ReadValueId_init(&rvi); rvi.nodeId = UA_NODEID_STRING(1, "the.answer"); @@ -232,12 +224,9 @@ START_TEST(ReadSingleAttributeBrowseNameWithoutTimestamp) { ck_assert_int_eq(1, respval->namespaceIndex); ck_assert(UA_String_equal(&myIntegerName.name, &respval->name)); UA_DataValue_deleteMembers(&resp); - UA_Server_delete(server); } END_TEST START_TEST(ReadSingleAttributeDisplayNameWithoutTimestamp) { - UA_Server *server = makeTestSequence(); - UA_ReadValueId rvi; UA_ReadValueId_init(&rvi); rvi.nodeId = UA_NODEID_STRING(1, "the.answer"); @@ -252,14 +241,11 @@ START_TEST(ReadSingleAttributeDisplayNameWithoutTimestamp) { ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_LOCALIZEDTEXT], resp.value.type); ck_assert(UA_String_equal(&comp.text, &respval->text)); ck_assert(UA_String_equal(&compNode->displayName.locale, &respval->locale)); - UA_Server_delete(server); UA_DataValue_deleteMembers(&resp); UA_NodeStore_deleteNode((UA_Node*)compNode); } END_TEST START_TEST(ReadSingleAttributeDescriptionWithoutTimestamp) { - UA_Server *server = makeTestSequence(); - UA_ReadValueId rvi; UA_ReadValueId_init(&rvi); rvi.nodeId = UA_NODEID_STRING(1, "the.answer"); @@ -275,12 +261,9 @@ START_TEST(ReadSingleAttributeDescriptionWithoutTimestamp) { ck_assert(UA_String_equal(&compNode->description.text, &respval->text)); UA_DataValue_deleteMembers(&resp); UA_NodeStore_deleteNode((UA_Node*)compNode); - UA_Server_delete(server); } END_TEST START_TEST(ReadSingleAttributeWriteMaskWithoutTimestamp) { - UA_Server *server = makeTestSequence(); - UA_ReadValueId rvi; UA_ReadValueId_init(&rvi); rvi.nodeId = UA_NODEID_STRING(1, "the.answer"); @@ -293,12 +276,9 @@ START_TEST(ReadSingleAttributeWriteMaskWithoutTimestamp) { ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_UINT32], resp.value.type); ck_assert_int_eq(0,*respval); UA_DataValue_deleteMembers(&resp); - UA_Server_delete(server); } END_TEST START_TEST(ReadSingleAttributeUserWriteMaskWithoutTimestamp) { - UA_Server *server = makeTestSequence(); - UA_ReadValueId rvi; UA_ReadValueId_init(&rvi); rvi.nodeId = UA_NODEID_STRING(1, "the.answer"); @@ -312,12 +292,9 @@ START_TEST(ReadSingleAttributeUserWriteMaskWithoutTimestamp) { /* ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_UINT32], resp.value.type); */ /* ck_assert_int_eq(0,*respval); */ UA_DataValue_deleteMembers(&resp); - UA_Server_delete(server); } END_TEST START_TEST(ReadSingleAttributeIsAbstractWithoutTimestamp) { - UA_Server *server = makeTestSequence(); - UA_ReadValueId rvi; UA_ReadValueId_init(&rvi); rvi.nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES); @@ -329,12 +306,9 @@ START_TEST(ReadSingleAttributeIsAbstractWithoutTimestamp) { ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BOOLEAN], resp.value.type); ck_assert(*(UA_Boolean* )resp.value.data==false); UA_DataValue_deleteMembers(&resp); - UA_Server_delete(server); } END_TEST START_TEST(ReadSingleAttributeSymmetricWithoutTimestamp) { - UA_Server *server = makeTestSequence(); - UA_ReadValueId rvi; UA_ReadValueId_init(&rvi); rvi.nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES); @@ -346,12 +320,9 @@ START_TEST(ReadSingleAttributeSymmetricWithoutTimestamp) { ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BOOLEAN], resp.value.type); ck_assert(*(UA_Boolean* )resp.value.data==false); UA_DataValue_deleteMembers(&resp); - UA_Server_delete(server); } END_TEST START_TEST(ReadSingleAttributeInverseNameWithoutTimestamp) { - UA_Server *server = makeTestSequence(); - UA_ReadValueId rvi; UA_ReadValueId_init(&rvi); rvi.nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES); @@ -366,12 +337,9 @@ START_TEST(ReadSingleAttributeInverseNameWithoutTimestamp) { ck_assert(UA_String_equal(&comp.text, &respval->text)); ck_assert(UA_String_equal(&comp.locale, &respval->locale)); UA_DataValue_deleteMembers(&resp); - UA_Server_delete(server); } END_TEST START_TEST(ReadSingleAttributeContainsNoLoopsWithoutTimestamp) { - UA_Server *server = makeTestSequence(); - UA_ReadValueId rvi; UA_ReadValueId_init(&rvi); rvi.nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_VIEWNODE); @@ -383,12 +351,9 @@ START_TEST(ReadSingleAttributeContainsNoLoopsWithoutTimestamp) { ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BOOLEAN], resp.value.type); ck_assert(*(UA_Boolean* )resp.value.data==false); UA_DataValue_deleteMembers(&resp); - UA_Server_delete(server); } END_TEST START_TEST(ReadSingleAttributeEventNotifierWithoutTimestamp) { - UA_Server *server = makeTestSequence(); - UA_ReadValueId rvi; UA_ReadValueId_init(&rvi); rvi.nodeId = UA_NODEID_NUMERIC(1, 50); @@ -401,12 +366,9 @@ START_TEST(ReadSingleAttributeEventNotifierWithoutTimestamp) { ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BYTE],resp.value.type); ck_assert_int_eq(*(UA_Byte*)resp.value.data, 0); UA_DataValue_deleteMembers(&resp); - UA_Server_delete(server); } END_TEST START_TEST(ReadSingleAttributeDataTypeWithoutTimestamp) { - UA_Server *server = makeTestSequence(); - UA_ReadValueId rvi; UA_ReadValueId_init(&rvi); rvi.nodeId = UA_NODEID_STRING(1, "the.answer"); @@ -422,12 +384,9 @@ START_TEST(ReadSingleAttributeDataTypeWithoutTimestamp) { ck_assert_int_eq(respval->namespaceIndex,0); ck_assert_int_eq(respval->identifier.numeric, UA_NS0ID_BASEDATATYPE); UA_DataValue_deleteMembers(&resp); - UA_Server_delete(server); } END_TEST START_TEST(ReadSingleAttributeValueRankWithoutTimestamp) { - UA_Server *server = makeTestSequence(); - UA_ReadValueId rvi; UA_ReadValueId_init(&rvi); rvi.nodeId = UA_NODEID_STRING(1, "the.answer"); @@ -439,12 +398,9 @@ START_TEST(ReadSingleAttributeValueRankWithoutTimestamp) { ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_INT32], resp.value.type); ck_assert_int_eq(-2, *(UA_Int32* )resp.value.data); UA_DataValue_deleteMembers(&resp); - UA_Server_delete(server); } END_TEST START_TEST(ReadSingleAttributeArrayDimensionsWithoutTimestamp) { - UA_Server *server = makeTestSequence(); - UA_ReadValueId rvi; UA_ReadValueId_init(&rvi); rvi.nodeId = UA_NODEID_STRING(1, "the.answer"); @@ -456,12 +412,9 @@ START_TEST(ReadSingleAttributeArrayDimensionsWithoutTimestamp) { ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_UINT32], resp.value.type); ck_assert_ptr_eq((UA_Int32*)resp.value.data,0); UA_DataValue_deleteMembers(&resp); - UA_Server_delete(server); } END_TEST START_TEST(ReadSingleAttributeAccessLevelWithoutTimestamp) { - UA_Server *server = makeTestSequence(); - UA_ReadValueId rvi; UA_ReadValueId_init(&rvi); rvi.nodeId = UA_NODEID_STRING(1, "the.answer"); @@ -473,12 +426,9 @@ START_TEST(ReadSingleAttributeAccessLevelWithoutTimestamp) { ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BYTE], resp.value.type); ck_assert_int_eq(*(UA_Byte*)resp.value.data, UA_ACCESSLEVELMASK_READ); // set by default UA_DataValue_deleteMembers(&resp); - UA_Server_delete(server); } END_TEST START_TEST(ReadSingleAttributeUserAccessLevelWithoutTimestamp) { - UA_Server *server = makeTestSequence(); - UA_ReadValueId rvi; UA_ReadValueId_init(&rvi); rvi.nodeId = UA_NODEID_STRING(1, "the.answer"); @@ -494,13 +444,10 @@ START_TEST(ReadSingleAttributeUserAccessLevelWithoutTimestamp) { /* ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BYTE], resp.value.type); */ /* ck_assert_int_eq(*(UA_Byte*)resp.value.data, compNode->accessLevel & 0xFF); // 0xFF is the default userAccessLevel */ /* UA_RCU_UNLOCK(); */ - UA_Server_delete(server); UA_DataValue_deleteMembers(&resp); } END_TEST START_TEST(ReadSingleAttributeMinimumSamplingIntervalWithoutTimestamp) { - UA_Server *server = makeTestSequence(); - UA_ReadValueId rvi; UA_ReadValueId_init(&rvi); rvi.nodeId = UA_NODEID_STRING(1, "the.answer"); @@ -516,12 +463,9 @@ START_TEST(ReadSingleAttributeMinimumSamplingIntervalWithoutTimestamp) { ck_assert(*respval == comp); UA_DataValue_deleteMembers(&resp); UA_NodeStore_deleteNode((UA_Node*)compNode); - UA_Server_delete(server); } END_TEST START_TEST(ReadSingleAttributeHistorizingWithoutTimestamp) { - UA_Server *server = makeTestSequence(); - UA_ReadValueId rvi; UA_ReadValueId_init(&rvi); rvi.nodeId = UA_NODEID_STRING(1, "the.answer"); @@ -533,12 +477,9 @@ START_TEST(ReadSingleAttributeHistorizingWithoutTimestamp) { ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BOOLEAN], resp.value.type); ck_assert(*(UA_Boolean*)resp.value.data==false); UA_DataValue_deleteMembers(&resp); - UA_Server_delete(server); } END_TEST START_TEST(ReadSingleAttributeExecutableWithoutTimestamp) { - UA_Server *server = makeTestSequence(); - #ifdef UA_ENABLE_METHODCALLS UA_ReadValueId rvi; UA_ReadValueId_init(&rvi); @@ -553,14 +494,10 @@ START_TEST(ReadSingleAttributeExecutableWithoutTimestamp) { ck_assert(*(UA_Boolean*)resp.value.data==false); UA_DataValue_deleteMembers(&resp); #endif - - UA_Server_delete(server); } END_TEST START_TEST(ReadSingleAttributeUserExecutableWithoutTimestamp) { #ifdef UA_ENABLE_METHODCALLS - UA_Server *server = makeTestSequence(); - UA_ReadValueId rvi; UA_ReadValueId_init(&rvi); rvi.nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_METHODNODE); @@ -573,13 +510,10 @@ START_TEST(ReadSingleAttributeUserExecutableWithoutTimestamp) { /* ck_assert_ptr_eq(&UA_TYPES[UA_TYPES_BOOLEAN], resp.value.type); */ /* ck_assert(*(UA_Boolean*)resp.value.data==false); */ UA_DataValue_deleteMembers(&resp); - UA_Server_delete(server); #endif } END_TEST START_TEST(ReadSingleDataSourceAttributeValueWithoutTimestamp) { - UA_Server *server = makeTestSequence(); - UA_ReadValueId rvi; UA_ReadValueId_init(&rvi); rvi.nodeId = UA_NODEID_STRING(1, "cpu.temperature"); @@ -588,13 +522,10 @@ START_TEST(ReadSingleDataSourceAttributeValueWithoutTimestamp) { UA_DataValue resp = UA_Server_read(server, &rvi, UA_TIMESTAMPSTORETURN_NEITHER); ck_assert_int_eq(UA_STATUSCODE_GOOD, resp.status); - UA_Server_delete(server); UA_DataValue_deleteMembers(&resp); } END_TEST START_TEST(ReadSingleDataSourceAttributeDataTypeWithoutTimestamp) { - UA_Server *server = makeTestSequence(); - UA_ReadValueId rvi; UA_ReadValueId_init(&rvi); rvi.nodeId = UA_NODEID_STRING(1, "cpu.temperature"); @@ -604,13 +535,10 @@ START_TEST(ReadSingleDataSourceAttributeDataTypeWithoutTimestamp) { ck_assert_int_eq(UA_STATUSCODE_GOOD, resp.status); ck_assert_int_eq(resp.hasServerTimestamp, false); - UA_Server_delete(server); UA_DataValue_deleteMembers(&resp); } END_TEST START_TEST (ReadSingleDataSourceAttributeArrayDimensionsWithoutTimestamp) { - UA_Server *server = makeTestSequence(); - UA_ReadValueId rvi; UA_ReadValueId_init(&rvi); rvi.nodeId = UA_NODEID_STRING(1, "cpu.temperature"); @@ -619,14 +547,12 @@ START_TEST (ReadSingleDataSourceAttributeArrayDimensionsWithoutTimestamp) { UA_DataValue resp = UA_Server_read(server, &rvi, UA_TIMESTAMPSTORETURN_NEITHER); ck_assert_int_eq(UA_STATUSCODE_GOOD, resp.status); - UA_Server_delete(server); UA_DataValue_deleteMembers(&resp); } END_TEST /* Tests for writeValue method */ START_TEST(WriteSingleAttributeNodeId) { - UA_Server *server = makeTestSequence(); UA_WriteValue wValue; UA_WriteValue_init(&wValue); UA_NodeId id; @@ -637,11 +563,9 @@ START_TEST(WriteSingleAttributeNodeId) { UA_Variant_setScalar(&wValue.value.value, &id, &UA_TYPES[UA_TYPES_NODEID]); UA_StatusCode retval = UA_Server_write(server, &wValue); ck_assert_int_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED); - UA_Server_delete(server); } END_TEST START_TEST(WriteSingleAttributeNodeclass) { - UA_Server *server = makeTestSequence(); UA_WriteValue wValue; UA_WriteValue_init(&wValue); wValue.nodeId = UA_NODEID_STRING(1, "the.answer"); @@ -652,11 +576,9 @@ START_TEST(WriteSingleAttributeNodeclass) { UA_Variant_setScalar(&wValue.value.value, &nc, &UA_TYPES[UA_TYPES_NODECLASS]); UA_StatusCode retval = UA_Server_write(server, &wValue); ck_assert_int_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED); - UA_Server_delete(server); } END_TEST START_TEST(WriteSingleAttributeBrowseName) { - UA_Server *server = makeTestSequence(); UA_WriteValue wValue; UA_WriteValue_init(&wValue); UA_QualifiedName testValue = UA_QUALIFIEDNAME(1, "the.answer"); @@ -666,11 +588,9 @@ START_TEST(WriteSingleAttributeBrowseName) { wValue.value.hasValue = true; UA_StatusCode retval = UA_Server_write(server, &wValue); ck_assert_int_eq(retval, UA_STATUSCODE_GOOD); - UA_Server_delete(server); } END_TEST START_TEST(WriteSingleAttributeDisplayName) { - UA_Server *server = makeTestSequence(); UA_WriteValue wValue; UA_WriteValue_init(&wValue); UA_LocalizedText testValue = UA_LOCALIZEDTEXT("en_EN", "the.answer"); @@ -680,11 +600,9 @@ START_TEST(WriteSingleAttributeDisplayName) { wValue.attributeId = UA_ATTRIBUTEID_DISPLAYNAME; UA_StatusCode retval = UA_Server_write(server, &wValue); ck_assert_int_eq(retval, UA_STATUSCODE_GOOD); - UA_Server_delete(server); } END_TEST START_TEST(WriteSingleAttributeDescription) { - UA_Server *server = makeTestSequence(); UA_WriteValue wValue; UA_WriteValue_init(&wValue); UA_LocalizedText testValue = UA_LOCALIZEDTEXT("en_EN", "the.answer"); @@ -696,11 +614,9 @@ START_TEST(WriteSingleAttributeDescription) { wValue.value.hasValue = true; UA_StatusCode retval = UA_Server_write(server, &wValue); ck_assert_int_eq(retval, UA_STATUSCODE_GOOD); - UA_Server_delete(server); } END_TEST START_TEST(WriteSingleAttributeWriteMask) { - UA_Server *server = makeTestSequence(); UA_WriteValue wValue; UA_WriteValue_init(&wValue); UA_Int32 testValue = 0; @@ -711,11 +627,9 @@ START_TEST(WriteSingleAttributeWriteMask) { wValue.value.hasValue = true; UA_StatusCode retval = UA_Server_write(server, &wValue); ck_assert_int_eq(retval, UA_STATUSCODE_GOOD); - UA_Server_delete(server); } END_TEST START_TEST(WriteSingleAttributeIsAbstract) { - UA_Server *server = makeTestSequence(); UA_WriteValue wValue; UA_WriteValue_init(&wValue); UA_Boolean testValue = true; @@ -725,11 +639,9 @@ START_TEST(WriteSingleAttributeIsAbstract) { wValue.value.hasValue = true; UA_StatusCode retval = UA_Server_write(server, &wValue); ck_assert_int_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID); - UA_Server_delete(server); } END_TEST START_TEST(WriteSingleAttributeSymmetric) { - UA_Server *server = makeTestSequence(); UA_WriteValue wValue; UA_WriteValue_init(&wValue); UA_Boolean testValue = true; @@ -739,11 +651,9 @@ START_TEST(WriteSingleAttributeSymmetric) { wValue.value.hasValue = true; UA_StatusCode retval = UA_Server_write(server, &wValue); ck_assert_int_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID); - UA_Server_delete(server); } END_TEST START_TEST(WriteSingleAttributeInverseName) { - UA_Server *server = makeTestSequence(); UA_WriteValue wValue; UA_WriteValue_init(&wValue); UA_LocalizedText testValue = UA_LOCALIZEDTEXT("en_US", "not.the.answer"); @@ -753,11 +663,9 @@ START_TEST(WriteSingleAttributeInverseName) { wValue.value.hasValue = true; UA_StatusCode retval = UA_Server_write(server, &wValue); ck_assert_int_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID); - UA_Server_delete(server); } END_TEST START_TEST(WriteSingleAttributeContainsNoLoops) { - UA_Server *server = makeTestSequence(); UA_WriteValue wValue; UA_WriteValue_init(&wValue); UA_Boolean testValue = true; @@ -767,11 +675,9 @@ START_TEST(WriteSingleAttributeContainsNoLoops) { wValue.value.hasValue = true; UA_StatusCode retval = UA_Server_write(server, &wValue); ck_assert_int_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID); - UA_Server_delete(server); } END_TEST START_TEST(WriteSingleAttributeEventNotifier) { - UA_Server *server = makeTestSequence(); UA_WriteValue wValue; UA_WriteValue_init(&wValue); UA_Byte testValue = 0; @@ -781,11 +687,9 @@ START_TEST(WriteSingleAttributeEventNotifier) { wValue.value.hasValue = true; UA_StatusCode retval = UA_Server_write(server, &wValue); ck_assert_int_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID); - UA_Server_delete(server); } END_TEST START_TEST(WriteSingleAttributeValue) { - UA_Server *server = makeTestSequence(); UA_WriteValue wValue; UA_WriteValue_init(&wValue); UA_Int32 myInteger = 20; @@ -806,11 +710,9 @@ START_TEST(WriteSingleAttributeValue) { ck_assert(resp.hasValue); ck_assert_int_eq(20, *(UA_Int32*)resp.value.data); UA_DataValue_deleteMembers(&resp); - UA_Server_delete(server); } END_TEST START_TEST(WriteSingleAttributeValueRangeFromScalar) { - UA_Server *server = makeTestSequence(); UA_WriteValue wValue; UA_WriteValue_init(&wValue); UA_Int32 myInteger = 20; @@ -821,11 +723,9 @@ START_TEST(WriteSingleAttributeValueRangeFromScalar) { wValue.attributeId = UA_ATTRIBUTEID_VALUE; UA_StatusCode retval = UA_Server_write(server, &wValue); ck_assert_int_eq(retval, UA_STATUSCODE_GOOD); - UA_Server_delete(server); } END_TEST START_TEST(WriteSingleAttributeValueRangeFromArray) { - UA_Server *server = makeTestSequence(); UA_WriteValue wValue; UA_WriteValue_init(&wValue); UA_Int32 myInteger = 20; @@ -836,11 +736,9 @@ START_TEST(WriteSingleAttributeValueRangeFromArray) { wValue.attributeId = UA_ATTRIBUTEID_VALUE; UA_StatusCode retval = UA_Server_write(server, &wValue); ck_assert_int_eq(retval, UA_STATUSCODE_GOOD); - UA_Server_delete(server); } END_TEST START_TEST(WriteSingleAttributeDataType) { - UA_Server *server = makeTestSequence(); UA_WriteValue wValue; UA_WriteValue_init(&wValue); UA_NodeId typeId; @@ -851,11 +749,9 @@ START_TEST(WriteSingleAttributeDataType) { UA_Variant_setScalar(&wValue.value.value, &typeId, &UA_TYPES[UA_TYPES_NODEID]); UA_StatusCode retval = UA_Server_write(server, &wValue); ck_assert_int_eq(retval, UA_STATUSCODE_BADTYPEMISMATCH); - UA_Server_delete(server); } END_TEST START_TEST(WriteSingleAttributeValueRank) { - UA_Server *server = makeTestSequence(); UA_WriteValue wValue; UA_WriteValue_init(&wValue); UA_Int32 testValue = -1; @@ -866,11 +762,9 @@ START_TEST(WriteSingleAttributeValueRank) { UA_StatusCode retval = UA_Server_write(server, &wValue); // Returns attributeInvalid, since variant/value may be writable ck_assert_int_eq(retval, UA_STATUSCODE_GOOD); - UA_Server_delete(server); } END_TEST START_TEST(WriteSingleAttributeArrayDimensions) { - UA_Server *server = makeTestSequence(); UA_WriteValue wValue; UA_WriteValue_init(&wValue); UA_UInt32 testValue[] = {1,1,1}; @@ -881,11 +775,9 @@ START_TEST(WriteSingleAttributeArrayDimensions) { UA_StatusCode retval = UA_Server_write(server, &wValue); // Returns attributeInvalid, since variant/value may be writable ck_assert_int_eq(retval, UA_STATUSCODE_BADTYPEMISMATCH); - UA_Server_delete(server); } END_TEST START_TEST(WriteSingleAttributeAccessLevel) { - UA_Server *server = makeTestSequence(); UA_WriteValue wValue; UA_WriteValue_init(&wValue); UA_Byte testValue = 0; @@ -895,11 +787,9 @@ START_TEST(WriteSingleAttributeAccessLevel) { wValue.value.hasValue = true; UA_StatusCode retval = UA_Server_write(server, &wValue); ck_assert_int_eq(retval, UA_STATUSCODE_GOOD); - UA_Server_delete(server); } END_TEST START_TEST(WriteSingleAttributeMinimumSamplingInterval) { - UA_Server *server = makeTestSequence(); UA_WriteValue wValue; UA_WriteValue_init(&wValue); UA_Double testValue = 0.0; @@ -909,11 +799,9 @@ START_TEST(WriteSingleAttributeMinimumSamplingInterval) { wValue.value.hasValue = true; UA_StatusCode retval = UA_Server_write(server, &wValue); ck_assert_int_eq(retval, UA_STATUSCODE_GOOD); - UA_Server_delete(server); } END_TEST START_TEST(WriteSingleAttributeHistorizing) { - UA_Server *server = makeTestSequence(); UA_WriteValue wValue; UA_WriteValue_init(&wValue); UA_Boolean testValue = true; @@ -923,11 +811,9 @@ START_TEST(WriteSingleAttributeHistorizing) { wValue.value.hasValue = true; UA_StatusCode retval = UA_Server_write(server, &wValue); ck_assert_int_eq(retval, UA_STATUSCODE_GOOD); - UA_Server_delete(server); } END_TEST START_TEST(WriteSingleAttributeExecutable) { - UA_Server *server = makeTestSequence(); UA_WriteValue wValue; UA_WriteValue_init(&wValue); UA_Boolean testValue = true; @@ -937,11 +823,9 @@ START_TEST(WriteSingleAttributeExecutable) { wValue.value.hasValue = true; UA_StatusCode retval = UA_Server_write(server, &wValue); ck_assert_int_eq(retval, UA_STATUSCODE_BADNODECLASSINVALID); - UA_Server_delete(server); } END_TEST START_TEST(WriteSingleDataSourceAttributeValue) { - UA_Server *server = makeTestSequence(); UA_WriteValue wValue; UA_WriteValue_init(&wValue); UA_Int32 testValue = 0; @@ -951,13 +835,13 @@ START_TEST(WriteSingleDataSourceAttributeValue) { wValue.value.hasValue = true; UA_StatusCode retval = UA_Server_write(server, &wValue); ck_assert_int_eq(retval, UA_STATUSCODE_BADWRITENOTSUPPORTED); - UA_Server_delete(server); } END_TEST static Suite * testSuite_services_attributes(void) { Suite *s = suite_create("services_attributes_read"); TCase *tc_readSingleAttributes = tcase_create("readSingleAttributes"); + tcase_add_checked_fixture(tc_readSingleAttributes, setup, teardown); tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeValueWithoutTimestamp); tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeValueRangeWithoutTimestamp); tcase_add_test(tc_readSingleAttributes, ReadSingleAttributeNodeIdWithoutTimestamp); @@ -988,6 +872,7 @@ static Suite * testSuite_services_attributes(void) { suite_add_tcase(s, tc_readSingleAttributes); TCase *tc_writeSingleAttributes = tcase_create("writeSingleAttributes"); + tcase_add_checked_fixture(tc_writeSingleAttributes, setup, teardown); tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeNodeId); tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeNodeclass); tcase_add_test(tc_writeSingleAttributes, WriteSingleAttributeBrowseName); diff --git a/tests/check_services_nodemanagement.c b/tests/check_services_nodemanagement.c index 8893b71574a..64e5bb1bdc9 100644 --- a/tests/check_services_nodemanagement.c +++ b/tests/check_services_nodemanagement.c @@ -19,14 +19,25 @@ #include #endif +static UA_Server *server = NULL; +static UA_ServerConfig *config = NULL; + +static void setup(void) { + config = UA_ServerConfig_new_default(); + server = UA_Server_new(config); +} + +static void teardown(void) { + UA_Server_delete(server); + UA_ServerConfig_delete(config); +} + static UA_StatusCode instantiationMethod(UA_NodeId newNodeId, UA_NodeId templateId, void *handle ) { *((UA_Int32 *) handle) += 1; return UA_STATUSCODE_GOOD; } START_TEST(AddVariableNode) { - UA_Server *server = UA_Server_new(UA_ServerConfig_standard); - /* add a variable node to the address space */ UA_VariableAttributes attr; UA_VariableAttributes_init(&attr); @@ -41,12 +52,9 @@ START_TEST(AddVariableNode) { UA_StatusCode res = UA_Server_addVariableNode(server, myIntegerNodeId, parentNodeId, parentReferenceNodeId, myIntegerName, UA_NODEID_NULL, attr, NULL, NULL); ck_assert_int_eq(UA_STATUSCODE_GOOD, res); - UA_Server_delete(server); } END_TEST START_TEST(AddComplexTypeWithInheritance) { - UA_Server *server = UA_Server_new(UA_ServerConfig_standard); - /* add a variable node to the address space */ UA_ObjectAttributes attr; UA_ObjectAttributes_init(&attr); @@ -61,15 +69,13 @@ START_TEST(AddComplexTypeWithInheritance) { UA_InstantiationCallback iCallback = {.method=instantiationMethod, .handle = (void *) &handleCalled}; UA_StatusCode res = UA_Server_addObjectNode(server, myObjectNodeId, parentNodeId, parentReferenceNodeId, - myObjectName, UA_NODEID_NUMERIC(0, 2004), attr, &iCallback, NULL); + myObjectName, UA_NODEID_NUMERIC(0, 2004), + attr, &iCallback, NULL); ck_assert_int_eq(UA_STATUSCODE_GOOD, res); ck_assert_int_gt(handleCalled, 0); // Should be 58, but may depend on NS0 XML detail - UA_Server_delete(server); } END_TEST START_TEST(AddNodeTwiceGivesError) { - UA_Server *server = UA_Server_new(UA_ServerConfig_standard); - /* add a variable node to the address space */ UA_VariableAttributes attr; UA_VariableAttributes_init(&attr); @@ -87,7 +93,6 @@ START_TEST(AddNodeTwiceGivesError) { res = UA_Server_addVariableNode(server, myIntegerNodeId, parentNodeId, parentReferenceNodeId, myIntegerName, UA_NODEID_NULL, attr, NULL, NULL); ck_assert_int_eq(res, UA_STATUSCODE_BADNODEIDEXISTS); - UA_Server_delete(server); } END_TEST static UA_Boolean constructorCalled = false; @@ -98,8 +103,6 @@ static void * objectConstructor(const UA_NodeId instance) { } START_TEST(AddObjectWithConstructor) { - UA_Server *server = UA_Server_new(UA_ServerConfig_standard); - /* Add an object type */ UA_NodeId objecttypeid = UA_NODEID_NUMERIC(0, 13371337); UA_ObjectTypeAttributes attr; @@ -127,8 +130,6 @@ START_TEST(AddObjectWithConstructor) { /* Verify that the constructor was called */ ck_assert_int_eq(constructorCalled, true); - - UA_Server_delete(server); } END_TEST static UA_Boolean destructorCalled = false; @@ -138,8 +139,6 @@ static void objectDestructor(const UA_NodeId instance, void *handle) { } START_TEST(DeleteObjectWithDestructor) { - UA_Server *server = UA_Server_new(UA_ServerConfig_standard); - /* Add an object type */ UA_NodeId objecttypeid = UA_NODEID_NUMERIC(0, 13371337); UA_ObjectTypeAttributes attr; @@ -171,13 +170,9 @@ START_TEST(DeleteObjectWithDestructor) { /* Verify that the destructor was called */ ck_assert_int_eq(destructorCalled, true); - - UA_Server_delete(server); } END_TEST START_TEST(DeleteObjectAndReferences) { - UA_Server *server = UA_Server_new(UA_ServerConfig_standard); - /* Add an object of the type */ UA_ObjectAttributes attr; UA_ObjectAttributes_init(&attr); @@ -239,15 +234,11 @@ START_TEST(DeleteObjectAndReferences) { } ck_assert_int_eq(refCount, 1); UA_BrowseResult_deleteMembers(&br); - - UA_Server_delete(server); } END_TEST /* Example taken from tutorial_server_object.c */ START_TEST(InstantiateObjectType) { - UA_Server *server = UA_Server_new(UA_ServerConfig_standard); - /* Define the object type */ UA_NodeId pumpTypeId = {1, UA_NODEIDTYPE_NUMERIC, {1001}}; @@ -338,14 +329,13 @@ START_TEST(InstantiateObjectType) { identifier */ oAttr, NULL, NULL); ck_assert_int_eq(retval, UA_STATUSCODE_GOOD); - - UA_Server_delete(server); } END_TEST int main(void) { Suite *s = suite_create("services_nodemanagement"); TCase *tc_addnodes = tcase_create("addnodes"); + tcase_add_checked_fixture(tc_addnodes, setup, teardown); tcase_add_test(tc_addnodes, AddVariableNode); tcase_add_test(tc_addnodes, AddComplexTypeWithInheritance); tcase_add_test(tc_addnodes, AddNodeTwiceGivesError); @@ -353,6 +343,7 @@ int main(void) { tcase_add_test(tc_addnodes, InstantiateObjectType); TCase *tc_deletenodes = tcase_create("deletenodes"); + tcase_add_checked_fixture(tc_deletenodes, setup, teardown); tcase_add_test(tc_deletenodes, DeleteObjectWithDestructor); tcase_add_test(tc_deletenodes, DeleteObjectAndReferences); diff --git a/tests/check_services_subscriptions.c b/tests/check_services_subscriptions.c index 704ebb0cc0b..02776167ede 100644 --- a/tests/check_services_subscriptions.c +++ b/tests/check_services_subscriptions.c @@ -11,16 +11,19 @@ #include "check.h" #include "testing_clock.h" -UA_Server *server = NULL; +static UA_Server *server = NULL; +static UA_ServerConfig *config = NULL; static void setup(void) { - server = UA_Server_new(UA_ServerConfig_standard); + config = UA_ServerConfig_new_default(); + server = UA_Server_new(config); UA_Server_run_startup(server); } static void teardown(void) { UA_Server_run_shutdown(server); UA_Server_delete(server); + UA_ServerConfig_delete(config); } UA_UInt32 subscriptionId; diff --git a/tests/check_services_view.c b/tests/check_services_view.c index fc52ee8e07f..b1ac80b9c13 100644 --- a/tests/check_services_view.c +++ b/tests/check_services_view.c @@ -13,8 +13,8 @@ #include "ua_network_tcp.h" UA_Server *server_translate_browse; +UA_ServerConfig *server_translate_config; UA_Boolean *running_translate_browse; -UA_ServerNetworkLayer nl_translate_browse; pthread_t server_thread_translate_browse; static void *serverloop_register(void *_) { @@ -27,12 +27,11 @@ static void setup_server(void) { // start server running_translate_browse = UA_Boolean_new(); *running_translate_browse = true; - UA_ServerConfig config_register = UA_ServerConfig_standard; - config_register.applicationDescription.applicationUri = UA_String_fromChars("urn:open62541.test.server_translate_browse"); - nl_translate_browse = UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664); - config_register.networkLayers = &nl_translate_browse; - config_register.networkLayersSize = 1; - server_translate_browse = UA_Server_new(config_register); + server_translate_config = UA_ServerConfig_new_default(); + UA_String_deleteMembers(&server_translate_config->applicationDescription.applicationUri); + server_translate_config->applicationDescription.applicationUri = + UA_String_fromChars("urn:open62541.test.server_translate_browse"); + server_translate_browse = UA_Server_new(server_translate_config); UA_Server_run_startup(server_translate_browse); pthread_create(&server_thread_translate_browse, NULL, serverloop_register, NULL); } @@ -42,9 +41,8 @@ static void teardown_server(void) { pthread_join(server_thread_translate_browse, NULL); UA_Server_run_shutdown(server_translate_browse); UA_Boolean_delete(running_translate_browse); - UA_String_deleteMembers(&server_translate_browse->config.applicationDescription.applicationUri); UA_Server_delete(server_translate_browse); - nl_translate_browse.deleteMembers(&nl_translate_browse); + UA_ServerConfig_delete(server_translate_config); } static size_t @@ -77,7 +75,8 @@ browseWithMaxResults(UA_Server *server, UA_NodeId nodeId, UA_UInt32 maxResults) } START_TEST(Service_Browse_WithMaxResults) { - UA_Server *server = UA_Server_new(UA_ServerConfig_standard); + UA_ServerConfig *config = UA_ServerConfig_new_default(); + UA_Server *server = UA_Server_new(config); UA_BrowseDescription bd; UA_BrowseDescription_init(&bd); @@ -99,11 +98,13 @@ START_TEST(Service_Browse_WithMaxResults) { } UA_Server_delete(server); + UA_ServerConfig_delete(config); } END_TEST START_TEST(Service_Browse_WithBrowseName) { - UA_Server *server = UA_Server_new(UA_ServerConfig_standard); + UA_ServerConfig *config = UA_ServerConfig_new_default(); + UA_Server *server = UA_Server_new(config); UA_BrowseDescription bd; UA_BrowseDescription_init(&bd); @@ -120,13 +121,14 @@ START_TEST(Service_Browse_WithBrowseName) { UA_BrowseResult_deleteMembers(&br); UA_Server_delete(server); + UA_ServerConfig_delete(config); } END_TEST START_TEST(Service_TranslateBrowsePathsToNodeIds) { - UA_Client *client = UA_Client_new(UA_ClientConfig_standard); + UA_Client *client = UA_Client_new(UA_ClientConfig_default); - UA_StatusCode retVal = UA_Client_connect(client, "opc.tcp://localhost:16664"); + UA_StatusCode retVal = UA_Client_connect(client, "opc.tcp://localhost:4840"); ck_assert_int_eq(retVal, UA_STATUSCODE_GOOD); // Just for testing we want to translate the following path to its corresponding node id diff --git a/tests/fuzz/fuzz_binary_message.cc b/tests/fuzz/fuzz_binary_message.cc index fa675213d00..be351561399 100644 --- a/tests/fuzz/fuzz_binary_message.cc +++ b/tests/fuzz/fuzz_binary_message.cc @@ -15,8 +15,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { UA_Connection c = createDummyConnection(); - UA_ServerConfig config = UA_ServerConfig_standard; - config.logger = UA_Log_Stdout; + UA_ServerConfig *config = UA_ServerConfig_new_default(); UA_Server *server = UA_Server_new(config); // we need to copy the message because it will be freed in the processing function @@ -30,6 +29,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { // if we got an invalid chunk, the message is not deleted, so delete it here UA_ByteString_deleteMembers(&msg); UA_Server_delete(server); + UA_ServerConfig_delete(config); UA_Connection_deleteMembers(&c); return 0; } diff --git a/tests/testing_networklayers.c b/tests/testing_networklayers.c index 969a2ce3340..048582eeafd 100644 --- a/tests/testing_networklayers.c +++ b/tests/testing_networklayers.c @@ -37,8 +37,8 @@ dummyClose(UA_Connection *connection) { UA_Connection createDummyConnection(void) { UA_Connection c; c.state = UA_CONNECTION_ESTABLISHED; - c.localConf = UA_ConnectionConfig_standard; - c.remoteConf = UA_ConnectionConfig_standard; + c.localConf = UA_ConnectionConfig_default; + c.remoteConf = UA_ConnectionConfig_default; c.channel = NULL; c.sockfd = 0; c.handle = NULL;