Browse Source

various changes

FlorianPalm 11 years ago
parent
commit
311cc947cf
6 changed files with 122 additions and 14 deletions
  1. 3 3
      configure
  2. 1 1
      examples/src/Makefile
  3. 12 6
      src/opcua_binaryEncDec.c
  4. 13 0
      src/opcua_binaryEncDec.h
  5. 45 4
      src/opcua_secureChannelLayer.c
  6. 48 0
      tests/check_stack.c

+ 3 - 3
configure

@@ -2765,9 +2765,9 @@ $as_echo "no" >&6; }
   SET_MAKE="MAKE=${MAKE-make}"
 fi
 
-if test -z $CFLAGS; then
-    CFLAGS='-O0'
-fi
+#if test -z $CFLAGS; then
+#    CFLAGS='-O0'
+#fi
 ac_ext=c
 ac_cpp='$CPP $CPPFLAGS'
 ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'

+ 1 - 1
examples/src/Makefile

@@ -85,7 +85,7 @@ AUTOMAKE = ${SHELL} /home/opcua/git/opcUaStack/missing --run automake-1.11
 AWK = mawk
 CC = gcc
 CCDEPMODE = depmode=gcc3
-CFLAGS = -O0
+CFLAGS = -g -O2
 CHECK_CFLAGS = -pthread -I/usr/local/include  
 CHECK_LIBS = -L/usr/local/lib -lcheck  
 CPP = gcc -E

+ 12 - 6
src/opcua_binaryEncDec.c

@@ -436,17 +436,22 @@ Int32 decoder_decodeBuiltInDatatype(char const * srcBuf, Int32 type, Int32 *pos,
 
 /* not tested */
 /*needs to be reimplemented */
-Int32 encode_builtInDatatypeArray(void *data, Int32 size, Int32 type,
+Int32 encoder_encodeBuiltInDatatypeArray(void *data, Int32 size, Int32 type,
 		Int32 *pos, char *dstBuf)
 {
 	int i;
-	void * pItem;
+	void * pItem = NULL;
 	encoder_encodeBuiltInDatatype((void*) (size), INT32, pos, dstBuf);
-	for (i = 0; i < size;)
+	pItem = data;
+	for (i = 0; i < size; i++)
 	{
-		encoder_encodeBuiltInDatatype(pItem, type, pos, dstBuf);
-		switch (type)
+		//-128 does the conversion e.g. from BOOLEAN_ARRAY to BOOLEAN (type)
+		encoder_encodeBuiltInDatatype(pItem, type - 128 , pos, dstBuf);
+		pItem++;
+	}
+	/*	switch (type)
 		{
+
 		case BOOLEAN:
 			pItem = (Boolean*) (data) + 1;
 			break;
@@ -524,6 +529,7 @@ Int32 encode_builtInDatatypeArray(void *data, Int32 size, Int32 type,
 			break;
 		}
 	}
+	*/
 	return UA_NO_ERROR;
 }
 
@@ -1250,7 +1256,7 @@ Int32 encodeVariant(UA_Variant *variant, Int32 *pos, char *dstBuf)
 		if (variant->ArrayLength > 0)
 		{
 			//encode array as given by variant type
-			encode_builtInDatatypeArray((void*) variant->Value,
+			encoder_encodeBuiltInDatatypeArray((void*) variant->Value,
 					variant->ArrayLength, (variant->EncodingMask & 31), pos,
 					dstBuf);
 		}

+ 13 - 0
src/opcua_binaryEncDec.h

@@ -39,6 +39,19 @@ Int32 decoder_decodeBuiltInDatatype(char const * srcBuf, Int32 type, Int32 *pos,
  */
 Int32 encoder_encodeBuiltInDatatype(void *data, Int32 type, Int32 *pos, char *dstBuf);
 
+
+/**
+ *
+ * @param data
+ * @param size
+ * @param type
+ * @param pos
+ * @param dstBuf
+ * @return
+ */
+Int32 encoder_encodeBuiltInDatatypeArray(void *data, Int32 size,
+		Int32 type, Int32 *pos,
+		char *dstBuf);
 /**
  *
  * @param buf

+ 45 - 4
src/opcua_secureChannelLayer.c

@@ -184,7 +184,48 @@ Int32 SL_processMessage(UA_connection *connection, UA_ByteString message)
 			// requestedLifetime
 			decoder_decodeBuiltInDatatype(message.Data,INT32,&pos,&requestedLifetime);
 			//TODO process requestedLifetime
-			//SL_openSecureChannel_respond(connection,response,TOKEN_LIFETIME);
+/* --------------------------------------------------------------------------------
+			UA_ByteString responseMessage;
+			char * response;
+			Int32 pos = 0;
+			String_Array stringArray;
+
+			stringArray.arrayLength = 0;
+			stringArray.data = NULL;
+
+			stringArray.dimensions.data = NULL;
+			stringArray.dimensions.length = 0;
+
+			UA_DateTime now = opcua_time_now();
+			UA_DiagnosticInfo returnDiagnostics;
+
+			Int32 StatusCode;
+			encoder_encodeBuiltInDatatype(now, DATE_TIME, &pos, response);
+			encoder_encodeBuiltInDatatype(requestHeader.requestHandle,INT32,&pos,response);
+			//return a valid StatusCode
+			StatusCode = 0;  //TODO generate valid StatusCode
+			encoder_encodeBuiltInDatatype(StatusCode,Int32,&pos,response);
+
+			encoder_encodeBuiltInDatatype
+
+			returnDiagnostics.EncodingMask = 0; // TODO return Dianostics if client requests
+
+			encoder_encodeBuiltInDatatype(returnDiagnostics,Int32,&pos,response);
+			//encoder_encodeBuiltInDatatype(stringArray,STRING_ARRAY,pos,response);
+
+			encoder_encodebuiltInDatatypeArray(stringArray.data,stringArray.arrayLength,STRING_ARRAY,&pos,response);
+			UA_ExtensionObject additionalHeader;
+			additionalHeader.Encoding = 0;
+
+			encode_encodebuiltInDatatype(&addtionalHeader
+			//get memory
+
+
+
+
+/* -------------------------------------------------------------------------------- */
+			//SL_openSecureChannel_respond(connection,TOKEN_LIFETIME);
+
 		}
 		else
 		{
@@ -264,8 +305,8 @@ void SL_receive(UA_connection *connection, UA_ByteString *serviceMessage)
 			if(connection->secureLayer->connectionState == connectionState_ESTABLISHED)
 			{
 				//TODO
-/*
-				if(SCM_Header.SecureChannelId == connection->secureLayer)
+
+				if(SCM_Header.SecureChannelId == connection->secureLayer->securityToken.secureChannelId)
 				{
 
 				}
@@ -273,7 +314,7 @@ void SL_receive(UA_connection *connection, UA_ByteString *serviceMessage)
 				{
 					//TODO generate ERROR_Bad_SecureChannelUnkown
 				}
-*/
+
 			}
 
 			break;

+ 48 - 0
tests/check_stack.c

@@ -606,6 +606,37 @@ START_TEST(DataValue_calcSize_test)
 }
 END_TEST
 
+START_TEST(encoder_encodeBuiltInDatatypeArray_test)
+{
+	Int32 position = 0;
+
+	char input = {1,2,3,4,5,6,7,8,9};
+	Int32 len = 9;
+	Int32 ret;
+	char *mem = malloc(13 * sizeof(Byte));
+
+
+	ret = encoder_encodeBuiltInDatatypeArray((void*)input,len, BYTE_ARRAY,
+			&position, mem);
+
+	ck_assert_int_eq(mem[4], 0x01);
+	ck_assert_int_eq(mem[5], 0x02);
+	ck_assert_int_eq(mem[6], 0x03);
+	ck_assert_int_eq(mem[7], 0x04);
+	ck_assert_int_eq(mem[8], 0x05);
+	ck_assert_int_eq(mem[9], 0x06);
+	ck_assert_int_eq(mem[10], 0x07);
+	ck_assert_int_eq(mem[11], 0x08);
+	ck_assert_int_eq(mem[12], 0x09);
+
+	ck_assert_int_eq(position, sizeof(Int32) + 9);
+	ck_assert_int_eq(ret, UA_NO_ERROR);
+
+
+	free(mem);
+}
+END_TEST
+
 Suite *testSuite_getPacketType(void)
 {
 	Suite *s = suite_create("getPacketType");
@@ -851,6 +882,14 @@ Suite* testSuite_dataValue_calcSize(void)
 	return s;
 }
 
+Suite *testSuite_encoder_encodeBuiltInDatatypeArray_test(void)
+{
+	Suite *s = suite_create("encoder_encodeBuiltInDatatypeArray_test");
+	TCase *tc_core = tcase_create("Core");
+	tcase_add_test(tc_core, encoder_encodeBuiltInDatatypeArray_test);
+	suite_add_tcase(s,tc_core);
+	return s;
+}
 int main (void)
 {
 	int number_failed = 0;
@@ -861,6 +900,13 @@ int main (void)
 	number_failed = srunner_ntests_failed(sr);
 	srunner_free(sr);
 
+
+	s = testSuite_encoder_encodeBuiltInDatatypeArray_test();
+	sr = srunner_create(s);
+	srunner_run_all(sr,CK_NORMAL);
+	number_failed += srunner_ntests_failed(sr);
+	srunner_free(sr);
+
 	s = testSuite_decodeByte();
 	sr = srunner_create(s);
 	srunner_run_all(sr,CK_NORMAL);
@@ -1007,6 +1053,8 @@ int main (void)
 	number_failed += srunner_ntests_failed(sr);
 	srunner_free(sr);
 
+
+
 	/* <TESTSUITE_TEMPLATE>
 	s =  <TESTSUITENAME>;
 	sr = srunner_create(s);