Prechádzať zdrojové kódy

libopen62541 compiles with Visual Studio 2013

Julius Pfrommer 9 rokov pred
rodič
commit
981725b5b3

+ 16 - 4
CMakeLists.txt

@@ -3,7 +3,7 @@ project (open62541)
 set (open62541_VERSION_MAJOR 0)
 set (open62541_VERSION_MINOR 1)
 
-# set (CMAKE_VERBOSE_MAKEFILE on )
+set (CMAKE_VERBOSE_MAKEFILE on )
 if (CMAKE_COMPILER_IS_GNUCC)
 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -pedantic -pipe -fstack-protector -Wall -Wextra -Wno-unused-parameter -Wno-unused-function -Wno-unused-label -Wpointer-arith -Wformat -Wreturn-type -Wsign-compare -Wmultichar -Wformat-nonliteral -Winit-self -Wuninitialized -Wno-deprecated -Wformat-security -Werror -ffunction-sections -fdata-sections -Wl,--gc-sections")
 endif (CMAKE_COMPILER_IS_GNUCC)
@@ -17,14 +17,14 @@ endif (MULTITHREADING)
 # encodings
 set (UA_ENCODING_AMOUNT 1) # binary encoding
 
-set (UA_ENCODING_XML ON CACHE BOOL "Enable XML-encoding of the UA types")
+set (UA_ENCODING_XML OFF CACHE BOOL "Enable XML-encoding of the UA types")
 if (UA_ENCODING_XML)
     MATH(EXPR UA_ENCODING_AMOUNT "${UA_ENCODING_AMOUNT}+1")
     find_package (EXPAT REQUIRED)
     if (EXPAT_FOUND)
         include_directories (${EXPAT_INCLUDE_DIRS})
     else (EXPAT_FOUND)
-        message (fatal_error "Expat library not found.")
+        message (FATAL_ERROR "Expat library not found.")
     endif (EXPAT_FOUND)
 endif (UA_ENCODING_XML)
 
@@ -81,7 +81,7 @@ if (UA_ENCODING_JSON)
     set (generate_options "${generate_options}--with-json")
 endif (UA_ENCODING_JSON)
 
-add_library(open62541 ${lib_sources})
+add_library (open62541 ${lib_sources})
 
 # generate data structures
 add_custom_command (OUTPUT ${PROJECT_BINARY_DIR}/ua_types_generated.c
@@ -96,6 +96,18 @@ add_custom_command (OUTPUT ${PROJECT_BINARY_DIR}/ua_namespace_0.c
                     DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/generate_namespace.py
                             ${CMAKE_CURRENT_SOURCE_DIR}/schema/NodeIds.csv)
 
+# download queue.h if required
+if (WIN32)
+	if (NOT EXISTS "${PROJECT_BINARY_DIR}/queue.h")
+        file (DOWNLOAD "http://openbsd.cs.toronto.edu/cgi-bin/cvsweb/~checkout~/src/sys/sys/queue.h" "${PROJECT_BINARY_DIR}/queue.h" STATUS result)
+		list (GET result 0 download_ok)
+		if (NOT ${download_ok} MATCHES 0)
+			execute_process (COMMAND rm "${PROJECT_BINARY_DIR}/queue.h") # remove empty file if created
+			message (FATAL_ERROR "queue.h could not be downloaded")
+		endif ()
+	endif ()
+endif (WIN32)
+
 # build example implementations
 add_executable(exampleServer examples/src/opcuaServer.c
                              examples/src/networklayer.c)

+ 183 - 264
src/ua_application.c

@@ -73,13 +73,23 @@ void appMockup_init() {
 	UA_NodeId RefTypeId_HasEffect = NS0NODEID(54);
 	UA_NodeId RefTypeId_HasHistoricalConfiguration = NS0NODEID(56);
 
+#define ADDINVERSEREFERENCE(NODE,REFTYPE,TARGET_NODEID) \
+	static struct UA_ReferenceNode NODE##ReferenceNode; \
+	UA_ReferenceNode_init(&NODE##ReferenceNode); \
+	NODE##ReferenceNode.referenceTypeId = REFTYPE; \
+	NODE##ReferenceNode.isInverse = UA_TRUE; \
+	NODE##ReferenceNode.targetId.nodeId = TARGET_NODEID; \
+	NODE##ReferenceNode.targetId.namespaceUri = UA_STRING_NULL; \
+	NODE##ReferenceNode.targetId.serverIndex = 0; \
+	AddReference((UA_Node*)NODE, &NODE##ReferenceNode, ns0)
+
 	UA_ReferenceTypeNode *references;
 	UA_ReferenceTypeNode_new(&references);
 	references->nodeId = RefTypeId_References;
 	references->nodeClass = UA_NODECLASS_REFERENCETYPE;
-	references->browseName = UA_QUALIFIEDNAME_STATIC("References");
-	references->displayName = UA_LOCALIZEDTEXT_STATIC("References");
-	references->description = UA_LOCALIZEDTEXT_STATIC("References");
+	UA_QUALIFIEDNAME_STATIC(references->browseName, "References");
+	UA_LOCALIZEDTEXT_STATIC(references->displayName, "References");
+	UA_LOCALIZEDTEXT_STATIC(references->description, "References");
 	references->isAbstract = UA_TRUE;
 	references->symmetric = UA_TRUE;
 	Namespace_insert(ns0,(UA_Node**)&references, NAMESPACE_INSERT_UNIQUE);
@@ -88,343 +98,329 @@ void appMockup_init() {
 	UA_ReferenceTypeNode_new(&hierarchicalreferences);
 	hierarchicalreferences->nodeId = RefTypeId_HierarchicalReferences;
 	hierarchicalreferences->nodeClass = UA_NODECLASS_REFERENCETYPE;
-	hierarchicalreferences->browseName = UA_QUALIFIEDNAME_STATIC("HierarchicalReferences");
-	hierarchicalreferences->displayName = UA_LOCALIZEDTEXT_STATIC("HierarchicalReferences");
-	hierarchicalreferences->description = UA_LOCALIZEDTEXT_STATIC("HierarchicalReferences");
+	UA_QUALIFIEDNAME_STATIC(hierarchicalreferences->browseName, "HierarchicalReferences");
+	UA_LOCALIZEDTEXT_STATIC(hierarchicalreferences->displayName, "HierarchicalReferences");
+	UA_LOCALIZEDTEXT_STATIC(hierarchicalreferences->description, "HierarchicalReferences");
 	hierarchicalreferences->isAbstract = UA_TRUE;
 	hierarchicalreferences->symmetric = UA_FALSE;
-	AddReference((UA_Node*)hierarchicalreferences, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
-		(UA_ExpandedNodeId){RefTypeId_References, UA_STRING_NULL, 0}}, ns0);
+	ADDINVERSEREFERENCE(hierarchicalreferences, RefTypeId_HasSubtype, RefTypeId_References);
 	Namespace_insert(ns0,(UA_Node**)&hierarchicalreferences, NAMESPACE_INSERT_UNIQUE);
 
 	UA_ReferenceTypeNode *nonhierarchicalreferences;
 	UA_ReferenceTypeNode_new(&nonhierarchicalreferences);
 	nonhierarchicalreferences->nodeId = RefTypeId_NonHierarchicalReferences;
 	nonhierarchicalreferences->nodeClass = UA_NODECLASS_REFERENCETYPE;
-	nonhierarchicalreferences->browseName = UA_QUALIFIEDNAME_STATIC("NonHierarchicalReferences");
-	nonhierarchicalreferences->displayName = UA_LOCALIZEDTEXT_STATIC("NonHierarchicalReferences");
-	nonhierarchicalreferences->description = UA_LOCALIZEDTEXT_STATIC("NonHierarchicalReferences");
+	UA_QUALIFIEDNAME_STATIC(nonhierarchicalreferences->browseName, "NonHierarchicalReferences");
+	UA_LOCALIZEDTEXT_STATIC(nonhierarchicalreferences->displayName, "NonHierarchicalReferences");
+	UA_LOCALIZEDTEXT_STATIC(nonhierarchicalreferences->description, "NonHierarchicalReferences");
 	nonhierarchicalreferences->isAbstract = UA_TRUE;
 	nonhierarchicalreferences->symmetric = UA_FALSE;
-	AddReference((UA_Node*)nonhierarchicalreferences, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
-		(UA_ExpandedNodeId){RefTypeId_References, UA_STRING_NULL, 0}}, ns0);
+	ADDINVERSEREFERENCE(nonhierarchicalreferences, RefTypeId_HasSubtype, RefTypeId_References);
 	Namespace_insert(ns0,(UA_Node**)&nonhierarchicalreferences, NAMESPACE_INSERT_UNIQUE);
 
 	UA_ReferenceTypeNode *haschild;
 	UA_ReferenceTypeNode_new(&haschild);
 	haschild->nodeId = RefTypeId_HasChild;
 	haschild->nodeClass = UA_NODECLASS_REFERENCETYPE;
-	haschild->browseName = UA_QUALIFIEDNAME_STATIC("HasChild");
-	haschild->displayName = UA_LOCALIZEDTEXT_STATIC("HasChild");
-	haschild->description = UA_LOCALIZEDTEXT_STATIC("HasChild");
+	UA_QUALIFIEDNAME_STATIC(haschild->browseName, "HasChild");
+	UA_LOCALIZEDTEXT_STATIC(haschild->displayName, "HasChild");
+	UA_LOCALIZEDTEXT_STATIC(haschild->description, "HasChild");
 	haschild->isAbstract = UA_TRUE;
 	haschild->symmetric = UA_FALSE;
-	AddReference((UA_Node*)haschild, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
-		(UA_ExpandedNodeId){RefTypeId_HierarchicalReferences, UA_STRING_NULL, 0}}, ns0);
+	ADDINVERSEREFERENCE(haschild, RefTypeId_HasSubtype, RefTypeId_HierarchicalReferences);
 	Namespace_insert(ns0,(UA_Node**)&haschild, NAMESPACE_INSERT_UNIQUE);
 
 	UA_ReferenceTypeNode *organizes;
 	UA_ReferenceTypeNode_new(&organizes);
 	organizes->nodeId = RefTypeId_Organizes;
 	organizes->nodeClass = UA_NODECLASS_REFERENCETYPE;
-	organizes->browseName = UA_QUALIFIEDNAME_STATIC("Organizes");
-	organizes->displayName = UA_LOCALIZEDTEXT_STATIC("Organizes");
-	organizes->description = UA_LOCALIZEDTEXT_STATIC("Organizes");
+	UA_QUALIFIEDNAME_STATIC(organizes->browseName, "Organizes");
+	UA_LOCALIZEDTEXT_STATIC(organizes->displayName, "Organizes");
+	UA_LOCALIZEDTEXT_STATIC(organizes->description, "Organizes");
 	organizes->isAbstract = UA_FALSE;
 	organizes->symmetric = UA_FALSE;
-	organizes->inverseName = UA_LOCALIZEDTEXT_STATIC("OrganizedBy");
-	AddReference((UA_Node*)organizes, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
-		(UA_ExpandedNodeId){RefTypeId_HierarchicalReferences, UA_STRING_NULL, 0}}, ns0);
+	UA_LOCALIZEDTEXT_STATIC(organizes->inverseName, "OrganizedBy");
+	ADDINVERSEREFERENCE(organizes, RefTypeId_HasSubtype, RefTypeId_HierarchicalReferences);
 	Namespace_insert(ns0,(UA_Node**)&organizes, NAMESPACE_INSERT_UNIQUE);
 
 	UA_ReferenceTypeNode *haseventsource;
 	UA_ReferenceTypeNode_new(&haseventsource);
 	haseventsource->nodeId = RefTypeId_HasEventSource;
 	haseventsource->nodeClass = UA_NODECLASS_REFERENCETYPE;
-	haseventsource->browseName = UA_QUALIFIEDNAME_STATIC("HasEventSource");
-	haseventsource->displayName = UA_LOCALIZEDTEXT_STATIC("HasEventSource");
-	haseventsource->description = UA_LOCALIZEDTEXT_STATIC("HasEventSource");
+	UA_QUALIFIEDNAME_STATIC(haseventsource->browseName, "HasEventSource");
+	UA_LOCALIZEDTEXT_STATIC(haseventsource->displayName, "HasEventSource");
+	UA_LOCALIZEDTEXT_STATIC(haseventsource->description, "HasEventSource");
 	haseventsource->isAbstract = UA_FALSE;
 	haseventsource->symmetric = UA_FALSE;
-	haseventsource->inverseName = UA_LOCALIZEDTEXT_STATIC("EventSourceOf");
-	AddReference((UA_Node*)haseventsource, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
-		(UA_ExpandedNodeId){RefTypeId_HierarchicalReferences, UA_STRING_NULL, 0}}, ns0);
+	UA_LOCALIZEDTEXT_STATIC(haseventsource->inverseName, "EventSourceOf");
+	ADDINVERSEREFERENCE(haseventsource, RefTypeId_HasSubtype, RefTypeId_HierarchicalReferences);
 	Namespace_insert(ns0,(UA_Node**)&haseventsource, NAMESPACE_INSERT_UNIQUE);
 
 	UA_ReferenceTypeNode *hasmodellingrule;
 	UA_ReferenceTypeNode_new(&hasmodellingrule);
 	hasmodellingrule->nodeId = RefTypeId_HasModellingRule;
 	hasmodellingrule->nodeClass = UA_NODECLASS_REFERENCETYPE;
-	hasmodellingrule->browseName = UA_QUALIFIEDNAME_STATIC("HasModellingRule");
-	hasmodellingrule->displayName = UA_LOCALIZEDTEXT_STATIC("HasModellingRule");
-	hasmodellingrule->description = UA_LOCALIZEDTEXT_STATIC("HasModellingRule");
+	UA_QUALIFIEDNAME_STATIC(hasmodellingrule->browseName, "HasModellingRule");
+	UA_LOCALIZEDTEXT_STATIC(hasmodellingrule->displayName, "HasModellingRule");
+	UA_LOCALIZEDTEXT_STATIC(hasmodellingrule->description, "HasModellingRule");
 	hasmodellingrule->isAbstract = UA_FALSE;
 	hasmodellingrule->symmetric = UA_FALSE;
-	hasmodellingrule->inverseName = UA_LOCALIZEDTEXT_STATIC("ModellingRuleOf");
-	AddReference((UA_Node*)hasmodellingrule, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
-		(UA_ExpandedNodeId){RefTypeId_NonHierarchicalReferences, UA_STRING_NULL, 0}}, ns0);
+	UA_LOCALIZEDTEXT_STATIC(hasmodellingrule->inverseName, "ModellingRuleOf");
+	ADDINVERSEREFERENCE(hasmodellingrule, RefTypeId_HasSubtype, RefTypeId_NonHierarchicalReferences);
 	Namespace_insert(ns0,(UA_Node**)&hasmodellingrule, NAMESPACE_INSERT_UNIQUE);
 
 	UA_ReferenceTypeNode *hasencoding;
 	UA_ReferenceTypeNode_new(&hasencoding);
 	hasencoding->nodeId = RefTypeId_HasEncoding;
 	hasencoding->nodeClass = UA_NODECLASS_REFERENCETYPE;
-	hasencoding->browseName = UA_QUALIFIEDNAME_STATIC("HasEncoding");
-	hasencoding->displayName = UA_LOCALIZEDTEXT_STATIC("HasEncoding");
-	hasencoding->description = UA_LOCALIZEDTEXT_STATIC("HasEncoding");
+	UA_QUALIFIEDNAME_STATIC(hasencoding->browseName, "HasEncoding");
+	UA_LOCALIZEDTEXT_STATIC(hasencoding->displayName, "HasEncoding");
+	UA_LOCALIZEDTEXT_STATIC(hasencoding->description, "HasEncoding");
 	hasencoding->isAbstract = UA_FALSE;
 	hasencoding->symmetric = UA_FALSE;
-	hasencoding->inverseName = UA_LOCALIZEDTEXT_STATIC("EncodingOf");
-	AddReference((UA_Node*)hasencoding, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
-		(UA_ExpandedNodeId){RefTypeId_NonHierarchicalReferences, UA_STRING_NULL, 0}}, ns0);
+	UA_LOCALIZEDTEXT_STATIC(hasencoding->inverseName, "EncodingOf");
+	ADDINVERSEREFERENCE(hasencoding, RefTypeId_HasSubtype, RefTypeId_NonHierarchicalReferences);
 	Namespace_insert(ns0,(UA_Node**)&hasencoding, NAMESPACE_INSERT_UNIQUE);
 
 	UA_ReferenceTypeNode *hasdescription;
 	UA_ReferenceTypeNode_new(&hasdescription);
 	hasdescription->nodeId = RefTypeId_HasDescription;
 	hasdescription->nodeClass = UA_NODECLASS_REFERENCETYPE;
-	hasdescription->browseName = UA_QUALIFIEDNAME_STATIC("HasDescription");
-	hasdescription->displayName = UA_LOCALIZEDTEXT_STATIC("HasDescription");
-	hasdescription->description = UA_LOCALIZEDTEXT_STATIC("HasDescription");
+	UA_QUALIFIEDNAME_STATIC(hasdescription->browseName, "HasDescription");
+	UA_LOCALIZEDTEXT_STATIC(hasdescription->displayName, "HasDescription");
+	UA_LOCALIZEDTEXT_STATIC(hasdescription->description, "HasDescription");
 	hasdescription->isAbstract = UA_FALSE;
 	hasdescription->symmetric = UA_FALSE;
-	hasdescription->inverseName = UA_LOCALIZEDTEXT_STATIC("DescriptionOf");
-	AddReference((UA_Node*)hasdescription, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
-		(UA_ExpandedNodeId){RefTypeId_NonHierarchicalReferences, UA_STRING_NULL, 0}}, ns0);
+	UA_LOCALIZEDTEXT_STATIC(hasdescription->inverseName, "DescriptionOf");
+	ADDINVERSEREFERENCE(hasdescription, RefTypeId_HasSubtype, RefTypeId_NonHierarchicalReferences);
 	Namespace_insert(ns0,(UA_Node**)&hasdescription, NAMESPACE_INSERT_UNIQUE);
 
 	UA_ReferenceTypeNode *hastypedefinition;
 	UA_ReferenceTypeNode_new(&hastypedefinition);
 	hastypedefinition->nodeId = RefTypeId_HasTypeDefinition;
 	hastypedefinition->nodeClass = UA_NODECLASS_REFERENCETYPE;
-	hastypedefinition->browseName = UA_QUALIFIEDNAME_STATIC("HasTypeDefinition");
-	hastypedefinition->displayName = UA_LOCALIZEDTEXT_STATIC("HasTypeDefinition");
-	hastypedefinition->description = UA_LOCALIZEDTEXT_STATIC("HasTypeDefinition");
+	UA_QUALIFIEDNAME_STATIC(hastypedefinition->browseName, "HasTypeDefinition");
+	UA_LOCALIZEDTEXT_STATIC(hastypedefinition->displayName, "HasTypeDefinition");
+	UA_LOCALIZEDTEXT_STATIC(hastypedefinition->description, "HasTypeDefinition");
 	hastypedefinition->isAbstract = UA_FALSE;
 	hastypedefinition->symmetric = UA_FALSE;
-	hastypedefinition->inverseName = UA_LOCALIZEDTEXT_STATIC("TypeDefinitionOf");
-	AddReference((UA_Node*)hastypedefinition, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
-		(UA_ExpandedNodeId){RefTypeId_NonHierarchicalReferences, UA_STRING_NULL, 0}}, ns0);
+	UA_LOCALIZEDTEXT_STATIC(hastypedefinition->inverseName, "TypeDefinitionOf");
+	ADDINVERSEREFERENCE(hastypedefinition, RefTypeId_HasSubtype, RefTypeId_NonHierarchicalReferences);
 	Namespace_insert(ns0,(UA_Node**)&hastypedefinition, NAMESPACE_INSERT_UNIQUE);
 
 	UA_ReferenceTypeNode *generatesevent;
 	UA_ReferenceTypeNode_new(&generatesevent);
 	generatesevent->nodeId = RefTypeId_GeneratesEvent;
 	generatesevent->nodeClass = UA_NODECLASS_REFERENCETYPE;
-	generatesevent->browseName = UA_QUALIFIEDNAME_STATIC("GeneratesEvent");
-	generatesevent->displayName = UA_LOCALIZEDTEXT_STATIC("GeneratesEvent");
-	generatesevent->description = UA_LOCALIZEDTEXT_STATIC("GeneratesEvent");
+	UA_QUALIFIEDNAME_STATIC(generatesevent->browseName, "GeneratesEvent");
+	UA_LOCALIZEDTEXT_STATIC(generatesevent->displayName, "GeneratesEvent");
+	UA_LOCALIZEDTEXT_STATIC(generatesevent->description, "GeneratesEvent");
 	generatesevent->isAbstract = UA_FALSE;
 	generatesevent->symmetric = UA_FALSE;
-	generatesevent->inverseName = UA_LOCALIZEDTEXT_STATIC("GeneratedBy");
-	AddReference((UA_Node*)generatesevent, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
-		(UA_ExpandedNodeId){RefTypeId_NonHierarchicalReferences, UA_STRING_NULL, 0}}, ns0);
+	UA_LOCALIZEDTEXT_STATIC(generatesevent->inverseName, "GeneratedBy");
+	ADDINVERSEREFERENCE(generatesevent, RefTypeId_HasSubtype, RefTypeId_NonHierarchicalReferences);
 	Namespace_insert(ns0,(UA_Node**)&generatesevent, NAMESPACE_INSERT_UNIQUE);
 
 	UA_ReferenceTypeNode *aggregates;
 	UA_ReferenceTypeNode_new(&aggregates);
 	aggregates->nodeId = RefTypeId_Aggregates;
 	aggregates->nodeClass = UA_NODECLASS_REFERENCETYPE;
-	aggregates->browseName = UA_QUALIFIEDNAME_STATIC("Aggregates");
-	aggregates->displayName = UA_LOCALIZEDTEXT_STATIC("Aggregates");
-	aggregates->description = UA_LOCALIZEDTEXT_STATIC("Aggregates");
+	UA_QUALIFIEDNAME_STATIC(aggregates->browseName, "Aggregates");
+	UA_LOCALIZEDTEXT_STATIC(aggregates->displayName, "Aggregates");
+	UA_LOCALIZEDTEXT_STATIC(aggregates->description, "Aggregates");
 	aggregates->isAbstract = UA_TRUE;
 	aggregates->symmetric = UA_FALSE;
-	AddReference((UA_Node*)aggregates, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
-		(UA_ExpandedNodeId){RefTypeId_HasChild, UA_STRING_NULL, 0}}, ns0);
+	ADDINVERSEREFERENCE(aggregates, RefTypeId_HasSubtype, RefTypeId_HasChild);
 	Namespace_insert(ns0,(UA_Node**)&aggregates, NAMESPACE_INSERT_UNIQUE);
 
 	UA_ReferenceTypeNode *hassubtype;
 	UA_ReferenceTypeNode_new(&hassubtype);
 	hassubtype->nodeId = RefTypeId_HasSubtype;
 	hassubtype->nodeClass = UA_NODECLASS_REFERENCETYPE;
-	hassubtype->browseName = UA_QUALIFIEDNAME_STATIC("HasSubtype");
-	hassubtype->displayName = UA_LOCALIZEDTEXT_STATIC("HasSubtype");
-	hassubtype->description = UA_LOCALIZEDTEXT_STATIC("HasSubtype");
+	UA_QUALIFIEDNAME_STATIC(hassubtype->browseName, "HasSubtype");
+	UA_LOCALIZEDTEXT_STATIC(hassubtype->displayName, "HasSubtype");
+	UA_LOCALIZEDTEXT_STATIC(hassubtype->description, "HasSubtype");
 	hassubtype->isAbstract = UA_FALSE;
 	hassubtype->symmetric = UA_FALSE;
-	hassubtype->inverseName = UA_LOCALIZEDTEXT_STATIC("SubtypeOf");
-	AddReference((UA_Node*)hassubtype, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
-		(UA_ExpandedNodeId){RefTypeId_HasChild, UA_STRING_NULL, 0}}, ns0);
+	UA_LOCALIZEDTEXT_STATIC(hassubtype->inverseName, "SubtypeOf");
+	ADDINVERSEREFERENCE(hassubtype, RefTypeId_HasSubtype, RefTypeId_HasChild);
 	Namespace_insert(ns0,(UA_Node**)&hassubtype, NAMESPACE_INSERT_UNIQUE);
 
 	UA_ReferenceTypeNode *hasproperty;
 	UA_ReferenceTypeNode_new(&hasproperty);
 	hasproperty->nodeId = RefTypeId_HasProperty;
 	hasproperty->nodeClass = UA_NODECLASS_REFERENCETYPE;
-	hasproperty->browseName = UA_QUALIFIEDNAME_STATIC("HasProperty");
-	hasproperty->displayName = UA_LOCALIZEDTEXT_STATIC("HasProperty");
-	hasproperty->description = UA_LOCALIZEDTEXT_STATIC("HasProperty");
+	UA_QUALIFIEDNAME_STATIC(hasproperty->browseName, "HasProperty");
+	UA_LOCALIZEDTEXT_STATIC(hasproperty->displayName, "HasProperty");
+	UA_LOCALIZEDTEXT_STATIC(hasproperty->description, "HasProperty");
 	hasproperty->isAbstract = UA_FALSE;
 	hasproperty->symmetric = UA_FALSE;
-	hasproperty->inverseName = UA_LOCALIZEDTEXT_STATIC("PropertyOf");
-	AddReference((UA_Node*)hasproperty, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
-		(UA_ExpandedNodeId){RefTypeId_Aggregates, UA_STRING_NULL, 0}}, ns0);
+	UA_LOCALIZEDTEXT_STATIC(hasproperty->inverseName, "PropertyOf");
+	ADDINVERSEREFERENCE(hasproperty, RefTypeId_HasSubtype, RefTypeId_Aggregates);
 	Namespace_insert(ns0,(UA_Node**)&hasproperty, NAMESPACE_INSERT_UNIQUE);
 
 	UA_ReferenceTypeNode *hascomponent;
 	UA_ReferenceTypeNode_new(&hascomponent);
 	hascomponent->nodeId = RefTypeId_HasComponent;
 	hascomponent->nodeClass = UA_NODECLASS_REFERENCETYPE;
-	hascomponent->browseName = UA_QUALIFIEDNAME_STATIC("HasComponent");
-	hascomponent->displayName = UA_LOCALIZEDTEXT_STATIC("HasComponent");
-	hascomponent->description = UA_LOCALIZEDTEXT_STATIC("HasComponent");
+	UA_QUALIFIEDNAME_STATIC(hascomponent->browseName, "HasComponent");
+	UA_LOCALIZEDTEXT_STATIC(hascomponent->displayName, "HasComponent");
+	UA_LOCALIZEDTEXT_STATIC(hascomponent->description, "HasComponent");
 	hascomponent->isAbstract = UA_FALSE;
 	hascomponent->symmetric = UA_FALSE;
-	hascomponent->inverseName = UA_LOCALIZEDTEXT_STATIC("ComponentOf");
-	AddReference((UA_Node*)hascomponent, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
-		(UA_ExpandedNodeId){RefTypeId_Aggregates, UA_STRING_NULL, 0}}, ns0);
+	UA_LOCALIZEDTEXT_STATIC(hascomponent->inverseName, "ComponentOf");
+	ADDINVERSEREFERENCE(hascomponent, RefTypeId_HasSubtype, RefTypeId_Aggregates);
 	Namespace_insert(ns0,(UA_Node**)&hascomponent, NAMESPACE_INSERT_UNIQUE);
 
 	UA_ReferenceTypeNode *hasnotifier;
 	UA_ReferenceTypeNode_new(&hasnotifier);
 	hasnotifier->nodeId = RefTypeId_HasNotifier;
 	hasnotifier->nodeClass = UA_NODECLASS_REFERENCETYPE;
-	hasnotifier->browseName = UA_QUALIFIEDNAME_STATIC("HasNotifier");
-	hasnotifier->displayName = UA_LOCALIZEDTEXT_STATIC("HasNotifier");
-	hasnotifier->description = UA_LOCALIZEDTEXT_STATIC("HasNotifier");
+	UA_QUALIFIEDNAME_STATIC(hasnotifier->browseName, "HasNotifier");
+	UA_LOCALIZEDTEXT_STATIC(hasnotifier->displayName, "HasNotifier");
+	UA_LOCALIZEDTEXT_STATIC(hasnotifier->description, "HasNotifier");
 	hasnotifier->isAbstract = UA_FALSE;
 	hasnotifier->symmetric = UA_FALSE;
-	hasnotifier->inverseName = UA_LOCALIZEDTEXT_STATIC("NotifierOf");
-	AddReference((UA_Node*)hasnotifier, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
-		(UA_ExpandedNodeId){RefTypeId_HasEventSource, UA_STRING_NULL, 0}}, ns0);
+	UA_LOCALIZEDTEXT_STATIC(hasnotifier->inverseName, "NotifierOf");
+	ADDINVERSEREFERENCE(hasnotifier, RefTypeId_HasSubtype, RefTypeId_HasEventSource);
 	Namespace_insert(ns0,(UA_Node**)&hasnotifier, NAMESPACE_INSERT_UNIQUE);
 
 	UA_ReferenceTypeNode *hasorderedcomponent;
 	UA_ReferenceTypeNode_new(&hasorderedcomponent);
 	hasorderedcomponent->nodeId = RefTypeId_HasOrderedComponent;
 	hasorderedcomponent->nodeClass = UA_NODECLASS_REFERENCETYPE;
-	hasorderedcomponent->browseName = UA_QUALIFIEDNAME_STATIC("HasOrderedComponent");
-	hasorderedcomponent->displayName = UA_LOCALIZEDTEXT_STATIC("HasOrderedComponent");
-	hasorderedcomponent->description = UA_LOCALIZEDTEXT_STATIC("HasOrderedComponent");
+	UA_QUALIFIEDNAME_STATIC(hasorderedcomponent->browseName, "HasOrderedComponent");
+	UA_LOCALIZEDTEXT_STATIC(hasorderedcomponent->displayName, "HasOrderedComponent");
+	UA_LOCALIZEDTEXT_STATIC(hasorderedcomponent->description, "HasOrderedComponent");
 	hasorderedcomponent->isAbstract = UA_FALSE;
 	hasorderedcomponent->symmetric = UA_FALSE;
-	hasorderedcomponent->inverseName = UA_LOCALIZEDTEXT_STATIC("OrderedComponentOf");
-	AddReference((UA_Node*)hasorderedcomponent, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
-		(UA_ExpandedNodeId){RefTypeId_HasComponent, UA_STRING_NULL, 0}}, ns0);
+	UA_LOCALIZEDTEXT_STATIC(hasorderedcomponent->inverseName, "OrderedComponentOf");
+	ADDINVERSEREFERENCE(hasorderedcomponent, RefTypeId_HasSubtype, RefTypeId_HasComponent);
 	Namespace_insert(ns0,(UA_Node**)&hasorderedcomponent, NAMESPACE_INSERT_UNIQUE);
 
 	UA_ReferenceTypeNode *hasmodelparent;
 	UA_ReferenceTypeNode_new(&hasmodelparent);
 	hasmodelparent->nodeId = RefTypeId_HasModelParent;
 	hasmodelparent->nodeClass = UA_NODECLASS_REFERENCETYPE;
-	hasmodelparent->browseName = UA_QUALIFIEDNAME_STATIC("HasModelParent");
-	hasmodelparent->displayName = UA_LOCALIZEDTEXT_STATIC("HasModelParent");
-	hasmodelparent->description = UA_LOCALIZEDTEXT_STATIC("HasModelParent");
+	UA_QUALIFIEDNAME_STATIC(hasmodelparent->browseName, "HasModelParent");
+	UA_LOCALIZEDTEXT_STATIC(hasmodelparent->displayName, "HasModelParent");
+	UA_LOCALIZEDTEXT_STATIC(hasmodelparent->description, "HasModelParent");
 	hasmodelparent->isAbstract = UA_FALSE;
 	hasmodelparent->symmetric = UA_FALSE;
-	hasmodelparent->inverseName = UA_LOCALIZEDTEXT_STATIC("ModelParentOf");
-	AddReference((UA_Node*)hasmodelparent, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
-		(UA_ExpandedNodeId){RefTypeId_NonHierarchicalReferences, UA_STRING_NULL, 0}}, ns0);
+	UA_LOCALIZEDTEXT_STATIC(hasmodelparent->inverseName, "ModelParentOf");
+	ADDINVERSEREFERENCE(hasmodelparent, RefTypeId_HasSubtype, RefTypeId_NonHierarchicalReferences);
 	Namespace_insert(ns0,(UA_Node**)&hasmodelparent, NAMESPACE_INSERT_UNIQUE);
 
 	UA_ReferenceTypeNode *fromstate;
 	UA_ReferenceTypeNode_new(&fromstate);
 	fromstate->nodeId = RefTypeId_FromState;
 	fromstate->nodeClass = UA_NODECLASS_REFERENCETYPE;
-	fromstate->browseName = UA_QUALIFIEDNAME_STATIC("FromState");
-	fromstate->displayName = UA_LOCALIZEDTEXT_STATIC("FromState");
-	fromstate->description = UA_LOCALIZEDTEXT_STATIC("FromState");
+	UA_QUALIFIEDNAME_STATIC(fromstate->browseName, "FromState");
+	UA_LOCALIZEDTEXT_STATIC(fromstate->displayName, "FromState");
+	UA_LOCALIZEDTEXT_STATIC(fromstate->description, "FromState");
 	fromstate->isAbstract = UA_FALSE;
 	fromstate->symmetric = UA_FALSE;
-	fromstate->inverseName = UA_LOCALIZEDTEXT_STATIC("ToTransition");
-	AddReference((UA_Node*)fromstate, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
-		(UA_ExpandedNodeId){RefTypeId_NonHierarchicalReferences, UA_STRING_NULL, 0}}, ns0);
+	UA_LOCALIZEDTEXT_STATIC(fromstate->inverseName, "ToTransition");
+	ADDINVERSEREFERENCE(fromstate, RefTypeId_HasSubtype, RefTypeId_NonHierarchicalReferences);
 	Namespace_insert(ns0,(UA_Node**)&fromstate, NAMESPACE_INSERT_UNIQUE);
 
 	UA_ReferenceTypeNode *tostate;
 	UA_ReferenceTypeNode_new(&tostate);
 	tostate->nodeId = RefTypeId_ToState;
 	tostate->nodeClass = UA_NODECLASS_REFERENCETYPE;
-	tostate->browseName = UA_QUALIFIEDNAME_STATIC("ToState");
-	tostate->displayName = UA_LOCALIZEDTEXT_STATIC("ToState");
-	tostate->description = UA_LOCALIZEDTEXT_STATIC("ToState");
+	UA_QUALIFIEDNAME_STATIC(tostate->browseName, "ToState");
+	UA_LOCALIZEDTEXT_STATIC(tostate->displayName, "ToState");
+	UA_LOCALIZEDTEXT_STATIC(tostate->description, "ToState");
 	tostate->isAbstract = UA_FALSE;
 	tostate->symmetric = UA_FALSE;
-	tostate->inverseName = UA_LOCALIZEDTEXT_STATIC("FromTransition");
-	AddReference((UA_Node*)tostate, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
-		(UA_ExpandedNodeId){RefTypeId_NonHierarchicalReferences, UA_STRING_NULL, 0}}, ns0);
+	UA_LOCALIZEDTEXT_STATIC(tostate->inverseName, "FromTransition");
+	ADDINVERSEREFERENCE(tostate, RefTypeId_HasSubtype, RefTypeId_NonHierarchicalReferences);
 	Namespace_insert(ns0,(UA_Node**)&tostate, NAMESPACE_INSERT_UNIQUE);
 
 	UA_ReferenceTypeNode *hascause;
 	UA_ReferenceTypeNode_new(&hascause);
 	hascause->nodeId = RefTypeId_HasCause;
 	hascause->nodeClass = UA_NODECLASS_REFERENCETYPE;
-	hascause->browseName = UA_QUALIFIEDNAME_STATIC("HasCause");
-	hascause->displayName = UA_LOCALIZEDTEXT_STATIC("HasCause");
-	hascause->description = UA_LOCALIZEDTEXT_STATIC("HasCause");
+	UA_QUALIFIEDNAME_STATIC(hascause->browseName, "HasCause");
+	UA_LOCALIZEDTEXT_STATIC(hascause->displayName, "HasCause");
+	UA_LOCALIZEDTEXT_STATIC(hascause->description, "HasCause");
 	hascause->isAbstract = UA_FALSE;
 	hascause->symmetric = UA_FALSE;
-	hascause->inverseName = UA_LOCALIZEDTEXT_STATIC("MayBeCausedBy");
-	AddReference((UA_Node*)hascause, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
-		(UA_ExpandedNodeId){RefTypeId_NonHierarchicalReferences, UA_STRING_NULL, 0}}, ns0);
+	UA_LOCALIZEDTEXT_STATIC(hascause->inverseName, "MayBeCausedBy");
+	ADDINVERSEREFERENCE(hascause, RefTypeId_HasSubtype, RefTypeId_NonHierarchicalReferences);
 	Namespace_insert(ns0,(UA_Node**)&hascause, NAMESPACE_INSERT_UNIQUE);
 
 	UA_ReferenceTypeNode *haseffect;
 	UA_ReferenceTypeNode_new(&haseffect);
 	haseffect->nodeId = RefTypeId_HasEffect;
 	haseffect->nodeClass = UA_NODECLASS_REFERENCETYPE;
-	haseffect->browseName = UA_QUALIFIEDNAME_STATIC("HasEffect");
-	haseffect->displayName = UA_LOCALIZEDTEXT_STATIC("HasEffect");
-	haseffect->description = UA_LOCALIZEDTEXT_STATIC("HasEffect");
+	UA_QUALIFIEDNAME_STATIC(haseffect->browseName, "HasEffect");
+	UA_LOCALIZEDTEXT_STATIC(haseffect->displayName, "HasEffect");
+	UA_LOCALIZEDTEXT_STATIC(haseffect->description, "HasEffect");
 	haseffect->isAbstract = UA_FALSE;
 	haseffect->symmetric = UA_FALSE;
-	haseffect->inverseName = UA_LOCALIZEDTEXT_STATIC("MayBeEffectedBy");
-	AddReference((UA_Node*)haseffect, &(UA_ReferenceNode){RefTypeId_HasSubtype, UA_TRUE,
-		(UA_ExpandedNodeId){RefTypeId_NonHierarchicalReferences, UA_STRING_NULL, 0}}, ns0);
+	UA_LOCALIZEDTEXT_STATIC(haseffect->inverseName, "MayBeEffectedBy");
+	ADDINVERSEREFERENCE(haseffect, RefTypeId_HasSubtype, RefTypeId_NonHierarchicalReferences);
 	Namespace_insert(ns0,(UA_Node**)&haseffect, NAMESPACE_INSERT_UNIQUE);
 
 	UA_ReferenceTypeNode *hashistoricalconfiguration;
 	UA_ReferenceTypeNode_new(&hashistoricalconfiguration);
 	hashistoricalconfiguration->nodeId = RefTypeId_HasHistoricalConfiguration;
 	hashistoricalconfiguration->nodeClass = UA_NODECLASS_REFERENCETYPE;
-	hashistoricalconfiguration->browseName = UA_QUALIFIEDNAME_STATIC("HasHistoricalConfiguration");
-	hashistoricalconfiguration->displayName = UA_LOCALIZEDTEXT_STATIC("HasHistoricalConfiguration");
-	hashistoricalconfiguration->description = UA_LOCALIZEDTEXT_STATIC("HasHistoricalConfiguration");
+	UA_QUALIFIEDNAME_STATIC(hashistoricalconfiguration->browseName, "HasHistoricalConfiguration");
+	UA_LOCALIZEDTEXT_STATIC(hashistoricalconfiguration->displayName, "HasHistoricalConfiguration");
+	UA_LOCALIZEDTEXT_STATIC(hashistoricalconfiguration->description, "HasHistoricalConfiguration");
 	hashistoricalconfiguration->isAbstract = UA_FALSE;
 	hashistoricalconfiguration->symmetric = UA_FALSE;
-	hashistoricalconfiguration->inverseName = UA_LOCALIZEDTEXT_STATIC("HistoricalConfigurationOf");
-	AddReference((UA_Node*)hashistoricalconfiguration, &(UA_ReferenceNode){RefTypeId_HasSubtype,
-		UA_TRUE, (UA_ExpandedNodeId){RefTypeId_Aggregates, UA_STRING_NULL, 0}}, ns0);
+	UA_LOCALIZEDTEXT_STATIC(hashistoricalconfiguration->inverseName, "HistoricalConfigurationOf");
+	ADDINVERSEREFERENCE(hashistoricalconfiguration, RefTypeId_HasSubtype, RefTypeId_Aggregates);
 	Namespace_insert(ns0,(UA_Node**)&hashistoricalconfiguration, NAMESPACE_INSERT_UNIQUE);
 
 
 	// ObjectTypes (Ids only)
-	UA_ExpandedNodeId ObjTypeId_FolderType = NS0EXPANDEDNODEID(61);
+	UA_ExpandedNodeId ObjTypeId_FolderType; NS0EXPANDEDNODEID(ObjTypeId_FolderType, 61);
 
 	// Objects (Ids only)
-	UA_ExpandedNodeId ObjId_ObjectsFolder = NS0EXPANDEDNODEID(85);
-	UA_ExpandedNodeId ObjId_TypesFolder = NS0EXPANDEDNODEID(86);
-	UA_ExpandedNodeId ObjId_ViewsFolder = NS0EXPANDEDNODEID(87);
-	UA_ExpandedNodeId ObjId_Server = NS0EXPANDEDNODEID(2253);
-	UA_ExpandedNodeId ObjId_ServerArray = NS0EXPANDEDNODEID(2254);
-	UA_ExpandedNodeId ObjId_NamespaceArray = NS0EXPANDEDNODEID(2255);
-	UA_ExpandedNodeId ObjId_ServerStatus = NS0EXPANDEDNODEID(2256);
-	UA_ExpandedNodeId ObjId_ServerCapabilities = NS0EXPANDEDNODEID(2268);
-	UA_ExpandedNodeId ObjId_State = NS0EXPANDEDNODEID(2259);
+	UA_ExpandedNodeId ObjId_ObjectsFolder; NS0EXPANDEDNODEID(ObjId_ObjectsFolder, 85);
+	UA_ExpandedNodeId ObjId_TypesFolder; NS0EXPANDEDNODEID(ObjId_TypesFolder, 86);
+	UA_ExpandedNodeId ObjId_ViewsFolder; NS0EXPANDEDNODEID(ObjId_ViewsFolder, 87);
+	UA_ExpandedNodeId ObjId_Server; NS0EXPANDEDNODEID(ObjId_Server, 2253);
+	UA_ExpandedNodeId ObjId_ServerArray; NS0EXPANDEDNODEID(ObjId_ServerArray, 2254);
+	UA_ExpandedNodeId ObjId_NamespaceArray; NS0EXPANDEDNODEID(ObjId_NamespaceArray, 2255);
+	UA_ExpandedNodeId ObjId_ServerStatus; NS0EXPANDEDNODEID(ObjId_ServerStatus, 2256);
+	UA_ExpandedNodeId ObjId_ServerCapabilities; NS0EXPANDEDNODEID(ObjId_ServerCapabilities, 2268);
+	UA_ExpandedNodeId ObjId_State; NS0EXPANDEDNODEID(ObjId_State, 2259);
 
 	// FolderType
 	UA_ObjectNode *folderType;
 	UA_ObjectNode_new(&folderType);
 	folderType->nodeId = NS0NODEID(61);
 	folderType->nodeClass = UA_NODECLASS_OBJECTTYPE; // I should not have to set this manually
-	folderType->browseName = UA_QUALIFIEDNAME_STATIC("FolderType");
-	folderType->displayName = UA_LOCALIZEDTEXT_STATIC("FolderType");
-	folderType->description = UA_LOCALIZEDTEXT_STATIC("FolderType");
+	UA_QUALIFIEDNAME_STATIC(folderType->browseName, "FolderType");
+	UA_LOCALIZEDTEXT_STATIC(folderType->displayName, "FolderType");
+	UA_LOCALIZEDTEXT_STATIC(folderType->description, "FolderType");
 	Namespace_insert(ns0,(UA_Node**)&folderType, NAMESPACE_INSERT_UNIQUE);
 
+#define ADDREFERENCE(NODE, REFTYPE, INVERSE, TARGET_NODEID) \
+	static struct UA_ReferenceNode NODE##REFTYPE##TARGET_NODEID; \
+	UA_ReferenceNode_init(&NODE##REFTYPE##TARGET_NODEID); \
+	NODE##REFTYPE##TARGET_NODEID.referenceTypeId = REFTYPE; \
+	NODE##REFTYPE##TARGET_NODEID.isInverse = INVERSE; \
+	NODE##REFTYPE##TARGET_NODEID.targetId = TARGET_NODEID; \
+	AddReference((UA_Node*)NODE, &NODE##REFTYPE##TARGET_NODEID, ns0)
+
 	// Root
 	UA_ObjectNode *root;
 	UA_ObjectNode_new(&root);
 	root->nodeId = NS0NODEID(84);
 	root->nodeClass = UA_NODECLASS_OBJECT; // I should not have to set this manually
-	root->browseName = UA_QUALIFIEDNAME_STATIC("Root");
-	root->displayName = UA_LOCALIZEDTEXT_STATIC("Root");
-	root->description = UA_LOCALIZEDTEXT_STATIC("Root");
-	AddReference((UA_Node*)root, &(UA_ReferenceNode){RefTypeId_HasTypeDefinition, UA_FALSE, ObjTypeId_FolderType}, ns0);
-	AddReference((UA_Node*)root, &(UA_ReferenceNode){RefTypeId_Organizes, UA_FALSE, ObjId_ObjectsFolder}, ns0);
-	AddReference((UA_Node*)root, &(UA_ReferenceNode){RefTypeId_Organizes, UA_FALSE, ObjId_TypesFolder}, ns0);
-	AddReference((UA_Node*)root, &(UA_ReferenceNode){RefTypeId_Organizes, UA_FALSE, ObjId_ViewsFolder}, ns0);
+	UA_QUALIFIEDNAME_STATIC(root->browseName, "Root");
+	UA_LOCALIZEDTEXT_STATIC(root->displayName, "Root");
+	UA_LOCALIZEDTEXT_STATIC(root->description, "Root");
+	ADDREFERENCE(root, RefTypeId_HasTypeDefinition, UA_FALSE, ObjTypeId_FolderType);
+	ADDREFERENCE(root, RefTypeId_Organizes, UA_FALSE, ObjId_ObjectsFolder);
+	ADDREFERENCE(root, RefTypeId_Organizes, UA_FALSE, ObjId_TypesFolder);
+	ADDREFERENCE(root, RefTypeId_Organizes, UA_FALSE, ObjId_ViewsFolder);
 	/* root becomes a managed node. we need to release it at the end.*/
 	Namespace_insert(ns0,(UA_Node**)&root, NAMESPACE_INSERT_UNIQUE | NAMESPACE_INSERT_GETMANAGED);
 
@@ -433,11 +429,11 @@ void appMockup_init() {
 	UA_ObjectNode_new(&objects);
 	objects->nodeId = ObjId_ObjectsFolder.nodeId;
 	objects->nodeClass = UA_NODECLASS_OBJECT;
-	objects->browseName = UA_QUALIFIEDNAME_STATIC("Objects");
-	objects->displayName = UA_LOCALIZEDTEXT_STATIC("Objects");
-	objects->description = UA_LOCALIZEDTEXT_STATIC("Objects");
-	AddReference((UA_Node*)objects, &(UA_ReferenceNode){RefTypeId_HasTypeDefinition, UA_FALSE, ObjTypeId_FolderType}, ns0);
-	AddReference((UA_Node*)objects, &(UA_ReferenceNode){RefTypeId_Organizes, UA_FALSE, ObjId_Server}, ns0);
+	UA_QUALIFIEDNAME_STATIC(objects->browseName, "Objects");
+	UA_LOCALIZEDTEXT_STATIC(objects->displayName, "Objects");
+	UA_LOCALIZEDTEXT_STATIC(objects->description, "Objects");
+	ADDREFERENCE(objects, RefTypeId_HasTypeDefinition, UA_FALSE, ObjTypeId_FolderType);
+	ADDREFERENCE(objects, RefTypeId_Organizes, UA_FALSE, ObjId_Server);
 	Namespace_insert(ns0,(UA_Node**)&objects, NAMESPACE_INSERT_UNIQUE);
 
 	// Types
@@ -445,10 +441,10 @@ void appMockup_init() {
 	UA_ObjectNode_new(&types);
 	types->nodeId = ObjId_TypesFolder.nodeId;
 	types->nodeClass = UA_NODECLASS_OBJECT;
-	types->browseName = UA_QUALIFIEDNAME_STATIC("Types");
-	types->displayName = UA_LOCALIZEDTEXT_STATIC("Types");
-	types->description = UA_LOCALIZEDTEXT_STATIC("Types");
-	AddReference((UA_Node*)types, &(UA_ReferenceNode){RefTypeId_HasTypeDefinition, UA_FALSE, ObjTypeId_FolderType}, ns0);
+	UA_QUALIFIEDNAME_STATIC(types->browseName, "Types");
+	UA_LOCALIZEDTEXT_STATIC(types->displayName, "Types");
+	UA_LOCALIZEDTEXT_STATIC(types->description, "Types");
+	ADDREFERENCE(types, RefTypeId_HasTypeDefinition, UA_FALSE, ObjTypeId_FolderType);
 	Namespace_insert(ns0,(UA_Node**)&types, NAMESPACE_INSERT_UNIQUE);
 
 	// Views
@@ -456,10 +452,10 @@ void appMockup_init() {
 	UA_ObjectNode_new(&views);
 	views->nodeId = ObjId_ViewsFolder.nodeId;
 	views->nodeClass = UA_NODECLASS_OBJECT;
-	views->browseName = UA_QUALIFIEDNAME_STATIC("Views");
-	views->displayName = UA_LOCALIZEDTEXT_STATIC("Views");
-	views->description = UA_LOCALIZEDTEXT_STATIC("Views");
-	AddReference((UA_Node*)views, &(UA_ReferenceNode){RefTypeId_HasTypeDefinition, UA_FALSE, ObjTypeId_FolderType}, ns0);
+	UA_QUALIFIEDNAME_STATIC(views->browseName, "Views");
+	UA_LOCALIZEDTEXT_STATIC(views->displayName, "Views");
+	UA_LOCALIZEDTEXT_STATIC(views->description, "Views");
+	ADDREFERENCE(views, RefTypeId_HasTypeDefinition, UA_FALSE, ObjTypeId_FolderType);
 	Namespace_insert(ns0,(UA_Node**)&views, NAMESPACE_INSERT_UNIQUE);
 
 	// Server
@@ -467,13 +463,13 @@ void appMockup_init() {
 	UA_ObjectNode_new(&server);
 	server->nodeId = ObjId_Server.nodeId;
 	server->nodeClass = UA_NODECLASS_OBJECT;
-	server->browseName = UA_QUALIFIEDNAME_STATIC("Server");
-	server->displayName = UA_LOCALIZEDTEXT_STATIC("Server");
-	server->description = UA_LOCALIZEDTEXT_STATIC("Server");
-	AddReference((UA_Node*)server, &(UA_ReferenceNode){RefTypeId_HasComponent, UA_FALSE, ObjId_ServerCapabilities}, ns0);
-	AddReference((UA_Node*)server, &(UA_ReferenceNode){RefTypeId_HasComponent, UA_FALSE, ObjId_NamespaceArray}, ns0);
-	AddReference((UA_Node*)server, &(UA_ReferenceNode){RefTypeId_HasProperty, UA_FALSE, ObjId_ServerStatus}, ns0);
-	AddReference((UA_Node*)server, &(UA_ReferenceNode){RefTypeId_HasProperty, UA_FALSE, ObjId_ServerArray}, ns0);
+	UA_QUALIFIEDNAME_STATIC(server->browseName, "Server");
+	UA_LOCALIZEDTEXT_STATIC(server->displayName, "Server");
+	UA_LOCALIZEDTEXT_STATIC(server->description, "Server");
+	ADDREFERENCE(server, RefTypeId_HasComponent, UA_FALSE, ObjId_ServerCapabilities);
+	ADDREFERENCE(server, RefTypeId_HasComponent, UA_FALSE, ObjId_NamespaceArray);
+	ADDREFERENCE(server, RefTypeId_HasProperty, UA_FALSE, ObjId_ServerStatus);
+	ADDREFERENCE(server, RefTypeId_HasProperty, UA_FALSE, ObjId_ServerArray);
 	Namespace_insert(ns0,(UA_Node**)&server, NAMESPACE_INSERT_UNIQUE);
 
 	// NamespaceArray
@@ -481,9 +477,9 @@ void appMockup_init() {
 	UA_VariableNode_new(&namespaceArray);
 	namespaceArray->nodeId = ObjId_NamespaceArray.nodeId;
 	namespaceArray->nodeClass = UA_NODECLASS_VARIABLE; //FIXME: this should go into _new?
-	namespaceArray->browseName = UA_QUALIFIEDNAME_STATIC("NamespaceArray");
-	namespaceArray->displayName = UA_LOCALIZEDTEXT_STATIC("NamespaceArray");
-	namespaceArray->description = UA_LOCALIZEDTEXT_STATIC("NamespaceArray");
+	UA_QUALIFIEDNAME_STATIC(namespaceArray->browseName, "NamespaceArray");
+	UA_LOCALIZEDTEXT_STATIC(namespaceArray->displayName, "NamespaceArray");
+	UA_LOCALIZEDTEXT_STATIC(namespaceArray->description, "NamespaceArray");
 	UA_Array_new((void**)&namespaceArray->value.data, 2, &UA_.types[UA_STRING]);
 	namespaceArray->value.vt = &UA_.types[UA_STRING];
 	namespaceArray->value.arrayLength = 2;
@@ -505,23 +501,22 @@ void appMockup_init() {
 	UA_VariableNode_new(&serverstatus);
 	serverstatus->nodeId = ObjId_ServerStatus.nodeId;
 	serverstatus->nodeClass = UA_NODECLASS_VARIABLE;
-	serverstatus->browseName = UA_QUALIFIEDNAME_STATIC("ServerStatus");
-	serverstatus->displayName = UA_LOCALIZEDTEXT_STATIC("ServerStatus");
-	serverstatus->description = UA_LOCALIZEDTEXT_STATIC("ServerStatus");
+	UA_QUALIFIEDNAME_STATIC(serverstatus->browseName, "ServerStatus");
+	UA_LOCALIZEDTEXT_STATIC(serverstatus->displayName, "ServerStatus");
+	UA_LOCALIZEDTEXT_STATIC(serverstatus->description, "ServerStatus");
 	UA_ServerStatusDataType *status;
 	UA_ServerStatusDataType_new(&status);
 	status->startTime = UA_DateTime_now();
 	status->currentTime = UA_DateTime_now();
 	status->state = UA_SERVERSTATE_RUNNING;
-	status->buildInfo = (UA_BuildInfo){
-		.productUri = UA_STRING_STATIC("open62541.org"),
-				.manufacturerName = UA_STRING_STATIC("open62541"),
-				.productName = UA_STRING_STATIC("open62541"),
-				.softwareVersion = UA_STRING_STATIC("0.0"),
-				.buildNumber = UA_STRING_STATIC("0.0"),
-				.buildDate = UA_DateTime_now()};
+	UA_STRING_STATIC(status->buildInfo.productUri, "open62541.org");
+	UA_STRING_STATIC(status->buildInfo.manufacturerName, "open62541");
+	UA_STRING_STATIC(status->buildInfo.productName, "open62541");
+	UA_STRING_STATIC(status->buildInfo.softwareVersion, "0.0");
+	UA_STRING_STATIC(status->buildInfo.buildNumber, "0.0");
+	status->buildInfo.buildDate = UA_DateTime_now();
 	status->secondsTillShutdown = 99999999;
-	status->shutdownReason = UA_LOCALIZEDTEXT_STATIC("because");
+	UA_LOCALIZEDTEXT_STATIC(status->shutdownReason, "because");
 	serverstatus->value.vt = &UA_.types[UA_SERVERSTATUSDATATYPE]; // gets encoded as an extensionobject
 	serverstatus->value.arrayLength = 1;
 	serverstatus->value.data = status;
@@ -532,9 +527,9 @@ void appMockup_init() {
 	UA_VariableNode_new(&state);
 	state->nodeId = ObjId_State.nodeId;
 	state->nodeClass = UA_NODECLASS_VARIABLE;
-	state->browseName = UA_QUALIFIEDNAME_STATIC("State");
-	state->displayName = UA_LOCALIZEDTEXT_STATIC("State");
-	state->description = UA_LOCALIZEDTEXT_STATIC("State");
+	UA_QUALIFIEDNAME_STATIC(state->browseName, "State");
+	UA_LOCALIZEDTEXT_STATIC(state->displayName, "State");
+	UA_LOCALIZEDTEXT_STATIC(state->description, "State");
 	state->value.vt = &UA_borrowed_.types[UA_SERVERSTATE];
 	state->value.arrayLength = 1;
 	state->value.data = &status->state; // points into the other object.
@@ -559,82 +554,6 @@ void appMockup_init() {
 	/*******************/
 	/* Namespace local */
 	/*******************/
-
-	// WORKS
-	UA_ExpandedNodeId ObjId_temperature1 = (UA_ExpandedNodeId){.nodeId = (UA_NodeId){.encodingByte = UA_NODEIDTYPE_TWOBYTE, .namespace = 0, .identifier.numeric = 108}, .namespaceUri = {-1, ((void *)0)}, .serverIndex = 0};
-
-	// temperature sensor
-	UA_VariableNode *temperature1;
-	UA_VariableNode_new(&temperature1);
-	temperature1->nodeId = ObjId_temperature1.nodeId;
-	temperature1->nodeClass = UA_NODECLASS_VARIABLE;
-	temperature1->browseName = UA_QUALIFIEDNAME_STATIC("temperature1");
-	temperature1->displayName = UA_LOCALIZEDTEXT_STATIC("temperature1");
-	temperature1->description = UA_LOCALIZEDTEXT_STATIC("temperature1");
-
-	//Set node value
-	UA_Variant *tmpNodeValue = &temperature1->value;
-	UA_Variant_init(tmpNodeValue);
-	UA_Float *tmpFloat;
-	UA_Float_new(&tmpFloat);
-	*tmpFloat = -273.15f;
-	tmpNodeValue->arrayDimensionsLength = 0;
-	tmpNodeValue->arrayLength = 1;
-	tmpNodeValue->data = (void*)tmpFloat;
-	tmpNodeValue->vt = &UA_.types[UA_FLOAT];
-
-	AddReference((UA_Node*)root, &(UA_ReferenceNode){RefTypeId_Organizes, UA_FALSE, ObjId_temperature1}, ns0);
-	Namespace_insert(ns0,(UA_Node**)&temperature1, NAMESPACE_INSERT_UNIQUE);
-
-
-	UA_ExpandedNodeId ObjId_redLED = (UA_ExpandedNodeId){.nodeId = (UA_NodeId){.encodingByte = UA_NODEIDTYPE_TWOBYTE, .namespace = 0, .identifier.numeric = 109}, .namespaceUri = {-1, ((void *)0)}, .serverIndex = 0};
-	// redLED sensor
-	UA_VariableNode *redLED;
-	UA_VariableNode_new(&redLED);
-	redLED->nodeId = ObjId_redLED.nodeId;
-	redLED->nodeClass = UA_NODECLASS_VARIABLE;
-	redLED->browseName = UA_QUALIFIEDNAME_STATIC("redLED");
-	redLED->displayName = UA_LOCALIZEDTEXT_STATIC("redLED");
-	redLED->description = UA_LOCALIZEDTEXT_STATIC("redLED");
-
-	//Set node value
-	UA_Variant *tmpNodeValue1 = &redLED->value;
-	UA_Variant_init(tmpNodeValue1);
-	UA_Boolean *ledVal;
-	UA_Boolean_new(&ledVal);
-	*ledVal = UA_FALSE;
-	tmpNodeValue1->arrayDimensionsLength = 0;
-	tmpNodeValue1->arrayLength = 1;
-	tmpNodeValue1->data = (void*)ledVal;
-	tmpNodeValue1->vt = &UA_.types[UA_BOOLEAN];
-
-	AddReference((UA_Node*)root, &(UA_ReferenceNode){RefTypeId_Organizes, UA_FALSE, ObjId_redLED}, ns0);
-	Namespace_insert(ns0,(UA_Node**)&redLED, NAMESPACE_INSERT_UNIQUE);
-
-
-	UA_ExpandedNodeId ObjId_yellowLED = (UA_ExpandedNodeId){.nodeId = (UA_NodeId){.encodingByte = UA_NODEIDTYPE_TWOBYTE, .namespace = 0, .identifier.numeric = 110}, .namespaceUri = {-1, ((void *)0)}, .serverIndex = 0};
-	// yellowLED sensor
-	UA_VariableNode *yellowLED;
-	UA_VariableNode_new(&yellowLED);
-	yellowLED->nodeId = ObjId_yellowLED.nodeId;
-	yellowLED->nodeClass = UA_NODECLASS_VARIABLE;
-	yellowLED->browseName = UA_QUALIFIEDNAME_STATIC("yellowLED");
-	yellowLED->displayName = UA_LOCALIZEDTEXT_STATIC("yellowLED");
-	yellowLED->description = UA_LOCALIZEDTEXT_STATIC("yellowLED");
-
-	//Set node value
-	UA_Variant *tmpNodeValue2 = &yellowLED->value;
-	UA_Variant_init(tmpNodeValue2);
-	UA_Boolean *ledVal1;
-	UA_Boolean_new(&ledVal1);
-	*ledVal1 = UA_FALSE;
-	tmpNodeValue2->arrayDimensionsLength = 0;
-	tmpNodeValue2->arrayLength = 1;
-	tmpNodeValue2->data = (void*)ledVal1;
-	tmpNodeValue2->vt = &UA_.types[UA_BOOLEAN];
-
-	AddReference((UA_Node*)root, &(UA_ReferenceNode){RefTypeId_Organizes, UA_FALSE, ObjId_yellowLED}, ns0);
-	Namespace_insert(ns0,(UA_Node**)&yellowLED, NAMESPACE_INSERT_UNIQUE);
 	
 	Namespace_releaseManagedNode((const UA_Node*)root);
 

+ 7 - 0
src/ua_config.h.in

@@ -1,2 +1,9 @@
 /* Definitions to be set by cmake. */
 #define UA_ENCODING_AMOUNT @UA_ENCODING_AMOUNT@
+#cmakedefine MSVC
+
+#ifndef MSVC
+#define INLINE inline
+#else
+#define INLINE __inline
+#endif

+ 20 - 14
src/ua_namespace.c

@@ -21,10 +21,10 @@ static hash_t const primes[] = {
 	134217689, 268435399, 536870909, 1073741789, 2147483647, 4294967291
 };
 
-static inline hash_t mod(hash_t h, hash_t size) { return h % size; }
-static inline hash_t mod2(hash_t h, hash_t size) { return 1 + (h % (size - 2)); }
+static INLINE hash_t mod(hash_t h, hash_t size) { return h % size; }
+static INLINE hash_t mod2(hash_t h, hash_t size) { return 1 + (h % (size - 2)); }
 
-static inline UA_Int16 higher_prime_index(hash_t n) {
+static INLINE UA_Int16 higher_prime_index(hash_t n) {
 	UA_UInt16 low  = 0;
 	UA_UInt16 high = sizeof(primes) / sizeof(hash_t);
 	while(low != high) {
@@ -38,7 +38,10 @@ static inline UA_Int16 higher_prime_index(hash_t n) {
 }
 
 /* Based on Murmur-Hash 3 by Austin Appleby (public domain, freely usable) */
-static inline hash_t hash_array(const UA_Byte *data, UA_UInt32 len) {
+static INLINE hash_t hash_array(const UA_Byte *data, UA_UInt32 len) {
+	const int32_t nblocks = len / 4;
+	const uint32_t *blocks;
+
 	static const uint32_t c1 = 0xcc9e2d51;
 	static const uint32_t c2 = 0x1b873593;
 	static const uint32_t r1 = 15;
@@ -47,10 +50,10 @@ static inline hash_t hash_array(const UA_Byte *data, UA_UInt32 len) {
 	static const uint32_t n  = 0xe6546b64;
 	hash_t hash = len;
 
-	if(data == UA_NULL) return 0;
+	if(data == UA_NULL)
+		return 0;
 
-	const int32_t   nblocks = len / 4;
-	const uint32_t *blocks  = (const uint32_t *)data;
+	blocks  = (const uint32_t *)data;
 	for(int32_t i = 0;i < nblocks;i++) {
 		uint32_t k = blocks[i];
 		k    *= c1;
@@ -86,7 +89,7 @@ static inline hash_t hash_array(const UA_Byte *data, UA_UInt32 len) {
 	return hash;
 }
 
-static inline hash_t hash(const UA_NodeId *n) {
+static INLINE hash_t hash(const UA_NodeId *n) {
 	switch(n->encodingByte) {
 	case UA_NODEIDTYPE_TWOBYTE:
 	case UA_NODEIDTYPE_FOURBYTE:
@@ -104,11 +107,12 @@ static inline hash_t hash(const UA_NodeId *n) {
 	}
 }
 
-static inline void clear_entry(Namespace * ns, const UA_Node ** entry) {
+static INLINE void clear_entry(Namespace * ns, const UA_Node ** entry) {
+	const UA_Node *node;
 	if(entry == UA_NULL || *entry == UA_NULL)
 		return;
 
-	const UA_Node *node = *entry;
+	node = *entry;
 	switch (node->nodeClass) {
 	case UA_NODECLASS_OBJECT:
 		UA_ObjectNode_delete((UA_ObjectNode *) node);
@@ -143,7 +147,7 @@ static inline void clear_entry(Namespace * ns, const UA_Node ** entry) {
 
 /* Returns UA_SUCCESS if an entry was found. Otherwise, UA_ERROR is returned and the "entry"
    argument points to the first free entry under the NodeId. */
-static inline UA_Int32 find_entry(const Namespace * ns, const UA_NodeId * nodeid, const UA_Node *** entry) {
+static INLINE UA_Int32 find_entry(const Namespace * ns, const UA_NodeId * nodeid, const UA_Node *** entry) {
 	hash_t h = hash(nodeid);
 	UA_UInt32 size = ns->size;
 	hash_t index = mod(h, size);
@@ -232,11 +236,12 @@ static UA_Int32 expand(Namespace * ns) {
 
 UA_Int32 Namespace_new(Namespace ** result, UA_UInt32 namespaceId) {
 	Namespace *ns;
+	UA_UInt32 sizePrimeIndex, size;
 	if(UA_alloc((void **)&ns, sizeof(Namespace)) != UA_SUCCESS)
 		return UA_ERR_NO_MEMORY;
 
-	UA_UInt32 sizePrimeIndex = higher_prime_index(32);
-	UA_UInt32 size = primes[sizePrimeIndex];
+	sizePrimeIndex = higher_prime_index(32);
+	size = primes[sizePrimeIndex];
 	if(UA_alloc((void **)&ns->entries, sizeof(UA_Node *) * size) != UA_SUCCESS) {
 		UA_free(ns);
 		return UA_ERR_NO_MEMORY;
@@ -294,9 +299,10 @@ UA_Int32 Namespace_insert(Namespace *ns, UA_Node **node, UA_Byte flags) {
 }
 
 UA_Int32 Namespace_get(const Namespace *ns, const UA_NodeId *nodeid, const UA_Node **managedNode) {
+	const UA_Node **entry;
 	if(ns == UA_NULL || nodeid == UA_NULL || managedNode == UA_NULL)
 		return UA_ERROR;
-	const UA_Node **entry;
+
 	if(find_entry(ns, nodeid, &entry) != UA_SUCCESS)
 		return UA_ERROR;
 

+ 4 - 3
src/ua_services_attribute.c

@@ -226,15 +226,16 @@ static UA_DataValue service_read_node(Application *app, const UA_ReadValueId *id
 UA_Int32 Service_Read(UA_Session session, const UA_ReadRequest *request,
                       UA_ReadResponse *response) {
 	Application *application = UA_NULL;
+	UA_Int32 readsize;
 	if(session == UA_NULL)
-	{
 		return UA_ERROR;
-	}
+
 	UA_Session_getApplicationPointer(session,&application);
+
 	if( application == UA_NULL)
 		return UA_ERROR;    // TODO: Return error message
 
-	UA_Int32 readsize = request->nodesToReadSize;
+	readsize = request->nodesToReadSize;
 	/* NothingTodo */
 	if(readsize <= 0) {
 		response->responseHeader.serviceResult = UA_STATUSCODE_BADNOTHINGTODO;

+ 8 - 6
src/ua_services_nodemanagement.c

@@ -95,13 +95,13 @@ UA_Int32 Service_AddNodes(UA_Session session, const UA_AddNodesRequest *request,
 
 static UA_Int32 AddSingleReference(UA_Node *node, UA_ReferenceNode *reference) {
 	// TODO: Check if reference already exists
-
+	UA_Int32 retval;
 	UA_Int32 count = node->referencesSize;
-	if(count < 0) count = 0;
 	UA_ReferenceNode *old_refs = node->references;
 	UA_ReferenceNode *new_refs;
+	if(count < 0) count = 0; 
 
-	UA_Int32 retval = UA_alloc((void **)&new_refs, sizeof(UA_ReferenceNode)*(count+1));
+	retval = UA_alloc((void **)&new_refs, sizeof(UA_ReferenceNode)*(count+1));
 	if(retval != UA_SUCCESS)
 		return UA_ERROR;
 	UA_memcpy(new_refs, old_refs, sizeof(UA_ReferenceNode)*count);
@@ -120,18 +120,20 @@ static UA_Int32 AddSingleReference(UA_Node *node, UA_ReferenceNode *reference) {
 
 UA_Int32 AddReference(UA_Node *node, UA_ReferenceNode *reference, Namespace *targetns) {
 	UA_Int32 retval = AddSingleReference(node, reference);
+	UA_Node *targetnode;
+	UA_ReferenceNode inversereference;
 	if(retval != UA_SUCCESS || targetns == UA_NULL)
 		return retval;
 
-	UA_Node *targetnode;
 	// Do a copy every time?
 	if(Namespace_get(targetns, &reference->targetId.nodeId, (const UA_Node**)&targetnode) != UA_SUCCESS)
 		return UA_ERROR;
 
-	UA_ReferenceNode inversereference;
 	inversereference.referenceTypeId = reference->referenceTypeId;
 	inversereference.isInverse = !reference->isInverse;
-	inversereference.targetId = (UA_ExpandedNodeId){node->nodeId, UA_STRING_NULL, 0};	
+	inversereference.targetId.nodeId = node->nodeId;
+	inversereference.targetId.namespaceUri = UA_STRING_NULL;
+	inversereference.targetId.serverIndex = 0;
 	retval = AddSingleReference(targetnode, &inversereference);
 	Namespace_releaseManagedNode(targetnode);
 

+ 5 - 4
src/ua_services_view.c

@@ -84,6 +84,7 @@ UA_UInt32 walkReferenceTree(Namespace *ns, const UA_ReferenceTypeNode *current,
 /* We do not search across namespaces so far. The id of the father-referencetype is returned in the array also. */
 static UA_Int32 findSubReferenceTypes(Namespace *ns, UA_NodeId *rootReferenceType, UA_NodeId **ids, UA_UInt32 *idcount) {
 	struct SubRefTypeIdList list;
+	UA_UInt32 count;
 	UA_SLIST_INIT(&list);
 
 	// walk the tree
@@ -91,7 +92,7 @@ static UA_Int32 findSubReferenceTypes(Namespace *ns, UA_NodeId *rootReferenceTyp
 	if(Namespace_get(ns, rootReferenceType, (const UA_Node**)&root) != UA_SUCCESS ||
 	   root->nodeClass != UA_NODECLASS_REFERENCETYPE)
 		return UA_ERROR;
-	UA_UInt32 count = walkReferenceTree(ns, root, &list);
+	count = walkReferenceTree(ns, root, &list);
 	Namespace_releaseManagedNode((const UA_Node*) root);
 
 	// copy results into an array
@@ -108,7 +109,7 @@ static UA_Int32 findSubReferenceTypes(Namespace *ns, UA_NodeId *rootReferenceTyp
 }
 
 /* is this a relevant reference? */
-static inline UA_Boolean Service_Browse_returnReference(UA_BrowseDescription *browseDescription, UA_ReferenceNode* reference,
+static INLINE UA_Boolean Service_Browse_returnReference(UA_BrowseDescription *browseDescription, UA_ReferenceNode* reference,
 														UA_NodeId *relevantRefTypes, UA_UInt32 relevantRefTypesCount) {
 	if (reference->isInverse == UA_TRUE && browseDescription->browseDirection == UA_BROWSEDIRECTION_FORWARD)
 		return UA_FALSE;
@@ -125,6 +126,8 @@ static inline UA_Boolean Service_Browse_returnReference(UA_BrowseDescription *br
 static void Service_Browse_getBrowseResult(Namespace *ns, UA_BrowseDescription *browseDescription,
 										   UA_UInt32 maxReferences, UA_BrowseResult *browseResult) {
 	const UA_Node* node;
+	UA_NodeId *relevantReferenceTypes;
+	UA_UInt32 relevantReferenceTypesCount = 0;
 	if(Namespace_get(ns, &browseDescription->nodeId, &node) != UA_SUCCESS) {
 		browseResult->statusCode = UA_STATUSCODE_BADNODEIDUNKNOWN;
 		return;
@@ -135,8 +138,6 @@ static void Service_Browse_getBrowseResult(Namespace *ns, UA_BrowseDescription *
 		maxReferences = node->referencesSize;
 
 	// discover the relevant subtypes
-	UA_NodeId *relevantReferenceTypes;
-	UA_UInt32 relevantReferenceTypesCount=0;
 	if(!browseDescription->includeSubtypes ||
 	   findSubReferenceTypes(ns, &browseDescription->referenceTypeId, &relevantReferenceTypes, &relevantReferenceTypesCount) != UA_SUCCESS) {
 		UA_alloc((void**)&relevantReferenceTypes, sizeof(UA_NodeId));

+ 19 - 18
src/ua_transport.c

@@ -84,8 +84,9 @@ UA_Int32 UA_OPCUATcpMessageHeader_init(UA_OPCUATcpMessageHeader *p) {
 
 UA_TYPE_NEW_DEFAULT(UA_OPCUATcpMessageHeader)
 UA_Int32 UA_OPCUATcpMessageHeader_copy(const UA_OPCUATcpMessageHeader *src,UA_OPCUATcpMessageHeader *dst) {
-    	if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
-    	UA_Int32 retval = UA_SUCCESS;
+	UA_Int32 retval = UA_SUCCESS;
+    if(src == UA_NULL || dst == UA_NULL)
+		return UA_ERROR;
 	memcpy(dst, src, sizeof(UA_OPCUATcpMessageHeader));
 	return retval;
 }
@@ -151,8 +152,8 @@ UA_Int32 UA_OPCUATcpHelloMessage_init(UA_OPCUATcpHelloMessage *p) {
 
 UA_TYPE_NEW_DEFAULT(UA_OPCUATcpHelloMessage)
 UA_Int32 UA_OPCUATcpHelloMessage_copy(const UA_OPCUATcpHelloMessage *src,UA_OPCUATcpHelloMessage *dst) {
-    	if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
-    	UA_Int32 retval = UA_SUCCESS;
+	UA_Int32 retval = UA_SUCCESS;
+    if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
 	memcpy(dst, src, sizeof(UA_OPCUATcpHelloMessage));
 	retval |= UA_String_copy(&src->endpointUrl,&dst->endpointUrl);
 	return retval;
@@ -214,8 +215,8 @@ UA_Int32 UA_OPCUATcpAcknowledgeMessage_init(UA_OPCUATcpAcknowledgeMessage *p) {
 
 UA_TYPE_NEW_DEFAULT(UA_OPCUATcpAcknowledgeMessage)
 UA_Int32 UA_OPCUATcpAcknowledgeMessage_copy(const UA_OPCUATcpAcknowledgeMessage *src,UA_OPCUATcpAcknowledgeMessage *dst) {
-    	if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
-    	UA_Int32 retval = UA_SUCCESS;
+	UA_Int32 retval = UA_SUCCESS;
+    if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
 	memcpy(dst, src, sizeof(UA_OPCUATcpAcknowledgeMessage));
 	return retval;
 }
@@ -264,8 +265,8 @@ UA_Int32 UA_SecureConversationMessageHeader_init(UA_SecureConversationMessageHea
 
 UA_TYPE_NEW_DEFAULT(UA_SecureConversationMessageHeader)
 UA_Int32 UA_SecureConversationMessageHeader_copy(const UA_SecureConversationMessageHeader *src,UA_SecureConversationMessageHeader *dst) {
-    	if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
-    	UA_Int32 retval = UA_SUCCESS;
+	UA_Int32 retval = UA_SUCCESS;
+    if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
 	memcpy(dst, src, sizeof(UA_SecureConversationMessageHeader));
 	return retval;
 }
@@ -321,8 +322,8 @@ UA_Int32 UA_AsymmetricAlgorithmSecurityHeader_init(UA_AsymmetricAlgorithmSecurit
 
 UA_TYPE_NEW_DEFAULT(UA_AsymmetricAlgorithmSecurityHeader)
 UA_Int32 UA_AsymmetricAlgorithmSecurityHeader_copy(const UA_AsymmetricAlgorithmSecurityHeader *src,UA_AsymmetricAlgorithmSecurityHeader *dst) {
-    	if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
-    	UA_Int32 retval = UA_SUCCESS;
+	UA_Int32 retval = UA_SUCCESS;
+    if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
 	memcpy(dst, src, sizeof(UA_AsymmetricAlgorithmSecurityHeader));
 	retval |= UA_ByteString_copy(&src->securityPolicyUri,&dst->securityPolicyUri);
 	retval |= UA_ByteString_copy(&src->senderCertificate,&dst->senderCertificate);
@@ -370,8 +371,8 @@ UA_Int32 UA_SymmetricAlgorithmSecurityHeader_init(UA_SymmetricAlgorithmSecurityH
 
 UA_TYPE_NEW_DEFAULT(UA_SymmetricAlgorithmSecurityHeader)
 UA_Int32 UA_SymmetricAlgorithmSecurityHeader_copy(const UA_SymmetricAlgorithmSecurityHeader *src,UA_SymmetricAlgorithmSecurityHeader *dst) {
-    	if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
-    	UA_Int32 retval = UA_SUCCESS;
+	UA_Int32 retval = UA_SUCCESS;
+    if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
 	memcpy(dst, src, sizeof(UA_SymmetricAlgorithmSecurityHeader));
 	return retval;
 }
@@ -420,8 +421,8 @@ UA_Int32 UA_SequenceHeader_init(UA_SequenceHeader *p) {
 
 UA_TYPE_NEW_DEFAULT(UA_SequenceHeader)
 UA_Int32 UA_SequenceHeader_copy(const UA_SequenceHeader *src,UA_SequenceHeader *dst) {
-    	if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
-    	UA_Int32 retval = UA_SUCCESS;
+	UA_Int32 retval = UA_SUCCESS;
+    if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
 	memcpy(dst, src, sizeof(UA_SequenceHeader));
 	return retval;
 }
@@ -474,8 +475,8 @@ UA_Int32 UA_SecureConversationMessageFooter_init(UA_SecureConversationMessageFoo
 
 UA_TYPE_NEW_DEFAULT(UA_SecureConversationMessageFooter)
 UA_Int32 UA_SecureConversationMessageFooter_copy(const UA_SecureConversationMessageFooter *src,UA_SecureConversationMessageFooter *dst) {
-    	if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
-    	UA_Int32 retval = UA_SUCCESS;
+	UA_Int32 retval = UA_SUCCESS;
+    if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
 	memcpy(dst, src, sizeof(UA_SecureConversationMessageFooter));
 
 
@@ -528,8 +529,8 @@ UA_Int32 UA_SecureConversationMessageAbortBody_init(UA_SecureConversationMessage
 
 UA_TYPE_NEW_DEFAULT(UA_SecureConversationMessageAbortBody)
 UA_Int32 UA_SecureConversationMessageAbortBody_copy(const UA_SecureConversationMessageAbortBody *src,UA_SecureConversationMessageAbortBody *dst) {
-    	if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
-    	UA_Int32 retval = UA_SUCCESS;
+	UA_Int32 retval = UA_SUCCESS;
+    if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
 	memcpy(dst, src, sizeof(UA_SecureConversationMessageAbortBody));
 	retval |= UA_String_copy(&src->reason,&dst->reason);
 	return retval;

+ 22 - 19
src/ua_types.c

@@ -2,8 +2,14 @@
 #include <stdlib.h> // alloc, free, vsnprintf
 #include <string.h>
 #include <stdarg.h> // va_start, va_end
+
+#ifdef WIN32
+#include <windows.h>
 #include <time.h>
+#else
 #include <sys/time.h>
+#endif
+
 #include "util/ua_util.h"
 #include "ua_types.h"
 #include "ua_types_encoding_binary.h"
@@ -147,8 +153,8 @@ UA_Int32 UA_String_deleteMembers(UA_String *p) {
 }
 
 UA_Int32 UA_String_copy(UA_String const *src, UA_String *dst) {
-	if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
 	UA_Int32 retval = UA_SUCCESS;
+	if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
 	dst->data   = UA_NULL;
 	dst->length = -1;
 	if(src->length > 0) {
@@ -298,8 +304,6 @@ UA_DateTimeStruct UA_DateTime_toStruct(UA_DateTime time) {
 	time_t    timeInSec = time/10000000; //converting the nanoseconds time in unixtime
 	struct tm ts;
 	ts = *gmtime(&timeInSec);
-	//strftime(buf, sizeof(buf), "%a %Y-%m-%d %H:%M:%S %Z", &ts);
-	//printf("%s\n", buf);
 	dateTimeStruct.sec    = ts.tm_sec;
 	dateTimeStruct.min    = ts.tm_min;
 	dateTimeStruct.hour   = ts.tm_hour;
@@ -339,8 +343,8 @@ UA_Int32 UA_Guid_init(UA_Guid *p) {
 
 UA_TYPE_NEW_DEFAULT(UA_Guid)
 UA_Int32 UA_Guid_copy(UA_Guid const *src, UA_Guid *dst) {
-	if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
 	UA_Int32 retval = UA_SUCCESS;
+	if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
 	retval |= UA_memcpy((void *)dst, (void *)src, sizeof(UA_Guid));
 	return retval;
 }
@@ -406,8 +410,8 @@ UA_Int32 UA_NodeId_init(UA_NodeId *p) {
 
 UA_TYPE_NEW_DEFAULT(UA_NodeId)
 UA_Int32 UA_NodeId_copy(UA_NodeId const *src, UA_NodeId *dst) {
-	if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
 	UA_Int32 retval = UA_SUCCESS;
+	if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
 	retval |= UA_Byte_copy(&src->encodingByte, &dst->encodingByte);
 
 	switch(src->encodingByte & UA_NODEIDTYPE_MASK) {
@@ -626,8 +630,8 @@ UA_Int32 UA_ExpandedNodeId_init(UA_ExpandedNodeId *p) {
 
 UA_TYPE_NEW_DEFAULT(UA_ExpandedNodeId)
 UA_Int32 UA_ExpandedNodeId_copy(UA_ExpandedNodeId const *src, UA_ExpandedNodeId *dst) {
-	if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
 	UA_Int32 retval = UA_SUCCESS;
+	if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
 	UA_String_copy(&src->namespaceUri, &dst->namespaceUri);
 	UA_NodeId_copy(&src->nodeId, &dst->nodeId);
 	UA_UInt32_copy(&src->serverIndex, &dst->serverIndex);
@@ -672,8 +676,8 @@ UA_Int32 UA_QualifiedName_init(UA_QualifiedName *p) {
 
 UA_TYPE_NEW_DEFAULT(UA_QualifiedName)
 UA_Int32 UA_QualifiedName_copy(UA_QualifiedName const *src, UA_QualifiedName *dst) {
-	if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
 	UA_Int32 retval = UA_SUCCESS;
+	if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
 	retval |= UA_String_copy(&src->name, &dst->name);
 	retval |= UA_UInt16_copy(&src->namespaceIndex, &dst->namespaceIndex);
 	return retval;
@@ -701,8 +705,8 @@ void UA_QualifiedName_printf(char const *label, const UA_QualifiedName *qn) {
 /* LocalizedText */
 UA_TYPE_DELETE_DEFAULT(UA_LocalizedText)
 UA_Int32 UA_LocalizedText_deleteMembers(UA_LocalizedText *p) {
-	if(p == UA_NULL) return UA_SUCCESS;
 	UA_Int32 retval = UA_SUCCESS;
+	if(p == UA_NULL) return UA_SUCCESS;
 	retval |= UA_String_deleteMembers(&p->locale);
 	retval |= UA_String_deleteMembers(&p->text);
 	return retval;
@@ -728,9 +732,8 @@ UA_Int32 UA_LocalizedText_copycstring(char const *src, UA_LocalizedText *dst) {
 }
 
 UA_Int32 UA_LocalizedText_copy(UA_LocalizedText const *src, UA_LocalizedText *dst) {
-	if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
 	UA_Int32 retval = UA_SUCCESS;
-
+	if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
 	retval |= UA_LocalizedText_init(dst);
 	retval |= UA_String_copy(&src->locale, &dst->locale);
 	if(retval != UA_SUCCESS) return retval;
@@ -769,8 +772,8 @@ UA_Int32 UA_ExtensionObject_init(UA_ExtensionObject *p) {
 
 UA_TYPE_NEW_DEFAULT(UA_ExtensionObject)
 UA_Int32 UA_ExtensionObject_copy(UA_ExtensionObject const *src, UA_ExtensionObject *dst) {
-	if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
 	UA_Int32 retval = UA_SUCCESS;
+	if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
 	retval |= UA_Byte_copy(&src->encoding, &dst->encoding);
 	retval |= UA_ByteString_copy(&src->body, &dst->body);
 	retval |= UA_NodeId_copy(&src->typeId, &dst->typeId);
@@ -817,8 +820,8 @@ UA_Int32 UA_DataValue_init(UA_DataValue *p) {
 
 UA_TYPE_NEW_DEFAULT(UA_DataValue)
 UA_Int32 UA_DataValue_copy(UA_DataValue const *src, UA_DataValue *dst) {
-	if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
 	UA_Int32 retval = UA_SUCCESS;
+	if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
 	UA_Byte_copy(&src->encodingMask, &dst->encodingMask);
 	UA_Int16_copy(&src->serverPicoseconds, &dst->serverPicoseconds);
 	UA_DateTime_copy(&src->serverTimestamp, &dst->serverTimestamp);
@@ -854,9 +857,10 @@ void UA_DataValue_print(const UA_DataValue *p, FILE *stream) {
 UA_TYPE_DELETE_DEFAULT(UA_Variant)
 UA_Int32 UA_Variant_deleteMembers(UA_Variant *p) {
 	UA_Int32 retval = UA_SUCCESS;
+	UA_Boolean hasDimensions;
 	if(p == UA_NULL) return retval;
 
-	UA_Boolean hasDimensions = p->arrayDimensions != UA_NULL;
+	hasDimensions = p->arrayDimensions != UA_NULL;
 
 	if(p->data != UA_NULL) {
 		retval |= UA_Array_delete(p->data, p->arrayLength, p->vt);
@@ -881,10 +885,9 @@ UA_Int32 UA_Variant_init(UA_Variant *p) {
 
 UA_TYPE_NEW_DEFAULT(UA_Variant)
 UA_Int32 UA_Variant_copy(UA_Variant const *src, UA_Variant *dst) {
+	UA_Int32  retval = UA_SUCCESS;
 	if(src == UA_NULL || dst == UA_NULL)
 		return UA_ERROR;
-
-	UA_Int32  retval = UA_SUCCESS;
 	dst->vt = src->vt;
 	retval |= UA_Int32_copy(&src->arrayLength, &dst->arrayLength);
 	retval |= UA_Int32_copy(&src->arrayDimensionsLength, &dst->arrayDimensionsLength);
@@ -988,8 +991,8 @@ UA_Int32 UA_DiagnosticInfo_init(UA_DiagnosticInfo *p) {
 
 UA_TYPE_NEW_DEFAULT(UA_DiagnosticInfo)
 UA_Int32 UA_DiagnosticInfo_copy(UA_DiagnosticInfo const *src, UA_DiagnosticInfo *dst) {
-	if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
 	UA_Int32 retval = UA_SUCCESS;
+	if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
 	retval |= UA_String_copy(&src->additionalInfo, &dst->additionalInfo);
 	retval |= UA_Byte_copy(&src->encodingMask, &dst->encodingMask);
 	retval |= UA_StatusCode_copy(&src->innerStatusCode, &dst->innerStatusCode);
@@ -1101,10 +1104,9 @@ UA_Int32 UA_Array_new(void **p, UA_Int32 noElements, UA_VTable_Entry *vt) {
 }
 
 UA_Int32 UA_Array_init(void *p, UA_Int32 noElements, UA_VTable_Entry *vt) {
+	UA_Int32 retval = UA_SUCCESS;
 	if(p == UA_NULL || vt == UA_NULL)
 		return UA_ERROR;
-
-	UA_Int32 retval = UA_SUCCESS;
 	char    *cp     = (char *)p; // so compilers allow pointer arithmetic
 	UA_UInt32 memSize = vt->memSize;
 	for(UA_Int32 i = 0;i < noElements && retval == UA_SUCCESS;i++) {
@@ -1132,10 +1134,11 @@ UA_Int32 UA_Array_delete(void *p, UA_Int32 noElements, UA_VTable_Entry *vt) {
 }
 
 UA_Int32 UA_Array_copy(const void *src, UA_Int32 noElements, UA_VTable_Entry *vt, void **dst) {
+	UA_Int32 retval;
 	if(src == UA_NULL || dst == UA_NULL || vt == UA_NULL)
 		return UA_ERROR;
 
-	UA_Int32 retval = UA_Array_new(dst, noElements, vt);
+	retval = UA_Array_new(dst, noElements, vt);
 	if(retval != UA_SUCCESS){
 		*dst = UA_NULL;
 		return retval;

+ 21 - 13
src/ua_types.h

@@ -129,9 +129,6 @@ typedef struct UA_NodeId {
 	} identifier;
 } UA_NodeId;
 
-#define NS0NODEID(NUMERIC_ID) \
-	(UA_NodeId){.encodingByte = 0 /*UA_NODEIDTYPE_TWOBYTE*/, .namespace = 0, .identifier.numeric = NUMERIC_ID}
-
 #define UA_NODEIDTYPE_NAMESPACE_URI_FLAG 0x80
 #define UA_NODEIDTYPE_SERVERINDEX_FLAG 0x40
 #define UA_NODEIDTYPE_MASK (~(UA_NODEIDTYPE_NAMESPACE_URI_FLAG | UA_NODEIDTYPE_SERVERINDEX_FLAG))
@@ -143,9 +140,6 @@ typedef struct UA_ExpandedNodeId {
 	UA_UInt32 serverIndex;
 } UA_ExpandedNodeId;
 
-#define NS0EXPANDEDNODEID(NUMERIC_ID) \
-	(UA_ExpandedNodeId){.nodeId = NS0NODEID(NUMERIC_ID), .namespaceUri = {-1, UA_NULL}, .serverIndex = 0}
-
 /** @brief A numeric identifier for a error or condition that is associated with a value or an operation. */
 typedef UA_UInt32 UA_StatusCode; // StatusCodes aren't an enum(=int) since 32 unsigned bits are needed. See also ua_statuscodes.h */
 
@@ -298,7 +292,9 @@ UA_TYPE_PROTOTYPES(UA_InvalidType)
 
 /* String */
 #define UA_STRING_NULL (UA_String){-1, UA_NULL}
-#define UA_STRING_STATIC(STRING) (UA_String){sizeof(STRING)-1, (UA_Byte*)STRING}
+#define UA_STRING_STATIC(VARIABLE, STRING) do { \
+	VARIABLE.length = sizeof(STRING)-1; \
+	VARIABLE.data = (UA_Byte*)STRING; } while (0)
 
 UA_Int32 UA_String_copycstring(char const *src, UA_String *dst);
 UA_Int32 UA_String_copyprintf(char const *fmt, UA_String *dst, ...);
@@ -345,18 +341,30 @@ void UA_NodeId_printf(char *label, const UA_NodeId *node);
 UA_Boolean UA_NodeId_isNull(const UA_NodeId *p);
 UA_Boolean UA_NodeId_isBasicType(UA_NodeId const *id);
 
+#define NS0NODEID(NUMERIC_ID) \
+	(UA_NodeId){ .encodingByte = 0 /*UA_NODEIDTYPE_TWOBYTE*/, .namespace = 0, .identifier.numeric = NUMERIC_ID }
+
 /* ExpandedNodeId */
 UA_Boolean UA_ExpandedNodeId_isNull(const UA_ExpandedNodeId *p);
 
+#define NS0EXPANDEDNODEID(VARIABLE, NUMERIC_ID) do { \
+	VARIABLE.nodeId = NS0NODEID(NUMERIC_ID); \
+	VARIABLE.namespaceUri = UA_STRING_NULL; \
+	VARIABLE.serverIndex = 0; } while(0)
+
 /* QualifiedName */
-#define UA_QUALIFIEDNAME_STATIC(STRING) \
-	(UA_QualifiedName){0, {sizeof(STRING)-1, (UA_Byte*)STRING}}
+#define UA_QUALIFIEDNAME_STATIC(VARIABLE, STRING) do {\
+	VARIABLE.namespaceIndex = 0; \
+	UA_STRING_STATIC(VARIABLE.name, STRING); } while (0)
 #ifdef DEBUG
 void UA_QualifiedName_printf(char const *label, const UA_QualifiedName *qn);
 #endif
 
 /* LocalizedText */
-#define UA_LOCALIZEDTEXT_STATIC(STRING) (UA_LocalizedText){{2, (UA_Byte*)"en"}, UA_STRING_STATIC(STRING)}
+#define UA_LOCALIZEDTEXT_STATIC(VARIABLE, STRING) do {\
+	UA_STRING_STATIC(VARIABLE.locale, "end"); \
+	UA_STRING_STATIC(VARIABLE.text, STRING); } while (0)
+
 UA_Int32 UA_LocalizedText_copycstring(char const *src, UA_LocalizedText *dst);
 
 /* Variant */
@@ -480,9 +488,9 @@ typedef struct UA_VTable {
 #define UA_TYPE_COPY_DEFAULT(TYPE)                             \
     UA_Int32 TYPE##_copy(TYPE const *src, TYPE *dst) {         \
 		if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;  \
-		UA_Int32 retval = UA_SUCCESS;                          \
-		retval |= UA_memcpy(dst, src, sizeof(TYPE));           \
-		return retval;                                         \
+{UA_Int32 retval = UA_SUCCESS;                          \
+	retval |= UA_memcpy(dst, src, sizeof(TYPE));           \
+	return retval;    }                                     \
 	}
 
 #define UA_TYPE_COPY_AS(TYPE, TYPE_AS)                         \

+ 37 - 23
src/ua_types_encoding_binary.c

@@ -1,7 +1,7 @@
 #include "ua_types_encoding_binary.h"
 #include "ua_namespace_0.h"
 
-static inline UA_Boolean is_builtin(UA_NodeId *typeid) {
+static INLINE UA_Boolean is_builtin(UA_NodeId *typeid) {
 	return (typeid->namespace == 0 && 1 <= typeid->identifier.numeric && typeid->identifier.numeric <= 25);
 }
 
@@ -49,13 +49,13 @@ static UA_Int32 UA_Array_calcSizeBinary_asExtensionObject(UA_Int32 nElements, UA
 
 UA_Int32 UA_Array_encodeBinary(const void *src, UA_Int32 noElements, UA_VTable_Entry *vt, UA_ByteString *dst,
                                UA_UInt32 *offset) {
+	UA_Int32 retval = UA_SUCCESS;
 	if(vt == UA_NULL || dst == UA_NULL || offset == UA_NULL || ((src == UA_NULL) && (noElements > 0)))
 		return UA_ERROR;
 
 	//Null Arrays are encoded with length = -1 // part 6 - §5.24
 	if(noElements < -1) noElements = -1;
 
-	UA_Int32 retval     = UA_SUCCESS;
 	retval = UA_Int32_encodeBinary(&noElements, dst, offset);
 	const UA_Byte *csrc = (const UA_Byte *)src;
 	UA_UInt32 memSize   = vt->memSize;
@@ -68,13 +68,14 @@ UA_Int32 UA_Array_encodeBinary(const void *src, UA_Int32 noElements, UA_VTable_E
 
 static UA_Int32 UA_Array_encodeBinary_asExtensionObject(const void *src, UA_Int32 noElements, UA_VTable_Entry *vt,
 														UA_ByteString *dst, UA_UInt32 *offset) {
+	UA_Int32 retval = UA_SUCCESS;
 	if(vt == UA_NULL || dst == UA_NULL || offset == UA_NULL || (src == UA_NULL && noElements > 0))
 		return UA_ERROR;
 
 	//Null Arrays are encoded with length = -1 // part 6 - §5.24
-	if(noElements < -1) noElements = -1;
+	if(noElements < -1)
+		noElements = -1;
 
-	UA_Int32 retval     = UA_SUCCESS;
 	retval = UA_Int32_encodeBinary(&noElements, dst, offset);
 	const UA_Byte *csrc = (const UA_Byte *)src;
 	UA_UInt32 memSize   = vt->memSize;
@@ -96,10 +97,10 @@ static UA_Int32 UA_Array_encodeBinary_asExtensionObject(const void *src, UA_Int3
 
 UA_Int32 UA_Array_decodeBinary(const UA_ByteString *src, UA_UInt32 *offset, UA_Int32 noElements, UA_VTable_Entry *vt,
                                void **dst) {
+	UA_Int32 retval = UA_SUCCESS;
 	if(vt == UA_NULL || src == UA_NULL || dst == UA_NULL || offset == UA_NULL)
 		return UA_ERROR;
 
-	UA_Int32 retval = UA_SUCCESS;
 	if(noElements <= 0) {
 		*dst = UA_NULL;
 		return retval;
@@ -250,15 +251,18 @@ UA_TYPE_CALCSIZEBINARY_SIZEOF(UA_Float)
 // FIXME: Implement NaN, Inf and Zero(s)
 UA_Byte UA_FLOAT_ZERO[] = { 0x00, 0x00, 0x00, 0x00 };
 UA_TYPE_DECODEBINARY(UA_Float,
+					 UA_Float mantissa;
+					 UA_UInt32 biasedExponent;
+					 UA_Float sign;
                      if(memcmp(&src->data[*offset], UA_FLOAT_ZERO,
-                               4) == 0) return UA_Int32_decodeBinary(src, offset, (UA_Int32 *)dst); UA_Float mantissa;
+                               4) == 0) return UA_Int32_decodeBinary(src, offset, (UA_Int32 *)dst);
+					 
                      mantissa = (UA_Float)(src->data[*offset] & 0xFF);                         // bits 0-7
                      mantissa = (mantissa / 256.0 ) + (UA_Float)(src->data[*offset+1] & 0xFF); // bits 8-15
                      mantissa = (mantissa / 256.0 ) + (UA_Float)(src->data[*offset+2] & 0x7F); // bits 16-22
-                     UA_UInt32 biasedExponent;
                      biasedExponent  = (src->data[*offset+2] & 0x80) >>  7;                   // bits 23
                      biasedExponent |= (src->data[*offset+3] & 0x7F) <<  1;                   // bits 24-30
-                     UA_Float sign = ( src->data[*offset+ 3] & 0x80 ) ? -1.0 : 1.0;           // bit 31
+                     sign = ( src->data[*offset+ 3] & 0x80 ) ? -1.0 : 1.0;           // bit 31
                      if(biasedExponent >= 127)
 						 *dst = (UA_Float)sign * (1 << (biasedExponent-127)) * (1.0 + mantissa / 128.0 );
                      else
@@ -270,9 +274,12 @@ UA_TYPE_ENCODEBINARY(UA_Float, return UA_UInt32_encodeBinary((UA_UInt32 *)src, d
 UA_TYPE_CALCSIZEBINARY_SIZEOF(UA_Double)
 // FIXME: Implement NaN, Inf and Zero(s)
 UA_Byte UA_DOUBLE_ZERO[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
-UA_TYPE_DECODEBINARY(UA_Double,
+					 UA_TYPE_DECODEBINARY(UA_Double,
+				     UA_Double sign;
+					 UA_Double mantissa;
+					 UA_UInt32 biasedExponent;
                      if(memcmp(&src->data[*offset], UA_DOUBLE_ZERO,
-                               8) == 0) return UA_Int64_decodeBinary(src, offset, (UA_Int64 *)dst); UA_Double mantissa;
+                               8) == 0) return UA_Int64_decodeBinary(src, offset, (UA_Int64 *)dst);
                      mantissa = (UA_Double)(src->data[*offset] & 0xFF);                         // bits 0-7
                      mantissa = (mantissa / 256.0 ) + (UA_Double)(src->data[*offset+1] & 0xFF); // bits 8-15
                      mantissa = (mantissa / 256.0 ) + (UA_Double)(src->data[*offset+2] & 0xFF); // bits 16-23
@@ -281,14 +288,13 @@ UA_TYPE_DECODEBINARY(UA_Double,
                      mantissa = (mantissa / 256.0 ) + (UA_Double)(src->data[*offset+5] & 0xFF); // bits 40-47
                      mantissa = (mantissa / 256.0 ) + (UA_Double)(src->data[*offset+6] & 0x0F); // bits 48-51
                      DBG_VERBOSE(printf("UA_Double_decodeBinary - mantissa=%f\n", mantissa));
-                     UA_UInt32 biasedExponent;
                      biasedExponent  = (src->data[*offset+6] & 0xF0) >>  4; // bits 52-55
                      DBG_VERBOSE(printf("UA_Double_decodeBinary - biasedExponent52-55=%d, src=%d\n", biasedExponent,
                                         src->data[*offset+6]));
                      biasedExponent |= ((UA_UInt32)(src->data[*offset+7] & 0x7F)) <<  4; // bits 56-62
                      DBG_VERBOSE(printf("UA_Double_decodeBinary - biasedExponent56-62=%d, src=%d\n", biasedExponent,
                                         src->data[*offset+7]));
-                     UA_Double sign = ( src->data[*offset+7] & 0x80 ) ? -1.0 : 1.0; // bit 63
+                     sign = ( src->data[*offset+7] & 0x80 ) ? -1.0 : 1.0; // bit 63
                      if(biasedExponent >= 1023)
 						 *dst = (UA_Double)sign * (1 << (biasedExponent-1023)) * (1.0 + mantissa / 8.0 );
                      else
@@ -727,20 +733,23 @@ UA_Int32 UA_DataValue_calcSizeBinary(UA_DataValue const *p) {
  * Officially, only builtin types are contained in a variant.
  *
  * Every ExtensionObject incurrs an overhead of 4 byte (nodeid) + 1 byte (encoding) */
-UA_Int32 UA_Variant_calcSizeBinary(UA_Variant const *p) { if(p == UA_NULL)
-   return sizeof(UA_Variant);
+UA_Int32 UA_Variant_calcSizeBinary(UA_Variant const *p) {
+	UA_Int32 arrayLength, length;
+	UA_Boolean isArray, hasDimensions, isBuiltin;
+	if(p == UA_NULL)
+		return sizeof(UA_Variant);
 
 	if(p->vt == UA_NULL)
 		return UA_ERR_INCONSISTENT;
-	UA_Int32 arrayLength = p->arrayLength;
+	arrayLength = p->arrayLength;
 	if(p->data == UA_NULL)
 		arrayLength = -1;
 
-	UA_Boolean isArray = arrayLength != 1;       // a single element is not an array
-	UA_Boolean hasDimensions = isArray && p->arrayDimensions != UA_NULL;
-	UA_Boolean isBuiltin = is_builtin(&p->vt->typeId);
+	isArray = arrayLength != 1;       // a single element is not an array
+	hasDimensions = isArray && p->arrayDimensions != UA_NULL;
+	isBuiltin = is_builtin(&p->vt->typeId);
 
-	UA_Int32   length        = sizeof(UA_Byte); //p->encodingMask
+	length = sizeof(UA_Byte); //p->encodingMask
 	if(isArray) {
 		// array length + the array itself
 		length += UA_Array_calcSizeBinary(arrayLength, p->vt, p->data);
@@ -763,14 +772,19 @@ UA_Int32 UA_Variant_calcSizeBinary(UA_Variant const *p) { if(p == UA_NULL)
 }
 
 UA_TYPE_ENCODEBINARY(UA_Variant,
+	                 UA_Byte encodingByte;
+					 UA_Boolean isArray;
+					 UA_Boolean hasDimensions;
+					 UA_Boolean isBuiltin;
+
                      if(src == UA_NULL || src->vt == UA_NULL || src->vt->typeId.namespace != 0)
 						 return UA_ERROR;
 
-                     UA_Boolean isArray       = src->arrayLength != 1;  // a single element is not an array
-                     UA_Boolean hasDimensions = isArray && src->arrayDimensions != UA_NULL;
-					 UA_Boolean isBuiltin = is_builtin(&src->vt->typeId);
+                     isArray       = src->arrayLength != 1;  // a single element is not an array
+                     hasDimensions = isArray && src->arrayDimensions != UA_NULL;
+					 isBuiltin = is_builtin(&src->vt->typeId);
 
-                     UA_Byte encodingByte = 0;
+                     encodingByte = 0;
                      if(isArray) {
                          encodingByte |= UA_VARIANT_ENCODINGMASKTYPE_ARRAY;
                          if(hasDimensions)

+ 21 - 13
src/util/ua_indexedList.c

@@ -10,9 +10,10 @@ UA_Int32 UA_indexedList_init(UA_indexedList_List* list){
 	return UA_list_init((UA_list_List*)list);
 }
 
-UA_Int32 UA_indexedList_destroy(UA_indexedList_List* list, UA_indexedList_PayloadVisitor visitor){
-	if(list==UA_NULL)return UA_ERROR;
+UA_Int32 UA_indexedList_destroy(UA_indexedList_List* list, UA_indexedList_PayloadVisitor visitor) {
 	UA_list_Element* current = UA_NULL;
+	if(list==UA_NULL)
+		return UA_ERROR;
 	current=list->first;
 	while(current){
 		UA_list_Element* next = current->next;
@@ -39,8 +40,9 @@ UA_Int32 UA_indexedList_initElement(UA_indexedList_Element* elem){
 }
 
 UA_Int32 UA_indexedList_addValue(UA_indexedList_List* list, UA_Int32 index, void* payload){
-	if(list==UA_NULL)return UA_ERROR;
 	UA_list_Element* dllElem;
+	if(list==UA_NULL)
+		return UA_ERROR;
 	UA_alloc((void**)&dllElem, sizeof(UA_list_Element));
 	UA_list_initElement(dllElem);
 	UA_indexedList_Element* iilElem;
@@ -54,11 +56,12 @@ UA_Int32 UA_indexedList_addValue(UA_indexedList_List* list, UA_Int32 index, void
 }
 
 UA_Int32 UA_indexedList_addValueToFront(UA_indexedList_List* list, UA_Int32 index, void* payload) {
-	if(list==UA_NULL)return UA_ERROR;
 	UA_list_Element* dllElem;
+	UA_indexedList_Element* iilElem;
+	if(list==UA_NULL)
+		return UA_ERROR;
 	UA_alloc((void**)&dllElem, sizeof(UA_list_Element));
 	UA_list_initElement(dllElem);
-	UA_indexedList_Element* iilElem;
 	UA_alloc((void**)&iilElem, sizeof(UA_indexedList_Element));
 	UA_indexedList_initElement(iilElem);
 	iilElem->index = index;
@@ -68,9 +71,11 @@ UA_Int32 UA_indexedList_addValueToFront(UA_indexedList_List* list, UA_Int32 inde
 	return UA_list_addElementToFront((UA_list_List*)list, dllElem);
 }
 
-UA_indexedList_Element* UA_indexedList_find(UA_indexedList_List* const list, UA_Int32 index){
-	if(list==UA_NULL)return UA_NULL;
-	UA_list_Element* current = list->first;
+UA_indexedList_Element* UA_indexedList_find(UA_indexedList_List* const list, UA_Int32 index) {
+	UA_list_Element* current;
+	if(list==UA_NULL)
+		return UA_NULL;
+	current = list->first;
 	while(current){
 		if(current->payload){
 			UA_indexedList_Element* elem = (UA_indexedList_Element*)current->payload;
@@ -83,18 +88,21 @@ UA_indexedList_Element* UA_indexedList_find(UA_indexedList_List* const list, UA_
 	return UA_NULL;
 }
 
-void* UA_indexedList_findValue(UA_indexedList_List* const list, UA_Int32 index){
+void* UA_indexedList_findValue(UA_indexedList_List* const list, UA_Int32 index) {
+	UA_indexedList_Element* iilElem;
 	if(list==UA_NULL)return UA_NULL;
-	UA_indexedList_Element* iilElem = UA_indexedList_find(list, index);
+	iilElem = UA_indexedList_find(list, index);
 	if(iilElem){
 		return iilElem->payload;
 	}
 	return UA_NULL;
 }
 
-UA_Int32 UA_indexedList_iterateValues(UA_indexedList_List* const list, UA_indexedList_PayloadVisitor visitor){
-	if(list==UA_NULL)return UA_ERROR;
-	UA_list_Element* current = list->first;
+UA_Int32 UA_indexedList_iterateValues(UA_indexedList_List* const list, UA_indexedList_PayloadVisitor visitor) {
+	UA_list_Element* current;
+	if(list==UA_NULL)
+		return UA_ERROR;
+	current = list->first;
 	while(current){
 		if(current->payload){
 			UA_indexedList_Element* elem = (UA_indexedList_Element*)current->payload;

+ 31 - 20
src/util/ua_list.c

@@ -25,8 +25,8 @@ UA_Int32 UA_list_init(UA_list_List* list){
 }
 
 UA_Int32 UA_list_addElementToFront(UA_list_List* list, UA_list_Element* element){
-	if(list==UA_NULL || element==UA_NULL) return UA_ERROR;
 	UA_list_Element* second = UA_NULL;
+	if(list==UA_NULL || element==UA_NULL) return UA_ERROR;
 	second = list->first;
 	list->first = element;
 	element->prev = UA_NULL;
@@ -42,9 +42,10 @@ UA_Int32 UA_list_addElementToFront(UA_list_List* list, UA_list_Element* element)
 	return UA_NO_ERROR;
 }
 
-UA_Int32 UA_list_addPayloadToFront(UA_list_List* list, void* const payload){
-	if(list==UA_NULL)return UA_ERROR;
+UA_Int32 UA_list_addPayloadToFront(UA_list_List* list, void* const payload) {
 	UA_list_Element* elem;
+	if(list==UA_NULL)
+		return UA_ERROR;
 	UA_alloc((void**)&elem, sizeof(*elem));
 	UA_list_initElement(elem);
 	elem->payload = payload;
@@ -52,9 +53,10 @@ UA_Int32 UA_list_addPayloadToFront(UA_list_List* list, void* const payload){
 	return UA_NO_ERROR;
 }
 
-UA_Int32 UA_list_addElementToBack(UA_list_List* list, UA_list_Element* element){
-	if(list==UA_NULL || element == UA_NULL)return UA_ERROR;
+UA_Int32 UA_list_addElementToBack(UA_list_List* list, UA_list_Element* element) {
 	UA_list_Element* secondLast = UA_NULL;
+	if(list==UA_NULL || element == UA_NULL)
+		return UA_ERROR;
 	secondLast = list->last;
 	list->last = element;
 	element->prev = secondLast;
@@ -70,9 +72,10 @@ UA_Int32 UA_list_addElementToBack(UA_list_List* list, UA_list_Element* element){
 	return UA_NO_ERROR;
 }
 
-UA_Int32 UA_list_addPayloadToBack(UA_list_List* list, void* const payload){
-	if(list==UA_NULL)return UA_ERROR;
+UA_Int32 UA_list_addPayloadToBack(UA_list_List* list, void* const payload) {
 	UA_list_Element* elem;
+	if(list==UA_NULL)
+		return UA_ERROR;
 	UA_alloc((void**)&elem, sizeof(*elem));
 	UA_list_initElement(elem);
 	elem->payload = payload;
@@ -80,9 +83,10 @@ UA_Int32 UA_list_addPayloadToBack(UA_list_List* list, void* const payload){
 	return UA_NO_ERROR;
 }
 
-UA_Int32 UA_list_removeFirst(UA_list_List* list, UA_list_PayloadVisitor visitor){
-	if(list==UA_NULL)return UA_ERROR;
+UA_Int32 UA_list_removeFirst(UA_list_List* list, UA_list_PayloadVisitor visitor) {
 	UA_list_Element* temp = UA_NULL;
+	if(list==UA_NULL)
+		return UA_ERROR;
 	if(list->first){
 		temp = list->first->next;
 		if(visitor){
@@ -103,9 +107,10 @@ UA_Int32 UA_list_removeFirst(UA_list_List* list, UA_list_PayloadVisitor visitor)
 	return UA_NO_ERROR;
 }
 
-UA_Int32 UA_list_removeLast(UA_list_List* list, UA_list_PayloadVisitor visitor){
-	if(list==UA_NULL)return UA_ERROR;
+UA_Int32 UA_list_removeLast(UA_list_List* list, UA_list_PayloadVisitor visitor) {
 	UA_list_Element* temp = UA_NULL;
+	if(list==UA_NULL)
+		return UA_ERROR;
 	if(list->last){
 		temp = list->last->prev;
 		if(visitor){
@@ -126,8 +131,9 @@ UA_Int32 UA_list_removeLast(UA_list_List* list, UA_list_PayloadVisitor visitor){
 	return UA_NO_ERROR;
 }
 
-UA_Int32 UA_list_removeElement(UA_list_Element* const elem, UA_list_PayloadVisitor visitor){
-	if(elem==UA_NULL)return UA_ERROR;
+UA_Int32 UA_list_removeElement(UA_list_Element* const elem, UA_list_PayloadVisitor visitor) {
+	if(elem==UA_NULL)
+		return UA_ERROR;
 	if(elem==elem->father->first){
 		return UA_list_removeFirst(elem->father, visitor);
 	}else if(elem==elem->father->last){
@@ -146,9 +152,10 @@ UA_Int32 UA_list_removeElement(UA_list_Element* const elem, UA_list_PayloadVisit
 	return UA_NO_ERROR;
 }
 
-UA_Int32 UA_list_destroy(UA_list_List* list, UA_list_PayloadVisitor visitor){
-	if(list==UA_NULL)return UA_ERROR;
+UA_Int32 UA_list_destroy(UA_list_List* list, UA_list_PayloadVisitor visitor) {
 	UA_list_Element* current = UA_NULL;
+	if(list==UA_NULL)
+		return UA_ERROR;
 	current=list->first;
 	while(current){
 		UA_list_Element* next = current->next;
@@ -162,9 +169,11 @@ UA_Int32 UA_list_destroy(UA_list_List* list, UA_list_PayloadVisitor visitor){
 	return UA_NO_ERROR;
 }
 
-UA_Int32 UA_list_iterateElement(UA_list_List* const list, UA_list_ElementVisitor visitor){
-	if(list==UA_NULL)return UA_ERROR;
-	UA_list_Element* current = list->first;
+UA_Int32 UA_list_iterateElement(UA_list_List* const list, UA_list_ElementVisitor visitor) {
+	UA_list_Element* current;
+	if(list==UA_NULL)
+		return UA_ERROR;
+	current = list->first;
 	while(current){
 		if(visitor){
 			(*visitor)(current);
@@ -186,8 +195,10 @@ UA_Int32 UA_list_iterateElement(UA_list_List* const list, UA_list_ElementVisitor
 }*/
 /** ANSI C forbids function nesting - reworked ugly version **/
 UA_Int32 UA_list_iteratePayload(UA_list_List* const list, UA_list_PayloadVisitor visitor){
-	if(list==UA_NULL)return UA_ERROR;
-	UA_list_Element* current = list->first;
+	UA_list_Element* current;
+	if(list==UA_NULL)
+		return UA_ERROR;
+	current = list->first;
 	while(current){
 		if(visitor){
 			(*visitor)(current->payload);

+ 4 - 0
src/util/ua_list.h

@@ -3,7 +3,11 @@
 
 #include "ua_types.h"
 #include <stddef.h> /* Needed for sys/queue.h */
+#ifndef MSVC
 #include <sys/queue.h>
+#else
+#include "queue.h"
+#endif
 
 /**********************/
 /* Singly Linked List */

+ 2 - 2
tools/generate_builtin.py

@@ -240,8 +240,8 @@ UA_TYPE_METHOD_DECODEXML_NOTIMPL(%(name)s)''')
 
     # 12) Copy
     printc('''UA_Int32 %(name)s_copy(const %(name)s *src,%(name)s *dst) {
-    if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
-    UA_Int32 retval = UA_SUCCESS;''')
+	UA_Int32 retval = UA_SUCCESS;
+    if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;''')
     printc("\tmemcpy(dst, src, sizeof(%(name)s));")
     for n,t in membermap.iteritems():
         if t.find("*") != -1: