ua_session.h 5.6 KB

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