ua_session.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. #include "ua_util.h"
  14. #define UA_MAXCONTINUATIONPOINTS 5
  15. typedef struct ContinuationPointEntry {
  16. LIST_ENTRY(ContinuationPointEntry) pointers;
  17. UA_ByteString identifier;
  18. UA_BrowseDescription browseDescription;
  19. UA_UInt32 maxReferences;
  20. /* The last point in the node references? */
  21. size_t referenceKindIndex;
  22. size_t targetIndex;
  23. } ContinuationPointEntry;
  24. struct UA_Subscription;
  25. typedef struct UA_Subscription UA_Subscription;
  26. #ifdef UA_ENABLE_SUBSCRIPTIONS
  27. typedef struct UA_PublishResponseEntry {
  28. SIMPLEQ_ENTRY(UA_PublishResponseEntry) listEntry;
  29. UA_UInt32 requestId;
  30. UA_PublishResponse response;
  31. } UA_PublishResponseEntry;
  32. #endif
  33. struct UA_Session {
  34. UA_ApplicationDescription clientDescription;
  35. UA_String sessionName;
  36. UA_Boolean activated;
  37. void *sessionHandle; // pointer assigned in userland-callback
  38. UA_NodeId authenticationToken;
  39. UA_NodeId sessionId;
  40. UA_UInt32 maxRequestMessageSize;
  41. UA_UInt32 maxResponseMessageSize;
  42. UA_Double timeout; // [ms]
  43. UA_DateTime validTill;
  44. UA_ByteString serverNonce;
  45. UA_SecureChannel *channel;
  46. UA_UInt16 availableContinuationPoints;
  47. LIST_HEAD(ContinuationPointList, ContinuationPointEntry) continuationPoints;
  48. #ifdef UA_ENABLE_SUBSCRIPTIONS
  49. UA_UInt32 lastSubscriptionID;
  50. UA_UInt32 lastSeenSubscriptionID;
  51. LIST_HEAD(UA_ListOfUASubscriptions, UA_Subscription) serverSubscriptions;
  52. SIMPLEQ_HEAD(UA_ListOfQueuedPublishResponses, UA_PublishResponseEntry) responseQueue;
  53. UA_UInt32 numSubscriptions;
  54. UA_UInt32 numPublishReq;
  55. #endif
  56. };
  57. /* Local access to the services (for startup and maintenance) uses this Session
  58. * with all possible access rights (Session ID: 1) */
  59. extern UA_Session adminSession;
  60. void UA_Session_init(UA_Session *session);
  61. void UA_Session_deleteMembersCleanup(UA_Session *session, UA_Server *server);
  62. /* If any activity on a session happens, the timeout is extended */
  63. void UA_Session_updateLifetime(UA_Session *session);
  64. #ifdef UA_ENABLE_SUBSCRIPTIONS
  65. void UA_Session_addSubscription(UA_Session *session, UA_Subscription *newSubscription);
  66. UA_UInt32
  67. UA_Session_getNumSubscriptions( UA_Session *session );
  68. UA_Subscription *
  69. UA_Session_getSubscriptionByID(UA_Session *session, UA_UInt32 subscriptionID);
  70. UA_StatusCode
  71. UA_Session_deleteSubscription(UA_Server *server, UA_Session *session,
  72. UA_UInt32 subscriptionID);
  73. UA_UInt32
  74. UA_Session_getUniqueSubscriptionID(UA_Session *session);
  75. UA_UInt32
  76. UA_Session_getNumPublishReq(UA_Session *session);
  77. UA_PublishResponseEntry*
  78. UA_Session_getPublishReq(UA_Session *session);
  79. void
  80. UA_Session_removePublishReq(UA_Session *session, UA_PublishResponseEntry* entry);
  81. void
  82. UA_Session_addPublishReq(UA_Session *session, UA_PublishResponseEntry* entry);
  83. #endif
  84. /**
  85. * Log Helper
  86. * ----------
  87. * We have to jump through some hoops to enable the use of format strings
  88. * without arguments since (pedantic) C99 does not allow variadic macros with
  89. * zero arguments. So we add a dummy argument that is not printed (%.0s is
  90. * string of length zero). */
  91. #define UA_LOG_TRACE_SESSION_INTERNAL(LOGGER, SESSION, MSG, ...) \
  92. UA_LOG_TRACE(LOGGER, UA_LOGCATEGORY_SESSION, \
  93. "Connection %i | SecureChannel %i | Session " UA_PRINTF_GUID_FORMAT " | " MSG "%.0s", \
  94. ((SESSION)->channel ? ((SESSION)->channel->connection ? (SESSION)->channel->connection->sockfd : 0) : 0), \
  95. ((SESSION)->channel ? (SESSION)->channel->securityToken.channelId : 0), \
  96. UA_PRINTF_GUID_DATA((SESSION)->sessionId.identifier.guid), __VA_ARGS__)
  97. #define UA_LOG_TRACE_SESSION(LOGGER, SESSION, ...) \
  98. UA_MACRO_EXPAND(UA_LOG_TRACE_SESSION_INTERNAL(LOGGER, SESSION, __VA_ARGS__, ""))
  99. #define UA_LOG_DEBUG_SESSION_INTERNAL(LOGGER, SESSION, MSG, ...) \
  100. UA_LOG_DEBUG(LOGGER, UA_LOGCATEGORY_SESSION, \
  101. "Connection %i | SecureChannel %i | Session " UA_PRINTF_GUID_FORMAT " | " MSG "%.0s", \
  102. ((SESSION)->channel ? ((SESSION)->channel->connection ? (SESSION)->channel->connection->sockfd : 0) : 0), \
  103. ((SESSION)->channel ? (SESSION)->channel->securityToken.channelId : 0), \
  104. UA_PRINTF_GUID_DATA((SESSION)->sessionId.identifier.guid), __VA_ARGS__)
  105. #define UA_LOG_DEBUG_SESSION(LOGGER, SESSION, ...) \
  106. UA_MACRO_EXPAND(UA_LOG_DEBUG_SESSION_INTERNAL(LOGGER, SESSION, __VA_ARGS__, ""))
  107. #define UA_LOG_INFO_SESSION_INTERNAL(LOGGER, SESSION, MSG, ...) \
  108. UA_LOG_INFO(LOGGER, UA_LOGCATEGORY_SESSION, \
  109. "Connection %i | SecureChannel %i | Session " UA_PRINTF_GUID_FORMAT " | " MSG "%.0s", \
  110. ((SESSION)->channel ? ((SESSION)->channel->connection ? (SESSION)->channel->connection->sockfd : 0) : 0), \
  111. ((SESSION)->channel ? (SESSION)->channel->securityToken.channelId : 0), \
  112. UA_PRINTF_GUID_DATA((SESSION)->sessionId.identifier.guid), __VA_ARGS__)
  113. #define UA_LOG_INFO_SESSION(LOGGER, SESSION, ...) \
  114. UA_MACRO_EXPAND(UA_LOG_INFO_SESSION_INTERNAL(LOGGER, SESSION, __VA_ARGS__, ""))
  115. #define UA_LOG_WARNING_SESSION_INTERNAL(LOGGER, SESSION, MSG, ...) \
  116. UA_LOG_WARNING(LOGGER, UA_LOGCATEGORY_SESSION, \
  117. "Connection %i | SecureChannel %i | Session " UA_PRINTF_GUID_FORMAT " | " MSG "%.0s", \
  118. ((SESSION)->channel ? ((SESSION)->channel->connection ? (SESSION)->channel->connection->sockfd : 0) : 0), \
  119. ((SESSION)->channel ? (SESSION)->channel->securityToken.channelId : 0), \
  120. UA_PRINTF_GUID_DATA((SESSION)->sessionId.identifier.guid), __VA_ARGS__)
  121. #define UA_LOG_WARNING_SESSION(LOGGER, SESSION, ...) \
  122. UA_MACRO_EXPAND(UA_LOG_WARNING_SESSION_INTERNAL(LOGGER, SESSION, __VA_ARGS__, ""))
  123. #define UA_LOG_ERROR_SESSION_INTERNAL(LOGGER, SESSION, MSG, ...) \
  124. UA_LOG_ERROR(LOGGER, UA_LOGCATEGORY_SESSION, \
  125. "Connection %i | SecureChannel %i | Session " UA_PRINTF_GUID_FORMAT " | " MSG "%.0s", \
  126. ((SESSION)->channel ? ((SESSION)->channel->connection ? (SESSION)->channel->connection->sockfd : 0) : 0), \
  127. ((SESSION)->channel ? (SESSION)->channel->securityToken.channelId : 0), \
  128. UA_PRINTF_GUID_DATA((SESSION)->sessionId.identifier.guid), __VA_ARGS__)
  129. #define UA_LOG_ERROR_SESSION(LOGGER, SESSION, ...) \
  130. UA_MACRO_EXPAND(UA_LOG_ERROR_SESSION_INTERNAL(LOGGER, SESSION, __VA_ARGS__, ""))
  131. #define UA_LOG_FATAL_SESSION_INTERNAL(LOGGER, SESSION, MSG, ...) \
  132. UA_LOG_FATAL(LOGGER, UA_LOGCATEGORY_SESSION, \
  133. "Connection %i | SecureChannel %i | Session " UA_PRINTF_GUID_FORMAT " | " MSG "%.0s", \
  134. ((SESSION)->channel ? ((SESSION)->channel->connection ? (SESSION)->channel->connection->sockfd : 0) : 0), \
  135. ((SESSION)->channel ? (SESSION)->channel->securityToken.channelId : 0), \
  136. UA_PRINTF_GUID_DATA((SESSION)->sessionId.identifier.guid), __VA_ARGS__)
  137. #define UA_LOG_FATAL_SESSION(LOGGER, SESSION, ...) \
  138. UA_MACRO_EXPAND(UA_LOG_FATAL_SESSION_INTERNAL(LOGGER, SESSION, __VA_ARGS__, ""))
  139. #ifdef __cplusplus
  140. } // extern "C"
  141. #endif
  142. #endif /* UA_SESSION_H_ */