Browse Source

include all sources in amalgamation + ifdefs to activate features; replace tabs with spaces

Julius Pfrommer 8 years ago
parent
commit
cd0c012e47

+ 69 - 78
CMakeLists.txt

@@ -15,7 +15,7 @@ if(GIT_FOUND)
   execute_process(COMMAND ${GIT_EXECUTABLE} describe --abbrev=7 --dirty --always --tags
                   RESULT_VARIABLE res_var
                   OUTPUT_VARIABLE GIT_COM_ID
-				  WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
+                  WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
     if(NOT ${res_var} EQUAL 0)
         set(GIT_COMMIT_ID "unknown--git-commit-id-unknown")
         message(STATUS "Git failed (not a repo, or no tags). Build will not contain git revision info." )
@@ -55,7 +55,7 @@ if(CMAKE_COMPILER_IS_GNUCC OR "x${CMAKE_C_COMPILER_ID}" STREQUAL "xClang")
   # library linking
   set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") # cmake sets -rdynamic by default
   if(NOT WIN32 AND NOT CYGWIN)
-	add_definitions(-Wshadow -Wconversion -fvisibility=hidden -fPIC)
+    add_definitions(-Wshadow -Wconversion -fvisibility=hidden -fPIC)
     if(NOT APPLE)
       set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,-z,norelro -Wl,--hash-style=gnu -Wl,--build-id=none")
     endif()
@@ -63,10 +63,10 @@ if(CMAKE_COMPILER_IS_GNUCC OR "x${CMAKE_C_COMPILER_ID}" STREQUAL "xClang")
 
   # Debug
   if(CMAKE_BUILD_TYPE STREQUAL "Debug")
-	# add_definitions(-fsanitize=address)
+    # add_definitions(-fsanitize=address)
     # list(APPEND open62541_LIBRARIES asan)
 
-	# add_definitions(-fsanitize=undefined)
+    # add_definitions(-fsanitize=undefined)
     # list(APPEND open62541_LIBRARIES ubsan)
 
   elseif(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" OR
@@ -87,7 +87,7 @@ if(CMAKE_COMPILER_IS_GNUCC OR "x${CMAKE_C_COMPILER_ID}" STREQUAL "xClang")
       endif()
     endif()
   endif()
-  
+
   if(APPLE)
     set(CMAKE_MACOSX_RPATH 1)
     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_DARWIN_C_SOURCE=1")
@@ -183,6 +183,7 @@ set(internal_headers ${PROJECT_SOURCE_DIR}/deps/queue.h
                      ${PROJECT_SOURCE_DIR}/src/ua_securechannel.h
                      ${PROJECT_SOURCE_DIR}/src/server/ua_nodes.h
                      ${PROJECT_SOURCE_DIR}/src/ua_session.h
+                     ${PROJECT_SOURCE_DIR}/src/server/ua_subscription.h
                      ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore.h
                      ${PROJECT_SOURCE_DIR}/src/server/ua_session_manager.h
                      ${PROJECT_SOURCE_DIR}/src/server/ua_securechannel_manager.h
@@ -210,6 +211,16 @@ set(lib_sources ${PROJECT_SOURCE_DIR}/src/ua_types.c
                 ${PROJECT_SOURCE_DIR}/src/server/ua_services_view.c
                 ${PROJECT_SOURCE_DIR}/src/client/ua_client.c
                 ${PROJECT_SOURCE_DIR}/src/client/ua_client_highlevel.c
+                # nodestores
+                ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore.c
+                ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore_concurrent.c
+                # method call
+                ${PROJECT_SOURCE_DIR}/src/server/ua_services_call.c
+                # subscriptions
+                ${PROJECT_SOURCE_DIR}/src/server/ua_subscription.c
+                ${PROJECT_SOURCE_DIR}/src/server/ua_services_subscription.c
+                ${PROJECT_SOURCE_DIR}/src/client/ua_client_highlevel_subscriptions.c
+                # plugins and dependencies
                 ${PROJECT_SOURCE_DIR}/plugins/networklayer_tcp.c
                 ${PROJECT_SOURCE_DIR}/plugins/logger_stdout.c
                 ${PROJECT_SOURCE_DIR}/plugins/ua_config_standard.c
@@ -217,32 +228,10 @@ set(lib_sources ${PROJECT_SOURCE_DIR}/src/ua_types.c
                 ${PROJECT_SOURCE_DIR}/deps/pcg_basic.c)
                 ##TODO: make client stuff optional
 
-if(UA_ENABLE_METHODCALLS)
-  list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/src/server/ua_services_call.c)
-endif()
-
 if(UA_ENABLE_EMBEDDED_LIBC)
   list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/deps/libc_string.c)
 endif()
 
-if(UA_ENABLE_MULTITHREADING)
-  find_package(Threads REQUIRED)
-  list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore_concurrent.c)
-else()
-  list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/src/server/ua_nodestore.c)
-endif()
-
-set(generate_subscriptiontypes "")
-if(UA_ENABLE_SUBSCRIPTIONS)
-  list(APPEND lib_sources ${PROJECT_SOURCE_DIR}/src/server/ua_services_subscription.c
-                          ${PROJECT_SOURCE_DIR}/src/server/ua_subscription.c
-                          ${PROJECT_SOURCE_DIR}/src/client/ua_client_highlevel_subscriptions.c)
-  #append subscription headers at before ua_session
-  list(FIND internal_headers "${PROJECT_SOURCE_DIR}/src/ua_nodestore.h" UaSessionPos) # position after session.h
-  list(INSERT internal_headers ${UaSessionPos} ${PROJECT_SOURCE_DIR}/src/server/ua_subscription.h)
-  set(generate_subscriptiontypes "--enable-subscription-types=1")
-endif()
-
 if(UA_ENABLE_GENERATE_NAMESPACE0)
   set(GENERATE_NAMESPACE0_FILE "Opc.Ua.NodeSet2.xml" CACHE STRING "Namespace definition XML file")
   set_property(CACHE GENERATE_NAMESPACE0_FILE PROPERTY STRINGS Opc.Ua.NodeSet2.xml Opc.Ua.NodeSet2.Minimal.xml)
@@ -380,10 +369,12 @@ if(UA_BUILD_EXAMPLESERVER)
     endif()
 
     if(UA_ENABLE_NONSTANDARD_UDP)
-      add_executable(exampleServerUDP $<TARGET_OBJECTS:open62541-object> examples/networklayer_udp.c examples/server_udp.c)
+      add_executable(exampleServerUDP $<TARGET_OBJECTS:open62541-object>
+                                      examples/networklayer_udp.c
+                                      examples/server_udp.c)
       target_link_libraries(exampleServerUDP ${open62541_LIBRARIES} open62541)
       if(UA_ENABLE_MULTITHREADING)
-  	    target_link_libraries(exampleServerUDP urcu-cds urcu urcu-common)
+        target_link_libraries(exampleServerUDP urcu-cds urcu urcu-common)
       endif()
       if (NOT APPLE)
         target_link_libraries(exampleServerUDP rt)
@@ -403,12 +394,12 @@ if(UA_BUILD_SELFSIGNED_CERTIFICATE)
 endif()
 
 if(UA_BUILD_EXAMPLECLIENT)
-	add_definitions(-DBENCHMARK)
+    add_definitions(-DBENCHMARK)
     set(client_source $<TARGET_OBJECTS:open62541-object>)
-	add_executable(client_static examples/client.c ${client_source})
+    add_executable(client_static examples/client.c ${client_source})
     add_executable(client examples/client.c)
-	target_link_libraries(client_static ${open62541_LIBRARIES})
-	target_link_libraries(client open62541 ${open62541_LIBRARIES})
+    target_link_libraries(client_static ${open62541_LIBRARIES})
+    target_link_libraries(client open62541 ${open62541_LIBRARIES})
     if(WIN32)
         target_link_libraries(client_static ws2_32)
         target_link_libraries(client ws2_32)
@@ -422,7 +413,7 @@ if(UA_BUILD_EXAMPLECLIENT)
     endif()
     if(UA_ENABLE_NONSTANDARD_STATELESS AND NOT UA_ENABLE_AMALGAMATION)
         add_executable(client_stateless examples/client_stateless.c ${client_source})
-	    target_link_libraries(client_stateless open62541 ${open62541_LIBRARIES})
+        target_link_libraries(client_stateless open62541 ${open62541_LIBRARIES})
         if(UA_ENABLE_MULTITHREADING)
             target_link_libraries(client_stateless urcu-cds urcu urcu-common pthread)
         endif()
@@ -430,7 +421,7 @@ if(UA_BUILD_EXAMPLECLIENT)
 endif()
 
 if(UA_BUILD_UNIT_TESTS)
-	add_definitions(-DUA_BUILD_UNIT_TESTS)
+  add_definitions(-DUA_BUILD_UNIT_TESTS)
     enable_testing()
     add_subdirectory(tests)
 endif()
@@ -440,66 +431,66 @@ if(UA_BUILD_EXAMPLES)
     #FIXME: we had problem with static linking for msvs, here a quick and dirty workaround
     #http://stackoverflow.com/questions/3704374/linking-error-lnk2019-in-msvc-unresolved-symbols-with-imp-prefix-but-shoul
     #http://stackoverflow.com/questions/1089828/same-header-file-for-both-dll-and-static-library
-	list(APPEND LIBS ${open62541_LIBRARIES})
+    list(APPEND LIBS ${open62541_LIBRARIES})
     if(NOT WIN32)
-		list(APPEND LIBS pthread)
-		if (NOT APPLE)
-		    list(APPEND LIBS rt)
-		endif()
-	else()
-		list(APPEND LIBS ws2_32)
-	endif()
-	if(UA_ENABLE_MULTITHREADING)
-		list(APPEND LIBS urcu-cds urcu urcu-common)
-	endif(UA_ENABLE_MULTITHREADING)
-	
+      list(APPEND LIBS pthread)
+      if (NOT APPLE)
+        list(APPEND LIBS rt)
+      endif()
+    else()
+      list(APPEND LIBS ws2_32)
+    endif()
+    if(UA_ENABLE_MULTITHREADING)
+      list(APPEND LIBS urcu-cds urcu urcu-common)
+    endif(UA_ENABLE_MULTITHREADING)
+    
     add_executable(server_variable ${PROJECT_SOURCE_DIR}/examples/server_variable.c $<TARGET_OBJECTS:open62541-object>)
-	target_link_libraries(server_variable ${LIBS})
+    target_link_libraries(server_variable ${LIBS})
 
     add_executable(server_mainloop ${PROJECT_SOURCE_DIR}/examples/server_mainloop.c $<TARGET_OBJECTS:open62541-object>)
-	target_link_libraries(server_mainloop ${LIBS})
+    target_link_libraries(server_mainloop ${LIBS})
 
-	add_executable(server_datasource ${PROJECT_SOURCE_DIR}/examples/server_datasource.c $<TARGET_OBJECTS:open62541-object>)
-	target_link_libraries(server_datasource ${LIBS})
+    add_executable(server_datasource ${PROJECT_SOURCE_DIR}/examples/server_datasource.c $<TARGET_OBJECTS:open62541-object>)
+    target_link_libraries(server_datasource ${LIBS})
 
-	# add_executable(server_readspeed ${PROJECT_SOURCE_DIR}/examples/server_readspeed.c $<TARGET_OBJECTS:open62541-object>)
-	# target_link_libraries(server_readspeed ${LIBS})
+    # add_executable(server_readspeed ${PROJECT_SOURCE_DIR}/examples/server_readspeed.c $<TARGET_OBJECTS:open62541-object>)
+    # target_link_libraries(server_readspeed ${LIBS})
 
-	add_executable(server_firstSteps ${PROJECT_SOURCE_DIR}/examples/server_firstSteps.c $<TARGET_OBJECTS:open62541-object>)
-	target_link_libraries(server_firstSteps ${LIBS})
+    add_executable(server_firstSteps ${PROJECT_SOURCE_DIR}/examples/server_firstSteps.c $<TARGET_OBJECTS:open62541-object>)
+    target_link_libraries(server_firstSteps ${LIBS})
 
-	add_executable(client_firstSteps ${PROJECT_SOURCE_DIR}/examples/client_firstSteps.c $<TARGET_OBJECTS:open62541-object>)
-	target_link_libraries(client_firstSteps ${LIBS})
+    add_executable(client_firstSteps ${PROJECT_SOURCE_DIR}/examples/client_firstSteps.c $<TARGET_OBJECTS:open62541-object>)
+    target_link_libraries(client_firstSteps ${LIBS})
 
-	add_executable(server_repeated_job ${PROJECT_SOURCE_DIR}/examples/server_repeated_job.c $<TARGET_OBJECTS:open62541-object>)
-	target_link_libraries(server_repeated_job ${LIBS})
+    add_executable(server_repeated_job ${PROJECT_SOURCE_DIR}/examples/server_repeated_job.c $<TARGET_OBJECTS:open62541-object>)
+    target_link_libraries(server_repeated_job ${LIBS})
 
-	add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/nodeset.h ${PROJECT_BINARY_DIR}/src_generated/nodeset.c
-					   PRE_BUILD
-					   COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/generate_open62541CCode.py
+    add_custom_command(OUTPUT ${PROJECT_BINARY_DIR}/src_generated/nodeset.h ${PROJECT_BINARY_DIR}/src_generated/nodeset.c
+                      PRE_BUILD
+                      COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/generate_open62541CCode.py
                                                     -i ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/NodeID_Blacklist_FullNS0.txt
                                                     ${PROJECT_SOURCE_DIR}/tools/schema/namespace0/Opc.Ua.NodeSet2.xml
                                                     ${PROJECT_SOURCE_DIR}/examples/server_nodeset.xml
                                                     ${PROJECT_BINARY_DIR}/src_generated/nodeset
-					   DEPENDS ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/generate_open62541CCode.py
-					           ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/logger.py
-					           ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/open62541_MacroHelper.py
-					           ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_builtin_types.py
-					           ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_constants.py
-					           ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_namespace.py
-					           ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_node_types.py
-					           ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/NodeID_Blacklist_FullNS0.txt
-					           ${PROJECT_SOURCE_DIR}/examples/server_nodeset.xml)
-					   
-	add_executable(server_nodeset ${PROJECT_SOURCE_DIR}/examples/server_nodeset.c
+                      DEPENDS ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/generate_open62541CCode.py
+                              ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/logger.py
+                              ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/open62541_MacroHelper.py
+                              ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_builtin_types.py
+                              ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_constants.py
+                              ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_namespace.py
+                              ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/ua_node_types.py
+                              ${PROJECT_SOURCE_DIR}/tools/pyUANamespace/NodeID_Blacklist_FullNS0.txt
+                              ${PROJECT_SOURCE_DIR}/examples/server_nodeset.xml)
+
+    add_executable(server_nodeset ${PROJECT_SOURCE_DIR}/examples/server_nodeset.c
                                   ${PROJECT_BINARY_DIR}/src_generated/nodeset.c
                                   $<TARGET_OBJECTS:open62541-object>)
-	target_link_libraries(server_nodeset ${LIBS})
+    target_link_libraries(server_nodeset ${LIBS})
 
-	if(UA_ENABLE_METHODCALLS)
-	  add_executable(server_method ${PROJECT_SOURCE_DIR}/examples/server_method.c $<TARGET_OBJECTS:open62541-object>)
-	  target_link_libraries(server_method ${LIBS})
-	endif()
+    if(UA_ENABLE_METHODCALLS)
+      add_executable(server_method ${PROJECT_SOURCE_DIR}/examples/server_method.c $<TARGET_OBJECTS:open62541-object>)
+      target_link_libraries(server_method ${LIBS})
+    endif()
 endif()
 
 if(UA_BUILD_DOCUMENTATION)

+ 4 - 0
src/client/ua_client_highlevel_subscriptions.c

@@ -1,3 +1,5 @@
+#ifdef UA_ENABLE_SUBSCRIPTIONS /* conditional compilation */
+
 #include "ua_client_highlevel.h"
 #include "ua_client_internal.h"
 #include "ua_util.h"
@@ -297,3 +299,5 @@ UA_StatusCode UA_Client_Subscriptions_manuallySendPublishRequest(UA_Client *clie
     }
     return UA_STATUSCODE_GOOD;
 }
+
+#endif /* UA_ENABLE_SUBSCRIPTIONS */

+ 4 - 0
src/server/ua_nodestore.c

@@ -1,3 +1,5 @@
+#ifndef UA_ENABLE_MULTITHREADING /* conditional compilation */
+
 #include <stdio.h>
 
 #include "ua_nodestore.h"
@@ -290,3 +292,5 @@ void UA_NodeStore_iterate(UA_NodeStore *ns, UA_NodeStore_nodeVisitor visitor) {
             visitor((UA_Node*)&ns->entries[i]->node);
     }
 }
+
+#endif /* UA_ENABLE_MULTITHREADING */

+ 4 - 0
src/server/ua_nodestore_concurrent.c

@@ -1,3 +1,5 @@
+#ifdef UA_ENABLE_MULTITHREADING /* conditional compilation */
+
 #include "ua_util.h"
 #include "ua_nodestore.h"
 
@@ -222,3 +224,5 @@ void UA_NodeStore_iterate(UA_NodeStore *ns, UA_NodeStore_nodeVisitor visitor) {
         cds_lfht_next(ht, &iter);
     }
 }
+
+#endif /* UA_ENABLE_MULTITHREADING */

+ 8 - 4
src/server/ua_services_call.c

@@ -1,3 +1,5 @@
+#ifdef UA_ENABLE_METHODCALLS /* conditional compilation */
+
 #include "ua_services.h"
 #include "ua_server_internal.h"
 
@@ -6,13 +8,13 @@ getArgumentsVariableNode(UA_Server *server, const UA_MethodNode *ofMethod,
                          UA_String withBrowseName) {
     UA_NodeId hasProperty = UA_NODEID_NUMERIC(0, UA_NS0ID_HASPROPERTY);
     for(size_t i = 0; i < ofMethod->referencesSize; i++) {
-        if(ofMethod->references[i].isInverse == false && 
+        if(ofMethod->references[i].isInverse == false &&
             UA_NodeId_equal(&hasProperty, &ofMethod->references[i].referenceTypeId)) {
             const UA_Node *refTarget =
                 UA_NodeStore_get(server->nodestore, &ofMethod->references[i].targetId.nodeId);
             if(!refTarget)
                 continue;
-            if(refTarget->nodeClass == UA_NODECLASS_VARIABLE && 
+            if(refTarget->nodeClass == UA_NODECLASS_VARIABLE &&
                 refTarget->browseName.namespaceIndex == 0 &&
                 UA_String_equal(&withBrowseName, &refTarget->browseName.name)) {
                 return (const UA_VariableNode*) refTarget;
@@ -30,7 +32,7 @@ satisfySignature(const UA_Variant *var, const UA_Argument *arg) {
     // Note: The namespace compiler will compile nodes with their actual array dimensions
     // Todo: Check if this is standard conform for scalars
     if(arg->arrayDimensionsSize > 0 && var->arrayDimensionsSize > 0)
-        if(var->arrayDimensionsSize != arg->arrayDimensionsSize) 
+        if(var->arrayDimensionsSize != arg->arrayDimensionsSize)
             return UA_STATUSCODE_BADINVALIDARGUMENT;
         
     UA_Int32 *varDims = var->arrayDimensions;
@@ -129,7 +131,7 @@ Service_Call_single(UA_Server *server, UA_Session *session, const UA_CallMethodR
     }
     
     /* Verify method/object relations */
-    // Object must have a hasComponent reference (or any inherited referenceType from sayd reference) 
+    // Object must have a hasComponent reference (or any inherited referenceType from sayd reference)
     // to be valid for a methodCall...
     result->statusCode = UA_STATUSCODE_BADMETHODINVALID;
     for(size_t i = 0; i < withObject->referencesSize; i++) {
@@ -204,3 +206,5 @@ void Service_Call(UA_Server *server, UA_Session *session, const UA_CallRequest *
     for(size_t i = 0; i < request->methodsToCallSize;i++)
         Service_Call_single(server, session, &request->methodsToCall[i], &response->results[i]);
 }
+
+#endif /* UA_ENABLE_METHODCALLS */

+ 66 - 62
src/server/ua_services_subscription.c

@@ -1,3 +1,5 @@
+#ifdef UA_ENABLE_SUBSCRIPTIONS /* conditional compilation */
+
 #include "ua_server_internal.h"
 #include "ua_services.h"
 #include "ua_subscription.h"
@@ -15,21 +17,22 @@ setSubscriptionSettings(UA_Server *server, UA_Subscription *subscription,
                         UA_UInt32 requestedMaxKeepAliveCount,
                         UA_UInt32 maxNotificationsPerPublish, UA_Byte priority) {
     Subscription_unregisterPublishJob(server, subscription);
-	subscription->publishingInterval = requestedPublishingInterval;
-	UA_BOUNDEDVALUE_SETWBOUNDS(server->config.publishingIntervalLimits,
-		requestedPublishingInterval, subscription->publishingInterval);
-	/* check for nan*/
-	if(requestedPublishingInterval != requestedPublishingInterval)
-		subscription->publishingInterval = server->config.publishingIntervalLimits.min;
+    subscription->publishingInterval = requestedPublishingInterval;
+    UA_BOUNDEDVALUE_SETWBOUNDS(server->config.publishingIntervalLimits,
+                               requestedPublishingInterval, subscription->publishingInterval);
+    /* check for nan*/
+    if(requestedPublishingInterval != requestedPublishingInterval)
+        subscription->publishingInterval = server->config.publishingIntervalLimits.min;
     UA_BOUNDEDVALUE_SETWBOUNDS(server->config.keepAliveCountLimits,
                                requestedMaxKeepAliveCount, subscription->maxKeepAliveCount);
     UA_BOUNDEDVALUE_SETWBOUNDS(server->config.lifeTimeCountLimits,
                                requestedLifetimeCount, subscription->lifeTimeCount);
     if(subscription->lifeTimeCount < 3 * subscription->maxKeepAliveCount)
         subscription->lifeTimeCount = 3 * subscription->maxKeepAliveCount;
-	subscription->notificationsPerPublish = maxNotificationsPerPublish;
-	if(maxNotificationsPerPublish == 0 || maxNotificationsPerPublish > server->config.maxNotificationsPerPublish)
-		subscription->notificationsPerPublish = server->config.maxNotificationsPerPublish;
+    subscription->notificationsPerPublish = maxNotificationsPerPublish;
+    if(maxNotificationsPerPublish == 0 ||
+       maxNotificationsPerPublish > server->config.maxNotificationsPerPublish)
+        subscription->notificationsPerPublish = server->config.maxNotificationsPerPublish;
     subscription->priority = priority;
     Subscription_registerPublishJob(server, subscription);
 }
@@ -44,12 +47,13 @@ void Service_CreateSubscription(UA_Server *server, UA_Session *session,
         return;
     }
 
-    UA_Session_addSubscription(session, newSubscription);    
+    UA_Session_addSubscription(session, newSubscription);
     newSubscription->publishingEnabled = request->publishingEnabled;
     setSubscriptionSettings(server, newSubscription, request->requestedPublishingInterval,
                             request->requestedLifetimeCount, request->requestedMaxKeepAliveCount,
                             request->maxNotificationsPerPublish, request->priority);
-    newSubscription->currentKeepAliveCount = newSubscription->maxKeepAliveCount; /* immediately send the first response */
+    /* immediately send the first response */
+    newSubscription->currentKeepAliveCount = newSubscription->maxKeepAliveCount;
     response->revisedPublishingInterval = newSubscription->publishingInterval;
     response->revisedLifetimeCount = newSubscription->lifeTimeCount;
     response->revisedMaxKeepAliveCount = newSubscription->maxKeepAliveCount;
@@ -75,30 +79,31 @@ void Service_ModifySubscription(UA_Server *server, UA_Session *session,
 }
 
 void Service_SetPublishingMode(UA_Server *server, UA_Session *session,
-	const UA_SetPublishingModeRequest *request,	UA_SetPublishingModeResponse *response) {
-
-	if(request->subscriptionIdsSize <= 0) {
-		response->responseHeader.serviceResult = UA_STATUSCODE_BADNOTHINGTODO;
-		return;
-	}
-
-	size_t size = request->subscriptionIdsSize;
-	response->results = UA_Array_new(size, &UA_TYPES[UA_TYPES_STATUSCODE]);
-	if(!response->results) {
-		response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
-		return;
-	}
-
-	response->resultsSize = size;
-	for(size_t i = 0; i < size; i++) {
-		UA_Subscription *sub = UA_Session_getSubscriptionByID(session, request->subscriptionIds[i]);
-		if(!sub) {
-			response->results[i] = UA_STATUSCODE_BADSUBSCRIPTIONIDINVALID;
-			continue;
-		}
-		sub->publishingEnabled = request->publishingEnabled;
+                               const UA_SetPublishingModeRequest *request,
+                               UA_SetPublishingModeResponse *response) {
+
+    if(request->subscriptionIdsSize <= 0) {
+        response->responseHeader.serviceResult = UA_STATUSCODE_BADNOTHINGTODO;
+        return;
+    }
+
+    size_t size = request->subscriptionIdsSize;
+    response->results = UA_Array_new(size, &UA_TYPES[UA_TYPES_STATUSCODE]);
+    if(!response->results) {
+        response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
+        return;
+    }
+
+    response->resultsSize = size;
+    for(size_t i = 0; i < size; i++) {
+        UA_Subscription *sub = UA_Session_getSubscriptionByID(session, request->subscriptionIds[i]);
+        if(!sub) {
+            response->results[i] = UA_STATUSCODE_BADSUBSCRIPTIONIDINVALID;
+            continue;
+        }
+        sub->publishingEnabled = request->publishingEnabled;
         sub->currentLifetimeCount = 0; /* Reset the subscription lifetime */
-	}
+    }
 }
 
 static void
@@ -109,12 +114,12 @@ setMonitoredItemSettings(UA_Server *server, UA_MonitoredItem *mon,
     MonitoredItem_unregisterSampleJob(server, mon);
     mon->monitoringMode = monitoringMode;
     mon->clientHandle = clientHandle;
-	mon->samplingInterval = samplingInterval;
-	UA_BOUNDEDVALUE_SETWBOUNDS(server->config.samplingIntervalLimits,
-		samplingInterval, mon->samplingInterval);
-	/* Check for nan */
-	if(samplingInterval != samplingInterval)
-		mon->samplingInterval = server->config.samplingIntervalLimits.min;
+    mon->samplingInterval = samplingInterval;
+    UA_BOUNDEDVALUE_SETWBOUNDS(server->config.samplingIntervalLimits,
+        samplingInterval, mon->samplingInterval);
+    /* Check for nan */
+    if(samplingInterval != samplingInterval)
+        mon->samplingInterval = server->config.samplingIntervalLimits.min;
     UA_BOUNDEDVALUE_SETWBOUNDS(server->config.queueSizeLimits,
                                queueSize, mon->maxQueueSize);
     mon->discardOldest = discardOldest;
@@ -136,7 +141,7 @@ Service_CreateMonitoredItems_single(UA_Server *server, UA_Session *session, UA_S
     // TODO: Check if the target node type has the requested attribute
 
     /* Check if the encoding is supported */
-	if(request->itemToMonitor.dataEncoding.name.length > 0 &&
+    if(request->itemToMonitor.dataEncoding.name.length > 0 &&
        !UA_String_equal(&binaryEncoding, &request->itemToMonitor.dataEncoding.name)) {
         result->statusCode = UA_STATUSCODE_BADDATAENCODINGUNSUPPORTED;
         return;
@@ -184,7 +189,6 @@ Service_CreateMonitoredItems(UA_Server *server, UA_Session *session,
 
     /* Reset the subscription lifetime */
     sub->currentLifetimeCount = 0;
-    
     if(request->itemsToCreateSize <= 0) {
         response->responseHeader.serviceResult = UA_STATUSCODE_BADNOTHINGTODO;
         return;
@@ -233,7 +237,6 @@ void Service_ModifyMonitoredItems(UA_Server *server, UA_Session *session,
 
     /* Reset the subscription lifetime */
     sub->currentLifetimeCount = 0;
-    
     if(request->itemsToModifySize <= 0) {
         response->responseHeader.serviceResult = UA_STATUSCODE_BADNOTHINGTODO;
         return;
@@ -255,24 +258,24 @@ void Service_ModifyMonitoredItems(UA_Server *server, UA_Session *session,
 
 void
 Service_Publish(UA_Server *server, UA_Session *session,
-	            const UA_PublishRequest *request, UA_UInt32 requestId) {
-	/* Return an error if the session has no subscription */
-	if(LIST_EMPTY(&session->serverSubscriptions)) {
-		UA_PublishResponse response;
-		UA_PublishResponse_init(&response);
-		response.responseHeader.requestHandle = request->requestHeader.requestHandle;
-		response.responseHeader.serviceResult = UA_STATUSCODE_BADNOSUBSCRIPTION;
-		UA_SecureChannel_sendBinaryMessage(session->channel, requestId, &response,
-			                               &UA_TYPES[UA_TYPES_PUBLISHRESPONSE]);
-		return;
-	}
-
-	// todo error handling for malloc
+                const UA_PublishRequest *request, UA_UInt32 requestId) {
+    /* Return an error if the session has no subscription */
+    if(LIST_EMPTY(&session->serverSubscriptions)) {
+        UA_PublishResponse response;
+        UA_PublishResponse_init(&response);
+        response.responseHeader.requestHandle = request->requestHeader.requestHandle;
+        response.responseHeader.serviceResult = UA_STATUSCODE_BADNOSUBSCRIPTION;
+        UA_SecureChannel_sendBinaryMessage(session->channel, requestId, &response,
+                                           &UA_TYPES[UA_TYPES_PUBLISHRESPONSE]);
+        return;
+    }
+
+    // todo error handling for malloc
     UA_PublishResponseEntry *entry = UA_malloc(sizeof(UA_PublishResponseEntry));
-	entry->requestId = requestId;
+    entry->requestId = requestId;
     UA_PublishResponse *response = &entry->response;
-	UA_PublishResponse_init(response);
-	response->responseHeader.requestHandle = request->requestHeader.requestHandle;
+    UA_PublishResponse_init(response);
+    response->responseHeader.requestHandle = request->requestHeader.requestHandle;
 
     /* Delete Acknowledged Subscription Messages */
     response->results = UA_malloc(request->subscriptionAcknowledgementsSize * sizeof(UA_StatusCode));
@@ -335,7 +338,7 @@ void Service_DeleteSubscriptions(UA_Server *server, UA_Session *session,
 
     for(size_t i = 0; i < request->subscriptionIdsSize; i++)
         response->results[i] = UA_Session_deleteSubscription(server, session, request->subscriptionIds[i]);
-} 
+}
 
 void Service_DeleteMonitoredItems(UA_Server *server, UA_Session *session,
                                   const UA_DeleteMonitoredItemsRequest *request,
@@ -348,7 +351,6 @@ void Service_DeleteMonitoredItems(UA_Server *server, UA_Session *session,
 
     /* Reset the subscription lifetime */
     sub->currentLifetimeCount = 0;
-    
     response->results = UA_malloc(sizeof(UA_StatusCode) * request->monitoredItemIdsSize);
     if(!response->results) {
         response->responseHeader.serviceResult = UA_STATUSCODE_BADOUTOFMEMORY;
@@ -371,7 +373,7 @@ void Service_Republish(UA_Server *server, UA_Session *session, const UA_Republis
 
     /* Reset the subscription lifetime */
     sub->currentLifetimeCount = 0;
-    
+
     /* Find the notification in the retransmission queue  */
     UA_NotificationMessageEntry *entry;
     LIST_FOREACH(entry, &sub->retransmissionQueue, listEntry) {
@@ -384,3 +386,5 @@ void Service_Republish(UA_Server *server, UA_Session *session, const UA_Republis
     else
       response->responseHeader.serviceResult = UA_STATUSCODE_BADMESSAGENOTAVAILABLE;
 }
+
+#endif /* UA_ENABLE_SUBSCRIPTIONS */

+ 37 - 33
src/server/ua_subscription.c

@@ -1,3 +1,5 @@
+#ifdef UA_ENABLE_SUBSCRIPTIONS /* conditional compilation */
+
 #include "ua_subscription.h"
 #include "ua_server_internal.h"
 #include "ua_services.h"
@@ -57,7 +59,7 @@ static void SampleCallback(UA_Server *server, UA_MonitoredItem *monitoredItem) {
     newvalue->clientHandle = monitoredItem->clientHandle;
     UA_LOG_DEBUG(server->config.logger, UA_LOGCATEGORY_SERVER,
                  "Sampling the value on monitoreditem %u", monitoredItem->itemId);
-  
+
     /* Read the value */
     UA_ReadValueId rvid;
     UA_ReadValueId_init(&rvid);
@@ -91,7 +93,7 @@ static void SampleCallback(UA_Server *server, UA_MonitoredItem *monitoredItem) {
                      "Do not sample since the data value has not changed");
         return;
     }
-  
+
     /* do we have space in the queue? */
     if(monitoredItem->currentQueueSize >= monitoredItem->maxQueueSize) {
         if(!monitoredItem->discardOldest) {
@@ -107,7 +109,7 @@ static void SampleCallback(UA_Server *server, UA_MonitoredItem *monitoredItem) {
         UA_free(queueItem);
         monitoredItem->currentQueueSize--;
     }
-  
+
     /* add the sample */
     UA_ByteString_deleteMembers(&monitoredItem->lastSampledValue);
     monitoredItem->lastSampledValue = newValueAsByteString;
@@ -145,12 +147,12 @@ UA_Subscription * UA_Subscription_new(UA_Session *session, UA_UInt32 subscriptio
     new->subscriptionID = subscriptionID;
     new->sequenceNumber = 0;
     new->maxKeepAliveCount = 0;
-	new->publishingEnabled = false;
+    new->publishingEnabled = false;
     memset(&new->publishJobGuid, 0, sizeof(UA_Guid));
     new->publishJobIsRegistered = false;
-	new->currentKeepAliveCount = 0;
-	new->currentLifetimeCount = 0;
-	new->state = UA_SUBSCRIPTIONSTATE_LATE; /* The first publish response is sent immediately */
+    new->currentKeepAliveCount = 0;
+    new->currentLifetimeCount = 0;
+    new->state = UA_SUBSCRIPTIONSTATE_LATE; /* The first publish response is sent immediately */
     LIST_INIT(&new->retransmissionQueue);
     LIST_INIT(&new->MonitoredItems);
     return new;
@@ -229,44 +231,44 @@ void UA_Subscription_publishCallback(UA_Server *server, UA_Subscription *sub) {
     if(!channel)
         return;
 
-	/* Dequeue a response */
-	UA_PublishResponseEntry *pre = SIMPLEQ_FIRST(&sub->session->responseQueue);
-	if(!pre) {
-		UA_LOG_DEBUG(server->config.logger, UA_LOGCATEGORY_SERVER,
-			"Cannot send a publish response on subscription %u " \
-			"since the publish queue is empty on session %u",
-			sub->subscriptionID, sub->session->authenticationToken.identifier.numeric);
-		if(sub->state != UA_SUBSCRIPTIONSTATE_LATE) {
-			sub->state = UA_SUBSCRIPTIONSTATE_LATE;
-		} else {
-			sub->currentLifetimeCount++;
-			if(sub->currentLifetimeCount >= sub->lifeTimeCount) {
-				UA_LOG_INFO(server->config.logger, UA_LOGCATEGORY_SERVER,
-					"End of lifetime for subscription %u on session %u",
-					sub->subscriptionID, sub->session->authenticationToken.identifier.numeric);
-				UA_Session_deleteSubscription(server, sub->session, sub->subscriptionID);
-			}
-		}
-		return;
-	}
-	SIMPLEQ_REMOVE_HEAD(&sub->session->responseQueue, listEntry);
+    /* Dequeue a response */
+    UA_PublishResponseEntry *pre = SIMPLEQ_FIRST(&sub->session->responseQueue);
+    if(!pre) {
+        UA_LOG_DEBUG(server->config.logger, UA_LOGCATEGORY_SERVER,
+            "Cannot send a publish response on subscription %u " \
+            "since the publish queue is empty on session %u",
+            sub->subscriptionID, sub->session->authenticationToken.identifier.numeric);
+        if(sub->state != UA_SUBSCRIPTIONSTATE_LATE) {
+            sub->state = UA_SUBSCRIPTIONSTATE_LATE;
+        } else {
+            sub->currentLifetimeCount++;
+            if(sub->currentLifetimeCount >= sub->lifeTimeCount) {
+                UA_LOG_INFO(server->config.logger, UA_LOGCATEGORY_SERVER,
+                    "End of lifetime for subscription %u on session %u",
+                    sub->subscriptionID, sub->session->authenticationToken.identifier.numeric);
+                UA_Session_deleteSubscription(server, sub->session, sub->subscriptionID);
+            }
+        }
+        return;
+    }
+    SIMPLEQ_REMOVE_HEAD(&sub->session->responseQueue, listEntry);
     UA_PublishResponse *response = &pre->response;
     UA_UInt32 requestId = pre->requestId;
 
-	/* We have a request. Reset state to normal. */
-	sub->state = UA_SUBSCRIPTIONSTATE_NORMAL;
+    /* We have a request. Reset state to normal. */
+    sub->state = UA_SUBSCRIPTIONSTATE_NORMAL;
     sub->currentKeepAliveCount = 0;
     sub->currentLifetimeCount = 0;
 
-	/* Prepare the response */
+    /* Prepare the response */
     response->responseHeader.timestamp = UA_DateTime_now();
     response->subscriptionId = sub->subscriptionID;
-	response->moreNotifications = moreNotifications;
+    response->moreNotifications = moreNotifications;
     UA_NotificationMessage *message = &response->notificationMessage;
     message->publishTime = response->responseHeader.timestamp;
     if(notifications == 0) {
         /* Send sequence number for the next notification */
-		message->sequenceNumber = sub->sequenceNumber + 1;
+        message->sequenceNumber = sub->sequenceNumber + 1;
     } else {
         /* Increase the sequence number */
         message->sequenceNumber = ++sub->sequenceNumber;
@@ -367,3 +369,5 @@ UA_StatusCode Subscription_unregisterPublishJob(UA_Server *server, UA_Subscripti
                      "with status code 0x%08x\n", retval);
     return retval;
 }
+
+#endif /* UA_ENABLE_SUBSCRIPTIONS */

+ 2 - 4
src/ua_securechannel.c

@@ -124,8 +124,7 @@ void UA_SecureChannel_revolveTokens(UA_SecureChannel *channel){
 }
 
 UA_StatusCode UA_SecureChannel_sendBinaryMessage(UA_SecureChannel *channel, UA_UInt32 requestId,
-                                                  const void *content,
-                                                  const UA_DataType *contentType) {
+                                                  const void *content, const UA_DataType *contentType) {
     UA_Connection *connection = channel->connection;
     if(!connection)
         return UA_STATUSCODE_BADINTERNALERROR;
@@ -147,8 +146,7 @@ UA_StatusCode UA_SecureChannel_sendBinaryMessage(UA_SecureChannel *channel, UA_U
     seqHeader.requestId = requestId;
 
     UA_ByteString message;
-    UA_StatusCode retval = connection->getSendBuffer(connection, connection->remoteConf.recvBufferSize,
-                                                     &message);
+    UA_StatusCode retval = connection->getSendBuffer(connection, connection->remoteConf.recvBufferSize, &message);
     if(retval != UA_STATUSCODE_GOOD)
         return retval;