ua_session.h 5.4 KB

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