MBCS patch partially applied (set only)
[public/netxms.git] / include / nms_util.h
CommitLineData
e9246d26 1/*
7ac71e60 2** NetXMS - Network Management System
7c521895 3** Copyright (C) 2003-2010 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
78
79
dcb44c9a 80//
4826c8a5 81// Token types for configuration loader
dcb44c9a
VK
82//
83
4826c8a5
VK
84#define CT_LONG 0
85#define CT_STRING 1
86#define CT_STRING_LIST 2
87#define CT_END_OF_LIST 3
88#define CT_BOOLEAN 4
89#define CT_WORD 5
fc935a60 90#define CT_IGNORE 6
4826c8a5
VK
91
92
93//
94// Return codes for NxLoadConfig()
95//
96
97#define NXCFG_ERR_OK 0
98#define NXCFG_ERR_NOFILE 1
99#define NXCFG_ERR_SYNTAX 2
100
101
9f2902ac
VK
102//
103// nxlog_open() flags
104//
105
106#define NXLOG_USE_SYSLOG ((DWORD)0x00000001)
107#define NXLOG_PRINT_TO_STDOUT ((DWORD)0x00000002)
108#define NXLOG_IS_OPEN ((DWORD)0x80000000)
109
110
8ff13508
VK
111//
112// strdup() replacement
113//
114
115#if defined(_WIN32) && defined(USE_WIN32_HEAP)
116#ifdef __cplusplus
117extern "C" {
118#endif
119char LIBNETXMS_EXPORTABLE *nx_strdup(const char *src);
120WCHAR LIBNETXMS_EXPORTABLE *nx_wcsdup(const WCHAR *src);
121#ifdef __cplusplus
122}
123#endif
124#endif
125
126
b160350d
VK
127//
128// Class for serial communications
129//
130
131#ifdef __cplusplus
132
133#ifndef _WIN32
134enum
135{
136 NOPARITY,
137 ODDPARITY,
138 EVENPARITY,
139 ONESTOPBIT,
140 TWOSTOPBITS
141};
142
70fed300
AK
143enum
144{
145 FLOW_NONE,
146 FLOW_HARDWARE,
147 FLOW_SOFTWARE
148};
149
b160350d
VK
150#ifndef INVALID_HANDLE_VALUE
151#define INVALID_HANDLE_VALUE (-1)
152#endif
153#endif /* _WIN32 */
154
155class LIBNETXMS_EXPORTABLE Serial
156{
157public:
158 Serial(void);
159 ~Serial(void);
160
e2d68ddd 161 bool Open(const TCHAR *pszPort);
b160350d
VK
162 void Close(void);
163 void SetTimeout(int nTimeout);
f3a581d0
AK
164 int Read(char *pBuff, int nSize); /* waits up to timeout and do single read */
165 int ReadAll(char *pBuff, int nSize); /* read until timeout or out of space */
e2d68ddd 166 bool Write(const char *pBuff, int nSize);
b160350d
VK
167 void Flush(void);
168 bool Set(int nSpeed, int nDataBits, int nParity, int nStopBits);
70fed300 169 bool Set(int nSpeed, int nDataBits, int nParity, int nStopBits, int nFlowControl);
b160350d
VK
170 bool Restart(void);
171
172private:
173 TCHAR *m_pszPort;
174 int m_nTimeout;
175 int m_nSpeed;
176 int m_nDataBits;
177 int m_nStopBits;
178 int m_nParity;
70fed300 179 int m_nFlowControl;
b160350d
VK
180
181#ifndef _WIN32
182 int m_hPort;
70fed300 183 struct termios m_originalSettings;
b160350d
VK
184#else
185 HANDLE m_hPort;
186#endif
187};
188
ff214673
VK
189
190//
191// Class for table data storage
192//
193
ccc34207
VK
194class CSCPMessage;
195
ff214673
VK
196class LIBNETXMS_EXPORTABLE Table
197{
198private:
199 int m_nNumRows;
200 int m_nNumCols;
201 TCHAR **m_ppData;
202 TCHAR **m_ppColNames;
e31c8e60
VK
203 LONG *m_colFormats;
204 TCHAR *m_title;
ff214673
VK
205
206public:
207 Table();
ccc34207 208 Table(CSCPMessage *msg);
ff214673
VK
209 ~Table();
210
3d5610eb 211 int fillMessage(CSCPMessage &msg, int offset, int rowLimit);
9e126e57 212
e31c8e60
VK
213 int getNumRows() { return m_nNumRows; }
214 int getNumColumns() { return m_nNumCols; }
215 const TCHAR *getTitle() { return CHECK_NULL_EX(m_title); }
9e126e57 216
e31c8e60
VK
217 const TCHAR *getColumnName(int col) { return ((col >= 0) && (col < m_nNumCols)) ? m_ppColNames[col] : NULL; }
218 LONG getColumnFormat(int col) { return ((col >= 0) && (col < m_nNumCols)) ? m_colFormats[col] : 0; }
219
220 void setTitle(const TCHAR *title) { safe_free(m_title); m_title = (title != NULL) ? _tcsdup(title) : NULL; }
221 int addColumn(const TCHAR *name, LONG format = 0);
222 int addRow();
9e126e57
VK
223
224 void setAt(int nRow, int nCol, LONG nData);
225 void setAt(int nRow, int nCol, DWORD dwData);
226 void setAt(int nRow, int nCol, double dData);
227 void setAt(int nRow, int nCol, INT64 nData);
228 void setAt(int nRow, int nCol, QWORD qwData);
229 void setAt(int nRow, int nCol, const TCHAR *pszData);
230 void setPreallocatedAt(int nRow, int nCol, TCHAR *pszData);
231
232 void set(int nCol, LONG nData) { setAt(m_nNumRows - 1, nCol, nData); }
233 void set(int nCol, DWORD dwData) { setAt(m_nNumRows - 1, nCol, dwData); }
234 void set(int nCol, double dData) { setAt(m_nNumRows - 1, nCol, dData); }
235 void set(int nCol, INT64 nData) { setAt(m_nNumRows - 1, nCol, nData); }
236 void set(int nCol, QWORD qwData) { setAt(m_nNumRows - 1, nCol, qwData); }
237 void set(int nCol, const TCHAR *pszData) { setAt(m_nNumRows - 1, nCol, pszData); }
238 void setPreallocated(int nCol, TCHAR *pszData) { setPreallocatedAt(m_nNumRows - 1, nCol, pszData); }
239
240 const TCHAR *getAsString(int nRow, int nCol);
241 LONG getAsInt(int nRow, int nCol);
242 DWORD getAsUInt(int nRow, int nCol);
243 INT64 getAsInt64(int nRow, int nCol);
244 QWORD getAsUInt64(int nRow, int nCol);
245 double getAsDouble(int nRow, int nCol);
ff214673
VK
246};
247
8bad8476
VK
248
249//
250// Dynamic string class
251//
252
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
ce7565e7 267 void setBuffer(TCHAR *pszBuffer);
8bad8476 268
2391d4fd 269 const String& operator =(const TCHAR *pszStr);
49bf9d8d 270 const String& operator =(const String &src);
2391d4fd 271 const String& operator +=(const TCHAR *pszStr);
ce7565e7 272 operator const TCHAR*() { return CHECK_NULL_EX(m_pszBuffer); }
8bad8476 273
ce7565e7
VK
274 void addString(const TCHAR *pStr, DWORD dwLen);
275 void addDynamicString(TCHAR *pszStr) { if (pszStr != NULL) { *this += pszStr; free(pszStr); } }
c577e360 276
ce7565e7
VK
277 void addMultiByteString(const char *pStr, DWORD dwSize, int nCodePage);
278 void addWideCharString(const WCHAR *pStr, DWORD dwSize);
ff175e91 279
ce7565e7 280 void addFormattedString(const TCHAR *format, ...);
893dfdd7 281 void addFormattedStringV(const TCHAR *format, va_list args);
ce7565e7
VK
282 void escapeCharacter(int ch, int esc);
283 void translate(const TCHAR *pszSrc, const TCHAR *pszDst);
c577e360 284
ce7565e7
VK
285 DWORD getSize() { return m_dwBufSize > 0 ? m_dwBufSize - 1 : 0; }
286 BOOL isEmpty() { return m_dwBufSize <= 1; }
c577e360 287
ce7565e7
VK
288 TCHAR *subStr(int nStart, int nLen, TCHAR *pszBuffer);
289 TCHAR *subStr(int nStart, int nLen) { return subStr(nStart, nLen, NULL); }
290 int find(const TCHAR *pszStr, int nStart = 0);
1e1450ef 291
0bbab9d3
VK
292 void trim();
293 void shrink(int chars = 1);
c577e360
VK
294};
295
296
297//
298// String map class
299//
300
301class LIBNETXMS_EXPORTABLE StringMap
302{
303protected:
fb986055
VK
304 DWORD m_size;
305 TCHAR **m_keys;
306 TCHAR **m_values;
c577e360 307
fb986055 308 DWORD find(const TCHAR *key);
c577e360
VK
309
310public:
311 StringMap();
fb986055 312 StringMap(const StringMap &src);
c577e360
VK
313 ~StringMap();
314
fb986055 315 StringMap& operator =(const StringMap &src);
40b7416c 316
fb986055
VK
317 void set(const TCHAR *key, const TCHAR *value);
318 void setPreallocated(TCHAR *key, TCHAR *value);
319 const TCHAR *get(const TCHAR *key);
320 void remove(const TCHAR *key);
321 void clear();
c577e360 322
fb986055
VK
323 DWORD getSize() { return m_size; }
324 const TCHAR *getKeyByIndex(DWORD idx) { return (idx < m_size) ? CHECK_NULL_EX(m_keys[idx]) : NULL; }
325 const TCHAR *getValueByIndex(DWORD idx) { return (idx < m_size) ? CHECK_NULL_EX(m_values[idx]) : NULL; }
8bad8476
VK
326};
327
6173bea8
VK
328
329//
330// String list class
331//
332
333class LIBNETXMS_EXPORTABLE StringList
334{
335private:
336 int m_count;
337 int m_allocated;
338 TCHAR **m_values;
339
340public:
341 StringList();
342 ~StringList();
343
344 void add(const TCHAR *value);
345 void addPreallocated(TCHAR *value);
346 void add(LONG value);
347 void add(DWORD value);
348 void add(INT64 value);
349 void add(QWORD value);
350 void add(double value);
351 void clear();
352 int getSize() { return m_count; }
353 const TCHAR *getValue(int index) { return ((index >=0) && (index < m_count)) ? m_values[index] : NULL; }
354};
355
b160350d
VK
356#endif /* __cplusplus */
357
358
4826c8a5
VK
359//
360// Configuration item template for configuration loader
361//
362
363typedef struct
364{
018fda4d 365 TCHAR szToken[64];
4826c8a5
VK
366 BYTE iType;
367 BYTE cSeparator; // Separator character for lists
368 WORD wListElements; // Number of list elements, should be set to 0 before calling NxLoadConfig()
369 DWORD dwBufferSize; // Buffer size for strings or flag to be set for CT_BOOLEAN
370 DWORD dwBufferPos; // Should be set to 0
371 void *pBuffer;
372} NX_CFG_TEMPLATE;
dcb44c9a
VK
373
374
bc858635
VK
375//
376// Code translation structure
377//
378
379typedef struct __CODE_TO_TEXT
380{
381 int code;
382 const TCHAR *text;
383} CODE_TO_TEXT;
384
385
3046f9a4
VK
386//
387// getopt() prototype if needed
388//
389
390#ifdef _WIN32
99e50bb7 391#include <netxms_getopt.h>
3046f9a4
VK
392#endif
393
394
f2fdf1b5
VK
395//
396// Win32 API functions missing under WinCE
397//
398
c32b805a 399#if defined(UNDER_CE) && defined(__cplusplus)
f2fdf1b5
VK
400
401inline void GetSystemTimeAsFileTime(LPFILETIME pFt)
402{
403 SYSTEMTIME sysTime;
404
405 GetSystemTime(&sysTime);
406 SystemTimeToFileTime(&sysTime, pFt);
407}
408
409#endif // UNDER_CE
410
411
3d1cb7d6
VK
412//
413// Structures for opendir() / readdir() / closedir()
414//
415
416#ifdef _WIN32
417
37d62364
AK
418#ifndef SWIGPERL
419
7f9e0c00 420typedef struct dirent
3d1cb7d6
VK
421{
422 long d_ino; /* inode number (not used by MS-DOS) */
423 int d_namlen; /* Name length */
424 char d_name[257]; /* file name */
425} _DIRECT;
426
427typedef struct _dir_struc
428{
429 char *start; /* Starting position */
430 char *curr; /* Current position */
431 long size; /* Size of string table */
432 long nfiles; /* number if filenames in table */
7f9e0c00 433 struct dirent dirstr; /* Directory structure to return */
3d1cb7d6
VK
434} DIR;
435
37d62364
AK
436#endif
437
3d1cb7d6
VK
438#endif /* _WIN32 */
439
440
e9246d26
VK
441//
442// Functions
443//
444
43d92b4c 445
babb8280 446#if WORDS_BIGENDIAN
43d92b4c
VK
447#define htonq(x) (x)
448#define ntohq(x) (x)
9f20696e
VK
449#define htond(x) (x)
450#define ntohd(x) (x)
babb8280
VK
451#define SwapWideString(x)
452#else
ca6ad6bb
VK
453#ifdef HAVE_HTONLL
454#define htonq(x) htonll(x)
455#else
babb8280 456#define htonq(x) __bswap_64(x)
ca6ad6bb
VK
457#endif
458#ifdef HAVE_NTOHLL
459#define ntohq(x) ntohll(x)
460#else
babb8280 461#define ntohq(x) __bswap_64(x)
ca6ad6bb 462#endif
babb8280
VK
463#define htond(x) __bswap_double(x)
464#define ntohd(x) __bswap_double(x)
465#define SwapWideString(x) __bswap_wstr(x)
43d92b4c 466#endif
15929b31 467
55b33d4c
VK
468#ifdef UNDER_CE
469#define close(x) CloseHandle((HANDLE)(x))
470#endif
471
c81979bc
VK
472#ifdef __cplusplus
473#ifndef LIBNETXMS_INLINE
4299401e 474 inline TCHAR *nx_strncpy(TCHAR *pszDest, const TCHAR *pszSrc, size_t nLen)
c81979bc 475 {
912b994d
VK
476#if defined(_WIN32) && (_MSC_VER >= 1400)
477 _tcsncpy_s(pszDest, nLen, pszSrc, _TRUNCATE);
478#else
c81979bc
VK
479 _tcsncpy(pszDest, pszSrc, nLen - 1);
480 pszDest[nLen - 1] = 0;
912b994d 481#endif
c81979bc
VK
482 return pszDest;
483 }
484#endif
485#else
4299401e 486 TCHAR LIBNETXMS_EXPORTABLE *nx_strncpy(TCHAR *pszDest, const TCHAR *pszSrc, size_t nLen);
c81979bc
VK
487#endif
488
b50f1100 489#ifdef __cplusplus
e9246d26
VK
490extern "C"
491{
b50f1100 492#endif
7c521895 493 int LIBNETXMS_EXPORTABLE ConnectEx(SOCKET s, struct sockaddr *addr, int len, DWORD timeout);
08043edf
VK
494 int LIBNETXMS_EXPORTABLE SendEx(SOCKET, const void *, size_t, int);
495 int LIBNETXMS_EXPORTABLE RecvEx(SOCKET nSocket, const void *pBuff,
496 size_t nSize, int nFlags, DWORD dwTimeout);
b24955fb 497
c5b523e2
VK
498#if defined(_WIN32) || !(HAVE_DECL___BSWAP_32)
499 DWORD LIBNETXMS_EXPORTABLE __bswap_32(DWORD dwVal);
500#endif
f52be742 501#if defined(_WIN32) || !(HAVE_DECL___BSWAP_64)
64584976
VK
502 QWORD LIBNETXMS_EXPORTABLE __bswap_64(QWORD qwVal);
503#endif
9f20696e 504 double LIBNETXMS_EXPORTABLE __bswap_double(double dVal);
273da39a 505 void LIBNETXMS_EXPORTABLE __bswap_wstr(UCS2CHAR *pStr);
64584976 506
076a55c4 507#if !defined(_WIN32) && !defined(_NETWARE)
8b86c5dc
VK
508#if defined(UNICODE_UCS2) || defined(UNICODE_UCS4)
509 void LIBNETXMS_EXPORTABLE wcsupr(WCHAR *in);
510#endif
511 void LIBNETXMS_EXPORTABLE strupr(char *in);
7e679c4b 512#endif
ab588c84 513
b8a8d064
VK
514 void LIBNETXMS_EXPORTABLE QSortEx(void *base, size_t nmemb, size_t size, void *arg,
515 int (*compare)(const void *, const void *, void *));
516
670c7f3d 517 INT64 LIBNETXMS_EXPORTABLE GetCurrentTimeMs(void);
3aa0061c 518 QWORD LIBNETXMS_EXPORTABLE FileSize(const TCHAR *pszFileName);
670c7f3d 519
64584976 520 int LIBNETXMS_EXPORTABLE BitsInMask(DWORD dwMask);
018fda4d 521 TCHAR LIBNETXMS_EXPORTABLE *IpToStr(DWORD dwAddr, TCHAR *szBuffer);
3aa0061c 522 DWORD LIBNETXMS_EXPORTABLE ResolveHostName(const TCHAR *pszName);
a1dc75b0 523
64584976 524 void LIBNETXMS_EXPORTABLE *nx_memdup(const void *pData, DWORD dwSize);
f218dc6d 525 void LIBNETXMS_EXPORTABLE nx_memswap(void *pBlock1, void *pBlock2, DWORD dwSize);
31521248 526
e25cadc9 527 TCHAR LIBNETXMS_EXPORTABLE *BinToStr(BYTE *pData, DWORD dwSize, TCHAR *pStr);
3aa0061c 528 DWORD LIBNETXMS_EXPORTABLE StrToBin(const TCHAR *pStr, BYTE *pData, DWORD dwSize);
c61f5190 529 void LIBNETXMS_EXPORTABLE MACToStr(BYTE *pData, TCHAR *pStr);
b50f1100 530
018fda4d 531 void LIBNETXMS_EXPORTABLE StrStrip(TCHAR *pszStr);
0bbab9d3 532 void LIBNETXMS_EXPORTABLE Trim(TCHAR *str);
018fda4d 533 BOOL LIBNETXMS_EXPORTABLE MatchString(const TCHAR *pattern, const TCHAR *string, BOOL matchCase);
9eea20df 534 BOOL LIBNETXMS_EXPORTABLE RegexpMatch(const TCHAR *pszStr, const TCHAR *pszExpr, BOOL bMatchCase);
018fda4d 535 TCHAR LIBNETXMS_EXPORTABLE *ExtractWord(TCHAR *line, TCHAR *buffer);
f3cdd1c5 536 TCHAR LIBNETXMS_EXPORTABLE **SplitString(const TCHAR *source, TCHAR sep, int *numStrings);
2391d4fd 537 int LIBNETXMS_EXPORTABLE NumChars(const TCHAR *pszStr, int ch);
3783d300 538 void LIBNETXMS_EXPORTABLE RemoveTrailingCRLF(TCHAR *str);
f7794b68
VK
539#ifdef __cplusplus
540 BOOL LIBNETXMS_EXPORTABLE IsValidObjectName(const TCHAR *pszName, BOOL bExtendedChars = FALSE);
541#endif
fa2b47a7 542 BOOL LIBNETXMS_EXPORTABLE IsValidScriptName(const TCHAR *pszName);
2391d4fd 543 void LIBNETXMS_EXPORTABLE TranslateStr(TCHAR *pszString, const TCHAR *pszSubStr, const TCHAR *pszReplace);
257defd7 544 TCHAR LIBNETXMS_EXPORTABLE *GetCleanFileName(TCHAR *pszFileName);
c3cfc039 545 void LIBNETXMS_EXPORTABLE GetOSVersionString(TCHAR *pszBuffer, int nBufSize);
3aa0061c 546 BYTE LIBNETXMS_EXPORTABLE *LoadFile(const TCHAR *pszFileName, DWORD *pdwFileSize);
ec4995e6 547
6120112b 548 DWORD LIBNETXMS_EXPORTABLE CalculateCRC32(const unsigned char *pData, DWORD dwSize, DWORD dwCRC);
a3c76aba 549 void LIBNETXMS_EXPORTABLE CalculateMD5Hash(const unsigned char *data, size_t nbytes, unsigned char *hash);
e0d4b618 550 void LIBNETXMS_EXPORTABLE MD5HashForPattern(const unsigned char *data, size_t patternSize, size_t fullSize, BYTE *hash);
a3c76aba 551 void LIBNETXMS_EXPORTABLE CalculateSHA1Hash(unsigned char *data, size_t nbytes, unsigned char *hash);
e0d4b618 552 void LIBNETXMS_EXPORTABLE SHA1HashForPattern(unsigned char *data, size_t patternSize, size_t fullSize, unsigned char *hash);
3aa0061c
VK
553 BOOL LIBNETXMS_EXPORTABLE CalculateFileMD5Hash(const TCHAR *pszFileName, BYTE *pHash);
554 BOOL LIBNETXMS_EXPORTABLE CalculateFileSHA1Hash(const TCHAR *pszFileName, BYTE *pHash);
555 BOOL LIBNETXMS_EXPORTABLE CalculateFileCRC32(const TCHAR *pszFileName, DWORD *pResult);
66c04cc7 556
4e2debcc
VK
557 void LIBNETXMS_EXPORTABLE ICEEncryptData(const BYTE *in, int inLen, BYTE *out, const BYTE *key);
558 void LIBNETXMS_EXPORTABLE ICEDecryptData(const BYTE *in, int inLen, BYTE *out, const BYTE *key);
559
6b1282e7
VK
560 BOOL LIBNETXMS_EXPORTABLE DecryptPassword(const TCHAR *login, const TCHAR *encryptedPasswd, TCHAR *decryptedPasswd);
561
46ef501a
VK
562 DWORD LIBNETXMS_EXPORTABLE IcmpPing(DWORD dwAddr, int iNumRetries, DWORD dwTimeout,
563 DWORD *pdwRTT, DWORD dwPacketSize);
4826c8a5 564
e6c91aac
VK
565 /* deprecated:
566 DWORD LIBNETXMS_EXPORTABLE NxLoadConfig(const TCHAR *pszFileName, const TCHAR *pszSection,
567 NX_CFG_TEMPLATE *pTemplateList, BOOL bPrint);*/
3aa0061c 568 int LIBNETXMS_EXPORTABLE NxDCIDataTypeFromText(const TCHAR *pszText);
aa13cfd9 569
4560d8bd 570 HMODULE LIBNETXMS_EXPORTABLE DLOpen(const TCHAR *pszLibName, TCHAR *pszErrorText);
aa13cfd9 571 void LIBNETXMS_EXPORTABLE DLClose(HMODULE hModule);
4560d8bd 572 void LIBNETXMS_EXPORTABLE *DLGetSymbolAddr(HMODULE hModule, const TCHAR *pszSymbol, TCHAR *pszErrorText);
aa13cfd9 573
c303351c 574 void LIBNETXMS_EXPORTABLE InitSubAgentAPI(void (* writeLog)(int, int, const TCHAR *),
6173bea8
VK
575 void (* sendTrap2)(DWORD, const char *, va_list),
576 void (* sendTrap1)(DWORD, int, TCHAR **),
f480bdd4
VK
577 BOOL (* sendFile)(void *, DWORD, const TCHAR *, long),
578 BOOL (* pushData)(const TCHAR *, const TCHAR *));
2e06d08b 579
2e06d08b
VK
580 BOOL LIBNETXMS_EXPORTABLE ExtractNamedOptionValue(const TCHAR *optString, const TCHAR *option, TCHAR *buffer, int bufSize);
581 BOOL LIBNETXMS_EXPORTABLE ExtractNamedOptionValueAsBool(const TCHAR *optString, const TCHAR *option, BOOL defVal);
582 long LIBNETXMS_EXPORTABLE ExtractNamedOptionValueAsInt(const TCHAR *optString, const TCHAR *option, long defVal);
ae9cddaf 583
92502d5f 584 TCHAR LIBNETXMS_EXPORTABLE *EscapeStringForXML(const TCHAR *string, int length);
66ae1b17
VK
585 const char LIBNETXMS_EXPORTABLE *XMLGetAttr(const char **attrs, const char *name);
586 int LIBNETXMS_EXPORTABLE XMLGetAttrInt(const char **attrs, const char *name, int defVal);
af885dca 587 DWORD LIBNETXMS_EXPORTABLE XMLGetAttrDWORD(const char **attrs, const char *name, DWORD defVal);
ccc34207 588 bool LIBNETXMS_EXPORTABLE XMLGetAttrBoolean(const char **attrs, const char *name, bool defVal);
92502d5f 589
bc858635
VK
590#ifdef __cplusplus
591 const TCHAR LIBNETXMS_EXPORTABLE *CodeToText(int iCode, CODE_TO_TEXT *pTranslator, const TCHAR *pszDefaultText = _T("Unknown"));
592#else
593 const TCHAR LIBNETXMS_EXPORTABLE *CodeToText(int iCode, CODE_TO_TEXT *pTranslator, const TCHAR *pszDefaultText);
594#endif
595
aa13cfd9 596#ifdef _WIN32
4299401e 597 TCHAR LIBNETXMS_EXPORTABLE *GetSystemErrorText(DWORD dwError, TCHAR *pszBuffer, size_t iBufSize);
ccc34207 598 BOOL LIBNETXMS_EXPORTABLE GetWindowsVersionString(TCHAR *versionString, int strSize);
11606542 599 INT64 LIBNETXMS_EXPORTABLE GetProcessRSS();
aa13cfd9 600#endif
696fc54f
VK
601
602#if !(HAVE_DAEMON)
b1a57444 603 int LIBNETXMS_EXPORTABLE daemon(int nochdir, int noclose);
696fc54f 604#endif
4332e9d8 605
3aa0061c 606 DWORD LIBNETXMS_EXPORTABLE inet_addr_w(const WCHAR *pszAddr);
268774a0 607
4332e9d8 608#ifndef _WIN32
664c7c49 609 BOOL LIBNETXMS_EXPORTABLE SetDefaultCodepage(const char *cp);
3aa0061c 610 int LIBNETXMS_EXPORTABLE WideCharToMultiByte(int iCodePage, DWORD dwFlags, const WCHAR *pWideCharStr,
4332e9d8
VK
611 int cchWideChar, char *pByteStr, int cchByteChar,
612 char *pDefaultChar, BOOL *pbUsedDefChar);
3aa0061c 613 int LIBNETXMS_EXPORTABLE MultiByteToWideChar(int iCodePage, DWORD dwFlags, const char *pByteStr,
4332e9d8
VK
614 int cchByteChar, WCHAR *pWideCharStr,
615 int cchWideChar);
04dbaf62 616
6b93c954 617#if !defined(UNICODE_UCS2) || !HAVE_WCSLEN
8b86c5dc 618 int LIBNETXMS_EXPORTABLE ucs2_strlen(const UCS2CHAR *pStr);
6b93c954
VK
619#endif
620#if !defined(UNICODE_UCS2) || !HAVE_WCSNCPY
8b86c5dc 621 UCS2CHAR LIBNETXMS_EXPORTABLE *ucs2_strncpy(UCS2CHAR *pDst, const UCS2CHAR *pSrc, int nDstLen);
6b93c954
VK
622#endif
623#if !defined(UNICODE_UCS2) || !HAVE_WCSDUP
8b86c5dc 624 UCS2CHAR LIBNETXMS_EXPORTABLE *ucs2_strdup(const UCS2CHAR *pStr);
4332e9d8 625#endif
8b86c5dc
VK
626
627#ifndef UNICODE
628 size_t LIBNETXMS_EXPORTABLE ucs2_to_mb(const UCS2CHAR *src, size_t srcLen, char *dst, size_t dstLen);
629 size_t LIBNETXMS_EXPORTABLE mb_to_ucs2(const char *src, size_t srcLen, UCS2CHAR *dst, size_t dstLen);
39945910
VK
630 UCS2CHAR LIBNETXMS_EXPORTABLE *UCS2StringFromMBString(const char *pszString);
631 char LIBNETXMS_EXPORTABLE *MBStringFromUCS2String(const UCS2CHAR *pszString);
8b86c5dc
VK
632#endif
633
04dbaf62 634#ifdef UNICODE
6e17f325
VK
635 int LIBNETXMS_EXPORTABLE nx_wprintf(const WCHAR *format, ...);
636 int LIBNETXMS_EXPORTABLE nx_fwprintf(FILE *fp, const WCHAR *format, ...);
637 int LIBNETXMS_EXPORTABLE nx_swprintf(WCHAR *buffer, size_t size, const WCHAR *format, ...);
638 int LIBNETXMS_EXPORTABLE nx_vwprintf(const WCHAR *format, va_list args);
639 int LIBNETXMS_EXPORTABLE nx_vfwprintf(FILE *fp, const WCHAR *format, va_list args);
640 int LIBNETXMS_EXPORTABLE nx_vswprintf(WCHAR *buffer, size_t size, const WCHAR *format, va_list args);
04dbaf62
VK
641#endif
642
3e39fcde 643#endif /* _WIN32 */
8b86c5dc 644
3aa0061c 645 WCHAR LIBNETXMS_EXPORTABLE *WideStringFromMBString(const char *pszString);
c16afb3d 646 WCHAR LIBNETXMS_EXPORTABLE *WideStringFromUTF8String(const char *pszString);
3aa0061c
VK
647 char LIBNETXMS_EXPORTABLE *MBStringFromWideString(const WCHAR *pwszString);
648 char LIBNETXMS_EXPORTABLE *UTF8StringFromWideString(const WCHAR *pwszString);
8b86c5dc 649
3d1058ed
VK
650#ifdef _WITH_ENCRYPTION
651 WCHAR LIBNETXMS_EXPORTABLE *ERR_error_string_W(int nError, WCHAR *pwszBuffer);
652#endif
653
8b86c5dc
VK
654#ifdef UNICODE_UCS4
655 size_t LIBNETXMS_EXPORTABLE ucs2_to_ucs4(const UCS2CHAR *src, size_t srcLen, WCHAR *dst, size_t dstLen);
656 size_t LIBNETXMS_EXPORTABLE ucs4_to_ucs2(const WCHAR *src, size_t srcLen, UCS2CHAR *dst, size_t dstLen);
b6e8dffe 657 size_t LIBNETXMS_EXPORTABLE ucs2_to_utf8(const UCS2CHAR *src, size_t srcLen, char *dst, size_t dstLen);
d9b66a56
VK
658 UCS2CHAR LIBNETXMS_EXPORTABLE *UCS2StringFromUCS4String(const WCHAR *pwszString);
659 WCHAR LIBNETXMS_EXPORTABLE *UCS4StringFromUCS2String(const UCS2CHAR *pszString);
b50f1100 660#endif
8b86c5dc 661
d9b66a56
VK
662#ifdef UNICODE
663
8b86c5dc
VK
664#if !HAVE_WFOPEN
665 FILE LIBNETXMS_EXPORTABLE *wfopen(const WCHAR *_name, const WCHAR *_type);
666#endif
667#if !HAVE_WOPEN
668 int LIBNETXMS_EXPORTABLE wopen(const WCHAR *, int, ...);
b50f1100 669#endif
8b86c5dc
VK
670#if !HAVE_WSTAT
671 int wstat(const WCHAR *_path, struct stat *_sbuf);
dde96745 672#endif
ccc34207
VK
673#if !HAVE_WRENAME
674 int wrename(const WCHAR *_oldpath, const WCHAR *_newpath);
675#endif
676#if !HAVE_WUNLINK
677 int wunlink(const WCHAR *_path);
678#endif
273da39a
VK
679#if !HAVE_WGETENV
680 WCHAR *wgetenv(const WCHAR *_string);
681#endif
d49d7500
VK
682#if !HAVE_WCSERROR && HAVE_STRERROR
683 WCHAR *wcserror(int errnum);
684#endif
685#if !HAVE_WCSERROR_R && HAVE_STRERROR_R
b0823d06
VK
686#if HAVE_POSIX_STRERROR_R
687 int wcserror_r(int errnum, WCHAR *strerrbuf, size_t buflen);
688#else
d49d7500
VK
689 WCHAR *wcserror_r(int errnum, WCHAR *strerrbuf, size_t buflen);
690#endif
b0823d06 691#endif
e05f8aaf
VK
692
693#endif /* UNICODE */
694
8b86c5dc
VK
695#if !HAVE_STRTOLL
696 INT64 LIBNETXMS_EXPORTABLE strtoll(const char *nptr, char **endptr, int base);
697#endif
698#if !HAVE_STRTOULL
699 QWORD LIBNETXMS_EXPORTABLE strtoull(const char *nptr, char **endptr, int base);
700#endif
e05f8aaf
VK
701
702#if !HAVE_WCSTOLL
703 INT64 LIBNETXMS_EXPORTABLE wcstoll(const WCHAR *nptr, WCHAR **endptr, int base);
704#endif
705#if !HAVE_WCSTOULL
706 QWORD LIBNETXMS_EXPORTABLE wcstoull(const WCHAR *nptr, WCHAR **endptr, int base);
707#endif
b50f1100 708
3d1cb7d6 709#ifdef _WIN32
37d62364 710#ifndef SWIGPERL
3d1cb7d6 711 DIR LIBNETXMS_EXPORTABLE *opendir(const char *filename);
7f9e0c00 712 struct dirent LIBNETXMS_EXPORTABLE *readdir(DIR *dirp);
3d1cb7d6
VK
713 int LIBNETXMS_EXPORTABLE closedir(DIR *dirp);
714#endif
37d62364 715#endif
3d1cb7d6 716
7f9e0c00
VK
717#if defined(_WIN32) || !(HAVE_SCANDIR)
718 int LIBNETXMS_EXPORTABLE scandir(const char *dir, struct dirent ***namelist,
719 int (*select)(const struct dirent *),
720 int (*compar)(const struct dirent **, const struct dirent **));
721 int LIBNETXMS_EXPORTABLE alphasort(const struct dirent **a, const struct dirent **b);
722#endif
723
55b33d4c
VK
724#ifdef UNDER_CE
725 int LIBNETXMS_EXPORTABLE _topen(TCHAR *pszName, int nFlags, ...);
726 int LIBNETXMS_EXPORTABLE read(int hFile, void *pBuffer, size_t nBytes);
727 int LIBNETXMS_EXPORTABLE write(int hFile, void *pBuffer, size_t nBytes);
728#endif
729
b71bff93 730#if !defined(_WIN32) && !defined(_NETWARE) && defined(NMS_THREADS_H_INCLUDED)
953dfe76 731void LIBNETXMS_EXPORTABLE StartMainLoop(THREAD_RESULT (THREAD_CALL * pfSignalHandler)(void *),
45c13da4 732 THREAD_RESULT (THREAD_CALL * pfMain)(void *));
953dfe76
VK
733#endif
734
9f2902ac 735BOOL LIBNETXMS_EXPORTABLE nxlog_open(const TCHAR *logName, DWORD flags, const TCHAR *msgModule,
d49d7500 736 unsigned int msgCount, const TCHAR **messages);
9f2902ac
VK
737void LIBNETXMS_EXPORTABLE nxlog_close(void);
738void LIBNETXMS_EXPORTABLE nxlog_write(DWORD msg, WORD wType, const char *format, ...);
4addc3a3
VK
739BOOL LIBNETXMS_EXPORTABLE nxlog_set_rotation_policy(int maxLogSize, int historySize);
740BOOL LIBNETXMS_EXPORTABLE nxlog_rotate();
9f2902ac 741
b50f1100 742#ifdef __cplusplus
e9246d26 743}
b50f1100 744#endif
e9246d26 745
a7ff20a5
VK
746
747//
748// C++ only finctions
749//
750
751#ifdef __cplusplus
752
753String LIBNETXMS_EXPORTABLE EscapeStringForXML2(const TCHAR *string, int length = -1);
754
755#endif
756
e9246d26 757#endif /* _nms_util_h_ */