00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef __YATECLASS_H
00026 #define __YATECLASS_H
00027
00028 #ifndef __cplusplus
00029 #error C++ is required
00030 #endif
00031
00032 #include <sys/types.h>
00033 #include <stddef.h>
00034 #include <unistd.h>
00035 #include <errno.h>
00036
00037 #ifndef _WORDSIZE
00038 #if defined(__arch64__) || defined(__x86_64__) \
00039 || defined(__amd64__) || defined(__ia64__) \
00040 || defined(__alpha__) || defined(__sparcv9)
00041 #define _WORDSIZE 64
00042 #else
00043 #define _WORDSIZE 32
00044 #endif
00045 #endif
00046
00047 #ifndef _WINDOWS
00048 #if defined(WIN32) || defined(_WIN32)
00049 #define _WINDOWS
00050 #endif
00051 #endif
00052
00053 #ifdef _WINDOWS
00054
00055 #include <windows.h>
00056 #include <io.h>
00057 #include <direct.h>
00058
00062 typedef signed __int8 int8_t;
00063 typedef unsigned __int8 u_int8_t;
00064 typedef unsigned __int8 uint8_t;
00065 typedef signed __int16 int16_t;
00066 typedef unsigned __int16 u_int16_t;
00067 typedef unsigned __int16 uint16_t;
00068 typedef signed __int32 int32_t;
00069 typedef unsigned __int32 u_int32_t;
00070 typedef unsigned __int32 uint32_t;
00071 typedef signed __int64 int64_t;
00072 typedef unsigned __int64 u_int64_t;
00073 typedef unsigned __int64 uint64_t;
00074
00075 typedef int pid_t;
00076 typedef int socklen_t;
00077 typedef unsigned long in_addr_t;
00078
00079 #ifndef strcasecmp
00080 #define strcasecmp _stricmp
00081 #endif
00082
00083 #ifndef strncasecmp
00084 #define strncasecmp _strnicmp
00085 #endif
00086
00087 #define vsnprintf _vsnprintf
00088 #define snprintf _snprintf
00089 #define strdup _strdup
00090 #define open _open
00091 #define dup2 _dup2
00092 #define read _read
00093 #define write _write
00094 #define close _close
00095 #define getpid _getpid
00096 #define chdir _chdir
00097 #define mkdir(p,m) _mkdir(p)
00098 #define unlink _unlink
00099
00100 #define O_RDWR _O_RDWR
00101 #define O_RDONLY _O_RDONLY
00102 #define O_WRONLY _O_WRONLY
00103 #define O_APPEND _O_APPEND
00104 #define O_BINARY _O_BINARY
00105 #define O_EXCL _O_EXCL
00106 #define O_CREAT _O_CREAT
00107 #define O_TRUNC _O_TRUNC
00108 #define O_NOCTTY 0
00109
00110 #define S_IRUSR _S_IREAD
00111 #define S_IWUSR _S_IWRITE
00112 #define S_IXUSR 0
00113 #define S_IRWXU (_S_IREAD|_S_IWRITE)
00114
00115 #ifdef LIBYATE_EXPORTS
00116 #define YATE_API __declspec(dllexport)
00117 #else
00118 #ifndef LIBYATE_STATIC
00119 #define YATE_API __declspec(dllimport)
00120 #endif
00121 #endif
00122
00123 #define FMT64 "%I64d"
00124 #define FMT64U "%I64u"
00125
00126 #else
00127
00128 #include <sys/time.h>
00129 #include <sys/socket.h>
00130
00131 #if defined(__FreeBSD__)
00132 #include <netinet/in_systm.h>
00133 #endif
00134
00135 #include <netinet/in.h>
00136 #include <netinet/ip.h>
00137 #include <netinet/tcp.h>
00138 #include <arpa/inet.h>
00139 #include <netdb.h>
00140
00144 #ifndef SOCKET
00145 typedef int SOCKET;
00146 #endif
00147 #ifndef HANDLE
00148 typedef int HANDLE;
00149 #endif
00150
00151 #ifndef O_BINARY
00152 #define O_BINARY 0
00153 #endif
00154
00155 #if _WORDSIZE == 64
00156 #define FMT64 "%ld"
00157 #define FMT64U "%lu"
00158 #else
00159 #define FMT64 "%lld"
00160 #define FMT64U "%llu"
00161 #endif
00162
00163 #endif
00164
00165 #ifndef IPTOS_LOWDELAY
00166 #define IPTOS_LOWDELAY 0x10
00167 #define IPTOS_THROUGHPUT 0x08
00168 #define IPTOS_RELIABILITY 0x04
00169 #define IPTOS_MINCOST 0x02
00170 #endif
00171
00172 #ifndef YATE_API
00173 #define YATE_API
00174 #endif
00175
00176 #ifdef _WINDOWS
00177 #undef RAND_MAX
00178 #define RAND_MAX 2147483647
00179 extern "C" {
00180 YATE_API long int random();
00181 YATE_API void srandom(unsigned int seed);
00182 }
00183 #endif
00184
00188 namespace TelEngine {
00189
00190 #ifdef HAVE_GCC_FORMAT_CHECK
00191 #define FORMAT_CHECK(f) __attribute__((format(printf,(f),(f)+1)))
00192 #else
00193 #define FORMAT_CHECK(f)
00194 #endif
00195
00200 YATE_API void abortOnBug();
00201
00206 YATE_API bool abortOnBug(bool doAbort);
00207
00213 enum DebugLevel {
00214 DebugFail = 0,
00215 DebugGoOn = 2,
00216 DebugStub = 4,
00217 DebugWarn = 5,
00218 DebugMild = 6,
00219 DebugCall = 7,
00220 DebugNote = 8,
00221 DebugInfo = 9,
00222 DebugAll = 10
00223 };
00224
00229 YATE_API int debugLevel();
00230
00236 YATE_API int debugLevel(int level);
00237
00243 YATE_API bool debugAt(int level);
00244
00251 YATE_API const char* debugColor(int level);
00252
00258 class YATE_API DebugEnabler
00259 {
00260 public:
00266 inline DebugEnabler(int level = TelEngine::debugLevel(), bool enabled = true)
00267 : m_level(DebugFail), m_enabled(enabled), m_chain(0), m_name(0)
00268 { debugLevel(level); }
00269
00270 inline ~DebugEnabler()
00271 { m_name = 0; m_chain = 0; }
00272
00277 inline int debugLevel() const
00278 { return m_chain ? m_chain->debugLevel() : m_level; }
00279
00285 int debugLevel(int level);
00286
00291 inline bool debugEnabled() const
00292 { return m_chain ? m_chain->debugEnabled() : m_enabled; }
00293
00298 inline void debugEnabled(bool enable)
00299 { m_enabled = enable; m_chain = 0; }
00300
00305 inline const char* debugName() const
00306 { return m_name; }
00307
00313 bool debugAt(int level) const;
00314
00319 inline bool debugChained() const
00320 { return m_chain != 0; }
00321
00326 inline void debugChain(const DebugEnabler* chain = 0)
00327 { m_chain = (chain != this) ? chain : 0; }
00328
00333 void debugCopy(const DebugEnabler* original = 0);
00334
00335 protected:
00340 inline void debugName(const char* name)
00341 { m_name = name; }
00342
00343 private:
00344 int m_level;
00345 bool m_enabled;
00346 const DebugEnabler* m_chain;
00347 const char* m_name;
00348 };
00349
00350 #if 0
00351
00356 void DDebug(int level, const char* format, ...);
00357
00363 void DDebug(const char* facility, int level, const char* format, ...);
00364
00370 void DDebug(const DebugEnabler* local, int level, const char* format, ...);
00371
00377 void XDebug(int level, const char* format, ...);
00378
00384 void XDebug(const char* facility, int level, const char* format, ...);
00385
00391 void XDebug(const DebugEnabler* local, int level, const char* format, ...);
00392
00398 void NDebug(int level, const char* format, ...);
00399
00405 void NDebug(const char* facility, int level, const char* format, ...);
00406
00412 void NDebug(const DebugEnabler* local, int level, const char* format, ...);
00413 #endif
00414
00415 #ifdef _DEBUG
00416 #undef DEBUG
00417 #define DEBUG
00418 #endif
00419
00420 #ifdef XDEBUG
00421 #undef DEBUG
00422 #define DEBUG
00423 #endif
00424
00425 #ifdef DEBUG
00426 #define DDebug Debug
00427 #else
00428 #ifdef _WINDOWS
00429 #define DDebug
00430 #else
00431 #define DDebug(arg...)
00432 #endif
00433 #endif
00434
00435 #ifdef XDEBUG
00436 #define XDebug Debug
00437 #else
00438 #ifdef _WINDOWS
00439 #define XDebug
00440 #else
00441 #define XDebug(arg...)
00442 #endif
00443 #endif
00444
00445 #ifndef NDEBUG
00446 #define NDebug Debug
00447 #else
00448 #ifdef _WINDOWS
00449 #define NDebug
00450 #else
00451 #define NDebug(arg...)
00452 #endif
00453 #endif
00454
00460 YATE_API void Debug(int level, const char* format, ...) FORMAT_CHECK(2);
00461
00468 YATE_API void Debug(const char* facility, int level, const char* format, ...) FORMAT_CHECK(3);
00469
00476 YATE_API void Debug(const DebugEnabler* local, int level, const char* format, ...) FORMAT_CHECK(3);
00477
00482 YATE_API void Output(const char* format, ...) FORMAT_CHECK(1);
00483
00490 class YATE_API Debugger
00491 {
00492 public:
00496 enum Formatting {
00497 None = 0,
00498 Relative,
00499 Absolute,
00500 Textual,
00501 };
00502
00508 Debugger(const char* name, const char* format = 0, ...);
00509
00516 Debugger(int level, const char* name, const char* format = 0, ...);
00517
00521 ~Debugger();
00522
00527 static void setOutput(void (*outFunc)(const char*,int) = 0);
00528
00533 static void setIntOut(void (*outFunc)(const char*,int) = 0);
00534
00540 static void enableOutput(bool enable = true, bool colorize = false);
00541
00546 static void setFormatting(Formatting format);
00547
00548 private:
00549 const char* m_name;
00550 };
00551
00556 struct TokenDict {
00560 const char* token;
00561
00565 int value;
00566 };
00567
00568 class String;
00569 class Mutex;
00570
00571 #if 0
00572
00577 void YCLASS(class type,class base);
00578
00584 void YCLASSIMP(class type,class base);
00585
00592 class* YOBJECT(class type,GenObject* pntr);
00593 #endif
00594
00595 #define YCLASS(type,base) \
00596 public: virtual void* getObject(const String& name) const \
00597 { return (name == #type) ? const_cast<type*>(this) : base::getObject(name); }
00598
00599 #define YCLASSIMP(type,base) \
00600 void* type::getObject(const String& name) const \
00601 { return (name == #type) ? const_cast<type*>(this) : base::getObject(name); }
00602
00603 #define YOBJECT(type,pntr) (static_cast<type*>((pntr) ? (pntr)->getObject(#type) : 0))
00604
00608 class YATE_API GenObject
00609 {
00610 public:
00614 virtual ~GenObject() { }
00615
00622 virtual bool alive() const;
00623
00627 virtual void destruct();
00628
00635 virtual const String& toString() const;
00636
00642 virtual void* getObject(const String& name) const;
00643 };
00644
00650 inline void destruct(GenObject* obj)
00651 { if (obj) obj->destruct(); }
00652
00659 template <class Obj> void destruct(Obj*& obj)
00660 { if (obj) { obj->destruct(); obj = 0; } }
00661
00666 class YATE_API RefObject : public GenObject
00667 {
00668 public:
00673 RefObject()
00674 : m_refcount(1) { }
00675
00679 virtual ~RefObject();
00680
00687 virtual bool alive() const;
00688
00693 bool ref();
00694
00703 bool deref();
00704
00709 inline int refcount() const
00710 { return m_refcount; }
00711
00716 virtual void destruct();
00717
00722 static Mutex& refMutex();
00723
00724 protected:
00730 virtual void zeroRefs();
00731
00740 virtual bool zeroRefsTest();
00741
00747 bool refInternal();
00748
00754 bool resurrect();
00755
00761 virtual void destroyed();
00762
00763 private:
00764 int m_refcount;
00765 };
00766
00772 class YATE_API RefPointerBase
00773 {
00774 protected:
00778 inline RefPointerBase()
00779 : m_pointer(0) { }
00780
00787 void assign(RefObject* oldptr, RefObject* newptr, void* pointer);
00788
00792 void* m_pointer;
00793 };
00794
00798 template <class Obj = RefObject> class RefPointer : public RefPointerBase
00799 {
00800 protected:
00805 inline Obj* pointer() const
00806 { return static_cast<Obj*>(m_pointer); }
00807
00812 inline void assign(Obj* object = 0)
00813 { RefPointerBase::assign(pointer(),object,object); }
00814
00815 public:
00819 inline RefPointer()
00820 { }
00821
00826 inline RefPointer(const RefPointer<Obj>& value)
00827 { assign(value); }
00828
00833 inline RefPointer(Obj* object)
00834 { assign(object); }
00835
00839 inline ~RefPointer()
00840 { assign(); }
00841
00845 inline RefPointer<Obj>& operator=(const RefPointer<Obj>& value)
00846 { assign(value.pointer()); return *this; }
00847
00851 inline RefPointer<Obj>& operator=(Obj* object)
00852 { assign(object); return *this; }
00853
00858 inline operator Obj*() const
00859 { return pointer(); }
00860
00864 inline Obj* operator->() const
00865 { return pointer(); }
00866
00870 inline Obj& operator*() const
00871 { return *pointer(); }
00872 };
00873
00877 template <class Obj = GenObject> class GenPointer : public GenObject
00878 {
00879 private:
00883 Obj* m_pointer;
00884
00885 public:
00889 inline GenPointer()
00890 : m_pointer(0)
00891 { }
00892
00897 inline GenPointer(const GenPointer<Obj>& value)
00898 : m_pointer(value)
00899 { }
00900
00905 inline GenPointer(Obj* object)
00906 : m_pointer(object)
00907 { }
00908
00912 inline GenPointer<Obj>& operator=(const GenPointer<Obj>& value)
00913 { m_pointer = value; return *this; }
00914
00918 inline GenPointer<Obj>& operator=(Obj* object)
00919 { m_pointer = object; return *this; }
00920
00925 inline operator Obj*() const
00926 { return m_pointer; }
00927
00931 inline Obj* operator->() const
00932 { return m_pointer; }
00933
00937 inline Obj& operator*() const
00938 { return *m_pointer; }
00939 };
00940
00945 class YATE_API ObjList : public GenObject
00946 {
00947 public:
00951 ObjList();
00952
00956 virtual ~ObjList();
00957
00963 virtual void* getObject(const String& name) const;
00964
00969 unsigned int length() const;
00970
00975 unsigned int count() const;
00976
00981 inline GenObject* get() const
00982 { return m_obj; }
00983
00990 GenObject* set(const GenObject* obj, bool delold = true);
00991
00996 inline ObjList* next() const
00997 { return m_next; }
00998
01003 ObjList* last() const;
01004
01009 ObjList* skipNull() const;
01010
01015 ObjList* skipNext() const;
01016
01022 ObjList* operator+(int index) const;
01023
01029 GenObject* operator[](int index) const;
01030
01036 GenObject* operator[](const String& str) const;
01037
01043 ObjList* find(const GenObject* obj) const;
01044
01050 ObjList* find(const String& str) const;
01051
01058 ObjList* insert(const GenObject* obj, bool compact = true);
01059
01066 ObjList* append(const GenObject* obj, bool compact = true);
01067
01073 GenObject* remove(bool delobj = true);
01074
01081 GenObject* remove(GenObject* obj, bool delobj = true);
01082
01086 void clear();
01087
01092 inline bool autoDelete()
01093 { return m_delete; }
01094
01099 inline void setDelete(bool autodelete)
01100 { m_delete = autodelete; }
01101
01102 private:
01103 ObjList* m_next;
01104 GenObject* m_obj;
01105 bool m_delete;
01106 };
01107
01116 class YATE_API Array : public RefObject
01117 {
01118 public:
01124 Array(int columns = 0, int rows = 0);
01125
01129 virtual ~Array();
01130
01136 virtual void* getObject(const String& name) const;
01137
01144 bool addRow(ObjList* row = 0, int index = -1);
01145
01152 bool addColumn(ObjList* column = 0, int index = -1);
01153
01159 bool delRow(int index);
01160
01166 bool delColumn(int index);
01167
01174 GenObject* get(int column, int row) const;
01175
01183 bool set(GenObject* obj, int column, int row);
01184
01189 inline int getRows() const
01190 { return m_rows; }
01191
01196 inline int getColumns() const
01197 { return m_columns; }
01198
01199 private:
01200 int m_rows;
01201 int m_columns;
01202 ObjList m_obj;
01203 };
01204
01205 class Regexp;
01206 class StringMatchPrivate;
01207
01215 class YATE_API String : public GenObject
01216 {
01217 public:
01221 String();
01222
01228 String(const char* value, int len = -1);
01229
01235 String(char value, unsigned int repeat = 1);
01236
01241 String(int value);
01242
01247 String(unsigned int value);
01248
01253 String(bool value);
01254
01259 String(const String& value);
01260
01265 String(const String* value);
01266
01270 virtual ~String();
01271
01277 virtual void* getObject(const String& name) const;
01278
01282 static const String& empty();
01283
01289 inline static const char* boolText(bool value)
01290 { return value ? "true" : "false"; }
01291
01296 inline const char* c_str() const
01297 { return m_string; }
01298
01303 inline const char* safe() const
01304 { return m_string ? m_string : ""; }
01305
01310 inline unsigned int length() const
01311 { return m_length; }
01312
01317 inline bool null() const
01318 { return !m_string; }
01319
01327 static int lenUtf8(const char* value, unsigned int maxSeq = 4, bool overlong = false);
01328
01335 inline int lenUtf8(unsigned int maxSeq = 4, bool overlong = false) const
01336 { return lenUtf8(m_string,maxSeq,overlong); }
01337
01338
01346 int fixUtf8(const char* replace = 0, unsigned int maxSeq = 4, bool overlong = false);
01347
01352 unsigned int hash() const;
01353
01359 static unsigned int hash(const char* value);
01360
01364 void clear();
01365
01371 char at(int index) const;
01372
01379 String substr(int offs, int len = -1) const;
01380
01384 String& trimBlanks();
01385
01390 virtual const String& toString() const;
01391
01398 int toInteger(int defvalue = 0, int base = 0) const;
01399
01407 int toInteger(const TokenDict* tokens, int defvalue = 0, int base = 0) const;
01408
01414 double toDouble(double defvalue = 0.0) const;
01415
01421 bool toBoolean(bool defvalue = false) const;
01422
01427 bool isBoolean() const;
01428
01433 String& toUpper();
01434
01439 String& toLower();
01440
01446 inline char operator[](int index) const
01447 { return at(index); }
01448
01453 inline operator const char*() const
01454 { return m_string; };
01455
01462 String& assign(const char* value, int len = -1);
01463
01470 String& assign(char value, unsigned int repeat = 1);
01471
01480 String& hexify(void* data, unsigned int len, char sep = 0, bool upCase = false);
01481
01485 inline String& operator=(const String& value)
01486 { return operator=(value.c_str()); }
01487
01492 inline String& operator=(const String* value)
01493 { return operator=(value ? value->c_str() : ""); }
01494
01499 String& operator=(const char* value);
01500
01504 String& operator=(char value);
01505
01509 String& operator=(int value);
01510
01514 String& operator=(unsigned int value);
01515
01519 inline String& operator=(bool value)
01520 { return operator=(boolText(value)); }
01521
01526 String& operator+=(const char* value);
01527
01531 String& operator+=(char value);
01532
01536 String& operator+=(int value);
01537
01541 String& operator+=(unsigned int value);
01542
01546 inline String& operator+=(bool value)
01547 { return operator+=(boolText(value)); }
01548
01552 bool operator==(const char* value) const;
01553
01557 bool operator!=(const char* value) const;
01558
01562 bool operator==(const String& value) const;
01563
01567 bool operator!=(const String& value) const;
01568
01572 bool operator&=(const char* value) const;
01573
01577 bool operator|=(const char* value) const;
01578
01582 inline String& operator<<(const char* value)
01583 { return operator+=(value); }
01584
01588 inline String& operator<<(char value)
01589 { return operator+=(value); }
01590
01594 inline String& operator<<(int value)
01595 { return operator+=(value); }
01596
01600 inline String& operator<<(unsigned int value)
01601 { return operator+=(value); }
01602
01606 inline String& operator<<(bool value)
01607 { return operator+=(value); }
01608
01613 String& operator>>(const char* skip);
01614
01618 String& operator>>(char& store);
01619
01623 String& operator>>(int& store);
01624
01628 String& operator>>(unsigned int& store);
01629
01633 String& operator>>(bool& store);
01634
01641 String& append(const char* value, const char* separator = 0, bool force = false);
01642
01649 String& append(const ObjList* list, const char* separator = 0, bool force = false);
01650
01657 inline String& append(const ObjList& list, const char* separator = 0, bool force = false)
01658 { return append(&list,separator,force); }
01659
01665 String& append(double value, unsigned int decimals = 3);
01666
01673 int find(char what, unsigned int offs = 0) const;
01674
01681 int find(const char* what, unsigned int offs = 0) const;
01682
01688 int rfind(char what) const;
01689
01697 bool startsWith(const char* what, bool wordBreak = false, bool caseInsensitive = false) const;
01698
01706 bool endsWith(const char* what, bool wordBreak = false, bool caseInsensitive = false) const;
01707
01719 bool startSkip(const char* what, bool wordBreak = true, bool caseInsensitive = false);
01720
01726 virtual bool matches(const String& value) const
01727 { return operator==(value); }
01728
01734 bool matches(Regexp& rexp);
01735
01741 int matchOffset(int index = 0) const;
01742
01748 int matchLength(int index = 0) const;
01749
01755 inline String matchString(int index = 0) const
01756 { return substr(matchOffset(index),matchLength(index)); }
01757
01763 String replaceMatches(const String& templ) const;
01764
01769 int matchCount() const;
01770
01777 ObjList* split(char separator, bool emptyOK = true) const;
01778
01785 static String msgEscape(const char* str, char extraEsc = 0);
01786
01792 inline String msgEscape(char extraEsc = 0) const
01793 { return msgEscape(c_str(),extraEsc); }
01794
01802 static String msgUnescape(const char* str, int* errptr = 0, char extraEsc = 0);
01803
01810 inline String msgUnescape(int* errptr = 0, char extraEsc = 0) const
01811 { return msgUnescape(c_str(),errptr,extraEsc); }
01812
01819 static String sqlEscape(const char* str, char extraEsc = 0);
01820
01826 inline String sqlEscape(char extraEsc = 0) const
01827 { return sqlEscape(c_str(),extraEsc); }
01828
01835 static String uriEscape(const char* str, char extraEsc = 0);
01836
01842 inline String uriEscape(char extraEsc = 0) const
01843 { return uriEscape(c_str(),extraEsc); }
01844
01851 static String uriUnescape(const char* str, int* errptr = 0);
01852
01858 inline String uriUnescape(int* errptr = 0) const
01859 { return uriUnescape(c_str(),errptr); }
01860
01861 protected:
01865 virtual void changed();
01866
01867 private:
01868 void clearMatches();
01869 char* m_string;
01870 unsigned int m_length;
01871
01872 mutable unsigned int m_hash;
01873 StringMatchPrivate* m_matches;
01874 };
01875
01881 inline const char *c_safe(const char* str)
01882 { return str ? str : ""; }
01883
01889 inline bool null(const char* str)
01890 { return !(str && *str); }
01891
01895 YATE_API String operator+(const String& s1, const String& s2);
01896
01900 YATE_API String operator+(const String& s1, const char* s2);
01901
01905 YATE_API String operator+(const char* s1, const String& s2);
01906
01911 inline const char *strcpy(String& dest, const char* src)
01912 { dest = src; return dest.c_str(); }
01913
01918 inline const char *strcat(String& dest, const char* src)
01919 { dest += src; return dest.c_str(); }
01920
01929 YATE_API int lookup(const char* str, const TokenDict* tokens, int defvalue = 0, int base = 0);
01930
01937 YATE_API const char* lookup(int value, const TokenDict* tokens, const char* defvalue = 0);
01938
01939
01944 class YATE_API Regexp : public String
01945 {
01946 friend class String;
01947 public:
01951 Regexp();
01952
01959 Regexp(const char* value, bool extended = false, bool insensitive = false);
01960
01965 Regexp(const Regexp& value);
01966
01970 virtual ~Regexp();
01971
01975 inline Regexp& operator=(const char* value)
01976 { String::operator=(value); return *this; }
01977
01982 bool compile();
01983
01989 bool matches(const char* value) const;
01990
01996 virtual bool matches(const String& value) const
01997 { return Regexp::matches(value.safe()); }
01998
02004 void setFlags(bool extended, bool insensitive);
02005
02010 bool isExtended() const;
02011
02016 bool isCaseInsensitive() const;
02017
02018 protected:
02022 virtual void changed();
02023
02024 private:
02025 void cleanup();
02026 bool matches(const char *value, StringMatchPrivate *matchlist);
02027 void* m_regexp;
02028 int m_flags;
02029 };
02030
02035 class YATE_API NamedString : public String
02036 {
02037 public:
02043 NamedString(const char* name, const char* value = 0);
02044
02049 inline const String& name() const
02050 { return m_name; }
02051
02056 virtual const String& toString() const;
02057
02063 virtual void* getObject(const String& name) const;
02064
02068 inline NamedString& operator=(const char* value)
02069 { String::operator=(value); return *this; }
02070
02071 private:
02072 NamedString();
02073 String m_name;
02074 };
02075
02082 class YATE_API NamedPointer : public NamedString
02083 {
02084 public:
02091 NamedPointer(const char* name, GenObject* data = 0, const char* value = 0);
02092
02096 virtual ~NamedPointer();
02097
02102 inline GenObject* userData() const
02103 { return m_data; }
02104
02110 GenObject* takeData();
02111
02117 void userData(GenObject* data);
02118
02124 inline void* userObject(const String& name) const
02125 { return m_data ? m_data->getObject(name) : 0; }
02126
02130 inline NamedPointer& operator=(const char* value)
02131 { NamedString::operator=(value); return *this; }
02132
02138 virtual void* getObject(const String& name) const;
02139
02140 protected:
02144 virtual void changed();
02145
02146 private:
02147 NamedPointer();
02148 GenObject* m_data;
02149 };
02150
02158 class YATE_API HashList : public GenObject
02159 {
02160 public:
02165 HashList(unsigned int size = 17);
02166
02170 virtual ~HashList();
02171
02177 virtual void* getObject(const String& name) const;
02178
02183 inline unsigned int length() const
02184 { return m_size; }
02185
02190 unsigned int count() const;
02191
02198 inline ObjList* getList(unsigned int index) const
02199 { return (index < m_size) ? m_lists[index] : 0; }
02200
02206 inline ObjList* getHashList(unsigned int hash) const
02207 { return getList(hash % m_size); }
02208
02214 inline ObjList* getHashList(const String& str) const
02215 { return getHashList(str.hash()); }
02216
02222 GenObject* operator[](const String& str) const;
02223
02229 ObjList* find(const GenObject* obj) const;
02230
02236 ObjList* find(const String& str) const;
02237
02243 ObjList* append(const GenObject* obj);
02244
02251 GenObject* remove(GenObject* obj, bool delobj = true);
02252
02256 void clear();
02257
02264 bool resync(GenObject* obj);
02265
02271 bool resync();
02272
02273 private:
02274 unsigned int m_size;
02275 ObjList** m_lists;
02276 };
02277
02284 class YATE_API ListIterator
02285 {
02286 public:
02292 ListIterator(ObjList& list);
02293
02299 ListIterator(HashList& list);
02300
02304 ~ListIterator();
02305
02310 inline unsigned int length() const
02311 { return m_length; }
02312
02319 GenObject* get(unsigned int index) const;
02320
02333 GenObject* get();
02334
02339 inline bool eof() const
02340 { return m_current >= m_length; }
02341
02345 inline void reset()
02346 { m_current = 0; }
02347
02348 private:
02349 ObjList* m_objList;
02350 HashList* m_hashList;
02351 GenObject** m_objects;
02352 unsigned int m_length;
02353 unsigned int m_current;
02354 };
02355
02360 class YATE_API Time
02361 {
02362 public:
02366 inline Time()
02367 : m_time(now())
02368 { }
02369
02374 inline Time(u_int64_t usec)
02375 : m_time(usec)
02376 { }
02377
02382 inline Time(const struct timeval* tv)
02383 : m_time(fromTimeval(tv))
02384 { }
02385
02390 inline Time(const struct timeval& tv)
02391 : m_time(fromTimeval(tv))
02392 { }
02393
02398 inline ~Time()
02399 { }
02400
02405 inline u_int32_t sec() const
02406 { return (u_int32_t)((m_time+500000) / 1000000); }
02407
02412 inline u_int64_t msec() const
02413 { return (m_time+500) / 1000; }
02414
02419 inline u_int64_t usec() const
02420 { return m_time; }
02421
02425 inline operator u_int64_t() const
02426 { return m_time; }
02427
02431 inline Time& operator=(u_int64_t usec)
02432 { m_time = usec; return *this; }
02433
02437 inline Time& operator+=(int64_t delta)
02438 { m_time += delta; return *this; }
02439
02443 inline Time& operator-=(int64_t delta)
02444 { m_time -= delta; return *this; }
02445
02450 inline void toTimeval(struct timeval* tv) const
02451 { toTimeval(tv, m_time); }
02452
02458 static void toTimeval(struct timeval* tv, u_int64_t usec);
02459
02465 static u_int64_t fromTimeval(const struct timeval* tv);
02466
02472 inline static u_int64_t fromTimeval(const struct timeval& tv)
02473 { return fromTimeval(&tv); }
02474
02479 static u_int64_t now();
02480
02485 static u_int64_t msecNow();
02486
02491 static u_int32_t secNow();
02492
02493 private:
02494 u_int64_t m_time;
02495 };
02496
02501 class YATE_API DataBlock : public GenObject
02502 {
02503 public:
02504
02508 DataBlock();
02509
02513 DataBlock(const DataBlock& value);
02514
02521 DataBlock(void* value, unsigned int len, bool copyData = true);
02522
02526 virtual ~DataBlock();
02527
02533 virtual void* getObject(const String& name) const;
02534
02538 static const DataBlock& empty();
02539
02544 inline void* data() const
02545 { return m_data; }
02546
02551 inline bool null() const
02552 { return !m_data; }
02553
02558 inline unsigned int length() const
02559 { return m_length; }
02560
02565 void clear(bool deleteData = true);
02566
02573 DataBlock& assign(void* value, unsigned int len, bool copyData = true);
02574
02580 inline void append(void* value, unsigned int len) {
02581 DataBlock tmp(value,len,false);
02582 append(tmp);
02583 tmp.clear(false);
02584 }
02585
02590 void append(const DataBlock& value);
02591
02596 void append(const String& value);
02597
02602 void insert(const DataBlock& value);
02603
02608 void truncate(unsigned int len);
02609
02614 void cut(int len);
02615
02619 DataBlock& operator=(const DataBlock& value);
02620
02624 inline DataBlock& operator+=(const DataBlock& value)
02625 { append(value); return *this; }
02626
02630 inline DataBlock& operator+=(const String& value)
02631 { append(value); return *this; }
02632
02641 bool convert(const DataBlock& src, const String& sFormat,
02642 const String& dFormat, unsigned maxlen = 0);
02643
02654 bool unHexify(const char* data, unsigned int len, char sep = 0);
02655
02656 private:
02657 void* m_data;
02658 unsigned int m_length;
02659 };
02660
02665 class YATE_API MD5
02666 {
02667 public:
02671 MD5();
02672
02677 MD5(const MD5& original);
02678
02684 MD5(const void* buf, unsigned int len);
02685
02690 MD5(const DataBlock& data);
02691
02696 MD5(const String& str);
02697
02701 ~MD5();
02702
02706 MD5& operator=(const MD5& original);
02707
02711 void clear();
02712
02717 void finalize();
02718
02725 bool update(const void* buf, unsigned int len);
02726
02732 inline bool update(const DataBlock& data)
02733 { return update(data.data(), data.length()); }
02734
02740 inline bool update(const String& str)
02741 { return update(str.c_str(), str.length()); }
02742
02746 inline MD5& operator<<(const String& value)
02747 { update(value); return *this; }
02748
02752 inline MD5& operator<<(const DataBlock& data)
02753 { update(data); return *this; }
02754
02758 MD5& operator<<(const char* value);
02759
02765 const unsigned char* rawDigest();
02766
02771 inline static unsigned int rawLength()
02772 { return 16; }
02773
02779 const String& hexDigest();
02780
02781 private:
02782 void init();
02783 void* m_private;
02784 String m_hex;
02785 unsigned char m_bin[16];
02786 };
02787
02792 class YATE_API SHA1
02793 {
02794 public:
02798 SHA1();
02799
02804 SHA1(const SHA1& original);
02805
02811 SHA1(const void* buf, unsigned int len);
02812
02817 SHA1(const DataBlock& data);
02818
02823 SHA1(const String& str);
02824
02828 ~SHA1();
02829
02833 SHA1& operator=(const SHA1& original);
02834
02838 void clear();
02839
02844 void finalize();
02845
02852 bool update(const void* buf, unsigned int len);
02853
02859 inline bool update(const DataBlock& data)
02860 { return update(data.data(), data.length()); }
02861
02867 inline bool update(const String& str)
02868 { return update(str.c_str(), str.length()); }
02869
02873 inline SHA1& operator<<(const String& value)
02874 { update(value); return *this; }
02875
02879 inline SHA1& operator<<(const DataBlock& data)
02880 { update(data); return *this; }
02881
02885 SHA1& operator<<(const char* value);
02886
02892 const unsigned char* rawDigest();
02893
02898 inline static unsigned int rawLength()
02899 { return 20; }
02900
02906 const String& hexDigest();
02907
02908 private:
02909 void init();
02910 void* m_private;
02911 String m_hex;
02912 unsigned char m_bin[20];
02913 };
02914
02919 class YATE_API Base64 : public DataBlock
02920 {
02921 public:
02925 inline Base64()
02926 {}
02927
02934 inline Base64(void* src, unsigned int len, bool copyData = true)
02935 : DataBlock(src,len,copyData)
02936 {}
02937
02947 void encode(String& dest, unsigned int lineLen = 0, bool lineAtEnd = false);
02948
02960 bool decode(DataBlock& dest, bool liberal = true);
02961
02965 inline Base64& operator<<(const String& value)
02966 { append(value); return *this; }
02967
02971 inline Base64& operator<<(const DataBlock& data)
02972 { append(data); return *this; }
02973
02977 inline Base64& operator<<(const char* value)
02978 { return operator<<(String(value)); }
02979 };
02980
02985 class YATE_API NamedList : public String
02986 {
02987 public:
02992 NamedList(const char* name);
02993
02998 NamedList(const NamedList& original);
02999
03005 virtual void* getObject(const String& name) const;
03006
03011 inline unsigned int length() const
03012 { return m_params.length(); }
03013
03018 inline unsigned int count() const
03019 { return m_params.count(); }
03020
03025 NamedList& addParam(NamedString* param);
03026
03032 NamedList& addParam(const char* name, const char* value);
03033
03038 NamedList& setParam(NamedString* param);
03039
03045 NamedList& setParam(const char* name, const char* value);
03046
03052 NamedList& clearParam(const String& name, char childSep = 0);
03053
03060 NamedList& copyParam(const NamedList& original, const String& name, char childSep = 0);
03061
03068 NamedList& copyParams(const NamedList& original, ObjList* list, char childSep = 0);
03069
03076 NamedList& copyParams(const NamedList& original, const String& list, char childSep = 0);
03077
03083 int getIndex(const NamedString* param) const;
03084
03090 int getIndex(const String& name) const;
03091
03097 NamedString* getParam(const String& name) const;
03098
03104 NamedString* getParam(unsigned int index) const;
03105
03111 const String& operator[](const String& name) const;
03112
03119 const char* getValue(const String& name, const char* defvalue = 0) const;
03120
03127 int getIntValue(const String& name, int defvalue = 0) const;
03128
03136 int getIntValue(const String& name, const TokenDict* tokens, int defvalue = 0) const;
03137
03144 double getDoubleValue(const String& name, double defvalue = 0.0) const;
03145
03152 bool getBoolValue(const String& name, bool defvalue = false) const;
03153
03161 int replaceParams(String& str, bool sqlEsc = false, char extraEsc = 0) const;
03162
03163 private:
03164 NamedList();
03165 NamedList& operator=(const NamedList& value);
03166 ObjList m_params;
03167 };
03168
03174 class YATE_API URI : public String
03175 {
03176 public:
03180 URI();
03181
03186 URI(const URI& uri);
03187
03192 URI(const String& uri);
03193
03198 URI(const char* uri);
03199
03208 URI(const char* proto, const char* user, const char* host, int port = 0, const char* desc = 0);
03209
03213 void parse() const;
03214
03219 inline URI& operator=(const URI& value)
03220 { String::operator=(value); return *this; }
03221
03226 inline URI& operator=(const String& value)
03227 { String::operator=(value); return *this; }
03228
03233 inline URI& operator=(const char* value)
03234 { String::operator=(value); return *this; }
03235
03240 inline const String& getDescription() const
03241 { parse(); return m_desc; }
03242
03247 inline const String& getProtocol() const
03248 { parse(); return m_proto; }
03249
03254 inline const String& getUser() const
03255 { parse(); return m_user; }
03256
03261 inline const String& getHost() const
03262 { parse(); return m_host; }
03263
03268 inline int getPort() const
03269 { parse(); return m_port; }
03270 protected:
03276 virtual void changed();
03277 mutable bool m_parsed;
03278 mutable String m_desc;
03279 mutable String m_proto;
03280 mutable String m_user;
03281 mutable String m_host;
03282 mutable int m_port;
03283 };
03284
03285 class MutexPrivate;
03286 class ThreadPrivate;
03287
03292 class YATE_API Mutex
03293 {
03294 friend class MutexPrivate;
03295 public:
03299 Mutex();
03300
03306 Mutex(bool recursive);
03307
03312 Mutex(const Mutex& original);
03313
03317 ~Mutex();
03318
03323 Mutex& operator=(const Mutex& original);
03324
03330 bool lock(long maxwait = -1);
03331
03335 void unlock();
03336
03342 bool locked() const;
03343
03349 bool check(long maxwait = -1);
03350
03355 bool recursive() const;
03356
03361 static int count();
03362
03367 static int locks();
03368
03374 static void wait(unsigned long maxwait);
03375
03376 private:
03377 MutexPrivate* privDataCopy() const;
03378 MutexPrivate* m_private;
03379 };
03380
03386 class YATE_API Lock
03387 {
03388 public:
03394 inline Lock(Mutex& mutex, long maxwait = -1)
03395 { m_mutex = mutex.lock(maxwait) ? &mutex : 0; }
03396
03402 inline Lock(Mutex* mutex, long maxwait = -1)
03403 { m_mutex = (mutex && mutex->lock(maxwait)) ? mutex : 0; }
03404
03408 inline ~Lock()
03409 { if (m_mutex) m_mutex->unlock(); }
03410
03415 inline Mutex* mutex() const
03416 { return m_mutex; }
03417
03421 inline void drop()
03422 { if (m_mutex) m_mutex->unlock(); m_mutex = 0; }
03423
03424 private:
03425 Mutex* m_mutex;
03426
03428 inline void* operator new(size_t);
03429
03431 inline void* operator new[](size_t);
03432
03434 inline Lock(const Lock&);
03435 };
03436
03443 class YATE_API Lock2
03444 {
03445 public:
03452 inline Lock2(Mutex* mx1, Mutex* mx2, long maxwait = -1)
03453 : m_mx1(0), m_mx2(0)
03454 { lock(mx1,mx2,maxwait); }
03455
03462 inline Lock2(Mutex& mx1, Mutex& mx2, long maxwait = -1)
03463 : m_mx1(0), m_mx2(0)
03464 { lock(&mx1,&mx2,maxwait); }
03465
03469 inline ~Lock2()
03470 { drop(); }
03471
03476 inline bool locked() const
03477 { return m_mx1 != 0; }
03478
03486 bool lock(Mutex* mx1, Mutex* mx2, long maxwait = -1);
03487
03495 inline bool lock(Mutex& mx1, Mutex& mx2, long maxwait = -1)
03496 { return lock(&mx1,&mx2); }
03497
03501 void drop();
03502
03503 private:
03504 Mutex* m_mx1;
03505 Mutex* m_mx2;
03506
03508 inline void* operator new(size_t);
03509
03511 inline void* operator new[](size_t);
03512
03514 inline Lock2(const Lock2&);
03515 };
03516
03522 class YATE_API Runnable
03523 {
03524 public:
03529 virtual void run() = 0;
03530
03534 virtual ~Runnable();
03535 };
03536
03543 class YATE_API Thread : public Runnable
03544 {
03545 friend class ThreadPrivate;
03546 friend class MutexPrivate;
03547 public:
03551 enum Priority {
03552 Lowest,
03553 Low,
03554 Normal,
03555 High,
03556 Highest
03557 };
03558
03562 virtual void cleanup();
03563
03568 bool startup();
03569
03574 bool error() const;
03575
03580 bool running() const;
03581
03586 inline int locks() const
03587 { return m_locks; }
03588
03593 inline bool locked() const
03594 { return m_locking || m_locks; }
03595
03600 const char* name() const;
03601
03606 static const char* currentName();
03607
03613 static void yield(bool exitCheck = false);
03614
03620 static void sleep(unsigned int sec, bool exitCheck = false);
03621
03627 static void msleep(unsigned long msec, bool exitCheck = false);
03628
03635 static void usleep(unsigned long usec, bool exitCheck = false);
03636
03642 static Thread* current();
03643
03648 static int count();
03649
03655 static bool check(bool exitNow = true);
03656
03660 static void exit();
03661
03666 void cancel(bool hard = false);
03667
03672 inline bool isCurrent() const
03673 { return current() == this; }
03674
03675
03682 static Priority priority(const char* name, Priority defvalue = Normal);
03683
03689 static const char* priority(Priority prio);
03690
03695 static void killall();
03696
03701 static void preExec();
03702
03703 protected:
03709 Thread(const char *name = 0, Priority prio = Normal);
03710
03716 Thread(const char *name, const char* prio);
03717
03721 virtual ~Thread();
03722
03723 private:
03724 ThreadPrivate* m_private;
03725 int m_locks;
03726 bool m_locking;
03727 };
03728
03729 class Socket;
03730
03735 class YATE_API SocketAddr : public GenObject
03736 {
03737 public:
03741 inline SocketAddr()
03742 : m_address(0), m_length(0)
03743 { }
03744
03749 inline SocketAddr(const SocketAddr& value)
03750 : m_address(0), m_length(0)
03751 { assign(value.address(),value.length()); }
03752
03757 SocketAddr(int family);
03758
03764 SocketAddr(const struct sockaddr* addr, socklen_t len = 0);
03765
03769 virtual ~SocketAddr();
03770
03775 inline SocketAddr& operator=(const SocketAddr& value)
03776 { assign(value.address(),value.length()); return *this; }
03777
03783 bool operator==(const SocketAddr& other) const;
03784
03790 inline bool operator!=(const SocketAddr& other) const
03791 { return !operator==(other); }
03792
03796 void clear();
03797
03803 bool assign(int family);
03804
03810 void assign(const struct sockaddr* addr, socklen_t len = 0);
03811
03817 bool local(const SocketAddr& remote);
03818
03823 inline bool valid() const
03824 { return m_length && m_address; }
03825
03830 inline bool null() const
03831 { return !(m_length && m_address); }
03832
03837 inline int family() const
03838 { return m_address ? m_address->sa_family : 0; }
03839
03844 inline const String& host() const
03845 { return m_host; }
03846
03851 virtual bool host(const String& name);
03852
03857 int port() const;
03858
03864 bool port(int newport);
03865
03870 inline struct sockaddr* address() const
03871 { return m_address; }
03872
03877 inline socklen_t length() const
03878 { return m_length; }
03879
03885 static bool supports(int family);
03886
03887 protected:
03891 virtual void stringify();
03892
03893 struct sockaddr* m_address;
03894 socklen_t m_length;
03895 String m_host;
03896 };
03897
03902 class YATE_API SocketFilter : public GenObject
03903 {
03904 friend class Socket;
03905 public:
03909 SocketFilter();
03910
03914 virtual ~SocketFilter();
03915
03921 virtual void* getObject(const String& name) const;
03922
03927 virtual void timerTick(const Time& when);
03928
03938 virtual bool received(void* buffer, int length, int flags, const struct sockaddr* addr, socklen_t adrlen) = 0;
03939
03944 inline Socket* socket() const
03945 { return m_socket; }
03946
03951 bool valid() const;
03952
03953 private:
03954 Socket* m_socket;
03955 };
03956
03961 class YATE_API Stream
03962 {
03963 public:
03967 virtual ~Stream();
03968
03973 inline int error() const
03974 { return m_error; }
03975
03980 virtual bool terminate() = 0;
03981
03986 virtual bool canRetry() const;
03987
03992 virtual bool valid() const = 0;
03993
03999 virtual bool setBlocking(bool block = true);
04000
04007 virtual int writeData(const void* buffer, int length) = 0;
04008
04014 int writeData(const char* str);
04015
04021 inline int writeData(const String& str)
04022 { return writeData(str.c_str(), str.length()); }
04023
04029 inline int writeData(const DataBlock& buf)
04030 { return writeData(buf.data(), buf.length()); }
04031
04038 virtual int readData(void* buffer, int length) = 0;
04039
04046 static bool allocPipe(Stream*& reader, Stream*& writer);
04047
04054 static bool allocPair(Stream*& str1, Stream*& str2);
04055
04060 static bool supportsPipes();
04061
04066 static bool supportsPairs();
04067
04068 protected:
04072 inline Stream()
04073 : m_error(0)
04074 { }
04075
04079 inline void clearError()
04080 { m_error = 0; }
04081
04082 int m_error;
04083 };
04084
04089 class YATE_API File : public Stream
04090 {
04091 public:
04095 File();
04096
04101 File(HANDLE handle);
04102
04106 virtual ~File();
04107
04118 virtual bool openPath(const char* name, bool canWrite = false, bool canRead = true,
04119 bool create = false, bool append = false, bool binary = false);
04120
04125 virtual bool terminate();
04126
04131 void attach(HANDLE handle);
04132
04137 HANDLE detach();
04138
04143 inline HANDLE handle() const
04144 { return m_handle; }
04145
04150 virtual bool canRetry() const;
04151
04156 virtual bool valid() const;
04157
04162 static HANDLE invalidHandle();
04163
04169 virtual bool setBlocking(bool block = true);
04170
04175 virtual unsigned int length();
04176
04183 virtual int writeData(const void* buffer, int length);
04184
04191 virtual int readData(void* buffer, int length);
04192
04198 static bool remove(const char* name);
04199
04206 static bool createPipe(File& reader, File& writer);
04207
04208 protected:
04209
04213 void copyError();
04214
04215 HANDLE m_handle;
04216 };
04217
04222 class YATE_API Socket : public Stream
04223 {
04224 public:
04228 enum TOS {
04229 LowDelay = IPTOS_LOWDELAY,
04230 MaxThroughput = IPTOS_THROUGHPUT,
04231 MaxReliability = IPTOS_RELIABILITY,
04232 MinCost = IPTOS_MINCOST,
04233 };
04234
04238 Socket();
04239
04244 Socket(SOCKET handle);
04245
04252 Socket(int domain, int type, int protocol = 0);
04253
04257 virtual ~Socket();
04258
04266 bool create(int domain, int type, int protocol = 0);
04267
04272 virtual bool terminate();
04273
04278 void attach(SOCKET handle);
04279
04284 SOCKET detach();
04285
04290 inline SOCKET handle() const
04291 { return m_handle; }
04292
04297 virtual bool canRetry() const;
04298
04303 virtual bool valid() const;
04304
04309 static SOCKET invalidHandle();
04310
04315 static int socketError();
04316
04325 bool setOption(int level, int name, const void* value = 0, socklen_t length = 0);
04326
04335 bool getOption(int level, int name, void* buffer, socklen_t* length);
04336
04342 bool setTOS(int tos);
04343
04349 virtual bool setBlocking(bool block = true);
04350
04358 bool setReuse(bool reuse = true, bool exclusive = false);
04359
04366 bool setLinger(int seconds = -1);
04367
04374 bool bind(struct sockaddr* addr, socklen_t addrlen);
04375
04381 inline bool bind(const SocketAddr& addr)
04382 { return bind(addr.address(), addr.length()); }
04383
04389 bool listen(unsigned int backlog = 0);
04390
04397 Socket* accept(struct sockaddr* addr = 0, socklen_t* addrlen = 0);
04398
04404 Socket* accept(SocketAddr& addr);
04405
04412 SOCKET acceptHandle(struct sockaddr* addr = 0, socklen_t* addrlen = 0);
04413
04419 static bool canSelect(SOCKET handle);
04420
04425 inline bool canSelect() const
04426 { return canSelect(handle()); }
04427
04433 Socket* peelOff(unsigned int assoc);
04434
04440 SOCKET peelOffHandle(unsigned int assoc);
04441
04448 bool connect(struct sockaddr* addr, socklen_t addrlen);
04449
04455 inline bool connect(const SocketAddr& addr)
04456 { return connect(addr.address(), addr.length()); }
04457
04464 bool shutdown(bool stopReads, bool stopWrites);
04465
04472 bool getSockName(struct sockaddr* addr, socklen_t* addrlen);
04473
04479 bool getSockName(SocketAddr& addr);
04480
04487 bool getPeerName(struct sockaddr* addr, socklen_t* addrlen);
04488
04494 bool getPeerName(SocketAddr& addr);
04495
04505 int sendTo(const void* buffer, int length, const struct sockaddr* addr, socklen_t adrlen, int flags = 0);
04506
04515 inline int sendTo(const void* buffer, int length, const SocketAddr& addr, int flags = 0)
04516 { return sendTo(buffer, length, addr.address(), addr.length(), flags); }
04517
04525 int send(const void* buffer, int length, int flags = 0);
04526
04533 virtual int writeData(const void* buffer, int length);
04534
04544 int recvFrom(void* buffer, int length, struct sockaddr* addr = 0, socklen_t* adrlen = 0, int flags = 0);
04545
04554 int recvFrom(void* buffer, int length, SocketAddr& addr, int flags = 0);
04555
04563 int recv(void* buffer, int length, int flags = 0);
04564
04571 virtual int readData(void* buffer, int length);
04572
04581 bool select(bool* readok, bool* writeok, bool* except, struct timeval* timeout = 0);
04582
04591 bool select(bool* readok, bool* writeok, bool* except, int64_t timeout);
04592
04598 bool installFilter(SocketFilter* filter);
04599
04605 void removeFilter(SocketFilter* filter, bool delobj = false);
04606
04610 void clearFilters();
04611
04618 virtual void timerTick(const Time& when);
04619
04627 static bool createPair(Socket& sock1, Socket& sock2, int domain = AF_UNIX);
04628
04629 protected:
04630
04634 void copyError();
04635
04642 bool checkError(int retcode, bool strict = false);
04643
04653 bool applyFilters(void* buffer, int length, int flags, const struct sockaddr* addr = 0, socklen_t adrlen = 0);
04654
04655 SOCKET m_handle;
04656 ObjList m_filters;
04657 };
04658
04664 class YATE_API SysUsage
04665 {
04666 public:
04670 enum Type {
04671 WallTime,
04672 UserTime,
04673 KernelTime
04674 };
04675
04679 static void init();
04680
04685 static u_int64_t startTime();
04686
04692 static u_int64_t usecRunTime(Type type = WallTime);
04693
04699 static u_int64_t msecRunTime(Type type = WallTime);
04700
04706 static u_int32_t secRunTime(Type type = WallTime);
04707
04713 static double runTime(Type type = WallTime);
04714
04715 };
04716
04717 };
04718
04719 #endif
04720
04721