fixed Windows build errors
[public/netxms.git] / include / nms_common.h
1 /*
2 ** NetXMS - Network Management System
3 ** Copyright (C) 2003-2014 Victor Kirhenshtein
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU Lesser General Public License as published by
7 ** the Free Software Foundation; either version 3 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU Lesser General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 **
19 ** File: nms_common.h
20 **
21 **/
22
23 #ifndef _nms_common_h_
24 #define _nms_common_h_
25
26 #ifdef WIN32
27 #ifndef _WIN32
28 #define _WIN32
29 #endif
30 #endif
31
32 #ifdef __SYMBIAN32__
33
34 // Symbian compiler defines _WIN32 in builds for emulator.
35 #undef _WIN32
36
37 #else
38
39 #if !defined(_WIN32) && !defined(UNDER_CE)
40
41 #ifdef _NETWARE
42 #include <config-netware.h>
43 #else
44 #include <config.h>
45 #ifdef WITH_OPENSSL
46 #define _WITH_ENCRYPTION 1
47 #endif
48 #endif
49
50 #else /* _WIN32 */
51
52 #ifndef UNDER_CE
53 #define _WITH_ENCRYPTION 1
54 #define WITH_LDAP 1
55 #if !defined(WINDOWS_ONLY) && !defined(_CRT_SECURE_NO_DEPRECATE)
56 #define _CRT_SECURE_NO_DEPRECATE
57 #endif
58 #endif
59
60 #endif
61
62 #endif /* __SYMBIAN32__ */
63
64 #if HAVE_JEMALLOC_JEMALLOC_H
65 #include <jemalloc/jemalloc.h>
66 #endif
67
68 #ifdef HAVE_STDARG_H
69 #include <stdarg.h>
70 #endif
71
72 #include <unicode.h>
73
74 #include <stdio.h>
75 #include <string.h>
76 #include <limits.h>
77
78 #include <netxms-version.h>
79
80 #if HAVE_WIDEC_H
81 #include <widec.h>
82 #endif // HAVE_WIDEC
83
84 /**
85 * Define __64BIT__ if compiling for 64bit platform with Visual C++
86 */
87 #if defined(_M_X64) || defined(_M_IA64) || defined(__LP64__) || defined(__PPC64__) || defined(__x86_64__)
88 #ifndef __64BIT__
89 #define __64BIT__
90 #endif
91 #endif
92
93 /**
94 * Wrappers for 64-bit integer constants
95 */
96 #if defined(__GNUC__) || defined(__HP_aCC) || defined(__IBMC__) || defined(__IBMCPP__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
97 #define _LL(x) (x ## LL)
98 #define _ULL(x) (x ## ULL)
99 #elif defined(_MSC_VER)
100 #define _LL(x) (x ## i64)
101 #define _ULL(x) (x ## ui64)
102 #else
103 #define _LL(x) (x)
104 #define _ULL(x) (x)
105 #endif
106
107 /**
108 * Common constants
109 */
110 #define MAX_SECRET_LENGTH 64
111 #define MAX_DB_STRING 256
112 #define MAX_PARAM_NAME 256
113 #define MAX_CONFIG_VALUE 2000
114 #define MAX_COLUMN_NAME 64
115 #define MAX_DNS_NAME 256
116 #define MAX_HELPDESK_REF_LEN 64
117 #define MAX_PASSWORD 256
118 #define MAX_SSH_LOGIN_LEN 64
119 #define MAX_SSH_PASSWORD_LEN 64
120 #define GROUP_FLAG ((UINT32)0x80000000)
121
122 #define NETXMS_MAX_CIPHERS 6
123 #define NETXMS_RSA_KEYLEN 2048
124
125 #ifndef LLONG_MAX
126 #define LLONG_MAX _LL(9223372036854775807)
127 #endif
128
129 #ifndef LLONG_MIN
130 #define LLONG_MIN (-LLONG_MAX - 1)
131 #endif
132
133 #ifndef ULLONG_MAX
134 #define ULLONG_MAX _ULL(18446744073709551615)
135 #endif
136
137 #ifndef EVENTLOG_DEBUG_TYPE
138 #define EVENTLOG_DEBUG_TYPE 0x0080
139 #endif
140
141 #define INVALID_INDEX 0xFFFFFFFF
142 #define MD5_DIGEST_SIZE 16
143 #define SHA1_DIGEST_SIZE 20
144 #define SHA256_DIGEST_SIZE 32
145
146 #define FILE_BUFFER_SIZE 32768
147
148 /**
149 * Compatibility defines for C sources
150 */
151 #if !defined(__cplusplus) && !defined(CORTEX)
152 typedef int bool;
153 #endif
154
155 /**
156 * Oracle Pro*C compatibility
157 */
158 #ifdef ORA_PROC
159 #undef BYTE
160 #undef DWORD
161 #endif
162
163
164 /***** Platform dependent includes and defines *****/
165
166 #if defined(_WIN32) || defined(UNDER_CE)
167
168 /********** WINDOWS ********************/
169
170 #ifndef _WIN32_WINNT
171 #define _WIN32_WINNT 0x0501
172 #endif
173
174 #define WITH_IPV6 1
175
176 #define USE_BUNDLED_LIBTRE 1
177 #define USE_BUNDLED_GETOPT 1
178
179 #define SAFE_FGETWS_WITH_POPEN 1
180
181 #define FS_PATH_SEPARATOR _T("\\")
182 #define FS_PATH_SEPARATOR_A "\\"
183 #define FS_PATH_SEPARATOR_W L"\\"
184 #define FS_PATH_SEPARATOR_CHAR _T('\\')
185
186 #define WEXITSTATUS(x) (x)
187
188 #if _MSC_VER > 1300
189 #define HAVE_SCPRINTF 1
190 #define HAVE_VSCPRINTF 1
191 #define HAVE_SCWPRINTF 1
192 #define HAVE_VSCWPRINTF 1
193 #endif
194
195 #define HAVE_SNPRINTF 1
196 #define HAVE_VSNPRINTF 1
197
198 #define HAVE_GETADDRINFO 1
199
200 #define HAVE_STDARG_H 1
201
202 #define HAVE_ALLOCA 1
203
204 #define HAVE_WCSLEN 1
205 #define HAVE_WCSNCPY 1
206 #define HAVE_WCSDUP 1
207
208 #ifndef va_copy
209 #define va_copy(x,y) (x = y)
210 #endif
211 #define HAVE_DECL_VA_COPY 1
212
213 #define HAVE_LIBCURL 1
214
215 #include <winsock2.h>
216 #include <windows.h>
217 #include <ws2tcpip.h>
218 #include <stdlib.h>
219 #include <malloc.h>
220
221 #ifndef UNDER_CE
222 #include <sys/stat.h>
223 #include <process.h>
224 #include <io.h>
225 #include <fcntl.h>
226 #include <direct.h>
227 #endif
228
229 #ifndef S_IRUSR
230 # define S_IRUSR 0400
231 #endif
232 #ifndef S_IWUSR
233 # define S_IWUSR 0200
234 #endif
235
236 #define snprintf _snprintf
237 #define vsnprintf _vsnprintf
238 #define snwprintf _snwprintf
239 #define vsnwprintf _vsnwprintf
240 #define scprintf _scprintf
241 #define vscprintf _vscprintf
242 #define scwprintf _scwprintf
243 #define vscwprintf _vscwprintf
244 #define popen _popen
245 #define pclose _pclose
246 #define stricmp _stricmp
247 #define strnicmp _strnicmp
248 #define strupr(s) _strupr(s)
249 #define getpid _getpid
250 #define fileno(f) _fileno(f)
251 #define chdir(p) _chdir(p)
252 #define mkdir(p,m) _mkdir(p,m)
253 #define lseek(f,o,w) _lseek(f,o,w)
254 #define unlink(x) _unlink(x)
255
256 typedef UINT64 QWORD; // for compatibility
257 typedef int socklen_t;
258 typedef long pid_t;
259 typedef LONG ssize_t;
260
261 typedef signed __int8 int8_t;
262 typedef signed __int16 int16_t;
263 typedef signed __int32 int32_t;
264 typedef signed __int64 int64_t;
265 typedef unsigned __int8 uint8_t;
266 typedef unsigned __int16 uint16_t;
267 typedef unsigned __int32 uint32_t;
268 typedef unsigned __int64 uint64_t;
269
270 #define INT64_FMT _T("%I64d")
271 #define INT64_FMTA "%I64d"
272 #define INT64_FMTW L"%I64d"
273 #define UINT64_FMT _T("%I64u")
274 #define UINT64_FMTA "%I64u"
275 #define UINT64_FMTW L"%I64u"
276 #define UINT64X_FMT(m) _T("%") m _T("I64X")
277 #if defined(__64BIT__) || (_MSC_VER > 1300)
278 #define TIME_T_FMT _T("%I64u")
279 #define TIME_T_FCAST(x) ((UINT64)(x))
280 #else
281 #define TIME_T_FMT _T("%u")
282 #define TIME_T_FCAST(x) ((UINT32)(x))
283 #endif
284
285 // Socket compatibility
286 #define SHUT_RD 0
287 #define SHUT_WR 1
288 #define SHUT_RDWR 2
289
290 #define SetSocketReuseFlag(s) { \
291 BOOL val = TRUE; \
292 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(BOOL)); \
293 }
294 #define SetSocketExclusiveAddrUse(s) { \
295 BOOL val = TRUE; \
296 setsockopt(s, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (char *)&val, sizeof(BOOL)); \
297 }
298 #define SELECT_NFDS(x) ((int)(x))
299 #define SetSocketNonBlocking(s) { \
300 u_long one = 1; \
301 ioctlsocket(s, FIONBIO, &one); \
302 }
303 #define SetSocketBlocking(s) { \
304 u_long zero = 0; \
305 ioctlsocket(s, FIONBIO, &zero); \
306 }
307 #define SetSocketNoDelay(s) { \
308 BOOL val = TRUE; \
309 setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(BOOL)); \
310 }
311 #define SetSocketBroadcast(s) { \
312 BOOL val = TRUE; \
313 setsockopt(s, SOL_SOCKET, SO_BROADCAST, (char *)&val, sizeof(BOOL)); \
314 }
315
316 #ifdef UNDER_CE
317 #define O_RDONLY 0x0004
318 #define O_WRONLY 0x0001
319 #define O_RDWR 0x0002
320 #define O_CREAT 0x0100
321 #define O_EXCL 0x0200
322 #define O_TRUNC 0x0800
323 #endif
324
325 #if !defined(UNDER_CE)
326 #define HAVE_LIBEXPAT 1
327 #endif
328
329 #define XMPP_SUPPORTED 1
330
331 #define HAVE_LOCALE_H 1
332 #define HAVE_SETLOCALE 1
333
334 // Use Win32 API instead of msvcrt for memory allocation
335 #ifdef USE_WIN32_HEAP
336
337 #define malloc(n) HeapAlloc(GetProcessHeap(), 0, n)
338 #define realloc(p, n) (((p) == NULL) ? HeapAlloc(GetProcessHeap(), 0, n) : HeapReAlloc(GetProcessHeap(), 0, p, n))
339 #define free(p) HeapFree(GetProcessHeap(), 0, p)
340 #define _tcsdup(s) nx__tcsdup(s)
341 #define wcsdup(s) nx_wcsdup(s)
342
343 #undef _tcsdup
344 #ifdef UNICODE
345 #define _tcsdup nx_wcsdup
346 #else
347 #define _tcsdup nx_strdup
348 #endif
349
350 #else
351
352 #define strdup _strdup
353 #define wcsdup _wcsdup
354
355 #endif
356
357 #elif defined(_NETWARE)
358
359 /********** NETWARE ********************/
360
361 #define FS_PATH_SEPARATOR _T("/")
362 #define FS_PATH_SEPARATOR_A "/"
363 #define FS_PATH_SEPARATOR_W L"/"
364 #define FS_PATH_SEPARATOR_CHAR _T('/')
365
366 #include <unistd.h>
367 #include <stdlib.h>
368 #include <sys/types.h>
369 #include <sys/stat.h>
370 #include <sys/socket.h>
371 #include <sys/select.h>
372 #include <netinet/in.h>
373 #include <netinet/tcp.h>
374 #include <arpa/inet.h>
375 #include <stdint.h>
376 #include <fcntl.h>
377 #include <errno.h>
378 #include <dirent.h>
379 #include <wchar.h>
380 #include <netdb.h>
381
382 typedef int BOOL;
383 #if (SIZEOF_LONG == 4)
384 typedef long INT32;
385 #else
386 typedef int INT32;
387 #endif
388 #if (SIZEOF_LONG == 4)
389 typedef unsigned long UINT32;
390 #else
391 typedef unsigned int UINT32;
392 #endif
393 typedef INT32 LONG;
394 typedef UINT32 DWORD;
395 typedef unsigned short UINT16;
396 typedef UINT16 WORD;
397 typedef unsigned char BYTE;
398 typedef void * HANDLE;
399 typedef void * HMODULE;
400
401 #ifdef X_INT64_X
402 typedef X_INT64_X INT64;
403 #else
404 #error Target system does not have signed 64bit integer type
405 #endif
406
407 #ifdef X_UINT64_X
408 typedef X_UINT64_X UINT64;
409 typedef UINT64 QWORD;
410 #else
411 #error Target system does not have unsigned 64bit integer type
412 #endif
413
414 #define INT64_FMT _T("%lld")
415 #define INT64_FMTW L"%lld"
416 #define INT64_FMTA "%lld"
417 #define UINT64_FMT _T("%llu")
418 #define UINT64_FMTW L"%llu"
419 #define UINT64_FMTA "%llu"
420 #define UINT64X_FMT(m) _T("%") m _T("llX")
421 #define TIME_T_FMT _T("%u")
422 #define TIME_T_FCAST(x) ((UINT32)(x))
423
424 #ifndef MAX_PATH
425 #define MAX_PATH 256
426 #endif
427
428 // Socket compatibility
429 typedef int SOCKET;
430
431 #define closesocket(x) close(x)
432 #define WSAGetLastError() (errno)
433
434 #define WSAEINTR EINTR
435 #define WSAEWOULDBLOCK EWOULDBLOCK
436 #define WSAEINPROGRESS EINPROGRESS
437 #define WSAESHUTDOWN ESHUTDOWN
438 #define INVALID_SOCKET (-1)
439
440 #define SetSocketReuseFlag(sd) { \
441 int nVal = 1; \
442 setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, (const void *)&nVal, \
443 (socklen_t)sizeof(nVal)); \
444 }
445
446 #define SetSocketExclusiveAddrUse(s)
447
448 #define SetSocketNonBlocking(s) { \
449 int f = fcntl(s, F_GETFL); \
450 if (f != -1) fcntl(s, F_SETFL, f | O_NONBLOCK); \
451 }
452
453 #define SetSocketNoDelay(s) { \
454 int val = 1; \
455 setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(int)); \
456 }
457
458 #define SetSocketBroadcast(s) { \
459 int val = 1; \
460 setsockopt(s, SOL_SOCKET, SO_BROADCAST, (char *)&val, sizeof(int)); \
461 }
462
463 #define SELECT_NFDS(x) (x)
464
465 #else /* not _WIN32 or _NETWARE */
466
467 /*********** UNIX *********************/
468
469 #ifndef PREFIX
470 #ifdef UNICODE
471 #define PREFIX L"/usr/local"
472 #else
473 #define PREFIX "/usr/local"
474 #endif
475 #warning Installation prefix not defined, defaulting to /usr/local
476 #endif
477
478 #if HAVE_ALLOCA_H
479 #include <alloca.h>
480 #endif
481
482 #if HAVE_WCHAR_H
483 #include <wchar.h>
484 #endif
485
486 #if HAVE_WCTYPE_H
487 #include <wctype.h>
488 #endif
489
490 // Fix for wcs* functions visibility in Solaris 11
491 #if defined(__sun) && (__cplusplus >= 199711L)
492 #if HAVE_WCSDUP
493 using std::wcsdup;
494 #endif
495 #if HAVE_WCSCASECMP
496 using std::wcscasecmp;
497 #endif
498 #if HAVE_WCSNCASECMP
499 using std::wcsncasecmp;
500 #endif
501 #endif
502
503 #include <errno.h>
504
505 #define FS_PATH_SEPARATOR _T("/")
506 #define FS_PATH_SEPARATOR_A "/"
507 #define FS_PATH_SEPARATOR_W L"/"
508 #define FS_PATH_SEPARATOR_CHAR _T('/')
509
510 #if HAVE_UNISTD_H
511 #include <unistd.h>
512 #endif
513
514 #if HAVE_STDLIB_H
515 #include <stdlib.h>
516 #endif
517
518 #if HAVE_SYS_TYPES_H
519 #include <sys/types.h>
520 #endif
521
522 #if HAVE_SYS_INT_TYPES_H
523 #include <sys/int_types.h>
524 #endif
525
526 #if HAVE_SYS_STAT_H
527 #include <sys/stat.h>
528 #endif
529
530 #if HAVE_SYS_SOCKET_H
531 #include <sys/socket.h>
532 #endif
533
534 #if HAVE_SYS_SELECT_H
535 #include <sys/select.h>
536 #endif
537
538 #if HAVE_NETINET_IN_H
539 #include <netinet/in.h>
540 #endif
541
542 #if HAVE_NETINET_TCP_H
543 #include <netinet/tcp.h>
544 #endif
545
546 #if HAVE_NET_NH_H
547 #include <net/nh.h>
548 #endif
549
550 #if HAVE_ARPA_INET_H
551 #include <arpa/inet.h>
552 #endif
553
554 #if HAVE_NETDB_H
555 #include <netdb.h>
556 #endif
557
558 #if HAVE_FCNTL_H
559 #include <fcntl.h>
560 #endif
561
562 #include <dirent.h>
563
564 #if _USE_GNU_PTH
565 #include <pth.h>
566 #endif
567
568 #ifdef __sun
569 #include <sys/atomic.h>
570 #endif
571
572 #if defined(__HP_aCC) && HAVE_ATOMIC_H
573 #include <atomic.h>
574 #endif
575
576 #ifdef __IBMCPP__
577 #include <builtins.h>
578 #endif
579
580 #ifdef __minix
581 #undef HAVE_ITOA /* Minix has non-compatible itoa() */
582 #undef HAVE_GETHOSTBYNAME2_R
583 #endif
584
585 #include <sys/socket.h>
586 #include <sys/un.h>
587
588 typedef int BOOL;
589 #if (SIZEOF_LONG == 4)
590 #if (SIZEOF_INT == 4)
591 typedef int INT32;
592 typedef unsigned int UINT32;
593 #else
594 typedef long INT32;
595 typedef unsigned long UINT32;
596 #endif
597 #undef __64BIT__
598 #else
599 typedef int INT32;
600 typedef unsigned int UINT32;
601 #ifndef __64BIT__
602 #define __64BIT__
603 #endif
604 #endif
605 typedef unsigned short UINT16;
606 typedef short INT16;
607 typedef unsigned char BYTE;
608 typedef INT32 LONG; // for compatibility
609 typedef UINT32 DWORD; // for compatibility
610 typedef UINT16 WORD; // for compatibility
611 typedef void * HANDLE;
612 typedef void * HMODULE;
613
614 #if !HAVE_MODE_T
615 typedef int mode_t;
616 #endif
617
618 // We have to use long as INT64 on HP-UX - otherwise
619 // there will be compilation errors because of type redefinition in
620 // system includes
621 #ifdef _HPUX
622
623 #ifdef __LP64__
624 typedef long INT64;
625 typedef unsigned long UINT64;
626 #else
627 typedef long long INT64;
628 typedef unsigned long long UINT64;
629 #endif
630
631 #else /* _HPUX */
632
633 #if HAVE_LONG_LONG && (SIZEOF_LONG_LONG == 8)
634 typedef long long INT64;
635 #elif HAVE_INT64_T
636 typedef int64_t INT64;
637 #elif SIZEOF_LONG == 8
638 typedef long INT64;
639 #else
640 #error Target system does not have signed 64bit integer type
641 #endif
642
643 #if HAVE_UNSIGNED_LONG_LONG && (SIZEOF_LONG_LONG == 8)
644 typedef unsigned long long UINT64;
645 #elif HAVE_UINT64_T
646 typedef uint64_t UINT64;
647 #elif HAVE_U_INT64_T
648 typedef u_int64_t UINT64;
649 #elif SIZEOF_LONG == 8
650 typedef unsigned long UINT64;
651 #else
652 #error Target system does not have unsigned 64bit integer type
653 #endif
654
655 #endif /* _HPUX */
656
657 typedef UINT64 QWORD; // for compatibility
658
659 #define INT64_FMT _T("%lld")
660 #define INT64_FMTW L"%lld"
661 #define INT64_FMTA "%lld"
662 #define UINT64_FMT _T("%llu")
663 #define UINT64_FMTW L"%llu"
664 #define UINT64_FMTA "%llu"
665 #define UINT64X_FMT(m) _T("%") m _T("llX")
666 #ifdef __64BIT__
667 #define TIME_T_FMT _T("%llu")
668 #define TIME_T_FCAST(x) ((UINT64)(x))
669 #else
670 #define TIME_T_FMT _T("%u")
671 #define TIME_T_FCAST(x) ((UINT32)(x))
672 #endif
673
674 #ifndef TRUE
675 #define TRUE 1
676 #endif
677 #ifndef FALSE
678 #define FALSE 0
679 #endif
680
681 #ifndef MAX_PATH
682 #ifdef PATH_MAX
683 #define MAX_PATH PATH_MAX
684 #else
685 #define MAX_PATH 1024
686 #endif
687 #endif
688
689 // Socket compatibility
690 typedef int SOCKET;
691
692 #define closesocket(x) close(x)
693 #define WSAGetLastError() (errno)
694
695 #define WSAEINTR EINTR
696 #define WSAEWOULDBLOCK EWOULDBLOCK
697 #define WSAEINPROGRESS EINPROGRESS
698 #define WSAESHUTDOWN ESHUTDOWN
699 #define INVALID_SOCKET (-1)
700
701 #define SetSocketReuseFlag(sd) { \
702 int nVal = 1; \
703 setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, (const void *)&nVal, \
704 (socklen_t)sizeof(nVal)); \
705 }
706
707 #define SetSocketExclusiveAddrUse(s)
708
709 #define SetSocketNonBlocking(s) { \
710 int f = fcntl(s, F_GETFL); \
711 if (f != -1) fcntl(s, F_SETFL, f | O_NONBLOCK); \
712 }
713
714 #define SetSocketNoDelay(s) { \
715 int val = 1; \
716 setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (const void *)&val, sizeof(int)); \
717 }
718
719 #define SetSocketBroadcast(s) { \
720 int val = 1; \
721 setsockopt(s, SOL_SOCKET, SO_BROADCAST, (const void *)&val, sizeof(int)); \
722 }
723
724 #define SELECT_NFDS(x) (x)
725
726 #if !(HAVE_SOCKLEN_T) && !defined(_USE_GNU_PTH)
727 typedef unsigned int socklen_t;
728 #endif
729
730 #ifndef SUN_LEN
731 #define SUN_LEN(su) (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path))
732 #endif
733
734 // Shared library suffix
735 #ifndef SHLIB_SUFFIX
736 #if defined(_HPUX) && !defined(__64BIT__)
737 #define SHLIB_SUFFIX _T(".sl")
738 #else
739 #define SHLIB_SUFFIX _T(".so")
740 #endif
741 #endif
742
743 typedef struct hostent HOSTENT;
744
745 #if HAVE_DECL___VA_COPY && !HAVE_DECL_VA_COPY
746 #define HAVE_DECL_VA_COPY 1
747 #define va_copy(d,s) __va_copy(d,s)
748 #endif
749
750 #endif /* _WIN32 */
751
752 /**
753 * Value used to indicate invalid pointer where NULL is not appropriate
754 */
755 #ifdef __64BIT__
756 #define INVALID_POINTER_VALUE ((void *)_ULL(0xFFFFFFFFFFFFFFFF))
757 #else
758 #define INVALID_POINTER_VALUE ((void *)0xFFFFFFFF)
759 #endif
760
761 /**
762 * Casting between pointer and 32-bit integer
763 */
764 #ifdef __64BIT__
765 #define CAST_FROM_POINTER(p, t) ((t)((UINT64)(p)))
766 #define CAST_TO_POINTER(v, t) ((t)((UINT64)(v)))
767 #else
768 #define CAST_FROM_POINTER(p, t) ((t)(p))
769 #define CAST_TO_POINTER(v, t) ((t)(v))
770 #endif
771
772 /**
773 * OpenSSL
774 */
775 #if defined(_WITH_ENCRYPTION) && !defined(ORA_PROC)
776
777 #include <openssl/crypto.h>
778 #include <openssl/rsa.h>
779 #include <openssl/pem.h>
780 #include <openssl/evp.h>
781 #include <openssl/rand.h>
782 #include <openssl/opensslv.h>
783 #include <openssl/err.h>
784
785 #ifdef NETXMS_NO_AES
786 #ifndef OPENSSL_NO_AES
787 #define OPENSSL_NO_AES
788 #endif
789 #endif
790
791 #ifdef NETXMS_NO_BF
792 #ifndef OPENSSL_NO_BF
793 #define OPENSSL_NO_BF
794 #endif
795 #endif
796
797 #ifdef NETXMS_NO_IDEA
798 #ifndef OPENSSL_NO_IDEA
799 #define OPENSSL_NO_IDEA
800 #endif
801 #endif
802
803 #ifdef NETXMS_NO_DES
804 #ifndef OPENSSL_NO_DES
805 #define OPENSSL_NO_DES
806 #endif
807 #endif
808
809 #if OPENSSL_VERSION_NUMBER >= 0x00907000
810 #define OPENSSL_CONST const
811 #else
812 #define OPENSSL_CONST
813 #endif
814
815 #else
816
817 // Prevent compilation errors on function prototypes
818 #define RSA void
819
820 #endif
821
822 /**
823 * open() flags compatibility
824 */
825 #ifndef O_BINARY
826 #define O_BINARY 0
827 #endif
828
829 /**
830 * Windows-specific structures for non-Windows platforms
831 */
832 #ifndef _WIN32
833
834 typedef struct tagPOINT
835 {
836 int x;
837 int y;
838 } POINT;
839
840 #endif
841
842 /**
843 * Event log severity codes
844 */
845 #ifndef _WIN32
846 #define EVENTLOG_SUCCESS 0x0000
847 #define EVENTLOG_ERROR_TYPE 0x0001
848 #define EVENTLOG_WARNING_TYPE 0x0002
849 #define EVENTLOG_INFORMATION_TYPE 0x0004
850 #define EVENTLOG_AUDIT_SUCCESS 0x0008
851 #define EVENTLOG_AUDIT_FAILURE 0x0010
852 #endif /* _WIN32 */
853
854 #define NXLOG_DEBUG EVENTLOG_DEBUG_TYPE
855 #define NXLOG_INFO EVENTLOG_INFORMATION_TYPE
856 #define NXLOG_WARNING EVENTLOG_WARNING_TYPE
857 #define NXLOG_ERROR EVENTLOG_ERROR_TYPE
858
859 /**
860 * Interface types
861 */
862 #define IFTYPE_OTHER 1
863 #define IFTYPE_REGULAR1822 2
864 #define IFTYPE_HDH1822 3
865 #define IFTYPE_DDN_X25 4
866 #define IFTYPE_RFC877_X25 5
867 #define IFTYPE_ETHERNET_CSMACD 6
868 #define IFTYPE_ISO88023_CSMACD 7
869 #define IFTYPE_ISO88024_TOKENBUS 8
870 #define IFTYPE_ISO88025_TOKENRING 9
871 #define IFTYPE_ISO88026_MAN 10
872 #define IFTYPE_STARLAN 11
873 #define IFTYPE_PROTEON_10MBIT 12
874 #define IFTYPE_PROTEON_80MBIT 13
875 #define IFTYPE_HYPERCHANNEL 14
876 #define IFTYPE_FDDI 15
877 #define IFTYPE_LAPB 16
878 #define IFTYPE_SDLC 17
879 #define IFTYPE_DS1 18
880 #define IFTYPE_E1 19
881 #define IFTYPE_BASIC_ISDN 20
882 #define IFTYPE_PRIMARY_ISDN 21
883 #define IFTYPE_PROP_PTP_SERIAL 22
884 #define IFTYPE_PPP 23
885 #define IFTYPE_SOFTWARE_LOOPBACK 24
886 #define IFTYPE_EON 25
887 #define IFTYPE_ETHERNET_3MBIT 26
888 #define IFTYPE_NSIP 27
889 #define IFTYPE_SLIP 28
890 #define IFTYPE_ULTRA 29
891 #define IFTYPE_DS3 30
892 #define IFTYPE_SMDS 31
893 #define IFTYPE_FRAME_RELAY 32
894 #define IFTYPE_RS232 33
895 #define IFTYPE_PARA 34
896 #define IFTYPE_ARCNET 35
897 #define IFTYPE_ARCNET_PLUS 36
898 #define IFTYPE_ATM 37
899 #define IFTYPE_MIOX25 38
900 #define IFTYPE_SONET 39
901 #define IFTYPE_X25PLE 40
902 #define IFTYPE_ISO88022LLC 41
903 #define IFTYPE_LOCALTALK 42
904 #define IFTYPE_SMDS_DXI 43
905 #define IFTYPE_FRAME_RELAY_SERVICE 44
906 #define IFTYPE_V35 45
907 #define IFTYPE_HSSI 46
908 #define IFTYPE_HIPPI 47
909 #define IFTYPE_MODEM 48
910 #define IFTYPE_AAL5 49
911 #define IFTYPE_SONET_PATH 50
912 #define IFTYPE_SONET_VT 51
913 #define IFTYPE_SMDS_ICIP 52
914 #define IFTYPE_PROP_VIRTUAL 53
915 #define IFTYPE_PROP_MULTIPLEXOR 54
916 #define IFTYPE_IEEE80212 55
917 #define IFTYPE_FIBRECHANNEL 56
918 #define IFTYPE_HIPPIINTERFACE 57
919 #define IFTYPE_FRAME_RELAY_INTERCONNECT 58
920 #define IFTYPE_AFLANE8023 59
921 #define IFTYPE_AFLANE8025 60
922 #define IFTYPE_CCTEMUL 61
923 #define IFTYPE_FAST_ETHERNET 62
924 #define IFTYPE_ISDN 63
925 #define IFTYPE_V11 64
926 #define IFTYPE_V36 65
927 #define IFTYPE_G703_AT64K 66
928 #define IFTYPE_G703_AT2MB 67
929 #define IFTYPE_QLLC 68
930 #define IFTYPE_FASTETHERFX 69
931 #define IFTYPE_CHANNEL 70
932 #define IFTYPE_IEEE80211 71
933 #define IFTYPE_IBM370_PARCHAN 72
934 #define IFTYPE_ESCON 73
935 #define IFTYPE_DLSW 74
936 #define IFTYPE_ISDNS 75
937 #define IFTYPE_ISDNU 76
938 #define IFTYPE_LAPD 77
939 #define IFTYPE_IPSWITCH 78
940 #define IFTYPE_RSRB 79
941 #define IFTYPE_ATMLOGICAL 80
942 #define IFTYPE_DS0 81
943 #define IFTYPE_DS0_BUNDLE 82
944 #define IFTYPE_BSC 83
945 #define IFTYPE_ASYNC 84
946 #define IFTYPE_CNR 85
947 #define IFTYPE_ISO88025DTR 86
948 #define IFTYPE_EPLRS 87
949 #define IFTYPE_ARAP 88
950 #define IFTYPE_PROPCNLS 89
951 #define IFTYPE_HOSTPAD 90
952 #define IFTYPE_TERMPAD 91
953 #define IFTYPE_FRAME_RELAY_MPI 92
954 #define IFTYPE_X213 93
955 #define IFTYPE_ADSL 94
956 #define IFTYPE_RADSL 95
957 #define IFTYPE_SDSL 96
958 #define IFTYPE_VDSL 97
959 #define IFTYPE_ISO88025CRFPINT 98
960 #define IFTYPE_MYRINET 99
961 #define IFTYPE_VOICEEM 100
962 #define IFTYPE_VOICEFXO 101
963 #define IFTYPE_VOICEFXS 102
964 #define IFTYPE_VOICEENCAP 103
965 #define IFTYPE_VOICEOVERIP 104
966 #define IFTYPE_ATMDXI 105
967 #define IFTYPE_ATMFUNI 106
968 #define IFTYPE_ATMIMA 107
969 #define IFTYPE_PPPMULTILINKBUNDLE 108
970 #define IFTYPE_IPOVERCDLC 109
971 #define IFTYPE_IPOVERCLAW 110
972 #define IFTYPE_STACKTOSTACK 111
973 #define IFTYPE_VIRTUAL_IP_ADDRESS 112
974 #define IFTYPE_MPC 113
975 #define IFTYPE_IPOVERATM 114
976 #define IFTYPE_ISO88025FIBER 115
977 #define IFTYPE_TDLC 116
978 #define IFTYPE_GIGABIT_ETHERNET 117
979 #define IFTYPE_HDLC 118
980 #define IFTYPE_LAPF 119
981 #define IFTYPE_V37 120
982 #define IFTYPE_X25MLP 121
983 #define IFTYPE_X25_HUNT_GROUP 122
984 #define IFTYPE_TRANSPHDLC 123
985 #define IFTYPE_INTERLEAVE 124
986 #define IFTYPE_FAST 125
987 #define IFTYPE_IP 126
988 #define IFTYPE_DOCSCABLE_MACLAYER 127
989 #define IFTYPE_DOCSCABLE_DOWNSTREAM 128
990 #define IFTYPE_DOCSCABLE_UPSTREAM 129
991 #define IFTYPE_A12MPPSWITCH 130
992 #define IFTYPE_TUNNEL 131
993 #define IFTYPE_COFFEE 132
994 #define IFTYPE_CES 133
995 #define IFTYPE_ATM_SUBINTERFACE 134
996 #define IFTYPE_L2VLAN 135
997 #define IFTYPE_L3IPVLAN 136
998 #define IFTYPE_L3IPXVLAN 137
999 #define IFTYPE_DIGITAL_POWERLINE 138
1000 #define IFTYPE_MEDIAMAIL_OVER_IP 139
1001 #define IFTYPE_DTM 140
1002 #define IFTYPE_DCN 141
1003 #define IFTYPE_IPFORWARD 142
1004 #define IFTYPE_MSDSL 143
1005 #define IFTYPE_IEEE1394 144
1006 #define IFTYPE_GSN 145
1007 #define IFTYPE_DVBRCC_MACLAYER 146
1008 #define IFTYPE_DVBRCC_DOWNSTREAM 147
1009 #define IFTYPE_DVBRCC_UPSTREAM 148
1010 #define IFTYPE_ATM_VIRTUAL 149
1011 #define IFTYPE_MPLS_TUNNEL 150
1012 #define IFTYPE_SRP 151
1013 #define IFTYPE_VOICE_OVER_ATM 152
1014 #define IFTYPE_VOICE_OVER_FRAME_RELAY 153
1015 #define IFTYPE_IDSL 154
1016 #define IFTYPE_COMPOSITE_LINK 155
1017 #define IFTYPE_SS7_SIGLINK 156
1018 #define IFTYPE_PROPWIRELESSP2P 157
1019 #define IFTYPE_FRFORWARD 158
1020 #define IFTYPE_RFC1483 159
1021 #define IFTYPE_USB 160
1022 #define IFTYPE_IEEE8023ADLAG 161
1023 #define IFTYPE_BGP_POLICY_ACCOUNTING 162
1024 #define IFTYPE_FRF16MFR_BUNDLE 163
1025 #define IFTYPE_H323_GATEKEEPER 164
1026 #define IFTYPE_H323_PROXY 165
1027 #define IFTYPE_MPLS 166
1028 #define IFTYPE_MFSIGLINK 167
1029 #define IFTYPE_HDSL2 168
1030 #define IFTYPE_SHDSL 169
1031 #define IFTYPE_DS1FDL 170
1032 #define IFTYPE_POS 171
1033 #define IFTYPE_DVBASI_IN 172
1034 #define IFTYPE_DVBASI_OUT 173
1035 #define IFTYPE_PLC 174
1036 #define IFTYPE_NFAS 175
1037 #define IFTYPE_TR008 176
1038 #define IFTYPE_GR303RDT 177
1039 #define IFTYPE_GR303IDT 178
1040 #define IFTYPE_ISUP 179
1041 #define IFTYPE_PROPDOCSWIRELESSMACLAYER 180
1042 #define IFTYPE_PROPDOCSWIRELESSDOWNSTREAM 181
1043 #define IFTYPE_PROPDOCSWIRELESSUPSTREAM 182
1044 #define IFTYPE_HIPERLAN2 183
1045 #define IFTYPE_PROPBWAP2MP 184
1046 #define IFTYPE_SONET_OVERHEAD_CHANNEL 185
1047 #define IFTYPE_DW_OVERHEAD_CHANNEL 186
1048 #define IFTYPE_AAL2 187
1049 #define IFTYPE_RADIOMAC 188
1050 #define IFTYPE_ATMRADIO 189
1051 #define IFTYPE_IMT 190
1052 #define IFTYPE_MVL 191
1053 #define IFTYPE_REACHDSL 192
1054 #define IFTYPE_FRDLCIENDPT 193
1055 #define IFTYPE_ATMVCIENDPT 194
1056 #define IFTYPE_OPTICAL_CHANNEL 195
1057 #define IFTYPE_OPTICAL_TRANSPORT 196
1058 #define IFTYPE_PROPATM 197
1059 #define IFTYPE_VOICE_OVER_CABLE 198
1060 #define IFTYPE_INFINIBAND 199
1061 #define IFTYPE_TELINK 200
1062 #define IFTYPE_Q2931 201
1063 #define IFTYPE_VIRTUALTG 202
1064 #define IFTYPE_SIPTG 203
1065 #define IFTYPE_SIPSIG 204
1066 #define IFTYPE_DOCSCABLEUPSTREAMCHANNEL 205
1067 #define IFTYPE_ECONET 206
1068 #define IFTYPE_PON155 207
1069 #define IFTYPE_PON622 208
1070 #define IFTYPE_BRIDGE 209
1071 #define IFTYPE_LINEGROUP 210
1072 #define IFTYPE_VOICEEMFGD 211
1073 #define IFTYPE_VOICEFGDEANA 212
1074 #define IFTYPE_VOICEDID 213
1075 #define IFTYPE_MPEG_TRANSPORT 214
1076 #define IFTYPE_SIXTOFOUR 215
1077 #define IFTYPE_GTP 216
1078 #define IFTYPE_PDNETHERLOOP1 217
1079 #define IFTYPE_PDNETHERLOOP2 218
1080 #define IFTYPE_OPTICAL_CHANNEL_GROUP 219
1081 #define IFTYPE_HOMEPNA 220
1082 #define IFTYPE_GFP 221
1083 #define IFTYPE_CISCO_ISL_VLAN 222
1084 #define IFTYPE_ACTELIS_METALOOP 223
1085 #define IFTYPE_FCIPLINK 224
1086 #define IFTYPE_RPR 225
1087 #define IFTYPE_QAM 226
1088 #define IFTYPE_LMP 227
1089 #define IFTYPE_CBLVECTASTAR 228
1090 #define IFTYPE_DOCSCABLEMCMTSDOWNSTREAM 229
1091 #define IFTYPE_ADSL2 230
1092 #define IFTYPE_MACSECCONTROLLEDIF 231
1093 #define IFTYPE_MACSECUNCONTROLLEDIF 232
1094 #define IFTYPE_AVICIOPTICALETHER 233
1095 #define IFTYPE_ATM_BOND 234
1096 #define IFTYPE_VOICEFGDOS 235
1097 #define IFTYPE_MOCA_VERSION1 236
1098 #define IFTYPE_IEEE80216WMAN 237
1099 #define IFTYPE_ADSL2PLUS 238
1100 #define IFTYPE_DVBRCSMACLAYER 239
1101 #define IFTYPE_DVBTDM 240
1102 #define IFTYPE_DVBRCSTDMA 241
1103 #define IFTYPE_X86LAPS 242
1104 #define IFTYPE_WWANPP 243
1105 #define IFTYPE_WWANPP2 244
1106 #define IFTYPE_VOICEEBS 245
1107 #define IFTYPE_IFPWTYPE 246
1108 #define IFTYPE_ILAN 247
1109 #define IFTYPE_PIP 248
1110 #define IFTYPE_ALUELP 249
1111 #define IFTYPE_GPON 250
1112 #define IFTYPE_VDSL2 251
1113 #define IFTYPE_CAPWAP_DOT11_PROFILE 252
1114 #define IFTYPE_CAPWAP_DOT11_BSS 253
1115 #define IFTYPE_CAPWAP_WTP_VIRTUAL_RADIO 254
1116 #define IFTYPE_BITS 255
1117 #define IFTYPE_DOCSCABLEUPSTREAMRFPORT 256
1118 #define IFTYPE_CABLEDOWNSTREAMRFPORT 257
1119 #define IFTYPE_VMWARE_VIRTUAL_NIC 258
1120 #define IFTYPE_IEEE802154 259
1121 #define IFTYPE_OTNODU 260
1122 #define IFTYPE_OTNOTU 261
1123 #define IFTYPE_IFVFITYPE 262
1124 #define IFTYPE_G9981 263
1125 #define IFTYPE_G9982 264
1126 #define IFTYPE_G9983 265
1127 #define IFTYPE_ALUEPON 266
1128 #define IFTYPE_ALUEPONONU 267
1129 #define IFTYPE_ALUEPONPHYSICALUNI 268
1130 #define IFTYPE_ALUEPONLOGICALLINK 269
1131 #define IFTYPE_ALUGPONONU 270
1132 #define IFTYPE_ALUGPONPHYSICALUNI 271
1133 #define IFTYPE_VMWARE_NIC_TEAM 272
1134
1135 /**
1136 * IP Header -- RFC 791
1137 */
1138 typedef struct tagIPHDR
1139 {
1140 BYTE m_cVIHL; // Version and IHL
1141 BYTE m_cTOS; // Type Of Service
1142 WORD m_wLen; // Total Length
1143 WORD m_wId; // Identification
1144 WORD m_wFlagOff; // Flags and Fragment Offset
1145 BYTE m_cTTL; // Time To Live
1146 BYTE m_cProtocol; // Protocol
1147 WORD m_wChecksum; // Checksum
1148 struct in_addr m_iaSrc; // Internet Address - Source
1149 struct in_addr m_iaDst; // Internet Address - Destination
1150 } IPHDR;
1151
1152 /**
1153 * ICMP Header - RFC 792
1154 */
1155 typedef struct tagICMPHDR
1156 {
1157 BYTE m_cType; // Type
1158 BYTE m_cCode; // Code
1159 WORD m_wChecksum; // Checksum
1160 WORD m_wId; // Identification
1161 WORD m_wSeq; // Sequence
1162 } ICMPHDR;
1163
1164 /**
1165 * INADDR_NONE can be undefined on some systems
1166 */
1167 #ifndef INADDR_NONE
1168 #define INADDR_NONE (0xFFFFFFFF)
1169 #endif
1170
1171 /**
1172 * Check if given string is NULL and always return valid pointer
1173 */
1174 #define CHECK_NULL(x) ((x) == NULL ? _T("(null)") : (x))
1175 #define CHECK_NULL_A(x) ((x) == NULL ? "(null)" : (x))
1176 #define CHECK_NULL_EX(x) ((x) == NULL ? _T("") : (x))
1177 #define CHECK_NULL_EX_A(x) ((x) == NULL ? "" : (x))
1178
1179 /**
1180 * Free memory block if it isn't NULL
1181 */
1182 #if FREE_IS_NULL_SAFE
1183 #define safe_free(x) free(x);
1184 #define safe_free_and_null(x) { free(x); x = NULL; }
1185 #else
1186 #define safe_free(x) { if ((x) != NULL) free(x); }
1187 #define safe_free_and_null(x) { if ((x) != NULL) { free(x); x = NULL; } }
1188 #endif
1189
1190 /**
1191 * free() wrapper if it isn't NULL safe
1192 */
1193 #if defined(__cplusplus) && !FREE_IS_NULL_SAFE
1194 inline void nx_free(void *p)
1195 {
1196 if (p != NULL)
1197 free(p);
1198 }
1199 #define free nx_free
1200 #endif
1201
1202 /**
1203 * delete object and nullify pointer
1204 */
1205 #define delete_and_null(x) { delete x; x = NULL; }
1206
1207 /**
1208 * Convert half-byte's value to hex digit and vice versa
1209 */
1210 #define bin2hex(x) ((x) < 10 ? ((x) + _T('0')) : ((x) + (_T('A') - 10)))
1211 #ifdef UNICODE
1212 #define hex2bin(x) ((((x) >= _T('0')) && ((x) <= _T('9'))) ? ((x) - _T('0')) : \
1213 (((towupper(x) >= _T('A')) && (towupper(x) <= _T('F'))) ? (towupper(x) - _T('A') + 10) : 0))
1214 #else
1215 #define hex2bin(x) ((((x) >= '0') && ((x) <= '9')) ? ((x) - '0') : \
1216 (((toupper(x) >= 'A') && (toupper(x) <= 'F')) ? (toupper(x) - 'A' + 10) : 0))
1217 #endif
1218
1219 /**
1220 * Define min() and max() if needed
1221 */
1222 #ifndef min
1223 #define min(a, b) ((a) < (b) ? (a) : (b))
1224 #endif
1225 #ifndef max
1226 #define max(a, b) ((a) > (b) ? (a) : (b))
1227 #endif
1228
1229 /**
1230 * Define _tcsicmp() for non-windows
1231 */
1232 #ifndef _WIN32
1233 #define stricmp strcasecmp
1234 #define strnicmp strncasecmp
1235 #define wcsicmp wcscasecmp
1236 #define wcsnicmp wcsncasecmp
1237 #endif
1238
1239 /**
1240 * Compare two numbers and return -1, 0, or 1
1241 */
1242 #define COMPARE_NUMBERS(n1,n2) (((n1) < (n2)) ? -1 : (((n1) > (n2)) ? 1 : 0))
1243
1244 /**
1245 * Increment pointer for given number of bytes
1246 */
1247 #define inc_ptr(ptr, step, ptype) ptr = (ptype *)(((char *)ptr) + step)
1248
1249 /**
1250 * Validate numerical value
1251 */
1252 #define VALIDATE_VALUE(var,x,y,z) { if ((var < x) || (var > y)) var = z; }
1253
1254 /**
1255 * DCI (data collection item) data types
1256 */
1257 #define DCI_DT_INT 0
1258 #define DCI_DT_UINT 1
1259 #define DCI_DT_INT64 2
1260 #define DCI_DT_UINT64 3
1261 #define DCI_DT_STRING 4
1262 #define DCI_DT_FLOAT 5
1263 #define DCI_DT_NULL 6
1264 #define DCI_DT_DEPRECATED 255 /* used internally by agent */
1265
1266 /**
1267 * Insert parameter as string
1268 */
1269 #ifdef UNICODE
1270 #define STRING(x) L#x
1271 #else
1272 #define STRING(x) #x
1273 #endif
1274
1275 /**
1276 * Pipe handle
1277 */
1278 #ifdef _WIN32
1279 #define HPIPE HANDLE
1280 #define INVALID_PIPE_HANDLE INVALID_HANDLE_VALUE
1281 #else
1282 #define HPIPE int
1283 #define INVALID_PIPE_HANDLE (-1)
1284 #endif
1285
1286 #ifdef __cplusplus
1287
1288 /**
1289 * Session enumeration callback return codes
1290 */
1291 enum EnumerationCallbackResult
1292 {
1293 _STOP = 0,
1294 _CONTINUE = 1
1295 };
1296
1297 #endif
1298
1299 #endif /* _nms_common_h_ */