Просмотр исходного кода

minor fixes of session service

Stasik0 лет назад: 9
Родитель
Сommit
5f80225cd8

+ 2 - 2
src/server/ua_server.c

@@ -241,9 +241,9 @@ UA_Server * UA_Server_new(void) {
                                  TOKENLIFETIME, STARTCHANNELID, STARTTOKENID);
 
 #define MAXSESSIONCOUNT 1000
-#define SESSIONLIFETIME 10000
+#define MAXSESSIONLIFETIME 10000
 #define STARTSESSIONID 1
-    UA_SessionManager_init(&server->sessionManager, MAXSESSIONCOUNT, SESSIONLIFETIME, STARTSESSIONID);
+    UA_SessionManager_init(&server->sessionManager, MAXSESSIONCOUNT, MAXSESSIONLIFETIME, STARTSESSIONID);
 
     server->nodestore = UA_NodeStore_new();
 

+ 1 - 1
src/server/ua_services_session.c

@@ -19,7 +19,7 @@ void Service_CreateSession(UA_Server *server, UA_SecureChannel *channel,
     // session is activated will the channel point to the session as well
 	UA_Session *newSession;
     response->responseHeader.serviceResult = UA_SessionManager_createSession(&server->sessionManager,
-                                                                             channel, &newSession);
+                                                                             channel, request, &newSession);
 	if(response->responseHeader.serviceResult != UA_STATUSCODE_GOOD)
 		return;
 

+ 4 - 4
src/server/ua_session_manager.c

@@ -14,11 +14,11 @@ struct session_list_entry {
 };
 
 UA_StatusCode UA_SessionManager_init(UA_SessionManager *sessionManager, UA_UInt32 maxSessionCount,
-                                    UA_UInt32 sessionTimeout, UA_UInt32 startSessionId) {
+                                    UA_UInt32 maxSessionLifeTime, UA_UInt32 startSessionId) {
     LIST_INIT(&sessionManager->sessions);
     sessionManager->maxSessionCount = maxSessionCount;
     sessionManager->lastSessionId   = startSessionId;
-    sessionManager->sessionTimeout  = sessionTimeout;
+    sessionManager->maxSessionLifeTime  = maxSessionLifeTime;
     sessionManager->currentSessionCount = 0;
     return UA_STATUSCODE_GOOD;
 }
@@ -87,7 +87,7 @@ UA_StatusCode UA_SessionManager_getSessionByToken(UA_SessionManager *sessionMana
 
 /** Creates and adds a session. */
 UA_StatusCode UA_SessionManager_createSession(UA_SessionManager *sessionManager, UA_SecureChannel *channel,
-                                              UA_Session **session) {
+												const UA_CreateSessionRequest *request, UA_Session **session) {
     if(sessionManager->currentSessionCount >= sessionManager->maxSessionCount)
         return UA_STATUSCODE_BADTOOMANYSESSIONS;
 
@@ -102,7 +102,7 @@ UA_StatusCode UA_SessionManager_createSession(UA_SessionManager *sessionManager,
                                                          .identifierType = UA_NODEIDTYPE_NUMERIC,
                                                          .identifier.numeric = sessionManager->lastSessionId };
     newentry->session.channel = channel;
-    newentry->session.timeout = 3600 * 1000; // 1h
+    newentry->session.timeout = (request->requestedSessionTimeout <= sessionManager->maxSessionLifeTime && request->requestedSessionTimeout>0) ? request->requestedSessionTimeout : sessionManager->maxSessionLifeTime;
     UA_Session_setExpirationDate(&newentry->session);
 
     sessionManager->currentSessionCount++;

+ 2 - 3
src/server/ua_session_manager.h

@@ -12,16 +12,15 @@ typedef struct UA_SessionManager {
     UA_Int32     lastSessionId;
     UA_UInt32    currentSessionCount;
     UA_DateTime  maxSessionLifeTime;
-    UA_DateTime  sessionTimeout;
 } UA_SessionManager;
 
 UA_StatusCode UA_SessionManager_init(UA_SessionManager *sessionManager, UA_UInt32 maxSessionCount,
-                                    UA_UInt32 sessionLifetime, UA_UInt32 startSessionId);
+                                    UA_UInt32 maxSessionLifeTime, UA_UInt32 startSessionId);
 
 void UA_SessionManager_deleteMembers(UA_SessionManager *sessionManager);
 
 UA_StatusCode UA_SessionManager_createSession(UA_SessionManager *sessionManager,
-                                              UA_SecureChannel *channel, UA_Session **session);
+                                              UA_SecureChannel *channel, const UA_CreateSessionRequest *request, UA_Session **session);
 
 UA_StatusCode UA_SessionManager_removeSession(UA_SessionManager *sessionManager,
                                               const UA_NodeId *sessionId);