latest changes from RCP console
[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);
d35ed0aa
VK
712
713 QWORD LIBNETXMS_EXPORTABLE FileSizeW(const WCHAR *pszFileName);
714 QWORD LIBNETXMS_EXPORTABLE FileSizeA(const char *pszFileName);
715#ifdef UNICODE
716#define FileSize FileSizeW
717#else
718#define FileSize FileSizeA
719#endif
670c7f3d 720
64584976 721 int LIBNETXMS_EXPORTABLE BitsInMask(DWORD dwMask);
018fda4d 722 TCHAR LIBNETXMS_EXPORTABLE *IpToStr(DWORD dwAddr, TCHAR *szBuffer);
e0f99bf0
VK
723#ifdef UNICODE
724 char LIBNETXMS_EXPORTABLE *IpToStrA(DWORD dwAddr, char *szBuffer);
17b35ccc
VK
725#else
726#define IpToStrA IpToStr
e0f99bf0 727#endif
36e44abe 728 TCHAR LIBNETXMS_EXPORTABLE *Ip6ToStr(BYTE *addr, TCHAR *buffer);
60557d06
VK
729 TCHAR LIBNETXMS_EXPORTABLE *SockaddrToStr(struct sockaddr *addr, TCHAR *buffer);
730
3aa0061c 731 DWORD LIBNETXMS_EXPORTABLE ResolveHostName(const TCHAR *pszName);
08b214c6
VK
732#ifdef UNICODE
733 DWORD LIBNETXMS_EXPORTABLE ResolveHostNameA(const char *pszName);
734#else
735#define ResolveHostNameA ResolveHostName
736#endif
a1dc75b0 737
64584976 738 void LIBNETXMS_EXPORTABLE *nx_memdup(const void *pData, DWORD dwSize);
f218dc6d 739 void LIBNETXMS_EXPORTABLE nx_memswap(void *pBlock1, void *pBlock2, DWORD dwSize);
31521248 740
d7970ee7
VK
741 WCHAR LIBNETXMS_EXPORTABLE *BinToStrW(const BYTE *pData, DWORD dwSize, WCHAR *pStr);
742 char LIBNETXMS_EXPORTABLE *BinToStrA(const BYTE *pData, DWORD dwSize, char *pStr);
743#ifdef UNICODE
744#define BinToStr BinToStrW
745#else
746#define BinToStr BinToStrA
747#endif
748
3aa0061c 749 DWORD LIBNETXMS_EXPORTABLE StrToBin(const TCHAR *pStr, BYTE *pData, DWORD dwSize);
f42b8099 750 TCHAR LIBNETXMS_EXPORTABLE *MACToStr(const BYTE *pData, TCHAR *pStr);
b50f1100 751
b07c50cc
VK
752 void LIBNETXMS_EXPORTABLE StrStripA(char *pszStr);
753 void LIBNETXMS_EXPORTABLE StrStripW(WCHAR *pszStr);
754#ifdef UNICODE
755#define StrStrip StrStripW
756#else
757#define StrStrip StrStripA
758#endif
759
ada97259 760 const char LIBNETXMS_EXPORTABLE *ExtractWordA(const char *line, char *buffer);
cafe592d 761 const WCHAR LIBNETXMS_EXPORTABLE *ExtractWordW(const WCHAR *line, WCHAR *buffer);
ada97259
VK
762#ifdef UNICODE
763#define ExtractWord ExtractWordW
764#else
765#define ExtractWord ExtractWordA
766#endif
767
3583a400
VK
768 int LIBNETXMS_EXPORTABLE NumCharsA(const char *pszStr, char ch);
769 int LIBNETXMS_EXPORTABLE NumCharsW(const WCHAR *pszStr, WCHAR ch);
770#ifdef UNICODE
771#define NumChars NumCharsW
772#else
773#define NumChars NumCharsA
774#endif
ada97259 775
35f836fe
VK
776 void LIBNETXMS_EXPORTABLE RemoveTrailingCRLFA(char *str);
777 void LIBNETXMS_EXPORTABLE RemoveTrailingCRLFW(WCHAR *str);
778#ifdef UNICODE
779#define RemoveTrailingCRLF RemoveTrailingCRLFW
780#else
781#define RemoveTrailingCRLF RemoveTrailingCRLFA
782#endif
783
cafe592d
VK
784 BOOL LIBNETXMS_EXPORTABLE RegexpMatchA(const char *pszStr, const char *pszExpr, BOOL bMatchCase);
785 BOOL LIBNETXMS_EXPORTABLE RegexpMatchW(const WCHAR *pszStr, const WCHAR *pszExpr, BOOL bMatchCase);
786#ifdef UNICODE
787#define RegexpMatch RegexpMatchW
788#else
789#define RegexpMatch RegexpMatchA
790#endif
791
ada97259
VK
792 void LIBNETXMS_EXPORTABLE Trim(TCHAR *str);
793 BOOL LIBNETXMS_EXPORTABLE MatchString(const TCHAR *pattern, const TCHAR *string, BOOL matchCase);
ada97259
VK
794 TCHAR LIBNETXMS_EXPORTABLE **SplitString(const TCHAR *source, TCHAR sep, int *numStrings);
795
f7794b68
VK
796#ifdef __cplusplus
797 BOOL LIBNETXMS_EXPORTABLE IsValidObjectName(const TCHAR *pszName, BOOL bExtendedChars = FALSE);
798#endif
fa2b47a7 799 BOOL LIBNETXMS_EXPORTABLE IsValidScriptName(const TCHAR *pszName);
7618e362 800 /* deprecated */ void LIBNETXMS_EXPORTABLE TranslateStr(TCHAR *pszString, const TCHAR *pszSubStr, const TCHAR *pszReplace);
1a5e0c22 801 const TCHAR LIBNETXMS_EXPORTABLE *GetCleanFileName(const TCHAR *pszFileName);
c3cfc039 802 void LIBNETXMS_EXPORTABLE GetOSVersionString(TCHAR *pszBuffer, int nBufSize);
3aa0061c 803 BYTE LIBNETXMS_EXPORTABLE *LoadFile(const TCHAR *pszFileName, DWORD *pdwFileSize);
08b214c6
VK
804#ifdef UNICODE
805 BYTE LIBNETXMS_EXPORTABLE *LoadFileA(const char *pszFileName, DWORD *pdwFileSize);
806#else
807#define LoadFileA LoadFile
808#endif
809
6120112b 810 DWORD LIBNETXMS_EXPORTABLE CalculateCRC32(const unsigned char *pData, DWORD dwSize, DWORD dwCRC);
a3c76aba 811 void LIBNETXMS_EXPORTABLE CalculateMD5Hash(const unsigned char *data, size_t nbytes, unsigned char *hash);
e0d4b618 812 void LIBNETXMS_EXPORTABLE MD5HashForPattern(const unsigned char *data, size_t patternSize, size_t fullSize, BYTE *hash);
a3c76aba 813 void LIBNETXMS_EXPORTABLE CalculateSHA1Hash(unsigned char *data, size_t nbytes, unsigned char *hash);
e0d4b618 814 void LIBNETXMS_EXPORTABLE SHA1HashForPattern(unsigned char *data, size_t patternSize, size_t fullSize, unsigned char *hash);
3aa0061c
VK
815 BOOL LIBNETXMS_EXPORTABLE CalculateFileMD5Hash(const TCHAR *pszFileName, BYTE *pHash);
816 BOOL LIBNETXMS_EXPORTABLE CalculateFileSHA1Hash(const TCHAR *pszFileName, BYTE *pHash);
817 BOOL LIBNETXMS_EXPORTABLE CalculateFileCRC32(const TCHAR *pszFileName, DWORD *pResult);
66c04cc7 818
4e2debcc
VK
819 void LIBNETXMS_EXPORTABLE ICEEncryptData(const BYTE *in, int inLen, BYTE *out, const BYTE *key);
820 void LIBNETXMS_EXPORTABLE ICEDecryptData(const BYTE *in, int inLen, BYTE *out, const BYTE *key);
821
6b1282e7
VK
822 BOOL LIBNETXMS_EXPORTABLE DecryptPassword(const TCHAR *login, const TCHAR *encryptedPasswd, TCHAR *decryptedPasswd);
823
46ef501a
VK
824 DWORD LIBNETXMS_EXPORTABLE IcmpPing(DWORD dwAddr, int iNumRetries, DWORD dwTimeout,
825 DWORD *pdwRTT, DWORD dwPacketSize);
4826c8a5 826
3aa0061c 827 int LIBNETXMS_EXPORTABLE NxDCIDataTypeFromText(const TCHAR *pszText);
aa13cfd9 828
4560d8bd 829 HMODULE LIBNETXMS_EXPORTABLE DLOpen(const TCHAR *pszLibName, TCHAR *pszErrorText);
aa13cfd9 830 void LIBNETXMS_EXPORTABLE DLClose(HMODULE hModule);
dda7c270 831 void LIBNETXMS_EXPORTABLE *DLGetSymbolAddr(HMODULE hModule, const char *pszSymbol, TCHAR *pszErrorText);
aa13cfd9 832
2e06d08b
VK
833 BOOL LIBNETXMS_EXPORTABLE ExtractNamedOptionValue(const TCHAR *optString, const TCHAR *option, TCHAR *buffer, int bufSize);
834 BOOL LIBNETXMS_EXPORTABLE ExtractNamedOptionValueAsBool(const TCHAR *optString, const TCHAR *option, BOOL defVal);
835 long LIBNETXMS_EXPORTABLE ExtractNamedOptionValueAsInt(const TCHAR *optString, const TCHAR *option, long defVal);
ae9cddaf 836
bc858635
VK
837#ifdef __cplusplus
838 const TCHAR LIBNETXMS_EXPORTABLE *CodeToText(int iCode, CODE_TO_TEXT *pTranslator, const TCHAR *pszDefaultText = _T("Unknown"));
839#else
840 const TCHAR LIBNETXMS_EXPORTABLE *CodeToText(int iCode, CODE_TO_TEXT *pTranslator, const TCHAR *pszDefaultText);
841#endif
842
aa13cfd9 843#ifdef _WIN32
4299401e 844 TCHAR LIBNETXMS_EXPORTABLE *GetSystemErrorText(DWORD dwError, TCHAR *pszBuffer, size_t iBufSize);
ccc34207 845 BOOL LIBNETXMS_EXPORTABLE GetWindowsVersionString(TCHAR *versionString, int strSize);
11606542 846 INT64 LIBNETXMS_EXPORTABLE GetProcessRSS();
aa13cfd9 847#endif
696fc54f
VK
848
849#if !(HAVE_DAEMON)
b1a57444 850 int LIBNETXMS_EXPORTABLE daemon(int nochdir, int noclose);
696fc54f 851#endif
4332e9d8 852
3aa0061c 853 DWORD LIBNETXMS_EXPORTABLE inet_addr_w(const WCHAR *pszAddr);
268774a0 854
4332e9d8 855#ifndef _WIN32
664c7c49 856 BOOL LIBNETXMS_EXPORTABLE SetDefaultCodepage(const char *cp);
3aa0061c 857 int LIBNETXMS_EXPORTABLE WideCharToMultiByte(int iCodePage, DWORD dwFlags, const WCHAR *pWideCharStr,
4332e9d8
VK
858 int cchWideChar, char *pByteStr, int cchByteChar,
859 char *pDefaultChar, BOOL *pbUsedDefChar);
3aa0061c 860 int LIBNETXMS_EXPORTABLE MultiByteToWideChar(int iCodePage, DWORD dwFlags, const char *pByteStr,
4332e9d8
VK
861 int cchByteChar, WCHAR *pWideCharStr,
862 int cchWideChar);
04dbaf62 863
6b93c954 864#if !defined(UNICODE_UCS2) || !HAVE_WCSLEN
8b86c5dc 865 int LIBNETXMS_EXPORTABLE ucs2_strlen(const UCS2CHAR *pStr);
6b93c954
VK
866#endif
867#if !defined(UNICODE_UCS2) || !HAVE_WCSNCPY
8b86c5dc 868 UCS2CHAR LIBNETXMS_EXPORTABLE *ucs2_strncpy(UCS2CHAR *pDst, const UCS2CHAR *pSrc, int nDstLen);
6b93c954
VK
869#endif
870#if !defined(UNICODE_UCS2) || !HAVE_WCSDUP
35f836fe 871 UCS2CHAR LIBNETXMS_EXPORTABLE *ucs2__tcsdup(const UCS2CHAR *pStr);
4332e9d8 872#endif
8b86c5dc 873
53c96e2d
VK
874 size_t LIBNETXMS_EXPORTABLE ucs2_to_mb(const UCS2CHAR *src, int srcLen, char *dst, int dstLen);
875 size_t LIBNETXMS_EXPORTABLE mb_to_ucs2(const char *src, int srcLen, UCS2CHAR *dst, int dstLen);
39945910
VK
876 UCS2CHAR LIBNETXMS_EXPORTABLE *UCS2StringFromMBString(const char *pszString);
877 char LIBNETXMS_EXPORTABLE *MBStringFromUCS2String(const UCS2CHAR *pszString);
8b86c5dc 878
6e17f325
VK
879 int LIBNETXMS_EXPORTABLE nx_wprintf(const WCHAR *format, ...);
880 int LIBNETXMS_EXPORTABLE nx_fwprintf(FILE *fp, const WCHAR *format, ...);
881 int LIBNETXMS_EXPORTABLE nx_swprintf(WCHAR *buffer, size_t size, const WCHAR *format, ...);
882 int LIBNETXMS_EXPORTABLE nx_vwprintf(const WCHAR *format, va_list args);
883 int LIBNETXMS_EXPORTABLE nx_vfwprintf(FILE *fp, const WCHAR *format, va_list args);
884 int LIBNETXMS_EXPORTABLE nx_vswprintf(WCHAR *buffer, size_t size, const WCHAR *format, va_list args);
04dbaf62 885
3e39fcde 886#endif /* _WIN32 */
8b86c5dc 887
3aa0061c 888 WCHAR LIBNETXMS_EXPORTABLE *WideStringFromMBString(const char *pszString);
c16afb3d 889 WCHAR LIBNETXMS_EXPORTABLE *WideStringFromUTF8String(const char *pszString);
3aa0061c
VK
890 char LIBNETXMS_EXPORTABLE *MBStringFromWideString(const WCHAR *pwszString);
891 char LIBNETXMS_EXPORTABLE *UTF8StringFromWideString(const WCHAR *pwszString);
8b86c5dc 892
3d1058ed
VK
893#ifdef _WITH_ENCRYPTION
894 WCHAR LIBNETXMS_EXPORTABLE *ERR_error_string_W(int nError, WCHAR *pwszBuffer);
895#endif
896
8b86c5dc 897#ifdef UNICODE_UCS4
53c96e2d
VK
898 size_t LIBNETXMS_EXPORTABLE ucs2_to_ucs4(const UCS2CHAR *src, int srcLen, WCHAR *dst, int dstLen);
899 size_t LIBNETXMS_EXPORTABLE ucs4_to_ucs2(const WCHAR *src, int srcLen, UCS2CHAR *dst, int dstLen);
900 size_t LIBNETXMS_EXPORTABLE ucs2_to_utf8(const UCS2CHAR *src, int srcLen, char *dst, int dstLen);
d9b66a56
VK
901 UCS2CHAR LIBNETXMS_EXPORTABLE *UCS2StringFromUCS4String(const WCHAR *pwszString);
902 WCHAR LIBNETXMS_EXPORTABLE *UCS4StringFromUCS2String(const UCS2CHAR *pszString);
b50f1100 903#endif
8b86c5dc 904
842c22f4
AK
905#if !defined(_WIN32) && !HAVE_WSTAT
906 int wstat(const WCHAR *_path, struct stat *_sbuf);
907#endif
908
ef856d02 909#if defined(UNICODE) && !defined(_WIN32)
d9b66a56 910
f3387429
VK
911#if !HAVE_WPOPEN
912 FILE LIBNETXMS_EXPORTABLE *wpopen(const WCHAR *_command, const WCHAR *_type);
913#endif
8b86c5dc
VK
914#if !HAVE_WFOPEN
915 FILE LIBNETXMS_EXPORTABLE *wfopen(const WCHAR *_name, const WCHAR *_type);
916#endif
917#if !HAVE_WOPEN
918 int LIBNETXMS_EXPORTABLE wopen(const WCHAR *, int, ...);
b50f1100 919#endif
f3387429
VK
920#if !HAVE_WCHMOD
921 int LIBNETXMS_EXPORTABLE wchmod(const WCHAR *_name, int mode);
922#endif
b07c50cc
VK
923#if !HAVE_WCHDIR
924 int wchdir(const WCHAR *_path);
925#endif
926#if !HAVE_WMKDIR
927 int wmkdir(const WCHAR *_path, int mode);
928#endif
929#if !HAVE_WRMDIR
930 int wrmdir(const WCHAR *_path);
931#endif
ccc34207
VK
932#if !HAVE_WRENAME
933 int wrename(const WCHAR *_oldpath, const WCHAR *_newpath);
934#endif
935#if !HAVE_WUNLINK
936 int wunlink(const WCHAR *_path);
937#endif
b07c50cc
VK
938#if !HAVE_WREMOVE
939 int wremove(const WCHAR *_path);
940#endif
941#if !HAVE_WSYSTEM
942 int wsystem(const WCHAR *_cmd);
943#endif
dda7c270
VK
944#if !HAVE_WMKSTEMP
945 int wmkstemp(const WCHAR *_template);
946#endif
b07c50cc
VK
947#if !HAVE_WACCESS
948 int waccess(const WCHAR *_path, int mode);
949#endif
273da39a
VK
950#if !HAVE_WGETENV
951 WCHAR *wgetenv(const WCHAR *_string);
952#endif
f3387429
VK
953#if !HAVE_WCTIME
954 WCHAR *wctime(const time_t *timep);
955#endif
d49d7500
VK
956#if !HAVE_WCSERROR && HAVE_STRERROR
957 WCHAR *wcserror(int errnum);
958#endif
959#if !HAVE_WCSERROR_R && HAVE_STRERROR_R
b0823d06
VK
960#if HAVE_POSIX_STRERROR_R
961 int wcserror_r(int errnum, WCHAR *strerrbuf, size_t buflen);
962#else
d49d7500
VK
963 WCHAR *wcserror_r(int errnum, WCHAR *strerrbuf, size_t buflen);
964#endif
b0823d06 965#endif
e05f8aaf 966
ef856d02 967#endif /* UNICODE && !_WIN32*/
e05f8aaf 968
8b86c5dc
VK
969#if !HAVE_STRTOLL
970 INT64 LIBNETXMS_EXPORTABLE strtoll(const char *nptr, char **endptr, int base);
971#endif
972#if !HAVE_STRTOULL
973 QWORD LIBNETXMS_EXPORTABLE strtoull(const char *nptr, char **endptr, int base);
974#endif
e05f8aaf
VK
975
976#if !HAVE_WCSTOLL
977 INT64 LIBNETXMS_EXPORTABLE wcstoll(const WCHAR *nptr, WCHAR **endptr, int base);
978#endif
979#if !HAVE_WCSTOULL
980 QWORD LIBNETXMS_EXPORTABLE wcstoull(const WCHAR *nptr, WCHAR **endptr, int base);
981#endif
b50f1100 982
fa88627b 983#if !HAVE_WCSDUP && !defined(_WIN32)
37861c72
VK
984 WCHAR LIBNETXMS_EXPORTABLE *wcsdup(const WCHAR *src);
985#endif
986
55e62b45
VK
987#if !HAVE_STRLWR && !defined(_WIN32)
988 char LIBNETXMS_EXPORTABLE *strlwr(char *str);
989 WCHAR LIBNETXMS_EXPORTABLE *wcslwr(WCHAR *str);
990#endif
991
3d1cb7d6 992#ifdef _WIN32
5ea2db30
VK
993#ifdef UNICODE
994 DIRW LIBNETXMS_EXPORTABLE *wopendir(const WCHAR *filename);
995 struct dirent_w LIBNETXMS_EXPORTABLE *wreaddir(DIRW *dirp);
996 int LIBNETXMS_EXPORTABLE wclosedir(DIRW *dirp);
997
998#define _topendir wopendir
999#define _treaddir wreaddir
1000#define _tclosedir wclosedir
1001#else
1002#define _topendir opendir
1003#define _treaddir readdir
1004#define _tclosedir closedir
1005#endif
1006
3d1cb7d6 1007 DIR LIBNETXMS_EXPORTABLE *opendir(const char *filename);
7f9e0c00 1008 struct dirent LIBNETXMS_EXPORTABLE *readdir(DIR *dirp);
3d1cb7d6 1009 int LIBNETXMS_EXPORTABLE closedir(DIR *dirp);
5ea2db30 1010
76b1d3d8
VK
1011#else /* not _WIN32 */
1012
1013 DIRW LIBNETXMS_EXPORTABLE *wopendir(const WCHAR *filename);
1014 struct dirent_w LIBNETXMS_EXPORTABLE *wreaddir(DIRW *dirp);
1015 int LIBNETXMS_EXPORTABLE wclosedir(DIRW *dirp);
1016
37d62364 1017#endif
3d1cb7d6 1018
7f9e0c00
VK
1019#if defined(_WIN32) || !(HAVE_SCANDIR)
1020 int LIBNETXMS_EXPORTABLE scandir(const char *dir, struct dirent ***namelist,
1021 int (*select)(const struct dirent *),
1022 int (*compar)(const struct dirent **, const struct dirent **));
1023 int LIBNETXMS_EXPORTABLE alphasort(const struct dirent **a, const struct dirent **b);
1024#endif
1025
55b33d4c
VK
1026#ifdef UNDER_CE
1027 int LIBNETXMS_EXPORTABLE _topen(TCHAR *pszName, int nFlags, ...);
1028 int LIBNETXMS_EXPORTABLE read(int hFile, void *pBuffer, size_t nBytes);
1029 int LIBNETXMS_EXPORTABLE write(int hFile, void *pBuffer, size_t nBytes);
1030#endif
1031
9f2902ac 1032BOOL LIBNETXMS_EXPORTABLE nxlog_open(const TCHAR *logName, DWORD flags, const TCHAR *msgModule,
d49d7500 1033 unsigned int msgCount, const TCHAR **messages);
9f2902ac
VK
1034void LIBNETXMS_EXPORTABLE nxlog_close(void);
1035void LIBNETXMS_EXPORTABLE nxlog_write(DWORD msg, WORD wType, const char *format, ...);
5945d50a 1036BOOL LIBNETXMS_EXPORTABLE nxlog_set_rotation_policy(int rotationMode, int maxLogSize, int historySize, const TCHAR *dailySuffix);
4addc3a3 1037BOOL LIBNETXMS_EXPORTABLE nxlog_rotate();
f669df41
VK
1038void LIBNETXMS_EXPORTABLE nxlog_set_console_writer(void (*writer)(const TCHAR *, ...));
1039
1040void LIBNETXMS_EXPORTABLE WriteToTerminal(const TCHAR *text);
1041void LIBNETXMS_EXPORTABLE WriteToTerminalEx(const TCHAR *format, ...);
9f2902ac 1042
37a7a862
VK
1043#ifdef _WIN32
1044int LIBNETXMS_EXPORTABLE mkstemp(char *tmpl);
1045int LIBNETXMS_EXPORTABLE wmkstemp(WCHAR *tmpl);
1046#ifdef UNICODE
1047#define _tmkstemp wmkstemp
1048#else
1049#define _tmkstemp mkstemp
1050#endif
1051#endif
1052
9b13553b
VK
1053#ifndef _WIN32
1054int strcat_s(char *dst, size_t dstSize, const char *src);
1055int wcscat_s(WCHAR *dst, size_t dstSize, const WCHAR *src);
1056#endif
1057
b50f1100 1058#ifdef __cplusplus
e9246d26 1059}
b50f1100 1060#endif
e9246d26 1061
a7ff20a5
VK
1062
1063//
1064// C++ only finctions
1065//
1066
1067#ifdef __cplusplus
1068
53c96e2d 1069TCHAR LIBNETXMS_EXPORTABLE *EscapeStringForXML(const TCHAR *string, int length);
a7ff20a5 1070String LIBNETXMS_EXPORTABLE EscapeStringForXML2(const TCHAR *string, int length = -1);
53c96e2d
VK
1071const char LIBNETXMS_EXPORTABLE *XMLGetAttr(const char **attrs, const char *name);
1072int LIBNETXMS_EXPORTABLE XMLGetAttrInt(const char **attrs, const char *name, int defVal);
1073DWORD LIBNETXMS_EXPORTABLE XMLGetAttrDWORD(const char **attrs, const char *name, DWORD defVal);
1074bool LIBNETXMS_EXPORTABLE XMLGetAttrBoolean(const char **attrs, const char *name, bool defVal);
1075
1076#if !defined(_WIN32) && !defined(_NETWARE) && defined(NMS_THREADS_H_INCLUDED)
1077void LIBNETXMS_EXPORTABLE StartMainLoop(THREAD_RESULT (THREAD_CALL * pfSignalHandler)(void *),
1078 THREAD_RESULT (THREAD_CALL * pfMain)(void *));
1079#endif
1080
1081void LIBNETXMS_EXPORTABLE InitSubAgentAPI(void (* writeLog)(int, int, const TCHAR *),
2dd24569
VK
1082 void (* sendTrap1)(DWORD, const TCHAR *, const char *, va_list),
1083 void (* sendTrap2)(DWORD, const TCHAR *, int, TCHAR **),
53c96e2d
VK
1084 BOOL (* sendFile)(void *, DWORD, const TCHAR *, long),
1085 BOOL (* pushData)(const TCHAR *, const TCHAR *));
a7ff20a5
VK
1086
1087#endif
1088
e9246d26 1089#endif /* _nms_util_h_ */