ソースを参照

Import vs2008 patch from @carljoerger and @frax2222

frax2222 7 年 前
コミット
5efd75e5dd

+ 21 - 18
include/ua_config.h.in

@@ -65,11 +65,14 @@ extern "C" {
 #include "ms_stdint.h" /* Includes stdint.h or workaround for older Visual Studios */
 
 #ifndef __cplusplus
-# include <stdbool.h> /* C99 Boolean */
-/* Manual Boolean:
-typedef uint8_t bool;
-#define true 1
-#define false 0 */
+# if defined(_MSC_VER) && _MSC_VER < 1800 
+    /* Workaround for old Visual Studios */
+    typedef uint8_t bool;
+#  define true 1
+#  define false 0
+# else
+#  include <stdbool.h> /* Default: C99 Boolean */
+# endif
 #endif
 
 /* Manually define some function on libc */
@@ -183,61 +186,61 @@ typedef uint8_t bool;
  * ^^^^^^^^^^^^^^^^^^ */
 #if defined(_WIN32) || (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
                         (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
-# define UA_BINARY_OVERLAYABLE_INTEGER true
+# define UA_BINARY_OVERLAYABLE_INTEGER 1
 #elif defined(__ANDROID__) /* Andoid */
 # include <endian.h>
 # if __BYTE_ORDER == __LITTLE_ENDIAN
-#  define UA_BINARY_OVERLAYABLE_INTEGER true
+#  define UA_BINARY_OVERLAYABLE_INTEGER 1
 # endif
 #elif defined(__linux__) /* Linux */
 # include <endian.h>
 # if __BYTE_ORDER == __LITTLE_ENDIAN
-#  define UA_BINARY_OVERLAYABLE_INTEGER true
+#  define UA_BINARY_OVERLAYABLE_INTEGER 1
 # endif
 # if __FLOAT_BYTE_ORDER == __LITTLE_ENDIAN
-#  define UA_BINARY_OVERLAYABLE_FLOAT true
+#  define UA_BINARY_OVERLAYABLE_FLOAT 1
 # endif
 #elif defined(__OpenBSD__) /* OpenBSD */
 # include <sys/endian.h>
 # if BYTE_ORDER == LITTLE_ENDIAN
-#  define UA_BINARY_OVERLAYABLE_INTEGER true
+#  define UA_BINARY_OVERLAYABLE_INTEGER 1
 # endif
 #elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) /* Other BSD */
 # include <sys/endian.h>
 # if _BYTE_ORDER == _LITTLE_ENDIAN
-#  define UA_BINARY_OVERLAYABLE_INTEGER true
+#  define UA_BINARY_OVERLAYABLE_INTEGER 1
 # endif
 #elif defined(__APPLE__) /* Apple (MacOS, iOS) */
 # include <libkern/OSByteOrder.h>
 # if defined(__LITTLE_ENDIAN__)
-#  define UA_BINARY_OVERLAYABLE_INTEGER true
+#  define UA_BINARY_OVERLAYABLE_INTEGER 1
 # endif
 #elif defined(__QNX__) || defined(__QNXNTO__) /* QNX */
 # include <gulliver.h>
 # if defined(__LITTLEENDIAN__)
-#  define UA_BINARY_OVERLAYABLE_INTEGER true
+#  define UA_BINARY_OVERLAYABLE_INTEGER 1
 # endif
 #endif
 
 #ifndef UA_BINARY_OVERLAYABLE_INTEGER
-# define UA_BINARY_OVERLAYABLE_INTEGER false
+# define UA_BINARY_OVERLAYABLE_INTEGER 0
 #endif
 
 /**
  * Float Endianness
  * ^^^^^^^^^^^^^^^^ */
 #if defined(_WIN32)
-# define UA_BINARY_OVERLAYABLE_FLOAT true
+# define UA_BINARY_OVERLAYABLE_FLOAT 1
 #elif defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
     (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__) /* Defined only in GCC */
-# define UA_BINARY_OVERLAYABLE_FLOAT true
+# define UA_BINARY_OVERLAYABLE_FLOAT 1
 #elif defined(__FLOAT_WORD_ORDER) && defined(__LITTLE_ENDIAN) && \
     (__FLOAT_WORD_ORDER == __LITTLE_ENDIAN) /* Defined only in GCC */
-# define UA_BINARY_OVERLAYABLE_FLOAT true
+# define UA_BINARY_OVERLAYABLE_FLOAT 1
 #endif
 
 #ifndef UA_BINARY_OVERLAYABLE_FLOAT
-# define UA_BINARY_OVERLAYABLE_FLOAT false
+# define UA_BINARY_OVERLAYABLE_FLOAT 0
 #endif
 
 #ifdef __cplusplus

+ 10 - 8
include/ua_job.h

@@ -27,16 +27,18 @@ typedef struct UA_Server UA_Server;
 
 typedef void (*UA_ServerCallback)(UA_Server *server, void *data);
 
+typedef enum {
+    UA_JOBTYPE_NOTHING,
+    UA_JOBTYPE_DETACHCONNECTION, /* Detach the connection from the secure channel (but don't delete it) */
+    UA_JOBTYPE_BINARYMESSAGE_NETWORKLAYER, /* The binary message is memory managed by the networklayer */
+    UA_JOBTYPE_BINARYMESSAGE_ALLOCATED, /* The binary message was relocated away from the networklayer */
+    UA_JOBTYPE_METHODCALL, /* Call the method as soon as possible */
+    UA_JOBTYPE_METHODCALL_DELAYED, /* Call the method as soon as all previous jobs have finished */
+} UA_JobType;
+
 /* Jobs describe work that is executed once or repeatedly in the server */
 typedef struct {
-    enum {
-        UA_JOBTYPE_NOTHING,
-        UA_JOBTYPE_DETACHCONNECTION, /* Detach the connection from the secure channel (but don't delete it) */
-        UA_JOBTYPE_BINARYMESSAGE_NETWORKLAYER, /* The binary message is memory managed by the networklayer */
-        UA_JOBTYPE_BINARYMESSAGE_ALLOCATED, /* The binary message was relocated away from the networklayer */
-        UA_JOBTYPE_METHODCALL, /* Call the method as soon as possible */
-        UA_JOBTYPE_METHODCALL_DELAYED, /* Call the method as soon as all previous jobs have finished */
-    } type;
+    UA_JobType type;
     union {
         UA_Connection *closeConnection;
         struct {

+ 2 - 2
plugins/ua_accesscontrol_default.c

@@ -23,7 +23,7 @@ activateSession_default(const UA_NodeId *sessionId, const UA_ExtensionObject *us
     /* anonymous login */
     if(enableAnonymousLogin &&
        userIdentityToken->content.decoded.type == &UA_TYPES[UA_TYPES_ANONYMOUSIDENTITYTOKEN]) {
-        const UA_AnonymousIdentityToken *token = userIdentityToken->content.decoded.data;
+        const UA_AnonymousIdentityToken *token = (UA_AnonymousIdentityToken *)userIdentityToken->content.decoded.data;
 
         /* Compatibility notice: Siemens OPC Scout v10 provides an empty
          * policyId. This is not compliant. For compatibility we will assume
@@ -38,7 +38,7 @@ activateSession_default(const UA_NodeId *sessionId, const UA_ExtensionObject *us
     /* username and password */
     if(enableUsernamePasswordLogin &&
        userIdentityToken->content.decoded.type == &UA_TYPES[UA_TYPES_USERNAMEIDENTITYTOKEN]) {
-        const UA_UserNameIdentityToken *token = userIdentityToken->content.decoded.data;
+        const UA_UserNameIdentityToken *token = (UA_UserNameIdentityToken *)userIdentityToken->content.decoded.data;
         if(!UA_String_equal(&token->policyId, &username_policy))
             return UA_STATUSCODE_BADIDENTITYTOKENINVALID;
 

+ 69 - 83
plugins/ua_config_standard.c

@@ -11,11 +11,11 @@
 /*******************************/
 
 const UA_EXPORT UA_ConnectionConfig UA_ConnectionConfig_standard = {
-    .protocolVersion = 0,
-    .sendBufferSize = 65535, /* 64k per chunk */
-    .recvBufferSize = 65535, /* 64k per chunk */
-    .maxMessageSize = 0, /* 0 -> unlimited */
-    .maxChunkCount = 0 /* 0 -> unlimited */
+	0, /* .protocolVersion */
+    65535, /* .sendBufferSize, 64k per chunk */
+    65535, /* .recvBufferSize, 64k per chunk */
+    0, /* .maxMessageSize, 0 -> unlimited */
+    0 /* .maxChunkCount, 0 -> unlimited */
 };
 
 /***************************/
@@ -41,82 +41,70 @@ const UA_EXPORT UA_ConnectionConfig UA_ConnectionConfig_standard = {
 const UA_Boolean enableAnonymousLogin = ENABLEANONYMOUSLOGIN;
 const UA_Boolean enableUsernamePasswordLogin = ENABLEUSERNAMEPASSWORDLOGIN;
 const size_t usernamePasswordsSize = 2;
-const UA_UsernamePasswordLogin *usernamePasswords = (UA_UsernamePasswordLogin[2]){
+
+UA_UsernamePasswordLogin UsernamePasswordLogin[2] = {
     { UA_STRING_STATIC("user1"), UA_STRING_STATIC("password") },
     { UA_STRING_STATIC("user2"), UA_STRING_STATIC("password1") } };
+const UA_UsernamePasswordLogin *usernamePasswords = UsernamePasswordLogin;
 
 const UA_EXPORT UA_ServerConfig UA_ServerConfig_standard = {
-    .nThreads = 1,
-    .logger = UA_Log_Stdout,
+	1, /* .nThreads */
+    UA_Log_Stdout, /* .logger */
 
     /* Server Description */
-    .buildInfo = {
-        .productUri = UA_STRING_STATIC(PRODUCT_URI),
-        .manufacturerName = UA_STRING_STATIC(MANUFACTURER_NAME),
-        .productName = UA_STRING_STATIC(PRODUCT_NAME),
-        .softwareVersion = UA_STRING_STATIC(VERSION(UA_OPEN62541_VER_MAJOR,
-                                                    UA_OPEN62541_VER_MINOR,
-                                                    UA_OPEN62541_VER_PATCH,
-                                                    UA_OPEN62541_VER_LABEL)),
-        .buildNumber = UA_STRING_STATIC(__DATE__ " " __TIME__),
-        .buildDate = 0 },
-    .applicationDescription = {
-        .applicationUri = UA_STRING_STATIC(APPLICATION_URI),
-        .productUri = UA_STRING_STATIC(PRODUCT_URI),
-        .applicationName = { .locale = UA_STRING_STATIC("en"),
-                             .text = UA_STRING_STATIC(APPLICATION_NAME) },
-        .applicationType = UA_APPLICATIONTYPE_SERVER,
-        .gatewayServerUri = UA_STRING_STATIC_NULL,
-        .discoveryProfileUri = UA_STRING_STATIC_NULL,
-        .discoveryUrlsSize = 0,
-        .discoveryUrls = NULL },
-    .serverCertificate = UA_STRING_STATIC_NULL,
-
-    /* Custom DataTypes */
-    .customDataTypesSize = 0,
-    .customDataTypes = NULL,
-
+    {UA_STRING_STATIC(PRODUCT_URI),
+     UA_STRING_STATIC(MANUFACTURER_NAME),
+     UA_STRING_STATIC(PRODUCT_NAME),
+     UA_STRING_STATIC(VERSION(UA_OPEN62541_VER_MAJOR, UA_OPEN62541_VER_MINOR,
+                              UA_OPEN62541_VER_PATCH, UA_OPEN62541_VER_LABEL)),
+     UA_STRING_STATIC(__DATE__ " " __TIME__), 0 }, /* .buildInfo */
+	 
+    {UA_STRING_STATIC(APPLICATION_URI),
+     UA_STRING_STATIC(PRODUCT_URI),
+     {UA_STRING_STATIC("en"),UA_STRING_STATIC(APPLICATION_NAME) },
+      UA_APPLICATIONTYPE_SERVER,
+      UA_STRING_STATIC_NULL,
+      UA_STRING_STATIC_NULL,
+      0, NULL }, /* .applicationDescription */
+    UA_STRING_STATIC_NULL, /* .serverCertificate */
+
+	/* Custom DataTypes */
+	0, /* .customDataTypesSize */
+	NULL, /* .customDataTypes */
+	
     /* Networking */
-    .networkLayersSize = 0,
-    .networkLayers = NULL,
+    0, /* .networkLayersSize */
+    NULL, /* .networkLayers */
 
     /* Access Control */
-    .accessControl = {
-        .enableAnonymousLogin = ENABLEANONYMOUSLOGIN,
-        .enableUsernamePasswordLogin = ENABLEUSERNAMEPASSWORDLOGIN,
-        .activateSession = activateSession_default,
-        .closeSession = closeSession_default,
-        .getUserRightsMask = getUserRightsMask_default,
-        .getUserAccessLevel = getUserAccessLevel_default,
-        .getUserExecutable = getUserExecutable_default,
-        .getUserExecutableOnObject = getUserExecutableOnObject_default,
-        .allowAddNode = allowAddNode_default,
-        .allowAddReference = allowAddReference_default,
-        .allowDeleteNode = allowDeleteNode_default,
-        .allowDeleteReference = allowDeleteReference_default
-    },
+    {ENABLEANONYMOUSLOGIN, ENABLEUSERNAMEPASSWORDLOGIN,
+     activateSession_default, closeSession_default,
+     getUserRightsMask_default, getUserAccessLevel_default,
+     getUserExecutable_default, getUserExecutableOnObject_default,
+     allowAddNode_default, allowAddReference_default,
+     allowDeleteNode_default, allowDeleteReference_default},
 
     /* Limits for SecureChannels */
-    .maxSecureChannels = 40,
-    .maxSecurityTokenLifetime = 10 * 60 * 1000, /* 10 minutes */
+    40, /* .maxSecureChannels */
+    10 * 60 * 1000, /* .maxSecurityTokenLifetime, 10 minutes */
 
     /* Limits for Sessions */
-    .maxSessions = 100,
-    .maxSessionTimeout = 60.0 * 60.0 * 1000.0, /* 1h */
+    100, /* .maxSessions */
+    60.0 * 60.0 * 1000.0, /* .maxSessionTimeout, 1h */
 
     /* Limits for Subscriptions */
-    .publishingIntervalLimits = { .min = 100.0, .max = 3600.0 * 1000.0 },
-    .lifeTimeCountLimits = { .max = 15000, .min = 3 },
-    .keepAliveCountLimits = { .max = 100, .min = 1 },
-    .maxNotificationsPerPublish = 1000,
-    .maxRetransmissionQueueSize = 0, /* unlimited */
+    {100.0,3600.0 * 1000.0 }, /* .publishingIntervalLimits */
+    {3, 15000 }, /* .lifeTimeCountLimits */
+    {1,100}, /* .keepAliveCountLimits */
+    1000, /* .maxNotificationsPerPublish */
+    0, /* .maxRetransmissionQueueSize, unlimited */
 
     /* Limits for MonitoredItems */
-    .samplingIntervalLimits = { .min = 50.0, .max = 24.0 * 3600.0 * 1000.0 },
-    .queueSizeLimits = { .max = 100, .min = 1 }
+    {50.0, 24.0 * 3600.0 * 1000.0 }, /* .samplingIntervalLimits */
+    {1,100} /* .queueSizeLimits */
 
 #ifdef UA_ENABLE_DISCOVERY
-	,.discoveryCleanupTimeout = 60*60
+	, 60*60 /* .discoveryCleanupTimeout */
 #endif
 };
 
@@ -125,21 +113,19 @@ const UA_EXPORT UA_ServerConfig UA_ServerConfig_standard = {
 /***************************/
 
 const UA_EXPORT UA_ClientConfig UA_ClientConfig_standard = {
-    .timeout = 5000, /* 5 seconds */
-    .secureChannelLifeTime = 10 * 60 * 1000, /* 10 minutes */
-    .logger = UA_Log_Stdout,
-    .localConnectionConfig = {
-        .protocolVersion = 0,
-        .sendBufferSize = 65535, /* 64k per chunk */
-        .recvBufferSize  = 65535, /* 64k per chunk */
-        .maxMessageSize = 0, /* 0 -> unlimited */
-        .maxChunkCount = 0 /* 0 -> unlimited */
-    },
-    .connectionFunc = UA_ClientConnectionTCP,
-
-    /* Custom DataTypes */
-    .customDataTypesSize = 0,
-    .customDataTypes = NULL
+    5000, /* .timeout, 5 seconds */
+    10 * 60 * 1000, /* .secureChannelLifeTime, 10 minutes */
+    UA_Log_Stdout, /* .logger */
+    /* .localConnectionConfig */
+    {0, /* .protocolVersion */
+     65535, /* .sendBufferSize, 64k per chunk */
+     65535, /* .recvBufferSize, 64k per chunk */
+     0, /* .maxMessageSize, 0 -> unlimited */
+     0 }, /* .maxChunkCount, 0 -> unlimited */
+    UA_ClientConnectionTCP, /* .connectionFunc */
+
+    0, /* .customDataTypesSize */
+    NULL /*.customDataTypes */
 };
 
 /****************************************/
@@ -149,12 +135,12 @@ const UA_EXPORT UA_ClientConfig UA_ClientConfig_standard = {
 #ifdef UA_ENABLE_SUBSCRIPTIONS
 
 const UA_SubscriptionSettings UA_SubscriptionSettings_standard = {
-    .requestedPublishingInterval = 500.0,
-    .requestedLifetimeCount = 10000,
-    .requestedMaxKeepAliveCount = 1,
-    .maxNotificationsPerPublish = 10,
-    .publishingEnabled = true,
-    .priority = 0
+    500.0, /* .requestedPublishingInterval */
+    10000, /* .requestedLifetimeCount */
+    1, /* .requestedMaxKeepAliveCount */
+    10, /* .maxNotificationsPerPublish */
+    true, /* .publishingEnabled */
+    0 /* .priority */
 };
 
 #endif

+ 27 - 22
plugins/ua_network_tcp.c

@@ -17,6 +17,9 @@
 #include <stdio.h> // snprintf
 #include <string.h> // memset
 #include <errno.h>
+#if UNDER_CE
+#define errno WSAGetLastError()
+#endif
 #ifdef _WIN32
 # ifndef __clang__
 #  include <malloc.h>
@@ -121,7 +124,7 @@ socket_write(UA_Connection *connection, UA_ByteString *buf) {
 
 static UA_StatusCode
 socket_recv(UA_Connection *connection, UA_ByteString *response, UA_UInt32 timeout) {
-    response->data = malloc(connection->localConf.recvBufferSize);
+    response->data = (UA_Byte *)malloc(connection->localConf.recvBufferSize);
     if(!response->data) {
         response->length = 0;
         return UA_STATUSCODE_BADOUTOFMEMORY; /* not enough memory retry */
@@ -255,6 +258,11 @@ static void FreeConnectionCallback(UA_Server *server, void *ptr) {
 
 #define MAXBACKLOG 100
 
+typedef struct {
+  UA_Connection *connection;
+  UA_Int32 sockfd;
+} ConnectionMapping;
+
 typedef struct {
     UA_ConnectionConfig conf;
     UA_UInt16 port;
@@ -263,10 +271,7 @@ typedef struct {
     /* open sockets and connections */
     UA_Int32 serversockfd;
     size_t mappingsSize;
-    struct ConnectionMapping {
-        UA_Connection *connection;
-        UA_Int32 sockfd;
-    } *mappings;
+    ConnectionMapping *mappings;
 } ServerNetworkLayerTCP;
 
 static UA_StatusCode
@@ -313,7 +318,7 @@ ServerNetworkLayerTCP_closeConnection(UA_Connection *connection) {
 #endif
 #if UA_LOGLEVEL <= 300
    //cppcheck-suppress unreadVariable
-    ServerNetworkLayerTCP *layer = connection->handle;
+    ServerNetworkLayerTCP *layer = (ServerNetworkLayerTCP *)connection->handle;
     UA_LOG_INFO(layer->logger, UA_LOGCATEGORY_NETWORK,
                 "Connection %i | Force closing the connection",
                 connection->sockfd);
@@ -326,14 +331,13 @@ ServerNetworkLayerTCP_closeConnection(UA_Connection *connection) {
 /* call only from the single networking thread */
 static UA_StatusCode
 ServerNetworkLayerTCP_add(ServerNetworkLayerTCP *layer, UA_Int32 newsockfd) {
-    UA_Connection *c = malloc(sizeof(UA_Connection));
+    UA_Connection *c = (UA_Connection *)malloc(sizeof(UA_Connection));
     if(!c)
         return UA_STATUSCODE_BADINTERNALERROR;
 
     struct sockaddr_in addr;
     socklen_t addrlen = sizeof(struct sockaddr_in);
     int res = getpeername(newsockfd, (struct sockaddr*)&addr, &addrlen);
-    
     if(res == 0) {
         UA_LOG_INFO(layer->logger, UA_LOGCATEGORY_NETWORK,
                     "Connection %i | New connection over TCP from %s:%d",
@@ -343,7 +347,6 @@ ServerNetworkLayerTCP_add(ServerNetworkLayerTCP *layer, UA_Int32 newsockfd) {
                        "Connection %i | New connection over TCP, "
                        "getpeername failed with errno %i", newsockfd, errno);
     }
-
     memset(c, 0, sizeof(UA_Connection));
     c->sockfd = newsockfd;
     c->handle = layer;
@@ -355,8 +358,8 @@ ServerNetworkLayerTCP_add(ServerNetworkLayerTCP *layer, UA_Int32 newsockfd) {
     c->releaseSendBuffer = ServerNetworkLayerReleaseSendBuffer;
     c->releaseRecvBuffer = ServerNetworkLayerReleaseRecvBuffer;
     c->state = UA_CONNECTION_OPENING;
-    struct ConnectionMapping *nm;
-    nm = realloc(layer->mappings, sizeof(struct ConnectionMapping)*(layer->mappingsSize+1));
+    ConnectionMapping *nm;
+    nm  = (ConnectionMapping *)realloc(layer->mappings, sizeof(ConnectionMapping)*(layer->mappingsSize+1));
     if(!nm) {
         UA_LOG_ERROR(layer->logger, UA_LOGCATEGORY_NETWORK, "No memory for a new Connection");
         free(c);
@@ -371,7 +374,7 @@ ServerNetworkLayerTCP_add(ServerNetworkLayerTCP *layer, UA_Int32 newsockfd) {
 
 static UA_StatusCode
 ServerNetworkLayerTCP_start(UA_ServerNetworkLayer *nl, UA_Logger logger) {
-    ServerNetworkLayerTCP *layer = nl->handle;
+    ServerNetworkLayerTCP *layer = (ServerNetworkLayerTCP *)nl->handle;
     layer->logger = logger;
 
     /* get the discovery url from the hostname */
@@ -415,9 +418,11 @@ ServerNetworkLayerTCP_start(UA_ServerNetworkLayer *nl, UA_Logger logger) {
     }
 
     /* Bind socket to address */
-    const struct sockaddr_in serv_addr = {
-        .sin_family = AF_INET, .sin_addr.s_addr = INADDR_ANY,
-        .sin_port = htons(layer->port), .sin_zero = {0}};
+    struct sockaddr_in serv_addr;
+    serv_addr.sin_family = AF_INET;
+    serv_addr.sin_port = htons(layer->port);
+    serv_addr.sin_addr.s_addr = INADDR_ANY;
+    memset(&(serv_addr.sin_zero), '\0', 8);
     if(bind(newsock, (const struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
         UA_LOG_WARNING(layer->logger, UA_LOGCATEGORY_NETWORK,
                        "Error during binding of the server socket");
@@ -442,7 +447,7 @@ ServerNetworkLayerTCP_start(UA_ServerNetworkLayer *nl, UA_Logger logger) {
 
 static size_t
 ServerNetworkLayerTCP_getJobs(UA_ServerNetworkLayer *nl, UA_Job **jobs, UA_UInt16 timeout) {
-    ServerNetworkLayerTCP *layer = nl->handle;
+    ServerNetworkLayerTCP *layer = (ServerNetworkLayerTCP *)nl->handle;
     fd_set fdset, errset;
     UA_Int32 highestfd = setFDSet(layer, &fdset);
     setFDSet(layer, &errset);
@@ -467,7 +472,7 @@ ServerNetworkLayerTCP_getJobs(UA_ServerNetworkLayer *nl, UA_Job **jobs, UA_UInt1
             /* Send messages directly and do wait to merge packets (disable
                Nagle's algorithm) */
             int i = 1;
-            setsockopt(newsockfd, IPPROTO_TCP, TCP_NODELAY, (void *)&i, sizeof(i));
+            setsockopt(newsockfd, IPPROTO_TCP, TCP_NODELAY, (const char *)&i, sizeof(i));
             ServerNetworkLayerTCP_add(layer, (UA_Int32)newsockfd);
         }
     }
@@ -476,7 +481,7 @@ ServerNetworkLayerTCP_getJobs(UA_ServerNetworkLayer *nl, UA_Job **jobs, UA_UInt1
        resulted socket */
     if(resultsize == 0)
         return 0;
-    UA_Job *js = malloc(sizeof(UA_Job) * (size_t)resultsize * 2);
+    UA_Job *js = (UA_Job*)malloc(sizeof(UA_Job) * (size_t)resultsize * 2);
     if(!js)
         return 0;
 
@@ -522,13 +527,13 @@ ServerNetworkLayerTCP_getJobs(UA_ServerNetworkLayer *nl, UA_Job **jobs, UA_UInt1
 
 static size_t
 ServerNetworkLayerTCP_stop(UA_ServerNetworkLayer *nl, UA_Job **jobs) {
-    ServerNetworkLayerTCP *layer = nl->handle;
+    ServerNetworkLayerTCP *layer = (ServerNetworkLayerTCP *)nl->handle;
     UA_LOG_INFO(layer->logger, UA_LOGCATEGORY_NETWORK,
                 "Shutting down the TCP network layer with %d open connection(s)",
                 layer->mappingsSize);
     shutdown((SOCKET)layer->serversockfd,2);
     CLOSESOCKET(layer->serversockfd);
-    UA_Job *items = malloc(sizeof(UA_Job) * layer->mappingsSize * 2);
+    UA_Job *items = (UA_Job *)malloc(sizeof(UA_Job) * layer->mappingsSize * 2);
     if(!items)
         return 0;
     for(size_t i = 0; i < layer->mappingsSize; ++i) {
@@ -548,7 +553,7 @@ ServerNetworkLayerTCP_stop(UA_ServerNetworkLayer *nl, UA_Job **jobs) {
 
 /* run only when the server is stopped */
 static void ServerNetworkLayerTCP_deleteMembers(UA_ServerNetworkLayer *nl) {
-    ServerNetworkLayerTCP *layer = nl->handle;
+    ServerNetworkLayerTCP *layer = (ServerNetworkLayerTCP *)nl->handle;
     free(layer->mappings);
     free(layer);
     UA_String_deleteMembers(&nl->discoveryUrl);
@@ -565,7 +570,7 @@ UA_ServerNetworkLayerTCP(UA_ConnectionConfig conf, UA_UInt16 port) {
 
     UA_ServerNetworkLayer nl;
     memset(&nl, 0, sizeof(UA_ServerNetworkLayer));
-    ServerNetworkLayerTCP *layer = calloc(1,sizeof(ServerNetworkLayerTCP));
+    ServerNetworkLayerTCP *layer = (ServerNetworkLayerTCP *)calloc(1,sizeof(ServerNetworkLayerTCP));
     if(!layer)
         return nl;
     

+ 3 - 3
src/client/ua_client_highlevel.c

@@ -32,7 +32,7 @@ UA_Client_NamespaceGetIndex(UA_Client *client, UA_String *namespaceUri,
     }
 
     retval = UA_STATUSCODE_BADNOTFOUND;
-    UA_String *ns = response.results[0].value.data;
+    UA_String *ns = (UA_String *)response.results[0].value.data;
     for(size_t i = 0; i < response.results[0].value.arrayLength; ++i){
         if(UA_String_equal(namespaceUri, &ns[i])) {
             *namespaceIndex = (UA_UInt16)i;
@@ -231,7 +231,7 @@ UA_Client_call(UA_Client *client, const UA_NodeId objectId,
     UA_CallMethodRequest_init(&item);
     item.methodId = methodId;
     item.objectId = objectId;
-    item.inputArguments = (void*)(uintptr_t)input; // cast const...
+    item.inputArguments = (UA_Variant *)(void*)(uintptr_t)input; // cast const...
     item.inputArgumentsSize = inputSize;
     request.methodsToCall = &item;
     request.methodsToCallSize = 1;
@@ -401,7 +401,7 @@ UA_Client_readArrayDimensionsAttribute(UA_Client *client, const UA_NodeId nodeId
         goto cleanup;
     }
 
-    *outArrayDimensions = res->value.data;
+    *outArrayDimensions = (UA_Int32 *)res->value.data;
     *outArrayDimensionsSize = res->value.arrayLength;
     UA_free(res->value.data);
     res->value.data = NULL;

+ 9 - 9
src/client/ua_client_highlevel_subscriptions.c

@@ -22,7 +22,7 @@ UA_Client_Subscriptions_new(UA_Client *client, UA_SubscriptionSettings settings,
     if(retval != UA_STATUSCODE_GOOD)
         goto cleanup;
 
-    UA_Client_Subscription *newSub = UA_malloc(sizeof(UA_Client_Subscription));
+    UA_Client_Subscription *newSub = (UA_Client_Subscription *)UA_malloc(sizeof(UA_Client_Subscription));
     if(!newSub) {
         retval = UA_STATUSCODE_BADOUTOFMEMORY;
         goto cleanup;
@@ -104,8 +104,8 @@ UA_Client_Subscriptions_forceDelete(UA_Client *client,
 UA_StatusCode
 UA_Client_Subscriptions_addMonitoredItem(UA_Client *client, UA_UInt32 subscriptionId,
                                          UA_NodeId nodeId, UA_UInt32 attributeID,
-                                         UA_MonitoredItemHandlingFunction hf,
-                                         void *hfContext, UA_UInt32 *newMonitoredItemId) {
+                                         UA_MonitoredItemHandlingFunction handlingFunction,
+                                         void *handlingContext, UA_UInt32 *newMonitoredItemId) {
     UA_Client_Subscription *sub;
     LIST_FOREACH(sub, &client->subscriptions, listEntry) {
         if(sub->SubscriptionID == subscriptionId)
@@ -143,7 +143,7 @@ UA_Client_Subscriptions_addMonitoredItem(UA_Client *client, UA_UInt32 subscripti
     }
 
     /* Create the handler */
-    UA_Client_MonitoredItem *newMon = UA_malloc(sizeof(UA_Client_MonitoredItem));
+    UA_Client_MonitoredItem *newMon = (UA_Client_MonitoredItem *)UA_malloc(sizeof(UA_Client_MonitoredItem));
     newMon->MonitoringMode = UA_MONITORINGMODE_REPORTING;
     UA_NodeId_copy(&nodeId, &newMon->monitoredNodeId);
     newMon->AttributeID = attributeID;
@@ -151,8 +151,8 @@ UA_Client_Subscriptions_addMonitoredItem(UA_Client *client, UA_UInt32 subscripti
     newMon->SamplingInterval = sub->PublishingInterval;
     newMon->QueueSize = 1;
     newMon->DiscardOldest = true;
-    newMon->handler = hf;
-    newMon->handlerContext = hfContext;
+    newMon->handler = handlingFunction;
+    newMon->handlerContext = handlingContext;
     newMon->MonitoredItemId = response.results[0].monitoredItemId;
     LIST_INSERT_HEAD(&sub->MonitoredItems, newMon, listEntry);
     *newMonitoredItemId = newMon->MonitoredItemId;
@@ -259,7 +259,7 @@ UA_Client_processPublishResponse(UA_Client *client, UA_PublishRequest *request,
         if(msg->notificationData[k].content.decoded.type != &UA_TYPES[UA_TYPES_DATACHANGENOTIFICATION])
             continue;
 
-        UA_DataChangeNotification *dataChangeNotification = msg->notificationData[k].content.decoded.data;
+        UA_DataChangeNotification *dataChangeNotification = (UA_DataChangeNotification *)msg->notificationData[k].content.decoded.data;
         for(size_t j = 0; j < dataChangeNotification->monitoredItemsSize; ++j) {
             UA_MonitoredItemNotification *mitemNot = &dataChangeNotification->monitoredItems[j];
             UA_Client_MonitoredItem *mon;
@@ -277,7 +277,7 @@ UA_Client_processPublishResponse(UA_Client *client, UA_PublishRequest *request,
     }
 
     /* Add to the list of pending acks */
-    UA_Client_NotificationsAckNumber *tmpAck = UA_malloc(sizeof(UA_Client_NotificationsAckNumber));
+    UA_Client_NotificationsAckNumber *tmpAck = (UA_Client_NotificationsAckNumber *)UA_malloc(sizeof(UA_Client_NotificationsAckNumber));
     tmpAck->subAck.sequenceNumber = msg->sequenceNumber;
     tmpAck->subAck.subscriptionId = sub->SubscriptionID;
     LIST_INSERT_HEAD(&client->pendingNotificationsAcks, tmpAck, listEntry);
@@ -299,7 +299,7 @@ UA_Client_Subscriptions_manuallySendPublishRequest(UA_Client *client) {
             ++request.subscriptionAcknowledgementsSize;
         if(request.subscriptionAcknowledgementsSize > 0) {
             request.subscriptionAcknowledgements =
-                UA_malloc(sizeof(UA_SubscriptionAcknowledgement) * request.subscriptionAcknowledgementsSize);
+                (UA_SubscriptionAcknowledgement *)UA_malloc(sizeof(UA_SubscriptionAcknowledgement) * request.subscriptionAcknowledgementsSize);
             if(!request.subscriptionAcknowledgements)
                 return UA_STATUSCODE_GOOD;
         }

+ 10 - 10
src/server/ua_nodestore.c

@@ -78,7 +78,7 @@ instantiateEntry(UA_NodeClass nodeClass) {
     default:
         return NULL;
     }
-    UA_NodeStoreEntry *entry = UA_calloc(1, size);
+    UA_NodeStoreEntry *entry = (UA_NodeStoreEntry *)UA_calloc(1, size);
     if(!entry)
         return NULL;
     entry->node.nodeClass = nodeClass;
@@ -152,7 +152,7 @@ expand(UA_NodeStore *ns) {
     UA_NodeStoreEntry **oentries = ns->entries;
     UA_UInt32 nindex = higher_prime_index(count * 2);
     UA_UInt32 nsize = primes[nindex];
-    UA_NodeStoreEntry **nentries = UA_calloc(nsize, sizeof(UA_NodeStoreEntry*));
+    UA_NodeStoreEntry **nentries = (UA_NodeStoreEntry **)UA_calloc(nsize, sizeof(UA_NodeStoreEntry*));
     if(!nentries)
         return UA_STATUSCODE_BADOUTOFMEMORY;
 
@@ -179,13 +179,13 @@ expand(UA_NodeStore *ns) {
 
 UA_NodeStore *
 UA_NodeStore_new(void) {
-    UA_NodeStore *ns = UA_malloc(sizeof(UA_NodeStore));
+    UA_NodeStore *ns = (UA_NodeStore *)UA_malloc(sizeof(UA_NodeStore));
     if(!ns)
         return NULL;
     ns->sizePrimeIndex = higher_prime_index(UA_NODESTORE_MINSIZE);
     ns->size = primes[ns->sizePrimeIndex];
     ns->count = 0;
-    ns->entries = UA_calloc(ns->size, sizeof(UA_NodeStoreEntry*));
+    ns->entries = (UA_NodeStoreEntry **)UA_calloc(ns->size, sizeof(UA_NodeStoreEntry*));
     if(!ns->entries) {
         UA_free(ns);
         return NULL;
@@ -290,15 +290,15 @@ UA_NodeStore_getCopy(UA_NodeStore *ns, const UA_NodeId *nodeid) {
     if(!slot)
         return NULL;
     UA_NodeStoreEntry *entry = *slot;
-    UA_NodeStoreEntry *new = instantiateEntry(entry->node.nodeClass);
-    if(!new)
+    UA_NodeStoreEntry *newItem = instantiateEntry(entry->node.nodeClass);
+    if(!newItem)
         return NULL;
-    if(UA_Node_copyAnyNodeClass(&entry->node, &new->node) != UA_STATUSCODE_GOOD) {
-        deleteEntry(new);
+    if(UA_Node_copyAnyNodeClass(&entry->node, &newItem->node) != UA_STATUSCODE_GOOD) {
+        deleteEntry(newItem);
         return NULL;
     }
-    new->orig = entry; // store the pointer to the original
-    return &new->node;
+    newItem->orig = entry; // store the pointer to the original
+    return &newItem->node;
 }
 
 UA_StatusCode

+ 1 - 1
src/server/ua_securechannel_manager.c

@@ -79,7 +79,7 @@ UA_SecureChannelManager_open(UA_SecureChannelManager *cm, UA_Connection *conn,
     }
 
     /* Set up the channel */
-    channel_list_entry *entry = UA_malloc(sizeof(channel_list_entry));
+    channel_list_entry *entry = (channel_list_entry*)UA_malloc(sizeof(channel_list_entry));
     if(!entry)
         return UA_STATUSCODE_BADOUTOFMEMORY;
     UA_SecureChannel_init(&entry->channel);

+ 47 - 51
src/server/ua_server.c

@@ -26,24 +26,18 @@ UA_THREAD_LOCAL bool rcu_locked = false;
 #if defined(UA_ENABLE_METHODCALLS) && defined(UA_ENABLE_SUBSCRIPTIONS)
 UA_THREAD_LOCAL UA_Session* methodCallSession = NULL;
 #endif
-
 static const UA_NodeId nodeIdHasSubType = {
-    .namespaceIndex = 0, .identifierType = UA_NODEIDTYPE_NUMERIC,
-    .identifier.numeric = UA_NS0ID_HASSUBTYPE};
+    0,UA_NODEIDTYPE_NUMERIC,{UA_NS0ID_HASSUBTYPE}};
 static const UA_NodeId nodeIdHasComponent = {
-    .namespaceIndex = 0, .identifierType = UA_NODEIDTYPE_NUMERIC,
-    .identifier.numeric = UA_NS0ID_HASCOMPONENT};
+    0,UA_NODEIDTYPE_NUMERIC,{UA_NS0ID_HASCOMPONENT}};
 static const UA_NodeId nodeIdHasProperty = {
-    .namespaceIndex = 0, .identifierType = UA_NODEIDTYPE_NUMERIC,
-    .identifier.numeric = UA_NS0ID_HASPROPERTY};
+    0,UA_NODEIDTYPE_NUMERIC,{UA_NS0ID_HASPROPERTY}};
 static const UA_NodeId nodeIdOrganizes = {
-    .namespaceIndex = 0, .identifierType = UA_NODEIDTYPE_NUMERIC,
-    .identifier.numeric = UA_NS0ID_ORGANIZES};
+    0,UA_NODEIDTYPE_NUMERIC,{UA_NS0ID_ORGANIZES}};
 
 #ifndef UA_ENABLE_GENERATE_NAMESPACE0
 static const UA_NodeId nodeIdNonHierarchicalReferences = {
-        .namespaceIndex = 0, .identifierType = UA_NODEIDTYPE_NUMERIC,
-        .identifier.numeric = UA_NS0ID_NONHIERARCHICALREFERENCES};
+    0,UA_NODEIDTYPE_NUMERIC,{UA_NS0ID_NONHIERARCHICALREFERENCES}};
 #endif
 
 /**********************/
@@ -58,7 +52,7 @@ UA_UInt16 addNamespace(UA_Server *server, const UA_String name) {
     }
 
     /* Make the array bigger */
-    UA_String *newNS = UA_realloc(server->namespaces,
+    UA_String *newNS = (UA_String*)UA_realloc(server->namespaces,
                                   sizeof(UA_String) * (server->namespacesSize + 1));
     if(!newNS)
         return 0;
@@ -76,8 +70,9 @@ UA_UInt16 addNamespace(UA_Server *server, const UA_String name) {
 
 UA_UInt16 UA_Server_addNamespace(UA_Server *server, const char* name) {
     /* Override const attribute to get string (dirty hack) */
-    const UA_String nameString = {.length = strlen(name),
-                                  .data = (UA_Byte*)(uintptr_t)name};
+    UA_String nameString;
+    nameString.length = strlen(name);
+    nameString.data = (UA_Byte*)(uintptr_t)name;
     return addNamespace(server, nameString);
 }
 
@@ -109,6 +104,12 @@ UA_Server_addExternalNamespace(UA_Server *server, const UA_String *url,
     if(!nodeStore)
         return UA_STATUSCODE_BADARGUMENTSMISSING;
 
+    char urlString[256];
+    if(url->length >= 256)
+        return UA_STATUSCODE_BADINTERNALERROR;
+    memcpy(urlString, url->data, url->length);
+    urlString[url->length] = 0;
+
     size_t size = server->externalNamespacesSize;
     server->externalNamespaces =
         UA_realloc(server->externalNamespaces, sizeof(UA_ExternalNamespace) * (size + 1));
@@ -383,7 +384,7 @@ writeNamespaces(void *handle, const UA_NodeId nodeid, const UA_Variant *data,
     if(range)
         return UA_STATUSCODE_BADINTERNALERROR;
 
-    UA_String *newNamespaces = data->data;
+    UA_String *newNamespaces = (UA_String*)data->data;
     size_t newNamespacesSize = data->arrayLength;
 
     /* Test if we append to the existing namespaces */
@@ -481,8 +482,8 @@ GetMonitoredItems(void *handle, const UA_NodeId *objectId,
     if(sizeOfOutput==0)
         return UA_STATUSCODE_GOOD;
 
-    UA_UInt32* clientHandles = UA_Array_new(sizeOfOutput, &UA_TYPES[UA_TYPES_UINT32]);
-    UA_UInt32* serverHandles = UA_Array_new(sizeOfOutput, &UA_TYPES[UA_TYPES_UINT32]);
+    UA_UInt32* clientHandles = (UA_UInt32 *)UA_Array_new(sizeOfOutput, &UA_TYPES[UA_TYPES_UINT32]);
+    UA_UInt32* serverHandles = (UA_UInt32 *)UA_Array_new(sizeOfOutput, &UA_TYPES[UA_TYPES_UINT32]);
     UA_UInt32 i = 0;
     LIST_FOREACH(monitoredItem, &subscription->monitoredItems, listEntry) {
         clientHandles[i] = monitoredItem->clientHandle;
@@ -496,7 +497,7 @@ GetMonitoredItems(void *handle, const UA_NodeId *objectId,
 #endif
 
 UA_Server * UA_Server_new(const UA_ServerConfig config) {
-    UA_Server *server = UA_calloc(1, sizeof(UA_Server));
+    UA_Server *server = (UA_Server *)UA_calloc(1, sizeof(UA_Server));
     if(!server)
         return NULL;
 
@@ -517,13 +518,13 @@ UA_Server * UA_Server_new(const UA_ServerConfig config) {
 #endif
 
     /* ns0 and ns1 */
-    server->namespaces = UA_Array_new(2, &UA_TYPES[UA_TYPES_STRING]);
+    server->namespaces = (UA_String *)UA_Array_new(2, &UA_TYPES[UA_TYPES_STRING]);
     server->namespaces[0] = UA_STRING_ALLOC("http://opcfoundation.org/UA/");
     UA_String_copy(&server->config.applicationDescription.applicationUri, &server->namespaces[1]);
     server->namespacesSize = 2;
 
     /* Create endpoints w/o endpointurl. It is added from the networklayers at startup */
-    server->endpointDescriptions = UA_Array_new(server->config.networkLayersSize,
+    server->endpointDescriptions = (UA_EndpointDescription *)UA_Array_new(server->config.networkLayersSize,
                                                 &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]);
     server->endpointDescriptionsSize = server->config.networkLayersSize;
     for(size_t i = 0; i < server->config.networkLayersSize; ++i) {
@@ -540,7 +541,7 @@ UA_Server * UA_Server_new(const UA_ServerConfig config) {
         if(server->config.accessControl.enableUsernamePasswordLogin)
             ++policies;
         endpoint->userIdentityTokensSize = policies;
-        endpoint->userIdentityTokens = UA_Array_new(policies, &UA_TYPES[UA_TYPES_USERTOKENPOLICY]);
+        endpoint->userIdentityTokens = (UA_UserTokenPolicy *)UA_Array_new(policies, &UA_TYPES[UA_TYPES_USERTOKENPOLICY]);
 
         size_t currentIndex = 0;
         if(server->config.accessControl.enableAnonymousLogin) {
@@ -568,8 +569,10 @@ UA_Server * UA_Server_new(const UA_ServerConfig config) {
     UA_SecureChannelManager_init(&server->secureChannelManager, server);
     UA_SessionManager_init(&server->sessionManager, server);
 
-    UA_Job cleanup = {.type = UA_JOBTYPE_METHODCALL,
-                      .job.methodCall = {.method = UA_Server_cleanup, .data = NULL} };
+   UA_Job cleanup;
+   cleanup.type = UA_JOBTYPE_METHODCALL; 
+   cleanup.job.methodCall.data = NULL;
+   cleanup.job.methodCall.method = UA_Server_cleanup;
     UA_Server_addRepeatedJob(server, cleanup, 10000, NULL);
 
 #ifdef UA_ENABLE_DISCOVERY
@@ -891,14 +894,8 @@ UA_Server * UA_Server_new(const UA_ServerConfig config) {
     /******************/
     /* Root and below */
     /******************/
-
-    static const UA_NodeId nodeIdFolderType = {
-        .namespaceIndex = 0, .identifierType = UA_NODEIDTYPE_NUMERIC,
-        .identifier.numeric = UA_NS0ID_FOLDERTYPE};
-    static const UA_NodeId nodeIdHasTypeDefinition = {
-        .namespaceIndex = 0, .identifierType = UA_NODEIDTYPE_NUMERIC,
-        .identifier.numeric = UA_NS0ID_HASTYPEDEFINITION};
-
+    const UA_NodeId nodeIdFolderType = UA_NODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE);
+    const UA_NodeId nodeIdHasTypeDefinition = UA_NODEID_NUMERIC(0, UA_NS0ID_HASTYPEDEFINITION);
     UA_ObjectNode *root = UA_NodeStore_newObjectNode();
     copyNames((UA_Node*)root, "Root");
     root->nodeId.identifier.numeric = UA_NS0ID_ROOTFOLDER;
@@ -990,8 +987,9 @@ UA_Server * UA_Server_new(const UA_ServerConfig config) {
     copyNames((UA_Node*)namespaceArray, "NamespaceArray");
     namespaceArray->nodeId.identifier.numeric = UA_NS0ID_SERVER_NAMESPACEARRAY;
     namespaceArray->valueSource = UA_VALUESOURCE_DATASOURCE;
-    namespaceArray->value.dataSource = (UA_DataSource) {.handle = server, .read = readNamespaces,
-                                                        .write = writeNamespaces};
+    namespaceArray->value.dataSource.handle = server;
+    namespaceArray->value.dataSource.read = readNamespaces;
+    namespaceArray->value.dataSource.write = writeNamespaces;
     namespaceArray->dataType = UA_TYPES[UA_TYPES_STRING].typeId;
     namespaceArray->valueRank = 1;
     namespaceArray->minimumSamplingInterval = 1.0;
@@ -1153,8 +1151,9 @@ UA_Server * UA_Server_new(const UA_ServerConfig config) {
     copyNames((UA_Node*)serverstatus, "ServerStatus");
     serverstatus->nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS);
     serverstatus->valueSource = UA_VALUESOURCE_DATASOURCE;
-    serverstatus->value.dataSource = (UA_DataSource) {.handle = server, .read = readStatus,
-                                                      .write = NULL};
+    serverstatus->value.dataSource.handle = server;
+    serverstatus->value.dataSource.read = readStatus;
+    serverstatus->value.dataSource.write = NULL;
     addNodeInternalWithType(server, (UA_Node*)serverstatus, UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER),
                             nodeIdHasComponent, UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATAVARIABLETYPE));
 
@@ -1172,8 +1171,9 @@ UA_Server * UA_Server_new(const UA_ServerConfig config) {
     copyNames((UA_Node*)currenttime, "CurrentTime");
     currenttime->nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS_CURRENTTIME);
     currenttime->valueSource = UA_VALUESOURCE_DATASOURCE;
-    currenttime->value.dataSource = (UA_DataSource) {.handle = NULL, .read = readCurrentTime,
-                                                     .write = NULL};
+    currenttime->value.dataSource.handle = NULL;
+    currenttime->value.dataSource.read = readCurrentTime;
+    currenttime->value.dataSource.write = NULL;
     addNodeInternalWithType(server, (UA_Node*)currenttime,
                             UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVERSTATUS),
                             nodeIdHasComponent, UA_NODEID_NUMERIC(0, UA_NS0ID_BASEDATAVARIABLETYPE));
@@ -1283,8 +1283,9 @@ UA_Server * UA_Server_new(const UA_ServerConfig config) {
     copyNames((UA_Node*)servicelevel, "ServiceLevel");
     servicelevel->nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_SERVICELEVEL);
     servicelevel->valueSource = UA_VALUESOURCE_DATASOURCE;
-    servicelevel->value.dataSource = (UA_DataSource) {.handle = server, .read = readServiceLevel,
-                                                      .write = NULL};
+    servicelevel->value.dataSource.handle = server;
+    servicelevel->value.dataSource.read = readServiceLevel;
+    servicelevel->value.dataSource.write = NULL;
     addNodeInternalWithType(server, (UA_Node*)servicelevel,
                             UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER), nodeIdHasComponent,
                             UA_NODEID_NUMERIC(0, UA_NS0ID_PROPERTYTYPE));
@@ -1293,7 +1294,9 @@ UA_Server * UA_Server_new(const UA_ServerConfig config) {
     copyNames((UA_Node*)auditing, "Auditing");
     auditing->nodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER_AUDITING);
     auditing->valueSource = UA_VALUESOURCE_DATASOURCE;
-    auditing->value.dataSource = (UA_DataSource) {.handle = server, .read = readAuditing, .write = NULL};
+    auditing->value.dataSource.handle = server;
+    auditing->value.dataSource.read = readAuditing;
+    auditing->value.dataSource.write = NULL;
     addNodeInternalWithType(server, (UA_Node*)auditing,
                             UA_NODEID_NUMERIC(0, UA_NS0ID_SERVER), nodeIdHasComponent,
                             UA_NODEID_NUMERIC(0, UA_NS0ID_PROPERTYTYPE));
@@ -1390,7 +1393,7 @@ static UA_StatusCode register_server_with_discovery_server(UA_Server *server, co
     retval |= UA_String_copy(&server->config.applicationDescription.productUri, &request.server.productUri);
 
     request.server.serverNamesSize = 1;
-    request.server.serverNames = UA_malloc(sizeof(UA_LocalizedText));
+    request.server.serverNames = (UA_LocalizedText *)UA_malloc(sizeof(UA_LocalizedText));
     if (!request.server.serverNames) {
         UA_Client_disconnect(client);
         UA_Client_delete(client);
@@ -1402,27 +1405,20 @@ static UA_StatusCode register_server_with_discovery_server(UA_Server *server, co
     retval |= UA_String_copy(&server->config.applicationDescription.gatewayServerUri, &request.server.gatewayServerUri);
     // TODO where do we get the discoveryProfileUri for application data?
 
-    request.server.discoveryUrls = UA_malloc(sizeof(UA_String) * server->config.applicationDescription.discoveryUrlsSize);
+    request.server.discoveryUrls = (UA_String *)UA_malloc(sizeof(UA_String) * server->config.applicationDescription.discoveryUrlsSize);
     if (!request.server.serverNames) {
         UA_RegisteredServer_deleteMembers(&request.server);
         UA_Client_disconnect(client);
         UA_Client_delete(client);
         return UA_STATUSCODE_BADOUTOFMEMORY;
     }
-
     for (size_t i = 0; i<server->config.applicationDescription.discoveryUrlsSize; i++) {
         retval |= UA_String_copy(&server->config.applicationDescription.discoveryUrls[i], &request.server.discoveryUrls[i]);
     }
-    if(retval != UA_STATUSCODE_GOOD) {
-        UA_RegisteredServer_deleteMembers(&request.server);
-        UA_Client_disconnect(client);
-        UA_Client_delete(client);
-        return UA_STATUSCODE_BADOUTOFMEMORY;
-    }
 
     /* add the discoveryUrls from the networklayers */
-    UA_String *disc = UA_realloc(request.server.discoveryUrls,
-                                 sizeof(UA_String) * (request.server.discoveryUrlsSize + server->config.networkLayersSize));
+    UA_String *disc = (UA_String *)UA_realloc(request.server.discoveryUrls, sizeof(UA_String) *
+                                                                           (request.server.discoveryUrlsSize + server->config.networkLayersSize));
     if(!disc) {
         UA_RegisteredServer_deleteMembers(&request.server);
         UA_Client_disconnect(client);

+ 11 - 5
src/server/ua_server_binary.c

@@ -408,7 +408,9 @@ processMSG(UA_Server *server, UA_SecureChannel *channel,
 
     /* CreateSession doesn't need a session */
     if(requestType == &UA_TYPES[UA_TYPES_CREATESESSIONREQUEST]) {
-        Service_CreateSession(server, channel, request, response);
+        Service_CreateSession(server, channel,
+			                  (const UA_CreateSessionRequest *)request,
+							  (UA_CreateSessionResponse *)response);
         goto send_response;
     }
 
@@ -428,7 +430,9 @@ processMSG(UA_Server *server, UA_SecureChannel *channel,
             UA_deleteMembers(request, requestType);
             return;
         }
-        Service_ActivateSession(server, channel, session, request, response);
+        Service_ActivateSession(server, channel, session,
+			                    (const UA_ActivateSessionRequest*)request,
+								(UA_ActivateSessionResponse*)response);
         goto send_response;
     }
 
@@ -479,7 +483,8 @@ processMSG(UA_Server *server, UA_SecureChannel *channel,
 #ifdef UA_ENABLE_SUBSCRIPTIONS
     /* The publish request is not answered immediately */
     if(requestType == &UA_TYPES[UA_TYPES_PUBLISHREQUEST]) {
-        Service_Publish(server, session, request, requestId);
+        Service_Publish(server, session,
+			            (const UA_PublishRequest*)request, requestId);
         UA_deleteMembers(request, requestType);
         return;
     }
@@ -574,8 +579,9 @@ UA_Server_processBinaryMessage(UA_Server *server, UA_Connection *connection,
             retval = UA_UInt32_decodeBinary(message, &offset, &channelId);
             if(retval != UA_STATUSCODE_GOOD)
                 connection->close(connection);
-            UA_ByteString offsetMessage = (UA_ByteString){
-                .data = message->data + 12, .length = message->length - 12};
+            UA_ByteString offsetMessage;
+			offsetMessage.data = message->data + 12;
+			offsetMessage.length = message->length - 12;
             processOPN(server, connection, channelId, &offsetMessage);
             break; }
         case UA_MESSAGETYPE_MSG:

+ 10 - 10
src/server/ua_server_utils.c

@@ -38,7 +38,7 @@ parse_numericrange(const UA_String *str, UA_NumericRange *range) {
         if(idx >= dimensionsMax) {
             UA_NumericRangeDimension *newds;
             size_t newdssize = sizeof(UA_NumericRangeDimension) * (dimensionsMax + 2);
-            newds = UA_realloc(dimensions, newdssize);
+            newds = (UA_NumericRangeDimension*)UA_realloc(dimensions, newdssize);
             if(!newds) {
                 retval = UA_STATUSCODE_BADOUTOFMEMORY;
                 break;
@@ -85,7 +85,7 @@ UA_StatusCode
 getTypeHierarchy(UA_NodeStore *ns, const UA_Node *rootRef, UA_Boolean inverse,
                  UA_NodeId **typeHierarchy, size_t *typeHierarchySize) {
     size_t results_size = 20; // probably too big, but saves mallocs
-    UA_NodeId *results = UA_malloc(sizeof(UA_NodeId) * results_size);
+    UA_NodeId *results = (UA_NodeId*)UA_malloc(sizeof(UA_NodeId) * results_size);
     if(!results)
         return UA_STATUSCODE_BADOUTOFMEMORY;
 
@@ -119,14 +119,14 @@ getTypeHierarchy(UA_NodeStore *ns, const UA_Node *rootRef, UA_Boolean inverse,
 
             /* increase array length if necessary */
             if(last + 1 >= results_size) {
-                                UA_NodeId *new_results =
-                                    UA_realloc(results, sizeof(UA_NodeId) * results_size * 2);
-                                if(!new_results) {
-                                    retval = UA_STATUSCODE_BADOUTOFMEMORY;
-                                    break;
-                                }
-                                results = new_results;
-                                results_size *= 2;
+                UA_NodeId *new_results =
+                    (UA_NodeId*)UA_realloc(results, sizeof(UA_NodeId) * results_size * 2);
+                if(!new_results) {
+                    retval = UA_STATUSCODE_BADOUTOFMEMORY;
+                    break;
+                }
+                results = new_results;
+                results_size *= 2;
             }
 
             /* copy new nodeid to the end of the list */

+ 4 - 2
src/server/ua_server_worker.c

@@ -49,10 +49,12 @@ processJob(UA_Server *server, UA_Job *job) {
         UA_Connection_detachSecureChannel(job->job.closeConnection);
         break;
     case UA_JOBTYPE_BINARYMESSAGE_NETWORKLAYER:
+        {
         UA_Server_processBinaryMessage(server, job->job.binaryMessage.connection,
                                        &job->job.binaryMessage.message);
         UA_Connection *connection = job->job.binaryMessage.connection;
         connection->releaseRecvBuffer(connection, &job->job.binaryMessage.message);
+        }
         break;
     case UA_JOBTYPE_BINARYMESSAGE_ALLOCATED:
         UA_Server_processBinaryMessage(server, job->job.binaryMessage.connection,
@@ -196,7 +198,7 @@ UA_Server_addRepeatedJob(UA_Server *server, UA_Job job,
         (UA_UInt64)interval * (UA_UInt64)UA_MSEC_TO_DATETIME; // from ms to 100ns resolution
 
     /* Create and fill the repeated job structure */
-    struct RepeatedJob *rj = UA_malloc(sizeof(struct RepeatedJob));
+    struct RepeatedJob *rj = (struct RepeatedJob *)UA_malloc(sizeof(struct RepeatedJob));
     if(!rj)
         return UA_STATUSCODE_BADOUTOFMEMORY;
     /* done inside addRepeatedJob:
@@ -368,7 +370,7 @@ typedef struct UA_DelayedJob {
 
 UA_StatusCode
 UA_Server_delayedCallback(UA_Server *server, UA_ServerCallback callback, void *data) {
-    UA_DelayedJob *dj = UA_malloc(sizeof(UA_DelayedJob));
+    UA_DelayedJob *dj = (UA_DelayedJob *)UA_malloc(sizeof(UA_DelayedJob));
     if(!dj)
         return UA_STATUSCODE_BADOUTOFMEMORY;
     dj->job.type = UA_JOBTYPE_METHODCALL;

+ 12 - 11
src/server/ua_services_attribute.c

@@ -175,9 +175,11 @@ typeCheckValue(UA_Server *server, const UA_NodeId *targetDataTypeId,
                UA_Int32 targetValueRank, size_t targetArrayDimensionsSize,
                const UA_UInt32 *targetArrayDimensions, const UA_Variant *value,
                const UA_NumericRange *range, UA_Variant *editableValue) {
-    /* Empty variant is only allowed for BaseDataType */
+    const UA_NodeId subtypeId = UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE);
+   
+	/* Empty variant always matches... */
     if(!value->type)
-        goto check_array;
+        return UA_STATUSCODE_GOOD;
 
     /* See if the types match. The nodeid on the wire may be != the nodeid in
      * the node for opaque types, enums and bytestrings. value contains the
@@ -186,7 +188,6 @@ typeCheckValue(UA_Server *server, const UA_NodeId *targetDataTypeId,
         goto check_array;
 
     /* Has the value a subtype of the required type? */
-    const UA_NodeId subtypeId = UA_NODEID_NUMERIC(0, UA_NS0ID_HASSUBTYPE);
     if(isNodeInTree(server->nodestore, &value->type->typeId, targetDataTypeId, &subtypeId, 1))
         goto check_array;
 
@@ -831,7 +832,7 @@ void Service_Read(UA_Server *server, UA_Session *session,
     }
 
     size_t size = request->nodesToReadSize;
-    response->results = UA_Array_new(size, &UA_TYPES[UA_TYPES_DATAVALUE]);
+    response->results = (UA_DataValue *)UA_Array_new(size, &UA_TYPES[UA_TYPES_DATAVALUE]);
     if(!response->results) {
         response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
         return;
@@ -955,7 +956,7 @@ __UA_Server_read(UA_Server *server, const UA_NodeId *nodeId,
        attributeId == UA_ATTRIBUTEID_ARRAYDIMENSIONS) {
         /* Return the entire variant */
         if(dv.value.storageType == UA_VARIANT_DATA_NODELETE) {
-            retval = UA_Variant_copy(&dv.value, v);
+            retval = UA_Variant_copy(&dv.value,(UA_Variant *) v);
         } else {
             /* storageType is UA_VARIANT_DATA. Copy the entire variant
              * (including pointers and all) */
@@ -1029,19 +1030,19 @@ CopyAttributeIntoNode(UA_Server *server, UA_Session *session,
         CHECK_USERWRITEMASK(2);
         CHECK_DATATYPE_SCALAR(QUALIFIEDNAME);
         UA_QualifiedName_deleteMembers(&node->browseName);
-        UA_QualifiedName_copy(value, &node->browseName);
+        UA_QualifiedName_copy((const UA_QualifiedName *)value, &node->browseName);
         break;
     case UA_ATTRIBUTEID_DISPLAYNAME:
         CHECK_USERWRITEMASK(6);
         CHECK_DATATYPE_SCALAR(LOCALIZEDTEXT);
         UA_LocalizedText_deleteMembers(&node->displayName);
-        UA_LocalizedText_copy(value, &node->displayName);
+        UA_LocalizedText_copy((const UA_LocalizedText *)value, &node->displayName);
         break;
     case UA_ATTRIBUTEID_DESCRIPTION:
         CHECK_USERWRITEMASK(5);
         CHECK_DATATYPE_SCALAR(LOCALIZEDTEXT);
         UA_LocalizedText_deleteMembers(&node->description);
-        UA_LocalizedText_copy(value, &node->description);
+        UA_LocalizedText_copy((const UA_LocalizedText *)value, &node->description);
         break;
     case UA_ATTRIBUTEID_WRITEMASK:
         CHECK_USERWRITEMASK(20);
@@ -1064,7 +1065,7 @@ CopyAttributeIntoNode(UA_Server *server, UA_Session *session,
         CHECK_USERWRITEMASK(10);
         CHECK_DATATYPE_SCALAR(LOCALIZEDTEXT);
         UA_LocalizedText_deleteMembers(&((UA_ReferenceTypeNode*)node)->inverseName);
-        UA_LocalizedText_copy(value, &((UA_ReferenceTypeNode*)node)->inverseName);
+        UA_LocalizedText_copy((const UA_LocalizedText *)value, &((UA_ReferenceTypeNode*)node)->inverseName);
         break;
     case UA_ATTRIBUTEID_CONTAINSNOLOOPS:
         CHECK_NODECLASS_WRITE(UA_NODECLASS_VIEW);
@@ -1111,7 +1112,7 @@ CopyAttributeIntoNode(UA_Server *server, UA_Session *session,
         CHECK_DATATYPE_ARRAY(UINT32);
         retval = writeArrayDimensionsAttribute(server, (UA_VariableNode*)node,
                                                wvalue->value.value.arrayLength,
-                                               wvalue->value.value.data);
+                                               (UA_UInt32 *)wvalue->value.value.data);
         break;
     case UA_ATTRIBUTEID_ACCESSLEVEL:
         CHECK_NODECLASS_WRITE(UA_NODECLASS_VARIABLE);
@@ -1156,7 +1157,7 @@ Service_Write(UA_Server *server, UA_Session *session,
         return;
     }
 
-    response->results = UA_Array_new(request->nodesToWriteSize, &UA_TYPES[UA_TYPES_STATUSCODE]);
+    response->results = (UA_StatusCode *)UA_Array_new(request->nodesToWriteSize, &UA_TYPES[UA_TYPES_STATUSCODE]);
     if(!response->results) {
         response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
         return;

+ 2 - 2
src/server/ua_services_call.c

@@ -134,7 +134,7 @@ Service_Call_single(UA_Server *server, UA_Session *session,
     const UA_VariableNode *outputArguments =
         getArgumentsVariableNode(server, methodCalled, UA_STRING("OutputArguments"));
     if(outputArguments) {
-        result->outputArguments = UA_Array_new(outputArguments->value.data.value.value.arrayLength,
+        result->outputArguments = (UA_Variant*)UA_Array_new(outputArguments->value.data.value.value.arrayLength,
                                                &UA_TYPES[UA_TYPES_VARIANT]);
         if(!result->outputArguments) {
             result->statusCode = UA_STATUSCODE_BADOUTOFMEMORY;
@@ -167,7 +167,7 @@ void Service_Call(UA_Server *server, UA_Session *session,
         return;
     }
 
-    response->results = UA_Array_new(request->methodsToCallSize, &UA_TYPES[UA_TYPES_CALLMETHODRESULT]);
+    response->results = (UA_CallMethodResult*)UA_Array_new(request->methodsToCallSize, &UA_TYPES[UA_TYPES_CALLMETHODRESULT]);
     if(!response->results) {
         response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
         return;

+ 19 - 10
src/server/ua_services_discovery.c

@@ -4,8 +4,10 @@
 
 #ifdef UA_ENABLE_DISCOVERY
     #ifdef _MSC_VER
-    # include <io.h> //access
-    # define access _access
+      #ifndef UNDER_CE
+        # include <io.h> //access
+        # define access _access
+      #endif
     #else
     # include <unistd.h> //access
     #endif
@@ -43,7 +45,7 @@ static UA_StatusCode copyRegisteredServerToApplicationDescription(const UA_FindS
 
     target->discoveryUrlsSize = registeredServer->discoveryUrlsSize;
     if (registeredServer->discoveryUrlsSize) {
-        target->discoveryUrls = UA_malloc(sizeof(UA_String) * registeredServer->discoveryUrlsSize);
+        target->discoveryUrls = (UA_String *)UA_malloc(sizeof(UA_String) * registeredServer->discoveryUrlsSize);
         if (!target->discoveryUrls) {
             return UA_STATUSCODE_BADOUTOFMEMORY;
         }
@@ -71,7 +73,7 @@ void Service_FindServers(UA_Server *server, UA_Session *session,
     // check if client only requested a specific set of servers
     if (request->serverUrisSize) {
 
-        foundServerFilteredPointer = UA_malloc(sizeof(UA_RegisteredServer*) * server->registeredServersSize);
+        foundServerFilteredPointer = (UA_RegisteredServer **)UA_malloc(sizeof(UA_RegisteredServer*) * server->registeredServersSize);
         if(!foundServerFilteredPointer) {
             response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
             return;
@@ -116,7 +118,7 @@ void Service_FindServers(UA_Server *server, UA_Session *session,
 #endif
 
     if(foundServersSize) {
-        foundServers = UA_malloc(sizeof(UA_ApplicationDescription) * foundServersSize);
+        foundServers = (UA_ApplicationDescription *)UA_malloc(sizeof(UA_ApplicationDescription) * foundServersSize);
         if (!foundServers) {
             if (foundServerFilteredPointer)
                 UA_free(foundServerFilteredPointer);
@@ -136,7 +138,7 @@ void Service_FindServers(UA_Server *server, UA_Session *session,
             }
 
             /* add the discoveryUrls from the networklayers */
-            UA_String* disc = UA_realloc(foundServers[0].discoveryUrls,
+            UA_String* disc = (UA_String *)UA_realloc(foundServers[0].discoveryUrls,
                                          sizeof(UA_String) * (foundServers[0].discoveryUrlsSize +
                                                               server->config.networkLayersSize));
             if(!disc) {
@@ -217,7 +219,7 @@ void Service_GetEndpoints(UA_Server *server, UA_Session *session, const UA_GetEn
 #ifdef NO_ALLOCA
     UA_Boolean relevant_endpoints[server->endpointDescriptionsSize];
 #else
-    UA_Boolean *relevant_endpoints = UA_alloca(sizeof(UA_Boolean) * server->endpointDescriptionsSize);
+    UA_Boolean *relevant_endpoints = (UA_Boolean *)UA_alloca(sizeof(UA_Boolean) * server->endpointDescriptionsSize);
 #endif
     memset(relevant_endpoints, 0, sizeof(UA_Boolean) * server->endpointDescriptionsSize);
     size_t relevant_count = 0;
@@ -250,7 +252,7 @@ void Service_GetEndpoints(UA_Server *server, UA_Session *session, const UA_GetEn
         nl_endpointurl = true;
     }
 
-    response->endpoints = UA_Array_new(relevant_count * clone_times, &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]);
+    response->endpoints = (UA_EndpointDescription *)UA_Array_new(relevant_count * clone_times, &UA_TYPES[UA_TYPES_ENDPOINTDESCRIPTION]);
     if(!response->endpoints) {
         response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
         return;
@@ -329,7 +331,7 @@ void Service_RegisterServer(UA_Server *server, UA_Session *session,
 
         UA_LOG_DEBUG_SESSION(server->config.logger, session, "Registering new server: %.*s", (int)request->server.serverUri.length, request->server.serverUri.data);
 
-        registeredServer_entry = UA_malloc(sizeof(registeredServer_list_entry));
+        registeredServer_entry = (registeredServer_list_entry *)UA_malloc(sizeof(registeredServer_list_entry));
         if(!registeredServer_entry) {
             response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
             return;
@@ -373,10 +375,17 @@ void UA_Discovery_cleanupTimedOut(UA_Server *server, UA_DateTime nowMonotonic) {
         UA_Boolean semaphoreDeleted = UA_FALSE;
 
         if (current->registeredServer.semaphoreFilePath.length) {
-            char* filePath = malloc(sizeof(char)*current->registeredServer.semaphoreFilePath.length+1);
+            char* filePath = (char *)malloc(sizeof(char)*current->registeredServer.semaphoreFilePath.length+1);
             memcpy( filePath, current->registeredServer.semaphoreFilePath.data, current->registeredServer.semaphoreFilePath.length );
             filePath[current->registeredServer.semaphoreFilePath.length] = '\0';
+#ifdef UNDER_CE
+           FILE *fp = fopen(filePath,"rb");
+		   semaphoreDeleted = (fp==NULL);
+		   if (fp)
+		     fclose(fp);
+#else
             semaphoreDeleted = access( filePath, 0 ) == -1;
+#endif
             free(filePath);
         }
 

+ 20 - 20
src/server/ua_services_nodemanagement.c

@@ -648,35 +648,35 @@ createNodeFromAttributes(UA_Server *server, const UA_AddNodesItem *item, UA_Node
 
     /* Copy the attributes into the node */
     void *data = item->nodeAttributes.content.decoded.data;
-    UA_StatusCode retval = copyStandardAttributes(node, item, data);
+    UA_StatusCode retval = copyStandardAttributes((UA_Node *)node, item, (UA_NodeAttributes *)data);
     switch(item->nodeClass) {
     case UA_NODECLASS_OBJECT:
         CHECK_ATTRIBUTES(OBJECTATTRIBUTES);
-        retval |= copyObjectNodeAttributes(node, data);
+        retval |= copyObjectNodeAttributes((UA_ObjectNode *)node, (UA_ObjectAttributes *)data);
         break;
     case UA_NODECLASS_VARIABLE:
         CHECK_ATTRIBUTES(VARIABLEATTRIBUTES);
-        retval |= copyVariableNodeAttributes(server, node, item, data);
+        retval |= copyVariableNodeAttributes(server, (UA_VariableNode *)node, item, (UA_VariableAttributes *)data);
         break;
     case UA_NODECLASS_OBJECTTYPE:
         CHECK_ATTRIBUTES(OBJECTTYPEATTRIBUTES);
-        retval |= copyObjectTypeNodeAttributes(node, data);
+        retval |= copyObjectTypeNodeAttributes((UA_ObjectTypeNode *)node, (UA_ObjectTypeAttributes *)data);
         break;
     case UA_NODECLASS_VARIABLETYPE:
         CHECK_ATTRIBUTES(VARIABLETYPEATTRIBUTES);
-        retval |= copyVariableTypeNodeAttributes(server, node, item, data);
+        retval |= copyVariableTypeNodeAttributes(server,(UA_VariableTypeNode *)node, item, (UA_VariableTypeAttributes *)data);
         break;
     case UA_NODECLASS_REFERENCETYPE:
         CHECK_ATTRIBUTES(REFERENCETYPEATTRIBUTES);
-        retval |= copyReferenceTypeNodeAttributes(node, data);
+        retval |= copyReferenceTypeNodeAttributes((UA_ReferenceTypeNode *)node,(const UA_ReferenceTypeAttributes *)data);
         break;
     case UA_NODECLASS_DATATYPE:
         CHECK_ATTRIBUTES(DATATYPEATTRIBUTES);
-        retval |= copyDataTypeNodeAttributes(node, data);
+        retval |= copyDataTypeNodeAttributes((UA_DataTypeNode *)node, (UA_DataTypeAttributes *)data);
         break;
     case UA_NODECLASS_VIEW:
         CHECK_ATTRIBUTES(VIEWATTRIBUTES);
-        retval |= copyViewNodeAttributes(node, data);
+        retval |= copyViewNodeAttributes((UA_ViewNode *)node, (const UA_ViewAttributes *)data);
         break;
     case UA_NODECLASS_METHOD:
     case UA_NODECLASS_UNSPECIFIED:
@@ -685,9 +685,9 @@ createNodeFromAttributes(UA_Server *server, const UA_AddNodesItem *item, UA_Node
     }
 
     if(retval == UA_STATUSCODE_GOOD)
-        *newNode = node;
+        *newNode = (UA_Node*)node;
     else
-        UA_NodeStore_deleteNode(node);
+        UA_NodeStore_deleteNode((UA_Node*)node);
     return retval;
 }
 
@@ -718,7 +718,7 @@ void Service_AddNodes(UA_Server *server, UA_Session *session,
     }
     size_t size = request->nodesToAddSize;
 
-    response->results = UA_Array_new(size, &UA_TYPES[UA_TYPES_ADDNODESRESULT]);
+    response->results = (UA_AddNodesResult *)UA_Array_new(size, &UA_TYPES[UA_TYPES_ADDNODESRESULT]);
     if(!response->results) {
         response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
         return;
@@ -778,9 +778,9 @@ __UA_Server_addNode(UA_Server *server, const UA_NodeClass nodeClass,
     item.browseName = browseName;
     item.nodeClass = nodeClass;
     item.typeDefinition.nodeId = typeDefinition;
-    item.nodeAttributes = (UA_ExtensionObject){
-        .encoding = UA_EXTENSIONOBJECT_DECODED_NODELETE,
-        .content.decoded = {attributeType, (void*)(uintptr_t)attr}};
+    item.nodeAttributes.encoding = UA_EXTENSIONOBJECT_DECODED_NODELETE;
+    item.nodeAttributes.content.decoded.type = attributeType;
+    item.nodeAttributes.content.decoded.data = (void*)(uintptr_t)attr;
 
     /* run the service */
     UA_AddNodesResult result;
@@ -974,7 +974,7 @@ addOneWayReference(UA_Server *server, UA_Session *session,
                    UA_Node *node, const UA_AddReferencesItem *item) {
     size_t i = node->referencesSize;
     size_t refssize = (i+1) | 3; // so the realloc is not necessary every time
-    UA_ReferenceNode *new_refs = UA_realloc(node->references, sizeof(UA_ReferenceNode) * refssize);
+    UA_ReferenceNode *new_refs = (UA_ReferenceNode *)UA_realloc(node->references, sizeof(UA_ReferenceNode) * refssize);
     if(!new_refs)
         return UA_STATUSCODE_BADOUTOFMEMORY;
     node->references = new_refs;
@@ -1009,7 +1009,7 @@ Service_AddReferences_single(UA_Server *server, UA_Session *session,
             continue;
         } else {
             UA_ExternalNodeStore *ens = &server->externalNamespaces[j].externalNodeStore;
-            retval = (UA_StatusCode)ens->addOneWayReference(ens->ensHandle, item);
+            retval = ens->addOneWayReference(ens->ensHandle, item);
             handledExternally = UA_TRUE;
             break;
         }
@@ -1075,7 +1075,7 @@ void Service_AddReferences(UA_Server *server, UA_Session *session,
         return;
     }
 
-    response->results = UA_malloc(sizeof(UA_StatusCode) * request->referencesToAddSize);
+    response->results = (UA_StatusCode *)UA_malloc(sizeof(UA_StatusCode) * request->referencesToAddSize);
     if(!response->results) {
         response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
         return;
@@ -1192,7 +1192,7 @@ void Service_DeleteNodes(UA_Server *server, UA_Session *session,
         return;
     }
 
-    response->results = UA_malloc(sizeof(UA_StatusCode) * request->nodesToDeleteSize);
+    response->results = (UA_StatusCode *)UA_malloc(sizeof(UA_StatusCode) * request->nodesToDeleteSize);
     if(!response->results) {
         response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;;
         return;
@@ -1280,7 +1280,7 @@ Service_DeleteReferences(UA_Server *server, UA_Session *session,
         return;
     }
 
-    response->results = UA_malloc(sizeof(UA_StatusCode) * request->referencesToDeleteSize);
+    response->results = (UA_StatusCode *)UA_malloc(sizeof(UA_StatusCode) * request->referencesToDeleteSize);
     if(!response->results) {
         response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;;
         return;
@@ -1397,7 +1397,7 @@ editMethodCallback(UA_Server *server, UA_Session* session,
                    UA_Node* node, const void* handle) {
     if(node->nodeClass != UA_NODECLASS_METHOD)
         return UA_STATUSCODE_BADNODECLASSINVALID;
-    const struct addMethodCallback *newCallback = handle;
+    const struct addMethodCallback *newCallback = (const struct addMethodCallback *)handle;
     UA_MethodNode *mnode = (UA_MethodNode*) node;
     mnode->attachedMethod = newCallback->callback;
     mnode->methodHandle   = newCallback->handle;

+ 9 - 9
src/server/ua_services_subscription.c

@@ -116,7 +116,7 @@ Service_SetPublishingMode(UA_Server *server, UA_Session *session,
     }
 
     size_t size = request->subscriptionIdsSize;
-    response->results = UA_Array_new(size, &UA_TYPES[UA_TYPES_STATUSCODE]);
+    response->results = (UA_StatusCode *)UA_Array_new(size, &UA_TYPES[UA_TYPES_STATUSCODE]);
     if(!response->results) {
         response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
         return;
@@ -171,7 +171,7 @@ setMonitoredItemSettings(UA_Server *server, UA_MonitoredItem *mon,
         /* Default: Trigger only on the value and the statuscode */
         mon->trigger = UA_DATACHANGETRIGGER_STATUSVALUE;
     } else {
-        UA_DataChangeFilter *filter = params->filter.content.decoded.data;
+        UA_DataChangeFilter *filter = (UA_DataChangeFilter *)params->filter.content.decoded.data;
         mon->trigger = filter->trigger;
     }
 
@@ -284,7 +284,7 @@ Service_CreateMonitoredItems(UA_Server *server, UA_Session *session,
         return;
     }
 
-    response->results = UA_Array_new(request->itemsToCreateSize,
+    response->results = (UA_MonitoredItemCreateResult *)UA_Array_new(request->itemsToCreateSize,
                                      &UA_TYPES[UA_TYPES_MONITOREDITEMCREATERESULT]);
     if(!response->results) {
         response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
@@ -339,7 +339,7 @@ void Service_ModifyMonitoredItems(UA_Server *server, UA_Session *session,
         return;
     }
 
-    response->results = UA_Array_new(request->itemsToModifySize,
+    response->results = (UA_MonitoredItemModifyResult *)UA_Array_new(request->itemsToModifySize,
                                      &UA_TYPES[UA_TYPES_MONITOREDITEMMODIFYRESULT]);
     if(!response->results) {
         response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
@@ -368,7 +368,7 @@ void Service_SetMonitoringMode(UA_Server *server, UA_Session *session,
         return;
     }
 
-    response->results = UA_Array_new(request->monitoredItemIdsSize, &UA_TYPES[UA_TYPES_STATUSCODE]);
+    response->results = (UA_StatusCode *)UA_Array_new(request->monitoredItemIdsSize, &UA_TYPES[UA_TYPES_STATUSCODE]);
     if(!response->results) {
         response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
         return;
@@ -404,7 +404,7 @@ Service_Publish(UA_Server *server, UA_Session *session,
         goto send_error;
     }
 
-    UA_PublishResponseEntry *entry = UA_malloc(sizeof(UA_PublishResponseEntry));
+    UA_PublishResponseEntry *entry = (UA_PublishResponseEntry *)UA_malloc(sizeof(UA_PublishResponseEntry));
     if(!entry) {
         retval = UA_STATUSCODE_BADOUTOFMEMORY;
         goto send_error;
@@ -416,7 +416,7 @@ Service_Publish(UA_Server *server, UA_Session *session,
     UA_PublishResponse_init(response);
     response->responseHeader.requestHandle = request->requestHeader.requestHandle;
     if(request->subscriptionAcknowledgementsSize > 0) {
-        response->results = UA_Array_new(request->subscriptionAcknowledgementsSize,
+        response->results = (UA_StatusCode *)UA_Array_new(request->subscriptionAcknowledgementsSize,
                                          &UA_TYPES[UA_TYPES_STATUSCODE]);
         if(!response->results) {
             UA_free(entry);
@@ -482,7 +482,7 @@ Service_DeleteSubscriptions(UA_Server *server, UA_Session *session,
         return;
     }
 
-    response->results = UA_malloc(sizeof(UA_StatusCode) * request->subscriptionIdsSize);
+    response->results = (UA_StatusCode *)UA_malloc(sizeof(UA_StatusCode) * request->subscriptionIdsSize);
     if(!response->results) {
         response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
         return;
@@ -533,7 +533,7 @@ void Service_DeleteMonitoredItems(UA_Server *server, UA_Session *session,
 
     /* Reset the subscription lifetime */
     sub->currentLifetimeCount = 0;
-    response->results = UA_malloc(sizeof(UA_StatusCode) * request->monitoredItemIdsSize);
+    response->results = (UA_StatusCode *)UA_malloc(sizeof(UA_StatusCode) * request->monitoredItemIdsSize);
     if(!response->results) {
         response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
         return;

+ 7 - 7
src/server/ua_services_view.c

@@ -210,7 +210,7 @@ Service_Browse_single(UA_Server *server, UA_Session *session,
         real_maxrefs = node->referencesSize;
     else if(real_maxrefs > node->referencesSize)
         real_maxrefs = node->referencesSize;
-    result->references = UA_Array_new(real_maxrefs, &UA_TYPES[UA_TYPES_REFERENCEDESCRIPTION]);
+    result->references = (UA_ReferenceDescription *)UA_Array_new(real_maxrefs, &UA_TYPES[UA_TYPES_REFERENCEDESCRIPTION]);
     if(!result->references) {
         result->statusCode = UA_STATUSCODE_BADOUTOFMEMORY;
         goto cleanup;
@@ -273,7 +273,7 @@ Service_Browse_single(UA_Server *server, UA_Session *session,
     } else if(maxrefs != 0 && referencesCount >= maxrefs) {
         /* create a cp */
         if(session->availableContinuationPoints <= 0 ||
-           !(cp = UA_malloc(sizeof(struct ContinuationPointEntry)))) {
+           !(cp = (struct ContinuationPointEntry *)UA_malloc(sizeof(struct ContinuationPointEntry)))) {
             result->statusCode = UA_STATUSCODE_BADNOCONTINUATIONPOINTS;
             return;
         }
@@ -306,7 +306,7 @@ void Service_Browse(UA_Server *server, UA_Session *session, const UA_BrowseReque
     }
 
     size_t size = request->nodesToBrowseSize;
-    response->results = UA_Array_new(size, &UA_TYPES[UA_TYPES_BROWSERESULT]);
+    response->results = (UA_BrowseResult *)UA_Array_new(size, &UA_TYPES[UA_TYPES_BROWSERESULT]);
     if(!response->results) {
         response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
         return;
@@ -384,7 +384,7 @@ void Service_BrowseNext(UA_Server *server, UA_Session *session, const UA_BrowseN
         return;
     }
     size_t size = request->continuationPointsSize;
-    response->results = UA_Array_new(size, &UA_TYPES[UA_TYPES_BROWSERESULT]);
+    response->results = (UA_BrowseResult *)UA_Array_new(size, &UA_TYPES[UA_TYPES_BROWSERESULT]);
     if(!response->results) {
         response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
         return;
@@ -463,7 +463,7 @@ walkBrowsePath(UA_Server *server, UA_Session *session, const UA_Node *node, cons
             // add the browsetarget
             if(*target_count >= *targets_size) {
                 UA_BrowsePathTarget *newtargets;
-                newtargets = UA_realloc(targets, sizeof(UA_BrowsePathTarget) * (*targets_size) * 2);
+                newtargets = (UA_BrowsePathTarget *)UA_realloc(targets, sizeof(UA_BrowsePathTarget) * (*targets_size) * 2);
                 if(!newtargets) {
                     retval = UA_STATUSCODE_BADOUTOFMEMORY;
                     break;
@@ -504,7 +504,7 @@ void Service_TranslateBrowsePathsToNodeIds_single(UA_Server *server, UA_Session
     }
 
     size_t arraySize = 10;
-    result->targets = UA_malloc(sizeof(UA_BrowsePathTarget) * arraySize);
+    result->targets = (UA_BrowsePathTarget *)UA_malloc(sizeof(UA_BrowsePathTarget) * arraySize);
     if(!result->targets) {
         result->statusCode = UA_STATUSCODE_BADOUTOFMEMORY;
         return;
@@ -540,7 +540,7 @@ void Service_TranslateBrowsePathsToNodeIds(UA_Server *server, UA_Session *sessio
     }
 
     size_t size = request->browsePathsSize;
-    response->results = UA_Array_new(size, &UA_TYPES[UA_TYPES_BROWSEPATHRESULT]);
+    response->results = (UA_BrowsePathResult *)UA_Array_new(size, &UA_TYPES[UA_TYPES_BROWSEPATHRESULT]);
     if(!response->results) {
         response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
         return;

+ 1 - 1
src/server/ua_session_manager.c

@@ -69,7 +69,7 @@ UA_SessionManager_createSession(UA_SessionManager *sm, UA_SecureChannel *channel
     if(sm->currentSessionCount >= sm->server->config.maxSessions)
         return UA_STATUSCODE_BADTOOMANYSESSIONS;
 
-    session_list_entry *newentry = UA_malloc(sizeof(session_list_entry));
+    session_list_entry *newentry = (session_list_entry *)UA_malloc(sizeof(session_list_entry));
     if(!newentry)
         return UA_STATUSCODE_BADOUTOFMEMORY;
 

+ 51 - 43
src/server/ua_subscription.c

@@ -13,20 +13,20 @@
 /*****************/
 
 UA_MonitoredItem * UA_MonitoredItem_new() {
-    UA_MonitoredItem *new = UA_malloc(sizeof(UA_MonitoredItem));
-    new->subscription = NULL;
-    new->currentQueueSize = 0;
-    new->maxQueueSize = 0;
-    new->monitoredItemType = UA_MONITOREDITEMTYPE_CHANGENOTIFY; /* currently hardcoded */
-    new->timestampsToReturn = UA_TIMESTAMPSTORETURN_SOURCE;
-    UA_String_init(&new->indexRange);
-    TAILQ_INIT(&new->queue);
-    UA_NodeId_init(&new->monitoredNodeId);
-    new->lastSampledValue = UA_BYTESTRING_NULL;
-    memset(&new->sampleJobGuid, 0, sizeof(UA_Guid));
-    new->sampleJobIsRegistered = false;
-    new->itemId = 0;
-    return new;
+    UA_MonitoredItem *newItem = (UA_MonitoredItem *)UA_malloc(sizeof(UA_MonitoredItem));
+    newItem->subscription = NULL;
+    newItem->currentQueueSize = 0;
+    newItem->maxQueueSize = 0;
+    newItem->monitoredItemType = UA_MONITOREDITEMTYPE_CHANGENOTIFY; /* currently hardcoded */
+    newItem->timestampsToReturn = UA_TIMESTAMPSTORETURN_SOURCE;
+    UA_String_init(&newItem->indexRange);
+    TAILQ_INIT(&newItem->queue);
+    UA_NodeId_init(&newItem->monitoredNodeId);
+    newItem->lastSampledValue = UA_BYTESTRING_NULL;
+    memset(&newItem->sampleJobGuid, 0, sizeof(UA_Guid));
+    newItem->sampleJobIsRegistered = false;
+    newItem->itemId = 0;
+    return newItem;
 }
 
 void MonitoredItem_delete(UA_Server *server, UA_MonitoredItem *monitoredItem) {
@@ -48,13 +48,20 @@ void MonitoredItem_delete(UA_Server *server, UA_MonitoredItem *monitoredItem) {
 
 static void
 ensureSpaceInMonitoredItemQueue(UA_MonitoredItem *mon) {
-    if(mon->currentQueueSize < mon->maxQueueSize)
+    if(mon->currentQueueSize < mon->maxQueueSize) {
         return;
-    MonitoredItem_queuedValue *queueItem;
-    if(mon->discardOldest)
+    }
+
+	MonitoredItem_queuedValue *queueItem =
+		TAILQ_LAST(&mon->queue, memberstruct(UA_MonitoredItem,QueueOfQueueDataValues));
+
+    if(mon->discardOldest) {
         queueItem = TAILQ_FIRST(&mon->queue);
-    else
-        queueItem = TAILQ_LAST(&mon->queue, QueueOfQueueDataValues);
+    } else {
+		queueItem = TAILQ_LAST(&mon->queue,
+		                       memberstruct(UA_MonitoredItem,QueueOfQueueDataValues));
+    }
+
     UA_assert(queueItem); /* When the currentQueueSize > 0, then there is an item */
     TAILQ_REMOVE(&mon->queue, queueItem, listEntry);
     UA_DataValue_deleteMembers(&queueItem->value);
@@ -147,7 +154,7 @@ void UA_MoniteredItem_SampleCallback(UA_Server *server, UA_MonitoredItem *monito
     Service_Read_single(server, sub->session, ts, &rvid, &value);
 
     /* Stack-allocate some memory for the value encoding */
-    UA_Byte *stackValueEncoding = UA_alloca(UA_VALUENCODING_MAXSTACK);
+    UA_Byte *stackValueEncoding = (UA_Byte *)UA_alloca(UA_VALUENCODING_MAXSTACK);
     UA_ByteString valueEncoding;
     valueEncoding.data = stackValueEncoding;
     valueEncoding.length = UA_VALUENCODING_MAXSTACK;
@@ -160,7 +167,7 @@ void UA_MoniteredItem_SampleCallback(UA_Server *server, UA_MonitoredItem *monito
         goto cleanup;
 
     /* Allocate the entry for the publish queue */
-    MonitoredItem_queuedValue *newQueueItem = UA_malloc(sizeof(MonitoredItem_queuedValue));
+    MonitoredItem_queuedValue *newQueueItem = (MonitoredItem_queuedValue *)UA_malloc(sizeof(MonitoredItem_queuedValue));
     if(!newQueueItem) {
         UA_LOG_WARNING_SESSION(server->config.logger, sub->session,
                                "Subscription %u | MonitoredItem %i | "
@@ -246,24 +253,24 @@ UA_StatusCode MonitoredItem_unregisterSampleJob(UA_Server *server, UA_MonitoredI
 /****************/
 
 UA_Subscription * UA_Subscription_new(UA_Session *session, UA_UInt32 subscriptionID) {
-    UA_Subscription *new = UA_malloc(sizeof(UA_Subscription));
-    if(!new)
+    UA_Subscription *newItem = (UA_Subscription *)UA_malloc(sizeof(UA_Subscription));
+    if(!newItem)
         return NULL;
-    new->session = session;
-    new->subscriptionID = subscriptionID;
-    new->sequenceNumber = 0;
-    new->maxKeepAliveCount = 0;
-    new->publishingEnabled = false;
-    memset(&new->publishJobGuid, 0, sizeof(UA_Guid));
-    new->publishJobIsRegistered = false;
-    new->currentKeepAliveCount = 0;
-    new->currentLifetimeCount = 0;
-    new->lastMonitoredItemId = 0;
-    new->state = UA_SUBSCRIPTIONSTATE_NORMAL; /* The first publish response is sent immediately */
-    LIST_INIT(&new->monitoredItems);
-    TAILQ_INIT(&new->retransmissionQueue);
-    new->retransmissionQueueSize = 0;
-    return new;
+    newItem->session = session;
+    newItem->subscriptionID = subscriptionID;
+    newItem->sequenceNumber = 0;
+    newItem->maxKeepAliveCount = 0;
+    newItem->publishingEnabled = false;
+    memset(&newItem->publishJobGuid, 0, sizeof(UA_Guid));
+    newItem->publishJobIsRegistered = false;
+    newItem->currentKeepAliveCount = 0;
+    newItem->currentLifetimeCount = 0;
+    newItem->lastMonitoredItemId = 0;
+    newItem->state = UA_SUBSCRIPTIONSTATE_NORMAL; /* The first publish response is sent immediately */
+    LIST_INIT(&newItem->monitoredItems);
+    TAILQ_INIT(&newItem->retransmissionQueue);
+    newItem->retransmissionQueueSize = 0;
+    return newItem;
 }
 
 void UA_Subscription_deleteMembers(UA_Subscription *subscription, UA_Server *server) {
@@ -336,7 +343,8 @@ UA_Subscription_addRetransmissionMessage(UA_Server *server, UA_Subscription *sub
     if(server->config.maxRetransmissionQueueSize > 0 &&
        sub->retransmissionQueueSize >= server->config.maxRetransmissionQueueSize) {
         UA_NotificationMessageEntry *lastentry =
-            TAILQ_LAST(&sub->retransmissionQueue, UA_ListOfNotificationMessages);
+            TAILQ_LAST(&sub->retransmissionQueue,
+			           memberstruct(UA_Subscription,UA_ListOfNotificationMessages));
         TAILQ_REMOVE(&sub->retransmissionQueue, lastentry, listEntry);
         --sub->retransmissionQueueSize;
         UA_NotificationMessage_deleteMembers(&lastentry->message);
@@ -368,7 +376,7 @@ prepareNotificationMessage(UA_Subscription *sub, UA_NotificationMessage *message
                            size_t notifications) {
     /* Array of ExtensionObject to hold different kinds of notifications
        (currently only DataChangeNotifications) */
-    message->notificationData = UA_Array_new(1, &UA_TYPES[UA_TYPES_EXTENSIONOBJECT]);
+    message->notificationData = (UA_ExtensionObject *)UA_Array_new(1, &UA_TYPES[UA_TYPES_EXTENSIONOBJECT]);
     if(!message->notificationData)
         return UA_STATUSCODE_BADOUTOFMEMORY;
     message->notificationDataSize = 1;
@@ -383,7 +391,7 @@ prepareNotificationMessage(UA_Subscription *sub, UA_NotificationMessage *message
     data->content.decoded.type = &UA_TYPES[UA_TYPES_DATACHANGENOTIFICATION];
 
     /* Allocate array of notifications */
-    dcn->monitoredItems =
+    dcn->monitoredItems = (UA_MonitoredItemNotification *)
         UA_Array_new(notifications, &UA_TYPES[UA_TYPES_MONITOREDITEMNOTIFICATION]);
     if(!dcn->monitoredItems)
         goto cleanup;
@@ -462,7 +470,7 @@ void UA_Subscription_publishCallback(UA_Server *server, UA_Subscription *sub) {
     UA_NotificationMessageEntry *retransmission = NULL;
     if(notifications > 0) {
         /* Allocate the retransmission entry */
-        retransmission = malloc(sizeof(UA_NotificationMessageEntry));
+        retransmission = (UA_NotificationMessageEntry *)malloc(sizeof(UA_NotificationMessageEntry));
         if(!retransmission) {
             UA_LOG_WARNING_SESSION(server->config.logger, sub->session,
                                    "Subscription %u | Could not allocate memory "
@@ -508,7 +516,7 @@ void UA_Subscription_publishCallback(UA_Server *server, UA_Subscription *sub) {
     /* Get the available sequence numbers from the retransmission queue */
     size_t available = sub->retransmissionQueueSize;
     if(available > 0) {
-        response->availableSequenceNumbers = UA_alloca(available * sizeof(UA_UInt32));
+        response->availableSequenceNumbers = (UA_UInt32 *)UA_alloca(available * sizeof(UA_UInt32));
         response->availableSequenceNumbersSize = available;
         size_t i = 0;
         UA_NotificationMessageEntry *nme;

+ 5 - 5
src/ua_securechannel.c

@@ -48,7 +48,7 @@ void UA_SecureChannel_deleteMembersCleanup(UA_SecureChannel *channel) {
 
 //TODO implement real nonce generator - DUMMY function
 UA_StatusCode UA_SecureChannel_generateNonce(UA_ByteString *nonce) {
-    if(!(nonce->data = UA_malloc(1)))
+    if(!(nonce->data = (UA_Byte *)UA_malloc(1)))
         return UA_STATUSCODE_BADOUTOFMEMORY;
     nonce->length  = 1;
     nonce->data[0] = 'a';
@@ -63,7 +63,7 @@ UA_StatusCode UA_SecureChannel_generateNonce(UA_ByteString *nonce) {
 #endif
 
 void UA_SecureChannel_attachSession(UA_SecureChannel *channel, UA_Session *session) {
-    struct SessionEntry *se = UA_malloc(sizeof(struct SessionEntry));
+    struct SessionEntry *se = (struct SessionEntry *)UA_malloc(sizeof(struct SessionEntry));
     if(!se)
         return;
     se->session = session;
@@ -263,7 +263,7 @@ UA_SecureChannel_removeChunk(UA_SecureChannel *channel, UA_UInt32 requestId) {
 static void
 appendChunk(struct ChunkEntry *ch, const UA_ByteString *msg,
             size_t offset, size_t chunklength) {
-    UA_Byte* new_bytes = UA_realloc(ch->bytes.data, ch->bytes.length + chunklength);
+    UA_Byte* new_bytes = (UA_Byte *)UA_realloc(ch->bytes.data, ch->bytes.length + chunklength);
     if(!new_bytes) {
         UA_ByteString_deleteMembers(&ch->bytes);
         return;
@@ -293,7 +293,7 @@ UA_SecureChannel_appendChunk(UA_SecureChannel *channel, UA_UInt32 requestId,
 
     /* No chunkentry on the channel, create one */
     if(!ch) {
-        ch = UA_malloc(sizeof(struct ChunkEntry));
+        ch = (struct ChunkEntry *)UA_malloc(sizeof(struct ChunkEntry));
         if(!ch)
             return;
         ch->requestId = requestId;
@@ -409,7 +409,7 @@ UA_SecureChannel_processChunks(UA_SecureChannel *channel, const UA_ByteString *c
                                                header.messageHeader.messageSize - processed_header,
                                                &realloced);
             if(message.length > 0) {
-                callback(application, channel, header.messageHeader.messageTypeAndChunkType & 0x00ffffff,
+                callback(application,(UA_SecureChannel *)channel,(UA_MessageType)(header.messageHeader.messageTypeAndChunkType & 0x00ffffff),
                          sequenceHeader.requestId, &message);
                 if(realloced)
                     UA_ByteString_deleteMembers(&message);

+ 23 - 12
src/ua_session.c

@@ -6,18 +6,29 @@
 #endif
 
 UA_Session adminSession = {
-    .clientDescription =  {.applicationUri = {0, NULL}, .productUri = {0, NULL},
-                           .applicationName = {.locale = {0, NULL}, .text = {0, NULL}},
-                           .applicationType = UA_APPLICATIONTYPE_CLIENT,
-                           .gatewayServerUri = {0, NULL}, .discoveryProfileUri = {0, NULL},
-                           .discoveryUrlsSize = 0, .discoveryUrls = NULL},
-    .sessionName = {sizeof("Administrator Session")-1, (UA_Byte*)"Administrator Session"},
-    .authenticationToken = {.namespaceIndex = 0, .identifierType = UA_NODEIDTYPE_NUMERIC,
-                            .identifier.numeric = 1},
-    .sessionId = {.namespaceIndex = 0, .identifierType = UA_NODEIDTYPE_NUMERIC, .identifier.numeric = 1},
-    .maxRequestMessageSize = UA_UINT32_MAX, .maxResponseMessageSize = UA_UINT32_MAX,
-    .timeout = (UA_Double)UA_INT64_MAX, .validTill = UA_INT64_MAX, .channel = NULL,
-    .continuationPoints = {NULL}};
+    {{0, NULL},{0, NULL},
+     {{0, NULL},{0, NULL}},
+     UA_APPLICATIONTYPE_CLIENT,
+     {0, NULL},{0, NULL},
+     0, NULL}, /* .clientDescription */
+    {sizeof("Administrator Session")-1, (UA_Byte*)"Administrator Session"}, /* .sessionName */
+	false, /* .activated */
+	NULL, /* .sessionHandle */
+    {0,UA_NODEIDTYPE_NUMERIC,{1}}, /* .authenticationToken */
+    {0,UA_NODEIDTYPE_NUMERIC,{1}}, /* .sessionId */
+    UA_UINT32_MAX, /* .maxRequestMessageSize */
+	UA_UINT32_MAX, /* .maxResponseMessageSize */
+    (UA_Double)UA_INT64_MAX, /* .timeout */
+	UA_INT64_MAX, /* .validTill */
+    NULL, /* .channel */
+    0, /* .availableContinuationPoints */
+    {NULL}, /* .continuationPoints */
+#ifdef UA_ENABLE_SUBSCRIPTIONS
+    0, /* .lastSubscriptionID */
+    {NULL}, /* .serverSubscriptions */
+    {NULL, NULL}, /* .responseQueue */
+#endif
+};
 
 void UA_Session_init(UA_Session *session) {
     UA_ApplicationDescription_init(&session->clientDescription);

+ 9 - 7
src/ua_types_encoding_binary.c

@@ -968,7 +968,7 @@ Variant_decodeBinary(UA_Variant *dst, const UA_DataType *_) {
         return retval;
     if(encodingByte == 0)
         return UA_STATUSCODE_GOOD; /* empty Variant (was already _inited) */
-    UA_Boolean isArray = encodingByte & UA_VARIANT_ENCODINGMASKTYPE_ARRAY;
+    UA_Boolean isArray = (encodingByte & UA_VARIANT_ENCODINGMASKTYPE_ARRAY) > 0;
     size_t typeIndex = (size_t)((encodingByte & UA_VARIANT_ENCODINGMASKTYPE_TYPEID_MASK) - 1);
     if(typeIndex > 24) /* the type must be builtin (maybe wrapped in an extensionobject) */
         return UA_STATUSCODE_BADDECODINGERROR;
@@ -1040,9 +1040,11 @@ Variant_decodeBinary(UA_Variant *dst, const UA_DataType *_) {
 static UA_StatusCode
 DataValue_encodeBinary(UA_DataValue const *src, const UA_DataType *_) {
     UA_Byte encodingMask = (UA_Byte)
-        (src->hasValue | (src->hasStatus << 1) | (src->hasSourceTimestamp << 2) |
-         (src->hasServerTimestamp << 3) | (src->hasSourcePicoseconds << 4) |
-         (src->hasServerPicoseconds << 5));
+        ((UA_Byte)src->hasValue | ((UA_Byte)src->hasStatus << 1) |
+		((UA_Byte)src->hasSourceTimestamp << 2) |
+        ((UA_Byte)src->hasServerTimestamp << 3) |
+		((UA_Byte)src->hasSourcePicoseconds << 4) |
+        ((UA_Byte)src->hasServerPicoseconds << 5));
     UA_StatusCode retval = Byte_encodeBinary(&encodingMask, NULL);
     if(src->hasValue)
         retval |= Variant_encodeBinary(&src->value, NULL);
@@ -1101,9 +1103,9 @@ DataValue_decodeBinary(UA_DataValue *dst, const UA_DataType *_) {
 static UA_StatusCode
 DiagnosticInfo_encodeBinary(const UA_DiagnosticInfo *src, const UA_DataType *_) {
     UA_Byte encodingMask = (UA_Byte)
-        (src->hasSymbolicId | (src->hasNamespaceUri << 1) |
-         (src->hasLocalizedText << 2) | (src->hasLocale << 3) |
-         (src->hasAdditionalInfo << 4) | (src->hasInnerDiagnosticInfo << 5));
+        ((UA_Byte)src->hasSymbolicId | ((UA_Byte)src->hasNamespaceUri << 1) |
+         ((UA_Byte)src->hasLocalizedText << 2) | ((UA_Byte)src->hasLocale << 3) |
+         ((UA_Byte)src->hasAdditionalInfo << 4) | ((UA_Byte)src->hasInnerDiagnosticInfo << 5));
     UA_StatusCode retval = Byte_encodeBinary(&encodingMask, NULL);
     if(src->hasSymbolicId)
         retval |= Int32_encodeBinary(&src->symbolicId);

+ 7 - 0
src/ua_util.h

@@ -10,6 +10,13 @@
 /* BSD Queue Macros */
 #include "queue.h"
 
+/* C++ Access to datatypes defined inside structs (for queue.h) */
+#ifdef __cplusplus
+# define memberstruct(container,member) container::member
+#else
+# define memberstruct(container,member) member
+#endif
+
 /* container_of */
 #define container_of(ptr, type, member) \
     (type *)((uintptr_t)ptr - offsetof(type,member))

+ 22 - 22
tools/generate_datatypes.py

@@ -79,22 +79,21 @@ class Type(object):
         binaryEncodingId = "0"
         if self.name in typedescriptions:
             description = typedescriptions[self.name]
-            typeid = "{.namespaceIndex = %s, .identifierType = UA_NODEIDTYPE_NUMERIC, .identifier.numeric = %s}" % (description.namespaceid, description.nodeid)
+            typeid = "{%s, UA_NODEIDTYPE_NUMERIC, {%s}}" % (description.namespaceid, description.nodeid)
             xmlEncodingId = description.xmlEncodingId
             binaryEncodingId = description.binaryEncodingId
         else:
-            typeid = "{.namespaceIndex = 0, .identifierType = UA_NODEIDTYPE_NUMERIC, .identifier.numeric = 0}"
-        return "{ .typeId = " + typeid + \
-            ",\n  .typeIndex = " + self.typeIndex + \
-            ",\n#ifdef UA_ENABLE_TYPENAMES\n  .typeName = \"%s\",\n#endif\n" % self.name + \
-            "  .memSize = sizeof(UA_" + self.name + ")" + \
-            ",\n  .builtin = " + self.builtin + \
-            ",\n  .pointerFree = " + self.pointerfree + \
-            ",\n  .overlayable = " + self.overlayable + \
-            ",\n  .binaryEncodingId = " + binaryEncodingId + \
-            ",\n  .membersSize = " + str(len(self.members)) + \
-            ",\n  .members = %s_members" % self.name + " }"
-            #",\n  .xmlEncodingId = " + xmlEncodingId + \ Not used for now
+            typeid = "{0, UA_NODEIDTYPE_NUMERIC, {0}}"
+        return "{\n#ifdef UA_ENABLE_TYPENAMES\n    \"%s\", /* .typeName */\n#endif\n" % self.name + \
+            "    " + typeid + ", /* .typeId */\n" + \
+            "    sizeof(UA_" + self.name + "), /* .memSize */\n" + \
+            "    " + self.typeIndex + ", /* .typeIndex */\n" + \
+            "    " + str(len(self.members)) + ", /* .membersSize */\n" + \
+            "    " + self.builtin + ", /* .builtin */\n" + \
+            "    " + self.pointerfree + ", /* .pointerFree */\n" + \
+            "    " + self.overlayable + ", /* .overlayable */ \n" + \
+            "    " + binaryEncodingId + ", /* .binaryEncodingId */\n" + \
+            "    %s_members" % self.name + " /* .members */ }"
 
     def members_c(self):
         if len(self.members)==0:
@@ -102,12 +101,11 @@ class Type(object):
         members = "static UA_DataTypeMember %s_members[%s] = {" % (self.name, len(self.members))
         before = None
         for index, member in enumerate(self.members):
-            m = "\n  { .memberTypeIndex = %s_%s,\n" % (member.memberType.outname.upper(), member.memberType.name.upper())
-            m += "#ifdef UA_ENABLE_TYPENAMES\n    .memberName = \"%s\",\n#endif\n" % member.name
-            m += "    .namespaceZero = %s,\n" % member.memberType.ns0
-            m += "    .padding = "
+            m = "\n{\n#ifdef UA_ENABLE_TYPENAMES\n    \"%s\", /* .memberName */\n#endif\n" % member.name
+            m += "    %s_%s, /* .memberTypeIndex */\n" % (member.memberType.outname.upper(), member.memberType.name.upper())
+            m += "    "
             if not before:
-                m += "0,\n"
+                m += "0,"
             else:
                 if member.isArray:
                     m += "offsetof(UA_%s, %sSize)" % (self.name, member.name)
@@ -115,11 +113,13 @@ class Type(object):
                     m += "offsetof(UA_%s, %s)" % (self.name, member.name)
                 m += " - offsetof(UA_%s, %s)" % (self.name, before.name)
                 if before.isArray:
-                    m += " - sizeof(void*),\n"
+                    m += " - sizeof(void*),"
                 else:
-                    m += " - sizeof(UA_%s),\n" % before.memberType.name
-            m += "    .isArray = " + ("true" if member.isArray else "false")
-            members += m + "\n  },"
+                    m += " - sizeof(UA_%s)," % before.memberType.name
+            m += " /* .padding */\n"
+            m += "    %s, /* .namespaceZero */\n" % member.memberType.ns0
+            m += ("    true" if member.isArray else "    false") + " /* .isArray */\n},"
+            members += m
             before = member
         return members + "};"