ua_session.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. LIST_HEAD(UA_ListOfUASubscriptions, UA_Subscription) serverSubscriptions;
  51. SIMPLEQ_HEAD(UA_ListOfQueuedPublishResponses, UA_PublishResponseEntry) responseQueue;
  52. #endif
  53. };
  54. /* Local access to the services (for startup and maintenance) uses this Session
  55. * with all possible access rights (Session ID: 1) */
  56. extern UA_Session adminSession;
  57. void UA_Session_init(UA_Session *session);
  58. void UA_Session_deleteMembersCleanup(UA_Session *session, UA_Server *server);
  59. /* If any activity on a session happens, the timeout is extended */
  60. void UA_Session_updateLifetime(UA_Session *session);
  61. #ifdef UA_ENABLE_SUBSCRIPTIONS
  62. void UA_Session_addSubscription(UA_Session *session, UA_Subscription *newSubscription);
  63. UA_Subscription *
  64. UA_Session_getSubscriptionByID(UA_Session *session, UA_UInt32 subscriptionID);
  65. UA_StatusCode
  66. UA_Session_deleteSubscription(UA_Server *server, UA_Session *session,
  67. UA_UInt32 subscriptionID);
  68. UA_UInt32
  69. UA_Session_getUniqueSubscriptionID(UA_Session *session);
  70. #endif
  71. /**
  72. * Log Helper
  73. * ----------
  74. * We have to jump through some hoops to enable the use of format strings
  75. * without arguments since (pedantic) C99 does not allow variadic macros with
  76. * zero arguments. So we add a dummy argument that is not printed (%.0s is
  77. * string of length zero). */
  78. #define UA_LOG_TRACE_SESSION_INTERNAL(LOGGER, SESSION, MSG, ...) \
  79. UA_LOG_TRACE(LOGGER, UA_LOGCATEGORY_SESSION, \
  80. "Connection %i | SecureChannel %i | Session " UA_PRINTF_GUID_FORMAT " | " MSG "%.0s", \
  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), __VA_ARGS__)
  84. #define UA_LOG_TRACE_SESSION(LOGGER, SESSION, ...) \
  85. UA_MACRO_EXPAND(UA_LOG_TRACE_SESSION_INTERNAL(LOGGER, SESSION, __VA_ARGS__, ""))
  86. #define UA_LOG_DEBUG_SESSION_INTERNAL(LOGGER, SESSION, MSG, ...) \
  87. UA_LOG_DEBUG(LOGGER, UA_LOGCATEGORY_SESSION, \
  88. "Connection %i | SecureChannel %i | Session " UA_PRINTF_GUID_FORMAT " | " MSG "%.0s", \
  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), __VA_ARGS__)
  92. #define UA_LOG_DEBUG_SESSION(LOGGER, SESSION, ...) \
  93. UA_MACRO_EXPAND(UA_LOG_DEBUG_SESSION_INTERNAL(LOGGER, SESSION, __VA_ARGS__, ""))
  94. #define UA_LOG_INFO_SESSION_INTERNAL(LOGGER, SESSION, MSG, ...) \
  95. UA_LOG_INFO(LOGGER, UA_LOGCATEGORY_SESSION, \
  96. "Connection %i | SecureChannel %i | Session " UA_PRINTF_GUID_FORMAT " | " MSG "%.0s", \
  97. ((SESSION)->channel ? ((SESSION)->channel->connection ? (SESSION)->channel->connection->sockfd : 0) : 0), \
  98. ((SESSION)->channel ? (SESSION)->channel->securityToken.channelId : 0), \
  99. UA_PRINTF_GUID_DATA((SESSION)->sessionId.identifier.guid), __VA_ARGS__)
  100. #define UA_LOG_INFO_SESSION(LOGGER, SESSION, ...) \
  101. UA_MACRO_EXPAND(UA_LOG_INFO_SESSION_INTERNAL(LOGGER, SESSION, __VA_ARGS__, ""))
  102. #define UA_LOG_WARNING_SESSION_INTERNAL(LOGGER, SESSION, MSG, ...) \
  103. UA_LOG_WARNING(LOGGER, UA_LOGCATEGORY_SESSION, \
  104. "Connection %i | SecureChannel %i | Session " UA_PRINTF_GUID_FORMAT " | " MSG "%.0s", \
  105. ((SESSION)->channel ? ((SESSION)->channel->connection ? (SESSION)->channel->connection->sockfd : 0) : 0), \
  106. ((SESSION)->channel ? (SESSION)->channel->securityToken.channelId : 0), \
  107. UA_PRINTF_GUID_DATA((SESSION)->sessionId.identifier.guid), __VA_ARGS__)
  108. #define UA_LOG_WARNING_SESSION(LOGGER, SESSION, ...) \
  109. UA_MACRO_EXPAND(UA_LOG_WARNING_SESSION_INTERNAL(LOGGER, SESSION, __VA_ARGS__, ""))
  110. #define UA_LOG_ERROR_SESSION_INTERNAL(LOGGER, SESSION, MSG, ...) \
  111. UA_LOG_ERROR(LOGGER, UA_LOGCATEGORY_SESSION, \
  112. "Connection %i | SecureChannel %i | Session " UA_PRINTF_GUID_FORMAT " | " MSG "%.0s", \
  113. ((SESSION)->channel ? ((SESSION)->channel->connection ? (SESSION)->channel->connection->sockfd : 0) : 0), \
  114. ((SESSION)->channel ? (SESSION)->channel->securityToken.channelId : 0), \
  115. UA_PRINTF_GUID_DATA((SESSION)->sessionId.identifier.guid), __VA_ARGS__)
  116. #define UA_LOG_ERROR_SESSION(LOGGER, SESSION, ...) \
  117. UA_MACRO_EXPAND(UA_LOG_ERROR_SESSION_INTERNAL(LOGGER, SESSION, __VA_ARGS__, ""))
  118. #define UA_LOG_FATAL_SESSION_INTERNAL(LOGGER, SESSION, MSG, ...) \
  119. UA_LOG_FATAL(LOGGER, UA_LOGCATEGORY_SESSION, \
  120. "Connection %i | SecureChannel %i | Session " UA_PRINTF_GUID_FORMAT " | " MSG "%.0s", \
  121. ((SESSION)->channel ? ((SESSION)->channel->connection ? (SESSION)->channel->connection->sockfd : 0) : 0), \
  122. ((SESSION)->channel ? (SESSION)->channel->securityToken.channelId : 0), \
  123. UA_PRINTF_GUID_DATA((SESSION)->sessionId.identifier.guid), __VA_ARGS__)
  124. #define UA_LOG_FATAL_SESSION(LOGGER, SESSION, ...) \
  125. UA_MACRO_EXPAND(UA_LOG_FATAL_SESSION_INTERNAL(LOGGER, SESSION, __VA_ARGS__, ""))
  126. #ifdef __cplusplus
  127. } // extern "C"
  128. #endif
  129. #endif /* UA_SESSION_H_ */