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