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 
5261  double getDoubleValue(const String& name, double defvalue = 0.0) const;
5262 
5269  bool getBoolValue(const String& name, bool defvalue = false) const;
5270 
5278  int replaceParams(String& str, bool sqlEsc = false, char extraEsc = 0) const;
5279 
5288  void dump(String& str, const char* separator, char quote = 0, bool force = false) const;
5289 
5294  static const NamedList& empty();
5295 
5300  inline ObjList* paramList()
5301  { return &m_params; }
5302 
5307  inline const ObjList* paramList() const
5308  { return &m_params; }
5309 
5310 private:
5311  NamedList(); // no default constructor please
5312  ObjList m_params;
5313 };
5314 
5320 class YATE_API NamedIterator
5321 {
5322 public:
5327  inline NamedIterator(const NamedList& list)
5328  : m_list(&list), m_item(list.m_params.skipNull())
5329  { }
5330 
5335  inline NamedIterator(const NamedIterator& original)
5336  : m_list(original.m_list), m_item(original.m_item)
5337  { }
5338 
5343  inline NamedIterator& operator=(const NamedList& list)
5344  { m_list = &list; m_item = list.m_params.skipNull(); return *this; }
5345 
5350  inline NamedIterator& operator=(const NamedIterator& original)
5351  { m_list = original.m_list; m_item = original.m_item; return *this; }
5352 
5357  const NamedString* get();
5358 
5362  inline bool eof() const
5363  { return !m_item; }
5364 
5368  inline void reset()
5369  { m_item = m_list->m_params.skipNull(); }
5370 
5371 private:
5372  NamedIterator(); // no default constructor please
5373  const NamedList* m_list;
5374  const ObjList* m_item;
5375 };
5376 
5382 class YATE_API URI : public String
5383 {
5384 public:
5388  URI();
5389 
5394  URI(const URI& uri);
5395 
5400  explicit URI(const String& uri);
5401 
5406  explicit URI(const char* uri);
5407 
5416  URI(const char* proto, const char* user, const char* host, int port = 0, const char* desc = 0);
5417 
5421  void parse() const;
5422 
5427  inline URI& operator=(const URI& value)
5428  { String::operator=(value); return *this; }
5429 
5434  inline URI& operator=(const String& value)
5435  { String::operator=(value); return *this; }
5436 
5441  inline URI& operator=(const char* value)
5442  { String::operator=(value); return *this; }
5443 
5448  inline const String& getDescription() const
5449  { parse(); return m_desc; }
5450 
5455  inline const String& getProtocol() const
5456  { parse(); return m_proto; }
5457 
5462  inline const String& getUser() const
5463  { parse(); return m_user; }
5464 
5469  inline const String& getHost() const
5470  { parse(); return m_host; }
5471 
5476  inline int getPort() const
5477  { parse(); return m_port; }
5478 
5483  inline const String& getExtra() const
5484  { parse(); return m_extra; }
5485 
5486 protected:
5492  virtual void changed();
5493  mutable bool m_parsed;
5494  mutable String m_desc;
5495  mutable String m_proto;
5496  mutable String m_user;
5497  mutable String m_host;
5498  mutable String m_extra;
5499  mutable int m_port;
5500 };
5501 
5502 class MutexPrivate;
5503 class SemaphorePrivate;
5504 class ThreadPrivate;
5505 
5510 class YATE_API Lockable
5511 {
5512 public:
5516  virtual ~Lockable();
5517 
5523  virtual bool lock(long maxwait = -1) = 0;
5524 
5529  virtual bool unlock() = 0;
5530 
5536  virtual bool locked() const = 0;
5537 
5543  virtual bool check(long maxwait = -1);
5544 
5551  virtual bool unlockAll();
5552 
5558  static void wait(unsigned long maxwait);
5559 
5564  static unsigned long wait();
5565 
5572  static void startUsingNow();
5573 
5580  static void enableSafety(bool safe = true);
5581 
5586  static bool safety();
5587 };
5588 
5593 class YATE_API Mutex : public Lockable
5594 {
5595  friend class MutexPrivate;
5596 public:
5603  explicit Mutex(bool recursive = false, const char* name = 0);
5604 
5609  Mutex(const Mutex& original);
5610 
5614  ~Mutex();
5615 
5620  Mutex& operator=(const Mutex& original);
5621 
5627  virtual bool lock(long maxwait = -1);
5628 
5633  virtual bool unlock();
5634 
5640  virtual bool locked() const;
5641 
5646  const char* owner() const;
5647 
5652  bool recursive() const;
5653 
5658  static int count();
5659 
5664  static int locks();
5665 
5670  static bool efficientTimedLock();
5671 
5672 private:
5673  MutexPrivate* privDataCopy() const;
5674  MutexPrivate* m_private;
5675 };
5676 
5683 class YATE_API MutexPool
5684 {
5685 public:
5696  MutexPool(unsigned int len = 13, bool recursive = false, const char* name = 0);
5697 
5701  ~MutexPool();
5702 
5710  inline unsigned int index(void* ptr) const
5711  { return ((unsigned int)(unsigned long)ptr) % m_length; }
5712 
5720  inline Mutex* mutex(void* ptr) const
5721  { return m_data[index(ptr)]; }
5722 
5728  inline Mutex* mutex(unsigned int idx) const
5729  { return m_data[idx % m_length]; }
5730 
5731 private:
5732  String* m_name; // Mutex names
5733  Mutex** m_data; // The array
5734  unsigned int m_length; // Array length
5735 };
5736 
5741 class YATE_API Semaphore : public Lockable
5742 {
5743  friend class SemaphorePrivate;
5744 public:
5751  explicit Semaphore(unsigned int maxcount = 1, const char* name = 0,
5752  unsigned int initialCount = 1);
5753 
5758  Semaphore(const Semaphore& original);
5759 
5763  ~Semaphore();
5764 
5769  Semaphore& operator=(const Semaphore& original);
5770 
5776  virtual bool lock(long maxwait = -1);
5777 
5782  virtual bool unlock();
5783 
5789  virtual bool locked() const;
5790 
5795  static int count();
5796 
5801  static int locks();
5802 
5807  static bool efficientTimedLock();
5808 
5809 private:
5810  SemaphorePrivate* privDataCopy() const;
5811  SemaphorePrivate* m_private;
5812 };
5813 
5819 class YATE_API Lock
5820 {
5821  YNOCOPY(Lock); // no automatic copies please
5822 public:
5828  inline Lock(Lockable& lck, long maxwait = -1)
5829  { m_lock = lck.lock(maxwait) ? &lck : 0; }
5830 
5836  inline Lock(Lockable* lck, long maxwait = -1)
5837  { m_lock = (lck && lck->lock(maxwait)) ? lck : 0; }
5838 
5842  inline ~Lock()
5843  { if (m_lock) m_lock->unlock(); }
5844 
5849  inline Lockable* locked() const
5850  { return m_lock; }
5851 
5855  inline void drop()
5856  { if (m_lock) m_lock->unlock(); m_lock = 0; }
5857 
5864  inline bool acquire(Lockable* lck, long maxwait = -1)
5865  { return (lck && (lck == m_lock)) ||
5866  (drop(),(lck && (m_lock = lck->lock(maxwait) ? lck : 0))); }
5867 
5874  inline bool acquire(Lockable& lck, long maxwait = -1)
5875  { return acquire(&lck,maxwait); }
5876 
5877 private:
5878  Lockable* m_lock;
5879 
5881  inline void* operator new(size_t);
5882 
5884  inline void* operator new[](size_t);
5885 };
5886 
5893 class YATE_API Lock2
5894 {
5895  YNOCOPY(Lock2); // no automatic copies please
5896 public:
5903  inline Lock2(Mutex* mx1, Mutex* mx2, long maxwait = -1)
5904  : m_mx1(0), m_mx2(0)
5905  { lock(mx1,mx2,maxwait); }
5906 
5913  inline Lock2(Mutex& mx1, Mutex& mx2, long maxwait = -1)
5914  : m_mx1(0), m_mx2(0)
5915  { lock(&mx1,&mx2,maxwait); }
5916 
5920  inline ~Lock2()
5921  { drop(); }
5922 
5927  inline bool locked() const
5928  { return m_mx1 != 0; }
5929 
5937  bool lock(Mutex* mx1, Mutex* mx2, long maxwait = -1);
5938 
5946  inline bool lock(Mutex& mx1, Mutex& mx2, long maxwait = -1)
5947  { return lock(&mx1,&mx2,maxwait); }
5948 
5952  void drop();
5953 
5954 private:
5955  Mutex* m_mx1;
5956  Mutex* m_mx2;
5957 
5959  inline void* operator new(size_t);
5960 
5962  inline void* operator new[](size_t);
5963 };
5964 
5970 class YATE_API Runnable
5971 {
5972 public:
5977  virtual void run() = 0;
5978 
5982  virtual ~Runnable();
5983 };
5984 
5991 class YATE_API Thread : public Runnable
5992 {
5993  friend class ThreadPrivate;
5994  friend class MutexPrivate;
5995  friend class SemaphorePrivate;
5996  YNOCOPY(Thread); // no automatic copies please
5997 public:
6001  enum Priority {
6002  Lowest,
6003  Low,
6004  Normal,
6005  High,
6006  Highest
6007  };
6008 
6012  virtual void cleanup();
6013 
6018  bool startup();
6019 
6024  bool error() const;
6025 
6030  bool running() const;
6031 
6038  int getAffinity(DataBlock& outCpuMask);
6039 
6047  int setAffinity(const String& cpus);
6048 
6055  int setAffinity(const DataBlock& mask);
6056 
6061  inline int locks() const
6062  { return m_locks; }
6063 
6068  inline bool locked() const
6069  { return m_locking || m_locks; }
6070 
6075  const char* name() const;
6076 
6081  static const char* currentName();
6082 
6089  static int getCurrentAffinity(DataBlock& outCpuMask);
6090 
6097  static int getCurrentAffinity(String& outCpus, bool hex = false);
6098 
6106  static int setCurrentAffinity(const String& cpus);
6107 
6114  static int setCurrentAffinity(const DataBlock& mask);
6115 
6124  static bool parseCPUMask(const String& cpus, DataBlock& mask);
6125 
6132  static void printCPUMask(const DataBlock& mask, String& str, bool hexa = true);
6133 
6139  static void yield(bool exitCheck = false);
6140 
6146  static void idle(bool exitCheck = false);
6147 
6153  static void sleep(unsigned int sec, bool exitCheck = false);
6154 
6160  static void msleep(unsigned long msec, bool exitCheck = false);
6161 
6168  static void usleep(unsigned long usec, bool exitCheck = false);
6169 
6174  static unsigned long idleUsec();
6175 
6180  static unsigned long idleMsec();
6181 
6186  static void idleMsec(unsigned long msec);
6187 
6193  static Thread* current();
6194 
6199  static int count();
6200 
6206  static bool check(bool exitNow = true);
6207 
6211  static void exit();
6212 
6217  void cancel(bool hard = false);
6218 
6223  inline bool isCurrent() const
6224  { return current() == this; }
6225 
6230  NamedCounter* getObjCounter() const;
6231 
6237  NamedCounter* setObjCounter(NamedCounter* counter);
6238 
6244  static NamedCounter* getCurrentObjCounter(bool always = false);
6245 
6251  static NamedCounter* setCurrentObjCounter(NamedCounter* counter);
6252 
6259  static Priority priority(const char* name, Priority defvalue = Normal);
6260 
6266  static const char* priority(Priority prio);
6267 
6272  static void killall();
6273 
6278  static void preExec();
6279 
6285  static int lastError();
6286 
6293  static inline bool errorString(String& buffer)
6294  { return errorString(buffer,lastError()); }
6295 
6306  static bool errorString(String& buffer, int code);
6307 
6308 protected:
6314  Thread(const char *name = 0, Priority prio = Normal);
6315 
6321  Thread(const char *name, const char* prio);
6322 
6326  virtual ~Thread();
6327 
6328 private:
6329  ThreadPrivate* m_private;
6330  int m_locks;
6331  bool m_locking;
6332 };
6333 
6338 class YATE_API TempObjectCounter
6339 {
6340  YNOCOPY(TempObjectCounter); // no automatic copies please
6341 public:
6348  : m_saved(0), m_enabled(enable)
6349  { if (m_enabled) m_saved = Thread::setCurrentObjCounter(counter); }
6350 
6356  inline TempObjectCounter(const GenObject* obj, bool enable = GenObject::getObjCounting())
6357  : m_saved(0), m_enabled(enable && obj)
6358  { if (m_enabled) m_saved = Thread::setCurrentObjCounter(obj->getObjCounter()); }
6359 
6365  inline TempObjectCounter(const GenObject& obj, bool enable = GenObject::getObjCounting())
6366  : m_saved(0), m_enabled(enable)
6367  { if (m_enabled) m_saved = Thread::setCurrentObjCounter(obj.getObjCounter()); }
6368 
6373  { if (m_enabled) Thread::setCurrentObjCounter(m_saved); }
6374 
6375 private:
6376  NamedCounter* m_saved;
6377  bool m_enabled;
6378 };
6379 
6380 class Socket;
6381 
6386 class YATE_API SocketAddr : public GenObject
6387 {
6389 public:
6393  enum Family {
6394  Unknown = AF_UNSPEC,
6395  IPv4 = AF_INET,
6396  AfMax = AF_MAX,
6397  AfUnsupported = AfMax,
6398 #ifdef AF_INET6
6399  IPv6 = AF_INET6,
6400 #else
6401  IPv6 = AfUnsupported + 1,
6402 #endif
6403 #ifdef HAS_AF_UNIX
6404  Unix = AF_UNIX,
6405 #else
6406  Unix = AfUnsupported + 2,
6407 #endif
6408  };
6409 
6413  inline SocketAddr()
6414  : m_address(0), m_length(0)
6415  { }
6416 
6421  inline SocketAddr(const SocketAddr& value)
6422  : GenObject(),
6423  m_address(0), m_length(0)
6424  { assign(value.address(),value.length()); }
6425 
6431  explicit SocketAddr(int family, const void* raw = 0);
6432 
6438  SocketAddr(const struct sockaddr* addr, socklen_t len = 0);
6439 
6443  virtual ~SocketAddr();
6444 
6449  inline SocketAddr& operator=(const SocketAddr& value)
6450  { assign(value.address(),value.length()); return *this; }
6451 
6457  bool operator==(const SocketAddr& other) const;
6458 
6464  inline bool operator!=(const SocketAddr& other) const
6465  { return !operator==(other); }
6466 
6470  void clear();
6471 
6477  bool assign(int family);
6478 
6484  void assign(const struct sockaddr* addr, socklen_t len = 0);
6485 
6491  bool assign(const DataBlock& addr);
6492 
6498  bool local(const SocketAddr& remote);
6499 
6504  inline bool valid() const
6505  { return m_length && m_address; }
6506 
6511  inline bool null() const
6512  { return !(m_length && m_address); }
6513 
6518  inline int family() const
6519  { return m_address ? m_address->sa_family : 0; }
6520 
6525  inline const char* familyName() const
6526  { return lookupFamily(family()); }
6527 
6532  inline unsigned int scopeId() const
6533  { return scopeId(address()); }
6534 
6540  inline bool scopeId(unsigned int val)
6541  { return scopeId(address(),val); }
6542 
6547  inline const String& host() const
6548  { return m_host; }
6549 
6554  inline const String& addr() const {
6555  if (!m_addr)
6556  updateAddr();
6557  return m_addr;
6558  }
6559 
6566  virtual bool host(const String& name);
6567 
6572  int port() const;
6573 
6579  bool port(int newport);
6580 
6585  inline struct sockaddr* address() const
6586  { return m_address; }
6587 
6592  inline socklen_t length() const
6593  { return m_length; }
6594 
6599  inline bool isNullAddr() const
6600  { return isNullAddr(m_host,family()); }
6601 
6607  int copyAddr(DataBlock& addr) const;
6608 
6614  static bool supports(int family);
6615 
6621  static int family(const String& addr);
6622 
6629  static bool stringify(String& buf, struct sockaddr* addr);
6630 
6639  static inline int unStringify(uint8_t* buf, const String& host,
6640  int family = Unknown) {
6641  SocketAddr sa(family);
6642  return sa.host(host) ? copyAddr(buf,sa.address()) : Unknown;
6643  }
6644 
6652  static int copyAddr(uint8_t* buf, struct sockaddr* addr);
6653 
6659  static inline unsigned int scopeId(struct sockaddr* addr) {
6660 #ifdef AF_INET6
6661  if (addr && addr->sa_family == AF_INET6)
6662  return ((struct sockaddr_in6*)addr)->sin6_scope_id;
6663 #endif
6664  return 0;
6665  }
6666 
6673  static inline bool scopeId(struct sockaddr* addr, unsigned int val) {
6674 #ifdef AF_INET6
6675  if (addr && addr->sa_family == AF_INET6) {
6676  ((struct sockaddr_in6*)addr)->sin6_scope_id = val;
6677  return true;
6678  }
6679 #endif
6680  return false;
6681  }
6682 
6690  static String& appendAddr(String& buf, const String& addr, int family = Unknown);
6691 
6700  static inline String& appendTo(String& buf, const String& addr, int port,
6701  int family = Unknown) {
6702  appendAddr(buf,addr,family) << ":" << port;
6703  return buf;
6704  }
6705 
6713  static inline String appendTo(const String& addr, int port, int family = Unknown) {
6714  String buf;
6715  appendTo(buf,addr,port,family);
6716  return buf;
6717  }
6718 
6725  static bool isNullAddr(const String& addr, int family = Unknown);
6726 
6735  static void splitIface(const String& buf, String& addr, String* iface = 0);
6736 
6748  static void split(const String& buf, String& addr, int& port, bool portPresent = false);
6749 
6755  static inline const char* lookupFamily(int family)
6756  { return lookup(family,s_familyName); }
6757 
6762  static const String& ipv4NullAddr();
6763 
6768  static const String& ipv6NullAddr();
6769 
6774  static const TokenDict* dictFamilyName();
6775 
6776 protected:
6780  virtual void stringify();
6781 
6785  virtual void updateAddr() const;
6786 
6787  struct sockaddr* m_address;
6788  socklen_t m_length;
6789  String m_host;
6790  mutable String m_addr;
6791 
6792 private:
6793  static const TokenDict s_familyName[];
6794 };
6795 
6800 class YATE_API SocketFilter : public GenObject
6801 {
6802  friend class Socket;
6803  YNOCOPY(SocketFilter); // no automatic copies please
6804 public:
6808  SocketFilter();
6809 
6813  virtual ~SocketFilter();
6814 
6820  virtual void* getObject(const String& name) const;
6821 
6826  virtual void timerTick(const Time& when);
6827 
6837  virtual bool received(void* buffer, int length, int flags, const struct sockaddr* addr, socklen_t adrlen) = 0;
6838 
6843  inline Socket* socket() const
6844  { return m_socket; }
6845 
6850  bool valid() const;
6851 
6852 private:
6853  Socket* m_socket;
6854 };
6855 
6860 class YATE_API Stream
6861 {
6862 public:
6866  enum SeekPos {
6867  SeekBegin, // Seek from start of stream
6868  SeekEnd, // Seek from stream end
6869  SeekCurrent // Seek from current position
6870  };
6871 
6875  virtual ~Stream();
6876 
6881  inline int error() const
6882  { return m_error; }
6883 
6888  virtual bool terminate() = 0;
6889 
6894  virtual bool canRetry() const;
6895 
6900  virtual bool inProgress() const;
6901 
6906  virtual bool valid() const = 0;
6907 
6913  virtual bool setBlocking(bool block = true);
6914 
6921  virtual int writeData(const void* buffer, int length) = 0;
6922 
6928  int writeData(const char* str);
6929 
6935  inline int writeData(const String& str)
6936  { return writeData(str.c_str(), str.length()); }
6937 
6943  inline int writeData(const DataBlock& buf)
6944  { return writeData(buf.data(), buf.length()); }
6945 
6952  virtual int readData(void* buffer, int length) = 0;
6953 
6958  virtual int64_t length();
6959 
6966  virtual int64_t seek(SeekPos pos, int64_t offset = 0);
6967 
6973  inline int64_t seek(int64_t offset)
6974  { return seek(SeekBegin,offset); }
6975 
6982  static bool allocPipe(Stream*& reader, Stream*& writer);
6983 
6990  static bool allocPair(Stream*& str1, Stream*& str2);
6991 
6996  static bool supportsPipes();
6997 
7002  static bool supportsPairs();
7003 
7004 protected:
7008  inline Stream()
7009  : m_error(0)
7010  { }
7011 
7015  inline void clearError()
7016  { m_error = 0; }
7017 
7018  int m_error;
7019 };
7020 
7025 class YATE_API MemoryStream : public Stream
7026 {
7027  YNOCOPY(MemoryStream); // no automatic copies please
7028 public:
7032  inline MemoryStream()
7033  : m_offset(0)
7034  { }
7035 
7040  inline MemoryStream(const DataBlock& data)
7041  : m_data(data), m_offset(0)
7042  { }
7043 
7048  inline const DataBlock& data() const
7049  { return m_data; }
7050 
7055  virtual bool terminate()
7056  { return true; }
7061  virtual bool valid() const
7062  { return true; }
7063 
7070  virtual int writeData(const void* buffer, int len);
7071 
7078  virtual int readData(void* buffer, int len);
7079 
7084  virtual int64_t length()
7085  { return m_data.length(); }
7086 
7093  virtual int64_t seek(SeekPos pos, int64_t offset = 0);
7094 
7095 protected:
7100 
7104  int64_t m_offset;
7105 };
7106 
7111 class YATE_API File : public Stream
7112 {
7113  YNOCOPY(File); // no automatic copies please
7114 public:
7118  File();
7119 
7124  explicit File(HANDLE handle);
7125 
7129  virtual ~File();
7130 
7143  virtual bool openPath(const char* name, bool canWrite = false, bool canRead = true,
7144  bool create = false, bool append = false, bool binary = false,
7145  bool pubReadable = false, bool pubWritable = false);
7146 
7151  virtual bool terminate();
7152 
7157  void attach(HANDLE handle);
7158 
7163  HANDLE detach();
7164 
7169  inline HANDLE handle() const
7170  { return m_handle; }
7171 
7176  virtual bool canRetry() const;
7177 
7182  virtual bool valid() const;
7183 
7188  static HANDLE invalidHandle();
7189 
7195  virtual bool setBlocking(bool block = true);
7196 
7201  virtual int64_t length();
7202 
7209  virtual int64_t seek(SeekPos pos, int64_t offset = 0);
7210 
7217  virtual int writeData(const void* buffer, int length);
7218 
7225  virtual int readData(void* buffer, int length);
7226 
7232  bool getFileTime(unsigned int& secEpoch);
7233 
7240  virtual bool md5(String& buffer);
7241 
7249  static bool setFileTime(const char* name, unsigned int secEpoch, int* error = 0);
7250 
7258  static bool getFileTime(const char* name, unsigned int& secEpoch, int* error = 0);
7259 
7266  static bool exists(const char* name, int* error = 0);
7267 
7275  static bool rename(const char* oldFile, const char* newFile, int* error = 0);
7276 
7283  static bool remove(const char* name, int* error = 0);
7284 
7292  static bool md5(const char* name, String& buffer, int* error = 0);
7293 
7301  static bool mkDir(const char* path, int* error = 0, int mode = -1);
7302 
7309  static bool rmDir(const char* path, int* error = 0);
7310 
7322  static bool listDirectory(const char* path, ObjList* dirs, ObjList* files,
7323  int* error = 0);
7324 
7331  static bool createPipe(File& reader, File& writer);
7332 
7333 protected:
7334 
7338  void copyError();
7339 
7340  HANDLE m_handle;
7341 };
7342 
7347 class YATE_API Socket : public Stream
7348 {
7349  YNOCOPY(Socket); // no automatic copies please
7350 public:
7354  enum TOS {
7355  Normal = 0,
7356  LowDelay = IPTOS_LOWDELAY,
7357  MaxThroughput = IPTOS_THROUGHPUT,
7358  MaxReliability = IPTOS_RELIABILITY,
7359  MinCost = IPTOS_MINCOST,
7360  };
7361 
7365  enum DSCP {
7366  DefaultPHB = 0x00,
7367  // Class selectors
7368  CS0 = 0x00,
7369  CS1 = 0x20,
7370  CS2 = 0x40,
7371  CS3 = 0x60,
7372  CS4 = 0x80,
7373  CS5 = 0xa0,
7374  CS6 = 0xc0,
7375  CS7 = 0xe0,
7376  // Assured forwarding
7377  AF11 = 0x28,
7378  AF12 = 0x30,
7379  AF13 = 0x38,
7380  AF21 = 0x48,
7381  AF22 = 0x50,
7382  AF23 = 0x58,
7383  AF31 = 0x68,
7384  AF32 = 0x70,
7385  AF33 = 0x78,
7386  AF41 = 0x88,
7387  AF42 = 0x90,
7388  AF43 = 0x98,
7389  // Expedited forwarding
7390  ExpeditedFwd = 0xb8,
7391  VoiceAdmit = 0xb0,
7392  };
7393 
7397  Socket();
7398 
7403  explicit Socket(SOCKET handle);
7404 
7411  Socket(int domain, int type, int protocol = 0);
7412 
7416  virtual ~Socket();
7417 
7425  virtual bool create(int domain, int type, int protocol = 0);
7426 
7431  virtual bool terminate();
7432 
7437  void attach(SOCKET handle);
7438 
7443  SOCKET detach();
7444 
7449  inline SOCKET handle() const
7450  { return m_handle; }
7451 
7456  virtual bool canRetry() const;
7457 
7462  virtual bool inProgress() const;
7463 
7468  virtual bool valid() const;
7469 
7474  static SOCKET invalidHandle();
7475 
7480  static int socketError();
7481 
7486  static const TokenDict* tosValues();
7487 
7496  virtual bool setOption(int level, int name, const void* value = 0, socklen_t length = 0);
7497 
7506  inline bool setIpv6OnlyOption(bool on) {
7507 #if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY)
7508  int value = on ? 1 : 0;
7509  return setOption(IPPROTO_IPV6,IPV6_V6ONLY,&value,sizeof(value));
7510 #else
7511  return false;
7512 #endif
7513  }
7514 
7523  virtual bool getOption(int level, int name, void* buffer, socklen_t* length);
7524 
7529  virtual bool setParams(const NamedList& params)
7530  { return false; }
7531 
7538  virtual bool getParams(const String& params, NamedList& result)
7539  { return false; }
7540 
7546  virtual bool setTOS(int tos);
7547 
7554  inline bool setTOS(const char* tos, int defTos = Normal)
7555  { return setTOS(lookup(tos,tosValues(),defTos)); }
7556 
7561  virtual int getTOS();
7562 
7568  virtual bool setBlocking(bool block = true);
7569 
7577  virtual bool setReuse(bool reuse = true, bool exclusive = false);
7578 
7585  virtual bool setLinger(int seconds = -1);
7586 
7593  virtual bool bind(struct sockaddr* addr, socklen_t addrlen);
7594 
7600  inline bool bind(const SocketAddr& addr)
7601  { return bind(addr.address(), addr.length()); }
7602 
7608  virtual bool listen(unsigned int backlog = 0);
7609 
7616  virtual Socket* accept(struct sockaddr* addr = 0, socklen_t* addrlen = 0);
7617 
7623  Socket* accept(SocketAddr& addr);
7624 
7631  SOCKET acceptHandle(struct sockaddr* addr = 0, socklen_t* addrlen = 0);
7632 
7640  bool updateError();
7641 
7646  static bool efficientSelect();
7647 
7653  static bool canSelect(SOCKET handle);
7654 
7659  virtual bool canSelect() const;
7660 
7667  virtual bool connect(struct sockaddr* addr, socklen_t addrlen);
7668 
7674  inline bool connect(const SocketAddr& addr)
7675  { return connect(addr.address(), addr.length()); }
7676 
7686  virtual bool connectAsync(struct sockaddr* addr, socklen_t addrlen, unsigned int toutUs,
7687  bool* timeout = 0);
7688 
7697  inline bool connectAsync(const SocketAddr& addr, unsigned int toutUs,
7698  bool* timeout = 0)
7699  { return connectAsync(addr.address(),addr.length(),toutUs,timeout); }
7700 
7707  virtual bool shutdown(bool stopReads, bool stopWrites);
7708 
7715  virtual bool getSockName(struct sockaddr* addr, socklen_t* addrlen);
7716 
7722  bool getSockName(SocketAddr& addr);
7723 
7730  virtual bool getPeerName(struct sockaddr* addr, socklen_t* addrlen);
7731 
7737  bool getPeerName(SocketAddr& addr);
7738 
7748  virtual int sendTo(const void* buffer, int length, const struct sockaddr* addr, socklen_t adrlen, int flags = 0);
7749 
7758  inline int sendTo(const void* buffer, int length, const SocketAddr& addr, int flags = 0)
7759  { return sendTo(buffer, length, addr.address(), addr.length(), flags); }
7760 
7768  virtual int send(const void* buffer, int length, int flags = 0);
7769 
7776  virtual int writeData(const void* buffer, int length);
7777 
7787  virtual int recvFrom(void* buffer, int length, struct sockaddr* addr = 0, socklen_t* adrlen = 0, int flags = 0);
7788 
7797  int recvFrom(void* buffer, int length, SocketAddr& addr, int flags = 0);
7798 
7806  virtual int recv(void* buffer, int length, int flags = 0);
7807 
7814  virtual int readData(void* buffer, int length);
7815 
7824  virtual bool select(bool* readok, bool* writeok, bool* except, struct timeval* timeout = 0);
7825 
7834  bool select(bool* readok, bool* writeok, bool* except, int64_t timeout);
7835 
7841  bool installFilter(SocketFilter* filter);
7842 
7848  void removeFilter(SocketFilter* filter, bool delobj = false);
7849 
7853  void clearFilters();
7854 
7861  virtual void timerTick(const Time& when);
7862 
7870  static bool createPair(Socket& sock1, Socket& sock2, int domain = AF_UNIX);
7871 
7872 protected:
7873 
7877  void copyError();
7878 
7885  bool checkError(int retcode, bool strict = false);
7886 
7896  bool applyFilters(void* buffer, int length, int flags, const struct sockaddr* addr = 0, socklen_t adrlen = 0);
7897 
7898  SOCKET m_handle;
7899  ObjList m_filters;
7900 };
7901 
7906 class YATE_API SctpSocket : public Socket
7907 {
7908  YNOCOPY(SctpSocket); // no automatic copies please
7909 public:
7913  inline SctpSocket()
7914  { }
7915 
7920  inline explicit SctpSocket(SOCKET fd)
7921  : Socket(fd)
7922  { }
7923 
7927  virtual ~SctpSocket();
7928 
7934  virtual bool bindx(ObjList& addresses) = 0;
7935 
7941  virtual bool connectx(ObjList& addresses) = 0;
7942 
7952  virtual int sendTo(void* buffer, int length, int stream, SocketAddr& addr, int flags) = 0;
7953 
7959  virtual Socket* accept(SocketAddr& addr)
7960  { return 0; }
7961 
7970  virtual int sendMsg(const void* buf, int length, int stream, int& flags) = 0;
7971 
7981  virtual int recvMsg(void* buf, int length, SocketAddr& addr, int& stream, int& flags) = 0;
7982 
7989  virtual bool setStreams(int inbound, int outbound) = 0;
7990 
7996  virtual bool subscribeEvents() = 0;
7997 
8004  virtual bool getStreams(int& inbound, int& outbound) = 0;
8005 
8011  virtual bool setPayload(u_int32_t payload) = 0;
8012 };
8013 
8018 class YATE_API SocketRef : public RefObject
8019 {
8020 public:
8025  inline SocketRef(Socket** socket)
8026  : m_socket(socket)
8027  { }
8028 
8033  inline SocketRef(Socket*& socket)
8034  : m_socket(&socket)
8035  { }
8036 
8042  virtual void* getObject(const String& name) const
8043  { return (name == YATOM("Socket*")) ? m_socket : RefObject::getObject(name); }
8044 
8045 private:
8046  SocketRef();
8047  void* m_socket;
8048 };
8049 
8054 class YATE_API DnsRecord : public GenObject
8055 {
8057  YNOCOPY(DnsRecord);
8058 public:
8065  inline DnsRecord(int ttl, int order, int pref)
8066  : m_ttl(ttl), m_order(order), m_pref(pref)
8067  {}
8068 
8072  inline DnsRecord()
8073  : m_order(0), m_pref(0)
8074  {}
8075 
8080  inline int ttl() const
8081  { return m_ttl; }
8082 
8087  inline int order() const
8088  { return m_order; }
8089 
8094  inline int pref() const
8095  { return m_pref; }
8096 
8102  virtual void dump(String& buf, const char* sep = " ");
8103 
8111  static bool insert(ObjList& list, DnsRecord* rec, bool ascPref);
8112 
8113 protected:
8114  int m_ttl;
8115  int m_order;
8116  int m_pref;
8117 };
8118 
8123 class YATE_API TxtRecord : public DnsRecord
8124 {
8126  YNOCOPY(TxtRecord);
8127 public:
8133  inline TxtRecord(int ttl, const char* text)
8134  : DnsRecord(ttl,-1,-1), m_text(text)
8135  {}
8136 
8141  inline const String& text() const
8142  { return m_text; }
8143 
8149  virtual void dump(String& buf, const char* sep = " ");
8150 
8156  static void copy(ObjList& dest, const ObjList& src);
8157 
8158 protected:
8159  String m_text;
8160 
8161 private:
8162  TxtRecord() {} // No default contructor
8163 };
8164 
8169 class YATE_API SrvRecord : public DnsRecord
8170 {
8172  YNOCOPY(SrvRecord);
8173 public:
8182  inline SrvRecord(int ttl, int prio, int weight, const char* addr, int port)
8183  : DnsRecord(ttl,prio,weight), m_address(addr), m_port(port)
8184  {}
8185 
8190  inline const String& address() const
8191  { return m_address; }
8192 
8197  inline int port() const
8198  { return m_port; }
8199 
8205  virtual void dump(String& buf, const char* sep = " ");
8206 
8212  static void copy(ObjList& dest, const ObjList& src);
8213 
8214 protected:
8215  String m_address;
8216  int m_port;
8217 
8218 private:
8219  SrvRecord() {} // No default contructor
8220 };
8221 
8226 class YATE_API NaptrRecord : public DnsRecord
8227 {
8230 public:
8241  NaptrRecord(int ttl, int ord, int pref, const char* flags, const char* serv,
8242  const char* regexp, const char* next);
8243 
8250  bool replace(String& str) const;
8251 
8257  virtual void dump(String& buf, const char* sep = " ");
8258 
8263  inline const String& flags() const
8264  { return m_flags; }
8265 
8270  inline const String& serv() const
8271  { return m_service; }
8272 
8277  inline const Regexp& regexp() const
8278  { return m_regmatch; }
8279 
8284  inline const String& repTemplate() const
8285  { return m_template; }
8286 
8291  inline const String& nextName() const
8292  { return m_next; }
8293 
8294 protected:
8295  String m_flags;
8296  String m_service;
8297  Regexp m_regmatch;
8298  String m_template;
8299  String m_next;
8300 
8301 private:
8302  NaptrRecord() {} // No default contructor
8303 };
8304 
8309 class YATE_API Resolver
8310 {
8311 public:
8315  enum Type {
8316  Unknown,
8317  Srv, // SRV (Service Location)
8318  Naptr, // NAPTR (Naming Authority Pointer)
8319  A4, // A (Address)
8320  A6, // AAAA (IPv6 Address)
8321  Txt, // TXT (Text)
8322  };
8323 
8330  static bool available(Type type = Unknown);
8331 
8338  static bool init(int timeout = -1, int retries = -1);
8339 
8348  static int query(Type type, const char* dname, ObjList& result, String* error = 0);
8349 
8357  static int srvQuery(const char* dname, ObjList& result, String* error = 0);
8358 
8366  static int naptrQuery(const char* dname, ObjList& result, String* error = 0);
8367 
8375  static int a4Query(const char* dname, ObjList& result, String* error = 0);
8376 
8384  static int a6Query(const char* dname, ObjList& result, String* error = 0);
8385 
8393  static int txtQuery(const char* dname, ObjList& result, String* error = 0);
8394 
8398  static const TokenDict s_types[];
8399 };
8400 
8405 class YATE_API Cipher : public GenObject
8406 {
8407 public:
8411  enum Direction {
8412  Bidir,
8413  Encrypt,
8414  Decrypt,
8415  };
8416 
8421  inline static const TokenDict* directions()
8422  { return s_directions; }
8423 
8430  inline static Direction direction(const char* name, Direction defdir = Bidir)
8431  { return (Direction)TelEngine::lookup(name,s_directions,defdir); }
8432 
8436  virtual ~Cipher();
8437 
8443  virtual void* getObject(const String& name) const;
8444 
8450  virtual bool valid(Direction dir = Bidir) const;
8451 
8456  virtual unsigned int blockSize() const = 0;
8457 
8462  virtual unsigned int initVectorSize() const;
8463 
8469  unsigned int bufferSize(unsigned int len) const;
8470 
8476  bool bufferFull(unsigned int len) const;
8477 
8485  virtual bool setKey(const void* key, unsigned int len, Direction dir = Bidir) = 0;
8486 
8493  inline bool setKey(const DataBlock& key, Direction dir = Bidir)
8494  { return setKey(key.data(),key.length(),dir); }
8495 
8503  virtual bool initVector(const void* vect, unsigned int len, Direction dir = Bidir);
8504 
8511  inline bool initVector(const DataBlock& vect, Direction dir = Bidir)
8512  { return initVector(vect.data(),vect.length(),dir); }
8513 
8521  virtual bool encrypt(void* outData, unsigned int len, const void* inpData = 0) = 0;
8522 
8528  inline bool encrypt(DataBlock& data)
8529  { return encrypt(data.data(),data.length()); }
8530 
8538  virtual bool decrypt(void* outData, unsigned int len, const void* inpData = 0) = 0;
8539 
8545  inline bool decrypt(DataBlock& data)
8546  { return decrypt(data.data(),data.length()); }
8547 
8548 private:
8549  static const TokenDict s_directions[];
8550 };
8551 
8557 class YATE_API Compressor : public String
8558 {
8560  YNOCOPY(Compressor); // no automatic copies please
8561 public:
8567  inline Compressor(const char* format, const char* name = 0)
8568  : String(name), m_format(format)
8569  {}
8570 
8574  virtual ~Compressor()
8575  {}
8576 
8581  inline const String& format() const
8582  { return m_format; }
8583 
8591  virtual bool init(bool comp = true, bool decomp = true,
8592  const NamedList& params = NamedList::empty())
8593  { return true; }
8594 
8599  virtual void finalize(bool comp)
8600  {}
8601 
8610  virtual int compress(const void* buf, unsigned int len, DataBlock& dest);
8611 
8620  virtual int decompress(const void* buf, unsigned int len, DataBlock& dest);
8621 
8632  virtual int writeComp(const void* buf, unsigned int len, bool flush) = 0;
8633 
8642  inline int writeComp(const DataBlock& data, bool flush)
8643  { return writeComp(data.data(),data.length(),flush); }
8644 
8653  inline int writeComp(const String& data, bool flush)
8654  { return writeComp(data.c_str(),data.length(),flush); }
8655 
8662  virtual int readComp(DataBlock& buf, bool flush) = 0;
8663 
8672  virtual int writeDecomp(const void* buf, unsigned int len, bool flush) = 0;
8673 
8681  inline int writeDecomp(const DataBlock& data, bool flush)
8682  { return writeDecomp(data.data(),data.length(),flush); }
8683 
8691  inline int writeDecomp(const String& data, bool flush)
8692  { return writeDecomp(data.c_str(),data.length(),flush); }
8693 
8700  virtual int readDecomp(DataBlock& buf, bool flush) = 0;
8701 
8702 protected:
8703  String m_format;
8704 };
8705 
8711 class YATE_API SysUsage
8712 {
8713 public:
8717  enum Type {
8718  WallTime,
8719  UserTime,
8720  KernelTime
8721  };
8722 
8726  static void init();
8727 
8732  static u_int64_t startTime();
8733 
8739  static u_int64_t usecRunTime(Type type = WallTime);
8740 
8746  static u_int64_t msecRunTime(Type type = WallTime);
8747 
8753  static u_int32_t secRunTime(Type type = WallTime);
8754 
8760  static double runTime(Type type = WallTime);
8761 
8762 };
8763 
8764 }; // namespace TelEngine
8765 
8766 #endif /* __YATECLASS_H */
8767 
8768 /* vi: set ts=8 sw=4 sts=4 noet: */
const char * token
Definition: yateclass.h:869
A Mutex pool.
Definition: yateclass.h:5683
int sendTo(const void *buffer, int length, const SocketAddr &addr, int flags=0)
Definition: yateclass.h:7758
Time & operator=(u_int64_t usec)
Definition: yateclass.h:3997
String & operator+=(bool value)
Definition: yateclass.h:2670
A DNS record.
Definition: yateclass.h:8054
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:5510
int writeData(const DataBlock &buf)
Definition: yateclass.h:6943
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:8567
int debugLevel()
GenPointer()
Definition: yateclass.h:1397
DataBlock & operator+=(const DataBlock &value)
Definition: yateclass.h:4427
int locks() const
Definition: yateclass.h:6061
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:5710
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:5462
u_int32_t sec() const
Definition: yateclass.h:3971
bool isNullAddr() const
Definition: yateclass.h:6599
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:5327
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:6755
SOCKET handle() const
Definition: yateclass.h:7449
static unsigned int scopeId(struct sockaddr *addr)
Definition: yateclass.h:6659
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:5720
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:6449
void TraceDebug(const char *traceId, int level, const char *format,...)
~Lock2()
Definition: yateclass.h:5920
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:8226
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:7032
bool decrypt(DataBlock &data)
Definition: yateclass.h:8545
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:8591
bool connectAsync(const SocketAddr &addr, unsigned int toutUs, bool *timeout=0)
Definition: yateclass.h:7697
A filter for received socket data.
Definition: yateclass.h:6800
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:8581
NamedIterator & operator=(const NamedList &list)
Definition: yateclass.h:5343
const String & address() const
Definition: yateclass.h:8190
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:5991
bool update(const String &str)
Definition: yateclass.h:4554
bool locked() const
Definition: yateclass.h:6068
const String & getExtra() const
Definition: yateclass.h:5483
~Lock()
Definition: yateclass.h:5842
int writeDecomp(const String &data, bool flush)
Definition: yateclass.h:8691
SeekPos
Definition: yateclass.h:6866
constant YSTRING(const char *string)
A stream file class.
Definition: yateclass.h:7111
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:6639
const Regexp & regexp() const
Definition: yateclass.h:8277
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:5946
static unsigned int appendTo(String &buf, uint64_t time, int frac=0)
Definition: yateclass.h:4143
Stream()
Definition: yateclass.h:7008
unsigned int length() const
Definition: yateclass.h:5057
static bool getObjCounting()
Definition: yateclass.h:1109
bool null() const
Definition: yateclass.h:6511
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:8263
Socket * socket() const
Definition: yateclass.h:6843
virtual unsigned int hashLength() const
Definition: yateclass.h:4931
Lock(Lockable &lck, long maxwait=-1)
Definition: yateclass.h:5828
An abstract cipher.
Definition: yateclass.h:8405
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:8033
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:7674
int port() const
Definition: yateclass.h:8197
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:6386
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:8087
URI & operator=(const char *value)
Definition: yateclass.h:5441
const String & name() const
Definition: yateclass.h:3495
SocketRef(Socket **socket)
Definition: yateclass.h:8025
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:7084
virtual ~Compressor()
Definition: yateclass.h:8574
String & operator<<(double value)
Definition: yateclass.h:2756
A list based Array.
Definition: yateclass.h:1845
MemoryStream(const DataBlock &data)
Definition: yateclass.h:7040
bool bind(const SocketAddr &addr)
Definition: yateclass.h:7600
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:8182
NamedIterator & operator=(const NamedIterator &original)
Definition: yateclass.h:5350
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:8291
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:6338
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:5874
virtual bool getParams(const String &params, NamedList &result)
Definition: yateclass.h:7538
static ObjList & eventsRw()
Definition: yateclass.h:3460
Type
Definition: yateclass.h:8315
Encapsulates a runnable task.
Definition: yateclass.h:5970
virtual bool valid() const
Definition: yateclass.h:7061
CapturedEvent(int level, const char *text)
Definition: yateclass.h:3413
int writeComp(const String &data, bool flush)
Definition: yateclass.h:8653
Base64 & operator<<(const DataBlock &data)
Definition: yateclass.h:4999
Abstract SCTP Socket.
Definition: yateclass.h:7906
struct sockaddr * address() const
Definition: yateclass.h:6585
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:5382
int family() const
Definition: yateclass.h:6518
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:5427
int operator[](signed int index) const
Definition: yateclass.h:4408
A class exposing system resources usage.
Definition: yateclass.h:8711
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:5362
GenObject * operator[](signed int index) const
Definition: yateclass.h:1545
virtual void * getObject(const String &name) const
Definition: yateclass.h:8042
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:8511
static unsigned int rawLength()
Definition: yateclass.h:4740
const String & host() const
Definition: yateclass.h:6547
bool scopeId(unsigned int val)
Definition: yateclass.h:6540
URI & operator=(const String &value)
Definition: yateclass.h:5434
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:6973
ObjList * paramList()
Definition: yateclass.h:5300
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:6700
Obj & operator*() const
Definition: yateclass.h:1378
TxtRecord(int ttl, const char *text)
Definition: yateclass.h:8133
RefPointer(Obj *object)
Definition: yateclass.h:1341
DSCP
Definition: yateclass.h:7365
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:6713
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:6421
const String & text() const
Definition: yateclass.h:8141
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:8411
A holder for a debug level.
Definition: yateclass.h:311
Lock2(Mutex *mx1, Mutex *mx2, long maxwait=-1)
Definition: yateclass.h:5903
RefObject holding a Socket pointer.
Definition: yateclass.h:8018
A generic socket class.
Definition: yateclass.h:7347
DataBlock m_data
Definition: yateclass.h:7099
virtual unsigned int hashLength() const
Definition: yateclass.h:4747
int error() const
Definition: yateclass.h:6881
void * data() const
Definition: yateclass.h:4289
bool acquire(Lockable *lck, long maxwait=-1)
Definition: yateclass.h:5864
An abstract hashing class.
Definition: yateclass.h:4498
DebugLevel
Definition: yateclass.h:256
TempObjectCounter(NamedCounter *counter, bool enable=GenObject::getObjCounting())
Definition: yateclass.h:6347
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:5476
void reset()
Definition: yateclass.h:5368
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:6525
socklen_t length() const
Definition: yateclass.h:6592
constant YATOM(const char *string)
String & operator<<(bool value)
Definition: yateclass.h:2750
bool setKey(const DataBlock &key, Direction dir=Bidir)
Definition: yateclass.h:8493
String & append(const char *value, int len)
void DDebug(int level, const char *format,...)
const String & getDescription() const
Definition: yateclass.h:5448
Obj * operator->() const
Definition: yateclass.h:1439
int64_t m_offset
Definition: yateclass.h:7104
A named string class.
Definition: yateclass.h:3480
virtual void finalize(bool comp)
Definition: yateclass.h:8599
A standard SHA256 digest calculator.
Definition: yateclass.h:4859
bool setTOS(const char *tos, int defTos=Normal)
Definition: yateclass.h:7554
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:5855
bool operator==(const String &value) const
Definition: yateclass.h:2692
DNS services.
Definition: yateclass.h:8309
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:8094
static void * getObject(const String &name, const GenObject *obj)
Definition: yateclass.h:1102
const String & getHost() const
Definition: yateclass.h:5469
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:7913
void clear(bool deleteData=true)
bool stripBOM()
Definition: yateclass.h:2362
const String & addr() const
Definition: yateclass.h:6554
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:5455
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:5819
Lock2(Mutex &mx1, Mutex &mx2, long maxwait=-1)
Definition: yateclass.h:5913
virtual Socket * accept(SocketAddr &addr)
Definition: yateclass.h:7959
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:5741
An abstract stream class capable of reading and writing.
Definition: yateclass.h:6860
void YCLASSIMP2(class type, class base1, class base2)
void clearError()
Definition: yateclass.h:7015
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:6356
A Stream that operates on DataBlocks in memory.
Definition: yateclass.h:7025
Templated pointer that can be inserted in a list.
Definition: yateclass.h:1385
bool encrypt(DataBlock &data)
Definition: yateclass.h:8528
virtual bool matches(const String &value) const
Definition: yateclass.h:2973
static bool errorString(String &buffer)
Definition: yateclass.h:6293
virtual void * getObject(const String &name) const
Time(const struct timeval &tv)
Definition: yateclass.h:3956
Ephemeral double mutex locking object.
Definition: yateclass.h:5893
bool valid() const
Definition: yateclass.h:6504
static u_int64_t now()
unsigned int length() const
Definition: yateclass.h:1735
int writeDecomp(const DataBlock &data, bool flush)
Definition: yateclass.h:8681
int level() const
Definition: yateclass.h:3429
SctpSocket(SOCKET fd)
Definition: yateclass.h:7920
ObjList * getHashList(const String &str) const
Definition: yateclass.h:3714
bool isCurrent() const
Definition: yateclass.h:6223
static NamedCounter * setCurrentObjCounter(NamedCounter *counter)
HANDLE handle() const
Definition: yateclass.h:7169
static const ObjList & events()
Definition: yateclass.h:3444
A text based DNS record.
Definition: yateclass.h:8123
Definition: yateclass.h:219
int writeData(const String &str)
Definition: yateclass.h:6935
int ttl() const
Definition: yateclass.h:8080
const DataBlock & data() const
Definition: yateclass.h:7048
TOS
Definition: yateclass.h:7354
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:5307
bool operator!=(const SocketAddr &other) const
Definition: yateclass.h:6464
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:5927
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:8421
Priority
Definition: yateclass.h:6001
const char * c_str() const
Definition: yateclass.h:2029
bool setIpv6OnlyOption(bool on)
Definition: yateclass.h:7506
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:6365
const char * debugLevelName(int level)
DnsRecord(int ttl, int order, int pref)
Definition: yateclass.h:8065
virtual bool setParams(const NamedList &params)
Definition: yateclass.h:7529
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:8642
static bool scopeId(struct sockaddr *addr, unsigned int val)
Definition: yateclass.h:6673
void Output(const char *format,...)
const String & serv() const
Definition: yateclass.h:8270
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:5836
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:8284
void YCLASS(class type, class base)
NamedIterator(const NamedIterator &original)
Definition: yateclass.h:5335
unsigned int scopeId() const
Definition: yateclass.h:6532
void setDelete(bool autodelete)
Definition: yateclass.h:1659
~TempObjectCounter()
Definition: yateclass.h:6372
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:8717
ObjList * getHashList(unsigned int hash) const
Definition: yateclass.h:3706
DnsRecord()
Definition: yateclass.h:8072
NamedList parameters iterator.
Definition: yateclass.h:5320
A vector holding GenObjects.
Definition: yateclass.h:1691
virtual bool terminate()
Definition: yateclass.h:7055
A SRV record.
Definition: yateclass.h:8169
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:5849
Mutex * mutex(unsigned int idx) const
Definition: yateclass.h:5728
void YIGNORE(primitive value)
bool matches(const char *value) const
UChar(signed char code)
Definition: yateclass.h:1990
Family
Definition: yateclass.h:6393
Mutex support.
Definition: yateclass.h:5593
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:8557
String & operator=(const String *value)
Definition: yateclass.h:2575
Engine globals.
Definition: yatengine.h:1189
Definition: yateclass.h:1048
SocketAddr()
Definition: yateclass.h:6413
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:8430
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)