Julius Pfrommer 11 rokov pred
rodič
commit
55804dbd55

+ 23 - 23
examples/src/networklayer.c

@@ -20,9 +20,9 @@ NL_Description NL_Description_TcpBinary  = {
 	{-1,8192,8192,16384,1}
 };
 
-_Bool NL_connectionComparer(void *p1, void* p2) {
-	NL_connection* c1 = (NL_connection*) p1;
-	NL_connection* c2 = (NL_connection*) p2;
+_Bool NL_ConnectionComparer(void *p1, void* p2) {
+	NL_Connection* c1 = (NL_Connection*) p1;
+	NL_Connection* c2 = (NL_Connection*) p2;
 	return (c1->connection.connectionHandle == c2->connection.connectionHandle);
 }
 
@@ -40,14 +40,14 @@ int NL_TCP_SetNonBlocking(int sock) {
 	return 0;
 }
 
-void NL_connection_printf(void* payload) {
-  NL_connection* c = (NL_connection*) payload;
+void NL_Connection_printf(void* payload) {
+  NL_Connection* c = (NL_Connection*) payload;
   printf("ListElement connectionHandle = %d\n",c->connection.connectionHandle);
 }
 
 /** the tcp reader thread - single shot if single-threaded, looping until CLOSE if multi-threaded
  */
-void* NL_TCP_reader(NL_connection *c) {
+void* NL_TCP_reader(NL_Connection *c) {
 
 	UA_ByteString readBuffer;
 	UA_alloc((void**)&(readBuffer.data),c->connection.localConf.recvBufferSize);
@@ -62,7 +62,7 @@ void* NL_TCP_reader(NL_connection *c) {
 			UA_ByteString_printx("received=",&readBuffer);
 
 			if (readBuffer.length  > 0) {
-				TL_process(&(c->connection),&readBuffer);
+				TL_Process(&(c->connection),&readBuffer);
 			} else {
 				c->connection.connectionState = connectionState_CLOSE;
 				perror("ERROR reading from socket1");
@@ -79,17 +79,17 @@ void* NL_TCP_reader(NL_connection *c) {
 
 		UA_ByteString_deleteMembers(&readBuffer);
 		DBG_VERBOSE(printf("NL_TCP_reader - search element to remove\n"));
-		UA_list_Element* lec = UA_list_search(&(c->networkLayer->connections),NL_connectionComparer,c);
-		DBG_VERBOSE(printf("NL_TCP_reader - remove connection for handle=%d\n",((NL_connection*)lec->payload)->connection.connectionHandle));
+		UA_list_Element* lec = UA_list_search(&(c->networkLayer->connections),NL_ConnectionComparer,c);
+		DBG_VERBOSE(printf("NL_TCP_reader - remove connection for handle=%d\n",((NL_Connection*)lec->payload)->connection.connectionHandle));
 		UA_list_removeElement(lec,UA_NULL);
-		DBG_VERBOSE(UA_list_iteratePayload(&(c->networkLayer->connections),NL_connection_printf));
+		DBG_VERBOSE(UA_list_iteratePayload(&(c->networkLayer->connections),NL_Connection_printf));
 		UA_free(c);
 	}
 	return UA_NULL;
 }
 
 /** write to a tcp transport layer connection */
-UA_Int32 NL_TCP_writer(TL_connection* c, UA_ByteString** gather_buf, UA_UInt32 gather_len) {
+UA_Int32 NL_TCP_writer(TL_Connection* c, UA_ByteString** gather_buf, UA_UInt32 gather_len) {
 
 	struct iovec iov[gather_len];
 	UA_UInt32 total_len = 0;
@@ -127,14 +127,14 @@ UA_Int32 NL_TCP_writer(TL_connection* c, UA_ByteString** gather_buf, UA_UInt32 g
 	return UA_SUCCESS;
 }
 
-void* NL_Connection_init(NL_connection* c, NL_data* tld, UA_Int32 connectionHandle, NL_reader reader, TL_writer writer)
+void* NL_Connection_init(NL_Connection* c, NL_data* tld, UA_Int32 connectionHandle, NL_Reader reader, TL_Writer writer)
 {
 	// connection layer of UA stack
 	c->connection.connectionHandle = connectionHandle;
 	c->connection.connectionState = connectionState_CLOSED;
 	c->connection.writerCallback = writer;
-	memcpy(&(c->connection.localConf),&(tld->tld->localConf),sizeof(TL_buffer));
-	memset(&(c->connection.remoteConf),0,sizeof(TL_buffer));
+	memcpy(&(c->connection.localConf),&(tld->tld->localConf),sizeof(TL_Buffer));
+	memset(&(c->connection.remoteConf),0,sizeof(TL_Buffer));
 	UA_String_copy(&(tld->endpointUrl), &(c->connection.localEndpointUrl));
 
 	// network layer
@@ -150,7 +150,7 @@ void* NL_Connection_init(NL_connection* c, NL_data* tld, UA_Int32 connectionHand
 /** the tcp listener routine.
  *  does a single shot if single threaded, runs forever if multithreaded
  */
-void* NL_TCP_listen(NL_connection* c) {
+void* NL_TCP_listen(NL_Connection* c) {
 	NL_data* tld = c->networkLayer;
 
 	do {
@@ -174,10 +174,10 @@ void* NL_TCP_listen(NL_connection* c) {
 				perror("ERROR on accept");
 			} else {
 				DBG_VERBOSE(printf("NL_TCP_listen - new connection on %d\n",newsockfd));
-				NL_connection* cclient;
+				NL_Connection* cclient;
 				UA_Int32 retval = UA_SUCCESS;
-				retval |= UA_alloc((void**)&cclient,sizeof(NL_connection));
-				NL_Connection_init(cclient, tld, newsockfd, NL_TCP_reader, (TL_writer) NL_TCP_writer);
+				retval |= UA_alloc((void**)&cclient,sizeof(NL_Connection));
+				NL_Connection_init(cclient, tld, newsockfd, NL_TCP_reader, (TL_Writer) NL_TCP_writer);
 				UA_list_addPayloadToBack(&(tld->connections),cclient);
 #ifdef MULTITHREADING
 					pthread_create( &(cclient->readerThreadHandle), NULL, (void*(*)(void*)) NL_TCP_reader, (void*) cclient);
@@ -198,11 +198,11 @@ void NL_addHandleToSet(UA_Int32 handle, NL_data* nl) {
 	nl->maxReaderHandle = (handle > nl->maxReaderHandle) ? handle : nl->maxReaderHandle;
 }
 void NL_setFdSet(void* payload) {
-  NL_connection* c = (NL_connection*) payload;
+  NL_Connection* c = (NL_Connection*) payload;
   NL_addHandleToSet(c->connection.connectionHandle, c->networkLayer);
 }
 void NL_checkFdSet(void* payload) {
-  NL_connection* c = (NL_connection*) payload;
+  NL_Connection* c = (NL_Connection*) payload;
   if (FD_ISSET(c->connection.connectionHandle, &(c->networkLayer->readerHandles))) {
 	  c->reader((void*)c);
   }
@@ -283,10 +283,10 @@ UA_Int32 NL_TCP_init(NL_data* tld, UA_Int32 port) {
 	// finally
 	if (retval == UA_SUCCESS) {
 		DBG_VERBOSE(printf("NL_TCP_init - new listener on %d\n",newsockfd));
-		NL_connection* c;
+		NL_Connection* c;
 		UA_Int32 retval = UA_SUCCESS;
-		retval |= UA_alloc((void**)&c,sizeof(NL_connection));
-		NL_Connection_init(c, tld, newsockfd, NL_TCP_listen, (TL_writer) UA_NULL);
+		retval |= UA_alloc((void**)&c,sizeof(NL_Connection));
+		NL_Connection_init(c, tld, newsockfd, NL_TCP_listen, (TL_Writer) NL_TCP_writer);
 		UA_list_addPayloadToBack(&(tld->connections),c);
 #ifdef MULTITHREADING
 			pthread_create( &(c->readerThreadHandle), NULL, (void*(*)(void*)) NL_TCP_listen, (void*) c);

+ 7 - 7
examples/src/networklayer.h

@@ -27,7 +27,7 @@ typedef struct T_NL_Description {
 	UA_Int32 encoding;
 	UA_Int32 connectionType;
 	UA_Int32 maxConnections;
-	TL_buffer localConf;
+	TL_Buffer localConf;
 } NL_Description;
 
 extern NL_Description NL_Description_TcpBinary;
@@ -44,16 +44,16 @@ typedef struct T_NL_data {
 	int maxReaderHandle;
 } NL_data;
 
-struct T_NL_connection;
-typedef void* (*NL_reader)(struct T_NL_connection *c);
-typedef struct T_NL_connection {
-	TL_connection connection;
-	NL_reader reader;
+struct NL_Connection_T;
+typedef void* (*NL_Reader)(struct NL_Connection_T *c);
+typedef struct NL_Connection_T {
+	TL_Connection connection;
+	NL_Reader reader;
 #ifdef MULTITHREADING
 	pthread_t readerThreadHandle;
 #endif
 	NL_data* networkLayer;
-} NL_connection;
+} NL_Connection;
 
 NL_data* NL_init(NL_Description* tlDesc, UA_Int32 port);
 UA_Int32 NL_msgLoop(NL_data* nl, struct timeval* tv,UA_Int32 (*timeoutCallBack)(void*),void *arg);

+ 4 - 4
examples/src/opcuaServerACPLT.c

@@ -46,7 +46,7 @@ typedef struct T_Server {
 } Server;
 Server server;
 
-UA_Int32 server_writer(TL_connection* connection, UA_ByteString** gather_buf, UA_UInt32 gather_len) {
+UA_Int32 server_writer(TL_Connection* connection, UA_ByteString** gather_buf, UA_UInt32 gather_len) {
 	UA_UInt32 total_len = 0;
 	for(UA_UInt32 i=0;i<gather_len;i++) {
 		total_len += gather_buf[i]->length;
@@ -67,9 +67,9 @@ UA_Int32 server_writer(TL_connection* connection, UA_ByteString** gather_buf, UA
 }
 
 void server_run() {
-	TL_connection connection;
+	TL_Connection connection;
 	connection.connectionState = connectionState_CLOSE;
-	connection.writerCallback = (TL_writer)server_writer;
+	connection.writerCallback = (TL_Writer)server_writer;
 	connection.localConf.maxChunkCount = 1;
 	connection.localConf.maxMessageSize = BUFFER_SIZE;
 	connection.localConf.protocolVersion = 0;
@@ -133,7 +133,7 @@ void server_run() {
                 slMessage.data = (UA_Byte*) buffer;
 				slMessage.length = n;
 				UA_ByteString_printx("server_run - received=",&slMessage);
-				TL_process(&connection, &slMessage);
+				TL_Process(&connection, &slMessage);
 			} else if (n < 0) {
 				perror("ERROR reading from socket1");
 				exit(1);

+ 9 - 9
src/ua_transport_binary.c

@@ -3,7 +3,7 @@
 #include "ua_transport.h"
 #include "ua_transport_binary_secure.h"
 
-UA_Int32 TL_check(TL_connection* connection, UA_ByteString* msg) {
+static UA_Int32 TL_check(TL_Connection* connection, UA_ByteString* msg) {
 	if(msg->length > (UA_Int32) connection->localConf.maxMessageSize || msg->length > (UA_Int32) connection->remoteConf.maxMessageSize) {
 		DBG_ERR(printf("TL_check - length error \n"));
 		return UA_ERR_INCONSISTENT;
@@ -11,7 +11,7 @@ UA_Int32 TL_check(TL_connection* connection, UA_ByteString* msg) {
 	return UA_SUCCESS;
 }
 
-UA_Int32 TL_handleHello(TL_connection* connection, UA_ByteString* msg, UA_Int32* pos) {
+static UA_Int32 TL_handleHello(TL_Connection* connection, UA_ByteString* msg, UA_Int32* pos) {
 	UA_Int32 retval = UA_SUCCESS;
 
 	UA_Int32 tmpPos = 0;
@@ -60,7 +60,7 @@ UA_Int32 TL_handleHello(TL_connection* connection, UA_ByteString* msg, UA_Int32*
 		UA_OPCUATcpAcknowledgeMessage_encodeBinary(&ackMessage,&tmpPos,&tmpMessage);
 
 		DBG_VERBOSE(printf("TL_process - Size messageToSend = %d, pos=%d\n",ackHeader.messageSize, tmpPos));
-		TL_send(connection, &tmpMessage_ptr, 1);
+		TL_Send(connection, &tmpMessage_ptr, 1);
 		UA_ByteString_deleteMembers(&tmpMessage);
 	} else {
 		DBG_ERR(printf("TL_process - wrong connection state \n"));
@@ -69,25 +69,25 @@ UA_Int32 TL_handleHello(TL_connection* connection, UA_ByteString* msg, UA_Int32*
 	return retval;
 }
 
-UA_Int32 TL_handleOpen(TL_connection* connection, UA_ByteString* msg, UA_Int32* pos) {
+static UA_Int32 TL_handleOpen(TL_Connection* connection, UA_ByteString* msg, UA_Int32* pos) {
 	if (connection->connectionState == connectionState_ESTABLISHED) {
 		return SL_Channel_new(connection,msg,pos); // create new secure channel and associate with this TL connection
 	}
 	return UA_ERR_INVALID_VALUE;
 }
 
-UA_Int32 TL_handleMsg(TL_connection* connection, UA_ByteString* msg, UA_Int32* pos) {
+static UA_Int32 TL_handleMsg(TL_Connection* connection, UA_ByteString* msg, UA_Int32* pos) {
 	SL_Channel* slc = connection->secureChannel;
 	return SL_process(slc,msg,pos);
 }
 
-UA_Int32 TL_handleClo(TL_connection* connection, UA_ByteString* msg, UA_Int32* pos) {
+static UA_Int32 TL_handleClo(TL_Connection* connection, UA_ByteString* msg, UA_Int32* pos) {
 	SL_Channel* slc = connection->secureChannel;
 	connection->connectionState = connectionState_CLOSE;
 	return SL_process(slc,msg,pos);
 }
 
-UA_Int32 TL_process(TL_connection* connection, UA_ByteString* msg) {
+UA_Int32 TL_Process(TL_Connection* connection, UA_ByteString* msg) {
 	UA_Int32 retval = UA_SUCCESS;
 	UA_Int32 pos = 0;
 	UA_OPCUATcpMessageHeader tcpMessageHeader;
@@ -119,7 +119,7 @@ UA_Int32 TL_process(TL_connection* connection, UA_ByteString* msg) {
 		UA_ByteString errorMsg;
 		UA_ByteString *errorMsg_ptr = &errorMsg;
 		UA_ByteString_newMembers(&errorMsg,10);
-		TL_send(connection,&errorMsg_ptr, 1);
+		TL_Send(connection,&errorMsg_ptr, 1);
 		UA_ByteString_deleteMembers(&errorMsg);
 	}
 	UA_OPCUATcpMessageHeader_deleteMembers(&tcpMessageHeader);
@@ -127,7 +127,7 @@ UA_Int32 TL_process(TL_connection* connection, UA_ByteString* msg) {
 }
 
 /** respond to client request */
-UA_Int32 TL_send(TL_connection* connection, UA_ByteString** gather_buf, UA_UInt32 gather_len) {
+UA_Int32 TL_Send(TL_Connection* connection, UA_ByteString** gather_buf, UA_UInt32 gather_len) {
 	UA_Int32 retval = UA_SUCCESS;
 	DBG_VERBOSE(printf("TL_send - entered \n"));
 

+ 10 - 11
src/ua_transport_binary.h

@@ -20,25 +20,24 @@ typedef struct {
 	UA_UInt32 recvBufferSize;
 	UA_UInt32 maxMessageSize;
 	UA_UInt32 maxChunkCount;
-} TL_buffer;
+} TL_Buffer;
 
 /* Transport Layer Connection */
-struct TL_connection_T; // forward declaration
-typedef UA_Int32 (*TL_writer)(struct TL_connection_T* connection, UA_ByteString** gather_bufs, UA_Int32 gather_len); // send mutiple buffer concatenated into one msg (zero copy)
+struct TL_Connection_T; // forward declaration
+typedef UA_Int32 (*TL_Writer)(struct TL_Connection_T* connection, UA_ByteString** gather_bufs, UA_Int32 gather_len); // send mutiple buffer concatenated into one msg (zero copy)
 
-typedef struct TL_connection_T {
+typedef struct TL_Connection_T {
 	UA_Int32 connectionHandle;
 	UA_UInt32 connectionState;
-	TL_buffer localConf;
-	TL_writer writerCallback;
-	TL_buffer remoteConf;
+	TL_Buffer localConf;
+	TL_Buffer remoteConf;
+	TL_Writer writerCallback;
 	UA_String localEndpointUrl;
 	UA_String remoteEndpointUrl;
 	struct SL_Channel_T* secureChannel;
-} TL_connection;
+} TL_Connection;
 
-UA_Int32 TL_check(TL_connection *connection, UA_ByteString* msg);
-UA_Int32 TL_send(TL_connection* connection, UA_ByteString** gather_buf, UA_UInt32 gather_len);
-UA_Int32 TL_process(TL_connection *connection, UA_ByteString *packet);
+UA_Int32 TL_Send(TL_Connection* connection, UA_ByteString** gather_buf, UA_UInt32 gather_len);
+UA_Int32 TL_Process(TL_Connection *connection, UA_ByteString *packet);
 
 #endif /* OPCUA_TRANSPORT_BINARY_H_ */

+ 2 - 2
src/ua_transport_binary_secure.c

@@ -62,7 +62,7 @@ static UA_Int32 SL_send(SL_Channel* channel, UA_ByteString const * responseMessa
 	/* encrypt Data*/
 
 	/* send Data */
-    TL_send(channel->tlConnection, (UA_ByteString **) &response_gather, 2);
+    TL_Send(channel->tlConnection, (UA_ByteString **) &response_gather, 2);
 
 	UA_ByteString_deleteMembers(&response_gather[0]);
 	return UA_SUCCESS;
@@ -167,7 +167,7 @@ UA_Int32 SL_Channel_init(SL_Channel *channel) {
 	return UA_SUCCESS;
 }
 
-UA_Int32 SL_Channel_new(TL_connection *connection, UA_ByteString* msg, UA_Int32* pos) {
+UA_Int32 SL_Channel_new(TL_Connection *connection, UA_ByteString* msg, UA_Int32* pos) {
 	UA_Int32 retval = UA_SUCCESS;
 
 	UA_SecureConversationMessageHeader secureConvHeader;

+ 2 - 2
src/ua_transport_binary_secure.h

@@ -14,7 +14,7 @@ typedef struct {
 
 typedef struct SL_Channel_T {
 	UA_String secureChannelId;
-	TL_connection* tlConnection;
+	TL_Connection* tlConnection;
 	Session *session; // equals UA_Null iff no session is active
 	UA_AsymmetricAlgorithmSecurityHeader remoteAsymAlgSettings;
 	UA_AsymmetricAlgorithmSecurityHeader localAsymAlgSettings;
@@ -28,6 +28,6 @@ typedef struct SL_Channel_T {
 
 UA_Int32 SL_initConnectionObject(SL_Channel *connection);
 UA_Int32 SL_process(SL_Channel* channel, UA_ByteString* msg, UA_Int32* pos);
-UA_Int32 SL_Channel_new(TL_connection *connection, UA_ByteString* msg, UA_Int32* pos);
+UA_Int32 SL_Channel_new(TL_Connection *connection, UA_ByteString* msg, UA_Int32* pos);
 
 #endif /* OPCUA_TRANSPORT_BINARY_SECURE_H_ */