fixes in performance tab - should show CPU usage for cisco routers
[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
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
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();
f3cdd1c5 251 String(const TCHAR *init);
643c9dcb 252 String(const String &src);
8bad8476
VK
253 ~String();
254
255 void SetBuffer(TCHAR *pszBuffer);
256
2391d4fd
VK
257 const String& operator =(const TCHAR *pszStr);
258 const String& operator +=(const TCHAR *pszStr);
8bad8476
VK
259 operator TCHAR*() { return CHECK_NULL_EX(m_pszBuffer); }
260
2391d4fd 261 void AddString(const TCHAR *pStr, DWORD dwLen);
c577e360
VK
262 void AddDynamicString(TCHAR *pszStr) { if (pszStr != NULL) { *this += pszStr; free(pszStr); } }
263
ff175e91
VK
264 void AddMultiByteString(const char *pStr, DWORD dwSize, int nCodePage);
265 void AddWideCharString(const WCHAR *pStr, DWORD dwSize);
266
2391d4fd 267 void AddFormattedString(const TCHAR *pszFormat, ...);
8bad8476 268 void EscapeCharacter(int ch, int esc);
2391d4fd 269 void Translate(const TCHAR *pszSrc, const TCHAR *pszDst);
c577e360 270
1e1450ef 271 DWORD Size() { return m_dwBufSize > 0 ? m_dwBufSize - 1 : 0; }
99c8959e 272 BOOL IsEmpty() { return m_dwBufSize <= 1; }
c577e360
VK
273
274 TCHAR *SubStr(int nStart, int nLen, TCHAR *pszBuffer);
275 TCHAR *SubStr(int nStart, int nLen) { return SubStr(nStart, nLen, NULL); }
2391d4fd 276 int Find(const TCHAR *pszStr, int nStart = 0);
1e1450ef 277
0bbab9d3
VK
278 void trim();
279 void shrink(int chars = 1);
c577e360
VK
280};
281
282
283//
284// String map class
285//
286
287class LIBNETXMS_EXPORTABLE StringMap
288{
289protected:
290 DWORD m_dwSize;
291 TCHAR **m_ppszKeys;
292 TCHAR **m_ppszValues;
293
c90d3610 294 DWORD Find(const TCHAR *pszKey);
c577e360
VK
295
296public:
297 StringMap();
35dfcebd 298 StringMap(StringMap *src);
c577e360
VK
299 ~StringMap();
300
40b7416c
VK
301 StringMap& operator =(StringMap &src);
302
c90d3610 303 void Set(const TCHAR *pszKey, const TCHAR *pszValue);
40b7416c 304 void SetPreallocated(TCHAR *pszKey, TCHAR *pszValue);
c90d3610 305 TCHAR *Get(const TCHAR *pszKey);
431f302b 306 void Delete(const TCHAR *pszKey);
c577e360
VK
307 void Clear(void);
308
309 DWORD Size(void) { return m_dwSize; }
79c2061c
VK
310 TCHAR *GetKeyByIndex(DWORD idx) { return (idx < m_dwSize) ? CHECK_NULL_EX(m_ppszKeys[idx]) : NULL; }
311 TCHAR *GetValueByIndex(DWORD idx) { return (idx < m_dwSize) ? CHECK_NULL_EX(m_ppszValues[idx]) : NULL; }
8bad8476
VK
312};
313
6173bea8
VK
314
315//
316// String list class
317//
318
319class LIBNETXMS_EXPORTABLE StringList
320{
321private:
322 int m_count;
323 int m_allocated;
324 TCHAR **m_values;
325
326public:
327 StringList();
328 ~StringList();
329
330 void add(const TCHAR *value);
331 void addPreallocated(TCHAR *value);
332 void add(LONG value);
333 void add(DWORD value);
334 void add(INT64 value);
335 void add(QWORD value);
336 void add(double value);
337 void clear();
338 int getSize() { return m_count; }
339 const TCHAR *getValue(int index) { return ((index >=0) && (index < m_count)) ? m_values[index] : NULL; }
340};
341
b160350d
VK
342#endif /* __cplusplus */
343
344
4826c8a5
VK
345//
346// Configuration item template for configuration loader
347//
348
349typedef struct
350{
018fda4d 351 TCHAR szToken[64];
4826c8a5
VK
352 BYTE iType;
353 BYTE cSeparator; // Separator character for lists
354 WORD wListElements; // Number of list elements, should be set to 0 before calling NxLoadConfig()
355 DWORD dwBufferSize; // Buffer size for strings or flag to be set for CT_BOOLEAN
356 DWORD dwBufferPos; // Should be set to 0
357 void *pBuffer;
358} NX_CFG_TEMPLATE;
dcb44c9a
VK
359
360
bc858635
VK
361//
362// Code translation structure
363//
364
365typedef struct __CODE_TO_TEXT
366{
367 int code;
368 const TCHAR *text;
369} CODE_TO_TEXT;
370
371
3046f9a4
VK
372//
373// getopt() prototype if needed
374//
375
376#ifdef _WIN32
99e50bb7 377#include <netxms_getopt.h>
3046f9a4
VK
378#endif
379
380
f2fdf1b5
VK
381//
382// Win32 API functions missing under WinCE
383//
384
c32b805a 385#if defined(UNDER_CE) && defined(__cplusplus)
f2fdf1b5
VK
386
387inline void GetSystemTimeAsFileTime(LPFILETIME pFt)
388{
389 SYSTEMTIME sysTime;
390
391 GetSystemTime(&sysTime);
392 SystemTimeToFileTime(&sysTime, pFt);
393}
394
395#endif // UNDER_CE
396
397
3d1cb7d6
VK
398//
399// Structures for opendir() / readdir() / closedir()
400//
401
402#ifdef _WIN32
403
37d62364
AK
404#ifndef SWIGPERL
405
7f9e0c00 406typedef struct dirent
3d1cb7d6
VK
407{
408 long d_ino; /* inode number (not used by MS-DOS) */
409 int d_namlen; /* Name length */
410 char d_name[257]; /* file name */
411} _DIRECT;
412
413typedef struct _dir_struc
414{
415 char *start; /* Starting position */
416 char *curr; /* Current position */
417 long size; /* Size of string table */
418 long nfiles; /* number if filenames in table */
7f9e0c00 419 struct dirent dirstr; /* Directory structure to return */
3d1cb7d6
VK
420} DIR;
421
37d62364
AK
422#endif
423
3d1cb7d6
VK
424#endif /* _WIN32 */
425
426
e9246d26
VK
427//
428// Functions
429//
430
43d92b4c 431
babb8280 432#if WORDS_BIGENDIAN
43d92b4c
VK
433#define htonq(x) (x)
434#define ntohq(x) (x)
9f20696e
VK
435#define htond(x) (x)
436#define ntohd(x) (x)
babb8280
VK
437#define SwapWideString(x)
438#else
ca6ad6bb
VK
439#ifdef HAVE_HTONLL
440#define htonq(x) htonll(x)
441#else
babb8280 442#define htonq(x) __bswap_64(x)
ca6ad6bb
VK
443#endif
444#ifdef HAVE_NTOHLL
445#define ntohq(x) ntohll(x)
446#else
babb8280 447#define ntohq(x) __bswap_64(x)
ca6ad6bb 448#endif
babb8280
VK
449#define htond(x) __bswap_double(x)
450#define ntohd(x) __bswap_double(x)
451#define SwapWideString(x) __bswap_wstr(x)
43d92b4c 452#endif
15929b31 453
55b33d4c
VK
454#ifdef UNDER_CE
455#define close(x) CloseHandle((HANDLE)(x))
456#endif
457
c81979bc
VK
458#ifdef __cplusplus
459#ifndef LIBNETXMS_INLINE
4299401e 460 inline TCHAR *nx_strncpy(TCHAR *pszDest, const TCHAR *pszSrc, size_t nLen)
c81979bc 461 {
912b994d
VK
462#if defined(_WIN32) && (_MSC_VER >= 1400)
463 _tcsncpy_s(pszDest, nLen, pszSrc, _TRUNCATE);
464#else
c81979bc
VK
465 _tcsncpy(pszDest, pszSrc, nLen - 1);
466 pszDest[nLen - 1] = 0;
912b994d 467#endif
c81979bc
VK
468 return pszDest;
469 }
470#endif
471#else
4299401e 472 TCHAR LIBNETXMS_EXPORTABLE *nx_strncpy(TCHAR *pszDest, const TCHAR *pszSrc, size_t nLen);
c81979bc
VK
473#endif
474
b50f1100 475#ifdef __cplusplus
e9246d26
VK
476extern "C"
477{
b50f1100 478#endif
08043edf
VK
479 int LIBNETXMS_EXPORTABLE SendEx(SOCKET, const void *, size_t, int);
480 int LIBNETXMS_EXPORTABLE RecvEx(SOCKET nSocket, const void *pBuff,
481 size_t nSize, int nFlags, DWORD dwTimeout);
b24955fb 482
c5b523e2
VK
483#if defined(_WIN32) || !(HAVE_DECL___BSWAP_32)
484 DWORD LIBNETXMS_EXPORTABLE __bswap_32(DWORD dwVal);
485#endif
f52be742 486#if defined(_WIN32) || !(HAVE_DECL___BSWAP_64)
64584976
VK
487 QWORD LIBNETXMS_EXPORTABLE __bswap_64(QWORD qwVal);
488#endif
9f20696e 489 double LIBNETXMS_EXPORTABLE __bswap_double(double dVal);
273da39a 490 void LIBNETXMS_EXPORTABLE __bswap_wstr(UCS2CHAR *pStr);
64584976 491
076a55c4 492#if !defined(_WIN32) && !defined(_NETWARE)
8b86c5dc
VK
493#if defined(UNICODE_UCS2) || defined(UNICODE_UCS4)
494 void LIBNETXMS_EXPORTABLE wcsupr(WCHAR *in);
495#endif
496 void LIBNETXMS_EXPORTABLE strupr(char *in);
7e679c4b 497#endif
ab588c84 498
b8a8d064
VK
499 void LIBNETXMS_EXPORTABLE QSortEx(void *base, size_t nmemb, size_t size, void *arg,
500 int (*compare)(const void *, const void *, void *));
501
670c7f3d 502 INT64 LIBNETXMS_EXPORTABLE GetCurrentTimeMs(void);
3aa0061c 503 QWORD LIBNETXMS_EXPORTABLE FileSize(const TCHAR *pszFileName);
670c7f3d 504
64584976 505 int LIBNETXMS_EXPORTABLE BitsInMask(DWORD dwMask);
018fda4d 506 TCHAR LIBNETXMS_EXPORTABLE *IpToStr(DWORD dwAddr, TCHAR *szBuffer);
3aa0061c 507 DWORD LIBNETXMS_EXPORTABLE ResolveHostName(const TCHAR *pszName);
a1dc75b0 508
64584976 509 void LIBNETXMS_EXPORTABLE *nx_memdup(const void *pData, DWORD dwSize);
f218dc6d 510 void LIBNETXMS_EXPORTABLE nx_memswap(void *pBlock1, void *pBlock2, DWORD dwSize);
31521248 511
e25cadc9 512 TCHAR LIBNETXMS_EXPORTABLE *BinToStr(BYTE *pData, DWORD dwSize, TCHAR *pStr);
3aa0061c 513 DWORD LIBNETXMS_EXPORTABLE StrToBin(const TCHAR *pStr, BYTE *pData, DWORD dwSize);
c61f5190 514 void LIBNETXMS_EXPORTABLE MACToStr(BYTE *pData, TCHAR *pStr);
b50f1100 515
018fda4d 516 void LIBNETXMS_EXPORTABLE StrStrip(TCHAR *pszStr);
0bbab9d3 517 void LIBNETXMS_EXPORTABLE Trim(TCHAR *str);
018fda4d 518 BOOL LIBNETXMS_EXPORTABLE MatchString(const TCHAR *pattern, const TCHAR *string, BOOL matchCase);
9eea20df 519 BOOL LIBNETXMS_EXPORTABLE RegexpMatch(const TCHAR *pszStr, const TCHAR *pszExpr, BOOL bMatchCase);
018fda4d 520 TCHAR LIBNETXMS_EXPORTABLE *ExtractWord(TCHAR *line, TCHAR *buffer);
f3cdd1c5 521 TCHAR LIBNETXMS_EXPORTABLE **SplitString(const TCHAR *source, TCHAR sep, int *numStrings);
2391d4fd 522 int LIBNETXMS_EXPORTABLE NumChars(const TCHAR *pszStr, int ch);
3783d300 523 void LIBNETXMS_EXPORTABLE RemoveTrailingCRLF(TCHAR *str);
f7794b68
VK
524#ifdef __cplusplus
525 BOOL LIBNETXMS_EXPORTABLE IsValidObjectName(const TCHAR *pszName, BOOL bExtendedChars = FALSE);
526#endif
fa2b47a7 527 BOOL LIBNETXMS_EXPORTABLE IsValidScriptName(const TCHAR *pszName);
2391d4fd 528 void LIBNETXMS_EXPORTABLE TranslateStr(TCHAR *pszString, const TCHAR *pszSubStr, const TCHAR *pszReplace);
257defd7 529 TCHAR LIBNETXMS_EXPORTABLE *GetCleanFileName(TCHAR *pszFileName);
c3cfc039 530 void LIBNETXMS_EXPORTABLE GetOSVersionString(TCHAR *pszBuffer, int nBufSize);
3aa0061c 531 BYTE LIBNETXMS_EXPORTABLE *LoadFile(const TCHAR *pszFileName, DWORD *pdwFileSize);
ec4995e6 532
6120112b 533 DWORD LIBNETXMS_EXPORTABLE CalculateCRC32(const unsigned char *pData, DWORD dwSize, DWORD dwCRC);
a3c76aba 534 void LIBNETXMS_EXPORTABLE CalculateMD5Hash(const unsigned char *data, size_t nbytes, unsigned char *hash);
e0d4b618 535 void LIBNETXMS_EXPORTABLE MD5HashForPattern(const unsigned char *data, size_t patternSize, size_t fullSize, BYTE *hash);
a3c76aba 536 void LIBNETXMS_EXPORTABLE CalculateSHA1Hash(unsigned char *data, size_t nbytes, unsigned char *hash);
e0d4b618 537 void LIBNETXMS_EXPORTABLE SHA1HashForPattern(unsigned char *data, size_t patternSize, size_t fullSize, unsigned char *hash);
3aa0061c
VK
538 BOOL LIBNETXMS_EXPORTABLE CalculateFileMD5Hash(const TCHAR *pszFileName, BYTE *pHash);
539 BOOL LIBNETXMS_EXPORTABLE CalculateFileSHA1Hash(const TCHAR *pszFileName, BYTE *pHash);
540 BOOL LIBNETXMS_EXPORTABLE CalculateFileCRC32(const TCHAR *pszFileName, DWORD *pResult);
66c04cc7 541
46ef501a
VK
542 DWORD LIBNETXMS_EXPORTABLE IcmpPing(DWORD dwAddr, int iNumRetries, DWORD dwTimeout,
543 DWORD *pdwRTT, DWORD dwPacketSize);
4826c8a5 544
e6c91aac
VK
545 /* deprecated:
546 DWORD LIBNETXMS_EXPORTABLE NxLoadConfig(const TCHAR *pszFileName, const TCHAR *pszSection,
547 NX_CFG_TEMPLATE *pTemplateList, BOOL bPrint);*/
3aa0061c 548 int LIBNETXMS_EXPORTABLE NxDCIDataTypeFromText(const TCHAR *pszText);
aa13cfd9 549
4560d8bd 550 HMODULE LIBNETXMS_EXPORTABLE DLOpen(const TCHAR *pszLibName, TCHAR *pszErrorText);
aa13cfd9 551 void LIBNETXMS_EXPORTABLE DLClose(HMODULE hModule);
4560d8bd 552 void LIBNETXMS_EXPORTABLE *DLGetSymbolAddr(HMODULE hModule, const TCHAR *pszSymbol, TCHAR *pszErrorText);
aa13cfd9 553
6173bea8
VK
554 void LIBNETXMS_EXPORTABLE InitSubAgentAPI(void (* writeLog)(int, const TCHAR *),
555 void (* sendTrap2)(DWORD, const char *, va_list),
556 void (* sendTrap1)(DWORD, int, TCHAR **),
557 BOOL (* sendFile)(void *, DWORD, const char *, long));
2e06d08b 558
2e06d08b
VK
559 BOOL LIBNETXMS_EXPORTABLE ExtractNamedOptionValue(const TCHAR *optString, const TCHAR *option, TCHAR *buffer, int bufSize);
560 BOOL LIBNETXMS_EXPORTABLE ExtractNamedOptionValueAsBool(const TCHAR *optString, const TCHAR *option, BOOL defVal);
561 long LIBNETXMS_EXPORTABLE ExtractNamedOptionValueAsInt(const TCHAR *optString, const TCHAR *option, long defVal);
ae9cddaf 562
92502d5f 563 TCHAR LIBNETXMS_EXPORTABLE *EscapeStringForXML(const TCHAR *string, int length);
66ae1b17
VK
564 const char LIBNETXMS_EXPORTABLE *XMLGetAttr(const char **attrs, const char *name);
565 int LIBNETXMS_EXPORTABLE XMLGetAttrInt(const char **attrs, const char *name, int defVal);
af885dca 566 DWORD LIBNETXMS_EXPORTABLE XMLGetAttrDWORD(const char **attrs, const char *name, DWORD defVal);
ccc34207 567 bool LIBNETXMS_EXPORTABLE XMLGetAttrBoolean(const char **attrs, const char *name, bool defVal);
92502d5f 568
bc858635
VK
569#ifdef __cplusplus
570 const TCHAR LIBNETXMS_EXPORTABLE *CodeToText(int iCode, CODE_TO_TEXT *pTranslator, const TCHAR *pszDefaultText = _T("Unknown"));
571#else
572 const TCHAR LIBNETXMS_EXPORTABLE *CodeToText(int iCode, CODE_TO_TEXT *pTranslator, const TCHAR *pszDefaultText);
573#endif
574
aa13cfd9 575#ifdef _WIN32
4299401e 576 TCHAR LIBNETXMS_EXPORTABLE *GetSystemErrorText(DWORD dwError, TCHAR *pszBuffer, size_t iBufSize);
ccc34207 577 BOOL LIBNETXMS_EXPORTABLE GetWindowsVersionString(TCHAR *versionString, int strSize);
aa13cfd9 578#endif
696fc54f
VK
579
580#if !(HAVE_DAEMON)
b1a57444 581 int LIBNETXMS_EXPORTABLE daemon(int nochdir, int noclose);
696fc54f 582#endif
4332e9d8 583
3aa0061c 584 DWORD LIBNETXMS_EXPORTABLE inet_addr_w(const WCHAR *pszAddr);
268774a0 585
4332e9d8 586#ifndef _WIN32
664c7c49 587 BOOL LIBNETXMS_EXPORTABLE SetDefaultCodepage(const char *cp);
3aa0061c 588 int LIBNETXMS_EXPORTABLE WideCharToMultiByte(int iCodePage, DWORD dwFlags, const WCHAR *pWideCharStr,
4332e9d8
VK
589 int cchWideChar, char *pByteStr, int cchByteChar,
590 char *pDefaultChar, BOOL *pbUsedDefChar);
3aa0061c 591 int LIBNETXMS_EXPORTABLE MultiByteToWideChar(int iCodePage, DWORD dwFlags, const char *pByteStr,
4332e9d8
VK
592 int cchByteChar, WCHAR *pWideCharStr,
593 int cchWideChar);
04dbaf62 594
6b93c954 595#if !defined(UNICODE_UCS2) || !HAVE_WCSLEN
8b86c5dc 596 int LIBNETXMS_EXPORTABLE ucs2_strlen(const UCS2CHAR *pStr);
6b93c954
VK
597#endif
598#if !defined(UNICODE_UCS2) || !HAVE_WCSNCPY
8b86c5dc 599 UCS2CHAR LIBNETXMS_EXPORTABLE *ucs2_strncpy(UCS2CHAR *pDst, const UCS2CHAR *pSrc, int nDstLen);
6b93c954
VK
600#endif
601#if !defined(UNICODE_UCS2) || !HAVE_WCSDUP
8b86c5dc 602 UCS2CHAR LIBNETXMS_EXPORTABLE *ucs2_strdup(const UCS2CHAR *pStr);
4332e9d8 603#endif
8b86c5dc
VK
604
605#ifndef UNICODE
606 size_t LIBNETXMS_EXPORTABLE ucs2_to_mb(const UCS2CHAR *src, size_t srcLen, char *dst, size_t dstLen);
607 size_t LIBNETXMS_EXPORTABLE mb_to_ucs2(const char *src, size_t srcLen, UCS2CHAR *dst, size_t dstLen);
39945910
VK
608 UCS2CHAR LIBNETXMS_EXPORTABLE *UCS2StringFromMBString(const char *pszString);
609 char LIBNETXMS_EXPORTABLE *MBStringFromUCS2String(const UCS2CHAR *pszString);
8b86c5dc
VK
610#endif
611
04dbaf62 612#ifdef UNICODE
6e17f325
VK
613 int LIBNETXMS_EXPORTABLE nx_wprintf(const WCHAR *format, ...);
614 int LIBNETXMS_EXPORTABLE nx_fwprintf(FILE *fp, const WCHAR *format, ...);
615 int LIBNETXMS_EXPORTABLE nx_swprintf(WCHAR *buffer, size_t size, const WCHAR *format, ...);
616 int LIBNETXMS_EXPORTABLE nx_vwprintf(const WCHAR *format, va_list args);
617 int LIBNETXMS_EXPORTABLE nx_vfwprintf(FILE *fp, const WCHAR *format, va_list args);
618 int LIBNETXMS_EXPORTABLE nx_vswprintf(WCHAR *buffer, size_t size, const WCHAR *format, va_list args);
04dbaf62
VK
619#endif
620
3e39fcde 621#endif /* _WIN32 */
8b86c5dc 622
3aa0061c 623 WCHAR LIBNETXMS_EXPORTABLE *WideStringFromMBString(const char *pszString);
c16afb3d 624 WCHAR LIBNETXMS_EXPORTABLE *WideStringFromUTF8String(const char *pszString);
3aa0061c
VK
625 char LIBNETXMS_EXPORTABLE *MBStringFromWideString(const WCHAR *pwszString);
626 char LIBNETXMS_EXPORTABLE *UTF8StringFromWideString(const WCHAR *pwszString);
8b86c5dc 627
3d1058ed
VK
628#ifdef _WITH_ENCRYPTION
629 WCHAR LIBNETXMS_EXPORTABLE *ERR_error_string_W(int nError, WCHAR *pwszBuffer);
630#endif
631
8b86c5dc
VK
632#ifdef UNICODE_UCS4
633 size_t LIBNETXMS_EXPORTABLE ucs2_to_ucs4(const UCS2CHAR *src, size_t srcLen, WCHAR *dst, size_t dstLen);
634 size_t LIBNETXMS_EXPORTABLE ucs4_to_ucs2(const WCHAR *src, size_t srcLen, UCS2CHAR *dst, size_t dstLen);
b6e8dffe 635 size_t LIBNETXMS_EXPORTABLE ucs2_to_utf8(const UCS2CHAR *src, size_t srcLen, char *dst, size_t dstLen);
d9b66a56
VK
636 UCS2CHAR LIBNETXMS_EXPORTABLE *UCS2StringFromUCS4String(const WCHAR *pwszString);
637 WCHAR LIBNETXMS_EXPORTABLE *UCS4StringFromUCS2String(const UCS2CHAR *pszString);
b50f1100 638#endif
8b86c5dc 639
d9b66a56
VK
640#ifdef UNICODE
641
8b86c5dc
VK
642#if !HAVE_WFOPEN
643 FILE LIBNETXMS_EXPORTABLE *wfopen(const WCHAR *_name, const WCHAR *_type);
644#endif
645#if !HAVE_WOPEN
646 int LIBNETXMS_EXPORTABLE wopen(const WCHAR *, int, ...);
b50f1100 647#endif
8b86c5dc
VK
648#if !HAVE_WSTAT
649 int wstat(const WCHAR *_path, struct stat *_sbuf);
dde96745 650#endif
ccc34207
VK
651#if !HAVE_WRENAME
652 int wrename(const WCHAR *_oldpath, const WCHAR *_newpath);
653#endif
654#if !HAVE_WUNLINK
655 int wunlink(const WCHAR *_path);
656#endif
273da39a
VK
657#if !HAVE_WGETENV
658 WCHAR *wgetenv(const WCHAR *_string);
659#endif
d49d7500
VK
660#if !HAVE_WCSERROR && HAVE_STRERROR
661 WCHAR *wcserror(int errnum);
662#endif
663#if !HAVE_WCSERROR_R && HAVE_STRERROR_R
664 WCHAR *wcserror_r(int errnum, WCHAR *strerrbuf, size_t buflen);
665#endif
e05f8aaf
VK
666
667#endif /* UNICODE */
668
8b86c5dc
VK
669#if !HAVE_STRTOLL
670 INT64 LIBNETXMS_EXPORTABLE strtoll(const char *nptr, char **endptr, int base);
671#endif
672#if !HAVE_STRTOULL
673 QWORD LIBNETXMS_EXPORTABLE strtoull(const char *nptr, char **endptr, int base);
674#endif
e05f8aaf
VK
675
676#if !HAVE_WCSTOLL
677 INT64 LIBNETXMS_EXPORTABLE wcstoll(const WCHAR *nptr, WCHAR **endptr, int base);
678#endif
679#if !HAVE_WCSTOULL
680 QWORD LIBNETXMS_EXPORTABLE wcstoull(const WCHAR *nptr, WCHAR **endptr, int base);
681#endif
b50f1100 682
3d1cb7d6 683#ifdef _WIN32
37d62364 684#ifndef SWIGPERL
3d1cb7d6 685 DIR LIBNETXMS_EXPORTABLE *opendir(const char *filename);
7f9e0c00 686 struct dirent LIBNETXMS_EXPORTABLE *readdir(DIR *dirp);
3d1cb7d6
VK
687 int LIBNETXMS_EXPORTABLE closedir(DIR *dirp);
688#endif
37d62364 689#endif
3d1cb7d6 690
7f9e0c00
VK
691#if defined(_WIN32) || !(HAVE_SCANDIR)
692 int LIBNETXMS_EXPORTABLE scandir(const char *dir, struct dirent ***namelist,
693 int (*select)(const struct dirent *),
694 int (*compar)(const struct dirent **, const struct dirent **));
695 int LIBNETXMS_EXPORTABLE alphasort(const struct dirent **a, const struct dirent **b);
696#endif
697
55b33d4c
VK
698#ifdef UNDER_CE
699 int LIBNETXMS_EXPORTABLE _topen(TCHAR *pszName, int nFlags, ...);
700 int LIBNETXMS_EXPORTABLE read(int hFile, void *pBuffer, size_t nBytes);
701 int LIBNETXMS_EXPORTABLE write(int hFile, void *pBuffer, size_t nBytes);
702#endif
703
b71bff93 704#if !defined(_WIN32) && !defined(_NETWARE) && defined(NMS_THREADS_H_INCLUDED)
953dfe76 705void LIBNETXMS_EXPORTABLE StartMainLoop(THREAD_RESULT (THREAD_CALL * pfSignalHandler)(void *),
45c13da4 706 THREAD_RESULT (THREAD_CALL * pfMain)(void *));
953dfe76
VK
707#endif
708
9f2902ac 709BOOL LIBNETXMS_EXPORTABLE nxlog_open(const TCHAR *logName, DWORD flags, const TCHAR *msgModule,
d49d7500 710 unsigned int msgCount, const TCHAR **messages);
9f2902ac
VK
711void LIBNETXMS_EXPORTABLE nxlog_close(void);
712void LIBNETXMS_EXPORTABLE nxlog_write(DWORD msg, WORD wType, const char *format, ...);
4addc3a3
VK
713BOOL LIBNETXMS_EXPORTABLE nxlog_set_rotation_policy(int maxLogSize, int historySize);
714BOOL LIBNETXMS_EXPORTABLE nxlog_rotate();
9f2902ac 715
b50f1100 716#ifdef __cplusplus
e9246d26 717}
b50f1100 718#endif
e9246d26
VK
719
720#endif /* _nms_util_h_ */