Module: sip-router Branch: master Commit: 2003bc3b1cc73caa36e9b4892d8d25f810d6c458 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=2003bc3b...
Author: Juha Heinanen jh@tutpro.com Committer: Juha Heinanen jh@tutpro.com Date: Thu Apr 11 08:11:35 2013 +0300
modules/registrar: unescape received value using kcore function
- Now that unescaped received value goes into separate buffer, it is possible to use kcore unescape function.
---
modules/registrar/path.c | 111 ++-------------------------------------------- 1 files changed, 4 insertions(+), 107 deletions(-)
diff --git a/modules/registrar/path.c b/modules/registrar/path.c index ef976e0..cefd59a 100644 --- a/modules/registrar/path.c +++ b/modules/registrar/path.c @@ -32,114 +32,11 @@ #include "../../data_lump.h" #include "../../parser/parse_rr.h" #include "../../parser/parse_uri.h" +#include "../../lib/kcore/strcommon.h" #include "path.h" #include "reg_mod.h"
-/*! \brief Unscape all printable ASCII characters */ -int unescape_string(str *sin, str *sout) -{ - char *at, *p, c; - - if(sin==NULL || sout==NULL || sin->s==NULL || sout->s==NULL - || sin->len<0 || sout->len < sin->len+1) - return -1; - - at = sout->s; - p = sin->s; - while(p < sin->s+sin->len) - { - if (*p == '%') - { - p++; - switch (*p) - { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - c = (*p - '0') << 4; - break; - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - c = (*p - 'a' + 10) << 4; - break; - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - c = (*p - 'A' + 10) << 4; - break; - default: - LM_ERR("invalid hex digit <%u>\n", (unsigned int)*p); - return -1; - } - p++; - switch (*p) - { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - c = c + (*p - '0'); - break; - case 'a': - case 'b': - case 'c': - case 'd': - case 'e': - case 'f': - c = c + (*p - 'a' + 10); - break; - case 'A': - case 'B': - case 'C': - case 'D': - case 'E': - case 'F': - c = c + (*p - 'A' + 10); - break; - default: - LM_ERR("invalid hex digit <%u>\n", (unsigned int)*p); - return -1; - } - if ((c < 32) || (c > 126)) - { - LM_ERR("invalid escaped character <%u>\n", (unsigned int)c); - return -1; - } - *at++ = c; - } else { - *at++ = *p; - } - p++; - } - - *at = 0; - sout->len = at - sout->s; - - LM_DBG("unescaped string is <%s>\n", sout->s); - return 0; -} - /*! \brief * Combines all Path HF bodies into one string. */ @@ -203,9 +100,9 @@ int build_path_vector(struct sip_msg *_m, str *path, str *received) if (hooks.contact.received) { uri_str.s = uri_buf; uri_str.len = MAX_URI_SIZE; - if (unescape_string(&(hooks.contact.received->body), &uri_str) < 0) { - LM_ERR("unescaping received failed\n"); - goto error; + if (unescape_user(&(hooks.contact.received->body), &uri_str) < 0) { + LM_ERR("unescaping received failed\n"); + goto error; } *received = uri_str; LM_DBG("received is <%.*s>\n", received->len, received->s);