fixed conflicts with Cortex headers
[public/netxms.git] / include / nms_common.h
CommitLineData
cbcaf8c8 1/*
7ac71e60 2** NetXMS - Network Management System
120bfcdf 3** Copyright (C) 2003-2014 Victor Kirhenshtein
cbcaf8c8
VK
4**
5** This program is free software; you can redistribute it and/or modify
68f384ea
VK
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
cbcaf8c8
VK
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**
68f384ea 15** You should have received a copy of the GNU Lesser General Public License
cbcaf8c8
VK
16** along with this program; if not, write to the Free Software
17** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18**
28c329e2 19** File: nms_common.h
cbcaf8c8
VK
20**
21**/
22
23#ifndef _nms_common_h_
24#define _nms_common_h_
25
a1cb335b
VK
26#ifdef WIN32
27#ifndef _WIN32
28#define _WIN32
29#endif
30#endif
31
e647245b
VK
32#ifdef __SYMBIAN32__
33
34// Symbian compiler defines _WIN32 in builds for emulator.
35#undef _WIN32
36
37#else
38
b40371d4 39#if !defined(_WIN32) && !defined(UNDER_CE)
e647245b 40
408a78b9 41#ifdef _NETWARE
8683077a 42#include <config-netware.h>
408a78b9 43#else
d2a3bf6b 44#include "config.h"
779c2678
VK
45#ifdef WITH_OPENSSL
46#define _WITH_ENCRYPTION 1
47#endif
408a78b9 48#endif
e647245b 49
15cf5acc 50#else /* _WIN32 */
e647245b 51
2c12edfc 52#ifndef UNDER_CE
15cf5acc 53#define _WITH_ENCRYPTION 1
6c352bb5 54#define WITH_LDAP 1
f00612ba 55#if !defined(WINDOWS_ONLY) && !defined(_CRT_SECURE_NO_DEPRECATE)
be460d82 56#define _CRT_SECURE_NO_DEPRECATE
2c12edfc 57#endif
f00612ba 58#endif
e647245b 59
f00612ba 60#endif
408a78b9 61
e647245b
VK
62#endif /* __SYMBIAN32__ */
63
6b42b6f1 64#ifdef HAVE_STDARG_H
e647245b 65#include <stdarg.h>
6b42b6f1
AK
66#endif
67
f2fdf1b5 68#include <unicode.h>
e647245b 69
f2fdf1b5
VK
70#include <stdio.h>
71#include <string.h>
b50f1100 72#include <limits.h>
93b18807 73
b900a78b 74#include <netxms-version.h>
8606bcf9 75
bde67a1f
VK
76/**
77 * Define __64BIT__ if compiling for 64bit platform with Visual C++
78 */
a731ec52
VK
79#if defined(_M_X64) || defined(_M_IA64)
80#ifndef __64BIT__
81#define __64BIT__
82#endif
83#endif
84
0cdf79a3
VK
85/**
86 * Wrappers for 64-bit integer constants
87 */
3a5657b9 88#if defined(__GNUC__) || defined(__HP_aCC) || defined(__IBMC__) || defined(__IBMCPP__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
c61f5190
VK
89#define _LL(x) (x ## LL)
90#define _ULL(x) (x ## ULL)
7946bd7c
VK
91#elif defined(_MSC_VER)
92#define _LL(x) (x ## i64)
93#define _ULL(x) (x ## ui64)
c61f5190
VK
94#else
95#define _LL(x) (x)
96#define _ULL(x) (x)
97#endif
98
480e036b
VK
99/**
100 * Common constants
101 */
fb52d37d 102#define MAX_SECRET_LENGTH 64
a7d07192 103#define MAX_DB_STRING 256
999812c7 104#define MAX_PARAM_NAME 256
cc8ce218 105#define MAX_COLUMN_NAME 64
5ad2167d 106#define MAX_DNS_NAME 256
d41268ba 107#define MAX_HELPDESK_REF_LEN 64
967893bb 108#define GROUP_FLAG ((UINT32)0x80000000)
e44ac467 109
d772d0dd 110#define NETXMS_MAX_CIPHERS 6
15cf5acc 111#define NETXMS_RSA_KEYLEN 2048
fb52d37d 112
b50f1100 113#ifndef LLONG_MAX
c61f5190 114#define LLONG_MAX _LL(9223372036854775807)
b50f1100
VK
115#endif
116
117#ifndef LLONG_MIN
118#define LLONG_MIN (-LLONG_MAX - 1)
119#endif
120
121#ifndef ULLONG_MAX
c61f5190 122#define ULLONG_MAX _ULL(18446744073709551615)
b50f1100
VK
123#endif
124
05f256fe 125#ifndef EVENTLOG_DEBUG_TYPE
ccc34207
VK
126#define EVENTLOG_DEBUG_TYPE 0x0080
127#endif
128
e647245b
VK
129#define INVALID_INDEX 0xFFFFFFFF
130#define MD5_DIGEST_SIZE 16
131#define SHA1_DIGEST_SIZE 20
132
9fa031cd 133#define FILE_BUFFER_SIZE 32768
134
664b42a4
VK
135/**
136 * Compatibility defines for C sources
137 */
735bac5c 138#if !defined(__cplusplus) && !defined(CORTEX)
ccc34207 139typedef int bool;
05f256fe
VK
140#endif
141
bde67a1f
VK
142/**
143 * Oracle Pro*C compatibility
144 */
909c0624 145#ifdef ORA_PROC
bde67a1f 146#undef BYTE
50456b1f 147#undef DWORD
bde67a1f
VK
148#endif
149
fb52d37d 150
bde67a1f 151/***** Platform dependent includes and defines *****/
fb52d37d 152
018fda4d 153#if defined(_WIN32) || defined(UNDER_CE)
076a55c4
VK
154
155/********** WINDOWS ********************/
e9246d26 156
e17fe9ab 157#ifndef _WIN32_WINNT
e82f7649 158#define _WIN32_WINNT 0x0502
e17fe9ab 159#endif
f33479c8 160
36e44abe
VK
161#define WITH_IPV6 1
162
807c0ccc 163#define USE_BUNDLED_LIBTRE 1
df9812a9 164#define USE_BUNDLED_GETOPT 1
807c0ccc 165
3bf0df9f
VK
166#define SAFE_FGETWS_WITH_POPEN 1
167
c6491611 168#define FS_PATH_SEPARATOR _T("\\")
b07c50cc
VK
169#define FS_PATH_SEPARATOR_A "\\"
170#define FS_PATH_SEPARATOR_W L"\\"
c6491611
VK
171#define FS_PATH_SEPARATOR_CHAR _T('\\')
172
b79e8fed
VK
173#define WEXITSTATUS(x) (x)
174
2385d5d0 175#if _MSC_VER > 1300
c6491611
VK
176#define HAVE_SCPRINTF 1
177#define HAVE_VSCPRINTF 1
178#define HAVE_SCWPRINTF 1
179#define HAVE_VSCWPRINTF 1
2385d5d0 180#endif
f70fc197 181
ce7565e7
VK
182#ifndef va_copy
183#define va_copy(x,y) (x = y)
184#endif
185#define HAVE_DECL_VA_COPY 1
186
74540dab
VK
187#define HAVE_LIBCURL 1
188
9caddb3c 189#include <winsock2.h>
510dd9c4 190#include <windows.h>
36e44abe 191#include <ws2tcpip.h>
d454fb4c 192#include <stdlib.h>
1ddf3f0c 193#include <malloc.h>
1dd2715c 194
018fda4d 195#ifndef UNDER_CE
a8d4cdee
VK
196#include <sys/stat.h>
197#include <process.h>
1dd2715c 198#include <io.h>
3d1cb7d6 199#include <fcntl.h>
a23d8e0d 200#include <direct.h>
018fda4d 201#endif
91ab8f0a 202
37d62364
AK
203#ifndef S_IRUSR
204# define S_IRUSR 0400
205#endif
206#ifndef S_IWUSR
207# define S_IWUSR 0200
208#endif
1dd2715c 209
34576b56
VK
210#define snprintf _snprintf
211#define vsnprintf _vsnprintf
f83a0c3a
VK
212#define snwprintf _snwprintf
213#define vsnwprintf _vsnwprintf
c6491611
VK
214#define scprintf _scprintf
215#define vscprintf _vscprintf
216#define scwprintf _scwprintf
217#define vscwprintf _vscwprintf
34576b56
VK
218#define popen _popen
219#define pclose _pclose
34576b56
VK
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)
ccc34207 227#define lseek(f,o,w) _lseek(f,o,w)
34576b56 228#define unlink(x) _unlink(x)
d4c266b6 229
967893bb 230typedef UINT64 QWORD; // for compatibility
670c7f3d 231typedef int socklen_t;
50456b1f 232typedef DWORD pid_t;
734e79a8
VK
233typedef LONG ssize_t;
234
235typedef signed __int8 int8_t;
236typedef signed __int16 int16_t;
237typedef signed __int32 int32_t;
238typedef signed __int64 int64_t;
239typedef unsigned __int8 uint8_t;
240typedef unsigned __int16 uint16_t;
241typedef unsigned __int32 uint32_t;
242typedef unsigned __int64 uint64_t;
e9246d26 243
8b1fedb2 244#define INT64_FMT _T("%I64d")
dda7c270 245#define INT64_FMTA "%I64d"
511bea22 246#define INT64_FMTW L"%I64d"
8b1fedb2 247#define UINT64_FMT _T("%I64u")
dda7c270 248#define UINT64_FMTA "%I64u"
511bea22 249#define UINT64_FMTW L"%I64u"
8b1fedb2 250#define UINT64X_FMT(m) _T("%") m _T("I64X")
0b514e86 251#if defined(__64BIT__) || (_MSC_VER > 1300)
34576b56 252#define TIME_T_FMT _T("%I64u")
967893bb 253#define TIME_T_FCAST(x) ((UINT64)(x))
1094818a 254#else
34576b56 255#define TIME_T_FMT _T("%u")
967893bb 256#define TIME_T_FCAST(x) ((UINT32)(x))
1094818a 257#endif
cb53cb15 258
8f7e2482
VK
259// Socket compatibility
260#define SHUT_RD 0
261#define SHUT_WR 1
262#define SHUT_RDWR 2
263
1ddf3f0c
VK
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}
a3c76aba 272#define SELECT_NFDS(x) ((int)(x))
19121a38
VK
273#define SetSocketNonBlocking(s) { \
274 u_long one = 1; \
275 ioctlsocket(s, FIONBIO, &one); \
276}
734e79a8
VK
277#define SetSocketBlocking(s) { \
278 u_long zero = 0; \
279 ioctlsocket(s, FIONBIO, &zero); \
280}
4a36d30c
VK
281#define SetSocketNoDelay(s) { \
282 BOOL val = TRUE; \
283 setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(BOOL)); \
284}
be45f318 285
55b33d4c
VK
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
3973f74b 295#if !defined(UNDER_CE)
c1099678 296#define HAVE_LIBEXPAT 1
1bb6b449
VK
297#endif
298
058bf6fc
VK
299#define XMPP_SUPPORTED 1
300
c1099678
VK
301#define HAVE_LOCALE_H 1
302#define HAVE_SETLOCALE 1
303
8ff13508
VK
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)
35f836fe 310#define _tcsdup(s) nx__tcsdup(s)
8ff13508
VK
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
076a55c4
VK
327#elif defined(_NETWARE)
328
329/********** NETWARE ********************/
330
636da5f3 331#define FS_PATH_SEPARATOR _T("/")
b07c50cc
VK
332#define FS_PATH_SEPARATOR_A "/"
333#define FS_PATH_SEPARATOR_W L"/"
636da5f3 334#define FS_PATH_SEPARATOR_CHAR _T('/')
62d11997 335
076a55c4
VK
336#include <unistd.h>
337#include <stdlib.h>
338#include <sys/types.h>
cc4c6659 339#include <sys/stat.h>
076a55c4
VK
340#include <sys/socket.h>
341#include <sys/select.h>
342#include <netinet/in.h>
e9c8eb1d 343#include <netinet/tcp.h>
076a55c4
VK
344#include <arpa/inet.h>
345#include <stdint.h>
346#include <fcntl.h>
5bdbe3df 347#include <errno.h>
c5a763cc 348#include <dirent.h>
8683077a 349#include <wchar.h>
46b0825e 350#include <netdb.h>
076a55c4
VK
351
352typedef int BOOL;
678de2bc 353#if (SIZEOF_LONG == 4)
967893bb 354typedef long INT32;
678de2bc 355#else
967893bb 356typedef int INT32;
678de2bc
VK
357#endif
358#if (SIZEOF_LONG == 4)
967893bb 359typedef unsigned long UINT32;
678de2bc 360#else
967893bb 361typedef unsigned int UINT32;
678de2bc 362#endif
967893bb 363typedef INT32 LONG;
50456b1f 364typedef UINT32 DWORD;
967893bb
VK
365typedef unsigned short UINT16;
366typedef UINT16 WORD;
076a55c4
VK
367typedef unsigned char BYTE;
368typedef void * HANDLE;
369typedef void * HMODULE;
370
371#ifdef X_INT64_X
372typedef 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
967893bb
VK
378typedef X_UINT64_X UINT64;
379typedef UINT64 QWORD;
076a55c4
VK
380#else
381#error Target system does not have unsigned 64bit integer type
382#endif
383
8b1fedb2 384#define INT64_FMT _T("%lld")
dda7c270
VK
385#define INT64_FMTW L"%lld"
386#define INT64_FMTA "%lld"
8b1fedb2 387#define UINT64_FMT _T("%llu")
dda7c270
VK
388#define UINT64_FMTW L"%llu"
389#define UINT64_FMTA "%llu"
8b1fedb2
VK
390#define UINT64X_FMT(m) _T("%") m _T("llX")
391#define TIME_T_FMT _T("%u")
967893bb 392#define TIME_T_FCAST(x) ((UINT32)(x))
cb53cb15 393
076a55c4
VK
394#ifndef MAX_PATH
395#define MAX_PATH 256
396#endif
397
398// Socket compatibility
399typedef int SOCKET;
400
401#define closesocket(x) close(x)
402#define WSAGetLastError() (errno)
403
f0ce9811 404#define WSAEINTR EINTR
a7a0c5cc 405#define WSAEWOULDBLOCK EWOULDBLOCK
1743a67a 406#define WSAEINPROGRESS EINPROGRESS
a2069340 407#define WSAESHUTDOWN ESHUTDOWN
f0ce9811 408#define INVALID_SOCKET (-1)
076a55c4 409
c5a763cc
VK
410#define SetSocketReuseFlag(sd) { \
411 int nVal = 1; \
412 setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, (const void *)&nVal, \
413 (socklen_t)sizeof(nVal)); \
414}
be45f318 415
1ddf3f0c
VK
416#define SetSocketExclusiveAddrUse(s)
417
19121a38
VK
418#define SetSocketNonBlocking(s) { \
419 int f = fcntl(s, F_GETFL); \
420 if (f != -1) fcntl(s, F_SETFL, f | O_NONBLOCK); \
421}
422
4a36d30c
VK
423#define SetSocketNoDelay(s) { \
424 int val = 1; \
425 setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(int)); \
426}
427
a3c76aba
VK
428#define SELECT_NFDS(x) (x)
429
967893bb 430#else /* not _WIN32 or _NETWARE */
076a55c4
VK
431
432/*********** UNIX *********************/
cbcaf8c8 433
28c329e2
VK
434#ifndef PREFIX
435#define PREFIX "/usr/local"
273da39a 436#define PREFIXW L"/usr/local"
28c329e2
VK
437#warning Installation prefix not defined, defaulting to /usr/local
438#endif
439
3e39fcde
VK
440#if HAVE_WCHAR_H
441#include <wchar.h>
442#endif
3e39fcde 443
8b86c5dc
VK
444#if HAVE_WCTYPE_H
445#include <wctype.h>
446#endif
447
5bdbe3df
VK
448#include <errno.h>
449
636da5f3 450#define FS_PATH_SEPARATOR _T("/")
b07c50cc
VK
451#define FS_PATH_SEPARATOR_A "/"
452#define FS_PATH_SEPARATOR_W L"/"
636da5f3 453#define FS_PATH_SEPARATOR_CHAR _T('/')
f70fc197 454
e31784c0 455#if HAVE_UNISTD_H
62d8cc27 456#include <unistd.h>
e31784c0
VK
457#endif
458
459#if HAVE_STDLIB_H
62d8cc27 460#include <stdlib.h>
e31784c0
VK
461#endif
462
463#if HAVE_SYS_TYPES_H
7e679c4b 464#include <sys/types.h>
e31784c0
VK
465#endif
466
521d90e7
VK
467#if HAVE_SYS_INT_TYPES_H
468#include <sys/int_types.h>
469#endif
470
cc4c6659
VK
471#if HAVE_SYS_STAT_H
472#include <sys/stat.h>
473#endif
474
e31784c0 475#if HAVE_SYS_SOCKET_H
62d8cc27 476#include <sys/socket.h>
e31784c0
VK
477#endif
478
479#if HAVE_SYS_SELECT_H
62d8cc27 480#include <sys/select.h>
e31784c0
VK
481#endif
482
483#if HAVE_NETINET_IN_H
7e679c4b 484#include <netinet/in.h>
e31784c0
VK
485#endif
486
e9c8eb1d
VK
487#if HAVE_NETINET_TCP_H
488#include <netinet/tcp.h>
489#endif
490
ca6ad6bb
VK
491#if HAVE_NET_NH_H
492#include <net/nh.h>
493#endif
494
e31784c0 495#if HAVE_ARPA_INET_H
62d8cc27 496#include <arpa/inet.h>
e31784c0
VK
497#endif
498
499#if HAVE_NETDB_H
93e601e5 500#include <netdb.h>
e31784c0 501#endif
7e679c4b 502
cc4c6659 503#if HAVE_FCNTL_H
4507063f 504#include <fcntl.h>
cc4c6659
VK
505#endif
506
507#include <dirent.h>
d6a35a77 508
cd4c8ca3
VK
509#if _USE_GNU_PTH
510#include <pth.h>
511#endif
512
62d7e83d
VK
513#ifdef __sun
514#include <sys/atomic.h>
515#endif
516
3268bb77 517#if defined(__HP_aCC) && HAVE_ATOMIC_H
5a64ab96
VK
518#include <atomic.h>
519#endif
520
efdaffe4
VK
521#ifdef __IBMCPP__
522#include <builtins.h>
523#endif
524
eefe7d68 525typedef int BOOL;
678de2bc 526#if (SIZEOF_LONG == 4)
efdaffe4
VK
527#if (SIZEOF_INT == 4)
528typedef int INT32;
529typedef unsigned int UINT32;
530#else
967893bb
VK
531typedef long INT32;
532typedef unsigned long UINT32;
efdaffe4 533#endif
3c3d2729 534#undef __64BIT__
678de2bc 535#else
967893bb
VK
536typedef int INT32;
537typedef unsigned int UINT32;
3c3d2729
VK
538#ifndef __64BIT__
539#define __64BIT__
540#endif
678de2bc 541#endif
967893bb
VK
542typedef unsigned short UINT16;
543typedef short INT16;
cbcaf8c8 544typedef unsigned char BYTE;
967893bb 545typedef INT32 LONG; // for compatibility
50456b1f 546typedef UINT32 DWORD; // for compatibility
967893bb 547typedef UINT16 WORD; // for compatibility
cbcaf8c8 548typedef void * HANDLE;
3cf35ea6 549typedef void * HMODULE;
521d90e7 550
8b86c5dc
VK
551#if !HAVE_MODE_T
552typedef int mode_t;
553#endif
554
628013e1
VK
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__
561typedef long INT64;
562typedef unsigned long UINT64;
563#else
564typedef long long INT64;
565typedef unsigned long long UINT64;
566#endif
567
568#else /* _HPUX */
569
6e383343 570#if HAVE_LONG_LONG && (SIZEOF_LONG_LONG == 8)
51128b42
VK
571typedef long long INT64;
572#elif HAVE_INT64_T
7e679c4b 573typedef int64_t INT64;
6e383343
VK
574#elif SIZEOF_LONG == 8
575typedef long INT64;
521d90e7
VK
576#else
577#error Target system does not have signed 64bit integer type
578#endif
579
6e383343 580#if HAVE_UNSIGNED_LONG_LONG && (SIZEOF_LONG_LONG == 8)
967893bb 581typedef unsigned long long UINT64;
51128b42 582#elif HAVE_UINT64_T
967893bb 583typedef uint64_t UINT64;
521d90e7 584#elif HAVE_U_INT64_T
967893bb 585typedef u_int64_t UINT64;
6e383343
VK
586#elif SIZEOF_LONG == 8
587typedef unsigned long UINT64;
521d90e7
VK
588#else
589#error Target system does not have unsigned 64bit integer type
590#endif
628013e1
VK
591
592#endif /* _HPUX */
593
967893bb 594typedef UINT64 QWORD; // for compatibility
7e679c4b 595
8b1fedb2 596#define INT64_FMT _T("%lld")
dda7c270
VK
597#define INT64_FMTW L"%lld"
598#define INT64_FMTA "%lld"
8b1fedb2 599#define UINT64_FMT _T("%llu")
dda7c270
VK
600#define UINT64_FMTW L"%llu"
601#define UINT64_FMTA "%llu"
8b1fedb2 602#define UINT64X_FMT(m) _T("%") m _T("llX")
1094818a 603#ifdef __64BIT__
8b1fedb2 604#define TIME_T_FMT _T("%llu")
967893bb 605#define TIME_T_FCAST(x) ((UINT64)(x))
1094818a 606#else
8b1fedb2 607#define TIME_T_FMT _T("%u")
967893bb 608#define TIME_T_FCAST(x) ((UINT32)(x))
1094818a 609#endif
cbcaf8c8 610
cd4c8ca3 611#ifndef TRUE
cbcaf8c8 612#define TRUE 1
cd4c8ca3
VK
613#endif
614#ifndef FALSE
cbcaf8c8 615#define FALSE 0
cd4c8ca3 616#endif
cbcaf8c8 617
a5de3def 618#ifndef MAX_PATH
120bfcdf
VK
619#ifdef PATH_MAX
620#define MAX_PATH PATH_MAX
621#else
622#define MAX_PATH 1024
623#endif
a5de3def
VK
624#endif
625
77312b6f 626// Socket compatibility
7e679c4b
AK
627typedef int SOCKET;
628
62d8cc27 629#define closesocket(x) close(x)
77312b6f
VK
630#define WSAGetLastError() (errno)
631
f0ce9811 632#define WSAEINTR EINTR
a7a0c5cc 633#define WSAEWOULDBLOCK EWOULDBLOCK
1743a67a 634#define WSAEINPROGRESS EINPROGRESS
a2069340 635#define WSAESHUTDOWN ESHUTDOWN
f0ce9811 636#define INVALID_SOCKET (-1)
62d8cc27 637
be45f318
VK
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
1ddf3f0c
VK
644#define SetSocketExclusiveAddrUse(s)
645
19121a38
VK
646#define SetSocketNonBlocking(s) { \
647 int f = fcntl(s, F_GETFL); \
648 if (f != -1) fcntl(s, F_SETFL, f | O_NONBLOCK); \
649}
650
4a36d30c
VK
651#define SetSocketNoDelay(s) { \
652 int val = 1; \
653 setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (const void *)&val, sizeof(int)); \
654}
655
a3c76aba
VK
656#define SELECT_NFDS(x) (x)
657
cd4c8ca3 658#if !(HAVE_SOCKLEN_T) && !defined(_USE_GNU_PTH)
8ecf30ab 659typedef unsigned int socklen_t;
3c2bbe5f
VK
660#endif
661
17d715ba 662// Shared library suffix
2b479c92 663#ifndef SHLIB_SUFFIX
17d715ba 664#if defined(_HPUX) && !defined(__64BIT__)
2b479c92 665#define SHLIB_SUFFIX _T(".sl")
17d715ba 666#else
2b479c92 667#define SHLIB_SUFFIX _T(".so")
17d715ba
VK
668#endif
669#endif
670
4383fcad
AK
671typedef struct hostent HOSTENT;
672
ce7565e7
VK
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
8d9f0998
VK
678#endif /* _WIN32 */
679
90d8fac8
VK
680/**
681 * Value used to indicate invalid pointer where NULL is not appropriate
682 */
a731ec52
VK
683#ifdef __64BIT__
684#define INVALID_POINTER_VALUE ((void *)_ULL(0xFFFFFFFFFFFFFFFF))
685#else
686#define INVALID_POINTER_VALUE ((void *)0xFFFFFFFF)
687#endif
688
90d8fac8
VK
689/**
690 * Casting between pointer and 32-bit integer
691 */
c88a8bc1 692#ifdef __64BIT__
967893bb
VK
693#define CAST_FROM_POINTER(p, t) ((t)((UINT64)(p)))
694#define CAST_TO_POINTER(v, t) ((t)((UINT64)(v)))
c88a8bc1 695#else
a23d8e0d
VK
696#define CAST_FROM_POINTER(p, t) ((t)(p))
697#define CAST_TO_POINTER(v, t) ((t)(v))
c88a8bc1
VK
698#endif
699
bde67a1f
VK
700/**
701 * OpenSSL
702 */
630d33da 703#if defined(_WITH_ENCRYPTION) && !defined(ORA_PROC)
15cf5acc
VK
704
705#include <openssl/crypto.h>
706#include <openssl/rsa.h>
707#include <openssl/pem.h>
e44ac467
VK
708#include <openssl/evp.h>
709#include <openssl/rand.h>
2d66c588 710#include <openssl/opensslv.h>
1f4cd940 711#include <openssl/err.h>
e44ac467 712
237cb1fe
VK
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
2d66c588
VK
737#if OPENSSL_VERSION_NUMBER >= 0x00907000
738#define OPENSSL_CONST const
739#else
740#define OPENSSL_CONST
741#endif
742
e44ac467
VK
743#else
744
745// Prevent compilation errors on function prototypes
746#define RSA void
15cf5acc
VK
747
748#endif
749
bde67a1f
VK
750/**
751 * open() flags compatibility
752 */
8d9f0998
VK
753#ifndef O_BINARY
754#define O_BINARY 0
cbcaf8c8
VK
755#endif
756
bde67a1f
VK
757/**
758 * Windows-specific structures for non-Windows platforms
759 */
1d410d50
VK
760#ifndef _WIN32
761
762typedef struct tagPOINT
763{
764 int x;
765 int y;
766} POINT;
767
768#endif
769
bde67a1f
VK
770/**
771 * Event log severity codes
772 */
9c02b362 773#ifndef _WIN32
ccc34207
VK
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
9c02b362
VK
780#endif /* _WIN32 */
781
203e9d8a
VK
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
bde67a1f
VK
787/**
788 * Interface types
789 */
020559de
VK
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
840a1a6a 1062
674164eb
VK
1063/**
1064 * IP Header -- RFC 791
1065 */
798f373a
VK
1066typedef 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
674164eb
VK
1080/**
1081 * ICMP Header - RFC 792
1082 */
798f373a
VK
1083typedef 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
798f373a
VK
1090} ICMPHDR;
1091
674164eb
VK
1092/**
1093 * INADDR_NONE can be undefined on some systems
1094 */
696fc54f
VK
1095#ifndef INADDR_NONE
1096#define INADDR_NONE (0xFFFFFFFF)
1097#endif
1098
674164eb
VK
1099/**
1100 * Check if IP address is a broadcast
1101 */
c8b1f788
VK
1102#define IsBroadcastAddress(addr, mask) (((addr) & (~(mask))) == (~(mask)))
1103
674164eb
VK
1104/**
1105 * Check if given string is NULL and always return valid pointer
1106 */
7da71731
VK
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))
ef44d5ea 1111
674164eb
VK
1112/**
1113 * Free memory block if it isn't NULL
1114 */
b6a77d6d 1115#define safe_free(x) { if ((x) != NULL) free(x); }
de2c1214 1116#define safe_free_and_null(x) { if ((x) != NULL) { free(x); x = NULL; } }
b6a77d6d 1117
674164eb
VK
1118/**
1119 * delete object and nullify pointer
1120 */
cd890184
VK
1121#define delete_and_null(x) { delete x; x = NULL; }
1122
674164eb
VK
1123/**
1124 * Convert half-byte's value to hex digit and vice versa
1125 */
4075c782
VK
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
93b18807
VK
1131#define hex2bin(x) ((((x) >= '0') && ((x) <= '9')) ? ((x) - '0') : \
1132 (((toupper(x) >= 'A') && (toupper(x) <= 'F')) ? (toupper(x) - 'A' + 10) : 0))
4075c782 1133#endif
fe49ce0b 1134
674164eb
VK
1135/**
1136 * Define min() and max() if needed
1137 */
7e679c4b 1138#ifndef min
8ec5c2c1 1139#define min(a, b) ((a) < (b) ? (a) : (b))
7e679c4b 1140#endif
53c17a96 1141#ifndef max
8ec5c2c1 1142#define max(a, b) ((a) > (b) ? (a) : (b))
53c17a96 1143#endif
7e679c4b 1144
674164eb
VK
1145/**
1146 * Define _tcsicmp() for non-windows
1147 */
daf35c51 1148#ifndef _WIN32
90ce1516
VK
1149#define stricmp strcasecmp
1150#define strnicmp strncasecmp
8b86c5dc
VK
1151#define wcsicmp wcscasecmp
1152#define wcsnicmp wcsncasecmp
daf35c51
VK
1153#endif
1154
674164eb
VK
1155/**
1156 * Compare two numbers and return -1, 0, or 1
1157 */
4c7a83e5
VK
1158#define COMPARE_NUMBERS(n1,n2) (((n1) < (n2)) ? -1 : (((n1) > (n2)) ? 1 : 0))
1159
674164eb
VK
1160/**
1161 * Increment pointer for given number of bytes
1162 */
9f20696e
VK
1163#define inc_ptr(ptr, step, ptype) ptr = (ptype *)(((char *)ptr) + step)
1164
674164eb
VK
1165/**
1166 * Validate numerical value
1167 */
52996299
VK
1168#define VALIDATE_VALUE(var,x,y,z) { if ((var < x) || (var > y)) var = z; }
1169
674164eb
VK
1170/**
1171 * DCI (data collection item) data types
1172 */
a72a1fb1
VK
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
20aaa307 1179#define DCI_DT_NULL 6
8f9299d1 1180#define DCI_DT_DEPRECATED 255 /* used internally by agent */
a72a1fb1 1181
674164eb
VK
1182/**
1183 * Insert parameter as string
1184 */
9493e563
VK
1185#ifdef UNICODE
1186#define STRING(x) L#x
1187#else
1188#define STRING(x) #x
1189#endif
1190
674164eb
VK
1191/**
1192 * Memory debug
1193 */
d8ca9c03
VK
1194#ifdef NETXMS_MEMORY_DEBUG
1195
1196#ifdef __cplusplus
1197extern "C" {
1198#endif
1199
1200void *nx_malloc(size_t, char *, int);
1201void *nx_realloc(void *, size_t, char *, int);
1202void nx_free(void *, char *, int);
1203
1204void InitMemoryDebugger(void);
1205void 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
cbcaf8c8 1217#endif /* _nms_common_h_ */