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