Kaynağa Gözat

repository gardening with no effect on actual code logic

Julius Pfrommer 10 yıl önce
ebeveyn
işleme
d5fa9c959e

+ 37 - 70
src/ua_stack_channel.c

@@ -1,10 +1,3 @@
-/*
- * ua_stack_channel.c
- *
- *  Created on: 09.05.2014
- *      Author: root
- */
-
 #include "ua_stack_channel.h"
 #include <time.h>
 #include <stdlib.h>
@@ -46,8 +39,8 @@ UA_Int32 SL_Channel_setRemoteSecuritySettings(SL_Channel *channel,
 	channel->requestId = sequenceHeader->requestId;
 	return retval;
 }
-/*
-UA_Int32 SL_Channel_initLocalSecuritySettings(SL_Channel *channel)
+
+/* UA_Int32 SL_Channel_initLocalSecuritySettings(SL_Channel *channel)
 {
 	UA_Int32 retval = UA_SUCCESS;
 	channel->localAsymAlgSettings.receiverCertificateThumbprint.data = UA_NULL;
@@ -58,8 +51,8 @@ UA_Int32 SL_Channel_initLocalSecuritySettings(SL_Channel *channel)
 	channel->localAsymAlgSettings.senderCertificate.data = UA_NULL;
 	channel->localAsymAlgSettings.senderCertificate.length = 0;
 	return retval;
-}
-*/
+} */
+
 UA_Int32 SL_Channel_new(SL_Channel **channel) {
 	UA_Int32 retval = UA_SUCCESS;
 	retval |= UA_alloc((void** )channel, sizeof(SL_Channel));
@@ -117,9 +110,7 @@ UA_Int32 SL_Channel_registerTokenProvider(SL_Channel *channel,
 
 UA_Int32 SL_Channel_getRemainingLifetime(SL_Channel *channel, UA_Int32 *lifetime) {
 	if (channel) {
-		UA_Int64 diffInMS =
-				(channel->securityToken.createdAt
-						- UA_DateTime_now()) / 1e7;
+		UA_Int64 diffInMS = (channel->securityToken.createdAt - UA_DateTime_now()) / 1e7;
 		if (diffInMS > UA_INT32_MAX) {
 			*lifetime = UA_INT32_MAX;
 		} else {
@@ -180,6 +171,7 @@ UA_Int32 SL_Channel_getConnection(SL_Channel *channel,
 	}
 	return UA_ERROR;
 }
+
 UA_Int32 SL_Channel_getRequestId(SL_Channel *channel, UA_UInt32 *requestId) {
 	if (channel) {
 		*requestId = channel->requestId;
@@ -187,6 +179,7 @@ UA_Int32 SL_Channel_getRequestId(SL_Channel *channel, UA_UInt32 *requestId) {
 	}
 	return UA_ERROR;
 }
+
 UA_Int32 SL_Channel_getSequenceNumber(SL_Channel *channel,
 		UA_UInt32 *sequenceNumber) {
 	if (channel) {
@@ -195,6 +188,7 @@ UA_Int32 SL_Channel_getSequenceNumber(SL_Channel *channel,
 	}
 	return UA_ERROR;
 }
+
 UA_Int32 SL_Channel_getState(SL_Channel *channel, SL_channelState *channelState) {
 	if (channel) {
 		*channelState = channel->state;
@@ -203,14 +197,12 @@ UA_Int32 SL_Channel_getState(SL_Channel *channel, SL_channelState *channelState)
 	return UA_ERROR;
 }
 
-UA_Int32 SL_Channel_getRevisedLifetime(SL_Channel *channel,
-		UA_UInt32 *revisedLifetime) {
-	if (channel) {
-		*revisedLifetime =
-				channel->securityToken.revisedLifetime;
-		return UA_SUCCESS;
-	}
-	return UA_ERROR;
+UA_Int32 SL_Channel_getRevisedLifetime(SL_Channel *channel, UA_UInt32 *revisedLifetime) {
+	if(!channel)
+		return UA_ERROR;
+
+	*revisedLifetime = channel->securityToken.revisedLifetime;
+	return UA_SUCCESS;
 }
 
 //setters
@@ -228,32 +220,25 @@ UA_Int32 SL_Channel_setState(SL_Channel *channel, SL_channelState channelState)
 
 
 UA_Boolean SL_Channel_compare(SL_Channel *channel1, SL_Channel *channel2) {
-	return (((SL_Channel*) channel1)->channelId
-			== ((SL_Channel*) channel2)->channelId) ?
-	UA_TRUE :
-															UA_FALSE;
+	return (((SL_Channel*) channel1)->channelId == ((SL_Channel*) channel2)->channelId) ?
+			UA_TRUE : UA_FALSE;
 }
 
 UA_Int32 SL_Channel_bind(SL_Channel *channel, UA_TL_Connection *connection) {
-	if (channel && connection) {
-		channel->connection = connection;
-		return UA_SUCCESS;
-	}
-	return UA_ERROR;
+	if (!channel || !connection)
+		return UA_ERROR;
+
+	channel->connection = connection;
+	return UA_SUCCESS;
 }
 
 UA_Int32 SL_Channel_deleteMembers(SL_Channel *channel) {
 	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_AsymmetricAlgorithmSecurityHeader_deleteMembers(
-			&channel->localAsymAlgSettings);
-	retval |= UA_ByteString_deleteMembers(
-			&channel->localNonce);
-	retval |= UA_AsymmetricAlgorithmSecurityHeader_deleteMembers(
-			&channel->remoteAsymAlgSettings);
-	retval |= UA_ByteString_deleteMembers(
-			&channel->remoteNonce);
-	retval |= UA_ChannelSecurityToken_deleteMembers(
-			&channel->securityToken);
+	retval |= UA_AsymmetricAlgorithmSecurityHeader_deleteMembers(&channel->localAsymAlgSettings);
+	retval |= UA_ByteString_deleteMembers(&channel->localNonce);
+	retval |= UA_AsymmetricAlgorithmSecurityHeader_deleteMembers(&channel->remoteAsymAlgSettings);
+	retval |= UA_ByteString_deleteMembers(&channel->remoteNonce);
+	retval |= UA_ChannelSecurityToken_deleteMembers(&channel->securityToken);
 	return retval;
 }
 UA_Int32 SL_Channel_delete(SL_Channel *channel) {
@@ -263,14 +248,9 @@ UA_Int32 SL_Channel_delete(SL_Channel *channel) {
 	return retval;
 }
 
-UA_Int32 SL_Channel_processTokenRequest(SL_Channel *channel,
-		UA_UInt32 requestedLifetime, UA_SecurityTokenRequestType requestType) {
-	if (channel->tokenProvider) {
-		return channel->tokenProvider(channel,
-				requestedLifetime, requestType,
-				&channel->securityToken);
-
-	}
+UA_Int32 SL_Channel_processTokenRequest(SL_Channel *channel, UA_UInt32 requestedLifetime, UA_SecurityTokenRequestType requestType) {
+	if (channel->tokenProvider)
+		return channel->tokenProvider(channel, requestedLifetime, requestType, &channel->securityToken);
 	printf("SL_Channel_processTokenRequest - no Token provider registered");
 	return UA_ERROR;
 }
@@ -278,21 +258,17 @@ UA_Int32 SL_Channel_renewToken(SL_Channel *channel, UA_UInt32 tokenId,
 		UA_DateTime revisedLifetime, UA_DateTime createdAt) {
 	channel->securityToken.tokenId = tokenId;
 	channel->securityToken.createdAt = createdAt;
-	channel->securityToken.revisedLifetime =
-			revisedLifetime;
+	channel->securityToken.revisedLifetime = revisedLifetime;
 	return UA_SUCCESS;
 }
 
-UA_Int32 SL_Channel_checkSequenceNumber(SL_Channel *channel,
-		UA_UInt32 sequenceNumber) {
+UA_Int32 SL_Channel_checkSequenceNumber(SL_Channel *channel, UA_UInt32 sequenceNumber) {
 	//TODO review checking of sequence
 	if (channel->sequenceNumber+1  == sequenceNumber) {
 		channel->sequenceNumber++;
-
 		return UA_SUCCESS;
 	}
-	printf(
-			"SL_Channel_checkSequenceNumber - ERROR, wrong SequenceNumber expected: %i, received: %i",
+	printf("SL_Channel_checkSequenceNumber - ERROR, wrong SequenceNumber expected: %i, received: %i",
 			channel->sequenceNumber + 1, sequenceNumber);
 	return UA_ERROR;
 
@@ -302,26 +278,20 @@ UA_Int32 SL_Channel_checkRequestId(SL_Channel *channel, UA_UInt32 requestId) {
 	//TODO review checking of request id
 	if (channel->requestId+1  == requestId) {
 		channel->requestId++;
-
 		return UA_SUCCESS;
 	}
-	printf(
-			"SL_Channel_requestId - ERROR, wrong requestId expected: %i, received: %i",
+	printf("SL_Channel_requestId - ERROR, wrong requestId expected: %i, received: %i",
 			channel->requestId + 1, requestId);
 	return UA_ERROR;
-
 }
 
-UA_Int32 SL_Channel_processOpenRequest(SL_Channel *channel,
-		const UA_OpenSecureChannelRequest* request,
-		UA_OpenSecureChannelResponse* response) {
+UA_Int32 SL_Channel_processOpenRequest(SL_Channel *channel, const UA_OpenSecureChannelRequest* request,
+									   UA_OpenSecureChannelResponse* response) {
 	UA_UInt32 protocolVersion;
 	SL_Channel* thisChannel = channel;
 	UA_Int32 retval = UA_SUCCESS;
 
-	UA_TL_Connection_getProtocolVersion(thisChannel->connection,
-			&protocolVersion);
-
+	UA_TL_Connection_getProtocolVersion(thisChannel->connection, &protocolVersion);
 
 	if (request->clientProtocolVersion != protocolVersion) {
 		printf("SL_Channel_processOpenRequest - error protocol version \n");
@@ -398,10 +368,7 @@ UA_Int32 SL_Channel_processOpenRequest(SL_Channel *channel,
 	}
 
 	response->serverProtocolVersion = protocolVersion;
-
-	UA_ChannelSecurityToken_copy(&channel->securityToken,
-			&(response->securityToken));
-
+	UA_ChannelSecurityToken_copy(&channel->securityToken, &(response->securityToken));
 	UA_ByteString_copy(&thisChannel->localNonce, &response->serverNonce);
 
 	return retval;

+ 14 - 31
src/ua_stack_channel.h

@@ -1,10 +1,3 @@
-/*
- * ua_stack_channel.h
- *
- *  Created on: 09.05.2014
- *      Author: root
- */
-
 #ifndef UA_STACK_CHANNEL_H_
 #define UA_STACK_CHANNEL_H_
 
@@ -24,9 +17,8 @@ typedef enum ChannelState {
 struct SL_Channel;
 typedef struct SL_Channel SL_Channel;
 
-
 typedef UA_Int32 (*SL_ChannelSecurityTokenProvider)(SL_Channel*, UA_Int32,
-		SecurityTokenRequestType, UA_ChannelSecurityToken*);
+		         SecurityTokenRequestType, UA_ChannelSecurityToken*);
 typedef UA_Int32 (*SL_ChannelIdProvider)(UA_UInt32*);
 UA_Int32 SL_Channel_new(SL_Channel **channel);
 
@@ -38,43 +30,34 @@ UA_Int32 SL_Channel_bind(SL_Channel *channel, UA_TL_Connection *connection);
 UA_Int32 SL_Channel_setRemoteSecuritySettings(SL_Channel *channel,
 		UA_AsymmetricAlgorithmSecurityHeader *asymSecHeader,
 		UA_SequenceHeader *sequenceHeader);
-UA_Int32 SL_Channel_initLocalSecuritySettings(SL_Channel *channel);
 
+UA_Int32 SL_Channel_initLocalSecuritySettings(SL_Channel *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_Channel *channel,
-		const UA_CloseSecureChannelRequest* request);
-UA_Int32 SL_Channel_registerTokenProvider(SL_Channel *channel,
-		SL_ChannelSecurityTokenProvider provider);
+
+UA_Int32 SL_Channel_processOpenRequest(SL_Channel *channel, const UA_OpenSecureChannelRequest* request,
+									   UA_OpenSecureChannelResponse* response);
+UA_Int32 SL_Channel_processCloseRequest(SL_Channel *channel, const UA_CloseSecureChannelRequest* request);
+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_Channel *channel, UA_UInt32 requestId);
-
-UA_Int32 SL_Channel_checkSequenceNumber(SL_Channel *channel,
-		UA_UInt32 sequenceNumber);
+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_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_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_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_Channel *channel,
-		UA_UInt32 *revisedLifetime);
+UA_Int32 SL_Channel_getRemainingLifetime(SL_Channel *channel, UA_Int32 *lifetime);
+UA_Int32 SL_Channel_getRevisedLifetime(SL_Channel *channel, UA_UInt32 *revisedLifetime);
 
 //setters
 UA_Int32 SL_Channel_setId(SL_Channel *channel, UA_UInt32 id);

+ 26 - 54
src/ua_stack_channel_manager.c

@@ -1,11 +1,3 @@
-/*
- * ua_stack_channel_manager.c
- *
- *  Created on: 09.05.2014
- *      Author: root
- */
-
-
 #include "ua_stack_channel_manager.h"
 
 struct SL_ChannelManager {
@@ -18,10 +10,11 @@ struct SL_ChannelManager {
 	UA_DateTime channelLifeTime;
 	UA_UInt32 lastTokenId;
 };
+
 static SL_ChannelManager *channelManager;
 
-UA_Int32 SL_ChannelManager_init(UA_UInt32 maxChannelCount,UA_UInt32 tokenLifetime, UA_UInt32 startChannelId, UA_UInt32 startTokenId, UA_String *endpointUrl)
-{
+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));
 	UA_list_init(&(channelManager->channels));
 	channelManager->lastChannelId = startChannelId;
@@ -33,81 +26,63 @@ UA_Int32 SL_ChannelManager_init(UA_UInt32 maxChannelCount,UA_UInt32 tokenLifetim
 	return UA_SUCCESS;
 }
 
-UA_Int32 SL_ChannelManager_addChannel(SL_Channel *channel)
-{
-	if (channelManager && (channelManager->maxChannelCount > channelManager->channels.size))
-	{
-
-//TODO lock access (mulitthreading)------------
-		UA_list_addPayloadToBack(&channelManager->channels,(void*)channel);
-		return UA_SUCCESS;
-
-//TODO lock access------------
-	}
-	return UA_ERROR;
+UA_Int32 SL_ChannelManager_addChannel(SL_Channel *channel) {
+	if (!channelManager || (channelManager->maxChannelCount <= channelManager->channels.size))
+		return UA_ERROR;
 
+	//TODO lock access (mulitthreading)------------
+	UA_list_addPayloadToBack(&channelManager->channels,(void*)channel);
+	return UA_SUCCESS;
+	//TODO lock access------------
 }
 
-UA_Int32 generateNewTokenId()
-{
+UA_Int32 generateNewTokenId() {
 	//TODO lock accesss
 	return channelManager->lastTokenId++;
 }
 
-UA_Int32 SL_ChannelManager_generateChannelId(UA_UInt32 *newChannelId)
-{
-	if(channelManager)
-	{
+UA_Int32 SL_ChannelManager_generateChannelId(UA_UInt32 *newChannelId) {
+	if(channelManager) {
 		*newChannelId = channelManager->lastChannelId++;
 		return UA_SUCCESS;
 	}
 	return UA_ERROR;
 }
 
-UA_UInt32 SL_ChannelManager_generateNewTokenId()
-{
+UA_UInt32 SL_ChannelManager_generateNewTokenId() {
 	return channelManager->lastTokenId++;
 }
 
 UA_Int32 SL_ChannelManager_generateToken(SL_Channel *channel, UA_Int32 requestedLifeTime,
 		SecurityTokenRequestType requestType,
-		UA_ChannelSecurityToken* newToken)
-{
+		UA_ChannelSecurityToken* newToken) {
 	UA_UInt32 tokenId;
 	if(channel){
 		SL_Channel_getTokenId(channel,&tokenId);
-		if(requestType==UA_SECURITYTOKEN_ISSUE)
-		{
+		if(requestType==UA_SECURITYTOKEN_ISSUE) {
 			SL_Channel_getChannelId(channel,&newToken->channelId);
 			newToken->createdAt = UA_DateTime_now();
 			newToken->revisedLifetime = requestedLifeTime > channelManager->maxChannelLifeTime ? channelManager->maxChannelLifeTime : requestedLifeTime;
 			newToken->tokenId = SL_ChannelManager_generateNewTokenId();
 			return UA_SUCCESS;
-		}
-		else if(requestType==UA_SECURITYTOKEN_RENEW)
-		{
+		} else if(requestType==UA_SECURITYTOKEN_RENEW) {
 			SL_Channel_getChannelId(channel,&newToken->channelId);
 			newToken->createdAt = UA_DateTime_now();
 			newToken->revisedLifetime = requestedLifeTime > channelManager->maxChannelLifeTime ? channelManager->maxChannelLifeTime : requestedLifeTime;
 			return UA_SUCCESS;
 		}
-		else
-		{
-			return UA_ERROR;
-		}
 	}
 	return UA_ERROR;
 }
 
-UA_Int32 SL_ChannelManager_removeChannel(UA_Int32 channelId)
-{
+UA_Int32 SL_ChannelManager_removeChannel(UA_Int32 channelId) {
 	//TODO lock access
 	SL_Channel *channel;
 	UA_Int32 retval = UA_SUCCESS;
 	SL_ChannelManager_getChannel(channelId, &channel);
 
 	UA_list_Element *element =  UA_list_search(&channelManager->channels, (UA_list_PayloadComparer)SL_Channel_compare, &channel);
-	if(element){
+	if(element) {
 		retval |= UA_list_removeElement(element,(UA_list_PayloadVisitor)SL_Channel_delete);
 		return retval;
 	}
@@ -115,8 +90,8 @@ UA_Int32 SL_ChannelManager_removeChannel(UA_Int32 channelId)
 
 	return UA_ERROR;
 }
-UA_Int32 SL_ChannelManager_getChannelLifeTime(UA_DateTime *lifeTime)
-{
+
+UA_Int32 SL_ChannelManager_getChannelLifeTime(UA_DateTime *lifeTime) {
 	*lifeTime = channelManager->channelLifeTime;
 	return UA_SUCCESS;
 }
@@ -127,25 +102,22 @@ UA_Int32 SL_ChannelManager_getChannelLifeTime(UA_DateTime *lifeTime)
 	return UA_SUCCESS;UA_list_Element
 }
 */
-UA_Int32 SL_ChannelManager_getChannel(UA_UInt32 channelId, SL_Channel **channel)
-{
+
+UA_Int32 SL_ChannelManager_getChannel(UA_UInt32 channelId, SL_Channel **channel) {
 	UA_UInt32 tmpChannelId;
 	if(channelManager==UA_NULL){
 		*channel = UA_NULL;
 		return UA_ERROR;
 	}
+
  	UA_list_Element* current = channelManager->channels.first;
-	while (current)
-	{
-		if (current->payload)
-		{
+	while (current) {
+		if (current->payload) {
 			UA_list_Element* elem = (UA_list_Element*) current;
 			*channel = ((SL_Channel*) (elem->payload));
 			SL_Channel_getChannelId(*channel, &tmpChannelId);
 		 	if(tmpChannelId == channelId)
-		 	{
 		 		return UA_SUCCESS;
-		 	}
 		}
 		current = current->next;
 	}

+ 0 - 12
src/ua_stack_channel_manager.h

@@ -1,22 +1,11 @@
-/*
- * ua_stack_channel_manager.h
- *
- *  Created on: 09.05.2014
- *      Author: root
- */
-
 #ifndef UA_STACK_CHANNEL_MANAGER_H_
 #define UA_STACK_CHANNEL_MANAGER_H_
 
 #include "ua_stack_channel.h"
 
-
-
-
 struct SL_ChannelManager;
 typedef struct SL_ChannelManager SL_ChannelManager;
 
-
 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_Channel *channel);
 UA_Int32 SL_ChannelManager_removeChannel(UA_Int32 channelId);
@@ -25,5 +14,4 @@ UA_Int32 SL_ChannelManager_getChannelLifeTime(UA_DateTime *lifeTime);
 UA_Int32 SL_ChannelManager_generateToken(SL_Channel *channel, UA_Int32 requestedLifeTime, SecurityTokenRequestType requestType, UA_ChannelSecurityToken* newToken);
 UA_Int32 SL_ChannelManager_generateChannelId(UA_UInt32 *newChannelId);
 
-
 #endif /* UA_STACK_CHANNEL_MANAGER_H_ */

+ 72 - 103
src/ua_stack_session.c

@@ -8,8 +8,7 @@
 #include <stdlib.h>
 
 #include "ua_stack_session.h"
-struct UA_Session
-{
+struct UA_Session {
 	UA_NodeId authenticationToken;
 	UA_NodeId sessionId;
 	UA_String name;
@@ -20,12 +19,10 @@ struct UA_Session
 	UA_UInt32 maxResponseMessageSize;
 	UA_Int64 timeout;
 	UA_DateTime validTill;
-
 };
 
 /* mock up function to generate tokens for authentication */
-UA_Int32 UA_Session_generateToken(UA_NodeId *newToken)
-{
+UA_Int32 UA_Session_generateToken(UA_NodeId *newToken) {
 	//Random token generation
 	UA_Int32 retval = UA_SUCCESS;
 	srand(time(NULL));
@@ -44,55 +41,48 @@ UA_Int32 UA_Session_generateToken(UA_NodeId *newToken)
 	UA_Int32 r2 = r1 && 0xFFFF;
 	r2 = r2 * 1;
 	newToken->identifier.guid.data3 = (UA_UInt16)((r>>16) );
-	for(i=0;i<8;i++)
-	{
+	for(i=0;i<8;i++) {
 		r = rand();
 		newToken->identifier.guid.data4[i] = (UA_Byte)((r>>28) );
 	}
-
-
 	return retval;
 }
 
-UA_Int32 UA_Session_bind(UA_Session *session, SL_Channel *channel)
-{
+UA_Int32 UA_Session_bind(UA_Session *session, SL_Channel *channel) {
+	if(!channel || !session)
+		return UA_ERROR;
 
-	if(channel && session)
-	{
-		session->channel = channel;
-		return UA_SUCCESS;
-	}
-	return UA_ERROR;
+	session->channel = channel;
+	return UA_SUCCESS;
 }
 
-UA_Int32 UA_Session_new(UA_Session **newSession)
-{
+UA_Int32 UA_Session_new(UA_Session **newSession) {
 	UA_Int32 retval = UA_SUCCESS;
 	UA_Session *session;
 
 	retval |= UA_alloc((void**)&session,sizeof(UA_Session));
-
 	retval |= UA_alloc((void**)session,sizeof(UA_Session));
 	*newSession = session;
 	**newSession = *session;
 	//get memory for request list
 	return retval;
 }
-UA_Int32 UA_Session_deleteMembers(UA_Session *session)
-{
+
+UA_Int32 UA_Session_deleteMembers(UA_Session *session) {
 	UA_Int32 retval = UA_SUCCESS;
 	retval |= UA_NodeId_deleteMembers(&session->authenticationToken);
 	retval |= UA_String_deleteMembers(&session->name);
 	retval |= UA_NodeId_deleteMembers(&session->sessionId);
 	return retval;
 }
-UA_Int32 UA_Session_delete(UA_Session *session)
-{
+
+UA_Int32 UA_Session_delete(UA_Session *session) {
 	UA_Int32 retval = UA_SUCCESS;
 	UA_Session_deleteMembers(session);
 	retval |= UA_free(session);
 	return retval;
 }
+
 UA_Int32 UA_Session_init(UA_Session *session, UA_String *sessionName, UA_Double requestedSessionTimeout,
 		UA_UInt32 maxRequestMessageSize,
 		UA_UInt32 maxResponseMessageSize,
@@ -112,109 +102,88 @@ UA_Int32 UA_Session_init(UA_Session *session, UA_String *sessionName, UA_Double
 	return retval;
 }
 
-UA_Boolean UA_Session_compare(UA_Session *session1, UA_Session *session2)
-{
-	if(session1 && session2){
-
-		if (UA_NodeId_equal(&session1->sessionId,
-				&session2->sessionId) == UA_EQUAL){
+UA_Boolean UA_Session_compare(UA_Session *session1, UA_Session *session2) {
+	if(session1 && session2) {
+		if (UA_NodeId_equal(&session1->sessionId, &session2->sessionId) == UA_EQUAL) {
 			return UA_TRUE;
 		}
 	}
 	return UA_FALSE;
 }
 
-UA_Boolean UA_Session_compareByToken(UA_Session *session, UA_NodeId *token)
-{
-	if(session && token){
+UA_Boolean UA_Session_compareByToken(UA_Session *session, UA_NodeId *token) {
+	if(session && token) {
 		return UA_NodeId_equal(&session->authenticationToken, token);
 	}
 	return UA_NOT_EQUAL;
 }
 
-UA_Boolean UA_Session_compareById(UA_Session *session, UA_NodeId *sessionId)
-{
-	if(session && sessionId){
+UA_Boolean UA_Session_compareById(UA_Session *session, UA_NodeId *sessionId) {
+	if(session && sessionId) {
 		return UA_NodeId_equal(&session->sessionId, sessionId);
 	}
 	return UA_NOT_EQUAL;
 }
 
-UA_Int32 UA_Session_getId(UA_Session *session, UA_NodeId *sessionId)
-{
-	if(session)
-	{
-		return UA_NodeId_copy(&session->sessionId, sessionId);
-	}
-	return UA_ERROR;
+UA_Int32 UA_Session_getId(UA_Session *session, UA_NodeId *sessionId) {
+	if(!session)
+		return UA_ERROR;
+	return UA_NodeId_copy(&session->sessionId, sessionId);
 }
 
-UA_Int32 UA_Session_getToken(UA_Session *session, UA_NodeId *authenticationToken)
-{
-	if(session)
-	{
-		return UA_NodeId_copy(&session->authenticationToken, authenticationToken);
-	}
-	return UA_ERROR;
-}
-UA_Int32 UA_Session_updateLifetime(UA_Session *session)
-{
-	if(session)
-	{
-		session->validTill = UA_DateTime_now() +
-				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)
-	{
-		*channel = session->channel;
-		return UA_SUCCESS;
-	}
-	return UA_ERROR;
-}
-UA_Int32 UA_Session_getPendingLifetime(UA_Session *session, UA_Double *pendingLifetime_ms)
-{
-	if(session)
-	{
-		*pendingLifetime_ms = (session->validTill- UA_DateTime_now() ) / 10000000; //difference in ms
-		return UA_SUCCESS;
-	}
-	return UA_ERROR;
+UA_Int32 UA_Session_getToken(UA_Session *session, UA_NodeId *authenticationToken) {
+	if(!session)
+		return UA_ERROR;
+	return UA_NodeId_copy(&session->authenticationToken, authenticationToken);
 }
 
-UA_Boolean UA_Session_verifyChannel(UA_Session *session, SL_Channel *channel)
-{
-	if(session && channel)
-	{
-		if(SL_Channel_compare(session->channel, channel) == UA_TRUE) {
-				return UA_TRUE;
-		}
-	}
-	return UA_FALSE;
+UA_Int32 UA_Session_updateLifetime(UA_Session *session) {
+	if(!session)
+		return UA_ERROR;
+
+	session->validTill = UA_DateTime_now() + session->timeout * 100000; //timeout in ms
+	return UA_SUCCESS;
 }
-UA_Int32 UA_Session_getApplicationPointer(UA_Session *session, Application** application)
-{
-	if(session)
-	{
-		*application = session->application;
-		return UA_SUCCESS;
-	}
-	*application = UA_NULL;
-	return UA_ERROR;
+
+UA_Int32 UA_Session_getChannel(UA_Session *session, SL_Channel **channel) {
+	if(!session)
+		return UA_ERROR;
+
+	*channel = session->channel;
+	return UA_SUCCESS;
+}
+
+UA_Int32 UA_Session_getPendingLifetime(UA_Session *session, UA_Double *pendingLifetime_ms) {
+	if(!session)
+		return UA_ERROR;
+
+	*pendingLifetime_ms = (session->validTill- UA_DateTime_now() ) / 10000000; //difference in ms
+	return UA_SUCCESS;
 }
 
-UA_Int32 UA_Session_setApplicationPointer(UA_Session *session, Application* application)
-{
-	if(session)
-	{
-		session->application = application;
-		return UA_SUCCESS;
+UA_Boolean UA_Session_verifyChannel(UA_Session *session, SL_Channel *channel) {
+	if(!session || !channel)
+		return UA_FALSE;
+
+	return SL_Channel_compare(session->channel, channel);
+}
+
+UA_Int32 UA_Session_getApplicationPointer(UA_Session *session, Application** application) {
+	if(!session) {
+		*application = UA_NULL;
+		return UA_ERROR;
 	}
-	return UA_ERROR;
+
+	*application = session->application;
+	return UA_SUCCESS;
+}
+
+UA_Int32 UA_Session_setApplicationPointer(UA_Session *session, Application* application) {
+	if(!session)
+		return UA_ERROR;
+
+	session->application = application;
+	return UA_SUCCESS;
 }
 
 

+ 15 - 9
src/ua_stack_session.h

@@ -1,25 +1,19 @@
-/*
- * ua_stack_session.h
- *
- *  Created on: 05.06.2014
- *      Author: root
- */
-
 #ifndef UA_STACK_SESSION_H_
 #define UA_STACK_SESSION_H_
 
-
 #include "ua_stack_channel.h"
 
 struct UA_Session;
 typedef struct UA_Session UA_Session;
 typedef UA_Int32(*UA_Session_idProvider)(UA_NodeId *newSessionId);
+
 /**
  * @brief creates a session object
  * @param newSession
  * @return error code
  */
 UA_Int32 UA_Session_new(UA_Session **newSession);
+
 /**
  * @brief inits a session object
  * @param session
@@ -36,7 +30,9 @@ UA_Int32 UA_Session_init(UA_Session *session, UA_String *sessionName, UA_Double
 		UA_UInt32 maxResponseMessageSize,
 		UA_Session_idProvider idProvider,
 		UA_Int64 timeout);
+
 UA_Int32 UA_Session_delete(UA_Session *session);
+
 /**
  * @brief compares two session objects
  * @param session1
@@ -44,6 +40,7 @@ UA_Int32 UA_Session_delete(UA_Session *session);
  * @return UA_TRUE if it is the same session, UA_FALSE else
  */
 UA_Boolean UA_Session_compare(UA_Session *session1, UA_Session *session2);
+
 /**
  * @brief compares two sessions by their authentication token
  * @param session
@@ -51,6 +48,7 @@ UA_Boolean UA_Session_compare(UA_Session *session1, UA_Session *session2);
  * @return UA_EQUAL if the session token matches the session UA_NOT_EQUAL
  */
 UA_Boolean UA_Session_compareByToken(UA_Session *session, UA_NodeId *token);
+
 /**
  * @brief compares two sessions by their session id
  * @param session
@@ -58,6 +56,7 @@ UA_Boolean UA_Session_compareByToken(UA_Session *session, UA_NodeId *token);
  * @return UA_EQUAL if the session identifier matches the session UA_NOT_EQUAL
  */
 UA_Boolean UA_Session_compareById(UA_Session *session, UA_NodeId *sessionId);
+
 /**
  * @brief binds a channel to a session
  * @param session
@@ -65,6 +64,7 @@ UA_Boolean UA_Session_compareById(UA_Session *session, UA_NodeId *sessionId);
  * @return error code
  */
 UA_Int32 UA_Session_bind(UA_Session *session, SL_Channel *channel);
+
 /**
  * @brief checks if the given channel is related to the session
  * @param session
@@ -72,12 +72,14 @@ UA_Int32 UA_Session_bind(UA_Session *session, SL_Channel *channel);
  * @return UA_TRUE if there is a relation between session and given channel
  */
 UA_Boolean UA_Session_verifyChannel(UA_Session *session, SL_Channel *channel);
+
 /**
  * @brief If any activity on a session happens, the timeout must be extended
  * @param session
  * @return error code
  */
 UA_Int32 UA_Session_updateLifetime(UA_Session *session);
+
 /**
  * @brief Gets the session identifier (UA_NodeId)
  * @param session session from which the identifier should be returned
@@ -85,6 +87,7 @@ UA_Int32 UA_Session_updateLifetime(UA_Session *session);
  * @return error code
  */
 UA_Int32 UA_Session_getId(UA_Session *session, UA_NodeId *sessionId);
+
 /**
  * @brief Gets the session authentication token
  * @param session session from which the token should be returned
@@ -92,6 +95,7 @@ UA_Int32 UA_Session_getId(UA_Session *session, UA_NodeId *sessionId);
  * @return error code
  */
 UA_Int32 UA_Session_getToken(UA_Session *session, UA_NodeId *authenticationToken);
+
 /**
  * @brief Gets the channel on which the session is currently running
  * @param session session from which the channel should be returned
@@ -99,6 +103,7 @@ UA_Int32 UA_Session_getToken(UA_Session *session, UA_NodeId *authenticationToken
  * @return
  */
 UA_Int32 UA_Session_getChannel(UA_Session *session, SL_Channel **channel);
+
 /**
  * @brief Gets the sessions pending lifetime (calculated from the timeout which was set)
  * @param session session from which the lifetime should be returned
@@ -106,6 +111,7 @@ UA_Int32 UA_Session_getChannel(UA_Session *session, SL_Channel **channel);
  * @return error code
  */
 UA_Int32 UA_Session_getPendingLifetime(UA_Session *session,UA_Double *pendingLifetime);
+
 /**
  * @brief Gets the pointer to the application
  * @param session session from which the application pointer should be returned
@@ -113,6 +119,7 @@ UA_Int32 UA_Session_getPendingLifetime(UA_Session *session,UA_Double *pendingLif
  * @return  error code
  */
 UA_Int32 UA_Session_getApplicationPointer(UA_Session *session, Application** application);
+
 /**
  * @brief Sets the application pointer to the application
  * @param session session of which the application pointer should be set
@@ -121,5 +128,4 @@ UA_Int32 UA_Session_getApplicationPointer(UA_Session *session, Application** app
  */
 UA_Int32 UA_Session_setApplicationPointer(UA_Session *session, Application* application);
 
-
 #endif /* UA_STACK_SESSION_H_ */

+ 30 - 63
src/ua_stack_session_manager.c

@@ -1,39 +1,26 @@
-/*
- * ua_stack_session_manager.c
- *
- *  Created on: 05.06.2014
- *      Author: root
- */
-
 #include "ua_stack_session_manager.h"
 
-
-struct UA_SessionManager
-{
+struct UA_SessionManager {
 	UA_list_List sessions;
 	UA_UInt32 maxSessionCount;
 	UA_Int32 lastSessionId;
 	UA_UInt32 currentSessionCount;
 	UA_DateTime maxSessionLifeTime;
-
 	UA_DateTime sessionTimeout;
 };
 
 static UA_SessionManager *sessionManager;
 
-UA_Int32 UA_SessionManager_generateSessionId(UA_NodeId *sessionId)
-{
+UA_Int32 UA_SessionManager_generateSessionId(UA_NodeId *sessionId) {
 	sessionId->nodeIdType = UA_NODEIDTYPE_NUMERIC;
 	sessionId->ns = 0;
 	sessionId->identifier.numeric = sessionManager->lastSessionId++;
 	return UA_SUCCESS;
 }
 
-UA_Int32 UA_SessionManager_init(UA_UInt32 maxSessionCount,UA_UInt32 sessionTimeout, 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_SessionManager));
-
 	retval |= UA_list_init(&sessionManager->sessions);
 	sessionManager->maxSessionCount = maxSessionCount;
 	sessionManager->lastSessionId = startSessionId;
@@ -41,21 +28,17 @@ UA_Int32 UA_SessionManager_init(UA_UInt32 maxSessionCount,UA_UInt32 sessionTimeo
 	return retval;
 }
 
-UA_Boolean UA_SessionManager_sessionExists(UA_Session *session)
-{
-
+UA_Boolean UA_SessionManager_sessionExists(UA_Session *session) {
 	if(sessionManager == UA_NULL)
-	{
 		return UA_FALSE;
-	}
 
-	if(UA_list_search(&sessionManager->sessions,(UA_list_PayloadComparer)UA_Session_compare,(void*)session))
-	{
+	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){
+
+		if(pendingLifetime>0)
 			return UA_TRUE;
-		}
+
 		//timeout of session reached so remove it
 		UA_NodeId sessionId;
 		UA_Session_getId(session,&sessionId);
@@ -64,27 +47,24 @@ UA_Boolean UA_SessionManager_sessionExists(UA_Session *session)
 	return UA_FALSE;
 }
 
-UA_Int32 UA_SessionManager_getSessionById(UA_NodeId *sessionId, UA_Session **session)
-{
-	if(sessionManager == UA_NULL)
-	{
+UA_Int32 UA_SessionManager_getSessionById(UA_NodeId *sessionId, UA_Session **session) {
+	if(sessionManager == UA_NULL) {
 		*session = UA_NULL;
 		return UA_ERROR;
 	}
 
 	UA_list_Element* current = sessionManager->sessions.first;
-	while (current)
-	{
-		if (current->payload)
-		{
+	while (current) {
+		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_Double pendingLifetime;
 				UA_Session_getPendingLifetime(*session, &pendingLifetime);
-				if(pendingLifetime > 0){
+
+				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;
@@ -97,28 +77,25 @@ UA_Int32 UA_SessionManager_getSessionById(UA_NodeId *sessionId, UA_Session **ses
 	return UA_ERROR;
 }
 
-UA_Int32 UA_SessionManager_getSessionByToken(UA_NodeId *token, UA_Session **session)
-{
-	if(sessionManager == UA_NULL)
-	{
+UA_Int32 UA_SessionManager_getSessionByToken(UA_NodeId *token, UA_Session **session) {
+	if(sessionManager == UA_NULL) {
 		*session = UA_NULL;
 		return UA_ERROR;
 	}
 
 	UA_list_Element* current = sessionManager->sessions.first;
-	while (current)
-	{
-		if (current->payload)
-		{
+	while (current) {
+		if (current->payload) {
 			UA_list_Element* elem = (UA_list_Element*) current;
 			*session = ((UA_Session*) (elem->payload));
 
-			if(UA_Session_compareByToken(*session,token) == UA_EQUAL){
+			if(UA_Session_compareByToken(*session,token) == UA_EQUAL) {
 				UA_Double pendingLifetime;
 				UA_Session_getPendingLifetime(*session, &pendingLifetime);
-				if(pendingLifetime > 0){
+
+				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;
@@ -131,15 +108,12 @@ UA_Int32 UA_SessionManager_getSessionByToken(UA_NodeId *token, UA_Session **sess
 	return UA_ERROR;
 }
 
-UA_Int32 UA_SessionManager_addSession(UA_Session *session)
-{
+UA_Int32 UA_SessionManager_addSession(UA_Session *session) {
 	UA_Int32 retval = UA_SUCCESS;
 	UA_NodeId sessionId;
-	if(!UA_SessionManager_sessionExists(session))
-	{
+	if(!UA_SessionManager_sessionExists(session)) {
 		retval |= UA_list_addPayloadToBack(&sessionManager->sessions,(void*)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);
 
@@ -147,19 +121,15 @@ UA_Int32 UA_SessionManager_addSession(UA_Session *session)
 	}
 	printf("UA_SessionManager_addSession - session already in list");
 	return UA_ERROR;
-
 }
 
-UA_Int32 UA_SessionManager_removeSession(UA_NodeId *sessionId)
-{
+UA_Int32 UA_SessionManager_removeSession(UA_NodeId *sessionId) {
 	UA_Int32 retval = UA_SUCCESS;
 	UA_list_Element *element = UA_list_search(&sessionManager->sessions,(UA_list_PayloadComparer)UA_Session_compare,sessionId);
-	if(element)
-	{
+	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;
 }
 /*
@@ -190,15 +160,12 @@ UA_Int32 UA_SessionManager_updateSessions()
 	return UA_SUCCESS;
 }
 */
-UA_Int32 UA_SessionManager_getSessionTimeout(UA_Int64 *timeout_ms)
-{
-	if(sessionManager)
-	{
+
+UA_Int32 UA_SessionManager_getSessionTimeout(UA_Int64 *timeout_ms) {
+	if(sessionManager) {
 		*timeout_ms = sessionManager->sessionTimeout;
 		return UA_SUCCESS;
 	}
 	*timeout_ms = 0;
 	return UA_ERROR;
 }
-
-

+ 1 - 21
src/ua_stack_session_manager.h

@@ -1,25 +1,11 @@
-/*
- * ua_stack_session_manager.h
- *
- *  Created on: 05.06.2014
- *      Author: root
- */
-
 #ifndef UA_STACK_SESSION_MANAGER_H_
 #define UA_STACK_SESSION_MANAGER_H_
 
-
-
 #include "ua_stack_session.h"
 
-
-
-//hide internal data of channelManager
 struct UA_SessionManager;
 typedef struct UA_SessionManager UA_SessionManager;
 
-//typedef struct UA_SessionManagerType *UA_SessionManager;
-
 /**
  * @brief initializes the session manager
  * @param maxSessionCount maximum amount of sessions which should be allowed to be created
@@ -27,8 +13,7 @@ typedef struct UA_SessionManager UA_SessionManager;
  * @param startSessionId the start id of the session identifiers, newer sessions get higher ids
  * @return error code
  */
-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
@@ -60,7 +45,6 @@ UA_Int32 UA_SessionManager_getSessionById(UA_NodeId *sessionId, UA_Session **ses
  */
 UA_Int32 UA_SessionManager_getSessionByToken(UA_NodeId *token, UA_Session **session);
 
-
 /**
  * @brief gets the session timeout value which should be assigned to
  * all sessions handled by the manager
@@ -69,12 +53,8 @@ UA_Int32 UA_SessionManager_getSessionByToken(UA_NodeId *token, UA_Session **sess
  */
 UA_Int32 UA_SessionManager_getSessionTimeout(UA_Int64 *timeout_ms);
 
-
 //UA_Int32 UA_SessionManager_updateSessions();
-
-
 //UA_Int32 UA_SessionManager_generateToken(UA_Session session, UA_Int32 requestedLifeTime, SecurityTokenRequestType requestType, UA_ChannelSecurityToken* newToken);
-
 UA_Int32 UA_SessionManager_generateSessionId(UA_NodeId *newSessionId);
 
 #endif /* UA_STACK_SESSION_MANAGER_H_ */

+ 2 - 2
src/ua_transport.h

@@ -12,14 +12,14 @@ typedef enum UA_ConnectionState {
 	CONNECTIONSTATE_OPENING,
 	CONNECTIONSTATE_ESTABLISHED,
 	CONNECTIONSTATE_CLOSE
-}UA_ConnectionState;
+} UA_ConnectionState;
 
 typedef struct Session {
 	UA_Int32 sessionId;
 	Application *application;
 } Session;
 
-typedef enum SecurityTokenRequestType{
+typedef enum SecurityTokenRequestType {
 	UA_SECURITYTOKEN_ISSUE = 0,
 	UA_SECURITYTOKEN_RENEW = 1
 } SecurityTokenRequestType;

+ 56 - 91
src/ua_transport_connection.c

@@ -1,13 +1,7 @@
-/*
- * ua_transport_connection.c
- *
- *  Created on: 10.05.2014
- *      Author: open62541
- */
-
 #include "ua_transport_connection.h"
 #include "ua_transport.h"
-struct UA_TL_Connection{
+
+struct UA_TL_Connection {
 	UA_Int32 connectionHandle;
 	UA_UInt32 state;
 	TL_Buffer localConf;
@@ -19,13 +13,11 @@ struct UA_TL_Connection{
 	void *networkLayerData;
 };
 
-
-UA_Int32 UA_TL_Connection_new(UA_TL_Connection **connection, TL_Buffer localBuffers,TL_Writer writer, TL_Closer closeCallback,UA_Int32 handle, void* networkLayerData)
-{
+UA_Int32 UA_TL_Connection_new(UA_TL_Connection **connection, TL_Buffer localBuffers,TL_Writer writer,
+		                      TL_Closer closeCallback,UA_Int32 handle, void* networkLayerData) {
 	UA_Int32 retval = UA_SUCCESS;
 	retval |= UA_alloc((void**)connection,sizeof(UA_TL_Connection));
-	if(retval == UA_SUCCESS)
-	{
+	if(retval == UA_SUCCESS) {
 		(*connection)->connectionHandle = handle;
 		(*connection)->localConf = localBuffers;
 		(*connection)->writer = writer;
@@ -36,35 +28,26 @@ UA_Int32 UA_TL_Connection_new(UA_TL_Connection **connection, TL_Buffer localBuff
 	return retval;
 }
 
-UA_Int32 UA_TL_Connection_delete(UA_TL_Connection *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_Connection *connection)
-{
+UA_Int32 UA_TL_Connection_close(UA_TL_Connection *connection) {
 	connection->state = CONNECTIONSTATE_CLOSED;
 	connection->closeCallback(connection);
 	return UA_SUCCESS;
 }
 
-UA_Boolean UA_TL_Connection_compare(UA_TL_Connection *connection1, UA_TL_Connection *connection2)
-{
-	if(connection1 && connection2)
-	{
-		if ((*(UA_TL_Connection**)connection1)->connectionHandle == (*(UA_TL_Connection**)connection2)->connectionHandle)
-		{
-			return UA_TRUE;
-		}
-	}
-	return UA_FALSE;
+UA_Boolean UA_TL_Connection_compare(UA_TL_Connection *connection1, UA_TL_Connection *connection2) {
+	if(!connection1 || !connection2)
+		return UA_FALSE;
+	return ((*(UA_TL_Connection**)connection1)->connectionHandle == (*(UA_TL_Connection**)connection2)->connectionHandle);
 }
 
 
-UA_Int32 UA_TL_Connection_configByHello(UA_TL_Connection *connection, UA_OPCUATcpHelloMessage *helloMessage)
-{
+UA_Int32 UA_TL_Connection_configByHello(UA_TL_Connection *connection, UA_OPCUATcpHelloMessage *helloMessage) {
 	UA_Int32 retval = UA_SUCCESS;
 	connection->remoteConf.maxChunkCount = helloMessage->maxChunkCount;
 	connection->remoteConf.maxMessageSize = helloMessage->maxMessageSize;
@@ -77,102 +60,84 @@ UA_Int32 UA_TL_Connection_configByHello(UA_TL_Connection *connection, UA_OPCUATc
 	return UA_SUCCESS;
 }
 
-UA_Int32 UA_TL_Connection_callWriter(UA_TL_Connection *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 connection->writer(connection->connectionHandle,gather_bufs, gather_len);
 }
 
 //setters
-UA_Int32 UA_TL_Connection_setWriter(UA_TL_Connection *connection, TL_Writer writer)
-{
+UA_Int32 UA_TL_Connection_setWriter(UA_TL_Connection *connection, TL_Writer writer) {
 	connection->writer = writer;
 	return UA_SUCCESS;
 }
-/*
-UA_Int32 UA_TL_Connection_setConnectionHandle(UA_TL_Connection *connection, UA_Int32 connectionHandle)
+
+/* UA_Int32 UA_TL_Connection_setConnectionHandle(UA_TL_Connection *connection, UA_Int32 connectionHandle)
 {
 	connection->connectionHandle = connectionHandle;
 	return UA_SUCCESS;
-}
-*/
-UA_Int32 UA_TL_Connection_setState(UA_TL_Connection *connection, UA_Int32 connectionState)
-{
-	if(connection)
-	{
-		connection->state = connectionState;
-		return UA_SUCCESS;
-	}else{
+} */
+
+UA_Int32 UA_TL_Connection_setState(UA_TL_Connection *connection, UA_Int32 connectionState) {
+	if(!connection)
 		return UA_ERROR;
-	}
+
+	connection->state = connectionState;
+	return UA_SUCCESS;
 }
+
 //getters
-UA_Int32 UA_TL_Connection_getState(UA_TL_Connection *connection, UA_Int32 *connectionState)
-{
-	if(connection)
-	{
-		*connectionState = connection->state;
-		return UA_SUCCESS;
-	}else{
+UA_Int32 UA_TL_Connection_getState(UA_TL_Connection *connection, UA_Int32 *connectionState) {
+	if(!connection) {
 		*connectionState = -1;
 		return UA_ERROR;
 	}
+
+	*connectionState = connection->state;
+	return UA_SUCCESS;
 }
 
-UA_Int32 UA_TL_Connection_getNetworkLayerData(UA_TL_Connection *connection,void** networkLayerData)
-{
-	if(connection)
-	{
-		*networkLayerData = connection->networkLayerData;
-		return UA_SUCCESS;
-	}else{
+UA_Int32 UA_TL_Connection_getNetworkLayerData(UA_TL_Connection *connection,void** networkLayerData) {
+	if(!connection) {
 		*networkLayerData = UA_NULL;
 		return UA_ERROR;
 	}
+
+	*networkLayerData = connection->networkLayerData;
+	return UA_SUCCESS;
 }
 
-UA_Int32 UA_TL_Connection_getProtocolVersion(UA_TL_Connection *connection, UA_UInt32 *protocolVersion)
-{
-	if(connection)
-	{
-		*protocolVersion = connection->localConf.protocolVersion;
-		return UA_SUCCESS;
-	}else{
+UA_Int32 UA_TL_Connection_getProtocolVersion(UA_TL_Connection *connection, UA_UInt32 *protocolVersion) {
+	if(!connection) {
 		*protocolVersion = 0xFF;
 		return UA_ERROR;
 	}
+
+	*protocolVersion = connection->localConf.protocolVersion;
+	return UA_SUCCESS;
 }
-UA_Int32 UA_TL_Connection_getLocalConfig(UA_TL_Connection *connection, TL_Buffer *localConfiguration)
-{
-	if(connection)
-	{
-		return UA_memcpy(localConfiguration,&connection->localConf, sizeof(TL_Buffer));
 
-	}else{
+UA_Int32 UA_TL_Connection_getLocalConfig(UA_TL_Connection *connection, TL_Buffer *localConfiguration) {
+	if(!connection) {
 		localConfiguration = UA_NULL;
 		return UA_ERROR;
 	}
-}
-UA_Int32 UA_TL_Connection_getHandle(UA_TL_Connection *connection, UA_UInt32 *connectionHandle)
-{
-	if(connection)
-	{
-		*connectionHandle = connection->connectionHandle;
-		return UA_SUCCESS;
-	}else{
-			connectionHandle = 0;
-			return UA_ERROR;
-		}
-}
 
-UA_Int32 UA_TL_Connection_bind(UA_TL_Connection *connection, UA_Int32 handle)
-{
-	if(connection)
-	{
-		connection->connectionHandle = handle;
-		return UA_SUCCESS;
-	}else{
+	return UA_memcpy(localConfiguration,&connection->localConf, sizeof(TL_Buffer));
+}
 
+UA_Int32 UA_TL_Connection_getHandle(UA_TL_Connection *connection, UA_UInt32 *connectionHandle) {
+	if(!connection) {
+		connectionHandle = 0;
 		return UA_ERROR;
 	}
 
+	*connectionHandle = connection->connectionHandle;
+	return UA_SUCCESS;
+}
+
+UA_Int32 UA_TL_Connection_bind(UA_TL_Connection *connection, UA_Int32 handle) {
+	if(!connection)
+		return UA_ERROR;
+
+	connection->connectionHandle = handle;
+	return UA_SUCCESS;
 }

+ 0 - 12
src/ua_transport_connection.h

@@ -1,14 +1,6 @@
-/*
- * ua_transport_connection.h
- *
- *  Created on: 10.05.2014
- *      Author: open62541
- */
-
 #ifndef UA_TRANSPORT_CONNECTION_H_
 #define UA_TRANSPORT_CONNECTION_H_
 
-
 #include "ua_transport.h"
 
 typedef struct TL_Buffer{
@@ -24,12 +16,9 @@ typedef struct UA_TL_Connection UA_TL_Connection;
 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_Connection *connection, UA_OPCUATcpHelloMessage *helloMessage);
-
 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_Connection *connection);
 UA_Int32 UA_TL_Connection_new(UA_TL_Connection **connection, TL_Buffer localBuffers,TL_Writer writer, TL_Closer closeCallback,UA_Int32 handle, void* networkLayerData);
 UA_Int32 UA_TL_Connection_bind(UA_TL_Connection *connection, UA_Int32 handle);
@@ -47,5 +36,4 @@ UA_Int32 UA_TL_Connection_getState(UA_TL_Connection *connection, UA_Int32 *conne
 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_ */

+ 19 - 36
src/ua_transport_connection_manager.c

@@ -8,75 +8,58 @@
 #include "ua_transport_connection_manager.h"
 #include "ua_indexedList.h"
 
-typedef struct UA_TL_ConnectionManager
-{
+typedef struct UA_TL_ConnectionManager {
 	UA_list_List connections;
 	UA_UInt32 maxConnectionCount;
 	UA_UInt32 currentConnectionCount;
-}UA_TL_ConnectionManager;
-
+} UA_TL_ConnectionManager;
 
 static UA_TL_ConnectionManager *connectionManager = UA_NULL;
 
-
-UA_Int32 UA_TL_ConnectionManager_init(UA_UInt32 maxConnectionCount)
-{
+UA_Int32 UA_TL_ConnectionManager_init(UA_UInt32 maxConnectionCount) {
 	UA_Int32 retval = UA_SUCCESS;
-	if(connectionManager == UA_NULL)
-	{
-		retval |= UA_alloc((void**)&connectionManager,sizeof(UA_TL_ConnectionManager));
-		connectionManager->maxConnectionCount = maxConnectionCount;
-		connectionManager->currentConnectionCount = 0;
-		retval |= UA_indexedList_init(&connectionManager->connections);
-		return UA_SUCCESS;
-	}
-	return UA_ERROR; //connection Manager already exists
+	if(connectionManager != UA_NULL)
+		return UA_ERROR; //connection Manager already exists
 
+	retval |= UA_alloc((void**)&connectionManager,sizeof(UA_TL_ConnectionManager));
+	connectionManager->maxConnectionCount = maxConnectionCount;
+	connectionManager->currentConnectionCount = 0;
+	retval |= UA_indexedList_init(&connectionManager->connections);
+	return UA_SUCCESS;
 }
-UA_Int32 UA_TL_ConnectionManager_addConnection(UA_TL_Connection *connection)
-{
+
+UA_Int32 UA_TL_ConnectionManager_addConnection(UA_TL_Connection *connection) {
 	UA_UInt32 connectionId;
 	UA_TL_Connection_getHandle(connection, &connectionId);
 	printf("UA_TL_ConnectionManager_addConnection - added connection with handle = %d \n", connectionId);
 	return UA_list_addPayloadToBack(&(connectionManager->connections), (void*)connection);
 }
 
-
-UA_Int32 UA_TL_ConnectionManager_removeConnection(UA_TL_Connection *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);
-
-	if(element)
-	{
+	if(element) {
 		UA_list_removeElement(element, (UA_list_PayloadVisitor)UA_TL_Connection_delete);
 	}
 	return UA_SUCCESS;
 }
 
-UA_Int32 UA_TL_ConnectionManager_getConnectionByHandle(UA_UInt32 connectionId, UA_TL_Connection **connection)
-{
+UA_Int32 UA_TL_ConnectionManager_getConnectionByHandle(UA_UInt32 connectionId, UA_TL_Connection **connection) {
 	UA_UInt32 tmpConnectionHandle;
-	if(connectionManager)
-	{
+	if(connectionManager) {
 		UA_list_Element* current = connectionManager->connections.first;
-		while (current)
-		{
-			if (current->payload)
-			{
+		while (current) {
+			if (current->payload) {
 				UA_list_Element* elem = (UA_list_Element*) current;
 				*connection = ((UA_TL_Connection*) (elem->payload));
 				UA_TL_Connection_getHandle(*connection, &tmpConnectionHandle);
 
 				if(tmpConnectionHandle == connectionId)
-				{
 					return UA_SUCCESS;
-				}
 			}
 			current = current->next;
 		}
 	}
+
 	*connection = UA_NULL;
 	return UA_ERROR;
 }
-
-

+ 2 - 8
src/ua_transport_connection_manager.h

@@ -1,19 +1,13 @@
-/*
- * ua_connection_manager.h
- *
- *  Created on: 11.05.2014
- *      Author: open62541
- */
-
 #ifndef UA_CONNECTION_MANAGER_H_
 #define UA_CONNECTION_MANAGER_H_
+
 #include "stdio.h"
 #include "ua_transport_connection.h"
 
-
 UA_Int32 UA_TL_ConnectionManager_init(UA_UInt32 maxConnectionCount);
 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_Connection **connection);