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