Explorar o código

yeah! sent correct OPF back, got MSG and CLO. memory problem still not solved however

Leon Urbas %!s(int64=11) %!d(string=hai) anos
pai
achega
ff1d397ca3
Modificáronse 4 ficheiros con 14 adicións e 8 borrados
  1. 3 2
      examples/src/opcuaServer.c
  2. 4 1
      src/opcua_basictypes.c
  3. 6 4
      src/opcua_secureLayer.c
  4. 1 1
      tool/generate_builtin.py

+ 3 - 2
examples/src/opcuaServer.c

@@ -137,11 +137,12 @@ void server_run()
 
 		if(connection.newDataToWrite)
 		{
-			printf("data will be sent \n");
+			UA_ByteString_printx("Send data:",&connection.writeData);
 			n = write(newsockfd,connection.writeData.data,connection.writeData.length);
 			printf("written %d bytes \n",n);
 			connection.newDataToWrite = 0;
-			UA_free(connection.writeData.data);
+			//FIXME: this seems to be the right address, free crashes however
+			//UA_free(connection.writeData.data);
 			connection.writeData.data = NULL;
 			connection.writeData.length = 0;
 		}

+ 4 - 1
src/opcua_basictypes.c

@@ -49,6 +49,7 @@ UA_Int32 UA_Array_encode(void const **src, UA_Int32 noElements, UA_Int32 type, U
 	return retVal;
 }
 
+// FIXME: While calcSize and encode handle size themselfes, decode relies on others to do things correctly
 UA_Int32 UA_Array_decode(UA_Byte const * src, UA_Int32 noElements, UA_Int32 type, UA_Int32* pos, void const **dst) {
 	UA_Int32 retval = UA_SUCCESS;
 	UA_Int32 i = 0;
@@ -441,7 +442,9 @@ void UA_ByteString_printx_hex(char* label, UA_ByteString* string) {
 }
 
 UA_Byte UA_Byte_securityPoliceNoneData[] = "http://opcfoundation.org/UA/SecurityPolicy#None";
-UA_ByteString UA_ByteString_securityPoliceNone = { sizeof(UA_Byte_securityPoliceNoneData), UA_Byte_securityPoliceNoneData };
+// sizeof()-1 : discard the implicit null-terminator of the c-char-string
+UA_ByteString UA_ByteString_securityPoliceNone = { sizeof(UA_Byte_securityPoliceNoneData)-1, UA_Byte_securityPoliceNoneData };
+
 UA_Int32 UA_ByteString_copy(UA_ByteString const * src, UA_ByteString* dst) {
 	return UA_String_copy((UA_String const*)src,(UA_String*)dst);
 }

+ 6 - 4
src/opcua_secureLayer.c

@@ -46,7 +46,7 @@ UA_Int32 SL_initConnectionObject(UA_connection *connection)
 	return UA_NO_ERROR;
 }
 
-UA_Int32 SL_send(UA_connection* connection, UA_ByteString* responseMessage, UA_Int32 type)
+UA_Int32 SL_send(UA_connection* connection, UA_ByteString const * responseMessage, UA_Int32 type)
 {
 	UA_UInt32 sequenceNumber;
 	UA_UInt32 requestId;
@@ -250,8 +250,9 @@ UA_Int32 SL_openSecureChannel(UA_connection *connection,
 
 	response.length = sizeResponseType + sizeRespHeader + sizeRespMessage;
 
-	//FIXME: Sten 4 bytes are missing
-	response.length += 4;
+	//FIXME: Sten: 4 bytes are missing
+	//Leon: fixed bug in generator / UA_Array_encode, still missing 2 :-(
+	response.length += 2;
 
 	//get memory for response
 	UA_alloc((void*)&(response.data), response.length);
@@ -289,7 +290,8 @@ UA_Int32 SL_openSecureChannel(UA_connection *connection,
 
 	//449 = openSecureChannelResponse
 	SL_send(connection, &response, 449);
-	UA_ByteString_deleteMembers(&response);
+	//FIXME: this call crashs in UA_free
+	//UA_ByteString_deleteMembers(&response);
 
 	return UA_SUCCESS;
 }

+ 1 - 1
tool/generate_builtin.py

@@ -178,7 +178,7 @@ def createStructured(element):
             if t in enum_types:
                 print('\tretval |= UA_'+t+'_encode(&(src->'+n+'),pos,dst);', end='\n', file=fc)
             elif t.find("**") != -1:
-                print('\tretval |= UA_Int32_encode(&(src->'+n+'Size),pos,dst); // encode size', end='\n', file=fc)
+                print('\t//retval |= UA_Int32_encode(&(src->'+n+'Size),pos,dst); // encode size managed by UA_Array_encode', end='\n', file=fc)
 		print("\tretval |= UA_Array_encode((void const**) (src->"+n+"),src->"+n+"Size, UA_" + t[0:t.find("*")].upper()+",pos,dst);", end='\n', file=fc)
             elif t.find("*") != -1:
                 print('\tretval |= UA_' + t[0:t.find("*")] + "_encode(src->" + n + ',pos,dst);', end='\n', file=fc)