Added protection to null pointers
[public/netxms.git] / include / nms_util.h
CommitLineData
e9246d26 1/*
7ac71e60 2** NetXMS - Network Management System
36e44abe 3** Copyright (C) 2003-2011 Victor Kirhenshtein
e9246d26
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
7** by the Free Software Foundation; either version 3 of the License, or
e9246d26
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
e9246d26
VK
16** along with this program; if not, write to the Free Software
17** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18**
fb7ce4b9 19** File: nms_util.h
e9246d26
VK
20**
21**/
22
23#ifndef _nms_util_h_
24#define _nms_util_h_
25
64584976
VK
26#ifdef _WIN32
27#ifdef LIBNETXMS_EXPORTS
28#define LIBNETXMS_EXPORTABLE __declspec(dllexport)
29#else
30#define LIBNETXMS_EXPORTABLE __declspec(dllimport)
31#endif
32#else /* _WIN32 */
33#define LIBNETXMS_EXPORTABLE
34#endif
35
36
e9246d26
VK
37#include <nms_common.h>
38#include <nms_cscp.h>
953dfe76 39#include <nms_threads.h>
64584976 40#include <time.h>
e9246d26 41
6d8aee95
VK
42#if HAVE_BYTESWAP_H
43#include <byteswap.h>
44#endif
45
92502d5f
VK
46#include <base64.h>
47
6d8aee95
VK
48
49//
92502d5f 50// Serial communications
6d8aee95
VK
51//
52
53#ifdef _WIN32
54
55#define FLOW_NONE 0
56#define FLOW_SOFTWARE 1
57#define FLOW_HARDWARE 2
58
59#else /* _WIN32 */
60
70fed300
AK
61#ifdef HAVE_TERMIOS_H
62# include <termios.h>
63#else
64# error termios.h not found
65#endif
66
6d8aee95
VK
67#endif /* _WIN32 */
68
69
70//
66c04cc7
VK
71// Return codes for IcmpPing()
72//
73
74#define ICMP_SUCCESS 0
75#define ICMP_UNREACHEABLE 1
76#define ICMP_TIMEOUT 2
77#define ICMP_RAW_SOCK_FAILED 3
416816ed 78#define ICMP_API_ERROR 3
66c04cc7
VK
79
80
81//
4826c8a5 82// Token types for configuration loader
dcb44c9a
VK
83//
84
4826c8a5
VK
85#define CT_LONG 0
86#define CT_STRING 1
87#define CT_STRING_LIST 2
88#define CT_END_OF_LIST 3
89#define CT_BOOLEAN 4
90#define CT_WORD 5
fc935a60 91#define CT_IGNORE 6
dda7c270 92#define CT_MB_STRING 7
4826c8a5
VK
93
94
95//
96// Return codes for NxLoadConfig()
97//
98
99#define NXCFG_ERR_OK 0
100#define NXCFG_ERR_NOFILE 1
101#define NXCFG_ERR_SYNTAX 2
102
103
104//
9f2902ac
VK
105// nxlog_open() flags
106//
107
108#define NXLOG_USE_SYSLOG ((DWORD)0x00000001)
109#define NXLOG_PRINT_TO_STDOUT ((DWORD)0x00000002)
110#define NXLOG_IS_OPEN ((DWORD)0x80000000)
111
112
113//
5945d50a
VK
114// nxlog rotation policy
115//
116
117#define NXLOG_ROTATION_DISABLED 0
118#define NXLOG_ROTATION_DAILY 1
119#define NXLOG_ROTATION_BY_SIZE 2
120
121
122//
35f836fe 123// _tcsdup() replacement
8ff13508
VK
124//
125
126#if defined(_WIN32) && defined(USE_WIN32_HEAP)
127#ifdef __cplusplus
128extern "C" {
129#endif
35f836fe 130char LIBNETXMS_EXPORTABLE *nx__tcsdup(const char *src);
8ff13508
VK
131WCHAR LIBNETXMS_EXPORTABLE *nx_wcsdup(const WCHAR *src);
132#ifdef __cplusplus
133}
134#endif
135#endif
136
137
138//
b160350d
VK
139// Class for serial communications
140//
141
142#ifdef __cplusplus
143
144#ifndef _WIN32
145enum
146{
147 NOPARITY,
148 ODDPARITY,
149 EVENPARITY,
150 ONESTOPBIT,
151 TWOSTOPBITS
152};
153
70fed300
AK
154enum
155{
156 FLOW_NONE,
157 FLOW_HARDWARE,
158 FLOW_SOFTWARE
159};
160
b160350d
VK
161#ifndef INVALID_HANDLE_VALUE
162#define INVALID_HANDLE_VALUE (-1)
163#endif
164#endif /* _WIN32 */
165
166class LIBNETXMS_EXPORTABLE Serial
167{
168public:
169 Serial(void);
170 ~Serial(void);
171
e2d68ddd 172 bool Open(const TCHAR *pszPort);
b160350d
VK
173 void Close(void);
174 void SetTimeout(int nTimeout);
f3a581d0
AK
175 int Read(char *pBuff, int nSize); /* waits up to timeout and do single read */
176 int ReadAll(char *pBuff, int nSize); /* read until timeout or out of space */
e2d68ddd 177 bool Write(const char *pBuff, int nSize);
b160350d
VK
178 void Flush(void);
179 bool Set(int nSpeed, int nDataBits, int nParity, int nStopBits);
70fed300 180 bool Set(int nSpeed, int nDataBits, int nParity, int nStopBits, int nFlowControl);
b160350d
VK
181 bool Restart(void);
182
183private:
184 TCHAR *m_pszPort;
185 int m_nTimeout;
186 int m_nSpeed;
187 int m_nDataBits;
188 int m_nStopBits;
189 int m_nParity;
70fed300 190 int m_nFlowControl;
b160350d
VK
191
192#ifndef _WIN32
193 int m_hPort;
70fed300 194 struct termios m_originalSettings;
b160350d
VK
195#else
196 HANDLE m_hPort;
197#endif
198};
199
ff214673
VK
200
201//
202// Class for table data storage
203//
204
ccc34207
VK
205class CSCPMessage;
206
ff214673
VK
207class LIBNETXMS_EXPORTABLE Table
208{
209private:
210 int m_nNumRows;
211 int m_nNumCols;
212 TCHAR **m_ppData;
213 TCHAR **m_ppColNames;
e31c8e60
VK
214 LONG *m_colFormats;
215 TCHAR *m_title;
ff214673
VK
216
217public:
218 Table();
ccc34207 219 Table(CSCPMessage *msg);
ff214673
VK
220 ~Table();
221
3d5610eb 222 int fillMessage(CSCPMessage &msg, int offset, int rowLimit);
9e126e57 223
e31c8e60
VK
224 int getNumRows() { return m_nNumRows; }
225 int getNumColumns() { return m_nNumCols; }
226 const TCHAR *getTitle() { return CHECK_NULL_EX(m_title); }
9e126e57 227
e31c8e60
VK
228 const TCHAR *getColumnName(int col) { return ((col >= 0) && (col < m_nNumCols)) ? m_ppColNames[col] : NULL; }
229 LONG getColumnFormat(int col) { return ((col >= 0) && (col < m_nNumCols)) ? m_colFormats[col] : 0; }
230
231 void setTitle(const TCHAR *title) { safe_free(m_title); m_title = (title != NULL) ? _tcsdup(title) : NULL; }
232 int addColumn(const TCHAR *name, LONG format = 0);
233 int addRow();
9e126e57
VK
234
235 void setAt(int nRow, int nCol, LONG nData);
236 void setAt(int nRow, int nCol, DWORD dwData);
237 void setAt(int nRow, int nCol, double dData);
238 void setAt(int nRow, int nCol, INT64 nData);
239 void setAt(int nRow, int nCol, QWORD qwData);
240 void setAt(int nRow, int nCol, const TCHAR *pszData);
241 void setPreallocatedAt(int nRow, int nCol, TCHAR *pszData);
242
243 void set(int nCol, LONG nData) { setAt(m_nNumRows - 1, nCol, nData); }
244 void set(int nCol, DWORD dwData) { setAt(m_nNumRows - 1, nCol, dwData); }
245 void set(int nCol, double dData) { setAt(m_nNumRows - 1, nCol, dData); }
246 void set(int nCol, INT64 nData) { setAt(m_nNumRows - 1, nCol, nData); }
247 void set(int nCol, QWORD qwData) { setAt(m_nNumRows - 1, nCol, qwData); }
248 void set(int nCol, const TCHAR *pszData) { setAt(m_nNumRows - 1, nCol, pszData); }
249 void setPreallocated(int nCol, TCHAR *pszData) { setPreallocatedAt(m_nNumRows - 1, nCol, pszData); }
250
251 const TCHAR *getAsString(int nRow, int nCol);
252 LONG getAsInt(int nRow, int nCol);
253 DWORD getAsUInt(int nRow, int nCol);
254 INT64 getAsInt64(int nRow, int nCol);
255 QWORD getAsUInt64(int nRow, int nCol);
256 double getAsDouble(int nRow, int nCol);
ff214673
VK
257};
258
8bad8476
VK
259
260//
261// Dynamic string class
262//
263
264class LIBNETXMS_EXPORTABLE String
265{
266protected:
267 TCHAR *m_pszBuffer;
268 DWORD m_dwBufSize;
269
270public:
c577e360
VK
271 static const int npos;
272
8bad8476 273 String();
f3cdd1c5 274 String(const TCHAR *init);
643c9dcb 275 String(const String &src);
8bad8476
VK
276 ~String();
277
7618e362 278 TCHAR *getBuffer() { return m_pszBuffer; }
ce7565e7 279 void setBuffer(TCHAR *pszBuffer);
8bad8476 280
2391d4fd 281 const String& operator =(const TCHAR *pszStr);
49bf9d8d 282 const String& operator =(const String &src);
2391d4fd 283 const String& operator +=(const TCHAR *pszStr);
ce7565e7 284 operator const TCHAR*() { return CHECK_NULL_EX(m_pszBuffer); }
8bad8476 285
08b214c6
VK
286 char *getUTF8String();
287
ce7565e7
VK
288 void addString(const TCHAR *pStr, DWORD dwLen);
289 void addDynamicString(TCHAR *pszStr) { if (pszStr != NULL) { *this += pszStr; free(pszStr); } }
c577e360 290
ce7565e7
VK
291 void addMultiByteString(const char *pStr, DWORD dwSize, int nCodePage);
292 void addWideCharString(const WCHAR *pStr, DWORD dwSize);
ff175e91 293
ce7565e7 294 void addFormattedString(const TCHAR *format, ...);
893dfdd7 295 void addFormattedStringV(const TCHAR *format, va_list args);
ce7565e7
VK
296 void escapeCharacter(int ch, int esc);
297 void translate(const TCHAR *pszSrc, const TCHAR *pszDst);
c577e360 298
ce7565e7
VK
299 DWORD getSize() { return m_dwBufSize > 0 ? m_dwBufSize - 1 : 0; }
300 BOOL isEmpty() { return m_dwBufSize <= 1; }
c577e360 301
ce7565e7
VK
302 TCHAR *subStr(int nStart, int nLen, TCHAR *pszBuffer);
303 TCHAR *subStr(int nStart, int nLen) { return subStr(nStart, nLen, NULL); }
304 int find(const TCHAR *pszStr, int nStart = 0);
1e1450ef 305
0bbab9d3
VK
306 void trim();
307 void shrink(int chars = 1);
c577e360
VK
308};
309
310
311//
312// String map class
313//
314
315class LIBNETXMS_EXPORTABLE StringMap
316{
317protected:
fb986055
VK
318 DWORD m_size;
319 TCHAR **m_keys;
320 TCHAR **m_values;
c577e360 321
fb986055 322 DWORD find(const TCHAR *key);
c577e360
VK
323
324public:
325 StringMap();
fb986055 326 StringMap(const StringMap &src);
c577e360
VK
327 ~StringMap();
328
fb986055 329 StringMap& operator =(const StringMap &src);
40b7416c 330
fb986055
VK
331 void set(const TCHAR *key, const TCHAR *value);
332 void setPreallocated(TCHAR *key, TCHAR *value);
5ad2167d
VK
333 void set(const TCHAR *key, DWORD value);
334
fb986055 335 const TCHAR *get(const TCHAR *key);
5ad2167d 336 DWORD getULong(const TCHAR *key, DWORD defaultValue);
6acb8479 337 bool getBoolean(const TCHAR *key, bool defaultValue);
5ad2167d 338
fb986055
VK
339 void remove(const TCHAR *key);
340 void clear();
c577e360 341
fb986055
VK
342 DWORD getSize() { return m_size; }
343 const TCHAR *getKeyByIndex(DWORD idx) { return (idx < m_size) ? CHECK_NULL_EX(m_keys[idx]) : NULL; }
344 const TCHAR *getValueByIndex(DWORD idx) { return (idx < m_size) ? CHECK_NULL_EX(m_values[idx]) : NULL; }
8bad8476
VK
345};
346
6173bea8
VK
347
348//
349// String list class
350//
351
352class LIBNETXMS_EXPORTABLE StringList
353{
354private:
355 int m_count;
356 int m_allocated;
357 TCHAR **m_values;
358
359public:
360 StringList();
361 ~StringList();
362
363 void add(const TCHAR *value);
364 void addPreallocated(TCHAR *value);
365 void add(LONG value);
366 void add(DWORD value);
367 void add(INT64 value);
368 void add(QWORD value);
369 void add(double value);
24dc5346 370 void replace(int index, const TCHAR *value);
6173bea8
VK
371 void clear();
372 int getSize() { return m_count; }
373 const TCHAR *getValue(int index) { return ((index >=0) && (index < m_count)) ? m_values[index] : NULL; }
ed806a1a
VK
374 int getIndex(const TCHAR *value);
375 int getIndexIgnoreCase(const TCHAR *value);
6173bea8
VK
376};
377
0d75ea88
VK
378
379//
380// Dynamic array class
381//
382
383class LIBNETXMS_EXPORTABLE Array
384{
385private:
386 int m_size;
387 int m_allocated;
388 int m_grow;
389 void **m_data;
390 bool m_objectOwner;
391
16d6f798 392 void internalRemove(int index, bool allowDestruction);
cfa7c21f 393 void destroyObject(void *object) { if (object != NULL) m_objectDestructor(object); }
16d6f798 394
0d75ea88 395protected:
cfa7c21f 396 void (*m_objectDestructor)(void *);
0d75ea88
VK
397
398public:
399 Array(int initial = 0, int grow = 16, bool owner = false);
400 virtual ~Array();
401
402 int add(void *object);
403 void *get(int index) { return ((index >= 0) && (index < m_size)) ? m_data[index] : NULL; }
47a89886 404 void set(int index, void *object);
24dc5346 405 void replace(int index, void *object);
16d6f798
VK
406 void remove(int index) { internalRemove(index, true); }
407 void unlink(int index) { internalRemove(index, false); }
0d75ea88
VK
408 void clear();
409
410 int size() { return m_size; }
411
412 void setOwner(bool owner) { m_objectOwner = owner; }
413 bool isOwner() { return m_objectOwner; }
414};
415
416template <class T> class ObjectArray : public Array
417{
cfa7c21f
VK
418private:
419 static void destructor(void *object) { delete (T*)object; }
0d75ea88
VK
420
421public:
cfa7c21f 422 ObjectArray(int initial = 0, int grow = 16, bool owner = false) : Array(initial, grow, owner) { m_objectDestructor = destructor; }
0d75ea88
VK
423 virtual ~ObjectArray() { }
424
47a89886 425 int add(T *object) { return Array::add((void *)object); }
0d75ea88 426 T *get(int index) { return (T*)Array::get(index); }
47a89886
VK
427 void set(int index, T *object) { Array::set(index, (void *)object); }
428 void replace(int index, T *object) { Array::replace(index, (void *)object); }
0d75ea88
VK
429};
430
7f632dfe
VK
431
432//
cc8ce218
VK
433// Auxilliary class to hold dynamically allocated array of structures
434//
435
436template <class T> class StructArray
437{
438private:
439 int m_count;
440 T *m_data;
441
442public:
443 StructArray(T *data, int count) { m_data = data; m_count = count; }
444 ~StructArray() { safe_free(m_data); }
445
446 int size() { return m_count; }
447 T *get(int index) { return ((index >= 0) && (index < m_count)) ? &m_data[index] : NULL; }
448};
449
450
451//
7f632dfe
VK
452// Auxilliary class for objects which counts references and
453// destroys itself wheren reference count falls to 0
454//
455
456class LIBNETXMS_EXPORTABLE RefCountObject
457{
458private:
459 int m_refCount;
460 MUTEX m_mutex;
461
462public:
463 RefCountObject();
464 virtual ~RefCountObject();
465
466 void incRefCount();
467 void decRefCount();
468};
469
58ee2f43
VK
470
471//
472// Network connection
473//
474
475class LIBNETXMS_EXPORTABLE SocketConnection
476{
477protected:
478 SOCKET m_socket;
479 char m_data[4096];
480 int m_dataPos;
481
482public:
483 SocketConnection();
484 virtual ~SocketConnection();
485
486 bool connectTCP(const TCHAR *hostName, WORD port, DWORD timeout);
487 void disconnect();
488
489 bool canRead(DWORD timeout);
37a83e60 490 int read(char *pBuff, int nSize, DWORD timeout = INFINITE);
58ee2f43
VK
491 bool waitForText(const char *text, int timeout);
492
493 int write(const char *pBuff, int nSize);
1671f85d
VK
494 bool writeLine(const char *line);
495
496 static SocketConnection *createTCPConnection(const TCHAR *hostName, WORD port, DWORD timeout);
58ee2f43
VK
497};
498
b160350d
VK
499#endif /* __cplusplus */
500
501
502//
4826c8a5
VK
503// Configuration item template for configuration loader
504//
505
506typedef struct
507{
018fda4d 508 TCHAR szToken[64];
4826c8a5
VK
509 BYTE iType;
510 BYTE cSeparator; // Separator character for lists
511 WORD wListElements; // Number of list elements, should be set to 0 before calling NxLoadConfig()
512 DWORD dwBufferSize; // Buffer size for strings or flag to be set for CT_BOOLEAN
513 DWORD dwBufferPos; // Should be set to 0
514 void *pBuffer;
515} NX_CFG_TEMPLATE;
dcb44c9a
VK
516
517
518//
bc858635
VK
519// Code translation structure
520//
521
522typedef struct __CODE_TO_TEXT
523{
524 int code;
525 const TCHAR *text;
526} CODE_TO_TEXT;
527
528
529//
3046f9a4
VK
530// getopt() prototype if needed
531//
532
df9812a9 533#if USE_BUNDLED_GETOPT
99e50bb7 534#include <netxms_getopt.h>
3046f9a4
VK
535#endif
536
537
538//
f2fdf1b5
VK
539// Win32 API functions missing under WinCE
540//
541
c32b805a 542#if defined(UNDER_CE) && defined(__cplusplus)
f2fdf1b5
VK
543
544inline void GetSystemTimeAsFileTime(LPFILETIME pFt)
545{
546 SYSTEMTIME sysTime;
547
548 GetSystemTime(&sysTime);
549 SystemTimeToFileTime(&sysTime, pFt);
550}
551
552#endif // UNDER_CE
553
554
555//
3d1cb7d6
VK
556// Structures for opendir() / readdir() / closedir()
557//
558
559#ifdef _WIN32
560
7f9e0c00 561typedef struct dirent
3d1cb7d6
VK
562{
563 long d_ino; /* inode number (not used by MS-DOS) */
564 int d_namlen; /* Name length */
565 char d_name[257]; /* file name */
566} _DIRECT;
567
568typedef struct _dir_struc
569{
570 char *start; /* Starting position */
571 char *curr; /* Current position */
572 long size; /* Size of string table */
573 long nfiles; /* number if filenames in table */
7f9e0c00 574 struct dirent dirstr; /* Directory structure to return */
3d1cb7d6
VK
575} DIR;
576
5ea2db30
VK
577#ifdef UNICODE
578
579typedef struct dirent_w
580{
581 long d_ino; /* inode number (not used by MS-DOS) */
582 int d_namlen; /* Name length */
583 WCHAR d_name[257]; /* file name */
584} _DIRECTW;
585
586typedef struct _dir_struc_w
587{
588 WCHAR *start; /* Starting position */
589 WCHAR *curr; /* Current position */
590 long size; /* Size of string table */
591 long nfiles; /* number if filenames in table */
592 struct dirent_w dirstr; /* Directory structure to return */
593} DIRW;
594
595#define _TDIR DIRW
596#define _TDIRECT _DIRECTW
597#define _tdirent dirent_w
598
599#else
600
601#define _TDIR DIR
602#define _TDIRECT _DIRECT
603#define _tdirent dirent
604
37d62364
AK
605#endif
606
76b1d3d8
VK
607#else /* not _WIN32 */
608
609typedef struct dirent_w
610{
611 long d_ino; /* inode number */
612 WCHAR d_name[257]; /* file name */
613} _DIRECTW;
614
615typedef struct _dir_struc_w
616{
617 DIR *dir; /* Original non-unicode structure */
618 struct dirent_w dirstr; /* Directory structure to return */
619} DIRW;
620
3d1cb7d6
VK
621#endif /* _WIN32 */
622
623
624//
e9246d26
VK
625// Functions
626//
627
43d92b4c 628
babb8280 629#if WORDS_BIGENDIAN
43d92b4c
VK
630#define htonq(x) (x)
631#define ntohq(x) (x)
9f20696e
VK
632#define htond(x) (x)
633#define ntohd(x) (x)
babb8280
VK
634#define SwapWideString(x)
635#else
ca6ad6bb
VK
636#ifdef HAVE_HTONLL
637#define htonq(x) htonll(x)
638#else
babb8280 639#define htonq(x) __bswap_64(x)
ca6ad6bb
VK
640#endif
641#ifdef HAVE_NTOHLL
642#define ntohq(x) ntohll(x)
643#else
babb8280 644#define ntohq(x) __bswap_64(x)
ca6ad6bb 645#endif
babb8280
VK
646#define htond(x) __bswap_double(x)
647#define ntohd(x) __bswap_double(x)
648#define SwapWideString(x) __bswap_wstr(x)
43d92b4c 649#endif
15929b31 650
55b33d4c
VK
651#ifdef UNDER_CE
652#define close(x) CloseHandle((HANDLE)(x))
653#endif
654
b50f1100 655#ifdef __cplusplus
4299401e 656 inline TCHAR *nx_strncpy(TCHAR *pszDest, const TCHAR *pszSrc, size_t nLen)
c81979bc 657 {
912b994d
VK
658#if defined(_WIN32) && (_MSC_VER >= 1400)
659 _tcsncpy_s(pszDest, nLen, pszSrc, _TRUNCATE);
660#else
c81979bc
VK
661 _tcsncpy(pszDest, pszSrc, nLen - 1);
662 pszDest[nLen - 1] = 0;
912b994d 663#endif
c81979bc
VK
664 return pszDest;
665 }
f3387429
VK
666
667#ifdef UNICODE
668 inline char *nx_strncpy_mb(char *pszDest, const char *pszSrc, size_t nLen)
669 {
670#if defined(_WIN32) && (_MSC_VER >= 1400)
6646dca4 671 strncpy_s(pszDest, nLen, pszSrc, _TRUNCATE);
f3387429
VK
672#else
673 strncpy(pszDest, pszSrc, nLen - 1);
674 pszDest[nLen - 1] = 0;
c81979bc 675#endif
f3387429
VK
676 return pszDest;
677 }
c81979bc 678#else
f3387429 679#define nx_strncpy_mb nx_strncpy
7b8b337e
VK
680#endif
681
7b8b337e
VK
682int LIBNETXMS_EXPORTABLE ConnectEx(SOCKET s, struct sockaddr *addr, int len, DWORD timeout);
683int LIBNETXMS_EXPORTABLE SendEx(SOCKET, const void *, size_t, int, MUTEX);
684int LIBNETXMS_EXPORTABLE RecvEx(SOCKET nSocket, const void *pBuff,
685 size_t nSize, int nFlags, DWORD dwTimeout);
c81979bc
VK
686#endif
687
688#ifdef __cplusplus
e9246d26
VK
689extern "C"
690{
b50f1100 691#endif
c5b523e2
VK
692#if defined(_WIN32) || !(HAVE_DECL___BSWAP_32)
693 DWORD LIBNETXMS_EXPORTABLE __bswap_32(DWORD dwVal);
694#endif
f52be742 695#if defined(_WIN32) || !(HAVE_DECL___BSWAP_64)
64584976
VK
696 QWORD LIBNETXMS_EXPORTABLE __bswap_64(QWORD qwVal);
697#endif
9f20696e 698 double LIBNETXMS_EXPORTABLE __bswap_double(double dVal);
273da39a 699 void LIBNETXMS_EXPORTABLE __bswap_wstr(UCS2CHAR *pStr);
64584976 700
076a55c4 701#if !defined(_WIN32) && !defined(_NETWARE)
8b86c5dc
VK
702#if defined(UNICODE_UCS2) || defined(UNICODE_UCS4)
703 void LIBNETXMS_EXPORTABLE wcsupr(WCHAR *in);
704#endif
705 void LIBNETXMS_EXPORTABLE strupr(char *in);
7e679c4b 706#endif
ab588c84 707
b8a8d064
VK
708 void LIBNETXMS_EXPORTABLE QSortEx(void *base, size_t nmemb, size_t size, void *arg,
709 int (*compare)(const void *, const void *, void *));
710
670c7f3d 711 INT64 LIBNETXMS_EXPORTABLE GetCurrentTimeMs(void);
3aa0061c 712 QWORD LIBNETXMS_EXPORTABLE FileSize(const TCHAR *pszFileName);
670c7f3d 713
64584976 714 int LIBNETXMS_EXPORTABLE BitsInMask(DWORD dwMask);
018fda4d 715 TCHAR LIBNETXMS_EXPORTABLE *IpToStr(DWORD dwAddr, TCHAR *szBuffer);
e0f99bf0
VK
716#ifdef UNICODE
717 char LIBNETXMS_EXPORTABLE *IpToStrA(DWORD dwAddr, char *szBuffer);
17b35ccc
VK
718#else
719#define IpToStrA IpToStr
e0f99bf0 720#endif
36e44abe 721 TCHAR LIBNETXMS_EXPORTABLE *Ip6ToStr(BYTE *addr, TCHAR *buffer);
60557d06
VK
722 TCHAR LIBNETXMS_EXPORTABLE *SockaddrToStr(struct sockaddr *addr, TCHAR *buffer);
723
3aa0061c 724 DWORD LIBNETXMS_EXPORTABLE ResolveHostName(const TCHAR *pszName);
08b214c6
VK
725#ifdef UNICODE
726 DWORD LIBNETXMS_EXPORTABLE ResolveHostNameA(const char *pszName);
727#else
728#define ResolveHostNameA ResolveHostName
729#endif
a1dc75b0 730
64584976 731 void LIBNETXMS_EXPORTABLE *nx_memdup(const void *pData, DWORD dwSize);
f218dc6d 732 void LIBNETXMS_EXPORTABLE nx_memswap(void *pBlock1, void *pBlock2, DWORD dwSize);
31521248 733
f42b8099 734 TCHAR LIBNETXMS_EXPORTABLE *BinToStr(const BYTE *pData, DWORD dwSize, TCHAR *pStr);
3aa0061c 735 DWORD LIBNETXMS_EXPORTABLE StrToBin(const TCHAR *pStr, BYTE *pData, DWORD dwSize);
f42b8099 736 TCHAR LIBNETXMS_EXPORTABLE *MACToStr(const BYTE *pData, TCHAR *pStr);
b50f1100 737
b07c50cc
VK
738 void LIBNETXMS_EXPORTABLE StrStripA(char *pszStr);
739 void LIBNETXMS_EXPORTABLE StrStripW(WCHAR *pszStr);
740#ifdef UNICODE
741#define StrStrip StrStripW
742#else
743#define StrStrip StrStripA
744#endif
745
ada97259 746 const char LIBNETXMS_EXPORTABLE *ExtractWordA(const char *line, char *buffer);
cafe592d 747 const WCHAR LIBNETXMS_EXPORTABLE *ExtractWordW(const WCHAR *line, WCHAR *buffer);
ada97259
VK
748#ifdef UNICODE
749#define ExtractWord ExtractWordW
750#else
751#define ExtractWord ExtractWordA
752#endif
753
3583a400
VK
754 int LIBNETXMS_EXPORTABLE NumCharsA(const char *pszStr, char ch);
755 int LIBNETXMS_EXPORTABLE NumCharsW(const WCHAR *pszStr, WCHAR ch);
756#ifdef UNICODE
757#define NumChars NumCharsW
758#else
759#define NumChars NumCharsA
760#endif
ada97259 761
35f836fe
VK
762 void LIBNETXMS_EXPORTABLE RemoveTrailingCRLFA(char *str);
763 void LIBNETXMS_EXPORTABLE RemoveTrailingCRLFW(WCHAR *str);
764#ifdef UNICODE
765#define RemoveTrailingCRLF RemoveTrailingCRLFW
766#else
767#define RemoveTrailingCRLF RemoveTrailingCRLFA
768#endif
769
cafe592d
VK
770 BOOL LIBNETXMS_EXPORTABLE RegexpMatchA(const char *pszStr, const char *pszExpr, BOOL bMatchCase);
771 BOOL LIBNETXMS_EXPORTABLE RegexpMatchW(const WCHAR *pszStr, const WCHAR *pszExpr, BOOL bMatchCase);
772#ifdef UNICODE
773#define RegexpMatch RegexpMatchW
774#else
775#define RegexpMatch RegexpMatchA
776#endif
777
ada97259
VK
778 void LIBNETXMS_EXPORTABLE Trim(TCHAR *str);
779 BOOL LIBNETXMS_EXPORTABLE MatchString(const TCHAR *pattern, const TCHAR *string, BOOL matchCase);
ada97259
VK
780 TCHAR LIBNETXMS_EXPORTABLE **SplitString(const TCHAR *source, TCHAR sep, int *numStrings);
781
f7794b68
VK
782#ifdef __cplusplus
783 BOOL LIBNETXMS_EXPORTABLE IsValidObjectName(const TCHAR *pszName, BOOL bExtendedChars = FALSE);
784#endif
fa2b47a7 785 BOOL LIBNETXMS_EXPORTABLE IsValidScriptName(const TCHAR *pszName);
7618e362 786 /* deprecated */ void LIBNETXMS_EXPORTABLE TranslateStr(TCHAR *pszString, const TCHAR *pszSubStr, const TCHAR *pszReplace);
1a5e0c22 787 const TCHAR LIBNETXMS_EXPORTABLE *GetCleanFileName(const TCHAR *pszFileName);
c3cfc039 788 void LIBNETXMS_EXPORTABLE GetOSVersionString(TCHAR *pszBuffer, int nBufSize);
3aa0061c 789 BYTE LIBNETXMS_EXPORTABLE *LoadFile(const TCHAR *pszFileName, DWORD *pdwFileSize);
08b214c6
VK
790#ifdef UNICODE
791 BYTE LIBNETXMS_EXPORTABLE *LoadFileA(const char *pszFileName, DWORD *pdwFileSize);
792#else
793#define LoadFileA LoadFile
794#endif
795
6120112b 796 DWORD LIBNETXMS_EXPORTABLE CalculateCRC32(const unsigned char *pData, DWORD dwSize, DWORD dwCRC);
a3c76aba 797 void LIBNETXMS_EXPORTABLE CalculateMD5Hash(const unsigned char *data, size_t nbytes, unsigned char *hash);
e0d4b618 798 void LIBNETXMS_EXPORTABLE MD5HashForPattern(const unsigned char *data, size_t patternSize, size_t fullSize, BYTE *hash);
a3c76aba 799 void LIBNETXMS_EXPORTABLE CalculateSHA1Hash(unsigned char *data, size_t nbytes, unsigned char *hash);
e0d4b618 800 void LIBNETXMS_EXPORTABLE SHA1HashForPattern(unsigned char *data, size_t patternSize, size_t fullSize, unsigned char *hash);
3aa0061c
VK
801 BOOL LIBNETXMS_EXPORTABLE CalculateFileMD5Hash(const TCHAR *pszFileName, BYTE *pHash);
802 BOOL LIBNETXMS_EXPORTABLE CalculateFileSHA1Hash(const TCHAR *pszFileName, BYTE *pHash);
803 BOOL LIBNETXMS_EXPORTABLE CalculateFileCRC32(const TCHAR *pszFileName, DWORD *pResult);
66c04cc7 804
4e2debcc
VK
805 void LIBNETXMS_EXPORTABLE ICEEncryptData(const BYTE *in, int inLen, BYTE *out, const BYTE *key);
806 void LIBNETXMS_EXPORTABLE ICEDecryptData(const BYTE *in, int inLen, BYTE *out, const BYTE *key);
807
6b1282e7
VK
808 BOOL LIBNETXMS_EXPORTABLE DecryptPassword(const TCHAR *login, const TCHAR *encryptedPasswd, TCHAR *decryptedPasswd);
809
46ef501a
VK
810 DWORD LIBNETXMS_EXPORTABLE IcmpPing(DWORD dwAddr, int iNumRetries, DWORD dwTimeout,
811 DWORD *pdwRTT, DWORD dwPacketSize);
4826c8a5 812
3aa0061c 813 int LIBNETXMS_EXPORTABLE NxDCIDataTypeFromText(const TCHAR *pszText);
aa13cfd9 814
4560d8bd 815 HMODULE LIBNETXMS_EXPORTABLE DLOpen(const TCHAR *pszLibName, TCHAR *pszErrorText);
aa13cfd9 816 void LIBNETXMS_EXPORTABLE DLClose(HMODULE hModule);
dda7c270 817 void LIBNETXMS_EXPORTABLE *DLGetSymbolAddr(HMODULE hModule, const char *pszSymbol, TCHAR *pszErrorText);
aa13cfd9 818
2e06d08b
VK
819 BOOL LIBNETXMS_EXPORTABLE ExtractNamedOptionValue(const TCHAR *optString, const TCHAR *option, TCHAR *buffer, int bufSize);
820 BOOL LIBNETXMS_EXPORTABLE ExtractNamedOptionValueAsBool(const TCHAR *optString, const TCHAR *option, BOOL defVal);
821 long LIBNETXMS_EXPORTABLE ExtractNamedOptionValueAsInt(const TCHAR *optString, const TCHAR *option, long defVal);
ae9cddaf 822
bc858635
VK
823#ifdef __cplusplus
824 const TCHAR LIBNETXMS_EXPORTABLE *CodeToText(int iCode, CODE_TO_TEXT *pTranslator, const TCHAR *pszDefaultText = _T("Unknown"));
825#else
826 const TCHAR LIBNETXMS_EXPORTABLE *CodeToText(int iCode, CODE_TO_TEXT *pTranslator, const TCHAR *pszDefaultText);
827#endif
828
aa13cfd9 829#ifdef _WIN32
4299401e 830 TCHAR LIBNETXMS_EXPORTABLE *GetSystemErrorText(DWORD dwError, TCHAR *pszBuffer, size_t iBufSize);
ccc34207 831 BOOL LIBNETXMS_EXPORTABLE GetWindowsVersionString(TCHAR *versionString, int strSize);
11606542 832 INT64 LIBNETXMS_EXPORTABLE GetProcessRSS();
aa13cfd9 833#endif
696fc54f
VK
834
835#if !(HAVE_DAEMON)
b1a57444 836 int LIBNETXMS_EXPORTABLE daemon(int nochdir, int noclose);
696fc54f 837#endif
4332e9d8 838
3aa0061c 839 DWORD LIBNETXMS_EXPORTABLE inet_addr_w(const WCHAR *pszAddr);
268774a0 840
4332e9d8 841#ifndef _WIN32
664c7c49 842 BOOL LIBNETXMS_EXPORTABLE SetDefaultCodepage(const char *cp);
3aa0061c 843 int LIBNETXMS_EXPORTABLE WideCharToMultiByte(int iCodePage, DWORD dwFlags, const WCHAR *pWideCharStr,
4332e9d8
VK
844 int cchWideChar, char *pByteStr, int cchByteChar,
845 char *pDefaultChar, BOOL *pbUsedDefChar);
3aa0061c 846 int LIBNETXMS_EXPORTABLE MultiByteToWideChar(int iCodePage, DWORD dwFlags, const char *pByteStr,
4332e9d8
VK
847 int cchByteChar, WCHAR *pWideCharStr,
848 int cchWideChar);
04dbaf62 849
6b93c954 850#if !defined(UNICODE_UCS2) || !HAVE_WCSLEN
8b86c5dc 851 int LIBNETXMS_EXPORTABLE ucs2_strlen(const UCS2CHAR *pStr);
6b93c954
VK
852#endif
853#if !defined(UNICODE_UCS2) || !HAVE_WCSNCPY
8b86c5dc 854 UCS2CHAR LIBNETXMS_EXPORTABLE *ucs2_strncpy(UCS2CHAR *pDst, const UCS2CHAR *pSrc, int nDstLen);
6b93c954
VK
855#endif
856#if !defined(UNICODE_UCS2) || !HAVE_WCSDUP
35f836fe 857 UCS2CHAR LIBNETXMS_EXPORTABLE *ucs2__tcsdup(const UCS2CHAR *pStr);
4332e9d8 858#endif
8b86c5dc 859
53c96e2d
VK
860 size_t LIBNETXMS_EXPORTABLE ucs2_to_mb(const UCS2CHAR *src, int srcLen, char *dst, int dstLen);
861 size_t LIBNETXMS_EXPORTABLE mb_to_ucs2(const char *src, int srcLen, UCS2CHAR *dst, int dstLen);
39945910
VK
862 UCS2CHAR LIBNETXMS_EXPORTABLE *UCS2StringFromMBString(const char *pszString);
863 char LIBNETXMS_EXPORTABLE *MBStringFromUCS2String(const UCS2CHAR *pszString);
8b86c5dc 864
04dbaf62 865#ifdef UNICODE
6e17f325
VK
866 int LIBNETXMS_EXPORTABLE nx_wprintf(const WCHAR *format, ...);
867 int LIBNETXMS_EXPORTABLE nx_fwprintf(FILE *fp, const WCHAR *format, ...);
868 int LIBNETXMS_EXPORTABLE nx_swprintf(WCHAR *buffer, size_t size, const WCHAR *format, ...);
869 int LIBNETXMS_EXPORTABLE nx_vwprintf(const WCHAR *format, va_list args);
870 int LIBNETXMS_EXPORTABLE nx_vfwprintf(FILE *fp, const WCHAR *format, va_list args);
871 int LIBNETXMS_EXPORTABLE nx_vswprintf(WCHAR *buffer, size_t size, const WCHAR *format, va_list args);
04dbaf62
VK
872#endif
873
3e39fcde 874#endif /* _WIN32 */
8b86c5dc 875
3aa0061c 876 WCHAR LIBNETXMS_EXPORTABLE *WideStringFromMBString(const char *pszString);
c16afb3d 877 WCHAR LIBNETXMS_EXPORTABLE *WideStringFromUTF8String(const char *pszString);
3aa0061c
VK
878 char LIBNETXMS_EXPORTABLE *MBStringFromWideString(const WCHAR *pwszString);
879 char LIBNETXMS_EXPORTABLE *UTF8StringFromWideString(const WCHAR *pwszString);
8b86c5dc 880
3d1058ed
VK
881#ifdef _WITH_ENCRYPTION
882 WCHAR LIBNETXMS_EXPORTABLE *ERR_error_string_W(int nError, WCHAR *pwszBuffer);
883#endif
884
8b86c5dc 885#ifdef UNICODE_UCS4
53c96e2d
VK
886 size_t LIBNETXMS_EXPORTABLE ucs2_to_ucs4(const UCS2CHAR *src, int srcLen, WCHAR *dst, int dstLen);
887 size_t LIBNETXMS_EXPORTABLE ucs4_to_ucs2(const WCHAR *src, int srcLen, UCS2CHAR *dst, int dstLen);
888 size_t LIBNETXMS_EXPORTABLE ucs2_to_utf8(const UCS2CHAR *src, int srcLen, char *dst, int dstLen);
d9b66a56
VK
889 UCS2CHAR LIBNETXMS_EXPORTABLE *UCS2StringFromUCS4String(const WCHAR *pwszString);
890 WCHAR LIBNETXMS_EXPORTABLE *UCS4StringFromUCS2String(const UCS2CHAR *pszString);
b50f1100 891#endif
8b86c5dc 892
ef856d02 893#if defined(UNICODE) && !defined(_WIN32)
d9b66a56 894
f3387429
VK
895#if !HAVE_WPOPEN
896 FILE LIBNETXMS_EXPORTABLE *wpopen(const WCHAR *_command, const WCHAR *_type);
897#endif
8b86c5dc
VK
898#if !HAVE_WFOPEN
899 FILE LIBNETXMS_EXPORTABLE *wfopen(const WCHAR *_name, const WCHAR *_type);
900#endif
901#if !HAVE_WOPEN
902 int LIBNETXMS_EXPORTABLE wopen(const WCHAR *, int, ...);
b50f1100 903#endif
f3387429
VK
904#if !HAVE_WCHMOD
905 int LIBNETXMS_EXPORTABLE wchmod(const WCHAR *_name, int mode);
906#endif
8b86c5dc
VK
907#if !HAVE_WSTAT
908 int wstat(const WCHAR *_path, struct stat *_sbuf);
dde96745 909#endif
b07c50cc
VK
910#if !HAVE_WCHDIR
911 int wchdir(const WCHAR *_path);
912#endif
913#if !HAVE_WMKDIR
914 int wmkdir(const WCHAR *_path, int mode);
915#endif
916#if !HAVE_WRMDIR
917 int wrmdir(const WCHAR *_path);
918#endif
ccc34207
VK
919#if !HAVE_WRENAME
920 int wrename(const WCHAR *_oldpath, const WCHAR *_newpath);
921#endif
922#if !HAVE_WUNLINK
923 int wunlink(const WCHAR *_path);
924#endif
b07c50cc
VK
925#if !HAVE_WREMOVE
926 int wremove(const WCHAR *_path);
927#endif
928#if !HAVE_WSYSTEM
929 int wsystem(const WCHAR *_cmd);
930#endif
dda7c270
VK
931#if !HAVE_WMKSTEMP
932 int wmkstemp(const WCHAR *_template);
933#endif
b07c50cc
VK
934#if !HAVE_WACCESS
935 int waccess(const WCHAR *_path, int mode);
936#endif
273da39a
VK
937#if !HAVE_WGETENV
938 WCHAR *wgetenv(const WCHAR *_string);
939#endif
f3387429
VK
940#if !HAVE_WCTIME
941 WCHAR *wctime(const time_t *timep);
942#endif
d49d7500
VK
943#if !HAVE_WCSERROR && HAVE_STRERROR
944 WCHAR *wcserror(int errnum);
945#endif
946#if !HAVE_WCSERROR_R && HAVE_STRERROR_R
b0823d06
VK
947#if HAVE_POSIX_STRERROR_R
948 int wcserror_r(int errnum, WCHAR *strerrbuf, size_t buflen);
949#else
d49d7500
VK
950 WCHAR *wcserror_r(int errnum, WCHAR *strerrbuf, size_t buflen);
951#endif
b0823d06 952#endif
e05f8aaf 953
ef856d02 954#endif /* UNICODE && !_WIN32*/
e05f8aaf 955
8b86c5dc
VK
956#if !HAVE_STRTOLL
957 INT64 LIBNETXMS_EXPORTABLE strtoll(const char *nptr, char **endptr, int base);
958#endif
959#if !HAVE_STRTOULL
960 QWORD LIBNETXMS_EXPORTABLE strtoull(const char *nptr, char **endptr, int base);
961#endif
e05f8aaf
VK
962
963#if !HAVE_WCSTOLL
964 INT64 LIBNETXMS_EXPORTABLE wcstoll(const WCHAR *nptr, WCHAR **endptr, int base);
965#endif
966#if !HAVE_WCSTOULL
967 QWORD LIBNETXMS_EXPORTABLE wcstoull(const WCHAR *nptr, WCHAR **endptr, int base);
968#endif
b50f1100 969
fa88627b 970#if !HAVE_WCSDUP && !defined(_WIN32)
37861c72
VK
971 WCHAR LIBNETXMS_EXPORTABLE *wcsdup(const WCHAR *src);
972#endif
973
3d1cb7d6 974#ifdef _WIN32
5ea2db30
VK
975#ifdef UNICODE
976 DIRW LIBNETXMS_EXPORTABLE *wopendir(const WCHAR *filename);
977 struct dirent_w LIBNETXMS_EXPORTABLE *wreaddir(DIRW *dirp);
978 int LIBNETXMS_EXPORTABLE wclosedir(DIRW *dirp);
979
980#define _topendir wopendir
981#define _treaddir wreaddir
982#define _tclosedir wclosedir
983#else
984#define _topendir opendir
985#define _treaddir readdir
986#define _tclosedir closedir
987#endif
988
3d1cb7d6 989 DIR LIBNETXMS_EXPORTABLE *opendir(const char *filename);
7f9e0c00 990 struct dirent LIBNETXMS_EXPORTABLE *readdir(DIR *dirp);
3d1cb7d6 991 int LIBNETXMS_EXPORTABLE closedir(DIR *dirp);
5ea2db30 992
76b1d3d8
VK
993#else /* not _WIN32 */
994
995 DIRW LIBNETXMS_EXPORTABLE *wopendir(const WCHAR *filename);
996 struct dirent_w LIBNETXMS_EXPORTABLE *wreaddir(DIRW *dirp);
997 int LIBNETXMS_EXPORTABLE wclosedir(DIRW *dirp);
998
37d62364 999#endif
3d1cb7d6 1000
7f9e0c00
VK
1001#if defined(_WIN32) || !(HAVE_SCANDIR)
1002 int LIBNETXMS_EXPORTABLE scandir(const char *dir, struct dirent ***namelist,
1003 int (*select)(const struct dirent *),
1004 int (*compar)(const struct dirent **, const struct dirent **));
1005 int LIBNETXMS_EXPORTABLE alphasort(const struct dirent **a, const struct dirent **b);
1006#endif
1007
55b33d4c
VK
1008#ifdef UNDER_CE
1009 int LIBNETXMS_EXPORTABLE _topen(TCHAR *pszName, int nFlags, ...);
1010 int LIBNETXMS_EXPORTABLE read(int hFile, void *pBuffer, size_t nBytes);
1011 int LIBNETXMS_EXPORTABLE write(int hFile, void *pBuffer, size_t nBytes);
1012#endif
1013
9f2902ac 1014BOOL LIBNETXMS_EXPORTABLE nxlog_open(const TCHAR *logName, DWORD flags, const TCHAR *msgModule,
d49d7500 1015 unsigned int msgCount, const TCHAR **messages);
9f2902ac
VK
1016void LIBNETXMS_EXPORTABLE nxlog_close(void);
1017void LIBNETXMS_EXPORTABLE nxlog_write(DWORD msg, WORD wType, const char *format, ...);
5945d50a 1018BOOL LIBNETXMS_EXPORTABLE nxlog_set_rotation_policy(int rotationMode, int maxLogSize, int historySize, const TCHAR *dailySuffix);
4addc3a3 1019BOOL LIBNETXMS_EXPORTABLE nxlog_rotate();
f669df41
VK
1020void LIBNETXMS_EXPORTABLE nxlog_set_console_writer(void (*writer)(const TCHAR *, ...));
1021
1022void LIBNETXMS_EXPORTABLE WriteToTerminal(const TCHAR *text);
1023void LIBNETXMS_EXPORTABLE WriteToTerminalEx(const TCHAR *format, ...);
9f2902ac 1024
37a7a862
VK
1025#ifdef _WIN32
1026int LIBNETXMS_EXPORTABLE mkstemp(char *tmpl);
1027int LIBNETXMS_EXPORTABLE wmkstemp(WCHAR *tmpl);
1028#ifdef UNICODE
1029#define _tmkstemp wmkstemp
1030#else
1031#define _tmkstemp mkstemp
1032#endif
1033#endif
1034
9b13553b
VK
1035#ifndef _WIN32
1036int strcat_s(char *dst, size_t dstSize, const char *src);
1037int wcscat_s(WCHAR *dst, size_t dstSize, const WCHAR *src);
1038#endif
1039
b50f1100 1040#ifdef __cplusplus
e9246d26 1041}
b50f1100 1042#endif
e9246d26 1043
a7ff20a5
VK
1044
1045//
1046// C++ only finctions
1047//
1048
1049#ifdef __cplusplus
1050
53c96e2d 1051TCHAR LIBNETXMS_EXPORTABLE *EscapeStringForXML(const TCHAR *string, int length);
a7ff20a5 1052String LIBNETXMS_EXPORTABLE EscapeStringForXML2(const TCHAR *string, int length = -1);
53c96e2d
VK
1053const char LIBNETXMS_EXPORTABLE *XMLGetAttr(const char **attrs, const char *name);
1054int LIBNETXMS_EXPORTABLE XMLGetAttrInt(const char **attrs, const char *name, int defVal);
1055DWORD LIBNETXMS_EXPORTABLE XMLGetAttrDWORD(const char **attrs, const char *name, DWORD defVal);
1056bool LIBNETXMS_EXPORTABLE XMLGetAttrBoolean(const char **attrs, const char *name, bool defVal);
1057
1058#if !defined(_WIN32) && !defined(_NETWARE) && defined(NMS_THREADS_H_INCLUDED)
1059void LIBNETXMS_EXPORTABLE StartMainLoop(THREAD_RESULT (THREAD_CALL * pfSignalHandler)(void *),
1060 THREAD_RESULT (THREAD_CALL * pfMain)(void *));
1061#endif
1062
1063void LIBNETXMS_EXPORTABLE InitSubAgentAPI(void (* writeLog)(int, int, const TCHAR *),
2dd24569
VK
1064 void (* sendTrap1)(DWORD, const TCHAR *, const char *, va_list),
1065 void (* sendTrap2)(DWORD, const TCHAR *, int, TCHAR **),
53c96e2d
VK
1066 BOOL (* sendFile)(void *, DWORD, const TCHAR *, long),
1067 BOOL (* pushData)(const TCHAR *, const TCHAR *));
a7ff20a5
VK
1068
1069#endif
1070
e9246d26 1071#endif /* _nms_util_h_ */