new log api: protocol fully implemented
[public/netxms.git] / include / nms_util.h
CommitLineData
8e76f8aa 1/* $Id$ */
e9246d26 2/*
7ac71e60 3** NetXMS - Network Management System
ccc34207 4** Copyright (C) 2003-2009 Victor Kirhenshtein
e9246d26
VK
5**
6** This program is free software; you can redistribute it and/or modify
7** it under the terms of the GNU General Public License as published by
8** the Free Software Foundation; either version 2 of the License, or
9** (at your option) any later version.
10**
11** This program is distributed in the hope that it will be useful,
12** but WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14** GNU General Public License for more details.
15**
16** You should have received a copy of the GNU General Public License
17** along with this program; if not, write to the Free Software
18** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19**
fb7ce4b9 20** File: nms_util.h
e9246d26
VK
21**
22**/
23
24#ifndef _nms_util_h_
25#define _nms_util_h_
26
64584976
VK
27#ifdef _WIN32
28#ifdef LIBNETXMS_EXPORTS
29#define LIBNETXMS_EXPORTABLE __declspec(dllexport)
30#else
31#define LIBNETXMS_EXPORTABLE __declspec(dllimport)
32#endif
33#else /* _WIN32 */
34#define LIBNETXMS_EXPORTABLE
35#endif
36
37
e9246d26
VK
38#include <nms_common.h>
39#include <nms_cscp.h>
953dfe76 40#include <nms_threads.h>
64584976 41#include <time.h>
e9246d26 42
6d8aee95
VK
43#if HAVE_BYTESWAP_H
44#include <byteswap.h>
45#endif
46
92502d5f
VK
47#include <base64.h>
48
6d8aee95
VK
49
50//
92502d5f 51// Serial communications
6d8aee95
VK
52//
53
54#ifdef _WIN32
55
56#define FLOW_NONE 0
57#define FLOW_SOFTWARE 1
58#define FLOW_HARDWARE 2
59
60#else /* _WIN32 */
61
70fed300
AK
62#ifdef HAVE_TERMIOS_H
63# include <termios.h>
64#else
65# error termios.h not found
66#endif
67
6d8aee95
VK
68#endif /* _WIN32 */
69
70
71//
72// Common constants
73//
f52be742 74
5d63b3c1 75#define INVALID_INDEX 0xFFFFFFFF
28dd92c9 76#define CSCP_TEMP_BUF_SIZE 65536
89bfdd9c 77#define MD5_DIGEST_SIZE 16
d0b249a8 78#define SHA1_DIGEST_SIZE 20
5d63b3c1
VK
79
80
81//
66c04cc7
VK
82// Return codes for IcmpPing()
83//
84
85#define ICMP_SUCCESS 0
86#define ICMP_UNREACHEABLE 1
87#define ICMP_TIMEOUT 2
88#define ICMP_RAW_SOCK_FAILED 3
89
90
91//
4826c8a5 92// Token types for configuration loader
dcb44c9a
VK
93//
94
4826c8a5
VK
95#define CT_LONG 0
96#define CT_STRING 1
97#define CT_STRING_LIST 2
98#define CT_END_OF_LIST 3
99#define CT_BOOLEAN 4
100#define CT_WORD 5
fc935a60 101#define CT_IGNORE 6
4826c8a5
VK
102
103
104//
105// Return codes for NxLoadConfig()
106//
107
108#define NXCFG_ERR_OK 0
109#define NXCFG_ERR_NOFILE 1
110#define NXCFG_ERR_SYNTAX 2
111
112
113//
9f2902ac
VK
114// nxlog_open() flags
115//
116
117#define NXLOG_USE_SYSLOG ((DWORD)0x00000001)
118#define NXLOG_PRINT_TO_STDOUT ((DWORD)0x00000002)
119#define NXLOG_IS_OPEN ((DWORD)0x80000000)
120
121
122//
b160350d
VK
123// Class for serial communications
124//
125
126#ifdef __cplusplus
127
128#ifndef _WIN32
129enum
130{
131 NOPARITY,
132 ODDPARITY,
133 EVENPARITY,
134 ONESTOPBIT,
135 TWOSTOPBITS
136};
137
70fed300
AK
138enum
139{
140 FLOW_NONE,
141 FLOW_HARDWARE,
142 FLOW_SOFTWARE
143};
144
b160350d
VK
145#ifndef INVALID_HANDLE_VALUE
146#define INVALID_HANDLE_VALUE (-1)
147#endif
148#endif /* _WIN32 */
149
150class LIBNETXMS_EXPORTABLE Serial
151{
152public:
153 Serial(void);
154 ~Serial(void);
155
e2d68ddd 156 bool Open(const TCHAR *pszPort);
b160350d
VK
157 void Close(void);
158 void SetTimeout(int nTimeout);
f3a581d0
AK
159 int Read(char *pBuff, int nSize); /* waits up to timeout and do single read */
160 int ReadAll(char *pBuff, int nSize); /* read until timeout or out of space */
e2d68ddd 161 bool Write(const char *pBuff, int nSize);
b160350d
VK
162 void Flush(void);
163 bool Set(int nSpeed, int nDataBits, int nParity, int nStopBits);
70fed300 164 bool Set(int nSpeed, int nDataBits, int nParity, int nStopBits, int nFlowControl);
b160350d
VK
165 bool Restart(void);
166
167private:
168 TCHAR *m_pszPort;
169 int m_nTimeout;
170 int m_nSpeed;
171 int m_nDataBits;
172 int m_nStopBits;
173 int m_nParity;
70fed300 174 int m_nFlowControl;
b160350d
VK
175
176#ifndef _WIN32
177 int m_hPort;
70fed300 178 struct termios m_originalSettings;
b160350d
VK
179#else
180 HANDLE m_hPort;
181#endif
182};
183
ff214673
VK
184
185//
186// Class for table data storage
187//
188
ccc34207
VK
189class CSCPMessage;
190
ff214673
VK
191class LIBNETXMS_EXPORTABLE Table
192{
193private:
194 int m_nNumRows;
195 int m_nNumCols;
196 TCHAR **m_ppData;
197 TCHAR **m_ppColNames;
198
199public:
200 Table();
ccc34207 201 Table(CSCPMessage *msg);
ff214673
VK
202 ~Table();
203
3d5610eb 204 int fillMessage(CSCPMessage &msg, int offset, int rowLimit);
9e126e57
VK
205
206 int getNumRows(void) { return m_nNumRows; }
207 int getNumColumns(void) { return m_nNumCols; }
208
209 int addColumn(TCHAR *pszName);
210 int addRow(void);
211
212 void setAt(int nRow, int nCol, LONG nData);
213 void setAt(int nRow, int nCol, DWORD dwData);
214 void setAt(int nRow, int nCol, double dData);
215 void setAt(int nRow, int nCol, INT64 nData);
216 void setAt(int nRow, int nCol, QWORD qwData);
217 void setAt(int nRow, int nCol, const TCHAR *pszData);
218 void setPreallocatedAt(int nRow, int nCol, TCHAR *pszData);
219
220 void set(int nCol, LONG nData) { setAt(m_nNumRows - 1, nCol, nData); }
221 void set(int nCol, DWORD dwData) { setAt(m_nNumRows - 1, nCol, dwData); }
222 void set(int nCol, double dData) { setAt(m_nNumRows - 1, nCol, dData); }
223 void set(int nCol, INT64 nData) { setAt(m_nNumRows - 1, nCol, nData); }
224 void set(int nCol, QWORD qwData) { setAt(m_nNumRows - 1, nCol, qwData); }
225 void set(int nCol, const TCHAR *pszData) { setAt(m_nNumRows - 1, nCol, pszData); }
226 void setPreallocated(int nCol, TCHAR *pszData) { setPreallocatedAt(m_nNumRows - 1, nCol, pszData); }
227
228 const TCHAR *getAsString(int nRow, int nCol);
229 LONG getAsInt(int nRow, int nCol);
230 DWORD getAsUInt(int nRow, int nCol);
231 INT64 getAsInt64(int nRow, int nCol);
232 QWORD getAsUInt64(int nRow, int nCol);
233 double getAsDouble(int nRow, int nCol);
ff214673
VK
234};
235
8bad8476
VK
236
237//
238// Dynamic string class
239//
240
241class LIBNETXMS_EXPORTABLE String
242{
243protected:
244 TCHAR *m_pszBuffer;
245 DWORD m_dwBufSize;
246
247public:
c577e360
VK
248 static const int npos;
249
8bad8476 250 String();
643c9dcb 251 String(const String &src);
8bad8476
VK
252 ~String();
253
254 void SetBuffer(TCHAR *pszBuffer);
255
2391d4fd
VK
256 const String& operator =(const TCHAR *pszStr);
257 const String& operator +=(const TCHAR *pszStr);
8bad8476
VK
258 operator TCHAR*() { return CHECK_NULL_EX(m_pszBuffer); }
259
2391d4fd 260 void AddString(const TCHAR *pStr, DWORD dwLen);
c577e360
VK
261 void AddDynamicString(TCHAR *pszStr) { if (pszStr != NULL) { *this += pszStr; free(pszStr); } }
262
ff175e91
VK
263 void AddMultiByteString(const char *pStr, DWORD dwSize, int nCodePage);
264 void AddWideCharString(const WCHAR *pStr, DWORD dwSize);
265
2391d4fd 266 void AddFormattedString(const TCHAR *pszFormat, ...);
8bad8476 267 void EscapeCharacter(int ch, int esc);
2391d4fd 268 void Translate(const TCHAR *pszSrc, const TCHAR *pszDst);
c577e360 269
1e1450ef 270 DWORD Size() { return m_dwBufSize > 0 ? m_dwBufSize - 1 : 0; }
99c8959e 271 BOOL IsEmpty() { return m_dwBufSize <= 1; }
c577e360
VK
272
273 TCHAR *SubStr(int nStart, int nLen, TCHAR *pszBuffer);
274 TCHAR *SubStr(int nStart, int nLen) { return SubStr(nStart, nLen, NULL); }
2391d4fd 275 int Find(const TCHAR *pszStr, int nStart = 0);
1e1450ef 276
0bbab9d3
VK
277 void trim();
278 void shrink(int chars = 1);
c577e360
VK
279};
280
281
282//
283// String map class
284//
285
286class LIBNETXMS_EXPORTABLE StringMap
287{
288protected:
289 DWORD m_dwSize;
290 TCHAR **m_ppszKeys;
291 TCHAR **m_ppszValues;
292
c90d3610 293 DWORD Find(const TCHAR *pszKey);
c577e360
VK
294
295public:
296 StringMap();
35dfcebd 297 StringMap(StringMap *src);
c577e360
VK
298 ~StringMap();
299
40b7416c
VK
300 StringMap& operator =(StringMap &src);
301
c90d3610 302 void Set(const TCHAR *pszKey, const TCHAR *pszValue);
40b7416c 303 void SetPreallocated(TCHAR *pszKey, TCHAR *pszValue);
c90d3610 304 TCHAR *Get(const TCHAR *pszKey);
431f302b 305 void Delete(const TCHAR *pszKey);
c577e360
VK
306 void Clear(void);
307
308 DWORD Size(void) { return m_dwSize; }
79c2061c
VK
309 TCHAR *GetKeyByIndex(DWORD idx) { return (idx < m_dwSize) ? CHECK_NULL_EX(m_ppszKeys[idx]) : NULL; }
310 TCHAR *GetValueByIndex(DWORD idx) { return (idx < m_dwSize) ? CHECK_NULL_EX(m_ppszValues[idx]) : NULL; }
8bad8476
VK
311};
312
b160350d
VK
313#endif /* __cplusplus */
314
315
316//
4826c8a5
VK
317// Configuration item template for configuration loader
318//
319
320typedef struct
321{
018fda4d 322 TCHAR szToken[64];
4826c8a5
VK
323 BYTE iType;
324 BYTE cSeparator; // Separator character for lists
325 WORD wListElements; // Number of list elements, should be set to 0 before calling NxLoadConfig()
326 DWORD dwBufferSize; // Buffer size for strings or flag to be set for CT_BOOLEAN
327 DWORD dwBufferPos; // Should be set to 0
328 void *pBuffer;
329} NX_CFG_TEMPLATE;
dcb44c9a
VK
330
331
332//
bc858635
VK
333// Code translation structure
334//
335
336typedef struct __CODE_TO_TEXT
337{
338 int code;
339 const TCHAR *text;
340} CODE_TO_TEXT;
341
342
343//
3046f9a4
VK
344// getopt() prototype if needed
345//
346
347#ifdef _WIN32
99e50bb7 348#include <netxms_getopt.h>
3046f9a4
VK
349#endif
350
351
352//
f2fdf1b5
VK
353// Win32 API functions missing under WinCE
354//
355
c32b805a 356#if defined(UNDER_CE) && defined(__cplusplus)
f2fdf1b5
VK
357
358inline void GetSystemTimeAsFileTime(LPFILETIME pFt)
359{
360 SYSTEMTIME sysTime;
361
362 GetSystemTime(&sysTime);
363 SystemTimeToFileTime(&sysTime, pFt);
364}
365
366#endif // UNDER_CE
367
368
369//
3d1cb7d6
VK
370// Structures for opendir() / readdir() / closedir()
371//
372
373#ifdef _WIN32
374
37d62364
AK
375#ifndef SWIGPERL
376
7f9e0c00 377typedef struct dirent
3d1cb7d6
VK
378{
379 long d_ino; /* inode number (not used by MS-DOS) */
380 int d_namlen; /* Name length */
381 char d_name[257]; /* file name */
382} _DIRECT;
383
384typedef struct _dir_struc
385{
386 char *start; /* Starting position */
387 char *curr; /* Current position */
388 long size; /* Size of string table */
389 long nfiles; /* number if filenames in table */
7f9e0c00 390 struct dirent dirstr; /* Directory structure to return */
3d1cb7d6
VK
391} DIR;
392
37d62364
AK
393#endif
394
3d1cb7d6
VK
395#endif /* _WIN32 */
396
397
398//
e9246d26
VK
399// Functions
400//
401
43d92b4c 402
babb8280 403#if WORDS_BIGENDIAN
43d92b4c
VK
404#define htonq(x) (x)
405#define ntohq(x) (x)
9f20696e
VK
406#define htond(x) (x)
407#define ntohd(x) (x)
babb8280
VK
408#define SwapWideString(x)
409#else
ca6ad6bb
VK
410#ifdef HAVE_HTONLL
411#define htonq(x) htonll(x)
412#else
babb8280 413#define htonq(x) __bswap_64(x)
ca6ad6bb
VK
414#endif
415#ifdef HAVE_NTOHLL
416#define ntohq(x) ntohll(x)
417#else
babb8280 418#define ntohq(x) __bswap_64(x)
ca6ad6bb 419#endif
babb8280
VK
420#define htond(x) __bswap_double(x)
421#define ntohd(x) __bswap_double(x)
422#define SwapWideString(x) __bswap_wstr(x)
43d92b4c 423#endif
15929b31 424
55b33d4c
VK
425#ifdef UNDER_CE
426#define close(x) CloseHandle((HANDLE)(x))
427#endif
428
b50f1100 429#ifdef __cplusplus
c81979bc 430#ifndef LIBNETXMS_INLINE
4299401e 431 inline TCHAR *nx_strncpy(TCHAR *pszDest, const TCHAR *pszSrc, size_t nLen)
c81979bc 432 {
912b994d
VK
433#if defined(_WIN32) && (_MSC_VER >= 1400)
434 _tcsncpy_s(pszDest, nLen, pszSrc, _TRUNCATE);
435#else
c81979bc
VK
436 _tcsncpy(pszDest, pszSrc, nLen - 1);
437 pszDest[nLen - 1] = 0;
912b994d 438#endif
c81979bc
VK
439 return pszDest;
440 }
441#endif
442#else
4299401e 443 TCHAR LIBNETXMS_EXPORTABLE *nx_strncpy(TCHAR *pszDest, const TCHAR *pszSrc, size_t nLen);
c81979bc
VK
444#endif
445
446#ifdef __cplusplus
e9246d26
VK
447extern "C"
448{
b50f1100 449#endif
08043edf
VK
450 int LIBNETXMS_EXPORTABLE SendEx(SOCKET, const void *, size_t, int);
451 int LIBNETXMS_EXPORTABLE RecvEx(SOCKET nSocket, const void *pBuff,
452 size_t nSize, int nFlags, DWORD dwTimeout);
b24955fb 453
c5b523e2
VK
454#if defined(_WIN32) || !(HAVE_DECL___BSWAP_32)
455 DWORD LIBNETXMS_EXPORTABLE __bswap_32(DWORD dwVal);
456#endif
f52be742 457#if defined(_WIN32) || !(HAVE_DECL___BSWAP_64)
64584976
VK
458 QWORD LIBNETXMS_EXPORTABLE __bswap_64(QWORD qwVal);
459#endif
9f20696e 460 double LIBNETXMS_EXPORTABLE __bswap_double(double dVal);
273da39a 461 void LIBNETXMS_EXPORTABLE __bswap_wstr(UCS2CHAR *pStr);
64584976 462
076a55c4 463#if !defined(_WIN32) && !defined(_NETWARE)
8b86c5dc
VK
464#if defined(UNICODE_UCS2) || defined(UNICODE_UCS4)
465 void LIBNETXMS_EXPORTABLE wcsupr(WCHAR *in);
466#endif
467 void LIBNETXMS_EXPORTABLE strupr(char *in);
7e679c4b 468#endif
ab588c84 469
b8a8d064
VK
470 void LIBNETXMS_EXPORTABLE QSortEx(void *base, size_t nmemb, size_t size, void *arg,
471 int (*compare)(const void *, const void *, void *));
472
670c7f3d 473 INT64 LIBNETXMS_EXPORTABLE GetCurrentTimeMs(void);
3aa0061c 474 QWORD LIBNETXMS_EXPORTABLE FileSize(const TCHAR *pszFileName);
670c7f3d 475
64584976 476 int LIBNETXMS_EXPORTABLE BitsInMask(DWORD dwMask);
018fda4d 477 TCHAR LIBNETXMS_EXPORTABLE *IpToStr(DWORD dwAddr, TCHAR *szBuffer);
3aa0061c 478 DWORD LIBNETXMS_EXPORTABLE ResolveHostName(const TCHAR *pszName);
a1dc75b0 479
64584976 480 void LIBNETXMS_EXPORTABLE *nx_memdup(const void *pData, DWORD dwSize);
f218dc6d 481 void LIBNETXMS_EXPORTABLE nx_memswap(void *pBlock1, void *pBlock2, DWORD dwSize);
31521248 482
e25cadc9 483 TCHAR LIBNETXMS_EXPORTABLE *BinToStr(BYTE *pData, DWORD dwSize, TCHAR *pStr);
3aa0061c 484 DWORD LIBNETXMS_EXPORTABLE StrToBin(const TCHAR *pStr, BYTE *pData, DWORD dwSize);
c61f5190 485 void LIBNETXMS_EXPORTABLE MACToStr(BYTE *pData, TCHAR *pStr);
b50f1100 486
018fda4d 487 void LIBNETXMS_EXPORTABLE StrStrip(TCHAR *pszStr);
0bbab9d3 488 void LIBNETXMS_EXPORTABLE Trim(TCHAR *str);
018fda4d 489 BOOL LIBNETXMS_EXPORTABLE MatchString(const TCHAR *pattern, const TCHAR *string, BOOL matchCase);
9eea20df 490 BOOL LIBNETXMS_EXPORTABLE RegexpMatch(const TCHAR *pszStr, const TCHAR *pszExpr, BOOL bMatchCase);
018fda4d 491 TCHAR LIBNETXMS_EXPORTABLE *ExtractWord(TCHAR *line, TCHAR *buffer);
2391d4fd 492 int LIBNETXMS_EXPORTABLE NumChars(const TCHAR *pszStr, int ch);
3783d300 493 void LIBNETXMS_EXPORTABLE RemoveTrailingCRLF(TCHAR *str);
f7794b68
VK
494#ifdef __cplusplus
495 BOOL LIBNETXMS_EXPORTABLE IsValidObjectName(const TCHAR *pszName, BOOL bExtendedChars = FALSE);
496#endif
fa2b47a7 497 BOOL LIBNETXMS_EXPORTABLE IsValidScriptName(const TCHAR *pszName);
2391d4fd 498 void LIBNETXMS_EXPORTABLE TranslateStr(TCHAR *pszString, const TCHAR *pszSubStr, const TCHAR *pszReplace);
257defd7 499 TCHAR LIBNETXMS_EXPORTABLE *GetCleanFileName(TCHAR *pszFileName);
c3cfc039 500 void LIBNETXMS_EXPORTABLE GetOSVersionString(TCHAR *pszBuffer, int nBufSize);
3aa0061c 501 BYTE LIBNETXMS_EXPORTABLE *LoadFile(const TCHAR *pszFileName, DWORD *pdwFileSize);
ec4995e6 502
6120112b 503 DWORD LIBNETXMS_EXPORTABLE CalculateCRC32(const unsigned char *pData, DWORD dwSize, DWORD dwCRC);
a3c76aba 504 void LIBNETXMS_EXPORTABLE CalculateMD5Hash(const unsigned char *data, size_t nbytes, unsigned char *hash);
e0d4b618 505 void LIBNETXMS_EXPORTABLE MD5HashForPattern(const unsigned char *data, size_t patternSize, size_t fullSize, BYTE *hash);
a3c76aba 506 void LIBNETXMS_EXPORTABLE CalculateSHA1Hash(unsigned char *data, size_t nbytes, unsigned char *hash);
e0d4b618 507 void LIBNETXMS_EXPORTABLE SHA1HashForPattern(unsigned char *data, size_t patternSize, size_t fullSize, unsigned char *hash);
3aa0061c
VK
508 BOOL LIBNETXMS_EXPORTABLE CalculateFileMD5Hash(const TCHAR *pszFileName, BYTE *pHash);
509 BOOL LIBNETXMS_EXPORTABLE CalculateFileSHA1Hash(const TCHAR *pszFileName, BYTE *pHash);
510 BOOL LIBNETXMS_EXPORTABLE CalculateFileCRC32(const TCHAR *pszFileName, DWORD *pResult);
66c04cc7 511
46ef501a
VK
512 DWORD LIBNETXMS_EXPORTABLE IcmpPing(DWORD dwAddr, int iNumRetries, DWORD dwTimeout,
513 DWORD *pdwRTT, DWORD dwPacketSize);
4826c8a5 514
e6c91aac
VK
515 /* deprecated:
516 DWORD LIBNETXMS_EXPORTABLE NxLoadConfig(const TCHAR *pszFileName, const TCHAR *pszSection,
517 NX_CFG_TEMPLATE *pTemplateList, BOOL bPrint);*/
3aa0061c 518 int LIBNETXMS_EXPORTABLE NxDCIDataTypeFromText(const TCHAR *pszText);
aa13cfd9 519
4560d8bd 520 HMODULE LIBNETXMS_EXPORTABLE DLOpen(const TCHAR *pszLibName, TCHAR *pszErrorText);
aa13cfd9 521 void LIBNETXMS_EXPORTABLE DLClose(HMODULE hModule);
4560d8bd 522 void LIBNETXMS_EXPORTABLE *DLGetSymbolAddr(HMODULE hModule, const TCHAR *pszSymbol, TCHAR *pszErrorText);
aa13cfd9 523
ae9cddaf 524 void LIBNETXMS_EXPORTABLE InitSubAgentsLogger(void (* pFunc)(int, TCHAR *));
15c8cf46 525 void LIBNETXMS_EXPORTABLE InitSubAgentsTrapSender(void (* pFunc1)(DWORD, int, TCHAR **),
2e06d08b 526
a765d97c 527 void (* pFunc2)(DWORD, const char *, va_list));
2e06d08b
VK
528 BOOL LIBNETXMS_EXPORTABLE ExtractNamedOptionValue(const TCHAR *optString, const TCHAR *option, TCHAR *buffer, int bufSize);
529 BOOL LIBNETXMS_EXPORTABLE ExtractNamedOptionValueAsBool(const TCHAR *optString, const TCHAR *option, BOOL defVal);
530 long LIBNETXMS_EXPORTABLE ExtractNamedOptionValueAsInt(const TCHAR *optString, const TCHAR *option, long defVal);
ae9cddaf 531
92502d5f 532 TCHAR LIBNETXMS_EXPORTABLE *EscapeStringForXML(const TCHAR *string, int length);
66ae1b17
VK
533 const char LIBNETXMS_EXPORTABLE *XMLGetAttr(const char **attrs, const char *name);
534 int LIBNETXMS_EXPORTABLE XMLGetAttrInt(const char **attrs, const char *name, int defVal);
af885dca 535 DWORD LIBNETXMS_EXPORTABLE XMLGetAttrDWORD(const char **attrs, const char *name, DWORD defVal);
ccc34207 536 bool LIBNETXMS_EXPORTABLE XMLGetAttrBoolean(const char **attrs, const char *name, bool defVal);
92502d5f 537
bc858635
VK
538#ifdef __cplusplus
539 const TCHAR LIBNETXMS_EXPORTABLE *CodeToText(int iCode, CODE_TO_TEXT *pTranslator, const TCHAR *pszDefaultText = _T("Unknown"));
540#else
541 const TCHAR LIBNETXMS_EXPORTABLE *CodeToText(int iCode, CODE_TO_TEXT *pTranslator, const TCHAR *pszDefaultText);
542#endif
543
aa13cfd9 544#ifdef _WIN32
4299401e 545 TCHAR LIBNETXMS_EXPORTABLE *GetSystemErrorText(DWORD dwError, TCHAR *pszBuffer, size_t iBufSize);
ccc34207 546 BOOL LIBNETXMS_EXPORTABLE GetWindowsVersionString(TCHAR *versionString, int strSize);
aa13cfd9 547#endif
696fc54f
VK
548
549#if !(HAVE_DAEMON)
b1a57444 550 int LIBNETXMS_EXPORTABLE daemon(int nochdir, int noclose);
696fc54f 551#endif
4332e9d8 552
3aa0061c 553 DWORD LIBNETXMS_EXPORTABLE inet_addr_w(const WCHAR *pszAddr);
268774a0 554
4332e9d8 555#ifndef _WIN32
664c7c49 556 BOOL LIBNETXMS_EXPORTABLE SetDefaultCodepage(const char *cp);
3aa0061c 557 int LIBNETXMS_EXPORTABLE WideCharToMultiByte(int iCodePage, DWORD dwFlags, const WCHAR *pWideCharStr,
4332e9d8
VK
558 int cchWideChar, char *pByteStr, int cchByteChar,
559 char *pDefaultChar, BOOL *pbUsedDefChar);
3aa0061c 560 int LIBNETXMS_EXPORTABLE MultiByteToWideChar(int iCodePage, DWORD dwFlags, const char *pByteStr,
4332e9d8
VK
561 int cchByteChar, WCHAR *pWideCharStr,
562 int cchWideChar);
04dbaf62 563
6b93c954 564#if !defined(UNICODE_UCS2) || !HAVE_WCSLEN
8b86c5dc 565 int LIBNETXMS_EXPORTABLE ucs2_strlen(const UCS2CHAR *pStr);
6b93c954
VK
566#endif
567#if !defined(UNICODE_UCS2) || !HAVE_WCSNCPY
8b86c5dc 568 UCS2CHAR LIBNETXMS_EXPORTABLE *ucs2_strncpy(UCS2CHAR *pDst, const UCS2CHAR *pSrc, int nDstLen);
6b93c954
VK
569#endif
570#if !defined(UNICODE_UCS2) || !HAVE_WCSDUP
8b86c5dc 571 UCS2CHAR LIBNETXMS_EXPORTABLE *ucs2_strdup(const UCS2CHAR *pStr);
4332e9d8 572#endif
8b86c5dc
VK
573
574#ifndef UNICODE
575 size_t LIBNETXMS_EXPORTABLE ucs2_to_mb(const UCS2CHAR *src, size_t srcLen, char *dst, size_t dstLen);
576 size_t LIBNETXMS_EXPORTABLE mb_to_ucs2(const char *src, size_t srcLen, UCS2CHAR *dst, size_t dstLen);
39945910
VK
577 UCS2CHAR LIBNETXMS_EXPORTABLE *UCS2StringFromMBString(const char *pszString);
578 char LIBNETXMS_EXPORTABLE *MBStringFromUCS2String(const UCS2CHAR *pszString);
8b86c5dc
VK
579#endif
580
04dbaf62 581#ifdef UNICODE
6e17f325
VK
582 int LIBNETXMS_EXPORTABLE nx_wprintf(const WCHAR *format, ...);
583 int LIBNETXMS_EXPORTABLE nx_fwprintf(FILE *fp, const WCHAR *format, ...);
584 int LIBNETXMS_EXPORTABLE nx_swprintf(WCHAR *buffer, size_t size, const WCHAR *format, ...);
585 int LIBNETXMS_EXPORTABLE nx_vwprintf(const WCHAR *format, va_list args);
586 int LIBNETXMS_EXPORTABLE nx_vfwprintf(FILE *fp, const WCHAR *format, va_list args);
587 int LIBNETXMS_EXPORTABLE nx_vswprintf(WCHAR *buffer, size_t size, const WCHAR *format, va_list args);
04dbaf62
VK
588#endif
589
3e39fcde 590#endif /* _WIN32 */
8b86c5dc 591
3aa0061c 592 WCHAR LIBNETXMS_EXPORTABLE *WideStringFromMBString(const char *pszString);
c16afb3d 593 WCHAR LIBNETXMS_EXPORTABLE *WideStringFromUTF8String(const char *pszString);
3aa0061c
VK
594 char LIBNETXMS_EXPORTABLE *MBStringFromWideString(const WCHAR *pwszString);
595 char LIBNETXMS_EXPORTABLE *UTF8StringFromWideString(const WCHAR *pwszString);
8b86c5dc 596
3d1058ed
VK
597#ifdef _WITH_ENCRYPTION
598 WCHAR LIBNETXMS_EXPORTABLE *ERR_error_string_W(int nError, WCHAR *pwszBuffer);
599#endif
600
8b86c5dc
VK
601#ifdef UNICODE_UCS4
602 size_t LIBNETXMS_EXPORTABLE ucs2_to_ucs4(const UCS2CHAR *src, size_t srcLen, WCHAR *dst, size_t dstLen);
603 size_t LIBNETXMS_EXPORTABLE ucs4_to_ucs2(const WCHAR *src, size_t srcLen, UCS2CHAR *dst, size_t dstLen);
b6e8dffe 604 size_t LIBNETXMS_EXPORTABLE ucs2_to_utf8(const UCS2CHAR *src, size_t srcLen, char *dst, size_t dstLen);
d9b66a56
VK
605 UCS2CHAR LIBNETXMS_EXPORTABLE *UCS2StringFromUCS4String(const WCHAR *pwszString);
606 WCHAR LIBNETXMS_EXPORTABLE *UCS4StringFromUCS2String(const UCS2CHAR *pszString);
b50f1100 607#endif
8b86c5dc 608
d9b66a56
VK
609#ifdef UNICODE
610
8b86c5dc
VK
611#if !HAVE_WFOPEN
612 FILE LIBNETXMS_EXPORTABLE *wfopen(const WCHAR *_name, const WCHAR *_type);
613#endif
614#if !HAVE_WOPEN
615 int LIBNETXMS_EXPORTABLE wopen(const WCHAR *, int, ...);
b50f1100 616#endif
8b86c5dc
VK
617#if !HAVE_WSTAT
618 int wstat(const WCHAR *_path, struct stat *_sbuf);
dde96745 619#endif
ccc34207
VK
620#if !HAVE_WRENAME
621 int wrename(const WCHAR *_oldpath, const WCHAR *_newpath);
622#endif
623#if !HAVE_WUNLINK
624 int wunlink(const WCHAR *_path);
625#endif
273da39a
VK
626#if !HAVE_WGETENV
627 WCHAR *wgetenv(const WCHAR *_string);
628#endif
d49d7500
VK
629#if !HAVE_WCSERROR && HAVE_STRERROR
630 WCHAR *wcserror(int errnum);
631#endif
632#if !HAVE_WCSERROR_R && HAVE_STRERROR_R
633 WCHAR *wcserror_r(int errnum, WCHAR *strerrbuf, size_t buflen);
634#endif
e05f8aaf
VK
635
636#endif /* UNICODE */
637
8b86c5dc
VK
638#if !HAVE_STRTOLL
639 INT64 LIBNETXMS_EXPORTABLE strtoll(const char *nptr, char **endptr, int base);
640#endif
641#if !HAVE_STRTOULL
642 QWORD LIBNETXMS_EXPORTABLE strtoull(const char *nptr, char **endptr, int base);
643#endif
e05f8aaf
VK
644
645#if !HAVE_WCSTOLL
646 INT64 LIBNETXMS_EXPORTABLE wcstoll(const WCHAR *nptr, WCHAR **endptr, int base);
647#endif
648#if !HAVE_WCSTOULL
649 QWORD LIBNETXMS_EXPORTABLE wcstoull(const WCHAR *nptr, WCHAR **endptr, int base);
650#endif
b50f1100 651
3d1cb7d6 652#ifdef _WIN32
37d62364 653#ifndef SWIGPERL
3d1cb7d6 654 DIR LIBNETXMS_EXPORTABLE *opendir(const char *filename);
7f9e0c00 655 struct dirent LIBNETXMS_EXPORTABLE *readdir(DIR *dirp);
3d1cb7d6
VK
656 int LIBNETXMS_EXPORTABLE closedir(DIR *dirp);
657#endif
37d62364 658#endif
3d1cb7d6 659
7f9e0c00
VK
660#if defined(_WIN32) || !(HAVE_SCANDIR)
661 int LIBNETXMS_EXPORTABLE scandir(const char *dir, struct dirent ***namelist,
662 int (*select)(const struct dirent *),
663 int (*compar)(const struct dirent **, const struct dirent **));
664 int LIBNETXMS_EXPORTABLE alphasort(const struct dirent **a, const struct dirent **b);
665#endif
666
55b33d4c
VK
667#ifdef UNDER_CE
668 int LIBNETXMS_EXPORTABLE _topen(TCHAR *pszName, int nFlags, ...);
669 int LIBNETXMS_EXPORTABLE read(int hFile, void *pBuffer, size_t nBytes);
670 int LIBNETXMS_EXPORTABLE write(int hFile, void *pBuffer, size_t nBytes);
671#endif
672
b71bff93 673#if !defined(_WIN32) && !defined(_NETWARE) && defined(NMS_THREADS_H_INCLUDED)
953dfe76 674void LIBNETXMS_EXPORTABLE StartMainLoop(THREAD_RESULT (THREAD_CALL * pfSignalHandler)(void *),
45c13da4 675 THREAD_RESULT (THREAD_CALL * pfMain)(void *));
953dfe76
VK
676#endif
677
9f2902ac 678BOOL LIBNETXMS_EXPORTABLE nxlog_open(const TCHAR *logName, DWORD flags, const TCHAR *msgModule,
d49d7500 679 unsigned int msgCount, const TCHAR **messages);
9f2902ac
VK
680void LIBNETXMS_EXPORTABLE nxlog_close(void);
681void LIBNETXMS_EXPORTABLE nxlog_write(DWORD msg, WORD wType, const char *format, ...);
4addc3a3
VK
682BOOL LIBNETXMS_EXPORTABLE nxlog_set_rotation_policy(int maxLogSize, int historySize);
683BOOL LIBNETXMS_EXPORTABLE nxlog_rotate();
9f2902ac 684
b50f1100 685#ifdef __cplusplus
e9246d26 686}
b50f1100 687#endif
e9246d26
VK
688
689#endif /* _nms_util_h_ */