ua_server_config.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. #endif
  19. /* Custom DataTypes */
  20. /* nothing to do */
  21. /* Networking */
  22. for(size_t i = 0; i < config->networkLayersSize; ++i)
  23. config->networkLayers[i].deleteMembers(&config->networkLayers[i]);
  24. UA_free(config->networkLayers);
  25. config->networkLayers = NULL;
  26. config->networkLayersSize = 0;
  27. UA_String_deleteMembers(&config->customHostname);
  28. config->customHostname = UA_STRING_NULL;
  29. for(size_t i = 0; i < config->securityPoliciesSize; ++i) {
  30. UA_SecurityPolicy *policy = &config->securityPolicies[i];
  31. policy->deleteMembers(policy);
  32. }
  33. UA_free(config->securityPolicies);
  34. config->securityPolicies = NULL;
  35. config->securityPoliciesSize = 0;
  36. for(size_t i = 0; i < config->endpointsSize; ++i)
  37. UA_EndpointDescription_deleteMembers(&config->endpoints[i]);
  38. UA_free(config->endpoints);
  39. config->endpoints = NULL;
  40. config->endpointsSize = 0;
  41. /* Certificate Validation */
  42. if(config->certificateVerification.deleteMembers)
  43. config->certificateVerification.deleteMembers(&config->certificateVerification);
  44. /* Access Control */
  45. if(config->accessControl.deleteMembers)
  46. config->accessControl.deleteMembers(&config->accessControl);
  47. /* Historical data */
  48. #ifdef UA_ENABLE_HISTORIZING
  49. if(config->historyDatabase.deleteMembers)
  50. config->historyDatabase.deleteMembers(&config->historyDatabase);
  51. #endif
  52. /* Logger */
  53. if(config->logger.clear)
  54. config->logger.clear(config->logger.context);
  55. }
  56. void
  57. UA_ServerConfig_setCustomHostname(UA_ServerConfig *config,
  58. const UA_String customHostname) {
  59. if(!config)
  60. return;
  61. UA_String_deleteMembers(&config->customHostname);
  62. UA_String_copy(&customHostname, &config->customHostname);
  63. }
  64. #ifdef UA_ENABLE_PUBSUB
  65. /* Add a pubsubTransportLayer to the configuration. Memory is reallocated on
  66. * demand. */
  67. UA_StatusCode
  68. UA_ServerConfig_addPubSubTransportLayer(UA_ServerConfig *config,
  69. UA_PubSubTransportLayer *pubsubTransportLayer) {
  70. if(config->pubsubTransportLayersSize == 0) {
  71. config->pubsubTransportLayers = (UA_PubSubTransportLayer *)
  72. UA_malloc(sizeof(UA_PubSubTransportLayer));
  73. } else {
  74. config->pubsubTransportLayers = (UA_PubSubTransportLayer*)
  75. UA_realloc(config->pubsubTransportLayers,
  76. sizeof(UA_PubSubTransportLayer) * (config->pubsubTransportLayersSize + 1));
  77. }
  78. if(config->pubsubTransportLayers == NULL)
  79. return UA_STATUSCODE_BADOUTOFMEMORY;
  80. memcpy(&config->pubsubTransportLayers[config->pubsubTransportLayersSize],
  81. pubsubTransportLayer, sizeof(UA_PubSubTransportLayer));
  82. config->pubsubTransportLayersSize++;
  83. return UA_STATUSCODE_GOOD;
  84. }
  85. #endif /* UA_ENABLE_PUBSUB */