瀏覽代碼

use NULL instead of UA_NULL; don't rename standard C functions; provide minimal replacements for libc on embedded targets

We only keep UA_malloc (and friends), while memset, memcpy, ... are used as usual.
Replacing malloc with sth custom makes sense. Replacing memcpy doesn't.
In the same vain, we use NULL instead of UA_NULL. That will make things easier for new contributors.

Some targets may not have a proper libc. For those, small replacements are provided.
Julius Pfrommer 9 年之前
父節點
當前提交
9dd20578a6
共有 43 個文件被更改,包括 434 次插入707 次删除
  1. 5 0
      CMakeLists.txt
  2. 35 0
      deps/libc_string.c
  3. 3 3
      examples/client_legacy.c
  4. 8 2
      examples/networklayer_tcp.c
  5. 11 0
      include/ua_config.h.in
  6. 11 13
      include/ua_types.h
  7. 1 1
      src/client/ua_client.c
  8. 4 4
      src/client/ua_client_highlevel.c
  9. 0 2
      src/client/ua_client_highlevel_subscriptions.c
  10. 13 13
      src/server/ua_nodes.c
  11. 13 13
      src/server/ua_nodestore.c
  12. 7 7
      src/server/ua_nodestore_concurrent.c
  13. 1 1
      src/server/ua_nodestore_hash.inc
  14. 1 1
      src/server/ua_securechannel_manager.c
  15. 19 19
      src/server/ua_server.c
  16. 13 13
      src/server/ua_server_worker.c
  17. 1 1
      src/server/ua_services.h
  18. 71 64
      src/server/ua_services_attribute.c
  19. 1 1
      src/server/ua_services_call.c
  20. 14 14
      src/server/ua_services_nodemanagement.c
  21. 4 4
      src/server/ua_services_session.c
  22. 15 15
      src/server/ua_services_view.c
  23. 3 3
      src/server/ua_session_manager.c
  24. 14 14
      src/server/ua_subscription.c
  25. 16 16
      src/ua_connection.c
  26. 6 6
      src/ua_securechannel.c
  27. 13 13
      src/ua_session.c
  28. 55 66
      src/ua_types.c
  29. 12 12
      src/ua_types_encoding_binary.c
  30. 8 38
      src/ua_util.h
  31. 0 4
      tests/CMakeLists.txt
  32. 0 115
      tests/check_base64.c
  33. 11 11
      tests/check_builtin.c
  34. 2 2
      tests/check_memory.c
  35. 24 24
      tests/check_nodestore.c
  36. 2 2
      tests/check_services_attributes.c
  37. 1 1
      tests/check_services_view.c
  38. 4 4
      tests/check_session.c
  39. 3 3
      tests/check_stack.c
  40. 0 173
      tests/check_xml.c
  41. 3 3
      tools/pyUANamespace/open62541_MacroHelper.py
  42. 1 1
      tools/pyUANamespace/ua_namespace.py
  43. 5 5
      tools/pyUANamespace/ua_node_types.py

+ 5 - 0
CMakeLists.txt

@@ -143,6 +143,11 @@ else()
   set(generate_typeintrospection "")
 endif()
 
+option(UA_EMBEDDED_LIBC "Target has no libc, use internal definitions" OFF)
+if(UA_EMBEDDED_LIBC)
+  list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/deps/libc_string.c)
+endif()
+
 option(ENABLE_SUBSCRIPTIONS "Enable compilation of subscription and monitoring support." OFF)
 if(ENABLE_SUBSCRIPTIONS)
   set(ENABLE_SUBSCRIPTIONS ON) #to propagate it to the config file

+ 35 - 0
deps/libc_string.c

@@ -0,0 +1,35 @@
+/*
+ * This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
+ */
+
+#include <stddef.h>
+
+void *memcpy(void * UA_RESTRICT dest, const void *UA_RESTRICT src, size_t n) {
+	unsigned char *d = dest;
+	const unsigned char *s = src;
+	while(n--)
+        *d++ = *s++;
+	return dest;
+}
+
+void *memset(void *dest, int c, size_t n) {
+    unsigned char c8 = n;
+    unsigned char *target = dest;
+    while(n--)
+        *target++ = c8;
+    return dest;
+}
+
+size_t strlen(const char *str) {
+    size_t len = 0;
+    for(const char *s = str; *s; s++)
+        len += 1;
+    return len;
+}
+
+int memcmp(const void *vl, const void *vr, size_t n) {
+    const unsigned char *l = vl, *r = vr;
+    for(; n && *l == *r; n--, l++, r++);
+    return n ? *l-*r : 0;
+}

+ 3 - 3
examples/client_legacy.c

@@ -68,11 +68,11 @@ static int sendOpenSecureChannel(UA_Int32 sock) {
     securityPolicy = UA_STRING("http://opcfoundation.org/UA/SecurityPolicy#None");
 
     UA_String senderCert;
-    senderCert.data = UA_NULL;
+    senderCert.data = NULL;
     senderCert.length = -1;
 
     UA_String receiverCertThumb;
-    receiverCertThumb.data = UA_NULL;
+    receiverCertThumb.data = NULL;
     receiverCertThumb.length = -1;
 
     UA_UInt32 sequenceNumber = 51;
@@ -672,7 +672,7 @@ int main(int argc, char *argv[]) {
     //save to file
     char data[100];
     const char flag = 'a';
-    FILE* fHandle = UA_NULL;
+    FILE* fHandle = NULL;
     if (defaultParams) {
         fHandle =  fopen("client.log", &flag);
     }else{

+ 8 - 2
examples/networklayer_tcp.c

@@ -6,6 +6,7 @@
 #include "networklayer_tcp.h"
 
 #include <stdlib.h> // malloc, free
+#include <stdio.h> // snprintf
 #include <string.h> // memset
 #include <errno.h>
 
@@ -426,8 +427,13 @@ UA_ServerNetworkLayer * ServerNetworkLayerTCP_new(UA_ConnectionConfig conf, UA_U
     layer->mappings = NULL;
     layer->port = port;
     char hostname[256];
-    gethostname(hostname, 255);
-    UA_String_copyprintf("opc.tcp://%s:%d", &layer->layer.discoveryUrl, hostname, port);
+    if(gethostname(hostname, 255) == 0) {
+        char discoveryUrl[256];
+        UA_String str;
+        str.length = snprintf(discoveryUrl, 255, "opc.tcp://%s:%d", hostname, port);
+        str.data = (UA_Byte*)discoveryUrl;
+        UA_String_copy(&str, &layer->layer.discoveryUrl);
+    }
 
     layer->layer.start = (UA_StatusCode(*)(UA_ServerNetworkLayer*,UA_Logger))ServerNetworkLayerTCP_start;
     layer->layer.getJobs = (size_t(*)(UA_ServerNetworkLayer*,UA_Job**,UA_UInt16))ServerNetworkLayerTCP_getJobs;

+ 11 - 0
include/ua_config.h.in

@@ -10,6 +10,7 @@
 #cmakedefine ENABLE_METHODCALLS
 #cmakedefine ENABLE_SUBSCRIPTIONS
 #cmakedefine ENABLE_TYPEINTROSPECTION
+#cmakedefine UA_EMBEDDED_LIBC
 
 /* Function Export */
 #ifdef _WIN32
@@ -97,4 +98,14 @@
 # define UA_FUNC_ATTR_WARN_UNUSED_RESULT
 #endif
 
+#include <stddef.h>
+#ifdef UA_EMBEDDED_LIBC
+  void *memcpy(void *UA_RESTRICT dest, const void *UA_RESTRICT src, size_t n);
+  void *memset(void *dest, int c, size_t n);
+  size_t strlen(const char *s);
+  int memcmp(const void *vl, const void *vr, size_t n);
+#else
+# include <string.h>
+#endif
+
 #endif /* UA_CONFIG_H_ */

+ 11 - 13
include/ua_types.h

@@ -21,11 +21,10 @@ extern "C" {
 #endif
 
 #ifndef UA_FFI_BINDINGS
-#include <inttypes.h>
 #include <stdbool.h>
-#include <stddef.h>
-#include <string.h>
+#include <inttypes.h>
 #endif
+
 #include "ua_config.h"
 #include "ua_statuscodes.h"
 
@@ -331,7 +330,6 @@ void UA_EXPORT UA_String_deleteMembers(UA_String *p);
 UA_StatusCode UA_EXPORT UA_String_copy(const UA_String *src, UA_String *dst);
 UA_String UA_EXPORT UA_String_fromChars(char const src[]); ///> Copies the content on the heap. Returns a null-string when alloc fails.
 UA_Boolean UA_EXPORT UA_String_equal(const UA_String *s1, const UA_String *s2); ///> Compares two strings
-UA_StatusCode UA_EXPORT UA_String_copyprintf(char const fmt[], UA_String *dst, ...); ///> Printf a char-array into a UA_String. Memory for the string data is allocated.
 UA_EXPORT extern const UA_String UA_STRING_NULL;
 static UA_INLINE UA_String UA_STRING(char *chars) {
     UA_String str;
@@ -351,15 +349,15 @@ UA_DateTime UA_EXPORT UA_DateTime_now(void); ///> The current time
 UA_StatusCode UA_EXPORT UA_DateTime_toString(UA_DateTime time, UA_String *timeString);
 
 typedef struct UA_DateTimeStruct {
-    UA_Int16 nanoSec;
-    UA_Int16 microSec;
-    UA_Int16 milliSec;
-    UA_Int16 sec;
-    UA_Int16 min;
-    UA_Int16 hour;
-    UA_Int16 day;
-    UA_Int16 month;
-    UA_Int16 year;
+    UA_UInt16 nanoSec;
+    UA_UInt16 microSec;
+    UA_UInt16 milliSec;
+    UA_UInt16 sec;
+    UA_UInt16 min;
+    UA_UInt16 hour;
+    UA_UInt16 day;
+    UA_UInt16 month;
+    UA_UInt16 year;
 } UA_DateTimeStruct;
 
 UA_DateTimeStruct UA_EXPORT UA_DateTime_toStruct(UA_DateTime time);

+ 1 - 1
src/client/ua_client.c

@@ -44,7 +44,7 @@ static void UA_Client_init(UA_Client* client, UA_ClientConfig config,
 UA_Client * UA_Client_new(UA_ClientConfig config, UA_Logger logger) {
     UA_Client *client = UA_calloc(1, sizeof(UA_Client));
     if(!client)
-        return UA_NULL;
+        return NULL;
 
     UA_Client_init(client, config, logger);
     return client;

+ 4 - 4
src/client/ua_client_highlevel.c

@@ -218,7 +218,7 @@ UA_Client_call(UA_Client *client, const UA_NodeId objectId, const UA_NodeId meth
     if(retval == UA_STATUSCODE_GOOD) {
         *output = response.results[0].outputArguments;
         *outputSize = response.results[0].outputArgumentsSize;
-        response.results[0].outputArguments = UA_NULL;
+        response.results[0].outputArguments = NULL;
         response.results[0].outputArgumentsSize = -1;
     }
     UA_CallResponse_deleteMembers(&response);
@@ -258,15 +258,15 @@ __UA_Client_readAttribute(UA_Client *client, UA_NodeId nodeId, UA_AttributeId at
         return retval;
     }
     if(attributeId == UA_ATTRIBUTEID_VALUE) {
-        UA_memcpy(out, &res->value, sizeof(UA_Variant));
+        memcpy(out, &res->value, sizeof(UA_Variant));
         UA_Variant_init(&res->value);
     }
     else if(res->value.type != outDataType) {
         retval = UA_STATUSCODE_BADUNEXPECTEDERROR;
     } else {
-        UA_memcpy(out, res->value.data, res->value.type->memSize);
+        memcpy(out, res->value.data, res->value.type->memSize);
         UA_free(res->value.data);
-        res->value.data = UA_NULL;
+        res->value.data = NULL;
     }
     UA_ReadResponse_deleteMembers(&response);
     return retval;

+ 0 - 2
src/client/ua_client_highlevel_subscriptions.c

@@ -273,8 +273,6 @@ UA_Client_processPublishRx(UA_Client *client, UA_PublishResponse response) {
         tmpAck = UA_malloc(sizeof(UA_Client_NotificationsAckNumber));
         tmpAck->subAck.sequenceNumber = msg.sequenceNumber;
         tmpAck->subAck.subscriptionId = sub->SubscriptionID;
-        tmpAck->listEntry.le_next = UA_NULL;
-        tmpAck->listEntry.le_prev = UA_NULL;
         LIST_INSERT_HEAD(&client->pendingNotificationsAcks, tmpAck, listEntry);
     }
     

+ 13 - 13
src/server/ua_nodes.c

@@ -11,7 +11,7 @@ static void UA_Node_init(UA_Node *p) {
 	UA_UInt32_init(&p->writeMask);
 	UA_UInt32_init(&p->userWriteMask);
 	p->referencesSize = -1;
-	p->references = UA_NULL;
+	p->references = NULL;
 }
 
 static void UA_Node_deleteMembers(UA_Node *p) {
@@ -122,16 +122,16 @@ UA_Node * UA_Node_copyAnyNodeClass(const UA_Node *node) {
         deleteNode = (UA_DeleteNodeFunction)UA_ViewNode_delete;
         break;
     default:
-        return UA_NULL;
+        return NULL;
         break;
     }
 
     UA_Node *copy = newNode();
     if(!copy)
-        return UA_NULL;
+        return NULL;
     if(copyNode(node, copy) != UA_STATUSCODE_GOOD) {
         deleteNode(copy);
-        return UA_NULL;
+        return NULL;
     }
     return copy;
 }
@@ -141,7 +141,7 @@ void UA_ObjectNode_init(UA_ObjectNode *p) {
 	UA_Node_init((UA_Node*)p);
     p->nodeClass = UA_NODECLASS_OBJECT;
     p->eventNotifier = 0;
-    p->instanceHandle = UA_NULL;
+    p->instanceHandle = NULL;
 }
 
 UA_ObjectNode * UA_ObjectNode_new(void) {
@@ -172,7 +172,7 @@ void UA_ObjectTypeNode_init(UA_ObjectTypeNode *p) {
     p->nodeClass = UA_NODECLASS_OBJECTTYPE;
     p->isAbstract = UA_FALSE;
     p->lifecycleManagement = (UA_ObjectLifecycleManagement)
-        {.constructor = UA_NULL, .destructor = UA_NULL};
+        {.constructor = NULL, .destructor = NULL};
 }
 
 UA_ObjectTypeNode * UA_ObjectTypeNode_new(void) {
@@ -203,7 +203,7 @@ void UA_VariableNode_init(UA_VariableNode *p) {
     p->nodeClass = UA_NODECLASS_VARIABLE;
     p->valueSource = UA_VALUESOURCE_VARIANT;
     UA_Variant_init(&p->value.variant.value);
-    p->value.variant.callback = (UA_ValueCallback){UA_NULL,UA_NULL,UA_NULL};
+    p->value.variant.callback = (UA_ValueCallback){NULL,NULL,NULL};
     p->valueRank = -2; // scalar or array of any dimension
     p->accessLevel = 0;
     p->userAccessLevel = 0;
@@ -256,7 +256,7 @@ void UA_VariableTypeNode_init(UA_VariableTypeNode *p) {
     p->nodeClass = UA_NODECLASS_VARIABLETYPE;
     p->valueSource = UA_VALUESOURCE_VARIANT;
     UA_Variant_init(&p->value.variant.value);
-    p->value.variant.callback = (UA_ValueCallback){UA_NULL, UA_NULL, UA_NULL};
+    p->value.variant.callback = (UA_ValueCallback){NULL, NULL, NULL};
     p->valueRank = -2; // scalar or array of any dimension
     p->isAbstract = UA_FALSE;
 }
@@ -344,8 +344,8 @@ void UA_MethodNode_init(UA_MethodNode *p) {
     p->executable = UA_FALSE;
     p->userExecutable = UA_FALSE;
 #ifdef ENABLE_METHODCALLS
-    p->methodHandle        = UA_NULL;
-    p->attachedMethod      = UA_NULL;
+    p->methodHandle        = NULL;
+    p->attachedMethod      = NULL;
 #endif
 }
 
@@ -358,7 +358,7 @@ UA_MethodNode * UA_MethodNode_new(void) {
 
 void UA_MethodNode_deleteMembers(UA_MethodNode *p) {
 #ifdef ENABLE_METHODCALLS
-    p->attachedMethod = UA_NULL;
+    p->attachedMethod = NULL;
 #endif
     UA_Node_deleteMembers((UA_Node*)p);
 }
@@ -366,8 +366,8 @@ void UA_MethodNode_deleteMembers(UA_MethodNode *p) {
 void UA_MethodNode_delete(UA_MethodNode *p) {
     UA_MethodNode_deleteMembers(p);
 #ifdef ENABLE_METHODCALLS
-    p->methodHandle   = UA_NULL;
-    p->attachedMethod = UA_NULL;
+    p->methodHandle   = NULL;
+    p->attachedMethod = NULL;
 #endif
     UA_free(p);
 }

+ 13 - 13
src/server/ua_nodestore.c

@@ -56,7 +56,7 @@ static UA_Boolean containsNodeId(const UA_NodeStore *ns, const UA_NodeId *nodeid
     hash_t         index = mod(h, size);
     struct nodeEntry **e = &ns->entries[index];
 
-    if(*e == UA_NULL) {
+    if(*e == NULL) {
         *entry = e;
         return UA_FALSE;
     }
@@ -74,7 +74,7 @@ static UA_Boolean containsNodeId(const UA_NodeStore *ns, const UA_NodeId *nodeid
 
         e = &ns->entries[index];
 
-        if(*e == UA_NULL) {
+        if(*e == NULL) {
             *entry = e;
             return UA_FALSE;
         }
@@ -106,7 +106,7 @@ static UA_StatusCode expand(UA_NodeStore *ns) {
     if(!(nentries = UA_malloc(sizeof(struct nodeEntry *) * nsize)))
         return UA_STATUSCODE_BADOUTOFMEMORY;
 
-    UA_memset(nentries, 0, nsize * sizeof(struct nodeEntry *));
+    memset(nentries, 0, nsize * sizeof(struct nodeEntry *));
     struct nodeEntry **oentries = ns->entries;
     ns->entries = nentries;
     ns->size    = nsize;
@@ -196,9 +196,9 @@ static struct nodeEntry * nodeEntryFromNode(UA_Node *node) {
 
     struct nodeEntry *newEntry;
     if(!(newEntry = UA_malloc(sizeof(struct nodeEntry) - sizeof(UA_Node) + nodesize)))
-        return UA_NULL;
+        return NULL;
 
-    UA_memcpy(&newEntry->node, node, nodesize);
+    memcpy(&newEntry->node, node, nodesize);
     UA_free(node);
     return newEntry;
 }
@@ -210,16 +210,16 @@ static struct nodeEntry * nodeEntryFromNode(UA_Node *node) {
 UA_NodeStore * UA_NodeStore_new(void) {
     UA_NodeStore *ns;
     if(!(ns = UA_malloc(sizeof(UA_NodeStore))))
-        return UA_NULL;
+        return NULL;
 
     ns->sizePrimeIndex = higher_prime_index(32);
     ns->size = primes[ns->sizePrimeIndex];
     ns->count = 0;
     if(!(ns->entries = UA_malloc(sizeof(struct nodeEntry *) * ns->size))) {
         UA_free(ns);
-        return UA_NULL;
+        return NULL;
     }
-    UA_memset(ns->entries, 0, ns->size * sizeof(struct nodeEntry *));
+    memset(ns->entries, 0, ns->size * sizeof(struct nodeEntry *));
     return ns;
 }
 
@@ -227,10 +227,10 @@ void UA_NodeStore_delete(UA_NodeStore *ns) {
     UA_UInt32 size = ns->size;
     struct nodeEntry **entries = ns->entries;
     for(UA_UInt32 i = 0;i < size;i++) {
-        if(entries[i] != UA_NULL) {
+        if(entries[i] != NULL) {
             entries[i]->refcount &= ~ALIVE_BIT; // mark dead
             deleteEntry(entries[i]);
-            entries[i] = UA_NULL;
+            entries[i] = NULL;
             ns->count--;
         }
     }
@@ -323,7 +323,7 @@ UA_StatusCode UA_NodeStore_replace(UA_NodeStore *ns, const UA_Node *oldNode, UA_
 const UA_Node * UA_NodeStore_get(const UA_NodeStore *ns, const UA_NodeId *nodeid) {
     struct nodeEntry **slot;
     if(!containsNodeId(ns, nodeid, &slot))
-        return UA_NULL;
+        return NULL;
     (*slot)->refcount++;
     return &(*slot)->node;
 }
@@ -336,7 +336,7 @@ UA_StatusCode UA_NodeStore_remove(UA_NodeStore *ns, const UA_NodeId *nodeid) {
     // Check before if deleting the node makes the UA_NodeStore inconsistent.
     (*slot)->refcount &= ~ALIVE_BIT; // mark dead
     deleteEntry(*slot);
-    *slot = UA_NULL;
+    *slot = NULL;
     ns->count--;
 
     /* Downsize the hashmap if it is very empty */
@@ -348,7 +348,7 @@ UA_StatusCode UA_NodeStore_remove(UA_NodeStore *ns, const UA_NodeId *nodeid) {
 
 void UA_NodeStore_iterate(const UA_NodeStore *ns, UA_NodeStore_nodeVisitor visitor) {
     for(UA_UInt32 i = 0;i < ns->size;i++) {
-        if(ns->entries[i] != UA_NULL)
+        if(ns->entries[i] != NULL)
             visitor(&ns->entries[i]->node);
     }
 }

+ 7 - 7
src/server/ua_nodestore_concurrent.c

@@ -81,13 +81,13 @@ void UA_NodeStore_release(const UA_Node *managed) {
 UA_NodeStore * UA_NodeStore_new() {
     UA_NodeStore *ns;
     if(!(ns = UA_malloc(sizeof(UA_NodeStore))))
-        return UA_NULL;
+        return NULL;
 
     /* 32 is the minimum size for the hashtable. */
     ns->ht = cds_lfht_new(32, 32, 0, CDS_LFHT_AUTO_RESIZE, NULL);
     if(!ns->ht) {
         UA_free(ns);
-        return UA_NULL;
+        return NULL;
     }
     return ns;
 }
@@ -106,7 +106,7 @@ void UA_NodeStore_delete(UA_NodeStore *ns) {
         cds_lfht_next(ht, &iter);
     }
     rcu_read_unlock();
-    cds_lfht_destroy(ht, UA_NULL);
+    cds_lfht_destroy(ht, NULL);
 
     UA_free(ns);
 }
@@ -146,7 +146,7 @@ UA_StatusCode UA_NodeStore_insert(UA_NodeStore *ns, UA_Node *node, const UA_Node
     struct nodeEntry *entry;
     if(!(entry = UA_malloc(sizeof(struct nodeEntry) - sizeof(UA_Node) + nodesize)))
         return UA_STATUSCODE_BADOUTOFMEMORY;
-    UA_memcpy((void*)&entry->node, node, nodesize);
+    memcpy((void*)&entry->node, node, nodesize);
 
     cds_lfht_node_init(&entry->htn);
     entry->refcount = ALIVE_BIT;
@@ -239,7 +239,7 @@ UA_StatusCode UA_NodeStore_replace(UA_NodeStore *ns, const UA_Node *oldNode, UA_
     struct nodeEntry *newEntry;
     if(!(newEntry = UA_malloc(sizeof(struct nodeEntry) - sizeof(UA_Node) + nodesize)))
         return UA_STATUSCODE_BADOUTOFMEMORY;
-    UA_memcpy((void*)&newEntry->node, node, nodesize);
+    memcpy((void*)&newEntry->node, node, nodesize);
 
     cds_lfht_node_init(&newEntry->htn);
     newEntry->refcount = ALIVE_BIT;
@@ -313,7 +313,7 @@ const UA_Node * UA_NodeStore_get(const UA_NodeStore *ns, const UA_NodeId *nodeid
 
     if(!found_entry) {
         rcu_read_unlock();
-        return UA_NULL;
+        return NULL;
     }
 
     /* This is done within a read-lock. The node will not be marked dead within a read-lock. */
@@ -328,7 +328,7 @@ void UA_NodeStore_iterate(const UA_NodeStore *ns, UA_NodeStore_nodeVisitor visit
 
     rcu_read_lock();
     cds_lfht_first(ht, &iter);
-    while(iter.node != UA_NULL) {
+    while(iter.node != NULL) {
         struct nodeEntry *found_entry = (struct nodeEntry *)cds_lfht_iter_get_node(&iter);
         uatomic_inc(&found_entry->refcount);
         const UA_Node      *node = &found_entry->node;

+ 1 - 1
src/server/ua_nodestore_hash.inc

@@ -5,7 +5,7 @@ static hash_t mod2(hash_t h, hash_t size) { return 1 + (h % (size - 2)); }
 
 /* Based on Murmur-Hash 3 by Austin Appleby (public domain, freely usable) */
 static hash_t hash_array(const UA_Byte *data, UA_UInt32 len, UA_UInt32 seed) {
-    if(data == UA_NULL)
+    if(data == NULL)
         return 0;
 
     const int32_t   nblocks = len / 4;

+ 1 - 1
src/server/ua_securechannel_manager.c

@@ -116,7 +116,7 @@ UA_SecureChannelManager_get(UA_SecureChannelManager *cm, UA_UInt32 channelId) {
         if(entry->channel.securityToken.channelId == channelId)
             return &entry->channel;
     }
-    return UA_NULL;
+    return NULL;
 }
 
 UA_StatusCode

+ 19 - 19
src/server/ua_server.c

@@ -38,7 +38,7 @@ static const UA_NodeId nodeIdOrganizes = {
 static const UA_ExpandedNodeId expandedNodeIdBaseDataVariabletype = {
     .nodeId = {.namespaceIndex = 0, .identifierType = UA_NODEIDTYPE_NUMERIC,
                .identifier.numeric = UA_NS0ID_HASTYPEDEFINITION},
-    .namespaceUri = {.length = -1, .data = UA_NULL}, .serverIndex = 0};
+    .namespaceUri = {.length = -1, .data = NULL}, .serverIndex = 0};
 
 #ifndef ENABLE_GENERATE_NAMESPACE0
 static const UA_NodeId nodeIdNonHierarchicalReferences = {
@@ -67,7 +67,7 @@ static void UA_Server_deleteExternalNamespaces(UA_Server *server) {
 	}
 	if(server->externalNamespacesSize > 0){
 		UA_free(server->externalNamespaces);
-		server->externalNamespaces = UA_NULL;
+		server->externalNamespaces = NULL;
 		server->externalNamespacesSize = 0;
 	}
 }
@@ -75,7 +75,7 @@ static void UA_Server_deleteExternalNamespaces(UA_Server *server) {
 UA_StatusCode UA_EXPORT
 UA_Server_addExternalNamespace(UA_Server *server, UA_UInt16 namespaceIndex,
                                const UA_String *url, UA_ExternalNodeStore *nodeStore) {
-	if(nodeStore == UA_NULL)
+	if(nodeStore == NULL)
 		return UA_STATUSCODE_BADARGUMENTSMISSING;
 
     UA_UInt32 size = server->externalNamespacesSize;
@@ -322,7 +322,7 @@ readStatus(void *handle, const UA_NodeId nodeid, UA_Boolean sourceTimeStamp,
     value->value.arrayLength = -1;
     value->value.data = status;
     value->value.arrayDimensionsSize = -1;
-    value->value.arrayDimensions = UA_NULL;
+    value->value.arrayDimensions = NULL;
     value->hasValue = UA_TRUE;
     if(sourceTimeStamp) {
         value->hasSourceTimestamp = UA_TRUE;
@@ -428,7 +428,7 @@ addVariableTypeNode_subtype(UA_Server *server, char* name, UA_UInt32 variabletyp
 UA_Server * UA_Server_new(UA_ServerConfig config) {
     UA_Server *server = UA_malloc(sizeof(UA_Server));
     if(!server)
-        return UA_NULL;
+        return NULL;
 
     //FIXME: config contains strings, for now its okay, but consider copying them aswell
     server->config = config;
@@ -439,17 +439,17 @@ UA_Server * UA_Server_new(UA_ServerConfig config) {
    	rcu_register_thread();
     cds_wfcq_init(&server->dispatchQueue_head, &server->dispatchQueue_tail);
     cds_lfs_init(&server->mainLoopJobs);
-    server->delayedJobs = UA_NULL;
+    server->delayedJobs = NULL;
 #endif
 
     // logger
-    server->logger = UA_NULL;
+    server->logger = NULL;
 
     // random seed
     server->random_seed = (UA_UInt32)UA_DateTime_now();
 
     // networklayers
-    server->networkLayers = UA_NULL;
+    server->networkLayers = NULL;
     server->networkLayersSize = 0;
 
     UA_ByteString_init(&server->serverCertificate);
@@ -467,7 +467,7 @@ UA_Server * UA_Server_new(UA_ServerConfig config) {
 
 #ifdef UA_EXTERNAL_NAMESPACES
     server->externalNamespacesSize = 0;
-    server->externalNamespaces = UA_NULL;
+    server->externalNamespaces = NULL;
 #endif
 
     /* ns0 and ns1 */
@@ -476,7 +476,7 @@ UA_Server * UA_Server_new(UA_ServerConfig config) {
     UA_String_copy(&server->description.applicationUri, &server->namespaces[1]);
     server->namespacesSize = 2;
 
-    server->endpointDescriptions = UA_NULL;
+    server->endpointDescriptions = NULL;
     server->endpointDescriptionsSize = 0;
 
     UA_EndpointDescription *endpoint = UA_EndpointDescription_new(); // todo: check return code
@@ -593,7 +593,7 @@ UA_Server * UA_Server_new(UA_ServerConfig config) {
     references->symmetric = UA_TRUE;
     references->inverseName = UA_LOCALIZEDTEXT_ALLOC("en_US", "References");
     /* The reference to root is later inserted */
-    UA_NodeStore_insert(server->nodestore, (UA_Node*)references, UA_NULL);
+    UA_NodeStore_insert(server->nodestore, (UA_Node*)references, NULL);
 
     UA_ReferenceTypeNode *hassubtype = UA_ReferenceTypeNode_new();
     copyNames((UA_Node*)hassubtype, "HasSubtype");
@@ -602,7 +602,7 @@ UA_Server * UA_Server_new(UA_ServerConfig config) {
     hassubtype->isAbstract = UA_FALSE;
     hassubtype->symmetric = UA_FALSE;
     /* The reference to root is later inserted */
-    UA_NodeStore_insert(server->nodestore, (UA_Node*)hassubtype, UA_NULL);
+    UA_NodeStore_insert(server->nodestore, (UA_Node*)hassubtype, NULL);
 
     /* Continue adding reference types with normal "addnode" */
     UA_ReferenceTypeNode *hierarchicalreferences = UA_ReferenceTypeNode_new();
@@ -793,7 +793,7 @@ UA_Server * UA_Server_new(UA_ServerConfig config) {
     UA_ObjectNode *root = UA_ObjectNode_new();
     copyNames((UA_Node*)root, "Root");
     root->nodeId.identifier.numeric = UA_NS0ID_ROOTFOLDER;
-    UA_NodeStore_insert(server->nodestore, (UA_Node*)root, UA_NULL);
+    UA_NodeStore_insert(server->nodestore, (UA_Node*)root, NULL);
 
     UA_ObjectNode *objects = UA_ObjectNode_new();
     copyNames((UA_Node*)objects, "Objects");
@@ -938,7 +938,7 @@ UA_Server * UA_Server_new(UA_ServerConfig config) {
     namespaceArray->nodeId.identifier.numeric = UA_NS0ID_SERVER_NAMESPACEARRAY;
     namespaceArray->valueSource = UA_VALUESOURCE_DATASOURCE;
     namespaceArray->value.dataSource = (UA_DataSource) {.handle = server, .read = readNamespaces,
-                                                        .write = UA_NULL};
+                                                        .write = NULL};
     namespaceArray->valueRank = 1;
     namespaceArray->minimumSamplingInterval = 1.0;
     addNodeInternal(server, (UA_Node*)namespaceArray, UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER), nodeIdHasProperty);
@@ -1052,7 +1052,7 @@ UA_Server * UA_Server_new(UA_ServerConfig config) {
     copyNames((UA_Node*)serverstatus, "ServerStatus");
     serverstatus->nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS);
     serverstatus->valueSource = UA_VALUESOURCE_DATASOURCE;
-    serverstatus->value.dataSource = (UA_DataSource) {.handle = server, .read = readStatus, .write = UA_NULL};
+    serverstatus->value.dataSource = (UA_DataSource) {.handle = server, .read = readStatus, .write = NULL};
     addNodeInternal(server, (UA_Node*)serverstatus, UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER),
                     nodeIdHasComponent);
     UA_Server_addReference(server, UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS),
@@ -1075,7 +1075,7 @@ UA_Server * UA_Server_new(UA_ServerConfig config) {
     currenttime->nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_CURRENTTIME);
     currenttime->valueSource = UA_VALUESOURCE_DATASOURCE;
     currenttime->value.dataSource = (UA_DataSource) {.handle = NULL, .read = readCurrentTime,
-                                                     .write = UA_NULL};
+                                                     .write = NULL};
     addNodeInternal(server, (UA_Node*)currenttime,
                     UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS), nodeIdHasComponent);
     UA_Server_addReference(server, UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_CURRENTTIME),
@@ -1300,10 +1300,10 @@ __UA_Server_readAttribute(UA_Server *server, const UA_NodeId nodeId,
         return retval;
     }
     if(attributeId == UA_ATTRIBUTEID_VALUE)
-        UA_memcpy(v, &dv.value, sizeof(UA_Variant));
+        memcpy(v, &dv.value, sizeof(UA_Variant));
     else {
-        UA_memcpy(v, dv.value.data, dv.value.type->memSize);
-        dv.value.data = UA_NULL;
+        memcpy(v, dv.value.data, dv.value.type->memSize);
+        dv.value.data = NULL;
         dv.value.arrayLength = -1;
         UA_Variant_deleteMembers(&dv.value);
     }

+ 13 - 13
src/server/ua_server_worker.c

@@ -108,7 +108,7 @@ static void dispatchJobs(UA_Server *server, UA_Job *jobs, size_t jobsSize) {
         struct DispatchJobsList *wln = UA_malloc(sizeof(struct DispatchJobsList));
         if(startIndex > 0) {
             wln->jobs = UA_malloc(size * sizeof(UA_Job));
-            UA_memcpy(wln->jobs, &jobs[startIndex], size * sizeof(UA_Job));
+            memcpy(wln->jobs, &jobs[startIndex], size * sizeof(UA_Job));
             wln->jobsSize = size;
         } else {
             /* forward the original array */
@@ -176,7 +176,7 @@ static void * workerLoop(struct workerStartData *startInfo) {
    	rcu_unregister_thread();
 
     /* we need to return _something_ for pthreads */
-    return UA_NULL;
+    return NULL;
 }
 
 static void emptyDispatchQueue(UA_Server *server) {
@@ -221,8 +221,8 @@ struct AddRepeatedJob {
 
 /* internal. call only from the main loop. */
 static UA_StatusCode addRepeatedJob(UA_Server *server, struct AddRepeatedJob * UA_RESTRICT arw) {
-    struct RepeatedJobs *matchingTw = UA_NULL; // add the item here
-    struct RepeatedJobs *lastTw = UA_NULL; // if there is no repeated job, add a new one this entry
+    struct RepeatedJobs *matchingTw = NULL; // add the item here
+    struct RepeatedJobs *lastTw = NULL; // if there is no repeated job, add a new one this entry
     struct RepeatedJobs *tempTw;
 
     /* search for matching entry */
@@ -325,9 +325,9 @@ UA_StatusCode UA_Server_addRepeatedJob(UA_Server *server, UA_Job job, UA_UInt32
 /* Returns the timeout until the next repeated job in ms */
 static UA_UInt16 processRepeatedJobs(UA_Server *server) {
     UA_DateTime current = UA_DateTime_now();
-    struct RepeatedJobs *tw = UA_NULL;
+    struct RepeatedJobs *tw = NULL;
 
-    while((tw = LIST_FIRST(&server->repeatedJobs)) != UA_NULL) {
+    while((tw = LIST_FIRST(&server->repeatedJobs)) != NULL) {
         if(tw->nextTime > current)
             break;
 
@@ -433,7 +433,7 @@ void UA_Server_deleteAllRepeatedJobs(UA_Server *server) {
 
 struct DelayedJobs {
     struct DelayedJobs *next;
-    UA_UInt32 *workerCounters; // initially UA_NULL until the counter are set
+    UA_UInt32 *workerCounters; // initially NULL until the counter are set
     UA_UInt32 jobsCount; // the size of the array is DELAYEDJOBSSIZE, the count may be less
     UA_Job jobs[DELAYEDJOBSSIZE]; // when it runs full, a new delayedJobs entry is created
 };
@@ -459,7 +459,7 @@ static void addDelayedJob(UA_Server *server, UA_Job *job) {
             return;
         }
         dj->jobsCount = 0;
-        dj->workerCounters = UA_NULL;
+        dj->workerCounters = NULL;
         dj->next = server->delayedJobs;
         server->delayedJobs = dj;
 
@@ -522,7 +522,7 @@ static void dispatchDelayedJobs(UA_Server *server, void *data /* not used, but n
     /* process and free all delayed jobs from here on */
     while(dw) {
         processJobs(server, dw->jobs, dw->jobsCount);
-        struct DelayedJobs *next = uatomic_xchg(&beforedw->next, UA_NULL);
+        struct DelayedJobs *next = uatomic_xchg(&beforedw->next, NULL);
         UA_free(dw);
         UA_free(dw->workerCounters);
         dw = next;
@@ -566,13 +566,13 @@ UA_StatusCode result = UA_STATUSCODE_GOOD;
         struct workerStartData *startData = UA_malloc(sizeof(struct workerStartData));
         startData->server = server;
         startData->workerCounter = &server->workerCounters[i];
-        pthread_create(&server->thr[i], UA_NULL, (void* (*)(void*))workerLoop, startData);
+        pthread_create(&server->thr[i], NULL, (void* (*)(void*))workerLoop, startData);
     }
 
     /* try to execute the delayed callbacks every 10 sec */
     UA_Job processDelayed = {.type = UA_JOBTYPE_METHODCALL,
-                             .job.methodCall = {.method = dispatchDelayedJobs, .data = UA_NULL} };
-    UA_Server_addRepeatedJob(server, processDelayed, 10000, UA_NULL);
+                             .job.methodCall = {.method = dispatchDelayedJobs, .data = NULL} };
+    UA_Server_addRepeatedJob(server, processDelayed, 10000, NULL);
 #endif
 
     /* Start the networklayers */
@@ -637,7 +637,7 @@ UA_StatusCode UA_Server_run_shutdown(UA_Server *server, UA_UInt16 nThreads){
 #ifdef UA_MULTITHREADING
     /* Wait for all worker threads to finish */
     for(UA_UInt32 i=0;i<nThreads;i++) {
-        pthread_join(server->thr[i], UA_NULL);
+        pthread_join(server->thr[i], NULL);
         UA_free(server->workerCounters[i]);
     }
     UA_free(server->workerCounters);

+ 1 - 1
src/server/ua_services.h

@@ -202,7 +202,7 @@ void Service_UnregisterNodes(UA_Server *server, UA_Session *session, const UA_Un
 
 /* Mock-Up of the function signature for Unit Tests */
 #ifdef BUILD_UNIT_TESTS
-UA_StatusCode parse_numericrange(const UA_String str, UA_NumericRange *range);
+UA_StatusCode parse_numericrange(const UA_String *str, UA_NumericRange *range);
 #endif
 
 /**

+ 71 - 64
src/server/ua_services_attribute.c

@@ -9,70 +9,77 @@
 /* Read Attribute */
 /******************/
 
+static size_t readNumber(UA_Byte *buf, UA_Int32 buflen, UA_UInt32 *number) {
+    UA_UInt32 n = 0;
+    size_t progress = 0;
+    /* read numbers until the end or a non-number character appears */
+    UA_Byte c;
+    while((UA_Int32)progress < buflen) {
+        c = buf[progress];
+        if('0' > c || '9' < c)
+            break;
+        n = (n*10) + (c-'0');
+        progress++;
+    }
+    *number = n;
+    return progress;
+}
+
+static size_t readDimension(UA_Byte *buf, UA_Int32 buflen, struct UA_NumericRangeDimension *dim) {
+    size_t progress = readNumber(buf, buflen, &dim->min);
+    if(progress == 0)
+        return 0;
+    if(buflen <= (UA_Int32)progress || buf[progress] != ':') {
+        dim->max = dim->min;
+        return progress;
+    }
+    size_t progress2 = readNumber(&buf[progress+1], buflen - (progress + 1), &dim->max);
+    if(progress2 == 0)
+        return 0;
+    return progress + progress2 + 1;
+}
+
 #ifndef BUILD_UNIT_TESTS
 static
 #endif
-UA_StatusCode parse_numericrange(const UA_String str, UA_NumericRange *range) {
-    if(str.length < 0 || str.length >= 1023)
-        return UA_STATUSCODE_BADINTERNALERROR;
-#ifdef _MSC_VER
-    char *cstring = (char*)UA_alloca(sizeof(char)*str.length+1);
-#else
-    char cstring[str.length+1];
-#endif
-    UA_memcpy(cstring, str.data, str.length);
-    cstring[str.length] = 0;
+UA_StatusCode parse_numericrange(const UA_String *str, UA_NumericRange *range) {
     UA_Int32 index = 0;
-    size_t dimensionsIndex = 0;
-    size_t dimensionsMax = 3; // more should be uncommon, realloc if necessary
-    struct UA_NumericRangeDimension *dimensions = UA_malloc(sizeof(struct UA_NumericRangeDimension) * 3);
-    if(!dimensions)
-        return UA_STATUSCODE_BADOUTOFMEMORY;
-    
+    size_t dimensionsMax = 0;
+    struct UA_NumericRangeDimension *dimensions = NULL;
     UA_StatusCode retval = UA_STATUSCODE_GOOD;
+    UA_Int32 pos = 0;
     do {
-        UA_Int32 min, max;
-        UA_Int32 progress;
-        UA_Int32 res = sscanf(&cstring[index], "%" SCNu32 "%n", &min, &progress);
-        if(res <= 0 || min < 0) {
-            retval = UA_STATUSCODE_BADINDEXRANGEINVALID;
-            break;
-        }
-        index += progress;
-        if(index >= str.length || cstring[index] == ',')
-            max = min;
-        else {
-            res = sscanf(&cstring[index], ":%" SCNu32 "%n", &max, &progress);
-            if(res <= 0 || max < 0 || min >= max) {
-                retval = UA_STATUSCODE_BADINDEXRANGEINVALID;
+        /* alloc dimensions */
+        if(index >= (UA_Int32)dimensionsMax) {
+            struct UA_NumericRangeDimension *newds = UA_realloc(dimensions, dimensionsMax + 2);
+            if(!newds) {
+                retval = UA_STATUSCODE_BADOUTOFMEMORY;
                 break;
             }
-            index += progress;
+            dimensions = newds;
+            dimensionsMax = dimensionsMax + 2;
         }
-        
-        if(dimensionsIndex >= dimensionsMax) {
-            struct UA_NumericRangeDimension *newDimensions =
-                UA_realloc(dimensions, sizeof(struct UA_NumericRangeDimension) * 2 * dimensionsMax);
-            if(!newDimensions) {
-                UA_free(dimensions);
-                return UA_STATUSCODE_BADOUTOFMEMORY;
-            }
-            dimensions = newDimensions;
-            dimensionsMax *= 2;
+
+        /* read the dimension */
+        size_t progress = readDimension(&str->data[pos], str->length - pos, &dimensions[index]);
+        if(progress == 0) {
+            retval = UA_STATUSCODE_BADINDEXRANGEINVALID;
+            break;
         }
+        pos += progress;
+        index++;
 
-        dimensions[dimensionsIndex].min = min;
-        dimensions[dimensionsIndex].max = max;
-        dimensionsIndex++;
-    } while(retval == UA_STATUSCODE_GOOD && index + 1 < str.length && cstring[index] == ',' && ++index);
+        /* loop into the next dimension */
+        if(pos >= str->length)
+            break;
+    } while(str->data[pos] == ',' && pos++);
 
-    if(retval != UA_STATUSCODE_GOOD) {
+    if(retval == UA_STATUSCODE_GOOD && index > 0) {
+        range->dimensions = dimensions;
+        range->dimensionsSize = index;
+    } else
         UA_free(dimensions);
-        return retval;
-    }
-        
-    range->dimensions = dimensions;
-    range->dimensionsSize = dimensionsIndex;
+
     return retval;
 }
 
@@ -99,10 +106,10 @@ static void handleSourceTimestamps(UA_TimestampsToReturn timestamps, UA_DataValu
 static UA_StatusCode getVariableNodeValue(const UA_VariableNode *vn, const UA_TimestampsToReturn timestamps,
                                           const UA_ReadValueId *id, UA_DataValue *v) {
     UA_NumericRange range;
-    UA_NumericRange *rangeptr = UA_NULL;
+    UA_NumericRange *rangeptr = NULL;
     UA_StatusCode retval = UA_STATUSCODE_GOOD;
     if(id->indexRange.length > 0) {
-        retval = parse_numericrange(id->indexRange, &range);
+        retval = parse_numericrange(&id->indexRange, &range);
         if(retval != UA_STATUSCODE_GOOD)
             return retval;
         rangeptr = &range;
@@ -139,7 +146,7 @@ static UA_StatusCode getVariableNodeDataType(const UA_VariableNode *vn, UA_DataV
         /* Read from the datasource to see the data type */
         UA_DataValue val;
         UA_DataValue_init(&val);
-        retval = vn->value.dataSource.read(vn->value.dataSource.handle, vn->nodeId, UA_FALSE, UA_NULL, &val);
+        retval = vn->value.dataSource.read(vn->value.dataSource.handle, vn->nodeId, UA_FALSE, NULL, &val);
         if(retval != UA_STATUSCODE_GOOD)
             return retval;
         retval = UA_Variant_setScalarCopy(&v->value, &val.value.type->typeId, &UA_TYPES[UA_TYPES_NODEID]);
@@ -157,7 +164,7 @@ static UA_StatusCode getVariableNodeArrayDimensions(const UA_VariableNode *vn, U
         /* Read the datasource to see the array dimensions */
         UA_DataValue val;
         UA_DataValue_init(&val);
-        retval = vn->value.dataSource.read(vn->value.dataSource.handle, vn->nodeId, UA_FALSE, UA_NULL, &val);
+        retval = vn->value.dataSource.read(vn->value.dataSource.handle, vn->nodeId, UA_FALSE, NULL, &val);
         if(retval != UA_STATUSCODE_GOOD)
             return retval;
         retval = UA_Variant_setArrayCopy(&v->value, val.value.arrayDimensions,
@@ -341,7 +348,7 @@ void Service_Read(UA_Server *server, UA_Session *session, const UA_ReadRequest *
 #ifdef UA_EXTERNAL_NAMESPACES
     UA_Boolean isExternal[size];
     UA_UInt32 indices[size];
-    UA_memset(isExternal, UA_FALSE, sizeof(UA_Boolean) * size);
+    memset(isExternal, UA_FALSE, sizeof(UA_Boolean) * size);
     for(size_t j = 0;j<server->externalNamespacesSize;j++) {
         size_t indexSize = 0;
         for(size_t i = 0;i < size;i++) {
@@ -378,7 +385,7 @@ void Service_Read(UA_Server *server, UA_Session *session, const UA_ReadRequest *
 		UA_Variant variant;
 		UA_Variant_init(&variant);
 
-		UA_DateTime* expireArray = UA_NULL;
+		UA_DateTime* expireArray = NULL;
 		expireArray = UA_Array_new(&UA_TYPES[UA_TYPES_DATETIME], request->nodesToReadSize);
 		variant.data = expireArray;
 
@@ -427,7 +434,7 @@ UA_StatusCode UA_Server_editNode(UA_Server *server, UA_Session *session, const U
             UA_Node_deleteAnyNodeClass(copy);
             return retval;
         }
-        retval = UA_NodeStore_replace(server->nodestore, node, copy, UA_NULL);
+        retval = UA_NodeStore_replace(server->nodestore, node, copy, NULL);
         if(retval != UA_STATUSCODE_GOOD)
             UA_Node_deleteAnyNodeClass(copy);
 #endif
@@ -459,10 +466,10 @@ Service_Write_single_ValueDataSource(UA_Server *server, UA_Session *session, con
     UA_StatusCode retval;
     if(wvalue->indexRange.length <= 0) {
         retval = node->value.dataSource.write(node->value.dataSource.handle, node->nodeId,
-                                              &wvalue->value.value, UA_NULL);
+                                              &wvalue->value.value, NULL);
     } else {
         UA_NumericRange range;
-        retval = parse_numericrange(wvalue->indexRange, &range);
+        retval = parse_numericrange(&wvalue->indexRange, &range);
         if(retval != UA_STATUSCODE_GOOD)
             return retval;
         retval = node->value.dataSource.write(node->value.dataSource.handle, node->nodeId,
@@ -481,10 +488,10 @@ MoveValueIntoNode(UA_Server *server, UA_Session *session, UA_VariableNode *node,
 
     /* Parse the range */
     UA_NumericRange range;
-    UA_NumericRange *rangeptr = UA_NULL;
+    UA_NumericRange *rangeptr = NULL;
     UA_StatusCode retval = UA_STATUSCODE_GOOD;
     if(wvalue->indexRange.length > 0) {
-        retval = parse_numericrange(wvalue->indexRange, &range);
+        retval = parse_numericrange(&wvalue->indexRange, &range);
         if(retval != UA_STATUSCODE_GOOD)
             return retval;
         rangeptr = &range;
@@ -661,7 +668,7 @@ UA_StatusCode Service_Write_single(UA_Server *server, UA_Session *session, UA_Wr
 
 void Service_Write(UA_Server *server, UA_Session *session, const UA_WriteRequest *request,
                    UA_WriteResponse *response) {
-    UA_assert(server != UA_NULL && session != UA_NULL && request != UA_NULL && response != UA_NULL);
+    UA_assert(server != NULL && session != NULL && request != NULL && response != NULL);
     UA_LOG_DEBUG(server->logger, UA_LOGCATEGORY_SESSION,
                  "Processing WriteRequest for Session (ns=%i,i=%i)",
                  session->sessionId.namespaceIndex, session->sessionId.identifier.numeric);
@@ -680,7 +687,7 @@ void Service_Write(UA_Server *server, UA_Session *session, const UA_WriteRequest
 #ifdef UA_EXTERNAL_NAMESPACES
     UA_Boolean isExternal[request->nodesToWriteSize];
     UA_UInt32 indices[request->nodesToWriteSize];
-    UA_memset(isExternal, UA_FALSE, sizeof(UA_Boolean)*request->nodesToWriteSize);
+    memset(isExternal, UA_FALSE, sizeof(UA_Boolean)*request->nodesToWriteSize);
     for(size_t j = 0; j < server->externalNamespacesSize; j++) {
         UA_UInt32 indexSize = 0;
         for(UA_Int32 i = 0; i < request->nodesToWriteSize; i++) {

+ 1 - 1
src/server/ua_services_call.c

@@ -25,7 +25,7 @@ static const UA_VariableNode
             UA_NodeStore_release(refTarget);
         }
     }
-    return UA_NULL;
+    return NULL;
 }
 
 static UA_StatusCode

+ 14 - 14
src/server/ua_services_nodemanagement.c

@@ -43,7 +43,7 @@ void UA_Server_addExistingNode(UA_Server *server, UA_Session *session, UA_Node *
 
     // todo: test if the referencetype is hierarchical
     // todo: namespace index is assumed to be valid
-    const UA_Node *managed = UA_NULL;
+    const UA_Node *managed = NULL;
     UA_NodeId tempNodeid = node->nodeId;
     tempNodeid.namespaceIndex = 0;
     if(UA_NodeId_isNull(&tempNodeid)) {
@@ -235,7 +235,7 @@ instantiateObjectNode(UA_Server *server, UA_Session *session,
     UA_BrowseResult browseResult;
     UA_BrowseResult_init(&browseResult);
     // todo: continuation points if there are too many results
-    Service_Browse_single(server, session, UA_NULL, &browseChildren, 100, &browseResult);
+    Service_Browse_single(server, session, NULL, &browseChildren, 100, &browseResult);
 
     for(UA_Int32 i = 0; i < browseResult.referencesSize; i++) {
         UA_ReferenceDescription *rd = &browseResult.references[i];
@@ -298,7 +298,7 @@ instantiateVariableNode(UA_Server *server, UA_Session *session, const UA_NodeId
     UA_BrowseResult browseResult;
     UA_BrowseResult_init(&browseResult);
     // todo: continuation points if there are too many results
-    Service_Browse_single(server, session, UA_NULL, &browseChildren, 100, &browseResult);
+    Service_Browse_single(server, session, NULL, &browseChildren, 100, &browseResult);
 
     /* add the child properties */
     for(UA_Int32 i = 0; i < browseResult.referencesSize; i++) {
@@ -337,7 +337,7 @@ static UA_Node *
 variableNodeFromAttributes(UA_AddNodesItem *item, UA_VariableAttributes *attr) {
     UA_VariableNode *vnode = UA_VariableNode_new();
     if(!vnode)
-        return UA_NULL;
+        return NULL;
     moveStandardAttributes((UA_Node*)vnode, item, (UA_NodeAttributes*)attr);
     // todo: test if the type / valueRank / value attributes are consistent
     vnode->accessLevel = attr->accessLevel;
@@ -354,7 +354,7 @@ static UA_Node *
 objectNodeFromAttributes(UA_AddNodesItem *item, UA_ObjectAttributes *attr) {
     UA_ObjectNode *onode = UA_ObjectNode_new();
     if(!onode)
-        return UA_NULL;
+        return NULL;
     moveStandardAttributes((UA_Node*)onode, item, (UA_NodeAttributes*)attr);
     onode->eventNotifier = attr->eventNotifier;
     return (UA_Node*)onode;
@@ -364,7 +364,7 @@ static UA_Node *
 referenceTypeNodeFromAttributes(UA_AddNodesItem *item, UA_ReferenceTypeAttributes *attr) {
     UA_ReferenceTypeNode *rtnode = UA_ReferenceTypeNode_new();
     if(!rtnode)
-        return UA_NULL;
+        return NULL;
     moveStandardAttributes((UA_Node*)rtnode, item, (UA_NodeAttributes*)attr);
     rtnode->isAbstract = attr->isAbstract;
     rtnode->symmetric = attr->symmetric;
@@ -377,7 +377,7 @@ static UA_Node *
 objectTypeNodeFromAttributes(UA_AddNodesItem *item, UA_ObjectTypeAttributes *attr) {
     UA_ObjectTypeNode *otnode = UA_ObjectTypeNode_new();
     if(!otnode)
-        return UA_NULL;
+        return NULL;
     moveStandardAttributes((UA_Node*)otnode, item, (UA_NodeAttributes*)attr);
     otnode->isAbstract = attr->isAbstract;
     return (UA_Node*)otnode;
@@ -387,7 +387,7 @@ static UA_Node *
 variableTypeNodeFromAttributes(UA_AddNodesItem *item, UA_VariableTypeAttributes *attr) {
     UA_VariableTypeNode *vtnode = UA_VariableTypeNode_new();
     if(!vtnode)
-        return UA_NULL;
+        return NULL;
     moveStandardAttributes((UA_Node*)vtnode, item, (UA_NodeAttributes*)attr);
     vtnode->value.variant.value = attr->value;
     UA_Variant_init(&attr->value);
@@ -402,7 +402,7 @@ static UA_Node *
 viewNodeFromAttributes(UA_AddNodesItem *item, UA_ViewAttributes *attr) {
     UA_ViewNode *vnode = UA_ViewNode_new();
     if(!vnode)
-        return UA_NULL;
+        return NULL;
     moveStandardAttributes((UA_Node*)vnode, item, (UA_NodeAttributes*)attr);
     vnode->containsNoLoops = attr->containsNoLoops;
     vnode->eventNotifier = attr->eventNotifier;
@@ -413,7 +413,7 @@ static UA_Node *
 dataTypeNodeFromAttributes(UA_AddNodesItem *item, UA_DataTypeAttributes *attr) {
     UA_DataTypeNode *dtnode = UA_DataTypeNode_new();
     if(!dtnode)
-        return UA_NULL;
+        return NULL;
     moveStandardAttributes((UA_Node*)dtnode, item, (UA_NodeAttributes*)attr);
     dtnode->isAbstract = attr->isAbstract;
     return (UA_Node*)dtnode;
@@ -551,7 +551,7 @@ void Service_AddNodes(UA_Server *server, UA_Session *session, const UA_AddNodesR
     UA_Boolean isExternal[size];
     UA_UInt32 indices[size];
 #endif
-    UA_memset(isExternal, UA_FALSE, sizeof(UA_Boolean) * size);
+    memset(isExternal, UA_FALSE, sizeof(UA_Boolean) * size);
     for(size_t j = 0; j <server->externalNamespacesSize; j++) {
         size_t indexSize = 0;
         for(size_t i = 0;i < size;i++) {
@@ -688,7 +688,7 @@ UA_Server_addMethodNode(UA_Server *server, const UA_NodeId requestedNewNodeId,
     if(result.statusCode != UA_STATUSCODE_GOOD)
         UA_MethodNode_delete(node);
     
-    if(result.statusCode == UA_STATUSCODE_GOOD && method != UA_NULL) {
+    if(result.statusCode == UA_STATUSCODE_GOOD && method != NULL) {
         UA_ExpandedNodeId parent;
         UA_ExpandedNodeId_init(&parent);
         parent.nodeId = result.addedNodeId;
@@ -805,7 +805,7 @@ void Service_AddReferences(UA_Server *server, UA_Session *session, const UA_AddR
     UA_Boolean *isExternal = UA_alloca(sizeof(UA_Boolean) * size);
     UA_UInt32 *indices = UA_alloca(sizeof(UA_UInt32) * size);
 #endif /*NO_ALLOCA */
-    UA_memset(isExternal, UA_FALSE, sizeof(UA_Boolean) * size);
+    memset(isExternal, UA_FALSE, sizeof(UA_Boolean) * size);
 	for(size_t j = 0; j < server->externalNamespacesSize; j++) {
 		size_t indicesSize = 0;
 		for(size_t i = 0;i < size;i++) {
@@ -870,7 +870,7 @@ UA_StatusCode Service_DeleteNodes_single(UA_Server *server, UA_Session *session,
         /* browse type definitions with admin rights */
         UA_BrowseResult result;
         UA_BrowseResult_init(&result);
-        Service_Browse_single(server, &adminSession, UA_NULL, &bd, UA_UINT32_MAX, &result);
+        Service_Browse_single(server, &adminSession, NULL, &bd, UA_UINT32_MAX, &result);
         for(int i = 0; i < result.referencesSize; i++) {
             /* call the destructor */
             UA_ReferenceDescription *rd = &result.references[i];

+ 4 - 4
src/server/ua_services_session.c

@@ -50,7 +50,7 @@ void Service_ActivateSession(UA_Server *server, UA_SecureChannel *channel,
         UA_SessionManager_getSession(&server->sessionManager,
                                      (const UA_NodeId*)&request->requestHeader.authenticationToken);
 
-	if(foundSession == UA_NULL) {
+	if(foundSession == NULL) {
         response->responseHeader.serviceResult = UA_STATUSCODE_BADSESSIONIDINVALID;
         UA_LOG_DEBUG(server->logger, UA_LOGCATEGORY_SESSION,
                      "Processing ActivateSessionRequest on SecureChannel %i, but no session found for the authentication token",
@@ -81,12 +81,12 @@ void Service_ActivateSession(UA_Server *server, UA_SecureChannel *channel,
     //(Compatibility notice)
     //Siemens OPC Scout v10 provides an empty policyId, this is not okay
     //For compatibility we will assume that empty policyId == ANONYMOUS_POLICY
-    //if(token.policyId.data == UA_NULL) {
+    //if(token.policyId.data == NULL) {
     //    /* 1) no policy defined */
     //    response->responseHeader.serviceResult = UA_STATUSCODE_BADIDENTITYTOKENINVALID;
     //} else
     //(End Compatibility notice)
-    if(server->config.Login_enableAnonymous && (token.policyId.data == UA_NULL || UA_String_equal(&token.policyId, &ap))) {
+    if(server->config.Login_enableAnonymous && (token.policyId.data == NULL || UA_String_equal(&token.policyId, &ap))) {
         /* 2) anonymous logins */
         if(foundSession->channel && foundSession->channel != channel)
             UA_SecureChannel_detachSession(foundSession->channel, foundSession);
@@ -97,7 +97,7 @@ void Service_ActivateSession(UA_Server *server, UA_SecureChannel *channel,
         /* 3) username logins */
         offset = 0;
         UA_UserNameIdentityToken_decodeBinary(&request->userIdentityToken.body, &offset, &username_token);
-        if(username_token.encryptionAlgorithm.data != UA_NULL) {
+        if(username_token.encryptionAlgorithm.data != NULL) {
             /* 3.1) we only support encryption */
             response->responseHeader.serviceResult = UA_STATUSCODE_BADIDENTITYTOKENINVALID;
         } else  if(username_token.userName.length == -1 && username_token.password.length == -1){

+ 15 - 15
src/server/ua_services_view.c

@@ -83,7 +83,7 @@ static const UA_Node * returnRelevantNodeExternal(UA_ExternalNodeStore *ens, con
     UA_Array_delete(diagnosticInfos, &UA_TYPES[UA_TYPES_DIAGNOSTICINFO], 6);
     if(node && descr->nodeClassMask != 0 && (node->nodeClass & descr->nodeClassMask) == 0) {
         UA_ObjectNode_delete((UA_ObjectNode*)node);
-        return UA_NULL;
+        return NULL;
     }
     return node;
 }
@@ -97,9 +97,9 @@ returnRelevantNode(UA_Server *server, const UA_BrowseDescription *descr, UA_Bool
                    UA_Boolean *isExternal) {
     /* reference in the right direction? */
     if(reference->isInverse && descr->browseDirection == UA_BROWSEDIRECTION_FORWARD)
-        return UA_NULL;
+        return NULL;
     if(!reference->isInverse && descr->browseDirection == UA_BROWSEDIRECTION_INVERSE)
-        return UA_NULL;
+        return NULL;
 
     /* is the reference part of the hierarchy of references we look for? */
     if(!return_all) {
@@ -111,7 +111,7 @@ returnRelevantNode(UA_Server *server, const UA_BrowseDescription *descr, UA_Bool
             }
         }
         if(!is_relevant)
-            return UA_NULL;
+            return NULL;
     }
 
 #ifdef UA_EXTERNAL_NAMESPACES
@@ -129,7 +129,7 @@ returnRelevantNode(UA_Server *server, const UA_BrowseDescription *descr, UA_Bool
     const UA_Node *node = UA_NodeStore_get(server->nodestore, &reference->targetId.nodeId);
     if(node && descr->nodeClassMask != 0 && (node->nodeClass & descr->nodeClassMask) == 0) {
     	UA_NodeStore_release(node);
-        return UA_NULL;
+        return NULL;
     }
     *isExternal = UA_FALSE;
     return node;
@@ -245,7 +245,7 @@ Service_Browse_single(UA_Server *server, UA_Session *session, struct Continuatio
     
     /* get the references that match the browsedescription */
     size_t relevant_refs_size = 0;
-    UA_NodeId *relevant_refs = UA_NULL;
+    UA_NodeId *relevant_refs = NULL;
     UA_Boolean all_refs = UA_NodeId_isNull(&descr->referenceTypeId);
     if(!all_refs) {
         if(descr->includeSubtypes) {
@@ -339,7 +339,7 @@ Service_Browse_single(UA_Server *server, UA_Session *session, struct Continuatio
 #endif
         if(retval != UA_STATUSCODE_GOOD) {
             UA_Array_delete(result->references, &UA_TYPES[UA_TYPES_REFERENCEDESCRIPTION], referencesCount);
-            result->references = UA_NULL;
+            result->references = NULL;
             result->referencesSize = 0;
             result->statusCode = UA_STATUSCODE_UNCERTAINNOTALLNODESAVAILABLE;
             goto cleanup;
@@ -350,7 +350,7 @@ Service_Browse_single(UA_Server *server, UA_Session *session, struct Continuatio
     result->referencesSize = referencesCount;
     if(referencesCount == 0) {
         UA_free(result->references);
-        result->references = UA_NULL;
+        result->references = NULL;
     }
 
     cleanup:
@@ -424,7 +424,7 @@ void Service_Browse(UA_Server *server, UA_Session *session, const UA_BrowseReque
     UA_Boolean *isExternal = UA_alloca(sizeof(UA_Boolean) * size);
     UA_UInt32 *indices = UA_alloca(sizeof(UA_UInt32) * size);
 #endif /*NO_ALLOCA */
-    UA_memset(isExternal, UA_FALSE, sizeof(UA_Boolean) * size);
+    memset(isExternal, UA_FALSE, sizeof(UA_Boolean) * size);
     for(size_t j = 0; j < server->externalNamespacesSize; j++) {
         size_t indexSize = 0;
         for(size_t i = 0; i < size; i++) {
@@ -446,7 +446,7 @@ void Service_Browse(UA_Server *server, UA_Session *session, const UA_BrowseReque
 #ifdef UA_EXTERNAL_NAMESPACES
         if(!isExternal[i])
 #endif
-            Service_Browse_single(server, session, UA_NULL, &request->nodesToBrowse[i],
+            Service_Browse_single(server, session, NULL, &request->nodesToBrowse[i],
                                   request->requestedMaxReferencesPerNode, &response->results[i]);
     }
 }
@@ -473,7 +473,7 @@ void Service_BrowseNext(UA_Server *server, UA_Session *session, const UA_BrowseN
            struct ContinuationPointEntry *cp, *temp;
            LIST_FOREACH_SAFE(cp, &session->continuationPoints, pointers, temp) {
                if(UA_ByteString_equal(&cp->identifier, &request->continuationPoints[i])) {
-                   Service_Browse_single(server, session, cp, UA_NULL, 0, &response->results[i]);
+                   Service_Browse_single(server, session, cp, NULL, 0, &response->results[i]);
                    break;
                }
            }
@@ -515,7 +515,7 @@ walkBrowsePath(UA_Server *server, UA_Session *session, const UA_Node *node, cons
         return UA_STATUSCODE_BADBROWSENAMEINVALID;
 
     UA_StatusCode retval = UA_STATUSCODE_GOOD;
-    UA_NodeId *reftypes = UA_NULL;
+    UA_NodeId *reftypes = NULL;
     size_t reftypes_count = 1; // all_refs or no subtypes => 1
     UA_Boolean all_refs = UA_FALSE;
     if(UA_NodeId_isNull(&elem->referenceTypeId))
@@ -603,7 +603,7 @@ void Service_TranslateBrowsePathsToNodeIds_single(UA_Server *server, UA_Session
     if(!firstNode) {
         result->statusCode = UA_STATUSCODE_BADNODEIDUNKNOWN;
         UA_free(result->targets);
-        result->targets = UA_NULL;
+        result->targets = NULL;
         return;
     }
     result->statusCode = walkBrowsePath(server, session, firstNode, &path->relativePath, 0,
@@ -613,7 +613,7 @@ void Service_TranslateBrowsePathsToNodeIds_single(UA_Server *server, UA_Session
         result->statusCode = UA_STATUSCODE_BADNOMATCH;
     if(result->statusCode != UA_STATUSCODE_GOOD) {
         UA_Array_delete(result->targets, &UA_TYPES[UA_TYPES_BROWSEPATHTARGET], result->targetsSize);
-        result->targets = UA_NULL;
+        result->targets = NULL;
         result->targetsSize = -1;
     }
 }
@@ -644,7 +644,7 @@ void Service_TranslateBrowsePathsToNodeIds(UA_Server *server, UA_Session *sessio
     UA_Boolean *isExternal = UA_alloca(sizeof(UA_Boolean) * size);
     UA_UInt32 *indices = UA_alloca(sizeof(UA_UInt32) * size);
 #endif /*NO_ALLOCA */
-    UA_memset(isExternal, UA_FALSE, sizeof(UA_Boolean) * size);
+    memset(isExternal, UA_FALSE, sizeof(UA_Boolean) * size);
     for(size_t j = 0; j < server->externalNamespacesSize; j++) {
     	size_t indexSize = 0;
     	for(size_t i = 0;i < size;i++) {

+ 3 - 3
src/server/ua_session_manager.c

@@ -36,15 +36,15 @@ void UA_SessionManager_cleanupTimedOut(UA_SessionManager *sessionManager,
 
 UA_Session *
 UA_SessionManager_getSession(UA_SessionManager *sessionManager, const UA_NodeId *token) {
-    session_list_entry *current = UA_NULL;
+    session_list_entry *current = NULL;
     LIST_FOREACH(current, &sessionManager->sessions, pointers) {
         if(UA_NodeId_equal(&current->session.authenticationToken, token)) {
             if(UA_DateTime_now() > current->session.validTill)
-                return UA_NULL;
+                return NULL;
             return &current->session;
         }
     }
-    return UA_NULL;
+    return NULL;
 }
 
 /** Creates and adds a session. But it is not yet attached to a secure channel. */

+ 14 - 14
src/server/ua_subscription.c

@@ -9,12 +9,12 @@
 UA_Subscription *UA_Subscription_new(UA_Int32 subscriptionID) {
     UA_Subscription *new = UA_malloc(sizeof(UA_Subscription));
     if(!new)
-        return UA_NULL;
+        return NULL;
     new->subscriptionID = subscriptionID;
     new->lastPublished  = 0;
     new->sequenceNumber = 1;
     memset(&new->timedUpdateJobGuid, 0, sizeof(UA_Guid));
-    new->timedUpdateJob          = UA_NULL;
+    new->timedUpdateJob          = NULL;
     new->timedUpdateIsRegistered = UA_FALSE;
     LIST_INIT(&new->MonitoredItems);
     LIST_INIT(&new->unpublishedNotifications);
@@ -38,7 +38,7 @@ void UA_Subscription_deleteMembers(UA_Subscription *subscription, UA_Server *ser
     Subscription_deleteUnpublishedNotification(0, true, subscription);
     
     // Unhook/Unregister any timed work assiociated with this subscription
-    if(subscription->timedUpdateJob != UA_NULL){
+    if(subscription->timedUpdateJob != NULL){
         Subscription_unregisterUpdateJob(server, subscription);
         UA_free(subscription->timedUpdateJob);
     }
@@ -63,9 +63,9 @@ void Subscription_generateKeepAlive(UA_Subscription *subscription) {
     UA_unpublishedNotification *msg = UA_malloc(sizeof(UA_unpublishedNotification));
     if(!msg)
         return;
-    msg->notification = UA_NULL;
+    msg->notification = NULL;
     msg->notification = UA_malloc(sizeof(UA_NotificationMessage));
-    msg->notification->notificationData = UA_NULL;
+    msg->notification->notificationData = NULL;
     // KeepAlive uses next message, but does not increment counter
     msg->notification->sequenceNumber = subscription->sequenceNumber + 1;
     msg->notification->publishTime    = UA_DateTime_now();
@@ -155,7 +155,7 @@ void Subscription_updateNotifications(UA_Subscription *subscription) {
             
             changeNotification->monitoredItemsSize  = monItemsChangeT;
             changeNotification->diagnosticInfosSize = 0;
-            changeNotification->diagnosticInfos     = UA_NULL;
+            changeNotification->diagnosticInfos     = NULL;
         
             msg->notification->notificationData[notmsgn].body.length =
                 UA_calcSizeBinary(changeNotification, &UA_TYPES[UA_TYPES_DATACHANGENOTIFICATION]);
@@ -187,7 +187,7 @@ void Subscription_updateNotifications(UA_Subscription *subscription) {
 UA_UInt32 *Subscription_getAvailableSequenceNumbers(UA_Subscription *sub) {
     UA_UInt32 *seqArray = UA_malloc(sizeof(UA_UInt32) * Subscription_queuedNotifications(sub));
     if(!seqArray)
-        return UA_NULL;
+        return NULL;
   
     int i = 0;
     UA_unpublishedNotification *not;
@@ -269,7 +269,7 @@ static void Subscription_timedUpdateNotificationsJob(UA_Server *server, void *da
 
 
 UA_StatusCode Subscription_createdUpdateJob(UA_Server *server, UA_Guid jobId, UA_Subscription *sub) {
-    if(server == UA_NULL || sub == UA_NULL)
+    if(server == NULL || sub == NULL)
         return UA_STATUSCODE_BADSERVERINDEXINVALID;
         
     UA_Job *theWork;
@@ -287,7 +287,7 @@ UA_StatusCode Subscription_createdUpdateJob(UA_Server *server, UA_Guid jobId, UA
 }
 
 UA_StatusCode Subscription_registerUpdateJob(UA_Server *server, UA_Subscription *sub) {
-    if(server == UA_NULL || sub == UA_NULL)
+    if(server == NULL || sub == NULL)
         return UA_STATUSCODE_BADSERVERINDEXINVALID;
     
     if(sub->publishingInterval <= 5 ) 
@@ -302,7 +302,7 @@ UA_StatusCode Subscription_registerUpdateJob(UA_Server *server, UA_Subscription
 }
 
 UA_StatusCode Subscription_unregisterUpdateJob(UA_Server *server, UA_Subscription *sub) {
-    if(server == UA_NULL || sub == UA_NULL)
+    if(server == NULL || sub == NULL)
         return UA_STATUSCODE_BADSERVERINDEXINVALID;
     UA_Int32 retval = UA_Server_removeRepeatedJob(server, sub->timedUpdateJobGuid);
     sub->timedUpdateIsRegistered = UA_FALSE;
@@ -428,14 +428,14 @@ UA_Boolean MonitoredItem_CopyMonitoredValueToVariant(UA_UInt32 attributeID, cons
                 if(srcAsVariableNode->valueSource != UA_VALUESOURCE_DATASOURCE)
                     break;
                 // todo: handle numeric ranges
-                if(srcAsVariableNode->value.dataSource.read(vsrc->value.dataSource.handle, vsrc->nodeId, UA_TRUE, UA_NULL,
+                if(srcAsVariableNode->value.dataSource.read(vsrc->value.dataSource.handle, vsrc->nodeId, UA_TRUE, NULL,
                                                             &sourceDataValue) != UA_STATUSCODE_GOOD)
                     break;
                 UA_DataValue_copy(&sourceDataValue, dst);
                 if(sourceDataValue.value.data) {
                     UA_deleteMembers(sourceDataValue.value.data, sourceDataValue.value.type);
                     UA_free(sourceDataValue.value.data);
-                    sourceDataValue.value.data = UA_NULL;
+                    sourceDataValue.value.data = NULL;
                 }
                 UA_DataValue_deleteMembers(&sourceDataValue);
                 samplingError = UA_FALSE;
@@ -483,8 +483,8 @@ void MonitoredItem_QueuePushDataValue(UA_Server *server, UA_MonitoredItem *monit
     if(!newvalue)
         return;
 
-    newvalue->listEntry.tqe_next = UA_NULL;
-    newvalue->listEntry.tqe_prev = UA_NULL;
+    newvalue->listEntry.tqe_next = NULL;
+    newvalue->listEntry.tqe_prev = NULL;
     UA_DataValue_init(&newvalue->value);
 
     // Verify that the *Node being monitored is still valid

+ 16 - 16
src/ua_connection.c

@@ -12,16 +12,16 @@ void UA_Connection_init(UA_Connection *connection) {
     connection->state = UA_CONNECTION_CLOSED;
     connection->localConf = UA_ConnectionConfig_standard;
     connection->remoteConf = UA_ConnectionConfig_standard;
-    connection->channel = UA_NULL;
+    connection->channel = NULL;
     connection->sockfd = 0;
-    connection->handle = UA_NULL;
+    connection->handle = NULL;
     UA_ByteString_init(&connection->incompleteMessage);
-    connection->send = UA_NULL;
-    connection->close = UA_NULL;
-    connection->recv = UA_NULL;
-    connection->getSendBuffer = UA_NULL;
-    connection->releaseSendBuffer = UA_NULL;
-    connection->releaseRecvBuffer = UA_NULL;
+    connection->send = NULL;
+    connection->close = NULL;
+    connection->recv = NULL;
+    connection->getSendBuffer = NULL;
+    connection->releaseSendBuffer = NULL;
+    connection->releaseRecvBuffer = NULL;
 }
 
 void UA_Connection_deleteMembers(UA_Connection *connection) {
@@ -46,7 +46,7 @@ UA_Job UA_Connection_completeMessages(UA_Connection *connection, UA_ByteString r
             connection->releaseRecvBuffer(connection, &received);
             return job;
         }
-        UA_memcpy(current.data + connection->incompleteMessage.length, received.data, received.length);
+        memcpy(current.data + connection->incompleteMessage.length, received.data, received.length);
         current.length = connection->incompleteMessage.length + received.length;
         connection->releaseRecvBuffer(connection, &received);
         UA_ByteString_init(&connection->incompleteMessage);
@@ -106,7 +106,7 @@ UA_Job UA_Connection_completeMessages(UA_Connection *connection, UA_ByteString r
         /* there is an incomplete message at the end of current */
         connection->incompleteMessage.data = UA_malloc(current.length - pos);
         if(connection->incompleteMessage.data) {
-            UA_memcpy(connection->incompleteMessage.data, &current.data[pos], current.length - pos);
+            memcpy(connection->incompleteMessage.data, &current.data[pos], current.length - pos);
             connection->incompleteMessage.length = current.length - pos;
         }
         current.length = pos;
@@ -125,21 +125,21 @@ void UA_Connection_detachSecureChannel(UA_Connection *connection) {
 #ifdef UA_MULTITHREADING
     UA_SecureChannel *channel = connection->channel;
     if(channel)
-        uatomic_cmpxchg(&channel->connection, connection, UA_NULL);
-    uatomic_set(&connection->channel, UA_NULL);
+        uatomic_cmpxchg(&channel->connection, connection, NULL);
+    uatomic_set(&connection->channel, NULL);
 #else
     if(connection->channel)
-        connection->channel->connection = UA_NULL;
-    connection->channel = UA_NULL;
+        connection->channel->connection = NULL;
+    connection->channel = NULL;
 #endif
 }
 
 void UA_Connection_attachSecureChannel(UA_Connection *connection, UA_SecureChannel *channel) {
 #ifdef UA_MULTITHREADING
-    if(uatomic_cmpxchg(&channel->connection, UA_NULL, connection) == UA_NULL)
+    if(uatomic_cmpxchg(&channel->connection, NULL, connection) == NULL)
         uatomic_set(&connection->channel, channel);
 #else
-    if(channel->connection != UA_NULL)
+    if(channel->connection != NULL)
         return;
     channel->connection = connection;
     connection->channel = channel;

+ 6 - 6
src/ua_securechannel.c

@@ -13,7 +13,7 @@ void UA_SecureChannel_init(UA_SecureChannel *channel) {
     UA_ByteString_init(&channel->clientNonce);
     UA_ByteString_init(&channel->serverNonce);
     channel->sequenceNumber = 0;
-    channel->connection = UA_NULL;
+    channel->connection = NULL;
     LIST_INIT(&channel->sessions);
 }
 
@@ -34,7 +34,7 @@ void UA_SecureChannel_deleteMembersCleanup(UA_SecureChannel *channel) {
     struct SessionEntry *se, *temp;
     LIST_FOREACH_SAFE(se, &channel->sessions, pointers, temp) {
         if(se->session)
-            se->session->channel = UA_NULL;
+            se->session->channel = NULL;
         LIST_REMOVE(se, pointers);
         UA_free(se);
     }
@@ -55,12 +55,12 @@ void UA_SecureChannel_attachSession(UA_SecureChannel *channel, UA_Session *sessi
         return;
     se->session = session;
 #ifdef UA_MULTITHREADING
-    if(uatomic_cmpxchg(&session->channel, UA_NULL, channel) != UA_NULL) {
+    if(uatomic_cmpxchg(&session->channel, NULL, channel) != NULL) {
         UA_free(se);
         return;
     }
 #else
-    if(session->channel != UA_NULL) {
+    if(session->channel != NULL) {
         UA_free(se);
         return;
     }
@@ -71,7 +71,7 @@ void UA_SecureChannel_attachSession(UA_SecureChannel *channel, UA_Session *sessi
 
 void UA_SecureChannel_detachSession(UA_SecureChannel *channel, UA_Session *session) {
     if(session)
-        session->channel = UA_NULL;
+        session->channel = NULL;
     struct SessionEntry *se, *temp;
     LIST_FOREACH_SAFE(se, &channel->sessions, pointers, temp) {
         if(se->session != session)
@@ -89,7 +89,7 @@ UA_Session * UA_SecureChannel_getSession(UA_SecureChannel *channel, UA_NodeId *t
             break;
     }
     if(!se)
-        return UA_NULL;
+        return NULL;
     return se->session;
 }
 

+ 13 - 13
src/ua_session.c

@@ -3,32 +3,32 @@
 #include "ua_statuscodes.h"
 
 UA_Session anonymousSession = {
-    .clientDescription =  {.applicationUri = {-1, UA_NULL}, .productUri = {-1, UA_NULL},
-                           .applicationName = {.locale = {-1, UA_NULL}, .text = {-1, UA_NULL}},
+    .clientDescription =  {.applicationUri = {-1, NULL}, .productUri = {-1, NULL},
+                           .applicationName = {.locale = {-1, NULL}, .text = {-1, NULL}},
                            .applicationType = UA_APPLICATIONTYPE_CLIENT,
-                           .gatewayServerUri = {-1, UA_NULL}, .discoveryProfileUri = {-1, UA_NULL},
-                           .discoveryUrlsSize = -1, .discoveryUrls = UA_NULL},
+                           .gatewayServerUri = {-1, NULL}, .discoveryProfileUri = {-1, NULL},
+                           .discoveryUrlsSize = -1, .discoveryUrls = NULL},
     .sessionName = {sizeof("Anonymous Session")-1, (UA_Byte*)"Anonymous Session"},
     .authenticationToken = {.namespaceIndex = 0, .identifierType = UA_NODEIDTYPE_NUMERIC,
                             .identifier.numeric = 0}, 
     .sessionId = {.namespaceIndex = 0, .identifierType = UA_NODEIDTYPE_NUMERIC, .identifier.numeric = 0},
     .maxRequestMessageSize = UA_UINT32_MAX, .maxResponseMessageSize = UA_UINT32_MAX,
-    .timeout = UA_INT64_MAX, .validTill = UA_INT64_MAX, .channel = UA_NULL,
-    .continuationPoints = {UA_NULL}};
+    .timeout = UA_INT64_MAX, .validTill = UA_INT64_MAX, .channel = NULL,
+    .continuationPoints = {NULL}};
 
 UA_Session adminSession = {
-    .clientDescription =  {.applicationUri = {-1, UA_NULL}, .productUri = {-1, UA_NULL},
-                           .applicationName = {.locale = {-1, UA_NULL}, .text = {-1, UA_NULL}},
+    .clientDescription =  {.applicationUri = {-1, NULL}, .productUri = {-1, NULL},
+                           .applicationName = {.locale = {-1, NULL}, .text = {-1, NULL}},
                            .applicationType = UA_APPLICATIONTYPE_CLIENT,
-                           .gatewayServerUri = {-1, UA_NULL}, .discoveryProfileUri = {-1, UA_NULL},
-                           .discoveryUrlsSize = -1, .discoveryUrls = UA_NULL},
+                           .gatewayServerUri = {-1, NULL}, .discoveryProfileUri = {-1, NULL},
+                           .discoveryUrlsSize = -1, .discoveryUrls = NULL},
     .sessionName = {sizeof("Administrator Session")-1, (UA_Byte*)"Administrator Session"},
     .authenticationToken = {.namespaceIndex = 0, .identifierType = UA_NODEIDTYPE_NUMERIC,
                             .identifier.numeric = 1},
     .sessionId = {.namespaceIndex = 0, .identifierType = UA_NODEIDTYPE_NUMERIC, .identifier.numeric = 1},
     .maxRequestMessageSize = UA_UINT32_MAX, .maxResponseMessageSize = UA_UINT32_MAX,
-    .timeout = UA_INT64_MAX, .validTill = UA_INT64_MAX, .channel = UA_NULL,
-    .continuationPoints = {UA_NULL}};
+    .timeout = UA_INT64_MAX, .validTill = UA_INT64_MAX, .channel = NULL,
+    .continuationPoints = {NULL}};
 
 void UA_Session_init(UA_Session *session) {
     UA_ApplicationDescription_init(&session->clientDescription);
@@ -40,7 +40,7 @@ void UA_Session_init(UA_Session *session) {
     session->maxResponseMessageSize = 0;
     session->timeout = 0;
     UA_DateTime_init(&session->validTill);
-    session->channel = UA_NULL;
+    session->channel = NULL;
 #ifdef ENABLE_SUBSCRIPTIONS
     SubscriptionManager_init(session);
 #endif

+ 55 - 66
src/ua_types.c

@@ -81,12 +81,12 @@ UA_TYPE_DEFAULT(UA_String)
 
 void UA_String_init(UA_String *p) {
     p->length = -1;
-    p->data   = UA_NULL;
+    p->data   = NULL;
 }
 
 void UA_String_deleteMembers(UA_String *p) {
     UA_free(p->data);
-    p->data = UA_NULL;
+    p->data = NULL;
     p->length = -1;
 }
 
@@ -95,7 +95,7 @@ UA_StatusCode UA_String_copy(UA_String const *src, UA_String *dst) {
     if(src->length > 0) {
         if(!(dst->data = UA_malloc((UA_UInt32)src->length)))
             return UA_STATUSCODE_BADOUTOFMEMORY;
-        UA_memcpy((void *)dst->data, src->data, (UA_UInt32)src->length);
+        memcpy((void *)dst->data, src->data, (UA_UInt32)src->length);
     }
     dst->length = src->length;
     return UA_STATUSCODE_GOOD;
@@ -106,7 +106,7 @@ UA_String UA_String_fromChars(char const src[]) {
     size_t length = strlen(src);
     if(length == 0) {
         str.length = 0;
-        str.data = UA_NULL;
+        str.data = NULL;
         return str;
     }
     str.data = UA_malloc(length);
@@ -114,37 +114,11 @@ UA_String UA_String_fromChars(char const src[]) {
         str.length = -1;
         return str;
     }
-    UA_memcpy(str.data, src, length);
+    memcpy(str.data, src, length);
     str.length = length;
     return str;
 }
 
-#define UA_STRING_ALLOCPRINTF_BUFSIZE 1024
-UA_StatusCode UA_String_copyprintf(char const fmt[], UA_String *dst, ...) {
-    char src[UA_STRING_ALLOCPRINTF_BUFSIZE];
-    va_list ap;
-    va_start(ap, dst);
-#if ((__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || __GNUC__ > 4 || defined(__clang__))
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wformat-nonliteral"
-#endif
-    // vsnprintf should only take a literal and no variable to be secure
-    UA_Int32 len = vsnprintf(src, UA_STRING_ALLOCPRINTF_BUFSIZE, fmt, ap);
-#if ((__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || __GNUC__ > 4 || defined(__clang__))
-#pragma GCC diagnostic pop
-#endif
-    va_end(ap);
-    if(len < 0)  // FIXME: old glibc 2.0 would return -1 when truncated
-        return UA_STATUSCODE_BADINTERNALERROR;
-    // since glibc 2.1 vsnprintf returns the len that would have resulted if buf were large enough
-    len = ( len > UA_STRING_ALLOCPRINTF_BUFSIZE ? UA_STRING_ALLOCPRINTF_BUFSIZE : len );
-    if(!(dst->data = UA_malloc((UA_UInt32)len)))
-        return UA_STATUSCODE_BADOUTOFMEMORY;
-    UA_memcpy((void *)dst->data, src, (UA_UInt32)len);
-    dst->length = len;
-    return UA_STATUSCODE_GOOD;
-}
-
 UA_Boolean UA_String_equal(const UA_String *string1, const UA_String *string2) {
     if(string1->length <= 0 && string2->length <= 0)
         return UA_TRUE;
@@ -191,7 +165,7 @@ int gettimeofday(struct timeval *tp, struct timezone *tzp) {
 UA_DateTime UA_DateTime_now() {
     UA_DateTime    dateTime;
     struct timeval tv;
-    gettimeofday(&tv, UA_NULL);
+    gettimeofday(&tv, NULL);
     dateTime = (tv.tv_sec + UNIX_EPOCH_BIAS_SEC)
                * HUNDRED_NANOSEC_PER_SEC + tv.tv_usec * HUNDRED_NANOSEC_PER_USEC;
     return dateTime;
@@ -200,22 +174,29 @@ UA_DateTime UA_DateTime_now() {
 UA_DateTimeStruct UA_DateTime_toStruct(UA_DateTime atime) {
     UA_DateTimeStruct dateTimeStruct;
     //calcualting the the milli-, micro- and nanoseconds
-    dateTimeStruct.nanoSec  = (UA_Int16)((atime % 10) * 100);
-    dateTimeStruct.microSec = (UA_Int16)((atime % 10000) / 10);
-    dateTimeStruct.milliSec = (UA_Int16)((atime % 10000000) / 10000);
+    dateTimeStruct.nanoSec  = (UA_UInt16)((atime % 10) * 100);
+    dateTimeStruct.microSec = (UA_UInt16)((atime % 10000) / 10);
+    dateTimeStruct.milliSec = (UA_UInt16)((atime % 10000000) / 10000);
 
     //calculating the unix time with #include <time.h>
     time_t secSinceUnixEpoch = (atime/10000000) - UNIX_EPOCH_BIAS_SEC;
     struct tm ts = *gmtime(&secSinceUnixEpoch);
-    dateTimeStruct.sec    = (UA_Int16)ts.tm_sec;
-    dateTimeStruct.min    = (UA_Int16)ts.tm_min;
-    dateTimeStruct.hour   = (UA_Int16)ts.tm_hour;
-    dateTimeStruct.day    = (UA_Int16)ts.tm_mday;
-    dateTimeStruct.month  = (UA_Int16)(ts.tm_mon + 1);
-    dateTimeStruct.year   = (UA_Int16)(ts.tm_year + 1900);
+    dateTimeStruct.sec    = (UA_UInt16)ts.tm_sec;
+    dateTimeStruct.min    = (UA_UInt16)ts.tm_min;
+    dateTimeStruct.hour   = (UA_UInt16)ts.tm_hour;
+    dateTimeStruct.day    = (UA_UInt16)ts.tm_mday;
+    dateTimeStruct.month  = (UA_UInt16)(ts.tm_mon + 1);
+    dateTimeStruct.year   = (UA_UInt16)(ts.tm_year + 1900);
     return dateTimeStruct;
 }
 
+static void printNumber(UA_UInt16 n, UA_Byte *pos, size_t digits) {
+    for(size_t i = 0; i < digits; i++) {
+        pos[digits-i-1] = (n % 10) + '0';
+        n = n / 10;
+    }
+}
+
 UA_StatusCode UA_DateTime_toString(UA_DateTime atime, UA_String *timeString) {
     // length of the string is 31 (incl. \0 at the end)
     if(!(timeString->data = UA_malloc(32)))
@@ -223,15 +204,23 @@ UA_StatusCode UA_DateTime_toString(UA_DateTime atime, UA_String *timeString) {
     timeString->length = 31;
 
     UA_DateTimeStruct tSt = UA_DateTime_toStruct(atime);
-#ifdef _MSC_VER
-    StringCchPrintf((char*)timeString->data, (size_t)timeString->length,
-        "%02d/%02d/%04d %02d:%02d:%02d.%03d.%03d.%03d",
-        tSt.month, tSt.day, tSt.year, tSt.hour, tSt.min, tSt.sec, tSt.milliSec, tSt.microSec, tSt.nanoSec);
-#else
-    sprintf((char*)timeString->data,
-        "%02d/%02d/%04d %02d:%02d:%02d.%03d.%03d.%03d", 
-        tSt.month, tSt.day, tSt.year, tSt.hour, tSt.min, tSt.sec, tSt.milliSec, tSt.microSec, tSt.nanoSec);
-#endif
+    printNumber(tSt.month, timeString->data, 2);
+    timeString->data[2] = '/';
+    printNumber(tSt.day, &timeString->data[3], 2);
+    timeString->data[5] = '/';
+    printNumber(tSt.year, &timeString->data[6], 4);
+    timeString->data[10] = ' ';
+    printNumber(tSt.hour, &timeString->data[11], 2);
+    timeString->data[13] = ':';
+    printNumber(tSt.min, &timeString->data[14], 2);
+    timeString->data[16] = ':';
+    printNumber(tSt.sec, &timeString->data[17], 2);
+    timeString->data[19] = '.';
+    printNumber(tSt.milliSec, &timeString->data[20], 3);
+    timeString->data[23] = '.';
+    printNumber(tSt.microSec, &timeString->data[24], 3);
+    timeString->data[27] = '.';
+    printNumber(tSt.nanoSec, &timeString->data[28], 3);
     return UA_STATUSCODE_GOOD;
 }
 
@@ -269,7 +258,7 @@ UA_StatusCode UA_ByteString_newMembers(UA_ByteString *p, UA_Int32 length) {
             return UA_STATUSCODE_BADOUTOFMEMORY;
         p->length = length;
     } else {
-        p->data = UA_NULL;
+        p->data = NULL;
         if(length == 0)
             p->length = 0;
         else
@@ -485,12 +474,12 @@ void UA_DataValue_deleteMembers(UA_DataValue *p) {
 }
 
 void UA_DataValue_init(UA_DataValue *p) {
-    UA_memset(p, 0, sizeof(UA_DataValue));
+    memset(p, 0, sizeof(UA_DataValue));
     UA_Variant_init(&p->value);
 }
 
 UA_StatusCode UA_DataValue_copy(UA_DataValue const *src, UA_DataValue *dst) {
-    UA_memcpy(dst, src, sizeof(UA_DataValue));
+    memcpy(dst, src, sizeof(UA_DataValue));
     UA_Variant_init(&dst->value);
     UA_StatusCode retval = UA_Variant_copy(&src->value, &dst->value);
     if(retval) {
@@ -506,8 +495,8 @@ UA_TYPE_DEFAULT(UA_Variant)
 void UA_Variant_init(UA_Variant *p) {
     p->storageType = UA_VARIANT_DATA;
     p->arrayLength = -1;
-    p->data = UA_NULL;
-    p->arrayDimensions = UA_NULL;
+    p->data = NULL;
+    p->arrayDimensions = NULL;
     p->arrayDimensionsSize = -1;
     p->type = &UA_TYPES[UA_TYPES_BOOLEAN];
 }
@@ -519,12 +508,12 @@ void UA_Variant_deleteMembers(UA_Variant *p) {
         if(p->arrayLength == -1)
             p->arrayLength = 1;
         UA_Array_delete(p->data, p->type, p->arrayLength);
-        p->data = UA_NULL;
+        p->data = NULL;
         p->arrayLength = -1;
     }
     if(p->arrayDimensions) {
         UA_free(p->arrayDimensions);
-        p->arrayDimensions = UA_NULL;
+        p->arrayDimensions = NULL;
         p->arrayDimensionsSize = -1;
     }
 }
@@ -558,7 +547,7 @@ UA_StatusCode UA_Variant_copy(UA_Variant const *src, UA_Variant *dst) {
 }
 
 UA_Boolean UA_Variant_isScalar(const UA_Variant *v) {
-    return (v->data != UA_NULL && v->arrayLength == -1);
+    return (v->data != NULL && v->arrayLength == -1);
 }
 
 /**
@@ -775,19 +764,19 @@ void UA_DiagnosticInfo_deleteMembers(UA_DiagnosticInfo *p) {
     UA_String_deleteMembers(&p->additionalInfo);
     if(p->hasInnerDiagnosticInfo && p->innerDiagnosticInfo) {
         UA_DiagnosticInfo_delete(p->innerDiagnosticInfo);
-        p->innerDiagnosticInfo = UA_NULL;
+        p->innerDiagnosticInfo = NULL;
     }
 }
 
 void UA_DiagnosticInfo_init(UA_DiagnosticInfo *p) {
-    UA_memset(p, 0, sizeof(UA_DiagnosticInfo));
+    memset(p, 0, sizeof(UA_DiagnosticInfo));
     UA_String_init(&p->additionalInfo);
 }
 
 UA_StatusCode UA_DiagnosticInfo_copy(UA_DiagnosticInfo const *src, UA_DiagnosticInfo *dst) {
-    UA_memcpy(dst, src, sizeof(UA_DiagnosticInfo));
+    memcpy(dst, src, sizeof(UA_DiagnosticInfo));
     UA_String_init(&dst->additionalInfo);
-    dst->innerDiagnosticInfo = UA_NULL;
+    dst->innerDiagnosticInfo = NULL;
     UA_StatusCode retval = UA_STATUSCODE_GOOD;
     if(src->hasAdditionalInfo)
        retval = UA_String_copy(&src->additionalInfo, &dst->additionalInfo);
@@ -872,7 +861,7 @@ void UA_init(void *p, const UA_DataType *type) {
             ptr += (member->padding >> 3);
             *((UA_Int32*)ptr) = -1;
             ptr += sizeof(UA_Int32) + (member->padding & 0x07);
-            *((void**)ptr) = UA_NULL;
+            *((void**)ptr) = NULL;
             ptr += sizeof(void*);
         }
     }
@@ -981,7 +970,7 @@ void UA_deleteMembers(void *p, const UA_DataType *type) {
             UA_Int32 elements = *(UA_Int32*)ptr;
             ptr += sizeof(UA_Int32) + (member->padding & 0x07);
             UA_Array_delete(*(void**)ptr, memberType, elements);
-            *(void**)ptr = UA_NULL;
+            *(void**)ptr = NULL;
             ptr += sizeof(void*);
         }
     }
@@ -998,7 +987,7 @@ void UA_delete(void *p, const UA_DataType *type) {
 
 void* UA_Array_new(const UA_DataType *type, UA_Int32 elements) {
     if((UA_Int32)type->memSize * elements < 0 || type->memSize * elements > MAX_ARRAY_SIZE )
-        return UA_NULL;
+        return NULL;
 
     if(type->fixedSize)
         return UA_calloc(elements, type->memSize);
@@ -1017,7 +1006,7 @@ void* UA_Array_new(const UA_DataType *type, UA_Int32 elements) {
 
 UA_StatusCode UA_Array_copy(const void *src, void **dst, const UA_DataType *type, UA_Int32 elements) {
     if(elements <= 0) {
-        *dst = UA_NULL;
+        *dst = NULL;
         return UA_STATUSCODE_GOOD;
     }
 

+ 12 - 12
src/ua_types_encoding_binary.c

@@ -38,7 +38,7 @@ static UA_StatusCode UA_Array_encodeBinary(const void *src, UA_Int32 noElements,
 static UA_StatusCode UA_Array_decodeBinary(const UA_ByteString *src, size_t *UA_RESTRICT offset,
                                            UA_Int32 noElements_signed, void **dst, const UA_DataType *dataType) {
     if(noElements_signed <= 0) {
-        *dst = UA_NULL;
+        *dst = NULL;
         return UA_STATUSCODE_GOOD;
     }
 
@@ -75,7 +75,7 @@ static UA_StatusCode UA_Array_decodeBinary(const UA_ByteString *src, size_t *UA_
     }
     if(retval != UA_STATUSCODE_GOOD) {
         UA_Array_delete(*dst, dataType, i);
-        *dst = UA_NULL;
+        *dst = NULL;
     }
     return retval;
 }
@@ -359,7 +359,7 @@ UA_StatusCode UA_String_encodeBinary(UA_String const *src, UA_ByteString *dst, s
 
     UA_StatusCode retval = UA_Int32_encodeBinary(&src->length, dst, offset);
     if(src->length > 0) {
-        UA_memcpy(&dst->data[*offset], src->data, src->length);
+        memcpy(&dst->data[*offset], src->data, src->length);
         *offset += src->length;
     }
     return retval;
@@ -381,7 +381,7 @@ UA_StatusCode UA_String_decodeBinary(UA_ByteString const *src, size_t *UA_RESTRI
         return UA_STATUSCODE_BADDECODINGERROR;
     if(!(dst->data = UA_malloc(length)))
         return UA_STATUSCODE_BADOUTOFMEMORY;
-    UA_memcpy(dst->data, &src->data[*offset], length);
+    memcpy(dst->data, &src->data[*offset], length);
     dst->length = length;
     *offset += length;
     return UA_STATUSCODE_GOOD;
@@ -595,10 +595,10 @@ UA_StatusCode UA_QualifiedName_encodeBinary(UA_QualifiedName const *src, UA_Byte
 UA_StatusCode UA_LocalizedText_encodeBinary(UA_LocalizedText const *src, UA_ByteString *dst,
                                             size_t *UA_RESTRICT offset) {
     UA_Byte encodingMask = 0;
-    if(src->locale.data != UA_NULL)
+    if(src->locale.data != NULL)
         encodingMask |=
         UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_LOCALE;
-    if(src->text.data != UA_NULL)
+    if(src->text.data != NULL)
         encodingMask |=
         UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_TEXT;
     UA_StatusCode retval = UA_Byte_encodeBinary(&encodingMask, dst, offset);
@@ -732,7 +732,7 @@ enum UA_VARIANT_ENCODINGMASKTYPE_enum {
 
 UA_StatusCode UA_Variant_encodeBinary(UA_Variant const *src, UA_ByteString *dst, size_t *UA_RESTRICT offset) {
     UA_Boolean isArray = src->arrayLength != -1 || !src->data; // a single element is not an array
-    UA_Boolean hasDimensions = isArray && src->arrayDimensions != UA_NULL;
+    UA_Boolean hasDimensions = isArray && src->arrayDimensions != NULL;
     UA_Boolean isBuiltin = src->type->namespaceZero && UA_IS_BUILTIN(src->type->typeIndex);
     UA_Byte encodingByte = 0;
     if(isArray) {
@@ -830,7 +830,7 @@ UA_StatusCode UA_Variant_decodeBinary(UA_ByteString const *src, size_t *UA_RESTR
             UA_NodeId_deleteMembers(&typeId);
             return retval;
         }
-        const UA_DataType *dataType = UA_NULL;
+        const UA_DataType *dataType = NULL;
         if(typeId.namespaceIndex == 0 && EOencodingByte == UA_EXTENSIONOBJECT_ENCODINGMASK_BODYISBYTESTRING) {
             for(typeIndex = 0;typeIndex < UA_TYPES_COUNT; typeIndex++) {
                 if(UA_NodeId_equal(&typeId, &UA_TYPES[typeIndex].typeId)) {
@@ -912,7 +912,7 @@ UA_StatusCode UA_DiagnosticInfo_decodeBinary(UA_ByteString const *src, size_t *U
             if(UA_DiagnosticInfo_decodeBinary(src, offset,
                                               dst->innerDiagnosticInfo) != UA_STATUSCODE_GOOD) {
                 UA_free(dst->innerDiagnosticInfo);
-                dst->innerDiagnosticInfo = UA_NULL;
+                dst->innerDiagnosticInfo = NULL;
                 retval |= UA_STATUSCODE_BADINTERNALERROR;
             }
         } else {
@@ -1145,9 +1145,9 @@ static size_t UA_QualifiedName_calcSizeBinary(UA_QualifiedName const *p) {
 
 static size_t UA_LocalizedText_calcSizeBinary(UA_LocalizedText const *p) {
     size_t length = 1; // for encodingMask
-    if(p->locale.data != UA_NULL)
+    if(p->locale.data != NULL)
         length += UA_String_calcSizeBinary(&p->locale);
-    if(p->text.data != UA_NULL)
+    if(p->text.data != NULL)
         length += UA_String_calcSizeBinary(&p->text);
     return length;
 }
@@ -1170,7 +1170,7 @@ static size_t UA_ExtensionObject_calcSizeBinary(UA_ExtensionObject const *p) {
 
 static size_t UA_Variant_calcSizeBinary(UA_Variant const *p) {
     UA_Boolean isArray = p->arrayLength != -1 || !p->data; // a single element is not an array
-    UA_Boolean hasDimensions = isArray && p->arrayDimensions != UA_NULL;
+    UA_Boolean hasDimensions = isArray && p->arrayDimensions != NULL;
     UA_Boolean isBuiltin = p->type->namespaceZero && UA_IS_BUILTIN(p->type->typeIndex);
     size_t length = sizeof(UA_Byte); //p->encodingMask
     UA_Int32 arrayLength = p->arrayLength;

+ 8 - 38
src/ua_util.h

@@ -3,47 +3,23 @@
 
 #include "ua_config.h"
 
+/* Subtract from nodeids to get from the encoding to the content */
+#define UA_ENCODINGOFFSET_XML 1
+#define UA_ENCODINGOFFSET_BINARY 2
+
+#include <assert.h> // assert
+#define UA_assert(ignore) assert(ignore)
+
 /*********************/
 /* Memory Management */
 /*********************/
 
+/* Replace the macros with functions for custom allocators if necessary */
 #include <stdlib.h> // malloc, free
-#include <string.h> // memcpy
-#include <assert.h> // assert
-
-#ifdef _MSC_VER
-#include <strsafe.h>
-#endif
-
 #ifdef _WIN32
 # include <malloc.h>
 #endif
 
-/* Visual Studio does not know fnct/unistd file access results */
-#ifdef _MSC_VER
-# ifndef R_OK
-#  define R_OK 4 /* Test for read permission */
-# endif
-# ifndef R_OK
-#  define W_OK 2 /* Test for write permission */
-# endif
-# ifndef X_OK
-#  define X_OK 1 /* Test for execute permission */
-# endif
-# ifndef F_OK
-#  define F_OK 0 /* Test for existence */
-# endif
-#endif
-
-#define UA_NULL ((void *)0)
-
-/* Subtract from nodeids to get from the encoding to the content */
-#define UA_ENCODINGOFFSET_XML 1
-#define UA_ENCODINGOFFSET_BINARY 2
-
-#define UA_assert(ignore) assert(ignore)
-
-/* Replace the macros with functions for custom allocators if necessary */
 #ifndef UA_free
 # define UA_free(ptr) free(ptr)
 #endif
@@ -57,9 +33,6 @@
 # define UA_realloc(ptr, size) realloc(ptr, size)
 #endif
 
-#define UA_memcpy(dst, src, size) memcpy(dst, src, size)
-#define UA_memset(ptr, value, size) memset(ptr, value, size)
-
 #ifndef NO_ALLOCA
 # ifdef __GNUC__
 #  define UA_alloca(size) __builtin_alloca (size)
@@ -91,10 +64,7 @@
 /* System Libraries */
 /********************/
 
-#include <stdarg.h> // va_start, va_end
 #include <time.h>
-#include <stdio.h> // printf
-
 #ifdef _WIN32
 # include <winsock2.h> //needed for amalgation
 # include <windows.h>

+ 0 - 4
tests/CMakeLists.txt

@@ -34,10 +34,6 @@ add_test(memory ${CMAKE_CURRENT_BINARY_DIR}/check_memory)
 # target_link_libraries(check_stack ${LIBS})
 # add_test(stack ${CMAKE_CURRENT_BINARY_DIR}/check_stack)
 
-# add_executable(check_base64 check_base64.c)
-# target_link_libraries(check_base64 ${LIBS})
-# add_test(base64 ${CMAKE_CURRENT_BINARY_DIR}/check_base64)
-
 add_executable(check_services_view check_services_view.c $<TARGET_OBJECTS:open62541-object>)
 target_link_libraries(check_services_view ${LIBS})
 add_test(services_view ${CMAKE_CURRENT_BINARY_DIR}/check_services_view)

+ 0 - 115
tests/check_base64.c

@@ -1,115 +0,0 @@
-#include <stdlib.h> // EXIT_SUCCESS
-#include "util/ua_base64.h"
-#include "check.h"
-
-START_TEST(base64_test_2padding)
-{
-	//this is base64'd ASCII string "open62541!"
-	UA_String encodedString; UA_STRING_STATIC(encodedString, "b3BlbjYyNTQxIQ==");
-
-	//assure that we allocate exactly 10 bytes
-	ck_assert_int_eq(UA_base64_getDecodedSize(&encodedString), 10);
-
-	UA_Byte* decodedData = (UA_Byte*)malloc(UA_base64_getDecodedSize(&encodedString));
-
-	UA_base64_decode(&encodedString, decodedData);
-
-	//check the string
-	ck_assert_int_eq(decodedData[0], 'o');
-	ck_assert_int_eq(decodedData[1], 'p');
-	ck_assert_int_eq(decodedData[2], 'e');
-	ck_assert_int_eq(decodedData[3], 'n');
-	ck_assert_int_eq(decodedData[4], '6');
-	ck_assert_int_eq(decodedData[5], '2');
-	ck_assert_int_eq(decodedData[6], '5');
-	ck_assert_int_eq(decodedData[7], '4');
-	ck_assert_int_eq(decodedData[8], '1');
-	ck_assert_int_eq(decodedData[9], '!');
-
-	free(decodedData);
-}
-END_TEST
-
-START_TEST(base64_test_1padding)
-{
-
-	//this is base64'd ASCII string "open62541!!"
-	UA_String encodedString; UA_STRING_STATIC(encodedString, "b3BlbjYyNTQxISE=");
-
-	//assure that we allocate exactly 11 bytes
-	ck_assert_int_eq(UA_base64_getDecodedSize(&encodedString), 11);
-
-	UA_Byte* decodedData = (UA_Byte*)malloc(UA_base64_getDecodedSize(&encodedString));
-
-	UA_base64_decode(&encodedString, decodedData);
-
-	//check the string
-	ck_assert_int_eq(decodedData[0], 'o');
-	ck_assert_int_eq(decodedData[1], 'p');
-	ck_assert_int_eq(decodedData[2], 'e');
-	ck_assert_int_eq(decodedData[3], 'n');
-	ck_assert_int_eq(decodedData[4], '6');
-	ck_assert_int_eq(decodedData[5], '2');
-	ck_assert_int_eq(decodedData[6], '5');
-	ck_assert_int_eq(decodedData[7], '4');
-	ck_assert_int_eq(decodedData[8], '1');
-	ck_assert_int_eq(decodedData[9], '!');
-	ck_assert_int_eq(decodedData[10], '!');
-
-	free(decodedData);
-}
-END_TEST
-
-START_TEST(base64_test_0padding)
-{
-
-	//this is base64'd ASCII string "open62541"
-	UA_String encodedString; UA_STRING_STATIC(encodedString, "b3BlbjYyNTQx");
-
-	//assure that we allocate exactly 9 bytes
-	ck_assert_int_eq(UA_base64_getDecodedSize(&encodedString), 9);
-
-	UA_Byte* decodedData = (UA_Byte*)malloc(UA_base64_getDecodedSize(&encodedString));
-
-	UA_base64_decode(&encodedString, decodedData);
-
-	//check the string
-	ck_assert_int_eq(decodedData[0], 'o');
-	ck_assert_int_eq(decodedData[1], 'p');
-	ck_assert_int_eq(decodedData[2], 'e');
-	ck_assert_int_eq(decodedData[3], 'n');
-	ck_assert_int_eq(decodedData[4], '6');
-	ck_assert_int_eq(decodedData[5], '2');
-	ck_assert_int_eq(decodedData[6], '5');
-	ck_assert_int_eq(decodedData[7], '4');
-	ck_assert_int_eq(decodedData[8], '1');
-
-	free(decodedData);
-}
-END_TEST
-
-Suite*base64_testSuite(void)
-{
-	Suite *s = suite_create("base64_test");
-	TCase *tc_core = tcase_create("Core");
-	tcase_add_test(tc_core, base64_test_2padding);
-	tcase_add_test(tc_core, base64_test_1padding);
-	tcase_add_test(tc_core, base64_test_0padding);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-
-int main (void)
-{
-	int number_failed = 0;
-
-	Suite* s = base64_testSuite();
-	SRunner* sr = srunner_create(s);
-	srunner_run_all(sr,CK_NORMAL);
-	number_failed += srunner_ntests_failed(sr);
-	srunner_free(sr);
-
-	return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
-
-}
-

+ 11 - 11
tests/check_builtin.c

@@ -80,7 +80,7 @@ END_TEST
 
 START_TEST(UA_String_calcSizeWithNegativLengthShallReturnEncodingSize) {
     // given
-    UA_String arg = { -1, UA_NULL };
+    UA_String arg = { -1, NULL };
     // when
     UA_UInt32 encodingSize = UA_calcSizeBinary(&arg, &UA_TYPES[UA_TYPES_STRING]);
     // then
@@ -100,7 +100,7 @@ END_TEST
 
 START_TEST(UA_String_calcSizeWithZeroLengthShallReturnEncodingSize) {
     // given
-    UA_String arg = { 0, UA_NULL };
+    UA_String arg = { 0, NULL };
     // when
     UA_UInt32 encodingSize = UA_calcSizeBinary(&arg, &UA_TYPES[UA_TYPES_STRING]);
     // then
@@ -300,9 +300,9 @@ START_TEST(UA_Variant_calcSizeVariableSizeArrayShallReturnEncodingSize) {
 #define ARRAY_LEN 3
     arg.arrayLength = ARRAY_LEN;
     UA_String strings[3];
-    strings[0] = (UA_String) {-1, UA_NULL };
+    strings[0] = (UA_String) {-1, NULL };
     strings[1] = (UA_String) {3, (UA_Byte *)"PLT" };
-    strings[2] = (UA_String) {47, UA_NULL };
+    strings[2] = (UA_String) {47, NULL };
     arg.data   = (void *)strings;
     // when
     UA_UInt32 encodingSize = UA_calcSizeBinary(&arg, &UA_TYPES[UA_TYPES_VARIANT]);
@@ -611,7 +611,7 @@ START_TEST(UA_String_decodeWithNegativeSizeShallNotAllocateMemoryAndNullPtr) {
     // then
     ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
     ck_assert_int_eq(dst.length, -1);
-    ck_assert_ptr_eq(dst.data, UA_NULL);
+    ck_assert_ptr_eq(dst.data, NULL);
 }
 END_TEST
 
@@ -627,7 +627,7 @@ START_TEST(UA_String_decodeWithZeroSizeShallNotAllocateMemoryAndNullPtr) {
     // then
     ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
     ck_assert_int_eq(dst.length, 0);
-    ck_assert_ptr_eq(dst.data, UA_NULL);
+    ck_assert_ptr_eq(dst.data, NULL);
 }
 END_TEST
 
@@ -751,7 +751,7 @@ START_TEST(UA_Variant_decodeSingleExtensionObjectShallSetVTAndAllocateMemory){
 
     UA_Variant tmpVariant;
     UA_Variant_init(&tmpVariant);
-    tmpVariant.arrayDimensions = UA_NULL;
+    tmpVariant.arrayDimensions = NULL;
     tmpVariant.arrayDimensionsSize = -1;
     tmpVariant.arrayLength = -1;
     tmpVariant.storageType = UA_VARIANT_DATA_NODELETE;
@@ -1305,7 +1305,7 @@ START_TEST(UA_ExtensionObject_copyShallWorkOnExample) {
     ck_assert_int_eq(valueCopied.typeId.identifier.numeric, value.typeId.identifier.numeric);
 
     //finally
-    value.body.data = UA_NULL; // we cannot free the static string
+    value.body.data = NULL; // we cannot free the static string
     UA_ExtensionObject_deleteMembers(&value);
     UA_ExtensionObject_deleteMembers(&valueCopied);
 }
@@ -1390,8 +1390,8 @@ START_TEST(UA_DiagnosticInfo_copyShallWorkOnExample) {
     ck_assert_int_eq(copiedValue.symbolicId, value.symbolicId);
 
     //finally
-    value.additionalInfo.data = UA_NULL; // do not delete the static string
-    value.innerDiagnosticInfo = UA_NULL; // do not delete the static innerdiagnosticinfo
+    value.additionalInfo.data = NULL; // do not delete the static string
+    value.innerDiagnosticInfo = NULL; // do not delete the static innerdiagnosticinfo
     UA_DiagnosticInfo_deleteMembers(&value);
     UA_DiagnosticInfo_deleteMembers(&copiedValue);
 
@@ -1549,7 +1549,7 @@ START_TEST(UA_Variant_copyShallWorkOnSingleValueExample) {
     ck_assert_int_eq(value.arrayLength, copiedValue.arrayLength);
 
     //finally
-    ((UA_String*)value.data)->data = UA_NULL; // the string is statically allocated. do not free it.
+    ((UA_String*)value.data)->data = NULL; // the string is statically allocated. do not free it.
     UA_Variant_deleteMembers(&value);
     UA_Variant_deleteMembers(&copiedValue);
 }

+ 2 - 2
tests/check_memory.c

@@ -12,7 +12,7 @@ START_TEST(newAndEmptyObjectShallBeDeleted) {
 	// given
 	void *obj = UA_new(&UA_TYPES[_i]);
 	// then
-	ck_assert_ptr_ne(obj, UA_NULL);
+	ck_assert_ptr_ne(obj, NULL);
     // finally
 	UA_delete(obj, &UA_TYPES[_i]);
 }
@@ -113,7 +113,7 @@ END_TEST
 
 START_TEST(decodeScalarBasicTypeFromRandomBufferShallSucceed) {
 	// given
-	void *obj1 = UA_NULL;
+	void *obj1 = NULL;
 	UA_ByteString msg1;
 	UA_Int32 retval = UA_STATUSCODE_GOOD;
 	UA_Int32 buflen = 256;

+ 24 - 24
tests/check_nodestore.c

@@ -16,7 +16,7 @@ int zeroCnt = 0;
 int visitCnt = 0;
 static void checkZeroVisitor(const UA_Node* node) {
 	visitCnt++;
-	if (node == UA_NULL) zeroCnt++;
+	if (node == NULL) zeroCnt++;
 }
 
 static void printVisitor(const UA_Node* node) {
@@ -38,7 +38,7 @@ START_TEST(replaceExistingNode) {
     const UA_Node *inserted;
 	UA_NodeStore_insert(ns, n1, &inserted);
 	UA_Node* n2 = createNode(0,2253);
-    UA_StatusCode retval = UA_NodeStore_replace(ns, inserted, n2, UA_NULL);
+    UA_StatusCode retval = UA_NodeStore_replace(ns, inserted, n2, NULL);
     UA_NodeStore_release(inserted);
     
 	ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
@@ -51,7 +51,7 @@ START_TEST(replaceNonExistingNode) {
 	UA_NodeStore *ns = UA_NodeStore_new();
 	UA_Node* n1 = createNode(0,2253);
 	UA_Node* n2 = createNode(0,2253);
-    UA_StatusCode retval = UA_NodeStore_replace(ns, n1, n2, UA_NULL);
+    UA_StatusCode retval = UA_NodeStore_replace(ns, n1, n2, NULL);
     
 	ck_assert_int_ne(retval, UA_STATUSCODE_GOOD);
     
@@ -91,7 +91,7 @@ START_TEST(failToFindNodeInOtherUA_NodeStore) {
 	UA_NodeStore *ns = UA_NodeStore_new();
 
 	UA_Node* n1 = createNode(0,2255);
-    UA_NodeStore_insert(ns, n1, UA_NULL);
+    UA_NodeStore_insert(ns, n1, NULL);
 
 	// when
 	UA_Node* n = createNode(1,2255);
@@ -114,18 +114,18 @@ START_TEST(findNodeInUA_NodeStoreWithSeveralEntries) {
 	// given
 	UA_NodeStore *ns = UA_NodeStore_new();
 	UA_Node* n1 = createNode(0,2253);
-    UA_NodeStore_insert(ns, n1, UA_NULL);
+    UA_NodeStore_insert(ns, n1, NULL);
 	UA_Node* n2 = createNode(0,2255);
-    UA_NodeStore_insert(ns, n2, UA_NULL);
+    UA_NodeStore_insert(ns, n2, NULL);
 	UA_Node* n3 = createNode(0,2257);
     const UA_Node *inserted;
     UA_NodeStore_insert(ns, n3, &inserted);
 	UA_Node* n4 = createNode(0,2200);
-    UA_NodeStore_insert(ns, n4, UA_NULL);
+    UA_NodeStore_insert(ns, n4, NULL);
 	UA_Node* n5 = createNode(0,1);
-    UA_NodeStore_insert(ns, n5, UA_NULL);
+    UA_NodeStore_insert(ns, n5, NULL);
 	UA_Node* n6 = createNode(0,12);
-    UA_NodeStore_insert(ns, n6, UA_NULL);
+    UA_NodeStore_insert(ns, n6, NULL);
 
 	// when
 	const UA_Node* nr = UA_NodeStore_get(ns,&inserted->nodeId);
@@ -148,17 +148,17 @@ START_TEST(iterateOverUA_NodeStoreShallNotVisitEmptyNodes) {
 	// given
 	UA_NodeStore *ns = UA_NodeStore_new();
 	UA_Node* n1 = createNode(0,2253);
-    UA_NodeStore_insert(ns, n1, UA_NULL);
+    UA_NodeStore_insert(ns, n1, NULL);
 	UA_Node* n2 = createNode(0,2255);
-    UA_NodeStore_insert(ns, n2, UA_NULL);
+    UA_NodeStore_insert(ns, n2, NULL);
 	UA_Node* n3 = createNode(0,2257);
-    UA_NodeStore_insert(ns, n3, UA_NULL);
+    UA_NodeStore_insert(ns, n3, NULL);
 	UA_Node* n4 = createNode(0,2200);
-    UA_NodeStore_insert(ns, n4, UA_NULL);
+    UA_NodeStore_insert(ns, n4, NULL);
 	UA_Node* n5 = createNode(0,1);
-    UA_NodeStore_insert(ns, n5, UA_NULL);
+    UA_NodeStore_insert(ns, n5, NULL);
 	UA_Node* n6 = createNode(0,12);
-    UA_NodeStore_insert(ns, n6, UA_NULL);
+    UA_NodeStore_insert(ns, n6, NULL);
 
 	// when
 	zeroCnt = 0;
@@ -185,7 +185,7 @@ START_TEST(findNodeInExpandedNamespace) {
 	UA_Int32 i=0;
 	for (; i<200; i++) {
 		n = createNode(0,i);
-        UA_NodeStore_insert(ns, n, UA_NULL);
+        UA_NodeStore_insert(ns, n, NULL);
 	}
 	// when
 	UA_Node *n2 = createNode(0,25);
@@ -212,7 +212,7 @@ START_TEST(iterateOverExpandedNamespaceShallNotVisitEmptyNodes) {
 	UA_Int32 i=0;
 	for (; i<200; i++) {
 		n = createNode(0,i);
-        UA_NodeStore_insert(ns, n, UA_NULL);
+        UA_NodeStore_insert(ns, n, NULL);
 	}
 	// when
 	zeroCnt = 0;
@@ -236,15 +236,15 @@ START_TEST(failToFindNonExistantNodeInUA_NodeStoreWithSeveralEntries) {
 	// given
 	UA_NodeStore *ns = UA_NodeStore_new();
 	UA_Node* n1 = createNode(0,2253);
-    UA_NodeStore_insert(ns, n1, UA_NULL);
+    UA_NodeStore_insert(ns, n1, NULL);
 	UA_Node* n2 = createNode(0,2255);
-    UA_NodeStore_insert(ns, n2, UA_NULL);
+    UA_NodeStore_insert(ns, n2, NULL);
 	UA_Node* n3 = createNode(0,2257);
-    UA_NodeStore_insert(ns, n3, UA_NULL);
+    UA_NodeStore_insert(ns, n3, NULL);
 	UA_Node* n4 = createNode(0,2200);
-    UA_NodeStore_insert(ns, n4, UA_NULL);
+    UA_NodeStore_insert(ns, n4, NULL);
 	UA_Node* n5 = createNode(0,1);
-    UA_NodeStore_insert(ns, n5, UA_NULL);
+    UA_NodeStore_insert(ns, n5, NULL);
 	UA_Node* n6 = createNode(0,12); 
 
 	// when
@@ -289,7 +289,7 @@ static void *profileGetThread(void *arg) {
 	}
 	rcu_unregister_thread();
 	
-	return UA_NULL;
+	return NULL;
 }
 #endif
 
@@ -303,7 +303,7 @@ START_TEST(profileGetDelete) {
 	UA_Node *n;
 	for (int i=0; i<N; i++) {
 		n = createNode(0,i);
-        UA_NodeStore_insert(ns, n, UA_NULL);
+        UA_NodeStore_insert(ns, n, NULL);
 	}
 	clock_t begin, end;
 	begin = clock();

+ 2 - 2
tests/check_services_attributes.c

@@ -879,7 +879,7 @@ START_TEST(WriteSingleAttributeUserExecutable) {
 START_TEST(numericRange) {
     UA_NumericRange range;
     const UA_String str = (UA_String){9, (UA_Byte*)"1:2,0:3,5"};
-    UA_StatusCode retval = parse_numericrange(str, &range);
+    UA_StatusCode retval = parse_numericrange(&str, &range);
     ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
     ck_assert_int_eq(range.dimensionsSize,3);
     ck_assert_int_eq(range.dimensions[0].min,1);
@@ -958,7 +958,7 @@ int main(void) {
 	Suite *s;
 	s = testSuite_services_attributes();
 	SRunner *sr = srunner_create(s);
-	// srunner_set_fork_status(sr, CK_NOFORK);
+	srunner_set_fork_status(sr, CK_NOFORK);
 	srunner_run_all(sr, CK_NORMAL);
 
 	number_failed += srunner_ntests_failed(sr);

+ 1 - 1
tests/check_services_view.c

@@ -17,7 +17,7 @@
 	request.browsePathsSize = 1;
 	UA_Array_new((void**)&request.browsePaths,request.browsePathsSize, &UA_.types[UA_BROWSEPATH]);
 
-	Service_TranslateBrowsePathsToNodeIds(UA_NULL,&request,&response);
+	Service_TranslateBrowsePathsToNodeIds(NULL,&request,&response);
 
 	ck_assert_int_eq(response.resultsSize,request.browsePathsSize);
 	ck_assert_int_eq(response.results[0].statusCode,UA_STATUSCODE_BADNOMATCH);

+ 4 - 4
tests/check_session.c

@@ -31,13 +31,13 @@ START_TEST(Session_init_ShallWork)
 	ck_assert_int_eq(session.activated,UA_FALSE);
 	ck_assert_int_eq(session.authenticationToken.identifier.numeric,tmpNodeId.identifier.numeric);
 	ck_assert_int_eq(session.availableContinuationPoints,MAXCONTINUATIONPOINTS);
-    ck_assert_ptr_eq(session.channel,UA_NULL);
-    ck_assert_ptr_eq(session.clientDescription.applicationName.locale.data,UA_NULL);
-    ck_assert_ptr_eq(session.continuationPoints.lh_first, UA_NULL);
+    ck_assert_ptr_eq(session.channel,NULL);
+    ck_assert_ptr_eq(session.clientDescription.applicationName.locale.data,NULL);
+    ck_assert_ptr_eq(session.continuationPoints.lh_first, NULL);
     ck_assert_int_eq(session.maxRequestMessageSize,0);
     ck_assert_int_eq(session.maxResponseMessageSize,0);
     ck_assert_int_eq(session.sessionId.identifier.numeric,tmpNodeId.identifier.numeric);
-    ck_assert_ptr_eq(session.sessionName.data,UA_NULL);
+    ck_assert_ptr_eq(session.sessionName.data,NULL);
     ck_assert_int_eq(session.timeout,0);
     ck_assert_int_eq(session.validTill,tmpDateTime);
 

+ 3 - 3
tests/check_stack.c

@@ -79,7 +79,7 @@ UA_Int32 stackTestFixture_delete(UA_UInt32 fixtureHandle) {
 stackTestFixture *stackTestFixture_getFixture(UA_UInt32 fixtureHandle) {
 	if(fixtureHandle < MAX_FIXTURES && ( fixturesMap & (1 << fixtureHandle)))
 		return fixtures[fixtureHandle];
-	return UA_NULL;
+	return NULL;
 }
 
 /** @brief write message provided in the gather buffers to the buffer of the fixture */
@@ -329,7 +329,7 @@ UA_Byte pkt_MSG_CreateSession[] = {
 START_TEST(emptyIndicationShallYieldNoResponse) {
 	// given
 	UA_Int32 handle = stackTestFixture_create(responseMsg, closerCallback);
-	UA_ByteString message = { -1, (UA_Byte *)UA_NULL };
+	UA_ByteString message = { -1, (UA_Byte *)NULL };
 
 	// when
 	indicateMsg(handle, &message);
@@ -424,7 +424,7 @@ START_TEST(validCreateSessionShallCreateSession) {
 
 
 	SL_ChannelManager_getChannel(25,&channel);
-	ck_assert_ptr_ne(channel,UA_NULL);
+	ck_assert_ptr_ne(channel,NULL);
 
 
 

+ 0 - 173
tests/check_xml.c

@@ -1,173 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include "ua_xml.h"
-#include "util/ua_util.h"
-#include "ua_types_generated.h"
-#include "ua_namespace.h"
-#include "ua_namespace_xml.h"
-#include "check.h"
-
-START_TEST(parseNumericNodeIdWithoutNsIdShallYieldNs0NodeId)
-{
-	// given
-	char txt[] = "i=2";
-	UA_NodeId nodeId = { (UA_Byte) 0, (UA_UInt16) 0, { 0 } };
-
-	// when
-	UA_Int32 retval = UA_NodeId_copycstring(txt,&nodeId,UA_NULL);
-
-	// then
-	ck_assert_int_eq(retval,UA_SUCCESS);
-	ck_assert_int_eq(nodeId.encodingByte,UA_NODEIDTYPE_FOURBYTE);
-	ck_assert_int_eq(nodeId.namespace,0);
-	ck_assert_int_eq(nodeId.identifier.numeric,2);
-
-	// finally
-}
-END_TEST
-
-START_TEST(parseNumericNodeIdWithNsShallYieldNodeIdWithNs)
-{
-	// given
-	char txt[] = "ns=1;i=2";
-	UA_NodeId nodeId = { (UA_Byte) 0, (UA_UInt16) 0, { 0 } };
-
-	// when
-	UA_Int32 retval = UA_NodeId_copycstring(txt,&nodeId,UA_NULL);
-
-	// then
-	ck_assert_int_eq(retval,UA_SUCCESS);
-	ck_assert_int_eq(nodeId.encodingByte,UA_NODEIDTYPE_FOURBYTE);
-	ck_assert_int_eq(nodeId.namespace,1);
-	ck_assert_int_eq(nodeId.identifier.numeric,2);
-
-	// finally
-}
-END_TEST
-
-START_TEST(loadUserNamespaceWithSingleProcessVariableShallSucceed)
-{
-	// given
-	char xml[]=
-"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
-"<UANodeSet>"
-	"<UAVariable NodeId=\"ns=1;i=2\" BrowseName=\"X1\" DataType=\"i=6\">"
-		"<DisplayName>Integer Variable</DisplayName>"
-		"<References>"
-			"<Reference ReferenceType=\"i=40\">i=63</Reference>"
-		"</References>"
-	"</UAVariable>"
-"</UANodeSet>";
-	Namespace *ns;
-	UA_NodeId nodeId;
-	UA_Int32 retval;
-
-	// when
-	retval = Namespace_loadFromString(&ns,1,"ROOT",xml);
-
-	// then
-	ck_assert_int_eq(retval,UA_SUCCESS);
-	ck_assert_ptr_ne(ns,UA_NULL);
-
-	UA_NodeId_copycstring("ns=1;i=2",&nodeId,UA_NULL);
-	ck_assert_int_eq(Namespace_contains(ns,&nodeId),UA_TRUE);
-
-	const UA_Node* nr = UA_NULL;
-	Namespace_Entry_Lock* nl = UA_NULL;
-	retval = Namespace_get(ns,&nodeId,&nr,&nl);
-	ck_assert_int_eq(retval,UA_SUCCESS);
-	ck_assert_ptr_ne(nr,UA_NULL);
-	ck_assert_int_eq(nr->references[0].referenceTypeId.identifier.numeric,40);
-	ck_assert_int_eq(nr->references[0].targetId.nodeId.identifier.numeric,63);
-
-
-	UA_NodeId_copycstring("i=2",&nodeId,UA_NULL);
-	ck_assert_int_eq(Namespace_contains(ns,&nodeId),UA_FALSE);
-
-	// finally
-	Namespace_delete(ns);
-}
-END_TEST
-
-START_TEST(loadUserNamespaceWithSingleProcessVariableAndAliasesShallSucceed)
-{
-	// given
-	char xml[]=
-"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
-"<UANodeSet>"
-	"<Aliases>"
-		"<Alias Alias=\"Int32\">i=6</Alias>"
-		"<Alias Alias=\"HasTypeDefinition\">i=40</Alias>"
-	"</Aliases>"
-	"<UAVariable NodeId=\"ns=1;i=4\" BrowseName=\"X1\" DataType=\"Int32\">"
-		"<DisplayName>Integer Variable</DisplayName>"
-		"<References>"
-			"<Reference ReferenceType=\"HasTypeDefinition\">i=63</Reference>"
-		"</References>"
-	"</UAVariable>"
-"</UANodeSet>";
-	Namespace *ns;
-	UA_NodeId nodeId;
-	UA_Int32 retval;
-
-	// when
-	retval = Namespace_loadFromString(&ns,1,"ROOT",xml);
-
-	// then
-	ck_assert_ptr_ne(ns,UA_NULL);
-	ck_assert_int_eq(retval,UA_SUCCESS);
-
-	UA_NodeId_copycstring("ns=1;i=4",&nodeId,UA_NULL);
-	ck_assert_int_eq(Namespace_contains(ns,&nodeId),UA_TRUE);
-
-	const UA_Node* nr = UA_NULL;
-	Namespace_Entry_Lock* nl = UA_NULL;
-	retval = Namespace_get(ns,&nodeId,&nr,&nl);
-	ck_assert_int_eq(retval,UA_SUCCESS);
-	ck_assert_ptr_ne(nr,UA_NULL);
-	ck_assert_int_eq(nr->references[0].referenceTypeId.identifier.numeric,40);
-	ck_assert_int_eq(nr->references[0].targetId.nodeId.identifier.numeric,63);
-
-	UA_NodeId_copycstring("ns=1;i=2",&nodeId,UA_NULL);
-	ck_assert_int_eq(Namespace_contains(ns,&nodeId),UA_FALSE);
-
-	UA_NodeId_copycstring("ns=2;i=4",&nodeId,UA_NULL);
-	ck_assert_int_eq(Namespace_contains(ns,&nodeId),UA_FALSE);
-
-	UA_NodeId_copycstring("i=4",&nodeId,UA_NULL);
-	ck_assert_int_eq(Namespace_contains(ns,&nodeId),UA_FALSE);
-
-	// finally
-	Namespace_delete(ns);
-}
-END_TEST
-
-Suite* testSuite()
-{
-	Suite *s = suite_create("XML Test");
-	TCase *tc_core = tcase_create("Core");
-
-	tcase_add_test(tc_core, parseNumericNodeIdWithoutNsIdShallYieldNs0NodeId);
-	tcase_add_test(tc_core, parseNumericNodeIdWithNsShallYieldNodeIdWithNs);
-	tcase_add_test(tc_core, loadUserNamespaceWithSingleProcessVariableShallSucceed);
-	tcase_add_test(tc_core, loadUserNamespaceWithSingleProcessVariableAndAliasesShallSucceed);
-	suite_add_tcase(s,tc_core);
-	return s;
-}
-
-int main (void)
-{
-	int number_failed = 0;
-
-	Suite *s;
-	SRunner *sr;
-
-	s = testSuite();
-	sr = srunner_create(s);
-	srunner_set_fork_status(sr, CK_NOFORK);
-	srunner_run_all(sr,CK_NORMAL);
-	number_failed += srunner_ntests_failed(sr);
-	srunner_free(sr);
-
-	return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
-}

+ 3 - 3
tools/pyUANamespace/open62541_MacroHelper.py

@@ -77,7 +77,7 @@ class open62541_MacroHelper():
     #else:
       #code.append(refid + ".isForward = UA_FALSE;")
     #code.append(refid + ".targetNodeId = " + self.getCreateExpandedNodeIDMacro(reference.target()) + ";")
-    #code.append("addOneWayReferenceWithSession(server, (UA_Session *) UA_NULL, &" + refid + ");")
+    #code.append("addOneWayReferenceWithSession(server, (UA_Session *) NULL, &" + refid + ");")
 
     if reference.isForward():
       code.append("UA_Server_addReference(server, " + self.getCreateNodeIDMacro(sourcenode) + ", " + self.getCreateNodeIDMacro(reference.referenceType()) + ", " + self.getCreateExpandedNodeIDMacro(reference.target()) + ", UA_TRUE);")
@@ -132,9 +132,9 @@ class open62541_MacroHelper():
       code.append("       , typeDefinition")
     
     if nodetype != "Method":
-      code.append("       , attr, UA_NULL);")
+      code.append("       , attr, NULL);")
     else:
-      code.append("       , attr, (UA_MethodCallback) UA_NULL, UA_NULL, 0, UA_NULL, 0, UA_NULL, UA_NULL);")
+      code.append("       , attr, (UA_MethodCallback) NULL, NULL, 0, NULL, 0, NULL, NULL);")
     return code
     
   def getCreateNodeBootstrap(self, node):

+ 1 - 1
tools/pyUANamespace/ua_namespace.py

@@ -642,7 +642,7 @@ class opcua_namespace():
     header.append('#include "ua_types.h"')
     header.append('#else')
     header.append('#include "open62541.h"')
-    header.append('#define UA_NULL ((void *)0)')
+    header.append('#define NULL ((void *)0)')
     header.append('#endif')
       
     code.append('#include "'+outfilename+'.h"')

+ 5 - 5
tools/pyUANamespace/ua_node_types.py

@@ -685,7 +685,7 @@ class opcua_node_t:
       code = code + codegen.getCreateNodeBootstrap(self)
       code = code + self.printOpen62541CCode_Subtype(unPrintedReferences = unPrintedReferences, bootstrapping = True)
       code.append("// Parent node does not exist yet. This node will be bootstrapped and linked later.")
-      code.append("UA_NodeStore_insert(server->nodestore, (UA_Node*) " + self.getCodePrintableID() + ", UA_NULL);")
+      code.append("UA_NodeStore_insert(server->nodestore, (UA_Node*) " + self.getCodePrintableID() + ", NULL);")
       
     # Try to print all references to nodes that already exist
     # Note: we know the reference types exist, because the namespace class made sure they were
@@ -1150,10 +1150,10 @@ class opcua_node_method_t(opcua_node_t):
     if bootstrapping == False:
       code.append("       // Note: in/outputArguments are added by attaching the variable nodes,")
       code.append("       //       not by including the in the addMethodNode() call.")
-      code.append("       UA_NULL,")
-      code.append("       UA_NULL,")
-      code.append("       0, UA_NULL,")
-      code.append("       0, UA_NULL,")
+      code.append("       NULL,")
+      code.append("       NULL,")
+      code.append("       0, NULL,")
+      code.append("       0, NULL,")
       code.append("       // FIXME: Missing executable")
       code.append("       // FIXME: Missing userExecutable")
       return code