ua_session.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. #ifndef UA_SESSION_H_
  5. #define UA_SESSION_H_
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. #include "queue.h"
  10. #include "ua_types.h"
  11. #include "ua_securechannel.h"
  12. #include "ua_server.h"
  13. #define UA_MAXCONTINUATIONPOINTS 5
  14. struct ContinuationPointEntry {
  15. LIST_ENTRY(ContinuationPointEntry) pointers;
  16. UA_ByteString identifier;
  17. UA_BrowseDescription browseDescription;
  18. UA_UInt32 continuationIndex;
  19. UA_UInt32 maxReferences;
  20. };
  21. struct UA_Subscription;
  22. typedef struct UA_Subscription UA_Subscription;
  23. #ifdef UA_ENABLE_SUBSCRIPTIONS
  24. typedef struct UA_PublishResponseEntry {
  25. SIMPLEQ_ENTRY(UA_PublishResponseEntry) listEntry;
  26. UA_UInt32 requestId;
  27. UA_PublishResponse response;
  28. } UA_PublishResponseEntry;
  29. #endif
  30. struct UA_Session {
  31. UA_ApplicationDescription clientDescription;
  32. UA_String sessionName;
  33. UA_Boolean activated;
  34. void *sessionHandle; // pointer assigned in userland-callback
  35. UA_NodeId authenticationToken;
  36. UA_NodeId sessionId;
  37. UA_UInt32 maxRequestMessageSize;
  38. UA_UInt32 maxResponseMessageSize;
  39. UA_Double timeout; // [ms]
  40. UA_DateTime validTill;
  41. UA_SecureChannel *channel;
  42. UA_UInt16 availableContinuationPoints;
  43. LIST_HEAD(ContinuationPointList, ContinuationPointEntry) continuationPoints;
  44. #ifdef UA_ENABLE_SUBSCRIPTIONS
  45. UA_UInt32 lastSubscriptionID;
  46. LIST_HEAD(UA_ListOfUASubscriptions, UA_Subscription) serverSubscriptions;
  47. SIMPLEQ_HEAD(UA_ListOfQueuedPublishResponses, UA_PublishResponseEntry) responseQueue;
  48. #endif
  49. };
  50. /* Local access to the services (for startup and maintenance) uses this Session
  51. * with all possible access rights (Session ID: 1) */
  52. extern UA_Session adminSession;
  53. void UA_Session_init(UA_Session *session);
  54. void UA_Session_deleteMembersCleanup(UA_Session *session, UA_Server *server);
  55. /* If any activity on a session happens, the timeout is extended */
  56. void UA_Session_updateLifetime(UA_Session *session);
  57. #ifdef UA_ENABLE_SUBSCRIPTIONS
  58. void UA_Session_addSubscription(UA_Session *session, UA_Subscription *newSubscription);
  59. UA_Subscription *
  60. UA_Session_getSubscriptionByID(UA_Session *session, UA_UInt32 subscriptionID);
  61. UA_StatusCode
  62. UA_Session_deleteSubscription(UA_Server *server, UA_Session *session,
  63. UA_UInt32 subscriptionID);
  64. UA_UInt32
  65. UA_Session_getUniqueSubscriptionID(UA_Session *session);
  66. #endif
  67. /**
  68. * Log Helper
  69. * ---------- */
  70. #define UA_LOG_TRACE_SESSION(LOGGER, SESSION, MSG, ...) \
  71. UA_LOG_TRACE(LOGGER, UA_LOGCATEGORY_SESSION, "Connection %i | SecureChannel %i | Session " UA_PRINTF_GUID_FORMAT " | " MSG, \
  72. (SESSION->channel ? (SESSION->channel->connection ? SESSION->channel->connection->sockfd : 0) : 0), \
  73. (SESSION->channel ? SESSION->channel->securityToken.channelId : 0), \
  74. UA_PRINTF_GUID_DATA(SESSION->sessionId.identifier.guid), \
  75. ##__VA_ARGS__);
  76. #define UA_LOG_DEBUG_SESSION(LOGGER, SESSION, MSG, ...) \
  77. UA_LOG_DEBUG(LOGGER, UA_LOGCATEGORY_SESSION, "Connection %i | SecureChannel %i | Session " UA_PRINTF_GUID_FORMAT " | " MSG, \
  78. (SESSION->channel ? (SESSION->channel->connection ? SESSION->channel->connection->sockfd : 0) : 0), \
  79. (SESSION->channel ? SESSION->channel->securityToken.channelId : 0), \
  80. UA_PRINTF_GUID_DATA(SESSION->sessionId.identifier.guid), \
  81. ##__VA_ARGS__);
  82. #define UA_LOG_INFO_SESSION(LOGGER, SESSION, MSG, ...) \
  83. UA_LOG_INFO(LOGGER, UA_LOGCATEGORY_SESSION, "Connection %i | SecureChannel %i | Session " UA_PRINTF_GUID_FORMAT " | " MSG, \
  84. (SESSION->channel ? (SESSION->channel->connection ? SESSION->channel->connection->sockfd : 0) : 0), \
  85. (SESSION->channel ? SESSION->channel->securityToken.channelId : 0), \
  86. UA_PRINTF_GUID_DATA(SESSION->sessionId.identifier.guid), \
  87. ##__VA_ARGS__);
  88. #define UA_LOG_WARNING_SESSION(LOGGER, SESSION, MSG, ...) \
  89. UA_LOG_WARNING(LOGGER, UA_LOGCATEGORY_SESSION, "Connection %i | SecureChannel %i | Session " UA_PRINTF_GUID_FORMAT " | " MSG, \
  90. (SESSION->channel ? (SESSION->channel->connection ? SESSION->channel->connection->sockfd : 0) : 0), \
  91. (SESSION->channel ? SESSION->channel->securityToken.channelId : 0), \
  92. UA_PRINTF_GUID_DATA(SESSION->sessionId.identifier.guid), \
  93. ##__VA_ARGS__);
  94. #define UA_LOG_ERROR_SESSION(LOGGER, SESSION, MSG, ...) \
  95. UA_LOG_ERROR(LOGGER, UA_LOGCATEGORY_SESSION, "Connection %i | SecureChannel %i | Session " UA_PRINTF_GUID_FORMAT " | " MSG, \
  96. (SESSION->channel ? (SESSION->channel->connection ? SESSION->channel->connection->sockfd : 0) : 0), \
  97. (SESSION->channel ? SESSION->channel->securityToken.channelId : 0), \
  98. UA_PRINTF_GUID_DATA(SESSION->sessionId.identifier.guid), \
  99. ##__VA_ARGS__);
  100. #define UA_LOG_FATAL_SESSION(LOGGER, SESSION, MSG, ...) \
  101. UA_LOG_FATAL(LOGGER, UA_LOGCATEGORY_SESSION, "Connection %i | SecureChannel %i | Session " UA_PRINTF_GUID_FORMAT " | " MSG, \
  102. (SESSION->channel ? (SESSION->channel->connection ? SESSION->channel->connection->sockfd : 0) : 0), \
  103. (SESSION->channel ? SESSION->channel->securityToken.channelId : 0), \
  104. UA_PRINTF_GUID_DATA(SESSION->sessionId.identifier.guid), \
  105. ##__VA_ARGS__);
  106. #ifdef __cplusplus
  107. } // extern "C"
  108. #endif
  109. #endif /* UA_SESSION_H_ */