[sr-dev] git:coudot/escape-param DELETED: lib/kcore: make escape_param() conform to RFC3261

Camille Oudot camille.oudot at orange.com
Mon Nov 25 18:05:18 CET 2013


Module: sip-router
Branch: coudot/escape-param DELETED
Commit: d2e964190cc4768a9968af3f699226980c169e07
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=d2e964190cc4768a9968af3f699226980c169e07

Author: Camille Oudot <camille.oudot at orange.com>
Committer: Camille Oudot <camille.oudot at orange.com>
Date:   Wed Nov  6 16:28:44 2013 +0100

lib/kcore: make escape_param() conform to RFC3261

escape_param

---

 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..3733cda 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';
+        } else if (isdigit((int)*p) || ((*p >= 'A') && (*p <= 'Z')) ||
+                ((*p >= 'a') && (*p <= 'z'))) {
+
+        } 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;
             }
-            break;
-        default:
-            *at = *p;
         }
         at++;
         p++;




More information about the sr-dev mailing list