Loading codec/c++/sip_codets.cpp +61 −0 Original line number Diff line number Diff line Loading @@ -88,6 +88,67 @@ private: boost::match_results<iterator> mResults; }; void normalise_quoted_string (Charstring& cs) throw (DecodeError) { std::string result; //FIXME: how LWS shall be normalised ? const unsigned char* p = cs.GetValueBin(); const unsigned char* end = p + (cs.GetLength() / 8); for ( ; p!=end ; p++) { switch (*p) { case '\r': case '\n': case ' ': case 0x21: // plain text result += *p; break; case '\\': // escaped character p++; if ((p == end) || ((*p == '\r') | (*p == '\n'))) { // cannot be escaped // (should never happen since we checked it wit a regex before) DecodeError e (&cs); e.Msg() << "Invalid escaped sequence in quoted string: \\\\x" << std::hex << ((int) *p) << std::endl; throw e; } // valid escaped character result += *p; break; default: if ((*p >= 0x23) && (*p <= 0x7e)) { // plain text result += *p; } else if (*p > 127) { // UTF-8 character // // FIXME: how to represent UTF-8 chars ? ('%xx' escape sequences are not used here) result += *p; } else { // non allowed character // (should never happen since we checked it wit a regex before) DecodeError e (&cs); e.Msg() << "Invalid character in quoted string: \\x" << std::hex << ((int) *p) << std::endl; throw e; } } } // replace the string with the quoted string Bytestring& bs = cs; bs.SetValue (result); } //WSP: space, htab, vtab, form feed #define SIPCHARS_WSP " \t\v\f" #define SIPREG_LWS "(?:[" SIPCHARS_WSP "]*\\r\\n)?[" SIPCHARS_WSP "]+" Loading Loading
codec/c++/sip_codets.cpp +61 −0 Original line number Diff line number Diff line Loading @@ -88,6 +88,67 @@ private: boost::match_results<iterator> mResults; }; void normalise_quoted_string (Charstring& cs) throw (DecodeError) { std::string result; //FIXME: how LWS shall be normalised ? const unsigned char* p = cs.GetValueBin(); const unsigned char* end = p + (cs.GetLength() / 8); for ( ; p!=end ; p++) { switch (*p) { case '\r': case '\n': case ' ': case 0x21: // plain text result += *p; break; case '\\': // escaped character p++; if ((p == end) || ((*p == '\r') | (*p == '\n'))) { // cannot be escaped // (should never happen since we checked it wit a regex before) DecodeError e (&cs); e.Msg() << "Invalid escaped sequence in quoted string: \\\\x" << std::hex << ((int) *p) << std::endl; throw e; } // valid escaped character result += *p; break; default: if ((*p >= 0x23) && (*p <= 0x7e)) { // plain text result += *p; } else if (*p > 127) { // UTF-8 character // // FIXME: how to represent UTF-8 chars ? ('%xx' escape sequences are not used here) result += *p; } else { // non allowed character // (should never happen since we checked it wit a regex before) DecodeError e (&cs); e.Msg() << "Invalid character in quoted string: \\x" << std::hex << ((int) *p) << std::endl; throw e; } } } // replace the string with the quoted string Bytestring& bs = cs; bs.SetValue (result); } //WSP: space, htab, vtab, form feed #define SIPCHARS_WSP " \t\v\f" #define SIPREG_LWS "(?:[" SIPCHARS_WSP "]*\\r\\n)?[" SIPCHARS_WSP "]+" Loading