Browse Source

fixed segfaults (session deletion, channel deletion)

FlorianPalm 10 years ago
parent
commit
e132b9e781

+ 2 - 2
examples/src/networklayer.c

@@ -240,7 +240,7 @@ UA_Int32 NL_TCP_writer(UA_Int32 connectionHandle, UA_ByteString const * const *
 	return UA_SUCCESS;
 }
 //callback function which is called when the UA_TL_Connection_close() function is initiated
-UA_Int32 NL_Connection_close(UA_TL_Connection1 connection)
+UA_Int32 NL_Connection_close(UA_TL_Connection connection)
 {
 	NL_Connection *networkLayerData = UA_NULL;
 	UA_TL_Connection_getNetworkLayerData(connection, (void**)&networkLayerData);
@@ -259,7 +259,7 @@ void* NL_Connection_init(NL_Connection* c, NL_data* tld, UA_Int32 connectionHand
 {
 
 
-	UA_TL_Connection1 connection = UA_NULL;
+	UA_TL_Connection connection = UA_NULL;
 	//create new connection object
 	UA_TL_Connection_new(&connection, tld->tld->localConf, writer, NL_Connection_close,c);
 	//add connection object to list, so stack is aware of its connections

+ 2 - 2
examples/src/networklayer.h

@@ -45,7 +45,7 @@ typedef struct NL_data {
 struct NL_Connection;
 typedef void* (*NL_Reader)(struct NL_Connection *c);
 typedef struct NL_Connection {
-	UA_TL_Connection1 connection;
+	UA_TL_Connection connection;
 	UA_Int32 state;
 	UA_UInt32 connectionHandle;
 	NL_Reader reader;
@@ -56,7 +56,7 @@ typedef struct NL_Connection {
 } NL_Connection;
 
 NL_data* NL_init(NL_Description* tlDesc, UA_Int32 port);
-UA_Int32 NL_Connection_close(UA_TL_Connection1 connection);
+UA_Int32 NL_Connection_close(UA_TL_Connection connection);
 UA_Int32 NL_msgLoop(NL_data* nl, struct timeval* tv,UA_Int32 (*timeoutCallBack)(void*),void *arg);
 UA_Int32 NL_TCP_writer(UA_Int32 connectionHandle, UA_ByteString const * const * gather_buf, UA_UInt32 gather_len);
 

+ 2 - 2
examples/src/opcuaServer.c

@@ -40,8 +40,8 @@ int main(int argc, char** argv) {
 	struct timeval tv = {1, 0}; // 1 second
 
 	SL_ChannelManager_init(2,3600000, 873, 23, &nl->endpointUrl);
-	UA_SessionManager_init(2,300000,5);
-
+	UA_SessionManager_init(2,30000,5);
+	//UA_TL_ConnectionManager_init(10);
   	NL_msgLoop(nl, &tv, serverCallback, argv[0]);
 
 }

+ 2 - 2
examples/src/opcuaServerACPLT.c

@@ -45,7 +45,7 @@ void server_run() {
 #ifdef DEBUG
 	tmpTestFunction();
 #endif
-	UA_TL_Connection1 connection;// = UA_NULL;
+	UA_TL_Connection connection;// = UA_NULL;
 	TL_Buffer localBuffers;
 	UA_Int32 connectionState;
 	//connection.connectionState = CONNECTIONSTATE_CLOSED;
@@ -98,7 +98,7 @@ void server_run() {
 	/* Now start listening for the clients, here process will
 	 * go in sleep mode and will wait for the incoming connection
 	 */
-	UA_TL_Connection1 tmpConnection;
+	UA_TL_Connection tmpConnection;
 
 	while (listen(sockfd, 5) != -1) {
 		clilen = sizeof(cli_addr);

+ 5 - 5
src/ua_services.h

@@ -34,7 +34,7 @@
  * the configuration information required to establish a SecureChannel and a
  * Session.
  */
-UA_Int32 Service_GetEndpoints(SL_secureChannel channel, const UA_GetEndpointsRequest* request, UA_GetEndpointsResponse *response);
+UA_Int32 Service_GetEndpoints(SL_Channel channel, const UA_GetEndpointsRequest* request, UA_GetEndpointsResponse *response);
 // Service_RegisterServer
 /** @} */
 
@@ -53,12 +53,12 @@ UA_Int32 Service_GetEndpoints(SL_secureChannel channel, const UA_GetEndpointsReq
  * to ensure Confidentiality and Integrity for Message exchange during a
  * Session.
  */
-UA_Int32 Service_OpenSecureChannel(SL_secureChannel channel, const UA_OpenSecureChannelRequest* request, UA_OpenSecureChannelResponse* response);
+UA_Int32 Service_OpenSecureChannel(SL_Channel channel, const UA_OpenSecureChannelRequest* request, UA_OpenSecureChannelResponse* response);
 
 /**
  * @brief This Service is used to terminate a SecureChannel.
  */
-UA_Int32 Service_CloseSecureChannel(SL_secureChannel channel, const UA_CloseSecureChannelRequest *request, UA_CloseSecureChannelResponse *response);
+UA_Int32 Service_CloseSecureChannel(SL_Channel channel, const UA_CloseSecureChannelRequest *request, UA_CloseSecureChannelResponse *response);
 /** @} */
 
 /**
@@ -77,7 +77,7 @@ UA_Int32 Service_CloseSecureChannel(SL_secureChannel channel, const UA_CloseSecu
  * logs and in the Server’s address space. The second is the authenticationToken
  * which is used to associate an incoming request with a Session.
  */
-UA_Int32 Service_CreateSession(SL_secureChannel channel, const UA_CreateSessionRequest *request, UA_CreateSessionResponse *response);
+UA_Int32 Service_CreateSession(SL_Channel channel, const UA_CreateSessionRequest *request, UA_CreateSessionResponse *response);
 
 /**
  * @brief This Service is used by the Client to submit its SoftwareCertificates
@@ -86,7 +86,7 @@ UA_Int32 Service_CreateSession(SL_secureChannel channel, const UA_CreateSessionR
  * Client before it issues any other Service request after CreateSession.
  * Failure to do so shall cause the Server to close the Session.
  */
-UA_Int32 Service_ActivateSession(SL_secureChannel channel, UA_Session session, const UA_ActivateSessionRequest *request, UA_ActivateSessionResponse *response);
+UA_Int32 Service_ActivateSession(SL_Channel channel, UA_Session session, const UA_ActivateSessionRequest *request, UA_ActivateSessionResponse *response);
 
 /**
  * @brief This Service is used to terminate a Session.

+ 1 - 1
src/ua_services_discovery.c

@@ -1,5 +1,5 @@
 #include "ua_services.h"
-UA_Int32 Service_GetEndpoints(SL_secureChannel channel, const UA_GetEndpointsRequest* request, UA_GetEndpointsResponse *response) {
+UA_Int32 Service_GetEndpoints(SL_Channel channel, const UA_GetEndpointsRequest* request, UA_GetEndpointsResponse *response) {
 #ifdef DEBUG
 	UA_String_printx("endpointUrl=", &request->endpointUrl);
 #endif

+ 6 - 4
src/ua_services_securechannel.c

@@ -1,7 +1,7 @@
 #include "ua_services.h"
 #include "ua_transport_binary_secure.h"
 
-UA_Int32 Service_OpenSecureChannel(SL_secureChannel channel,
+UA_Int32 Service_OpenSecureChannel(SL_Channel channel,
 const UA_OpenSecureChannelRequest* request,
 UA_OpenSecureChannelResponse* response)
 {
@@ -16,11 +16,13 @@ UA_OpenSecureChannelResponse* response)
 	return retval;
 }
 
-UA_Int32 Service_CloseSecureChannel(SL_secureChannel channel, const UA_CloseSecureChannelRequest *request,
+UA_Int32 Service_CloseSecureChannel(SL_Channel channel, const UA_CloseSecureChannelRequest *request,
 UA_CloseSecureChannelResponse *response)
 {
-UA_Int32 retval = UA_SUCCESS;
-
+	UA_Int32 retval = UA_SUCCESS;
+	UA_UInt32 channelId;
+	SL_Channel_getChannelId(channel,&channelId);
+	SL_ChannelManager_removeChannel(channelId);
 // 62451 Part 6 Chapter 7.1.4 - The server does not send a CloseSecureChannel response
 
 return retval;

+ 13 - 11
src/ua_services_session.c

@@ -2,33 +2,32 @@
 #include "ua_stack_session_manager.h"
 #include "ua_application.h"
 
-//Session sessionMockup = {
-//		(UA_Int32) 0,
-//		&appMockup
-//};
 
-UA_Int32 Service_CreateSession(SL_secureChannel channel, const UA_CreateSessionRequest *request, UA_CreateSessionResponse *response) {
+UA_Int32 Service_CreateSession(SL_Channel channel, const UA_CreateSessionRequest *request, UA_CreateSessionResponse *response) {
 UA_String_printf("CreateSession Service - endpointUrl=", &(request->endpointUrl));
 
 	UA_Session *newSession;
+	UA_Int64 timeout;
 
+	UA_SessionManager_getSessionTimeout(&timeout);
 	UA_Session_new(&newSession);
 	//TODO get maxResponseMessageSize
 	UA_Session_init(*newSession, (UA_String*)&request->sessionName,
 	request->requestedSessionTimeout,
 	request->maxResponseMessageSize,
 	9999,
-	(UA_Session_idProvider)UA_SessionManager_generateSessionId);
+	(UA_Session_idProvider)UA_SessionManager_generateSessionId,
+	timeout);
 
 	UA_SessionManager_addSession(newSession);
 	UA_Session_getId(*newSession, &response->sessionId);
 	UA_Session_getToken(*newSession, &(response->authenticationToken));
-
-
+	response->revisedSessionTimeout = timeout;
+	//TODO fill results
 	return UA_SUCCESS;
 }
 
-UA_Int32 Service_ActivateSession(SL_secureChannel channel,UA_Session session,
+UA_Int32 Service_ActivateSession(SL_Channel channel,UA_Session session,
 		const UA_ActivateSessionRequest *request, UA_ActivateSessionResponse *response)
 {
 
@@ -40,12 +39,15 @@ UA_Int32 Service_ActivateSession(SL_secureChannel channel,UA_Session session,
 	// 321 == AnonymousIdentityToken_Encoding_DefaultBinary
 	UA_NodeId_printf("ActivateSession - uIdToken.type=", &(request->userIdentityToken.typeId));
 	UA_ByteString_printx_hex("ActivateSession - uIdToken.body=", &(request->userIdentityToken.body));
-
+	//TODO fill results
 	return UA_SUCCESS;
 }
 
 UA_Int32 Service_CloseSession(UA_Session session, const UA_CloseSessionRequest *request, UA_CloseSessionResponse *response) {
-//FIXME channel->session = UA_NULL;
+	UA_NodeId sessionId;
+	UA_Session_getId(session,&sessionId);
+
+	UA_SessionManager_removeSession(&sessionId);
 // FIXME: set response
 return UA_SUCCESS;
 }

+ 83 - 80
src/ua_stack_channel.c

@@ -9,12 +9,12 @@
 #include <time.h>
 #include <stdlib.h>
 
-typedef struct SL_Channel1 {
+typedef struct SL_ChannelStruct {
 	SL_channelState state;
 	UA_UInt32 channelId;
 	//TL_Connection* tlConnection;
 
-	UA_TL_Connection1 connection;
+	UA_TL_Connection connection;
 	UA_UInt32 requestId;
 	//UA_UInt32 lastRequestId;
 
@@ -32,20 +32,20 @@ typedef struct SL_Channel1 {
 	UA_ByteString localNonce;
 	SL_ChannelSecurityTokenProvider tokenProvider;
 	SL_ChannelIdProvider channelIdProvider;
-}SL_Channel1;
+}SL_ChannelType;
 
 
-UA_Int32 SL_Channel_registerTokenProvider(SL_secureChannel channel, SL_ChannelSecurityTokenProvider provider)
+UA_Int32 SL_Channel_registerTokenProvider(SL_Channel channel, SL_ChannelSecurityTokenProvider provider)
 {
-	((SL_Channel1*)channel)->tokenProvider = provider;
+	((SL_ChannelType*)channel)->tokenProvider = provider;
 	return UA_SUCCESS;
 }
 
-UA_Int32 SL_Channel_getRemainingLifetime(SL_secureChannel channel, UA_Int32 *lifetime)
+UA_Int32 SL_Channel_getRemainingLifetime(SL_Channel channel, UA_Int32 *lifetime)
 {
 	if(channel)
 	{
-		UA_Int64 diffInMS = (((SL_Channel1*)channel)->securityToken.createdAt - UA_DateTime_now()) / 1e7;
+		UA_Int64 diffInMS = (((SL_ChannelType*)channel)->securityToken.createdAt - UA_DateTime_now()) / 1e7;
 		if(diffInMS > UA_INT32_MAX)
 		{
 			*lifetime = UA_INT32_MAX;
@@ -62,103 +62,103 @@ UA_Int32 SL_Channel_getRemainingLifetime(SL_secureChannel channel, UA_Int32 *lif
 	}
 }
 
-UA_Int32 SL_Channel_getChannelId(SL_secureChannel channel, UA_UInt32 *channelId)
+UA_Int32 SL_Channel_getChannelId(SL_Channel channel, UA_UInt32 *channelId)
 {
 	if(channel)
 	{
-		*channelId = ((SL_Channel1*)channel)->channelId;
+		*channelId = ((SL_ChannelType*)channel)->channelId;
 		return UA_SUCCESS;
 	}
 	return UA_ERROR;
 }
 
-UA_Int32 SL_Channel_getTokenId(SL_secureChannel channel, UA_UInt32 *tokenId)
+UA_Int32 SL_Channel_getTokenId(SL_Channel channel, UA_UInt32 *tokenId)
 {
 	if(channel)
 	{
-		*tokenId = ((SL_Channel1*)channel)->securityToken.tokenId;
+		*tokenId = ((SL_ChannelType*)channel)->securityToken.tokenId;
 		return UA_SUCCESS;
 	}
 	return UA_ERROR;
 }
 
-UA_Int32 SL_Channel_getLocalAsymAlgSettings(SL_secureChannel channel, UA_AsymmetricAlgorithmSecurityHeader **asymAlgSettings)
+UA_Int32 SL_Channel_getLocalAsymAlgSettings(SL_Channel channel, UA_AsymmetricAlgorithmSecurityHeader **asymAlgSettings)
 {
 	UA_Int32 retval = 0;
 
 	retval |= UA_alloc((void**)asymAlgSettings,UA_AsymmetricAlgorithmSecurityHeader_calcSizeBinary(UA_NULL));
 
-	retval |= UA_ByteString_copy(&(channel->localAsymAlgSettings.receiverCertificateThumbprint),
+	retval |= UA_ByteString_copy(&(((SL_ChannelType*)channel)->localAsymAlgSettings.receiverCertificateThumbprint),
 			&(*asymAlgSettings)->receiverCertificateThumbprint);
-	retval |= UA_ByteString_copy(&(channel->localAsymAlgSettings.securityPolicyUri),
+	retval |= UA_ByteString_copy(&(((SL_ChannelType*)channel)->localAsymAlgSettings.securityPolicyUri),
 				&(*asymAlgSettings)->securityPolicyUri);
-	retval |= UA_ByteString_copy(&(channel->localAsymAlgSettings.senderCertificate),
+	retval |= UA_ByteString_copy(&(((SL_ChannelType*)channel)->localAsymAlgSettings.senderCertificate),
 					&(*asymAlgSettings)->senderCertificate);
 
 	return UA_SUCCESS;
 }
-UA_Int32 SL_Channel_getConnection(SL_secureChannel channel, UA_TL_Connection1 *connection)
+UA_Int32 SL_Channel_getConnection(SL_Channel channel, UA_TL_Connection *connection)
 {
 	if(channel)
 	{
-		*connection = ((SL_Channel1*)channel)->connection;
+		*connection = ((SL_ChannelType*)channel)->connection;
 		return UA_SUCCESS;
 	}
 	return UA_ERROR;
 }
-UA_Int32 SL_Channel_getRequestId(SL_secureChannel channel, UA_UInt32 *requestId)
+UA_Int32 SL_Channel_getRequestId(SL_Channel channel, UA_UInt32 *requestId)
 {
 	if(channel)
 	{
-		*requestId = ((SL_Channel1*)channel)->requestId;
+		*requestId = ((SL_ChannelType*)channel)->requestId;
 		return UA_SUCCESS;
 	}
 	return UA_ERROR;
 }
-UA_Int32 SL_Channel_getSequenceNumber(SL_secureChannel channel, UA_UInt32 *sequenceNumber)
+UA_Int32 SL_Channel_getSequenceNumber(SL_Channel channel, UA_UInt32 *sequenceNumber)
 {
 	if(channel)
 	{
-		*sequenceNumber = ((SL_Channel1*)channel)->sequenceNumber;
+		*sequenceNumber = ((SL_ChannelType*)channel)->sequenceNumber;
 		return UA_SUCCESS;
 	}
 	return UA_ERROR;
 }
-UA_Int32 SL_Channel_getState(SL_secureChannel channel,SL_channelState *channelState)
+UA_Int32 SL_Channel_getState(SL_Channel channel,SL_channelState *channelState)
 {
 	if(channel)
 	{
-		*channelState = ((SL_Channel1*)channel)->state;
+		*channelState = ((SL_ChannelType*)channel)->state;
 		return UA_SUCCESS;
 	}
 	return UA_ERROR;
 }
 
-UA_Int32 SL_Channel_getRevisedLifetime(SL_secureChannel channel, UA_UInt32 *revisedLifetime)
+UA_Int32 SL_Channel_getRevisedLifetime(SL_Channel channel, UA_UInt32 *revisedLifetime)
 {
 	if(channel)
 	{
-		*revisedLifetime = ((SL_Channel1*)channel)->securityToken.revisedLifetime;
+		*revisedLifetime = ((SL_ChannelType*)channel)->securityToken.revisedLifetime;
 		return UA_SUCCESS;
 	}
 	return UA_ERROR;
 }
 
 //setters
-UA_Int32 SL_Channel_setId(SL_secureChannel channel, UA_UInt32 id)
+UA_Int32 SL_Channel_setId(SL_Channel channel, UA_UInt32 id)
 {
-	((SL_Channel1*)channel)->channelId = id;
+	((SL_ChannelType*)channel)->channelId = id;
 	return UA_SUCCESS;
 }
 
 //private function
-UA_Int32 SL_Channel_setState(SL_secureChannel channel,SL_channelState channelState)
+UA_Int32 SL_Channel_setState(SL_Channel channel,SL_channelState channelState)
 {
-	((SL_Channel1*)channel)->state = channelState;
+	((SL_ChannelType*)channel)->state = channelState;
 	return UA_SUCCESS;
 }
 
-UA_Int32 SL_Channel_init(SL_secureChannel channel,
+UA_Int32 SL_Channel_init(SL_Channel channel,
 		UA_ByteString *receiverCertificateThumbprint,
 		UA_ByteString *securityPolicyUri,
 		UA_ByteString *senderCertificate,
@@ -166,17 +166,17 @@ UA_Int32 SL_Channel_init(SL_secureChannel channel,
 {
 	UA_Int32 retval = UA_SUCCESS;
 	retval |= UA_ByteString_copy(receiverCertificateThumbprint,
-			&((SL_Channel1*)channel)->localAsymAlgSettings.receiverCertificateThumbprint);
+			&((SL_ChannelType*)channel)->localAsymAlgSettings.receiverCertificateThumbprint);
 
 	retval |= UA_ByteString_copy(securityPolicyUri,
-			&((SL_Channel1*)channel)->localAsymAlgSettings.securityPolicyUri);
+			&((SL_ChannelType*)channel)->localAsymAlgSettings.securityPolicyUri);
 
 	retval |= UA_ByteString_copy(senderCertificate,
-			&((SL_Channel1*)channel)->localAsymAlgSettings.senderCertificate);
+			&((SL_ChannelType*)channel)->localAsymAlgSettings.senderCertificate);
 
 
 
-	((SL_Channel1*)channel)->state = UA_SL_CHANNEL_CLOSED;
+	((SL_ChannelType*)channel)->state = UA_SL_CHANNEL_CLOSED;
 	return retval;
 }
 //TODO implement real nonce generator - DUMMY function
@@ -189,13 +189,13 @@ UA_Int32 SL_Channel_generateNonce(UA_ByteString *nonce)
 	return UA_SUCCESS;
 }
 
-UA_Boolean SL_Channel_compare(SL_secureChannel channel1, SL_secureChannel channel2)
+UA_Boolean SL_Channel_compare(SL_Channel channel1, SL_Channel channel2)
 {
-	return (((SL_Channel1*)channel1)->channelId == ((SL_Channel1*)channel2)->channelId)
+	return (((SL_ChannelType*)channel1)->channelId == ((SL_ChannelType*)channel2)->channelId)
 			? UA_EQUAL : UA_NOT_EQUAL;
 }
 
-UA_Int32 SL_Channel_new(SL_secureChannel **channel,
+UA_Int32 SL_Channel_new(SL_Channel **channel,
 		SL_ChannelIdProvider channelIdProvider,
 		SL_ChannelSecurityTokenProvider tokenProvider,
 		UA_ByteString *receiverCertificateThumbprint,
@@ -206,10 +206,10 @@ UA_Int32 SL_Channel_new(SL_secureChannel **channel,
 {
 	UA_Int32 retval = UA_SUCCESS;
 
-	retval |= UA_alloc((void**)channel,sizeof(SL_secureChannel));
+	retval |= UA_alloc((void**)channel,sizeof(SL_Channel));
 
-	SL_Channel1 *thisChannel = UA_NULL;
-	retval |= UA_alloc((void**)&thisChannel,sizeof(SL_Channel1));
+	SL_ChannelType *thisChannel = UA_NULL;
+	retval |= UA_alloc((void**)&thisChannel,sizeof(SL_ChannelType));
 
 	thisChannel->channelIdProvider = channelIdProvider;
 	thisChannel->tokenProvider = tokenProvider;
@@ -225,12 +225,12 @@ UA_Int32 SL_Channel_new(SL_secureChannel **channel,
 
 	thisChannel->state = UA_SL_CHANNEL_CLOSED;
 
-	**channel = (SL_secureChannel)thisChannel;
+	**channel = (SL_Channel)thisChannel;
 
 	return UA_SUCCESS;
 }
-UA_Int32 SL_Channel_initByRequest(SL_secureChannel channel,
-		UA_TL_Connection1 connection,
+UA_Int32 SL_Channel_initByRequest(SL_Channel channel,
+		UA_TL_Connection connection,
 		const UA_ByteString* msg,
 		UA_UInt32* pos)
 {
@@ -241,9 +241,9 @@ UA_Int32 SL_Channel_initByRequest(SL_secureChannel channel,
 	UA_SequenceHeader_init(sequenceHeader);
 
 
-	((SL_Channel1*)channel)->channelIdProvider(&((SL_Channel1*)channel)->channelId);
+	((SL_ChannelType*)channel)->channelIdProvider(&((SL_ChannelType*)channel)->channelId);
 
-	((SL_Channel1*)channel)->connection = connection;
+	((SL_ChannelType*)channel)->connection = connection;
 
 	SL_Channel_generateNonce(&channel->localNonce);
 
@@ -267,73 +267,78 @@ UA_Int32 SL_Channel_initByRequest(SL_secureChannel channel,
 
 	return UA_SUCCESS;
 }
-
-UA_Int32 SL_Channel_delete(SL_secureChannel channel)
+UA_Int32 SL_Channel_deleteMembers(SL_Channel channel)
 {
-	//TODO implement me
-	//((SL_Channel1*)channel)->
-	return UA_SUCCESS;
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_AsymmetricAlgorithmSecurityHeader_deleteMembers(&((SL_ChannelType*)channel)->localAsymAlgSettings);
+	retval |= UA_ByteString_deleteMembers(&((SL_ChannelType*)channel)->localNonce);
+	retval |= UA_AsymmetricAlgorithmSecurityHeader_deleteMembers(&((SL_ChannelType*)channel)->remoteAsymAlgSettings);
+	retval |= UA_ByteString_deleteMembers(&((SL_ChannelType*)channel)->remoteNonce);
+	retval |= UA_ChannelSecurityToken_deleteMembers(&((SL_ChannelType*)channel)->securityToken);
+	return retval;
 }
-
-UA_Int32 SL_Channel_deleteMembers(SL_secureChannel channel)
+UA_Int32 SL_Channel_delete(SL_Channel *channel)
 {
-	//TODO implement me!
-	return UA_SUCCESS;
+	UA_Int32 retval = UA_SUCCESS;
+	retval = SL_Channel_deleteMembers(*channel);
+	retval = UA_free(*channel);
+	return retval;
 }
-UA_Int32 SL_Channel_processTokenRequest(SL_secureChannel channel,UA_UInt32 requestedLifetime, UA_SecurityTokenRequestType requestType)
+
+UA_Int32 SL_Channel_processTokenRequest(SL_Channel channel,UA_UInt32 requestedLifetime, UA_SecurityTokenRequestType requestType)
 {
-	if(((SL_Channel1*)channel)->tokenProvider)
+	if(((SL_ChannelType*)channel)->tokenProvider)
 	{
-		return ((SL_Channel1*)channel)->tokenProvider(channel,requestedLifetime,requestType, &((SL_Channel1*)channel)->securityToken);
+		return ((SL_ChannelType*)channel)->tokenProvider(channel,requestedLifetime,requestType, &((SL_ChannelType*)channel)->securityToken);
 	}
 		printf("SL_Channel_processTokenRequest - no Token provider registered");
 		return UA_ERROR;
 }
-UA_Int32 SL_Channel_renewToken(SL_secureChannel channel, UA_UInt32 tokenId,UA_DateTime revisedLifetime, UA_DateTime createdAt)
+UA_Int32 SL_Channel_renewToken(SL_Channel channel, UA_UInt32 tokenId,UA_DateTime revisedLifetime, UA_DateTime createdAt)
 {
-	((SL_Channel1*)channel)->securityToken.tokenId = tokenId;
-	((SL_Channel1*)channel)->securityToken.createdAt = createdAt;
-	((SL_Channel1*)channel)->securityToken.revisedLifetime = revisedLifetime;
+	((SL_ChannelType*)channel)->securityToken.tokenId = tokenId;
+	((SL_ChannelType*)channel)->securityToken.createdAt = createdAt;
+	((SL_ChannelType*)channel)->securityToken.revisedLifetime = revisedLifetime;
 	return UA_SUCCESS;
 }
 
 
-UA_Int32 SL_Channel_checkSequenceNumber(SL_secureChannel channel, UA_UInt32 sequenceNumber)
+UA_Int32 SL_Channel_checkSequenceNumber(SL_Channel channel, UA_UInt32 sequenceNumber)
 {
-	((SL_Channel1*)channel)->sequenceNumber = sequenceNumber; //TODO mock up, to be removed;
+	((SL_ChannelType*)channel)->sequenceNumber = sequenceNumber; //TODO mock up, to be removed;
 	return UA_SUCCESS;
 
-	if(((SL_Channel1*)channel)->sequenceNumber+1 == sequenceNumber){
-		((SL_Channel1*)channel)->sequenceNumber++;
+	if(((SL_ChannelType*)channel)->sequenceNumber+1 == sequenceNumber){
+		((SL_ChannelType*)channel)->sequenceNumber++;
 
 		return UA_SUCCESS;
 	}
 	printf("SL_Channel_checkSequenceNumber - ERROR, wrong SequenceNumber expected: %i, received: %i",
-			((SL_Channel1*)channel)->sequenceNumber+1,sequenceNumber);
+			((SL_ChannelType*)channel)->sequenceNumber+1,sequenceNumber);
 	return UA_ERROR;
 
 }
 
-UA_Int32 SL_Channel_checkRequestId(SL_secureChannel channel, UA_UInt32 requestId)
+UA_Int32 SL_Channel_checkRequestId(SL_Channel channel, UA_UInt32 requestId)
 {
-	((SL_Channel1*)channel)->requestId = requestId; //TODO mock up, to be removed;
+	((SL_ChannelType*)channel)->requestId = requestId; //TODO mock up, to be removed;
 	return UA_SUCCESS;
-	if(((SL_Channel1*)channel)->requestId+1 == requestId){
-		((SL_Channel1*)channel)->requestId++;
+	if(((SL_ChannelType*)channel)->requestId+1 == requestId){
+		((SL_ChannelType*)channel)->requestId++;
 
 		return UA_SUCCESS;
 	}
 	printf("SL_Channel_requestId - ERROR, wrong requestId expected: %i, received: %i",
-			((SL_Channel1*)channel)->requestId+1,requestId);
+			((SL_ChannelType*)channel)->requestId+1,requestId);
 	return UA_ERROR;
 
 }
 
-UA_Int32 SL_Channel_processOpenRequest(SL_secureChannel channel,
+UA_Int32 SL_Channel_processOpenRequest(SL_Channel channel,
 		const UA_OpenSecureChannelRequest* request, UA_OpenSecureChannelResponse* response)
 {
 	UA_UInt32 protocolVersion;
-	SL_Channel1 *thisChannel = (SL_Channel1*)channel;
+	SL_ChannelType *thisChannel = (SL_ChannelType*)channel;
 	UA_Int32 retval = UA_SUCCESS;
 
 	UA_TL_Connection_getProtocolVersion(thisChannel->connection, &protocolVersion);
@@ -357,8 +362,6 @@ UA_Int32 SL_Channel_processOpenRequest(SL_secureChannel channel,
 		}
 		printf(
 				"SL_Channel_processOpenRequest - creating new token for a new SecureChannel\n");
-
-
 		SL_Channel_processTokenRequest(channel,request->requestedLifetime, request->requestType);
 		//	SL_createNewToken(connection);
 		break;
@@ -407,8 +410,8 @@ UA_Int32 SL_Channel_processOpenRequest(SL_secureChannel channel,
 		//TODO check if senderCertificate and ReceiverCertificateThumbprint are present
 		break;
 	}
-
-	thisChannel->state = CONNECTIONSTATE_ESTABLISHED;
+	UA_ByteString_copy(&request->clientNonce,&thisChannel->remoteNonce);
+	thisChannel->state = UA_SL_CHANNEL_OPEN;
 
 	if (request->requestHeader.returnDiagnostics != 0)
 	{
@@ -425,7 +428,7 @@ UA_Int32 SL_Channel_processOpenRequest(SL_secureChannel channel,
 
 	response->serverProtocolVersion = protocolVersion;
 
-	UA_ChannelSecurityToken_copy(&((SL_Channel1*)(channel))->securityToken, &(response->securityToken));
+	UA_ChannelSecurityToken_copy(&((SL_ChannelType*)(channel))->securityToken, &(response->securityToken));
 
 	UA_ByteString_copy(&thisChannel->localNonce, &response->serverNonce);
 
@@ -433,11 +436,11 @@ UA_Int32 SL_Channel_processOpenRequest(SL_secureChannel channel,
 	return retval;
 }
 
-UA_Int32 SL_Channel_processCloseRequest(SL_secureChannel channel,
+UA_Int32 SL_Channel_processCloseRequest(SL_Channel channel,
 		const UA_CloseSecureChannelRequest* request)
 {
 	SL_Channel_setState(channel,UA_SL_CHANNEL_CLOSED);
-	UA_TL_Connection1 connection;
+	UA_TL_Connection connection;
 	SL_Channel_getConnection(channel, &connection);
 	UA_TL_Connection_close(connection);
 	return UA_SUCCESS;

+ 27 - 27
src/ua_stack_channel.h

@@ -20,11 +20,11 @@ typedef enum ChannelState {
 	UA_SL_CHANNEL_OPEN
 }SL_channelState;
 //hide object behind typedef
-typedef struct SL_Channel1 *SL_secureChannel;
-typedef UA_Int32 (*SL_ChannelSecurityTokenProvider)(SL_secureChannel ,UA_Int32 , SecurityTokenRequestType, UA_ChannelSecurityToken*);
+typedef struct SL_ChannelStruct *SL_Channel;
+typedef UA_Int32 (*SL_ChannelSecurityTokenProvider)(SL_Channel ,UA_Int32 , SecurityTokenRequestType, UA_ChannelSecurityToken*);
 typedef UA_Int32 (*SL_ChannelIdProvider)(UA_UInt32*);
 
-UA_Int32 SL_Channel_new(SL_secureChannel **channel,
+UA_Int32 SL_Channel_new(SL_Channel **channel,
 		SL_ChannelIdProvider channelIdProvider,
 		SL_ChannelSecurityTokenProvider tokenProvider,
 		UA_ByteString *receiverCertificateThumbprint,
@@ -32,16 +32,16 @@ UA_Int32 SL_Channel_new(SL_secureChannel **channel,
 		UA_ByteString *senderCertificate,
 		UA_MessageSecurityMode securityMode);
 
-UA_Int32 SL_Channel_init(SL_secureChannel channel,
+UA_Int32 SL_Channel_init(SL_Channel channel,
 		UA_ByteString *receiverCertificateThumbprint,
 		UA_ByteString *securityPolicyUri,
 		UA_ByteString *senderCertificate, UA_MessageSecurityMode securityMode);
 
-UA_Int32 SL_Channel_initByRequest(SL_secureChannel channel, UA_TL_Connection1 connection, const UA_ByteString* msg,
+UA_Int32 SL_Channel_initByRequest(SL_Channel channel, UA_TL_Connection connection, const UA_ByteString* msg,
 		UA_UInt32* pos);
 
-UA_Int32 SL_Channel_initMembers(SL_secureChannel channel,
-		UA_TL_Connection1 *connection,
+UA_Int32 SL_Channel_initMembers(SL_Channel channel,
+		UA_TL_Connection *connection,
 		UA_UInt32 connectionId,
 		UA_UInt32 sequenceNumber,
 		UA_UInt32 requestId,
@@ -52,35 +52,35 @@ UA_Int32 SL_Channel_initMembers(SL_secureChannel channel,
 		UA_ByteString *securityPolicyUri,
 		UA_ByteString *senderCertificate);
 
-UA_Int32 SL_Channel_delete(SL_secureChannel channel);
-UA_Int32 SL_Channel_deleteMembers(SL_secureChannel channel);
-UA_Int32 SL_Channel_renewToken(SL_secureChannel channel, UA_UInt32 tokenId, UA_DateTime revisedLifetime, UA_DateTime createdAt);
-UA_Int32 SL_Channel_processOpenRequest(SL_secureChannel channel,
+UA_Int32 SL_Channel_delete(SL_Channel *channel);
+UA_Int32 SL_Channel_deleteMembers(SL_Channel channel);
+UA_Int32 SL_Channel_renewToken(SL_Channel channel, UA_UInt32 tokenId, UA_DateTime revisedLifetime, UA_DateTime createdAt);
+UA_Int32 SL_Channel_processOpenRequest(SL_Channel channel,
 		const UA_OpenSecureChannelRequest* request, UA_OpenSecureChannelResponse* response);
-UA_Int32 SL_Channel_processCloseRequest(SL_secureChannel channel,
+UA_Int32 SL_Channel_processCloseRequest(SL_Channel channel,
 		const UA_CloseSecureChannelRequest* request);
-UA_Int32 SL_Channel_registerTokenProvider(SL_secureChannel channel,SL_ChannelSecurityTokenProvider provider);
+UA_Int32 SL_Channel_registerTokenProvider(SL_Channel channel,SL_ChannelSecurityTokenProvider provider);
 UA_Int32 SL_Channel_registerChannelIdProvider(SL_ChannelIdProvider provider);
-UA_Int32 SL_Channel_checkRequestId(SL_secureChannel channel, UA_UInt32 requestId);
+UA_Int32 SL_Channel_checkRequestId(SL_Channel channel, UA_UInt32 requestId);
 
-UA_Int32 SL_Channel_checkSequenceNumber(SL_secureChannel channel, UA_UInt32 sequenceNumber);
-UA_Boolean SL_Channel_compare(SL_secureChannel channel1, SL_secureChannel channel2);
+UA_Int32 SL_Channel_checkSequenceNumber(SL_Channel channel, UA_UInt32 sequenceNumber);
+UA_Boolean SL_Channel_compare(SL_Channel channel1, SL_Channel channel2);
 //getters
-UA_Int32 SL_Channel_getChannelId(SL_secureChannel channel, UA_UInt32 *channelId);
-UA_Int32 SL_Channel_getTokenId(SL_secureChannel channel, UA_UInt32 *tokenlId);
-UA_Int32 SL_Channel_getSequenceNumber(SL_secureChannel channel, UA_UInt32 *sequenceNumber);
-UA_Int32 SL_Channel_getRequestId(SL_secureChannel channel, UA_UInt32 *requestId);
-UA_Int32 SL_Channel_getConnectionId(SL_secureChannel channel, UA_UInt32 *connectionId);
-UA_Int32 SL_Channel_getConnection(SL_secureChannel channel, UA_TL_Connection1 *connection);
-UA_Int32 SL_Channel_getState(SL_secureChannel channel, SL_channelState *channelState);
-UA_Int32 SL_Channel_getLocalAsymAlgSettings(SL_secureChannel channel, UA_AsymmetricAlgorithmSecurityHeader **asymAlgSettings);
-UA_Int32 SL_Channel_getRemainingLifetime(SL_secureChannel channel, UA_Int32 *lifetime);
+UA_Int32 SL_Channel_getChannelId(SL_Channel channel, UA_UInt32 *channelId);
+UA_Int32 SL_Channel_getTokenId(SL_Channel channel, UA_UInt32 *tokenlId);
+UA_Int32 SL_Channel_getSequenceNumber(SL_Channel channel, UA_UInt32 *sequenceNumber);
+UA_Int32 SL_Channel_getRequestId(SL_Channel channel, UA_UInt32 *requestId);
+UA_Int32 SL_Channel_getConnectionId(SL_Channel channel, UA_UInt32 *connectionId);
+UA_Int32 SL_Channel_getConnection(SL_Channel channel, UA_TL_Connection *connection);
+UA_Int32 SL_Channel_getState(SL_Channel channel, SL_channelState *channelState);
+UA_Int32 SL_Channel_getLocalAsymAlgSettings(SL_Channel channel, UA_AsymmetricAlgorithmSecurityHeader **asymAlgSettings);
+UA_Int32 SL_Channel_getRemainingLifetime(SL_Channel channel, UA_Int32 *lifetime);
 
-UA_Int32 SL_Channel_getRevisedLifetime(SL_secureChannel channel, UA_UInt32 *revisedLifetime);
+UA_Int32 SL_Channel_getRevisedLifetime(SL_Channel channel, UA_UInt32 *revisedLifetime);
 
 
 //setters
-UA_Int32 SL_Channel_setId(SL_secureChannel channel, UA_UInt32 id);
+UA_Int32 SL_Channel_setId(SL_Channel channel, UA_UInt32 id);
 
 
 

+ 7 - 34
src/ua_stack_channel_manager.c

@@ -20,18 +20,7 @@ typedef struct SL_ChannelManager {
 	UA_UInt32 lastTokenId;
 }SL_ChannelManager;
 static SL_ChannelManager *channelManager;
-/*
-UA_Int32 SL_ChannelManager_newChannelByRequest(UA_Int32 connectionId, const UA_ByteString* msg,
-		UA_Int32* pos, SL_secureChannel *newChannel)
-{
-	UA_UInt32 channelId = 0;
-	SL_Channel_newChannelByRequest(connectionId, msg, pos, newChannel);
 
-	SL_ChannelManager_addChannel(newChannel, &channelId);
-	SL_Channel_setId(newChannel, channelId);
-	return UA_SUCCESS;
-}
-*/
 UA_Int32 SL_ChannelManager_init(UA_UInt32 maxChannelCount,UA_UInt32 tokenLifetime, UA_UInt32 startChannelId, UA_UInt32 startTokenId, UA_String *endpointUrl)
 {
 	UA_alloc((void**)&channelManager,sizeof(SL_ChannelManager));
@@ -45,7 +34,7 @@ UA_Int32 SL_ChannelManager_init(UA_UInt32 maxChannelCount,UA_UInt32 tokenLifetim
 	return UA_SUCCESS;
 }
 
-UA_Int32 SL_ChannelManager_addChannel(SL_secureChannel *channel)
+UA_Int32 SL_ChannelManager_addChannel(SL_Channel *channel)
 {
 	if (channelManager->maxChannelCount > channelManager->currentChannelCount)
 	{
@@ -86,7 +75,7 @@ UA_UInt32 SL_ChannelManager_generateNewTokenId()
 	return channelManager->lastTokenId++;
 }
 
-UA_Int32 SL_ChannelManager_generateToken(SL_secureChannel channel, UA_Int32 requestedLifeTime,
+UA_Int32 SL_ChannelManager_generateToken(SL_Channel channel, UA_Int32 requestedLifeTime,
 		SecurityTokenRequestType requestType,
 		UA_ChannelSecurityToken* newToken)
 {
@@ -116,14 +105,6 @@ UA_Int32 SL_ChannelManager_generateToken(SL_secureChannel channel, UA_Int32 requ
 	return UA_ERROR;
 }
 
-UA_Int32 SL_ChannelManager_processOpenRequest(SL_secureChannel channel,
-		const UA_OpenSecureChannelRequest* request, UA_OpenSecureChannelResponse* response)
-{
-
-
-	return UA_SUCCESS;
-}
-
 UA_Int32 SL_ChannelManager_updateChannels()
 {
 	//TODO lock access
@@ -136,7 +117,7 @@ UA_Int32 SL_ChannelManager_updateChannels()
 		{
 			UA_indexedList_Element* elem =
 					(UA_indexedList_Element*) current->payload;
-			SL_secureChannel *channel = (SL_secureChannel*) elem->payload;
+			SL_Channel *channel = (SL_Channel*) elem->payload;
 			//remove channels with expired lifetime, close linked list
 			if (channel)
 			{
@@ -164,7 +145,7 @@ UA_Int32 SL_ChannelManager_updateChannels()
 UA_Int32 SL_ChannelManager_removeChannel(UA_Int32 channelId)
 {
 	//TODO lock access
-	SL_secureChannel channel;
+	SL_Channel channel;
 	UA_Int32 retval = UA_SUCCESS;
 	SL_ChannelManager_getChannel(channelId, &channel);
 
@@ -173,16 +154,8 @@ UA_Int32 SL_ChannelManager_removeChannel(UA_Int32 channelId)
 		retval |= UA_list_removeElement(element,(UA_list_PayloadVisitor)SL_Channel_delete);
 		return retval;
 	}
-	/*if (element)
-	{
-		element->next->prev = element->prev;
-		element->prev->next = element->next;
-
-		SL_Channel_delete((SL_secureChannel)element->payload);
 		//TODO notify server application that secureChannel has been closed part 6 - §7.1.4
-	}
-	*/
-	//channel not found
+
 	return UA_ERROR;
 }
 UA_Int32 SL_ChannelManager_getChannelLifeTime(UA_DateTime *lifeTime)
@@ -197,7 +170,7 @@ UA_Int32 SL_ChannelManager_getChannelLifeTime(UA_DateTime *lifeTime)
 	return UA_SUCCESS;UA_list_Element
 }
 */
-UA_Int32 SL_ChannelManager_getChannel(UA_UInt32 channelId, SL_secureChannel *channel)
+UA_Int32 SL_ChannelManager_getChannel(UA_UInt32 channelId, SL_Channel *channel)
 {
 	UA_UInt32 tmpChannelId;
  	UA_list_Element* current = channelManager->channels.first;
@@ -206,7 +179,7 @@ UA_Int32 SL_ChannelManager_getChannel(UA_UInt32 channelId, SL_secureChannel *cha
 		if (current->payload)
 		{
 			UA_list_Element* elem = (UA_list_Element*) current;
-			*channel = *((SL_secureChannel*) (elem->payload));
+			*channel = *((SL_Channel*) (elem->payload));
 			SL_Channel_getChannelId(*channel, &tmpChannelId);
 		 	if(tmpChannelId == channelId)
 		 	{

+ 3 - 3
src/ua_stack_channel_manager.h

@@ -17,20 +17,20 @@ typedef struct SL_ChannelManager *SL_secureChannelManager;
 
 
 UA_Int32 SL_ChannelManager_init(UA_UInt32 maxChannelCount,UA_UInt32 tokenLifetime, UA_UInt32 startChannelId, UA_UInt32 startTokenId, UA_String *endpointUrl);
-UA_Int32 SL_ChannelManager_addChannel(SL_secureChannel *channel);
+UA_Int32 SL_ChannelManager_addChannel(SL_Channel *channel);
 //UA_Int32 SL_ChannelManager_renewChannelToken(UA_Int32 channelId, UA_DateTime requestedLifeTime);
 //UA_Int32 SL_ChannelManager_createChannelToken(SL_secureChannel channel);
 //UA_Int32 SL_ChannelManager_renewChannelToken(SL_secureChannel channel);
 
 //UA_Int32 SL_ChannelManager_bindChannel(UA_Int32 channelId, TL_Connection *connection);
 UA_Int32 SL_ChannelManager_removeChannel(UA_Int32 channelId);
-UA_Int32 SL_ChannelManager_getChannel(UA_UInt32 channelId, SL_secureChannel *channel);
+UA_Int32 SL_ChannelManager_getChannel(UA_UInt32 channelId, SL_Channel *channel);
 
 UA_Int32 SL_ChannelManager_updateChannels();
 
 UA_Int32 SL_ChannelManager_getChannelLifeTime(UA_DateTime *lifeTime);
 
-UA_Int32 SL_ChannelManager_generateToken(SL_secureChannel channel, UA_Int32 requestedLifeTime, SecurityTokenRequestType requestType, UA_ChannelSecurityToken* newToken);
+UA_Int32 SL_ChannelManager_generateToken(SL_Channel channel, UA_Int32 requestedLifeTime, SecurityTokenRequestType requestType, UA_ChannelSecurityToken* newToken);
 
 UA_Int32 SL_ChannelManager_generateChannelId(UA_UInt32 *newChannelId);
 

+ 42 - 13
src/ua_stack_session.c

@@ -8,21 +8,23 @@
 #include <stdlib.h>
 
 #include "ua_stack_session.h"
-typedef struct UA_SessionType
+typedef struct UA_SessionStruct
 {
 	UA_NodeId authenticationToken;
 	UA_NodeId sessionId;
 	UA_String name;
 	Application *application;
-	UA_list_List pendingRequests;
-	SL_secureChannel channel;
+//	UA_list_List pendingRequests;
+	SL_Channel channel;
 	UA_UInt32 maxRequestMessageSize;
 	UA_UInt32 maxResponseMessageSize;
+	UA_Int64 timeout;
+	UA_DateTime validTill;
 
 }UA_SessionType;
 
 /* mock up function to generate tokens for authentication */
-UA_Int32 UA_Session_generateAuthenticationToken(UA_NodeId *newToken)
+UA_Int32 UA_Session_generateToken(UA_NodeId *newToken)
 {
 	//Random token generation
 	UA_Int32 retval = UA_SUCCESS;
@@ -52,7 +54,7 @@ UA_Int32 UA_Session_generateAuthenticationToken(UA_NodeId *newToken)
 	return retval;
 }
 
-UA_Int32 UA_Session_bind(UA_Session session, SL_secureChannel channel)
+UA_Int32 UA_Session_bind(UA_Session session, SL_Channel channel)
 {
 
 	if(channel && session)
@@ -76,28 +78,37 @@ UA_Int32 UA_Session_new(UA_Session **newSession)
 	//get memory for request list
 	return retval;
 }
-
+UA_Int32 UA_Session_deleteMembers(UA_Session session)
+{
+	UA_Int32 retval = UA_SUCCESS;
+	retval |= UA_NodeId_deleteMembers(&((UA_SessionType*)session)->authenticationToken);
+	retval |= UA_String_deleteMembers(&((UA_SessionType*)session)->name);
+	retval |= UA_NodeId_deleteMembers(&((UA_SessionType*)session)->sessionId);
+	return retval;
+}
 UA_Int32 UA_Session_delete(UA_Session *session)
 {
 	UA_Int32 retval = UA_SUCCESS;
+	UA_Session_deleteMembers(*session);
 	retval |= UA_free((UA_SessionType*)(*session));
 	return retval;
 }
-
 UA_Int32 UA_Session_init(UA_Session session, UA_String *sessionName, UA_Double requestedSessionTimeout,
 		UA_UInt32 maxRequestMessageSize,
 		UA_UInt32 maxResponseMessageSize,
-		UA_Session_idProvider idProvider){
+		UA_Session_idProvider idProvider,
+		UA_Int64 timeout){
 	UA_Int32 retval = UA_SUCCESS;
 	retval |= UA_String_copy(sessionName, &((UA_SessionType*)session)->name);
 	((UA_SessionType*)session)->maxRequestMessageSize = maxRequestMessageSize;
 	((UA_SessionType*)session)->maxResponseMessageSize = maxResponseMessageSize;
 
-	UA_Session_generateAuthenticationToken(&((UA_SessionType*)session)->authenticationToken);
+	UA_Session_generateToken(&((UA_SessionType*)session)->authenticationToken);
 
 	idProvider(&((UA_SessionType*)session)->sessionId);
+	((UA_SessionType*)session)->timeout = requestedSessionTimeout > timeout ? timeout : requestedSessionTimeout;
 
-	//TODO handle requestedSessionTimeout
+	UA_Session_updateLifetime(session);
 	return retval;
 }
 
@@ -144,8 +155,17 @@ UA_Int32 UA_Session_getToken(UA_Session session, UA_NodeId *authenticationToken)
 	}
 	return UA_ERROR;
 }
-
-UA_Int32 UA_Session_getChannel(UA_Session session, SL_secureChannel *channel)
+UA_Int32 UA_Session_updateLifetime(UA_Session session)
+{
+	if(session)
+	{
+		((UA_SessionType*)session)->validTill = UA_DateTime_now() +
+				((UA_SessionType*)session)->timeout * 100000; //timeout in ms
+		return UA_SUCCESS;
+	}
+	return UA_ERROR;
+}
+UA_Int32 UA_Session_getChannel(UA_Session session, SL_Channel *channel)
 {
 	if(session)
 	{
@@ -154,8 +174,17 @@ UA_Int32 UA_Session_getChannel(UA_Session session, SL_secureChannel *channel)
 	}
 	return UA_ERROR;
 }
+UA_Int32 UA_Session_getPendingLifetime(UA_Session session, UA_Double *pendingLifetime_ms)
+{
+	if(session)
+	{
+		*pendingLifetime_ms = (((UA_SessionType*)session)->validTill- UA_DateTime_now() ) / 10000000; //difference in ms
+		return UA_SUCCESS;
+	}
+	return UA_ERROR;
+}
 
-UA_Boolean UA_Session_verifyChannel(UA_Session session, SL_secureChannel channel)
+UA_Boolean UA_Session_verifyChannel(UA_Session session, SL_Channel channel)
 {
 	if(session && channel)
 	{

+ 8 - 7
src/ua_stack_session.h

@@ -12,26 +12,27 @@
 #include "ua_stack_channel.h"
 
 
-typedef struct UA_SessionType *UA_Session;
+typedef struct UA_SessionStruct *UA_Session;
 typedef UA_Int32(*UA_Session_idProvider)(UA_NodeId *newSessionId);
 
 UA_Int32 UA_Session_new(UA_Session **newSession);
 UA_Int32 UA_Session_init(UA_Session session, UA_String *sessionName, UA_Double requestedSessionTimeout,
 		UA_UInt32 maxRequestMessageSize,
 		UA_UInt32 maxResponseMessageSize,
-		UA_Session_idProvider idProvider);
+		UA_Session_idProvider idProvider,
+		UA_Int64 timeout);
 UA_Int32 UA_Session_delete(UA_Session *session);
 
 UA_Boolean UA_Session_compare(UA_Session session1, UA_Session session2);
 UA_Boolean UA_Session_compareByToken(UA_Session session, UA_NodeId *token);
 UA_Boolean UA_Session_compareById(UA_Session session, UA_NodeId *sessionId);
-UA_Int32 UA_Session_bind(UA_Session session, SL_secureChannel channel);
-UA_Boolean UA_Session_verifyChannel(UA_Session session, SL_secureChannel channel);
-
+UA_Int32 UA_Session_bind(UA_Session session, SL_Channel channel);
+UA_Boolean UA_Session_verifyChannel(UA_Session session, SL_Channel channel);
+UA_Int32 UA_Session_updateLifetime(UA_Session session);
 UA_Int32 UA_Session_getId(UA_Session session, UA_NodeId *sessionId);
 UA_Int32 UA_Session_getToken(UA_Session session, UA_NodeId *authenticationToken);
-UA_Int32 UA_Session_getChannel(UA_Session session, SL_secureChannel *channel);
-
+UA_Int32 UA_Session_getChannel(UA_Session session, SL_Channel *channel);
+UA_Int32 UA_Session_getPendingLifetime(UA_Session,UA_Double *pendingLifetime);
 UA_Int32 UA_Session_getApplicationPointer(UA_Session session, Application** application);
 
 UA_Int32 UA_Session_setApplicationPointer(UA_Session session, Application* application);

+ 100 - 38
src/ua_stack_session_manager.c

@@ -18,7 +18,7 @@ typedef struct UA_SessionManagerType
 	UA_UInt32 currentSessionCount;
 	UA_DateTime maxSessionLifeTime;
 
-	UA_DateTime sessionLifetime;
+	UA_DateTime sessionTimeout;
 }UA_SessionManagerType;
 
 static UA_SessionManagerType *sessionManager;
@@ -31,7 +31,7 @@ UA_Int32 UA_SessionManager_generateSessionId(UA_NodeId *sessionId)
 	return UA_SUCCESS;
 }
 
-UA_Int32 UA_SessionManager_init(UA_UInt32 maxSessionCount,UA_UInt32 sessionLifetime, UA_UInt32 startSessionId)
+UA_Int32 UA_SessionManager_init(UA_UInt32 maxSessionCount,UA_UInt32 sessionTimeout, UA_UInt32 startSessionId)
 {
 	UA_Int32 retval = UA_SUCCESS;
 	retval |= UA_alloc((void**)&sessionManager,sizeof(UA_SessionManagerType));
@@ -40,16 +40,29 @@ UA_Int32 UA_SessionManager_init(UA_UInt32 maxSessionCount,UA_UInt32 sessionLifet
 
 	sessionManager->maxSessionCount = maxSessionCount;
 	sessionManager->lastSessionId = startSessionId;
-	sessionManager->sessionLifetime = sessionLifetime;
+	sessionManager->sessionTimeout = sessionTimeout;
 	return retval;
 }
 
 UA_Boolean UA_SessionManager_sessionExists(UA_Session *session)
 {
 
-	if(sessionManager && UA_list_search(&sessionManager->sessions,(UA_list_PayloadComparer)UA_Session_compare,(void*)session))
+	if(sessionManager == UA_NULL)
 	{
-		return UA_TRUE;
+		return UA_FALSE;
+	}
+
+	if(UA_list_search(&sessionManager->sessions,(UA_list_PayloadComparer)UA_Session_compare,(void*)session))
+	{
+		UA_Double pendingLifetime;
+		UA_Session_getPendingLifetime(*session,&pendingLifetime);
+		if(pendingLifetime>0){
+			return UA_TRUE;
+		}
+		//timeout of session reached so remove it
+		UA_NodeId sessionId;
+		UA_Session_getId(*session,&sessionId);
+		UA_SessionManager_removeSession(&sessionId);
 	}
 	return UA_FALSE;
 }
@@ -58,20 +71,30 @@ UA_Int32 UA_SessionManager_getSessionById(UA_NodeId *sessionId, UA_Session *sess
 {
 	if(sessionManager != UA_NULL)
 	{
-		UA_list_Element* current = sessionManager->sessions.first;
-		while (current)
+		*session = UA_NULL;
+		return UA_ERROR;
+	}
+
+	UA_list_Element* current = sessionManager->sessions.first;
+	while (current)
+	{
+		if (current->payload)
 		{
-			if (current->payload)
-			{
-				UA_list_Element* elem = (UA_list_Element*) current;
-				*session = *((UA_Session*) (elem->payload));
-				if(UA_Session_compareById(*session,sessionId) == UA_EQUAL)
-				{
+			UA_list_Element* elem = (UA_list_Element*) current;
+			*session = *((UA_Session*) (elem->payload));
+			if(UA_Session_compareById(*session,sessionId) == UA_EQUAL){
+				UA_Double pendingLifetime;
+				UA_Session_getPendingLifetime(*session, &pendingLifetime);
+				if(pendingLifetime > 0){
 					return UA_SUCCESS;
 				}
+				//session not valid anymore -> remove it
+				UA_list_removeElement(elem, (UA_list_PayloadVisitor)UA_Session_delete);
+				*session = UA_NULL;
+				return UA_ERROR;
 			}
-			current = current->next;
 		}
+		current = current->next;
 	}
 	*session = UA_NULL;
 	return UA_ERROR;
@@ -79,23 +102,33 @@ UA_Int32 UA_SessionManager_getSessionById(UA_NodeId *sessionId, UA_Session *sess
 
 UA_Int32 UA_SessionManager_getSessionByToken(UA_NodeId *token, UA_Session *session)
 {
-	if(sessionManager != UA_NULL)
+	if(sessionManager == UA_NULL)
+	{
+		*session = UA_NULL;
+		return UA_ERROR;
+	}
+
+	UA_list_Element* current = sessionManager->sessions.first;
+	while (current)
 	{
-		UA_list_Element* current = sessionManager->sessions.first;
-		while (current)
+		if (current->payload)
 		{
-			if (current->payload)
-			{
-				UA_list_Element* elem = (UA_list_Element*) current;
-				*session = *((UA_Session*) (elem->payload));
-				if(UA_Session_compareByToken(*session,token) == UA_EQUAL)
-				{
+			UA_list_Element* elem = (UA_list_Element*) current;
+			*session = *((UA_Session*) (elem->payload));
+
+			if(UA_Session_compareByToken(*session,token) == UA_EQUAL){
+				UA_Double pendingLifetime;
+				UA_Session_getPendingLifetime(*session, &pendingLifetime);
+				if(pendingLifetime > 0){
 					return UA_SUCCESS;
 				}
+				//session not valid anymore -> remove it
+				UA_list_removeElement(elem, (UA_list_PayloadVisitor)UA_Session_delete);
+				*session = UA_NULL;
+				return UA_ERROR;
 			}
-			current = current->next;
 		}
-
+		current = current->next;
 	}
 	*session = UA_NULL;
 	return UA_ERROR;
@@ -111,16 +144,14 @@ UA_Int32 UA_SessionManager_addSession(UA_Session *session)
 		UA_Session_getId(*session, &sessionId);
 
 		printf("UA_SessionManager_addSession - added session with id = %d \n",sessionId.identifier.numeric);
+		printf("UA_SessionManager_addSession - current session count: %i \n",sessionManager->sessions.size);
 
 		return retval;
 	}
-	else
-	{
-		printf("UA_SessionManager_addSession - session already in list");
-		return UA_ERROR;
-	}
-}
+	printf("UA_SessionManager_addSession - session already in list");
+	return UA_ERROR;
 
+}
 
 UA_Int32 UA_SessionManager_removeSession(UA_NodeId *sessionId)
 {
@@ -129,17 +160,48 @@ UA_Int32 UA_SessionManager_removeSession(UA_NodeId *sessionId)
 	if(element)
 	{
 		retval |= UA_list_removeElement(element,(UA_list_PayloadVisitor)UA_Session_delete);
+		printf("UA_SessionManager_removeSession - session removed, current count: %i \n",sessionManager->sessions.size);
 	}
+
 	return retval;
 }
 
-UA_Int32 UA_SessionManager_getSession(UA_UInt32 sessionId, UA_Session *session);
-
-UA_Int32 UA_SessionManager_updateSessions();
-
-UA_Int32 UA_SessionManager_getSessionLifeTime(UA_DateTime *lifeTime);
+UA_Int32 UA_SessionManager_updateSessions()
+{
+	if(sessionManager == UA_NULL)
+	{
+		return UA_ERROR;
+	}
+	UA_list_Element* current = sessionManager->sessions.first;
+	while (current)
+	{
+		if (current->payload)
+		{
+			UA_list_Element* elem = (UA_list_Element*) current;
+			UA_Session session = *((UA_Session*) (elem->payload));
+			UA_Double pendingLifetime;
+			UA_Session_getPendingLifetime(session, &pendingLifetime);
+
+			if(pendingLifetime <= 0){
+				UA_NodeId sessionId;
+				UA_Session_getId(session,&sessionId);
+				UA_SessionManager_removeSession(&sessionId);
+			}
+		}
+		current = current->next;
+	}
+	return UA_SUCCESS;
+}
 
-UA_Int32 SL_UA_SessionManager_generateToken(SL_secureChannel channel, UA_Int32 requestedLifeTime, SecurityTokenRequestType requestType, UA_ChannelSecurityToken* newToken);
+UA_Int32 UA_SessionManager_getSessionTimeout(UA_Int64 *timeout_ms)
+{
+	if(sessionManager)
+	{
+		*timeout_ms = sessionManager->sessionTimeout;
+		return UA_SUCCESS;
+	}
+	*timeout_ms = 0;
+	return UA_ERROR;
+}
 
-UA_Int32 SL_UA_SessionManager_generateSessionId(UA_UInt32 *newChannelId);
 

+ 17 - 7
src/ua_stack_session_manager.h

@@ -22,7 +22,7 @@ typedef struct UA_SessionManagerType *UA_SessionManager;
  * @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
+ * @return error code
  */
 UA_Int32 UA_SessionManager_init(UA_UInt32 maxSessionCount,UA_UInt32 sessionLifetime,
 		UA_UInt32 startSessionId);
@@ -30,14 +30,14 @@ UA_Int32 UA_SessionManager_init(UA_UInt32 maxSessionCount,UA_UInt32 sessionLifet
 /**
  * @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
+ * @return error code
  */
 UA_Int32 UA_SessionManager_addSession(UA_Session *session);
 
 /**
  * @brief removes a session from the manager list
  * @param sessionId id which assign to a session
- * @return error code if all goes well UA_SUCCESS is returned
+ * @return error code
  */
 UA_Int32 UA_SessionManager_removeSession(UA_NodeId *sessionId);
 
@@ -45,7 +45,7 @@ UA_Int32 UA_SessionManager_removeSession(UA_NodeId *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
+ * @return error code
  */
 UA_Int32 UA_SessionManager_getSessionById(UA_NodeId *sessionId, UA_Session *session);
 
@@ -53,14 +53,24 @@ UA_Int32 UA_SessionManager_getSessionById(UA_NodeId *sessionId, UA_Session *sess
  * @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
+ * @return error code
  */
 UA_Int32 UA_SessionManager_getSessionByToken(UA_NodeId *token, UA_Session *session);
 
-UA_Int32 UA_SessionManager_updateSessions();
 
+/**
+ * @brief gets the session timeout value which should be assigned to
+ * all sessions handled by the manager
+ * @param timeout_ms timeout in milliseconds
+ * @return error code
+ */
+UA_Int32 UA_SessionManager_getSessionTimeout(UA_Int64 *timeout_ms);
+/**
+ * @brief updates all session
+ * @return
+ */
+UA_Int32 UA_SessionManager_updateSessions();
 
-UA_Int32 UA_SessionManager_getSessionLifeTime(UA_DateTime *lifeTime);
 
 //UA_Int32 UA_SessionManager_generateToken(UA_Session session, UA_Int32 requestedLifeTime, SecurityTokenRequestType requestType, UA_ChannelSecurityToken* newToken);
 

+ 7 - 7
src/ua_transport_binary.c

@@ -5,7 +5,7 @@
 #include "ua_transport_connection.h"
 
 
-static UA_Int32 TL_handleHello(UA_TL_Connection1 connection, const UA_ByteString* msg, UA_UInt32* pos){
+static UA_Int32 TL_handleHello(UA_TL_Connection connection, const UA_ByteString* msg, UA_UInt32* pos){
 	UA_Int32 retval = UA_SUCCESS;
 	UA_UInt32 tmpPos = 0;
 	UA_Int32 connectionState;
@@ -71,10 +71,10 @@ static UA_Int32 TL_securitySettingsMockup_get(UA_ByteString *receiverCertificate
 
 	return UA_SUCCESS;
 }
-static UA_Int32 TL_handleOpen(UA_TL_Connection1 connection, const UA_ByteString* msg, UA_UInt32* pos) {
+static UA_Int32 TL_handleOpen(UA_TL_Connection connection, const UA_ByteString* msg, UA_UInt32* pos) {
 	UA_Int32 retval = UA_SUCCESS;
 	UA_Int32 state;
-	SL_secureChannel *channel;
+	SL_Channel *channel;
 
 	UA_ByteString receiverCertificateThumbprint;
 	UA_ByteString securityPolicyUri;
@@ -109,7 +109,7 @@ static UA_Int32 TL_handleOpen(UA_TL_Connection1 connection, const UA_ByteString*
 	return UA_ERR_INVALID_VALUE;
 }
 
-static UA_Int32 TL_handleMsg(UA_TL_Connection1 connection, const UA_ByteString* msg, UA_UInt32* pos) {
+static UA_Int32 TL_handleMsg(UA_TL_Connection connection, const UA_ByteString* msg, UA_UInt32* pos) {
 	UA_Int32 state;
 	UA_TL_Connection_getState(connection,&state);
 	if (state == CONNECTIONSTATE_ESTABLISHED) {
@@ -118,7 +118,7 @@ static UA_Int32 TL_handleMsg(UA_TL_Connection1 connection, const UA_ByteString*
 	return UA_ERR_INVALID_VALUE;
 }
 
-static UA_Int32 TL_handleClo(UA_TL_Connection1 connection, const UA_ByteString* msg, UA_UInt32* pos) {
+static UA_Int32 TL_handleClo(UA_TL_Connection connection, const UA_ByteString* msg, UA_UInt32* pos) {
 	UA_Int32 retval = UA_SUCCESS;
 	SL_Process(msg,pos);
 
@@ -126,7 +126,7 @@ static UA_Int32 TL_handleClo(UA_TL_Connection1 connection, const UA_ByteString*
 	return retval;
 }
 
-UA_Int32 TL_Process(UA_TL_Connection1 connection, const UA_ByteString* msg) {
+UA_Int32 TL_Process(UA_TL_Connection connection, const UA_ByteString* msg) {
 	UA_Int32 retval = UA_SUCCESS;
 	UA_UInt32 pos = 0;
 	UA_OPCUATcpMessageHeader tcpMessageHeader;
@@ -181,7 +181,7 @@ UA_Int32 TL_Process(UA_TL_Connection1 connection, const UA_ByteString* msg) {
 }
 
 /** respond to client request */
-UA_Int32 TL_Send(UA_TL_Connection1 connection, const UA_ByteString** gather_buf, UA_UInt32 gather_len) {
+UA_Int32 TL_Send(UA_TL_Connection connection, const UA_ByteString** gather_buf, UA_UInt32 gather_len) {
 	UA_Int32 retval = UA_SUCCESS;
 
 

+ 2 - 2
src/ua_transport_binary.h

@@ -34,7 +34,7 @@ typedef struct TL_Connection_T {
 } TL_Connection;
 */
 
-UA_Int32 TL_Send(UA_TL_Connection1 connection, const UA_ByteString** gather_buf, UA_UInt32 gather_len);
-UA_Int32 TL_Process(UA_TL_Connection1 connection, const UA_ByteString* msg);
+UA_Int32 TL_Send(UA_TL_Connection connection, const UA_ByteString** gather_buf, UA_UInt32 gather_len);
+UA_Int32 TL_Process(UA_TL_Connection connection, const UA_ByteString* msg);
 
 #endif /* OPCUA_TRANSPORT_BINARY_H_ */

+ 22 - 12
src/ua_transport_binary_secure.c

@@ -12,7 +12,7 @@
 #define SIZE_SECURECHANNEL_HEADER 12
 #define SIZE_SEQHEADER_HEADER 8
 
-static UA_Int32 SL_Send(SL_secureChannel channel,
+static UA_Int32 SL_Send(SL_Channel channel,
 		const UA_ByteString * responseMessage, UA_Int32 type)
 {
 
@@ -25,7 +25,7 @@ static UA_Int32 SL_Send(SL_secureChannel channel,
 	UA_UInt32 channelId;
 	UA_UInt32 sequenceNumber;
 	UA_UInt32 requestId;
-	UA_TL_Connection1 connection;
+	UA_TL_Connection connection;
 	UA_NodeId resp_nodeid;
 	UA_AsymmetricAlgorithmSecurityHeader *asymAlgSettings = UA_NULL;
 
@@ -57,7 +57,7 @@ static UA_Int32 SL_Send(SL_secureChannel channel,
 	// sizeSignature = 0;
 	UA_ByteString *header = (UA_ByteString *) response_gather[0];
 
-	/*---encode Secure Conversation Message HeaService_CreateSessionder ---*/
+	/*---encode Secure Conversation Message Header  ---*/
 	if (isAsym)
 	{
 		header->data[0] = 'O';
@@ -174,7 +174,7 @@ static void init_response_header(UA_RequestHeader const * p,
 	UA_##TYPE##Response_deleteMembers(&r); \
 
 
-UA_Int32 SL_handleRequest(SL_secureChannel channel, const UA_ByteString* msg,
+UA_Int32 SL_handleRequest(SL_Channel channel, const UA_ByteString* msg,
 		UA_UInt32 *pos)
 {
 	UA_Int32 retval = UA_SUCCESS;
@@ -226,6 +226,7 @@ UA_Int32 SL_handleRequest(SL_secureChannel channel, const UA_ByteString* msg,
 	else if (serviceid == UA_ACTIVATESESSIONREQUEST_NS0)
 	{
 		RESPONSE_PREPARE(ActivateSession);
+		UA_Session_updateLifetime(session); //renew session timeout
 		Service_ActivateSession(channel, session,&p, &r);
 		RESPONSE_CLEANUP(ActivateSession);
 
@@ -234,17 +235,25 @@ UA_Int32 SL_handleRequest(SL_secureChannel channel, const UA_ByteString* msg,
 	else if (serviceid == UA_CLOSESESSIONREQUEST_NS0)
 	{
 		RESPONSE_PREPARE(CloseSession);
-		Service_CloseSession(session,&p, &r);
+		if (UA_Session_verifyChannel(session,channel)){
+			UA_Session_updateLifetime(session); //renew session timeout
+			Service_CloseSession(session,&p, &r);
 		RESPONSE_CLEANUP(CloseSession);
-
+		}
+		else
+		{
+			DBG_VERBOSE(printf("session does not match secure channel"));
+		}
 		responsetype = UA_CLOSESESSIONRESPONSE_NS0;
 	}
 	else if (serviceid == UA_READREQUEST_NS0)
 	{
 
 		RESPONSE_PREPARE(Read);
+		UA_Session_updateLifetime(session); //renew session timeout
 		DBG_VERBOSE(printf("Finished Service: %s\n", Read));
 		if (UA_Session_verifyChannel(session,channel)){
+			UA_Session_updateLifetime(session); //renew session timeout
 			Service_Read(session,&p, &r);
 		}
 		else
@@ -253,7 +262,6 @@ UA_Int32 SL_handleRequest(SL_secureChannel channel, const UA_ByteString* msg,
 		}
 		DBG_VERBOSE(printf("Finished Service: %s\n", Read));
 		RESPONSE_CLEANUP(Read);
-		//TODO prepare userdefined implementation
 
 		responsetype = UA_READRESPONSE_NS0;
 	}
@@ -263,6 +271,7 @@ UA_Int32 SL_handleRequest(SL_secureChannel channel, const UA_ByteString* msg,
 		RESPONSE_PREPARE(Write);
 		DBG_VERBOSE(printf("Finished Service: %s\n", Write));
 		if (UA_Session_verifyChannel(session,channel)){
+			UA_Session_updateLifetime(session); //renew session timeout
 			Service_Write(session,&p, &r);
 		}
 		else
@@ -400,8 +409,9 @@ UA_Int32 SL_handleRequest(SL_secureChannel channel, const UA_ByteString* msg,
 		UA_ResponseHeader_encodeBinary(&r, &response_msg,&sendOffset);
 		responsetype = UA_RESPONSEHEADER_NS0;
 	}
-
-	SL_Send(channel, &response_msg, responsetype);
+	if(serviceid != UA_CLOSESECURECHANNELREQUEST_NS0){
+		SL_Send(channel, &response_msg, responsetype);
+	}
 	UA_ByteString_deleteMembers(&response_msg);
 	*pos = recvOffset;
 	return retval;
@@ -414,12 +424,12 @@ UA_Int32 SL_handleRequest(SL_secureChannel channel, const UA_ByteString* msg,
  * @return
  */
 
-UA_Int32 SL_ProcessOpenChannel(SL_secureChannel channel, const UA_ByteString* msg,
+UA_Int32 SL_ProcessOpenChannel(SL_Channel channel, const UA_ByteString* msg,
 		UA_UInt32 *pos)
 {
 	return SL_handleRequest(channel, msg, pos);
 }
-UA_Int32 SL_ProcessCloseChannel(SL_secureChannel channel, const UA_ByteString* msg,
+UA_Int32 SL_ProcessCloseChannel(SL_Channel channel, const UA_ByteString* msg,
 		UA_UInt32 *pos)
 {
 	return SL_handleRequest(channel, msg, pos);
@@ -431,7 +441,7 @@ UA_Int32 SL_Process(const UA_ByteString* msg,
 	DBG_VERBOSE(printf("SL_process - entered \n"));
 	UA_UInt32 secureChannelId;
 	UA_UInt32 foundChannelId;
-	SL_secureChannel channel;
+	SL_Channel channel;
 	UA_SequenceHeader sequenceHeader;
 
 

+ 2 - 2
src/ua_transport_binary_secure.h

@@ -50,8 +50,8 @@ UA_Int32 SL_Process(const UA_ByteString* msg, UA_UInt32* pos);
  * @return Returns UA_SUCCESS if successful executed, UA_ERROR in any other case
 
  */
-UA_Int32 SL_ProcessOpenChannel(SL_secureChannel channel, const UA_ByteString* msg,
+UA_Int32 SL_ProcessOpenChannel(SL_Channel channel, const UA_ByteString* msg,
 		UA_UInt32 *pos);
-UA_Int32 SL_ProcessCloseChannel(SL_secureChannel channel, const UA_ByteString* msg,
+UA_Int32 SL_ProcessCloseChannel(SL_Channel channel, const UA_ByteString* msg,
 		UA_UInt32 *pos);
 #endif /* OPCUA_TRANSPORT_BINARY_SECURE_H_ */

+ 43 - 43
src/ua_transport_connection.c

@@ -7,7 +7,7 @@
 
 #include "ua_transport_connection.h"
 #include "ua_transport.h"
-typedef struct TL_Connection{
+typedef struct TL_ConnectionStruct{
 	UA_Int32 connectionHandle;
 	UA_UInt32 state;
 	TL_Buffer localConf;
@@ -17,43 +17,43 @@ typedef struct TL_Connection{
 	UA_String remoteEndpointUrl;
 	TL_Closer closeCallback;
 	void *networkLayerData;
-} TL_Connection;
+} TL_ConnectionType;
 
 
-UA_Int32 UA_TL_Connection_new(UA_TL_Connection1 *connection, TL_Buffer localBuffers,TL_Writer writer, TL_Closer closeCallback, void* networkLayerData)
+UA_Int32 UA_TL_Connection_new(UA_TL_Connection *connection, TL_Buffer localBuffers,TL_Writer writer, TL_Closer closeCallback, void* networkLayerData)
 {
 	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_alloc((void**)connection,sizeof(TL_Connection));
+	retval |= UA_alloc((void**)connection,sizeof(TL_ConnectionType));
 	if(retval == UA_SUCCESS)
 	{
-		(*((TL_Connection**)connection))->localConf = localBuffers;
-		(*((TL_Connection**)connection))->writer = writer;
-		(*((TL_Connection**)connection))->closeCallback = closeCallback;
-		(*((TL_Connection**)connection))->state = CONNECTIONSTATE_CLOSED;
-		(*((TL_Connection**)connection))->networkLayerData = networkLayerData;
+		(*((TL_ConnectionType**)connection))->localConf = localBuffers;
+		(*((TL_ConnectionType**)connection))->writer = writer;
+		(*((TL_ConnectionType**)connection))->closeCallback = closeCallback;
+		(*((TL_ConnectionType**)connection))->state = CONNECTIONSTATE_CLOSED;
+		(*((TL_ConnectionType**)connection))->networkLayerData = networkLayerData;
 	}
 	return retval;
 }
 
-UA_Int32 UA_TL_Connection_delete(UA_TL_Connection1 connection)
+UA_Int32 UA_TL_Connection_delete(UA_TL_Connection connection)
 {
 	UA_Int32 retval = UA_SUCCESS;
 	retval |= UA_free((void*)connection);
 	return retval;
 }
 
-UA_Int32 UA_TL_Connection_close(UA_TL_Connection1 connection)
+UA_Int32 UA_TL_Connection_close(UA_TL_Connection connection)
 {
-	((TL_Connection*)connection)->state = CONNECTIONSTATE_CLOSE;
-	((TL_Connection*)connection)->closeCallback(connection);
+	((TL_ConnectionType*)connection)->state = CONNECTIONSTATE_CLOSE;
+	((TL_ConnectionType*)connection)->closeCallback(connection);
 	return UA_SUCCESS;
 }
 
-UA_Boolean UA_TL_Connection_compare(UA_TL_Connection1 *connection1, UA_TL_Connection1 *connection2)
+UA_Boolean UA_TL_Connection_compare(UA_TL_Connection *connection1, UA_TL_Connection *connection2)
 {
 	if(connection1 && connection2)
 	{
-		if ((*(TL_Connection**)connection1)->connectionHandle == (*(TL_Connection**)connection2)->connectionHandle)
+		if ((*(TL_ConnectionType**)connection1)->connectionHandle == (*(TL_ConnectionType**)connection2)->connectionHandle)
 		{
 			return UA_TRUE;
 		}
@@ -62,52 +62,52 @@ UA_Boolean UA_TL_Connection_compare(UA_TL_Connection1 *connection1, UA_TL_Connec
 }
 
 
-UA_Int32 UA_TL_Connection_configByHello(UA_TL_Connection1 connection, UA_OPCUATcpHelloMessage *helloMessage)
+UA_Int32 UA_TL_Connection_configByHello(UA_TL_Connection connection, UA_OPCUATcpHelloMessage *helloMessage)
 {
 	UA_Int32 retval = UA_SUCCESS;
-	((TL_Connection*)connection)->remoteConf.maxChunkCount = helloMessage->maxChunkCount;
-	((TL_Connection*)connection)->remoteConf.maxMessageSize = helloMessage->maxMessageSize;
-	((TL_Connection*)connection)->remoteConf.protocolVersion = helloMessage->protocolVersion;
-	((TL_Connection*)connection)->remoteConf.recvBufferSize = helloMessage->receiveBufferSize;
-	((TL_Connection*)connection)->remoteConf.sendBufferSize = helloMessage->sendBufferSize;
-	((TL_Connection*)connection)->state = CONNECTIONSTATE_ESTABLISHED;
-	retval |= UA_String_copy(&helloMessage->endpointUrl,&connection->remoteEndpointUrl);
+	((TL_ConnectionType*)connection)->remoteConf.maxChunkCount = helloMessage->maxChunkCount;
+	((TL_ConnectionType*)connection)->remoteConf.maxMessageSize = helloMessage->maxMessageSize;
+	((TL_ConnectionType*)connection)->remoteConf.protocolVersion = helloMessage->protocolVersion;
+	((TL_ConnectionType*)connection)->remoteConf.recvBufferSize = helloMessage->receiveBufferSize;
+	((TL_ConnectionType*)connection)->remoteConf.sendBufferSize = helloMessage->sendBufferSize;
+	((TL_ConnectionType*)connection)->state = CONNECTIONSTATE_ESTABLISHED;
+	retval |= UA_String_copy(&helloMessage->endpointUrl,&((TL_ConnectionType*)connection)->remoteEndpointUrl);
 
 	return UA_SUCCESS;
 }
 
-UA_Int32 UA_TL_Connection_callWriter(UA_TL_Connection1 connection, const UA_ByteString** gather_bufs, UA_Int32 gather_len)
+UA_Int32 UA_TL_Connection_callWriter(UA_TL_Connection connection, const UA_ByteString** gather_bufs, UA_Int32 gather_len)
 {
-	return ((TL_Connection*)connection)->writer(((TL_Connection*)connection)->connectionHandle,gather_bufs, gather_len);
+	return ((TL_ConnectionType*)connection)->writer(((TL_ConnectionType*)connection)->connectionHandle,gather_bufs, gather_len);
 }
 
 //setters
-UA_Int32 UA_TL_Connection_setWriter(UA_TL_Connection1 connection, TL_Writer writer)
+UA_Int32 UA_TL_Connection_setWriter(UA_TL_Connection connection, TL_Writer writer)
 {
-	((TL_Connection*)connection)->writer = writer;
+	((TL_ConnectionType*)connection)->writer = writer;
 	return UA_SUCCESS;
 }
-UA_Int32 UA_TL_Connection_setConnectionHandle(UA_TL_Connection1 connection, UA_Int32 connectionHandle)
+UA_Int32 UA_TL_Connection_setConnectionHandle(UA_TL_Connection connection, UA_Int32 connectionHandle)
 {
-	((TL_Connection*)connection)->connectionHandle = connectionHandle;
+	((TL_ConnectionType*)connection)->connectionHandle = connectionHandle;
 	return UA_SUCCESS;
 }
-UA_Int32 UA_TL_Connection_setState(UA_TL_Connection1 connection, UA_Int32 connectionState)
+UA_Int32 UA_TL_Connection_setState(UA_TL_Connection connection, UA_Int32 connectionState)
 {
 	if(connection)
 	{
-		((TL_Connection*)connection)->state = connectionState;
+		((TL_ConnectionType*)connection)->state = connectionState;
 		return UA_SUCCESS;
 	}else{
 		return UA_ERROR;
 	}
 }
 //getters
-UA_Int32 UA_TL_Connection_getState(UA_TL_Connection1 connection, UA_Int32 *connectionState)
+UA_Int32 UA_TL_Connection_getState(UA_TL_Connection connection, UA_Int32 *connectionState)
 {
 	if(connection)
 	{
-		*connectionState = ((TL_Connection*)connection)->state;
+		*connectionState = ((TL_ConnectionType*)connection)->state;
 		return UA_SUCCESS;
 	}else{
 		*connectionState = -1;
@@ -115,11 +115,11 @@ UA_Int32 UA_TL_Connection_getState(UA_TL_Connection1 connection, UA_Int32 *conne
 	}
 }
 
-UA_Int32 UA_TL_Connection_getNetworkLayerData(UA_TL_Connection1 connection,void** networkLayerData)
+UA_Int32 UA_TL_Connection_getNetworkLayerData(UA_TL_Connection connection,void** networkLayerData)
 {
 	if(connection)
 	{
-		*networkLayerData = ((TL_Connection*)connection)->networkLayerData;
+		*networkLayerData = ((TL_ConnectionType*)connection)->networkLayerData;
 		return UA_SUCCESS;
 	}else{
 		*networkLayerData = UA_NULL;
@@ -127,33 +127,33 @@ UA_Int32 UA_TL_Connection_getNetworkLayerData(UA_TL_Connection1 connection,void*
 	}
 }
 
-UA_Int32 UA_TL_Connection_getProtocolVersion(UA_TL_Connection1 connection, UA_UInt32 *protocolVersion)
+UA_Int32 UA_TL_Connection_getProtocolVersion(UA_TL_Connection connection, UA_UInt32 *protocolVersion)
 {
 	if(connection)
 	{
-		*protocolVersion = ((TL_Connection*)connection)->localConf.protocolVersion;
+		*protocolVersion = ((TL_ConnectionType*)connection)->localConf.protocolVersion;
 		return UA_SUCCESS;
 	}else{
 		*protocolVersion = 0xFF;
 		return UA_ERROR;
 	}
 }
-UA_Int32 UA_TL_Connection_getLocalConfig(UA_TL_Connection1 connection, TL_Buffer *localConfiguration)
+UA_Int32 UA_TL_Connection_getLocalConfig(UA_TL_Connection connection, TL_Buffer *localConfiguration)
 {
 	if(connection)
 	{
-		return UA_memcpy(localConfiguration,&((TL_Connection*)connection)->localConf, sizeof(TL_Buffer));
+		return UA_memcpy(localConfiguration,&((TL_ConnectionType*)connection)->localConf, sizeof(TL_Buffer));
 
 	}else{
 		localConfiguration = UA_NULL;
 		return UA_ERROR;
 	}
 }
-UA_Int32 UA_TL_Connection_getHandle(UA_TL_Connection1 connection, UA_UInt32 *connectionHandle)
+UA_Int32 UA_TL_Connection_getHandle(UA_TL_Connection connection, UA_UInt32 *connectionHandle)
 {
 	if(connection)
 	{
-		*connectionHandle = ((TL_Connection*)connection)->connectionHandle;
+		*connectionHandle = ((TL_ConnectionType*)connection)->connectionHandle;
 		return UA_SUCCESS;
 	}else{
 			connectionHandle = 0;
@@ -161,11 +161,11 @@ UA_Int32 UA_TL_Connection_getHandle(UA_TL_Connection1 connection, UA_UInt32 *con
 		}
 }
 
-UA_Int32 UA_TL_Connection_bind(UA_TL_Connection1 connection, UA_Int32 handle)
+UA_Int32 UA_TL_Connection_bind(UA_TL_Connection connection, UA_Int32 handle)
 {
 	if(connection)
 	{
-		((TL_Connection*)connection)->connectionHandle = handle;
+		((TL_ConnectionType*)connection)->connectionHandle = handle;
 		return UA_SUCCESS;
 	}else{
 

+ 17 - 17
src/ua_transport_connection.h

@@ -19,33 +19,33 @@ typedef struct TL_Buffer{
 	UA_UInt32 maxChunkCount;
 } TL_Buffer;
 
-typedef struct TL_Connection *UA_TL_Connection1;
+typedef struct UA_ConnectionStruct *UA_TL_Connection;
 
-typedef UA_Int32 (*TL_Closer)(UA_TL_Connection1);
+typedef UA_Int32 (*TL_Closer)(UA_TL_Connection);
 typedef UA_Int32 (*TL_Writer)(UA_Int32 connectionHandle, const UA_ByteString** gather_bufs, UA_Int32 gather_len); // send mutiple buffer concatenated into one msg (zero copy)
 
 
-UA_Int32 UA_TL_Connection_configByHello(UA_TL_Connection1 connection, UA_OPCUATcpHelloMessage *helloMessage);
+UA_Int32 UA_TL_Connection_configByHello(UA_TL_Connection connection, UA_OPCUATcpHelloMessage *helloMessage);
 
-UA_Int32 UA_TL_Connection_delete(UA_TL_Connection1 connection);
-UA_Int32 UA_TL_Connection_callWriter(UA_TL_Connection1 connection, const UA_ByteString** gather_bufs, UA_Int32 gather_len);
+UA_Int32 UA_TL_Connection_delete(UA_TL_Connection connection);
+UA_Int32 UA_TL_Connection_callWriter(UA_TL_Connection connection, const UA_ByteString** gather_bufs, UA_Int32 gather_len);
 
-UA_Int32 UA_TL_Connection_close(UA_TL_Connection1 connection);
-UA_Int32 UA_TL_Connection_new(UA_TL_Connection1 *connection, TL_Buffer localBuffers,TL_Writer writer, TL_Closer closeCallback, void* networkLayerData);
-UA_Int32 UA_TL_Connection_bind(UA_TL_Connection1 connection, UA_Int32 handle);
-UA_Boolean UA_TL_Connection_compare(UA_TL_Connection1 *connection1, UA_TL_Connection1 *connection2);
+UA_Int32 UA_TL_Connection_close(UA_TL_Connection connection);
+UA_Int32 UA_TL_Connection_new(UA_TL_Connection *connection, TL_Buffer localBuffers,TL_Writer writer, TL_Closer closeCallback, void* networkLayerData);
+UA_Int32 UA_TL_Connection_bind(UA_TL_Connection connection, UA_Int32 handle);
+UA_Boolean UA_TL_Connection_compare(UA_TL_Connection *connection1, UA_TL_Connection *connection2);
 
 //setters
-UA_Int32 UA_TL_Connection_setState(UA_TL_Connection1 connection, UA_Int32 connectionState);
-UA_Int32 UA_TL_Connection_setWriter(UA_TL_Connection1 connection, TL_Writer writer);
-UA_Int32 UA_TL_Connection_setConnectionHandle(UA_TL_Connection1 connection, UA_Int32 connectionHandle);
+UA_Int32 UA_TL_Connection_setState(UA_TL_Connection connection, UA_Int32 connectionState);
+UA_Int32 UA_TL_Connection_setWriter(UA_TL_Connection connection, TL_Writer writer);
+UA_Int32 UA_TL_Connection_setConnectionHandle(UA_TL_Connection connection, UA_Int32 connectionHandle);
 
 //getters
-UA_Int32 UA_TL_Connection_getHandle(UA_TL_Connection1 connection, UA_UInt32 *connectionId);
-UA_Int32 UA_TL_Connection_getProtocolVersion(UA_TL_Connection1 connection, UA_UInt32 *protocolVersion);
-UA_Int32 UA_TL_Connection_getState(UA_TL_Connection1 connection, UA_Int32 *connectionState);
-UA_Int32 UA_TL_Connection_getLocalConfig(UA_TL_Connection1 connection, TL_Buffer *localConfiguration);
-UA_Int32 UA_TL_Connection_getNetworkLayerData(UA_TL_Connection1 connection,void** networkLayerData);
+UA_Int32 UA_TL_Connection_getHandle(UA_TL_Connection connection, UA_UInt32 *connectionId);
+UA_Int32 UA_TL_Connection_getProtocolVersion(UA_TL_Connection connection, UA_UInt32 *protocolVersion);
+UA_Int32 UA_TL_Connection_getState(UA_TL_Connection connection, UA_Int32 *connectionState);
+UA_Int32 UA_TL_Connection_getLocalConfig(UA_TL_Connection connection, TL_Buffer *localConfiguration);
+UA_Int32 UA_TL_Connection_getNetworkLayerData(UA_TL_Connection connection,void** networkLayerData);
 
 
 #endif /* UA_TRANSPORT_CONNECTION_H_ */

+ 4 - 4
src/ua_transport_connection_manager.c

@@ -35,7 +35,7 @@ UA_Int32 UA_TL_ConnectionManager_init(UA_UInt32 maxConnectionCount)
 	}
 	return UA_SUCCESS;
 }
-UA_Int32 UA_TL_ConnectionManager_addConnection(UA_TL_Connection1 *connection)
+UA_Int32 UA_TL_ConnectionManager_addConnection(UA_TL_Connection *connection)
 {
 	UA_UInt32 connectionId;
 	UA_TL_Connection_getHandle(*connection, &connectionId);
@@ -44,7 +44,7 @@ UA_Int32 UA_TL_ConnectionManager_addConnection(UA_TL_Connection1 *connection)
 }
 
 
-UA_Int32 UA_TL_ConnectionManager_removeConnection(UA_TL_Connection1 connection)
+UA_Int32 UA_TL_ConnectionManager_removeConnection(UA_TL_Connection connection)
 {
 	UA_list_Element *element =  UA_list_find(&connectionManager->connections, (UA_list_PayloadMatcher)UA_TL_Connection_compare);
 
@@ -55,7 +55,7 @@ UA_Int32 UA_TL_ConnectionManager_removeConnection(UA_TL_Connection1 connection)
 	return UA_SUCCESS;
 }
 
-UA_Int32 UA_TL_ConnectionManager_getConnectionByHandle(UA_UInt32 connectionId, UA_TL_Connection1 *connection)
+UA_Int32 UA_TL_ConnectionManager_getConnectionByHandle(UA_UInt32 connectionId, UA_TL_Connection *connection)
 {
 	UA_UInt32 tmpConnectionHandle;
 	if(connectionManager)
@@ -66,7 +66,7 @@ UA_Int32 UA_TL_ConnectionManager_getConnectionByHandle(UA_UInt32 connectionId, U
 			if (current->payload)
 			{
 				UA_list_Element* elem = (UA_list_Element*) current;
-				*connection = *((UA_TL_Connection1*) (elem->payload));
+				*connection = *((UA_TL_Connection*) (elem->payload));
 				UA_TL_Connection_getHandle(*connection, &tmpConnectionHandle);
 
 				if(tmpConnectionHandle == connectionId)

+ 3 - 3
src/ua_transport_connection_manager.h

@@ -12,9 +12,9 @@
 
 
 UA_Int32 UA_TL_ConnectionManager_init(UA_UInt32 maxConnectionCount);
-UA_Int32 UA_TL_ConnectionManager_addConnection(UA_TL_Connection1 *connection);
-UA_Int32 UA_TL_ConnectionManager_removeConnection(UA_TL_Connection1 connection);
+UA_Int32 UA_TL_ConnectionManager_addConnection(UA_TL_Connection *connection);
+UA_Int32 UA_TL_ConnectionManager_removeConnection(UA_TL_Connection connection);
 //getter
-UA_Int32 UA_TL_ConnectionManager_getConnectionByHandle(UA_UInt32 connectionId, UA_TL_Connection1 *connection);
+UA_Int32 UA_TL_ConnectionManager_getConnectionByHandle(UA_UInt32 connectionId, UA_TL_Connection *connection);
 
 #endif /* UA_CONNECTION_MANAGER_H_ */