Ver código fonte

Merge remote-tracking branch 'origin/master' into connection_secureChannel

Conflicts:
	src/Makefile.am
FlorianPalm 10 anos atrás
pai
commit
0d565705d3

+ 11 - 12
src/Makefile.am

@@ -1,4 +1,3 @@
-#optimization levels depending on debug
 AM_CFLAGS = $(GLOBAL_AM_CFLAGS) -I$(top_builddir)/include -I$(top_builddir)/src -I. -I$(top_builddir)/src/util
 TOOL_DIR = ../tools
 lib_LTLIBRARIES = libopen62541.la
@@ -28,20 +27,20 @@ libopen62541_la_SOURCES = opcua.c \
 .PHONY: convenience-link clean-convenience-link
 
 convenience-link: $(lib_LTLIBRARIES)
-	@test -e $(top_builddir)/lib || mkdir $(top_builddir)/lib
-	@for soname in `echo | $(EGREP) "^dlname=" $^ | $(SED) -e "s|^dlname='\(.*\)'|\1|"`; do \
+	@test -e "$(top_builddir)/lib" || mkdir "$(top_builddir)/lib"
+	@for soname in `echo | $(EGREP) "^dlname=" $^ | $(SED) -e "s|^dlname='\(.*\)'|\1|"`; do  \
 		echo "$$soname: creating convenience link from $(abs_builddir)/.libs to $(top_builddir)/lib"; \
 		rm -f $(top_builddir)/lib/$$soname ; \
-		test -e $(abs_builddir)/.libs/$$soname && \
-		cd $(top_builddir)/lib && \
-		$(LN_S) $(abs_builddir)/.libs/$$soname $$soname || true;\
-		done
-	@for aname in `echo | $(EGREP) "^dlname=" $^ | $(SED) -e "s|^dlname='\(.*\)\.\(.*\)'|\1\.a|"`; do \
+		test -e "$(abs_builddir)/.libs/$$soname" && \
+		cd "$(top_builddir)/lib" && \
+		$(LN_S) "$(abs_builddir)/.libs/$$soname" "$$soname" || true;\
+	done
+	@for aname in `echo | $(EGREP) "^dlname=" $^ | $(SED) -e "s|^dlname='\(.*\)\.\(.*\)'|\1\.a|"`; do  \
 		echo "$$aname: creating convenience link from $(abs_builddir)/.libs to $(top_builddir)/lib"; \
-		rm -f $(top_builddir)/lib/$$aname ; \
-		test -e $(abs_builddir)/.libs/$$aname && \
-		cd $(top_builddir)/lib && \
-		$(LN_S) $(abs_builddir)/.libs/$$aname $$aname || true;\
+		rm -f "$(top_builddir)/lib/$$aname" ; \
+		test -e "$(abs_builddir)/.libs/$$aname" && \
+		cd "$(top_builddir)/lib" && \
+		$(LN_S) "$(abs_builddir)/.libs/$$aname" "$$aname" || true;\
 	done
 
 clean-convenience-link:

+ 40 - 0
src/ua_stack_session.c

@@ -13,6 +13,8 @@ typedef struct UA_SessionType
 	UA_NodeId sessionId;
 	void *applicationPayload;
 	Application *application;
+	UA_list_List pendingRequests;
+	SL_secureChannel channel;
 }UA_SessionType;
 
 
@@ -24,3 +26,41 @@ UA_Boolean UA_Session_compare(UA_Session session1, UA_Session session2)
 	}
 	return UA_FALSE;
 }
+
+UA_Boolean UA_Session_compareByToken(UA_Session session, UA_NodeId *token)
+{
+	if(session && token)
+	{
+		return UA_NodeId_compare(&((UA_SessionType*)session)->authenticationToken, token);
+	}
+	return UA_FALSE;
+}
+
+UA_Boolean UA_Session_compareById(UA_Session session, UA_NodeId *sessionId)
+{
+	if(session && sessionId)
+	{
+		return UA_NodeId_compare(&((UA_SessionType*)session)->sessionId, sessionId);
+	}
+	return UA_FALSE;
+}
+
+UA_Int32 UA_Session_getId(UA_Session session, UA_NodeId *sessionId)
+{
+	if(session)
+	{
+		return UA_NodeId_copy(&((UA_SessionType*)session)->sessionId, sessionId);
+	}
+	return UA_ERROR;
+}
+
+UA_Int32 UA_Session_getChannel(UA_Session session, SL_secureChannel *channel)
+{
+	if(session)
+	{
+		*channel = ((UA_SessionType*)session)->channel;
+		return UA_SUCCESS;
+	}
+	return UA_ERROR;
+
+}

+ 3 - 2
src/ua_stack_session.h

@@ -9,7 +9,7 @@
 #define UA_STACK_SESSION_H_
 
 #include "include/opcua.h"
-
+#include "ua_stack_channel.h"
 
 #endif /* UA_STACK_SESSION_H_ */
 
@@ -19,4 +19,5 @@ typedef 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);

+ 64 - 4
src/ua_stack_session_manager.c

@@ -31,14 +31,73 @@ UA_Int32 UA_SessionManager_init(UA_UInt32 maxSessionCount,UA_UInt32 sessionLifet
 	sessionManager->sessionLifetime = sessionLifetime;
 	return retval;
 }
-UA_Int32 UA_SessionManager_addSession(UA_Session *session)
+
+UA_Boolean UA_SessionManager_sessionExists(UA_Session *session)
 {
+	if(UA_list_search(sessionManager->sessions,(UA_list_PayloadComparer)UA_Session_compare,(void*)session))
+	{
+		return UA_TRUE;
+	}
+	return UA_FALSE;
+}
 
+UA_Int32 UA_SessionManager_getSessionById(UA_NodeId *sessionId, UA_Session *session)
+{
+	UA_UInt32 tmpSessionId;
+ 	UA_list_Element* current = sessionManager->sessions.first;
+	while (current)
+	{
+		if (current->payload)
+		{
+			UA_list_Element* elem = (UA_list_Element*) current;
+			*session = *((UA_Session*) (elem->payload));
+		 	if(UA_Session_compareById(*session,sessionId))
+		 	{
+		 		return UA_SUCCESS;
+		 	}
+		}
+	}
+	*session = UA_NULL;
+	return UA_ERROR;
+}
 
-	if(UA_SessionManager_getSession())
-	UA_list_addElementToBack(sessionManager->sessions,session);
+UA_Int32 UA_SessionManager_getSessionByToken(UA_NodeId *token, UA_Session *session)
+{
+	UA_UInt32 tmpSessionId;
+ 	UA_list_Element* current = sessionManager->sessions.first;
+	while (current)
+	{
+		if (current->payload)
+		{
+			UA_list_Element* elem = (UA_list_Element*) current;
+			*session = *((UA_Session*) (elem->payload));
+		 	if(UA_Session_compareByToken(*session,token))
+		 	{
+		 		return UA_SUCCESS;
+		 	}
+		}
+	}
+	*session = UA_NULL;
+	return UA_ERROR;
 }
-UA_Int32 UA_SessionManager_removeSession(UA_Int32 channelId);
+
+UA_Int32 UA_SessionManager_addSession(UA_Session *session)
+{
+	UA_Int32 retval = UA_SUCCESS;
+	if(!UA_SessionManager_sessionExists(session))
+	{
+		retval |= UA_list_addElementToBack(sessionManager->sessions,session);
+		return retval;
+	}
+	else
+	{
+		printf("UA_SessionManager_addSession - session already in list");
+		return UA_ERROR;
+	}
+}
+
+
+/*UA_Int32 UA_SessionManager_removeSession(UA_Int32 channelId);
 
 UA_Int32 UA_SessionManager_getSession(UA_UInt32 sessionId, UA_Session *session);
 
@@ -49,3 +108,4 @@ UA_Int32 UA_SessionManager_getSessionLifeTime(UA_DateTime *lifeTime);
 UA_Int32 SL_UA_SessionManager_generateToken(SL_secureChannel channel, UA_Int32 requestedLifeTime, SecurityTokenRequestType requestType, UA_ChannelSecurityToken* newToken);
 
 UA_Int32 SL_UA_SessionManager_generateSessionId(UA_UInt32 *newChannelId);
+*/

+ 6 - 4
src/ua_stack_session_manager.h

@@ -18,11 +18,13 @@
 typedef struct UA_SessionManagerType *UA_SessionManager;
 
 
-UA_Int32 UA_SessionManager_init(UA_UInt32 maxSessionCount,UA_UInt32 tokenLifetime, UA_UInt32 startChannelId, UA_UInt32 startTokenId, UA_String *endpointUrl);
-UA_Int32 UA_SessionManager_addSession(SL_secureChannel *channel);
-UA_Int32 UA_SessionManager_removeSession(UA_Int32 channelId);
+UA_Int32 UA_SessionManager_init(UA_UInt32 maxSessionCount,UA_UInt32 sessionLifetime, UA_UInt32 startSessionId);
+UA_Int32 UA_SessionManager_addSession(UA_Session *session);
+UA_Int32 UA_SessionManager_removeSession(UA_Int32 sessionId);
+
+UA_Int32 UA_SessionManager_getSessionById(UA_NodeId sessionId, UA_Session *session);
+UA_Int32 UA_SessionManager_getSessionByToken(UA_NodeId sessionId, UA_Session *session);
 
-UA_Int32 UA_SessionManager_getSession(UA_UInt32 sessionId, UA_Session *session);
 UA_Int32 UA_SessionManager_updateSessions();
 
 UA_Int32 UA_SessionManager_getSessionLifeTime(UA_DateTime *lifeTime);