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