2 ** NetXMS - Network Management System
3 ** Copyright (C) 2003-2015 Victor Kirhenshtein
5 ** This program is free software; you can redistribute it and/or modify
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
8 ** (at your option) any later version.
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.
15 ** You should have received a copy of the GNU Lesser General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #ifdef LIBNETXMS_EXPORTS
28 #define LIBNETXMS_EXPORTABLE __declspec(dllexport)
30 #define LIBNETXMS_EXPORTABLE __declspec(dllimport)
33 #define LIBNETXMS_EXPORTABLE
37 #include <nms_common.h>
39 #include <nms_threads.h>
48 /*** Byte swapping ***/
54 #define SwapWideString(x)
57 #define htonq(x) htonll(x)
59 #define htonq(x) __bswap_64(x)
62 #define ntohq(x) ntohll(x)
64 #define ntohq(x) __bswap_64(x)
66 #define htond(x) __bswap_double(x)
67 #define ntohd(x) __bswap_double(x)
68 #define SwapWideString(x) __bswap_wstr(x)
75 #if defined(_WIN32) || !(HAVE_DECL___BSWAP_32)
76 UINT32 LIBNETXMS_EXPORTABLE
__bswap_32(UINT32 dwVal
);
78 #if defined(_WIN32) || !(HAVE_DECL___BSWAP_64)
79 UINT64 LIBNETXMS_EXPORTABLE
__bswap_64(UINT64 qwVal
);
81 double LIBNETXMS_EXPORTABLE
__bswap_double(double dVal
);
82 void LIBNETXMS_EXPORTABLE
__bswap_wstr(UCS2CHAR
*pStr
);
89 /*** Serial communications ***/
93 #define FLOW_SOFTWARE 1
94 #define FLOW_HARDWARE 2
101 # error termios.h not found
107 * Return codes for IcmpPing()
109 #define ICMP_SUCCESS 0
110 #define ICMP_UNREACHEABLE 1
111 #define ICMP_TIMEOUT 2
112 #define ICMP_RAW_SOCK_FAILED 3
113 #define ICMP_API_ERROR 4
116 * Token types for configuration loader
120 #define CT_STRING_LIST 2
121 #define CT_END_OF_LIST 3
125 #define CT_MB_STRING 7
126 #define CT_BOOLEAN64 8
129 * Uninitialized value for override indicator
131 #define NXCONFIG_UNINITIALIZED_VALUE (-1)
134 * Return codes for NxLoadConfig()
136 #define NXCFG_ERR_OK 0
137 #define NXCFG_ERR_NOFILE 1
138 #define NXCFG_ERR_SYNTAX 2
143 #define NXLOG_USE_SYSLOG ((UINT32)0x00000001)
144 #define NXLOG_PRINT_TO_STDOUT ((UINT32)0x00000002)
145 #define NXLOG_BACKGROUND_WRITER ((UINT32)0x00000004)
146 #define NXLOG_DEBUG_MODE ((UINT32)0x00000008)
147 #define NXLOG_IS_OPEN ((UINT32)0x80000000)
150 * nxlog rotation policy
152 #define NXLOG_ROTATION_DISABLED 0
153 #define NXLOG_ROTATION_DAILY 1
154 #define NXLOG_ROTATION_BY_SIZE 2
157 * _tcsdup() replacement
159 #if defined(_WIN32) && defined(USE_WIN32_HEAP)
163 char LIBNETXMS_EXPORTABLE
*nx_strdup(const char *src
);
164 WCHAR LIBNETXMS_EXPORTABLE
*nx_wcsdup(const WCHAR
*src
);
173 #if !HAVE_WCSDUP && !defined(_WIN32)
178 WCHAR LIBNETXMS_EXPORTABLE
*wcsdup(const WCHAR
*src
);
185 // Some AIX versions have broken wcsdup() so we use internal implementation
189 WCHAR LIBNETXMS_EXPORTABLE
*nx_wcsdup(const WCHAR
*src
);
194 #define wcsdup nx_wcsdup
201 * Extended tcsdup: returns NULL if NULL pointer passed
203 inline TCHAR
*_tcsdup_ex(const TCHAR
*s
)
205 return (s
!= NULL
) ? _tcsdup(s
) : NULL
;
211 * String conversion helpers
216 WCHAR LIBNETXMS_EXPORTABLE
*WideStringFromMBString(const char *pszString
);
217 WCHAR LIBNETXMS_EXPORTABLE
*WideStringFromMBStringSysLocale(const char *pszString
);
218 WCHAR LIBNETXMS_EXPORTABLE
*WideStringFromUTF8String(const char *pszString
);
219 char LIBNETXMS_EXPORTABLE
*MBStringFromWideString(const WCHAR
*pwszString
);
220 char LIBNETXMS_EXPORTABLE
*MBStringFromWideStringSysLocale(const WCHAR
*pwszString
);
221 char LIBNETXMS_EXPORTABLE
*UTF8StringFromWideString(const WCHAR
*pwszString
);
227 #define UTF8StringFromTString(s) UTF8StringFromWideString(s)
229 #define UTF8StringFromTString(s) UTF8StringFromMBString(s)
233 * Class for serial communications
254 #ifndef INVALID_HANDLE_VALUE
255 #define INVALID_HANDLE_VALUE (-1)
259 class LIBNETXMS_EXPORTABLE Serial
272 struct termios m_originalSettings
;
281 bool open(const TCHAR
*pszPort
);
283 void setTimeout(int nTimeout
);
284 int read(char *pBuff
, int nSize
); /* waits up to timeout and do single read */
285 int readAll(char *pBuff
, int nSize
); /* read until timeout or out of space */
286 int readToMark(char *buff
, int size
, const char **marks
, char **occurence
);
287 bool write(const char *pBuff
, int nSize
);
289 bool set(int nSpeed
, int nDataBits
, int nParity
, int nStopBits
, int nFlowControl
= FLOW_NONE
);
294 * Dynamic string class
296 class LIBNETXMS_EXPORTABLE String
302 size_t m_allocationStep
;
305 static const int npos
;
308 String(const TCHAR
*init
);
309 String(const String
&src
);
312 TCHAR
*getBuffer() { return m_buffer
; }
313 void setBuffer(TCHAR
*buffer
);
315 size_t getAllocationStep() { return m_allocationStep
; }
316 void setAllocationStep(size_t step
) { m_allocationStep
= step
; }
318 const String
& operator =(const TCHAR
*str
);
319 const String
& operator =(const String
&src
);
320 const String
& operator +=(const TCHAR
*str
);
321 const String
& operator +=(const String
&str
);
322 operator const TCHAR
*() const { return CHECK_NULL_EX(m_buffer
); }
324 char *getUTF8String();
326 void append(const TCHAR
*str
) { if (str
!= NULL
) append(str
, _tcslen(str
)); }
327 void append(const TCHAR
*str
, size_t len
);
328 void append(const TCHAR c
) { append(&c
, 1); }
329 void append(INT32 n
);
330 void append(UINT32 n
);
331 void append(INT64 n
);
332 void append(UINT64 n
);
334 void appendPreallocated(TCHAR
*str
) { if (str
!= NULL
) { append(str
); free(str
); } }
336 void appendMBString(const char *str
, size_t len
, int nCodePage
);
337 void appendWideString(const WCHAR
*str
, size_t len
);
339 void appendFormattedString(const TCHAR
*format
, ...);
340 void appendFormattedStringV(const TCHAR
*format
, va_list args
);
344 size_t length() const { return m_length
; }
345 bool isEmpty() const { return m_length
== 0; }
347 wchar_t charAt(size_t pos
) const { return (pos
< m_length
) ? m_buffer
[pos
] : 0; }
349 TCHAR
*substring(int nStart
, int nLen
, TCHAR
*pszBuffer
= NULL
);
350 int find(const TCHAR
*str
, int nStart
= 0);
352 void escapeCharacter(int ch
, int esc
);
353 void replace(const TCHAR
*pszSrc
, const TCHAR
*pszDst
);
355 void shrink(int chars
= 1);
359 * Abstract iterator class (to be implemented by actual iterable class)
361 class LIBNETXMS_EXPORTABLE AbstractIterator
364 virtual ~AbstractIterator();
366 virtual bool hasNext() = 0;
367 virtual void *next() = 0;
368 virtual void remove() = 0;
372 * Iterator class (public interface for iteration)
374 template <class T
> class Iterator
377 AbstractIterator
*m_worker
;
380 Iterator(AbstractIterator
*worker
) { m_worker
= worker
; }
381 ~Iterator() { delete m_worker
; }
383 bool hasNext() { return m_worker
->hasNext(); }
384 T
*next() { return (T
*)m_worker
->next(); }
385 void remove() { m_worker
->remove(); }
389 * Dynamic array class
391 class LIBNETXMS_EXPORTABLE Array
397 size_t m_elementSize
;
401 void internalRemove(int index
, bool allowDestruction
);
402 void destroyObject(void *object
) { if (object
!= NULL
) m_objectDestructor(object
); }
405 bool m_storePointers
;
406 void (*m_objectDestructor
)(void *);
408 Array(void *data
, int initial
, int grow
, size_t elementSize
);
409 void *__getBuffer() const { return m_data
; }
412 Array(int initial
= 0, int grow
= 16, bool owner
= false);
415 int add(void *element
);
416 void *get(int index
) const { return ((index
>= 0) && (index
< m_size
)) ? (m_storePointers
? m_data
[index
] : (void *)((char *)m_data
+ index
* m_elementSize
)): NULL
; }
417 int indexOf(void *element
) const;
418 void set(int index
, void *element
);
419 void replace(int index
, void *element
);
420 void remove(int index
) { internalRemove(index
, true); }
421 void remove(void *element
) { internalRemove(indexOf(element
), true); }
422 void unlink(int index
) { internalRemove(index
, false); }
423 void unlink(void *element
) { internalRemove(indexOf(element
), false); }
425 void sort(int (*cb
)(const void *, const void *));
426 void *find(const void *key
, int (*cb
)(const void *, const void *)) const;
428 int size() const { return m_size
; }
430 void setOwner(bool owner
) { m_objectOwner
= owner
; }
431 bool isOwner() const { return m_objectOwner
; }
435 * Array iterator class
437 class LIBNETXMS_EXPORTABLE ArrayIterator
: public AbstractIterator
444 ArrayIterator(Array
*array
);
446 virtual bool hasNext();
447 virtual void *next();
448 virtual void remove();
452 * Template class for dynamic array which holds objects
454 template <class T
> class ObjectArray
: public Array
457 static void destructor(void *object
) { delete (T
*)object
; }
460 ObjectArray(int initial
= 0, int grow
= 16, bool owner
= false) : Array(initial
, grow
, owner
) { m_objectDestructor
= destructor
; }
461 virtual ~ObjectArray() { }
463 int add(T
*object
) { return Array::add((void *)object
); }
464 T
*get(int index
) const { return (T
*)Array::get(index
); }
465 int indexOf(T
*object
) const { return Array::indexOf((void *)object
); }
466 bool contains(T
*object
) const { return indexOf(object
) >= 0; }
467 void set(int index
, T
*object
) { Array::set(index
, (void *)object
); }
468 void replace(int index
, T
*object
) { Array::replace(index
, (void *)object
); }
469 void remove(int index
) { Array::remove(index
); }
470 void remove(T
*object
) { Array::remove((void *)object
); }
471 void unlink(int index
) { Array::unlink(index
); }
472 void unlink(T
*object
) { Array::unlink((void *)object
); }
474 Iterator
<T
> *iterator() { return new Iterator
<T
>(new ArrayIterator(this)); }
478 * Template class for dynamic array which holds scalar values
480 template <class T
> class IntegerArray
: public Array
483 static void destructor(void *element
) { }
486 IntegerArray(int initial
= 0, int grow
= 16) : Array(NULL
, initial
, grow
, sizeof(T
)) { m_objectDestructor
= destructor
; m_storePointers
= (sizeof(T
) == sizeof(void *)); }
487 virtual ~IntegerArray() { }
489 int add(T value
) { return Array::add(m_storePointers
? CAST_TO_POINTER(value
, void *) : &value
); }
490 T
get(int index
) const { if (m_storePointers
) return CAST_FROM_POINTER(Array::get(index
), T
); T
*p
= (T
*)Array::get(index
); return (p
!= NULL
) ? *p
: 0; }
491 int indexOf(T value
) const { return Array::indexOf(m_storePointers
? CAST_TO_POINTER(value
, void *) : &value
); }
492 bool contains(T value
) const { return indexOf(value
) >= 0; }
493 void set(int index
, T value
) { Array::set(index
, m_storePointers
? CAST_TO_POINTER(value
, void *) : &value
); }
494 void replace(int index
, T value
) { Array::replace(index
, m_storePointers
? CAST_TO_POINTER(value
, void *) : &value
); }
496 T
*getBuffer() const { return (T
*)__getBuffer(); }
500 * Auxilliary class to hold dynamically allocated array of structures
502 template <class T
> class StructArray
: public Array
505 static void destructor(void *element
) { }
508 StructArray(int initial
= 0, int grow
= 16) : Array(NULL
, initial
, grow
, sizeof(T
)) { m_objectDestructor
= destructor
; }
509 StructArray(T
*data
, int size
) : Array(data
, size
, 16, sizeof(T
)) { m_objectDestructor
= destructor
; }
510 virtual ~StructArray() { }
512 int add(T
*element
) { return Array::add((void *)element
); }
513 T
*get(int index
) const { return (T
*)Array::get(index
); }
514 int indexOf(T
*element
) const { return Array::indexOf((void *)element
); }
515 bool contains(T
*element
) const { return indexOf(element
) >= 0; }
516 void set(int index
, T
*element
) { Array::set(index
, (void *)element
); }
517 void replace(int index
, T
*element
) { Array::replace(index
, (void *)element
); }
518 void remove(int index
) { Array::remove(index
); }
519 void remove(T
*element
) { Array::remove((void *)element
); }
520 void unlink(int index
) { Array::unlink(index
); }
521 void unlink(T
*element
) { Array::unlink((void *)element
); }
523 T
*getBuffer() const { return (T
*)__getBuffer(); }
527 * Entry of string map (internal)
529 struct StringMapEntry
;
541 * String maps base class
543 class LIBNETXMS_EXPORTABLE StringMapBase
546 StringMapEntry
*m_data
;
549 void (*m_objectDestructor
)(void *);
551 StringMapEntry
*find(const TCHAR
*key
) const;
552 void setObject(TCHAR
*key
, void *value
, bool keyPreAlloc
);
553 void *getObject(const TCHAR
*key
) const;
554 void destroyObject(void *object
) { if (object
!= NULL
) m_objectDestructor(object
); }
557 StringMapBase(bool objectOwner
);
558 virtual ~StringMapBase();
560 void setOwner(bool owner
) { m_objectOwner
= owner
; }
561 void setIgnoreCase(bool ignore
);
563 void remove(const TCHAR
*key
);
565 void filterElements(bool (*filter
)(const TCHAR
*, const void *, void *), void *userData
);
568 bool contains(const TCHAR
*key
) const { return find(key
) != NULL
; }
570 EnumerationCallbackResult
forEach(EnumerationCallbackResult (*cb
)(const TCHAR
*, const void *, void *), void *userData
) const;
571 const void *findElement(bool (*comparator
)(const TCHAR
*, const void *, void *), void *userData
) const;
573 StructArray
<KeyValuePair
> *toArray() const;
574 StringList
*keys() const;
585 class LIBNETXMS_EXPORTABLE StringMap
: public StringMapBase
588 StringMap() : StringMapBase(true) { }
589 StringMap(const StringMap
&src
);
590 virtual ~StringMap();
592 StringMap
& operator =(const StringMap
&src
);
594 void set(const TCHAR
*key
, const TCHAR
*value
) { setObject((TCHAR
*)key
, _tcsdup(value
), false); }
595 void setPreallocated(TCHAR
*key
, TCHAR
*value
) { setObject(key
, value
, true); }
596 void set(const TCHAR
*key
, UINT32 value
);
598 void addAll(StringMap
*src
);
600 const TCHAR
*get(const TCHAR
*key
) const { return (const TCHAR
*)getObject(key
); }
601 INT32
getInt32(const TCHAR
*key
, INT32 defaultValue
) const;
602 UINT32
getUInt32(const TCHAR
*key
, UINT32 defaultValue
) const;
603 INT64
getInt64(const TCHAR
*key
, INT64 defaultValue
) const;
604 UINT64
getUInt64(const TCHAR
*key
, UINT64 defaultValue
) const;
605 double getDouble(const TCHAR
*key
, double defaultValue
) const;
606 bool getBoolean(const TCHAR
*key
, bool defaultValue
) const;
608 void fillMessage(NXCPMessage
*msg
, UINT32 sizeFieldId
, UINT32 baseFieldId
) const;
609 void loadMessage(const NXCPMessage
*msg
, UINT32 sizeFieldId
, UINT32 baseFieldId
);
613 * String map template for holding objects as values
615 template <class T
> class StringObjectMap
: public StringMapBase
618 static void destructor(void *object
) { delete (T
*)object
; }
621 StringObjectMap(bool objectOwner
) : StringMapBase(objectOwner
) { m_objectDestructor
= destructor
; }
623 void set(const TCHAR
*key
, T
*object
) { setObject((TCHAR
*)key
, (void *)object
, false); }
624 void setPreallocated(TCHAR
*key
, T
*object
) { setObject((TCHAR
*)key
, (void *)object
, true); }
625 T
*get(const TCHAR
*key
) const { return (T
*)getObject(key
); }
631 class LIBNETXMS_EXPORTABLE StringList
640 StringList(const StringList
*src
);
641 StringList(const TCHAR
*src
, const TCHAR
*separator
);
644 void add(const TCHAR
*value
);
645 void addPreallocated(TCHAR
*value
);
646 void add(INT32 value
);
647 void add(UINT32 value
);
648 void add(INT64 value
);
649 void add(UINT64 value
);
650 void add(double value
);
651 void replace(int index
, const TCHAR
*value
);
652 void addOrReplace(int index
, const TCHAR
*value
);
653 void addOrReplacePreallocated(int index
, TCHAR
*value
);
655 void addMBString(const char *value
) { addPreallocated(WideStringFromMBString(value
)); }
657 void addMBString(const char *value
) { add(value
); }
660 int size() const { return m_count
; }
661 const TCHAR
*get(int index
) const { return ((index
>=0) && (index
< m_count
)) ? m_values
[index
] : NULL
; }
662 int indexOf(const TCHAR
*value
) const;
663 int indexOfIgnoreCase(const TCHAR
*value
) const;
664 void remove(int index
);
665 void addAll(const StringList
*src
);
666 void merge(const StringList
*src
, bool matchCase
);
667 TCHAR
*join(const TCHAR
*separator
);
668 void splitAndAdd(const TCHAR
*src
, const TCHAR
*separator
);
669 void sort(bool ascending
= true, bool caseSensitive
= false);
670 void fillMessage(NXCPMessage
*msg
, UINT32 baseId
, UINT32 countId
);
674 * Entry of string set
676 struct StringSetEntry
;
689 * String set iterator
691 class LIBNETXMS_EXPORTABLE StringSetIterator
: public AbstractIterator
694 StringSet
*m_stringSet
;
695 StringSetEntry
*m_curr
;
696 StringSetEntry
*m_next
;
699 StringSetIterator(StringSet
*stringSet
);
701 virtual bool hasNext();
702 virtual void *next();
703 virtual void remove();
709 class LIBNETXMS_EXPORTABLE StringSet
711 friend class StringSetIterator
;
714 StringSetEntry
*m_data
;
720 void add(const TCHAR
*str
);
721 void addPreallocated(TCHAR
*str
);
722 void remove(const TCHAR
*str
);
726 bool contains(const TCHAR
*str
) const;
727 bool equals(const StringSet
*s
) const;
729 void addAll(StringSet
*src
);
730 void addAll(TCHAR
**strings
, int count
);
731 void splitAndAdd(const TCHAR
*src
, const TCHAR
*separator
);
732 void addAllPreallocated(TCHAR
**strings
, int count
);
734 void forEach(bool (*cb
)(const TCHAR
*, void *), void *userData
) const;
736 void fillMessage(NXCPMessage
*msg
, UINT32 baseId
, UINT32 countId
) const;
737 void addAllFromMessage(const NXCPMessage
*msg
, UINT32 baseId
, UINT32 countId
, bool clearBeforeAdd
, bool toUppercase
);
739 String
join(const TCHAR
*separator
);
741 Iterator
<const TCHAR
> *iterator() { return new Iterator
<const TCHAR
>(new StringSetIterator(this)); }
745 * Opaque hash map entry structure
750 * Hash map base class (for fixed size non-pointer keys)
752 class LIBNETXMS_EXPORTABLE HashMapBase
754 friend class HashMapIterator
;
757 HashMapEntry
*m_data
;
759 unsigned int m_keylen
;
761 HashMapEntry
*find(const void *key
) const;
762 void destroyObject(void *object
) { if (object
!= NULL
) m_objectDestructor(object
); }
765 void (*m_objectDestructor
)(void *);
767 HashMapBase(bool objectOwner
, unsigned int keylen
);
769 void *_get(const void *key
) const;
770 void _set(const void *key
, void *value
);
771 void _remove(const void *key
);
773 bool _contains(const void *key
) const { return find(key
) != NULL
; }
776 virtual ~HashMapBase();
778 void setOwner(bool owner
) { m_objectOwner
= owner
; }
783 EnumerationCallbackResult
forEach(EnumerationCallbackResult (*cb
)(const void *, const void *, void *), void *userData
) const;
784 const void *findElement(bool (*comparator
)(const void *, const void *, void *), void *userData
) const;
790 class LIBNETXMS_EXPORTABLE HashMapIterator
: public AbstractIterator
793 HashMapBase
*m_hashMap
;
794 HashMapEntry
*m_curr
;
795 HashMapEntry
*m_next
;
798 HashMapIterator(HashMapBase
*hashMap
);
800 virtual bool hasNext();
801 virtual void *next();
802 virtual void remove();
806 * Hash map template for holding objects as values
808 template <class K
, class V
> class HashMap
: public HashMapBase
811 static void destructor(void *object
) { delete (V
*)object
; }
814 HashMap(bool objectOwner
= false) : HashMapBase(objectOwner
, sizeof(K
)) { m_objectDestructor
= destructor
; }
816 V
*get(const K
& key
) { return (V
*)_get(&key
); }
817 void set(const K
& key
, V
*value
) { _set(&key
, (void *)value
); }
818 void remove(const K
& key
) { _remove(&key
); }
819 bool contains(const K
& key
) { return _contains(&key
); }
821 Iterator
<V
> *iterator() { return new Iterator
<V
>(new HashMapIterator(this)); }
825 * Hash map template for holding reference counting objects as values
827 template <class K
, class V
> class RefCountHashMap
: public HashMapBase
830 static void destructor(void *object
) { if (object
!= NULL
) ((V
*)object
)->decRefCount(); }
833 RefCountHashMap(bool objectOwner
= false) : HashMapBase(objectOwner
, sizeof(K
)) { m_objectDestructor
= destructor
; }
835 V
*get(const K
& key
) { V
*v
= (V
*)_get(&key
); if (v
!= NULL
) v
->incRefCount(); return v
; }
836 void set(const K
& key
, V
*value
) { if (value
!= NULL
) value
->incRefCount(); _set(&key
, (void *)value
); }
837 void remove(const K
& key
) { _remove(&key
); }
838 bool contains(const K
& key
) { return _contains(&key
); }
840 Iterator
<V
> *iterator() { return new Iterator
<V
>(new HashMapIterator(this)); }
846 class LIBNETXMS_EXPORTABLE ByteStream
853 size_t m_allocationStep
;
856 ByteStream(size_t initial
= 8192);
857 ByteStream(const void *data
, size_t size
);
858 virtual ~ByteStream();
860 static ByteStream
*load(const TCHAR
*file
);
862 void seek(size_t pos
) { if (pos
<= m_size
) m_pos
= pos
; }
863 size_t pos() { return m_pos
; }
864 size_t size() { return m_size
; }
865 bool eos() { return m_pos
== m_size
; }
867 void setAllocationStep(size_t s
) { m_allocationStep
= s
; }
869 const BYTE
*buffer(size_t *size
) { *size
= m_size
; return m_data
; }
871 void write(const void *data
, size_t size
);
872 void write(char c
) { write(&c
, 1); }
873 void write(BYTE b
) { write(&b
, 1); }
874 void write(INT16 n
) { UINT16 x
= htons((UINT16
)n
); write(&x
, 2); }
875 void write(UINT16 n
) { UINT16 x
= htons(n
); write(&x
, 2); }
876 void write(INT32 n
) { UINT32 x
= htonl((UINT32
)n
); write(&x
, 4); }
877 void write(UINT32 n
) { UINT32 x
= htonl(n
); write(&x
, 4); }
878 void write(INT64 n
) { UINT64 x
= htonq((UINT64
)n
); write(&x
, 8); }
879 void write(UINT64 n
) { UINT64 x
= htonq(n
); write(&x
, 8); }
880 void write(double n
) { double x
= htond(n
); write(&x
, 8); }
881 void writeString(const TCHAR
*s
);
883 size_t read(void *buffer
, size_t count
);
884 char readChar() { return !eos() ? (char)m_data
[m_pos
++] : 0; }
885 BYTE
readByte() { return !eos() ? m_data
[m_pos
++] : 0; }
899 * Auxilliary class for objects which counts references and
900 * destroys itself wheren reference count falls to 0
902 class LIBNETXMS_EXPORTABLE RefCountObject
905 VolatileCounter m_refCount
;
908 virtual ~RefCountObject();
918 InterlockedIncrement(&m_refCount
);
923 if (InterlockedDecrement(&m_refCount
) == 0)
931 * Table column definition
933 class LIBNETXMS_EXPORTABLE TableColumnDefinition
937 TCHAR
*m_displayName
;
939 bool m_instanceColumn
;
942 TableColumnDefinition(const TCHAR
*name
, const TCHAR
*displayName
, INT32 dataType
, bool isInstance
);
943 TableColumnDefinition(NXCPMessage
*msg
, UINT32 baseId
);
944 TableColumnDefinition(TableColumnDefinition
*src
);
945 ~TableColumnDefinition();
947 void fillMessage(NXCPMessage
*msg
, UINT32 baseId
);
949 const TCHAR
*getName() { return m_name
; }
950 const TCHAR
*getDisplayName() { return m_displayName
; }
951 INT32
getDataType() { return m_dataType
; }
952 bool isInstanceColumn() { return m_instanceColumn
; }
954 void setDataType(INT32 type
) { m_dataType
= type
; }
955 void setInstanceColumn(bool isInstance
) { m_instanceColumn
= isInstance
; }
956 void setDisplayName(const TCHAR
*name
) { safe_free(m_displayName
); m_displayName
= _tcsdup(CHECK_NULL_EX(name
)); }
970 TableCell() { m_value
= NULL
; m_status
= -1; m_objectId
= 0; }
971 TableCell(const TCHAR
*value
) { m_value
= _tcsdup_ex(value
); m_status
= -1; m_objectId
= 0; }
972 TableCell(const TCHAR
*value
, int status
) { m_value
= _tcsdup_ex(value
); m_status
= status
; m_objectId
= 0; }
973 TableCell(TableCell
*src
) { m_value
= _tcsdup_ex(src
->m_value
); m_status
= src
->m_status
; m_objectId
= src
->m_objectId
; }
974 ~TableCell() { safe_free(m_value
); }
976 void set(const TCHAR
*value
, int status
, UINT32 objectId
) { safe_free(m_value
); m_value
= _tcsdup_ex(value
); m_status
= status
; m_objectId
= objectId
; }
977 void setPreallocated(TCHAR
*value
, int status
, UINT32 objectId
) { safe_free(m_value
); m_value
= value
; m_status
= status
; m_objectId
= objectId
; }
979 const TCHAR
*getValue() { return m_value
; }
980 void setValue(const TCHAR
*value
) { safe_free(m_value
); m_value
= _tcsdup_ex(value
); }
981 void setPreallocatedValue(TCHAR
*value
) { free(m_value
); m_value
= value
; }
983 int getStatus() { return m_status
; }
984 void setStatus(int status
) { m_status
= status
; }
986 int getObjectId() { return m_objectId
; }
987 void setObjectId(UINT32 id
) { m_objectId
= id
; }
996 ObjectArray
<TableCell
> *m_cells
;
1000 TableRow(int columnCount
);
1001 TableRow(TableRow
*src
);
1002 ~TableRow() { delete m_cells
; }
1004 void addColumn() { m_cells
->add(new TableCell
); }
1005 void deleteColumn(int index
) { m_cells
->remove(index
); }
1007 void set(int index
, const TCHAR
*value
, int status
, UINT32 objectId
) { TableCell
*c
= m_cells
->get(index
); if (c
!= NULL
) c
->set(value
, status
, objectId
); }
1008 void setPreallocated(int index
, TCHAR
*value
, int status
, UINT32 objectId
) { TableCell
*c
= m_cells
->get(index
); if (c
!= NULL
) c
->setPreallocated(value
, status
, objectId
); }
1010 void setValue(int index
, const TCHAR
*value
) { TableCell
*c
= m_cells
->get(index
); if (c
!= NULL
) c
->setValue(value
); }
1011 void setPreallocatedValue(int index
, TCHAR
*value
) { TableCell
*c
= m_cells
->get(index
); if (c
!= NULL
) c
->setPreallocatedValue(value
); else free(value
); }
1013 void setStatus(int index
, int status
) { TableCell
*c
= m_cells
->get(index
); if (c
!= NULL
) c
->setStatus(status
); }
1015 const TCHAR
*getValue(int index
) { TableCell
*c
= m_cells
->get(index
); return (c
!= NULL
) ? c
->getValue() : NULL
; }
1016 int getStatus(int index
) { TableCell
*c
= m_cells
->get(index
); return (c
!= NULL
) ? c
->getStatus() : -1; }
1018 UINT32
getObjectId() { return m_objectId
; }
1019 void setObjectId(UINT32 id
) { m_objectId
= id
; }
1021 UINT32
getCellObjectId(int index
) { TableCell
*c
= m_cells
->get(index
); return (c
!= NULL
) ? c
->getObjectId() : 0; }
1022 void setCellObjectId(int index
, UINT32 id
) { TableCell
*c
= m_cells
->get(index
); if (c
!= NULL
) c
->setObjectId(id
); }
1026 * Class for table data storage
1028 class LIBNETXMS_EXPORTABLE Table
: public RefCountObject
1031 ObjectArray
<TableRow
> *m_data
;
1032 ObjectArray
<TableColumnDefinition
> *m_columns
;
1035 bool m_extendedFormat
;
1037 void createFromMessage(NXCPMessage
*msg
);
1039 bool parseXML(const char *xml
);
1044 Table(NXCPMessage
*msg
);
1047 int fillMessage(NXCPMessage
&msg
, int offset
, int rowLimit
);
1048 void updateFromMessage(NXCPMessage
*msg
);
1050 void addAll(Table
*src
);
1051 void copyRow(Table
*src
, int row
);
1053 int getNumRows() { return m_data
->size(); }
1054 int getNumColumns() { return m_columns
->size(); }
1055 const TCHAR
*getTitle() { return CHECK_NULL_EX(m_title
); }
1056 int getSource() { return m_source
; }
1058 bool isExtendedFormat() { return m_extendedFormat
; }
1059 void setExtendedFormat(bool ext
) { m_extendedFormat
= ext
; }
1061 const TCHAR
*getColumnName(int col
) { return ((col
>= 0) && (col
< m_columns
->size())) ? m_columns
->get(col
)->getName() : NULL
; }
1062 INT32
getColumnDataType(int col
) { return ((col
>= 0) && (col
< m_columns
->size())) ? m_columns
->get(col
)->getDataType() : 0; }
1063 int getColumnIndex(const TCHAR
*name
);
1064 ObjectArray
<TableColumnDefinition
> *getColumnDefinitions() { return m_columns
; }
1066 void setTitle(const TCHAR
*title
) { safe_free(m_title
); m_title
= _tcsdup_ex(title
); }
1067 void setSource(int source
) { m_source
= source
; }
1068 int addColumn(const TCHAR
*name
, INT32 dataType
= 0, const TCHAR
*displayName
= NULL
, bool isInstance
= false);
1069 void setColumnDataType(int col
, INT32 dataType
) { if ((col
>= 0) && (col
< m_columns
->size())) m_columns
->get(col
)->setDataType(dataType
); }
1072 void deleteRow(int row
);
1073 void deleteColumn(int col
);
1075 void setAt(int nRow
, int nCol
, INT32 nData
);
1076 void setAt(int nRow
, int nCol
, UINT32 dwData
);
1077 void setAt(int nRow
, int nCol
, double dData
);
1078 void setAt(int nRow
, int nCol
, INT64 nData
);
1079 void setAt(int nRow
, int nCol
, UINT64 qwData
);
1080 void setAt(int nRow
, int nCol
, const TCHAR
*pszData
);
1081 void setPreallocatedAt(int nRow
, int nCol
, TCHAR
*pszData
);
1083 void set(int nCol
, INT32 nData
) { setAt(getNumRows() - 1, nCol
, nData
); }
1084 void set(int nCol
, UINT32 dwData
) { setAt(getNumRows() - 1, nCol
, dwData
); }
1085 void set(int nCol
, double dData
) { setAt(getNumRows() - 1, nCol
, dData
); }
1086 void set(int nCol
, INT64 nData
) { setAt(getNumRows() - 1, nCol
, nData
); }
1087 void set(int nCol
, UINT64 qwData
) { setAt(getNumRows() - 1, nCol
, qwData
); }
1088 void set(int nCol
, const TCHAR
*data
) { setAt(getNumRows() - 1, nCol
, data
); }
1090 void set(int nCol
, const char *data
) { setPreallocatedAt(getNumRows() - 1, nCol
, WideStringFromMBString(data
)); }
1092 void set(int nCol
, const WCHAR
*data
) { setPreallocatedAt(getNumRows() - 1, nCol
, MBStringFromWideString(data
)); }
1094 void setPreallocated(int nCol
, TCHAR
*data
) { setPreallocatedAt(getNumRows() - 1, nCol
, data
); }
1096 void setStatusAt(int row
, int col
, int status
);
1097 void setStatus(int col
, int status
) { setStatusAt(getNumRows() - 1, col
, status
); }
1099 const TCHAR
*getAsString(int nRow
, int nCol
);
1100 INT32
getAsInt(int nRow
, int nCol
);
1101 UINT32
getAsUInt(int nRow
, int nCol
);
1102 INT64
getAsInt64(int nRow
, int nCol
);
1103 UINT64
getAsUInt64(int nRow
, int nCol
);
1104 double getAsDouble(int nRow
, int nCol
);
1106 int getStatus(int nRow
, int nCol
);
1108 void buildInstanceString(int row
, TCHAR
*buffer
, size_t bufLen
);
1109 int findRowByInstance(const TCHAR
*instance
);
1111 UINT32
getObjectId(int row
) { TableRow
*r
= m_data
->get(row
); return (r
!= NULL
) ? r
->getObjectId() : 0; }
1112 void setObjectId(int row
, UINT32 id
) { TableRow
*r
= m_data
->get(row
); if (r
!= NULL
) r
->setObjectId(id
); }
1114 void setCellObjectIdAt(int row
, int col
, UINT32 objectId
);
1115 void setCellObjectId(int col
, UINT32 objectId
) { setCellObjectIdAt(getNumRows() - 1, col
, objectId
); }
1116 UINT32
getCellObjectId(int row
, int col
) { TableRow
*r
= m_data
->get(row
); return (r
!= NULL
) ? r
->getCellObjectId(col
) : 0; }
1118 static Table
*createFromXML(const char *xml
);
1125 union SockAddrBuffer
1127 struct sockaddr_in sa4
;
1129 struct sockaddr_in6 sa6
;
1134 * sockaddr length calculation
1137 #define SA_LEN(sa) (((sa)->sa_family == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6))
1139 #define SA_LEN(sa) sizeof(struct sockaddr_in)
1143 * Get port number from SockAddrBuffer
1146 #define SA_PORT(sa) ((((struct sockaddr *)sa)->sa_family == AF_INET) ? ((struct sockaddr_in *)sa)->sin_port : ((struct sockaddr_in6 *)sa)->sin6_port)
1148 #define SA_PORT(sa) (((struct sockaddr_in *)sa)->sin_port)
1152 * Compare addresses in sockaddr
1154 inline bool SocketAddressEquals(struct sockaddr
*a1
, struct sockaddr
*a2
)
1156 if (a1
->sa_family
!= a2
->sa_family
)
1158 if (a1
->sa_family
== AF_INET
)
1159 return ((struct sockaddr_in
*)a1
)->sin_addr
.s_addr
== ((struct sockaddr_in
*)a2
)->sin_addr
.s_addr
;
1161 if (a1
->sa_family
== AF_INET6
)
1162 return !memcmp(((struct sockaddr_in6
*)a1
)->sin6_addr
.s6_addr
, ((struct sockaddr_in6
*)a2
)->sin6_addr
.s6_addr
, 16);
1170 class LIBNETXMS_EXPORTABLE InetAddress
1183 InetAddress(UINT32 addr
);
1184 InetAddress(UINT32 addr
, UINT32 mask
);
1185 InetAddress(const BYTE
*addr
, int maskBits
= 128);
1187 bool isAnyLocal() const;
1188 bool isLoopback() const;
1189 bool isMulticast() const;
1190 bool isBroadcast() const;
1191 bool isLinkLocal() const;
1192 bool isValid() const { return m_family
!= AF_UNSPEC
; }
1193 bool isValidUnicast() const { return isValid() && !isAnyLocal() && !isLoopback() && !isMulticast() && !isBroadcast() && !isLinkLocal(); }
1195 int getFamily() const { return m_family
; }
1196 UINT32
getAddressV4() const { return (m_family
== AF_INET
) ? m_addr
.v4
: 0; }
1197 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"; }
1199 bool contain(const InetAddress
&a
) const;
1200 bool sameSubnet(const InetAddress
&a
) const;
1201 bool equals(const InetAddress
&a
) const;
1202 int compareTo(const InetAddress
&a
) const;
1204 void setMaskBits(int m
) { m_maskBits
= m
; }
1205 int getMaskBits() const { return m_maskBits
; }
1206 int getHostBits() const { return (m_family
== AF_INET
) ? (32 - m_maskBits
) : (128 - m_maskBits
); }
1208 InetAddress
getSubnetAddress() const;
1209 InetAddress
getSubnetBroadcast() const;
1210 bool isSubnetBroadcast(int maskBits
) const;
1212 String
toString() const;
1213 TCHAR
*toString(TCHAR
*buffer
) const;
1215 char *toStringA(char *buffer
) const;
1217 char *toStringA(char *buffer
) const { return toString(buffer
); }
1220 BYTE
*buildHashKey(BYTE
*key
) const;
1222 TCHAR
*getHostByAddr(TCHAR
*buffer
, size_t buflen
) const;
1224 struct sockaddr
*fillSockAddr(SockAddrBuffer
*buffer
, UINT16 port
= 0) const;
1226 static InetAddress
resolveHostName(const WCHAR
*hostname
, int af
= AF_INET
);
1227 static InetAddress
resolveHostName(const char *hostname
, int af
= AF_INET
);
1228 static InetAddress
parse(const WCHAR
*str
);
1229 static InetAddress
parse(const char *str
);
1230 static InetAddress
createFromSockaddr(struct sockaddr
*s
);
1232 static const InetAddress INVALID
;
1233 static const InetAddress LOOPBACK
;
1239 class LIBNETXMS_EXPORTABLE InetAddressList
1242 ObjectArray
<InetAddress
> *m_list
;
1244 int indexOf(const InetAddress
& addr
) const;
1250 void add(const InetAddress
& addr
);
1251 void add(const InetAddressList
& addrList
);
1252 void replace(const InetAddress
& addr
);
1253 void remove(const InetAddress
& addr
);
1254 void clear() { m_list
->clear(); }
1255 const InetAddress
& get(int index
) const { const InetAddress
*a
= m_list
->get(index
); return (a
!= NULL
) ? *a
: InetAddress::INVALID
; }
1257 int size() const { return m_list
->size(); }
1258 bool hasAddress(const InetAddress
& addr
) const { return indexOf(addr
) != -1; }
1259 const InetAddress
& findAddress(const InetAddress
& addr
) const { int idx
= indexOf(addr
); return (idx
!= -1) ? *m_list
->get(idx
) : InetAddress::INVALID
; }
1260 const InetAddress
& findSameSubnetAddress(const InetAddress
& addr
) const;
1261 const InetAddress
& getFirstUnicastAddress() const;
1262 const InetAddress
& getFirstUnicastAddressV4() const;
1263 bool hasValidUnicastAddress() const { return getFirstUnicastAddress().isValid(); }
1264 bool isLoopbackOnly() const;
1266 const ObjectArray
<InetAddress
> *getList() const { return m_list
; }
1268 void fillMessage(NXCPMessage
*msg
, UINT32 sizeFieldId
, UINT32 baseFieldId
) const;
1272 * Network connection
1274 class LIBNETXMS_EXPORTABLE SocketConnection
1283 virtual ~SocketConnection();
1285 bool connectTCP(const TCHAR
*hostName
, WORD port
, UINT32 timeout
);
1286 bool connectTCP(UINT32 ip
, WORD port
, UINT32 timeout
);
1289 bool canRead(UINT32 timeout
);
1290 virtual int read(char *pBuff
, int nSize
, UINT32 timeout
= INFINITE
);
1291 bool waitForText(const char *text
, int timeout
);
1293 int write(const char *pBuff
, int nSize
);
1294 bool writeLine(const char *line
);
1296 static SocketConnection
*createTCPConnection(const TCHAR
*hostName
, WORD port
, UINT32 timeout
);
1300 * Telnet connection - handles all telnet negotiation
1302 class LIBNETXMS_EXPORTABLE TelnetConnection
: public SocketConnection
1305 bool connectTCP(const TCHAR
*hostName
, WORD port
, UINT32 timeout
);
1306 bool connectTCP(UINT32 ip
, WORD port
, UINT32 timeout
);
1309 static TelnetConnection
*createConnection(const TCHAR
*hostName
, WORD port
, UINT32 timeout
);
1311 bool connect(const TCHAR
*hostName
, WORD port
, UINT32 timeout
);
1312 bool connect(UINT32 ip
, WORD port
, UINT32 timeout
);
1313 virtual int read(char *pBuff
, int nSize
, UINT32 timeout
= INFINITE
);
1314 int readLine(char *buffer
, int size
, UINT32 timeout
= INFINITE
);
1318 * Postal address representation
1320 class LIBNETXMS_EXPORTABLE PostalAddress
1325 TCHAR
*m_streetAddress
;
1330 PostalAddress(const TCHAR
*country
, const TCHAR
*city
, const TCHAR
*streetAddress
, const TCHAR
*postcode
);
1333 const TCHAR
*getCountry() const { return CHECK_NULL_EX(m_country
); }
1334 const TCHAR
*getCity() const { return CHECK_NULL_EX(m_city
); }
1335 const TCHAR
*getStreetAddress() const { return CHECK_NULL_EX(m_streetAddress
); }
1336 const TCHAR
*getPostCode() const { return CHECK_NULL_EX(m_postcode
); }
1338 void setCountry(const TCHAR
*country
) { safe_free(m_country
); m_country
= _tcsdup_ex(country
); }
1339 void setCity(const TCHAR
*city
) { safe_free(m_city
); m_city
= _tcsdup_ex(city
); }
1340 void setStreetAddress(const TCHAR
*streetAddress
) { safe_free(m_streetAddress
); m_streetAddress
= _tcsdup_ex(streetAddress
); }
1341 void setPostCode(const TCHAR
*postcode
) { safe_free(m_postcode
); m_postcode
= _tcsdup_ex(postcode
); }
1344 #endif /* __cplusplus */
1347 * Configuration item template for configuration loader
1353 BYTE separator
; // Separator character for lists
1354 WORD listElements
; // Number of list elements, should be set to 0 before calling NxLoadConfig()
1355 UINT64 bufferSize
; // Buffer size for strings or flag to be set for CT_BOOLEAN
1356 UINT32 bufferPos
; // Should be set to 0
1358 void *overrideIndicator
;
1362 * Code translation structure
1364 typedef struct __CODE_TO_TEXT
1371 * getopt() prototype if needed
1373 #if USE_BUNDLED_GETOPT
1374 #include <netxms_getopt.h>
1378 // Structures for opendir() / readdir() / closedir()
1383 typedef struct dirent
1385 long d_ino
; /* inode number (not used by MS-DOS) */
1386 int d_namlen
; /* Name length */
1387 char d_name
[257]; /* file name */
1390 typedef struct _dir_struc
1392 char *start
; /* Starting position */
1393 char *curr
; /* Current position */
1394 long size
; /* Size of string table */
1395 long nfiles
; /* number if filenames in table */
1396 struct dirent dirstr
; /* Directory structure to return */
1401 typedef struct dirent_w
1403 long d_ino
; /* inode number (not used by MS-DOS) */
1404 int d_namlen
; /* Name length */
1405 WCHAR d_name
[257]; /* file name */
1408 typedef struct _dir_struc_w
1410 WCHAR
*start
; /* Starting position */
1411 WCHAR
*curr
; /* Current position */
1412 long size
; /* Size of string table */
1413 long nfiles
; /* number if filenames in table */
1414 struct dirent_w dirstr
; /* Directory structure to return */
1418 #define _TDIRECT _DIRECTW
1419 #define _tdirent dirent_w
1424 #define _TDIRECT _DIRECT
1425 #define _tdirent dirent
1429 #else /* not _WIN32 */
1431 typedef struct dirent_w
1433 long d_ino
; /* inode number */
1434 WCHAR d_name
[257]; /* file name */
1437 typedef struct _dir_struc_w
1439 DIR *dir
; /* Original non-unicode structure */
1440 struct dirent_w dirstr
; /* Directory structure to return */
1452 inline TCHAR
*nx_strncpy(TCHAR
*pszDest
, const TCHAR
*pszSrc
, size_t nLen
)
1454 #if defined(_WIN32) && (_MSC_VER >= 1400)
1455 _tcsncpy_s(pszDest
, nLen
, pszSrc
, _TRUNCATE
);
1457 _tcsncpy(pszDest
, pszSrc
, nLen
- 1);
1458 pszDest
[nLen
- 1] = 0;
1464 inline char *nx_strncpy_mb(char *pszDest
, const char *pszSrc
, size_t nLen
)
1466 #if defined(_WIN32) && (_MSC_VER >= 1400)
1467 strncpy_s(pszDest
, nLen
, pszSrc
, _TRUNCATE
);
1469 strncpy(pszDest
, pszSrc
, nLen
- 1);
1470 pszDest
[nLen
- 1] = 0;
1475 #define nx_strncpy_mb nx_strncpy
1478 int LIBNETXMS_EXPORTABLE
ConnectEx(SOCKET s
, struct sockaddr
*addr
, int len
, UINT32 timeout
);
1479 int LIBNETXMS_EXPORTABLE
SendEx(SOCKET hSocket
, const void *data
, size_t len
, int flags
, MUTEX mutex
);
1480 int LIBNETXMS_EXPORTABLE
RecvEx(SOCKET hSocket
, void *data
, size_t len
, int flags
, UINT32 timeout
);
1481 bool LIBNETXMS_EXPORTABLE
RecvAll(SOCKET s
, void *buffer
, size_t size
, UINT32 timeout
);
1483 SOCKET LIBNETXMS_EXPORTABLE
ConnectToHost(const InetAddress
& addr
, UINT16 port
, UINT32 timeout
);
1485 #endif /* __cplusplus */
1492 void LIBNETXMS_EXPORTABLE
InitNetXMSProcess();
1494 #if !defined(_WIN32) && !defined(_NETWARE)
1495 #if defined(UNICODE_UCS2) || defined(UNICODE_UCS4)
1496 void LIBNETXMS_EXPORTABLE
__wcsupr(WCHAR
*in
);
1497 #define wcsupr __wcsupr
1499 void LIBNETXMS_EXPORTABLE
__strupr(char *in
);
1500 #define strupr __strupr
1503 void LIBNETXMS_EXPORTABLE
QSortEx(void *base
, size_t nmemb
, size_t size
, void *arg
,
1504 int (*compare
)(const void *, const void *, void *));
1506 INT64 LIBNETXMS_EXPORTABLE
GetCurrentTimeMs();
1508 UINT64 LIBNETXMS_EXPORTABLE
FileSizeW(const WCHAR
*pszFileName
);
1509 UINT64 LIBNETXMS_EXPORTABLE
FileSizeA(const char *pszFileName
);
1511 #define FileSize FileSizeW
1513 #define FileSize FileSizeA
1516 int LIBNETXMS_EXPORTABLE
BitsInMask(UINT32 dwMask
);
1517 TCHAR LIBNETXMS_EXPORTABLE
*IpToStr(UINT32 dwAddr
, TCHAR
*szBuffer
);
1519 char LIBNETXMS_EXPORTABLE
*IpToStrA(UINT32 dwAddr
, char *szBuffer
);
1521 #define IpToStrA IpToStr
1523 TCHAR LIBNETXMS_EXPORTABLE
*Ip6ToStr(const BYTE
*addr
, TCHAR
*buffer
);
1525 char LIBNETXMS_EXPORTABLE
*Ip6ToStrA(const BYTE
*addr
, char *buffer
);
1527 #define Ip6ToStrA Ip6ToStr
1529 TCHAR LIBNETXMS_EXPORTABLE
*SockaddrToStr(struct sockaddr
*addr
, TCHAR
*buffer
);
1531 UINT32 LIBNETXMS_EXPORTABLE
ResolveHostNameA(const char *name
);
1532 UINT32 LIBNETXMS_EXPORTABLE
ResolveHostNameW(const WCHAR
*name
);
1534 #define ResolveHostName ResolveHostNameW
1536 #define ResolveHostName ResolveHostNameA
1539 void LIBNETXMS_EXPORTABLE
*nx_memdup(const void *data
, size_t size
);
1540 void LIBNETXMS_EXPORTABLE
nx_memswap(void *block1
, void *block2
, size_t size
);
1542 WCHAR LIBNETXMS_EXPORTABLE
*BinToStrW(const BYTE
*data
, size_t size
, WCHAR
*pStr
);
1543 char LIBNETXMS_EXPORTABLE
*BinToStrA(const BYTE
*data
, size_t size
, char *pStr
);
1545 #define BinToStr BinToStrW
1547 #define BinToStr BinToStrA
1550 size_t LIBNETXMS_EXPORTABLE
StrToBinW(const WCHAR
*pStr
, BYTE
*data
, size_t size
);
1551 size_t LIBNETXMS_EXPORTABLE
StrToBinA(const char *pStr
, BYTE
*data
, size_t size
);
1553 #define StrToBin StrToBinW
1555 #define StrToBin StrToBinA
1558 TCHAR LIBNETXMS_EXPORTABLE
*MACToStr(const BYTE
*data
, TCHAR
*pStr
);
1560 void LIBNETXMS_EXPORTABLE
StrStripA(char *pszStr
);
1561 void LIBNETXMS_EXPORTABLE
StrStripW(WCHAR
*pszStr
);
1563 #define StrStrip StrStripW
1565 #define StrStrip StrStripA
1568 const char LIBNETXMS_EXPORTABLE
*ExtractWordA(const char *line
, char *buffer
);
1569 const WCHAR LIBNETXMS_EXPORTABLE
*ExtractWordW(const WCHAR
*line
, WCHAR
*buffer
);
1571 #define ExtractWord ExtractWordW
1573 #define ExtractWord ExtractWordA
1576 int LIBNETXMS_EXPORTABLE
NumCharsA(const char *pszStr
, char ch
);
1577 int LIBNETXMS_EXPORTABLE
NumCharsW(const WCHAR
*pszStr
, WCHAR ch
);
1579 #define NumChars NumCharsW
1581 #define NumChars NumCharsA
1584 void LIBNETXMS_EXPORTABLE
RemoveTrailingCRLFA(char *str
);
1585 void LIBNETXMS_EXPORTABLE
RemoveTrailingCRLFW(WCHAR
*str
);
1587 #define RemoveTrailingCRLF RemoveTrailingCRLFW
1589 #define RemoveTrailingCRLF RemoveTrailingCRLFA
1592 BOOL LIBNETXMS_EXPORTABLE
RegexpMatchA(const char *str
, const char *expr
, bool matchCase
);
1593 BOOL LIBNETXMS_EXPORTABLE
RegexpMatchW(const WCHAR
*str
, const WCHAR
*expr
, bool matchCase
);
1595 #define RegexpMatch RegexpMatchW
1597 #define RegexpMatch RegexpMatchA
1600 const TCHAR LIBNETXMS_EXPORTABLE
*ExpandFileName(const TCHAR
*name
, TCHAR
*buffer
, size_t bufSize
, bool allowShellCommand
);
1601 BOOL LIBNETXMS_EXPORTABLE
CreateFolder(const TCHAR
*directory
);
1602 TCHAR LIBNETXMS_EXPORTABLE
*Trim(TCHAR
*str
);
1603 bool LIBNETXMS_EXPORTABLE
MatchString(const TCHAR
*pattern
, const TCHAR
*str
, bool matchCase
);
1604 TCHAR LIBNETXMS_EXPORTABLE
**SplitString(const TCHAR
*source
, TCHAR sep
, int *numStrings
);
1605 int LIBNETXMS_EXPORTABLE
GetLastMonthDay(struct tm
*currTime
);
1607 bool LIBNETXMS_EXPORTABLE
MatchScheduleElement(TCHAR
*pszPattern
, int nValue
, int maxValue
, struct tm
*localTime
, time_t currTime
= 0);
1609 bool LIBNETXMS_EXPORTABLE
MatchScheduleElement(TCHAR
*pszPattern
, int nValue
, int maxValue
, struct tm
*localTime
, time_t currTime
);
1614 BOOL LIBNETXMS_EXPORTABLE
IsValidObjectName(const TCHAR
*pszName
, BOOL bExtendedChars
= FALSE
);
1616 BOOL LIBNETXMS_EXPORTABLE
IsValidScriptName(const TCHAR
*pszName
);
1617 /* deprecated */ void LIBNETXMS_EXPORTABLE
TranslateStr(TCHAR
*pszString
, const TCHAR
*pszSubStr
, const TCHAR
*pszReplace
);
1618 const TCHAR LIBNETXMS_EXPORTABLE
*GetCleanFileName(const TCHAR
*pszFileName
);
1619 void LIBNETXMS_EXPORTABLE
GetOSVersionString(TCHAR
*pszBuffer
, int nBufSize
);
1620 BYTE LIBNETXMS_EXPORTABLE
*LoadFile(const TCHAR
*pszFileName
, UINT32
*pdwFileSize
);
1622 BYTE LIBNETXMS_EXPORTABLE
*LoadFileA(const char *pszFileName
, UINT32
*pdwFileSize
);
1624 #define LoadFileA LoadFile
1627 UINT32 LIBNETXMS_EXPORTABLE
CalculateCRC32(const unsigned char *data
, UINT32 size
, UINT32 dwCRC
);
1628 void LIBNETXMS_EXPORTABLE
CalculateMD5Hash(const unsigned char *data
, size_t nbytes
, unsigned char *hash
);
1629 void LIBNETXMS_EXPORTABLE
MD5HashForPattern(const unsigned char *data
, size_t patternSize
, size_t fullSize
, BYTE
*hash
);
1630 void LIBNETXMS_EXPORTABLE
CalculateSHA1Hash(unsigned char *data
, size_t nbytes
, unsigned char *hash
);
1631 void LIBNETXMS_EXPORTABLE
SHA1HashForPattern(unsigned char *data
, size_t patternSize
, size_t fullSize
, unsigned char *hash
);
1632 void LIBNETXMS_EXPORTABLE
CalculateSHA256Hash(const unsigned char *data
, size_t len
, unsigned char *hash
);
1633 BOOL LIBNETXMS_EXPORTABLE
CalculateFileMD5Hash(const TCHAR
*pszFileName
, BYTE
*pHash
);
1634 BOOL LIBNETXMS_EXPORTABLE
CalculateFileSHA1Hash(const TCHAR
*pszFileName
, BYTE
*pHash
);
1635 BOOL LIBNETXMS_EXPORTABLE
CalculateFileCRC32(const TCHAR
*pszFileName
, UINT32
*pResult
);
1637 void LIBNETXMS_EXPORTABLE
GenerateRandomBytes(BYTE
*buffer
, size_t size
);
1639 void LIBNETXMS_EXPORTABLE
ICEEncryptData(const BYTE
*in
, int inLen
, BYTE
*out
, const BYTE
*key
);
1640 void LIBNETXMS_EXPORTABLE
ICEDecryptData(const BYTE
*in
, int inLen
, BYTE
*out
, const BYTE
*key
);
1642 bool LIBNETXMS_EXPORTABLE
DecryptPassword(const TCHAR
*login
, const TCHAR
*encryptedPasswd
, TCHAR
*decryptedPasswd
, size_t bufferLenght
);
1644 int LIBNETXMS_EXPORTABLE
NxDCIDataTypeFromText(const TCHAR
*pszText
);
1646 HMODULE LIBNETXMS_EXPORTABLE
DLOpen(const TCHAR
*pszLibName
, TCHAR
*pszErrorText
);
1647 void LIBNETXMS_EXPORTABLE
DLClose(HMODULE hModule
);
1648 void LIBNETXMS_EXPORTABLE
*DLGetSymbolAddr(HMODULE hModule
, const char *pszSymbol
, TCHAR
*pszErrorText
);
1650 bool LIBNETXMS_EXPORTABLE
ExtractNamedOptionValueW(const WCHAR
*optString
, const WCHAR
*option
, WCHAR
*buffer
, int bufSize
);
1651 bool LIBNETXMS_EXPORTABLE
ExtractNamedOptionValueAsBoolW(const WCHAR
*optString
, const WCHAR
*option
, bool defVal
);
1652 long LIBNETXMS_EXPORTABLE
ExtractNamedOptionValueAsIntW(const WCHAR
*optString
, const WCHAR
*option
, long defVal
);
1654 bool LIBNETXMS_EXPORTABLE
ExtractNamedOptionValueA(const char *optString
, const char *option
, char *buffer
, int bufSize
);
1655 bool LIBNETXMS_EXPORTABLE
ExtractNamedOptionValueAsBoolA(const char *optString
, const char *option
, bool defVal
);
1656 long LIBNETXMS_EXPORTABLE
ExtractNamedOptionValueAsIntA(const char *optString
, const char *option
, long defVal
);
1659 #define ExtractNamedOptionValue ExtractNamedOptionValueW
1660 #define ExtractNamedOptionValueAsBool ExtractNamedOptionValueAsBoolW
1661 #define ExtractNamedOptionValueAsInt ExtractNamedOptionValueAsIntW
1663 #define ExtractNamedOptionValue ExtractNamedOptionValueA
1664 #define ExtractNamedOptionValueAsBool ExtractNamedOptionValueAsBoolA
1665 #define ExtractNamedOptionValueAsInt ExtractNamedOptionValueAsIntA
1669 const TCHAR LIBNETXMS_EXPORTABLE
*CodeToText(int iCode
, CODE_TO_TEXT
*pTranslator
, const TCHAR
*pszDefaultText
= _T("Unknown"));
1671 const TCHAR LIBNETXMS_EXPORTABLE
*CodeToText(int iCode
, CODE_TO_TEXT
*pTranslator
, const TCHAR
*pszDefaultText
);
1675 TCHAR LIBNETXMS_EXPORTABLE
*GetSystemErrorText(UINT32 dwError
, TCHAR
*pszBuffer
, size_t iBufSize
);
1676 BOOL LIBNETXMS_EXPORTABLE
GetWindowsVersionString(TCHAR
*versionString
, int strSize
);
1677 INT64 LIBNETXMS_EXPORTABLE
GetProcessRSS();
1680 #if !HAVE_DAEMON || !HAVE_DECL_DAEMON
1681 int LIBNETXMS_EXPORTABLE
__daemon(int nochdir
, int noclose
);
1682 #define daemon __daemon
1685 UINT32 LIBNETXMS_EXPORTABLE
inet_addr_w(const WCHAR
*pszAddr
);
1688 BOOL LIBNETXMS_EXPORTABLE
SetDefaultCodepage(const char *cp
);
1689 int LIBNETXMS_EXPORTABLE
WideCharToMultiByte(int iCodePage
, UINT32 dwFlags
, const WCHAR
*pWideCharStr
,
1690 int cchWideChar
, char *pByteStr
, int cchByteChar
,
1691 char *pDefaultChar
, BOOL
*pbUsedDefChar
);
1692 int LIBNETXMS_EXPORTABLE
MultiByteToWideChar(int iCodePage
, UINT32 dwFlags
, const char *pByteStr
,
1693 int cchByteChar
, WCHAR
*pWideCharStr
,
1696 #if !defined(UNICODE_UCS2) || !HAVE_WCSLEN
1697 int LIBNETXMS_EXPORTABLE
ucs2_strlen(const UCS2CHAR
*pStr
);
1699 #if !defined(UNICODE_UCS2) || !HAVE_WCSNCPY
1700 UCS2CHAR LIBNETXMS_EXPORTABLE
*ucs2_strncpy(UCS2CHAR
*pDst
, const UCS2CHAR
*pSrc
, int nDstLen
);
1702 #if !defined(UNICODE_UCS2) || !HAVE_WCSDUP
1703 UCS2CHAR LIBNETXMS_EXPORTABLE
*ucs2_strdup(const UCS2CHAR
*pStr
);
1706 size_t LIBNETXMS_EXPORTABLE
ucs2_to_mb(const UCS2CHAR
*src
, int srcLen
, char *dst
, int dstLen
);
1707 size_t LIBNETXMS_EXPORTABLE
mb_to_ucs2(const char *src
, int srcLen
, UCS2CHAR
*dst
, int dstLen
);
1708 UCS2CHAR LIBNETXMS_EXPORTABLE
*UCS2StringFromMBString(const char *pszString
);
1709 char LIBNETXMS_EXPORTABLE
*MBStringFromUCS2String(const UCS2CHAR
*pszString
);
1711 int LIBNETXMS_EXPORTABLE
nx_wprintf(const WCHAR
*format
, ...);
1712 int LIBNETXMS_EXPORTABLE
nx_fwprintf(FILE *fp
, const WCHAR
*format
, ...);
1713 int LIBNETXMS_EXPORTABLE
nx_swprintf(WCHAR
*buffer
, size_t size
, const WCHAR
*format
, ...);
1714 int LIBNETXMS_EXPORTABLE
nx_vwprintf(const WCHAR
*format
, va_list args
);
1715 int LIBNETXMS_EXPORTABLE
nx_vfwprintf(FILE *fp
, const WCHAR
*format
, va_list args
);
1716 int LIBNETXMS_EXPORTABLE
nx_vswprintf(WCHAR
*buffer
, size_t size
, const WCHAR
*format
, va_list args
);
1718 int LIBNETXMS_EXPORTABLE
nx_wscanf(const WCHAR
*format
, ...);
1719 int LIBNETXMS_EXPORTABLE
nx_fwscanf(FILE *fp
, const WCHAR
*format
, ...);
1720 int LIBNETXMS_EXPORTABLE
nx_swscanf(const WCHAR
*str
, const WCHAR
*format
, ...);
1721 int LIBNETXMS_EXPORTABLE
nx_vwscanf(const WCHAR
*format
, va_list args
);
1722 int LIBNETXMS_EXPORTABLE
nx_vfwscanf(FILE *fp
, const WCHAR
*format
, va_list args
);
1723 int LIBNETXMS_EXPORTABLE
nx_vswscanf(const WCHAR
*str
, const WCHAR
*format
, va_list args
);
1727 #ifdef _WITH_ENCRYPTION
1728 WCHAR LIBNETXMS_EXPORTABLE
*ERR_error_string_W(int nError
, WCHAR
*pwszBuffer
);
1732 size_t LIBNETXMS_EXPORTABLE
ucs2_to_ucs4(const UCS2CHAR
*src
, int srcLen
, WCHAR
*dst
, int dstLen
);
1733 size_t LIBNETXMS_EXPORTABLE
ucs4_to_ucs2(const WCHAR
*src
, int srcLen
, UCS2CHAR
*dst
, int dstLen
);
1734 size_t LIBNETXMS_EXPORTABLE
ucs2_to_utf8(const UCS2CHAR
*src
, int srcLen
, char *dst
, int dstLen
);
1735 UCS2CHAR LIBNETXMS_EXPORTABLE
*UCS2StringFromUCS4String(const WCHAR
*pwszString
);
1736 WCHAR LIBNETXMS_EXPORTABLE
*UCS4StringFromUCS2String(const UCS2CHAR
*pszString
);
1739 size_t LIBNETXMS_EXPORTABLE
utf8_to_mb(const char *src
, int srcLen
, char *dst
, int dstLen
);
1740 size_t LIBNETXMS_EXPORTABLE
mb_to_utf8(const char *src
, int srcLen
, char *dst
, int dstLen
);
1741 char LIBNETXMS_EXPORTABLE
*MBStringFromUTF8String(const char *s
);
1742 char LIBNETXMS_EXPORTABLE
*UTF8StringFromMBString(const char *s
);
1744 #if !defined(_WIN32) && !HAVE_WSTAT
1745 int wstat(const WCHAR
*_path
, struct stat
*_sbuf
);
1748 #if defined(UNICODE) && !defined(_WIN32)
1751 FILE LIBNETXMS_EXPORTABLE
*wpopen(const WCHAR
*_command
, const WCHAR
*_type
);
1754 FILE LIBNETXMS_EXPORTABLE
*wfopen(const WCHAR
*_name
, const WCHAR
*_type
);
1756 #if HAVE_FOPEN64 && !HAVE_WFOPEN64
1757 FILE LIBNETXMS_EXPORTABLE
*wfopen64(const WCHAR
*_name
, const WCHAR
*_type
);
1760 int LIBNETXMS_EXPORTABLE
wopen(const WCHAR
*, int, ...);
1763 int LIBNETXMS_EXPORTABLE
wchmod(const WCHAR
*_name
, int mode
);
1766 int wchdir(const WCHAR
*_path
);
1769 int wmkdir(const WCHAR
*_path
, int mode
);
1772 int wrmdir(const WCHAR
*_path
);
1775 int wrename(const WCHAR
*_oldpath
, const WCHAR
*_newpath
);
1778 int wunlink(const WCHAR
*_path
);
1781 int wremove(const WCHAR
*_path
);
1784 int wsystem(const WCHAR
*_cmd
);
1787 int wmkstemp(WCHAR
*_template
);
1790 int waccess(const WCHAR
*_path
, int mode
);
1793 WCHAR
*wgetenv(const WCHAR
*_string
);
1796 WCHAR
*wctime(const time_t *timep
);
1799 int putws(const WCHAR
*s
);
1801 #if !HAVE_WCSERROR && (HAVE_STRERROR || HAVE_DECL_STRERROR)
1802 WCHAR
*wcserror(int errnum
);
1804 #if !HAVE_WCSERROR_R && HAVE_STRERROR_R
1805 #if HAVE_POSIX_STRERROR_R
1806 int wcserror_r(int errnum
, WCHAR
*strerrbuf
, size_t buflen
);
1808 WCHAR
*wcserror_r(int errnum
, WCHAR
*strerrbuf
, size_t buflen
);
1812 #endif /* UNICODE && !_WIN32*/
1815 INT64 LIBNETXMS_EXPORTABLE
strtoll(const char *nptr
, char **endptr
, int base
);
1818 UINT64 LIBNETXMS_EXPORTABLE
strtoull(const char *nptr
, char **endptr
, int base
);
1822 INT64 LIBNETXMS_EXPORTABLE
wcstoll(const WCHAR
*nptr
, WCHAR
**endptr
, int base
);
1825 UINT64 LIBNETXMS_EXPORTABLE
wcstoull(const WCHAR
*nptr
, WCHAR
**endptr
, int base
);
1828 #if !HAVE_WCSLWR && !defined(_WIN32)
1829 WCHAR LIBNETXMS_EXPORTABLE
*wcslwr(WCHAR
*str
);
1832 #if !HAVE_WCSCASECMP && !defined(_WIN32)
1833 int LIBNETXMS_EXPORTABLE
wcscasecmp(const wchar_t *s1
, const wchar_t *s2
);
1836 #if !HAVE_WCSNCASECMP && !defined(_WIN32)
1837 int LIBNETXMS_EXPORTABLE
wcsncasecmp(const wchar_t *s1
, const wchar_t *s2
, size_t n
);
1840 #if !defined(_WIN32) && (!HAVE_WCSFTIME || !WORKING_WCSFTIME)
1841 size_t LIBNETXMS_EXPORTABLE
nx_wcsftime(WCHAR
*buffer
, size_t bufsize
, const WCHAR
*format
, const struct tm
*t
);
1843 #define wcsftime nx_wcsftime
1848 #if HAVE_ITOA && !HAVE__ITOA
1851 #define HAVE__ITOA 1
1853 #if !HAVE__ITOA && !defined(_WIN32)
1854 char LIBNETXMS_EXPORTABLE
*_itoa(int value
, char *str
, int base
);
1857 #if HAVE_ITOW && !HAVE__ITOW
1860 #define HAVE__ITOW 1
1862 #if !HAVE__ITOW && !defined(_WIN32)
1863 WCHAR LIBNETXMS_EXPORTABLE
*_itow(int value
, WCHAR
*str
, int base
);
1870 DIRW LIBNETXMS_EXPORTABLE
*wopendir(const WCHAR
*filename
);
1871 struct dirent_w LIBNETXMS_EXPORTABLE
*wreaddir(DIRW
*dirp
);
1872 int LIBNETXMS_EXPORTABLE
wclosedir(DIRW
*dirp
);
1874 #define _topendir wopendir
1875 #define _treaddir wreaddir
1876 #define _tclosedir wclosedir
1878 #define _topendir opendir
1879 #define _treaddir readdir
1880 #define _tclosedir closedir
1883 DIR LIBNETXMS_EXPORTABLE
*opendir(const char *filename
);
1884 struct dirent LIBNETXMS_EXPORTABLE
*readdir(DIR *dirp
);
1885 int LIBNETXMS_EXPORTABLE
closedir(DIR *dirp
);
1887 #else /* not _WIN32 */
1889 DIRW LIBNETXMS_EXPORTABLE
*wopendir(const WCHAR
*filename
);
1890 struct dirent_w LIBNETXMS_EXPORTABLE
*wreaddir(DIRW
*dirp
);
1891 int LIBNETXMS_EXPORTABLE
wclosedir(DIRW
*dirp
);
1895 #if defined(_WIN32) || !(HAVE_SCANDIR)
1896 int LIBNETXMS_EXPORTABLE
scandir(const char *dir
, struct dirent
***namelist
,
1897 int (*select
)(const struct dirent
*),
1898 int (*compar
)(const struct dirent
**, const struct dirent
**));
1899 int LIBNETXMS_EXPORTABLE
alphasort(const struct dirent
**a
, const struct dirent
**b
);
1902 TCHAR LIBNETXMS_EXPORTABLE
*safe_fgetts(TCHAR
*buffer
, int len
, FILE *f
);
1904 bool LIBNETXMS_EXPORTABLE
nxlog_open(const TCHAR
*logName
, UINT32 flags
, const TCHAR
*msgModule
,
1905 unsigned int msgCount
, const TCHAR
**messages
, DWORD debugMsg
);
1906 void LIBNETXMS_EXPORTABLE
nxlog_close(void);
1907 void LIBNETXMS_EXPORTABLE
nxlog_write(DWORD msg
, WORD wType
, const char *format
, ...);
1908 void LIBNETXMS_EXPORTABLE
nxlog_debug(int level
, const TCHAR
*format
, ...);
1909 void LIBNETXMS_EXPORTABLE
nxlog_debug2(int level
, const TCHAR
*format
, va_list args
);
1910 bool LIBNETXMS_EXPORTABLE
nxlog_set_rotation_policy(int rotationMode
, int maxLogSize
, int historySize
, const TCHAR
*dailySuffix
);
1911 bool LIBNETXMS_EXPORTABLE
nxlog_rotate();
1912 void LIBNETXMS_EXPORTABLE
nxlog_set_debug_level(int level
);
1913 int LIBNETXMS_EXPORTABLE
nxlog_get_debug_level();
1915 typedef void (*NxLogDebugWriter
)(const TCHAR
*);
1916 void LIBNETXMS_EXPORTABLE
nxlog_set_debug_writer(NxLogDebugWriter writer
);
1918 typedef void (*NxLogConsoleWriter
)(const TCHAR
*, ...);
1919 void LIBNETXMS_EXPORTABLE
nxlog_set_console_writer(NxLogConsoleWriter writer
);
1921 void LIBNETXMS_EXPORTABLE
WriteToTerminal(const TCHAR
*text
);
1922 void LIBNETXMS_EXPORTABLE
WriteToTerminalEx(const TCHAR
*format
, ...)
1923 #if !defined(UNICODE) && (defined(__GNUC__) || defined(__clang__))
1924 __attribute__ ((format(printf
, 1, 2)))
1929 int LIBNETXMS_EXPORTABLE
mkstemp(char *tmpl
);
1930 int LIBNETXMS_EXPORTABLE
wmkstemp(WCHAR
*tmpl
);
1932 #define _tmkstemp wmkstemp
1934 #define _tmkstemp mkstemp
1939 int strcat_s(char *dst
, size_t dstSize
, const char *src
);
1940 int wcscat_s(WCHAR
*dst
, size_t dstSize
, const WCHAR
*src
);
1944 char LIBNETXMS_EXPORTABLE
*strptime(const char *buf
, const char *fmt
, struct tm
*_tm
);
1948 time_t LIBNETXMS_EXPORTABLE
timegm(struct tm
*_tm
);
1952 int LIBNETXMS_EXPORTABLE
nx_inet_pton(int af
, const char *src
, void *dst
);
1953 #define inet_pton nx_inet_pton
1956 int LIBNETXMS_EXPORTABLE
GetSleepTime(int hour
, int minute
, int second
);
1957 time_t LIBNETXMS_EXPORTABLE
ParseDateTimeA(const char *text
, time_t defaultValue
);
1958 time_t LIBNETXMS_EXPORTABLE
ParseDateTimeW(const WCHAR
*text
, time_t defaultValue
);
1961 #define ParseDateTime ParseDateTimeW
1963 #define ParseDateTime ParseDateTimeA
1972 // C++ only functions
1977 enum nxDirectoryType
1986 TCHAR LIBNETXMS_EXPORTABLE
*GetHeapInfo();
1988 void LIBNETXMS_EXPORTABLE
GetNetXMSDirectory(nxDirectoryType type
, TCHAR
*dir
);
1990 UINT32 LIBNETXMS_EXPORTABLE
IcmpPing(const InetAddress
& addr
, int iNumRetries
, UINT32 dwTimeout
, UINT32
*pdwRTT
, UINT32 dwPacketSize
);
1992 TCHAR LIBNETXMS_EXPORTABLE
*EscapeStringForXML(const TCHAR
*str
, int length
);
1993 String LIBNETXMS_EXPORTABLE
EscapeStringForXML2(const TCHAR
*str
, int length
= -1);
1994 const char LIBNETXMS_EXPORTABLE
*XMLGetAttr(const char **attrs
, const char *name
);
1995 int LIBNETXMS_EXPORTABLE
XMLGetAttrInt(const char **attrs
, const char *name
, int defVal
);
1996 UINT32 LIBNETXMS_EXPORTABLE
XMLGetAttrUINT32(const char **attrs
, const char *name
, UINT32 defVal
);
1997 bool LIBNETXMS_EXPORTABLE
XMLGetAttrBoolean(const char **attrs
, const char *name
, bool defVal
);
1999 String LIBNETXMS_EXPORTABLE
EscapeStringForJSON(const TCHAR
*s
);
2001 #if !defined(_WIN32) && !defined(_NETWARE) && defined(NMS_THREADS_H_INCLUDED)
2002 void LIBNETXMS_EXPORTABLE
StartMainLoop(ThreadFunction pfSignalHandler
, ThreadFunction pfMain
);
2007 #endif /* _nms_util_h_ */