Module: sip-router
Branch: master
Commit: 504973f1dabdc60212cba2bacaede9fe8a36e952
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=504973f…
Author: Camille Oudot <camille.oudot(a)orange.com>
Committer: Camille Oudot <camille.oudot(a)orange.com>
Date: Wed Nov 6 16:28:44 2013 +0100
lib/kcore: make escape_param() conform to RFC3261
---
lib/kcore/strcommon.c | 72 ++++++++++++++++++++++++++++++------------------
1 files changed, 45 insertions(+), 27 deletions(-)
diff --git a/lib/kcore/strcommon.c b/lib/kcore/strcommon.c
index 1c4e9a2..fa01a03 100644
--- a/lib/kcore/strcommon.c
+++ b/lib/kcore/strcommon.c
@@ -312,7 +312,11 @@ int unescape_param(str *sin, str *sout)
/*! \brief
* Escape all printable characters that are not valid in
- * a param part of request uri: = | ; | , | | " | ? | &
+ * a param part of request uri
+ * no_need_to_escape = unreserved | param-unreserved
+ * unreserved = alphanum | mark
+ * mark = - | _ | . | ! | ~ | * | ' | ( | )
+ * param-unreserved = [ | ] | / | : | & | + | $
*/
int escape_param(str *sin, str *sout)
{
@@ -329,33 +333,47 @@ int escape_param(str *sin, str *sout)
if (*p < 32 || *p > 126) {
LM_ERR("invalid escaped character <%u>\n", (unsigned
int)*p);
return -1;
- }
- switch (*p) {
- case ' ':
- case '?':
- case '&':
- case '=':
- case ',':
- case ';':
- case '"':
- case '+':
- *at++ = '%';
- x = (*p) >> 4;
- if (x < 10)
- {
- *at++ = x + '0';
- } else {
- *at++ = x - 10 + 'a';
- }
- x = (*p) & 0x0f;
- if (x < 10) {
- *at = x + '0';
- } else {
- *at = x - 10 + 'a';
- }
- break;
- default:
+ } else if (isdigit((int)*p) || ((*p >= 'A') && (*p <=
'Z')) ||
+ ((*p >= 'a') && (*p <= 'z'))) {
*at = *p;
+ } else {
+ switch (*p) {
+ case '-':
+ case '_':
+ case '.':
+ case '!':
+ case '~':
+ case '*':
+ case '\'':
+ case '(':
+ case ')':
+ case '[':
+ case ']':
+ case '/':
+ case ':':
+ case '&':
+ case '+':
+ case '$':
+ *at = *p;
+ break;
+ default:
+
+ *at++ = '%';
+ x = (*p) >> 4;
+ if (x < 10)
+ {
+ *at++ = x + '0';
+ } else {
+ *at++ = x - 10 + 'a';
+ }
+ x = (*p) & 0x0f;
+ if (x < 10) {
+ *at = x + '0';
+ } else {
+ *at = x - 10 + 'a';
+ }
+ break;
+ }
}
at++;
p++;