Added functionality to send <<ERROR>> status for cashed dci values Fixes #1092
[public/netxms.git] / include / nms_util.h
CommitLineData
cc022855 1/*
7ac71e60 2** NetXMS - Network Management System
6f95ef89 3** Copyright (C) 2003-2015 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
4b47d7d7
VK
48/*** Byte swapping ***/
49#if WORDS_BIGENDIAN
50#define htonq(x) (x)
51#define ntohq(x) (x)
52#define htond(x) (x)
53#define ntohd(x) (x)
54#define SwapWideString(x)
55#else
56#ifdef HAVE_HTONLL
57#define htonq(x) htonll(x)
58#else
59#define htonq(x) __bswap_64(x)
60#endif
61#ifdef HAVE_NTOHLL
62#define ntohq(x) ntohll(x)
63#else
64#define ntohq(x) __bswap_64(x)
65#endif
66#define htond(x) __bswap_double(x)
67#define ntohd(x) __bswap_double(x)
68#define SwapWideString(x) __bswap_wstr(x)
69#endif
6d8aee95 70
4b47d7d7
VK
71#ifdef __cplusplus
72extern "C" {
73#endif
74
75#if defined(_WIN32) || !(HAVE_DECL___BSWAP_32)
76UINT32 LIBNETXMS_EXPORTABLE __bswap_32(UINT32 dwVal);
77#endif
78#if defined(_WIN32) || !(HAVE_DECL___BSWAP_64)
79UINT64 LIBNETXMS_EXPORTABLE __bswap_64(UINT64 qwVal);
80#endif
81double LIBNETXMS_EXPORTABLE __bswap_double(double dVal);
82void LIBNETXMS_EXPORTABLE __bswap_wstr(UCS2CHAR *pStr);
6d8aee95 83
4b47d7d7
VK
84#ifdef __cplusplus
85}
86#endif
87
88
89/*** Serial communications ***/
6d8aee95
VK
90#ifdef _WIN32
91
92#define FLOW_NONE 0
93#define FLOW_SOFTWARE 1
94#define FLOW_HARDWARE 2
95
96#else /* _WIN32 */
97
70fed300
AK
98#ifdef HAVE_TERMIOS_H
99# include <termios.h>
100#else
101# error termios.h not found
102#endif
103
6d8aee95
VK
104#endif /* _WIN32 */
105
e2e66145
VK
106/**
107 * Return codes for IcmpPing()
108 */
66c04cc7
VK
109#define ICMP_SUCCESS 0
110#define ICMP_UNREACHEABLE 1
111#define ICMP_TIMEOUT 2
112#define ICMP_RAW_SOCK_FAILED 3
5418d4bb 113#define ICMP_API_ERROR 4
66c04cc7 114
e2e66145
VK
115/**
116 * Token types for configuration loader
117 */
4826c8a5
VK
118#define CT_LONG 0
119#define CT_STRING 1
120#define CT_STRING_LIST 2
121#define CT_END_OF_LIST 3
122#define CT_BOOLEAN 4
123#define CT_WORD 5
fc935a60 124#define CT_IGNORE 6
dda7c270 125#define CT_MB_STRING 7
e95680e5 126#define CT_BOOLEAN64 8
4826c8a5 127
605fc935 128/**
e2e66145
VK
129 * Uninitialized value for override indicator
130 */
131#define NXCONFIG_UNINITIALIZED_VALUE (-1)
132
133/**
605fc935
VK
134 * Return codes for NxLoadConfig()
135 */
4826c8a5
VK
136#define NXCFG_ERR_OK 0
137#define NXCFG_ERR_NOFILE 1
138#define NXCFG_ERR_SYNTAX 2
139
605fc935
VK
140/**
141 * nxlog_open() flags
142 */
4e0e77e6
VK
143#define NXLOG_USE_SYSLOG ((UINT32)0x00000001)
144#define NXLOG_PRINT_TO_STDOUT ((UINT32)0x00000002)
145#define NXLOG_BACKGROUND_WRITER ((UINT32)0x00000004)
146#define NXLOG_IS_OPEN ((UINT32)0x80000000)
9f2902ac 147
605fc935
VK
148/**
149 * nxlog rotation policy
150 */
5945d50a
VK
151#define NXLOG_ROTATION_DISABLED 0
152#define NXLOG_ROTATION_DAILY 1
153#define NXLOG_ROTATION_BY_SIZE 2
154
605fc935
VK
155/**
156 * _tcsdup() replacement
157 */
8ff13508
VK
158#if defined(_WIN32) && defined(USE_WIN32_HEAP)
159#ifdef __cplusplus
160extern "C" {
161#endif
fd72502a 162char LIBNETXMS_EXPORTABLE *nx_strdup(const char *src);
8ff13508
VK
163WCHAR LIBNETXMS_EXPORTABLE *nx_wcsdup(const WCHAR *src);
164#ifdef __cplusplus
165}
166#endif
167#endif
168
605fc935 169/**
f4d2c9ba
VK
170 * Custom wcsdup
171 */
172#if !HAVE_WCSDUP && !defined(_WIN32)
fd72502a 173
f4d2c9ba
VK
174#ifdef __cplusplus
175extern "C" {
176#endif
177 WCHAR LIBNETXMS_EXPORTABLE *wcsdup(const WCHAR *src);
178#ifdef __cplusplus
179}
180#endif
fd72502a
VK
181
182#elif defined(_AIX)
183
184// Some AIX versions have broken wcsdup() so we use internal implementation
185#ifdef __cplusplus
186extern "C" {
187#endif
188 WCHAR LIBNETXMS_EXPORTABLE *nx_wcsdup(const WCHAR *src);
189#ifdef __cplusplus
190}
191#endif
192
193#define wcsdup nx_wcsdup
194
f4d2c9ba
VK
195#endif
196
c012b7b7
VK
197#ifdef __cplusplus
198
f4d2c9ba 199/**
c83f6449
VK
200 * Extended tcsdup: returns NULL if NULL pointer passed
201 */
202inline TCHAR *_tcsdup_ex(const TCHAR *s)
203{
204 return (s != NULL) ? _tcsdup(s) : NULL;
205}
206
c012b7b7
VK
207#endif
208
c83f6449 209/**
d65c16a8
VK
210 * String conversion helpers
211 */
212#ifdef __cplusplus
213extern "C" {
214#endif
215WCHAR LIBNETXMS_EXPORTABLE *WideStringFromMBString(const char *pszString);
fe8ea784 216WCHAR LIBNETXMS_EXPORTABLE *WideStringFromMBStringSysLocale(const char *pszString);
d65c16a8
VK
217WCHAR LIBNETXMS_EXPORTABLE *WideStringFromUTF8String(const char *pszString);
218char LIBNETXMS_EXPORTABLE *MBStringFromWideString(const WCHAR *pwszString);
fe8ea784 219char LIBNETXMS_EXPORTABLE *MBStringFromWideStringSysLocale(const WCHAR *pwszString);
d65c16a8
VK
220char LIBNETXMS_EXPORTABLE *UTF8StringFromWideString(const WCHAR *pwszString);
221#ifdef __cplusplus
222}
223#endif
224
f38a7636 225#ifdef UNICODE
7fcdcb0c 226#define UTF8StringFromTString(s) UTF8StringFromWideString(s)
f38a7636 227#else
7fcdcb0c 228#define UTF8StringFromTString(s) UTF8StringFromMBString(s)
f38a7636
AK
229#endif
230
d65c16a8 231/**
605fc935
VK
232 * Class for serial communications
233 */
b160350d
VK
234#ifdef __cplusplus
235
236#ifndef _WIN32
237enum
238{
239 NOPARITY,
240 ODDPARITY,
241 EVENPARITY,
242 ONESTOPBIT,
243 TWOSTOPBITS
244};
245
70fed300
AK
246enum
247{
248 FLOW_NONE,
249 FLOW_HARDWARE,
250 FLOW_SOFTWARE
251};
252
b160350d
VK
253#ifndef INVALID_HANDLE_VALUE
254#define INVALID_HANDLE_VALUE (-1)
255#endif
256#endif /* _WIN32 */
257
258class LIBNETXMS_EXPORTABLE Serial
259{
b160350d
VK
260private:
261 TCHAR *m_pszPort;
262 int m_nTimeout;
263 int m_nSpeed;
264 int m_nDataBits;
265 int m_nStopBits;
266 int m_nParity;
70fed300 267 int m_nFlowControl;
b160350d
VK
268
269#ifndef _WIN32
270 int m_hPort;
70fed300 271 struct termios m_originalSettings;
b160350d
VK
272#else
273 HANDLE m_hPort;
274#endif
b160350d 275
826fcc1f
VK
276public:
277 Serial();
278 ~Serial();
279
280 bool open(const TCHAR *pszPort);
281 void close();
282 void setTimeout(int nTimeout);
283 int read(char *pBuff, int nSize); /* waits up to timeout and do single read */
284 int readAll(char *pBuff, int nSize); /* read until timeout or out of space */
c3f71625 285 int readToMark(char *buff, int size, const char **marks, char **occurence);
826fcc1f
VK
286 bool write(const char *pBuff, int nSize);
287 void flush();
288 bool set(int nSpeed, int nDataBits, int nParity, int nStopBits, int nFlowControl = FLOW_NONE);
289 bool restart();
290};
ff214673 291
3fe40613
VK
292/**
293 * Dynamic string class
294 */
8bad8476
VK
295class LIBNETXMS_EXPORTABLE String
296{
297protected:
4e0e77e6
VK
298 TCHAR *m_buffer;
299 size_t m_length;
300 size_t m_allocated;
dcc7a2b0 301 size_t m_allocationStep;
8bad8476
VK
302
303public:
c577e360
VK
304 static const int npos;
305
8bad8476 306 String();
f3cdd1c5 307 String(const TCHAR *init);
643c9dcb 308 String(const String &src);
8bad8476
VK
309 ~String();
310
4e0e77e6
VK
311 TCHAR *getBuffer() { return m_buffer; }
312 void setBuffer(TCHAR *buffer);
8bad8476 313
dcc7a2b0
VK
314 size_t getAllocationStep() { return m_allocationStep; }
315 void setAllocationStep(size_t step) { m_allocationStep = step; }
4e0e77e6
VK
316
317 const String& operator =(const TCHAR *str);
49bf9d8d 318 const String& operator =(const String &src);
1d34c533
VK
319 const String& operator +=(const TCHAR *str);
320 const String& operator +=(const String &str);
5508ef9f 321 operator const TCHAR*() const { return CHECK_NULL_EX(m_buffer); }
8bad8476 322
08b214c6
VK
323 char *getUTF8String();
324
4e0e77e6
VK
325 void append(const TCHAR *str) { if (str != NULL) append(str, _tcslen(str)); }
326 void append(const TCHAR *str, size_t len);
f98a8402 327 void append(const TCHAR c) { append(&c, 1); }
5f648670
VK
328 void append(INT32 n);
329 void append(UINT32 n);
330 void append(INT64 n);
331 void append(UINT64 n);
4e0e77e6
VK
332
333 void appendPreallocated(TCHAR *str) { if (str != NULL) { append(str); free(str); } }
334
335 void appendMBString(const char *str, size_t len, int nCodePage);
336 void appendWideString(const WCHAR *str, size_t len);
c577e360 337
4e0e77e6
VK
338 void appendFormattedString(const TCHAR *format, ...);
339 void appendFormattedStringV(const TCHAR *format, va_list args);
ff175e91 340
4e0e77e6 341 void clear();
c577e360 342
4e0e77e6
VK
343 size_t length() const { return m_length; }
344 bool isEmpty() const { return m_length == 0; }
c577e360 345
7ac965a4 346 wchar_t charAt(size_t pos) const { return (pos < m_length) ? m_buffer[pos] : 0; }
807a4c40 347
4e0e77e6
VK
348 TCHAR *substring(int nStart, int nLen, TCHAR *pszBuffer = NULL);
349 int find(const TCHAR *str, int nStart = 0);
1e1450ef 350
6bcafa2d
VK
351 void escapeCharacter(int ch, int esc);
352 void replace(const TCHAR *pszSrc, const TCHAR *pszDst);
0bbab9d3
VK
353 void trim();
354 void shrink(int chars = 1);
c577e360
VK
355};
356
3fe40613 357/**
df26f039
VK
358 * Abstract iterator class (to be implemented by actual iterable class)
359 */
360class LIBNETXMS_EXPORTABLE AbstractIterator
361{
362public:
c5e1f0bb
VK
363 virtual ~AbstractIterator();
364
df26f039
VK
365 virtual bool hasNext() = 0;
366 virtual void *next() = 0;
e0f7dbec 367 virtual void remove() = 0;
df26f039
VK
368};
369
370/**
371 * Iterator class (public interface for iteration)
372 */
373template <class T> class Iterator
374{
375private:
376 AbstractIterator *m_worker;
377
378public:
379 Iterator(AbstractIterator *worker) { m_worker = worker; }
380 ~Iterator() { delete m_worker; }
381
382 bool hasNext() { return m_worker->hasNext(); }
383 T *next() { return (T *)m_worker->next(); }
e0f7dbec 384 void remove() { m_worker->remove(); }
df26f039
VK
385};
386
387/**
f9861ff9
VK
388 * Dynamic array class
389 */
390class LIBNETXMS_EXPORTABLE Array
391{
392private:
393 int m_size;
394 int m_allocated;
395 int m_grow;
396 size_t m_elementSize;
397 void **m_data;
398 bool m_objectOwner;
399
400 void internalRemove(int index, bool allowDestruction);
401 void destroyObject(void *object) { if (object != NULL) m_objectDestructor(object); }
402
403protected:
404 bool m_storePointers;
405 void (*m_objectDestructor)(void *);
406
407 Array(void *data, int initial, int grow, size_t elementSize);
dcc7a2b0 408 void *__getBuffer() const { return m_data; }
f9861ff9
VK
409
410public:
411 Array(int initial = 0, int grow = 16, bool owner = false);
412 virtual ~Array();
413
414 int add(void *element);
dcc7a2b0
VK
415 void *get(int index) const { return ((index >= 0) && (index < m_size)) ? (m_storePointers ? m_data[index] : (void *)((char *)m_data + index * m_elementSize)): NULL; }
416 int indexOf(void *element) const;
f9861ff9
VK
417 void set(int index, void *element);
418 void replace(int index, void *element);
419 void remove(int index) { internalRemove(index, true); }
420 void remove(void *element) { internalRemove(indexOf(element), true); }
421 void unlink(int index) { internalRemove(index, false); }
422 void unlink(void *element) { internalRemove(indexOf(element), false); }
423 void clear();
424 void sort(int (*cb)(const void *, const void *));
dcc7a2b0 425 void *find(const void *key, int (*cb)(const void *, const void *)) const;
f9861ff9 426
dcc7a2b0 427 int size() const { return m_size; }
f9861ff9
VK
428
429 void setOwner(bool owner) { m_objectOwner = owner; }
dcc7a2b0 430 bool isOwner() const { return m_objectOwner; }
f9861ff9
VK
431};
432
433/**
df26f039
VK
434 * Array iterator class
435 */
436class LIBNETXMS_EXPORTABLE ArrayIterator : public AbstractIterator
437{
438private:
e0f7dbec 439 Array *m_array;
df26f039
VK
440 int m_pos;
441
442public:
e0f7dbec 443 ArrayIterator(Array *array);
df26f039
VK
444
445 virtual bool hasNext();
446 virtual void *next();
e0f7dbec 447 virtual void remove();
df26f039
VK
448};
449
450/**
f9861ff9
VK
451 * Template class for dynamic array which holds objects
452 */
453template <class T> class ObjectArray : public Array
454{
455private:
456 static void destructor(void *object) { delete (T*)object; }
457
458public:
459 ObjectArray(int initial = 0, int grow = 16, bool owner = false) : Array(initial, grow, owner) { m_objectDestructor = destructor; }
460 virtual ~ObjectArray() { }
461
462 int add(T *object) { return Array::add((void *)object); }
dcc7a2b0
VK
463 T *get(int index) const { return (T*)Array::get(index); }
464 int indexOf(T *object) const { return Array::indexOf((void *)object); }
dfed892b 465 bool contains(T *object) const { return indexOf(object) >= 0; }
f9861ff9
VK
466 void set(int index, T *object) { Array::set(index, (void *)object); }
467 void replace(int index, T *object) { Array::replace(index, (void *)object); }
468 void remove(int index) { Array::remove(index); }
469 void remove(T *object) { Array::remove((void *)object); }
470 void unlink(int index) { Array::unlink(index); }
471 void unlink(T *object) { Array::unlink((void *)object); }
df26f039 472
e0f7dbec 473 Iterator<T> *iterator() { return new Iterator<T>(new ArrayIterator(this)); }
f9861ff9
VK
474};
475
476/**
477 * Template class for dynamic array which holds scalar values
478 */
479template <class T> class IntegerArray : public Array
480{
481private:
482 static void destructor(void *element) { }
483
484public:
485 IntegerArray(int initial = 0, int grow = 16) : Array(NULL, initial, grow, sizeof(T)) { m_objectDestructor = destructor; m_storePointers = (sizeof(T) == sizeof(void *)); }
486 virtual ~IntegerArray() { }
487
488 int add(T value) { return Array::add(m_storePointers ? CAST_TO_POINTER(value, void *) : &value); }
e5390fb5 489 T get(int index) const { if (m_storePointers) return CAST_FROM_POINTER(Array::get(index), T); T *p = (T*)Array::get(index); return (p != NULL) ? *p : 0; }
dcc7a2b0 490 int indexOf(T value) const { return Array::indexOf(m_storePointers ? CAST_TO_POINTER(value, void *) : &value); }
dfed892b 491 bool contains(T value) const { return indexOf(value) >= 0; }
f9861ff9
VK
492 void set(int index, T value) { Array::set(index, m_storePointers ? CAST_TO_POINTER(value, void *) : &value); }
493 void replace(int index, T value) { Array::replace(index, m_storePointers ? CAST_TO_POINTER(value, void *) : &value); }
494
dcc7a2b0 495 T *getBuffer() const { return (T*)__getBuffer(); }
f9861ff9
VK
496};
497
498/**
499 * Auxilliary class to hold dynamically allocated array of structures
500 */
501template <class T> class StructArray : public Array
502{
503private:
504 static void destructor(void *element) { }
505
506public:
507 StructArray(int initial = 0, int grow = 16) : Array(NULL, initial, grow, sizeof(T)) { m_objectDestructor = destructor; }
508 StructArray(T *data, int size) : Array(data, size, 16, sizeof(T)) { m_objectDestructor = destructor; }
509 virtual ~StructArray() { }
510
511 int add(T *element) { return Array::add((void *)element); }
dcc7a2b0
VK
512 T *get(int index) const { return (T*)Array::get(index); }
513 int indexOf(T *element) const { return Array::indexOf((void *)element); }
dfed892b 514 bool contains(T *element) const { return indexOf(element) >= 0; }
f9861ff9
VK
515 void set(int index, T *element) { Array::set(index, (void *)element); }
516 void replace(int index, T *element) { Array::replace(index, (void *)element); }
517 void remove(int index) { Array::remove(index); }
518 void remove(T *element) { Array::remove((void *)element); }
519 void unlink(int index) { Array::unlink(index); }
520 void unlink(T *element) { Array::unlink((void *)element); }
521
dcc7a2b0 522 T *getBuffer() const { return (T*)__getBuffer(); }
f9861ff9
VK
523};
524
525/**
526 * Entry of string map (internal)
400e55c4
VK
527 */
528struct StringMapEntry;
529
530/**
f9861ff9
VK
531 * Key/value pair
532 */
533struct KeyValuePair
534{
535 const TCHAR *key;
536 const void *value;
537};
538
539/**
3fe40613
VK
540 * String maps base class
541 */
542class LIBNETXMS_EXPORTABLE StringMapBase
c577e360
VK
543{
544protected:
400e55c4 545 StringMapEntry *m_data;
3fe40613 546 bool m_objectOwner;
55bdca5a 547 bool m_ignoreCase;
3fe40613 548 void (*m_objectDestructor)(void *);
c577e360 549
6e14de7c 550 StringMapEntry *find(const TCHAR *key) const;
3fe40613 551 void setObject(TCHAR *key, void *value, bool keyPreAlloc);
6e14de7c 552 void *getObject(const TCHAR *key) const;
3fe40613 553 void destroyObject(void *object) { if (object != NULL) m_objectDestructor(object); }
c577e360
VK
554
555public:
3fe40613
VK
556 StringMapBase(bool objectOwner);
557 virtual ~StringMapBase();
558
55bdca5a 559 void setOwner(bool owner) { m_objectOwner = owner; }
91a581c5 560 void setIgnoreCase(bool ignore);
55bdca5a 561
3fe40613
VK
562 void remove(const TCHAR *key);
563 void clear();
c07cf3be 564 void filterElements(bool (*filter)(const TCHAR *, const void *, void *), void *userData);
3fe40613 565
6e14de7c
VK
566 int size() const;
567 bool contains(const TCHAR *key) const { return find(key) != NULL; }
400e55c4 568
6e14de7c
VK
569 EnumerationCallbackResult forEach(EnumerationCallbackResult (*cb)(const TCHAR *, const void *, void *), void *userData) const;
570 const void *findElement(bool (*comparator)(const TCHAR *, const void *, void *), void *userData) const;
f9861ff9 571
6e14de7c
VK
572 StructArray<KeyValuePair> *toArray() const;
573 StringList *keys() const;
3fe40613
VK
574};
575
576/**
400e55c4
VK
577 * NXCP message class
578 */
b368969c 579class NXCPMessage;
400e55c4
VK
580
581/**
3fe40613
VK
582 * String map class
583 */
584class LIBNETXMS_EXPORTABLE StringMap : public StringMapBase
585{
586public:
587 StringMap() : StringMapBase(true) { }
fb986055 588 StringMap(const StringMap &src);
3fe40613 589 virtual ~StringMap();
c577e360 590
fb986055 591 StringMap& operator =(const StringMap &src);
40b7416c 592
3fe40613
VK
593 void set(const TCHAR *key, const TCHAR *value) { setObject((TCHAR *)key, _tcsdup(value), false); }
594 void setPreallocated(TCHAR *key, TCHAR *value) { setObject(key, value, true); }
967893bb 595 void set(const TCHAR *key, UINT32 value);
5ad2167d 596
a6312bd6
VK
597 void addAll(StringMap *src);
598
6e14de7c 599 const TCHAR *get(const TCHAR *key) const { return (const TCHAR *)getObject(key); }
7ec22f81
VK
600 INT32 getInt32(const TCHAR *key, INT32 defaultValue) const;
601 UINT32 getUInt32(const TCHAR *key, UINT32 defaultValue) const;
602 INT64 getInt64(const TCHAR *key, INT64 defaultValue) const;
603 UINT64 getUInt64(const TCHAR *key, UINT64 defaultValue) const;
604 double getDouble(const TCHAR *key, double defaultValue) const;
6e14de7c 605 bool getBoolean(const TCHAR *key, bool defaultValue) const;
5ad2167d 606
6e14de7c 607 void fillMessage(NXCPMessage *msg, UINT32 sizeFieldId, UINT32 baseFieldId) const;
ca0a165b 608 void loadMessage(const NXCPMessage *msg, UINT32 sizeFieldId, UINT32 baseFieldId);
8bad8476
VK
609};
610
3fe40613
VK
611/**
612 * String map template for holding objects as values
613 */
614template <class T> class StringObjectMap : public StringMapBase
615{
616private:
617 static void destructor(void *object) { delete (T*)object; }
6173bea8 618
3fe40613
VK
619public:
620 StringObjectMap(bool objectOwner) : StringMapBase(objectOwner) { m_objectDestructor = destructor; }
621
622 void set(const TCHAR *key, T *object) { setObject((TCHAR *)key, (void *)object, false); }
6e14de7c 623 T *get(const TCHAR *key) const { return (T*)getObject(key); }
3fe40613 624};
6173bea8 625
3fe40613
VK
626/**
627 * String list class
628 */
6173bea8
VK
629class LIBNETXMS_EXPORTABLE StringList
630{
631private:
632 int m_count;
633 int m_allocated;
634 TCHAR **m_values;
635
636public:
637 StringList();
01116597 638 StringList(const StringList *src);
22ee6d97 639 StringList(const TCHAR *src, const TCHAR *separator);
6173bea8
VK
640 ~StringList();
641
642 void add(const TCHAR *value);
643 void addPreallocated(TCHAR *value);
967893bb
VK
644 void add(INT32 value);
645 void add(UINT32 value);
6173bea8 646 void add(INT64 value);
967893bb 647 void add(UINT64 value);
6173bea8 648 void add(double value);
24dc5346 649 void replace(int index, const TCHAR *value);
b0353a33
VK
650 void addOrReplace(int index, const TCHAR *value);
651 void addOrReplacePreallocated(int index, TCHAR *value);
e2dc0372
VK
652#ifdef UNICODE
653 void addMBString(const char *value) { addPreallocated(WideStringFromMBString(value)); }
654#else
655 void addMBString(const char *value) { add(value); }
656#endif
6173bea8 657 void clear();
01116597
VK
658 int size() const { return m_count; }
659 const TCHAR *get(int index) const { return ((index >=0) && (index < m_count)) ? m_values[index] : NULL; }
660 int indexOf(const TCHAR *value) const;
661 int indexOfIgnoreCase(const TCHAR *value) const;
d51f2182 662 void remove(int index);
86c126f5 663 void addAll(const StringList *src);
93dbc1be 664 void merge(const StringList *src, bool matchCase);
7d25a5c5 665 TCHAR *join(const TCHAR *separator);
22ee6d97 666 void splitAndAdd(const TCHAR *src, const TCHAR *separator);
7d37e727 667 void sort(bool ascending = true, bool caseSensitive = false);
6fbaa926 668 void fillMessage(NXCPMessage *msg, UINT32 baseId, UINT32 countId);
6173bea8
VK
669};
670
3fe40613 671/**
a58501c0
VK
672 * Entry of string set
673 */
674struct StringSetEntry;
675
676/**
f3603b79
VK
677 * NXCP message
678 */
b368969c 679class NXCPMessage;
f3603b79
VK
680
681/**
8100b554
VK
682 * String set
683 */
684class StringSet;
685
686/**
687 * String set iterator
688 */
689class LIBNETXMS_EXPORTABLE StringSetIterator : public AbstractIterator
690{
691private:
692 StringSet *m_stringSet;
693 StringSetEntry *m_curr;
694 StringSetEntry *m_next;
695
696public:
697 StringSetIterator(StringSet *stringSet);
698
699 virtual bool hasNext();
700 virtual void *next();
701 virtual void remove();
702};
703
704/**
a58501c0
VK
705 * String set class
706 */
707class LIBNETXMS_EXPORTABLE StringSet
708{
8100b554
VK
709 friend class StringSetIterator;
710
a58501c0
VK
711private:
712 StringSetEntry *m_data;
713
714public:
715 StringSet();
716 ~StringSet();
717
718 void add(const TCHAR *str);
f3603b79 719 void addPreallocated(TCHAR *str);
a58501c0
VK
720 void remove(const TCHAR *str);
721 void clear();
722
8100b554
VK
723 int size() const;
724 bool contains(const TCHAR *str) const;
725 bool equals(const StringSet *s) const;
a58501c0 726
fa493140 727 void addAll(StringSet *src);
f3603b79 728 void addAll(TCHAR **strings, int count);
d45f9179 729 void splitAndAdd(const TCHAR *src, const TCHAR *separator);
d6c4cdc1 730 void addAllPreallocated(TCHAR **strings, int count);
f3603b79 731
8100b554
VK
732 void forEach(bool (*cb)(const TCHAR *, void *), void *userData) const;
733
734 void fillMessage(NXCPMessage *msg, UINT32 baseId, UINT32 countId) const;
735 void addAllFromMessage(const NXCPMessage *msg, UINT32 baseId, UINT32 countId, bool clearBeforeAdd, bool toUppercase);
c262bc08 736
d45f9179 737 String join(const TCHAR *separator);
8100b554
VK
738
739 Iterator<const TCHAR> *iterator() { return new Iterator<const TCHAR>(new StringSetIterator(this)); }
a58501c0
VK
740};
741
742/**
296ae03d
VK
743 * Opaque hash map entry structure
744 */
745struct HashMapEntry;
746
747/**
748 * Hash map base class (for fixed size non-pointer keys)
749 */
750class LIBNETXMS_EXPORTABLE HashMapBase
751{
df26f039
VK
752 friend class HashMapIterator;
753
296ae03d
VK
754private:
755 HashMapEntry *m_data;
756 bool m_objectOwner;
757 unsigned int m_keylen;
758
df26f039 759 HashMapEntry *find(const void *key) const;
296ae03d
VK
760 void destroyObject(void *object) { if (object != NULL) m_objectDestructor(object); }
761
762protected:
763 void (*m_objectDestructor)(void *);
764
765 HashMapBase(bool objectOwner, unsigned int keylen);
766
df26f039 767 void *_get(const void *key) const;
296ae03d
VK
768 void _set(const void *key, void *value);
769 void _remove(const void *key);
770
df26f039 771 bool _contains(const void *key) const { return find(key) != NULL; }
296ae03d
VK
772
773public:
774 virtual ~HashMapBase();
775
776 void setOwner(bool owner) { m_objectOwner = owner; }
777 void clear();
778
df26f039
VK
779 int size() const;
780
781 EnumerationCallbackResult forEach(EnumerationCallbackResult (*cb)(const void *, const void *, void *), void *userData) const;
782 const void *findElement(bool (*comparator)(const void *, const void *, void *), void *userData) const;
783};
296ae03d 784
df26f039
VK
785/**
786 * Hash map iterator
787 */
788class LIBNETXMS_EXPORTABLE HashMapIterator : public AbstractIterator
789{
790private:
791 HashMapBase *m_hashMap;
792 HashMapEntry *m_curr;
793 HashMapEntry *m_next;
794
795public:
796 HashMapIterator(HashMapBase *hashMap);
797
798 virtual bool hasNext();
799 virtual void *next();
e0f7dbec 800 virtual void remove();
296ae03d
VK
801};
802
803/**
804 * Hash map template for holding objects as values
805 */
806template <class K, class V> class HashMap : public HashMapBase
807{
808private:
809 static void destructor(void *object) { delete (V*)object; }
810
811public:
812 HashMap(bool objectOwner = false) : HashMapBase(objectOwner, sizeof(K)) { m_objectDestructor = destructor; }
813
814 V *get(const K& key) { return (V*)_get(&key); }
815 void set(const K& key, V *value) { _set(&key, (void *)value); }
816 void remove(const K& key) { _remove(&key); }
817 bool contains(const K& key) { return _contains(&key); }
df26f039
VK
818
819 Iterator<V> *iterator() { return new Iterator<V>(new HashMapIterator(this)); }
296ae03d
VK
820};
821
822/**
50963ced
VK
823 * Hash map template for holding reference counting objects as values
824 */
825template <class K, class V> class RefCountHashMap : public HashMapBase
826{
827private:
87c91211 828 static void destructor(void *object) { if (object != NULL) ((V*)object)->decRefCount(); }
50963ced
VK
829
830public:
831 RefCountHashMap(bool objectOwner = false) : HashMapBase(objectOwner, sizeof(K)) { m_objectDestructor = destructor; }
832
87c91211
VK
833 V *get(const K& key) { V *v = (V*)_get(&key); if (v != NULL) v->incRefCount(); return v; }
834 void set(const K& key, V *value) { if (value != NULL) value->incRefCount(); _set(&key, (void *)value); }
50963ced
VK
835 void remove(const K& key) { _remove(&key); }
836 bool contains(const K& key) { return _contains(&key); }
837
838 Iterator<V> *iterator() { return new Iterator<V>(new HashMapIterator(this)); }
839};
840
841/**
57f34c0a
VK
842 * Byte stream
843 */
844class LIBNETXMS_EXPORTABLE ByteStream
845{
846private:
847 BYTE *m_data;
848 size_t m_size;
849 size_t m_allocated;
850 size_t m_pos;
3cf3dedd 851 size_t m_allocationStep;
57f34c0a
VK
852
853public:
854 ByteStream(size_t initial = 8192);
855 ByteStream(const void *data, size_t size);
856 virtual ~ByteStream();
857
4b47d7d7
VK
858 static ByteStream *load(const TCHAR *file);
859
860 void seek(size_t pos) { if (pos <= m_size) m_pos = pos; }
57f34c0a
VK
861 size_t pos() { return m_pos; }
862 size_t size() { return m_size; }
863 bool eos() { return m_pos == m_size; }
864
3cf3dedd
VK
865 void setAllocationStep(size_t s) { m_allocationStep = s; }
866
867 const BYTE *buffer(size_t *size) { *size = m_size; return m_data; }
57f34c0a 868
4b47d7d7 869 void write(const void *data, size_t size);
57f34c0a
VK
870 void write(char c) { write(&c, 1); }
871 void write(BYTE b) { write(&b, 1); }
872 void write(INT16 n) { UINT16 x = htons((UINT16)n); write(&x, 2); }
873 void write(UINT16 n) { UINT16 x = htons(n); write(&x, 2); }
874 void write(INT32 n) { UINT32 x = htonl((UINT32)n); write(&x, 4); }
875 void write(UINT32 n) { UINT32 x = htonl(n); write(&x, 4); }
4b47d7d7
VK
876 void write(INT64 n) { UINT64 x = htonq((UINT64)n); write(&x, 8); }
877 void write(UINT64 n) { UINT64 x = htonq(n); write(&x, 8); }
878 void write(double n) { double x = htond(n); write(&x, 8); }
879 void writeString(const TCHAR *s);
57f34c0a 880
4b47d7d7 881 size_t read(void *buffer, size_t count);
57f34c0a
VK
882 char readChar() { return !eos() ? (char)m_data[m_pos++] : 0; }
883 BYTE readByte() { return !eos() ? m_data[m_pos++] : 0; }
884 INT16 readInt16();
885 UINT16 readUInt16();
886 INT32 readInt32();
887 UINT32 readUInt32();
4b47d7d7
VK
888 INT64 readInt64();
889 UINT64 readUInt64();
890 double readDouble();
891 TCHAR *readString();
892
893 bool save(int f);
57f34c0a
VK
894};
895
896/**
25fe6265
VK
897 * Auxilliary class for objects which counts references and
898 * destroys itself wheren reference count falls to 0
899 */
7f632dfe
VK
900class LIBNETXMS_EXPORTABLE RefCountObject
901{
902private:
7785322f 903 VolatileCounter m_refCount;
7f632dfe 904
7dd6369a
VK
905protected:
906 virtual ~RefCountObject();
907
7f632dfe 908public:
7785322f
VK
909 RefCountObject()
910 {
911 m_refCount = 1;
912 }
913
914 void incRefCount()
915 {
916 InterlockedIncrement(&m_refCount);
917 }
918
919 void decRefCount()
920 {
921 if (InterlockedDecrement(&m_refCount) == 0)
922 delete this;
923 }
7f632dfe
VK
924};
925
b368969c 926class NXCPMessage;
967893bb
VK
927
928/**
929 * Table column definition
930 */
931class LIBNETXMS_EXPORTABLE TableColumnDefinition
932{
933private:
934 TCHAR *m_name;
935 TCHAR *m_displayName;
936 INT32 m_dataType;
937 bool m_instanceColumn;
938
939public:
940 TableColumnDefinition(const TCHAR *name, const TCHAR *displayName, INT32 dataType, bool isInstance);
b368969c 941 TableColumnDefinition(NXCPMessage *msg, UINT32 baseId);
967893bb
VK
942 TableColumnDefinition(TableColumnDefinition *src);
943 ~TableColumnDefinition();
944
b368969c 945 void fillMessage(NXCPMessage *msg, UINT32 baseId);
967893bb
VK
946
947 const TCHAR *getName() { return m_name; }
948 const TCHAR *getDisplayName() { return m_displayName; }
949 INT32 getDataType() { return m_dataType; }
950 bool isInstanceColumn() { return m_instanceColumn; }
951
952 void setDataType(INT32 type) { m_dataType = type; }
953 void setInstanceColumn(bool isInstance) { m_instanceColumn = isInstance; }
a0ddfb29 954 void setDisplayName(const TCHAR *name) { safe_free(m_displayName); m_displayName = _tcsdup(CHECK_NULL_EX(name)); }
967893bb
VK
955};
956
957/**
d6bbfa4e
VK
958 * Table cell
959 */
960class TableCell
961{
962private:
963 TCHAR *m_value;
964 int m_status;
43666be9 965 UINT32 m_objectId;
d6bbfa4e
VK
966
967public:
43666be9
VK
968 TableCell() { m_value = NULL; m_status = -1; m_objectId = 0; }
969 TableCell(const TCHAR *value) { m_value = _tcsdup_ex(value); m_status = -1; m_objectId = 0; }
970 TableCell(const TCHAR *value, int status) { m_value = _tcsdup_ex(value); m_status = status; m_objectId = 0; }
971 TableCell(TableCell *src) { m_value = _tcsdup_ex(src->m_value); m_status = src->m_status; m_objectId = src->m_objectId; }
d6bbfa4e
VK
972 ~TableCell() { safe_free(m_value); }
973
43666be9
VK
974 void set(const TCHAR *value, int status, UINT32 objectId) { safe_free(m_value); m_value = _tcsdup_ex(value); m_status = status; m_objectId = objectId; }
975 void setPreallocated(TCHAR *value, int status, UINT32 objectId) { safe_free(m_value); m_value = value; m_status = status; m_objectId = objectId; }
d6bbfa4e
VK
976
977 const TCHAR *getValue() { return m_value; }
c83f6449 978 void setValue(const TCHAR *value) { safe_free(m_value); m_value = _tcsdup_ex(value); }
d6bbfa4e
VK
979 void setPreallocatedValue(TCHAR *value) { safe_free(m_value); m_value = value; }
980
981 int getStatus() { return m_status; }
982 void setStatus(int status) { m_status = status; }
43666be9
VK
983
984 int getObjectId() { return m_objectId; }
985 void setObjectId(UINT32 id) { m_objectId = id; }
d6bbfa4e
VK
986};
987
988/**
989 * Table row
990 */
991class TableRow
992{
993private:
994 ObjectArray<TableCell> *m_cells;
995 UINT32 m_objectId;
bac74bf7 996
d6bbfa4e
VK
997public:
998 TableRow(int columnCount);
999 TableRow(TableRow *src);
1000 ~TableRow() { delete m_cells; }
1001
1002 void addColumn() { m_cells->add(new TableCell); }
1003 void deleteColumn(int index) { m_cells->remove(index); }
bac74bf7 1004
43666be9
VK
1005 void set(int index, const TCHAR *value, int status, UINT32 objectId) { TableCell *c = m_cells->get(index); if (c != NULL) c->set(value, status, objectId); }
1006 void setPreallocated(int index, TCHAR *value, int status, UINT32 objectId) { TableCell *c = m_cells->get(index); if (c != NULL) c->setPreallocated(value, status, objectId); }
d6bbfa4e
VK
1007
1008 void setValue(int index, const TCHAR *value) { TableCell *c = m_cells->get(index); if (c != NULL) c->setValue(value); }
1009 void setPreallocatedValue(int index, TCHAR *value) { TableCell *c = m_cells->get(index); if (c != NULL) c->setPreallocatedValue(value); }
1010
1011 void setStatus(int index, int status) { TableCell *c = m_cells->get(index); if (c != NULL) c->setStatus(status); }
1012
1013 const TCHAR *getValue(int index) { TableCell *c = m_cells->get(index); return (c != NULL) ? c->getValue() : NULL; }
1014 int getStatus(int index) { TableCell *c = m_cells->get(index); return (c != NULL) ? c->getStatus() : -1; }
1015
1016 UINT32 getObjectId() { return m_objectId; }
1017 void setObjectId(UINT32 id) { m_objectId = id; }
43666be9
VK
1018
1019 UINT32 getCellObjectId(int index) { TableCell *c = m_cells->get(index); return (c != NULL) ? c->getObjectId() : 0; }
1020 void setCellObjectId(int index, UINT32 id) { TableCell *c = m_cells->get(index); if (c != NULL) c->setObjectId(id); }
d6bbfa4e
VK
1021};
1022
1023/**
967893bb
VK
1024 * Class for table data storage
1025 */
a0ddfb29 1026class LIBNETXMS_EXPORTABLE Table : public RefCountObject
967893bb
VK
1027{
1028private:
d6bbfa4e 1029 ObjectArray<TableRow> *m_data;
967893bb
VK
1030 ObjectArray<TableColumnDefinition> *m_columns;
1031 TCHAR *m_title;
1032 int m_source;
d6bbfa4e 1033 bool m_extendedFormat;
967893bb 1034
b368969c 1035 void createFromMessage(NXCPMessage *msg);
967893bb 1036 void destroy();
63ff3c9d 1037 bool parseXML(const char *xml);
967893bb
VK
1038
1039public:
1040 Table();
a0ddfb29 1041 Table(Table *src);
b368969c 1042 Table(NXCPMessage *msg);
b549a0f8 1043 virtual ~Table();
967893bb 1044
b368969c
VK
1045 int fillMessage(NXCPMessage &msg, int offset, int rowLimit);
1046 void updateFromMessage(NXCPMessage *msg);
967893bb 1047
a0ddfb29
VK
1048 void addAll(Table *src);
1049 void copyRow(Table *src, int row);
967893bb 1050
d6bbfa4e
VK
1051 int getNumRows() { return m_data->size(); }
1052 int getNumColumns() { return m_columns->size(); }
967893bb
VK
1053 const TCHAR *getTitle() { return CHECK_NULL_EX(m_title); }
1054 int getSource() { return m_source; }
1055
d6bbfa4e
VK
1056 bool isExtendedFormat() { return m_extendedFormat; }
1057 void setExtendedFormat(bool ext) { m_extendedFormat = ext; }
1058
967893bb
VK
1059 const TCHAR *getColumnName(int col) { return ((col >= 0) && (col < m_columns->size())) ? m_columns->get(col)->getName() : NULL; }
1060 INT32 getColumnDataType(int col) { return ((col >= 0) && (col < m_columns->size())) ? m_columns->get(col)->getDataType() : 0; }
1061 int getColumnIndex(const TCHAR *name);
1062 ObjectArray<TableColumnDefinition> *getColumnDefinitions() { return m_columns; }
1063
c83f6449 1064 void setTitle(const TCHAR *title) { safe_free(m_title); m_title = _tcsdup_ex(title); }
967893bb 1065 void setSource(int source) { m_source = source; }
8dba1eac 1066 int addColumn(const TCHAR *name, INT32 dataType = 0, const TCHAR *displayName = NULL, bool isInstance = false);
967893bb
VK
1067 void setColumnDataType(int col, INT32 dataType) { if ((col >= 0) && (col < m_columns->size())) m_columns->get(col)->setDataType(dataType); }
1068 int addRow();
1069
25076d53
VK
1070 void deleteRow(int row);
1071 void deleteColumn(int col);
1072
967893bb
VK
1073 void setAt(int nRow, int nCol, INT32 nData);
1074 void setAt(int nRow, int nCol, UINT32 dwData);
1075 void setAt(int nRow, int nCol, double dData);
1076 void setAt(int nRow, int nCol, INT64 nData);
1077 void setAt(int nRow, int nCol, UINT64 qwData);
1078 void setAt(int nRow, int nCol, const TCHAR *pszData);
1079 void setPreallocatedAt(int nRow, int nCol, TCHAR *pszData);
1080
d6bbfa4e
VK
1081 void set(int nCol, INT32 nData) { setAt(getNumRows() - 1, nCol, nData); }
1082 void set(int nCol, UINT32 dwData) { setAt(getNumRows() - 1, nCol, dwData); }
1083 void set(int nCol, double dData) { setAt(getNumRows() - 1, nCol, dData); }
1084 void set(int nCol, INT64 nData) { setAt(getNumRows() - 1, nCol, nData); }
1085 void set(int nCol, UINT64 qwData) { setAt(getNumRows() - 1, nCol, qwData); }
d65c16a8
VK
1086 void set(int nCol, const TCHAR *data) { setAt(getNumRows() - 1, nCol, data); }
1087#ifdef UNICODE
1088 void set(int nCol, const char *data) { setPreallocatedAt(getNumRows() - 1, nCol, WideStringFromMBString(data)); }
1089#else
1090 void set(int nCol, const WCHAR *data) { setPreallocatedAt(getNumRows() - 1, nCol, MBStringFromWideString(data)); }
1091#endif
1092 void setPreallocated(int nCol, TCHAR *data) { setPreallocatedAt(getNumRows() - 1, nCol, data); }
d6bbfa4e
VK
1093
1094 void setStatusAt(int row, int col, int status);
1095 void setStatus(int col, int status) { setStatusAt(getNumRows() - 1, col, status); }
967893bb
VK
1096
1097 const TCHAR *getAsString(int nRow, int nCol);
1098 INT32 getAsInt(int nRow, int nCol);
1099 UINT32 getAsUInt(int nRow, int nCol);
1100 INT64 getAsInt64(int nRow, int nCol);
1101 UINT64 getAsUInt64(int nRow, int nCol);
1102 double getAsDouble(int nRow, int nCol);
22aaa779 1103
d6bbfa4e
VK
1104 int getStatus(int nRow, int nCol);
1105
22aaa779 1106 void buildInstanceString(int row, TCHAR *buffer, size_t bufLen);
a0ddfb29 1107 int findRowByInstance(const TCHAR *instance);
d6bbfa4e
VK
1108
1109 UINT32 getObjectId(int row) { TableRow *r = m_data->get(row); return (r != NULL) ? r->getObjectId() : 0; }
1110 void setObjectId(int row, UINT32 id) { TableRow *r = m_data->get(row); if (r != NULL) r->setObjectId(id); }
a3d3f9d5 1111
43666be9
VK
1112 void setCellObjectIdAt(int row, int col, UINT32 objectId);
1113 void setCellObjectId(int col, UINT32 objectId) { setCellObjectIdAt(getNumRows() - 1, col, objectId); }
1114 UINT32 getCellObjectId(int row, int col) { TableRow *r = m_data->get(row); return (r != NULL) ? r->getCellObjectId(col) : 0; }
1115
63ff3c9d
VK
1116 static Table *createFromXML(const char *xml);
1117 TCHAR *createXML();
967893bb
VK
1118};
1119
25fe6265 1120/**
c11eee9b
VK
1121 * sockaddr buffer
1122 */
1123union SockAddrBuffer
1124{
1125 struct sockaddr_in sa4;
1126#ifdef WITH_IPV6
1127 struct sockaddr_in6 sa6;
1128#endif
1129};
1130
1131/**
1132 * sockaddr length calculation
1133 */
1134#ifdef WITH_IPV6
1135#define SA_LEN(sa) (((sa)->sa_family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6))
1136#else
1137#define SA_LEN(sa) sizeof(struct sockaddr_in)
1138#endif
1139
1140/**
5f6e8d09
VK
1141 * Get port number from SockAddrBuffer
1142 */
1143#ifdef WITH_IPV6
1144#define SA_PORT(sa) ((((struct sockaddr *)sa)->sa_family == AF_INET) ? ((struct sockaddr_in *)sa)->sin_port : ((struct sockaddr_in6 *)sa)->sin6_port)
1145#else
1146#define SA_PORT(sa) (((struct sockaddr_in *)sa)->sin_port)
1147#endif
1148
1149/**
30592fa6
VK
1150 * Compare addresses in sockaddr
1151 */
1152inline bool SocketAddressEquals(struct sockaddr *a1, struct sockaddr *a2)
1153{
1154 if (a1->sa_family != a2->sa_family)
1155 return false;
1156 if (a1->sa_family == AF_INET)
1157 return ((struct sockaddr_in *)a1)->sin_addr.s_addr == ((struct sockaddr_in *)a2)->sin_addr.s_addr;
1158#ifdef WITH_IPV6
1159 if (a1->sa_family == AF_INET6)
1160 return !memcmp(((struct sockaddr_in6 *)a1)->sin6_addr.s6_addr, ((struct sockaddr_in6 *)a2)->sin6_addr.s6_addr, 16);
1161#endif
1162 return false;
1163}
1164
1165/**
9319c166
VK
1166 * IP address
1167 */
1168class LIBNETXMS_EXPORTABLE InetAddress
1169{
9319c166 1170private:
8c75ad41
VK
1171 short m_maskBits;
1172 short m_family;
1173 union
1174 {
1175 UINT32 v4;
1176 BYTE v6[16];
1177 } m_addr;
9319c166
VK
1178
1179public:
8c75ad41
VK
1180 InetAddress();
1181 InetAddress(UINT32 addr);
c75e9ee4 1182 InetAddress(UINT32 addr, UINT32 mask);
4203dcb5 1183 InetAddress(const BYTE *addr, int maskBits = 128);
9319c166 1184
8c75ad41
VK
1185 bool isAnyLocal() const;
1186 bool isLoopback() const;
1187 bool isMulticast() const;
1188 bool isBroadcast() const;
4203dcb5 1189 bool isLinkLocal() const;
8c75ad41 1190 bool isValid() const { return m_family != AF_UNSPEC; }
4203dcb5 1191 bool isValidUnicast() const { return isValid() && !isAnyLocal() && !isLoopback() && !isMulticast() && !isBroadcast() && !isLinkLocal(); }
9319c166 1192
8c75ad41 1193 int getFamily() const { return m_family; }
c7853753
VK
1194 UINT32 getAddressV4() const { return (m_family == AF_INET) ? m_addr.v4 : 0; }
1195 const BYTE *getAddressV6() const { return (m_family == AF_INET6) ? m_addr.v6 : (const BYTE *)"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; }
9319c166 1196
8c75ad41 1197 bool contain(const InetAddress &a) const;
43709a0c 1198 bool sameSubnet(const InetAddress &a) const;
8c75ad41
VK
1199 bool equals(const InetAddress &a) const;
1200 int compareTo(const InetAddress &a) const;
9319c166 1201
8c75ad41
VK
1202 void setMaskBits(int m) { m_maskBits = m; }
1203 int getMaskBits() const { return m_maskBits; }
c75e9ee4 1204 int getHostBits() const { return (m_family == AF_INET) ? (32 - m_maskBits) : (128 - m_maskBits); }
9319c166 1205
463b1d34 1206 InetAddress getSubnetAddress() const;
ba889094 1207 InetAddress getSubnetBroadcast() const;
463b1d34 1208 bool isSubnetBroadcast(int maskBits) const;
ffabd7f8 1209
8c75ad41
VK
1210 String toString() const;
1211 TCHAR *toString(TCHAR *buffer) const;
af4a09df
VK
1212#ifdef UNICODE
1213 char *toStringA(char *buffer) const;
1214#else
1215 char *toStringA(char *buffer) const { return toString(buffer); }
1216#endif
9319c166 1217
43709a0c 1218 BYTE *buildHashKey(BYTE *key) const;
f3b94fc5 1219
43709a0c
VK
1220 TCHAR *getHostByAddr(TCHAR *buffer, size_t buflen) const;
1221
1222 struct sockaddr *fillSockAddr(SockAddrBuffer *buffer, UINT16 port = 0) const;
c11eee9b 1223
c7853753
VK
1224 static InetAddress resolveHostName(const WCHAR *hostname, int af = AF_INET);
1225 static InetAddress resolveHostName(const char *hostname, int af = AF_INET);
f3b94fc5
VK
1226 static InetAddress parse(const WCHAR *str);
1227 static InetAddress parse(const char *str);
8c75ad41 1228 static InetAddress createFromSockaddr(struct sockaddr *s);
dcc7a2b0
VK
1229
1230 static const InetAddress INVALID;
48313f37 1231 static const InetAddress LOOPBACK;
dcc7a2b0
VK
1232};
1233
1234/**
1235 * IP address list
1236 */
1237class LIBNETXMS_EXPORTABLE InetAddressList
1238{
1239private:
1240 ObjectArray<InetAddress> *m_list;
1241
1242 int indexOf(const InetAddress& addr) const;
1243
1244public:
1245 InetAddressList();
1246 ~InetAddressList();
1247
1248 void add(const InetAddress& addr);
c30c0c0f
VK
1249 void add(const InetAddressList& addrList);
1250 void replace(const InetAddress& addr);
dcc7a2b0 1251 void remove(const InetAddress& addr);
c30c0c0f 1252 void clear() { m_list->clear(); }
4203dcb5 1253 const InetAddress& get(int index) const { const InetAddress *a = m_list->get(index); return (a != NULL) ? *a : InetAddress::INVALID; }
dcc7a2b0
VK
1254
1255 int size() const { return m_list->size(); }
1256 bool hasAddress(const InetAddress& addr) const { return indexOf(addr) != -1; }
4203dcb5 1257 const InetAddress& findAddress(const InetAddress& addr) const { int idx = indexOf(addr); return (idx != -1) ? *m_list->get(idx) : InetAddress::INVALID; }
c34b611c 1258 const InetAddress& findSameSubnetAddress(const InetAddress& addr) const;
dcc7a2b0 1259 const InetAddress& getFirstUnicastAddress() const;
c34b611c
VK
1260 const InetAddress& getFirstUnicastAddressV4() const;
1261 bool hasValidUnicastAddress() const { return getFirstUnicastAddress().isValid(); }
c30c0c0f 1262 bool isLoopbackOnly() const;
dcc7a2b0
VK
1263
1264 const ObjectArray<InetAddress> *getList() const { return m_list; }
40c8f341
VK
1265
1266 void fillMessage(NXCPMessage *msg, UINT32 sizeFieldId, UINT32 baseFieldId) const;
9319c166
VK
1267};
1268
1269/**
25fe6265
VK
1270 * Network connection
1271 */
58ee2f43
VK
1272class LIBNETXMS_EXPORTABLE SocketConnection
1273{
1274protected:
1275 SOCKET m_socket;
1276 char m_data[4096];
1277 int m_dataPos;
1278
1279public:
1280 SocketConnection();
1281 virtual ~SocketConnection();
1282
967893bb
VK
1283 bool connectTCP(const TCHAR *hostName, WORD port, UINT32 timeout);
1284 bool connectTCP(UINT32 ip, WORD port, UINT32 timeout);
58ee2f43
VK
1285 void disconnect();
1286
967893bb
VK
1287 bool canRead(UINT32 timeout);
1288 virtual int read(char *pBuff, int nSize, UINT32 timeout = INFINITE);
58ee2f43 1289 bool waitForText(const char *text, int timeout);
cc022855 1290
58ee2f43 1291 int write(const char *pBuff, int nSize);
1671f85d
VK
1292 bool writeLine(const char *line);
1293
967893bb 1294 static SocketConnection *createTCPConnection(const TCHAR *hostName, WORD port, UINT32 timeout);
58ee2f43
VK
1295};
1296
030a0779
VK
1297/**
1298 * Telnet connection - handles all telnet negotiation
1299 */
def5b792
AK
1300class LIBNETXMS_EXPORTABLE TelnetConnection : public SocketConnection
1301{
030a0779 1302protected:
967893bb
VK
1303 bool connectTCP(const TCHAR *hostName, WORD port, UINT32 timeout);
1304 bool connectTCP(UINT32 ip, WORD port, UINT32 timeout);
030a0779 1305
def5b792 1306public:
967893bb 1307 static TelnetConnection *createConnection(const TCHAR *hostName, WORD port, UINT32 timeout);
d4e9d325 1308
967893bb
VK
1309 bool connect(const TCHAR *hostName, WORD port, UINT32 timeout);
1310 bool connect(UINT32 ip, WORD port, UINT32 timeout);
1311 virtual int read(char *pBuff, int nSize, UINT32 timeout = INFINITE);
1312 int readLine(char *buffer, int size, UINT32 timeout = INFINITE);
def5b792
AK
1313};
1314
56fa1092
VK
1315/**
1316 * Postal address representation
1317 */
1318class LIBNETXMS_EXPORTABLE PostalAddress
1319{
1320private:
1321 TCHAR *m_country;
1322 TCHAR *m_city;
1323 TCHAR *m_streetAddress;
1324 TCHAR *m_postcode;
1325
1326public:
1327 PostalAddress();
1328 PostalAddress(const TCHAR *country, const TCHAR *city, const TCHAR *streetAddress, const TCHAR *postcode);
1329 ~PostalAddress();
1330
63e99e56
VK
1331 const TCHAR *getCountry() const { return CHECK_NULL_EX(m_country); }
1332 const TCHAR *getCity() const { return CHECK_NULL_EX(m_city); }
1333 const TCHAR *getStreetAddress() const { return CHECK_NULL_EX(m_streetAddress); }
1334 const TCHAR *getPostCode() const { return CHECK_NULL_EX(m_postcode); }
56fa1092
VK
1335
1336 void setCountry(const TCHAR *country) { safe_free(m_country); m_country = _tcsdup_ex(country); }
1337 void setCity(const TCHAR *city) { safe_free(m_city); m_city = _tcsdup_ex(city); }
1338 void setStreetAddress(const TCHAR *streetAddress) { safe_free(m_streetAddress); m_streetAddress = _tcsdup_ex(streetAddress); }
1339 void setPostCode(const TCHAR *postcode) { safe_free(m_postcode); m_postcode = _tcsdup_ex(postcode); }
1340};
1341
b160350d
VK
1342#endif /* __cplusplus */
1343
030a0779
VK
1344/**
1345 * Configuration item template for configuration loader
1346 */
4826c8a5
VK
1347typedef struct
1348{
e2e66145
VK
1349 TCHAR token[64];
1350 BYTE type;
1351 BYTE separator; // Separator character for lists
1352 WORD listElements; // Number of list elements, should be set to 0 before calling NxLoadConfig()
e95680e5 1353 UINT64 bufferSize; // Buffer size for strings or flag to be set for CT_BOOLEAN
e2e66145
VK
1354 UINT32 bufferPos; // Should be set to 0
1355 void *buffer;
1356 void *overrideIndicator;
4826c8a5 1357} NX_CFG_TEMPLATE;
dcb44c9a 1358
030a0779
VK
1359/**
1360 * Code translation structure
1361 */
1b56f3c5 1362typedef struct __CODE_TO_TEXT
bc858635
VK
1363{
1364 int code;
1365 const TCHAR *text;
1366} CODE_TO_TEXT;
1367
e2e66145
VK
1368/**
1369 * getopt() prototype if needed
1370 */
df9812a9 1371#if USE_BUNDLED_GETOPT
99e50bb7 1372#include <netxms_getopt.h>
3046f9a4
VK
1373#endif
1374
f2fdf1b5 1375//
3d1cb7d6
VK
1376// Structures for opendir() / readdir() / closedir()
1377//
1378
1379#ifdef _WIN32
1380
7f9e0c00 1381typedef struct dirent
3d1cb7d6
VK
1382{
1383 long d_ino; /* inode number (not used by MS-DOS) */
1384 int d_namlen; /* Name length */
1385 char d_name[257]; /* file name */
1386} _DIRECT;
1387
1388typedef struct _dir_struc
1389{
1390 char *start; /* Starting position */
1391 char *curr; /* Current position */
1392 long size; /* Size of string table */
1393 long nfiles; /* number if filenames in table */
7f9e0c00 1394 struct dirent dirstr; /* Directory structure to return */
3d1cb7d6
VK
1395} DIR;
1396
5ea2db30
VK
1397#ifdef UNICODE
1398
1399typedef struct dirent_w
1400{
1401 long d_ino; /* inode number (not used by MS-DOS) */
1402 int d_namlen; /* Name length */
1403 WCHAR d_name[257]; /* file name */
1404} _DIRECTW;
1405
1406typedef struct _dir_struc_w
1407{
1408 WCHAR *start; /* Starting position */
1409 WCHAR *curr; /* Current position */
1410 long size; /* Size of string table */
1411 long nfiles; /* number if filenames in table */
1412 struct dirent_w dirstr; /* Directory structure to return */
1413} DIRW;
1414
1415#define _TDIR DIRW
1416#define _TDIRECT _DIRECTW
1417#define _tdirent dirent_w
1418
1419#else
1420
1421#define _TDIR DIR
1422#define _TDIRECT _DIRECT
1423#define _tdirent dirent
1424
37d62364
AK
1425#endif
1426
76b1d3d8
VK
1427#else /* not _WIN32 */
1428
1429typedef struct dirent_w
1430{
1431 long d_ino; /* inode number */
1432 WCHAR d_name[257]; /* file name */
1433} _DIRECTW;
1434
1435typedef struct _dir_struc_w
1436{
1437 DIR *dir; /* Original non-unicode structure */
1438 struct dirent_w dirstr; /* Directory structure to return */
1439} DIRW;
1440
3d1cb7d6
VK
1441#endif /* _WIN32 */
1442
1443
1444//
e9246d26
VK
1445// Functions
1446//
1447
b50f1100 1448#ifdef __cplusplus
18c575eb 1449
2e590d1a
VK
1450inline TCHAR *nx_strncpy(TCHAR *pszDest, const TCHAR *pszSrc, size_t nLen)
1451{
912b994d 1452#if defined(_WIN32) && (_MSC_VER >= 1400)
2e590d1a 1453 _tcsncpy_s(pszDest, nLen, pszSrc, _TRUNCATE);
912b994d 1454#else
2e590d1a
VK
1455 _tcsncpy(pszDest, pszSrc, nLen - 1);
1456 pszDest[nLen - 1] = 0;
912b994d 1457#endif
2e590d1a
VK
1458 return pszDest;
1459}
f3387429
VK
1460
1461#ifdef UNICODE
2e590d1a
VK
1462inline char *nx_strncpy_mb(char *pszDest, const char *pszSrc, size_t nLen)
1463{
f3387429 1464#if defined(_WIN32) && (_MSC_VER >= 1400)
2e590d1a 1465 strncpy_s(pszDest, nLen, pszSrc, _TRUNCATE);
f3387429 1466#else
2e590d1a
VK
1467 strncpy(pszDest, pszSrc, nLen - 1);
1468 pszDest[nLen - 1] = 0;
c81979bc 1469#endif
2e590d1a
VK
1470 return pszDest;
1471}
c81979bc 1472#else
f3387429 1473#define nx_strncpy_mb nx_strncpy
7b8b337e
VK
1474#endif
1475
967893bb 1476int LIBNETXMS_EXPORTABLE ConnectEx(SOCKET s, struct sockaddr *addr, int len, UINT32 timeout);
5e60b759
VK
1477int LIBNETXMS_EXPORTABLE SendEx(SOCKET hSocket, const void *data, size_t len, int flags, MUTEX mutex);
1478int LIBNETXMS_EXPORTABLE RecvEx(SOCKET hSocket, void *data, size_t len, int flags, UINT32 timeout);
18c575eb
VK
1479bool LIBNETXMS_EXPORTABLE RecvAll(SOCKET s, void *buffer, size_t size, UINT32 timeout);
1480
b42c9187
VK
1481SOCKET LIBNETXMS_EXPORTABLE ConnectToHost(const InetAddress& addr, UINT16 port, UINT32 timeout);
1482
b0608204 1483#endif /* __cplusplus */
c81979bc
VK
1484
1485#ifdef __cplusplus
e9246d26
VK
1486extern "C"
1487{
b50f1100 1488#endif
735bac5c 1489
fe8ea784
VK
1490void LIBNETXMS_EXPORTABLE InitNetXMSProcess();
1491
076a55c4 1492#if !defined(_WIN32) && !defined(_NETWARE)
8b86c5dc 1493#if defined(UNICODE_UCS2) || defined(UNICODE_UCS4)
735bac5c
VK
1494void LIBNETXMS_EXPORTABLE __wcsupr(WCHAR *in);
1495#define wcsupr __wcsupr
cc022855 1496#endif
735bac5c
VK
1497void LIBNETXMS_EXPORTABLE __strupr(char *in);
1498#define strupr __strupr
7e679c4b 1499#endif
cc022855 1500
735bac5c 1501void LIBNETXMS_EXPORTABLE QSortEx(void *base, size_t nmemb, size_t size, void *arg,
b8a8d064
VK
1502 int (*compare)(const void *, const void *, void *));
1503
735bac5c 1504INT64 LIBNETXMS_EXPORTABLE GetCurrentTimeMs();
d35ed0aa 1505
735bac5c
VK
1506UINT64 LIBNETXMS_EXPORTABLE FileSizeW(const WCHAR *pszFileName);
1507UINT64 LIBNETXMS_EXPORTABLE FileSizeA(const char *pszFileName);
d35ed0aa
VK
1508#ifdef UNICODE
1509#define FileSize FileSizeW
1510#else
1511#define FileSize FileSizeA
1512#endif
670c7f3d 1513
735bac5c
VK
1514int LIBNETXMS_EXPORTABLE BitsInMask(UINT32 dwMask);
1515TCHAR LIBNETXMS_EXPORTABLE *IpToStr(UINT32 dwAddr, TCHAR *szBuffer);
e0f99bf0 1516#ifdef UNICODE
735bac5c 1517char LIBNETXMS_EXPORTABLE *IpToStrA(UINT32 dwAddr, char *szBuffer);
17b35ccc
VK
1518#else
1519#define IpToStrA IpToStr
e0f99bf0 1520#endif
8c75ad41 1521TCHAR LIBNETXMS_EXPORTABLE *Ip6ToStr(const BYTE *addr, TCHAR *buffer);
af4a09df
VK
1522#ifdef UNICODE
1523char LIBNETXMS_EXPORTABLE *Ip6ToStrA(const BYTE *addr, char *buffer);
1524#else
1525#define Ip6ToStrA Ip6ToStr
1526#endif
735bac5c 1527TCHAR LIBNETXMS_EXPORTABLE *SockaddrToStr(struct sockaddr *addr, TCHAR *buffer);
60557d06 1528
735bac5c
VK
1529UINT32 LIBNETXMS_EXPORTABLE ResolveHostNameA(const char *name);
1530UINT32 LIBNETXMS_EXPORTABLE ResolveHostNameW(const WCHAR *name);
08b214c6 1531#ifdef UNICODE
cfe20cce 1532#define ResolveHostName ResolveHostNameW
08b214c6 1533#else
cfe20cce 1534#define ResolveHostName ResolveHostNameA
08b214c6 1535#endif
a1dc75b0 1536
735bac5c
VK
1537void LIBNETXMS_EXPORTABLE *nx_memdup(const void *data, size_t size);
1538void LIBNETXMS_EXPORTABLE nx_memswap(void *block1, void *block2, size_t size);
31521248 1539
735bac5c
VK
1540WCHAR LIBNETXMS_EXPORTABLE *BinToStrW(const BYTE *data, size_t size, WCHAR *pStr);
1541char LIBNETXMS_EXPORTABLE *BinToStrA(const BYTE *data, size_t size, char *pStr);
d7970ee7
VK
1542#ifdef UNICODE
1543#define BinToStr BinToStrW
1544#else
1545#define BinToStr BinToStrA
1546#endif
1547
735bac5c
VK
1548size_t LIBNETXMS_EXPORTABLE StrToBinW(const WCHAR *pStr, BYTE *data, size_t size);
1549size_t LIBNETXMS_EXPORTABLE StrToBinA(const char *pStr, BYTE *data, size_t size);
52db3ed1
VK
1550#ifdef UNICODE
1551#define StrToBin StrToBinW
1552#else
1553#define StrToBin StrToBinA
1554#endif
cc022855 1555
735bac5c 1556TCHAR LIBNETXMS_EXPORTABLE *MACToStr(const BYTE *data, TCHAR *pStr);
b50f1100 1557
735bac5c
VK
1558void LIBNETXMS_EXPORTABLE StrStripA(char *pszStr);
1559void LIBNETXMS_EXPORTABLE StrStripW(WCHAR *pszStr);
b07c50cc
VK
1560#ifdef UNICODE
1561#define StrStrip StrStripW
1562#else
1563#define StrStrip StrStripA
1564#endif
1565
735bac5c
VK
1566const char LIBNETXMS_EXPORTABLE *ExtractWordA(const char *line, char *buffer);
1567const WCHAR LIBNETXMS_EXPORTABLE *ExtractWordW(const WCHAR *line, WCHAR *buffer);
ada97259
VK
1568#ifdef UNICODE
1569#define ExtractWord ExtractWordW
1570#else
1571#define ExtractWord ExtractWordA
1572#endif
1573
735bac5c
VK
1574int LIBNETXMS_EXPORTABLE NumCharsA(const char *pszStr, char ch);
1575int LIBNETXMS_EXPORTABLE NumCharsW(const WCHAR *pszStr, WCHAR ch);
3583a400
VK
1576#ifdef UNICODE
1577#define NumChars NumCharsW
1578#else
1579#define NumChars NumCharsA
1580#endif
ada97259 1581
735bac5c
VK
1582void LIBNETXMS_EXPORTABLE RemoveTrailingCRLFA(char *str);
1583void LIBNETXMS_EXPORTABLE RemoveTrailingCRLFW(WCHAR *str);
35f836fe
VK
1584#ifdef UNICODE
1585#define RemoveTrailingCRLF RemoveTrailingCRLFW
1586#else
1587#define RemoveTrailingCRLF RemoveTrailingCRLFA
1588#endif
1589
4893b4aa
VK
1590BOOL LIBNETXMS_EXPORTABLE RegexpMatchA(const char *str, const char *expr, bool matchCase);
1591BOOL LIBNETXMS_EXPORTABLE RegexpMatchW(const WCHAR *str, const WCHAR *expr, bool matchCase);
cafe592d
VK
1592#ifdef UNICODE
1593#define RegexpMatch RegexpMatchW
1594#else
1595#define RegexpMatch RegexpMatchA
1596#endif
1597
735bac5c 1598const TCHAR LIBNETXMS_EXPORTABLE *ExpandFileName(const TCHAR *name, TCHAR *buffer, size_t bufSize, bool allowShellCommand);
d77c193c 1599BOOL LIBNETXMS_EXPORTABLE CreateFolder(const TCHAR *directory);
818f8c94 1600TCHAR LIBNETXMS_EXPORTABLE *Trim(TCHAR *str);
735bac5c
VK
1601bool LIBNETXMS_EXPORTABLE MatchString(const TCHAR *pattern, const TCHAR *str, bool matchCase);
1602TCHAR LIBNETXMS_EXPORTABLE **SplitString(const TCHAR *source, TCHAR sep, int *numStrings);
0a145c10 1603int LIBNETXMS_EXPORTABLE GetLastMonthDay(struct tm *currTime);
1604#ifdef __cplusplus
1605bool LIBNETXMS_EXPORTABLE MatchScheduleElement(TCHAR *pszPattern, int nValue, int maxValue, struct tm *localTime, time_t currTime = 0);
1606#else
1607bool LIBNETXMS_EXPORTABLE MatchScheduleElement(TCHAR *pszPattern, int nValue, int maxValue, struct tm *localTime, time_t currTime);
1608#endif
1609
ada97259 1610
f7794b68 1611#ifdef __cplusplus
735bac5c 1612BOOL LIBNETXMS_EXPORTABLE IsValidObjectName(const TCHAR *pszName, BOOL bExtendedChars = FALSE);
f7794b68 1613#endif
735bac5c
VK
1614BOOL LIBNETXMS_EXPORTABLE IsValidScriptName(const TCHAR *pszName);
1615/* deprecated */ void LIBNETXMS_EXPORTABLE TranslateStr(TCHAR *pszString, const TCHAR *pszSubStr, const TCHAR *pszReplace);
1616const TCHAR LIBNETXMS_EXPORTABLE *GetCleanFileName(const TCHAR *pszFileName);
1617void LIBNETXMS_EXPORTABLE GetOSVersionString(TCHAR *pszBuffer, int nBufSize);
1618BYTE LIBNETXMS_EXPORTABLE *LoadFile(const TCHAR *pszFileName, UINT32 *pdwFileSize);
08b214c6 1619#ifdef UNICODE
735bac5c 1620BYTE LIBNETXMS_EXPORTABLE *LoadFileA(const char *pszFileName, UINT32 *pdwFileSize);
08b214c6
VK
1621#else
1622#define LoadFileA LoadFile
1623#endif
1624
735bac5c
VK
1625UINT32 LIBNETXMS_EXPORTABLE CalculateCRC32(const unsigned char *data, UINT32 size, UINT32 dwCRC);
1626void LIBNETXMS_EXPORTABLE CalculateMD5Hash(const unsigned char *data, size_t nbytes, unsigned char *hash);
1627void LIBNETXMS_EXPORTABLE MD5HashForPattern(const unsigned char *data, size_t patternSize, size_t fullSize, BYTE *hash);
1628void LIBNETXMS_EXPORTABLE CalculateSHA1Hash(unsigned char *data, size_t nbytes, unsigned char *hash);
1629void LIBNETXMS_EXPORTABLE SHA1HashForPattern(unsigned char *data, size_t patternSize, size_t fullSize, unsigned char *hash);
1718cc2a 1630void LIBNETXMS_EXPORTABLE CalculateSHA256Hash(const unsigned char *data, size_t len, unsigned char *hash);
735bac5c
VK
1631BOOL LIBNETXMS_EXPORTABLE CalculateFileMD5Hash(const TCHAR *pszFileName, BYTE *pHash);
1632BOOL LIBNETXMS_EXPORTABLE CalculateFileSHA1Hash(const TCHAR *pszFileName, BYTE *pHash);
1633BOOL LIBNETXMS_EXPORTABLE CalculateFileCRC32(const TCHAR *pszFileName, UINT32 *pResult);
66c04cc7 1634
981d246a
VK
1635void LIBNETXMS_EXPORTABLE GenerateRandomBytes(BYTE *buffer, size_t size);
1636
735bac5c
VK
1637void LIBNETXMS_EXPORTABLE ICEEncryptData(const BYTE *in, int inLen, BYTE *out, const BYTE *key);
1638void LIBNETXMS_EXPORTABLE ICEDecryptData(const BYTE *in, int inLen, BYTE *out, const BYTE *key);
4e2debcc 1639
f2436b76 1640bool LIBNETXMS_EXPORTABLE DecryptPassword(const TCHAR *login, const TCHAR *encryptedPasswd, TCHAR *decryptedPasswd, size_t bufferLenght);
6b1282e7 1641
735bac5c 1642int LIBNETXMS_EXPORTABLE NxDCIDataTypeFromText(const TCHAR *pszText);
aa13cfd9 1643
735bac5c
VK
1644HMODULE LIBNETXMS_EXPORTABLE DLOpen(const TCHAR *pszLibName, TCHAR *pszErrorText);
1645void LIBNETXMS_EXPORTABLE DLClose(HMODULE hModule);
1646void LIBNETXMS_EXPORTABLE *DLGetSymbolAddr(HMODULE hModule, const char *pszSymbol, TCHAR *pszErrorText);
aa13cfd9 1647
735bac5c
VK
1648bool LIBNETXMS_EXPORTABLE ExtractNamedOptionValueW(const WCHAR *optString, const WCHAR *option, WCHAR *buffer, int bufSize);
1649bool LIBNETXMS_EXPORTABLE ExtractNamedOptionValueAsBoolW(const WCHAR *optString, const WCHAR *option, bool defVal);
1650long LIBNETXMS_EXPORTABLE ExtractNamedOptionValueAsIntW(const WCHAR *optString, const WCHAR *option, long defVal);
289d126b 1651
735bac5c
VK
1652bool LIBNETXMS_EXPORTABLE ExtractNamedOptionValueA(const char *optString, const char *option, char *buffer, int bufSize);
1653bool LIBNETXMS_EXPORTABLE ExtractNamedOptionValueAsBoolA(const char *optString, const char *option, bool defVal);
1654long LIBNETXMS_EXPORTABLE ExtractNamedOptionValueAsIntA(const char *optString, const char *option, long defVal);
289d126b
VK
1655
1656#ifdef UNICODE
1657#define ExtractNamedOptionValue ExtractNamedOptionValueW
1658#define ExtractNamedOptionValueAsBool ExtractNamedOptionValueAsBoolW
1659#define ExtractNamedOptionValueAsInt ExtractNamedOptionValueAsIntW
1660#else
1661#define ExtractNamedOptionValue ExtractNamedOptionValueA
1662#define ExtractNamedOptionValueAsBool ExtractNamedOptionValueAsBoolA
1663#define ExtractNamedOptionValueAsInt ExtractNamedOptionValueAsIntA
1664#endif
ae9cddaf 1665
bc858635 1666#ifdef __cplusplus
735bac5c 1667const TCHAR LIBNETXMS_EXPORTABLE *CodeToText(int iCode, CODE_TO_TEXT *pTranslator, const TCHAR *pszDefaultText = _T("Unknown"));
bc858635 1668#else
735bac5c 1669const TCHAR LIBNETXMS_EXPORTABLE *CodeToText(int iCode, CODE_TO_TEXT *pTranslator, const TCHAR *pszDefaultText);
bc858635
VK
1670#endif
1671
aa13cfd9 1672#ifdef _WIN32
735bac5c
VK
1673TCHAR LIBNETXMS_EXPORTABLE *GetSystemErrorText(UINT32 dwError, TCHAR *pszBuffer, size_t iBufSize);
1674BOOL LIBNETXMS_EXPORTABLE GetWindowsVersionString(TCHAR *versionString, int strSize);
1675INT64 LIBNETXMS_EXPORTABLE GetProcessRSS();
aa13cfd9 1676#endif
696fc54f 1677
de4c0511
VK
1678#if !HAVE_DAEMON || !HAVE_DECL_DAEMON
1679int LIBNETXMS_EXPORTABLE __daemon(int nochdir, int noclose);
1680#define daemon __daemon
696fc54f 1681#endif
4332e9d8 1682
735bac5c 1683UINT32 LIBNETXMS_EXPORTABLE inet_addr_w(const WCHAR *pszAddr);
268774a0 1684
4332e9d8 1685#ifndef _WIN32
735bac5c
VK
1686BOOL LIBNETXMS_EXPORTABLE SetDefaultCodepage(const char *cp);
1687int LIBNETXMS_EXPORTABLE WideCharToMultiByte(int iCodePage, UINT32 dwFlags, const WCHAR *pWideCharStr,
1688 int cchWideChar, char *pByteStr, int cchByteChar,
1689 char *pDefaultChar, BOOL *pbUsedDefChar);
1690int LIBNETXMS_EXPORTABLE MultiByteToWideChar(int iCodePage, UINT32 dwFlags, const char *pByteStr,
1691 int cchByteChar, WCHAR *pWideCharStr,
1692 int cchWideChar);
04dbaf62 1693
6b93c954 1694#if !defined(UNICODE_UCS2) || !HAVE_WCSLEN
735bac5c 1695int LIBNETXMS_EXPORTABLE ucs2_strlen(const UCS2CHAR *pStr);
6b93c954
VK
1696#endif
1697#if !defined(UNICODE_UCS2) || !HAVE_WCSNCPY
735bac5c 1698UCS2CHAR LIBNETXMS_EXPORTABLE *ucs2_strncpy(UCS2CHAR *pDst, const UCS2CHAR *pSrc, int nDstLen);
6b93c954
VK
1699#endif
1700#if !defined(UNICODE_UCS2) || !HAVE_WCSDUP
b6ec31bb 1701UCS2CHAR LIBNETXMS_EXPORTABLE *ucs2_strdup(const UCS2CHAR *pStr);
4332e9d8 1702#endif
8b86c5dc 1703
735bac5c
VK
1704size_t LIBNETXMS_EXPORTABLE ucs2_to_mb(const UCS2CHAR *src, int srcLen, char *dst, int dstLen);
1705size_t LIBNETXMS_EXPORTABLE mb_to_ucs2(const char *src, int srcLen, UCS2CHAR *dst, int dstLen);
1706UCS2CHAR LIBNETXMS_EXPORTABLE *UCS2StringFromMBString(const char *pszString);
1707char LIBNETXMS_EXPORTABLE *MBStringFromUCS2String(const UCS2CHAR *pszString);
8b86c5dc 1708
735bac5c
VK
1709int LIBNETXMS_EXPORTABLE nx_wprintf(const WCHAR *format, ...);
1710int LIBNETXMS_EXPORTABLE nx_fwprintf(FILE *fp, const WCHAR *format, ...);
1711int LIBNETXMS_EXPORTABLE nx_swprintf(WCHAR *buffer, size_t size, const WCHAR *format, ...);
1712int LIBNETXMS_EXPORTABLE nx_vwprintf(const WCHAR *format, va_list args);
1713int LIBNETXMS_EXPORTABLE nx_vfwprintf(FILE *fp, const WCHAR *format, va_list args);
1714int LIBNETXMS_EXPORTABLE nx_vswprintf(WCHAR *buffer, size_t size, const WCHAR *format, va_list args);
04dbaf62 1715
735bac5c
VK
1716int LIBNETXMS_EXPORTABLE nx_wscanf(const WCHAR *format, ...);
1717int LIBNETXMS_EXPORTABLE nx_fwscanf(FILE *fp, const WCHAR *format, ...);
1718int LIBNETXMS_EXPORTABLE nx_swscanf(const WCHAR *str, const WCHAR *format, ...);
1719int LIBNETXMS_EXPORTABLE nx_vwscanf(const WCHAR *format, va_list args);
1720int LIBNETXMS_EXPORTABLE nx_vfwscanf(FILE *fp, const WCHAR *format, va_list args);
1721int LIBNETXMS_EXPORTABLE nx_vswscanf(const WCHAR *str, const WCHAR *format, va_list args);
25575d38 1722
3e39fcde 1723#endif /* _WIN32 */
8b86c5dc 1724
3d1058ed 1725#ifdef _WITH_ENCRYPTION
735bac5c 1726WCHAR LIBNETXMS_EXPORTABLE *ERR_error_string_W(int nError, WCHAR *pwszBuffer);
3d1058ed
VK
1727#endif
1728
8b86c5dc 1729#ifdef UNICODE_UCS4
735bac5c
VK
1730size_t LIBNETXMS_EXPORTABLE ucs2_to_ucs4(const UCS2CHAR *src, int srcLen, WCHAR *dst, int dstLen);
1731size_t LIBNETXMS_EXPORTABLE ucs4_to_ucs2(const WCHAR *src, int srcLen, UCS2CHAR *dst, int dstLen);
1732size_t LIBNETXMS_EXPORTABLE ucs2_to_utf8(const UCS2CHAR *src, int srcLen, char *dst, int dstLen);
1733UCS2CHAR LIBNETXMS_EXPORTABLE *UCS2StringFromUCS4String(const WCHAR *pwszString);
1734WCHAR LIBNETXMS_EXPORTABLE *UCS4StringFromUCS2String(const UCS2CHAR *pszString);
b50f1100 1735#endif
8b86c5dc 1736
ebe98224
VK
1737size_t LIBNETXMS_EXPORTABLE utf8_to_mb(const char *src, int srcLen, char *dst, int dstLen);
1738size_t LIBNETXMS_EXPORTABLE mb_to_utf8(const char *src, int srcLen, char *dst, int dstLen);
1739char LIBNETXMS_EXPORTABLE *MBStringFromUTF8String(const char *s);
1740char LIBNETXMS_EXPORTABLE *UTF8StringFromMBString(const char *s);
1741
842c22f4 1742#if !defined(_WIN32) && !HAVE_WSTAT
735bac5c 1743int wstat(const WCHAR *_path, struct stat *_sbuf);
842c22f4
AK
1744#endif
1745
ef856d02 1746#if defined(UNICODE) && !defined(_WIN32)
d9b66a56 1747
f3387429 1748#if !HAVE_WPOPEN
735bac5c 1749FILE LIBNETXMS_EXPORTABLE *wpopen(const WCHAR *_command, const WCHAR *_type);
f3387429 1750#endif
8b86c5dc 1751#if !HAVE_WFOPEN
735bac5c 1752FILE LIBNETXMS_EXPORTABLE *wfopen(const WCHAR *_name, const WCHAR *_type);
8b86c5dc 1753#endif
8c2489aa 1754#if HAVE_FOPEN64 && !HAVE_WFOPEN64
735bac5c 1755FILE LIBNETXMS_EXPORTABLE *wfopen64(const WCHAR *_name, const WCHAR *_type);
8c2489aa 1756#endif
8b86c5dc 1757#if !HAVE_WOPEN
735bac5c 1758int LIBNETXMS_EXPORTABLE wopen(const WCHAR *, int, ...);
b50f1100 1759#endif
f3387429 1760#if !HAVE_WCHMOD
735bac5c 1761int LIBNETXMS_EXPORTABLE wchmod(const WCHAR *_name, int mode);
f3387429 1762#endif
b07c50cc 1763#if !HAVE_WCHDIR
735bac5c 1764int wchdir(const WCHAR *_path);
b07c50cc
VK
1765#endif
1766#if !HAVE_WMKDIR
735bac5c 1767int wmkdir(const WCHAR *_path, int mode);
b07c50cc
VK
1768#endif
1769#if !HAVE_WRMDIR
735bac5c 1770int wrmdir(const WCHAR *_path);
b07c50cc 1771#endif
ccc34207 1772#if !HAVE_WRENAME
735bac5c 1773int wrename(const WCHAR *_oldpath, const WCHAR *_newpath);
ccc34207
VK
1774#endif
1775#if !HAVE_WUNLINK
735bac5c 1776int wunlink(const WCHAR *_path);
ccc34207 1777#endif
b07c50cc 1778#if !HAVE_WREMOVE
735bac5c 1779int wremove(const WCHAR *_path);
b07c50cc
VK
1780#endif
1781#if !HAVE_WSYSTEM
735bac5c 1782int wsystem(const WCHAR *_cmd);
b07c50cc 1783#endif
dda7c270 1784#if !HAVE_WMKSTEMP
735bac5c 1785int wmkstemp(WCHAR *_template);
dda7c270 1786#endif
b07c50cc 1787#if !HAVE_WACCESS
735bac5c 1788int waccess(const WCHAR *_path, int mode);
b07c50cc 1789#endif
273da39a 1790#if !HAVE_WGETENV
735bac5c 1791WCHAR *wgetenv(const WCHAR *_string);
273da39a 1792#endif
f3387429 1793#if !HAVE_WCTIME
735bac5c 1794WCHAR *wctime(const time_t *timep);
f3387429 1795#endif
0186b5da 1796#if !HAVE_PUTWS
735bac5c 1797int putws(const WCHAR *s);
0186b5da 1798#endif
9757ca46 1799#if !HAVE_WCSERROR && (HAVE_STRERROR || HAVE_DECL_STRERROR)
735bac5c 1800WCHAR *wcserror(int errnum);
d49d7500
VK
1801#endif
1802#if !HAVE_WCSERROR_R && HAVE_STRERROR_R
b0823d06 1803#if HAVE_POSIX_STRERROR_R
735bac5c 1804int wcserror_r(int errnum, WCHAR *strerrbuf, size_t buflen);
b0823d06 1805#else
735bac5c 1806WCHAR *wcserror_r(int errnum, WCHAR *strerrbuf, size_t buflen);
d49d7500 1807#endif
b0823d06 1808#endif
e05f8aaf 1809
ef856d02 1810#endif /* UNICODE && !_WIN32*/
e05f8aaf 1811
8b86c5dc 1812#if !HAVE_STRTOLL
735bac5c 1813INT64 LIBNETXMS_EXPORTABLE strtoll(const char *nptr, char **endptr, int base);
8b86c5dc
VK
1814#endif
1815#if !HAVE_STRTOULL
735bac5c 1816UINT64 LIBNETXMS_EXPORTABLE strtoull(const char *nptr, char **endptr, int base);
8b86c5dc 1817#endif
e05f8aaf
VK
1818
1819#if !HAVE_WCSTOLL
735bac5c 1820INT64 LIBNETXMS_EXPORTABLE wcstoll(const WCHAR *nptr, WCHAR **endptr, int base);
e05f8aaf
VK
1821#endif
1822#if !HAVE_WCSTOULL
735bac5c 1823UINT64 LIBNETXMS_EXPORTABLE wcstoull(const WCHAR *nptr, WCHAR **endptr, int base);
e05f8aaf 1824#endif
b50f1100 1825
2f56be29 1826#if !HAVE_WCSLWR && !defined(_WIN32)
735bac5c 1827WCHAR LIBNETXMS_EXPORTABLE *wcslwr(WCHAR *str);
fdf1ed50
VK
1828#endif
1829
4d978b4a 1830#if !HAVE_WCSCASECMP && !defined(_WIN32)
735bac5c 1831int LIBNETXMS_EXPORTABLE wcscasecmp(const wchar_t *s1, const wchar_t *s2);
4d978b4a
VK
1832#endif
1833
f4d2c9ba 1834#if !HAVE_WCSNCASECMP && !defined(_WIN32)
735bac5c 1835int LIBNETXMS_EXPORTABLE wcsncasecmp(const wchar_t *s1, const wchar_t *s2, size_t n);
f4d2c9ba
VK
1836#endif
1837
75b4d48e
VK
1838#if !defined(_WIN32) && (!HAVE_WCSFTIME || !WORKING_WCSFTIME)
1839size_t LIBNETXMS_EXPORTABLE nx_wcsftime(WCHAR *buffer, size_t bufsize, const WCHAR *format, const struct tm *t);
1840#undef wcsftime
1841#define wcsftime nx_wcsftime
1842#endif
1843
9138dfe2
VK
1844#ifndef _WIN32
1845
1846#if HAVE_ITOA && !HAVE__ITOA
1847#define _itoa itoa
1848#undef HAVE__ITOA
1849#define HAVE__ITOA 1
1850#endif
1851#if !HAVE__ITOA && !defined(_WIN32)
1852char LIBNETXMS_EXPORTABLE *_itoa(int value, char *str, int base);
1853#endif
1854
1855#if HAVE_ITOW && !HAVE__ITOW
1856#define _itow itow
1857#undef HAVE__ITOW
1858#define HAVE__ITOW 1
1859#endif
1860#if !HAVE__ITOW && !defined(_WIN32)
1861WCHAR LIBNETXMS_EXPORTABLE *_itow(int value, WCHAR *str, int base);
1862#endif
1863
1864#endif /* _WIN32 */
1865
3d1cb7d6 1866#ifdef _WIN32
5ea2db30 1867#ifdef UNICODE
735bac5c
VK
1868DIRW LIBNETXMS_EXPORTABLE *wopendir(const WCHAR *filename);
1869struct dirent_w LIBNETXMS_EXPORTABLE *wreaddir(DIRW *dirp);
1870int LIBNETXMS_EXPORTABLE wclosedir(DIRW *dirp);
5ea2db30
VK
1871
1872#define _topendir wopendir
1873#define _treaddir wreaddir
1874#define _tclosedir wclosedir
1875#else
1876#define _topendir opendir
1877#define _treaddir readdir
1878#define _tclosedir closedir
1879#endif
1880
735bac5c
VK
1881DIR LIBNETXMS_EXPORTABLE *opendir(const char *filename);
1882struct dirent LIBNETXMS_EXPORTABLE *readdir(DIR *dirp);
1883int LIBNETXMS_EXPORTABLE closedir(DIR *dirp);
5ea2db30 1884
76b1d3d8
VK
1885#else /* not _WIN32 */
1886
735bac5c
VK
1887DIRW LIBNETXMS_EXPORTABLE *wopendir(const WCHAR *filename);
1888struct dirent_w LIBNETXMS_EXPORTABLE *wreaddir(DIRW *dirp);
1889int LIBNETXMS_EXPORTABLE wclosedir(DIRW *dirp);
76b1d3d8 1890
37d62364 1891#endif
3d1cb7d6 1892
7f9e0c00 1893#if defined(_WIN32) || !(HAVE_SCANDIR)
735bac5c
VK
1894int LIBNETXMS_EXPORTABLE scandir(const char *dir, struct dirent ***namelist,
1895 int (*select)(const struct dirent *),
1896 int (*compar)(const struct dirent **, const struct dirent **));
1897int LIBNETXMS_EXPORTABLE alphasort(const struct dirent **a, const struct dirent **b);
7f9e0c00
VK
1898#endif
1899
3bf0df9f
VK
1900TCHAR LIBNETXMS_EXPORTABLE *safe_fgetts(TCHAR *buffer, int len, FILE *f);
1901
2df047f4
VK
1902bool LIBNETXMS_EXPORTABLE nxlog_open(const TCHAR *logName, UINT32 flags, const TCHAR *msgModule,
1903 unsigned int msgCount, const TCHAR **messages, DWORD debugMsg);
9f2902ac
VK
1904void LIBNETXMS_EXPORTABLE nxlog_close(void);
1905void LIBNETXMS_EXPORTABLE nxlog_write(DWORD msg, WORD wType, const char *format, ...);
2df047f4
VK
1906void LIBNETXMS_EXPORTABLE nxlog_debug(int level, const TCHAR *format, ...);
1907void LIBNETXMS_EXPORTABLE nxlog_debug2(int level, const TCHAR *format, va_list args);
1908bool LIBNETXMS_EXPORTABLE nxlog_set_rotation_policy(int rotationMode, int maxLogSize, int historySize, const TCHAR *dailySuffix);
1909bool LIBNETXMS_EXPORTABLE nxlog_rotate();
1910void LIBNETXMS_EXPORTABLE nxlog_set_debug_level(int level);
1911int LIBNETXMS_EXPORTABLE nxlog_get_debug_level();
7c587518
VK
1912
1913typedef void (*NxLogDebugWriter)(const TCHAR *);
1914void LIBNETXMS_EXPORTABLE nxlog_set_debug_writer(NxLogDebugWriter writer);
9113e749
VK
1915
1916typedef void (*NxLogConsoleWriter)(const TCHAR *, ...);
1917void LIBNETXMS_EXPORTABLE nxlog_set_console_writer(NxLogConsoleWriter writer);
f669df41
VK
1918
1919void LIBNETXMS_EXPORTABLE WriteToTerminal(const TCHAR *text);
6e383343
VK
1920void LIBNETXMS_EXPORTABLE WriteToTerminalEx(const TCHAR *format, ...)
1921#if !defined(UNICODE) && (defined(__GNUC__) || defined(__clang__))
1922 __attribute__ ((format(printf, 1, 2)))
1923#endif
1924;
9f2902ac 1925
37a7a862
VK
1926#ifdef _WIN32
1927int LIBNETXMS_EXPORTABLE mkstemp(char *tmpl);
1928int LIBNETXMS_EXPORTABLE wmkstemp(WCHAR *tmpl);
1929#ifdef UNICODE
1930#define _tmkstemp wmkstemp
1931#else
1932#define _tmkstemp mkstemp
1933#endif
1934#endif
1935
9b13553b
VK
1936#ifndef _WIN32
1937int strcat_s(char *dst, size_t dstSize, const char *src);
1938int wcscat_s(WCHAR *dst, size_t dstSize, const WCHAR *src);
1939#endif
1940
c57d020a
VK
1941#if !HAVE_STRPTIME
1942char LIBNETXMS_EXPORTABLE *strptime(const char *buf, const char *fmt, struct tm *_tm);
1943#endif
1944
1945#if !HAVE_TIMEGM
1946time_t LIBNETXMS_EXPORTABLE timegm(struct tm *_tm);
1947#endif
1948
6f95ef89
VK
1949#if !HAVE_INET_PTON
1950int LIBNETXMS_EXPORTABLE nx_inet_pton(int af, const char *src, void *dst);
1951#define inet_pton nx_inet_pton
1952#endif
1953
b06ae508 1954int LIBNETXMS_EXPORTABLE GetSleepTime(int hour, int minute, int second);
b60584cf
VK
1955time_t LIBNETXMS_EXPORTABLE ParseDateTimeA(const char *text, time_t defaultValue);
1956time_t LIBNETXMS_EXPORTABLE ParseDateTimeW(const WCHAR *text, time_t defaultValue);
1957
1958#ifdef UNICODE
1959#define ParseDateTime ParseDateTimeW
1960#else
1961#define ParseDateTime ParseDateTimeA
1962#endif
b06ae508 1963
b50f1100 1964#ifdef __cplusplus
e9246d26 1965}
b50f1100 1966#endif
e9246d26 1967
a7ff20a5
VK
1968
1969//
b06ae508 1970// C++ only functions
a7ff20a5
VK
1971//
1972
1973#ifdef __cplusplus
1974
a97f02e1
VK
1975enum nxDirectoryType
1976{
1977 nxDirBin = 0,
1978 nxDirData = 1,
1979 nxDirEtc = 2,
1039d7ee
VK
1980 nxDirLib = 3,
1981 nxDirShare = 4
a97f02e1
VK
1982};
1983
5962498b
VK
1984TCHAR LIBNETXMS_EXPORTABLE *GetHeapInfo();
1985
a97f02e1
VK
1986void LIBNETXMS_EXPORTABLE GetNetXMSDirectory(nxDirectoryType type, TCHAR *dir);
1987
43709a0c
VK
1988UINT32 LIBNETXMS_EXPORTABLE IcmpPing(const InetAddress& addr, int iNumRetries, UINT32 dwTimeout, UINT32 *pdwRTT, UINT32 dwPacketSize);
1989
240816b0
VK
1990TCHAR LIBNETXMS_EXPORTABLE *EscapeStringForXML(const TCHAR *str, int length);
1991String LIBNETXMS_EXPORTABLE EscapeStringForXML2(const TCHAR *str, int length = -1);
53c96e2d
VK
1992const char LIBNETXMS_EXPORTABLE *XMLGetAttr(const char **attrs, const char *name);
1993int LIBNETXMS_EXPORTABLE XMLGetAttrInt(const char **attrs, const char *name, int defVal);
967893bb 1994UINT32 LIBNETXMS_EXPORTABLE XMLGetAttrUINT32(const char **attrs, const char *name, UINT32 defVal);
53c96e2d
VK
1995bool LIBNETXMS_EXPORTABLE XMLGetAttrBoolean(const char **attrs, const char *name, bool defVal);
1996
1997#if !defined(_WIN32) && !defined(_NETWARE) && defined(NMS_THREADS_H_INCLUDED)
9113e749 1998void LIBNETXMS_EXPORTABLE StartMainLoop(ThreadFunction pfSignalHandler, ThreadFunction pfMain);
53c96e2d
VK
1999#endif
2000
a7ff20a5
VK
2001#endif
2002
e9246d26 2003#endif /* _nms_util_h_ */