open62541 1.4.15
Open source implementation of OPC UA
Loading...
Searching...
No Matches
config.h
Go to the documentation of this file.
1/** This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5#ifndef UA_CONFIG_H_
6#define UA_CONFIG_H_
7
8
9#define UA_OPEN62541_VER_MAJOR 1
10#define UA_OPEN62541_VER_MINOR 4
11#define UA_OPEN62541_VER_PATCH 15
12#define UA_OPEN62541_VER_LABEL "-undefined" /* Release candidate label, etc. */
13#define UA_OPEN62541_VER_COMMIT "unknown-commit"
14#define UA_OPEN62541_VERSION "v1.4.15-undefined"
15
16
17
18/** #undef UA_ARCHITECTURE_WIN32 */
19#define UA_ARCHITECTURE_POSIX
20
21/** Select default architecture if none is selected */
22#if !defined(UA_ARCHITECTURE_WIN32) && !defined(UA_ARCHITECTURE_POSIX)
23# ifdef _WIN32
24# define UA_ARCHITECTURE_WIN32
25# else
26# define UA_ARCHITECTURE_POSIX
27# endif
28#endif
29
30
31
32#define UA_LOGLEVEL 100
33#ifndef UA_ENABLE_AMALGAMATION
34/** #undef UA_ENABLE_AMALGAMATION */
35#endif
36#define UA_ENABLE_METHODCALLS
37#define UA_ENABLE_NODEMANAGEMENT
38#define UA_ENABLE_SUBSCRIPTIONS
39#define UA_ENABLE_PUBSUB
40/** #undef UA_ENABLE_PUBSUB_ENCRYPTION */
41/** #undef UA_ENABLE_PUBSUB_FILE_CONFIG */
42#define UA_ENABLE_PUBSUB_INFORMATIONMODEL
43#define UA_ENABLE_DA
44#define UA_ENABLE_DIAGNOSTICS
45#define UA_ENABLE_HISTORIZING
46#define UA_ENABLE_PARSING
47#define UA_ENABLE_SUBSCRIPTIONS_EVENTS
48#define UA_ENABLE_JSON_ENCODING
49/** #undef UA_ENABLE_XML_ENCODING */
50/** #undef UA_ENABLE_MQTT */
51/** #undef UA_ENABLE_NODESET_INJECTOR */
52/** #undef UA_INFORMATION_MODEL_AUTOLOAD */
53/** #undef UA_ENABLE_ENCRYPTION_MBEDTLS */
54/** #undef UA_ENABLE_CERT_REJECTED_DIR */
55/** #undef UA_ENABLE_TPM2_SECURITY */
56/** #undef UA_ENABLE_ENCRYPTION_OPENSSL */
57/** #undef UA_ENABLE_ENCRYPTION_LIBRESSL */
58#if defined(UA_ENABLE_ENCRYPTION_MBEDTLS) || defined(UA_ENABLE_ENCRYPTION_OPENSSL) || defined(UA_ENABLE_ENCRYPTION_LIBRESSL)
59#define UA_ENABLE_ENCRYPTION
60#endif
61/** #undef UA_ENABLE_SUBSCRIPTIONS_ALARMS_CONDITIONS */
62
63/** Multithreading */
64/** #undef UA_ENABLE_IMMUTABLE_NODES */
65#define UA_MULTITHREADING 100
66
67/** Advanced Options */
68#define UA_ENABLE_STATUSCODE_DESCRIPTIONS
69#define UA_ENABLE_TYPEDESCRIPTION
70/** #undef UA_ENABLE_INLINABLE_EXPORT */
71#define UA_ENABLE_NODESET_COMPILER_DESCRIPTIONS
72/** #undef UA_ENABLE_DETERMINISTIC_RNG */
73#define UA_ENABLE_DISCOVERY
74/** #undef UA_ENABLE_DISCOVERY_MULTICAST */
75/** #undef UA_ENABLE_QUERY */
76/** #undef UA_ENABLE_MALLOC_SINGLETON */
77#define UA_ENABLE_DISCOVERY_SEMAPHORE
78#define UA_GENERATED_NAMESPACE_ZERO
79/** #undef UA_GENERATED_NAMESPACE_ZERO_FULL */
80/** #undef UA_ENABLE_PUBSUB_MONITORING */
81/** #undef UA_ENABLE_PUBSUB_BUFMALLOC */
82/** #undef UA_ENABLE_PUBSUB_SKS */
83
84/** Options for Debugging */
85#define UA_DEBUG
86/** #undef UA_DEBUG_DUMP_PKGS */
87/** #undef UA_DEBUG_FILE_LINE_INFO */
88
89/** Options for Tests */
90/** #undef UA_ENABLE_ALLOW_REUSEADDR */
91
92
93/** #undef UA_DYNAMIC_LINKING */
94
95/** Shortcuts for extern "C" declarations */
96#if !defined(_UA_BEGIN_DECLS)
97# ifdef __cplusplus
98# define _UA_BEGIN_DECLS extern "C" {
99# else
100# define _UA_BEGIN_DECLS
101# endif
102#endif
103#if !defined(_UA_END_DECLS)
104# ifdef __cplusplus
105# define _UA_END_DECLS }
106# else
107# define _UA_END_DECLS
108# endif
109#endif
110
111
112
113#if defined(__QNX__)
114# define _QNX_SOURCE 1
115#endif
116
117
118#ifdef UA_ARCHITECTURE_POSIX
119# if !defined(_XOPEN_SOURCE) && !defined(__FreeBSD__)
120# define _XOPEN_SOURCE 600
121# endif
122# ifndef _DEFAULT_SOURCE
123# define _DEFAULT_SOURCE
124# endif
125
126/** On older systems we need to define _BSD_SOURCE.
127 * _DEFAULT_SOURCE is an alias for that. */
128# ifndef _BSD_SOURCE
129# define _BSD_SOURCE
130# endif
131
132/** Define _GNU_SOURCE to get functions like poll. Comment this out to
133 * only use standard POSIX definitions. */
134# ifndef _GNU_SOURCE
135# define _GNU_SOURCE
136# endif
137
138#define UA_HAS_GETIFADDR 1
139#endif
140
141
142#include <stddef.h>
143#include <stdint.h>
144#include <stdbool.h>
145#include <inttypes.h>
146#include <float.h>
147#include <string.h>
148
149
150#ifdef _MSC_VER
151# define __inline
152#else
153# define inline
154#endif
155
156/** An inlinable method is typically defined as "static inline". Some
157 * applications, such as language bindings with a C FFI (foreign function
158 * interface), can however not work with static inline methods. These can set
159 * the global UA_ENABLE_INLINABLE_EXPORT macro which causes all inlinable
160 * methods to be exported as a regular public API method.
161 *
162 * Note that UA_ENABLE_INLINABLE_EXPORT has a negative impact for both size and
163 * performance of the library. */
164#if defined(UA_ENABLE_INLINABLE_EXPORT) && defined(UA_INLINABLE_IMPL)
165# define UA_INLINABLE(decl, impl) decl; decl impl
166#elif defined(UA_ENABLE_INLINABLE_EXPORT)
167# define UA_INLINABLE(decl, impl) decl;
168#else
169# define UA_INLINABLE(decl, impl) static decl impl
170#endif
171
172
173#if UA_MULTITHREADING >= 100
174# if defined(__GNUC__) /* Also covers clang */
175# define UA_THREAD_LOCAL __thread
176# elif defined(_MSC_VER)
177# define UA_THREAD_LOCAL __declspec(thread)
178# endif
179#endif
180#ifndef UA_THREAD_LOCAL
181# define UA_THREAD_LOCAL
182#endif
183
184
185
186/** Intrinsic atomic operations are not available everywhere for MSVC.
187 * Use the win32 API. Prevent duplicate definitions by via winsock2. */
188#if UA_MULTITHREADING >= 100 && defined(_WIN32)
189# ifndef _WINSOCKAPI_
190# define _NO_WINSOCKAPI_
191# endif
192# define _WINSOCKAPI_
193# include <windows.h>
194# ifdef _NO_WINSOCKAPI_
195# undef _WINSOCKAPI_
196# endif
197#endif
198
199static void *
200UA_atomic_xchg(void * volatile * addr, void *newptr) {
201#if UA_MULTITHREADING >= 100 && defined(_WIN32) /* Visual Studio */
202 return InterlockedExchangePointer(addr, newptr);
203#elif UA_MULTITHREADING >= 100 && defined(__GNUC__) /* GCC/Clang */
204 return __sync_lock_test_and_set(addr, newptr);
205#else
206# if UA_MULTITHREADING >= 100
207# warning Atomic operations not implemented
208# endif
209 void *old = *addr;
210 *addr = newptr;
211 return old;
212#endif
213}
214
215static void *
216UA_atomic_cmpxchg(void * volatile * addr, void *expected, void *newptr) {
217#if UA_MULTITHREADING >= 100 && defined(_WIN32) /* Visual Studio */
218 return InterlockedCompareExchangePointer(addr, newptr, expected);
219#elif UA_MULTITHREADING >= 100 && defined(__GNUC__) /* GCC/Clang */
220 return __sync_val_compare_and_swap(addr, expected, newptr);
221#else
222 void *old = *addr;
223 if(old == expected)
224 *addr = newptr;
225 return old;
226#endif
227}
228
229
230
231#ifdef UA_ENABLE_MALLOC_SINGLETON
232extern UA_THREAD_LOCAL void * (*UA_mallocSingleton)(size_t size);
233extern UA_THREAD_LOCAL void (*UA_freeSingleton)(void *ptr);
234extern UA_THREAD_LOCAL void * (*UA_callocSingleton)(size_t nelem, size_t elsize);
235extern UA_THREAD_LOCAL void * (*UA_reallocSingleton)(void *ptr, size_t size);
236# define UA_malloc(size) UA_mallocSingleton(size)
237# define UA_free(ptr) UA_freeSingleton(ptr)
238# define UA_calloc(num, size) UA_callocSingleton(num, size)
239# define UA_realloc(ptr, size) UA_reallocSingleton(ptr, size)
240#else
241# include <stdlib.h>
242# define UA_free free
243# define UA_malloc malloc
244# define UA_calloc calloc
245# define UA_realloc realloc
246#endif
247
248/** Stack-allocation of memory. Use C99 variable-length arrays if possible.
249 * Otherwise revert to alloca. Note that alloca is not supported on some
250 * plattforms. */
251#ifndef UA_STACKARRAY
252# if defined(__GNUC__) || defined(__clang__)
253# define UA_STACKARRAY(TYPE, NAME, SIZE) TYPE NAME[SIZE]
254# else
255# if defined(__GNUC__) || defined(__clang__)
256# define UA_alloca(size) __builtin_alloca (size)
257# elif defined(_WIN32)
258# define UA_alloca(SIZE) _alloca(SIZE)
259# else
260# include <alloca.h>
261# define UA_alloca(SIZE) alloca(SIZE)
262# endif
263# define UA_STACKARRAY(TYPE, NAME, SIZE) \
264 /* cppcheck-suppress allocaCalled */ \
265 TYPE *(NAME) = (TYPE*)UA_alloca(sizeof(TYPE) * (SIZE))
266# endif
267#endif
268
269
270#ifdef UA_DEBUG
271# include <assert.h>
272# define UA_assert(ignore) assert(ignore)
273#else
274# define UA_assert(ignore) do {} while(0)
275#endif
276
277/** Outputs an error message at compile time if the assert fails.
278 * Example usage:
279 * UA_STATIC_ASSERT(sizeof(long)==7, use_another_compiler_luke)
280 * See: https://stackoverflow.com/a/4815532/869402 */
281#if defined(__cplusplus) && __cplusplus >= 201103L /* C++11 or above */
282# define UA_STATIC_ASSERT(cond,msg) static_assert(cond, #msg)
283#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L /* C11 or above */
284# define UA_STATIC_ASSERT(cond,msg) _Static_assert(cond, #msg)
285#elif defined(__GNUC__) || defined(__clang__) || defined(_MSC_VER) /* GCC, Clang, MSC */
286# define UA_CTASTR2(pre,post) pre ## post
287# define UA_CTASTR(pre,post) UA_CTASTR2(pre,post)
288# ifndef __COUNTER__ /* PPC GCC fix */
289# define __COUNTER__ __LINE__
290# endif
291# define UA_STATIC_ASSERT(cond,msg) \
292 typedef struct { \
293 unsigned int UA_CTASTR(static_assertion_failed_,msg) : !!(cond); \
294 } UA_CTASTR(static_assertion_failed_,__COUNTER__)
295#else /* Everybody else */
296# define UA_STATIC_ASSERT(cond,msg) typedef char static_assertion_##msg[(cond)?1:-1]
297#endif
298
299
300
301#if UA_MULTITHREADING < 100
302
303# define UA_LOCK_INIT(lock)
304# define UA_LOCK_DESTROY(lock)
305# define UA_LOCK(lock)
306# define UA_UNLOCK(lock)
307# define UA_LOCK_ASSERT(lock, num)
308
309#elif defined(UA_ARCHITECTURE_WIN32)
310
311typedef struct {
312 /* Critical sections on win32 are always recursive */
313 CRITICAL_SECTION mutex;
314 int mutexCounter;
315} UA_Lock;
316
317static void
318UA_LOCK_INIT(UA_Lock *lock) {
319 InitializeCriticalSection(&lock->mutex);
320 lock->mutexCounter = 0;
321}
322
323static void
324UA_LOCK_DESTROY(UA_Lock *lock) {
325 DeleteCriticalSection(&lock->mutex);
326}
327
328static void
329UA_LOCK(UA_Lock *lock) {
330 EnterCriticalSection(&lock->mutex);
331 ++lock->mutexCounter;
332}
333
334static void
335UA_UNLOCK(UA_Lock *lock) {
336 --lock->mutexCounter;
337 LeaveCriticalSection(&lock->mutex);
338}
339
340static void
341UA_LOCK_ASSERT(UA_Lock *lock, int num) {
342 UA_assert(num <= 0 || lock->mutexCounter > 0);
343}
344
345#elif defined(UA_ARCHITECTURE_POSIX)
346
347#include <pthread.h>
348
349typedef struct {
350 pthread_mutex_t mutex;
352} UA_Lock;
353
354static void
355UA_LOCK_INIT(UA_Lock *lock) {
356 pthread_mutexattr_t mattr;
357 pthread_mutexattr_init(&mattr);
358 pthread_mutexattr_settype(&mattr, PTHREAD_MUTEX_RECURSIVE);
359 pthread_mutex_init(&lock->mutex, &mattr);
360 pthread_mutexattr_destroy(&mattr);
361 lock->mutexCounter = 0;
362}
363
364static void
365UA_LOCK_DESTROY(UA_Lock *lock) {
366 pthread_mutex_destroy(&lock->mutex);
367}
368
369static void
370UA_LOCK(UA_Lock *lock) {
371 pthread_mutex_lock(&lock->mutex);
372 lock->mutexCounter++;
373}
374
375static void
376UA_UNLOCK(UA_Lock *lock) {
377 lock->mutexCounter--;
378 pthread_mutex_unlock(&lock->mutex);
379}
380
381static void
382UA_LOCK_ASSERT(UA_Lock *lock, int num) {
383 UA_assert(num <= 0 || lock->mutexCounter > 0);
384}
385
386#endif
387
388
389#if defined(_WIN32) && defined(UA_DYNAMIC_LINKING)
390# ifdef UA_DYNAMIC_LINKING_EXPORT /* export dll */
391# ifdef __GNUC__
392# define __attribute__ ((dllexport))
393# else
394# define __declspec(dllexport)
395# endif
396# else /* import dll */
397# ifdef __GNUC__
398# define __attribute__ ((dllimport))
399# else
400# define __declspec(dllimport)
401# endif
402# endif
403#else /* non win32 */
404# if __GNUC__ || __clang__
405# define __attribute__ ((visibility ("default")))
406# endif
407#endif
408#ifndef
409# define /* fallback to default */
410#endif
411
412
413#define UA_THREADSAFE
414
415
416#ifdef _MSC_VER
417# define__restrict
418#elif defined(__GNUC__)
419# define__restrict__
420#elif defined(__CODEGEARC__)
421# define_RESTRICT
422#else
423# definerestrict
424#endif
425
426
427#if defined(__GNUC__) || defined(__clang__)
428# define UA_LIKELY(x) __builtin_expect((x), 1)
429# define UA_UNLIKELY(x) __builtin_expect((x), 0)
430#else
431# define UA_LIKELY(x) x
432# define UA_UNLIKELY(x) x
433#endif
434
435
436#if defined(__GNUC__) || defined(__clang__)
437# define __attribute__((malloc))
438# define UA_FUNC_ATTR_PURE __attribute__ ((pure))
439# define UA_FUNC_ATTR_CONST __attribute__((const))
440# define __attribute__((warn_unused_result))
441# define UA_FORMAT(X,Y) __attribute__ ((format (printf, X, Y)))
442#elif defined(_MSC_VER) && _MSC_VER >= 1800
443# include <sal.h>
444# define
445# define UA_FUNC_ATTR_PURE
446# define UA_FUNC_ATTR_CONST
447# define _Check_return_
448# define UA_FORMAT(X,Y)
449#else
450# define
451# define UA_FUNC_ATTR_PURE
452# define UA_FUNC_ATTR_CONST
453# define
454# define UA_FORMAT(X,Y)
455#endif
456
457#if defined(__GNUC__) || defined(__clang__)
458# define UA_DEPRECATED __attribute__((deprecated))
459#elif defined(_MSC_VER)
460# define UA_DEPRECATED __declspec(deprecated)
461#else
462# define UA_DEPRECATED
463#endif
464
465
466
467#if defined(UA_INTERNAL) && (defined(__GNUC__) || defined(__clang__))
468# define UA_INTERNAL_DEPRECATED \
469 _Pragma ("GCC warning \"Macro is deprecated for internal use\"")
470#else
471# define UA_INTERNAL_DEPRECATED
472#endif
473
474#if defined(UA_INTERNAL) && (defined(__GNUC__) || defined(__clang__))
475# define UA_INTERNAL_FUNC_ATTR_WARN_UNUSED_RESULT \
476 __attribute__((warn_unused_result))
477#else
478# define UA_INTERNAL_FUNC_ATTR_WARN_UNUSED_RESULT
479#endif
480
481
482#if defined(_WIN32)
483# define UA_LITTLE_ENDIAN 1
484#elif defined(__i386__) || defined(__x86_64__) || defined(__amd64__)
485# define UA_LITTLE_ENDIAN 1
486#elif (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
487 (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__))
488# define UA_LITTLE_ENDIAN 1
489#elif defined(__linux__) /* Linux (including Android) */
490# include <endian.h>
491# if __BYTE_ORDER == __LITTLE_ENDIAN
492# define UA_LITTLE_ENDIAN 1
493# endif
494#elif defined(__OpenBSD__) /* OpenBSD */
495# include <sys/endian.h>
496# if BYTE_ORDER == LITTLE_ENDIAN
497# define UA_LITTLE_ENDIAN 1
498# endif
499#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) /* Other BSD */
500# include <sys/endian.h>
501# if _BYTE_ORDER == _LITTLE_ENDIAN
502# define UA_LITTLE_ENDIAN 1
503# endif
504#elif defined(__APPLE__) /* Apple (MacOS, iOS) */
505# include <libkern/OSByteOrder.h>
506# if defined(__LITTLE_ENDIAN__)
507# define UA_LITTLE_ENDIAN 1
508# endif
509#elif defined(__QNX__) || defined(__QNXNTO__) /* QNX */
510# include <gulliver.h>
511# if defined(__LITTLEENDIAN__)
512# define UA_LITTLE_ENDIAN 1
513# endif
514#elif defined(_OS9000) /* OS-9 */
515# if defined(_LIL_END)
516# define UA_LITTLE_ENDIAN 1
517# endif
518#endif
519#ifndef UA_LITTLE_ENDIAN
520# define UA_LITTLE_ENDIAN 0
521#endif
522
523/** Can the integers be memcpy'd onto the network buffer? Add additional checks
524 * here. Some platforms (e.g. QNX) have sizeof(bool) > 1. Manually disable
525 * overlayed integer encoding if that is the case. */
526#if (UA_LITTLE_ENDIAN == 1)
527UA_STATIC_ASSERT(sizeof(bool) == 1, cannot_overlay_integers_with_large_bool);
528# define UA_BINARY_OVERLAYABLE_INTEGER 1
529#else
530# define UA_BINARY_OVERLAYABLE_INTEGER 0
531#endif
532
533
534
535#ifndef UA_FLOAT_IEEE754
536#if defined(_WIN32)
537# define UA_FLOAT_IEEE754 1
538#elif defined(__i386__) || defined(__x86_64__) || defined(__amd64__) || \
539 defined(__ia64__) || defined(__powerpc__) || defined(__sparc__) || \
540 defined(__arm__)
541# define UA_FLOAT_IEEE754 1
542#elif defined(__STDC_IEC_559__)
543# define UA_FLOAT_IEEE754 1
544#elif defined(ESP_PLATFORM)
545# define UA_FLOAT_IEEE754 1
546#else
547# define UA_FLOAT_IEEE754 0
548#endif
549#endif
550
551/** Wikipedia says (https://en.wikipedia.org/wiki/Endianness): Although the
552 * ubiquitous x86 processors of today use little-endian storage for all types of
553 * data (integer, floating point, BCD), there are a number of hardware
554 * architectures where floating-point numbers are represented in big-endian form
555 * while integers are represented in little-endian form. */
556#if defined(_WIN32)
557# define UA_FLOAT_LITTLE_ENDIAN 1
558#elif defined(__i386__) || defined(__x86_64__) || defined(__amd64__)
559# define UA_FLOAT_LITTLE_ENDIAN 1
560#elif defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
561 (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__) /* Defined only in GCC */
562# define UA_FLOAT_LITTLE_ENDIAN 1
563#elif defined(__FLOAT_WORD_ORDER) && defined(__LITTLE_ENDIAN) && \
564 (__FLOAT_WORD_ORDER == __LITTLE_ENDIAN) /* Defined only in GCC */
565# define UA_FLOAT_LITTLE_ENDIAN 1
566#endif
567#ifndef UA_FLOAT_LITTLE_ENDIAN
568# define UA_FLOAT_LITTLE_ENDIAN 0
569#endif
570
571/** Only if the floating points are litle-endian **and** in IEEE 754 format can
572 * we memcpy directly onto the network buffer. */
573#if (UA_FLOAT_IEEE754 == 1) && (UA_FLOAT_LITTLE_ENDIAN == 1)
574# define UA_BINARY_OVERLAYABLE_FLOAT 1
575#else
576# define UA_BINARY_OVERLAYABLE_FLOAT 0
577#endif
578
579#endif /* UA_CONFIG_H_ */
#define UA_assert(ignore)
Definition config.h:272
#define UA_STATIC_ASSERT(cond, msg)
Outputs an error message at compile time if the assert fails.
Definition config.h:296
#define UA_THREAD_LOCAL
Definition config.h:181
int mutexCounter
Definition config.h:351
pthread_mutex_t mutex
Definition config.h:350