ua_services_session.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "ua_services.h"
  2. #include "ua_server.h"
  3. #include "ua_session_manager.h"
  4. #include "ua_statuscodes.h"
  5. #include "ua_util.h"
  6. void Service_CreateSession(UA_Server *server, UA_SecureChannel *channel,
  7. const UA_CreateSessionRequest *request,
  8. UA_CreateSessionResponse *response) {
  9. // creates a session and adds a pointer to the channel. Only when the
  10. // session is activated will the channel point to the session as well
  11. UA_Session *newSession;
  12. response->responseHeader.serviceResult = UA_SessionManager_createSession(server->sessionManager,
  13. channel, &newSession);
  14. if(response->responseHeader.serviceResult != UA_STATUSCODE_GOOD)
  15. return;
  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. }
  24. void Service_ActivateSession(UA_Server *server,UA_SecureChannel *channel,
  25. const UA_ActivateSessionRequest *request,
  26. UA_ActivateSessionResponse *response) {
  27. // make the channel know about the session
  28. UA_Session *foundSession;
  29. UA_SessionManager_getSessionByToken(server->sessionManager,
  30. (UA_NodeId*)&request->requestHeader.authenticationToken,
  31. &foundSession);
  32. if(foundSession == UA_NULL)
  33. response->responseHeader.serviceResult = UA_STATUSCODE_BADIDENTITYTOKENINVALID;
  34. else
  35. channel->session = foundSession;
  36. }
  37. void Service_CloseSession(UA_Server *server, const UA_CloseSessionRequest *request,
  38. UA_CloseSessionResponse *response) {
  39. UA_Session *foundSession;
  40. UA_SessionManager_getSessionByToken(server->sessionManager,
  41. (UA_NodeId*)&request->requestHeader.authenticationToken,
  42. &foundSession);
  43. if(foundSession == UA_NULL){
  44. response->responseHeader.serviceResult = UA_STATUSCODE_BADIDENTITYTOKENINVALID;
  45. return;
  46. }
  47. if(UA_SessionManager_removeSession(server->sessionManager, &foundSession->sessionId) == UA_STATUSCODE_GOOD){
  48. response->responseHeader.serviceResult = UA_STATUSCODE_GOOD;
  49. }else{
  50. //still not 100% sure about the return code
  51. response->responseHeader.serviceResult = UA_STATUSCODE_BADSECURECHANNELIDINVALID;
  52. }
  53. }