|
@@ -29,7 +29,7 @@ UA_TYPE_NEW_DEFAULT(UA_Boolean)
|
|
|
UA_TYPE_COPY_DEFAULT(UA_Boolean)
|
|
|
#ifdef DEBUG
|
|
|
void UA_Boolean_print(const UA_Boolean *p, FILE *stream) {
|
|
|
- if(p == UA_NULL || stream == UA_NULL) return;
|
|
|
+ if(!p || !stream) return;
|
|
|
if(*p) fprintf(stream, "UA_TRUE");
|
|
|
else fprintf(stream, "UA_FALSE");
|
|
|
}
|
|
@@ -39,7 +39,7 @@ void UA_Boolean_print(const UA_Boolean *p, FILE *stream) {
|
|
|
UA_TYPE_DEFAULT(UA_SByte)
|
|
|
#ifdef DEBUG
|
|
|
void UA_SByte_print(const UA_SByte *p, FILE *stream) {
|
|
|
- if(p == UA_NULL || stream == UA_NULL) return;
|
|
|
+ if(!p || !stream) return;
|
|
|
UA_SByte x = *p;
|
|
|
fprintf(stream, "%s%x\n", x < 0 ? "-" : "", x < 0 ? -x : x);
|
|
|
}
|
|
@@ -49,7 +49,7 @@ void UA_SByte_print(const UA_SByte *p, FILE *stream) {
|
|
|
UA_TYPE_DEFAULT(UA_Byte)
|
|
|
#ifdef DEBUG
|
|
|
void UA_Byte_print(const UA_Byte *p, FILE *stream) {
|
|
|
- if(p == UA_NULL || stream == UA_NULL) return;
|
|
|
+ if(!p || !stream) return;
|
|
|
fprintf(stream, "%x", *p);
|
|
|
}
|
|
|
#endif
|
|
@@ -58,7 +58,7 @@ void UA_Byte_print(const UA_Byte *p, FILE *stream) {
|
|
|
UA_TYPE_DEFAULT(UA_Int16)
|
|
|
#ifdef DEBUG
|
|
|
void UA_Int16_print(const UA_Int16 *p, FILE *stream) {
|
|
|
- if(p == UA_NULL || stream == UA_NULL) return;
|
|
|
+ if(!p || !stream) return;
|
|
|
fprintf(stream, "%d", *p);
|
|
|
}
|
|
|
#endif
|
|
@@ -67,7 +67,7 @@ void UA_Int16_print(const UA_Int16 *p, FILE *stream) {
|
|
|
UA_TYPE_DEFAULT(UA_UInt16)
|
|
|
#ifdef DEBUG
|
|
|
void UA_UInt16_print(const UA_UInt16 *p, FILE *stream) {
|
|
|
- if(p == UA_NULL || stream == UA_NULL) return;
|
|
|
+ if(!p || !stream) return;
|
|
|
fprintf(stream, "%u", *p);
|
|
|
}
|
|
|
#endif
|
|
@@ -76,7 +76,7 @@ void UA_UInt16_print(const UA_UInt16 *p, FILE *stream) {
|
|
|
UA_TYPE_DEFAULT(UA_Int32)
|
|
|
#ifdef DEBUG
|
|
|
void UA_Int32_print(const UA_Int32 *p, FILE *stream) {
|
|
|
- if(p == UA_NULL || stream == UA_NULL) return;
|
|
|
+ if(!p || !stream) return;
|
|
|
fprintf(stream, "%d", *p);
|
|
|
}
|
|
|
|
|
@@ -86,7 +86,7 @@ void UA_Int32_print(const UA_Int32 *p, FILE *stream) {
|
|
|
UA_TYPE_DEFAULT(UA_UInt32)
|
|
|
#ifdef DEBUG
|
|
|
void UA_UInt32_print(const UA_UInt32 *p, FILE *stream) {
|
|
|
- if(p == UA_NULL || stream == UA_NULL) return;
|
|
|
+ if(!p || !stream) return;
|
|
|
fprintf(stream, "%u", *p);
|
|
|
}
|
|
|
#endif
|
|
@@ -95,7 +95,7 @@ void UA_UInt32_print(const UA_UInt32 *p, FILE *stream) {
|
|
|
UA_TYPE_DEFAULT(UA_Int64)
|
|
|
#ifdef DEBUG
|
|
|
void UA_Int64_print(const UA_Int64 *p, FILE *stream) {
|
|
|
- if(p == UA_NULL || stream == UA_NULL) return;
|
|
|
+ if(!p || !stream) return;
|
|
|
fprintf(stream, "%" PRIi64, *p);
|
|
|
}
|
|
|
#endif
|
|
@@ -104,7 +104,7 @@ void UA_Int64_print(const UA_Int64 *p, FILE *stream) {
|
|
|
UA_TYPE_DEFAULT(UA_UInt64)
|
|
|
#ifdef DEBUG
|
|
|
void UA_UInt64_print(const UA_UInt64 *p, FILE *stream) {
|
|
|
- if(p == UA_NULL || stream == UA_NULL) return;
|
|
|
+ if(!p || !stream) return;
|
|
|
fprintf(stream, "%" PRIu64, *p);
|
|
|
}
|
|
|
#endif
|
|
@@ -113,7 +113,7 @@ void UA_UInt64_print(const UA_UInt64 *p, FILE *stream) {
|
|
|
UA_TYPE_DEFAULT(UA_Float)
|
|
|
#ifdef DEBUG
|
|
|
void UA_Float_print(const UA_Float *p, FILE *stream) {
|
|
|
- if(p == UA_NULL || stream == UA_NULL) return;
|
|
|
+ if(!p || !stream) return;
|
|
|
fprintf(stream, "%f", *p);
|
|
|
}
|
|
|
#endif
|
|
@@ -122,7 +122,7 @@ void UA_Float_print(const UA_Float *p, FILE *stream) {
|
|
|
UA_TYPE_DEFAULT(UA_Double)
|
|
|
#ifdef DEBUG
|
|
|
void UA_Double_print(const UA_Double *p, FILE *stream) {
|
|
|
- if(p == UA_NULL || stream == UA_NULL) return;
|
|
|
+ if(!p || !stream) return;
|
|
|
fprintf(stream, "%f", *p);
|
|
|
}
|
|
|
#endif
|
|
@@ -137,28 +137,30 @@ void UA_String_init(UA_String *p) {
|
|
|
|
|
|
UA_TYPE_DELETE_DEFAULT(UA_String)
|
|
|
void UA_String_deleteMembers(UA_String *p) {
|
|
|
- if(p && p->length > 0 && p->data != UA_NULL) {
|
|
|
+ if(p->data != UA_NULL) {
|
|
|
UA_free(p->data);
|
|
|
UA_String_init(p);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-UA_Int32 UA_String_copy(UA_String const *src, UA_String *dst) {
|
|
|
- if(!src || !dst) return UA_ERROR;
|
|
|
+UA_StatusCode UA_String_copy(UA_String const *src, UA_String *dst) {
|
|
|
+ if(!src || !dst)
|
|
|
+ return UA_STATUSCODE_BADINTERNALERROR;
|
|
|
if(src->length > 0) {
|
|
|
if(!(dst->data = UA_alloc(src->length)))
|
|
|
return UA_STATUSCODE_BADOUTOFMEMORY;
|
|
|
UA_memcpy((void *)dst->data, src->data, src->length);
|
|
|
}
|
|
|
dst->length = src->length;
|
|
|
- return UA_SUCCESS;
|
|
|
+ return UA_STATUSCODE_GOOD;
|
|
|
}
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
void UA_String_print(const UA_String *p, FILE *stream) {
|
|
|
- if(p == UA_NULL || stream == UA_NULL) return;
|
|
|
+ if(!p || !stream)
|
|
|
+ return;
|
|
|
fprintf(stream, "(UA_String){%d,", p->length);
|
|
|
- if(p->data != UA_NULL)
|
|
|
+ if(p->data)
|
|
|
fprintf(stream, "\"%.*s\"}", p->length, p->data);
|
|
|
else
|
|
|
fprintf(stream, "UA_NULL}");
|
|
@@ -173,15 +175,15 @@ UA_Int32 UA_String_copycstring(char const *src, UA_String *dst) {
|
|
|
return UA_STATUSCODE_BADOUTOFMEMORY;
|
|
|
UA_memcpy((void *)dst->data, src, dst->length);
|
|
|
}
|
|
|
- return UA_SUCCESS;
|
|
|
+ return UA_STATUSCODE_GOOD;
|
|
|
}
|
|
|
|
|
|
#define UA_STRING_COPYPRINTF_BUFSIZE 1024
|
|
|
-UA_Int32 UA_String_copyprintf(char const *fmt, UA_String *dst, ...) {
|
|
|
- UA_Int32 retval = UA_SUCCESS;
|
|
|
- char src[UA_STRING_COPYPRINTF_BUFSIZE];
|
|
|
- UA_Int32 len;
|
|
|
- va_list ap;
|
|
|
+UA_StatusCode UA_String_copyprintf(char const *fmt, UA_String *dst, ...) {
|
|
|
+ UA_StatusCode retval = UA_STATUSCODE_GOOD;
|
|
|
+ char src[UA_STRING_COPYPRINTF_BUFSIZE];
|
|
|
+ UA_Int32 len;
|
|
|
+ va_list ap;
|
|
|
va_start(ap, dst);
|
|
|
#pragma GCC diagnostic push
|
|
|
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
|
|
@@ -192,7 +194,7 @@ UA_Int32 UA_String_copyprintf(char const *fmt, UA_String *dst, ...) {
|
|
|
if(len < 0) { // FIXME: old glibc 2.0 would return -1 when truncated
|
|
|
dst->length = 0;
|
|
|
dst->data = UA_NULL;
|
|
|
- retval = UA_ERR_INVALID_VALUE;
|
|
|
+ retval = UA_STATUSCODE_BADINTERNALERROR;
|
|
|
} else {
|
|
|
// since glibc 2.1 vsnprintf returns len that would have resulted if buf were large enough
|
|
|
dst->length = ( len > UA_STRING_COPYPRINTF_BUFSIZE ? UA_STRING_COPYPRINTF_BUFSIZE : len );
|
|
@@ -224,8 +226,9 @@ void UA_String_printf(char const *label, const UA_String *string) {
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
void UA_String_printx(char const *label, const UA_String *string) {
|
|
|
- if(string == UA_NULL) {
|
|
|
- printf("%s {NULL}\n", label); return;
|
|
|
+ if(!string) {
|
|
|
+ printf("%s {NULL}\n", label);
|
|
|
+ return;
|
|
|
}
|
|
|
printf("%s {Length=%d, Data=", label, string->length);
|
|
|
if(string->length > 0) {
|
|
@@ -312,7 +315,7 @@ UA_DateTimeStruct UA_DateTime_toStruct(UA_DateTime time) {
|
|
|
return dateTimeStruct;
|
|
|
}
|
|
|
|
|
|
-UA_Int32 UA_DateTime_toString(UA_DateTime time, UA_String *timeString) {
|
|
|
+UA_StatusCode UA_DateTime_toString(UA_DateTime time, UA_String *timeString) {
|
|
|
// length of the string is 31 (incl. \0 at the end)
|
|
|
if(!(timeString->data = UA_alloc(31)))
|
|
|
return UA_STATUSCODE_BADOUTOFMEMORY;
|
|
@@ -321,7 +324,7 @@ UA_Int32 UA_DateTime_toString(UA_DateTime time, UA_String *timeString) {
|
|
|
UA_DateTimeStruct tSt = UA_DateTime_toStruct(time);
|
|
|
sprintf((char*)timeString->data, "%2d/%2d/%4d %2d:%2d:%2d.%3d.%3d.%3d", tSt.mounth, tSt.day, tSt.year,
|
|
|
tSt.hour, tSt.min, tSt.sec, tSt.milliSec, tSt.microSec, tSt.nanoSec);
|
|
|
- return UA_SUCCESS;
|
|
|
+ return UA_STATUSCODE_GOOD;
|
|
|
}
|
|
|
|
|
|
/* Guid */
|
|
@@ -343,17 +346,17 @@ void UA_Guid_init(UA_Guid *p) {
|
|
|
}
|
|
|
|
|
|
UA_TYPE_NEW_DEFAULT(UA_Guid)
|
|
|
-UA_Int32 UA_Guid_copy(UA_Guid const *src, UA_Guid *dst) {
|
|
|
- if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
|
|
|
+UA_StatusCode UA_Guid_copy(UA_Guid const *src, UA_Guid *dst) {
|
|
|
+ if(!src || !dst)
|
|
|
+ return UA_STATUSCODE_BADINTERNALERROR;
|
|
|
UA_memcpy((void *)dst, (void *)src, sizeof(UA_Guid));
|
|
|
- return UA_SUCCESS;
|
|
|
+ return UA_STATUSCODE_GOOD;
|
|
|
}
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
void UA_Guid_print(const UA_Guid *p, FILE *stream) {
|
|
|
- if(p == UA_NULL || stream == UA_NULL) return;
|
|
|
- fprintf(stream, "(UA_Guid){%u, %u %u {%x,%x,%x,%x,%x,%x,%x,%x}}", p->data1, p->data2, p->data3,
|
|
|
- p->data4[0],
|
|
|
+ if(!p || !stream) return;
|
|
|
+ fprintf(stream, "(UA_Guid){%u, %u %u {%x,%x,%x,%x,%x,%x,%x,%x}}", p->data1, p->data2, p->data3, p->data4[0],
|
|
|
p->data4[1], p->data4[2], p->data4[3], p->data4[4], p->data4[5], p->data4[6], p->data4[7]);
|
|
|
}
|
|
|
#endif
|
|
@@ -387,8 +390,8 @@ UA_Byte UA_Byte_securityPoliceNoneData[] = "http://opcfoundation.org/UA/Se
|
|
|
UA_ByteString UA_ByteString_securityPoliceNone =
|
|
|
{ sizeof(UA_Byte_securityPoliceNoneData)-1, UA_Byte_securityPoliceNoneData };
|
|
|
|
|
|
-UA_Int32 UA_ByteString_newMembers(UA_ByteString *p, UA_Int32 length) {
|
|
|
- UA_Int32 retval = UA_SUCCESS;
|
|
|
+UA_StatusCode UA_ByteString_newMembers(UA_ByteString *p, UA_Int32 length) {
|
|
|
+ UA_StatusCode retval = UA_STATUSCODE_GOOD;
|
|
|
if(length > 0) {
|
|
|
if((p->data = UA_alloc(length))) {
|
|
|
p->length = length;
|
|
@@ -396,7 +399,8 @@ UA_Int32 UA_ByteString_newMembers(UA_ByteString *p, UA_Int32 length) {
|
|
|
}
|
|
|
retval = UA_STATUSCODE_BADOUTOFMEMORY;
|
|
|
}
|
|
|
- p->length = -1;
|
|
|
+ if(length < 0)
|
|
|
+ p->length = -1;
|
|
|
p->data = UA_NULL;
|
|
|
return retval;
|
|
|
}
|
|
@@ -413,15 +417,15 @@ void UA_NodeId_init(UA_NodeId *p) {
|
|
|
}
|
|
|
|
|
|
UA_TYPE_NEW_DEFAULT(UA_NodeId)
|
|
|
-UA_Int32 UA_NodeId_copy(UA_NodeId const *src, UA_NodeId *dst) {
|
|
|
- UA_Int32 retval = UA_SUCCESS;
|
|
|
- if(src == UA_NULL || dst == UA_NULL)
|
|
|
- return UA_ERROR;
|
|
|
+UA_StatusCode UA_NodeId_copy(UA_NodeId const *src, UA_NodeId *dst) {
|
|
|
+ UA_StatusCode retval = UA_STATUSCODE_GOOD;
|
|
|
+ if(!src || !dst)
|
|
|
+ return UA_STATUSCODE_BADINTERNALERROR;
|
|
|
|
|
|
switch(src->identifierType) {
|
|
|
case UA_NODEIDTYPE_NUMERIC:
|
|
|
*dst = *src;
|
|
|
- return UA_SUCCESS;
|
|
|
+ return UA_STATUSCODE_GOOD;
|
|
|
break;
|
|
|
|
|
|
case UA_NODEIDTYPE_STRING: // Table 6, second entry
|
|
@@ -470,8 +474,7 @@ void UA_NodeId_deleteMembers(UA_NodeId *p) {
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
void UA_NodeId_print(const UA_NodeId *p, FILE *stream) {
|
|
|
- if(p == UA_NULL || stream == UA_NULL)
|
|
|
- return;
|
|
|
+ if(!p || !stream) return;
|
|
|
|
|
|
fprintf(stream, "(UA_NodeId){");
|
|
|
switch(p->identifierType) {
|
|
@@ -524,7 +527,7 @@ void UA_NodeId_print(const UA_NodeId *p, FILE *stream) {
|
|
|
#endif
|
|
|
|
|
|
UA_EQUALITY UA_NodeId_equal(const UA_NodeId *n1, const UA_NodeId *n2) {
|
|
|
- if(n1 == UA_NULL || n2 == UA_NULL || n1->namespaceIndex != n2->namespaceIndex)
|
|
|
+ if(!n1 || !n2 || n1->namespaceIndex != n2->namespaceIndex)
|
|
|
return UA_NOT_EQUAL;
|
|
|
|
|
|
switch(n1->identifierType) {
|
|
@@ -549,20 +552,24 @@ UA_EQUALITY UA_NodeId_equal(const UA_NodeId *n1, const UA_NodeId *n2) {
|
|
|
UA_Boolean UA_NodeId_isNull(const UA_NodeId *p) {
|
|
|
switch(p->identifierType) {
|
|
|
case UA_NODEIDTYPE_NUMERIC:
|
|
|
- if(p->namespaceIndex != 0 || p->identifier.numeric != 0) return UA_FALSE;
|
|
|
+ if(p->namespaceIndex != 0 || p->identifier.numeric != 0)
|
|
|
+ return UA_FALSE;
|
|
|
break;
|
|
|
|
|
|
case UA_NODEIDTYPE_STRING:
|
|
|
- if(p->namespaceIndex != 0 || p->identifier.string.length != 0) return UA_FALSE;
|
|
|
+ if(p->namespaceIndex != 0 || p->identifier.string.length != 0)
|
|
|
+ return UA_FALSE;
|
|
|
break;
|
|
|
|
|
|
case UA_NODEIDTYPE_GUID:
|
|
|
if(p->namespaceIndex != 0 ||
|
|
|
- memcmp(&p->identifier.guid, (char[sizeof(UA_Guid)]) { 0 }, sizeof(UA_Guid)) != 0) return UA_FALSE;
|
|
|
+ memcmp(&p->identifier.guid, (char[sizeof(UA_Guid)]) { 0 }, sizeof(UA_Guid)) != 0)
|
|
|
+ return UA_FALSE;
|
|
|
break;
|
|
|
|
|
|
case UA_NODEIDTYPE_BYTESTRING:
|
|
|
- if(p->namespaceIndex != 0 || p->identifier.byteString.length != 0) return UA_FALSE;
|
|
|
+ if(p->namespaceIndex != 0 || p->identifier.byteString.length != 0)
|
|
|
+ return UA_FALSE;
|
|
|
break;
|
|
|
|
|
|
default:
|
|
@@ -587,18 +594,21 @@ void UA_ExpandedNodeId_init(UA_ExpandedNodeId *p) {
|
|
|
}
|
|
|
|
|
|
UA_TYPE_NEW_DEFAULT(UA_ExpandedNodeId)
|
|
|
-UA_Int32 UA_ExpandedNodeId_copy(UA_ExpandedNodeId const *src, UA_ExpandedNodeId *dst) {
|
|
|
- UA_Int32 retval = UA_SUCCESS;
|
|
|
- if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
|
|
|
- UA_String_copy(&src->namespaceUri, &dst->namespaceUri);
|
|
|
- UA_NodeId_copy(&src->nodeId, &dst->nodeId);
|
|
|
- UA_UInt32_copy(&src->serverIndex, &dst->serverIndex);
|
|
|
+UA_StatusCode UA_ExpandedNodeId_copy(UA_ExpandedNodeId const *src, UA_ExpandedNodeId *dst) {
|
|
|
+ UA_StatusCode retval = UA_STATUSCODE_GOOD;
|
|
|
+ if(!src || !dst)
|
|
|
+ return UA_STATUSCODE_BADINTERNALERROR;
|
|
|
+ retval |= UA_String_copy(&src->namespaceUri, &dst->namespaceUri);
|
|
|
+ retval |= UA_NodeId_copy(&src->nodeId, &dst->nodeId);
|
|
|
+ dst->serverIndex = src->serverIndex;
|
|
|
+ if(retval)
|
|
|
+ UA_ExpandedNodeId_deleteMembers(dst);
|
|
|
return retval;
|
|
|
}
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
void UA_ExpandedNodeId_print(const UA_ExpandedNodeId *p, FILE *stream) {
|
|
|
- if(p == UA_NULL || stream == UA_NULL) return;
|
|
|
+ if(!p || !stream) return;
|
|
|
fprintf(stream, "(UA_ExpandedNodeId){");
|
|
|
UA_NodeId_print(&p->nodeId, stream);
|
|
|
fprintf(stream, ",");
|
|
@@ -630,23 +640,26 @@ void UA_QualifiedName_init(UA_QualifiedName *p) {
|
|
|
}
|
|
|
|
|
|
UA_TYPE_NEW_DEFAULT(UA_QualifiedName)
|
|
|
-UA_Int32 UA_QualifiedName_copy(UA_QualifiedName const *src, UA_QualifiedName *dst) {
|
|
|
- UA_Int32 retval = UA_SUCCESS;
|
|
|
- if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
|
|
|
+UA_StatusCode UA_QualifiedName_copy(UA_QualifiedName const *src, UA_QualifiedName *dst) {
|
|
|
+ UA_StatusCode retval = UA_STATUSCODE_GOOD;
|
|
|
+ if(!src || !dst)
|
|
|
+ return UA_STATUSCODE_BADINTERNALERROR;
|
|
|
retval |= UA_String_copy(&src->name, &dst->name);
|
|
|
- retval |= UA_UInt16_copy(&src->namespaceIndex, &dst->namespaceIndex);
|
|
|
+ dst->namespaceIndex = src->namespaceIndex;
|
|
|
+ if(retval)
|
|
|
+ UA_QualifiedName_deleteMembers(dst);
|
|
|
return retval;
|
|
|
|
|
|
}
|
|
|
|
|
|
-UA_Int32 UA_QualifiedName_copycstring(char const *src, UA_QualifiedName *dst) {
|
|
|
+UA_StatusCode UA_QualifiedName_copycstring(char const *src, UA_QualifiedName *dst) {
|
|
|
dst->namespaceIndex = 0;
|
|
|
return UA_String_copycstring(src, &dst->name);
|
|
|
}
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
void UA_QualifiedName_print(const UA_QualifiedName *p, FILE *stream) {
|
|
|
- if(p == UA_NULL || stream == UA_NULL) return;
|
|
|
+ if(!p || !stream) return;
|
|
|
fprintf(stream, "(UA_QualifiedName){");
|
|
|
UA_UInt16_print(&p->namespaceIndex, stream);
|
|
|
fprintf(stream, ",");
|
|
@@ -677,30 +690,33 @@ void UA_LocalizedText_init(UA_LocalizedText *p) {
|
|
|
}
|
|
|
|
|
|
UA_TYPE_NEW_DEFAULT(UA_LocalizedText)
|
|
|
-UA_Int32 UA_LocalizedText_copycstring(char const *src, UA_LocalizedText *dst) {
|
|
|
- if(dst == UA_NULL) return UA_ERROR;
|
|
|
+UA_StatusCode UA_LocalizedText_copycstring(char const *src, UA_LocalizedText *dst) {
|
|
|
+ UA_StatusCode retval = UA_STATUSCODE_GOOD;
|
|
|
+ if(!dst)
|
|
|
+ return UA_STATUSCODE_BADINTERNALERROR;
|
|
|
UA_LocalizedText_init(dst);
|
|
|
-
|
|
|
- UA_Int32 retval = UA_SUCCESS;
|
|
|
retval |= UA_String_copycstring("en", &dst->locale); // TODO: Are language codes upper case?
|
|
|
- if(retval != UA_SUCCESS) return retval;
|
|
|
retval |= UA_String_copycstring(src, &dst->text);
|
|
|
+ if(retval)
|
|
|
+ UA_LocalizedText_deleteMembers(dst);
|
|
|
return retval;
|
|
|
}
|
|
|
|
|
|
-UA_Int32 UA_LocalizedText_copy(UA_LocalizedText const *src, UA_LocalizedText *dst) {
|
|
|
- UA_Int32 retval = UA_SUCCESS;
|
|
|
- if(!src || !dst) return UA_ERROR;
|
|
|
+UA_StatusCode UA_LocalizedText_copy(UA_LocalizedText const *src, UA_LocalizedText *dst) {
|
|
|
+ UA_Int32 retval = UA_STATUSCODE_GOOD;
|
|
|
+ if(!src || !dst)
|
|
|
+ return UA_STATUSCODE_BADINTERNALERROR;
|
|
|
UA_LocalizedText_init(dst);
|
|
|
retval |= UA_String_copy(&src->locale, &dst->locale);
|
|
|
- if(retval != UA_SUCCESS) return retval;
|
|
|
retval |= UA_String_copy(&src->text, &dst->text);
|
|
|
+ if(retval)
|
|
|
+ UA_LocalizedText_deleteMembers(dst);
|
|
|
return retval;
|
|
|
}
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
void UA_LocalizedText_print(const UA_LocalizedText *p, FILE *stream) {
|
|
|
- if(p == UA_NULL || stream == UA_NULL) return;
|
|
|
+ if(!p || !stream) return;
|
|
|
fprintf(stream, "(UA_LocalizedText){");
|
|
|
UA_String_print(&p->locale, stream);
|
|
|
fprintf(stream, ",");
|
|
@@ -725,18 +741,21 @@ void UA_ExtensionObject_init(UA_ExtensionObject *p) {
|
|
|
}
|
|
|
|
|
|
UA_TYPE_NEW_DEFAULT(UA_ExtensionObject)
|
|
|
-UA_Int32 UA_ExtensionObject_copy(UA_ExtensionObject const *src, UA_ExtensionObject *dst) {
|
|
|
- UA_Int32 retval = UA_SUCCESS;
|
|
|
- if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
|
|
|
+UA_StatusCode UA_ExtensionObject_copy(UA_ExtensionObject const *src, UA_ExtensionObject *dst) {
|
|
|
+ UA_StatusCode retval = UA_STATUSCODE_GOOD;
|
|
|
+ if(!src || !dst)
|
|
|
+ return UA_STATUSCODE_BADINTERNALERROR;
|
|
|
dst->encoding = src->encoding;
|
|
|
retval |= UA_ByteString_copy(&src->body, &dst->body);
|
|
|
retval |= UA_NodeId_copy(&src->typeId, &dst->typeId);
|
|
|
+ if(retval)
|
|
|
+ UA_ExtensionObject_deleteMembers(dst);
|
|
|
return retval;
|
|
|
}
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
void UA_ExtensionObject_print(const UA_ExtensionObject *p, FILE *stream) {
|
|
|
- if(p == UA_NULL || stream == UA_NULL) return;
|
|
|
+ if(!p || !stream) return;
|
|
|
fprintf(stream, "(UA_ExtensionObject){");
|
|
|
UA_NodeId_print(&p->typeId, stream);
|
|
|
if(p->encoding == UA_EXTENSIONOBJECT_ENCODINGMASK_BODYISBYTESTRING)
|
|
@@ -769,22 +788,25 @@ void UA_DataValue_init(UA_DataValue *p) {
|
|
|
}
|
|
|
|
|
|
UA_TYPE_NEW_DEFAULT(UA_DataValue)
|
|
|
-UA_Int32 UA_DataValue_copy(UA_DataValue const *src, UA_DataValue *dst) {
|
|
|
- UA_Int32 retval = UA_SUCCESS;
|
|
|
- if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
|
|
|
- UA_Byte_copy(&src->encodingMask, &dst->encodingMask);
|
|
|
- UA_Int16_copy(&src->serverPicoseconds, &dst->serverPicoseconds);
|
|
|
- UA_DateTime_copy(&src->serverTimestamp, &dst->serverTimestamp);
|
|
|
- UA_Int16_copy(&src->sourcePicoseconds, &dst->sourcePicoseconds);
|
|
|
- UA_DateTime_copy(&src->sourceTimestamp, &dst->sourceTimestamp);
|
|
|
- UA_StatusCode_copy(&src->status, &dst->status);
|
|
|
- UA_Variant_copy(&src->value, &dst->value);
|
|
|
+UA_StatusCode UA_DataValue_copy(UA_DataValue const *src, UA_DataValue *dst) {
|
|
|
+ UA_StatusCode retval = UA_STATUSCODE_GOOD;
|
|
|
+ if(!src || !dst)
|
|
|
+ return UA_STATUSCODE_BADINTERNALERROR;
|
|
|
+ dst->encodingMask = src->encodingMask;
|
|
|
+ dst->serverPicoseconds = src->serverPicoseconds;
|
|
|
+ retval |= UA_DateTime_copy(&src->serverTimestamp, &dst->serverTimestamp);
|
|
|
+ dst->sourcePicoseconds = src->sourcePicoseconds;
|
|
|
+ retval |= UA_DateTime_copy(&src->sourceTimestamp, &dst->sourceTimestamp);
|
|
|
+ dst->status = src->status;
|
|
|
+ retval |= UA_Variant_copy(&src->value, &dst->value);
|
|
|
+ if(retval)
|
|
|
+ UA_DataValue_deleteMembers(dst);
|
|
|
return retval;
|
|
|
}
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
void UA_DataValue_print(const UA_DataValue *p, FILE *stream) {
|
|
|
- if(p == UA_NULL || stream == UA_NULL) return;
|
|
|
+ if(!p || !stream) return;
|
|
|
fprintf(stream, "(UA_DataValue){");
|
|
|
UA_Byte_print(&p->encodingMask, stream);
|
|
|
fprintf(stream, ",");
|
|
@@ -807,7 +829,7 @@ void UA_DataValue_print(const UA_DataValue *p, FILE *stream) {
|
|
|
UA_TYPE_DELETE_DEFAULT(UA_Variant)
|
|
|
void UA_Variant_deleteMembers(UA_Variant *p) {
|
|
|
if(p->storageType == UA_VARIANT_DATA) {
|
|
|
- if(p->storage.data.dataPtr != UA_NULL) {
|
|
|
+ if(p->storage.data.dataPtr) {
|
|
|
if(p->storage.data.arrayLength == 1)
|
|
|
p->vt->delete(p->storage.data.dataPtr);
|
|
|
else
|
|
@@ -839,9 +861,10 @@ void UA_Variant_init(UA_Variant *p) {
|
|
|
}
|
|
|
|
|
|
/** It is not allowed to copy into a variant that points to an external data source. */
|
|
|
-UA_Int32 UA_Variant_copy(UA_Variant const *src, UA_Variant *dst) {
|
|
|
- if(!src || !dst || dst->storageType == UA_VARIANT_DATASOURCE) return UA_ERROR;
|
|
|
- UA_Int32 retval = UA_SUCCESS;
|
|
|
+UA_StatusCode UA_Variant_copy(UA_Variant const *src, UA_Variant *dst) {
|
|
|
+ UA_StatusCode retval = UA_STATUSCODE_GOOD;
|
|
|
+ if(!src || !dst || dst->storageType == UA_VARIANT_DATASOURCE)
|
|
|
+ return UA_STATUSCODE_BADINTERNALERROR;
|
|
|
|
|
|
UA_VariantData *dstdata = &dst->storage.data;
|
|
|
const UA_VariantData *srcdata;
|
|
@@ -849,20 +872,17 @@ UA_Int32 UA_Variant_copy(UA_Variant const *src, UA_Variant *dst) {
|
|
|
srcdata = &src->storage.data;
|
|
|
else {
|
|
|
retval |= src->storage.datasource.read(src->storage.datasource.identifier, &srcdata);
|
|
|
- if(retval != UA_SUCCESS)
|
|
|
- return retval;
|
|
|
+ if(retval) return retval;
|
|
|
}
|
|
|
|
|
|
// now copy from srcdata to dstdata.
|
|
|
dst->vt = src->vt;
|
|
|
retval |= UA_Array_copy(srcdata->dataPtr, srcdata->arrayLength, src->vt, &dstdata->dataPtr);
|
|
|
- if(retval != UA_SUCCESS)
|
|
|
- goto clean_up;
|
|
|
+ if(retval) goto clean_up;
|
|
|
dstdata->arrayLength = srcdata->arrayLength;
|
|
|
- if(srcdata->arrayDimensions != UA_NULL) {
|
|
|
+ if(srcdata->arrayDimensions) {
|
|
|
retval |= UA_Array_copy(srcdata->arrayDimensions, srcdata->arrayDimensionsLength, &UA_[UA_INT32], (void **)&dstdata->arrayDimensions);
|
|
|
- if(retval != UA_SUCCESS)
|
|
|
- goto clean_up2;
|
|
|
+ if(retval) goto clean_up2;
|
|
|
dstdata->arrayDimensionsLength = srcdata->arrayDimensionsLength;
|
|
|
}
|
|
|
|
|
@@ -874,7 +894,7 @@ UA_Int32 UA_Variant_copy(UA_Variant const *src, UA_Variant *dst) {
|
|
|
|
|
|
// clean ups are falling through to the "lower levels"
|
|
|
clean_up2:
|
|
|
- if(dstdata->arrayDimensions != UA_NULL)
|
|
|
+ if(dstdata->arrayDimensions)
|
|
|
UA_Array_delete(dstdata->dataPtr, dstdata->arrayLength, src->vt);
|
|
|
|
|
|
clean_up:
|
|
@@ -885,31 +905,36 @@ UA_Int32 UA_Variant_copy(UA_Variant const *src, UA_Variant *dst) {
|
|
|
}
|
|
|
|
|
|
/** Copies data into a variant. The target variant has always a storagetype UA_VARIANT_DATA */
|
|
|
-UA_Int32 UA_Variant_copySetValue(UA_Variant *v, const UA_VTable_Entry *vt, const void *value) {
|
|
|
- if(v == UA_NULL || vt == UA_NULL || value == UA_NULL)
|
|
|
- return UA_ERROR;
|
|
|
+UA_StatusCode UA_Variant_copySetValue(UA_Variant *v, const UA_VTable_Entry *vt, const void *value) {
|
|
|
+ UA_StatusCode retval = UA_STATUSCODE_GOOD;
|
|
|
+ if(!v || !vt || !value)
|
|
|
+ return UA_STATUSCODE_BADINTERNALERROR;
|
|
|
UA_Variant_init(v);
|
|
|
v->vt = vt;
|
|
|
v->storage.data.arrayLength = 1; // no array but a single entry
|
|
|
- UA_Int32 retval = UA_SUCCESS;
|
|
|
retval |= vt->new(&v->storage.data.dataPtr);
|
|
|
- if(retval == UA_SUCCESS)
|
|
|
- retval |= vt->copy(value, v->storage.data.dataPtr);
|
|
|
+ retval |= vt->copy(value, v->storage.data.dataPtr);
|
|
|
+ if(retval)
|
|
|
+ UA_Variant_deleteMembers(v);
|
|
|
return retval;
|
|
|
}
|
|
|
-UA_Int32 UA_Variant_copySetArray(UA_Variant *v, const UA_VTable_Entry *vt, UA_Int32 arrayLength,
|
|
|
- const void *array) {
|
|
|
- if(v == UA_NULL || vt == UA_NULL || array == UA_NULL)
|
|
|
- return UA_ERROR;
|
|
|
+UA_StatusCode UA_Variant_copySetArray(UA_Variant *v, const UA_VTable_Entry *vt, UA_Int32 arrayLength,
|
|
|
+ const void *array) {
|
|
|
+ UA_StatusCode retval = UA_STATUSCODE_GOOD;
|
|
|
+ if(!v || !vt || !array)
|
|
|
+ return UA_STATUSCODE_BADINTERNALERROR;
|
|
|
UA_Variant_init(v);
|
|
|
v->vt = vt;
|
|
|
v->storage.data.arrayLength = arrayLength;
|
|
|
- return UA_Array_copy(array, arrayLength, vt, &v->storage.data.dataPtr);
|
|
|
+ retval = UA_Array_copy(array, arrayLength, vt, &v->storage.data.dataPtr);
|
|
|
+ if(retval)
|
|
|
+ UA_Variant_deleteMembers(v);
|
|
|
+ return retval;
|
|
|
}
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
void UA_Variant_print(const UA_Variant *p, FILE *stream) {
|
|
|
- if(p == UA_NULL || stream == UA_NULL) return;
|
|
|
+ if(!p || !stream) return;
|
|
|
UA_UInt32 ns0id = UA_ns0ToVTableIndex(&p->vt->typeId);
|
|
|
if(p->storageType == UA_VARIANT_DATASOURCE) {
|
|
|
fprintf(stream, "Variant from a Datasource");
|
|
@@ -956,30 +981,32 @@ void UA_DiagnosticInfo_init(UA_DiagnosticInfo *p) {
|
|
|
}
|
|
|
|
|
|
UA_TYPE_NEW_DEFAULT(UA_DiagnosticInfo)
|
|
|
-UA_Int32 UA_DiagnosticInfo_copy(UA_DiagnosticInfo const *src, UA_DiagnosticInfo *dst) {
|
|
|
- UA_Int32 retval = UA_SUCCESS;
|
|
|
- if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
|
|
|
+UA_StatusCode UA_DiagnosticInfo_copy(UA_DiagnosticInfo const *src, UA_DiagnosticInfo *dst) {
|
|
|
+ UA_StatusCode retval = UA_STATUSCODE_GOOD;
|
|
|
+ if(!src || !dst)
|
|
|
+ return UA_STATUSCODE_BADINTERNALERROR;
|
|
|
+ UA_DiagnosticInfo_deleteMembers(dst);
|
|
|
retval |= UA_String_copy(&src->additionalInfo, &dst->additionalInfo);
|
|
|
- retval |= UA_Byte_copy(&src->encodingMask, &dst->encodingMask);
|
|
|
+ dst->encodingMask = src->encodingMask;
|
|
|
retval |= UA_StatusCode_copy(&src->innerStatusCode, &dst->innerStatusCode);
|
|
|
if(src->innerDiagnosticInfo) {
|
|
|
if((dst->innerDiagnosticInfo = UA_alloc(sizeof(UA_DiagnosticInfo))))
|
|
|
retval |= UA_DiagnosticInfo_copy(src->innerDiagnosticInfo, dst->innerDiagnosticInfo);
|
|
|
else
|
|
|
retval |= UA_STATUSCODE_BADOUTOFMEMORY;
|
|
|
- } else
|
|
|
- dst->innerDiagnosticInfo = UA_NULL;
|
|
|
- retval |= UA_Int32_copy(&src->locale, &dst->locale);
|
|
|
- retval |= UA_Int32_copy(&src->localizedText, &dst->localizedText);
|
|
|
- retval |= UA_Int32_copy(&src->namespaceUri, &dst->namespaceUri);
|
|
|
- retval |= UA_Int32_copy(&src->symbolicId, &dst->symbolicId);
|
|
|
-
|
|
|
+ }
|
|
|
+ dst->locale = src->locale;
|
|
|
+ dst->localizedText = src->localizedText;
|
|
|
+ dst->namespaceUri = src->namespaceUri;
|
|
|
+ dst->symbolicId = src->symbolicId;
|
|
|
+ if(retval)
|
|
|
+ UA_DiagnosticInfo_deleteMembers(dst);
|
|
|
return retval;
|
|
|
}
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
void UA_DiagnosticInfo_print(const UA_DiagnosticInfo *p, FILE *stream) {
|
|
|
- if(p == UA_NULL || stream == UA_NULL) return;
|
|
|
+ if(!p || !stream) return;
|
|
|
fprintf(stream, "(UA_DiagnosticInfo){");
|
|
|
UA_Byte_print(&p->encodingMask, stream);
|
|
|
fprintf(stream, ",");
|
|
@@ -995,7 +1022,7 @@ void UA_DiagnosticInfo_print(const UA_DiagnosticInfo *p, FILE *stream) {
|
|
|
fprintf(stream, ",");
|
|
|
UA_StatusCode_print(&p->innerStatusCode, stream);
|
|
|
fprintf(stream, ",");
|
|
|
- if(p->innerDiagnosticInfo != UA_NULL) {
|
|
|
+ if(p->innerDiagnosticInfo) {
|
|
|
fprintf(stream, "&");
|
|
|
UA_DiagnosticInfo_print(p->innerDiagnosticInfo, stream);
|
|
|
} else
|
|
@@ -1017,17 +1044,17 @@ void UA_InvalidType_init(UA_InvalidType *p) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
-UA_Int32 UA_InvalidType_copy(UA_InvalidType const *src, UA_InvalidType *dst) {
|
|
|
- return UA_ERR_INVALID_VALUE;
|
|
|
+UA_StatusCode UA_InvalidType_copy(UA_InvalidType const *src, UA_InvalidType *dst) {
|
|
|
+ return UA_STATUSCODE_BADINTERNALERROR;
|
|
|
}
|
|
|
|
|
|
-UA_Int32 UA_InvalidType_new(UA_InvalidType **p) {
|
|
|
- return UA_ERR_INVALID_VALUE;
|
|
|
+UA_StatusCode UA_InvalidType_new(UA_InvalidType **p) {
|
|
|
+ return UA_STATUSCODE_BADINTERNALERROR;
|
|
|
}
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
void UA_InvalidType_print(const UA_InvalidType *p, FILE *stream) {
|
|
|
- if(p == UA_NULL || stream == UA_NULL) return;
|
|
|
+ if(!p || !stream) return;
|
|
|
fprintf(stream, "(UA_InvalidType){ERROR (invalid type)}");
|
|
|
}
|
|
|
#endif
|
|
@@ -1036,27 +1063,26 @@ void UA_InvalidType_print(const UA_InvalidType *p, FILE *stream) {
|
|
|
/* Array */
|
|
|
/*********/
|
|
|
|
|
|
-UA_Int32 UA_Array_new(void **p, UA_Int32 noElements, const UA_VTable_Entry *vt) {
|
|
|
- if(vt == UA_NULL)
|
|
|
- return UA_ERROR;
|
|
|
+UA_StatusCode UA_Array_new(void **p, UA_Int32 noElements, const UA_VTable_Entry *vt) {
|
|
|
+ if(!vt) return UA_STATUSCODE_BADINTERNALERROR;
|
|
|
|
|
|
if(noElements <= 0) {
|
|
|
*p = UA_NULL;
|
|
|
- return UA_SUCCESS;
|
|
|
+ return UA_STATUSCODE_GOOD;
|
|
|
}
|
|
|
|
|
|
// FIXME! Arrays cannot be larger than 2**20.
|
|
|
// This was randomly chosen so that the development VM does not blow up.
|
|
|
if(noElements > 1048576) {
|
|
|
*p = UA_NULL;
|
|
|
- return UA_ERROR;
|
|
|
+ return UA_STATUSCODE_BADINTERNALERROR;
|
|
|
}
|
|
|
|
|
|
if(!(*p = UA_alloc(vt->memSize * noElements)))
|
|
|
return UA_STATUSCODE_BADOUTOFMEMORY;
|
|
|
|
|
|
UA_Array_init(*p, noElements, vt);
|
|
|
- return UA_SUCCESS;
|
|
|
+ return UA_STATUSCODE_GOOD;
|
|
|
}
|
|
|
|
|
|
void UA_Array_init(void *p, UA_Int32 noElements, const UA_VTable_Entry *vt) {
|
|
@@ -1080,13 +1106,13 @@ void UA_Array_delete(void *p, UA_Int32 noElements, const UA_VTable_Entry *vt) {
|
|
|
UA_free(p);
|
|
|
}
|
|
|
|
|
|
-UA_Int32 UA_Array_copy(const void *src, UA_Int32 noElements, const UA_VTable_Entry *vt, void **dst) {
|
|
|
+UA_StatusCode UA_Array_copy(const void *src, UA_Int32 noElements, const UA_VTable_Entry *vt, void **dst) {
|
|
|
UA_Int32 retval;
|
|
|
- if(src == UA_NULL || dst == UA_NULL || vt == UA_NULL)
|
|
|
- return UA_ERROR;
|
|
|
+ if(!src || !dst || !vt)
|
|
|
+ return UA_STATUSCODE_BADINTERNALERROR;
|
|
|
|
|
|
retval = UA_Array_new(dst, noElements, vt);
|
|
|
- if(retval != UA_SUCCESS) {
|
|
|
+ if(retval) {
|
|
|
*dst = UA_NULL;
|
|
|
return retval;
|
|
|
}
|
|
@@ -1095,13 +1121,13 @@ UA_Int32 UA_Array_copy(const void *src, UA_Int32 noElements, const UA_VTable_Ent
|
|
|
char *cdst = (char *)*dst;
|
|
|
UA_UInt32 memSize = vt->memSize;
|
|
|
UA_Int32 i = 0;
|
|
|
- for(;i < noElements && retval == UA_SUCCESS;i++) {
|
|
|
+ for(;i < noElements && retval == UA_STATUSCODE_GOOD;i++) {
|
|
|
retval |= vt->copy(csrc, cdst);
|
|
|
csrc += memSize;
|
|
|
cdst += memSize;
|
|
|
}
|
|
|
|
|
|
- if(retval != UA_SUCCESS) {
|
|
|
+ if(retval) {
|
|
|
i--; // undo last increase
|
|
|
UA_Array_delete(*dst, i, vt);
|
|
|
*dst = UA_NULL;
|
|
@@ -1112,7 +1138,7 @@ UA_Int32 UA_Array_copy(const void *src, UA_Int32 noElements, const UA_VTable_Ent
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
void UA_Array_print(const void *p, UA_Int32 noElements, const UA_VTable_Entry *vt, FILE *stream) {
|
|
|
- if(p == UA_NULL || vt == UA_NULL || stream == UA_NULL) return;
|
|
|
+ if(!p || !vt || !stream) return;
|
|
|
fprintf(stream, "(%s){", vt->name);
|
|
|
char *cp = (char *)p; // so compilers allow pointer arithmetic
|
|
|
UA_UInt32 memSize = vt->memSize;
|