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