Browse Source

run uncrustify on all source files

Julius Pfrommer 10 years ago
parent
commit
aead82e671

+ 293 - 276
src/server/ua_namespace.c

@@ -3,336 +3,353 @@
 #include <stdio.h>
 
 struct UA_Namespace {
-	const UA_Node ** entries;
-	UA_UInt32 size;
-	UA_UInt32 count;
-	UA_UInt32 sizePrimeIndex;
+    const UA_Node **entries;
+    UA_UInt32       size;
+    UA_UInt32       count;
+    UA_UInt32       sizePrimeIndex;
 };
 
 typedef UA_UInt32 hash_t;
 /* The size of the hash-map is always a prime number. They are chosen to be
    close to the next power of 2. So the size ca. doubles with each prime. */
 static hash_t const primes[] = {
-	7,         13,        31,        61,         127,        251,
-	509,       1021,      2039,      4093,       8191,       16381,
-	32749,     65521,     131071,    262139,     524287,     1048573,
-	2097143,   4194301,   8388593,   16777213,   33554393,   67108859,
-	134217689, 268435399, 536870909, 1073741789, 2147483647, 4294967291
+    7,         13,         31,         61,         127,         251,
+    509,       1021,       2039,       4093,       8191,        16381,
+    32749,     65521,      131071,     262139,     524287,      1048573,
+    2097143,   4194301,    8388593,    16777213,   33554393,    67108859,
+    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) {
-	UA_UInt16 low  = 0;
-	UA_UInt16 high = sizeof(primes) / sizeof(hash_t);
-	while(low != high) {
-		UA_UInt16 mid = low + (high - low) / 2;
-		if(n > primes[mid])
-			low = mid + 1;
-		else
-			high = mid;
-	}
-	return low;
+    UA_UInt16 low  = 0;
+    UA_UInt16 high = sizeof(primes) / sizeof(hash_t);
+    while(low != high) {
+        UA_UInt16 mid = low + (high - low) / 2;
+        if(n > primes[mid])
+            low = mid + 1;
+        else
+            high = mid;
+    }
+    return low;
 }
 
 /* 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) {
-	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;
-	static const uint32_t r2 = 13;
-	static const uint32_t m  = 5;
-	static const uint32_t n  = 0xe6546b64;
-	hash_t hash = len;
-
-	if(data == UA_NULL)
-		return 0;
-
-	blocks  = (const uint32_t *)data;
-	for(int32_t i = 0;i < nblocks;i++) {
-		uint32_t k = blocks[i];
-		k    *= c1;
-		k     = (k << r1) | (k >> (32 - r1));
-		k    *= c2;
-		hash ^= k;
-		hash  = ((hash << r2) | (hash >> (32 - r2))) * m + n;
-	}
-
-	const uint8_t *tail = (const uint8_t *)(data + nblocks * 4);
-	uint32_t       k1   = 0;
-
-	switch(len & 3) {
-	case 3:
-		k1 ^= tail[2] << 16;
-	case 2:
-		k1 ^= tail[1] << 8;
-	case 1:
-		k1   ^= tail[0];
-		k1   *= c1;
-		k1    = (k1 << r1) | (k1 >> (32 - r1));
-		k1   *= c2;
-		hash ^= k1;
-	}
-
-	hash ^= len;
-	hash ^= (hash >> 16);
-	hash *= 0x85ebca6b;
-	hash ^= (hash >> 13);
-	hash *= 0xc2b2ae35;
-	hash ^= (hash >> 16);
-
-	return hash;
+    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;
+    static const uint32_t r2 = 13;
+    static const uint32_t m  = 5;
+    static const uint32_t n  = 0xe6546b64;
+    hash_t hash = len;
+
+    if(data == UA_NULL)
+        return 0;
+
+    blocks = (const uint32_t *)data;
+    for(int32_t i = 0;i < nblocks;i++) {
+        uint32_t k = blocks[i];
+        k    *= c1;
+        k     = (k << r1) | (k >> (32 - r1));
+        k    *= c2;
+        hash ^= k;
+        hash  = ((hash << r2) | (hash >> (32 - r2))) * m + n;
+    }
+
+    const uint8_t *tail = (const uint8_t *)(data + nblocks * 4);
+    uint32_t       k1   = 0;
+
+    switch(len & 3) {
+    case 3:
+        k1 ^= tail[2] << 16;
+
+    case 2:
+        k1 ^= tail[1] << 8;
+
+    case 1:
+        k1   ^= tail[0];
+        k1   *= c1;
+        k1    = (k1 << r1) | (k1 >> (32 - r1));
+        k1   *= c2;
+        hash ^= k1;
+    }
+
+    hash ^= len;
+    hash ^= (hash >> 16);
+    hash *= 0x85ebca6b;
+    hash ^= (hash >> 13);
+    hash *= 0xc2b2ae35;
+    hash ^= (hash >> 16);
+
+    return hash;
 }
 
 static INLINE hash_t hash(const UA_NodeId *n) {
-	switch(n->identifierType) {
-	case UA_NODEIDTYPE_NUMERIC:
-		/*  Knuth's multiplicative hashing */
-		return n->identifier.numeric * 2654435761;   // mod(2^32) is implicit
-	case UA_NODEIDTYPE_STRING:
-		return hash_array(n->identifier.string.data, n->identifier.string.length);
-	case UA_NODEIDTYPE_GUID:
-		return hash_array((UA_Byte *)&(n->identifier.guid), sizeof(UA_Guid));
-	case UA_NODEIDTYPE_BYTESTRING:
-		return hash_array((UA_Byte *)n->identifier.byteString.data, n->identifier.byteString.length);
-	default:
-		return 0;
-	}
+    switch(n->identifierType) {
+    case UA_NODEIDTYPE_NUMERIC:
+        /*  Knuth's multiplicative hashing */
+        return n->identifier.numeric * 2654435761;   // mod(2^32) is implicit
+
+    case UA_NODEIDTYPE_STRING:
+        return hash_array(n->identifier.string.data, n->identifier.string.length);
+
+    case UA_NODEIDTYPE_GUID:
+        return hash_array((UA_Byte *)&(n->identifier.guid), sizeof(UA_Guid));
+
+    case UA_NODEIDTYPE_BYTESTRING:
+        return hash_array((UA_Byte *)n->identifier.byteString.data, n->identifier.byteString.length);
+
+    default:
+        return 0;
+    }
 }
 
-static INLINE void clear_entry(UA_Namespace * ns, const UA_Node ** entry) {
-	const UA_Node *node;
-	if(entry == UA_NULL || *entry == UA_NULL)
-		return;
-
-	node = *entry;
-	switch (node->nodeClass) {
-	case UA_NODECLASS_OBJECT:
-		UA_ObjectNode_delete((UA_ObjectNode *) node);
-		break;
-	case UA_NODECLASS_VARIABLE:
-		UA_VariableNode_delete((UA_VariableNode *) node);
-		break;
-	case UA_NODECLASS_METHOD:
-		UA_MethodNode_delete((UA_MethodNode *) node);
-		break;
-	case UA_NODECLASS_OBJECTTYPE:
-		UA_ObjectTypeNode_delete((UA_ObjectTypeNode *) node);
-		break;
-	case UA_NODECLASS_VARIABLETYPE:
-		UA_VariableTypeNode_delete((UA_VariableTypeNode *) node);
-		break;
-	case UA_NODECLASS_REFERENCETYPE:
-		UA_ReferenceTypeNode_delete((UA_ReferenceTypeNode *) node);
-		break;
-	case UA_NODECLASS_DATATYPE:
-		UA_DataTypeNode_delete((UA_DataTypeNode *) node);
-		break;
-	case UA_NODECLASS_VIEW:
-		UA_ViewNode_delete((UA_ViewNode *) node);
-		break;
-	default:
-		break;
-	}
-	entry = UA_NULL;
-	ns->count--;
+static INLINE void clear_entry(UA_Namespace *ns, const UA_Node **entry) {
+    const UA_Node *node;
+    if(entry == UA_NULL || *entry == UA_NULL)
+        return;
+
+    node = *entry;
+    switch(node->nodeClass) {
+    case UA_NODECLASS_OBJECT:
+        UA_ObjectNode_delete((UA_ObjectNode *)node);
+        break;
+
+    case UA_NODECLASS_VARIABLE:
+        UA_VariableNode_delete((UA_VariableNode *)node);
+        break;
+
+    case UA_NODECLASS_METHOD:
+        UA_MethodNode_delete((UA_MethodNode *)node);
+        break;
+
+    case UA_NODECLASS_OBJECTTYPE:
+        UA_ObjectTypeNode_delete((UA_ObjectTypeNode *)node);
+        break;
+
+    case UA_NODECLASS_VARIABLETYPE:
+        UA_VariableTypeNode_delete((UA_VariableTypeNode *)node);
+        break;
+
+    case UA_NODECLASS_REFERENCETYPE:
+        UA_ReferenceTypeNode_delete((UA_ReferenceTypeNode *)node);
+        break;
+
+    case UA_NODECLASS_DATATYPE:
+        UA_DataTypeNode_delete((UA_DataTypeNode *)node);
+        break;
+
+    case UA_NODECLASS_VIEW:
+        UA_ViewNode_delete((UA_ViewNode *)node);
+        break;
+
+    default:
+        break;
+    }
+    entry = UA_NULL;
+    ns->count--;
 }
 
 /* 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 UA_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);
-	const UA_Node **e = &ns->entries[index];
-
-	if(*e == UA_NULL) {
-		*entry = e;
-		return UA_ERROR;
-	}
-
-	if(UA_NodeId_equal(&(*e)->nodeId, nodeid) == UA_EQUAL) {
-		*entry = e;
-		return UA_SUCCESS;
-	}
-
-	hash_t hash2 = mod2(h, size);
-	for(;;) {
-		index += hash2;
-		if(index >= size)
-			index -= size;
-
-		e = &ns->entries[index];
-
-		if(*e == UA_NULL) {
-			*entry = e;
-			return UA_ERROR;
-		}
-
-		if(UA_NodeId_equal(&(*e)->nodeId, nodeid) == UA_EQUAL) {
-			*entry = e;
-			return UA_SUCCESS;
-		}
-	}
-
-	/* NOTREACHED */
-	return UA_SUCCESS;
+static INLINE UA_Int32 find_entry(const UA_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);
+    const UA_Node **e     = &ns->entries[index];
+
+    if(*e == UA_NULL) {
+        *entry = e;
+        return UA_ERROR;
+    }
+
+    if(UA_NodeId_equal(&(*e)->nodeId, nodeid) == UA_EQUAL) {
+        *entry = e;
+        return UA_SUCCESS;
+    }
+
+    hash_t hash2 = mod2(h, size);
+    for(;;) {
+        index += hash2;
+        if(index >= size)
+            index -= size;
+
+        e = &ns->entries[index];
+
+        if(*e == UA_NULL) {
+            *entry = e;
+            return UA_ERROR;
+        }
+
+        if(UA_NodeId_equal(&(*e)->nodeId, nodeid) == UA_EQUAL) {
+            *entry = e;
+            return UA_SUCCESS;
+        }
+    }
+
+    /* NOTREACHED */
+    return UA_SUCCESS;
 }
 
 /* The following function changes size of memory allocated for the entries and
    repeatedly inserts the table elements. The occupancy of the table after the
    call will be about 50%. If memory allocation failures occur, this function
    will return UA_ERROR. */
-static UA_Int32 expand(UA_Namespace * ns) {
-	const UA_Node **nentries;
-	int32_t nsize;
-	UA_UInt32 nindex;
-
-	const UA_Node **oentries = ns->entries;
-	int32_t osize = ns->size;
-	const UA_Node **olimit = &oentries[osize];
-	int32_t count = ns->count;
-
-	/* Resize only when table after removal of unused elements is either too full or too empty.  */
-	if(count * 2 < osize && (count * 8 > osize || osize <= 32)) {
-		return UA_SUCCESS;
-	}
-
-	nindex = higher_prime_index(count * 2);
-	nsize = primes[nindex];
-
-	if(UA_alloc((void **)&nentries, sizeof(UA_Node *) * nsize) != UA_SUCCESS)
-		return UA_ERR_NO_MEMORY;
-
-	memset(nentries, 0, nsize * sizeof(UA_Node *));
-	ns->entries = nentries;
-	ns->size = nsize;
-	ns->sizePrimeIndex = nindex;
-
-	const UA_Node **p = oentries;
-	do {
-		if(*p != UA_NULL) {
-			const UA_Node **e;
-			find_entry(ns, &(*p)->nodeId, &e);	/* We know this returns an empty entry here */
-			*e = *p;
-		}
-		p++;
-	} while(p < olimit);
-
-	UA_free(oentries);
-	return UA_SUCCESS;
+static UA_Int32 expand(UA_Namespace *ns) {
+    const UA_Node **nentries;
+    int32_t nsize;
+    UA_UInt32       nindex;
+
+    const UA_Node **oentries = ns->entries;
+    int32_t osize = ns->size;
+    const UA_Node **olimit   = &oentries[osize];
+    int32_t count = ns->count;
+
+    /* Resize only when table after removal of unused elements is either too full or too empty.  */
+    if(count * 2 < osize && (count * 8 > osize || osize <= 32))
+        return UA_SUCCESS;
+
+    nindex = higher_prime_index(count * 2);
+    nsize  = primes[nindex];
+
+    if(UA_alloc((void **)&nentries, sizeof(UA_Node *) * nsize) != UA_SUCCESS)
+        return UA_ERR_NO_MEMORY;
+
+    memset(nentries, 0, nsize * sizeof(UA_Node *));
+    ns->entries = nentries;
+    ns->size    = nsize;
+    ns->sizePrimeIndex = nindex;
+
+    const UA_Node **p = oentries;
+    do {
+        if(*p != UA_NULL) {
+            const UA_Node **e;
+            find_entry(ns, &(*p)->nodeId, &e);  /* We know this returns an empty entry here */
+            *e = *p;
+        }
+        p++;
+    } while(p < olimit);
+
+    UA_free(oentries);
+    return UA_SUCCESS;
 }
 
 /**********************/
 /* Exported functions */
 /**********************/
 
-UA_Int32 UA_Namespace_new(UA_Namespace ** result) {
-	UA_Namespace *ns;
-	UA_UInt32 sizePrimeIndex, size;
-	if(UA_alloc((void **)&ns, sizeof(UA_Namespace)) != UA_SUCCESS)
-		return UA_ERR_NO_MEMORY;
-
-	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;
-	}
-
-	/* set entries to zero */
-	memset(ns->entries, 0, size * sizeof(UA_Node *));
-
-	*ns = (UA_Namespace) {ns->entries, size, 0, sizePrimeIndex};
-	*result = ns;
-	return UA_SUCCESS;
+UA_Int32 UA_Namespace_new(UA_Namespace **result) {
+    UA_Namespace *ns;
+    UA_UInt32     sizePrimeIndex, size;
+    if(UA_alloc((void **)&ns, sizeof(UA_Namespace)) != UA_SUCCESS)
+        return UA_ERR_NO_MEMORY;
+
+    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;
+    }
+
+    /* set entries to zero */
+    memset(ns->entries, 0, size * sizeof(UA_Node *));
+
+    *ns     = (UA_Namespace) {ns->entries, size, 0, sizePrimeIndex };
+    *result = ns;
+    return UA_SUCCESS;
 }
 
-UA_Int32 UA_Namespace_delete(UA_Namespace * ns) {
-	UA_UInt32 size = ns->size;
-	const UA_Node **entries = ns->entries;
+UA_Int32 UA_Namespace_delete(UA_Namespace *ns) {
+    UA_UInt32       size    = ns->size;
+    const UA_Node **entries = ns->entries;
 
-	for(UA_UInt32 i = 0; i < size; i++)
-		clear_entry(ns, &entries[i]);
-	
-	UA_free(ns->entries);
-	UA_free(ns);
-	return UA_SUCCESS;
+    for(UA_UInt32 i = 0;i < size;i++)
+        clear_entry(ns, &entries[i]);
+
+    UA_free(ns->entries);
+    UA_free(ns);
+    return UA_SUCCESS;
 }
 
 UA_Int32 UA_Namespace_insert(UA_Namespace *ns, UA_Node **node, UA_Byte flags) {
-	if(ns == UA_NULL || node == UA_NULL || *node == UA_NULL)
-		return UA_ERROR;
-	
-	if(ns->size * 3 <= ns->count * 4) {
-		if(expand(ns) != UA_SUCCESS)
-			return UA_ERROR;
-	}
-
-	const UA_Node ** entry;
-	UA_Int32 found = find_entry(ns, &(*node)->nodeId, &entry);
-
-	if(flags & UA_NAMESPACE_INSERT_UNIQUE) {
-		if(found == UA_SUCCESS)
-			return UA_ERROR;	/* There is already an entry for that nodeid */
-		else
-			*entry = *node;
-	} else {
-		if(found == UA_SUCCESS)
-			clear_entry(ns, entry);
-		*entry = *node;
-	}
-
-	if(!(flags & UA_NAMESPACE_INSERT_GETMANAGED))
-		*node = UA_NULL;
-	
-	ns->count++;
-	return UA_SUCCESS;
+    if(ns == UA_NULL || node == UA_NULL || *node == UA_NULL)
+        return UA_ERROR;
+
+    if(ns->size * 3 <= ns->count * 4) {
+        if(expand(ns) != UA_SUCCESS)
+            return UA_ERROR;
+    }
+
+    const UA_Node **entry;
+    UA_Int32 found = find_entry(ns, &(*node)->nodeId, &entry);
+
+    if(flags & UA_NAMESPACE_INSERT_UNIQUE) {
+        if(found == UA_SUCCESS)
+            return UA_ERROR;    /* There is already an entry for that nodeid */
+        else
+            *entry = *node;
+    } else {
+        if(found == UA_SUCCESS)
+            clear_entry(ns, entry);
+        *entry = *node;
+    }
+
+    if(!(flags & UA_NAMESPACE_INSERT_GETMANAGED))
+        *node = UA_NULL;
+
+    ns->count++;
+    return UA_SUCCESS;
 }
 
 UA_Int32 UA_Namespace_get(const UA_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(ns == UA_NULL || nodeid == UA_NULL || managedNode == UA_NULL)
+        return UA_ERROR;
 
-	if(find_entry(ns, nodeid, &entry) != UA_SUCCESS)
-		return UA_ERROR;
+    if(find_entry(ns, nodeid, &entry) != UA_SUCCESS)
+        return UA_ERROR;
 
-	*managedNode = *entry;
-	return UA_SUCCESS;
+    *managedNode = *entry;
+    return UA_SUCCESS;
 }
 
-UA_Int32 UA_Namespace_remove(UA_Namespace * ns, const UA_NodeId * nodeid) {
-	const UA_Node **entry;
-	if(find_entry(ns, nodeid, &entry) != UA_SUCCESS)
-		return UA_ERROR;
+UA_Int32 UA_Namespace_remove(UA_Namespace *ns, const UA_NodeId *nodeid) {
+    const UA_Node **entry;
+    if(find_entry(ns, nodeid, &entry) != UA_SUCCESS)
+        return UA_ERROR;
 
-	// Check before if deleting the node makes the UA_Namespace inconsistent.
-	clear_entry(ns, entry);
+    // Check before if deleting the node makes the UA_Namespace inconsistent.
+    clear_entry(ns, entry);
 
-	/* Downsize the hashmap if it is very empty */
-	if(ns->count * 8 < ns->size && ns->size > 32)
-		expand(ns);
+    /* Downsize the hashmap if it is very empty */
+    if(ns->count * 8 < ns->size && ns->size > 32)
+        expand(ns);
 
-	return UA_SUCCESS;
+    return UA_SUCCESS;
 }
 
-UA_Int32 UA_Namespace_iterate(const UA_Namespace * ns, UA_Namespace_nodeVisitor visitor) {
-	if(ns == UA_NULL || visitor == UA_NULL)
-		return UA_ERROR;
-	
-	for(UA_UInt32 i = 0; i < ns->size; i++) {
-		const UA_Node *node = ns->entries[i];
-		if(node != UA_NULL)
-			visitor(node);
-	}
-	return UA_SUCCESS;
+UA_Int32 UA_Namespace_iterate(const UA_Namespace *ns, UA_Namespace_nodeVisitor visitor) {
+    if(ns == UA_NULL || visitor == UA_NULL)
+        return UA_ERROR;
+
+    for(UA_UInt32 i = 0;i < ns->size;i++) {
+        const UA_Node *node = ns->entries[i];
+        if(node != UA_NULL)
+            visitor(node);
+    }
+    return UA_SUCCESS;
 }
 
 void UA_Namespace_releaseManagedNode(const UA_Node *managed) {
-	;
+    ;
 }

+ 5 - 5
src/server/ua_namespace.h

@@ -7,7 +7,7 @@
 
 /**
    @ingroup server
-   
+
    @defgroup namespace Namespace
 
    @brief The namespace is the central storage for nodes in the UA address
@@ -43,21 +43,21 @@ UA_Int32 UA_Namespace_delete(UA_Namespace *ns);
 UA_Int32 UA_Namespace_insert(UA_Namespace *ns, UA_Node **node, UA_Byte flags);
 
 /** @brief Remove a node from the namespace. Always succeeds, even if the node
-	was not found. */
+    was not found. */
 UA_Int32 UA_Namespace_remove(UA_Namespace *ns, const UA_NodeId *nodeid);
 
 /** @brief Retrieve a node (read-only) from the namespace. Nodes are immutable.
     They can only be replaced. After the Node is no longer used, the locked
     entry needs to be released. */
 UA_Int32 UA_Namespace_get(const UA_Namespace *ns, const UA_NodeId *nodeid,
-						  const UA_Node **managedNode);
+                          const UA_Node **managedNode);
 
 /** @brief Release a managed node. Do never insert a node that isn't stored in a
-	namespace. */
+    namespace. */
 void UA_Namespace_releaseManagedNode(const UA_Node *managed);
 
 /** @brief A function that can be evaluated on all entries in a namespace via
-	UA_Namespace_iterate. Note that the visitor is read-only on the nodes. */
+    UA_Namespace_iterate. Note that the visitor is read-only on the nodes. */
 typedef void (*UA_Namespace_nodeVisitor)(const UA_Node *node);
 
 /** @brief Iterate over all nodes in a namespace. */

+ 294 - 294
src/server/ua_namespace_concurrent.c

@@ -7,14 +7,14 @@
 
 #define ALIVE_BIT (1 << 15) /* Alive bit in the readcount */
 typedef struct UA_Namespace_Entry {
-	struct cds_lfht_node htn; /* contains next-ptr for urcu-hashmap */
-	struct rcu_head rcu_head; /* For call-rcu */
-	UA_UInt16 readcount;      /* Counts the amount of readers on it [alive-bit, 15 counter-bits] */
-	UA_Node   node;           /* Might be cast from any _bigger_ UA_Node* type. Allocate enough memory! */
+    struct cds_lfht_node htn;      /* contains next-ptr for urcu-hashmap */
+    struct rcu_head      rcu_head; /* For call-rcu */
+    UA_UInt16 readcount;           /* Counts the amount of readers on it [alive-bit, 15 counter-bits] */
+    UA_Node   node;                /* Might be cast from any _bigger_ UA_Node* type. Allocate enough memory! */
 } UA_Namespace_Entry;
 
 struct UA_Namespace {
-	struct cds_lfht *ht; /* Hash table */
+    struct cds_lfht *ht; /* Hash table */
 };
 
 /********/
@@ -25,73 +25,73 @@ typedef UA_UInt32 hash_t;
 
 /* 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 const uint32_t c1 = 0xcc9e2d51;
-	static const uint32_t c2 = 0x1b873593;
-	static const uint32_t r1 = 15;
-	static const uint32_t r2 = 13;
-	static const uint32_t m  = 5;
-	static const uint32_t n  = 0xe6546b64;
-	hash_t hash = len;
-
-	if(data == UA_NULL) return 0;
-
-	const int32_t   nblocks = len / 4;
-	const uint32_t *blocks  = (const uint32_t *)data;
-	for(int32_t i = 0;i < nblocks;i++) {
-		uint32_t k = blocks[i];
-		k    *= c1;
-		k     = (k << r1) | (k >> (32 - r1));
-		k    *= c2;
-		hash ^= k;
-		hash  = ((hash << r2) | (hash >> (32 - r2))) * m + n;
-	}
-
-	const uint8_t *tail = (const uint8_t *)(data + nblocks * 4);
-	uint32_t       k1   = 0;
-
-	switch(len & 3) {
-	case 3:
-		k1 ^= tail[2] << 16;
-
-	case 2:
-		k1 ^= tail[1] << 8;
-
-	case 1:
-		k1   ^= tail[0];
-		k1   *= c1;
-		k1    = (k1 << r1) | (k1 >> (32 - r1));
-		k1   *= c2;
-		hash ^= k1;
-	}
-
-	hash ^= len;
-	hash ^= (hash >> 16);
-	hash *= 0x85ebca6b;
-	hash ^= (hash >> 13);
-	hash *= 0xc2b2ae35;
-	hash ^= (hash >> 16);
-
-	return hash;
+    static const uint32_t c1 = 0xcc9e2d51;
+    static const uint32_t c2 = 0x1b873593;
+    static const uint32_t r1 = 15;
+    static const uint32_t r2 = 13;
+    static const uint32_t m  = 5;
+    static const uint32_t n  = 0xe6546b64;
+    hash_t hash = len;
+
+    if(data == UA_NULL) return 0;
+
+    const int32_t   nblocks = len / 4;
+    const uint32_t *blocks  = (const uint32_t *)data;
+    for(int32_t i = 0;i < nblocks;i++) {
+        uint32_t k = blocks[i];
+        k    *= c1;
+        k     = (k << r1) | (k >> (32 - r1));
+        k    *= c2;
+        hash ^= k;
+        hash  = ((hash << r2) | (hash >> (32 - r2))) * m + n;
+    }
+
+    const uint8_t *tail = (const uint8_t *)(data + nblocks * 4);
+    uint32_t       k1   = 0;
+
+    switch(len & 3) {
+    case 3:
+        k1 ^= tail[2] << 16;
+
+    case 2:
+        k1 ^= tail[1] << 8;
+
+    case 1:
+        k1   ^= tail[0];
+        k1   *= c1;
+        k1    = (k1 << r1) | (k1 >> (32 - r1));
+        k1   *= c2;
+        hash ^= k1;
+    }
+
+    hash ^= len;
+    hash ^= (hash >> 16);
+    hash *= 0x85ebca6b;
+    hash ^= (hash >> 13);
+    hash *= 0xc2b2ae35;
+    hash ^= (hash >> 16);
+
+    return hash;
 }
 
 static inline hash_t hash(const UA_NodeId *n) {
-	switch(n->identifierType) {
-	case UA_NODEIDTYPE_NUMERIC:
-		/*  Knuth's multiplicative hashing */
-		return n->identifier.numeric * 2654435761;   // mod(2^32) is implicit
+    switch(n->identifierType) {
+    case UA_NODEIDTYPE_NUMERIC:
+        /*  Knuth's multiplicative hashing */
+        return n->identifier.numeric * 2654435761;   // mod(2^32) is implicit
 
-	case UA_NODEIDTYPE_STRING:
-		return hash_array(n->identifier.string.data, n->identifier.string.length);
+    case UA_NODEIDTYPE_STRING:
+        return hash_array(n->identifier.string.data, n->identifier.string.length);
 
-	case UA_NODEIDTYPE_GUID:
-		return hash_array((UA_Byte *)&(n->identifier.guid), sizeof(UA_Guid));
+    case UA_NODEIDTYPE_GUID:
+        return hash_array((UA_Byte *)&(n->identifier.guid), sizeof(UA_Guid));
 
-	case UA_NODEIDTYPE_BYTESTRING:
-		return hash_array((UA_Byte *)n->identifier.byteString.data, n->identifier.byteString.length);
+    case UA_NODEIDTYPE_BYTESTRING:
+        return hash_array((UA_Byte *)n->identifier.byteString.data, n->identifier.byteString.length);
 
-	default:
-		return 0;
-	}
+    default:
+        return 0;
+    }
 }
 
 /*************/
@@ -99,50 +99,50 @@ static inline hash_t hash(const UA_NodeId *n) {
 /*************/
 
 static inline void node_deleteMembers(const UA_Node *node) {
-	switch(node->nodeClass) {
-	case UA_NODECLASS_OBJECT:
-		UA_ObjectNode_deleteMembers((UA_ObjectNode *)node);
-		break;
-
-	case UA_NODECLASS_VARIABLE:
-		UA_VariableNode_deleteMembers((UA_VariableNode *)node);
-		break;
-
-	case UA_NODECLASS_METHOD:
-		UA_MethodNode_deleteMembers((UA_MethodNode *)node);
-		break;
-
-	case UA_NODECLASS_OBJECTTYPE:
-		UA_ObjectTypeNode_deleteMembers((UA_ObjectTypeNode *)node);
-		break;
-
-	case UA_NODECLASS_VARIABLETYPE:
-		UA_VariableTypeNode_deleteMembers((UA_VariableTypeNode *)node);
-		break;
-
-	case UA_NODECLASS_REFERENCETYPE:
-		UA_ReferenceTypeNode_deleteMembers((UA_ReferenceTypeNode *)node);
-		break;
-
-	case UA_NODECLASS_DATATYPE:
-		UA_DataTypeNode_deleteMembers((UA_DataTypeNode *)node);
-		break;
-
-	case UA_NODECLASS_VIEW:
-		UA_ViewNode_deleteMembers((UA_ViewNode *)node);
-		break;
-
-	default:
-		break;
-	}
+    switch(node->nodeClass) {
+    case UA_NODECLASS_OBJECT:
+        UA_ObjectNode_deleteMembers((UA_ObjectNode *)node);
+        break;
+
+    case UA_NODECLASS_VARIABLE:
+        UA_VariableNode_deleteMembers((UA_VariableNode *)node);
+        break;
+
+    case UA_NODECLASS_METHOD:
+        UA_MethodNode_deleteMembers((UA_MethodNode *)node);
+        break;
+
+    case UA_NODECLASS_OBJECTTYPE:
+        UA_ObjectTypeNode_deleteMembers((UA_ObjectTypeNode *)node);
+        break;
+
+    case UA_NODECLASS_VARIABLETYPE:
+        UA_VariableTypeNode_deleteMembers((UA_VariableTypeNode *)node);
+        break;
+
+    case UA_NODECLASS_REFERENCETYPE:
+        UA_ReferenceTypeNode_deleteMembers((UA_ReferenceTypeNode *)node);
+        break;
+
+    case UA_NODECLASS_DATATYPE:
+        UA_DataTypeNode_deleteMembers((UA_DataTypeNode *)node);
+        break;
+
+    case UA_NODECLASS_VIEW:
+        UA_ViewNode_deleteMembers((UA_ViewNode *)node);
+        break;
+
+    default:
+        break;
+    }
 }
 
 /* We are in a rcu_read lock. So the node will not be freed under our feet. */
 static int compare(struct cds_lfht_node *htn, const void *orig) {
-	UA_NodeId *origid = (UA_NodeId*)orig;
-	UA_NodeId   *newid  = &((UA_Namespace_Entry *)htn)->node.nodeId; /* The htn is first in the entry structure. */
+    UA_NodeId *origid = (UA_NodeId *)orig;
+    UA_NodeId *newid  = &((UA_Namespace_Entry *)htn)->node.nodeId;   /* The htn is first in the entry structure. */
 
-	return UA_NodeId_equal(newid, origid) == UA_EQUAL;
+    return UA_NodeId_equal(newid, origid) == UA_EQUAL;
 }
 
 /* The entry was removed from the hashtable. No more readers can get it. Since
@@ -150,221 +150,221 @@ static int compare(struct cds_lfht_node *htn, const void *orig) {
    section) increased the readcount, we only need to wait for the readcount
    to reach zero. */
 static void markDead(struct rcu_head *head) {
-	UA_Namespace_Entry *entry = caa_container_of(head, UA_Namespace_Entry, rcu_head);
-	if(uatomic_sub_return(&entry->readcount, ALIVE_BIT) > 0)
-		return;
+    UA_Namespace_Entry *entry = caa_container_of(head, UA_Namespace_Entry, rcu_head);
+    if(uatomic_sub_return(&entry->readcount, ALIVE_BIT) > 0)
+        return;
 
-	node_deleteMembers(&entry->node);
-	UA_free(entry);
-	return;
+    node_deleteMembers(&entry->node);
+    UA_free(entry);
+    return;
 }
 
 /* Free the entry if it is dead and nobody uses it anymore */
 void UA_Namespace_releaseManagedNode(const UA_Node *managed) {
-	if(managed == UA_NULL)
-		return;
-	
-	UA_Namespace_Entry *entry = caa_container_of(managed, UA_Namespace_Entry, node); // pointer to the first entry
-	if(uatomic_sub_return(&entry->readcount, 1) > 0)
-		return;
-
-	node_deleteMembers(managed);
-	UA_free(entry);
-	return;
+    if(managed == UA_NULL)
+        return;
+
+    UA_Namespace_Entry *entry = caa_container_of(managed, UA_Namespace_Entry, node); // pointer to the first entry
+    if(uatomic_sub_return(&entry->readcount, 1) > 0)
+        return;
+
+    node_deleteMembers(managed);
+    UA_free(entry);
+    return;
 }
 
 UA_Int32 UA_Namespace_new(UA_Namespace **result, UA_UInt32 namespaceIndex) {
-	UA_Namespace *ns;
-	if(UA_alloc((void **)&ns, sizeof(UA_Namespace)) != UA_SUCCESS)
-		return UA_ERR_NO_MEMORY;
-
-	/* 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_ERR_NO_MEMORY;
-	}
-
-	ns->namespaceIndex = namespaceIndex;
-	*result = ns;
-	return UA_SUCCESS;
+    UA_Namespace *ns;
+    if(UA_alloc((void **)&ns, sizeof(UA_Namespace)) != UA_SUCCESS)
+        return UA_ERR_NO_MEMORY;
+
+    /* 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_ERR_NO_MEMORY;
+    }
+
+    ns->namespaceIndex = namespaceIndex;
+    *result = ns;
+    return UA_SUCCESS;
 }
 
 UA_Int32 UA_Namespace_delete(UA_Namespace *ns) {
-	if(ns == UA_NULL)
-		return UA_ERROR;
-
-	struct cds_lfht *ht = ns->ht;
-	struct cds_lfht_iter iter;
-	struct cds_lfht_node *found_htn;
-
-	rcu_read_lock();
-	cds_lfht_first(ht, &iter);
-	while(iter.node != UA_NULL) {
-		found_htn = cds_lfht_iter_get_node(&iter);
-		if(!cds_lfht_del(ht, found_htn)) {
-			UA_Namespace_Entry *entry = caa_container_of(found_htn, UA_Namespace_Entry, htn);
-			call_rcu(&entry->rcu_head, markDead);
-		}
-		cds_lfht_next(ht, &iter);
-	}
-	rcu_read_unlock();
-
-	if(!cds_lfht_destroy(ht, UA_NULL)) {
-		UA_free(ns);
-		return UA_SUCCESS;
-	}
-	else
-		return UA_ERROR;
+    if(ns == UA_NULL)
+        return UA_ERROR;
+
+    struct cds_lfht      *ht = ns->ht;
+    struct cds_lfht_iter  iter;
+    struct cds_lfht_node *found_htn;
+
+    rcu_read_lock();
+    cds_lfht_first(ht, &iter);
+    while(iter.node != UA_NULL) {
+        found_htn = cds_lfht_iter_get_node(&iter);
+        if(!cds_lfht_del(ht, found_htn)) {
+            UA_Namespace_Entry *entry = caa_container_of(found_htn, UA_Namespace_Entry, htn);
+            call_rcu(&entry->rcu_head, markDead);
+        }
+        cds_lfht_next(ht, &iter);
+    }
+    rcu_read_unlock();
+
+    if(!cds_lfht_destroy(ht, UA_NULL)) {
+        UA_free(ns);
+        return UA_SUCCESS;
+    }else
+        return UA_ERROR;
 }
 
 UA_Int32 UA_Namespace_insert(UA_Namespace *ns, UA_Node **node, UA_Byte flags) {
-	if(ns == UA_NULL || node == UA_NULL || *node == UA_NULL || (*node)->nodeId.namespaceIndex != ns->namespaceIndex)
-		return UA_ERROR;
-
-	UA_UInt32 nodesize;
-	/* Copy the node into the entry. Then reset the original node. It shall no longer be used. */
-	switch((*node)->nodeClass) {
-	case UA_NODECLASS_OBJECT:
-		nodesize = sizeof(UA_ObjectNode);
-		break;
-
-	case UA_NODECLASS_VARIABLE:
-		nodesize = sizeof(UA_VariableNode);
-		break;
-
-	case UA_NODECLASS_METHOD:
-		nodesize = sizeof(UA_MethodNode);
-		break;
-
-	case UA_NODECLASS_OBJECTTYPE:
-		nodesize = sizeof(UA_ObjectTypeNode);
-		break;
-
-	case UA_NODECLASS_VARIABLETYPE:
-		nodesize = sizeof(UA_VariableTypeNode);
-		break;
-
-	case UA_NODECLASS_REFERENCETYPE:
-		nodesize = sizeof(UA_ReferenceTypeNode);
-		break;
-
-	case UA_NODECLASS_DATATYPE:
-		nodesize = sizeof(UA_DataTypeNode);
-		break;
-
-	case UA_NODECLASS_VIEW:
-		nodesize = sizeof(UA_ViewNode);
-		break;
-
-	default:
-		return UA_ERROR;
-	}
-
-	UA_Namespace_Entry *entry;
-	if(UA_alloc((void **)&entry, sizeof(UA_Namespace_Entry) - sizeof(UA_Node) + nodesize))
-		return UA_ERR_NO_MEMORY;
-	memcpy(&entry->node, *node, nodesize);
-
-	cds_lfht_node_init(&entry->htn);
-	entry->readcount = ALIVE_BIT;
-	if(flags & UA_NAMESPACE_INSERT_GETMANAGED)
-		entry->readcount++;
-
-	hash_t nhash = hash(&(*node)->nodeId);
-	struct cds_lfht_node *result;
-	if(flags & UA_NAMESPACE_INSERT_UNIQUE) {
-		rcu_read_lock();
-		result = cds_lfht_add_unique(ns->ht, nhash, compare, &entry->node.nodeId, &entry->htn);
-		rcu_read_unlock();
-
-		/* If the nodeid exists already */
-		if(result != &entry->htn) {
-			UA_free(entry);
-			return UA_ERROR;     // TODO: define a UA_EXISTS_ALREADY
-		}
-	} else {
-		rcu_read_lock();
-		result = cds_lfht_add_replace(ns->ht, nhash, compare, &(*node)->nodeId, &entry->htn);
-		/* If an entry got replaced, mark it as dead. */
-		if(result) {
-			UA_Namespace_Entry *entry = caa_container_of(result, UA_Namespace_Entry, htn);
-			call_rcu(&entry->rcu_head, markDead);      /* Queue this for the next time when no readers are on the entry.*/
-		}
-		rcu_read_unlock();
-	}
-
-	UA_free((UA_Node*)*node);     /* The old node is replaced by a managed node. */
-	if(flags & UA_NAMESPACE_INSERT_GETMANAGED)
-		*node = &entry->node;
-	else
-		*node = UA_NULL;
-
-	return UA_SUCCESS;
+    if(ns == UA_NULL || node == UA_NULL || *node == UA_NULL || (*node)->nodeId.namespaceIndex !=
+       ns->namespaceIndex)
+        return UA_ERROR;
+
+    UA_UInt32 nodesize;
+    /* Copy the node into the entry. Then reset the original node. It shall no longer be used. */
+    switch((*node)->nodeClass) {
+    case UA_NODECLASS_OBJECT:
+        nodesize = sizeof(UA_ObjectNode);
+        break;
+
+    case UA_NODECLASS_VARIABLE:
+        nodesize = sizeof(UA_VariableNode);
+        break;
+
+    case UA_NODECLASS_METHOD:
+        nodesize = sizeof(UA_MethodNode);
+        break;
+
+    case UA_NODECLASS_OBJECTTYPE:
+        nodesize = sizeof(UA_ObjectTypeNode);
+        break;
+
+    case UA_NODECLASS_VARIABLETYPE:
+        nodesize = sizeof(UA_VariableTypeNode);
+        break;
+
+    case UA_NODECLASS_REFERENCETYPE:
+        nodesize = sizeof(UA_ReferenceTypeNode);
+        break;
+
+    case UA_NODECLASS_DATATYPE:
+        nodesize = sizeof(UA_DataTypeNode);
+        break;
+
+    case UA_NODECLASS_VIEW:
+        nodesize = sizeof(UA_ViewNode);
+        break;
+
+    default:
+        return UA_ERROR;
+    }
+
+    UA_Namespace_Entry *entry;
+    if(UA_alloc((void **)&entry, sizeof(UA_Namespace_Entry) - sizeof(UA_Node) + nodesize))
+        return UA_ERR_NO_MEMORY;
+    memcpy(&entry->node, *node, nodesize);
+
+    cds_lfht_node_init(&entry->htn);
+    entry->readcount = ALIVE_BIT;
+    if(flags & UA_NAMESPACE_INSERT_GETMANAGED)
+        entry->readcount++;
+
+    hash_t nhash = hash(&(*node)->nodeId);
+    struct cds_lfht_node *result;
+    if(flags & UA_NAMESPACE_INSERT_UNIQUE) {
+        rcu_read_lock();
+        result = cds_lfht_add_unique(ns->ht, nhash, compare, &entry->node.nodeId, &entry->htn);
+        rcu_read_unlock();
+
+        /* If the nodeid exists already */
+        if(result != &entry->htn) {
+            UA_free(entry);
+            return UA_ERROR;     // TODO: define a UA_EXISTS_ALREADY
+        }
+    } else {
+        rcu_read_lock();
+        result = cds_lfht_add_replace(ns->ht, nhash, compare, &(*node)->nodeId, &entry->htn);
+        /* If an entry got replaced, mark it as dead. */
+        if(result) {
+            UA_Namespace_Entry *entry = caa_container_of(result, UA_Namespace_Entry, htn);
+            call_rcu(&entry->rcu_head, markDead);      /* Queue this for the next time when no readers are on the entry.*/
+        }
+        rcu_read_unlock();
+    }
+
+    UA_free((UA_Node *)*node);     /* The old node is replaced by a managed node. */
+    if(flags & UA_NAMESPACE_INSERT_GETMANAGED)
+        *node = &entry->node;
+    else
+        *node = UA_NULL;
+
+    return UA_SUCCESS;
 }
 
 UA_Int32 UA_Namespace_remove(UA_Namespace *ns, const UA_NodeId *nodeid) {
-	hash_t nhash = hash(nodeid);
-	struct cds_lfht_iter iter;
-
-	rcu_read_lock();
-	cds_lfht_lookup(ns->ht, nhash, compare, &nodeid, &iter);
-	struct cds_lfht_node *found_htn = cds_lfht_iter_get_node(&iter);
-
-	/* If this fails, then the node has already been removed. */
-	if(!found_htn || cds_lfht_del(ns->ht, found_htn) != 0) {
-		rcu_read_unlock();
-		return UA_ERROR;
-	}
-	
-	UA_Namespace_Entry *entry = caa_container_of(found_htn, UA_Namespace_Entry, htn);
-	call_rcu(&entry->rcu_head, markDead);
-	rcu_read_unlock();
-
-	return UA_SUCCESS;
+    hash_t nhash = hash(nodeid);
+    struct cds_lfht_iter iter;
+
+    rcu_read_lock();
+    cds_lfht_lookup(ns->ht, nhash, compare, &nodeid, &iter);
+    struct cds_lfht_node *found_htn = cds_lfht_iter_get_node(&iter);
+
+    /* If this fails, then the node has already been removed. */
+    if(!found_htn || cds_lfht_del(ns->ht, found_htn) != 0) {
+        rcu_read_unlock();
+        return UA_ERROR;
+    }
+
+    UA_Namespace_Entry *entry = caa_container_of(found_htn, UA_Namespace_Entry, htn);
+    call_rcu(&entry->rcu_head, markDead);
+    rcu_read_unlock();
+
+    return UA_SUCCESS;
 }
 
 UA_Int32 UA_Namespace_get(const UA_Namespace *ns, const UA_NodeId *nodeid, const UA_Node **managedNode) {
-	hash_t nhash     = hash(nodeid);
-	struct cds_lfht_iter iter;
+    hash_t nhash = hash(nodeid);
+    struct cds_lfht_iter iter;
 
-	rcu_read_lock();
-	cds_lfht_lookup(ns->ht, nhash, compare, nodeid, &iter);
-	UA_Namespace_Entry *found_entry = (UA_Namespace_Entry *)cds_lfht_iter_get_node(&iter);
+    rcu_read_lock();
+    cds_lfht_lookup(ns->ht, nhash, compare, nodeid, &iter);
+    UA_Namespace_Entry *found_entry = (UA_Namespace_Entry *)cds_lfht_iter_get_node(&iter);
 
-	if(!found_entry) {
-		rcu_read_unlock();
-		return UA_ERROR;  // TODO: UA_NOTFOUND
-	}
+    if(!found_entry) {
+        rcu_read_unlock();
+        return UA_ERROR;  // TODO: UA_NOTFOUND
+    }
 
-	/* This is done within a read-lock. The node will not be marked dead within a read-lock. */
-	uatomic_inc(&found_entry->readcount);
-	rcu_read_unlock();
+    /* This is done within a read-lock. The node will not be marked dead within a read-lock. */
+    uatomic_inc(&found_entry->readcount);
+    rcu_read_unlock();
 
-	*managedNode = &found_entry->node;
-	return UA_SUCCESS;
+    *managedNode = &found_entry->node;
+    return UA_SUCCESS;
 }
 
 UA_Int32 UA_Namespace_iterate(const UA_Namespace *ns, UA_Namespace_nodeVisitor visitor) {
-	if(ns == UA_NULL || visitor == UA_NULL)
-		return UA_ERROR;
-	
-	struct cds_lfht *ht = ns->ht;
-	struct cds_lfht_iter iter;
-
-	rcu_read_lock();
-	cds_lfht_first(ht, &iter);
-	while(iter.node != UA_NULL) {
-		UA_Namespace_Entry *found_entry = (UA_Namespace_Entry *)cds_lfht_iter_get_node(&iter);
-		uatomic_inc(&found_entry->readcount);
-		const UA_Node *node = &found_entry->node;
-		rcu_read_unlock();
-		visitor(node);
-		UA_Namespace_releaseManagedNode((UA_Node *)node);
-		rcu_read_lock();
-		cds_lfht_next(ht, &iter);
-	}
-	rcu_read_unlock();
-
-	return UA_SUCCESS;
+    if(ns == UA_NULL || visitor == UA_NULL)
+        return UA_ERROR;
+
+    struct cds_lfht     *ht = ns->ht;
+    struct cds_lfht_iter iter;
+
+    rcu_read_lock();
+    cds_lfht_first(ht, &iter);
+    while(iter.node != UA_NULL) {
+        UA_Namespace_Entry *found_entry = (UA_Namespace_Entry *)cds_lfht_iter_get_node(&iter);
+        uatomic_inc(&found_entry->readcount);
+        const UA_Node      *node = &found_entry->node;
+        rcu_read_unlock();
+        visitor(node);
+        UA_Namespace_releaseManagedNode((UA_Node *)node);
+        rcu_read_lock();
+        cds_lfht_next(ht, &iter);
+    }
+    rcu_read_unlock();
+
+    return UA_SUCCESS;
 }

+ 113 - 112
src/server/ua_securechannel_manager.c

@@ -2,138 +2,139 @@
 #include "util/ua_util.h"
 
 struct channel_list_entry {
-	UA_SecureChannel channel;
-	LIST_ENTRY(channel_list_entry) pointers;
+    UA_SecureChannel channel;
+    LIST_ENTRY(channel_list_entry) pointers;
 };
 
 struct UA_SecureChannelManager {
-	UA_Int32 maxChannelCount;
-	UA_DateTime maxChannelLifetime;
-	LIST_HEAD(channel_list, channel_list_entry) channels;
-	UA_MessageSecurityMode securityMode;
-	UA_String endpointUrl;
-	UA_DateTime channelLifeTime;
-	UA_Int32 lastChannelId;
-	UA_UInt32 lastTokenId;
+    UA_Int32    maxChannelCount;
+    UA_DateTime maxChannelLifetime;
+    LIST_HEAD(channel_list, channel_list_entry) channels;
+    UA_MessageSecurityMode securityMode;
+    UA_String   endpointUrl;
+    UA_DateTime channelLifeTime;
+    UA_Int32    lastChannelId;
+    UA_UInt32   lastTokenId;
 };
 
 UA_Int32 UA_SecureChannelManager_new(UA_SecureChannelManager **cm, UA_UInt32 maxChannelCount,
-							UA_UInt32 tokenLifetime, UA_UInt32 startChannelId,
-							UA_UInt32 startTokenId, UA_String *endpointUrl) {
-	UA_alloc((void**)cm,sizeof(UA_SecureChannelManager));
-	UA_SecureChannelManager *channelManager = *cm;
-	LIST_INIT(&channelManager->channels);
-	channelManager->lastChannelId = startChannelId;
-	channelManager->lastTokenId = startTokenId;
-	UA_String_copy(endpointUrl,&channelManager->endpointUrl);
-	channelManager->maxChannelLifetime = tokenLifetime;
-	channelManager->maxChannelCount = maxChannelCount;
-	return UA_SUCCESS;
+                                     UA_UInt32 tokenLifetime, UA_UInt32 startChannelId,
+                                     UA_UInt32 startTokenId, UA_String *endpointUrl) {
+    UA_alloc((void **)cm, sizeof(UA_SecureChannelManager));
+    UA_SecureChannelManager *channelManager = *cm;
+    LIST_INIT(&channelManager->channels);
+    channelManager->lastChannelId      = startChannelId;
+    channelManager->lastTokenId        = startTokenId;
+    UA_String_copy(endpointUrl, &channelManager->endpointUrl);
+    channelManager->maxChannelLifetime = tokenLifetime;
+    channelManager->maxChannelCount    = maxChannelCount;
+    return UA_SUCCESS;
 }
 
 UA_Int32 UA_SecureChannelManager_delete(UA_SecureChannelManager *cm) {
-	struct channel_list_entry *entry;
-	LIST_FOREACH(entry, &cm->channels, pointers) {
-		// deleting a securechannel means closing the connection
-		// delete the binaryconnction beforehand. so there is no pointer
-		// todo: unbind entry->channel.connection;
-		LIST_REMOVE(entry, pointers);
-		UA_SecureChannel_deleteMembers(&entry->channel);
-		UA_free(entry);
-	}
-	UA_String_deleteMembers(&cm->endpointUrl);
-	UA_free(cm);	
-	return UA_SUCCESS;
+    struct channel_list_entry *entry;
+    LIST_FOREACH(entry, &cm->channels, pointers) {
+        // deleting a securechannel means closing the connection
+        // delete the binaryconnction beforehand. so there is no pointer
+        // todo: unbind entry->channel.connection;
+        LIST_REMOVE(entry, pointers);
+        UA_SecureChannel_deleteMembers(&entry->channel);
+        UA_free(entry);
+    }
+    UA_String_deleteMembers(&cm->endpointUrl);
+    UA_free(cm);
+    return UA_SUCCESS;
 }
 
-UA_Int32 UA_SecureChannelManager_open(UA_SecureChannelManager *cm,
-									  UA_Connection *conn,
-									  const UA_OpenSecureChannelRequest* request,
-									  UA_OpenSecureChannelResponse* response) {
-	struct channel_list_entry *entry;
-	UA_alloc((void**)&entry, sizeof(struct channel_list_entry));
-
-	entry->channel.connection = conn;
-	entry->channel.securityToken.channelId = cm->lastChannelId++;
-	entry->channel.securityToken.tokenId = cm->lastTokenId++;
-	entry->channel.securityToken.createdAt = UA_DateTime_now();
-	entry->channel.securityToken.revisedLifetime =
-		request->requestedLifetime > cm->maxChannelLifetime ?
-		cm->maxChannelLifetime : request->requestedLifetime;
-
-	switch (request->securityMode) {
-	case UA_SECURITYMODE_INVALID:
-		printf("UA_SecureChannel_processOpenRequest - client demands invalid \n");
-		break;
-
-	case UA_SECURITYMODE_NONE:
-		UA_ByteString_copy(&request->clientNonce, &entry->channel.clientNonce);
-		entry->channel.clientAsymAlgSettings.receiverCertificateThumbprint.data = UA_NULL;
-		entry->channel.clientAsymAlgSettings.receiverCertificateThumbprint.length = -1;
-		entry->channel.clientAsymAlgSettings.senderCertificate.data = UA_NULL;
-		entry->channel.clientAsymAlgSettings.senderCertificate.length = -1;
-		break;
-
-	case UA_SECURITYMODE_SIGNANDENCRYPT:
-		printf("UA_SecureChannel_processOpenRequest - client demands signed & encrypted \n");
-		//TODO check if senderCertificate and ReceiverCertificateThumbprint are present
-		break;
-	}
-
-	UA_String_copycstring("http://opcfoundation.org/UA/SecurityPolicy#None",
-						  (UA_String*)&entry->channel.serverAsymAlgSettings.securityPolicyUri);
-	LIST_INSERT_HEAD(&cm->channels, entry, pointers);
-
-	response->serverProtocolVersion = 0;
-	UA_SecureChannel_generateNonce(&entry->channel.serverNonce);
-	UA_ByteString_copy(&entry->channel.serverNonce, &response->serverNonce);
-	UA_ChannelSecurityToken_copy(&entry->channel.securityToken, &response->securityToken);
-	
-	return UA_SUCCESS;
+UA_Int32 UA_SecureChannelManager_open(UA_SecureChannelManager           *cm,
+                                      UA_Connection                     *conn,
+                                      const UA_OpenSecureChannelRequest *request,
+                                      UA_OpenSecureChannelResponse      *response) {
+    struct channel_list_entry *entry;
+    UA_alloc((void **)&entry, sizeof(struct channel_list_entry));
+
+    entry->channel.connection = conn;
+    entry->channel.securityToken.channelId       = cm->lastChannelId++;
+    entry->channel.securityToken.tokenId         = cm->lastTokenId++;
+    entry->channel.securityToken.createdAt       = UA_DateTime_now();
+    entry->channel.securityToken.revisedLifetime =
+        request->requestedLifetime > cm->maxChannelLifetime ?
+        cm->maxChannelLifetime : request->requestedLifetime;
+
+    switch(request->securityMode) {
+    case UA_SECURITYMODE_INVALID:
+        printf("UA_SecureChannel_processOpenRequest - client demands invalid \n");
+        break;
+
+    case UA_SECURITYMODE_NONE:
+        UA_ByteString_copy(&request->clientNonce, &entry->channel.clientNonce);
+        entry->channel.clientAsymAlgSettings.receiverCertificateThumbprint.data   = UA_NULL;
+        entry->channel.clientAsymAlgSettings.receiverCertificateThumbprint.length = -1;
+        entry->channel.clientAsymAlgSettings.senderCertificate.data   = UA_NULL;
+        entry->channel.clientAsymAlgSettings.senderCertificate.length = -1;
+        break;
+
+    case UA_SECURITYMODE_SIGNANDENCRYPT:
+        printf("UA_SecureChannel_processOpenRequest - client demands signed & encrypted \n");
+        //TODO check if senderCertificate and ReceiverCertificateThumbprint are present
+        break;
+    }
+
+    UA_String_copycstring("http://opcfoundation.org/UA/SecurityPolicy#None",
+                          (UA_String *)&entry->channel.serverAsymAlgSettings.securityPolicyUri);
+    LIST_INSERT_HEAD(&cm->channels, entry, pointers);
+
+    response->serverProtocolVersion = 0;
+    UA_SecureChannel_generateNonce(&entry->channel.serverNonce);
+    UA_ByteString_copy(&entry->channel.serverNonce, &response->serverNonce);
+    UA_ChannelSecurityToken_copy(&entry->channel.securityToken, &response->securityToken);
+
+    return UA_SUCCESS;
 }
 
-UA_Int32 UA_SecureChannelManager_renew(UA_SecureChannelManager *cm,
-									   UA_Connection *conn,
-									   const UA_OpenSecureChannelRequest* request,
-									   UA_OpenSecureChannelResponse* response) {
+UA_Int32 UA_SecureChannelManager_renew(UA_SecureChannelManager           *cm,
+                                       UA_Connection                     *conn,
+                                       const UA_OpenSecureChannelRequest *request,
+                                       UA_OpenSecureChannelResponse      *response) {
 
-	UA_SecureChannel *channel = conn->channel;
-	if(channel == UA_NULL)
-		return UA_ERROR;
+    UA_SecureChannel *channel = conn->channel;
+    if(channel == UA_NULL)
+        return UA_ERROR;
 
 
-	// TODO write response
+    // TODO write response
 
-	channel->securityToken.createdAt = UA_DateTime_now(); // todo: is wanted?
-	channel->securityToken.revisedLifetime = request->requestedLifetime > cm->maxChannelLifetime ?
-		cm->maxChannelLifetime : request->requestedLifetime;
-	return UA_SUCCESS;
+    channel->securityToken.createdAt       = UA_DateTime_now(); // todo: is wanted?
+    channel->securityToken.revisedLifetime = request->requestedLifetime > cm->maxChannelLifetime ?
+                                             cm->maxChannelLifetime : request->requestedLifetime;
+    return UA_SUCCESS;
 }
 
-UA_Int32 UA_SecureChannelManager_get(UA_SecureChannelManager *cm, UA_UInt32 channelId, UA_SecureChannel **channel) {
-	struct channel_list_entry *entry;
-	LIST_FOREACH(entry, &cm->channels, pointers) {
-		if(entry->channel.securityToken.channelId == channelId) {
-			*channel = &entry->channel;
-			return UA_SUCCESS;
-		}
-	}
-	*channel = UA_NULL;
-	return UA_ERROR;
+UA_Int32 UA_SecureChannelManager_get(UA_SecureChannelManager *cm, UA_UInt32 channelId,
+                                     UA_SecureChannel **channel) {
+    struct channel_list_entry *entry;
+    LIST_FOREACH(entry, &cm->channels, pointers) {
+        if(entry->channel.securityToken.channelId == channelId) {
+            *channel = &entry->channel;
+            return UA_SUCCESS;
+        }
+    }
+    *channel = UA_NULL;
+    return UA_ERROR;
 }
 
 UA_Int32 UA_SecureChannelManager_close(UA_SecureChannelManager *cm, UA_UInt32 channelId) {
-	//TODO lock access
-	// TODO: close the binaryconnection if it is still open. So we dö not have stray pointers..
-	struct channel_list_entry *entry;
-	LIST_FOREACH(entry, &cm->channels, pointers) {
-		if(entry->channel.securityToken.channelId == channelId) {
-			UA_SecureChannel_deleteMembers(&entry->channel);
-			LIST_REMOVE(entry, pointers);
-			UA_free(entry);
-			return UA_SUCCESS;
-		}
-	}
-	//TODO notify server application that secureChannel has been closed part 6 - §7.1.4
-	return UA_ERROR;
+    //TODO lock access
+    // TODO: close the binaryconnection if it is still open. So we dö not have stray pointers..
+    struct channel_list_entry *entry;
+    LIST_FOREACH(entry, &cm->channels, pointers) {
+        if(entry->channel.securityToken.channelId == channelId) {
+            UA_SecureChannel_deleteMembers(&entry->channel);
+            LIST_REMOVE(entry, pointers);
+            UA_free(entry);
+            return UA_SUCCESS;
+        }
+    }
+    //TODO notify server application that secureChannel has been closed part 6 - §7.1.4
+    return UA_ERROR;
 }

+ 7 - 7
src/server/ua_securechannel_manager.h

@@ -8,17 +8,17 @@ struct UA_SecureChannelManager;
 typedef struct UA_SecureChannelManager UA_SecureChannelManager;
 
 UA_Int32 UA_SecureChannelManager_new(UA_SecureChannelManager **cm, UA_UInt32 maxChannelCount,
-									 UA_UInt32 tokenLifetime, UA_UInt32 startChannelId,
-									 UA_UInt32 startTokenId, UA_String *endpointUrl);
+                                     UA_UInt32 tokenLifetime, UA_UInt32 startChannelId,
+                                     UA_UInt32 startTokenId, UA_String *endpointUrl);
 UA_Int32 UA_SecureChannelManager_delete(UA_SecureChannelManager *cm);
 UA_Int32 UA_SecureChannelManager_open(UA_SecureChannelManager *cm, UA_Connection *conn,
-										const UA_OpenSecureChannelRequest* request,
-										UA_OpenSecureChannelResponse* response);
+                                      const UA_OpenSecureChannelRequest *request,
+                                      UA_OpenSecureChannelResponse *response);
 UA_Int32 UA_SecureChannelManager_renew(UA_SecureChannelManager *cm, UA_Connection *conn,
-									   const UA_OpenSecureChannelRequest* request,
-									   UA_OpenSecureChannelResponse* response);
+                                       const UA_OpenSecureChannelRequest *request,
+                                       UA_OpenSecureChannelResponse *response);
 UA_Int32 UA_SecureChannelManager_get(UA_SecureChannelManager *cm, UA_UInt32 channelId,
-									   UA_SecureChannel **channel);
+                                     UA_SecureChannel **channel);
 UA_Int32 UA_SecureChannelManager_close(UA_SecureChannelManager *cm, UA_UInt32 channelId);
 
 #endif /* UA_CHANNEL_MANAGER_H_ */

File diff suppressed because it is too large
+ 559 - 558
src/server/ua_server.c


+ 10 - 10
src/server/ua_server.h

@@ -10,25 +10,25 @@
 
 /**
    @defgroup server
-*/
+ */
 
 typedef struct UA_IndexedNamespace {
-	UA_UInt32 namespaceIndex;
-	UA_Namespace *namespace;
+    UA_UInt32 namespaceIndex;
+    UA_Namespace *namespace;
 } UA_IndexedNamespace;
 
 typedef struct UA_Server {
-	UA_ApplicationDescription description;
-	UA_SecureChannelManager *secureChannelManager;
-	UA_SessionManager *sessionManager;
-	UA_UInt32 namespacesSize;
-	UA_IndexedNamespace *namespaces;
-	UA_Logger logger;
+    UA_ApplicationDescription description;
+    UA_SecureChannelManager  *secureChannelManager;
+    UA_SessionManager   *sessionManager;
+    UA_UInt32 namespacesSize;
+    UA_IndexedNamespace *namespaces;
+    UA_Logger logger;
 } UA_Server;
 
 void UA_Server_init(UA_Server *server, UA_String *endpointUrl);
 UA_Int32 UA_Server_deleteMembers(UA_Server *server);
 UA_Int32 UA_Server_processBinaryMessage(UA_Server *server, UA_Connection *connection,
-										const UA_ByteString* msg);
+                                        const UA_ByteString *msg);
 
 #endif /* UA_SERVER_H_ */

+ 293 - 287
src/server/ua_server_binary.c

@@ -2,321 +2,327 @@
 #include "ua_services.h"
 #include "ua_statuscodes.h"
 
-static void processHello(UA_Connection *connection, const UA_ByteString* msg,
-						 UA_UInt32* pos) {
-	UA_UInt32 tmpPos = 0;
-	UA_OPCUATcpHelloMessage helloMessage;
-
-	if (connection->state != UA_CONNECTION_OPENING) {
-		// multiple HEL are not allowed
-		connection->close(connection->callbackHandle);
-		return;
-	}
-
-	UA_OPCUATcpHelloMessage_decodeBinary(msg,pos,&helloMessage);
-	connection->remoteConf.maxChunkCount = helloMessage.maxChunkCount;
-	connection->remoteConf.maxMessageSize = helloMessage.maxMessageSize;
-	connection->remoteConf.protocolVersion = helloMessage.protocolVersion;
-	connection->remoteConf.recvBufferSize = helloMessage.receiveBufferSize;
-	connection->remoteConf.sendBufferSize = helloMessage.sendBufferSize;
-
-	connection->state = UA_CONNECTION_ESTABLISHED;
-
-	// build acknowledge response
-	UA_OPCUATcpMessageHeader ackHeader;
-	ackHeader.messageType = UA_MESSAGETYPE_ACK;
-	ackHeader.isFinal = 'F';
-
-	UA_OPCUATcpAcknowledgeMessage ackMessage;
-	ackMessage.protocolVersion = connection->localConf.protocolVersion;
-	ackMessage.receiveBufferSize = connection->localConf.recvBufferSize;
-	ackMessage.sendBufferSize = connection->localConf.sendBufferSize;
-	ackMessage.maxMessageSize = connection->localConf.maxMessageSize;
-	ackMessage.maxChunkCount = connection->localConf.maxChunkCount;
-
-	ackHeader.messageSize = UA_OPCUATcpAcknowledgeMessage_calcSizeBinary(&ackMessage) +
-		UA_OPCUATcpMessageHeader_calcSizeBinary(&ackHeader);
-	UA_ByteString *ack_msg;
-	UA_alloc((void **)&ack_msg, sizeof(UA_ByteString));
-	UA_ByteString_newMembers(ack_msg, ackHeader.messageSize);
-	tmpPos = 0;
-	UA_OPCUATcpMessageHeader_encodeBinary(&ackHeader,ack_msg,&tmpPos);
-	UA_OPCUATcpAcknowledgeMessage_encodeBinary(&ackMessage, ack_msg,&tmpPos);
-	UA_ByteStringArray answer_buf = {.stringsSize = 1, .strings = ack_msg};
-	connection->write(connection->callbackHandle, &answer_buf);
-	UA_ByteString_delete(ack_msg);
+static void processHello(UA_Connection *connection, const UA_ByteString *msg,
+                         UA_UInt32 *pos) {
+    UA_UInt32 tmpPos = 0;
+    UA_OPCUATcpHelloMessage helloMessage;
+
+    if(connection->state != UA_CONNECTION_OPENING) {
+        // multiple HEL are not allowed
+        connection->close(connection->callbackHandle);
+        return;
+    }
+
+    UA_OPCUATcpHelloMessage_decodeBinary(msg, pos, &helloMessage);
+    connection->remoteConf.maxChunkCount   = helloMessage.maxChunkCount;
+    connection->remoteConf.maxMessageSize  = helloMessage.maxMessageSize;
+    connection->remoteConf.protocolVersion = helloMessage.protocolVersion;
+    connection->remoteConf.recvBufferSize  = helloMessage.receiveBufferSize;
+    connection->remoteConf.sendBufferSize  = helloMessage.sendBufferSize;
+
+    connection->state = UA_CONNECTION_ESTABLISHED;
+
+    // build acknowledge response
+    UA_OPCUATcpMessageHeader ackHeader;
+    ackHeader.messageType = UA_MESSAGETYPE_ACK;
+    ackHeader.isFinal     = 'F';
+
+    UA_OPCUATcpAcknowledgeMessage ackMessage;
+    ackMessage.protocolVersion   = connection->localConf.protocolVersion;
+    ackMessage.receiveBufferSize = connection->localConf.recvBufferSize;
+    ackMessage.sendBufferSize    = connection->localConf.sendBufferSize;
+    ackMessage.maxMessageSize    = connection->localConf.maxMessageSize;
+    ackMessage.maxChunkCount     = connection->localConf.maxChunkCount;
+
+    ackHeader.messageSize = UA_OPCUATcpAcknowledgeMessage_calcSizeBinary(&ackMessage) +
+                            UA_OPCUATcpMessageHeader_calcSizeBinary(&ackHeader);
+    UA_ByteString *ack_msg;
+    UA_alloc((void **)&ack_msg, sizeof(UA_ByteString));
+    UA_ByteString_newMembers(ack_msg, ackHeader.messageSize);
+    tmpPos = 0;
+    UA_OPCUATcpMessageHeader_encodeBinary(&ackHeader, ack_msg, &tmpPos);
+    UA_OPCUATcpAcknowledgeMessage_encodeBinary(&ackMessage, ack_msg, &tmpPos);
+    UA_ByteStringArray answer_buf = { .stringsSize = 1, .strings = ack_msg };
+    connection->write(connection->callbackHandle, &answer_buf);
+    UA_ByteString_delete(ack_msg);
 }
 
 static void processOpen(UA_Connection *connection, UA_Server *server,
-					   const UA_ByteString* msg, UA_UInt32* pos) {
-	UA_UInt32 secureChannelId;
-	if (connection->state != UA_CONNECTION_ESTABLISHED) {
-		if(connection->state == UA_CONNECTION_OPENING)
-			connection->close(connection->callbackHandle);
-		return;
-	}
-
-	UA_UInt32_decodeBinary(msg, pos, &secureChannelId);
-	// needs asym encoding for returning
-	// call the service!!!!
-	/* if(connection->channel != UA_NULL) { */
-	/* 	//create new channel */
-	/* 	SL_Channel *newChannel; */
-	/* 	retval |= SL_ChannelManager_generateChannel(cm, ) */
-	/* 	retval |= SL_ProcessOpenChannel(newChannel, server, msg, pos); */
-	/* 	retval |= SL_Channel_bind(newChannel, connection); */
-	/* 	return retval; */
-	/* } */
-	/* // channel already exists, renew token? */
-	/* retval |= SL_ProcessOpenChannel(channel, server, msg, pos); */
-	/* return retval; */
+                        const UA_ByteString *msg, UA_UInt32 *pos) {
+    UA_UInt32 secureChannelId;
+    if(connection->state != UA_CONNECTION_ESTABLISHED) {
+        if(connection->state == UA_CONNECTION_OPENING)
+            connection->close(connection->callbackHandle);
+        return;
+    }
+
+    UA_UInt32_decodeBinary(msg, pos, &secureChannelId);
+    // needs asym encoding for returning
+    // call the service!!!!
+    /* if(connection->channel != UA_NULL) { */
+    /*  //create new channel */
+    /*  SL_Channel *newChannel; */
+    /*  retval |= SL_ChannelManager_generateChannel(cm, ) */
+    /*  retval |= SL_ProcessOpenChannel(newChannel, server, msg, pos); */
+    /*  retval |= SL_Channel_bind(newChannel, connection); */
+    /*  return retval; */
+    /* } */
+    /* // channel already exists, renew token? */
+    /* retval |= SL_ProcessOpenChannel(channel, server, msg, pos); */
+    /* return retval; */
 }
 
-static void init_response_header(UA_RequestHeader const * p, UA_ResponseHeader * r) {
-	r->requestHandle = p->requestHandle;
-	r->serviceResult = UA_STATUSCODE_GOOD;
-	r->stringTableSize = 0;
-	r->timestamp = UA_DateTime_now();
+static void init_response_header(UA_RequestHeader const *p, UA_ResponseHeader *r) {
+    r->requestHandle   = p->requestHandle;
+    r->serviceResult   = UA_STATUSCODE_GOOD;
+    r->stringTableSize = 0;
+    r->timestamp       = UA_DateTime_now();
 }
 
-#define CHECK_PROCESS(CODE, CLEANUP)								\
-	do {															\
-	if(CODE != UA_SUCCESS) {										\
-	    CLEANUP;                                                    \
-        goto clean_up;												\
-    } } while(0)
-
-#define INVOKE_SERVICE(TYPE) do {										\
-	UA_##TYPE##Request p;											\
-	UA_##TYPE##Response r;											\
-	UA_Session *session = UA_NULL;									\
-	CHECK_PROCESS(UA_##TYPE##Request_decodeBinary(msg, pos, &p),;);		\
-	UA_##TYPE##Response_init(&r);										\
-		init_response_header(&p.requestHeader, &r.responseHeader);		\
-	UA_SessionManager_getSessionByToken(server->sessionManager, &p.requestHeader.authenticationToken, \
-										&session);						\
-	DBG_VERBOSE(printf("Invoke Service: %s\n", #TYPE));					\
-	Service_##TYPE(server, session, &p, &r);							\
-	DBG_VERBOSE(printf("Finished Service: %s\n", #TYPE));				\
-	UA_ByteString_newMembers(&responseBuf.strings[1], UA_##TYPE##Response_calcSizeBinary(&r)); \
-	UA_##TYPE##Response_encodeBinary(&r, &responseBuf.strings[1], &sendOffset);	\
-	UA_##TYPE##Request_deleteMembers(&p);								\
-	UA_##TYPE##Response_deleteMembers(&r);								\
-	responseType = requestType.nodeId.identifier.numeric + 3;			\
-	} while(0)
+#define CHECK_PROCESS(CODE, CLEANUP) \
+    do {                             \
+        if(CODE != UA_SUCCESS) {     \
+            CLEANUP;                 \
+            goto clean_up;           \
+        } } while(0)
+
+#define INVOKE_SERVICE(TYPE) do {                                                                         \
+        UA_##TYPE##Request p;                                                                             \
+        UA_##TYPE##Response r;                                                                            \
+        UA_Session *session = UA_NULL;                                                                    \
+        CHECK_PROCESS(UA_##TYPE##Request_decodeBinary(msg, pos, &p),; );                                  \
+        UA_##TYPE##Response_init(&r);                                                                     \
+        init_response_header(&p.requestHeader, &r.responseHeader);                                        \
+        UA_SessionManager_getSessionByToken(server->sessionManager, &p.requestHeader.authenticationToken, \
+                                            &session);                                                    \
+        DBG_VERBOSE(printf("Invoke Service: %s\n", # TYPE));                                              \
+        Service_##TYPE(server, session, &p, &r);                                                          \
+        DBG_VERBOSE(printf("Finished Service: %s\n", # TYPE));                                            \
+        UA_ByteString_newMembers(&responseBuf.strings[1], UA_##TYPE##Response_calcSizeBinary(&r));        \
+        UA_##TYPE##Response_encodeBinary(&r, &responseBuf.strings[1], &sendOffset);                       \
+        UA_##TYPE##Request_deleteMembers(&p);                                                             \
+        UA_##TYPE##Response_deleteMembers(&r);                                                            \
+        responseType = requestType.nodeId.identifier.numeric + 3;                                         \
+} while(0)
 
 static void processMessage(UA_Connection *connection, UA_Server *server,
-						   const UA_ByteString* msg, UA_UInt32* pos) {
-	// 1) Read in the securechannel
-	UA_UInt32 secureChannelId;
-	UA_UInt32_decodeBinary(msg, pos, &secureChannelId);
-	UA_SecureChannel *channel;
- 	UA_SecureChannelManager_get(server->secureChannelManager, secureChannelId, &channel);
-
-	// 2) Read the security header
-	UA_UInt32 tokenId;
-	UA_UInt32_decodeBinary(msg, pos, &tokenId);
-	UA_SequenceHeader sequenceHeader;
-	CHECK_PROCESS(UA_SequenceHeader_decodeBinary(msg, pos, &sequenceHeader),;);
-	//UA_SecureChannel_checkSequenceNumber(channel,sequenceHeader.sequenceNumber);
-	//UA_SecureChannel_checkRequestId(channel,sequenceHeader.requestId);
-	
-	// 3) Read the nodeid of the request
-	UA_ExpandedNodeId requestType;
-	CHECK_PROCESS(UA_ExpandedNodeId_decodeBinary(msg, pos, &requestType),;);
-	if(requestType.nodeId.identifierType != UA_NODEIDTYPE_NUMERIC)
-		goto close_connection;
-
-	// 4) process the request
-	UA_ByteStringArray responseBuf;
-	UA_ByteStringArray_init(&responseBuf, 2);
-
-	UA_UInt32 responseType;
-
-	//subtract 2 for binary encoding
-	UA_UInt32 sendOffset = 0;
-	switch(requestType.nodeId.identifier.numeric - 2) {
-	case UA_GETENDPOINTSREQUEST_NS0: {
-		UA_GetEndpointsRequest p;
-		UA_GetEndpointsResponse r;
-		CHECK_PROCESS(UA_GetEndpointsRequest_decodeBinary(msg, pos, &p),;);
-		UA_GetEndpointsResponse_init(&r);
-		init_response_header(&p.requestHeader, &r.responseHeader);
-		Service_GetEndpoints(server, &p, &r);
-		UA_ByteString_newMembers(&responseBuf.strings[1],
-								 UA_GetEndpointsResponse_calcSizeBinary(&r));
-		UA_GetEndpointsResponse_encodeBinary(&r, &responseBuf.strings[1], &sendOffset);
-		UA_GetEndpointsRequest_deleteMembers(&p);
-		UA_GetEndpointsResponse_deleteMembers(&r);
-		responseType = requestType.nodeId.identifier.numeric + 3;
-		break;
-	}
-		
-	case UA_CREATESESSIONREQUEST_NS0: {
-		UA_CreateSessionRequest p;
-		UA_CreateSessionResponse r;
-		CHECK_PROCESS(UA_CreateSessionRequest_decodeBinary(msg, pos, &p),;);
-		UA_CreateSessionResponse_init(&r);
-		init_response_header(&p.requestHeader, &r.responseHeader);
-		Service_CreateSession(server,channel,  &p, &r);
-		UA_ByteString_newMembers(&responseBuf.strings[1],
-								 UA_CreateSessionResponse_calcSizeBinary(&r));
-		UA_CreateSessionResponse_encodeBinary(&r, &responseBuf.strings[1], &sendOffset);
-		UA_CreateSessionRequest_deleteMembers(&p);
-		UA_CreateSessionResponse_deleteMembers(&r);
-		responseType = requestType.nodeId.identifier.numeric + 3;
-		break;
-	}
-
-	case UA_ACTIVATESESSIONREQUEST_NS0:
-		INVOKE_SERVICE(ActivateSession);
-		break;
-
-	case UA_READREQUEST_NS0:
-		INVOKE_SERVICE(Read);
-		break;
-
-	case UA_WRITEREQUEST_NS0:
-		INVOKE_SERVICE(Write);
-		break;
-
-	case UA_BROWSEREQUEST_NS0:
-		INVOKE_SERVICE(Browse);
-		break;
-
-	case UA_CREATESUBSCRIPTIONREQUEST_NS0:
-		INVOKE_SERVICE(CreateSubscription);
-		break;
-
-	case UA_TRANSLATEBROWSEPATHSTONODEIDSREQUEST_NS0:
-		INVOKE_SERVICE(TranslateBrowsePathsToNodeIds);
-		break;
-		
-	case UA_PUBLISHREQUEST_NS0:
-		INVOKE_SERVICE(Publish);
-		break;
-
-	case UA_CREATEMONITOREDITEMSREQUEST_NS0:
-		INVOKE_SERVICE(CreateMonitoredItems);
-		break;
-
-	case UA_SETPUBLISHINGMODEREQUEST_NS0:
-		INVOKE_SERVICE(SetPublishingMode);
-		break;
-		
-	default: {
-		printf("SL_processMessage - unknown request, namespace=%d, request=%d\n",
-			   requestType.nodeId.namespaceIndex, requestType.nodeId.identifier.numeric);
-		UA_RequestHeader p;
-		UA_ResponseHeader r;
-		CHECK_PROCESS(UA_RequestHeader_decodeBinary(msg, pos, &p),;);
-		UA_ResponseHeader_init(&r);
-		r.requestHandle = p.requestHandle;
-		r.serviceResult = UA_STATUSCODE_BADSERVICEUNSUPPORTED;
-		UA_ByteString_newMembers(&responseBuf.strings[1], UA_ResponseHeader_calcSizeBinary(&r));
-		UA_ResponseHeader_encodeBinary(&r, &responseBuf.strings[1], &sendOffset);
-		UA_RequestHeader_deleteMembers(&p);
-		UA_ResponseHeader_deleteMembers(&r);
-		responseType = UA_RESPONSEHEADER_NS0 + 2;
-	}
-	}
-
-	// 5) Build the header
+                           const UA_ByteString *msg, UA_UInt32 *pos) {
+    // 1) Read in the securechannel
+    UA_UInt32 secureChannelId;
+    UA_UInt32_decodeBinary(msg, pos, &secureChannelId);
+    UA_SecureChannel *channel;
+    UA_SecureChannelManager_get(server->secureChannelManager, secureChannelId, &channel);
+
+    // 2) Read the security header
+    UA_UInt32 tokenId;
+    UA_UInt32_decodeBinary(msg, pos, &tokenId);
+    UA_SequenceHeader sequenceHeader;
+    CHECK_PROCESS(UA_SequenceHeader_decodeBinary(msg, pos, &sequenceHeader),; );
+    //UA_SecureChannel_checkSequenceNumber(channel,sequenceHeader.sequenceNumber);
+    //UA_SecureChannel_checkRequestId(channel,sequenceHeader.requestId);
+
+    // 3) Read the nodeid of the request
+    UA_ExpandedNodeId requestType;
+    CHECK_PROCESS(UA_ExpandedNodeId_decodeBinary(msg, pos, &requestType),; );
+    if(requestType.nodeId.identifierType != UA_NODEIDTYPE_NUMERIC)
+        goto close_connection;
+
+    // 4) process the request
+    UA_ByteStringArray responseBuf;
+    UA_ByteStringArray_init(&responseBuf, 2);
+
+    UA_UInt32 responseType;
+
+    //subtract 2 for binary encoding
+    UA_UInt32 sendOffset = 0;
+    switch(requestType.nodeId.identifier.numeric - 2) {
+    case UA_GETENDPOINTSREQUEST_NS0:
+    {
+        UA_GetEndpointsRequest  p;
+        UA_GetEndpointsResponse r;
+        CHECK_PROCESS(UA_GetEndpointsRequest_decodeBinary(msg, pos, &p),; );
+        UA_GetEndpointsResponse_init(&r);
+        init_response_header(&p.requestHeader, &r.responseHeader);
+        Service_GetEndpoints(server, &p, &r);
+        UA_ByteString_newMembers(&responseBuf.strings[1],
+                                 UA_GetEndpointsResponse_calcSizeBinary(&r));
+        UA_GetEndpointsResponse_encodeBinary(&r, &responseBuf.strings[1], &sendOffset);
+        UA_GetEndpointsRequest_deleteMembers(&p);
+        UA_GetEndpointsResponse_deleteMembers(&r);
+        responseType = requestType.nodeId.identifier.numeric + 3;
+        break;
+    }
+
+    case UA_CREATESESSIONREQUEST_NS0:
+    {
+        UA_CreateSessionRequest  p;
+        UA_CreateSessionResponse r;
+        CHECK_PROCESS(UA_CreateSessionRequest_decodeBinary(msg, pos, &p),; );
+        UA_CreateSessionResponse_init(&r);
+        init_response_header(&p.requestHeader, &r.responseHeader);
+        Service_CreateSession(server, channel,  &p, &r);
+        UA_ByteString_newMembers(&responseBuf.strings[1],
+                                 UA_CreateSessionResponse_calcSizeBinary(&r));
+        UA_CreateSessionResponse_encodeBinary(&r, &responseBuf.strings[1], &sendOffset);
+        UA_CreateSessionRequest_deleteMembers(&p);
+        UA_CreateSessionResponse_deleteMembers(&r);
+        responseType = requestType.nodeId.identifier.numeric + 3;
+        break;
+    }
+
+    case UA_ACTIVATESESSIONREQUEST_NS0:
+        INVOKE_SERVICE(ActivateSession);
+        break;
+
+    case UA_READREQUEST_NS0:
+        INVOKE_SERVICE(Read);
+        break;
+
+    case UA_WRITEREQUEST_NS0:
+        INVOKE_SERVICE(Write);
+        break;
+
+    case UA_BROWSEREQUEST_NS0:
+        INVOKE_SERVICE(Browse);
+        break;
+
+    case UA_CREATESUBSCRIPTIONREQUEST_NS0:
+        INVOKE_SERVICE(CreateSubscription);
+        break;
+
+    case UA_TRANSLATEBROWSEPATHSTONODEIDSREQUEST_NS0:
+        INVOKE_SERVICE(TranslateBrowsePathsToNodeIds);
+        break;
+
+    case UA_PUBLISHREQUEST_NS0:
+        INVOKE_SERVICE(Publish);
+        break;
+
+    case UA_CREATEMONITOREDITEMSREQUEST_NS0:
+        INVOKE_SERVICE(CreateMonitoredItems);
+        break;
+
+    case UA_SETPUBLISHINGMODEREQUEST_NS0:
+        INVOKE_SERVICE(SetPublishingMode);
+        break;
+
+    default:
+    {
+        printf("SL_processMessage - unknown request, namespace=%d, request=%d\n",
+               requestType.nodeId.namespaceIndex, requestType.nodeId.identifier.numeric);
+        UA_RequestHeader  p;
+        UA_ResponseHeader r;
+        CHECK_PROCESS(UA_RequestHeader_decodeBinary(msg, pos, &p),; );
+        UA_ResponseHeader_init(&r);
+        r.requestHandle = p.requestHandle;
+        r.serviceResult = UA_STATUSCODE_BADSERVICEUNSUPPORTED;
+        UA_ByteString_newMembers(&responseBuf.strings[1], UA_ResponseHeader_calcSizeBinary(&r));
+        UA_ResponseHeader_encodeBinary(&r, &responseBuf.strings[1], &sendOffset);
+        UA_RequestHeader_deleteMembers(&p);
+        UA_ResponseHeader_deleteMembers(&r);
+        responseType = UA_RESPONSEHEADER_NS0 + 2;
+    }
+    }
+
+    // 5) Build the header
 #define SIZE_SECURECHANNEL_HEADER 12
 #define SIZE_SEQHEADER_HEADER 8
-	UA_NodeId response_nodeid = {.namespaceIndex = 0, .identifierType = UA_NODEIDTYPE_NUMERIC,
-								 .identifier.numeric = responseType}; // add 2 for binary encoding
+    UA_NodeId response_nodeid = { .namespaceIndex     = 0, .identifierType = UA_NODEIDTYPE_NUMERIC,
+                                  .identifier.numeric = responseType }; // add 2 for binary encoding
 
-	UA_ByteString_newMembers(&responseBuf.strings[0],
-							 8 + 16 + // normal header + 4*32bit secure channel information
-							 UA_NodeId_calcSizeBinary(&response_nodeid));
+    UA_ByteString_newMembers(&responseBuf.strings[0],
+                             8 + 16 + // normal header + 4*32bit secure channel information
+                             UA_NodeId_calcSizeBinary(&response_nodeid));
 
-	// sizePadding = 0;
-	// sizeSignature = 0;
-	UA_ByteString *header = &responseBuf.strings[0];
+    // sizePadding = 0;
+    // sizeSignature = 0;
+    UA_ByteString *header = &responseBuf.strings[0];
 
-	// secure conversation message header
-	header->data[0] = 'M';
-	header->data[1] = 'S';
-	header->data[2] = 'G';
-	header->data[3] = 'F';
-	UA_UInt32 rpos = 4;
+    // secure conversation message header
+    header->data[0] = 'M';
+    header->data[1] = 'S';
+    header->data[2] = 'G';
+    header->data[3] = 'F';
+    UA_UInt32 rpos       = 4;
 
-	UA_Int32 packetSize = header->length + responseBuf.strings[0].length;
-	UA_Int32_encodeBinary(&packetSize, header, &rpos);
-	UA_UInt32_encodeBinary(&channel->securityToken.channelId, header, &rpos);
+    UA_Int32  packetSize = header->length + responseBuf.strings[0].length;
+    UA_Int32_encodeBinary(&packetSize, header, &rpos);
+    UA_UInt32_encodeBinary(&channel->securityToken.channelId, header, &rpos);
 
-	// algorithm security header
-	UA_UInt32_encodeBinary(&channel->securityToken.tokenId, header,&rpos);
+    // algorithm security header
+    UA_UInt32_encodeBinary(&channel->securityToken.tokenId, header, &rpos);
 
-	// encode sequence header
-	UA_UInt32_encodeBinary(&channel->sequenceNumber, header, &rpos);
-	UA_UInt32_encodeBinary(&channel->requestId, header,&rpos);
+    // encode sequence header
+    UA_UInt32_encodeBinary(&channel->sequenceNumber, header, &rpos);
+    UA_UInt32_encodeBinary(&channel->requestId, header, &rpos);
 
-	// add payload type
-	UA_NodeId_encodeBinary(&response_nodeid, header,&rpos);
+    // add payload type
+    UA_NodeId_encodeBinary(&response_nodeid, header, &rpos);
 
-	// sign data
+    // sign data
 
-	// encrypt data
+    // encrypt data
 
-	// 6) Send it over the wire.
-	connection->write(connection->callbackHandle, &responseBuf);
+    // 6) Send it over the wire.
+    connection->write(connection->callbackHandle, &responseBuf);
 
- clean_up:
-	UA_ExpandedNodeId_deleteMembers(&requestType);
-	UA_ByteStringArray_deleteMembers(&responseBuf);
-	return;
+clean_up:
+    UA_ExpandedNodeId_deleteMembers(&requestType);
+    UA_ByteStringArray_deleteMembers(&responseBuf);
+    return;
 
- close_connection:
-	// make sure allocated data has been freed
-	connection->state = UA_CONNECTION_CLOSING;
-	connection->close(connection->callbackHandle);
-	return;
+close_connection:
+    // make sure allocated data has been freed
+    connection->state = UA_CONNECTION_CLOSING;
+    connection->close(connection->callbackHandle);
+    return;
 }
 
 static void processClose(UA_Connection *connection, UA_Server *server,
-						const UA_ByteString* msg, UA_UInt32* pos) {
-	// just read in the sequenceheader
+                         const UA_ByteString *msg, UA_UInt32 *pos) {
+    // just read in the sequenceheader
 
 }
 
 UA_Int32 UA_Server_processBinaryMessage(UA_Server *server, UA_Connection *connection,
-										const UA_ByteString* msg) {
-	UA_Int32 retval = UA_SUCCESS;
-	UA_UInt32 pos = 0;
-	UA_OPCUATcpMessageHeader tcpMessageHeader;
-	do {
-		retval = UA_OPCUATcpMessageHeader_decodeBinary(msg,&pos,&tcpMessageHeader);
-		if (retval == UA_SUCCESS) {
-			// none of the process-functions returns an error its all contained inside.
-			switch(tcpMessageHeader.messageType) {
-			case UA_MESSAGETYPE_HEL:
-				processHello(connection, msg, &pos);
-				break;
-			case UA_MESSAGETYPE_OPN:
-				processOpen(connection, server, msg, &pos);
-				break;
-			case UA_MESSAGETYPE_MSG:
-				// if this fails, the connection is closed (no break on the case)
-				if(connection->state == UA_CONNECTION_ESTABLISHED &&
-				   connection->channel != UA_NULL) {
-					processMessage(connection, server, msg, &pos);
-					break;
-				}
-			case UA_MESSAGETYPE_CLO:
-				connection->state = UA_CONNECTION_CLOSING;
-				processClose(connection, server, msg, &pos);
-				connection->close(connection->callbackHandle);
-				break;
-			}
-		} else {
-			printf("TL_Process - ERROR: decoding of header failed \n");
-			connection->state = UA_CONNECTION_CLOSING;
-			processClose(connection, server, msg, &pos);
-			connection->close(connection->callbackHandle);
-		}
-		UA_OPCUATcpMessageHeader_deleteMembers(&tcpMessageHeader);
-	} while(msg->length > (UA_Int32)pos);
-	return retval;
+                                        const UA_ByteString *msg) {
+    UA_Int32  retval = UA_SUCCESS;
+    UA_UInt32 pos    = 0;
+    UA_OPCUATcpMessageHeader tcpMessageHeader;
+    do {
+        retval = UA_OPCUATcpMessageHeader_decodeBinary(msg, &pos, &tcpMessageHeader);
+        if(retval == UA_SUCCESS) {
+            // none of the process-functions returns an error its all contained inside.
+            switch(tcpMessageHeader.messageType) {
+            case UA_MESSAGETYPE_HEL:
+                processHello(connection, msg, &pos);
+                break;
+
+            case UA_MESSAGETYPE_OPN:
+                processOpen(connection, server, msg, &pos);
+                break;
+
+            case UA_MESSAGETYPE_MSG:
+                // if this fails, the connection is closed (no break on the case)
+                if(connection->state == UA_CONNECTION_ESTABLISHED &&
+                   connection->channel != UA_NULL) {
+                    processMessage(connection, server, msg, &pos);
+                    break;
+                }
+
+            case UA_MESSAGETYPE_CLO:
+                connection->state = UA_CONNECTION_CLOSING;
+                processClose(connection, server, msg, &pos);
+                connection->close(connection->callbackHandle);
+                break;
+            }
+        } else {
+            printf("TL_Process - ERROR: decoding of header failed \n");
+            connection->state = UA_CONNECTION_CLOSING;
+            processClose(connection, server, msg, &pos);
+            connection->close(connection->callbackHandle);
+        }
+        UA_OPCUATcpMessageHeader_deleteMembers(&tcpMessageHeader);
+    } while(msg->length > (UA_Int32)pos);
+    return retval;
 }

+ 32 - 32
src/server/ua_services.h

@@ -28,9 +28,9 @@
  * the configuration information required to establish a SecureChannel and a
  * Session.
  */
-UA_Int32 Service_GetEndpoints(UA_Server *server,
-							  const UA_GetEndpointsRequest* request,
-							  UA_GetEndpointsResponse *response);
+UA_Int32 Service_GetEndpoints(UA_Server                    *server,
+                              const UA_GetEndpointsRequest *request,
+                              UA_GetEndpointsResponse      *response);
 // Service_RegisterServer
 /** @} */
 
@@ -45,16 +45,16 @@ UA_Int32 Service_GetEndpoints(UA_Server *server,
  */
 
 /** @brief This Service is used to open or renew a SecureChannel that can be
-  used to ensure Confidentiality and Integrity for Message exchange during a
-  Session. */
+   used to ensure Confidentiality and Integrity for Message exchange during a
+   Session. */
 UA_Int32 Service_OpenSecureChannel(UA_Server *server, UA_Connection *connection,
-								   const UA_OpenSecureChannelRequest* request,
-								   UA_OpenSecureChannelResponse* response);
+                                   const UA_OpenSecureChannelRequest *request,
+                                   UA_OpenSecureChannelResponse *response);
 
 /** @brief This Service is used to terminate a SecureChannel. */
 UA_Int32 Service_CloseSecureChannel(UA_Server *server, UA_SecureChannel *channel,
-									const UA_CloseSecureChannelRequest *request,
-									UA_CloseSecureChannelResponse *response);
+                                    const UA_CloseSecureChannelRequest *request,
+                                    UA_CloseSecureChannelResponse *response);
 /** @} */
 
 /**
@@ -74,8 +74,8 @@ UA_Int32 Service_CloseSecureChannel(UA_Server *server, UA_SecureChannel *channel
  * which is used to associate an incoming request with a Session.
  */
 UA_Int32 Service_CreateSession(UA_Server *server, UA_SecureChannel *channel,
-							   const UA_CreateSessionRequest *request,
-							   UA_CreateSessionResponse *response);
+                               const UA_CreateSessionRequest *request,
+                               UA_CreateSessionResponse *response);
 
 /**
  * @brief This Service is used by the Client to submit its SoftwareCertificates
@@ -85,15 +85,15 @@ UA_Int32 Service_CreateSession(UA_Server *server, UA_SecureChannel *channel,
  * Failure to do so shall cause the Server to close the Session.
  */
 UA_Int32 Service_ActivateSession(UA_Server *server, UA_Session *session,
-								 const UA_ActivateSessionRequest *request,
-								 UA_ActivateSessionResponse *response);
+                                 const UA_ActivateSessionRequest *request,
+                                 UA_ActivateSessionResponse *response);
 
 /**
  * @brief This Service is used to terminate a Session.
  */
 UA_Int32 Service_CloseSession(UA_Server *server, UA_Session *session,
-							  const UA_CloseSessionRequest *request,
-							  UA_CloseSessionResponse *response);
+                              const UA_CloseSessionRequest *request,
+                              UA_CloseSessionResponse *response);
 // Service_Cancel
 /** @} */
 
@@ -111,14 +111,14 @@ UA_Int32 Service_CloseSession(UA_Server *server, UA_Session *session,
  * @brief This Service is used to add one or more Nodes into the AddressSpace hierarchy.
  */
 UA_Int32 Service_AddNodes(UA_Server *server, UA_Session *session,
-						  const UA_AddNodesRequest *request, UA_AddNodesResponse *response);
+                          const UA_AddNodesRequest *request, UA_AddNodesResponse *response);
 
 /**
  * @brief This Service is used to add one or more References to one or more Nodes
  */
 UA_Int32 Service_AddReferences(UA_Server *server, UA_Session *session,
-							   const UA_AddReferencesRequest *request,
-							   UA_AddReferencesResponse *response);
+                               const UA_AddReferencesRequest *request,
+                               UA_AddReferencesResponse *response);
 
 // Service_DeleteNodes
 // Service_DeleteReferences
@@ -137,16 +137,16 @@ UA_Int32 Service_AddReferences(UA_Server *server, UA_Session *session,
  * @brief This Service is used to discover the References of a specified Node.
  * The browse can be further limited by the use of a View. This Browse Service
  * also supports a primitive filtering capability.
- */ 
+ */
 UA_Int32 Service_Browse(UA_Server *server, UA_Session *session,
-						const UA_BrowseRequest *request, UA_BrowseResponse *response);
+                        const UA_BrowseRequest *request, UA_BrowseResponse *response);
 
 /**
  * @brief This Service is used to translate textual node paths to their respective ids.
  */
 UA_Int32 Service_TranslateBrowsePathsToNodeIds(UA_Server *server, UA_Session *session,
-											   const UA_TranslateBrowsePathsToNodeIdsRequest *request,
-											   UA_TranslateBrowsePathsToNodeIdsResponse *response);
+                                               const UA_TranslateBrowsePathsToNodeIdsRequest *request,
+                                               UA_TranslateBrowsePathsToNodeIdsResponse *response);
 // Service_BrowseNext
 // Service_TranslateBrowsePathsToNodeIds
 // Service_RegisterNodes
@@ -190,7 +190,7 @@ UA_Int32 Service_TranslateBrowsePathsToNodeIds(UA_Server *server, UA_Session *se
  * elements of the composite.
  */
 UA_Int32 Service_Read(UA_Server *server, UA_Session *session, const UA_ReadRequest *request,
-					  UA_ReadResponse *response);
+                      UA_ReadResponse *response);
 // Service_HistoryRead
 /**
  * @brief This Service is used to write one or more Attributes of one or more
@@ -200,7 +200,7 @@ UA_Int32 Service_Read(UA_Server *server, UA_Session *session, const UA_ReadReque
  *  elements of the composite.
  */
 UA_Int32 Service_Write(UA_Server *server, UA_Session *session, const UA_WriteRequest *request,
-					   UA_WriteResponse *response);
+                       UA_WriteResponse *response);
 // Service_HistoryUpdate
 /** @} */
 
@@ -208,7 +208,7 @@ UA_Int32 Service_Write(UA_Server *server, UA_Session *session, const UA_WriteReq
  * @name Method Service Set
  *
  * The Method Service Set defines the means to invoke methods. A method shall be
-a component of an Object.
+   a component of an Object.
  *
  * @{
  */
@@ -233,8 +233,8 @@ a component of an Object.
  * referenced by the triggered items.
  */
 UA_Int32 Service_CreateMonitoredItems(UA_Server *server, UA_Session *session,
-									  const UA_CreateMonitoredItemsRequest *request,
-									  UA_CreateMonitoredItemsResponse *response);
+                                      const UA_CreateMonitoredItemsRequest *request,
+                                      UA_CreateMonitoredItemsResponse *response);
 // Service_ModifyMonitoredItems
 // Service_SetMonitoringMode
 // Service_SetTriggering
@@ -250,17 +250,17 @@ UA_Int32 Service_CreateMonitoredItems(UA_Server *server, UA_Session *session,
  */
 // Service_CreateSubscription
 UA_Int32 Service_CreateSubscription(UA_Server *server, UA_Session *session,
-									const UA_CreateSubscriptionRequest *request,
-									UA_CreateSubscriptionResponse *response);
+                                    const UA_CreateSubscriptionRequest *request,
+                                    UA_CreateSubscriptionResponse *response);
 // Service_ModifySubscription
 // Service_SetPublishingMode
 UA_Int32 Service_SetPublishingMode(UA_Server *server, UA_Session *session,
-								   const UA_SetPublishingModeRequest *request,
+                                   const UA_SetPublishingModeRequest *request,
                                    UA_SetPublishingModeResponse *response);
 
 UA_Int32 Service_Publish(UA_Server *server, UA_Session *session,
-						 const UA_PublishRequest *request,
-						 UA_PublishResponse *response);
+                         const UA_PublishRequest *request,
+                         UA_PublishResponse *response);
 
 // Service_Republish
 // Service_TransferSubscription

+ 407 - 407
src/server/ua_services_attribute.c

@@ -2,424 +2,424 @@
 #include "ua_statuscodes.h"
 
 enum UA_AttributeId {
-	UA_ATTRIBUTEID_NODEID                  = 1,
-	UA_ATTRIBUTEID_NODECLASS               = 2,
-	UA_ATTRIBUTEID_BROWSENAME              = 3,
-	UA_ATTRIBUTEID_DISPLAYNAME             = 4,
-	UA_ATTRIBUTEID_DESCRIPTION             = 5,
-	UA_ATTRIBUTEID_WRITEMASK               = 6,
-	UA_ATTRIBUTEID_USERWRITEMASK           = 7,
-	UA_ATTRIBUTEID_ISABSTRACT              = 8,
-	UA_ATTRIBUTEID_SYMMETRIC               = 9,
-	UA_ATTRIBUTEID_INVERSENAME             = 10,
-	UA_ATTRIBUTEID_CONTAINSNOLOOPS         = 11,
-	UA_ATTRIBUTEID_EVENTNOTIFIER           = 12,
-	UA_ATTRIBUTEID_VALUE                   = 13,
-	UA_ATTRIBUTEID_DATATYPE                = 14,
-	UA_ATTRIBUTEID_VALUERANK               = 15,
-	UA_ATTRIBUTEID_ARRAYDIMENSIONS         = 16,
-	UA_ATTRIBUTEID_ACCESSLEVEL             = 17,
-	UA_ATTRIBUTEID_USERACCESSLEVEL         = 18,
-	UA_ATTRIBUTEID_MINIMUMSAMPLINGINTERVAL = 19,
-	UA_ATTRIBUTEID_HISTORIZING             = 20,
-	UA_ATTRIBUTEID_EXECUTABLE              = 21,
-	UA_ATTRIBUTEID_USEREXECUTABLE          = 22
+    UA_ATTRIBUTEID_NODEID = 1,
+    UA_ATTRIBUTEID_NODECLASS = 2,
+    UA_ATTRIBUTEID_BROWSENAME = 3,
+    UA_ATTRIBUTEID_DISPLAYNAME             = 4,
+    UA_ATTRIBUTEID_DESCRIPTION             = 5,
+    UA_ATTRIBUTEID_WRITEMASK               = 6,
+    UA_ATTRIBUTEID_USERWRITEMASK           = 7,
+    UA_ATTRIBUTEID_ISABSTRACT              = 8,
+    UA_ATTRIBUTEID_SYMMETRIC               = 9,
+    UA_ATTRIBUTEID_INVERSENAME             = 10,
+    UA_ATTRIBUTEID_CONTAINSNOLOOPS         = 11,
+    UA_ATTRIBUTEID_EVENTNOTIFIER           = 12,
+    UA_ATTRIBUTEID_VALUE                   = 13,
+    UA_ATTRIBUTEID_DATATYPE                = 14,
+    UA_ATTRIBUTEID_VALUERANK               = 15,
+    UA_ATTRIBUTEID_ARRAYDIMENSIONS         = 16,
+    UA_ATTRIBUTEID_ACCESSLEVEL             = 17,
+    UA_ATTRIBUTEID_USERACCESSLEVEL         = 18,
+    UA_ATTRIBUTEID_MINIMUMSAMPLINGINTERVAL = 19,
+    UA_ATTRIBUTEID_HISTORIZING             = 20,
+    UA_ATTRIBUTEID_EXECUTABLE              = 21,
+    UA_ATTRIBUTEID_USEREXECUTABLE          = 22
 };
 
-#define CHECK_NODECLASS(CLASS)									   \
-	if(!(node->nodeClass & (CLASS))) {							   \
-		v.encodingMask = UA_DATAVALUE_ENCODINGMASK_STATUSCODE;	   \
-		v.status       = UA_STATUSCODE_BADNOTREADABLE;			   \
-		break;													   \
-	}															   \
+#define CHECK_NODECLASS(CLASS)                                 \
+    if(!(node->nodeClass & (CLASS))) {                         \
+        v.encodingMask = UA_DATAVALUE_ENCODINGMASK_STATUSCODE; \
+        v.status       = UA_STATUSCODE_BADNOTREADABLE;         \
+        break;                                                 \
+    }                                                          \
 
 static UA_DataValue service_read_node(UA_Server *server, const UA_ReadValueId *id) {
-	UA_DataValue v;
-	UA_DataValue_init(&v);
-
-	UA_Namespace *ns = UA_NULL;
-	for(UA_UInt32 i=0; i<server->namespacesSize;i++) {
-		if(server->namespaces[i].namespaceIndex == id->nodeId.namespaceIndex) {
-			ns = server->namespaces[i].namespace;
-			break;
-		}
-	}
-
-	if(ns == UA_NULL) {
-		v.encodingMask = UA_DATAVALUE_ENCODINGMASK_STATUSCODE;
-		v.status       = UA_STATUSCODE_BADNODEIDUNKNOWN;
-		return v;
-	}
-
-	UA_Node const *node = UA_NULL;
-	UA_Int32 result = UA_Namespace_get(ns, &(id->nodeId), &node);
-	if(result != UA_SUCCESS || node == UA_NULL) {
-		v.encodingMask = UA_DATAVALUE_ENCODINGMASK_STATUSCODE;
-		v.status       = UA_STATUSCODE_BADNODEIDUNKNOWN;
-		return v;
-	}
-	UA_Int32 retval = UA_SUCCESS;
-
-	switch(id->attributeId) {
-	case UA_ATTRIBUTEID_NODEID:
-		v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
-		retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_NODEID], &node->nodeId);
-		break;
-
-	case UA_ATTRIBUTEID_NODECLASS:
-		v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
-		retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_INT32], &node->nodeClass);
-		break;
-
-	case UA_ATTRIBUTEID_BROWSENAME:
-		v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
-		retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_QUALIFIEDNAME], &node->browseName);
-		break;
-
-	case UA_ATTRIBUTEID_DISPLAYNAME:
-		v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
-		retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_LOCALIZEDTEXT],
-		                                  &node->displayName);
-		break;
-
-	case UA_ATTRIBUTEID_DESCRIPTION:
-		v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
-		retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_LOCALIZEDTEXT],
-		                                  &node->description);
-		break;
-
-	case UA_ATTRIBUTEID_WRITEMASK:
-		v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
-		retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_UINT32], &node->writeMask);
-		break;
-
-	case UA_ATTRIBUTEID_USERWRITEMASK:
-		v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
-		retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_UINT32], &node->userWriteMask);
-		break;
-
-	case UA_ATTRIBUTEID_ISABSTRACT:
-		CHECK_NODECLASS(UA_NODECLASS_REFERENCETYPE | UA_NODECLASS_OBJECTTYPE | UA_NODECLASS_VARIABLETYPE | UA_NODECLASS_DATATYPE);
-		v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
-		retval |=
-		    UA_Variant_copySetValue(&v.value, &UA_.types[UA_BOOLEAN],
-		                            &((UA_ReferenceTypeNode *)node)->isAbstract);
-		break;
-
-	case UA_ATTRIBUTEID_SYMMETRIC:
-		CHECK_NODECLASS(UA_NODECLASS_REFERENCETYPE);
-		v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
-		retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_BOOLEAN],
-		                                  &((UA_ReferenceTypeNode *)node)->symmetric);
-		break;
-
-	case UA_ATTRIBUTEID_INVERSENAME:
-		CHECK_NODECLASS(UA_NODECLASS_REFERENCETYPE);
-		v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
-		retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_LOCALIZEDTEXT],
-		                                  &((UA_ReferenceTypeNode *)node)->inverseName);
-		break;
-
-	case UA_ATTRIBUTEID_CONTAINSNOLOOPS:
-		CHECK_NODECLASS(UA_NODECLASS_VIEW);
-		v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
-		retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_BOOLEAN],
-		                                  &((UA_ViewNode *)node)->containsNoLoops);
-		break;
-
-	case UA_ATTRIBUTEID_EVENTNOTIFIER:
-		CHECK_NODECLASS(UA_NODECLASS_VIEW | UA_NODECLASS_OBJECT);
-		v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
-		retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_BYTE],
-		                                  &((UA_ViewNode *)node)->eventNotifier);
-		break;
-
-	case UA_ATTRIBUTEID_VALUE:
-		CHECK_NODECLASS(UA_NODECLASS_VARIABLE | UA_NODECLASS_VARIABLETYPE);
-		v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
-		// TODO: Ensure that the borrowed value is not freed prematurely (multithreading)
-		/* retval |= UA_Variant_borrowSetValue(&v.value, &UA_.types[UA_VARIANT], */
-		/*                                     &((UA_VariableNode *)node)->value); */
-		retval |= UA_Variant_copy(&((UA_VariableNode *)node)->value, &v.value);
-		break;
-
-	case UA_ATTRIBUTEID_DATATYPE:
-		CHECK_NODECLASS(UA_NODECLASS_VARIABLE | UA_NODECLASS_VARIABLETYPE);
-		v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
-		retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_NODEID],
-		                                  &((UA_VariableTypeNode *)node)->dataType);
-		break;
-
-	case UA_ATTRIBUTEID_VALUERANK:
-		CHECK_NODECLASS(UA_NODECLASS_VARIABLE | UA_NODECLASS_VARIABLETYPE);
-		v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
-		retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_INT32],
-		                                  &((UA_VariableTypeNode *)node)->valueRank);
-		break;
-
-	case UA_ATTRIBUTEID_ARRAYDIMENSIONS:
-		CHECK_NODECLASS(UA_NODECLASS_VARIABLE | UA_NODECLASS_VARIABLETYPE);
-		v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
-		UA_Variant_copySetArray(&v.value, &UA_.types[UA_UINT32],
-		                        ((UA_VariableTypeNode *)node)->arrayDimensionsSize,
-		                        &((UA_VariableTypeNode *)node)->arrayDimensions);
-		break;
-
-	case UA_ATTRIBUTEID_ACCESSLEVEL:
-		CHECK_NODECLASS(UA_NODECLASS_VARIABLE);
-		v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
-		retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_BYTE],
-		                                  &((UA_VariableNode *)node)->accessLevel);
-		break;
-
-	case UA_ATTRIBUTEID_USERACCESSLEVEL:
-		CHECK_NODECLASS(UA_NODECLASS_VARIABLE);
-		v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
-		retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_BYTE],
-		                                  &((UA_VariableNode *)node)->userAccessLevel);
-		break;
-
-	case UA_ATTRIBUTEID_MINIMUMSAMPLINGINTERVAL:
-		CHECK_NODECLASS(UA_NODECLASS_VARIABLE);
-		v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
-		retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_DOUBLE],
-		                                  &((UA_VariableNode *)node)->minimumSamplingInterval);
-		break;
-
-	case UA_ATTRIBUTEID_HISTORIZING:
-		CHECK_NODECLASS(UA_NODECLASS_VARIABLE);
-		v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
-		retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_BOOLEAN],
-		                                  &((UA_VariableNode *)node)->historizing);
-		break;
-
-	case UA_ATTRIBUTEID_EXECUTABLE:
-		CHECK_NODECLASS(UA_NODECLASS_METHOD);
-		v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
-		retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_BOOLEAN],
-		                                  &((UA_MethodNode *)node)->executable);
-		break;
-
-	case UA_ATTRIBUTEID_USEREXECUTABLE:
-		CHECK_NODECLASS(UA_NODECLASS_METHOD);
-		v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
-		retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_BOOLEAN],
-		                                  &((UA_MethodNode *)node)->userExecutable);
-		break;
-
-	default:
-		v.encodingMask = UA_DATAVALUE_ENCODINGMASK_STATUSCODE;
-		v.status       = UA_STATUSCODE_BADATTRIBUTEIDINVALID;
-		break;
-	}
-
-	UA_Namespace_releaseManagedNode(node);
-
-	if(retval != UA_SUCCESS) {
-		v.encodingMask = UA_DATAVALUE_ENCODINGMASK_STATUSCODE;
-		v.status       = UA_STATUSCODE_BADNOTREADABLE;
-	}
-
-
-	return v;
+    UA_DataValue v;
+    UA_DataValue_init(&v);
+
+    UA_Namespace *ns = UA_NULL;
+    for(UA_UInt32 i = 0;i < server->namespacesSize;i++) {
+        if(server->namespaces[i].namespaceIndex == id->nodeId.namespaceIndex) {
+            ns = server->namespaces[i].namespace;
+            break;
+        }
+    }
+
+    if(ns == UA_NULL) {
+    v.encodingMask = UA_DATAVALUE_ENCODINGMASK_STATUSCODE;
+    v.status       = UA_STATUSCODE_BADNODEIDUNKNOWN;
+    return v;
+    }
+
+    UA_Node const *node   = UA_NULL;
+    UA_Int32       result = UA_Namespace_get(ns, &(id->nodeId), &node);
+    if(result != UA_SUCCESS || node == UA_NULL) {
+        v.encodingMask = UA_DATAVALUE_ENCODINGMASK_STATUSCODE;
+        v.status       = UA_STATUSCODE_BADNODEIDUNKNOWN;
+        return v;
+    }
+    UA_Int32 retval = UA_SUCCESS;
+
+    switch(id->attributeId) {
+    case UA_ATTRIBUTEID_NODEID:
+        v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
+        retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_NODEID], &node->nodeId);
+        break;
+
+    case UA_ATTRIBUTEID_NODECLASS:
+        v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
+        retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_INT32], &node->nodeClass);
+        break;
+
+    case UA_ATTRIBUTEID_BROWSENAME:
+        v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
+        retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_QUALIFIEDNAME], &node->browseName);
+        break;
+
+    case UA_ATTRIBUTEID_DISPLAYNAME:
+        v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
+        retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_LOCALIZEDTEXT],
+                                          &node->displayName);
+        break;
+
+    case UA_ATTRIBUTEID_DESCRIPTION:
+        v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
+        retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_LOCALIZEDTEXT],
+                                          &node->description);
+        break;
+
+    case UA_ATTRIBUTEID_WRITEMASK:
+        v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
+        retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_UINT32], &node->writeMask);
+        break;
+
+    case UA_ATTRIBUTEID_USERWRITEMASK:
+        v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
+        retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_UINT32], &node->userWriteMask);
+        break;
+
+    case UA_ATTRIBUTEID_ISABSTRACT:
+        CHECK_NODECLASS(
+            UA_NODECLASS_REFERENCETYPE | UA_NODECLASS_OBJECTTYPE | UA_NODECLASS_VARIABLETYPE |
+            UA_NODECLASS_DATATYPE);
+        v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
+        retval |=
+            UA_Variant_copySetValue(&v.value, &UA_.types[UA_BOOLEAN],
+                                    &((UA_ReferenceTypeNode *)node)->isAbstract);
+        break;
+
+    case UA_ATTRIBUTEID_SYMMETRIC:
+        CHECK_NODECLASS(UA_NODECLASS_REFERENCETYPE);
+        v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
+        retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_BOOLEAN],
+                                          &((UA_ReferenceTypeNode *)node)->symmetric);
+        break;
+
+    case UA_ATTRIBUTEID_INVERSENAME:
+        CHECK_NODECLASS(UA_NODECLASS_REFERENCETYPE);
+        v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
+        retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_LOCALIZEDTEXT],
+                                          &((UA_ReferenceTypeNode *)node)->inverseName);
+        break;
+
+    case UA_ATTRIBUTEID_CONTAINSNOLOOPS:
+        CHECK_NODECLASS(UA_NODECLASS_VIEW);
+        v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
+        retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_BOOLEAN],
+                                          &((UA_ViewNode *)node)->containsNoLoops);
+        break;
+
+    case UA_ATTRIBUTEID_EVENTNOTIFIER:
+        CHECK_NODECLASS(UA_NODECLASS_VIEW | UA_NODECLASS_OBJECT);
+        v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
+        retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_BYTE],
+                                          &((UA_ViewNode *)node)->eventNotifier);
+        break;
+
+    case UA_ATTRIBUTEID_VALUE:
+        CHECK_NODECLASS(UA_NODECLASS_VARIABLE | UA_NODECLASS_VARIABLETYPE);
+        v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
+        // TODO: Ensure that the borrowed value is not freed prematurely (multithreading)
+        /* retval |= UA_Variant_borrowSetValue(&v.value, &UA_.types[UA_VARIANT], */
+        /*                                     &((UA_VariableNode *)node)->value); */
+        retval |= UA_Variant_copy(&((UA_VariableNode *)node)->value, &v.value);
+        break;
+
+    case UA_ATTRIBUTEID_DATATYPE:
+        CHECK_NODECLASS(UA_NODECLASS_VARIABLE | UA_NODECLASS_VARIABLETYPE);
+        v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
+        retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_NODEID],
+                                          &((UA_VariableTypeNode *)node)->dataType);
+        break;
+
+    case UA_ATTRIBUTEID_VALUERANK:
+        CHECK_NODECLASS(UA_NODECLASS_VARIABLE | UA_NODECLASS_VARIABLETYPE);
+        v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
+        retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_INT32],
+                                          &((UA_VariableTypeNode *)node)->valueRank);
+        break;
+
+    case UA_ATTRIBUTEID_ARRAYDIMENSIONS:
+        CHECK_NODECLASS(UA_NODECLASS_VARIABLE | UA_NODECLASS_VARIABLETYPE);
+        v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
+        UA_Variant_copySetArray(&v.value, &UA_.types[UA_UINT32],
+                                ((UA_VariableTypeNode *)node)->arrayDimensionsSize,
+                                &((UA_VariableTypeNode *)node)->arrayDimensions);
+        break;
+
+    case UA_ATTRIBUTEID_ACCESSLEVEL:
+        CHECK_NODECLASS(UA_NODECLASS_VARIABLE);
+        v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
+        retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_BYTE],
+                                          &((UA_VariableNode *)node)->accessLevel);
+        break;
+
+    case UA_ATTRIBUTEID_USERACCESSLEVEL:
+        CHECK_NODECLASS(UA_NODECLASS_VARIABLE);
+        v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
+        retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_BYTE],
+                                          &((UA_VariableNode *)node)->userAccessLevel);
+        break;
+
+    case UA_ATTRIBUTEID_MINIMUMSAMPLINGINTERVAL:
+        CHECK_NODECLASS(UA_NODECLASS_VARIABLE);
+        v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
+        retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_DOUBLE],
+                                          &((UA_VariableNode *)node)->minimumSamplingInterval);
+        break;
+
+    case UA_ATTRIBUTEID_HISTORIZING:
+        CHECK_NODECLASS(UA_NODECLASS_VARIABLE);
+        v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
+        retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_BOOLEAN],
+                                          &((UA_VariableNode *)node)->historizing);
+        break;
+
+    case UA_ATTRIBUTEID_EXECUTABLE:
+        CHECK_NODECLASS(UA_NODECLASS_METHOD);
+        v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
+        retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_BOOLEAN],
+                                          &((UA_MethodNode *)node)->executable);
+        break;
+
+    case UA_ATTRIBUTEID_USEREXECUTABLE:
+        CHECK_NODECLASS(UA_NODECLASS_METHOD);
+        v.encodingMask = UA_DATAVALUE_ENCODINGMASK_VARIANT;
+        retval |= UA_Variant_copySetValue(&v.value, &UA_.types[UA_BOOLEAN],
+                                          &((UA_MethodNode *)node)->userExecutable);
+        break;
+
+    default:
+        v.encodingMask = UA_DATAVALUE_ENCODINGMASK_STATUSCODE;
+        v.status       = UA_STATUSCODE_BADATTRIBUTEIDINVALID;
+        break;
+    }
+
+    UA_Namespace_releaseManagedNode(node);
+
+    if(retval != UA_SUCCESS) {
+        v.encodingMask = UA_DATAVALUE_ENCODINGMASK_STATUSCODE;
+        v.status       = UA_STATUSCODE_BADNOTREADABLE;
+    }
+
+
+    return v;
 }
 UA_Int32 Service_Read(UA_Server *server, UA_Session *session, const UA_ReadRequest *request,
-					  UA_ReadResponse *response) {
-	UA_Int32 readsize;
-	if(server == UA_NULL || session == UA_NULL)
-		return UA_ERROR;
-
-	readsize = request->nodesToReadSize;
-	/* NothingTodo */
-	if(readsize <= 0) {
-		response->responseHeader.serviceResult = UA_STATUSCODE_BADNOTHINGTODO;
-		response->resultsSize = 0;
-		return UA_SUCCESS;
-	}
-
-	response->resultsSize = readsize;
-	UA_alloc((void **)&response->results, sizeof(UA_DataValue) * readsize);
-	for(UA_Int32 i = 0;i < readsize;i++) {
-		DBG_VERBOSE(printf("service_read - attributeId=%d\n", request->nodesToRead[i].attributeId));
-		DBG_VERBOSE(UA_NodeId_printf("service_read - nodeId=", &(request->nodesToRead[i].nodeId)));
-		response->results[i] = service_read_node(server, &request->nodesToRead[i]);
-	}
-	response->responseHeader.serviceResult = UA_STATUSCODE_GOOD;
-	response->diagnosticInfosSize = 0;
-	return UA_SUCCESS;
+                      UA_ReadResponse *response) {
+    UA_Int32 readsize;
+    if(server == UA_NULL || session == UA_NULL)
+        return UA_ERROR;
+
+    readsize = request->nodesToReadSize;
+    /* NothingTodo */
+    if(readsize <= 0) {
+        response->responseHeader.serviceResult = UA_STATUSCODE_BADNOTHINGTODO;
+        response->resultsSize = 0;
+        return UA_SUCCESS;
+    }
+
+    response->resultsSize = readsize;
+    UA_alloc((void **)&response->results, sizeof(UA_DataValue) * readsize);
+    for(UA_Int32 i = 0;i < readsize;i++) {
+        DBG_VERBOSE(printf("service_read - attributeId=%d\n", request->nodesToRead[i].attributeId));
+        DBG_VERBOSE(UA_NodeId_printf("service_read - nodeId=", &(request->nodesToRead[i].nodeId)));
+        response->results[i] = service_read_node(server, &request->nodesToRead[i]);
+    }
+    response->responseHeader.serviceResult = UA_STATUSCODE_GOOD;
+    response->diagnosticInfosSize = 0;
+    return UA_SUCCESS;
 }
 
 UA_Int32 Service_Write_writeNode(UA_Server *server, UA_WriteValue *writeValue,
-								 UA_StatusCode *result) {
-	UA_Int32 retval = UA_SUCCESS;
-
-	UA_Namespace *ns = UA_NULL;
-	for(UA_UInt32 i=0; i<server->namespacesSize;i++) {
-		if(server->namespaces[i].namespaceIndex == writeValue->nodeId.namespaceIndex) {
-			ns = server->namespaces[i].namespace;
-			break;
-		}
-	}
-	
-	if(ns==UA_NULL) {
-		*result = UA_STATUSCODE_BADNODEIDINVALID;
-		return UA_ERROR;
-	}
-
-	const UA_Node *node;
-	if(UA_Namespace_get(ns, &writeValue->nodeId, &node) != UA_SUCCESS) {
-		return UA_ERROR;
-	}
-
-	switch(writeValue->attributeId) {
-	case UA_ATTRIBUTEID_NODEID:
-		/* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){ } */
-		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
-		return UA_ERROR;
-		break;
-
-	case UA_ATTRIBUTEID_NODECLASS:
-		/* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){ } */
-		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
-		return UA_ERROR;
-		break;
-
-	case UA_ATTRIBUTEID_BROWSENAME:
-		/* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
-		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
-		return UA_ERROR;
-		break;
-
-	case UA_ATTRIBUTEID_DISPLAYNAME:
-		/* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
-		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
-		return UA_ERROR;
-		break;
-
-	case UA_ATTRIBUTEID_DESCRIPTION:
-		/* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
-		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
-		return UA_ERROR;
-		break;
-
-	case UA_ATTRIBUTEID_WRITEMASK:
-		/* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
-		break;
-
-	case UA_ATTRIBUTEID_USERWRITEMASK:
-		/* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
-		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
-		return UA_ERROR;
-		break;
-
-	case UA_ATTRIBUTEID_ISABSTRACT:
-
-		/* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
-		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
-
-		break;
-
-	case UA_ATTRIBUTEID_SYMMETRIC:
-		/* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
-		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
-		return UA_ERROR;
-		break;
-
-	case UA_ATTRIBUTEID_INVERSENAME:
-		/* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
-		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
-		break;
-
-	case UA_ATTRIBUTEID_CONTAINSNOLOOPS:
-		/* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
-		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
-		return UA_ERROR;
-		break;
-
-	case UA_ATTRIBUTEID_EVENTNOTIFIER:
-		/* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
-		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
-		break;
-
-	case UA_ATTRIBUTEID_VALUE:
-		if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT) {
-			// TODO: Ensure that the borrowed value is not freed prematurely (multithreading)
-			/* retval |= UA_Variant_borrowSetValue(&v.value, &UA_.types[UA_VARIANT], */
-			/*                                     &((UA_VariableNode *)node)->value); */
-			retval |= UA_Variant_copy(&writeValue->value.value, &((UA_VariableNode *)node)->value);
-			*result = UA_STATUSCODE_GOOD;
-		}
-
-		break;
-
-	case UA_ATTRIBUTEID_DATATYPE:
-		/* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
-		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
-		break;
-
-	case UA_ATTRIBUTEID_VALUERANK:
-		/* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
-		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
-		break;
-
-	case UA_ATTRIBUTEID_ARRAYDIMENSIONS:
-		/* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
-		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
-		break;
-
-	case UA_ATTRIBUTEID_ACCESSLEVEL:
-		/* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
-		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
-		break;
-
-	case UA_ATTRIBUTEID_USERACCESSLEVEL:
-		/* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
-		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
-		return UA_ERROR;
-		break;
-
-	case UA_ATTRIBUTEID_MINIMUMSAMPLINGINTERVAL:
-		/* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
-		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
-		break;
-
-	case UA_ATTRIBUTEID_HISTORIZING:
-		/* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
-		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
-		break;
-
-	case UA_ATTRIBUTEID_EXECUTABLE:
-		/* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
-		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
-		break;
-
-	case UA_ATTRIBUTEID_USEREXECUTABLE:
-		/* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
-		*result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
-		break;
-
-	default:
-		*result      = UA_STATUSCODE_BADATTRIBUTEIDINVALID;
-		break;
-	}
-
-	UA_Namespace_releaseManagedNode(node);
-	return retval;
+                                 UA_StatusCode *result) {
+    UA_Int32      retval = UA_SUCCESS;
+
+    UA_Namespace *ns     = UA_NULL;
+    for(UA_UInt32 i = 0;i < server->namespacesSize;i++) {
+        if(server->namespaces[i].namespaceIndex == writeValue->nodeId.namespaceIndex) {
+            ns = server->namespaces[i].namespace;
+            break;
+        }
+    }
+
+    if(ns == UA_NULL) {
+    *result = UA_STATUSCODE_BADNODEIDINVALID;
+    return UA_ERROR;
+    }
+
+    const UA_Node *node;
+    if(UA_Namespace_get(ns, &writeValue->nodeId, &node) != UA_SUCCESS)
+        return UA_ERROR;
+
+    switch(writeValue->attributeId) {
+    case UA_ATTRIBUTEID_NODEID:
+        /* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){ } */
+        *result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+        return UA_ERROR;
+        break;
+
+    case UA_ATTRIBUTEID_NODECLASS:
+        /* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){ } */
+        *result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+        return UA_ERROR;
+        break;
+
+    case UA_ATTRIBUTEID_BROWSENAME:
+        /* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
+        *result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+        return UA_ERROR;
+        break;
+
+    case UA_ATTRIBUTEID_DISPLAYNAME:
+        /* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
+        *result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+        return UA_ERROR;
+        break;
+
+    case UA_ATTRIBUTEID_DESCRIPTION:
+        /* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
+        *result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+        return UA_ERROR;
+        break;
+
+    case UA_ATTRIBUTEID_WRITEMASK:
+        /* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
+        break;
+
+    case UA_ATTRIBUTEID_USERWRITEMASK:
+        /* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
+        *result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+        return UA_ERROR;
+        break;
+
+    case UA_ATTRIBUTEID_ISABSTRACT:
+
+        /* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
+        *result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+
+        break;
+
+    case UA_ATTRIBUTEID_SYMMETRIC:
+        /* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
+        *result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+        return UA_ERROR;
+        break;
+
+    case UA_ATTRIBUTEID_INVERSENAME:
+        /* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
+        *result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+        break;
+
+    case UA_ATTRIBUTEID_CONTAINSNOLOOPS:
+        /* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
+        *result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+        return UA_ERROR;
+        break;
+
+    case UA_ATTRIBUTEID_EVENTNOTIFIER:
+        /* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
+        *result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+        break;
+
+    case UA_ATTRIBUTEID_VALUE:
+        if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT) {
+            // TODO: Ensure that the borrowed value is not freed prematurely (multithreading)
+            /* retval |= UA_Variant_borrowSetValue(&v.value, &UA_.types[UA_VARIANT], */
+            /*                                     &((UA_VariableNode *)node)->value); */
+            retval |= UA_Variant_copy(&writeValue->value.value, &((UA_VariableNode *)node)->value);
+            *result = UA_STATUSCODE_GOOD;
+        }
+
+        break;
+
+    case UA_ATTRIBUTEID_DATATYPE:
+        /* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
+        *result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+        break;
+
+    case UA_ATTRIBUTEID_VALUERANK:
+        /* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
+        *result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+        break;
+
+    case UA_ATTRIBUTEID_ARRAYDIMENSIONS:
+        /* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
+        *result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+        break;
+
+    case UA_ATTRIBUTEID_ACCESSLEVEL:
+        /* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
+        *result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+        break;
+
+    case UA_ATTRIBUTEID_USERACCESSLEVEL:
+        /* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
+        *result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+        return UA_ERROR;
+        break;
+
+    case UA_ATTRIBUTEID_MINIMUMSAMPLINGINTERVAL:
+        /* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
+        *result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+        break;
+
+    case UA_ATTRIBUTEID_HISTORIZING:
+        /* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
+        *result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+        break;
+
+    case UA_ATTRIBUTEID_EXECUTABLE:
+        /* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
+        *result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+        break;
+
+    case UA_ATTRIBUTEID_USEREXECUTABLE:
+        /* if(writeValue->value.encodingMask == UA_DATAVALUE_ENCODINGMASK_VARIANT){} */
+        *result = UA_STATUSCODE_BADWRITENOTSUPPORTED;
+        break;
+
+    default:
+        *result = UA_STATUSCODE_BADATTRIBUTEIDINVALID;
+        break;
+    }
+
+    UA_Namespace_releaseManagedNode(node);
+    return retval;
 
 }
 
 UA_Int32 Service_Write(UA_Server *server, UA_Session *session, const UA_WriteRequest *request,
-					   UA_WriteResponse *response) {
-	UA_Int32 retval = UA_SUCCESS;
-	UA_Int32 i;
-	if(session == UA_NULL || server == UA_NULL)
-		return UA_ERROR;    // TODO: Return error message
-	response->resultsSize = request->nodesToWriteSize;
-	//TODO evalutate diagnostic info within the request
-	UA_Array_new((void**)&response->results,response->resultsSize,&UA_.types[UA_STATUSCODE]);
-	for(i=0; i < request->nodesToWriteSize; i++){
-		retval |= Service_Write_writeNode(server, &request->nodesToWrite[i], &response->results[i]);
-	}
-
-	return retval;
+                       UA_WriteResponse *response) {
+    UA_Int32 retval = UA_SUCCESS;
+    UA_Int32 i;
+    if(session == UA_NULL || server == UA_NULL)
+        return UA_ERROR;    // TODO: Return error message
+    response->resultsSize = request->nodesToWriteSize;
+    //TODO evalutate diagnostic info within the request
+    UA_Array_new((void **)&response->results, response->resultsSize, &UA_.types[UA_STATUSCODE]);
+    for(i = 0;i < request->nodesToWriteSize;i++)
+        retval |= Service_Write_writeNode(server, &request->nodesToWrite[i], &response->results[i]);
+
+    return retval;
 }

+ 34 - 34
src/server/ua_services_discovery.c

@@ -1,41 +1,41 @@
 #include "ua_services.h"
 
-UA_Int32 Service_GetEndpoints(UA_Server *server,
-							  const UA_GetEndpointsRequest* request,
-							  UA_GetEndpointsResponse *response) {
-	response->endpointsSize = 1;
-	UA_Array_new((void**) &response->endpoints, response->endpointsSize,
-			&UA_.types[UA_ENDPOINTDESCRIPTION]);
+UA_Int32 Service_GetEndpoints(UA_Server                    *server,
+                              const UA_GetEndpointsRequest *request,
+                              UA_GetEndpointsResponse      *response) {
+    response->endpointsSize = 1;
+    UA_Array_new((void **)&response->endpoints, response->endpointsSize,
+                 &UA_.types[UA_ENDPOINTDESCRIPTION]);
 
-	//FIXME hard-coded code
-	response->endpoints[0].securityMode = UA_MESSAGESECURITYMODE_NONE;
-	UA_String_copycstring("http://opcfoundation.org/UA/SecurityPolicy#None",
-						  &response->endpoints[0].securityPolicyUri);
-	UA_String_copycstring("http://opcfoundation.org/UA-Profile/Transport/uatcp-uasc-uabinary",
-						  &response->endpoints[0].transportProfileUri);
+    //FIXME hard-coded code
+    response->endpoints[0].securityMode = UA_MESSAGESECURITYMODE_NONE;
+    UA_String_copycstring("http://opcfoundation.org/UA/SecurityPolicy#None",
+                          &response->endpoints[0].securityPolicyUri);
+    UA_String_copycstring("http://opcfoundation.org/UA-Profile/Transport/uatcp-uasc-uabinary",
+                          &response->endpoints[0].transportProfileUri);
 
-	response->endpoints[0].userIdentityTokensSize = 1;
-	UA_Array_new((void**) &response->endpoints[0].userIdentityTokens,
-			response->endpoints[0].userIdentityTokensSize,
-			&UA_.types[UA_USERTOKENPOLICY]);
-	UA_UserTokenPolicy *token = &response->endpoints[0].userIdentityTokens[0];
-	UA_String_copycstring("my-anonymous-policy", &token->policyId); // defined per server
-	token->tokenType = UA_USERTOKENTYPE_ANONYMOUS;
-	token->issuerEndpointUrl = (UA_String ) { -1, UA_NULL };
-	token->issuedTokenType = (UA_String ) { -1, UA_NULL };
-	token->securityPolicyUri = (UA_String ) { -1, UA_NULL };
+    response->endpoints[0].userIdentityTokensSize = 1;
+    UA_Array_new((void **)&response->endpoints[0].userIdentityTokens,
+                 response->endpoints[0].userIdentityTokensSize,
+                 &UA_.types[UA_USERTOKENPOLICY]);
+    UA_UserTokenPolicy *token = &response->endpoints[0].userIdentityTokens[0];
+    UA_String_copycstring("my-anonymous-policy", &token->policyId); // defined per server
+    token->tokenType         = UA_USERTOKENTYPE_ANONYMOUS;
+    token->issuerEndpointUrl = (UA_String ) {-1, UA_NULL };
+    token->issuedTokenType   = (UA_String ) {-1, UA_NULL };
+    token->securityPolicyUri = (UA_String ) {-1, UA_NULL };
 
-	UA_String_copy(&request->endpointUrl, &response->endpoints[0].endpointUrl);
-	UA_String_copycstring("http://open62541.info/product/release",
-						  &(response->endpoints[0].server.productUri));
-	// FIXME: This information should be provided by the application, preferably in the address space
-	UA_String_copycstring("http://open62541.info/applications/4711",
-						  &(response->endpoints[0].server.applicationUri));
-	UA_LocalizedText_copycstring("The open62541 application",
-								 &(response->endpoints[0].server.applicationName));
-	// FIXME: This should be a feature of the application and an enum
-	response->endpoints[0].server.applicationType = UA_APPLICATIONTYPE_SERVER;
-	// all the other strings are empty by initialization
+    UA_String_copy(&request->endpointUrl, &response->endpoints[0].endpointUrl);
+    UA_String_copycstring("http://open62541.info/product/release",
+                          &(response->endpoints[0].server.productUri));
+    // FIXME: This information should be provided by the application, preferably in the address space
+    UA_String_copycstring("http://open62541.info/applications/4711",
+                          &(response->endpoints[0].server.applicationUri));
+    UA_LocalizedText_copycstring("The open62541 application",
+                                 &(response->endpoints[0].server.applicationName));
+    // FIXME: This should be a feature of the application and an enum
+    response->endpoints[0].server.applicationType = UA_APPLICATIONTYPE_SERVER;
+    // all the other strings are empty by initialization
 
-	return UA_SUCCESS;
+    return UA_SUCCESS;
 }

+ 23 - 21
src/server/ua_services_monitoreditems.c

@@ -5,33 +5,35 @@
 /* Activate once the infrastructure for pushing events is in place. */
 
 UA_Int32 Service_CreateMonitoredItems(UA_Server *server, UA_Session *session,
-									  const UA_CreateMonitoredItemsRequest *request,
-									  UA_CreateMonitoredItemsResponse *response) {
-	if (request->itemsToCreateSize > 0) {
-		response->resultsSize = request->itemsToCreateSize;
+                                      const UA_CreateMonitoredItemsRequest *request,
+                                      UA_CreateMonitoredItemsResponse *response) {
+    if(request->itemsToCreateSize > 0) {
+        response->resultsSize = request->itemsToCreateSize;
 
-		UA_Array_new((void**)&(response->results),response->resultsSize,&UA_.types[UA_MONITOREDITEMCREATERESULT]);
-		for (int i=0;request->itemsToCreateSize > 0 && i < request->itemsToCreateSize;i++) {
+        UA_Array_new((void **)&(response->results), response->resultsSize,
+                     &UA_.types[UA_MONITOREDITEMCREATERESULT]);
+        for(int i = 0;request->itemsToCreateSize > 0 && i < request->itemsToCreateSize;i++) {
 #ifdef DEBUG
-			UA_NodeId_printf("CreateMonitoredItems - itemToCreate=",&(request->itemsToCreate[i].itemToMonitor.nodeId));
+            UA_NodeId_printf("CreateMonitoredItems - itemToCreate=",
+                             &(request->itemsToCreate[i].itemToMonitor.nodeId));
 #endif
-			//FIXME: search the object in the namespace
+            //FIXME: search the object in the namespace
 
-			if (request->itemsToCreate[i].itemToMonitor.nodeId.identifier.numeric == 2253) { // server
+            if(request->itemsToCreate[i].itemToMonitor.nodeId.identifier.numeric == 2253) {  // server
 
-				response->results[i].statusCode = UA_STATUSCODE_GOOD;
-				response->results[i].monitoredItemId = 1;
-				response->results[i].revisedSamplingInterval = 4294967295;
-				response->results[i].revisedQueueSize = 0;
-			} else {
-				// response->results[i]->statusCode = UA_STATUSCODE_BAD_NODEIDUNKNOWN;
+                response->results[i].statusCode       = UA_STATUSCODE_GOOD;
+                response->results[i].monitoredItemId  = 1;
+                response->results[i].revisedSamplingInterval = 4294967295;
+                response->results[i].revisedQueueSize = 0;
+            } else {
+                // response->results[i]->statusCode = UA_STATUSCODE_BAD_NODEIDUNKNOWN;
 
-				response->results[i].statusCode = -1;
-			}
-		}
-	}
-	//mock up
-	return UA_SUCCESS;
+                response->results[i].statusCode = -1;
+            }
+        }
+    }
+    //mock up
+    return UA_SUCCESS;
 }
 
 //#endif

+ 137 - 137
src/server/ua_services_nodemanagement.c

@@ -4,155 +4,155 @@
 #include "ua_services_internal.h"
 #include "ua_session.h"
 
-#define CHECKED_ACTION(ACTION, CLEAN_UP, GOTO) do {	\
-	status |= ACTION; \
-	if(status != UA_SUCCESS) { \
-		CLEAN_UP; \
-		goto GOTO; \
-	} } while(0) \
+#define CHECKED_ACTION(ACTION, CLEAN_UP, GOTO) do { \
+        status |= ACTION;                           \
+        if(status != UA_SUCCESS) {                  \
+            CLEAN_UP;                               \
+            goto GOTO;                              \
+        } } while(0)                                \
 
 static UA_AddNodesResult addSingleNode(UA_Server *server, UA_AddNodesItem *item) {
-	UA_AddNodesResult result;
-	UA_AddNodesResult_init(&result);
-
-	// TODO: search for namespaceUris and not only ns-ids.
-	UA_Namespace *parent_ns = UA_NULL;
-	for(UA_UInt32 i=0; i<server->namespacesSize;i++) {
-		if(server->namespaces[i].namespaceIndex == item->parentNodeId.nodeId.namespaceIndex) {
-			parent_ns = server->namespaces[i].namespace;
-			break;
-		}
-	}
-	
-	if(parent_ns == UA_NULL) {
-		result.statusCode = UA_STATUSCODE_BADPARENTNODEIDINVALID;
-		return result;
-	}
-
-	UA_Namespace *ns = UA_NULL;
-	UA_Boolean nodeid_isnull = UA_NodeId_isNull(&item->requestedNewNodeId.nodeId);
-
-	if(nodeid_isnull) ns = parent_ns;
-	else {
-		for(UA_UInt32 i=0; i<server->namespacesSize;i++) {
-			if(server->namespaces[i].namespaceIndex == item->requestedNewNodeId.nodeId.namespaceIndex) {
-				parent_ns = server->namespaces[i].namespace;
-				break;
-			}
-		}
-	}
-
-	if(ns == UA_NULL || item->requestedNewNodeId.nodeId.namespaceIndex == 0) {
-		result.statusCode = UA_STATUSCODE_BADNODEIDREJECTED;
-		return result;
-	}
-
-	UA_Int32 status = UA_SUCCESS;
-	const UA_Node *parent;
-	CHECKED_ACTION(UA_Namespace_get(parent_ns, &item->parentNodeId.nodeId, &parent),
-				   result.statusCode = UA_STATUSCODE_BADPARENTNODEIDINVALID, ret);
-
-	/* if(!nodeid_isnull && Namespace_contains(ns, &item->requestedNewNodeId.nodeId)) { */
-	/* 	result.statusCode = UA_STATUSCODE_BADNODEIDEXISTS; */
-	/* 	goto ret; */
-	/* } */
-
-	/**
-	   TODO:
-
-	   1) Check for the remaining conditions 
-	   Bad_ReferenceTypeIdInvalid  See Table 166 for the description of this result code.
-	   Bad_ReferenceNotAllowed  The reference could not be created because it violates constraints imposed by the data model.
-	   Bad_NodeClassInvalid  See Table 166 for the description of this result code.
-	   Bad_BrowseNameInvalid  See Table 166 for the description of this result code.
-	   Bad_BrowseNameDuplicated  The browse name is not unique among nodes that share the same relationship with the parent.
-	   Bad_NodeAttributesInvalid  The node Attributes are not valid for the node class.
-	   Bad_TypeDefinitionInvalid  See Table 166 for the description of this result code.
-	   Bad_UserAccessDenied  See Table 165 for the description of this result code
-
-	   2) Parse the UA_Node from the ExtensionObject
-	   3) Create a new entry in the namespace
-	   4) Add the reference to the parent.
-	 */
-
- ret:
-	UA_Namespace_releaseManagedNode(parent);
-	return result;
+    UA_AddNodesResult result;
+    UA_AddNodesResult_init(&result);
+
+    // TODO: search for namespaceUris and not only ns-ids.
+    UA_Namespace *parent_ns = UA_NULL;
+    for(UA_UInt32 i = 0;i < server->namespacesSize;i++) {
+        if(server->namespaces[i].namespaceIndex == item->parentNodeId.nodeId.namespaceIndex) {
+            parent_ns = server->namespaces[i].namespace;
+            break;
+        }
+    }
+
+    if(parent_ns == UA_NULL) {
+    result.statusCode = UA_STATUSCODE_BADPARENTNODEIDINVALID;
+    return result;
+    }
+
+    UA_Namespace *ns = UA_NULL;
+    UA_Boolean    nodeid_isnull = UA_NodeId_isNull(&item->requestedNewNodeId.nodeId);
+
+    if(nodeid_isnull) ns = parent_ns;
+    else {
+        for(UA_UInt32 i = 0;i < server->namespacesSize;i++) {
+            if(server->namespaces[i].namespaceIndex == item->requestedNewNodeId.nodeId.namespaceIndex) {
+                parent_ns = server->namespaces[i].namespace;
+                break;
+            }
+        }
+    }
+
+    if(ns == UA_NULL || item->requestedNewNodeId.nodeId.namespaceIndex == 0) {
+    result.statusCode = UA_STATUSCODE_BADNODEIDREJECTED;
+    return result;
+    }
+
+    UA_Int32       status = UA_SUCCESS;
+    const UA_Node *parent;
+    CHECKED_ACTION(UA_Namespace_get(parent_ns, &item->parentNodeId.nodeId, &parent),
+                   result.statusCode = UA_STATUSCODE_BADPARENTNODEIDINVALID, ret);
+
+    /* if(!nodeid_isnull && Namespace_contains(ns, &item->requestedNewNodeId.nodeId)) { */
+    /*  result.statusCode = UA_STATUSCODE_BADNODEIDEXISTS; */
+    /*  goto ret; */
+    /* } */
+
+    /**
+       TODO:
+
+       1) Check for the remaining conditions
+       Bad_ReferenceTypeIdInvalid  See Table 166 for the description of this result code.
+       Bad_ReferenceNotAllowed  The reference could not be created because it violates constraints imposed by the data model.
+       Bad_NodeClassInvalid  See Table 166 for the description of this result code.
+       Bad_BrowseNameInvalid  See Table 166 for the description of this result code.
+       Bad_BrowseNameDuplicated  The browse name is not unique among nodes that share the same relationship with the parent.
+       Bad_NodeAttributesInvalid  The node Attributes are not valid for the node class.
+       Bad_TypeDefinitionInvalid  See Table 166 for the description of this result code.
+       Bad_UserAccessDenied  See Table 165 for the description of this result code
+
+       2) Parse the UA_Node from the ExtensionObject
+       3) Create a new entry in the namespace
+       4) Add the reference to the parent.
+     */
+
+ret:
+    UA_Namespace_releaseManagedNode(parent);
+    return result;
 }
 
 UA_Int32 Service_AddNodes(UA_Server *server, UA_Session *session,
-						  const UA_AddNodesRequest *request, UA_AddNodesResponse *response) {
-	if(session == UA_NULL)
-		return UA_ERROR;	// TODO: Return error message
-
-	UA_Int32 nodestoaddsize = request->nodesToAddSize;
-	if(nodestoaddsize <= 0) {
-		response->responseHeader.serviceResult = UA_STATUSCODE_BADNOTHINGTODO;
-		response->resultsSize = 0;
-		return UA_SUCCESS;
-	}
-
-	response->resultsSize = nodestoaddsize;
-	UA_alloc((void **)&response->results, sizeof(void *) * nodestoaddsize);
-	for(int i = 0; i < nodestoaddsize; i++) {
-		DBG_VERBOSE(UA_QualifiedName_printf("service_addnodes - name=", &(request->nodesToAdd[i].browseName)));
-		response->results[i] = addSingleNode(server, &request->nodesToAdd[i]);
-	}
-	response->responseHeader.serviceResult = UA_STATUSCODE_GOOD;
-	response->diagnosticInfosSize = -1;
-	return UA_SUCCESS;
-	
+                          const UA_AddNodesRequest *request, UA_AddNodesResponse *response) {
+    if(session == UA_NULL)
+        return UA_ERROR;    // TODO: Return error message
+
+    UA_Int32 nodestoaddsize = request->nodesToAddSize;
+    if(nodestoaddsize <= 0) {
+        response->responseHeader.serviceResult = UA_STATUSCODE_BADNOTHINGTODO;
+        response->resultsSize = 0;
+        return UA_SUCCESS;
+    }
+
+    response->resultsSize = nodestoaddsize;
+    UA_alloc((void **)&response->results, sizeof(void *) * nodestoaddsize);
+    for(int i = 0;i < nodestoaddsize;i++) {
+        DBG_VERBOSE(UA_QualifiedName_printf("service_addnodes - name=", &(request->nodesToAdd[i].browseName)));
+        response->results[i] = addSingleNode(server, &request->nodesToAdd[i]);
+    }
+    response->responseHeader.serviceResult = UA_STATUSCODE_GOOD;
+    response->diagnosticInfosSize = -1;
+    return UA_SUCCESS;
+
 }
 
 static UA_Int32 AddSingleReference(UA_Node *node, UA_ReferenceNode *reference) {
-	// TODO: Check if reference already exists
-	UA_Int32 retval;
-	UA_Int32 count = node->referencesSize;
-	UA_ReferenceNode *old_refs = node->references;
-	UA_ReferenceNode *new_refs;
-	if(count < 0) count = 0; 
-
-	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);
-	retval |= UA_ReferenceNode_copy(reference, &new_refs[count]);
-
-	if(retval != UA_SUCCESS) {
-		UA_free(new_refs);
-		return retval;
-	}
-	
-	node->references = new_refs;
-	node->referencesSize = count+1;
-	UA_free(old_refs);
-	return retval;
+    // TODO: Check if reference already exists
+    UA_Int32 retval;
+    UA_Int32 count = node->referencesSize;
+    UA_ReferenceNode *old_refs = node->references;
+    UA_ReferenceNode *new_refs;
+    if(count < 0) count = 0;
+
+    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);
+    retval |= UA_ReferenceNode_copy(reference, &new_refs[count]);
+
+    if(retval != UA_SUCCESS) {
+        UA_free(new_refs);
+        return retval;
+    }
+
+    node->references     = new_refs;
+    node->referencesSize = count+1;
+    UA_free(old_refs);
+    return retval;
 }
 
 UA_Int32 AddReference(UA_Node *node, UA_ReferenceNode *reference, UA_Namespace *targetns) {
-	UA_Int32 retval = AddSingleReference(node, reference);
-	UA_Node *targetnode;
-	UA_ReferenceNode inversereference;
-	if(retval != UA_SUCCESS || targetns == UA_NULL)
-		return retval;
-
-	// Do a copy every time?
-	if(UA_Namespace_get(targetns, &reference->targetId.nodeId, (const UA_Node**)&targetnode) != UA_SUCCESS)
-		return UA_ERROR;
-
-	inversereference.referenceTypeId = reference->referenceTypeId;
-	inversereference.isInverse = !reference->isInverse;
-	inversereference.targetId.nodeId = node->nodeId;
-	inversereference.targetId.namespaceUri = UA_STRING_NULL;
-	inversereference.targetId.serverIndex = 0;
-	retval = AddSingleReference(targetnode, &inversereference);
-	UA_Namespace_releaseManagedNode(targetnode);
-
-	return retval;
+    UA_Int32 retval = AddSingleReference(node, reference);
+    UA_Node *targetnode;
+    UA_ReferenceNode inversereference;
+    if(retval != UA_SUCCESS || targetns == UA_NULL)
+        return retval;
+
+    // Do a copy every time?
+    if(UA_Namespace_get(targetns, &reference->targetId.nodeId, (const UA_Node **)&targetnode) != UA_SUCCESS)
+        return UA_ERROR;
+
+    inversereference.referenceTypeId       = reference->referenceTypeId;
+    inversereference.isInverse             = !reference->isInverse;
+    inversereference.targetId.nodeId       = node->nodeId;
+    inversereference.targetId.namespaceUri = UA_STRING_NULL;
+    inversereference.targetId.serverIndex  = 0;
+    retval = AddSingleReference(targetnode, &inversereference);
+    UA_Namespace_releaseManagedNode(targetnode);
+
+    return retval;
 }
 
 UA_Int32 Service_AddReferences(UA_Server *server, UA_Session *session,
-							   const UA_AddReferencesRequest *request,
-							   UA_AddReferencesResponse *response) {
-	return UA_ERROR;
+                               const UA_AddReferencesRequest *request,
+                               UA_AddReferencesResponse *response) {
+    return UA_ERROR;
 }

+ 13 - 14
src/server/ua_services_securechannel.c

@@ -1,21 +1,20 @@
 #include "ua_services.h"
 
 UA_Int32 Service_OpenSecureChannel(UA_Server *server, UA_Connection *connection,
-								   const UA_OpenSecureChannelRequest* request,
-								   UA_OpenSecureChannelResponse* response) {
-	UA_Int32 retval = UA_SUCCESS;
-	// todo: if(request->clientProtocolVersion != protocolVersion)
-	if(request->requestType == UA_SECURITYTOKEN_ISSUE) {
-		retval |= UA_SecureChannelManager_open(server->secureChannelManager, connection, request, response);
-	} else {
-		retval |= UA_SecureChannelManager_renew(server->secureChannelManager, connection, request, response);
-	}
-	return retval;
+                                   const UA_OpenSecureChannelRequest *request,
+                                   UA_OpenSecureChannelResponse *response) {
+    UA_Int32 retval = UA_SUCCESS;
+    // todo: if(request->clientProtocolVersion != protocolVersion)
+    if(request->requestType == UA_SECURITYTOKEN_ISSUE)
+        retval |= UA_SecureChannelManager_open(server->secureChannelManager, connection, request, response);
+    else
+        retval |= UA_SecureChannelManager_renew(server->secureChannelManager, connection, request, response);
+    return retval;
 }
 
 UA_Int32 Service_CloseSecureChannel(UA_Server *server, UA_SecureChannel *channel,
-									const UA_CloseSecureChannelRequest *request,
-									UA_CloseSecureChannelResponse *response) {
-	return UA_SecureChannelManager_close(server->secureChannelManager, channel->securityToken.channelId);
-	// 62451 Part 6 Chapter 7.1.4 - The server does not send a CloseSecureChannel response
+                                    const UA_CloseSecureChannelRequest *request,
+                                    UA_CloseSecureChannelResponse *response) {
+    return UA_SecureChannelManager_close(server->secureChannelManager, channel->securityToken.channelId);
+    // 62451 Part 6 Chapter 7.1.4 - The server does not send a CloseSecureChannel response
 }

+ 32 - 32
src/server/ua_services_session.c

@@ -2,45 +2,45 @@
 #include "ua_server.h"
 
 UA_Int32 Service_CreateSession(UA_Server *server, UA_SecureChannel *channel,
-							   const UA_CreateSessionRequest *request,
-							   UA_CreateSessionResponse *response) {
-	/* UA_Session *newSession;
-	UA_Int64 timeout;
+                               const UA_CreateSessionRequest *request,
+                               UA_CreateSessionResponse *response) {
+    /* UA_Session *newSession;
+       UA_Int64 timeout;
 
-	UA_SessionManager_getSessionTimeout(&timeout);
-	UA_Session_new(&newSession);
-	//TODO get maxResponseMessageSize
-	UA_Session_setApplicationPointer(newSession, &server->applications[0]); // todo: select application according to the endpointurl in the request
-	UA_Session_init(newSession, (UA_String*)&request->sessionName,
-	request->requestedSessionTimeout,
-	request->maxResponseMessageSize,
-	9999,
-	(UA_Session_idProvider)UA_SessionManager_generateSessionId,
-	timeout);
+       UA_SessionManager_getSessionTimeout(&timeout);
+       UA_Session_new(&newSession);
+       //TODO get maxResponseMessageSize
+       UA_Session_setApplicationPointer(newSession, &server->applications[0]); // todo: select application according to the endpointurl in the request
+       UA_Session_init(newSession, (UA_String*)&request->sessionName,
+       request->requestedSessionTimeout,
+       request->maxResponseMessageSize,
+       9999,
+       (UA_Session_idProvider)UA_SessionManager_generateSessionId,
+       timeout);
 
-	UA_SessionManager_addSession(newSession);
-	UA_Session_getId(newSession, &response->sessionId);
-	UA_Session_getToken(newSession, &(response->authenticationToken));
-	response->revisedSessionTimeout = timeout; */
-	//TODO fill results
-	return UA_SUCCESS;
+       UA_SessionManager_addSession(newSession);
+       UA_Session_getId(newSession, &response->sessionId);
+       UA_Session_getToken(newSession, &(response->authenticationToken));
+       response->revisedSessionTimeout = timeout; */
+    //TODO fill results
+    return UA_SUCCESS;
 }
 
 UA_Int32 Service_ActivateSession(UA_Server *server, UA_Session *session,
-								 const UA_ActivateSessionRequest *request,
-								 UA_ActivateSessionResponse *response) {
-	//UA_Session_bind(session, channel);
-	//TODO fill results
-	return UA_SUCCESS;
+                                 const UA_ActivateSessionRequest *request,
+                                 UA_ActivateSessionResponse *response) {
+    //UA_Session_bind(session, channel);
+    //TODO fill results
+    return UA_SUCCESS;
 }
 
 UA_Int32 Service_CloseSession(UA_Server *server, UA_Session *session,
-							  const UA_CloseSessionRequest *request,
-							  UA_CloseSessionResponse *response) {
-	/* UA_NodeId sessionId; */
-	/* UA_Session_getId(session,&sessionId); */
+                              const UA_CloseSessionRequest *request,
+                              UA_CloseSessionResponse *response) {
+    /* UA_NodeId sessionId; */
+    /* UA_Session_getId(session,&sessionId); */
 
-	/* UA_SessionManager_removeSession(&sessionId); */
-	// FIXME: set response
-	return UA_SUCCESS;
+    /* UA_SessionManager_removeSession(&sessionId); */
+    // FIXME: set response
+    return UA_SUCCESS;
 }

+ 18 - 18
src/server/ua_services_subscription.c

@@ -8,31 +8,31 @@
 #include "ua_statuscodes.h"
 
 UA_Int32 Service_CreateSubscription(UA_Server *server, UA_Session *session,
-									const UA_CreateSubscriptionRequest *request,
-									UA_CreateSubscriptionResponse *response) {
+                                    const UA_CreateSubscriptionRequest *request,
+                                    UA_CreateSubscriptionResponse *response) {
 
-	response->subscriptionId = 42;
-	response->revisedPublishingInterval = 100000;
-	response->revisedLifetimeCount = 120000;
-	response->revisedMaxKeepAliveCount = 50;
-	return UA_SUCCESS;
+    response->subscriptionId            = 42;
+    response->revisedPublishingInterval = 100000;
+    response->revisedLifetimeCount      = 120000;
+    response->revisedMaxKeepAliveCount  = 50;
+    return UA_SUCCESS;
 }
 
 UA_Int32 Service_Publish(UA_Server *server, UA_Session *session,
-						 const UA_PublishRequest *request,
-						 UA_PublishResponse *response) {
+                         const UA_PublishRequest *request,
+                         UA_PublishResponse *response) {
 
-	response->subscriptionId = 42;
-	response->notificationMessage.sequenceNumber = 1;
-	response->notificationMessage.publishTime = UA_DateTime_now();
-	return UA_SUCCESS;
+    response->subscriptionId = 42;
+    response->notificationMessage.sequenceNumber = 1;
+    response->notificationMessage.publishTime    = UA_DateTime_now();
+    return UA_SUCCESS;
 }
 
 UA_Int32 Service_SetPublishingMode(UA_Server *server, UA_Session *session,
-								   const UA_SetPublishingModeRequest *request,
+                                   const UA_SetPublishingModeRequest *request,
                                    UA_SetPublishingModeResponse *response) {
-	response->diagnosticInfos = UA_NULL;
-	response->results = UA_NULL;
-	response->resultsSize = 0;
-	return UA_SUCCESS;
+    response->diagnosticInfos = UA_NULL;
+    response->results = UA_NULL;
+    response->resultsSize     = 0;
+    return UA_SUCCESS;
 }

+ 232 - 222
src/server/ua_services_view.c

@@ -1,251 +1,261 @@
 #include "ua_services.h"
 #include "ua_statuscodes.h"
 
-UA_Int32 Service_Browse_getReferenceDescription(UA_Namespace *ns, UA_ReferenceNode* reference,
-												UA_UInt32 nodeClassMask, UA_UInt32 resultMask,
-												UA_ReferenceDescription* referenceDescription) {
-	const UA_Node* foundNode;
-	if(UA_Namespace_get(ns,&reference->targetId.nodeId,&foundNode) != UA_SUCCESS)
-		return UA_ERROR;
-
-	UA_NodeId_copy(&foundNode->nodeId, &referenceDescription->nodeId.nodeId);
-	//TODO ExpandedNodeId is a mockup
-	referenceDescription->nodeId.serverIndex = 0;
-	referenceDescription->nodeId.namespaceUri.length = -1;
-
-	UA_UInt32 mask = 0;
-	for (mask = 0x01; mask <= 0x40; mask *= 2) {
-		switch (mask & (resultMask)) {
-		case UA_BROWSERESULTMASK_REFERENCETYPEID:
-			UA_NodeId_copy(&reference->referenceTypeId, &referenceDescription->referenceTypeId);
-			break;
-		case UA_BROWSERESULTMASK_ISFORWARD:
-			referenceDescription->isForward = !reference->isInverse;
-			break;
-		case UA_BROWSERESULTMASK_NODECLASS:
-			UA_NodeClass_copy(&foundNode->nodeClass, &referenceDescription->nodeClass);
-			break;
-		case UA_BROWSERESULTMASK_BROWSENAME:
-			UA_QualifiedName_copy(&foundNode->browseName, &referenceDescription->browseName);
-			break;
-		case UA_BROWSERESULTMASK_DISPLAYNAME:
-			UA_LocalizedText_copy(&foundNode->displayName, &referenceDescription->displayName);
-			break;
-		case UA_BROWSERESULTMASK_TYPEDEFINITION:
-			if (foundNode->nodeClass != UA_NODECLASS_OBJECT &&
-				foundNode->nodeClass != UA_NODECLASS_VARIABLE)
-				break;
-
-			for(UA_Int32 i = 0;i<foundNode->referencesSize;i++) {
-				UA_ReferenceNode *ref = &foundNode->references[i];
-				if(ref->referenceTypeId.identifier.numeric == 40 /* hastypedefinition */) {
-					UA_ExpandedNodeId_copy(&ref->targetId, &referenceDescription->typeDefinition);
-					break;
-				}
-			}
-			break;
-		}
-	}
-	
-	UA_Namespace_releaseManagedNode(foundNode);
-	return UA_SUCCESS;
+UA_Int32 Service_Browse_getReferenceDescription(UA_Namespace *ns, UA_ReferenceNode *reference,
+                                                UA_UInt32 nodeClassMask, UA_UInt32 resultMask,
+                                                UA_ReferenceDescription *referenceDescription) {
+    const UA_Node *foundNode;
+    if(UA_Namespace_get(ns, &reference->targetId.nodeId, &foundNode) != UA_SUCCESS)
+        return UA_ERROR;
+
+    UA_NodeId_copy(&foundNode->nodeId, &referenceDescription->nodeId.nodeId);
+    //TODO ExpandedNodeId is a mockup
+    referenceDescription->nodeId.serverIndex = 0;
+    referenceDescription->nodeId.namespaceUri.length = -1;
+
+    UA_UInt32 mask = 0;
+    for(mask = 0x01;mask <= 0x40;mask *= 2) {
+        switch(mask & (resultMask)) {
+        case UA_BROWSERESULTMASK_REFERENCETYPEID:
+            UA_NodeId_copy(&reference->referenceTypeId, &referenceDescription->referenceTypeId);
+            break;
+
+        case UA_BROWSERESULTMASK_ISFORWARD:
+            referenceDescription->isForward = !reference->isInverse;
+            break;
+
+        case UA_BROWSERESULTMASK_NODECLASS:
+            UA_NodeClass_copy(&foundNode->nodeClass, &referenceDescription->nodeClass);
+            break;
+
+        case UA_BROWSERESULTMASK_BROWSENAME:
+            UA_QualifiedName_copy(&foundNode->browseName, &referenceDescription->browseName);
+            break;
+
+        case UA_BROWSERESULTMASK_DISPLAYNAME:
+            UA_LocalizedText_copy(&foundNode->displayName, &referenceDescription->displayName);
+            break;
+
+        case UA_BROWSERESULTMASK_TYPEDEFINITION:
+            if(foundNode->nodeClass != UA_NODECLASS_OBJECT &&
+               foundNode->nodeClass != UA_NODECLASS_VARIABLE)
+                break;
+
+            for(UA_Int32 i = 0;i < foundNode->referencesSize;i++) {
+                UA_ReferenceNode *ref = &foundNode->references[i];
+                if(ref->referenceTypeId.identifier.numeric == 40 /* hastypedefinition */) {
+                    UA_ExpandedNodeId_copy(&ref->targetId, &referenceDescription->typeDefinition);
+                    break;
+                }
+            }
+            break;
+        }
+    }
+
+    UA_Namespace_releaseManagedNode(foundNode);
+    return UA_SUCCESS;
 }
 
 /* singly-linked list */
 struct SubRefTypeId {
-	UA_NodeId id;
-	SLIST_ENTRY(SubRefTypeId) next;
+    UA_NodeId id;
+    SLIST_ENTRY(SubRefTypeId) next;
 };
 SLIST_HEAD(SubRefTypeIdList, SubRefTypeId);
 
 UA_UInt32 walkReferenceTree(UA_Namespace *ns, const UA_ReferenceTypeNode *current,
-							struct SubRefTypeIdList *list) {
-	// insert the current referencetype
-	struct SubRefTypeId *element;
-	UA_alloc((void**)&element, sizeof(struct SubRefTypeId));
-	element->id = current->nodeId;
-	SLIST_INSERT_HEAD(list, element, next);
-
-	UA_UInt32 count = 1; // the current element
-
-	// walk the tree
-	for(UA_Int32 i = 0;i < current->referencesSize;i++) {
-		if(current->references[i].referenceTypeId.identifier.numeric == 45 /* HasSubtype */ &&
-		   current->references[i].isInverse == UA_FALSE) {
-			const UA_Node *node;
-			if(UA_Namespace_get(ns, &current->references[i].targetId.nodeId, &node) == UA_SUCCESS
-			   && node->nodeClass == UA_NODECLASS_REFERENCETYPE) {
-				count += walkReferenceTree(ns,(UA_ReferenceTypeNode*)node, list);
-				UA_Namespace_releaseManagedNode(node);
-			}
-		}
-	}
-	return count;
+                            struct SubRefTypeIdList *list) {
+    // insert the current referencetype
+    struct SubRefTypeId *element;
+    UA_alloc((void **)&element, sizeof(struct SubRefTypeId));
+    element->id = current->nodeId;
+    SLIST_INSERT_HEAD(list, element, next);
+
+    UA_UInt32 count = 1; // the current element
+
+    // walk the tree
+    for(UA_Int32 i = 0;i < current->referencesSize;i++) {
+        if(current->references[i].referenceTypeId.identifier.numeric == 45 /* HasSubtype */ &&
+           current->references[i].isInverse == UA_FALSE) {
+            const UA_Node *node;
+            if(UA_Namespace_get(ns, &current->references[i].targetId.nodeId, &node) == UA_SUCCESS
+               && node->nodeClass == UA_NODECLASS_REFERENCETYPE) {
+                count += walkReferenceTree(ns, (UA_ReferenceTypeNode *)node, list);
+                UA_Namespace_releaseManagedNode(node);
+            }
+        }
+    }
+    return count;
 }
 
 /* We do not search across namespaces so far. The id of the father-referencetype is returned in the array also. */
 static UA_Int32 findSubReferenceTypes(UA_Namespace *ns, UA_NodeId *rootReferenceType,
-									  UA_NodeId **ids, UA_UInt32 *idcount) {
-	struct SubRefTypeIdList list;
-	UA_UInt32 count;
-	SLIST_INIT(&list);
-
-	// walk the tree
-	const UA_ReferenceTypeNode *root;
-	if(UA_Namespace_get(ns, rootReferenceType, (const UA_Node**)&root) != UA_SUCCESS ||
-	   root->nodeClass != UA_NODECLASS_REFERENCETYPE)
-		return UA_ERROR;
-	count = walkReferenceTree(ns, root, &list);
-	UA_Namespace_releaseManagedNode((const UA_Node*) root);
-
-	// copy results into an array
-	UA_alloc((void**) ids, sizeof(UA_NodeId)*count);
-	for(UA_UInt32 i = 0; i < count;i++) {
-		struct SubRefTypeId *element = SLIST_FIRST(&list);
-		UA_NodeId_copy(&element->id, &(*ids)[i]);
-		SLIST_REMOVE_HEAD(&list, next);
-		UA_free(element);
-	}
-	*idcount = count;
-
-	return UA_SUCCESS;
+                                      UA_NodeId **ids, UA_UInt32 *idcount) {
+    struct SubRefTypeIdList list;
+    UA_UInt32 count;
+    SLIST_INIT(&list);
+
+    // walk the tree
+    const UA_ReferenceTypeNode *root;
+    if(UA_Namespace_get(ns, rootReferenceType, (const UA_Node **)&root) != UA_SUCCESS ||
+       root->nodeClass != UA_NODECLASS_REFERENCETYPE)
+        return UA_ERROR;
+    count = walkReferenceTree(ns, root, &list);
+    UA_Namespace_releaseManagedNode((const UA_Node *)root);
+
+    // copy results into an array
+    UA_alloc((void **)ids, sizeof(UA_NodeId)*count);
+    for(UA_UInt32 i = 0;i < count;i++) {
+        struct SubRefTypeId *element = SLIST_FIRST(&list);
+        UA_NodeId_copy(&element->id, &(*ids)[i]);
+        SLIST_REMOVE_HEAD(&list, next);
+        UA_free(element);
+    }
+    *idcount = count;
+
+    return UA_SUCCESS;
 }
 
 /* is this a relevant 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;
-	else if (reference->isInverse == UA_FALSE &&
-			 browseDescription->browseDirection == UA_BROWSEDIRECTION_INVERSE)
-		return UA_FALSE;
-	for(UA_UInt32 i = 0; i<relevantRefTypesCount;i++) {
-		if(UA_NodeId_equal(&browseDescription->referenceTypeId, &relevantRefTypes[i]) == UA_EQUAL)
-			return UA_TRUE;
-	}
-	return UA_FALSE;
+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;
+    else if(reference->isInverse == UA_FALSE &&
+            browseDescription->browseDirection == UA_BROWSEDIRECTION_INVERSE)
+        return UA_FALSE;
+    for(UA_UInt32 i = 0;i < relevantRefTypesCount;i++) {
+        if(UA_NodeId_equal(&browseDescription->referenceTypeId, &relevantRefTypes[i]) == UA_EQUAL)
+            return UA_TRUE;
+    }
+    return UA_FALSE;
 }
 
 /* Return results to a single browsedescription. */
-static void Service_Browse_getBrowseResult(UA_Namespace *ns,
-										   UA_BrowseDescription *browseDescription,
-										   UA_UInt32 maxReferences,
-										   UA_BrowseResult *browseResult) {
-	const UA_Node* node;
-	UA_NodeId *relevantReferenceTypes;
-	UA_UInt32 relevantReferenceTypesCount = 0;
-	if(UA_Namespace_get(ns, &browseDescription->nodeId, &node) != UA_SUCCESS) {
-		browseResult->statusCode = UA_STATUSCODE_BADNODEIDUNKNOWN;
-		return;
-	}
-
-	// 0 => unlimited references
-	if(maxReferences == 0)
-		maxReferences = node->referencesSize;
-
-	// discover the relevant subtypes
-	if(!browseDescription->includeSubtypes ||
-	   findSubReferenceTypes(ns, &browseDescription->referenceTypeId, &relevantReferenceTypes,
-							 &relevantReferenceTypesCount) != UA_SUCCESS) {
-		UA_alloc((void**)&relevantReferenceTypes, sizeof(UA_NodeId));
-		UA_NodeId_copy(&browseDescription->referenceTypeId, relevantReferenceTypes);
-		relevantReferenceTypesCount = 1;
-	}
-
-	/* We do not use a linked list but traverse the nodes references list twice
-	 * (once for counting, once for generating the referencedescriptions). That
-	 * is much faster than using a linked list, since the references are
-	 * allocated in a continuous blob and RAM access is predictible/does not
-	 * miss cache lines so often. TODO: measure with some huge objects! */
-	UA_UInt32 refs = 0;
-	for(UA_Int32 i=0;i < node->referencesSize && refs <= maxReferences;i++) {
-		if(Service_Browse_returnReference(browseDescription, &node->references[i], relevantReferenceTypes, relevantReferenceTypesCount))
-			refs++;
-	}
-
-	// can we return all relevant references at once?
-	UA_Boolean finished = UA_TRUE;
-	if(refs > maxReferences) {
-		refs--;
-		finished = UA_FALSE;
-	}
-	
-	browseResult->referencesSize = refs;
-	UA_Array_new((void**) &browseResult->references, refs, &UA_.types[UA_REFERENCEDESCRIPTION]);
-	
-	for(UA_UInt32 i = 0, j=0; j < refs; i++) {
-		if(!Service_Browse_returnReference(browseDescription, &node->references[i], relevantReferenceTypes, relevantReferenceTypesCount))
-			continue;
-		
-		if(Service_Browse_getReferenceDescription(ns, &node->references[i], browseDescription->nodeClassMask,
-												  browseDescription->resultMask, &browseResult->references[j]) != UA_SUCCESS)
-			browseResult->statusCode = UA_STATUSCODE_UNCERTAINNOTALLNODESAVAILABLE;
-		j++;
-	}
-
-	if(!finished) {
-		// Todo. Set the Statuscode and the continuation point.
-	}
-	
-	UA_Namespace_releaseManagedNode(node);
-	UA_Array_delete(relevantReferenceTypes, relevantReferenceTypesCount, &UA_.types[UA_NODEID]);
+static void Service_Browse_getBrowseResult(UA_Namespace         *ns,
+                                           UA_BrowseDescription *browseDescription,
+                                           UA_UInt32             maxReferences,
+                                           UA_BrowseResult      *browseResult) {
+    const UA_Node *node;
+    UA_NodeId     *relevantReferenceTypes;
+    UA_UInt32      relevantReferenceTypesCount = 0;
+    if(UA_Namespace_get(ns, &browseDescription->nodeId, &node) != UA_SUCCESS) {
+        browseResult->statusCode = UA_STATUSCODE_BADNODEIDUNKNOWN;
+        return;
+    }
+
+    // 0 => unlimited references
+    if(maxReferences == 0)
+        maxReferences = node->referencesSize;
+
+    // discover the relevant subtypes
+    if(!browseDescription->includeSubtypes ||
+       findSubReferenceTypes(ns, &browseDescription->referenceTypeId, &relevantReferenceTypes,
+                             &relevantReferenceTypesCount) != UA_SUCCESS) {
+        UA_alloc((void **)&relevantReferenceTypes, sizeof(UA_NodeId));
+        UA_NodeId_copy(&browseDescription->referenceTypeId, relevantReferenceTypes);
+        relevantReferenceTypesCount = 1;
+    }
+
+    /* We do not use a linked list but traverse the nodes references list twice
+     * (once for counting, once for generating the referencedescriptions). That
+     * is much faster than using a linked list, since the references are
+     * allocated in a continuous blob and RAM access is predictible/does not
+     * miss cache lines so often. TODO: measure with some huge objects! */
+    UA_UInt32 refs = 0;
+    for(UA_Int32 i = 0;i < node->referencesSize && refs <= maxReferences;i++) {
+        if(Service_Browse_returnReference(browseDescription, &node->references[i], relevantReferenceTypes,
+                                          relevantReferenceTypesCount))
+            refs++;
+    }
+
+    // can we return all relevant references at once?
+    UA_Boolean finished = UA_TRUE;
+    if(refs > maxReferences) {
+        refs--;
+        finished = UA_FALSE;
+    }
+
+    browseResult->referencesSize = refs;
+    UA_Array_new((void **)&browseResult->references, refs, &UA_.types[UA_REFERENCEDESCRIPTION]);
+
+    for(UA_UInt32 i = 0, j = 0;j < refs;i++) {
+        if(!Service_Browse_returnReference(browseDescription, &node->references[i], relevantReferenceTypes,
+                                           relevantReferenceTypesCount))
+            continue;
+
+        if(Service_Browse_getReferenceDescription(ns, &node->references[i], browseDescription->nodeClassMask,
+                                                  browseDescription->resultMask,
+                                                  &browseResult->references[j]) != UA_SUCCESS)
+            browseResult->statusCode = UA_STATUSCODE_UNCERTAINNOTALLNODESAVAILABLE;
+        j++;
+    }
+
+    if(!finished) {
+        // Todo. Set the Statuscode and the continuation point.
+    }
+
+    UA_Namespace_releaseManagedNode(node);
+    UA_Array_delete(relevantReferenceTypes, relevantReferenceTypesCount, &UA_.types[UA_NODEID]);
 }
 
 UA_Int32 Service_Browse(UA_Server *server, UA_Session *session,
-						const UA_BrowseRequest *request, UA_BrowseResponse *response) {
-	UA_Int32 retval = UA_SUCCESS;
-	if(server == UA_NULL || session == UA_NULL)
-		return UA_ERROR;
-	
-	//TODO request->view not used atm
-	UA_Array_new((void**) &(response->results), request->nodesToBrowseSize, &UA_.types[UA_BROWSERESULT]);
-	response->resultsSize = request->nodesToBrowseSize;
-
-	for(UA_Int32 i=0; i < request->nodesToBrowseSize; i++) {
-		UA_Namespace *ns = UA_NULL;
-
-		for(UA_UInt32 i=0; i<server->namespacesSize;i++) {
-			if(server->namespaces[i].namespaceIndex ==
-			   request->nodesToBrowse[i].nodeId.namespaceIndex) {
-				ns = server->namespaces[i].namespace;
-				break;
-			}
-		}
-
-		if(ns == UA_NULL) {
-			response->results[i].statusCode = UA_STATUSCODE_BADNODEIDUNKNOWN;
-			continue;
-		}
-		
-		// Service_Browse_getBrowseResult has no return value. All errors are resolved internally.
-		Service_Browse_getBrowseResult(ns, &request->nodesToBrowse[i],
-									   request->requestedMaxReferencesPerNode,
-									   &response->results[i]);
-	}
-
-	//TODO fill Diagnostic info array
-	response->diagnosticInfosSize = 0;
-	response->diagnosticInfos = UA_NULL;
-	return retval;
+                        const UA_BrowseRequest *request, UA_BrowseResponse *response) {
+    UA_Int32 retval = UA_SUCCESS;
+    if(server == UA_NULL || session == UA_NULL)
+        return UA_ERROR;
+
+    //TODO request->view not used atm
+    UA_Array_new((void **)&(response->results), request->nodesToBrowseSize, &UA_.types[UA_BROWSERESULT]);
+    response->resultsSize = request->nodesToBrowseSize;
+
+    for(UA_Int32 i = 0;i < request->nodesToBrowseSize;i++) {
+        UA_Namespace *ns = UA_NULL;
+
+        for(UA_UInt32 i = 0;i < server->namespacesSize;i++) {
+            if(server->namespaces[i].namespaceIndex ==
+               request->nodesToBrowse[i].nodeId.namespaceIndex) {
+                ns = server->namespaces[i].namespace;
+                break;
+            }
+        }
+
+        if(ns == UA_NULL) {
+        response->results[i].statusCode = UA_STATUSCODE_BADNODEIDUNKNOWN;
+        continue;
+        }
+
+        // Service_Browse_getBrowseResult has no return value. All errors are resolved internally.
+        Service_Browse_getBrowseResult(ns, &request->nodesToBrowse[i],
+                                       request->requestedMaxReferencesPerNode,
+                                       &response->results[i]);
+    }
+
+    //TODO fill Diagnostic info array
+    response->diagnosticInfosSize = 0;
+    response->diagnosticInfos     = UA_NULL;
+    return retval;
 }
 
 
 UA_Int32 Service_TranslateBrowsePathsToNodeIds(UA_Server *server, UA_Session *session,
-											   const UA_TranslateBrowsePathsToNodeIdsRequest *request,
-											   UA_TranslateBrowsePathsToNodeIdsResponse *response) {
-	UA_Int32 retval = UA_SUCCESS;
-	DBG_VERBOSE(printf("TranslateBrowsePathsToNodeIdsService - %i path(s)", request->browsePathsSize));
-
-	// Allocate space for a correct answer
-	response->resultsSize = request->browsePathsSize;
-	// _init of the elements is done in Array_new
-	UA_Array_new((void**) &response->results, request->browsePathsSize, &UA_.types[UA_BROWSEPATHRESULT]);
-
-	for (UA_Int32 i = 0; i < request->browsePathsSize; i++) {
-		//FIXME: implement
-		response->results[i].statusCode = UA_STATUSCODE_BADNOMATCH;
-	}
-
-	return retval;
+                                               const UA_TranslateBrowsePathsToNodeIdsRequest *request,
+                                               UA_TranslateBrowsePathsToNodeIdsResponse *response) {
+    UA_Int32 retval = UA_SUCCESS;
+    DBG_VERBOSE(printf("TranslateBrowsePathsToNodeIdsService - %i path(s)", request->browsePathsSize));
+
+    // Allocate space for a correct answer
+    response->resultsSize = request->browsePathsSize;
+    // _init of the elements is done in Array_new
+    UA_Array_new((void **)&response->results, request->browsePathsSize, &UA_.types[UA_BROWSEPATHRESULT]);
+
+    for(UA_Int32 i = 0;i < request->browsePathsSize;i++) {
+        //FIXME: implement
+        response->results[i].statusCode = UA_STATUSCODE_BADNOMATCH;
+    }
+
+    return retval;
 }

+ 127 - 124
src/server/ua_session_manager.c

@@ -2,156 +2,159 @@
 #include "util/ua_list.h"
 
 struct UA_SessionManager {
-	UA_list_List sessions;
-	UA_UInt32 maxSessionCount;
-	UA_Int32 lastSessionId;
-	UA_UInt32 currentSessionCount;
-	UA_DateTime maxSessionLifeTime;
-	UA_DateTime sessionTimeout;
+    UA_list_List sessions;
+    UA_UInt32    maxSessionCount;
+    UA_Int32     lastSessionId;
+    UA_UInt32    currentSessionCount;
+    UA_DateTime  maxSessionLifeTime;
+    UA_DateTime  sessionTimeout;
 };
 UA_Int32 UA_SessionManager_new(UA_SessionManager **sessionManager, UA_UInt32 maxSessionCount,
-								UA_UInt32 sessionTimeout, UA_UInt32 startSessionId) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_alloc((void**)sessionManager,sizeof(UA_SessionManager));
-	retval |= UA_list_init(&(*sessionManager)->sessions);
-	(*sessionManager)->maxSessionCount = maxSessionCount;
-	(*sessionManager)->lastSessionId = startSessionId;
-	(*sessionManager)->sessionTimeout = sessionTimeout;
-	return retval;
+                               UA_UInt32 sessionTimeout, UA_UInt32 startSessionId) {
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_alloc((void **)sessionManager, sizeof(UA_SessionManager));
+    retval |= UA_list_init(&(*sessionManager)->sessions);
+    (*sessionManager)->maxSessionCount = maxSessionCount;
+    (*sessionManager)->lastSessionId   = startSessionId;
+    (*sessionManager)->sessionTimeout  = sessionTimeout;
+    return retval;
 }
 
 UA_Int32 UA_SessionManager_delete(UA_SessionManager *sessionManager) {
-	// todo
-	return UA_SUCCESS;
+    // todo
+    return UA_SUCCESS;
 }
 
 
 UA_Int32 UA_SessionManager_generateSessionId(UA_SessionManager *sessionManager,
-											 UA_NodeId *sessionId) {
-	sessionId->namespaceIndex = 0;
-	sessionId->identifierType = UA_NODEIDTYPE_NUMERIC;
-	sessionId->identifier.numeric = sessionManager->lastSessionId++;
-	return UA_SUCCESS;
+                                             UA_NodeId         *sessionId) {
+    sessionId->namespaceIndex     = 0;
+    sessionId->identifierType     = UA_NODEIDTYPE_NUMERIC;
+    sessionId->identifier.numeric = sessionManager->lastSessionId++;
+    return UA_SUCCESS;
 }
 
 UA_Boolean UA_SessionManager_sessionExists(UA_SessionManager *sessionManager,
-										   UA_Session *session) {
-	if(sessionManager == UA_NULL)
-		return UA_FALSE;
-
-	if(UA_list_search(&sessionManager->sessions,
-					  (UA_list_PayloadComparer)UA_Session_compare,(void*)session)) {
-		UA_Double pendingLifetime;
-		UA_Session_getPendingLifetime(session,&pendingLifetime);
-
-		if(pendingLifetime>0)
-			return UA_TRUE;
-
-		//timeout of session reached so remove it
-		UA_NodeId *sessionId = &session->sessionId;
-		UA_SessionManager_removeSession(sessionManager, sessionId);
-	}
-	return UA_FALSE;
+                                           UA_Session        *session) {
+    if(sessionManager == UA_NULL)
+        return UA_FALSE;
+
+    if(UA_list_search(&sessionManager->sessions,
+                      (UA_list_PayloadComparer)UA_Session_compare, (void *)session)) {
+        UA_Double pendingLifetime;
+        UA_Session_getPendingLifetime(session, &pendingLifetime);
+
+        if(pendingLifetime > 0)
+            return UA_TRUE;
+
+        //timeout of session reached so remove it
+        UA_NodeId *sessionId = &session->sessionId;
+        UA_SessionManager_removeSession(sessionManager, sessionId);
+    }
+    return UA_FALSE;
 }
 
 UA_Int32 UA_SessionManager_getSessionById(UA_SessionManager *sessionManager,
-										  UA_NodeId *sessionId, UA_Session **session) {
-	if(sessionManager == UA_NULL) {
-		*session = UA_NULL;
-		return UA_ERROR;
-	}
-
-	UA_list_Element* current = sessionManager->sessions.first;
-	while (current) {
-		if (current->payload) {
-			UA_list_Element* elem = (UA_list_Element*) current;
-			*session = ((UA_Session*) (elem->payload));
-			if(UA_NodeId_equal(&(*session)->sessionId, sessionId) == UA_EQUAL){
-				UA_Double pendingLifetime;
-				UA_Session_getPendingLifetime(*session, &pendingLifetime);
-
-				if(pendingLifetime > 0)
-					return UA_SUCCESS;
-
-				//session not valid anymore -> remove it
-				UA_list_removeElement(elem, (UA_list_PayloadVisitor)UA_Session_delete);
-				*session = UA_NULL;
-				return UA_ERROR;
-			}
-		}
-		current = current->next;
-	}
-	*session = UA_NULL;
-	return UA_ERROR;
+                                          UA_NodeId *sessionId, UA_Session **session) {
+    if(sessionManager == UA_NULL) {
+        *session = UA_NULL;
+        return UA_ERROR;
+    }
+
+    UA_list_Element *current = sessionManager->sessions.first;
+    while(current) {
+        if(current->payload) {
+            UA_list_Element *elem = (UA_list_Element *)current;
+            *session = ((UA_Session *)(elem->payload));
+            if(UA_NodeId_equal(&(*session)->sessionId, sessionId) == UA_EQUAL) {
+                UA_Double pendingLifetime;
+                UA_Session_getPendingLifetime(*session, &pendingLifetime);
+
+                if(pendingLifetime > 0)
+                    return UA_SUCCESS;
+
+                //session not valid anymore -> remove it
+                UA_list_removeElement(elem, (UA_list_PayloadVisitor)UA_Session_delete);
+                *session = UA_NULL;
+                return UA_ERROR;
+            }
+        }
+        current = current->next;
+    }
+    *session = UA_NULL;
+    return UA_ERROR;
 }
 
 UA_Int32 UA_SessionManager_getSessionByToken(UA_SessionManager *sessionManager,
-											 UA_NodeId *token, UA_Session **session) {
-	if(sessionManager == UA_NULL) {
-		*session = UA_NULL;
-		return UA_ERROR;
-	}
-
-	UA_list_Element* current = sessionManager->sessions.first;
-	while (current) {
-		if (current->payload) {
-			UA_list_Element* elem = (UA_list_Element*) current;
-			*session = ((UA_Session*) (elem->payload));
-
-			if(UA_NodeId_equal(&(*session)->authenticationToken, token) == UA_EQUAL) {
-				UA_Double pendingLifetime;
-				UA_Session_getPendingLifetime(*session, &pendingLifetime);
-
-				if(pendingLifetime > 0)
-					return UA_SUCCESS;
-
-				//session not valid anymore -> remove it
-				UA_list_removeElement(elem, (UA_list_PayloadVisitor)UA_Session_delete);
-				*session = UA_NULL;
-				return UA_ERROR;
-			}
-		}
-		current = current->next;
-	}
-	*session = UA_NULL;
-	return UA_ERROR;
+                                             UA_NodeId *token, UA_Session **session) {
+    if(sessionManager == UA_NULL) {
+        *session = UA_NULL;
+        return UA_ERROR;
+    }
+
+    UA_list_Element *current = sessionManager->sessions.first;
+    while(current) {
+        if(current->payload) {
+            UA_list_Element *elem = (UA_list_Element *)current;
+            *session = ((UA_Session *)(elem->payload));
+
+            if(UA_NodeId_equal(&(*session)->authenticationToken, token) == UA_EQUAL) {
+                UA_Double pendingLifetime;
+                UA_Session_getPendingLifetime(*session, &pendingLifetime);
+
+                if(pendingLifetime > 0)
+                    return UA_SUCCESS;
+
+                //session not valid anymore -> remove it
+                UA_list_removeElement(elem, (UA_list_PayloadVisitor)UA_Session_delete);
+                *session = UA_NULL;
+                return UA_ERROR;
+            }
+        }
+        current = current->next;
+    }
+    *session = UA_NULL;
+    return UA_ERROR;
 }
 
 /** Creates and adds a session. */
 UA_Int32 UA_SessionManager_addSession(UA_SessionManager *sessionManager,
-									  UA_SecureChannel *channel, UA_Session **session) {
-	UA_Int32 retval = UA_SUCCESS;
-	if(sessionManager->currentSessionCount >= sessionManager->maxSessionCount)
-		return UA_ERROR;
-	UA_Session_new(session);
-	(*session)->sessionId = (UA_NodeId){.namespaceIndex = 1, .identifierType = UA_NODEIDTYPE_NUMERIC,
-							 .identifier.numeric = sessionManager->lastSessionId++};
-	(*session)->channel = channel;
-	channel->session = *session;
-
-	sessionManager->currentSessionCount++;
-	return retval;
+                                      UA_SecureChannel *channel, UA_Session **session) {
+    UA_Int32 retval = UA_SUCCESS;
+    if(sessionManager->currentSessionCount >= sessionManager->maxSessionCount)
+        return UA_ERROR;
+    UA_Session_new(session);
+    (*session)->sessionId = (UA_NodeId) {.namespaceIndex     = 1, .identifierType = UA_NODEIDTYPE_NUMERIC,
+                                         .identifier.numeric = sessionManager->lastSessionId++ };
+    (*session)->channel   = channel;
+    channel->session      = *session;
+
+    sessionManager->currentSessionCount++;
+    return retval;
 }
 
 UA_Int32 UA_SessionManager_removeSession(UA_SessionManager *sessionManager,
-										 UA_NodeId *sessionId) {
-	UA_Int32 retval = UA_SUCCESS;
-	UA_list_Element *element = UA_list_search(&sessionManager->sessions,(UA_list_PayloadComparer)UA_Session_compare,sessionId);
-	if(element) {
-	    UA_Session *session = element->payload;
-		session->channel->session = UA_NULL;
-		retval |= UA_list_removeElement(element,(UA_list_PayloadVisitor)UA_Session_delete);
-		printf("UA_SessionManager_removeSession - session removed, current count: %i \n",sessionManager->sessions.size);
-	}
-	return retval;
+                                         UA_NodeId         *sessionId) {
+    UA_Int32 retval = UA_SUCCESS;
+    UA_list_Element *element =
+        UA_list_search(&sessionManager->sessions, (UA_list_PayloadComparer)UA_Session_compare,
+                       sessionId);
+    if(element) {
+        UA_Session *session = element->payload;
+        session->channel->session = UA_NULL;
+        retval |= UA_list_removeElement(element, (UA_list_PayloadVisitor)UA_Session_delete);
+        printf("UA_SessionManager_removeSession - session removed, current count: %i \n",
+               sessionManager->sessions.size);
+    }
+    return retval;
 }
 
 UA_Int32 UA_SessionManager_getSessionTimeout(UA_SessionManager *sessionManager,
-											 UA_Int64 *timeout_ms) {
-	if(sessionManager) {
-		*timeout_ms = sessionManager->sessionTimeout;
-		return UA_SUCCESS;
-	}
-	*timeout_ms = 0;
-	return UA_ERROR;
+                                             UA_Int64          *timeout_ms) {
+    if(sessionManager) {
+        *timeout_ms = sessionManager->sessionTimeout;
+        return UA_SUCCESS;
+    }
+    *timeout_ms = 0;
+    return UA_ERROR;
 }

+ 7 - 7
src/server/ua_session_manager.h

@@ -7,12 +7,12 @@ struct UA_SessionManager;
 typedef struct UA_SessionManager UA_SessionManager;
 
 UA_Int32 UA_SessionManager_new(UA_SessionManager **sessionManager, UA_UInt32 maxSessionCount,
-								UA_UInt32 sessionLifetime, UA_UInt32 startSessionId);
+                               UA_UInt32 sessionLifetime, UA_UInt32 startSessionId);
 
 UA_Int32 UA_SessionManager_delete(UA_SessionManager *sessionManager);
 
 UA_Int32 UA_SessionManager_addSession(UA_SessionManager *sessionManager,
-									  UA_SecureChannel *channel, UA_Session **session);
+                                      UA_SecureChannel *channel, UA_Session **session);
 
 /**
  * @brief removes a session from the manager list
@@ -20,7 +20,7 @@ UA_Int32 UA_SessionManager_addSession(UA_SessionManager *sessionManager,
  * @return error code
  */
 UA_Int32 UA_SessionManager_removeSession(UA_SessionManager *sessionManager,
-										 UA_NodeId *sessionId);
+                                         UA_NodeId         *sessionId);
 
 /**
  * @brief finds the session which is identified by the sessionId
@@ -29,7 +29,7 @@ UA_Int32 UA_SessionManager_removeSession(UA_SessionManager *sessionManager,
  * @return error code
  */
 UA_Int32 UA_SessionManager_getSessionById(UA_SessionManager *sessionManager,
-										  UA_NodeId *sessionId, UA_Session **session);
+                                          UA_NodeId *sessionId, UA_Session **session);
 
 /**
  * @brief
@@ -38,7 +38,7 @@ UA_Int32 UA_SessionManager_getSessionById(UA_SessionManager *sessionManager,
  * @return error code
  */
 UA_Int32 UA_SessionManager_getSessionByToken(UA_SessionManager *sessionManager,
-											 UA_NodeId *token, UA_Session **session);
+                                             UA_NodeId *token, UA_Session **session);
 
 /**
  * @brief gets the session timeout value which should be assigned to
@@ -47,11 +47,11 @@ UA_Int32 UA_SessionManager_getSessionByToken(UA_SessionManager *sessionManager,
  * @return error code
  */
 UA_Int32 UA_SessionManager_getSessionTimeout(UA_SessionManager *sessionManager,
-											 UA_Int64 *timeout_ms);
+                                             UA_Int64          *timeout_ms);
 
 //UA_Int32 UA_SessionManager_updateSessions();
 //UA_Int32 UA_SessionManager_generateToken(UA_Session session, UA_Int32 requestedLifeTime, SecurityTokenRequestType requestType, UA_ChannelSecurityToken* newToken);
 UA_Int32 UA_SessionManager_generateSessionId(UA_SessionManager *sessionManager,
-											 UA_NodeId *newSessionId);
+                                             UA_NodeId         *newSessionId);
 
 #endif /* UA_SESSION_MANAGER_H_ */

+ 30 - 30
src/ua_connection.c

@@ -1,44 +1,44 @@
 #include "ua_connection.h"
 
-UA_ConnectionConfig UA_ConnectionConfig_standard = {.protocolVersion = 0, .sendBufferSize = 8192,
-													.recvBufferSize = 8192, .maxMessageSize = 8192,
-													.maxChunkCount = 1};
+UA_ConnectionConfig UA_ConnectionConfig_standard = { .protocolVersion = 0,    .sendBufferSize = 8192,
+                                                     .recvBufferSize  = 8192, .maxMessageSize = 8192,
+                                                     .maxChunkCount   = 1 };
 
 UA_Int32 UA_ByteStringArray_init(UA_ByteStringArray *stringarray, UA_UInt32 length) {
-	if(!stringarray || length == 0)
-		return UA_ERROR;
-	if(UA_alloc((void**)&stringarray->strings, sizeof(UA_String) * length) != UA_SUCCESS)
-		return UA_ERROR;
-	for(UA_UInt32 i=0;i<length;i++)
-		UA_String_init(&stringarray->strings[i]);
-	stringarray->stringsSize = length;
-	return UA_ERROR;
+    if(!stringarray || length == 0)
+        return UA_ERROR;
+    if(UA_alloc((void **)&stringarray->strings, sizeof(UA_String) * length) != UA_SUCCESS)
+        return UA_ERROR;
+    for(UA_UInt32 i = 0;i < length;i++)
+        UA_String_init(&stringarray->strings[i]);
+    stringarray->stringsSize = length;
+    return UA_ERROR;
 }
 
 UA_Int32 UA_ByteStringArray_deleteMembers(UA_ByteStringArray *stringarray) {
-	if(!stringarray)
-		return UA_ERROR;
-	for(UA_UInt32 i=0;i<stringarray->stringsSize;i++)
-		UA_String_deleteMembers(&stringarray->strings[i]);
-	UA_free(stringarray);
-	return UA_SUCCESS;
+    if(!stringarray)
+        return UA_ERROR;
+    for(UA_UInt32 i = 0;i < stringarray->stringsSize;i++)
+        UA_String_deleteMembers(&stringarray->strings[i]);
+    UA_free(stringarray);
+    return UA_SUCCESS;
 }
 
 UA_Int32 UA_Connection_init(UA_Connection *connection,
-								  UA_ConnectionConfig localConf,
-								  void *callbackHandle,
-								  UA_Int32 (*close)(void *handle),
-								  UA_Int32 (*write)(void *handle, UA_ByteStringArray *buf)) {
-	connection->state = UA_CONNECTION_OPENING;
-	connection->localConf = localConf;
-	connection->channel = UA_NULL;
-	connection->callbackHandle = callbackHandle;
-	connection->close = close;
-	connection->write = write;
-	return UA_SUCCESS;
+                            UA_ConnectionConfig localConf,
+                            void *callbackHandle,
+                            UA_Int32 (*close)(void *handle),
+                            UA_Int32 (*write)(void *handle, UA_ByteStringArray *buf)) {
+    connection->state          = UA_CONNECTION_OPENING;
+    connection->localConf      = localConf;
+    connection->channel        = UA_NULL;
+    connection->callbackHandle = callbackHandle;
+    connection->close          = close;
+    connection->write          = write;
+    return UA_SUCCESS;
 }
 
 UA_Int32 UA_Connection_deleteMembers(UA_Connection *connection) {
-	UA_free(connection->callbackHandle);
-	return UA_SUCCESS;
+    UA_free(connection->callbackHandle);
+    return UA_SUCCESS;
 }

+ 20 - 20
src/ua_connection.h

@@ -6,25 +6,25 @@
 /* used for zero-copy communication. the array of bytestrings is sent over the
    network as a single buffer. */
 typedef struct UA_ByteStringArray {
-	UA_UInt32 stringsSize;
-	UA_ByteString *strings;
+    UA_UInt32      stringsSize;
+    UA_ByteString *strings;
 } UA_ByteStringArray;
 
 UA_Int32 UA_ByteStringArray_init(UA_ByteStringArray *stringarray, UA_UInt32 length);
 UA_Int32 UA_ByteStringArray_deleteMembers(UA_ByteStringArray *stringarray);
 
 typedef enum UA_ConnectionState {
-	UA_CONNECTION_OPENING,
-	UA_CONNECTION_CLOSING,
-	UA_CONNECTION_ESTABLISHED
+    UA_CONNECTION_OPENING,
+    UA_CONNECTION_CLOSING,
+    UA_CONNECTION_ESTABLISHED
 } UA_ConnectionState;
 
 typedef struct UA_ConnectionConfig {
-	UA_UInt32 protocolVersion;
-	UA_UInt32 sendBufferSize;
-	UA_UInt32 recvBufferSize;
-	UA_UInt32 maxMessageSize;
-	UA_UInt32 maxChunkCount;
+    UA_UInt32 protocolVersion;
+    UA_UInt32 sendBufferSize;
+    UA_UInt32 recvBufferSize;
+    UA_UInt32 maxMessageSize;
+    UA_UInt32 maxChunkCount;
 } UA_ConnectionConfig;
 
 extern UA_ConnectionConfig UA_ConnectionConfig_standard;
@@ -37,20 +37,20 @@ typedef UA_Int32 (*UA_Connection_writeCallback)(void *handle, UA_ByteStringArray
 typedef UA_Int32 (*UA_Connection_closeCallback)(void *handle);
 
 typedef struct UA_Connection {
-	UA_ConnectionState state;
-	UA_ConnectionConfig localConf;
-	UA_ConnectionConfig remoteConf;
-	UA_SecureChannel *channel;
-	void *callbackHandle;
-	UA_Connection_writeCallback write;
-	UA_Connection_closeCallback close;
+    UA_ConnectionState  state;
+    UA_ConnectionConfig localConf;
+    UA_ConnectionConfig remoteConf;
+    UA_SecureChannel   *channel;
+    void *callbackHandle;
+    UA_Connection_writeCallback write;
+    UA_Connection_closeCallback close;
 } UA_Connection;
 
 UA_Int32 UA_Connection_init(UA_Connection *connection, UA_ConnectionConfig localConf,
-							void *callbackHandle, UA_Int32 (*close)(void *handle),
-							UA_Int32 (*write)(void *handle, UA_ByteStringArray *buf));
+                            void *callbackHandle, UA_Int32 (*close)(void *handle),
+                            UA_Int32 (*write)(void *handle, UA_ByteStringArray *buf));
 UA_Int32 UA_Connection_deleteMembers(UA_Connection *connection);
 
 // todo: closing a binaryconnection that was closed on the network level
-	
+
 #endif /* UA_CONNECTION_H_ */

+ 38 - 38
src/ua_securechannel.c

@@ -3,61 +3,61 @@
 #include "ua_securechannel.h"
 
 UA_Int32 UA_SecureChannel_init(UA_SecureChannel *channel) {
-	UA_AsymmetricAlgorithmSecurityHeader_init(&channel->clientAsymAlgSettings);
-	UA_AsymmetricAlgorithmSecurityHeader_init(&channel->serverAsymAlgSettings);
-	UA_ByteString_init(&channel->clientNonce);
-	UA_ByteString_init(&channel->serverNonce);
-	channel->connection = UA_NULL;
-	channel->session = UA_NULL;
-	return UA_SUCCESS;
+    UA_AsymmetricAlgorithmSecurityHeader_init(&channel->clientAsymAlgSettings);
+    UA_AsymmetricAlgorithmSecurityHeader_init(&channel->serverAsymAlgSettings);
+    UA_ByteString_init(&channel->clientNonce);
+    UA_ByteString_init(&channel->serverNonce);
+    channel->connection = UA_NULL;
+    channel->session    = UA_NULL;
+    return UA_SUCCESS;
 }
 
 UA_Int32 UA_SecureChannel_deleteMembers(UA_SecureChannel *channel) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_AsymmetricAlgorithmSecurityHeader_deleteMembers(&channel->serverAsymAlgSettings);
-	retval |= UA_ByteString_deleteMembers(&channel->serverNonce);
-	retval |= UA_AsymmetricAlgorithmSecurityHeader_deleteMembers(&channel->clientAsymAlgSettings);
-	retval |= UA_ByteString_deleteMembers(&channel->clientNonce);
-	retval |= UA_ChannelSecurityToken_deleteMembers(&channel->securityToken);
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_AsymmetricAlgorithmSecurityHeader_deleteMembers(&channel->serverAsymAlgSettings);
+    retval |= UA_ByteString_deleteMembers(&channel->serverNonce);
+    retval |= UA_AsymmetricAlgorithmSecurityHeader_deleteMembers(&channel->clientAsymAlgSettings);
+    retval |= UA_ByteString_deleteMembers(&channel->clientNonce);
+    retval |= UA_ChannelSecurityToken_deleteMembers(&channel->securityToken);
+    return retval;
 }
 UA_Int32 UA_SecureChannel_delete(UA_SecureChannel *channel) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval = UA_SecureChannel_deleteMembers(channel);
-	retval = UA_free(channel);
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    retval = UA_SecureChannel_deleteMembers(channel);
+    retval = UA_free(channel);
+    return retval;
 }
 
 UA_Boolean UA_SecureChannel_compare(UA_SecureChannel *sc1, UA_SecureChannel *sc2) {
-	return (sc1->securityToken.channelId == sc2->securityToken.channelId) ?
-			UA_TRUE : UA_FALSE;
+    return (sc1->securityToken.channelId == sc2->securityToken.channelId) ?
+           UA_TRUE : UA_FALSE;
 }
 
 //TODO implement real nonce generator - DUMMY function
 UA_Int32 UA_SecureChannel_generateNonce(UA_ByteString *nonce) {
-	//UA_ByteString_new(&nonce);
-	UA_alloc((void** )&nonce->data, 1);
-	nonce->length = 1;
-	nonce->data[0] = 'a';
-	return UA_SUCCESS;
+    //UA_ByteString_new(&nonce);
+    UA_alloc((void ** )&nonce->data, 1);
+    nonce->length  = 1;
+    nonce->data[0] = 'a';
+    return UA_SUCCESS;
 }
 
 UA_Int32 UA_SecureChannel_updateRequestId(UA_SecureChannel *channel, UA_UInt32 requestId) {
-	//TODO review checking of request id
-	if (channel->requestId+1  == requestId) {
-		channel->requestId++;
-		return UA_SUCCESS;
-	}
-	return UA_ERROR;
+    //TODO review checking of request id
+    if(channel->requestId+1  == requestId) {
+        channel->requestId++;
+        return UA_SUCCESS;
+    }
+    return UA_ERROR;
 }
 
 UA_Int32 UA_SecureChannel_updateSequenceNumber(UA_SecureChannel *channel,
-											  UA_UInt32 sequenceNumber) {
-	//TODO review checking of sequence
-	if (channel->sequenceNumber+1  == sequenceNumber) {
-		channel->sequenceNumber++;
-		return UA_SUCCESS;
-	}
-	return UA_ERROR;
+                                               UA_UInt32         sequenceNumber) {
+    //TODO review checking of sequence
+    if(channel->sequenceNumber+1  == sequenceNumber) {
+        channel->sequenceNumber++;
+        return UA_SUCCESS;
+    }
+    return UA_ERROR;
 
 }

+ 10 - 10
src/ua_securechannel.h

@@ -18,16 +18,16 @@ struct UA_Session;
 typedef struct UA_Session UA_Session;
 
 struct UA_SecureChannel {
-	UA_MessageSecurityMode securityMode;
-	UA_ChannelSecurityToken securityToken; // the channelId is contained in the securityToken
-	UA_AsymmetricAlgorithmSecurityHeader clientAsymAlgSettings;
-	UA_AsymmetricAlgorithmSecurityHeader serverAsymAlgSettings;
-	UA_ByteString clientNonce;
-	UA_ByteString serverNonce;
-	UA_UInt32 requestId;
-	UA_UInt32 sequenceNumber;
-	UA_Connection *connection; // make this more generic when http connections exist
-	UA_Session *session;
+    UA_MessageSecurityMode  securityMode;
+    UA_ChannelSecurityToken securityToken; // the channelId is contained in the securityToken
+    UA_AsymmetricAlgorithmSecurityHeader clientAsymAlgSettings;
+    UA_AsymmetricAlgorithmSecurityHeader serverAsymAlgSettings;
+    UA_ByteString  clientNonce;
+    UA_ByteString  serverNonce;
+    UA_UInt32      requestId;
+    UA_UInt32      sequenceNumber;
+    UA_Connection *connection; // make this more generic when http connections exist
+    UA_Session    *session;
 };
 
 UA_Int32 UA_SecureChannel_init(UA_SecureChannel *channel);

+ 61 - 61
src/ua_session.c

@@ -4,90 +4,90 @@
 #include "ua_session.h"
 
 UA_Int32 UA_Session_new(UA_Session **session) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_alloc((void**)session, sizeof(UA_Session));
-	if(retval == UA_SUCCESS)
-		UA_Session_init(*session);
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_alloc((void **)session, sizeof(UA_Session));
+    if(retval == UA_SUCCESS)
+        UA_Session_init(*session);
+    return retval;
 }
 
 /* mock up function to generate tokens for authentication */
 UA_Int32 UA_Session_generateToken(UA_NodeId *newToken) {
-	//Random token generation
-	UA_Int32 retval = UA_SUCCESS;
-	srand(time(NULL));
+    //Random token generation
+    UA_Int32 retval = UA_SUCCESS;
+    srand(time(NULL));
 
-	UA_Int32 i = 0;
-	UA_Int32 r = 0;
-	//retval |= UA_NodeId_new(newToken);
+    UA_Int32 i = 0;
+    UA_Int32 r = 0;
+    //retval |= UA_NodeId_new(newToken);
 
-	newToken->namespaceIndex = 0; // where else?
-	newToken->identifierType = UA_NODEIDTYPE_GUID;
-	newToken->identifier.guid.data1 = rand();
-	r = rand();
-	newToken->identifier.guid.data2 = (UA_UInt16)((r>>16) );
-	r = rand();
-	UA_Int32 r1 = (r>>16);
-	UA_Int32 r2 = r1 & 0xFFFF;
-	r2 = r2 * 1;
-	newToken->identifier.guid.data3 = (UA_UInt16)((r>>16) );
-	for(i=0;i<8;i++) {
-		r = rand();
-		newToken->identifier.guid.data4[i] = (UA_Byte)((r>>28) );
-	}
-	return retval;
+    newToken->namespaceIndex = 0; // where else?
+    newToken->identifierType = UA_NODEIDTYPE_GUID;
+    newToken->identifier.guid.data1 = rand();
+    r = rand();
+    newToken->identifier.guid.data2 = (UA_UInt16)((r>>16) );
+    r = rand();
+    UA_Int32 r1 = (r>>16);
+    UA_Int32 r2 = r1 & 0xFFFF;
+    r2 = r2 * 1;
+    newToken->identifier.guid.data3 = (UA_UInt16)((r>>16) );
+    for(i = 0;i < 8;i++) {
+        r = rand();
+        newToken->identifier.guid.data4[i] = (UA_Byte)((r>>28) );
+    }
+    return retval;
 }
 
-UA_Int32 UA_Session_init(UA_Session *session){
-	if(!session)
-		return UA_ERROR;
-	
-	UA_NodeId_init(&session->authenticationToken);
-	UA_NodeId_init(&session->sessionId);
-	UA_String_init(&session->sessionName);
-	session->maxRequestMessageSize = 0;
-	session->maxResponseMessageSize = 0;
-	session->timeout = 0;
-	UA_DateTime_init(&session->validTill);
-	session->channel = UA_NULL;
-	return UA_SUCCESS;
+UA_Int32 UA_Session_init(UA_Session *session) {
+    if(!session)
+        return UA_ERROR;
+
+    UA_NodeId_init(&session->authenticationToken);
+    UA_NodeId_init(&session->sessionId);
+    UA_String_init(&session->sessionName);
+    session->maxRequestMessageSize  = 0;
+    session->maxResponseMessageSize = 0;
+    session->timeout = 0;
+    UA_DateTime_init(&session->validTill);
+    session->channel = UA_NULL;
+    return UA_SUCCESS;
 }
 
 UA_Int32 UA_Session_deleteMembers(UA_Session *session) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_NodeId_deleteMembers(&session->authenticationToken);
-	retval |= UA_NodeId_deleteMembers(&session->sessionId);
-	retval |= UA_String_deleteMembers(&session->sessionName);
-	session->channel = UA_NULL;
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_NodeId_deleteMembers(&session->authenticationToken);
+    retval |= UA_NodeId_deleteMembers(&session->sessionId);
+    retval |= UA_String_deleteMembers(&session->sessionName);
+    session->channel = UA_NULL;
+    return retval;
 }
 
 UA_Int32 UA_Session_delete(UA_Session *session) {
-	UA_Int32 retval = UA_SUCCESS;
-	UA_Session_deleteMembers(session);
-	retval |= UA_free(session);
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    UA_Session_deleteMembers(session);
+    retval |= UA_free(session);
+    return retval;
 }
 
 UA_Boolean UA_Session_compare(UA_Session *session1, UA_Session *session2) {
-	if(session1 && session2 &&
-	   UA_NodeId_equal(&session1->sessionId, &session2->sessionId) == UA_EQUAL)
-			return UA_TRUE;
-	return UA_FALSE;
+    if(session1 && session2 &&
+       UA_NodeId_equal(&session1->sessionId, &session2->sessionId) == UA_EQUAL)
+        return UA_TRUE;
+    return UA_FALSE;
 }
 
 UA_Int32 UA_Session_updateLifetime(UA_Session *session) {
-	if(!session)
-		return UA_ERROR;
+    if(!session)
+        return UA_ERROR;
 
-	session->validTill = UA_DateTime_now() + session->timeout * 100000; //timeout in ms
-	return UA_SUCCESS;
+    session->validTill = UA_DateTime_now() + session->timeout * 100000; //timeout in ms
+    return UA_SUCCESS;
 }
 
 UA_Int32 UA_Session_getPendingLifetime(UA_Session *session, UA_Double *pendingLifetime_ms) {
-	if(!session)
-		return UA_ERROR;
+    if(!session)
+        return UA_ERROR;
 
-	*pendingLifetime_ms = (session->validTill - UA_DateTime_now())/10000000; //difference in ms
-	return UA_SUCCESS;
+    *pendingLifetime_ms = (session->validTill - UA_DateTime_now())/10000000; //difference in ms
+    return UA_SUCCESS;
 }

+ 10 - 10
src/ua_session.h

@@ -11,15 +11,15 @@
  */
 
 struct UA_Session {
-	UA_ApplicationDescription clientDescription;
-	UA_String sessionName;
-	UA_NodeId authenticationToken;
-	UA_NodeId sessionId;
-	UA_UInt32 maxRequestMessageSize;
-	UA_UInt32 maxResponseMessageSize;
-	UA_Int64 timeout;
-	UA_DateTime validTill;
-	UA_SecureChannel *channel;
+    UA_ApplicationDescription clientDescription;
+    UA_String         sessionName;
+    UA_NodeId         authenticationToken;
+    UA_NodeId         sessionId;
+    UA_UInt32         maxRequestMessageSize;
+    UA_UInt32         maxResponseMessageSize;
+    UA_Int64          timeout;
+    UA_DateTime       validTill;
+    UA_SecureChannel *channel;
 };
 
 UA_Int32 UA_Session_new(UA_Session **session);
@@ -34,6 +34,6 @@ UA_Boolean UA_Session_compare(UA_Session *session1, UA_Session *session2);
 UA_Int32 UA_Session_updateLifetime(UA_Session *session);
 
 /** Gets the sessions pending lifetime (calculated from the timeout which was set) */
-UA_Int32 UA_Session_getPendingLifetime(UA_Session *session,UA_Double *pendingLifetime);
+UA_Int32 UA_Session_getPendingLifetime(UA_Session *session, UA_Double *pendingLifetime);
 
 #endif /* UA_SESSION_H_ */

+ 457 - 380
src/ua_transport.c

@@ -3,534 +3,611 @@
 #include "ua_namespace_0.h" // for the vtable UA_
 
 UA_TYPE_DEFAULT(UA_MessageType)
-UA_Int32 UA_MessageType_calcSize(UA_MessageType const * ptr) {
-	if(ptr==UA_NULL) {return sizeof(UA_MessageType);}
-	return 0
-	 + 3 * sizeof(UA_Byte);
-}
-
-UA_Int32 UA_MessageType_encodeBinary(UA_MessageType const * src, UA_ByteString* dst, UA_UInt32 *offset) {
-	UA_Int32 retval = UA_SUCCESS;
-	UA_Byte tmpBuf[3];
-	tmpBuf[0] = (UA_Byte)((((UA_Int32)*src) >> 16) );
-	tmpBuf[1] = (UA_Byte)((((UA_Int32)*src) >> 8));
-	tmpBuf[2] = (UA_Byte)(((UA_Int32)*src));
-
-	retval |= UA_Byte_encodeBinary(&(tmpBuf[0]),dst,offset);
-	retval |= UA_Byte_encodeBinary(&(tmpBuf[1]),dst,offset);
-	retval |= UA_Byte_encodeBinary(&(tmpBuf[2]),dst,offset);
-	return retval;
-}
-
-UA_Int32 UA_MessageType_decodeBinary(UA_ByteString const * src, UA_UInt32 *offset, UA_MessageType* dst) {
-	UA_Int32 retval = UA_SUCCESS;
-	UA_Byte tmpBuf[3];
-	retval |= UA_Byte_decodeBinary(src,offset,&(tmpBuf[0])); //messageType to Byte representation
-	retval |= UA_Byte_decodeBinary(src,offset,&(tmpBuf[1]));
-	retval |= UA_Byte_decodeBinary(src,offset,&(tmpBuf[2]));
-	*dst = (UA_MessageType)((UA_Int32)(tmpBuf[0]<<16) + (UA_Int32)(tmpBuf[1]<<8) + (UA_Int32)(tmpBuf[2]));
-	return retval;
-}
-
-void UA_MessageType_printf(char *label, UA_MessageType* p) {
-	UA_Byte* b = (UA_Byte*) p;
-	printf("%s{%c%c%c}\n", label, b[2],b[1],b[0]);
-}
-
-UA_Int32 UA_OPCUATcpMessageHeader_calcSizeBinary(UA_OPCUATcpMessageHeader const * ptr) {
-    	if(ptr==UA_NULL) return sizeof(UA_OPCUATcpMessageHeader);
-    	return 0
-	 + 3 // messageType
-	 + sizeof(UA_Byte) // isFinal
-	 + sizeof(UA_UInt32) // messageSize
-	;
-}
-
-UA_Int32 UA_OPCUATcpMessageHeader_encodeBinary(UA_OPCUATcpMessageHeader const * src, UA_ByteString* dst, UA_UInt32 *offset) {
-    	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_MessageType_encodeBinary(&src->messageType,dst,offset);
-	retval |= UA_Byte_encodeBinary(&src->isFinal,dst,offset);
-	retval |= UA_UInt32_encodeBinary(&src->messageSize,dst,offset);
-	return retval;
-}
-
-UA_Int32 UA_OPCUATcpMessageHeader_decodeBinary(UA_ByteString const * src, UA_UInt32 *offset, UA_OPCUATcpMessageHeader * dst) {
-    	UA_Int32 retval = UA_SUCCESS;
-	UA_OPCUATcpMessageHeader_init(dst);
-	CHECKED_DECODE(UA_MessageType_decodeBinary(src,offset,&dst->messageType), UA_OPCUATcpMessageHeader_deleteMembers(dst));
-	CHECKED_DECODE(UA_Byte_decodeBinary(src,offset,&dst->isFinal), UA_OPCUATcpMessageHeader_deleteMembers(dst));
-	CHECKED_DECODE(UA_UInt32_decodeBinary(src,offset,&dst->messageSize), UA_OPCUATcpMessageHeader_deleteMembers(dst));
-	return retval;
+UA_Int32 UA_MessageType_calcSize(UA_MessageType const *ptr) {
+    if(ptr == UA_NULL) return sizeof(UA_MessageType); return 0
+           + 3 * sizeof(UA_Byte);
+}
+
+UA_Int32 UA_MessageType_encodeBinary(UA_MessageType const *src, UA_ByteString *dst, UA_UInt32 *offset) {
+    UA_Int32 retval = UA_SUCCESS;
+    UA_Byte  tmpBuf[3];
+    tmpBuf[0] = (UA_Byte)((((UA_Int32)*src) >> 16) );
+    tmpBuf[1] = (UA_Byte)((((UA_Int32)*src) >> 8));
+    tmpBuf[2] = (UA_Byte)(((UA_Int32)*src));
+
+    retval   |= UA_Byte_encodeBinary(&(tmpBuf[0]), dst, offset);
+    retval   |= UA_Byte_encodeBinary(&(tmpBuf[1]), dst, offset);
+    retval   |= UA_Byte_encodeBinary(&(tmpBuf[2]), dst, offset);
+    return retval;
+}
+
+UA_Int32 UA_MessageType_decodeBinary(UA_ByteString const *src, UA_UInt32 *offset, UA_MessageType *dst) {
+    UA_Int32 retval = UA_SUCCESS;
+    UA_Byte  tmpBuf[3];
+    retval |= UA_Byte_decodeBinary(src, offset, &(tmpBuf[0])); //messageType to Byte representation
+    retval |= UA_Byte_decodeBinary(src, offset, &(tmpBuf[1]));
+    retval |= UA_Byte_decodeBinary(src, offset, &(tmpBuf[2]));
+    *dst    = (UA_MessageType)((UA_Int32)(tmpBuf[0]<<16) + (UA_Int32)(tmpBuf[1]<<8) + (UA_Int32)(tmpBuf[2]));
+    return retval;
+}
+
+void UA_MessageType_printf(char *label, UA_MessageType *p) {
+    UA_Byte *b = (UA_Byte *)p;
+    printf("%s{%c%c%c}\n", label, b[2], b[1], b[0]);
+}
+
+UA_Int32 UA_OPCUATcpMessageHeader_calcSizeBinary(UA_OPCUATcpMessageHeader const *ptr) {
+    if(ptr == UA_NULL) return sizeof(UA_OPCUATcpMessageHeader);
+    return 0
+           + 3                 // messageType
+           + sizeof(UA_Byte)   // isFinal
+           + sizeof(UA_UInt32) // messageSize
+    ;
+}
+
+UA_Int32 UA_OPCUATcpMessageHeader_encodeBinary(UA_OPCUATcpMessageHeader const *src, UA_ByteString *dst,
+                                               UA_UInt32 *offset) {
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_MessageType_encodeBinary(&src->messageType, dst, offset);
+    retval |= UA_Byte_encodeBinary(&src->isFinal, dst, offset);
+    retval |= UA_UInt32_encodeBinary(&src->messageSize, dst, offset);
+    return retval;
+}
+
+UA_Int32 UA_OPCUATcpMessageHeader_decodeBinary(UA_ByteString const *src, UA_UInt32 *offset,
+                                               UA_OPCUATcpMessageHeader *dst) {
+    UA_Int32 retval = UA_SUCCESS;
+    UA_OPCUATcpMessageHeader_init(dst);
+    CHECKED_DECODE(UA_MessageType_decodeBinary(src, offset,
+                                               &dst->messageType), UA_OPCUATcpMessageHeader_deleteMembers(dst));
+    CHECKED_DECODE(UA_Byte_decodeBinary(src, offset,
+                                        &dst->isFinal), UA_OPCUATcpMessageHeader_deleteMembers(dst));
+    CHECKED_DECODE(UA_UInt32_decodeBinary(src, offset,
+                                          &dst->messageSize), UA_OPCUATcpMessageHeader_deleteMembers(dst));
+    return retval;
 }
 
 UA_Int32 UA_OPCUATcpMessageHeader_delete(UA_OPCUATcpMessageHeader *p) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_OPCUATcpMessageHeader_deleteMembers(p);
-	retval |= UA_free(p);
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_OPCUATcpMessageHeader_deleteMembers(p);
+    retval |= UA_free(p);
+    return retval;
 }
 
 UA_Int32 UA_OPCUATcpMessageHeader_deleteMembers(UA_OPCUATcpMessageHeader *p) {
-    	UA_Int32 retval = UA_SUCCESS;
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    return retval;
 }
 
 UA_Int32 UA_OPCUATcpMessageHeader_init(UA_OPCUATcpMessageHeader *p) {
-    	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_Byte_init(&p->isFinal);
-	retval |= UA_UInt32_init(&p->messageSize);
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_Byte_init(&p->isFinal);
+    retval |= UA_UInt32_init(&p->messageSize);
+    return retval;
 }
 
 UA_TYPE_NEW_DEFAULT(UA_OPCUATcpMessageHeader)
-UA_Int32 UA_OPCUATcpMessageHeader_copy(const UA_OPCUATcpMessageHeader *src,UA_OPCUATcpMessageHeader *dst) {
-	UA_Int32 retval = UA_SUCCESS;
+UA_Int32 UA_OPCUATcpMessageHeader_copy(const UA_OPCUATcpMessageHeader *src, UA_OPCUATcpMessageHeader *dst) {
+    UA_Int32 retval = UA_SUCCESS;
     if(src == UA_NULL || dst == UA_NULL)
-		return UA_ERROR;
-	memcpy(dst, src, sizeof(UA_OPCUATcpMessageHeader));
-	return retval;
-}
-
-UA_Int32 UA_OPCUATcpHelloMessage_calcSizeBinary(UA_OPCUATcpHelloMessage const * ptr) {
-    	if(ptr==UA_NULL) return sizeof(UA_OPCUATcpHelloMessage);
-    	return 0
-	 + sizeof(UA_UInt32) // protocolVersion
-	 + sizeof(UA_UInt32) // receiveBufferSize
-	 + sizeof(UA_UInt32) // sendBufferSize
-	 + sizeof(UA_UInt32) // maxMessageSize
-	 + sizeof(UA_UInt32) // maxChunkCount
-	 + UA_String_calcSizeBinary(&ptr->endpointUrl)
-	;
-}
-
-UA_Int32 UA_OPCUATcpHelloMessage_encodeBinary(UA_OPCUATcpHelloMessage const * src, UA_ByteString* dst, UA_UInt32 *offset) {
-    	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_UInt32_encodeBinary(&src->protocolVersion,dst,offset);
-	retval |= UA_UInt32_encodeBinary(&src->receiveBufferSize,dst,offset);
-	retval |= UA_UInt32_encodeBinary(&src->sendBufferSize,dst,offset);
-	retval |= UA_UInt32_encodeBinary(&src->maxMessageSize,dst,offset);
-	retval |= UA_UInt32_encodeBinary(&src->maxChunkCount,dst,offset);
-	retval |= UA_String_encodeBinary(&src->endpointUrl,dst,offset);
-	return retval;
-}
-
-UA_Int32 UA_OPCUATcpHelloMessage_decodeBinary(UA_ByteString const * src, UA_UInt32 *offset, UA_OPCUATcpHelloMessage * dst) {
-    	UA_Int32 retval = UA_SUCCESS;
-	UA_OPCUATcpHelloMessage_init(dst);
-	CHECKED_DECODE(UA_UInt32_decodeBinary(src,offset,&dst->protocolVersion), UA_OPCUATcpHelloMessage_deleteMembers(dst));
-	CHECKED_DECODE(UA_UInt32_decodeBinary(src,offset,&dst->receiveBufferSize), UA_OPCUATcpHelloMessage_deleteMembers(dst));
-	CHECKED_DECODE(UA_UInt32_decodeBinary(src,offset,&dst->sendBufferSize), UA_OPCUATcpHelloMessage_deleteMembers(dst));
-	CHECKED_DECODE(UA_UInt32_decodeBinary(src,offset,&dst->maxMessageSize), UA_OPCUATcpHelloMessage_deleteMembers(dst));
-	CHECKED_DECODE(UA_UInt32_decodeBinary(src,offset,&dst->maxChunkCount), UA_OPCUATcpHelloMessage_deleteMembers(dst));
-	CHECKED_DECODE(UA_String_decodeBinary(src,offset,&dst->endpointUrl), UA_OPCUATcpHelloMessage_deleteMembers(dst));
-	return retval;
+        return UA_ERROR;
+    memcpy(dst, src, sizeof(UA_OPCUATcpMessageHeader));
+    return retval;
+}
+
+UA_Int32 UA_OPCUATcpHelloMessage_calcSizeBinary(UA_OPCUATcpHelloMessage const *ptr) {
+    if(ptr == UA_NULL) return sizeof(UA_OPCUATcpHelloMessage);
+    return 0
+           + sizeof(UA_UInt32) // protocolVersion
+           + sizeof(UA_UInt32) // receiveBufferSize
+           + sizeof(UA_UInt32) // sendBufferSize
+           + sizeof(UA_UInt32) // maxMessageSize
+           + sizeof(UA_UInt32) // maxChunkCount
+           + UA_String_calcSizeBinary(&ptr->endpointUrl)
+    ;
+}
+
+UA_Int32 UA_OPCUATcpHelloMessage_encodeBinary(UA_OPCUATcpHelloMessage const *src, UA_ByteString *dst,
+                                              UA_UInt32 *offset) {
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_UInt32_encodeBinary(&src->protocolVersion, dst, offset);
+    retval |= UA_UInt32_encodeBinary(&src->receiveBufferSize, dst, offset);
+    retval |= UA_UInt32_encodeBinary(&src->sendBufferSize, dst, offset);
+    retval |= UA_UInt32_encodeBinary(&src->maxMessageSize, dst, offset);
+    retval |= UA_UInt32_encodeBinary(&src->maxChunkCount, dst, offset);
+    retval |= UA_String_encodeBinary(&src->endpointUrl, dst, offset);
+    return retval;
+}
+
+UA_Int32 UA_OPCUATcpHelloMessage_decodeBinary(UA_ByteString const *src, UA_UInt32 *offset,
+                                              UA_OPCUATcpHelloMessage *dst) {
+    UA_Int32 retval = UA_SUCCESS;
+    UA_OPCUATcpHelloMessage_init(dst);
+    CHECKED_DECODE(UA_UInt32_decodeBinary(src, offset,
+                                          &dst->protocolVersion), UA_OPCUATcpHelloMessage_deleteMembers(dst));
+    CHECKED_DECODE(UA_UInt32_decodeBinary(src, offset,
+                                          &dst->receiveBufferSize), UA_OPCUATcpHelloMessage_deleteMembers(dst));
+    CHECKED_DECODE(UA_UInt32_decodeBinary(src, offset,
+                                          &dst->sendBufferSize), UA_OPCUATcpHelloMessage_deleteMembers(dst));
+    CHECKED_DECODE(UA_UInt32_decodeBinary(src, offset,
+                                          &dst->maxMessageSize), UA_OPCUATcpHelloMessage_deleteMembers(dst));
+    CHECKED_DECODE(UA_UInt32_decodeBinary(src, offset,
+                                          &dst->maxChunkCount), UA_OPCUATcpHelloMessage_deleteMembers(dst));
+    CHECKED_DECODE(UA_String_decodeBinary(src, offset,
+                                          &dst->endpointUrl), UA_OPCUATcpHelloMessage_deleteMembers(dst));
+    return retval;
 }
 
 UA_Int32 UA_OPCUATcpHelloMessage_delete(UA_OPCUATcpHelloMessage *p) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_OPCUATcpHelloMessage_deleteMembers(p);
-	retval |= UA_free(p);
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_OPCUATcpHelloMessage_deleteMembers(p);
+    retval |= UA_free(p);
+    return retval;
 }
 
 UA_Int32 UA_OPCUATcpHelloMessage_deleteMembers(UA_OPCUATcpHelloMessage *p) {
-    	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_String_deleteMembers(&p->endpointUrl);
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_String_deleteMembers(&p->endpointUrl);
+    return retval;
 }
 
 UA_Int32 UA_OPCUATcpHelloMessage_init(UA_OPCUATcpHelloMessage *p) {
-    	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_UInt32_init(&p->protocolVersion);
-	retval |= UA_UInt32_init(&p->receiveBufferSize);
-	retval |= UA_UInt32_init(&p->sendBufferSize);
-	retval |= UA_UInt32_init(&p->maxMessageSize);
-	retval |= UA_UInt32_init(&p->maxChunkCount);
-	retval |= UA_String_init(&p->endpointUrl);
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_UInt32_init(&p->protocolVersion);
+    retval |= UA_UInt32_init(&p->receiveBufferSize);
+    retval |= UA_UInt32_init(&p->sendBufferSize);
+    retval |= UA_UInt32_init(&p->maxMessageSize);
+    retval |= UA_UInt32_init(&p->maxChunkCount);
+    retval |= UA_String_init(&p->endpointUrl);
+    return retval;
 }
 
 UA_TYPE_NEW_DEFAULT(UA_OPCUATcpHelloMessage)
-UA_Int32 UA_OPCUATcpHelloMessage_copy(const UA_OPCUATcpHelloMessage *src,UA_OPCUATcpHelloMessage *dst) {
-	UA_Int32 retval = UA_SUCCESS;
+UA_Int32 UA_OPCUATcpHelloMessage_copy(const UA_OPCUATcpHelloMessage *src, UA_OPCUATcpHelloMessage *dst) {
+    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;
-}
-
-UA_Int32 UA_OPCUATcpAcknowledgeMessage_calcSizeBinary(UA_OPCUATcpAcknowledgeMessage const * ptr) {
-    	if(ptr==UA_NULL) return sizeof(UA_OPCUATcpAcknowledgeMessage);
-    	return 0
-	 + sizeof(UA_UInt32) // protocolVersion
-	 + sizeof(UA_UInt32) // receiveBufferSize
-	 + sizeof(UA_UInt32) // sendBufferSize
-	 + sizeof(UA_UInt32) // maxMessageSize
-	 + sizeof(UA_UInt32) // maxChunkCount
-	;
-}
-
-UA_Int32 UA_OPCUATcpAcknowledgeMessage_encodeBinary(UA_OPCUATcpAcknowledgeMessage const * src, UA_ByteString* dst, UA_UInt32 *offset) {
-    	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_UInt32_encodeBinary(&src->protocolVersion,dst,offset);
-	retval |= UA_UInt32_encodeBinary(&src->receiveBufferSize,dst,offset);
-	retval |= UA_UInt32_encodeBinary(&src->sendBufferSize,dst,offset);
-	retval |= UA_UInt32_encodeBinary(&src->maxMessageSize,dst,offset);
-	retval |= UA_UInt32_encodeBinary(&src->maxChunkCount,dst,offset);
-	return retval;
-}
-
-UA_Int32 UA_OPCUATcpAcknowledgeMessage_decodeBinary(UA_ByteString const * src, UA_UInt32 *offset, UA_OPCUATcpAcknowledgeMessage * dst) {
-    	UA_Int32 retval = UA_SUCCESS;
-	UA_OPCUATcpAcknowledgeMessage_init(dst);
-	CHECKED_DECODE(UA_UInt32_decodeBinary(src,offset,&dst->protocolVersion), UA_OPCUATcpAcknowledgeMessage_deleteMembers(dst));
-	CHECKED_DECODE(UA_UInt32_decodeBinary(src,offset,&dst->receiveBufferSize), UA_OPCUATcpAcknowledgeMessage_deleteMembers(dst));
-	CHECKED_DECODE(UA_UInt32_decodeBinary(src,offset,&dst->sendBufferSize), UA_OPCUATcpAcknowledgeMessage_deleteMembers(dst));
-	CHECKED_DECODE(UA_UInt32_decodeBinary(src,offset,&dst->maxMessageSize), UA_OPCUATcpAcknowledgeMessage_deleteMembers(dst));
-	CHECKED_DECODE(UA_UInt32_decodeBinary(src,offset,&dst->maxChunkCount), UA_OPCUATcpAcknowledgeMessage_deleteMembers(dst));
-	return retval;
+    memcpy(dst, src, sizeof(UA_OPCUATcpHelloMessage));
+    retval |= UA_String_copy(&src->endpointUrl, &dst->endpointUrl);
+    return retval;
+}
+
+UA_Int32 UA_OPCUATcpAcknowledgeMessage_calcSizeBinary(UA_OPCUATcpAcknowledgeMessage const *ptr) {
+    if(ptr == UA_NULL) return sizeof(UA_OPCUATcpAcknowledgeMessage);
+    return 0
+           + sizeof(UA_UInt32) // protocolVersion
+           + sizeof(UA_UInt32) // receiveBufferSize
+           + sizeof(UA_UInt32) // sendBufferSize
+           + sizeof(UA_UInt32) // maxMessageSize
+           + sizeof(UA_UInt32) // maxChunkCount
+    ;
+}
+
+UA_Int32 UA_OPCUATcpAcknowledgeMessage_encodeBinary(UA_OPCUATcpAcknowledgeMessage const *src,
+                                                    UA_ByteString                       *dst,
+                                                    UA_UInt32                           *offset) {
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_UInt32_encodeBinary(&src->protocolVersion, dst, offset);
+    retval |= UA_UInt32_encodeBinary(&src->receiveBufferSize, dst, offset);
+    retval |= UA_UInt32_encodeBinary(&src->sendBufferSize, dst, offset);
+    retval |= UA_UInt32_encodeBinary(&src->maxMessageSize, dst, offset);
+    retval |= UA_UInt32_encodeBinary(&src->maxChunkCount, dst, offset);
+    return retval;
+}
+
+UA_Int32 UA_OPCUATcpAcknowledgeMessage_decodeBinary(UA_ByteString const *src, UA_UInt32 *offset,
+                                                    UA_OPCUATcpAcknowledgeMessage *dst) {
+    UA_Int32 retval = UA_SUCCESS;
+    UA_OPCUATcpAcknowledgeMessage_init(dst);
+    CHECKED_DECODE(UA_UInt32_decodeBinary(src, offset,
+                                          &dst->protocolVersion),
+                   UA_OPCUATcpAcknowledgeMessage_deleteMembers(dst));
+    CHECKED_DECODE(UA_UInt32_decodeBinary(src, offset,
+                                          &dst->receiveBufferSize),
+                   UA_OPCUATcpAcknowledgeMessage_deleteMembers(dst));
+    CHECKED_DECODE(UA_UInt32_decodeBinary(src, offset,
+                                          &dst->sendBufferSize),
+                   UA_OPCUATcpAcknowledgeMessage_deleteMembers(dst));
+    CHECKED_DECODE(UA_UInt32_decodeBinary(src, offset,
+                                          &dst->maxMessageSize),
+                   UA_OPCUATcpAcknowledgeMessage_deleteMembers(dst));
+    CHECKED_DECODE(UA_UInt32_decodeBinary(src, offset,
+                                          &dst->maxChunkCount),
+                   UA_OPCUATcpAcknowledgeMessage_deleteMembers(dst));
+    return retval;
 }
 
 UA_Int32 UA_OPCUATcpAcknowledgeMessage_delete(UA_OPCUATcpAcknowledgeMessage *p) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_OPCUATcpAcknowledgeMessage_deleteMembers(p);
-	retval |= UA_free(p);
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_OPCUATcpAcknowledgeMessage_deleteMembers(p);
+    retval |= UA_free(p);
+    return retval;
 }
 
 UA_Int32 UA_OPCUATcpAcknowledgeMessage_deleteMembers(UA_OPCUATcpAcknowledgeMessage *p) {
-    	UA_Int32 retval = UA_SUCCESS;
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    return retval;
 }
 
 UA_Int32 UA_OPCUATcpAcknowledgeMessage_init(UA_OPCUATcpAcknowledgeMessage *p) {
-    	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_UInt32_init(&p->protocolVersion);
-	retval |= UA_UInt32_init(&p->receiveBufferSize);
-	retval |= UA_UInt32_init(&p->sendBufferSize);
-	retval |= UA_UInt32_init(&p->maxMessageSize);
-	retval |= UA_UInt32_init(&p->maxChunkCount);
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_UInt32_init(&p->protocolVersion);
+    retval |= UA_UInt32_init(&p->receiveBufferSize);
+    retval |= UA_UInt32_init(&p->sendBufferSize);
+    retval |= UA_UInt32_init(&p->maxMessageSize);
+    retval |= UA_UInt32_init(&p->maxChunkCount);
+    return retval;
 }
 
 UA_TYPE_NEW_DEFAULT(UA_OPCUATcpAcknowledgeMessage)
-UA_Int32 UA_OPCUATcpAcknowledgeMessage_copy(const UA_OPCUATcpAcknowledgeMessage *src,UA_OPCUATcpAcknowledgeMessage *dst) {
-	UA_Int32 retval = UA_SUCCESS;
+UA_Int32 UA_OPCUATcpAcknowledgeMessage_copy(const UA_OPCUATcpAcknowledgeMessage *src,
+                                            UA_OPCUATcpAcknowledgeMessage       *dst) {
+    UA_Int32 retval = UA_SUCCESS;
     if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
-	memcpy(dst, src, sizeof(UA_OPCUATcpAcknowledgeMessage));
-	return retval;
+    memcpy(dst, src, sizeof(UA_OPCUATcpAcknowledgeMessage));
+    return retval;
 }
 
-UA_Int32 UA_SecureConversationMessageHeader_calcSizeBinary(UA_SecureConversationMessageHeader const * ptr) {
-    	if(ptr==UA_NULL) return sizeof(UA_SecureConversationMessageHeader);
-    	return 0
-	 + sizeof(UA_OPCUATcpMessageHeader) // messageHeader CHECK: delete this or use in binary_secure.c
-	 + sizeof(UA_UInt32) // secureChannelId
-	;
+UA_Int32 UA_SecureConversationMessageHeader_calcSizeBinary(UA_SecureConversationMessageHeader const *ptr) {
+    if(ptr == UA_NULL) return sizeof(UA_SecureConversationMessageHeader);
+    return 0
+           + sizeof(UA_OPCUATcpMessageHeader) // messageHeader CHECK: delete this or use in binary_secure.c
+           + sizeof(UA_UInt32)                // secureChannelId
+    ;
 }
 
-UA_Int32 UA_SecureConversationMessageHeader_encodeBinary(UA_SecureConversationMessageHeader const * src, UA_ByteString* dst, UA_UInt32 *offset) {
-    	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_OPCUATcpMessageHeader_encodeBinary(&src->messageHeader,dst,offset);
-	retval |= UA_UInt32_encodeBinary(&src->secureChannelId,dst,offset);
-	return retval;
+UA_Int32 UA_SecureConversationMessageHeader_encodeBinary(UA_SecureConversationMessageHeader const *src,
+                                                         UA_ByteString                            *dst,
+                                                         UA_UInt32                                *offset) {
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_OPCUATcpMessageHeader_encodeBinary(&src->messageHeader, dst, offset);
+    retval |= UA_UInt32_encodeBinary(&src->secureChannelId, dst, offset);
+    return retval;
 }
 
-UA_Int32 UA_SecureConversationMessageHeader_decodeBinary(UA_ByteString const * src, UA_UInt32 *offset, UA_SecureConversationMessageHeader * dst) {
-    	UA_Int32 retval = UA_SUCCESS;
-	UA_SecureConversationMessageHeader_init(dst);
-	CHECKED_DECODE(UA_OPCUATcpMessageHeader_decodeBinary(src,offset,&dst->messageHeader), UA_SecureConversationMessageHeader_deleteMembers(dst));
-	CHECKED_DECODE(UA_UInt32_decodeBinary(src,offset,&dst->secureChannelId), UA_SecureConversationMessageHeader_deleteMembers(dst));
-	return retval;
+UA_Int32 UA_SecureConversationMessageHeader_decodeBinary(UA_ByteString const *src, UA_UInt32 *offset,
+                                                         UA_SecureConversationMessageHeader *dst) {
+    UA_Int32 retval = UA_SUCCESS;
+    UA_SecureConversationMessageHeader_init(dst);
+    CHECKED_DECODE(UA_OPCUATcpMessageHeader_decodeBinary(src, offset,
+                                                         &dst->messageHeader),
+                   UA_SecureConversationMessageHeader_deleteMembers(dst));
+    CHECKED_DECODE(UA_UInt32_decodeBinary(src, offset,
+                                          &dst->secureChannelId),
+                   UA_SecureConversationMessageHeader_deleteMembers(dst));
+    return retval;
 }
 
 UA_Int32 UA_SecureConversationMessageHeader_delete(UA_SecureConversationMessageHeader *p) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_SecureConversationMessageHeader_deleteMembers(p);
-	retval |= UA_free(p);
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_SecureConversationMessageHeader_deleteMembers(p);
+    retval |= UA_free(p);
+    return retval;
 }
 
 UA_Int32 UA_SecureConversationMessageHeader_deleteMembers(UA_SecureConversationMessageHeader *p) {
-    	UA_Int32 retval = UA_SUCCESS;
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    return retval;
 }
 
 UA_Int32 UA_SecureConversationMessageHeader_init(UA_SecureConversationMessageHeader *p) {
-    	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_OPCUATcpMessageHeader_init(&p->messageHeader);
-	retval |= UA_UInt32_init(&p->secureChannelId);
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_OPCUATcpMessageHeader_init(&p->messageHeader);
+    retval |= UA_UInt32_init(&p->secureChannelId);
+    return retval;
 }
 
 UA_TYPE_NEW_DEFAULT(UA_SecureConversationMessageHeader)
-UA_Int32 UA_SecureConversationMessageHeader_copy(const UA_SecureConversationMessageHeader *src,UA_SecureConversationMessageHeader *dst) {
-	UA_Int32 retval = UA_SUCCESS;
+UA_Int32 UA_SecureConversationMessageHeader_copy(const UA_SecureConversationMessageHeader *src,
+                                                 UA_SecureConversationMessageHeader       *dst) {
+    UA_Int32 retval = UA_SUCCESS;
     if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
-	memcpy(dst, src, sizeof(UA_SecureConversationMessageHeader));
-	return retval;
-}
-
-UA_Int32 UA_AsymmetricAlgorithmSecurityHeader_calcSizeBinary(UA_AsymmetricAlgorithmSecurityHeader const * ptr) {
-    	if(ptr==UA_NULL) return sizeof(UA_AsymmetricAlgorithmSecurityHeader);
-    	return 0
-	 + UA_ByteString_calcSizeBinary(&ptr->securityPolicyUri)
-	 + UA_ByteString_calcSizeBinary(&ptr->senderCertificate)
-	 + UA_ByteString_calcSizeBinary(&ptr->receiverCertificateThumbprint)
-	;
-}
-
-UA_Int32 UA_AsymmetricAlgorithmSecurityHeader_encodeBinary(UA_AsymmetricAlgorithmSecurityHeader const * src, UA_ByteString* dst, UA_UInt32 *offset) {
-    	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_ByteString_encodeBinary(&src->securityPolicyUri,dst,offset);
-	retval |= UA_ByteString_encodeBinary(&src->senderCertificate,dst,offset);
-	retval |= UA_ByteString_encodeBinary(&src->receiverCertificateThumbprint,dst,offset);
-	return retval;
-}
-
-UA_Int32 UA_AsymmetricAlgorithmSecurityHeader_decodeBinary(UA_ByteString const * src, UA_UInt32 *offset, UA_AsymmetricAlgorithmSecurityHeader * dst) {
-    	UA_Int32 retval = UA_SUCCESS;
-	UA_AsymmetricAlgorithmSecurityHeader_init(dst);
-	CHECKED_DECODE(UA_ByteString_decodeBinary(src,offset,&dst->securityPolicyUri), UA_AsymmetricAlgorithmSecurityHeader_deleteMembers(dst));
-	CHECKED_DECODE(UA_ByteString_decodeBinary(src,offset,&dst->senderCertificate), UA_AsymmetricAlgorithmSecurityHeader_deleteMembers(dst));
-	CHECKED_DECODE(UA_ByteString_decodeBinary(src,offset,&dst->receiverCertificateThumbprint), UA_AsymmetricAlgorithmSecurityHeader_deleteMembers(dst));
-	return retval;
+    memcpy(dst, src, sizeof(UA_SecureConversationMessageHeader));
+    return retval;
+}
+
+UA_Int32 UA_AsymmetricAlgorithmSecurityHeader_calcSizeBinary(UA_AsymmetricAlgorithmSecurityHeader const *ptr)
+{
+    if(ptr == UA_NULL) return sizeof(UA_AsymmetricAlgorithmSecurityHeader);
+    return 0
+           + UA_ByteString_calcSizeBinary(&ptr->securityPolicyUri)
+           + UA_ByteString_calcSizeBinary(&ptr->senderCertificate)
+           + UA_ByteString_calcSizeBinary(&ptr->receiverCertificateThumbprint)
+    ;
+}
+
+UA_Int32 UA_AsymmetricAlgorithmSecurityHeader_encodeBinary(UA_AsymmetricAlgorithmSecurityHeader const *src,
+                                                           UA_ByteString                              *dst,
+                                                           UA_UInt32                                  *offset)
+{
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_ByteString_encodeBinary(&src->securityPolicyUri, dst, offset);
+    retval |= UA_ByteString_encodeBinary(&src->senderCertificate, dst, offset);
+    retval |= UA_ByteString_encodeBinary(&src->receiverCertificateThumbprint, dst, offset);
+    return retval;
+}
+
+UA_Int32 UA_AsymmetricAlgorithmSecurityHeader_decodeBinary(UA_ByteString const *src, UA_UInt32 *offset,
+                                                           UA_AsymmetricAlgorithmSecurityHeader *dst) {
+    UA_Int32 retval = UA_SUCCESS;
+    UA_AsymmetricAlgorithmSecurityHeader_init(dst);
+    CHECKED_DECODE(UA_ByteString_decodeBinary(src, offset,
+                                              &dst->securityPolicyUri),
+                   UA_AsymmetricAlgorithmSecurityHeader_deleteMembers(dst));
+    CHECKED_DECODE(UA_ByteString_decodeBinary(src, offset,
+                                              &dst->senderCertificate),
+                   UA_AsymmetricAlgorithmSecurityHeader_deleteMembers(dst));
+    CHECKED_DECODE(UA_ByteString_decodeBinary(src, offset,
+                                              &dst->receiverCertificateThumbprint),
+                   UA_AsymmetricAlgorithmSecurityHeader_deleteMembers(dst));
+    return retval;
 }
 
 UA_Int32 UA_AsymmetricAlgorithmSecurityHeader_delete(UA_AsymmetricAlgorithmSecurityHeader *p) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_AsymmetricAlgorithmSecurityHeader_deleteMembers(p);
-	retval |= UA_free(p);
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_AsymmetricAlgorithmSecurityHeader_deleteMembers(p);
+    retval |= UA_free(p);
+    return retval;
 }
 
 UA_Int32 UA_AsymmetricAlgorithmSecurityHeader_deleteMembers(UA_AsymmetricAlgorithmSecurityHeader *p) {
-    	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_ByteString_deleteMembers(&p->securityPolicyUri);
-	retval |= UA_ByteString_deleteMembers(&p->senderCertificate);
-	retval |= UA_ByteString_deleteMembers(&p->receiverCertificateThumbprint);
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_ByteString_deleteMembers(&p->securityPolicyUri);
+    retval |= UA_ByteString_deleteMembers(&p->senderCertificate);
+    retval |= UA_ByteString_deleteMembers(&p->receiverCertificateThumbprint);
+    return retval;
 }
 
 UA_Int32 UA_AsymmetricAlgorithmSecurityHeader_init(UA_AsymmetricAlgorithmSecurityHeader *p) {
-    	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_ByteString_init(&p->securityPolicyUri);
-	retval |= UA_ByteString_init(&p->senderCertificate);
-	retval |= UA_ByteString_init(&p->receiverCertificateThumbprint);
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_ByteString_init(&p->securityPolicyUri);
+    retval |= UA_ByteString_init(&p->senderCertificate);
+    retval |= UA_ByteString_init(&p->receiverCertificateThumbprint);
+    return retval;
 }
 
 UA_TYPE_NEW_DEFAULT(UA_AsymmetricAlgorithmSecurityHeader)
-UA_Int32 UA_AsymmetricAlgorithmSecurityHeader_copy(const UA_AsymmetricAlgorithmSecurityHeader *src,UA_AsymmetricAlgorithmSecurityHeader *dst) {
-	UA_Int32 retval = UA_SUCCESS;
+UA_Int32 UA_AsymmetricAlgorithmSecurityHeader_copy(const UA_AsymmetricAlgorithmSecurityHeader *src,
+                                                   UA_AsymmetricAlgorithmSecurityHeader       *dst) {
+    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);
-	retval |= UA_ByteString_copy(&src->receiverCertificateThumbprint,&dst->receiverCertificateThumbprint);
-	return retval;
+    memcpy(dst, src, sizeof(UA_AsymmetricAlgorithmSecurityHeader));
+    retval |= UA_ByteString_copy(&src->securityPolicyUri, &dst->securityPolicyUri);
+    retval |= UA_ByteString_copy(&src->senderCertificate, &dst->senderCertificate);
+    retval |= UA_ByteString_copy(&src->receiverCertificateThumbprint, &dst->receiverCertificateThumbprint);
+    return retval;
 }
 
-UA_Int32 UA_SymmetricAlgorithmSecurityHeader_calcSizeBinary(UA_SymmetricAlgorithmSecurityHeader const * ptr) {
-    	if(ptr==UA_NULL) return sizeof(UA_SymmetricAlgorithmSecurityHeader);
-    	return 0
-	 + sizeof(UA_UInt32) // tokenId
-	;
+UA_Int32 UA_SymmetricAlgorithmSecurityHeader_calcSizeBinary(UA_SymmetricAlgorithmSecurityHeader const *ptr) {
+    if(ptr == UA_NULL) return sizeof(UA_SymmetricAlgorithmSecurityHeader);
+    return 0
+           + sizeof(UA_UInt32) // tokenId
+    ;
 }
 
-UA_Int32 UA_SymmetricAlgorithmSecurityHeader_encodeBinary(UA_SymmetricAlgorithmSecurityHeader const * src, UA_ByteString* dst, UA_UInt32 *offset) {
-    	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_UInt32_encodeBinary(&src->tokenId,dst,offset);
-	return retval;
+UA_Int32 UA_SymmetricAlgorithmSecurityHeader_encodeBinary(UA_SymmetricAlgorithmSecurityHeader const *src,
+                                                          UA_ByteString                             *dst,
+                                                          UA_UInt32                                 *offset)
+{
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_UInt32_encodeBinary(&src->tokenId, dst, offset);
+    return retval;
 }
 
-UA_Int32 UA_SymmetricAlgorithmSecurityHeader_decodeBinary(UA_ByteString const * src, UA_UInt32 *offset, UA_SymmetricAlgorithmSecurityHeader * dst) {
-    	UA_Int32 retval = UA_SUCCESS;
-	UA_SymmetricAlgorithmSecurityHeader_init(dst);
-	CHECKED_DECODE(UA_UInt32_decodeBinary(src,offset,&dst->tokenId), UA_SymmetricAlgorithmSecurityHeader_deleteMembers(dst));
-	return retval;
+UA_Int32 UA_SymmetricAlgorithmSecurityHeader_decodeBinary(UA_ByteString const *src, UA_UInt32 *offset,
+                                                          UA_SymmetricAlgorithmSecurityHeader *dst) {
+    UA_Int32 retval = UA_SUCCESS;
+    UA_SymmetricAlgorithmSecurityHeader_init(dst);
+    CHECKED_DECODE(UA_UInt32_decodeBinary(src, offset,
+                                          &dst->tokenId),
+                   UA_SymmetricAlgorithmSecurityHeader_deleteMembers(dst));
+    return retval;
 }
 
 UA_Int32 UA_SymmetricAlgorithmSecurityHeader_delete(UA_SymmetricAlgorithmSecurityHeader *p) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_SymmetricAlgorithmSecurityHeader_deleteMembers(p);
-	retval |= UA_free(p);
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_SymmetricAlgorithmSecurityHeader_deleteMembers(p);
+    retval |= UA_free(p);
+    return retval;
 }
 
 UA_Int32 UA_SymmetricAlgorithmSecurityHeader_deleteMembers(UA_SymmetricAlgorithmSecurityHeader *p) {
-    	UA_Int32 retval = UA_SUCCESS;
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    return retval;
 }
 
 UA_Int32 UA_SymmetricAlgorithmSecurityHeader_init(UA_SymmetricAlgorithmSecurityHeader *p) {
-    	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_UInt32_init(&p->tokenId);
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_UInt32_init(&p->tokenId);
+    return retval;
 }
 
 UA_TYPE_NEW_DEFAULT(UA_SymmetricAlgorithmSecurityHeader)
-UA_Int32 UA_SymmetricAlgorithmSecurityHeader_copy(const UA_SymmetricAlgorithmSecurityHeader *src,UA_SymmetricAlgorithmSecurityHeader *dst) {
-	UA_Int32 retval = UA_SUCCESS;
+UA_Int32 UA_SymmetricAlgorithmSecurityHeader_copy(const UA_SymmetricAlgorithmSecurityHeader *src,
+                                                  UA_SymmetricAlgorithmSecurityHeader       *dst) {
+    UA_Int32 retval = UA_SUCCESS;
     if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
-	memcpy(dst, src, sizeof(UA_SymmetricAlgorithmSecurityHeader));
-	return retval;
+    memcpy(dst, src, sizeof(UA_SymmetricAlgorithmSecurityHeader));
+    return retval;
 }
 
-UA_Int32 UA_SequenceHeader_calcSizeBinary(UA_SequenceHeader const * ptr) {
-    	if(ptr==UA_NULL) return sizeof(UA_SequenceHeader);
-    	return 0
-	 + sizeof(UA_UInt32) // sequenceNumber
-	 + sizeof(UA_UInt32) // requestId
-	;
+UA_Int32 UA_SequenceHeader_calcSizeBinary(UA_SequenceHeader const *ptr) {
+    if(ptr == UA_NULL) return sizeof(UA_SequenceHeader);
+    return 0
+           + sizeof(UA_UInt32) // sequenceNumber
+           + sizeof(UA_UInt32) // requestId
+    ;
 }
 
-UA_Int32 UA_SequenceHeader_encodeBinary(UA_SequenceHeader const * src, UA_ByteString* dst, UA_UInt32 *offset) {
-    	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_UInt32_encodeBinary(&src->sequenceNumber,dst,offset);
-	retval |= UA_UInt32_encodeBinary(&src->requestId,dst,offset);
-	return retval;
+UA_Int32 UA_SequenceHeader_encodeBinary(UA_SequenceHeader const *src, UA_ByteString *dst,
+                                        UA_UInt32 *offset) {
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_UInt32_encodeBinary(&src->sequenceNumber, dst, offset);
+    retval |= UA_UInt32_encodeBinary(&src->requestId, dst, offset);
+    return retval;
 }
 
-UA_Int32 UA_SequenceHeader_decodeBinary(UA_ByteString const * src, UA_UInt32 *offset, UA_SequenceHeader * dst) {
-    	UA_Int32 retval = UA_SUCCESS;
-	UA_SequenceHeader_init(dst);
-	CHECKED_DECODE(UA_UInt32_decodeBinary(src,offset,&dst->sequenceNumber), UA_SequenceHeader_deleteMembers(dst));
-	CHECKED_DECODE(UA_UInt32_decodeBinary(src,offset,&dst->requestId), UA_SequenceHeader_deleteMembers(dst));
-	return retval;
+UA_Int32 UA_SequenceHeader_decodeBinary(UA_ByteString const *src, UA_UInt32 *offset,
+                                        UA_SequenceHeader *dst) {
+    UA_Int32 retval = UA_SUCCESS;
+    UA_SequenceHeader_init(dst);
+    CHECKED_DECODE(UA_UInt32_decodeBinary(src, offset,
+                                          &dst->sequenceNumber), UA_SequenceHeader_deleteMembers(dst));
+    CHECKED_DECODE(UA_UInt32_decodeBinary(src, offset, &dst->requestId), UA_SequenceHeader_deleteMembers(dst));
+    return retval;
 }
 
 UA_Int32 UA_SequenceHeader_delete(UA_SequenceHeader *p) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_SequenceHeader_deleteMembers(p);
-	retval |= UA_free(p);
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_SequenceHeader_deleteMembers(p);
+    retval |= UA_free(p);
+    return retval;
 }
 
 UA_Int32 UA_SequenceHeader_deleteMembers(UA_SequenceHeader *p) {
-    	UA_Int32 retval = UA_SUCCESS;
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    return retval;
 }
 
 UA_Int32 UA_SequenceHeader_init(UA_SequenceHeader *p) {
-    	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_UInt32_init(&p->sequenceNumber);
-	retval |= UA_UInt32_init(&p->requestId);
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_UInt32_init(&p->sequenceNumber);
+    retval |= UA_UInt32_init(&p->requestId);
+    return retval;
 }
 
 UA_TYPE_NEW_DEFAULT(UA_SequenceHeader)
-UA_Int32 UA_SequenceHeader_copy(const UA_SequenceHeader *src,UA_SequenceHeader *dst) {
-	UA_Int32 retval = UA_SUCCESS;
+UA_Int32 UA_SequenceHeader_copy(const UA_SequenceHeader *src, UA_SequenceHeader *dst) {
+    UA_Int32 retval = UA_SUCCESS;
     if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
-	memcpy(dst, src, sizeof(UA_SequenceHeader));
-	return retval;
+    memcpy(dst, src, sizeof(UA_SequenceHeader));
+    return retval;
 }
 
-UA_Int32 UA_SecureConversationMessageFooter_calcSizeBinary(UA_SecureConversationMessageFooter const * ptr) {
-    	if(ptr==UA_NULL) return sizeof(UA_SecureConversationMessageFooter);
-    	return 0 + UA_Array_calcSizeBinary(ptr->paddingSize, &UA_.types[UA_BYTE],ptr->padding)
-	 + sizeof(UA_Byte) // signature
-	;
+UA_Int32 UA_SecureConversationMessageFooter_calcSizeBinary(UA_SecureConversationMessageFooter const *ptr) {
+    if(ptr == UA_NULL) return sizeof(UA_SecureConversationMessageFooter);
+    return 0 + UA_Array_calcSizeBinary(ptr->paddingSize, &UA_.types[UA_BYTE], ptr->padding)
+           + sizeof(UA_Byte) // signature
+    ;
 }
 
-UA_Int32 UA_SecureConversationMessageFooter_encodeBinary(UA_SecureConversationMessageFooter const * src, UA_ByteString* dst, UA_UInt32 *offset) {
-    	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_Array_encodeBinary(src->padding,src->paddingSize,&UA_.types[UA_BYTE],dst,offset);
-	retval |= UA_Byte_encodeBinary(&src->signature,dst,offset);
+UA_Int32 UA_SecureConversationMessageFooter_encodeBinary(UA_SecureConversationMessageFooter const *src,
+                                                         UA_ByteString                            *dst,
+                                                         UA_UInt32                                *offset) {
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_Array_encodeBinary(src->padding, src->paddingSize, &UA_.types[UA_BYTE], dst, offset);
+    retval |= UA_Byte_encodeBinary(&src->signature, dst, offset);
 
-	return retval;
+    return retval;
 }
 
-UA_Int32 UA_SecureConversationMessageFooter_decodeBinary(UA_ByteString const * src, UA_UInt32 *offset, UA_SecureConversationMessageFooter * dst) {
-    	UA_Int32 retval = UA_SUCCESS;
-	UA_SecureConversationMessageFooter_init(dst);
-	CHECKED_DECODE(UA_Int32_decodeBinary(src,offset,&dst->paddingSize),UA_SecureConversationMessageFooter_deleteMembers(dst));
-	CHECKED_DECODE(UA_Array_decodeBinary(src,offset,dst->paddingSize,&UA_.types[UA_BYTE],(void**)&dst->padding), UA_SecureConversationMessageFooter_deleteMembers(dst));
-	CHECKED_DECODE(UA_Byte_decodeBinary(src,offset,&dst->signature), UA_SecureConversationMessageFooter_deleteMembers(dst));
-	return retval;
+UA_Int32 UA_SecureConversationMessageFooter_decodeBinary(UA_ByteString const *src, UA_UInt32 *offset,
+                                                         UA_SecureConversationMessageFooter *dst) {
+    UA_Int32 retval = UA_SUCCESS;
+    UA_SecureConversationMessageFooter_init(dst);
+    CHECKED_DECODE(UA_Int32_decodeBinary(src, offset,
+                                         &dst->paddingSize),
+                   UA_SecureConversationMessageFooter_deleteMembers(dst));
+    CHECKED_DECODE(UA_Array_decodeBinary(src, offset, dst->paddingSize, &UA_.types[UA_BYTE],
+                                         (void **)&dst->padding),
+                   UA_SecureConversationMessageFooter_deleteMembers(dst));
+    CHECKED_DECODE(UA_Byte_decodeBinary(src, offset,
+                                        &dst->signature),
+                   UA_SecureConversationMessageFooter_deleteMembers(dst));
+    return retval;
 }
 
 UA_Int32 UA_SecureConversationMessageFooter_delete(UA_SecureConversationMessageFooter *p) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_SecureConversationMessageFooter_deleteMembers(p);
-	retval |= UA_free(p);
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_SecureConversationMessageFooter_deleteMembers(p);
+    retval |= UA_free(p);
+    return retval;
 }
 
 UA_Int32 UA_SecureConversationMessageFooter_deleteMembers(UA_SecureConversationMessageFooter *p) {
-    	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_Array_delete((void*)p->padding,p->paddingSize,&UA_.types[UA_BYTE]);
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_Array_delete((void *)p->padding, p->paddingSize, &UA_.types[UA_BYTE]);
+    return retval;
 }
 
 UA_Int32 UA_SecureConversationMessageFooter_init(UA_SecureConversationMessageFooter *p) {
-    	UA_Int32 retval = UA_SUCCESS;
-	p->paddingSize = 0;
-	p->padding = UA_NULL;
-	retval |= UA_Byte_init(&p->signature);
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    p->paddingSize = 0;
+    p->padding     = UA_NULL;
+    retval |= UA_Byte_init(&p->signature);
+    return retval;
 }
 
 UA_TYPE_NEW_DEFAULT(UA_SecureConversationMessageFooter)
-UA_Int32 UA_SecureConversationMessageFooter_copy(const UA_SecureConversationMessageFooter *src,UA_SecureConversationMessageFooter *dst) {
-	UA_Int32 retval = UA_SUCCESS;
+UA_Int32 UA_SecureConversationMessageFooter_copy(const UA_SecureConversationMessageFooter *src,
+                                                 UA_SecureConversationMessageFooter       *dst) {
+    UA_Int32 retval = UA_SUCCESS;
     if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;
-	memcpy(dst, src, sizeof(UA_SecureConversationMessageFooter));
+    memcpy(dst, src, sizeof(UA_SecureConversationMessageFooter));
 
 
-	retval |= UA_Array_copy(src->padding, src->paddingSize,&UA_.types[UA_BYTE],(void**)&dst->padding);
-	return retval;
+    retval |= UA_Array_copy(src->padding, src->paddingSize, &UA_.types[UA_BYTE], (void **)&dst->padding);
+    return retval;
 }
 
-UA_Int32 UA_SecureConversationMessageAbortBody_calcSizeBinary(UA_SecureConversationMessageAbortBody const * ptr) {
-    	if(ptr==UA_NULL) return sizeof(UA_SecureConversationMessageAbortBody);
-    	return 0
-	 + sizeof(UA_UInt32) // error
-	 + UA_String_calcSizeBinary(&ptr->reason)
-	;
+UA_Int32 UA_SecureConversationMessageAbortBody_calcSizeBinary(
+    UA_SecureConversationMessageAbortBody const *ptr) {
+    if(ptr == UA_NULL) return sizeof(UA_SecureConversationMessageAbortBody);
+    return 0
+           + sizeof(UA_UInt32) // error
+           + UA_String_calcSizeBinary(&ptr->reason)
+    ;
 }
 
-UA_Int32 UA_SecureConversationMessageAbortBody_encodeBinary(UA_SecureConversationMessageAbortBody const * src, UA_ByteString* dst, UA_UInt32 *offset) {
-    	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_UInt32_encodeBinary(&src->error,dst,offset);
-	retval |= UA_String_encodeBinary(&src->reason,dst,offset);
-	return retval;
+UA_Int32 UA_SecureConversationMessageAbortBody_encodeBinary(
+    UA_SecureConversationMessageAbortBody const *src,
+    UA_ByteString                               *dst,
+    UA_UInt32                                   *
+    offset) {
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_UInt32_encodeBinary(&src->error, dst, offset);
+    retval |= UA_String_encodeBinary(&src->reason, dst, offset);
+    return retval;
 }
 
-UA_Int32 UA_SecureConversationMessageAbortBody_decodeBinary(UA_ByteString const * src, UA_UInt32 *offset, UA_SecureConversationMessageAbortBody * dst) {
-    	UA_Int32 retval = UA_SUCCESS;
-	UA_SecureConversationMessageAbortBody_init(dst);
-	CHECKED_DECODE(UA_UInt32_decodeBinary(src,offset,&dst->error), UA_SecureConversationMessageAbortBody_deleteMembers(dst));
-	CHECKED_DECODE(UA_String_decodeBinary(src,offset,&dst->reason), UA_SecureConversationMessageAbortBody_deleteMembers(dst));
-	return retval;
+UA_Int32 UA_SecureConversationMessageAbortBody_decodeBinary(UA_ByteString const *src, UA_UInt32 *offset,
+                                                            UA_SecureConversationMessageAbortBody *dst) {
+    UA_Int32 retval = UA_SUCCESS;
+    UA_SecureConversationMessageAbortBody_init(dst);
+    CHECKED_DECODE(UA_UInt32_decodeBinary(src, offset,
+                                          &dst->error),
+                   UA_SecureConversationMessageAbortBody_deleteMembers(dst));
+    CHECKED_DECODE(UA_String_decodeBinary(src, offset,
+                                          &dst->reason),
+                   UA_SecureConversationMessageAbortBody_deleteMembers(dst));
+    return retval;
 }
 
 UA_Int32 UA_SecureConversationMessageAbortBody_delete(UA_SecureConversationMessageAbortBody *p) {
-	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_SecureConversationMessageAbortBody_deleteMembers(p);
-	retval |= UA_free(p);
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_SecureConversationMessageAbortBody_deleteMembers(p);
+    retval |= UA_free(p);
+    return retval;
 }
 
 UA_Int32 UA_SecureConversationMessageAbortBody_deleteMembers(UA_SecureConversationMessageAbortBody *p) {
-    	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_String_deleteMembers(&p->reason);
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_String_deleteMembers(&p->reason);
+    return retval;
 }
 
 UA_Int32 UA_SecureConversationMessageAbortBody_init(UA_SecureConversationMessageAbortBody *p) {
-    	UA_Int32 retval = UA_SUCCESS;
-	retval |= UA_UInt32_init(&p->error);
-	retval |= UA_String_init(&p->reason);
-	return retval;
+    UA_Int32 retval = UA_SUCCESS;
+    retval |= UA_UInt32_init(&p->error);
+    retval |= UA_String_init(&p->reason);
+    return retval;
 }
 
 UA_TYPE_NEW_DEFAULT(UA_SecureConversationMessageAbortBody)
-UA_Int32 UA_SecureConversationMessageAbortBody_copy(const UA_SecureConversationMessageAbortBody *src,UA_SecureConversationMessageAbortBody *dst) {
-	UA_Int32 retval = UA_SUCCESS;
+UA_Int32 UA_SecureConversationMessageAbortBody_copy(const UA_SecureConversationMessageAbortBody *src,
+                                                    UA_SecureConversationMessageAbortBody       *dst) {
+    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;
+    memcpy(dst, src, sizeof(UA_SecureConversationMessageAbortBody));
+    retval |= UA_String_copy(&src->reason, &dst->reason);
+    return retval;
 }

+ 39 - 39
src/ua_transport.h

@@ -5,107 +5,107 @@
 #include "ua_types_encoding_binary.h"
 
 typedef enum SecurityTokenRequestType {
-	UA_SECURITYTOKEN_ISSUE = 0,
-	UA_SECURITYTOKEN_RENEW = 1
+    UA_SECURITYTOKEN_ISSUE = 0,
+    UA_SECURITYTOKEN_RENEW = 1
 } SecurityTokenRequestType;
 
 typedef enum {
-	UA_SECURITYMODE_INVALID = 0,
-	UA_SECURITYMODE_NONE = 1,
-	UA_SECURITYMODE_SIGNANDENCRYPT = 2
+    UA_SECURITYMODE_INVALID        = 0,
+    UA_SECURITYMODE_NONE           = 1,
+    UA_SECURITYMODE_SIGNANDENCRYPT = 2
 } SecurityMode;
 
 /* MessageType */
 typedef UA_Int32 UA_MessageType;
 enum UA_MessageType {
-	UA_MESSAGETYPE_HEL = 0x48454C, // H E L
-	UA_MESSAGETYPE_ACK = 0x41434B, // A C k
-	UA_MESSAGETYPE_ERR = 0x455151, // E R R
-	UA_MESSAGETYPE_OPN = 0x4F504E, // O P N
-	UA_MESSAGETYPE_MSG = 0x4D5347, // M S G
-	UA_MESSAGETYPE_CLO = 0x434C4F  // C L O
+    UA_MESSAGETYPE_HEL = 0x48454C, // H E L
+    UA_MESSAGETYPE_ACK = 0x41434B, // A C k
+    UA_MESSAGETYPE_ERR = 0x455151, // E R R
+    UA_MESSAGETYPE_OPN = 0x4F504E, // O P N
+    UA_MESSAGETYPE_MSG = 0x4D5347, // M S G
+    UA_MESSAGETYPE_CLO = 0x434C4F  // C L O
 };
 UA_TYPE_PROTOTYPES(UA_MessageType)
 UA_TYPE_BINARY_ENCODING(UA_MessageType)
-void UA_MessageType_printf(char *label, UA_MessageType* p);
+void UA_MessageType_printf(char *label, UA_MessageType *p);
 
 /** @brief TCP Header */
 typedef struct UA_OPCUATcpMessageHeader {
-	UA_MessageType messageType;
-	UA_Byte isFinal;
-	UA_UInt32 messageSize;
+    UA_MessageType messageType;
+    UA_Byte isFinal;
+    UA_UInt32      messageSize;
 } UA_OPCUATcpMessageHeader;
 UA_TYPE_PROTOTYPES(UA_OPCUATcpMessageHeader)
 UA_TYPE_BINARY_ENCODING(UA_OPCUATcpMessageHeader)
 
 /** @brief Hello Message */
 typedef struct UA_OPCUATcpHelloMesage {
-	UA_UInt32 protocolVersion;
-	UA_UInt32 receiveBufferSize;
-	UA_UInt32 sendBufferSize;
-	UA_UInt32 maxMessageSize;
-	UA_UInt32 maxChunkCount;
-	UA_String endpointUrl;
+    UA_UInt32 protocolVersion;
+    UA_UInt32 receiveBufferSize;
+    UA_UInt32 sendBufferSize;
+    UA_UInt32 maxMessageSize;
+    UA_UInt32 maxChunkCount;
+    UA_String endpointUrl;
 } UA_OPCUATcpHelloMessage;
 UA_TYPE_PROTOTYPES(UA_OPCUATcpHelloMessage)
 UA_TYPE_BINARY_ENCODING(UA_OPCUATcpHelloMessage)
 
 /** @brief Acknowledge Message */
 typedef struct UA_OPCUATcpAcknowledgeMessage {
-	UA_UInt32 protocolVersion;
-	UA_UInt32 receiveBufferSize;
-	UA_UInt32 sendBufferSize;
-	UA_UInt32 maxMessageSize;
-	UA_UInt32 maxChunkCount;
+    UA_UInt32 protocolVersion;
+    UA_UInt32 receiveBufferSize;
+    UA_UInt32 sendBufferSize;
+    UA_UInt32 maxMessageSize;
+    UA_UInt32 maxChunkCount;
 } UA_OPCUATcpAcknowledgeMessage;
 UA_TYPE_PROTOTYPES(UA_OPCUATcpAcknowledgeMessage)
 UA_TYPE_BINARY_ENCODING(UA_OPCUATcpAcknowledgeMessage)
 
 /** @brief Secure Layer Sequence Header */
 typedef struct UA_SecureConversationMessageHeader {
-	UA_OPCUATcpMessageHeader messageHeader;
-	UA_UInt32 secureChannelId;
+    UA_OPCUATcpMessageHeader messageHeader;
+    UA_UInt32 secureChannelId;
 } UA_SecureConversationMessageHeader;
 UA_TYPE_PROTOTYPES(UA_SecureConversationMessageHeader)
 UA_TYPE_BINARY_ENCODING(UA_SecureConversationMessageHeader)
 
 /** @brief Security Header> */
 typedef struct UA_AsymmetricAlgorithmSecurityHeader {
-	UA_ByteString securityPolicyUri;
-	UA_ByteString senderCertificate;
-	UA_ByteString receiverCertificateThumbprint;
+    UA_ByteString securityPolicyUri;
+    UA_ByteString senderCertificate;
+    UA_ByteString receiverCertificateThumbprint;
 } UA_AsymmetricAlgorithmSecurityHeader;
 UA_TYPE_PROTOTYPES(UA_AsymmetricAlgorithmSecurityHeader)
 UA_TYPE_BINARY_ENCODING(UA_AsymmetricAlgorithmSecurityHeader)
 
 /** @brief Secure Layer Symmetric Algorithm Header */
 typedef struct UA_SymmetricAlgorithmSecurityHeader {
-	UA_UInt32 tokenId;
+    UA_UInt32 tokenId;
 } UA_SymmetricAlgorithmSecurityHeader;
 UA_TYPE_PROTOTYPES(UA_SymmetricAlgorithmSecurityHeader)
 UA_TYPE_BINARY_ENCODING(UA_SymmetricAlgorithmSecurityHeader)
 
 /** @brief Secure Layer Sequence Header */
 typedef struct UA_SequenceHeader {
-	UA_UInt32 sequenceNumber;
-	UA_UInt32 requestId;
+    UA_UInt32 sequenceNumber;
+    UA_UInt32 requestId;
 } UA_SequenceHeader;
 UA_TYPE_PROTOTYPES(UA_SequenceHeader)
 UA_TYPE_BINARY_ENCODING(UA_SequenceHeader)
 
 /** @brief Secure Conversation Message Footer */
 typedef struct UA_SecureConversationMessageFooter {
-	UA_Int32 paddingSize;
-	UA_Byte* padding;
-	UA_Byte signature;
+    UA_Int32 paddingSize;
+    UA_Byte *padding;
+    UA_Byte  signature;
 } UA_SecureConversationMessageFooter;
 UA_TYPE_PROTOTYPES(UA_SecureConversationMessageFooter)
 UA_TYPE_BINARY_ENCODING(UA_SecureConversationMessageFooter)
 
 /** @brief Secure Conversation Message Abort Body */
 typedef struct UA_SecureConversationMessageAbortBody {
-	UA_UInt32 error;
-	UA_String reason;
+    UA_UInt32 error;
+    UA_String reason;
 } UA_SecureConversationMessageAbortBody;
 UA_TYPE_PROTOTYPES(UA_SecureConversationMessageAbortBody)
 UA_TYPE_BINARY_ENCODING(UA_SecureConversationMessageAbortBody)

File diff suppressed because it is too large
+ 701 - 697
src/ua_types.c


+ 156 - 155
src/ua_types.h

@@ -72,23 +72,23 @@ typedef int16_t UA_Int16;
 
 /** @brief An integer value between 0 and 65 535. */
 typedef uint16_t UA_UInt16;
-#define UA_UINT16_MAX  65535
-#define UA_UINT16_MIN  0
+#define UA_UINT16_MAX 65535
+#define UA_UINT16_MIN 0
 
 /** @brief An integer value between -2 147 483 648 and 2 147 483 647. */
 typedef int32_t UA_Int32;
-#define UA_INT32_MAX  2147483647
-#define UA_INT32_MIN  −2147483648
+#define UA_INT32_MAX 2147483647
+#define UA_INT32_MIN −2147483648
 
 /** @brief An integer value between 0 and 429 4967 295. */
 typedef uint32_t UA_UInt32;
-#define UA_UINT32_MAX  4294967295;
-#define UA_UINT32_MIN  0;
+#define UA_UINT32_MAX 4294967295
+#define UA_UINT32_MIN 0
 
 /** @brief An integer value between -10 223 372 036 854 775 808 and 9 223 372 036 854 775 807 */
 typedef int64_t UA_Int64;
-#define UA_INT64_MAX  9223372036854775807
-#define UA_INT64_MIN  −9223372036854775808
+#define UA_INT64_MAX 9223372036854775807
+#define UA_INT64_MIN −9223372036854775808
 
 /** @brief An integer value between 0 and 18 446 744 073 709 551 615. */
 typedef uint64_t UA_UInt64;
@@ -103,8 +103,8 @@ typedef double UA_Double;
 
 /** @brief A sequence of Unicode characters. */
 typedef struct UA_String {
-	UA_Int32 length;
-	UA_Byte *data;
+    UA_Int32 length;
+    UA_Byte *data;
 } UA_String;
 
 /** @brief An instance in time. */
@@ -112,10 +112,10 @@ typedef UA_Int64 UA_DateTime; //100 nanosecond resolution
 
 /** @brief A 16 byte value that can be used as a globally unique identifier. */
 typedef struct UA_Guid {
-	UA_UInt32 data1;
-	UA_UInt16 data2;
-	UA_UInt16 data3;
-	UA_Byte   data4[8];
+    UA_UInt32 data1;
+    UA_UInt16 data2;
+    UA_UInt16 data3;
+    UA_Byte   data4[8];
 } UA_Guid;
 
 /** @brief A sequence of octets. */
@@ -127,26 +127,26 @@ typedef struct UA_String UA_XmlElement;
 /** @brief An identifier for a node in the address space of an OPC UA Server. */
 /* The shortened numeric types are introduced during encoding. */
 typedef struct UA_NodeId {
-	UA_UInt16 namespaceIndex;
-	enum {
-		UA_NODEIDTYPE_NUMERIC = 2,
-		UA_NODEIDTYPE_STRING = 3,
-		UA_NODEIDTYPE_GUID = 4,
-		UA_NODEIDTYPE_BYTESTRING = 5
-	} identifierType;
-	union {
-		UA_UInt32     numeric;
-		UA_String     string;
-		UA_Guid       guid;
-		UA_ByteString byteString;
-	} identifier;
+    UA_UInt16 namespaceIndex;
+    enum {
+        UA_NODEIDTYPE_NUMERIC    = 2,
+        UA_NODEIDTYPE_STRING     = 3,
+        UA_NODEIDTYPE_GUID       = 4,
+        UA_NODEIDTYPE_BYTESTRING = 5
+    } identifierType;
+    union {
+        UA_UInt32     numeric;
+        UA_String     string;
+        UA_Guid       guid;
+        UA_ByteString byteString;
+    } identifier;
 } UA_NodeId;
 
 /** @brief A NodeId that allows the namespace URI to be specified instead of an index. */
 typedef struct UA_ExpandedNodeId {
-	UA_NodeId nodeId;
-	UA_String namespaceUri; // not encoded if length=-1
-	UA_UInt32 serverIndex; // not encoded if 0
+    UA_NodeId nodeId;
+    UA_String namespaceUri; // not encoded if length=-1
+    UA_UInt32 serverIndex;  // not encoded if 0
 } UA_ExpandedNodeId;
 
 /** @brief A numeric identifier for a error or condition that is associated with a value or an operation. */
@@ -154,26 +154,26 @@ typedef UA_UInt32 UA_StatusCode; // StatusCodes aren't an enum(=int) since 32 un
 
 /** @brief A name qualified by a namespace. */
 typedef struct UA_QualifiedName {
-	UA_UInt16 namespaceIndex;
-	UA_String name;
+    UA_UInt16 namespaceIndex;
+    UA_String name;
 } UA_QualifiedName;
 
 /** @brief Human readable text with an optional locale identifier. */
 typedef struct UA_LocalizedText {
-	UA_String locale;
-	UA_String text;
+    UA_String locale;
+    UA_String text;
 } UA_LocalizedText;
 
 /** @brief A structure that contains an application specific data type that may
     not be recognized by the receiver. */
 typedef struct UA_ExtensionObject {
-	UA_NodeId typeId;
-	enum {
-		UA_EXTENSIONOBJECT_ENCODINGMASK_NOBODYISENCODED  = 0,
-		UA_EXTENSIONOBJECT_ENCODINGMASK_BODYISBYTESTRING = 1,
-		UA_EXTENSIONOBJECT_ENCODINGMASK_BODYISXML        = 2
-	} encoding;
-	UA_ByteString body; // contains either the bytestring or a pointer to the memory-object
+    UA_NodeId typeId;
+    enum {
+        UA_EXTENSIONOBJECT_ENCODINGMASK_NOBODYISENCODED  = 0,
+        UA_EXTENSIONOBJECT_ENCODINGMASK_BODYISBYTESTRING = 1,
+        UA_EXTENSIONOBJECT_ENCODINGMASK_BODYISXML        = 2
+    } encoding;
+    UA_ByteString body; // contains either the bytestring or a pointer to the memory-object
 } UA_ExtensionObject;
 
 struct UA_VTable_Entry; // forwards declaration
@@ -184,60 +184,60 @@ typedef struct UA_VTable_Entry UA_VTable_Entry;
  * Variants store (arrays of) built-in types. If you want to store a more
  * complex (or self-defined) type, you have to use an UA_ExtensionObject.*/
 typedef struct UA_Variant {
-	UA_VTable_Entry *vt;          // internal entry into vTable
-	UA_Int32  arrayLength;        // total number of elements
-	void     *data;
-	UA_Int32  arrayDimensionsLength;
-	UA_Int32 *arrayDimensions;
+    UA_VTable_Entry *vt;          // internal entry into vTable
+    UA_Int32  arrayLength;        // total number of elements
+    void     *data;
+    UA_Int32  arrayDimensionsLength;
+    UA_Int32 *arrayDimensions;
 } UA_Variant;
 
 /* VariantBinaryEncoding - Part: 6, Chapter: 5.2.2.16, Page: 22 */
 enum UA_VARIANT_ENCODINGMASKTYPE_enum {
-	UA_VARIANT_ENCODINGMASKTYPE_TYPEID_MASK = 0x3F,            // bits 0:5
-	UA_VARIANT_ENCODINGMASKTYPE_DIMENSIONS  = (0x01 << 6),     // bit 6
-	UA_VARIANT_ENCODINGMASKTYPE_ARRAY       = (0x01 << 7)      // bit 7
+    UA_VARIANT_ENCODINGMASKTYPE_TYPEID_MASK = 0x3F,            // bits 0:5
+    UA_VARIANT_ENCODINGMASKTYPE_DIMENSIONS  = (0x01 << 6),     // bit 6
+    UA_VARIANT_ENCODINGMASKTYPE_ARRAY       = (0x01 << 7)      // bit 7
 };
 
 /** @brief A data value with an associated status code and timestamps. */
 typedef struct UA_DataValue {
-	UA_Byte       encodingMask;
-	UA_Variant    value;
-	UA_StatusCode status;
-	UA_DateTime   sourceTimestamp;
-	UA_Int16      sourcePicoseconds;
-	UA_DateTime   serverTimestamp;
-	UA_Int16      serverPicoseconds;
+    UA_Byte       encodingMask;
+    UA_Variant    value;
+    UA_StatusCode status;
+    UA_DateTime   sourceTimestamp;
+    UA_Int16      sourcePicoseconds;
+    UA_DateTime   serverTimestamp;
+    UA_Int16      serverPicoseconds;
 } UA_DataValue;
 
 enum UA_DATAVALUE_ENCODINGMASKTYPE_enum {
-	UA_DATAVALUE_ENCODINGMASK_VARIANT           = 0x01,
-	UA_DATAVALUE_ENCODINGMASK_STATUSCODE        = 0x02,
-	UA_DATAVALUE_ENCODINGMASK_SOURCETIMESTAMP   = 0x04,
-	UA_DATAVALUE_ENCODINGMASK_SERVERTIMESTAMP   = 0x08,
-	UA_DATAVALUE_ENCODINGMASK_SOURCEPICOSECONDS = 0x10,
-	UA_DATAVALUE_ENCODINGMASK_SERVERPICOSECONDS = 0x20
+    UA_DATAVALUE_ENCODINGMASK_VARIANT           = 0x01,
+    UA_DATAVALUE_ENCODINGMASK_STATUSCODE        = 0x02,
+    UA_DATAVALUE_ENCODINGMASK_SOURCETIMESTAMP   = 0x04,
+    UA_DATAVALUE_ENCODINGMASK_SERVERTIMESTAMP   = 0x08,
+    UA_DATAVALUE_ENCODINGMASK_SOURCEPICOSECONDS = 0x10,
+    UA_DATAVALUE_ENCODINGMASK_SERVERPICOSECONDS = 0x20
 };
 
 /** @brief A structure that contains detailed error and diagnostic information associated with a StatusCode. */
 typedef struct UA_DiagnosticInfo {
-	UA_Byte       encodingMask;     // Type of the Enum UA_DIAGNOSTICINFO_ENCODINGMASKTYPE
-	UA_Int32      symbolicId;
-	UA_Int32      namespaceUri;
-	UA_Int32      localizedText;
-	UA_Int32      locale;
-	UA_String     additionalInfo;
-	UA_StatusCode innerStatusCode;
-	struct UA_DiagnosticInfo *innerDiagnosticInfo;
+    UA_Byte       encodingMask;     // Type of the Enum UA_DIAGNOSTICINFO_ENCODINGMASKTYPE
+    UA_Int32      symbolicId;
+    UA_Int32      namespaceUri;
+    UA_Int32      localizedText;
+    UA_Int32      locale;
+    UA_String     additionalInfo;
+    UA_StatusCode innerStatusCode;
+    struct UA_DiagnosticInfo *innerDiagnosticInfo;
 } UA_DiagnosticInfo;
 
 enum UA_DIAGNOSTICINFO_ENCODINGMASKTYPE_enum {
-	UA_DIAGNOSTICINFO_ENCODINGMASK_SYMBOLICID          = 0x01,
-	UA_DIAGNOSTICINFO_ENCODINGMASK_NAMESPACE           = 0x02,
-	UA_DIAGNOSTICINFO_ENCODINGMASK_LOCALIZEDTEXT       = 0x04,
-	UA_DIAGNOSTICINFO_ENCODINGMASK_LOCALE              = 0x08,
-	UA_DIAGNOSTICINFO_ENCODINGMASK_ADDITIONALINFO      = 0x10,
-	UA_DIAGNOSTICINFO_ENCODINGMASK_INNERSTATUSCODE     = 0x20,
-	UA_DIAGNOSTICINFO_ENCODINGMASK_INNERDIAGNOSTICINFO = 0x40
+    UA_DIAGNOSTICINFO_ENCODINGMASK_SYMBOLICID          = 0x01,
+    UA_DIAGNOSTICINFO_ENCODINGMASK_NAMESPACE           = 0x02,
+    UA_DIAGNOSTICINFO_ENCODINGMASK_LOCALIZEDTEXT       = 0x04,
+    UA_DIAGNOSTICINFO_ENCODINGMASK_LOCALE              = 0x08,
+    UA_DIAGNOSTICINFO_ENCODINGMASK_ADDITIONALINFO      = 0x10,
+    UA_DIAGNOSTICINFO_ENCODINGMASK_INNERSTATUSCODE     = 0x20,
+    UA_DIAGNOSTICINFO_ENCODINGMASK_INNERDIAGNOSTICINFO = 0x40
 };
 
 /** @brief Type use internally to denote an invalid datatype. */
@@ -248,13 +248,13 @@ typedef void UA_InvalidType;
 /*************/
 
 #ifdef DEBUG
-#define UA_TYPE_PROTOTYPES(TYPE)             \
-    UA_Int32 TYPE##_new(TYPE **p);           \
-    UA_Int32 TYPE##_init(TYPE * p);          \
-    UA_Int32 TYPE##_delete(TYPE * p);        \
-    UA_Int32 TYPE##_deleteMembers(TYPE * p); \
+#define UA_TYPE_PROTOTYPES(TYPE)                      \
+    UA_Int32 TYPE##_new(TYPE **p);                    \
+    UA_Int32 TYPE##_init(TYPE * p);                   \
+    UA_Int32 TYPE##_delete(TYPE * p);                 \
+    UA_Int32 TYPE##_deleteMembers(TYPE * p);          \
     UA_Int32 TYPE##_copy(const TYPE *src, TYPE *dst); \
-	void TYPE##_print(const TYPE *p, FILE *stream);
+    void     TYPE##_print(const TYPE *p, FILE *stream);
 #else
 #define UA_TYPE_PROTOTYPES(TYPE)             \
     UA_Int32 TYPE##_new(TYPE **p);           \
@@ -293,10 +293,10 @@ UA_TYPE_PROTOTYPES(UA_DiagnosticInfo)
 UA_TYPE_PROTOTYPES(UA_InvalidType)
 
 /* String */
-#define UA_STRING_NULL (UA_String){-1, UA_NULL}
+#define UA_STRING_NULL (UA_String) {-1, UA_NULL }
 #define UA_STRING_STATIC(VARIABLE, STRING) do { \
-	VARIABLE.length = sizeof(STRING)-1; \
-	VARIABLE.data = (UA_Byte*)STRING; } while (0)
+        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, ...);
@@ -310,15 +310,15 @@ void UA_String_printx_hex(char const *label, const UA_String *string);
 /* DateTime */
 UA_DateTime UA_DateTime_now();
 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 mounth;
-	UA_Int16 year;
+    UA_Int16 nanoSec;
+    UA_Int16 microSec;
+    UA_Int16 milliSec;
+    UA_Int16 sec;
+    UA_Int16 min;
+    UA_Int16 hour;
+    UA_Int16 day;
+    UA_Int16 mounth;
+    UA_Int16 year;
 } UA_DateTimeStruct;
 UA_DateTimeStruct UA_DateTime_toStruct(UA_DateTime time);
 UA_Int32 UA_DateTime_toString(UA_DateTime time, UA_String *timeString);
@@ -340,29 +340,30 @@ UA_Int32 UA_NodeId_equal(const UA_NodeId *n1, const UA_NodeId *n2);
 UA_Boolean UA_NodeId_isNull(const UA_NodeId *p);
 UA_Boolean UA_NodeId_isBasicType(UA_NodeId const *id);
 
-#define NS0NODEID(NUMERIC_ID) \
-	(UA_NodeId){ .namespaceIndex = 0, .identifierType = UA_NODEIDTYPE_NUMERIC, .identifier.numeric = NUMERIC_ID }
+#define NS0NODEID(NUMERIC_ID)                                                                        \
+    (UA_NodeId) {.namespaceIndex = 0, .identifierType = UA_NODEIDTYPE_NUMERIC, .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)
+#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(VARIABLE, STRING) do { \
-	VARIABLE.namespaceIndex = 0; \
-	UA_STRING_STATIC(VARIABLE.name, STRING); } while (0)
+        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(VARIABLE, STRING) do { \
-	UA_STRING_STATIC(VARIABLE.locale, "en"); \
-	UA_STRING_STATIC(VARIABLE.text, STRING); } while (0)
+        UA_STRING_STATIC(VARIABLE.locale, "en");       \
+        UA_STRING_STATIC(VARIABLE.text, STRING); } while(0)
 
 UA_Int32 UA_LocalizedText_copycstring(char const *src, UA_LocalizedText *dst);
 
@@ -394,38 +395,38 @@ void UA_Array_print(const void *p, UA_Int32 noElements, UA_VTable_Entry *vt, FIL
 /**********/
 
 typedef struct UA_Encoding {
-	/**  Returns the size of the encoded element.*/
-	UA_Int32 (*calcSize)(const void *p);
-	/** Encodes the type into the destination bytestring. */
-	UA_Int32 (*encode)(const void *src, UA_ByteString *dst, UA_UInt32 *offset);
-	/** Decodes a ByteString into an UA datatype. */
-	UA_Int32 (*decode)(const UA_ByteString *src, UA_UInt32 *offset, void *dst);
+    /**  Returns the size of the encoded element.*/
+    UA_Int32 (*calcSize)(const void *p);
+    /** Encodes the type into the destination bytestring. */
+    UA_Int32 (*encode)(const void *src, UA_ByteString *dst, UA_UInt32 *offset);
+    /** Decodes a ByteString into an UA datatype. */
+    UA_Int32 (*decode)(const UA_ByteString *src, UA_UInt32 *offset, void *dst);
 } UA_Encoding;
 
 #define UA_ENCODING_BINARY 0 // Binary encoding is always available
 
 struct UA_VTable_Entry {
-	UA_NodeId  typeId;
-	UA_Byte   *name;
-	UA_Int32   (*new)(void **p);
-	UA_Int32   (*init)(void *p);
-	UA_Int32   (*copy)(void const *src, void *dst);
-	UA_Int32   (*delete)(void *p);
-	UA_Int32   (*deleteMembers)(void *p);
+    UA_NodeId  typeId;
+    UA_Byte   *name;
+    UA_Int32   (*new)(void **p);
+    UA_Int32   (*init)(void *p);
+    UA_Int32   (*copy)(void const *src, void *dst);
+    UA_Int32   (*delete)(void *p);
+    UA_Int32   (*deleteMembers)(void *p);
 #ifdef DEBUG
-	void       (*print)(const void *p, FILE *stream);
+    void       (*print)(const void *p, FILE *stream);
 #endif
-	UA_UInt32  memSize;       // size of the struct only in memory (no dynamic components)
-	UA_Boolean dynMembers;    // does the type contain members that are dynamically
-	                          // allocated (strings, ..)? Otherwise, the size on
-	                          // the wire == size in memory.
-	UA_Encoding encodings[UA_ENCODING_AMOUNT]; // binary, xml, ... UA_ENCODING_AMOUNT is set by the build script
+    UA_UInt32  memSize;                        // size of the struct only in memory (no dynamic components)
+    UA_Boolean dynMembers;                     // does the type contain members that are dynamically
+                                               // allocated (strings, ..)? Otherwise, the size on
+                                               // the wire == size in memory.
+    UA_Encoding encodings[UA_ENCODING_AMOUNT]; // binary, xml, ... UA_ENCODING_AMOUNT is set by the build script
 };
 
 typedef UA_Int32 (*UA_nodeIdToVTableIndex)(const UA_NodeId *id);
 typedef struct UA_VTable {
-	UA_nodeIdToVTableIndex getTypeIndex;
-	UA_VTable_Entry       *types;
+    UA_nodeIdToVTableIndex getTypeIndex;
+    UA_VTable_Entry       *types;
 } UA_VTable;
 
 /***********************************/
@@ -441,31 +442,31 @@ typedef struct UA_VTable {
 
 #define UA_TYPE_NEW_DEFAULT(TYPE)                     \
     UA_Int32 TYPE##_new(TYPE **p) {                   \
-		UA_Int32 retval = UA_SUCCESS;                 \
-		retval |= UA_alloc((void **)p, sizeof(TYPE)); \
-		retval |= TYPE##_init(*p);                    \
-		return retval;                                \
-	}
+        UA_Int32 retval = UA_SUCCESS;                 \
+        retval |= UA_alloc((void **)p, sizeof(TYPE)); \
+        retval |= TYPE##_init(*p);                    \
+        return retval;                                \
+    }
 
 #define UA_TYPE_INIT_DEFAULT(TYPE)         \
     UA_Int32 TYPE##_init(TYPE * p) {       \
-		if(p == UA_NULL) return UA_ERROR;  \
-		*p = (TYPE)0;                      \
-		return UA_SUCCESS;                 \
-	}
+        if(p == UA_NULL) return UA_ERROR;  \
+        *p = (TYPE)0;                      \
+        return UA_SUCCESS;                 \
+    }
 
 #define UA_TYPE_INIT_AS(TYPE, TYPE_AS)       \
     UA_Int32 TYPE##_init(TYPE * p) {         \
-		return TYPE_AS##_init((TYPE_AS *)p); \
-	}
+        return TYPE_AS##_init((TYPE_AS *)p); \
+    }
 
 #define UA_TYPE_DELETE_DEFAULT(TYPE)       \
     UA_Int32 TYPE##_delete(TYPE *p) {      \
-		UA_Int32 retval = UA_SUCCESS;      \
-		retval |= TYPE##_deleteMembers(p); \
-		retval |= UA_free(p);              \
-		return retval;                     \
-	}
+        UA_Int32 retval = UA_SUCCESS;      \
+        retval |= TYPE##_deleteMembers(p); \
+        retval |= UA_free(p);              \
+        return retval;                     \
+    }
 
 #define UA_TYPE_DELETE_AS(TYPE, TYPE_AS) \
     UA_Int32 TYPE##_delete(TYPE * p) { return TYPE_AS##_delete((TYPE_AS *)p); }
@@ -479,21 +480,21 @@ typedef struct UA_VTable {
 /* Use only when the type has no arrays. Otherwise, implement deep copy */
 #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;    }                                     \
-	}
+        if(src == UA_NULL || dst == UA_NULL) return UA_ERROR;  \
+        { UA_Int32 retval = UA_SUCCESS;                        \
+          retval |= UA_memcpy(dst, src, sizeof(TYPE));         \
+          return retval;    }                                  \
+    }
 
 #define UA_TYPE_COPY_AS(TYPE, TYPE_AS)                         \
     UA_Int32 TYPE##_copy(TYPE const *src, TYPE *dst) {         \
-		return TYPE_AS##_copy((TYPE_AS *)src, (TYPE_AS *)dst); \
-	}
+        return TYPE_AS##_copy((TYPE_AS *)src, (TYPE_AS *)dst); \
+    }
 
-#define UA_TYPE_PRINT_AS(TYPE, TYPE_AS)                        \
-    void TYPE##_print(TYPE const *p, FILE *stream) {		   \
-		TYPE_AS##_print((TYPE_AS *)p, stream);				   \
-	}														   \
+#define UA_TYPE_PRINT_AS(TYPE, TYPE_AS)              \
+    void TYPE##_print(TYPE const *p, FILE *stream) { \
+        TYPE_AS##_print((TYPE_AS *)p, stream);       \
+    }                                                \
 
 #ifdef DEBUG //print functions only in debug mode
 #define UA_TYPE_AS(TYPE, TYPE_AS)           \
@@ -501,8 +502,8 @@ typedef struct UA_VTable {
     UA_TYPE_INIT_AS(TYPE, TYPE_AS)          \
     UA_TYPE_DELETE_AS(TYPE, TYPE_AS)        \
     UA_TYPE_DELETEMEMBERS_AS(TYPE, TYPE_AS) \
-    UA_TYPE_COPY_AS(TYPE, TYPE_AS)			\
-	UA_TYPE_PRINT_AS(TYPE, TYPE_AS)
+    UA_TYPE_COPY_AS(TYPE, TYPE_AS)          \
+    UA_TYPE_PRINT_AS(TYPE, TYPE_AS)
 #else
 #define UA_TYPE_AS(TYPE, TYPE_AS)           \
     UA_TYPE_NEW_DEFAULT(TYPE)               \

File diff suppressed because it is too large
+ 750 - 715
src/ua_types_encoding_binary.c


+ 16 - 13
src/ua_types_encoding_binary.h

@@ -35,26 +35,26 @@
 /* Stop decoding at the first failure. Free members that were already allocated.
    It is assumed that retval is already defined. */
 #define CHECKED_DECODE(DECODE, CLEAN_UP) do { \
-		retval |= DECODE;                     \
-		if(retval != UA_SUCCESS) {            \
-			CLEAN_UP;                         \
-			return retval;                    \
-		} } while(0)
+        retval |= DECODE;                     \
+        if(retval != UA_SUCCESS) {            \
+            CLEAN_UP;                         \
+            return retval;                    \
+        } } while(0)
 
 #define UA_TYPE_CALCSIZEBINARY_AS(TYPE, TYPE_AS)       \
     UA_Int32 TYPE##_calcSizeBinary(TYPE const *p) {    \
-		return TYPE_AS##_calcSizeBinary((TYPE_AS *)p); \
-	}
+        return TYPE_AS##_calcSizeBinary((TYPE_AS *)p); \
+    }
 
 #define UA_TYPE_ENCODEBINARY_AS(TYPE, TYPE_AS)                                             \
     UA_Int32 TYPE##_encodeBinary(TYPE const *src, UA_ByteString *dst, UA_UInt32 *offset) { \
-		return TYPE_AS##_encodeBinary((TYPE_AS *)src, dst, offset);                        \
-	}
+        return TYPE_AS##_encodeBinary((TYPE_AS *)src, dst, offset);                        \
+    }
 
 #define UA_TYPE_DECODEBINARY_AS(TYPE, TYPE_AS)                                             \
     UA_Int32 TYPE##_decodeBinary(UA_ByteString const *src, UA_UInt32 *offset, TYPE *dst) { \
-		return TYPE_AS##_decodeBinary(src, offset, (TYPE_AS *)dst);                        \
-	}
+        return TYPE_AS##_decodeBinary(src, offset, (TYPE_AS *)dst);                        \
+    }
 #define UA_TYPE_BINARY_ENCODING_AS(TYPE, TYPE_AS) \
     UA_TYPE_CALCSIZEBINARY_AS(TYPE, TYPE_AS)      \
     UA_TYPE_ENCODEBINARY_AS(TYPE, TYPE_AS)        \
@@ -102,10 +102,13 @@ UA_TYPE_BINARY_ENCODING(UA_InvalidType)
 UA_Int32 UA_Array_calcSizeBinary(UA_Int32 nElements, UA_VTable_Entry *vt, const void *data);
 
 /* @brief Encodes an array into a binary blob. The array size is printed as well. */
-UA_Int32 UA_Array_encodeBinary(const void *src, UA_Int32 noElements, UA_VTable_Entry *vt, UA_ByteString *dst, UA_UInt32 *offset);
+UA_Int32 UA_Array_encodeBinary(const void *src, UA_Int32 noElements, UA_VTable_Entry *vt, UA_ByteString *dst,
+                               UA_UInt32 *offset);
 
 /* @brief Decodes an array from a binary blob. The array is allocated automatically before decoding. */
-UA_Int32 UA_Array_decodeBinary(const UA_ByteString *src, UA_UInt32 * offset, UA_Int32 noElements, UA_VTable_Entry *vt, void **dst);
+UA_Int32 UA_Array_decodeBinary(const UA_ByteString *src, UA_UInt32 *offset, UA_Int32 noElements,
+                               UA_VTable_Entry *vt,
+                               void **dst);
 
 /// @} /* end of group */
 

+ 113 - 117
src/util/ua_base64.c

@@ -1,153 +1,149 @@
 /*
-begin library headers
-*/
+   begin library headers
+ */
 
 /*
-cdecode.h - c header for a base64 decoding algorithm
+   cdecode.h - c header for a base64 decoding algorithm
 
-This is part of the libb64 project, and has been placed in the public domain.
-For details, see http://sourceforge.net/projects/libb64
-*/
+   This is part of the libb64 project, and has been placed in the public domain.
+   For details, see http://sourceforge.net/projects/libb64
+ */
 #ifndef BASE64_CDECODE_H
 #define BASE64_CDECODE_H
 
-typedef enum
-{
-	step_a, step_b, step_c, step_d
+typedef enum {
+    step_a, step_b, step_c, step_d
 } base64_decodestep;
 
-typedef struct
-{
-	base64_decodestep step;
-	char plainchar;
+typedef struct {
+    base64_decodestep step;
+    char plainchar;
 } base64_decodestate;
 
-void base64_init_decodestate(base64_decodestate* state_in);
+void base64_init_decodestate(base64_decodestate *state_in);
 
 int base64_decode_value(char value_in);
 
-int base64_decode_block(const char* code_in, const int length_in, char* plaintext_out, base64_decodestate* state_in);
+int base64_decode_block(const char *code_in, const int length_in, char *plaintext_out,
+                        base64_decodestate *state_in);
 
 #endif /* BASE64_CDECODE_H */
 
 /*
-end library headers
-*/
+   end library headers
+ */
 
 #include "ua_base64.h"
 
-UA_Int32 UA_base64_getDecodedSize(UA_String* const base64EncodedData){
-	//note that base64-encoded data length is always divisible by 4
-	UA_Int32 temp = base64EncodedData->length * 3 / 4;
+UA_Int32 UA_base64_getDecodedSize(UA_String *const base64EncodedData) {
+    //note that base64-encoded data length is always divisible by 4
+    UA_Int32 temp = base64EncodedData->length * 3 / 4;
 
-	//subtract padding
-	if(base64EncodedData->data[base64EncodedData->length-1] == '=') {
-		temp--;
-		if(base64EncodedData->data[base64EncodedData->length-2] == '=') {
-			temp--;
-		}
-	}
+    //subtract padding
+    if(base64EncodedData->data[base64EncodedData->length-1] == '=') {
+        temp--;
+        if(base64EncodedData->data[base64EncodedData->length-2] == '=')
+            temp--;
+    }
 
-	return temp;
+    return temp;
 }
 
-UA_Int32 UA_base64_decode(UA_String* const base64EncodedData, UA_Byte* target){
-	if(target == UA_NULL){
-		return UA_ERROR;
-	}
-	base64_decodestate state;
-	base64_init_decodestate(&state);
-	base64_decode_block((char*)(base64EncodedData->data), base64EncodedData->length, (char*)target, &state);
-	return UA_NO_ERROR;
+UA_Int32 UA_base64_decode(UA_String *const base64EncodedData, UA_Byte *target) {
+    if(target == UA_NULL)
+        return UA_ERROR;
+    base64_decodestate state;
+    base64_init_decodestate(&state);
+    base64_decode_block((char *)(base64EncodedData->data), base64EncodedData->length, (char *)target, &state);
+    return UA_NO_ERROR;
 }
 
 /*
-begin library code
-*/
+   begin library code
+ */
 
 /*
-cdecoder.c - c source to a base64 decoding algorithm implementation
-
-This is part of the libb64 project, and has been placed in the public domain.
-For details, see http://sourceforge.net/projects/libb64
-*/
-
-int base64_decode_value(char value_in)
-{
-	static const char decoding[] = {62,-1,-1,-1,63,52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-2,-1,-1,-1,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1,-1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51};
-	static const char decoding_size = sizeof(decoding);
-	value_in -= 43;
-	if (value_in > decoding_size) return -1;
-	return decoding[(int)value_in];
+   cdecoder.c - c source to a base64 decoding algorithm implementation
+
+   This is part of the libb64 project, and has been placed in the public domain.
+   For details, see http://sourceforge.net/projects/libb64
+ */
+
+int base64_decode_value(char value_in) {
+    static const char decoding[]    =
+    { 62, -1,   -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -2, -1, -1, -1, 0,  1,  2,  3,
+      4,  5,
+      6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, -1, 26,
+      27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51 };
+    static const char decoding_size = sizeof(decoding);
+    value_in -= 43;
+    if(value_in > decoding_size) return -1;
+    return decoding[(int)value_in];
 }
 
-void base64_init_decodestate(base64_decodestate* state_in)
-{
-	state_in->step = step_a;
-	state_in->plainchar = 0;
+void base64_init_decodestate(base64_decodestate *state_in) {
+    state_in->step      = step_a;
+    state_in->plainchar = 0;
 }
 
-int base64_decode_block(const char* code_in, const int length_in, char* plaintext_out, base64_decodestate* state_in)
-{
-	const char* codechar = code_in;
-	char* plainchar = plaintext_out;
-	signed char fragment;
-	
-	*plainchar = state_in->plainchar;
-	
-	switch (state_in->step)
-	{
-		while (1)
-		{
-	case step_a:
-			do {
-				if (codechar == code_in+length_in)
-				{
-					state_in->step = step_a;
-					state_in->plainchar = *plainchar;
-					return plainchar - plaintext_out;
-				}
-				fragment = (char)base64_decode_value(*codechar++);
-			} while (fragment < 0);
-			*plainchar    = (fragment & 0x03f) << 2;
-	case step_b:
-			do {
-				if (codechar == code_in+length_in)
-				{
-					state_in->step = step_b;
-					state_in->plainchar = *plainchar;
-					return plainchar - plaintext_out;
-				}
-				fragment = (char)base64_decode_value(*codechar++);
-			} while (fragment < 0);
-			*plainchar++ |= (fragment & 0x030) >> 4;
-			*plainchar    = (fragment & 0x00f) << 4;
-	case step_c:
-			do {
-				if (codechar == code_in+length_in)
-				{
-					state_in->step = step_c;
-					state_in->plainchar = *plainchar;
-					return plainchar - plaintext_out;
-				}
-				fragment = (char)base64_decode_value(*codechar++);
-			} while (fragment < 0);
-			*plainchar++ |= (fragment & 0x03c) >> 2;
-			*plainchar    = (fragment & 0x003) << 6;
-	case step_d:
-			do {
-				if (codechar == code_in+length_in)
-				{
-					state_in->step = step_d;
-					state_in->plainchar = *plainchar;
-					return plainchar - plaintext_out;
-				}
-				fragment = (char)base64_decode_value(*codechar++);
-			} while (fragment < 0);
-			*plainchar++   |= (fragment & 0x03f);
-		}
-	}
-	/* control should not reach here */
-	return plainchar - plaintext_out;
+int base64_decode_block(const char *code_in, const int length_in, char *plaintext_out,
+                        base64_decodestate *state_in) {
+    const char *codechar  = code_in;
+    char       *plainchar = plaintext_out;
+    signed char fragment;
+
+    *plainchar = state_in->plainchar;
+
+    switch(state_in->step) {
+        while(1) {
+        case step_a:
+            do {
+                if(codechar == code_in+length_in) {
+                    state_in->step      = step_a;
+                    state_in->plainchar = *plainchar;
+                    return plainchar - plaintext_out;
+                }
+                fragment = (char)base64_decode_value(*codechar++);
+            } while(fragment < 0);
+            *plainchar = (fragment & 0x03f) << 2;
+
+        case step_b:
+            do {
+                if(codechar == code_in+length_in) {
+                    state_in->step      = step_b;
+                    state_in->plainchar = *plainchar;
+                    return plainchar - plaintext_out;
+                }
+                fragment = (char)base64_decode_value(*codechar++);
+            } while(fragment < 0);
+            *plainchar++ |= (fragment & 0x030) >> 4;
+            *plainchar    = (fragment & 0x00f) << 4;
+
+        case step_c:
+            do {
+                if(codechar == code_in+length_in) {
+                    state_in->step      = step_c;
+                    state_in->plainchar = *plainchar;
+                    return plainchar - plaintext_out;
+                }
+                fragment = (char)base64_decode_value(*codechar++);
+            } while(fragment < 0);
+            *plainchar++ |= (fragment & 0x03c) >> 2;
+            *plainchar    = (fragment & 0x003) << 6;
+
+        case step_d:
+            do {
+                if(codechar == code_in+length_in) {
+                    state_in->step      = step_d;
+                    state_in->plainchar = *plainchar;
+                    return plainchar - plaintext_out;
+                }
+                fragment = (char)base64_decode_value(*codechar++);
+            } while(fragment < 0);
+            *plainchar++ |= (fragment & 0x03f);
+        }
+    }
+    /* control should not reach here */
+    return plainchar - plaintext_out;
 }
 

+ 2 - 2
src/util/ua_base64.h

@@ -12,9 +12,9 @@
 #include "ua_util.h"
 
 /** @brief calculates the exact size for the binary data that is encoded in base64 encoded string */
-UA_Int32 UA_base64_getDecodedSize(UA_String* const base64EncodedData);
+UA_Int32 UA_base64_getDecodedSize(UA_String *const base64EncodedData);
 
 /** @brief decodes base64 encoded string into target, target should be at least of the size returned by UA_base64_getDecodedSizeUB */
-UA_Int32 UA_base64_decode(UA_String* const base64EncodedData, UA_Byte* target);
+UA_Int32 UA_base64_decode(UA_String *const base64EncodedData, UA_Byte *target);
 
 #endif /* UA_BASE64_H_ */

+ 228 - 245
src/util/ua_list.c

@@ -1,253 +1,236 @@
 #include "ua_list.h"
 #include "ua_util.h"
 
-void UA_list_defaultFreer(void* payload){
-	if(payload){
-		UA_free(payload);
-	}
-}
-
-UA_Int32 UA_list_initElement(UA_list_Element* element){
-	if(element==UA_NULL) return UA_ERROR;
-	element->next=UA_NULL;
-	element->prev=UA_NULL;
-	element->father=UA_NULL;
-	element->payload=UA_NULL;
-	return UA_NO_ERROR;
-}
-
-UA_Int32 UA_list_init(UA_list_List* list){
-	if(list==UA_NULL) return UA_ERROR;
-	list->first = UA_NULL;
-	list->last = UA_NULL;
-	list->size = 0;
-	return UA_NO_ERROR;
-}
-
-UA_Int32 UA_list_addElementToFront(UA_list_List* list, UA_list_Element* element){
-	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;
-	element->next = second;
-	element->father = list;
-	if(second){
-		second->prev=element;
-	}
-	list->size++;
-	if(list->size==1){
-		list->last=element;
-	}
-	return UA_NO_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;
-	UA_list_addElementToFront(list, elem);
-	return UA_NO_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;
-	element->next = UA_NULL;
-	element->father = list;
-	if(secondLast){
-		secondLast->next = element;
-	}
-	list->size++;
-	if(list->size==1){
-		list->first=element;
-	}
-	return UA_NO_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;
-	UA_list_addElementToBack(list, elem);
-	return UA_NO_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){
-			(*visitor)(list->first->payload);
-		}
-		UA_free(list->first);
-		list->first = temp;
-		if(temp){
-			temp->prev = UA_NULL;
-		}
-		list->size--;
-		if(list->size == 1){
-			list->last = temp;
-		}else if(list->size==0){
-			list->last = UA_NULL;
-		}
-	}
-	return UA_NO_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){
-			(*visitor)(list->last->payload);
-		}
-		UA_free(list->last);
-		list->last = temp;
-		if(temp){
-			temp->next = UA_NULL;
-		}
-		list->size--;
-		if(list->size == 1){
-			list->first = temp;
-		}else if(list->size==0){
-			list->first = UA_NULL;
-		}
-	}
-	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;
-	if(elem==elem->father->first){
-		return UA_list_removeFirst(elem->father, visitor);
-	}else if(elem==elem->father->last){
-		return UA_list_removeLast(elem->father, visitor);
-	}else{
-		UA_list_Element* prev = elem->prev;
-		UA_list_Element* next = elem->next;
-		prev->next = next;
-		next->prev = prev;
-		if(visitor){
-			(*visitor)(elem->payload);
-		}
-		(elem->father)->size--;
-		UA_free(elem);
-	}
-	return UA_NO_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;
-		if(visitor){
-			(*visitor)(current->payload);
-		}
-		UA_free(current);
-		current = next;
-	}
-	UA_list_init(list);
-	return UA_NO_ERROR;
-}
-
-UA_Int32 UA_list_iterateElement(UA_list_List* const list, UA_list_ElementVisitor visitor) {
-	UA_list_Element* current;
-	UA_list_Element* next = UA_NULL;
-	if(list==UA_NULL)
-		return UA_ERROR;
-	current = list->first;
-	while(current){
-		next=current->next;
-		if(visitor){
-			(*visitor)(current);
-		}
-		current = next;
-	}
-	return UA_NO_ERROR;
+void UA_list_defaultFreer(void *payload) {
+    if(payload)
+        UA_free(payload);
+}
+
+UA_Int32 UA_list_initElement(UA_list_Element *element) {
+    if(element == UA_NULL) return UA_ERROR;
+    element->next    = UA_NULL;
+    element->prev    = UA_NULL;
+    element->father  = UA_NULL;
+    element->payload = UA_NULL;
+    return UA_NO_ERROR;
+}
+
+UA_Int32 UA_list_init(UA_list_List *list) {
+    if(list == UA_NULL) return UA_ERROR;
+    list->first = UA_NULL;
+    list->last  = UA_NULL;
+    list->size  = 0;
+    return UA_NO_ERROR;
+}
+
+UA_Int32 UA_list_addElementToFront(UA_list_List *list, UA_list_Element *element) {
+    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;
+    element->next   = second;
+    element->father = list;
+    if(second)
+        second->prev = element;
+    list->size++;
+    if(list->size == 1)
+        list->last = element;
+    return UA_NO_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;
+    UA_list_addElementToFront(list, elem);
+    return UA_NO_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;
+    element->next   = UA_NULL;
+    element->father = list;
+    if(secondLast)
+        secondLast->next = element;
+    list->size++;
+    if(list->size == 1)
+        list->first = element;
+    return UA_NO_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;
+    UA_list_addElementToBack(list, elem);
+    return UA_NO_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)
+            (*visitor)(list->first->payload);
+        UA_free(list->first);
+        list->first = temp;
+        if(temp)
+            temp->prev = UA_NULL;
+        list->size--;
+        if(list->size == 1)
+            list->last = temp;
+        else if(list->size == 0)
+            list->last = UA_NULL;
+    }
+    return UA_NO_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)
+            (*visitor)(list->last->payload);
+        UA_free(list->last);
+        list->last = temp;
+        if(temp)
+            temp->next = UA_NULL;
+        list->size--;
+        if(list->size == 1)
+            list->first = temp;
+        else if(list->size == 0)
+            list->first = UA_NULL;
+    }
+    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;
+    if(elem == elem->father->first)
+        return UA_list_removeFirst(elem->father, visitor);
+    else if(elem == elem->father->last)
+        return UA_list_removeLast(elem->father, visitor);
+    else{
+        UA_list_Element *prev = elem->prev;
+        UA_list_Element *next = elem->next;
+        prev->next = next;
+        next->prev = prev;
+        if(visitor)
+            (*visitor)(elem->payload);
+        (elem->father)->size--;
+        UA_free(elem);
+    }
+    return UA_NO_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;
+        if(visitor)
+            (*visitor)(current->payload);
+        UA_free(current);
+        current = next;
+    }
+    UA_list_init(list);
+    return UA_NO_ERROR;
+}
+
+UA_Int32 UA_list_iterateElement(UA_list_List *const list, UA_list_ElementVisitor visitor) {
+    UA_list_Element *current;
+    UA_list_Element *next = UA_NULL;
+    if(list == UA_NULL)
+        return UA_ERROR;
+    current = list->first;
+    while(current) {
+        next = current->next;
+        if(visitor)
+            (*visitor)(current);
+        current = next;
+    }
+    return UA_NO_ERROR;
 }
 
 /*Int32 UA_list_iteratePayload(UA_list_list* const list, UA_payloadVisitor visitor){
-	void visitorTemp(UA_list_element* element){
-		if(visitor){
-			(*visitor)(element->payload);
-		}
-	}
-	if(list==NULL)return UA_ERROR;
-	UA_list_iterateElement(list, visitorTemp);
-	return UA_NO_ERROR;
-}*/
+    void visitorTemp(UA_list_element* element){
+        if(visitor){
+            (*visitor)(element->payload);
+        }
+    }
+    if(list==NULL)return UA_ERROR;
+    UA_list_iterateElement(list, visitorTemp);
+    return UA_NO_ERROR;
+   }*/
 /** ANSI C forbids function nesting - reworked ugly version **/
-UA_Int32 UA_list_iteratePayload(UA_list_List* const list, UA_list_PayloadVisitor visitor){
-	UA_list_Element* current;
-	UA_list_Element* next = UA_NULL;
-	if(list==UA_NULL)
-		return UA_ERROR;
-	current = list->first;
-	while(current){
-		next = current->next;
-		if(visitor){
-			(*visitor)(current->payload);
-		}
-		current = next;
-	}
-	return UA_NO_ERROR;
-}
-
-UA_list_Element* UA_list_find(UA_list_List* const list, UA_list_PayloadMatcher matcher){
-	if(list==UA_NULL)return UA_NULL;
-	if(matcher){
-		UA_list_Element* current = list->first;
-		while(current){
-			if(matcher && (*matcher)(current->payload)==TRUE){
-				return current;
-			}
-			current=current->next;
-		}
-	}
-	/* nothing found */
-	return UA_NULL;
-}
-
-UA_list_Element* UA_list_search(UA_list_List* const list, UA_list_PayloadComparer compare, void* payload){
-	if(list==UA_NULL)return UA_NULL;
-	if(compare){
-		UA_list_Element* current = list->first;
-		while(current){
-			if(compare && (*compare)(current->payload, payload)==TRUE){
-				return current;
-			}
-			current=current->next;
-		}
-	}
-	/* nothing found */
-	return UA_NULL;
-}
-
-UA_list_Element* UA_list_getFirst(UA_list_List* const list){
-	if(list==UA_NULL)return UA_NULL;
-	return list->first;
-}
-
-UA_list_Element* UA_list_getLast(UA_list_List* const list){
-	if(list==UA_NULL)return UA_NULL;
-	return list->last;
+UA_Int32 UA_list_iteratePayload(UA_list_List *const list, UA_list_PayloadVisitor visitor) {
+    UA_list_Element *current;
+    UA_list_Element *next = UA_NULL;
+    if(list == UA_NULL)
+        return UA_ERROR;
+    current = list->first;
+    while(current) {
+        next = current->next;
+        if(visitor)
+            (*visitor)(current->payload);
+        current = next;
+    }
+    return UA_NO_ERROR;
+}
+
+UA_list_Element *UA_list_find(UA_list_List *const list, UA_list_PayloadMatcher matcher) {
+    if(list == UA_NULL) return UA_NULL;
+    if(matcher) {
+        UA_list_Element *current = list->first;
+        while(current) {
+            if(matcher && (*matcher)(current->payload) == TRUE)
+                return current;
+            current = current->next;
+        }
+    }
+    /* nothing found */
+    return UA_NULL;
+}
+
+UA_list_Element *UA_list_search(UA_list_List *const list, UA_list_PayloadComparer compare, void *payload) {
+    if(list == UA_NULL) return UA_NULL;
+    if(compare) {
+        UA_list_Element *current = list->first;
+        while(current) {
+            if(compare && (*compare)(current->payload, payload) == TRUE)
+                return current;
+            current = current->next;
+        }
+    }
+    /* nothing found */
+    return UA_NULL;
+}
+
+UA_list_Element *UA_list_getFirst(UA_list_List *const list) {
+    if(list == UA_NULL) return UA_NULL;
+    return list->first;
+}
+
+UA_list_Element *UA_list_getLast(UA_list_List *const list) {
+    if(list == UA_NULL) return UA_NULL;
+    return list->last;
 }

+ 28 - 28
src/util/ua_list.h

@@ -7,59 +7,59 @@
 /* Doubly Linked List */
 /**********************/
 
-typedef void (*UA_list_PayloadVisitor)(void* payload);
+typedef void (*UA_list_PayloadVisitor)(void *payload);
 
 typedef struct UA_list_Element {
-	struct UA_list_List* father;
-	void *payload;
-    struct UA_list_Element* next;
-    struct UA_list_Element* prev;
+    struct UA_list_List    *father;
+    void *payload;
+    struct UA_list_Element *next;
+    struct UA_list_Element *prev;
 }UA_list_Element;
 
 typedef struct UA_list_List {
-   struct UA_list_Element* first;
-   struct UA_list_Element* last;
-   UA_Int32 size;
+    struct UA_list_Element *first;
+    struct UA_list_Element *last;
+    UA_Int32 size;
 }UA_list_List;
 
-typedef void (*UA_list_ElementVisitor)(UA_list_Element* payload);
+typedef void (*UA_list_ElementVisitor)(UA_list_Element *payload);
 
 //typedef Boolean (*UA_list_PayloadMatcher)(void* payload);
-typedef _Bool (*UA_list_PayloadMatcher)(void* payload);
-typedef _Bool (*UA_list_PayloadComparer)(void* payload, void* otherPayload);
+typedef _Bool (*UA_list_PayloadMatcher)(void *payload);
+typedef _Bool (*UA_list_PayloadComparer)(void *payload, void *otherPayload);
 
-void UA_list_defaultFreer(void* payload);
+void UA_list_defaultFreer(void *payload);
 
-UA_Int32 UA_list_initElement(UA_list_Element* element);
+UA_Int32 UA_list_initElement(UA_list_Element *element);
 
-UA_Int32 UA_list_init(UA_list_List* list);
+UA_Int32 UA_list_init(UA_list_List *list);
 
-UA_Int32 UA_list_addElementToFront(UA_list_List* list, UA_list_Element* element);
+UA_Int32 UA_list_addElementToFront(UA_list_List *list, UA_list_Element *element);
 
-UA_Int32 UA_list_addPayloadToFront(UA_list_List* list, void* const payload);
+UA_Int32 UA_list_addPayloadToFront(UA_list_List *list, void *const payload);
 
-UA_Int32 UA_list_addElementToBack(UA_list_List* list, UA_list_Element* element);
+UA_Int32 UA_list_addElementToBack(UA_list_List *list, UA_list_Element *element);
 
-UA_Int32 UA_list_addPayloadToBack(UA_list_List* list, void* const payload);
+UA_Int32 UA_list_addPayloadToBack(UA_list_List *list, void *const payload);
 
-UA_Int32 UA_list_removeFirst(UA_list_List* list, UA_list_PayloadVisitor visitor);
+UA_Int32 UA_list_removeFirst(UA_list_List *list, UA_list_PayloadVisitor visitor);
 
-UA_Int32 UA_list_removeLast(UA_list_List* list, UA_list_PayloadVisitor visitor);
+UA_Int32 UA_list_removeLast(UA_list_List *list, UA_list_PayloadVisitor visitor);
 
-UA_Int32 UA_list_removeElement(UA_list_Element* const elem, UA_list_PayloadVisitor visitor);
+UA_Int32 UA_list_removeElement(UA_list_Element *const elem, UA_list_PayloadVisitor visitor);
 
-UA_Int32 UA_list_destroy(UA_list_List* list, UA_list_PayloadVisitor visitor);
+UA_Int32 UA_list_destroy(UA_list_List *list, UA_list_PayloadVisitor visitor);
 
-UA_Int32 UA_list_iterateElement(UA_list_List* const list, UA_list_ElementVisitor visitor);
+UA_Int32 UA_list_iterateElement(UA_list_List *const list, UA_list_ElementVisitor visitor);
 
-UA_Int32 UA_list_iteratePayload(UA_list_List* const list, UA_list_PayloadVisitor visitor);
+UA_Int32 UA_list_iteratePayload(UA_list_List *const list, UA_list_PayloadVisitor visitor);
 
-UA_list_Element* UA_list_find(UA_list_List* const list, UA_list_PayloadMatcher matcher);
+UA_list_Element *UA_list_find(UA_list_List *const list, UA_list_PayloadMatcher matcher);
 
-UA_list_Element* UA_list_search(UA_list_List* const list, UA_list_PayloadComparer compare, void* payload);
+UA_list_Element *UA_list_search(UA_list_List *const list, UA_list_PayloadComparer compare, void *payload);
 
-UA_list_Element* UA_list_getFirst(UA_list_List* const list);
+UA_list_Element *UA_list_getFirst(UA_list_List *const list);
 
-UA_list_Element* UA_list_getLast(UA_list_List* const list);
+UA_list_Element *UA_list_getLast(UA_list_List *const list);
 
 #endif /* UA_LIST_H_ */

+ 17 - 17
src/util/ua_log.h

@@ -6,56 +6,56 @@
 
    @brief Logging functionality is externally provided to the open62541 libary.
    The server contains a logger-struct with function callbacks
-*/
+ */
 
 typedef enum UA_LoggerCategory {
-	UA_LOGGINGCATEGORY_CONNECTION,
-	UA_LOGGINGCATEGORY_SESSION,
-	UA_LOGGINGCATEGORY_SUBSCRIPTION,
-	UA_LOGGINGCATEGORY_SERVER
+    UA_LOGGINGCATEGORY_CONNECTION,
+    UA_LOGGINGCATEGORY_SESSION,
+    UA_LOGGINGCATEGORY_SUBSCRIPTION,
+    UA_LOGGINGCATEGORY_SERVER
 } UA_LoggerCategory;
 
 typedef struct UA_Logger {
-	void (*log_trace)(UA_LoggerCategory category, const char *msg, ...);
-	void (*log_debug)(UA_LoggerCategory category, const char *msg, ...);
-	void (*log_info)(UA_LoggerCategory category, const char *msg, ...);
-	void (*log_warning)(UA_LoggerCategory category, const char *msg, ...);
-	void (*log_error)(UA_LoggerCategory category, const char *msg, ...);
-	void (*log_fatal)(UA_LoggerCategory category, const char *msg, ...);
+    void (*log_trace)(UA_LoggerCategory category, const char *msg, ...);
+    void (*log_debug)(UA_LoggerCategory category, const char *msg, ...);
+    void (*log_info)(UA_LoggerCategory category, const char *msg, ...);
+    void (*log_warning)(UA_LoggerCategory category, const char *msg, ...);
+    void (*log_error)(UA_LoggerCategory category, const char *msg, ...);
+    void (*log_fatal)(UA_LoggerCategory category, const char *msg, ...);
 } UA_Logger;
 
 #if UA_LOGLEVEL <= 100
-#define UA_LOG_TRACE(CATEGORY, MSG, ...) do{ logger.log_trace(CATEGORY, MSG, __VA_ARGS__); } while(0)
+#define UA_LOG_TRACE(CATEGORY, MSG, ...) do { logger.log_trace(CATEGORY, MSG, __VA_ARGS__); } while(0)
 #else
 #define UA_LOG_TRACE(CATEGORY, MSG, ...) do {} while(0)
 #endif
 
 #if UA_LOGLEVEL <= 200
-#define UA_LOG_DEBUG(CATEGORY, MSG, ...) do{ logger.log_debug(CATEGORY, MSG, __VA_ARGS__); } while(0)
+#define UA_LOG_DEBUG(CATEGORY, MSG, ...) do { logger.log_debug(CATEGORY, MSG, __VA_ARGS__); } while(0)
 #else
 #define UA_LOG_DEBUG(CATEGORY, MSG, ...) do {} while(0)
 #endif
 
 #if UA_LOGLEVEL <= 300
-#define UA_LOG_INFO(CATEGORY, MSG, ...) do{ logger.log_info(CATEGORY, MSG, __VA_ARGS__); } while(0)
+#define UA_LOG_INFO(CATEGORY, MSG, ...) do { logger.log_info(CATEGORY, MSG, __VA_ARGS__); } while(0)
 #else
 #define UA_LOG_INFO(CATEGORY, MSG, ...) do {} while(0)
 #endif
 
 #if UA_LOGLEVEL <= 400
-#define UA_LOG_WARNING(CATEGORY, MSG, ...) do{ logger.log_warning(CATEGORY, MSG, __VA_ARGS__); } while(0)
+#define UA_LOG_WARNING(CATEGORY, MSG, ...) do { logger.log_warning(CATEGORY, MSG, __VA_ARGS__); } while(0)
 #else
 #define UA_LOG_WARNING(CATEGORY, MSG, ...) do {} while(0)
 #endif
 
 #if UA_LOGLEVEL <= 500
-#define UA_LOG_ERROR(CATEGORY, MSG, ...) do{ logger.log_error(CATEGORY, MSG, __VA_ARGS__); } while(0)
+#define UA_LOG_ERROR(CATEGORY, MSG, ...) do { logger.log_error(CATEGORY, MSG, __VA_ARGS__); } while(0)
 #else
 #define UA_LOG_ERROR(CATEGORY, MSG, ...) do {} while(0)
 #endif
 
 #if UA_LOGLEVEL <= 600
-#define UA_LOG_FATAL(CATEGORY, MSG, ...) do{ logger.log_fatal(CATEGORY, MSG, __VA_ARGS__); } while(0)
+#define UA_LOG_FATAL(CATEGORY, MSG, ...) do { logger.log_fatal(CATEGORY, MSG, __VA_ARGS__); } while(0)
 #else
 #define UA_LOG_FATAL(CATEGORY, MSG, ...) do {} while(0)
 #endif

+ 7 - 7
src/util/ua_util.c

@@ -7,14 +7,14 @@ extern INLINE UA_Int32 _UA_alloc(void **ptr, UA_Int32 size, char *pname, char *s
 extern INLINE UA_Int32 _UA_alloca(void **ptr, UA_Int32 size, char *pname, char *sname, char *f, UA_Int32 l);
 
 UA_Int32 UA_memcpy(void *dst, void const *src, UA_Int32 size) {
-	if(dst == UA_NULL) return UA_ERR_INVALID_VALUE;
-	DBG_VERBOSE(printf("UA_memcpy - %p;%p;%d\n", dst, src, size));
-	memcpy(dst, src, size);
-	return UA_SUCCESS;
+    if(dst == UA_NULL) return UA_ERR_INVALID_VALUE;
+    DBG_VERBOSE(printf("UA_memcpy - %p;%p;%d\n", dst, src, size));
+    memcpy(dst, src, size);
+    return UA_SUCCESS;
 }
 
 UA_Int32 UA_VTable_isValidType(UA_Int32 type) {
-	if(type < 0 /* UA_BOOLEAN */ || type > 271 /* UA_INVALID */)
-		return UA_ERR_INVALID_VALUE;
-	return UA_SUCCESS;
+    if(type < 0 /* UA_BOOLEAN */ || type > 271 /* UA_INVALID */)
+        return UA_ERR_INVALID_VALUE;
+    return UA_SUCCESS;
 }

+ 20 - 20
src/util/ua_util.h

@@ -52,31 +52,31 @@ void const *UA_alloc_lastptr;
 #define UA_NULL ((void *)0)
 
 INLINE UA_Int32 _UA_free(void *ptr, char *pname, char *f, UA_Int32 l) {
-	DBG_VERBOSE(printf("UA_free;%p;;%s;;%s;%d\n", ptr, pname, f, l); fflush(stdout));
-	free(ptr); // checks if ptr != NULL in the background
-	return UA_SUCCESS;
+    DBG_VERBOSE(printf("UA_free;%p;;%s;;%s;%d\n", ptr, pname, f, l); fflush(stdout));
+    free(ptr); // checks if ptr != NULL in the background
+    return UA_SUCCESS;
 }
 
 INLINE UA_Int32 _UA_alloc(void **ptr, UA_Int32 size, char *pname, char *sname, char *f, UA_Int32 l) {
-	if(ptr == UA_NULL)
-		return UA_ERR_INVALID_VALUE;
-	UA_alloc_lastptr = *ptr = malloc(size);
-	DBG_VERBOSE(printf("UA_alloc - %p;%d;%s;%s;%s;%d\n", *ptr, size, pname, sname, f, l); fflush(stdout));
-	if(*ptr == UA_NULL)
-		return UA_ERR_NO_MEMORY;
-	return UA_SUCCESS;
+    if(ptr == UA_NULL)
+        return UA_ERR_INVALID_VALUE;
+    UA_alloc_lastptr = *ptr = malloc(size);
+    DBG_VERBOSE(printf("UA_alloc - %p;%d;%s;%s;%s;%d\n", *ptr, size, pname, sname, f, l); fflush(stdout));
+    if(*ptr == UA_NULL)
+        return UA_ERR_NO_MEMORY;
+    return UA_SUCCESS;
 }
 
 INLINE UA_Int32 _UA_alloca(void **ptr, UA_Int32 size, char *pname, char *sname, char *f, UA_Int32 l) {
-	if(ptr == UA_NULL)
-		return UA_ERR_INVALID_VALUE;
+    if(ptr == UA_NULL)
+        return UA_ERR_INVALID_VALUE;
 #ifdef MSVC
-	*ptr = _alloca(size);
+    *ptr = _alloca(size);
 #else
-	*ptr = alloca(size);
+    *ptr = alloca(size);
 #endif
-	DBG_VERBOSE(printf("UA_alloca - %p;%d;%s;%s;%s;%d\n", *ptr, size, pname, sname, f, l); fflush(stdout));
-	return UA_SUCCESS;
+    DBG_VERBOSE(printf("UA_alloca - %p;%d;%s;%s;%s;%d\n", *ptr, size, pname, sname, f, l); fflush(stdout));
+    return UA_SUCCESS;
 }
 
 UA_Int32 UA_memcpy(void *dst, void const *src, UA_Int32 size);
@@ -86,10 +86,10 @@ UA_Int32 UA_VTable_isValidType(UA_Int32 type);
 #define UA_alloc(ptr, size) _UA_alloc(ptr, size, # ptr, # size, __FILE__, __LINE__)
 
 /** @brief UA_alloca assigns memory on the stack instead of the heap. It is a
-	very fast alternative to standard malloc. The memory is automatically
-	returned ('freed') when the current function returns. Use this only for
-	small temporary values. For more than 100Byte, it is more reasonable to use
-	proper UA_alloc. */
+    very fast alternative to standard malloc. The memory is automatically
+    returned ('freed') when the current function returns. Use this only for
+    small temporary values. For more than 100Byte, it is more reasonable to use
+    proper UA_alloc. */
 #define UA_alloca(ptr, size) _UA_alloca(ptr, size, # ptr, # size, __FILE__, __LINE__)
 
 #define UA_assert(ignore) assert(ignore)

+ 1 - 1
tools/uncrustify.cfg

@@ -1,6 +1,6 @@
 # Basics
 code_width		= 110
-indent_with_tabs	= 1		# 1=indent to level only, 2=indent with tabs
+indent_with_tabs	= 0		# 1=indent to level only, 2=indent with tabs
 input_tab_size		= 4		# original tab size
 output_tab_size		= 4		# new tab size
 indent_columns		= output_tab_size