ua_client_config.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 2018 (c) Stefan Profanter, fortiss GmbH
  6. * Copyright 2018 (c) Thomas Stalder, Blue Time Concept SA
  7. */
  8. #ifndef UA_CLIENT_CONFIG_H
  9. #define UA_CLIENT_CONFIG_H
  10. #include "ua_config.h"
  11. #include "ua_plugin_securitypolicy.h"
  12. #include "ua_plugin_network.h"
  13. _UA_BEGIN_DECLS
  14. struct UA_Client;
  15. typedef struct UA_Client UA_Client;
  16. /**
  17. * .. _client-config:
  18. *
  19. * Client Configuration
  20. * --------------------
  21. *
  22. * The client configuration is used for setting connection parameters and
  23. * additional settings used by the client.
  24. * The configuration should not be modified after it is passed to a client.
  25. * Currently, only one client can use a configuration at a time.
  26. *
  27. * Examples for configurations are provided in the ``/plugins`` folder.
  28. * The usual usage is as follows:
  29. *
  30. * 1. Create a client configuration with default settings as a starting point
  31. * 2. Modifiy the configuration, e.g. modifying the timeout
  32. * 3. Instantiate a client with it
  33. * 4. After shutdown of the client, clean up the configuration (free memory)
  34. *
  35. * The :ref:`tutorials` provide a good starting point for this. */
  36. typedef enum {
  37. UA_CLIENTSTATE_DISCONNECTED, /* The client is disconnected */
  38. UA_CLIENTSTATE_WAITING_FOR_ACK, /* The Client has sent HEL and waiting */
  39. UA_CLIENTSTATE_CONNECTED, /* A TCP connection to the server is open */
  40. UA_CLIENTSTATE_SECURECHANNEL, /* A SecureChannel to the server is open */
  41. UA_CLIENTSTATE_SESSION, /* A session with the server is open */
  42. UA_CLIENTSTATE_SESSION_DISCONNECTED, /* Disconnected vs renewed? */
  43. UA_CLIENTSTATE_SESSION_RENEWED /* A session with the server is open (renewed) */
  44. } UA_ClientState;
  45. typedef struct {
  46. /* Basic client configuration */
  47. void *clientContext; /* User-defined data attached to the client */
  48. UA_Logger logger; /* Logger used by the client */
  49. UA_UInt32 timeout; /* Response timeout in ms */
  50. UA_ApplicationDescription clientDescription;
  51. /* Basic connection configuration */
  52. UA_ExtensionObject userIdentityToken; /* Configured User-Identity Token */
  53. UA_MessageSecurityMode securityMode; /* None, Sign, SignAndEncrypt. The
  54. * default is invalid. This indicates
  55. * the client to select any matching
  56. * endpoint. */
  57. UA_String securityPolicyUri; /* SecurityPolicy for the SecureChannel. An
  58. * empty string indicates the client to select
  59. * any matching SecurityPolicy. */
  60. /* Advanced connection configuration
  61. *
  62. * If either endpoint or userTokenPolicy has been set (at least one non-zero
  63. * byte in either structure), then the selected Endpoint and UserTokenPolicy
  64. * overwrite the settings in the basic connection configuration. The
  65. * userTokenPolicy array in the EndpointDescription is ignored. The selected
  66. * userTokenPolicy is set in the dedicated configuration field.
  67. *
  68. * If the advanced configuration is not set, the client will write to it the
  69. * selected Endpoint and UserTokenPolicy during GetEndpoints.
  70. *
  71. * The information in the advanced configuration is used during reconnect
  72. * when the SecureChannel was broken. */
  73. UA_EndpointDescription endpoint;
  74. UA_UserTokenPolicy userTokenPolicy;
  75. /* Advanced client configuration */
  76. UA_UInt32 secureChannelLifeTime; /* Lifetime in ms (then the channel needs
  77. to be renewed) */
  78. UA_UInt32 requestedSessionTimeout; /* Session timeout in ms */
  79. UA_ConnectionConfig localConnectionConfig;
  80. UA_UInt32 connectivityCheckInterval; /* Connectivity check interval in ms.
  81. * 0 = background task disabled */
  82. const UA_DataTypeArray *customDataTypes; /* Custom DataTypes. Attention!
  83. * Custom datatypes are not cleaned
  84. * up together with the
  85. * configuration. So it is possible
  86. * to allocate them on ROM. */
  87. /* Available SecurityPolicies */
  88. size_t securityPoliciesSize;
  89. UA_SecurityPolicy *securityPolicies;
  90. /* Certificate Verification Plugin */
  91. UA_CertificateVerification certificateVerification;
  92. /* Callbacks for async connection handshakes */
  93. UA_ConnectClientConnection connectionFunc;
  94. UA_ConnectClientConnection initConnectionFunc;
  95. void (*pollConnectionFunc)(UA_Client *client, void *context);
  96. /* Callback for state changes */
  97. void (*stateCallback)(UA_Client *client, UA_ClientState clientState);
  98. /* When connectivityCheckInterval is greater than 0, every
  99. * connectivityCheckInterval (in ms), a async read request is performed on
  100. * the server. inactivityCallback is called when the client receive no
  101. * response for this read request The connection can be closed, this in an
  102. * attempt to recreate a healthy connection. */
  103. void (*inactivityCallback)(UA_Client *client);
  104. #ifdef UA_ENABLE_SUBSCRIPTIONS
  105. /* Number of PublishResponse queued up in the server */
  106. UA_UInt16 outStandingPublishRequests;
  107. /* If the client does not receive a PublishResponse after the defined delay
  108. * of ``(sub->publishingInterval * sub->maxKeepAliveCount) +
  109. * client->config.timeout)``, then subscriptionInactivityCallback is called
  110. * for the subscription.. */
  111. void (*subscriptionInactivityCallback)(UA_Client *client,
  112. UA_UInt32 subscriptionId,
  113. void *subContext);
  114. #endif
  115. } UA_ClientConfig;
  116. _UA_END_DECLS
  117. #endif /* UA_CLIENT_CONFIG_H */