ua_session.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. typedef struct ContinuationPointEntry {
  15. LIST_ENTRY(ContinuationPointEntry) pointers;
  16. UA_ByteString identifier;
  17. UA_BrowseDescription browseDescription;
  18. UA_UInt32 maxReferences;
  19. /* The last point in the node references? */
  20. size_t referenceKindIndex;
  21. size_t targetIndex;
  22. } ContinuationPointEntry;
  23. struct UA_Subscription;
  24. typedef struct UA_Subscription UA_Subscription;
  25. #ifdef UA_ENABLE_SUBSCRIPTIONS
  26. typedef struct UA_PublishResponseEntry {
  27. SIMPLEQ_ENTRY(UA_PublishResponseEntry) listEntry;
  28. UA_UInt32 requestId;
  29. UA_PublishResponse response;
  30. } UA_PublishResponseEntry;
  31. #endif
  32. struct UA_Session {
  33. UA_ApplicationDescription clientDescription;
  34. UA_String sessionName;
  35. UA_Boolean activated;
  36. void *sessionHandle; // pointer assigned in userland-callback
  37. UA_NodeId authenticationToken;
  38. UA_NodeId sessionId;
  39. UA_UInt32 maxRequestMessageSize;
  40. UA_UInt32 maxResponseMessageSize;
  41. UA_Double timeout; // [ms]
  42. UA_DateTime validTill;
  43. UA_SecureChannel *channel;
  44. UA_UInt16 availableContinuationPoints;
  45. LIST_HEAD(ContinuationPointList, ContinuationPointEntry) continuationPoints;
  46. #ifdef UA_ENABLE_SUBSCRIPTIONS
  47. UA_UInt32 lastSubscriptionID;
  48. LIST_HEAD(UA_ListOfUASubscriptions, UA_Subscription) serverSubscriptions;
  49. SIMPLEQ_HEAD(UA_ListOfQueuedPublishResponses, UA_PublishResponseEntry) responseQueue;
  50. #endif
  51. };
  52. /* Local access to the services (for startup and maintenance) uses this Session
  53. * with all possible access rights (Session ID: 1) */
  54. extern UA_Session adminSession;
  55. void UA_Session_init(UA_Session *session);
  56. void UA_Session_deleteMembersCleanup(UA_Session *session, UA_Server *server);
  57. /* If any activity on a session happens, the timeout is extended */
  58. void UA_Session_updateLifetime(UA_Session *session);
  59. #ifdef UA_ENABLE_SUBSCRIPTIONS
  60. void UA_Session_addSubscription(UA_Session *session, UA_Subscription *newSubscription);
  61. UA_Subscription *
  62. UA_Session_getSubscriptionByID(UA_Session *session, UA_UInt32 subscriptionID);
  63. UA_StatusCode
  64. UA_Session_deleteSubscription(UA_Server *server, UA_Session *session,
  65. UA_UInt32 subscriptionID);
  66. UA_UInt32
  67. UA_Session_getUniqueSubscriptionID(UA_Session *session);
  68. #endif
  69. /**
  70. * Log Helper
  71. * ---------- */
  72. #define UA_LOG_TRACE_SESSION(LOGGER, SESSION, MSG, ...) \
  73. UA_LOG_TRACE(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_DEBUG_SESSION(LOGGER, SESSION, MSG, ...) \
  79. UA_LOG_DEBUG(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_INFO_SESSION(LOGGER, SESSION, MSG, ...) \
  85. UA_LOG_INFO(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_WARNING_SESSION(LOGGER, SESSION, MSG, ...) \
  91. UA_LOG_WARNING(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_ERROR_SESSION(LOGGER, SESSION, MSG, ...) \
  97. UA_LOG_ERROR(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. #define UA_LOG_FATAL_SESSION(LOGGER, SESSION, MSG, ...) \
  103. UA_LOG_FATAL(LOGGER, UA_LOGCATEGORY_SESSION, "Connection %i | SecureChannel %i | Session " UA_PRINTF_GUID_FORMAT " | " MSG, \
  104. ((SESSION)->channel ? ((SESSION)->channel->connection ? (SESSION)->channel->connection->sockfd : 0) : 0), \
  105. ((SESSION)->channel ? (SESSION)->channel->securityToken.channelId : 0), \
  106. UA_PRINTF_GUID_DATA((SESSION)->sessionId.identifier.guid), \
  107. ##__VA_ARGS__);
  108. #ifdef __cplusplus
  109. } // extern "C"
  110. #endif
  111. #endif /* UA_SESSION_H_ */