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