Kaynağa Gözat

added basic functions for session support

FlorianPalm 10 yıl önce
ebeveyn
işleme
75abd0df44

+ 2 - 0
src/Makefile.am

@@ -19,6 +19,8 @@ libopen62541_la_SOURCES = opcua.c \
 			ua_services_view.c \
 			ua_application.c \
 			ua_xml.c\
+			ua_stack_session.c\
+			ua_stack_sessionManager.c\
 			ua_stack_channel.c \
 			ua_stack_channel_manager.c \
 			ua_transport_connection_manager.c \

+ 1 - 1
src/ua_stack_channel.h

@@ -64,7 +64,7 @@ UA_Int32 SL_Channel_registerChannelIdProvider(SL_ChannelIdProvider provider);
 UA_Int32 SL_Channel_checkRequestId(SL_secureChannel channel, UA_UInt32 requestId);
 
 UA_Int32 SL_Channel_checkSequenceNumber(SL_secureChannel channel, UA_UInt32 sequenceNumber);
-_Bool SL_Channel_equal(void* channel1, void* channel2);
+UA_Boolean SL_Channel_equal(void* channel1, void* channel2);
 //getters
 UA_Int32 SL_Channel_getChannelId(SL_secureChannel channel, UA_UInt32 *channelId);
 UA_Int32 SL_Channel_getTokenId(SL_secureChannel channel, UA_UInt32 *tokenlId);

+ 4 - 3
src/ua_stack_session.h

@@ -8,16 +8,17 @@
 #ifndef UA_STACK_SESSION_H_
 #define UA_STACK_SESSION_H_
 
-#include "include/opcua.h"
+#include "../include/opcua.h"
 #include "ua_stack_channel.h"
 
 #endif /* UA_STACK_SESSION_H_ */
 
 
-
-typedef UA_SessionType *UA_Session;
+typedef struct UA_SessionType *UA_Session;
 
 
 UA_Boolean UA_Session_compare(UA_Session session1, UA_Session session2);
 UA_Int32 UA_Session_getId(UA_Session session, UA_NodeId *sessionId);
 UA_Int32 UA_Session_getChannel(UA_Session session, SL_secureChannel *channel);
+
+UA_Int32 UA_Session_new(UA_Session *newSession);

+ 38 - 6
src/ua_stack_session_manager.h

@@ -8,8 +8,8 @@
 #ifndef UA_STACK_SESSION_MANAGER_H_
 #define UA_STACK_SESSION_MANAGER_H_
 
-#include "include/opcua.h"
-#include "include/ua_list.h"
+#include "../include/opcua.h"
+#include "../include/ua_list.h"
 #include "ua_stack_session.h"
 
 
@@ -17,20 +17,52 @@
 //hide internal data of channelManager
 typedef struct UA_SessionManagerType *UA_SessionManager;
 
+/**
+ * @brief initializes the session manager
+ * @param maxSessionCount maximum amount of sessions which should be allowed to be created
+ * @param sessionLifetime lifetime of a session, after this time the session must be renewed
+ * @param startSessionId the start id of the session identifiers, newer sessions get higher ids
+ * @return error code if all goes well UA_SUCCESS is returned
+ */
+UA_Int32 UA_SessionManager_init(UA_UInt32 maxSessionCount,UA_UInt32 sessionLifetime,
+		UA_UInt32 startSessionId);
 
-UA_Int32 UA_SessionManager_init(UA_UInt32 maxSessionCount,UA_UInt32 sessionLifetime, UA_UInt32 startSessionId);
+/**
+ * @brief adds a session to the manager list
+ * @param session session object which should be added to the manager list
+ * @return error code if all goes well UA_SUCCESS is returned
+ */
 UA_Int32 UA_SessionManager_addSession(UA_Session *session);
+
+/**
+ * @brief removes a session from the manager list
+ * @param sessionId removes a session by its id
+ * @return error code if all goes well UA_SUCCESS is returned
+ */
 UA_Int32 UA_SessionManager_removeSession(UA_Int32 sessionId);
 
+/**
+ * @brief finds the session which is identified by the sessionId
+ * @param sessionId the session id is used to identify the unknown session
+ * @param session the session object is returned if no error occurs
+ * @return error code if all goes well UA_SUCCESS is returned
+ */
 UA_Int32 UA_SessionManager_getSessionById(UA_NodeId sessionId, UA_Session *session);
-UA_Int32 UA_SessionManager_getSessionByToken(UA_NodeId sessionId, UA_Session *session);
+
+/**
+ * @brief
+ * @param token authentication token which is used to get the session object
+ * @param session output, session object which is identified by the authentication token
+ * @return error code if all goes well UA_SUCCESS is returned
+ */
+UA_Int32 UA_SessionManager_getSessionByToken(UA_NodeId *token, UA_Session *session);
 
 UA_Int32 UA_SessionManager_updateSessions();
 
 UA_Int32 UA_SessionManager_getSessionLifeTime(UA_DateTime *lifeTime);
 
-UA_Int32 UA_SessionManager_generateToken(SL_secureChannel channel, UA_Int32 requestedLifeTime, SecurityTokenRequestType requestType, UA_ChannelSecurityToken* newToken);
+//UA_Int32 UA_SessionManager_generateToken(UA_Session session, UA_Int32 requestedLifeTime, SecurityTokenRequestType requestType, UA_ChannelSecurityToken* newToken);
 
-UA_Int32 UA_SessionManager_generateSessionId(UA_UInt32 *newChannelId);
+UA_Int32 UA_SessionManager_generateSessionId(UA_NodeId *newSessionId);
 
 #endif /* UA_STACK_SESSION_MANAGER_H_ */

+ 3 - 0
src/ua_transport_binary_secure.c

@@ -6,6 +6,8 @@
 #include "ua_transport.h"
 #include "ua_statuscodes.h"
 #include "ua_services.h"
+#include "ua_stack_session_manager.h"
+#include "ua_stack_session.h"
 
 #define SIZE_SECURECHANNEL_HEADER 12
 #define SIZE_SEQHEADER_HEADER 8
@@ -135,6 +137,7 @@ static void init_response_header(UA_RequestHeader const * p,
 #define INVOKE_SERVICE(TYPE) \
 	UA_##TYPE##Request p; \
 	UA_##TYPE##Response r; \
+	UA_NodeId authenticationToken; \
 	UA_##TYPE##Request_decodeBinary(msg, pos, &p); \
 	UA_##TYPE##Response_init(&r); \
 	init_response_header(&p.requestHeader, &r.responseHeader); \