added macro DISABLE_COPY_CTOR; minor refactoring
[public/netxms.git] / include / nms_common.h
CommitLineData
08f16c05 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
b40371d4 32#if !defined(_WIN32) && !defined(UNDER_CE)
e647245b 33
f62b7eab 34#include <config.h>
9c3bf7f4 35#if defined(WITH_OPENSSL) || defined(WITH_COMMONCRYPTO)
779c2678
VK
36#define _WITH_ENCRYPTION 1
37#endif
e647245b 38
15cf5acc 39#else /* _WIN32 */
e647245b 40
2c12edfc 41#ifndef UNDER_CE
15cf5acc 42#define _WITH_ENCRYPTION 1
3c15eedb 43#define WITH_OPENSSL 1
6c352bb5 44#define WITH_LDAP 1
f00612ba 45#if !defined(WINDOWS_ONLY) && !defined(_CRT_SECURE_NO_DEPRECATE)
be460d82 46#define _CRT_SECURE_NO_DEPRECATE
2c12edfc 47#endif
f00612ba 48#endif
e647245b 49
879855b3
VK
50// prevent defining min and max macros in Windows headers
51#ifndef NOMINMAX
52#define NOMINMAX
53#endif
54
f5fb7a0f
VK
55// prevent defining ETIMEDOUT, ECONNRESET, etc. to wrong values
56#define _CRT_NO_POSIX_ERROR_CODES
57
82b4c558 58#endif /* _WIN32 */
e647245b 59
f92a016a
VK
60#if HAVE_JEMALLOC_JEMALLOC_H
61#include <jemalloc/jemalloc.h>
62#endif
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
5a82ecc7 76#if HAVE_WIDEC_H
5c0258d5 77#include <widec.h>
82b4c558 78#endif /* HAVE_WIDEC */
9068a8c6 79
bde67a1f
VK
80/**
81 * Define __64BIT__ if compiling for 64bit platform with Visual C++
82 */
c3561262 83#if defined(_M_X64) || defined(_M_IA64) || defined(__LP64__) || defined(__PPC64__) || defined(__x86_64__)
a731ec52
VK
84#ifndef __64BIT__
85#define __64BIT__
86#endif
87#endif
88
0cdf79a3
VK
89/**
90 * Wrappers for 64-bit integer constants
91 */
3a5657b9 92#if defined(__GNUC__) || defined(__HP_aCC) || defined(__IBMC__) || defined(__IBMCPP__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)
c61f5190
VK
93#define _LL(x) (x ## LL)
94#define _ULL(x) (x ## ULL)
7946bd7c
VK
95#elif defined(_MSC_VER)
96#define _LL(x) (x ## i64)
97#define _ULL(x) (x ## ui64)
c61f5190
VK
98#else
99#define _LL(x) (x)
100#define _ULL(x) (x)
101#endif
102
480e036b
VK
103/**
104 * Common constants
105 */
fb52d37d 106#define MAX_SECRET_LENGTH 64
a7d07192 107#define MAX_DB_STRING 256
999812c7 108#define MAX_PARAM_NAME 256
2589cc10 109#define MAX_CONFIG_VALUE 2000
cc8ce218 110#define MAX_COLUMN_NAME 64
5ad2167d 111#define MAX_DNS_NAME 256
d41268ba 112#define MAX_HELPDESK_REF_LEN 64
f33d5471 113#define MAX_PASSWORD 256
241541f4
VK
114#define MAX_SSH_LOGIN_LEN 64
115#define MAX_SSH_PASSWORD_LEN 64
967893bb 116#define GROUP_FLAG ((UINT32)0x80000000)
e44ac467 117
d772d0dd 118#define NETXMS_MAX_CIPHERS 6
15cf5acc 119#define NETXMS_RSA_KEYLEN 2048
fb52d37d 120
b50f1100 121#ifndef LLONG_MAX
c61f5190 122#define LLONG_MAX _LL(9223372036854775807)
b50f1100
VK
123#endif
124
125#ifndef LLONG_MIN
126#define LLONG_MIN (-LLONG_MAX - 1)
127#endif
128
129#ifndef ULLONG_MAX
c61f5190 130#define ULLONG_MAX _ULL(18446744073709551615)
b50f1100
VK
131#endif
132
05f256fe 133#ifndef EVENTLOG_DEBUG_TYPE
ccc34207
VK
134#define EVENTLOG_DEBUG_TYPE 0x0080
135#endif
136
e647245b
VK
137#define INVALID_INDEX 0xFFFFFFFF
138#define MD5_DIGEST_SIZE 16
139#define SHA1_DIGEST_SIZE 20
1718cc2a 140#define SHA256_DIGEST_SIZE 32
e647245b 141
9fa031cd 142#define FILE_BUFFER_SIZE 32768
143
664b42a4
VK
144/**
145 * Compatibility defines for C sources
146 */
07a7e06b 147#if !defined(__cplusplus) && !defined(CORTEX) && !HAVE_BOOL
ccc34207 148typedef int bool;
05f256fe
VK
149#endif
150
bde67a1f
VK
151/**
152 * Oracle Pro*C compatibility
153 */
909c0624 154#ifdef ORA_PROC
bde67a1f 155#undef BYTE
50456b1f 156#undef DWORD
bde67a1f
VK
157#endif
158
1de39d9e
VK
159/**
160 * Java class path separator character
161 */
162#ifdef _WIN32
163#define JAVA_CLASSPATH_SEPARATOR _T(';')
164#else
165#define JAVA_CLASSPATH_SEPARATOR _T(':')
166#endif
167
fb52d37d 168
bde67a1f 169/***** Platform dependent includes and defines *****/
fb52d37d 170
018fda4d 171#if defined(_WIN32) || defined(UNDER_CE)
076a55c4
VK
172
173/********** WINDOWS ********************/
e9246d26 174
96772780
VK
175#ifdef _MSC_FULL_VER
176#define __BUILD_VERSION_STRING(s,v) s v
177#define __STR_NX(x) #x
178#define __STR(x) __STR_NX(x)
179#define CPP_COMPILER_VERSION __STR(__BUILD_VERSION_STRING(Microsoft C/C++ Optimizing Compiler Version,_MSC_FULL_VER))
180#endif
181
f5fb7a0f
VK
182// Disable some warnings:
183// 4577 - 'noexcept' used with no exception handling mode specified
184#pragma warning(disable: 4577)
185
e17fe9ab 186#ifndef _WIN32_WINNT
e4590ef2 187#define _WIN32_WINNT 0x0501
e17fe9ab 188#endif
f33479c8 189
36e44abe
VK
190#define WITH_IPV6 1
191
807c0ccc 192#define USE_BUNDLED_LIBTRE 1
df9812a9 193#define USE_BUNDLED_GETOPT 1
807c0ccc 194
3bf0df9f
VK
195#define SAFE_FGETWS_WITH_POPEN 1
196
c6491611 197#define FS_PATH_SEPARATOR _T("\\")
b07c50cc
VK
198#define FS_PATH_SEPARATOR_A "\\"
199#define FS_PATH_SEPARATOR_W L"\\"
c6491611
VK
200#define FS_PATH_SEPARATOR_CHAR _T('\\')
201
b79e8fed
VK
202#define WEXITSTATUS(x) (x)
203
a9bad162 204#if _MSC_VER >= 1310
c6491611
VK
205#define HAVE_SCPRINTF 1
206#define HAVE_VSCPRINTF 1
207#define HAVE_SCWPRINTF 1
208#define HAVE_VSCWPRINTF 1
2385d5d0 209#endif
f70fc197 210
a9bad162
VK
211#if _MSC_VER >= 1800
212#define HAVE_STRTOLL 1
213#define HAVE_STRTOULL 1
214#define HAVE_WCSTOLL 1
215#define HAVE_WCSTOULL 1
216#endif
217
342a701d
VK
218#define HAVE_SNPRINTF 1
219#define HAVE_VSNPRINTF 1
220
ecdf8898
VK
221#define HAVE_GETADDRINFO 1
222
d63aad11
VK
223#define HAVE_STDARG_H 1
224
8d4bb054
VK
225#define HAVE_ALLOCA 1
226
7768852d
VK
227#define HAVE_WCSLEN 1
228#define HAVE_WCSNCPY 1
669fcb92 229#define HAVE_WCSDUP 1
7b45b90d 230#define HAVE_WUTIME 1
7768852d 231
74540dab
VK
232#define HAVE_LIBCURL 1
233
c7850580
VK
234#define HAVE_DIRENT_D_TYPE 1
235
9caddb3c 236#include <winsock2.h>
510dd9c4 237#include <windows.h>
36e44abe 238#include <ws2tcpip.h>
d454fb4c 239#include <stdlib.h>
1ddf3f0c 240#include <malloc.h>
1dd2715c 241
a9bad162
VK
242#include <stdarg.h>
243#ifndef va_copy
244#define va_copy(x,y) (x = y)
245#endif
246#define HAVE_DECL_VA_COPY 1
247
018fda4d 248#ifndef UNDER_CE
a8d4cdee 249#include <sys/stat.h>
7b45b90d 250#include <sys/utime.h>
a8d4cdee 251#include <process.h>
1dd2715c 252#include <io.h>
3d1cb7d6 253#include <fcntl.h>
a23d8e0d 254#include <direct.h>
018fda4d 255#endif
91ab8f0a 256
37d62364
AK
257#ifndef S_IRUSR
258# define S_IRUSR 0400
259#endif
260#ifndef S_IWUSR
261# define S_IWUSR 0200
262#endif
1dd2715c 263
34576b56
VK
264#define snprintf _snprintf
265#define vsnprintf _vsnprintf
f83a0c3a
VK
266#define snwprintf _snwprintf
267#define vsnwprintf _vsnwprintf
c6491611
VK
268#define scprintf _scprintf
269#define vscprintf _vscprintf
270#define scwprintf _scwprintf
271#define vscwprintf _vscwprintf
34576b56
VK
272#define popen _popen
273#define pclose _pclose
34576b56
VK
274#define stricmp _stricmp
275#define strnicmp _strnicmp
c90ea787
VK
276#define wcsicmp _wcsicmp
277#define wcsnicmp _wcsnicmp
3da622d4 278#define strlwr(s) _strlwr(s)
34576b56 279#define strupr(s) _strupr(s)
70af47c2 280#define putenv(s) _putenv(s)
34576b56
VK
281#define fileno(f) _fileno(f)
282#define chdir(p) _chdir(p)
283#define mkdir(p,m) _mkdir(p,m)
ccc34207 284#define lseek(f,o,w) _lseek(f,o,w)
34576b56 285#define unlink(x) _unlink(x)
d4c266b6 286
967893bb 287typedef UINT64 QWORD; // for compatibility
670c7f3d 288typedef int socklen_t;
1edb2dab 289typedef long pid_t;
734e79a8
VK
290typedef LONG ssize_t;
291
292typedef signed __int8 int8_t;
293typedef signed __int16 int16_t;
294typedef signed __int32 int32_t;
295typedef signed __int64 int64_t;
296typedef unsigned __int8 uint8_t;
297typedef unsigned __int16 uint16_t;
298typedef unsigned __int32 uint32_t;
08f16c05 299typedef unsigned __int64 uint64_t;
e9246d26 300
8b1fedb2 301#define INT64_FMT _T("%I64d")
dda7c270 302#define INT64_FMTA "%I64d"
511bea22 303#define INT64_FMTW L"%I64d"
8b1fedb2 304#define UINT64_FMT _T("%I64u")
dda7c270 305#define UINT64_FMTA "%I64u"
511bea22 306#define UINT64_FMTW L"%I64u"
8b1fedb2 307#define UINT64X_FMT(m) _T("%") m _T("I64X")
0b514e86 308#if defined(__64BIT__) || (_MSC_VER > 1300)
34576b56 309#define TIME_T_FMT _T("%I64u")
967893bb 310#define TIME_T_FCAST(x) ((UINT64)(x))
1094818a 311#else
34576b56 312#define TIME_T_FMT _T("%u")
967893bb 313#define TIME_T_FCAST(x) ((UINT32)(x))
1094818a 314#endif
cb53cb15 315
64a055a2
VK
316#ifndef __clang__
317
3c15eedb
VK
318#define HAVE_DECL_BSWAP_16 1
319#define HAVE_DECL_BSWAP_32 1
320#define HAVE_DECL_BSWAP_64 1
321
98a314d9
VK
322#define bswap_16(n) _byteswap_ushort(n)
323#define bswap_32(n) _byteswap_ulong(n)
324#define bswap_64(n) _byteswap_uint64(n)
3c15eedb 325
64a055a2
VK
326#endif
327
8f7e2482
VK
328// Socket compatibility
329#define SHUT_RD 0
330#define SHUT_WR 1
331#define SHUT_RDWR 2
332
1ddf3f0c
VK
333#define SetSocketReuseFlag(s) { \
334 BOOL val = TRUE; \
335 setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(BOOL)); \
336}
337#define SetSocketExclusiveAddrUse(s) { \
338 BOOL val = TRUE; \
339 setsockopt(s, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (char *)&val, sizeof(BOOL)); \
340}
a3c76aba 341#define SELECT_NFDS(x) ((int)(x))
19121a38
VK
342#define SetSocketNonBlocking(s) { \
343 u_long one = 1; \
344 ioctlsocket(s, FIONBIO, &one); \
345}
734e79a8
VK
346#define SetSocketBlocking(s) { \
347 u_long zero = 0; \
348 ioctlsocket(s, FIONBIO, &zero); \
349}
4a36d30c
VK
350#define SetSocketNoDelay(s) { \
351 BOOL val = TRUE; \
352 setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(BOOL)); \
353}
08f16c05 354#define SetSocketBroadcast(s) { \
355 BOOL val = TRUE; \
356 setsockopt(s, SOL_SOCKET, SO_BROADCAST, (char *)&val, sizeof(BOOL)); \
357}
be45f318 358
55b33d4c
VK
359#ifdef UNDER_CE
360#define O_RDONLY 0x0004
361#define O_WRONLY 0x0001
362#define O_RDWR 0x0002
363#define O_CREAT 0x0100
364#define O_EXCL 0x0200
365#define O_TRUNC 0x0800
366#endif
367
3973f74b 368#if !defined(UNDER_CE)
c1099678 369#define HAVE_LIBEXPAT 1
1bb6b449
VK
370#endif
371
058bf6fc
VK
372#define XMPP_SUPPORTED 1
373
c1099678
VK
374#define HAVE_LOCALE_H 1
375#define HAVE_SETLOCALE 1
376
8ff13508
VK
377// Use Win32 API instead of msvcrt for memory allocation
378#ifdef USE_WIN32_HEAP
379
380#define malloc(n) HeapAlloc(GetProcessHeap(), 0, n)
381#define realloc(p, n) (((p) == NULL) ? HeapAlloc(GetProcessHeap(), 0, n) : HeapReAlloc(GetProcessHeap(), 0, p, n))
382#define free(p) HeapFree(GetProcessHeap(), 0, p)
a65409fe 383#define _tcsdup(s) nx__tcsdup(s)
8ff13508
VK
384#define wcsdup(s) nx_wcsdup(s)
385
386#undef _tcsdup
387#ifdef UNICODE
388#define _tcsdup nx_wcsdup
389#else
390#define _tcsdup nx_strdup
391#endif
392
393#else
394
395#define strdup _strdup
396#define wcsdup _wcsdup
397
398#endif
399
82b4c558 400#else /* not _WIN32 */
076a55c4
VK
401
402/*********** UNIX *********************/
cbcaf8c8 403
28c329e2 404#ifndef PREFIX
124528cc
VK
405#ifdef UNICODE
406#define PREFIX L"/usr/local"
407#else
28c329e2 408#define PREFIX "/usr/local"
124528cc 409#endif
28c329e2
VK
410#warning Installation prefix not defined, defaulting to /usr/local
411#endif
412
5456cd6d
VK
413#if HAVE_STDBOOL_H
414#include <stdbool.h>
415#endif
416
ccfe2ba0
VK
417#if HAVE_ALLOCA_H
418#include <alloca.h>
419#endif
420
3e39fcde
VK
421#if HAVE_WCHAR_H
422#include <wchar.h>
423#endif
3e39fcde 424
8b86c5dc
VK
425#if HAVE_WCTYPE_H
426#include <wctype.h>
427#endif
428
e2e3ce85
VK
429// Fix for wcs* functions visibility in Solaris 11
430#if defined(__sun) && (__cplusplus >= 199711L)
431#if HAVE_WCSDUP
432using std::wcsdup;
433#endif
434#if HAVE_WCSCASECMP
435using std::wcscasecmp;
436#endif
437#if HAVE_WCSNCASECMP
438using std::wcsncasecmp;
439#endif
440#endif
441
5bdbe3df
VK
442#include <errno.h>
443
636da5f3 444#define FS_PATH_SEPARATOR _T("/")
b07c50cc
VK
445#define FS_PATH_SEPARATOR_A "/"
446#define FS_PATH_SEPARATOR_W L"/"
636da5f3 447#define FS_PATH_SEPARATOR_CHAR _T('/')
f70fc197 448
e31784c0 449#if HAVE_UNISTD_H
62d8cc27 450#include <unistd.h>
e31784c0
VK
451#endif
452
453#if HAVE_STDLIB_H
62d8cc27 454#include <stdlib.h>
e31784c0
VK
455#endif
456
457#if HAVE_SYS_TYPES_H
7e679c4b 458#include <sys/types.h>
e31784c0
VK
459#endif
460
7b45b90d 461#if HAVE_UTIME_H
462#include <utime.h>
463#endif
464
521d90e7
VK
465#if HAVE_SYS_INT_TYPES_H
466#include <sys/int_types.h>
467#endif
468
cc4c6659
VK
469#if HAVE_SYS_STAT_H
470#include <sys/stat.h>
471#endif
472
e31784c0 473#if HAVE_SYS_SOCKET_H
62d8cc27 474#include <sys/socket.h>
e31784c0
VK
475#endif
476
477#if HAVE_SYS_SELECT_H
62d8cc27 478#include <sys/select.h>
e31784c0
VK
479#endif
480
481#if HAVE_NETINET_IN_H
7e679c4b 482#include <netinet/in.h>
e31784c0
VK
483#endif
484
e9c8eb1d
VK
485#if HAVE_NETINET_TCP_H
486#include <netinet/tcp.h>
487#endif
488
ca6ad6bb
VK
489#if HAVE_NET_NH_H
490#include <net/nh.h>
491#endif
492
e31784c0 493#if HAVE_ARPA_INET_H
62d8cc27 494#include <arpa/inet.h>
e31784c0
VK
495#endif
496
497#if HAVE_NETDB_H
93e601e5 498#include <netdb.h>
e31784c0 499#endif
7e679c4b 500
cc4c6659 501#if HAVE_FCNTL_H
4507063f 502#include <fcntl.h>
cc4c6659
VK
503#endif
504
505#include <dirent.h>
d6a35a77 506
cd4c8ca3
VK
507#if _USE_GNU_PTH
508#include <pth.h>
0c78603d
VK
509#else
510#include <pthread.h>
cd4c8ca3
VK
511#endif
512
efdaffe4
VK
513#ifdef __IBMCPP__
514#include <builtins.h>
515#endif
516
ef8a3c32
VK
517#ifdef __minix
518#undef HAVE_ITOA /* Minix has non-compatible itoa() */
519#undef HAVE_GETHOSTBYNAME2_R
520#endif
521
0f8cd7ae
VK
522#include <sys/socket.h>
523#include <sys/un.h>
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
efc49272
VK
618// Some systems may define true and false which may break overloaded functions
619#ifdef __cplusplus
620#undef true
621#undef false
622#endif
623
a5de3def 624#ifndef MAX_PATH
120bfcdf
VK
625#ifdef PATH_MAX
626#define MAX_PATH PATH_MAX
627#else
628#define MAX_PATH 1024
629#endif
a5de3def
VK
630#endif
631
c90ea787
VK
632// Windows compatibility layer for standard C I/O functions
633#ifdef __cplusplus
634
635inline int _access(const char *pathname, int mode) { return ::access(pathname, mode); }
636inline int _open(const char *pathname, int flags) { return ::open(pathname, flags); }
637inline int _open(const char *pathname, int flags, mode_t mode) { return ::open(pathname, flags, mode); }
638inline ssize_t _read(int fd, void *buf, size_t count) { return ::read(fd, buf, count); }
639inline ssize_t _write(int fd, const void *buf, size_t count) { return ::write(fd, buf, count); }
640inline int _close(int fd) { return ::close(fd); }
641
642#else
643
644#define _access(p, m) access((p), (m))
ee088bd0
VK
645#define _open open
646#define _close(f) close(f)
647#define _read(f, b, l) read((f), (b), (l))
c90ea787
VK
648#define _write(f, b, l) write((f), (b), (l))
649#define _close(f) close(f)
650
651#endif
ee088bd0 652
77312b6f 653// Socket compatibility
7e679c4b
AK
654typedef int SOCKET;
655
eae56922 656#define closesocket(x) _close(x)
77312b6f
VK
657#define WSAGetLastError() (errno)
658
f0ce9811 659#define WSAEINTR EINTR
a7a0c5cc 660#define WSAEWOULDBLOCK EWOULDBLOCK
1743a67a 661#define WSAEINPROGRESS EINPROGRESS
a2069340 662#define WSAESHUTDOWN ESHUTDOWN
f0ce9811 663#define INVALID_SOCKET (-1)
62d8cc27 664
be45f318
VK
665#define SetSocketReuseFlag(sd) { \
666 int nVal = 1; \
667 setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, (const void *)&nVal, \
668 (socklen_t)sizeof(nVal)); \
669}
670
1ddf3f0c
VK
671#define SetSocketExclusiveAddrUse(s)
672
19121a38
VK
673#define SetSocketNonBlocking(s) { \
674 int f = fcntl(s, F_GETFL); \
675 if (f != -1) fcntl(s, F_SETFL, f | O_NONBLOCK); \
676}
677
4a36d30c
VK
678#define SetSocketNoDelay(s) { \
679 int val = 1; \
680 setsockopt(s, IPPROTO_TCP, TCP_NODELAY, (const void *)&val, sizeof(int)); \
681}
682
08f16c05 683#define SetSocketBroadcast(s) { \
684 int val = 1; \
685 setsockopt(s, SOL_SOCKET, SO_BROADCAST, (const void *)&val, sizeof(int)); \
686}
687
a3c76aba
VK
688#define SELECT_NFDS(x) (x)
689
cd4c8ca3 690#if !(HAVE_SOCKLEN_T) && !defined(_USE_GNU_PTH)
8ecf30ab 691typedef unsigned int socklen_t;
3c2bbe5f
VK
692#endif
693
0f8cd7ae
VK
694#ifndef SUN_LEN
695#define SUN_LEN(su) (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path))
696#endif
697
17d715ba 698// Shared library suffix
2b479c92 699#ifndef SHLIB_SUFFIX
17d715ba 700#if defined(_HPUX) && !defined(__64BIT__)
2b479c92 701#define SHLIB_SUFFIX _T(".sl")
17d715ba 702#else
2b479c92 703#define SHLIB_SUFFIX _T(".so")
17d715ba
VK
704#endif
705#endif
706
4383fcad
AK
707typedef struct hostent HOSTENT;
708
ce7565e7
VK
709#if HAVE_DECL___VA_COPY && !HAVE_DECL_VA_COPY
710#define HAVE_DECL_VA_COPY 1
711#define va_copy(d,s) __va_copy(d,s)
712#endif
713
8d9f0998
VK
714#endif /* _WIN32 */
715
90d8fac8
VK
716/**
717 * Value used to indicate invalid pointer where NULL is not appropriate
718 */
a731ec52
VK
719#ifdef __64BIT__
720#define INVALID_POINTER_VALUE ((void *)_ULL(0xFFFFFFFFFFFFFFFF))
721#else
722#define INVALID_POINTER_VALUE ((void *)0xFFFFFFFF)
723#endif
724
90d8fac8
VK
725/**
726 * Casting between pointer and 32-bit integer
727 */
c88a8bc1 728#ifdef __64BIT__
967893bb
VK
729#define CAST_FROM_POINTER(p, t) ((t)((UINT64)(p)))
730#define CAST_TO_POINTER(v, t) ((t)((UINT64)(v)))
c88a8bc1 731#else
a23d8e0d
VK
732#define CAST_FROM_POINTER(p, t) ((t)(p))
733#define CAST_TO_POINTER(v, t) ((t)(v))
c88a8bc1
VK
734#endif
735
bde67a1f 736/**
bde67a1f
VK
737 * open() flags compatibility
738 */
8d9f0998
VK
739#ifndef O_BINARY
740#define O_BINARY 0
cbcaf8c8
VK
741#endif
742
bde67a1f
VK
743/**
744 * Windows-specific structures for non-Windows platforms
08f16c05 745 */
1d410d50
VK
746#ifndef _WIN32
747
748typedef struct tagPOINT
749{
750 int x;
751 int y;
752} POINT;
753
754#endif
755
bde67a1f
VK
756/**
757 * Event log severity codes
758 */
9c02b362 759#ifndef _WIN32
ccc34207
VK
760#define EVENTLOG_SUCCESS 0x0000
761#define EVENTLOG_ERROR_TYPE 0x0001
762#define EVENTLOG_WARNING_TYPE 0x0002
763#define EVENTLOG_INFORMATION_TYPE 0x0004
764#define EVENTLOG_AUDIT_SUCCESS 0x0008
765#define EVENTLOG_AUDIT_FAILURE 0x0010
9c02b362
VK
766#endif /* _WIN32 */
767
203e9d8a
VK
768#define NXLOG_DEBUG EVENTLOG_DEBUG_TYPE
769#define NXLOG_INFO EVENTLOG_INFORMATION_TYPE
770#define NXLOG_WARNING EVENTLOG_WARNING_TYPE
771#define NXLOG_ERROR EVENTLOG_ERROR_TYPE
772
bde67a1f
VK
773/**
774 * Interface types
775 */
020559de
VK
776#define IFTYPE_OTHER 1
777#define IFTYPE_REGULAR1822 2
778#define IFTYPE_HDH1822 3
779#define IFTYPE_DDN_X25 4
780#define IFTYPE_RFC877_X25 5
781#define IFTYPE_ETHERNET_CSMACD 6
782#define IFTYPE_ISO88023_CSMACD 7
783#define IFTYPE_ISO88024_TOKENBUS 8
784#define IFTYPE_ISO88025_TOKENRING 9
785#define IFTYPE_ISO88026_MAN 10
786#define IFTYPE_STARLAN 11
787#define IFTYPE_PROTEON_10MBIT 12
788#define IFTYPE_PROTEON_80MBIT 13
789#define IFTYPE_HYPERCHANNEL 14
790#define IFTYPE_FDDI 15
791#define IFTYPE_LAPB 16
792#define IFTYPE_SDLC 17
793#define IFTYPE_DS1 18
794#define IFTYPE_E1 19
795#define IFTYPE_BASIC_ISDN 20
796#define IFTYPE_PRIMARY_ISDN 21
797#define IFTYPE_PROP_PTP_SERIAL 22
798#define IFTYPE_PPP 23
799#define IFTYPE_SOFTWARE_LOOPBACK 24
800#define IFTYPE_EON 25
801#define IFTYPE_ETHERNET_3MBIT 26
802#define IFTYPE_NSIP 27
803#define IFTYPE_SLIP 28
804#define IFTYPE_ULTRA 29
805#define IFTYPE_DS3 30
806#define IFTYPE_SMDS 31
807#define IFTYPE_FRAME_RELAY 32
808#define IFTYPE_RS232 33
809#define IFTYPE_PARA 34
810#define IFTYPE_ARCNET 35
811#define IFTYPE_ARCNET_PLUS 36
812#define IFTYPE_ATM 37
813#define IFTYPE_MIOX25 38
814#define IFTYPE_SONET 39
815#define IFTYPE_X25PLE 40
816#define IFTYPE_ISO88022LLC 41
817#define IFTYPE_LOCALTALK 42
818#define IFTYPE_SMDS_DXI 43
819#define IFTYPE_FRAME_RELAY_SERVICE 44
820#define IFTYPE_V35 45
821#define IFTYPE_HSSI 46
822#define IFTYPE_HIPPI 47
823#define IFTYPE_MODEM 48
824#define IFTYPE_AAL5 49
825#define IFTYPE_SONET_PATH 50
826#define IFTYPE_SONET_VT 51
827#define IFTYPE_SMDS_ICIP 52
828#define IFTYPE_PROP_VIRTUAL 53
829#define IFTYPE_PROP_MULTIPLEXOR 54
830#define IFTYPE_IEEE80212 55
831#define IFTYPE_FIBRECHANNEL 56
832#define IFTYPE_HIPPIINTERFACE 57
833#define IFTYPE_FRAME_RELAY_INTERCONNECT 58
834#define IFTYPE_AFLANE8023 59
835#define IFTYPE_AFLANE8025 60
836#define IFTYPE_CCTEMUL 61
837#define IFTYPE_FAST_ETHERNET 62
838#define IFTYPE_ISDN 63
839#define IFTYPE_V11 64
840#define IFTYPE_V36 65
841#define IFTYPE_G703_AT64K 66
842#define IFTYPE_G703_AT2MB 67
843#define IFTYPE_QLLC 68
844#define IFTYPE_FASTETHERFX 69
845#define IFTYPE_CHANNEL 70
846#define IFTYPE_IEEE80211 71
847#define IFTYPE_IBM370_PARCHAN 72
848#define IFTYPE_ESCON 73
849#define IFTYPE_DLSW 74
850#define IFTYPE_ISDNS 75
851#define IFTYPE_ISDNU 76
852#define IFTYPE_LAPD 77
853#define IFTYPE_IPSWITCH 78
854#define IFTYPE_RSRB 79
855#define IFTYPE_ATMLOGICAL 80
856#define IFTYPE_DS0 81
857#define IFTYPE_DS0_BUNDLE 82
858#define IFTYPE_BSC 83
859#define IFTYPE_ASYNC 84
860#define IFTYPE_CNR 85
861#define IFTYPE_ISO88025DTR 86
862#define IFTYPE_EPLRS 87
863#define IFTYPE_ARAP 88
864#define IFTYPE_PROPCNLS 89
865#define IFTYPE_HOSTPAD 90
866#define IFTYPE_TERMPAD 91
867#define IFTYPE_FRAME_RELAY_MPI 92
868#define IFTYPE_X213 93
869#define IFTYPE_ADSL 94
870#define IFTYPE_RADSL 95
871#define IFTYPE_SDSL 96
872#define IFTYPE_VDSL 97
873#define IFTYPE_ISO88025CRFPINT 98
874#define IFTYPE_MYRINET 99
875#define IFTYPE_VOICEEM 100
876#define IFTYPE_VOICEFXO 101
877#define IFTYPE_VOICEFXS 102
878#define IFTYPE_VOICEENCAP 103
879#define IFTYPE_VOICEOVERIP 104
880#define IFTYPE_ATMDXI 105
881#define IFTYPE_ATMFUNI 106
882#define IFTYPE_ATMIMA 107
883#define IFTYPE_PPPMULTILINKBUNDLE 108
884#define IFTYPE_IPOVERCDLC 109
885#define IFTYPE_IPOVERCLAW 110
886#define IFTYPE_STACKTOSTACK 111
887#define IFTYPE_VIRTUAL_IP_ADDRESS 112
888#define IFTYPE_MPC 113
889#define IFTYPE_IPOVERATM 114
890#define IFTYPE_ISO88025FIBER 115
891#define IFTYPE_TDLC 116
892#define IFTYPE_GIGABIT_ETHERNET 117
893#define IFTYPE_HDLC 118
894#define IFTYPE_LAPF 119
895#define IFTYPE_V37 120
896#define IFTYPE_X25MLP 121
897#define IFTYPE_X25_HUNT_GROUP 122
898#define IFTYPE_TRANSPHDLC 123
899#define IFTYPE_INTERLEAVE 124
900#define IFTYPE_FAST 125
901#define IFTYPE_IP 126
902#define IFTYPE_DOCSCABLE_MACLAYER 127
903#define IFTYPE_DOCSCABLE_DOWNSTREAM 128
904#define IFTYPE_DOCSCABLE_UPSTREAM 129
905#define IFTYPE_A12MPPSWITCH 130
906#define IFTYPE_TUNNEL 131
907#define IFTYPE_COFFEE 132
908#define IFTYPE_CES 133
909#define IFTYPE_ATM_SUBINTERFACE 134
910#define IFTYPE_L2VLAN 135
911#define IFTYPE_L3IPVLAN 136
912#define IFTYPE_L3IPXVLAN 137
913#define IFTYPE_DIGITAL_POWERLINE 138
914#define IFTYPE_MEDIAMAIL_OVER_IP 139
915#define IFTYPE_DTM 140
916#define IFTYPE_DCN 141
917#define IFTYPE_IPFORWARD 142
918#define IFTYPE_MSDSL 143
919#define IFTYPE_IEEE1394 144
920#define IFTYPE_GSN 145
921#define IFTYPE_DVBRCC_MACLAYER 146
922#define IFTYPE_DVBRCC_DOWNSTREAM 147
923#define IFTYPE_DVBRCC_UPSTREAM 148
924#define IFTYPE_ATM_VIRTUAL 149
925#define IFTYPE_MPLS_TUNNEL 150
926#define IFTYPE_SRP 151
927#define IFTYPE_VOICE_OVER_ATM 152
928#define IFTYPE_VOICE_OVER_FRAME_RELAY 153
929#define IFTYPE_IDSL 154
930#define IFTYPE_COMPOSITE_LINK 155
931#define IFTYPE_SS7_SIGLINK 156
932#define IFTYPE_PROPWIRELESSP2P 157
933#define IFTYPE_FRFORWARD 158
934#define IFTYPE_RFC1483 159
935#define IFTYPE_USB 160
936#define IFTYPE_IEEE8023ADLAG 161
937#define IFTYPE_BGP_POLICY_ACCOUNTING 162
938#define IFTYPE_FRF16MFR_BUNDLE 163
939#define IFTYPE_H323_GATEKEEPER 164
940#define IFTYPE_H323_PROXY 165
941#define IFTYPE_MPLS 166
942#define IFTYPE_MFSIGLINK 167
943#define IFTYPE_HDSL2 168
944#define IFTYPE_SHDSL 169
945#define IFTYPE_DS1FDL 170
946#define IFTYPE_POS 171
947#define IFTYPE_DVBASI_IN 172
948#define IFTYPE_DVBASI_OUT 173
949#define IFTYPE_PLC 174
950#define IFTYPE_NFAS 175
951#define IFTYPE_TR008 176
952#define IFTYPE_GR303RDT 177
953#define IFTYPE_GR303IDT 178
954#define IFTYPE_ISUP 179
955#define IFTYPE_PROPDOCSWIRELESSMACLAYER 180
956#define IFTYPE_PROPDOCSWIRELESSDOWNSTREAM 181
957#define IFTYPE_PROPDOCSWIRELESSUPSTREAM 182
958#define IFTYPE_HIPERLAN2 183
959#define IFTYPE_PROPBWAP2MP 184
960#define IFTYPE_SONET_OVERHEAD_CHANNEL 185
961#define IFTYPE_DW_OVERHEAD_CHANNEL 186
962#define IFTYPE_AAL2 187
963#define IFTYPE_RADIOMAC 188
964#define IFTYPE_ATMRADIO 189
965#define IFTYPE_IMT 190
966#define IFTYPE_MVL 191
967#define IFTYPE_REACHDSL 192
968#define IFTYPE_FRDLCIENDPT 193
969#define IFTYPE_ATMVCIENDPT 194
970#define IFTYPE_OPTICAL_CHANNEL 195
971#define IFTYPE_OPTICAL_TRANSPORT 196
972#define IFTYPE_PROPATM 197
973#define IFTYPE_VOICE_OVER_CABLE 198
974#define IFTYPE_INFINIBAND 199
975#define IFTYPE_TELINK 200
976#define IFTYPE_Q2931 201
977#define IFTYPE_VIRTUALTG 202
978#define IFTYPE_SIPTG 203
979#define IFTYPE_SIPSIG 204
980#define IFTYPE_DOCSCABLEUPSTREAMCHANNEL 205
981#define IFTYPE_ECONET 206
982#define IFTYPE_PON155 207
983#define IFTYPE_PON622 208
984#define IFTYPE_BRIDGE 209
985#define IFTYPE_LINEGROUP 210
986#define IFTYPE_VOICEEMFGD 211
987#define IFTYPE_VOICEFGDEANA 212
988#define IFTYPE_VOICEDID 213
989#define IFTYPE_MPEG_TRANSPORT 214
990#define IFTYPE_SIXTOFOUR 215
991#define IFTYPE_GTP 216
992#define IFTYPE_PDNETHERLOOP1 217
993#define IFTYPE_PDNETHERLOOP2 218
994#define IFTYPE_OPTICAL_CHANNEL_GROUP 219
995#define IFTYPE_HOMEPNA 220
996#define IFTYPE_GFP 221
997#define IFTYPE_CISCO_ISL_VLAN 222
998#define IFTYPE_ACTELIS_METALOOP 223
999#define IFTYPE_FCIPLINK 224
1000#define IFTYPE_RPR 225
1001#define IFTYPE_QAM 226
1002#define IFTYPE_LMP 227
1003#define IFTYPE_CBLVECTASTAR 228
1004#define IFTYPE_DOCSCABLEMCMTSDOWNSTREAM 229
1005#define IFTYPE_ADSL2 230
1006#define IFTYPE_MACSECCONTROLLEDIF 231
1007#define IFTYPE_MACSECUNCONTROLLEDIF 232
1008#define IFTYPE_AVICIOPTICALETHER 233
1009#define IFTYPE_ATM_BOND 234
1010#define IFTYPE_VOICEFGDOS 235
1011#define IFTYPE_MOCA_VERSION1 236
1012#define IFTYPE_IEEE80216WMAN 237
1013#define IFTYPE_ADSL2PLUS 238
1014#define IFTYPE_DVBRCSMACLAYER 239
1015#define IFTYPE_DVBTDM 240
1016#define IFTYPE_DVBRCSTDMA 241
1017#define IFTYPE_X86LAPS 242
1018#define IFTYPE_WWANPP 243
1019#define IFTYPE_WWANPP2 244
1020#define IFTYPE_VOICEEBS 245
1021#define IFTYPE_IFPWTYPE 246
1022#define IFTYPE_ILAN 247
1023#define IFTYPE_PIP 248
1024#define IFTYPE_ALUELP 249
1025#define IFTYPE_GPON 250
1026#define IFTYPE_VDSL2 251
1027#define IFTYPE_CAPWAP_DOT11_PROFILE 252
1028#define IFTYPE_CAPWAP_DOT11_BSS 253
1029#define IFTYPE_CAPWAP_WTP_VIRTUAL_RADIO 254
1030#define IFTYPE_BITS 255
1031#define IFTYPE_DOCSCABLEUPSTREAMRFPORT 256
1032#define IFTYPE_CABLEDOWNSTREAMRFPORT 257
1033#define IFTYPE_VMWARE_VIRTUAL_NIC 258
1034#define IFTYPE_IEEE802154 259
1035#define IFTYPE_OTNODU 260
1036#define IFTYPE_OTNOTU 261
1037#define IFTYPE_IFVFITYPE 262
1038#define IFTYPE_G9981 263
1039#define IFTYPE_G9982 264
1040#define IFTYPE_G9983 265
1041#define IFTYPE_ALUEPON 266
1042#define IFTYPE_ALUEPONONU 267
1043#define IFTYPE_ALUEPONPHYSICALUNI 268
1044#define IFTYPE_ALUEPONLOGICALLINK 269
1045#define IFTYPE_ALUGPONONU 270
1046#define IFTYPE_ALUGPONPHYSICALUNI 271
1047#define IFTYPE_VMWARE_NIC_TEAM 272
840a1a6a 1048
674164eb
VK
1049/**
1050 * IP Header -- RFC 791
1051 */
798f373a
VK
1052typedef struct tagIPHDR
1053{
1054 BYTE m_cVIHL; // Version and IHL
1055 BYTE m_cTOS; // Type Of Service
1056 WORD m_wLen; // Total Length
1057 WORD m_wId; // Identification
1058 WORD m_wFlagOff; // Flags and Fragment Offset
1059 BYTE m_cTTL; // Time To Live
1060 BYTE m_cProtocol; // Protocol
1061 WORD m_wChecksum; // Checksum
1062 struct in_addr m_iaSrc; // Internet Address - Source
1063 struct in_addr m_iaDst; // Internet Address - Destination
1064} IPHDR;
1065
674164eb
VK
1066/**
1067 * ICMP Header - RFC 792
1068 */
798f373a
VK
1069typedef struct tagICMPHDR
1070{
1071 BYTE m_cType; // Type
1072 BYTE m_cCode; // Code
1073 WORD m_wChecksum; // Checksum
1074 WORD m_wId; // Identification
1075 WORD m_wSeq; // Sequence
798f373a
VK
1076} ICMPHDR;
1077
674164eb
VK
1078/**
1079 * INADDR_NONE can be undefined on some systems
1080 */
696fc54f
VK
1081#ifndef INADDR_NONE
1082#define INADDR_NONE (0xFFFFFFFF)
1083#endif
1084
674164eb 1085/**
674164eb
VK
1086 * Check if given string is NULL and always return valid pointer
1087 */
7da71731
VK
1088#define CHECK_NULL(x) ((x) == NULL ? _T("(null)") : (x))
1089#define CHECK_NULL_A(x) ((x) == NULL ? "(null)" : (x))
1090#define CHECK_NULL_EX(x) ((x) == NULL ? _T("") : (x))
1091#define CHECK_NULL_EX_A(x) ((x) == NULL ? "" : (x))
ef44d5ea 1092
674164eb
VK
1093/**
1094 * Free memory block if it isn't NULL
1095 */
2f64a076
VK
1096#if FREE_IS_NULL_SAFE
1097#define safe_free(x) free(x);
1098#define safe_free_and_null(x) { free(x); x = NULL; }
1099#else
b6a77d6d 1100#define safe_free(x) { if ((x) != NULL) free(x); }
de2c1214 1101#define safe_free_and_null(x) { if ((x) != NULL) { free(x); x = NULL; } }
2f64a076
VK
1102#endif
1103
1104/**
1105 * free() wrapper if it isn't NULL safe
1106 */
1107#if defined(__cplusplus) && !FREE_IS_NULL_SAFE
1108inline void nx_free(void *p)
1109{
1110 if (p != NULL)
1111 free(p);
1112}
1113#define free nx_free
1114#endif
b6a77d6d 1115
674164eb
VK
1116/**
1117 * delete object and nullify pointer
1118 */
cd890184
VK
1119#define delete_and_null(x) { delete x; x = NULL; }
1120
674164eb
VK
1121/**
1122 * Convert half-byte's value to hex digit and vice versa
1123 */
4075c782
VK
1124#define bin2hex(x) ((x) < 10 ? ((x) + _T('0')) : ((x) + (_T('A') - 10)))
1125#ifdef UNICODE
1126#define hex2bin(x) ((((x) >= _T('0')) && ((x) <= _T('9'))) ? ((x) - _T('0')) : \
1127 (((towupper(x) >= _T('A')) && (towupper(x) <= _T('F'))) ? (towupper(x) - _T('A') + 10) : 0))
1128#else
93b18807
VK
1129#define hex2bin(x) ((((x) >= '0') && ((x) <= '9')) ? ((x) - '0') : \
1130 (((toupper(x) >= 'A') && (toupper(x) <= 'F')) ? (toupper(x) - 'A' + 10) : 0))
4075c782 1131#endif
fe49ce0b 1132
674164eb 1133/**
78032263 1134 * Define MIN() and MAX()
674164eb 1135 */
78032263 1136#undef MIN
b9792835 1137#define MIN(a, b) ((a) < (b) ? (a) : (b))
78032263 1138#undef MAX
b9792835 1139#define MAX(a, b) ((a) > (b) ? (a) : (b))
7e679c4b 1140
674164eb
VK
1141/**
1142 * Define _tcsicmp() for non-windows
1143 */
daf35c51 1144#ifndef _WIN32
90ce1516
VK
1145#define stricmp strcasecmp
1146#define strnicmp strncasecmp
8b86c5dc
VK
1147#define wcsicmp wcscasecmp
1148#define wcsnicmp wcsncasecmp
daf35c51
VK
1149#endif
1150
674164eb
VK
1151/**
1152 * Compare two numbers and return -1, 0, or 1
1153 */
4c7a83e5
VK
1154#define COMPARE_NUMBERS(n1,n2) (((n1) < (n2)) ? -1 : (((n1) > (n2)) ? 1 : 0))
1155
674164eb
VK
1156/**
1157 * Increment pointer for given number of bytes
1158 */
9f20696e
VK
1159#define inc_ptr(ptr, step, ptype) ptr = (ptype *)(((char *)ptr) + step)
1160
674164eb
VK
1161/**
1162 * Validate numerical value
1163 */
52996299
VK
1164#define VALIDATE_VALUE(var,x,y,z) { if ((var < x) || (var > y)) var = z; }
1165
674164eb
VK
1166/**
1167 * DCI (data collection item) data types
1168 */
a72a1fb1
VK
1169#define DCI_DT_INT 0
1170#define DCI_DT_UINT 1
1171#define DCI_DT_INT64 2
1172#define DCI_DT_UINT64 3
1173#define DCI_DT_STRING 4
1174#define DCI_DT_FLOAT 5
20aaa307 1175#define DCI_DT_NULL 6
8f9299d1 1176#define DCI_DT_DEPRECATED 255 /* used internally by agent */
a72a1fb1 1177
674164eb
VK
1178/**
1179 * Insert parameter as string
1180 */
9493e563
VK
1181#ifdef UNICODE
1182#define STRING(x) L#x
1183#else
1184#define STRING(x) #x
1185#endif
1186
674164eb 1187/**
6be0a20b
VK
1188 * Pipe handle
1189 */
1190#ifdef _WIN32
1191#define HPIPE HANDLE
1192#define INVALID_PIPE_HANDLE INVALID_HANDLE_VALUE
1193#else
1194#define HPIPE int
1195#define INVALID_PIPE_HANDLE (-1)
1196#endif
1197
34b9a3e7
VK
1198#ifdef __cplusplus
1199
b9792835
VK
1200#include <algorithm>
1201
34b9a3e7
VK
1202/**
1203 * Session enumeration callback return codes
1204 */
1205enum EnumerationCallbackResult
1206{
1207 _STOP = 0,
1208 _CONTINUE = 1
1209};
1210
ab7a30e6
VK
1211/**
1212 * Disable copy constructor if compiler supports it
1213 */
1214#if CAN_DELETE_COPY_CTOR
1215#define DISABLE_COPY_CTOR(c) c (const c &s) = delete;
1216#else
1217#define DISABLE_COPY_CTOR(c)
1218#endif
1219
34b9a3e7
VK
1220#endif
1221
cbcaf8c8 1222#endif /* _nms_common_h_ */