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
700 struct TokenDict64 {
704 const char* token;
705
709 int64_t value;
710 };
711
712 class String;
713 class DataBlock;
714 class Mutex;
715 class ObjList;
716 class NamedCounter;
717
718 #if 0 /* for documentation generator */
719
723 void YIGNORE(primitive value);
724
730 constant YSTRING(const char* string);
731
737 constant YATOM(const char* string);
738
744 void YCLASS(class type,class base);
745
752 void YCLASS2(class type,class base1,class base2);
753
761 void YCLASS3(class type,class base1,class base2,class base3);
762
768 void YCLASSIMP(class type,class base);
769
776 void YCLASSIMP2(class type,class base1,class base2);
777
785 void YCLASSIMP3(class type,class base1,class base2,class base3);
786
793 class* YOBJECT(class type,GenObject* pntr);
794
799 void YNOCOPY(class type);
800 #endif
801
802 #define YCLASS(type,base) \
803 public: virtual void* getObject(const String& name) const \
804 { return (name == YATOM(#type)) ? const_cast<type*>(this) : base::getObject(name); }
805
806 #define YCLASS2(type,base1,base2) \
807 public: virtual void* getObject(const String& name) const \
808 { if (name == YATOM(#type)) return const_cast<type*>(this); \
809 void* tmp = base1::getObject(name); \
810 return tmp ? tmp : base2::getObject(name); }
811
812 #define YCLASS3(type,base1,base2,base3) \
813 public: virtual void* getObject(const String& name) const \
814 { if (name == YATOM(#type)) return const_cast<type*>(this); \
815 void* tmp = base1::getObject(name); \
816 if (tmp) return tmp; \
817 tmp = base2::getObject(name); \
818 return tmp ? tmp : base3::getObject(name); }
819
820 #define YCLASSIMP(type,base) \
821 void* type::getObject(const String& name) const \
822 { return (name == YATOM(#type)) ? const_cast<type*>(this) : base::getObject(name); }
823
824 #define YCLASSIMP2(type,base1,base2) \
825 void* type::getObject(const String& name) const \
826 { if (name == YATOM(#type)) return const_cast<type*>(this); \
827 void* tmp = base1::getObject(name); \
828 return tmp ? tmp : base2::getObject(name); }
829
830 #define YCLASSIMP3(type,base1,base2,base3) \
831 void* type::getObject(const String& name) const \
832 { if (name == YATOM(#type)) return const_cast<type*>(this); \
833 void* tmp = base1::getObject(name); \
834 if (tmp) return tmp; \
835 tmp = base2::getObject(name); \
836 return tmp ? tmp : base3::getObject(name); }
837
838 #define YOBJECT(type,pntr) (static_cast<type*>(GenObject::getObject(YATOM(#type),pntr)))
839
840 #define YNOCOPY(type) private: \
841 type(const type&); \
842 void operator=(const type&)
843
844
848 class YATE_API GenObject
849 {
850 YNOCOPY(GenObject); // no automatic copies please
851 public:
855 GenObject();
856
860 virtual ~GenObject() { setObjCounter(0); }
861
868 virtual bool alive() const;
869
873 virtual void destruct();
874
881 virtual const String& toString() const;
882
888 virtual void* getObject(const String& name) const;
889
896 static inline void* getObject(const String& name, const GenObject* obj)
897 { return obj ? obj->getObject(name) : 0; }
898
903 static inline bool getObjCounting()
904 { return s_counting; }
905
910 static inline void setObjCounting(bool enable)
911 { s_counting = enable; }
912
917 inline NamedCounter* getObjCounter() const
918 { return m_counter; }
919
925 NamedCounter* setObjCounter(NamedCounter* counter);
926
933 static NamedCounter* getObjCounter(const String& name, bool create = true);
934
939 static ObjList& getObjCounters();
940
941 private:
942 NamedCounter* m_counter;
943 static bool s_counting;
944 };
945
951 inline void destruct(GenObject* obj)
952 { if (obj) obj->destruct(); }
953
960 template <class Obj> void destruct(Obj*& obj)
961 { if (obj) { obj->destruct(); obj = 0; } }
962
967 class YATE_API RefObject : public GenObject
968 {
969 YNOCOPY(RefObject); // no automatic copies please
970 public:
975 RefObject();
976
980 virtual ~RefObject();
981
987 virtual void* getObject(const String& name) const;
988
995 virtual bool alive() const;
996
1001 bool ref();
1002
1011 bool deref();
1012
1017 inline int refcount() const
1018 { return m_refcount; }
1019
1024 virtual void destruct();
1025
1031 inline static bool alive(const RefObject* obj)
1032 { return obj && (obj->refcount() > 0); }
1033
1039 static bool efficientIncDec();
1040
1041 protected:
1047 virtual void zeroRefs();
1048
1054 bool resurrect();
1055
1061 virtual void destroyed();
1062
1063 private:
1064 int m_refcount;
1065 Mutex* m_mutex;
1066 };
1067
1073 class YATE_API RefPointerBase
1074 {
1075 protected:
1079 inline RefPointerBase()
1080 : m_pointer(0) { }
1081
1088 void assign(RefObject* oldptr, RefObject* newptr, void* pointer);
1089
1093 void* m_pointer;
1094 };
1095
1099 template <class Obj = RefObject> class RefPointer : public RefPointerBase
1100 {
1101 protected:
1106 inline Obj* pointer() const
1107 { return static_cast<Obj*>(m_pointer); }
1108
1113 inline void assign(Obj* object = 0)
1114 { RefPointerBase::assign(pointer(),object,object); }
1115
1116 public:
1120 inline RefPointer()
1121 { }
1122
1127 inline RefPointer(const RefPointer<Obj>& value)
1128 : RefPointerBase()
1129 { assign(value); }
1130
1135 inline RefPointer(Obj* object)
1136 { assign(object); }
1137
1141 inline ~RefPointer()
1142 { assign(); }
1143
1147 inline RefPointer<Obj>& operator=(const RefPointer<Obj>& value)
1148 { assign(value.pointer()); return *this; }
1149
1153 inline RefPointer<Obj>& operator=(Obj* object)
1154 { assign(object); return *this; }
1155
1160 inline operator Obj*() const
1161 { return pointer(); }
1162
1166 inline Obj* operator->() const
1167 { return pointer(); }
1168
1172 inline Obj& operator*() const
1173 { return *pointer(); }
1174 };
1175
1179 template <class Obj = GenObject> class GenPointer : public GenObject
1180 {
1181 private:
1185 Obj* m_pointer;
1186
1187 public:
1191 inline GenPointer()
1192 : m_pointer(0)
1193 { }
1194
1199 inline GenPointer(const GenPointer<Obj>& value)
1200 : m_pointer(value)
1201 { }
1202
1207 inline GenPointer(Obj* object)
1208 : m_pointer(object)
1209 { }
1210
1214 inline GenPointer<Obj>& operator=(const GenPointer<Obj>& value)
1215 { m_pointer = value; return *this; }
1216
1220 inline GenPointer<Obj>& operator=(Obj* object)
1221 { m_pointer = object; return *this; }
1222
1227 inline operator Obj*() const
1228 { return m_pointer; }
1229
1233 inline Obj* operator->() const
1234 { return m_pointer; }
1235
1239 inline Obj& operator*() const
1240 { return *m_pointer; }
1241 };
1242
1247 class YATE_API ObjList : public GenObject
1248 {
1249 YNOCOPY(ObjList); // no automatic copies please
1250 public:
1254 ObjList();
1255
1259 virtual ~ObjList();
1260
1266 virtual void* getObject(const String& name) const;
1267
1272 unsigned int length() const;
1273
1278 unsigned int count() const;
1279
1284 inline GenObject* get() const
1285 { return m_obj; }
1286
1293 GenObject* set(const GenObject* obj, bool delold = true);
1294
1299 inline ObjList* next() const
1300 { return m_next; }
1301
1306 ObjList* last() const;
1307
1312 ObjList* skipNull() const;
1313
1318 ObjList* skipNext() const;
1319
1325 GenObject* at(int index) const;
1326
1332 ObjList* operator+(int index) const;
1333
1339 inline GenObject* operator[](signed int index) const
1340 { return at(index); }
1341
1347 inline GenObject* operator[](unsigned int index) const
1348 { return at(index); }
1349
1355 GenObject* operator[](const String& str) const;
1356
1362 ObjList* find(const GenObject* obj) const;
1363
1369 ObjList* find(const String& str) const;
1370
1376 int index(const GenObject* obj) const;
1377
1383 int index(const String& str) const;
1384
1391 ObjList* insert(const GenObject* obj, bool compact = true);
1392
1399 ObjList* append(const GenObject* obj, bool compact = true);
1400
1407 ObjList* setUnique(const GenObject* obj, bool compact = true);
1408
1414 GenObject* remove(bool delobj = true);
1415
1422 GenObject* remove(GenObject* obj, bool delobj = true);
1423
1430 GenObject* remove(const String& str, bool delobj = true);
1431
1435 void clear();
1436
1440 void compact();
1441
1446 inline bool autoDelete()
1447 { return m_delete; }
1448
1453 inline void setDelete(bool autodelete)
1454 { m_delete = autodelete; }
1455
1460 static const ObjList& empty();
1461
1474 void sort(int (*callbackCompare)(GenObject* obj1, GenObject* obj2, void* context), void* context = 0);
1475 private:
1476 ObjList* m_next;
1477 GenObject* m_obj;
1478 bool m_delete;
1479 };
1480
1485 class YATE_API ObjVector : public GenObject
1486 {
1487 YNOCOPY(ObjVector); // no automatic copies please
1488 public:
1493 inline explicit ObjVector(bool autodelete = true)
1494 : m_length(0), m_objects(0), m_delete(autodelete)
1495 { }
1496
1502 ObjVector(unsigned int maxLen, bool autodelete = true);
1503
1511 ObjVector(ObjList& list, bool move = true, unsigned int maxLen = 0, bool autodelete = true);
1512
1516 virtual ~ObjVector();
1517
1523 virtual void* getObject(const String& name) const;
1524
1529 inline unsigned int length() const
1530 { return m_length; }
1531
1536 unsigned int count() const;
1537
1542 bool null() const;
1543
1549 inline GenObject* at(int index) const
1550 { return (index >= 0 && index < (int)m_length) ? m_objects[index] : 0; }
1551
1557 inline GenObject* operator[](signed int index) const
1558 { return at(index); }
1559
1565 inline GenObject* operator[](unsigned int index) const
1566 { return at(index); }
1567
1575 unsigned int assign(ObjList& list, bool move = true, unsigned int maxLen = 0);
1576
1582 GenObject* take(unsigned int index);
1583
1590 bool set(GenObject* obj, unsigned int index);
1591
1597 int index(const GenObject* obj) const;
1598
1604 int index(const String& str) const;
1605
1609 void clear();
1610
1615 inline bool autoDelete()
1616 { return m_delete; }
1617
1622 inline void setDelete(bool autodelete)
1623 { m_delete = autodelete; }
1624
1625 private:
1626 unsigned int m_length;
1627 GenObject** m_objects;
1628 bool m_delete;
1629 };
1630
1639 class YATE_API Array : public RefObject
1640 {
1641 public:
1647 explicit Array(int columns = 0, int rows = 0);
1648
1652 virtual ~Array();
1653
1659 virtual void* getObject(const String& name) const;
1660
1667 bool addRow(ObjList* row = 0, int index = -1);
1668
1675 bool addColumn(ObjList* column = 0, int index = -1);
1676
1682 bool delRow(int index);
1683
1689 bool delColumn(int index);
1690
1697 GenObject* get(int column, int row) const;
1698
1705 GenObject* take(int column, int row);
1706
1714 bool set(GenObject* obj, int column, int row);
1715
1720 inline int getRows() const
1721 { return m_rows; }
1722
1727 inline int getColumns() const
1728 { return m_columns; }
1729
1737 inline ObjList* getColumn(int column) const {
1738 if (column >= 0 || column < m_columns)
1739 return static_cast<ObjList*>(m_obj[column]);
1740 return 0;
1741 }
1742
1743 private:
1744 int m_rows;
1745 int m_columns;
1746 ObjList m_obj;
1747 };
1748
1749 class Regexp;
1750 class StringMatchPrivate;
1751
1756 class YATE_API UChar
1757 {
1758 public:
1759 enum Endianness {
1760 LE = 0,
1761 BE = 1,
1762 Native = 2,
1763 };
1768 inline explicit UChar(uint32_t code = 0)
1769 : m_chr(code)
1770 { encode(); }
1771
1776 inline explicit UChar(int32_t code)
1777 : m_chr((code < 0) ? 0 : code)
1778 { encode(); }
1779
1784 inline explicit UChar(signed char code)
1785 : m_chr((unsigned char)code)
1786 { encode(); }
1787
1792 inline explicit UChar(unsigned char code)
1793 : m_chr(code)
1794 { encode(); }
1795
1801 inline UChar& operator=(uint32_t code)
1802 { m_chr = code; encode(); return *this; }
1803
1809 inline UChar& operator=(char code)
1810 { m_chr = (unsigned char)code; encode(); return *this; }
1811
1816 inline uint32_t code() const
1817 { return m_chr; }
1818
1823 inline const char* c_str() const
1824 { return m_str; }
1825
1830 inline operator const char*() const
1831 { return m_str; };
1832
1840 bool decode(const char*& str, uint32_t maxChar = 0x10ffff, bool overlong = false);
1841
1850 bool decode(uint16_t*& buff, unsigned int& len, Endianness order, uint32_t maxChar = 0x10ffff);
1851
1859 bool decode(DataBlock& buff, Endianness order, uint32_t maxChar = 0x10ffff);
1860
1868 bool encode(uint16_t*& buff, unsigned int& len, Endianness order);
1869
1876 bool encode(DataBlock& buff, Endianness order);
1877
1888 static bool decode(String& out, uint16_t*& buff, unsigned int& len, Endianness order, bool checkBOM = false, uint32_t maxChar = 0x10ffff);
1889
1898 static bool encode(DataBlock& out, const char*& str, Endianness order, bool addBOM = false);
1899
1909 static bool encode(uint16_t*& buff, unsigned int& len, const char*& str, Endianness order, bool addBOM = false);
1910
1911 private:
1912 void encode();
1913 uint32_t m_chr;
1914 char m_str[8];
1915 };
1916
1924 class YATE_API String : public GenObject
1925 {
1926 public:
1927 enum Align {
1928 Left = 0,
1929 Center,
1930 Right
1931 };
1932
1936 String();
1937
1943 String(const char* value, int len = -1);
1944
1950 explicit String(char value, unsigned int repeat = 1);
1951
1956 explicit String(int32_t value);
1957
1962 explicit String(uint32_t value);
1963
1968 explicit String(int64_t value);
1969
1974 explicit String(uint64_t value);
1975
1980 explicit String(bool value);
1981
1986 explicit String(double value);
1987
1992 String(const String& value);
1993
1998 String(const String* value);
1999
2003 virtual ~String();
2004
2010 virtual void* getObject(const String& name) const;
2011
2016 static const String& empty();
2017
2023 inline static const char* boolText(bool value)
2024 { return value ? "true" : "false"; }
2025
2030 inline const char* c_str() const
2031 { return m_string; }
2032
2037 inline const char* safe() const
2038 { return m_string ? m_string : ""; }
2039
2045 inline const char* safe(const char* defStr) const
2046 { return m_string ? m_string : (defStr ? defStr : ""); }
2047
2052 inline unsigned int length() const
2053 { return m_length; }
2054
2059 inline bool null() const
2060 { return !m_string; }
2061
2069 static int lenUtf8(const char* value, uint32_t maxChar = 0x10ffff, bool overlong = false);
2070
2077 inline int lenUtf8(uint32_t maxChar = 0x10ffff, bool overlong = false) const
2078 { return lenUtf8(m_string,maxChar,overlong); }
2079
2080
2088 int fixUtf8(const char* replace = 0, uint32_t maxChar = 0x10ffff, bool overlong = false);
2089
2095 unsigned int encodeFlags(const TokenDict* tokens) const;
2096
2102 uint64_t encodeFlags(const TokenDict64* tokens) const;
2103
2111 const String& decodeFlags(unsigned int flags, const TokenDict* tokens, bool unknownflag = true);
2112
2120 const String& decodeFlags(uint64_t flags, const TokenDict64* tokens, bool unknownflag = true);
2126 inline static bool checkBOM(const char* str)
2127 { return str && (str[0] == '\357') && (str[1] == '\273') && (str[2] == '\277'); }
2128
2133 inline bool checkBOM() const
2134 { return checkBOM(c_str()); }
2135
2141 inline static bool stripBOM(const char*& str)
2142 { return checkBOM(str) && (str += 3); }
2143
2149 inline static bool stripBOM(char*& str)
2150 { return checkBOM(str) && (str += 3); }
2151
2156 inline bool stripBOM()
2157 { return checkBOM(c_str()) && &(*this = c_str() + 3); }
2158
2163 inline unsigned int hash() const
2164 {
2165 if (m_hash == YSTRING_INIT_HASH)
2166 m_hash = hash(m_string);
2167 return m_hash;
2168 }
2169
2176 static unsigned int hash(const char* value, unsigned int h = 0);
2177
2181 void clear();
2182
2188 char at(int index) const;
2189
2196 String substr(int offs, int len = -1) const;
2197
2201 String& trimBlanks();
2202
2207 String& trimSpaces();
2208
2213 virtual const String& toString() const;
2214
2225 int toInteger(int defvalue = 0, int base = 0, int minvalue = INT_MIN,
2226 int maxvalue = INT_MAX, bool clamp = true) const;
2227
2235 int toInteger(const TokenDict* tokens, int defvalue = 0, int base = 0) const;
2236
2247 long int toLong(long int defvalue = 0, int base = 0, long int minvalue = LONG_MIN,
2248 long int maxvalue = LONG_MAX, bool clamp = true) const;
2249
2260 int64_t toInt64(int64_t defvalue = 0, int base = 0, int64_t minvalue = LLONG_MIN,
2261 int64_t maxvalue = LLONG_MAX, bool clamp = true) const;
2262
2268 double toDouble(double defvalue = 0.0) const;
2269
2275 bool toBoolean(bool defvalue = false) const;
2276
2281 bool isBoolean() const;
2282
2287 String& toUpper();
2288
2293 String& toLower();
2294
2300 inline char operator[](signed int index) const
2301 { return at(index); }
2302
2308 inline char operator[](unsigned int index) const
2309 { return at(index); }
2310
2315 inline operator const char*() const
2316 { return m_string; };
2317
2324 String& assign(const char* value, int len = -1);
2325
2332 String& assign(char value, unsigned int repeat = 1);
2333
2342 String& hexify(void* data, unsigned int len, char sep = 0, bool upCase = false);
2343
2348 inline String& operator=(const String& value)
2349 { return operator=(value.c_str()); }
2350
2356 inline String& operator=(const String* value)
2357 { return operator=(value ? value->c_str() : ""); }
2358
2364 String& operator=(const char* value);
2365
2370 String& operator=(char value);
2371
2376 String& operator=(int32_t value);
2377
2382 String& operator=(uint32_t value);
2383
2388 String& operator=(int64_t value);
2389
2394 String& operator=(uint64_t value);
2395
2400 inline String& operator=(bool value)
2401 { return operator=(boolText(value)); }
2402
2407 String& operator=(double value);
2408
2414 inline String& operator+=(const char* value)
2415 { return append(value,-1); }
2416
2421 String& operator+=(char value);
2422
2427 String& operator+=(int32_t value);
2428
2433 String& operator+=(uint32_t value);
2434
2439 String& operator+=(int64_t value);
2440
2445 String& operator+=(uint64_t value);
2446
2451 inline String& operator+=(bool value)
2452 { return operator+=(boolText(value)); }
2453
2458 String& operator+=(double value);
2459
2463 bool operator==(const char* value) const;
2464
2468 bool operator!=(const char* value) const;
2469
2473 inline bool operator==(const String& value) const
2474 { return (this == &value) || ((hash() == value.hash()) && operator==(value.c_str())); }
2475
2479 inline bool operator!=(const String& value) const
2480 { return (this != &value) && ((hash() != value.hash()) || operator!=(value.c_str())); }
2481
2485 bool operator&=(const char* value) const;
2486
2490 bool operator|=(const char* value) const;
2491
2495 inline String& operator<<(const char* value)
2496 { return operator+=(value); }
2497
2501 inline String& operator<<(char value)
2502 { return operator+=(value); }
2503
2507 inline String& operator<<(int32_t value)
2508 { return operator+=(value); }
2509
2513 inline String& operator<<(uint32_t value)
2514 { return operator+=(value); }
2515
2519 inline String& operator<<(int64_t value)
2520 { return operator+=(value); }
2521
2525 inline String& operator<<(uint64_t value)
2526 { return operator+=(value); }
2527
2531 inline String& operator<<(bool value)
2532 { return operator+=(value); }
2533
2537 inline String& operator<<(double value)
2538 { return operator+=(value); }
2539
2544 String& operator>>(const char* skip);
2545
2549 String& operator>>(char& store);
2550
2554 String& operator>>(UChar& store);
2555
2559 String& operator>>(int& store);
2560
2564 String& operator>>(unsigned int& store);
2565
2569 String& operator>>(bool& store);
2570
2577 String& append(const char* value, int len);
2578
2585 String& append(const char* value, const char* separator = 0, bool force = false);
2586
2593 String& append(const ObjList* list, const char* separator = 0, bool force = false);
2594
2601 inline String& append(const ObjList& list, const char* separator = 0, bool force = false)
2602 { return append(&list,separator,force); }
2603
2609 String& append(double value, unsigned int decimals = 3);
2610
2616 String& printf(const char* format, ...) FORMAT_CHECK(2);
2617
2623 String& printf(unsigned int length, const char* format, ...) FORMAT_CHECK(3);
2624
2633 String& appendFixed(unsigned int fixedLength, const char* str, unsigned int len = -1, char fill = ' ', int align = Left);
2634
2642 inline String& appendFixed(unsigned int fixedLength, const String& str, char fill = ' ', int align = Left)
2643 { return appendFixed(fixedLength,str.c_str(),str.length(),fill,align); }
2644
2651 int find(char what, unsigned int offs = 0) const;
2652
2659 int find(const char* what, unsigned int offs = 0) const;
2660
2666 int rfind(char what) const;
2667
2673 int rfind(const char* what) const;
2674
2682 bool startsWith(const char* what, bool wordBreak = false, bool caseInsensitive = false) const;
2683
2691 bool endsWith(const char* what, bool wordBreak = false, bool caseInsensitive = false) const;
2692
2704 bool startSkip(const char* what, bool wordBreak = true, bool caseInsensitive = false);
2705
2712 String& extractTo(const char* sep, String& store);
2713
2720 String& extractTo(const char* sep, bool& store);
2721
2729 String& extractTo(const char* sep, int& store, int base = 0);
2730
2739 String& extractTo(const char* sep, int& store, const TokenDict* tokens, int base = 0);
2740
2747 String& extractTo(const char* sep, double& store);
2748
2754 virtual bool matches(const String& value) const
2755 { return operator==(value); }
2756
2762 bool matches(const Regexp& rexp);
2763
2769 int matchOffset(int index = 0) const;
2770
2776 int matchLength(int index = 0) const;
2777
2783 inline String matchString(int index = 0) const
2784 { return substr(matchOffset(index),matchLength(index)); }
2785
2791 String replaceMatches(const String& templ) const;
2792
2797 int matchCount() const;
2798
2805 ObjList* split(char separator, bool emptyOK = true) const;
2806
2813 ObjList* split(const Regexp& reg, bool emptyOK = true) const;
2814
2821 static String msgEscape(const char* str, char extraEsc = 0);
2822
2828 inline String msgEscape(char extraEsc = 0) const
2829 { return msgEscape(c_str(),extraEsc); }
2830
2838 static String msgUnescape(const char* str, int* errptr = 0, char extraEsc = 0);
2839
2846 inline String msgUnescape(int* errptr = 0, char extraEsc = 0) const
2847 { return msgUnescape(c_str(),errptr,extraEsc); }
2848
2855 static String sqlEscape(const char* str, char extraEsc = 0);
2856
2862 inline String sqlEscape(char extraEsc = 0) const
2863 { return sqlEscape(c_str(),extraEsc); }
2864
2872 static String uriEscape(const char* str, char extraEsc = 0, const char* noEsc = 0);
2873
2881 static String uriEscape(const char* str, const char* extraEsc, const char* noEsc = 0);
2882
2889 inline String uriEscape(char extraEsc = 0, const char* noEsc = 0) const
2890 { return uriEscape(c_str(),extraEsc,noEsc); }
2891
2898 static String uriUnescape(const char* str, int* errptr = 0);
2899
2905 inline String uriUnescape(int* errptr = 0) const
2906 { return uriUnescape(c_str(),errptr); }
2907
2914 static const String* atom(const String*& str, const char* val);
2915
2916 protected:
2920 virtual void changed();
2921
2922 private:
2923 void clearMatches();
2924 char* m_string;
2925 unsigned int m_length;
2926 // I hope every C++ compiler now knows about mutable...
2927 mutable unsigned int m_hash;
2928 StringMatchPrivate* m_matches;
2929 };
2930
2936 inline const char* c_str(const String* str)
2937 { return str ? str->c_str() : (const char*)0; }
2938
2944 inline const char* c_safe(const char* str)
2945 { return str ? str : ""; }
2946
2952 inline const char* c_safe(const String* str)
2953 { return str ? str->safe() : ""; }
2954
2960 inline bool null(const char* str)
2961 { return !(str && *str); }
2962
2968 inline bool null(const String* str)
2969 { return !str || str->null(); }
2970
2974 YATE_API String operator+(const String& s1, const String& s2);
2975
2979 YATE_API String operator+(const String& s1, const char* s2);
2980
2984 YATE_API String operator+(const char* s1, const String& s2);
2985
2990 inline const char *strcpy(String& dest, const char* src)
2991 { dest = src; return dest.c_str(); }
2992
2997 inline const char *strcat(String& dest, const char* src)
2998 { dest += src; return dest.c_str(); }
2999
3008 YATE_API int lookup(const char* str, const TokenDict* tokens, int defvalue = 0, int base = 0);
3009
3016 YATE_API const char* lookup(int value, const TokenDict* tokens, const char* defvalue = 0);
3017
3026 YATE_API int64_t lookup(const char* str, const TokenDict64* tokens, int64_t defvalue = 0, int base = 0);
3027
3034 YATE_API const char* lookup(int64_t value, const TokenDict64* tokens, const char* defvalue = 0);
3035
3036 class NamedList;
3037
3045 YATE_API bool controlReturn(NamedList* params, bool ret, const char* retVal = 0);
3046
3051 class YATE_API Regexp : public String
3052 {
3053 friend class String;
3054 public:
3058 Regexp();
3059
3066 explicit Regexp(const char* value, bool extended = false, bool insensitive = false);
3067
3072 Regexp(const Regexp& value);
3073
3077 virtual ~Regexp();
3078
3082 inline Regexp& operator=(const char* value)
3083 { String::operator=(value); return *this; }
3084
3089 inline bool compile() const
3090 { return m_regexp || (m_compile && doCompile()); }
3091
3097 bool matches(const char* value) const;
3098
3104 virtual bool matches(const String& value) const
3105 { return Regexp::matches(value.safe()); }
3106
3112 void setFlags(bool extended, bool insensitive);
3113
3118 bool isExtended() const;
3119
3124 bool isCaseInsensitive() const;
3125
3126 protected:
3130 virtual void changed();
3131
3136 bool doCompile() const;
3137
3138 private:
3139 void cleanup();
3140 bool matches(const char* value, StringMatchPrivate* matchlist) const;
3141 mutable void* m_regexp;
3142 mutable bool m_compile;
3143 int m_flags;
3144 };
3145
3150 class Atom
3151 {
3152 public:
3157 inline explicit Atom(const char* value)
3158 : m_atom(0)
3159 { String::atom(m_atom,value); }
3160
3165 inline operator const String&() const
3166 { return *m_atom; }
3167
3172 inline const String* operator->() const
3173 { return m_atom; }
3174
3175 private:
3176 const String* m_atom;
3177 };
3178
3183 class YATE_API CapturedEvent : public String
3184 {
3185 friend class Engine;
3186 YCLASS(CapturedEvent,String)
3187 public:
3193 inline CapturedEvent(int level, const char* text)
3194 : String(text), m_level(level)
3195 { }
3196
3201 inline CapturedEvent(const CapturedEvent& original)
3202 : String(original), m_level(original.level())
3203 { }
3204
3209 inline int level() const
3210 { return m_level; }
3211
3212
3217 inline static bool capturing()
3218 { return s_capturing; }
3219
3224 inline static const ObjList& events()
3225 { return s_events; }
3226
3232 inline static void append(int level, const char* text)
3233 { if (text && *text) s_events.append(new CapturedEvent(level,text)); }
3234
3235 protected:
3240 inline static ObjList& eventsRw()
3241 { return s_events; }
3242
3247 inline static void capturing(bool capture)
3248 { s_capturing = capture; }
3249
3250 private:
3251 int m_level;
3252 static ObjList s_events;
3253 static bool s_capturing;
3254 };
3255
3260 class YATE_API NamedString : public String
3261 {
3262 YNOCOPY(NamedString); // no automatic copies please
3263 public:
3269 explicit NamedString(const char* name, const char* value = 0);
3270
3275 inline const String& name() const
3276 { return m_name; }
3277
3282 virtual const String& toString() const;
3283
3289 virtual void* getObject(const String& name) const;
3290
3294 inline NamedString& operator=(const char* value)
3295 { String::operator=(value); return *this; }
3296
3297 private:
3298 NamedString(); // no default constructor please
3299 String m_name;
3300 };
3301
3308 class YATE_API NamedPointer : public NamedString
3309 {
3310 public:
3317 explicit NamedPointer(const char* name, GenObject* data = 0, const char* value = 0);
3318
3322 virtual ~NamedPointer();
3323
3328 inline GenObject* userData() const
3329 { return m_data; }
3330
3336 GenObject* takeData();
3337
3343 void userData(GenObject* data);
3344
3350 inline void* userObject(const String& name) const
3351 { return m_data ? m_data->getObject(name) : 0; }
3352
3356 inline NamedPointer& operator=(const char* value)
3357 { NamedString::operator=(value); return *this; }
3358
3364 virtual void* getObject(const String& name) const;
3365
3366 protected:
3370 virtual void changed();
3371
3372 private:
3373 NamedPointer(); // no default constructor please
3374 GenObject* m_data;
3375 };
3376
3381 class YATE_API NamedCounter : public String
3382 {
3383 YNOCOPY(NamedCounter); // no automatic copies please
3384 public:
3389 explicit NamedCounter(const String& name);
3390
3395 inline bool enabled() const
3396 { return m_enabled; }
3397
3402 inline void enable(bool val)
3403 { m_enabled = val; }
3404
3409 int inc();
3410
3415 int dec();
3416
3421 inline int count() const
3422 { return m_count; }
3423
3424 private:
3425 int m_count;
3426 bool m_enabled;
3427 Mutex* m_mutex;
3428 };
3429
3437 class YATE_API HashList : public GenObject
3438 {
3439 YNOCOPY(HashList); // no automatic copies please
3440 public:
3445 explicit HashList(unsigned int size = 17);
3446
3450 virtual ~HashList();
3451
3457 virtual void* getObject(const String& name) const;
3458
3463 inline unsigned int length() const
3464 { return m_size; }
3465
3470 unsigned int count() const;
3471
3478 inline ObjList* getList(unsigned int index) const
3479 { return (index < m_size) ? m_lists[index] : 0; }
3480
3486 inline ObjList* getHashList(unsigned int hash) const
3487 { return getList(hash % m_size); }
3488
3494 inline ObjList* getHashList(const String& str) const
3495 { return getHashList(str.hash()); }
3496
3502 GenObject* operator[](const String& str) const;
3503
3510 ObjList* find(const GenObject* obj) const;
3511
3518 ObjList* find(const GenObject* obj, unsigned int hash) const;
3519
3525 ObjList* find(const String& str) const;
3526
3532 ObjList* append(const GenObject* obj);
3533
3541 GenObject* remove(GenObject* obj, bool delobj = true, bool useHash = false);
3542
3549 inline GenObject* remove(const String& str, bool delobj = true)
3550 {
3551 ObjList* n = find(str);
3552 return n ? n->remove(delobj) : 0;
3553 }
3554
3558 void clear();
3559
3566 bool resync(GenObject* obj);
3567
3573 bool resync();
3574
3575 private:
3576 unsigned int m_size;
3577 ObjList** m_lists;
3578 };
3579
3586 class YATE_API ListIterator
3587 {
3588 YNOCOPY(ListIterator); // no automatic copies please
3589 public:
3596 ListIterator(ObjList& list, int offset = 0);
3597
3604 ListIterator(HashList& list, int offset = 0);
3605
3609 ~ListIterator();
3610
3615 inline unsigned int length() const
3616 { return m_length; }
3617
3621 void clear();
3622
3628 void assign(ObjList& list, int offset = 0);
3629
3635 void assign(HashList& list, int offset = 0);
3636
3643 GenObject* get(unsigned int index) const;
3644
3657 GenObject* get();
3658
3663 inline bool eof() const
3664 { return m_current >= m_length; }
3665
3669 inline void reset()
3670 { m_current = 0; }
3671
3672 private:
3673 ObjList* m_objList;
3674 HashList* m_hashList;
3675 GenObject** m_objects;
3676 unsigned int* m_hashes;
3677 unsigned int m_length;
3678 unsigned int m_current;
3679 };
3680
3685 class YATE_API Time
3686 {
3687 public:
3691 inline Time()
3692 : m_time(now())
3693 { }
3694
3699 inline Time(u_int64_t usec)
3700 : m_time(usec)
3701 { }
3702
3707 inline explicit Time(const struct timeval* tv)
3708 : m_time(fromTimeval(tv))
3709 { }
3710
3715 inline explicit Time(const struct timeval& tv)
3716 : m_time(fromTimeval(tv))
3717 { }
3718
3723 inline ~Time()
3724 { }
3725
3730 inline u_int32_t sec() const
3731 { return (u_int32_t)((m_time+500000) / 1000000); }
3732
3737 inline u_int64_t msec() const
3738 { return (m_time+500) / 1000; }
3739
3744 inline u_int64_t usec() const
3745 { return m_time; }
3746
3750 inline operator u_int64_t() const
3751 { return m_time; }
3752
3756 inline Time& operator=(u_int64_t usec)
3757 { m_time = usec; return *this; }
3758
3762 inline Time& operator+=(int64_t delta)
3763 { m_time += delta; return *this; }
3764
3768 inline Time& operator-=(int64_t delta)
3769 { m_time -= delta; return *this; }
3770
3775 inline void toTimeval(struct timeval* tv) const
3776 { toTimeval(tv, m_time); }
3777
3783 static void toTimeval(struct timeval* tv, u_int64_t usec);
3784
3790 static u_int64_t fromTimeval(const struct timeval* tv);
3791
3797 inline static u_int64_t fromTimeval(const struct timeval& tv)
3798 { return fromTimeval(&tv); }
3799
3804 static u_int64_t now();
3805
3810 static u_int64_t msecNow();
3811
3816 static u_int32_t secNow();
3817
3831 static unsigned int toEpoch(int year, unsigned int month, unsigned int day,
3832 unsigned int hour, unsigned int minute, unsigned int sec, int offset = 0);
3833
3846 static bool toDateTime(unsigned int epochTimeSec, int& year, unsigned int& month,
3847 unsigned int& day, unsigned int& hour, unsigned int& minute, unsigned int& sec,
3848 unsigned int* wDay = 0);
3849
3857 static uint32_t toNtp(uint32_t sec, uint32_t* over = 0, bool rfc2030 = true);
3858
3865 inline uint32_t toNtp(uint32_t* over = 0, bool rfc2030 = true)
3866 { return toNtp(sec(),over,rfc2030); }
3867
3876 static uint32_t fromNtp(uint32_t val, uint32_t* under = 0, bool rfc2030 = true);
3877
3889 static unsigned int toString(char* buf, uint64_t time, int frac = 0);
3890
3902 static inline unsigned int appendTo(String& buf, uint64_t time, int frac = 0) {
3903 char tmp[30];
3904 unsigned int n = toString(tmp,time,frac);
3905 if (n)
3906 buf.append(tmp,n);
3907 return n;
3908 }
3909
3919 static uint64_t toEpoch(const char* buf, unsigned int len, int frac = 0);
3920
3926 static inline bool isLeap(unsigned int year)
3927 { return (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)); }
3928
3933 static int timeZone();
3934
3935 private:
3936 u_int64_t m_time;
3937 };
3938
3943 class YATE_API Random
3944 {
3945 public:
3950 inline Random(u_int32_t seed = Time::now() & 0xffffffff)
3951 : m_random(seed)
3952 { }
3953
3958 inline u_int32_t get() const
3959 { return m_random; }
3960
3965 inline void set(u_int32_t seed)
3966 { m_random = seed; }
3967
3972 u_int32_t next();
3973
3978 static long int random();
3979
3984 static void srandom(unsigned int seed);
3985
3986 private:
3987 u_int32_t m_random;
3988 };
3989
3994 class YATE_API DataBlock : public GenObject
3995 {
3996 public:
3997
4002 DataBlock(unsigned int overAlloc = 0);
4003
4008 DataBlock(const DataBlock& value);
4009
4015 DataBlock(const DataBlock& value, unsigned int overAlloc);
4016
4024 DataBlock(void* value, unsigned int len, bool copyData = true, unsigned int overAlloc = 0);
4025
4029 virtual ~DataBlock();
4030
4036 virtual void* getObject(const String& name) const;
4037
4041 static const DataBlock& empty();
4042
4047 inline void* data() const
4048 { return m_data; }
4049
4056 inline unsigned char* data(unsigned int offs, unsigned int len = 1) const
4057 { return (offs + len <= m_length) ? (static_cast<unsigned char*>(m_data) + offs) : 0; }
4058
4065 inline int at(unsigned int offs, int defvalue = -1) const
4066 { return (offs < m_length) ? static_cast<unsigned char*>(m_data)[offs] : defvalue; }
4067
4072 inline bool null() const
4073 { return !m_data; }
4074
4079 inline unsigned int length() const
4080 { return m_length; }
4081
4086 inline unsigned int overAlloc() const
4087 { return m_overAlloc; }
4088
4093 inline void overAlloc(unsigned int bytes)
4094 { m_overAlloc = bytes; }
4095
4100 void clear(bool deleteData = true);
4101
4109 DataBlock& assign(void* value, unsigned int len, bool copyData = true, unsigned int allocated = 0);
4110
4116 inline void append(void* value, unsigned int len) {
4117 DataBlock tmp(value,len,false);
4118 append(tmp);
4119 tmp.clear(false);
4120 }
4121
4126 void append(const DataBlock& value);
4127
4132 void append(const String& value);
4133
4138 void insert(const DataBlock& value);
4139
4144 inline void resize(unsigned int len) {
4145 if (len != length())
4146 assign(0,len);
4147 }
4148
4153 void truncate(unsigned int len);
4154
4159 void cut(int len);
4160
4166 inline int operator[](signed int index) const
4167 { return at(index); }
4168
4174 inline int operator[](unsigned int index) const
4175 { return at(index); }
4176
4180 DataBlock& operator=(const DataBlock& value);
4181
4185 inline DataBlock& operator+=(const DataBlock& value)
4186 { append(value); return *this; }
4187
4191 inline DataBlock& operator+=(const String& value)
4192 { append(value); return *this; }
4193
4202 bool convert(const DataBlock& src, const String& sFormat,
4203 const String& dFormat, unsigned maxlen = 0);
4204
4215 bool unHexify(const char* data, unsigned int len, char sep);
4216
4226 bool unHexify(const char* data, unsigned int len);
4227
4234 inline bool unHexify(const String& data)
4235 { return unHexify(data.c_str(),data.length()); }
4236
4242 String sqlEscape(char extraEsc) const;
4243
4244 private:
4245 unsigned int allocLen(unsigned int len) const;
4246 void* m_data;
4247 unsigned int m_length;
4248 unsigned int m_allocated;
4249 unsigned int m_overAlloc;
4250 };
4251
4256 class YATE_API Hasher
4257 {
4258 public:
4262 virtual ~Hasher();
4263
4267 virtual void clear() = 0;
4268
4273 virtual void finalize() = 0;
4274
4280 virtual const unsigned char* rawDigest() = 0;
4281
4287 inline const String& hexDigest()
4288 { finalize(); return m_hex; }
4289
4296 inline bool update(const void* buf, unsigned int len)
4297 { return updateInternal(buf,len); }
4298
4304 inline bool update(const DataBlock& data)
4305 { return updateInternal(data.data(), data.length()); }
4306
4312 inline bool update(const String& str)
4313 { return updateInternal(str.c_str(), str.length()); }
4314
4319 inline Hasher& operator<<(const String& value)
4320 { update(value); return *this; }
4321
4326 inline Hasher& operator<<(const DataBlock& data)
4327 { update(data); return *this; }
4328
4333 Hasher& operator<<(const char* value);
4334
4342 bool hmacStart(DataBlock& opad, const void* key, unsigned int keyLen);
4343
4350 inline bool hmacStart(DataBlock& opad, const DataBlock& key)
4351 { return hmacStart(opad,key.data(),key.length()); }
4352
4359 inline bool hmacStart(DataBlock& opad, const String& key)
4360 { return hmacStart(opad,key.c_str(),key.length()); }
4361
4367 bool hmacFinal(const DataBlock& opad);
4368
4377 bool hmac(const void* key, unsigned int keyLen, const void* msg, unsigned int msgLen);
4378
4385 inline bool hmac(const DataBlock& key, const DataBlock& msg)
4386 { return hmac(key.data(),key.length(),msg.data(),msg.length()); }
4387
4394 inline bool hmac(const String& key, const String& msg)
4395 { return hmac(key.c_str(),key.length(),msg.c_str(),msg.length()); }
4396
4401 virtual unsigned int hashLength() const = 0;
4402
4407 virtual unsigned int hmacBlockSize() const;
4408
4409 protected:
4413 inline Hasher()
4414 : m_private(0)
4415 { }
4416
4423 virtual bool updateInternal(const void* buf, unsigned int len) = 0;
4424
4425 void* m_private;
4426 String m_hex;
4427 };
4428
4433 class YATE_API MD5 : public Hasher
4434 {
4435 public:
4439 MD5();
4440
4445 MD5(const MD5& original);
4446
4452 MD5(const void* buf, unsigned int len);
4453
4458 MD5(const DataBlock& data);
4459
4464 MD5(const String& str);
4465
4469 MD5& operator=(const MD5& original);
4470
4474 virtual ~MD5();
4475
4479 virtual void clear();
4480
4485 virtual void finalize();
4486
4492 virtual const unsigned char* rawDigest();
4493
4498 inline static unsigned int rawLength()
4499 { return 16; }
4500
4505 virtual unsigned int hashLength() const
4506 { return 16; }
4507
4508 protected:
4509 bool updateInternal(const void* buf, unsigned int len);
4510
4511 private:
4512 void init();
4513 unsigned char m_bin[16];
4514 };
4515
4520 class YATE_API SHA1 : public Hasher
4521 {
4522 public:
4526 SHA1();
4527
4532 SHA1(const SHA1& original);
4533
4539 SHA1(const void* buf, unsigned int len);
4540
4545 SHA1(const DataBlock& data);
4546
4551 SHA1(const String& str);
4552
4556 SHA1& operator=(const SHA1& original);
4557
4561 virtual ~SHA1();
4562
4566 virtual void clear();
4567
4572 virtual void finalize();
4573
4579 virtual const unsigned char* rawDigest();
4580
4585 inline static unsigned int rawLength()
4586 { return 20; }
4587
4592 virtual unsigned int hashLength() const
4593 { return 20; }
4594
4603 static bool fips186prf(DataBlock& out, const DataBlock& seed, unsigned int len);
4604
4605 protected:
4606 bool updateInternal(const void* buf, unsigned int len);
4607
4608 private:
4609 void init();
4610 unsigned char m_bin[20];
4611 };
4612
4617 class YATE_API SHA256 : public Hasher
4618 {
4619 public:
4623 SHA256();
4624
4629 SHA256(const SHA256& original);
4630
4636 SHA256(const void* buf, unsigned int len);
4637
4642 SHA256(const DataBlock& data);
4643
4648 SHA256(const String& str);
4649
4653 SHA256& operator=(const SHA256& original);
4654
4658 virtual ~SHA256();
4659
4663 virtual void clear();
4664
4669 virtual void finalize();
4670
4676 virtual const unsigned char* rawDigest();
4677
4682 inline static unsigned int rawLength()
4683 { return 32; }
4684
4689 virtual unsigned int hashLength() const
4690 { return 32; }
4691
4692 protected:
4693 bool updateInternal(const void* buf, unsigned int len);
4694
4695 private:
4696 void init();
4697 unsigned char m_bin[32];
4698 };
4699
4704 class YATE_API Base64 : public DataBlock
4705 {
4706 YNOCOPY(Base64); // no automatic copies please
4707 public:
4711 inline Base64()
4712 { }
4713
4720 inline Base64(void* src, unsigned int len, bool copyData = true)
4721 : DataBlock(src,len,copyData)
4722 { }
4723
4733 void encode(String& dest, unsigned int lineLen = 0, bool lineAtEnd = false);
4734
4746 bool decode(DataBlock& dest, bool liberal = true);
4747
4751 inline Base64& operator<<(const String& value)
4752 { append(value); return *this; }
4753
4757 inline Base64& operator<<(const DataBlock& data)
4758 { append(data); return *this; }
4759
4763 inline Base64& operator<<(const char* value)
4764 { return operator<<(String(value)); }
4765 };
4766
4767 class NamedIterator;
4768
4773 class YATE_API NamedList : public String
4774 {
4775 friend class NamedIterator;
4776 public:
4781 explicit NamedList(const char* name);
4782
4787 NamedList(const NamedList& original);
4788
4795 NamedList(const char* name, const NamedList& original, const String& prefix);
4796
4802 NamedList& operator=(const NamedList& value);
4803
4809 virtual void* getObject(const String& name) const;
4810
4815 inline unsigned int length() const
4816 { return m_params.length(); }
4817
4822 inline unsigned int count() const
4823 { return m_params.count(); }
4824
4828 inline void clearParams()
4829 { m_params.clear(); }
4830
4836 NamedList& addParam(NamedString* param);
4837
4845 NamedList& addParam(const char* name, const char* value, bool emptyOK = true);
4846
4852 inline NamedList& setParam(NamedString* param)
4853 {
4854 if (param)
4855 m_params.setUnique(param);
4856 return *this;
4857 }
4858
4865 NamedList& setParam(const String& name, const char* value);
4866
4873 NamedList& clearParam(const String& name, char childSep = 0);
4874
4881 NamedList& clearParam(NamedString* param, bool delParam = true);
4882
4890 NamedList& copyParam(const NamedList& original, const String& name, char childSep = 0);
4891
4897 NamedList& copyParams(const NamedList& original);
4898
4906 NamedList& copyParams(const NamedList& original, ObjList* list, char childSep = 0);
4907
4915 NamedList& copyParams(const NamedList& original, const String& list, char childSep = 0);
4916
4925 NamedList& copySubParams(const NamedList& original, const String& prefix,
4926 bool skipPrefix = true, bool replace = false);
4927
4933 bool hasSubParams(const char* prefix) const;
4934
4940 int getIndex(const NamedString* param) const;
4941
4947 int getIndex(const String& name) const;
4948
4954 NamedString* getParam(const String& name) const;
4955
4961 NamedString* getParam(unsigned int index) const;
4962
4968 const String& operator[](const String& name) const;
4969
4976 const char* getValue(const String& name, const char* defvalue = 0) const;
4977
4988 int getIntValue(const String& name, int defvalue = 0, int minvalue = INT_MIN,
4989 int maxvalue = INT_MAX, bool clamp = true) const;
4990
4998 int getIntValue(const String& name, const TokenDict* tokens, int defvalue = 0) const;
4999
5010 int64_t getInt64Value(const String& name, int64_t defvalue = 0, int64_t minvalue = LLONG_MIN,
5011 int64_t maxvalue = LLONG_MAX, bool clamp = true) const;
5012
5019 double getDoubleValue(const String& name, double defvalue = 0.0) const;
5020
5027 bool getBoolValue(const String& name, bool defvalue = false) const;
5028
5036 int replaceParams(String& str, bool sqlEsc = false, char extraEsc = 0) const;
5037
5046 void dump(String& str, const char* separator, char quote = 0, bool force = false) const;
5047
5052 static const NamedList& empty();
5053
5058 inline ObjList* paramList()
5059 { return &m_params; }
5060
5065 inline const ObjList* paramList() const
5066 { return &m_params; }
5067
5068 private:
5069 NamedList(); // no default constructor please
5070 ObjList m_params;
5071 };
5072
5078 class YATE_API NamedIterator
5079 {
5080 public:
5085 inline NamedIterator(const NamedList& list)
5086 : m_list(&list), m_item(list.m_params.skipNull())
5087 { }
5088
5093 inline NamedIterator(const NamedIterator& original)
5094 : m_list(original.m_list), m_item(original.m_item)
5095 { }
5096
5101 inline NamedIterator& operator=(const NamedList& list)
5102 { m_list = &list; m_item = list.m_params.skipNull(); return *this; }
5103
5108 inline NamedIterator& operator=(const NamedIterator& original)
5109 { m_list = original.m_list; m_item = original.m_item; return *this; }
5110
5115 const NamedString* get();
5116
5120 inline bool eof() const
5121 { return !m_item; }
5122
5126 inline void reset()
5127 { m_item = m_list->m_params.skipNull(); }
5128
5129 private:
5130 NamedIterator(); // no default constructor please
5131 const NamedList* m_list;
5132 const ObjList* m_item;
5133 };
5134
5140 class YATE_API URI : public String
5141 {
5142 public:
5146 URI();
5147
5152 URI(const URI& uri);
5153
5158 explicit URI(const String& uri);
5159
5164 explicit URI(const char* uri);
5165
5174 URI(const char* proto, const char* user, const char* host, int port = 0, const char* desc = 0);
5175
5179 void parse() const;
5180
5185 inline URI& operator=(const URI& value)
5186 { String::operator=(value); return *this; }
5187
5192 inline URI& operator=(const String& value)
5193 { String::operator=(value); return *this; }
5194
5199 inline URI& operator=(const char* value)
5200 { String::operator=(value); return *this; }
5201
5206 inline const String& getDescription() const
5207 { parse(); return m_desc; }
5208
5213 inline const String& getProtocol() const
5214 { parse(); return m_proto; }
5215
5220 inline const String& getUser() const
5221 { parse(); return m_user; }
5222
5227 inline const String& getHost() const
5228 { parse(); return m_host; }
5229
5234 inline int getPort() const
5235 { parse(); return m_port; }
5236
5241 inline const String& getExtra() const
5242 { parse(); return m_extra; }
5243
5244 protected:
5250 virtual void changed();
5251 mutable bool m_parsed;
5252 mutable String m_desc;
5253 mutable String m_proto;
5254 mutable String m_user;
5255 mutable String m_host;
5256 mutable String m_extra;
5257 mutable int m_port;
5258 };
5259
5260 class MutexPrivate;
5261 class SemaphorePrivate;
5262 class ThreadPrivate;
5263
5268 class YATE_API Lockable
5269 {
5270 public:
5274 virtual ~Lockable();
5275
5281 virtual bool lock(long maxwait = -1) = 0;
5282
5287 virtual bool unlock() = 0;
5288
5294 virtual bool locked() const = 0;
5295
5301 virtual bool check(long maxwait = -1);
5302
5309 virtual bool unlockAll();
5310
5316 static void wait(unsigned long maxwait);
5317
5322 static unsigned long wait();
5323
5330 static void startUsingNow();
5331
5338 static void enableSafety(bool safe = true);
5339
5344 static bool safety();
5345 };
5346
5351 class YATE_API Mutex : public Lockable
5352 {
5353 friend class MutexPrivate;
5354 public:
5361 explicit Mutex(bool recursive = false, const char* name = 0);
5362
5367 Mutex(const Mutex& original);
5368
5372 ~Mutex();
5373
5378 Mutex& operator=(const Mutex& original);
5379
5385 virtual bool lock(long maxwait = -1);
5386
5391 virtual bool unlock();
5392
5398 virtual bool locked() const;
5399
5404 const char* owner() const;
5405
5410 bool recursive() const;
5411
5416 static int count();
5417
5422 static int locks();
5423
5428 static bool efficientTimedLock();
5429
5430 private:
5431 MutexPrivate* privDataCopy() const;
5432 MutexPrivate* m_private;
5433 };
5434
5441 class YATE_API MutexPool
5442 {
5443 public:
5454 MutexPool(unsigned int len = 13, bool recursive = false, const char* name = 0);
5455
5459 ~MutexPool();
5460
5468 inline unsigned int index(void* ptr) const
5469 { return ((unsigned int)(unsigned long)ptr) % m_length; }
5470
5478 inline Mutex* mutex(void* ptr) const
5479 { return m_data[index(ptr)]; }
5480
5486 inline Mutex* mutex(unsigned int idx) const
5487 { return m_data[idx % m_length]; }
5488
5489 private:
5490 String* m_name; // Mutex names
5491 Mutex** m_data; // The array
5492 unsigned int m_length; // Array length
5493 };
5494
5499 class YATE_API Semaphore : public Lockable
5500 {
5501 friend class SemaphorePrivate;
5502 public:
5509 explicit Semaphore(unsigned int maxcount = 1, const char* name = 0,
5510 unsigned int initialCount = 1);
5511
5516 Semaphore(const Semaphore& original);
5517
5521 ~Semaphore();
5522
5527 Semaphore& operator=(const Semaphore& original);
5528
5534 virtual bool lock(long maxwait = -1);
5535
5540 virtual bool unlock();
5541
5547 virtual bool locked() const;
5548
5553 static int count();
5554
5559 static int locks();
5560
5565 static bool efficientTimedLock();
5566
5567 private:
5568 SemaphorePrivate* privDataCopy() const;
5569 SemaphorePrivate* m_private;
5570 };
5571
5577 class YATE_API Lock
5578 {
5579 YNOCOPY(Lock); // no automatic copies please
5580 public:
5586 inline Lock(Lockable& lck, long maxwait = -1)
5587 { m_lock = lck.lock(maxwait) ? &lck : 0; }
5588
5594 inline Lock(Lockable* lck, long maxwait = -1)
5595 { m_lock = (lck && lck->lock(maxwait)) ? lck : 0; }
5596
5600 inline ~Lock()
5601 { if (m_lock) m_lock->unlock(); }
5602
5607 inline Lockable* locked() const
5608 { return m_lock; }
5609
5613 inline void drop()
5614 { if (m_lock) m_lock->unlock(); m_lock = 0; }
5615
5622 inline bool acquire(Lockable* lck, long maxwait = -1)
5623 { return (lck && (lck == m_lock)) ||
5624 (drop(),(lck && (m_lock = lck->lock(maxwait) ? lck : 0))); }
5625
5632 inline bool acquire(Lockable& lck, long maxwait = -1)
5633 { return acquire(&lck,maxwait); }
5634
5635 private:
5636 Lockable* m_lock;
5637
5639 inline void* operator new(size_t);
5640
5642 inline void* operator new[](size_t);
5643 };
5644
5651 class YATE_API Lock2
5652 {
5653 YNOCOPY(Lock2); // no automatic copies please
5654 public:
5661 inline Lock2(Mutex* mx1, Mutex* mx2, long maxwait = -1)
5662 : m_mx1(0), m_mx2(0)
5663 { lock(mx1,mx2,maxwait); }
5664
5671 inline Lock2(Mutex& mx1, Mutex& mx2, long maxwait = -1)
5672 : m_mx1(0), m_mx2(0)
5673 { lock(&mx1,&mx2,maxwait); }
5674
5678 inline ~Lock2()
5679 { drop(); }
5680
5685 inline bool locked() const
5686 { return m_mx1 != 0; }
5687
5695 bool lock(Mutex* mx1, Mutex* mx2, long maxwait = -1);
5696
5704 inline bool lock(Mutex& mx1, Mutex& mx2, long maxwait = -1)
5705 { return lock(&mx1,&mx2,maxwait); }
5706
5710 void drop();
5711
5712 private:
5713 Mutex* m_mx1;
5714 Mutex* m_mx2;
5715
5717 inline void* operator new(size_t);
5718
5720 inline void* operator new[](size_t);
5721 };
5722
5728 class YATE_API Runnable
5729 {
5730 public:
5735 virtual void run() = 0;
5736
5740 virtual ~Runnable();
5741 };
5742
5749 class YATE_API Thread : public Runnable
5750 {
5751 friend class ThreadPrivate;
5752 friend class MutexPrivate;
5753 friend class SemaphorePrivate;
5754 YNOCOPY(Thread); // no automatic copies please
5755 public:
5759 enum Priority {
5760 Lowest,
5761 Low,
5762 Normal,
5763 High,
5764 Highest
5765 };
5766
5770 virtual void cleanup();
5771
5776 bool startup();
5777
5782 bool error() const;
5783
5788 bool running() const;
5789
5794 inline int locks() const
5795 { return m_locks; }
5796
5801 inline bool locked() const
5802 { return m_locking || m_locks; }
5803
5808 const char* name() const;
5809
5814 static const char* currentName();
5815
5821 static void yield(bool exitCheck = false);
5822
5828 static void idle(bool exitCheck = false);
5829
5835 static void sleep(unsigned int sec, bool exitCheck = false);
5836
5842 static void msleep(unsigned long msec, bool exitCheck = false);
5843
5850 static void usleep(unsigned long usec, bool exitCheck = false);
5851
5856 static unsigned long idleUsec();
5857
5862 static unsigned long idleMsec();
5863
5868 static void idleMsec(unsigned long msec);
5869
5875 static Thread* current();
5876
5881 static int count();
5882
5888 static bool check(bool exitNow = true);
5889
5893 static void exit();
5894
5899 void cancel(bool hard = false);
5900
5905 inline bool isCurrent() const
5906 { return current() == this; }
5907
5912 NamedCounter* getObjCounter() const;
5913
5919 NamedCounter* setObjCounter(NamedCounter* counter);
5920
5926 static NamedCounter* getCurrentObjCounter(bool always = false);
5927
5933 static NamedCounter* setCurrentObjCounter(NamedCounter* counter);
5934
5941 static Priority priority(const char* name, Priority defvalue = Normal);
5942
5948 static const char* priority(Priority prio);
5949
5954 static void killall();
5955
5960 static void preExec();
5961
5967 static int lastError();
5968
5975 static inline bool errorString(String& buffer)
5976 { return errorString(buffer,lastError()); }
5977
5988 static bool errorString(String& buffer, int code);
5989
5990 protected:
5996 Thread(const char *name = 0, Priority prio = Normal);
5997
6003 Thread(const char *name, const char* prio);
6004
6008 virtual ~Thread();
6009
6010 private:
6011 ThreadPrivate* m_private;
6012 int m_locks;
6013 bool m_locking;
6014 };
6015
6020 class YATE_API TempObjectCounter
6021 {
6022 YNOCOPY(TempObjectCounter); // no automatic copies please
6023 public:
6029 inline TempObjectCounter(NamedCounter* counter, bool enable = GenObject::getObjCounting())
6030 : m_saved(0), m_enabled(enable)
6031 { if (m_enabled) m_saved = Thread::setCurrentObjCounter(counter); }
6032
6038 inline TempObjectCounter(const GenObject* obj, bool enable = GenObject::getObjCounting())
6039 : m_saved(0), m_enabled(enable && obj)
6040 { if (m_enabled) m_saved = Thread::setCurrentObjCounter(obj->getObjCounter()); }
6041
6047 inline TempObjectCounter(const GenObject& obj, bool enable = GenObject::getObjCounting())
6048 : m_saved(0), m_enabled(enable)
6049 { if (m_enabled) m_saved = Thread::setCurrentObjCounter(obj.getObjCounter()); }
6050
6054 inline ~TempObjectCounter()
6055 { if (m_enabled) Thread::setCurrentObjCounter(m_saved); }
6056
6057 private:
6058 NamedCounter* m_saved;
6059 bool m_enabled;
6060 };
6061
6062 class Socket;
6063
6068 class YATE_API SocketAddr : public GenObject
6069 {
6070 YCLASS(SocketAddr,GenObject)
6071 public:
6075 enum Family {
6076 Unknown = AF_UNSPEC,
6077 IPv4 = AF_INET,
6078 AfMax = AF_MAX,
6079 AfUnsupported = AfMax,
6080 #ifdef AF_INET6
6081 IPv6 = AF_INET6,
6082 #else
6083 IPv6 = AfUnsupported + 1,
6084 #endif
6085 #ifdef HAS_AF_UNIX
6086 Unix = AF_UNIX,
6087 #else
6088 Unix = AfUnsupported + 2,
6089 #endif
6090 };
6091
6095 inline SocketAddr()
6096 : m_address(0), m_length(0)
6097 { }
6098
6103 inline SocketAddr(const SocketAddr& value)
6104 : GenObject(),
6105 m_address(0), m_length(0)
6106 { assign(value.address(),value.length()); }
6107
6113 explicit SocketAddr(int family, const void* raw = 0);
6114
6120 SocketAddr(const struct sockaddr* addr, socklen_t len = 0);
6121
6125 virtual ~SocketAddr();
6126
6131 inline SocketAddr& operator=(const SocketAddr& value)
6132 { assign(value.address(),value.length()); return *this; }
6133
6139 bool operator==(const SocketAddr& other) const;
6140
6146 inline bool operator!=(const SocketAddr& other) const
6147 { return !operator==(other); }
6148
6152 void clear();
6153
6159 bool assign(int family);
6160
6166 void assign(const struct sockaddr* addr, socklen_t len = 0);
6167
6173 bool assign(const DataBlock& addr);
6174
6180 bool local(const SocketAddr& remote);
6181
6186 inline bool valid() const
6187 { return m_length && m_address; }
6188
6193 inline bool null() const
6194 { return !(m_length && m_address); }
6195
6200 inline int family() const
6201 { return m_address ? m_address->sa_family : 0; }
6202
6207 inline const char* familyName()
6208 { return lookupFamily(family()); }
6209
6214 inline unsigned int scopeId() const
6215 { return scopeId(address()); }
6216
6222 inline bool scopeId(unsigned int val)
6223 { return scopeId(address(),val); }
6224
6229 inline const String& host() const
6230 { return m_host; }
6231
6236 inline const String& addr() const {
6237 if (!m_addr)
6238 updateAddr();
6239 return m_addr;
6240 }
6241
6248 virtual bool host(const String& name);
6249
6254 int port() const;
6255
6261 bool port(int newport);
6262
6267 inline struct sockaddr* address() const
6268 { return m_address; }
6269
6274 inline socklen_t length() const
6275 { return m_length; }
6276
6281 inline bool isNullAddr() const
6282 { return isNullAddr(m_host,family()); }
6283
6289 int copyAddr(DataBlock& addr) const;
6290
6296 static bool supports(int family);
6297
6303 static int family(const String& addr);
6304
6311 static bool stringify(String& buf, struct sockaddr* addr);
6312
6321 static inline int unStringify(uint8_t* buf, const String& host,
6322 int family = Unknown) {
6323 SocketAddr sa(family);
6324 return sa.host(host) ? copyAddr(buf,sa.address()) : Unknown;
6325 }
6326
6334 static int copyAddr(uint8_t* buf, struct sockaddr* addr);
6335
6341 static inline unsigned int scopeId(struct sockaddr* addr) {
6342 #ifdef AF_INET6
6343 if (addr && addr->sa_family == AF_INET6)
6344 return ((struct sockaddr_in6*)addr)->sin6_scope_id;
6345 #endif
6346 return 0;
6347 }
6348
6355 static inline bool scopeId(struct sockaddr* addr, unsigned int val) {
6356 #ifdef AF_INET6
6357 if (addr && addr->sa_family == AF_INET6) {
6358 ((struct sockaddr_in6*)addr)->sin6_scope_id = val;
6359 return true;
6360 }
6361 #endif
6362 return false;
6363 }
6364
6372 static String& appendAddr(String& buf, const String& addr, int family = Unknown);
6373
6382 static inline String& appendTo(String& buf, const String& addr, int port,
6383 int family = Unknown) {
6384 appendAddr(buf,addr,family) << ":" << port;
6385 return buf;
6386 }
6387
6395 static inline String appendTo(const String& addr, int port, int family = Unknown) {
6396 String buf;
6397 appendTo(buf,addr,port,family);
6398 return buf;
6399 }
6400
6407 static bool isNullAddr(const String& addr, int family = Unknown);
6408
6417 static void splitIface(const String& buf, String& addr, String* iface = 0);
6418
6430 static void split(const String& buf, String& addr, int& port, bool portPresent = false);
6431
6437 static inline const char* lookupFamily(int family)
6438 { return lookup(family,s_familyName); }
6439
6444 static const String& ipv4NullAddr();
6445
6450 static const String& ipv6NullAddr();
6451
6456 static const TokenDict* dictFamilyName();
6457
6458 protected:
6462 virtual void stringify();
6463
6467 virtual void updateAddr() const;
6468
6469 struct sockaddr* m_address;
6470 socklen_t m_length;
6471 String m_host;
6472 mutable String m_addr;
6473
6474 private:
6475 static const TokenDict s_familyName[];
6476 };
6477
6482 class YATE_API SocketFilter : public GenObject
6483 {
6484 friend class Socket;
6485 YNOCOPY(SocketFilter); // no automatic copies please
6486 public:
6490 SocketFilter();
6491
6495 virtual ~SocketFilter();
6496
6502 virtual void* getObject(const String& name) const;
6503
6508 virtual void timerTick(const Time& when);
6509
6519 virtual bool received(void* buffer, int length, int flags, const struct sockaddr* addr, socklen_t adrlen) = 0;
6520
6525 inline Socket* socket() const
6526 { return m_socket; }
6527
6532 bool valid() const;
6533
6534 private:
6535 Socket* m_socket;
6536 };
6537
6542 class YATE_API Stream
6543 {
6544 public:
6548 enum SeekPos {
6549 SeekBegin, // Seek from start of stream
6550 SeekEnd, // Seek from stream end
6551 SeekCurrent // Seek from current position
6552 };
6553
6557 virtual ~Stream();
6558
6563 inline int error() const
6564 { return m_error; }
6565
6570 virtual bool terminate() = 0;
6571
6576 virtual bool canRetry() const;
6577
6582 virtual bool inProgress() const;
6583
6588 virtual bool valid() const = 0;
6589
6595 virtual bool setBlocking(bool block = true);
6596
6603 virtual int writeData(const void* buffer, int length) = 0;
6604
6610 int writeData(const char* str);
6611
6617 inline int writeData(const String& str)
6618 { return writeData(str.c_str(), str.length()); }
6619
6625 inline int writeData(const DataBlock& buf)
6626 { return writeData(buf.data(), buf.length()); }
6627
6634 virtual int readData(void* buffer, int length) = 0;
6635
6640 virtual int64_t length();
6641
6648 virtual int64_t seek(SeekPos pos, int64_t offset = 0);
6649
6655 inline int64_t seek(int64_t offset)
6656 { return seek(SeekBegin,offset); }
6657
6664 static bool allocPipe(Stream*& reader, Stream*& writer);
6665
6672 static bool allocPair(Stream*& str1, Stream*& str2);
6673
6678 static bool supportsPipes();
6679
6684 static bool supportsPairs();
6685
6686 protected:
6690 inline Stream()
6691 : m_error(0)
6692 { }
6693
6697 inline void clearError()
6698 { m_error = 0; }
6699
6700 int m_error;
6701 };
6702
6707 class YATE_API MemoryStream : public Stream
6708 {
6709 YNOCOPY(MemoryStream); // no automatic copies please
6710 public:
6714 inline MemoryStream()
6715 : m_offset(0)
6716 { }
6717
6722 inline MemoryStream(const DataBlock& data)
6723 : m_data(data), m_offset(0)
6724 { }
6725
6730 inline const DataBlock& data() const
6731 { return m_data; }
6732
6737 virtual bool terminate()
6738 { return true; }
6743 virtual bool valid() const
6744 { return true; }
6745
6752 virtual int writeData(const void* buffer, int len);
6753
6760 virtual int readData(void* buffer, int len);
6761
6766 virtual int64_t length()
6767 { return m_data.length(); }
6768
6775 virtual int64_t seek(SeekPos pos, int64_t offset = 0);
6776
6777 protected:
6781 DataBlock m_data;
6782
6786 int64_t m_offset;
6787 };
6788
6793 class YATE_API File : public Stream
6794 {
6795 YNOCOPY(File); // no automatic copies please
6796 public:
6800 File();
6801
6806 explicit File(HANDLE handle);
6807
6811 virtual ~File();
6812
6825 virtual bool openPath(const char* name, bool canWrite = false, bool canRead = true,
6826 bool create = false, bool append = false, bool binary = false,
6827 bool pubReadable = false, bool pubWritable = false);
6828
6833 virtual bool terminate();
6834
6839 void attach(HANDLE handle);
6840
6845 HANDLE detach();
6846
6851 inline HANDLE handle() const
6852 { return m_handle; }
6853
6858 virtual bool canRetry() const;
6859
6864 virtual bool valid() const;
6865
6870 static HANDLE invalidHandle();
6871
6877 virtual bool setBlocking(bool block = true);
6878
6883 virtual int64_t length();
6884
6891 virtual int64_t seek(SeekPos pos, int64_t offset = 0);
6892
6899 virtual int writeData(const void* buffer, int length);
6900
6907 virtual int readData(void* buffer, int length);
6908
6914 bool getFileTime(unsigned int& secEpoch);
6915
6922 virtual bool md5(String& buffer);
6923
6931 static bool setFileTime(const char* name, unsigned int secEpoch, int* error = 0);
6932
6940 static bool getFileTime(const char* name, unsigned int& secEpoch, int* error = 0);
6941
6948 static bool exists(const char* name, int* error = 0);
6949
6957 static bool rename(const char* oldFile, const char* newFile, int* error = 0);
6958
6965 static bool remove(const char* name, int* error = 0);
6966
6974 static bool md5(const char* name, String& buffer, int* error = 0);
6975
6983 static bool mkDir(const char* path, int* error = 0, int mode = -1);
6984
6991 static bool rmDir(const char* path, int* error = 0);
6992
7004 static bool listDirectory(const char* path, ObjList* dirs, ObjList* files,
7005 int* error = 0);
7006
7013 static bool createPipe(File& reader, File& writer);
7014
7015 protected:
7016
7020 void copyError();
7021
7022 HANDLE m_handle;
7023 };
7024
7029 class YATE_API Socket : public Stream
7030 {
7031 YNOCOPY(Socket); // no automatic copies please
7032 public:
7036 enum TOS {
7037 Normal = 0,
7038 LowDelay = IPTOS_LOWDELAY,
7039 MaxThroughput = IPTOS_THROUGHPUT,
7040 MaxReliability = IPTOS_RELIABILITY,
7041 MinCost = IPTOS_MINCOST,
7042 };
7043
7047 enum DSCP {
7048 DefaultPHB = 0x00,
7049 // Class selectors
7050 CS0 = 0x00,
7051 CS1 = 0x20,
7052 CS2 = 0x40,
7053 CS3 = 0x60,
7054 CS4 = 0x80,
7055 CS5 = 0xa0,
7056 CS6 = 0xc0,
7057 CS7 = 0xe0,
7058 // Assured forwarding
7059 AF11 = 0x28,
7060 AF12 = 0x30,
7061 AF13 = 0x38,
7062 AF21 = 0x48,
7063 AF22 = 0x50,
7064 AF23 = 0x58,
7065 AF31 = 0x68,
7066 AF32 = 0x70,
7067 AF33 = 0x78,
7068 AF41 = 0x88,
7069 AF42 = 0x90,
7070 AF43 = 0x98,
7071 // Expedited forwarding
7072 ExpeditedFwd = 0xb8,
7073 VoiceAdmit = 0xb0,
7074 };
7075
7079 Socket();
7080
7085 explicit Socket(SOCKET handle);
7086
7093 Socket(int domain, int type, int protocol = 0);
7094
7098 virtual ~Socket();
7099
7107 virtual bool create(int domain, int type, int protocol = 0);
7108
7113 virtual bool terminate();
7114
7119 void attach(SOCKET handle);
7120
7125 SOCKET detach();
7126
7131 inline SOCKET handle() const
7132 { return m_handle; }
7133
7138 virtual bool canRetry() const;
7139
7144 virtual bool inProgress() const;
7145
7150 virtual bool valid() const;
7151
7156 static SOCKET invalidHandle();
7157
7162 static int socketError();
7163
7168 static const TokenDict* tosValues();
7169
7178 virtual bool setOption(int level, int name, const void* value = 0, socklen_t length = 0);
7179
7188 inline bool setIpv6OnlyOption(bool on) {
7189 #if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY)
7190 int value = on ? 1 : 0;
7191 return setOption(IPPROTO_IPV6,IPV6_V6ONLY,&value,sizeof(value));
7192 #else
7193 return false;
7194 #endif
7195 }
7196
7205 virtual bool getOption(int level, int name, void* buffer, socklen_t* length);
7206
7211 virtual bool setParams(const NamedList& params)
7212 { return false; }
7213
7220 virtual bool getParams(const String& params, NamedList& result)
7221 { return false; }
7222
7228 virtual bool setTOS(int tos);
7229
7236 inline bool setTOS(const char* tos, int defTos = Normal)
7237 { return setTOS(lookup(tos,tosValues(),defTos)); }
7238
7243 virtual int getTOS();
7244
7250 virtual bool setBlocking(bool block = true);
7251
7259 virtual bool setReuse(bool reuse = true, bool exclusive = false);
7260
7267 virtual bool setLinger(int seconds = -1);
7268
7275 virtual bool bind(struct sockaddr* addr, socklen_t addrlen);
7276
7282 inline bool bind(const SocketAddr& addr)
7283 { return bind(addr.address(), addr.length()); }
7284
7290 virtual bool listen(unsigned int backlog = 0);
7291
7298 virtual Socket* accept(struct sockaddr* addr = 0, socklen_t* addrlen = 0);
7299
7305 Socket* accept(SocketAddr& addr);
7306
7313 SOCKET acceptHandle(struct sockaddr* addr = 0, socklen_t* addrlen = 0);
7314
7322 bool updateError();
7323
7328 static bool efficientSelect();
7329
7335 static bool canSelect(SOCKET handle);
7336
7341 virtual bool canSelect() const;
7342
7349 virtual bool connect(struct sockaddr* addr, socklen_t addrlen);
7350
7356 inline bool connect(const SocketAddr& addr)
7357 { return connect(addr.address(), addr.length()); }
7358
7368 virtual bool connectAsync(struct sockaddr* addr, socklen_t addrlen, unsigned int toutUs,
7369 bool* timeout = 0);
7370
7379 inline bool connectAsync(const SocketAddr& addr, unsigned int toutUs,
7380 bool* timeout = 0)
7381 { return connectAsync(addr.address(),addr.length(),toutUs,timeout); }
7382
7389 virtual bool shutdown(bool stopReads, bool stopWrites);
7390
7397 virtual bool getSockName(struct sockaddr* addr, socklen_t* addrlen);
7398
7404 bool getSockName(SocketAddr& addr);
7405
7412 virtual bool getPeerName(struct sockaddr* addr, socklen_t* addrlen);
7413
7419 bool getPeerName(SocketAddr& addr);
7420
7430 virtual int sendTo(const void* buffer, int length, const struct sockaddr* addr, socklen_t adrlen, int flags = 0);
7431
7440 inline int sendTo(const void* buffer, int length, const SocketAddr& addr, int flags = 0)
7441 { return sendTo(buffer, length, addr.address(), addr.length(), flags); }
7442
7450 virtual int send(const void* buffer, int length, int flags = 0);
7451
7458 virtual int writeData(const void* buffer, int length);
7459
7469 virtual int recvFrom(void* buffer, int length, struct sockaddr* addr = 0, socklen_t* adrlen = 0, int flags = 0);
7470
7479 int recvFrom(void* buffer, int length, SocketAddr& addr, int flags = 0);
7480
7488 virtual int recv(void* buffer, int length, int flags = 0);
7489
7496 virtual int readData(void* buffer, int length);
7497
7506 virtual bool select(bool* readok, bool* writeok, bool* except, struct timeval* timeout = 0);
7507
7516 bool select(bool* readok, bool* writeok, bool* except, int64_t timeout);
7517
7523 bool installFilter(SocketFilter* filter);
7524
7530 void removeFilter(SocketFilter* filter, bool delobj = false);
7531
7535 void clearFilters();
7536
7543 virtual void timerTick(const Time& when);
7544
7552 static bool createPair(Socket& sock1, Socket& sock2, int domain = AF_UNIX);
7553
7554 protected:
7555
7559 void copyError();
7560
7567 bool checkError(int retcode, bool strict = false);
7568
7578 bool applyFilters(void* buffer, int length, int flags, const struct sockaddr* addr = 0, socklen_t adrlen = 0);
7579
7580 SOCKET m_handle;
7581 ObjList m_filters;
7582 };
7583
7588 class YATE_API SctpSocket : public Socket
7589 {
7590 YNOCOPY(SctpSocket); // no automatic copies please
7591 public:
7595 inline SctpSocket()
7596 { }
7597
7602 inline explicit SctpSocket(SOCKET fd)
7603 : Socket(fd)
7604 { }
7605
7609 virtual ~SctpSocket();
7610
7616 virtual bool bindx(ObjList& addresses) = 0;
7617
7623 virtual bool connectx(ObjList& addresses) = 0;
7624
7634 virtual int sendTo(void* buffer, int length, int stream, SocketAddr& addr, int flags) = 0;
7635
7641 virtual Socket* accept(SocketAddr& addr)
7642 { return 0; }
7643
7652 virtual int sendMsg(const void* buf, int length, int stream, int& flags) = 0;
7653
7663 virtual int recvMsg(void* buf, int length, SocketAddr& addr, int& stream, int& flags) = 0;
7664
7671 virtual bool setStreams(int inbound, int outbound) = 0;
7672
7678 virtual bool subscribeEvents() = 0;
7679
7686 virtual bool getStreams(int& inbound, int& outbound) = 0;
7687
7693 virtual bool setPayload(u_int32_t payload) = 0;
7694 };
7695
7700 class YATE_API SocketRef : public RefObject
7701 {
7702 public:
7707 inline SocketRef(Socket** socket)
7708 : m_socket(socket)
7709 { }
7710
7715 inline SocketRef(Socket*& socket)
7716 : m_socket(&socket)
7717 { }
7718
7724 virtual void* getObject(const String& name) const
7725 { return (name == YATOM("Socket*")) ? m_socket : RefObject::getObject(name); }
7726
7727 private:
7728 SocketRef();
7729 void* m_socket;
7730 };
7731
7736 class YATE_API DnsRecord : public GenObject
7737 {
7738 YCLASS(DnsRecord,GenObject)
7739 YNOCOPY(DnsRecord);
7740 public:
7747 inline DnsRecord(int ttl, int order, int pref)
7748 : m_ttl(ttl), m_order(order), m_pref(pref)
7749 {}
7750
7754 inline DnsRecord()
7755 : m_order(0), m_pref(0)
7756 {}
7757
7762 inline int ttl() const
7763 { return m_ttl; }
7764
7769 inline int order() const
7770 { return m_order; }
7771
7776 inline int pref() const
7777 { return m_pref; }
7778
7784 virtual void dump(String& buf, const char* sep = " ");
7785
7793 static bool insert(ObjList& list, DnsRecord* rec, bool ascPref);
7794
7795 protected:
7796 int m_ttl;
7797 int m_order;
7798 int m_pref;
7799 };
7800
7805 class YATE_API TxtRecord : public DnsRecord
7806 {
7807 YCLASS(TxtRecord,DnsRecord)
7808 YNOCOPY(TxtRecord);
7809 public:
7815 inline TxtRecord(int ttl, const char* text)
7816 : DnsRecord(ttl,-1,-1), m_text(text)
7817 {}
7818
7823 inline const String& text() const
7824 { return m_text; }
7825
7831 virtual void dump(String& buf, const char* sep = " ");
7832
7838 static void copy(ObjList& dest, const ObjList& src);
7839
7840 protected:
7841 String m_text;
7842
7843 private:
7844 TxtRecord() {} // No default contructor
7845 };
7846
7851 class YATE_API SrvRecord : public DnsRecord
7852 {
7853 YCLASS(SrvRecord,DnsRecord)
7854 YNOCOPY(SrvRecord);
7855 public:
7864 inline SrvRecord(int ttl, int prio, int weight, const char* addr, int port)
7865 : DnsRecord(ttl,prio,weight), m_address(addr), m_port(port)
7866 {}
7867
7872 inline const String& address() const
7873 { return m_address; }
7874
7879 inline int port() const
7880 { return m_port; }
7881
7887 virtual void dump(String& buf, const char* sep = " ");
7888
7894 static void copy(ObjList& dest, const ObjList& src);
7895
7896 protected:
7897 String m_address;
7898 int m_port;
7899
7900 private:
7901 SrvRecord() {} // No default contructor
7902 };
7903
7908 class YATE_API NaptrRecord : public DnsRecord
7909 {
7910 YCLASS(NaptrRecord,DnsRecord)
7911 YNOCOPY(NaptrRecord);
7912 public:
7923 NaptrRecord(int ttl, int ord, int pref, const char* flags, const char* serv,
7924 const char* regexp, const char* next);
7925
7932 bool replace(String& str) const;
7933
7939 virtual void dump(String& buf, const char* sep = " ");
7940
7945 inline const String& flags() const
7946 { return m_flags; }
7947
7952 inline const String& serv() const
7953 { return m_service; }
7954
7959 inline const Regexp& regexp() const
7960 { return m_regmatch; }
7961
7966 inline const String& repTemplate() const
7967 { return m_template; }
7968
7973 inline const String& nextName() const
7974 { return m_next; }
7975
7976 protected:
7977 String m_flags;
7978 String m_service;
7979 Regexp m_regmatch;
7980 String m_template;
7981 String m_next;
7982
7983 private:
7984 NaptrRecord() {} // No default contructor
7985 };
7986
7991 class YATE_API Resolver
7992 {
7993 public:
7997 enum Type {
7998 Unknown,
7999 Srv, // SRV (Service Location)
8000 Naptr, // NAPTR (Naming Authority Pointer)
8001 A4, // A (Address)
8002 A6, // AAAA (IPv6 Address)
8003 Txt, // TXT (Text)
8004 };
8005
8012 static bool available(Type type = Unknown);
8013
8020 static bool init(int timeout = -1, int retries = -1);
8021
8030 static int query(Type type, const char* dname, ObjList& result, String* error = 0);
8031
8039 static int srvQuery(const char* dname, ObjList& result, String* error = 0);
8040
8048 static int naptrQuery(const char* dname, ObjList& result, String* error = 0);
8049
8057 static int a4Query(const char* dname, ObjList& result, String* error = 0);
8058
8066 static int a6Query(const char* dname, ObjList& result, String* error = 0);
8067
8075 static int txtQuery(const char* dname, ObjList& result, String* error = 0);
8076
8080 static const TokenDict s_types[];
8081 };
8082
8087 class YATE_API Cipher : public GenObject
8088 {
8089 public:
8093 enum Direction {
8094 Bidir,
8095 Encrypt,
8096 Decrypt,
8097 };
8098
8103 inline static const TokenDict* directions()
8104 { return s_directions; }
8105
8112 inline static Direction direction(const char* name, Direction defdir = Bidir)
8113 { return (Direction)TelEngine::lookup(name,s_directions,defdir); }
8114
8118 virtual ~Cipher();
8119
8125 virtual void* getObject(const String& name) const;
8126
8132 virtual bool valid(Direction dir = Bidir) const;
8133
8138 virtual unsigned int blockSize() const = 0;
8139
8144 virtual unsigned int initVectorSize() const;
8145
8151 unsigned int bufferSize(unsigned int len) const;
8152
8158 bool bufferFull(unsigned int len) const;
8159
8167 virtual bool setKey(const void* key, unsigned int len, Direction dir = Bidir) = 0;
8168
8175 inline bool setKey(const DataBlock& key, Direction dir = Bidir)
8176 { return setKey(key.data(),key.length(),dir); }
8177
8185 virtual bool initVector(const void* vect, unsigned int len, Direction dir = Bidir);
8186
8193 inline bool initVector(const DataBlock& vect, Direction dir = Bidir)
8194 { return initVector(vect.data(),vect.length(),dir); }
8195
8203 virtual bool encrypt(void* outData, unsigned int len, const void* inpData = 0) = 0;
8204
8210 inline bool encrypt(DataBlock& data)
8211 { return encrypt(data.data(),data.length()); }
8212
8220 virtual bool decrypt(void* outData, unsigned int len, const void* inpData = 0) = 0;
8221
8227 inline bool decrypt(DataBlock& data)
8228 { return decrypt(data.data(),data.length()); }
8229
8230 private:
8231 static const TokenDict s_directions[];
8232 };
8233
8239 class YATE_API Compressor : public String
8240 {
8241 YCLASS(Compressor,String)
8242 YNOCOPY(Compressor); // no automatic copies please
8243 public:
8249 inline Compressor(const char* format, const char* name = 0)
8250 : String(name), m_format(format)
8251 {}
8252
8256 virtual ~Compressor()
8257 {}
8258
8263 inline const String& format() const
8264 { return m_format; }
8265
8273 virtual bool init(bool comp = true, bool decomp = true,
8274 const NamedList& params = NamedList::empty())
8275 { return true; }
8276
8281 virtual void finalize(bool comp)
8282 {}
8283
8292 virtual int compress(const void* buf, unsigned int len, DataBlock& dest);
8293
8302 virtual int decompress(const void* buf, unsigned int len, DataBlock& dest);
8303
8314 virtual int writeComp(const void* buf, unsigned int len, bool flush) = 0;
8315
8324 inline int writeComp(const DataBlock& data, bool flush)
8325 { return writeComp(data.data(),data.length(),flush); }
8326
8335 inline int writeComp(const String& data, bool flush)
8336 { return writeComp(data.c_str(),data.length(),flush); }
8337
8344 virtual int readComp(DataBlock& buf, bool flush) = 0;
8345
8354 virtual int writeDecomp(const void* buf, unsigned int len, bool flush) = 0;
8355
8363 inline int writeDecomp(const DataBlock& data, bool flush)
8364 { return writeDecomp(data.data(),data.length(),flush); }
8365
8373 inline int writeDecomp(const String& data, bool flush)
8374 { return writeDecomp(data.c_str(),data.length(),flush); }
8375
8382 virtual int readDecomp(DataBlock& buf, bool flush) = 0;
8383
8384 protected:
8385 String m_format;
8386 };
8387
8393 class YATE_API SysUsage
8394 {
8395 public:
8399 enum Type {
8400 WallTime,
8401 UserTime,
8402 KernelTime
8403 };
8404
8408 static void init();
8409
8414 static u_int64_t startTime();
8415
8421 static u_int64_t usecRunTime(Type type = WallTime);
8422
8428 static u_int64_t msecRunTime(Type type = WallTime);
8429
8435 static u_int32_t secRunTime(Type type = WallTime);
8436
8442 static double runTime(Type type = WallTime);
8443
8444 };
8445
8446 }; // namespace TelEngine
8447
8448 #endif /* __YATECLASS_H */
8449
8450 /* vi: set ts=8 sw=4 sts=4 noet: */
TelEngine::TokenDict64::token
const char * token
Definition: yateclass.h:704
TelEngine::MutexPool
A Mutex pool.
Definition: yateclass.h:5441
TelEngine::Socket::sendTo
int sendTo(const void *buffer, int length, const SocketAddr &addr, int flags=0)
Definition: yateclass.h:7440
TelEngine::Time::operator=
Time & operator=(u_int64_t usec)
Definition: yateclass.h:3756
TelEngine::String::operator+=
String & operator+=(bool value)
Definition: yateclass.h:2451
TelEngine::DnsRecord
A DNS record.
Definition: yateclass.h:7736
TelEngine::RefPointerBase
Internal helper class.
Definition: yateclass.h:1073
TelEngine::c_safe
const char * c_safe(const char *str)
Definition: yateclass.h:2944
TelEngine::NamedCounter::count
int count() const
Definition: yateclass.h:3421
TelEngine::String::null
bool null() const
Definition: yateclass.h:2059
TelEngine::Lockable
Abstract interface for lockable objects.
Definition: yateclass.h:5268
TelEngine::Stream::writeData
int writeData(const DataBlock &buf)
Definition: yateclass.h:6625
TelEngine::RefPointer::RefPointer
RefPointer(const RefPointer< Obj > &value)
Definition: yateclass.h:1127
TelEngine::debugColor
const char * debugColor(int level)
TelEngine::Compressor::Compressor
Compressor(const char *format, const char *name=0)
Definition: yateclass.h:8249
TelEngine::debugLevel
int debugLevel()
TelEngine::GenPointer::GenPointer
GenPointer()
Definition: yateclass.h:1191
TelEngine::DataBlock::operator+=
DataBlock & operator+=(const DataBlock &value)
Definition: yateclass.h:4185
TelEngine::Thread::locks
int locks() const
Definition: yateclass.h:5794
TelEngine::ObjVector::operator[]
GenObject * operator[](unsigned int index) const
Definition: yateclass.h:1565
TelEngine::RefObject::alive
static bool alive(const RefObject *obj)
Definition: yateclass.h:1031
TelEngine::UChar::operator=
UChar & operator=(char code)
Definition: yateclass.h:1809
TelEngine::MutexPool::index
unsigned int index(void *ptr) const
Definition: yateclass.h:5468
TelEngine::ObjVector::setDelete
void setDelete(bool autodelete)
Definition: yateclass.h:1622
TelEngine::Hasher::hmacStart
bool hmacStart(DataBlock &opad, const DataBlock &key)
Definition: yateclass.h:4350
TelEngine::String::c_str
const char * c_str() const
Definition: yateclass.h:2030
TelEngine::ObjVector::operator[]
GenObject * operator[](signed int index) const
Definition: yateclass.h:1557
TelEngine::DataBlock
A class that holds just a block of raw data.
Definition: yateclass.h:3994
TelEngine::HashList::getList
ObjList * getList(unsigned int index) const
Definition: yateclass.h:3478
TelEngine::String::sqlEscape
String sqlEscape(char extraEsc=0) const
Definition: yateclass.h:2862
TelEngine::DebugEnabler::debugLevel
int debugLevel() const
Definition: yateclass.h:328
TelEngine::ObjList::next
ObjList * next() const
Definition: yateclass.h:1299
TelEngine::URI::getUser
const String & getUser() const
Definition: yateclass.h:5220
TelEngine::Time::sec
u_int32_t sec() const
Definition: yateclass.h:3730
TelEngine::SocketAddr::isNullAddr
bool isNullAddr() const
Definition: yateclass.h:6281
TelEngine::UChar::UChar
UChar(uint32_t code=0)
Definition: yateclass.h:1768
TelEngine::RefObject
Definition: yateclass.h:967
TelEngine::TokenDict::value
int value
Definition: yateclass.h:692
TelEngine::Regexp
A regexp matching class.
Definition: yateclass.h:3051
TelEngine::NamedIterator::NamedIterator
NamedIterator(const NamedList &list)
Definition: yateclass.h:5085
TelEngine::GenObject::setObjCounting
static void setObjCounting(bool enable)
Definition: yateclass.h:910
TelEngine::Debug
void Debug(int level, const char *format,...)
TelEngine::SocketAddr::lookupFamily
static const char * lookupFamily(int family)
Definition: yateclass.h:6437
TelEngine::Socket::handle
SOCKET handle() const
Definition: yateclass.h:7131
TelEngine::SocketAddr::scopeId
static unsigned int scopeId(struct sockaddr *addr)
Definition: yateclass.h:6341
TelEngine::CapturedEvent
A captured event string with a debug level.
Definition: yateclass.h:3183
TelEngine::String::safe
const char * safe(const char *defStr) const
Definition: yateclass.h:2045
TelEngine::Regexp::operator=
Regexp & operator=(const char *value)
Definition: yateclass.h:3082
TelEngine::String::matchString
String matchString(int index=0) const
Definition: yateclass.h:2783
TelEngine::MutexPool::mutex
Mutex * mutex(void *ptr) const
Definition: yateclass.h:5478
TelEngine::GenPointer::operator=
GenPointer< Obj > & operator=(Obj *object)
Definition: yateclass.h:1220
TelEngine::RefPointer::RefPointer
RefPointer()
Definition: yateclass.h:1120
TelEngine::String::operator<<
String & operator<<(int64_t value)
Definition: yateclass.h:2519
TelEngine::SocketAddr::operator=
SocketAddr & operator=(const SocketAddr &value)
Definition: yateclass.h:6131
TelEngine::Lock2::~Lock2
~Lock2()
Definition: yateclass.h:5678
TelEngine::ObjList::operator[]
GenObject * operator[](unsigned int index) const
Definition: yateclass.h:1347
TelEngine::GenPointer::operator=
GenPointer< Obj > & operator=(const GenPointer< Obj > &value)
Definition: yateclass.h:1214
TelEngine::ObjList::skipNull
ObjList * skipNull() const
TelEngine::NaptrRecord
A NAPTR record.
Definition: yateclass.h:7908
TelEngine::Time::toTimeval
void toTimeval(struct timeval *tv) const
Definition: yateclass.h:3775
TelEngine::ListIterator::eof
bool eof() const
Definition: yateclass.h:3663
TelEngine::CapturedEvent::capturing
static bool capturing()
Definition: yateclass.h:3217
TelEngine::MemoryStream::MemoryStream
MemoryStream()
Definition: yateclass.h:6714
TelEngine::Cipher::decrypt
bool decrypt(DataBlock &data)
Definition: yateclass.h:8227
TelEngine::UChar::code
uint32_t code() const
Definition: yateclass.h:1816
TelEngine::Compressor::init
virtual bool init(bool comp=true, bool decomp=true, const NamedList &params=NamedList::empty())
Definition: yateclass.h:8273
TelEngine::Socket::connectAsync
bool connectAsync(const SocketAddr &addr, unsigned int toutUs, bool *timeout=0)
Definition: yateclass.h:7379
TelEngine::SocketFilter
A filter for received socket data.
Definition: yateclass.h:6482
TelEngine::Hasher::hexDigest
const String & hexDigest()
Definition: yateclass.h:4287
TelEngine::strcat
const char * strcat(String &dest, const char *src)
Definition: yateclass.h:2997
TelEngine::Compressor::format
const String & format() const
Definition: yateclass.h:8263
TelEngine::NamedIterator::operator=
NamedIterator & operator=(const NamedList &list)
Definition: yateclass.h:5101
TelEngine::SrvRecord::address
const String & address() const
Definition: yateclass.h:7872
TelEngine::ObjList::autoDelete
bool autoDelete()
Definition: yateclass.h:1446
TelEngine::UChar::UChar
UChar(int32_t code)
Definition: yateclass.h:1776
TelEngine::Debugger::Formatting
Formatting
Definition: yateclass.h:576
TelEngine::GenObject::~GenObject
virtual ~GenObject()
Definition: yateclass.h:860
TelEngine::CapturedEvent::append
static void append(int level, const char *text)
Definition: yateclass.h:3232
TelEngine::Thread
Thread support class.
Definition: yateclass.h:5749
TelEngine::Hasher::update
bool update(const String &str)
Definition: yateclass.h:4312
TelEngine::Thread::locked
bool locked() const
Definition: yateclass.h:5801
TelEngine::URI::getExtra
const String & getExtra() const
Definition: yateclass.h:5241
TelEngine::Lock::~Lock
~Lock()
Definition: yateclass.h:5600
TelEngine::Compressor::writeDecomp
int writeDecomp(const String &data, bool flush)
Definition: yateclass.h:8373
TelEngine::Stream::SeekPos
SeekPos
Definition: yateclass.h:6548
TelEngine::YSTRING
constant YSTRING(const char *string)
TelEngine::File
A stream file class.
Definition: yateclass.h:6793
TelEngine::Hasher::hmac
bool hmac(const String &key, const String &msg)
Definition: yateclass.h:4394
TelEngine::SocketAddr::unStringify
static int unStringify(uint8_t *buf, const String &host, int family=Unknown)
Definition: yateclass.h:6321
TelEngine::NaptrRecord::regexp
const Regexp & regexp() const
Definition: yateclass.h:7959
TelEngine::RefPointer::operator=
RefPointer< Obj > & operator=(const RefPointer< Obj > &value)
Definition: yateclass.h:1147
TelEngine::String::boolText
static const char * boolText(bool value)
Definition: yateclass.h:2023
TelEngine::Lock2::lock
bool lock(Mutex &mx1, Mutex &mx2, long maxwait=-1)
Definition: yateclass.h:5704
TelEngine::Time::appendTo
static unsigned int appendTo(String &buf, uint64_t time, int frac=0)
Definition: yateclass.h:3902
TelEngine::Stream::Stream
Stream()
Definition: yateclass.h:6690
TelEngine::NamedList::length
unsigned int length() const
Definition: yateclass.h:4815
TelEngine::GenObject::getObjCounting
static bool getObjCounting()
Definition: yateclass.h:903
TelEngine::SocketAddr::null
bool null() const
Definition: yateclass.h:6193
TelEngine::NamedCounter::enable
void enable(bool val)
Definition: yateclass.h:3402
TelEngine::String::uriEscape
String uriEscape(char extraEsc=0, const char *noEsc=0) const
Definition: yateclass.h:2889
TelEngine::Regexp::compile
bool compile() const
Definition: yateclass.h:3089
TelEngine::String::checkBOM
bool checkBOM() const
Definition: yateclass.h:2133
TelEngine::Hasher::hmac
bool hmac(const DataBlock &key, const DataBlock &msg)
Definition: yateclass.h:4385
TelEngine::NaptrRecord::flags
const String & flags() const
Definition: yateclass.h:7945
TelEngine::SocketFilter::socket
Socket * socket() const
Definition: yateclass.h:6525
TelEngine::SHA256::hashLength
virtual unsigned int hashLength() const
Definition: yateclass.h:4689
TelEngine::Lock::Lock
Lock(Lockable &lck, long maxwait=-1)
Definition: yateclass.h:5586
TelEngine::Cipher
An abstract cipher.
Definition: yateclass.h:8087
TelEngine::SHA1::hashLength
virtual unsigned int hashLength() const
Definition: yateclass.h:4592
TelEngine::RefPointer::~RefPointer
~RefPointer()
Definition: yateclass.h:1141
TelEngine::HashList::length
unsigned int length() const
Definition: yateclass.h:3463
TelEngine::Time::msec
u_int64_t msec() const
Definition: yateclass.h:3737
TelEngine::Array::getColumn
ObjList * getColumn(int column) const
Definition: yateclass.h:1737
TelEngine::Time::Time
Time()
Definition: yateclass.h:3691
TelEngine::SocketRef::SocketRef
SocketRef(Socket *&socket)
Definition: yateclass.h:7715
TelEngine::DataBlock::data
unsigned char * data(unsigned int offs, unsigned int len=1) const
Definition: yateclass.h:4056
TelEngine::XDebug
void XDebug(int level, const char *format,...)
TelEngine::SHA1::rawLength
static unsigned int rawLength()
Definition: yateclass.h:4585
TelEngine::Base64::Base64
Base64(void *src, unsigned int len, bool copyData=true)
Definition: yateclass.h:4720
TelEngine::String::operator<<
String & operator<<(const char *value)
Definition: yateclass.h:2495
TelEngine::Socket::connect
bool connect(const SocketAddr &addr)
Definition: yateclass.h:7356
TelEngine::SrvRecord::port
int port() const
Definition: yateclass.h:7879
TelEngine::RefPointer::pointer
Obj * pointer() const
Definition: yateclass.h:1106
TelEngine::String::uriUnescape
String uriUnescape(int *errptr=0) const
Definition: yateclass.h:2905
TelEngine::Time::~Time
~Time()
Definition: yateclass.h:3723
TelEngine::SocketAddr
A socket address holder.
Definition: yateclass.h:6068
TelEngine::ObjVector::ObjVector
ObjVector(bool autodelete=true)
Definition: yateclass.h:1493
TelEngine::Time::fromTimeval
static u_int64_t fromTimeval(const struct timeval &tv)
Definition: yateclass.h:3797
TelEngine::DebugEnabler::debugChained
bool debugChained() const
Definition: yateclass.h:370
TelEngine::DataBlock::resize
void resize(unsigned int len)
Definition: yateclass.h:4144
TelEngine::DnsRecord::order
int order() const
Definition: yateclass.h:7769
TelEngine::URI::operator=
URI & operator=(const char *value)
Definition: yateclass.h:5199
TelEngine::NamedString::name
const String & name() const
Definition: yateclass.h:3275
TelEngine::SocketRef::SocketRef
SocketRef(Socket **socket)
Definition: yateclass.h:7707
TelEngine::String::atom
static const String * atom(const String *&str, const char *val)
TelEngine::String::operator<<
String & operator<<(uint64_t value)
Definition: yateclass.h:2525
TelEngine::DebugEnabler::debugName
const char * debugName() const
Definition: yateclass.h:356
TelEngine::MemoryStream::length
virtual int64_t length()
Definition: yateclass.h:6766
TelEngine::Compressor::~Compressor
virtual ~Compressor()
Definition: yateclass.h:8256
TelEngine::String::operator<<
String & operator<<(double value)
Definition: yateclass.h:2537
TelEngine::Array
A list based Array.
Definition: yateclass.h:1639
TelEngine::MemoryStream::MemoryStream
MemoryStream(const DataBlock &data)
Definition: yateclass.h:6722
TelEngine::Socket::bind
bool bind(const SocketAddr &addr)
Definition: yateclass.h:7282
TelEngine::ListIterator::length
unsigned int length() const
Definition: yateclass.h:3615
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:7864
TelEngine::NamedIterator::operator=
NamedIterator & operator=(const NamedIterator &original)
Definition: yateclass.h:5108
TelEngine::Random::set
void set(u_int32_t seed)
Definition: yateclass.h:3965
TelEngine::ObjList::remove
GenObject * remove(bool delobj=true)
TelEngine::NamedPointer::userObject
void * userObject(const String &name) const
Definition: yateclass.h:3350
TelEngine::SocketAddr::familyName
const char * familyName()
Definition: yateclass.h:6207
TelEngine::NaptrRecord::nextName
const String & nextName() const
Definition: yateclass.h:7973
TelEngine::DebugEnabler::debugName
void debugName(const char *name)
Definition: yateclass.h:391
TelEngine::Hasher::Hasher
Hasher()
Definition: yateclass.h:4413
TelEngine::RefPointer::operator=
RefPointer< Obj > & operator=(Obj *object)
Definition: yateclass.h:1153
TelEngine::ObjVector::at
GenObject * at(int index) const
Definition: yateclass.h:1549
TelEngine::NamedList::setParam
NamedList & setParam(NamedString *param)
Definition: yateclass.h:4852
TelEngine::TempObjectCounter
Ephemeral object counter changer.
Definition: yateclass.h:6020
TelEngine::String::stripBOM
static bool stripBOM(const char *&str)
Definition: yateclass.h:2141
TelEngine::Lock::acquire
bool acquire(Lockable &lck, long maxwait=-1)
Definition: yateclass.h:5632
TelEngine::Socket::getParams
virtual bool getParams(const String &params, NamedList &result)
Definition: yateclass.h:7220
TelEngine::CapturedEvent::eventsRw
static ObjList & eventsRw()
Definition: yateclass.h:3240
TelEngine::Resolver::Type
Type
Definition: yateclass.h:7997
TelEngine::Runnable
Encapsulates a runnable task.
Definition: yateclass.h:5728
TelEngine::MemoryStream::valid
virtual bool valid() const
Definition: yateclass.h:6743
TelEngine::CapturedEvent::CapturedEvent
CapturedEvent(int level, const char *text)
Definition: yateclass.h:3193
TelEngine::Compressor::writeComp
int writeComp(const String &data, bool flush)
Definition: yateclass.h:8335
TelEngine::Base64::operator<<
Base64 & operator<<(const DataBlock &data)
Definition: yateclass.h:4757
TelEngine::SctpSocket
Abstract SCTP Socket.
Definition: yateclass.h:7588
TelEngine::SocketAddr::address
struct sockaddr * address() const
Definition: yateclass.h:6267
TelEngine::SHA1
A standard SHA1 digest calculator.
Definition: yateclass.h:4520
TelEngine::GenObject::destruct
virtual void destruct()
TelEngine::GenPointer::GenPointer
GenPointer(Obj *object)
Definition: yateclass.h:1207
TelEngine::Time::toNtp
uint32_t toNtp(uint32_t *over=0, bool rfc2030=true)
Definition: yateclass.h:3865
TelEngine::Time::Time
Time(const struct timeval *tv)
Definition: yateclass.h:3707
TelEngine::URI
Encapsulation for an URI.
Definition: yateclass.h:5140
TelEngine::SocketAddr::family
int family() const
Definition: yateclass.h:6200
TelEngine::NamedList::count
unsigned int count() const
Definition: yateclass.h:4822
TelEngine::DataBlock::overAlloc
void overAlloc(unsigned int bytes)
Definition: yateclass.h:4093
TelEngine::Time::operator-=
Time & operator-=(int64_t delta)
Definition: yateclass.h:3768
TelEngine::Hasher::operator<<
Hasher & operator<<(const String &value)
Definition: yateclass.h:4319
TelEngine::String::operator=
String & operator=(const String &value)
Definition: yateclass.h:2348
TelEngine::String::operator=
String & operator=(bool value)
Definition: yateclass.h:2400
TelEngine::String::checkBOM
static bool checkBOM(const char *str)
Definition: yateclass.h:2126
TelEngine::URI::operator=
URI & operator=(const URI &value)
Definition: yateclass.h:5185
TelEngine::DataBlock::operator[]
int operator[](signed int index) const
Definition: yateclass.h:4166
TelEngine::SysUsage
A class exposing system resources usage.
Definition: yateclass.h:8393
TelEngine::CapturedEvent::capturing
static void capturing(bool capture)
Definition: yateclass.h:3247
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:4174
TelEngine::CapturedEvent::CapturedEvent
CapturedEvent(const CapturedEvent &original)
Definition: yateclass.h:3201
TelEngine::NamedIterator::eof
bool eof() const
Definition: yateclass.h:5120
TelEngine::ObjList::operator[]
GenObject * operator[](signed int index) const
Definition: yateclass.h:1339
TelEngine::SocketRef::getObject
virtual void * getObject(const String &name) const
Definition: yateclass.h:7724
TelEngine::Base64::operator<<
Base64 & operator<<(const String &value)
Definition: yateclass.h:4751
TelEngine::destruct
void destruct(GenObject *obj)
Definition: yateclass.h:951
TelEngine::Cipher::initVector
bool initVector(const DataBlock &vect, Direction dir=Bidir)
Definition: yateclass.h:8193
TelEngine::MD5::rawLength
static unsigned int rawLength()
Definition: yateclass.h:4498
TelEngine::SocketAddr::host
const String & host() const
Definition: yateclass.h:6229
TelEngine::SocketAddr::scopeId
bool scopeId(unsigned int val)
Definition: yateclass.h:6222
TelEngine::URI::operator=
URI & operator=(const String &value)
Definition: yateclass.h:5192
TelEngine::String::operator[]
char operator[](signed int index) const
Definition: yateclass.h:2300
TelEngine::RefPointerBase::assign
void assign(RefObject *oldptr, RefObject *newptr, void *pointer)
TelEngine::Stream::seek
int64_t seek(int64_t offset)
Definition: yateclass.h:6655
TelEngine::NamedList::paramList
ObjList * paramList()
Definition: yateclass.h:5058
TelEngine::UChar::UChar
UChar(unsigned char code)
Definition: yateclass.h:1792
TelEngine::UChar::operator=
UChar & operator=(uint32_t code)
Definition: yateclass.h:1801
TelEngine::SocketAddr::appendTo
static String & appendTo(String &buf, const String &addr, int port, int family=Unknown)
Definition: yateclass.h:6382
TelEngine::RefPointer::operator*
Obj & operator*() const
Definition: yateclass.h:1172
TelEngine::TxtRecord::TxtRecord
TxtRecord(int ttl, const char *text)
Definition: yateclass.h:7815
TelEngine::RefPointer::RefPointer
RefPointer(Obj *object)
Definition: yateclass.h:1135
TelEngine::Socket::DSCP
DSCP
Definition: yateclass.h:7047
TelEngine::NamedPointer::userData
GenObject * userData() const
Definition: yateclass.h:3328
TelEngine::UChar
A single Unicode character.
Definition: yateclass.h:1756
TelEngine::DataBlock::append
void append(void *value, unsigned int len)
Definition: yateclass.h:4116
TelEngine::DataBlock::unHexify
bool unHexify(const String &data)
Definition: yateclass.h:4234
TelEngine::SocketAddr::appendTo
static String appendTo(const String &addr, int port, int family=Unknown)
Definition: yateclass.h:6395
TelEngine::Time
A time holding class.
Definition: yateclass.h:3685
TelEngine::Time::operator+=
Time & operator+=(int64_t delta)
Definition: yateclass.h:3762
TelEngine::Time::isLeap
static bool isLeap(unsigned int year)
Definition: yateclass.h:3926
TelEngine::SocketAddr::SocketAddr
SocketAddr(const SocketAddr &value)
Definition: yateclass.h:6103
TelEngine::TxtRecord::text
const String & text() const
Definition: yateclass.h:7823
TelEngine::Atom::operator->
const String * operator->() const
Definition: yateclass.h:3172
TelEngine::Lockable::lock
virtual bool lock(long maxwait=-1)=0
TelEngine::GenPointer::operator*
Obj & operator*() const
Definition: yateclass.h:1239
TelEngine::Cipher::Direction
Direction
Definition: yateclass.h:8093
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:5661
TelEngine::SocketRef
RefObject holding a Socket pointer.
Definition: yateclass.h:7700
TelEngine::Socket
A generic socket class.
Definition: yateclass.h:7029
TelEngine::MemoryStream::m_data
DataBlock m_data
Definition: yateclass.h:6781
TelEngine::MD5::hashLength
virtual unsigned int hashLength() const
Definition: yateclass.h:4505
TelEngine::Stream::error
int error() const
Definition: yateclass.h:6563
TelEngine::DataBlock::data
void * data() const
Definition: yateclass.h:4047
TelEngine::Lock::acquire
bool acquire(Lockable *lck, long maxwait=-1)
Definition: yateclass.h:5622
TelEngine::Hasher
An abstract hashing class.
Definition: yateclass.h:4256
TelEngine::DebugLevel
DebugLevel
Definition: yateclass.h:254
TelEngine::TempObjectCounter::TempObjectCounter
TempObjectCounter(NamedCounter *counter, bool enable=GenObject::getObjCounting())
Definition: yateclass.h:6029
TelEngine::NamedList::empty
static const NamedList & empty()
TelEngine::ListIterator::reset
void reset()
Definition: yateclass.h:3669
TelEngine::String::msgUnescape
String msgUnescape(int *errptr=0, char extraEsc=0) const
Definition: yateclass.h:2846
TelEngine::String::lenUtf8
int lenUtf8(uint32_t maxChar=0x10ffff, bool overlong=false) const
Definition: yateclass.h:2077
TelEngine::String::operator<<
String & operator<<(char value)
Definition: yateclass.h:2501
TelEngine::Debugger
An object that logs messages on creation and destruction.
Definition: yateclass.h:570
TelEngine::URI::getPort
int getPort() const
Definition: yateclass.h:5234
TelEngine::NamedIterator::reset
void reset()
Definition: yateclass.h:5126
TelEngine::Atom
Atom string holder.
Definition: yateclass.h:3150
TelEngine::String::operator<<
String & operator<<(int32_t value)
Definition: yateclass.h:2507
TelEngine::DebugEnabler::debugChain
void debugChain(const DebugEnabler *chain=0)
Definition: yateclass.h:377
TelEngine::NamedPointer
A named pointer class.
Definition: yateclass.h:3308
TelEngine::NamedCounter::enabled
bool enabled() const
Definition: yateclass.h:3395
TelEngine::YOBJECT
class * YOBJECT(class type, GenObject *pntr)
TelEngine::SocketAddr::length
socklen_t length() const
Definition: yateclass.h:6274
TelEngine::YATOM
constant YATOM(const char *string)
TelEngine::String::operator<<
String & operator<<(bool value)
Definition: yateclass.h:2531
TelEngine::Cipher::setKey
bool setKey(const DataBlock &key, Direction dir=Bidir)
Definition: yateclass.h:8175
TelEngine::String::append
String & append(const char *value, int len)
TelEngine::DDebug
void DDebug(int level, const char *format,...)
TelEngine::URI::getDescription
const String & getDescription() const
Definition: yateclass.h:5206
TelEngine::GenPointer::operator->
Obj * operator->() const
Definition: yateclass.h:1233
TelEngine::MemoryStream::m_offset
int64_t m_offset
Definition: yateclass.h:6786
TelEngine::NamedString
A named string class.
Definition: yateclass.h:3260
TelEngine::Compressor::finalize
virtual void finalize(bool comp)
Definition: yateclass.h:8281
TelEngine::SHA256
A standard SHA256 digest calculator.
Definition: yateclass.h:4617
TelEngine::Socket::setTOS
bool setTOS(const char *tos, int defTos=Normal)
Definition: yateclass.h:7236
TelEngine::String::msgEscape
String msgEscape(char extraEsc=0) const
Definition: yateclass.h:2828
TelEngine::String::operator!=
bool operator!=(const String &value) const
Definition: yateclass.h:2479
TelEngine::SHA256::rawLength
static unsigned int rawLength()
Definition: yateclass.h:4682
TelEngine::Lock::drop
void drop()
Definition: yateclass.h:5613
TelEngine::String::operator==
bool operator==(const String &value) const
Definition: yateclass.h:2473
TelEngine::Resolver
DNS services.
Definition: yateclass.h:7991
TelEngine::Array::getColumns
int getColumns() const
Definition: yateclass.h:1727
TelEngine::c_str
const char * c_str(const String *str)
Definition: yateclass.h:2936
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:2960
TelEngine::NDebug
void NDebug(int level, const char *format,...)
TelEngine::DnsRecord::pref
int pref() const
Definition: yateclass.h:7776
TelEngine::GenObject::getObject
static void * getObject(const String &name, const GenObject *obj)
Definition: yateclass.h:896
TelEngine::URI::getHost
const String & getHost() const
Definition: yateclass.h:5227
TelEngine::GenObject::getObjCounter
NamedCounter * getObjCounter() const
Definition: yateclass.h:917
TelEngine::Base64
Base64 encoder/decoder class.
Definition: yateclass.h:4704
TelEngine::YCLASSIMP3
void YCLASSIMP3(class type, class base1, class base2, class base3)
TelEngine::HashList
A hashed object list class.
Definition: yateclass.h:3437
TelEngine::SctpSocket::SctpSocket
SctpSocket()
Definition: yateclass.h:7595
TelEngine::DataBlock::clear
void clear(bool deleteData=true)
TelEngine::String::stripBOM
bool stripBOM()
Definition: yateclass.h:2156
TelEngine::SocketAddr::addr
const String & addr() const
Definition: yateclass.h:6236
TelEngine::RefObject::refcount
int refcount() const
Definition: yateclass.h:1017
TelEngine::YCLASSIMP
void YCLASSIMP(class type, class base)
TelEngine::Base64::operator<<
Base64 & operator<<(const char *value)
Definition: yateclass.h:4763
TelEngine::NamedList
A named string container class.
Definition: yateclass.h:4773
TelEngine::operator+
String operator+(const String &s1, const String &s2)
TelEngine::RefPointerBase::m_pointer
void * m_pointer
Definition: yateclass.h:1093
TelEngine::DataBlock::operator+=
DataBlock & operator+=(const String &value)
Definition: yateclass.h:4191
TelEngine::URI::getProtocol
const String & getProtocol() const
Definition: yateclass.h:5213
TelEngine::String::operator[]
char operator[](unsigned int index) const
Definition: yateclass.h:2308
TelEngine::Regexp::matches
virtual bool matches(const String &value) const
Definition: yateclass.h:3104
TelEngine::RefPointer
Templated smart pointer class.
Definition: yateclass.h:1099
TelEngine::Lock
Ephemeral mutex or semaphore locking object.
Definition: yateclass.h:5577
TelEngine::Lock2::Lock2
Lock2(Mutex &mx1, Mutex &mx2, long maxwait=-1)
Definition: yateclass.h:5671
TelEngine::SctpSocket::accept
virtual Socket * accept(SocketAddr &addr)
Definition: yateclass.h:7641
TelEngine::Hasher::hmacStart
bool hmacStart(DataBlock &opad, const String &key)
Definition: yateclass.h:4359
TelEngine::YCLASS3
void YCLASS3(class type, class base1, class base2, class base3)
TelEngine::Random
Pseudo random number generator.
Definition: yateclass.h:3943
TelEngine::operator<<
String & operator<<(String &str, const Complex &c)
Definition: yatemath.h:1685
TelEngine::GenPointer::GenPointer
GenPointer(const GenPointer< Obj > &value)
Definition: yateclass.h:1199
TelEngine::Hasher::update
bool update(const void *buf, unsigned int len)
Definition: yateclass.h:4296
TelEngine::Hasher::operator<<
Hasher & operator<<(const DataBlock &data)
Definition: yateclass.h:4326
TelEngine::Semaphore
Semaphore implementation.
Definition: yateclass.h:5499
TelEngine::Stream
An abstract stream class capable of reading and writing.
Definition: yateclass.h:6542
TelEngine::YCLASSIMP2
void YCLASSIMP2(class type, class base1, class base2)
TelEngine::Stream::clearError
void clearError()
Definition: yateclass.h:6697
TelEngine::Base64::Base64
Base64()
Definition: yateclass.h:4711
TelEngine::String::append
String & append(const ObjList &list, const char *separator=0, bool force=false)
Definition: yateclass.h:2601
TelEngine::TempObjectCounter::TempObjectCounter
TempObjectCounter(const GenObject *obj, bool enable=GenObject::getObjCounting())
Definition: yateclass.h:6038
TelEngine::MemoryStream
A Stream that operates on DataBlocks in memory.
Definition: yateclass.h:6707
TelEngine::GenPointer
Templated pointer that can be inserted in a list.
Definition: yateclass.h:1179
TelEngine::Cipher::encrypt
bool encrypt(DataBlock &data)
Definition: yateclass.h:8210
TelEngine::String::matches
virtual bool matches(const String &value) const
Definition: yateclass.h:2754
TelEngine::Thread::errorString
static bool errorString(String &buffer)
Definition: yateclass.h:5975
TelEngine::GenObject::getObject
virtual void * getObject(const String &name) const
TelEngine::Time::Time
Time(const struct timeval &tv)
Definition: yateclass.h:3715
TelEngine::Lock2
Ephemeral double mutex locking object.
Definition: yateclass.h:5651
TelEngine::SocketAddr::valid
bool valid() const
Definition: yateclass.h:6186
TelEngine::Time::now
static u_int64_t now()
TelEngine::ObjVector::length
unsigned int length() const
Definition: yateclass.h:1529
TelEngine::Compressor::writeDecomp
int writeDecomp(const DataBlock &data, bool flush)
Definition: yateclass.h:8363
TelEngine::CapturedEvent::level
int level() const
Definition: yateclass.h:3209
TelEngine::SctpSocket::SctpSocket
SctpSocket(SOCKET fd)
Definition: yateclass.h:7602
TelEngine::HashList::getHashList
ObjList * getHashList(const String &str) const
Definition: yateclass.h:3494
TelEngine::Thread::isCurrent
bool isCurrent() const
Definition: yateclass.h:5905
TelEngine::Thread::setCurrentObjCounter
static NamedCounter * setCurrentObjCounter(NamedCounter *counter)
TelEngine::File::handle
HANDLE handle() const
Definition: yateclass.h:6851
TelEngine::CapturedEvent::events
static const ObjList & events()
Definition: yateclass.h:3224
TelEngine::TxtRecord
A text based DNS record.
Definition: yateclass.h:7805
TelEngine
Definition: yateclass.h:217
TelEngine::Stream::writeData
int writeData(const String &str)
Definition: yateclass.h:6617
TelEngine::DnsRecord::ttl
int ttl() const
Definition: yateclass.h:7762
TelEngine::MemoryStream::data
const DataBlock & data() const
Definition: yateclass.h:6730
TelEngine::Socket::TOS
TOS
Definition: yateclass.h:7036
TelEngine::NamedPointer::operator=
NamedPointer & operator=(const char *value)
Definition: yateclass.h:3356
TelEngine::NamedString::operator=
NamedString & operator=(const char *value)
Definition: yateclass.h:3294
TelEngine::NamedList::paramList
const ObjList * paramList() const
Definition: yateclass.h:5065
TelEngine::SocketAddr::operator!=
bool operator!=(const SocketAddr &other) const
Definition: yateclass.h:6146
TelEngine::String
A C-style string handling class.
Definition: yateclass.h:1924
TelEngine::Atom::Atom
Atom(const char *value)
Definition: yateclass.h:3157
TelEngine::RefPointer::assign
void assign(Obj *object=0)
Definition: yateclass.h:1113
TelEngine::Lock2::locked
bool locked() const
Definition: yateclass.h:5685
TelEngine::strcpy
const char * strcpy(String &dest, const char *src)
Definition: yateclass.h:2990
TelEngine::ListIterator
Class used to iterate the items of a list.
Definition: yateclass.h:3586
TelEngine::TokenDict
Definition: yateclass.h:683
TelEngine::Cipher::directions
static const TokenDict * directions()
Definition: yateclass.h:8103
TelEngine::Thread::Priority
Priority
Definition: yateclass.h:5759
TelEngine::UChar::c_str
const char * c_str() const
Definition: yateclass.h:1823
TelEngine::Socket::setIpv6OnlyOption
bool setIpv6OnlyOption(bool on)
Definition: yateclass.h:7188
TelEngine::Time::Time
Time(u_int64_t usec)
Definition: yateclass.h:3699
TelEngine::ObjVector::autoDelete
bool autoDelete()
Definition: yateclass.h:1615
TelEngine::TempObjectCounter::TempObjectCounter
TempObjectCounter(const GenObject &obj, bool enable=GenObject::getObjCounting())
Definition: yateclass.h:6047
TelEngine::debugLevelName
const char * debugLevelName(int level)
TelEngine::DnsRecord::DnsRecord
DnsRecord(int ttl, int order, int pref)
Definition: yateclass.h:7747
TelEngine::Socket::setParams
virtual bool setParams(const NamedList &params)
Definition: yateclass.h:7211
TelEngine::Time::usec
u_int64_t usec() const
Definition: yateclass.h:3744
TelEngine::String::safe
const char * safe() const
Definition: yateclass.h:2037
TelEngine::Compressor::writeComp
int writeComp(const DataBlock &data, bool flush)
Definition: yateclass.h:8324
TelEngine::SocketAddr::scopeId
static bool scopeId(struct sockaddr *addr, unsigned int val)
Definition: yateclass.h:6355
TelEngine::Output
void Output(const char *format,...)
TelEngine::NaptrRecord::serv
const String & serv() const
Definition: yateclass.h:7952
TelEngine::TokenDict64::value
int64_t value
Definition: yateclass.h:709
TelEngine::ObjList
An object list class.
Definition: yateclass.h:1247
TelEngine::DataBlock::length
unsigned int length() const
Definition: yateclass.h:4079
TelEngine::String::length
unsigned int length() const
Definition: yateclass.h:2052
TelEngine::Alarm
void Alarm(const char *component, int level, const char *format,...)
TelEngine::Lock::Lock
Lock(Lockable *lck, long maxwait=-1)
Definition: yateclass.h:5594
TelEngine::debugAt
bool debugAt(int level)
TelEngine::DataBlock::null
bool null() const
Definition: yateclass.h:4072
TelEngine::YNOCOPY
void YNOCOPY(class type)
TelEngine::NamedList::clearParams
void clearParams()
Definition: yateclass.h:4828
TelEngine::NaptrRecord::repTemplate
const String & repTemplate() const
Definition: yateclass.h:7966
TelEngine::YCLASS
void YCLASS(class type, class base)
TelEngine::NamedIterator::NamedIterator
NamedIterator(const NamedIterator &original)
Definition: yateclass.h:5093
TelEngine::SocketAddr::scopeId
unsigned int scopeId() const
Definition: yateclass.h:6214
TelEngine::ObjList::setDelete
void setDelete(bool autodelete)
Definition: yateclass.h:1453
TelEngine::TempObjectCounter::~TempObjectCounter
~TempObjectCounter()
Definition: yateclass.h:6054
TelEngine::String::stripBOM
static bool stripBOM(char *&str)
Definition: yateclass.h:2149
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:4065
TelEngine::Hasher::update
bool update(const DataBlock &data)
Definition: yateclass.h:4304
TelEngine::SysUsage::Type
Type
Definition: yateclass.h:8399
TelEngine::HashList::getHashList
ObjList * getHashList(unsigned int hash) const
Definition: yateclass.h:3486
TelEngine::DnsRecord::DnsRecord
DnsRecord()
Definition: yateclass.h:7754
TelEngine::NamedIterator
NamedList parameters iterator.
Definition: yateclass.h:5078
TelEngine::ObjVector
A vector holding GenObjects.
Definition: yateclass.h:1485
TelEngine::MemoryStream::terminate
virtual bool terminate()
Definition: yateclass.h:6737
TelEngine::SrvRecord
A SRV record.
Definition: yateclass.h:7851
TelEngine::Random::Random
Random(u_int32_t seed=Time::now()&0xffffffff)
Definition: yateclass.h:3950
TelEngine::RefPointer::operator->
Obj * operator->() const
Definition: yateclass.h:1166
TelEngine::TokenDict64
Definition: yateclass.h:700
TelEngine::Lock::locked
Lockable * locked() const
Definition: yateclass.h:5607
TelEngine::MutexPool::mutex
Mutex * mutex(unsigned int idx) const
Definition: yateclass.h:5486
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:1784
TelEngine::SocketAddr::Family
Family
Definition: yateclass.h:6075
TelEngine::Mutex
Mutex support.
Definition: yateclass.h:5351
TelEngine::String::hash
unsigned int hash() const
Definition: yateclass.h:2163
TelEngine::MD5
A standard MD5 digest calculator.
Definition: yateclass.h:4433
TelEngine::RefPointerBase::RefPointerBase
RefPointerBase()
Definition: yateclass.h:1079
TelEngine::Compressor
An abstract data (de)compressor.
Definition: yateclass.h:8239
TelEngine::String::operator=
String & operator=(const String *value)
Definition: yateclass.h:2356
TelEngine::Engine
Engine globals.
Definition: yatengine.h:1161
TelEngine::GenObject
Definition: yateclass.h:848
TelEngine::SocketAddr::SocketAddr
SocketAddr()
Definition: yateclass.h:6095
TelEngine::DebugEnabler::debugEnabled
void debugEnabled(bool enable)
Definition: yateclass.h:349
TelEngine::DataBlock::overAlloc
unsigned int overAlloc() const
Definition: yateclass.h:4086
TelEngine::String::operator<<
String & operator<<(uint32_t value)
Definition: yateclass.h:2513
TelEngine::Array::getRows
int getRows() const
Definition: yateclass.h:1720
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:8112
TelEngine::String::operator+=
String & operator+=(const char *value)
Definition: yateclass.h:2414
TelEngine::NamedCounter
Atomic counter with name.
Definition: yateclass.h:3381
TelEngine::YCLASS2
void YCLASS2(class type, class base1, class base2)