Browse Source

pointer and const issues

Leon Urbas 11 years ago
parent
commit
b52c2e446e

+ 65 - 46
src/opcua_binaryEncDec.c

@@ -96,7 +96,8 @@ Int32 encoder_encodeBuiltInDatatype(void *data, Int32 type, Int32 *pos,
 	}
 	return UA_NO_ERROR;
 }
-Int32 decoder_decodeBuiltInDatatype(char *srcBuf, Int32 type, Int32 *pos,
+
+Int32 decoder_decodeBuiltInDatatype(char const * srcBuf, Int32 type, Int32 *pos,
 		void *dstStructure)
 {
 	Boolean tmp;
@@ -526,7 +527,7 @@ Int32 encode_builtInDatatypeArray(void *data, Int32 size, Int32 type,
 	return UA_NO_ERROR;
 }
 
-Int32 decodeBoolean(char * const buf, Int32 *pos, Boolean *dst)
+Int32 decodeBoolean(char const * const buf, Int32 *pos, Boolean *dst)
 {
 	*dst = ((Boolean) (buf[*pos]) > 0) ? UA_TRUE : UA_FALSE;
 	return UA_NO_ERROR;
@@ -537,7 +538,7 @@ void encodeBoolean(Boolean value, Int32 *pos, char *dstBuf)
 	memcpy(&(dstBuf[*pos]), &tmpBool, sizeof(Boolean));
 }
 
-Int32 decodeSByte(char * const buf, Int32 *pos, SByte *dst)
+Int32 decodeSByte(char const * const buf, Int32 *pos, SByte *dst)
 {
 	*pos = (*pos) + 1;
 	*dst = (SByte) buf[(*pos) - 1];
@@ -550,7 +551,7 @@ void encodeSByte(SByte value, Int32 *pos, char *dstBuf)
 	*pos = (*pos) + 1;
 
 }
-Int32 decodeByte(char * const buf, Int32 *pos, Byte* dst)
+Int32 decodeByte(char const * const buf, Int32 *pos, Byte* dst)
 {
 	*pos = (*pos) + 1;
 	*dst = (Byte) buf[(*pos) - 1];
@@ -563,7 +564,7 @@ void encodeByte(Byte value, Int32 *pos, char *dstBuf)
 	*pos = (*pos) + 1;
 }
 
-Int32 decodeUInt16(char * const buf, Int32 *pos, UInt16 *dst)
+Int32 decodeUInt16(char const * const buf, Int32 *pos, UInt16 *dst)
 {
 	Byte t1 = buf[*pos];
 	UInt16 t2 = (UInt16) (buf[*pos + 1] << 8);
@@ -577,7 +578,7 @@ void encodeUInt16(UInt16 value, Int32 *pos, char* dstBuf)
 	*pos = (*pos) + sizeof(UInt16);
 }
 
-Int32 decodeInt16(char * const buf, Int32 *pos, Int16 *dst)
+Int32 decodeInt16(char const * const buf, Int32 *pos, Int16 *dst)
 {
 	SByte t1 = buf[*pos];
 	Int32 t2 = (Int16) (buf[*pos + 1] << 8);
@@ -591,7 +592,7 @@ void encodeInt16(Int16 value, Int32 *pos, char *dstBuf)
 	*pos = (*pos) + sizeof(Int16);
 }
 
-Int32 decodeInt32(char * const buf, Int32 *pos, Int32 *dst)
+Int32 decodeInt32(char const * const buf, Int32 *pos, Int32 *dst)
 {
 	Int32 t1 = (SByte) buf[*pos];
 	Int32 t2 = (Int32) (((SByte) (buf[*pos + 1]) & 0xFF) << 8);
@@ -607,24 +608,24 @@ void encodeInt32(Int32 value, Int32 *pos, char *dstBuf)
 	*pos = (*pos) + sizeof(Int32);
 }
 
-Int32 decodeUInt32(char * const buf, Int32 *pos, UInt32 *dst)
+Int32 decodeUInt32(char const * const buf, Int32 *pos, UInt32 *dst)
 {
 	Byte t1 = buf[*pos];
-	UInt32 t2 = (UInt32) (buf[*pos + 1] << 8);
-	UInt32 t3 = (UInt32) (buf[*pos + 2] << 16);
-	UInt32 t4 = (UInt32) (buf[*pos + 3] << 24);
+	UInt32 t2 = (UInt32) buf[*pos + 1] << 8;
+	UInt32 t3 = (UInt32) buf[*pos + 2] << 16;
+	UInt32 t4 = (UInt32) buf[*pos + 3] << 24;
 	*pos += sizeof(UInt32);
 	*dst = t1 + t2 + t3 + t4;
 	return UA_NO_ERROR;
 }
+
 void encodeUInt32(UInt32 value, Int32 *pos, char *dstBuf)
 {
 	memcpy(&(dstBuf[*pos]), &value, sizeof(UInt32));
 	*pos += 4;
-
 }
 
-Int32 decodeInt64(char * const buf, Int32 *pos, Int64 *dst)
+Int32 decodeInt64(char const *  buf, Int32 *pos, Int64 *dst)
 {
 
 	SByte t1 = buf[*pos];
@@ -645,7 +646,7 @@ void encodeInt64(Int64 value, Int32 *pos, char *dstBuf)
 	*pos = (*pos) + sizeof(Int64);
 }
 
-Int32 decodeUInt64(char * const buf, Int32 *pos, UInt64 *dst)
+Int32 decodeUInt64(char const * buf, Int32 *pos, UInt64 *dst)
 {
 
 	Byte t1 = buf[*pos];
@@ -666,7 +667,7 @@ void encodeUInt64(UInt64 value, Int32 *pos, char *dstBuf)
 	*pos = (*pos) + sizeof(UInt64);
 }
 
-Int32 decodeFloat(char *buf, Int32 *pos, Float *dst)
+Int32 decodeFloat(char const * buf, Int32 *pos, Float *dst)
 {
 	Float tmpFloat;
 	memcpy(&tmpFloat, &(buf[*pos]), sizeof(Float));
@@ -681,7 +682,7 @@ Int32 encodeFloat(Float value, Int32 *pos, char *dstBuf)
 	return UA_NO_ERROR;
 }
 
-Int32 decodeDouble(char *buf, Int32 *pos, Double *dst)
+Int32 decodeDouble(char const *  buf, Int32 *pos, Double *dst)
 {
 	Double tmpDouble;
 	tmpDouble = (Double) (buf[*pos]);
@@ -696,10 +697,10 @@ Int32 encodeDouble(Double value, Int32 *pos, char *dstBuf)
 	return UA_NO_ERROR;
 }
 
-Int32 decodeUAString(char * const buf, Int32 *pos, UA_String *dstUAString)
+Int32 decodeUAString(char const * buf, Int32 *pos, UA_String * dstUAString)
 {
 
-	decoder_decodeBuiltInDatatype(buf, INT32, pos, (&dstUAString->Length));
+	decoder_decodeBuiltInDatatype(buf, INT32, pos, &(dstUAString->Length));
 
 	if (dstUAString->Length > 0)
 	{
@@ -742,7 +743,7 @@ Int32 UAString_calcSize(UA_String *string)
 	}
 }
 
-Int32 decodeUADateTime(char * const buf, Int32 *pos, UA_DateTime *dst)
+Int32 decodeUADateTime(char const * buf, Int32 *pos, UA_DateTime *dst)
 {
 	decoder_decodeBuiltInDatatype(buf, INT64, pos, dst);
 	return UA_NO_ERROR;
@@ -752,7 +753,7 @@ void encodeUADateTime(UA_DateTime time, Int32 *pos, char *dstBuf)
 	encodeInt64(time, pos, dstBuf);
 }
 
-Int32 decodeUAGuid(char * const buf, Int32 *pos, UA_Guid *dstGUID)
+Int32 decodeUAGuid(char const * buf, Int32 *pos, UA_Guid *dstGUID)
 {
 	decoder_decodeBuiltInDatatype(buf, INT32, pos, &(dstGUID->Data1));
 
@@ -780,7 +781,7 @@ Int32 UAGuid_calcSize(UA_Guid *guid)
 			+ UAByteString_calcSize(&(guid->Data4));
 }
 
-Int32 decodeUAByteString(char * const buf, Int32* pos,
+Int32 decodeUAByteString(char const * const buf, Int32* pos,
 		UA_ByteString *dstBytestring)
 {
 
@@ -796,7 +797,7 @@ Int32 encodeXmlElement(UA_XmlElement *xmlElement, Int32 *pos, char *dstBuf)
 {
 	return encodeUAByteString(&(xmlElement->Data), pos, dstBuf);
 }
-Int32 decodeXmlElement(char * const buf, Int32* pos, UA_XmlElement *xmlElement)
+Int32 decodeXmlElement(char const * buf, Int32* pos, UA_XmlElement *xmlElement)
 {
 	return decodeUAByteString(buf, pos, &xmlElement->Data);
 }
@@ -806,33 +807,45 @@ Int32 UAByteString_calcSize(UA_ByteString *byteString)
 	return UAString_calcSize((UA_String*) byteString);
 }
 
-Int32 decodeUANodeId(char * const buf, Int32 *pos, UA_NodeId *dstNodeId)
+/* See 62541-6 §5.2.2.9 */
+Int32 decodeUANodeId(char const * buf, Int32 *pos, UA_NodeId *dstNodeId)
 {
-	decoder_decodeBuiltInDatatype(buf, INT32, pos, &(dstNodeId->EncodingByte));
+	decoder_decodeBuiltInDatatype(buf, BYTE, pos, &(dstNodeId->EncodingByte));
 
 	switch (dstNodeId->EncodingByte)
 	{
-	case NIEVT_TWO_BYTE:
+	case NIEVT_TWO_BYTE: // Table 7
 		decoder_decodeBuiltInDatatype(buf, BYTE, pos,
 				&(dstNodeId->Identifier.Numeric));
+		dstNodeId->Namespace = 0; // default OPC UA Namespace
 		break;
-	case NIEVT_FOUR_BYTE:
+	case NIEVT_FOUR_BYTE: // Table 8
+		decoder_decodeBuiltInDatatype(buf, BYTE, pos,
+				&(dstNodeId->Namespace));
 		decoder_decodeBuiltInDatatype(buf, UINT16, pos,
 				&(dstNodeId->Identifier.Numeric));
 		break;
-	case NIEVT_NUMERIC:
+	case NIEVT_NUMERIC: // Table 6, first entry
+		decoder_decodeBuiltInDatatype(buf, UINT16, pos,
+				&(dstNodeId->Namespace));
 		decoder_decodeBuiltInDatatype(buf, UINT32, pos,
 				&(dstNodeId->Identifier.Numeric));
 		break;
-	case NIEVT_STRING:
+	case NIEVT_STRING: // Table 6, second entry
+		decoder_decodeBuiltInDatatype(buf, UINT16, pos,
+				&(dstNodeId->Namespace));
 		decoder_decodeBuiltInDatatype(buf, STRING, pos,
 				&(dstNodeId->Identifier.String));
 		break;
-	case NIEVT_GUID:
+	case NIEVT_GUID: // Table 6, third entry
+		decoder_decodeBuiltInDatatype(buf, UINT16, pos,
+				&(dstNodeId->Namespace));
 		decoder_decodeBuiltInDatatype(buf, GUID, pos,
 				&(dstNodeId->Identifier.Guid));
 		break;
-	case NIEVT_BYTESTRING:
+	case NIEVT_BYTESTRING: // Table 6, "OPAQUE"
+		decoder_decodeBuiltInDatatype(buf, UINT16, pos,
+				&(dstNodeId->Namespace));
 		decoder_decodeBuiltInDatatype(buf, BYTE_STRING, pos,
 				&(dstNodeId->Identifier.ByteString));
 		break;
@@ -910,7 +923,7 @@ Int32 nodeId_calcSize(UA_NodeId *nodeId)
  * Chapter: 7.13
  * Page: 118
  */
-Int32 decodeIntegerId(char* buf, Int32 *pos, Int32 *dst)
+Int32 decodeIntegerId(char const * buf, Int32 *pos, Int32 *dst)
 {
 	decoder_decodeBuiltInDatatype(buf, INT32, pos, dst);
 	return UA_NO_ERROR;
@@ -920,7 +933,7 @@ void encodeIntegerId(UA_AD_IntegerId integerId, Int32 *pos, char *buf)
 	encodeInt32(integerId, pos, buf);
 }
 
-Int32 decodeExpandedNodeId(char * const buf, Int32 *pos,
+Int32 decodeExpandedNodeId(char const * const buf, Int32 *pos,
 		UA_ExpandedNodeId *nodeId)
 {
 
@@ -1061,14 +1074,14 @@ Int32 ExpandedNodeId_calcSize(UA_ExpandedNodeId *nodeId){
 	return length;
 }
 
-Int32 decodeUAStatusCode(char * const buf, Int32 *pos, UA_StatusCode* dst)
+Int32 decodeUAStatusCode(char const * buf, Int32 *pos, UA_StatusCode* dst)
 {
 	decoder_decodeBuiltInDatatype(buf, UINT32, pos, dst);
 	return UA_NO_ERROR;
 
 }
 
-Int32 decodeQualifiedName(char * const buf, Int32 *pos,
+Int32 decodeQualifiedName(char const * const buf, Int32 *pos,
 		UA_QualifiedName *dstQualifiedName)
 {
 	//TODO memory management for ua string
@@ -1097,7 +1110,7 @@ Int32 QualifiedName_calcSize(UA_QualifiedName *qualifiedName)
 	return length;
 }
 
-Int32 decodeLocalizedText(char * const buf, Int32 *pos,
+Int32 decodeLocalizedText(char const * const buf, Int32 *pos,
 		UA_LocalizedText *dstLocalizedText)
 {
 	//TODO memory management for ua string
@@ -1141,7 +1154,7 @@ Int32 LocalizedText_calcSize(UA_LocalizedText *localizedText)
 	return length;
 }
 
-Int32 decodeExtensionObject(char * const buf, Int32 *pos,
+Int32 decodeExtensionObject(char const * const buf, Int32 *pos,
 		UA_ExtensionObject *dstExtensionObject)
 {
 	//TODO to be implemented
@@ -1204,7 +1217,7 @@ Int32 ExtensionObject_calcSize(UA_ExtensionObject *extensionObject)
 	return length;
 }
 
-Int32 decodeVariant(char * const buf, Int32 *pos, UA_Variant *dstVariant)
+Int32 decodeVariant(char const * const buf, Int32 *pos, UA_Variant *dstVariant)
 {
 	decoder_decodeBuiltInDatatype(buf, BYTE, pos, &(dstVariant->EncodingMask));
 
@@ -1281,7 +1294,7 @@ Int32 Variant_calcSize(UA_Variant *variant)
 	return length;
 }
 
-Int32 decodeDataValue(char* const buf, Int32 *pos, UA_DataValue *dstDataValue)
+Int32 decodeDataValue(char const * const buf, Int32 *pos, UA_DataValue *dstDataValue)
 {
 
 	decoder_decodeBuiltInDatatype(buf, BYTE, pos,
@@ -1393,7 +1406,7 @@ Int32 DataValue_calcSize(UA_DataValue *dataValue)
  * Chapter: 7.9
  * Page: 116
  */
-Int32 decodeDiagnosticInfo(char *buf, Int32 *pos,
+Int32 decodeDiagnosticInfo(char const * const buf, Int32 *pos,
 		UA_DiagnosticInfo *dstDiagnosticInfo)
 {
 
@@ -1553,26 +1566,32 @@ Int32 diagnosticInfo_calcSize(UA_DiagnosticInfo *diagnosticInfo)
 Int32 decodeRequestHeader(const AD_RawMessage *srcRaw, Int32 *pos,
 		UA_AD_RequestHeader *dstRequestHeader)
 {
+	return decoder_decodeRequestHeader(srcRaw->message, pos, dstRequestHeader);
+}
+
+Int32 decoder_decodeRequestHeader(char const * const message, Int32 *pos,
+		UA_AD_RequestHeader *dstRequestHeader)
+{
 
-	decoder_decodeBuiltInDatatype(srcRaw->message, NODE_ID, pos,
+	decoder_decodeBuiltInDatatype(message, NODE_ID, pos,
 			&(dstRequestHeader->authenticationToken));
 
-	decoder_decodeBuiltInDatatype(srcRaw->message, DATE_TIME, pos,
+	decoder_decodeBuiltInDatatype(message, DATE_TIME, pos,
 			&(dstRequestHeader->timestamp));
 	//dstRequestHeader->timestamp = decodeUADateTime(srcRaw->message, pos);
 	//TODO check integer id - uint or int type
-	decoder_decodeBuiltInDatatype(srcRaw->message, INT32, pos,
+	decoder_decodeBuiltInDatatype(message, INT32, pos,
 			&(dstRequestHeader->requestHandle));
 
 	//dstRequestHeader->requestHandle = decodeIntegerId(srcRaw->message, pos);
-	decoder_decodeBuiltInDatatype(srcRaw->message, UINT32, pos,
+	decoder_decodeBuiltInDatatype(message, UINT32, pos,
 			&(dstRequestHeader->returnDiagnostics));
 	//dstRequestHeader->returnDiagnostics = decodeUInt32(srcRaw->message, pos);
 
-	decoder_decodeBuiltInDatatype(srcRaw->message, STRING, pos,
+	decoder_decodeBuiltInDatatype(message, STRING, pos,
 			&(dstRequestHeader->auditEntryId));
 	//decodeUAString(srcRaw->message, pos, &dstRequestHeader->auditEntryId);
-	decoder_decodeBuiltInDatatype(srcRaw->message, UINT32, pos,
+	decoder_decodeBuiltInDatatype(message, UINT32, pos,
 			&(dstRequestHeader->timeoutHint));
 	//dstRequestHeader->timeoutHint = decodeUInt32(srcRaw->message, pos);
 
@@ -1588,7 +1607,7 @@ Int32 decodeRequestHeader(const AD_RawMessage *srcRaw, Int32 *pos,
  * Page: 133
  */
 /** \copydoc encodeResponseHeader */
-Int32 encodeResponseHeader(const UA_AD_ResponseHeader *responseHeader, Int32 *pos,
+Int32 encodeResponseHeader(UA_AD_ResponseHeader const * responseHeader, Int32 *pos,
 		UA_ByteString *dstBuf)
 {
 	encodeUADateTime(responseHeader->timestamp, pos, dstBuf->Data);

+ 19 - 19
src/opcua_binaryEncDec.h

@@ -27,7 +27,7 @@
  * @param dstStructure
  * @return
  */
-Int32 decoder_decodeBuiltInDatatype(char *srcBuf, Int32 type, Int32 *pos,
+Int32 decoder_decodeBuiltInDatatype(char const * srcBuf, Int32 type, Int32 *pos,
 		void *dstStructure);
 /**
  *
@@ -46,7 +46,7 @@ Int32 encoder_encodeBuiltInDatatype(void *data, Int32 type, Int32 *pos, char *ds
  * @param dst
  * @return
  */
-Int32 decodeBoolean(char * const buf, Int32 *pos, Boolean *dst);
+Int32 decodeBoolean(char const * buf, Int32 *pos, Boolean *dst);
 /**
  *
  * @param value
@@ -61,7 +61,7 @@ void encodeBoolean(Boolean value, Int32 *pos, char *dstBuf);
  * @param dst
  * @return
  */
-Int32 decodeSByte(char * const buf, Int32 *pos, SByte *dst);
+Int32 decodeSByte(char const * buf, Int32 *pos, SByte *dst);
 /**
  *
  * @param value
@@ -76,7 +76,7 @@ void encodeSByte(SByte value, Int32 *pos, char *dstBuf);
  * @param dst
  * @return
  */
-Int32 decodeByte(char *const buf, Int32 *pos,Byte *dst);
+Int32 decodeByte(char const * buf, Int32 *pos,Byte *dst);
 /**
  *
  * @param value
@@ -90,7 +90,7 @@ void encodeByte(Byte value, Int32 *pos, char *dstBuf);
  * @param pos
  * @return
  */
-Int32 decodeUInt16(char *const buf, Int32 *pos, UInt16 *dst);
+Int32 decodeUInt16(char const * buf, Int32 *pos, UInt16 *dst);
 /**
  *
  * @param value
@@ -105,7 +105,7 @@ void encodeUInt16(UInt16 value, Int32 *pos, char *dstBuf);
  * @param dst
  * @return
  */
-Int32 decodeInt16(char *const buf, Int32 *pos, Int16 *dst);
+Int32 decodeInt16(char const * buf, Int32 *pos, Int16 *dst);
 /**
  *
  * @param value
@@ -120,7 +120,7 @@ void encodeInt16(Int16 value, Int32 *pos, char *dstBuf);
  * @param dst
  * @return
  */
-Int32 decodeInt32(char *const buf, Int32 *pos, Int32 *dst);
+Int32 decodeInt32(char const * buf, Int32 *pos, Int32 *dst);
 /**
  *
  * @param value
@@ -135,7 +135,7 @@ void encodeInt32(Int32 value, Int32 *pos, char *dstBuf);
  * @param dst
  * @return
  */
-Int32 decodeUInt32(char *const buf, Int32 *pos, UInt32 *dst);
+Int32 decodeUInt32(char const * const buf, Int32 *pos, UInt32 *dst);
 /**
  *
  * @param value
@@ -150,7 +150,7 @@ void encodeUInt32(UInt32 value, Int32 *pos, char *dstBuf);
  * @param dst
  * @return
  */
-Int32 decodeInt64(char *const buf, Int32 *pos,Int64 *dst);
+Int32 decodeInt64(char const * buf, Int32 *pos,Int64 *dst);
 /**
  *
  * @param value
@@ -165,7 +165,7 @@ void encodeInt64(Int64 value, Int32 *pos, char *dstBuf);
  * @param dst
  * @return
  */
-Int32 decodeUInt64(char *const buf, Int32 *pos, UInt64 *dst);
+Int32 decodeUInt64(char const * buf, Int32 *pos, UInt64 *dst);
 /**
  *
  * @param value
@@ -180,7 +180,7 @@ void encodeUInt64(UInt64 value, Int32 *pos, char *dstBuf);
  * @param dstNodeId		receiver of the nodeid structure
  * @param return		success = 0
  */
-Int32 decodeUANodeId(char *const buf, Int32 *pos, UA_NodeId *dstNodeId);
+Int32 decodeUANodeId(char const * buf, Int32 *pos, UA_NodeId *dstNodeId);
 /**
  *
  * @param buf
@@ -188,7 +188,7 @@ Int32 decodeUANodeId(char *const buf, Int32 *pos, UA_NodeId *dstNodeId);
  * @param dst
  * @return
  */
-Int32 decodeFloat(char *buf, Int32 *pos, Float *dst);
+Int32 decodeFloat(char const * buf, Int32 *pos, Float *dst);
 /**
  *
  * @param value
@@ -204,7 +204,7 @@ Int32 encodeFloat(Float value,Int32 *pos,char *dstBuf);
  * @param dst
  * @return
  */
-Int32 decodeDouble(char *buf, Int32 *pos, Double *dst);
+Int32 decodeDouble(char const * buf, Int32 *pos, Double *dst);
 /**
  *
  * @param value
@@ -236,7 +236,7 @@ Int32 encodeUAGuid(UA_Guid *srcGuid, Int32 *pos, char *buf);
  * @param dstGUID
  * @return
  */
-Int32 decodeUAGuid(char *const buf, Int32 *pos, UA_Guid *dstGUID);
+Int32 decodeUAGuid(char const * buf, Int32 *pos, UA_Guid *dstGUID);
 /**
  *
  * @param buf
@@ -244,14 +244,14 @@ Int32 decodeUAGuid(char *const buf, Int32 *pos, UA_Guid *dstGUID);
  * @param dst
  * @return
  */
-Int32 decodeUAStatusCode(char *const buf, Int32 *pos,UA_StatusCode* dst);
+Int32 decodeUAStatusCode(char const * buf, Int32 *pos,UA_StatusCode* dst);
 /**
  *
  * @param buf
  * @param pos
  * @return
  */
-Int32 decodeUADateTime(char *const buf, Int32 *pos,UA_DateTime *dst);
+Int32 decodeUADateTime(char const * buf, Int32 *pos,UA_DateTime *dst);
 /**
  *
  * @param time
@@ -267,7 +267,7 @@ void encodeUADateTime(UA_DateTime time, Int32 *pos, char *dstBuf);
  * @param dstUAString
  * @return
  */
-Int32 decodeUAString(char *const buf, Int32 *pos, UA_String *dstUAString);
+Int32 decodeUAString(char const * buf, Int32 *pos, UA_String *dstUAString);
 /**
  *
  * @param byteString
@@ -289,14 +289,14 @@ Int32 encodeXmlElement(UA_XmlElement *xmlElement, Int32 *pos, char *dstBuf);
  * @param xmlElement
  * @return
  */
-Int32 decodeXmlElement(char * const buf, Int32* pos, UA_XmlElement *xmlElement);
+Int32 decodeXmlElement(char const * buf, Int32* pos, UA_XmlElement *xmlElement);
 /**
  *
  * @param buf
  * @param pos
  * @return
  */
-Int32 decodeIntegerId(char* buf, Int32 *pos, Int32* dst);
+Int32 decodeIntegerId(char const * buf, Int32 *pos, Int32* dst);
 /**
  *
  * @param integerId

+ 5 - 1
src/opcua_builtInDatatypes.c

@@ -7,7 +7,7 @@
 
 
 #include "opcua_builtInDatatypes.h"
-
+#include <stdio.h>
 
 Int32 UA_String_compare(UA_String *string1,UA_String *string2)
 {
@@ -38,3 +38,7 @@ Int32 UA_ByteString_compare(UA_ByteString *string1,UA_ByteString *string2)
 {
 	return UA_String_compare((UA_String*)string1,(UA_String*)string2);
 }
+
+void UA_String_printf(char* label, UA_ByteString* string) {
+	printf("%s %.*s\n", label, string->Length, (char*) string->Data);
+}

+ 7 - 1
src/opcua_builtInDatatypes.h

@@ -236,6 +236,12 @@ typedef enum UA_IdentifierType
 }
 UA_IdentifierType;
 
+/**
+ * NodeIds
+* Part: 6
+* Chapter: 5.2.2.9
+* Table 5
+*/
 typedef enum UA_NodeIdEncodingValuesType
 {
 	// Some Values are called the same as previous Enumerations so we need
@@ -256,7 +262,7 @@ UA_NodeIdEncodingValuesType;
 */
 typedef struct UA_NodeId
 {
-	Int32 EncodingByte; //enum BID_NodeIdEncodingValuesType
+	Byte   EncodingByte; //enum BID_NodeIdEncodingValuesType
 	UInt16 Namespace;
 
     union

+ 31 - 19
src/opcua_secureChannelLayer.c

@@ -18,7 +18,6 @@ Int32 SL_secureChannel_open(const UA_connection *connection,
 		const SL_AsymmetricAlgorithmSecurityHeader *AASHeader,
 		const SL_SequenceHeader *SequenceHeader)
 {
-
 	UA_AD_ResponseHeader responseHeader;
 	AD_RawMessage rawMessage;
 	Int32 position = 0;
@@ -70,7 +69,9 @@ Int32 SL_createSecurityToken(UA_connection *connection, Int32 lifeTime)
 }
 
 
-
+/* 62451-6 §6.4.4, Table 34
+ *
+ */
 Int32 SL_processMessage(UA_connection *connection, UA_ByteString message)
 {
 	Int32 pos = 0;
@@ -80,13 +81,14 @@ Int32 SL_processMessage(UA_connection *connection, UA_ByteString message)
 	Int32 requestType;
 	Int32 securityMode;
 	Int32 requestedLifetime;
-	decoder_decodeBuiltInDatatype(message,NODE_ID,&pos,ServiceRequestType);
+
+	decoder_decodeBuiltInDatatype(message.Data,NODE_ID,&pos,&ServiceRequestType);
 
 	if(ServiceRequestType.EncodingByte == NIEVT_FOUR_BYTE)
 	{
 		if(ServiceRequestType.Identifier.Numeric == 446) // OpensecureChannelRequest
 		{
-			decodeRequestHeader(message, &pos, requestHeader);
+			decoder_decodeRequestHeader(message.Data, &pos, &requestHeader);
 			decoder_decodeBuiltInDatatype(message.Data,UINT32, &pos, &clientProtocolVersion);
 
 			if(clientProtocolVersion != connection->transportLayer.remoteConf.protocolVersion)
@@ -96,8 +98,9 @@ Int32 SL_processMessage(UA_connection *connection, UA_ByteString message)
 				//TODO ERROR_Bad_ProtocolVersionUnsupported
 
 			}
+
 			//securityTokenRequestType
-			decoder_decodeBuiltInDatatype(message,INT32,&pos,requestType);
+			decoder_decodeBuiltInDatatype(message.Data,INT32,&pos,&requestType);
 			switch(requestType)
 			{
 			case securityToken_ISSUE:
@@ -107,6 +110,7 @@ Int32 SL_processMessage(UA_connection *connection, UA_ByteString message)
 					//TODO return ERROR
 					return UA_ERROR;
 				}
+				printf("TODO: create new token for a new SecureChannel\n");
 			//	SL_createNewToken(connection);
 				break;
 			case securityToken_RENEW:
@@ -116,10 +120,12 @@ Int32 SL_processMessage(UA_connection *connection, UA_ByteString message)
 					//TODO return ERROR
 					return UA_ERROR;
 				}
+				printf("TODO: create new token for an existing SecureChannel\n");
 				break;
 			}
+
 			//securityMode
-			decoder_decodeBuiltInDatatype(message,INT32,&pos,&securityMode);
+			decoder_decodeBuiltInDatatype(message.Data,INT32,&pos,&securityMode);
 			switch(securityMode)
 			{
 			case securityMode_INVALID:
@@ -135,7 +141,8 @@ Int32 SL_processMessage(UA_connection *connection, UA_ByteString message)
 				//TODO check if senderCertificate and ReceiverCertificateThumbprint are present
 				break;
 			}
-			decoder_decodeBuiltInDatatype(message,INT32,&pos,&requestedLifetime);
+			// requestedLifetime
+			decoder_decodeBuiltInDatatype(message.Data,INT32,&pos,&requestedLifetime);
 			//TODO process requestedLifetime
 		}
 		else
@@ -180,8 +187,10 @@ void SL_receive(UA_connection *connection, UA_ByteString *serviceMessage)
 		{
 
 		case packetType_OPN : /* openSecureChannel Message received */
-
 				decodeAASHeader(&secureChannelPacket,&pos,&AAS_Header);
+				UA_String_printf("AAS_Header.ReceiverThumbprint=", &(AAS_Header.ReceiverThumbprint));
+				UA_String_printf("AAS_Header.SecurityPolicyUri=", &(AAS_Header.SecurityPolicyUri));
+				UA_String_printf("AAS_Header.SenderCertificate=", &(AAS_Header.SenderCertificate));
 				if(SCM_Header.SecureChannelId != 0)
 				{
 
@@ -199,8 +208,7 @@ void SL_receive(UA_connection *connection, UA_ByteString *serviceMessage)
 				connection->secureLayer.sequenceNumber = SequenceHeader.SequenceNumber;
 
 				//SL_decrypt(&secureChannelPacket);
-
-				message.Data = secureChannelPacket.Data[pos];
+				message.Data = &secureChannelPacket.Data[pos];
 				message.Length = secureChannelPacket.Length - pos;
 
 				SL_processMessage(connection, message);
@@ -302,12 +310,15 @@ void SL_receive(UA_connection *connection, UA_ByteString *serviceMessage)
 Int32 decodeSCMHeader(UA_ByteString *rawMessage,Int32 *pos,
 		SL_SecureConversationMessageHeader* SC_Header)
 {
+	UInt32 err;
 	printf("decodeSCMHeader - entered \n");
-	SC_Header->MessageType = TL_getPacketType(rawMessage);
-	*pos += 3;//TL_MESSAGE_TYPE_LEN;
+	// LU: wild guess - reset pos, we want to reread the message type again
+	*pos = 0;
+	SC_Header->MessageType = TL_getPacketType(rawMessage, pos);
 	SC_Header->IsFinal = rawMessage->Data[*pos];
-	SC_Header->MessageSize = decodeUInt32(rawMessage, *pos);
-	SC_Header->SecureChannelId = decodeUInt32(rawMessage, *pos);
+	*pos += 1;
+	decodeUInt32(rawMessage->Data, pos, &(SC_Header->MessageSize));
+	decodeUInt32(rawMessage->Data, pos, &(SC_Header->SecureChannelId));
 	return UA_NO_ERROR;
 
 }
@@ -346,8 +357,8 @@ Int32 encodeSCMHeader(SL_SecureConversationMessageHeader *SC_Header,
 Int32 decodeSequenceHeader(UA_ByteString *rawMessage, Int32 *pos,
 		SL_SequenceHeader *SequenceHeader)
 {
-	SequenceHeader->RequestId = decodeUInt32(rawMessage->Data, pos);
-	SequenceHeader->SequenceNumber = decodeUInt32(rawMessage->Data, pos);
+	decodeUInt32(rawMessage->Data, pos, &(SequenceHeader->RequestId));
+	decodeUInt32(rawMessage->Data, pos, &(SequenceHeader->SequenceNumber));
 	return UA_NO_ERROR;
 }
 Int32 encodeSequenceHeader(SL_SequenceHeader *sequenceHeader,Int32 *pos,
@@ -363,11 +374,12 @@ Int32 decodeAASHeader(UA_ByteString *rawMessage, Int32 *pos,
 	SL_AsymmetricAlgorithmSecurityHeader* AAS_Header)
 {
 	Int32 err = 0;
-	err += decodeUAByteString(rawMessage->Data,pos,AAS_Header->SecurityPolicyUri);
-	err += decodeUAByteString(rawMessage->Data,pos,AAS_Header->SenderCertificate);
-	err += decodeUAByteString(rawMessage->Data,pos,AAS_Header->ReceiverThumbprint);
+	err += decodeUAByteString(rawMessage->Data,pos,&(AAS_Header->SecurityPolicyUri));
+	err += decodeUAByteString(rawMessage->Data,pos,&(AAS_Header->SenderCertificate));
+	err += decodeUAByteString(rawMessage->Data,pos,&(AAS_Header->ReceiverThumbprint));
 	return err;
 }
+
 Int32 encodeAASHeader(SL_AsymmetricAlgorithmSecurityHeader *AAS_Header,
 		Int32 *pos, AD_RawMessage* dstRawMessage)
 {

+ 10 - 10
src/opcua_transportLayer.c

@@ -113,9 +113,11 @@ Int32 TL_receive(UA_connection *connection, UA_ByteString *packet)
 	return UA_NO_ERROR;
 }
 
+#define Cmp3Byte(data,pos,a,b,c) (*((Int32*) ((data)+(pos))) & 0xFFFFFF) == (Int32)(((Byte)(a))|((Byte)(b))<<8|((Byte)(c))<<16)
 
 Int32 TL_getPacketType(UA_ByteString *packet, Int32 *pos)
 {
+	Int32 retVal = -1;
 	printf("TL_getPacketType - entered \n");
 	printf("TL_getPacketType - pos = %d \n",*pos);
 	//printf(packet->Data[*pos]);
@@ -125,47 +127,45 @@ Int32 TL_getPacketType(UA_ByteString *packet, Int32 *pos)
 	   packet->Data[*pos+2] == 'L')
 	{
 		*pos += 3 * sizeof(Byte);
-		return packetType_HEL;
+		retVal = packetType_HEL;
 	}
 	else if(packet->Data[*pos] == 'A' &&
 	        packet->Data[*pos+1] == 'C' &&
 	        packet->Data[*pos+2] == 'K')
 	{
 		*pos += 3 * sizeof(Byte);
-		return packetType_ACK;
+		retVal = packetType_ACK;
 	}
 	else if(packet->Data[*pos] == 'E' &&
 			packet->Data[*pos+1] == 'R' &&
 			packet->Data[*pos+2] == 'R')
 	{
 		*pos += 3 * sizeof(Byte);
-		return packetType_ERR;
+		retVal =  packetType_ERR;
 	}
 	else if(packet->Data[*pos] == 'O' &&
 	        packet->Data[*pos+1] == 'P' &&
 	        packet->Data[*pos+2] == 'N')
 	{
 		*pos += 3 * sizeof(Byte);
-		return packetType_OPN;
+		retVal =  packetType_OPN;
 	}
 	else if(packet->Data[*pos] == 'C' &&
 	        packet->Data[*pos+1] == 'L' &&
 	        packet->Data[*pos+2] == 'O')
 	{
 		*pos += 3 * sizeof(Byte);
-		return packetType_CLO;
+		retVal =  packetType_CLO;
 	}
 	else if(packet->Data[*pos] == 'M' &&
 			packet->Data[*pos+1] == 'S' &&
 			packet->Data[*pos+2] == 'G')
 	{
 		*pos += 3 * sizeof(Byte);
-		return packetType_MSG;
+		retVal =  packetType_MSG;
 	}
-
-
-	return -1;//TODO ERROR no valid message received
-
+	//TODO retVal == -1 -- ERROR no valid message received
+	return retVal;
 }