Yate
yateclass.h
1
22#ifndef __YATECLASS_H
23#define __YATECLASS_H
24
25#ifndef __cplusplus
26#error C++ is required
27#endif
28
29#include <limits.h>
30#include <sys/types.h>
31#include <stddef.h>
32#include <unistd.h>
33#include <errno.h>
34#include <stdarg.h>
35
36#ifndef _WORDSIZE
37#if defined(__arch64__) || defined(__x86_64__) \
38 || defined(__amd64__) || defined(__ia64__) \
39 || defined(__alpha__) || defined(__sparcv9) || defined(__mips64)
40#define _WORDSIZE 64
41#else
42#define _WORDSIZE 32
43#endif
44#endif
45
46#ifndef _WINDOWS
47#if defined(WIN32) || defined(_WIN32)
48#define _WINDOWS
49#endif
50#endif
51
52#ifdef _WINDOWS
53
54#include <windows.h>
55#include <io.h>
56#include <direct.h>
57
61typedef signed __int8 int8_t;
62typedef unsigned __int8 u_int8_t;
63typedef unsigned __int8 uint8_t;
64typedef signed __int16 int16_t;
65typedef unsigned __int16 u_int16_t;
66typedef unsigned __int16 uint16_t;
67typedef signed __int32 int32_t;
68typedef unsigned __int32 u_int32_t;
69typedef unsigned __int32 uint32_t;
70typedef signed __int64 int64_t;
71typedef unsigned __int64 u_int64_t;
72typedef unsigned __int64 uint64_t;
73
74typedef int pid_t;
75typedef int socklen_t;
76typedef unsigned long in_addr_t;
77
78#ifndef strcasecmp
79#define strcasecmp _stricmp
80#endif
81
82#ifndef strncasecmp
83#define strncasecmp _strnicmp
84#endif
85
86#define vsnprintf _vsnprintf
87#define snprintf _snprintf
88#define strdup _strdup
89#define strtoll _strtoi64
90#define strtoull _strtoui64
91#define open _open
92#define dup2 _dup2
93#define read _read
94#define write _write
95#define close _close
96#define getpid _getpid
97#define chdir _chdir
98#define mkdir(p,m) _mkdir(p)
99#define unlink _unlink
100#define llabs _abs64
101
102#define O_RDWR _O_RDWR
103#define O_RDONLY _O_RDONLY
104#define O_WRONLY _O_WRONLY
105#define O_APPEND _O_APPEND
106#define O_BINARY _O_BINARY
107#define O_EXCL _O_EXCL
108#define O_CREAT _O_CREAT
109#define O_TRUNC _O_TRUNC
110#define O_NOCTTY 0
111
112#define S_IRUSR _S_IREAD
113#define S_IWUSR _S_IWRITE
114#define S_IXUSR 0
115#define S_IRWXU (_S_IREAD|_S_IWRITE)
116
117#ifdef LIBYATE_EXPORTS
118#define YATE_API __declspec(dllexport)
119#else
120#ifndef LIBYATE_STATIC
121#define YATE_API __declspec(dllimport)
122#endif
123#endif
124
125#define FMT64 "%I64d"
126#define FMT64U "%I64u"
127
128#else /* _WINDOWS */
129
130#include <sys/time.h>
131#include <sys/socket.h>
132
133#if defined(__FreeBSD__)
134#include <netinet/in_systm.h>
135#endif
136
137#include <netinet/in.h>
138#include <netinet/ip.h>
139#include <netinet/tcp.h>
140#include <arpa/inet.h>
141#include <netdb.h>
142
146#ifndef SOCKET
147typedef int SOCKET;
148#endif
149#ifndef HANDLE
150typedef int HANDLE;
151#endif
152
153#ifndef O_BINARY
154#define O_BINARY 0
155#endif
156
157#if _WORDSIZE == 64 && !defined(__APPLE__)
158#define FMT64 "%ld"
159#define FMT64U "%lu"
160#else
161#define FMT64 "%lld"
162#define FMT64U "%llu"
163#endif
164
165#endif /* ! _WINDOWS */
166
167#ifndef LLONG_MAX
168#ifdef _I64_MAX
169#define LLONG_MAX _I64_MAX
170#else
171#define LLONG_MAX 9223372036854775807LL
172#endif
173#endif
174
175#ifndef LLONG_MIN
176#ifdef _I64_MIN
177#define LLONG_MIN _I64_MIN
178#else
179#define LLONG_MIN (-LLONG_MAX - 1LL)
180#endif
181#endif
182
183#ifndef ULLONG_MAX
184#ifdef _UI64_MAX
185#define ULLONG_MAX _UI64_MAX
186#else
187#define ULLONG_MAX 18446744073709551615ULL
188#endif
189#endif
190
191#ifndef O_LARGEFILE
192#define O_LARGEFILE 0
193#endif
194
195#ifndef IPTOS_LOWDELAY
196#define IPTOS_LOWDELAY 0x10
197#define IPTOS_THROUGHPUT 0x08
198#define IPTOS_RELIABILITY 0x04
199#endif
200#ifndef IPTOS_MINCOST
201#define IPTOS_MINCOST 0x02
202#endif
203#ifndef IPPROTO_SCTP
204#define IPPROTO_SCTP 132
205#endif
206
207#ifndef YATE_API
208#define YATE_API
209#endif
210
211#ifdef _WINDOWS
212#undef RAND_MAX
213#define RAND_MAX 2147483647
214#endif
215
219namespace TelEngine {
220
221#ifdef HAVE_GCC_FORMAT_CHECK
222#define FORMAT_CHECK(f) __attribute__((format(printf,(f),(f)+1)))
223#else
224#define FORMAT_CHECK(f)
225#endif
226
227#define YIGNORE(v) while (v) { break; }
228
229#ifdef HAVE_BLOCK_RETURN
230#define YSTRING(s) (*({static const String str("" s);&str;}))
231#define YATOM(s) (*({static const String* str(0);str ? str : String::atom(str,"" s);}))
232#else
233#define YSTRING(s) ("" s)
234#define YATOM(s) ("" s)
235#endif
236
237#define YSTRING_INIT_HASH ((unsigned) -1)
238
243YATE_API void abortOnBug();
244
249YATE_API bool abortOnBug(bool doAbort);
250
256enum DebugLevel {
257 DebugFail = 0,
258 DebugTest = 1,
259 DebugCrit = 2,
260 DebugGoOn = DebugCrit,
261 DebugConf = 3,
262 DebugStub = 4,
263 DebugWarn = 5,
264 DebugMild = 6,
265 DebugNote = 7,
266 DebugCall = 8,
267 DebugInfo = 9,
268 DebugAll = 10
269};
270
275YATE_API int debugLevel();
276
282YATE_API int debugLevel(int level);
283
289YATE_API bool debugAt(int level);
290
297YATE_API const char* debugColor(int level);
298
304YATE_API const char* debugLevelName(int level);
305
311class YATE_API DebugEnabler
312{
313public:
319 inline DebugEnabler(int level = TelEngine::debugLevel(), bool enabled = true)
320 : m_level(DebugFail), m_enabled(enabled), m_chain(0), m_name(0)
321 { debugLevel(level); }
322
323 inline ~DebugEnabler()
324 { m_name = 0; m_chain = 0; }
325
330 inline int debugLevel() const
331 { return m_chain ? m_chain->debugLevel() : m_level; }
332
338 int debugLevel(int level);
339
344 inline bool debugEnabled() const
345 { return m_chain ? m_chain->debugEnabled() : m_enabled; }
346
351 inline void debugEnabled(bool enable)
352 { m_enabled = enable; m_chain = 0; }
353
358 inline const char* debugName() const
359 { return m_name; }
360
366 bool debugAt(int level) const;
367
372 inline bool debugChained() const
373 { return m_chain != 0; }
374
379 inline void debugChain(const DebugEnabler* chain = 0)
380 { m_chain = (chain != this) ? chain : 0; }
381
386 void debugCopy(const DebugEnabler* original = 0);
387
388protected:
393 inline void debugName(const char* name)
394 { m_name = name; }
395
396private:
397 int m_level;
398 bool m_enabled;
399 const DebugEnabler* m_chain;
400 const char* m_name;
401};
402
403#if 0 /* for documentation generator */
409void DDebug(int level, const char* format, ...);
410
416void DDebug(const char* facility, int level, const char* format, ...);
417
423void DDebug(const DebugEnabler* local, int level, const char* format, ...);
424
430void XDebug(int level, const char* format, ...);
431
437void XDebug(const char* facility, int level, const char* format, ...);
438
444void XDebug(const DebugEnabler* local, int level, const char* format, ...);
445
451void NDebug(int level, const char* format, ...);
452
458void NDebug(const char* facility, int level, const char* format, ...);
459
465void NDebug(const DebugEnabler* local, int level, const char* format, ...);
466#endif
467
468#if defined(_DEBUG) || defined(DEBUG) || defined(XDEBUG)
469#undef DEBUG
470#define DEBUG 1
471#endif
472
473#ifdef DEBUG
474#define DDebug Debug
475#else
476#ifdef _WINDOWS
477#define DDebug do { break; } while
478#else
479#define DDebug(arg...)
480#endif
481#endif
482
483#ifdef XDEBUG
484#define XDebug Debug
485#else
486#ifdef _WINDOWS
487#define XDebug do { break; } while
488#else
489#define XDebug(arg...)
490#endif
491#endif
492
493#ifndef NDEBUG
494#define NDebug Debug
495#else
496#ifdef _WINDOWS
497#define NDebug do { break; } while
498#else
499#define NDebug(arg...)
500#endif
501#endif
502
508YATE_API void Debug(int level, const char* format, ...) FORMAT_CHECK(2);
509
516YATE_API void Debug(const char* facility, int level, const char* format, ...) FORMAT_CHECK(3);
517
524YATE_API void Debug(const DebugEnabler* local, int level, const char* format, ...) FORMAT_CHECK(3);
525
532YATE_API void Alarm(const char* component, int level, const char* format, ...) FORMAT_CHECK(3);
533
540YATE_API void Alarm(const DebugEnabler* component, int level, const char* format, ...) FORMAT_CHECK(3);
541
549YATE_API void Alarm(const char* component, const char* info, int level, const char* format, ...) FORMAT_CHECK(4);
550
558YATE_API void Alarm(const DebugEnabler* component, const char* info, int level, const char* format, ...) FORMAT_CHECK(4);
559
564YATE_API void Output(const char* format, ...) FORMAT_CHECK(1);
565
572YATE_API void TraceDebug(const char* traceId, int level, const char* format, ...) FORMAT_CHECK(3);
573
581YATE_API void TraceDebug(const char* traceId, const char* facility, int level,
582 const char* format, ...) FORMAT_CHECK(4);
583
591YATE_API void TraceDebug(const char* traceId, const DebugEnabler* local, int level,
592 const char* format, ...) FORMAT_CHECK(4);
593
594
595#if 0 /* for documentation generator */
602void TraceDebugObj(GenObject* obj, int level, const char* format, ...);
603
611void TraceDebugObj(GenObject* obj, const char* facility, int level, const char* format, ...);
612
620void TraceDebugObj(GenObject* obj, const DebugEnabler* local, int level, const char* format, ...);
621
628void Trace(GenObject* obj, int level, const char* format, ...);
629
637void Trace(GenObject* obj, const char* facility, int level, const char* format, ...);
638
646void Trace(GenObject* obj, const DebugEnabler* local, int level, const char* format, ...);
647
654void TraceObj(GenObject* obj, int level, const char* format, ...);
655
663void TraceObj(GenObject* obj, const char* facility, int level, const char* format, ...);
664
672void TraceObj(GenObject* obj, const DebugEnabler* local, int level, const char* format, ...);
673
674#endif
675
676#define TraceDebugObj(pGenObj,...) \
677TraceDebug((!!(pGenObj)) ? (pGenObj)->traceId() : "",##__VA_ARGS__)
678
679#define Trace(traceId,...) \
680do { if (!TelEngine::null(traceId)) TraceDebug(traceId,##__VA_ARGS__); } while(false)
681
682#define TraceObj(pGenObj,...) \
683do { if (!!(pGenObj) && (pGenObj)->traceId()) TraceDebug((pGenObj)->traceId(),##__VA_ARGS__); } while (false)
684
685
694YATE_API void TraceAlarm(const char* traceId, const char* component, int level,
695 const char* format, ...) FORMAT_CHECK(4);
696
704YATE_API void TraceAlarm(const char* traceId, const DebugEnabler* component,
705 int level, const char* format, ...) FORMAT_CHECK(4);
706
715YATE_API void TraceAlarm(const char* traceId, const char* component, const char* info,
716 int level, const char* format, ...) FORMAT_CHECK(5);
717
726YATE_API void TraceAlarm(const char* traceId, const DebugEnabler* component,
727 const char* info, int level, const char* format, ...) FORMAT_CHECK(5);
728
735class YATE_API Debugger
736{
737public:
742 None = 0,
743 Relative, // from program start
744 Absolute, // from EPOCH (1-1-1970)
745 Textual, // absolute GMT in YYYYMMDDhhmmss.uuuuuu format
746 TextLocal, // local time in YYYYMMDDhhmmss.uuuuuu format
747 TextSep, // absolute GMT in YYYY-MM-DD_hh:mm:ss.uuuuuu format
748 TextLSep, // local time in YYYY-MM-DD_hh:mm:ss.uuuuuu format
749 };
750
756 explicit Debugger(const char* name, const char* format = 0, ...);
757
764 Debugger(int level, const char* name, const char* format = 0, ...);
765
770
775 static void setOutput(void (*outFunc)(const char*,int) = 0);
776
781 static void setIntOut(void (*outFunc)(const char*,int) = 0);
782
787 static void setAlarmHook(void (*alarmFunc)(const char*,int,const char*,const char*) = 0);
788
793 static void setRelayHook(void (*relayFunc)(int,const char*,const char*,const char*) = 0);
794
800 static void enableOutput(bool enable = true, bool colorize = false);
801
806 static uint32_t getStartTimeSec();
807
813
819 static void setFormatting(Formatting format, uint32_t startTimeSec = 0);
820
827 static unsigned int formatTime(char* buf, Formatting format = getFormatting());
828
837 static void relayOutput(int level, char* buffer, const char* component = 0, const char* info = 0);
838
839private:
840 const char* m_name;
841 int m_level;
842};
843
848struct TokenDict {
852 const char* token;
853
857 int value;
858};
859
869 const char* token;
870
874 int64_t value;
875};
876
877class String;
878class DataBlock;
879class Mutex;
880class ObjList;
881class NamedCounter;
882
883#if 0 /* for documentation generator */
888void YIGNORE(primitive value);
889
895constant YSTRING(const char* string);
896
902constant YATOM(const char* string);
903
909void YCLASS(class type,class base);
910
917void YCLASS2(class type,class base1,class base2);
918
926void YCLASS3(class type,class base1,class base2,class base3);
927
933void YCLASSIMP(class type,class base);
934
941void YCLASSIMP2(class type,class base1,class base2);
942
950void YCLASSIMP3(class type,class base1,class base2,class base3);
951
958class* YOBJECT(class type,GenObject* pntr);
959
964void YNOCOPY(class type);
965#endif
966
967#define YCLASS(type,base) \
968public: virtual void* getObject(const String& name) const \
969{ return (name == YATOM(#type)) ? const_cast<type*>(this) : base::getObject(name); }
970
971#define YCLASS2(type,base1,base2) \
972public: virtual void* getObject(const String& name) const \
973{ if (name == YATOM(#type)) return const_cast<type*>(this); \
974 void* tmp = base1::getObject(name); \
975 return tmp ? tmp : base2::getObject(name); }
976
977#define YCLASS3(type,base1,base2,base3) \
978public: virtual void* getObject(const String& name) const \
979{ if (name == YATOM(#type)) return const_cast<type*>(this); \
980 void* tmp = base1::getObject(name); \
981 if (tmp) return tmp; \
982 tmp = base2::getObject(name); \
983 return tmp ? tmp : base3::getObject(name); }
984
985#define YCLASSIMP(type,base) \
986void* type::getObject(const String& name) const \
987{ return (name == YATOM(#type)) ? const_cast<type*>(this) : base::getObject(name); }
988
989#define YCLASSIMP2(type,base1,base2) \
990void* type::getObject(const String& name) const \
991{ if (name == YATOM(#type)) return const_cast<type*>(this); \
992 void* tmp = base1::getObject(name); \
993 return tmp ? tmp : base2::getObject(name); }
994
995#define YCLASSIMP3(type,base1,base2,base3) \
996void* type::getObject(const String& name) const \
997{ if (name == YATOM(#type)) return const_cast<type*>(this); \
998 void* tmp = base1::getObject(name); \
999 if (tmp) return tmp; \
1000 tmp = base2::getObject(name); \
1001 return tmp ? tmp : base3::getObject(name); }
1002
1003#define YOBJECT(type,pntr) (static_cast<type*>(GenObject::getObject(YATOM(#type),pntr)))
1004
1005#define YNOCOPY(type) private: \
1006type(const type&); \
1007void operator=(const type&)
1008
1009
1015YATE_API inline uint32_t hashInt64(uint64_t val)
1016{
1017 return (uint32_t)(((val ^ (val >> 48)) ^ (val >> 32)) ^ (val >> 16));
1018}
1019
1025YATE_API inline uint32_t hashInt32(uint32_t val)
1026{
1027 return (uint32_t)((val ^ (val >> 16)) ^ (val << 16));
1028}
1029
1035YATE_API inline uint32_t hashPtr(const void* ptr)
1036{
1037#if (_WORDSIZE == 64)
1038 return hashInt64((uintptr_t)ptr);
1039#else
1040 return hashInt32((uintptr_t)ptr);
1041#endif
1042}
1043
1044
1048class YATE_API GenObject
1049{
1050 YNOCOPY(GenObject); // no automatic copies please
1051public:
1056
1060 virtual ~GenObject() { setObjCounter(0); }
1061
1068 virtual bool alive() const;
1069
1073 virtual void destruct();
1074
1081 virtual const String& toString() const;
1082
1087 virtual const String& traceId() const;
1088
1094 virtual void* getObject(const String& name) const;
1095
1102 static inline void* getObject(const String& name, const GenObject* obj)
1103 { return obj ? obj->getObject(name) : 0; }
1104
1109 static inline bool getObjCounting()
1110 { return s_counting; }
1111
1116 static inline void setObjCounting(bool enable)
1117 { s_counting = enable; }
1118
1124 { return m_counter; }
1125
1132
1139 static NamedCounter* getObjCounter(const String& name, bool create = true);
1140
1146
1147private:
1148 NamedCounter* m_counter;
1149 static bool s_counting;
1150};
1151
1157inline void destruct(GenObject* obj)
1158 { if (obj) obj->destruct(); }
1159
1166template <class Obj> void destruct(Obj*& obj)
1167 { if (obj) { obj->destruct(); obj = 0; } }
1168
1173class YATE_API RefObject : public GenObject
1174{
1175 YNOCOPY(RefObject); // no automatic copies please
1176public:
1182
1186 virtual ~RefObject();
1187
1193 virtual void* getObject(const String& name) const;
1194
1201 virtual bool alive() const;
1202
1207 bool ref();
1208
1217 bool deref();
1218
1223 inline int refcount() const
1224 { return m_refcount; }
1225
1230 virtual void destruct();
1231
1237 inline static bool alive(const RefObject* obj)
1238 { return obj && (obj->refcount() > 0); }
1239
1245 static bool efficientIncDec();
1246
1247protected:
1253 virtual void zeroRefs();
1254
1261
1267 virtual void destroyed();
1268
1269private:
1270 int m_refcount;
1271 Mutex* m_mutex;
1272};
1273
1279class YATE_API RefPointerBase
1280{
1281protected:
1286 : m_pointer(0) { }
1287
1294 void assign(RefObject* oldptr, RefObject* newptr, void* pointer);
1295
1300};
1301
1305template <class Obj = RefObject> class RefPointer : public RefPointerBase
1306{
1307protected:
1312 inline Obj* pointer() const
1313 { return static_cast<Obj*>(m_pointer); }
1314
1319 inline void assign(Obj* object = 0)
1320 { RefPointerBase::assign(pointer(),object,object); }
1321
1322public:
1326 inline RefPointer()
1327 { }
1328
1333 inline RefPointer(const RefPointer<Obj>& value)
1334 : RefPointerBase()
1335 { assign(value); }
1336
1341 inline RefPointer(Obj* object)
1342 { assign(object); }
1343
1348 { assign(); }
1349
1354 { assign(value.pointer()); return *this; }
1355
1359 inline RefPointer<Obj>& operator=(Obj* object)
1360 { assign(object); return *this; }
1361
1366 inline operator Obj*() const
1367 { return pointer(); }
1368
1372 inline Obj* operator->() const
1373 { return pointer(); }
1374
1378 inline Obj& operator*() const
1379 { return *pointer(); }
1380};
1381
1385template <class Obj = GenObject> class GenPointer : public GenObject
1386{
1387private:
1391 Obj* m_pointer;
1392
1393public:
1397 inline GenPointer()
1398 : m_pointer(0)
1399 { }
1400
1405 inline GenPointer(const GenPointer<Obj>& value)
1406 : m_pointer(value)
1407 { }
1408
1413 inline GenPointer(Obj* object)
1414 : m_pointer(object)
1415 { }
1416
1421 { m_pointer = value; return *this; }
1422
1426 inline GenPointer<Obj>& operator=(Obj* object)
1427 { m_pointer = object; return *this; }
1428
1433 inline operator Obj*() const
1434 { return m_pointer; }
1435
1439 inline Obj* operator->() const
1440 { return m_pointer; }
1441
1445 inline Obj& operator*() const
1446 { return *m_pointer; }
1447};
1448
1453class YATE_API ObjList : public GenObject
1454{
1455 YNOCOPY(ObjList); // no automatic copies please
1456public:
1461
1465 virtual ~ObjList();
1466
1472 virtual void* getObject(const String& name) const;
1473
1478 unsigned int length() const;
1479
1484 unsigned int count() const;
1485
1490 inline GenObject* get() const
1491 { return m_obj; }
1492
1499 GenObject* set(const GenObject* obj, bool delold = true);
1500
1505 inline ObjList* next() const
1506 { return m_next; }
1507
1512 ObjList* last() const;
1513
1519
1525
1531 GenObject* at(int index) const;
1532
1538 ObjList* operator+(int index) const;
1539
1545 inline GenObject* operator[](signed int index) const
1546 { return at(index); }
1547
1553 inline GenObject* operator[](unsigned int index) const
1554 { return at(index); }
1555
1561 GenObject* operator[](const String& str) const;
1562
1568 ObjList* find(const GenObject* obj) const;
1569
1575 ObjList* find(const String& str) const;
1576
1582 int index(const GenObject* obj) const;
1583
1589 int index(const String& str) const;
1590
1597 ObjList* insert(const GenObject* obj, bool compact = true);
1598
1605 ObjList* append(const GenObject* obj, bool compact = true);
1606
1613 ObjList* setUnique(const GenObject* obj, bool compact = true);
1614
1620 GenObject* remove(bool delobj = true);
1621
1628 GenObject* remove(GenObject* obj, bool delobj = true);
1629
1636 GenObject* remove(const String& str, bool delobj = true);
1637
1641 void clear();
1642
1646 void compact();
1647
1652 inline bool autoDelete()
1653 { return m_delete; }
1654
1659 inline void setDelete(bool autodelete)
1660 { m_delete = autodelete; }
1661
1666 static const ObjList& empty();
1667
1680 void sort(int (*callbackCompare)(GenObject* obj1, GenObject* obj2, void* context), void* context = 0);
1681private:
1682 ObjList* m_next;
1683 GenObject* m_obj;
1684 bool m_delete;
1685};
1686
1691class YATE_API ObjVector : public GenObject
1692{
1693 YNOCOPY(ObjVector); // no automatic copies please
1694public:
1699 inline explicit ObjVector(bool autodelete = true)
1700 : m_length(0), m_objects(0), m_delete(autodelete)
1701 { }
1702
1708 ObjVector(unsigned int maxLen, bool autodelete = true);
1709
1717 ObjVector(ObjList& list, bool move = true, unsigned int maxLen = 0, bool autodelete = true);
1718
1722 virtual ~ObjVector();
1723
1729 virtual void* getObject(const String& name) const;
1730
1735 inline unsigned int length() const
1736 { return m_length; }
1737
1742 unsigned int count() const;
1743
1748 bool null() const;
1749
1755 inline GenObject* at(int index) const
1756 { return (index >= 0 && index < (int)m_length) ? m_objects[index] : 0; }
1757
1763 inline GenObject* operator[](signed int index) const
1764 { return at(index); }
1765
1771 inline GenObject* operator[](unsigned int index) const
1772 { return at(index); }
1773
1781 unsigned int assign(ObjList& list, bool move = true, unsigned int maxLen = 0);
1782
1788 GenObject* take(unsigned int index);
1789
1796 bool set(GenObject* obj, unsigned int index);
1797
1803 int index(const GenObject* obj) const;
1804
1810 int index(const String& str) const;
1811
1815 void clear();
1816
1821 inline bool autoDelete()
1822 { return m_delete; }
1823
1828 inline void setDelete(bool autodelete)
1829 { m_delete = autodelete; }
1830
1831private:
1832 unsigned int m_length;
1833 GenObject** m_objects;
1834 bool m_delete;
1835};
1836
1845class YATE_API Array : public RefObject
1846{
1847public:
1853 explicit Array(int columns = 0, int rows = 0);
1854
1858 virtual ~Array();
1859
1865 virtual void* getObject(const String& name) const;
1866
1873 bool addRow(ObjList* row = 0, int index = -1);
1874
1881 bool addColumn(ObjList* column = 0, int index = -1);
1882
1888 bool delRow(int index);
1889
1895 bool delColumn(int index);
1896
1903 GenObject* get(int column, int row) const;
1904
1911 GenObject* take(int column, int row);
1912
1920 bool set(GenObject* obj, int column, int row);
1921
1926 inline int getRows() const
1927 { return m_rows; }
1928
1933 inline int getColumns() const
1934 { return m_columns; }
1935
1943 inline ObjList* getColumn(int column) const {
1944 if (column >= 0 || column < m_columns)
1945 return static_cast<ObjList*>(m_obj[column]);
1946 return 0;
1947 }
1948
1949private:
1950 int m_rows;
1951 int m_columns;
1952 ObjList m_obj;
1953};
1954
1955class Regexp;
1956class StringMatchPrivate;
1957
1962class YATE_API UChar
1963{
1964public:
1965 enum Endianness {
1966 LE = 0,
1967 BE = 1,
1968 Native = 2,
1969 };
1974 inline explicit UChar(uint32_t code = 0)
1975 : m_chr(code)
1976 { encode(); }
1977
1982 inline explicit UChar(int32_t code)
1983 : m_chr((code < 0) ? 0 : code)
1984 { encode(); }
1985
1990 inline explicit UChar(signed char code)
1991 : m_chr((unsigned char)code)
1992 { encode(); }
1993
1998 inline explicit UChar(unsigned char code)
1999 : m_chr(code)
2000 { encode(); }
2001
2007 inline UChar& operator=(uint32_t code)
2008 { m_chr = code; encode(); return *this; }
2009
2015 inline UChar& operator=(char code)
2016 { m_chr = (unsigned char)code; encode(); return *this; }
2017
2022 inline uint32_t code() const
2023 { return m_chr; }
2024
2029 inline const char* c_str() const
2030 { return m_str; }
2031
2036 inline operator const char*() const
2037 { return m_str; };
2038
2046 bool decode(const char*& str, uint32_t maxChar = 0x10ffff, bool overlong = false);
2047
2056 bool decode(uint16_t*& buff, unsigned int& len, Endianness order, uint32_t maxChar = 0x10ffff);
2057
2065 bool decode(DataBlock& buff, Endianness order, uint32_t maxChar = 0x10ffff);
2066
2074 bool encode(uint16_t*& buff, unsigned int& len, Endianness order);
2075
2082 bool encode(DataBlock& buff, Endianness order);
2083
2094 static bool decode(String& out, uint16_t*& buff, unsigned int& len, Endianness order, bool checkBOM = false, uint32_t maxChar = 0x10ffff);
2095
2104 static bool encode(DataBlock& out, const char*& str, Endianness order, bool addBOM = false);
2105
2115 static bool encode(uint16_t*& buff, unsigned int& len, const char*& str, Endianness order, bool addBOM = false);
2116
2117private:
2118 void encode();
2119 uint32_t m_chr;
2120 char m_str[8];
2121};
2122
2130class YATE_API String : public GenObject
2131{
2132public:
2133 enum Align {
2134 Left = 0,
2135 Center,
2136 Right
2137 };
2138
2143
2149 String(const char* value, int len = -1);
2150
2156 explicit String(char value, unsigned int repeat = 1);
2157
2162 explicit String(int32_t value);
2163
2168 explicit String(uint32_t value);
2169
2174 explicit String(int64_t value);
2175
2180 explicit String(uint64_t value);
2181
2186 explicit String(bool value);
2187
2192 explicit String(double value);
2193
2198 String(const String& value);
2199
2204 String(const String* value);
2205
2209 virtual ~String();
2210
2216 virtual void* getObject(const String& name) const;
2217
2222 static const String& empty();
2223
2229 inline static const char* boolText(bool value)
2230 { return value ? "true" : "false"; }
2231
2236 inline const char* c_str() const
2237 { return m_string; }
2238
2243 inline const char* safe() const
2244 { return m_string ? m_string : ""; }
2245
2251 inline const char* safe(const char* defStr) const
2252 { return m_string ? m_string : (defStr ? defStr : ""); }
2253
2258 inline unsigned int length() const
2259 { return m_length; }
2260
2265 inline bool null() const
2266 { return !m_string; }
2267
2275 static int lenUtf8(const char* value, uint32_t maxChar = 0x10ffff, bool overlong = false);
2276
2283 inline int lenUtf8(uint32_t maxChar = 0x10ffff, bool overlong = false) const
2284 { return lenUtf8(m_string,maxChar,overlong); }
2285
2286
2294 int fixUtf8(const char* replace = 0, uint32_t maxChar = 0x10ffff, bool overlong = false);
2295
2301 unsigned int encodeFlags(const TokenDict* tokens) const;
2302
2308 uint64_t encodeFlags(const TokenDict64* tokens) const;
2309
2317 const String& decodeFlags(unsigned int flags, const TokenDict* tokens, bool unknownflag = true);
2318
2326 const String& decodeFlags(uint64_t flags, const TokenDict64* tokens, bool unknownflag = true);
2332 inline static bool checkBOM(const char* str)
2333 { return str && (str[0] == '\357') && (str[1] == '\273') && (str[2] == '\277'); }
2334
2339 inline bool checkBOM() const
2340 { return checkBOM(c_str()); }
2341
2347 inline static bool stripBOM(const char*& str)
2348 { return checkBOM(str) && (str += 3); }
2349
2355 inline static bool stripBOM(char*& str)
2356 { return checkBOM(str) && (str += 3); }
2357
2362 inline bool stripBOM()
2363 { return checkBOM(c_str()) && &(*this = c_str() + 3); }
2364
2369 inline unsigned int hash() const
2370 {
2371 if (m_hash == YSTRING_INIT_HASH)
2372 m_hash = hash(m_string);
2373 return m_hash;
2374 }
2375
2382 static unsigned int hash(const char* value, unsigned int h = 0);
2383
2387 void clear();
2388
2394 char at(int index) const;
2395
2402 String substr(int offs, int len = -1) const;
2403
2408
2414
2419 virtual const String& toString() const;
2420
2431 int toInteger(int defvalue = 0, int base = 0, int minvalue = INT_MIN,
2432 int maxvalue = INT_MAX, bool clamp = true) const;
2433
2441 int toInteger(const TokenDict* tokens, int defvalue = 0, int base = 0) const;
2442
2453 long int toLong(long int defvalue = 0, int base = 0, long int minvalue = LONG_MIN,
2454 long int maxvalue = LONG_MAX, bool clamp = true) const;
2455
2466 int64_t toInt64(int64_t defvalue = 0, int base = 0, int64_t minvalue = LLONG_MIN,
2467 int64_t maxvalue = LLONG_MAX, bool clamp = true) const;
2468
2479 uint64_t toUInt64(uint64_t defvalue = 0, int base = 0, uint64_t minvalue = 0,
2480 uint64_t maxvalue = ULLONG_MAX, bool clamp = true) const;
2481
2487 double toDouble(double defvalue = 0.0) const;
2488
2494 bool toBoolean(bool defvalue = false) const;
2495
2500 bool isBoolean() const;
2501
2507
2513
2519 inline char operator[](signed int index) const
2520 { return at(index); }
2521
2527 inline char operator[](unsigned int index) const
2528 { return at(index); }
2529
2534 inline operator const char*() const
2535 { return m_string; };
2536
2543 String& assign(const char* value, int len = -1);
2544
2551 String& assign(char value, unsigned int repeat = 1);
2552
2561 String& hexify(void* data, unsigned int len, char sep = 0, bool upCase = false);
2562
2567 inline String& operator=(const String& value)
2568 { return operator=(value.c_str()); }
2569
2575 inline String& operator=(const String* value)
2576 { return operator=(value ? value->c_str() : ""); }
2577
2583 String& operator=(const char* value);
2584
2589 String& operator=(char value);
2590
2595 String& operator=(int32_t value);
2596
2601 String& operator=(uint32_t value);
2602
2607 String& operator=(int64_t value);
2608
2613 String& operator=(uint64_t value);
2614
2619 inline String& operator=(bool value)
2620 { return operator=(boolText(value)); }
2621
2626 String& operator=(double value);
2627
2633 inline String& operator+=(const char* value)
2634 { return append(value,-1); }
2635
2640 String& operator+=(char value);
2641
2646 String& operator+=(int32_t value);
2647
2652 String& operator+=(uint32_t value);
2653
2658 String& operator+=(int64_t value);
2659
2664 String& operator+=(uint64_t value);
2665
2670 inline String& operator+=(bool value)
2671 { return operator+=(boolText(value)); }
2672
2677 String& operator+=(double value);
2678
2682 bool operator==(const char* value) const;
2683
2687 bool operator!=(const char* value) const;
2688
2692 inline bool operator==(const String& value) const
2693 { return (this == &value) || ((hash() == value.hash()) && operator==(value.c_str())); }
2694
2698 inline bool operator!=(const String& value) const
2699 { return (this != &value) && ((hash() != value.hash()) || operator!=(value.c_str())); }
2700
2704 bool operator&=(const char* value) const;
2705
2709 bool operator|=(const char* value) const;
2710
2714 inline String& operator<<(const char* value)
2715 { return operator+=(value); }
2716
2720 inline String& operator<<(char value)
2721 { return operator+=(value); }
2722
2726 inline String& operator<<(int32_t value)
2727 { return operator+=(value); }
2728
2732 inline String& operator<<(uint32_t value)
2733 { return operator+=(value); }
2734
2738 inline String& operator<<(int64_t value)
2739 { return operator+=(value); }
2740
2744 inline String& operator<<(uint64_t value)
2745 { return operator+=(value); }
2746
2750 inline String& operator<<(bool value)
2751 { return operator+=(value); }
2752
2756 inline String& operator<<(double value)
2757 { return operator+=(value); }
2758
2763 String& operator>>(const char* skip);
2764
2768 String& operator>>(char& store);
2769
2774
2778 String& operator>>(int& store);
2779
2783 String& operator>>(unsigned int& store);
2784
2788 String& operator>>(bool& store);
2789
2796 String& append(const char* value, int len);
2797
2804 String& append(const char* value, const char* separator = 0, bool force = false);
2805
2812 String& append(const ObjList* list, const char* separator = 0, bool force = false);
2813
2820 inline String& append(const ObjList& list, const char* separator = 0, bool force = false)
2821 { return append(&list,separator,force); }
2822
2828 String& append(double value, unsigned int decimals = 3);
2829
2835 String& printf(const char* format, ...) FORMAT_CHECK(2);
2836
2842 String& printf(unsigned int length, const char* format, ...) FORMAT_CHECK(3);
2843
2852 String& appendFixed(unsigned int fixedLength, const char* str, unsigned int len = -1, char fill = ' ', int align = Left);
2853
2861 inline String& appendFixed(unsigned int fixedLength, const String& str, char fill = ' ', int align = Left)
2862 { return appendFixed(fixedLength,str.c_str(),str.length(),fill,align); }
2863
2870 int find(char what, unsigned int offs = 0) const;
2871
2878 int find(const char* what, unsigned int offs = 0) const;
2879
2885 int rfind(char what) const;
2886
2892 int rfind(const char* what) const;
2893
2901 bool startsWith(const char* what, bool wordBreak = false, bool caseInsensitive = false) const;
2902
2910 bool endsWith(const char* what, bool wordBreak = false, bool caseInsensitive = false) const;
2911
2923 bool startSkip(const char* what, bool wordBreak = true, bool caseInsensitive = false);
2924
2931 String& extractTo(const char* sep, String& store);
2932
2939 String& extractTo(const char* sep, bool& store);
2940
2948 String& extractTo(const char* sep, int& store, int base = 0);
2949
2958 String& extractTo(const char* sep, int& store, const TokenDict* tokens, int base = 0);
2959
2966 String& extractTo(const char* sep, double& store);
2967
2973 virtual bool matches(const String& value) const
2974 { return operator==(value); }
2975
2981 bool matches(const Regexp& rexp);
2982
2988 int matchOffset(int index = 0) const;
2989
2995 int matchLength(int index = 0) const;
2996
3002 inline String matchString(int index = 0) const
3003 { return substr(matchOffset(index),matchLength(index)); }
3004
3010 String replaceMatches(const String& templ) const;
3011
3016 int matchCount() const;
3017
3024 ObjList* split(char separator, bool emptyOK = true) const;
3025
3032 ObjList* split(const Regexp& reg, bool emptyOK = true) const;
3033
3040 static String msgEscape(const char* str, char extraEsc = 0);
3041
3047 inline String msgEscape(char extraEsc = 0) const
3048 { return msgEscape(c_str(),extraEsc); }
3049
3057 static String msgUnescape(const char* str, int* errptr = 0, char extraEsc = 0);
3058
3065 inline String msgUnescape(int* errptr = 0, char extraEsc = 0) const
3066 { return msgUnescape(c_str(),errptr,extraEsc); }
3067
3074 static String sqlEscape(const char* str, char extraEsc = 0);
3075
3081 inline String sqlEscape(char extraEsc = 0) const
3082 { return sqlEscape(c_str(),extraEsc); }
3083
3091 static String uriEscape(const char* str, char extraEsc = 0, const char* noEsc = 0);
3092
3100 static String uriEscape(const char* str, const char* extraEsc, const char* noEsc = 0);
3101
3108 inline String uriEscape(char extraEsc = 0, const char* noEsc = 0) const
3109 { return uriEscape(c_str(),extraEsc,noEsc); }
3110
3117 static String uriUnescape(const char* str, int* errptr = 0);
3118
3124 inline String uriUnescape(int* errptr = 0) const
3125 { return uriUnescape(c_str(),errptr); }
3126
3133 static const String* atom(const String*& str, const char* val);
3134
3135protected:
3139 virtual void changed();
3140
3141private:
3142 void clearMatches();
3143 char* m_string;
3144 unsigned int m_length;
3145 // I hope every C++ compiler now knows about mutable...
3146 mutable unsigned int m_hash;
3147 StringMatchPrivate* m_matches;
3148};
3149
3155inline const char* c_str(const String* str)
3156 { return str ? str->c_str() : (const char*)0; }
3157
3163inline const char* c_safe(const char* str)
3164 { return str ? str : ""; }
3165
3171inline const char* c_safe(const String* str)
3172 { return str ? str->safe() : ""; }
3173
3179inline bool null(const char* str)
3180 { return !(str && *str); }
3181
3187inline bool null(const String* str)
3188 { return !str || str->null(); }
3189
3193YATE_API String operator+(const String& s1, const String& s2);
3194
3198YATE_API String operator+(const String& s1, const char* s2);
3199
3203YATE_API String operator+(const char* s1, const String& s2);
3204
3209inline const char *strcpy(String& dest, const char* src)
3210 { dest = src; return dest.c_str(); }
3211
3216inline const char *strcat(String& dest, const char* src)
3217 { dest += src; return dest.c_str(); }
3218
3227YATE_API int lookup(const char* str, const TokenDict* tokens, int defvalue = 0, int base = 0);
3228
3235YATE_API const char* lookup(int value, const TokenDict* tokens, const char* defvalue = 0);
3236
3245YATE_API int64_t lookup(const char* str, const TokenDict64* tokens, int64_t defvalue = 0, int base = 0);
3246
3253YATE_API const char* lookup(int64_t value, const TokenDict64* tokens, const char* defvalue = 0);
3254
3255class NamedList;
3256
3264YATE_API bool controlReturn(NamedList* params, bool ret, const char* retVal = 0);
3265
3270class YATE_API Regexp : public String
3271{
3272 YCLASS(Regexp,String)
3273 friend class String;
3274public:
3279
3286 explicit Regexp(const char* value, bool extended = false, bool insensitive = false);
3287
3292 Regexp(const Regexp& value);
3293
3297 virtual ~Regexp();
3298
3302 inline Regexp& operator=(const char* value)
3303 { String::operator=(value); return *this; }
3304
3309 inline bool compile() const
3310 { return m_regexp || (m_compile && doCompile()); }
3311
3317 bool matches(const char* value) const;
3318
3324 virtual bool matches(const String& value) const
3325 { return Regexp::matches(value.safe()); }
3326
3332 void setFlags(bool extended, bool insensitive);
3333
3338 bool isExtended() const;
3339
3344 bool isCaseInsensitive() const;
3345
3346protected:
3350 virtual void changed();
3351
3356 bool doCompile() const;
3357
3358private:
3359 void cleanup();
3360 bool matches(const char* value, StringMatchPrivate* matchlist) const;
3361 mutable void* m_regexp;
3362 mutable bool m_compile;
3363 int m_flags;
3364};
3365
3370class Atom
3371{
3372public:
3377 inline explicit Atom(const char* value)
3378 : m_atom(0)
3379 { String::atom(m_atom,value); }
3380
3385 inline operator const String&() const
3386 { return *m_atom; }
3387
3392 inline const String* operator->() const
3393 { return m_atom; }
3394
3395private:
3396 const String* m_atom;
3397};
3398
3403class YATE_API CapturedEvent : public String
3404{
3405 friend class Engine;
3406 YCLASS(CapturedEvent,String)
3407public:
3413 inline CapturedEvent(int level, const char* text)
3414 : String(text), m_level(level)
3415 { }
3416
3421 inline CapturedEvent(const CapturedEvent& original)
3422 : String(original), m_level(original.level())
3423 { }
3424
3429 inline int level() const
3430 { return m_level; }
3431
3432
3437 inline static bool capturing()
3438 { return s_capturing; }
3439
3444 inline static const ObjList& events()
3445 { return s_events; }
3446
3452 inline static void append(int level, const char* text)
3453 { if (text && *text) s_events.append(new CapturedEvent(level,text)); }
3454
3455protected:
3460 inline static ObjList& eventsRw()
3461 { return s_events; }
3462
3467 inline static void capturing(bool capture)
3468 { s_capturing = capture; }
3469
3470private:
3471 int m_level;
3472 static ObjList s_events;
3473 static bool s_capturing;
3474};
3475
3480class YATE_API NamedString : public String
3481{
3482 YNOCOPY(NamedString); // no automatic copies please
3483public:
3489 explicit NamedString(const char* name, const char* value = 0);
3490
3495 inline const String& name() const
3496 { return m_name; }
3497
3502 virtual const String& toString() const;
3503
3509 virtual void* getObject(const String& name) const;
3510
3514 inline NamedString& operator=(const char* value)
3515 { String::operator=(value); return *this; }
3516
3517private:
3518 NamedString(); // no default constructor please
3519 String m_name;
3520};
3521
3528class YATE_API NamedPointer : public NamedString
3529{
3530public:
3537 explicit NamedPointer(const char* name, GenObject* data = 0, const char* value = 0);
3538
3542 virtual ~NamedPointer();
3543
3548 inline GenObject* userData() const
3549 { return m_data; }
3550
3557
3563 void userData(GenObject* data);
3564
3570 inline void* userObject(const String& name) const
3571 { return m_data ? m_data->getObject(name) : 0; }
3572
3576 inline NamedPointer& operator=(const char* value)
3577 { NamedString::operator=(value); return *this; }
3578
3584 virtual void* getObject(const String& name) const;
3585
3586protected:
3590 virtual void changed();
3591
3592private:
3593 NamedPointer(); // no default constructor please
3594 GenObject* m_data;
3595};
3596
3601class YATE_API NamedCounter : public String
3602{
3603 YNOCOPY(NamedCounter); // no automatic copies please
3604public:
3609 explicit NamedCounter(const String& name);
3610
3615 inline bool enabled() const
3616 { return m_enabled; }
3617
3622 inline void enable(bool val)
3623 { m_enabled = val; }
3624
3629 int inc();
3630
3635 int dec();
3636
3641 inline int count() const
3642 { return m_count; }
3643
3644private:
3645 int m_count;
3646 bool m_enabled;
3647 Mutex* m_mutex;
3648};
3649
3657class YATE_API HashList : public GenObject
3658{
3659 YNOCOPY(HashList); // no automatic copies please
3660public:
3665 explicit HashList(unsigned int size = 17);
3666
3670 virtual ~HashList();
3671
3677 virtual void* getObject(const String& name) const;
3678
3683 inline unsigned int length() const
3684 { return m_size; }
3685
3690 unsigned int count() const;
3691
3698 inline ObjList* getList(unsigned int index) const
3699 { return (index < m_size) ? m_lists[index] : 0; }
3700
3706 inline ObjList* getHashList(unsigned int hash) const
3707 { return getList(hash % m_size); }
3708
3714 inline ObjList* getHashList(const String& str) const
3715 { return getHashList(str.hash()); }
3716
3722 GenObject* operator[](const String& str) const;
3723
3730 ObjList* find(const GenObject* obj) const;
3731
3738 ObjList* find(const GenObject* obj, unsigned int hash) const;
3739
3745 ObjList* find(const String& str) const;
3746
3753
3760 ObjList* append(const GenObject* obj, unsigned int hash);
3761
3769 GenObject* remove(GenObject* obj, bool delobj = true, bool useHash = false);
3770
3777 inline GenObject* remove(const String& str, bool delobj = true)
3778 {
3779 ObjList* n = find(str);
3780 return n ? n->remove(delobj) : 0;
3781 }
3782
3790 inline GenObject* remove(GenObject* obj, unsigned int hash, bool delobj = true)
3791 {
3792 ObjList* n = find(obj,hash);
3793 return n ? n->remove(delobj) : 0;
3794 }
3795
3799 void clear();
3800
3807 bool resync(GenObject* obj);
3808
3814 bool resync();
3815
3816private:
3817 unsigned int m_size;
3818 ObjList** m_lists;
3819};
3820
3827class YATE_API ListIterator
3828{
3829 YNOCOPY(ListIterator); // no automatic copies please
3830public:
3837 ListIterator(ObjList& list, int offset = 0);
3838
3845 ListIterator(HashList& list, int offset = 0);
3846
3851
3856 inline unsigned int length() const
3857 { return m_length; }
3858
3862 void clear();
3863
3869 void assign(ObjList& list, int offset = 0);
3870
3876 void assign(HashList& list, int offset = 0);
3877
3884 GenObject* get(unsigned int index) const;
3885
3899
3904 inline bool eof() const
3905 { return m_current >= m_length; }
3906
3910 inline void reset()
3911 { m_current = 0; }
3912
3913private:
3914 ObjList* m_objList;
3915 HashList* m_hashList;
3916 GenObject** m_objects;
3917 unsigned int* m_hashes;
3918 unsigned int m_length;
3919 unsigned int m_current;
3920};
3921
3926class YATE_API Time
3927{
3928public:
3932 inline Time()
3933 : m_time(now())
3934 { }
3935
3940 inline Time(u_int64_t usec)
3941 : m_time(usec)
3942 { }
3943
3948 inline explicit Time(const struct timeval* tv)
3949 : m_time(fromTimeval(tv))
3950 { }
3951
3956 inline explicit Time(const struct timeval& tv)
3957 : m_time(fromTimeval(tv))
3958 { }
3959
3964 inline ~Time()
3965 { }
3966
3971 inline u_int32_t sec() const
3972 { return (u_int32_t)((m_time+500000) / 1000000); }
3973
3978 inline u_int64_t msec() const
3979 { return (m_time+500) / 1000; }
3980
3985 inline u_int64_t usec() const
3986 { return m_time; }
3987
3991 inline operator u_int64_t() const
3992 { return m_time; }
3993
3997 inline Time& operator=(u_int64_t usec)
3998 { m_time = usec; return *this; }
3999
4003 inline Time& operator+=(int64_t delta)
4004 { m_time += delta; return *this; }
4005
4009 inline Time& operator-=(int64_t delta)
4010 { m_time -= delta; return *this; }
4011
4016 inline void toTimeval(struct timeval* tv) const
4017 { toTimeval(tv, m_time); }
4018
4024 static void toTimeval(struct timeval* tv, u_int64_t usec);
4025
4031 static u_int64_t fromTimeval(const struct timeval* tv);
4032
4038 inline static u_int64_t fromTimeval(const struct timeval& tv)
4039 { return fromTimeval(&tv); }
4040
4045 static u_int64_t now();
4046
4051 static u_int64_t msecNow();
4052
4057 static u_int32_t secNow();
4058
4072 static unsigned int toEpoch(int year, unsigned int month, unsigned int day,
4073 unsigned int hour, unsigned int minute, unsigned int sec, int offset = 0);
4074
4087 static bool toDateTime(unsigned int epochTimeSec, int& year, unsigned int& month,
4088 unsigned int& day, unsigned int& hour, unsigned int& minute, unsigned int& sec,
4089 unsigned int* wDay = 0);
4090
4098 static uint32_t toNtp(uint32_t sec, uint32_t* over = 0, bool rfc2030 = true);
4099
4106 inline uint32_t toNtp(uint32_t* over = 0, bool rfc2030 = true)
4107 { return toNtp(sec(),over,rfc2030); }
4108
4117 static uint32_t fromNtp(uint32_t val, uint32_t* under = 0, bool rfc2030 = true);
4118
4130 static unsigned int toString(char* buf, uint64_t time, int frac = 0);
4131
4143 static inline unsigned int appendTo(String& buf, uint64_t time, int frac = 0) {
4144 char tmp[30];
4145 unsigned int n = toString(tmp,time,frac);
4146 if (n)
4147 buf.append(tmp,n);
4148 return n;
4149 }
4150
4160 static uint64_t toEpoch(const char* buf, unsigned int len, int frac = 0);
4161
4167 static inline bool isLeap(unsigned int year)
4168 { return (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)); }
4169
4175 static int timeZone(u_int32_t when = secNow());
4176
4177private:
4178 u_int64_t m_time;
4179};
4180
4185class YATE_API Random
4186{
4187public:
4192 inline Random(u_int32_t seed = Time::now() & 0xffffffff)
4193 : m_random(seed)
4194 { }
4195
4200 inline u_int32_t get() const
4201 { return m_random; }
4202
4207 inline void set(u_int32_t seed)
4208 { m_random = seed; }
4209
4214 u_int32_t next();
4215
4220 static long int random();
4221
4226 static void srandom(unsigned int seed);
4227
4228private:
4229 u_int32_t m_random;
4230};
4231
4236class YATE_API DataBlock : public GenObject
4237{
4238public:
4239
4244 DataBlock(unsigned int overAlloc = 0);
4245
4250 DataBlock(const DataBlock& value);
4251
4257 DataBlock(const DataBlock& value, unsigned int overAlloc);
4258
4266 DataBlock(void* value, unsigned int len, bool copyData = true, unsigned int overAlloc = 0);
4267
4271 virtual ~DataBlock();
4272
4278 virtual void* getObject(const String& name) const;
4279
4283 static const DataBlock& empty();
4284
4289 inline void* data() const
4290 { return m_data; }
4291
4298 inline unsigned char* data(unsigned int offs, unsigned int len = 1) const
4299 { return (offs + len <= m_length) ? (static_cast<unsigned char*>(m_data) + offs) : 0; }
4300
4307 inline int at(unsigned int offs, int defvalue = -1) const
4308 { return (offs < m_length) ? static_cast<unsigned char*>(m_data)[offs] : defvalue; }
4309
4314 inline bool null() const
4315 { return !m_data; }
4316
4321 inline unsigned int length() const
4322 { return m_length; }
4323
4328 inline unsigned int overAlloc() const
4329 { return m_overAlloc; }
4330
4335 inline void overAlloc(unsigned int bytes)
4336 { m_overAlloc = bytes; }
4337
4342 void clear(bool deleteData = true);
4343
4351 DataBlock& assign(void* value, unsigned int len, bool copyData = true, unsigned int allocated = 0);
4352
4358 inline void append(void* value, unsigned int len) {
4359 DataBlock tmp(value,len,false);
4360 append(tmp);
4361 tmp.clear(false);
4362 }
4363
4368 void append(const DataBlock& value);
4369
4374 void append(const String& value);
4375
4380 void insert(const DataBlock& value);
4381
4386 inline void resize(unsigned int len) {
4387 if (len != length())
4388 assign(0,len);
4389 }
4390
4395 void truncate(unsigned int len);
4396
4401 void cut(int len);
4402
4408 inline int operator[](signed int index) const
4409 { return at(index); }
4410
4416 inline int operator[](unsigned int index) const
4417 { return at(index); }
4418
4423
4427 inline DataBlock& operator+=(const DataBlock& value)
4428 { append(value); return *this; }
4429
4433 inline DataBlock& operator+=(const String& value)
4434 { append(value); return *this; }
4435
4444 bool convert(const DataBlock& src, const String& sFormat,
4445 const String& dFormat, unsigned maxlen = 0);
4446
4457 bool unHexify(const char* data, unsigned int len, char sep);
4458
4468 bool unHexify(const char* data, unsigned int len);
4469
4476 inline bool unHexify(const String& data)
4477 { return unHexify(data.c_str(),data.length()); }
4478
4484 String sqlEscape(char extraEsc) const;
4485
4486private:
4487 unsigned int allocLen(unsigned int len) const;
4488 void* m_data;
4489 unsigned int m_length;
4490 unsigned int m_allocated;
4491 unsigned int m_overAlloc;
4492};
4493
4498class YATE_API Hasher
4499{
4500public:
4504 virtual ~Hasher();
4505
4509 virtual void clear() = 0;
4510
4515 virtual void finalize() = 0;
4516
4522 virtual const unsigned char* rawDigest() = 0;
4523
4529 inline const String& hexDigest()
4530 { finalize(); return m_hex; }
4531
4538 inline bool update(const void* buf, unsigned int len)
4539 { return updateInternal(buf,len); }
4540
4546 inline bool update(const DataBlock& data)
4547 { return updateInternal(data.data(), data.length()); }
4548
4554 inline bool update(const String& str)
4555 { return updateInternal(str.c_str(), str.length()); }
4556
4561 inline Hasher& operator<<(const String& value)
4562 { update(value); return *this; }
4563
4568 inline Hasher& operator<<(const DataBlock& data)
4569 { update(data); return *this; }
4570
4575 Hasher& operator<<(const char* value);
4576
4584 bool hmacStart(DataBlock& opad, const void* key, unsigned int keyLen);
4585
4592 inline bool hmacStart(DataBlock& opad, const DataBlock& key)
4593 { return hmacStart(opad,key.data(),key.length()); }
4594
4601 inline bool hmacStart(DataBlock& opad, const String& key)
4602 { return hmacStart(opad,key.c_str(),key.length()); }
4603
4609 bool hmacFinal(const DataBlock& opad);
4610
4619 bool hmac(const void* key, unsigned int keyLen, const void* msg, unsigned int msgLen);
4620
4627 inline bool hmac(const DataBlock& key, const DataBlock& msg)
4628 { return hmac(key.data(),key.length(),msg.data(),msg.length()); }
4629
4636 inline bool hmac(const String& key, const String& msg)
4637 { return hmac(key.c_str(),key.length(),msg.c_str(),msg.length()); }
4638
4643 virtual unsigned int hashLength() const = 0;
4644
4649 virtual unsigned int hmacBlockSize() const;
4650
4651protected:
4655 inline Hasher()
4656 : m_private(0)
4657 { }
4658
4665 virtual bool updateInternal(const void* buf, unsigned int len) = 0;
4666
4667 void* m_private;
4668 String m_hex;
4669};
4670
4675class YATE_API MD5 : public Hasher
4676{
4677public:
4682
4687 MD5(const MD5& original);
4688
4694 MD5(const void* buf, unsigned int len);
4695
4700 MD5(const DataBlock& data);
4701
4706 MD5(const String& str);
4707
4711 MD5& operator=(const MD5& original);
4712
4716 virtual ~MD5();
4717
4721 virtual void clear();
4722
4727 virtual void finalize();
4728
4734 virtual const unsigned char* rawDigest();
4735
4740 inline static unsigned int rawLength()
4741 { return 16; }
4742
4747 virtual unsigned int hashLength() const
4748 { return 16; }
4749
4750protected:
4751 bool updateInternal(const void* buf, unsigned int len);
4752
4753private:
4754 void init();
4755 unsigned char m_bin[16];
4756};
4757
4762class YATE_API SHA1 : public Hasher
4763{
4764public:
4769
4774 SHA1(const SHA1& original);
4775
4781 SHA1(const void* buf, unsigned int len);
4782
4787 SHA1(const DataBlock& data);
4788
4793 SHA1(const String& str);
4794
4798 SHA1& operator=(const SHA1& original);
4799
4803 virtual ~SHA1();
4804
4808 virtual void clear();
4809
4814 virtual void finalize();
4815
4821 virtual const unsigned char* rawDigest();
4822
4827 inline static unsigned int rawLength()
4828 { return 20; }
4829
4834 virtual unsigned int hashLength() const
4835 { return 20; }
4836
4845 static bool fips186prf(DataBlock& out, const DataBlock& seed, unsigned int len);
4846
4847protected:
4848 bool updateInternal(const void* buf, unsigned int len);
4849
4850private:
4851 void init();
4852 unsigned char m_bin[20];
4853};
4854
4859class YATE_API SHA256 : public Hasher
4860{
4861public:
4866
4871 SHA256(const SHA256& original);
4872
4878 SHA256(const void* buf, unsigned int len);
4879
4884 SHA256(const DataBlock& data);
4885
4890 SHA256(const String& str);
4891
4895 SHA256& operator=(const SHA256& original);
4896
4900 virtual ~SHA256();
4901
4905 virtual void clear();
4906
4911 virtual void finalize();
4912
4918 virtual const unsigned char* rawDigest();
4919
4924 inline static unsigned int rawLength()
4925 { return 32; }
4926
4931 virtual unsigned int hashLength() const
4932 { return 32; }
4933
4934protected:
4935 bool updateInternal(const void* buf, unsigned int len);
4936
4937private:
4938 void init();
4939 unsigned char m_bin[32];
4940};
4941
4946class YATE_API Base64 : public DataBlock
4947{
4948 YNOCOPY(Base64); // no automatic copies please
4949public:
4953 inline Base64()
4954 { }
4955
4962 inline Base64(void* src, unsigned int len, bool copyData = true)
4963 : DataBlock(src,len,copyData)
4964 { }
4965
4975 void encode(String& dest, unsigned int lineLen = 0, bool lineAtEnd = false);
4976
4988 bool decode(DataBlock& dest, bool liberal = true);
4989
4993 inline Base64& operator<<(const String& value)
4994 { append(value); return *this; }
4995
4999 inline Base64& operator<<(const DataBlock& data)
5000 { append(data); return *this; }
5001
5005 inline Base64& operator<<(const char* value)
5006 { return operator<<(String(value)); }
5007};
5008
5009class NamedIterator;
5010
5015class YATE_API NamedList : public String
5016{
5017 friend class NamedIterator;
5018public:
5023 explicit NamedList(const char* name);
5024
5029 NamedList(const NamedList& original);
5030
5037 NamedList(const char* name, const NamedList& original, const String& prefix);
5038
5045
5051 virtual void* getObject(const String& name) const;
5052
5057 inline unsigned int length() const
5058 { return m_params.length(); }
5059
5064 inline unsigned int count() const
5065 { return m_params.count(); }
5066
5070 inline void clearParams()
5071 { m_params.clear(); }
5072
5079
5087 NamedList& addParam(const char* name, const char* value, bool emptyOK = true);
5088
5095 {
5096 if (param)
5097 m_params.setUnique(param);
5098 return *this;
5099 }
5100
5107 NamedList& setParam(const String& name, const char* value);
5108
5115 NamedList& clearParam(const String& name, char childSep = 0);
5116
5123 NamedList& clearParam(NamedString* param, bool delParam = true);
5124
5132 NamedList& copyParam(const NamedList& original, const String& name, char childSep = 0);
5133
5139 NamedList& copyParams(const NamedList& original);
5140
5148 NamedList& copyParams(const NamedList& original, ObjList* list, char childSep = 0);
5149
5157 NamedList& copyParams(const NamedList& original, const String& list, char childSep = 0);
5158
5167 NamedList& copySubParams(const NamedList& original, const String& prefix,
5168 bool skipPrefix = true, bool replace = false);
5169
5175 bool hasSubParams(const char* prefix) const;
5176
5182 int getIndex(const NamedString* param) const;
5183
5189 int getIndex(const String& name) const;
5190
5196 NamedString* getParam(const String& name) const;
5197
5203 NamedString* getParam(unsigned int index) const;
5204
5210 const String& operator[](const String& name) const;
5211
5218 const char* getValue(const String& name, const char* defvalue = 0) const;
5219
5230 int getIntValue(const String& name, int defvalue = 0, int minvalue = INT_MIN,
5231 int maxvalue = INT_MAX, bool clamp = true) const;
5232
5240 int getIntValue(const String& name, const TokenDict* tokens, int defvalue = 0) const;
5241
5252 int64_t getInt64Value(const String& name, int64_t defvalue = 0, int64_t minvalue = LLONG_MIN,
5253 int64_t maxvalue = LLONG_MAX, bool clamp = true) const;
5254
5265 uint64_t getUInt64Value(const String& name, uint64_t defvalue = 0, uint64_t minvalue = 0,
5266 uint64_t maxvalue = ULLONG_MAX, bool clamp = true) const;
5267
5274 double getDoubleValue(const String& name, double defvalue = 0.0) const;
5275
5282 bool getBoolValue(const String& name, bool defvalue = false) const;
5283
5291 int replaceParams(String& str, bool sqlEsc = false, char extraEsc = 0) const;
5292
5301 void dump(String& str, const char* separator, char quote = 0, bool force = false) const;
5302
5307 static const NamedList& empty();
5308
5314 { return &m_params; }
5315
5320 inline const ObjList* paramList() const
5321 { return &m_params; }
5322
5323private:
5324 NamedList(); // no default constructor please
5325 ObjList m_params;
5326};
5327
5333class YATE_API NamedIterator
5334{
5335public:
5340 inline NamedIterator(const NamedList& list)
5341 : m_list(&list), m_item(list.m_params.skipNull())
5342 { }
5343
5348 inline NamedIterator(const NamedIterator& original)
5349 : m_list(original.m_list), m_item(original.m_item)
5350 { }
5351
5356 inline NamedIterator& operator=(const NamedList& list)
5357 { m_list = &list; m_item = list.m_params.skipNull(); return *this; }
5358
5363 inline NamedIterator& operator=(const NamedIterator& original)
5364 { m_list = original.m_list; m_item = original.m_item; return *this; }
5365
5371
5375 inline bool eof() const
5376 { return !m_item; }
5377
5381 inline void reset()
5382 { m_item = m_list->m_params.skipNull(); }
5383
5384private:
5385 NamedIterator(); // no default constructor please
5386 const NamedList* m_list;
5387 const ObjList* m_item;
5388};
5389
5395class YATE_API URI : public String
5396{
5397public:
5402
5407 URI(const URI& uri);
5408
5413 explicit URI(const String& uri);
5414
5419 explicit URI(const char* uri);
5420
5429 URI(const char* proto, const char* user, const char* host, int port = 0, const char* desc = 0);
5430
5434 void parse() const;
5435
5440 inline URI& operator=(const URI& value)
5441 { String::operator=(value); return *this; }
5442
5447 inline URI& operator=(const String& value)
5448 { String::operator=(value); return *this; }
5449
5454 inline URI& operator=(const char* value)
5455 { String::operator=(value); return *this; }
5456
5461 inline const String& getDescription() const
5462 { parse(); return m_desc; }
5463
5468 inline const String& getProtocol() const
5469 { parse(); return m_proto; }
5470
5475 inline const String& getUser() const
5476 { parse(); return m_user; }
5477
5482 inline const String& getHost() const
5483 { parse(); return m_host; }
5484
5489 inline int getPort() const
5490 { parse(); return m_port; }
5491
5496 inline const String& getExtra() const
5497 { parse(); return m_extra; }
5498
5499protected:
5505 virtual void changed();
5506 mutable bool m_parsed;
5507 mutable String m_desc;
5508 mutable String m_proto;
5509 mutable String m_user;
5510 mutable String m_host;
5511 mutable String m_extra;
5512 mutable int m_port;
5513};
5514
5515class MutexPrivate;
5516class SemaphorePrivate;
5517class ThreadPrivate;
5518
5523class YATE_API Lockable
5524{
5525public:
5529 virtual ~Lockable();
5530
5536 virtual bool lock(long maxwait = -1) = 0;
5537
5542 virtual bool unlock() = 0;
5543
5549 virtual bool locked() const = 0;
5550
5556 virtual bool check(long maxwait = -1);
5557
5564 virtual bool unlockAll();
5565
5571 static void wait(unsigned long maxwait);
5572
5577 static unsigned long wait();
5578
5585 static void startUsingNow();
5586
5593 static void enableSafety(bool safe = true);
5594
5599 static bool safety();
5600};
5601
5606class YATE_API Mutex : public Lockable
5607{
5608 friend class MutexPrivate;
5609public:
5616 explicit Mutex(bool recursive = false, const char* name = 0);
5617
5622 Mutex(const Mutex& original);
5623
5628
5633 Mutex& operator=(const Mutex& original);
5634
5640 virtual bool lock(long maxwait = -1);
5641
5646 virtual bool unlock();
5647
5653 virtual bool locked() const;
5654
5659 const char* owner() const;
5660
5665 bool recursive() const;
5666
5671 static int count();
5672
5677 static int locks();
5678
5683 static bool efficientTimedLock();
5684
5685private:
5686 MutexPrivate* privDataCopy() const;
5687 MutexPrivate* m_private;
5688};
5689
5696class YATE_API MutexPool
5697{
5698public:
5709 MutexPool(unsigned int len = 13, bool recursive = false, const char* name = 0);
5710
5715
5723 inline unsigned int index(void* ptr) const
5724 { return ((unsigned int)(unsigned long)ptr) % m_length; }
5725
5733 inline Mutex* mutex(void* ptr) const
5734 { return m_data[index(ptr)]; }
5735
5741 inline Mutex* mutex(unsigned int idx) const
5742 { return m_data[idx % m_length]; }
5743
5744private:
5745 String* m_name; // Mutex names
5746 Mutex** m_data; // The array
5747 unsigned int m_length; // Array length
5748};
5749
5754class YATE_API Semaphore : public Lockable
5755{
5756 friend class SemaphorePrivate;
5757public:
5764 explicit Semaphore(unsigned int maxcount = 1, const char* name = 0,
5765 unsigned int initialCount = 1);
5766
5771 Semaphore(const Semaphore& original);
5772
5777
5782 Semaphore& operator=(const Semaphore& original);
5783
5789 virtual bool lock(long maxwait = -1);
5790
5795 virtual bool unlock();
5796
5802 virtual bool locked() const;
5803
5808 static int count();
5809
5814 static int locks();
5815
5820 static bool efficientTimedLock();
5821
5822private:
5823 SemaphorePrivate* privDataCopy() const;
5824 SemaphorePrivate* m_private;
5825};
5826
5832class YATE_API Lock
5833{
5834 YNOCOPY(Lock); // no automatic copies please
5835public:
5841 inline Lock(Lockable& lck, long maxwait = -1)
5842 { m_lock = lck.lock(maxwait) ? &lck : 0; }
5843
5849 inline Lock(Lockable* lck, long maxwait = -1)
5850 { m_lock = (lck && lck->lock(maxwait)) ? lck : 0; }
5851
5855 inline ~Lock()
5856 { if (m_lock) m_lock->unlock(); }
5857
5862 inline Lockable* locked() const
5863 { return m_lock; }
5864
5868 inline void drop()
5869 { if (m_lock) m_lock->unlock(); m_lock = 0; }
5870
5877 inline bool acquire(Lockable* lck, long maxwait = -1)
5878 { return (lck && (lck == m_lock)) ||
5879 (drop(),(lck && (m_lock = lck->lock(maxwait) ? lck : 0))); }
5880
5887 inline bool acquire(Lockable& lck, long maxwait = -1)
5888 { return acquire(&lck,maxwait); }
5889
5890private:
5891 Lockable* m_lock;
5892
5894 inline void* operator new(size_t);
5895
5897 inline void* operator new[](size_t);
5898};
5899
5906class YATE_API Lock2
5907{
5908 YNOCOPY(Lock2); // no automatic copies please
5909public:
5916 inline Lock2(Mutex* mx1, Mutex* mx2, long maxwait = -1)
5917 : m_mx1(0), m_mx2(0)
5918 { lock(mx1,mx2,maxwait); }
5919
5926 inline Lock2(Mutex& mx1, Mutex& mx2, long maxwait = -1)
5927 : m_mx1(0), m_mx2(0)
5928 { lock(&mx1,&mx2,maxwait); }
5929
5933 inline ~Lock2()
5934 { drop(); }
5935
5940 inline bool locked() const
5941 { return m_mx1 != 0; }
5942
5950 bool lock(Mutex* mx1, Mutex* mx2, long maxwait = -1);
5951
5959 inline bool lock(Mutex& mx1, Mutex& mx2, long maxwait = -1)
5960 { return lock(&mx1,&mx2,maxwait); }
5961
5965 void drop();
5966
5967private:
5968 Mutex* m_mx1;
5969 Mutex* m_mx2;
5970
5972 inline void* operator new(size_t);
5973
5975 inline void* operator new[](size_t);
5976};
5977
5983class YATE_API Runnable
5984{
5985public:
5990 virtual void run() = 0;
5991
5995 virtual ~Runnable();
5996};
5997
6004class YATE_API Thread : public Runnable
6005{
6006 friend class ThreadPrivate;
6007 friend class MutexPrivate;
6008 friend class SemaphorePrivate;
6009 YNOCOPY(Thread); // no automatic copies please
6010public:
6015 Lowest,
6016 Low,
6017 Normal,
6018 High,
6019 Highest
6020 };
6021
6025 virtual void cleanup();
6026
6031 bool startup();
6032
6037 bool error() const;
6038
6043 bool running() const;
6044
6051 int getAffinity(DataBlock& outCpuMask);
6052
6060 int setAffinity(const String& cpus);
6061
6068 int setAffinity(const DataBlock& mask);
6069
6074 inline int locks() const
6075 { return m_locks; }
6076
6081 inline bool locked() const
6082 { return m_locking || m_locks; }
6083
6088 const char* name() const;
6089
6094 static const char* currentName();
6095
6102 static int getCurrentAffinity(DataBlock& outCpuMask);
6103
6110 static int getCurrentAffinity(String& outCpus, bool hex = false);
6111
6119 static int setCurrentAffinity(const String& cpus);
6120
6127 static int setCurrentAffinity(const DataBlock& mask);
6128
6137 static bool parseCPUMask(const String& cpus, DataBlock& mask);
6138
6145 static void printCPUMask(const DataBlock& mask, String& str, bool hexa = true);
6146
6152 static void yield(bool exitCheck = false);
6153
6159 static void idle(bool exitCheck = false);
6160
6166 static void sleep(unsigned int sec, bool exitCheck = false);
6167
6173 static void msleep(unsigned long msec, bool exitCheck = false);
6174
6181 static void usleep(unsigned long usec, bool exitCheck = false);
6182
6187 static unsigned long idleUsec();
6188
6193 static unsigned long idleMsec();
6194
6199 static void idleMsec(unsigned long msec);
6200
6206 static Thread* current();
6207
6212 static int count();
6213
6219 static bool check(bool exitNow = true);
6220
6224 static void exit();
6225
6230 void cancel(bool hard = false);
6231
6236 inline bool isCurrent() const
6237 { return current() == this; }
6238
6244
6251
6257 static NamedCounter* getCurrentObjCounter(bool always = false);
6258
6265
6272 static Priority priority(const char* name, Priority defvalue = Normal);
6273
6279 static const char* priority(Priority prio);
6280
6285 static void killall();
6286
6291 static void preExec();
6292
6298 static int lastError();
6299
6306 static inline bool errorString(String& buffer)
6307 { return errorString(buffer,lastError()); }
6308
6319 static bool errorString(String& buffer, int code);
6320
6321protected:
6327 Thread(const char *name = 0, Priority prio = Normal);
6328
6334 Thread(const char *name, const char* prio);
6335
6339 virtual ~Thread();
6340
6341private:
6342 ThreadPrivate* m_private;
6343 int m_locks;
6344 bool m_locking;
6345};
6346
6351class YATE_API TempObjectCounter
6352{
6353 YNOCOPY(TempObjectCounter); // no automatic copies please
6354public:
6361 : m_saved(0), m_enabled(enable)
6362 { if (m_enabled) m_saved = Thread::setCurrentObjCounter(counter); }
6363
6369 inline TempObjectCounter(const GenObject* obj, bool enable = GenObject::getObjCounting())
6370 : m_saved(0), m_enabled(enable && obj)
6371 { if (m_enabled) m_saved = Thread::setCurrentObjCounter(obj->getObjCounter()); }
6372
6378 inline TempObjectCounter(const GenObject& obj, bool enable = GenObject::getObjCounting())
6379 : m_saved(0), m_enabled(enable)
6380 { if (m_enabled) m_saved = Thread::setCurrentObjCounter(obj.getObjCounter()); }
6381
6386 { if (m_enabled) Thread::setCurrentObjCounter(m_saved); }
6387
6388private:
6389 NamedCounter* m_saved;
6390 bool m_enabled;
6391};
6392
6393class Socket;
6394
6399class YATE_API SocketAddr : public GenObject
6400{
6401 YCLASS(SocketAddr,GenObject)
6402public:
6406 enum Family {
6407 Unknown = AF_UNSPEC,
6408 IPv4 = AF_INET,
6409 AfMax = AF_MAX,
6410 AfUnsupported = AfMax,
6411#ifdef AF_INET6
6412 IPv6 = AF_INET6,
6413#else
6414 IPv6 = AfUnsupported + 1,
6415#endif
6416#ifdef HAS_AF_UNIX
6417 Unix = AF_UNIX,
6418#else
6419 Unix = AfUnsupported + 2,
6420#endif
6421 };
6422
6426 inline SocketAddr()
6427 : m_address(0), m_length(0)
6428 { }
6429
6434 inline SocketAddr(const SocketAddr& value)
6435 : GenObject(),
6436 m_address(0), m_length(0)
6437 { assign(value.address(),value.length()); }
6438
6444 explicit SocketAddr(int family, const void* raw = 0);
6445
6451 SocketAddr(const struct sockaddr* addr, socklen_t len = 0);
6452
6456 virtual ~SocketAddr();
6457
6462 inline SocketAddr& operator=(const SocketAddr& value)
6463 { assign(value.address(),value.length()); return *this; }
6464
6470 bool operator==(const SocketAddr& other) const;
6471
6477 inline bool operator!=(const SocketAddr& other) const
6478 { return !operator==(other); }
6479
6483 void clear();
6484
6490 bool assign(int family);
6491
6497 void assign(const struct sockaddr* addr, socklen_t len = 0);
6498
6504 bool assign(const DataBlock& addr);
6505
6511 bool local(const SocketAddr& remote);
6512
6517 inline bool valid() const
6518 { return m_length && m_address; }
6519
6524 inline bool null() const
6525 { return !(m_length && m_address); }
6526
6531 inline int family() const
6532 { return m_address ? m_address->sa_family : 0; }
6533
6538 inline const char* familyName() const
6539 { return lookupFamily(family()); }
6540
6545 inline unsigned int scopeId() const
6546 { return scopeId(address()); }
6547
6553 inline bool scopeId(unsigned int val)
6554 { return scopeId(address(),val); }
6555
6560 inline const String& host() const
6561 { return m_host; }
6562
6567 inline const String& addr() const {
6568 if (!m_addr)
6569 updateAddr();
6570 return m_addr;
6571 }
6572
6579 virtual bool host(const String& name);
6580
6585 int port() const;
6586
6592 bool port(int newport);
6593
6598 inline struct sockaddr* address() const
6599 { return m_address; }
6600
6605 inline socklen_t length() const
6606 { return m_length; }
6607
6612 inline bool isNullAddr() const
6613 { return isNullAddr(m_host,family()); }
6614
6620 int copyAddr(DataBlock& addr) const;
6621
6627 static bool supports(int family);
6628
6634 static int family(const String& addr);
6635
6642 static bool stringify(String& buf, struct sockaddr* addr);
6643
6652 static inline int unStringify(uint8_t* buf, const String& host,
6653 int family = Unknown) {
6654 SocketAddr sa(family);
6655 return sa.host(host) ? copyAddr(buf,sa.address()) : Unknown;
6656 }
6657
6665 static int copyAddr(uint8_t* buf, struct sockaddr* addr);
6666
6672 static inline unsigned int scopeId(struct sockaddr* addr) {
6673#ifdef AF_INET6
6674 if (addr && addr->sa_family == AF_INET6)
6675 return ((struct sockaddr_in6*)addr)->sin6_scope_id;
6676#endif
6677 return 0;
6678 }
6679
6686 static inline bool scopeId(struct sockaddr* addr, unsigned int val) {
6687#ifdef AF_INET6
6688 if (addr && addr->sa_family == AF_INET6) {
6689 ((struct sockaddr_in6*)addr)->sin6_scope_id = val;
6690 return true;
6691 }
6692#endif
6693 return false;
6694 }
6695
6703 static String& appendAddr(String& buf, const String& addr, int family = Unknown);
6704
6713 static inline String& appendTo(String& buf, const String& addr, int port,
6714 int family = Unknown) {
6715 appendAddr(buf,addr,family) << ":" << port;
6716 return buf;
6717 }
6718
6726 static inline String appendTo(const String& addr, int port, int family = Unknown) {
6727 String buf;
6728 appendTo(buf,addr,port,family);
6729 return buf;
6730 }
6731
6738 static bool isNullAddr(const String& addr, int family = Unknown);
6739
6748 static void splitIface(const String& buf, String& addr, String* iface = 0);
6749
6761 static void split(const String& buf, String& addr, int& port, bool portPresent = false);
6762
6768 static inline const char* lookupFamily(int family)
6769 { return lookup(family,s_familyName); }
6770
6775 static const String& ipv4NullAddr();
6776
6781 static const String& ipv6NullAddr();
6782
6787 static const TokenDict* dictFamilyName();
6788
6789protected:
6793 virtual void stringify();
6794
6798 virtual void updateAddr() const;
6799
6800 struct sockaddr* m_address;
6801 socklen_t m_length;
6802 String m_host;
6803 mutable String m_addr;
6804
6805private:
6806 static const TokenDict s_familyName[];
6807};
6808
6813class YATE_API SocketFilter : public GenObject
6814{
6815 friend class Socket;
6816 YNOCOPY(SocketFilter); // no automatic copies please
6817public:
6822
6826 virtual ~SocketFilter();
6827
6833 virtual void* getObject(const String& name) const;
6834
6839 virtual void timerTick(const Time& when);
6840
6850 virtual bool received(void* buffer, int length, int flags, const struct sockaddr* addr, socklen_t adrlen) = 0;
6851
6856 inline Socket* socket() const
6857 { return m_socket; }
6858
6863 bool valid() const;
6864
6865private:
6866 Socket* m_socket;
6867};
6868
6873class YATE_API Stream
6874{
6875public:
6879 enum SeekPos {
6880 SeekBegin, // Seek from start of stream
6881 SeekEnd, // Seek from stream end
6882 SeekCurrent // Seek from current position
6883 };
6884
6888 virtual ~Stream();
6889
6894 inline int error() const
6895 { return m_error; }
6896
6901 virtual bool terminate() = 0;
6902
6907 virtual bool canRetry() const;
6908
6913 virtual bool inProgress() const;
6914
6919 virtual bool valid() const = 0;
6920
6926 virtual bool setBlocking(bool block = true);
6927
6934 virtual int writeData(const void* buffer, int length) = 0;
6935
6941 int writeData(const char* str);
6942
6948 inline int writeData(const String& str)
6949 { return writeData(str.c_str(), str.length()); }
6950
6956 inline int writeData(const DataBlock& buf)
6957 { return writeData(buf.data(), buf.length()); }
6958
6965 virtual int readData(void* buffer, int length) = 0;
6966
6971 virtual int64_t length();
6972
6979 virtual int64_t seek(SeekPos pos, int64_t offset = 0);
6980
6986 inline int64_t seek(int64_t offset)
6987 { return seek(SeekBegin,offset); }
6988
6995 static bool allocPipe(Stream*& reader, Stream*& writer);
6996
7003 static bool allocPair(Stream*& str1, Stream*& str2);
7004
7009 static bool supportsPipes();
7010
7015 static bool supportsPairs();
7016
7017protected:
7021 inline Stream()
7022 : m_error(0)
7023 { }
7024
7028 inline void clearError()
7029 { m_error = 0; }
7030
7031 int m_error;
7032};
7033
7038class YATE_API MemoryStream : public Stream
7039{
7040 YNOCOPY(MemoryStream); // no automatic copies please
7041public:
7046 : m_offset(0)
7047 { }
7048
7053 inline MemoryStream(const DataBlock& data)
7054 : m_data(data), m_offset(0)
7055 { }
7056
7061 inline const DataBlock& data() const
7062 { return m_data; }
7063
7068 virtual bool terminate()
7069 { return true; }
7074 virtual bool valid() const
7075 { return true; }
7076
7083 virtual int writeData(const void* buffer, int len);
7084
7091 virtual int readData(void* buffer, int len);
7092
7097 virtual int64_t length()
7098 { return m_data.length(); }
7099
7106 virtual int64_t seek(SeekPos pos, int64_t offset = 0);
7107
7108protected:
7113
7117 int64_t m_offset;
7118};
7119
7124class YATE_API File : public Stream
7125{
7126 YNOCOPY(File); // no automatic copies please
7127public:
7132
7137 explicit File(HANDLE handle);
7138
7142 virtual ~File();
7143
7156 virtual bool openPath(const char* name, bool canWrite = false, bool canRead = true,
7157 bool create = false, bool append = false, bool binary = false,
7158 bool pubReadable = false, bool pubWritable = false);
7159
7164 virtual bool terminate();
7165
7170 void attach(HANDLE handle);
7171
7176 HANDLE detach();
7177
7182 inline HANDLE handle() const
7183 { return m_handle; }
7184
7189 virtual bool canRetry() const;
7190
7195 virtual bool valid() const;
7196
7201 static HANDLE invalidHandle();
7202
7208 virtual bool setBlocking(bool block = true);
7209
7214 virtual int64_t length();
7215
7222 virtual int64_t seek(SeekPos pos, int64_t offset = 0);
7223
7230 virtual int writeData(const void* buffer, int length);
7231
7238 virtual int readData(void* buffer, int length);
7239
7245 bool getFileTime(unsigned int& secEpoch);
7246
7253 virtual bool md5(String& buffer);
7254
7262 static bool setFileTime(const char* name, unsigned int secEpoch, int* error = 0);
7263
7271 static bool getFileTime(const char* name, unsigned int& secEpoch, int* error = 0);
7272
7279 static bool exists(const char* name, int* error = 0);
7280
7288 static bool rename(const char* oldFile, const char* newFile, int* error = 0);
7289
7296 static bool remove(const char* name, int* error = 0);
7297
7305 static bool md5(const char* name, String& buffer, int* error = 0);
7306
7314 static bool mkDir(const char* path, int* error = 0, int mode = -1);
7315
7322 static bool rmDir(const char* path, int* error = 0);
7323
7335 static bool listDirectory(const char* path, ObjList* dirs, ObjList* files,
7336 int* error = 0);
7337
7344 static bool createPipe(File& reader, File& writer);
7345
7346protected:
7347
7352
7353 HANDLE m_handle;
7354};
7355
7360class YATE_API Socket : public Stream
7361{
7362 YNOCOPY(Socket); // no automatic copies please
7363public:
7367 enum TOS {
7368 Normal = 0,
7369 LowDelay = IPTOS_LOWDELAY,
7370 MaxThroughput = IPTOS_THROUGHPUT,
7371 MaxReliability = IPTOS_RELIABILITY,
7372 MinCost = IPTOS_MINCOST,
7373 };
7374
7378 enum DSCP {
7379 DefaultPHB = 0x00,
7380 // Class selectors
7381 CS0 = 0x00,
7382 CS1 = 0x20,
7383 CS2 = 0x40,
7384 CS3 = 0x60,
7385 CS4 = 0x80,
7386 CS5 = 0xa0,
7387 CS6 = 0xc0,
7388 CS7 = 0xe0,
7389 // Assured forwarding
7390 AF11 = 0x28,
7391 AF12 = 0x30,
7392 AF13 = 0x38,
7393 AF21 = 0x48,
7394 AF22 = 0x50,
7395 AF23 = 0x58,
7396 AF31 = 0x68,
7397 AF32 = 0x70,
7398 AF33 = 0x78,
7399 AF41 = 0x88,
7400 AF42 = 0x90,
7401 AF43 = 0x98,
7402 // Expedited forwarding
7403 ExpeditedFwd = 0xb8,
7404 VoiceAdmit = 0xb0,
7405 };
7406
7411
7416 explicit Socket(SOCKET handle);
7417
7424 Socket(int domain, int type, int protocol = 0);
7425
7429 virtual ~Socket();
7430
7438 virtual bool create(int domain, int type, int protocol = 0);
7439
7444 virtual bool terminate();
7445
7450 void attach(SOCKET handle);
7451
7456 SOCKET detach();
7457
7462 inline SOCKET handle() const
7463 { return m_handle; }
7464
7469 virtual bool canRetry() const;
7470
7475 virtual bool inProgress() const;
7476
7481 virtual bool valid() const;
7482
7487 static SOCKET invalidHandle();
7488
7493 static int socketError();
7494
7499 static const TokenDict* tosValues();
7500
7509 virtual bool setOption(int level, int name, const void* value = 0, socklen_t length = 0);
7510
7519 inline bool setIpv6OnlyOption(bool on) {
7520#if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY)
7521 int value = on ? 1 : 0;
7522 return setOption(IPPROTO_IPV6,IPV6_V6ONLY,&value,sizeof(value));
7523#else
7524 return false;
7525#endif
7526 }
7527
7536 virtual bool getOption(int level, int name, void* buffer, socklen_t* length);
7537
7542 virtual bool setParams(const NamedList& params)
7543 { return false; }
7544
7551 virtual bool getParams(const String& params, NamedList& result)
7552 { return false; }
7553
7559 virtual bool setTOS(int tos);
7560
7567 inline bool setTOS(const char* tos, int defTos = Normal)
7568 { return setTOS(lookup(tos,tosValues(),defTos)); }
7569
7574 virtual int getTOS();
7575
7581 virtual bool setBlocking(bool block = true);
7582
7590 virtual bool setReuse(bool reuse = true, bool exclusive = false);
7591
7598 virtual bool setLinger(int seconds = -1);
7599
7606 virtual bool bind(struct sockaddr* addr, socklen_t addrlen);
7607
7613 inline bool bind(const SocketAddr& addr)
7614 { return bind(addr.address(), addr.length()); }
7615
7621 virtual bool listen(unsigned int backlog = 0);
7622
7629 virtual Socket* accept(struct sockaddr* addr = 0, socklen_t* addrlen = 0);
7630
7637
7644 SOCKET acceptHandle(struct sockaddr* addr = 0, socklen_t* addrlen = 0);
7645
7654
7659 static bool efficientSelect();
7660
7666 static bool canSelect(SOCKET handle);
7667
7672 virtual bool canSelect() const;
7673
7680 virtual bool connect(struct sockaddr* addr, socklen_t addrlen);
7681
7687 inline bool connect(const SocketAddr& addr)
7688 { return connect(addr.address(), addr.length()); }
7689
7699 virtual bool connectAsync(struct sockaddr* addr, socklen_t addrlen, unsigned int toutUs,
7700 bool* timeout = 0);
7701
7710 inline bool connectAsync(const SocketAddr& addr, unsigned int toutUs,
7711 bool* timeout = 0)
7712 { return connectAsync(addr.address(),addr.length(),toutUs,timeout); }
7713
7720 virtual bool shutdown(bool stopReads, bool stopWrites);
7721
7728 virtual bool getSockName(struct sockaddr* addr, socklen_t* addrlen);
7729
7736
7743 virtual bool getPeerName(struct sockaddr* addr, socklen_t* addrlen);
7744
7751
7761 virtual int sendTo(const void* buffer, int length, const struct sockaddr* addr, socklen_t adrlen, int flags = 0);
7762
7771 inline int sendTo(const void* buffer, int length, const SocketAddr& addr, int flags = 0)
7772 { return sendTo(buffer, length, addr.address(), addr.length(), flags); }
7773
7781 virtual int send(const void* buffer, int length, int flags = 0);
7782
7789 virtual int writeData(const void* buffer, int length);
7790
7800 virtual int recvFrom(void* buffer, int length, struct sockaddr* addr = 0, socklen_t* adrlen = 0, int flags = 0);
7801
7810 int recvFrom(void* buffer, int length, SocketAddr& addr, int flags = 0);
7811
7819 virtual int recv(void* buffer, int length, int flags = 0);
7820
7827 virtual int readData(void* buffer, int length);
7828
7837 virtual bool select(bool* readok, bool* writeok, bool* except, struct timeval* timeout = 0);
7838
7847 bool select(bool* readok, bool* writeok, bool* except, int64_t timeout);
7848
7855
7861 void removeFilter(SocketFilter* filter, bool delobj = false);
7862
7867
7874 virtual void timerTick(const Time& when);
7875
7883 static bool createPair(Socket& sock1, Socket& sock2, int domain = AF_UNIX);
7884
7885protected:
7886
7891
7898 bool checkError(int retcode, bool strict = false);
7899
7909 bool applyFilters(void* buffer, int length, int flags, const struct sockaddr* addr = 0, socklen_t adrlen = 0);
7910
7911 SOCKET m_handle;
7912 ObjList m_filters;
7913};
7914
7919class YATE_API SctpSocket : public Socket
7920{
7921 YNOCOPY(SctpSocket); // no automatic copies please
7922public:
7926 inline SctpSocket()
7927 { }
7928
7933 inline explicit SctpSocket(SOCKET fd)
7934 : Socket(fd)
7935 { }
7936
7940 virtual ~SctpSocket();
7941
7947 virtual bool bindx(ObjList& addresses) = 0;
7948
7954 virtual bool connectx(ObjList& addresses) = 0;
7955
7965 virtual int sendTo(void* buffer, int length, int stream, SocketAddr& addr, int flags) = 0;
7966
7972 virtual Socket* accept(SocketAddr& addr)
7973 { return 0; }
7974
7983 virtual int sendMsg(const void* buf, int length, int stream, int& flags) = 0;
7984
7994 virtual int recvMsg(void* buf, int length, SocketAddr& addr, int& stream, int& flags) = 0;
7995
8002 virtual bool setStreams(int inbound, int outbound) = 0;
8003
8009 virtual bool subscribeEvents() = 0;
8010
8017 virtual bool getStreams(int& inbound, int& outbound) = 0;
8018
8024 virtual bool setPayload(u_int32_t payload) = 0;
8025};
8026
8031class YATE_API SocketRef : public RefObject
8032{
8033public:
8038 inline SocketRef(Socket** socket)
8039 : m_socket(socket)
8040 { }
8041
8046 inline SocketRef(Socket*& socket)
8047 : m_socket(&socket)
8048 { }
8049
8055 virtual void* getObject(const String& name) const
8056 { return (name == YATOM("Socket*")) ? m_socket : RefObject::getObject(name); }
8057
8058private:
8059 SocketRef();
8060 void* m_socket;
8061};
8062
8067class YATE_API DnsRecord : public GenObject
8068{
8069 YCLASS(DnsRecord,GenObject)
8070 YNOCOPY(DnsRecord);
8071public:
8078 inline DnsRecord(int ttl, int order, int pref)
8079 : m_ttl(ttl), m_order(order), m_pref(pref)
8080 {}
8081
8085 inline DnsRecord()
8086 : m_order(0), m_pref(0)
8087 {}
8088
8093 inline int ttl() const
8094 { return m_ttl; }
8095
8100 inline int order() const
8101 { return m_order; }
8102
8107 inline int pref() const
8108 { return m_pref; }
8109
8115 virtual void dump(String& buf, const char* sep = " ");
8116
8124 static bool insert(ObjList& list, DnsRecord* rec, bool ascPref);
8125
8126protected:
8127 int m_ttl;
8128 int m_order;
8129 int m_pref;
8130};
8131
8136class YATE_API TxtRecord : public DnsRecord
8137{
8138 YCLASS(TxtRecord,DnsRecord)
8139 YNOCOPY(TxtRecord);
8140public:
8146 inline TxtRecord(int ttl, const char* text)
8147 : DnsRecord(ttl,-1,-1), m_text(text)
8148 {}
8149
8154 inline const String& text() const
8155 { return m_text; }
8156
8162 virtual void dump(String& buf, const char* sep = " ");
8163
8169 static void copy(ObjList& dest, const ObjList& src);
8170
8171protected:
8172 String m_text;
8173
8174private:
8175 TxtRecord() {} // No default contructor
8176};
8177
8182class YATE_API SrvRecord : public DnsRecord
8183{
8184 YCLASS(SrvRecord,DnsRecord)
8185 YNOCOPY(SrvRecord);
8186public:
8195 inline SrvRecord(int ttl, int prio, int weight, const char* addr, int port)
8196 : DnsRecord(ttl,prio,weight), m_address(addr), m_port(port)
8197 {}
8198
8203 inline const String& address() const
8204 { return m_address; }
8205
8210 inline int port() const
8211 { return m_port; }
8212
8218 virtual void dump(String& buf, const char* sep = " ");
8219
8225 static void copy(ObjList& dest, const ObjList& src);
8226
8227protected:
8228 String m_address;
8229 int m_port;
8230
8231private:
8232 SrvRecord() {} // No default contructor
8233};
8234
8239class YATE_API NaptrRecord : public DnsRecord
8240{
8241 YCLASS(NaptrRecord,DnsRecord)
8242 YNOCOPY(NaptrRecord);
8243public:
8254 NaptrRecord(int ttl, int ord, int pref, const char* flags, const char* serv,
8255 const char* regexp, const char* next);
8256
8263 bool replace(String& str) const;
8264
8270 virtual void dump(String& buf, const char* sep = " ");
8271
8276 inline const String& flags() const
8277 { return m_flags; }
8278
8283 inline const String& serv() const
8284 { return m_service; }
8285
8290 inline const Regexp& regexp() const
8291 { return m_regmatch; }
8292
8297 inline const String& repTemplate() const
8298 { return m_template; }
8299
8304 inline const String& nextName() const
8305 { return m_next; }
8306
8307protected:
8308 String m_flags;
8309 String m_service;
8310 Regexp m_regmatch;
8311 String m_template;
8312 String m_next;
8313
8314private:
8315 NaptrRecord() {} // No default contructor
8316};
8317
8322class YATE_API Resolver
8323{
8324public:
8328 enum Type {
8329 Unknown,
8330 Srv, // SRV (Service Location)
8331 Naptr, // NAPTR (Naming Authority Pointer)
8332 A4, // A (Address)
8333 A6, // AAAA (IPv6 Address)
8334 Txt, // TXT (Text)
8335 };
8336
8343 static bool available(Type type = Unknown);
8344
8351 static bool init(int timeout = -1, int retries = -1);
8352
8361 static int query(Type type, const char* dname, ObjList& result, String* error = 0);
8362
8370 static int srvQuery(const char* dname, ObjList& result, String* error = 0);
8371
8379 static int naptrQuery(const char* dname, ObjList& result, String* error = 0);
8380
8388 static int a4Query(const char* dname, ObjList& result, String* error = 0);
8389
8397 static int a6Query(const char* dname, ObjList& result, String* error = 0);
8398
8406 static int txtQuery(const char* dname, ObjList& result, String* error = 0);
8407
8411 static const TokenDict s_types[];
8412};
8413
8418class YATE_API Cipher : public GenObject
8419{
8420public:
8425 Bidir,
8426 Encrypt,
8427 Decrypt,
8428 };
8429
8434 inline static const TokenDict* directions()
8435 { return s_directions; }
8436
8443 inline static Direction direction(const char* name, Direction defdir = Bidir)
8444 { return (Direction)TelEngine::lookup(name,s_directions,defdir); }
8445
8449 virtual ~Cipher();
8450
8456 virtual void* getObject(const String& name) const;
8457
8463 virtual bool valid(Direction dir = Bidir) const;
8464
8469 virtual unsigned int blockSize() const = 0;
8470
8475 virtual unsigned int initVectorSize() const;
8476
8482 unsigned int bufferSize(unsigned int len) const;
8483
8489 bool bufferFull(unsigned int len) const;
8490
8498 virtual bool setKey(const void* key, unsigned int len, Direction dir = Bidir) = 0;
8499
8506 inline bool setKey(const DataBlock& key, Direction dir = Bidir)
8507 { return setKey(key.data(),key.length(),dir); }
8508
8516 virtual bool initVector(const void* vect, unsigned int len, Direction dir = Bidir);
8517
8524 inline bool initVector(const DataBlock& vect, Direction dir = Bidir)
8525 { return initVector(vect.data(),vect.length(),dir); }
8526
8534 virtual bool encrypt(void* outData, unsigned int len, const void* inpData = 0) = 0;
8535
8541 inline bool encrypt(DataBlock& data)
8542 { return encrypt(data.data(),data.length()); }
8543
8551 virtual bool decrypt(void* outData, unsigned int len, const void* inpData = 0) = 0;
8552
8558 inline bool decrypt(DataBlock& data)
8559 { return decrypt(data.data(),data.length()); }
8560
8561private:
8562 static const TokenDict s_directions[];
8563};
8564
8570class YATE_API Compressor : public String
8571{
8572 YCLASS(Compressor,String)
8573 YNOCOPY(Compressor); // no automatic copies please
8574public:
8580 inline Compressor(const char* format, const char* name = 0)
8581 : String(name), m_format(format)
8582 {}
8583
8587 virtual ~Compressor()
8588 {}
8589
8594 inline const String& format() const
8595 { return m_format; }
8596
8604 virtual bool init(bool comp = true, bool decomp = true,
8605 const NamedList& params = NamedList::empty())
8606 { return true; }
8607
8612 virtual void finalize(bool comp)
8613 {}
8614
8623 virtual int compress(const void* buf, unsigned int len, DataBlock& dest);
8624
8633 virtual int decompress(const void* buf, unsigned int len, DataBlock& dest);
8634
8645 virtual int writeComp(const void* buf, unsigned int len, bool flush) = 0;
8646
8655 inline int writeComp(const DataBlock& data, bool flush)
8656 { return writeComp(data.data(),data.length(),flush); }
8657
8666 inline int writeComp(const String& data, bool flush)
8667 { return writeComp(data.c_str(),data.length(),flush); }
8668
8675 virtual int readComp(DataBlock& buf, bool flush) = 0;
8676
8685 virtual int writeDecomp(const void* buf, unsigned int len, bool flush) = 0;
8686
8694 inline int writeDecomp(const DataBlock& data, bool flush)
8695 { return writeDecomp(data.data(),data.length(),flush); }
8696
8704 inline int writeDecomp(const String& data, bool flush)
8705 { return writeDecomp(data.c_str(),data.length(),flush); }
8706
8713 virtual int readDecomp(DataBlock& buf, bool flush) = 0;
8714
8715protected:
8716 String m_format;
8717};
8718
8724class YATE_API SysUsage
8725{
8726public:
8730 enum Type {
8731 WallTime,
8732 UserTime,
8733 KernelTime
8734 };
8735
8739 static void init();
8740
8745 static u_int64_t startTime();
8746
8752 static u_int64_t usecRunTime(Type type = WallTime);
8753
8759 static u_int64_t msecRunTime(Type type = WallTime);
8760
8766 static u_int32_t secRunTime(Type type = WallTime);
8767
8773 static double runTime(Type type = WallTime);
8774
8775};
8776
8777}; // namespace TelEngine
8778
8779#endif /* __YATECLASS_H */
8780
8781/* vi: set ts=8 sw=4 sts=4 noet: */
A list based Array.
Definition yateclass.h:1846
virtual void * getObject(const String &name) const
GenObject * take(int column, int row)
virtual ~Array()
bool delRow(int index)
ObjList * getColumn(int column) const
Definition yateclass.h:1943
int getColumns() const
Definition yateclass.h:1933
bool set(GenObject *obj, int column, int row)
bool delColumn(int index)
Array(int columns=0, int rows=0)
bool addRow(ObjList *row=0, int index=-1)
int getRows() const
Definition yateclass.h:1926
bool addColumn(ObjList *column=0, int index=-1)
GenObject * get(int column, int row) const
Atom string holder.
Definition yateclass.h:3371
const String * operator->() const
Definition yateclass.h:3392
Atom(const char *value)
Definition yateclass.h:3377
Base64 encoder/decoder class.
Definition yateclass.h:4947
Base64 & operator<<(const char *value)
Definition yateclass.h:5005
Base64(void *src, unsigned int len, bool copyData=true)
Definition yateclass.h:4962
bool decode(DataBlock &dest, bool liberal=true)
Base64()
Definition yateclass.h:4953
Base64 & operator<<(const DataBlock &data)
Definition yateclass.h:4999
void encode(String &dest, unsigned int lineLen=0, bool lineAtEnd=false)
Base64 & operator<<(const String &value)
Definition yateclass.h:4993
A captured event string with a debug level.
Definition yateclass.h:3404
int level() const
Definition yateclass.h:3429
static void append(int level, const char *text)
Definition yateclass.h:3452
CapturedEvent(const CapturedEvent &original)
Definition yateclass.h:3421
static ObjList & eventsRw()
Definition yateclass.h:3460
static bool capturing()
Definition yateclass.h:3437
static const ObjList & events()
Definition yateclass.h:3444
static void capturing(bool capture)
Definition yateclass.h:3467
CapturedEvent(int level, const char *text)
Definition yateclass.h:3413
An abstract cipher.
Definition yateclass.h:8419
bool initVector(const DataBlock &vect, Direction dir=Bidir)
Definition yateclass.h:8524
virtual void * getObject(const String &name) const
Direction
Definition yateclass.h:8424
unsigned int bufferSize(unsigned int len) const
virtual bool valid(Direction dir=Bidir) const
virtual bool encrypt(void *outData, unsigned int len, const void *inpData=0)=0
bool bufferFull(unsigned int len) const
virtual ~Cipher()
bool decrypt(DataBlock &data)
Definition yateclass.h:8558
virtual bool setKey(const void *key, unsigned int len, Direction dir=Bidir)=0
bool encrypt(DataBlock &data)
Definition yateclass.h:8541
virtual bool decrypt(void *outData, unsigned int len, const void *inpData=0)=0
static Direction direction(const char *name, Direction defdir=Bidir)
Definition yateclass.h:8443
virtual bool initVector(const void *vect, unsigned int len, Direction dir=Bidir)
virtual unsigned int blockSize() const =0
static const TokenDict * directions()
Definition yateclass.h:8434
virtual unsigned int initVectorSize() const
bool setKey(const DataBlock &key, Direction dir=Bidir)
Definition yateclass.h:8506
An abstract data (de)compressor.
Definition yateclass.h:8571
virtual int compress(const void *buf, unsigned int len, DataBlock &dest)
Compressor(const char *format, const char *name=0)
Definition yateclass.h:8580
virtual int writeDecomp(const void *buf, unsigned int len, bool flush)=0
virtual bool init(bool comp=true, bool decomp=true, const NamedList &params=NamedList::empty())
Definition yateclass.h:8604
virtual int readComp(DataBlock &buf, bool flush)=0
int writeComp(const DataBlock &data, bool flush)
Definition yateclass.h:8655
virtual ~Compressor()
Definition yateclass.h:8587
virtual void finalize(bool comp)
Definition yateclass.h:8612
virtual int writeComp(const void *buf, unsigned int len, bool flush)=0
int writeDecomp(const String &data, bool flush)
Definition yateclass.h:8704
int writeDecomp(const DataBlock &data, bool flush)
Definition yateclass.h:8694
virtual int readDecomp(DataBlock &buf, bool flush)=0
int writeComp(const String &data, bool flush)
Definition yateclass.h:8666
const String & format() const
Definition yateclass.h:8594
virtual int decompress(const void *buf, unsigned int len, DataBlock &dest)
A class that holds just a block of raw data.
Definition yateclass.h:4237
static const DataBlock & empty()
void cut(int len)
int at(unsigned int offs, int defvalue=-1) const
Definition yateclass.h:4307
void overAlloc(unsigned int bytes)
Definition yateclass.h:4335
virtual void * getObject(const String &name) const
DataBlock & operator+=(const DataBlock &value)
Definition yateclass.h:4427
DataBlock(const DataBlock &value, unsigned int overAlloc)
void append(const DataBlock &value)
virtual ~DataBlock()
DataBlock & operator+=(const String &value)
Definition yateclass.h:4433
DataBlock(const DataBlock &value)
bool convert(const DataBlock &src, const String &sFormat, const String &dFormat, unsigned maxlen=0)
void truncate(unsigned int len)
bool null() const
Definition yateclass.h:4314
unsigned char * data(unsigned int offs, unsigned int len=1) const
Definition yateclass.h:4298
int operator[](unsigned int index) const
Definition yateclass.h:4416
void clear(bool deleteData=true)
bool unHexify(const String &data)
Definition yateclass.h:4476
String sqlEscape(char extraEsc) const
void append(const String &value)
void append(void *value, unsigned int len)
Definition yateclass.h:4358
void * data() const
Definition yateclass.h:4289
DataBlock & operator=(const DataBlock &value)
int operator[](signed int index) const
Definition yateclass.h:4408
DataBlock(void *value, unsigned int len, bool copyData=true, unsigned int overAlloc=0)
void insert(const DataBlock &value)
void resize(unsigned int len)
Definition yateclass.h:4386
bool unHexify(const char *data, unsigned int len, char sep)
unsigned int overAlloc() const
Definition yateclass.h:4328
unsigned int length() const
Definition yateclass.h:4321
DataBlock & assign(void *value, unsigned int len, bool copyData=true, unsigned int allocated=0)
bool unHexify(const char *data, unsigned int len)
DataBlock(unsigned int overAlloc=0)
A holder for a debug level.
Definition yateclass.h:312
void debugChain(const DebugEnabler *chain=0)
Definition yateclass.h:379
void debugName(const char *name)
Definition yateclass.h:393
void debugEnabled(bool enable)
Definition yateclass.h:351
DebugEnabler(int level=TelEngine::debugLevel(), bool enabled=true)
Definition yateclass.h:319
void debugCopy(const DebugEnabler *original=0)
bool debugEnabled() const
Definition yateclass.h:344
bool debugAt(int level) const
bool debugChained() const
Definition yateclass.h:372
int debugLevel() const
Definition yateclass.h:330
int debugLevel(int level)
const char * debugName() const
Definition yateclass.h:358
An object that logs messages on creation and destruction.
Definition yateclass.h:736
Formatting
Definition yateclass.h:741
static void setRelayHook(void(*relayFunc)(int, const char *, const char *, const char *)=0)
static void setIntOut(void(*outFunc)(const char *, int)=0)
Debugger(int level, const char *name, const char *format=0,...)
Debugger(const char *name, const char *format=0,...)
static Formatting getFormatting()
static unsigned int formatTime(char *buf, Formatting format=getFormatting())
static void setAlarmHook(void(*alarmFunc)(const char *, int, const char *, const char *)=0)
static void relayOutput(int level, char *buffer, const char *component=0, const char *info=0)
static uint32_t getStartTimeSec()
static void setOutput(void(*outFunc)(const char *, int)=0)
static void setFormatting(Formatting format, uint32_t startTimeSec=0)
static void enableOutput(bool enable=true, bool colorize=false)
A DNS record.
Definition yateclass.h:8068
DnsRecord(int ttl, int order, int pref)
Definition yateclass.h:8078
virtual void dump(String &buf, const char *sep=" ")
DnsRecord()
Definition yateclass.h:8085
static bool insert(ObjList &list, DnsRecord *rec, bool ascPref)
int ttl() const
Definition yateclass.h:8093
int order() const
Definition yateclass.h:8100
int pref() const
Definition yateclass.h:8107
A stream file class.
Definition yateclass.h:7125
HANDLE detach()
static bool exists(const char *name, int *error=0)
static bool getFileTime(const char *name, unsigned int &secEpoch, int *error=0)
static bool listDirectory(const char *path, ObjList *dirs, ObjList *files, int *error=0)
virtual bool terminate()
void copyError()
HANDLE handle() const
Definition yateclass.h:7182
virtual bool valid() const
static bool rename(const char *oldFile, const char *newFile, int *error=0)
virtual int readData(void *buffer, int length)
virtual ~File()
File(HANDLE handle)
void attach(HANDLE handle)
virtual int64_t length()
bool getFileTime(unsigned int &secEpoch)
static bool remove(const char *name, int *error=0)
static bool setFileTime(const char *name, unsigned int secEpoch, int *error=0)
virtual int writeData(const void *buffer, int length)
virtual bool canRetry() const
virtual int64_t seek(SeekPos pos, int64_t offset=0)
static bool mkDir(const char *path, int *error=0, int mode=-1)
virtual bool md5(String &buffer)
static bool rmDir(const char *path, int *error=0)
virtual bool setBlocking(bool block=true)
static HANDLE invalidHandle()
virtual bool openPath(const char *name, bool canWrite=false, bool canRead=true, bool create=false, bool append=false, bool binary=false, bool pubReadable=false, bool pubWritable=false)
static bool createPipe(File &reader, File &writer)
static bool md5(const char *name, String &buffer, int *error=0)
Definition yateclass.h:1049
virtual void * getObject(const String &name) const
static void setObjCounting(bool enable)
Definition yateclass.h:1116
virtual ~GenObject()
Definition yateclass.h:1060
static ObjList & getObjCounters()
virtual bool alive() const
virtual void destruct()
virtual const String & toString() const
NamedCounter * setObjCounter(NamedCounter *counter)
static bool getObjCounting()
Definition yateclass.h:1109
virtual const String & traceId() const
static void * getObject(const String &name, const GenObject *obj)
Definition yateclass.h:1102
static NamedCounter * getObjCounter(const String &name, bool create=true)
NamedCounter * getObjCounter() const
Definition yateclass.h:1123
Templated pointer that can be inserted in a list.
Definition yateclass.h:1386
GenPointer< Obj > & operator=(const GenPointer< Obj > &value)
Definition yateclass.h:1420
Obj & operator*() const
Definition yateclass.h:1445
GenPointer()
Definition yateclass.h:1397
GenPointer(const GenPointer< Obj > &value)
Definition yateclass.h:1405
GenPointer(Obj *object)
Definition yateclass.h:1413
GenPointer< Obj > & operator=(Obj *object)
Definition yateclass.h:1426
Obj * operator->() const
Definition yateclass.h:1439
A hashed object list class.
Definition yateclass.h:3658
ObjList * getHashList(const String &str) const
Definition yateclass.h:3714
virtual void * getObject(const String &name) const
GenObject * remove(GenObject *obj, unsigned int hash, bool delobj=true)
Definition yateclass.h:3790
ObjList * find(const GenObject *obj) const
ObjList * append(const GenObject *obj)
ObjList * getList(unsigned int index) const
Definition yateclass.h:3698
ObjList * find(const GenObject *obj, unsigned int hash) const
HashList(unsigned int size=17)
GenObject * remove(const String &str, bool delobj=true)
Definition yateclass.h:3777
ObjList * append(const GenObject *obj, unsigned int hash)
ObjList * getHashList(unsigned int hash) const
Definition yateclass.h:3706
virtual ~HashList()
GenObject * operator[](const String &str) const
bool resync()
void clear()
unsigned int count() const
GenObject * remove(GenObject *obj, bool delobj=true, bool useHash=false)
unsigned int length() const
Definition yateclass.h:3683
ObjList * find(const String &str) const
bool resync(GenObject *obj)
An abstract hashing class.
Definition yateclass.h:4499
bool update(const DataBlock &data)
Definition yateclass.h:4546
virtual unsigned int hmacBlockSize() const
bool hmacStart(DataBlock &opad, const String &key)
Definition yateclass.h:4601
bool update(const void *buf, unsigned int len)
Definition yateclass.h:4538
virtual void finalize()=0
virtual void clear()=0
Hasher()
Definition yateclass.h:4655
virtual unsigned int hashLength() const =0
virtual const unsigned char * rawDigest()=0
bool hmac(const DataBlock &key, const DataBlock &msg)
Definition yateclass.h:4627
virtual ~Hasher()
bool update(const String &str)
Definition yateclass.h:4554
bool hmacFinal(const DataBlock &opad)
const String & hexDigest()
Definition yateclass.h:4529
bool hmac(const String &key, const String &msg)
Definition yateclass.h:4636
bool hmacStart(DataBlock &opad, const void *key, unsigned int keyLen)
Hasher & operator<<(const DataBlock &data)
Definition yateclass.h:4568
Hasher & operator<<(const String &value)
Definition yateclass.h:4561
virtual bool updateInternal(const void *buf, unsigned int len)=0
bool hmac(const void *key, unsigned int keyLen, const void *msg, unsigned int msgLen)
bool hmacStart(DataBlock &opad, const DataBlock &key)
Definition yateclass.h:4592
Hasher & operator<<(const char *value)
Class used to iterate the items of a list.
Definition yateclass.h:3828
ListIterator(ObjList &list, int offset=0)
GenObject * get()
void assign(HashList &list, int offset=0)
void reset()
Definition yateclass.h:3910
unsigned int length() const
Definition yateclass.h:3856
void assign(ObjList &list, int offset=0)
ListIterator(HashList &list, int offset=0)
bool eof() const
Definition yateclass.h:3904
GenObject * get(unsigned int index) const
Ephemeral double mutex locking object.
Definition yateclass.h:5907
void drop()
bool lock(Mutex *mx1, Mutex *mx2, long maxwait=-1)
~Lock2()
Definition yateclass.h:5933
bool locked() const
Definition yateclass.h:5940
bool lock(Mutex &mx1, Mutex &mx2, long maxwait=-1)
Definition yateclass.h:5959
Lock2(Mutex &mx1, Mutex &mx2, long maxwait=-1)
Definition yateclass.h:5926
Lock2(Mutex *mx1, Mutex *mx2, long maxwait=-1)
Definition yateclass.h:5916
Ephemeral mutex or semaphore locking object.
Definition yateclass.h:5833
void drop()
Definition yateclass.h:5868
Lock(Lockable &lck, long maxwait=-1)
Definition yateclass.h:5841
~Lock()
Definition yateclass.h:5855
Lockable * locked() const
Definition yateclass.h:5862
Lock(Lockable *lck, long maxwait=-1)
Definition yateclass.h:5849
bool acquire(Lockable &lck, long maxwait=-1)
Definition yateclass.h:5887
bool acquire(Lockable *lck, long maxwait=-1)
Definition yateclass.h:5877
Abstract interface for lockable objects.
Definition yateclass.h:5524
virtual bool locked() const =0
virtual bool lock(long maxwait=-1)=0
virtual bool unlockAll()
static unsigned long wait()
static bool safety()
static void wait(unsigned long maxwait)
static void enableSafety(bool safe=true)
virtual bool check(long maxwait=-1)
virtual bool unlock()=0
virtual ~Lockable()
static void startUsingNow()
A standard MD5 digest calculator.
Definition yateclass.h:4676
MD5 & operator=(const MD5 &original)
static unsigned int rawLength()
Definition yateclass.h:4740
MD5(const MD5 &original)
MD5(const DataBlock &data)
virtual void finalize()
virtual const unsigned char * rawDigest()
MD5(const void *buf, unsigned int len)
virtual void clear()
virtual ~MD5()
MD5(const String &str)
bool updateInternal(const void *buf, unsigned int len)
virtual unsigned int hashLength() const
Definition yateclass.h:4747
A Stream that operates on DataBlocks in memory.
Definition yateclass.h:7039
virtual bool terminate()
Definition yateclass.h:7068
MemoryStream()
Definition yateclass.h:7045
virtual bool valid() const
Definition yateclass.h:7074
virtual int64_t length()
Definition yateclass.h:7097
virtual int writeData(const void *buffer, int len)
virtual int64_t seek(SeekPos pos, int64_t offset=0)
const DataBlock & data() const
Definition yateclass.h:7061
int64_t m_offset
Definition yateclass.h:7117
DataBlock m_data
Definition yateclass.h:7112
virtual int readData(void *buffer, int len)
MemoryStream(const DataBlock &data)
Definition yateclass.h:7053
A Mutex pool.
Definition yateclass.h:5697
unsigned int index(void *ptr) const
Definition yateclass.h:5723
MutexPool(unsigned int len=13, bool recursive=false, const char *name=0)
Mutex * mutex(void *ptr) const
Definition yateclass.h:5733
Mutex * mutex(unsigned int idx) const
Definition yateclass.h:5741
Mutex support.
Definition yateclass.h:5607
virtual bool locked() const
Mutex & operator=(const Mutex &original)
static int count()
bool recursive() const
Mutex(const Mutex &original)
static bool efficientTimedLock()
virtual bool unlock()
static int locks()
Mutex(bool recursive=false, const char *name=0)
const char * owner() const
virtual bool lock(long maxwait=-1)
Atomic counter with name.
Definition yateclass.h:3602
NamedCounter(const String &name)
int count() const
Definition yateclass.h:3641
void enable(bool val)
Definition yateclass.h:3622
bool enabled() const
Definition yateclass.h:3615
NamedList parameters iterator.
Definition yateclass.h:5334
NamedIterator & operator=(const NamedIterator &original)
Definition yateclass.h:5363
NamedIterator & operator=(const NamedList &list)
Definition yateclass.h:5356
const NamedString * get()
NamedIterator(const NamedIterator &original)
Definition yateclass.h:5348
void reset()
Definition yateclass.h:5381
NamedIterator(const NamedList &list)
Definition yateclass.h:5340
bool eof() const
Definition yateclass.h:5375
A named string container class.
Definition yateclass.h:5016
virtual void * getObject(const String &name) const
int getIndex(const NamedString *param) const
void clearParams()
Definition yateclass.h:5070
void dump(String &str, const char *separator, char quote=0, bool force=false) const
NamedList & copyParams(const NamedList &original, ObjList *list, char childSep=0)
static const NamedList & empty()
NamedList(const char *name)
NamedList & setParam(const String &name, const char *value)
NamedList & clearParam(NamedString *param, bool delParam=true)
NamedString * getParam(const String &name) const
NamedList & operator=(const NamedList &value)
const ObjList * paramList() const
Definition yateclass.h:5320
NamedList & copyParam(const NamedList &original, const String &name, char childSep=0)
NamedList & setParam(NamedString *param)
Definition yateclass.h:5094
NamedList(const NamedList &original)
int64_t getInt64Value(const String &name, int64_t defvalue=0, int64_t minvalue=LLONG_MIN, int64_t maxvalue=LLONG_MAX, bool clamp=true) const
int getIntValue(const String &name, int defvalue=0, int minvalue=INT_MIN, int maxvalue=INT_MAX, bool clamp=true) const
const char * getValue(const String &name, const char *defvalue=0) const
NamedList & copyParams(const NamedList &original, const String &list, char childSep=0)
int getIndex(const String &name) const
bool getBoolValue(const String &name, bool defvalue=false) const
double getDoubleValue(const String &name, double defvalue=0.0) const
NamedList & copyParams(const NamedList &original)
NamedList & addParam(NamedString *param)
int replaceParams(String &str, bool sqlEsc=false, char extraEsc=0) const
int getIntValue(const String &name, const TokenDict *tokens, int defvalue=0) const
ObjList * paramList()
Definition yateclass.h:5313
bool hasSubParams(const char *prefix) const
NamedList & addParam(const char *name, const char *value, bool emptyOK=true)
NamedList & copySubParams(const NamedList &original, const String &prefix, bool skipPrefix=true, bool replace=false)
const String & operator[](const String &name) const
unsigned int count() const
Definition yateclass.h:5064
unsigned int length() const
Definition yateclass.h:5057
NamedList(const char *name, const NamedList &original, const String &prefix)
uint64_t getUInt64Value(const String &name, uint64_t defvalue=0, uint64_t minvalue=0, uint64_t maxvalue=ULLONG_MAX, bool clamp=true) const
NamedString * getParam(unsigned int index) const
NamedList & clearParam(const String &name, char childSep=0)
A named pointer class.
Definition yateclass.h:3529
void userData(GenObject *data)
virtual void * getObject(const String &name) const
GenObject * userData() const
Definition yateclass.h:3548
NamedPointer(const char *name, GenObject *data=0, const char *value=0)
virtual void changed()
GenObject * takeData()
void * userObject(const String &name) const
Definition yateclass.h:3570
virtual ~NamedPointer()
NamedPointer & operator=(const char *value)
Definition yateclass.h:3576
A named string class.
Definition yateclass.h:3481
virtual void * getObject(const String &name) const
NamedString & operator=(const char *value)
Definition yateclass.h:3514
NamedString(const char *name, const char *value=0)
virtual const String & toString() const
const String & name() const
Definition yateclass.h:3495
A NAPTR record.
Definition yateclass.h:8240
const String & serv() const
Definition yateclass.h:8283
bool replace(String &str) const
virtual void dump(String &buf, const char *sep=" ")
const Regexp & regexp() const
Definition yateclass.h:8290
const String & nextName() const
Definition yateclass.h:8304
const String & repTemplate() const
Definition yateclass.h:8297
NaptrRecord(int ttl, int ord, int pref, const char *flags, const char *serv, const char *regexp, const char *next)
const String & flags() const
Definition yateclass.h:8276
An object list class.
Definition yateclass.h:1454
void compact()
virtual void * getObject(const String &name) const
ObjList * next() const
Definition yateclass.h:1505
ObjList * last() const
virtual ~ObjList()
void sort(int(*callbackCompare)(GenObject *obj1, GenObject *obj2, void *context), void *context=0)
ObjList * find(const GenObject *obj) const
ObjList * setUnique(const GenObject *obj, bool compact=true)
ObjList * append(const GenObject *obj, bool compact=true)
GenObject * set(const GenObject *obj, bool delold=true)
GenObject * at(int index) const
int index(const String &str) const
GenObject * remove(GenObject *obj, bool delobj=true)
ObjList * skipNull() const
void setDelete(bool autodelete)
Definition yateclass.h:1659
GenObject * operator[](signed int index) const
Definition yateclass.h:1545
GenObject * remove(const String &str, bool delobj=true)
ObjList * skipNext() const
GenObject * operator[](unsigned int index) const
Definition yateclass.h:1553
bool autoDelete()
Definition yateclass.h:1652
ObjList * operator+(int index) const
GenObject * operator[](const String &str) const
GenObject * get() const
Definition yateclass.h:1490
void clear()
static const ObjList & empty()
unsigned int count() const
int index(const GenObject *obj) const
ObjList * insert(const GenObject *obj, bool compact=true)
unsigned int length() const
ObjList * find(const String &str) const
GenObject * remove(bool delobj=true)
A vector holding GenObjects.
Definition yateclass.h:1692
virtual void * getObject(const String &name) const
ObjVector(bool autodelete=true)
Definition yateclass.h:1699
ObjVector(ObjList &list, bool move=true, unsigned int maxLen=0, bool autodelete=true)
bool null() const
GenObject * at(int index) const
Definition yateclass.h:1755
int index(const String &str) const
void setDelete(bool autodelete)
Definition yateclass.h:1828
ObjVector(unsigned int maxLen, bool autodelete=true)
GenObject * operator[](signed int index) const
Definition yateclass.h:1763
GenObject * operator[](unsigned int index) const
Definition yateclass.h:1771
bool autoDelete()
Definition yateclass.h:1821
bool set(GenObject *obj, unsigned int index)
GenObject * take(unsigned int index)
void clear()
unsigned int count() const
int index(const GenObject *obj) const
unsigned int length() const
Definition yateclass.h:1735
virtual ~ObjVector()
unsigned int assign(ObjList &list, bool move=true, unsigned int maxLen=0)
Pseudo random number generator.
Definition yateclass.h:4186
u_int32_t next()
u_int32_t get() const
Definition yateclass.h:4200
static long int random()
void set(u_int32_t seed)
Definition yateclass.h:4207
Random(u_int32_t seed=Time::now() &0xffffffff)
Definition yateclass.h:4192
static void srandom(unsigned int seed)
Definition yateclass.h:1174
static bool efficientIncDec()
static bool alive(const RefObject *obj)
Definition yateclass.h:1237
virtual void zeroRefs()
virtual void * getObject(const String &name) const
bool resurrect()
virtual void destroyed()
virtual bool alive() const
virtual void destruct()
virtual ~RefObject()
bool deref()
int refcount() const
Definition yateclass.h:1223
bool ref()
Internal helper class.
Definition yateclass.h:1280
RefPointerBase()
Definition yateclass.h:1285
void * m_pointer
Definition yateclass.h:1299
void assign(RefObject *oldptr, RefObject *newptr, void *pointer)
Templated smart pointer class.
Definition yateclass.h:1306
RefPointer< Obj > & operator=(Obj *object)
Definition yateclass.h:1359
RefPointer< Obj > & operator=(const RefPointer< Obj > &value)
Definition yateclass.h:1353
Obj & operator*() const
Definition yateclass.h:1378
Obj * pointer() const
Definition yateclass.h:1312
void assign(Obj *object=0)
Definition yateclass.h:1319
~RefPointer()
Definition yateclass.h:1347
RefPointer()
Definition yateclass.h:1326
Obj * operator->() const
Definition yateclass.h:1372
RefPointer(const RefPointer< Obj > &value)
Definition yateclass.h:1333
RefPointer(Obj *object)
Definition yateclass.h:1341
A regexp matching class.
Definition yateclass.h:3271
bool isCaseInsensitive() const
bool doCompile() const
virtual ~Regexp()
Regexp(const char *value, bool extended=false, bool insensitive=false)
virtual void changed()
bool compile() const
Definition yateclass.h:3309
bool isExtended() const
void setFlags(bool extended, bool insensitive)
Regexp(const Regexp &value)
Regexp & operator=(const char *value)
Definition yateclass.h:3302
bool matches(const char *value) const
virtual bool matches(const String &value) const
Definition yateclass.h:3324
DNS services.
Definition yateclass.h:8323
static bool init(int timeout=-1, int retries=-1)
static int naptrQuery(const char *dname, ObjList &result, String *error=0)
Type
Definition yateclass.h:8328
static int query(Type type, const char *dname, ObjList &result, String *error=0)
static bool available(Type type=Unknown)
static int a6Query(const char *dname, ObjList &result, String *error=0)
static int srvQuery(const char *dname, ObjList &result, String *error=0)
static int a4Query(const char *dname, ObjList &result, String *error=0)
static int txtQuery(const char *dname, ObjList &result, String *error=0)
Encapsulates a runnable task.
Definition yateclass.h:5984
virtual void run()=0
virtual ~Runnable()
A standard SHA1 digest calculator.
Definition yateclass.h:4763
SHA1 & operator=(const SHA1 &original)
SHA1(const void *buf, unsigned int len)
static unsigned int rawLength()
Definition yateclass.h:4827
SHA1(const SHA1 &original)
virtual void finalize()
virtual const unsigned char * rawDigest()
SHA1(const String &str)
static bool fips186prf(DataBlock &out, const DataBlock &seed, unsigned int len)
virtual ~SHA1()
virtual void clear()
SHA1(const DataBlock &data)
bool updateInternal(const void *buf, unsigned int len)
virtual unsigned int hashLength() const
Definition yateclass.h:4834
A standard SHA256 digest calculator.
Definition yateclass.h:4860
static unsigned int rawLength()
Definition yateclass.h:4924
virtual ~SHA256()
SHA256(const void *buf, unsigned int len)
SHA256(const DataBlock &data)
virtual void finalize()
virtual const unsigned char * rawDigest()
SHA256(const SHA256 &original)
SHA256(const String &str)
virtual void clear()
SHA256 & operator=(const SHA256 &original)
bool updateInternal(const void *buf, unsigned int len)
virtual unsigned int hashLength() const
Definition yateclass.h:4931
Abstract SCTP Socket.
Definition yateclass.h:7920
virtual bool subscribeEvents()=0
virtual bool connectx(ObjList &addresses)=0
virtual int recvMsg(void *buf, int length, SocketAddr &addr, int &stream, int &flags)=0
virtual bool getStreams(int &inbound, int &outbound)=0
SctpSocket()
Definition yateclass.h:7926
virtual int sendTo(void *buffer, int length, int stream, SocketAddr &addr, int flags)=0
virtual int sendMsg(const void *buf, int length, int stream, int &flags)=0
virtual bool setPayload(u_int32_t payload)=0
virtual bool setStreams(int inbound, int outbound)=0
virtual Socket * accept(SocketAddr &addr)
Definition yateclass.h:7972
SctpSocket(SOCKET fd)
Definition yateclass.h:7933
virtual ~SctpSocket()
virtual bool bindx(ObjList &addresses)=0
Semaphore implementation.
Definition yateclass.h:5755
virtual bool locked() const
static int count()
Semaphore(const Semaphore &original)
static bool efficientTimedLock()
virtual bool unlock()
Semaphore & operator=(const Semaphore &original)
static int locks()
virtual bool lock(long maxwait=-1)
Semaphore(unsigned int maxcount=1, const char *name=0, unsigned int initialCount=1)
A socket address holder.
Definition yateclass.h:6400
static unsigned int scopeId(struct sockaddr *addr)
Definition yateclass.h:6672
static String appendTo(const String &addr, int port, int family=Unknown)
Definition yateclass.h:6726
static const char * lookupFamily(int family)
Definition yateclass.h:6768
int copyAddr(DataBlock &addr) const
static String & appendTo(String &buf, const String &addr, int port, int family=Unknown)
Definition yateclass.h:6713
int port() const
static bool scopeId(struct sockaddr *addr, unsigned int val)
Definition yateclass.h:6686
bool assign(int family)
bool operator!=(const SocketAddr &other) const
Definition yateclass.h:6477
SocketAddr(int family, const void *raw=0)
bool valid() const
Definition yateclass.h:6517
virtual void stringify()
socklen_t length() const
Definition yateclass.h:6605
static bool isNullAddr(const String &addr, int family=Unknown)
struct sockaddr * address() const
Definition yateclass.h:6598
static bool stringify(String &buf, struct sockaddr *addr)
static int unStringify(uint8_t *buf, const String &host, int family=Unknown)
Definition yateclass.h:6652
bool operator==(const SocketAddr &other) const
virtual ~SocketAddr()
SocketAddr & operator=(const SocketAddr &value)
Definition yateclass.h:6462
int family() const
Definition yateclass.h:6531
bool null() const
Definition yateclass.h:6524
bool assign(const DataBlock &addr)
Family
Definition yateclass.h:6406
unsigned int scopeId() const
Definition yateclass.h:6545
static String & appendAddr(String &buf, const String &addr, int family=Unknown)
SocketAddr(const SocketAddr &value)
Definition yateclass.h:6434
const char * familyName() const
Definition yateclass.h:6538
static int family(const String &addr)
const String & host() const
Definition yateclass.h:6560
bool scopeId(unsigned int val)
Definition yateclass.h:6553
static void splitIface(const String &buf, String &addr, String *iface=0)
static const TokenDict * dictFamilyName()
static void split(const String &buf, String &addr, int &port, bool portPresent=false)
SocketAddr(const struct sockaddr *addr, socklen_t len=0)
static int copyAddr(uint8_t *buf, struct sockaddr *addr)
static bool supports(int family)
void assign(const struct sockaddr *addr, socklen_t len=0)
virtual bool host(const String &name)
const String & addr() const
Definition yateclass.h:6567
void clear()
static const String & ipv4NullAddr()
bool local(const SocketAddr &remote)
static const String & ipv6NullAddr()
bool port(int newport)
SocketAddr()
Definition yateclass.h:6426
virtual void updateAddr() const
bool isNullAddr() const
Definition yateclass.h:6612
A filter for received socket data.
Definition yateclass.h:6814
virtual void * getObject(const String &name) const
virtual bool received(void *buffer, int length, int flags, const struct sockaddr *addr, socklen_t adrlen)=0
bool valid() const
virtual ~SocketFilter()
Socket * socket() const
Definition yateclass.h:6856
virtual void timerTick(const Time &when)
RefObject holding a Socket pointer.
Definition yateclass.h:8032
virtual void * getObject(const String &name) const
Definition yateclass.h:8055
SocketRef(Socket *&socket)
Definition yateclass.h:8046
SocketRef(Socket **socket)
Definition yateclass.h:8038
A generic socket class.
Definition yateclass.h:7361
virtual bool connectAsync(struct sockaddr *addr, socklen_t addrlen, unsigned int toutUs, bool *timeout=0)
SOCKET detach()
static const TokenDict * tosValues()
virtual bool setReuse(bool reuse=true, bool exclusive=false)
bool connectAsync(const SocketAddr &addr, unsigned int toutUs, bool *timeout=0)
Definition yateclass.h:7710
virtual bool terminate()
void copyError()
bool installFilter(SocketFilter *filter)
Socket(SOCKET handle)
void attach(SOCKET handle)
virtual bool connect(struct sockaddr *addr, socklen_t addrlen)
virtual int getTOS()
virtual int send(const void *buffer, int length, int flags=0)
bool getPeerName(SocketAddr &addr)
virtual bool valid() const
DSCP
Definition yateclass.h:7378
virtual bool getOption(int level, int name, void *buffer, socklen_t *length)
virtual int readData(void *buffer, int length)
static bool createPair(Socket &sock1, Socket &sock2, int domain=AF_UNIX)
virtual bool getPeerName(struct sockaddr *addr, socklen_t *addrlen)
static bool efficientSelect()
static int socketError()
virtual ~Socket()
bool bind(const SocketAddr &addr)
Definition yateclass.h:7613
bool getSockName(SocketAddr &addr)
virtual bool inProgress() const
Socket * accept(SocketAddr &addr)
virtual bool shutdown(bool stopReads, bool stopWrites)
SOCKET handle() const
Definition yateclass.h:7462
int sendTo(const void *buffer, int length, const SocketAddr &addr, int flags=0)
Definition yateclass.h:7771
bool setIpv6OnlyOption(bool on)
Definition yateclass.h:7519
virtual bool canSelect() const
bool checkError(int retcode, bool strict=false)
virtual Socket * accept(struct sockaddr *addr=0, socklen_t *addrlen=0)
virtual bool create(int domain, int type, int protocol=0)
virtual int recv(void *buffer, int length, int flags=0)
virtual bool getSockName(struct sockaddr *addr, socklen_t *addrlen)
virtual int sendTo(const void *buffer, int length, const struct sockaddr *addr, socklen_t adrlen, int flags=0)
virtual int writeData(const void *buffer, int length)
bool applyFilters(void *buffer, int length, int flags, const struct sockaddr *addr=0, socklen_t adrlen=0)
virtual bool canRetry() const
virtual bool getParams(const String &params, NamedList &result)
Definition yateclass.h:7551
virtual bool setTOS(int tos)
virtual bool setOption(int level, int name, const void *value=0, socklen_t length=0)
virtual bool setParams(const NamedList &params)
Definition yateclass.h:7542
virtual void timerTick(const Time &when)
virtual bool setBlocking(bool block=true)
virtual bool bind(struct sockaddr *addr, socklen_t addrlen)
virtual int recvFrom(void *buffer, int length, struct sockaddr *addr=0, socklen_t *adrlen=0, int flags=0)
void removeFilter(SocketFilter *filter, bool delobj=false)
Socket(int domain, int type, int protocol=0)
virtual bool listen(unsigned int backlog=0)
static SOCKET invalidHandle()
SOCKET acceptHandle(struct sockaddr *addr=0, socklen_t *addrlen=0)
static bool canSelect(SOCKET handle)
TOS
Definition yateclass.h:7367
void clearFilters()
bool updateError()
virtual bool setLinger(int seconds=-1)
bool setTOS(const char *tos, int defTos=Normal)
Definition yateclass.h:7567
bool connect(const SocketAddr &addr)
Definition yateclass.h:7687
bool select(bool *readok, bool *writeok, bool *except, int64_t timeout)
virtual bool select(bool *readok, bool *writeok, bool *except, struct timeval *timeout=0)
int recvFrom(void *buffer, int length, SocketAddr &addr, int flags=0)
A SRV record.
Definition yateclass.h:8183
SrvRecord(int ttl, int prio, int weight, const char *addr, int port)
Definition yateclass.h:8195
int port() const
Definition yateclass.h:8210
static void copy(ObjList &dest, const ObjList &src)
virtual void dump(String &buf, const char *sep=" ")
const String & address() const
Definition yateclass.h:8203
An abstract stream class capable of reading and writing.
Definition yateclass.h:6874
int writeData(const DataBlock &buf)
Definition yateclass.h:6956
static bool allocPipe(Stream *&reader, Stream *&writer)
virtual int readData(void *buffer, int length)=0
virtual ~Stream()
int error() const
Definition yateclass.h:6894
SeekPos
Definition yateclass.h:6879
virtual bool inProgress() const
Stream()
Definition yateclass.h:7021
static bool supportsPipes()
virtual bool terminate()=0
virtual int64_t length()
virtual int writeData(const void *buffer, int length)=0
void clearError()
Definition yateclass.h:7028
int writeData(const String &str)
Definition yateclass.h:6948
static bool supportsPairs()
int writeData(const char *str)
virtual bool canRetry() const
virtual int64_t seek(SeekPos pos, int64_t offset=0)
static bool allocPair(Stream *&str1, Stream *&str2)
virtual bool setBlocking(bool block=true)
virtual bool valid() const =0
int64_t seek(int64_t offset)
Definition yateclass.h:6986
A C-style string handling class.
Definition yateclass.h:2131
const char * c_str() const
Definition yateclass.h:2236
String & printf(unsigned int length, const char *format,...)
double toDouble(double defvalue=0.0) const
String & appendFixed(unsigned int fixedLength, const String &str, char fill=' ', int align=Left)
Definition yateclass.h:2861
bool checkBOM() const
Definition yateclass.h:2339
int find(const char *what, unsigned int offs=0) const
String & trimSpaces()
String & operator=(bool value)
Definition yateclass.h:2619
String & append(double value, unsigned int decimals=3)
String(uint32_t value)
virtual void * getObject(const String &name) const
static String msgUnescape(const char *str, int *errptr=0, char extraEsc=0)
static String msgEscape(const char *str, char extraEsc=0)
String & operator>>(int &store)
static bool stripBOM(char *&str)
Definition yateclass.h:2355
bool startSkip(const char *what, bool wordBreak=true, bool caseInsensitive=false)
int find(char what, unsigned int offs=0) const
String(bool value)
char operator[](unsigned int index) const
Definition yateclass.h:2527
bool operator|=(const char *value) const
int64_t toInt64(int64_t defvalue=0, int base=0, int64_t minvalue=LLONG_MIN, int64_t maxvalue=LLONG_MAX, bool clamp=true) const
String & extractTo(const char *sep, int &store, int base=0)
String & hexify(void *data, unsigned int len, char sep=0, bool upCase=false)
String & operator+=(int64_t value)
static String sqlEscape(const char *str, char extraEsc=0)
String(int64_t value)
ObjList * split(char separator, bool emptyOK=true) const
static String uriEscape(const char *str, char extraEsc=0, const char *noEsc=0)
static String uriEscape(const char *str, const char *extraEsc, const char *noEsc=0)
bool operator==(const char *value) const
static bool checkBOM(const char *str)
Definition yateclass.h:2332
char at(int index) const
String replaceMatches(const String &templ) const
bool endsWith(const char *what, bool wordBreak=false, bool caseInsensitive=false) const
String & operator>>(bool &store)
uint64_t encodeFlags(const TokenDict64 *tokens) const
String & extractTo(const char *sep, double &store)
String uriUnescape(int *errptr=0) const
Definition yateclass.h:3124
int rfind(const char *what) const
String & operator+=(const char *value)
Definition yateclass.h:2633
String(uint64_t value)
String & extractTo(const char *sep, String &store)
String & append(const ObjList &list, const char *separator=0, bool force=false)
Definition yateclass.h:2820
String & operator<<(const char *value)
Definition yateclass.h:2714
ObjList * split(const Regexp &reg, bool emptyOK=true) const
String matchString(int index=0) const
Definition yateclass.h:3002
String & operator<<(int32_t value)
Definition yateclass.h:2726
String & operator=(int64_t value)
bool null() const
Definition yateclass.h:2265
virtual void changed()
String & operator+=(uint64_t value)
const String & decodeFlags(unsigned int flags, const TokenDict *tokens, bool unknownflag=true)
String & operator=(uint32_t value)
const char * safe() const
Definition yateclass.h:2243
int lenUtf8(uint32_t maxChar=0x10ffff, bool overlong=false) const
Definition yateclass.h:2283
static int lenUtf8(const char *value, uint32_t maxChar=0x10ffff, bool overlong=false)
int fixUtf8(const char *replace=0, uint32_t maxChar=0x10ffff, bool overlong=false)
String & operator>>(const char *skip)
String & append(const ObjList *list, const char *separator=0, bool force=false)
int rfind(char what) const
String & extractTo(const char *sep, int &store, const TokenDict *tokens, int base=0)
String & operator+=(int32_t value)
String sqlEscape(char extraEsc=0) const
Definition yateclass.h:3081
String & operator=(const char *value)
bool operator==(const String &value) const
Definition yateclass.h:2692
String & extractTo(const char *sep, bool &store)
String(const String *value)
String & operator+=(uint32_t value)
virtual ~String()
int matchCount() const
bool operator!=(const String &value) const
Definition yateclass.h:2698
virtual const String & toString() const
bool stripBOM()
Definition yateclass.h:2362
String & operator>>(unsigned int &store)
String & assign(char value, unsigned int repeat=1)
String & trimBlanks()
String & assign(const char *value, int len=-1)
bool operator&=(const char *value) const
static const String * atom(const String *&str, const char *val)
String & appendFixed(unsigned int fixedLength, const char *str, unsigned int len=-1, char fill=' ', int align=Left)
String(const char *value, int len=-1)
String & operator<<(uint32_t value)
Definition yateclass.h:2732
uint64_t toUInt64(uint64_t defvalue=0, int base=0, uint64_t minvalue=0, uint64_t maxvalue=ULLONG_MAX, bool clamp=true) const
String & operator<<(uint64_t value)
Definition yateclass.h:2744
String & operator<<(double value)
Definition yateclass.h:2756
static String uriUnescape(const char *str, int *errptr=0)
String(char value, unsigned int repeat=1)
String & append(const char *value, int len)
String & operator>>(char &store)
static const char * boolText(bool value)
Definition yateclass.h:2229
static unsigned int hash(const char *value, unsigned int h=0)
bool toBoolean(bool defvalue=false) const
static bool stripBOM(const char *&str)
Definition yateclass.h:2347
void clear()
String & operator=(char value)
int toInteger(const TokenDict *tokens, int defvalue=0, int base=0) const
unsigned int hash() const
Definition yateclass.h:2369
String uriEscape(char extraEsc=0, const char *noEsc=0) const
Definition yateclass.h:3108
String & operator=(const String &value)
Definition yateclass.h:2567
long int toLong(long int defvalue=0, int base=0, long int minvalue=LONG_MIN, long int maxvalue=LONG_MAX, bool clamp=true) const
int toInteger(int defvalue=0, int base=0, int minvalue=INT_MIN, int maxvalue=INT_MAX, bool clamp=true) const
String & toLower()
String & operator=(uint64_t value)
String & operator+=(char value)
String & operator<<(bool value)
Definition yateclass.h:2750
bool startsWith(const char *what, bool wordBreak=false, bool caseInsensitive=false) const
String & operator>>(UChar &store)
int matchLength(int index=0) const
static const String & empty()
const char * safe(const char *defStr) const
Definition yateclass.h:2251
String & toUpper()
char operator[](signed int index) const
Definition yateclass.h:2519
String(const String &value)
int matchOffset(int index=0) const
String & operator=(int32_t value)
String & operator+=(double value)
String & append(const char *value, const char *separator=0, bool force=false)
unsigned int encodeFlags(const TokenDict *tokens) const
unsigned int length() const
Definition yateclass.h:2258
String & operator+=(bool value)
Definition yateclass.h:2670
bool operator!=(const char *value) const
String & operator<<(char value)
Definition yateclass.h:2720
String msgEscape(char extraEsc=0) const
Definition yateclass.h:3047
const String & decodeFlags(uint64_t flags, const TokenDict64 *tokens, bool unknownflag=true)
String & operator=(double value)
bool matches(const Regexp &rexp)
String & operator<<(int64_t value)
Definition yateclass.h:2738
String msgUnescape(int *errptr=0, char extraEsc=0) const
Definition yateclass.h:3065
String & printf(const char *format,...)
String(int32_t value)
String(double value)
virtual bool matches(const String &value) const
Definition yateclass.h:2973
bool isBoolean() const
String & operator=(const String *value)
Definition yateclass.h:2575
String substr(int offs, int len=-1) const
A class exposing system resources usage.
Definition yateclass.h:8725
static u_int64_t usecRunTime(Type type=WallTime)
Type
Definition yateclass.h:8730
static u_int64_t startTime()
static double runTime(Type type=WallTime)
static u_int64_t msecRunTime(Type type=WallTime)
static void init()
static u_int32_t secRunTime(Type type=WallTime)
Ephemeral object counter changer.
Definition yateclass.h:6352
TempObjectCounter(const GenObject *obj, bool enable=GenObject::getObjCounting())
Definition yateclass.h:6369
TempObjectCounter(const GenObject &obj, bool enable=GenObject::getObjCounting())
Definition yateclass.h:6378
TempObjectCounter(NamedCounter *counter, bool enable=GenObject::getObjCounting())
Definition yateclass.h:6360
~TempObjectCounter()
Definition yateclass.h:6385
Thread support class.
Definition yateclass.h:6005
static int count()
virtual void cleanup()
static int setCurrentAffinity(const DataBlock &mask)
static void preExec()
static void sleep(unsigned int sec, bool exitCheck=false)
virtual ~Thread()
static int setCurrentAffinity(const String &cpus)
static bool check(bool exitNow=true)
Priority
Definition yateclass.h:6014
int setAffinity(const DataBlock &mask)
static void usleep(unsigned long usec, bool exitCheck=false)
static unsigned long idleMsec()
static void idleMsec(unsigned long msec)
static bool errorString(String &buffer)
Definition yateclass.h:6306
Thread(const char *name, const char *prio)
static NamedCounter * getCurrentObjCounter(bool always=false)
static void yield(bool exitCheck=false)
static bool errorString(String &buffer, int code)
static void printCPUMask(const DataBlock &mask, String &str, bool hexa=true)
int locks() const
Definition yateclass.h:6074
int getAffinity(DataBlock &outCpuMask)
static void killall()
const char * name() const
bool locked() const
Definition yateclass.h:6081
static Thread * current()
bool running() const
static unsigned long idleUsec()
static void exit()
static int getCurrentAffinity(DataBlock &outCpuMask)
static const char * priority(Priority prio)
bool error() const
static void msleep(unsigned long msec, bool exitCheck=false)
static int getCurrentAffinity(String &outCpus, bool hex=false)
static NamedCounter * setCurrentObjCounter(NamedCounter *counter)
NamedCounter * setObjCounter(NamedCounter *counter)
static bool parseCPUMask(const String &cpus, DataBlock &mask)
bool startup()
bool isCurrent() const
Definition yateclass.h:6236
int setAffinity(const String &cpus)
static const char * currentName()
static void idle(bool exitCheck=false)
static Priority priority(const char *name, Priority defvalue=Normal)
void cancel(bool hard=false)
static int lastError()
Thread(const char *name=0, Priority prio=Normal)
NamedCounter * getObjCounter() const
A time holding class.
Definition yateclass.h:3927
static void toTimeval(struct timeval *tv, u_int64_t usec)
static unsigned int toString(char *buf, uint64_t time, int frac=0)
static uint64_t toEpoch(const char *buf, unsigned int len, int frac=0)
Time & operator-=(int64_t delta)
Definition yateclass.h:4009
Time()
Definition yateclass.h:3932
static int timeZone(u_int32_t when=secNow())
static uint32_t toNtp(uint32_t sec, uint32_t *over=0, bool rfc2030=true)
void toTimeval(struct timeval *tv) const
Definition yateclass.h:4016
static unsigned int appendTo(String &buf, uint64_t time, int frac=0)
Definition yateclass.h:4143
Time & operator=(u_int64_t usec)
Definition yateclass.h:3997
Time(u_int64_t usec)
Definition yateclass.h:3940
static uint32_t fromNtp(uint32_t val, uint32_t *under=0, bool rfc2030=true)
static unsigned int toEpoch(int year, unsigned int month, unsigned int day, unsigned int hour, unsigned int minute, unsigned int sec, int offset=0)
u_int64_t msec() const
Definition yateclass.h:3978
static u_int64_t fromTimeval(const struct timeval &tv)
Definition yateclass.h:4038
static bool toDateTime(unsigned int epochTimeSec, int &year, unsigned int &month, unsigned int &day, unsigned int &hour, unsigned int &minute, unsigned int &sec, unsigned int *wDay=0)
Time(const struct timeval &tv)
Definition yateclass.h:3956
u_int64_t usec() const
Definition yateclass.h:3985
Time(const struct timeval *tv)
Definition yateclass.h:3948
static u_int64_t now()
Time & operator+=(int64_t delta)
Definition yateclass.h:4003
uint32_t toNtp(uint32_t *over=0, bool rfc2030=true)
Definition yateclass.h:4106
static u_int64_t fromTimeval(const struct timeval *tv)
u_int32_t sec() const
Definition yateclass.h:3971
static u_int32_t secNow()
static bool isLeap(unsigned int year)
Definition yateclass.h:4167
~Time()
Definition yateclass.h:3964
static u_int64_t msecNow()
A text based DNS record.
Definition yateclass.h:8137
TxtRecord(int ttl, const char *text)
Definition yateclass.h:8146
static void copy(ObjList &dest, const ObjList &src)
virtual void dump(String &buf, const char *sep=" ")
const String & text() const
Definition yateclass.h:8154
A single Unicode character.
Definition yateclass.h:1963
const char * c_str() const
Definition yateclass.h:2029
static bool encode(uint16_t *&buff, unsigned int &len, const char *&str, Endianness order, bool addBOM=false)
bool encode(uint16_t *&buff, unsigned int &len, Endianness order)
bool decode(uint16_t *&buff, unsigned int &len, Endianness order, uint32_t maxChar=0x10ffff)
UChar & operator=(char code)
Definition yateclass.h:2015
UChar(uint32_t code=0)
Definition yateclass.h:1974
UChar(int32_t code)
Definition yateclass.h:1982
UChar & operator=(uint32_t code)
Definition yateclass.h:2007
bool decode(const char *&str, uint32_t maxChar=0x10ffff, bool overlong=false)
static bool decode(String &out, uint16_t *&buff, unsigned int &len, Endianness order, bool checkBOM=false, uint32_t maxChar=0x10ffff)
static bool encode(DataBlock &out, const char *&str, Endianness order, bool addBOM=false)
UChar(unsigned char code)
Definition yateclass.h:1998
bool decode(DataBlock &buff, Endianness order, uint32_t maxChar=0x10ffff)
bool encode(DataBlock &buff, Endianness order)
uint32_t code() const
Definition yateclass.h:2022
UChar(signed char code)
Definition yateclass.h:1990
Encapsulation for an URI.
Definition yateclass.h:5396
URI(const URI &uri)
const String & getUser() const
Definition yateclass.h:5475
virtual void changed()
URI(const char *proto, const char *user, const char *host, int port=0, const char *desc=0)
void parse() const
const String & getExtra() const
Definition yateclass.h:5496
URI & operator=(const String &value)
Definition yateclass.h:5447
URI(const char *uri)
const String & getDescription() const
Definition yateclass.h:5461
URI & operator=(const URI &value)
Definition yateclass.h:5440
URI & operator=(const char *value)
Definition yateclass.h:5454
int getPort() const
Definition yateclass.h:5489
URI(const String &uri)
const String & getProtocol() const
Definition yateclass.h:5468
const String & getHost() const
Definition yateclass.h:5482
Definition yatemime.h:34
Complex operator+(const Complex &c1, const Complex &c2)
Definition yatemath.h:1567
Definition yateclass.h:865
const char * token
Definition yateclass.h:869
int64_t value
Definition yateclass.h:874
Definition yateclass.h:848
const char * token
Definition yateclass.h:852
int value
Definition yateclass.h:857