ua_session.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #ifndef UA_SESSION_H_
  2. #define UA_SESSION_H_
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  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_String sessionName;
  30. UA_Boolean activated;
  31. void *sessionHandle; // pointer assigned in userland-callback
  32. UA_NodeId authenticationToken;
  33. UA_NodeId sessionId;
  34. UA_UInt32 maxRequestMessageSize;
  35. UA_UInt32 maxResponseMessageSize;
  36. UA_Double timeout; // [ms]
  37. UA_DateTime validTill;
  38. UA_SecureChannel *channel;
  39. UA_UInt16 availableContinuationPoints;
  40. LIST_HEAD(ContinuationPointList, ContinuationPointEntry) continuationPoints;
  41. #ifdef UA_ENABLE_SUBSCRIPTIONS
  42. UA_UInt32 lastSubscriptionID;
  43. LIST_HEAD(UA_ListOfUASubscriptions, UA_Subscription) serverSubscriptions;
  44. SIMPLEQ_HEAD(UA_ListOfQueuedPublishResponses, UA_PublishResponseEntry) responseQueue;
  45. #endif
  46. };
  47. /* Local access to the services (for startup and maintenance) uses this Session
  48. * with all possible access rights (Session ID: 1) */
  49. extern UA_Session adminSession;
  50. void UA_Session_init(UA_Session *session);
  51. void UA_Session_deleteMembersCleanup(UA_Session *session, UA_Server *server);
  52. /* If any activity on a session happens, the timeout is extended */
  53. void UA_Session_updateLifetime(UA_Session *session);
  54. #ifdef UA_ENABLE_SUBSCRIPTIONS
  55. void UA_Session_addSubscription(UA_Session *session, UA_Subscription *newSubscription);
  56. UA_Subscription *
  57. UA_Session_getSubscriptionByID(UA_Session *session, UA_UInt32 subscriptionID);
  58. UA_StatusCode
  59. UA_Session_deleteSubscription(UA_Server *server, UA_Session *session,
  60. UA_UInt32 subscriptionID);
  61. UA_UInt32
  62. UA_Session_getUniqueSubscriptionID(UA_Session *session);
  63. #endif
  64. /**
  65. * Log Helper
  66. * ---------- */
  67. #define UA_LOG_TRACE_SESSION(LOGGER, SESSION, MSG, ...) \
  68. UA_LOG_TRACE(LOGGER, UA_LOGCATEGORY_SESSION, "Connection %i | SecureChannel %i | Session " UA_PRINTF_GUID_FORMAT " | " MSG, \
  69. (SESSION->channel ? (SESSION->channel->connection ? SESSION->channel->connection->sockfd : 0) : 0), \
  70. (SESSION->channel ? SESSION->channel->securityToken.channelId : 0), \
  71. UA_PRINTF_GUID_DATA(SESSION->sessionId.identifier.guid), \
  72. ##__VA_ARGS__);
  73. #define UA_LOG_DEBUG_SESSION(LOGGER, SESSION, MSG, ...) \
  74. UA_LOG_DEBUG(LOGGER, UA_LOGCATEGORY_SESSION, "Connection %i | SecureChannel %i | Session " UA_PRINTF_GUID_FORMAT " | " MSG, \
  75. (SESSION->channel ? (SESSION->channel->connection ? SESSION->channel->connection->sockfd : 0) : 0), \
  76. (SESSION->channel ? SESSION->channel->securityToken.channelId : 0), \
  77. UA_PRINTF_GUID_DATA(SESSION->sessionId.identifier.guid), \
  78. ##__VA_ARGS__);
  79. #define UA_LOG_INFO_SESSION(LOGGER, SESSION, MSG, ...) \
  80. UA_LOG_INFO(LOGGER, UA_LOGCATEGORY_SESSION, "Connection %i | SecureChannel %i | Session " UA_PRINTF_GUID_FORMAT " | " MSG, \
  81. (SESSION->channel ? (SESSION->channel->connection ? SESSION->channel->connection->sockfd : 0) : 0), \
  82. (SESSION->channel ? SESSION->channel->securityToken.channelId : 0), \
  83. UA_PRINTF_GUID_DATA(SESSION->sessionId.identifier.guid), \
  84. ##__VA_ARGS__);
  85. #define UA_LOG_WARNING_SESSION(LOGGER, SESSION, MSG, ...) \
  86. UA_LOG_WARNING(LOGGER, UA_LOGCATEGORY_SESSION, "Connection %i | SecureChannel %i | Session " UA_PRINTF_GUID_FORMAT " | " MSG, \
  87. (SESSION->channel ? (SESSION->channel->connection ? SESSION->channel->connection->sockfd : 0) : 0), \
  88. (SESSION->channel ? SESSION->channel->securityToken.channelId : 0), \
  89. UA_PRINTF_GUID_DATA(SESSION->sessionId.identifier.guid), \
  90. ##__VA_ARGS__);
  91. #define UA_LOG_ERROR_SESSION(LOGGER, SESSION, MSG, ...) \
  92. UA_LOG_ERROR(LOGGER, UA_LOGCATEGORY_SESSION, "Connection %i | SecureChannel %i | Session " UA_PRINTF_GUID_FORMAT " | " MSG, \
  93. (SESSION->channel ? (SESSION->channel->connection ? SESSION->channel->connection->sockfd : 0) : 0), \
  94. (SESSION->channel ? SESSION->channel->securityToken.channelId : 0), \
  95. UA_PRINTF_GUID_DATA(SESSION->sessionId.identifier.guid), \
  96. ##__VA_ARGS__);
  97. #define UA_LOG_FATAL_SESSION(LOGGER, SESSION, MSG, ...) \
  98. UA_LOG_FATAL(LOGGER, UA_LOGCATEGORY_SESSION, "Connection %i | SecureChannel %i | Session " UA_PRINTF_GUID_FORMAT " | " MSG, \
  99. (SESSION->channel ? (SESSION->channel->connection ? SESSION->channel->connection->sockfd : 0) : 0), \
  100. (SESSION->channel ? SESSION->channel->securityToken.channelId : 0), \
  101. UA_PRINTF_GUID_DATA(SESSION->sessionId.identifier.guid), \
  102. ##__VA_ARGS__);
  103. #ifdef __cplusplus
  104. } // extern "C"
  105. #endif
  106. #endif /* UA_SESSION_H_ */