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