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
239class Lockable;
240class Semaphore;
241class Mutex;
242class RWLock;
243class WLock;
244class RLock;
245class RWLockPrivate;
246class String;
247class DataBlock;
248class ObjList;
249class NamedCounter;
250class MutexPrivate;
251class SemaphorePrivate;
252class ThreadPrivate;
253struct TokenDictStr;
254struct TokenDictStr64;
255
260YATE_API void abortOnBug();
261
266YATE_API bool abortOnBug(bool doAbort);
267
273enum DebugLevel {
274 DebugFail = 0,
275 DebugTest = 1,
276 DebugCrit = 2,
277 DebugGoOn = DebugCrit,
278 DebugConf = 3,
279 DebugStub = 4,
280 DebugWarn = 5,
281 DebugMild = 6,
282 DebugNote = 7,
283 DebugCall = 8,
284 DebugInfo = 9,
285 DebugAll = 10
286};
287
292YATE_API int debugLevel();
293
299YATE_API int debugLevel(int level);
300
306YATE_API bool debugAt(int level);
307
314YATE_API const char* debugColor(int level);
315
321YATE_API const char* debugLevelName(int level);
322
328class YATE_API DebugEnabler
329{
330public:
336 inline DebugEnabler(int level = TelEngine::debugLevel(), bool enabled = true)
337 : m_level(DebugFail), m_enabled(enabled), m_chain(0), m_name(0)
338 { debugLevel(level); }
339
340 inline ~DebugEnabler()
341 { m_name = 0; m_chain = 0; }
342
347 inline int debugLevel() const
348 { return m_chain ? m_chain->debugLevel() : m_level; }
349
355 int debugLevel(int level);
356
361 inline bool debugEnabled() const
362 { return m_chain ? m_chain->debugEnabled() : m_enabled; }
363
368 inline void debugEnabled(bool enable)
369 { m_enabled = enable; m_chain = 0; }
370
375 inline const char* debugName() const
376 { return m_name; }
377
383 bool debugAt(int level) const;
384
389 inline bool debugChained() const
390 { return m_chain != 0; }
391
396 inline void debugChain(const DebugEnabler* chain = 0)
397 { m_chain = (chain != this) ? chain : 0; }
398
403 void debugCopy(const DebugEnabler* original = 0);
404
409 void debugSet(const char* desc);
410
411protected:
416 inline void debugName(const char* name)
417 { m_name = name; }
418
419private:
420 int m_level;
421 bool m_enabled;
422 const DebugEnabler* m_chain;
423 const char* m_name;
424};
425
426#if 0 /* for documentation generator */
432void DDebug(int level, const char* format, ...);
433
439void DDebug(const char* facility, int level, const char* format, ...);
440
446void DDebug(const DebugEnabler* local, int level, const char* format, ...);
447
453void XDebug(int level, const char* format, ...);
454
460void XDebug(const char* facility, int level, const char* format, ...);
461
467void XDebug(const DebugEnabler* local, int level, const char* format, ...);
468
474void NDebug(int level, const char* format, ...);
475
481void NDebug(const char* facility, int level, const char* format, ...);
482
488void NDebug(const DebugEnabler* local, int level, const char* format, ...);
489#endif
490
491#if defined(_DEBUG) || defined(DEBUG) || defined(XDEBUG)
492#undef DEBUG
493#define DEBUG 1
494#endif
495
496#ifdef DEBUG
497#define DDebug Debug
498#else
499#ifdef _WINDOWS
500#define DDebug do { break; } while
501#else
502#define DDebug(arg...)
503#endif
504#endif
505
506#ifdef XDEBUG
507#define XDebug Debug
508#else
509#ifdef _WINDOWS
510#define XDebug do { break; } while
511#else
512#define XDebug(arg...)
513#endif
514#endif
515
516#ifndef NDEBUG
517#define NDebug Debug
518#else
519#ifdef _WINDOWS
520#define NDebug do { break; } while
521#else
522#define NDebug(arg...)
523#endif
524#endif
525
531YATE_API void Debug(int level, const char* format, ...) FORMAT_CHECK(2);
532
539YATE_API void Debug(const char* facility, int level, const char* format, ...) FORMAT_CHECK(3);
540
547YATE_API void Debug(const DebugEnabler* local, int level, const char* format, ...) FORMAT_CHECK(3);
548
555YATE_API void Alarm(const char* component, int level, const char* format, ...) FORMAT_CHECK(3);
556
563YATE_API void Alarm(const DebugEnabler* component, int level, const char* format, ...) FORMAT_CHECK(3);
564
572YATE_API void Alarm(const char* component, const char* info, int level, const char* format, ...) FORMAT_CHECK(4);
573
581YATE_API void Alarm(const DebugEnabler* component, const char* info, int level, const char* format, ...) FORMAT_CHECK(4);
582
587YATE_API void Output(const char* format, ...) FORMAT_CHECK(1);
588
595YATE_API void TraceDebug(const char* traceId, int level, const char* format, ...) FORMAT_CHECK(3);
596
604YATE_API void TraceDebug(const char* traceId, const char* facility, int level,
605 const char* format, ...) FORMAT_CHECK(4);
606
614YATE_API void TraceDebug(const char* traceId, const DebugEnabler* local, int level,
615 const char* format, ...) FORMAT_CHECK(4);
616
617
618#if 0 /* for documentation generator */
625void TraceDebugObj(GenObject* obj, int level, const char* format, ...);
626
634void TraceDebugObj(GenObject* obj, const char* facility, int level, const char* format, ...);
635
643void TraceDebugObj(GenObject* obj, const DebugEnabler* local, int level, const char* format, ...);
644
651void Trace(GenObject* obj, int level, const char* format, ...);
652
660void Trace(GenObject* obj, const char* facility, int level, const char* format, ...);
661
669void Trace(GenObject* obj, const DebugEnabler* local, int level, const char* format, ...);
670
677void TraceObj(GenObject* obj, int level, const char* format, ...);
678
686void TraceObj(GenObject* obj, const char* facility, int level, const char* format, ...);
687
695void TraceObj(GenObject* obj, const DebugEnabler* local, int level, const char* format, ...);
696
697#endif
698
699#define TraceDebugObj(pGenObj,...) \
700TraceDebug((!!(pGenObj)) ? (pGenObj)->traceId() : "",##__VA_ARGS__)
701
702#define Trace(traceId,...) \
703do { if (!TelEngine::null(traceId)) TraceDebug(traceId,##__VA_ARGS__); } while(false)
704
705#define TraceObj(pGenObj,...) \
706do { if (!!(pGenObj) && (pGenObj)->traceId()) TraceDebug((pGenObj)->traceId(),##__VA_ARGS__); } while (false)
707
708
716YATE_API void TraceAlarm(const char* traceId, const char* component, int level,
717 const char* format, ...) FORMAT_CHECK(4);
718
726YATE_API void TraceAlarm(const char* traceId, const DebugEnabler* component,
727 int level, const char* format, ...) FORMAT_CHECK(4);
728
737YATE_API void TraceAlarm(const char* traceId, const char* component, const char* info,
738 int level, const char* format, ...) FORMAT_CHECK(5);
739
748YATE_API void TraceAlarm(const char* traceId, const DebugEnabler* component,
749 const char* info, int level, const char* format, ...) FORMAT_CHECK(5);
750
757class YATE_API Debugger
758{
759public:
764 None = 0,
765 Relative, // from program start
766 Absolute, // from EPOCH (1-1-1970)
767 Textual, // absolute GMT in YYYYMMDDhhmmss.uuuuuu format
768 TextLocal, // local time in YYYYMMDDhhmmss.uuuuuu format
769 TextSep, // absolute GMT in YYYY-MM-DD_hh:mm:ss.uuuuuu format
770 TextLSep, // local time in YYYY-MM-DD_hh:mm:ss.uuuuuu format
771 };
772
778 explicit Debugger(const char* name, const char* format = 0, ...);
779
786 Debugger(int level, const char* name, const char* format = 0, ...);
787
795 Debugger(DebugEnabler* enabler, int level, const char* name, const char* format = 0, ...);
796
801
806 static void setOutput(void (*outFunc)(const char*,int) = 0);
807
812 static void setIntOut(void (*outFunc)(const char*,int) = 0);
813
818 static void setAlarmHook(void (*alarmFunc)(const char*,int,const char*,const char*) = 0);
819
824 static void setRelayHook(void (*relayFunc)(int,const char*,const char*,const char*) = 0);
825
831 static void enableOutput(bool enable = true, bool colorize = false);
832
837 static uint32_t getStartTimeSec();
838
844
850 static void setFormatting(Formatting format, uint32_t startTimeSec = 0);
851
858 static unsigned int formatTime(char* buf, Formatting format = getFormatting());
859
868 static void relayOutput(int level, char* buffer, const char* component = 0, const char* info = 0);
869
874 static void outputTimestamp(bool on);
875
880 static bool outputTimestamp();
881
882private:
883 const char* m_name;
884 int m_level;
885};
886
891struct TokenDict {
895 const char* token;
896
900 int value;
901};
902
912 const char* token;
913
917 int64_t value;
918};
919
920
921#if 0 /* for documentation generator */
926void YIGNORE(primitive value);
927
933constant YSTRING(const char* string);
934
940constant YATOM(const char* string);
941
947void YCLASS(class type,class base);
948
955void YCLASS2(class type,class base1,class base2);
956
964void YCLASS3(class type,class base1,class base2,class base3);
965
973void YCLASS_DATA(var dataPtr,class type,class base);
974
983void YCLASS2_DATA(var dataPtr,class type,class base1,class base2);
984
994void YCLASS3_DATA(var dataPtr,class type,class base1,class base2,class base3);
995
1001void YCLASSIMP(class type,class base);
1002
1009void YCLASSIMP2(class type,class base1,class base2);
1010
1018void YCLASSIMP3(class type,class base1,class base2,class base3);
1019
1026class* YOBJECT(class type,GenObject* pntr);
1027
1032void YNOCOPY(class type);
1033#endif
1034
1035#define YCLASS(type,base) \
1036public: virtual void* getObject(const String& name) const \
1037{ return (name == YATOM(#type)) ? const_cast<type*>(this) : base::getObject(name); }
1038
1039#define YCLASS2(type,base1,base2) \
1040public: virtual void* getObject(const String& name) const \
1041{ if (name == YATOM(#type)) return const_cast<type*>(this); \
1042 void* tmp = base1::getObject(name); \
1043 return tmp ? tmp : base2::getObject(name); }
1044
1045#define YCLASS3(type,base1,base2,base3) \
1046public: virtual void* getObject(const String& name) const \
1047{ if (name == YATOM(#type)) return const_cast<type*>(this); \
1048 void* tmp = base1::getObject(name); \
1049 if (tmp) return tmp; \
1050 tmp = base2::getObject(name); \
1051 return tmp ? tmp : base3::getObject(name); }
1052
1053#define YCLASS_CALL(res) { void* tmp = res; if (tmp) return tmp; }
1054#define YCLASS_CALL_LAST(base1,base2) { void* tmp = base1::getObject(name); return tmp ? tmp : base2::getObject(name); }
1055#define YCLASS_DATA_CHECK_PTR(dataPtr,type) { \
1056 if (dataPtr) YCLASS_CALL((dataPtr)->getObject(name)) \
1057 if (name == YATOM(#type)) return const_cast<type*>(this); \
1058}
1059
1060#define YCLASS_DATA(dataPtr,type,base) \
1061public: virtual void* getObject(const String& name) const { \
1062 YCLASS_DATA_CHECK_PTR(dataPtr,type) \
1063 return base::getObject(name); \
1064}
1065
1066#define YCLASS2_DATA(dataPtr,type,base1,base2) \
1067public: virtual void* getObject(const String& name) const { \
1068 YCLASS_DATA_CHECK_PTR(dataPtr,type) \
1069 YCLASS_CALL_LAST(base,base2) \
1070}
1071
1072#define YCLASS3_DATA(dataPtr,type,base1,base2,base3) \
1073public: virtual void* getObject(const String& name) const { \
1074 YCLASS_DATA_CHECK_PTR(dataPtr,type) \
1075 YCLASS_CALL(base1::getObject(name)) \
1076 YCLASS_CALL_LAST(base2,base3) \
1077}
1078
1079#define YCLASSIMP(type,base) \
1080void* type::getObject(const String& name) const \
1081{ return (name == YATOM(#type)) ? const_cast<type*>(this) : base::getObject(name); }
1082
1083#define YCLASSIMP2(type,base1,base2) \
1084void* type::getObject(const String& name) const \
1085{ if (name == YATOM(#type)) return const_cast<type*>(this); \
1086 void* tmp = base1::getObject(name); \
1087 return tmp ? tmp : base2::getObject(name); }
1088
1089#define YCLASSIMP3(type,base1,base2,base3) \
1090void* type::getObject(const String& name) const \
1091{ if (name == YATOM(#type)) return const_cast<type*>(this); \
1092 void* tmp = base1::getObject(name); \
1093 if (tmp) return tmp; \
1094 tmp = base2::getObject(name); \
1095 return tmp ? tmp : base3::getObject(name); }
1096
1097#define YOBJECT(type,pntr) (static_cast<type*>(GenObject::getObject(YATOM(#type),pntr)))
1098
1099#define YNOCOPY(type) private: \
1100type(const type&); \
1101void operator=(const type&)
1102
1103
1109YATE_API inline uint32_t hashInt64(uint64_t val)
1110{
1111 return (uint32_t)(((val ^ (val >> 48)) ^ (val >> 32)) ^ (val >> 16));
1112}
1113
1119YATE_API inline uint32_t hashInt32(uint32_t val)
1120{
1121 return (uint32_t)((val ^ (val >> 16)) ^ (val << 16));
1122}
1123
1129YATE_API inline uint32_t hashPtr(const void* ptr)
1130{
1131#if (_WORDSIZE == 64)
1132 return hashInt64((uintptr_t)ptr);
1133#else
1134 return hashInt32((uintptr_t)ptr);
1135#endif
1136}
1137
1154template <class Obj> void yateSort(Obj* buf, unsigned int len,
1155 int (*callbackCompare)(Obj& obj1, Obj& obj2, void* context),
1156 void* context = 0)
1157{
1158 if (!buf)
1159 return;
1160 while (len > 1) {
1161 unsigned int n = len;
1162 len = 0;
1163 for (unsigned int i = 1; i < n; ++i) {
1164 if (callbackCompare(buf[i - 1],buf[i],context) <= 0)
1165 continue;
1166 Obj tmp = buf[i - 1];
1167 buf[i - 1] = buf[i];
1168 buf[i] = tmp;
1169 len = i;
1170 }
1171 }
1172}
1173
1174
1175#undef YATOMIC_BUILTIN
1176#define YATOMIC_LOCK
1177#ifdef ATOMIC_OPS
1178 #ifndef _WINDOWS
1179 #define YATOMIC_BUILTIN
1180 #undef YATOMIC_LOCK
1181 #endif
1182#endif
1183#ifdef YATOMIC_LOCK
1184 #define YATOMIC_OP_LOCK_WRITE WLock lck(m_lock)
1185 #define YATOMIC_OP_LOCK_READ RLock lck(m_lock)
1186#else
1187 #define YATOMIC_OP_LOCK_WRITE {}
1188 #define YATOMIC_OP_LOCK_READ {}
1189#endif
1190
1195class YATE_API AtomicOp
1196{
1197public:
1202
1207 inline RWLock* lock() const
1208 { return m_lock; }
1209
1214 static bool efficient();
1215
1216protected:
1220 mutable RWLock* m_lock;
1221};
1222
1227template <class Type> class YAtomicNumber : public AtomicOp
1228{
1229public:
1234 : m_value(0)
1235 {}
1236
1241 explicit inline YAtomicNumber(Type val)
1242 : m_value(val)
1243 {}
1244
1249 explicit inline YAtomicNumber(const YAtomicNumber& val)
1250 : m_value(val.valueAtomic())
1251 {}
1252
1257 inline Type value() const
1258 { return m_value; }
1259
1264 inline Type value()
1265 { return m_value; }
1266
1271 inline Type& valueRef()
1272 { return m_value; }
1273
1278 inline Type valueAtomic() const {
1279#ifdef YATOMIC_BUILTIN
1280 return __sync_add_and_fetch(&m_value,0);
1281#else
1282 YATOMIC_OP_LOCK_READ;
1283 return m_value;
1284#endif
1285 }
1286
1291 inline Type valueAtomic() {
1292#ifdef YATOMIC_BUILTIN
1293 return __sync_add_and_fetch(&m_value,0);
1294#else
1295 YATOMIC_OP_LOCK_READ;
1296 return m_value;
1297#endif
1298 }
1299
1305 inline Type set(Type val) {
1306#ifdef YATOMIC_BUILTIN
1307 return __sync_val_compare_and_swap(&m_value,valueAtomic(),val);
1308#else
1309 YATOMIC_OP_LOCK_WRITE;
1310 int old = m_value;
1311 m_value = val;
1312 return old;
1313#endif
1314 }
1315
1320 inline Type inc() {
1321#ifdef YATOMIC_BUILTIN
1322 return __sync_add_and_fetch(&m_value,1);
1323#else
1324 YATOMIC_OP_LOCK_WRITE;
1325 return ++m_value;
1326#endif
1327 }
1328
1333 inline Type dec() {
1334#ifdef YATOMIC_BUILTIN
1335 return __sync_sub_and_fetch(&m_value,1);
1336#else
1337 YATOMIC_OP_LOCK_WRITE;
1338 return --m_value;
1339#endif
1340 }
1341
1347 inline Type add(Type val) {
1348#ifdef YATOMIC_BUILTIN
1349 return __sync_add_and_fetch(&m_value,val);
1350#else
1351 YATOMIC_OP_LOCK_WRITE;
1352 m_value += val;
1353 return m_value;
1354#endif
1355 }
1356
1362 inline Type sub(Type val) {
1363#ifdef YATOMIC_BUILTIN
1364 return __sync_sub_and_fetch(&m_value,val);
1365#else
1366 YATOMIC_OP_LOCK_WRITE;
1367 m_value -= val;
1368 return m_value;
1369#endif
1370 }
1371
1377 inline Type bitAnd(Type val) {
1378#ifdef YATOMIC_BUILTIN
1379 return __sync_and_and_fetch(&m_value,val);
1380#else
1381 YATOMIC_OP_LOCK_WRITE;
1382 m_value &= val;
1383 return m_value;
1384#endif
1385 }
1386
1392 inline Type bitOr(Type val) {
1393#ifdef YATOMIC_BUILTIN
1394 return __sync_or_and_fetch(&m_value,val);
1395#else
1396 YATOMIC_OP_LOCK_WRITE;
1397 m_value |= val;
1398 return m_value;
1399#endif
1400 }
1401
1407 inline Type bitXor(Type val) {
1408#ifdef YATOMIC_BUILTIN
1409 return __sync_xor_and_fetch(&m_value,val);
1410#else
1411 YATOMIC_OP_LOCK_WRITE;
1412 m_value ^= val;
1413 return m_value;
1414#endif
1415 }
1416
1421 inline Type preInc() {
1422#ifdef YATOMIC_BUILTIN
1423 return __sync_fetch_and_add(&m_value,1);
1424#else
1425 YATOMIC_OP_LOCK_WRITE;
1426 int old = m_value++;
1427 return old;
1428#endif
1429 }
1430
1435 inline Type preDec() {
1436#ifdef YATOMIC_BUILTIN
1437 return __sync_fetch_and_sub(&m_value,1);
1438#else
1439 YATOMIC_OP_LOCK_WRITE;
1440 int old = m_value--;
1441 return old;
1442#endif
1443 }
1444
1450 inline Type preAdd(Type val) {
1451#ifdef YATOMIC_BUILTIN
1452 return __sync_fetch_and_add(&m_value,val);
1453#else
1454 YATOMIC_OP_LOCK_WRITE;
1455 int old = m_value;
1456 m_value += val;
1457 return old;
1458#endif
1459 }
1460
1466 inline Type preSub(Type val) {
1467#ifdef YATOMIC_BUILTIN
1468 return __sync_fetch_and_sub(&m_value,val);
1469#else
1470 YATOMIC_OP_LOCK_WRITE;
1471 int old = m_value;
1472 m_value -= val;
1473 return old;
1474#endif
1475 }
1476
1482 inline Type preBitAnd(Type val) {
1483#ifdef YATOMIC_BUILTIN
1484 return __sync_fetch_and_and(&m_value,val);
1485#else
1486 YATOMIC_OP_LOCK_WRITE;
1487 Type old = m_value;
1488 m_value &= val;
1489 return old;
1490#endif
1491 }
1492
1498 inline Type preBitOr(Type val) {
1499#ifdef YATOMIC_BUILTIN
1500 return __sync_fetch_and_or(&m_value,val);
1501#else
1502 YATOMIC_OP_LOCK_WRITE;
1503 Type old = m_value;
1504 m_value |= val;
1505 return old;
1506#endif
1507 }
1508
1514 inline Type preBitXor(Type val) {
1515#ifdef YATOMIC_BUILTIN
1516 return __sync_fetch_and_xor(&m_value,val);
1517#else
1518 YATOMIC_OP_LOCK_WRITE;
1519 Type old = m_value;
1520 m_value ^= val;
1521 return old;
1522#endif
1523 }
1524
1529 inline operator Type()
1530 { return valueAtomic(); }
1531
1536 inline operator Type() const
1537 { return valueAtomic(); }
1538
1543 inline YAtomicNumber& operator=(Type val)
1544 { set(val); return *this; }
1545
1551 { set((Type)val); return *this; }
1552
1557 inline Type operator+=(Type val)
1558 { return add(val); }
1559
1563 inline Type operator++()
1564 { return inc(); }
1565
1569 inline Type operator--()
1570 { return dec(); }
1571
1575 inline Type operator++(int)
1576 { return preInc(); }
1577
1581 inline Type operator--(int)
1582 { return preDec(); }
1583
1588 inline Type operator-=(Type val)
1589 { return sub(val); }
1590
1595 inline Type operator&=(Type val)
1596 { return bitAnd(val); }
1597
1602 inline Type operator|=(Type val)
1603 { return bitOr(val); }
1604
1609 inline Type operator^=(Type val)
1610 { return bitXor(val); }
1611
1612protected:
1613 mutable Type m_value;
1614};
1615
1622
1626class YATE_API GenObject
1627{
1628 YNOCOPY(GenObject); // no automatic copies please
1629public:
1634
1638 virtual ~GenObject() { setObjCounter(0); }
1639
1646 virtual bool alive() const;
1647
1651 virtual void destruct();
1652
1659 virtual const String& toString() const;
1660
1665 virtual const String& traceId() const;
1666
1672 virtual void* getObject(const String& name) const;
1673
1680 static inline void* getObject(const String& name, const GenObject* obj)
1681 { return obj ? obj->getObject(name) : 0; }
1682
1687 static inline bool getObjCounting()
1688 { return s_counting; }
1689
1694 static inline void setObjCounting(bool enable)
1695 { s_counting = enable; }
1696
1702 { return m_counter; }
1703
1710
1717 static NamedCounter* getObjCounter(const String& name, bool create = true);
1718
1724
1725private:
1726 NamedCounter* m_counter;
1727 static bool s_counting;
1728};
1729
1735inline void destruct(GenObject* obj)
1736 { if (obj) obj->destruct(); }
1737
1744template <class Obj> void destruct(Obj*& obj)
1745 { if (obj) { obj->destruct(); obj = 0; } }
1746
1751class YATE_API RefObject : public GenObject
1752{
1753 YNOCOPY(RefObject); // no automatic copies please
1754public:
1760
1764 virtual ~RefObject();
1765
1771 virtual void* getObject(const String& name) const;
1772
1779 virtual bool alive() const;
1780
1785 bool ref();
1786
1795 bool deref();
1796
1801 inline int refcount() const
1802 { return m_refcount; }
1803
1808 virtual void destruct();
1809
1815 inline static bool alive(const RefObject* obj)
1816 { return obj && (obj->refcount() > 0); }
1817
1823 static bool efficientIncDec();
1824
1825protected:
1831 virtual void zeroRefs();
1832
1839
1845 virtual void destroyed();
1846
1847private:
1848 int m_refcount;
1849 Mutex* m_mutex;
1850};
1851
1857class YATE_API RefPointerBase
1858{
1859protected:
1864 : m_pointer(0) { }
1865
1872 void assign(RefObject* oldptr, RefObject* newptr, void* pointer);
1873
1878};
1879
1883template <class Obj = RefObject> class RefPointer : public RefPointerBase
1884{
1885protected:
1890 inline Obj* pointer() const
1891 { return static_cast<Obj*>(m_pointer); }
1892
1897 inline void assign(Obj* object = 0)
1898 { RefPointerBase::assign(pointer(),object,object); }
1899
1900public:
1904 inline RefPointer()
1905 { }
1906
1911 inline RefPointer(const RefPointer<Obj>& value)
1912 : RefPointerBase()
1913 { assign(value); }
1914
1919 inline RefPointer(Obj* object)
1920 { assign(object); }
1921
1926 { assign(); }
1927
1932 { assign(value.pointer()); return *this; }
1933
1937 inline RefPointer<Obj>& operator=(Obj* object)
1938 { assign(object); return *this; }
1939
1944 inline operator Obj*() const
1945 { return pointer(); }
1946
1950 inline Obj* operator->() const
1951 { return pointer(); }
1952
1956 inline Obj& operator*() const
1957 { return *pointer(); }
1958};
1959
1963template <class Obj = GenObject> class GenPointer : public GenObject
1964{
1965private:
1969 Obj* m_pointer;
1970
1971public:
1975 inline GenPointer()
1976 : m_pointer(0)
1977 { }
1978
1983 inline GenPointer(const GenPointer<Obj>& value)
1984 : m_pointer(value)
1985 { }
1986
1991 inline GenPointer(Obj* object)
1992 : m_pointer(object)
1993 { }
1994
1999 { m_pointer = value; return *this; }
2000
2004 inline GenPointer<Obj>& operator=(Obj* object)
2005 { m_pointer = object; return *this; }
2006
2011 inline operator Obj*() const
2012 { return m_pointer; }
2013
2017 inline Obj* operator->() const
2018 { return m_pointer; }
2019
2023 inline Obj& operator*() const
2024 { return *m_pointer; }
2025};
2026
2031class YATE_API ObjList : public GenObject
2032{
2033 YNOCOPY(ObjList); // no automatic copies please
2034public:
2039
2043 virtual ~ObjList();
2044
2050 virtual void* getObject(const String& name) const;
2051
2056 unsigned int length() const;
2057
2062 unsigned int count() const;
2063
2068 inline GenObject* get() const
2069 { return m_obj; }
2070
2077 GenObject* set(const GenObject* obj, bool delold = true);
2078
2083 inline ObjList* next() const
2084 { return m_next; }
2085
2090 ObjList* last() const;
2091
2097
2103
2109 GenObject* at(int index) const;
2110
2116 ObjList* operator+(int index) const;
2117
2123 inline GenObject* operator[](signed int index) const
2124 { return at(index); }
2125
2131 inline GenObject* operator[](unsigned int index) const
2132 { return at(index); }
2133
2139 inline GenObject* operator[](const String& str) const {
2140 ObjList* o = find(str);
2141 return o ? o->get() : 0;
2142 }
2143
2149 ObjList* find(const GenObject* obj) const;
2150
2156 inline GenObject* findObj(const GenObject* obj) const {
2157 ObjList* o = find(obj);
2158 return o ? o->get() : 0;
2159 }
2160
2166 ObjList* find(const String& str) const;
2167
2173 int index(const GenObject* obj) const;
2174
2180 int index(const String& str) const;
2181
2188 ObjList* insert(const GenObject* obj, bool compact = true);
2189
2196 ObjList* append(const GenObject* obj, bool compact = true);
2197
2204 ObjList* setUnique(const GenObject* obj, bool compact = true);
2205
2211 GenObject* remove(bool delobj = true);
2212
2219 GenObject* remove(GenObject* obj, bool delobj = true);
2220
2227 GenObject* remove(const String& str, bool delobj = true);
2228
2232 void clear();
2233
2237 void compact();
2238
2243 inline bool autoDelete()
2244 { return m_delete; }
2245
2250 inline void setDelete(bool autodelete)
2251 { m_delete = autodelete; }
2252
2262 GenObject* find(Lockable& lock, const GenObject* obj, bool ref = false, long maxwait = -1) const;
2263
2273 GenObject* find(Lockable& lock, const String& str, bool ref = false, long maxwait = -1) const;
2274
2284 ObjList* insert(Lockable& lock, const GenObject* obj, bool autoDelete = true,
2285 long maxwait = -1, bool compact = true);
2286
2296 ObjList* append(Lockable& lock, const GenObject* obj, bool autoDelete = true,
2297 long maxwait = -1, bool compact = true);
2298
2308 ObjList* setUnique(Lockable& lock, const GenObject* obj, bool autoDelete = true,
2309 long maxwait = -1, bool compact = true);
2310
2318 GenObject* remove(Lockable& lock, bool delobj = true, long maxwait = -1);
2319
2328 GenObject* remove(Lockable& lock, GenObject* obj, bool delobj = true, long maxwait = -1);
2329
2338 GenObject* remove(Lockable& lock, const String& str, bool delobj = true, long maxwait = -1);
2339
2345 void clear(Lockable& lock, long maxwait = -1);
2346
2352 void compact(Lockable& lock, long maxwait = -1);
2353
2362 ObjList* move(ObjList* dest, Lockable* lock = 0, long maxwait = -1);
2363
2371 ObjList* copy(ObjList* dest, Lockable* lock = 0, long maxwait = -1) const;
2372
2377 static const ObjList& empty();
2378
2391 void sort(int (*callbackCompare)(GenObject* obj1, GenObject* obj2, void* context), void* context = 0);
2392private:
2393 ObjList* m_next;
2394 GenObject* m_obj;
2395 bool m_delete;
2396};
2397
2402class YATE_API ObjVector : public GenObject
2403{
2404 YNOCOPY(ObjVector); // no automatic copies please
2405public:
2411 inline explicit ObjVector(bool autodelete = true, unsigned int allocChunk = 0)
2412 : m_length(0), m_objects(0), m_delete(autodelete), m_size(0), m_allocChunk(allocChunk)
2413 { }
2414
2421 ObjVector(unsigned int maxLen, bool autodelete = true, unsigned int allocChunk = 0);
2422
2431 ObjVector(ObjList& list, bool move = true, unsigned int maxLen = 0, bool autodelete = true,
2432 unsigned int allocChunk = 0);
2433
2437 virtual ~ObjVector();
2438
2444 virtual void* getObject(const String& name) const;
2445
2450 inline unsigned int length() const
2451 { return m_length; }
2452
2457 inline GenObject** data()
2458 { return m_objects; }
2459
2466 inline GenObject** data(unsigned int offs, unsigned int len = 1)
2467 { return (offs + len <= m_length) ? m_objects + offs : 0; }
2468
2473 inline const GenObject** data() const
2474 { return (const GenObject**)m_objects; }
2475
2482 inline const GenObject** data(unsigned int offs, unsigned int len = 1) const
2483 { return (offs + len <= m_length) ? (const GenObject**)m_objects + offs : 0; }
2484
2489 unsigned int count() const;
2490
2495 bool null() const;
2496
2502 inline GenObject* at(unsigned int index) const
2503 { return index < m_length ? m_objects[index] : 0; }
2504
2512 unsigned int assign(ObjList& list, bool move = true, unsigned int maxLen = 0);
2513
2520 unsigned int insert(unsigned int pos, unsigned int items);
2521
2529 unsigned int cut(unsigned int pos, unsigned int items, bool reAlloc = true);
2530
2537 inline unsigned int cut(int items, bool reAlloc = true) {
2538 if (!items)
2539 return m_length;
2540 if (items < 0)
2541 return cut(0,-items,reAlloc);
2542 if ((unsigned int)items < m_length)
2543 return cut(m_length - items,items,reAlloc);
2544 return cut(0,m_length,reAlloc);
2545 }
2546
2555 inline unsigned int resize(unsigned int len, bool keepData = false, bool reAlloc = true) {
2556 if (!len) {
2557 clear();
2558 return length();
2559 }
2560 if (!keepData)
2561 reset();
2562 return (len == length()) ? length(): (len > length() ?
2563 insert(length(),len - length()) : cut(len,length() - len,reAlloc));
2564 }
2565
2571 inline unsigned int compact(bool resizeToCount = false) {
2572 unsigned int n = compact(0,m_length);
2573 if (resizeToCount)
2574 resize(n,true);
2575 return n;
2576 }
2577
2584 unsigned int compact(unsigned int pos, int len);
2585
2591 inline GenObject* take(unsigned int index) {
2592 GenObject* ret = at(index);
2593 if (ret)
2594 m_objects[index] = 0;
2595 return ret;
2596 }
2597
2604 bool set(GenObject* obj, unsigned int index);
2605
2611 inline bool appendObj(GenObject* obj) {
2612 unsigned int idx = length();
2613 return idx < resize(length() + 1,true) && (!obj || set(obj,idx));
2614 }
2615
2624 inline bool appendObj(GenObject* obj, bool fromStart, bool beforeNonNull = false) {
2625 int idx = indexFree(fromStart,beforeNonNull);
2626 if (idx < 0)
2627 return appendObj(obj);
2628 set(obj,idx);
2629 return true;
2630 }
2631
2638 inline bool insertObj(GenObject* obj, unsigned int pos) {
2639 if (pos >= length())
2640 return appendObj(obj);
2641 unsigned int n = length();
2642 return (n < insert(pos,1)) && set(obj,pos);
2643 }
2644
2650 int index(const GenObject* obj) const;
2651
2657 int index(const String& str) const;
2658
2666 int indexFree(bool fromStart, bool beforeNonNull = false) const;
2667
2673 inline GenObject* operator[](unsigned int idx) const
2674 { return at(idx); }
2675
2681 inline GenObject* operator[](signed int idx) const
2682 { return idx < 0 ? 0 : at(idx); }
2683
2689 inline GenObject* operator[](const String& str) const {
2690 int idx = index(str);
2691 return idx >= 0 ? m_objects[idx] : 0;
2692 }
2693
2697 void clear();
2698
2704 void reset(unsigned int pos = 0, int len = -1);
2705
2710 inline bool autoDelete()
2711 { return m_delete; }
2712
2717 inline void setDelete(bool autodelete)
2718 { m_delete = autodelete; }
2719
2724 inline unsigned int allocChunk() const
2725 { return m_allocChunk; }
2726
2731 inline void allocChunk(unsigned int count)
2732 { m_allocChunk = count; }
2733
2738 inline unsigned int size() const
2739 { return m_size; }
2740
2741private:
2742 // Calculate allocate size. Assumes given 'len' is checked.
2743 // Return 0 if required len falls into [m_length .. m_size] interval
2744 inline unsigned int allocLen(unsigned int len) {
2745 if (!len || m_allocChunk < 2)
2746 return len;
2747 // Allocate using over alloc chunks
2748 unsigned int rest = len % m_allocChunk;
2749 if (rest)
2750 len += m_allocChunk - rest;
2751 return m_length <= len && len <= m_size ? 0 : len;
2752 }
2753
2754 unsigned int m_length;
2755 GenObject** m_objects;
2756 bool m_delete;
2757 unsigned int m_size;
2758 unsigned int m_allocChunk;
2759};
2760
2769class YATE_API Array : public RefObject
2770{
2771public:
2777 explicit Array(int columns = 0, int rows = 0);
2778
2782 virtual ~Array();
2783
2789 virtual void* getObject(const String& name) const;
2790
2797 bool addRow(ObjList* row = 0, int index = -1);
2798
2805 bool addColumn(ObjList* column = 0, int index = -1);
2806
2812 bool delRow(int index);
2813
2819 bool delColumn(int index);
2820
2827 GenObject* get(int column, int row) const;
2828
2835 GenObject* take(int column, int row);
2836
2844 bool set(GenObject* obj, int column, int row);
2845
2850 inline int getRows() const
2851 { return m_rows; }
2852
2857 inline int getColumns() const
2858 { return m_columns; }
2859
2867 inline ObjList* getColumn(int column) const {
2868 if (column >= 0 || column < m_columns)
2869 return static_cast<ObjList*>(m_obj[column]);
2870 return 0;
2871 }
2872
2873private:
2874 int m_rows;
2875 int m_columns;
2876 ObjList m_obj;
2877};
2878
2879class Regexp;
2880class StringMatchPrivate;
2881
2886class YATE_API UChar
2887{
2888public:
2889 enum Endianness {
2890 LE = 0,
2891 BE = 1,
2892 Native = 2,
2893 };
2898 inline explicit UChar(uint32_t code = 0)
2899 : m_chr(code)
2900 { encode(); }
2901
2906 inline explicit UChar(int32_t code)
2907 : m_chr((code < 0) ? 0 : code)
2908 { encode(); }
2909
2914 inline explicit UChar(signed char code)
2915 : m_chr((unsigned char)code)
2916 { encode(); }
2917
2922 inline explicit UChar(unsigned char code)
2923 : m_chr(code)
2924 { encode(); }
2925
2931 inline UChar& operator=(uint32_t code)
2932 { m_chr = code; encode(); return *this; }
2933
2939 inline UChar& operator=(char code)
2940 { m_chr = (unsigned char)code; encode(); return *this; }
2941
2946 inline uint32_t code() const
2947 { return m_chr; }
2948
2953 inline const char* c_str() const
2954 { return m_str; }
2955
2960 inline operator const char*() const
2961 { return m_str; };
2962
2970 bool decode(const char*& str, uint32_t maxChar = 0x10ffff, bool overlong = false);
2971
2980 bool decode(uint16_t*& buff, unsigned int& len, Endianness order, uint32_t maxChar = 0x10ffff);
2981
2989 bool decode(DataBlock& buff, Endianness order, uint32_t maxChar = 0x10ffff);
2990
2998 bool encode(uint16_t*& buff, unsigned int& len, Endianness order);
2999
3006 bool encode(DataBlock& buff, Endianness order);
3007
3018 static bool decode(String& out, uint16_t*& buff, unsigned int& len, Endianness order, bool checkBOM = false, uint32_t maxChar = 0x10ffff);
3019
3028 static bool encode(DataBlock& out, const char*& str, Endianness order, bool addBOM = false);
3029
3039 static bool encode(uint16_t*& buff, unsigned int& len, const char*& str, Endianness order, bool addBOM = false);
3040
3041private:
3042 void encode();
3043 uint32_t m_chr;
3044 char m_str[8];
3045};
3046
3054class YATE_API String : public GenObject
3055{
3056public:
3057 enum Align {
3058 Left = 0,
3059 Center,
3060 Right
3061 };
3062
3067
3073 String(const char* value, int len = -1);
3074
3080 explicit String(char value, unsigned int repeat = 1);
3081
3086 explicit String(int32_t value);
3087
3092 explicit String(uint32_t value);
3093
3098 explicit String(int64_t value);
3099
3104 explicit String(uint64_t value);
3105
3110 explicit String(bool value);
3111
3116 explicit String(double value);
3117
3122 String(const String& value);
3123
3128 String(const String* value);
3129
3133 virtual ~String();
3134
3140 virtual void* getObject(const String& name) const;
3141
3146 static const String& empty();
3147
3153 inline static const char* boolText(bool value)
3154 { return value ? "true" : "false"; }
3155
3160 inline const char* c_str() const
3161 { return m_string; }
3162
3167 inline const char* safe() const
3168 { return m_string ? m_string : ""; }
3169
3175 inline const char* safe(const char* defStr) const
3176 { return m_string ? m_string : (defStr ? defStr : ""); }
3177
3182 inline unsigned int length() const
3183 { return m_length; }
3184
3189 inline bool null() const
3190 { return !m_string; }
3191
3199 static int lenUtf8(const char* value, uint32_t maxChar = 0x10ffff, bool overlong = false);
3200
3207 inline int lenUtf8(uint32_t maxChar = 0x10ffff, bool overlong = false) const
3208 { return lenUtf8(m_string,maxChar,overlong); }
3209
3217 int fixUtf8(const char* replace = 0, uint32_t maxChar = 0x10ffff, bool overlong = false);
3218
3224 unsigned int encodeFlags(const TokenDict* tokens) const;
3225
3231 uint64_t encodeFlags(const TokenDict64* tokens) const;
3232
3240 String& decodeFlags(unsigned int flags, const TokenDict* tokens, bool unknownflag = true);
3241
3249 String& decodeFlags(uint64_t flags, const TokenDict64* tokens, bool unknownflag = true);
3250
3256 inline static bool checkBOM(const char* str)
3257 { return str && (str[0] == '\357') && (str[1] == '\273') && (str[2] == '\277'); }
3258
3263 inline bool checkBOM() const
3264 { return checkBOM(c_str()); }
3265
3271 inline static bool stripBOM(const char*& str)
3272 { return checkBOM(str) && (str += 3); }
3273
3279 inline static bool stripBOM(char*& str)
3280 { return checkBOM(str) && (str += 3); }
3281
3286 inline bool stripBOM()
3287 { return checkBOM(c_str()) && &(*this = c_str() + 3); }
3288
3293 inline unsigned int hash() const
3294 {
3295 if (m_hash == YSTRING_INIT_HASH)
3296 m_hash = hash(m_string);
3297 return m_hash;
3298 }
3299
3306 static unsigned int hash(const char* value, unsigned int h = 0);
3307
3311 void clear();
3312
3318 char at(int index) const;
3319
3326 String substr(int offs, int len = -1) const;
3327
3332
3338
3343 virtual const String& toString() const;
3344
3355 int toInteger(int defvalue = 0, int base = 0, int minvalue = INT_MIN,
3356 int maxvalue = INT_MAX, bool clamp = true) const;
3357
3365 int toInteger(const TokenDict* tokens, int defvalue = 0, int base = 0) const;
3366
3374 int toInteger(const TokenDictStr* tokens, int defvalue = 0, int base = 0) const;
3375
3386 long int toLong(long int defvalue = 0, int base = 0, long int minvalue = LONG_MIN,
3387 long int maxvalue = LONG_MAX, bool clamp = true) const;
3388
3399 int64_t toInt64(int64_t defvalue = 0, int base = 0, int64_t minvalue = LLONG_MIN,
3400 int64_t maxvalue = LLONG_MAX, bool clamp = true) const;
3401
3409 int64_t toInt64Dict(const TokenDict64* tokens, int64_t defvalue = 0, int base = 0) const;
3410
3418 int64_t toInt64Dict(const TokenDictStr64* tokens, int64_t defvalue = 0, int base = 0) const;
3419
3430 uint64_t toUInt64(uint64_t defvalue = 0, int base = 0, uint64_t minvalue = 0,
3431 uint64_t maxvalue = ULLONG_MAX, bool clamp = true) const;
3432
3438 double toDouble(double defvalue = 0.0) const;
3439
3445 bool toBoolean(bool defvalue = false) const;
3446
3451 bool isBoolean() const;
3452
3458
3464
3470 inline char operator[](signed int index) const
3471 { return at(index); }
3472
3478 inline char operator[](unsigned int index) const
3479 { return at(index); }
3480
3485 inline operator const char*() const
3486 { return m_string; };
3487
3494 String& assign(const char* value, int len = -1);
3495
3502 String& assign(char value, unsigned int repeat = 1);
3503
3512 String& hexify(const void* data, unsigned int len, char sep = 0, bool upCase = false);
3513
3518 inline String& operator=(const String& value)
3519 { return operator=(value.c_str()); }
3520
3526 inline String& operator=(const String* value)
3527 { return operator=(value ? value->c_str() : ""); }
3528
3534 String& operator=(const char* value);
3535
3540 String& operator=(char value);
3541
3546 String& operator=(int32_t value);
3547
3552 String& operator=(uint32_t value);
3553
3558 String& operator=(int64_t value);
3559
3564 String& operator=(uint64_t value);
3565
3570 inline String& operator=(bool value)
3571 { return operator=(boolText(value)); }
3572
3577 String& operator=(double value);
3578
3584 inline String& operator+=(const char* value)
3585 { return append(value,-1); }
3586
3591 String& operator+=(char value);
3592
3597 String& operator+=(int32_t value);
3598
3603 String& operator+=(uint32_t value);
3604
3609 String& operator+=(int64_t value);
3610
3615 String& operator+=(uint64_t value);
3616
3621 inline String& operator+=(bool value)
3622 { return operator+=(boolText(value)); }
3623
3628 String& operator+=(double value);
3629
3633 bool operator==(const char* value) const;
3634
3638 bool operator!=(const char* value) const;
3639
3643 inline bool operator==(const String& value) const
3644 { return (this == &value) || ((hash() == value.hash()) && operator==(value.c_str())); }
3645
3649 inline bool operator!=(const String& value) const
3650 { return (this != &value) && ((hash() != value.hash()) || operator!=(value.c_str())); }
3651
3655 bool operator&=(const char* value) const;
3656
3660 bool operator|=(const char* value) const;
3661
3665 inline String& operator<<(const char* value)
3666 { return operator+=(value); }
3667
3671 inline String& operator<<(char value)
3672 { return operator+=(value); }
3673
3677 inline String& operator<<(int32_t value)
3678 { return operator+=(value); }
3679
3683 inline String& operator<<(uint32_t value)
3684 { return operator+=(value); }
3685
3689 inline String& operator<<(int64_t value)
3690 { return operator+=(value); }
3691
3695 inline String& operator<<(uint64_t value)
3696 { return operator+=(value); }
3697
3701 inline String& operator<<(bool value)
3702 { return operator+=(value); }
3703
3707 inline String& operator<<(double value)
3708 { return operator+=(value); }
3709
3714 String& operator>>(const char* skip);
3715
3719 String& operator>>(char& store);
3720
3725
3729 String& operator>>(int& store);
3730
3734 String& operator>>(unsigned int& store);
3735
3739 String& operator>>(bool& store);
3740
3747 String& append(const char* value, int len);
3748
3755 String& append(const char* value, const char* separator = 0, bool force = false);
3756
3763 String& append(const ObjList* list, const char* separator = 0, bool force = false);
3764
3771 inline String& append(const ObjList& list, const char* separator = 0, bool force = false)
3772 { return append(&list,separator,force); }
3773
3780 inline String& append(char value, unsigned int len = 1)
3781 { return insert(length(),value,len); }
3782
3788 String& append(double value, unsigned int decimals = 3);
3789
3797 String& insert(unsigned int pos, const char* value, int len = -1);
3798
3806 String& insert(unsigned int pos, char value, unsigned int len = 1);
3807
3813 String& printf(const char* format, ...) FORMAT_CHECK(2);
3814
3820 String& printf(unsigned int length, const char* format, ...) FORMAT_CHECK(3);
3821
3827 String& printfAppend(const char* format, ...) FORMAT_CHECK(2);
3828
3834 String& printfAppend(unsigned int length, const char* format, ...) FORMAT_CHECK(3);
3835
3844 String& appendFixed(unsigned int fixedLength, const char* str, unsigned int len = -1, char fill = ' ', int align = Left);
3845
3853 inline String& appendFixed(unsigned int fixedLength, const String& str, char fill = ' ', int align = Left)
3854 { return appendFixed(fixedLength,str.c_str(),str.length(),fill,align); }
3855
3862 int find(char what, unsigned int offs = 0) const;
3863
3870 int find(const char* what, unsigned int offs = 0) const;
3871
3877 int rfind(char what) const;
3878
3884 int rfind(const char* what) const;
3885
3893 bool startsWith(const char* what, bool wordBreak = false, bool caseInsensitive = false) const;
3894
3902 bool endsWith(const char* what, bool wordBreak = false, bool caseInsensitive = false) const;
3903
3915 bool startSkip(const char* what, bool wordBreak = true, bool caseInsensitive = false);
3916
3932 String& replaceChars(const char* what, const char* repl, bool inPlace = false,
3933 int wLen = -1, int rLen = -1, bool* chg = 0);
3934
3943 inline String& removeChars(const char* what, int wLen = -1, bool* chg = 0)
3944 { return replaceChars(what,0,false,wLen,-1,chg); }
3945
3952 String& extractTo(const char* sep, String& store);
3953
3960 String& extractTo(const char* sep, bool& store);
3961
3969 String& extractTo(const char* sep, int& store, int base = 0);
3970
3979 String& extractTo(const char* sep, int& store, const TokenDict* tokens, int base = 0);
3980
3987 String& extractTo(const char* sep, double& store);
3988
3994 virtual bool matches(const String& value) const
3995 { return operator==(value); }
3996
4002 bool matches(const Regexp& rexp);
4003
4009 int matchOffset(int index = 0) const;
4010
4016 int matchLength(int index = 0) const;
4017
4023 inline String matchString(int index = 0) const
4024 { return substr(matchOffset(index),matchLength(index)); }
4025
4031 String replaceMatches(const String& templ) const;
4032
4037 int matchCount() const;
4038
4046 ObjList* split(ObjList& list, char separator, bool emptyOK = true) const;
4047
4055 ObjList* split(ObjList& list, const Regexp& reg, bool emptyOK = true) const;
4056
4063 inline ObjList* split(char separator, bool emptyOK = true) const {
4064 ObjList* lst = new ObjList;
4065 split(*lst,separator,emptyOK);
4066 return lst;
4067 }
4068
4075 inline ObjList* split(const Regexp& reg, bool emptyOK = true) const {
4076 ObjList* lst = new ObjList;
4077 split(*lst,reg,emptyOK);
4078 return lst;
4079 }
4080
4087 static String msgEscape(const char* str, char extraEsc = 0);
4088
4094 inline String msgEscape(char extraEsc = 0) const
4095 { return msgEscape(c_str(),extraEsc); }
4096
4104 static String msgUnescape(const char* str, int* errptr = 0, char extraEsc = 0);
4105
4112 inline String msgUnescape(int* errptr = 0, char extraEsc = 0) const
4113 { return msgUnescape(c_str(),errptr,extraEsc); }
4114
4121 static String sqlEscape(const char* str, char extraEsc = 0);
4122
4128 inline String sqlEscape(char extraEsc = 0) const
4129 { return sqlEscape(c_str(),extraEsc); }
4130
4139 static String& uriEscapeTo(String& buf, const char* str, char extraEsc = 0,
4140 const char* noEsc = 0);
4141
4150 static String& uriEscapeTo(String& buf, const char* str, const char* extraEsc,
4151 const char* noEsc = 0);
4152
4160 inline String& uriEscapeTo(String& buf, char extraEsc = 0, const char* noEsc = 0) const
4161 { return uriEscapeTo(buf,c_str(),extraEsc,noEsc); }
4162
4170 static inline String uriEscape(const char* str, char extraEsc = 0, const char* noEsc = 0) {
4171 String tmp;
4172 return uriEscapeTo(tmp,str,extraEsc,noEsc);
4173 }
4174
4182 static inline String uriEscape(const char* str, const char* extraEsc, const char* noEsc = 0) {
4183 String tmp;
4184 return uriEscapeTo(tmp,str,extraEsc,noEsc);
4185 }
4186
4193 inline String uriEscape(char extraEsc = 0, const char* noEsc = 0) const
4194 { return uriEscape(c_str(),extraEsc,noEsc); }
4195
4205 static String& uriUnescapeTo(String& buf, const char* str, bool setPartial = false,
4206 int* errptr = 0);
4207
4215 inline String& uriUnescapeTo(String& buf, bool setPartial = false, int* errptr = 0) const
4216 { return uriUnescapeTo(buf,c_str(),setPartial,errptr); }
4217
4224 inline String& uriUnescapeStr(bool setPartial = false, int* errptr = 0)
4225 { return uriUnescapeTo(*this,c_str(),setPartial,errptr); }
4226
4234 static inline String uriUnescape(const char* str, int* errptr = 0, bool setPartial = true) {
4235 String tmp;
4236 return uriUnescapeTo(tmp,str,setPartial,errptr);
4237 }
4238
4245 inline String uriUnescape(int* errptr = 0, bool setPartial = true) const
4246 { return uriUnescape(c_str(),errptr,setPartial); }
4247
4254 static const String* atom(const String*& str, const char* val);
4255
4265 static unsigned int c_starts_with(const char* str, const char* what, int lenStr = -1,
4266 int lenWhat = -1, bool caseInsensitive = false);
4267
4277 static unsigned int c_ends_with(const char* str, const char* what, int lenStr = -1,
4278 int lenWhat = -1, bool caseInsensitive = false);
4279
4289 static inline unsigned int c_skip(const char*& str, const char* what, int lenStr = -1,
4290 int lenWhat = -1, bool caseInsensitive = false) {
4291 unsigned int n = c_starts_with(str,what,lenStr,lenWhat,caseInsensitive);
4292 str += n;
4293 return n;
4294 }
4295
4304 static unsigned int c_skip_chars(const char*& str, const char* what,
4305 int len = -1, bool skipFound = true);
4306
4325 static char* c_replace_chars(const char* str, const char* what, const char* repl = 0,
4326 bool inPlace = false, int wLen = -1, int rLen = -1, bool* chg = 0);
4327
4328protected:
4332 virtual void changed();
4333
4334private:
4335 String& changeStringData(char* data, unsigned int len);
4336 void clearMatches();
4337 char* m_string;
4338 unsigned int m_length;
4339 // I hope every C++ compiler now knows about mutable...
4340 mutable unsigned int m_hash;
4341 StringMatchPrivate* m_matches;
4342};
4343
4349class YATE_API AutoGenObject : public String
4350{
4351 YCLASS_DATA(m_pointer,AutoGenObject,String)
4352 YNOCOPY(AutoGenObject); // no automatic copies please
4353public:
4360 inline AutoGenObject(GenObject* gen = 0, const char* name = 0, bool owned = true)
4361 : String(name), m_pointer(gen), m_owned(owned)
4362 {}
4363
4368 { set(); }
4369
4374 inline GenObject* data() const
4375 { return m_pointer; }
4376
4381 inline GenObject* take() {
4382 GenObject* gen = m_pointer;
4383 m_pointer = 0;
4384 return gen;
4385 }
4386
4392 inline void set(GenObject* gen = 0, bool owned = true) {
4393 if (m_pointer == gen)
4394 return;
4395 GenObject* tmp = m_pointer;
4396 m_pointer = gen;
4397 if (m_owned)
4398 TelEngine::destruct(tmp);
4399 m_owned = owned;
4400 }
4401
4407 { set(gen); return *this; }
4408
4413 inline operator GenObject*() const
4414 { return m_pointer; }
4415
4419 inline GenObject* operator->() const
4420 { return m_pointer; }
4421
4425 inline GenObject& operator*() const
4426 { return *m_pointer; }
4427
4428private:
4429 GenObject* m_pointer;
4430 bool m_owned;
4431};
4432
4441template <class Obj> class GenericVector : public GenObject
4442{
4443public:
4449 inline GenericVector(unsigned int overAlloc = 0, const char* name = 0)
4450 : m_data(0), m_length(0), m_size(0), m_overAlloc(overAlloc), m_name(name)
4451 {}
4452
4460 inline GenericVector(const Obj* items, unsigned int count, unsigned int overAlloc = 0,
4461 const char* name = 0)
4462 : m_data(0), m_length(0), m_size(0), m_overAlloc(overAlloc), m_name(name)
4463 { assign(count,items); }
4464
4471 inline GenericVector(const ObjList& items, unsigned int overAlloc = 0,
4472 const char* name = 0)
4473 : m_data(0), m_length(0), m_size(0), m_overAlloc(overAlloc), m_name(name)
4474 { assign(items); }
4475
4480 inline GenericVector(const GenericVector& other)
4481 : m_data(0), m_length(0), m_size(0), m_overAlloc(other.overAlloc()),
4482 m_name(other.name())
4483 { assign(other.length(),other.data()); }
4484
4489 { clear(); }
4490
4495 inline unsigned int length() const
4496 { return m_length; }
4497
4502 inline unsigned int size() const
4503 { return m_size; }
4504
4509 inline unsigned int overAlloc() const
4510 { return m_overAlloc; }
4511
4516 inline void overAlloc(unsigned int count)
4517 { m_overAlloc = count; }
4518
4523 inline const String& name() const
4524 { return m_name; }
4525
4532 inline Obj* data(unsigned int offs = 0, unsigned int count = 0)
4533 { return dataAvail(offs,count); }
4534
4541 inline const Obj* data(unsigned int offs = 0, unsigned int count = 0) const
4542 { return dataAvail(offs,count); }
4543
4548 inline Obj* first()
4549 { return m_data; }
4550
4555 inline const Obj* first() const
4556 { return m_data; }
4557
4562 inline Obj* last()
4563 { return length() ? m_data + length() - 1 : 0; }
4564
4569 inline const Obj* last() const
4570 { return length() ? m_data + length() - 1 : 0; }
4571
4580 inline int indexOf(const String& name, unsigned int offs = 0, Obj** found = 0) const {
4581 const Obj* d = data(offs);
4582 for (; offs < length(); ++offs, ++d)
4583 if (name == d->toString()) {
4584 if (found)
4585 *found = (Obj*)d;
4586 return offs;
4587 }
4588 return -1;
4589 }
4590
4598 inline Obj* find(const String& name, unsigned int offs = 0) const {
4599 Obj* d = 0;
4600 indexOf(name,offs,&d);
4601 return d;
4602 }
4603
4612 inline int indexOfValue(const Obj& val, unsigned int offs = 0, Obj** found = 0) const {
4613 for (const Obj* d = data(offs); offs < length(); ++offs, ++d)
4614 if (val == *d) {
4615 if (found)
4616 *found = (Obj*)d;
4617 return offs;
4618 }
4619 return -1;
4620 }
4621
4629 inline Obj* findValue(const Obj& val, unsigned int offs = 0) const {
4630 Obj* d = 0;
4631 indexOfValue(val,offs,&d);
4632 return d;
4633 }
4634
4638 inline void clear() {
4639 if (!m_data)
4640 return;
4641 delete[] m_data;
4642 m_data = 0;
4643 m_length = m_size = 0;
4644 }
4645
4653 inline bool assign(unsigned int len, const Obj* items = 0, unsigned int count = 0) {
4654 if (!len)
4655 return true;
4656 unsigned int sz = len + m_overAlloc;
4657 Obj* tmp = new Obj[sz];
4658 if (!tmp) {
4659 Debug("YateVector",DebugFail,"Failed to allocate %u item(s) bytes=%u",
4660 sz,(unsigned int)(sz * sizeof(Obj)));
4661 return false;
4662 }
4663 if (items)
4664 copy(tmp,items,!count ? len : (count <= len ? count : len));
4665 if (m_data)
4666 delete[] m_data;
4667 m_data = tmp;
4668 m_length = len;
4669 m_size = sz;
4670 return true;
4671 }
4672
4682 inline bool resize(unsigned int len) {
4683 if (!len || len == length())
4684 return true;
4685 if (len > size())
4686 return assign(len,m_data,length());
4687 if (length() > len) {
4688 if ((size() - len) > m_overAlloc)
4689 return assign(len,m_data,length());
4690 fill(len,length() - len);
4691 }
4692 m_length = len;
4693 return true;
4694 }
4695
4701 inline bool removeLast(unsigned int count = 1) {
4702 if (!count)
4703 return true;
4704 if (count < length())
4705 return resize(length() - count);
4706 clear();
4707 return true;
4708 }
4709
4717 inline unsigned int fill(unsigned int offs = 0, int count = -1, const Obj* value = 0) {
4718 if (!count)
4719 return 0;
4720 unsigned int n = numItems(offs,count < 0 ? length() : (unsigned int)count);
4721 if (!n)
4722 return 0;
4723 if (value)
4724 fillArray(*value,m_data + offs,n);
4725 else {
4726 Obj item;
4727 fillArray(item,m_data + offs,n);
4728 }
4729 return n;
4730 }
4731
4739 inline unsigned int fillObj(const Obj& value, unsigned int offs = 0, int count = -1)
4740 { return fill(offs,count,&value); }
4741
4749 inline unsigned int fillObj(const Obj* items, unsigned int count, unsigned int offs = 0) {
4750 if (!(items && count))
4751 return 0;
4752 unsigned int n = numItems(offs,count);
4753 if (n)
4754 copy(m_data + offs,items,n);
4755 return n;
4756 }
4757
4763 inline Obj* append(const Obj& item) {
4764 if (!resize(length() + 1))
4765 return 0;
4766 m_data[length() - 1] = item;
4767 return (Obj*)&item;
4768 }
4769
4776 inline unsigned int append(const Obj* items, unsigned int count) {
4777 if (!(items && count && resize(length() + count)))
4778 return 0;
4779 copy(m_data + length() - count,items,count);
4780 return count;
4781 }
4782
4788 inline unsigned int append(const ObjList& list) {
4789 unsigned int n = list.count();
4790 if (!(n && resize(length() + n)))
4791 return 0;
4792 copy(m_data + length() - n,list);
4793 return n;
4794 }
4795
4801 inline unsigned int assign(const ObjList& list) {
4802 unsigned int n = list.count();
4803 if (!(n && resize(n)))
4804 return 0;
4805 copy(m_data,list);
4806 return n;
4807 }
4808
4814 inline Obj* set(const Obj& item) {
4815 int idx = indexOf(item);
4816 if (idx < 0)
4817 return append(item);
4818 m_data[idx] = item;
4819 return (Obj*)&item;
4820 }
4821
4826 inline GenericVector& operator=(const GenericVector& other) {
4827 assign(other.length(),other.data());
4828 return *this;
4829 }
4830
4835 inline GenericVector& operator=(const Obj& item) {
4836 assign(1,&item);
4837 return *this;
4838 }
4839
4844 inline GenericVector& operator+=(const Obj& item) {
4845 append(item);
4846 return *this;
4847 }
4848
4854 if (&other != this)
4855 append(other.data(),other.length());
4856 else {
4857 unsigned int n = length();
4858 resize(2 * n);
4859 fillObj(data(),n,n);
4860 }
4861 return *this;
4862 }
4863
4868 virtual const String& toString() const
4869 { return name(); }
4870
4871protected:
4872 // Retrive data available from offset
4873 inline Obj* dataAvail(unsigned int offs, unsigned int count) const {
4874 if (offs >= length() || !m_data)
4875 return 0;
4876 return (count <= (length() - offs)) ? (m_data + offs) : 0;
4877 }
4878 // Calculate the number of items available from offset
4879 inline unsigned int numItems(unsigned int offs, unsigned int count) const {
4880 if (offs >= length())
4881 return 0;
4882 offs = length() - offs;
4883 return (count <= offs) ? count : offs;
4884 }
4885 static inline void fillArray(const Obj& value, Obj* dest, unsigned int n)
4886 { while (n) { *dest++ = value; --n; } }
4887 static inline void copy(Obj* dest, const ObjList& src) {
4888 for (const ObjList* o = src.skipNull(); o; o = o->skipNext())
4889 *dest++ = *static_cast<Obj*>(o->get());
4890 }
4891 static inline void copy(Obj* dest, const Obj* src, unsigned int n)
4892 { while (n) { *dest++ = *src++; --n; } }
4893
4894 Obj* m_data;
4895 unsigned int m_length;
4896 unsigned int m_size;
4897 unsigned int m_overAlloc;
4898
4899private:
4900 String m_name;
4901};
4902
4908inline const char* c_str(const String* str)
4909 { return str ? str->c_str() : (const char*)0; }
4910
4916inline const char* c_safe(const char* str)
4917 { return str ? str : ""; }
4918
4924inline const char* c_safe(const String* str)
4925 { return str ? str->safe() : ""; }
4926
4932inline bool null(const char* str)
4933 { return !(str && *str); }
4934
4940inline bool null(const String* str)
4941 { return !str || str->null(); }
4942
4946YATE_API String operator+(const String& s1, const String& s2);
4947
4951YATE_API String operator+(const String& s1, const char* s2);
4952
4956YATE_API String operator+(const char* s1, const String& s2);
4957
4962inline const char *strcpy(String& dest, const char* src)
4963 { dest = src; return dest.c_str(); }
4964
4969inline const char *strcat(String& dest, const char* src)
4970 { dest += src; return dest.c_str(); }
4971
4980YATE_API int lookup(const char* str, const TokenDict* tokens, int defvalue = 0, int base = 0);
4981
4988YATE_API const char* lookup(int value, const TokenDict* tokens, const char* defvalue = 0);
4989
4998YATE_API int64_t lookup(const char* str, const TokenDict64* tokens, int64_t defvalue = 0, int base = 0);
4999
5006YATE_API const char* lookup(int64_t value, const TokenDict64* tokens, const char* defvalue = 0);
5007
5017
5022};
5023
5034
5038 int64_t value;
5039};
5040
5049YATE_API int lookup(const String& str, const TokenDictStr* tokens, int defvalue = 0, int base = 0);
5050
5057YATE_API const String& lookup(int value, const TokenDictStr* tokens, const String& defvalue = String::empty());
5058
5067YATE_API int64_t lookup(const String& str, const TokenDictStr64* tokens, int64_t defvalue = 0, int base = 0);
5068
5075YATE_API const String& lookup(int64_t value, const TokenDictStr64* tokens, const String& defvalue = String::empty());
5076
5077
5078class NamedList;
5079
5087YATE_API bool controlReturn(NamedList* params, bool ret, const char* retVal = 0);
5088
5093class YATE_API Regexp : public String
5094{
5095 YCLASS(Regexp,String)
5096 friend class String;
5097public:
5102
5109 explicit Regexp(const char* value, bool extended = false, bool insensitive = false);
5110
5115 Regexp(const Regexp& value);
5116
5120 virtual ~Regexp();
5121
5125 inline Regexp& operator=(const char* value)
5126 { String::operator=(value); return *this; }
5127
5132 inline bool compile() const
5133 { return m_regexp || (m_compile && doCompile()); }
5134
5140 bool matches(const char* value) const;
5141
5147 virtual bool matches(const String& value) const
5148 { return Regexp::matches(value.safe()); }
5149
5155 void setFlags(bool extended, bool insensitive);
5156
5161 bool isExtended() const;
5162
5167 bool isCaseInsensitive() const;
5168
5169protected:
5173 virtual void changed();
5174
5179 bool doCompile() const;
5180
5181private:
5182 void cleanup();
5183 bool matches(const char* value, StringMatchPrivate* matchlist) const;
5184 mutable void* m_regexp;
5185 mutable bool m_compile;
5186 int m_flags;
5187};
5188
5193class Atom
5194{
5195public:
5200 inline explicit Atom(const char* value)
5201 : m_atom(0)
5202 { String::atom(m_atom,value); }
5203
5208 inline operator const String&() const
5209 { return *m_atom; }
5210
5215 inline const String* operator->() const
5216 { return m_atom; }
5217
5218private:
5219 const String* m_atom;
5220};
5221
5226class YATE_API CapturedEvent : public String
5227{
5228 friend class Engine;
5229 YCLASS(CapturedEvent,String)
5230public:
5236 inline CapturedEvent(int level, const char* text)
5237 : String(text), m_level(level)
5238 { }
5239
5244 inline CapturedEvent(const CapturedEvent& original)
5245 : String(original), m_level(original.level())
5246 { }
5247
5252 inline int level() const
5253 { return m_level; }
5254
5255
5260 inline static bool capturing()
5261 { return s_capturing; }
5262
5267 inline static const ObjList& events()
5268 { return s_events; }
5269
5275 inline static void append(int level, const char* text)
5276 { if (text && *text) s_events.append(new CapturedEvent(level,text)); }
5277
5278protected:
5283 inline static ObjList& eventsRw()
5284 { return s_events; }
5285
5290 inline static void capturing(bool capture)
5291 { s_capturing = capture; }
5292
5293private:
5294 int m_level;
5295 static ObjList s_events;
5296 static bool s_capturing;
5297};
5298
5303class YATE_API NamedString : public String
5304{
5305 YNOCOPY(NamedString); // no automatic copies please
5306public:
5313 explicit NamedString(const char* name, const char* value = 0, int len = -1);
5314
5319 inline const String& name() const
5320 { return m_name; }
5321
5326 virtual const String& toString() const;
5327
5333 virtual void* getObject(const String& name) const;
5334
5338 inline NamedString& operator=(const char* value)
5339 { String::operator=(value); return *this; }
5340
5341private:
5342 NamedString(); // no default constructor please
5343 String m_name;
5344};
5345
5352class YATE_API NamedPointer : public NamedString
5353{
5354public:
5362 explicit NamedPointer(const char* name, GenObject* data = 0, const char* value = 0,
5363 int len = -1);
5364
5368 virtual ~NamedPointer();
5369
5374 inline GenObject* userData() const
5375 { return m_data; }
5376
5383
5389 void userData(GenObject* data);
5390
5396 inline void* userObject(const String& name) const
5397 { return m_data ? m_data->getObject(name) : 0; }
5398
5402 inline NamedPointer& operator=(const char* value)
5403 { NamedString::operator=(value); return *this; }
5404
5410 virtual void* getObject(const String& name) const;
5411
5412protected:
5416 virtual void changed();
5417
5418private:
5419 NamedPointer(); // no default constructor please
5420 GenObject* m_data;
5421};
5422
5427class YATE_API NamedCounter : public String
5428{
5429 YNOCOPY(NamedCounter); // no automatic copies please
5430public:
5435 explicit NamedCounter(const String& name)
5436 : String(name), m_enabled(GenObject::getObjCounting())
5437 {}
5438
5443 inline bool enabled() const
5444 { return m_enabled; }
5445
5450 inline void enable(bool val)
5451 { m_enabled = val; }
5452
5457 inline int inc()
5458 { return m_count.inc(); }
5459
5464 inline int dec()
5465 { return m_count.dec(); }
5466
5472 inline int add(int val)
5473 { return m_count.add(val); }
5474
5479 inline int count() const
5480 { return m_count; }
5481
5482private:
5483 AtomicInt m_count;
5484 bool m_enabled;
5485};
5486
5494class YATE_API HashList : public GenObject
5495{
5496 YNOCOPY(HashList); // no automatic copies please
5497public:
5502 explicit HashList(unsigned int size = 17);
5503
5507 virtual ~HashList();
5508
5514 virtual void* getObject(const String& name) const;
5515
5520 inline unsigned int length() const
5521 { return m_size; }
5522
5527 unsigned int count() const;
5528
5535 inline ObjList* getList(unsigned int index) const
5536 { return (index < m_size) ? m_lists[index] : 0; }
5537
5543 inline ObjList* getHashList(unsigned int hash) const
5544 { return getList(hash % m_size); }
5545
5551 inline ObjList* getHashList(const String& str) const
5552 { return getHashList(str.hash()); }
5553
5559 GenObject* operator[](const String& str) const;
5560
5567 ObjList* find(const GenObject* obj) const;
5568
5575 ObjList* find(const GenObject* obj, unsigned int hash) const;
5576
5582 ObjList* find(const String& str) const;
5583
5590
5597 ObjList* append(const GenObject* obj, unsigned int hash);
5598
5606 GenObject* remove(GenObject* obj, bool delobj = true, bool useHash = false);
5607
5614 inline GenObject* remove(const String& str, bool delobj = true)
5615 {
5616 ObjList* n = find(str);
5617 return n ? n->remove(delobj) : 0;
5618 }
5619
5627 inline GenObject* remove(GenObject* obj, unsigned int hash, bool delobj = true)
5628 {
5629 ObjList* n = find(obj,hash);
5630 return n ? n->remove(delobj) : 0;
5631 }
5632
5636 void clear();
5637
5644 bool resync(GenObject* obj);
5645
5651 bool resync();
5652
5653private:
5654 unsigned int m_size;
5655 ObjList** m_lists;
5656};
5657
5664class YATE_API ListIterator
5665{
5666 YNOCOPY(ListIterator); // no automatic copies please
5667public:
5674 ListIterator(ObjList& list, int offset = 0);
5675
5682 ListIterator(HashList& list, int offset = 0);
5683
5688
5693 inline unsigned int length() const
5694 { return m_length; }
5695
5699 void clear();
5700
5706 void assign(ObjList& list, int offset = 0);
5707
5713 void assign(HashList& list, int offset = 0);
5714
5721 GenObject* get(unsigned int index) const;
5722
5736
5741 inline bool eof() const
5742 { return m_current >= m_length; }
5743
5747 inline void reset()
5748 { m_current = 0; }
5749
5750private:
5751 ObjList* m_objList;
5752 HashList* m_hashList;
5753 GenObject** m_objects;
5754 unsigned int* m_hashes;
5755 unsigned int m_length;
5756 unsigned int m_current;
5757};
5758
5763class YATE_API Time
5764{
5765public:
5769 inline Time()
5770 : m_time(now())
5771 { }
5772
5777 inline Time(u_int64_t usec)
5778 : m_time(usec)
5779 { }
5780
5785 inline explicit Time(const struct timeval* tv)
5786 : m_time(fromTimeval(tv))
5787 { }
5788
5793 inline explicit Time(const struct timeval& tv)
5794 : m_time(fromTimeval(tv))
5795 { }
5796
5801 inline ~Time()
5802 { }
5803
5808 inline u_int32_t sec() const
5809 { return (u_int32_t)((m_time+500000) / 1000000); }
5810
5815 inline u_int64_t msec() const
5816 { return (m_time+500) / 1000; }
5817
5822 inline u_int64_t usec() const
5823 { return m_time; }
5824
5828 inline operator u_int64_t() const
5829 { return m_time; }
5830
5834 inline Time& operator=(u_int64_t usec)
5835 { m_time = usec; return *this; }
5836
5840 inline Time& operator+=(int64_t delta)
5841 { m_time += delta; return *this; }
5842
5846 inline Time& operator-=(int64_t delta)
5847 { m_time -= delta; return *this; }
5848
5853 inline void toTimeval(struct timeval* tv) const
5854 { toTimeval(tv, m_time); }
5855
5861 static void toTimeval(struct timeval* tv, u_int64_t usec);
5862
5868 static u_int64_t fromTimeval(const struct timeval* tv);
5869
5875 inline static u_int64_t fromTimeval(const struct timeval& tv)
5876 { return fromTimeval(&tv); }
5877
5882 static u_int64_t now();
5883
5888 static u_int64_t msecNow();
5889
5894 static u_int32_t secNow();
5895
5909 static unsigned int toEpoch(int year, unsigned int month, unsigned int day,
5910 unsigned int hour, unsigned int minute, unsigned int sec, int offset = 0);
5911
5924 static bool toDateTime(unsigned int epochTimeSec, int& year, unsigned int& month,
5925 unsigned int& day, unsigned int& hour, unsigned int& minute, unsigned int& sec,
5926 unsigned int* wDay = 0);
5927
5935 static uint32_t toNtp(uint32_t sec, uint32_t* over = 0, bool rfc2030 = true);
5936
5943 inline uint32_t toNtp(uint32_t* over = 0, bool rfc2030 = true)
5944 { return toNtp(sec(),over,rfc2030); }
5945
5954 static uint32_t fromNtp(uint32_t val, uint32_t* under = 0, bool rfc2030 = true);
5955
5967 static unsigned int toString(char* buf, uint64_t time, int frac = 0);
5968
5980 static inline unsigned int appendTo(String& buf, uint64_t time, int frac = 0) {
5981 char tmp[30];
5982 unsigned int n = toString(tmp,time,frac);
5983 if (n)
5984 buf.append(tmp,n);
5985 return n;
5986 }
5987
5997 static uint64_t toEpoch(const char* buf, unsigned int len, int frac = 0);
5998
6004 static inline bool isLeap(unsigned int year)
6005 { return (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)); }
6006
6012 static int timeZone(u_int32_t when = secNow());
6013
6014private:
6015 u_int64_t m_time;
6016};
6017
6022class YATE_API Random
6023{
6024public:
6029 inline Random(u_int32_t seed = Time::now() & 0xffffffff)
6030 : m_random(seed)
6031 { }
6032
6037 inline u_int32_t get() const
6038 { return m_random; }
6039
6044 inline void set(u_int32_t seed)
6045 { m_random = seed; }
6046
6051 u_int32_t next();
6052
6057 static long int random();
6058
6063 static void srandom(unsigned int seed);
6064
6065private:
6066 u_int32_t m_random;
6067};
6068
6073class YATE_API DataBlock : public GenObject
6074{
6075 YCLASS(DataBlock,GenObject)
6076public:
6081 DataBlock(unsigned int overAlloc = 0);
6082
6087 DataBlock(const DataBlock& value);
6088
6094 DataBlock(const DataBlock& value, unsigned int overAlloc);
6095
6103 DataBlock(void* value, unsigned int len, bool copyData = true, unsigned int overAlloc = 0);
6104
6108 virtual ~DataBlock();
6109
6113 static const DataBlock& empty();
6114
6119 inline void* data() const
6120 { return m_data; }
6121
6128 inline unsigned char* data(unsigned int offs, unsigned int len = 1) const
6129 { return (offs + len <= m_length) ? (static_cast<unsigned char*>(m_data) + offs) : 0; }
6130
6137 inline int at(unsigned int offs, int defvalue = -1) const
6138 { return (offs < m_length) ? static_cast<unsigned char*>(m_data)[offs] : defvalue; }
6139
6144 inline bool null() const
6145 { return !m_data; }
6146
6151 inline unsigned int length() const
6152 { return m_length; }
6153
6158 inline unsigned int size() const
6159 { return m_allocated; }
6160
6165 inline unsigned int overAlloc() const
6166 { return m_overAlloc; }
6167
6172 inline void overAlloc(unsigned int bytes)
6173 { m_overAlloc = bytes; }
6174
6179 void clear(bool deleteData = true);
6180
6188 DataBlock& assign(void* value, unsigned int len, bool copyData = true, unsigned int allocated = 0);
6189
6200 bool change(unsigned int pos, const void* buf, unsigned int bufLen,
6201 unsigned int extra = 0, int extraVal = 0, bool mayOverlap = true);
6202
6209 inline bool change8hton(unsigned int pos, uint64_t value) {
6210 if (!value)
6211 return change(pos,0,0,8);
6212 uint8_t buf[8];
6213 hton8(buf,value);
6214 return change(pos,buf,8,0,0,false);
6215 }
6216
6223 inline bool change4hton(unsigned int pos, uint32_t value) {
6224 if (!value)
6225 return change(pos,0,0,4);
6226 uint8_t buf[4];
6227 hton4(buf,value);
6228 return change(pos,buf,4,0,0,false);
6229 }
6230
6237 inline bool change3hton(unsigned int pos, uint32_t value) {
6238 if (!value)
6239 return change(pos,0,0,3);
6240 uint8_t buf[3];
6241 hton3(buf,value);
6242 return change(pos,buf,3,0,0,false);
6243 }
6244
6251 inline bool change2hton(unsigned int pos, uint16_t value) {
6252 uint8_t buf[2];
6253 hton2(buf,value);
6254 return change(pos,buf,2,0,0,false);
6255 }
6256
6264 inline bool changeHton(unsigned int pos, uint64_t value, uint8_t bytes) {
6265 if (!bytes)
6266 return true;
6267 if (bytes > 8)
6268 bytes = 8;
6269 if (!value)
6270 return change(pos,0,0,bytes);
6271 uint8_t buf[8];
6272 hton(buf,value,bytes);
6273 return change(pos,buf,bytes,0,0,false);
6274 }
6275
6283 inline bool changeLsb(unsigned int pos, uint64_t value, uint8_t bytes = 8) {
6284 if (!value)
6285 return bytes ? change(pos,0,0,bytes <= 8 ? bytes : 8) : true;
6286 uint8_t buf[8];
6287 if (bytes >= 8) {
6288 lsbSet(buf,value,8);
6289 return change(pos,buf,8,0,0,false);
6290 }
6291 else if (!bytes)
6292 return true;
6293 lsbSet(buf,value,bytes);
6294 return change(pos,buf,bytes,0,0,false);
6295 }
6296
6303 inline void append(const void* value, unsigned int len, bool mayOverlap = true) {
6304 if (value && len)
6305 change(length(),value,len,0,0,mayOverlap);
6306 }
6307
6313 inline void append(const DataBlock& value, bool mayOverlap = true) {
6314 if (value.length())
6315 change(length(),value.data(),value.length(),0,0,mayOverlap);
6316 }
6317
6322 inline void append(const String& value) {
6323 if (value.length())
6324 change(length(),value.c_str(),value.length(),0,0,false);
6325 }
6326
6332 inline void appendBytes(unsigned int count, uint8_t val = 0)
6333 { insertBytes(count,length(),val); }
6334
6339 inline void append8hton(uint64_t value)
6340 { change8hton(length(),value); }
6341
6346 inline void append4hton(uint32_t value)
6347 { change4hton(length(),value); }
6348
6353 inline void append3hton(uint32_t value)
6354 { change3hton(length(),value); }
6355
6360 inline void append2hton(uint16_t value)
6361 { change2hton(length(),value); }
6362
6368 inline void appendHton(uint64_t value, uint8_t bytes)
6369 { changeHton(length(),value,bytes); }
6370
6376 inline void append8lsb(uint64_t value, uint8_t bytes = 8)
6377 { changeLsb(length(),value,bytes); }
6378
6383 inline void append1(uint8_t value)
6384 { append((const void*)&value,1,false); }
6385
6393 inline void insert(const void* buf, unsigned int bufLen, unsigned int pos = 0,
6394 bool mayOverlap = true)
6395 { change(pos,buf,bufLen,0,0,mayOverlap); }
6396
6403 inline void insert(const DataBlock& value, unsigned int pos = 0, bool mayOverlap = true)
6404 { insert(value.data(),value.length(),pos,mayOverlap); }
6405
6412 inline void insertBytes(unsigned int count, unsigned int pos = 0, uint8_t val = 0) {
6413 if (count)
6414 change(pos,0,0,count,val,false);
6415 }
6416
6422 inline void insert8hton(uint64_t value, unsigned int pos = 0)
6423 { change8hton(pos,value); }
6424
6430 inline void insert4hton(uint32_t value, unsigned int pos = 0)
6431 { change4hton(pos,value); }
6432
6438 inline void insert3hton(uint32_t value, unsigned int pos = 0)
6439 { change3hton(pos,value); }
6440
6446 inline void insert2hton(uint16_t value, unsigned int pos = 0)
6447 { change2hton(pos,value); }
6448
6455 inline void insertHton(uint64_t value, uint8_t bytes = 8, unsigned int pos = 0)
6456 { changeHton(pos,value,bytes); }
6457
6464 inline void insertLsb(uint64_t value, uint8_t bytes = 8, unsigned int pos = 0)
6465 { changeLsb(pos,value,bytes); }
6466
6472 inline void insert1(uint8_t value, unsigned int pos = 0)
6473 { insert((const void*)&value,1,pos,false); }
6474
6483 void resize(unsigned int len, bool keepData = false, bool reAlloc = true);
6484
6491 inline void truncate(unsigned int len, bool reAlloc = true) {
6492 if (!len)
6493 clear();
6494 else if (len < length())
6495 cut(len,length() - len,reAlloc);
6496 }
6497
6505 void cut(unsigned int pos, unsigned int len, bool reAlloc = true);
6506
6511 inline void cut(int len) {
6512 if (len <= 0)
6513 cut(0,-len);
6514 else if ((unsigned int)len < length())
6515 cut(length() - len,len);
6516 else
6517 clear();
6518 }
6519
6525 inline int operator[](signed int index) const
6526 { return at(index); }
6527
6533 inline int operator[](unsigned int index) const
6534 { return at(index); }
6535
6539 inline DataBlock& operator=(const DataBlock& value)
6540 { assign(value.data(),value.length()); return *this; }
6541
6545 inline DataBlock& operator+=(const DataBlock& value)
6546 { append(value); return *this; }
6547
6551 inline DataBlock& operator+=(const String& value)
6552 { append(value); return *this; }
6553
6562 bool convert(const DataBlock& src, const String& sFormat,
6563 const String& dFormat, unsigned maxlen = 0);
6564
6580 bool changeHex(unsigned int pos, const char* data, unsigned int len, char sep = 0,
6581 bool guessSep = true, bool emptyOk = true, int* res = 0);
6582
6597 inline bool changeHex(unsigned int pos, const String& data, char sep = 0, bool guessSep = true,
6598 bool emptyOk = true, int* res = 0)
6599 { return changeHex(pos,data.c_str(),data.length(),sep,guessSep,emptyOk,res); }
6600
6614 inline bool appendHex(const String& data, char sep = 0, bool guessSep = true,
6615 bool emptyOk = true, int* res = 0)
6616 { return changeHex(length(),data,sep,guessSep,emptyOk,res); }
6617
6628 inline bool unHexify(const char* data, unsigned int len, char sep) {
6629 clear();
6630 return changeHex(length(),data,len,sep,false);
6631 }
6632
6642 inline bool unHexify(const char* data, unsigned int len) {
6643 clear();
6644 return changeHex(length(),data,len);
6645 }
6646
6653 inline bool unHexify(const String& data)
6654 { return unHexify(data.c_str(),data.length()); }
6655
6663 inline String& sqlEscape(String& str, char extraEsc = 0) const
6664 { return sqlEscape(str,data(),length(),extraEsc); }
6665
6671 inline String sqlEscape(char extraEsc) const {
6672 String tmp;
6673 return sqlEscape(tmp,extraEsc);
6674 }
6675
6685 static String& sqlEscape(String& str, const void* data, unsigned int len, char extraEsc = 0);
6686
6697 static void moveData(void* buf, unsigned int bufLen, unsigned int len,
6698 unsigned int dPos, unsigned int sPos, int fill = -1);
6699
6711 static void rebuildDataInsert(void* dest, unsigned int dLen, const void* src, unsigned int sLen,
6712 unsigned int pos, unsigned int space, int fill = -1);
6713
6725 static void rebuildDataRemove(void* dest, unsigned int dLen, const void* src, unsigned int sLen,
6726 unsigned int pos, unsigned int space, int fillAfter = -1);
6727
6734 static inline uint64_t ntoh8advance(const uint8_t*& buf) {
6735 uint64_t val = ((uint64_t)*buf++) << 56;
6736 val |= ((uint64_t)*buf++) << 48;
6737 val |= ((uint64_t)*buf++) << 40;
6738 val |= ((uint64_t)*buf++) << 32;
6739 val |= ((uint64_t)*buf++) << 24;
6740 val |= ((uint64_t)*buf++) << 16;
6741 val |= ((uint64_t)*buf++) << 8;
6742 val |= (uint64_t)*buf++;
6743 return val;
6744 }
6745
6753 static inline uint64_t ntoh8advance(const uint8_t*& buf, unsigned int& len) {
6754 len -= 8;
6755 return ntoh8advance(buf);
6756 }
6757
6763 static inline uint64_t ntoh8(const uint8_t* buf)
6764 { return ntoh8advance(buf); }
6765
6771 static inline void hton8advance(uint8_t*& buf, uint64_t val) {
6772 *buf++ = (uint8_t)(val >> 56);
6773 *buf++ = (uint8_t)(val >> 48);
6774 *buf++ = (uint8_t)(val >> 40);
6775 *buf++ = (uint8_t)(val >> 32);
6776 *buf++ = (uint8_t)(val >> 24);
6777 *buf++ = (uint8_t)(val >> 16);
6778 *buf++ = (uint8_t)(val >> 8);
6779 *buf++ = (uint8_t)val;
6780 }
6781
6789 static inline void hton8advance(uint8_t*& buf, uint64_t val, unsigned int& len) {
6790 len += 8;
6791 hton8advance(buf,val);
6792 }
6793
6799 static inline void hton8(uint8_t* buf, uint64_t val)
6800 { return hton8advance(buf,val); }
6801
6808 static inline uint32_t ntoh4advance(const uint8_t*& buf) {
6809 uint32_t val = (uint32_t)(*buf++) << 24;
6810 val |= (uint32_t)(*buf++) << 16;
6811 val |= (uint32_t)(*buf++) << 8;
6812 val |= (uint32_t)(*buf++);
6813 return val;
6814 }
6815
6823 static inline uint32_t ntoh4advance(const uint8_t*& buf, unsigned int& len) {
6824 len -= 4;
6825 return ntoh4advance(buf);
6826 }
6827
6833 static inline uint32_t ntoh4(const uint8_t* buf)
6834 { return ntoh4advance(buf); }
6835
6842 static inline void hton4advance(uint8_t*& buf, uint32_t val) {
6843 *buf++ = (uint8_t)(val >> 24);
6844 *buf++ = (uint8_t)(val >> 16);
6845 *buf++ = (uint8_t)(val >> 8);
6846 *buf++ = (uint8_t)val;
6847 }
6848
6856 static inline void hton4advance(uint8_t*& buf, uint32_t val, unsigned int& len) {
6857 len += 4;
6858 hton4advance(buf,val);
6859 }
6860
6866 static inline void hton4(uint8_t* buf, uint32_t val)
6867 { hton4advance(buf,val); }
6868
6875 static inline uint32_t ntoh3advance(const uint8_t*& buf) {
6876 uint32_t val = (uint32_t)(*buf++) << 16;
6877 val |= (uint32_t)(*buf++) << 8;
6878 val |= (uint32_t)(*buf++);
6879 return val;
6880 }
6881
6889 static inline uint32_t ntoh3advance(const uint8_t*& buf, unsigned int& len) {
6890 len -= 3;
6891 return ntoh3advance(buf);
6892 }
6893
6899 static inline uint32_t ntoh3(const uint8_t* buf)
6900 { return ntoh3advance(buf); }
6901
6908 static inline void hton3advance(uint8_t*& buf, uint32_t val) {
6909 *buf++ = (uint8_t)(val >> 16);
6910 *buf++ = (uint8_t)(val >> 8);
6911 *buf++ = (uint8_t)val;
6912 }
6913
6921 static inline void hton3advance(uint8_t*& buf, uint32_t val, unsigned int& len) {
6922 len += 3;
6923 hton3advance(buf,val);
6924 }
6925
6931 static inline void hton3(uint8_t* buf, uint32_t val)
6932 { hton3advance(buf,val); }
6933
6940 static inline uint16_t ntoh2advance(const uint8_t*& buf) {
6941 uint16_t val = (uint16_t)(*buf++) << 8;
6942 val |= (uint16_t)(*buf++);
6943 return val;
6944 }
6945
6953 static inline uint16_t ntoh2advance(const uint8_t*& buf, unsigned int& len) {
6954 len -= 2;
6955 return ntoh2advance(buf);
6956 }
6957
6963 static inline uint16_t ntoh2(const uint8_t* buf)
6964 { return ntoh2advance(buf); }
6965
6972 static inline void hton2advance(uint8_t*& buf, uint16_t val) {
6973 *buf++ = (uint8_t)(val >> 8);
6974 *buf++ = (uint8_t)val;
6975 }
6976
6984 static inline void hton2advance(uint8_t*& buf, uint16_t val, unsigned int& len) {
6985 len += 2;
6986 hton2advance(buf,val);
6987 }
6988
6994 static inline void hton2(uint8_t* buf, uint16_t val)
6995 { hton2advance(buf,val); }
6996
7004 static inline uint64_t ntohAdvance(const uint8_t*& buf, uint8_t bytes) {
7005 if (bytes > 7)
7006 return ntoh8advance(buf);
7007 uint64_t val = 0;
7008 for (int n = 8 * ((int)bytes - 1); n >= 0; n -= 8)
7009 val |= ((uint64_t)*buf++) << n;
7010 return val;
7011 }
7012
7021 static inline uint64_t ntohAdvance(const uint8_t*& buf, unsigned int& len, uint8_t bytes) {
7022 if (bytes > 8)
7023 bytes = 8;
7024 len -= bytes;
7025 return ntohAdvance(buf,bytes);
7026 }
7027
7034 static inline uint64_t ntoh(const uint8_t* buf, uint8_t bytes)
7035 { return ntohAdvance(buf,bytes); }
7036
7044 static inline void htonAdvance(uint8_t*& buf, uint64_t val, uint8_t bytes) {
7045 if (bytes > 7)
7046 return hton8advance(buf,val);
7047 for (int n = 8 * ((int)bytes - 1); n >= 0; n -= 8)
7048 *buf++ = (uint8_t)(val >> n);
7049 }
7050
7059 static inline void htonAdvance(uint8_t*& buf, uint64_t val, unsigned int& len, uint8_t bytes) {
7060 if (bytes > 8)
7061 bytes = 8;
7062 len += bytes;
7063 htonAdvance(buf,val,bytes);
7064 }
7065
7072 static inline void hton(uint8_t* buf, uint64_t val, uint8_t bytes)
7073 { return htonAdvance(buf,val,bytes); }
7074
7082 static inline uint64_t lsbAdvance(const uint8_t*& buf, uint8_t bytes) {
7083 if (bytes > 8)
7084 bytes = 8;
7085 uint64_t val = 0;
7086 for (uint8_t i = 0; i < bytes; ++i)
7087 val |= ((uint64_t)*buf++) << (i * 8);
7088 return val;
7089 }
7090
7099 static inline uint64_t lsbAdvance(const uint8_t*& buf, unsigned int& len, uint8_t bytes) {
7100 if (bytes > 8)
7101 bytes = 8;
7102 len -= bytes;
7103 return lsbAdvance(buf,bytes);
7104 }
7105
7112 static inline uint64_t lsb(const uint8_t* buf, uint8_t bytes)
7113 { return lsbAdvance(buf,bytes); }
7114
7122 static inline void lsbSetAdvance(uint8_t*& buf, uint64_t val, uint8_t bytes) {
7123 if (bytes > 8)
7124 bytes = 8;
7125 for (uint8_t i = 0; i < bytes; ++i)
7126 *buf++ = (uint8_t)(val >> (i * 8));
7127 }
7128
7137 static inline void lsbSetAdvance(uint8_t*& buf, uint64_t val, unsigned int& len, uint8_t bytes) {
7138 if (bytes > 8)
7139 bytes = 8;
7140 len += bytes;
7141 lsbSetAdvance(buf,val,bytes);
7142 }
7143
7150 static inline void lsbSet(uint8_t* buf, uint64_t val, uint8_t bytes)
7151 { return lsbSetAdvance(buf,val,bytes); }
7152
7153private:
7154 inline unsigned int allocLen(unsigned int len) const {
7155 // allocate a multiple of 8 bytes
7156 unsigned int over = (8 - (len & 7)) & 7;
7157 if (over < m_overAlloc)
7158 return (len + m_overAlloc + 7) & ~7;
7159 else
7160 return len + over;
7161 }
7162 void* m_data;
7163 unsigned int m_length;
7164 unsigned int m_allocated;
7165 unsigned int m_overAlloc;
7166};
7167
7172class YATE_API Hasher
7173{
7174public:
7178 virtual ~Hasher();
7179
7183 virtual void clear() = 0;
7184
7189 virtual void finalize() = 0;
7190
7196 virtual const unsigned char* rawDigest() = 0;
7197
7203 inline const String& hexDigest()
7204 { finalize(); return m_hex; }
7205
7212 inline bool update(const void* buf, unsigned int len)
7213 { return updateInternal(buf,len); }
7214
7220 inline bool update(const DataBlock& data)
7221 { return updateInternal(data.data(), data.length()); }
7222
7228 inline bool update(const String& str)
7229 { return updateInternal(str.c_str(), str.length()); }
7230
7235 inline Hasher& operator<<(const String& value)
7236 { update(value); return *this; }
7237
7242 inline Hasher& operator<<(const DataBlock& data)
7243 { update(data); return *this; }
7244
7249 Hasher& operator<<(const char* value);
7250
7258 bool hmacStart(DataBlock& opad, const void* key, unsigned int keyLen);
7259
7266 inline bool hmacStart(DataBlock& opad, const DataBlock& key)
7267 { return hmacStart(opad,key.data(),key.length()); }
7268
7275 inline bool hmacStart(DataBlock& opad, const String& key)
7276 { return hmacStart(opad,key.c_str(),key.length()); }
7277
7283 bool hmacFinal(const DataBlock& opad);
7284
7293 bool hmac(const void* key, unsigned int keyLen, const void* msg, unsigned int msgLen);
7294
7301 inline bool hmac(const DataBlock& key, const DataBlock& msg)
7302 { return hmac(key.data(),key.length(),msg.data(),msg.length()); }
7303
7310 inline bool hmac(const String& key, const String& msg)
7311 { return hmac(key.c_str(),key.length(),msg.c_str(),msg.length()); }
7312
7317 virtual unsigned int hashLength() const = 0;
7318
7323 virtual unsigned int hmacBlockSize() const;
7324
7325protected:
7329 inline Hasher()
7330 : m_private(0)
7331 { }
7332
7339 virtual bool updateInternal(const void* buf, unsigned int len) = 0;
7340
7341 void* m_private;
7342 String m_hex;
7343};
7344
7349class YATE_API MD5 : public Hasher
7350{
7351public:
7356
7361 MD5(const MD5& original);
7362
7368 MD5(const void* buf, unsigned int len);
7369
7374 MD5(const DataBlock& data);
7375
7380 MD5(const String& str);
7381
7385 MD5& operator=(const MD5& original);
7386
7390 virtual ~MD5();
7391
7395 virtual void clear();
7396
7401 virtual void finalize();
7402
7408 virtual const unsigned char* rawDigest();
7409
7414 inline static unsigned int rawLength()
7415 { return 16; }
7416
7421 virtual unsigned int hashLength() const
7422 { return 16; }
7423
7424protected:
7425 bool updateInternal(const void* buf, unsigned int len);
7426
7427private:
7428 void init();
7429 unsigned char m_bin[16];
7430};
7431
7436class YATE_API SHA1 : public Hasher
7437{
7438public:
7443
7448 SHA1(const SHA1& original);
7449
7455 SHA1(const void* buf, unsigned int len);
7456
7461 SHA1(const DataBlock& data);
7462
7467 SHA1(const String& str);
7468
7472 SHA1& operator=(const SHA1& original);
7473
7477 virtual ~SHA1();
7478
7482 virtual void clear();
7483
7488 virtual void finalize();
7489
7495 virtual const unsigned char* rawDigest();
7496
7501 inline static unsigned int rawLength()
7502 { return 20; }
7503
7508 virtual unsigned int hashLength() const
7509 { return 20; }
7510
7519 static bool fips186prf(DataBlock& out, const DataBlock& seed, unsigned int len);
7520
7521protected:
7522 bool updateInternal(const void* buf, unsigned int len);
7523
7524private:
7525 void init();
7526 unsigned char m_bin[20];
7527};
7528
7533class YATE_API SHA256 : public Hasher
7534{
7535public:
7540
7545 SHA256(const SHA256& original);
7546
7552 SHA256(const void* buf, unsigned int len);
7553
7558 SHA256(const DataBlock& data);
7559
7564 SHA256(const String& str);
7565
7569 SHA256& operator=(const SHA256& original);
7570
7574 virtual ~SHA256();
7575
7579 virtual void clear();
7580
7585 virtual void finalize();
7586
7592 virtual const unsigned char* rawDigest();
7593
7598 inline static unsigned int rawLength()
7599 { return 32; }
7600
7605 virtual unsigned int hashLength() const
7606 { return 32; }
7607
7608protected:
7609 bool updateInternal(const void* buf, unsigned int len);
7610
7611private:
7612 void init();
7613 unsigned char m_bin[32];
7614};
7615
7620class YATE_API Base64 : public DataBlock
7621{
7622 YNOCOPY(Base64); // no automatic copies please
7623public:
7627 inline Base64()
7628 { }
7629
7636 inline Base64(void* src, unsigned int len, bool copyData = true)
7637 : DataBlock(src,len,copyData)
7638 { }
7639
7649 void encode(String& dest, unsigned int lineLen = 0, bool lineAtEnd = false);
7650
7662 bool decode(DataBlock& dest, bool liberal = true);
7663
7667 inline Base64& operator<<(const String& value)
7668 { append(value); return *this; }
7669
7673 inline Base64& operator<<(const DataBlock& data)
7674 { append(data); return *this; }
7675
7679 inline Base64& operator<<(const char* value)
7680 { return operator<<(String(value)); }
7681};
7682
7683class NamedIterator;
7684
7689class YATE_API NamedList : public String
7690{
7691 friend class NamedIterator;
7692public:
7697 DumpAddSeparator = 0x0001, // Add separator before dumped list data
7698 DumpForcePrefix = 0x0001, // Force given prefix even if dumped data is empty
7699 DumpName = 0x0002, // Dump list name
7700 DumpQuoteName = 0x0004, // Quote list name
7701 DumpEmptyName = 0x0008, // Dump empty list name
7702 DumpQuoteParamName = 0x0010, // Quote parameter name
7703 DumpDontQuoteParamValue = 0x0020,// Do not quote parameter value
7704 };
7705
7710 explicit NamedList(const char* name);
7711
7716 NamedList(const NamedList& original);
7717
7724 NamedList(const char* name, const NamedList& original, const String& prefix);
7725
7732
7738 virtual void* getObject(const String& name) const;
7739
7744 inline unsigned int length() const
7745 { return m_params.length(); }
7746
7751 inline unsigned int count() const
7752 { return m_params.count(); }
7753
7757 inline void clearParams()
7758 { m_params.clear(); }
7759
7766
7774 NamedList& addParam(const char* name, const char* value, bool emptyOK = true);
7775
7782 inline NamedList& addParam(const char* name, int64_t value) {
7783 NamedString* ns = new NamedString(name);
7784 *static_cast<String*>(ns) = value;
7785 return addParam(ns);
7786 }
7787
7794 inline NamedList& addParam(const char* name, uint64_t value) {
7795 NamedString* ns = new NamedString(name);
7796 *static_cast<String*>(ns) = value;
7797 return addParam(ns);
7798 }
7799
7806 inline NamedList& addParam(const char* name, int32_t value) {
7807 NamedString* ns = new NamedString(name);
7808 *static_cast<String*>(ns) = value;
7809 return addParam(ns);
7810 }
7811
7818 inline NamedList& addParam(const char* name, uint32_t value) {
7819 NamedString* ns = new NamedString(name);
7820 *static_cast<String*>(ns) = value;
7821 return addParam(ns);
7822 }
7823
7830 inline NamedList& addParam(const char* name, double value) {
7831 NamedString* ns = new NamedString(name);
7832 *static_cast<String*>(ns) = value;
7833 return addParam(ns);
7834 }
7835
7842 inline NamedList& addParam(const char* name, bool value)
7843 { return addParam(name,String::boolText(value)); }
7844
7853 inline NamedList& addParam(const char* name, unsigned int flags, const TokenDict* tokens,
7854 bool unknownflag = true) {
7855 NamedString* ns = new NamedString(name);
7856 ns->decodeFlags(flags,tokens,unknownflag);
7857 return addParam(ns);
7858 }
7859
7868 inline NamedList& addParam(const char* name, uint64_t flags, const TokenDict64* tokens,
7869 bool unknownflag = true) {
7870 NamedString* ns = new NamedString(name);
7871 ns->decodeFlags(flags,tokens,unknownflag);
7872 return addParam(ns);
7873 }
7874
7883 inline NamedList& addParamHex(const char* name, const void* buf,
7884 unsigned int len, char sep = 0) {
7885 NamedString* ns = new NamedString(name);
7886 if (buf && len)
7887 ns->hexify((void*)buf,len,sep);
7888 return addParam(ns);
7889 }
7890
7897
7904 NamedList& setParam(const String& name, const char* value);
7905
7912 NamedList& setParam(const String& name, int64_t value);
7913
7920 NamedList& setParam(const String& name, uint64_t value);
7921
7928 NamedList& setParam(const String& name, int32_t value);
7929
7936 NamedList& setParam(const String& name, uint32_t value);
7937
7944 NamedList& setParam(const String& name, double value);
7945
7952 inline NamedList& setParam(const String& name, bool value)
7953 { return setParam(name,String::boolText(value)); }
7954
7963 NamedList& setParam(const String& name, unsigned int flags, const TokenDict* tokens,
7964 bool unknownflag = true);
7965
7974 NamedList& setParam(const String& name, uint64_t flags, const TokenDict64* tokens,
7975 bool unknownflag = true);
7976
7985 NamedList& setParamHex(const String& name, const void* buf, unsigned int len, char sep = 0);
7986
7994 NamedList& clearParam(const String& name, char childSep = 0, const String* value = 0);
7995
8002 NamedList& clearParam(NamedString* param, bool delParam = true);
8003
8011 NamedList& copyParam(const NamedList& original, const String& name, char childSep = 0);
8012
8020 NamedList& copyParams(bool replace, const NamedList& original, bool copyUserData = false);
8021
8027 inline NamedList& copyParams(const NamedList& original)
8028 { return copyParams(true,original); }
8029
8037 NamedList& copyParams(const NamedList& original, ObjList* list, char childSep = 0);
8038
8046 NamedList& copyParams(const NamedList& original, const String& list, char childSep = 0);
8047
8056 NamedList& copySubParams(const NamedList& original, const String& prefix,
8057 bool skipPrefix = true, bool replace = false);
8058
8064 bool hasSubParams(const char* prefix) const;
8065
8071 int getIndex(const NamedString* param) const;
8072
8078 int getIndex(const String& name) const;
8079
8085 NamedString* getParam(const String& name) const;
8086
8092 NamedString* getParam(unsigned int index) const;
8093
8099 const String& operator[](const String& name) const;
8100
8107 const char* getValue(const String& name, const char* defvalue = 0) const;
8108
8119 int getIntValue(const String& name, int defvalue = 0, int minvalue = INT_MIN,
8120 int maxvalue = INT_MAX, bool clamp = true) const;
8121
8129 int getIntValue(const String& name, const TokenDict* tokens, int defvalue = 0) const;
8130
8138 int getIntValue(const String& name, const TokenDictStr* tokens, int defvalue = 0) const;
8139
8140
8151 int64_t getInt64Value(const String& name, int64_t defvalue = 0, int64_t minvalue = LLONG_MIN,
8152 int64_t maxvalue = LLONG_MAX, bool clamp = true) const;
8153
8161 int64_t getInt64ValueDict(const String& name, const TokenDict64* tokens, int64_t defvalue = 0) const;
8162
8170 int64_t getInt64ValueDict(const String& name, const TokenDictStr64* tokens, int64_t defvalue = 0) const;
8171
8182 uint64_t getUInt64Value(const String& name, uint64_t defvalue = 0, uint64_t minvalue = 0,
8183 uint64_t maxvalue = ULLONG_MAX, bool clamp = true) const;
8184
8191 double getDoubleValue(const String& name, double defvalue = 0.0) const;
8192
8199 bool getBoolValue(const String& name, bool defvalue = false) const;
8200
8208 int replaceParams(String& str, bool sqlEsc = false, char extraEsc = 0) const;
8209
8218 void dump(String& str, const char* separator, char quote = 0, bool force = false) const;
8219
8230 bool dump(String& str, unsigned int flags, const char* separator,
8231 const char* nameSep = 0, const char* prefix = 0, char quote = 0) const;
8232
8237 static const NamedList& empty();
8238
8244 { return &m_params; }
8245
8250 inline const ObjList* paramList() const
8251 { return &m_params; }
8252
8253private:
8254 NamedList(); // no default constructor please
8255 ObjList m_params;
8256};
8257
8263class YATE_API NamedIterator
8264{
8265public:
8270 inline NamedIterator(const NamedList& list)
8271 : m_list(&list), m_item(list.m_params.skipNull())
8272 { }
8273
8278 inline NamedIterator(const NamedIterator& original)
8279 : m_list(original.m_list), m_item(original.m_item)
8280 { }
8281
8286 inline NamedIterator& operator=(const NamedList& list)
8287 { m_list = &list; m_item = list.m_params.skipNull(); return *this; }
8288
8293 inline NamedIterator& operator=(const NamedIterator& original)
8294 { m_list = original.m_list; m_item = original.m_item; return *this; }
8295
8301
8305 inline bool eof() const
8306 { return !m_item; }
8307
8311 inline void reset()
8312 { m_item = m_list->m_params.skipNull(); }
8313
8314private:
8315 NamedIterator(); // no default constructor please
8316 const NamedList* m_list;
8317 const ObjList* m_item;
8318};
8319
8325class YATE_API URI : public String
8326{
8327public:
8332
8337 URI(const URI& uri);
8338
8343 explicit URI(const String& uri);
8344
8349 explicit URI(const char* uri);
8350
8359 URI(const char* proto, const char* user, const char* host, int port = 0, const char* desc = 0);
8360
8364 void parse() const;
8365
8370 inline URI& operator=(const URI& value)
8371 { String::operator=(value); return *this; }
8372
8377 inline URI& operator=(const String& value)
8378 { String::operator=(value); return *this; }
8379
8384 inline URI& operator=(const char* value)
8385 { String::operator=(value); return *this; }
8386
8391 inline const String& getDescription() const
8392 { parse(); return m_desc; }
8393
8398 inline const String& getProtocol() const
8399 { parse(); return m_proto; }
8400
8405 inline const String& getUser() const
8406 { parse(); return m_user; }
8407
8412 inline const String& getHost() const
8413 { parse(); return m_host; }
8414
8419 inline int getPort() const
8420 { parse(); return m_port; }
8421
8426 inline const String& getExtra() const
8427 { parse(); return m_extra; }
8428
8433 static void setup(const NamedList& params);
8434
8435protected:
8441 virtual void changed();
8442
8446 virtual void clearData() const;
8447
8448 mutable bool m_parsed;
8449 mutable String m_desc;
8450 mutable String m_proto;
8451 mutable String m_user;
8452 mutable String m_host;
8453 mutable String m_extra;
8454 mutable int m_port;
8455};
8456
8457class MatchingItemBase;
8458class MatchingItemString;
8459class MatchingItemRegexp;
8460class MatchingItemRandom;
8461class MatchingItemList;
8462class MatchingItemCustom;
8463
8468class YATE_API MatchingParams : public String
8469{
8470 YCLASS(MatchingParams,String)
8471public:
8476 inline MatchingParams(const char* name = 0)
8477 : String(name), m_now(0)
8478 {}
8479
8480 uint64_t m_now; // Current time to be set when needed
8481 ObjList m_params; // Arbitray parameters. May be set during matching
8482};
8483
8488class YATE_API MatchingItemDump : public String
8489{
8490 YCLASS(MatchingItemDump,String)
8491public:
8496 NoInitialListDesc = 0x00000001, // Do not dump list description at depth 0
8497 DumpXmlStr = 0x00000002, // Used in dump(): dump string in xml format
8498 };
8499
8505 inline MatchingItemDump(const NamedList* params = 0, const char* name = 0)
8506 : String(name), m_flags(0), m_rexEnclose('/'), m_strEnclose('\''),
8507 m_nameValueSep(": "), m_negated('!'), m_caseInsentive('i'),
8508 m_regexpBasic(0), m_regexpExtended(0)
8509 {
8510 if (params)
8511 init(*params);
8512 }
8513
8518 virtual void init(const NamedList& params);
8519
8529 virtual String& dump(const MatchingItemBase* mi, String& buf,
8530 const String& indent = String::empty(), const String& origIndent = String::empty(),
8531 unsigned int depth = 0) const;
8532
8542 virtual String& dumpValue(const MatchingItemBase* mi, String& buf,
8543 const String& indent = String::empty(), const String& origIndent = String::empty(),
8544 unsigned int depth = 0) const;
8545
8552 virtual GenObject* dumpXml(const MatchingItemBase* mi, unsigned int depth = 0) const;
8553
8563 static inline String& dumpItem(const MatchingItemBase* mi, String& buf,
8564 const String& indent = String::empty(), const String& origIndent = String::empty(),
8565 const NamedList* params = 0) {
8566 MatchingItemDump tmp(params);
8567 return tmp.dump(mi,buf,indent,origIndent);
8568 }
8569
8576 static inline GenObject* dumpItemXml(const MatchingItemBase* mi, const NamedList* params = 0) {
8577 MatchingItemDump tmp(params);
8578 return tmp.dumpXml(mi);
8579 }
8580
8581 unsigned int m_flags; // Dump flags
8582 char m_rexEnclose; // Regexp enclose char
8583 char m_strEnclose; // String enclose char
8584 String m_nameValueSep; // Separator to be set between name and value
8585 char m_negated; // Negated match value
8586 char m_caseInsentive; // Case insensitive match value
8587 char m_regexpBasic; // Basic POSIX regexp value
8588 char m_regexpExtended; // Extended POSIX regexp value
8589};
8590
8595class YATE_API MatchingItemLoad : public String
8596{
8597 YCLASS(MatchingItemLoad,String)
8598public:
8603 RexBasic = 0x00000001, // Load basic POSIX regular expressions
8604 RexDetect = 0x00000002, // Detect regular expression if value starts with ^
8605 // Used when loading from parameters list
8606 RexDetectNegated = 0x00000004, // Detect negated regular expression if value ends with ^
8607 // Used when loading from parameters list
8608 RexValidate = 0x00000008, // Validate regular expressions
8609 NameReqSimple = 0x00000010, // Request name of the parameter to match
8610 // Used when loading from XML
8611 IgnoreFailed = 0x00000020, // Ignore failed to load items
8612 ListAny = 0x00000040, // Default 'any' (not match all) parameter value when loading a list
8613 // Used when loading from parameters list
8614 PrivateFlag = 0x100000000,// Private flag to be used for derived classes
8615 DefaultFlags = RexDetect | RexDetectNegated | NameReqSimple,
8616 };
8617
8622 ItemNegated = 0x00000001,// Matching is negated
8623 ItemCaseInsensitive = 0x00000002,// Matching is case insensitive
8624 ItemBasic = 0x00000004,// Matching regexp: use basic POSIX
8625 ItemAny = 0x00000008,// Matching list: match any
8626 ItemPrivateFlag = 0x00010000,// Private flag to be used for custom matching
8627 };
8628
8634 inline MatchingItemLoad(uint64_t flags = DefaultFlags, const char* name = 0)
8635 : String(name), m_flags(flags), m_ignore(0), m_allow(0), m_dbg(0)
8636 {}
8637
8647 virtual MatchingItemBase* load(const NamedList& params, String* error = 0,
8648 const char* prefix = 0, const char* suffix = 0) const;
8649
8656 virtual MatchingItemBase* loadXml(const String& str, String* error = 0) const;
8657
8664 virtual MatchingItemBase* loadXml(const GenObject* gen, String* error = 0) const;
8665
8670 static const TokenDict64* loadFlags();
8671
8676 static const TokenDict* itemFlags();
8677
8678 uint64_t m_flags; // Load flags
8679 ObjList* m_ignore; // Optional list of mathing names to ignore (blacklist)
8680 ObjList* m_allow; // Optional list of mathing names to allow (whitelist)
8681 DebugEnabler* m_dbg; // Optional pointer to DebugEnabler to be used to put errors
8682
8683private:
8684 inline bool flagSet(uint64_t mask) const
8685 { return 0 != (m_flags & mask); }
8686 inline int emptyNameAllow(String* error) const {
8687 if (!flagSet(NameReqSimple))
8688 return 0;
8689 if (flagSet(IgnoreFailed))
8690 return 1;
8691 if (error)
8692 error->printf("empty parameter match name");
8693 return -1;
8694 }
8695 inline bool ignore(const String& name) const
8696 { return (m_ignore && m_ignore->find(name)) || (m_allow && !m_allow->find(name)); }
8697};
8698
8703class YATE_API MatchingItemBase : public GenObject
8704{
8706 friend class MatchingItemList;
8707public:
8714 inline MatchingItemBase(const char* name, bool negated = false)
8715 : m_name(name), m_notNegated(!negated)
8716 {}
8717
8722 inline const String& name() const
8723 { return m_name; }
8724
8729 inline bool negated() const
8730 { return !m_notNegated; }
8731
8738 inline bool matchString(const String& str, MatchingParams* params = 0) const
8739 { return m_notNegated == runMatchString(str,params); }
8740
8747 inline bool matchListParam(const NamedList& list, MatchingParams* params = 0) const
8748 { return m_notNegated == runMatchListParam(list,params); }
8749
8756 virtual bool runMatchString(const String& str, MatchingParams* params = 0) const
8757 { return false; }
8758
8765 virtual bool runMatchListParam(const NamedList& list, MatchingParams* params = 0) const
8766 { return runMatchString(list[name()]); }
8767
8772 virtual MatchingItemBase* copy() const
8773 { return 0; }
8774
8779 virtual const MatchingItemString* itemString() const
8780 { return 0; }
8781
8786 virtual const MatchingItemRegexp* itemRegexp() const
8787 { return 0; }
8788
8793 virtual const MatchingItemRandom* itemRandom() const
8794 { return 0; }
8795
8800 virtual const MatchingItemList* itemList() const
8801 { return 0; }
8802
8807 virtual const MatchingItemCustom* itemCustom() const
8808 { return 0; }
8809
8819 virtual String& dump(String& buf, const MatchingItemDump* dump = 0,
8820 const String& indent = String::empty(), const String& origIndent = String::empty(),
8821 unsigned int depth = 0) const
8822 { return buf; }
8823
8833 virtual String& dumpValue(String& buf, const MatchingItemDump* dump = 0,
8834 const String& indent = String::empty(), const String& origIndent = String::empty(),
8835 unsigned int depth = 0) const
8836 { return buf; }
8837
8844 virtual GenObject* dumpXml(const MatchingItemDump* dump = 0, unsigned int depth = 0) const
8845 { return 0; }
8846
8851 virtual const String& toString() const
8852 { return name(); }
8853
8854private:
8855 String m_name; // Item name
8856 bool m_notNegated; // Item is not negated
8857};
8858
8864{
8866public:
8875 inline MatchingItemString(const char* name, const char* value, bool caseInsensitive = false,
8876 bool negated = false)
8877 : MatchingItemBase(name,negated), m_value(value), m_caseMatch(!caseInsensitive)
8878 {}
8879
8884 inline const String& value() const
8885 { return m_value; }
8886
8891 inline bool caseInsensitive() const
8892 { return !m_caseMatch; }
8893
8900 virtual bool runMatchString(const String& str, MatchingParams* params = 0) const
8901 { return m_caseMatch ? (str == m_value) : (str &= m_value); }
8902
8907 virtual MatchingItemBase* copy() const
8908 { return new MatchingItemString(name(),value(),caseInsensitive(),negated()); }
8909
8914 virtual const MatchingItemString* itemString() const
8915 { return this; }
8916
8917private:
8918 String m_value; // String to match
8919 bool m_caseMatch; // Non case insensitive match
8920};
8921
8927{
8929public:
8937 inline MatchingItemRegexp(const char* name, const char* value, bool negated = false)
8938 : MatchingItemBase(name,negated), m_value(value)
8939 {}
8940
8948 inline MatchingItemRegexp(const char* name, const Regexp& value, bool negated = false)
8949 : MatchingItemBase(name,negated), m_value(value)
8950 {}
8951
8956 inline const Regexp& value() const
8957 { return m_value; }
8958
8965 virtual bool runMatchString(const String& str, MatchingParams* params = 0) const
8966 { return m_value.matches(str); }
8967
8972 virtual MatchingItemBase* copy() const
8973 { return new MatchingItemRegexp(name(),value(),negated()); }
8974
8979 virtual const MatchingItemRegexp* itemRegexp() const
8980 { return this; }
8981
8994 static MatchingItemRegexp* build(const char* name, const String& str, int negated = 0,
8995 bool insensitive = false, bool extended = false, int fail = 1);
8996
8997private:
8998 Regexp m_value; // Regexp used for matching
8999};
9000
9010{
9012public:
9022 inline MatchingItemRandom(uint32_t val, uint32_t maxVal, bool negated = false,
9023 const char* name = 0)
9024 : MatchingItemBase(name,negated), m_value(val), m_maxVal(maxVal) {
9025 if (!m_value) // Never match
9026 m_maxVal = 100;
9027 else if (m_maxVal < 2) // Always match. Avoid division by 0
9028 m_value = m_maxVal = 100;
9029 }
9030
9035 inline uint32_t value() const
9036 { return m_value; }
9037
9042 inline uint32_t maxValue() const
9043 { return m_maxVal; }
9044
9049 inline bool randomMatch() const
9050 { return value() > (Random::random() % maxValue()); }
9051
9058 virtual bool runMatchString(const String& str, MatchingParams* params = 0) const
9059 { return randomMatch(); }
9060
9067 virtual bool runMatchListParam(const NamedList& list, MatchingParams* params = 0) const
9068 { return (!name() || list.getParam(name())) ? randomMatch() : false; }
9069
9074 virtual MatchingItemBase* copy() const
9075 { return new MatchingItemRandom(value(),maxValue(),negated(),name()); }
9076
9081 virtual const MatchingItemRandom* itemRandom() const
9082 { return this; }
9083
9084private:
9085 uint32_t m_value; // Reference value
9086 uint32_t m_maxVal; // Max value
9087};
9088
9093class YATE_API MatchingItemList : public MatchingItemBase
9094{
9096public:
9104 inline MatchingItemList(const char* name, bool matchAll = true, bool negated = false)
9105 : MatchingItemBase(name,negated), m_matchAll(matchAll)
9106 {}
9107
9112 inline bool matchAll() const
9113 { return m_matchAll; }
9114
9119 inline unsigned int length() const
9120 { return m_value.length(); }
9121
9126 inline unsigned int count() const
9127 { return m_value.count(); }
9128
9134 inline const MatchingItemBase* at(unsigned int index) const
9135 { return static_cast<MatchingItemBase*>(m_value.at(index)); }
9136
9142 inline int indexOf(const String& name) const
9143 { return m_value.index(name); }
9144
9150 inline const MatchingItemBase* find(const String& name) const {
9151 int idx = indexOf(name);
9152 return idx >= 0 ? at(idx) : 0;
9153 }
9154
9165 bool change(MatchingItemBase* item, int pos = -1, bool ins = false, unsigned int overAlloc = 1);
9166
9174 inline bool append(MatchingItemBase* item, unsigned int overAlloc = 1)
9175 { return change(item,-1,false,overAlloc); }
9176
9181 inline void append(ObjList& list) {
9182 ObjList* first = list.skipNull();
9183 if (!first)
9184 return;
9185 unsigned int count = first->count();
9186 append(static_cast<MatchingItemBase*>(first->remove(false)),count - 1);
9187 while (0 != (first = first->skipNull()))
9188 append(static_cast<MatchingItemBase*>(first->remove(false)),0);
9189 }
9190
9200 inline bool set(MatchingItemBase* item, unsigned int pos, unsigned int overAlloc = 1)
9201 { return change(item,pos,false,overAlloc); }
9202
9211 inline bool insert(MatchingItemBase* item, unsigned int pos = 0, unsigned int overAlloc = 1)
9212 { return change(item,pos,true,overAlloc); }
9213
9220 virtual bool runMatchString(const String& str, MatchingParams* params = 0) const;
9221
9228 virtual bool runMatchListParam(const NamedList& list, MatchingParams* params = 0) const;
9229
9234 virtual MatchingItemBase* copy() const;
9235
9240 virtual const MatchingItemList* itemList() const
9241 { return this; }
9242
9251
9252private:
9253 ObjVector m_value; // List of items to match
9254 bool m_matchAll; // Match all/any item(s)
9255};
9256
9262{
9264public:
9272 inline MatchingItemCustom(const char* name, const char* type, bool negated = false)
9273 : MatchingItemBase(name,negated), m_type(type)
9274 {}
9275
9280 inline const String& type() const
9281 { return m_type; }
9282
9287 virtual const MatchingItemCustom* itemCustom() const
9288 { return this; }
9289
9290private:
9291 String m_type;
9292};
9293
9298class YATE_API Lockable
9299{
9300public:
9304 virtual ~Lockable();
9305
9311 virtual bool lock(long maxwait = -1) = 0;
9312
9317 virtual bool unlock() = 0;
9318
9324 virtual bool locked() const = 0;
9325
9331 virtual bool check(long maxwait = -1);
9332
9339 virtual bool unlockAll();
9340
9346 { return 0; }
9347
9353 { return 0; }
9354
9360 { return 0; }
9361
9367 static void wait(unsigned long maxwait);
9368
9373 static unsigned long wait();
9374
9381 static void startUsingNow();
9382
9389 static void enableSafety(bool safe = true);
9390
9395 static bool safety();
9396};
9397
9402class YATE_API Mutex : public Lockable
9403{
9404 friend class MutexPrivate;
9405public:
9412 explicit Mutex(bool recursive = false, const char* name = 0);
9413
9418 Mutex(const Mutex& original);
9419
9424
9429 Mutex& operator=(const Mutex& original);
9430
9436 virtual bool lock(long maxwait = -1);
9437
9442 virtual bool unlock();
9443
9449 virtual bool locked() const;
9450
9455 const char* owner() const;
9456
9461 bool recursive() const;
9462
9468 { return this; }
9469
9474 static int count();
9475
9480 static int locks();
9481
9486 static bool efficientTimedLock();
9487
9488private:
9489 MutexPrivate* privDataCopy() const;
9490 MutexPrivate* m_private;
9491};
9492
9499class YATE_API MutexPool
9500{
9501public:
9512 MutexPool(unsigned int len = 13, bool recursive = false, const char* name = 0);
9513
9518
9526 inline unsigned int index(void* ptr) const
9527 { return ((unsigned int)(unsigned long)ptr) % m_length; }
9528
9536 inline Mutex* mutex(void* ptr) const
9537 { return m_data[index(ptr)]; }
9538
9544 inline Mutex* mutex(unsigned int idx) const
9545 { return m_data[idx % m_length]; }
9546
9547private:
9548 String* m_name; // Mutex names
9549 Mutex** m_data; // The array
9550 unsigned int m_length; // Array length
9551};
9552
9557class YATE_API Semaphore : public Lockable
9558{
9559 friend class SemaphorePrivate;
9560public:
9567 explicit Semaphore(unsigned int maxcount = 1, const char* name = 0,
9568 unsigned int initialCount = 1);
9569
9574 Semaphore(const Semaphore& original);
9575
9580
9585 Semaphore& operator=(const Semaphore& original);
9586
9592 virtual bool lock(long maxwait = -1);
9593
9598 virtual bool unlock();
9599
9605 virtual bool locked() const;
9606
9612 { return this; }
9613
9618 static int count();
9619
9624 static int locks();
9625
9630 static bool efficientTimedLock();
9631
9632private:
9633 SemaphorePrivate* privDataCopy() const;
9634 SemaphorePrivate* m_private;
9635};
9636
9643class YATE_API Lock2
9644{
9645 YNOCOPY(Lock2); // no automatic copies please
9646public:
9653 inline Lock2(Mutex* mx1, Mutex* mx2, long maxwait = -1)
9654 : m_mx1(0), m_mx2(0)
9655 { lock(mx1,mx2,maxwait); }
9656
9663 inline Lock2(Mutex& mx1, Mutex& mx2, long maxwait = -1)
9664 : m_mx1(0), m_mx2(0)
9665 { lock(&mx1,&mx2,maxwait); }
9666
9670 inline ~Lock2()
9671 { drop(); }
9672
9677 inline bool locked() const
9678 { return m_mx1 != 0; }
9679
9687 bool lock(Mutex* mx1, Mutex* mx2, long maxwait = -1);
9688
9696 inline bool lock(Mutex& mx1, Mutex& mx2, long maxwait = -1)
9697 { return lock(&mx1,&mx2,maxwait); }
9698
9702 void drop();
9703
9704private:
9705 Mutex* m_mx1;
9706 Mutex* m_mx2;
9707
9709 inline void* operator new(size_t);
9710
9712 inline void* operator new[](size_t);
9713};
9714
9719class YATE_API RWLock : public Lockable
9720{
9721 friend class RWLockPrivate;
9722public:
9727 RWLock(const char* name = 0);
9728
9733 RWLock(const RWLock& original);
9734
9739
9744 virtual bool unlock();
9745
9751 bool readLock(long maxWait = -1);
9752
9758 bool writeLock(long maxWait = -1);
9759
9765 virtual bool lock(long maxWait = -1)
9766 { return writeLock(maxWait); }
9767
9773 virtual bool locked() const;
9774
9780 { return this; }
9781
9787 static void disableRWLock(bool disable);
9788
9789private:
9790 RWLockPrivate* privDataCopy() const;
9791 RWLockPrivate* m_private;
9792};
9793
9798class YATE_API RLock
9799{
9800public:
9806 inline RLock(RWLock& lck, long maxWait = -1)
9807 { m_lock = lck.readLock(maxWait) ? &lck : 0; }
9808
9814 inline RLock(RWLock* lck, long maxwait = -1)
9815 { m_lock = (lck && lck->readLock(maxwait)) ? lck : 0; }
9816
9821 { if (m_lock) m_lock->unlock(); }
9822
9827 inline RWLock* locked() const
9828 { return m_lock; }
9829
9833 inline void drop()
9834 { if (m_lock) m_lock->unlock(); m_lock = 0; }
9835
9842 inline bool acquire(RWLock* lck, long maxwait = -1)
9843 { return (lck && (lck == m_lock)) ||
9844 (drop(),(lck && (m_lock = lck->readLock(maxwait) ? lck : 0))); }
9845
9852 inline bool acquire(RWLock& lck, long maxwait = -1)
9853 { return acquire(&lck,maxwait); }
9854
9855private:
9856 RWLock* m_lock;
9857
9859 inline void* operator new(size_t);
9860
9862 inline void* operator new[](size_t);
9863};
9864
9869class YATE_API WLock
9870{
9871public:
9877 inline WLock(RWLock& lck, long maxWait = -1)
9878 { m_lock = lck.writeLock(maxWait) ? &lck : 0; }
9879
9885 inline WLock(RWLock* lck, long maxWait = -1)
9886 { m_lock = (lck && lck->writeLock(maxWait)) ? lck : 0; }
9887
9892 { if (m_lock) m_lock->unlock(); }
9893
9898 inline RWLock* locked() const
9899 { return m_lock; }
9900
9904 inline void drop()
9905 { if (m_lock) m_lock->unlock(); m_lock = 0; }
9906
9913 inline bool acquire(RWLock* lck, long maxWait = -1)
9914 { return (lck && (lck == m_lock)) ||
9915 (drop(),(lck && (m_lock = lck->writeLock(maxWait) ? lck : 0))); }
9916
9923 inline bool acquire(RWLock& lck, long maxWait = -1)
9924 { return acquire(&lck,maxWait); }
9925
9926private:
9927 RWLock* m_lock;
9928
9930 inline void* operator new(size_t);
9931
9933 inline void* operator new[](size_t);
9934};
9935
9942class YATE_API RWLockPool
9943{
9944public:
9953 RWLockPool(unsigned int len = 13, const char* name = 0);
9954
9959
9967 inline unsigned int index(void* ptr) const
9968 { return ((unsigned int)(unsigned long)ptr) % m_length; }
9969
9977 inline RWLock* lock(void* ptr) const
9978 { return m_data[index(ptr)]; }
9979
9985 inline RWLock* lock(unsigned int idx) const
9986 { return m_data[idx % m_length]; }
9987
9988private:
9989 String* m_name; // RWLock names
9990 RWLock** m_data; // The array
9991 unsigned int m_length; // Array length
9992};
9993
9999class YATE_API Lock
10000{
10001 YNOCOPY(Lock); // no automatic copies please
10002public:
10009 inline Lock(Lockable& lck, long maxwait = -1, bool readLock = false)
10010 : m_lock(0)
10011 { acquire(lck,maxwait,readLock); }
10012
10019 inline Lock(Lockable* lck, long maxwait = -1, bool readLock = false)
10020 : m_lock(0)
10021 { acquire(lck,maxwait,readLock); }
10022
10026 inline ~Lock()
10027 { drop(); }
10028
10033 inline Lockable* locked() const
10034 { return m_lock; }
10035
10039 inline void drop()
10040 { if (m_lock) m_lock->unlock(); m_lock = 0; }
10041
10049 inline bool acquire(Lockable* lck, long maxwait = -1, bool readLock = false) {
10050 if (lck != m_lock) {
10051 drop();
10052 if (lck) {
10053 RWLock* rd = readLock ? lck->lockableRWLock() : 0;
10054 m_lock = (rd ? rd->readLock(maxwait) : lck->lock(maxwait)) ? lck : 0;
10055 }
10056 }
10057 return 0 != locked();
10058 }
10059
10067 inline bool acquire(Lockable& lck, long maxwait = -1, bool readLock = false)
10068 { return acquire(&lck,maxwait,readLock); }
10069
10070private:
10071 Lockable* m_lock;
10072
10074 inline void* operator new(size_t);
10075
10077 inline void* operator new[](size_t);
10078};
10079
10088template <class Obj> Obj* ref(RefPointer<Obj>& dest, Obj* obj, Lockable& lock, long maxwait = -1)
10089{
10090 Lock lck(lock,maxwait,true);
10091 dest = obj;
10092 return dest;
10093}
10094
10104template <class Obj> Obj* find(RefPointer<Obj>& dest, const ObjList& list,
10105 const String& name, Lockable& lock, long maxwait = -1)
10106{
10107 Lock lck(lock,maxwait,true);
10108 dest = static_cast<Obj*>(list[name]);
10109 return dest;
10110}
10111
10121template <class Obj> Obj* find(RefPointer<Obj>& dest, const ObjList& list,
10122 const GenObject* gen, Lockable& lock, long maxwait = -1)
10123{
10124 Lock lck(lock,maxwait,true);
10125 dest = static_cast<Obj*>(list.findObj(gen));
10126 return dest;
10127}
10128
10139template <class Obj> Obj* findObj(RefPointer<Obj>& dest, const ObjList& list,
10140 const String& name, Lockable& lock, long maxwait = -1)
10141{
10142 Lock lck(lock,maxwait,true);
10143 dest = YOBJECT(Obj,list[name]);
10144 return dest;
10145}
10146
10157template <class Obj> Obj* findObj(RefPointer<Obj>& dest, const ObjList& list,
10158 const GenObject* gen, Lockable& lock, long maxwait = -1)
10159{
10160 Lock lck(lock,maxwait,true);
10161 dest = YOBJECT(Obj,list.findObj(gen));
10162 return dest;
10163}
10164
10170class YATE_API Runnable
10171{
10172public:
10177 virtual void run() = 0;
10178
10182 virtual ~Runnable();
10183};
10184
10191class YATE_API Thread : public Runnable
10192{
10193 friend class ThreadPrivate;
10194 friend class MutexPrivate;
10195 friend class SemaphorePrivate;
10196 friend class RWLockPrivate;
10197 YNOCOPY(Thread); // no automatic copies please
10198public:
10203 Lowest,
10204 Low,
10205 Normal,
10206 High,
10207 Highest
10208 };
10209
10213 virtual void cleanup();
10214
10219 bool startup();
10220
10225 bool error() const;
10226
10231 bool running() const;
10232
10239 int getAffinity(DataBlock& outCpuMask);
10240
10248 int setAffinity(const String& cpus);
10249
10256 int setAffinity(const DataBlock& mask);
10257
10262 inline int locks() const
10263 { return m_locks; }
10264
10269 inline bool locked() const
10270 { return m_locking || m_locks; }
10271
10276 const char* name() const;
10277
10282 static const char* currentName();
10283
10290 static int getCurrentAffinity(DataBlock& outCpuMask);
10291
10298 static int getCurrentAffinity(String& outCpus, bool hex = false);
10299
10307 static int setCurrentAffinity(const String& cpus);
10308
10315 static int setCurrentAffinity(const DataBlock& mask);
10316
10325 static bool parseCPUMask(const String& cpus, DataBlock& mask);
10326
10333 static void printCPUMask(const DataBlock& mask, String& str, bool hexa = true);
10334
10340 static void yield(bool exitCheck = false);
10341
10347 static void idle(bool exitCheck = false);
10348
10354 static void sleep(unsigned int sec, bool exitCheck = false);
10355
10361 static void msleep(unsigned long msec, bool exitCheck = false);
10362
10369 static void usleep(unsigned long usec, bool exitCheck = false);
10370
10375 static unsigned long idleUsec();
10376
10381 static unsigned long idleMsec();
10382
10387 static void idleMsec(unsigned long msec);
10388
10394 static Thread* current();
10395
10400 static int count();
10401
10407 static bool check(bool exitNow = true);
10408
10412 static void exit();
10413
10418 void cancel(bool hard = false);
10419
10424 inline bool isCurrent() const
10425 { return current() == this; }
10426
10432
10439
10445 static NamedCounter* getCurrentObjCounter(bool always = false);
10446
10453
10460 static Priority priority(const char* name, Priority defvalue = Normal);
10461
10467 static const char* priority(Priority prio);
10468
10473 static void killall();
10474
10479 static void preExec();
10480
10486 static int lastError();
10487
10494 static inline bool errorString(String& buffer)
10495 { return errorString(buffer,lastError()); }
10496
10507 static bool errorString(String& buffer, int code);
10508
10509protected:
10515 Thread(const char *name = 0, Priority prio = Normal);
10516
10522 Thread(const char *name, const char* prio);
10523
10527 virtual ~Thread();
10528
10529private:
10530 ThreadPrivate* m_private;
10531 int m_locks;
10532 bool m_locking;
10533};
10534
10539class YATE_API TempObjectCounter
10540{
10541 YNOCOPY(TempObjectCounter); // no automatic copies please
10542public:
10549 : m_saved(0), m_enabled(enable)
10550 { if (m_enabled) m_saved = Thread::setCurrentObjCounter(counter); }
10551
10557 inline TempObjectCounter(const GenObject* obj, bool enable = GenObject::getObjCounting())
10558 : m_saved(0), m_enabled(enable && obj)
10559 { if (m_enabled) m_saved = Thread::setCurrentObjCounter(obj->getObjCounter()); }
10560
10566 inline TempObjectCounter(const GenObject& obj, bool enable = GenObject::getObjCounting())
10567 : m_saved(0), m_enabled(enable)
10568 { if (m_enabled) m_saved = Thread::setCurrentObjCounter(obj.getObjCounter()); }
10569
10574 { if (m_enabled) Thread::setCurrentObjCounter(m_saved); }
10575
10576private:
10577 NamedCounter* m_saved;
10578 bool m_enabled;
10579};
10580
10581class Socket;
10582
10587class YATE_API SocketAddr : public GenObject
10588{
10589 YCLASS(SocketAddr,GenObject)
10590public:
10594 enum Family {
10595 Unknown = AF_UNSPEC,
10596 IPv4 = AF_INET,
10597 AfMax = AF_MAX,
10598 AfUnsupported = AfMax,
10599#ifdef AF_INET6
10600 IPv6 = AF_INET6,
10601#else
10602 IPv6 = AfUnsupported + 1,
10603#endif
10604#ifdef HAS_AF_UNIX
10605 Unix = AF_UNIX,
10606#else
10607 Unix = AfUnsupported + 2,
10608#endif
10609 };
10610
10614 inline SocketAddr()
10615 : m_address(0), m_length(0)
10616 { }
10617
10622 inline SocketAddr(const SocketAddr& value)
10623 : GenObject(),
10624 m_address(0), m_length(0)
10625 { assign(value.address(),value.length()); }
10626
10632 explicit SocketAddr(int family, const void* raw = 0);
10633
10639 SocketAddr(const struct sockaddr* addr, socklen_t len = 0);
10640
10644 virtual ~SocketAddr();
10645
10650 inline SocketAddr& operator=(const SocketAddr& value)
10651 { assign(value.address(),value.length()); return *this; }
10652
10658 bool operator==(const SocketAddr& other) const;
10659
10665 inline bool operator!=(const SocketAddr& other) const
10666 { return !operator==(other); }
10667
10671 void clear();
10672
10678 bool assign(int family);
10679
10685 void assign(const struct sockaddr* addr, socklen_t len = 0);
10686
10692 bool assign(const DataBlock& addr);
10693
10699 bool local(const SocketAddr& remote);
10700
10705 inline bool valid() const
10706 { return m_length && m_address; }
10707
10712 inline bool null() const
10713 { return !(m_length && m_address); }
10714
10719 inline int family() const
10720 { return m_address ? m_address->sa_family : 0; }
10721
10726 inline const char* familyName() const
10727 { return lookupFamily(family()); }
10728
10733 inline unsigned int scopeId() const
10734 { return scopeId(address()); }
10735
10741 inline bool scopeId(unsigned int val)
10742 { return scopeId(address(),val); }
10743
10748 inline const String& host() const
10749 { return m_host; }
10750
10756 inline const String& addr(bool full = false) const {
10757 const String& s = full ? m_addrFull : m_addr;
10758 if (!s)
10759 updateAddr(full);
10760 return s;
10761 }
10762
10767 inline const String& iface() const
10768 { return m_iface; }
10769
10776 inline bool iface(const char* name, bool uriUnescape = false) {
10777 m_iface = name;
10778 if (!m_iface || !uriUnescape)
10779 return true;
10780 int e = -1;
10781 m_iface.uriUnescapeStr(false,&e);
10782 return e < 0;
10783 }
10784
10791 virtual bool host(const String& name);
10792
10797 int port() const;
10798
10804 bool port(int newport);
10805
10810 inline struct sockaddr* address() const
10811 { return m_address; }
10812
10817 inline socklen_t length() const
10818 { return m_length; }
10819
10824 inline bool isNullAddr() const
10825 { return isNullAddr(m_host,family()); }
10826
10832 int copyAddr(DataBlock& addr) const;
10833
10839 static bool supports(int family);
10840
10846 static int family(const String& addr);
10847
10854 static bool stringify(String& buf, struct sockaddr* addr);
10855
10864 static inline int unStringify(uint8_t* buf, const String& host,
10865 int family = Unknown) {
10866 SocketAddr sa(family);
10867 return sa.host(host) ? copyAddr(buf,sa.address()) : Unknown;
10868 }
10869
10877 static int copyAddr(uint8_t* buf, struct sockaddr* addr);
10878
10884 static inline unsigned int scopeId(struct sockaddr* addr) {
10885#ifdef AF_INET6
10886 if (addr && addr->sa_family == AF_INET6)
10887 return ((struct sockaddr_in6*)addr)->sin6_scope_id;
10888#endif
10889 return 0;
10890 }
10891
10898 static inline bool scopeId(struct sockaddr* addr, unsigned int val) {
10899#ifdef AF_INET6
10900 if (addr && addr->sa_family == AF_INET6) {
10901 ((struct sockaddr_in6*)addr)->sin6_scope_id = val;
10902 return true;
10903 }
10904#endif
10905 return false;
10906 }
10907
10916 static String& appendAddr(String& buf, const String& addr, int family = Unknown,
10917 const String& iface = String::empty());
10918
10928 static inline String& appendTo(String& buf, const String& addr, int port,
10929 int family = Unknown, const String& iface = String::empty()) {
10930 appendAddr(buf,addr,family,iface) << ":" << port;
10931 return buf;
10932 }
10933
10942 static inline String appendTo(const String& addr, int port, int family = Unknown,
10943 const String& iface = String::empty()) {
10944 String buf;
10945 return appendTo(buf,addr,port,family,iface);
10946 }
10947
10954 static bool isNullAddr(const String& addr, int family = Unknown);
10955
10964 static void splitIface(const String& buf, String& addr, String* iface = 0);
10965
10977 static void split(const String& buf, String& addr, int& port, bool portPresent = false);
10978
10984 static inline const char* lookupFamily(int family)
10985 { return lookup(family,s_familyName); }
10986
10991 static const String& ipv4NullAddr();
10992
10997 static const String& ipv6NullAddr();
10998
11003 static const TokenDict* dictFamilyName();
11004
11009 static inline const char* ifaceNameExtraEscape()
11010 { return s_ifaceNameExtraEscape; }
11011
11018 static inline String& escapeIface(String& buf, const char* name)
11019 { return String::uriEscapeTo(buf,name,ifaceNameExtraEscape()); }
11020
11021protected:
11025 virtual void stringify();
11026
11032 virtual void updateAddr(bool full = false) const;
11033
11034 struct sockaddr* m_address;
11035 socklen_t m_length;
11036 String m_host;
11037 String m_iface;
11038 mutable String m_addr;
11039 mutable String m_addrFull;
11040
11041private:
11042 static const TokenDict s_familyName[];
11043 static const char* s_ifaceNameExtraEscape;
11044};
11045
11050class YATE_API SocketFilter : public GenObject
11051{
11052 friend class Socket;
11053 YNOCOPY(SocketFilter); // no automatic copies please
11054public:
11059
11063 virtual ~SocketFilter();
11064
11070 virtual void* getObject(const String& name) const;
11071
11076 virtual void timerTick(const Time& when);
11077
11087 virtual bool received(const void* buffer, int length, int flags, const struct sockaddr* addr, socklen_t adrlen) = 0;
11088
11098 virtual bool sent(const void* buffer, int length, int flags, const struct sockaddr* addr, socklen_t adrlen)
11099 { return false; }
11100
11105 inline Socket* socket() const
11106 { return m_socket; }
11107
11112 bool valid() const;
11113
11114private:
11115 Socket* m_socket;
11116};
11117
11122class YATE_API Stream
11123{
11124public:
11128 enum SeekPos {
11129 SeekBegin, // Seek from start of stream
11130 SeekEnd, // Seek from stream end
11131 SeekCurrent // Seek from current position
11132 };
11133
11137 virtual ~Stream();
11138
11143 inline int error() const
11144 { return m_error; }
11145
11150 virtual bool terminate() = 0;
11151
11156 virtual bool canRetry() const;
11157
11162 virtual bool inProgress() const;
11163
11168 virtual bool valid() const = 0;
11169
11175 virtual bool setBlocking(bool block = true);
11176
11183 virtual int writeData(const void* buffer, int length) = 0;
11184
11190 int writeData(const char* str);
11191
11197 inline int writeData(const String& str)
11198 { return writeData(str.c_str(), str.length()); }
11199
11205 inline int writeData(const DataBlock& buf)
11206 { return writeData(buf.data(), buf.length()); }
11207
11214 virtual int readData(void* buffer, int length) = 0;
11215
11220 virtual int64_t length();
11221
11228 virtual int64_t seek(SeekPos pos, int64_t offset = 0);
11229
11235 inline int64_t seek(int64_t offset)
11236 { return seek(SeekBegin,offset); }
11237
11244 static bool allocPipe(Stream*& reader, Stream*& writer);
11245
11252 static bool allocPair(Stream*& str1, Stream*& str2);
11253
11258 static bool supportsPipes();
11259
11264 static bool supportsPairs();
11265
11266protected:
11270 inline Stream()
11271 : m_error(0)
11272 { }
11273
11277 inline void clearError()
11278 { m_error = 0; }
11279
11280 int m_error;
11281};
11282
11287class YATE_API MemoryStream : public Stream
11288{
11289 YNOCOPY(MemoryStream); // no automatic copies please
11290public:
11295 : m_offset(0)
11296 { }
11297
11302 inline MemoryStream(const DataBlock& data)
11303 : m_data(data), m_offset(0)
11304 { }
11305
11310 inline const DataBlock& data() const
11311 { return m_data; }
11312
11317 virtual bool terminate()
11318 { return true; }
11323 virtual bool valid() const
11324 { return true; }
11325
11332 virtual int writeData(const void* buffer, int len);
11333
11340 virtual int readData(void* buffer, int len);
11341
11346 virtual int64_t length()
11347 { return m_data.length(); }
11348
11355 virtual int64_t seek(SeekPos pos, int64_t offset = 0);
11356
11357protected:
11362
11366 int64_t m_offset;
11367};
11368
11373class YATE_API File : public Stream
11374{
11375 YNOCOPY(File); // no automatic copies please
11376public:
11381
11386 explicit File(HANDLE handle);
11387
11391 virtual ~File();
11392
11405 virtual bool openPath(const char* name, bool canWrite = false, bool canRead = true,
11406 bool create = false, bool append = false, bool binary = false,
11407 bool pubReadable = false, bool pubWritable = false);
11408
11413 virtual bool terminate();
11414
11419 void attach(HANDLE handle);
11420
11425 HANDLE detach();
11426
11431 inline HANDLE handle() const
11432 { return m_handle; }
11433
11438 virtual bool canRetry() const;
11439
11444 virtual bool valid() const;
11445
11450 static HANDLE invalidHandle();
11451
11457 virtual bool setBlocking(bool block = true);
11458
11463 virtual int64_t length();
11464
11471 virtual int64_t seek(SeekPos pos, int64_t offset = 0);
11472
11479 virtual int writeData(const void* buffer, int length);
11480
11487 virtual int readData(void* buffer, int length);
11488
11494 bool getFileTime(unsigned int& secEpoch);
11495
11502 virtual bool md5(String& buffer);
11503
11511 static bool setFileTime(const char* name, unsigned int secEpoch, int* error = 0);
11512
11520 static bool getFileTime(const char* name, unsigned int& secEpoch, int* error = 0);
11521
11528 static bool exists(const char* name, int* error = 0);
11529
11537 static bool rename(const char* oldFile, const char* newFile, int* error = 0);
11538
11545 static bool remove(const char* name, int* error = 0);
11546
11554 static bool md5(const char* name, String& buffer, int* error = 0);
11555
11563 static bool mkDir(const char* path, int* error = 0, int mode = -1);
11564
11571 static bool rmDir(const char* path, int* error = 0);
11572
11584 static bool listDirectory(const char* path, ObjList* dirs, ObjList* files,
11585 int* error = 0);
11586
11593 static bool createPipe(File& reader, File& writer);
11594
11595protected:
11596
11601
11602 HANDLE m_handle;
11603};
11604
11609class YATE_API Socket : public Stream
11610{
11611 YNOCOPY(Socket); // no automatic copies please
11612public:
11616 enum TOS {
11617 Normal = 0,
11618 LowDelay = IPTOS_LOWDELAY,
11619 MaxThroughput = IPTOS_THROUGHPUT,
11620 MaxReliability = IPTOS_RELIABILITY,
11621 MinCost = IPTOS_MINCOST,
11622 };
11623
11627 enum DSCP {
11628 DefaultPHB = 0x00,
11629 // Class selectors
11630 CS0 = 0x00,
11631 CS1 = 0x20,
11632 CS2 = 0x40,
11633 CS3 = 0x60,
11634 CS4 = 0x80,
11635 CS5 = 0xa0,
11636 CS6 = 0xc0,
11637 CS7 = 0xe0,
11638 // Assured forwarding
11639 AF11 = 0x28,
11640 AF12 = 0x30,
11641 AF13 = 0x38,
11642 AF21 = 0x48,
11643 AF22 = 0x50,
11644 AF23 = 0x58,
11645 AF31 = 0x68,
11646 AF32 = 0x70,
11647 AF33 = 0x78,
11648 AF41 = 0x88,
11649 AF42 = 0x90,
11650 AF43 = 0x98,
11651 // Expedited forwarding
11652 ExpeditedFwd = 0xb8,
11653 VoiceAdmit = 0xb0,
11654 };
11655
11660 FProtoIpv6 = 0x0001, // IPv6 protocol (IPPROTO_IPV6) socket option
11661 FIpv6Only = 0x0002, // IPv6 only socket option
11662 FBindToIface = 0x0004, // Bind to specific interface for non IPv6
11663 FEfficientSelect = 0x0008, // Efficient select() is available
11664 FExclusiveAddrUse = 0x0010, // Exclusive access may be indicated in reuse
11665 FReusePort = 0x0020, // Port reuse (bind on same port)
11666 };
11667
11672
11677 explicit Socket(SOCKET handle);
11678
11685 Socket(int domain, int type, int protocol = 0);
11686
11690 virtual ~Socket();
11691
11699 virtual bool create(int domain, int type, int protocol = 0);
11700
11705 virtual bool terminate();
11706
11711 void attach(SOCKET handle);
11712
11717 SOCKET detach();
11718
11723 inline SOCKET handle() const
11724 { return m_handle; }
11725
11730 virtual bool canRetry() const;
11731
11736 virtual bool inProgress() const;
11737
11742 virtual bool valid() const;
11743
11748 static SOCKET invalidHandle();
11749
11754 static int socketError();
11755
11760 static const TokenDict* tosValues();
11761
11770 virtual bool setOption(int level, int name, const void* value = 0, socklen_t length = 0);
11771
11780 inline bool setIpv6OnlyOption(bool on) {
11781#if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY)
11782 int value = on ? 1 : 0;
11783 return setOption(IPPROTO_IPV6,IPV6_V6ONLY,&value,sizeof(value));
11784#else
11785 return false;
11786#endif
11787 }
11788
11797 virtual bool getOption(int level, int name, void* buffer, socklen_t* length);
11798
11803 virtual bool setParams(const NamedList& params)
11804 { return false; }
11805
11812 virtual bool getParams(const String& params, NamedList& result)
11813 { return false; }
11814
11820 virtual bool setTOS(int tos);
11821
11828 inline bool setTOS(const char* tos, int defTos = Normal)
11829 { return setTOS(lookup(tos,tosValues(),defTos)); }
11830
11835 virtual int getTOS();
11836
11842 virtual bool setBlocking(bool block = true);
11843
11855 virtual bool setReuse(bool reuse = true, bool exclusive = false, bool setPort = false);
11856
11863 virtual bool setLinger(int seconds = -1);
11864
11871 virtual bool bind(struct sockaddr* addr, socklen_t addrlen);
11872
11882 virtual bool bind(struct sockaddr* addr, socklen_t addrlen,
11883 const char* iface, int ifLen = -1);
11884
11891 inline bool bind(const SocketAddr& addr)
11892 { return bind(addr.address(),addr.length(),addr.iface(),addr.iface().length()); }
11893
11902 virtual bool bindIface(const char* iface, int ifLen = -1, int family = SocketAddr::Unknown);
11903
11909 virtual bool listen(unsigned int backlog = 0);
11910
11917 virtual Socket* accept(struct sockaddr* addr = 0, socklen_t* addrlen = 0);
11918
11924 virtual Socket* accept(SocketAddr& addr);
11925
11932 SOCKET acceptHandle(struct sockaddr* addr = 0, socklen_t* addrlen = 0);
11933
11942
11947 static bool efficientSelect();
11948
11954 static bool canSelect(SOCKET handle);
11955
11960 virtual bool canSelect() const;
11961
11968 virtual bool connect(struct sockaddr* addr, socklen_t addrlen);
11969
11975 inline bool connect(const SocketAddr& addr)
11976 { return connect(addr.address(), addr.length()); }
11977
11987 virtual bool connectAsync(struct sockaddr* addr, socklen_t addrlen, unsigned int toutUs,
11988 bool* timeout = 0);
11989
11998 inline bool connectAsync(const SocketAddr& addr, unsigned int toutUs,
11999 bool* timeout = 0)
12000 { return connectAsync(addr.address(),addr.length(),toutUs,timeout); }
12001
12008 virtual bool shutdown(bool stopReads, bool stopWrites);
12009
12016 virtual bool getSockName(struct sockaddr* addr, socklen_t* addrlen);
12017
12024
12031 virtual bool getPeerName(struct sockaddr* addr, socklen_t* addrlen);
12032
12039
12045 virtual bool getBoundIface(String& buf);
12046
12056 virtual int sendTo(const void* buffer, int length, const struct sockaddr* addr, socklen_t adrlen, int flags = 0);
12057
12066 inline int sendTo(const void* buffer, int length, const SocketAddr& addr, int flags = 0)
12067 { return sendTo(buffer, length, addr.address(), addr.length(), flags); }
12068
12076 virtual int send(const void* buffer, int length, int flags = 0);
12077
12084 virtual int writeData(const void* buffer, int length);
12085
12095 virtual int recvFrom(void* buffer, int length, struct sockaddr* addr = 0, socklen_t* adrlen = 0, int flags = 0);
12096
12105 int recvFrom(void* buffer, int length, SocketAddr& addr, int flags = 0);
12106
12114 virtual int recv(void* buffer, int length, int flags = 0);
12115
12122 virtual int readData(void* buffer, int length);
12123
12132 virtual bool select(bool* readok, bool* writeok, bool* except, struct timeval* timeout = 0);
12133
12142 bool select(bool* readok, bool* writeok, bool* except, int64_t timeout);
12143
12150
12156 void removeFilter(SocketFilter* filter, bool delobj = false);
12157
12162 void clearFilters(bool del = true);
12163
12170 virtual void timerTick(const Time& when);
12171
12179 static bool createPair(Socket& sock1, Socket& sock2, int domain = AF_UNIX);
12180
12185 static inline unsigned int features()
12186 { return s_features; }
12187
12188protected:
12189
12194
12201 bool checkError(int retcode, bool strict = false);
12202
12213 bool applyFilters(const void* buffer, int length, int flags, const struct sockaddr* addr = 0,
12214 socklen_t adrlen = 0, bool rx = true);
12215
12216 SOCKET m_handle;
12217 ObjList m_filters;
12218
12219private:
12220 static unsigned int s_features;
12221};
12222
12227class YATE_API SctpSocket : public Socket
12228{
12229 YNOCOPY(SctpSocket); // no automatic copies please
12230public:
12234 inline SctpSocket()
12235 { }
12236
12241 inline explicit SctpSocket(SOCKET fd)
12242 : Socket(fd)
12243 { }
12244
12248 virtual ~SctpSocket();
12249
12255 virtual bool bindx(ObjList& addresses) = 0;
12256
12262 virtual bool connectx(ObjList& addresses) = 0;
12263
12273 virtual int sendTo(void* buffer, int length, int stream, SocketAddr& addr, int flags) = 0;
12274
12280 virtual Socket* accept(SocketAddr& addr)
12281 { return 0; }
12282
12291 virtual int sendMsg(const void* buf, int length, int stream, int& flags) = 0;
12292
12302 virtual int recvMsg(void* buf, int length, SocketAddr& addr, int& stream, int& flags) = 0;
12303
12310 virtual bool setStreams(int inbound, int outbound) = 0;
12311
12317 virtual bool subscribeEvents() = 0;
12318
12325 virtual bool getStreams(int& inbound, int& outbound) = 0;
12326
12332 virtual bool setPayload(u_int32_t payload) = 0;
12333};
12334
12339class YATE_API SocketRef : public RefObject
12340{
12341public:
12346 inline SocketRef(Socket** socket)
12347 : m_socket(socket)
12348 { }
12349
12354 inline SocketRef(Socket*& socket)
12355 : m_socket(&socket)
12356 { }
12357
12363 virtual void* getObject(const String& name) const
12364 { return (name == YATOM("Socket*")) ? m_socket : RefObject::getObject(name); }
12365
12366private:
12367 SocketRef();
12368 void* m_socket;
12369};
12370
12375class YATE_API DnsRecord : public GenObject
12376{
12377 YCLASS(DnsRecord,GenObject)
12378 YNOCOPY(DnsRecord);
12379public:
12386 inline DnsRecord(int ttl, int order, int pref)
12387 : m_ttl(ttl), m_order(order), m_pref(pref)
12388 {}
12389
12393 inline DnsRecord()
12394 : m_order(0), m_pref(0)
12395 {}
12396
12401 inline int ttl() const
12402 { return m_ttl; }
12403
12408 inline int order() const
12409 { return m_order; }
12410
12415 inline int pref() const
12416 { return m_pref; }
12417
12423 virtual void dump(String& buf, const char* sep = " ");
12424
12432 static bool insert(ObjList& list, DnsRecord* rec, bool ascPref);
12433
12434protected:
12435 int m_ttl;
12436 int m_order;
12437 int m_pref;
12438};
12439
12444class YATE_API TxtRecord : public DnsRecord
12445{
12446 YCLASS(TxtRecord,DnsRecord)
12447 YNOCOPY(TxtRecord);
12448public:
12454 inline TxtRecord(int ttl, const char* text)
12455 : DnsRecord(ttl,-1,-1), m_text(text)
12456 {}
12457
12462 inline const String& text() const
12463 { return m_text; }
12464
12470 virtual void dump(String& buf, const char* sep = " ");
12471
12477 static void copy(ObjList& dest, const ObjList& src);
12478
12479protected:
12480 String m_text;
12481
12482private:
12483 TxtRecord() {} // No default contructor
12484};
12485
12490class YATE_API SrvRecord : public DnsRecord
12491{
12492 YCLASS(SrvRecord,DnsRecord)
12493 YNOCOPY(SrvRecord);
12494public:
12503 inline SrvRecord(int ttl, int prio, int weight, const char* addr, int port)
12504 : DnsRecord(ttl,prio,weight), m_address(addr), m_port(port)
12505 {}
12506
12511 inline const String& address() const
12512 { return m_address; }
12513
12518 inline int port() const
12519 { return m_port; }
12520
12526 virtual void dump(String& buf, const char* sep = " ");
12527
12533 static void copy(ObjList& dest, const ObjList& src);
12534
12535protected:
12536 String m_address;
12537 int m_port;
12538
12539private:
12540 SrvRecord() {} // No default contructor
12541};
12542
12547class YATE_API NaptrRecord : public DnsRecord
12548{
12549 YCLASS(NaptrRecord,DnsRecord)
12550 YNOCOPY(NaptrRecord);
12551public:
12562 NaptrRecord(int ttl, int ord, int pref, const char* flags, const char* serv,
12563 const char* regexp, const char* next);
12564
12571 bool replace(String& str) const;
12572
12578 virtual void dump(String& buf, const char* sep = " ");
12579
12584 inline const String& flags() const
12585 { return m_flags; }
12586
12591 inline const String& serv() const
12592 { return m_service; }
12593
12598 inline const Regexp& regexp() const
12599 { return m_regmatch; }
12600
12605 inline const String& repTemplate() const
12606 { return m_template; }
12607
12612 inline const String& nextName() const
12613 { return m_next; }
12614
12615protected:
12616 String m_flags;
12617 String m_service;
12618 Regexp m_regmatch;
12619 String m_template;
12620 String m_next;
12621
12622private:
12623 NaptrRecord() {} // No default contructor
12624};
12625
12630class YATE_API Resolver
12631{
12632public:
12636 enum Type {
12637 Unknown,
12638 Srv, // SRV (Service Location)
12639 Naptr, // NAPTR (Naming Authority Pointer)
12640 A4, // A (Address)
12641 A6, // AAAA (IPv6 Address)
12642 Txt, // TXT (Text)
12643 };
12644
12651 static bool available(Type type = Unknown);
12652
12659 static bool init(int timeout = -1, int retries = -1);
12660
12669 static int query(Type type, const char* dname, ObjList& result, String* error = 0);
12670
12678 static int srvQuery(const char* dname, ObjList& result, String* error = 0);
12679
12687 static int naptrQuery(const char* dname, ObjList& result, String* error = 0);
12688
12696 static int a4Query(const char* dname, ObjList& result, String* error = 0);
12697
12705 static int a6Query(const char* dname, ObjList& result, String* error = 0);
12706
12714 static int txtQuery(const char* dname, ObjList& result, String* error = 0);
12715
12719 static const TokenDict s_types[];
12720};
12721
12726class YATE_API Cipher : public GenObject
12727{
12728public:
12733 Bidir,
12734 Encrypt,
12735 Decrypt,
12736 };
12737
12742 inline static const TokenDict* directions()
12743 { return s_directions; }
12744
12751 inline static Direction direction(const char* name, Direction defdir = Bidir)
12752 { return (Direction)TelEngine::lookup(name,s_directions,defdir); }
12753
12757 virtual ~Cipher();
12758
12764 virtual void* getObject(const String& name) const;
12765
12771 virtual bool valid(Direction dir = Bidir) const;
12772
12777 virtual unsigned int blockSize() const = 0;
12778
12783 virtual unsigned int initVectorSize() const;
12784
12790 unsigned int bufferSize(unsigned int len) const;
12791
12797 bool bufferFull(unsigned int len) const;
12798
12806 virtual bool setKey(const void* key, unsigned int len, Direction dir = Bidir) = 0;
12807
12814 inline bool setKey(const DataBlock& key, Direction dir = Bidir)
12815 { return setKey(key.data(),key.length(),dir); }
12816
12824 virtual bool initVector(const void* vect, unsigned int len, Direction dir = Bidir);
12825
12832 inline bool initVector(const DataBlock& vect, Direction dir = Bidir)
12833 { return initVector(vect.data(),vect.length(),dir); }
12834
12842 virtual bool encrypt(void* outData, unsigned int len, const void* inpData = 0) = 0;
12843
12849 inline bool encrypt(DataBlock& data)
12850 { return encrypt(data.data(),data.length()); }
12851
12859 virtual bool decrypt(void* outData, unsigned int len, const void* inpData = 0) = 0;
12860
12866 inline bool decrypt(DataBlock& data)
12867 { return decrypt(data.data(),data.length()); }
12868
12869private:
12870 static const TokenDict s_directions[];
12871};
12872
12878class YATE_API Compressor : public String
12879{
12880 YCLASS(Compressor,String)
12881 YNOCOPY(Compressor); // no automatic copies please
12882public:
12888 inline Compressor(const char* format, const char* name = 0)
12889 : String(name), m_format(format)
12890 {}
12891
12895 virtual ~Compressor()
12896 {}
12897
12902 inline const String& format() const
12903 { return m_format; }
12904
12912 virtual bool init(bool comp = true, bool decomp = true,
12913 const NamedList& params = NamedList::empty())
12914 { return true; }
12915
12920 virtual void finalize(bool comp)
12921 {}
12922
12931 virtual int compress(const void* buf, unsigned int len, DataBlock& dest);
12932
12941 virtual int decompress(const void* buf, unsigned int len, DataBlock& dest);
12942
12953 virtual int writeComp(const void* buf, unsigned int len, bool flush) = 0;
12954
12963 inline int writeComp(const DataBlock& data, bool flush)
12964 { return writeComp(data.data(),data.length(),flush); }
12965
12974 inline int writeComp(const String& data, bool flush)
12975 { return writeComp(data.c_str(),data.length(),flush); }
12976
12983 virtual int readComp(DataBlock& buf, bool flush) = 0;
12984
12993 virtual int writeDecomp(const void* buf, unsigned int len, bool flush) = 0;
12994
13002 inline int writeDecomp(const DataBlock& data, bool flush)
13003 { return writeDecomp(data.data(),data.length(),flush); }
13004
13012 inline int writeDecomp(const String& data, bool flush)
13013 { return writeDecomp(data.c_str(),data.length(),flush); }
13014
13021 virtual int readDecomp(DataBlock& buf, bool flush) = 0;
13022
13023protected:
13024 String m_format;
13025};
13026
13032class YATE_API SysUsage
13033{
13034public:
13038 enum Type {
13039 WallTime,
13040 UserTime,
13041 KernelTime
13042 };
13043
13047 static void init();
13048
13053 static u_int64_t startTime();
13054
13060 static u_int64_t usecRunTime(Type type = WallTime);
13061
13067 static u_int64_t msecRunTime(Type type = WallTime);
13068
13074 static u_int32_t secRunTime(Type type = WallTime);
13075
13081 static double runTime(Type type = WallTime);
13082
13083};
13084
13089class YATE_API CaptureInfo
13090{
13091public:
13099 CaptureInfo(uint64_t ts = Time::now(), SocketAddr* srcAddr = 0,
13100 SocketAddr* dstAddr = 0, const NamedList& extra = NamedList::empty())
13101 : m_ts(ts), m_srcAddr(srcAddr), m_dstAddr(dstAddr), m_extraInfo(extra)
13102 { }
13103
13108 inline SocketAddr* srcAddr() const
13109 { return m_srcAddr; }
13110
13115 inline SocketAddr* dstAddr() const
13116 { return m_dstAddr; }
13117
13122 inline const NamedList& extraInfo() const
13123 { return m_extraInfo; }
13124
13129 inline uint64_t ts() const
13130 { return m_ts; }
13131
13136 inline uint16_t srcPort() const
13137 { return srcAddr() ? srcAddr()->port() : 0; }
13138
13143 inline uint16_t dstPort() const
13144 { return dstAddr() ? dstAddr()->port() : 0; }
13145
13146private:
13147 uint64_t m_ts;
13148 SocketAddr* m_srcAddr;
13149 SocketAddr* m_dstAddr;
13150 NamedList m_extraInfo;
13151};
13152
13157class YATE_API Capture : public RefObject
13158{
13159 YCLASS(Capture,RefObject);
13160
13161public:
13166 Capture(const char* name)
13167 : m_name(name)
13168 { }
13169
13175 virtual bool initialize(const NamedList& params) = 0;
13176
13184 virtual bool write(const uint8_t* data, unsigned int len, const CaptureInfo& info) = 0;
13185
13190 virtual bool valid() const = 0;
13191
13196 virtual const String& name() const
13197 { return m_name; }
13198
13199private:
13200 String m_name;
13201};
13202
13203}; // namespace TelEngine
13204
13205#endif /* __YATECLASS_H */
13206
13207/* vi: set ts=8 sw=4 sts=4 noet: */
A list based Array.
Definition yateclass.h:2770
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:2867
int getColumns() const
Definition yateclass.h:2857
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:2850
bool addColumn(ObjList *column=0, int index=-1)
GenObject * get(int column, int row) const
Atom string holder.
Definition yateclass.h:5194
const String * operator->() const
Definition yateclass.h:5215
Atom(const char *value)
Definition yateclass.h:5200
Base class for atomic operations.
Definition yateclass.h:1196
RWLock * lock() const
Definition yateclass.h:1207
RWLock * m_lock
Definition yateclass.h:1220
static bool efficient()
GenObject pointer holder.
Definition yateclass.h:4350
GenObject & operator*() const
Definition yateclass.h:4425
void set(GenObject *gen=0, bool owned=true)
Definition yateclass.h:4392
GenObject * operator->() const
Definition yateclass.h:4419
GenObject * take()
Definition yateclass.h:4381
AutoGenObject & operator=(GenObject *gen)
Definition yateclass.h:4406
~AutoGenObject()
Definition yateclass.h:4367
GenObject * data() const
Definition yateclass.h:4374
AutoGenObject(GenObject *gen=0, const char *name=0, bool owned=true)
Definition yateclass.h:4360
Base64 encoder/decoder class.
Definition yateclass.h:7621
Base64 & operator<<(const char *value)
Definition yateclass.h:7679
Base64(void *src, unsigned int len, bool copyData=true)
Definition yateclass.h:7636
bool decode(DataBlock &dest, bool liberal=true)
Base64()
Definition yateclass.h:7627
Base64 & operator<<(const DataBlock &data)
Definition yateclass.h:7673
void encode(String &dest, unsigned int lineLen=0, bool lineAtEnd=false)
Base64 & operator<<(const String &value)
Definition yateclass.h:7667
Data associated with a captured packet.
Definition yateclass.h:13090
CaptureInfo(uint64_t ts=Time::now(), SocketAddr *srcAddr=0, SocketAddr *dstAddr=0, const NamedList &extra=NamedList::empty())
Definition yateclass.h:13099
uint16_t srcPort() const
Definition yateclass.h:13136
const NamedList & extraInfo() const
Definition yateclass.h:13122
uint64_t ts() const
Definition yateclass.h:13129
uint16_t dstPort() const
Definition yateclass.h:13143
SocketAddr * dstAddr() const
Definition yateclass.h:13115
SocketAddr * srcAddr() const
Definition yateclass.h:13108
Packet capture class.
Definition yateclass.h:13158
Capture(const char *name)
Definition yateclass.h:13166
virtual bool initialize(const NamedList &params)=0
virtual bool write(const uint8_t *data, unsigned int len, const CaptureInfo &info)=0
virtual const String & name() const
Definition yateclass.h:13196
virtual bool valid() const =0
A captured event string with a debug level.
Definition yateclass.h:5227
int level() const
Definition yateclass.h:5252
static void append(int level, const char *text)
Definition yateclass.h:5275
CapturedEvent(const CapturedEvent &original)
Definition yateclass.h:5244
static ObjList & eventsRw()
Definition yateclass.h:5283
static bool capturing()
Definition yateclass.h:5260
static const ObjList & events()
Definition yateclass.h:5267
static void capturing(bool capture)
Definition yateclass.h:5290
CapturedEvent(int level, const char *text)
Definition yateclass.h:5236
An abstract cipher.
Definition yateclass.h:12727
bool initVector(const DataBlock &vect, Direction dir=Bidir)
Definition yateclass.h:12832
virtual void * getObject(const String &name) const
Direction
Definition yateclass.h:12732
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:12866
virtual bool setKey(const void *key, unsigned int len, Direction dir=Bidir)=0
bool encrypt(DataBlock &data)
Definition yateclass.h:12849
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:12751
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:12742
virtual unsigned int initVectorSize() const
bool setKey(const DataBlock &key, Direction dir=Bidir)
Definition yateclass.h:12814
An abstract data (de)compressor.
Definition yateclass.h:12879
virtual int compress(const void *buf, unsigned int len, DataBlock &dest)
Compressor(const char *format, const char *name=0)
Definition yateclass.h:12888
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:12912
virtual int readComp(DataBlock &buf, bool flush)=0
int writeComp(const DataBlock &data, bool flush)
Definition yateclass.h:12963
virtual ~Compressor()
Definition yateclass.h:12895
virtual void finalize(bool comp)
Definition yateclass.h:12920
virtual int writeComp(const void *buf, unsigned int len, bool flush)=0
int writeDecomp(const String &data, bool flush)
Definition yateclass.h:13012
int writeDecomp(const DataBlock &data, bool flush)
Definition yateclass.h:13002
virtual int readDecomp(DataBlock &buf, bool flush)=0
int writeComp(const String &data, bool flush)
Definition yateclass.h:12974
const String & format() const
Definition yateclass.h:12902
virtual int decompress(const void *buf, unsigned int len, DataBlock &dest)
A class that holds just a block of raw data.
Definition yateclass.h:6074
static const DataBlock & empty()
void append(const DataBlock &value, bool mayOverlap=true)
Definition yateclass.h:6313
void cut(int len)
Definition yateclass.h:6511
int at(unsigned int offs, int defvalue=-1) const
Definition yateclass.h:6137
static void hton8advance(uint8_t *&buf, uint64_t val, unsigned int &len)
Definition yateclass.h:6789
void overAlloc(unsigned int bytes)
Definition yateclass.h:6172
void append2hton(uint16_t value)
Definition yateclass.h:6360
static uint16_t ntoh2(const uint8_t *buf)
Definition yateclass.h:6963
DataBlock & operator+=(const DataBlock &value)
Definition yateclass.h:6545
static void rebuildDataInsert(void *dest, unsigned int dLen, const void *src, unsigned int sLen, unsigned int pos, unsigned int space, int fill=-1)
void append8hton(uint64_t value)
Definition yateclass.h:6339
DataBlock(const DataBlock &value, unsigned int overAlloc)
static void hton2advance(uint8_t *&buf, uint16_t val, unsigned int &len)
Definition yateclass.h:6984
bool changeLsb(unsigned int pos, uint64_t value, uint8_t bytes=8)
Definition yateclass.h:6283
virtual ~DataBlock()
void appendBytes(unsigned int count, uint8_t val=0)
Definition yateclass.h:6332
void append(const void *value, unsigned int len, bool mayOverlap=true)
Definition yateclass.h:6303
DataBlock & operator+=(const String &value)
Definition yateclass.h:6551
void insertLsb(uint64_t value, uint8_t bytes=8, unsigned int pos=0)
Definition yateclass.h:6464
static uint32_t ntoh3advance(const uint8_t *&buf, unsigned int &len)
Definition yateclass.h:6889
static uint64_t ntoh(const uint8_t *buf, uint8_t bytes)
Definition yateclass.h:7034
static void hton(uint8_t *buf, uint64_t val, uint8_t bytes)
Definition yateclass.h:7072
void append8lsb(uint64_t value, uint8_t bytes=8)
Definition yateclass.h:6376
static void hton4advance(uint8_t *&buf, uint32_t val)
Definition yateclass.h:6842
static void rebuildDataRemove(void *dest, unsigned int dLen, const void *src, unsigned int sLen, unsigned int pos, unsigned int space, int fillAfter=-1)
static void lsbSet(uint8_t *buf, uint64_t val, uint8_t bytes)
Definition yateclass.h:7150
void insert(const void *buf, unsigned int bufLen, unsigned int pos=0, bool mayOverlap=true)
Definition yateclass.h:6393
DataBlock(const DataBlock &value)
bool changeHex(unsigned int pos, const String &data, char sep=0, bool guessSep=true, bool emptyOk=true, int *res=0)
Definition yateclass.h:6597
void resize(unsigned int len, bool keepData=false, bool reAlloc=true)
bool convert(const DataBlock &src, const String &sFormat, const String &dFormat, unsigned maxlen=0)
void insert(const DataBlock &value, unsigned int pos=0, bool mayOverlap=true)
Definition yateclass.h:6403
void insert8hton(uint64_t value, unsigned int pos=0)
Definition yateclass.h:6422
void append3hton(uint32_t value)
Definition yateclass.h:6353
static void moveData(void *buf, unsigned int bufLen, unsigned int len, unsigned int dPos, unsigned int sPos, int fill=-1)
bool change3hton(unsigned int pos, uint32_t value)
Definition yateclass.h:6237
bool null() const
Definition yateclass.h:6144
void insert3hton(uint32_t value, unsigned int pos=0)
Definition yateclass.h:6438
void insertHton(uint64_t value, uint8_t bytes=8, unsigned int pos=0)
Definition yateclass.h:6455
unsigned char * data(unsigned int offs, unsigned int len=1) const
Definition yateclass.h:6128
bool appendHex(const String &data, char sep=0, bool guessSep=true, bool emptyOk=true, int *res=0)
Definition yateclass.h:6614
void insert4hton(uint32_t value, unsigned int pos=0)
Definition yateclass.h:6430
unsigned int size() const
Definition yateclass.h:6158
bool change2hton(unsigned int pos, uint16_t value)
Definition yateclass.h:6251
void insertBytes(unsigned int count, unsigned int pos=0, uint8_t val=0)
Definition yateclass.h:6412
static void hton3advance(uint8_t *&buf, uint32_t val, unsigned int &len)
Definition yateclass.h:6921
static uint64_t lsbAdvance(const uint8_t *&buf, unsigned int &len, uint8_t bytes)
Definition yateclass.h:7099
static void hton3(uint8_t *buf, uint32_t val)
Definition yateclass.h:6931
int operator[](unsigned int index) const
Definition yateclass.h:6533
void appendHton(uint64_t value, uint8_t bytes)
Definition yateclass.h:6368
static uint64_t ntohAdvance(const uint8_t *&buf, unsigned int &len, uint8_t bytes)
Definition yateclass.h:7021
static uint64_t ntoh8advance(const uint8_t *&buf)
Definition yateclass.h:6734
static void hton2advance(uint8_t *&buf, uint16_t val)
Definition yateclass.h:6972
void clear(bool deleteData=true)
bool unHexify(const String &data)
Definition yateclass.h:6653
static uint64_t lsb(const uint8_t *buf, uint8_t bytes)
Definition yateclass.h:7112
static String & sqlEscape(String &str, const void *data, unsigned int len, char extraEsc=0)
static void hton8(uint8_t *buf, uint64_t val)
Definition yateclass.h:6799
String sqlEscape(char extraEsc) const
Definition yateclass.h:6671
static uint32_t ntoh3(const uint8_t *buf)
Definition yateclass.h:6899
bool change4hton(unsigned int pos, uint32_t value)
Definition yateclass.h:6223
void append(const String &value)
Definition yateclass.h:6322
void insert1(uint8_t value, unsigned int pos=0)
Definition yateclass.h:6472
static uint32_t ntoh4advance(const uint8_t *&buf, unsigned int &len)
Definition yateclass.h:6823
static uint32_t ntoh3advance(const uint8_t *&buf)
Definition yateclass.h:6875
void append1(uint8_t value)
Definition yateclass.h:6383
static uint64_t lsbAdvance(const uint8_t *&buf, uint8_t bytes)
Definition yateclass.h:7082
static void htonAdvance(uint8_t *&buf, uint64_t val, uint8_t bytes)
Definition yateclass.h:7044
static uint64_t ntoh8advance(const uint8_t *&buf, unsigned int &len)
Definition yateclass.h:6753
void * data() const
Definition yateclass.h:6119
void insert2hton(uint16_t value, unsigned int pos=0)
Definition yateclass.h:6446
static void hton8advance(uint8_t *&buf, uint64_t val)
Definition yateclass.h:6771
bool changeHton(unsigned int pos, uint64_t value, uint8_t bytes)
Definition yateclass.h:6264
static uint32_t ntoh4(const uint8_t *buf)
Definition yateclass.h:6833
static uint16_t ntoh2advance(const uint8_t *&buf, unsigned int &len)
Definition yateclass.h:6953
DataBlock & operator=(const DataBlock &value)
Definition yateclass.h:6539
bool changeHex(unsigned int pos, const char *data, unsigned int len, char sep=0, bool guessSep=true, bool emptyOk=true, int *res=0)
static void lsbSetAdvance(uint8_t *&buf, uint64_t val, uint8_t bytes)
Definition yateclass.h:7122
static void htonAdvance(uint8_t *&buf, uint64_t val, unsigned int &len, uint8_t bytes)
Definition yateclass.h:7059
static void hton4advance(uint8_t *&buf, uint32_t val, unsigned int &len)
Definition yateclass.h:6856
int operator[](signed int index) const
Definition yateclass.h:6525
DataBlock(void *value, unsigned int len, bool copyData=true, unsigned int overAlloc=0)
static void hton2(uint8_t *buf, uint16_t val)
Definition yateclass.h:6994
bool unHexify(const char *data, unsigned int len, char sep)
Definition yateclass.h:6628
static uint32_t ntoh4advance(const uint8_t *&buf)
Definition yateclass.h:6808
void append4hton(uint32_t value)
Definition yateclass.h:6346
void cut(unsigned int pos, unsigned int len, bool reAlloc=true)
bool change8hton(unsigned int pos, uint64_t value)
Definition yateclass.h:6209
static void lsbSetAdvance(uint8_t *&buf, uint64_t val, unsigned int &len, uint8_t bytes)
Definition yateclass.h:7137
static uint64_t ntoh8(const uint8_t *buf)
Definition yateclass.h:6763
unsigned int overAlloc() const
Definition yateclass.h:6165
unsigned int length() const
Definition yateclass.h:6151
DataBlock & assign(void *value, unsigned int len, bool copyData=true, unsigned int allocated=0)
static void hton3advance(uint8_t *&buf, uint32_t val)
Definition yateclass.h:6908
String & sqlEscape(String &str, char extraEsc=0) const
Definition yateclass.h:6663
static uint64_t ntohAdvance(const uint8_t *&buf, uint8_t bytes)
Definition yateclass.h:7004
void truncate(unsigned int len, bool reAlloc=true)
Definition yateclass.h:6491
static uint16_t ntoh2advance(const uint8_t *&buf)
Definition yateclass.h:6940
bool unHexify(const char *data, unsigned int len)
Definition yateclass.h:6642
static void hton4(uint8_t *buf, uint32_t val)
Definition yateclass.h:6866
bool change(unsigned int pos, const void *buf, unsigned int bufLen, unsigned int extra=0, int extraVal=0, bool mayOverlap=true)
DataBlock(unsigned int overAlloc=0)
A holder for a debug level.
Definition yateclass.h:329
void debugChain(const DebugEnabler *chain=0)
Definition yateclass.h:396
void debugName(const char *name)
Definition yateclass.h:416
void debugEnabled(bool enable)
Definition yateclass.h:368
DebugEnabler(int level=TelEngine::debugLevel(), bool enabled=true)
Definition yateclass.h:336
void debugCopy(const DebugEnabler *original=0)
bool debugEnabled() const
Definition yateclass.h:361
void debugSet(const char *desc)
bool debugAt(int level) const
bool debugChained() const
Definition yateclass.h:389
int debugLevel() const
Definition yateclass.h:347
int debugLevel(int level)
const char * debugName() const
Definition yateclass.h:375
An object that logs messages on creation and destruction.
Definition yateclass.h:758
Formatting
Definition yateclass.h:763
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 void outputTimestamp(bool on)
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)
Debugger(DebugEnabler *enabler, int level, const char *name, const char *format=0,...)
static bool outputTimestamp()
static void setFormatting(Formatting format, uint32_t startTimeSec=0)
static void enableOutput(bool enable=true, bool colorize=false)
A DNS record.
Definition yateclass.h:12376
DnsRecord(int ttl, int order, int pref)
Definition yateclass.h:12386
virtual void dump(String &buf, const char *sep=" ")
DnsRecord()
Definition yateclass.h:12393
static bool insert(ObjList &list, DnsRecord *rec, bool ascPref)
int ttl() const
Definition yateclass.h:12401
int order() const
Definition yateclass.h:12408
int pref() const
Definition yateclass.h:12415
A stream file class.
Definition yateclass.h:11374
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:11431
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:1627
virtual void * getObject(const String &name) const
static void setObjCounting(bool enable)
Definition yateclass.h:1694
virtual ~GenObject()
Definition yateclass.h:1638
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:1687
virtual const String & traceId() const
static void * getObject(const String &name, const GenObject *obj)
Definition yateclass.h:1680
static NamedCounter * getObjCounter(const String &name, bool create=true)
NamedCounter * getObjCounter() const
Definition yateclass.h:1701
Templated pointer that can be inserted in a list.
Definition yateclass.h:1964
GenPointer< Obj > & operator=(const GenPointer< Obj > &value)
Definition yateclass.h:1998
Obj & operator*() const
Definition yateclass.h:2023
GenPointer()
Definition yateclass.h:1975
GenPointer(const GenPointer< Obj > &value)
Definition yateclass.h:1983
GenPointer(Obj *object)
Definition yateclass.h:1991
GenPointer< Obj > & operator=(Obj *object)
Definition yateclass.h:2004
Obj * operator->() const
Definition yateclass.h:2017
Template for generic object vector.
Definition yateclass.h:4442
unsigned int fillObj(const Obj *items, unsigned int count, unsigned int offs=0)
Definition yateclass.h:4749
Obj * find(const String &name, unsigned int offs=0) const
Definition yateclass.h:4598
Obj * last()
Definition yateclass.h:4562
GenericVector & operator+=(const GenericVector &other)
Definition yateclass.h:4853
Obj * findValue(const Obj &val, unsigned int offs=0) const
Definition yateclass.h:4629
bool assign(unsigned int len, const Obj *items=0, unsigned int count=0)
Definition yateclass.h:4653
void overAlloc(unsigned int count)
Definition yateclass.h:4516
Obj * append(const Obj &item)
Definition yateclass.h:4763
Obj * set(const Obj &item)
Definition yateclass.h:4814
unsigned int fill(unsigned int offs=0, int count=-1, const Obj *value=0)
Definition yateclass.h:4717
GenericVector(const ObjList &items, unsigned int overAlloc=0, const char *name=0)
Definition yateclass.h:4471
int indexOfValue(const Obj &val, unsigned int offs=0, Obj **found=0) const
Definition yateclass.h:4612
unsigned int append(const Obj *items, unsigned int count)
Definition yateclass.h:4776
Obj * first()
Definition yateclass.h:4548
int indexOf(const String &name, unsigned int offs=0, Obj **found=0) const
Definition yateclass.h:4580
bool removeLast(unsigned int count=1)
Definition yateclass.h:4701
unsigned int size() const
Definition yateclass.h:4502
unsigned int fillObj(const Obj &value, unsigned int offs=0, int count=-1)
Definition yateclass.h:4739
GenericVector(unsigned int overAlloc=0, const char *name=0)
Definition yateclass.h:4449
Obj * data(unsigned int offs=0, unsigned int count=0)
Definition yateclass.h:4532
virtual const String & toString() const
Definition yateclass.h:4868
GenericVector(const GenericVector &other)
Definition yateclass.h:4480
bool resize(unsigned int len)
Definition yateclass.h:4682
GenericVector & operator+=(const Obj &item)
Definition yateclass.h:4844
GenericVector & operator=(const GenericVector &other)
Definition yateclass.h:4826
virtual ~GenericVector()
Definition yateclass.h:4488
unsigned int append(const ObjList &list)
Definition yateclass.h:4788
const Obj * last() const
Definition yateclass.h:4569
const String & name() const
Definition yateclass.h:4523
GenericVector(const Obj *items, unsigned int count, unsigned int overAlloc=0, const char *name=0)
Definition yateclass.h:4460
void clear()
Definition yateclass.h:4638
unsigned int overAlloc() const
Definition yateclass.h:4509
unsigned int length() const
Definition yateclass.h:4495
const Obj * data(unsigned int offs=0, unsigned int count=0) const
Definition yateclass.h:4541
GenericVector & operator=(const Obj &item)
Definition yateclass.h:4835
const Obj * first() const
Definition yateclass.h:4555
unsigned int assign(const ObjList &list)
Definition yateclass.h:4801
A hashed object list class.
Definition yateclass.h:5495
ObjList * getHashList(const String &str) const
Definition yateclass.h:5551
virtual void * getObject(const String &name) const
GenObject * remove(GenObject *obj, unsigned int hash, bool delobj=true)
Definition yateclass.h:5627
ObjList * find(const GenObject *obj) const
ObjList * append(const GenObject *obj)
ObjList * getList(unsigned int index) const
Definition yateclass.h:5535
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:5614
ObjList * append(const GenObject *obj, unsigned int hash)
ObjList * getHashList(unsigned int hash) const
Definition yateclass.h:5543
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:5520
ObjList * find(const String &str) const
bool resync(GenObject *obj)
An abstract hashing class.
Definition yateclass.h:7173
bool update(const DataBlock &data)
Definition yateclass.h:7220
virtual unsigned int hmacBlockSize() const
bool hmacStart(DataBlock &opad, const String &key)
Definition yateclass.h:7275
bool update(const void *buf, unsigned int len)
Definition yateclass.h:7212
virtual void finalize()=0
virtual void clear()=0
Hasher()
Definition yateclass.h:7329
virtual unsigned int hashLength() const =0
virtual const unsigned char * rawDigest()=0
bool hmac(const DataBlock &key, const DataBlock &msg)
Definition yateclass.h:7301
virtual ~Hasher()
bool update(const String &str)
Definition yateclass.h:7228
bool hmacFinal(const DataBlock &opad)
const String & hexDigest()
Definition yateclass.h:7203
bool hmac(const String &key, const String &msg)
Definition yateclass.h:7310
bool hmacStart(DataBlock &opad, const void *key, unsigned int keyLen)
Hasher & operator<<(const DataBlock &data)
Definition yateclass.h:7242
Hasher & operator<<(const String &value)
Definition yateclass.h:7235
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:7266
Hasher & operator<<(const char *value)
Class used to iterate the items of a list.
Definition yateclass.h:5665
ListIterator(ObjList &list, int offset=0)
GenObject * get()
void assign(HashList &list, int offset=0)
void reset()
Definition yateclass.h:5747
unsigned int length() const
Definition yateclass.h:5693
void assign(ObjList &list, int offset=0)
ListIterator(HashList &list, int offset=0)
bool eof() const
Definition yateclass.h:5741
GenObject * get(unsigned int index) const
Ephemeral double mutex locking object.
Definition yateclass.h:9644
void drop()
bool lock(Mutex *mx1, Mutex *mx2, long maxwait=-1)
~Lock2()
Definition yateclass.h:9670
bool locked() const
Definition yateclass.h:9677
bool lock(Mutex &mx1, Mutex &mx2, long maxwait=-1)
Definition yateclass.h:9696
Lock2(Mutex &mx1, Mutex &mx2, long maxwait=-1)
Definition yateclass.h:9663
Lock2(Mutex *mx1, Mutex *mx2, long maxwait=-1)
Definition yateclass.h:9653
Ephemeral mutex, semaphore or rw-lock locking object.
Definition yateclass.h:10000
void drop()
Definition yateclass.h:10039
Lock(Lockable *lck, long maxwait=-1, bool readLock=false)
Definition yateclass.h:10019
bool acquire(Lockable *lck, long maxwait=-1, bool readLock=false)
Definition yateclass.h:10049
bool acquire(Lockable &lck, long maxwait=-1, bool readLock=false)
Definition yateclass.h:10067
~Lock()
Definition yateclass.h:10026
Lockable * locked() const
Definition yateclass.h:10033
Lock(Lockable &lck, long maxwait=-1, bool readLock=false)
Definition yateclass.h:10009
Abstract interface for lockable objects.
Definition yateclass.h:9299
virtual Mutex * lockableMutex()
Definition yateclass.h:9345
virtual bool locked() const =0
virtual RWLock * lockableRWLock()
Definition yateclass.h:9359
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 Semaphore * lockableSemaphore()
Definition yateclass.h:9352
virtual bool unlock()=0
virtual ~Lockable()
static void startUsingNow()
A standard MD5 digest calculator.
Definition yateclass.h:7350
MD5 & operator=(const MD5 &original)
static unsigned int rawLength()
Definition yateclass.h:7414
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:7421
Matching item common interface.
Definition yateclass.h:8704
virtual const MatchingItemRegexp * itemRegexp() const
Definition yateclass.h:8786
virtual bool runMatchString(const String &str, MatchingParams *params=0) const
Definition yateclass.h:8756
bool matchListParam(const NamedList &list, MatchingParams *params=0) const
Definition yateclass.h:8747
virtual GenObject * dumpXml(const MatchingItemDump *dump=0, unsigned int depth=0) const
Definition yateclass.h:8844
MatchingItemBase(const char *name, bool negated=false)
Definition yateclass.h:8714
virtual const MatchingItemList * itemList() const
Definition yateclass.h:8800
virtual const MatchingItemRandom * itemRandom() const
Definition yateclass.h:8793
bool negated() const
Definition yateclass.h:8729
bool matchString(const String &str, MatchingParams *params=0) const
Definition yateclass.h:8738
virtual String & dumpValue(String &buf, const MatchingItemDump *dump=0, const String &indent=String::empty(), const String &origIndent=String::empty(), unsigned int depth=0) const
Definition yateclass.h:8833
virtual const String & toString() const
Definition yateclass.h:8851
virtual bool runMatchListParam(const NamedList &list, MatchingParams *params=0) const
Definition yateclass.h:8765
virtual const MatchingItemCustom * itemCustom() const
Definition yateclass.h:8807
virtual MatchingItemBase * copy() const
Definition yateclass.h:8772
const String & name() const
Definition yateclass.h:8722
virtual String & dump(String &buf, const MatchingItemDump *dump=0, const String &indent=String::empty(), const String &origIndent=String::empty(), unsigned int depth=0) const
Definition yateclass.h:8819
virtual const MatchingItemString * itemString() const
Definition yateclass.h:8779
Base class for custom matching.
Definition yateclass.h:9262
virtual const MatchingItemCustom * itemCustom() const
Definition yateclass.h:9287
const String & type() const
Definition yateclass.h:9280
MatchingItemCustom(const char *name, const char *type, bool negated=false)
Definition yateclass.h:9272
Matching item dump parameters.
Definition yateclass.h:8489
static String & dumpItem(const MatchingItemBase *mi, String &buf, const String &indent=String::empty(), const String &origIndent=String::empty(), const NamedList *params=0)
Definition yateclass.h:8563
virtual GenObject * dumpXml(const MatchingItemBase *mi, unsigned int depth=0) const
virtual String & dumpValue(const MatchingItemBase *mi, String &buf, const String &indent=String::empty(), const String &origIndent=String::empty(), unsigned int depth=0) const
DumpFlags
Definition yateclass.h:8495
MatchingItemDump(const NamedList *params=0, const char *name=0)
Definition yateclass.h:8505
virtual String & dump(const MatchingItemBase *mi, String &buf, const String &indent=String::empty(), const String &origIndent=String::empty(), unsigned int depth=0) const
virtual void init(const NamedList &params)
static GenObject * dumpItemXml(const MatchingItemBase *mi, const NamedList *params=0)
Definition yateclass.h:8576
A list of matching items.
Definition yateclass.h:9094
MatchingItemList(const char *name, bool matchAll=true, bool negated=false)
Definition yateclass.h:9104
virtual bool runMatchString(const String &str, MatchingParams *params=0) const
bool change(MatchingItemBase *item, int pos=-1, bool ins=false, unsigned int overAlloc=1)
bool matchAll() const
Definition yateclass.h:9112
bool set(MatchingItemBase *item, unsigned int pos, unsigned int overAlloc=1)
Definition yateclass.h:9200
virtual const MatchingItemList * itemList() const
Definition yateclass.h:9240
bool append(MatchingItemBase *item, unsigned int overAlloc=1)
Definition yateclass.h:9174
bool insert(MatchingItemBase *item, unsigned int pos=0, unsigned int overAlloc=1)
Definition yateclass.h:9211
virtual bool runMatchListParam(const NamedList &list, MatchingParams *params=0) const
const MatchingItemBase * find(const String &name) const
Definition yateclass.h:9150
virtual MatchingItemBase * copy() const
int indexOf(const String &name) const
Definition yateclass.h:9142
const MatchingItemBase * at(unsigned int index) const
Definition yateclass.h:9134
void append(ObjList &list)
Definition yateclass.h:9181
unsigned int count() const
Definition yateclass.h:9126
static MatchingItemBase * optimize(MatchingItemList *list)
unsigned int length() const
Definition yateclass.h:9119
Matching item load parameters.
Definition yateclass.h:8596
static const TokenDict64 * loadFlags()
virtual MatchingItemBase * load(const NamedList &params, String *error=0, const char *prefix=0, const char *suffix=0) const
LoadFlags
Definition yateclass.h:8602
static const TokenDict * itemFlags()
virtual MatchingItemBase * loadXml(const String &str, String *error=0) const
virtual MatchingItemBase * loadXml(const GenObject *gen, String *error=0) const
ItemFlags
Definition yateclass.h:8621
MatchingItemLoad(uint64_t flags=DefaultFlags, const char *name=0)
Definition yateclass.h:8634
Random number matching.
Definition yateclass.h:9010
virtual bool runMatchString(const String &str, MatchingParams *params=0) const
Definition yateclass.h:9058
virtual const MatchingItemRandom * itemRandom() const
Definition yateclass.h:9081
MatchingItemRandom(uint32_t val, uint32_t maxVal, bool negated=false, const char *name=0)
Definition yateclass.h:9022
virtual bool runMatchListParam(const NamedList &list, MatchingParams *params=0) const
Definition yateclass.h:9067
virtual MatchingItemBase * copy() const
Definition yateclass.h:9074
uint32_t maxValue() const
Definition yateclass.h:9042
uint32_t value() const
Definition yateclass.h:9035
bool randomMatch() const
Definition yateclass.h:9049
A matching item using a regular expression.
Definition yateclass.h:8927
virtual const MatchingItemRegexp * itemRegexp() const
Definition yateclass.h:8979
virtual bool runMatchString(const String &str, MatchingParams *params=0) const
Definition yateclass.h:8965
MatchingItemRegexp(const char *name, const char *value, bool negated=false)
Definition yateclass.h:8937
const Regexp & value() const
Definition yateclass.h:8956
static MatchingItemRegexp * build(const char *name, const String &str, int negated=0, bool insensitive=false, bool extended=false, int fail=1)
MatchingItemRegexp(const char *name, const Regexp &value, bool negated=false)
Definition yateclass.h:8948
virtual MatchingItemBase * copy() const
Definition yateclass.h:8972
String comparison matching item.
Definition yateclass.h:8864
virtual bool runMatchString(const String &str, MatchingParams *params=0) const
Definition yateclass.h:8900
MatchingItemString(const char *name, const char *value, bool caseInsensitive=false, bool negated=false)
Definition yateclass.h:8875
virtual MatchingItemBase * copy() const
Definition yateclass.h:8907
const String & value() const
Definition yateclass.h:8884
bool caseInsensitive() const
Definition yateclass.h:8891
virtual const MatchingItemString * itemString() const
Definition yateclass.h:8914
Matching item match parameters.
Definition yateclass.h:8469
MatchingParams(const char *name=0)
Definition yateclass.h:8476
A Stream that operates on DataBlocks in memory.
Definition yateclass.h:11288
virtual bool terminate()
Definition yateclass.h:11317
MemoryStream()
Definition yateclass.h:11294
virtual bool valid() const
Definition yateclass.h:11323
virtual int64_t length()
Definition yateclass.h:11346
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:11310
int64_t m_offset
Definition yateclass.h:11366
DataBlock m_data
Definition yateclass.h:11361
virtual int readData(void *buffer, int len)
MemoryStream(const DataBlock &data)
Definition yateclass.h:11302
A Mutex pool.
Definition yateclass.h:9500
unsigned int index(void *ptr) const
Definition yateclass.h:9526
MutexPool(unsigned int len=13, bool recursive=false, const char *name=0)
Mutex * mutex(void *ptr) const
Definition yateclass.h:9536
Mutex * mutex(unsigned int idx) const
Definition yateclass.h:9544
Mutex support.
Definition yateclass.h:9403
virtual bool locked() const
Mutex & operator=(const Mutex &original)
static int count()
virtual Mutex * lockableMutex()
Definition yateclass.h:9467
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:5428
NamedCounter(const String &name)
Definition yateclass.h:5435
int count() const
Definition yateclass.h:5479
int dec()
Definition yateclass.h:5464
void enable(bool val)
Definition yateclass.h:5450
int add(int val)
Definition yateclass.h:5472
bool enabled() const
Definition yateclass.h:5443
int inc()
Definition yateclass.h:5457
NamedList parameters iterator.
Definition yateclass.h:8264
NamedIterator & operator=(const NamedIterator &original)
Definition yateclass.h:8293
NamedIterator & operator=(const NamedList &list)
Definition yateclass.h:8286
const NamedString * get()
NamedIterator(const NamedIterator &original)
Definition yateclass.h:8278
void reset()
Definition yateclass.h:8311
NamedIterator(const NamedList &list)
Definition yateclass.h:8270
bool eof() const
Definition yateclass.h:8305
A named string container class.
Definition yateclass.h:7690
NamedList & setParamHex(const String &name, const void *buf, unsigned int len, char sep=0)
NamedList & setParam(const String &name, double value)
bool dump(String &str, unsigned int flags, const char *separator, const char *nameSep=0, const char *prefix=0, char quote=0) const
int64_t getInt64ValueDict(const String &name, const TokenDictStr64 *tokens, int64_t defvalue=0) const
NamedList & setParam(const String &name, bool value)
Definition yateclass.h:7952
NamedList & addParam(const char *name, double value)
Definition yateclass.h:7830
int getIntValue(const String &name, const TokenDictStr *tokens, int defvalue=0) const
virtual void * getObject(const String &name) const
NamedList & setParam(const String &name, uint32_t value)
int getIndex(const NamedString *param) const
void clearParams()
Definition yateclass.h:7757
NamedList & setParam(const String &name, int32_t value)
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:8250
NamedList & copyParam(const NamedList &original, const String &name, char childSep=0)
DumpFlags
Definition yateclass.h:7696
int64_t getInt64ValueDict(const String &name, const TokenDict64 *tokens, int64_t defvalue=0) const
NamedList & setParam(NamedString *param)
NamedList(const NamedList &original)
NamedList & setParam(const String &name, int64_t value)
NamedList & setParam(const String &name, uint64_t value)
NamedList & addParam(const char *name, uint64_t flags, const TokenDict64 *tokens, bool unknownflag=true)
Definition yateclass.h:7868
NamedList & addParam(const char *name, unsigned int flags, const TokenDict *tokens, bool unknownflag=true)
Definition yateclass.h:7853
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
NamedList & setParam(const String &name, uint64_t flags, const TokenDict64 *tokens, bool unknownflag=true)
NamedList & addParam(const char *name, uint32_t value)
Definition yateclass.h:7818
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
NamedList & addParam(const char *name, int32_t value)
Definition yateclass.h:7806
NamedList & addParam(const char *name, int64_t value)
Definition yateclass.h:7782
NamedList & addParam(const char *name, bool value)
Definition yateclass.h:7842
bool getBoolValue(const String &name, bool defvalue=false) const
double getDoubleValue(const String &name, double defvalue=0.0) const
NamedList & copyParams(const NamedList &original)
Definition yateclass.h:8027
NamedList & clearParam(const String &name, char childSep=0, const String *value=0)
NamedList & addParam(const char *name, uint64_t value)
Definition yateclass.h:7794
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:8243
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:7751
NamedList & copyParams(bool replace, const NamedList &original, bool copyUserData=false)
NamedList & setParam(const String &name, unsigned int flags, const TokenDict *tokens, bool unknownflag=true)
unsigned int length() const
Definition yateclass.h:7744
NamedList & addParamHex(const char *name, const void *buf, unsigned int len, char sep=0)
Definition yateclass.h:7883
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
A named pointer class.
Definition yateclass.h:5353
void userData(GenObject *data)
virtual void * getObject(const String &name) const
NamedPointer(const char *name, GenObject *data=0, const char *value=0, int len=-1)
GenObject * userData() const
Definition yateclass.h:5374
virtual void changed()
GenObject * takeData()
void * userObject(const String &name) const
Definition yateclass.h:5396
virtual ~NamedPointer()
NamedPointer & operator=(const char *value)
Definition yateclass.h:5402
A named string class.
Definition yateclass.h:5304
NamedString(const char *name, const char *value=0, int len=-1)
virtual void * getObject(const String &name) const
NamedString & operator=(const char *value)
Definition yateclass.h:5338
virtual const String & toString() const
const String & name() const
Definition yateclass.h:5319
A NAPTR record.
Definition yateclass.h:12548
const String & serv() const
Definition yateclass.h:12591
bool replace(String &str) const
virtual void dump(String &buf, const char *sep=" ")
const Regexp & regexp() const
Definition yateclass.h:12598
const String & nextName() const
Definition yateclass.h:12612
const String & repTemplate() const
Definition yateclass.h:12605
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:12584
An object list class.
Definition yateclass.h:2032
void compact()
virtual void * getObject(const String &name) const
GenObject * remove(Lockable &lock, GenObject *obj, bool delobj=true, long maxwait=-1)
ObjList * next() const
Definition yateclass.h:2083
void compact(Lockable &lock, long maxwait=-1)
ObjList * last() const
GenObject * remove(Lockable &lock, bool delobj=true, long maxwait=-1)
ObjList * setUnique(Lockable &lock, const GenObject *obj, bool autoDelete=true, long maxwait=-1, bool compact=true)
ObjList * move(ObjList *dest, Lockable *lock=0, long maxwait=-1)
virtual ~ObjList()
ObjList * insert(Lockable &lock, const GenObject *obj, bool autoDelete=true, long maxwait=-1, bool compact=true)
void sort(int(*callbackCompare)(GenObject *obj1, GenObject *obj2, void *context), void *context=0)
ObjList * copy(ObjList *dest, Lockable *lock=0, long maxwait=-1) const
ObjList * find(const GenObject *obj) const
GenObject * find(Lockable &lock, const String &str, bool ref=false, long maxwait=-1) 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:2250
GenObject * findObj(const GenObject *obj) const
Definition yateclass.h:2156
GenObject * operator[](signed int index) const
Definition yateclass.h:2123
void clear(Lockable &lock, long maxwait=-1)
GenObject * remove(const String &str, bool delobj=true)
ObjList * skipNext() const
GenObject * operator[](unsigned int index) const
Definition yateclass.h:2131
bool autoDelete()
Definition yateclass.h:2243
ObjList * operator+(int index) const
ObjList * append(Lockable &lock, const GenObject *obj, bool autoDelete=true, long maxwait=-1, bool compact=true)
GenObject * operator[](const String &str) const
Definition yateclass.h:2139
GenObject * get() const
Definition yateclass.h:2068
void clear()
static const ObjList & empty()
GenObject * remove(Lockable &lock, const String &str, bool delobj=true, long maxwait=-1)
unsigned int count() const
GenObject * find(Lockable &lock, const GenObject *obj, bool ref=false, long maxwait=-1) 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:2403
const GenObject ** data(unsigned int offs, unsigned int len=1) const
Definition yateclass.h:2482
unsigned int cut(int items, bool reAlloc=true)
Definition yateclass.h:2537
GenObject ** data()
Definition yateclass.h:2457
virtual void * getObject(const String &name) const
bool appendObj(GenObject *obj, bool fromStart, bool beforeNonNull=false)
Definition yateclass.h:2624
const GenObject ** data() const
Definition yateclass.h:2473
unsigned int compact(bool resizeToCount=false)
Definition yateclass.h:2571
unsigned int allocChunk() const
Definition yateclass.h:2724
ObjVector(ObjList &list, bool move=true, unsigned int maxLen=0, bool autodelete=true, unsigned int allocChunk=0)
void reset(unsigned int pos=0, int len=-1)
GenObject * operator[](unsigned int idx) const
Definition yateclass.h:2673
ObjVector(bool autodelete=true, unsigned int allocChunk=0)
Definition yateclass.h:2411
bool null() const
int index(const String &str) const
unsigned int size() const
Definition yateclass.h:2738
GenObject ** data(unsigned int offs, unsigned int len=1)
Definition yateclass.h:2466
unsigned int compact(unsigned int pos, int len)
void setDelete(bool autodelete)
Definition yateclass.h:2717
unsigned int cut(unsigned int pos, unsigned int items, bool reAlloc=true)
GenObject * operator[](signed int idx) const
Definition yateclass.h:2681
bool autoDelete()
Definition yateclass.h:2710
void allocChunk(unsigned int count)
Definition yateclass.h:2731
unsigned int insert(unsigned int pos, unsigned int items)
ObjVector(unsigned int maxLen, bool autodelete=true, unsigned int allocChunk=0)
GenObject * operator[](const String &str) const
Definition yateclass.h:2689
bool appendObj(GenObject *obj)
Definition yateclass.h:2611
int indexFree(bool fromStart, bool beforeNonNull=false) const
bool set(GenObject *obj, unsigned int index)
GenObject * take(unsigned int index)
Definition yateclass.h:2591
void clear()
unsigned int count() const
bool insertObj(GenObject *obj, unsigned int pos)
Definition yateclass.h:2638
int index(const GenObject *obj) const
GenObject * at(unsigned int index) const
Definition yateclass.h:2502
unsigned int length() const
Definition yateclass.h:2450
virtual ~ObjVector()
unsigned int assign(ObjList &list, bool move=true, unsigned int maxLen=0)
unsigned int resize(unsigned int len, bool keepData=false, bool reAlloc=true)
Definition yateclass.h:2555
Definition yateclass.h:9799
void drop()
Definition yateclass.h:9833
bool acquire(RWLock *lck, long maxwait=-1)
Definition yateclass.h:9842
~RLock()
Definition yateclass.h:9820
RLock(RWLock *lck, long maxwait=-1)
Definition yateclass.h:9814
RLock(RWLock &lck, long maxWait=-1)
Definition yateclass.h:9806
RWLock * locked() const
Definition yateclass.h:9827
bool acquire(RWLock &lck, long maxwait=-1)
Definition yateclass.h:9852
A RWLock pool.
Definition yateclass.h:9943
unsigned int index(void *ptr) const
Definition yateclass.h:9967
RWLock * lock(unsigned int idx) const
Definition yateclass.h:9985
RWLockPool(unsigned int len=13, const char *name=0)
RWLock * lock(void *ptr) const
Definition yateclass.h:9977
Read/write lock support.
Definition yateclass.h:9720
virtual bool locked() const
static void disableRWLock(bool disable)
virtual RWLock * lockableRWLock()
Definition yateclass.h:9779
RWLock(const RWLock &original)
bool readLock(long maxWait=-1)
RWLock(const char *name=0)
virtual bool lock(long maxWait=-1)
Definition yateclass.h:9765
bool writeLock(long maxWait=-1)
virtual bool unlock()
Pseudo random number generator.
Definition yateclass.h:6023
u_int32_t next()
u_int32_t get() const
Definition yateclass.h:6037
static long int random()
void set(u_int32_t seed)
Definition yateclass.h:6044
Random(u_int32_t seed=Time::now() &0xffffffff)
Definition yateclass.h:6029
static void srandom(unsigned int seed)
Definition yateclass.h:1752
static bool efficientIncDec()
static bool alive(const RefObject *obj)
Definition yateclass.h:1815
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:1801
bool ref()
Internal helper class.
Definition yateclass.h:1858
RefPointerBase()
Definition yateclass.h:1863
void * m_pointer
Definition yateclass.h:1877
void assign(RefObject *oldptr, RefObject *newptr, void *pointer)
Templated smart pointer class.
Definition yateclass.h:1884
RefPointer< Obj > & operator=(Obj *object)
Definition yateclass.h:1937
RefPointer< Obj > & operator=(const RefPointer< Obj > &value)
Definition yateclass.h:1931
Obj & operator*() const
Definition yateclass.h:1956
Obj * pointer() const
Definition yateclass.h:1890
void assign(Obj *object=0)
Definition yateclass.h:1897
~RefPointer()
Definition yateclass.h:1925
RefPointer()
Definition yateclass.h:1904
Obj * operator->() const
Definition yateclass.h:1950
RefPointer(const RefPointer< Obj > &value)
Definition yateclass.h:1911
RefPointer(Obj *object)
Definition yateclass.h:1919
A regexp matching class.
Definition yateclass.h:5094
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:5132
bool isExtended() const
void setFlags(bool extended, bool insensitive)
Regexp(const Regexp &value)
Regexp & operator=(const char *value)
Definition yateclass.h:5125
bool matches(const char *value) const
virtual bool matches(const String &value) const
Definition yateclass.h:5147
DNS services.
Definition yateclass.h:12631
static bool init(int timeout=-1, int retries=-1)
static int naptrQuery(const char *dname, ObjList &result, String *error=0)
Type
Definition yateclass.h:12636
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:10171
virtual void run()=0
virtual ~Runnable()
A standard SHA1 digest calculator.
Definition yateclass.h:7437
SHA1 & operator=(const SHA1 &original)
SHA1(const void *buf, unsigned int len)
static unsigned int rawLength()
Definition yateclass.h:7501
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:7508
A standard SHA256 digest calculator.
Definition yateclass.h:7534
static unsigned int rawLength()
Definition yateclass.h:7598
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:7605
Abstract SCTP Socket.
Definition yateclass.h:12228
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:12234
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:12280
SctpSocket(SOCKET fd)
Definition yateclass.h:12241
virtual ~SctpSocket()
virtual bool bindx(ObjList &addresses)=0
Semaphore implementation.
Definition yateclass.h:9558
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 Semaphore * lockableSemaphore()
Definition yateclass.h:9611
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:10588
static unsigned int scopeId(struct sockaddr *addr)
Definition yateclass.h:10884
static const char * lookupFamily(int family)
Definition yateclass.h:10984
bool iface(const char *name, bool uriUnescape=false)
Definition yateclass.h:10776
int copyAddr(DataBlock &addr) const
static String & appendAddr(String &buf, const String &addr, int family=Unknown, const String &iface=String::empty())
int port() const
static bool scopeId(struct sockaddr *addr, unsigned int val)
Definition yateclass.h:10898
bool assign(int family)
bool operator!=(const SocketAddr &other) const
Definition yateclass.h:10665
SocketAddr(int family, const void *raw=0)
static String & appendTo(String &buf, const String &addr, int port, int family=Unknown, const String &iface=String::empty())
Definition yateclass.h:10928
bool valid() const
Definition yateclass.h:10705
virtual void stringify()
socklen_t length() const
Definition yateclass.h:10817
virtual void updateAddr(bool full=false) const
static bool isNullAddr(const String &addr, int family=Unknown)
static String appendTo(const String &addr, int port, int family=Unknown, const String &iface=String::empty())
Definition yateclass.h:10942
struct sockaddr * address() const
Definition yateclass.h:10810
static bool stringify(String &buf, struct sockaddr *addr)
static int unStringify(uint8_t *buf, const String &host, int family=Unknown)
Definition yateclass.h:10864
bool operator==(const SocketAddr &other) const
virtual ~SocketAddr()
SocketAddr & operator=(const SocketAddr &value)
Definition yateclass.h:10650
int family() const
Definition yateclass.h:10719
bool null() const
Definition yateclass.h:10712
bool assign(const DataBlock &addr)
Family
Definition yateclass.h:10594
const String & addr(bool full=false) const
Definition yateclass.h:10756
unsigned int scopeId() const
Definition yateclass.h:10733
SocketAddr(const SocketAddr &value)
Definition yateclass.h:10622
const char * familyName() const
Definition yateclass.h:10726
static int family(const String &addr)
const String & host() const
Definition yateclass.h:10748
bool scopeId(unsigned int val)
Definition yateclass.h:10741
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)
static const char * ifaceNameExtraEscape()
Definition yateclass.h:11009
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 & iface() const
Definition yateclass.h:10767
void clear()
static const String & ipv4NullAddr()
bool local(const SocketAddr &remote)
static const String & ipv6NullAddr()
static String & escapeIface(String &buf, const char *name)
Definition yateclass.h:11018
bool port(int newport)
SocketAddr()
Definition yateclass.h:10614
bool isNullAddr() const
Definition yateclass.h:10824
A filter for received socket data.
Definition yateclass.h:11051
virtual void * getObject(const String &name) const
virtual bool received(const void *buffer, int length, int flags, const struct sockaddr *addr, socklen_t adrlen)=0
bool valid() const
virtual ~SocketFilter()
virtual bool sent(const void *buffer, int length, int flags, const struct sockaddr *addr, socklen_t adrlen)
Definition yateclass.h:11098
Socket * socket() const
Definition yateclass.h:11105
virtual void timerTick(const Time &when)
RefObject holding a Socket pointer.
Definition yateclass.h:12340
virtual void * getObject(const String &name) const
Definition yateclass.h:12363
SocketRef(Socket *&socket)
Definition yateclass.h:12354
SocketRef(Socket **socket)
Definition yateclass.h:12346
A generic socket class.
Definition yateclass.h:11610
virtual bool connectAsync(struct sockaddr *addr, socklen_t addrlen, unsigned int toutUs, bool *timeout=0)
SOCKET detach()
static const TokenDict * tosValues()
bool connectAsync(const SocketAddr &addr, unsigned int toutUs, bool *timeout=0)
Definition yateclass.h:11998
virtual bool terminate()
void copyError()
void clearFilters(bool del=true)
bool installFilter(SocketFilter *filter)
Socket(SOCKET handle)
void attach(SOCKET handle)
virtual bool setReuse(bool reuse=true, bool exclusive=false, bool setPort=false)
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:11627
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:11891
Features
Definition yateclass.h:11659
virtual bool bindIface(const char *iface, int ifLen=-1, int family=SocketAddr::Unknown)
bool getSockName(SocketAddr &addr)
virtual bool inProgress() const
virtual bool shutdown(bool stopReads, bool stopWrites)
SOCKET handle() const
Definition yateclass.h:11723
int sendTo(const void *buffer, int length, const SocketAddr &addr, int flags=0)
Definition yateclass.h:12066
bool setIpv6OnlyOption(bool on)
Definition yateclass.h:11780
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 bind(struct sockaddr *addr, socklen_t addrlen, const char *iface, int ifLen=-1)
virtual bool getSockName(struct sockaddr *addr, socklen_t *addrlen)
static unsigned int features()
Definition yateclass.h:12185
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)
virtual bool canRetry() const
virtual bool getParams(const String &params, NamedList &result)
Definition yateclass.h:11812
virtual bool setTOS(int tos)
virtual bool setOption(int level, int name, const void *value=0, socklen_t length=0)
bool applyFilters(const void *buffer, int length, int flags, const struct sockaddr *addr=0, socklen_t adrlen=0, bool rx=true)
virtual bool setParams(const NamedList &params)
Definition yateclass.h:11803
virtual void timerTick(const Time &when)
virtual bool setBlocking(bool block=true)
virtual Socket * accept(SocketAddr &addr)
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:11616
bool updateError()
virtual bool setLinger(int seconds=-1)
bool setTOS(const char *tos, int defTos=Normal)
Definition yateclass.h:11828
bool connect(const SocketAddr &addr)
Definition yateclass.h:11975
virtual bool getBoundIface(String &buf)
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:12491
SrvRecord(int ttl, int prio, int weight, const char *addr, int port)
Definition yateclass.h:12503
int port() const
Definition yateclass.h:12518
static void copy(ObjList &dest, const ObjList &src)
virtual void dump(String &buf, const char *sep=" ")
const String & address() const
Definition yateclass.h:12511
An abstract stream class capable of reading and writing.
Definition yateclass.h:11123
int writeData(const DataBlock &buf)
Definition yateclass.h:11205
static bool allocPipe(Stream *&reader, Stream *&writer)
virtual int readData(void *buffer, int length)=0
virtual ~Stream()
int error() const
Definition yateclass.h:11143
SeekPos
Definition yateclass.h:11128
virtual bool inProgress() const
Stream()
Definition yateclass.h:11270
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:11277
int writeData(const String &str)
Definition yateclass.h:11197
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:11235
A C-style string handling class.
Definition yateclass.h:3055
String & removeChars(const char *what, int wLen=-1, bool *chg=0)
Definition yateclass.h:3943
const char * c_str() const
Definition yateclass.h:3160
String & printf(unsigned int length, const char *format,...)
double toDouble(double defvalue=0.0) const
String & printfAppend(const char *format,...)
String & appendFixed(unsigned int fixedLength, const String &str, char fill=' ', int align=Left)
Definition yateclass.h:3853
bool checkBOM() const
Definition yateclass.h:3263
int find(const char *what, unsigned int offs=0) const
String & trimSpaces()
String & operator=(bool value)
Definition yateclass.h:3570
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 & replaceChars(const char *what, const char *repl, bool inPlace=false, int wLen=-1, int rLen=-1, bool *chg=0)
static unsigned int c_skip(const char *&str, const char *what, int lenStr=-1, int lenWhat=-1, bool caseInsensitive=false)
Definition yateclass.h:4289
String & operator>>(int &store)
static bool stripBOM(char *&str)
Definition yateclass.h:3279
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:3478
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 & operator+=(int64_t value)
static String sqlEscape(const char *str, char extraEsc=0)
ObjList * split(ObjList &list, const Regexp &reg, bool emptyOK=true) const
String(int64_t value)
ObjList * split(char separator, bool emptyOK=true) const
Definition yateclass.h:4063
static String uriEscape(const char *str, char extraEsc=0, const char *noEsc=0)
Definition yateclass.h:4170
static String uriEscape(const char *str, const char *extraEsc, const char *noEsc=0)
Definition yateclass.h:4182
bool operator==(const char *value) const
static bool checkBOM(const char *str)
Definition yateclass.h:3256
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
static unsigned int c_starts_with(const char *str, const char *what, int lenStr=-1, int lenWhat=-1, bool caseInsensitive=false)
String & extractTo(const char *sep, double &store)
int rfind(const char *what) const
String & operator+=(const char *value)
Definition yateclass.h:3584
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:3771
String & operator<<(const char *value)
Definition yateclass.h:3665
String & insert(unsigned int pos, char value, unsigned int len=1)
ObjList * split(const Regexp &reg, bool emptyOK=true) const
Definition yateclass.h:4075
String matchString(int index=0) const
Definition yateclass.h:4023
String & operator<<(int32_t value)
Definition yateclass.h:3677
String & operator=(int64_t value)
bool null() const
Definition yateclass.h:3189
virtual void changed()
String & operator+=(uint64_t value)
String & operator=(uint32_t value)
const char * safe() const
Definition yateclass.h:3167
int lenUtf8(uint32_t maxChar=0x10ffff, bool overlong=false) const
Definition yateclass.h:3207
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)
int64_t toInt64Dict(const TokenDictStr64 *tokens, int64_t defvalue=0, int base=0) const
static String & uriEscapeTo(String &buf, const char *str, const char *extraEsc, const char *noEsc=0)
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)
static char * c_replace_chars(const char *str, const char *what, const char *repl=0, bool inPlace=false, int wLen=-1, int rLen=-1, bool *chg=0)
String & hexify(const void *data, unsigned int len, char sep=0, bool upCase=false)
static String uriUnescape(const char *str, int *errptr=0, bool setPartial=true)
Definition yateclass.h:4234
String sqlEscape(char extraEsc=0) const
Definition yateclass.h:4128
String & operator=(const char *value)
bool operator==(const String &value) const
Definition yateclass.h:3643
String uriUnescape(int *errptr=0, bool setPartial=true) const
Definition yateclass.h:4245
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:3649
String & insert(unsigned int pos, const char *value, int len=-1)
virtual const String & toString() const
bool stripBOM()
Definition yateclass.h:3286
String & operator>>(unsigned int &store)
String & uriEscapeTo(String &buf, char extraEsc=0, const char *noEsc=0) const
Definition yateclass.h:4160
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)
int64_t toInt64Dict(const TokenDict64 *tokens, int64_t defvalue=0, int base=0) const
static unsigned int c_ends_with(const char *str, const char *what, int lenStr=-1, int lenWhat=-1, bool caseInsensitive=false)
String(const char *value, int len=-1)
String & operator<<(uint32_t value)
Definition yateclass.h:3683
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:3695
String & operator<<(double value)
Definition yateclass.h:3707
String & append(char value, unsigned int len=1)
Definition yateclass.h:3780
String(char value, unsigned int repeat=1)
int toInteger(const TokenDictStr *tokens, int defvalue=0, int base=0) const
String & append(const char *value, int len)
String & operator>>(char &store)
static const char * boolText(bool value)
Definition yateclass.h:3153
static unsigned int c_skip_chars(const char *&str, const char *what, int len=-1, bool skipFound=true)
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:3271
void clear()
String & operator=(char value)
int toInteger(const TokenDict *tokens, int defvalue=0, int base=0) const
String & uriUnescapeStr(bool setPartial=false, int *errptr=0)
Definition yateclass.h:4224
unsigned int hash() const
Definition yateclass.h:3293
String uriEscape(char extraEsc=0, const char *noEsc=0) const
Definition yateclass.h:4193
String & operator=(const String &value)
Definition yateclass.h:3518
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 & decodeFlags(unsigned int flags, const TokenDict *tokens, bool unknownflag=true)
String & operator=(uint64_t value)
String & operator+=(char value)
String & operator<<(bool value)
Definition yateclass.h:3701
bool startsWith(const char *what, bool wordBreak=false, bool caseInsensitive=false) const
String & decodeFlags(uint64_t flags, const TokenDict64 *tokens, bool unknownflag=true)
String & operator>>(UChar &store)
int matchLength(int index=0) const
static const String & empty()
const char * safe(const char *defStr) const
Definition yateclass.h:3175
String & toUpper()
char operator[](signed int index) const
Definition yateclass.h:3470
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)
ObjList * split(ObjList &list, char separator, bool emptyOK=true) const
unsigned int encodeFlags(const TokenDict *tokens) const
unsigned int length() const
Definition yateclass.h:3182
String & printfAppend(unsigned int length, const char *format,...)
static String & uriEscapeTo(String &buf, const char *str, char extraEsc=0, const char *noEsc=0)
String & operator+=(bool value)
Definition yateclass.h:3621
bool operator!=(const char *value) const
String & operator<<(char value)
Definition yateclass.h:3671
String msgEscape(char extraEsc=0) const
Definition yateclass.h:4094
String & operator=(double value)
bool matches(const Regexp &rexp)
String & operator<<(int64_t value)
Definition yateclass.h:3689
String msgUnescape(int *errptr=0, char extraEsc=0) const
Definition yateclass.h:4112
String & printf(const char *format,...)
String(int32_t value)
String(double value)
virtual bool matches(const String &value) const
Definition yateclass.h:3994
bool isBoolean() const
String & operator=(const String *value)
Definition yateclass.h:3526
String & uriUnescapeTo(String &buf, bool setPartial=false, int *errptr=0) const
Definition yateclass.h:4215
static String & uriUnescapeTo(String &buf, const char *str, bool setPartial=false, int *errptr=0)
String substr(int offs, int len=-1) const
A class exposing system resources usage.
Definition yateclass.h:13033
static u_int64_t usecRunTime(Type type=WallTime)
Type
Definition yateclass.h:13038
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:10540
TempObjectCounter(const GenObject *obj, bool enable=GenObject::getObjCounting())
Definition yateclass.h:10557
TempObjectCounter(const GenObject &obj, bool enable=GenObject::getObjCounting())
Definition yateclass.h:10566
TempObjectCounter(NamedCounter *counter, bool enable=GenObject::getObjCounting())
Definition yateclass.h:10548
~TempObjectCounter()
Definition yateclass.h:10573
Thread support class.
Definition yateclass.h:10192
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:10202
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:10494
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:10262
int getAffinity(DataBlock &outCpuMask)
static void killall()
const char * name() const
bool locked() const
Definition yateclass.h:10269
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:10424
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:5764
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:5846
Time()
Definition yateclass.h:5769
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:5853
static unsigned int appendTo(String &buf, uint64_t time, int frac=0)
Definition yateclass.h:5980
Time & operator=(u_int64_t usec)
Definition yateclass.h:5834
Time(u_int64_t usec)
Definition yateclass.h:5777
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:5815
static u_int64_t fromTimeval(const struct timeval &tv)
Definition yateclass.h:5875
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:5793
u_int64_t usec() const
Definition yateclass.h:5822
Time(const struct timeval *tv)
Definition yateclass.h:5785
static u_int64_t now()
Time & operator+=(int64_t delta)
Definition yateclass.h:5840
uint32_t toNtp(uint32_t *over=0, bool rfc2030=true)
Definition yateclass.h:5943
static u_int64_t fromTimeval(const struct timeval *tv)
u_int32_t sec() const
Definition yateclass.h:5808
static u_int32_t secNow()
static bool isLeap(unsigned int year)
Definition yateclass.h:6004
~Time()
Definition yateclass.h:5801
static u_int64_t msecNow()
A text based DNS record.
Definition yateclass.h:12445
TxtRecord(int ttl, const char *text)
Definition yateclass.h:12454
static void copy(ObjList &dest, const ObjList &src)
virtual void dump(String &buf, const char *sep=" ")
const String & text() const
Definition yateclass.h:12462
A single Unicode character.
Definition yateclass.h:2887
const char * c_str() const
Definition yateclass.h:2953
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:2939
UChar(uint32_t code=0)
Definition yateclass.h:2898
UChar(int32_t code)
Definition yateclass.h:2906
UChar & operator=(uint32_t code)
Definition yateclass.h:2931
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:2922
bool decode(DataBlock &buff, Endianness order, uint32_t maxChar=0x10ffff)
bool encode(DataBlock &buff, Endianness order)
uint32_t code() const
Definition yateclass.h:2946
UChar(signed char code)
Definition yateclass.h:2914
Encapsulation for an URI.
Definition yateclass.h:8326
static void setup(const NamedList &params)
virtual void clearData() const
URI(const URI &uri)
const String & getUser() const
Definition yateclass.h:8405
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:8426
URI & operator=(const String &value)
Definition yateclass.h:8377
URI(const char *uri)
const String & getDescription() const
Definition yateclass.h:8391
URI & operator=(const URI &value)
Definition yateclass.h:8370
URI & operator=(const char *value)
Definition yateclass.h:8384
int getPort() const
Definition yateclass.h:8419
URI(const String &uri)
const String & getProtocol() const
Definition yateclass.h:8398
const String & getHost() const
Definition yateclass.h:8412
Definition yateclass.h:9870
void drop()
Definition yateclass.h:9904
bool acquire(RWLock *lck, long maxWait=-1)
Definition yateclass.h:9913
~WLock()
Definition yateclass.h:9891
RWLock * locked() const
Definition yateclass.h:9898
WLock(RWLock *lck, long maxWait=-1)
Definition yateclass.h:9885
WLock(RWLock &lck, long maxWait=-1)
Definition yateclass.h:9877
bool acquire(RWLock &lck, long maxWait=-1)
Definition yateclass.h:9923
An atomic number.
Definition yateclass.h:1228
YAtomicNumber(const YAtomicNumber &val)
Definition yateclass.h:1249
Type operator++()
Definition yateclass.h:1563
Type operator|=(Type val)
Definition yateclass.h:1602
Type operator&=(Type val)
Definition yateclass.h:1595
Type valueAtomic() const
Definition yateclass.h:1278
Type preAdd(Type val)
Definition yateclass.h:1450
YAtomicNumber & operator=(Type val)
Definition yateclass.h:1543
Type operator^=(Type val)
Definition yateclass.h:1609
Type operator-=(Type val)
Definition yateclass.h:1588
Type preBitAnd(Type val)
Definition yateclass.h:1482
Type dec()
Definition yateclass.h:1333
Type operator--(int)
Definition yateclass.h:1581
Type value() const
Definition yateclass.h:1257
Type bitOr(Type val)
Definition yateclass.h:1392
Type preSub(Type val)
Definition yateclass.h:1466
YAtomicNumber & operator=(const YAtomicNumber &val)
Definition yateclass.h:1550
YAtomicNumber(Type val)
Definition yateclass.h:1241
Type valueAtomic()
Definition yateclass.h:1291
Type preBitOr(Type val)
Definition yateclass.h:1498
Type operator--()
Definition yateclass.h:1569
Type add(Type val)
Definition yateclass.h:1347
YAtomicNumber()
Definition yateclass.h:1233
Type preBitXor(Type val)
Definition yateclass.h:1514
Type sub(Type val)
Definition yateclass.h:1362
Type preDec()
Definition yateclass.h:1435
Type operator++(int)
Definition yateclass.h:1575
Type value()
Definition yateclass.h:1264
Type operator+=(Type val)
Definition yateclass.h:1557
Type inc()
Definition yateclass.h:1320
Type & valueRef()
Definition yateclass.h:1271
Type set(Type val)
Definition yateclass.h:1305
Type bitXor(Type val)
Definition yateclass.h:1407
Type preInc()
Definition yateclass.h:1421
Type bitAnd(Type val)
Definition yateclass.h:1377
Definition yatemime.h:34
Complex operator+(const Complex &c1, const Complex &c2)
Definition yatemath.h:1567
Definition yateclass.h:908
const char * token
Definition yateclass.h:912
int64_t value
Definition yateclass.h:917
Definition yateclass.h:5029
String token
Definition yateclass.h:5033
int64_t value
Definition yateclass.h:5038
Definition yateclass.h:5012
String token
Definition yateclass.h:5016
int value
Definition yateclass.h:5021
Definition yateclass.h:891
const char * token
Definition yateclass.h:895
int value
Definition yateclass.h:900