Explorar o código

rename plugins to begin with ua_

Julius Pfrommer %!s(int64=8) %!d(string=hai) anos
pai
achega
54daafd37a

+ 4 - 4
CMakeLists.txt

@@ -167,8 +167,8 @@ set(exported_headers ${PROJECT_BINARY_DIR}/src_generated/ua_config.h
                      ${PROJECT_SOURCE_DIR}/include/ua_server_external_ns.h
                      ${PROJECT_SOURCE_DIR}/include/ua_client.h
                      ${PROJECT_SOURCE_DIR}/include/ua_client_highlevel.h
-                     ${PROJECT_SOURCE_DIR}/plugins/networklayer_tcp.h
-                     ${PROJECT_SOURCE_DIR}/plugins/logger_stdout.h
+                     ${PROJECT_SOURCE_DIR}/plugins/ua_network_tcp.h
+                     ${PROJECT_SOURCE_DIR}/plugins/ua_log_stdout.h
                      ${PROJECT_SOURCE_DIR}/plugins/ua_config_standard.h)
 set(internal_headers ${PROJECT_SOURCE_DIR}/deps/queue.h
                      ${PROJECT_SOURCE_DIR}/deps/pcg_basic.h
@@ -221,8 +221,8 @@ set(lib_sources ${PROJECT_SOURCE_DIR}/src/ua_types.c
                 ${PROJECT_SOURCE_DIR}/src/client/ua_client_highlevel_subscriptions.c
                 # plugins and dependencies
                 ${PROJECT_SOURCE_DIR}/plugins/ua_clock.c
-                ${PROJECT_SOURCE_DIR}/plugins/networklayer_tcp.c
-                ${PROJECT_SOURCE_DIR}/plugins/logger_stdout.c
+                ${PROJECT_SOURCE_DIR}/plugins/ua_network_tcp.c
+                ${PROJECT_SOURCE_DIR}/plugins/ua_log_stdout.c
                 ${PROJECT_SOURCE_DIR}/plugins/ua_config_standard.c
                 ${PROJECT_SOURCE_DIR}/deps/libc_time.c
                 ${PROJECT_SOURCE_DIR}/deps/pcg_basic.c)

+ 3 - 5
examples/client.c

@@ -1,14 +1,12 @@
-/*
- * This work is licensed under a Creative Commons CCZero 1.0 Universal License.
- * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
- */
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
 
 #ifdef UA_NO_AMALGAMATION
 # include "ua_types.h"
 # include "ua_client.h"
 # include "ua_client_highlevel.h"
 # include "ua_nodeids.h"
-# include "networklayer_tcp.h"
+# include "ua_network_tcp.h"
 # include "ua_config_standard.h"
 # include "ua_types_encoding_binary.h"
 #else

+ 3 - 2
examples/client_firstSteps.c

@@ -1,5 +1,5 @@
-//This file contains source-code that is discussed in a tutorial located here:
-//http://open62541.org/doc/sphinx/tutorial_firstStepsClient.html
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
 
 #include <stdio.h>
 #include <inttypes.h>
@@ -7,6 +7,7 @@
 #ifdef UA_NO_AMALGAMATION
 # include "ua_client.h"
 # include "ua_config_standard.h"
+# include "ua_network_tcp.h"
 #else
 # include "open62541.h"
 #endif

+ 5 - 6
examples/server.c

@@ -1,7 +1,5 @@
-/*
- * This work is licensed under a Creative Commons CCZero 1.0 Universal License.
- * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
- */
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
 //to compile with single file releases:
 // * single-threaded: gcc -std=c99 server.c open62541.c -o server
 // * multi-threaded: gcc -std=c99 server.c open62541.c -o server -lurcu-cds -lurcu -lurcu-common -lpthread
@@ -11,7 +9,8 @@
 # include "ua_types.h"
 # include "ua_server.h"
 # include "ua_config_standard.h"
-# include "networklayer_tcp.h"
+# include "ua_network_tcp.h"
+# include "ua_log_stdout.h"
 #else
 # include "open62541.h"
 #endif
@@ -41,7 +40,7 @@
 /****************************/
 
 UA_Boolean running = 1;
-UA_Logger logger = Logger_Stdout;
+UA_Logger logger = UA_Log_Stdout;
 
 /*************************/
 /* Read-only data source */

+ 9 - 13
examples/server.cpp

@@ -1,7 +1,5 @@
-/*
- * This work is licensed under a Creative Commons CCZero 1.0 Universal License.
- * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
- */
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
 
 #include <signal.h>
 #include <iostream>
@@ -9,22 +7,20 @@
 
 #ifdef UA_NO_AMALGAMATION
 # include "ua_server.h"
-# include "logger_stdout.h"
-# include "networklayer_tcp.h"
+# include "ua_log_stdout.h"
+# include "ua_network_tcp.h"
 #else
 # include "open62541.h"
 #endif
 
-/**
- * Build Instructions (Linux)
+/* Build Instructions (Linux)
  * - gcc -std=c99 -c open62541.c
- * - g++ server.cpp open62541.o -o server
- */
+ * - g++ server.cpp open62541.o -o server */
 
 using namespace std;
 
 UA_Boolean running = true;
-UA_Logger logger = Logger_Stdout;
+UA_Logger logger = UA_Log_Stdout;
 
 static void stopHandler(int sign) {
     UA_LOG_INFO(logger, UA_LOGCATEGORY_SERVER, "received ctrl-c");
@@ -61,8 +57,8 @@ int main() {
     UA_QualifiedName_deleteMembers(&myIntegerName);
 
     UA_StatusCode retval = UA_Server_run(server, &running);
-	UA_Server_delete(server);
+    UA_Server_delete(server);
     nl.deleteMembers(&nl);
 
-	return retval;
+    return retval;
 }

+ 5 - 6
examples/server_datasource.c

@@ -1,7 +1,5 @@
-/*
- * This work is licensed under a Creative Commons CCZero 1.0 Universal License.
- * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
- */
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
 
 #include <signal.h>
 #include <stdio.h>
@@ -10,13 +8,14 @@
 # include "ua_types.h"
 # include "ua_server.h"
 # include "ua_config_standard.h"
-# include "networklayer_tcp.h"
+# include "ua_network_tcp.h"
+# include "ua_log_stdout.h"
 #else
 # include "open62541.h"
 #endif
 
 UA_Boolean running = true;
-UA_Logger logger = Logger_Stdout;
+UA_Logger logger = UA_Log_Stdout;
 
 static void stopHandler(int sign) {
     UA_LOG_INFO(logger, UA_LOGCATEGORY_SERVER, "received ctrl-c");

+ 3 - 8
examples/server_firstSteps.c

@@ -1,10 +1,5 @@
-/*
- * This work is licensed under a Creative Commons CCZero 1.0 Universal License.
- * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
- */
-
-// This file contains source-code that is discussed in a tutorial located here:
-// http://open62541.org/doc/sphinx/tutorial_firstStepsServer.html
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
 
 #include <stdio.h>
 #include <signal.h>
@@ -13,7 +8,7 @@
 # include "ua_types.h"
 # include "ua_server.h"
 # include "ua_config_standard.h"
-# include "networklayer_tcp.h"
+# include "ua_network_tcp.h"
 #else
 # include "open62541.h"
 #endif

+ 3 - 2
examples/server_mainloop.c

@@ -14,13 +14,14 @@
 # include "ua_types.h"
 # include "ua_server.h"
 # include "ua_config_standard.h"
-# include "networklayer_tcp.h"
+# include "ua_network_tcp.h"
+# include "ua_log_stdout.h"
 #else
 # include "open62541.h"
 #endif
 
 UA_Boolean running = true;
-UA_Logger logger = Logger_Stdout;
+UA_Logger logger = UA_Log_Stdout;
 
 static void stopHandler(int sign) {
     UA_LOG_INFO(logger, UA_LOGCATEGORY_SERVER, "received ctrl-c");

+ 14 - 18
examples/server_method.c

@@ -1,7 +1,5 @@
-/*
- * This work is licensed under a Creative Commons CCZero 1.0 Universal License.
- * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
- */
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
 
 #include <signal.h>
 #include <stdlib.h>
@@ -10,13 +8,14 @@
 # include "ua_types.h"
 # include "ua_server.h"
 # include "ua_config_standard.h"
-# include "networklayer_tcp.h"
+# include "ua_network_tcp.h"
+# include "ua_log_stdout.h"
 #else
 # include "open62541.h"
 #endif
 
 UA_Boolean running = true;
-UA_Logger logger = Logger_Stdout;
+UA_Logger logger = UA_Log_Stdout;
 
 static UA_StatusCode
 helloWorldMethod(void *handle, const UA_NodeId objectId, size_t inputSize, const UA_Variant *input,
@@ -32,12 +31,12 @@ helloWorldMethod(void *handle, const UA_NodeId objectId, size_t inputSize, const
         UA_String_deleteMembers(&tmp);
         UA_LOG_INFO(logger, UA_LOGCATEGORY_SERVER, "Hello World was called");
         return UA_STATUSCODE_GOOD;
-} 
+}
 
 static UA_StatusCode
 fooBarMethod(void *handle, const UA_NodeId objectId, size_t inputSize, const UA_Variant *input,
                  size_t outputSize, UA_Variant *output) {
-	// Exactly the same as helloWorld, but returns foobar
+    // Exactly the same as helloWorld, but returns foobar
         UA_String *inputStr = (UA_String*)input->data;
         UA_String tmp = UA_STRING_ALLOC("FooBar! ");
         if(inputStr->length > 0) {
@@ -49,15 +48,15 @@ fooBarMethod(void *handle, const UA_NodeId objectId, size_t inputSize, const UA_
         UA_String_deleteMembers(&tmp);
         UA_LOG_INFO(logger, UA_LOGCATEGORY_SERVER, "Hello World was called");
         return UA_STATUSCODE_GOOD;
-} 
+}
 
 static UA_StatusCode
 IncInt32ArrayValuesMethod(void *handle, const UA_NodeId objectId, size_t inputSize,
                           const UA_Variant *input, size_t outputSize, UA_Variant *output) {
-	UA_Variant_setArrayCopy(output, input->data, 5, &UA_TYPES[UA_TYPES_INT32]);
-	for(size_t i = 0; i< input->arrayLength; i++)
-		((UA_Int32*)output->data)[i] = ((UA_Int32*)input->data)[i] + 1;
-	return UA_STATUSCODE_GOOD;
+    UA_Variant_setArrayCopy(output, input->data, 5, &UA_TYPES[UA_TYPES_INT32]);
+    for(size_t i = 0; i< input->arrayLength; i++)
+        ((UA_Int32*)output->data)[i] = ((UA_Int32*)input->data)[i] + 1;
+    return UA_STATUSCODE_GOOD;
 }
 
 static void stopHandler(int sign) {
@@ -94,7 +93,7 @@ int main(int argc, char** argv) {
     outputArguments.description = UA_LOCALIZEDTEXT("en_US", "A String");
     outputArguments.name = UA_STRING("MyOutput");
     outputArguments.valueRank = -1;
-        
+
     UA_MethodAttributes helloAttr;
     UA_MethodAttributes_init(&helloAttr);
     helloAttr.description = UA_LOCALIZEDTEXT("en_US","Say `Hello World`");
@@ -135,7 +134,6 @@ int main(int argc, char** argv) {
     outputArguments.name = UA_STRING("output is the array, each index is incremented by one");
     outputArguments.valueRank = 1;
 
-    
     UA_MethodAttributes incAttr;
     UA_MethodAttributes_init(&incAttr);
     incAttr.description = UA_LOCALIZEDTEXT("en_US","1dArrayExample");
@@ -154,7 +152,7 @@ int main(int argc, char** argv) {
        the opportunity to define the callback... we could do that now
     */
     UA_Server_setMethodNode_callback(server, UA_NODEID_NUMERIC(1,62541), &fooBarMethod, NULL);
-    
+
     //END OF EXAMPLE 3
     /* start server */
     UA_StatusCode retval = UA_Server_run(server, &running);
@@ -167,5 +165,3 @@ int main(int argc, char** argv) {
 
     return (int)retval;
 }
-
-

+ 5 - 6
examples/server_nodeset.c

@@ -1,7 +1,5 @@
-/*
- * This work is licensed under a Creative Commons CCZero 1.0 Universal License.
- * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
- */
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
 
 #include <signal.h>
 #include <stdlib.h>
@@ -10,7 +8,8 @@
 # include "ua_types.h"
 # include "ua_server.h"
 # include "ua_config_standard.h"
-# include "networklayer_tcp.h"
+# include "ua_network_tcp.h"
+# include "ua_log_stdout.h"
 #else
 # include "open62541.h"
 #endif
@@ -18,7 +17,7 @@
 /* files nodeset.h and nodeset.c are created from server_nodeset.xml in the /src_generated directory by CMake */
 #include "nodeset.h"
 
-UA_Logger logger = Logger_Stdout;
+UA_Logger logger = UA_Log_Stdout;
 UA_Boolean running = true;
 
 static void stopHandler(int sign) {

+ 5 - 6
examples/server_repeated_job.c

@@ -1,7 +1,5 @@
-/*
- * This work is licensed under a Creative Commons CCZero 1.0 Universal License.
- * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
- */
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
 
 #include <signal.h>
 
@@ -9,13 +7,14 @@
 # include "ua_types.h"
 # include "ua_server.h"
 # include "ua_config_standard.h"
-# include "networklayer_tcp.h"
+# include "ua_network_tcp.h"
+# include "ua_log_stdout.h"
 #else
 # include "open62541.h"
 #endif
 
 UA_Boolean running = true;
-UA_Logger logger = Logger_Stdout;
+UA_Logger logger = UA_Log_Stdout;
 
 static void stopHandler(int sign) {
     UA_LOG_INFO(logger, UA_LOGCATEGORY_SERVER, "received ctrl-c");

+ 9 - 10
examples/server_variable.c

@@ -1,7 +1,5 @@
-/*
- * This work is licensed under a Creative Commons CCZero 1.0 Universal License.
- * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
- */
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
 
 #include <signal.h>
 
@@ -9,13 +7,14 @@
 # include "ua_types.h"
 # include "ua_server.h"
 # include "ua_config_standard.h"
-# include "networklayer_tcp.h"
+# include "ua_network_tcp.h"
+# include "ua_log_stdout.h"
 #else
 # include "open62541.h"
 #endif
 
 UA_Boolean running = true;
-UA_Logger logger = Logger_Stdout;
+UA_Logger logger = UA_Log_Stdout;
 
 static void stopHandler(int sign) {
     UA_LOG_INFO(logger, UA_LOGCATEGORY_SERVER, "received ctrl-c");
@@ -42,10 +41,10 @@ int main(int argc, char** argv) {
     /* add a variable node to the address space */
     UA_VariableAttributes attr;
     UA_VariableAttributes_init(&attr);
-    UA_Int32 myInteger = 42;
-    UA_Variant_setScalar(&attr.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]);
-    attr.description = UA_LOCALIZEDTEXT("en_US","the answer");
-    attr.displayName = UA_LOCALIZEDTEXT("en_US","the answer");
+    /* UA_Int32 myInteger = 42; */
+    /* UA_Variant_setScalar(&attr.value, &myInteger, &UA_TYPES[UA_TYPES_INT32]); */
+    /* attr.description = UA_LOCALIZEDTEXT("en_US","the answer"); */
+    /* attr.displayName = UA_LOCALIZEDTEXT("en_US","the answer"); */
     UA_NodeId myIntegerNodeId = UA_NODEID_STRING(1, "the.answer");
     UA_QualifiedName myIntegerName = UA_QUALIFIEDNAME(1, "the answer");
     UA_NodeId parentNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_OBJECTSFOLDER);

+ 0 - 1
include/ua_config.h.in

@@ -38,7 +38,6 @@ extern "C" {
 #cmakedefine UA_ENABLE_NODEMANAGEMENT
 
 #cmakedefine UA_ENABLE_EMBEDDED_LIBC
-#cmakedefine UA_ENABLE_EMBEDDED_CLOCK
 
 #cmakedefine UA_ENABLE_NONSTANDARD_UDP
 #cmakedefine UA_ENABLE_NONSTANDARD_STATELESS

+ 5 - 5
include/ua_constants.h

@@ -66,11 +66,11 @@ typedef enum {
 #define UA_ACCESSLEVELMASK_HISTORYWRITE 0x08
 #define UA_ACCESSLEVELMASK_SEMANTICCHANGE 0x10
 
-/** Write Masks
- *  -----------
- *  The write mask and user write mask is given by the following constants that are
- *  XORed for the overall write mask.
- *  Part 3: 5.2.7 Table 2
+/**
+ * Write Masks
+ * -----------
+ * The write mask and user write mask is given by the following constants that
+ * are XORed for the overall write mask. Part 3: 5.2.7 Table 2
  */
 #define UA_WRITEMASK_ACCESSLEVEL                1<<0
 #define UA_WRITEMASK_ARRRAYDIMENSIONS           1<<1

+ 1 - 1
include/ua_server.h

@@ -299,7 +299,7 @@ UA_Server_setMethodNode_callback(UA_Server *server, const UA_NodeId methodNodeId
 
 /**
  * Node Addition and Deletion
- * ^^^^^^^^^^^^^^^^^^^^^^^^^ */
+ * ^^^^^^^^^^^^^^^^^^^^^^^^^^ */
 UA_StatusCode UA_EXPORT
 UA_Server_deleteNode(UA_Server *server, const UA_NodeId nodeId, UA_Boolean deleteReferences);
 

+ 4 - 2
include/ua_types.h

@@ -20,10 +20,10 @@
 extern "C" {
 #endif
 
-#include <stdint.h>
-#include <stdbool.h>
 #include "ua_config.h"
 #include "ua_constants.h"
+#include <stdint.h>
+#include <stdbool.h>
 
 /**
  * Data Types
@@ -504,6 +504,8 @@ typedef struct {
 } UA_ExtensionObject;
 
 /**
+ * .. _variant:
+ *
  * Variant
  * ^^^^^^^
  * Variants may contain data of any type. See the Section `Generic Type

+ 0 - 22
plugins/logger_stdout.h

@@ -1,22 +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.
- */
-
-#ifndef LOGGER_STDOUT_H_
-#define LOGGER_STDOUT_H_
-
-#include "ua_types.h"
-#include "ua_log.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-UA_EXPORT void Logger_Stdout(UA_LogLevel level, UA_LogCategory category, const char *msg, ...);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* LOGGER_STDOUT_H_ */

+ 6 - 5
plugins/ua_clock.c

@@ -4,7 +4,9 @@
 #include "ua_types.h"
 
 #include <time.h>
-#if !defined(_WIN32) || defined(__MINGW32__)
+#if defined(_WIN32)
+# include <windows.h>
+#else
 # include <sys/time.h>
 #endif
 
@@ -14,7 +16,7 @@
 #endif
 
 UA_DateTime UA_DateTime_now(void) {
-#if defined(_WIN32) && !defined(__MINGW32__)
+#if defined(_WIN32)
     /* Windows filetime has the same definition as UA_DateTime */
     FILETIME ft;
     SYSTEMTIME st;
@@ -36,8 +38,7 @@ UA_DateTime UA_DateTime_nowMonotonic(void) {
     LARGE_INTEGER freq, ticks;
     QueryPerformanceFrequency(&freq);
     QueryPerformanceCounter(&ticks);
-    UA_Double ticks2dt = UA_SEC_TO_DATETIME;
-    ticks2dt /= freq.QuadPart;
+    UA_Double ticks2dt = UA_SEC_TO_DATETIME / freq.QuadPart;
     return (UA_DateTime)(ticks.QuadPart * ticks2dt);
 #elif defined(__APPLE__) || defined(__MACH__)
     /* OS X does not have clock_gettime, use clock_get_time */
@@ -47,7 +48,7 @@ UA_DateTime UA_DateTime_nowMonotonic(void) {
     clock_get_time(cclock, &mts);
     mach_port_deallocate(mach_task_self(), cclock);
     return (mts.tv_sec * UA_SEC_TO_DATETIME) + (mts.tv_nsec / 100);
-#elif defined(__CYGWIN__) || !defined(CLOCK_MONOTONIC_RAW)
+#elif !defined(CLOCK_MONOTONIC_RAW)
     struct timespec ts;
     clock_gettime(CLOCK_MONOTONIC, &ts);
     return (ts.tv_sec * UA_SEC_TO_DATETIME) + (ts.tv_nsec / 100);

+ 7 - 2
plugins/ua_config_standard.c

@@ -1,4 +1,9 @@
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
+
 #include "ua_config_standard.h"
+#include "ua_log_stdout.h"
+#include "ua_network_tcp.h"
 
 #define MANUFACTURER_NAME "open62541"
 #define PRODUCT_NAME "open62541 OPC UA Server"
@@ -15,7 +20,7 @@ UA_UsernamePasswordLogin usernamePasswords[2] = {
 
 const UA_ServerConfig UA_ServerConfig_standard = {
     .nThreads = 1,
-    .logger = Logger_Stdout,
+    .logger = UA_Log_Stdout,
 
     /* Server Description */
     .buildInfo = {
@@ -69,7 +74,7 @@ const UA_ServerConfig UA_ServerConfig_standard = {
 const UA_EXPORT UA_ClientConfig UA_ClientConfig_standard = {
     .timeout = 5000,
     .secureChannelLifeTime = 600000,
-    .logger = Logger_Stdout,
+    .logger = UA_Log_Stdout,
     .localConnectionConfig = {
         .protocolVersion = 0,
         .sendBufferSize = 65535,

+ 2 - 6
plugins/ua_config_standard.h

@@ -1,15 +1,11 @@
-/*
- * This work is licensed under a Creative Commons CCZero 1.0 Universal License.
- * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
- */
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
 
 #ifndef UA_CONFIG_STANDARD_H_
 #define UA_CONFIG_STANDARD_H_
 
 #include "ua_server.h"
 #include "ua_client.h"
-#include "logger_stdout.h"
-#include "networklayer_tcp.h"
 
 #ifdef __cplusplus
 extern "C" {

+ 6 - 8
plugins/logger_stdout.c

@@ -1,11 +1,9 @@
-/*
- * This work is licensed under a Creative Commons CCZero 1.0 Universal License.
- * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
- */
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
 
 #include <stdio.h>
 #include <stdarg.h>
-#include "logger_stdout.h"
+#include "ua_log_stdout.h"
 #include "ua_types_generated.h"
 
 const char *LogLevelNames[6] = {"trace", "debug", "info", "warning", "error", "fatal"};
@@ -16,10 +14,10 @@ const char *LogCategoryNames[6] = {"network", "channel", "session", "server", "c
 #pragma GCC diagnostic ignored "-Wformat-nonliteral"
 #endif
 
-void Logger_Stdout(UA_LogLevel level, UA_LogCategory category, const char *msg, ...) {
-	UA_String t = UA_DateTime_toString(UA_DateTime_now());
+void UA_Log_Stdout(UA_LogLevel level, UA_LogCategory category, const char *msg, ...) {
+    UA_String t = UA_DateTime_toString(UA_DateTime_now());
     printf("[%.23s] %s/%s\t", t.data, LogLevelNames[level], LogCategoryNames[category]);
-	UA_ByteString_deleteMembers(&t);
+    UA_ByteString_deleteMembers(&t);
     va_list ap;
     va_start(ap, msg);
     vprintf(msg, ap);

+ 20 - 0
plugins/ua_log_stdout.h

@@ -0,0 +1,20 @@
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
+
+#ifndef UA_LOG_STDOUT_H_
+#define UA_LOG_STDOUT_H_
+
+#include "ua_types.h"
+#include "ua_log.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+UA_EXPORT void UA_Log_Stdout(UA_LogLevel level, UA_LogCategory category, const char *msg, ...);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* UA_LOG_STDOUT_H_ */

+ 5 - 5
plugins/networklayer_tcp.c

@@ -1,9 +1,7 @@
- /*
- * This work is licensed under a Creative Commons CCZero 1.0 Universal License.
- * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
- */
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
 
-#include "networklayer_tcp.h"
+#include "ua_network_tcp.h"
 
 #include <stdlib.h> // malloc, free
 #include <stdio.h> // snprintf
@@ -423,7 +421,9 @@ ServerNetworkLayerTCP_getJobs(UA_ServerNetworkLayer *nl, UA_Job **jobs, UA_UInt1
         int newsockfd = accept(layer->serversockfd, (struct sockaddr *) &cli_addr, &cli_len);
         int i = 1;
         if(newsockfd >= 0) {
+            /* Send messages directly and do wait to merge packets (disable Nagle's algorithm) */
             setsockopt(newsockfd, IPPROTO_TCP, TCP_NODELAY, (void *)&i, sizeof(i));
+
             socket_set_nonblocking(newsockfd);
             ServerNetworkLayerTCP_add(layer, newsockfd);
         }

+ 5 - 7
plugins/networklayer_tcp.h

@@ -1,10 +1,8 @@
-/*
- * This work is licensed under a Creative Commons CCZero 1.0 Universal License.
- * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
- */
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
 
-#ifndef NETWORKLAYERTCP_H_
-#define NETWORKLAYERTCP_H_
+#ifndef UA_NETWORK_TCP_H_
+#define UA_NETWORK_TCP_H_
 
 #ifdef __cplusplus
 extern "C" {
@@ -23,4 +21,4 @@ UA_ClientConnectionTCP(UA_ConnectionConfig conf, const char *endpointUrl, UA_Log
 } // extern "C"
 #endif
 
-#endif /* NETWORKLAYERTCP_H_ */
+#endif /* UA_NETWORK_TCP_H_ */

+ 49 - 52
plugins/networklayer_udp.c

@@ -1,14 +1,11 @@
- /*
- * This work is licensed under a Creative Commons CCZero 1.0 Universal License.
- * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
- */
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
 
-#define _XOPEN_SOURCE 500 //some users need this for some reason
-#define __USE_BSD
+#include "networklayer_udp.h"
 #include <stdlib.h> // malloc, free
 #include <stdio.h>
 #include <string.h> // memset
-#include "networklayer_udp.h"
+
 #ifdef UA_ENABLE_MULTITHREADING
 # include <urcu/uatomic.h>
 #endif
@@ -17,7 +14,7 @@
 # include <errno.h> // errno, EINTR
 # include <fcntl.h> // fcntl
 # include <strings.h> //bzero
-# include <sys/select.h> 
+# include <sys/select.h>
 # include <netinet/in.h>
 # include <netinet/tcp.h>
 # include <sys/socketvar.h>
@@ -56,16 +53,16 @@ static void ReleaseMallocedBuffer(UA_Connection *connection, UA_ByteString *buf)
 /* Forwarded to the server as a (UA_Connection) and used for callbacks back into
    the networklayer */
 typedef struct {
-	UA_Connection connection;
-	struct sockaddr from;
-	socklen_t fromlen;
+    UA_Connection connection;
+    struct sockaddr from;
+    socklen_t fromlen;
 } UDPConnection;
 
 typedef struct {
     UA_ServerNetworkLayer layer;
-	UA_ConnectionConfig conf;
-	fd_set fdset;
-	UA_Int32 serversockfd;
+    UA_ConnectionConfig conf;
+    fd_set fdset;
+    UA_Int32 serversockfd;
     UA_UInt32 port;
 } ServerNetworkLayerUDP;
 
@@ -73,25 +70,25 @@ typedef struct {
 static UA_StatusCode sendUDP(UA_Connection *connection, UA_ByteString *buf) {
     UDPConnection *udpc = (UDPConnection*)connection;
     ServerNetworkLayerUDP *layer = (ServerNetworkLayerUDP*)connection->handle;
-	size_t nWritten = 0;
-	struct sockaddr_in *sin = NULL;
+    size_t nWritten = 0;
+    struct sockaddr_in *sin = NULL;
 
-	if (udpc->from.sa_family == AF_INET) {
+    if (udpc->from.sa_family == AF_INET) {
 #if ((__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || __GNUC__ > 4 || defined(__clang__))
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wcast-align"
 #endif
-	    sin = (struct sockaddr_in *) &udpc->from;
+        sin = (struct sockaddr_in *) &udpc->from;
 #if ((__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || __GNUC__ > 4 || defined(__clang__))
 #pragma GCC diagnostic pop
 #endif
-	} else {
+    } else {
         UA_ByteString_deleteMembers(buf);
-		return UA_STATUSCODE_BADINTERNALERROR;
+        return UA_STATUSCODE_BADINTERNALERROR;
     }
 
-	while (nWritten < (size_t)buf->length) {
-		UA_Int32 n = sendto(layer->serversockfd, buf->data, buf->length, 0,
+    while (nWritten < (size_t)buf->length) {
+        UA_Int32 n = sendto(layer->serversockfd, buf->data, buf->length, 0,
                             (struct sockaddr*)sin, sizeof(struct sockaddr_in));
         if(n == -1L) {
             UA_LOG_WARNING(layer->layer.logger, UA_LOGCATEGORY_NETWORK, "UDP send error %i", errno);
@@ -99,7 +96,7 @@ static UA_StatusCode sendUDP(UA_Connection *connection, UA_ByteString *buf) {
             return UA_STATUSCODE_BADINTERNALERROR;
         }
         nWritten += n;
-	}
+    }
     UA_ByteString_deleteMembers(buf);
     return UA_STATUSCODE_GOOD;
 }
@@ -112,38 +109,38 @@ static UA_StatusCode socket_set_nonblocking(UA_Int32 sockfd) {
 }
 
 static void setFDSet(ServerNetworkLayerUDP *layer) {
-	FD_ZERO(&layer->fdset);
-	FD_SET(layer->serversockfd, &layer->fdset);
+    FD_ZERO(&layer->fdset);
+    FD_SET(layer->serversockfd, &layer->fdset);
 }
 
 static void closeConnectionUDP(UA_Connection *handle) {
-	free(handle);
+    free(handle);
 }
 
 static UA_StatusCode ServerNetworkLayerUDP_start(ServerNetworkLayerUDP *layer, UA_Logger logger) {
     layer->layer.logger = logger;
     layer->serversockfd = socket(PF_INET, SOCK_DGRAM, 0);
     if(layer->serversockfd < 0) {
-		UA_LOG_WARNING(layer->layer.logger, UA_LOGCATEGORY_NETWORK, "Error opening socket");
-		return UA_STATUSCODE_BADINTERNALERROR;
-	} 
-	const struct sockaddr_in serv_addr =
+        UA_LOG_WARNING(layer->layer.logger, UA_LOGCATEGORY_NETWORK, "Error opening socket");
+        return UA_STATUSCODE_BADINTERNALERROR;
+    }
+    const struct sockaddr_in serv_addr =
         {.sin_family = AF_INET, .sin_addr.s_addr = INADDR_ANY,
          .sin_port = htons(layer->port), .sin_zero = {0}};
-	int optval = 1;
-	if(setsockopt(layer->serversockfd, SOL_SOCKET,
+    int optval = 1;
+    if(setsockopt(layer->serversockfd, SOL_SOCKET,
                   SO_REUSEADDR, (const char *)&optval, sizeof(optval)) == -1) {
         UA_LOG_WARNING(layer->layer.logger, UA_LOGCATEGORY_NETWORK, "Could not setsockopt");
-		CLOSESOCKET(layer->serversockfd);
-		return UA_STATUSCODE_BADINTERNALERROR;
-	}
-	if(bind(layer->serversockfd, (const struct sockaddr *)&serv_addr,
+        CLOSESOCKET(layer->serversockfd);
+        return UA_STATUSCODE_BADINTERNALERROR;
+    }
+    if(bind(layer->serversockfd, (const struct sockaddr *)&serv_addr,
             sizeof(serv_addr)) < 0) {
         UA_LOG_WARNING(layer->layer.logger, UA_LOGCATEGORY_NETWORK, "Could not bind the socket");
-		CLOSESOCKET(layer->serversockfd);
-		return UA_STATUSCODE_BADINTERNALERROR;
-	}
-	socket_set_nonblocking(layer->serversockfd);
+        CLOSESOCKET(layer->serversockfd);
+        return UA_STATUSCODE_BADINTERNALERROR;
+    }
+    socket_set_nonblocking(layer->serversockfd);
     UA_LOG_WARNING(layer->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;
@@ -159,9 +156,9 @@ static size_t ServerNetworkLayerUDP_getJobs(ServerNetworkLayerUDP *layer, UA_Job
         return 0;
     }
     items = malloc(sizeof(UA_Job)*resultsize);
-	// read from established sockets
+    // read from established sockets
     UA_Int32 j = 0;
-	UA_ByteString buf = {-1, NULL};
+    UA_ByteString buf = {-1, NULL};
     if(!buf.data) {
         buf.data = malloc(sizeof(UA_Byte) * layer->conf.recvBufferSize);
         if(!buf.data)
@@ -170,12 +167,12 @@ static size_t ServerNetworkLayerUDP_getJobs(ServerNetworkLayerUDP *layer, UA_Job
     struct sockaddr sender;
     socklen_t sendsize = sizeof(sender);
     bzero(&sender, sizeof(sender));
-	ssize_t rec_result = recvfrom(layer->serversockfd, buf.data, layer->conf.recvBufferSize, 0, &sender, &sendsize);
+    ssize_t rec_result = recvfrom(layer->serversockfd, buf.data, layer->conf.recvBufferSize, 0, &sender, &sendsize);
     if (rec_result > 0) {
-    	buf.length = rec_result;
+        buf.length = rec_result;
         UDPConnection *c = malloc(sizeof(UDPConnection));
         if(!c){
-       	    free(items);
+                free(items);
             return UA_STATUSCODE_BADINTERNALERROR;
         }
         UA_Connection_init(&c->connection);
@@ -196,19 +193,19 @@ static size_t ServerNetworkLayerUDP_getJobs(ServerNetworkLayerUDP *layer, UA_Job
         items[j].job.binaryMessage.connection = (UA_Connection*)c;
         buf.data = NULL;
         j++;
-		*jobs = items;
+        *jobs = items;
     } else {
-		free(items);
-		*jobs = NULL;
-	}
+        free(items);
+        *jobs = NULL;
+    }
     if(buf.data)
         free(buf.data);
     return j;
 }
 
 static UA_Int32 ServerNetworkLayerUDP_stop(ServerNetworkLayerUDP * layer, UA_Job **jobs) {
-	CLOSESOCKET(layer->serversockfd);
-	return 0;
+    CLOSESOCKET(layer->serversockfd);
+    return 0;
 }
 
 static void ServerNetworkLayerUDP_deleteMembers(ServerNetworkLayerUDP *layer) {
@@ -220,7 +217,7 @@ UA_ServerNetworkLayer * ServerNetworkLayerUDP_new(UA_ConnectionConfig conf, UA_U
         return NULL;
     memset(layer, 0, sizeof(ServerNetworkLayerUDP));
 
-	layer->conf = conf;
+    layer->conf = conf;
     layer->port = port;
     layer->layer.start = (UA_StatusCode(*)(UA_ServerNetworkLayer*,UA_Logger))ServerNetworkLayerUDP_start;
     layer->layer.getJobs = (size_t(*)(UA_ServerNetworkLayer*,UA_Job**,UA_UInt16))ServerNetworkLayerUDP_getJobs;

+ 6 - 8
plugins/networklayer_udp.h

@@ -1,10 +1,8 @@
-/*
- * This work is licensed under a Creative Commons CCZero 1.0 Universal License.
- * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
- */
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information. */
 
-#ifndef NETWORKLAYERUDP_H_
-#define NETWORKLAYERUDP_H_
+#ifndef UA_NETWORKLAYER_UDP_H_
+#define UA_NETWORKLAYER_UDP_H_
 
 #ifdef __cplusplus
 extern "C" {
@@ -13,7 +11,7 @@ extern "C" {
 #include "ua_server.h"
 #include "ua_client.h"
 
-/** @brief Create the UDP networklayer and listen to the specified port */
+/* Create the UDP networklayer and listen to the specified port */
 UA_ServerNetworkLayer UA_EXPORT * ServerNetworkLayerUDP_new(UA_ConnectionConfig conf, UA_UInt32 port);
 
 UA_Connection UA_EXPORT
@@ -23,4 +21,4 @@ ClientNetworkLayerUDP_connect(UA_ConnectionConfig conf, char endpointUrl[], UA_L
 } // extern "C"
 #endif
 
-#endif /* NETWORKLAYERUDP_H_ */
+#endif /* UA_NETWORKLAYER_UDP_H_ */

+ 5 - 18
src/ua_util.h

@@ -58,30 +58,17 @@
 # warning The compiler does not allow thread-local variables. The library can be built, but will not be thread safe.
 #endif
 
-/********************/
-/* System Libraries */
-/********************/
+/*************************/
+/* External Dependencies */
+/*************************/
 
+/* Fix redefinition of SLIST_ENTRY on windows */
 #ifdef _WIN32
-# include <winsock2.h> //needed for amalgamation
+# include <winsock2.h>
 # include <windows.h>
 # undef SLIST_ENTRY
 #endif
 
-#include <time.h>
-#if !defined(_WIN32) || defined(__MINGW32__)
-# include <sys/time.h>
-#endif
-
-#if defined(__APPLE__) || defined(__MACH__)
-#include <mach/clock.h>
-#include <mach/mach.h>
-#endif
-
-/*************************/
-/* External Dependencies */
-/*************************/
-
 #include "queue.h"
 
 #ifdef UA_ENABLE_MULTITHREADING

+ 18 - 17
tests/check_server_binary_messages.c

@@ -5,6 +5,7 @@
 #include "ua_server.h"
 #include "ua_server_internal.h"
 #include "ua_config_standard.h"
+#include "ua_log_stdout.h"
 #include "testing_networklayers.h"
 
 size_t files;
@@ -31,7 +32,7 @@ static UA_ByteString readFile(char *filename) {
 START_TEST(processMessage) {
     UA_Connection c = createDummyConnection();
     UA_ServerConfig config = UA_ServerConfig_standard;
-    config.logger = Logger_Stdout;
+    config.logger = UA_Log_Stdout;
     UA_Server *server = UA_Server_new(config);
     for(size_t i = 0; i < files; i++) {
         UA_ByteString msg = readFile(filenames[i]);
@@ -41,17 +42,17 @@ START_TEST(processMessage) {
             UA_Server_processBinaryMessage(server, &c, &msg);
         UA_ByteString_deleteMembers(&msg);
     }
-	UA_Server_delete(server);
+    UA_Server_delete(server);
     UA_Connection_deleteMembers(&c);
 }
 END_TEST
 
 static Suite *testSuite_binaryMessages(void) {
-	Suite *s = suite_create("Test server with messages stored in text files");
-	TCase *tc_messages = tcase_create("binary messages");
-	tcase_add_test(tc_messages, processMessage);
-	suite_add_tcase(s, tc_messages);
-	return s;
+    Suite *s = suite_create("Test server with messages stored in text files");
+    TCase *tc_messages = tcase_create("binary messages");
+    tcase_add_test(tc_messages, processMessage);
+    suite_add_tcase(s, tc_messages);
+    return s;
 }
 
 int main(int argc, char **argv) {
@@ -59,14 +60,14 @@ int main(int argc, char **argv) {
         return EXIT_FAILURE;
     filenames = &argv[1];
     files = argc - 1;
-	int number_failed = 0;
-	Suite *s;
-	SRunner *sr;
-	s  = testSuite_binaryMessages();
-	sr = srunner_create(s);
-	srunner_set_fork_status(sr, CK_NOFORK);
-	srunner_run_all(sr, CK_NORMAL);
-	number_failed += srunner_ntests_failed(sr);
-	srunner_free(sr);
-	return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+    int number_failed = 0;
+    Suite *s;
+    SRunner *sr;
+    s  = testSuite_binaryMessages();
+    sr = srunner_create(s);
+    srunner_set_fork_status(sr, CK_NOFORK);
+    srunner_run_all(sr, CK_NORMAL);
+    number_failed += srunner_ntests_failed(sr);
+    srunner_free(sr);
+    return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
 }