Browse Source

Server: Initialize the config in the server

Julius Pfrommer 5 years ago
parent
commit
fd08d012d9
79 changed files with 674 additions and 1086 deletions
  1. 1 0
      CMakeLists.txt
  2. 3 3
      README.md
  3. 2 5
      examples/CMakeLists.txt
  4. 12 9
      examples/access_control/server_access_control.c
  5. 4 4
      examples/custom_datatype/server_types_custom.c
  6. 7 4
      examples/discovery/server_lds.c
  7. 4 8
      examples/discovery/server_multicast.c
  8. 6 6
      examples/discovery/server_register.c
  9. 0 69
      examples/encryption/server_basic256sha256.c
  10. 12 12
      examples/encryption/server_basic128rsa15.c
  11. 2 3
      examples/nodeset/server_nodeset.c
  12. 3 5
      examples/nodeset/server_nodeset_plcopen.c
  13. 3 5
      examples/nodeset/server_nodeset_powerlink.c
  14. 6 3
      examples/nodeset/server_testnodeset.c
  15. 9 13
      examples/pubsub/tutorial_pubsub_connection.c
  16. 7 6
      examples/pubsub/tutorial_pubsub_publish.c
  17. 7 5
      examples/pubsub/tutorial_pubsub_subscribe.c
  18. 4 6
      examples/pubsub_realtime/pubsub_interrupt_publish.c
  19. 3 3
      examples/server.cpp
  20. 12 20
      examples/server_ctt.c
  21. 15 15
      examples/server_inheritance.c
  22. 3 3
      examples/server_instantiation.c
  23. 2 3
      examples/server_mainloop.c
  24. 3 3
      examples/server_repeated_job.c
  25. 3 3
      examples/tutorial_server_datasource.c
  26. 3 3
      examples/tutorial_server_events.c
  27. 2 4
      examples/tutorial_server_firststeps.c
  28. 37 46
      examples/tutorial_server_historicaldata.c
  29. 3 3
      examples/tutorial_server_method.c
  30. 3 3
      examples/tutorial_server_monitoreditems.c
  31. 3 3
      examples/tutorial_server_object.c
  32. 3 3
      examples/tutorial_server_variable.c
  33. 3 3
      examples/tutorial_server_variabletype.c
  34. 5 4
      include/open62541/server.h
  35. 8 0
      include/open62541/server_config.h
  36. 26 54
      plugins/include/open62541/server_config_default.h
  37. 96 413
      plugins/ua_config_default.c
  38. 15 15
      src/server/ua_server.c
  39. 106 0
      src/server/ua_server_config.c
  40. 7 0
      src/server/ua_server_internal.h
  41. 2 4
      tests/client/check_client.c
  42. 3 3
      tests/client/check_client_async.c
  43. 5 7
      tests/client/check_client_async_connect.c
  44. 2 4
      tests/client/check_client_highlevel.c
  45. 14 13
      tests/client/check_client_historical_data.c
  46. 2 4
      tests/client/check_client_securechannel.c
  47. 3 4
      tests/client/check_client_subscriptions.c
  48. 6 19
      tests/encryption/check_encryption_basic128rsa15.c
  49. 6 19
      tests/encryption/check_encryption_basic256sha256.c
  50. 2 4
      tests/fuzz/corpus_generator.c
  51. 10 10
      tests/fuzz/fuzz_binary_message.cc
  52. 2 4
      tests/nodeset-compiler/check_nodeset_compiler_adi.c
  53. 2 5
      tests/nodeset-compiler/check_nodeset_compiler_plc.c
  54. 3 5
      tests/nodeset-compiler/check_nodeset_compiler_testnodeset.c
  55. 6 8
      tests/pubsub/check_pubsub_connection_udp.c
  56. 7 8
      tests/pubsub/check_pubsub_informationmodel.c
  57. 11 18
      tests/pubsub/check_pubsub_informationmodel_methods.c
  58. 4 8
      tests/pubsub/check_pubsub_multiple_layer.c
  59. 7 8
      tests/pubsub/check_pubsub_pds.c
  60. 7 8
      tests/pubsub/check_pubsub_publish.c
  61. 5 7
      tests/pubsub/check_pubsub_publish_json.c
  62. 6 8
      tests/pubsub/check_pubsub_publishspeed.c
  63. 2 4
      tests/server/check_accesscontrol.c
  64. 12 8
      tests/server/check_discovery.c
  65. 5 10
      tests/server/check_local_monitored_item.c
  66. 2 4
      tests/server/check_monitoreditem_filter.c
  67. 2 5
      tests/server/check_node_inheritance.c
  68. 2 4
      tests/server/check_server.c
  69. 21 27
      tests/server/check_server_historical_data.c
  70. 3 6
      tests/server/check_server_jobs.c
  71. 2 5
      tests/server/check_server_monitoringspeed.c
  72. 2 4
      tests/server/check_server_readspeed.c
  73. 16 19
      tests/server/check_server_userspace.c
  74. 7 10
      tests/server/check_services_attributes.c
  75. 2 4
      tests/server/check_services_call.c
  76. 5 5
      tests/server/check_services_nodemanagement.c
  77. 3 6
      tests/server/check_services_subscriptions.c
  78. 9 10
      tests/server/check_services_view.c
  79. 11 7
      tests/server/check_subscription_events.c

+ 1 - 0
CMakeLists.txt

@@ -617,6 +617,7 @@ set(lib_sources ${PROJECT_SOURCE_DIR}/src/ua_types.c
                 ${PROJECT_SOURCE_DIR}/src/server/ua_nodes.c
                 ${PROJECT_SOURCE_DIR}/src/server/ua_server.c
                 ${PROJECT_SOURCE_DIR}/src/server/ua_server_ns0.c
+                ${PROJECT_SOURCE_DIR}/src/server/ua_server_config.c
                 ${PROJECT_SOURCE_DIR}/src/server/ua_server_binary.c
                 ${PROJECT_SOURCE_DIR}/src/server/ua_server_utils.c
                 ${PROJECT_SOURCE_DIR}/src/server/ua_server_discovery.c

+ 3 - 3
README.md

@@ -146,8 +146,8 @@ int main(int argc, char** argv)
     signal(SIGINT, signalHandler); /* catch ctrl-c */
 
     /* Create a server listening on port 4840 */
-    UA_ServerConfig *config = UA_ServerConfig_new_default();
-    UA_Server *server = UA_Server_new(config);
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig_initDefault(UA_Server_getConfig(server));
 
     /* Add a variable node */
     /* 1) Define the node attributes */
@@ -169,8 +169,8 @@ int main(int argc, char** argv)
 
     /* Run the server loop */
     UA_StatusCode status = UA_Server_run(server, &running);
+
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
     return status;
 }
 ```

+ 2 - 5
examples/CMakeLists.txt

@@ -148,12 +148,9 @@ if(UA_ENABLE_HISTORIZING)
 endif()
 
 if(UA_ENABLE_ENCRYPTION)
-    add_example(server_basic128rsa15 encryption/server_basic128rsa15.c)
-    add_example(server_basic256sha256 encryption/server_basic256sha256.c)
+    add_example(server_encryption encryption/server_encryption.c)
     add_example(client_encryption encryption/client_encryption.c)
-    # common.h
-    target_include_directories(server_basic128rsa15 PRIVATE "${PROJECT_SOURCE_DIR}/examples")
-    target_include_directories(server_basic256sha256 PRIVATE "${PROJECT_SOURCE_DIR}/examples")
+    target_include_directories(server_encryption PRIVATE "${PROJECT_SOURCE_DIR}/examples")
     target_include_directories(client_encryption PRIVATE "${PROJECT_SOURCE_DIR}/examples")
 endif()
 

+ 12 - 9
examples/access_control/server_access_control.c

@@ -56,23 +56,26 @@ int main(void) {
     signal(SIGINT, stopHandler);
     signal(SIGTERM, stopHandler);
 
-    UA_ServerConfig *config = UA_ServerConfig_new_default();
-    // disable anonymous logins, enable two user/password logins
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+    UA_ServerConfig_setDefault(config);
+
+    /* Disable anonymous logins, enable two user/password logins */
     config->accessControl.deleteMembers(&config->accessControl);
-    if (UA_AccessControl_default(&config->accessControl, false, 2, logins) != UA_STATUSCODE_GOOD) {
-        return EXIT_FAILURE;
-    }
+    UA_StatusCode retval = UA_AccessControl_default(&config->accessControl,
+                                                    false, 2, logins);
+    if(retval != UA_STATUSCODE_GOOD)
+        goto cleanup;
 
-    // Set accessControl functions for nodeManagement
+    /* Set accessControl functions for nodeManagement */
     config->accessControl.allowAddNode = allowAddNode;
     config->accessControl.allowAddReference = allowAddReference;
     config->accessControl.allowDeleteNode = allowDeleteNode;
     config->accessControl.allowDeleteReference = allowDeleteReference;
 
-    UA_Server *server = UA_Server_new(config);
+    retval = UA_Server_run(server, &running);
 
-    UA_StatusCode retval = UA_Server_run(server, &running);
+ cleanup:
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
     return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
 }

+ 4 - 4
examples/custom_datatype/server_types_custom.c

@@ -64,7 +64,10 @@ int main(void) {
     signal(SIGINT, stopHandler);
     signal(SIGTERM, stopHandler);
 
-    UA_ServerConfig *config = UA_ServerConfig_new_default();
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+    UA_ServerConfig_setDefault(config);
+
     /* Make your custom datatype known to the stack */
     UA_DataType *types = (UA_DataType*)UA_malloc(sizeof(UA_DataType));
     UA_DataTypeMember *members = (UA_DataTypeMember*)UA_malloc(sizeof(UA_DataTypeMember) * 3);
@@ -79,8 +82,6 @@ int main(void) {
     UA_DataTypeArray customDataTypes = {config->customDataTypes, 1, types};
     config->customDataTypes = &customDataTypes;
 
-    UA_Server *server = UA_Server_new(config);
-
     add3PointDataType(server);
     add3DPointVariable(server);
 
@@ -89,6 +90,5 @@ int main(void) {
     UA_Server_delete(server);
     UA_free(members);
     UA_free(types);
-    UA_ServerConfig_delete(config);
     return EXIT_SUCCESS;
 }

+ 7 - 4
examples/discovery/server_lds.c

@@ -21,7 +21,10 @@ int main(void) {
     signal(SIGINT, stopHandler);
     signal(SIGTERM, stopHandler);
 
-    UA_ServerConfig *config = UA_ServerConfig_new_default();
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+    UA_ServerConfig_setDefault(config);
+    
     config->applicationDescription.applicationType = UA_APPLICATIONTYPE_DISCOVERYSERVER;
     UA_String_clear(&config->applicationDescription.applicationUri);
     config->applicationDescription.applicationUri =
@@ -32,17 +35,17 @@ int main(void) {
     UA_String *caps = UA_String_new();
     *caps = UA_String_fromChars("LDS");
     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
      * bigger than 10 seconds, because cleanup is only triggered approximately
      * every 10 seconds. The server will still be removed depending on the
      * state of the semaphore file. */
-    // config.discoveryCleanupTimeout = 60*60;
-    UA_Server *server = UA_Server_new(config);
+    // config->discoveryCleanupTimeout = 60*60;
 
     UA_StatusCode retval = UA_Server_run(server, &running);
+
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
     return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
 }

+ 4 - 8
examples/discovery/server_multicast.c

@@ -268,7 +268,10 @@ int main(int argc, char **argv) {
     signal(SIGINT, stopHandler); /* catches ctrl-c */
     signal(SIGTERM, stopHandler);
 
-    UA_ServerConfig *config = UA_ServerConfig_new_minimal(16600, NULL);
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+    UA_ServerConfig_setMinimal(config, 16600, NULL);
+
     // To enable mDNS discovery, set application type to discovery server.
     config->applicationDescription.applicationType = UA_APPLICATIONTYPE_DISCOVERYSERVER;
     UA_String_clear(&config->applicationDescription.applicationUri);
@@ -279,7 +282,6 @@ int main(int argc, char **argv) {
     //config.serverCapabilitiesSize = 1;
     //UA_String caps = UA_String_fromChars("LDS");
     //config.serverCapabilities = ∩︀
-    UA_Server *server = UA_Server_new(config);
 
     /* add a variable node to the address space */
     UA_Int32 myInteger = 42;
@@ -308,7 +310,6 @@ int main(int argc, char **argv) {
                      "Could not start the server. StatusCode %s",
                      UA_StatusCode_name(retval));
         UA_Server_delete(server);
-        UA_ServerConfig_delete(config);
         UA_free(discovery_url);
         return EXIT_FAILURE;
     }
@@ -318,7 +319,6 @@ int main(int argc, char **argv) {
         UA_Server_run_iterate(server, true);
     if(!running) {
         UA_Server_delete(server);
-        UA_ServerConfig_delete(config);
         UA_free(discovery_url);
         return EXIT_FAILURE;
     }
@@ -333,7 +333,6 @@ int main(int argc, char **argv) {
         UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
                      "Could not find any suitable endpoints on discovery server");
         UA_Server_delete(server);
-        UA_ServerConfig_delete(config);
         return EXIT_FAILURE;
     }
 
@@ -342,7 +341,6 @@ int main(int argc, char **argv) {
         UA_LOG_FATAL(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
                      "Could not create the client for remote registering");
         UA_Server_delete(server);
-        UA_ServerConfig_delete(config);
         return EXIT_FAILURE;
     }
 
@@ -360,7 +358,6 @@ int main(int argc, char **argv) {
         UA_Client_disconnect(clientRegister);
         UA_Client_delete(clientRegister);
         UA_Server_delete(server);
-        UA_ServerConfig_delete(config);
         return EXIT_FAILURE;
     }
 
@@ -380,6 +377,5 @@ int main(int argc, char **argv) {
     UA_Client_disconnect(clientRegister);
     UA_Client_delete(clientRegister);
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
     return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
 }

+ 6 - 6
examples/discovery/server_register.c

@@ -64,7 +64,10 @@ int main(int argc, char **argv) {
     signal(SIGINT, stopHandler); /* catches ctrl-c */
     signal(SIGTERM, stopHandler);
 
-    UA_ServerConfig *config = UA_ServerConfig_new_minimal(4841, NULL);;
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+    UA_ServerConfig_setMinimal(config, 4841, NULL);
+
     UA_String_clear(&config->applicationDescription.applicationUri);
     config->applicationDescription.applicationUri =
         UA_String_fromChars("urn:open62541.example.server_register");
@@ -74,8 +77,6 @@ int main(int argc, char **argv) {
     //UA_String caps = UA_String_fromChars("LDS");
     //config.serverCapabilities = ∩︀
 
-    UA_Server *server = UA_Server_new(config);
-
     /* add a variable node to the address space */
     UA_Int32 myInteger = 42;
     UA_NodeId myIntegerNodeId = UA_NODEID_STRING(1, "the.answer");
@@ -109,11 +110,12 @@ int main(int argc, char **argv) {
         UA_Client_disconnect(clientRegister);
         UA_Client_delete(clientRegister);
         UA_Server_delete(server);
-        UA_ServerConfig_delete(config);
+        UA_Server_delete(server);
         return EXIT_FAILURE;
     }
 
     retval = UA_Server_run(server, &running);
+
     if(retval != UA_STATUSCODE_GOOD) {
         UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
                      "Could not start the server. StatusCode %s",
@@ -121,7 +123,6 @@ int main(int argc, char **argv) {
         UA_Client_disconnect(clientRegister);
         UA_Client_delete(clientRegister);
         UA_Server_delete(server);
-        UA_ServerConfig_delete(config);
         return EXIT_FAILURE;
     }
 
@@ -136,6 +137,5 @@ int main(int argc, char **argv) {
     UA_Client_disconnect(clientRegister);
     UA_Client_delete(clientRegister);
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
     return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;;
 }

+ 0 - 69
examples/encryption/server_basic256sha256.c

@@ -1,69 +0,0 @@
-/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
- * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
-
-#include <open62541/client_highlevel.h>
-#include <open62541/plugin/log_stdout.h>
-#include <open62541/plugin/securitypolicy.h>
-#include <open62541/server.h>
-#include <open62541/server_config_default.h>
-
-#include <signal.h>
-#include <stdlib.h>
-
-#include "common.h"
-
-UA_Boolean running = true;
-static void stopHandler(int sig) {
-    UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND, "received ctrl-c");
-    running = false;
-}
-
-int main(int argc, char* argv[]) {
-    signal(SIGINT, stopHandler);
-    signal(SIGTERM, stopHandler);
-
-    if(argc < 3) {
-        UA_LOG_FATAL(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
-                     "Missing arguments. Arguments are "
-                     "<server-certificate.der> <private-key.der> "
-                     "[<trustlist1.crl>, ...]");
-        return EXIT_FAILURE;
-    }
-
-    /* Load certificate and private key */
-    UA_ByteString certificate = loadFile(argv[1]);
-    UA_ByteString privateKey = loadFile(argv[2]);
-
-    /* Load the trustlist */
-    size_t trustListSize = 0;
-    if(argc > 3)
-        trustListSize = (size_t)argc-3;
-    UA_STACKARRAY(UA_ByteString, trustList, trustListSize);
-    for(size_t i = 0; i < trustListSize; i++)
-        trustList[i] = loadFile(argv[i+3]);
-
-    /* Loading of a revocation list currently unsupported */
-    UA_ByteString *revocationList = NULL;
-    size_t revocationListSize = 0;
-
-    UA_ServerConfig *config =
-        UA_ServerConfig_new_basic256sha256(4840, &certificate, &privateKey,
-                                          trustList, trustListSize,
-                                          revocationList, revocationListSize);
-    UA_ByteString_clear(&certificate);
-    UA_ByteString_clear(&privateKey);
-    for(size_t i = 0; i < trustListSize; i++)
-        UA_ByteString_clear(&trustList[i]);
-
-    if(!config) {
-        UA_LOG_FATAL(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
-                     "Could not create the server config");
-        return EXIT_FAILURE;
-    }
-
-    UA_Server *server = UA_Server_new(config);
-    UA_StatusCode retval = UA_Server_run(server, &running);
-    UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
-    return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;;
-}

+ 12 - 12
examples/encryption/server_basic128rsa15.c

@@ -46,24 +46,24 @@ int main(int argc, char* argv[]) {
     UA_ByteString *revocationList = NULL;
     size_t revocationListSize = 0;
 
-    UA_ServerConfig *config =
-        UA_ServerConfig_new_basic128rsa15(4840, &certificate, &privateKey,
-                                          trustList, trustListSize,
-                                          revocationList, revocationListSize);
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+
+    UA_StatusCode retval =
+        UA_ServerConfig_setDefaultWithSecurityPolicies(config, 4840,
+                                                       &certificate, &privateKey,
+                                                       trustList, trustListSize,
+                                                       revocationList, revocationListSize);
     UA_ByteString_clear(&certificate);
     UA_ByteString_clear(&privateKey);
     for(size_t i = 0; i < trustListSize; i++)
         UA_ByteString_clear(&trustList[i]);
+    if(retval != UA_STATUSCODE_GOOD)
+        goto cleanup;
 
-    if(!config) {
-        UA_LOG_FATAL(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
-                     "Could not create the server config");
-        return EXIT_FAILURE;
-    }
+    retval = UA_Server_run(server, &running);
 
-    UA_Server *server = UA_Server_new(config);
-    UA_StatusCode retval = UA_Server_run(server, &running);
+ cleanup:
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
     return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
 }

+ 2 - 3
examples/nodeset/server_nodeset.c

@@ -24,8 +24,8 @@ int main(int argc, char** argv) {
     signal(SIGINT, stopHandler);
     signal(SIGTERM, stopHandler);
     
-    UA_ServerConfig *config = UA_ServerConfig_new_default();
-    UA_Server *server = UA_Server_new(config);
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
 
     UA_StatusCode retval;
     /* create nodes from nodeset */
@@ -49,6 +49,5 @@ int main(int argc, char** argv) {
     }
 
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
     return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
 }

+ 3 - 5
examples/nodeset/server_nodeset_plcopen.c

@@ -26,27 +26,25 @@ int main(int argc, char** argv) {
     signal(SIGINT, stopHandler);
     signal(SIGTERM, stopHandler);
 
-    UA_ServerConfig *config = UA_ServerConfig_new_default();
-    UA_Server *server = UA_Server_new(config);
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
 
     /* create nodes from nodeset */
     UA_StatusCode retval = namespace_di_generated(server);
     if(retval != UA_STATUSCODE_GOOD) {
         UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "Adding the DI namespace failed. Please check previous error output.");
         UA_Server_delete(server);
-        UA_ServerConfig_delete(config);
         return EXIT_FAILURE;
     }
     retval |= namespace_plc_generated(server);
     if(retval != UA_STATUSCODE_GOOD) {
         UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "Adding the PLCopen namespace failed. Please check previous error output.");
         UA_Server_delete(server);
-        UA_ServerConfig_delete(config);
         return EXIT_FAILURE;
     }
 
     retval = UA_Server_run(server, &running);
+
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
     return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
 }

+ 3 - 5
examples/nodeset/server_nodeset_powerlink.c

@@ -26,27 +26,25 @@ int main(int argc, char** argv) {
     signal(SIGINT, stopHandler);
     signal(SIGTERM, stopHandler);
 
-    UA_ServerConfig *config = UA_ServerConfig_new_default();
-    UA_Server *server = UA_Server_new(config);
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
 
     /* create nodes from nodeset */
     UA_StatusCode retval = namespace_di_generated(server);
     if(retval != UA_STATUSCODE_GOOD) {
         UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "Adding the DI namespace failed. Please check previous error output.");
         UA_Server_delete(server);
-        UA_ServerConfig_delete(config);
         return EXIT_FAILURE;
     }
     retval |= namespace_powerlink_generated(server);
     if(retval != UA_STATUSCODE_GOOD) {
         UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "Adding the Powerlink namespace failed. Please check previous error output.");
         UA_Server_delete(server);
-        UA_ServerConfig_delete(config);
         return EXIT_FAILURE;
     }
 
     retval = UA_Server_run(server, &running);
+
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
     return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
 }

+ 6 - 3
examples/nodeset/server_testnodeset.c

@@ -26,9 +26,12 @@ int main(int argc, char **argv)
 {
     signal(SIGINT, stopHandler);
     signal(SIGTERM, stopHandler);
-    UA_ServerConfig *config = UA_ServerConfig_new_default();
+
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+    UA_ServerConfig_setDefault(config);
+
     config->customDataTypes = &customTypesArray;
-    UA_Server *server = UA_Server_new(config);
 
     UA_StatusCode retval;
     /* create nodes from nodeset */
@@ -45,7 +48,7 @@ int main(int argc, char **argv)
         printf("point 2d x: %f y: %f \n", p->x, p->y);
         retval = UA_Server_run(server, &running);
     }
+
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
     return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
 }

+ 9 - 13
examples/pubsub/tutorial_pubsub_connection.c

@@ -24,7 +24,9 @@ int main(void) {
     signal(SIGINT, stopHandler);
     signal(SIGTERM, stopHandler);
 
-    UA_ServerConfig *config = UA_ServerConfig_new_default();
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+    UA_ServerConfig_setDefault(config);
 
     /* Add the PubSubTransportLayer implementation to the server config.
      * The PubSubTransportLayer is a factory to create new connections
@@ -33,17 +35,14 @@ int main(void) {
      */
     config->pubsubTransportLayers = (UA_PubSubTransportLayer *) UA_malloc(sizeof(UA_PubSubTransportLayer));
     if(!config->pubsubTransportLayers) {
-        UA_ServerConfig_delete(config);
+        UA_Server_delete(server);
         return -1;
     }
     /* It is possible to use multiple PubSubTransportLayers on runtime. The correct factory
-     * is selected on runtime by the standard defined PubSub TransportProfileUri's.
-     */
+     * is selected on runtime by the standard defined PubSub TransportProfileUri's. */
     config->pubsubTransportLayers[0] = UA_PubSubTransportLayerUDPMP();
     config->pubsubTransportLayersSize++;
 
-    UA_Server *server = UA_Server_new(config);
-
     /* Create a new ConnectionConfig. The addPubSubConnection function takes the
      * config and create a new connection. The Connection identifier is
      * copied to the NodeId parameter.*/
@@ -53,14 +52,12 @@ int main(void) {
     connectionConfig.transportProfileUri = UA_STRING("http://opcfoundation.org/UA-Profile/Transport/pubsub-udp-uadp");
     connectionConfig.enabled = UA_TRUE;
     /* The address and interface is part of the standard
-     * defined UA_NetworkAddressUrlDataType.
-     */
+     * defined UA_NetworkAddressUrlDataType. */
     UA_NetworkAddressUrlDataType networkAddressUrl = {UA_STRING_NULL , UA_STRING("opc.udp://224.0.0.22:4840/")};
     UA_Variant_setScalar(&connectionConfig.address, &networkAddressUrl, &UA_TYPES[UA_TYPES_NETWORKADDRESSURLDATATYPE]);
     connectionConfig.publisherId.numeric = UA_UInt32_random();
     /* Connection options are given as Key/Value Pairs. The available options are
-     * maybe standard or vendor defined.
-     */
+     * maybe standard or vendor defined. */
     UA_KeyValuePair connectionOptions[3];
     connectionOptions[0].key = UA_QUALIFIEDNAME(0, "ttl");
     UA_UInt32 ttl = 10;
@@ -74,8 +71,7 @@ int main(void) {
     connectionConfig.connectionProperties = connectionOptions;
     connectionConfig.connectionPropertiesSize = 3;
     /* Create a new concrete connection and add the connection
-     * to the current PubSub configuration.
-     */
+     * to the current PubSub configuration. */
     UA_NodeId connectionIdentifier;
     UA_StatusCode retval = UA_Server_addPubSubConnection(server, &connectionConfig, &connectionIdentifier);
     if(retval == UA_STATUSCODE_GOOD){
@@ -84,7 +80,7 @@ int main(void) {
     }
 
     retval |= UA_Server_run(server, &running);
+
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
     return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
 }

+ 7 - 6
examples/pubsub/tutorial_pubsub_publish.c

@@ -159,14 +159,16 @@ static int run(UA_String *transportProfile,
     signal(SIGINT, stopHandler);
     signal(SIGTERM, stopHandler);
 
-    UA_StatusCode retval = UA_STATUSCODE_GOOD;
-    UA_ServerConfig *config = UA_ServerConfig_new_default();
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+    UA_ServerConfig_setDefault(config);
+
     /* Details about the connection configuration and handling are located in
      * the pubsub connection tutorial */
     config->pubsubTransportLayers =
         (UA_PubSubTransportLayer *) UA_calloc(2, sizeof(UA_PubSubTransportLayer));
     if(!config->pubsubTransportLayers) {
-        UA_ServerConfig_delete(config);
+        UA_Server_delete(server);
         return EXIT_FAILURE;
     }
     config->pubsubTransportLayers[0] = UA_PubSubTransportLayerUDPMP();
@@ -175,7 +177,6 @@ static int run(UA_String *transportProfile,
     config->pubsubTransportLayers[1] = UA_PubSubTransportLayerEthernet();
     config->pubsubTransportLayersSize++;
 #endif
-    UA_Server *server = UA_Server_new(config);
 
     addPubSubConnection(server, transportProfile, networkAddressUrl);
     addPublishedDataSet(server);
@@ -183,9 +184,9 @@ static int run(UA_String *transportProfile,
     addWriterGroup(server);
     addDataSetWriter(server);
 
-    retval |= UA_Server_run(server, &running);
+    UA_StatusCode retval = UA_Server_run(server, &running);
+
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
     return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 

+ 7 - 5
examples/pubsub/tutorial_pubsub_subscribe.c

@@ -105,13 +105,16 @@ run(UA_String *transportProfile, UA_NetworkAddressUrlDataType *networkAddressUrl
     signal(SIGINT, stopHandler);
     signal(SIGTERM, stopHandler);
 
-    UA_ServerConfig *config = UA_ServerConfig_new_minimal(4801, NULL);
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+    UA_ServerConfig_setMinimal(config, 4801, NULL);
+
     /* Details about the PubSubTransportLayer can be found inside the
      * tutorial_pubsub_connection */
     config->pubsubTransportLayers = (UA_PubSubTransportLayer *)
         UA_calloc(2, sizeof(UA_PubSubTransportLayer));
-    if (!config->pubsubTransportLayers) {
-        UA_ServerConfig_delete(config);
+    if(!config->pubsubTransportLayers) {
+        UA_Server_delete(server);
         return EXIT_FAILURE;
     }
     config->pubsubTransportLayers[0] = UA_PubSubTransportLayerUDPMP();
@@ -120,7 +123,6 @@ run(UA_String *transportProfile, UA_NetworkAddressUrlDataType *networkAddressUrl
     config->pubsubTransportLayers[1] = UA_PubSubTransportLayerEthernet();
     config->pubsubTransportLayersSize++;
 #endif
-    UA_Server *server = UA_Server_new(config);
 
     UA_PubSubConnectionConfig connectionConfig;
     memset(&connectionConfig, 0, sizeof(connectionConfig));
@@ -154,8 +156,8 @@ run(UA_String *transportProfile, UA_NetworkAddressUrlDataType *networkAddressUrl
     }
 
     retval |= UA_Server_run(server, &running);
+
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
     return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;;
 }
 

+ 4 - 6
examples/pubsub_realtime/pubsub_interrupt_publish.c

@@ -307,17 +307,15 @@ int main(void) {
     signal(SIGINT, stopHandler);
     signal(SIGTERM, stopHandler);
 
-    UA_ServerConfig* config = UA_ServerConfig_new_minimal(4840, NULL);
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+    UA_ServerConfig_setDefault(config);
+
     config->pubsubTransportLayers = (UA_PubSubTransportLayer *)
         UA_malloc(sizeof(UA_PubSubTransportLayer));
-    if(!config->pubsubTransportLayers) {
-        UA_ServerConfig_delete(config);
-        return -1;
-    }
     config->pubsubTransportLayers[0] = UA_PubSubTransportLayerEthernet();
     config->pubsubTransportLayersSize++;
 
-    UA_Server *server = UA_Server_new(config);
     addServerNodes(server);
     addPubSubConfiguration(server);
 

+ 3 - 3
examples/server.cpp

@@ -23,8 +23,8 @@ int main() {
     signal(SIGINT, stopHandler);
     signal(SIGTERM, stopHandler);
 
-    UA_ServerConfig *config = UA_ServerConfig_new_default();
-    UA_Server *server = UA_Server_new(config);
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
 
     // add a variable node to the adresspace
     UA_VariableAttributes attr = UA_VariableAttributes_default;
@@ -46,7 +46,7 @@ int main() {
     UA_QualifiedName_clear(&myIntegerName);
 
     UA_StatusCode retval = UA_Server_run(server, &running);
+
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
     return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
 }

+ 12 - 20
examples/server_ctt.c

@@ -442,14 +442,18 @@ int main(int argc, char **argv) {
     signal(SIGINT, stopHandler); /* catches ctrl-c */
     signal(SIGTERM, stopHandler);
 
-    UA_ServerConfig *config;
+    UA_Server *server = UA_Server_new();
+    if(server == NULL)
+        return EXIT_FAILURE;
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+
 #ifdef UA_ENABLE_ENCRYPTION
     if(argc < 3) {
         UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
                        "Missing arguments for encryption support. "
                        "Arguments are <server-certificate.der> "
                        "<private-key.der> [<trustlist1.crl>, ...]");
-        config = UA_ServerConfig_new_minimal(4840, NULL);
+        UA_ServerConfig_setDefault(config);
     } else {
         /* Load certificate and private key */
         UA_ByteString certificate = loadFile(argv[1]);
@@ -477,9 +481,10 @@ int main(int argc, char **argv) {
         UA_ByteString *revocationList = NULL;
         size_t revocationListSize = 0;
 
-        config = UA_ServerConfig_new_allSecurityPolicies(4840, &certificate, &privateKey,
-                                                         trustList, trustListSize,
-                                                         revocationList, revocationListSize);
+        UA_ServerConfig_setDefaultWithSecurityPolicies(config, 4840,
+                                                       &certificate, &privateKey,
+                                                       trustList, trustListSize,
+                                                       revocationList, revocationListSize);
         UA_ByteString_clear(&certificate);
         UA_ByteString_clear(&privateKey);
         for(size_t i = 0; i < trustListSize; i++)
@@ -493,31 +498,18 @@ int main(int argc, char **argv) {
     } else {
         certificate = loadFile(argv[1]);
     }
-    config = UA_ServerConfig_new_minimal(4840, &certificate);
+    UA_ServerConfig_setDefault(config);
     UA_ByteString_clear(&certificate);
 #endif
 
-    if(!config) {
-        UA_LOG_FATAL(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
-                     "Could not create the server config");
-        return EXIT_FAILURE;
-    }
-
     /* Override with a custom access control policy */
     config->accessControl.getUserAccessLevel = getUserAccessLevel_disallowSpecific;
 
-    /* uncomment next line to add a custom hostname */
-    // UA_ServerConfig_set_customHostname(config, UA_STRING("custom"));
-
-    UA_Server *server = UA_Server_new(config);
-    if(server == NULL)
-        return EXIT_FAILURE;
-
     setInformationModel(server);
 
     /* run server */
     UA_StatusCode retval = UA_Server_run(server, &running);
+
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
     return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
 }

+ 15 - 15
examples/server_inheritance.c

@@ -19,7 +19,7 @@ static void stopHandler(int sig) {
  * Create a rudimentary objectType
  *
  * Type:
- * + MamalType
+ * + MammalType
  *  v- Class  = "mamalia"
  *  v- Species
  *  o- Abilities
@@ -32,19 +32,19 @@ static void stopHandler(int sig) {
  *          v- MakeSound = "Wuff"
  *           v- FetchNewPaper
  */
-static void createMamals(UA_Server *server) {
+static void createMammals(UA_Server *server) {
 
 
     UA_ObjectTypeAttributes otAttr = UA_ObjectTypeAttributes_default;
-    otAttr.description = UA_LOCALIZEDTEXT("en-US", "A mamal");
-    otAttr.displayName = UA_LOCALIZEDTEXT("en-US", "MamalType");
+    otAttr.description = UA_LOCALIZEDTEXT("en-US", "A mammal");
+    otAttr.displayName = UA_LOCALIZEDTEXT("en-US", "MammalType");
     UA_Server_addObjectTypeNode(server, UA_NODEID_NUMERIC(1, 10000),
                                 UA_NODEID_NUMERIC(0, UA_NS0ID_BASEOBJECTTYPE),
                                 UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE),
-                                UA_QUALIFIEDNAME(1, "MamalType"), otAttr, NULL, NULL);
+                                UA_QUALIFIEDNAME(1, "MammalType"), otAttr, NULL, NULL);
 
     UA_VariableAttributes vAttr = UA_VariableAttributes_default;
-    vAttr.description =  UA_LOCALIZEDTEXT("en-US", "This mamals class");
+    vAttr.description =  UA_LOCALIZEDTEXT("en-US", "This mammals class");
     vAttr.displayName =  UA_LOCALIZEDTEXT("en-US", "Class");
     UA_String classVar = UA_STRING("mamalia");
     UA_Variant_setScalar(&vAttr.value, &classVar, &UA_TYPES[UA_TYPES_STRING]);
@@ -55,7 +55,7 @@ static void createMamals(UA_Server *server) {
                               vAttr, NULL, NULL);
 
     vAttr = UA_VariableAttributes_default;
-    vAttr.description =  UA_LOCALIZEDTEXT("en-US", "This mamals species");
+    vAttr.description =  UA_LOCALIZEDTEXT("en-US", "This mammals species");
     vAttr.displayName =  UA_LOCALIZEDTEXT("en-US", "Species");
     UA_Server_addVariableNode(server, UA_NODEID_NUMERIC(1, 10002),
                               UA_NODEID_NUMERIC(1, 10000),
@@ -64,7 +64,7 @@ static void createMamals(UA_Server *server) {
                               vAttr, NULL, NULL);
 
     otAttr = UA_ObjectTypeAttributes_default;
-    otAttr.description = UA_LOCALIZEDTEXT("en-US", "A dog, subtype of mamal");
+    otAttr.description = UA_LOCALIZEDTEXT("en-US", "A dog, subtype of mammal");
     otAttr.displayName = UA_LOCALIZEDTEXT("en-US", "DogType");
     UA_Server_addObjectTypeNode(server, UA_NODEID_NUMERIC(1, 20000),
                                 UA_NODEID_NUMERIC(1, 10000),
@@ -119,12 +119,12 @@ static void createMamals(UA_Server *server) {
                             oAttr, NULL, NULL);
 
     oAttr = UA_ObjectAttributes_default;
-    oAttr.description = UA_LOCALIZEDTEXT("en-US", "A mamal");
-    oAttr.displayName = UA_LOCALIZEDTEXT("en-US", "Mamal1");
+    oAttr.description = UA_LOCALIZEDTEXT("en-US", "A mmamal");
+    oAttr.displayName = UA_LOCALIZEDTEXT("en-US", "Mmamal1");
     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),
+                            UA_QUALIFIEDNAME(1, "Mammal1"), UA_NODEID_NUMERIC(1, 10000),
                             oAttr, NULL, NULL);
 
 }
@@ -250,16 +250,16 @@ int main(void) {
     signal(SIGINT,  stopHandler);
     signal(SIGTERM, stopHandler);
 
-    UA_ServerConfig *config = UA_ServerConfig_new_default();
-    UA_Server *server = UA_Server_new(config);
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
 
-    createMamals(server);
+    createMammals(server);
 
     createCustomInheritance(server);
 
     /* Run the server */
     UA_StatusCode retval = UA_Server_run(server, &running);
+
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
     return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
 }

+ 3 - 3
examples/server_instantiation.c

@@ -17,8 +17,8 @@ int main(void) {
     signal(SIGINT,  stopHandler);
     signal(SIGTERM, stopHandler);
 
-    UA_ServerConfig *config = UA_ServerConfig_new_default();
-    UA_Server *server = UA_Server_new(config);
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
 
     /* Create a rudimentary objectType
      * 
@@ -81,7 +81,7 @@ int main(void) {
                             oAttr, NULL, NULL);
 
     retval = UA_Server_run(server, &running);
+
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
     return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
 }

+ 2 - 3
examples/server_mainloop.c

@@ -23,8 +23,8 @@ int main(int argc, char** argv) {
     signal(SIGINT, stopHandler);
     signal(SIGTERM, stopHandler);
 
-    UA_ServerConfig *config = UA_ServerConfig_new_default();
-    UA_Server *server = UA_Server_new(config);
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
 
     /* Should the server networklayer block (with a timeout) until a message
        arrives or should it return immediately? */
@@ -56,6 +56,5 @@ int main(int argc, char** argv) {
 
  cleanup:
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
     return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
 }

+ 3 - 3
examples/server_repeated_job.c

@@ -23,14 +23,14 @@ int main(void) {
     signal(SIGINT, stopHandler);
     signal(SIGTERM, stopHandler);
 
-    UA_ServerConfig *config = UA_ServerConfig_new_default();
-    UA_Server *server = UA_Server_new(config);
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
 
     /* Add a repeated callback to the server */
     UA_Server_addRepeatedCallback(server, testCallback, NULL, 2000, NULL); /* call every 2 sec */
 
     UA_StatusCode retval = UA_Server_run(server, &running);
+
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
     return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
 }

+ 3 - 3
examples/tutorial_server_datasource.c

@@ -163,15 +163,15 @@ int main(void) {
     signal(SIGINT, stopHandler);
     signal(SIGTERM, stopHandler);
 
-    UA_ServerConfig *config = UA_ServerConfig_new_default();
-    UA_Server *server = UA_Server_new(config);
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
 
     addCurrentTimeVariable(server);
     addValueCallbackToCurrentTimeVariable(server);
     addCurrentTimeDataSourceVariable(server);
 
     UA_StatusCode retval = UA_Server_run(server, &running);
+
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
     return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
 }

+ 3 - 3
examples/tutorial_server_events.c

@@ -149,14 +149,14 @@ int main (void) {
     signal(SIGINT, stopHandler);
     signal(SIGTERM, stopHandler);
 
-    UA_ServerConfig *config = UA_ServerConfig_new_default();
-    UA_Server *server = UA_Server_new(config);
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
 
     addNewEventType(server);
     addGenerateEventMethod(server);
 
     UA_StatusCode retval = UA_Server_run(server, &running);
+
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
     return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
 }

+ 2 - 4
examples/tutorial_server_firststeps.c

@@ -37,14 +37,12 @@ int main(void) {
     signal(SIGINT, stopHandler);
     signal(SIGTERM, stopHandler);
 
-    UA_ServerConfig *config = UA_ServerConfig_new_default();
-    UA_Server *server = UA_Server_new(config);
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
 
     UA_StatusCode retval = UA_Server_run(server, &running);
 
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
-
     return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 

+ 37 - 46
examples/tutorial_server_historicaldata.c

@@ -26,20 +26,20 @@ int main(void) {
     signal(SIGINT, stopHandler);
     signal(SIGTERM, stopHandler);
 
-    UA_ServerConfig *config = UA_ServerConfig_new_default();
-    /*
-     * We need a gathering for the plugin to constuct.
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+    UA_ServerConfig_setDefault(config);
+
+    /* We need a gathering for the plugin to constuct.
      * The UA_HistoryDataGathering is responsible to collect data and store it to the database.
      * We will use this gathering for one node, only. initialNodeIdStoreSize = 1
-     * The store will grow if you register more than one node, but this is expensive.
-     */
+     * The store will grow if you register more than one node, but this is expensive. */
     UA_HistoryDataGathering gathering = UA_HistoryDataGathering_Default(1);
-    /*
-     * We set the responsible plugin in the configuration.
-     * UA_HistoryDatabase is the main plugin which handles the historical data service.
-     */
+
+    /* We set the responsible plugin in the configuration. UA_HistoryDatabase is
+     * the main plugin which handles the historical data service. */
     config->historyDatabase = UA_HistoryDatabase_default(gathering);
-    UA_Server *server = UA_Server_new(config);
+
     /* Define the attribute of the uint32 variable node */
     UA_VariableAttributes attr = UA_VariableAttributes_default;
     UA_UInt32 myUint32 = 40;
@@ -47,14 +47,10 @@ int main(void) {
     attr.description = UA_LOCALIZEDTEXT("en-US","myUintValue");
     attr.displayName = UA_LOCALIZEDTEXT("en-US","myUintValue");
     attr.dataType = UA_TYPES[UA_TYPES_UINT32].typeId;
-    /*
-     * We set the access level to also support history read
-     * This is what will be reported to clients
-     */
+    /* We set the access level to also support history read
+     * This is what will be reported to clients */
     attr.accessLevel = UA_ACCESSLEVELMASK_READ | UA_ACCESSLEVELMASK_WRITE | UA_ACCESSLEVELMASK_HISTORYREAD;
-    /*
-     * We also set this node to historizing, so the server internals also know from it.
-     */
+    /* We also set this node to historizing, so the server internals also know from it. */
     attr.historizing = true;
 
     /* Add the variable node to the information model */
@@ -73,26 +69,25 @@ int main(void) {
                                                      attr,
                                                      NULL,
                                                      &outNodeId);
-    UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "UA_Server_addVariableNode %s", UA_StatusCode_name(retval));
-    /*
-     * Now we define the settings for our node
-     */
+
+    UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
+                "UA_Server_addVariableNode %s", UA_StatusCode_name(retval));
+
+    /* Now we define the settings for our node */
     UA_HistorizingNodeIdSettings setting;
-    /*
-     * There is a memory based database plugin. We will use that.
-     * We just reserve space for 3 nodes with 100 values each.
-     * This will also automaticaly grow if needed, but that is expensive,
-     * because all data must be copied.
-     */
+
+    /* There is a memory based database plugin. We will use that. We just
+     * reserve space for 3 nodes with 100 values each. This will also
+     * automaticaly grow if needed, but that is expensive, because all data must
+     * be copied. */
     setting.historizingBackend = UA_HistoryDataBackend_Memory(3, 100);
-    /*
-     * We want the server to serve a maximum of 100 values per request.
-     * This value depend on the plattform you are running the server.
-     * A big server can serve more values, smaller ones less.
-     */
+
+    /* We want the server to serve a maximum of 100 values per request. This
+     * value depend on the plattform you are running the server. A big server
+     * can serve more values, smaller ones less. */
     setting.maxHistoryDataResponseSize = 100;
-    /*
-     * If we have a sensor which do not report updates
+
+    /* If we have a sensor which do not report updates
      * and need to be polled we change the setting like that.
      * The polling interval in ms.
      *
@@ -103,25 +98,22 @@ int main(void) {
     setting.historizingUpdateStrategy = UA_HISTORIZINGUPDATESTRATEGY_POLL;
      */
 
-    /*
-     * If you want to insert the values to the database yourself, we can set the user strategy here.
+    /* If you want to insert the values to the database yourself, we can set the user strategy here.
      * This is useful if you for example want a value stored, if a defined delta is reached.
      * Then you should use a local monitored item with a fuzziness and store the value in the callback.
      *
     setting.historizingUpdateStrategy = UA_HISTORIZINGUPDATESTRATEGY_USER;
      */
 
-    /*
-     * We want the values stored in the database, when the nodes value is set.
-     */
+    /* We want the values stored in the database, when the nodes value is
+     * set. */
     setting.historizingUpdateStrategy = UA_HISTORIZINGUPDATESTRATEGY_VALUESET;
-    /*
-     * At the end we register the node for gathering data in the database.
-     */
+
+    /* At the end we register the node for gathering data in the database. */
     retval = gathering.registerNodeId(server, gathering.context, &outNodeId, setting);
     UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "registerNodeId %s", UA_StatusCode_name(retval));
-    /*
-     * If you use UA_HISTORIZINGUPDATESTRATEGY_POLL, then start the polling.
+
+    /* If you use UA_HISTORIZINGUPDATESTRATEGY_POLL, then start the polling.
      *
     retval = gathering.startPoll(server, gathering.context, &outNodeId);
     UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "startPoll %s", UA_StatusCode_name(retval));
@@ -134,8 +126,7 @@ int main(void) {
     retval = gathering.stopPoll(server, gathering.context, &outNodeId);
     UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "stopPoll %s", UA_StatusCode_name(retval));
     */
-    UA_Server_run_shutdown(server);
+
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
     return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
 }

+ 3 - 3
examples/tutorial_server_method.c

@@ -174,14 +174,14 @@ int main(void) {
     signal(SIGINT, stopHandler);
     signal(SIGTERM, stopHandler);
 
-    UA_ServerConfig *config = UA_ServerConfig_new_default();
-    UA_Server *server = UA_Server_new(config);
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
 
     addHellWorldMethod(server);
     addIncInt32ArrayMethod(server);
 
     UA_StatusCode retval = UA_Server_run(server, &running);
+
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
     return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
 }

+ 3 - 3
examples/tutorial_server_monitoreditems.c

@@ -58,13 +58,13 @@ int main(void) {
     signal(SIGINT, stopHandler);
     signal(SIGTERM, stopHandler);
 
-    UA_ServerConfig *config = UA_ServerConfig_new_default();
-    UA_Server *server = UA_Server_new(config);
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
 
     addMonitoredItemToCurrentTimeVariable(server);
 
     UA_StatusCode retval = UA_Server_run(server, &running);
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
+
     return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
 }

+ 3 - 3
examples/tutorial_server_object.c

@@ -318,8 +318,8 @@ int main(void) {
     signal(SIGINT, stopHandler);
     signal(SIGTERM, stopHandler);
 
-    UA_ServerConfig *config = UA_ServerConfig_new_default();
-    UA_Server *server = UA_Server_new(config);
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
 
     manuallyDefinePump(server);
     defineObjectTypes(server);
@@ -330,7 +330,7 @@ int main(void) {
     addPumpObjectInstance(server, "pump5");
 
     UA_StatusCode retval = UA_Server_run(server, &running);
+
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
     return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
 }

+ 3 - 3
examples/tutorial_server_variable.c

@@ -109,15 +109,15 @@ int main(void) {
     signal(SIGINT, stopHandler);
     signal(SIGTERM, stopHandler);
 
-    UA_ServerConfig *config = UA_ServerConfig_new_default();
-    UA_Server *server = UA_Server_new(config);
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
 
     addVariable(server);
     writeVariable(server);
     writeWrongVariable(server);
 
     UA_StatusCode retval = UA_Server_run(server, &running);
+
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
     return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
 }

+ 3 - 3
examples/tutorial_server_variabletype.c

@@ -127,8 +127,8 @@ int main(void) {
     signal(SIGINT, stopHandler);
     signal(SIGTERM, stopHandler);
 
-    UA_ServerConfig *config = UA_ServerConfig_new_default();
-    UA_Server *server = UA_Server_new(config);
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
 
     addVariableType2DPoint(server);
     addVariable(server);
@@ -136,7 +136,7 @@ int main(void) {
     writeVariable(server);
 
     UA_StatusCode retval = UA_Server_run(server, &running);
+
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
     return retval == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
 }

+ 5 - 4
include/open62541/server.h

@@ -42,9 +42,13 @@ struct UA_Client;
  * Server Lifecycle
  * ---------------- */
 
-UA_Server UA_EXPORT * UA_Server_new(const UA_ServerConfig *config);
+UA_Server UA_EXPORT * UA_Server_new(void);
+
 void UA_EXPORT UA_Server_delete(UA_Server *server);
 
+UA_ServerConfig UA_EXPORT *
+UA_Server_getConfig(UA_Server *server);
+
 /* Runs the main loop of the server. In each iteration, this calls into the
  * networklayers to see if messages have arrived.
  *
@@ -1283,9 +1287,6 @@ UA_Server_updateCertificate(UA_Server *server,
 /* Add a new namespace to the server. Returns the index of the new namespace */
 UA_UInt16 UA_EXPORT UA_Server_addNamespace(UA_Server *server, const char* name);
 
-UA_ServerConfig*
-UA_Server_getConfig(UA_Server *server);
-
 /* Get namespace by name from the server. */
 UA_StatusCode UA_EXPORT
 UA_Server_getNamespaceByName(UA_Server *server, const UA_String namespaceUri,

+ 8 - 0
include/open62541/server_config.h

@@ -222,6 +222,14 @@ struct UA_ServerConfig {
 #endif
 };
 
+void UA_EXPORT
+UA_ServerConfig_clean(UA_ServerConfig *config);
+
+/* Set a custom hostname in server configuration */
+UA_EXPORT void
+UA_ServerConfig_setCustomHostname(UA_ServerConfig *config,
+                                  const UA_String customHostname);
+
 _UA_END_DECLS
 
 #endif /* UA_SERVER_CONFIG_H_ */

+ 26 - 54
plugins/include/open62541/server_config_default.h

@@ -17,7 +17,8 @@ _UA_BEGIN_DECLS
 /* Default Connection */
 /**********************/
 
-extern const UA_EXPORT UA_ConnectionConfig UA_ConnectionConfig_default;
+extern const UA_EXPORT
+UA_ConnectionConfig UA_ConnectionConfig_default;
 
 /*************************/
 /* Default Server Config */
@@ -37,75 +38,46 @@ extern const UA_EXPORT UA_ConnectionConfig UA_ConnectionConfig_default;
  * @param recvBufferSize The size in bytes for the network receive buffer
  *
  */
-UA_EXPORT UA_ServerConfig *
-UA_ServerConfig_new_customBuffer(UA_UInt16 portNumber, const UA_ByteString *certificate,
-                                 UA_UInt32 sendBufferSize, UA_UInt32 recvBufferSize);
+UA_EXPORT UA_StatusCode
+UA_ServerConfig_setMinimalCustomBuffer(UA_ServerConfig *config,
+                                       UA_UInt16 portNumber,
+                                       const UA_ByteString *certificate,
+                                       UA_UInt32 sendBufferSize,
+                                       UA_UInt32 recvBufferSize);
 
 /* 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``. */
-static UA_INLINE UA_ServerConfig *
-UA_ServerConfig_new_minimal(UA_UInt16 portNumber, const UA_ByteString *certificate) {
-    return UA_ServerConfig_new_customBuffer(portNumber, certificate, 0 ,0);
+ * server certificate may be supplied but is optional. */
+static UA_INLINE UA_StatusCode
+UA_ServerConfig_setMinimal(UA_ServerConfig *config, UA_UInt16 portNumber,
+                           const UA_ByteString *certificate) {
+    return UA_ServerConfig_setMinimalCustomBuffer(config, portNumber,
+                                                  certificate, 0, 0);
 }
 
 #ifdef UA_ENABLE_ENCRYPTION
 
-UA_EXPORT UA_ServerConfig *
-UA_ServerConfig_new_basic128rsa15(UA_UInt16 portNumber,
-                                  const UA_ByteString *certificate,
-                                  const UA_ByteString *privateKey,
-                                  const UA_ByteString *trustList,
-                                  size_t trustListSize,
-                                  const UA_ByteString *revocationList,
-                                  size_t revocationListSize);
-
-UA_EXPORT UA_ServerConfig *
-UA_ServerConfig_new_basic256sha256(UA_UInt16 portNumber,
-                                   const UA_ByteString *certificate,
-                                   const UA_ByteString *privateKey,
-                                   const UA_ByteString *trustList,
-                                   size_t trustListSize,
-                                   const UA_ByteString *revocationList,
-                                   size_t revocationListSize);
-
-UA_EXPORT UA_ServerConfig *
-UA_ServerConfig_new_allSecurityPolicies(UA_UInt16 portNumber,
-                                        const UA_ByteString *certificate,
-                                        const UA_ByteString *privateKey,
-                                        const UA_ByteString *trustList,
-                                        size_t trustListSize,
-                                        const UA_ByteString *revocationList,
-                                        size_t revocationListSize);
+UA_EXPORT UA_StatusCode
+UA_ServerConfig_setDefaultWithSecurityPolicies(UA_ServerConfig *conf,
+                                               UA_UInt16 portNumber,
+                                               const UA_ByteString *certificate,
+                                               const UA_ByteString *privateKey,
+                                               const UA_ByteString *trustList,
+                                               size_t trustListSize,
+                                               const UA_ByteString *revocationList,
+                                               size_t revocationListSize);
 
 #endif
 
 /* Creates a server config on the default port 4840 with no server
  * certificate. */
-static UA_INLINE UA_ServerConfig *
-UA_ServerConfig_new_default(void) {
-    return UA_ServerConfig_new_minimal(4840, NULL);
+static UA_INLINE UA_StatusCode
+UA_ServerConfig_setDefault(UA_ServerConfig *config) {
+    return UA_ServerConfig_setMinimal(config, 4840, NULL);
 }
 
-/* Set a custom hostname in server configuration
- *
- * @param config A valid server configuration
- * @param customHostname The custom hostname used by the server */
-
-UA_EXPORT void
-UA_ServerConfig_set_customHostname(UA_ServerConfig *config,
-                                   const UA_String customHostname);
-
-/* Frees allocated memory in the server config */
-UA_EXPORT void
-UA_ServerConfig_delete(UA_ServerConfig *config);
-
 _UA_END_DECLS
 
 #endif /* UA_SERVER_CONFIG_DEFAULT_H_ */

+ 96 - 413
plugins/ua_config_default.c

@@ -87,26 +87,15 @@ createEndpoint(UA_ServerConfig *conf, UA_EndpointDescription *endpoint,
     return UA_STATUSCODE_GOOD;
 }
 
-void
-UA_ServerConfig_set_customHostname(UA_ServerConfig *config, const UA_String customHostname) {
-    if(!config)
-        return;
-    UA_String_deleteMembers(&config->customHostname);
-    UA_String_copy(&customHostname, &config->customHostname);
-}
-
 static const size_t usernamePasswordsSize = 2;
 static UA_UsernamePasswordLogin usernamePasswords[2] = {
     {UA_STRING_STATIC("user1"), UA_STRING_STATIC("password")},
     {UA_STRING_STATIC("user2"), UA_STRING_STATIC("password1")}};
 
-static UA_ServerConfig *
-createDefaultConfig(void) {
-    UA_ServerConfig *conf = (UA_ServerConfig *)UA_malloc(sizeof(UA_ServerConfig));
-    if(!conf)
-        return NULL;
-
+static UA_StatusCode
+setDefaultConfig(UA_ServerConfig *conf) {
     /* Zero out.. All members have a valid initial value */
+    UA_ServerConfig_clean(conf);
     memset(conf, 0, sizeof(UA_ServerConfig));
 
     /* --> Start setting the default static config <-- */
@@ -163,10 +152,12 @@ createDefaultConfig(void) {
     conf->nodeLifecycle.constructor = NULL;
     conf->nodeLifecycle.destructor = NULL;
 
-    if (UA_AccessControl_default(&conf->accessControl, true, usernamePasswordsSize,
-            usernamePasswords) != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
+    UA_StatusCode retval = UA_AccessControl_default(&conf->accessControl, true,
+                                                    usernamePasswordsSize,
+                                                    usernamePasswords);
+    if(retval != UA_STATUSCODE_GOOD) {
+        UA_ServerConfig_clean(conf);
+        return retval;
     }
 
     /* Relax constraints for the InformationModel */
@@ -223,7 +214,7 @@ createDefaultConfig(void) {
 
     /* --> Finish setting the default static config <-- */
 
-    return conf;
+    return UA_STATUSCODE_GOOD;
 }
 
 static UA_StatusCode
@@ -250,319 +241,106 @@ addDefaultNetworkLayers(UA_ServerConfig *conf, UA_UInt16 portNumber,
     return UA_STATUSCODE_GOOD;
 }
 
-UA_ServerConfig *
-UA_ServerConfig_new_customBuffer(UA_UInt16 portNumber,
-                                 const UA_ByteString *certificate,
-                                 UA_UInt32 sendBufferSize,
-                                 UA_UInt32 recvBufferSize) {
-    UA_ServerConfig *conf = createDefaultConfig();
-    if (!conf) {
-        return NULL;
-    }
-
-    UA_StatusCode retval = UA_Nodestore_default_new(&conf->nodestore);
+UA_EXPORT UA_StatusCode
+UA_ServerConfig_setMinimalCustomBuffer(UA_ServerConfig *config, UA_UInt16 portNumber,
+                                       const UA_ByteString *certificate,
+                                       UA_UInt32 sendBufferSize,
+                                       UA_UInt32 recvBufferSize) {
+    UA_StatusCode retval = setDefaultConfig(config);
     if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
+        UA_ServerConfig_clean(config);
+        return retval;
     }
 
-    retval = addDefaultNetworkLayers(conf, portNumber, sendBufferSize, recvBufferSize);
+    retval = addDefaultNetworkLayers(config, portNumber, sendBufferSize, recvBufferSize);
     if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
+        UA_ServerConfig_clean(config);
+        return retval;
     }
 
     /* Allocate the SecurityPolicies */
-    conf->securityPolicies = (UA_SecurityPolicy *)UA_malloc(sizeof(UA_SecurityPolicy));
-    if(!conf->securityPolicies) {
-       UA_ServerConfig_delete(conf);
-       return NULL;
+    config->securityPolicies = (UA_SecurityPolicy *)UA_malloc(sizeof(UA_SecurityPolicy));
+    if(!config->securityPolicies) {
+        UA_ServerConfig_clean(config);
+        return retval;
     }
-    conf->securityPoliciesSize = 1;
+    config->securityPoliciesSize = 1;
 
     /* Populate the SecurityPolicies */
     UA_ByteString localCertificate = UA_BYTESTRING_NULL;
     if(certificate)
         localCertificate = *certificate;
-    retval = UA_SecurityPolicy_None(&conf->securityPolicies[0], NULL,
-                                    localCertificate, &conf->logger);
+    retval = UA_SecurityPolicy_None(&config->securityPolicies[0], NULL,
+                                    localCertificate, &config->logger);
     if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
+        UA_ServerConfig_clean(config);
+        return retval;
     }
 
     /* Allocate the endpoint */
-    conf->endpoints = (UA_EndpointDescription *)UA_malloc(sizeof(UA_EndpointDescription));
-    if(!conf->endpoints) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
+    config->endpoints = (UA_EndpointDescription *)
+        UA_malloc(sizeof(UA_EndpointDescription));
+    if(!config->endpoints) {
+        UA_ServerConfig_clean(config);
+        return retval;
     }
-    conf->endpointsSize = 1;
+    config->endpointsSize = 1;
 
     /* Populate the endpoint */
-    retval = createEndpoint(conf, &conf->endpoints[0], &conf->securityPolicies[0],
+    retval = createEndpoint(config, &config->endpoints[0],
+                            &config->securityPolicies[0],
                             UA_MESSAGESECURITYMODE_NONE);
     if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
+        UA_ServerConfig_clean(config);
+        return retval;
     }
 
-    return conf;
+    return UA_STATUSCODE_GOOD;
 }
 
 #ifdef UA_ENABLE_ENCRYPTION
 
-UA_ServerConfig *
-UA_ServerConfig_new_basic128rsa15(UA_UInt16 portNumber,
-                                  const UA_ByteString *certificate,
-                                  const UA_ByteString *privateKey,
-                                  const UA_ByteString *trustList,
-                                  size_t trustListSize,
-                                  const UA_ByteString *revocationList,
-                                  size_t revocationListSize) {
-    UA_ServerConfig *conf = createDefaultConfig();
-    if(!conf)
-        return NULL;
-
-    UA_StatusCode retval =
-        UA_CertificateVerification_Trustlist(&conf->certificateVerification,
-                                             trustList, trustListSize,
-                                             revocationList, revocationListSize);
-    if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
-    }
-
-    retval = UA_Nodestore_default_new(&conf->nodestore);
-    if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
-    }
-
-    retval = addDefaultNetworkLayers(conf, portNumber, 0, 0);
-    if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
-    }
-
-    if(trustListSize == 0)
-        UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
-                       "No CA trust-list provided. Any remote certificate will be accepted.");
-
-    /* Allocate the SecurityPolicies */
-    conf->securityPoliciesSize = 0;
-    conf->securityPolicies = (UA_SecurityPolicy *)UA_malloc(sizeof(UA_SecurityPolicy) * 2);
-    if(!conf->securityPolicies) {
-       UA_ServerConfig_delete(conf);
-       return NULL;
-    }
-
-    /* Populate the SecurityPolicies */
-    UA_ByteString localCertificate = UA_BYTESTRING_NULL;
-    UA_ByteString localPrivateKey  = UA_BYTESTRING_NULL;
-    if(certificate)
-        localCertificate = *certificate;
-    if(privateKey)
-       localPrivateKey = *privateKey;
-
-    ++conf->securityPoliciesSize;
-    retval = UA_SecurityPolicy_None(&conf->securityPolicies[0], NULL,
-                                    localCertificate, &conf->logger);
-    if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
-    }
-    ++conf->securityPoliciesSize;
-
-    retval = UA_SecurityPolicy_Basic128Rsa15(&conf->securityPolicies[1],
-                                             &conf->certificateVerification,
-                                             localCertificate, localPrivateKey,
-                                             &conf->logger);
-    if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
-    }
-
-    /* Allocate the endpoints */
-    conf->endpointsSize = 0;
-    conf->endpoints = (UA_EndpointDescription *)
-        UA_malloc(sizeof(UA_EndpointDescription) * 3);
-    if(!conf->endpoints) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
-    }
-
-    /* Populate the endpoints */
-    ++conf->endpointsSize;
-    retval = createEndpoint(conf, &conf->endpoints[0], &conf->securityPolicies[0],
-                            UA_MESSAGESECURITYMODE_NONE);
-    if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
-    }
-
-    ++conf->endpointsSize;
-    retval = createEndpoint(conf, &conf->endpoints[1], &conf->securityPolicies[1],
-                            UA_MESSAGESECURITYMODE_SIGN);
-    if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
-    }
-
-    ++conf->endpointsSize;
-    retval = createEndpoint(conf, &conf->endpoints[2], &conf->securityPolicies[1],
-                            UA_MESSAGESECURITYMODE_SIGNANDENCRYPT);
-    if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
-    }
-
-    return conf;
-}
-
-UA_ServerConfig *
-UA_ServerConfig_new_basic256sha256(UA_UInt16 portNumber,
-                                   const UA_ByteString *certificate,
-                                   const UA_ByteString *privateKey,
-                                   const UA_ByteString *trustList,
-                                   size_t trustListSize,
-                                   const UA_ByteString *revocationList,
-                                   size_t revocationListSize) {
-    UA_ServerConfig *conf = createDefaultConfig();
-    if(!conf)
-        return NULL;
-
-    UA_StatusCode retval =
-        UA_CertificateVerification_Trustlist(&conf->certificateVerification,
-                                             trustList, trustListSize,
-                                             revocationList, revocationListSize);
-    if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
-    }
-
-    retval = addDefaultNetworkLayers(conf, portNumber, 0, 0);
-    if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
-    }
-
-    if(trustListSize == 0)
-        UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
-                       "No CA trust-list provided. Any remote certificate will be accepted.");
-
-    /* Allocate the SecurityPolicies */
-    conf->securityPoliciesSize = 0;
-    conf->securityPolicies = (UA_SecurityPolicy *)UA_malloc(sizeof(UA_SecurityPolicy) * 2);
-    if(!conf->securityPolicies) {
-       UA_ServerConfig_delete(conf);
-       return NULL;
-    }
-
-    /* Populate the SecurityPolicies */
-    UA_ByteString localCertificate = UA_BYTESTRING_NULL;
-    UA_ByteString localPrivateKey  = UA_BYTESTRING_NULL;
-    if(certificate)
-        localCertificate = *certificate;
-    if(privateKey)
-       localPrivateKey = *privateKey;
-    ++conf->securityPoliciesSize;
-    retval = UA_SecurityPolicy_None(&conf->securityPolicies[0], NULL,
-                                    localCertificate, &conf->logger);
-    if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
-    }
-    ++conf->securityPoliciesSize;
-    retval = UA_SecurityPolicy_Basic256Sha256(&conf->securityPolicies[1],
-                                              &conf->certificateVerification,
-                                              localCertificate, localPrivateKey,
-                                              &conf->logger);
-    if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
-    }
-
-    /* Allocate the endpoints */
-    conf->endpointsSize = 0;
-    conf->endpoints = (UA_EndpointDescription *)
-        UA_malloc(sizeof(UA_EndpointDescription) * 3);
-    if(!conf->endpoints) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
-    }
-
-    /* Populate the endpoints */
-    ++conf->endpointsSize;
-    retval = createEndpoint(conf, &conf->endpoints[0], &conf->securityPolicies[0],
-                            UA_MESSAGESECURITYMODE_NONE);
-    if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
-    }
-
-    ++conf->endpointsSize;
-    retval = createEndpoint(conf, &conf->endpoints[1], &conf->securityPolicies[1],
-                            UA_MESSAGESECURITYMODE_SIGN);
-    if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
-    }
-
-    ++conf->endpointsSize;
-    retval = createEndpoint(conf, &conf->endpoints[2], &conf->securityPolicies[1],
-                            UA_MESSAGESECURITYMODE_SIGNANDENCRYPT);
-    if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
-    }
-
-    return conf;
-}
-
-UA_ServerConfig *
-UA_ServerConfig_new_allSecurityPolicies(UA_UInt16 portNumber,
-                                        const UA_ByteString *certificate,
-                                        const UA_ByteString *privateKey,
-                                        const UA_ByteString *trustList,
-                                        size_t trustListSize,
-                                        const UA_ByteString *revocationList,
-                                        size_t revocationListSize) {
-    UA_ServerConfig *conf = createDefaultConfig();
-    if(!conf)
-        return NULL;
-
-    UA_StatusCode retval =
-        UA_CertificateVerification_Trustlist(&conf->certificateVerification,
-                                             trustList, trustListSize,
-                                             revocationList, revocationListSize);
-    if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
+UA_EXPORT UA_StatusCode
+UA_ServerConfig_setDefaultWithSecurityPolicies(UA_ServerConfig *conf,
+                                               UA_UInt16 portNumber,
+                                               const UA_ByteString *certificate,
+                                               const UA_ByteString *privateKey,
+                                               const UA_ByteString *trustList,
+                                               size_t trustListSize,
+                                               const UA_ByteString *revocationList,
+                                               size_t revocationListSize) {
+    UA_StatusCode retval = setDefaultConfig(conf);
+    if(retval != UA_STATUSCODE_GOOD) {
+        UA_ServerConfig_clean(conf);
+        return retval;
     }
 
-    retval = UA_Nodestore_default_new(&conf->nodestore);
+    retval = UA_CertificateVerification_Trustlist(&conf->certificateVerification,
+                                                  trustList, trustListSize,
+                                                  revocationList, revocationListSize);
     if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
+        UA_ServerConfig_clean(conf);
+        return retval;
     }
 
     retval = addDefaultNetworkLayers(conf, portNumber, 0, 0);
     if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
+        UA_ServerConfig_clean(conf);
+        return retval;
     }
 
     if(trustListSize == 0)
         UA_LOG_WARNING(UA_Log_Stdout, UA_LOGCATEGORY_USERLAND,
-                       "No CA trust-list provided. Any remote certificate will be accepted.");
+                       "No CA trust-list provided. "
+                       "Any remote certificate will be accepted.");
 
     /* Allocate the SecurityPolicies */
     conf->securityPoliciesSize = 0;
-    conf->securityPolicies = (UA_SecurityPolicy *)UA_malloc(sizeof(UA_SecurityPolicy) * 4);
+    conf->securityPolicies = (UA_SecurityPolicy *)
+        UA_malloc(sizeof(UA_SecurityPolicy) * 4);
     if(!conf->securityPolicies) {
-       UA_ServerConfig_delete(conf);
-       return NULL;
+       UA_ServerConfig_clean(conf);
+       return retval;
     }
 
     /* Populate the SecurityPolicies */
@@ -576,8 +354,8 @@ UA_ServerConfig_new_allSecurityPolicies(UA_UInt16 portNumber,
     retval = UA_SecurityPolicy_None(&conf->securityPolicies[0], NULL,
                                     localCertificate, &conf->logger);
     if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
+        UA_ServerConfig_clean(conf);
+        return retval;
     }
     ++conf->securityPoliciesSize;
 
@@ -586,26 +364,28 @@ UA_ServerConfig_new_allSecurityPolicies(UA_UInt16 portNumber,
                                              localCertificate, localPrivateKey,
                                              &conf->logger);
     if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
+        UA_ServerConfig_clean(conf);
+        return retval;
     }
     ++conf->securityPoliciesSize;
 
     retval = UA_SecurityPolicy_Basic256(&conf->securityPolicies[2],
                                         &conf->certificateVerification,
-                                        localCertificate, localPrivateKey, &conf->logger);
+                                        localCertificate, localPrivateKey,
+                                        &conf->logger);
     if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
+        UA_ServerConfig_clean(conf);
+        return retval;
     }
     ++conf->securityPoliciesSize;
 
     retval = UA_SecurityPolicy_Basic256Sha256(&conf->securityPolicies[3],
                                               &conf->certificateVerification,
-                                              localCertificate, localPrivateKey, &conf->logger);
+                                              localCertificate, localPrivateKey,
+                                              &conf->logger);
     if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
+        UA_ServerConfig_clean(conf);
+        return retval;
     }
     ++conf->securityPoliciesSize;
 
@@ -614,168 +394,71 @@ UA_ServerConfig_new_allSecurityPolicies(UA_UInt16 portNumber,
     conf->endpoints = (UA_EndpointDescription *)
         UA_malloc(sizeof(UA_EndpointDescription) * 7);
     if(!conf->endpoints) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
+        UA_ServerConfig_clean(conf);
+        return retval;
     }
 
     /* Populate the endpoints */
     retval = createEndpoint(conf, &conf->endpoints[conf->endpointsSize],
                             &conf->securityPolicies[0], UA_MESSAGESECURITYMODE_NONE);
     if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
+        UA_ServerConfig_clean(conf);
+        return retval;
     }
     ++conf->endpointsSize;
 
     retval = createEndpoint(conf, &conf->endpoints[conf->endpointsSize],
                             &conf->securityPolicies[1], UA_MESSAGESECURITYMODE_SIGN);
     if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
+        UA_ServerConfig_clean(conf);
+        return retval;
     }
     ++conf->endpointsSize;
 
     retval = createEndpoint(conf, &conf->endpoints[conf->endpointsSize],
                             &conf->securityPolicies[1], UA_MESSAGESECURITYMODE_SIGNANDENCRYPT);
     if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
+        UA_ServerConfig_clean(conf);
+        return retval;
     }
     ++conf->endpointsSize;
 
     retval = createEndpoint(conf, &conf->endpoints[conf->endpointsSize],
                             &conf->securityPolicies[2], UA_MESSAGESECURITYMODE_SIGN);
     if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
+        UA_ServerConfig_clean(conf);
+        return retval;
     }
     ++conf->endpointsSize;
 
     retval = createEndpoint(conf, &conf->endpoints[conf->endpointsSize],
                             &conf->securityPolicies[2], UA_MESSAGESECURITYMODE_SIGNANDENCRYPT);
     if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
+        UA_ServerConfig_clean(conf);
+        return retval;
     }
     ++conf->endpointsSize;
 
     retval = createEndpoint(conf, &conf->endpoints[conf->endpointsSize],
                             &conf->securityPolicies[3], UA_MESSAGESECURITYMODE_SIGN);
     if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
+        UA_ServerConfig_clean(conf);
+        return retval;
     }
     ++conf->endpointsSize;
 
     retval = createEndpoint(conf, &conf->endpoints[conf->endpointsSize],
                             &conf->securityPolicies[3], UA_MESSAGESECURITYMODE_SIGNANDENCRYPT);
     if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(conf);
-        return NULL;
+        UA_ServerConfig_clean(conf);
+        return retval;
     }
     ++conf->endpointsSize;
 
-    return conf;
-}
-
-
-#endif
-
-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
-
-    /* Nodestore */
-    if(config->nodestore.deleteNodestore)
-        config->nodestore.deleteNodestore(config->nodestore.context);
-
-    /* Custom DataTypes */
-    /* nothing to do */
-
-    /* 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;
-    UA_String_deleteMembers(&config->customHostname);
-    config->customHostname = UA_STRING_NULL;
-
-    for(size_t i = 0; i < config->securityPoliciesSize; ++i) {
-        UA_SecurityPolicy *policy = &config->securityPolicies[i];
-        policy->deleteMembers(policy);
-    }
-    UA_free(config->securityPolicies);
-    config->securityPolicies = NULL;
-    config->securityPoliciesSize = 0;
-
-    for(size_t i = 0; i < config->endpointsSize; ++i)
-        UA_EndpointDescription_deleteMembers(&config->endpoints[i]);
-
-    UA_free(config->endpoints);
-    config->endpoints = NULL;
-    config->endpointsSize = 0;
-
-    /* Certificate Validation */
-    config->certificateVerification.deleteMembers(&config->certificateVerification);
-
-    /* Access Control */
-    config->accessControl.deleteMembers(&config->accessControl);
-
-    /* Historical data */
-#ifdef UA_ENABLE_HISTORIZING
-    if(config->historyDatabase.deleteMembers)
-        config->historyDatabase.deleteMembers(&config->historyDatabase);
-#endif
-
-    /* Logger */
-    if(config->logger.clear)
-        config->logger.clear(config->logger.context);
-
-    UA_free(config);
-}
-
-
-#ifdef UA_ENABLE_PUBSUB /* conditional compilation */
-/**
- * Add a pubsubTransportLayer to the configuration.
- * Memory is reallocated on demand */
-UA_StatusCode
-UA_ServerConfig_addPubSubTransportLayer(UA_ServerConfig *config,
-        UA_PubSubTransportLayer *pubsubTransportLayer) {
-
-    if(config->pubsubTransportLayersSize == 0) {
-        config->pubsubTransportLayers = (UA_PubSubTransportLayer *)
-                UA_malloc(sizeof(UA_PubSubTransportLayer));
-    } else {
-        config->pubsubTransportLayers = (UA_PubSubTransportLayer*)
-                UA_realloc(config->pubsubTransportLayers,
-                sizeof(UA_PubSubTransportLayer) * (config->pubsubTransportLayersSize + 1));
-    }
-
-    if(config->pubsubTransportLayers == NULL)
-        return UA_STATUSCODE_BADOUTOFMEMORY;
-
-    memcpy(&config->pubsubTransportLayers[config->pubsubTransportLayersSize],
-            pubsubTransportLayer, sizeof(UA_PubSubTransportLayer));
-    config->pubsubTransportLayersSize++;
-
     return UA_STATUSCODE_GOOD;
 }
-#endif /* UA_ENABLE_PUBSUB */
 
+#endif
 
 /***************************/
 /* Default Client Settings */

+ 15 - 15
src/server/ua_server.c

@@ -168,6 +168,9 @@ void UA_Server_delete(UA_Server *server) {
     /* Clean up the nodestore */
     UA_Nodestore_delete(server->nsCtx);
 
+    /* Clean up the config */
+    UA_ServerConfig_clean(&server->config);
+
     /* Delete the server itself */
     UA_free(server);
 }
@@ -188,19 +191,12 @@ UA_Server_cleanup(UA_Server *server, void *_) {
 /********************/
 
 UA_Server *
-UA_Server_new(const UA_ServerConfig *config) {
-    /* A config is required */
-    if(!config)
-        return NULL;
-
+UA_Server_new() {
     /* Allocate the server */
     UA_Server *server = (UA_Server *)UA_calloc(1, sizeof(UA_Server));
     if(!server)
         return NULL;
 
-    /* Set the config */
-    server->config = *config;
-
     /* Init start time to zero, the actual start time will be sampled in
      * UA_Server_run_startup() */
     server->startTime = 0;
@@ -235,11 +231,6 @@ UA_Server_new(const UA_ServerConfig *config) {
     UA_Server_addRepeatedCallback(server, (UA_ServerCallback)UA_Server_cleanup, NULL,
                                   10000.0, NULL);
 
-    /* Initialized discovery */
-#ifdef UA_ENABLE_DISCOVERY
-    UA_DiscoveryManager_init(&server->discoveryManager, server);
-#endif
-
     /* Initialize namespace 0*/
     UA_StatusCode retVal = UA_Nodestore_new(&server->nsCtx);
     if(retVal != UA_STATUSCODE_GOOD)
@@ -404,8 +395,8 @@ verifyServerApplicationURI(const UA_Server *server) {
 
 UA_StatusCode
 UA_Server_run_startup(UA_Server *server) {
-    UA_Variant var;
-    UA_StatusCode result = UA_STATUSCODE_GOOD;
+    if(server->state > UA_SERVERLIFECYCLE_FRESH)
+        return UA_STATUSCODE_GOOD;
     
     /* At least one endpoint has to be configured */
     if(server->config.endpointsSize == 0) {
@@ -413,6 +404,11 @@ UA_Server_run_startup(UA_Server *server) {
                        "There has to be at least one endpoint.");
     }
 
+    /* Initialized discovery */
+#ifdef UA_ENABLE_DISCOVERY
+    UA_DiscoveryManager_init(&server->discoveryManager, server);
+#endif
+
     /* Does the ApplicationURI match the local certificates? */
 #ifdef UA_ENABLE_ENCRYPTION
     verifyServerApplicationURI(server);
@@ -420,6 +416,7 @@ UA_Server_run_startup(UA_Server *server) {
 
     /* Sample the start time and set it to the Server object */
     server->startTime = UA_DateTime_now();
+    UA_Variant var;
     UA_Variant_init(&var);
     UA_Variant_setScalar(&var, &server->startTime, &UA_TYPES[UA_TYPES_DATETIME]);
     UA_Server_writeValue(server,
@@ -427,6 +424,7 @@ UA_Server_run_startup(UA_Server *server) {
                          var);
 
     /* Start the networklayers */
+    UA_StatusCode result = UA_STATUSCODE_GOOD;
     for(size_t i = 0; i < server->config.networkLayersSize; ++i) {
         UA_ServerNetworkLayer *nl = &server->config.networkLayers[i];
         result |= nl->start(nl, &server->config.customHostname);
@@ -446,6 +444,8 @@ UA_Server_run_startup(UA_Server *server) {
         startMulticastDiscoveryServer(server);
 #endif
 
+    server->state = UA_SERVERLIFECYCLE_FRESH;
+
     return result;
 }
 

+ 106 - 0
src/server/ua_server_config.c

@@ -0,0 +1,106 @@
+/* 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/. 
+ *
+ *    Copyright 2019 (c) Fraunhofer IOSB (Author: Julius Pfrommer)
+ */
+
+#include <open62541/server_config.h>
+
+void
+UA_ServerConfig_clean(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 */
+    /* nothing to do */
+
+    /* 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;
+    UA_String_deleteMembers(&config->customHostname);
+    config->customHostname = UA_STRING_NULL;
+
+    for(size_t i = 0; i < config->securityPoliciesSize; ++i) {
+        UA_SecurityPolicy *policy = &config->securityPolicies[i];
+        policy->deleteMembers(policy);
+    }
+    UA_free(config->securityPolicies);
+    config->securityPolicies = NULL;
+    config->securityPoliciesSize = 0;
+
+    for(size_t i = 0; i < config->endpointsSize; ++i)
+        UA_EndpointDescription_deleteMembers(&config->endpoints[i]);
+
+    UA_free(config->endpoints);
+    config->endpoints = NULL;
+    config->endpointsSize = 0;
+
+    /* Certificate Validation */
+    if(config->certificateVerification.deleteMembers)
+        config->certificateVerification.deleteMembers(&config->certificateVerification);
+
+    /* Access Control */
+    if(config->accessControl.deleteMembers)
+        config->accessControl.deleteMembers(&config->accessControl);
+
+    /* Historical data */
+#ifdef UA_ENABLE_HISTORIZING
+    if(config->historyDatabase.deleteMembers)
+        config->historyDatabase.deleteMembers(&config->historyDatabase);
+#endif
+
+    /* Logger */
+    if(config->logger.clear)
+        config->logger.clear(config->logger.context);
+}
+
+void
+UA_ServerConfig_setCustomHostname(UA_ServerConfig *config,
+                                  const UA_String customHostname) {
+    if(!config)
+        return;
+    UA_String_deleteMembers(&config->customHostname);
+    UA_String_copy(&customHostname, &config->customHostname);
+}
+
+#ifdef UA_ENABLE_PUBSUB
+/* Add a pubsubTransportLayer to the configuration. Memory is reallocated on
+ * demand. */
+UA_StatusCode
+UA_ServerConfig_addPubSubTransportLayer(UA_ServerConfig *config,
+        UA_PubSubTransportLayer *pubsubTransportLayer) {
+
+    if(config->pubsubTransportLayersSize == 0) {
+        config->pubsubTransportLayers = (UA_PubSubTransportLayer *)
+                UA_malloc(sizeof(UA_PubSubTransportLayer));
+    } else {
+        config->pubsubTransportLayers = (UA_PubSubTransportLayer*)
+                UA_realloc(config->pubsubTransportLayers,
+                sizeof(UA_PubSubTransportLayer) * (config->pubsubTransportLayersSize + 1));
+    }
+
+    if(config->pubsubTransportLayers == NULL)
+        return UA_STATUSCODE_BADOUTOFMEMORY;
+
+    memcpy(&config->pubsubTransportLayers[config->pubsubTransportLayersSize],
+            pubsubTransportLayer, sizeof(UA_PubSubTransportLayer));
+    config->pubsubTransportLayersSize++;
+
+    return UA_STATUSCODE_GOOD;
+}
+#endif /* UA_ENABLE_PUBSUB */

+ 7 - 0
src/server/ua_server_internal.h

@@ -49,6 +49,11 @@ typedef struct {
 
 #endif
 
+typedef enum {
+    UA_SERVERLIFECYCLE_FRESH,
+    UA_SERVERLIFECYLE_RUNNING
+} UA_ServerLifecycle;
+
 struct UA_Server {
     /* Config */
     UA_ServerConfig config;
@@ -57,6 +62,8 @@ struct UA_Server {
     /* Nodestore */
     void *nsCtx;
 
+    UA_ServerLifecycle state;
+
     /* Security */
     UA_SecureChannelManager secureChannelManager;
     UA_SessionManager sessionManager;

+ 2 - 4
tests/client/check_client.c

@@ -16,7 +16,6 @@
 #include "thread_wrapper.h"
 
 UA_Server *server;
-UA_ServerConfig *config;
 UA_Boolean running;
 UA_ServerNetworkLayer nl;
 THREAD_HANDLE server_thread;
@@ -55,8 +54,8 @@ THREAD_CALLBACK(serverloop) {
 
 static void setup(void) {
     running = true;
-    config = UA_ServerConfig_new_default();
-    server = UA_Server_new(config);
+    server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
     UA_Server_run_startup(server);
     addVariable(16366);
     THREAD_CREATE(server_thread, serverloop);
@@ -67,7 +66,6 @@ static void teardown(void) {
     THREAD_JOIN(server_thread);
     UA_Server_run_shutdown(server);
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
 }
 
 START_TEST(Client_connect) {

+ 3 - 3
tests/client/check_client_async.c

@@ -32,8 +32,9 @@ THREAD_CALLBACK(serverloop) {
 
 static void setup(void) {
     running = true;
-    config = UA_ServerConfig_new_default();
-    server = UA_Server_new(config);
+    server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
+
     UA_Server_run_startup(server);
     THREAD_CREATE(server_thread, serverloop);
 }
@@ -43,7 +44,6 @@ static void teardown(void) {
     THREAD_JOIN(server_thread);
     UA_Server_run_shutdown(server);
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
 }
 
 static void asyncReadCallback(UA_Client *client, void *userdata,

+ 5 - 7
tests/client/check_client_async_connect.c

@@ -18,7 +18,6 @@
 #include "thread_wrapper.h"
 
 UA_Server *server;
-UA_ServerConfig *config;
 UA_Boolean running;
 UA_ServerNetworkLayer nl;
 THREAD_HANDLE server_thread;
@@ -30,16 +29,16 @@ THREAD_CALLBACK(serverloop) {
 }
 
 static void
-onConnect (UA_Client *Client, void *connected, UA_UInt32 requestId,
-           void *response) {
+onConnect(UA_Client *Client, void *connected,
+          UA_UInt32 requestId, void *response) {
     if (UA_Client_getState (Client) == UA_CLIENTSTATE_SESSION)
         *(UA_Boolean *)connected = true;
 }
 
 static void setup(void) {
     running = true;
-    config = UA_ServerConfig_new_default();
-    server = UA_Server_new(config);
+    server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
     UA_Server_run_startup(server);
     THREAD_CREATE(server_thread, serverloop);
     /* Waiting server is up */
@@ -51,7 +50,6 @@ static void teardown(void) {
     THREAD_JOIN(server_thread);
     UA_Server_run_shutdown(server);
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
 }
 
 static void
@@ -80,7 +78,7 @@ START_TEST(Client_connect_async){
     bReq.nodesToBrowse[0].resultMask = UA_BROWSERESULTMASK_ALL; /* return everything */
     /* Connected gets updated when client is connected */
 
-    do{
+    do {
         if(connected) {
             /* If not connected requests are not sent */
             UA_Client_sendAsyncBrowseRequest (client, &bReq, asyncBrowseCallback,

+ 2 - 4
tests/client/check_client_highlevel.c

@@ -13,7 +13,6 @@
 #include "thread_wrapper.h"
 
 UA_Server *server;
-UA_ServerConfig *config;
 UA_Boolean running;
 UA_ServerNetworkLayer nl;
 THREAD_HANDLE server_thread;
@@ -31,8 +30,8 @@ THREAD_CALLBACK(serverloop) {
 
 static void setup(void) {
     running = true;
-    config = UA_ServerConfig_new_default();
-    server = UA_Server_new(config);
+    server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
 
     ck_assert_uint_eq(2, UA_Server_addNamespace(server, CUSTOM_NS));
 
@@ -52,7 +51,6 @@ static void teardown(void) {
     THREAD_JOIN(server_thread);
     UA_Server_run_shutdown(server);
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
 }
 
 START_TEST(Misc_State) {

+ 14 - 13
tests/client/check_client_historical_data.c

@@ -28,7 +28,6 @@
 #include <stddef.h>
 
 static UA_Server *server;
-static UA_ServerConfig *config;
 #ifdef UA_ENABLE_HISTORIZING
 static UA_HistoryDataGathering *gathering;
 #endif
@@ -53,22 +52,22 @@ static struct ReceiveTupel receivedTestData[(sizeof(testData) / sizeof(testData[
 static size_t receivedTestDataPos;
 #endif
 
-THREAD_CALLBACK(serverloop)
-{
+THREAD_CALLBACK(serverloop) {
     while(running)
         UA_Server_run_iterate(server, true);
     return 0;
 }
+
 #ifdef UA_ENABLE_HISTORIZING
 static UA_Boolean
 fillHistoricalDataBackend(UA_HistoryDataBackend backend);
-static void resetReceiveBuffer(void)
-{
+static void resetReceiveBuffer(void) {
     receivedTestDataPos = 0;
     memset(receivedTestData, 0, sizeof(receivedTestData));
 }
-static void fillInt64DataValue(UA_DateTime timestamp, UA_Int64 value, UA_DataValue *dataValue)
-{
+
+static void fillInt64DataValue(UA_DateTime timestamp, UA_Int64 value,
+                               UA_DataValue *dataValue) {
     UA_DataValue_init(dataValue);
     dataValue->hasValue = true;
     UA_Int64 d = value;
@@ -81,18 +80,20 @@ static void fillInt64DataValue(UA_DateTime timestamp, UA_Int64 value, UA_DataVal
     dataValue->status = UA_STATUSCODE_GOOD;
 }
 #endif
-static void
-setup(void)
-{
+
+static void setup(void) {
     running = true;
-    config = UA_ServerConfig_new_default();
+    server = UA_Server_new();
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+    UA_ServerConfig_setDefault(config);
+
 #ifdef UA_ENABLE_HISTORIZING
     resetReceiveBuffer();
     gathering = (UA_HistoryDataGathering*)UA_calloc(1, sizeof(UA_HistoryDataGathering));
     *gathering = UA_HistoryDataGathering_Default(1);
     config->historyDatabase = UA_HistoryDatabase_default(*gathering);
 #endif
-    server = UA_Server_new(config);
+
     UA_StatusCode retval = UA_Server_run_startup(server);
     ck_assert_str_eq(UA_StatusCode_name(retval), UA_StatusCode_name(UA_STATUSCODE_GOOD));
     THREAD_CREATE(server_thread, serverloop);
@@ -134,6 +135,7 @@ setup(void)
 
     ck_assert(fillHistoricalDataBackend(setting.historizingBackend));
 #endif
+
     client = UA_Client_new();
     UA_ClientConfig_setDefault(UA_Client_getConfig(client));
     retval = UA_Client_connect(client, "opc.tcp://localhost:4840");
@@ -159,7 +161,6 @@ teardown(void)
     THREAD_JOIN(server_thread);
     UA_Server_run_shutdown(server);
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
 #ifdef UA_ENABLE_HISTORIZING
     UA_free(gathering);
 #endif

+ 2 - 4
tests/client/check_client_securechannel.c

@@ -16,7 +16,6 @@
 #include "thread_wrapper.h"
 
 UA_Server *server;
-UA_ServerConfig *config;
 UA_Boolean running;
 THREAD_HANDLE server_thread;
 
@@ -28,8 +27,8 @@ THREAD_CALLBACK(serverloop) {
 
 static void setup(void) {
     running = true;
-    config = UA_ServerConfig_new_default();
-    server = UA_Server_new(config);
+    server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
     UA_Server_run_startup(server);
     THREAD_CREATE(server_thread, serverloop);
     UA_realSleep(100);
@@ -40,7 +39,6 @@ static void teardown(void) {
     THREAD_JOIN(server_thread);
     UA_Server_run_shutdown(server);
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
 }
 
 START_TEST(SecureChannel_timeout_max) {

+ 3 - 4
tests/client/check_client_subscriptions.c

@@ -18,7 +18,6 @@
 #include "thread_wrapper.h"
 
 UA_Server *server;
-UA_ServerConfig *config;
 UA_Boolean running;
 UA_ServerNetworkLayer nl;
 THREAD_HANDLE server_thread;
@@ -31,9 +30,10 @@ THREAD_CALLBACK(serverloop) {
 
 static void setup(void) {
     running = true;
-    config = UA_ServerConfig_new_default();
+    server = UA_Server_new();
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+    UA_ServerConfig_setDefault(config);
     config->maxPublishReqPerSession = 5;
-    server = UA_Server_new(config);
     UA_Server_run_startup(server);
     THREAD_CREATE(server_thread, serverloop);
 }
@@ -43,7 +43,6 @@ static void teardown(void) {
     THREAD_JOIN(server_thread);
     UA_Server_run_shutdown(server);
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
 }
 
 #ifdef UA_ENABLE_SUBSCRIPTIONS

+ 6 - 19
tests/encryption/check_encryption_basic128rsa15.c

@@ -19,7 +19,6 @@
 #include "thread_wrapper.h"
 
 UA_Server *server;
-UA_ServerConfig *config;
 UA_Boolean running;
 UA_ServerNetworkLayer nl;
 THREAD_HANDLE server_thread;
@@ -58,14 +57,15 @@ static void setup(void) {
     UA_ByteString *revocationList = NULL;
     size_t revocationListSize = 0;
 
-    config = UA_ServerConfig_new_basic128rsa15(4840, &certificate, &privateKey,
-                                               trustList, trustListSize,
-                                               revocationList, revocationListSize);
+    server = UA_Server_new();
+    UA_ServerConfig_setDefaultWithSecurityPolicies(UA_Server_getConfig(server),
+                                                   4840, &certificate, &privateKey,
+                                                   trustList, trustListSize,
+                                                   revocationList, revocationListSize);
 
     for(size_t i = 0; i < trustListSize; i++)
         UA_ByteString_deleteMembers(&trustList[i]);
 
-    server = UA_Server_new(config);
     UA_Server_run_startup(server);
     THREAD_CREATE(server_thread, serverloop);
 }
@@ -75,7 +75,6 @@ static void teardown(void) {
     THREAD_JOIN(server_thread);
     UA_Server_run_shutdown(server);
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
 }
 
 START_TEST(encryption_connect) {
@@ -86,7 +85,6 @@ START_TEST(encryption_connect) {
     size_t trustListSize = 0;
     UA_ByteString *revocationList = NULL;
     size_t revocationListSize = 0;
-    UA_ByteString *remoteCertificate = NULL;
 
     /* Load certificate and private key */
     UA_ByteString certificate;
@@ -105,19 +103,10 @@ START_TEST(encryption_connect) {
     client = UA_Client_new();
     UA_ClientConfig_setDefault(UA_Client_getConfig(client));
     ck_assert_msg(client != NULL);
-    remoteCertificate = UA_ByteString_new();
     UA_StatusCode retval = UA_Client_getEndpoints(client, "opc.tcp://localhost:4840",
                                                   &endpointArraySize, &endpointArray);
     ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
-
-    for(size_t endPointCount = 0; endPointCount < endpointArraySize; endPointCount++) {
-        if(endpointArray[endPointCount].securityMode == UA_MESSAGESECURITYMODE_SIGNANDENCRYPT)
-            UA_ByteString_copy(&endpointArray[endPointCount].serverCertificate, remoteCertificate);
-    }
-
-    if(UA_ByteString_equal(remoteCertificate, &UA_BYTESTRING_NULL)) {
-        ck_abort_msg("Server does not support Security Mode of UA_MESSAGESECURITYMODE_SIGNANDENCRYPT");
-    }
+    ck_assert(endpointArraySize > 0);
 
     UA_Array_delete(endpointArray, endpointArraySize,
                     &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]);
@@ -164,8 +153,6 @@ START_TEST(encryption_connect) {
     ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
     UA_Variant_deleteMembers(&val);
 
-    UA_ByteString_delete(remoteCertificate);
-
     UA_Client_disconnect(client);
     UA_Client_delete(client);
 }

+ 6 - 19
tests/encryption/check_encryption_basic256sha256.c

@@ -22,7 +22,6 @@
 #include "thread_wrapper.h"
 
 UA_Server *server;
-UA_ServerConfig *config;
 UA_Boolean running;
 UA_ServerNetworkLayer nl;
 THREAD_HANDLE server_thread;
@@ -61,14 +60,15 @@ static void setup(void) {
     UA_ByteString *revocationList = NULL;
     size_t revocationListSize = 0;
 
-    config = UA_ServerConfig_new_basic256sha256(4840, &certificate, &privateKey,
-                                                trustList, trustListSize,
-                                                revocationList, revocationListSize);
+    server = UA_Server_new();
+    UA_ServerConfig_setDefaultWithSecurityPolicies(UA_Server_getConfig(server),
+                                                   4840, &certificate, &privateKey,
+                                                   trustList, trustListSize,
+                                                   revocationList, revocationListSize);
 
     for(size_t i = 0; i < trustListSize; i++)
         UA_ByteString_deleteMembers(&trustList[i]);
 
-    server = UA_Server_new(config);
     UA_Server_run_startup(server);
     THREAD_CREATE(server_thread, serverloop);
 }
@@ -78,7 +78,6 @@ static void teardown(void) {
     THREAD_JOIN(server_thread);
     UA_Server_run_shutdown(server);
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
 }
 
 START_TEST(encryption_connect) {
@@ -89,7 +88,6 @@ START_TEST(encryption_connect) {
     size_t trustListSize = 0;
     UA_ByteString *revocationList = NULL;
     size_t revocationListSize = 0;
-    UA_ByteString *remoteCertificate = NULL;
 
     /* Load certificate and private key */
     UA_ByteString certificate;
@@ -108,19 +106,10 @@ START_TEST(encryption_connect) {
     client = UA_Client_new();
     UA_ClientConfig_setDefault(UA_Client_getConfig(client));
     ck_assert_msg(client != NULL);
-    remoteCertificate = UA_ByteString_new();
     UA_StatusCode retval = UA_Client_getEndpoints(client, "opc.tcp://localhost:4840",
                                                   &endpointArraySize, &endpointArray);
     ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
-
-    for(size_t endPointCount = 0; endPointCount < endpointArraySize; endPointCount++) {
-        if(endpointArray[endPointCount].securityMode == UA_MESSAGESECURITYMODE_SIGNANDENCRYPT)
-            UA_ByteString_copy(&endpointArray[endPointCount].serverCertificate, remoteCertificate);
-    }
-
-    if(UA_ByteString_equal(remoteCertificate, &UA_BYTESTRING_NULL)) {
-        ck_abort_msg("Server does not support Security Mode of UA_MESSAGESECURITYMODE_SIGNANDENCRYPT");
-    }
+    ck_assert(endpointArraySize > 0);
 
     UA_Array_delete(endpointArray, endpointArraySize,
                     &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]);
@@ -167,8 +156,6 @@ START_TEST(encryption_connect) {
     ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
     UA_Variant_deleteMembers(&val);
 
-    UA_ByteString_delete(remoteCertificate);
-
     UA_Client_disconnect(client);
     UA_Client_delete(client);
 }

+ 2 - 4
tests/fuzz/corpus_generator.c

@@ -33,7 +33,6 @@
 #include <sys/stat.h>
 
 UA_Server *server;
-UA_ServerConfig *config;
 UA_Boolean running;
 pthread_t server_thread;
 
@@ -45,8 +44,8 @@ static void * serverloop(void *_) {
 
 static void start_server(void) {
     running = true;
-    config = UA_ServerConfig_new_default();
-    server = UA_Server_new(config);
+    server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
     UA_Server_run_startup(server);
     pthread_create(&server_thread, NULL, serverloop, NULL);
 }
@@ -56,7 +55,6 @@ static void teardown_server(void) {
     pthread_join(server_thread, NULL);
     UA_Server_run_shutdown(server);
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
 }
 
 static void emptyCorpusDir(void) {

+ 10 - 10
tests/fuzz/fuzz_binary_message.cc

@@ -26,25 +26,26 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
     size -= 4;
 
     UA_Connection c = createDummyConnection(RECEIVE_BUFFER_SIZE, NULL);
-    UA_ServerConfig *config = UA_ServerConfig_new_default();
-    if (!config) {
+    UA_Server *server = UA_Server_new();
+    if(!server) {
         UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
-                     "Could not create server config using UA_ServerConfig_new_default");
+                     "Could not create server instance using UA_Server_new");
         return 0;
     }
-    UA_Server *server = UA_Server_new(config);
-    if (server == NULL) {
-        UA_ServerConfig_delete(config);
+
+    UA_StatusCode retval = UA_ServerConfig_setDefault(UA_Server_getConfig(server));
+    if(retval != UA_STATUSCODE_GOOD) {
+        UA_Server_delete(server);
         UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
-                     "Could not create server instance using UA_Server_new");
+                     "Could not set the server config");
         return 0;
     }
 
     // we need to copy the message because it will be freed in the processing function
     UA_ByteString msg = UA_ByteString();
-    UA_StatusCode retval = UA_ByteString_allocBuffer(&msg, size);
+    retval = UA_ByteString_allocBuffer(&msg, size);
     if(retval != UA_STATUSCODE_GOOD) {
-        UA_ServerConfig_delete(config);
+        UA_Server_delete(server);
         UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_SERVER,
                      "Could not allocate message buffer");
         return 0;
@@ -56,7 +57,6 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
     UA_ByteString_deleteMembers(&msg);
     UA_Server_run_shutdown(server);
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
     c.close(&c);
     UA_Connection_deleteMembers(&c);
     return 0;

+ 2 - 4
tests/nodeset-compiler/check_nodeset_compiler_adi.c

@@ -11,18 +11,16 @@
 #include "testing_clock.h"
 
 UA_Server *server = NULL;
-UA_ServerConfig *config = NULL;
 
 static void setup(void) {
-    config = UA_ServerConfig_new_default();
-    server = UA_Server_new(config);
+    server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
     UA_Server_run_startup(server);
 }
 
 static void teardown(void) {
     UA_Server_run_shutdown(server);
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
 }
 
 

+ 2 - 5
tests/nodeset-compiler/check_nodeset_compiler_plc.c

@@ -13,21 +13,18 @@
 #include "unistd.h"
 
 UA_Server *server = NULL;
-UA_ServerConfig *config = NULL;
 
 static void setup(void) {
-    config = UA_ServerConfig_new_default();
-    server = UA_Server_new(config);
+    server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
     UA_Server_run_startup(server);
 }
 
 static void teardown(void) {
     UA_Server_run_shutdown(server);
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
 }
 
-
 START_TEST(Server_addDiNodeset) {
     UA_StatusCode retval = namespace_tests_di_generated(server);
     ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);

+ 3 - 5
tests/nodeset-compiler/check_nodeset_compiler_testnodeset.c

@@ -12,21 +12,19 @@
 #include "unistd.h"
 
 UA_Server *server = NULL;
-UA_ServerConfig *config = NULL;
-
 UA_DataTypeArray customTypesArray = { NULL, UA_TYPES_TESTS_TESTNODESET_COUNT, UA_TYPES_TESTS_TESTNODESET};
 
 static void setup(void) {
-    config = UA_ServerConfig_new_default();
+    server = UA_Server_new();
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+    UA_ServerConfig_setDefault(config);
     config->customDataTypes = &customTypesArray;
-    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);
 }
 
 START_TEST(Server_addTestNodeset) {

+ 6 - 8
tests/pubsub/check_pubsub_connection_udp.c

@@ -15,24 +15,22 @@
 #include <check.h>
 
 UA_Server *server = NULL;
-UA_ServerConfig *config = NULL;
 
 static void setup(void) {
-    config = UA_ServerConfig_new_default();
-    config->pubsubTransportLayers = (UA_PubSubTransportLayer *) UA_malloc(sizeof(UA_PubSubTransportLayer));
-    if(!config->pubsubTransportLayers) {
-        UA_ServerConfig_delete(config);
-    }
+    server = UA_Server_new();
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+    UA_ServerConfig_setDefault(config);
+
+    config->pubsubTransportLayers = (UA_PubSubTransportLayer *)
+        UA_malloc(sizeof(UA_PubSubTransportLayer));
     config->pubsubTransportLayers[0] = UA_PubSubTransportLayerUDPMP();
     config->pubsubTransportLayersSize++;
-    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);
 }
 
 START_TEST(AddConnectionsWithMinimalValidConfiguration){

+ 7 - 8
tests/pubsub/check_pubsub_informationmodel.c

@@ -20,27 +20,26 @@
 #include "check.h"
 
 UA_Server *server = NULL;
-UA_ServerConfig *config = NULL;
 
 UA_NodeId connection1, connection2, writerGroup1, writerGroup2, writerGroup3,
         publishedDataSet1, publishedDataSet2, dataSetWriter1, dataSetWriter2, dataSetWriter3;
 
 static void setup(void) {
-    config = UA_ServerConfig_new_default();
-    config->pubsubTransportLayers = (UA_PubSubTransportLayer *) UA_malloc(sizeof(UA_PubSubTransportLayer));
-    if(!config->pubsubTransportLayers) {
-        UA_ServerConfig_delete(config);
-    }
+    server = UA_Server_new();
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+    UA_ServerConfig_setDefault(config);
+
+    config->pubsubTransportLayers = (UA_PubSubTransportLayer *)
+        UA_malloc(sizeof(UA_PubSubTransportLayer));
     config->pubsubTransportLayers[0] = UA_PubSubTransportLayerUDPMP();
     config->pubsubTransportLayersSize++;
-    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);
 }
 
 static void addPublishedDataSet(UA_String pdsName, UA_NodeId *assignedId){

+ 11 - 18
tests/pubsub/check_pubsub_informationmodel_methods.c

@@ -7,21 +7,16 @@
 
 #include <string.h>
 #include <math.h>
-#include "src_generated/ua_types_generated.h"
-#include "ua_types.h"
-#include "src_generated/ua_types_generated_encoding_binary.h"
-#include "ua_types.h"
-#include "ua_server_pubsub.h"
-#include "src_generated/ua_types_generated.h"
-#include "ua_network_pubsub_udp.h"
-#include "ua_server_internal.h"
+#include <open62541/plugin/pubsub_udp.h>
+#include <open62541/server_config_default.h>
+#include <open62541/server_pubsub.h>
+#include <open62541/types_generated_encoding_binary.h>
+#include <open62541/client.h>
+#include <open62541/client_config_default.h>
 #include "check.h"
-#include "ua_plugin_pubsub.h"
-#include "ua_config_default.h"
 #include "thread_wrapper.h"
 
 UA_Server *server = NULL;
-UA_ServerConfig *config = NULL;
 UA_Boolean running;
 THREAD_HANDLE server_thread;
 
@@ -33,14 +28,13 @@ THREAD_CALLBACK(serverloop) {
 
 static void setup(void) {
     running = true;
-    config = UA_ServerConfig_new_default();
-    config->pubsubTransportLayers = (UA_PubSubTransportLayer *) UA_malloc(sizeof(UA_PubSubTransportLayer));
-    if(!config->pubsubTransportLayers) {
-        UA_ServerConfig_delete(config);
-    }
+    server = UA_Server_new();
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+    UA_ServerConfig_setDefault(config);
+    config->pubsubTransportLayers = (UA_PubSubTransportLayer *)
+        UA_malloc(sizeof(UA_PubSubTransportLayer));
     config->pubsubTransportLayers[0] = UA_PubSubTransportLayerUDPMP();
     config->pubsubTransportLayersSize++;
-    server = UA_Server_new(config);
     UA_Server_run_startup(server);
     THREAD_CREATE(server_thread, serverloop);
 }
@@ -50,7 +44,6 @@ static void teardown(void) {
     THREAD_JOIN(server_thread);
     UA_Server_run_shutdown(server);
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
 }
 
 static UA_NodeId

+ 4 - 8
tests/pubsub/check_pubsub_multiple_layer.c

@@ -16,7 +16,6 @@
 #include <check.h>
 
 UA_Server *server = NULL;
-UA_ServerConfig *config = NULL;
 UA_NodeId connection1, connection2;
 
 static void setup(void) {
@@ -26,7 +25,9 @@ static void teardown(void) {
 }
 
 START_TEST(AddMultipleTransportLayers){
-    config = UA_ServerConfig_new_default();
+    server = UA_Server_new();
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+    UA_ServerConfig_setDefault(config);
 
     UA_PubSubTransportLayer pubsubTransportLayer;
 
@@ -44,13 +45,8 @@ START_TEST(AddMultipleTransportLayers){
     UA_ServerConfig_addPubSubTransportLayer(config, &pubsubTransportLayer);
     ck_assert_int_eq(config->pubsubTransportLayersSize, 3);
 
-    server = UA_Server_new(config);
     UA_Server_delete(server);
-
-    UA_ServerConfig_delete(config);
-
-    } END_TEST
-
+} END_TEST
 
 int main(void) {
     TCase *tc_add_pubsub_writergroup = tcase_create("PubSub Layer allocation");

+ 7 - 8
tests/pubsub/check_pubsub_pds.c

@@ -16,24 +16,23 @@
 #include <check.h>
 
 UA_Server *server = NULL;
-UA_ServerConfig *config = NULL;
 
 static void setup(void) {
-    config = UA_ServerConfig_new_default();
-    config->pubsubTransportLayers = (UA_PubSubTransportLayer *) UA_malloc(sizeof(UA_PubSubTransportLayer));
-    if(!config->pubsubTransportLayers) {
-        UA_ServerConfig_delete(config);
-    }
+    server = UA_Server_new();
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+    UA_ServerConfig_setDefault(config);
+
+    config->pubsubTransportLayers = (UA_PubSubTransportLayer*)
+        UA_malloc(sizeof(UA_PubSubTransportLayer));
     config->pubsubTransportLayers[0] = UA_PubSubTransportLayerUDPMP();
     config->pubsubTransportLayersSize++;
-    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);
 }
 
 START_TEST(AddPDSWithMinimalValidConfiguration){

+ 7 - 8
tests/pubsub/check_pubsub_publish.c

@@ -17,19 +17,19 @@
 #include <check.h>
 
 UA_Server *server = NULL;
-UA_ServerConfig *config = NULL;
 UA_NodeId connection1, connection2, writerGroup1, writerGroup2, writerGroup3,
         publishedDataSet1, publishedDataSet2, dataSetWriter1, dataSetWriter2, dataSetWriter3;
 
 static void setup(void) {
-    config = UA_ServerConfig_new_default();
-    config->pubsubTransportLayers = (UA_PubSubTransportLayer *) UA_malloc(sizeof(UA_PubSubTransportLayer));
-    if(!config->pubsubTransportLayers) {
-        UA_ServerConfig_delete(config);
-    }
+    server = UA_Server_new();
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+    UA_ServerConfig_setDefault(config);
+
+    config->pubsubTransportLayers = (UA_PubSubTransportLayer*)
+        UA_malloc(sizeof(UA_PubSubTransportLayer));
     config->pubsubTransportLayers[0] = UA_PubSubTransportLayerUDPMP();
     config->pubsubTransportLayersSize++;
-    server = UA_Server_new(config);
+
     UA_Server_run_startup(server);
     //add 2 connections
     UA_PubSubConnectionConfig connectionConfig;
@@ -46,7 +46,6 @@ static void setup(void) {
 static void teardown(void) {
     UA_Server_run_shutdown(server);
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
 }
 
 START_TEST(AddWriterGroupWithValidConfiguration){

+ 5 - 7
tests/pubsub/check_pubsub_publish_json.c

@@ -17,18 +17,17 @@
 #include <check.h>
 
 UA_Server *server = NULL;
-UA_ServerConfig *config = NULL;
 UA_NodeId connection1, writerGroup1, publishedDataSet1, dataSetWriter1;
 
 static void setup(void) {
-    config = UA_ServerConfig_new_default();
+    server = UA_Server_new();
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+    UA_ServerConfig_setDefault(config);
+
     config->pubsubTransportLayers = (UA_PubSubTransportLayer *) UA_malloc(sizeof(UA_PubSubTransportLayer));
-    if(!config->pubsubTransportLayers) {
-        UA_ServerConfig_delete(config);
-    }
     config->pubsubTransportLayers[0] = UA_PubSubTransportLayerUDPMP();
     config->pubsubTransportLayersSize++;
-    server = UA_Server_new(config);
+
     UA_Server_run_startup(server);
     UA_PubSubConnectionConfig connectionConfig;
     memset(&connectionConfig, 0, sizeof(UA_PubSubConnectionConfig));
@@ -43,7 +42,6 @@ static void setup(void) {
 static void teardown(void) {
     UA_Server_run_shutdown(server);
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
 }
 
 START_TEST(SinglePublishDataSetField){

+ 6 - 8
tests/pubsub/check_pubsub_publishspeed.c

@@ -17,19 +17,18 @@
 #include <time.h>
 
 UA_Server *server = NULL;
-UA_ServerConfig *config = NULL;
 UA_NodeId connection1, connection2, writerGroup1, writerGroup2, writerGroup3,
         publishedDataSet1, publishedDataSet2, dataSetWriter1, dataSetWriter2, dataSetWriter3;
 
 static void setup(void) {
-    config = UA_ServerConfig_new_default();
-    config->pubsubTransportLayers = (UA_PubSubTransportLayer *) UA_malloc(sizeof(UA_PubSubTransportLayer));
-    if(!config->pubsubTransportLayers) {
-        UA_ServerConfig_delete(config);
-    }
+    server = UA_Server_new();
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+    UA_ServerConfig_setDefault(config);
+
+    config->pubsubTransportLayers = (UA_PubSubTransportLayer*)
+        UA_malloc(sizeof(UA_PubSubTransportLayer));
     config->pubsubTransportLayers[0] = UA_PubSubTransportLayerUDPMP();
     config->pubsubTransportLayersSize++;
-    server = UA_Server_new(config);
 
     UA_PubSubConnectionConfig connectionConfig;
     memset(&connectionConfig, 0, sizeof(UA_PubSubConnectionConfig));
@@ -64,7 +63,6 @@ static void setup(void) {
 static void teardown(void) {
     UA_Server_run_shutdown(server);
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
 }
 
 START_TEST(PublishSpeedTest) {

+ 2 - 4
tests/server/check_accesscontrol.c

@@ -13,7 +13,6 @@
 #include "thread_wrapper.h"
 
 UA_Server *server;
-UA_ServerConfig *config;
 UA_Boolean running;
 UA_ServerNetworkLayer nl;
 THREAD_HANDLE server_thread;
@@ -26,8 +25,8 @@ THREAD_CALLBACK(serverloop) {
 
 static void setup(void) {
     running = true;
-    config = UA_ServerConfig_new_default();
-    server = UA_Server_new(config);
+    server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
     UA_Server_run_startup(server);
     THREAD_CREATE(server_thread, serverloop);
 }
@@ -37,7 +36,6 @@ static void teardown(void) {
     THREAD_JOIN(server_thread);
     UA_Server_run_shutdown(server);
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
 }
 
 START_TEST(Client_anonymous) {

+ 12 - 8
tests/server/check_discovery.c

@@ -27,7 +27,6 @@
 #define checkWait registerTimeout + 11
 
 UA_Server *server_lds;
-UA_ServerConfig *config_lds;
 UA_Boolean *running_lds;
 THREAD_HANDLE server_thread_lds;
 UA_Client *clientRegisterRepeated;
@@ -42,7 +41,11 @@ static void setup_lds(void) {
     // start LDS server
     running_lds = UA_Boolean_new();
     *running_lds = true;
-    config_lds = UA_ServerConfig_new_default();
+
+    server_lds = UA_Server_new();
+    UA_ServerConfig *config_lds = UA_Server_getConfig(server_lds);
+    UA_ServerConfig_setDefault(config_lds);
+
     config_lds->applicationDescription.applicationType = UA_APPLICATIONTYPE_DISCOVERYSERVER;
     UA_String_deleteMembers(&config_lds->applicationDescription.applicationUri);
     config_lds->applicationDescription.applicationUri =
@@ -56,7 +59,7 @@ static void setup_lds(void) {
     *caps = UA_String_fromChars("LDS");
     config_lds->serverCapabilities = caps;
     config_lds->discoveryCleanupTimeout = registerTimeout;
-    server_lds = UA_Server_new(config_lds);
+
     UA_Server_run_startup(server_lds);
     THREAD_CREATE(server_thread_lds, serverloop_lds);
 
@@ -71,11 +74,9 @@ static void teardown_lds(void) {
     UA_Server_run_shutdown(server_lds);
     UA_Boolean_delete(running_lds);
     UA_Server_delete(server_lds);
-    UA_ServerConfig_delete(config_lds);
 }
 
 UA_Server *server_register;
-UA_ServerConfig *config_register;
 UA_Boolean *running_register;
 THREAD_HANDLE server_thread_register;
 
@@ -91,7 +92,11 @@ static void setup_register(void) {
     // start register server
     running_register = UA_Boolean_new();
     *running_register = true;
-    config_register = UA_ServerConfig_new_minimal(16664, NULL);
+
+    server_register = UA_Server_new();
+    UA_ServerConfig *config_register = UA_Server_getConfig(server_register);
+    UA_ServerConfig_setMinimal(config_register, 16664, NULL);
+
     UA_String_deleteMembers(&config_register->applicationDescription.applicationUri);
     config_register->applicationDescription.applicationUri =
         UA_String_fromChars("urn:open62541.test.server_register");
@@ -99,7 +104,7 @@ static void setup_register(void) {
     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);
     THREAD_CREATE(server_thread_register, serverloop_register);
 }
@@ -110,7 +115,6 @@ static void teardown_register(void) {
     UA_Server_run_shutdown(server_register);
     UA_Boolean_delete(running_register);
     UA_Server_delete(server_register);
-    UA_ServerConfig_delete(config_register);
 }
 
 START_TEST(Server_register) {

+ 5 - 10
tests/server/check_local_monitored_item.c

@@ -23,18 +23,16 @@
 #endif
 
 UA_Server *server;
-UA_ServerConfig *config;
 size_t callbackCount = 0;
 
 UA_NodeId parentNodeId;
 UA_NodeId parentReferenceNodeId;
 UA_NodeId outNodeId;
 
-static void
-setup(void)
-{
-    config = UA_ServerConfig_new_default();
-    server = UA_Server_new(config);
+static void setup(void) {
+    server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
+
     UA_StatusCode retval = UA_Server_run_startup(server);
     ASSERT_STATUSCODE(retval, UA_STATUSCODE_GOOD);
     /* Define the attribute of the uint32 variable node */
@@ -63,16 +61,13 @@ setup(void)
                                                 &outNodeId), UA_STATUSCODE_GOOD);
 }
 
-static void
-teardown(void)
-{
+static void teardown(void) {
     /* cleanup */
     UA_NodeId_deleteMembers(&parentNodeId);
     UA_NodeId_deleteMembers(&parentReferenceNodeId);
     UA_NodeId_deleteMembers(&outNodeId);
     UA_Server_run_shutdown(server);
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
 }
 
 static void

+ 2 - 4
tests/server/check_monitoreditem_filter.c

@@ -20,7 +20,6 @@
 #include "thread_wrapper.h"
 
 UA_Server *server;
-UA_ServerConfig *config;
 UA_Boolean running;
 THREAD_HANDLE server_thread;
 
@@ -44,8 +43,8 @@ THREAD_CALLBACK(serverloop) {
 static void setup(void) {
     UA_DataValue_init(&lastValue);
     running = true;
-    config = UA_ServerConfig_new_default();
-    server = UA_Server_new(config);
+    server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
     UA_Server_run_startup(server);
     THREAD_CREATE(server_thread, serverloop);
 
@@ -118,7 +117,6 @@ static void teardown(void) {
     THREAD_JOIN(server_thread);
     UA_Server_run_shutdown(server);
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
     UA_DataValue_deleteMembers(&lastValue);
 }
 

+ 2 - 5
tests/server/check_node_inheritance.c

@@ -9,20 +9,17 @@
 #include <check.h>
 
 UA_Server *server = NULL;
-UA_ServerConfig *config = NULL;
-
 UA_UInt32 valueToBeInherited = 42;
 
 static void setup(void) {
-    config = UA_ServerConfig_new_default();
-    server = UA_Server_new(config);
+    server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
     UA_Server_run_startup(server);
 }
 
 static void teardown(void) {
     UA_Server_run_shutdown(server);
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
 }
 
 #ifdef UA_GENERATED_NAMESPACE_ZERO

+ 2 - 4
tests/server/check_server.c

@@ -19,16 +19,14 @@
 #include "check.h"
 
 static UA_Server *server = NULL;
-static UA_ServerConfig *config = NULL;
 
 static void setup(void) {
-    config = UA_ServerConfig_new_default();
-    server = UA_Server_new(config);
+    server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
 }
 
 static void teardown(void) {
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
 }
 
 START_TEST(checkGetConfig) {

+ 21 - 27
tests/server/check_server_historical_data.c

@@ -31,7 +31,6 @@
 #include <stddef.h>
 
 static UA_Server *server;
-static UA_ServerConfig *config;
 #ifdef UA_ENABLE_HISTORIZING
 static UA_HistoryDataGathering *gathering;
 #endif
@@ -60,8 +59,7 @@ static void serverMutexUnlock(void) {
     }
 }
 
-THREAD_CALLBACK(serverloop)
-{
+THREAD_CALLBACK(serverloop) {
     while(running) {
         serverMutexLock();
         UA_Server_run_iterate(server, false);
@@ -70,27 +68,30 @@ THREAD_CALLBACK(serverloop)
     return 0;
 }
 
-static void
-setup(void)
-{
+static void setup(void) {
     if (!(MUTEX_INIT(serverMutex))) {
         fprintf(stderr, "Server mutex was not created correctly.\n");
         exit(1);
     }
     running = true;
-    config = UA_ServerConfig_new_default();
+
+    server = UA_Server_new();
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+    UA_ServerConfig_setDefault(config);
+
 #ifdef UA_ENABLE_HISTORIZING
     gathering = (UA_HistoryDataGathering*)UA_calloc(1, sizeof(UA_HistoryDataGathering));
     *gathering = UA_HistoryDataGathering_Default(1);
     config->historyDatabase = UA_HistoryDatabase_default(*gathering);
 #endif
-    server = UA_Server_new(config);
+
     UA_StatusCode retval = UA_Server_run_startup(server);
-    if (retval != UA_STATUSCODE_GOOD)
-    {
+    if(retval != UA_STATUSCODE_GOOD) {
         fprintf(stderr, "Error while calling Server_run_startup. %s\n", UA_StatusCode_name(retval));
+        UA_Server_delete(server);
         exit(1);
     }
+
     THREAD_CREATE(server_thread, serverloop);
     /* Define the attribute of the uint32 variable node */
     UA_VariableAttributes attr = UA_VariableAttributes_default;
@@ -108,27 +109,23 @@ setup(void)
     parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);
     parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
     UA_NodeId_init(&outNodeId);
-    retval = UA_Server_addVariableNode(server,
-                                                uint32NodeId,
-                                                parentNodeId,
-                                                parentReferenceNodeId,
-                                                uint32Name,
-                                                UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATAVARIABLETYPE),
-                                                attr,
-                                                NULL,
-                                                &outNodeId);
-    if (retval != UA_STATUSCODE_GOOD)
-    {
+    retval = UA_Server_addVariableNode(server, uint32NodeId, parentNodeId,
+                                       parentReferenceNodeId, uint32Name,
+                                       UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATAVARIABLETYPE),
+                                       attr, NULL, &outNodeId);
+    if (retval != UA_STATUSCODE_GOOD) {
         fprintf(stderr, "Error adding variable node. %s\n", UA_StatusCode_name(retval));
+        UA_Server_delete(server);
         exit(1);
     }
 
     client = UA_Client_new();
     UA_ClientConfig_setDefault(UA_Client_getConfig(client));
     retval = UA_Client_connect(client, "opc.tcp://localhost:4840");
-    if (retval != UA_STATUSCODE_GOOD)
-    {
+    if (retval != UA_STATUSCODE_GOOD) {
         fprintf(stderr, "Client can not connect to opc.tcp://localhost:4840. %s\n", UA_StatusCode_name(retval));
+        UA_Client_delete(client);
+        UA_Server_delete(server);
         exit(1);
     }
 
@@ -136,9 +133,7 @@ setup(void)
     client->connection.recv = UA_Client_recvTesting;
 }
 
-static void
-teardown(void)
-{
+static void teardown(void) {
     /* cleanup */
     UA_Client_disconnect(client);
     UA_Client_delete(client);
@@ -149,7 +144,6 @@ teardown(void)
     UA_NodeId_deleteMembers(&outNodeId);
     UA_Server_run_shutdown(server);
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
 #ifdef UA_ENABLE_HISTORIZING
     UA_free(gathering);
 #endif

+ 3 - 6
tests/server/check_server_jobs.c

@@ -11,22 +11,19 @@
 #include "testing_clock.h"
 
 UA_Server *server = NULL;
-UA_ServerConfig *config = NULL;
+UA_Boolean *executed;
 
 static void setup(void) {
-    config = UA_ServerConfig_new_default();
-    server = UA_Server_new(config);
+    server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
     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;
-
 static void
 dummyCallback(UA_Server *serverPtr, void *data) {
     *executed = true;

+ 2 - 5
tests/server/check_server_monitoringspeed.c

@@ -21,13 +21,11 @@ static UA_SecurityPolicy dummyPolicy;
 static UA_Connection testingConnection;
 static funcs_called funcsCalled;
 static key_sizes keySizes;
-
-static UA_ServerConfig *config;
 static UA_Server *server;
 
 static void setup(void) {
-    config = UA_ServerConfig_new_default();
-    server = UA_Server_new(config);
+    server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
 
     TestingPolicy(&dummyPolicy, UA_BYTESTRING_NULL, &funcsCalled, &keySizes);
     UA_SecureChannel_init(&testChannel);
@@ -45,7 +43,6 @@ static void teardown(void) {
     testingConnection.close(&testingConnection);
 
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
 }
 
 static size_t callbackCount = 0;

+ 2 - 4
tests/server/check_server_readspeed.c

@@ -22,12 +22,11 @@ static UA_Connection testingConnection;
 static funcs_called funcsCalled;
 static key_sizes keySizes;
 
-static UA_ServerConfig *config;
 static UA_Server *server;
 
 static void setup(void) {
-    config = UA_ServerConfig_new_default();
-    server = UA_Server_new(config);
+    server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
 
     TestingPolicy(&dummyPolicy, UA_BYTESTRING_NULL, &funcsCalled, &keySizes);
     UA_SecureChannel_init(&testChannel);
@@ -45,7 +44,6 @@ static void teardown(void) {
     testingConnection.close(&testingConnection);
 
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
 }
 
 START_TEST(readSpeed) {

+ 16 - 19
tests/server/check_server_userspace.c

@@ -14,8 +14,8 @@
 #endif
 
 START_TEST(Server_addNamespace_ShallWork) {
-    UA_ServerConfig *config = UA_ServerConfig_new_default();
-    UA_Server *server = UA_Server_new(config);
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
 
     UA_UInt16 a = UA_Server_addNamespace(server, "http://nameOfNamespace");
     UA_UInt16 b = UA_Server_addNamespace(server, "http://nameOfNamespace");
@@ -26,13 +26,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_new_default();
-    UA_Server *server = UA_Server_new(config);
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
 
     UA_Variant namespaces;
     UA_StatusCode retval = UA_STATUSCODE_GOOD;
@@ -60,7 +59,6 @@ START_TEST(Server_addNamespace_writeService) {
 
     UA_Variant_deleteMembers(&namespaces);
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
 }
 END_TEST
 
@@ -81,8 +79,8 @@ nodeIter(UA_NodeId childId, UA_Boolean isInverse, UA_NodeId referenceTypeId, voi
 
     int i;
 
-    for (i=0; i<NODE_ITER_DATA_SIZE; i++) {
-        if (UA_NodeId_equal(&childId, &objectsFolderChildren[i].id)) {
+    for(i=0; i<NODE_ITER_DATA_SIZE; i++) {
+        if(UA_NodeId_equal(&childId, &objectsFolderChildren[i].id)) {
             break;
         }
     }
@@ -99,9 +97,8 @@ nodeIter(UA_NodeId childId, UA_Boolean isInverse, UA_NodeId referenceTypeId, voi
 }
 
 START_TEST(Server_forEachChildNodeCall) {
-
-    UA_ServerConfig *config = UA_ServerConfig_new_default();
-    UA_Server *server = UA_Server_new(config);
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
 
     /* List all the children/references of the objects folder
      * The forEachChildNodeCall has to hit all of them */
@@ -121,7 +118,9 @@ START_TEST(Server_forEachChildNodeCall) {
     objectsFolderChildren[2].referenceTypeID = UA_NODEID_NUMERIC(0, UA_NS0ID_HASTYPEDEFINITION);
     objectsFolderChildren[2].hit = UA_FALSE;
 
-    UA_StatusCode retval = UA_Server_forEachChildNodeCall(server, UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER), nodeIter, &objectsFolderChildren);
+    UA_StatusCode retval =
+        UA_Server_forEachChildNodeCall(server, UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER),
+                                       nodeIter, &objectsFolderChildren);
     ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
 
     /* Check if all nodes are hit */
@@ -130,8 +129,6 @@ START_TEST(Server_forEachChildNodeCall) {
     }
 
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
-
 } END_TEST
 
 
@@ -139,9 +136,11 @@ START_TEST(Server_set_customHostname) {
     UA_String customHost = UA_STRING("fancy-host");
     UA_UInt16 port = 10042;
 
-    UA_ServerConfig *config = UA_ServerConfig_new_minimal(port, NULL);
-    UA_ServerConfig_set_customHostname(config, customHost);
-    UA_Server *server = UA_Server_new(config);
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+    UA_ServerConfig_setMinimal(config, port, NULL);
+    UA_ServerConfig_setCustomHostname(config, customHost);
+
     UA_StatusCode retval = UA_Server_run_startup(server);
     ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
 
@@ -158,11 +157,9 @@ START_TEST(Server_set_customHostname) {
     }
     UA_Server_run_shutdown(server);
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
 }
 END_TEST
 
-
 static Suite* testSuite_ServerUserspace(void) {
     Suite *s = suite_create("ServerUserspace");
     TCase *tc_core = tcase_create("Core");

+ 7 - 10
tests/server/check_services_attributes.c

@@ -19,7 +19,6 @@
 #endif
 
 static UA_Server *server = NULL;
-static UA_ServerConfig *config = NULL;
 
 static UA_StatusCode
 readCPUTemperature(UA_Server *server_,
@@ -35,12 +34,11 @@ readCPUTemperature(UA_Server *server_,
 
 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);
+    server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
     UA_StatusCode retval = UA_STATUSCODE_GOOD;
 
     /* VariableNode */
@@ -146,8 +144,7 @@ static void setup(void) {
 
 static UA_VariableNode* makeCompareSequence(void) {
     UA_VariableNode *node = (UA_VariableNode*)
-        config->nodestore.newNode(config->nodestore.context,
-                                  UA_NODECLASS_VARIABLE);
+        UA_Nodestore_newNode(server->nsCtx, UA_NODECLASS_VARIABLE);
 
     UA_Int32 myInteger = 42;
     UA_Variant_setScalarCopy(&node->value.data.value.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
@@ -282,7 +279,7 @@ START_TEST(ReadSingleAttributeDisplayNameWithoutTimestamp) {
     ck_assert(UA_String_equal(&comp.text, &respval->text));
     ck_assert(UA_String_equal(&compNode->displayName.locale, &respval->locale));
     UA_DataValue_deleteMembers(&resp);
-    config->nodestore.deleteNode(config->nodestore.context, (UA_Node*)compNode);
+    UA_Nodestore_deleteNode(server->nsCtx, (UA_Node*)compNode);
 } END_TEST
 
 START_TEST(ReadSingleAttributeDescriptionWithoutTimestamp) {
@@ -300,7 +297,7 @@ START_TEST(ReadSingleAttributeDescriptionWithoutTimestamp) {
     ck_assert(UA_String_equal(&compNode->description.locale, &respval->locale));
     ck_assert(UA_String_equal(&compNode->description.text, &respval->text));
     UA_DataValue_deleteMembers(&resp);
-    config->nodestore.deleteNode(config->nodestore.context, (UA_Node*)compNode);
+    UA_Nodestore_deleteNode(server->nsCtx, (UA_Node*)compNode);
 } END_TEST
 
 START_TEST(ReadSingleAttributeWriteMaskWithoutTimestamp) {
@@ -478,7 +475,7 @@ START_TEST(ReadSingleAttributeUserAccessLevelWithoutTimestamp) {
 
     /* Uncommented since the accesslevel is always 0xff for the local admin user */
     /* const UA_VariableNode* compNode = */
-    /*     (const UA_VariableNode*)UA_NodeStore_get(server->nodestore, &rvi.nodeId); */
+    /*     (const UA_VariableNode*)UA_NodeStore_getNode(server->nsCtx, &rvi.nodeId); */
     /* ck_assert_int_eq(0, resp.value.arrayLength); */
     /* 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 */
@@ -500,7 +497,7 @@ START_TEST(ReadSingleAttributeMinimumSamplingIntervalWithoutTimestamp) {
     ck_assert(&UA_TYPES[UA_TYPES_DOUBLE] == resp.value.type);
     ck_assert(*respval == comp);
     UA_DataValue_deleteMembers(&resp);
-    config->nodestore.deleteNode(config->nodestore.context, (UA_Node*)compNode);
+    UA_Nodestore_deleteNode(server->nsCtx, (UA_Node*)compNode);
 } END_TEST
 
 START_TEST(ReadSingleAttributeHistorizingWithoutTimestamp) {

+ 2 - 4
tests/server/check_services_call.c

@@ -19,7 +19,6 @@
 #include "check.h"
 
 static UA_Server *server = NULL;
-static UA_ServerConfig *config = NULL;
 
 static UA_StatusCode
 methodCallback(UA_Server *serverArg,
@@ -33,8 +32,8 @@ methodCallback(UA_Server *serverArg,
 }
 
 static void setup(void) {
-    config = UA_ServerConfig_new_default();
-    server = UA_Server_new(config);
+    server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
 
     UA_MethodAttributes noFpAttr = UA_MethodAttributes_default;
     noFpAttr.description = UA_LOCALIZEDTEXT("en-US","No function pointer attached");
@@ -63,7 +62,6 @@ static void setup(void) {
 
 static void teardown(void) {
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
 }
 
 START_TEST(callUnknownMethod) {

+ 5 - 5
tests/server/check_services_nodemanagement.c

@@ -13,7 +13,6 @@
 #include <time.h>
 
 static UA_Server *server = NULL;
-static UA_ServerConfig *config = NULL;
 static UA_Int32 handleCalled = 0;
 
 static UA_StatusCode
@@ -25,21 +24,22 @@ globalInstantiationMethod(UA_Server *server_,
 }
 
 static void setup(void) {
-    config = UA_ServerConfig_new_default();
+    server = UA_Server_new();
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+    UA_ServerConfig_setDefault(config);
+
     UA_GlobalNodeLifecycle lifecycle;
     lifecycle.constructor = globalInstantiationMethod;
     lifecycle.destructor = NULL;
     config->nodeLifecycle = lifecycle;
-    server = UA_Server_new(config);
 }
 
 static void teardown(void) {
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
 }
 
 START_TEST(AddVariableNode) {
-    /* add a variable node to the address space */
+    /* Add a variable node to the address space */
     UA_VariableAttributes attr = UA_VariableAttributes_default;
     UA_Int32 myInteger = 42;
     UA_Variant_setScalar(&attr.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);

+ 3 - 6
tests/server/check_services_subscriptions.c

@@ -14,9 +14,7 @@
 #include "testing_clock.h"
 
 static UA_Server *server = NULL;
-static UA_ServerConfig *config = NULL;
 static UA_Session *session = NULL;
-
 static UA_UInt32 monitored = 0; /* Number of active MonitoredItems */
 
 static void
@@ -41,9 +39,10 @@ createSession(void) {
 }
 
 static void setup(void) {
-    config = UA_ServerConfig_new_default();
+    server = UA_Server_new();
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+    UA_ServerConfig_setDefault(config);
     config->monitoredItemRegisterCallback = monitoredRegisterCallback;
-    server = UA_Server_new(config);
     UA_Server_run_startup(server);
     createSession();
 }
@@ -51,8 +50,6 @@ static void setup(void) {
 static void teardown(void) {
     UA_Server_run_shutdown(server);
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
-
     ck_assert_uint_eq(monitored, 0); /* All MonitoredItems have been de-registered */
 }
 

+ 9 - 10
tests/server/check_services_view.c

@@ -16,7 +16,6 @@
 #include "thread_wrapper.h"
 
 UA_Server *server_translate_browse;
-UA_ServerConfig *server_translate_config;
 UA_Boolean *running_translate_browse;
 THREAD_HANDLE server_thread_translate_browse;
 
@@ -30,11 +29,14 @@ static void setup_server(void) {
     // start server
     running_translate_browse = UA_Boolean_new();
     *running_translate_browse = true;
-    server_translate_config = UA_ServerConfig_new_default();
+
+    server_translate_browse = UA_Server_new();
+    UA_ServerConfig *server_translate_config = UA_Server_getConfig(server_translate_browse);
+    UA_ServerConfig_setDefault(server_translate_config);
+
     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);
     THREAD_CREATE(server_thread_translate_browse, serverloop_register);
 }
@@ -45,7 +47,6 @@ static void teardown_server(void) {
     UA_Server_run_shutdown(server_translate_browse);
     UA_Boolean_delete(running_translate_browse);
     UA_Server_delete(server_translate_browse);
-    UA_ServerConfig_delete(server_translate_config);
 }
 
 static size_t
@@ -78,8 +79,8 @@ browseWithMaxResults(UA_Server *server, UA_NodeId nodeId, UA_UInt32 maxResults)
 }
 
 START_TEST(Service_Browse_WithMaxResults) {
-    UA_ServerConfig *config = UA_ServerConfig_new_default();
-    UA_Server *server = UA_Server_new(config);
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
 
     UA_BrowseDescription bd;
     UA_BrowseDescription_init(&bd);
@@ -101,13 +102,12 @@ START_TEST(Service_Browse_WithMaxResults) {
     }
     
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
 }
 END_TEST
 
 START_TEST(Service_Browse_WithBrowseName) {
-    UA_ServerConfig *config = UA_ServerConfig_new_default();
-    UA_Server *server = UA_Server_new(config);
+    UA_Server *server = UA_Server_new();
+    UA_ServerConfig_setDefault(UA_Server_getConfig(server));
 
     UA_BrowseDescription bd;
     UA_BrowseDescription_init(&bd);
@@ -124,7 +124,6 @@ START_TEST(Service_Browse_WithBrowseName) {
 
     UA_BrowseResult_deleteMembers(&br);
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
 }
 END_TEST
 

+ 11 - 7
tests/server/check_subscription_events.c

@@ -19,7 +19,6 @@
 #ifdef UA_ENABLE_SUBSCRIPTIONS_EVENTS
 
 static UA_Server *server;
-static UA_ServerConfig *config;
 static UA_Boolean running;
 static THREAD_HANDLE server_thread;
 static MUTEX_HANDLE serverMutex;
@@ -180,10 +179,14 @@ setup(void) {
         exit(1);
     }
     running = true;
-    config = UA_ServerConfig_new_default();
+
+    server = UA_Server_new();
+    UA_ServerConfig *config = UA_Server_getConfig(server);
+    UA_ServerConfig_setDefault(config);
+
     config->maxPublishReqPerSession = 5;
-    server = UA_Server_new(config);
     UA_Server_run_startup(server);
+
     addNewEventType();
     setupSelectClauses();
     THREAD_CREATE(server_thread, serverloop);
@@ -208,7 +211,6 @@ teardown(void) {
     removeSubscription();
     UA_Server_run_shutdown(server);
     UA_Server_delete(server);
-    UA_ServerConfig_delete(config);
     UA_Array_delete(selectClauses, nSelectClauses, &UA_TYPES[UA_TYPES_SIMPLEATTRIBUTEOPERAND]);
 
     UA_Client_disconnect(client);
@@ -219,10 +221,12 @@ teardown(void) {
     }
 }
 
-static UA_StatusCode triggerEventLocked(const UA_NodeId eventNodeId, const UA_NodeId origin,
-                                        UA_ByteString *outEventId, const UA_Boolean deleteEventNode) {
+static UA_StatusCode
+triggerEventLocked(const UA_NodeId eventNodeId, const UA_NodeId origin,
+                   UA_ByteString *outEventId, const UA_Boolean deleteEventNode) {
     serverMutexLock();
-    UA_StatusCode retval = UA_Server_triggerEvent(server, eventNodeId, origin, outEventId, deleteEventNode);
+    UA_StatusCode retval = UA_Server_triggerEvent(server, eventNodeId, origin,
+                                                  outEventId, deleteEventNode);
     serverMutexUnlock();
     return retval;
 }