client_config.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. UA_ApplicationDescription clientDescription;
  52. /* Basic connection configuration */
  53. UA_ExtensionObject userIdentityToken; /* Configured User-Identity Token */
  54. UA_MessageSecurityMode securityMode; /* None, Sign, SignAndEncrypt. The
  55. * default is invalid. This indicates
  56. * the client to select any matching
  57. * endpoint. */
  58. UA_String securityPolicyUri; /* SecurityPolicy for the SecureChannel. An
  59. * empty string indicates the client to select
  60. * any matching SecurityPolicy. */
  61. /* Advanced connection configuration
  62. *
  63. * If either endpoint or userTokenPolicy has been set (at least one non-zero
  64. * byte in either structure), then the selected Endpoint and UserTokenPolicy
  65. * overwrite the settings in the basic connection configuration. The
  66. * userTokenPolicy array in the EndpointDescription is ignored. The selected
  67. * userTokenPolicy is set in the dedicated configuration field.
  68. *
  69. * If the advanced configuration is not set, the client will write to it the
  70. * selected Endpoint and UserTokenPolicy during GetEndpoints.
  71. *
  72. * The information in the advanced configuration is used during reconnect
  73. * when the SecureChannel was broken. */
  74. UA_EndpointDescription endpoint;
  75. UA_UserTokenPolicy userTokenPolicy;
  76. /* Advanced client configuration */
  77. UA_UInt32 secureChannelLifeTime; /* Lifetime in ms (then the channel needs
  78. to be renewed) */
  79. UA_UInt32 requestedSessionTimeout; /* Session timeout in ms */
  80. UA_ConnectionConfig localConnectionConfig;
  81. UA_UInt32 connectivityCheckInterval; /* Connectivity check interval in ms.
  82. * 0 = background task disabled */
  83. const UA_DataTypeArray *customDataTypes; /* Custom DataTypes. Attention!
  84. * Custom datatypes are not cleaned
  85. * up together with the
  86. * configuration. So it is possible
  87. * to allocate them on ROM. */
  88. /* Available SecurityPolicies */
  89. size_t securityPoliciesSize;
  90. UA_SecurityPolicy *securityPolicies;
  91. /* Certificate Verification Plugin */
  92. UA_CertificateVerification certificateVerification;
  93. /* Callbacks for async connection handshakes */
  94. UA_ConnectClientConnection connectionFunc;
  95. UA_ConnectClientConnection initConnectionFunc;
  96. void (*pollConnectionFunc)(UA_Client *client, void *context);
  97. /* Callback for state changes */
  98. void (*stateCallback)(UA_Client *client, UA_ClientState clientState);
  99. /* When connectivityCheckInterval is greater than 0, every
  100. * connectivityCheckInterval (in ms), a async read request is performed on
  101. * the server. inactivityCallback is called when the client receive no
  102. * response for this read request The connection can be closed, this in an
  103. * attempt to recreate a healthy connection. */
  104. void (*inactivityCallback)(UA_Client *client);
  105. #ifdef UA_ENABLE_SUBSCRIPTIONS
  106. /* Number of PublishResponse queued up in the server */
  107. UA_UInt16 outStandingPublishRequests;
  108. /* If the client does not receive a PublishResponse after the defined delay
  109. * of ``(sub->publishingInterval * sub->maxKeepAliveCount) +
  110. * client->config.timeout)``, then subscriptionInactivityCallback is called
  111. * for the subscription.. */
  112. void (*subscriptionInactivityCallback)(UA_Client *client,
  113. UA_UInt32 subscriptionId,
  114. void *subContext);
  115. #endif
  116. } UA_ClientConfig;
  117. _UA_END_DECLS
  118. #endif /* UA_CLIENT_CONFIG_H */