ua_session.h 5.3 KB

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