mirror of
https://github.com/open62541/open62541.git
synced 2026-10-23 00:38:40 +08:00
refactor(core): Move architecture-specific definition out of the public headers
This commit is contained in:
committed by
Julius Pfrommer
parent
c499d55bd7
commit
928931ec36
@@ -10,6 +10,15 @@
|
||||
|
||||
#include <open62541/plugin/eventloop.h>
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# include <BaseTsd.h>
|
||||
typedef SSIZE_T ssize_t;
|
||||
#else
|
||||
# include <unistd.h> /* ssize_t */
|
||||
#endif
|
||||
|
||||
struct MQTTConnectionManager;
|
||||
typedef struct MQTTConnectionManager MQTTConnectionManager;
|
||||
|
||||
|
||||
@@ -14,6 +14,13 @@
|
||||
|
||||
#if defined(UA_ARCHITECTURE_POSIX) || defined(UA_ARCHITECTURE_WIN32)
|
||||
|
||||
/* Include architecture-specific definitions */
|
||||
#if defined(UA_ARCHITECTURE_WIN32)
|
||||
#include "win32/ua_architecture.h"
|
||||
#elif defined(UA_ARCHITECTURE_POSIX)
|
||||
#include "posix/ua_architecture.h"
|
||||
#endif
|
||||
|
||||
#include "common/ua_timer.h"
|
||||
#include "open62541_queue.h"
|
||||
|
||||
|
||||
@@ -73,8 +73,6 @@ void UA_sleep_ms(unsigned long ms);
|
||||
#define UA_POLLIN POLLIN
|
||||
#define UA_POLLOUT POLLOUT
|
||||
|
||||
#define UA_ENABLE_LOG_COLORS
|
||||
|
||||
#define UA_getnameinfo(sa, salen, host, hostlen, serv, servlen, flags) \
|
||||
getnameinfo(sa, salen, host, hostlen, serv, servlen, flags)
|
||||
#define UA_poll poll
|
||||
@@ -105,15 +103,6 @@ void UA_sleep_ms(unsigned long ms);
|
||||
# define UA_if_nametoindex if_nametoindex
|
||||
#endif
|
||||
|
||||
/* Use the standard malloc */
|
||||
#include <stdlib.h>
|
||||
#ifndef UA_free
|
||||
# define UA_free free
|
||||
# define UA_malloc malloc
|
||||
# define UA_calloc calloc
|
||||
# define UA_realloc realloc
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <strings.h>
|
||||
#define UA_snprintf snprintf
|
||||
@@ -132,58 +121,6 @@ void UA_sleep_ms(unsigned long ms);
|
||||
errno = 0; \
|
||||
}
|
||||
|
||||
#if UA_MULTITHREADING >= 100
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
typedef struct {
|
||||
pthread_mutex_t mutex;
|
||||
int mutexCounter;
|
||||
} UA_Lock;
|
||||
|
||||
#define UA_LOCK_STATIC_INIT {PTHREAD_MUTEX_INITIALIZER, 0}
|
||||
|
||||
static UA_INLINE void
|
||||
UA_LOCK_INIT(UA_Lock *lock) {
|
||||
pthread_mutex_init(&lock->mutex, NULL);
|
||||
lock->mutexCounter = 0;
|
||||
}
|
||||
|
||||
static UA_INLINE void
|
||||
UA_LOCK_DESTROY(UA_Lock *lock) {
|
||||
pthread_mutex_destroy(&lock->mutex);
|
||||
}
|
||||
|
||||
static UA_INLINE void
|
||||
UA_LOCK(UA_Lock *lock) {
|
||||
pthread_mutex_lock(&lock->mutex);
|
||||
UA_assert(lock->mutexCounter == 0);
|
||||
lock->mutexCounter++;
|
||||
}
|
||||
|
||||
static UA_INLINE void
|
||||
UA_UNLOCK(UA_Lock *lock) {
|
||||
UA_assert(lock->mutexCounter == 1);
|
||||
lock->mutexCounter--;
|
||||
pthread_mutex_unlock(&lock->mutex);
|
||||
}
|
||||
|
||||
static UA_INLINE void
|
||||
UA_LOCK_ASSERT(UA_Lock *lock, int num) {
|
||||
UA_assert(lock->mutexCounter == num);
|
||||
}
|
||||
|
||||
#else
|
||||
#define UA_EMPTY_STATEMENT \
|
||||
do { \
|
||||
} while(0)
|
||||
#define UA_LOCK_INIT(lock) UA_EMPTY_STATEMENT
|
||||
#define UA_LOCK_DESTROY(lock) UA_EMPTY_STATEMENT
|
||||
#define UA_LOCK(lock) UA_EMPTY_STATEMENT
|
||||
#define UA_UNLOCK(lock) UA_EMPTY_STATEMENT
|
||||
#define UA_LOCK_ASSERT(lock, num) UA_EMPTY_STATEMENT
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__) && defined(_SYS_QUEUE_H_)
|
||||
// in some compilers there's already a _SYS_QUEUE_H_ which is included first and doesn't
|
||||
// have all functions
|
||||
|
||||
@@ -131,14 +131,6 @@ void UA_sleep_ms(unsigned long ms);
|
||||
# undef maxStringLength
|
||||
#endif
|
||||
|
||||
/* Use the standard malloc */
|
||||
#ifndef UA_free
|
||||
# define UA_free free
|
||||
# define UA_malloc malloc
|
||||
# define UA_calloc calloc
|
||||
# define UA_realloc realloc
|
||||
#endif
|
||||
|
||||
#ifdef __CODEGEARC__
|
||||
#define _snprintf_s(a,b,c,...) snprintf(a,b,__VA_ARGS__)
|
||||
#endif
|
||||
@@ -158,48 +150,6 @@ void UA_sleep_ms(unsigned long ms);
|
||||
}
|
||||
#define UA_LOG_SOCKET_ERRNO_GAI_WRAP UA_LOG_SOCKET_ERRNO_WRAP
|
||||
|
||||
#if UA_MULTITHREADING >= 100
|
||||
|
||||
typedef struct {
|
||||
CRITICAL_SECTION mutex;
|
||||
int mutexCounter;
|
||||
} UA_Lock;
|
||||
|
||||
static UA_INLINE void
|
||||
UA_LOCK_INIT(UA_Lock *lock) {
|
||||
InitializeCriticalSection(&lock->mutex);
|
||||
lock->mutexCounter = 0;
|
||||
}
|
||||
|
||||
static UA_INLINE void
|
||||
UA_LOCK_DESTROY(UA_Lock *lock) {
|
||||
DeleteCriticalSection(&lock->mutex);
|
||||
}
|
||||
|
||||
static UA_INLINE void
|
||||
UA_LOCK(UA_Lock *lock) {
|
||||
EnterCriticalSection(&lock->mutex);
|
||||
UA_assert(++(lock->mutexCounter) == 1);
|
||||
}
|
||||
|
||||
static UA_INLINE void
|
||||
UA_UNLOCK(UA_Lock *lock) {
|
||||
UA_assert(--(lock->mutexCounter) == 0);
|
||||
LeaveCriticalSection(&lock->mutex);
|
||||
}
|
||||
|
||||
static UA_INLINE void
|
||||
UA_LOCK_ASSERT(UA_Lock *lock, int num) {
|
||||
UA_assert(lock->mutexCounter == num);
|
||||
}
|
||||
#else
|
||||
#define UA_LOCK_INIT(lock)
|
||||
#define UA_LOCK_DESTROY(lock)
|
||||
#define UA_LOCK(lock)
|
||||
#define UA_UNLOCK(lock)
|
||||
#define UA_LOCK_ASSERT(lock, num)
|
||||
#endif
|
||||
|
||||
/* Fix redefinition of SLIST_ENTRY on mingw winnt.h */
|
||||
#if !defined(_SYS_QUEUE_H_) && defined(SLIST_ENTRY)
|
||||
# undef SLIST_ENTRY
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <open62541/client_highlevel.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void) {
|
||||
UA_Client *client = UA_Client_new();
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static UA_Boolean
|
||||
allowAddNode(UA_Server *server, UA_AccessControl *ac,
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <open62541/plugin/log_stdout.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef UA_ENABLE_SUBSCRIPTIONS
|
||||
static void
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <open62541/server_config_default.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "common.h"
|
||||
|
||||
#define NODES_EXIST
|
||||
/* async connection callback, it only gets called after the completion of the whole
|
||||
@@ -107,7 +108,7 @@ main(int argc, char *argv[]) {
|
||||
UA_Client_connectAsync(client, "opc.tcp://localhost:4840");
|
||||
|
||||
/*Windows needs time to response*/
|
||||
UA_sleep_ms(100);
|
||||
sleep_ms(100);
|
||||
|
||||
/* What happens if client tries to send request before connected? */
|
||||
UA_Client_sendAsyncBrowseRequest(client, &bReq, fileBrowsed, &userdata, &reqId);
|
||||
@@ -123,7 +124,7 @@ main(int argc, char *argv[]) {
|
||||
/* Requests are processed */
|
||||
UA_BrowseRequest_clear(&bReq);
|
||||
UA_Client_run_iterate(client, 0);
|
||||
UA_sleep_ms(100);
|
||||
sleep_ms(100);
|
||||
|
||||
/* Break loop if server cannot be connected within 2s -- prevents build timeout */
|
||||
if(UA_DateTime_nowMonotonic() - startTime > 2000 * UA_DATETIME_MSEC)
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include "common.h"
|
||||
|
||||
UA_Boolean running = true;
|
||||
|
||||
@@ -49,7 +50,7 @@ int main(void) {
|
||||
UA_LOG_ERROR(UA_Log_Stdout, UA_LOGCATEGORY_CLIENT, "Not connected. Retrying to connect in 1 second");
|
||||
/* The connect may timeout after 1 second (see above) or it may fail immediately on network errors */
|
||||
/* E.g. name resolution errors or unreachable network. Thus there should be a small sleep here */
|
||||
UA_sleep_ms(1000);
|
||||
sleep_ms(1000);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -72,7 +73,7 @@ int main(void) {
|
||||
dts.day, dts.month, dts.year, dts.hour, dts.min, dts.sec, dts.milliSec);
|
||||
}
|
||||
UA_Variant_clear(&value);
|
||||
UA_sleep_ms(1000);
|
||||
sleep_ms(1000);
|
||||
};
|
||||
|
||||
/* Clean up */
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
#include <open62541/client_subscriptions.h>
|
||||
#include <open62541/plugin/log_stdout.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -130,7 +132,7 @@ main(void) {
|
||||
"Not connected. Retrying to connect in 1 second");
|
||||
/* The connect may timeout after 1 second (see above) or it may fail immediately on network errors */
|
||||
/* E.g. name resolution errors or unreachable network. Thus there should be a small sleep here */
|
||||
UA_sleep_ms(1000);
|
||||
sleep_ms(1000);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,17 @@
|
||||
|
||||
#include <open62541/types.h>
|
||||
#include <open62541/types_generated_handling.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
/* sleep_ms */
|
||||
#ifdef _WIN32
|
||||
# include <synchapi.h>
|
||||
# define sleep_ms(ms) Sleep(ms)
|
||||
#else
|
||||
# include <unistd.h>
|
||||
# define sleep_ms(ms) usleep(ms * 1000)
|
||||
#endif
|
||||
|
||||
/* loadFile parses the certificate file.
|
||||
*
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <open62541/client_highlevel.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "custom_datatype.h"
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <open62541/plugin/log_stdout.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define DISCOVERY_SERVER_ENDPOINT "opc.tcp://localhost:4840"
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
const UA_ByteString UA_SECURITY_POLICY_BASIC128_URI =
|
||||
{56, (UA_Byte *)"http://opcfoundation.org/UA/SecurityPolicy#Basic128Rsa15"};
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <open62541/util.h>
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define USE_FILTER_OR_TYPEOF
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
UA_Boolean running = true;
|
||||
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
#include <open62541/server_config_default.h>
|
||||
#include <open62541/plugin/nodesetloader.h>
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
|
||||
UA_Boolean running = true;
|
||||
static void stopHandler(int sign) {
|
||||
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "received ctrl-c");
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
#include <open62541/server_config_default.h>
|
||||
#include <open62541/plugin/nodesetloader.h>
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
|
||||
UA_Boolean running = true;
|
||||
static void stopHandler(int sign) {
|
||||
UA_LOG_INFO(UA_Log_Stdout, UA_LOGCATEGORY_SERVER, "received ctrl-c");
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "../server/ua_server_internal.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include <open62541/plugin/securitypolicy_default.h>
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define UA_AES128CTR_SIGNING_KEY_LENGTH 32
|
||||
#define UA_AES128CTR_KEY_LENGTH 16
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
#include <open62541/server_pubsub.h>
|
||||
#include <open62541/server_config_default.h>
|
||||
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
|
||||
UA_NodeId connectionIdentifier;
|
||||
UA_NodeId readerGroupIdentifier;
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define Publisher_ID 60
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include <open62541/server_config_default.h>
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
|
||||
UA_NodeId connectionIdent, publishedDataSetIdent, writerGroupIdent;
|
||||
|
||||
|
||||
@@ -44,6 +44,8 @@
|
||||
#include <open62541/server.h>
|
||||
#include <open62541/plugin/securitypolicy_default.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define CONNECTION_NAME "MQTT Publisher Connection"
|
||||
#define TRANSPORT_PROFILE_URI "http://opcfoundation.org/UA-Profile/Transport/pubsub-mqtt"
|
||||
#define MQTT_CLIENT_ID "TESTCLIENTPUBSUBMQTT"
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
#include <open62541/server.h>
|
||||
#include <open62541/server_pubsub.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
UA_NodeId connectionIdent, publishedDataSetIdent, writerGroupIdent;
|
||||
|
||||
static void
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <open62541/plugin/pki_default.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
@@ -218,7 +219,7 @@ readRandomStringData (UA_Server *server,
|
||||
return UA_STATUSCODE_GOOD;
|
||||
}
|
||||
char randomName[12];
|
||||
UA_snprintf(randomName, 12, "Random%u", UA_UInt32_random());
|
||||
snprintf(randomName, 12, "Random%u", UA_UInt32_random());
|
||||
UA_String toggle = UA_STRING(randomName);
|
||||
UA_Variant_setScalarCopy(&value->value, &toggle, &UA_TYPES[UA_TYPES_STRING]);
|
||||
value->hasValue = true;
|
||||
@@ -282,7 +283,7 @@ readByteString (UA_Server *server,
|
||||
return UA_STATUSCODE_GOOD;
|
||||
}
|
||||
char randomName[8];
|
||||
UA_snprintf(randomName, 8, "%u%u", UA_UInt32_random(), UA_UInt32_random());
|
||||
snprintf(randomName, 8, "%u%u", UA_UInt32_random(), UA_UInt32_random());
|
||||
UA_ByteString randomByte = UA_BYTESTRING(randomName);
|
||||
UA_Variant_setScalarCopy(&value->value, &randomByte, &UA_TYPES[UA_TYPES_BYTESTRING]);
|
||||
value->hasValue = true;
|
||||
@@ -535,7 +536,7 @@ setInformationModel(UA_Server *server) {
|
||||
attr.dataType = UA_TYPES[type].typeId;
|
||||
#ifndef UA_ENABLE_TYPEDESCRIPTION
|
||||
char name[15];
|
||||
UA_snprintf(name, 15, "%02d", type);
|
||||
snprintf(name, 15, "%02d", type);
|
||||
attr.displayName = UA_LOCALIZEDTEXT("en-US", name);
|
||||
UA_QualifiedName qualifiedName = UA_QUALIFIEDNAME(1, name);
|
||||
#else
|
||||
@@ -622,7 +623,7 @@ setInformationModel(UA_Server *server) {
|
||||
id = DEPTHID; // running id in namespace 0 - Start with Matrix NODE
|
||||
for(UA_UInt32 i = 1; i <= 20; i++) {
|
||||
char name[15];
|
||||
UA_snprintf(name, 15, "depth%u", i);
|
||||
snprintf(name, 15, "depth%u", i);
|
||||
object_attr.description = UA_LOCALIZEDTEXT("en-US", name);
|
||||
object_attr.displayName = UA_LOCALIZEDTEXT("en-US", name);
|
||||
UA_Server_addObjectNode(server, UA_NODEID_NUMERIC(1, id + i),
|
||||
@@ -703,9 +704,9 @@ setInformationModel(UA_Server *server) {
|
||||
for(size_t j = 0; j < 100; j++) {
|
||||
char name[32];
|
||||
#ifndef UA_ENABLE_TYPEDESCRIPTION
|
||||
UA_snprintf(name, 20, "%02d - %i", type, scale_i);
|
||||
snprintf(name, 20, "%02d - %i", type, scale_i);
|
||||
#else
|
||||
UA_snprintf(name, 20, "%s - %i", UA_TYPES[type].typeName, scale_i);
|
||||
snprintf(name, 20, "%s - %i", UA_TYPES[type].typeName, scale_i);
|
||||
#endif
|
||||
attr.displayName = UA_LOCALIZEDTEXT("en-US", name);
|
||||
UA_QualifiedName qualifiedName = UA_QUALIFIEDNAME(1, name);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#ifdef __linux__
|
||||
#include <getopt.h>
|
||||
#endif
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <open62541/server_config_default.h>
|
||||
#include <open62541/util.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <open62541/server_config_default.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static void
|
||||
variables_basic(void) {
|
||||
|
||||
@@ -34,6 +34,9 @@
|
||||
#include <open62541/plugin/log_stdout.h>
|
||||
#include <open62541/server.h>
|
||||
|
||||
#include <signal.h>
|
||||
#include "common.h"
|
||||
|
||||
#ifndef WIN32
|
||||
#include <pthread.h>
|
||||
#define THREAD_HANDLE pthread_t
|
||||
@@ -187,7 +190,7 @@ THREAD_CALLBACK(ThreadWorker) {
|
||||
UA_CallMethodResult_clear(&response);
|
||||
} else {
|
||||
/* not a good style, but done for simplicity :-) */
|
||||
UA_sleep_ms(100);
|
||||
sleep_ms(100);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <open62541/plugin/log_stdout.h>
|
||||
#include <open62541/server.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static void
|
||||
addVariable(UA_Server *server) {
|
||||
|
||||
@@ -263,6 +263,12 @@ extern UA_THREAD_LOCAL void * (*UA_reallocSingleton)(void *ptr, size_t size);
|
||||
# define UA_free(ptr) UA_freeSingleton(ptr)
|
||||
# define UA_calloc(num, size) UA_callocSingleton(num, size)
|
||||
# define UA_realloc(ptr, size) UA_reallocSingleton(ptr, size)
|
||||
#else
|
||||
# include <stdlib.h>
|
||||
# define UA_free free
|
||||
# define UA_malloc malloc
|
||||
# define UA_calloc calloc
|
||||
# define UA_realloc realloc
|
||||
#endif
|
||||
|
||||
/* Stack-allocation of memory. Use C99 variable-length arrays if possible.
|
||||
@@ -321,6 +327,96 @@ extern UA_THREAD_LOCAL void * (*UA_reallocSingleton)(void *ptr, size_t size);
|
||||
# define UA_STATIC_ASSERT(cond,msg) typedef char static_assertion_##msg[(cond)?1:-1]
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Locking for Multithreading
|
||||
* -------------------------- */
|
||||
|
||||
#if UA_MULTITHREADING < 100
|
||||
|
||||
# define UA_LOCK_INIT(lock)
|
||||
# define UA_LOCK_DESTROY(lock)
|
||||
# define UA_LOCK(lock)
|
||||
# define UA_UNLOCK(lock)
|
||||
# define UA_LOCK_ASSERT(lock, num)
|
||||
|
||||
#elif defined(UA_ARCHITECTURE_WIN32)
|
||||
|
||||
typedef struct {
|
||||
CRITICAL_SECTION mutex;
|
||||
int mutexCounter;
|
||||
} UA_Lock;
|
||||
|
||||
static UA_INLINE void
|
||||
UA_LOCK_INIT(UA_Lock *lock) {
|
||||
InitializeCriticalSection(&lock->mutex);
|
||||
lock->mutexCounter = 0;
|
||||
}
|
||||
|
||||
static UA_INLINE void
|
||||
UA_LOCK_DESTROY(UA_Lock *lock) {
|
||||
DeleteCriticalSection(&lock->mutex);
|
||||
}
|
||||
|
||||
static UA_INLINE void
|
||||
UA_LOCK(UA_Lock *lock) {
|
||||
EnterCriticalSection(&lock->mutex);
|
||||
UA_assert(++(lock->mutexCounter) == 1);
|
||||
}
|
||||
|
||||
static UA_INLINE void
|
||||
UA_UNLOCK(UA_Lock *lock) {
|
||||
UA_assert(--(lock->mutexCounter) == 0);
|
||||
LeaveCriticalSection(&lock->mutex);
|
||||
}
|
||||
|
||||
static UA_INLINE void
|
||||
UA_LOCK_ASSERT(UA_Lock *lock, int num) {
|
||||
UA_assert(lock->mutexCounter == num);
|
||||
}
|
||||
|
||||
#elif defined(UA_ARCHITECTURE_POSIX)
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
typedef struct {
|
||||
pthread_mutex_t mutex;
|
||||
int mutexCounter;
|
||||
} UA_Lock;
|
||||
|
||||
#define UA_LOCK_STATIC_INIT {PTHREAD_MUTEX_INITIALIZER, 0}
|
||||
|
||||
static UA_INLINE void
|
||||
UA_LOCK_INIT(UA_Lock *lock) {
|
||||
pthread_mutex_init(&lock->mutex, NULL);
|
||||
lock->mutexCounter = 0;
|
||||
}
|
||||
|
||||
static UA_INLINE void
|
||||
UA_LOCK_DESTROY(UA_Lock *lock) {
|
||||
pthread_mutex_destroy(&lock->mutex);
|
||||
}
|
||||
|
||||
static UA_INLINE void
|
||||
UA_LOCK(UA_Lock *lock) {
|
||||
pthread_mutex_lock(&lock->mutex);
|
||||
UA_assert(lock->mutexCounter == 0);
|
||||
lock->mutexCounter++;
|
||||
}
|
||||
|
||||
static UA_INLINE void
|
||||
UA_UNLOCK(UA_Lock *lock) {
|
||||
UA_assert(lock->mutexCounter == 1);
|
||||
lock->mutexCounter--;
|
||||
pthread_mutex_unlock(&lock->mutex);
|
||||
}
|
||||
|
||||
static UA_INLINE void
|
||||
UA_LOCK_ASSERT(UA_Lock *lock, int num) {
|
||||
UA_assert(lock->mutexCounter == num);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Dynamic Linking
|
||||
* ---------------
|
||||
@@ -547,7 +643,4 @@ UA_STATIC_ASSERT(sizeof(bool) == 1, cannot_overlay_integers_with_large_bool);
|
||||
# define UA_BINARY_OVERLAYABLE_FLOAT 0
|
||||
#endif
|
||||
|
||||
/* Include architecture-specific definitions */
|
||||
#include "${UA_ARCHITECTURE}/ua_architecture.h"
|
||||
|
||||
#endif /* UA_CONFIG_H_ */
|
||||
|
||||
@@ -22,6 +22,14 @@
|
||||
#include <open62541/plugin/securitypolicy_default.h>
|
||||
#include <open62541/server_config_default.h>
|
||||
|
||||
#include <stdio.h> /* For printf */
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <winsock2.h>
|
||||
#else
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
/* Struct initialization works across ANSI C/C99/C++ if it is done when the
|
||||
* variable is first declared. Assigning values to existing structs is
|
||||
* heterogeneous across the three. */
|
||||
@@ -393,8 +401,8 @@ setDefaultConfig(UA_ServerConfig *conf, UA_UInt16 portNumber) {
|
||||
/* 1) Listen on all interfaces (also external). This must be the first
|
||||
* entry if this is desired. Otherwise some interfaces may be blocked
|
||||
* (already in use) with a hostname that is only locally reachable.*/
|
||||
UA_snprintf(serverUrlBuffer[0], sizeof(serverUrlBuffer[0]),
|
||||
"opc.tcp://:%u", portNumber);
|
||||
snprintf(serverUrlBuffer[0], sizeof(serverUrlBuffer[0]),
|
||||
"opc.tcp://:%u", portNumber);
|
||||
serverUrls[serverUrlsSize] = UA_STRING(serverUrlBuffer[0]);
|
||||
serverUrlsSize++;
|
||||
|
||||
@@ -404,14 +412,14 @@ setDefaultConfig(UA_ServerConfig *conf, UA_UInt16 portNumber) {
|
||||
WSADATA wsaData;
|
||||
WSAStartup(MAKEWORD(2, 2), &wsaData);
|
||||
#endif
|
||||
int err = UA_gethostname(hostnamestr, sizeof(hostnamestr));
|
||||
int err = gethostname(hostnamestr, sizeof(hostnamestr));
|
||||
#ifdef _WIN32
|
||||
WSACleanup();
|
||||
#endif
|
||||
|
||||
if(err == 0) {
|
||||
UA_snprintf(serverUrlBuffer[1], sizeof(serverUrlBuffer[1]),
|
||||
"opc.tcp://%s:%u", hostnamestr, portNumber);
|
||||
snprintf(serverUrlBuffer[1], sizeof(serverUrlBuffer[1]),
|
||||
"opc.tcp://%s:%u", hostnamestr, portNumber);
|
||||
serverUrls[serverUrlsSize] = UA_STRING(serverUrlBuffer[1]);
|
||||
serverUrlsSize++;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
/* ANSI escape sequences for color output taken from here:
|
||||
* https://stackoverflow.com/questions/3219393/stdlib-and-colored-output-in-c*/
|
||||
|
||||
#ifdef UA_ENABLE_LOG_COLORS
|
||||
#ifdef UA_ARCHITECTURE_POSIX
|
||||
# define ANSI_COLOR_RED "\x1b[31m"
|
||||
# define ANSI_COLOR_GREEN "\x1b[32m"
|
||||
# define ANSI_COLOR_YELLOW "\x1b[33m"
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#if defined(__linux__) || defined(__unix__)
|
||||
|
||||
#include <syslog.h>
|
||||
#include <stdio.h>
|
||||
|
||||
const char *syslogLevelNames[6] = {"trace", "debug", "info",
|
||||
"warn", "error", "fatal"};
|
||||
|
||||
@@ -12,6 +12,14 @@
|
||||
|
||||
#if defined(UA_ENABLE_DISCOVERY) && defined(UA_ENABLE_DISCOVERY_MULTICAST)
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <winsock2.h>
|
||||
#else
|
||||
# include <sys/types.h>
|
||||
# include <sys/socket.h>
|
||||
# include <netdb.h>
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
UA_DISCOVERY_TCP, /* OPC UA TCP mapping */
|
||||
UA_DISCOVERY_TLS /* OPC UA HTTPS mapping */
|
||||
|
||||
+14
-2
@@ -144,6 +144,19 @@ UA_String_isEmpty(const UA_String *s) {
|
||||
return (s->length == 0 || s->data == NULL);
|
||||
}
|
||||
|
||||
static UA_Byte
|
||||
lowercase(UA_Byte c) {
|
||||
if(((int)c) - 'A' < 26) return c | 32;
|
||||
return c;
|
||||
}
|
||||
|
||||
static int
|
||||
casecmp(const UA_Byte *l, const UA_Byte *r, size_t n) {
|
||||
if(!n--) return 0;
|
||||
for(; *l && *r && n && (*l == *r || lowercase(*l) == lowercase(*r)); l++, r++, n--);
|
||||
return lowercase(*l) - lowercase(*r);
|
||||
}
|
||||
|
||||
/* Do not expose UA_String_equal_ignorecase to public API as it currently only handles
|
||||
* ASCII strings, and not UTF8! */
|
||||
UA_Boolean
|
||||
@@ -155,8 +168,7 @@ UA_String_equal_ignorecase(const UA_String *s1, const UA_String *s2) {
|
||||
if(s2->data == NULL)
|
||||
return false;
|
||||
|
||||
//FIXME this currently does not handle UTF8
|
||||
return UA_strncasecmp((const char*)s1->data, (const char*)s2->data, s1->length) == 0;
|
||||
return casecmp(s1->data, s2->data, s1->length) == 0;
|
||||
}
|
||||
|
||||
static UA_StatusCode
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <float.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h> /* for snprintf */
|
||||
|
||||
#include "../deps/itoa.h"
|
||||
#include "../deps/parse_num.h"
|
||||
@@ -402,7 +403,7 @@ ENCODE_JSON(Float) {
|
||||
} else if(*src == -INFINITY) {
|
||||
strcpy(buffer, "\"-Infinity\"");
|
||||
} else {
|
||||
UA_snprintf(buffer, 200, "%.149g", (UA_Double)*src);
|
||||
snprintf(buffer, 200, "%.149g", (UA_Double)*src);
|
||||
}
|
||||
|
||||
size_t len = strlen(buffer);
|
||||
@@ -427,7 +428,7 @@ ENCODE_JSON(Double) {
|
||||
} else if(*src == -INFINITY) {
|
||||
strcpy(buffer, "\"-Infinity\"");
|
||||
} else {
|
||||
UA_snprintf(buffer, 2000, "%.1074g", *src);
|
||||
snprintf(buffer, 2000, "%.1074g", *src);
|
||||
}
|
||||
|
||||
size_t len = strlen(buffer);
|
||||
|
||||
@@ -488,6 +488,7 @@ UA_Guid_random(void) {
|
||||
|
||||
/* Global malloc singletons */
|
||||
#ifdef UA_ENABLE_MALLOC_SINGLETON
|
||||
# include <stdlib.h>
|
||||
UA_EXPORT UA_THREAD_LOCAL void * (*UA_mallocSingleton)(size_t size) = malloc;
|
||||
UA_EXPORT UA_THREAD_LOCAL void (*UA_freeSingleton)(void *ptr) = free;
|
||||
UA_EXPORT UA_THREAD_LOCAL void * (*UA_callocSingleton)(size_t nelem, size_t elsize) = calloc;
|
||||
|
||||
@@ -171,7 +171,15 @@ isTrue(uint8_t expr) {
|
||||
* Utility Functions
|
||||
* ----------------- */
|
||||
|
||||
#define UA_fileExists(X) ( access(X, 0) == 0)
|
||||
#ifdef UA_ENABLE_DISCOVERY_SEMAPHORE
|
||||
# ifdef _WIN32
|
||||
# include <io.h>
|
||||
# define UA_fileExists(X) ( _access(X, 0) == 0)
|
||||
# else
|
||||
# include <unistd.h>
|
||||
# define UA_fileExists(X) ( access(X, 0) == 0)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
void
|
||||
UA_cleanupDataTypeWithCustom(const UA_DataTypeArray *customTypes);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <open62541/plugin/eventloop.h>
|
||||
#include "testing_clock.h"
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <check.h>
|
||||
|
||||
#define N_EVENTS 10000
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "ua_util_internal.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "check.h"
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "thread_wrapper.h"
|
||||
#include "historical_read_test_data.h"
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static UA_Server *server;
|
||||
static UA_HistoryDataGathering *gathering;
|
||||
|
||||
@@ -1534,8 +1534,6 @@ START_TEST(Client_subscription_transfer) {
|
||||
ck_assert_uint_eq(monResponse.statusCode, UA_STATUSCODE_GOOD);
|
||||
}
|
||||
|
||||
UA_sleep_ms(1000);
|
||||
|
||||
/* Create a second client */
|
||||
UA_Client *client2 = UA_Client_new();
|
||||
UA_ClientConfig_setDefault(UA_Client_getConfig(client2));
|
||||
@@ -1561,7 +1559,7 @@ START_TEST(Client_subscription_transfer) {
|
||||
UA_Client_run_iterate(client, 1);
|
||||
UA_Client_run_iterate(client2, 1);
|
||||
|
||||
UA_sleep_ms(100);
|
||||
UA_fakeSleep(100);
|
||||
}
|
||||
|
||||
/* Delete */
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
** fuzzed input.
|
||||
*/
|
||||
#include <base64.h>
|
||||
#include <malloc.h>
|
||||
|
||||
extern "C" int
|
||||
LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
** fuzzed input.
|
||||
*/
|
||||
#include <base64.h>
|
||||
#include <malloc.h>
|
||||
|
||||
extern "C" int
|
||||
LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
#include "custom_memory_manager.h"
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <open62541/plugin/log_stdout.h>
|
||||
#include <open62541/server_config_default.h>
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <open62541/client_config_default.h>
|
||||
#include <open62541/client_highlevel.h>
|
||||
#include <check.h>
|
||||
#include <stdio.h>
|
||||
#include "thread_wrapper.h"
|
||||
#include "deviceObjectType.h"
|
||||
#include "mt_testing.h"
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <open62541/client_config_default.h>
|
||||
#include <open62541/client_highlevel.h>
|
||||
#include <check.h>
|
||||
#include <stdio.h>
|
||||
#include "thread_wrapper.h"
|
||||
#include "deviceObjectType.h"
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <open62541/client_config_default.h>
|
||||
#include <open62541/client_highlevel.h>
|
||||
#include <check.h>
|
||||
#include <stdio.h>
|
||||
#include "thread_wrapper.h"
|
||||
#include "mt_testing.h"
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <open62541/client_config_default.h>
|
||||
#include <open62541/client_highlevel.h>
|
||||
#include <check.h>
|
||||
#include <stdio.h>
|
||||
#include "thread_wrapper.h"
|
||||
#include "mt_testing.h"
|
||||
|
||||
|
||||
@@ -407,7 +407,7 @@ END_TEST
|
||||
|
||||
START_TEST(requestUnknownStartingTokenId){
|
||||
UA_fakeSleep(1000);
|
||||
UA_sleep_ms(4000);
|
||||
UA_realSleep(4000);
|
||||
UA_Client *sksClient = UA_Client_new();
|
||||
encyrptedclientconnect(sksClient, "user1", "password");
|
||||
UA_StatusCode expectedCode = UA_STATUSCODE_GOOD;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "server/ua_server_internal.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "testing_clock.h"
|
||||
#include "thread_wrapper.h"
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "server/ua_server_internal.h"
|
||||
|
||||
#include <check.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "testing_clock.h"
|
||||
#include "thread_wrapper.h"
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <open62541/server_config_default.h>
|
||||
|
||||
#include <check.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "server/ua_server_internal.h"
|
||||
#include "testing_clock.h"
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
#include <check.h>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "testing_networklayers.h"
|
||||
#include "testing_policy.h"
|
||||
@@ -43,7 +44,7 @@ START_TEST(readSpeed) {
|
||||
UA_NodeId parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
|
||||
for(size_t i = 0; i < READNODES; i++) {
|
||||
char varName[20];
|
||||
UA_snprintf(varName, 20, "Variable %u", (UA_UInt32)i);
|
||||
snprintf(varName, 20, "Variable %u", (UA_UInt32)i);
|
||||
UA_NodeId myNodeId = UA_NODEID_STRING(1, varName);
|
||||
UA_QualifiedName myName = UA_QUALIFIEDNAME(1, varName);
|
||||
retval = UA_Server_addVariableNode(server, myNodeId, parentNodeId,
|
||||
@@ -112,7 +113,7 @@ START_TEST(readSpeedWithEncoding) {
|
||||
UA_NodeId parentReferenceNodeId = UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES);
|
||||
for(size_t i = 0; i < READNODES; i++) {
|
||||
char varName[20];
|
||||
UA_snprintf(varName, 20, "Variable %u", (UA_UInt32)i);
|
||||
snprintf(varName, 20, "Variable %u", (UA_UInt32)i);
|
||||
UA_NodeId myNodeId = UA_NODEID_STRING(1, varName);
|
||||
UA_QualifiedName myName = UA_QUALIFIEDNAME(1, varName);
|
||||
retval = UA_Server_addVariableNode(server, myNodeId, parentNodeId,
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <check.h>
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static UA_Server *server;
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <open62541/client_subscriptions.h>
|
||||
|
||||
#include <check.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "testing_clock.h"
|
||||
#include "thread_wrapper.h"
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "server/ua_subscription.h"
|
||||
|
||||
#include <check.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "testing_clock.h"
|
||||
#include "thread_wrapper.h"
|
||||
|
||||
Reference in New Issue
Block a user