client_config.h 6.2 KB

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