Browse Source

set standard visibility to hidden, clean include hierarchy.
this is recommended for shared libraries

Julius Pfrommer 10 years ago
parent
commit
04627d13e1

+ 32 - 23
CMakeLists.txt

@@ -5,6 +5,8 @@ project(open62541)
 set(open62541_VERSION_MAJOR 0)
 set(open62541_VERSION_MINOR 1)
 
+set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
+
 # main sources of libopen62541
 include_directories("${CMAKE_CURRENT_SOURCE_DIR}/src")
 file(GLOB_RECURSE headers "${CMAKE_CURRENT_SOURCE_DIR}/src/*.h")
@@ -37,17 +39,18 @@ set(lib_sources src/ua_types.c
                 ${generated_headers})
 
 # compiler flags
-if(CMAKE_COMPILER_IS_GNUCC)
-add_definitions(-std=c99 -pedantic -pipe -fstack-protector -Wall -Wextra
-                -Wno-unused-parameter -Wno-unused-function -Wno-unused-label
-                -Wpointer-arith -Wformat -Wreturn-type -Wsign-compare -Wmultichar
-                -Wformat-nonliteral -Winit-self -Wuninitialized -Wno-deprecated
-                -Wformat-security -Werror -ffunction-sections -fdata-sections
-                -Wl,--gc-sections)
-	if(WIN32)
-	    add_definitions(-fno-stack-protector)
-	endif(WIN32)
-endif(CMAKE_COMPILER_IS_GNUCC)
+if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
+add_definitions(-std=c99 -pedantic -pipe -fvisibility=hidden -Wall -Wextra -Werror -Wformat
+                -Wno-unused-parameter -Wno-unused-function -Wno-unused-label -Wpointer-arith -Wreturn-type -Wsign-compare -Wmultichar
+                -Winit-self -Wuninitialized -Wno-deprecated -Wformat-security -ffunction-sections -fdata-sections)
+    if(NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
+        add_definitions(-Wformat-nonliteral -Wl,--gc-sections)
+    endif()
+	if(NOT WIN32)
+	    add_definitions(-fstack-protector)
+	endif()
+endif()
+add_definitions(-Dopen62541_EXPORTS) # dllexport/dllimport differentiation in ua_config.h when building the lib on windows
 
 # build settings
 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules")
@@ -63,14 +66,14 @@ if(ENABLE_SELFSIGNED)
                    COMMAND python ${PROJECT_SOURCE_DIR}/tools/certs/create_self-signed.py ${PROJECT_BINARY_DIR}
                    DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tools/certs/create_self-signed.py
                            ${CMAKE_CURRENT_SOURCE_DIR}/tools/certs/localhost.cnf)
-endif(ENABLE_SELFSIGNED)
+endif()
 
 
 ## auto-generate all types or only the relevant subset?
 option(TYPES_ONLY_NEEDED "Include only compile-needed types" OFF)
 if(TYPES_ONLY_NEEDED)
     list(APPEND generate_src_options "--only-needed")
-endif(TYPES_ONLY_NEEDED)
+endif()
 
 ## encodings
 set(UA_ENCODING_AMOUNT 1) # binary encoding
@@ -90,7 +93,7 @@ if(ENABLE_XML_ENCODING)
                             src/ongoing/ua_namespace_xml.c
                             src/ongoing/ua_xml.c)
     list(APPEND generate_src_options "--with-xml")
-endif(ENABLE_XML_ENCODING)
+endif()
 
 ### json
 option(ENABLE_JSON_ENCODING "Enable JSON-encoding of the UA types" OFF)
@@ -108,7 +111,7 @@ if(ENABLE_MULTITHREADING)
     list(APPEND lib_sources src/server/ua_nodestore_concurrent.c)
 else()
     list(APPEND lib_sources src/server/ua_nodestore.c)
-endif(ENABLE_MULTITHREADING)
+endif()
 
 add_library(open62541 ${lib_sources}) # we can add more files to lib_sources later on
 
@@ -123,7 +126,7 @@ if(ENABLE_COVERAGE)
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
     set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
     set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fprofile-arcs -ftest-coverage")
-endif(ENABLE_COVERAGE)
+endif()
 
 configure_file("src/ua_config.h.in" "${PROJECT_BINARY_DIR}/src_generated/ua_config.h")
 
@@ -149,23 +152,29 @@ add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/ua_transport_gener
                            ${CMAKE_CURRENT_SOURCE_DIR}/schema/Custom.Opc.Ua.Transport.bsd)
 
 # build example server
-add_executable(exampleServer examples/opcuaServer.c
-                             examples/logger_stdout.c
-                             examples/networklayer_tcp.c)
+set(server_sources examples/opcuaServer.c
+                   examples/logger_stdout.c)
+# if(NOT ENABLE_MULTITHREADING)
+    list(APPEND server_sources examples/networklayer_tcp.c)
+# else()
+#    list(APPEND server_sources examples/networklayer_tcp_concurrent.c)
+# endif()
+add_executable(exampleServer ${server_sources})
 target_link_libraries(exampleServer open62541)
 if(WIN32)
     target_link_libraries(exampleServer ws2_32)
 endif(WIN32)
 if(ENABLE_MULTITHREADING)
-    target_link_libraries(exampleServer urcu-cds urcu)
-endif(ENABLE_MULTITHREADING)
+    find_package(LibUV REQUIRED)
+    target_link_libraries(exampleServer urcu-cds urcu uv)
+endif()
 
 # build unit tests
 option(ENABLE_UNIT_TESTS "Run unit tests after building" OFF)
 if(ENABLE_UNIT_TESTS)
     enable_testing()
     add_subdirectory(tests)
-endif(ENABLE_UNIT_TESTS)
+endif()
 
 # build documentation
 option(GENERATE_DOCUMENTATION "Generate doxygen documentation" OFF)
@@ -179,7 +188,7 @@ if(GENERATE_DOCUMENTATION)
                       ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
                       WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
                       COMMENT "Generating API documentation with Doxygen")
-endif(GENERATE_DOCUMENTATION)
+endif()
 
 # download queue.h if required
 if(WIN32)

CMakeModules/FindCheck.cmake → cmake/FindCheck.cmake


+ 9 - 9
examples/networklayer_tcp.c

@@ -53,7 +53,7 @@ typedef struct TCPConnectionHandle {
 UA_Int32 NetworklayerTCP_new(NetworklayerTCP **newlayer, UA_ConnectionConfig localConf,
 							 UA_UInt32 port) {
     UA_UInt32 retval = UA_SUCCESS;
-    retval |= UA_alloc((void**)newlayer, sizeof(NetworklayerTCP));
+    newlayer = malloc(sizeof(NetworklayerTCP));
     if(retval != UA_SUCCESS)
         return UA_ERROR;
 	(*newlayer)->localConf = localConf;
@@ -74,10 +74,10 @@ UA_Int32 NetworklayerTCP_remove(NetworklayerTCP *layer, UA_Int32 sockfd) {
 	UA_Connection_deleteMembers(&layer->connections[index].connection);
 
 	TCPConnection *newconnections;
-	UA_alloc((void**)&newconnections, sizeof(TCPConnection) * (layer->connectionsSize-1));
-	UA_memcpy(newconnections, &layer->connections, sizeof(TCPConnection) * index);
-	UA_memcpy(&newconnections[index], &layer->connections[index+1],
-			  sizeof(TCPConnection) * (layer->connectionsSize - index - 1));
+    newconnections = malloc(sizeof(TCPConnection) * (layer->connectionsSize-1));
+	memcpy(newconnections, &layer->connections, sizeof(TCPConnection) * index);
+	memcpy(&newconnections[index], &layer->connections[index+1],
+           sizeof(TCPConnection) * (layer->connectionsSize - index - 1));
 	layer->connections = newconnections;
 	layer->connectionsSize--;
 	return UA_SUCCESS;
@@ -89,8 +89,8 @@ void NetworklayerTCP_delete(NetworklayerTCP *layer) {
         UA_Connection_deleteMembers(&layer->connections[index].connection);
 		CLOSESOCKET(layer->connections[index].sockfd);
 	}
-	UA_free(layer->connections);
-	UA_free(layer);
+	free(layer->connections);
+	free(layer);
 }
 
 /** Callback function */
@@ -158,7 +158,7 @@ UA_Int32 NetworklayerTCP_add(NetworklayerTCP *layer, UA_Int32 newsockfd) {
 	newconnection->sockfd = newsockfd;
 
 	struct TCPConnectionHandle *callbackhandle;
-	UA_alloc((void**)&callbackhandle, sizeof(struct TCPConnectionHandle));
+    callbackhandle = malloc(sizeof(struct TCPConnectionHandle));
 	callbackhandle->layer = layer;
 	callbackhandle->sockfd = newsockfd;
 	UA_Connection_init(&newconnection->connection, layer->localConf, callbackhandle,
@@ -192,7 +192,7 @@ UA_Int32 setNonBlocking(int sockid) {
 
 void readConnection(NetworklayerTCP *layer, UA_Server *server, TCPConnection *entry) {
 	UA_ByteString readBuffer;
-	UA_alloc((void**)&readBuffer.data, layer->localConf.recvBufferSize);
+    readBuffer.data = malloc(layer->localConf.recvBufferSize);
 #ifdef WIN32
 	readBuffer.length = recv(entry->sockfd, (char *)readBuffer.data,
 							 layer->localConf.recvBufferSize, 0);

+ 0 - 1
examples/networklayer_tcp.h

@@ -6,7 +6,6 @@
 #ifndef NETWORKLAYERTCP_H_
 #define NETWORKLAYERTCP_H_
 
-#include <time.h>
 #include "server/ua_server.h"
 
 struct NetworklayerTCP;

+ 2 - 1
examples/opcuaServer.c

@@ -4,6 +4,7 @@
  */
 
 #include <stdio.h>
+#include <stdlib.h> 
 #ifndef WIN32
 #include <sys/mman.h>
 #include <sys/wait.h>
@@ -44,7 +45,7 @@ UA_ByteString loadCertificate() {
 
     fseek(fp, 0, SEEK_END);
     certificate.length = ftell(fp);
-    UA_alloc((void**)&certificate.data, certificate.length*sizeof(UA_Byte));
+    certificate.data = malloc(certificate.length*sizeof(UA_Byte));
 
     fseek(fp, 0, SEEK_SET);
     if(fread(certificate.data, sizeof(UA_Byte), certificate.length, fp) < (size_t)certificate.length)

+ 1 - 0
src/server/ua_nodestore.c

@@ -1,4 +1,5 @@
 #include "ua_nodestore.h"
+#include "util/ua_util.h"
 
 struct UA_NodeStore {
     const UA_Node **entries;

+ 1 - 6
src/server/ua_nodestore.h

@@ -1,8 +1,7 @@
 #ifndef UA_NODESTORE_H_
 #define UA_NODESTORE_H_
 
-#include "ua_types.h"
-#include "ua_types_generated.h"
+#include "ua_server.h"
 
 /**
    @ingroup server
@@ -22,10 +21,6 @@
    @{
  */
 
-/** @brief UA_NodeStore datastructure. Mainly a hashmap to UA_Nodes */
-struct UA_NodeStore;
-typedef struct UA_NodeStore UA_NodeStore;
-
 /** @brief Create a new namespace */
 UA_Int32 UA_NodeStore_new(UA_NodeStore **result);
 

+ 1 - 0
src/server/ua_nodestore_concurrent.c

@@ -1,4 +1,5 @@
 #include "ua_nodestore.h"
+#include "util/ua_util.h"
 
 #include <urcu.h>
 #include <urcu/compiler.h> // for caa_container_of

+ 1 - 0
src/server/ua_securechannel_manager.c

@@ -1,4 +1,5 @@
 #include "ua_securechannel_manager.h"
+#include "util/ua_util.h"
 
 struct channel_list_entry {
     UA_SecureChannel channel;

+ 1 - 4
src/server/ua_securechannel_manager.h

@@ -1,12 +1,9 @@
 #ifndef UA_CHANNEL_MANAGER_H_
 #define UA_CHANNEL_MANAGER_H_
 
-#include "ua_types_generated.h"
+#include "ua_server.h"
 #include "ua_securechannel.h"
 
-struct UA_SecureChannelManager;
-typedef struct UA_SecureChannelManager UA_SecureChannelManager;
-
 UA_Int32 UA_SecureChannelManager_new(UA_SecureChannelManager **cm, UA_UInt32 maxChannelCount,
                                      UA_UInt32 tokenLifetime, UA_UInt32 startChannelId,
                                      UA_UInt32 startTokenId, UA_String *endpointUrl);

+ 3 - 0
src/server/ua_server.c

@@ -1,6 +1,9 @@
 #include "ua_server.h"
 #include "ua_services_internal.h" // AddReferences
 #include "ua_namespace_0.h"
+#include "ua_securechannel_manager.h"
+#include "ua_session_manager.h"
+#include "util/ua_util.h"
 
 UA_Int32 UA_Server_deleteMembers(UA_Server *server) {
     UA_ApplicationDescription_deleteMembers(&server->description);

+ 14 - 7
src/server/ua_server.h

@@ -3,15 +3,22 @@
 
 #include "ua_types.h"
 #include "ua_types_generated.h"
-#include "ua_nodestore.h"
-#include "ua_securechannel_manager.h"
-#include "ua_session_manager.h"
+#include "ua_connection.h"
 #include "util/ua_log.h"
 
 /**
    @defgroup server Server
  */
 
+struct UA_SecureChannelManager;
+typedef struct UA_SecureChannelManager UA_SecureChannelManager;
+
+struct UA_SessionManager;
+typedef struct UA_SessionManager UA_SessionManager;
+
+struct UA_NodeStore;
+typedef struct UA_NodeStore UA_NodeStore;
+
 typedef struct UA_Server {
     UA_ApplicationDescription description;
     UA_SecureChannelManager *secureChannelManager;
@@ -21,9 +28,9 @@ typedef struct UA_Server {
     UA_ByteString serverCertificate;
 } UA_Server;
 
-void UA_Server_init(UA_Server *server, UA_String *endpointUrl);
-UA_Int32 UA_Server_deleteMembers(UA_Server *server);
-UA_Int32 UA_Server_processBinaryMessage(UA_Server *server, UA_Connection *connection,
-                                        const UA_ByteString *msg);
+void UA_LIBEXPORT UA_Server_init(UA_Server *server, UA_String *endpointUrl);
+UA_Int32 UA_LIBEXPORT UA_Server_deleteMembers(UA_Server *server);
+UA_Int32 UA_LIBEXPORT UA_Server_processBinaryMessage(UA_Server *server, UA_Connection *connection,
+                                                     const UA_ByteString *msg);
 
 #endif /* UA_SERVER_H_ */

+ 2 - 0
src/server/ua_server_binary.c

@@ -1,6 +1,8 @@
 #include "ua_server.h"
 #include "ua_services.h"
 #include "ua_statuscodes.h"
+#include "util/ua_util.h"
+#include "ua_securechannel_manager.h"
 
 static void processHello(UA_Connection *connection, const UA_ByteString *msg,
                          UA_UInt32 *pos) {

+ 1 - 0
src/server/ua_services.h

@@ -4,6 +4,7 @@
 #include "ua_types.h"
 #include "ua_types_generated.h"
 #include "ua_server.h"
+#include "ua_session.h"
 
 /**
  * @defgroup services Services

+ 2 - 0
src/server/ua_services_attribute.c

@@ -1,5 +1,7 @@
 #include "ua_services.h"
 #include "ua_statuscodes.h"
+#include "ua_nodestore.h"
+#include "util/ua_util.h"
 
 enum UA_AttributeId {
     UA_ATTRIBUTEID_NODEID = 1,

+ 1 - 0
src/server/ua_services_nodemanagement.c

@@ -3,6 +3,7 @@
 #include "ua_nodestore.h"
 #include "ua_services_internal.h"
 #include "ua_session.h"
+#include "util/ua_util.h"
 
 #define CHECKED_ACTION(ACTION, CLEAN_UP, GOTO) do { \
         status |= ACTION;                           \

+ 1 - 0
src/server/ua_services_securechannel.c

@@ -1,4 +1,5 @@
 #include "ua_services.h"
+#include "ua_securechannel_manager.h"
 
 UA_Int32 Service_OpenSecureChannel(UA_Server *server, UA_Connection *connection,
                                    const UA_OpenSecureChannelRequest *request,

+ 1 - 6
src/server/ua_services_subscription.c

@@ -1,11 +1,6 @@
-/*
- * ua_services_subscription.c
- *
- *  Created on: 18.06.2014
- *      Author: root
- */
 #include "ua_services.h"
 #include "ua_statuscodes.h"
+#include "util/ua_util.h"
 
 UA_Int32 Service_CreateSubscription(UA_Server *server, UA_Session *session,
                                     const UA_CreateSubscriptionRequest *request,

+ 2 - 0
src/server/ua_services_view.c

@@ -1,5 +1,7 @@
 #include "ua_services.h"
 #include "ua_statuscodes.h"
+#include "ua_nodestore.h"
+#include "util/ua_util.h"
 
 UA_Int32 Service_Browse_getReferenceDescription(UA_NodeStore *ns, UA_ReferenceNode *reference,
                                                 UA_UInt32 nodeClassMask, UA_UInt32 resultMask,

+ 2 - 0
src/server/ua_session_manager.c

@@ -1,4 +1,5 @@
 #include "ua_session_manager.h"
+#include "util/ua_util.h"
 #include "util/ua_list.h"
 
 struct UA_SessionManager {
@@ -9,6 +10,7 @@ struct UA_SessionManager {
     UA_DateTime  maxSessionLifeTime;
     UA_DateTime  sessionTimeout;
 };
+
 UA_Int32 UA_SessionManager_new(UA_SessionManager **sessionManager, UA_UInt32 maxSessionCount,
                                UA_UInt32 sessionTimeout, UA_UInt32 startSessionId) {
     UA_Int32 retval = UA_SUCCESS;

+ 1 - 3
src/server/ua_session_manager.h

@@ -1,11 +1,9 @@
 #ifndef UA_SESSION_MANAGER_H_
 #define UA_SESSION_MANAGER_H_
 
+#include "ua_server.h"
 #include "ua_session.h"
 
-struct UA_SessionManager;
-typedef struct UA_SessionManager UA_SessionManager;
-
 UA_Int32 UA_SessionManager_new(UA_SessionManager **sessionManager, UA_UInt32 maxSessionCount,
                                UA_UInt32 sessionLifetime, UA_UInt32 startSessionId);
 

+ 29 - 0
src/ua_config.h.in

@@ -11,3 +11,32 @@
 #else
 #define INLINE __inline
 #endif
+
+/* Visibility */
+#ifdef MSVC
+#define INLINE __inline
+#else
+#define INLINE inline
+#endif
+
+#if defined(_WIN32) || defined(__CYGWIN__)
+  #ifdef open62541_EXPORTS
+    #ifdef __GNUC__
+      #define UA_LIBEXPORT __attribute__ ((dllexport))
+    #else
+      #define UA_LIBEXPORT __declspec(dllexport)
+    #endif
+  #else
+    #ifdef __GNUC__
+      #define UA_LIBEXPORT __attribute__ ((dllimport))
+    #else
+      #define UA_LIBEXPORT __declspec(dllimport)
+    #endif
+  #endif
+#else
+  #if __GNUC__ >= 4 || __clang__
+    #define UA_LIBEXPORT __attribute__ ((visibility ("default")))
+  #else
+    #define UA_LIBEXPORT
+  #endif
+#endif

+ 4 - 4
src/ua_connection.h

@@ -27,7 +27,7 @@ typedef struct UA_ConnectionConfig {
     UA_UInt32 maxChunkCount;
 } UA_ConnectionConfig;
 
-extern UA_ConnectionConfig UA_ConnectionConfig_standard;
+extern UA_LIBEXPORT UA_ConnectionConfig UA_ConnectionConfig_standard;
 
 /* Forward declaration */
 struct UA_SecureChannel;
@@ -46,9 +46,9 @@ typedef struct UA_Connection {
     UA_Connection_closeCallback close;
 } UA_Connection;
 
-UA_Int32 UA_Connection_init(UA_Connection *connection, UA_ConnectionConfig localConf, void *callbackHandle,
-                            UA_Connection_closeCallback close, UA_Connection_writeCallback write);
-UA_Int32 UA_Connection_deleteMembers(UA_Connection *connection);
+UA_Int32 UA_LIBEXPORT UA_Connection_init(UA_Connection *connection, UA_ConnectionConfig localConf, void *callbackHandle,
+                                       UA_Connection_closeCallback close, UA_Connection_writeCallback write);
+UA_Int32 UA_LIBEXPORT UA_Connection_deleteMembers(UA_Connection *connection);
 
 // todo: closing a binaryconnection that was closed on the network level
 

+ 1 - 0
src/ua_securechannel.c

@@ -1,6 +1,7 @@
 #include <time.h>
 #include <stdlib.h>
 #include "ua_securechannel.h"
+#include "util/ua_util.h"
 
 UA_Int32 UA_SecureChannel_init(UA_SecureChannel *channel) {
     UA_AsymmetricAlgorithmSecurityHeader_init(&channel->clientAsymAlgSettings);

+ 1 - 0
src/ua_securechannel.h

@@ -3,6 +3,7 @@
 
 #include "ua_types_generated.h"
 #include "ua_transport.h"
+#include "ua_transport_generated.h"
 #include "ua_connection.h"
 
 /**

+ 1 - 0
src/ua_session.c

@@ -2,6 +2,7 @@
 #include <stdlib.h>
 
 #include "ua_session.h"
+#include "util/ua_util.h"
 
 UA_Int32 UA_Session_new(UA_Session **session) {
     UA_Int32 retval = UA_SUCCESS;

+ 1 - 0
src/ua_transport.c

@@ -2,6 +2,7 @@
 #include <stdio.h>
 #endif
 #include "ua_transport.h"
+#include "util/ua_util.h"
 
 UA_TYPE_DEFAULT(UA_MessageType)
 UA_Int32 UA_MessageType_calcSizeBinary(UA_MessageType const *ptr) {

+ 0 - 1
src/ua_transport.h

@@ -32,6 +32,5 @@ void UA_MessageType_printf(char *label, UA_MessageType *p);
 #endif
 
 /* All other transport types are auto-generated from a schema definition. */
-#include "ua_transport_generated.h"
 
 #endif /* UA_TRANSPORT_H_ */

+ 51 - 41
src/ua_types.h

@@ -16,6 +16,10 @@
 #ifndef UA_TYPES_H_
 #define UA_TYPES_H_
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 #include "ua_config.h"
 #include <stdio.h>
 #include <stdint.h>
@@ -48,6 +52,8 @@
  * @{
  */
 
+#define UA_NULL ((void *)0)
+
 /* Function return values */
 #define UA_SUCCESS 0
 #define UA_NO_ERROR UA_SUCCESS
@@ -264,19 +270,19 @@ typedef void UA_InvalidType;
 
 #ifdef DEBUG
 #define UA_TYPE_PROTOTYPES(TYPE)                      \
-    UA_Int32 TYPE##_new(TYPE **p);                    \
-    UA_Int32 TYPE##_init(TYPE * p);                   \
-    UA_Int32 TYPE##_delete(TYPE * p);                 \
-    UA_Int32 TYPE##_deleteMembers(TYPE * p);          \
-    UA_Int32 TYPE##_copy(const TYPE *src, TYPE *dst); \
-    void     TYPE##_print(const TYPE *p, FILE *stream);
+    UA_Int32 UA_LIBEXPORT TYPE##_new(TYPE **p);                    \
+    UA_Int32 UA_LIBEXPORT TYPE##_init(TYPE * p);                   \
+    UA_Int32 UA_LIBEXPORT TYPE##_delete(TYPE * p);                 \
+    UA_Int32 UA_LIBEXPORT TYPE##_deleteMembers(TYPE * p);          \
+    UA_Int32 UA_LIBEXPORT TYPE##_copy(const TYPE *src, TYPE *dst); \
+    void     UA_LIBEXPORT TYPE##_print(const TYPE *p, FILE *stream);
 #else
 #define UA_TYPE_PROTOTYPES(TYPE)             \
-    UA_Int32 TYPE##_new(TYPE **p);           \
-    UA_Int32 TYPE##_init(TYPE * p);          \
-    UA_Int32 TYPE##_delete(TYPE * p);        \
-    UA_Int32 TYPE##_deleteMembers(TYPE * p); \
-    UA_Int32 TYPE##_copy(const TYPE *src, TYPE *dst);
+    UA_Int32 UA_LIBEXPORT TYPE##_new(TYPE **p);           \
+    UA_Int32 UA_LIBEXPORT TYPE##_init(TYPE * p);          \
+    UA_Int32 UA_LIBEXPORT TYPE##_delete(TYPE * p);        \
+    UA_Int32 UA_LIBEXPORT TYPE##_deleteMembers(TYPE * p); \
+    UA_Int32 UA_LIBEXPORT TYPE##_copy(const TYPE *src, TYPE *dst);
 #endif
 
 /* Functions for all types */
@@ -313,17 +319,17 @@ UA_TYPE_PROTOTYPES(UA_InvalidType)
         VARIABLE.length = sizeof(STRING)-1;     \
         VARIABLE.data   = (UA_Byte *)STRING; } while(0)
 
-UA_Int32 UA_String_copycstring(char const *src, UA_String *dst);
-UA_Int32 UA_String_copyprintf(char const *fmt, UA_String *dst, ...);
-UA_Int32 UA_String_equal(const UA_String *string1, const UA_String *string2);
+UA_Int32 UA_LIBEXPORT UA_String_copycstring(char const *src, UA_String *dst);
+UA_Int32 UA_LIBEXPORT UA_String_copyprintf(char const *fmt, UA_String *dst, ...);
+UA_Int32 UA_LIBEXPORT UA_String_equal(const UA_String *string1, const UA_String *string2);
 #ifdef DEBUG
-void UA_String_printf(char const *label, const UA_String *string);
-void UA_String_printx(char const *label, const UA_String *string);
-void UA_String_printx_hex(char const *label, const UA_String *string);
+void UA_LIBEXPORT UA_String_printf(char const *label, const UA_String *string);
+void UA_LIBEXPORT UA_String_printx(char const *label, const UA_String *string);
+void UA_LIBEXPORT UA_String_printx_hex(char const *label, const UA_String *string);
 #endif
 
 /* DateTime */
-UA_DateTime UA_DateTime_now();
+UA_DateTime UA_LIBEXPORT UA_DateTime_now();
 typedef struct UA_DateTimeStruct {
     UA_Int16 nanoSec;
     UA_Int16 microSec;
@@ -335,32 +341,32 @@ typedef struct UA_DateTimeStruct {
     UA_Int16 mounth;
     UA_Int16 year;
 } UA_DateTimeStruct;
-UA_DateTimeStruct UA_DateTime_toStruct(UA_DateTime time);
-UA_Int32 UA_DateTime_toString(UA_DateTime time, UA_String *timeString);
+UA_DateTimeStruct UA_LIBEXPORT UA_DateTime_toStruct(UA_DateTime time);
+UA_Int32 UA_LIBEXPORT UA_DateTime_toString(UA_DateTime time, UA_String *timeString);
 
 /* Guid */
-UA_Int32 UA_Guid_equal(const UA_Guid *g1, const UA_Guid *g2);
+UA_Int32 UA_LIBEXPORT UA_Guid_equal(const UA_Guid *g1, const UA_Guid *g2);
 
 /* ByteString */
-UA_Int32 UA_ByteString_equal(const UA_ByteString *string1, const UA_ByteString *string2);
-UA_Int32 UA_ByteString_newMembers(UA_ByteString *p, UA_Int32 length);
+UA_Int32 UA_LIBEXPORT UA_ByteString_equal(const UA_ByteString *string1, const UA_ByteString *string2);
+UA_Int32 UA_LIBEXPORT UA_ByteString_newMembers(UA_ByteString *p, UA_Int32 length);
 #ifdef DEBUG
-void UA_ByteString_printf(char *label, const UA_ByteString *string);
-void UA_ByteString_printx(char *label, const UA_ByteString *string);
-void UA_ByteString_printx_hex(char *label, const UA_ByteString *string);
+void UA_LIBEXPORT UA_ByteString_printf(char *label, const UA_ByteString *string);
+void UA_LIBEXPORT UA_ByteString_printx(char *label, const UA_ByteString *string);
+void UA_LIBEXPORT UA_ByteString_printx_hex(char *label, const UA_ByteString *string);
 #endif
 
 /* NodeId */
-UA_Int32 UA_NodeId_equal(const UA_NodeId *n1, const UA_NodeId *n2);
-UA_Boolean UA_NodeId_isNull(const UA_NodeId *p);
-UA_Boolean UA_NodeId_isBasicType(UA_NodeId const *id);
+UA_Int32 UA_LIBEXPORT UA_NodeId_equal(const UA_NodeId *n1, const UA_NodeId *n2);
+UA_Boolean UA_LIBEXPORT UA_NodeId_isNull(const UA_NodeId *p);
+UA_Boolean UA_LIBEXPORT UA_NodeId_isBasicType(UA_NodeId const *id);
 
 #define NS0NODEID(NUMERIC_ID)                                                                        \
     (UA_NodeId) {.namespaceIndex = 0, .identifierType = UA_NODEIDTYPE_NUMERIC, .identifier.numeric = \
                      NUMERIC_ID }
 
 /* ExpandedNodeId */
-UA_Boolean UA_ExpandedNodeId_isNull(const UA_ExpandedNodeId *p);
+UA_Boolean UA_LIBEXPORT UA_ExpandedNodeId_isNull(const UA_ExpandedNodeId *p);
 
 #define NS0EXPANDEDNODEID(VARIABLE, NUMERIC_ID) do {   \
         VARIABLE.nodeId       = NS0NODEID(NUMERIC_ID); \
@@ -371,9 +377,9 @@ UA_Boolean UA_ExpandedNodeId_isNull(const UA_ExpandedNodeId *p);
 #define UA_QUALIFIEDNAME_STATIC(VARIABLE, STRING) do { \
         VARIABLE.namespaceIndex = 0;                   \
         UA_STRING_STATIC(VARIABLE.name, STRING); } while(0)
-UA_Int32 UA_QualifiedName_copycstring(char const *src, UA_QualifiedName *dst);
+UA_Int32 UA_LIBEXPORT UA_QualifiedName_copycstring(char const *src, UA_QualifiedName *dst);
 #ifdef DEBUG
-void UA_QualifiedName_printf(char const *label, const UA_QualifiedName *qn);
+void UA_LIBEXPORT UA_QualifiedName_printf(char const *label, const UA_QualifiedName *qn);
 #endif
 
 /* LocalizedText */
@@ -381,27 +387,27 @@ void UA_QualifiedName_printf(char const *label, const UA_QualifiedName *qn);
         UA_STRING_STATIC(VARIABLE.locale, "en");       \
         UA_STRING_STATIC(VARIABLE.text, STRING); } while(0)
 
-UA_Int32 UA_LocalizedText_copycstring(char const *src, UA_LocalizedText *dst);
+UA_Int32 UA_LIBEXPORT UA_LocalizedText_copycstring(char const *src, UA_LocalizedText *dst);
 
 /* Variant */
-UA_Int32 UA_Variant_copySetValue(UA_Variant *v, UA_VTable_Entry *vt, const void *value);
-UA_Int32 UA_Variant_copySetArray(UA_Variant *v, UA_VTable_Entry *vt, UA_Int32 arrayLength, const void *array);
+UA_Int32 UA_LIBEXPORT UA_Variant_copySetValue(UA_Variant *v, UA_VTable_Entry *vt, const void *value);
+UA_Int32 UA_LIBEXPORT UA_Variant_copySetArray(UA_Variant *v, UA_VTable_Entry *vt, UA_Int32 arrayLength, const void *array);
 
 /** @brief Allows to define variants whose payload will not be deleted. This is
    achieved by a second vtable. The functionality can be used e.g. when
    UA_VariableNodes point into a "father" structured object that is stored in an
    UA_VariableNode itself. This is not possible for arrays so far. */
-UA_Int32 UA_Variant_borrowSetValue(UA_Variant *v, UA_VTable_Entry *vt, const void *value);
+UA_Int32 UA_LIBEXPORT UA_Variant_borrowSetValue(UA_Variant *v, UA_VTable_Entry *vt, const void *value);
 
 /* Array operations */
-UA_Int32 UA_Array_new(void **p, UA_Int32 noElements, UA_VTable_Entry *vt);
-UA_Int32 UA_Array_init(void *p, UA_Int32 noElements, UA_VTable_Entry *vt);
-UA_Int32 UA_Array_delete(void *p, UA_Int32 noElements, UA_VTable_Entry *vt);
+UA_Int32 UA_LIBEXPORT UA_Array_new(void **p, UA_Int32 noElements, UA_VTable_Entry *vt);
+UA_Int32 UA_LIBEXPORT UA_Array_init(void *p, UA_Int32 noElements, UA_VTable_Entry *vt);
+UA_Int32 UA_LIBEXPORT UA_Array_delete(void *p, UA_Int32 noElements, UA_VTable_Entry *vt);
 
 /* @brief The destination array is allocated according to noElements. */
-UA_Int32 UA_Array_copy(const void *src, UA_Int32 noElements, UA_VTable_Entry *vt, void **dst);
+UA_Int32 UA_LIBEXPORT UA_Array_copy(const void *src, UA_Int32 noElements, UA_VTable_Entry *vt, void **dst);
 #ifdef DEBUG
-void UA_Array_print(const void *p, UA_Int32 noElements, UA_VTable_Entry *vt, FILE *stream);
+void UA_LIBEXPORT UA_Array_print(const void *p, UA_Int32 noElements, UA_VTable_Entry *vt, FILE *stream);
 #endif
 
 /**********/
@@ -529,4 +535,8 @@ typedef struct UA_VTable {
 
 /// @} /* end of group */
 
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
 #endif /* UA_TYPES_H_ */

+ 1 - 0
src/ua_types_encoding_binary.c

@@ -1,4 +1,5 @@
 #include "ua_types_encoding_binary.h"
+#include "util/ua_util.h"
 #include "ua_namespace_0.h"
 
 static INLINE UA_Boolean is_builtin(UA_NodeId *typeid ) {

+ 0 - 6
src/util/ua_util.c

@@ -12,9 +12,3 @@ UA_Int32 UA_memcpy(void *dst, void const *src, UA_Int32 size) {
     memcpy(dst, src, size);
     return UA_SUCCESS;
 }
-
-UA_Int32 UA_VTable_isValidType(UA_Int32 type) {
-    if(type < 0 /* UA_BOOLEAN */ || type > 271 /* UA_INVALID */)
-        return UA_ERR_INVALID_VALUE;
-    return UA_SUCCESS;
-}

+ 5 - 18
src/util/ua_util.h

@@ -1,5 +1,5 @@
-#ifndef UA_UTILITY_H_
-#define UA_UTILITY_H_
+#ifndef UA_UTIL_H_
+#define UA_UTIL_H_
 
 #include <stdio.h>  // printf
 #include <stdlib.h> // malloc, free
@@ -38,19 +38,9 @@
 # endif
 #endif
 
-#ifdef MSVC
-#define INLINE __inline
-#else
-#define INLINE inline
-#endif
-
-/* Global Variables */
-extern UA_ByteString UA_ByteString_securityPoliceNone;
-void const *UA_alloc_lastptr;
+#define UA_assert(ignore) assert(ignore)
 
 /* Heap memory functions */
-#define UA_NULL ((void *)0)
-
 INLINE UA_Int32 _UA_free(void *ptr, char *pname, char *f, UA_Int32 l) {
     DBG_VERBOSE(printf("UA_free;%p;;%s;;%s;%d\n", ptr, pname, f, l); fflush(stdout));
     free(ptr); // checks if ptr != NULL in the background
@@ -60,7 +50,7 @@ INLINE UA_Int32 _UA_free(void *ptr, char *pname, char *f, UA_Int32 l) {
 INLINE UA_Int32 _UA_alloc(void **ptr, UA_Int32 size, char *pname, char *sname, char *f, UA_Int32 l) {
     if(ptr == UA_NULL)
         return UA_ERR_INVALID_VALUE;
-    UA_alloc_lastptr = *ptr = malloc(size);
+    *ptr = malloc(size);
     DBG_VERBOSE(printf("UA_alloc - %p;%d;%s;%s;%s;%d\n", *ptr, size, pname, sname, f, l); fflush(stdout));
     if(*ptr == UA_NULL)
         return UA_ERR_NO_MEMORY;
@@ -80,7 +70,6 @@ INLINE UA_Int32 _UA_alloca(void **ptr, UA_Int32 size, char *pname, char *sname,
 }
 
 UA_Int32 UA_memcpy(void *dst, void const *src, UA_Int32 size);
-UA_Int32 UA_VTable_isValidType(UA_Int32 type);
 
 #define UA_free(ptr) _UA_free(ptr, # ptr, __FILE__, __LINE__)
 #define UA_alloc(ptr, size) _UA_alloc(ptr, size, # ptr, # size, __FILE__, __LINE__)
@@ -92,6 +81,4 @@ UA_Int32 UA_VTable_isValidType(UA_Int32 type);
     proper UA_alloc. */
 #define UA_alloca(ptr, size) _UA_alloca(ptr, size, # ptr, # size, __FILE__, __LINE__)
 
-#define UA_assert(ignore) assert(ignore)
-
-#endif /* UA_UTILITY_H_ */
+#endif /* UA_UTIL_H_ */

+ 1 - 4
tests/check_builtin.c

@@ -4,6 +4,7 @@
 #include "ua_types_encoding_binary.h"
 #include "ua_namespace_0.h"
 #include "ua_transport.h"
+#include "util/ua_util.h"
 #include "check.h"
 
 START_TEST(UA_Boolean_calcSizeWithNullArgumentShallReturnStorageSize) {
@@ -761,7 +762,6 @@ START_TEST(UA_String_decodeShallAllocateMemoryAndCopyString) {
 	// then
 	ck_assert_int_eq(retval, UA_SUCCESS);
 	ck_assert_int_eq(dst.length, 8);
-	ck_assert_ptr_eq(dst.data, UA_alloc_lastptr);
 	ck_assert_int_eq(dst.data[3], 'L');
 	// finally
 	UA_String_deleteMembers(&dst);
@@ -848,7 +848,6 @@ START_TEST(UA_NodeId_decodeStringShallAllocateMemory) {
 	ck_assert_int_eq(dst.identifierType, UA_NODEIDTYPE_STRING);
 	ck_assert_int_eq(dst.namespaceIndex, 1);
 	ck_assert_int_eq(dst.identifier.string.length, 3);
-	ck_assert_ptr_eq(dst.identifier.string.data, UA_alloc_lastptr);
 	ck_assert_int_eq(dst.identifier.string.data[1], 'L');
 	// finally
 	UA_NodeId_deleteMembers(&dst);
@@ -867,7 +866,6 @@ START_TEST(UA_Variant_decodeWithOutArrayFlagSetShallSetVTAndAllocateMemoryForArr
 	ck_assert_int_eq(pos, 5);
 	ck_assert_ptr_eq(dst.vt, &UA_.types[UA_INT32]);
 	ck_assert_int_eq(dst.arrayLength, 1);
-	ck_assert_ptr_eq(dst.data, UA_alloc_lastptr);
 	ck_assert_int_eq(*(UA_Int32 *)dst.data, 255);
 	// finally
 	UA_Variant_deleteMembers(&dst);
@@ -890,7 +888,6 @@ START_TEST(UA_Variant_decodeWithArrayFlagSetShallSetVTAndAllocateMemoryForArray)
 	ck_assert_int_eq(pos, 1+4+2*4);
 	ck_assert_ptr_eq(dst.vt, &UA_.types[UA_INT32]);
 	ck_assert_int_eq(dst.arrayLength, 2);
-	ck_assert_ptr_eq(dst.data, UA_alloc_lastptr);
 	ck_assert_int_eq(((UA_Int32 *)dst.data)[0], 255);
 	ck_assert_int_eq(((UA_Int32 *)dst.data)[1], -1);
 	// finally

+ 1 - 0
tests/check_nodestore.c

@@ -4,6 +4,7 @@
 
 #include "ua_types.h"
 #include "server/ua_nodestore.h"
+#include "util/ua_util.h"
 #include "check.h"
 
 #ifdef MULTITHREADING

+ 2 - 3
tools/generate_builtin.py

@@ -310,9 +310,8 @@ printc('''/**
  * on host '''+platform.uname()[1]+''' by user '''+getpass.getuser()+''' at '''+ time.strftime("%Y-%m-%d %I:%M:%S")+'''
  */
  
-#include "''' + args.outfile.split("/")[-1] + '.h"\n')
-#include "ua_types_encoding_binary.h"
-#include "util/ua_util.h"
+#include "''' + args.outfile.split("/")[-1] + '''.h"
+#include "util/ua_util.h"\n''')
 
 # types for which we create a vector type
 arraytypes = set()

+ 1 - 1
tools/generate_namespace.py

@@ -94,7 +94,6 @@ printh('''/**********************************************************
  **********************************************************/\n 
 #ifndef ''' + args.outfile.upper().split("/")[-1] + '''_H_
 #define ''' + args.outfile.upper().split("/")[-1] + '''_H_\n
-#include "util/ua_util.h"
 #include "ua_types.h"  // definition of UA_VTable and basic UA_Types
 #include "ua_types_generated.h"\n
 /**
@@ -124,6 +123,7 @@ printc('''/**********************************************************
        ''' at '''+ time.strftime("%Y-%m-%d %I:%M:%S")+'''
  **********************************************************/\n
 #include "''' + args.outfile.split("/")[-1] + '''.h"\n
+#include "util/ua_util.h"
 UA_Int32 UA_ns0ToVTableIndex(const UA_NodeId *id) {
 	UA_Int32 retval = 0; // InvalidType
         if(id->namespaceIndex != 0) return retval;