Loading codec/c++/sip_codets.cpp +38 −36 Original line number Diff line number Diff line #include "gen_classes.h" #include <regex.h> #include <boost/regex.hpp> namespace t3devlib { namespace gen { Loading @@ -10,7 +9,7 @@ public: Regex(const char* regex, int flags = 0) : mSource (regex), mRegex (regex, boost::regex_constants::extended) : mSource (regex), mRegex (regex, boost::regex_constants::perl) { //FIXME: remove flags ? } Loading @@ -21,7 +20,7 @@ public: int result = boost::regex_search (mStart, mStop, mResults, mRegex); #if 0 boost::match_results<iterator>::iterator it; std::cout << endl << "matching /"<< mSource <<"/" << endl; int id=0; Loading @@ -31,6 +30,7 @@ std::cout << "first " << id << " *" << &*it->first << "*" << endl; std::cout << "second " << id << " *" << &*it->second << "*" << endl; id++; } #endif return result; } Loading Loading @@ -80,7 +80,7 @@ private: }; void remove_whitespace (Buffer & buffer) { static Regex reg_ws ("[ \t\r\n\f\v]+", REG_ICASE); static Regex reg_ws ("[ \t\r\n\f\v]+"); if (reg_ws.Match (buffer)) { int nPos = buffer.GetPosition() + reg_ws.GetMatchedLength(); buffer.SetPosition (nPos); Loading @@ -106,14 +106,14 @@ void read_sp (Buffer & buffer, Variable* v) { #define SIPCHARS_USER_UNRESERVED "&=+$,;?/" #define SIPCHARS_UTF8_NONASCII "\xC0-\xFD" #define SIPCHARS_UTF8_CONTENT "\x80-\xBF" #define SIPREG_ESCAPED "(%[0-9A-F]{2})" #define SIPREG_ESCAPED "(%[0-9A-Fa-f]{2})" #define SIPREG_TOKEN "^[" SIPCHARS_ALFANUM ".!%*_+`'~\\-]+" //FIXME: WSP is not clearly defined (all whitespaces) #define SIPCHARS_WSP " " // sip version #define SIPREG_SIP_VERSION "SIP/[0-9].[0-9]" #define SIPREG_SIP_VERSION "SIP/[0-9]\\.[0-9]" // host name #define SIPREG_TOPLABEL "[" SIPCHARS_ALFA "]([" SIPCHARS_ALFANUM "\\-]*[" SIPCHARS_ALFANUM "])?" Loading Loading @@ -149,12 +149,12 @@ void read_sp (Buffer & buffer, Variable* v) { void SipUrl::PreDecodeField (int id, Buffer& buffer) throw (DecodeError) { static Regex reg_scheme ("^[" SIPCHARS_ALFA "][" SIPCHARS_ALFANUM "+.\\-]*:", REG_ICASE); static Regex reg_userinfo ("^([:" SIPCHARS_UNRESERVED SIPCHARS_USER_UNRESERVED "]|" SIPREG_ESCAPED "])+@", REG_ICASE); static Regex reg_hostport ("^[][" SIPCHARS_ALFANUM ":.\\-]+", REG_ICASE); static Regex reg_absolute_uri ("^" SIPREG_ABSOLUTE_URI, REG_ICASE); static Regex reg_urlParams ("^;" SIPREG_PPARAM_ALLOWED, REG_ICASE); static Regex reg_headers ("^[?]" SIPREG_PPARAM_ALLOWED, REG_ICASE); static Regex reg_scheme ("^[" SIPCHARS_ALFA "][" SIPCHARS_ALFANUM "+.\\-]*:"); static Regex reg_userinfo ("^([:" SIPCHARS_UNRESERVED SIPCHARS_USER_UNRESERVED "]|" SIPREG_ESCAPED "])+@"); static Regex reg_hostport ("^[][" SIPCHARS_ALFANUM ":.\\-]+"); static Regex reg_absolute_uri ("^" SIPREG_ABSOLUTE_URI); static Regex reg_urlParams ("^;" SIPREG_PPARAM_ALLOWED); static Regex reg_headers ("^[?]" SIPREG_PPARAM_ALLOWED); const char * pszScheme; switch (id) { Loading Loading @@ -224,8 +224,8 @@ void SipUrl::PreDecodeField (int id, Buffer& buffer) throw (DecodeError) void UserInfo::PreDecodeField (int id, Buffer& buffer) throw (DecodeError) { static Regex reg_username ("^([" SIPCHARS_UNRESERVED SIPCHARS_USER_UNRESERVED "]|" SIPREG_ESCAPED ")+:", REG_ICASE); static Regex reg_password ("^([&=+$," SIPCHARS_UNRESERVED "]|" SIPREG_ESCAPED ")*", REG_ICASE); static Regex reg_username ("^([" SIPCHARS_UNRESERVED SIPCHARS_USER_UNRESERVED "]|" SIPREG_ESCAPED ")+:"); static Regex reg_password ("^([&=+$," SIPCHARS_UNRESERVED "]|" SIPREG_ESCAPED ")*"); switch (id) { case id_userOrTelephoneSubscriber: if (reg_username.Match (buffer)) { Loading @@ -246,8 +246,8 @@ void UserInfo::PreDecodeField (int id, Buffer& buffer) throw (DecodeError) void HostPort::PreDecodeField (int id, Buffer& buffer) throw (DecodeError) { static Regex reg_host ("^" SIPREG_HOST, REG_ICASE); static Regex reg_absolute_uri ("^" SIPREG_ABSOLUTE_URI, REG_ICASE); static Regex reg_host ("^" SIPREG_HOST); static Regex reg_absolute_uri ("^" SIPREG_ABSOLUTE_URI); static Regex reg_colon ("^:"); // absoluteURI is mapped into SipUrl.hostPort.host and requires special handling Loading Loading @@ -314,13 +314,13 @@ void AmpersandParam_List::PreDecodeField (int id, Buffer& buffer) throw (DecodeE void GenericParam::PreDecodeField (int id, Buffer& buffer) throw (DecodeError) { static Regex reg_equals ("^=", REG_ICASE); static Regex reg_equals ("^="); static Regex reg_pparname ("^" SIPREG_PPARAM "+", REG_ICASE); static Regex reg_pparvalue ("^" SIPREG_PPARAM "*", REG_ICASE); static Regex reg_pparname ("^" SIPREG_PPARAM "+"); static Regex reg_pparvalue ("^" SIPREG_PPARAM "*"); static Regex reg_hparname ("^" SIPREG_HPARAM "+", REG_ICASE); static Regex reg_hparvalue ("^" SIPREG_HPARAM "*", REG_ICASE); static Regex reg_hparname ("^" SIPREG_HPARAM "+"); static Regex reg_hparvalue ("^" SIPREG_HPARAM "*"); Regex * preg_name; Regex * preg_value; Loading Loading @@ -370,9 +370,9 @@ void GenericParam::PreDecodeField (int id, Buffer& buffer) throw (DecodeError) void RequestLine::PreDecodeField (int id, Buffer& buffer) throw (DecodeError) { static Regex reg_method (SIPREG_TOKEN, REG_ICASE); static Regex reg_request_uri ("[^ \t\n\r]+", REG_ICASE); static Regex reg_sip_version (SIPREG_SIP_VERSION, REG_ICASE); static Regex reg_method (SIPREG_TOKEN); static Regex reg_request_uri ("[^ \t\n\r]+"); static Regex reg_sip_version (SIPREG_SIP_VERSION); switch (id) { case id_method: reg_method.AssertMatch (buffer, this); Loading Loading @@ -447,7 +447,7 @@ void Method::Encode (Buffer& buffer) throw (EncodeError) void Method::Decode (Buffer& buffer) throw (DecodeError) { static Regex reg_method (SIPREG_TOKEN, REG_ICASE); static Regex reg_method (SIPREG_TOKEN); reg_method.AssertMatch (buffer, this); Loading @@ -470,9 +470,9 @@ void Method::Decode (Buffer& buffer) throw (DecodeError) void StatusLine::PreDecodeField (int id, Buffer& buffer) throw (DecodeError) { static Regex reg_sip_version (SIPREG_SIP_VERSION, REG_ICASE); static Regex reg_status_code ("^[0-9]{3}", REG_ICASE); static Regex reg_phrase ("([" SIPCHARS_RESERVED SIPCHARS_UNRESERVED SIPCHARS_UTF8_NONASCII SIPCHARS_UTF8_CONTENT " \t]|" SIPREG_ESCAPED ")*", REG_ICASE); static Regex reg_sip_version (SIPREG_SIP_VERSION); static Regex reg_status_code ("^[0-9]{3}"); static Regex reg_phrase ("([" SIPCHARS_RESERVED SIPCHARS_UNRESERVED SIPCHARS_UTF8_NONASCII SIPCHARS_UTF8_CONTENT " \t]|" SIPREG_ESCAPED ")*"); switch (id) { case id_sipVersion: Loading Loading @@ -584,7 +584,7 @@ SipHeaderMap SipHeaderMap::msInstance; void MessageHeader::PreDecodeField (Buffer& buffer) throw (DecodeError) { static Regex reg_header_name ("^([A-Za-z\\-]+)" SIPREG_HCOLON, REG_ICASE); static Regex reg_header_name ("^([A-Za-z\\-]+)" SIPREG_HCOLON); if (reg_header_name.Match (buffer)) { Loading @@ -596,8 +596,10 @@ void MessageHeader::PreDecodeField (Buffer& buffer) throw (DecodeError) void MessageHeader::PostDecodeField (int id, Buffer& buffer) throw (DecodeError) { //TODO: match CRLF throw DecodeError (this, __PRETTY_FUNCTION__); static Regex reg_crlf ("^\r\n"); reg_crlf.AssertMatch (buffer, this); buffer.SetPosition(buffer.GetPosition() + reg_crlf.GetMatchedLength()); } Loading Loading @@ -688,7 +690,7 @@ void FieldName::Encode (Buffer& buffer) throw (EncodeError) void FieldName::Decode (Buffer& buffer) throw (DecodeError) { static Regex reg_header_name ("^([A-Z\\-]+)" SIPREG_HCOLON, REG_ICASE); static Regex reg_header_name ("^([A-Za-z\\-]+)" SIPREG_HCOLON); reg_header_name.AssertMatch (buffer, this); SetValueString (SipHeaderMap::GetByName(reg_header_name.GetMatchedString (1)).mIdFieldName.c_str()); Loading @@ -698,7 +700,7 @@ void FieldName::Decode (Buffer& buffer) throw (DecodeError) void Addr_Union::PreDecode (Buffer& buffer) throw (DecodeError) { static Regex reg_scheme ("^[A-Z][A-Z0-9]*:", REG_ICASE); static Regex reg_scheme ("^[A-Za-z][A-Za-z0-9]*:"); SetHypChosenId ( reg_scheme.Match (buffer) Loading Loading
codec/c++/sip_codets.cpp +38 −36 Original line number Diff line number Diff line #include "gen_classes.h" #include <regex.h> #include <boost/regex.hpp> namespace t3devlib { namespace gen { Loading @@ -10,7 +9,7 @@ public: Regex(const char* regex, int flags = 0) : mSource (regex), mRegex (regex, boost::regex_constants::extended) : mSource (regex), mRegex (regex, boost::regex_constants::perl) { //FIXME: remove flags ? } Loading @@ -21,7 +20,7 @@ public: int result = boost::regex_search (mStart, mStop, mResults, mRegex); #if 0 boost::match_results<iterator>::iterator it; std::cout << endl << "matching /"<< mSource <<"/" << endl; int id=0; Loading @@ -31,6 +30,7 @@ std::cout << "first " << id << " *" << &*it->first << "*" << endl; std::cout << "second " << id << " *" << &*it->second << "*" << endl; id++; } #endif return result; } Loading Loading @@ -80,7 +80,7 @@ private: }; void remove_whitespace (Buffer & buffer) { static Regex reg_ws ("[ \t\r\n\f\v]+", REG_ICASE); static Regex reg_ws ("[ \t\r\n\f\v]+"); if (reg_ws.Match (buffer)) { int nPos = buffer.GetPosition() + reg_ws.GetMatchedLength(); buffer.SetPosition (nPos); Loading @@ -106,14 +106,14 @@ void read_sp (Buffer & buffer, Variable* v) { #define SIPCHARS_USER_UNRESERVED "&=+$,;?/" #define SIPCHARS_UTF8_NONASCII "\xC0-\xFD" #define SIPCHARS_UTF8_CONTENT "\x80-\xBF" #define SIPREG_ESCAPED "(%[0-9A-F]{2})" #define SIPREG_ESCAPED "(%[0-9A-Fa-f]{2})" #define SIPREG_TOKEN "^[" SIPCHARS_ALFANUM ".!%*_+`'~\\-]+" //FIXME: WSP is not clearly defined (all whitespaces) #define SIPCHARS_WSP " " // sip version #define SIPREG_SIP_VERSION "SIP/[0-9].[0-9]" #define SIPREG_SIP_VERSION "SIP/[0-9]\\.[0-9]" // host name #define SIPREG_TOPLABEL "[" SIPCHARS_ALFA "]([" SIPCHARS_ALFANUM "\\-]*[" SIPCHARS_ALFANUM "])?" Loading Loading @@ -149,12 +149,12 @@ void read_sp (Buffer & buffer, Variable* v) { void SipUrl::PreDecodeField (int id, Buffer& buffer) throw (DecodeError) { static Regex reg_scheme ("^[" SIPCHARS_ALFA "][" SIPCHARS_ALFANUM "+.\\-]*:", REG_ICASE); static Regex reg_userinfo ("^([:" SIPCHARS_UNRESERVED SIPCHARS_USER_UNRESERVED "]|" SIPREG_ESCAPED "])+@", REG_ICASE); static Regex reg_hostport ("^[][" SIPCHARS_ALFANUM ":.\\-]+", REG_ICASE); static Regex reg_absolute_uri ("^" SIPREG_ABSOLUTE_URI, REG_ICASE); static Regex reg_urlParams ("^;" SIPREG_PPARAM_ALLOWED, REG_ICASE); static Regex reg_headers ("^[?]" SIPREG_PPARAM_ALLOWED, REG_ICASE); static Regex reg_scheme ("^[" SIPCHARS_ALFA "][" SIPCHARS_ALFANUM "+.\\-]*:"); static Regex reg_userinfo ("^([:" SIPCHARS_UNRESERVED SIPCHARS_USER_UNRESERVED "]|" SIPREG_ESCAPED "])+@"); static Regex reg_hostport ("^[][" SIPCHARS_ALFANUM ":.\\-]+"); static Regex reg_absolute_uri ("^" SIPREG_ABSOLUTE_URI); static Regex reg_urlParams ("^;" SIPREG_PPARAM_ALLOWED); static Regex reg_headers ("^[?]" SIPREG_PPARAM_ALLOWED); const char * pszScheme; switch (id) { Loading Loading @@ -224,8 +224,8 @@ void SipUrl::PreDecodeField (int id, Buffer& buffer) throw (DecodeError) void UserInfo::PreDecodeField (int id, Buffer& buffer) throw (DecodeError) { static Regex reg_username ("^([" SIPCHARS_UNRESERVED SIPCHARS_USER_UNRESERVED "]|" SIPREG_ESCAPED ")+:", REG_ICASE); static Regex reg_password ("^([&=+$," SIPCHARS_UNRESERVED "]|" SIPREG_ESCAPED ")*", REG_ICASE); static Regex reg_username ("^([" SIPCHARS_UNRESERVED SIPCHARS_USER_UNRESERVED "]|" SIPREG_ESCAPED ")+:"); static Regex reg_password ("^([&=+$," SIPCHARS_UNRESERVED "]|" SIPREG_ESCAPED ")*"); switch (id) { case id_userOrTelephoneSubscriber: if (reg_username.Match (buffer)) { Loading @@ -246,8 +246,8 @@ void UserInfo::PreDecodeField (int id, Buffer& buffer) throw (DecodeError) void HostPort::PreDecodeField (int id, Buffer& buffer) throw (DecodeError) { static Regex reg_host ("^" SIPREG_HOST, REG_ICASE); static Regex reg_absolute_uri ("^" SIPREG_ABSOLUTE_URI, REG_ICASE); static Regex reg_host ("^" SIPREG_HOST); static Regex reg_absolute_uri ("^" SIPREG_ABSOLUTE_URI); static Regex reg_colon ("^:"); // absoluteURI is mapped into SipUrl.hostPort.host and requires special handling Loading Loading @@ -314,13 +314,13 @@ void AmpersandParam_List::PreDecodeField (int id, Buffer& buffer) throw (DecodeE void GenericParam::PreDecodeField (int id, Buffer& buffer) throw (DecodeError) { static Regex reg_equals ("^=", REG_ICASE); static Regex reg_equals ("^="); static Regex reg_pparname ("^" SIPREG_PPARAM "+", REG_ICASE); static Regex reg_pparvalue ("^" SIPREG_PPARAM "*", REG_ICASE); static Regex reg_pparname ("^" SIPREG_PPARAM "+"); static Regex reg_pparvalue ("^" SIPREG_PPARAM "*"); static Regex reg_hparname ("^" SIPREG_HPARAM "+", REG_ICASE); static Regex reg_hparvalue ("^" SIPREG_HPARAM "*", REG_ICASE); static Regex reg_hparname ("^" SIPREG_HPARAM "+"); static Regex reg_hparvalue ("^" SIPREG_HPARAM "*"); Regex * preg_name; Regex * preg_value; Loading Loading @@ -370,9 +370,9 @@ void GenericParam::PreDecodeField (int id, Buffer& buffer) throw (DecodeError) void RequestLine::PreDecodeField (int id, Buffer& buffer) throw (DecodeError) { static Regex reg_method (SIPREG_TOKEN, REG_ICASE); static Regex reg_request_uri ("[^ \t\n\r]+", REG_ICASE); static Regex reg_sip_version (SIPREG_SIP_VERSION, REG_ICASE); static Regex reg_method (SIPREG_TOKEN); static Regex reg_request_uri ("[^ \t\n\r]+"); static Regex reg_sip_version (SIPREG_SIP_VERSION); switch (id) { case id_method: reg_method.AssertMatch (buffer, this); Loading Loading @@ -447,7 +447,7 @@ void Method::Encode (Buffer& buffer) throw (EncodeError) void Method::Decode (Buffer& buffer) throw (DecodeError) { static Regex reg_method (SIPREG_TOKEN, REG_ICASE); static Regex reg_method (SIPREG_TOKEN); reg_method.AssertMatch (buffer, this); Loading @@ -470,9 +470,9 @@ void Method::Decode (Buffer& buffer) throw (DecodeError) void StatusLine::PreDecodeField (int id, Buffer& buffer) throw (DecodeError) { static Regex reg_sip_version (SIPREG_SIP_VERSION, REG_ICASE); static Regex reg_status_code ("^[0-9]{3}", REG_ICASE); static Regex reg_phrase ("([" SIPCHARS_RESERVED SIPCHARS_UNRESERVED SIPCHARS_UTF8_NONASCII SIPCHARS_UTF8_CONTENT " \t]|" SIPREG_ESCAPED ")*", REG_ICASE); static Regex reg_sip_version (SIPREG_SIP_VERSION); static Regex reg_status_code ("^[0-9]{3}"); static Regex reg_phrase ("([" SIPCHARS_RESERVED SIPCHARS_UNRESERVED SIPCHARS_UTF8_NONASCII SIPCHARS_UTF8_CONTENT " \t]|" SIPREG_ESCAPED ")*"); switch (id) { case id_sipVersion: Loading Loading @@ -584,7 +584,7 @@ SipHeaderMap SipHeaderMap::msInstance; void MessageHeader::PreDecodeField (Buffer& buffer) throw (DecodeError) { static Regex reg_header_name ("^([A-Za-z\\-]+)" SIPREG_HCOLON, REG_ICASE); static Regex reg_header_name ("^([A-Za-z\\-]+)" SIPREG_HCOLON); if (reg_header_name.Match (buffer)) { Loading @@ -596,8 +596,10 @@ void MessageHeader::PreDecodeField (Buffer& buffer) throw (DecodeError) void MessageHeader::PostDecodeField (int id, Buffer& buffer) throw (DecodeError) { //TODO: match CRLF throw DecodeError (this, __PRETTY_FUNCTION__); static Regex reg_crlf ("^\r\n"); reg_crlf.AssertMatch (buffer, this); buffer.SetPosition(buffer.GetPosition() + reg_crlf.GetMatchedLength()); } Loading Loading @@ -688,7 +690,7 @@ void FieldName::Encode (Buffer& buffer) throw (EncodeError) void FieldName::Decode (Buffer& buffer) throw (DecodeError) { static Regex reg_header_name ("^([A-Z\\-]+)" SIPREG_HCOLON, REG_ICASE); static Regex reg_header_name ("^([A-Za-z\\-]+)" SIPREG_HCOLON); reg_header_name.AssertMatch (buffer, this); SetValueString (SipHeaderMap::GetByName(reg_header_name.GetMatchedString (1)).mIdFieldName.c_str()); Loading @@ -698,7 +700,7 @@ void FieldName::Decode (Buffer& buffer) throw (DecodeError) void Addr_Union::PreDecode (Buffer& buffer) throw (DecodeError) { static Regex reg_scheme ("^[A-Z][A-Z0-9]*:", REG_ICASE); static Regex reg_scheme ("^[A-Za-z][A-Za-z0-9]*:"); SetHypChosenId ( reg_scheme.Match (buffer) Loading