ua_services_session.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "ua_services.h"
  2. #include "ua_server.h"
  3. #include "ua_session_manager.h"
  4. UA_Int32 Service_CreateSession(UA_Server *server, UA_SecureChannel *channel,
  5. const UA_CreateSessionRequest *request,
  6. UA_CreateSessionResponse *response) {
  7. // creates a session and adds a pointer to the channel. Only when the
  8. // session is activated will the channel point to the session as well
  9. UA_Int32 retval = UA_SUCCESS;
  10. UA_Session *newSession;
  11. retval |= UA_SessionManager_createSession(server->sessionManager, channel, &newSession);
  12. if(retval != UA_SUCCESS)
  13. {
  14. return retval;
  15. }
  16. //TODO get maxResponseMessageSize
  17. UA_String_copy(&request->sessionName, &newSession->sessionName);
  18. newSession->maxResponseMessageSize = request->maxResponseMessageSize;
  19. response->sessionId = newSession->sessionId;
  20. response->revisedSessionTimeout = newSession->timeout;
  21. response->authenticationToken = newSession->authenticationToken;
  22. //channel->session = newSession;
  23. return retval;
  24. }
  25. UA_Int32 Service_ActivateSession(UA_Server *server, UA_Session *session,
  26. const UA_ActivateSessionRequest *request,
  27. UA_ActivateSessionResponse *response) {
  28. // make the channel know about the session
  29. UA_Session *foundSession;
  30. if(session == UA_NULL)
  31. {
  32. return UA_ERROR;
  33. }
  34. UA_SessionManager_getSessionById(server->sessionManager,&session->sessionId,&foundSession);
  35. if(foundSession == UA_NULL)
  36. {
  37. return UA_ERROR;
  38. }
  39. //channel at creation must be the same at activation
  40. if(foundSession->channel != session->channel)
  41. {
  42. return UA_ERROR;
  43. }
  44. session->channel->session = session;
  45. return UA_SUCCESS;
  46. }
  47. UA_Int32 Service_CloseSession(UA_Server *server, UA_Session *session,
  48. const UA_CloseSessionRequest *request,
  49. UA_CloseSessionResponse *response) {
  50. session->channel->session = UA_NULL;
  51. UA_SessionManager_removeSession(server->sessionManager, &session->sessionId);
  52. /* UA_NodeId sessionId; */
  53. /* UA_Session_getId(session,&sessionId); */
  54. /* UA_SessionManager_removeSession(&sessionId); */
  55. // FIXME: set response
  56. return UA_SUCCESS;
  57. }