Yate: yateclass.h Source File

Yate

- Main Page
- Namespaces
- Classes
- Files

- File List

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
61 typedef signed __int8 int8_t;
62 typedef unsigned __int8 u_int8_t;
63 typedef unsigned __int8 uint8_t;
64 typedef signed __int16 int16_t;
65 typedef unsigned __int16 u_int16_t;
66 typedef unsigned __int16 uint16_t;
67 typedef signed __int32 int32_t;
68 typedef unsigned __int32 u_int32_t;
69 typedef unsigned __int32 uint32_t;
70 typedef signed __int64 int64_t;
71 typedef unsigned __int64 u_int64_t;
72 typedef unsigned __int64 uint64_t;
73
74 typedef int pid_t;
75 typedef int socklen_t;
76 typedef 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 open _open
91 #define dup2 _dup2
92 #define read _read
93 #define write _write
94 #define close _close
95 #define getpid _getpid
96 #define chdir _chdir
97 #define mkdir(p,m) _mkdir(p)
98 #define unlink _unlink
99
100 #define O_RDWR _O_RDWR
101 #define O_RDONLY _O_RDONLY
102 #define O_WRONLY _O_WRONLY
103 #define O_APPEND _O_APPEND
104 #define O_BINARY _O_BINARY
105 #define O_EXCL _O_EXCL
106 #define O_CREAT _O_CREAT
107 #define O_TRUNC _O_TRUNC
108 #define O_NOCTTY 0
109
110 #define S_IRUSR _S_IREAD
111 #define S_IWUSR _S_IWRITE
112 #define S_IXUSR 0
113 #define S_IRWXU (_S_IREAD|_S_IWRITE)
114
115 #ifdef LIBYATE_EXPORTS
116 #define YATE_API __declspec(dllexport)
117 #else
118 #ifndef LIBYATE_STATIC
119 #define YATE_API __declspec(dllimport)
120 #endif
121 #endif
122
123 #define FMT64 "%I64d"
124 #define FMT64U "%I64u"
125
126 #else /* _WINDOWS */
127
128 #include <sys/time.h>
129 #include <sys/socket.h>
130
131 #if defined(__FreeBSD__)
132 #include <netinet/in_systm.h>
133 #endif
134
135 #include <netinet/in.h>
136 #include <netinet/ip.h>
137 #include <netinet/tcp.h>
138 #include <arpa/inet.h>
139 #include <netdb.h>
140
144 #ifndef SOCKET
145 typedef int SOCKET;
146 #endif
147 #ifndef HANDLE
148 typedef int HANDLE;
149 #endif
150
151 #ifndef O_BINARY
152 #define O_BINARY 0
153 #endif
154
155 #if _WORDSIZE == 64 && !defined(__APPLE__)
156 #define FMT64 "%ld"
157 #define FMT64U "%lu"
158 #else
159 #define FMT64 "%lld"
160 #define FMT64U "%llu"
161 #endif
162
163 #endif /* ! _WINDOWS */
164
165 #ifndef LLONG_MAX
166 #ifdef _I64_MAX
167 #define LLONG_MAX _I64_MAX
168 #else
169 #define LLONG_MAX 9223372036854775807LL
170 #endif
171 #endif
172
173 #ifndef LLONG_MIN
174 #ifdef _I64_MIN
175 #define LLONG_MIN _I64_MIN
176 #else
177 #define LLONG_MIN (-LLONG_MAX - 1LL)
178 #endif
179 #endif
180
181 #ifndef ULLONG_MAX
182 #ifdef _UI64_MAX
183 #define ULLONG_MAX _UI64_MAX
184 #else
185 #define ULLONG_MAX 18446744073709551615ULL
186 #endif
187 #endif
188
189 #ifndef O_LARGEFILE
190 #define O_LARGEFILE 0
191 #endif
192
193 #ifndef IPTOS_LOWDELAY
194 #define IPTOS_LOWDELAY 0x10
195 #define IPTOS_THROUGHPUT 0x08
196 #define IPTOS_RELIABILITY 0x04
197 #endif
198 #ifndef IPTOS_MINCOST
199 #define IPTOS_MINCOST 0x02
200 #endif
201 #ifndef IPPROTO_SCTP
202 #define IPPROTO_SCTP 132
203 #endif
204
205 #ifndef YATE_API
206 #define YATE_API
207 #endif
208
209 #ifdef _WINDOWS
210 #undef RAND_MAX
211 #define RAND_MAX 2147483647
212 #endif
213
217 namespace TelEngine {
218
219 #ifdef HAVE_GCC_FORMAT_CHECK
220 #define FORMAT_CHECK(f) __attribute__((format(printf,(f),(f)+1)))
221 #else
222 #define FORMAT_CHECK(f)
223 #endif
224
225 #define YIGNORE(v) while (v) { break; }
226
227 #ifdef HAVE_BLOCK_RETURN
228 #define YSTRING(s) (*({static const String str("" s);&str;}))
229 #define YATOM(s) (*({static const String* str(0);str ? str : String::atom(str,"" s);}))
230 #else
231 #define YSTRING(s) ("" s)
232 #define YATOM(s) ("" s)
233 #endif
234
235 #define YSTRING_INIT_HASH ((unsigned) -1)
236
241 YATE_API void abortOnBug();
242
247 YATE_API bool abortOnBug(bool doAbort);
248
254 enum DebugLevel {
255 DebugFail = 0,
256 DebugTest = 1,
257 DebugCrit = 2,
258 DebugGoOn = DebugCrit,
259 DebugConf = 3,
260 DebugStub = 4,
261 DebugWarn = 5,
262 DebugMild = 6,
263 DebugNote = 7,
264 DebugCall = 8,
265 DebugInfo = 9,
266 DebugAll = 10
267 };
268
273 YATE_API int debugLevel();
274
280 YATE_API int debugLevel(int level);
281
287 YATE_API bool debugAt(int level);
288
295 YATE_API const char* debugColor(int level);
296
302 YATE_API const char* debugLevelName(int level);
303
309 class YATE_API DebugEnabler
310 {
311 public:
317 inline DebugEnabler(int level = TelEngine::debugLevel(), bool enabled = true)
318 : m_level(DebugFail), m_enabled(enabled), m_chain(0), m_name(0)
319 { debugLevel(level); }
320
321 inline ~DebugEnabler()
322 { m_name = 0; m_chain = 0; }
323
328 inline int debugLevel() const
329 { return m_chain ? m_chain->debugLevel() : m_level; }
330
336 int debugLevel(int level);
337
342 inline bool debugEnabled() const
343 { return m_chain ? m_chain->debugEnabled() : m_enabled; }
344
349 inline void debugEnabled(bool enable)
350 { m_enabled = enable; m_chain = 0; }
351
356 inline const char* debugName() const
357 { return m_name; }
358
364 bool debugAt(int level) const;
365
370 inline bool debugChained() const
371 { return m_chain != 0; }
372
377 inline void debugChain(const DebugEnabler* chain = 0)
378 { m_chain = (chain != this) ? chain : 0; }
379
384 void debugCopy(const DebugEnabler* original = 0);
385
386 protected:
391 inline void debugName(const char* name)
392 { m_name = name; }
393
394 private:
395 int m_level;
396 bool m_enabled;
397 const DebugEnabler* m_chain;
398 const char* m_name;
399 };
400
401 #if 0 /* for documentation generator */
402
407 void DDebug(int level, const char* format, ...);
408
414 void DDebug(const char* facility, int level, const char* format, ...);
415
421 void DDebug(const DebugEnabler* local, int level, const char* format, ...);
422
428 void XDebug(int level, const char* format, ...);
429
435 void XDebug(const char* facility, int level, const char* format, ...);
436
442 void XDebug(const DebugEnabler* local, int level, const char* format, ...);
443
449 void NDebug(int level, const char* format, ...);
450
456 void NDebug(const char* facility, int level, const char* format, ...);
457
463 void NDebug(const DebugEnabler* local, int level, const char* format, ...);
464 #endif
465
466 #if defined(_DEBUG) || defined(DEBUG) || defined(XDEBUG)
467 #undef DEBUG
468 #define DEBUG 1
469 #endif
470
471 #ifdef DEBUG
472 #define DDebug Debug
473 #else
474 #ifdef _WINDOWS
475 #define DDebug do { break; } while
476 #else
477 #define DDebug(arg...)
478 #endif
479 #endif
480
481 #ifdef XDEBUG
482 #define XDebug Debug
483 #else
484 #ifdef _WINDOWS
485 #define XDebug do { break; } while
486 #else
487 #define XDebug(arg...)
488 #endif
489 #endif
490
491 #ifndef NDEBUG
492 #define NDebug Debug
493 #else
494 #ifdef _WINDOWS
495 #define NDebug do { break; } while
496 #else
497 #define NDebug(arg...)
498 #endif
499 #endif
500
506 YATE_API void Debug(int level, const char* format, ...) FORMAT_CHECK(2);
507
514 YATE_API void Debug(const char* facility, int level, const char* format, ...) FORMAT_CHECK(3);
515
522 YATE_API void Debug(const DebugEnabler* local, int level, const char* format, ...) FORMAT_CHECK(3);
523
530 YATE_API void Alarm(const char* component, int level, const char* format, ...) FORMAT_CHECK(3);
531
538 YATE_API void Alarm(const DebugEnabler* component, int level, const char* format, ...) FORMAT_CHECK(3);
539
547 YATE_API void Alarm(const char* component, const char* info, int level, const char* format, ...) FORMAT_CHECK(4);
548
556 YATE_API void Alarm(const DebugEnabler* component, const char* info, int level, const char* format, ...) FORMAT_CHECK(4);
557
562 YATE_API void Output(const char* format, ...) FORMAT_CHECK(1);
563
570 class YATE_API Debugger
571 {
572 public:
576 enum Formatting {
577 None = 0,
578 Relative, // from program start
579 Absolute, // from EPOCH (1-1-1970)
580 Textual, // absolute GMT in YYYYMMDDhhmmss.uuuuuu format
581 TextLocal, // local time in YYYYMMDDhhmmss.uuuuuu format
582 TextSep, // absolute GMT in YYYY-MM-DD_hh:mm:ss.uuuuuu format
583 TextLSep, // local time in YYYY-MM-DD_hh:mm:ss.uuuuuu format
584 };
585
591 explicit Debugger(const char* name, const char* format = 0, ...);
592
599 Debugger(int level, const char* name, const char* format = 0, ...);
600
604 ~Debugger();
605
610 static void setOutput(void (*outFunc)(const char*,int) = 0);
611
616 static void setIntOut(void (*outFunc)(const char*,int) = 0);
617
622 static void setAlarmHook(void (*alarmFunc)(const char*,int,const char*,const char*) = 0);
623
628 static void setRelayHook(void (*relayFunc)(int,const char*,const char*,const char*) = 0);
629
635 static void enableOutput(bool enable = true, bool colorize = false);
636
641 static uint32_t getStartTimeSec();
642
647 static Formatting getFormatting();
648
654 static void setFormatting(Formatting format, uint32_t startTimeSec = 0);
655
662 static unsigned int formatTime(char* buf, Formatting format = getFormatting());
663
672 static void relayOutput(int level, char* buffer, const char* component = 0, const char* info = 0);
673
674 private:
675 const char* m_name;
676 int m_level;
677 };
678
683 struct TokenDict {
687 const char* token;
688
692 int value;
693 };
694
695 class String;
696 class DataBlock;
697 class Mutex;
698 class ObjList;
699 class NamedCounter;
700
701 #if 0 /* for documentation generator */
702
706 void YIGNORE(primitive value);
707
713 constant YSTRING(const char* string);
714
720 constant YATOM(const char* string);
721
727 void YCLASS(class type,class base);
728
735 void YCLASS2(class type,class base1,class base2);
736
744 void YCLASS3(class type,class base1,class base2,class base3);
745
751 void YCLASSIMP(class type,class base);
752
759 void YCLASSIMP2(class type,class base1,class base2);
760
768 void YCLASSIMP3(class type,class base1,class base2,class base3);
769
776 class* YOBJECT(class type,GenObject* pntr);
777
782 void YNOCOPY(class type);
783 #endif
784
785 #define YCLASS(type,base) \
786 public: virtual void* getObject(const String& name) const \
787 { return (name == YATOM(#type)) ? const_cast<type*>(this) : base::getObject(name); }
788
789 #define YCLASS2(type,base1,base2) \
790 public: virtual void* getObject(const String& name) const \
791 { if (name == YATOM(#type)) return const_cast<type*>(this); \
792 void* tmp = base1::getObject(name); \
793 return tmp ? tmp : base2::getObject(name); }
794
795 #define YCLASS3(type,base1,base2,base3) \
796 public: virtual void* getObject(const String& name) const \
797 { if (name == YATOM(#type)) return const_cast<type*>(this); \
798 void* tmp = base1::getObject(name); \
799 if (tmp) return tmp; \
800 tmp = base2::getObject(name); \
801 return tmp ? tmp : base3::getObject(name); }
802
803 #define YCLASSIMP(type,base) \
804 void* type::getObject(const String& name) const \
805 { return (name == YATOM(#type)) ? const_cast<type*>(this) : base::getObject(name); }
806
807 #define YCLASSIMP2(type,base1,base2) \
808 void* type::getObject(const String& name) const \
809 { if (name == YATOM(#type)) return const_cast<type*>(this); \
810 void* tmp = base1::getObject(name); \
811 return tmp ? tmp : base2::getObject(name); }
812
813 #define YCLASSIMP3(type,base1,base2,base3) \
814 void* type::getObject(const String& name) const \
815 { if (name == YATOM(#type)) return const_cast<type*>(this); \
816 void* tmp = base1::getObject(name); \
817 if (tmp) return tmp; \
818 tmp = base2::getObject(name); \
819 return tmp ? tmp : base3::getObject(name); }
820
821 #define YOBJECT(type,pntr) (static_cast<type*>(GenObject::getObject(YATOM(#type),pntr)))
822
823 #define YNOCOPY(type) private: \
824 type(const type&); \
825 void operator=(const type&)
826
827
831 class YATE_API GenObject
832 {
833 YNOCOPY(GenObject); // no automatic copies please
834 public:
838 GenObject();
839
843 virtual ~GenObject() { setObjCounter(0); }
844
851 virtual bool alive() const;
852
856 virtual void destruct();
857
864 virtual const String& toString() const;
865
871 virtual void* getObject(const String& name) const;
872
879 static inline void* getObject(const String& name, const GenObject* obj)
880 { return obj ? obj->getObject(name) : 0; }
881
886 static inline bool getObjCounting()
887 { return s_counting; }
888
893 static inline void setObjCounting(bool enable)
894 { s_counting = enable; }
895
900 inline NamedCounter* getObjCounter() const
901 { return m_counter; }
902
908 NamedCounter* setObjCounter(NamedCounter* counter);
909
916 static NamedCounter* getObjCounter(const String& name, bool create = true);
917
922 static ObjList& getObjCounters();
923
924 private:
925 NamedCounter* m_counter;
926 static bool s_counting;
927 };
928
934 inline void destruct(GenObject* obj)
935 { if (obj) obj->destruct(); }
936
943 template <class Obj> void destruct(Obj*& obj)
944 { if (obj) { obj->destruct(); obj = 0; } }
945
950 class YATE_API RefObject : public GenObject
951 {
952 YNOCOPY(RefObject); // no automatic copies please
953 public:
958 RefObject();
959
963 virtual ~RefObject();
964
970 virtual void* getObject(const String& name) const;
971
978 virtual bool alive() const;
979
984 bool ref();
985
994 bool deref();
995
1000 inline int refcount() const
1001 { return m_refcount; }
1002
1007 virtual void destruct();
1008
1014 inline static bool alive(const RefObject* obj)
1015 { return obj && (obj->refcount() > 0); }
1016
1022 static bool efficientIncDec();
1023
1024 protected:
1030 virtual void zeroRefs();
1031
1037 bool resurrect();
1038
1044 virtual void destroyed();
1045
1046 private:
1047 int m_refcount;
1048 Mutex* m_mutex;
1049 };
1050
1056 class YATE_API RefPointerBase
1057 {
1058 protected:
1062 inline RefPointerBase()
1063 : m_pointer(0) { }
1064
1071 void assign(RefObject* oldptr, RefObject* newptr, void* pointer);
1072
1076 void* m_pointer;
1077 };
1078
1082 template <class Obj = RefObject> class RefPointer : public RefPointerBase
1083 {
1084 protected:
1089 inline Obj* pointer() const
1090 { return static_cast<Obj*>(m_pointer); }
1091
1096 inline void assign(Obj* object = 0)
1097 { RefPointerBase::assign(pointer(),object,object); }
1098
1099 public:
1103 inline RefPointer()
1104 { }
1105
1110 inline RefPointer(const RefPointer<Obj>& value)
1111 : RefPointerBase()
1112 { assign(value); }
1113
1118 inline RefPointer(Obj* object)
1119 { assign(object); }
1120
1124 inline ~RefPointer()
1125 { assign(); }
1126
1130 inline RefPointer<Obj>& operator=(const RefPointer<Obj>& value)
1131 { assign(value.pointer()); return *this; }
1132
1136 inline RefPointer<Obj>& operator=(Obj* object)
1137 { assign(object); return *this; }
1138
1143 inline operator Obj*() const
1144 { return pointer(); }
1145
1149 inline Obj* operator->() const
1150 { return pointer(); }
1151
1155 inline Obj& operator*() const
1156 { return *pointer(); }
1157 };
1158
1162 template <class Obj = GenObject> class GenPointer : public GenObject
1163 {
1164 private:
1168 Obj* m_pointer;
1169
1170 public:
1174 inline GenPointer()
1175 : m_pointer(0)
1176 { }
1177
1182 inline GenPointer(const GenPointer<Obj>& value)
1183 : m_pointer(value)
1184 { }
1185
1190 inline GenPointer(Obj* object)
1191 : m_pointer(object)
1192 { }
1193
1197 inline GenPointer<Obj>& operator=(const GenPointer<Obj>& value)
1198 { m_pointer = value; return *this; }
1199
1203 inline GenPointer<Obj>& operator=(Obj* object)
1204 { m_pointer = object; return *this; }
1205
1210 inline operator Obj*() const
1211 { return m_pointer; }
1212
1216 inline Obj* operator->() const
1217 { return m_pointer; }
1218
1222 inline Obj& operator*() const
1223 { return *m_pointer; }
1224 };
1225
1230 class YATE_API ObjList : public GenObject
1231 {
1232 YNOCOPY(ObjList); // no automatic copies please
1233 public:
1237 ObjList();
1238
1242 virtual ~ObjList();
1243
1249 virtual void* getObject(const String& name) const;
1250
1255 unsigned int length() const;
1256
1261 unsigned int count() const;
1262
1267 inline GenObject* get() const
1268 { return m_obj; }
1269
1276 GenObject* set(const GenObject* obj, bool delold = true);
1277
1282 inline ObjList* next() const
1283 { return m_next; }
1284
1289 ObjList* last() const;
1290
1295 ObjList* skipNull() const;
1296
1301 ObjList* skipNext() const;
1302
1308 GenObject* at(int index) const;
1309
1315 ObjList* operator+(int index) const;
1316
1322 inline GenObject* operator[](signed int index) const
1323 { return at(index); }
1324
1330 inline GenObject* operator[](unsigned int index) const
1331 { return at(index); }
1332
1338 GenObject* operator[](const String& str) const;
1339
1345 ObjList* find(const GenObject* obj) const;
1346
1352 ObjList* find(const String& str) const;
1353
1359 int index(const GenObject* obj) const;
1360
1366 int index(const String& str) const;
1367
1374 ObjList* insert(const GenObject* obj, bool compact = true);
1375
1382 ObjList* append(const GenObject* obj, bool compact = true);
1383
1390 ObjList* setUnique(const GenObject* obj, bool compact = true);
1391
1397 GenObject* remove(bool delobj = true);
1398
1405 GenObject* remove(GenObject* obj, bool delobj = true);
1406
1413 GenObject* remove(const String& str, bool delobj = true);
1414
1418 void clear();
1419
1423 void compact();
1424
1429 inline bool autoDelete()
1430 { return m_delete; }
1431
1436 inline void setDelete(bool autodelete)
1437 { m_delete = autodelete; }
1438
1443 static const ObjList& empty();
1444
1457 void sort(int (*callbackCompare)(GenObject* obj1, GenObject* obj2, void* context), void* context = 0);
1458 private:
1459 ObjList* m_next;
1460 GenObject* m_obj;
1461 bool m_delete;
1462 };
1463
1468 class YATE_API ObjVector : public GenObject
1469 {
1470 YNOCOPY(ObjVector); // no automatic copies please
1471 public:
1476 inline explicit ObjVector(bool autodelete = true)
1477 : m_length(0), m_objects(0), m_delete(autodelete)
1478 { }
1479
1485 ObjVector(unsigned int maxLen, bool autodelete = true);
1486
1494 ObjVector(ObjList& list, bool move = true, unsigned int maxLen = 0, bool autodelete = true);
1495
1499 virtual ~ObjVector();
1500
1506 virtual void* getObject(const String& name) const;
1507
1512 inline unsigned int length() const
1513 { return m_length; }
1514
1519 unsigned int count() const;
1520
1525 bool null() const;
1526
1532 inline GenObject* at(int index) const
1533 { return (index >= 0 && index < (int)m_length) ? m_objects[index] : 0; }
1534
1540 inline GenObject* operator[](signed int index) const
1541 { return at(index); }
1542
1548 inline GenObject* operator[](unsigned int index) const
1549 { return at(index); }
1550
1558 unsigned int assign(ObjList& list, bool move = true, unsigned int maxLen = 0);
1559
1565 GenObject* take(unsigned int index);
1566
1573 bool set(GenObject* obj, unsigned int index);
1574
1580 int index(const GenObject* obj) const;
1581
1587 int index(const String& str) const;
1588
1592 void clear();
1593
1598 inline bool autoDelete()
1599 { return m_delete; }
1600
1605 inline void setDelete(bool autodelete)
1606 { m_delete = autodelete; }
1607
1608 private:
1609 unsigned int m_length;
1610 GenObject** m_objects;
1611 bool m_delete;
1612 };
1613
1622 class YATE_API Array : public RefObject
1623 {
1624 public:
1630 explicit Array(int columns = 0, int rows = 0);
1631
1635 virtual ~Array();
1636
1642 virtual void* getObject(const String& name) const;
1643
1650 bool addRow(ObjList* row = 0, int index = -1);
1651
1658 bool addColumn(ObjList* column = 0, int index = -1);
1659
1665 bool delRow(int index);
1666
1672 bool delColumn(int index);
1673
1680 GenObject* get(int column, int row) const;
1681
1688 GenObject* take(int column, int row);
1689
1697 bool set(GenObject* obj, int column, int row);
1698
1703 inline int getRows() const
1704 { return m_rows; }
1705
1710 inline int getColumns() const
1711 { return m_columns; }
1712
1720 inline ObjList* getColumn(int column) const {
1721 if (column >= 0 || column < m_columns)
1722 return static_cast<ObjList*>(m_obj[column]);
1723 return 0;
1724 }
1725
1726 private:
1727 int m_rows;
1728 int m_columns;
1729 ObjList m_obj;
1730 };
1731
1732 class Regexp;
1733 class StringMatchPrivate;
1734
1739 class YATE_API UChar
1740 {
1741 public:
1742 enum Endianness {
1743 LE = 0,
1744 BE = 1,
1745 Native = 2,
1746 };
1751 inline explicit UChar(uint32_t code = 0)
1752 : m_chr(code)
1753 { encode(); }
1754
1759 inline explicit UChar(int32_t code)
1760 : m_chr((code < 0) ? 0 : code)
1761 { encode(); }
1762
1767 inline explicit UChar(signed char code)
1768 : m_chr((unsigned char)code)
1769 { encode(); }
1770
1775 inline explicit UChar(unsigned char code)
1776 : m_chr(code)
1777 { encode(); }
1778
1784 inline UChar& operator=(uint32_t code)
1785 { m_chr = code; encode(); return *this; }
1786
1792 inline UChar& operator=(char code)
1793 { m_chr = (unsigned char)code; encode(); return *this; }
1794
1799 inline uint32_t code() const
1800 { return m_chr; }
1801
1806 inline const char* c_str() const
1807 { return m_str; }
1808
1813 inline operator const char*() const
1814 { return m_str; };
1815
1823 bool decode(const char*& str, uint32_t maxChar = 0x10ffff, bool overlong = false);
1824
1833 bool decode(uint16_t*& buff, unsigned int& len, Endianness order, uint32_t maxChar = 0x10ffff);
1834
1842 bool decode(DataBlock& buff, Endianness order, uint32_t maxChar = 0x10ffff);
1843
1851 bool encode(uint16_t*& buff, unsigned int& len, Endianness order);
1852
1859 bool encode(DataBlock& buff, Endianness order);
1860
1871 static bool decode(String& out, uint16_t*& buff, unsigned int& len, Endianness order, bool checkBOM = false, uint32_t maxChar = 0x10ffff);
1872
1881 static bool encode(DataBlock& out, const char*& str, Endianness order, bool addBOM = false);
1882
1892 static bool encode(uint16_t*& buff, unsigned int& len, const char*& str, Endianness order, bool addBOM = false);
1893
1894 private:
1895 void encode();
1896 uint32_t m_chr;
1897 char m_str[8];
1898 };
1899
1907 class YATE_API String : public GenObject
1908 {
1909 public:
1910 enum Align {
1911 Left = 0,
1912 Center,
1913 Right
1914 };
1915
1919 String();
1920
1926 String(const char* value, int len = -1);
1927
1933 explicit String(char value, unsigned int repeat = 1);
1934
1939 explicit String(int32_t value);
1940
1945 explicit String(uint32_t value);
1946
1951 explicit String(int64_t value);
1952
1957 explicit String(uint64_t value);
1958
1963 explicit String(bool value);
1964
1969 explicit String(double value);
1970
1975 String(const String& value);
1976
1981 String(const String* value);
1982
1986 virtual ~String();
1987
1993 virtual void* getObject(const String& name) const;
1994
1999 static const String& empty();
2000
2006 inline static const char* boolText(bool value)
2007 { return value ? "true" : "false"; }
2008
2013 inline const char* c_str() const
2014 { return m_string; }
2015
2020 inline const char* safe() const
2021 { return m_string ? m_string : ""; }
2022
2028 inline const char* safe(const char* defStr) const
2029 { return m_string ? m_string : (defStr ? defStr : ""); }
2030
2035 inline unsigned int length() const
2036 { return m_length; }
2037
2042 inline bool null() const
2043 { return !m_string; }
2044
2052 static int lenUtf8(const char* value, uint32_t maxChar = 0x10ffff, bool overlong = false);
2053
2060 inline int lenUtf8(uint32_t maxChar = 0x10ffff, bool overlong = false) const
2061 { return lenUtf8(m_string,maxChar,overlong); }
2062
2063
2071 int fixUtf8(const char* replace = 0, uint32_t maxChar = 0x10ffff, bool overlong = false);
2072
2078 inline static bool checkBOM(const char* str)
2079 { return str && (str[0] == '\357') && (str[1] == '\273') && (str[2] == '\277'); }
2080
2085 inline bool checkBOM() const
2086 { return checkBOM(c_str()); }
2087
2093 inline static bool stripBOM(const char*& str)
2094 { return checkBOM(str) && (str += 3); }
2095
2101 inline static bool stripBOM(char*& str)
2102 { return checkBOM(str) && (str += 3); }
2103
2108 inline bool stripBOM()
2109 { return checkBOM(c_str()) && &(*this = c_str() + 3); }
2110
2115 inline unsigned int hash() const
2116 {
2117 if (m_hash == YSTRING_INIT_HASH)
2118 m_hash = hash(m_string);
2119 return m_hash;
2120 }
2121
2128 static unsigned int hash(const char* value, unsigned int h = 0);
2129
2133 void clear();
2134
2140 char at(int index) const;
2141
2148 String substr(int offs, int len = -1) const;
2149
2153 String& trimBlanks();
2154
2159 String& trimSpaces();
2160
2165 virtual const String& toString() const;
2166
2177 int toInteger(int defvalue = 0, int base = 0, int minvalue = INT_MIN,
2178 int maxvalue = INT_MAX, bool clamp = true) const;
2179
2187 int toInteger(const TokenDict* tokens, int defvalue = 0, int base = 0) const;
2188
2199 long int toLong(long int defvalue = 0, int base = 0, long int minvalue = LONG_MIN,
2200 long int maxvalue = LONG_MAX, bool clamp = true) const;
2201
2212 int64_t toInt64(int64_t defvalue = 0, int base = 0, int64_t minvalue = LLONG_MIN,
2213 int64_t maxvalue = LLONG_MAX, bool clamp = true) const;
2214
2220 double toDouble(double defvalue = 0.0) const;
2221
2227 bool toBoolean(bool defvalue = false) const;
2228
2233 bool isBoolean() const;
2234
2239 String& toUpper();
2240
2245 String& toLower();
2246
2252 inline char operator[](signed int index) const
2253 { return at(index); }
2254
2260 inline char operator[](unsigned int index) const
2261 { return at(index); }
2262
2267 inline operator const char*() const
2268 { return m_string; };
2269
2276 String& assign(const char* value, int len = -1);
2277
2284 String& assign(char value, unsigned int repeat = 1);
2285
2294 String& hexify(void* data, unsigned int len, char sep = 0, bool upCase = false);
2295
2300 inline String& operator=(const String& value)
2301 { return operator=(value.c_str()); }
2302
2308 inline String& operator=(const String* value)
2309 { return operator=(value ? value->c_str() : ""); }
2310
2316 String& operator=(const char* value);
2317
2322 String& operator=(char value);
2323
2328 String& operator=(int32_t value);
2329
2334 String& operator=(uint32_t value);
2335
2340 String& operator=(int64_t value);
2341
2346 String& operator=(uint64_t value);
2347
2352 inline String& operator=(bool value)
2353 { return operator=(boolText(value)); }
2354
2359 String& operator=(double value);
2360
2366 inline String& operator+=(const char* value)
2367 { return append(value,-1); }
2368
2373 String& operator+=(char value);
2374
2379 String& operator+=(int32_t value);
2380
2385 String& operator+=(uint32_t value);
2386
2391 String& operator+=(int64_t value);
2392
2397 String& operator+=(uint64_t value);
2398
2403 inline String& operator+=(bool value)
2404 { return operator+=(boolText(value)); }
2405
2410 String& operator+=(double value);
2411
2415 bool operator==(const char* value) const;
2416
2420 bool operator!=(const char* value) const;
2421
2425 inline bool operator==(const String& value) const
2426 { return (this == &value) || ((hash() == value.hash()) && operator==(value.c_str())); }
2427
2431 inline bool operator!=(const String& value) const
2432 { return (this != &value) && ((hash() != value.hash()) || operator!=(value.c_str())); }
2433
2437 bool operator&=(const char* value) const;
2438
2442 bool operator|=(const char* value) const;
2443
2447 inline String& operator<<(const char* value)
2448 { return operator+=(value); }
2449
2453 inline String& operator<<(char value)
2454 { return operator+=(value); }
2455
2459 inline String& operator<<(int32_t value)
2460 { return operator+=(value); }
2461
2465 inline String& operator<<(uint32_t value)
2466 { return operator+=(value); }
2467
2471 inline String& operator<<(int64_t value)
2472 { return operator+=(value); }
2473
2477 inline String& operator<<(uint64_t value)
2478 { return operator+=(value); }
2479
2483 inline String& operator<<(bool value)
2484 { return operator+=(value); }
2485
2489 inline String& operator<<(double value)
2490 { return operator+=(value); }
2491
2496 String& operator>>(const char* skip);
2497
2501 String& operator>>(char& store);
2502
2506 String& operator>>(UChar& store);
2507
2511 String& operator>>(int& store);
2512
2516 String& operator>>(unsigned int& store);
2517
2521 String& operator>>(bool& store);
2522
2529 String& append(const char* value, int len);
2530
2537 String& append(const char* value, const char* separator = 0, bool force = false);
2538
2545 String& append(const ObjList* list, const char* separator = 0, bool force = false);
2546
2553 inline String& append(const ObjList& list, const char* separator = 0, bool force = false)
2554 { return append(&list,separator,force); }
2555
2561 String& append(double value, unsigned int decimals = 3);
2562
2568 String& printf(const char* format, ...) FORMAT_CHECK(2);
2569
2575 String& printf(unsigned int length, const char* format, ...) FORMAT_CHECK(3);
2576
2585 String& appendFixed(unsigned int fixedLength, const char* str, unsigned int len = -1, char fill = ' ', int align = Left);
2586
2594 inline String& appendFixed(unsigned int fixedLength, const String& str, char fill = ' ', int align = Left)
2595 { return appendFixed(fixedLength,str.c_str(),str.length(),fill,align); }
2596
2603 int find(char what, unsigned int offs = 0) const;
2604
2611 int find(const char* what, unsigned int offs = 0) const;
2612
2618 int rfind(char what) const;
2619
2625 int rfind(const char* what) const;
2626
2634 bool startsWith(const char* what, bool wordBreak = false, bool caseInsensitive = false) const;
2635
2643 bool endsWith(const char* what, bool wordBreak = false, bool caseInsensitive = false) const;
2644
2656 bool startSkip(const char* what, bool wordBreak = true, bool caseInsensitive = false);
2657
2664 String& extractTo(const char* sep, String& store);
2665
2672 String& extractTo(const char* sep, bool& store);
2673
2681 String& extractTo(const char* sep, int& store, int base = 0);
2682
2691 String& extractTo(const char* sep, int& store, const TokenDict* tokens, int base = 0);
2692
2699 String& extractTo(const char* sep, double& store);
2700
2706 virtual bool matches(const String& value) const
2707 { return operator==(value); }
2708
2714 bool matches(const Regexp& rexp);
2715
2721 int matchOffset(int index = 0) const;
2722
2728 int matchLength(int index = 0) const;
2729
2735 inline String matchString(int index = 0) const
2736 { return substr(matchOffset(index),matchLength(index)); }
2737
2743 String replaceMatches(const String& templ) const;
2744
2749 int matchCount() const;
2750
2757 ObjList* split(char separator, bool emptyOK = true) const;
2758
2765 static String msgEscape(const char* str, char extraEsc = 0);
2766
2772 inline String msgEscape(char extraEsc = 0) const
2773 { return msgEscape(c_str(),extraEsc); }
2774
2782 static String msgUnescape(const char* str, int* errptr = 0, char extraEsc = 0);
2783
2790 inline String msgUnescape(int* errptr = 0, char extraEsc = 0) const
2791 { return msgUnescape(c_str(),errptr,extraEsc); }
2792
2799 static String sqlEscape(const char* str, char extraEsc = 0);
2800
2806 inline String sqlEscape(char extraEsc = 0) const
2807 { return sqlEscape(c_str(),extraEsc); }
2808
2816 static String uriEscape(const char* str, char extraEsc = 0, const char* noEsc = 0);
2817
2825 static String uriEscape(const char* str, const char* extraEsc, const char* noEsc = 0);
2826
2833 inline String uriEscape(char extraEsc = 0, const char* noEsc = 0) const
2834 { return uriEscape(c_str(),extraEsc,noEsc); }
2835
2842 static String uriUnescape(const char* str, int* errptr = 0);
2843
2849 inline String uriUnescape(int* errptr = 0) const
2850 { return uriUnescape(c_str(),errptr); }
2851
2858 static const String* atom(const String*& str, const char* val);
2859
2860 protected:
2864 virtual void changed();
2865
2866 private:
2867 void clearMatches();
2868 char* m_string;
2869 unsigned int m_length;
2870 // I hope every C++ compiler now knows about mutable...
2871 mutable unsigned int m_hash;
2872 StringMatchPrivate* m_matches;
2873 };
2874
2880 inline const char* c_str(const String* str)
2881 { return str ? str->c_str() : (const char*)0; }
2882
2888 inline const char* c_safe(const char* str)
2889 { return str ? str : ""; }
2890
2896 inline const char* c_safe(const String* str)
2897 { return str ? str->safe() : ""; }
2898
2904 inline bool null(const char* str)
2905 { return !(str && *str); }
2906
2912 inline bool null(const String* str)
2913 { return !str || str->null(); }
2914
2918 YATE_API String operator+(const String& s1, const String& s2);
2919
2923 YATE_API String operator+(const String& s1, const char* s2);
2924
2928 YATE_API String operator+(const char* s1, const String& s2);
2929
2934 inline const char *strcpy(String& dest, const char* src)
2935 { dest = src; return dest.c_str(); }
2936
2941 inline const char *strcat(String& dest, const char* src)
2942 { dest += src; return dest.c_str(); }
2943
2952 YATE_API int lookup(const char* str, const TokenDict* tokens, int defvalue = 0, int base = 0);
2953
2960 YATE_API const char* lookup(int value, const TokenDict* tokens, const char* defvalue = 0);
2961
2962 class NamedList;
2963
2971 YATE_API bool controlReturn(NamedList* params, bool ret, const char* retVal = 0);
2972
2977 class YATE_API Regexp : public String
2978 {
2979 friend class String;
2980 public:
2984 Regexp();
2985
2992 explicit Regexp(const char* value, bool extended = false, bool insensitive = false);
2993
2998 Regexp(const Regexp& value);
2999
3003 virtual ~Regexp();
3004
3008 inline Regexp& operator=(const char* value)
3009 { String::operator=(value); return *this; }
3010
3015 inline bool compile() const
3016 { return m_regexp || (m_compile && doCompile()); }
3017
3023 bool matches(const char* value) const;
3024
3030 virtual bool matches(const String& value) const
3031 { return Regexp::matches(value.safe()); }
3032
3038 void setFlags(bool extended, bool insensitive);
3039
3044 bool isExtended() const;
3045
3050 bool isCaseInsensitive() const;
3051
3052 protected:
3056 virtual void changed();
3057
3062 bool doCompile() const;
3063
3064 private:
3065 void cleanup();
3066 bool matches(const char* value, StringMatchPrivate* matchlist) const;
3067 mutable void* m_regexp;
3068 mutable bool m_compile;
3069 int m_flags;
3070 };
3071
3076 class Atom
3077 {
3078 public:
3083 inline explicit Atom(const char* value)
3084 : m_atom(0)
3085 { String::atom(m_atom,value); }
3086
3091 inline operator const String&() const
3092 { return *m_atom; }
3093
3098 inline const String* operator->() const
3099 { return m_atom; }
3100
3101 private:
3102 const String* m_atom;
3103 };
3104
3109 class YATE_API CapturedEvent : public String
3110 {
3111 friend class Engine;
3112 YCLASS(CapturedEvent,String)
3113 public:
3119 inline CapturedEvent(int level, const char* text)
3120 : String(text), m_level(level)
3121 { }
3122
3127 inline CapturedEvent(const CapturedEvent& original)
3128 : String(original), m_level(original.level())
3129 { }
3130
3135 inline int level() const
3136 { return m_level; }
3137
3138
3143 inline static bool capturing()
3144 { return s_capturing; }
3145
3150 inline static const ObjList& events()
3151 { return s_events; }
3152
3158 inline static void append(int level, const char* text)
3159 { if (text && *text) s_events.append(new CapturedEvent(level,text)); }
3160
3161 protected:
3166 inline static ObjList& eventsRw()
3167 { return s_events; }
3168
3173 inline static void capturing(bool capture)
3174 { s_capturing = capture; }
3175
3176 private:
3177 int m_level;
3178 static ObjList s_events;
3179 static bool s_capturing;
3180 };
3181
3186 class YATE_API NamedString : public String
3187 {
3188 YNOCOPY(NamedString); // no automatic copies please
3189 public:
3195 explicit NamedString(const char* name, const char* value = 0);
3196
3201 inline const String& name() const
3202 { return m_name; }
3203
3208 virtual const String& toString() const;
3209
3215 virtual void* getObject(const String& name) const;
3216
3220 inline NamedString& operator=(const char* value)
3221 { String::operator=(value); return *this; }
3222
3223 private:
3224 NamedString(); // no default constructor please
3225 String m_name;
3226 };
3227
3234 class YATE_API NamedPointer : public NamedString
3235 {
3236 public:
3243 explicit NamedPointer(const char* name, GenObject* data = 0, const char* value = 0);
3244
3248 virtual ~NamedPointer();
3249
3254 inline GenObject* userData() const
3255 { return m_data; }
3256
3262 GenObject* takeData();
3263
3269 void userData(GenObject* data);
3270
3276 inline void* userObject(const String& name) const
3277 { return m_data ? m_data->getObject(name) : 0; }
3278
3282 inline NamedPointer& operator=(const char* value)
3283 { NamedString::operator=(value); return *this; }
3284
3290 virtual void* getObject(const String& name) const;
3291
3292 protected:
3296 virtual void changed();
3297
3298 private:
3299 NamedPointer(); // no default constructor please
3300 GenObject* m_data;
3301 };
3302
3307 class YATE_API NamedCounter : public String
3308 {
3309 YNOCOPY(NamedCounter); // no automatic copies please
3310 public:
3315 explicit NamedCounter(const String& name);
3316
3321 inline bool enabled() const
3322 { return m_enabled; }
3323
3328 inline void enable(bool val)
3329 { m_enabled = val; }
3330
3335 int inc();
3336
3341 int dec();
3342
3347 inline int count() const
3348 { return m_count; }
3349
3350 private:
3351 int m_count;
3352 bool m_enabled;
3353 Mutex* m_mutex;
3354 };
3355
3363 class YATE_API HashList : public GenObject
3364 {
3365 YNOCOPY(HashList); // no automatic copies please
3366 public:
3371 explicit HashList(unsigned int size = 17);
3372
3376 virtual ~HashList();
3377
3383 virtual void* getObject(const String& name) const;
3384
3389 inline unsigned int length() const
3390 { return m_size; }
3391
3396 unsigned int count() const;
3397
3404 inline ObjList* getList(unsigned int index) const
3405 { return (index < m_size) ? m_lists[index] : 0; }
3406
3412 inline ObjList* getHashList(unsigned int hash) const
3413 { return getList(hash % m_size); }
3414
3420 inline ObjList* getHashList(const String& str) const
3421 { return getHashList(str.hash()); }
3422
3428 GenObject* operator[](const String& str) const;
3429
3436 ObjList* find(const GenObject* obj) const;
3437
3444 ObjList* find(const GenObject* obj, unsigned int hash) const;
3445
3451 ObjList* find(const String& str) const;
3452
3458 ObjList* append(const GenObject* obj);
3459
3467 GenObject* remove(GenObject* obj, bool delobj = true, bool useHash = false);
3468
3475 inline GenObject* remove(const String& str, bool delobj = true)
3476 {
3477 ObjList* n = find(str);
3478 return n ? n->remove(delobj) : 0;
3479 }
3480
3484 void clear();
3485
3492 bool resync(GenObject* obj);
3493
3499 bool resync();
3500
3501 private:
3502 unsigned int m_size;
3503 ObjList** m_lists;
3504 };
3505
3512 class YATE_API ListIterator
3513 {
3514 YNOCOPY(ListIterator); // no automatic copies please
3515 public:
3522 ListIterator(ObjList& list, int offset = 0);
3523
3530 ListIterator(HashList& list, int offset = 0);
3531
3535 ~ListIterator();
3536
3541 inline unsigned int length() const
3542 { return m_length; }
3543
3547 void clear();
3548
3554 void assign(ObjList& list, int offset = 0);
3555
3561 void assign(HashList& list, int offset = 0);
3562
3569 GenObject* get(unsigned int index) const;
3570
3583 GenObject* get();
3584
3589 inline bool eof() const
3590 { return m_current >= m_length; }
3591
3595 inline void reset()
3596 { m_current = 0; }
3597
3598 private:
3599 ObjList* m_objList;
3600 HashList* m_hashList;
3601 GenObject** m_objects;
3602 unsigned int* m_hashes;
3603 unsigned int m_length;
3604 unsigned int m_current;
3605 };
3606
3611 class YATE_API Time
3612 {
3613 public:
3617 inline Time()
3618 : m_time(now())
3619 { }
3620
3625 inline Time(u_int64_t usec)
3626 : m_time(usec)
3627 { }
3628
3633 inline explicit Time(const struct timeval* tv)
3634 : m_time(fromTimeval(tv))
3635 { }
3636
3641 inline explicit Time(const struct timeval& tv)
3642 : m_time(fromTimeval(tv))
3643 { }
3644
3649 inline ~Time()
3650 { }
3651
3656 inline u_int32_t sec() const
3657 { return (u_int32_t)((m_time+500000) / 1000000); }
3658
3663 inline u_int64_t msec() const
3664 { return (m_time+500) / 1000; }
3665
3670 inline u_int64_t usec() const
3671 { return m_time; }
3672
3676 inline operator u_int64_t() const
3677 { return m_time; }
3678
3682 inline Time& operator=(u_int64_t usec)
3683 { m_time = usec; return *this; }
3684
3688 inline Time& operator+=(int64_t delta)
3689 { m_time += delta; return *this; }
3690
3694 inline Time& operator-=(int64_t delta)
3695 { m_time -= delta; return *this; }
3696
3701 inline void toTimeval(struct timeval* tv) const
3702 { toTimeval(tv, m_time); }
3703
3709 static void toTimeval(struct timeval* tv, u_int64_t usec);
3710
3716 static u_int64_t fromTimeval(const struct timeval* tv);
3717
3723 inline static u_int64_t fromTimeval(const struct timeval& tv)
3724 { return fromTimeval(&tv); }
3725
3730 static u_int64_t now();
3731
3736 static u_int64_t msecNow();
3737
3742 static u_int32_t secNow();
3743
3757 static unsigned int toEpoch(int year, unsigned int month, unsigned int day,
3758 unsigned int hour, unsigned int minute, unsigned int sec, int offset = 0);
3759
3772 static bool toDateTime(unsigned int epochTimeSec, int& year, unsigned int& month,
3773 unsigned int& day, unsigned int& hour, unsigned int& minute, unsigned int& sec,
3774 unsigned int* wDay = 0);
3775
3781 static inline bool isLeap(unsigned int year)
3782 { return (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)); }
3783
3788 static int timeZone();
3789
3790 private:
3791 u_int64_t m_time;
3792 };
3793
3798 class YATE_API Random
3799 {
3800 public:
3805 inline Random(u_int32_t seed = Time::now() & 0xffffffff)
3806 : m_random(seed)
3807 { }
3808
3813 inline u_int32_t get() const
3814 { return m_random; }
3815
3820 inline void set(u_int32_t seed)
3821 { m_random = seed; }
3822
3827 u_int32_t next();
3828
3833 static long int random();
3834
3839 static void srandom(unsigned int seed);
3840
3841 private:
3842 u_int32_t m_random;
3843 };
3844
3849 class YATE_API DataBlock : public GenObject
3850 {
3851 public:
3852
3857 DataBlock(unsigned int overAlloc = 0);
3858
3863 DataBlock(const DataBlock& value);
3864
3870 DataBlock(const DataBlock& value, unsigned int overAlloc);
3871
3879 DataBlock(void* value, unsigned int len, bool copyData = true, unsigned int overAlloc = 0);
3880
3884 virtual ~DataBlock();
3885
3891 virtual void* getObject(const String& name) const;
3892
3896 static const DataBlock& empty();
3897
3902 inline void* data() const
3903 { return m_data; }
3904
3911 inline unsigned char* data(unsigned int offs, unsigned int len = 1) const
3912 { return (offs + len <= m_length) ? (static_cast<unsigned char*>(m_data) + offs) : 0; }
3913
3920 inline int at(unsigned int offs, int defvalue = -1) const
3921 { return (offs < m_length) ? static_cast<unsigned char*>(m_data)[offs] : defvalue; }
3922
3927 inline bool null() const
3928 { return !m_data; }
3929
3934 inline unsigned int length() const
3935 { return m_length; }
3936
3941 inline unsigned int overAlloc() const
3942 { return m_overAlloc; }
3943
3948 inline void overAlloc(unsigned int bytes)
3949 { m_overAlloc = bytes; }
3950
3955 void clear(bool deleteData = true);
3956
3964 DataBlock& assign(void* value, unsigned int len, bool copyData = true, unsigned int allocated = 0);
3965
3971 inline void append(void* value, unsigned int len) {
3972 DataBlock tmp(value,len,false);
3973 append(tmp);
3974 tmp.clear(false);
3975 }
3976
3981 void append(const DataBlock& value);
3982
3987 void append(const String& value);
3988
3993 void insert(const DataBlock& value);
3994
3999 inline void resize(unsigned int len) {
4000 if (len != length())
4001 assign(0,len);
4002 }
4003
4008 void truncate(unsigned int len);
4009
4014 void cut(int len);
4015
4021 inline int operator[](signed int index) const
4022 { return at(index); }
4023
4029 inline int operator[](unsigned int index) const
4030 { return at(index); }
4031
4035 DataBlock& operator=(const DataBlock& value);
4036
4040 inline DataBlock& operator+=(const DataBlock& value)
4041 { append(value); return *this; }
4042
4046 inline DataBlock& operator+=(const String& value)
4047 { append(value); return *this; }
4048
4057 bool convert(const DataBlock& src, const String& sFormat,
4058 const String& dFormat, unsigned maxlen = 0);
4059
4070 bool unHexify(const char* data, unsigned int len, char sep);
4071
4081 bool unHexify(const char* data, unsigned int len);
4082
4089 inline bool unHexify(const String& data)
4090 { return unHexify(data.c_str(),data.length()); }
4091
4097 String sqlEscape(char extraEsc) const;
4098
4099 private:
4100 unsigned int allocLen(unsigned int len) const;
4101 void* m_data;
4102 unsigned int m_length;
4103 unsigned int m_allocated;
4104 unsigned int m_overAlloc;
4105 };
4106
4111 class YATE_API Hasher
4112 {
4113 public:
4117 virtual ~Hasher();
4118
4122 virtual void clear() = 0;
4123
4128 virtual void finalize() = 0;
4129
4135 virtual const unsigned char* rawDigest() = 0;
4136
4142 inline const String& hexDigest()
4143 { finalize(); return m_hex; }
4144
4151 inline bool update(const void* buf, unsigned int len)
4152 { return updateInternal(buf,len); }
4153
4159 inline bool update(const DataBlock& data)
4160 { return updateInternal(data.data(), data.length()); }
4161
4167 inline bool update(const String& str)
4168 { return updateInternal(str.c_str(), str.length()); }
4169
4174 inline Hasher& operator<<(const String& value)
4175 { update(value); return *this; }
4176
4181 inline Hasher& operator<<(const DataBlock& data)
4182 { update(data); return *this; }
4183
4188 Hasher& operator<<(const char* value);
4189
4197 bool hmacStart(DataBlock& opad, const void* key, unsigned int keyLen);
4198
4205 inline bool hmacStart(DataBlock& opad, const DataBlock& key)
4206 { return hmacStart(opad,key.data(),key.length()); }
4207
4214 inline bool hmacStart(DataBlock& opad, const String& key)
4215 { return hmacStart(opad,key.c_str(),key.length()); }
4216
4222 bool hmacFinal(const DataBlock& opad);
4223
4232 bool hmac(const void* key, unsigned int keyLen, const void* msg, unsigned int msgLen);
4233
4240 inline bool hmac(const DataBlock& key, const DataBlock& msg)
4241 { return hmac(key.data(),key.length(),msg.data(),msg.length()); }
4242
4249 inline bool hmac(const String& key, const String& msg)
4250 { return hmac(key.c_str(),key.length(),msg.c_str(),msg.length()); }
4251
4256 virtual unsigned int hashLength() const = 0;
4257
4262 virtual unsigned int hmacBlockSize() const;
4263
4264 protected:
4268 inline Hasher()
4269 : m_private(0)
4270 { }
4271
4278 virtual bool updateInternal(const void* buf, unsigned int len) = 0;
4279
4280 void* m_private;
4281 String m_hex;
4282 };
4283
4288 class YATE_API MD5 : public Hasher
4289 {
4290 public:
4294 MD5();
4295
4300 MD5(const MD5& original);
4301
4307 MD5(const void* buf, unsigned int len);
4308
4313 MD5(const DataBlock& data);
4314
4319 MD5(const String& str);
4320
4324 MD5& operator=(const MD5& original);
4325
4329 virtual ~MD5();
4330
4334 virtual void clear();
4335
4340 virtual void finalize();
4341
4347 virtual const unsigned char* rawDigest();
4348
4353 inline static unsigned int rawLength()
4354 { return 16; }
4355
4360 virtual unsigned int hashLength() const
4361 { return 16; }
4362
4363 protected:
4364 bool updateInternal(const void* buf, unsigned int len);
4365
4366 private:
4367 void init();
4368 unsigned char m_bin[16];
4369 };
4370
4375 class YATE_API SHA1 : public Hasher
4376 {
4377 public:
4381 SHA1();
4382
4387 SHA1(const SHA1& original);
4388
4394 SHA1(const void* buf, unsigned int len);
4395
4400 SHA1(const DataBlock& data);
4401
4406 SHA1(const String& str);
4407
4411 SHA1& operator=(const SHA1& original);
4412
4416 virtual ~SHA1();
4417
4421 virtual void clear();
4422
4427 virtual void finalize();
4428
4434 virtual const unsigned char* rawDigest();
4435
4440 inline static unsigned int rawLength()
4441 { return 20; }
4442
4447 virtual unsigned int hashLength() const
4448 { return 20; }
4449
4458 static bool fips186prf(DataBlock& out, const DataBlock& seed, unsigned int len);
4459
4460 protected:
4461 bool updateInternal(const void* buf, unsigned int len);
4462
4463 private:
4464 void init();
4465 unsigned char m_bin[20];
4466 };
4467
4472 class YATE_API SHA256 : public Hasher
4473 {
4474 public:
4478 SHA256();
4479
4484 SHA256(const SHA256& original);
4485
4491 SHA256(const void* buf, unsigned int len);
4492
4497 SHA256(const DataBlock& data);
4498
4503 SHA256(const String& str);
4504
4508 SHA256& operator=(const SHA256& original);
4509
4513 virtual ~SHA256();
4514
4518 virtual void clear();
4519
4524 virtual void finalize();
4525
4531 virtual const unsigned char* rawDigest();
4532
4537 inline static unsigned int rawLength()
4538 { return 32; }
4539
4544 virtual unsigned int hashLength() const
4545 { return 32; }
4546
4547 protected:
4548 bool updateInternal(const void* buf, unsigned int len);
4549
4550 private:
4551 void init();
4552 unsigned char m_bin[32];
4553 };
4554
4559 class YATE_API Base64 : public DataBlock
4560 {
4561 YNOCOPY(Base64); // no automatic copies please
4562 public:
4566 inline Base64()
4567 { }
4568
4575 inline Base64(void* src, unsigned int len, bool copyData = true)
4576 : DataBlock(src,len,copyData)
4577 { }
4578
4588 void encode(String& dest, unsigned int lineLen = 0, bool lineAtEnd = false);
4589
4601 bool decode(DataBlock& dest, bool liberal = true);
4602
4606 inline Base64& operator<<(const String& value)
4607 { append(value); return *this; }
4608
4612 inline Base64& operator<<(const DataBlock& data)
4613 { append(data); return *this; }
4614
4618 inline Base64& operator<<(const char* value)
4619 { return operator<<(String(value)); }
4620 };
4621
4622 class NamedIterator;
4623
4628 class YATE_API NamedList : public String
4629 {
4630 friend class NamedIterator;
4631 public:
4636 explicit NamedList(const char* name);
4637
4642 NamedList(const NamedList& original);
4643
4650 NamedList(const char* name, const NamedList& original, const String& prefix);
4651
4657 NamedList& operator=(const NamedList& value);
4658
4664 virtual void* getObject(const String& name) const;
4665
4670 inline unsigned int length() const
4671 { return m_params.length(); }
4672
4677 inline unsigned int count() const
4678 { return m_params.count(); }
4679
4683 inline void clearParams()
4684 { m_params.clear(); }
4685
4691 NamedList& addParam(NamedString* param);
4692
4700 NamedList& addParam(const char* name, const char* value, bool emptyOK = true);
4701
4707 inline NamedList& setParam(NamedString* param)
4708 {
4709 if (param)
4710 m_params.setUnique(param);
4711 return *this;
4712 }
4713
4720 NamedList& setParam(const String& name, const char* value);
4721
4728 NamedList& clearParam(const String& name, char childSep = 0);
4729
4736 NamedList& clearParam(NamedString* param, bool delParam = true);
4737
4745 NamedList& copyParam(const NamedList& original, const String& name, char childSep = 0);
4746
4752 NamedList& copyParams(const NamedList& original);
4753
4761 NamedList& copyParams(const NamedList& original, ObjList* list, char childSep = 0);
4762
4770 NamedList& copyParams(const NamedList& original, const String& list, char childSep = 0);
4771
4780 NamedList& copySubParams(const NamedList& original, const String& prefix,
4781 bool skipPrefix = true, bool replace = false);
4782
4788 bool hasSubParams(const char* prefix) const;
4789
4795 int getIndex(const NamedString* param) const;
4796
4802 int getIndex(const String& name) const;
4803
4809 NamedString* getParam(const String& name) const;
4810
4816 NamedString* getParam(unsigned int index) const;
4817
4823 const String& operator[](const String& name) const;
4824
4831 const char* getValue(const String& name, const char* defvalue = 0) const;
4832
4843 int getIntValue(const String& name, int defvalue = 0, int minvalue = INT_MIN,
4844 int maxvalue = INT_MAX, bool clamp = true) const;
4845
4853 int getIntValue(const String& name, const TokenDict* tokens, int defvalue = 0) const;
4854
4865 int64_t getInt64Value(const String& name, int64_t defvalue = 0, int64_t minvalue = LLONG_MIN,
4866 int64_t maxvalue = LLONG_MAX, bool clamp = true) const;
4867
4874 double getDoubleValue(const String& name, double defvalue = 0.0) const;
4875
4882 bool getBoolValue(const String& name, bool defvalue = false) const;
4883
4891 int replaceParams(String& str, bool sqlEsc = false, char extraEsc = 0) const;
4892
4901 void dump(String& str, const char* separator, char quote = 0, bool force = false) const;
4902
4907 static const NamedList& empty();
4908
4913 inline ObjList* paramList()
4914 { return &m_params; }
4915
4920 inline const ObjList* paramList() const
4921 { return &m_params; }
4922
4923 private:
4924 NamedList(); // no default constructor please
4925 ObjList m_params;
4926 };
4927
4933 class YATE_API NamedIterator
4934 {
4935 public:
4940 inline NamedIterator(const NamedList& list)
4941 : m_list(&list), m_item(list.m_params.skipNull())
4942 { }
4943
4948 inline NamedIterator(const NamedIterator& original)
4949 : m_list(original.m_list), m_item(original.m_item)
4950 { }
4951
4956 inline NamedIterator& operator=(const NamedList& list)
4957 { m_list = &list; m_item = list.m_params.skipNull(); return *this; }
4958
4963 inline NamedIterator& operator=(const NamedIterator& original)
4964 { m_list = original.m_list; m_item = original.m_item; return *this; }
4965
4970 const NamedString* get();
4971
4975 inline bool eof() const
4976 { return !m_item; }
4977
4981 inline void reset()
4982 { m_item = m_list->m_params.skipNull(); }
4983
4984 private:
4985 NamedIterator(); // no default constructor please
4986 const NamedList* m_list;
4987 const ObjList* m_item;
4988 };
4989
4995 class YATE_API URI : public String
4996 {
4997 public:
5001 URI();
5002
5007 URI(const URI& uri);
5008
5013 explicit URI(const String& uri);
5014
5019 explicit URI(const char* uri);
5020
5029 URI(const char* proto, const char* user, const char* host, int port = 0, const char* desc = 0);
5030
5034 void parse() const;
5035
5040 inline URI& operator=(const URI& value)
5041 { String::operator=(value); return *this; }
5042
5047 inline URI& operator=(const String& value)
5048 { String::operator=(value); return *this; }
5049
5054 inline URI& operator=(const char* value)
5055 { String::operator=(value); return *this; }
5056
5061 inline const String& getDescription() const
5062 { parse(); return m_desc; }
5063
5068 inline const String& getProtocol() const
5069 { parse(); return m_proto; }
5070
5075 inline const String& getUser() const
5076 { parse(); return m_user; }
5077
5082 inline const String& getHost() const
5083 { parse(); return m_host; }
5084
5089 inline int getPort() const
5090 { parse(); return m_port; }
5091
5096 inline const String& getExtra() const
5097 { parse(); return m_extra; }
5098
5099 protected:
5105 virtual void changed();
5106 mutable bool m_parsed;
5107 mutable String m_desc;
5108 mutable String m_proto;
5109 mutable String m_user;
5110 mutable String m_host;
5111 mutable String m_extra;
5112 mutable int m_port;
5113 };
5114
5115 class MutexPrivate;
5116 class SemaphorePrivate;
5117 class ThreadPrivate;
5118
5123 class YATE_API Lockable
5124 {
5125 public:
5129 virtual ~Lockable();
5130
5136 virtual bool lock(long maxwait = -1) = 0;
5137
5142 virtual bool unlock() = 0;
5143
5149 virtual bool locked() const = 0;
5150
5156 virtual bool check(long maxwait = -1);
5157
5164 virtual bool unlockAll();
5165
5171 static void wait(unsigned long maxwait);
5172
5177 static unsigned long wait();
5178
5185 static void startUsingNow();
5186
5193 static void enableSafety(bool safe = true);
5194
5199 static bool safety();
5200 };
5201
5206 class YATE_API Mutex : public Lockable
5207 {
5208 friend class MutexPrivate;
5209 public:
5216 explicit Mutex(bool recursive = false, const char* name = 0);
5217
5222 Mutex(const Mutex& original);
5223
5227 ~Mutex();
5228
5233 Mutex& operator=(const Mutex& original);
5234
5240 virtual bool lock(long maxwait = -1);
5241
5246 virtual bool unlock();
5247
5253 virtual bool locked() const;
5254
5259 const char* owner() const;
5260
5265 bool recursive() const;
5266
5271 static int count();
5272
5277 static int locks();
5278
5283 static bool efficientTimedLock();
5284
5285 private:
5286 MutexPrivate* privDataCopy() const;
5287 MutexPrivate* m_private;
5288 };
5289
5296 class YATE_API MutexPool
5297 {
5298 public:
5309 MutexPool(unsigned int len = 13, bool recursive = false, const char* name = 0);
5310
5314 ~MutexPool();
5315
5323 inline unsigned int index(void* ptr) const
5324 { return ((unsigned int)(unsigned long)ptr) % m_length; }
5325
5333 inline Mutex* mutex(void* ptr) const
5334 { return m_data[index(ptr)]; }
5335
5341 inline Mutex* mutex(unsigned int idx) const
5342 { return m_data[idx % m_length]; }
5343
5344 private:
5345 String* m_name; // Mutex names
5346 Mutex** m_data; // The array
5347 unsigned int m_length; // Array length
5348 };
5349
5354 class YATE_API Semaphore : public Lockable
5355 {
5356 friend class SemaphorePrivate;
5357 public:
5364 explicit Semaphore(unsigned int maxcount = 1, const char* name = 0,
5365 unsigned int initialCount = 1);
5366
5371 Semaphore(const Semaphore& original);
5372
5376 ~Semaphore();
5377
5382 Semaphore& operator=(const Semaphore& original);
5383
5389 virtual bool lock(long maxwait = -1);
5390
5395 virtual bool unlock();
5396
5402 virtual bool locked() const;
5403
5408 static int count();
5409
5414 static int locks();
5415
5420 static bool efficientTimedLock();
5421
5422 private:
5423 SemaphorePrivate* privDataCopy() const;
5424 SemaphorePrivate* m_private;
5425 };
5426
5432 class YATE_API Lock
5433 {
5434 YNOCOPY(Lock); // no automatic copies please
5435 public:
5441 inline Lock(Lockable& lck, long maxwait = -1)
5442 { m_lock = lck.lock(maxwait) ? &lck : 0; }
5443
5449 inline Lock(Lockable* lck, long maxwait = -1)
5450 { m_lock = (lck && lck->lock(maxwait)) ? lck : 0; }
5451
5455 inline ~Lock()
5456 { if (m_lock) m_lock->unlock(); }
5457
5462 inline Lockable* locked() const
5463 { return m_lock; }
5464
5468 inline void drop()
5469 { if (m_lock) m_lock->unlock(); m_lock = 0; }
5470
5477 inline bool acquire(Lockable* lck, long maxwait = -1)
5478 { return (lck && (lck == m_lock)) ||
5479 (drop(),(lck && (m_lock = lck->lock(maxwait) ? lck : 0))); }
5480
5487 inline bool acquire(Lockable& lck, long maxwait = -1)
5488 { return acquire(&lck,maxwait); }
5489
5490 private:
5491 Lockable* m_lock;
5492
5494 inline void* operator new(size_t);
5495
5497 inline void* operator new[](size_t);
5498 };
5499
5506 class YATE_API Lock2
5507 {
5508 YNOCOPY(Lock2); // no automatic copies please
5509 public:
5516 inline Lock2(Mutex* mx1, Mutex* mx2, long maxwait = -1)
5517 : m_mx1(0), m_mx2(0)
5518 { lock(mx1,mx2,maxwait); }
5519
5526 inline Lock2(Mutex& mx1, Mutex& mx2, long maxwait = -1)
5527 : m_mx1(0), m_mx2(0)
5528 { lock(&mx1,&mx2,maxwait); }
5529
5533 inline ~Lock2()
5534 { drop(); }
5535
5540 inline bool locked() const
5541 { return m_mx1 != 0; }
5542
5550 bool lock(Mutex* mx1, Mutex* mx2, long maxwait = -1);
5551
5559 inline bool lock(Mutex& mx1, Mutex& mx2, long maxwait = -1)
5560 { return lock(&mx1,&mx2,maxwait); }
5561
5565 void drop();
5566
5567 private:
5568 Mutex* m_mx1;
5569 Mutex* m_mx2;
5570
5572 inline void* operator new(size_t);
5573
5575 inline void* operator new[](size_t);
5576 };
5577
5583 class YATE_API Runnable
5584 {
5585 public:
5590 virtual void run() = 0;
5591
5595 virtual ~Runnable();
5596 };
5597
5604 class YATE_API Thread : public Runnable
5605 {
5606 friend class ThreadPrivate;
5607 friend class MutexPrivate;
5608 friend class SemaphorePrivate;
5609 YNOCOPY(Thread); // no automatic copies please
5610 public:
5614 enum Priority {
5615 Lowest,
5616 Low,
5617 Normal,
5618 High,
5619 Highest
5620 };
5621
5625 virtual void cleanup();
5626
5631 bool startup();
5632
5637 bool error() const;
5638
5643 bool running() const;
5644
5649 inline int locks() const
5650 { return m_locks; }
5651
5656 inline bool locked() const
5657 { return m_locking || m_locks; }
5658
5663 const char* name() const;
5664
5669 static const char* currentName();
5670
5676 static void yield(bool exitCheck = false);
5677
5683 static void idle(bool exitCheck = false);
5684
5690 static void sleep(unsigned int sec, bool exitCheck = false);
5691
5697 static void msleep(unsigned long msec, bool exitCheck = false);
5698
5705 static void usleep(unsigned long usec, bool exitCheck = false);
5706
5711 static unsigned long idleUsec();
5712
5717 static unsigned long idleMsec();
5718
5723 static void idleMsec(unsigned long msec);
5724
5730 static Thread* current();
5731
5736 static int count();
5737
5743 static bool check(bool exitNow = true);
5744
5748 static void exit();
5749
5754 void cancel(bool hard = false);
5755
5760 inline bool isCurrent() const
5761 { return current() == this; }
5762
5767 NamedCounter* getObjCounter() const;
5768
5774 NamedCounter* setObjCounter(NamedCounter* counter);
5775
5781 static NamedCounter* getCurrentObjCounter(bool always = false);
5782
5788 static NamedCounter* setCurrentObjCounter(NamedCounter* counter);
5789
5796 static Priority priority(const char* name, Priority defvalue = Normal);
5797
5803 static const char* priority(Priority prio);
5804
5809 static void killall();
5810
5815 static void preExec();
5816
5822 static int lastError();
5823
5830 static inline bool errorString(String& buffer)
5831 { return errorString(buffer,lastError()); }
5832
5843 static bool errorString(String& buffer, int code);
5844
5845 protected:
5851 Thread(const char *name = 0, Priority prio = Normal);
5852
5858 Thread(const char *name, const char* prio);
5859
5863 virtual ~Thread();
5864
5865 private:
5866 ThreadPrivate* m_private;
5867 int m_locks;
5868 bool m_locking;
5869 };
5870
5875 class YATE_API TempObjectCounter
5876 {
5877 YNOCOPY(TempObjectCounter); // no automatic copies please
5878 public:
5884 inline TempObjectCounter(NamedCounter* counter, bool enable = GenObject::getObjCounting())
5885 : m_saved(0), m_enabled(enable)
5886 { if (m_enabled) m_saved = Thread::setCurrentObjCounter(counter); }
5887
5893 inline TempObjectCounter(const GenObject* obj, bool enable = GenObject::getObjCounting())
5894 : m_saved(0), m_enabled(enable && obj)
5895 { if (m_enabled) m_saved = Thread::setCurrentObjCounter(obj->getObjCounter()); }
5896
5902 inline TempObjectCounter(const GenObject& obj, bool enable = GenObject::getObjCounting())
5903 : m_saved(0), m_enabled(enable)
5904 { if (m_enabled) m_saved = Thread::setCurrentObjCounter(obj.getObjCounter()); }
5905
5909 inline ~TempObjectCounter()
5910 { if (m_enabled) Thread::setCurrentObjCounter(m_saved); }
5911
5912 private:
5913 NamedCounter* m_saved;
5914 bool m_enabled;
5915 };
5916
5917 class Socket;
5918
5923 class YATE_API SocketAddr : public GenObject
5924 {
5925 YCLASS(SocketAddr,GenObject)
5926 public:
5930 enum Family {
5931 Unknown = AF_UNSPEC,
5932 IPv4 = AF_INET,
5933 AfMax = AF_MAX,
5934 AfUnsupported = AfMax,
5935 #ifdef AF_INET6
5936 IPv6 = AF_INET6,
5937 #else
5938 IPv6 = AfUnsupported + 1,
5939 #endif
5940 #ifdef HAS_AF_UNIX
5941 Unix = AF_UNIX,
5942 #else
5943 Unix = AfUnsupported + 2,
5944 #endif
5945 };
5946
5950 inline SocketAddr()
5951 : m_address(0), m_length(0)
5952 { }
5953
5958 inline SocketAddr(const SocketAddr& value)
5959 : GenObject(),
5960 m_address(0), m_length(0)
5961 { assign(value.address(),value.length()); }
5962
5968 explicit SocketAddr(int family, const void* raw = 0);
5969
5975 SocketAddr(const struct sockaddr* addr, socklen_t len = 0);
5976
5980 virtual ~SocketAddr();
5981
5986 inline SocketAddr& operator=(const SocketAddr& value)
5987 { assign(value.address(),value.length()); return *this; }
5988
5994 bool operator==(const SocketAddr& other) const;
5995
6001 inline bool operator!=(const SocketAddr& other) const
6002 { return !operator==(other); }
6003
6007 void clear();
6008
6014 bool assign(int family);
6015
6021 void assign(const struct sockaddr* addr, socklen_t len = 0);
6022
6028 bool assign(const DataBlock& addr);
6029
6035 bool local(const SocketAddr& remote);
6036
6041 inline bool valid() const
6042 { return m_length && m_address; }
6043
6048 inline bool null() const
6049 { return !(m_length && m_address); }
6050
6055 inline int family() const
6056 { return m_address ? m_address->sa_family : 0; }
6057
6062 inline const char* familyName()
6063 { return lookupFamily(family()); }
6064
6069 inline unsigned int scopeId() const
6070 { return scopeId(address()); }
6071
6077 inline bool scopeId(unsigned int val)
6078 { return scopeId(address(),val); }
6079
6084 inline const String& host() const
6085 { return m_host; }
6086
6091 inline const String& addr() const {
6092 if (!m_addr)
6093 updateAddr();
6094 return m_addr;
6095 }
6096
6103 virtual bool host(const String& name);
6104
6109 int port() const;
6110
6116 bool port(int newport);
6117
6122 inline struct sockaddr* address() const
6123 { return m_address; }
6124
6129 inline socklen_t length() const
6130 { return m_length; }
6131
6136 inline bool isNullAddr() const
6137 { return isNullAddr(m_host,family()); }
6138
6144 int copyAddr(DataBlock& addr) const;
6145
6151 static bool supports(int family);
6152
6158 static int family(const String& addr);
6159
6166 static bool stringify(String& buf, struct sockaddr* addr);
6167
6176 static inline int unStringify(uint8_t* buf, const String& host,
6177 int family = Unknown) {
6178 SocketAddr sa(family);
6179 return sa.host(host) ? copyAddr(buf,sa.address()) : Unknown;
6180 }
6181
6189 static int copyAddr(uint8_t* buf, struct sockaddr* addr);
6190
6196 static inline unsigned int scopeId(struct sockaddr* addr) {
6197 #ifdef AF_INET6
6198 if (addr && addr->sa_family == AF_INET6)
6199 return ((struct sockaddr_in6*)addr)->sin6_scope_id;
6200 #endif
6201 return 0;
6202 }
6203
6210 static inline bool scopeId(struct sockaddr* addr, unsigned int val) {
6211 #ifdef AF_INET6
6212 if (addr && addr->sa_family == AF_INET6) {
6213 ((struct sockaddr_in6*)addr)->sin6_scope_id = val;
6214 return true;
6215 }
6216 #endif
6217 return false;
6218 }
6219
6227 static String& appendAddr(String& buf, const String& addr, int family = Unknown);
6228
6237 static inline String& appendTo(String& buf, const String& addr, int port,
6238 int family = Unknown) {
6239 appendAddr(buf,addr,family) << ":" << port;
6240 return buf;
6241 }
6242
6250 static inline String appendTo(const String& addr, int port, int family = Unknown) {
6251 String buf;
6252 appendTo(buf,addr,port,family);
6253 return buf;
6254 }
6255
6262 static bool isNullAddr(const String& addr, int family = Unknown);
6263
6272 static void splitIface(const String& buf, String& addr, String* iface = 0);
6273
6285 static void split(const String& buf, String& addr, int& port, bool portPresent = false);
6286
6292 static inline const char* lookupFamily(int family)
6293 { return lookup(family,s_familyName); }
6294
6299 static const String& ipv4NullAddr();
6300
6305 static const String& ipv6NullAddr();
6306
6311 static const TokenDict* dictFamilyName();
6312
6313 protected:
6317 virtual void stringify();
6318
6322 virtual void updateAddr() const;
6323
6324 struct sockaddr* m_address;
6325 socklen_t m_length;
6326 String m_host;
6327 mutable String m_addr;
6328
6329 private:
6330 static const TokenDict s_familyName[];
6331 };
6332
6337 class YATE_API SocketFilter : public GenObject
6338 {
6339 friend class Socket;
6340 YNOCOPY(SocketFilter); // no automatic copies please
6341 public:
6345 SocketFilter();
6346
6350 virtual ~SocketFilter();
6351
6357 virtual void* getObject(const String& name) const;
6358
6363 virtual void timerTick(const Time& when);
6364
6374 virtual bool received(void* buffer, int length, int flags, const struct sockaddr* addr, socklen_t adrlen) = 0;
6375
6380 inline Socket* socket() const
6381 { return m_socket; }
6382
6387 bool valid() const;
6388
6389 private:
6390 Socket* m_socket;
6391 };
6392
6397 class YATE_API Stream
6398 {
6399 public:
6403 enum SeekPos {
6404 SeekBegin, // Seek from start of stream
6405 SeekEnd, // Seek from stream end
6406 SeekCurrent // Seek from current position
6407 };
6408
6412 virtual ~Stream();
6413
6418 inline int error() const
6419 { return m_error; }
6420
6425 virtual bool terminate() = 0;
6426
6431 virtual bool canRetry() const;
6432
6437 virtual bool inProgress() const;
6438
6443 virtual bool valid() const = 0;
6444
6450 virtual bool setBlocking(bool block = true);
6451
6458 virtual int writeData(const void* buffer, int length) = 0;
6459
6465 int writeData(const char* str);
6466
6472 inline int writeData(const String& str)
6473 { return writeData(str.c_str(), str.length()); }
6474
6480 inline int writeData(const DataBlock& buf)
6481 { return writeData(buf.data(), buf.length()); }
6482
6489 virtual int readData(void* buffer, int length) = 0;
6490
6495 virtual int64_t length();
6496
6503 virtual int64_t seek(SeekPos pos, int64_t offset = 0);
6504
6510 inline int64_t seek(int64_t offset)
6511 { return seek(SeekBegin,offset); }
6512
6519 static bool allocPipe(Stream*& reader, Stream*& writer);
6520
6527 static bool allocPair(Stream*& str1, Stream*& str2);
6528
6533 static bool supportsPipes();
6534
6539 static bool supportsPairs();
6540
6541 protected:
6545 inline Stream()
6546 : m_error(0)
6547 { }
6548
6552 inline void clearError()
6553 { m_error = 0; }
6554
6555 int m_error;
6556 };
6557
6562 class YATE_API MemoryStream : public Stream
6563 {
6564 YNOCOPY(MemoryStream); // no automatic copies please
6565 public:
6569 inline MemoryStream()
6570 : m_offset(0)
6571 { }
6572
6577 inline MemoryStream(const DataBlock& data)
6578 : m_data(data), m_offset(0)
6579 { }
6580
6585 inline const DataBlock& data() const
6586 { return m_data; }
6587
6592 virtual bool terminate()
6593 { return true; }
6598 virtual bool valid() const
6599 { return true; }
6600
6607 virtual int writeData(const void* buffer, int len);
6608
6615 virtual int readData(void* buffer, int len);
6616
6621 virtual int64_t length()
6622 { return m_data.length(); }
6623
6630 virtual int64_t seek(SeekPos pos, int64_t offset = 0);
6631
6632 protected:
6636 DataBlock m_data;
6637
6641 int64_t m_offset;
6642 };
6643
6648 class YATE_API File : public Stream
6649 {
6650 YNOCOPY(File); // no automatic copies please
6651 public:
6655 File();
6656
6661 explicit File(HANDLE handle);
6662
6666 virtual ~File();
6667
6680 virtual bool openPath(const char* name, bool canWrite = false, bool canRead = true,
6681 bool create = false, bool append = false, bool binary = false,
6682 bool pubReadable = false, bool pubWritable = false);
6683
6688 virtual bool terminate();
6689
6694 void attach(HANDLE handle);
6695
6700 HANDLE detach();
6701
6706 inline HANDLE handle() const
6707 { return m_handle; }
6708
6713 virtual bool canRetry() const;
6714
6719 virtual bool valid() const;
6720
6725 static HANDLE invalidHandle();
6726
6732 virtual bool setBlocking(bool block = true);
6733
6738 virtual int64_t length();
6739
6746 virtual int64_t seek(SeekPos pos, int64_t offset = 0);
6747
6754 virtual int writeData(const void* buffer, int length);
6755
6762 virtual int readData(void* buffer, int length);
6763
6769 bool getFileTime(unsigned int& secEpoch);
6770
6777 virtual bool md5(String& buffer);
6778
6786 static bool setFileTime(const char* name, unsigned int secEpoch, int* error = 0);
6787
6795 static bool getFileTime(const char* name, unsigned int& secEpoch, int* error = 0);
6796
6803 static bool exists(const char* name, int* error = 0);
6804
6812 static bool rename(const char* oldFile, const char* newFile, int* error = 0);
6813
6820 static bool remove(const char* name, int* error = 0);
6821
6829 static bool md5(const char* name, String& buffer, int* error = 0);
6830
6838 static bool mkDir(const char* path, int* error = 0, int mode = -1);
6839
6846 static bool rmDir(const char* path, int* error = 0);
6847
6859 static bool listDirectory(const char* path, ObjList* dirs, ObjList* files,
6860 int* error = 0);
6861
6868 static bool createPipe(File& reader, File& writer);
6869
6870 protected:
6871
6875 void copyError();
6876
6877 HANDLE m_handle;
6878 };
6879
6884 class YATE_API Socket : public Stream
6885 {
6886 YNOCOPY(Socket); // no automatic copies please
6887 public:
6891 enum TOS {
6892 Normal = 0,
6893 LowDelay = IPTOS_LOWDELAY,
6894 MaxThroughput = IPTOS_THROUGHPUT,
6895 MaxReliability = IPTOS_RELIABILITY,
6896 MinCost = IPTOS_MINCOST,
6897 };
6898
6902 enum DSCP {
6903 DefaultPHB = 0x00,
6904 // Class selectors
6905 CS0 = 0x00,
6906 CS1 = 0x20,
6907 CS2 = 0x40,
6908 CS3 = 0x60,
6909 CS4 = 0x80,
6910 CS5 = 0xa0,
6911 CS6 = 0xc0,
6912 CS7 = 0xe0,
6913 // Assured forwarding
6914 AF11 = 0x28,
6915 AF12 = 0x30,
6916 AF13 = 0x38,
6917 AF21 = 0x48,
6918 AF22 = 0x50,
6919 AF23 = 0x58,
6920 AF31 = 0x68,
6921 AF32 = 0x70,
6922 AF33 = 0x78,
6923 AF41 = 0x88,
6924 AF42 = 0x90,
6925 AF43 = 0x98,
6926 // Expedited forwarding
6927 ExpeditedFwd = 0xb8,
6928 VoiceAdmit = 0xb0,
6929 };
6930
6934 Socket();
6935
6940 explicit Socket(SOCKET handle);
6941
6948 Socket(int domain, int type, int protocol = 0);
6949
6953 virtual ~Socket();
6954
6962 virtual bool create(int domain, int type, int protocol = 0);
6963
6968 virtual bool terminate();
6969
6974 void attach(SOCKET handle);
6975
6980 SOCKET detach();
6981
6986 inline SOCKET handle() const
6987 { return m_handle; }
6988
6993 virtual bool canRetry() const;
6994
6999 virtual bool inProgress() const;
7000
7005 virtual bool valid() const;
7006
7011 static SOCKET invalidHandle();
7012
7017 static int socketError();
7018
7023 static const TokenDict* tosValues();
7024
7033 virtual bool setOption(int level, int name, const void* value = 0, socklen_t length = 0);
7034
7043 inline bool setIpv6OnlyOption(bool on) {
7044 #if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY)
7045 int value = on ? 1 : 0;
7046 return setOption(IPPROTO_IPV6,IPV6_V6ONLY,&value,sizeof(value));
7047 #else
7048 return false;
7049 #endif
7050 }
7051
7060 virtual bool getOption(int level, int name, void* buffer, socklen_t* length);
7061
7066 virtual bool setParams(const NamedList& params)
7067 { return false; }
7068
7075 virtual bool getParams(const String& params, NamedList& result)
7076 { return false; }
7077
7083 virtual bool setTOS(int tos);
7084
7091 inline bool setTOS(const char* tos, int defTos = Normal)
7092 { return setTOS(lookup(tos,tosValues(),defTos)); }
7093
7098 virtual int getTOS();
7099
7105 virtual bool setBlocking(bool block = true);
7106
7114 virtual bool setReuse(bool reuse = true, bool exclusive = false);
7115
7122 virtual bool setLinger(int seconds = -1);
7123
7130 virtual bool bind(struct sockaddr* addr, socklen_t addrlen);
7131
7137 inline bool bind(const SocketAddr& addr)
7138 { return bind(addr.address(), addr.length()); }
7139
7145 virtual bool listen(unsigned int backlog = 0);
7146
7153 virtual Socket* accept(struct sockaddr* addr = 0, socklen_t* addrlen = 0);
7154
7160 Socket* accept(SocketAddr& addr);
7161
7168 SOCKET acceptHandle(struct sockaddr* addr = 0, socklen_t* addrlen = 0);
7169
7177 bool updateError();
7178
7183 static bool efficientSelect();
7184
7190 static bool canSelect(SOCKET handle);
7191
7196 virtual bool canSelect() const;
7197
7204 virtual bool connect(struct sockaddr* addr, socklen_t addrlen);
7205
7211 inline bool connect(const SocketAddr& addr)
7212 { return connect(addr.address(), addr.length()); }
7213
7223 virtual bool connectAsync(struct sockaddr* addr, socklen_t addrlen, unsigned int toutUs,
7224 bool* timeout = 0);
7225
7234 inline bool connectAsync(const SocketAddr& addr, unsigned int toutUs,
7235 bool* timeout = 0)
7236 { return connectAsync(addr.address(),addr.length(),toutUs,timeout); }
7237
7244 virtual bool shutdown(bool stopReads, bool stopWrites);
7245
7252 virtual bool getSockName(struct sockaddr* addr, socklen_t* addrlen);
7253
7259 bool getSockName(SocketAddr& addr);
7260
7267 virtual bool getPeerName(struct sockaddr* addr, socklen_t* addrlen);
7268
7274 bool getPeerName(SocketAddr& addr);
7275
7285 virtual int sendTo(const void* buffer, int length, const struct sockaddr* addr, socklen_t adrlen, int flags = 0);
7286
7295 inline int sendTo(const void* buffer, int length, const SocketAddr& addr, int flags = 0)
7296 { return sendTo(buffer, length, addr.address(), addr.length(), flags); }
7297
7305 virtual int send(const void* buffer, int length, int flags = 0);
7306
7313 virtual int writeData(const void* buffer, int length);
7314
7324 virtual int recvFrom(void* buffer, int length, struct sockaddr* addr = 0, socklen_t* adrlen = 0, int flags = 0);
7325
7334 int recvFrom(void* buffer, int length, SocketAddr& addr, int flags = 0);
7335
7343 virtual int recv(void* buffer, int length, int flags = 0);
7344
7351 virtual int readData(void* buffer, int length);
7352
7361 virtual bool select(bool* readok, bool* writeok, bool* except, struct timeval* timeout = 0);
7362
7371 bool select(bool* readok, bool* writeok, bool* except, int64_t timeout);
7372
7378 bool installFilter(SocketFilter* filter);
7379
7385 void removeFilter(SocketFilter* filter, bool delobj = false);
7386
7390 void clearFilters();
7391
7398 virtual void timerTick(const Time& when);
7399
7407 static bool createPair(Socket& sock1, Socket& sock2, int domain = AF_UNIX);
7408
7409 protected:
7410
7414 void copyError();
7415
7422 bool checkError(int retcode, bool strict = false);
7423
7433 bool applyFilters(void* buffer, int length, int flags, const struct sockaddr* addr = 0, socklen_t adrlen = 0);
7434
7435 SOCKET m_handle;
7436 ObjList m_filters;
7437 };
7438
7443 class YATE_API SctpSocket : public Socket
7444 {
7445 YNOCOPY(SctpSocket); // no automatic copies please
7446 public:
7450 inline SctpSocket()
7451 { }
7452
7457 inline explicit SctpSocket(SOCKET fd)
7458 : Socket(fd)
7459 { }
7460
7464 virtual ~SctpSocket();
7465
7471 virtual bool bindx(ObjList& addresses) = 0;
7472
7478 virtual bool connectx(ObjList& addresses) = 0;
7479
7489 virtual int sendTo(void* buffer, int length, int stream, SocketAddr& addr, int flags) = 0;
7490
7496 virtual Socket* accept(SocketAddr& addr)
7497 { return 0; }
7498
7507 virtual int sendMsg(const void* buf, int length, int stream, int& flags) = 0;
7508
7518 virtual int recvMsg(void* buf, int length, SocketAddr& addr, int& stream, int& flags) = 0;
7519
7526 virtual bool setStreams(int inbound, int outbound) = 0;
7527
7533 virtual bool subscribeEvents() = 0;
7534
7541 virtual bool getStreams(int& inbound, int& outbound) = 0;
7542
7548 virtual bool setPayload(u_int32_t payload) = 0;
7549 };
7550
7555 class YATE_API SocketRef : public RefObject
7556 {
7557 public:
7562 inline SocketRef(Socket** socket)
7563 : m_socket(socket)
7564 { }
7565
7570 inline SocketRef(Socket*& socket)
7571 : m_socket(&socket)
7572 { }
7573
7579 virtual void* getObject(const String& name) const
7580 { return (name == YATOM("Socket*")) ? m_socket : RefObject::getObject(name); }
7581
7582 private:
7583 SocketRef();
7584 void* m_socket;
7585 };
7586
7591 class YATE_API DnsRecord : public GenObject
7592 {
7593 YCLASS(DnsRecord,GenObject)
7594 YNOCOPY(DnsRecord);
7595 public:
7602 inline DnsRecord(int ttl, int order, int pref)
7603 : m_ttl(ttl), m_order(order), m_pref(pref)
7604 {}
7605
7609 inline DnsRecord()
7610 : m_order(0), m_pref(0)
7611 {}
7612
7617 inline int ttl() const
7618 { return m_ttl; }
7619
7624 inline int order() const
7625 { return m_order; }
7626
7631 inline int pref() const
7632 { return m_pref; }
7633
7639 virtual void dump(String& buf, const char* sep = " ");
7640
7648 static bool insert(ObjList& list, DnsRecord* rec, bool ascPref);
7649
7650 protected:
7651 int m_ttl;
7652 int m_order;
7653 int m_pref;
7654 };
7655
7660 class YATE_API TxtRecord : public DnsRecord
7661 {
7662 YCLASS(TxtRecord,DnsRecord)
7663 YNOCOPY(TxtRecord);
7664 public:
7670 inline TxtRecord(int ttl, const char* text)
7671 : DnsRecord(ttl,-1,-1), m_text(text)
7672 {}
7673
7678 inline const String& text() const
7679 { return m_text; }
7680
7686 virtual void dump(String& buf, const char* sep = " ");
7687
7693 static void copy(ObjList& dest, const ObjList& src);
7694
7695 protected:
7696 String m_text;
7697
7698 private:
7699 TxtRecord() {} // No default contructor
7700 };
7701
7706 class YATE_API SrvRecord : public DnsRecord
7707 {
7708 YCLASS(SrvRecord,DnsRecord)
7709 YNOCOPY(SrvRecord);
7710 public:
7719 inline SrvRecord(int ttl, int prio, int weight, const char* addr, int port)
7720 : DnsRecord(ttl,prio,weight), m_address(addr), m_port(port)
7721 {}
7722
7727 inline const String& address() const
7728 { return m_address; }
7729
7734 inline int port() const
7735 { return m_port; }
7736
7742 virtual void dump(String& buf, const char* sep = " ");
7743
7749 static void copy(ObjList& dest, const ObjList& src);
7750
7751 protected:
7752 String m_address;
7753 int m_port;
7754
7755 private:
7756 SrvRecord() {} // No default contructor
7757 };
7758
7763 class YATE_API NaptrRecord : public DnsRecord
7764 {
7765 YCLASS(NaptrRecord,DnsRecord)
7766 YNOCOPY(NaptrRecord);
7767 public:
7778 NaptrRecord(int ttl, int ord, int pref, const char* flags, const char* serv,
7779 const char* regexp, const char* next);
7780
7787 bool replace(String& str) const;
7788
7794 virtual void dump(String& buf, const char* sep = " ");
7795
7800 inline const String& flags() const
7801 { return m_flags; }
7802
7807 inline const String& serv() const
7808 { return m_service; }
7809
7814 inline const Regexp& regexp() const
7815 { return m_regmatch; }
7816
7821 inline const String& repTemplate() const
7822 { return m_template; }
7823
7828 inline const String& nextName() const
7829 { return m_next; }
7830
7831 protected:
7832 String m_flags;
7833 String m_service;
7834 Regexp m_regmatch;
7835 String m_template;
7836 String m_next;
7837
7838 private:
7839 NaptrRecord() {} // No default contructor
7840 };
7841
7846 class YATE_API Resolver
7847 {
7848 public:
7852 enum Type {
7853 Unknown,
7854 Srv, // SRV (Service Location)
7855 Naptr, // NAPTR (Naming Authority Pointer)
7856 A4, // A (Address)
7857 A6, // AAAA (IPv6 Address)
7858 Txt, // TXT (Text)
7859 };
7860
7867 static bool available(Type type = Unknown);
7868
7875 static bool init(int timeout = -1, int retries = -1);
7876
7885 static int query(Type type, const char* dname, ObjList& result, String* error = 0);
7886
7894 static int srvQuery(const char* dname, ObjList& result, String* error = 0);
7895
7903 static int naptrQuery(const char* dname, ObjList& result, String* error = 0);
7904
7912 static int a4Query(const char* dname, ObjList& result, String* error = 0);
7913
7921 static int a6Query(const char* dname, ObjList& result, String* error = 0);
7922
7930 static int txtQuery(const char* dname, ObjList& result, String* error = 0);
7931
7935 static const TokenDict s_types[];
7936 };
7937
7942 class YATE_API Cipher : public GenObject
7943 {
7944 public:
7948 enum Direction {
7949 Bidir,
7950 Encrypt,
7951 Decrypt,
7952 };
7953
7958 inline static const TokenDict* directions()
7959 { return s_directions; }
7960
7967 inline static Direction direction(const char* name, Direction defdir = Bidir)
7968 { return (Direction)TelEngine::lookup(name,s_directions,defdir); }
7969
7973 virtual ~Cipher();
7974
7980 virtual void* getObject(const String& name) const;
7981
7987 virtual bool valid(Direction dir = Bidir) const;
7988
7993 virtual unsigned int blockSize() const = 0;
7994
7999 virtual unsigned int initVectorSize() const;
8000
8006 unsigned int bufferSize(unsigned int len) const;
8007
8013 bool bufferFull(unsigned int len) const;
8014
8022 virtual bool setKey(const void* key, unsigned int len, Direction dir = Bidir) = 0;
8023
8030 inline bool setKey(const DataBlock& key, Direction dir = Bidir)
8031 { return setKey(key.data(),key.length(),dir); }
8032
8040 virtual bool initVector(const void* vect, unsigned int len, Direction dir = Bidir);
8041
8048 inline bool initVector(const DataBlock& vect, Direction dir = Bidir)
8049 { return initVector(vect.data(),vect.length(),dir); }
8050
8058 virtual bool encrypt(void* outData, unsigned int len, const void* inpData = 0) = 0;
8059
8065 inline bool encrypt(DataBlock& data)
8066 { return encrypt(data.data(),data.length()); }
8067
8075 virtual bool decrypt(void* outData, unsigned int len, const void* inpData = 0) = 0;
8076
8082 inline bool decrypt(DataBlock& data)
8083 { return decrypt(data.data(),data.length()); }
8084
8085 private:
8086 static const TokenDict s_directions[];
8087 };
8088
8094 class YATE_API Compressor : public String
8095 {
8096 YCLASS(Compressor,String)
8097 YNOCOPY(Compressor); // no automatic copies please
8098 public:
8104 inline Compressor(const char* format, const char* name = 0)
8105 : String(name), m_format(format)
8106 {}
8107
8111 virtual ~Compressor()
8112 {}
8113
8118 inline const String& format() const
8119 { return m_format; }
8120
8128 virtual bool init(bool comp = true, bool decomp = true,
8129 const NamedList& params = NamedList::empty())
8130 { return true; }
8131
8136 virtual void finalize(bool comp)
8137 {}
8138
8147 virtual int compress(const void* buf, unsigned int len, DataBlock& dest);
8148
8157 virtual int decompress(const void* buf, unsigned int len, DataBlock& dest);
8158
8169 virtual int writeComp(const void* buf, unsigned int len, bool flush) = 0;
8170
8179 inline int writeComp(const DataBlock& data, bool flush)
8180 { return writeComp(data.data(),data.length(),flush); }
8181
8190 inline int writeComp(const String& data, bool flush)
8191 { return writeComp(data.c_str(),data.length(),flush); }
8192
8199 virtual int readComp(DataBlock& buf, bool flush) = 0;
8200
8209 virtual int writeDecomp(const void* buf, unsigned int len, bool flush) = 0;
8210
8218 inline int writeDecomp(const DataBlock& data, bool flush)
8219 { return writeDecomp(data.data(),data.length(),flush); }
8220
8228 inline int writeDecomp(const String& data, bool flush)
8229 { return writeDecomp(data.c_str(),data.length(),flush); }
8230
8237 virtual int readDecomp(DataBlock& buf, bool flush) = 0;
8238
8239 protected:
8240 String m_format;
8241 };
8242
8248 class YATE_API SysUsage
8249 {
8250 public:
8254 enum Type {
8255 WallTime,
8256 UserTime,
8257 KernelTime
8258 };
8259
8263 static void init();
8264
8269 static u_int64_t startTime();
8270
8276 static u_int64_t usecRunTime(Type type = WallTime);
8277
8283 static u_int64_t msecRunTime(Type type = WallTime);
8284
8290 static u_int32_t secRunTime(Type type = WallTime);
8291
8297 static double runTime(Type type = WallTime);
8298
8299 };
8300
8301 }; // namespace TelEngine
8302
8303 #endif /* __YATECLASS_H */
8304
8305 /* vi: set ts=8 sw=4 sts=4 noet: */
TelEngine::MutexPool
A Mutex pool.
Definition: yateclass.h:5296
TelEngine::Socket::sendTo
int sendTo(const void *buffer, int length, const SocketAddr &addr, int flags=0)
Definition: yateclass.h:7295
TelEngine::Time::operator=
Time & operator=(u_int64_t usec)
Definition: yateclass.h:3682
TelEngine::String::operator+=
String & operator+=(bool value)
Definition: yateclass.h:2403
TelEngine::DnsRecord
A DNS record.
Definition: yateclass.h:7591
TelEngine::RefPointerBase
Internal helper class.
Definition: yateclass.h:1056
TelEngine::c_safe
const char * c_safe(const char *str)
Definition: yateclass.h:2888
TelEngine::NamedCounter::count
int count() const
Definition: yateclass.h:3347
TelEngine::String::null
bool null() const
Definition: yateclass.h:2042
TelEngine::Lockable
Abstract interface for lockable objects.
Definition: yateclass.h:5123
TelEngine::Stream::writeData
int writeData(const DataBlock &buf)
Definition: yateclass.h:6480
TelEngine::RefPointer::RefPointer
RefPointer(const RefPointer< Obj > &value)
Definition: yateclass.h:1110
TelEngine::debugColor
const char * debugColor(int level)
TelEngine::Compressor::Compressor
Compressor(const char *format, const char *name=0)
Definition: yateclass.h:8104
TelEngine::debugLevel
int debugLevel()
TelEngine::GenPointer::GenPointer
GenPointer()
Definition: yateclass.h:1174
TelEngine::DataBlock::operator+=
DataBlock & operator+=(const DataBlock &value)
Definition: yateclass.h:4040
TelEngine::Thread::locks
int locks() const
Definition: yateclass.h:5649
TelEngine::ObjVector::operator[]
GenObject * operator[](unsigned int index) const
Definition: yateclass.h:1548
TelEngine::RefObject::alive
static bool alive(const RefObject *obj)
Definition: yateclass.h:1014
TelEngine::UChar::operator=
UChar & operator=(char code)
Definition: yateclass.h:1792
TelEngine::MutexPool::index
unsigned int index(void *ptr) const
Definition: yateclass.h:5323
TelEngine::ObjVector::setDelete
void setDelete(bool autodelete)
Definition: yateclass.h:1605
TelEngine::Hasher::hmacStart
bool hmacStart(DataBlock &opad, const DataBlock &key)
Definition: yateclass.h:4205
TelEngine::String::c_str
const char * c_str() const
Definition: yateclass.h:2013
TelEngine::ObjVector::operator[]
GenObject * operator[](signed int index) const
Definition: yateclass.h:1540
TelEngine::DataBlock
A class that holds just a block of raw data.
Definition: yateclass.h:3849
TelEngine::HashList::getList
ObjList * getList(unsigned int index) const
Definition: yateclass.h:3404
TelEngine::String::sqlEscape
String sqlEscape(char extraEsc=0) const
Definition: yateclass.h:2806
TelEngine::DebugEnabler::debugLevel
int debugLevel() const
Definition: yateclass.h:328
TelEngine::ObjList::next
ObjList * next() const
Definition: yateclass.h:1282
TelEngine::URI::getUser
const String & getUser() const
Definition: yateclass.h:5075
TelEngine::Time::sec
u_int32_t sec() const
Definition: yateclass.h:3656
TelEngine::SocketAddr::isNullAddr
bool isNullAddr() const
Definition: yateclass.h:6136
TelEngine::UChar::UChar
UChar(uint32_t code=0)
Definition: yateclass.h:1751
TelEngine::RefObject
Definition: yateclass.h:950
TelEngine::TokenDict::value
int value
Definition: yateclass.h:692
TelEngine::Regexp
A regexp matching class.
Definition: yateclass.h:2977
TelEngine::NamedIterator::NamedIterator
NamedIterator(const NamedList &list)
Definition: yateclass.h:4940
TelEngine::GenObject::setObjCounting
static void setObjCounting(bool enable)
Definition: yateclass.h:893
TelEngine::Debug
void Debug(int level, const char *format,...)
TelEngine::SocketAddr::lookupFamily
static const char * lookupFamily(int family)
Definition: yateclass.h:6292
TelEngine::Socket::handle
SOCKET handle() const
Definition: yateclass.h:6986
TelEngine::SocketAddr::scopeId
static unsigned int scopeId(struct sockaddr *addr)
Definition: yateclass.h:6196
TelEngine::CapturedEvent
A captured event string with a debug level.
Definition: yateclass.h:3109
TelEngine::String::safe
const char * safe(const char *defStr) const
Definition: yateclass.h:2028
TelEngine::Regexp::operator=
Regexp & operator=(const char *value)
Definition: yateclass.h:3008
TelEngine::String::matchString
String matchString(int index=0) const
Definition: yateclass.h:2735
TelEngine::MutexPool::mutex
Mutex * mutex(void *ptr) const
Definition: yateclass.h:5333
TelEngine::GenPointer::operator=
GenPointer< Obj > & operator=(Obj *object)
Definition: yateclass.h:1203
TelEngine::RefPointer::RefPointer
RefPointer()
Definition: yateclass.h:1103
TelEngine::String::operator<<
String & operator<<(int64_t value)
Definition: yateclass.h:2471
TelEngine::SocketAddr::operator=
SocketAddr & operator=(const SocketAddr &value)
Definition: yateclass.h:5986
TelEngine::Lock2::~Lock2
~Lock2()
Definition: yateclass.h:5533
TelEngine::ObjList::operator[]
GenObject * operator[](unsigned int index) const
Definition: yateclass.h:1330
TelEngine::GenPointer::operator=
GenPointer< Obj > & operator=(const GenPointer< Obj > &value)
Definition: yateclass.h:1197
TelEngine::ObjList::skipNull
ObjList * skipNull() const
TelEngine::NaptrRecord
A NAPTR record.
Definition: yateclass.h:7763
TelEngine::Time::toTimeval
void toTimeval(struct timeval *tv) const
Definition: yateclass.h:3701
TelEngine::ListIterator::eof
bool eof() const
Definition: yateclass.h:3589
TelEngine::CapturedEvent::capturing
static bool capturing()
Definition: yateclass.h:3143
TelEngine::MemoryStream::MemoryStream
MemoryStream()
Definition: yateclass.h:6569
TelEngine::Cipher::decrypt
bool decrypt(DataBlock &data)
Definition: yateclass.h:8082
TelEngine::UChar::code
uint32_t code() const
Definition: yateclass.h:1799
TelEngine::Compressor::init
virtual bool init(bool comp=true, bool decomp=true, const NamedList &params=NamedList::empty())
Definition: yateclass.h:8128
TelEngine::Socket::connectAsync
bool connectAsync(const SocketAddr &addr, unsigned int toutUs, bool *timeout=0)
Definition: yateclass.h:7234
TelEngine::SocketFilter
A filter for received socket data.
Definition: yateclass.h:6337
TelEngine::Hasher::hexDigest
const String & hexDigest()
Definition: yateclass.h:4142
TelEngine::strcat
const char * strcat(String &dest, const char *src)
Definition: yateclass.h:2941
TelEngine::Compressor::format
const String & format() const
Definition: yateclass.h:8118
TelEngine::NamedIterator::operator=
NamedIterator & operator=(const NamedList &list)
Definition: yateclass.h:4956
TelEngine::SrvRecord::address
const String & address() const
Definition: yateclass.h:7727
TelEngine::ObjList::autoDelete
bool autoDelete()
Definition: yateclass.h:1429
TelEngine::UChar::UChar
UChar(int32_t code)
Definition: yateclass.h:1759
TelEngine::Debugger::Formatting
Formatting
Definition: yateclass.h:576
TelEngine::GenObject::~GenObject
virtual ~GenObject()
Definition: yateclass.h:843
TelEngine::CapturedEvent::append
static void append(int level, const char *text)
Definition: yateclass.h:3158
TelEngine::Thread
Thread support class.
Definition: yateclass.h:5604
TelEngine::Hasher::update
bool update(const String &str)
Definition: yateclass.h:4167
TelEngine::Thread::locked
bool locked() const
Definition: yateclass.h:5656
TelEngine::URI::getExtra
const String & getExtra() const
Definition: yateclass.h:5096
TelEngine::Lock::~Lock
~Lock()
Definition: yateclass.h:5455
TelEngine::Compressor::writeDecomp
int writeDecomp(const String &data, bool flush)
Definition: yateclass.h:8228
TelEngine::Stream::SeekPos
SeekPos
Definition: yateclass.h:6403
TelEngine::YSTRING
constant YSTRING(const char *string)
TelEngine::File
A stream file class.
Definition: yateclass.h:6648
TelEngine::Hasher::hmac
bool hmac(const String &key, const String &msg)
Definition: yateclass.h:4249
TelEngine::SocketAddr::unStringify
static int unStringify(uint8_t *buf, const String &host, int family=Unknown)
Definition: yateclass.h:6176
TelEngine::NaptrRecord::regexp
const Regexp & regexp() const
Definition: yateclass.h:7814
TelEngine::RefPointer::operator=
RefPointer< Obj > & operator=(const RefPointer< Obj > &value)
Definition: yateclass.h:1130
TelEngine::String::boolText
static const char * boolText(bool value)
Definition: yateclass.h:2006
TelEngine::Lock2::lock
bool lock(Mutex &mx1, Mutex &mx2, long maxwait=-1)
Definition: yateclass.h:5559
TelEngine::Stream::Stream
Stream()
Definition: yateclass.h:6545
TelEngine::NamedList::length
unsigned int length() const
Definition: yateclass.h:4670
TelEngine::GenObject::getObjCounting
static bool getObjCounting()
Definition: yateclass.h:886
TelEngine::SocketAddr::null
bool null() const
Definition: yateclass.h:6048
TelEngine::NamedCounter::enable
void enable(bool val)
Definition: yateclass.h:3328
TelEngine::String::uriEscape
String uriEscape(char extraEsc=0, const char *noEsc=0) const
Definition: yateclass.h:2833
TelEngine::Regexp::compile
bool compile() const
Definition: yateclass.h:3015
TelEngine::String::checkBOM
bool checkBOM() const
Definition: yateclass.h:2085
TelEngine::Hasher::hmac
bool hmac(const DataBlock &key, const DataBlock &msg)
Definition: yateclass.h:4240
TelEngine::NaptrRecord::flags
const String & flags() const
Definition: yateclass.h:7800
TelEngine::SocketFilter::socket
Socket * socket() const
Definition: yateclass.h:6380
TelEngine::SHA256::hashLength
virtual unsigned int hashLength() const
Definition: yateclass.h:4544
TelEngine::Lock::Lock
Lock(Lockable &lck, long maxwait=-1)
Definition: yateclass.h:5441
TelEngine::Cipher
An abstract cipher.
Definition: yateclass.h:7942
TelEngine::SHA1::hashLength
virtual unsigned int hashLength() const
Definition: yateclass.h:4447
TelEngine::RefPointer::~RefPointer
~RefPointer()
Definition: yateclass.h:1124
TelEngine::HashList::length
unsigned int length() const
Definition: yateclass.h:3389
TelEngine::Time::msec
u_int64_t msec() const
Definition: yateclass.h:3663
TelEngine::Array::getColumn
ObjList * getColumn(int column) const
Definition: yateclass.h:1720
TelEngine::Time::Time
Time()
Definition: yateclass.h:3617
TelEngine::SocketRef::SocketRef
SocketRef(Socket *&socket)
Definition: yateclass.h:7570
TelEngine::DataBlock::data
unsigned char * data(unsigned int offs, unsigned int len=1) const
Definition: yateclass.h:3911
TelEngine::XDebug
void XDebug(int level, const char *format,...)
TelEngine::SHA1::rawLength
static unsigned int rawLength()
Definition: yateclass.h:4440
TelEngine::Base64::Base64
Base64(void *src, unsigned int len, bool copyData=true)
Definition: yateclass.h:4575
TelEngine::String::operator<<
String & operator<<(const char *value)
Definition: yateclass.h:2447
TelEngine::Socket::connect
bool connect(const SocketAddr &addr)
Definition: yateclass.h:7211
TelEngine::SrvRecord::port
int port() const
Definition: yateclass.h:7734
TelEngine::RefPointer::pointer
Obj * pointer() const
Definition: yateclass.h:1089
TelEngine::String::uriUnescape
String uriUnescape(int *errptr=0) const
Definition: yateclass.h:2849
TelEngine::Time::~Time
~Time()
Definition: yateclass.h:3649
TelEngine::SocketAddr
A socket address holder.
Definition: yateclass.h:5923
TelEngine::ObjVector::ObjVector
ObjVector(bool autodelete=true)
Definition: yateclass.h:1476
TelEngine::Time::fromTimeval
static u_int64_t fromTimeval(const struct timeval &tv)
Definition: yateclass.h:3723
TelEngine::DebugEnabler::debugChained
bool debugChained() const
Definition: yateclass.h:370
TelEngine::DataBlock::resize
void resize(unsigned int len)
Definition: yateclass.h:3999
TelEngine::DnsRecord::order
int order() const
Definition: yateclass.h:7624
TelEngine::URI::operator=
URI & operator=(const char *value)
Definition: yateclass.h:5054
TelEngine::NamedString::name
const String & name() const
Definition: yateclass.h:3201
TelEngine::SocketRef::SocketRef
SocketRef(Socket **socket)
Definition: yateclass.h:7562
TelEngine::String::atom
static const String * atom(const String *&str, const char *val)
TelEngine::String::operator<<
String & operator<<(uint64_t value)
Definition: yateclass.h:2477
TelEngine::DebugEnabler::debugName
const char * debugName() const
Definition: yateclass.h:356
TelEngine::MemoryStream::length
virtual int64_t length()
Definition: yateclass.h:6621
TelEngine::Compressor::~Compressor
virtual ~Compressor()
Definition: yateclass.h:8111
TelEngine::String::operator<<
String & operator<<(double value)
Definition: yateclass.h:2489
TelEngine::Array
A list based Array.
Definition: yateclass.h:1622
TelEngine::MemoryStream::MemoryStream
MemoryStream(const DataBlock &data)
Definition: yateclass.h:6577
TelEngine::Socket::bind
bool bind(const SocketAddr &addr)
Definition: yateclass.h:7137
TelEngine::ListIterator::length
unsigned int length() const
Definition: yateclass.h:3541
TelEngine::RefObject::getObject
virtual void * getObject(const String &name) const
TelEngine::SrvRecord::SrvRecord
SrvRecord(int ttl, int prio, int weight, const char *addr, int port)
Definition: yateclass.h:7719
TelEngine::NamedIterator::operator=
NamedIterator & operator=(const NamedIterator &original)
Definition: yateclass.h:4963
TelEngine::Random::set
void set(u_int32_t seed)
Definition: yateclass.h:3820
TelEngine::ObjList::remove
GenObject * remove(bool delobj=true)
TelEngine::NamedPointer::userObject
void * userObject(const String &name) const
Definition: yateclass.h:3276
TelEngine::SocketAddr::familyName
const char * familyName()
Definition: yateclass.h:6062
TelEngine::NaptrRecord::nextName
const String & nextName() const
Definition: yateclass.h:7828
TelEngine::DebugEnabler::debugName
void debugName(const char *name)
Definition: yateclass.h:391
TelEngine::Hasher::Hasher
Hasher()
Definition: yateclass.h:4268
TelEngine::RefPointer::operator=
RefPointer< Obj > & operator=(Obj *object)
Definition: yateclass.h:1136
TelEngine::ObjVector::at
GenObject * at(int index) const
Definition: yateclass.h:1532
TelEngine::NamedList::setParam
NamedList & setParam(NamedString *param)
Definition: yateclass.h:4707
TelEngine::TempObjectCounter
Ephemeral object counter changer.
Definition: yateclass.h:5875
TelEngine::String::stripBOM
static bool stripBOM(const char *&str)
Definition: yateclass.h:2093
TelEngine::Lock::acquire
bool acquire(Lockable &lck, long maxwait=-1)
Definition: yateclass.h:5487
TelEngine::Socket::getParams
virtual bool getParams(const String &params, NamedList &result)
Definition: yateclass.h:7075
TelEngine::CapturedEvent::eventsRw
static ObjList & eventsRw()
Definition: yateclass.h:3166
TelEngine::Resolver::Type
Type
Definition: yateclass.h:7852
TelEngine::Runnable
Encapsulates a runnable task.
Definition: yateclass.h:5583
TelEngine::MemoryStream::valid
virtual bool valid() const
Definition: yateclass.h:6598
TelEngine::CapturedEvent::CapturedEvent
CapturedEvent(int level, const char *text)
Definition: yateclass.h:3119
TelEngine::Compressor::writeComp
int writeComp(const String &data, bool flush)
Definition: yateclass.h:8190
TelEngine::Base64::operator<<
Base64 & operator<<(const DataBlock &data)
Definition: yateclass.h:4612
TelEngine::SctpSocket
Abstract SCTP Socket.
Definition: yateclass.h:7443
TelEngine::SocketAddr::address
struct sockaddr * address() const
Definition: yateclass.h:6122
TelEngine::SHA1
A standard SHA1 digest calculator.
Definition: yateclass.h:4375
TelEngine::GenObject::destruct
virtual void destruct()
TelEngine::GenPointer::GenPointer
GenPointer(Obj *object)
Definition: yateclass.h:1190
TelEngine::Time::Time
Time(const struct timeval *tv)
Definition: yateclass.h:3633
TelEngine::URI
Encapsulation for an URI.
Definition: yateclass.h:4995
TelEngine::SocketAddr::family
int family() const
Definition: yateclass.h:6055
TelEngine::NamedList::count
unsigned int count() const
Definition: yateclass.h:4677
TelEngine::DataBlock::overAlloc
void overAlloc(unsigned int bytes)
Definition: yateclass.h:3948
TelEngine::Time::operator-=
Time & operator-=(int64_t delta)
Definition: yateclass.h:3694
TelEngine::Hasher::operator<<
Hasher & operator<<(const String &value)
Definition: yateclass.h:4174
TelEngine::String::operator=
String & operator=(const String &value)
Definition: yateclass.h:2300
TelEngine::String::operator=
String & operator=(bool value)
Definition: yateclass.h:2352
TelEngine::String::checkBOM
static bool checkBOM(const char *str)
Definition: yateclass.h:2078
TelEngine::URI::operator=
URI & operator=(const URI &value)
Definition: yateclass.h:5040
TelEngine::DataBlock::operator[]
int operator[](signed int index) const
Definition: yateclass.h:4021
TelEngine::SysUsage
A class exposing system resources usage.
Definition: yateclass.h:8248
TelEngine::CapturedEvent::capturing
static void capturing(bool capture)
Definition: yateclass.h:3173
TelEngine::TokenDict::token
const char * token
Definition: yateclass.h:687
TelEngine::lookup
int lookup(const char *str, const TokenDict *tokens, int defvalue=0, int base=0)
TelEngine::DataBlock::operator[]
int operator[](unsigned int index) const
Definition: yateclass.h:4029
TelEngine::CapturedEvent::CapturedEvent
CapturedEvent(const CapturedEvent &original)
Definition: yateclass.h:3127
TelEngine::NamedIterator::eof
bool eof() const
Definition: yateclass.h:4975
TelEngine::ObjList::operator[]
GenObject * operator[](signed int index) const
Definition: yateclass.h:1322
TelEngine::SocketRef::getObject
virtual void * getObject(const String &name) const
Definition: yateclass.h:7579
TelEngine::Base64::operator<<
Base64 & operator<<(const String &value)
Definition: yateclass.h:4606
TelEngine::destruct
void destruct(GenObject *obj)
Definition: yateclass.h:934
TelEngine::Cipher::initVector
bool initVector(const DataBlock &vect, Direction dir=Bidir)
Definition: yateclass.h:8048
TelEngine::MD5::rawLength
static unsigned int rawLength()
Definition: yateclass.h:4353
TelEngine::SocketAddr::host
const String & host() const
Definition: yateclass.h:6084
TelEngine::SocketAddr::scopeId
bool scopeId(unsigned int val)
Definition: yateclass.h:6077
TelEngine::URI::operator=
URI & operator=(const String &value)
Definition: yateclass.h:5047
TelEngine::String::operator[]
char operator[](signed int index) const
Definition: yateclass.h:2252
TelEngine::RefPointerBase::assign
void assign(RefObject *oldptr, RefObject *newptr, void *pointer)
TelEngine::Stream::seek
int64_t seek(int64_t offset)
Definition: yateclass.h:6510
TelEngine::NamedList::paramList
ObjList * paramList()
Definition: yateclass.h:4913
TelEngine::UChar::UChar
UChar(unsigned char code)
Definition: yateclass.h:1775
TelEngine::UChar::operator=
UChar & operator=(uint32_t code)
Definition: yateclass.h:1784
TelEngine::SocketAddr::appendTo
static String & appendTo(String &buf, const String &addr, int port, int family=Unknown)
Definition: yateclass.h:6237
TelEngine::RefPointer::operator*
Obj & operator*() const
Definition: yateclass.h:1155
TelEngine::TxtRecord::TxtRecord
TxtRecord(int ttl, const char *text)
Definition: yateclass.h:7670
TelEngine::RefPointer::RefPointer
RefPointer(Obj *object)
Definition: yateclass.h:1118
TelEngine::Socket::DSCP
DSCP
Definition: yateclass.h:6902
TelEngine::NamedPointer::userData
GenObject * userData() const
Definition: yateclass.h:3254
TelEngine::UChar
A single Unicode character.
Definition: yateclass.h:1739
TelEngine::DataBlock::append
void append(void *value, unsigned int len)
Definition: yateclass.h:3971
TelEngine::DataBlock::unHexify
bool unHexify(const String &data)
Definition: yateclass.h:4089
TelEngine::SocketAddr::appendTo
static String appendTo(const String &addr, int port, int family=Unknown)
Definition: yateclass.h:6250
TelEngine::Time
A time holding class.
Definition: yateclass.h:3611
TelEngine::Time::operator+=
Time & operator+=(int64_t delta)
Definition: yateclass.h:3688
TelEngine::Time::isLeap
static bool isLeap(unsigned int year)
Definition: yateclass.h:3781
TelEngine::SocketAddr::SocketAddr
SocketAddr(const SocketAddr &value)
Definition: yateclass.h:5958
TelEngine::TxtRecord::text
const String & text() const
Definition: yateclass.h:7678
TelEngine::Atom::operator->
const String * operator->() const
Definition: yateclass.h:3098
TelEngine::Lockable::lock
virtual bool lock(long maxwait=-1)=0
TelEngine::GenPointer::operator*
Obj & operator*() const
Definition: yateclass.h:1222
TelEngine::Cipher::Direction
Direction
Definition: yateclass.h:7948
TelEngine::DebugEnabler
A holder for a debug level.
Definition: yateclass.h:309
TelEngine::Lock2::Lock2
Lock2(Mutex *mx1, Mutex *mx2, long maxwait=-1)
Definition: yateclass.h:5516
TelEngine::SocketRef
RefObject holding a Socket pointer.
Definition: yateclass.h:7555
TelEngine::Socket
A generic socket class.
Definition: yateclass.h:6884
TelEngine::MemoryStream::m_data
DataBlock m_data
Definition: yateclass.h:6636
TelEngine::MD5::hashLength
virtual unsigned int hashLength() const
Definition: yateclass.h:4360
TelEngine::Stream::error
int error() const
Definition: yateclass.h:6418
TelEngine::DataBlock::data
void * data() const
Definition: yateclass.h:3902
TelEngine::Lock::acquire
bool acquire(Lockable *lck, long maxwait=-1)
Definition: yateclass.h:5477
TelEngine::Hasher
An abstract hashing class.
Definition: yateclass.h:4111
TelEngine::DebugLevel
DebugLevel
Definition: yateclass.h:254
TelEngine::TempObjectCounter::TempObjectCounter
TempObjectCounter(NamedCounter *counter, bool enable=GenObject::getObjCounting())
Definition: yateclass.h:5884
TelEngine::NamedList::empty
static const NamedList & empty()
TelEngine::ListIterator::reset
void reset()
Definition: yateclass.h:3595
TelEngine::String::msgUnescape
String msgUnescape(int *errptr=0, char extraEsc=0) const
Definition: yateclass.h:2790
TelEngine::String::lenUtf8
int lenUtf8(uint32_t maxChar=0x10ffff, bool overlong=false) const
Definition: yateclass.h:2060
TelEngine::String::operator<<
String & operator<<(char value)
Definition: yateclass.h:2453
TelEngine::Debugger
An object that logs messages on creation and destruction.
Definition: yateclass.h:570
TelEngine::URI::getPort
int getPort() const
Definition: yateclass.h:5089
TelEngine::NamedIterator::reset
void reset()
Definition: yateclass.h:4981
TelEngine::Atom
Atom string holder.
Definition: yateclass.h:3076
TelEngine::String::operator<<
String & operator<<(int32_t value)
Definition: yateclass.h:2459
TelEngine::DebugEnabler::debugChain
void debugChain(const DebugEnabler *chain=0)
Definition: yateclass.h:377
TelEngine::NamedPointer
A named pointer class.
Definition: yateclass.h:3234
TelEngine::NamedCounter::enabled
bool enabled() const
Definition: yateclass.h:3321
TelEngine::YOBJECT
class * YOBJECT(class type, GenObject *pntr)
TelEngine::SocketAddr::length
socklen_t length() const
Definition: yateclass.h:6129
TelEngine::YATOM
constant YATOM(const char *string)
TelEngine::String::operator<<
String & operator<<(bool value)
Definition: yateclass.h:2483
TelEngine::Cipher::setKey
bool setKey(const DataBlock &key, Direction dir=Bidir)
Definition: yateclass.h:8030
TelEngine::DDebug
void DDebug(int level, const char *format,...)
TelEngine::URI::getDescription
const String & getDescription() const
Definition: yateclass.h:5061
TelEngine::GenPointer::operator->
Obj * operator->() const
Definition: yateclass.h:1216
TelEngine::MemoryStream::m_offset
int64_t m_offset
Definition: yateclass.h:6641
TelEngine::NamedString
A named string class.
Definition: yateclass.h:3186
TelEngine::Compressor::finalize
virtual void finalize(bool comp)
Definition: yateclass.h:8136
TelEngine::SHA256
A standard SHA256 digest calculator.
Definition: yateclass.h:4472
TelEngine::Socket::setTOS
bool setTOS(const char *tos, int defTos=Normal)
Definition: yateclass.h:7091
TelEngine::String::msgEscape
String msgEscape(char extraEsc=0) const
Definition: yateclass.h:2772
TelEngine::String::operator!=
bool operator!=(const String &value) const
Definition: yateclass.h:2431
TelEngine::SHA256::rawLength
static unsigned int rawLength()
Definition: yateclass.h:4537
TelEngine::Lock::drop
void drop()
Definition: yateclass.h:5468
TelEngine::String::operator==
bool operator==(const String &value) const
Definition: yateclass.h:2425
TelEngine::Resolver
DNS services.
Definition: yateclass.h:7846
TelEngine::Array::getColumns
int getColumns() const
Definition: yateclass.h:1710
TelEngine::c_str
const char * c_str(const String *str)
Definition: yateclass.h:2880
TelEngine::DebugEnabler::DebugEnabler
DebugEnabler(int level=TelEngine::debugLevel(), bool enabled=true)
Definition: yateclass.h:317
TelEngine::null
bool null(const char *str)
Definition: yateclass.h:2904
TelEngine::NDebug
void NDebug(int level, const char *format,...)
TelEngine::DnsRecord::pref
int pref() const
Definition: yateclass.h:7631
TelEngine::GenObject::getObject
static void * getObject(const String &name, const GenObject *obj)
Definition: yateclass.h:879
TelEngine::URI::getHost
const String & getHost() const
Definition: yateclass.h:5082
TelEngine::GenObject::getObjCounter
NamedCounter * getObjCounter() const
Definition: yateclass.h:900
TelEngine::Base64
Base64 encoder/decoder class.
Definition: yateclass.h:4559
TelEngine::YCLASSIMP3
void YCLASSIMP3(class type, class base1, class base2, class base3)
TelEngine::HashList
A hashed object list class.
Definition: yateclass.h:3363
TelEngine::SctpSocket::SctpSocket
SctpSocket()
Definition: yateclass.h:7450
TelEngine::DataBlock::clear
void clear(bool deleteData=true)
TelEngine::String::stripBOM
bool stripBOM()
Definition: yateclass.h:2108
TelEngine::SocketAddr::addr
const String & addr() const
Definition: yateclass.h:6091
TelEngine::RefObject::refcount
int refcount() const
Definition: yateclass.h:1000
TelEngine::YCLASSIMP
void YCLASSIMP(class type, class base)
TelEngine::Base64::operator<<
Base64 & operator<<(const char *value)
Definition: yateclass.h:4618
TelEngine::NamedList
A named string container class.
Definition: yateclass.h:4628
TelEngine::operator+
String operator+(const String &s1, const String &s2)
TelEngine::RefPointerBase::m_pointer
void * m_pointer
Definition: yateclass.h:1076
TelEngine::DataBlock::operator+=
DataBlock & operator+=(const String &value)
Definition: yateclass.h:4046
TelEngine::URI::getProtocol
const String & getProtocol() const
Definition: yateclass.h:5068
TelEngine::String::operator[]
char operator[](unsigned int index) const
Definition: yateclass.h:2260
TelEngine::Regexp::matches
virtual bool matches(const String &value) const
Definition: yateclass.h:3030
TelEngine::RefPointer
Templated smart pointer class.
Definition: yateclass.h:1082
TelEngine::Lock
Ephemeral mutex or semaphore locking object.
Definition: yateclass.h:5432
TelEngine::Lock2::Lock2
Lock2(Mutex &mx1, Mutex &mx2, long maxwait=-1)
Definition: yateclass.h:5526
TelEngine::SctpSocket::accept
virtual Socket * accept(SocketAddr &addr)
Definition: yateclass.h:7496
TelEngine::Hasher::hmacStart
bool hmacStart(DataBlock &opad, const String &key)
Definition: yateclass.h:4214
TelEngine::YCLASS3
void YCLASS3(class type, class base1, class base2, class base3)
TelEngine::Random
Pseudo random number generator.
Definition: yateclass.h:3798
TelEngine::operator<<
String & operator<<(String &str, const Complex &c)
Definition: yatemath.h:1685
TelEngine::GenPointer::GenPointer
GenPointer(const GenPointer< Obj > &value)
Definition: yateclass.h:1182
TelEngine::Hasher::update
bool update(const void *buf, unsigned int len)
Definition: yateclass.h:4151
TelEngine::Hasher::operator<<
Hasher & operator<<(const DataBlock &data)
Definition: yateclass.h:4181
TelEngine::Semaphore
Semaphore implementation.
Definition: yateclass.h:5354
TelEngine::Stream
An abstract stream class capable of reading and writing.
Definition: yateclass.h:6397
TelEngine::YCLASSIMP2
void YCLASSIMP2(class type, class base1, class base2)
TelEngine::Stream::clearError
void clearError()
Definition: yateclass.h:6552
TelEngine::Base64::Base64
Base64()
Definition: yateclass.h:4566
TelEngine::String::append
String & append(const ObjList &list, const char *separator=0, bool force=false)
Definition: yateclass.h:2553
TelEngine::TempObjectCounter::TempObjectCounter
TempObjectCounter(const GenObject *obj, bool enable=GenObject::getObjCounting())
Definition: yateclass.h:5893
TelEngine::MemoryStream
A Stream that operates on DataBlocks in memory.
Definition: yateclass.h:6562
TelEngine::GenPointer
Templated pointer that can be inserted in a list.
Definition: yateclass.h:1162
TelEngine::Cipher::encrypt
bool encrypt(DataBlock &data)
Definition: yateclass.h:8065
TelEngine::String::matches
virtual bool matches(const String &value) const
Definition: yateclass.h:2706
TelEngine::Thread::errorString
static bool errorString(String &buffer)
Definition: yateclass.h:5830
TelEngine::GenObject::getObject
virtual void * getObject(const String &name) const
TelEngine::Time::Time
Time(const struct timeval &tv)
Definition: yateclass.h:3641
TelEngine::Lock2
Ephemeral double mutex locking object.
Definition: yateclass.h:5506
TelEngine::SocketAddr::valid
bool valid() const
Definition: yateclass.h:6041
TelEngine::Time::now
static u_int64_t now()
TelEngine::ObjVector::length
unsigned int length() const
Definition: yateclass.h:1512
TelEngine::Compressor::writeDecomp
int writeDecomp(const DataBlock &data, bool flush)
Definition: yateclass.h:8218
TelEngine::CapturedEvent::level
int level() const
Definition: yateclass.h:3135
TelEngine::SctpSocket::SctpSocket
SctpSocket(SOCKET fd)
Definition: yateclass.h:7457
TelEngine::HashList::getHashList
ObjList * getHashList(const String &str) const
Definition: yateclass.h:3420
TelEngine::Thread::isCurrent
bool isCurrent() const
Definition: yateclass.h:5760
TelEngine::Thread::setCurrentObjCounter
static NamedCounter * setCurrentObjCounter(NamedCounter *counter)
TelEngine::File::handle
HANDLE handle() const
Definition: yateclass.h:6706
TelEngine::CapturedEvent::events
static const ObjList & events()
Definition: yateclass.h:3150
TelEngine::TxtRecord
A text based DNS record.
Definition: yateclass.h:7660
TelEngine
Definition: yateclass.h:217
TelEngine::Stream::writeData
int writeData(const String &str)
Definition: yateclass.h:6472
TelEngine::DnsRecord::ttl
int ttl() const
Definition: yateclass.h:7617
TelEngine::MemoryStream::data
const DataBlock & data() const
Definition: yateclass.h:6585
TelEngine::Socket::TOS
TOS
Definition: yateclass.h:6891
TelEngine::NamedPointer::operator=
NamedPointer & operator=(const char *value)
Definition: yateclass.h:3282
TelEngine::NamedString::operator=
NamedString & operator=(const char *value)
Definition: yateclass.h:3220
TelEngine::NamedList::paramList
const ObjList * paramList() const
Definition: yateclass.h:4920
TelEngine::SocketAddr::operator!=
bool operator!=(const SocketAddr &other) const
Definition: yateclass.h:6001
TelEngine::String
A C-style string handling class.
Definition: yateclass.h:1907
TelEngine::Atom::Atom
Atom(const char *value)
Definition: yateclass.h:3083
TelEngine::RefPointer::assign
void assign(Obj *object=0)
Definition: yateclass.h:1096
TelEngine::Lock2::locked
bool locked() const
Definition: yateclass.h:5540
TelEngine::strcpy
const char * strcpy(String &dest, const char *src)
Definition: yateclass.h:2934
TelEngine::ListIterator
Class used to iterate the items of a list.
Definition: yateclass.h:3512
TelEngine::TokenDict
Definition: yateclass.h:683
TelEngine::Cipher::directions
static const TokenDict * directions()
Definition: yateclass.h:7958
TelEngine::Thread::Priority
Priority
Definition: yateclass.h:5614
TelEngine::UChar::c_str
const char * c_str() const
Definition: yateclass.h:1806
TelEngine::Socket::setIpv6OnlyOption
bool setIpv6OnlyOption(bool on)
Definition: yateclass.h:7043
TelEngine::Time::Time
Time(u_int64_t usec)
Definition: yateclass.h:3625
TelEngine::ObjVector::autoDelete
bool autoDelete()
Definition: yateclass.h:1598
TelEngine::TempObjectCounter::TempObjectCounter
TempObjectCounter(const GenObject &obj, bool enable=GenObject::getObjCounting())
Definition: yateclass.h:5902
TelEngine::debugLevelName
const char * debugLevelName(int level)
TelEngine::DnsRecord::DnsRecord
DnsRecord(int ttl, int order, int pref)
Definition: yateclass.h:7602
TelEngine::Socket::setParams
virtual bool setParams(const NamedList &params)
Definition: yateclass.h:7066
TelEngine::Time::usec
u_int64_t usec() const
Definition: yateclass.h:3670
TelEngine::String::safe
const char * safe() const
Definition: yateclass.h:2020
TelEngine::Compressor::writeComp
int writeComp(const DataBlock &data, bool flush)
Definition: yateclass.h:8179
TelEngine::SocketAddr::scopeId
static bool scopeId(struct sockaddr *addr, unsigned int val)
Definition: yateclass.h:6210
TelEngine::Output
void Output(const char *format,...)
TelEngine::NaptrRecord::serv
const String & serv() const
Definition: yateclass.h:7807
TelEngine::ObjList
An object list class.
Definition: yateclass.h:1230
TelEngine::DataBlock::length
unsigned int length() const
Definition: yateclass.h:3934
TelEngine::String::length
unsigned int length() const
Definition: yateclass.h:2035
TelEngine::Alarm
void Alarm(const char *component, int level, const char *format,...)
TelEngine::Lock::Lock
Lock(Lockable *lck, long maxwait=-1)
Definition: yateclass.h:5449
TelEngine::debugAt
bool debugAt(int level)
TelEngine::DataBlock::null
bool null() const
Definition: yateclass.h:3927
TelEngine::YNOCOPY
void YNOCOPY(class type)
TelEngine::NamedList::clearParams
void clearParams()
Definition: yateclass.h:4683
TelEngine::NaptrRecord::repTemplate
const String & repTemplate() const
Definition: yateclass.h:7821
TelEngine::YCLASS
void YCLASS(class type, class base)
TelEngine::NamedIterator::NamedIterator
NamedIterator(const NamedIterator &original)
Definition: yateclass.h:4948
TelEngine::SocketAddr::scopeId
unsigned int scopeId() const
Definition: yateclass.h:6069
TelEngine::ObjList::setDelete
void setDelete(bool autodelete)
Definition: yateclass.h:1436
TelEngine::TempObjectCounter::~TempObjectCounter
~TempObjectCounter()
Definition: yateclass.h:5909
TelEngine::String::stripBOM
static bool stripBOM(char *&str)
Definition: yateclass.h:2101
TelEngine::abortOnBug
void abortOnBug()
TelEngine::DebugEnabler::debugEnabled
bool debugEnabled() const
Definition: yateclass.h:342
TelEngine::DataBlock::at
int at(unsigned int offs, int defvalue=-1) const
Definition: yateclass.h:3920
TelEngine::Hasher::update
bool update(const DataBlock &data)
Definition: yateclass.h:4159
TelEngine::SysUsage::Type
Type
Definition: yateclass.h:8254
TelEngine::HashList::getHashList
ObjList * getHashList(unsigned int hash) const
Definition: yateclass.h:3412
TelEngine::DnsRecord::DnsRecord
DnsRecord()
Definition: yateclass.h:7609
TelEngine::NamedIterator
NamedList parameters iterator.
Definition: yateclass.h:4933
TelEngine::ObjVector
A vector holding GenObjects.
Definition: yateclass.h:1468
TelEngine::MemoryStream::terminate
virtual bool terminate()
Definition: yateclass.h:6592
TelEngine::SrvRecord
A SRV record.
Definition: yateclass.h:7706
TelEngine::Random::Random
Random(u_int32_t seed=Time::now()&0xffffffff)
Definition: yateclass.h:3805
TelEngine::RefPointer::operator->
Obj * operator->() const
Definition: yateclass.h:1149
TelEngine::Lock::locked
Lockable * locked() const
Definition: yateclass.h:5462
TelEngine::MutexPool::mutex
Mutex * mutex(unsigned int idx) const
Definition: yateclass.h:5341
TelEngine::YIGNORE
void YIGNORE(primitive value)
TelEngine::Regexp::matches
bool matches(const char *value) const
TelEngine::UChar::UChar
UChar(signed char code)
Definition: yateclass.h:1767
TelEngine::SocketAddr::Family
Family
Definition: yateclass.h:5930
TelEngine::Mutex
Mutex support.
Definition: yateclass.h:5206
TelEngine::String::hash
unsigned int hash() const
Definition: yateclass.h:2115
TelEngine::MD5
A standard MD5 digest calculator.
Definition: yateclass.h:4288
TelEngine::RefPointerBase::RefPointerBase
RefPointerBase()
Definition: yateclass.h:1062
TelEngine::Compressor
An abstract data (de)compressor.
Definition: yateclass.h:8094
TelEngine::String::operator=
String & operator=(const String *value)
Definition: yateclass.h:2308
TelEngine::Engine
Engine globals.
Definition: yatengine.h:1161
TelEngine::GenObject
Definition: yateclass.h:831
TelEngine::SocketAddr::SocketAddr
SocketAddr()
Definition: yateclass.h:5950
TelEngine::DebugEnabler::debugEnabled
void debugEnabled(bool enable)
Definition: yateclass.h:349
TelEngine::DataBlock::overAlloc
unsigned int overAlloc() const
Definition: yateclass.h:3941
TelEngine::String::operator<<
String & operator<<(uint32_t value)
Definition: yateclass.h:2465
TelEngine::Array::getRows
int getRows() const
Definition: yateclass.h:1703
TelEngine::controlReturn
bool controlReturn(NamedList *params, bool ret, const char *retVal=0)
TelEngine::Cipher::direction
static Direction direction(const char *name, Direction defdir=Bidir)
Definition: yateclass.h:7967
TelEngine::String::operator+=
String & operator+=(const char *value)
Definition: yateclass.h:2366
TelEngine::NamedCounter
Atomic counter with name.
Definition: yateclass.h:3307
TelEngine::YCLASS2
void YCLASS2(class type, class base1, class base2)