Browse Source

Further adaption to architecture folder

# Conflicts:
#	plugins/ua_log_socket_error.h
Stefan Profanter 6 years ago
parent
commit
a0d6e2b166
45 changed files with 668 additions and 702 deletions
  1. 23 11
      CMakeLists.txt
  2. 2 0
      plugins/arch/CMakeLists.txt
  3. 8 43
      plugins/arch/Readme.md
  4. 0 0
      arch/arduino/CMakeLists.txt
  5. 1 0
      plugins/arch/freertos/CMakeLists.txt
  6. 30 54
      plugins/arch/freertos/ua_architecture.h
  7. 45 0
      arch/freertos/ua_architecture_functions.c
  8. 1 15
      plugins/arch/freertos/ua_clock.c
  9. 1 0
      plugins/arch/posix/CMakeLists.txt
  10. 34 40
      plugins/arch/posix/ua_architecture.h
  11. 29 0
      arch/posix/ua_architecture_functions.c
  12. 1 15
      plugins/arch/posix/ua_clock.c
  13. 159 0
      arch/ua_architecture_functions.h
  14. 57 64
      plugins/ua_network_tcp.c
  15. 0 0
      arch/ua_network_tcp.h
  16. 1 8
      plugins/ua_network_udp.c
  17. 0 0
      arch/ua_network_udp.h
  18. 1 0
      plugins/arch/vxworks/CMakeLists.txt
  19. 44 38
      plugins/arch/vxworks/ua_architecture.h
  20. 29 0
      arch/vxworks/ua_architecture_functions.c
  21. 0 0
      arch/vxworks/ua_clock.c
  22. 2 0
      plugins/arch/win32/CMakeLists.txt
  23. 125 0
      arch/win32/ua_architecture.h
  24. 31 0
      arch/win32/ua_architecture_functions.c
  25. 1 2
      plugins/arch/win32/ua_clock.c
  26. 0 21
      examples/client_connect_loop.c
  27. 0 21
      examples/client_subscription_loop.c
  28. 1 6
      examples/server_mainloop.c
  29. 2 27
      include/ua_config.h.in
  30. 0 2
      include/ua_plugin_network.h
  31. 0 3
      plugins/CMakeLists.txt
  32. 0 102
      plugins/arch/win32/ua_architecture.h
  33. 0 37
      plugins/ua_log_socket_error.h
  34. 0 13
      src/server/ua_mdns.c
  35. 1 5
      src/server/ua_server.c
  36. 1 5
      src/server/ua_server_internal.h
  37. 2 11
      src/server/ua_services_discovery.c
  38. 21 100
      src/server/ua_services_discovery_multicast.c
  39. 2 2
      tests/CMakeLists.txt
  40. 0 4
      tests/client/check_client_async.c
  41. 2 2
      tests/fuzz/CMakeLists.txt
  42. 3 20
      tests/server/check_discovery.c
  43. 1 18
      tests/testing-plugins/testing_clock.c
  44. 0 13
      tools/amalgamate.py
  45. 7 0
      tools/cmake/macros.cmake

+ 23 - 11
CMakeLists.txt

@@ -64,7 +64,7 @@ endif(${UA_ARCHITECTURE} STREQUAL "None")
 
 message(STATUS "The selected architecture is ${UA_ARCHITECTURE}")
 
-add_subdirectory(plugins)
+add_subdirectory(arch)
 
 GET_PROPERTY(architectures GLOBAL PROPERTY UA_ARCHITECTURES)
 list(SORT architectures)
@@ -77,6 +77,17 @@ GET_PROPERTY(ua_architecture_headers GLOBAL PROPERTY UA_ARCHITECTURE_HEADERS)
 
 GET_PROPERTY(ua_architecture_sources GLOBAL PROPERTY UA_ARCHITECTURE_SOURCES)
 
+set(ua_architecture_sources ${ua_architecture_sources}
+            ${PROJECT_SOURCE_DIR}/arch/ua_network_tcp.c
+)
+
+set(ua_architecture_headers ${ua_architecture_headers}
+            ${PROJECT_SOURCE_DIR}/arch/ua_network_tcp.h
+            ${PROJECT_SOURCE_DIR}/arch/ua_architecture_functions.h
+)
+
+
+
 if(${UA_ARCHITECTURE} STREQUAL "None")
   message(FATAL_ERROR "No architecture was selected. Please select the architecture of your target platform")
 endif(${UA_ARCHITECTURE} STREQUAL "None")
@@ -353,13 +364,13 @@ include_directories(${PROJECT_SOURCE_DIR}/include
                     ${PROJECT_BINARY_DIR}/src_generated
                     ${MBEDTLS_INCLUDE_DIRS})
 
-set(exported_headers ${PROJECT_BINARY_DIR}/src_generated/ua_config.h
-                     ${PROJECT_SOURCE_DIR}/include/ua_types.h
+set(exported_headers ${PROJECT_SOURCE_DIR}/arch/${UA_ARCHITECTURE}/ua_architecture.h
+                     ${PROJECT_BINARY_DIR}/src_generated/ua_config.h
+                     ${PROJECT_SOURCE_DIR}/deps/ms_stdint.h
                      ${PROJECT_BINARY_DIR}/src_generated/ua_statuscodes.h
                      ${PROJECT_BINARY_DIR}/src_generated/ua_nodeids.h
                      ${PROJECT_SOURCE_DIR}/include/ua_constants.h
-                     ${PROJECT_SOURCE_DIR}/plugins/arch/${UA_ARCHITECTURE}/ua_architecture.h
-                     ${PROJECT_SOURCE_DIR}/deps/ms_stdint.h
+                     ${PROJECT_SOURCE_DIR}/include/ua_types.h
                      ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated.h
                      ${PROJECT_BINARY_DIR}/src_generated/ua_types_generated_handling.h
                      ${PROJECT_SOURCE_DIR}/include/ua_server.h
@@ -442,18 +453,15 @@ set(lib_sources ${PROJECT_SOURCE_DIR}/src/ua_types.c
                 ${PROJECT_SOURCE_DIR}/deps/libc_time.c
                 ${PROJECT_SOURCE_DIR}/deps/pcg_basic.c)
 
-set(default_plugin_headers ${PROJECT_SOURCE_DIR}/plugins/ua_network_tcp.h
-                           ${PROJECT_SOURCE_DIR}/plugins/ua_accesscontrol_default.h
+set(default_plugin_headers ${PROJECT_SOURCE_DIR}/plugins/ua_accesscontrol_default.h
                            ${PROJECT_SOURCE_DIR}/plugins/ua_pki_certificate.h
                            ${PROJECT_SOURCE_DIR}/plugins/ua_log_stdout.h
                            ${PROJECT_SOURCE_DIR}/plugins/ua_nodestore_default.h
                            ${PROJECT_SOURCE_DIR}/plugins/ua_config_default.h
                            ${PROJECT_SOURCE_DIR}/plugins/ua_securitypolicy_none.h
-                           ${PROJECT_SOURCE_DIR}/plugins/ua_log_socket_error.h
 )
 
-set(default_plugin_sources ${PROJECT_SOURCE_DIR}/plugins/ua_network_tcp.c
-                           ${PROJECT_SOURCE_DIR}/plugins/ua_log_stdout.c
+set(default_plugin_sources ${PROJECT_SOURCE_DIR}/plugins/ua_log_stdout.c
                            ${PROJECT_SOURCE_DIR}/plugins/ua_accesscontrol_default.c
                            ${PROJECT_SOURCE_DIR}/plugins/ua_pki_certificate.c
                            ${PROJECT_SOURCE_DIR}/plugins/ua_nodestore_default.c
@@ -485,7 +493,7 @@ if(UA_DEBUG_DUMP_PKGS)
 endif()
 
 if(UA_ENABLE_NONSTANDARD_UDP)
-    list(APPEND exported_headers ${PROJECT_SOURCE_DIR}/plugins/ua_network_udp.h)
+    list(APPEND exported_headers ${PROJECT_SOURCE_DIR}/arch/ua_network_udp.h)
 endif()
 
 if(UA_ENABLE_DISCOVERY_MULTICAST)
@@ -795,10 +803,14 @@ add_custom_target(cpplint cpplint
                   ${internal_headers}
                   ${default_plugin_headers}
                   ${default_plugin_sources}
+                  ${ua_architecture_headers}
+                  ${ua_architecture_sources}
                   DEPENDS ${lib_sources}
                           ${internal_headers}
                           ${default_plugin_headers}
                           ${default_plugin_sources}
+                          ${ua_architecture_headers}
+                          ${ua_architecture_sources}
 
                   COMMENT "Run cpplint code style checker on the library")
 

+ 2 - 0
plugins/arch/CMakeLists.txt

@@ -1,5 +1,7 @@
 SET(SOURCE_GROUP ${SOURCE_GROUP}\\arch)
 
+ua_include_directories(${CMAKE_CURRENT_SOURCE_DIR}) #to have access to ua_network_tcp.h and udp.h
+
 add_subdirectory(posix)
 add_subdirectory(win32)
 add_subdirectory(arduino)

+ 8 - 43
plugins/arch/Readme.md

@@ -63,19 +63,12 @@
     * Define and include all that's needed for your architecture
     */
     
-    
-    
-    /*
-    * Implement int UA_sleep_ms(unsigned int miliSeconds);
-    */ 
-    
     /*
     * Define OPTVAL_TYPE for non windows systems. In doubt, use int //TODO: Is this really necessary
     */
     
-    
     /*
-    * Define the following network options for ipv4 and ipv6 if they are enabled or not
+    * Define the following network options
     */
     
     
@@ -94,47 +87,19 @@
     * Define the ua_getnameinfo if your architecture supports it
     */
     
-    
-    
     /*
-    * Implement the following socket functions (you can #define them): 
+    * Use #define for the functions defined in ua_architecture_functions.h
+    * or implement them in a ua_architecture_functions.c file and 
+    * put it in your new_arch folder and add it in the CMakeLists.txt file 
+    * using ua_add_architecture_file(${CMAKE_CURRENT_SOURCE_DIR}/ua_architecture_functions.c)
     */ 
     
-    #include "ua_types.h"
-    
-    /* ssize_t ua_send(UA_SOCKET sockfd, const void *buf, size_t len, int flags);
-    * int ua_select(UA_SOCKET nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
-    * ssize_t ua_recv(UA_SOCKET sockfd, void *buf, size_t len, int flags);
-    * int ua_shutdown(UA_SOCKET sockfd, int how);
-    * UA_SOCKET ua_socket(int domain, int type, int protocol);
-    * int ua_bind(UA_SOCKET sockfd, const struct sockaddr *addr, socklen_t addrlen);
-    * int ua_listen(UA_SOCKET sockfd, int backlog);
-    * int ua_accept(UA_SOCKET sockfd, struct sockaddr *addr, socklen_t *addrlen);
-    * int ua_close(UA_SOCKET sockfd);
-    * int ua_connect(UA_SOCKET sockfd, const struct sockaddr *addr, socklen_t addrlen);
-    * void UA_fd_set(UA_SOCKET fd, fd_set *set);
-    * int UA_fd_isset(UA_SOCKET fd, fd_set *set)
-    * const char* ua_translate_error(int errorCode)
-    * int ua_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res);
-    * UA_StatusCode socket_set_blocking(UA_SOCKET sockfd); 
-    * UA_StatusCode socket_set_nonblocking(UA_SOCKET sockfd); 
-    * int ua_getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen); //Only in non windows architectures
-    * int ua_setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);
-    * void ua_freeaddrinfo(struct addrinfo *res);
-    */
-    
     /*
-    * Define int ua_snprintf(char* pa_stream, size_t pa_size, const char* pa_format, ...);
+    * Define UA_LOG_SOCKET_ERRNO_WRAP(LOG) which prints the string error given a char* errno_str variable
+    * Do the same for UA_LOG_SOCKET_ERRNO_GAI_WRAP(LOG) for errors related to getaddrinfo
     */
     
-    
-    /*
-    * Define
-    * void ua_initialize_architecture_network(void);
-    * void ua_deinitialize_architecture_network(void);
-    */
-    
-    
+    #include "../ua_architecture_functions.h"
     
     #endif /* PLUGINS_ARCH_NEW_ARCH_UA_ARCHITECTURE_H_ */
     

plugins/arch/arduino/CMakeLists.txt → arch/arduino/CMakeLists.txt


+ 1 - 0
plugins/arch/freertos/CMakeLists.txt

@@ -6,6 +6,7 @@ if("${UA_ARCHITECTURE}" STREQUAL "freertos")
 
     ua_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
     ua_add_architecture_file(${CMAKE_CURRENT_SOURCE_DIR}/ua_clock.c)
+    ua_add_architecture_file(${CMAKE_CURRENT_SOURCE_DIR}/ua_architecture_functions.c)
     
     SET(UA_FREERTOS_INCLUDES "" CACHE STRING "Folders to include from the freeRTOS OS")
     ua_include_directories(${UA_FREERTOS_INCLUDES})

+ 30 - 54
plugins/arch/freertos/ua_architecture.h

@@ -21,7 +21,7 @@
 #include <string.h>
 
 #define LWIP_TIMEVAL_PRIVATE 0
-#define LWIP_COMPAT_MUTEX 0
+//#define LWIP_COMPAT_MUTEX 0
 #define LWIP_POSIX_SOCKETS_IO_NAMES 0
 #ifdef LWIP_COMPAT_SOCKETS
 #undef LWIP_COMPAT_SOCKETS
@@ -44,6 +44,8 @@
 #define UA_fd_set(fd, fds) FD_SET((unsigned int)fd, fds)
 #define UA_fd_isset(fd, fds) FD_ISSET((unsigned int)fd, fds)
 
+#define UA_access access
+
 #define UA_IPV6 0
 #define UA_SOCKET int
 #define UA_INVALID_SOCKET -1
@@ -54,64 +56,38 @@
 #define UA_WOULDBLOCK EWOULDBLOCK
 #define UA_ERR_CONNECTION_PROGRESS EINPROGRESS
 
-#include "ua_types.h"
-
-static UA_INLINE int gethostname_freertos(char* name, size_t len){
-  if(strlen(UA_FREERTOS_HOSTNAME) > (len))
-    return -1;
-  strcpy(name, UA_FREERTOS_HOSTNAME);
-  return 0;
-}
-#define gethostname gethostname_freertos
-
-#define ua_send lwip_send
-#define ua_recv lwip_recv
-#define ua_close lwip_close
-#define ua_select lwip_select
-#define ua_shutdown lwip_shutdown
-#define ua_socket lwip_socket
-#define ua_bind lwip_bind
-#define ua_listen lwip_listen
-#define ua_accept lwip_accept
-#define ua_connect lwip_connect
-#define ua_getsockopt lwip_getsockopt
-#define ua_setsockopt lwip_setsockopt
-#define ua_translate_error(x) ""
-#define ua_freeaddrinfo lwip_freeaddrinfo
-
-static UA_INLINE int ua_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res){
-  if(NULL == node){
-    const char* hostname = UA_FREERTOS_HOSTNAME;
-    return lwip_getaddrinfo(hostname, service, hints, res);
-  }else{
-    return lwip_getaddrinfo(node, service, hints, res);
-  }
-}
-
-static UA_INLINE uint32_t socket_set_blocking(UA_SOCKET sockfd){
-  int on = 0;
-  if(lwip_ioctl(sockfd, FIONBIO, &on) < 0)
-    return UA_STATUSCODE_BADINTERNALERROR;
-  return UA_STATUSCODE_GOOD;
-}
-
-static UA_INLINE uint32_t socket_set_nonblocking(UA_SOCKET sockfd){
-  int on = 1;
-  if(lwip_ioctl(sockfd, FIONBIO, &on) < 0)
-    return UA_STATUSCODE_BADINTERNALERROR;
-  return UA_STATUSCODE_GOOD;
-}
+#define UA_send lwip_send
+#define UA_recv lwip_recv
+#define UA_close lwip_close
+#define UA_select lwip_select
+#define UA_shutdown lwip_shutdown
+#define UA_socket lwip_socket
+#define UA_bind lwip_bind
+#define UA_listen lwip_listen
+#define UA_accept lwip_accept
+#define UA_connect lwip_connect
+#define UA_getsockopt lwip_getsockopt
+#define UA_setsockopt lwip_setsockopt
+#define UA_freeaddrinfo lwip_freeaddrinfo
+#define UA_gethostname gethostname_freertos
+
+#define UA_free vPortFree
+#define UA_malloc pvPortMalloc
+#define UA_calloc pvPortCalloc
+#define UA_realloc pvPortRealloc
 
 #include <stdio.h>
-#define ua_snprintf snprintf
+#define UA_snprintf snprintf
 
-static UA_INLINE void ua_initialize_architecture_network(void){
-  return;
-}
+int gethostname_freertos(char* name, size_t len);
 
-static UA_INLINE void ua_deinitialize_architecture_network(void){
-  return;
+#define UA_LOG_SOCKET_ERRNO_WRAP(LOG) { \
+    char *errno_str = ""; \
+    LOG; \
 }
 
+#define UA_LOG_SOCKET_ERRNO_GAI_WRAP UA_LOG_SOCKET_ERRNO_WRAP
+
+#include "../ua_architecture_functions.h"
 
 #endif /* PLUGINS_ARCH_FREERTOS_UA_ARCHITECTURE_H_ */

+ 45 - 0
arch/freertos/ua_architecture_functions.c

@@ -0,0 +1,45 @@
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
+ *
+ *    Copyright 2018 (c) Jose Cabral, fortiss IOSB
+ */
+
+#include "ua_types.h"
+
+unsigned int UA_socket_set_blocking(UA_SOCKET sockfd){
+  int on = 0;
+  if(lwip_ioctl(sockfd, FIONBIO, &on) < 0)
+    return UA_STATUSCODE_BADINTERNALERROR;
+  return UA_STATUSCODE_GOOD;
+}
+
+unsigned int UA_socket_set_nonblocking(UA_SOCKET sockfd){
+  int on = 1;
+  if(lwip_ioctl(sockfd, FIONBIO, &on) < 0)
+    return UA_STATUSCODE_BADINTERNALERROR;
+  return UA_STATUSCODE_GOOD;
+}
+
+int gethostname_freertos(char* name, size_t len){
+  if(strlen(UA_FREERTOS_HOSTNAME) > (len))
+    return -1;
+  strcpy(name, UA_FREERTOS_HOSTNAME);
+  return 0;
+}
+
+int UA_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res){
+  if(NULL == node){
+    const char* hostname = UA_FREERTOS_HOSTNAME;
+    return lwip_getaddrinfo(hostname, service, hints, res);
+  }else{
+    return lwip_getaddrinfo(node, service, hints, res);
+  }
+}
+
+void UA_initialize_architecture_network(void){
+  return;
+}
+
+void UA_deinitialize_architecture_network(void){
+  return;
+}

+ 1 - 15
plugins/arch/freertos/ua_clock.c

@@ -6,24 +6,10 @@
  *    Copyright 2017 (c) Thomas Stalder
  */
 
-/* Enable POSIX features */
-#if !defined(_XOPEN_SOURCE)
-# define _XOPEN_SOURCE 600
-#endif
-#ifndef _DEFAULT_SOURCE
-# define _DEFAULT_SOURCE
-#endif
-/* On older systems we need to define _BSD_SOURCE.
- * _DEFAULT_SOURCE is an alias for that. */
-#ifndef _BSD_SOURCE
-# define _BSD_SOURCE
-#endif
-
+#include "ua_types.h"
 #include <time.h>
 #include <sys/time.h>
 
-#include "ua_types.h"
-
 #include <task.h>
 
 UA_DateTime UA_DateTime_now(void) {

+ 1 - 0
plugins/arch/posix/CMakeLists.txt

@@ -6,5 +6,6 @@ if("${UA_ARCHITECTURE}" STREQUAL "posix")
 
 ua_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
 ua_add_architecture_file(${CMAKE_CURRENT_SOURCE_DIR}/ua_clock.c)
+ua_add_architecture_file(${CMAKE_CURRENT_SOURCE_DIR}/ua_architecture_functions.c)
 
 endif()

+ 34 - 40
plugins/arch/posix/ua_architecture.h

@@ -9,7 +9,7 @@
 #define PLUGINS_ARCH_POSIX_UA_ARCHITECTURE_H_
 
 /* Enable POSIX features */
-#if !defined(_XOPEN_SOURCE)
+#if !defined(_XOPEN_SOURCE) && !defined(_WRS_KERNEL)
 # define _XOPEN_SOURCE 600
 #endif
 #ifndef _DEFAULT_SOURCE
@@ -31,7 +31,6 @@
 
 #define OPTVAL_TYPE int
 
-
 #include <fcntl.h>
 #include <unistd.h> // read, write, close
 
@@ -62,6 +61,8 @@
 # define UA_fd_isset(fd, fds) FD_ISSET(fd, fds)
 #endif
 
+#define UA_access access
+
 #define UA_IPV6 1
 #define UA_SOCKET int
 #define UA_INVALID_SOCKET -1
@@ -72,48 +73,41 @@
 #define UA_WOULDBLOCK EWOULDBLOCK
 #define UA_ERR_CONNECTION_PROGRESS EINPROGRESS
 
-#include "ua_types.h"
-
-#define ua_getnameinfo getnameinfo
-#define ua_send send
-#define ua_recv recv
-#define ua_close close
-#define ua_select select
-#define ua_shutdown shutdown
-#define ua_socket socket
-#define ua_bind bind
-#define ua_listen listen
-#define ua_accept accept
-#define ua_connect connect
-#define ua_translate_error gai_strerror
-#define ua_getaddrinfo getaddrinfo
-#define ua_getsockopt getsockopt
-#define ua_setsockopt setsockopt
-#define ua_freeaddrinfo freeaddrinfo
-
-static UA_INLINE uint32_t socket_set_blocking(UA_SOCKET sockfd){
-  int opts = fcntl(sockfd, F_GETFL);
-  if(opts < 0 || fcntl(sockfd, F_SETFL, opts & (~O_NONBLOCK)) < 0)
-      return UA_STATUSCODE_BADINTERNALERROR;
-  return UA_STATUSCODE_GOOD;
-}
-
-static UA_INLINE uint32_t socket_set_nonblocking(UA_SOCKET sockfd){
-  int opts = fcntl(sockfd, F_GETFL);
-  if(opts < 0 || fcntl(sockfd, F_SETFL, opts | O_NONBLOCK) < 0)
-    return UA_STATUSCODE_BADINTERNALERROR;
-  return UA_STATUSCODE_GOOD;
-}
+#define UA_getnameinfo getnameinfo
+#define UA_send send
+#define UA_recv recv
+#define UA_close close
+#define UA_select select
+#define UA_shutdown shutdown
+#define UA_socket socket
+#define UA_bind bind
+#define UA_listen listen
+#define UA_accept accept
+#define UA_connect connect
+#define UA_getaddrinfo getaddrinfo
+#define UA_getsockopt getsockopt
+#define UA_setsockopt setsockopt
+#define UA_freeaddrinfo freeaddrinfo
+#define UA_gethostname gethostname
+
+#include <stdlib.h>
+#define UA_free free
+#define UA_malloc malloc
+#define UA_calloc calloc
+#define UA_realloc realloc
 
 #include <stdio.h>
-#define ua_snprintf snprintf
+#define UA_snprintf snprintf
 
-static UA_INLINE void ua_initialize_architecture_network(void){
-  return;
+#define UA_LOG_SOCKET_ERRNO_WRAP(LOG) { \
+    char *errno_str = strerror(errno); \
+    LOG; \
 }
-
-static UA_INLINE void ua_deinitialize_architecture_network(void){
-  return;
+#define UA_LOG_SOCKET_ERRNO_GAI_WRAP(LOG) { \
+    const char *errno_str = gai_strerror(errno); \
+    LOG; \
 }
 
+#include "../ua_architecture_functions.h"
+
 #endif /* PLUGINS_ARCH_POSIX_UA_ARCHITECTURE_H_ */

+ 29 - 0
arch/posix/ua_architecture_functions.c

@@ -0,0 +1,29 @@
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
+ *
+ *    Copyright 2018 (c) Jose Cabral, fortiss GmbH
+ */
+
+#include "ua_types.h"
+
+unsigned int UA_socket_set_blocking(UA_SOCKET sockfd){
+  int opts = fcntl(sockfd, F_GETFL);
+  if(opts < 0 || fcntl(sockfd, F_SETFL, opts & (~O_NONBLOCK)) < 0)
+      return UA_STATUSCODE_BADINTERNALERROR;
+  return UA_STATUSCODE_GOOD;
+}
+
+unsigned int UA_socket_set_nonblocking(UA_SOCKET sockfd){
+  int opts = fcntl(sockfd, F_GETFL);
+  if(opts < 0 || fcntl(sockfd, F_SETFL, opts | O_NONBLOCK) < 0)
+    return UA_STATUSCODE_BADINTERNALERROR;
+  return UA_STATUSCODE_GOOD;
+}
+
+void UA_initialize_architecture_network(void){
+  return;
+}
+
+void UA_deinitialize_architecture_network(void){
+  return;
+}

+ 1 - 15
plugins/arch/posix/ua_clock.c

@@ -6,19 +6,7 @@
  *    Copyright 2017 (c) Thomas Stalder, Blue Time Concept SA
  */
 
-/* Enable POSIX features */
-#if !defined(_XOPEN_SOURCE)
-# define _XOPEN_SOURCE 600
-#endif
-#ifndef _DEFAULT_SOURCE
-# define _DEFAULT_SOURCE
-#endif
-/* On older systems we need to define _BSD_SOURCE.
- * _DEFAULT_SOURCE is an alias for that. */
-#ifndef _BSD_SOURCE
-# define _BSD_SOURCE
-#endif
-
+#include "ua_types.h"
 #include <time.h>
 #include <sys/time.h>
 
@@ -27,8 +15,6 @@
 # include <mach/mach.h>
 #endif
 
-#include "ua_types.h"
-
 UA_DateTime UA_DateTime_now(void) {
     struct timeval tv;
     gettimeofday(&tv, NULL);

+ 159 - 0
arch/ua_architecture_functions.h

@@ -0,0 +1,159 @@
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
+ *
+ *    Copyright 2018 (c) Jose Cabral, fortiss GmbH
+ */
+
+/*
+ * This header has all the functions that are architecture dependent. The declaration is behind a ifndef since
+ * they can be previously defined in the ua_architecture.h which include this files at the end
+ */
+
+#ifndef PLUGINS_ARCH_UA_ARCHITECTURE_FUNCTIONS_H_
+#define PLUGINS_ARCH_UA_ARCHITECTURE_FUNCTIONS_H_
+
+#include "ua_config.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Allocation functions
+ */
+
+#ifndef UA_malloc
+void* UA_malloc(size_t size); //allocate memory in the heap with size bytes
+#endif
+
+#ifndef UA_calloc
+void* UA_calloc(size_t num, size_t size); //allocate memory in the heap with size*num bytes and set the memory to zero
+#endif
+
+#ifndef UA_realloc
+void* UA_realloc(void *ptr, size_t new_size);//re-allocate memory in the heap with new_size bytes from previously allocated memory ptr
+#endif
+
+#ifndef UA_free
+void UA_free(void* ptr); //de-allocate memory previously allocated with UA_malloc, UA_calloc or UA_realloc
+#endif
+
+/*
+ * Sleep function
+ */
+
+#ifndef UA_sleep_ms
+int UA_sleep_ms(unsigned int miliSeconds); //suspend the thread for a certain amount of mili seconds
+#endif
+
+/*
+ * Socket functions
+ */
+
+#ifndef UA_send
+ssize_t UA_send(UA_SOCKET sockfd, const void *buf, size_t len, int flags); //equivalent to posix send implementation
+#endif
+
+#ifndef UA_select
+int UA_select(UA_SOCKET nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); //equivalent to posix select implementation
+#endif
+
+#ifndef UA_recv
+ssize_t UA_recv(UA_SOCKET sockfd, void *buf, size_t len, int flags); //equivalent to posix recv implementation
+#endif
+
+#ifndef UA_shutdown
+int UA_shutdown(UA_SOCKET sockfd, int how); //equivalent to posix shutdown implementation
+#endif
+
+#ifndef UA_socket
+UA_SOCKET UA_socket(int domain, int type, int protocol);//equivalent to posix socket implementation
+#endif
+
+#ifndef UA_bind
+int UA_bind(UA_SOCKET sockfd, const struct sockaddr *addr, socklen_t addrlen);//equivalent to posix bind implementation
+#endif
+
+#ifndef UA_listen
+int UA_listen(UA_SOCKET sockfd, int backlog);//equivalent to posix listen implementation
+#endif
+
+#ifndef UA_accept
+int UA_accept(UA_SOCKET sockfd, struct sockaddr *addr, socklen_t *addrlen);//equivalent to posix accept implementation
+#endif
+
+#ifndef UA_close
+int UA_close(UA_SOCKET sockfd);//equivalent to posix close implementation
+#endif
+
+#ifndef UA_connect
+int UA_connect(UA_SOCKET sockfd, const struct sockaddr *addr, socklen_t addrlen);//equivalent to posix connect implementation
+#endif
+
+#ifndef UA_fd_set
+void UA_fd_set(UA_SOCKET fd, fd_set *set); //equivalent to posix FD_SET implementation
+#endif
+
+#ifndef UA_fd_isset
+int UA_fd_isset(UA_SOCKET fd, fd_set *set);//equivalent to posix FD_ISSET implementation
+#endif
+
+#ifndef UA_getaddrinfo
+int UA_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res);//equivalent to posix getaddrinfo implementation
+#endif
+
+#ifndef UA_socket_set_blocking
+unsigned int UA_socket_set_blocking(UA_SOCKET sockfd);//set a socket as blocking. Returns 0 if OK, other value otherwise
+#endif
+
+#ifndef UA_socket_set_nonblocking
+unsigned int UA_socket_set_nonblocking(UA_SOCKET sockfd);//set a socket as non-blocking. Returns 0 if OK, other value otherwise
+#endif
+
+#ifndef UA_getsockopt
+int UA_getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen); //equivalent to posix getsockopt implementation. Only in non windows architectures
+#endif
+
+#ifndef UA_setsockopt
+int UA_setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);//equivalent to posix setsockopt implementation
+#endif
+
+#ifndef UA_freeaddrinfo
+void UA_freeaddrinfo(struct addrinfo *res);//equivalent to posix freeaddrinfo implementatio
+#endif
+
+#ifndef UA_gethostname
+int UA_gethostname(char *name, size_t len);//equivalent to posix gethostname implementatio
+#endif
+
+#ifndef UA_initialize_architecture_network
+void UA_initialize_architecture_network(void);//initializes all needed for using the network interfaces
+#endif
+
+#ifndef UA_deinitialize_architecture_network
+void UA_deinitialize_architecture_network(void);//de-initializes the network interfaces
+#endif
+
+/*
+ * Print function
+ */
+#ifndef UA_snprintf
+int UA_snprintf(char* pa_stream, size_t pa_size, const char* pa_format, ...); //prints text to output
+#endif
+
+/*
+ * Access to file function
+ */
+
+#ifndef UA_access
+int UA_access(const char *pathname, int mode); //equivalent implementation of https://linux.die.net/man/2/access
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+
+
+
+#endif /* PLUGINS_ARCH_UA_ARCHITECTURE_FUNCTIONS_H_ */

+ 57 - 64
plugins/ua_network_tcp.c

@@ -8,20 +8,15 @@
  *    Copyright 2017 (c) Thomas Stalder, Blue Time Concept SA
  */
 
-
-#include "ua_architecture.h"
-
-#ifndef MSG_NOSIGNAL
-#define MSG_NOSIGNAL 0
-#endif
-
 #include "ua_network_tcp.h"
 #include "ua_log_stdout.h"
 #include "../deps/queue.h"
 
 #include <string.h> // memset
 
-#include "ua_log_socket_error.h"
+#ifndef MSG_NOSIGNAL
+#define MSG_NOSIGNAL 0
+#endif
 
 /****************************/
 /* Generic Socket Functions */
@@ -64,7 +59,7 @@ connection_write(UA_Connection *connection, UA_ByteString *buf) {
         ssize_t n = 0;
         do {
             size_t bytes_to_send = buf->length - nWritten;
-            n = ua_send(connection->sockfd,
+            n = UA_send(connection->sockfd,
                      (const char*)buf->data + nWritten,
                      bytes_to_send, flags);
             if(n < 0 && UA_ERRNO != UA_INTERRUPTED && UA_ERRNO != UA_AGAIN) {
@@ -95,7 +90,7 @@ connection_recv(UA_Connection *connection, UA_ByteString *response,
         UA_UInt32 timeout_usec = timeout * 1000;
         struct timeval tmptv = {(long int)(timeout_usec / 1000000),
                                 (long int)(timeout_usec % 1000000)};
-        int resultsize = ua_select(connection->sockfd+1, &fdset, NULL,
+        int resultsize = UA_select(connection->sockfd+1, &fdset, NULL,
                                 NULL, &tmptv);
 
         /* No result */
@@ -122,7 +117,7 @@ connection_recv(UA_Connection *connection, UA_ByteString *response,
     }
 
     /* Get the received packet(s) */
-    ssize_t ret = ua_recv(connection->sockfd, (char*)response->data,
+    ssize_t ret = UA_recv(connection->sockfd, (char*)response->data,
                        connection->localConf.recvBufferSize, 0);
 
     /* The remote side closed the connection */
@@ -182,7 +177,7 @@ static void
 ServerNetworkLayerTCP_close(UA_Connection *connection) {
     if (connection->state == UA_CONNECTION_CLOSED)
         return;
-    ua_shutdown((UA_SOCKET)connection->sockfd, 2);
+    UA_shutdown((UA_SOCKET)connection->sockfd, 2);
     connection->state = UA_CONNECTION_CLOSED;
 }
 
@@ -190,11 +185,11 @@ static UA_StatusCode
 ServerNetworkLayerTCP_add(ServerNetworkLayerTCP *layer, UA_Int32 newsockfd,
                           struct sockaddr_storage *remote) {
     /* Set nonblocking */
-    socket_set_nonblocking(newsockfd);
+    UA_socket_set_nonblocking(newsockfd);//TODO: check return value
 
     /* Do not merge packets on the socket (disable Nagle's algorithm) */
     int dummy = 1;
-    if(ua_setsockopt(newsockfd, IPPROTO_TCP, TCP_NODELAY,
+    if(UA_setsockopt(newsockfd, IPPROTO_TCP, TCP_NODELAY,
                (const char *)&dummy, sizeof(dummy)) < 0) {
         UA_LOG_SOCKET_ERRNO_WRAP(
                 UA_LOG_ERROR(layer->logger, UA_LOGCATEGORY_NETWORK,
@@ -203,10 +198,10 @@ ServerNetworkLayerTCP_add(ServerNetworkLayerTCP *layer, UA_Int32 newsockfd,
         return UA_STATUSCODE_BADUNEXPECTEDERROR;
     }
 
-#if defined(ua_getnameinfo)
+#if defined(UA_getnameinfo)
     /* Get the peer name for logging */
     char remote_name[100];
-    int res = ua_getnameinfo((struct sockaddr*)remote,
+    int res = UA_getnameinfo((struct sockaddr*)remote,
                           sizeof(struct sockaddr_storage),
                           remote_name, sizeof(remote_name),
                           NULL, 0, NI_NUMERICHOST);
@@ -228,7 +223,7 @@ ServerNetworkLayerTCP_add(ServerNetworkLayerTCP *layer, UA_Int32 newsockfd,
     /* Allocate and initialize the connection */
     ConnectionEntry *e = (ConnectionEntry*)UA_malloc(sizeof(ConnectionEntry));
     if(!e){
-        ua_close(newsockfd);
+        UA_close(newsockfd);
         return UA_STATUSCODE_BADOUTOFMEMORY;
     }
 
@@ -255,7 +250,7 @@ ServerNetworkLayerTCP_add(ServerNetworkLayerTCP *layer, UA_Int32 newsockfd,
 static void
 addServerSocket(ServerNetworkLayerTCP *layer, struct addrinfo *ai) {
     /* Create the server socket */
-    UA_SOCKET newsock = ua_socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
+    UA_SOCKET newsock = UA_socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
     if(newsock == UA_INVALID_SOCKET)
     {
         UA_LOG_WARNING(layer->logger, UA_LOGCATEGORY_NETWORK,
@@ -270,45 +265,45 @@ addServerSocket(ServerNetworkLayerTCP *layer, struct addrinfo *ai) {
     int optval = 1;
 #if UA_IPV6
     if(ai->ai_family == AF_INET6 &&
-       ua_setsockopt(newsock, IPPROTO_IPV6, IPV6_V6ONLY,
+       UA_setsockopt(newsock, IPPROTO_IPV6, IPV6_V6ONLY,
                   (const char*)&optval, sizeof(optval)) == -1) {
         UA_LOG_WARNING(layer->logger, UA_LOGCATEGORY_NETWORK,
                        "Could not set an IPv6 socket to IPv6 only");
-        ua_close(newsock);
+        UA_close(newsock);
         return;
     }
 #endif
-    if(ua_setsockopt(newsock, SOL_SOCKET, SO_REUSEADDR,
+    if(UA_setsockopt(newsock, SOL_SOCKET, SO_REUSEADDR,
                   (const char *)&optval, sizeof(optval)) == -1) {
         UA_LOG_WARNING(layer->logger, UA_LOGCATEGORY_NETWORK,
                        "Could not make the socket reusable");
-        ua_close(newsock);
+        UA_close(newsock);
         return;
     }
 
 
-    if(socket_set_nonblocking(newsock) != UA_STATUSCODE_GOOD) {
+    if(UA_socket_set_nonblocking(newsock) != UA_STATUSCODE_GOOD) {
         UA_LOG_WARNING(layer->logger, UA_LOGCATEGORY_NETWORK,
                        "Could not set the server socket to nonblocking");
-        ua_close(newsock);
+        UA_close(newsock);
         return;
     }
 
     /* Bind socket to address */
-    if(ua_bind(newsock, ai->ai_addr, (socklen_t)ai->ai_addrlen) < 0) {
+    if(UA_bind(newsock, ai->ai_addr, (socklen_t)ai->ai_addrlen) < 0) {
         UA_LOG_SOCKET_ERRNO_WRAP(
             UA_LOG_WARNING(layer->logger, UA_LOGCATEGORY_NETWORK,
                            "Error binding a server socket: %s", errno_str));
-        ua_close(newsock);
+        UA_close(newsock);
         return;
     }
 
     /* Start listening */
-    if(ua_listen(newsock, MAXBACKLOG) < 0) {
+    if(UA_listen(newsock, MAXBACKLOG) < 0) {
         UA_LOG_SOCKET_ERRNO_WRAP(
                 UA_LOG_WARNING(layer->logger, UA_LOGCATEGORY_NETWORK,
                        "Error listening on server socket: %s", errno_str));
-        ua_close(newsock);
+        UA_close(newsock);
         return;
     }
 
@@ -318,7 +313,7 @@ addServerSocket(ServerNetworkLayerTCP *layer, struct addrinfo *ai) {
 
 static UA_StatusCode
 ServerNetworkLayerTCP_start(UA_ServerNetworkLayer *nl, const UA_String *customHostname) {
-  ua_initialize_architecture_network();
+  UA_initialize_architecture_network();
 
     ServerNetworkLayerTCP *layer = (ServerNetworkLayerTCP *)nl->handle;
 
@@ -326,16 +321,16 @@ ServerNetworkLayerTCP_start(UA_ServerNetworkLayer *nl, const UA_String *customHo
     UA_String du = UA_STRING_NULL;
     if (customHostname->length) {
         char discoveryUrl[256];
-        du.length = (size_t)ua_snprintf(discoveryUrl, 255, "opc.tcp://%.*s:%d/",
+        du.length = (size_t)UA_snprintf(discoveryUrl, 255, "opc.tcp://%.*s:%d/",
                                      (int)customHostname->length,
                                      customHostname->data,
                                      layer->port);
         du.data = (UA_Byte*)discoveryUrl;
     }else{
         char hostname[256];
-        if(gethostname(hostname, 255) == 0) {
+        if(UA_gethostname(hostname, 255) == 0) {
             char discoveryUrl[256];
-            du.length = (size_t)ua_snprintf(discoveryUrl, 255, "opc.tcp://%s:%d/",
+            du.length = (size_t)UA_snprintf(discoveryUrl, 255, "opc.tcp://%s:%d/",
                                          hostname, layer->port);
             du.data = (UA_Byte*)discoveryUrl;
         }
@@ -344,14 +339,14 @@ ServerNetworkLayerTCP_start(UA_ServerNetworkLayer *nl, const UA_String *customHo
 
     /* Get addrinfo of the server and create server sockets */
     char portno[6];
-    ua_snprintf(portno, 6, "%d", layer->port);
+    UA_snprintf(portno, 6, "%d", layer->port);
     struct addrinfo hints, *res;
     memset(&hints, 0, sizeof hints);
     hints.ai_family = AF_UNSPEC;
     hints.ai_socktype = SOCK_STREAM;
     hints.ai_flags = AI_PASSIVE;
     hints.ai_protocol = IPPROTO_TCP;
-    if(ua_getaddrinfo(NULL, portno, &hints, &res) != 0)
+    if(UA_getaddrinfo(NULL, portno, &hints, &res) != 0)
         return UA_STATUSCODE_BADINTERNALERROR;
 
     /* There might be serveral addrinfos (for different network cards,
@@ -361,7 +356,7 @@ ServerNetworkLayerTCP_start(UA_ServerNetworkLayer *nl, const UA_String *customHo
         layer->serverSocketsSize < FD_SETSIZE && ai != NULL;
         ai = ai->ai_next)
         addServerSocket(layer, ai);
-    ua_freeaddrinfo(res);
+    UA_freeaddrinfo(res);
 
     UA_LOG_INFO(layer->logger, UA_LOGCATEGORY_NETWORK,
                 "TCP network layer listening on %.*s",
@@ -404,7 +399,7 @@ ServerNetworkLayerTCP_listen(UA_ServerNetworkLayer *nl, UA_Server *server,
     UA_Int32 highestfd = setFDSet(layer, &fdset);
     setFDSet(layer, &errset);
     struct timeval tmptv = {0, timeout * 1000};
-    if (ua_select(highestfd+1, &fdset, NULL, &errset, &tmptv) < 0) {
+    if (UA_select(highestfd+1, &fdset, NULL, &errset, &tmptv) < 0) {
         UA_LOG_SOCKET_ERRNO_WRAP(
             UA_LOG_WARNING(layer->logger, UA_LOGCATEGORY_NETWORK,
                                   "Socket select failed with %s", errno_str));
@@ -419,7 +414,7 @@ ServerNetworkLayerTCP_listen(UA_ServerNetworkLayer *nl, UA_Server *server,
 
         struct sockaddr_storage remote;
         socklen_t remote_size = sizeof(remote);
-        UA_SOCKET newsockfd = ua_accept((UA_SOCKET)layer->serverSockets[i],
+        UA_SOCKET newsockfd = UA_accept((UA_SOCKET)layer->serverSockets[i],
                                   (struct sockaddr*)&remote, &remote_size);
         if(newsockfd == UA_INVALID_SOCKET)
             continue;
@@ -441,7 +436,7 @@ ServerNetworkLayerTCP_listen(UA_ServerNetworkLayer *nl, UA_Server *server,
                         "Connection %i | Closed by the server (no Hello Message)",
                          e->connection.sockfd);
             LIST_REMOVE(e, pointers);
-            ua_close(e->connection.sockfd);
+            UA_close(e->connection.sockfd);
             UA_Server_removeConnection(server, &e->connection);
             continue;
         }
@@ -467,7 +462,7 @@ ServerNetworkLayerTCP_listen(UA_ServerNetworkLayer *nl, UA_Server *server,
                         "Connection %i | Closed",
                         e->connection.sockfd);
             LIST_REMOVE(e, pointers);
-            ua_close(e->connection.sockfd);
+            UA_close(e->connection.sockfd);
             UA_Server_removeConnection(server, &e->connection);
         }
     }
@@ -482,8 +477,8 @@ ServerNetworkLayerTCP_stop(UA_ServerNetworkLayer *nl, UA_Server *server) {
 
     /* Close the server sockets */
     for(UA_UInt16 i = 0; i < layer->serverSocketsSize; i++) {
-        ua_shutdown(layer->serverSockets[i], 2);
-        ua_close(layer->serverSockets[i]);
+        UA_shutdown(layer->serverSockets[i], 2);
+        UA_close(layer->serverSockets[i]);
     }
     layer->serverSocketsSize = 0;
 
@@ -496,7 +491,7 @@ ServerNetworkLayerTCP_stop(UA_ServerNetworkLayer *nl, UA_Server *server) {
      * the connection. */
     ServerNetworkLayerTCP_listen(nl, server, 0);
 
-    ua_deinitialize_architecture_network();
+    UA_deinitialize_architecture_network();
 }
 
 /* run only when the server is stopped */
@@ -510,7 +505,7 @@ ServerNetworkLayerTCP_deleteMembers(UA_ServerNetworkLayer *nl) {
     ConnectionEntry *e, *e_tmp;
     LIST_FOREACH_SAFE(e, &layer->connections, pointers, e_tmp) {
         LIST_REMOVE(e, pointers);
-        ua_close(e->connection.sockfd);
+        UA_close(e->connection.sockfd);
         UA_free(e);
     }
 
@@ -547,8 +542,8 @@ static void
 ClientNetworkLayerTCP_close(UA_Connection *connection) {
     if (connection->state == UA_CONNECTION_CLOSED)
         return;
-    ua_shutdown(connection->sockfd, 2);
-    ua_close(connection->sockfd);
+    UA_shutdown(connection->sockfd, 2);
+    UA_close(connection->sockfd);
     connection->state = UA_CONNECTION_CLOSED;
 }
 
@@ -557,7 +552,7 @@ UA_ClientConnectionTCP(UA_ConnectionConfig conf,
                        const char *endpointUrl, const UA_UInt32 timeout,
                        UA_Logger logger) {
 
-    ua_initialize_architecture_network();
+    UA_initialize_architecture_network();
 
     if(logger == NULL) {
         logger = UA_Log_Stdout;
@@ -605,13 +600,11 @@ UA_ClientConnectionTCP(UA_ConnectionConfig conf,
     hints.ai_socktype = SOCK_STREAM;
     hints.ai_protocol = IPPROTO_TCP;
     char portStr[6];
-    ua_snprintf(portStr, 6, "%d", port);
-    int error = ua_getaddrinfo(hostname, portStr, &hints, &server);
+    UA_snprintf(portStr, 6, "%d", port);
+    int error = UA_getaddrinfo(hostname, portStr, &hints, &server);
     if(error != 0 || !server) {
-        UA_LOG_WARNING(logger, UA_LOGCATEGORY_NETWORK,
-
-                       "DNS lookup of %s failed with error %s",
-                       hostname, ua_translate_error(error));
+        UA_LOG_SOCKET_ERRNO_GAI_WRAP(UA_LOG_WARNING(logger, UA_LOGCATEGORY_NETWORK,
+                                              "DNS lookup of %s failed with error %s", hostname, errno_str));
         return connection;
     }
 
@@ -625,13 +618,13 @@ UA_ClientConnectionTCP(UA_ConnectionConfig conf,
      * reached. */
     do {
         /* Get a socket */
-        clientsockfd = ua_socket(server->ai_family,
+        clientsockfd = UA_socket(server->ai_family,
                               server->ai_socktype,
                               server->ai_protocol);
         if(clientsockfd == UA_INVALID_SOCKET) {
             UA_LOG_SOCKET_ERRNO_WRAP(UA_LOG_WARNING(logger, UA_LOGCATEGORY_NETWORK,
                                                     "Could not create client socket: %s", errno_str));
-            ua_freeaddrinfo(server);
+            UA_freeaddrinfo(server);
             return connection;
         }
 
@@ -641,16 +634,16 @@ UA_ClientConnectionTCP(UA_ConnectionConfig conf,
         connection.sockfd = clientsockfd;
 
         /* Non blocking connect to be able to timeout */
-        if (socket_set_nonblocking(clientsockfd) != UA_STATUSCODE_GOOD) {
+        if (UA_socket_set_nonblocking(clientsockfd) != UA_STATUSCODE_GOOD) {
             UA_LOG_WARNING(logger, UA_LOGCATEGORY_NETWORK,
                            "Could not set the client socket to nonblocking");
             ClientNetworkLayerTCP_close(&connection);
-            ua_freeaddrinfo(server);
+            UA_freeaddrinfo(server);
             return connection;
         }
 
         /* Non blocking connect */
-        error = ua_connect(clientsockfd, server->ai_addr, (socklen_t)server->ai_addrlen);
+        error = UA_connect(clientsockfd, server->ai_addr, (socklen_t)server->ai_addrlen);
 
         if ((error == -1) && (UA_ERRNO != UA_ERR_CONNECTION_PROGRESS)) {
             ClientNetworkLayerTCP_close(&connection);
@@ -658,7 +651,7 @@ UA_ClientConnectionTCP(UA_ConnectionConfig conf,
                     UA_LOG_WARNING(logger, UA_LOGCATEGORY_NETWORK,
                                    "Connection to %s failed with error: %s",
                                    endpointUrl, errno_str));
-            ua_freeaddrinfo(server);
+            UA_freeaddrinfo(server);
             return connection;
         }
 
@@ -676,7 +669,7 @@ UA_ClientConnectionTCP(UA_ConnectionConfig conf,
             struct timeval tmptv = {(long int) (timeout_usec / 1000000),
                                     (long int) (timeout_usec % 1000000)};
 
-            int resultsize = ua_select(clientsockfd + 1, NULL, &fdset, NULL, &tmptv);
+            int resultsize = UA_select(clientsockfd + 1, NULL, &fdset, NULL, &tmptv);
 
             if(resultsize == 1) {
 #ifdef _WIN32
@@ -688,7 +681,7 @@ UA_ClientConnectionTCP(UA_ConnectionConfig conf,
                 OPTVAL_TYPE so_error;
                 socklen_t len = sizeof so_error;
 
-                int ret = ua_getsockopt(clientsockfd, SOL_SOCKET, SO_ERROR, &so_error, &len);
+                int ret = UA_getsockopt(clientsockfd, SOL_SOCKET, SO_ERROR, &so_error, &len);
 
                 if (ret != 0 || so_error != 0) {
                     /* on connection refused we should still try to connect */
@@ -698,7 +691,7 @@ UA_ClientConnectionTCP(UA_ConnectionConfig conf,
                         UA_LOG_WARNING(logger, UA_LOGCATEGORY_NETWORK,
                                        "Connection to %s failed with error: %s",
                                        endpointUrl, strerror(ret == 0 ? so_error : UA_ERRNO));
-                        ua_freeaddrinfo(server);
+                        UA_freeaddrinfo(server);
                         return connection;
                     }
                     /* wait until we try a again. Do not make this too small, otherwise the
@@ -718,7 +711,7 @@ UA_ClientConnectionTCP(UA_ConnectionConfig conf,
 
     } while ((UA_DateTime_nowMonotonic() - connStart) < dtTimeout);
 
-    ua_freeaddrinfo(server);
+    UA_freeaddrinfo(server);
 
     if(!connected) {
         /* connection timeout */
@@ -732,7 +725,7 @@ UA_ClientConnectionTCP(UA_ConnectionConfig conf,
 
 
     /* We are connected. Reset socket to blocking */
-    if(socket_set_blocking(clientsockfd) != UA_STATUSCODE_GOOD) {
+    if(UA_socket_set_blocking(clientsockfd) != UA_STATUSCODE_GOOD) {
         UA_LOG_WARNING(logger, UA_LOGCATEGORY_NETWORK,
                        "Could not set the client socket to blocking");
         ClientNetworkLayerTCP_close(&connection);
@@ -741,7 +734,7 @@ UA_ClientConnectionTCP(UA_ConnectionConfig conf,
 
 #ifdef SO_NOSIGPIPE
     int val = 1;
-    int sso_result = ua_setsockopt(connection.sockfd, SOL_SOCKET,
+    int sso_result = UA_setsockopt(connection.sockfd, SOL_SOCKET,
                                 SO_NOSIGPIPE, (void*)&val, sizeof(val));
     if(sso_result < 0)
         UA_LOG_WARNING(logger, UA_LOGCATEGORY_NETWORK,

plugins/ua_network_tcp.h → arch/ua_network_tcp.h


+ 1 - 8
plugins/ua_network_udp.c

@@ -117,13 +117,6 @@ static UA_StatusCode sendUDP(UA_Connection *connection, UA_ByteString *buf) {
     return UA_STATUSCODE_GOOD;
 }
 
-static UA_StatusCode socket_set_nonblocking(UA_Int32 sockfd) {
-    int opts = fcntl(sockfd, F_GETFL);
-    if(opts < 0 || fcntl(sockfd, F_SETFL, opts|O_NONBLOCK) < 0)
-        return UA_STATUSCODE_BADINTERNALERROR;
-    return UA_STATUSCODE_GOOD;
-}
-
 static void setFDSet(ServerNetworkLayerUDP *layer) {
     FD_ZERO(&layer->fdset);
     FD_SET(layer->serversockfd, &layer->fdset);
@@ -159,7 +152,7 @@ static UA_StatusCode ServerNetworkLayerUDP_start(UA_ServerNetworkLayer *nl, UA_L
         CLOSESOCKET(layer->serversockfd);
         return UA_STATUSCODE_BADINTERNALERROR;
     }
-    socket_set_nonblocking(layer->serversockfd);
+    UA_socket_set_nonblocking(layer->serversockfd);
     UA_LOG_WARNING(layer->logger, UA_LOGCATEGORY_NETWORK, "Listening for UDP connections on %s:%d",
                    inet_ntoa(serv_addr.sin_addr), ntohs(serv_addr.sin_port));
     return UA_STATUSCODE_GOOD;

plugins/ua_network_udp.h → arch/ua_network_udp.h


+ 1 - 0
plugins/arch/vxworks/CMakeLists.txt

@@ -6,6 +6,7 @@ if("${UA_ARCHITECTURE}" STREQUAL "vxworks")
 
     ua_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
     ua_add_architecture_file(${CMAKE_CURRENT_SOURCE_DIR}/ua_clock.c)
+    ua_add_architecture_file(${CMAKE_CURRENT_SOURCE_DIR}/ua_architecture_functions.c)
     
     ua_architecture_remove_definitions(-Werror -Wpedantic -Wno-static-in-inline -fPIC)
     ua_architecture_add_definitions(-D_WRS_KERNEL)

+ 44 - 38
plugins/arch/vxworks/ua_architecture.h

@@ -27,6 +27,17 @@
    nanosleep(&timeToSleep, NULL);                 \
  }
 
+#ifdef UINT32_C
+# undef UINT32_C
+#endif
+
+#define UINT32_C(x) ((x) + (UINT32_MAX - UINT32_MAX))
+
+#ifdef UA_BINARY_OVERLAYABLE_FLOAT
+# undef UA_BINARY_OVERLAYABLE_FLOAT
+#endif
+#define UA_BINARY_OVERLAYABLE_FLOAT 1
+
 #define OPTVAL_TYPE int
 
 #include <fcntl.h>
@@ -36,6 +47,8 @@
 #define UA_fd_set(fd, fds) FD_SET((unsigned int)fd, fds)
 #define UA_fd_isset(fd, fds) FD_ISSET((unsigned int)fd, fds)
 
+#define UA_access access
+
 #define UA_IPV6 1
 #define UA_SOCKET int
 #define UA_INVALID_SOCKET -1
@@ -46,48 +59,41 @@
 #define UA_WOULDBLOCK EWOULDBLOCK
 #define UA_ERR_CONNECTION_PROGRESS EINPROGRESS
 
-#include "ua_types.h"
-
-#define ua_getnameinfo getnameinfo
-#define ua_send send
-#define ua_recv recv
-#define ua_close close
-#define ua_select select
-#define ua_shutdown shutdown
-#define ua_socket socket
-#define ua_bind bind
-#define ua_listen listen
-#define ua_accept accept
-#define ua_connect connect
-#define ua_translate_error gai_strerror
-#define ua_getaddrinfo getaddrinfo
-#define ua_getsockopt getsockopt
-#define ua_setsockopt setsockopt
-#define ua_freeaddrinfo freeaddrinfo
-
-static UA_INLINE uint32_t socket_set_blocking(UA_SOCKET sockfd){
-  int on = FALSE;
-  if(ioctl(sockfd, FIONBIO, &on) < 0)
-    return UA_STATUSCODE_BADINTERNALERROR;
-  return UA_STATUSCODE_GOOD;
-}
-
-static UA_INLINE uint32_t socket_set_nonblocking(UA_SOCKET sockfd){
-  int on = TRUE;
-  if(ioctl(sockfd, FIONBIO, &on) < 0)
-    return UA_STATUSCODE_BADINTERNALERROR;
-  return UA_STATUSCODE_GOOD;
-}
+#define UA_getnameinfo getnameinfo
+#define UA_send send
+#define UA_recv recv
+#define UA_close close
+#define UA_select select
+#define UA_shutdown shutdown
+#define UA_socket socket
+#define UA_bind bind
+#define UA_listen listen
+#define UA_accept accept
+#define UA_connect connect
+#define UA_getaddrinfo getaddrinfo
+#define UA_getsockopt getsockopt
+#define UA_setsockopt setsockopt
+#define UA_freeaddrinfo freeaddrinfo
+#define UA_gethostname gethostname
+
+#include <stdlib.h>
+#define UA_free free
+#define UA_malloc malloc
+#define UA_calloc calloc
+#define UA_realloc realloc
 
 #include <stdio.h>
-#define ua_snprintf snprintf
+#define UA_snprintf snprintf
 
-static UA_INLINE void ua_initialize_architecture_network(void){
-  return;
+#define UA_LOG_SOCKET_ERRNO_WRAP(LOG) { \
+    char *errno_str = strerror(errno); \
+    LOG; \
 }
-
-static UA_INLINE void ua_deinitialize_architecture_network(void){
-  return;
+#define UA_LOG_SOCKET_ERRNO_GAI_WRAP(LOG) { \
+    char *errno_str = gai_strerror(errno); \
+    LOG; \
 }
 
+#include "../ua_architecture_functions.h"
+
 #endif /* PLUGINS_ARCH_VXWORKS_UA_ARCHITECTURE_H_ */

+ 29 - 0
arch/vxworks/ua_architecture_functions.c

@@ -0,0 +1,29 @@
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
+ *
+ *    Copyright 2018 (c) Jose Cabral, fortiss GmbH
+ */
+
+#include "ua_types.h"
+
+unsigned int UA_socket_set_blocking(UA_SOCKET sockfd){
+  int on = FALSE;
+  if(ioctl(sockfd, FIONBIO, &on) < 0)
+    return UA_STATUSCODE_BADINTERNALERROR;
+  return UA_STATUSCODE_GOOD;
+}
+
+unsigned int UA_socket_set_nonblocking(UA_SOCKET sockfd){
+  int on = TRUE;
+  if(ioctl(sockfd, FIONBIO, &on) < 0)
+    return UA_STATUSCODE_BADINTERNALERROR;
+  return UA_STATUSCODE_GOOD;
+}
+
+void UA_initialize_architecture_network(void){
+  return;
+}
+
+void UA_deinitialize_architecture_network(void){
+  return;
+}

plugins/arch/vxworks/ua_clock.c → arch/vxworks/ua_clock.c


+ 2 - 0
plugins/arch/win32/CMakeLists.txt

@@ -6,5 +6,7 @@ if("${UA_ARCHITECTURE}" STREQUAL "win32")
 
 ua_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
 ua_add_architecture_file(${CMAKE_CURRENT_SOURCE_DIR}/ua_clock.c)
+ua_add_architecture_file(${CMAKE_CURRENT_SOURCE_DIR}/ua_architecture_functions.c)
+
 
 endif()

+ 125 - 0
arch/win32/ua_architecture.h

@@ -0,0 +1,125 @@
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
+ *
+ *    Copyright 2016-2017 (c) Julius Pfrommer, Fraunhofer IOSB
+ *    Copyright 2017 (c) Stefan Profanter, fortiss GmbH
+ */
+
+#ifndef PLUGINS_ARCH_WIN32_UA_ARCHITECTURE_H_
+#define PLUGINS_ARCH_WIN32_UA_ARCHITECTURE_H_
+
+#ifndef _BSD_SOURCE
+# define _BSD_SOURCE
+#endif
+
+/* Disable some security warnings on MSVC */
+#ifdef _MSC_VER
+# define _CRT_SECURE_NO_WARNINGS
+#endif
+
+/* Assume that Windows versions are newer than Windows XP */
+#if defined(__MINGW32__) && (!defined(WINVER) || WINVER < 0x501)
+# undef WINVER
+# undef _WIN32_WINDOWS
+# undef _WIN32_WINNT
+# define WINVER 0x0501
+# define _WIN32_WINDOWS 0x0501
+# define _WIN32_WINNT 0x0501
+#endif
+
+/* Backup definition of SLIST_ENTRY on mingw winnt.h */
+#ifdef SLIST_ENTRY
+# pragma push_macro("SLIST_ENTRY")
+# undef SLIST_ENTRY
+# define POP_SLIST_ENTRY
+#endif
+
+
+#include <stdlib.h>
+#if defined(_WIN32) && !defined(__clang__)
+# include <malloc.h>
+#endif
+
+#include <stdio.h>
+#include <errno.h>
+#include <winsock2.h>
+#include <ws2tcpip.h>
+#include <windows.h>
+
+#ifdef _MSC_VER
+# ifndef UNDER_CE
+#  include <io.h> //access
+#  define UA_access _access
+# endif
+#else
+# include <unistd.h> //access and tests
+# define UA_access access
+#endif
+
+
+
+#ifdef POP_SLIST_ENTRY
+# undef SLIST_ENTRY
+# undef POP_SLIST_ENTRY
+# pragma pop_macro("SLIST_ENTRY")
+#endif
+
+#define ssize_t int
+#define OPTVAL_TYPE char
+#define UA_sleep_ms(X) Sleep(X)
+
+#define UA_fd_set(fd, fds) FD_SET((unsigned int)fd, fds)
+#define UA_fd_isset(fd, fds) FD_ISSET((unsigned int)fd, fds)
+
+#ifdef UNDER_CE
+# define errno
+#endif
+
+#define UA_IPV6 1
+#define UA_SOCKET int
+#define UA_INVALID_SOCKET -1
+#define UA_ERRNO WSAGetLastError()
+#define UA_INTERRUPTED WSAEINTR
+#define UA_AGAIN WSAEWOULDBLOCK
+#define UA_EAGAIN EAGAIN
+#define UA_WOULDBLOCK WSAEWOULDBLOCK
+#define UA_ERR_CONNECTION_PROGRESS WSAEWOULDBLOCK
+
+#define UA_getnameinfo getnameinfo
+#define UA_send send
+#define UA_recv recv
+#define UA_close closesocket
+#define UA_select select
+#define UA_shutdown shutdown
+#define UA_socket socket
+#define UA_bind bind
+#define UA_listen listen
+#define UA_accept accept
+#define UA_connect connect
+#define UA_getaddrinfo getaddrinfo
+#define UA_getsockopt getsockopt
+#define UA_setsockopt setsockopt
+#define UA_freeaddrinfo freeaddrinfo
+#define UA_gethostname gethostname
+
+#define UA_free free
+#define UA_malloc malloc
+#define UA_calloc calloc
+#define UA_realloc realloc
+
+#define UA_snprintf(source, size, string, ...) _snprintf_s(source, size, _TRUNCATE, string, __VA_ARGS__)
+
+#define UA_LOG_SOCKET_ERRNO_WRAP(LOG) { \
+    char *errno_str = NULL; \
+    FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, \
+    NULL, WSAGetLastError(), \
+    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), \
+    (LPSTR)&errno_str, 0, NULL); \
+    LOG; \
+    LocalFree(errno_str); \
+}
+#define UA_LOG_SOCKET_ERRNO_GAI_WRAP UA_LOG_SOCKET_ERRNO_WRAP
+
+#include "../ua_architecture_functions.h"
+
+#endif /* PLUGINS_ARCH_WIN32_UA_ARCHITECTURE_H_ */

+ 31 - 0
arch/win32/ua_architecture_functions.c

@@ -0,0 +1,31 @@
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
+ *
+ *    Copyright 2018 (c) Jose Cabral, fortiss GmbH
+ */
+
+#include "ua_types.h"
+
+unsigned int UA_socket_set_blocking(UA_SOCKET sockfd){
+  u_long iMode = 0;
+  if(ioctlsocket(sockfd, FIONBIO, &iMode) != NO_ERROR)
+    return UA_STATUSCODE_BADINTERNALERROR;
+  return UA_STATUSCODE_GOOD;;
+}
+
+unsigned int UA_socket_set_nonblocking(UA_SOCKET sockfd){
+  u_long iMode = 1;
+  if(ioctlsocket(sockfd, FIONBIO, &iMode) != NO_ERROR)
+    return UA_STATUSCODE_BADINTERNALERROR;
+  return UA_STATUSCODE_GOOD;;
+}
+
+void UA_initialize_architecture_network(void){
+  WSADATA wsaData;
+  WORD wVersionRequested = MAKEWORD(2, 2);
+  WSAStartup(wVersionRequested, &wsaData);
+}
+
+void UA_deinitialize_architecture_network(void){
+  WSACleanup();
+}

+ 1 - 2
plugins/arch/win32/ua_clock.c

@@ -10,6 +10,7 @@
 # define _BSD_SOURCE
 #endif
 
+#include "ua_types.h"
 #include <time.h>
 /* Backup definition of SLIST_ENTRY on mingw winnt.h */
 # ifdef SLIST_ENTRY
@@ -25,8 +26,6 @@
 #  pragma pop_macro("SLIST_ENTRY")
 # endif
 
-#include "ua_types.h"
-
 UA_DateTime UA_DateTime_now(void) {
     /* Windows filetime has the same definition as UA_DateTime */
     FILETIME ft;

+ 0 - 21
examples/client_connect_loop.c

@@ -1,19 +1,6 @@
 /* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
 
-/* Enable POSIX features */
-#if !defined(_XOPEN_SOURCE) && !defined(_WRS_KERNEL)
-# define _XOPEN_SOURCE 600
-#endif
-#ifndef _DEFAULT_SOURCE
-# define _DEFAULT_SOURCE
-#endif
-/* On older systems we need to define _BSD_SOURCE.
- * _DEFAULT_SOURCE is an alias for that. */
-#ifndef _BSD_SOURCE
-# define _BSD_SOURCE
-#endif
-
 /**
  * Client disconnect handling
  * --------------------------
@@ -26,14 +13,6 @@
 #include "open62541.h"
 #include <signal.h>
 
-#ifdef _WIN32
-# include <windows.h>
-# define UA_sleep_ms(X) Sleep(X)
-#else
-# include <unistd.h>
-# define UA_sleep_ms(X) usleep(X * 1000)
-#endif
-
 UA_Boolean running = true;
 UA_Logger logger = UA_Log_Stdout;
 

+ 0 - 21
examples/client_subscription_loop.c

@@ -1,19 +1,6 @@
 /* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
 
-/* Enable POSIX features */
-#if !defined(_XOPEN_SOURCE) && !defined(_WRS_KERNEL)
-# define _XOPEN_SOURCE 600
-#endif
-#ifndef _DEFAULT_SOURCE
-# define _DEFAULT_SOURCE
-#endif
-/* On older systems we need to define _BSD_SOURCE.
- * _DEFAULT_SOURCE is an alias for that. */
-#ifndef _BSD_SOURCE
-# define _BSD_SOURCE
-#endif
-
 /**
  * Client disconnect handling
  * --------------------------
@@ -26,14 +13,6 @@
 #include "open62541.h"
 #include <signal.h>
 
-#ifdef _WIN32
-# include <windows.h>
-# define UA_sleep_ms(X) Sleep(X)
-#else
-# include <unistd.h>
-# define UA_sleep_ms(X) usleep(X * 1000)
-#endif
-
 UA_Boolean running = true;
 UA_Logger logger = UA_Log_Stdout;
 

+ 1 - 6
examples/server_mainloop.c

@@ -3,13 +3,8 @@
  * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
  */
 
+#include "open62541.h"
 #include <signal.h>
-#ifdef _WIN32
-# include <winsock2.h>
-#else
-# include <sys/select.h>
-#endif
-# include "open62541.h"
 
 UA_Boolean running = true;
 static void stopHandler(int sign) {

+ 2 - 27
include/ua_config.h.in

@@ -47,6 +47,8 @@ extern "C" {
 #cmakedefine UA_DEBUG
 #cmakedefine UA_DEBUG_DUMP_PKGS
 
+#include "ua_architecture.h"
+
 /**
  * C99 Definitions
  * --------------- */
@@ -57,9 +59,6 @@ extern "C" {
 #if !defined(_MSC_VER) || _MSC_VER >= 1600
 # include <stdint.h>
 # include <stdbool.h> /* C99 Boolean */
-# if defined(_WRS_KERNEL)
-# define UINT32_C(x) ((x) + (UINT32_MAX - UINT32_MAX)) 
-# endif
 #else
 # include "ms_stdint.h"
 # if !defined(__bool_true_false_are_defined)
@@ -111,28 +110,6 @@ extern "C" {
  * The default is to use the malloc implementation from ``stdlib.h``. Override
  * if required. Changing the settings has no effect on a pre-compiled
  * library. */
-#include <stdlib.h>
-#if defined(_WIN32) && !defined(__clang__)
-# include <malloc.h>
-#endif
-
-#if !defined(UA_FREERTOS)
-
-# define UA_free(ptr) free(ptr)
-# define UA_malloc(size) malloc(size)
-# define UA_calloc(num, size) calloc(num, size)
-# define UA_realloc(ptr, size) realloc(ptr, size)
-
-#else
-
-# include <FreeRTOS.h>
-
-# define UA_free(ptr) vPortFree(ptr)
-# define UA_malloc(size) pvPortMalloc(size)
-# define UA_calloc(num, size) pvPortCalloc(num, size)
-# define UA_realloc(ptr, size) pvPortRealloc(ptr, size)
-
-#endif
 
 /* Stack-allocation of memory. Use C99 variable-length arrays if possible.
  * Otherwise revert to alloca. Note that alloca is not supported on some
@@ -299,8 +276,6 @@ extern "C" {
 # elif __FLOAT_WORD_ORDER == __LITTLE_ENDIAN
 #  define UA_BINARY_OVERLAYABLE_FLOAT 1
 # endif
-#elif defined(_WRS_KERNEL)
-# define UA_BINARY_OVERLAYABLE_FLOAT 1
 #endif
 
 #ifndef UA_BINARY_OVERLAYABLE_FLOAT

+ 0 - 2
include/ua_plugin_network.h

@@ -13,8 +13,6 @@
 extern "C" {
 #endif
 
-#include "ua_architecture.h"
-
 #include "ua_server.h"
 #include "ua_plugin_log.h"
 

+ 0 - 3
plugins/CMakeLists.txt

@@ -1,3 +0,0 @@
-SET(SOURCE_GROUP plugins)
-
-add_subdirectory(arch)

+ 0 - 102
plugins/arch/win32/ua_architecture.h

@@ -1,102 +0,0 @@
-/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
- * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
- *
- *    Copyright 2016-2017 (c) Julius Pfrommer, Fraunhofer IOSB
- *    Copyright 2017 (c) Stefan Profanter, fortiss GmbH
- */
-
-#ifndef PLUGINS_ARCH_WIN32_UA_ARCHITECTURE_H_
-#define PLUGINS_ARCH_WIN32_UA_ARCHITECTURE_H_
-
-#ifndef _BSD_SOURCE
-# define _BSD_SOURCE
-#endif
-
-/* Disable some security warnings on MSVC */
-#ifdef _MSC_VER
-# define _CRT_SECURE_NO_WARNINGS
-#endif
-
-/* Assume that Windows versions are newer than Windows XP */
-#if defined(__MINGW32__) && (!defined(WINVER) || WINVER < 0x501)
-# undef WINVER
-# undef _WIN32_WINDOWS
-# undef _WIN32_WINNT
-# define WINVER 0x0501
-# define _WIN32_WINDOWS 0x0501
-# define _WIN32_WINNT 0x0501
-#endif
-
-#include <errno.h>
-#include <winsock2.h>
-#include <ws2tcpip.h>
-#define ssize_t int
-#define OPTVAL_TYPE char
-#define UA_sleep_ms(X) Sleep(X)
-
-#define UA_fd_set(fd, fds) FD_SET((unsigned int)fd, fds)
-#define UA_fd_isset(fd, fds) FD_ISSET((unsigned int)fd, fds)
-
-#ifdef UNDER_CE
-# define errno
-#endif
-
-#define UA_IPV6 1
-#define UA_SOCKET int
-#define UA_INVALID_SOCKET -1
-#define UA_ERRNO WSAGetLastError()
-#define UA_INTERRUPTED WSAEINTR
-#define UA_AGAIN WSAEWOULDBLOCK
-#define UA_EAGAIN EAGAIN
-#define UA_WOULDBLOCK WSAEWOULDBLOCK
-#define UA_ERR_CONNECTION_PROGRESS WSAEWOULDBLOCK
-
-#include "ua_types.h"
-
-#define ua_getnameinfo getnameinfo
-#define ua_send send
-#define ua_recv recv
-#define ua_close closesocket
-#define ua_select select
-#define ua_shutdown shutdown
-#define ua_socket socket
-#define ua_bind bind
-#define ua_listen listen
-#define ua_accept accept
-#define ua_connect connect
-#define ua_translate_error gai_strerror
-#define ua_getaddrinfo getaddrinfo
-#define ua_getsockopt getsockopt
-#define ua_setsockopt setsockopt
-#define ua_freeaddrinfo freeaddrinfo
-
-
-static UA_INLINE UA_StatusCode socket_set_blocking(UA_SOCKET sockfd){
-  u_long iMode = 0;
-  if(ioctlsocket(sockfd, FIONBIO, &iMode) != NO_ERROR)
-    return UA_STATUSCODE_BADINTERNALERROR;
-  return UA_STATUSCODE_GOOD;;
-}
-
-static UA_INLINE UA_StatusCode socket_set_nonblocking(UA_SOCKET sockfd){
-  u_long iMode = 1;
-  if(ioctlsocket(sockfd, FIONBIO, &iMode) != NO_ERROR)
-    return UA_STATUSCODE_BADINTERNALERROR;
-  return UA_STATUSCODE_GOOD;;
-}
-
-
-#include <stdio.h>
-#define ua_snprintf(source, size, string, ...) _snprintf_s(source, size, _TRUNCATE, string, __VA_ARGS__)
-
-static UA_INLINE void ua_initialize_architecture_network(void){
-  WSADATA wsaData;
-  WORD wVersionRequested = MAKEWORD(2, 2);
-  WSAStartup(wVersionRequested, &wsaData);
-}
-
-static UA_INLINE void ua_deinitialize_architecture_network(void){
-  WSACleanup();
-}
-
-#endif /* PLUGINS_ARCH_WIN32_UA_ARCHITECTURE_H_ */

+ 0 - 37
plugins/ua_log_socket_error.h

@@ -1,37 +0,0 @@
-/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
- * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. 
- *
- *    Copyright 2017 (c) Stefan Profanter, fortiss GmbH
- */
-
-#ifndef UA_LOG_SOCKET_ERROR_H_
-#define UA_LOG_SOCKET_ERROR_H_
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-#ifdef _WIN32
-#include <winsock2.h>
-#define UA_LOG_SOCKET_ERRNO_WRAP(LOG) { \
-    char *errno_str = NULL; \
-    FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, \
-    NULL, WSAGetLastError(), \
-    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), \
-    (LPSTR)&errno_str, 0, NULL); \
-    LOG; \
-    LocalFree(errno_str); \
-}
-#else
-#define UA_LOG_SOCKET_ERRNO_WRAP(LOG) { \
-    char *errno_str = strerror(errno); \
-    LOG; \
-}
-#endif
-
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
-#endif /* UA_LOG_SOCKET_ERROR_H_ */

+ 0 - 13
src/server/ua_mdns.c

@@ -6,19 +6,6 @@
  *    Copyright 2017 (c) Fraunhofer IOSB (Author: Julius Pfrommer)
  */
 
-/* Enable POSIX features */
-#if !defined(_XOPEN_SOURCE) && !defined(_WRS_KERNEL)
-# define _XOPEN_SOURCE 600
-#endif
-#ifndef _DEFAULT_SOURCE
-# define _DEFAULT_SOURCE
-#endif
-/* On older systems we need to define _BSD_SOURCE.
- * _DEFAULT_SOURCE is an alias for that. */
-#ifndef _BSD_SOURCE
-# define _BSD_SOURCE
-#endif
-
 #include "ua_server_internal.h"
 #include "ua_mdns_internal.h"
 #include "ua_util.h"

+ 1 - 5
src/server/ua_server.c

@@ -250,11 +250,7 @@ UA_Server_new(const UA_ServerConfig *config) {
     /* Initialize multicast discovery */
 #if defined(UA_ENABLE_DISCOVERY) && defined(UA_ENABLE_DISCOVERY_MULTICAST)
     server->mdnsDaemon = NULL;
-#ifdef _WIN32
-    server->mdnsSocket = INVALID_SOCKET;
-#else
-    server->mdnsSocket = -1;
-#endif
+    server->mdnsSocket = UA_INVALID_SOCKET;
     server->mdnsMainSrvAdded = UA_FALSE;
     if(server->config.applicationDescription.applicationType == UA_APPLICATIONTYPE_DISCOVERYSERVER)
         initMulticastDiscoveryServer(server);

+ 1 - 5
src/server/ua_server_internal.h

@@ -98,11 +98,7 @@ struct UA_Server {
     void* registerServerCallbackData;
 # ifdef UA_ENABLE_DISCOVERY_MULTICAST
     mdns_daemon_t *mdnsDaemon;
-#ifdef _WIN32
-    SOCKET mdnsSocket;
-#else
-    int mdnsSocket;
-#endif
+    UA_SOCKET mdnsSocket;
     UA_Boolean mdnsMainSrvAdded;
 #  ifdef UA_ENABLE_MULTITHREADING
     pthread_t mdnsThread;

+ 2 - 11
src/server/ua_services_discovery.c

@@ -15,15 +15,6 @@
 #include "ua_services.h"
 #include "ua_mdns_internal.h"
 
-#ifdef _MSC_VER
-# ifndef UNDER_CE
-#  include <io.h> //access
-#  define access _access
-# endif
-#else
-# include <unistd.h> //access
-#endif
-
 #ifdef UA_ENABLE_DISCOVERY
 
 #include "ua_client_internal.h"
@@ -416,7 +407,7 @@ process_RegisterServer(UA_Server *server, UA_Session *session,
         }
         memcpy(filePath, requestServer->semaphoreFilePath.data, requestServer->semaphoreFilePath.length );
         filePath[requestServer->semaphoreFilePath.length] = '\0';
-        if(access( filePath, 0 ) == -1) {
+        if(UA_access( filePath, 0 ) == -1) {
             responseHeader->serviceResult = UA_STATUSCODE_BADSEMPAHOREFILEMISSING;
             UA_free(filePath);
             return;
@@ -553,7 +544,7 @@ void UA_Discovery_cleanupTimedOut(UA_Server *server, UA_DateTime nowMonotonic) {
                 if(fp)
                     fclose(fp);
 #else
-                semaphoreDeleted = access( filePath, 0 ) == -1;
+                semaphoreDeleted = UA_access( filePath, 0 ) == -1;
 #endif
                 UA_free(filePath);
             } else {

+ 21 - 100
src/server/ua_services_discovery_multicast.c

@@ -7,46 +7,12 @@
  *    Copyright 2017 (c) Thomas Stalder, Blue Time Concept SA
  */
 
-/* Enable POSIX features */
-#if !defined(_XOPEN_SOURCE) && !defined(_WRS_KERNEL)
-# define _XOPEN_SOURCE 600
-#endif
-#ifndef _DEFAULT_SOURCE
-# define _DEFAULT_SOURCE
-#endif
-/* On older systems we need to define _BSD_SOURCE.
- * _DEFAULT_SOURCE is an alias for that. */
-#ifndef _BSD_SOURCE
-# define _BSD_SOURCE
-#endif
-
 #include "ua_server_internal.h"
 #include "ua_services.h"
 #include "ua_mdns_internal.h"
 
 #if defined(UA_ENABLE_DISCOVERY) && defined(UA_ENABLE_DISCOVERY_MULTICAST)
 
-#ifdef _MSC_VER
-# ifndef UNDER_CE
-#  include <io.h> //access
-#  define access _access
-# endif
-#else
-# include <unistd.h> //access
-#endif
-
-#include <fcntl.h>
-#include <errno.h>
-#ifdef _WIN32
-# define CLOSESOCKET(S) closesocket((SOCKET)S)
-# define errno__ WSAGetLastError()
-#else
-# define CLOSESOCKET(S) close(S)
-# define errno__ errno
-#endif
-
-#include "ua_log_socket_error.h"
-
 #ifdef UA_ENABLE_MULTITHREADING
 
 static void *
@@ -57,7 +23,7 @@ multicastWorkerLoop(UA_Server *server) {
 
     while(*running) {
         FD_ZERO(&fds);
-        FD_SET(server->mdnsSocket, &fds);
+        UA_fd_set(server->mdnsSocket, &fds);
         select(server->mdnsSocket + 1, &fds, 0, 0, &next_sleep);
 
         if(!*running)
@@ -97,7 +63,7 @@ static UA_StatusCode
 multicastListenStop(UA_Server* server) {
     mdnsd_shutdown(server->mdnsDaemon);
     // wake up select
-    write(server->mdnsSocket, "\0", 1);
+    write(server->mdnsSocket, "\0", 1); //TODO: move to arch?
     if(pthread_join(server->mdnsThread, NULL)) {
         UA_LOG_ERROR(server->config.logger, UA_LOGCATEGORY_SERVER,
                      "Multicast error: Can not stop thread.");
@@ -144,7 +110,7 @@ void startMulticastDiscoveryServer(UA_Server *server) {
 
 void stopMulticastDiscoveryServer(UA_Server *server) {
     char hostname[256];
-    if(gethostname(hostname, 255) == 0) {
+    if(UA_gethostname(hostname, 255) == 0) {
         UA_String hnString = UA_STRING(hostname);
         UA_Discovery_removeRecord(server, &server->config.mdnsServerName,
                                   &hnString, 4840, UA_TRUE);
@@ -276,29 +242,9 @@ UA_Server_setServerOnNetworkCallback(UA_Server *server,
     server->serverOnNetworkCallbackData = data;
 }
 
-static void
-socket_mdns_set_nonblocking(int sockfd) {
-#ifdef _WIN32
-    u_long iMode = 1;
-    ioctlsocket(sockfd, FIONBIO, &iMode);
-#else
-    int opts = fcntl(sockfd, F_GETFL);
-    fcntl(sockfd, F_SETFL, opts|O_NONBLOCK);
-#endif
-}
-
 /* Create multicast 224.0.0.251:5353 socket */
-#ifdef _WIN32
-static SOCKET
-#else
-static int
-#endif
-discovery_createMulticastSocket(void) {
-#ifdef _WIN32
-    SOCKET s;
-#else
-    int s;
-#endif
+static UA_SOCKET discovery_createMulticastSocket(void) {
+    UA_SOCKET s;
     int flag = 1, ittl = 255;
     struct sockaddr_in in;
     struct ip_mreq mc;
@@ -310,34 +256,25 @@ discovery_createMulticastSocket(void) {
     in.sin_port = htons(5353);
     in.sin_addr.s_addr = 0;
 
-#ifdef _WIN32
-    if((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == INVALID_SOCKET)
-        return INVALID_SOCKET;
-#else
-    if((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
-        return -1;
-#endif
+    if((s = UA_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == UA_INVALID_SOCKET)
+        return UA_INVALID_SOCKET;
 
 #ifdef SO_REUSEPORT
-    setsockopt(s, SOL_SOCKET, SO_REUSEPORT, (char *)&flag, sizeof(flag));
-#endif
-    setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&flag, sizeof(flag));
-    if(bind(s, (struct sockaddr *)&in, sizeof(in))) {
-        CLOSESOCKET(s);
-#ifdef _WIN32
-        return INVALID_SOCKET;
-#else
-        return -1;
+    UA_setsockopt(s, SOL_SOCKET, SO_REUSEPORT, (char *)&flag, sizeof(flag));
 #endif
+    UA_setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&flag, sizeof(flag));
+    if(UA_bind(s, (struct sockaddr *)&in, sizeof(in))) {
+        UA_close(s);
+        return UA_INVALID_SOCKET;
     }
 
     mc.imr_multiaddr.s_addr = inet_addr("224.0.0.251");
     mc.imr_interface.s_addr = htonl(INADDR_ANY);
-    setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*)&mc, sizeof(mc));
-    setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, (char*)&ttl, sizeof(ttl));
-    setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, (char*)&ittl, sizeof(ittl));
+    UA_setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char*)&mc, sizeof(mc));
+    UA_setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, (char*)&ttl, sizeof(ttl));
+    UA_setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, (char*)&ittl, sizeof(ittl));
 
-    socket_mdns_set_nonblocking(s);
+    UA_socket_set_nonblocking(s); //TODO: check return value
     return s;
 }
 
@@ -345,17 +282,9 @@ discovery_createMulticastSocket(void) {
 UA_StatusCode
 initMulticastDiscoveryServer(UA_Server* server) {
     server->mdnsDaemon = mdnsd_new(QCLASS_IN, 1000);
-#ifdef _WIN32
-    WORD wVersionRequested = MAKEWORD(2, 2);
-    WSADATA wsaData;
-    WSAStartup(wVersionRequested, &wsaData);
-#endif
+    UA_initialize_architecture_network();
 
-#ifdef _WIN32
-    if((server->mdnsSocket = discovery_createMulticastSocket()) == INVALID_SOCKET) {
-#else
-    if((server->mdnsSocket = discovery_createMulticastSocket()) < 0) {
-#endif
+    if((server->mdnsSocket = discovery_createMulticastSocket()) == UA_INVALID_SOCKET) {
         UA_LOG_SOCKET_ERRNO_WRAP(
                 UA_LOG_ERROR(server->config.logger, UA_LOGCATEGORY_SERVER,
                      "Could not create multicast socket. Error: %s", errno_str));
@@ -369,17 +298,9 @@ initMulticastDiscoveryServer(UA_Server* server) {
 void destroyMulticastDiscoveryServer(UA_Server* server) {
     mdnsd_shutdown(server->mdnsDaemon);
     mdnsd_free(server->mdnsDaemon);
-#ifdef _WIN32
-    if(server->mdnsSocket != INVALID_SOCKET) {
-#else
-    if(server->mdnsSocket >= 0) {
-#endif
-        CLOSESOCKET(server->mdnsSocket);
-#ifdef _WIN32
-        server->mdnsSocket = INVALID_SOCKET;
-#else
-        server->mdnsSocket = -1;
-#endif
+    if(server->mdnsSocket != UA_INVALID_SOCKET) {
+        UA_close(server->mdnsSocket);
+        server->mdnsSocket = UA_INVALID_SOCKET;
     }
 }
 

+ 2 - 2
tests/CMakeLists.txt

@@ -31,7 +31,7 @@ endif()
 
 
 # Use different plugins for testing
-set(test_plugin_sources ${PROJECT_SOURCE_DIR}/plugins/ua_network_tcp.c
+set(test_plugin_sources ${PROJECT_SOURCE_DIR}/arch/ua_network_tcp.c
                         ${PROJECT_SOURCE_DIR}/tests/testing-plugins/testing_clock.c
                         ${PROJECT_SOURCE_DIR}/plugins/ua_log_stdout.c
                         ${PROJECT_SOURCE_DIR}/plugins/ua_config_default.c
@@ -51,7 +51,7 @@ if(UA_ENABLE_ENCRYPTION)
         ${PROJECT_SOURCE_DIR}/plugins/ua_securitypolicy_basic256sha256.c)
 endif()
 
-add_library(open62541-testplugins OBJECT ${test_plugin_sources})
+add_library(open62541-testplugins OBJECT ${test_plugin_sources} ${PROJECT_SOURCE_DIR}/arch/${UA_ARCHITECTURE}/ua_architecture_functions.c)
 add_dependencies(open62541-testplugins open62541)
 target_compile_definitions(open62541-testplugins PRIVATE -DUA_DYNAMIC_LINKING_EXPORT)
 

+ 0 - 4
tests/client/check_client_async.c

@@ -5,10 +5,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-#ifndef WIN32
-#include <unistd.h>
-#endif
-
 #include "ua_types.h"
 #include "ua_server.h"
 #include "ua_client.h"

+ 2 - 2
tests/fuzz/CMakeLists.txt

@@ -52,7 +52,7 @@ endif()
 list(APPEND LIBS "${open62541_LIBRARIES}")
 
 # Use different plugins for testing
-set(fuzzing_plugin_sources ${PROJECT_SOURCE_DIR}/plugins/ua_network_tcp.c
+set(fuzzing_plugin_sources ${PROJECT_SOURCE_DIR}/arch/ua_network_tcp.c
         ${PROJECT_SOURCE_DIR}/tests/testing-plugins/testing_clock.c
         ${PROJECT_SOURCE_DIR}/tests/testing-plugins/testing_networklayers.c
         ${PROJECT_SOURCE_DIR}/plugins/ua_log_stdout.c
@@ -70,7 +70,7 @@ if(UA_ENABLE_ENCRYPTION)
         ${PROJECT_SOURCE_DIR}/plugins/ua_securitypolicy_basic256sha256.c)
 endif()
 
-add_library(open62541-fuzzplugins OBJECT ${fuzzing_plugin_sources})
+add_library(open62541-fuzzplugins OBJECT ${fuzzing_plugin_sources} ${PROJECT_SOURCE_DIR}/arch/${UA_ARCHITECTURE}/ua_architecture_functions.c)
 add_dependencies(open62541-fuzzplugins open62541)
 
 # the fuzzer test are built directly on the open62541 object files. so they can

+ 3 - 20
tests/server/check_discovery.c

@@ -2,26 +2,6 @@
 *  License, v. 2.0. If a copy of the MPL was not distributed with this
 *  file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-#if !defined(_XOPEN_SOURCE) && !defined(_WRS_KERNEL)
-# define _XOPEN_SOURCE 500
-#endif
-#ifndef _DEFAULT_SOURCE
-# define _DEFAULT_SOURCE
-#endif
-
-// On older systems we need to define _BSD_SOURCE
-// _DEFAULT_SOURCE is an alias for that
-#ifndef _BSD_SOURCE
-# define _BSD_SOURCE
-#endif
-
-#include <stdio.h>
-#include <fcntl.h>
-#include <check.h>
-#ifndef _WIN32
-#include <unistd.h>
-#endif
-
 #include "server/ua_server_internal.h"
 #include "ua_client.h"
 #include "ua_config_default.h"
@@ -29,6 +9,9 @@
 #include "testing_clock.h"
 #include "thread_wrapper.h"
 
+#include <fcntl.h>
+#include <check.h>
+
 // set register timeout to 1 second so we are able to test it.
 #define registerTimeout 1
 // cleanup is only triggered every 10 seconds, thus wait a bit longer to check

+ 1 - 18
tests/testing-plugins/testing_clock.c

@@ -2,25 +2,8 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-/* Enable POSIX features */
-#if !defined(_XOPEN_SOURCE) && !defined(_WRS_KERNEL)
-# define _XOPEN_SOURCE 600
-#endif
-#ifndef _DEFAULT_SOURCE
-# define _DEFAULT_SOURCE
-#endif
-/* On older systems we need to define _BSD_SOURCE.
- * _DEFAULT_SOURCE is an alias for that. */
-#ifndef _BSD_SOURCE
-# define _BSD_SOURCE
-#endif
-
-#include <time.h>
-#ifdef _WIN32
-# include <windows.h>
-#endif
 #include "testing_clock.h"
-
+#include <time.h>
 
 UA_DateTime testingClock = 0;
 

+ 0 - 13
tools/amalgamate.py

@@ -53,19 +53,6 @@ if is_c:
 # define MDNSD_DYNAMIC_LINKING
 #endif
 
-/* Enable POSIX features */
-#if !defined(_XOPEN_SOURCE) && !defined(_WRS_KERNEL)
-# define _XOPEN_SOURCE 600
-#endif
-#ifndef _DEFAULT_SOURCE
-# define _DEFAULT_SOURCE
-#endif
-/* On older systems we need to define _BSD_SOURCE.
- * _DEFAULT_SOURCE is an alias for that. */
-#ifndef _BSD_SOURCE
-# define _BSD_SOURCE
-#endif
-
 /* Disable security warnings for BSD sockets on MSVC */
 #ifdef _MSC_VER
 # define _CRT_SECURE_NO_WARNINGS

+ 7 - 0
tools/cmake/macros.cmake

@@ -1,39 +1,46 @@
+#Add a new architecture to to the lists of available architectures
 FUNCTION(ua_add_architecture)
     FOREACH(ARG ${ARGV})
         set_property(GLOBAL APPEND PROPERTY UA_ARCHITECTURES ${ARG})
     ENDFOREACH(ARG)
 ENDFUNCTION(ua_add_architecture)
 
+#Include folders to the compilation
 FUNCTION(ua_include_directories)
     FOREACH(ARG ${ARGV})
         set_property(GLOBAL APPEND PROPERTY UA_INCLUDE_DIRECTORIES ${ARG})
     ENDFOREACH(ARG)
 ENDFUNCTION(ua_include_directories)
 
+#Add a new header file to the architecture group
 FUNCTION(ua_add_architecture_header)
     FOREACH(ARG ${ARGV})
         set_property(GLOBAL APPEND PROPERTY UA_ARCHITECTURE_HEADERS ${ARG})
     ENDFOREACH(ARG)
 ENDFUNCTION(ua_add_architecture_header)
 
+#Add a new source file to the architecture group
 FUNCTION(ua_add_architecture_file)
     FOREACH(ARG ${ARGV})
         set_property(GLOBAL APPEND PROPERTY UA_ARCHITECTURE_SOURCES ${ARG})
     ENDFOREACH(ARG)
 ENDFUNCTION(ua_add_architecture_file)
 
+#Add definitions to the compilations that are exclusive for the selected architecture
 FUNCTION(ua_architecture_add_definitions)
     FOREACH(ARG ${ARGV})
         set_property(GLOBAL APPEND PROPERTY UA_ARCHITECTURE_ADD_DEFINITIONS ${ARG})
     ENDFOREACH(ARG)
 ENDFUNCTION(ua_architecture_add_definitions)
 
+#Remove definitions from the compilations that are exclusive for the selected architecture
 FUNCTION(ua_architecture_remove_definitions)
     FOREACH(ARG ${ARGV})
         set_property(GLOBAL APPEND PROPERTY UA_ARCHITECTURE_REMOVE_DEFINITIONS ${ARG})
     ENDFOREACH(ARG)
 ENDFUNCTION(ua_architecture_remove_definitions)
 
+#Add libraries to be linked to the comnpilation that are exclusive for the selected architecture
 FUNCTION(ua_architecture_append_to_library)
     FOREACH(ARG ${ARGV})
         set_property(GLOBAL APPEND PROPERTY UA_ARCHITECTURE_APPEND_TO_LIBRARY ${ARG})