ua_session.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. * C99 requires at least one element for the variadic argument. If the log
  73. * statement has no variable arguments, supply an additional NULL. It will be
  74. * ignored by printf. */
  75. #define UA_LOG_TRACE_SESSION(LOGGER, SESSION, MSG, ...) \
  76. UA_LOG_TRACE(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_DEBUG_SESSION(LOGGER, SESSION, MSG, ...) \
  82. UA_LOG_DEBUG(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_INFO_SESSION(LOGGER, SESSION, MSG, ...) \
  88. UA_LOG_INFO(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_WARNING_SESSION(LOGGER, SESSION, MSG, ...) \
  94. UA_LOG_WARNING(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. #define UA_LOG_ERROR_SESSION(LOGGER, SESSION, MSG, ...) \
  100. UA_LOG_ERROR(LOGGER, UA_LOGCATEGORY_SESSION, "Connection %i | SecureChannel %i | Session " UA_PRINTF_GUID_FORMAT " | " MSG, \
  101. ((SESSION)->channel ? ((SESSION)->channel->connection ? (SESSION)->channel->connection->sockfd : 0) : 0), \
  102. ((SESSION)->channel ? (SESSION)->channel->securityToken.channelId : 0), \
  103. UA_PRINTF_GUID_DATA((SESSION)->sessionId.identifier.guid), \
  104. __VA_ARGS__);
  105. #define UA_LOG_FATAL_SESSION(LOGGER, SESSION, MSG, ...) \
  106. UA_LOG_FATAL(LOGGER, UA_LOGCATEGORY_SESSION, "Connection %i | SecureChannel %i | Session " UA_PRINTF_GUID_FORMAT " | " MSG, \
  107. ((SESSION)->channel ? ((SESSION)->channel->connection ? (SESSION)->channel->connection->sockfd : 0) : 0), \
  108. ((SESSION)->channel ? (SESSION)->channel->securityToken.channelId : 0), \
  109. UA_PRINTF_GUID_DATA((SESSION)->sessionId.identifier.guid), \
  110. __VA_ARGS__);
  111. #ifdef __cplusplus
  112. } // extern "C"
  113. #endif
  114. #endif /* UA_SESSION_H_ */