libnxsrv and nxcore moved to VS2005 (nxcore cannot be linked because libnxsl not...
[public/netxms.git] / include / nms_util.h
CommitLineData
8e76f8aa 1/* $Id$ */
e9246d26 2/*
7ac71e60 3** NetXMS - Network Management System
fb7ce4b9 4** Copyright (C) 2003, 2004, 2005, 2006, 2007 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
66c04cc7
VK
81//
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
dcb44c9a 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
9f2902ac
VK
113//
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
b160350d
VK
122//
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
189class LIBNETXMS_EXPORTABLE Table
190{
191private:
192 int m_nNumRows;
193 int m_nNumCols;
194 TCHAR **m_ppData;
195 TCHAR **m_ppColNames;
196
197public:
198 Table();
199 ~Table();
200
201 int GetNumRows(void) { return m_nNumRows; }
202 int GetNumColumns(void) { return m_nNumCols; }
203
204 void AddColumn(TCHAR *pszName);
205 void AddRow(void);
206
207 void SetAt(int nRow, int nCol, TCHAR *pszData);
208 void SetAt(int nRow, int nCol, LONG nData);
209 void SetAt(int nRow, int nCol, DWORD dwData);
210 void SetAt(int nRow, int nCol, double dData);
211 void SetAt(int nRow, int nCol, INT64 nData);
212 void SetAt(int nRow, int nCol, QWORD qwData);
213
214 void Set(int nCol, TCHAR *pszData) { SetAt(m_nNumRows - 1, nCol, pszData); }
215 void Set(int nCol, LONG nData) { SetAt(m_nNumRows - 1, nCol, nData); }
216 void Set(int nCol, DWORD dwData) { SetAt(m_nNumRows - 1, nCol, dwData); }
217 void Set(int nCol, double dData) { SetAt(m_nNumRows - 1, nCol, dData); }
218 void Set(int nCol, INT64 nData) { SetAt(m_nNumRows - 1, nCol, nData); }
219 void Set(int nCol, QWORD qwData) { SetAt(m_nNumRows - 1, nCol, qwData); }
220
221 TCHAR *GetAsString(int nRow, int nCol);
222 LONG GetAsInt(int nRow, int nCol);
223 DWORD GetAsUInt(int nRow, int nCol);
224 INT64 GetAsInt64(int nRow, int nCol);
225 QWORD GetAsUInt64(int nRow, int nCol);
226 double GetAsDouble(int nRow, int nCol);
227};
228
8bad8476
VK
229
230//
231// Dynamic string class
232//
233
234class LIBNETXMS_EXPORTABLE String
235{
236protected:
237 TCHAR *m_pszBuffer;
238 DWORD m_dwBufSize;
239
240public:
c577e360
VK
241 static const int npos;
242
8bad8476
VK
243 String();
244 ~String();
245
246 void SetBuffer(TCHAR *pszBuffer);
247
2391d4fd
VK
248 const String& operator =(const TCHAR *pszStr);
249 const String& operator +=(const TCHAR *pszStr);
8bad8476
VK
250 operator TCHAR*() { return CHECK_NULL_EX(m_pszBuffer); }
251
2391d4fd 252 void AddString(const TCHAR *pStr, DWORD dwLen);
c577e360
VK
253 void AddDynamicString(TCHAR *pszStr) { if (pszStr != NULL) { *this += pszStr; free(pszStr); } }
254
2391d4fd 255 void AddFormattedString(const TCHAR *pszFormat, ...);
8bad8476 256 void EscapeCharacter(int ch, int esc);
2391d4fd 257 void Translate(const TCHAR *pszSrc, const TCHAR *pszDst);
c577e360 258
1e1450ef 259 DWORD Size() { return m_dwBufSize > 0 ? m_dwBufSize - 1 : 0; }
99c8959e 260 BOOL IsEmpty() { return m_dwBufSize <= 1; }
c577e360
VK
261
262 TCHAR *SubStr(int nStart, int nLen, TCHAR *pszBuffer);
263 TCHAR *SubStr(int nStart, int nLen) { return SubStr(nStart, nLen, NULL); }
2391d4fd 264 int Find(const TCHAR *pszStr, int nStart = 0);
1e1450ef
VK
265
266 void Strip();
c577e360
VK
267};
268
269
270//
271// String map class
272//
273
274class LIBNETXMS_EXPORTABLE StringMap
275{
276protected:
277 DWORD m_dwSize;
278 TCHAR **m_ppszKeys;
279 TCHAR **m_ppszValues;
280
c90d3610 281 DWORD Find(const TCHAR *pszKey);
c577e360
VK
282
283public:
284 StringMap();
35dfcebd 285 StringMap(StringMap *src);
c577e360
VK
286 ~StringMap();
287
40b7416c
VK
288 StringMap& operator =(StringMap &src);
289
c90d3610 290 void Set(const TCHAR *pszKey, const TCHAR *pszValue);
40b7416c 291 void SetPreallocated(TCHAR *pszKey, TCHAR *pszValue);
c90d3610 292 TCHAR *Get(const TCHAR *pszKey);
431f302b 293 void Delete(const TCHAR *pszKey);
c577e360
VK
294 void Clear(void);
295
296 DWORD Size(void) { return m_dwSize; }
297 TCHAR *GetKeyByIndex(DWORD idx) { return (idx < m_dwSize) ? m_ppszKeys[idx] : NULL; }
298 TCHAR *GetValueByIndex(DWORD idx) { return (idx < m_dwSize) ? m_ppszValues[idx] : NULL; }
8bad8476
VK
299};
300
b160350d
VK
301#endif /* __cplusplus */
302
303
4826c8a5
VK
304//
305// Configuration item template for configuration loader
306//
307
308typedef struct
309{
018fda4d 310 TCHAR szToken[64];
4826c8a5
VK
311 BYTE iType;
312 BYTE cSeparator; // Separator character for lists
313 WORD wListElements; // Number of list elements, should be set to 0 before calling NxLoadConfig()
314 DWORD dwBufferSize; // Buffer size for strings or flag to be set for CT_BOOLEAN
315 DWORD dwBufferPos; // Should be set to 0
316 void *pBuffer;
317} NX_CFG_TEMPLATE;
dcb44c9a
VK
318
319
bc858635
VK
320//
321// Code translation structure
322//
323
324typedef struct __CODE_TO_TEXT
325{
326 int code;
327 const TCHAR *text;
328} CODE_TO_TEXT;
329
330
3046f9a4
VK
331//
332// getopt() prototype if needed
333//
334
335#ifdef _WIN32
99e50bb7 336#include <netxms_getopt.h>
3046f9a4
VK
337#endif
338
339
f2fdf1b5
VK
340//
341// Win32 API functions missing under WinCE
342//
343
c32b805a 344#if defined(UNDER_CE) && defined(__cplusplus)
f2fdf1b5
VK
345
346inline void GetSystemTimeAsFileTime(LPFILETIME pFt)
347{
348 SYSTEMTIME sysTime;
349
350 GetSystemTime(&sysTime);
351 SystemTimeToFileTime(&sysTime, pFt);
352}
353
354#endif // UNDER_CE
355
356
3d1cb7d6
VK
357//
358// Structures for opendir() / readdir() / closedir()
359//
360
361#ifdef _WIN32
362
37d62364
AK
363#ifndef SWIGPERL
364
7f9e0c00 365typedef struct dirent
3d1cb7d6
VK
366{
367 long d_ino; /* inode number (not used by MS-DOS) */
368 int d_namlen; /* Name length */
369 char d_name[257]; /* file name */
370} _DIRECT;
371
372typedef struct _dir_struc
373{
374 char *start; /* Starting position */
375 char *curr; /* Current position */
376 long size; /* Size of string table */
377 long nfiles; /* number if filenames in table */
7f9e0c00 378 struct dirent dirstr; /* Directory structure to return */
3d1cb7d6
VK
379} DIR;
380
37d62364
AK
381#endif
382
3d1cb7d6
VK
383#endif /* _WIN32 */
384
385
e9246d26
VK
386//
387// Functions
388//
389
43d92b4c 390
babb8280 391#if WORDS_BIGENDIAN
43d92b4c
VK
392#define htonq(x) (x)
393#define ntohq(x) (x)
9f20696e
VK
394#define htond(x) (x)
395#define ntohd(x) (x)
babb8280
VK
396#define SwapWideString(x)
397#else
ca6ad6bb
VK
398#ifdef HAVE_HTONLL
399#define htonq(x) htonll(x)
400#else
babb8280 401#define htonq(x) __bswap_64(x)
ca6ad6bb
VK
402#endif
403#ifdef HAVE_NTOHLL
404#define ntohq(x) ntohll(x)
405#else
babb8280 406#define ntohq(x) __bswap_64(x)
ca6ad6bb 407#endif
babb8280
VK
408#define htond(x) __bswap_double(x)
409#define ntohd(x) __bswap_double(x)
410#define SwapWideString(x) __bswap_wstr(x)
43d92b4c 411#endif
15929b31 412
55b33d4c
VK
413#ifdef UNDER_CE
414#define close(x) CloseHandle((HANDLE)(x))
415#endif
416
c81979bc
VK
417#ifdef __cplusplus
418#ifndef LIBNETXMS_INLINE
4299401e 419 inline TCHAR *nx_strncpy(TCHAR *pszDest, const TCHAR *pszSrc, size_t nLen)
c81979bc
VK
420 {
421 _tcsncpy(pszDest, pszSrc, nLen - 1);
422 pszDest[nLen - 1] = 0;
423 return pszDest;
424 }
425#endif
426#else
4299401e 427 TCHAR LIBNETXMS_EXPORTABLE *nx_strncpy(TCHAR *pszDest, const TCHAR *pszSrc, size_t nLen);
c81979bc
VK
428#endif
429
b50f1100 430#ifdef __cplusplus
e9246d26
VK
431extern "C"
432{
b50f1100 433#endif
08043edf
VK
434 int LIBNETXMS_EXPORTABLE SendEx(SOCKET, const void *, size_t, int);
435 int LIBNETXMS_EXPORTABLE RecvEx(SOCKET nSocket, const void *pBuff,
436 size_t nSize, int nFlags, DWORD dwTimeout);
b24955fb 437
c5b523e2
VK
438#if defined(_WIN32) || !(HAVE_DECL___BSWAP_32)
439 DWORD LIBNETXMS_EXPORTABLE __bswap_32(DWORD dwVal);
440#endif
f52be742 441#if defined(_WIN32) || !(HAVE_DECL___BSWAP_64)
64584976
VK
442 QWORD LIBNETXMS_EXPORTABLE __bswap_64(QWORD qwVal);
443#endif
9f20696e 444 double LIBNETXMS_EXPORTABLE __bswap_double(double dVal);
273da39a 445 void LIBNETXMS_EXPORTABLE __bswap_wstr(UCS2CHAR *pStr);
64584976 446
076a55c4 447#if !defined(_WIN32) && !defined(_NETWARE)
8b86c5dc
VK
448#if defined(UNICODE_UCS2) || defined(UNICODE_UCS4)
449 void LIBNETXMS_EXPORTABLE wcsupr(WCHAR *in);
450#endif
451 void LIBNETXMS_EXPORTABLE strupr(char *in);
7e679c4b 452#endif
ab588c84 453
b8a8d064
VK
454 void LIBNETXMS_EXPORTABLE QSortEx(void *base, size_t nmemb, size_t size, void *arg,
455 int (*compare)(const void *, const void *, void *));
456
670c7f3d 457 INT64 LIBNETXMS_EXPORTABLE GetCurrentTimeMs(void);
3aa0061c 458 QWORD LIBNETXMS_EXPORTABLE FileSize(const TCHAR *pszFileName);
670c7f3d 459
64584976 460 int LIBNETXMS_EXPORTABLE BitsInMask(DWORD dwMask);
018fda4d 461 TCHAR LIBNETXMS_EXPORTABLE *IpToStr(DWORD dwAddr, TCHAR *szBuffer);
3aa0061c 462 DWORD LIBNETXMS_EXPORTABLE ResolveHostName(const TCHAR *pszName);
a1dc75b0 463
64584976 464 void LIBNETXMS_EXPORTABLE *nx_memdup(const void *pData, DWORD dwSize);
f218dc6d 465 void LIBNETXMS_EXPORTABLE nx_memswap(void *pBlock1, void *pBlock2, DWORD dwSize);
31521248 466
e25cadc9 467 TCHAR LIBNETXMS_EXPORTABLE *BinToStr(BYTE *pData, DWORD dwSize, TCHAR *pStr);
3aa0061c 468 DWORD LIBNETXMS_EXPORTABLE StrToBin(const TCHAR *pStr, BYTE *pData, DWORD dwSize);
c61f5190 469 void LIBNETXMS_EXPORTABLE MACToStr(BYTE *pData, TCHAR *pStr);
b50f1100 470
018fda4d
AK
471 void LIBNETXMS_EXPORTABLE StrStrip(TCHAR *pszStr);
472 BOOL LIBNETXMS_EXPORTABLE MatchString(const TCHAR *pattern, const TCHAR *string, BOOL matchCase);
9eea20df 473 BOOL LIBNETXMS_EXPORTABLE RegexpMatch(const TCHAR *pszStr, const TCHAR *pszExpr, BOOL bMatchCase);
018fda4d 474 TCHAR LIBNETXMS_EXPORTABLE *ExtractWord(TCHAR *line, TCHAR *buffer);
2391d4fd 475 int LIBNETXMS_EXPORTABLE NumChars(const TCHAR *pszStr, int ch);
f7794b68
VK
476#ifdef __cplusplus
477 BOOL LIBNETXMS_EXPORTABLE IsValidObjectName(const TCHAR *pszName, BOOL bExtendedChars = FALSE);
478#endif
fa2b47a7 479 BOOL LIBNETXMS_EXPORTABLE IsValidScriptName(const TCHAR *pszName);
2391d4fd 480 void LIBNETXMS_EXPORTABLE TranslateStr(TCHAR *pszString, const TCHAR *pszSubStr, const TCHAR *pszReplace);
257defd7 481 TCHAR LIBNETXMS_EXPORTABLE *GetCleanFileName(TCHAR *pszFileName);
c3cfc039 482 void LIBNETXMS_EXPORTABLE GetOSVersionString(TCHAR *pszBuffer, int nBufSize);
3aa0061c 483 BYTE LIBNETXMS_EXPORTABLE *LoadFile(const TCHAR *pszFileName, DWORD *pdwFileSize);
ec4995e6 484
6120112b 485 DWORD LIBNETXMS_EXPORTABLE CalculateCRC32(const unsigned char *pData, DWORD dwSize, DWORD dwCRC);
a3c76aba
VK
486 void LIBNETXMS_EXPORTABLE CalculateMD5Hash(const unsigned char *data, size_t nbytes, unsigned char *hash);
487 void LIBNETXMS_EXPORTABLE CalculateSHA1Hash(unsigned char *data, size_t nbytes, unsigned char *hash);
3aa0061c
VK
488 BOOL LIBNETXMS_EXPORTABLE CalculateFileMD5Hash(const TCHAR *pszFileName, BYTE *pHash);
489 BOOL LIBNETXMS_EXPORTABLE CalculateFileSHA1Hash(const TCHAR *pszFileName, BYTE *pHash);
490 BOOL LIBNETXMS_EXPORTABLE CalculateFileCRC32(const TCHAR *pszFileName, DWORD *pResult);
66c04cc7 491
46ef501a
VK
492 DWORD LIBNETXMS_EXPORTABLE IcmpPing(DWORD dwAddr, int iNumRetries, DWORD dwTimeout,
493 DWORD *pdwRTT, DWORD dwPacketSize);
4826c8a5 494
3aa0061c 495 DWORD LIBNETXMS_EXPORTABLE NxLoadConfig(const TCHAR *pszFileName, const TCHAR *pszSection,
6849d9be 496 NX_CFG_TEMPLATE *pTemplateList, BOOL bPrint);
3aa0061c 497 int LIBNETXMS_EXPORTABLE NxDCIDataTypeFromText(const TCHAR *pszText);
aa13cfd9 498
4560d8bd 499 HMODULE LIBNETXMS_EXPORTABLE DLOpen(const TCHAR *pszLibName, TCHAR *pszErrorText);
aa13cfd9 500 void LIBNETXMS_EXPORTABLE DLClose(HMODULE hModule);
4560d8bd 501 void LIBNETXMS_EXPORTABLE *DLGetSymbolAddr(HMODULE hModule, const TCHAR *pszSymbol, TCHAR *pszErrorText);
aa13cfd9 502
ae9cddaf 503 void LIBNETXMS_EXPORTABLE InitSubAgentsLogger(void (* pFunc)(int, TCHAR *));
15c8cf46 504 void LIBNETXMS_EXPORTABLE InitSubAgentsTrapSender(void (* pFunc1)(DWORD, int, TCHAR **),
2e06d08b 505
a765d97c 506 void (* pFunc2)(DWORD, const char *, va_list));
2e06d08b
VK
507 BOOL LIBNETXMS_EXPORTABLE ExtractNamedOptionValue(const TCHAR *optString, const TCHAR *option, TCHAR *buffer, int bufSize);
508 BOOL LIBNETXMS_EXPORTABLE ExtractNamedOptionValueAsBool(const TCHAR *optString, const TCHAR *option, BOOL defVal);
509 long LIBNETXMS_EXPORTABLE ExtractNamedOptionValueAsInt(const TCHAR *optString, const TCHAR *option, long defVal);
ae9cddaf 510
92502d5f 511 TCHAR LIBNETXMS_EXPORTABLE *EscapeStringForXML(const TCHAR *string, int length);
66ae1b17
VK
512 const char LIBNETXMS_EXPORTABLE *XMLGetAttr(const char **attrs, const char *name);
513 int LIBNETXMS_EXPORTABLE XMLGetAttrInt(const char **attrs, const char *name, int defVal);
514 int LIBNETXMS_EXPORTABLE XMLGetAttrDWORD(const char **attrs, const char *name, DWORD defVal);
58a41c03 515 BOOL LIBNETXMS_EXPORTABLE XMLGetAttrBoolean(const char **attrs, const char *name, BOOL defVal);
92502d5f 516
bc858635
VK
517#ifdef __cplusplus
518 const TCHAR LIBNETXMS_EXPORTABLE *CodeToText(int iCode, CODE_TO_TEXT *pTranslator, const TCHAR *pszDefaultText = _T("Unknown"));
519#else
520 const TCHAR LIBNETXMS_EXPORTABLE *CodeToText(int iCode, CODE_TO_TEXT *pTranslator, const TCHAR *pszDefaultText);
521#endif
522
aa13cfd9 523#ifdef _WIN32
4299401e 524 TCHAR LIBNETXMS_EXPORTABLE *GetSystemErrorText(DWORD dwError, TCHAR *pszBuffer, size_t iBufSize);
aa13cfd9 525#endif
696fc54f
VK
526
527#if !(HAVE_DAEMON)
b1a57444 528 int LIBNETXMS_EXPORTABLE daemon(int nochdir, int noclose);
696fc54f 529#endif
4332e9d8 530
3aa0061c 531 DWORD LIBNETXMS_EXPORTABLE inet_addr_w(const WCHAR *pszAddr);
268774a0 532
4332e9d8 533#ifndef _WIN32
664c7c49 534 BOOL LIBNETXMS_EXPORTABLE SetDefaultCodepage(const char *cp);
3aa0061c 535 int LIBNETXMS_EXPORTABLE WideCharToMultiByte(int iCodePage, DWORD dwFlags, const WCHAR *pWideCharStr,
4332e9d8
VK
536 int cchWideChar, char *pByteStr, int cchByteChar,
537 char *pDefaultChar, BOOL *pbUsedDefChar);
3aa0061c 538 int LIBNETXMS_EXPORTABLE MultiByteToWideChar(int iCodePage, DWORD dwFlags, const char *pByteStr,
4332e9d8
VK
539 int cchByteChar, WCHAR *pWideCharStr,
540 int cchWideChar);
04dbaf62 541
6b93c954 542#if !defined(UNICODE_UCS2) || !HAVE_WCSLEN
8b86c5dc 543 int LIBNETXMS_EXPORTABLE ucs2_strlen(const UCS2CHAR *pStr);
6b93c954
VK
544#endif
545#if !defined(UNICODE_UCS2) || !HAVE_WCSNCPY
8b86c5dc 546 UCS2CHAR LIBNETXMS_EXPORTABLE *ucs2_strncpy(UCS2CHAR *pDst, const UCS2CHAR *pSrc, int nDstLen);
6b93c954
VK
547#endif
548#if !defined(UNICODE_UCS2) || !HAVE_WCSDUP
8b86c5dc 549 UCS2CHAR LIBNETXMS_EXPORTABLE *ucs2_strdup(const UCS2CHAR *pStr);
4332e9d8 550#endif
8b86c5dc
VK
551
552#ifndef UNICODE
553 size_t LIBNETXMS_EXPORTABLE ucs2_to_mb(const UCS2CHAR *src, size_t srcLen, char *dst, size_t dstLen);
554 size_t LIBNETXMS_EXPORTABLE mb_to_ucs2(const char *src, size_t srcLen, UCS2CHAR *dst, size_t dstLen);
555#endif
556
04dbaf62 557#ifdef UNICODE
6e17f325
VK
558 int LIBNETXMS_EXPORTABLE nx_wprintf(const WCHAR *format, ...);
559 int LIBNETXMS_EXPORTABLE nx_fwprintf(FILE *fp, const WCHAR *format, ...);
560 int LIBNETXMS_EXPORTABLE nx_swprintf(WCHAR *buffer, size_t size, const WCHAR *format, ...);
561 int LIBNETXMS_EXPORTABLE nx_vwprintf(const WCHAR *format, va_list args);
562 int LIBNETXMS_EXPORTABLE nx_vfwprintf(FILE *fp, const WCHAR *format, va_list args);
563 int LIBNETXMS_EXPORTABLE nx_vswprintf(WCHAR *buffer, size_t size, const WCHAR *format, va_list args);
04dbaf62
VK
564#endif
565
3e39fcde 566#endif /* _WIN32 */
8b86c5dc 567
3aa0061c 568 WCHAR LIBNETXMS_EXPORTABLE *WideStringFromMBString(const char *pszString);
c16afb3d 569 WCHAR LIBNETXMS_EXPORTABLE *WideStringFromUTF8String(const char *pszString);
3aa0061c
VK
570 char LIBNETXMS_EXPORTABLE *MBStringFromWideString(const WCHAR *pwszString);
571 char LIBNETXMS_EXPORTABLE *UTF8StringFromWideString(const WCHAR *pwszString);
8b86c5dc 572
3d1058ed
VK
573#ifdef _WITH_ENCRYPTION
574 WCHAR LIBNETXMS_EXPORTABLE *ERR_error_string_W(int nError, WCHAR *pwszBuffer);
575#endif
576
8b86c5dc
VK
577#ifdef UNICODE_UCS4
578 size_t LIBNETXMS_EXPORTABLE ucs2_to_ucs4(const UCS2CHAR *src, size_t srcLen, WCHAR *dst, size_t dstLen);
579 size_t LIBNETXMS_EXPORTABLE ucs4_to_ucs2(const WCHAR *src, size_t srcLen, UCS2CHAR *dst, size_t dstLen);
b6e8dffe 580 size_t LIBNETXMS_EXPORTABLE ucs2_to_utf8(const UCS2CHAR *src, size_t srcLen, char *dst, size_t dstLen);
d9b66a56
VK
581 UCS2CHAR LIBNETXMS_EXPORTABLE *UCS2StringFromUCS4String(const WCHAR *pwszString);
582 WCHAR LIBNETXMS_EXPORTABLE *UCS4StringFromUCS2String(const UCS2CHAR *pszString);
b50f1100 583#endif
8b86c5dc 584
d9b66a56
VK
585#ifdef UNICODE
586
8b86c5dc
VK
587#if !HAVE_WFOPEN
588 FILE LIBNETXMS_EXPORTABLE *wfopen(const WCHAR *_name, const WCHAR *_type);
589#endif
590#if !HAVE_WOPEN
591 int LIBNETXMS_EXPORTABLE wopen(const WCHAR *, int, ...);
b50f1100 592#endif
8b86c5dc
VK
593#if !HAVE_WSTAT
594 int wstat(const WCHAR *_path, struct stat *_sbuf);
dde96745 595#endif
273da39a
VK
596#if !HAVE_WGETENV
597 WCHAR *wgetenv(const WCHAR *_string);
598#endif
d49d7500
VK
599#if !HAVE_WCSERROR && HAVE_STRERROR
600 WCHAR *wcserror(int errnum);
601#endif
602#if !HAVE_WCSERROR_R && HAVE_STRERROR_R
603 WCHAR *wcserror_r(int errnum, WCHAR *strerrbuf, size_t buflen);
604#endif
e05f8aaf
VK
605
606#endif /* UNICODE */
607
8b86c5dc
VK
608#if !HAVE_STRTOLL
609 INT64 LIBNETXMS_EXPORTABLE strtoll(const char *nptr, char **endptr, int base);
610#endif
611#if !HAVE_STRTOULL
612 QWORD LIBNETXMS_EXPORTABLE strtoull(const char *nptr, char **endptr, int base);
613#endif
e05f8aaf
VK
614
615#if !HAVE_WCSTOLL
616 INT64 LIBNETXMS_EXPORTABLE wcstoll(const WCHAR *nptr, WCHAR **endptr, int base);
617#endif
618#if !HAVE_WCSTOULL
619 QWORD LIBNETXMS_EXPORTABLE wcstoull(const WCHAR *nptr, WCHAR **endptr, int base);
620#endif
b50f1100 621
3d1cb7d6 622#ifdef _WIN32
37d62364 623#ifndef SWIGPERL
3d1cb7d6 624 DIR LIBNETXMS_EXPORTABLE *opendir(const char *filename);
7f9e0c00 625 struct dirent LIBNETXMS_EXPORTABLE *readdir(DIR *dirp);
3d1cb7d6
VK
626 int LIBNETXMS_EXPORTABLE closedir(DIR *dirp);
627#endif
37d62364 628#endif
3d1cb7d6 629
7f9e0c00
VK
630#if defined(_WIN32) || !(HAVE_SCANDIR)
631 int LIBNETXMS_EXPORTABLE scandir(const char *dir, struct dirent ***namelist,
632 int (*select)(const struct dirent *),
633 int (*compar)(const struct dirent **, const struct dirent **));
634 int LIBNETXMS_EXPORTABLE alphasort(const struct dirent **a, const struct dirent **b);
635#endif
636
55b33d4c
VK
637#ifdef UNDER_CE
638 int LIBNETXMS_EXPORTABLE _topen(TCHAR *pszName, int nFlags, ...);
639 int LIBNETXMS_EXPORTABLE read(int hFile, void *pBuffer, size_t nBytes);
640 int LIBNETXMS_EXPORTABLE write(int hFile, void *pBuffer, size_t nBytes);
641#endif
642
b71bff93 643#if !defined(_WIN32) && !defined(_NETWARE) && defined(NMS_THREADS_H_INCLUDED)
953dfe76 644void LIBNETXMS_EXPORTABLE StartMainLoop(THREAD_RESULT (THREAD_CALL * pfSignalHandler)(void *),
45c13da4 645 THREAD_RESULT (THREAD_CALL * pfMain)(void *));
953dfe76
VK
646#endif
647
9f2902ac 648BOOL LIBNETXMS_EXPORTABLE nxlog_open(const TCHAR *logName, DWORD flags, const TCHAR *msgModule,
d49d7500 649 unsigned int msgCount, const TCHAR **messages);
9f2902ac
VK
650void LIBNETXMS_EXPORTABLE nxlog_close(void);
651void LIBNETXMS_EXPORTABLE nxlog_write(DWORD msg, WORD wType, const char *format, ...);
652
b50f1100 653#ifdef __cplusplus
e9246d26 654}
b50f1100 655#endif
e9246d26
VK
656
657#endif /* _nms_util_h_ */