Added method for URI escaping an entire list of characters.

Escape status detail characters that may disturb status parsing.


git-svn-id: http://voip.null.ro/svn/yate@6184 acf43c95-373e-0410-b603-e72c3f656dc1
This commit is contained in:
paulc 2017-02-16 11:24:25 +00:00
parent 8393e4a963
commit afbeb65da9
6 changed files with 35 additions and 7 deletions

View File

@ -1612,7 +1612,9 @@ void Driver::statusDetail(String& str)
ObjList* l = m_chans.skipNull();
for (; l; l=l->skipNext()) {
Channel* c = static_cast<Channel*>(l->get());
str.append(c->id(),",") << "=" << c->status() << "|" << c->address() << "|" << c->getPeerId();
str.append(c->id(),",") << "=" << c->status()
<< "|" << String::uriEscape(c->address(),",;|"," +?&")
<< "|" << c->getPeerId();
}
}

View File

@ -1451,8 +1451,24 @@ String String::uriEscape(const char* str, char extraEsc, const char* noEsc)
return s;
char c;
while ((c=*str++)) {
if ((unsigned char)c <= ' ' || c == '%' || c == extraEsc ||
((c == '+' || c == '?' || c == '&') && !(noEsc && ::strchr(noEsc,c))))
if ((unsigned char)c < ' ' || c == '%' || c == extraEsc ||
((c == ' ' || c == '+' || c == '?' || c == '&') && !(noEsc && ::strchr(noEsc,c))))
s << '%' << hexEncode(c >> 4) << hexEncode(c);
else
s += c;
}
return s;
}
String String::uriEscape(const char* str, const char* extraEsc, const char* noEsc)
{
String s;
if (TelEngine::null(str))
return s;
char c;
while ((c=*str++)) {
if ((unsigned char)c < ' ' || c == '%' || (extraEsc && ::strchr(extraEsc,c)) ||
((c == ' ' || c == '+' || c == '?' || c == '&') && !(noEsc && ::strchr(noEsc,c))))
s << '%' << hexEncode(c >> 4) << hexEncode(c);
else
s += c;

View File

@ -415,8 +415,9 @@ void CdrBuilder::emit(const char *operation)
String CdrBuilder::getStatus() const
{
String s(m_status);
s << "|" << getValue(YSTRING("caller")) << "|" << getValue(YSTRING("called")) <<
"|" << getValue(YSTRING("billid"));
s << "|" << String::uriEscape(getValue(YSTRING("caller")),",;|"," +?&")
<< "|" << String::uriEscape(getValue(YSTRING("called")),",;|"," +?&")
<< "|" << String::uriEscape(getValue(YSTRING("billid")),",;|"," +?&");
unsigned int sec = 0;
if (m_start)
sec = (int)((Time::now() - m_start + 500000) / 1000000);

View File

@ -234,7 +234,7 @@ bool StatusHandler::received(Message &msg)
first = false;
else
msg.retValue() << ",";
msg.retValue() << *acct << "=" << user;
msg.retValue() << *acct << "=" << String::uriEscape(user,",;|"," +?&");
}
}
msg.retValue() << "\r\n";

View File

@ -42,7 +42,7 @@ public:
virtual bool msgOperation(Message& msg, const String& operation);
void chanReplaced(const String& initial, const String& final);
inline void statusDetail(String& str) const
{ str.append(id() + "=" + m_state + "|" + m_tones,","); }
{ str.append(id() + "=" + m_state + "|" + String::uriEscape(m_tones,",;|"," +?&"),","); }
protected:
inline const String& state() const
{ return m_state; }

View File

@ -2739,6 +2739,15 @@ public:
*/
static String uriEscape(const char* str, char extraEsc = 0, const char* noEsc = 0);
/**
* Create an escaped string suitable for use in URIs
* @param str String to convert to escaped format
* @param extraEsc Pointer to string of characters to escape other than the defaults
* @param noEsc Optional pointer to string of characters that shouldn't be escaped
* @return The string with special characters escaped
*/
static String uriEscape(const char* str, const char* extraEsc, const char* noEsc = 0);
/**
* Create an escaped string suitable for use in URI
* @param extraEsc Character to escape other than the default ones