ua_server_config.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  4. *
  5. * Copyright 2019 (c) Fraunhofer IOSB (Author: Julius Pfrommer)
  6. */
  7. #include <open62541/server_config.h>
  8. void
  9. UA_ServerConfig_clean(UA_ServerConfig *config) {
  10. if(!config)
  11. return;
  12. /* Server Description */
  13. UA_BuildInfo_deleteMembers(&config->buildInfo);
  14. UA_ApplicationDescription_deleteMembers(&config->applicationDescription);
  15. #ifdef UA_ENABLE_DISCOVERY_MULTICAST
  16. UA_MdnsDiscoveryConfiguration_clear(&config->discovery.mdns);
  17. UA_String_clear(&config->discovery.mdnsInterfaceIP);
  18. # if !defined(UA_HAS_GETIFADDR)
  19. if (config->discovery.ipAddressListSize) {
  20. UA_free(config->discovery.ipAddressList);
  21. }
  22. # endif
  23. #endif
  24. /* Custom DataTypes */
  25. /* nothing to do */
  26. /* Networking */
  27. for(size_t i = 0; i < config->networkLayersSize; ++i)
  28. config->networkLayers[i].clear(&config->networkLayers[i]);
  29. UA_free(config->networkLayers);
  30. config->networkLayers = NULL;
  31. config->networkLayersSize = 0;
  32. UA_String_deleteMembers(&config->customHostname);
  33. config->customHostname = UA_STRING_NULL;
  34. for(size_t i = 0; i < config->securityPoliciesSize; ++i) {
  35. UA_SecurityPolicy *policy = &config->securityPolicies[i];
  36. policy->clear(policy);
  37. }
  38. UA_free(config->securityPolicies);
  39. config->securityPolicies = NULL;
  40. config->securityPoliciesSize = 0;
  41. for(size_t i = 0; i < config->endpointsSize; ++i)
  42. UA_EndpointDescription_deleteMembers(&config->endpoints[i]);
  43. UA_free(config->endpoints);
  44. config->endpoints = NULL;
  45. config->endpointsSize = 0;
  46. /* Nodestore */
  47. if(config->nodestore.context && config->nodestore.clear) {
  48. config->nodestore.clear(config->nodestore.context);
  49. config->nodestore.context = NULL;
  50. }
  51. /* Certificate Validation */
  52. if(config->certificateVerification.clear)
  53. config->certificateVerification.clear(&config->certificateVerification);
  54. /* Access Control */
  55. if(config->accessControl.clear)
  56. config->accessControl.clear(&config->accessControl);
  57. /* Historical data */
  58. #ifdef UA_ENABLE_HISTORIZING
  59. if(config->historyDatabase.clear)
  60. config->historyDatabase.clear(&config->historyDatabase);
  61. #endif
  62. /* Logger */
  63. if(config->logger.clear)
  64. config->logger.clear(config->logger.context);
  65. }
  66. void
  67. UA_ServerConfig_setCustomHostname(UA_ServerConfig *config,
  68. const UA_String customHostname) {
  69. if(!config)
  70. return;
  71. UA_String_deleteMembers(&config->customHostname);
  72. UA_String_copy(&customHostname, &config->customHostname);
  73. }
  74. #ifdef UA_ENABLE_PUBSUB
  75. /* Add a pubsubTransportLayer to the configuration. Memory is reallocated on
  76. * demand. */
  77. UA_StatusCode
  78. UA_ServerConfig_addPubSubTransportLayer(UA_ServerConfig *config,
  79. UA_PubSubTransportLayer *pubsubTransportLayer) {
  80. if(config->pubsubTransportLayersSize == 0) {
  81. config->pubsubTransportLayers = (UA_PubSubTransportLayer *)
  82. UA_malloc(sizeof(UA_PubSubTransportLayer));
  83. } else {
  84. config->pubsubTransportLayers = (UA_PubSubTransportLayer*)
  85. UA_realloc(config->pubsubTransportLayers,
  86. sizeof(UA_PubSubTransportLayer) * (config->pubsubTransportLayersSize + 1));
  87. }
  88. if(config->pubsubTransportLayers == NULL)
  89. return UA_STATUSCODE_BADOUTOFMEMORY;
  90. memcpy(&config->pubsubTransportLayers[config->pubsubTransportLayersSize],
  91. pubsubTransportLayer, sizeof(UA_PubSubTransportLayer));
  92. config->pubsubTransportLayersSize++;
  93. return UA_STATUSCODE_GOOD;
  94. }
  95. #endif /* UA_ENABLE_PUBSUB */