ua_services_session.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include "ua_services.h"
  2. #include "ua_server_internal.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, channel, &newSession);
  13. if(response->responseHeader.serviceResult != UA_STATUSCODE_GOOD)
  14. return;
  15. //TODO get maxResponseMessageSize
  16. UA_String_copy(&request->sessionName, &newSession->sessionName);
  17. newSession->maxResponseMessageSize = request->maxResponseMessageSize;
  18. response->sessionId = newSession->sessionId;
  19. response->revisedSessionTimeout = newSession->timeout;
  20. response->authenticationToken = newSession->authenticationToken;
  21. UA_ByteString_copy(&server->serverCertificate, &response->serverCertificate);
  22. response->serverEndpointsSize = 1;
  23. response->serverEndpoints = UA_alloc(sizeof(UA_EndpointDescription));
  24. UA_EndpointDescription_copy(server->endpointDescriptions, response->serverEndpoints);
  25. }
  26. void Service_ActivateSession(UA_Server *server,UA_SecureChannel *channel,
  27. const UA_ActivateSessionRequest *request,
  28. UA_ActivateSessionResponse *response) {
  29. // make the channel know about the session
  30. UA_Session *foundSession;
  31. UA_SessionManager_getSessionByToken(&server->sessionManager,
  32. (UA_NodeId*)&request->requestHeader.authenticationToken,
  33. &foundSession);
  34. if(foundSession == UA_NULL)
  35. response->responseHeader.serviceResult = UA_STATUSCODE_BADIDENTITYTOKENINVALID;
  36. else
  37. channel->session = foundSession;
  38. }
  39. void Service_CloseSession(UA_Server *server, const UA_CloseSessionRequest *request,
  40. UA_CloseSessionResponse *response) {
  41. UA_Session *foundSession;
  42. UA_SessionManager_getSessionByToken(&server->sessionManager,
  43. (UA_NodeId*)&request->requestHeader.authenticationToken,
  44. &foundSession);
  45. if(foundSession == UA_NULL){
  46. response->responseHeader.serviceResult = UA_STATUSCODE_BADIDENTITYTOKENINVALID;
  47. return;
  48. }
  49. if(UA_SessionManager_removeSession(&server->sessionManager, &foundSession->sessionId) == UA_STATUSCODE_GOOD){
  50. response->responseHeader.serviceResult = UA_STATUSCODE_GOOD;
  51. }else{
  52. //still not 100% sure about the return code
  53. response->responseHeader.serviceResult = UA_STATUSCODE_BADSECURECHANNELIDINVALID;
  54. }
  55. }