Browse Source

Merge branch 'master' of https://github.com/acplt/open62541

Conflicts:
	src/opcua_secureLayer.c
FlorianPalm 11 years ago
parent
commit
616a850fd4
5 changed files with 68 additions and 41 deletions
  1. 3 1
      src/opcua_secureLayer.c
  2. 27 38
      src/opcua_transportLayer.c
  3. 1 1
      tests/check_stack.c
  4. 24 1
      tool/generate_builtin.py
  5. 13 0
      tool/plugin_Node.py

+ 3 - 1
src/opcua_secureLayer.c

@@ -470,6 +470,7 @@ void SL_receive(UA_connection *connection, UA_ByteString *serviceMessage) {
 	UA_SecureConversationMessageHeader secureConvHeader;
 	UA_AsymmetricAlgorithmSecurityHeader asymAlgSecHeader;
 	UA_SequenceHeader sequenceHeader;
+	UA_Int32 packetType = 0;
 	UA_Int32 pos = 0;
 	UA_Int32 iTmp;
 	//TODO Error Handling, length checking
@@ -488,7 +489,7 @@ void SL_receive(UA_connection *connection, UA_ByteString *serviceMessage) {
 		switch (secureConvHeader.tcpMessageHeader->messageType) {
 
 		case UA_MESSAGETYPE_OPN: /* openSecureChannel Message received */
-			UA_AsymmetricAlgorithmSecurityHeader_encode(secureChannelPacket.data, &pos, &asymAlgSecHeader);
+			UA_AsymmetricAlgorithmSecurityHeader_decode(secureChannelPacket.data, &pos, &asymAlgSecHeader);
 			UA_ByteString_printf("SL_receive - AAS_Header.ReceiverThumbprint=",
 					&(asymAlgSecHeader.receiverCertificateThumbprint));
 			UA_ByteString_printf("SL_receive - AAS_Header.SecurityPolicyUri=",
@@ -615,3 +616,4 @@ void SL_receive(UA_connection *connection, UA_ByteString *serviceMessage) {
 }
 
 
+

+ 27 - 38
src/opcua_transportLayer.c

@@ -72,12 +72,6 @@ UA_Int32 TL_receive(UA_connection *connection, UA_ByteString *packet)
 		printf("TL_receive - connection->readData.length %d \n",connection->readData.length);
 
 
-		//is final chunk or not
-		//TODO process chunks
-		pos += sizeof(UA_Byte);
-		//save the message size if needed
-		pos += sizeof(UA_UInt32);
-
 		printf("TL_receive - MessageType = %d \n",tcpMessageHeader->messageType);
 		switch(tcpMessageHeader->messageType)
 		{
@@ -180,7 +174,10 @@ UA_Int32 TL_process(UA_connection *connection,UA_Int32 packetType, UA_Int32 *pos
 	UA_Byte reserved;
 	UA_UInt32 messageSize;
 	UA_OPCUATcpHelloMessage *helloMessage;
+	UA_OPCUATcpAcknowledgeMessage *ackMessage;
+	UA_OPCUATcpMessageHeader *ackHeader;
 	UA_alloc((void**)(&helloMessage),UA_OPCUATcpHelloMessage_calcSize(UA_NULL));
+
 	printf("TL_process - entered \n");
 	struct TL_header tmpHeader;
 	switch(packetType)
@@ -209,53 +206,45 @@ UA_Int32 TL_process(UA_connection *connection,UA_Int32 packetType, UA_Int32 *pos
 
 			connection->transportLayer.remoteConf.maxChunkCount = helloMessage->maxChunkCount;
 			printf("TL_process - maxChunkCount = %d \n",connection->transportLayer.remoteConf.maxChunkCount);
+			UA_String_copy(&(helloMessage->endpointUrl), &(connection->transportLayer.endpointURL));
 
+			/* send back acknowledge */
+			//memory for message
+			UA_alloc((void**)&(ackMessage),UA_OPCUATcpAcknowledgeMessage_calcSize(UA_NULL));
+
+			ackMessage->protocolVersion = connection->transportLayer.localConf.protocolVersion;
+			ackMessage->receiveBufferSize = connection->transportLayer.localConf.recvBufferSize;
+			ackMessage->maxMessageSize = connection->transportLayer.localConf.maxMessageSize;
+			ackMessage->maxChunkCount = connection->transportLayer.localConf.maxChunkCount;
+
+			//memory for header
+			UA_alloc((void**)&(ackHeader),UA_OPCUATcpMessageHeader_calcSize(UA_NULL));
+
+			ackHeader->messageType = UA_MESSAGETYPE_ACK;
+			ackHeader->isFinal = 'F';
+			ackHeader->messageSize = UA_OPCUATcpAcknowledgeMessage_calcSize(ackMessage) +
+					UA_OPCUATcpMessageHeader_calcSize(ackHeader);
+
+			//allocate memory in stream
+			UA_alloc((void**)&(tmpMessage.data),ackHeader->messageSize);
+			//encode header and message
+			UA_OPCUATcpMessageHeader_encode(ackHeader,&tmpPos,tmpMessage.data);
+			UA_OPCUATcpAcknowledgeMessage_encode(ackMessage,&tmpPos,tmpMessage.data);
 
-			UA_String_decode(connection->readData.data,pos,(&(connection->transportLayer.endpointURL)));
 
-			/* send back acknowledge */
-			UA_alloc((void**)&(tmpMessage.data),SIZE_OF_ACKNOWLEDGE_MESSAGE);
-			if(tmpMessage.data == UA_NULL)
-			{
-				printf("TL_process - memory allocation failed \n");
-			}
 			tmpMessage.length = SIZE_OF_ACKNOWLEDGE_MESSAGE;
-			printf("TL_process - allocated memory \n");
-			/* ------------------------ Header ------------------------ */
-			// MessageType
-			tmpMessage.data[0] = 'A';
-			tmpMessage.data[1] = 'C';
-			tmpMessage.data[2] = 'K';
-			tmpPos += 3;
-			// Chunk
-			reserved = 'F';
-			UA_Byte_encode(&reserved, &tmpPos, tmpMessage.data);
-			// MessageSize
-			messageSize = SIZE_OF_ACKNOWLEDGE_MESSAGE;
-			UA_UInt32_encode(&messageSize,&tmpPos, tmpMessage.data);
-			printf("TL_process - Size messageToSend = %d \n",messageSize);
 
+			printf("TL_process - Size messageToSend = %d \n",ackHeader->messageSize);
 			/* ------------------------ Body ------------------------ */
 			// protocol version
-			UA_UInt32_encode(&(connection->transportLayer.localConf.protocolVersion),
-					&tmpPos, tmpMessage.data);
 			printf("TL_process - localConf.protocolVersion = %d \n",connection->transportLayer.localConf.protocolVersion);
-
 			//receive buffer size
-			UA_UInt32_encode(&(connection->transportLayer.localConf.recvBufferSize),
-					&tmpPos, tmpMessage.data);
 			printf("TL_process - localConf.recvBufferSize = %d \n", connection->transportLayer.localConf.recvBufferSize);
 			//send buffer size
-			UA_UInt32_encode(&(connection->transportLayer.localConf.sendBufferSize),
-					&tmpPos, tmpMessage.data);
 			printf("TL_process - localConf.sendBufferSize = %d \n", connection->transportLayer.localConf.sendBufferSize);
 			//maximum message size
-			UA_UInt32_encode(&(connection->transportLayer.localConf.maxMessageSize),
-					&tmpPos, tmpMessage.data);
 			printf("TL_process - localConf.maxMessageSize = %d \n", connection->transportLayer.localConf.maxMessageSize);
 			//maximum chunk count
-			UA_UInt32_encode(&(connection->transportLayer.localConf.maxChunkCount),
-					&tmpPos, tmpMessage.data);
 			printf("TL_process - localConf.maxChunkCount = %d \n", connection->transportLayer.localConf.maxChunkCount);
 
 			TL_send(connection, &tmpMessage);

+ 1 - 1
tests/check_stack.c

@@ -73,7 +73,7 @@ START_TEST(encode_builtInDatatypeArray_test_String)
 			0xFF, 0xFF, 0xFF, 0xFF		// s2.Length
 	};
 
-	UA_Array_encode((void const**)array, noElements, UA_ByteString, &pos, buf);
+	UA_Array_encode((void const**)array, noElements, UA_BYTESTRING, &pos, buf);
 
 	// check size
 	ck_assert_int_eq(pos, 4 + 4 + 6 + 4);

+ 24 - 1
tool/generate_builtin.py

@@ -261,6 +261,23 @@ print('#define OPCUA_H_', end='\n', file=fh)
 print('#include "opcua_basictypes.h"', end='\n', file=fh)
 print('#include "opcua_namespace_0.h"', end='\n', file=fh);
 
+
+#plugin handling
+import os
+files = [f for f in os.listdir('.') if os.path.isfile(f) and f[-3:] == ".py" and f[:7] == "plugin_"]
+plugin_types = []
+packageForType = OrderedDict()
+
+for f in files:
+	package = f[:-3]
+	exec "import " + package
+	exec "pluginSetup = " + package + ".setup()"
+	if pluginSetup["pluginType"] == "structuredObject":
+		plugin_types.append(pluginSetup["tagName"])
+		packageForType[pluginSetup["tagName"]] = [package,pluginSetup]
+		print("Custom object creation for tag " + pluginSetup["tagName"] + " imported from package " + package)
+#end plugin handling
+
 for element in types:
     name = element.get("Name")
     if skipType(name):
@@ -285,7 +302,13 @@ for element in types:
     #    print "package ListOf" + name + " is new Types.Arrays.UA_Builtin_Arrays(" + name + ");\n"
 
 for name, element in deferred_types.iteritems():
-    createStructured(element)
+	if name in plugin_types:
+		#execute plugin if registered
+		exec "ret = " + packageForType[name][0]+"."+packageForType[name][1]["functionCall"]
+		if ret == "default":
+			createStructured(element)
+	else:
+		createStructured(element)
     # if name in arraytypes:
     #    print "package ListOf" + name + " is new Types.Arrays.UA_Builtin_Arrays(" + name + ");\n"
 

+ 13 - 0
tool/plugin_Node.py

@@ -0,0 +1,13 @@
+from __future__ import print_function
+
+def setup():
+	config = dict()
+	config["pluginType"] = "structuredObject";
+	config["tagName"] = "Node";
+	config["functionCall"] = "createElement(element, fc, fh)"
+	return config
+
+def createElement(element, fc, fh):
+	print("/* Hello from plugin */", end='\n', file=fc)
+	#return "default" to execute the default createElement
+	return "default"