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
3fe40613
VK
259/**
260 * Dynamic string class
261 */
8bad8476
VK
262class LIBNETXMS_EXPORTABLE String
263{
264protected:
265 TCHAR *m_pszBuffer;
266 DWORD m_dwBufSize;
267
268public:
c577e360
VK
269 static const int npos;
270
8bad8476 271 String();
f3cdd1c5 272 String(const TCHAR *init);
643c9dcb 273 String(const String &src);
8bad8476
VK
274 ~String();
275
7618e362 276 TCHAR *getBuffer() { return m_pszBuffer; }
ce7565e7 277 void setBuffer(TCHAR *pszBuffer);
8bad8476 278
2391d4fd 279 const String& operator =(const TCHAR *pszStr);
49bf9d8d 280 const String& operator =(const String &src);
2391d4fd 281 const String& operator +=(const TCHAR *pszStr);
ce7565e7 282 operator const TCHAR*() { return CHECK_NULL_EX(m_pszBuffer); }
8bad8476 283
08b214c6
VK
284 char *getUTF8String();
285
ce7565e7
VK
286 void addString(const TCHAR *pStr, DWORD dwLen);
287 void addDynamicString(TCHAR *pszStr) { if (pszStr != NULL) { *this += pszStr; free(pszStr); } }
c577e360 288
ce7565e7
VK
289 void addMultiByteString(const char *pStr, DWORD dwSize, int nCodePage);
290 void addWideCharString(const WCHAR *pStr, DWORD dwSize);
ff175e91 291
ce7565e7 292 void addFormattedString(const TCHAR *format, ...);
893dfdd7 293 void addFormattedStringV(const TCHAR *format, va_list args);
ce7565e7
VK
294 void escapeCharacter(int ch, int esc);
295 void translate(const TCHAR *pszSrc, const TCHAR *pszDst);
c577e360 296
ce7565e7
VK
297 DWORD getSize() { return m_dwBufSize > 0 ? m_dwBufSize - 1 : 0; }
298 BOOL isEmpty() { return m_dwBufSize <= 1; }
c577e360 299
ce7565e7
VK
300 TCHAR *subStr(int nStart, int nLen, TCHAR *pszBuffer);
301 TCHAR *subStr(int nStart, int nLen) { return subStr(nStart, nLen, NULL); }
302 int find(const TCHAR *pszStr, int nStart = 0);
1e1450ef 303
0bbab9d3
VK
304 void trim();
305 void shrink(int chars = 1);
c577e360
VK
306};
307
3fe40613
VK
308/**
309 * String maps base class
310 */
311class LIBNETXMS_EXPORTABLE StringMapBase
c577e360
VK
312{
313protected:
fb986055
VK
314 DWORD m_size;
315 TCHAR **m_keys;
3fe40613
VK
316 void **m_values;
317 bool m_objectOwner;
318 void (*m_objectDestructor)(void *);
c577e360 319
fb986055 320 DWORD find(const TCHAR *key);
3fe40613
VK
321 void setObject(TCHAR *key, void *value, bool keyPreAlloc);
322 void *getObject(const TCHAR *key);
323 void destroyObject(void *object) { if (object != NULL) m_objectDestructor(object); }
c577e360
VK
324
325public:
3fe40613
VK
326 StringMapBase(bool objectOwner);
327 virtual ~StringMapBase();
328
329 void remove(const TCHAR *key);
330 void clear();
331
332 DWORD getSize() { return m_size; }
333 const TCHAR *getKeyByIndex(DWORD idx) { return (idx < m_size) ? CHECK_NULL_EX(m_keys[idx]) : NULL; }
334};
335
336/**
337 * String map class
338 */
339class LIBNETXMS_EXPORTABLE StringMap : public StringMapBase
340{
341public:
342 StringMap() : StringMapBase(true) { }
fb986055 343 StringMap(const StringMap &src);
3fe40613 344 virtual ~StringMap();
c577e360 345
fb986055 346 StringMap& operator =(const StringMap &src);
40b7416c 347
3fe40613
VK
348 void set(const TCHAR *key, const TCHAR *value) { setObject((TCHAR *)key, _tcsdup(value), false); }
349 void setPreallocated(TCHAR *key, TCHAR *value) { setObject(key, value, true); }
5ad2167d
VK
350 void set(const TCHAR *key, DWORD value);
351
3fe40613 352 const TCHAR *get(const TCHAR *key) { return (const TCHAR *)getObject(key); }
5ad2167d 353 DWORD getULong(const TCHAR *key, DWORD defaultValue);
6acb8479 354 bool getBoolean(const TCHAR *key, bool defaultValue);
5ad2167d 355
3fe40613 356 const TCHAR *getValueByIndex(DWORD idx) { return (idx < m_size) ? CHECK_NULL_EX((TCHAR *)m_values[idx]) : NULL; }
8bad8476
VK
357};
358
3fe40613
VK
359/**
360 * String map template for holding objects as values
361 */
362template <class T> class StringObjectMap : public StringMapBase
363{
364private:
365 static void destructor(void *object) { delete (T*)object; }
6173bea8 366
3fe40613
VK
367public:
368 StringObjectMap(bool objectOwner) : StringMapBase(objectOwner) { m_objectDestructor = destructor; }
369
370 void set(const TCHAR *key, T *object) { setObject((TCHAR *)key, (void *)object, false); }
371 T *get(const TCHAR *key) { return (T*)getObject(key); }
372 T *getValueByIndex(DWORD idx) { return (idx < m_size) ? (T *)m_values[idx] : NULL; }
373};
6173bea8 374
3fe40613
VK
375/**
376 * String list class
377 */
6173bea8
VK
378class LIBNETXMS_EXPORTABLE StringList
379{
380private:
381 int m_count;
382 int m_allocated;
383 TCHAR **m_values;
384
385public:
386 StringList();
387 ~StringList();
388
389 void add(const TCHAR *value);
390 void addPreallocated(TCHAR *value);
391 void add(LONG value);
392 void add(DWORD value);
393 void add(INT64 value);
394 void add(QWORD value);
395 void add(double value);
24dc5346 396 void replace(int index, const TCHAR *value);
6173bea8
VK
397 void clear();
398 int getSize() { return m_count; }
399 const TCHAR *getValue(int index) { return ((index >=0) && (index < m_count)) ? m_values[index] : NULL; }
ed806a1a
VK
400 int getIndex(const TCHAR *value);
401 int getIndexIgnoreCase(const TCHAR *value);
6173bea8
VK
402};
403
3fe40613
VK
404/**
405 * Dynamic array class
406 */
0d75ea88
VK
407class LIBNETXMS_EXPORTABLE Array
408{
409private:
410 int m_size;
411 int m_allocated;
412 int m_grow;
413 void **m_data;
414 bool m_objectOwner;
415
16d6f798 416 void internalRemove(int index, bool allowDestruction);
cfa7c21f 417 void destroyObject(void *object) { if (object != NULL) m_objectDestructor(object); }
16d6f798 418
0d75ea88 419protected:
cfa7c21f 420 void (*m_objectDestructor)(void *);
0d75ea88
VK
421
422public:
423 Array(int initial = 0, int grow = 16, bool owner = false);
424 virtual ~Array();
425
426 int add(void *object);
427 void *get(int index) { return ((index >= 0) && (index < m_size)) ? m_data[index] : NULL; }
47a89886 428 void set(int index, void *object);
24dc5346 429 void replace(int index, void *object);
16d6f798
VK
430 void remove(int index) { internalRemove(index, true); }
431 void unlink(int index) { internalRemove(index, false); }
0d75ea88
VK
432 void clear();
433
434 int size() { return m_size; }
435
436 void setOwner(bool owner) { m_objectOwner = owner; }
437 bool isOwner() { return m_objectOwner; }
438};
439
3fe40613
VK
440/**
441 * Template class for dynamic array which holds objects
442 */
0d75ea88
VK
443template <class T> class ObjectArray : public Array
444{
cfa7c21f
VK
445private:
446 static void destructor(void *object) { delete (T*)object; }
0d75ea88
VK
447
448public:
cfa7c21f 449 ObjectArray(int initial = 0, int grow = 16, bool owner = false) : Array(initial, grow, owner) { m_objectDestructor = destructor; }
0d75ea88
VK
450 virtual ~ObjectArray() { }
451
47a89886 452 int add(T *object) { return Array::add((void *)object); }
0d75ea88 453 T *get(int index) { return (T*)Array::get(index); }
47a89886
VK
454 void set(int index, T *object) { Array::set(index, (void *)object); }
455 void replace(int index, T *object) { Array::replace(index, (void *)object); }
0d75ea88
VK
456};
457
7f632dfe
VK
458
459//
cc8ce218
VK
460// Auxilliary class to hold dynamically allocated array of structures
461//
462
463template <class T> class StructArray
464{
465private:
466 int m_count;
467 T *m_data;
468
469public:
470 StructArray(T *data, int count) { m_data = data; m_count = count; }
471 ~StructArray() { safe_free(m_data); }
472
473 int size() { return m_count; }
474 T *get(int index) { return ((index >= 0) && (index < m_count)) ? &m_data[index] : NULL; }
475};
476
477
478//
7f632dfe
VK
479// Auxilliary class for objects which counts references and
480// destroys itself wheren reference count falls to 0
481//
482
483class LIBNETXMS_EXPORTABLE RefCountObject
484{
485private:
486 int m_refCount;
487 MUTEX m_mutex;
488
489public:
490 RefCountObject();
491 virtual ~RefCountObject();
492
493 void incRefCount();
494 void decRefCount();
495};
496
58ee2f43
VK
497
498//
499// Network connection
500//
501
502class LIBNETXMS_EXPORTABLE SocketConnection
503{
504protected:
505 SOCKET m_socket;
506 char m_data[4096];
507 int m_dataPos;
508
509public:
510 SocketConnection();
511 virtual ~SocketConnection();
512
513 bool connectTCP(const TCHAR *hostName, WORD port, DWORD timeout);
514 void disconnect();
515
516 bool canRead(DWORD timeout);
37a83e60 517 int read(char *pBuff, int nSize, DWORD timeout = INFINITE);
58ee2f43
VK
518 bool waitForText(const char *text, int timeout);
519
520 int write(const char *pBuff, int nSize);
1671f85d
VK
521 bool writeLine(const char *line);
522
523 static SocketConnection *createTCPConnection(const TCHAR *hostName, WORD port, DWORD timeout);
58ee2f43
VK
524};
525
b160350d
VK
526#endif /* __cplusplus */
527
528
529//
4826c8a5
VK
530// Configuration item template for configuration loader
531//
532
533typedef struct
534{
018fda4d 535 TCHAR szToken[64];
4826c8a5
VK
536 BYTE iType;
537 BYTE cSeparator; // Separator character for lists
538 WORD wListElements; // Number of list elements, should be set to 0 before calling NxLoadConfig()
539 DWORD dwBufferSize; // Buffer size for strings or flag to be set for CT_BOOLEAN
540 DWORD dwBufferPos; // Should be set to 0
541 void *pBuffer;
542} NX_CFG_TEMPLATE;
dcb44c9a
VK
543
544
545//
bc858635
VK
546// Code translation structure
547//
548
549typedef struct __CODE_TO_TEXT
550{
551 int code;
552 const TCHAR *text;
553} CODE_TO_TEXT;
554
555
556//
3046f9a4
VK
557// getopt() prototype if needed
558//
559
df9812a9 560#if USE_BUNDLED_GETOPT
99e50bb7 561#include <netxms_getopt.h>
3046f9a4
VK
562#endif
563
564
565//
f2fdf1b5
VK
566// Win32 API functions missing under WinCE
567//
568
c32b805a 569#if defined(UNDER_CE) && defined(__cplusplus)
f2fdf1b5
VK
570
571inline void GetSystemTimeAsFileTime(LPFILETIME pFt)
572{
573 SYSTEMTIME sysTime;
574
575 GetSystemTime(&sysTime);
576 SystemTimeToFileTime(&sysTime, pFt);
577}
578
579#endif // UNDER_CE
580
581
582//
3d1cb7d6
VK
583// Structures for opendir() / readdir() / closedir()
584//
585
586#ifdef _WIN32
587
7f9e0c00 588typedef struct dirent
3d1cb7d6
VK
589{
590 long d_ino; /* inode number (not used by MS-DOS) */
591 int d_namlen; /* Name length */
592 char d_name[257]; /* file name */
593} _DIRECT;
594
595typedef struct _dir_struc
596{
597 char *start; /* Starting position */
598 char *curr; /* Current position */
599 long size; /* Size of string table */
600 long nfiles; /* number if filenames in table */
7f9e0c00 601 struct dirent dirstr; /* Directory structure to return */
3d1cb7d6
VK
602} DIR;
603
5ea2db30
VK
604#ifdef UNICODE
605
606typedef struct dirent_w
607{
608 long d_ino; /* inode number (not used by MS-DOS) */
609 int d_namlen; /* Name length */
610 WCHAR d_name[257]; /* file name */
611} _DIRECTW;
612
613typedef struct _dir_struc_w
614{
615 WCHAR *start; /* Starting position */
616 WCHAR *curr; /* Current position */
617 long size; /* Size of string table */
618 long nfiles; /* number if filenames in table */
619 struct dirent_w dirstr; /* Directory structure to return */
620} DIRW;
621
622#define _TDIR DIRW
623#define _TDIRECT _DIRECTW
624#define _tdirent dirent_w
625
626#else
627
628#define _TDIR DIR
629#define _TDIRECT _DIRECT
630#define _tdirent dirent
631
37d62364
AK
632#endif
633
76b1d3d8
VK
634#else /* not _WIN32 */
635
636typedef struct dirent_w
637{
638 long d_ino; /* inode number */
639 WCHAR d_name[257]; /* file name */
640} _DIRECTW;
641
642typedef struct _dir_struc_w
643{
644 DIR *dir; /* Original non-unicode structure */
645 struct dirent_w dirstr; /* Directory structure to return */
646} DIRW;
647
3d1cb7d6
VK
648#endif /* _WIN32 */
649
650
651//
e9246d26
VK
652// Functions
653//
654
43d92b4c 655
babb8280 656#if WORDS_BIGENDIAN
43d92b4c
VK
657#define htonq(x) (x)
658#define ntohq(x) (x)
9f20696e
VK
659#define htond(x) (x)
660#define ntohd(x) (x)
babb8280
VK
661#define SwapWideString(x)
662#else
ca6ad6bb
VK
663#ifdef HAVE_HTONLL
664#define htonq(x) htonll(x)
665#else
babb8280 666#define htonq(x) __bswap_64(x)
ca6ad6bb
VK
667#endif
668#ifdef HAVE_NTOHLL
669#define ntohq(x) ntohll(x)
670#else
babb8280 671#define ntohq(x) __bswap_64(x)
ca6ad6bb 672#endif
babb8280
VK
673#define htond(x) __bswap_double(x)
674#define ntohd(x) __bswap_double(x)
675#define SwapWideString(x) __bswap_wstr(x)
43d92b4c 676#endif
15929b31 677
55b33d4c
VK
678#ifdef UNDER_CE
679#define close(x) CloseHandle((HANDLE)(x))
680#endif
681
b50f1100 682#ifdef __cplusplus
4299401e 683 inline TCHAR *nx_strncpy(TCHAR *pszDest, const TCHAR *pszSrc, size_t nLen)
c81979bc 684 {
912b994d
VK
685#if defined(_WIN32) && (_MSC_VER >= 1400)
686 _tcsncpy_s(pszDest, nLen, pszSrc, _TRUNCATE);
687#else
c81979bc
VK
688 _tcsncpy(pszDest, pszSrc, nLen - 1);
689 pszDest[nLen - 1] = 0;
912b994d 690#endif
c81979bc
VK
691 return pszDest;
692 }
f3387429
VK
693
694#ifdef UNICODE
695 inline char *nx_strncpy_mb(char *pszDest, const char *pszSrc, size_t nLen)
696 {
697#if defined(_WIN32) && (_MSC_VER >= 1400)
6646dca4 698 strncpy_s(pszDest, nLen, pszSrc, _TRUNCATE);
f3387429
VK
699#else
700 strncpy(pszDest, pszSrc, nLen - 1);
701 pszDest[nLen - 1] = 0;
c81979bc 702#endif
f3387429
VK
703 return pszDest;
704 }
c81979bc 705#else
f3387429 706#define nx_strncpy_mb nx_strncpy
7b8b337e
VK
707#endif
708
7b8b337e
VK
709int LIBNETXMS_EXPORTABLE ConnectEx(SOCKET s, struct sockaddr *addr, int len, DWORD timeout);
710int LIBNETXMS_EXPORTABLE SendEx(SOCKET, const void *, size_t, int, MUTEX);
711int LIBNETXMS_EXPORTABLE RecvEx(SOCKET nSocket, const void *pBuff,
712 size_t nSize, int nFlags, DWORD dwTimeout);
c81979bc
VK
713#endif
714
715#ifdef __cplusplus
e9246d26
VK
716extern "C"
717{
b50f1100 718#endif
c5b523e2
VK
719#if defined(_WIN32) || !(HAVE_DECL___BSWAP_32)
720 DWORD LIBNETXMS_EXPORTABLE __bswap_32(DWORD dwVal);
721#endif
f52be742 722#if defined(_WIN32) || !(HAVE_DECL___BSWAP_64)
64584976
VK
723 QWORD LIBNETXMS_EXPORTABLE __bswap_64(QWORD qwVal);
724#endif
9f20696e 725 double LIBNETXMS_EXPORTABLE __bswap_double(double dVal);
273da39a 726 void LIBNETXMS_EXPORTABLE __bswap_wstr(UCS2CHAR *pStr);
64584976 727
076a55c4 728#if !defined(_WIN32) && !defined(_NETWARE)
8b86c5dc
VK
729#if defined(UNICODE_UCS2) || defined(UNICODE_UCS4)
730 void LIBNETXMS_EXPORTABLE wcsupr(WCHAR *in);
731#endif
732 void LIBNETXMS_EXPORTABLE strupr(char *in);
7e679c4b 733#endif
ab588c84 734
b8a8d064
VK
735 void LIBNETXMS_EXPORTABLE QSortEx(void *base, size_t nmemb, size_t size, void *arg,
736 int (*compare)(const void *, const void *, void *));
737
670c7f3d 738 INT64 LIBNETXMS_EXPORTABLE GetCurrentTimeMs(void);
d35ed0aa
VK
739
740 QWORD LIBNETXMS_EXPORTABLE FileSizeW(const WCHAR *pszFileName);
741 QWORD LIBNETXMS_EXPORTABLE FileSizeA(const char *pszFileName);
742#ifdef UNICODE
743#define FileSize FileSizeW
744#else
745#define FileSize FileSizeA
746#endif
670c7f3d 747
64584976 748 int LIBNETXMS_EXPORTABLE BitsInMask(DWORD dwMask);
018fda4d 749 TCHAR LIBNETXMS_EXPORTABLE *IpToStr(DWORD dwAddr, TCHAR *szBuffer);
e0f99bf0
VK
750#ifdef UNICODE
751 char LIBNETXMS_EXPORTABLE *IpToStrA(DWORD dwAddr, char *szBuffer);
17b35ccc
VK
752#else
753#define IpToStrA IpToStr
e0f99bf0 754#endif
36e44abe 755 TCHAR LIBNETXMS_EXPORTABLE *Ip6ToStr(BYTE *addr, TCHAR *buffer);
60557d06
VK
756 TCHAR LIBNETXMS_EXPORTABLE *SockaddrToStr(struct sockaddr *addr, TCHAR *buffer);
757
3aa0061c 758 DWORD LIBNETXMS_EXPORTABLE ResolveHostName(const TCHAR *pszName);
08b214c6
VK
759#ifdef UNICODE
760 DWORD LIBNETXMS_EXPORTABLE ResolveHostNameA(const char *pszName);
761#else
762#define ResolveHostNameA ResolveHostName
763#endif
a1dc75b0 764
64584976 765 void LIBNETXMS_EXPORTABLE *nx_memdup(const void *pData, DWORD dwSize);
f218dc6d 766 void LIBNETXMS_EXPORTABLE nx_memswap(void *pBlock1, void *pBlock2, DWORD dwSize);
31521248 767
d7970ee7
VK
768 WCHAR LIBNETXMS_EXPORTABLE *BinToStrW(const BYTE *pData, DWORD dwSize, WCHAR *pStr);
769 char LIBNETXMS_EXPORTABLE *BinToStrA(const BYTE *pData, DWORD dwSize, char *pStr);
770#ifdef UNICODE
771#define BinToStr BinToStrW
772#else
773#define BinToStr BinToStrA
774#endif
775
3aa0061c 776 DWORD LIBNETXMS_EXPORTABLE StrToBin(const TCHAR *pStr, BYTE *pData, DWORD dwSize);
f42b8099 777 TCHAR LIBNETXMS_EXPORTABLE *MACToStr(const BYTE *pData, TCHAR *pStr);
b50f1100 778
b07c50cc
VK
779 void LIBNETXMS_EXPORTABLE StrStripA(char *pszStr);
780 void LIBNETXMS_EXPORTABLE StrStripW(WCHAR *pszStr);
781#ifdef UNICODE
782#define StrStrip StrStripW
783#else
784#define StrStrip StrStripA
785#endif
786
ada97259 787 const char LIBNETXMS_EXPORTABLE *ExtractWordA(const char *line, char *buffer);
cafe592d 788 const WCHAR LIBNETXMS_EXPORTABLE *ExtractWordW(const WCHAR *line, WCHAR *buffer);
ada97259
VK
789#ifdef UNICODE
790#define ExtractWord ExtractWordW
791#else
792#define ExtractWord ExtractWordA
793#endif
794
3583a400
VK
795 int LIBNETXMS_EXPORTABLE NumCharsA(const char *pszStr, char ch);
796 int LIBNETXMS_EXPORTABLE NumCharsW(const WCHAR *pszStr, WCHAR ch);
797#ifdef UNICODE
798#define NumChars NumCharsW
799#else
800#define NumChars NumCharsA
801#endif
ada97259 802
35f836fe
VK
803 void LIBNETXMS_EXPORTABLE RemoveTrailingCRLFA(char *str);
804 void LIBNETXMS_EXPORTABLE RemoveTrailingCRLFW(WCHAR *str);
805#ifdef UNICODE
806#define RemoveTrailingCRLF RemoveTrailingCRLFW
807#else
808#define RemoveTrailingCRLF RemoveTrailingCRLFA
809#endif
810
cafe592d
VK
811 BOOL LIBNETXMS_EXPORTABLE RegexpMatchA(const char *pszStr, const char *pszExpr, BOOL bMatchCase);
812 BOOL LIBNETXMS_EXPORTABLE RegexpMatchW(const WCHAR *pszStr, const WCHAR *pszExpr, BOOL bMatchCase);
813#ifdef UNICODE
814#define RegexpMatch RegexpMatchW
815#else
816#define RegexpMatch RegexpMatchA
817#endif
818
a73a4403 819 const TCHAR LIBNETXMS_EXPORTABLE *ExpandFileName(const TCHAR *name, TCHAR *buffer, size_t bufSize);
ada97259
VK
820 void LIBNETXMS_EXPORTABLE Trim(TCHAR *str);
821 BOOL LIBNETXMS_EXPORTABLE MatchString(const TCHAR *pattern, const TCHAR *string, BOOL matchCase);
ada97259
VK
822 TCHAR LIBNETXMS_EXPORTABLE **SplitString(const TCHAR *source, TCHAR sep, int *numStrings);
823
f7794b68
VK
824#ifdef __cplusplus
825 BOOL LIBNETXMS_EXPORTABLE IsValidObjectName(const TCHAR *pszName, BOOL bExtendedChars = FALSE);
826#endif
fa2b47a7 827 BOOL LIBNETXMS_EXPORTABLE IsValidScriptName(const TCHAR *pszName);
7618e362 828 /* deprecated */ void LIBNETXMS_EXPORTABLE TranslateStr(TCHAR *pszString, const TCHAR *pszSubStr, const TCHAR *pszReplace);
1a5e0c22 829 const TCHAR LIBNETXMS_EXPORTABLE *GetCleanFileName(const TCHAR *pszFileName);
c3cfc039 830 void LIBNETXMS_EXPORTABLE GetOSVersionString(TCHAR *pszBuffer, int nBufSize);
3aa0061c 831 BYTE LIBNETXMS_EXPORTABLE *LoadFile(const TCHAR *pszFileName, DWORD *pdwFileSize);
08b214c6
VK
832#ifdef UNICODE
833 BYTE LIBNETXMS_EXPORTABLE *LoadFileA(const char *pszFileName, DWORD *pdwFileSize);
834#else
835#define LoadFileA LoadFile
836#endif
837
6120112b 838 DWORD LIBNETXMS_EXPORTABLE CalculateCRC32(const unsigned char *pData, DWORD dwSize, DWORD dwCRC);
a3c76aba 839 void LIBNETXMS_EXPORTABLE CalculateMD5Hash(const unsigned char *data, size_t nbytes, unsigned char *hash);
e0d4b618 840 void LIBNETXMS_EXPORTABLE MD5HashForPattern(const unsigned char *data, size_t patternSize, size_t fullSize, BYTE *hash);
a3c76aba 841 void LIBNETXMS_EXPORTABLE CalculateSHA1Hash(unsigned char *data, size_t nbytes, unsigned char *hash);
e0d4b618 842 void LIBNETXMS_EXPORTABLE SHA1HashForPattern(unsigned char *data, size_t patternSize, size_t fullSize, unsigned char *hash);
3aa0061c
VK
843 BOOL LIBNETXMS_EXPORTABLE CalculateFileMD5Hash(const TCHAR *pszFileName, BYTE *pHash);
844 BOOL LIBNETXMS_EXPORTABLE CalculateFileSHA1Hash(const TCHAR *pszFileName, BYTE *pHash);
845 BOOL LIBNETXMS_EXPORTABLE CalculateFileCRC32(const TCHAR *pszFileName, DWORD *pResult);
66c04cc7 846
4e2debcc
VK
847 void LIBNETXMS_EXPORTABLE ICEEncryptData(const BYTE *in, int inLen, BYTE *out, const BYTE *key);
848 void LIBNETXMS_EXPORTABLE ICEDecryptData(const BYTE *in, int inLen, BYTE *out, const BYTE *key);
849
6b1282e7
VK
850 BOOL LIBNETXMS_EXPORTABLE DecryptPassword(const TCHAR *login, const TCHAR *encryptedPasswd, TCHAR *decryptedPasswd);
851
46ef501a
VK
852 DWORD LIBNETXMS_EXPORTABLE IcmpPing(DWORD dwAddr, int iNumRetries, DWORD dwTimeout,
853 DWORD *pdwRTT, DWORD dwPacketSize);
4826c8a5 854
3aa0061c 855 int LIBNETXMS_EXPORTABLE NxDCIDataTypeFromText(const TCHAR *pszText);
aa13cfd9 856
4560d8bd 857 HMODULE LIBNETXMS_EXPORTABLE DLOpen(const TCHAR *pszLibName, TCHAR *pszErrorText);
aa13cfd9 858 void LIBNETXMS_EXPORTABLE DLClose(HMODULE hModule);
dda7c270 859 void LIBNETXMS_EXPORTABLE *DLGetSymbolAddr(HMODULE hModule, const char *pszSymbol, TCHAR *pszErrorText);
aa13cfd9 860
2e06d08b
VK
861 BOOL LIBNETXMS_EXPORTABLE ExtractNamedOptionValue(const TCHAR *optString, const TCHAR *option, TCHAR *buffer, int bufSize);
862 BOOL LIBNETXMS_EXPORTABLE ExtractNamedOptionValueAsBool(const TCHAR *optString, const TCHAR *option, BOOL defVal);
863 long LIBNETXMS_EXPORTABLE ExtractNamedOptionValueAsInt(const TCHAR *optString, const TCHAR *option, long defVal);
ae9cddaf 864
bc858635
VK
865#ifdef __cplusplus
866 const TCHAR LIBNETXMS_EXPORTABLE *CodeToText(int iCode, CODE_TO_TEXT *pTranslator, const TCHAR *pszDefaultText = _T("Unknown"));
867#else
868 const TCHAR LIBNETXMS_EXPORTABLE *CodeToText(int iCode, CODE_TO_TEXT *pTranslator, const TCHAR *pszDefaultText);
869#endif
870
aa13cfd9 871#ifdef _WIN32
4299401e 872 TCHAR LIBNETXMS_EXPORTABLE *GetSystemErrorText(DWORD dwError, TCHAR *pszBuffer, size_t iBufSize);
ccc34207 873 BOOL LIBNETXMS_EXPORTABLE GetWindowsVersionString(TCHAR *versionString, int strSize);
11606542 874 INT64 LIBNETXMS_EXPORTABLE GetProcessRSS();
aa13cfd9 875#endif
696fc54f
VK
876
877#if !(HAVE_DAEMON)
b1a57444 878 int LIBNETXMS_EXPORTABLE daemon(int nochdir, int noclose);
696fc54f 879#endif
4332e9d8 880
3aa0061c 881 DWORD LIBNETXMS_EXPORTABLE inet_addr_w(const WCHAR *pszAddr);
268774a0 882
4332e9d8 883#ifndef _WIN32
664c7c49 884 BOOL LIBNETXMS_EXPORTABLE SetDefaultCodepage(const char *cp);
3aa0061c 885 int LIBNETXMS_EXPORTABLE WideCharToMultiByte(int iCodePage, DWORD dwFlags, const WCHAR *pWideCharStr,
4332e9d8
VK
886 int cchWideChar, char *pByteStr, int cchByteChar,
887 char *pDefaultChar, BOOL *pbUsedDefChar);
3aa0061c 888 int LIBNETXMS_EXPORTABLE MultiByteToWideChar(int iCodePage, DWORD dwFlags, const char *pByteStr,
4332e9d8
VK
889 int cchByteChar, WCHAR *pWideCharStr,
890 int cchWideChar);
04dbaf62 891
6b93c954 892#if !defined(UNICODE_UCS2) || !HAVE_WCSLEN
8b86c5dc 893 int LIBNETXMS_EXPORTABLE ucs2_strlen(const UCS2CHAR *pStr);
6b93c954
VK
894#endif
895#if !defined(UNICODE_UCS2) || !HAVE_WCSNCPY
8b86c5dc 896 UCS2CHAR LIBNETXMS_EXPORTABLE *ucs2_strncpy(UCS2CHAR *pDst, const UCS2CHAR *pSrc, int nDstLen);
6b93c954
VK
897#endif
898#if !defined(UNICODE_UCS2) || !HAVE_WCSDUP
35f836fe 899 UCS2CHAR LIBNETXMS_EXPORTABLE *ucs2__tcsdup(const UCS2CHAR *pStr);
4332e9d8 900#endif
8b86c5dc 901
53c96e2d
VK
902 size_t LIBNETXMS_EXPORTABLE ucs2_to_mb(const UCS2CHAR *src, int srcLen, char *dst, int dstLen);
903 size_t LIBNETXMS_EXPORTABLE mb_to_ucs2(const char *src, int srcLen, UCS2CHAR *dst, int dstLen);
39945910
VK
904 UCS2CHAR LIBNETXMS_EXPORTABLE *UCS2StringFromMBString(const char *pszString);
905 char LIBNETXMS_EXPORTABLE *MBStringFromUCS2String(const UCS2CHAR *pszString);
8b86c5dc 906
6e17f325
VK
907 int LIBNETXMS_EXPORTABLE nx_wprintf(const WCHAR *format, ...);
908 int LIBNETXMS_EXPORTABLE nx_fwprintf(FILE *fp, const WCHAR *format, ...);
909 int LIBNETXMS_EXPORTABLE nx_swprintf(WCHAR *buffer, size_t size, const WCHAR *format, ...);
910 int LIBNETXMS_EXPORTABLE nx_vwprintf(const WCHAR *format, va_list args);
911 int LIBNETXMS_EXPORTABLE nx_vfwprintf(FILE *fp, const WCHAR *format, va_list args);
912 int LIBNETXMS_EXPORTABLE nx_vswprintf(WCHAR *buffer, size_t size, const WCHAR *format, va_list args);
04dbaf62 913
3e39fcde 914#endif /* _WIN32 */
8b86c5dc 915
3aa0061c 916 WCHAR LIBNETXMS_EXPORTABLE *WideStringFromMBString(const char *pszString);
c16afb3d 917 WCHAR LIBNETXMS_EXPORTABLE *WideStringFromUTF8String(const char *pszString);
3aa0061c
VK
918 char LIBNETXMS_EXPORTABLE *MBStringFromWideString(const WCHAR *pwszString);
919 char LIBNETXMS_EXPORTABLE *UTF8StringFromWideString(const WCHAR *pwszString);
8b86c5dc 920
3d1058ed
VK
921#ifdef _WITH_ENCRYPTION
922 WCHAR LIBNETXMS_EXPORTABLE *ERR_error_string_W(int nError, WCHAR *pwszBuffer);
923#endif
924
8b86c5dc 925#ifdef UNICODE_UCS4
53c96e2d
VK
926 size_t LIBNETXMS_EXPORTABLE ucs2_to_ucs4(const UCS2CHAR *src, int srcLen, WCHAR *dst, int dstLen);
927 size_t LIBNETXMS_EXPORTABLE ucs4_to_ucs2(const WCHAR *src, int srcLen, UCS2CHAR *dst, int dstLen);
928 size_t LIBNETXMS_EXPORTABLE ucs2_to_utf8(const UCS2CHAR *src, int srcLen, char *dst, int dstLen);
d9b66a56
VK
929 UCS2CHAR LIBNETXMS_EXPORTABLE *UCS2StringFromUCS4String(const WCHAR *pwszString);
930 WCHAR LIBNETXMS_EXPORTABLE *UCS4StringFromUCS2String(const UCS2CHAR *pszString);
b50f1100 931#endif
8b86c5dc 932
842c22f4
AK
933#if !defined(_WIN32) && !HAVE_WSTAT
934 int wstat(const WCHAR *_path, struct stat *_sbuf);
935#endif
936
ef856d02 937#if defined(UNICODE) && !defined(_WIN32)
d9b66a56 938
f3387429
VK
939#if !HAVE_WPOPEN
940 FILE LIBNETXMS_EXPORTABLE *wpopen(const WCHAR *_command, const WCHAR *_type);
941#endif
8b86c5dc
VK
942#if !HAVE_WFOPEN
943 FILE LIBNETXMS_EXPORTABLE *wfopen(const WCHAR *_name, const WCHAR *_type);
944#endif
945#if !HAVE_WOPEN
946 int LIBNETXMS_EXPORTABLE wopen(const WCHAR *, int, ...);
b50f1100 947#endif
f3387429
VK
948#if !HAVE_WCHMOD
949 int LIBNETXMS_EXPORTABLE wchmod(const WCHAR *_name, int mode);
950#endif
b07c50cc
VK
951#if !HAVE_WCHDIR
952 int wchdir(const WCHAR *_path);
953#endif
954#if !HAVE_WMKDIR
955 int wmkdir(const WCHAR *_path, int mode);
956#endif
957#if !HAVE_WRMDIR
958 int wrmdir(const WCHAR *_path);
959#endif
ccc34207
VK
960#if !HAVE_WRENAME
961 int wrename(const WCHAR *_oldpath, const WCHAR *_newpath);
962#endif
963#if !HAVE_WUNLINK
964 int wunlink(const WCHAR *_path);
965#endif
b07c50cc
VK
966#if !HAVE_WREMOVE
967 int wremove(const WCHAR *_path);
968#endif
969#if !HAVE_WSYSTEM
970 int wsystem(const WCHAR *_cmd);
971#endif
dda7c270
VK
972#if !HAVE_WMKSTEMP
973 int wmkstemp(const WCHAR *_template);
974#endif
b07c50cc
VK
975#if !HAVE_WACCESS
976 int waccess(const WCHAR *_path, int mode);
977#endif
273da39a
VK
978#if !HAVE_WGETENV
979 WCHAR *wgetenv(const WCHAR *_string);
980#endif
f3387429
VK
981#if !HAVE_WCTIME
982 WCHAR *wctime(const time_t *timep);
983#endif
d49d7500
VK
984#if !HAVE_WCSERROR && HAVE_STRERROR
985 WCHAR *wcserror(int errnum);
986#endif
987#if !HAVE_WCSERROR_R && HAVE_STRERROR_R
b0823d06
VK
988#if HAVE_POSIX_STRERROR_R
989 int wcserror_r(int errnum, WCHAR *strerrbuf, size_t buflen);
990#else
d49d7500
VK
991 WCHAR *wcserror_r(int errnum, WCHAR *strerrbuf, size_t buflen);
992#endif
b0823d06 993#endif
e05f8aaf 994
ef856d02 995#endif /* UNICODE && !_WIN32*/
e05f8aaf 996
8b86c5dc
VK
997#if !HAVE_STRTOLL
998 INT64 LIBNETXMS_EXPORTABLE strtoll(const char *nptr, char **endptr, int base);
999#endif
1000#if !HAVE_STRTOULL
1001 QWORD LIBNETXMS_EXPORTABLE strtoull(const char *nptr, char **endptr, int base);
1002#endif
e05f8aaf
VK
1003
1004#if !HAVE_WCSTOLL
1005 INT64 LIBNETXMS_EXPORTABLE wcstoll(const WCHAR *nptr, WCHAR **endptr, int base);
1006#endif
1007#if !HAVE_WCSTOULL
1008 QWORD LIBNETXMS_EXPORTABLE wcstoull(const WCHAR *nptr, WCHAR **endptr, int base);
1009#endif
b50f1100 1010
fa88627b 1011#if !HAVE_WCSDUP && !defined(_WIN32)
37861c72
VK
1012 WCHAR LIBNETXMS_EXPORTABLE *wcsdup(const WCHAR *src);
1013#endif
1014
55e62b45
VK
1015#if !HAVE_STRLWR && !defined(_WIN32)
1016 char LIBNETXMS_EXPORTABLE *strlwr(char *str);
1017 WCHAR LIBNETXMS_EXPORTABLE *wcslwr(WCHAR *str);
1018#endif
1019
3d1cb7d6 1020#ifdef _WIN32
5ea2db30
VK
1021#ifdef UNICODE
1022 DIRW LIBNETXMS_EXPORTABLE *wopendir(const WCHAR *filename);
1023 struct dirent_w LIBNETXMS_EXPORTABLE *wreaddir(DIRW *dirp);
1024 int LIBNETXMS_EXPORTABLE wclosedir(DIRW *dirp);
1025
1026#define _topendir wopendir
1027#define _treaddir wreaddir
1028#define _tclosedir wclosedir
1029#else
1030#define _topendir opendir
1031#define _treaddir readdir
1032#define _tclosedir closedir
1033#endif
1034
3d1cb7d6 1035 DIR LIBNETXMS_EXPORTABLE *opendir(const char *filename);
7f9e0c00 1036 struct dirent LIBNETXMS_EXPORTABLE *readdir(DIR *dirp);
3d1cb7d6 1037 int LIBNETXMS_EXPORTABLE closedir(DIR *dirp);
5ea2db30 1038
76b1d3d8
VK
1039#else /* not _WIN32 */
1040
1041 DIRW LIBNETXMS_EXPORTABLE *wopendir(const WCHAR *filename);
1042 struct dirent_w LIBNETXMS_EXPORTABLE *wreaddir(DIRW *dirp);
1043 int LIBNETXMS_EXPORTABLE wclosedir(DIRW *dirp);
1044
37d62364 1045#endif
3d1cb7d6 1046
7f9e0c00
VK
1047#if defined(_WIN32) || !(HAVE_SCANDIR)
1048 int LIBNETXMS_EXPORTABLE scandir(const char *dir, struct dirent ***namelist,
1049 int (*select)(const struct dirent *),
1050 int (*compar)(const struct dirent **, const struct dirent **));
1051 int LIBNETXMS_EXPORTABLE alphasort(const struct dirent **a, const struct dirent **b);
1052#endif
1053
55b33d4c
VK
1054#ifdef UNDER_CE
1055 int LIBNETXMS_EXPORTABLE _topen(TCHAR *pszName, int nFlags, ...);
1056 int LIBNETXMS_EXPORTABLE read(int hFile, void *pBuffer, size_t nBytes);
1057 int LIBNETXMS_EXPORTABLE write(int hFile, void *pBuffer, size_t nBytes);
1058#endif
1059
9f2902ac 1060BOOL LIBNETXMS_EXPORTABLE nxlog_open(const TCHAR *logName, DWORD flags, const TCHAR *msgModule,
d49d7500 1061 unsigned int msgCount, const TCHAR **messages);
9f2902ac
VK
1062void LIBNETXMS_EXPORTABLE nxlog_close(void);
1063void LIBNETXMS_EXPORTABLE nxlog_write(DWORD msg, WORD wType, const char *format, ...);
5945d50a 1064BOOL LIBNETXMS_EXPORTABLE nxlog_set_rotation_policy(int rotationMode, int maxLogSize, int historySize, const TCHAR *dailySuffix);
4addc3a3 1065BOOL LIBNETXMS_EXPORTABLE nxlog_rotate();
f669df41
VK
1066void LIBNETXMS_EXPORTABLE nxlog_set_console_writer(void (*writer)(const TCHAR *, ...));
1067
1068void LIBNETXMS_EXPORTABLE WriteToTerminal(const TCHAR *text);
1069void LIBNETXMS_EXPORTABLE WriteToTerminalEx(const TCHAR *format, ...);
9f2902ac 1070
37a7a862
VK
1071#ifdef _WIN32
1072int LIBNETXMS_EXPORTABLE mkstemp(char *tmpl);
1073int LIBNETXMS_EXPORTABLE wmkstemp(WCHAR *tmpl);
1074#ifdef UNICODE
1075#define _tmkstemp wmkstemp
1076#else
1077#define _tmkstemp mkstemp
1078#endif
1079#endif
1080
9b13553b
VK
1081#ifndef _WIN32
1082int strcat_s(char *dst, size_t dstSize, const char *src);
1083int wcscat_s(WCHAR *dst, size_t dstSize, const WCHAR *src);
1084#endif
1085
b50f1100 1086#ifdef __cplusplus
e9246d26 1087}
b50f1100 1088#endif
e9246d26 1089
a7ff20a5
VK
1090
1091//
1092// C++ only finctions
1093//
1094
1095#ifdef __cplusplus
1096
53c96e2d 1097TCHAR LIBNETXMS_EXPORTABLE *EscapeStringForXML(const TCHAR *string, int length);
a7ff20a5 1098String LIBNETXMS_EXPORTABLE EscapeStringForXML2(const TCHAR *string, int length = -1);
53c96e2d
VK
1099const char LIBNETXMS_EXPORTABLE *XMLGetAttr(const char **attrs, const char *name);
1100int LIBNETXMS_EXPORTABLE XMLGetAttrInt(const char **attrs, const char *name, int defVal);
1101DWORD LIBNETXMS_EXPORTABLE XMLGetAttrDWORD(const char **attrs, const char *name, DWORD defVal);
1102bool LIBNETXMS_EXPORTABLE XMLGetAttrBoolean(const char **attrs, const char *name, bool defVal);
1103
1104#if !defined(_WIN32) && !defined(_NETWARE) && defined(NMS_THREADS_H_INCLUDED)
1105void LIBNETXMS_EXPORTABLE StartMainLoop(THREAD_RESULT (THREAD_CALL * pfSignalHandler)(void *),
1106 THREAD_RESULT (THREAD_CALL * pfMain)(void *));
1107#endif
1108
1109void LIBNETXMS_EXPORTABLE InitSubAgentAPI(void (* writeLog)(int, int, const TCHAR *),
2dd24569
VK
1110 void (* sendTrap1)(DWORD, const TCHAR *, const char *, va_list),
1111 void (* sendTrap2)(DWORD, const TCHAR *, int, TCHAR **),
53c96e2d
VK
1112 BOOL (* sendFile)(void *, DWORD, const TCHAR *, long),
1113 BOOL (* pushData)(const TCHAR *, const TCHAR *));
a7ff20a5
VK
1114
1115#endif
1116
e9246d26 1117#endif /* _nms_util_h_ */