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