mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-26 22:30:28 +00:00
Adds ast_escape_encoded utility to properly handle escaping of quoted field before uri.
This commit backports a feature in trunk affecting initreqprep so that display name won't be encoded improperly. Also includes unit tests for the ast_escape_quoted function. This patch gives 1.8 a much improved outlook in countries which don't use standard ASCII characters. (closes issue ASTERISK-16949) Reported by: Örn Arnarson Review: https://reviewboard.asterisk.org/r/1235/ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@322585 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
31
main/utils.c
31
main/utils.c
@@ -415,6 +415,37 @@ char *ast_uri_encode(const char *string, char *outbuf, int buflen, int do_specia
|
||||
return outbuf;
|
||||
}
|
||||
|
||||
/*! \brief escapes characters specified for quoted portions of sip messages */
|
||||
char *ast_escape_quoted(const char *string, char *outbuf, int buflen)
|
||||
{
|
||||
const char *ptr = string;
|
||||
char *out = outbuf;
|
||||
char *allow = "\t\v !"; /* allow LWS (minus \r and \n) and "!" */
|
||||
|
||||
while (*ptr && out - outbuf < buflen - 1) {
|
||||
if (!(strchr(allow, *ptr))
|
||||
&& !(*ptr >= '#' && *ptr <= '[') /* %x23 - %x5b */
|
||||
&& !(*ptr >= ']' && *ptr <= '~') /* %x5d - %x7e */
|
||||
&& !((unsigned char) *ptr > 0x7f)) { /* UTF8-nonascii */
|
||||
|
||||
if (out - outbuf >= buflen - 2) {
|
||||
break;
|
||||
}
|
||||
out += sprintf(out, "\\%c", (unsigned char) *ptr);
|
||||
} else {
|
||||
*out = *ptr;
|
||||
out++;
|
||||
}
|
||||
ptr++;
|
||||
}
|
||||
|
||||
if (buflen) {
|
||||
*out = '\0';
|
||||
}
|
||||
|
||||
return outbuf;
|
||||
}
|
||||
|
||||
/*! \brief ast_uri_decode: Decode SIP URI, URN, URL (overwrite the string) */
|
||||
void ast_uri_decode(char *s)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user