/
nms_common.h
1364 lines (1129 loc) · 32.1 KB
/
nms_common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
** NetXMS - Network Management System
** Copyright (C) 2003-2024 Victor Kirhenshtein
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
** the Free Software Foundation; either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**
** File: nms_common.h
**
**/
#ifndef _nms_common_h_
#define _nms_common_h_
#ifdef WIN32
#ifndef _WIN32
#define _WIN32
#endif
#endif
#if !defined(_WIN32)
#include <config.h>
#if defined(WITH_OPENSSL)
#define _WITH_ENCRYPTION 1
#endif
#else /* _WIN32 */
#define _WITH_ENCRYPTION 1
#if !defined(WINDOWS_ONLY) && !defined(_CRT_SECURE_NO_DEPRECATE)
#define _CRT_SECURE_NO_DEPRECATE
#endif
// Turn off C++ exceptions use in standard header files
#ifndef _HAS_EXCEPTIONS
#define _HAS_EXCEPTIONS 0
#endif
// prevent defining min and max macros in Windows headers
#ifndef NOMINMAX
#define NOMINMAX
#endif
// prevent defining ETIMEDOUT, ECONNRESET, etc. to wrong values
#ifndef ALLOW_CRT_POSIX_ERROR_CODES
#define _CRT_NO_POSIX_ERROR_CODES
#endif
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#endif /* _WIN32 */
#if HAVE_JEMALLOC_JEMALLOC_H
#include <jemalloc/jemalloc.h>
#endif
#ifdef HAVE_STDARG_H
#include <stdarg.h>
#endif
#include <unicode.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <assert.h>
#if HAVE_WIDEC_H
#include <widec.h>
#endif /* HAVE_WIDEC */
#include <symbol_visibility.h>
/******* export attribute for libnetxms symbols *******/
#ifdef LIBNETXMS_EXPORTS
#define LIBNETXMS_EXPORTABLE __EXPORT
#define LIBNETXMS_EXPORTABLE_VAR(v) __EXPORT_VAR(v)
#else
#define LIBNETXMS_EXPORTABLE __IMPORT
#define LIBNETXMS_EXPORTABLE_VAR(v) __IMPORT_VAR(v)
#endif
#ifdef LIBNETXMS_TEMPLATE_EXPORTS
#define LIBNETXMS_TEMPLATE_EXPORTABLE __EXPORT
#else
#define LIBNETXMS_TEMPLATE_EXPORTABLE __IMPORT
#endif
/**
* Define __64BIT__ if compiling for 64bit platform with Visual C++
*/
#if defined(_M_X64) || defined(_M_IA64) || defined(__LP64__) || defined(__PPC64__) || defined(__x86_64__)
#ifndef __64BIT__
#define __64BIT__
#endif
#endif
/**
* Common constants
*/
#define MAX_SECRET_LENGTH 89
#define MAX_DB_STRING 256
#define MAX_PARAM_NAME 256
#define MAX_CONFIG_VALUE 2000
#define MAX_COLUMN_NAME 64
#define MAX_DNS_NAME 256
#define MAX_HELPDESK_REF_LEN 64
#define MAX_PASSWORD 256
#define GROUP_FLAG ((uint32_t)0x40000000)
#define NETXMS_MAX_CIPHERS 6
#define NETXMS_RSA_KEYLEN 4096
#define INVALID_INDEX 0xFFFFFFFF
#define MD4_DIGEST_SIZE 16
#define MD5_DIGEST_SIZE 16
#define SHA1_DIGEST_SIZE 20
#define SHA224_DIGEST_SIZE 28
#define SHA256_DIGEST_SIZE 32
#define SHA384_DIGEST_SIZE 48
#define SHA512_DIGEST_SIZE 64
#define FILE_BUFFER_SIZE ((size_t)32768)
/**
* Compatibility defines for C sources
*/
#if !defined(__cplusplus) && !defined(CORTEX) && !HAVE_BOOL
typedef int bool;
#endif
/**
* Oracle Pro*C compatibility
*/
#ifdef ORA_PROC
#undef BYTE
#undef DWORD
#endif
/**
* Java class path separator character
*/
#ifdef _WIN32
#define JAVA_CLASSPATH_SEPARATOR _T(';')
#else
#define JAVA_CLASSPATH_SEPARATOR _T(':')
#endif
/**
* Hint for zlib to use "const" qualifier
*/
#define ZLIB_CONST
/***** Platform dependent includes and defines *****/
#if defined(_WIN32)
/********** WINDOWS ********************/
#ifdef _MSC_FULL_VER
#define __BUILD_VERSION_STRING(s,v) s v
#define __STR_NX(x) #x
#define __STR(x) __STR_NX(x)
#define CPP_COMPILER_VERSION __STR(__BUILD_VERSION_STRING(Microsoft C/C++ Optimizing Compiler Version,_MSC_FULL_VER))
#endif
#define _Noreturn __declspec(noreturn)
#define CAN_DELETE_COPY_CTOR 1
#define HAVE_FINAL_SPECIFIER 1
#define HAVE_OVERRIDE_SPECIFIER 1
#define HAVE_THREAD_LOCAL_STORAGE 1
#define HAVE_STD_MAKE_UNIQUE 1
#define HAVE_DECL_CURL_URL 1
#define HAVE_DECL_CURLE_NOT_BUILT_IN 1
#define HAVE_DECL_CURLE_UNKNOWN_OPTION 1
#define HAVE_DECL_CURLOPT_RESOLVE 1
#define HAVE_DECL_CURLOPT_XOAUTH2_BEARER 1
#define VA_LIST_IS_POINTER 1
// Disable some warnings:
// 4293 - 'function xxx' not available as intrinsic function
// 4530 - C++ exception handler used, but unwind semantics are not enabled
// 4577 - 'noexcept' used with no exception handling mode specified
#pragma warning(disable: 4293)
#pragma warning(disable: 4530)
#pragma warning(disable: 4577)
// Set API version to Windows 7
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0601
#endif
/**
* Epoch offset for FILETIME structure
*/
#define EPOCHFILETIME (116444736000000000i64)
#define WITH_IPV6 1
#define WITH_PYTHON 1
#define WITH_MICROHTTPD 1
#define WITH_OPENSSL 1
#define WITH_LDAP 1
#define WITH_LIBISOTREE 1
#define WITH_MODBUS 1
#define HAVE_MODBUS_H 1
#define USE_BUNDLED_LIBTRE 1
#define USE_BUNDLED_GETOPT 1
#define SAFE_FGETWS_WITH_POPEN 1
#define FREE_IS_NULL_SAFE 1
#define FS_PATH_SEPARATOR _T("\\")
#define FS_PATH_SEPARATOR_A "\\"
#define FS_PATH_SEPARATOR_W L"\\"
#define FS_PATH_SEPARATOR_CHAR _T('\\')
#define FS_PATH_SEPARATOR_CHAR_A '\\'
#define FS_PATH_SEPARATOR_CHAR_W L'\\'
#define EXECUTABLE_FILE_SUFFIX _T(".exe")
#define WEXITSTATUS(x) (x)
#if _MSC_VER >= 1310
#define HAVE_SCPRINTF 1
#define HAVE_VSCPRINTF 1
#define HAVE_SCWPRINTF 1
#define HAVE_VSCWPRINTF 1
#endif
#if _MSC_VER >= 1800
#define HAVE_STRTOLL 1
#define HAVE_STRTOULL 1
#define HAVE_WCSTOLL 1
#define HAVE_WCSTOULL 1
#endif
#define HAVE_TOUPPER 1
#define HAVE_TOWUPPER 1
#define HAVE_TOLOWER 1
#define HAVE_TOWLOWER 1
#define HAVE_SNPRINTF 1
#define HAVE_VSNPRINTF 1
#define HAVE_GETADDRINFO 1
#define HAVE_STDARG_H 1
#define HAVE_ALLOCA 1
#define HAVE_WCSLEN 1
#define HAVE_WCSNCPY 1
#define HAVE_WCSDUP 1
#define HAVE_WUTIME 1
#define HAVE_STD_ATOMIC 1
#define HAVE_LIBCURL 1
#define HAVE_LIBJQ 1
#define HAVE_DIRENT_D_TYPE 1
#define HAVE_MOSQUITTO_THREADED_SET 1
#define HAVE_X509_STORE_SET_VERIFY_CB 1
#define HAVE_X509_STORE_CTX_SET_VERIFY_CB 1
#include <winsock2.h>
#include <windows.h>
#include <ws2tcpip.h>
#include <stdlib.h>
#include <malloc.h>
#include <stdarg.h>
#ifndef va_copy
#define va_copy(x,y) (x = y)
#endif
#define HAVE_DECL_VA_COPY 1
#include <sys/stat.h>
#include <sys/utime.h>
#include <process.h>
#include <io.h>
#include <fcntl.h>
#include <direct.h>
#ifndef S_IRUSR
#define S_IRUSR _S_IREAD
#endif
#ifndef S_IWUSR
#define S_IWUSR _S_IWRITE
#endif
#ifndef S_IRGRP
#define S_IRGRP _S_IREAD
#endif
#ifndef S_IWGRP
#define S_IWGRP _S_IWRITE
#endif
#ifndef S_IROTH
#define S_IROTH _S_IREAD
#endif
#ifndef S_IWOTH
#define S_IWOTH _S_IWRITE
#endif
/* Mode flags for _access() */
#define F_OK 0
#define R_OK 4
#define W_OK 2
#define X_OK R_OK /* on Windows execute is granted if read is granted */
#define STDIN_FILENO _fileno(stdin)
#define STDOUT_FILENO _fileno(stdout)
#define STDERR_FILENO _fileno(stderr)
#define snprintf _snprintf
#define vsnprintf _vsnprintf
#define snwprintf _snwprintf
#define vsnwprintf _vsnwprintf
#define scprintf _scprintf
#define vscprintf _vscprintf
#define scwprintf _scwprintf
#define vscwprintf _vscwprintf
#define stricmp _stricmp
#define strnicmp _strnicmp
#define wcsicmp _wcsicmp
#define wcsnicmp _wcsnicmp
#define strlwr(s) _strlwr(s)
#define strupr(s) _strupr(s)
typedef UINT64 QWORD; // for compatibility
typedef int socklen_t;
typedef long pid_t;
#ifdef _WIN64
typedef __int64 ssize_t;
#define CAN_OVERLOAD_SSIZE_T 1
#else
typedef __int32 ssize_t;
#define CAN_OVERLOAD_SSIZE_T 0
#endif
typedef __int64 off64_t;
typedef signed __int8 int8_t;
typedef signed __int16 int16_t;
typedef signed __int32 int32_t;
typedef signed __int64 int64_t;
typedef unsigned __int8 uint8_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int32 uint32_t;
typedef unsigned __int64 uint64_t;
#define INT64_FMT _T("%I64d")
#define INT64_FMTA "%I64d"
#define INT64_FMTW L"%I64d"
#define UINT64_FMT _T("%I64u")
#define UINT64_FMTA "%I64u"
#define UINT64_FMTW L"%I64u"
#define UINT64_FMT_ARGS(m) _T("%") m _T("I64u")
#define UINT64X_FMT(m) _T("%") m _T("I64X")
#if defined(__64BIT__) || (_MSC_VER > 1300)
#define TIME_T_FMT _T("%I64u")
#define TIME_T_FCAST(x) ((UINT64)(x))
#else
#define TIME_T_FMT _T("%u")
#define TIME_T_FCAST(x) ((UINT32)(x))
#endif
#ifndef __clang__
#define HAVE_DECL_BSWAP_16 1
#define HAVE_DECL_BSWAP_32 1
#define HAVE_DECL_BSWAP_64 1
#define bswap_16(n) _byteswap_ushort(n)
#define bswap_32(n) _byteswap_ulong(n)
#define bswap_64(n) _byteswap_uint64(n)
#endif
#define HAVE_LIBEXPAT 1
#define XMPP_SUPPORTED 1
#define HAVE_LOCALE_H 1
#define HAVE_SETLOCALE 1
#define SHLIB_SUFFIX _T(".dll")
#ifdef __cplusplus
/**
* Get UNIX time from Windows file time represented as 64 bit integer
*/
static inline time_t FileTimeToUnixTime(uint64_t ft)
{
return (ft > 0) ? static_cast<time_t>((ft - EPOCHFILETIME) / 10000000) : 0;
}
/**
* Get UNIX time from Windows file time represented as LARGE_INTEGER structure
*/
static inline time_t FileTimeToUnixTime(LARGE_INTEGER li)
{
return (li.QuadPart > 0) ? static_cast<time_t>((li.QuadPart - EPOCHFILETIME) / 10000000) : 0;
}
/**
* Get UNIX time from Windows file time represented as FILETIME structure
*/
static inline time_t FileTimeToUnixTime(const FILETIME &ft)
{
LARGE_INTEGER li;
li.LowPart = ft.dwLowDateTime;
li.HighPart = ft.dwHighDateTime;
return (li.QuadPart > 0) ? static_cast<time_t>((li.QuadPart - EPOCHFILETIME) / 10000000) : 0;
}
#endif
#else /* not _WIN32 */
/*********** UNIX *********************/
#ifndef PREFIX
#ifdef UNICODE
#define PREFIX L"/usr/local"
#else
#define PREFIX "/usr/local"
#endif
#warning Installation prefix not defined, defaulting to /usr/local
#endif
#ifndef SYSCONFDIR
#ifdef UNICODE
#define SYSCONFDIR PREFIX L"/etc"
#else
#define SYSCONFDIR PREFIX "/etc"
#endif
#warning SYSCONFDIR not defined, defaulting to $prefix/etc
#endif
#if HAVE_THREAD_LOCAL_SPECIFIER
#define HAVE_THREAD_LOCAL_STORAGE 1
#elif HAVE_THREAD_SPECIFIER
#define thread_local __thread
#define HAVE_THREAD_LOCAL_STORAGE 1
#else
#define thread_local
#define HAVE_THREAD_LOCAL_STORAGE 0
#endif
/* Minix defines BYTE in const.h - include it early and undef */
#ifdef __minix
#include <minix/const.h>
#undef BYTE
#endif
#if HAVE_STDBOOL_H
#include <stdbool.h>
#endif
#if HAVE_ALLOCA_H
#include <alloca.h>
#endif
#if HAVE_WCHAR_H
#include <wchar.h>
#endif
#if HAVE_WCTYPE_H
#include <wctype.h>
#endif
// Fix for wcs* functions visibility in Solaris 11
#if defined(__sun) && (__cplusplus >= 199711L) && (__SUNPRO_CC < 0x5150)
#if HAVE_WCSDUP
using std::wcsdup;
#endif
#if HAVE_WCSCASECMP
using std::wcscasecmp;
#endif
#if HAVE_WCSNCASECMP
using std::wcsncasecmp;
#endif
#endif
#include <errno.h>
#define FS_PATH_SEPARATOR _T("/")
#define FS_PATH_SEPARATOR_A "/"
#define FS_PATH_SEPARATOR_W L"/"
#define FS_PATH_SEPARATOR_CHAR _T('/')
#define FS_PATH_SEPARATOR_CHAR_A '/'
#define FS_PATH_SEPARATOR_CHAR_W L'/'
#define EXECUTABLE_FILE_SUFFIX
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#if HAVE_STDLIB_H
#include <stdlib.h>
#endif
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#if HAVE_STDINT_H
#include <stdint.h>
#endif
#if HAVE_UTIME_H
#include <utime.h>
#endif
#if HAVE_SYS_INT_TYPES_H
#include <sys/int_types.h>
#endif
#if HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#if HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#if HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif
#if HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#if HAVE_NETINET_TCP_H
#include <netinet/tcp.h>
#endif
#if HAVE_NET_NH_H
#include <net/nh.h>
#endif
#if HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
#if HAVE_NETDB_H
#include <netdb.h>
#endif
#if HAVE_FCNTL_H
#include <fcntl.h>
#endif
#include <dirent.h>
#if _USE_GNU_PTH
#include <pth.h>
#else
#include <pthread.h>
#endif
#ifdef __IBMCPP__
#include <builtins.h>
#endif
#ifdef __minix
#undef HAVE_GETHOSTBYNAME2_R
#endif
#include <sys/socket.h>
#include <sys/un.h>
#if !HAVE_INT64_T || !HAVE_UINT64_T
#if !HAVE_INT64_T
#if HAVE_LONG_LONG && (SIZEOF_LONG_LONG == 8)
typedef long long int64_t;
#elif SIZEOF_LONG == 8
typedef long int64_t;
#else
#error Target system does not have signed 64bit integer type
#endif
#endif
#if !HAVE_UINT64_T
#if HAVE_UNSIGNED_LONG_LONG && (SIZEOF_LONG_LONG == 8)
typedef unsigned long long uint64_t;
#elif HAVE_U_INT64_T
typedef u_int64_t uint64_t;
#elif SIZEOF_LONG == 8
typedef unsigned long uint64_t;
#else
#error Target system does not have unsigned 64bit integer type
#endif
#endif
#endif
#if (SIZEOF_LONG == 4)
#if (SIZEOF_INT == 4)
#if !HAVE_INT32_T
typedef int int32_t;
#endif
#if !HAVE_UINT32_T
typedef unsigned int uint32_t;
#endif
#else
#if !HAVE_INT32_T
typedef long int32_t;
#endif
#if !HAVE_UINT32_T
typedef unsigned long uint32_t;
#endif
#endif
#undef __64BIT__
#else
#if !HAVE_INT32_T
typedef int int32_t;
#endif
#if !HAVE_UINT32_T
typedef unsigned int uint32_t;
#endif
#ifndef __64BIT__
#define __64BIT__
#endif
#endif
#if !HAVE_INT16_T
typedef short int16_t;
#endif
#if !HAVE_UINT16_T
typedef unsigned short uint16_t;
#endif
#if !HAVE_INT8_T
typedef char int8_t;
#endif
#if !HAVE_UINT8_T
typedef unsigned char uint8_t;
#endif
#if !HAVE_INTPTR_T
#if SIZEOF_VOIDP == 8
typedef int64_t intptr_t;
#else
typedef int32_t intptr_t;
#endif
#endif
#if !HAVE_UINTPTR_T
#if SIZEOF_VOIDP == 8
typedef uint64_t uintptr_t;
#else
typedef uint32_t uintptr_t;
#endif
#endif
#if !HAVE_NULLPTR
#define nullptr NULL
#endif
/* Deprectaed compatibility types - to be removed */
typedef uint8_t BYTE;
typedef int16_t INT16;
typedef uint16_t UINT16;
typedef uint16_t WORD;
typedef int32_t INT32;
typedef int32_t LONG;
typedef uint32_t UINT32;
typedef uint32_t DWORD;
typedef int64_t INT64;
typedef uint64_t UINT64;
typedef uint64_t QWORD;
typedef void * HANDLE;
typedef void * HINSTANCE;
typedef void * HMODULE;
#if !HAVE_MODE_T
typedef int mode_t;
#endif
#if !HAVE_OFF64_T
typedef int64_t off64_t;
#endif
#if defined(PRId64)
#define INT64_FMT _T("%") PRId64
#define INT64_FMTW L"%" PRId64
#define INT64_FMTA "%" PRId64
#elif SIZEOF_LONG == 8
#define INT64_FMT _T("%ld")
#define INT64_FMTW L"%ld"
#define INT64_FMTA "%ld"
#else
#define INT64_FMT _T("%lld")
#define INT64_FMTW L"%lld"
#define INT64_FMTA "%lld"
#endif
#if defined(PRIu64)
#define UINT64_FMT _T("%") PRIu64
#define UINT64_FMTW L"%" PRIu64
#define UINT64_FMTA "%" PRIu64
#define UINT64_FMT_ARGS(m) _T("%") m PRIu64
#elif SIZEOF_LONG == 8
#define UINT64_FMT _T("%lu")
#define UINT64_FMTW L"%lu"
#define UINT64_FMTA "%lu"
#define UINT64_FMT_ARGS(m) _T("%") m _T("lu")
#else
#define UINT64_FMT _T("%llu")
#define UINT64_FMTW L"%llu"
#define UINT64_FMTA "%llu"
#define UINT64_FMT_ARGS(m) _T("%") m _T("llu")
#endif
#if defined(PRIX64)
#define UINT64X_FMT(m) _T("%") m PRIX64
#elif SIZEOF_LONG == 8
#define UINT64X_FMT(m) _T("%") m _T("lX")
#else
#define UINT64X_FMT(m) _T("%") m _T("llX")
#endif
#ifdef __64BIT__
#define TIME_T_FMT UINT64_FMT
#define TIME_T_FCAST(x) ((uint64_t)(x))
#else
#define TIME_T_FMT _T("%u")
#define TIME_T_FCAST(x) ((uint32_t)(x))
#endif
typedef int BOOL;
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
// on AIX open_memstream only declared if _XOPEN_SOURCE >= 700
// which is incompatible with other parts of code
#ifdef _AIX
#ifdef __cplusplus
extern "C"
#endif
FILE *open_memstream(char **, size_t *);
#endif
// Some systems may define true and false which may break overloaded functions
#ifdef __cplusplus
#undef true
#undef false
#endif
#ifndef MAX_PATH
#ifdef PATH_MAX
#define MAX_PATH PATH_MAX
#else
#define MAX_PATH 1024
#endif
#endif
// Windows compatibility layer for standard C I/O functions
#ifdef __cplusplus
static inline int _access(const char *pathname, int mode) { return ::access(pathname, mode); }
static inline int _chdir(const char *path) { return ::chdir(path); }
static inline int _close(int fd) { return ::close(fd); }
static inline int _fileno(FILE *stream) { return fileno(stream); }
static inline char *_getcwd(char *buffer, size_t size) { return ::getcwd(buffer, size); }
static inline int _isatty(int fd) { return ::isatty(fd); }
static inline off_t _lseek(int fd, off_t offset, int whence) { return ::lseek(fd, offset, whence); }
static inline off_t _tell(int fd) { return ::lseek(fd, 0, SEEK_CUR); }
static inline int _mkdir(const char *pathname, mode_t mode) { return ::mkdir(pathname, mode); }
static inline int _open(const char *pathname, int flags) { return ::open(pathname, flags); }
static inline int _open(const char *pathname, int flags, mode_t mode) { return ::open(pathname, flags, mode); }
static inline int _pclose(FILE *stream) { return ::pclose(stream); }
static inline FILE *_popen(const char *command, const char *type) { return ::popen(command, type); }
static inline int _putenv(char *string) { return ::putenv(string); }
static inline ssize_t _read(int fd, void *buf, size_t count) { return ::read(fd, buf, count); }
static inline int _remove(const char *pathname) { return ::remove(pathname); }
static inline char *_strdup(const char *s) { return ::strdup(s); }
static inline int _unlink(const char *pathname) { return ::unlink(pathname); }
static inline ssize_t _write(int fd, const void *buf, size_t count) { return ::write(fd, buf, count); }
#else
#define _access(p, m) access((p), (m))
#define _chdir(p) chdir(p)
#define _close(f) close(f)
#define _fileno(f) fileno(f)
#define _getcwd(b, s) getcwd((b), (s))
#define _isatty(f) isatty(f)
#define _lseek(f, o, w) lseek((f), (o) ,(w))
#define _tell(f) lseek((f), 0, SEEK_CUR)
#define _mkdir(p, m) mkdir((p), (m))
#define _open open
#define _pclose(f) pclose(f)
#define _popen(c, m) popen((c), (m))
#define _putenv(s) putenv(s)
#define _read(f, b, l) read((f), (b), (l))
#define _remove(f) remove(f)
#define _unlink(f) unlink(f)
#define _write(f, b, l) write((f), (b), (l))
#endif
// SecureZeroMemory for non-Windows platforms
#if HAVE_DECL_EXPLICIT_BZERO
#define SecureZeroMemory explicit_bzero
#elif HAVE_DECL_MEMSET_S
#ifdef __cplusplus
static inline void SecureZeroMemory(void *mem, size_t count)
{
memset_s(mem, count, 0, count);
}
#else
#define SecureZeroMemory(m,c) memset_s((m),(c),0,(c))
#endif
#else
#define IMPLEMENT_SECURE_ZERO_MEMORY
void LIBNETXMS_EXPORTABLE SecureZeroMemory(void *mem, size_t count);
#endif
// Shared library suffix
#ifndef SHLIB_SUFFIX
#define SHLIB_SUFFIX _T(".so")
#endif
typedef struct hostent HOSTENT;
#if HAVE_DECL___VA_COPY && !HAVE_DECL_VA_COPY
#define HAVE_DECL_VA_COPY 1
#define va_copy(d,s) __va_copy(d,s)
#endif
#endif /* _WIN32 */
/**
* Macros for marking deprecated functions
*/
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
#define NETXMS_DEPRECATED(note) __attribute__((deprecated(note)))
#else
#define NETXMS_DEPRECATED(note)
#endif
/**
* Wrappers for 64-bit integer constants
*/
#if defined(__GNUC__) || defined(__HP_aCC) || defined(__IBMC__) || defined(__IBMCPP__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
#ifdef INT64_C
#define _LL(x) INT64_C(x)
#else
#define _LL(x) (x ## LL)
#endif
#ifdef UINT64_C
#define _ULL(x) UINT64_C(x)
#else
#define _ULL(x) (x ## ULL)
#endif
#elif defined(_MSC_VER)
#define _LL(x) (x ## i64)
#define _ULL(x) (x ## ui64)
#else
#define _LL(x) (x)
#define _ULL(x) (x)
#endif
#ifndef LLONG_MAX
#define LLONG_MAX _LL(9223372036854775807)
#endif
#ifndef LLONG_MIN
#define LLONG_MIN (-LLONG_MAX - 1)
#endif
#ifndef ULLONG_MAX
#define ULLONG_MAX _ULL(18446744073709551615)
#endif
/**
* Value used to indicate invalid pointer where NULL is not appropriate
*/
#ifdef __64BIT__
#define INVALID_POINTER_VALUE ((void *)_ULL(0xFFFFFFFFFFFFFFFF))
#else
#define INVALID_POINTER_VALUE ((void *)0xFFFFFFFF)
#endif
/**
* Casting between pointer and integer
*/
#define CAST_FROM_POINTER(p, t) ((t)((uintptr_t)(p)))
#define CAST_TO_POINTER(v, t) ((t)((uintptr_t)(v)))
/**
* Macros for defining bit masks
*/
#define MASK_BIT(n) static_cast<uint32_t>(1 << (n))
#define MASK_BIT64(n) static_cast<uint64_t>(_ULL(1) << (n))
/**
* open() flags compatibility
*/
#ifndef O_BINARY
#define O_BINARY 0
#endif
/**
* Event log severity codes
*/
#ifdef _WIN32
#define EVENTLOG_DEBUG_TYPE 0x0080
#else
#define EVENTLOG_SUCCESS 0x0000
#define EVENTLOG_ERROR_TYPE 0x0001
#define EVENTLOG_WARNING_TYPE 0x0002
#define EVENTLOG_INFORMATION_TYPE 0x0004
#define EVENTLOG_AUDIT_SUCCESS 0x0008
#define EVENTLOG_AUDIT_FAILURE 0x0010
#define EVENTLOG_DEBUG_TYPE 0x0080
#endif /* _WIN32 */
#define NXLOG_DEBUG EVENTLOG_DEBUG_TYPE
#define NXLOG_INFO EVENTLOG_INFORMATION_TYPE
#define NXLOG_WARNING EVENTLOG_WARNING_TYPE
#define NXLOG_ERROR EVENTLOG_ERROR_TYPE
/**
* INADDR_NONE can be undefined on some systems
*/
#ifndef INADDR_NONE
#define INADDR_NONE (0xFFFFFFFF)
#endif
/**
* Check if given string is NULL and always return valid pointer
*/
#ifdef __cplusplus
static inline const TCHAR *CHECK_NULL(const TCHAR *x) { return (x == nullptr) ? _T("(null)") : x; }
static inline const char *CHECK_NULL_A(const char *x) { return (x == nullptr) ? "(null)" : x; }
static inline const WCHAR *CHECK_NULL_W(const WCHAR *x) { return (x == nullptr) ? L"(null)" : x; }
static inline const TCHAR *CHECK_NULL_EX(const TCHAR *x) { return (x == nullptr) ? _T("") : x; }
static inline const char *CHECK_NULL_EX_A(const char *x) { return (x == nullptr) ? "" : x; }
static inline const WCHAR *CHECK_NULL_EX_W(const WCHAR *x) { return (x == nullptr) ? L"" : x; }
#else
#define CHECK_NULL(x) ((x) == NULL ? _T("(null)") : (x))
#define CHECK_NULL_A(x) ((x) == NULL ? "(null)" : (x))
#define CHECK_NULL_W(x) ((x) == NULL ? L"(null)" : (x))
#define CHECK_NULL_EX(x) ((x) == NULL ? _T("") : (x))
#define CHECK_NULL_EX_A(x) ((x) == NULL ? "" : (x))
#define CHECK_NULL_EX_W(x) ((x) == NULL ? L"" : (x))
#endif
/***** Common C++ includes *****/
#ifdef __cplusplus
#if defined(__IBMCPP_TR1__)
#include <memory>
using std::tr1::shared_ptr;
using std::tr1::weak_ptr;
using std::tr1::static_pointer_cast;
using std::tr1::enable_shared_from_this;
// xlC++ implementation C++11 TR1 does not have make_shared
template<typename T, typename... Args>