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