Fixed broken popup menu actions on "Interfaces" tab
[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
6d8aee95
VK
48
49//
92502d5f 50// Serial communications
6d8aee95
VK
51//
52
53#ifdef _WIN32
54
55#define FLOW_NONE 0
56#define FLOW_SOFTWARE 1
57#define FLOW_HARDWARE 2
58
59#else /* _WIN32 */
60
70fed300
AK
61#ifdef HAVE_TERMIOS_H
62# include <termios.h>
63#else
64# error termios.h not found
65#endif
66
6d8aee95
VK
67#endif /* _WIN32 */
68
e2e66145
VK
69/**
70 * Return codes for IcmpPing()
71 */
66c04cc7
VK
72#define ICMP_SUCCESS 0
73#define ICMP_UNREACHEABLE 1
74#define ICMP_TIMEOUT 2
75#define ICMP_RAW_SOCK_FAILED 3
5418d4bb 76#define ICMP_API_ERROR 4
66c04cc7 77
e2e66145
VK
78/**
79 * Token types for configuration loader
80 */
4826c8a5
VK
81#define CT_LONG 0
82#define CT_STRING 1
83#define CT_STRING_LIST 2
84#define CT_END_OF_LIST 3
85#define CT_BOOLEAN 4
86#define CT_WORD 5
fc935a60 87#define CT_IGNORE 6
dda7c270 88#define CT_MB_STRING 7
e95680e5 89#define CT_BOOLEAN64 8
4826c8a5 90
605fc935 91/**
e2e66145
VK
92 * Uninitialized value for override indicator
93 */
94#define NXCONFIG_UNINITIALIZED_VALUE (-1)
95
96/**
605fc935
VK
97 * Return codes for NxLoadConfig()
98 */
4826c8a5
VK
99#define NXCFG_ERR_OK 0
100#define NXCFG_ERR_NOFILE 1
101#define NXCFG_ERR_SYNTAX 2
102
605fc935
VK
103/**
104 * nxlog_open() flags
105 */
4e0e77e6
VK
106#define NXLOG_USE_SYSLOG ((UINT32)0x00000001)
107#define NXLOG_PRINT_TO_STDOUT ((UINT32)0x00000002)
108#define NXLOG_BACKGROUND_WRITER ((UINT32)0x00000004)
109#define NXLOG_IS_OPEN ((UINT32)0x80000000)
9f2902ac 110
605fc935
VK
111/**
112 * nxlog rotation policy
113 */
5945d50a
VK
114#define NXLOG_ROTATION_DISABLED 0
115#define NXLOG_ROTATION_DAILY 1
116#define NXLOG_ROTATION_BY_SIZE 2
117
605fc935
VK
118/**
119 * _tcsdup() replacement
120 */
8ff13508
VK
121#if defined(_WIN32) && defined(USE_WIN32_HEAP)
122#ifdef __cplusplus
123extern "C" {
124#endif
fd72502a 125char LIBNETXMS_EXPORTABLE *nx_strdup(const char *src);
8ff13508
VK
126WCHAR LIBNETXMS_EXPORTABLE *nx_wcsdup(const WCHAR *src);
127#ifdef __cplusplus
128}
129#endif
130#endif
131
605fc935 132/**
f4d2c9ba
VK
133 * Custom wcsdup
134 */
135#if !HAVE_WCSDUP && !defined(_WIN32)
fd72502a 136
f4d2c9ba
VK
137#ifdef __cplusplus
138extern "C" {
139#endif
140 WCHAR LIBNETXMS_EXPORTABLE *wcsdup(const WCHAR *src);
141#ifdef __cplusplus
142}
143#endif
fd72502a
VK
144
145#elif defined(_AIX)
146
147// Some AIX versions have broken wcsdup() so we use internal implementation
148#ifdef __cplusplus
149extern "C" {
150#endif
151 WCHAR LIBNETXMS_EXPORTABLE *nx_wcsdup(const WCHAR *src);
152#ifdef __cplusplus
153}
154#endif
155
156#define wcsdup nx_wcsdup
157
f4d2c9ba
VK
158#endif
159
c012b7b7
VK
160#ifdef __cplusplus
161
f4d2c9ba 162/**
c83f6449
VK
163 * Extended tcsdup: returns NULL if NULL pointer passed
164 */
165inline TCHAR *_tcsdup_ex(const TCHAR *s)
166{
167 return (s != NULL) ? _tcsdup(s) : NULL;
168}
169
c012b7b7
VK
170#endif
171
c83f6449 172/**
d65c16a8
VK
173 * String conversion helpers
174 */
175#ifdef __cplusplus
176extern "C" {
177#endif
178WCHAR LIBNETXMS_EXPORTABLE *WideStringFromMBString(const char *pszString);
179WCHAR LIBNETXMS_EXPORTABLE *WideStringFromUTF8String(const char *pszString);
180char LIBNETXMS_EXPORTABLE *MBStringFromWideString(const WCHAR *pwszString);
181char LIBNETXMS_EXPORTABLE *UTF8StringFromWideString(const WCHAR *pwszString);
182#ifdef __cplusplus
183}
184#endif
185
186/**
605fc935
VK
187 * Class for serial communications
188 */
b160350d
VK
189#ifdef __cplusplus
190
191#ifndef _WIN32
192enum
193{
194 NOPARITY,
195 ODDPARITY,
196 EVENPARITY,
197 ONESTOPBIT,
198 TWOSTOPBITS
199};
200
70fed300
AK
201enum
202{
203 FLOW_NONE,
204 FLOW_HARDWARE,
205 FLOW_SOFTWARE
206};
207
b160350d
VK
208#ifndef INVALID_HANDLE_VALUE
209#define INVALID_HANDLE_VALUE (-1)
210#endif
211#endif /* _WIN32 */
212
213class LIBNETXMS_EXPORTABLE Serial
214{
b160350d
VK
215private:
216 TCHAR *m_pszPort;
217 int m_nTimeout;
218 int m_nSpeed;
219 int m_nDataBits;
220 int m_nStopBits;
221 int m_nParity;
70fed300 222 int m_nFlowControl;
b160350d
VK
223
224#ifndef _WIN32
225 int m_hPort;
70fed300 226 struct termios m_originalSettings;
b160350d
VK
227#else
228 HANDLE m_hPort;
229#endif
b160350d 230
826fcc1f
VK
231public:
232 Serial();
233 ~Serial();
234
235 bool open(const TCHAR *pszPort);
236 void close();
237 void setTimeout(int nTimeout);
238 int read(char *pBuff, int nSize); /* waits up to timeout and do single read */
239 int readAll(char *pBuff, int nSize); /* read until timeout or out of space */
c3f71625 240 int readToMark(char *buff, int size, const char **marks, char **occurence);
826fcc1f
VK
241 bool write(const char *pBuff, int nSize);
242 void flush();
243 bool set(int nSpeed, int nDataBits, int nParity, int nStopBits, int nFlowControl = FLOW_NONE);
244 bool restart();
245};
ff214673 246
3fe40613
VK
247/**
248 * Dynamic string class
249 */
8bad8476
VK
250class LIBNETXMS_EXPORTABLE String
251{
252protected:
4e0e77e6
VK
253 TCHAR *m_buffer;
254 size_t m_length;
255 size_t m_allocated;
256 int m_allocationStep;
8bad8476
VK
257
258public:
c577e360
VK
259 static const int npos;
260
8bad8476 261 String();
f3cdd1c5 262 String(const TCHAR *init);
643c9dcb 263 String(const String &src);
8bad8476
VK
264 ~String();
265
4e0e77e6
VK
266 TCHAR *getBuffer() { return m_buffer; }
267 void setBuffer(TCHAR *buffer);
8bad8476 268
4e0e77e6
VK
269 int getAllocationStep() { return m_allocationStep; }
270 void setAllocationStep(int step) { m_allocationStep = step; }
271
272 const String& operator =(const TCHAR *str);
49bf9d8d 273 const String& operator =(const String &src);
1d34c533
VK
274 const String& operator +=(const TCHAR *str);
275 const String& operator +=(const String &str);
4e0e77e6 276 operator const TCHAR*() { return CHECK_NULL_EX(m_buffer); }
8bad8476 277
08b214c6
VK
278 char *getUTF8String();
279
4e0e77e6
VK
280 void append(const TCHAR *str) { if (str != NULL) append(str, _tcslen(str)); }
281 void append(const TCHAR *str, size_t len);
282
283 void appendPreallocated(TCHAR *str) { if (str != NULL) { append(str); free(str); } }
284
285 void appendMBString(const char *str, size_t len, int nCodePage);
286 void appendWideString(const WCHAR *str, size_t len);
c577e360 287
4e0e77e6
VK
288 void appendFormattedString(const TCHAR *format, ...);
289 void appendFormattedStringV(const TCHAR *format, va_list args);
ff175e91 290
4e0e77e6 291 void clear();
c577e360 292
4e0e77e6
VK
293 size_t length() const { return m_length; }
294 bool isEmpty() const { return m_length == 0; }
c577e360 295
4e0e77e6
VK
296 TCHAR *substring(int nStart, int nLen, TCHAR *pszBuffer = NULL);
297 int find(const TCHAR *str, int nStart = 0);
1e1450ef 298
6bcafa2d
VK
299 void escapeCharacter(int ch, int esc);
300 void replace(const TCHAR *pszSrc, const TCHAR *pszDst);
0bbab9d3
VK
301 void trim();
302 void shrink(int chars = 1);
c577e360
VK
303};
304
3fe40613 305/**
f9861ff9
VK
306 * Dynamic array class
307 */
308class LIBNETXMS_EXPORTABLE Array
309{
310private:
311 int m_size;
312 int m_allocated;
313 int m_grow;
314 size_t m_elementSize;
315 void **m_data;
316 bool m_objectOwner;
317
318 void internalRemove(int index, bool allowDestruction);
319 void destroyObject(void *object) { if (object != NULL) m_objectDestructor(object); }
320
321protected:
322 bool m_storePointers;
323 void (*m_objectDestructor)(void *);
324
325 Array(void *data, int initial, int grow, size_t elementSize);
326 void *__getBuffer() { return m_data; }
327
328public:
329 Array(int initial = 0, int grow = 16, bool owner = false);
330 virtual ~Array();
331
332 int add(void *element);
333 void *get(int index) { return ((index >= 0) && (index < m_size)) ? (m_storePointers ? m_data[index] : (void *)((char *)m_data + index * m_elementSize)): NULL; }
334 int indexOf(void *element);
335 void set(int index, void *element);
336 void replace(int index, void *element);
337 void remove(int index) { internalRemove(index, true); }
338 void remove(void *element) { internalRemove(indexOf(element), true); }
339 void unlink(int index) { internalRemove(index, false); }
340 void unlink(void *element) { internalRemove(indexOf(element), false); }
341 void clear();
342 void sort(int (*cb)(const void *, const void *));
343 void *find(const void *key, int (*cb)(const void *, const void *));
344
345 int size() { return m_size; }
346
347 void setOwner(bool owner) { m_objectOwner = owner; }
348 bool isOwner() { return m_objectOwner; }
349};
350
351/**
352 * Template class for dynamic array which holds objects
353 */
354template <class T> class ObjectArray : public Array
355{
356private:
357 static void destructor(void *object) { delete (T*)object; }
358
359public:
360 ObjectArray(int initial = 0, int grow = 16, bool owner = false) : Array(initial, grow, owner) { m_objectDestructor = destructor; }
361 virtual ~ObjectArray() { }
362
363 int add(T *object) { return Array::add((void *)object); }
364 T *get(int index) { return (T*)Array::get(index); }
365 int indexOf(T *object) { return Array::indexOf((void *)object); }
366 void set(int index, T *object) { Array::set(index, (void *)object); }
367 void replace(int index, T *object) { Array::replace(index, (void *)object); }
368 void remove(int index) { Array::remove(index); }
369 void remove(T *object) { Array::remove((void *)object); }
370 void unlink(int index) { Array::unlink(index); }
371 void unlink(T *object) { Array::unlink((void *)object); }
372};
373
374/**
375 * Template class for dynamic array which holds scalar values
376 */
377template <class T> class IntegerArray : public Array
378{
379private:
380 static void destructor(void *element) { }
381
382public:
383 IntegerArray(int initial = 0, int grow = 16) : Array(NULL, initial, grow, sizeof(T)) { m_objectDestructor = destructor; m_storePointers = (sizeof(T) == sizeof(void *)); }
384 virtual ~IntegerArray() { }
385
386 int add(T value) { return Array::add(m_storePointers ? CAST_TO_POINTER(value, void *) : &value); }
387 T get(int index) { return m_storePointers ? CAST_FROM_POINTER(Array::get(index), T) : *((T*)Array::get(index)); }
388 int indexOf(T value) { return Array::indexOf(m_storePointers ? CAST_TO_POINTER(value, void *) : &value); }
389 void set(int index, T value) { Array::set(index, m_storePointers ? CAST_TO_POINTER(value, void *) : &value); }
390 void replace(int index, T value) { Array::replace(index, m_storePointers ? CAST_TO_POINTER(value, void *) : &value); }
391
392 T *getBuffer() { return (T*)__getBuffer(); }
393};
394
395/**
396 * Auxilliary class to hold dynamically allocated array of structures
397 */
398template <class T> class StructArray : public Array
399{
400private:
401 static void destructor(void *element) { }
402
403public:
404 StructArray(int initial = 0, int grow = 16) : Array(NULL, initial, grow, sizeof(T)) { m_objectDestructor = destructor; }
405 StructArray(T *data, int size) : Array(data, size, 16, sizeof(T)) { m_objectDestructor = destructor; }
406 virtual ~StructArray() { }
407
408 int add(T *element) { return Array::add((void *)element); }
409 T *get(int index) { return (T*)Array::get(index); }
410 int indexOf(T *element) { return Array::indexOf((void *)element); }
411 void set(int index, T *element) { Array::set(index, (void *)element); }
412 void replace(int index, T *element) { Array::replace(index, (void *)element); }
413 void remove(int index) { Array::remove(index); }
414 void remove(T *element) { Array::remove((void *)element); }
415 void unlink(int index) { Array::unlink(index); }
416 void unlink(T *element) { Array::unlink((void *)element); }
417
418 T *getBuffer() { return (T*)__getBuffer(); }
419};
420
421/**
422 * Entry of string map (internal)
400e55c4
VK
423 */
424struct StringMapEntry;
425
426/**
f9861ff9
VK
427 * Key/value pair
428 */
429struct KeyValuePair
430{
431 const TCHAR *key;
432 const void *value;
433};
434
435/**
3fe40613
VK
436 * String maps base class
437 */
438class LIBNETXMS_EXPORTABLE StringMapBase
c577e360
VK
439{
440protected:
400e55c4 441 StringMapEntry *m_data;
3fe40613 442 bool m_objectOwner;
55bdca5a 443 bool m_ignoreCase;
3fe40613 444 void (*m_objectDestructor)(void *);
c577e360 445
400e55c4 446 StringMapEntry *find(const TCHAR *key);
3fe40613
VK
447 void setObject(TCHAR *key, void *value, bool keyPreAlloc);
448 void *getObject(const TCHAR *key);
449 void destroyObject(void *object) { if (object != NULL) m_objectDestructor(object); }
c577e360
VK
450
451public:
3fe40613
VK
452 StringMapBase(bool objectOwner);
453 virtual ~StringMapBase();
454
55bdca5a 455 void setOwner(bool owner) { m_objectOwner = owner; }
91a581c5 456 void setIgnoreCase(bool ignore);
55bdca5a 457
3fe40613
VK
458 void remove(const TCHAR *key);
459 void clear();
460
c1a30973 461 int size();
400e55c4
VK
462 bool contains(const TCHAR *key) { return find(key) != NULL; }
463
464 bool forEach(bool (*cb)(const TCHAR *, const void *, void *), void *userData);
beab0421 465 const void *findElement(bool (*comparator)(const TCHAR *, const void *, void *), void *userData);
f9861ff9
VK
466
467 StructArray<KeyValuePair> *toArray();
3fe40613
VK
468};
469
470/**
400e55c4
VK
471 * NXCP message class
472 */
b368969c 473class NXCPMessage;
400e55c4
VK
474
475/**
3fe40613
VK
476 * String map class
477 */
478class LIBNETXMS_EXPORTABLE StringMap : public StringMapBase
479{
480public:
481 StringMap() : StringMapBase(true) { }
fb986055 482 StringMap(const StringMap &src);
3fe40613 483 virtual ~StringMap();
c577e360 484
fb986055 485 StringMap& operator =(const StringMap &src);
40b7416c 486
3fe40613
VK
487 void set(const TCHAR *key, const TCHAR *value) { setObject((TCHAR *)key, _tcsdup(value), false); }
488 void setPreallocated(TCHAR *key, TCHAR *value) { setObject(key, value, true); }
967893bb 489 void set(const TCHAR *key, UINT32 value);
5ad2167d 490
a6312bd6
VK
491 void addAll(StringMap *src);
492
3fe40613 493 const TCHAR *get(const TCHAR *key) { return (const TCHAR *)getObject(key); }
967893bb 494 UINT32 getULong(const TCHAR *key, UINT32 defaultValue);
6acb8479 495 bool getBoolean(const TCHAR *key, bool defaultValue);
5ad2167d 496
b368969c 497 void fillMessage(NXCPMessage *msg, UINT32 sizeFieldId, UINT32 baseFieldId);
8bad8476
VK
498};
499
3fe40613
VK
500/**
501 * String map template for holding objects as values
502 */
503template <class T> class StringObjectMap : public StringMapBase
504{
505private:
506 static void destructor(void *object) { delete (T*)object; }
6173bea8 507
3fe40613
VK
508public:
509 StringObjectMap(bool objectOwner) : StringMapBase(objectOwner) { m_objectDestructor = destructor; }
510
511 void set(const TCHAR *key, T *object) { setObject((TCHAR *)key, (void *)object, false); }
512 T *get(const TCHAR *key) { return (T*)getObject(key); }
3fe40613 513};
6173bea8 514
3fe40613
VK
515/**
516 * String list class
517 */
6173bea8
VK
518class LIBNETXMS_EXPORTABLE StringList
519{
520private:
521 int m_count;
522 int m_allocated;
523 TCHAR **m_values;
524
525public:
526 StringList();
86c126f5 527 StringList(StringList *src);
22ee6d97 528 StringList(const TCHAR *src, const TCHAR *separator);
6173bea8
VK
529 ~StringList();
530
531 void add(const TCHAR *value);
532 void addPreallocated(TCHAR *value);
967893bb
VK
533 void add(INT32 value);
534 void add(UINT32 value);
6173bea8 535 void add(INT64 value);
967893bb 536 void add(UINT64 value);
6173bea8 537 void add(double value);
24dc5346 538 void replace(int index, const TCHAR *value);
6173bea8 539 void clear();
a6312bd6
VK
540 int size() { return m_count; }
541 const TCHAR *get(int index) { return ((index >=0) && (index < m_count)) ? m_values[index] : NULL; }
542 int indexOf(const TCHAR *value);
543 int indexOfIgnoreCase(const TCHAR *value);
d51f2182 544 void remove(int index);
86c126f5 545 void addAll(const StringList *src);
93dbc1be 546 void merge(const StringList *src, bool matchCase);
7d25a5c5 547 TCHAR *join(const TCHAR *separator);
22ee6d97 548 void splitAndAdd(const TCHAR *src, const TCHAR *separator);
6173bea8
VK
549};
550
3fe40613 551/**
a58501c0
VK
552 * Entry of string set
553 */
554struct StringSetEntry;
555
556/**
f3603b79
VK
557 * NXCP message
558 */
b368969c 559class NXCPMessage;
f3603b79
VK
560
561/**
a58501c0
VK
562 * String set class
563 */
564class LIBNETXMS_EXPORTABLE StringSet
565{
566private:
567 StringSetEntry *m_data;
568
569public:
570 StringSet();
571 ~StringSet();
572
573 void add(const TCHAR *str);
f3603b79 574 void addPreallocated(TCHAR *str);
a58501c0
VK
575 void remove(const TCHAR *str);
576 void clear();
577
578 int size();
f3603b79 579 bool contains(const TCHAR *str);
5b521bfc 580 bool equals(StringSet *s);
a58501c0 581
fa493140 582 void addAll(StringSet *src);
f3603b79 583 void addAll(TCHAR **strings, int count);
d6c4cdc1 584 void addAllPreallocated(TCHAR **strings, int count);
a58501c0 585 void forEach(bool (*cb)(const TCHAR *, void *), void *userData);
f3603b79 586
b368969c
VK
587 void fillMessage(NXCPMessage *msg, UINT32 baseId, UINT32 countId);
588 void addAllFromMessage(NXCPMessage *msg, UINT32 baseId, UINT32 countId, bool clearBeforeAdd, bool toUppercase);
c262bc08
VK
589
590 String getAll(const TCHAR *separator);
a58501c0
VK
591};
592
593/**
25fe6265
VK
594 * Auxilliary class for objects which counts references and
595 * destroys itself wheren reference count falls to 0
596 */
7f632dfe
VK
597class LIBNETXMS_EXPORTABLE RefCountObject
598{
599private:
7785322f 600 VolatileCounter m_refCount;
7f632dfe
VK
601
602public:
7785322f
VK
603 RefCountObject()
604 {
605 m_refCount = 1;
606 }
b549a0f8 607 virtual ~RefCountObject();
7785322f
VK
608
609 void incRefCount()
610 {
611 InterlockedIncrement(&m_refCount);
612 }
613
614 void decRefCount()
615 {
616 if (InterlockedDecrement(&m_refCount) == 0)
617 delete this;
618 }
7f632dfe
VK
619};
620
b368969c 621class NXCPMessage;
967893bb
VK
622
623/**
624 * Table column definition
625 */
626class LIBNETXMS_EXPORTABLE TableColumnDefinition
627{
628private:
629 TCHAR *m_name;
630 TCHAR *m_displayName;
631 INT32 m_dataType;
632 bool m_instanceColumn;
633
634public:
635 TableColumnDefinition(const TCHAR *name, const TCHAR *displayName, INT32 dataType, bool isInstance);
b368969c 636 TableColumnDefinition(NXCPMessage *msg, UINT32 baseId);
967893bb
VK
637 TableColumnDefinition(TableColumnDefinition *src);
638 ~TableColumnDefinition();
639
b368969c 640 void fillMessage(NXCPMessage *msg, UINT32 baseId);
967893bb
VK
641
642 const TCHAR *getName() { return m_name; }
643 const TCHAR *getDisplayName() { return m_displayName; }
644 INT32 getDataType() { return m_dataType; }
645 bool isInstanceColumn() { return m_instanceColumn; }
646
647 void setDataType(INT32 type) { m_dataType = type; }
648 void setInstanceColumn(bool isInstance) { m_instanceColumn = isInstance; }
a0ddfb29 649 void setDisplayName(const TCHAR *name) { safe_free(m_displayName); m_displayName = _tcsdup(CHECK_NULL_EX(name)); }
967893bb
VK
650};
651
652/**
d6bbfa4e
VK
653 * Table cell
654 */
655class TableCell
656{
657private:
658 TCHAR *m_value;
659 int m_status;
660
661public:
662 TableCell() { m_value = NULL; m_status = -1; }
c83f6449
VK
663 TableCell(const TCHAR *value) { m_value = _tcsdup_ex(value); m_status = -1; }
664 TableCell(const TCHAR *value, int status) { m_value = _tcsdup_ex(value); m_status = status; }
665 TableCell(TableCell *src) { m_value = _tcsdup_ex(src->m_value); m_status = src->m_status; }
d6bbfa4e
VK
666 ~TableCell() { safe_free(m_value); }
667
c83f6449 668 void set(const TCHAR *value, int status) { safe_free(m_value); m_value = _tcsdup_ex(value); m_status = status; }
d6bbfa4e
VK
669 void setPreallocated(TCHAR *value, int status) { safe_free(m_value); m_value = value; m_status = status; }
670
671 const TCHAR *getValue() { return m_value; }
c83f6449 672 void setValue(const TCHAR *value) { safe_free(m_value); m_value = _tcsdup_ex(value); }
d6bbfa4e
VK
673 void setPreallocatedValue(TCHAR *value) { safe_free(m_value); m_value = value; }
674
675 int getStatus() { return m_status; }
676 void setStatus(int status) { m_status = status; }
677};
678
679/**
680 * Table row
681 */
682class TableRow
683{
684private:
685 ObjectArray<TableCell> *m_cells;
686 UINT32 m_objectId;
bac74bf7 687
d6bbfa4e
VK
688public:
689 TableRow(int columnCount);
690 TableRow(TableRow *src);
691 ~TableRow() { delete m_cells; }
692
693 void addColumn() { m_cells->add(new TableCell); }
694 void deleteColumn(int index) { m_cells->remove(index); }
bac74bf7 695
d6bbfa4e
VK
696 void set(int index, const TCHAR *value, int status) { TableCell *c = m_cells->get(index); if (c != NULL) c->set(value, status); }
697 void setPreallocated(int index, TCHAR *value, int status) { TableCell *c = m_cells->get(index); if (c != NULL) c->setPreallocated(value, status); }
698
699 void setValue(int index, const TCHAR *value) { TableCell *c = m_cells->get(index); if (c != NULL) c->setValue(value); }
700 void setPreallocatedValue(int index, TCHAR *value) { TableCell *c = m_cells->get(index); if (c != NULL) c->setPreallocatedValue(value); }
701
702 void setStatus(int index, int status) { TableCell *c = m_cells->get(index); if (c != NULL) c->setStatus(status); }
703
704 const TCHAR *getValue(int index) { TableCell *c = m_cells->get(index); return (c != NULL) ? c->getValue() : NULL; }
705 int getStatus(int index) { TableCell *c = m_cells->get(index); return (c != NULL) ? c->getStatus() : -1; }
706
707 UINT32 getObjectId() { return m_objectId; }
708 void setObjectId(UINT32 id) { m_objectId = id; }
709};
710
711/**
967893bb
VK
712 * Class for table data storage
713 */
a0ddfb29 714class LIBNETXMS_EXPORTABLE Table : public RefCountObject
967893bb
VK
715{
716private:
d6bbfa4e 717 ObjectArray<TableRow> *m_data;
967893bb
VK
718 ObjectArray<TableColumnDefinition> *m_columns;
719 TCHAR *m_title;
720 int m_source;
d6bbfa4e 721 bool m_extendedFormat;
967893bb 722
b368969c 723 void createFromMessage(NXCPMessage *msg);
967893bb
VK
724 void destroy();
725
726public:
727 Table();
a0ddfb29 728 Table(Table *src);
b368969c 729 Table(NXCPMessage *msg);
b549a0f8 730 virtual ~Table();
967893bb 731
b368969c
VK
732 int fillMessage(NXCPMessage &msg, int offset, int rowLimit);
733 void updateFromMessage(NXCPMessage *msg);
967893bb 734
a0ddfb29
VK
735 void addAll(Table *src);
736 void copyRow(Table *src, int row);
967893bb 737
d6bbfa4e
VK
738 int getNumRows() { return m_data->size(); }
739 int getNumColumns() { return m_columns->size(); }
967893bb
VK
740 const TCHAR *getTitle() { return CHECK_NULL_EX(m_title); }
741 int getSource() { return m_source; }
742
d6bbfa4e
VK
743 bool isExtendedFormat() { return m_extendedFormat; }
744 void setExtendedFormat(bool ext) { m_extendedFormat = ext; }
745
967893bb
VK
746 const TCHAR *getColumnName(int col) { return ((col >= 0) && (col < m_columns->size())) ? m_columns->get(col)->getName() : NULL; }
747 INT32 getColumnDataType(int col) { return ((col >= 0) && (col < m_columns->size())) ? m_columns->get(col)->getDataType() : 0; }
748 int getColumnIndex(const TCHAR *name);
749 ObjectArray<TableColumnDefinition> *getColumnDefinitions() { return m_columns; }
750
c83f6449 751 void setTitle(const TCHAR *title) { safe_free(m_title); m_title = _tcsdup_ex(title); }
967893bb 752 void setSource(int source) { m_source = source; }
8dba1eac 753 int addColumn(const TCHAR *name, INT32 dataType = 0, const TCHAR *displayName = NULL, bool isInstance = false);
967893bb
VK
754 void setColumnDataType(int col, INT32 dataType) { if ((col >= 0) && (col < m_columns->size())) m_columns->get(col)->setDataType(dataType); }
755 int addRow();
756
25076d53
VK
757 void deleteRow(int row);
758 void deleteColumn(int col);
759
967893bb
VK
760 void setAt(int nRow, int nCol, INT32 nData);
761 void setAt(int nRow, int nCol, UINT32 dwData);
762 void setAt(int nRow, int nCol, double dData);
763 void setAt(int nRow, int nCol, INT64 nData);
764 void setAt(int nRow, int nCol, UINT64 qwData);
765 void setAt(int nRow, int nCol, const TCHAR *pszData);
766 void setPreallocatedAt(int nRow, int nCol, TCHAR *pszData);
767
d6bbfa4e
VK
768 void set(int nCol, INT32 nData) { setAt(getNumRows() - 1, nCol, nData); }
769 void set(int nCol, UINT32 dwData) { setAt(getNumRows() - 1, nCol, dwData); }
770 void set(int nCol, double dData) { setAt(getNumRows() - 1, nCol, dData); }
771 void set(int nCol, INT64 nData) { setAt(getNumRows() - 1, nCol, nData); }
772 void set(int nCol, UINT64 qwData) { setAt(getNumRows() - 1, nCol, qwData); }
d65c16a8
VK
773 void set(int nCol, const TCHAR *data) { setAt(getNumRows() - 1, nCol, data); }
774#ifdef UNICODE
775 void set(int nCol, const char *data) { setPreallocatedAt(getNumRows() - 1, nCol, WideStringFromMBString(data)); }
776#else
777 void set(int nCol, const WCHAR *data) { setPreallocatedAt(getNumRows() - 1, nCol, MBStringFromWideString(data)); }
778#endif
779 void setPreallocated(int nCol, TCHAR *data) { setPreallocatedAt(getNumRows() - 1, nCol, data); }
d6bbfa4e
VK
780
781 void setStatusAt(int row, int col, int status);
782 void setStatus(int col, int status) { setStatusAt(getNumRows() - 1, col, status); }
967893bb
VK
783
784 const TCHAR *getAsString(int nRow, int nCol);
785 INT32 getAsInt(int nRow, int nCol);
786 UINT32 getAsUInt(int nRow, int nCol);
787 INT64 getAsInt64(int nRow, int nCol);
788 UINT64 getAsUInt64(int nRow, int nCol);
789 double getAsDouble(int nRow, int nCol);
22aaa779 790
d6bbfa4e
VK
791 int getStatus(int nRow, int nCol);
792
22aaa779 793 void buildInstanceString(int row, TCHAR *buffer, size_t bufLen);
a0ddfb29 794 int findRowByInstance(const TCHAR *instance);
d6bbfa4e
VK
795
796 UINT32 getObjectId(int row) { TableRow *r = m_data->get(row); return (r != NULL) ? r->getObjectId() : 0; }
797 void setObjectId(int row, UINT32 id) { TableRow *r = m_data->get(row); if (r != NULL) r->setObjectId(id); }
967893bb
VK
798};
799
25fe6265 800/**
c11eee9b
VK
801 * sockaddr buffer
802 */
803union SockAddrBuffer
804{
805 struct sockaddr_in sa4;
806#ifdef WITH_IPV6
807 struct sockaddr_in6 sa6;
808#endif
809};
810
811/**
812 * sockaddr length calculation
813 */
814#ifdef WITH_IPV6
815#define SA_LEN(sa) (((sa)->sa_family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6))
816#else
817#define SA_LEN(sa) sizeof(struct sockaddr_in)
818#endif
819
820/**
9319c166
VK
821 * IP address
822 */
823class LIBNETXMS_EXPORTABLE InetAddress
824{
9319c166 825private:
8c75ad41
VK
826 short m_maskBits;
827 short m_family;
828 union
829 {
830 UINT32 v4;
831 BYTE v6[16];
832 } m_addr;
9319c166
VK
833
834public:
8c75ad41
VK
835 InetAddress();
836 InetAddress(UINT32 addr);
837 InetAddress(BYTE *addr);
9319c166 838
8c75ad41
VK
839 bool isAnyLocal() const;
840 bool isLoopback() const;
841 bool isMulticast() const;
842 bool isBroadcast() const;
843 bool isValid() const { return m_family != AF_UNSPEC; }
9319c166 844
8c75ad41 845 int getFamily() const { return m_family; }
c7853753
VK
846 UINT32 getAddressV4() const { return (m_family == AF_INET) ? m_addr.v4 : 0; }
847 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 848
8c75ad41
VK
849 bool contain(const InetAddress &a) const;
850 bool equals(const InetAddress &a) const;
851 int compareTo(const InetAddress &a) const;
9319c166 852
8c75ad41
VK
853 void setMaskBits(int m) { m_maskBits = m; }
854 int getMaskBits() const { return m_maskBits; }
9319c166 855
8c75ad41
VK
856 String toString() const;
857 TCHAR *toString(TCHAR *buffer) const;
9319c166 858
f3b94fc5
VK
859 TCHAR *getHostByAddr(TCHAR *buffer, size_t buflen);
860
c11eee9b
VK
861 struct sockaddr *fillSockAddr(SockAddrBuffer *buffer, UINT16 port = 0);
862
c7853753
VK
863 static InetAddress resolveHostName(const WCHAR *hostname, int af = AF_INET);
864 static InetAddress resolveHostName(const char *hostname, int af = AF_INET);
f3b94fc5
VK
865 static InetAddress parse(const WCHAR *str);
866 static InetAddress parse(const char *str);
8c75ad41 867 static InetAddress createFromSockaddr(struct sockaddr *s);
9319c166
VK
868};
869
870/**
25fe6265
VK
871 * Network connection
872 */
58ee2f43
VK
873class LIBNETXMS_EXPORTABLE SocketConnection
874{
875protected:
876 SOCKET m_socket;
877 char m_data[4096];
878 int m_dataPos;
879
880public:
881 SocketConnection();
882 virtual ~SocketConnection();
883
967893bb
VK
884 bool connectTCP(const TCHAR *hostName, WORD port, UINT32 timeout);
885 bool connectTCP(UINT32 ip, WORD port, UINT32 timeout);
58ee2f43
VK
886 void disconnect();
887
967893bb
VK
888 bool canRead(UINT32 timeout);
889 virtual int read(char *pBuff, int nSize, UINT32 timeout = INFINITE);
58ee2f43 890 bool waitForText(const char *text, int timeout);
cc022855 891
58ee2f43 892 int write(const char *pBuff, int nSize);
1671f85d
VK
893 bool writeLine(const char *line);
894
967893bb 895 static SocketConnection *createTCPConnection(const TCHAR *hostName, WORD port, UINT32 timeout);
58ee2f43
VK
896};
897
030a0779
VK
898/**
899 * Telnet connection - handles all telnet negotiation
900 */
def5b792
AK
901class LIBNETXMS_EXPORTABLE TelnetConnection : public SocketConnection
902{
030a0779 903protected:
967893bb
VK
904 bool connectTCP(const TCHAR *hostName, WORD port, UINT32 timeout);
905 bool connectTCP(UINT32 ip, WORD port, UINT32 timeout);
030a0779 906
def5b792 907public:
967893bb 908 static TelnetConnection *createConnection(const TCHAR *hostName, WORD port, UINT32 timeout);
d4e9d325 909
967893bb
VK
910 bool connect(const TCHAR *hostName, WORD port, UINT32 timeout);
911 bool connect(UINT32 ip, WORD port, UINT32 timeout);
912 virtual int read(char *pBuff, int nSize, UINT32 timeout = INFINITE);
913 int readLine(char *buffer, int size, UINT32 timeout = INFINITE);
def5b792
AK
914};
915
56fa1092
VK
916/**
917 * Postal address representation
918 */
919class LIBNETXMS_EXPORTABLE PostalAddress
920{
921private:
922 TCHAR *m_country;
923 TCHAR *m_city;
924 TCHAR *m_streetAddress;
925 TCHAR *m_postcode;
926
927public:
928 PostalAddress();
929 PostalAddress(const TCHAR *country, const TCHAR *city, const TCHAR *streetAddress, const TCHAR *postcode);
930 ~PostalAddress();
931
932 const TCHAR *getCountry() { return CHECK_NULL_EX(m_country); }
933 const TCHAR *getCity() { return CHECK_NULL_EX(m_city); }
934 const TCHAR *getStreetAddress() { return CHECK_NULL_EX(m_streetAddress); }
935 const TCHAR *getPostCode() { return CHECK_NULL_EX(m_postcode); }
936
937 void setCountry(const TCHAR *country) { safe_free(m_country); m_country = _tcsdup_ex(country); }
938 void setCity(const TCHAR *city) { safe_free(m_city); m_city = _tcsdup_ex(city); }
939 void setStreetAddress(const TCHAR *streetAddress) { safe_free(m_streetAddress); m_streetAddress = _tcsdup_ex(streetAddress); }
940 void setPostCode(const TCHAR *postcode) { safe_free(m_postcode); m_postcode = _tcsdup_ex(postcode); }
941};
942
b160350d
VK
943#endif /* __cplusplus */
944
030a0779
VK
945/**
946 * Configuration item template for configuration loader
947 */
4826c8a5
VK
948typedef struct
949{
e2e66145
VK
950 TCHAR token[64];
951 BYTE type;
952 BYTE separator; // Separator character for lists
953 WORD listElements; // Number of list elements, should be set to 0 before calling NxLoadConfig()
e95680e5 954 UINT64 bufferSize; // Buffer size for strings or flag to be set for CT_BOOLEAN
e2e66145
VK
955 UINT32 bufferPos; // Should be set to 0
956 void *buffer;
957 void *overrideIndicator;
4826c8a5 958} NX_CFG_TEMPLATE;
dcb44c9a 959
030a0779
VK
960/**
961 * Code translation structure
962 */
bc858635
VK
963typedef struct __CODE_TO_TEXT
964{
965 int code;
966 const TCHAR *text;
967} CODE_TO_TEXT;
968
e2e66145
VK
969/**
970 * getopt() prototype if needed
971 */
df9812a9 972#if USE_BUNDLED_GETOPT
99e50bb7 973#include <netxms_getopt.h>
3046f9a4
VK
974#endif
975
976
977//
f2fdf1b5
VK
978// Win32 API functions missing under WinCE
979//
980
c32b805a 981#if defined(UNDER_CE) && defined(__cplusplus)
f2fdf1b5
VK
982
983inline void GetSystemTimeAsFileTime(LPFILETIME pFt)
984{
985 SYSTEMTIME sysTime;
cc022855 986
f2fdf1b5
VK
987 GetSystemTime(&sysTime);
988 SystemTimeToFileTime(&sysTime, pFt);
989}
990
991#endif // UNDER_CE
992
993
994//
3d1cb7d6
VK
995// Structures for opendir() / readdir() / closedir()
996//
997
998#ifdef _WIN32
999
7f9e0c00 1000typedef struct dirent
3d1cb7d6
VK
1001{
1002 long d_ino; /* inode number (not used by MS-DOS) */
1003 int d_namlen; /* Name length */
1004 char d_name[257]; /* file name */
1005} _DIRECT;
1006
1007typedef struct _dir_struc
1008{
1009 char *start; /* Starting position */
1010 char *curr; /* Current position */
1011 long size; /* Size of string table */
1012 long nfiles; /* number if filenames in table */
7f9e0c00 1013 struct dirent dirstr; /* Directory structure to return */
3d1cb7d6
VK
1014} DIR;
1015
5ea2db30
VK
1016#ifdef UNICODE
1017
1018typedef struct dirent_w
1019{
1020 long d_ino; /* inode number (not used by MS-DOS) */
1021 int d_namlen; /* Name length */
1022 WCHAR d_name[257]; /* file name */
1023} _DIRECTW;
1024
1025typedef struct _dir_struc_w
1026{
1027 WCHAR *start; /* Starting position */
1028 WCHAR *curr; /* Current position */
1029 long size; /* Size of string table */
1030 long nfiles; /* number if filenames in table */
1031 struct dirent_w dirstr; /* Directory structure to return */
1032} DIRW;
1033
1034#define _TDIR DIRW
1035#define _TDIRECT _DIRECTW
1036#define _tdirent dirent_w
1037
1038#else
1039
1040#define _TDIR DIR
1041#define _TDIRECT _DIRECT
1042#define _tdirent dirent
1043
37d62364
AK
1044#endif
1045
76b1d3d8
VK
1046#else /* not _WIN32 */
1047
1048typedef struct dirent_w
1049{
1050 long d_ino; /* inode number */
1051 WCHAR d_name[257]; /* file name */
1052} _DIRECTW;
1053
1054typedef struct _dir_struc_w
1055{
1056 DIR *dir; /* Original non-unicode structure */
1057 struct dirent_w dirstr; /* Directory structure to return */
1058} DIRW;
1059
3d1cb7d6
VK
1060#endif /* _WIN32 */
1061
1062
1063//
e9246d26
VK
1064// Functions
1065//
1066
babb8280 1067#if WORDS_BIGENDIAN
43d92b4c
VK
1068#define htonq(x) (x)
1069#define ntohq(x) (x)
9f20696e
VK
1070#define htond(x) (x)
1071#define ntohd(x) (x)
babb8280
VK
1072#define SwapWideString(x)
1073#else
ca6ad6bb
VK
1074#ifdef HAVE_HTONLL
1075#define htonq(x) htonll(x)
1076#else
babb8280 1077#define htonq(x) __bswap_64(x)
ca6ad6bb
VK
1078#endif
1079#ifdef HAVE_NTOHLL
1080#define ntohq(x) ntohll(x)
1081#else
babb8280 1082#define ntohq(x) __bswap_64(x)
ca6ad6bb 1083#endif
babb8280
VK
1084#define htond(x) __bswap_double(x)
1085#define ntohd(x) __bswap_double(x)
1086#define SwapWideString(x) __bswap_wstr(x)
43d92b4c 1087#endif
15929b31 1088
55b33d4c
VK
1089#ifdef UNDER_CE
1090#define close(x) CloseHandle((HANDLE)(x))
1091#endif
1092
b50f1100 1093#ifdef __cplusplus
2e590d1a
VK
1094inline TCHAR *nx_strncpy(TCHAR *pszDest, const TCHAR *pszSrc, size_t nLen)
1095{
912b994d 1096#if defined(_WIN32) && (_MSC_VER >= 1400)
2e590d1a 1097 _tcsncpy_s(pszDest, nLen, pszSrc, _TRUNCATE);
912b994d 1098#else
2e590d1a
VK
1099 _tcsncpy(pszDest, pszSrc, nLen - 1);
1100 pszDest[nLen - 1] = 0;
912b994d 1101#endif
2e590d1a
VK
1102 return pszDest;
1103}
f3387429
VK
1104
1105#ifdef UNICODE
2e590d1a
VK
1106inline char *nx_strncpy_mb(char *pszDest, const char *pszSrc, size_t nLen)
1107{
f3387429 1108#if defined(_WIN32) && (_MSC_VER >= 1400)
2e590d1a 1109 strncpy_s(pszDest, nLen, pszSrc, _TRUNCATE);
f3387429 1110#else
2e590d1a
VK
1111 strncpy(pszDest, pszSrc, nLen - 1);
1112 pszDest[nLen - 1] = 0;
c81979bc 1113#endif
2e590d1a
VK
1114 return pszDest;
1115}
c81979bc 1116#else
f3387429 1117#define nx_strncpy_mb nx_strncpy
7b8b337e
VK
1118#endif
1119
967893bb 1120int LIBNETXMS_EXPORTABLE ConnectEx(SOCKET s, struct sockaddr *addr, int len, UINT32 timeout);
5e60b759
VK
1121int LIBNETXMS_EXPORTABLE SendEx(SOCKET hSocket, const void *data, size_t len, int flags, MUTEX mutex);
1122int LIBNETXMS_EXPORTABLE RecvEx(SOCKET hSocket, void *data, size_t len, int flags, UINT32 timeout);
b0608204 1123#endif /* __cplusplus */
c81979bc
VK
1124
1125#ifdef __cplusplus
e9246d26
VK
1126extern "C"
1127{
b50f1100 1128#endif
735bac5c 1129
c5b523e2 1130#if defined(_WIN32) || !(HAVE_DECL___BSWAP_32)
735bac5c 1131UINT32 LIBNETXMS_EXPORTABLE __bswap_32(UINT32 dwVal);
c5b523e2 1132#endif
f52be742 1133#if defined(_WIN32) || !(HAVE_DECL___BSWAP_64)
735bac5c 1134UINT64 LIBNETXMS_EXPORTABLE __bswap_64(UINT64 qwVal);
64584976 1135#endif
735bac5c
VK
1136double LIBNETXMS_EXPORTABLE __bswap_double(double dVal);
1137void LIBNETXMS_EXPORTABLE __bswap_wstr(UCS2CHAR *pStr);
64584976 1138
076a55c4 1139#if !defined(_WIN32) && !defined(_NETWARE)
8b86c5dc 1140#if defined(UNICODE_UCS2) || defined(UNICODE_UCS4)
735bac5c
VK
1141void LIBNETXMS_EXPORTABLE __wcsupr(WCHAR *in);
1142#define wcsupr __wcsupr
cc022855 1143#endif
735bac5c
VK
1144void LIBNETXMS_EXPORTABLE __strupr(char *in);
1145#define strupr __strupr
7e679c4b 1146#endif
cc022855 1147
735bac5c 1148void LIBNETXMS_EXPORTABLE QSortEx(void *base, size_t nmemb, size_t size, void *arg,
b8a8d064
VK
1149 int (*compare)(const void *, const void *, void *));
1150
735bac5c 1151INT64 LIBNETXMS_EXPORTABLE GetCurrentTimeMs();
d35ed0aa 1152
735bac5c
VK
1153UINT64 LIBNETXMS_EXPORTABLE FileSizeW(const WCHAR *pszFileName);
1154UINT64 LIBNETXMS_EXPORTABLE FileSizeA(const char *pszFileName);
d35ed0aa
VK
1155#ifdef UNICODE
1156#define FileSize FileSizeW
1157#else
1158#define FileSize FileSizeA
1159#endif
670c7f3d 1160
735bac5c
VK
1161int LIBNETXMS_EXPORTABLE BitsInMask(UINT32 dwMask);
1162TCHAR LIBNETXMS_EXPORTABLE *IpToStr(UINT32 dwAddr, TCHAR *szBuffer);
e0f99bf0 1163#ifdef UNICODE
735bac5c 1164char LIBNETXMS_EXPORTABLE *IpToStrA(UINT32 dwAddr, char *szBuffer);
17b35ccc
VK
1165#else
1166#define IpToStrA IpToStr
e0f99bf0 1167#endif
8c75ad41 1168TCHAR LIBNETXMS_EXPORTABLE *Ip6ToStr(const BYTE *addr, TCHAR *buffer);
735bac5c 1169TCHAR LIBNETXMS_EXPORTABLE *SockaddrToStr(struct sockaddr *addr, TCHAR *buffer);
60557d06 1170
735bac5c
VK
1171UINT32 LIBNETXMS_EXPORTABLE ResolveHostNameA(const char *name);
1172UINT32 LIBNETXMS_EXPORTABLE ResolveHostNameW(const WCHAR *name);
08b214c6 1173#ifdef UNICODE
cfe20cce 1174#define ResolveHostName ResolveHostNameW
08b214c6 1175#else
cfe20cce 1176#define ResolveHostName ResolveHostNameA
08b214c6 1177#endif
a1dc75b0 1178
735bac5c
VK
1179void LIBNETXMS_EXPORTABLE *nx_memdup(const void *data, size_t size);
1180void LIBNETXMS_EXPORTABLE nx_memswap(void *block1, void *block2, size_t size);
31521248 1181
735bac5c
VK
1182WCHAR LIBNETXMS_EXPORTABLE *BinToStrW(const BYTE *data, size_t size, WCHAR *pStr);
1183char LIBNETXMS_EXPORTABLE *BinToStrA(const BYTE *data, size_t size, char *pStr);
d7970ee7
VK
1184#ifdef UNICODE
1185#define BinToStr BinToStrW
1186#else
1187#define BinToStr BinToStrA
1188#endif
1189
735bac5c
VK
1190size_t LIBNETXMS_EXPORTABLE StrToBinW(const WCHAR *pStr, BYTE *data, size_t size);
1191size_t LIBNETXMS_EXPORTABLE StrToBinA(const char *pStr, BYTE *data, size_t size);
52db3ed1
VK
1192#ifdef UNICODE
1193#define StrToBin StrToBinW
1194#else
1195#define StrToBin StrToBinA
1196#endif
cc022855 1197
735bac5c 1198TCHAR LIBNETXMS_EXPORTABLE *MACToStr(const BYTE *data, TCHAR *pStr);
b50f1100 1199
735bac5c
VK
1200void LIBNETXMS_EXPORTABLE StrStripA(char *pszStr);
1201void LIBNETXMS_EXPORTABLE StrStripW(WCHAR *pszStr);
b07c50cc
VK
1202#ifdef UNICODE
1203#define StrStrip StrStripW
1204#else
1205#define StrStrip StrStripA
1206#endif
1207
735bac5c
VK
1208const char LIBNETXMS_EXPORTABLE *ExtractWordA(const char *line, char *buffer);
1209const WCHAR LIBNETXMS_EXPORTABLE *ExtractWordW(const WCHAR *line, WCHAR *buffer);
ada97259
VK
1210#ifdef UNICODE
1211#define ExtractWord ExtractWordW
1212#else
1213#define ExtractWord ExtractWordA
1214#endif
1215
735bac5c
VK
1216int LIBNETXMS_EXPORTABLE NumCharsA(const char *pszStr, char ch);
1217int LIBNETXMS_EXPORTABLE NumCharsW(const WCHAR *pszStr, WCHAR ch);
3583a400
VK
1218#ifdef UNICODE
1219#define NumChars NumCharsW
1220#else
1221#define NumChars NumCharsA
1222#endif
ada97259 1223
735bac5c
VK
1224void LIBNETXMS_EXPORTABLE RemoveTrailingCRLFA(char *str);
1225void LIBNETXMS_EXPORTABLE RemoveTrailingCRLFW(WCHAR *str);
35f836fe
VK
1226#ifdef UNICODE
1227#define RemoveTrailingCRLF RemoveTrailingCRLFW
1228#else
1229#define RemoveTrailingCRLF RemoveTrailingCRLFA
1230#endif
1231
4893b4aa
VK
1232BOOL LIBNETXMS_EXPORTABLE RegexpMatchA(const char *str, const char *expr, bool matchCase);
1233BOOL LIBNETXMS_EXPORTABLE RegexpMatchW(const WCHAR *str, const WCHAR *expr, bool matchCase);
cafe592d
VK
1234#ifdef UNICODE
1235#define RegexpMatch RegexpMatchW
1236#else
1237#define RegexpMatch RegexpMatchA
1238#endif
1239
735bac5c 1240const TCHAR LIBNETXMS_EXPORTABLE *ExpandFileName(const TCHAR *name, TCHAR *buffer, size_t bufSize, bool allowShellCommand);
818f8c94 1241TCHAR LIBNETXMS_EXPORTABLE *Trim(TCHAR *str);
735bac5c
VK
1242bool LIBNETXMS_EXPORTABLE MatchString(const TCHAR *pattern, const TCHAR *str, bool matchCase);
1243TCHAR LIBNETXMS_EXPORTABLE **SplitString(const TCHAR *source, TCHAR sep, int *numStrings);
ada97259 1244
f7794b68 1245#ifdef __cplusplus
735bac5c 1246BOOL LIBNETXMS_EXPORTABLE IsValidObjectName(const TCHAR *pszName, BOOL bExtendedChars = FALSE);
f7794b68 1247#endif
735bac5c
VK
1248BOOL LIBNETXMS_EXPORTABLE IsValidScriptName(const TCHAR *pszName);
1249/* deprecated */ void LIBNETXMS_EXPORTABLE TranslateStr(TCHAR *pszString, const TCHAR *pszSubStr, const TCHAR *pszReplace);
1250const TCHAR LIBNETXMS_EXPORTABLE *GetCleanFileName(const TCHAR *pszFileName);
1251void LIBNETXMS_EXPORTABLE GetOSVersionString(TCHAR *pszBuffer, int nBufSize);
1252BYTE LIBNETXMS_EXPORTABLE *LoadFile(const TCHAR *pszFileName, UINT32 *pdwFileSize);
08b214c6 1253#ifdef UNICODE
735bac5c 1254BYTE LIBNETXMS_EXPORTABLE *LoadFileA(const char *pszFileName, UINT32 *pdwFileSize);
08b214c6
VK
1255#else
1256#define LoadFileA LoadFile
1257#endif
1258
735bac5c
VK
1259UINT32 LIBNETXMS_EXPORTABLE CalculateCRC32(const unsigned char *data, UINT32 size, UINT32 dwCRC);
1260void LIBNETXMS_EXPORTABLE CalculateMD5Hash(const unsigned char *data, size_t nbytes, unsigned char *hash);
1261void LIBNETXMS_EXPORTABLE MD5HashForPattern(const unsigned char *data, size_t patternSize, size_t fullSize, BYTE *hash);
1262void LIBNETXMS_EXPORTABLE CalculateSHA1Hash(unsigned char *data, size_t nbytes, unsigned char *hash);
1263void LIBNETXMS_EXPORTABLE SHA1HashForPattern(unsigned char *data, size_t patternSize, size_t fullSize, unsigned char *hash);
1264BOOL LIBNETXMS_EXPORTABLE CalculateFileMD5Hash(const TCHAR *pszFileName, BYTE *pHash);
1265BOOL LIBNETXMS_EXPORTABLE CalculateFileSHA1Hash(const TCHAR *pszFileName, BYTE *pHash);
1266BOOL LIBNETXMS_EXPORTABLE CalculateFileCRC32(const TCHAR *pszFileName, UINT32 *pResult);
66c04cc7 1267
735bac5c
VK
1268void LIBNETXMS_EXPORTABLE ICEEncryptData(const BYTE *in, int inLen, BYTE *out, const BYTE *key);
1269void LIBNETXMS_EXPORTABLE ICEDecryptData(const BYTE *in, int inLen, BYTE *out, const BYTE *key);
4e2debcc 1270
735bac5c 1271BOOL LIBNETXMS_EXPORTABLE DecryptPassword(const TCHAR *login, const TCHAR *encryptedPasswd, TCHAR *decryptedPasswd);
6b1282e7 1272
735bac5c 1273UINT32 LIBNETXMS_EXPORTABLE IcmpPing(UINT32 dwAddr, int iNumRetries, UINT32 dwTimeout, UINT32 *pdwRTT, UINT32 dwPacketSize);
4826c8a5 1274
735bac5c 1275int LIBNETXMS_EXPORTABLE NxDCIDataTypeFromText(const TCHAR *pszText);
aa13cfd9 1276
735bac5c
VK
1277HMODULE LIBNETXMS_EXPORTABLE DLOpen(const TCHAR *pszLibName, TCHAR *pszErrorText);
1278void LIBNETXMS_EXPORTABLE DLClose(HMODULE hModule);
1279void LIBNETXMS_EXPORTABLE *DLGetSymbolAddr(HMODULE hModule, const char *pszSymbol, TCHAR *pszErrorText);
aa13cfd9 1280
735bac5c
VK
1281bool LIBNETXMS_EXPORTABLE ExtractNamedOptionValueW(const WCHAR *optString, const WCHAR *option, WCHAR *buffer, int bufSize);
1282bool LIBNETXMS_EXPORTABLE ExtractNamedOptionValueAsBoolW(const WCHAR *optString, const WCHAR *option, bool defVal);
1283long LIBNETXMS_EXPORTABLE ExtractNamedOptionValueAsIntW(const WCHAR *optString, const WCHAR *option, long defVal);
289d126b 1284
735bac5c
VK
1285bool LIBNETXMS_EXPORTABLE ExtractNamedOptionValueA(const char *optString, const char *option, char *buffer, int bufSize);
1286bool LIBNETXMS_EXPORTABLE ExtractNamedOptionValueAsBoolA(const char *optString, const char *option, bool defVal);
1287long LIBNETXMS_EXPORTABLE ExtractNamedOptionValueAsIntA(const char *optString, const char *option, long defVal);
289d126b
VK
1288
1289#ifdef UNICODE
1290#define ExtractNamedOptionValue ExtractNamedOptionValueW
1291#define ExtractNamedOptionValueAsBool ExtractNamedOptionValueAsBoolW
1292#define ExtractNamedOptionValueAsInt ExtractNamedOptionValueAsIntW
1293#else
1294#define ExtractNamedOptionValue ExtractNamedOptionValueA
1295#define ExtractNamedOptionValueAsBool ExtractNamedOptionValueAsBoolA
1296#define ExtractNamedOptionValueAsInt ExtractNamedOptionValueAsIntA
1297#endif
ae9cddaf 1298
bc858635 1299#ifdef __cplusplus
735bac5c 1300const TCHAR LIBNETXMS_EXPORTABLE *CodeToText(int iCode, CODE_TO_TEXT *pTranslator, const TCHAR *pszDefaultText = _T("Unknown"));
bc858635 1301#else
735bac5c 1302const TCHAR LIBNETXMS_EXPORTABLE *CodeToText(int iCode, CODE_TO_TEXT *pTranslator, const TCHAR *pszDefaultText);
bc858635
VK
1303#endif
1304
aa13cfd9 1305#ifdef _WIN32
735bac5c
VK
1306TCHAR LIBNETXMS_EXPORTABLE *GetSystemErrorText(UINT32 dwError, TCHAR *pszBuffer, size_t iBufSize);
1307BOOL LIBNETXMS_EXPORTABLE GetWindowsVersionString(TCHAR *versionString, int strSize);
1308INT64 LIBNETXMS_EXPORTABLE GetProcessRSS();
aa13cfd9 1309#endif
696fc54f
VK
1310
1311#if !(HAVE_DAEMON)
735bac5c 1312int LIBNETXMS_EXPORTABLE daemon(int nochdir, int noclose);
696fc54f 1313#endif
4332e9d8 1314
735bac5c 1315UINT32 LIBNETXMS_EXPORTABLE inet_addr_w(const WCHAR *pszAddr);
268774a0 1316
4332e9d8 1317#ifndef _WIN32
735bac5c
VK
1318BOOL LIBNETXMS_EXPORTABLE SetDefaultCodepage(const char *cp);
1319int LIBNETXMS_EXPORTABLE WideCharToMultiByte(int iCodePage, UINT32 dwFlags, const WCHAR *pWideCharStr,
1320 int cchWideChar, char *pByteStr, int cchByteChar,
1321 char *pDefaultChar, BOOL *pbUsedDefChar);
1322int LIBNETXMS_EXPORTABLE MultiByteToWideChar(int iCodePage, UINT32 dwFlags, const char *pByteStr,
1323 int cchByteChar, WCHAR *pWideCharStr,
1324 int cchWideChar);
04dbaf62 1325
6b93c954 1326#if !defined(UNICODE_UCS2) || !HAVE_WCSLEN
735bac5c 1327int LIBNETXMS_EXPORTABLE ucs2_strlen(const UCS2CHAR *pStr);
6b93c954
VK
1328#endif
1329#if !defined(UNICODE_UCS2) || !HAVE_WCSNCPY
735bac5c 1330UCS2CHAR LIBNETXMS_EXPORTABLE *ucs2_strncpy(UCS2CHAR *pDst, const UCS2CHAR *pSrc, int nDstLen);
6b93c954
VK
1331#endif
1332#if !defined(UNICODE_UCS2) || !HAVE_WCSDUP
b6ec31bb 1333UCS2CHAR LIBNETXMS_EXPORTABLE *ucs2_strdup(const UCS2CHAR *pStr);
4332e9d8 1334#endif
8b86c5dc 1335
735bac5c
VK
1336size_t LIBNETXMS_EXPORTABLE ucs2_to_mb(const UCS2CHAR *src, int srcLen, char *dst, int dstLen);
1337size_t LIBNETXMS_EXPORTABLE mb_to_ucs2(const char *src, int srcLen, UCS2CHAR *dst, int dstLen);
1338UCS2CHAR LIBNETXMS_EXPORTABLE *UCS2StringFromMBString(const char *pszString);
1339char LIBNETXMS_EXPORTABLE *MBStringFromUCS2String(const UCS2CHAR *pszString);
8b86c5dc 1340
735bac5c
VK
1341int LIBNETXMS_EXPORTABLE nx_wprintf(const WCHAR *format, ...);
1342int LIBNETXMS_EXPORTABLE nx_fwprintf(FILE *fp, const WCHAR *format, ...);
1343int LIBNETXMS_EXPORTABLE nx_swprintf(WCHAR *buffer, size_t size, const WCHAR *format, ...);
1344int LIBNETXMS_EXPORTABLE nx_vwprintf(const WCHAR *format, va_list args);
1345int LIBNETXMS_EXPORTABLE nx_vfwprintf(FILE *fp, const WCHAR *format, va_list args);
1346int LIBNETXMS_EXPORTABLE nx_vswprintf(WCHAR *buffer, size_t size, const WCHAR *format, va_list args);
04dbaf62 1347
735bac5c
VK
1348int LIBNETXMS_EXPORTABLE nx_wscanf(const WCHAR *format, ...);
1349int LIBNETXMS_EXPORTABLE nx_fwscanf(FILE *fp, const WCHAR *format, ...);
1350int LIBNETXMS_EXPORTABLE nx_swscanf(const WCHAR *str, const WCHAR *format, ...);
1351int LIBNETXMS_EXPORTABLE nx_vwscanf(const WCHAR *format, va_list args);
1352int LIBNETXMS_EXPORTABLE nx_vfwscanf(FILE *fp, const WCHAR *format, va_list args);
1353int LIBNETXMS_EXPORTABLE nx_vswscanf(const WCHAR *str, const WCHAR *format, va_list args);
25575d38 1354
3e39fcde 1355#endif /* _WIN32 */
8b86c5dc 1356
3d1058ed 1357#ifdef _WITH_ENCRYPTION
735bac5c 1358WCHAR LIBNETXMS_EXPORTABLE *ERR_error_string_W(int nError, WCHAR *pwszBuffer);
3d1058ed
VK
1359#endif
1360
8b86c5dc 1361#ifdef UNICODE_UCS4
735bac5c
VK
1362size_t LIBNETXMS_EXPORTABLE ucs2_to_ucs4(const UCS2CHAR *src, int srcLen, WCHAR *dst, int dstLen);
1363size_t LIBNETXMS_EXPORTABLE ucs4_to_ucs2(const WCHAR *src, int srcLen, UCS2CHAR *dst, int dstLen);
1364size_t LIBNETXMS_EXPORTABLE ucs2_to_utf8(const UCS2CHAR *src, int srcLen, char *dst, int dstLen);
1365UCS2CHAR LIBNETXMS_EXPORTABLE *UCS2StringFromUCS4String(const WCHAR *pwszString);
1366WCHAR LIBNETXMS_EXPORTABLE *UCS4StringFromUCS2String(const UCS2CHAR *pszString);
b50f1100 1367#endif
8b86c5dc 1368
842c22f4 1369#if !defined(_WIN32) && !HAVE_WSTAT
735bac5c 1370int wstat(const WCHAR *_path, struct stat *_sbuf);
842c22f4
AK
1371#endif
1372
ef856d02 1373#if defined(UNICODE) && !defined(_WIN32)
d9b66a56 1374
f3387429 1375#if !HAVE_WPOPEN
735bac5c 1376FILE LIBNETXMS_EXPORTABLE *wpopen(const WCHAR *_command, const WCHAR *_type);
f3387429 1377#endif
8b86c5dc 1378#if !HAVE_WFOPEN
735bac5c 1379FILE LIBNETXMS_EXPORTABLE *wfopen(const WCHAR *_name, const WCHAR *_type);
8b86c5dc 1380#endif
8c2489aa 1381#if HAVE_FOPEN64 && !HAVE_WFOPEN64
735bac5c 1382FILE LIBNETXMS_EXPORTABLE *wfopen64(const WCHAR *_name, const WCHAR *_type);
8c2489aa 1383#endif
8b86c5dc 1384#if !HAVE_WOPEN
735bac5c 1385int LIBNETXMS_EXPORTABLE wopen(const WCHAR *, int, ...);
b50f1100 1386#endif
f3387429 1387#if !HAVE_WCHMOD
735bac5c 1388int LIBNETXMS_EXPORTABLE wchmod(const WCHAR *_name, int mode);
f3387429 1389#endif
b07c50cc 1390#if !HAVE_WCHDIR
735bac5c 1391int wchdir(const WCHAR *_path);
b07c50cc
VK
1392#endif
1393#if !HAVE_WMKDIR
735bac5c 1394int wmkdir(const WCHAR *_path, int mode);
b07c50cc
VK
1395#endif
1396#if !HAVE_WRMDIR
735bac5c 1397int wrmdir(const WCHAR *_path);
b07c50cc 1398#endif
ccc34207 1399#if !HAVE_WRENAME
735bac5c 1400int wrename(const WCHAR *_oldpath, const WCHAR *_newpath);
ccc34207
VK
1401#endif
1402#if !HAVE_WUNLINK
735bac5c 1403int wunlink(const WCHAR *_path);
ccc34207 1404#endif
b07c50cc 1405#if !HAVE_WREMOVE
735bac5c 1406int wremove(const WCHAR *_path);
b07c50cc
VK
1407#endif
1408#if !HAVE_WSYSTEM
735bac5c 1409int wsystem(const WCHAR *_cmd);
b07c50cc 1410#endif
dda7c270 1411#if !HAVE_WMKSTEMP
735bac5c 1412int wmkstemp(WCHAR *_template);
dda7c270 1413#endif
b07c50cc 1414#if !HAVE_WACCESS
735bac5c 1415int waccess(const WCHAR *_path, int mode);
b07c50cc 1416#endif
273da39a 1417#if !HAVE_WGETENV
735bac5c 1418WCHAR *wgetenv(const WCHAR *_string);
273da39a 1419#endif
f3387429 1420#if !HAVE_WCTIME
735bac5c 1421WCHAR *wctime(const time_t *timep);
f3387429 1422#endif
0186b5da 1423#if !HAVE_PUTWS
735bac5c 1424int putws(const WCHAR *s);
0186b5da 1425#endif
d49d7500 1426#if !HAVE_WCSERROR && HAVE_STRERROR
735bac5c 1427WCHAR *wcserror(int errnum);
d49d7500
VK
1428#endif
1429#if !HAVE_WCSERROR_R && HAVE_STRERROR_R
b0823d06 1430#if HAVE_POSIX_STRERROR_R
735bac5c 1431int wcserror_r(int errnum, WCHAR *strerrbuf, size_t buflen);
b0823d06 1432#else
735bac5c 1433WCHAR *wcserror_r(int errnum, WCHAR *strerrbuf, size_t buflen);
d49d7500 1434#endif
b0823d06 1435#endif
e05f8aaf 1436
ef856d02 1437#endif /* UNICODE && !_WIN32*/
e05f8aaf 1438
8b86c5dc 1439#if !HAVE_STRTOLL
735bac5c 1440INT64 LIBNETXMS_EXPORTABLE strtoll(const char *nptr, char **endptr, int base);
8b86c5dc
VK
1441#endif
1442#if !HAVE_STRTOULL
735bac5c 1443UINT64 LIBNETXMS_EXPORTABLE strtoull(const char *nptr, char **endptr, int base);
8b86c5dc 1444#endif
e05f8aaf
VK
1445
1446#if !HAVE_WCSTOLL
735bac5c 1447INT64 LIBNETXMS_EXPORTABLE wcstoll(const WCHAR *nptr, WCHAR **endptr, int base);
e05f8aaf
VK
1448#endif
1449#if !HAVE_WCSTOULL
735bac5c 1450UINT64 LIBNETXMS_EXPORTABLE wcstoull(const WCHAR *nptr, WCHAR **endptr, int base);
e05f8aaf 1451#endif
b50f1100 1452
2f56be29 1453#if !HAVE_WCSLWR && !defined(_WIN32)
735bac5c 1454WCHAR LIBNETXMS_EXPORTABLE *wcslwr(WCHAR *str);
fdf1ed50
VK
1455#endif
1456
4d978b4a 1457#if !HAVE_WCSCASECMP && !defined(_WIN32)
735bac5c 1458int LIBNETXMS_EXPORTABLE wcscasecmp(const wchar_t *s1, const wchar_t *s2);
4d978b4a
VK
1459#endif
1460
f4d2c9ba 1461#if !HAVE_WCSNCASECMP && !defined(_WIN32)
735bac5c 1462int LIBNETXMS_EXPORTABLE wcsncasecmp(const wchar_t *s1, const wchar_t *s2, size_t n);
f4d2c9ba
VK
1463#endif
1464
3d1cb7d6 1465#ifdef _WIN32
5ea2db30 1466#ifdef UNICODE
735bac5c
VK
1467DIRW LIBNETXMS_EXPORTABLE *wopendir(const WCHAR *filename);
1468struct dirent_w LIBNETXMS_EXPORTABLE *wreaddir(DIRW *dirp);
1469int LIBNETXMS_EXPORTABLE wclosedir(DIRW *dirp);
5ea2db30
VK
1470
1471#define _topendir wopendir
1472#define _treaddir wreaddir
1473#define _tclosedir wclosedir
1474#else
1475#define _topendir opendir
1476#define _treaddir readdir
1477#define _tclosedir closedir
1478#endif
1479
735bac5c
VK
1480DIR LIBNETXMS_EXPORTABLE *opendir(const char *filename);
1481struct dirent LIBNETXMS_EXPORTABLE *readdir(DIR *dirp);
1482int LIBNETXMS_EXPORTABLE closedir(DIR *dirp);
5ea2db30 1483
76b1d3d8
VK
1484#else /* not _WIN32 */
1485
735bac5c
VK
1486DIRW LIBNETXMS_EXPORTABLE *wopendir(const WCHAR *filename);
1487struct dirent_w LIBNETXMS_EXPORTABLE *wreaddir(DIRW *dirp);
1488int LIBNETXMS_EXPORTABLE wclosedir(DIRW *dirp);
76b1d3d8 1489
37d62364 1490#endif
3d1cb7d6 1491
7f9e0c00 1492#if defined(_WIN32) || !(HAVE_SCANDIR)
735bac5c
VK
1493int LIBNETXMS_EXPORTABLE scandir(const char *dir, struct dirent ***namelist,
1494 int (*select)(const struct dirent *),
1495 int (*compar)(const struct dirent **, const struct dirent **));
1496int LIBNETXMS_EXPORTABLE alphasort(const struct dirent **a, const struct dirent **b);
7f9e0c00
VK
1497#endif
1498
3bf0df9f
VK
1499TCHAR LIBNETXMS_EXPORTABLE *safe_fgetts(TCHAR *buffer, int len, FILE *f);
1500
55b33d4c 1501#ifdef UNDER_CE
3bf0df9f
VK
1502int LIBNETXMS_EXPORTABLE _topen(TCHAR *pszName, int nFlags, ...);
1503int LIBNETXMS_EXPORTABLE read(int hFile, void *pBuffer, size_t nBytes);
1504int LIBNETXMS_EXPORTABLE write(int hFile, void *pBuffer, size_t nBytes);
55b33d4c
VK
1505#endif
1506
967893bb 1507BOOL LIBNETXMS_EXPORTABLE nxlog_open(const TCHAR *logName, UINT32 flags, const TCHAR *msgModule,
d49d7500 1508 unsigned int msgCount, const TCHAR **messages);
9f2902ac
VK
1509void LIBNETXMS_EXPORTABLE nxlog_close(void);
1510void LIBNETXMS_EXPORTABLE nxlog_write(DWORD msg, WORD wType, const char *format, ...);
5945d50a 1511BOOL LIBNETXMS_EXPORTABLE nxlog_set_rotation_policy(int rotationMode, int maxLogSize, int historySize, const TCHAR *dailySuffix);
4addc3a3 1512BOOL LIBNETXMS_EXPORTABLE nxlog_rotate();
9113e749
VK
1513
1514typedef void (*NxLogConsoleWriter)(const TCHAR *, ...);
1515void LIBNETXMS_EXPORTABLE nxlog_set_console_writer(NxLogConsoleWriter writer);
f669df41
VK
1516
1517void LIBNETXMS_EXPORTABLE WriteToTerminal(const TCHAR *text);
6e383343
VK
1518void LIBNETXMS_EXPORTABLE WriteToTerminalEx(const TCHAR *format, ...)
1519#if !defined(UNICODE) && (defined(__GNUC__) || defined(__clang__))
1520 __attribute__ ((format(printf, 1, 2)))
1521#endif
1522;
9f2902ac 1523
37a7a862
VK
1524#ifdef _WIN32
1525int LIBNETXMS_EXPORTABLE mkstemp(char *tmpl);
1526int LIBNETXMS_EXPORTABLE wmkstemp(WCHAR *tmpl);
1527#ifdef UNICODE
1528#define _tmkstemp wmkstemp
1529#else
1530#define _tmkstemp mkstemp
1531#endif
1532#endif
1533
9b13553b
VK
1534#ifndef _WIN32
1535int strcat_s(char *dst, size_t dstSize, const char *src);
1536int wcscat_s(WCHAR *dst, size_t dstSize, const WCHAR *src);
1537#endif
1538
c57d020a
VK
1539#if !HAVE_STRPTIME
1540char LIBNETXMS_EXPORTABLE *strptime(const char *buf, const char *fmt, struct tm *_tm);
1541#endif
1542
1543#if !HAVE_TIMEGM
1544time_t LIBNETXMS_EXPORTABLE timegm(struct tm *_tm);
1545#endif
1546
6f95ef89
VK
1547#if !HAVE_INET_PTON
1548int LIBNETXMS_EXPORTABLE nx_inet_pton(int af, const char *src, void *dst);
1549#define inet_pton nx_inet_pton
1550#endif
1551
b50f1100 1552#ifdef __cplusplus
e9246d26 1553}
b50f1100 1554#endif
e9246d26 1555
a7ff20a5
VK
1556
1557//
1558// C++ only finctions
1559//
1560
1561#ifdef __cplusplus
1562
240816b0
VK
1563TCHAR LIBNETXMS_EXPORTABLE *EscapeStringForXML(const TCHAR *str, int length);
1564String LIBNETXMS_EXPORTABLE EscapeStringForXML2(const TCHAR *str, int length = -1);
53c96e2d
VK
1565const char LIBNETXMS_EXPORTABLE *XMLGetAttr(const char **attrs, const char *name);
1566int LIBNETXMS_EXPORTABLE XMLGetAttrInt(const char **attrs, const char *name, int defVal);
967893bb 1567UINT32 LIBNETXMS_EXPORTABLE XMLGetAttrUINT32(const char **attrs, const char *name, UINT32 defVal);
53c96e2d
VK
1568bool LIBNETXMS_EXPORTABLE XMLGetAttrBoolean(const char **attrs, const char *name, bool defVal);
1569
1570#if !defined(_WIN32) && !defined(_NETWARE) && defined(NMS_THREADS_H_INCLUDED)
9113e749 1571void LIBNETXMS_EXPORTABLE StartMainLoop(ThreadFunction pfSignalHandler, ThreadFunction pfMain);
53c96e2d
VK
1572#endif
1573
a7ff20a5
VK
1574#endif
1575
e9246d26 1576#endif /* _nms_util_h_ */