ua_server_config.c 3.4 KB

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