implemented object serach by IP address
[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
b160350d
VK
113//
114// Class for serial communications
115//
116
117#ifdef __cplusplus
118
119#ifndef _WIN32
120enum
121{
122 NOPARITY,
123 ODDPARITY,
124 EVENPARITY,
125 ONESTOPBIT,
126 TWOSTOPBITS
127};
128
70fed300
AK
129enum
130{
131 FLOW_NONE,
132 FLOW_HARDWARE,
133 FLOW_SOFTWARE
134};
135
b160350d
VK
136#ifndef INVALID_HANDLE_VALUE
137#define INVALID_HANDLE_VALUE (-1)
138#endif
139#endif /* _WIN32 */
140
141class LIBNETXMS_EXPORTABLE Serial
142{
143public:
144 Serial(void);
145 ~Serial(void);
146
e2d68ddd 147 bool Open(const TCHAR *pszPort);
b160350d
VK
148 void Close(void);
149 void SetTimeout(int nTimeout);
f3a581d0
AK
150 int Read(char *pBuff, int nSize); /* waits up to timeout and do single read */
151 int ReadAll(char *pBuff, int nSize); /* read until timeout or out of space */
e2d68ddd 152 bool Write(const char *pBuff, int nSize);
b160350d
VK
153 void Flush(void);
154 bool Set(int nSpeed, int nDataBits, int nParity, int nStopBits);
70fed300 155 bool Set(int nSpeed, int nDataBits, int nParity, int nStopBits, int nFlowControl);
b160350d
VK
156 bool Restart(void);
157
158private:
159 TCHAR *m_pszPort;
160 int m_nTimeout;
161 int m_nSpeed;
162 int m_nDataBits;
163 int m_nStopBits;
164 int m_nParity;
70fed300 165 int m_nFlowControl;
b160350d
VK
166
167#ifndef _WIN32
168 int m_hPort;
70fed300 169 struct termios m_originalSettings;
b160350d
VK
170#else
171 HANDLE m_hPort;
172#endif
173};
174
ff214673
VK
175
176//
177// Class for table data storage
178//
179
180class LIBNETXMS_EXPORTABLE Table
181{
182private:
183 int m_nNumRows;
184 int m_nNumCols;
185 TCHAR **m_ppData;
186 TCHAR **m_ppColNames;
187
188public:
189 Table();
190 ~Table();
191
192 int GetNumRows(void) { return m_nNumRows; }
193 int GetNumColumns(void) { return m_nNumCols; }
194
195 void AddColumn(TCHAR *pszName);
196 void AddRow(void);
197
198 void SetAt(int nRow, int nCol, TCHAR *pszData);
199 void SetAt(int nRow, int nCol, LONG nData);
200 void SetAt(int nRow, int nCol, DWORD dwData);
201 void SetAt(int nRow, int nCol, double dData);
202 void SetAt(int nRow, int nCol, INT64 nData);
203 void SetAt(int nRow, int nCol, QWORD qwData);
204
205 void Set(int nCol, TCHAR *pszData) { SetAt(m_nNumRows - 1, nCol, pszData); }
206 void Set(int nCol, LONG nData) { SetAt(m_nNumRows - 1, nCol, nData); }
207 void Set(int nCol, DWORD dwData) { SetAt(m_nNumRows - 1, nCol, dwData); }
208 void Set(int nCol, double dData) { SetAt(m_nNumRows - 1, nCol, dData); }
209 void Set(int nCol, INT64 nData) { SetAt(m_nNumRows - 1, nCol, nData); }
210 void Set(int nCol, QWORD qwData) { SetAt(m_nNumRows - 1, nCol, qwData); }
211
212 TCHAR *GetAsString(int nRow, int nCol);
213 LONG GetAsInt(int nRow, int nCol);
214 DWORD GetAsUInt(int nRow, int nCol);
215 INT64 GetAsInt64(int nRow, int nCol);
216 QWORD GetAsUInt64(int nRow, int nCol);
217 double GetAsDouble(int nRow, int nCol);
218};
219
8bad8476
VK
220
221//
222// Dynamic string class
223//
224
225class LIBNETXMS_EXPORTABLE String
226{
227protected:
228 TCHAR *m_pszBuffer;
229 DWORD m_dwBufSize;
230
231public:
c577e360
VK
232 static const int npos;
233
8bad8476
VK
234 String();
235 ~String();
236
237 void SetBuffer(TCHAR *pszBuffer);
238
2391d4fd
VK
239 const String& operator =(const TCHAR *pszStr);
240 const String& operator +=(const TCHAR *pszStr);
8bad8476
VK
241 operator TCHAR*() { return CHECK_NULL_EX(m_pszBuffer); }
242
2391d4fd 243 void AddString(const TCHAR *pStr, DWORD dwLen);
c577e360
VK
244 void AddDynamicString(TCHAR *pszStr) { if (pszStr != NULL) { *this += pszStr; free(pszStr); } }
245
2391d4fd 246 void AddFormattedString(const TCHAR *pszFormat, ...);
8bad8476 247 void EscapeCharacter(int ch, int esc);
2391d4fd 248 void Translate(const TCHAR *pszSrc, const TCHAR *pszDst);
c577e360 249
1e1450ef 250 DWORD Size() { return m_dwBufSize > 0 ? m_dwBufSize - 1 : 0; }
c577e360
VK
251
252 TCHAR *SubStr(int nStart, int nLen, TCHAR *pszBuffer);
253 TCHAR *SubStr(int nStart, int nLen) { return SubStr(nStart, nLen, NULL); }
2391d4fd 254 int Find(const TCHAR *pszStr, int nStart = 0);
1e1450ef
VK
255
256 void Strip();
c577e360
VK
257};
258
259
260//
261// String map class
262//
263
264class LIBNETXMS_EXPORTABLE StringMap
265{
266protected:
267 DWORD m_dwSize;
268 TCHAR **m_ppszKeys;
269 TCHAR **m_ppszValues;
270
c90d3610 271 DWORD Find(const TCHAR *pszKey);
c577e360
VK
272
273public:
274 StringMap();
35dfcebd 275 StringMap(StringMap *src);
c577e360
VK
276 ~StringMap();
277
40b7416c
VK
278 StringMap& operator =(StringMap &src);
279
c90d3610 280 void Set(const TCHAR *pszKey, const TCHAR *pszValue);
40b7416c 281 void SetPreallocated(TCHAR *pszKey, TCHAR *pszValue);
c90d3610 282 TCHAR *Get(const TCHAR *pszKey);
431f302b 283 void Delete(const TCHAR *pszKey);
c577e360
VK
284 void Clear(void);
285
286 DWORD Size(void) { return m_dwSize; }
287 TCHAR *GetKeyByIndex(DWORD idx) { return (idx < m_dwSize) ? m_ppszKeys[idx] : NULL; }
288 TCHAR *GetValueByIndex(DWORD idx) { return (idx < m_dwSize) ? m_ppszValues[idx] : NULL; }
8bad8476
VK
289};
290
b160350d
VK
291#endif /* __cplusplus */
292
293
4826c8a5
VK
294//
295// Configuration item template for configuration loader
296//
297
298typedef struct
299{
018fda4d 300 TCHAR szToken[64];
4826c8a5
VK
301 BYTE iType;
302 BYTE cSeparator; // Separator character for lists
303 WORD wListElements; // Number of list elements, should be set to 0 before calling NxLoadConfig()
304 DWORD dwBufferSize; // Buffer size for strings or flag to be set for CT_BOOLEAN
305 DWORD dwBufferPos; // Should be set to 0
306 void *pBuffer;
307} NX_CFG_TEMPLATE;
dcb44c9a
VK
308
309
bc858635
VK
310//
311// Code translation structure
312//
313
314typedef struct __CODE_TO_TEXT
315{
316 int code;
317 const TCHAR *text;
318} CODE_TO_TEXT;
319
320
3046f9a4
VK
321//
322// getopt() prototype if needed
323//
324
325#ifdef _WIN32
99e50bb7 326#include <netxms_getopt.h>
3046f9a4
VK
327#endif
328
329
f2fdf1b5
VK
330//
331// Win32 API functions missing under WinCE
332//
333
c32b805a 334#if defined(UNDER_CE) && defined(__cplusplus)
f2fdf1b5
VK
335
336inline void GetSystemTimeAsFileTime(LPFILETIME pFt)
337{
338 SYSTEMTIME sysTime;
339
340 GetSystemTime(&sysTime);
341 SystemTimeToFileTime(&sysTime, pFt);
342}
343
344#endif // UNDER_CE
345
346
3d1cb7d6
VK
347//
348// Structures for opendir() / readdir() / closedir()
349//
350
351#ifdef _WIN32
352
37d62364
AK
353#ifndef SWIGPERL
354
7f9e0c00 355typedef struct dirent
3d1cb7d6
VK
356{
357 long d_ino; /* inode number (not used by MS-DOS) */
358 int d_namlen; /* Name length */
359 char d_name[257]; /* file name */
360} _DIRECT;
361
362typedef struct _dir_struc
363{
364 char *start; /* Starting position */
365 char *curr; /* Current position */
366 long size; /* Size of string table */
367 long nfiles; /* number if filenames in table */
7f9e0c00 368 struct dirent dirstr; /* Directory structure to return */
3d1cb7d6
VK
369} DIR;
370
37d62364
AK
371#endif
372
3d1cb7d6
VK
373#endif /* _WIN32 */
374
375
e9246d26
VK
376//
377// Functions
378//
379
43d92b4c 380
babb8280 381#if WORDS_BIGENDIAN
43d92b4c
VK
382#define htonq(x) (x)
383#define ntohq(x) (x)
9f20696e
VK
384#define htond(x) (x)
385#define ntohd(x) (x)
babb8280
VK
386#define SwapWideString(x)
387#else
ca6ad6bb
VK
388#ifdef HAVE_HTONLL
389#define htonq(x) htonll(x)
390#else
babb8280 391#define htonq(x) __bswap_64(x)
ca6ad6bb
VK
392#endif
393#ifdef HAVE_NTOHLL
394#define ntohq(x) ntohll(x)
395#else
babb8280 396#define ntohq(x) __bswap_64(x)
ca6ad6bb 397#endif
babb8280
VK
398#define htond(x) __bswap_double(x)
399#define ntohd(x) __bswap_double(x)
400#define SwapWideString(x) __bswap_wstr(x)
43d92b4c 401#endif
15929b31 402
55b33d4c
VK
403#ifdef UNDER_CE
404#define close(x) CloseHandle((HANDLE)(x))
405#endif
406
c81979bc
VK
407#ifdef __cplusplus
408#ifndef LIBNETXMS_INLINE
409 inline TCHAR *nx_strncpy(TCHAR *pszDest, const TCHAR *pszSrc, int nLen)
410 {
411 _tcsncpy(pszDest, pszSrc, nLen - 1);
412 pszDest[nLen - 1] = 0;
413 return pszDest;
414 }
415#endif
416#else
3aa0061c 417 TCHAR LIBNETXMS_EXPORTABLE *nx_strncpy(TCHAR *pszDest, const TCHAR *pszSrc, int nLen);
c81979bc
VK
418#endif
419
b50f1100 420#ifdef __cplusplus
e9246d26
VK
421extern "C"
422{
b50f1100 423#endif
08043edf
VK
424 int LIBNETXMS_EXPORTABLE SendEx(SOCKET, const void *, size_t, int);
425 int LIBNETXMS_EXPORTABLE RecvEx(SOCKET nSocket, const void *pBuff,
426 size_t nSize, int nFlags, DWORD dwTimeout);
b24955fb 427
c5b523e2
VK
428#if defined(_WIN32) || !(HAVE_DECL___BSWAP_32)
429 DWORD LIBNETXMS_EXPORTABLE __bswap_32(DWORD dwVal);
430#endif
f52be742 431#if defined(_WIN32) || !(HAVE_DECL___BSWAP_64)
64584976
VK
432 QWORD LIBNETXMS_EXPORTABLE __bswap_64(QWORD qwVal);
433#endif
9f20696e 434 double LIBNETXMS_EXPORTABLE __bswap_double(double dVal);
273da39a 435 void LIBNETXMS_EXPORTABLE __bswap_wstr(UCS2CHAR *pStr);
64584976 436
076a55c4 437#if !defined(_WIN32) && !defined(_NETWARE)
8b86c5dc
VK
438#if defined(UNICODE_UCS2) || defined(UNICODE_UCS4)
439 void LIBNETXMS_EXPORTABLE wcsupr(WCHAR *in);
440#endif
441 void LIBNETXMS_EXPORTABLE strupr(char *in);
7e679c4b 442#endif
ab588c84 443
b8a8d064
VK
444 void LIBNETXMS_EXPORTABLE QSortEx(void *base, size_t nmemb, size_t size, void *arg,
445 int (*compare)(const void *, const void *, void *));
446
670c7f3d 447 INT64 LIBNETXMS_EXPORTABLE GetCurrentTimeMs(void);
3aa0061c 448 QWORD LIBNETXMS_EXPORTABLE FileSize(const TCHAR *pszFileName);
670c7f3d 449
64584976 450 int LIBNETXMS_EXPORTABLE BitsInMask(DWORD dwMask);
018fda4d 451 TCHAR LIBNETXMS_EXPORTABLE *IpToStr(DWORD dwAddr, TCHAR *szBuffer);
3aa0061c 452 DWORD LIBNETXMS_EXPORTABLE ResolveHostName(const TCHAR *pszName);
a1dc75b0 453
64584976 454 void LIBNETXMS_EXPORTABLE *nx_memdup(const void *pData, DWORD dwSize);
f218dc6d 455 void LIBNETXMS_EXPORTABLE nx_memswap(void *pBlock1, void *pBlock2, DWORD dwSize);
31521248 456
e25cadc9 457 TCHAR LIBNETXMS_EXPORTABLE *BinToStr(BYTE *pData, DWORD dwSize, TCHAR *pStr);
3aa0061c 458 DWORD LIBNETXMS_EXPORTABLE StrToBin(const TCHAR *pStr, BYTE *pData, DWORD dwSize);
c61f5190 459 void LIBNETXMS_EXPORTABLE MACToStr(BYTE *pData, TCHAR *pStr);
b50f1100 460
018fda4d
AK
461 void LIBNETXMS_EXPORTABLE StrStrip(TCHAR *pszStr);
462 BOOL LIBNETXMS_EXPORTABLE MatchString(const TCHAR *pattern, const TCHAR *string, BOOL matchCase);
ea1acec2 463 BOOL LIBNETXMS_EXPORTABLE RegexpMatch(TCHAR *pszStr, TCHAR *pszExpr, BOOL bMatchCase);
018fda4d 464 TCHAR LIBNETXMS_EXPORTABLE *ExtractWord(TCHAR *line, TCHAR *buffer);
2391d4fd 465 int LIBNETXMS_EXPORTABLE NumChars(const TCHAR *pszStr, int ch);
f7794b68
VK
466#ifdef __cplusplus
467 BOOL LIBNETXMS_EXPORTABLE IsValidObjectName(const TCHAR *pszName, BOOL bExtendedChars = FALSE);
468#endif
fa2b47a7 469 BOOL LIBNETXMS_EXPORTABLE IsValidScriptName(const TCHAR *pszName);
2391d4fd 470 void LIBNETXMS_EXPORTABLE TranslateStr(TCHAR *pszString, const TCHAR *pszSubStr, const TCHAR *pszReplace);
257defd7 471 TCHAR LIBNETXMS_EXPORTABLE *GetCleanFileName(TCHAR *pszFileName);
c3cfc039 472 void LIBNETXMS_EXPORTABLE GetOSVersionString(TCHAR *pszBuffer, int nBufSize);
3aa0061c 473 BYTE LIBNETXMS_EXPORTABLE *LoadFile(const TCHAR *pszFileName, DWORD *pdwFileSize);
ec4995e6 474
6120112b 475 DWORD LIBNETXMS_EXPORTABLE CalculateCRC32(const unsigned char *pData, DWORD dwSize, DWORD dwCRC);
a3c76aba
VK
476 void LIBNETXMS_EXPORTABLE CalculateMD5Hash(const unsigned char *data, size_t nbytes, unsigned char *hash);
477 void LIBNETXMS_EXPORTABLE CalculateSHA1Hash(unsigned char *data, size_t nbytes, unsigned char *hash);
3aa0061c
VK
478 BOOL LIBNETXMS_EXPORTABLE CalculateFileMD5Hash(const TCHAR *pszFileName, BYTE *pHash);
479 BOOL LIBNETXMS_EXPORTABLE CalculateFileSHA1Hash(const TCHAR *pszFileName, BYTE *pHash);
480 BOOL LIBNETXMS_EXPORTABLE CalculateFileCRC32(const TCHAR *pszFileName, DWORD *pResult);
66c04cc7 481
46ef501a
VK
482 DWORD LIBNETXMS_EXPORTABLE IcmpPing(DWORD dwAddr, int iNumRetries, DWORD dwTimeout,
483 DWORD *pdwRTT, DWORD dwPacketSize);
4826c8a5 484
3aa0061c 485 DWORD LIBNETXMS_EXPORTABLE NxLoadConfig(const TCHAR *pszFileName, const TCHAR *pszSection,
6849d9be 486 NX_CFG_TEMPLATE *pTemplateList, BOOL bPrint);
3aa0061c 487 int LIBNETXMS_EXPORTABLE NxDCIDataTypeFromText(const TCHAR *pszText);
aa13cfd9 488
4560d8bd 489 HMODULE LIBNETXMS_EXPORTABLE DLOpen(const TCHAR *pszLibName, TCHAR *pszErrorText);
aa13cfd9 490 void LIBNETXMS_EXPORTABLE DLClose(HMODULE hModule);
4560d8bd 491 void LIBNETXMS_EXPORTABLE *DLGetSymbolAddr(HMODULE hModule, const TCHAR *pszSymbol, TCHAR *pszErrorText);
aa13cfd9 492
ae9cddaf 493 void LIBNETXMS_EXPORTABLE InitSubAgentsLogger(void (* pFunc)(int, TCHAR *));
15c8cf46 494 void LIBNETXMS_EXPORTABLE InitSubAgentsTrapSender(void (* pFunc1)(DWORD, int, TCHAR **),
2e06d08b 495
a765d97c 496 void (* pFunc2)(DWORD, const char *, va_list));
2e06d08b
VK
497 BOOL LIBNETXMS_EXPORTABLE ExtractNamedOptionValue(const TCHAR *optString, const TCHAR *option, TCHAR *buffer, int bufSize);
498 BOOL LIBNETXMS_EXPORTABLE ExtractNamedOptionValueAsBool(const TCHAR *optString, const TCHAR *option, BOOL defVal);
499 long LIBNETXMS_EXPORTABLE ExtractNamedOptionValueAsInt(const TCHAR *optString, const TCHAR *option, long defVal);
ae9cddaf 500
92502d5f 501 TCHAR LIBNETXMS_EXPORTABLE *EscapeStringForXML(const TCHAR *string, int length);
66ae1b17
VK
502 const char LIBNETXMS_EXPORTABLE *XMLGetAttr(const char **attrs, const char *name);
503 int LIBNETXMS_EXPORTABLE XMLGetAttrInt(const char **attrs, const char *name, int defVal);
504 int LIBNETXMS_EXPORTABLE XMLGetAttrDWORD(const char **attrs, const char *name, DWORD defVal);
92502d5f 505
bc858635
VK
506#ifdef __cplusplus
507 const TCHAR LIBNETXMS_EXPORTABLE *CodeToText(int iCode, CODE_TO_TEXT *pTranslator, const TCHAR *pszDefaultText = _T("Unknown"));
508#else
509 const TCHAR LIBNETXMS_EXPORTABLE *CodeToText(int iCode, CODE_TO_TEXT *pTranslator, const TCHAR *pszDefaultText);
510#endif
511
aa13cfd9 512#ifdef _WIN32
018fda4d 513 TCHAR LIBNETXMS_EXPORTABLE *GetSystemErrorText(DWORD dwError, TCHAR *pszBuffer, int iBufSize);
aa13cfd9 514#endif
696fc54f
VK
515
516#if !(HAVE_DAEMON)
b1a57444 517 int LIBNETXMS_EXPORTABLE daemon(int nochdir, int noclose);
696fc54f 518#endif
4332e9d8 519
3aa0061c 520 DWORD LIBNETXMS_EXPORTABLE inet_addr_w(const WCHAR *pszAddr);
268774a0 521
4332e9d8 522#ifndef _WIN32
664c7c49 523 BOOL LIBNETXMS_EXPORTABLE SetDefaultCodepage(const char *cp);
3aa0061c 524 int LIBNETXMS_EXPORTABLE WideCharToMultiByte(int iCodePage, DWORD dwFlags, const WCHAR *pWideCharStr,
4332e9d8
VK
525 int cchWideChar, char *pByteStr, int cchByteChar,
526 char *pDefaultChar, BOOL *pbUsedDefChar);
3aa0061c 527 int LIBNETXMS_EXPORTABLE MultiByteToWideChar(int iCodePage, DWORD dwFlags, const char *pByteStr,
4332e9d8
VK
528 int cchByteChar, WCHAR *pWideCharStr,
529 int cchWideChar);
04dbaf62 530
6b93c954 531#if !defined(UNICODE_UCS2) || !HAVE_WCSLEN
8b86c5dc 532 int LIBNETXMS_EXPORTABLE ucs2_strlen(const UCS2CHAR *pStr);
6b93c954
VK
533#endif
534#if !defined(UNICODE_UCS2) || !HAVE_WCSNCPY
8b86c5dc 535 UCS2CHAR LIBNETXMS_EXPORTABLE *ucs2_strncpy(UCS2CHAR *pDst, const UCS2CHAR *pSrc, int nDstLen);
6b93c954
VK
536#endif
537#if !defined(UNICODE_UCS2) || !HAVE_WCSDUP
8b86c5dc 538 UCS2CHAR LIBNETXMS_EXPORTABLE *ucs2_strdup(const UCS2CHAR *pStr);
4332e9d8 539#endif
8b86c5dc
VK
540
541#ifndef UNICODE
542 size_t LIBNETXMS_EXPORTABLE ucs2_to_mb(const UCS2CHAR *src, size_t srcLen, char *dst, size_t dstLen);
543 size_t LIBNETXMS_EXPORTABLE mb_to_ucs2(const char *src, size_t srcLen, UCS2CHAR *dst, size_t dstLen);
544#endif
545
04dbaf62 546#ifdef UNICODE
6e17f325
VK
547 int LIBNETXMS_EXPORTABLE nx_wprintf(const WCHAR *format, ...);
548 int LIBNETXMS_EXPORTABLE nx_fwprintf(FILE *fp, const WCHAR *format, ...);
549 int LIBNETXMS_EXPORTABLE nx_swprintf(WCHAR *buffer, size_t size, const WCHAR *format, ...);
550 int LIBNETXMS_EXPORTABLE nx_vwprintf(const WCHAR *format, va_list args);
551 int LIBNETXMS_EXPORTABLE nx_vfwprintf(FILE *fp, const WCHAR *format, va_list args);
552 int LIBNETXMS_EXPORTABLE nx_vswprintf(WCHAR *buffer, size_t size, const WCHAR *format, va_list args);
04dbaf62
VK
553#endif
554
3e39fcde 555#endif /* _WIN32 */
8b86c5dc 556
3aa0061c 557 WCHAR LIBNETXMS_EXPORTABLE *WideStringFromMBString(const char *pszString);
c16afb3d 558 WCHAR LIBNETXMS_EXPORTABLE *WideStringFromUTF8String(const char *pszString);
3aa0061c
VK
559 char LIBNETXMS_EXPORTABLE *MBStringFromWideString(const WCHAR *pwszString);
560 char LIBNETXMS_EXPORTABLE *UTF8StringFromWideString(const WCHAR *pwszString);
8b86c5dc 561
3d1058ed
VK
562#ifdef _WITH_ENCRYPTION
563 WCHAR LIBNETXMS_EXPORTABLE *ERR_error_string_W(int nError, WCHAR *pwszBuffer);
564#endif
565
8b86c5dc
VK
566#ifdef UNICODE_UCS4
567 size_t LIBNETXMS_EXPORTABLE ucs2_to_ucs4(const UCS2CHAR *src, size_t srcLen, WCHAR *dst, size_t dstLen);
568 size_t LIBNETXMS_EXPORTABLE ucs4_to_ucs2(const WCHAR *src, size_t srcLen, UCS2CHAR *dst, size_t dstLen);
b6e8dffe 569 size_t LIBNETXMS_EXPORTABLE ucs2_to_utf8(const UCS2CHAR *src, size_t srcLen, char *dst, size_t dstLen);
d9b66a56
VK
570 UCS2CHAR LIBNETXMS_EXPORTABLE *UCS2StringFromUCS4String(const WCHAR *pwszString);
571 WCHAR LIBNETXMS_EXPORTABLE *UCS4StringFromUCS2String(const UCS2CHAR *pszString);
b50f1100 572#endif
8b86c5dc 573
d9b66a56
VK
574#ifdef UNICODE
575
8b86c5dc
VK
576#if !HAVE_WFOPEN
577 FILE LIBNETXMS_EXPORTABLE *wfopen(const WCHAR *_name, const WCHAR *_type);
578#endif
579#if !HAVE_WOPEN
580 int LIBNETXMS_EXPORTABLE wopen(const WCHAR *, int, ...);
b50f1100 581#endif
8b86c5dc
VK
582#if !HAVE_WSTAT
583 int wstat(const WCHAR *_path, struct stat *_sbuf);
dde96745 584#endif
273da39a
VK
585#if !HAVE_WGETENV
586 WCHAR *wgetenv(const WCHAR *_string);
587#endif
e05f8aaf
VK
588
589#endif /* UNICODE */
590
8b86c5dc
VK
591#if !HAVE_STRTOLL
592 INT64 LIBNETXMS_EXPORTABLE strtoll(const char *nptr, char **endptr, int base);
593#endif
594#if !HAVE_STRTOULL
595 QWORD LIBNETXMS_EXPORTABLE strtoull(const char *nptr, char **endptr, int base);
596#endif
e05f8aaf
VK
597
598#if !HAVE_WCSTOLL
599 INT64 LIBNETXMS_EXPORTABLE wcstoll(const WCHAR *nptr, WCHAR **endptr, int base);
600#endif
601#if !HAVE_WCSTOULL
602 QWORD LIBNETXMS_EXPORTABLE wcstoull(const WCHAR *nptr, WCHAR **endptr, int base);
603#endif
b50f1100 604
3d1cb7d6 605#ifdef _WIN32
37d62364 606#ifndef SWIGPERL
3d1cb7d6 607 DIR LIBNETXMS_EXPORTABLE *opendir(const char *filename);
7f9e0c00 608 struct dirent LIBNETXMS_EXPORTABLE *readdir(DIR *dirp);
3d1cb7d6
VK
609 int LIBNETXMS_EXPORTABLE closedir(DIR *dirp);
610#endif
37d62364 611#endif
3d1cb7d6 612
7f9e0c00
VK
613#if defined(_WIN32) || !(HAVE_SCANDIR)
614 int LIBNETXMS_EXPORTABLE scandir(const char *dir, struct dirent ***namelist,
615 int (*select)(const struct dirent *),
616 int (*compar)(const struct dirent **, const struct dirent **));
617 int LIBNETXMS_EXPORTABLE alphasort(const struct dirent **a, const struct dirent **b);
618#endif
619
55b33d4c
VK
620#ifdef UNDER_CE
621 int LIBNETXMS_EXPORTABLE _topen(TCHAR *pszName, int nFlags, ...);
622 int LIBNETXMS_EXPORTABLE read(int hFile, void *pBuffer, size_t nBytes);
623 int LIBNETXMS_EXPORTABLE write(int hFile, void *pBuffer, size_t nBytes);
624#endif
625
b71bff93 626#if !defined(_WIN32) && !defined(_NETWARE) && defined(NMS_THREADS_H_INCLUDED)
953dfe76 627void LIBNETXMS_EXPORTABLE StartMainLoop(THREAD_RESULT (THREAD_CALL * pfSignalHandler)(void *),
45c13da4 628 THREAD_RESULT (THREAD_CALL * pfMain)(void *));
953dfe76
VK
629#endif
630
b50f1100 631#ifdef __cplusplus
e9246d26 632}
b50f1100 633#endif
e9246d26
VK
634
635#endif /* _nms_util_h_ */
70fed300
AK
636
637///////////////////////////////////////////////////////////////////////////////
638/*
639
640$Log: not supported by cvs2svn $
6b93c954
VK
641Revision 1.124 2008/04/18 17:54:06 victor
642SQLite driver changed to new API spec
643
c16afb3d
VK
644Revision 1.123 2008/04/14 15:33:33 victor
645Added possibility to use non-UNICODE bindings in ODBC calls
646
2e06d08b
VK
647Revision 1.122 2008/04/12 10:44:45 victor
648ODBC driver now compiles on systems with 4-byte wchar_t
649
d9b66a56
VK
650Revision 1.121 2008/02/25 21:30:25 victor
651- Situation update in EPP fully implemented
652- Version set to 0.2.20-rc2
653
40b7416c
VK
654Revision 1.120 2008/02/22 08:34:41 victor
655Various changes related mostly to situations
656
35dfcebd
VK
657Revision 1.119 2008/02/17 18:44:48 victor
658- Situation management complete on server side and almost complete in client library
659- User system rights changed to DWORD value from WORD value
660- Cosmetic fixes in DB drivers
661- Minor changes in libnetxms utility functions
662
431f302b
VK
663Revision 1.118 2008/01/29 00:13:27 victor
664Console is worling on Linux/UNICODE
665
6e17f325
VK
666Revision 1.117 2008/01/28 21:56:53 victor
667Added wrappers for UNIX versions of wprintf functions
668
04dbaf62
VK
669Revision 1.116 2008/01/28 20:23:44 victor
670Console compiles on UNIX with UNICODE
671
273da39a
VK
672Revision 1.115 2008/01/28 18:09:38 victor
673Preparation for UNICODE support on UNIX
674
8b86c5dc
VK
675Revision 1.114 2008/01/18 17:00:34 victor
676Correct checking for getopt_long()
677
99e50bb7
VK
678Revision 1.113 2007/12/05 14:17:23 victor
679
680SetDefaultCodePage now will check if codepage supported by iconv
681
664c7c49
VK
682Revision 1.112 2007/09/21 10:31:05 victor
683Fixed issue 185 (creting object with russion characters in name)
684
f7794b68
VK
685Revision 1.111 2007/09/20 13:03:59 victor
686- Most of GCC 4.2 warnings cleaned up
687- Other minor fixes
688
a765d97c
VK
689Revision 1.110 2007/07/25 12:03:05 victor
690More const char* fixes
691
3aa0061c
VK
692Revision 1.109 2007/07/25 11:27:36 victor
693Fixed some issues with char* -> const char* conversion
694
2391d4fd
VK
695Revision 1.108 2007/07/11 19:46:57 victor
696- New client source tree added
697- Minor changes in libraris for better support of new console
698
4560d8bd
VK
699Revision 1.107 2007/07/02 23:14:16 victor
700Various fixes
701
c3cfc039
VK
702Revision 1.106 2007/06/20 13:28:35 victor
703Fixed 'const char *' to 'char *' conversion error with some GCC versions
704
c90d3610
VK
705Revision 1.105 2007/05/15 09:36:32 victor
706Various improvements in web UI
707
fb7ce4b9
VK
708Revision 1.104 2007/05/11 15:44:46 victor
709- Added improved qsort()
710- Minor changes in web ui
711
b8a8d064
VK
712Revision 1.103 2007/05/07 11:35:41 victor
713- Unfinished changes in alarm generation code
714- nxhttpd redesigned
715
c577e360
VK
716Revision 1.102 2007/03/23 15:59:04 victor
717- All certificates now stored in database
718- CA certificates can be imported from management console
719- Fixed problems with some "invisible" system rights
720- Minor UI fixes
721
3d1058ed
VK
722Revision 1.101 2007/02/09 22:38:07 victor
723Crash dump generator added to console
724
ec4995e6
VK
725Revision 1.100 2007/01/24 00:52:28 alk
726Serial::ReadAll() added: read all data until timeout. returns data size, -1 it timeout w/o any data
727
f3a581d0
AK
728Revision 1.99 2007/01/11 18:56:14 victor
729- Added Process.COuntEx parameter
730- Added filtering by command line and window title to process.XXX parameters
731
ea1acec2
VK
732Revision 1.98 2006/12/17 10:31:37 victor
733ODBC driver made compatible with latest unixODBC
734
da27aabd
VK
735Revision 1.97 2006/12/11 21:19:27 victor
736Management pack creation almost working (only SNMP traps cannot be exported)
737
8bad8476
VK
738Revision 1.96 2006/11/03 08:58:56 victor
739- Added utillity class "Table"
740- Changed defines for iconv() usage on NetWare
741- Semi-complete "alarm details" view
742
ff214673
VK
743Revision 1.95 2006/10/17 21:20:25 victor
744Finished Implementation of agent traps and added trap sending API for subagents
745
15c8cf46
VK
746Revision 1.94 2006/10/05 05:24:05 victor
747Minor changes
748
5f461694
VK
749Revision 1.93 2006/10/01 20:43:37 victor
750UNICODE-related fixes
751
6cdccf82
VK
752Revision 1.92 2006/10/01 16:01:09 victor
753Yet another Linux UNICODE fix
754
556d9c45
VK
755Revision 1.91 2006/10/01 15:47:39 victor
756More UNICODE fixes
757
1738fb2b
VK
758Revision 1.90 2006/10/01 15:26:28 victor
759Some UNICODE-related fixes
760
3e39fcde
VK
761Revision 1.89 2006/09/30 22:41:08 victor
762Database driver API changed: now all SQL queries and results passed as UNICODE strings
763
7d4b78b3
VK
764Revision 1.88 2006/09/27 13:04:45 victor
765Preparation for process information parameters
766
ca6ad6bb
VK
767Revision 1.87 2006/09/27 04:15:25 victor
768AIX: implemented Net.InterfaceList
769
e25cadc9
VK
770Revision 1.86 2006/09/23 23:49:41 victor
771Console working with UNICODE!
772
dde96745
VK
773Revision 1.85 2006/09/10 06:59:36 victor
774Fixed problmes with Win32 build
775
6d8aee95
VK
776Revision 1.84 2006/09/07 22:02:06 alk
777UNIX version of Serial rewritten
778termio removed from configure (depricated in favour of termio_s_?)
779
70fed300
AK
780
781*/