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