]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-9809: [mod_sofia] url encode caller id number before sticking it in the from heade...
authorMike Jerris <mike@jerris.com>
Fri, 6 Jan 2017 22:16:16 +0000 (16:16 -0600)
committerMike Jerris <mike@jerris.com>
Fri, 6 Jan 2017 22:16:16 +0000 (16:16 -0600)
src/include/switch_utils.h
src/mod/endpoints/mod_sofia/sofia_glue.c
src/switch_utils.c

index 2692cdf4d31a7a1278b9ea23cfe99c233ead9c37..f54d1d1d2b054e14096ea84df8a80acf6c61becb 100644 (file)
@@ -1107,6 +1107,13 @@ static inline int switch_needs_url_encode(const char *s)
 SWITCH_DECLARE(char *) switch_url_encode_opt(const char *url, char *buf, size_t len, switch_bool_t double_encode);
 SWITCH_DECLARE(char *) switch_url_encode(const char *url, char *buf, size_t len);
 SWITCH_DECLARE(char *) switch_url_decode(char *s);
+
+SWITCH_DECLARE(char *) switch_core_url_encode_opt(switch_memory_pool_t *pool, const char *url, switch_bool_t double_encode);
+SWITCH_DECLARE(char *) switch_core_url_encode(switch_memory_pool_t *pool, const char *url);
+SWITCH_DECLARE(char *) switch_core_session_url_encode_opt(switch_core_session_t *session, const char *url, switch_bool_t double_encode);
+SWITCH_DECLARE(char *) switch_core_session_url_encode(switch_core_session_t *session, const char *url);
+
+
 SWITCH_DECLARE(switch_bool_t) switch_simple_email(const char *to,
                                                                                                  const char *from,
                                                                                                  const char *headers,
index 7bc26b94e7f2b409799fb3a863a49c753f122120..12dd673d29a965ffebd298b7f0df80a95c0842fe 100644 (file)
@@ -860,6 +860,7 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session)
                if (!tech_pvt->from_str) {
                        const char *sipip;
                        const char *format;
+                       char *use_cid_num = switch_core_session_url_encode(tech_pvt->session, cid_num);
 
                        sipip = tech_pvt->profile->sipip;
 
@@ -873,7 +874,7 @@ switch_status_t sofia_glue_do_invite(switch_core_session_t *session)
 
                        format = strchr(sipip, ':') ? "\"%s\" <sip:%s%s[%s]>" : "\"%s\" <sip:%s%s%s>";
 
-                       tech_pvt->from_str = switch_core_session_sprintf(tech_pvt->session, format, cid_name, cid_num, !zstr(cid_num) ? "@" : "", sipip);
+                       tech_pvt->from_str = switch_core_session_sprintf(tech_pvt->session, format, cid_name, use_cid_num, !zstr(cid_num) ? "@" : "", sipip);
                }
 
                if (from_var) {
index 5c47974f1b5576682b279b2092d81c01842328de..6d0e0a5e912d8553069e077be366c641b9532e5d 100644 (file)
@@ -3228,6 +3228,58 @@ SWITCH_DECLARE(int) switch_socket_waitfor(switch_pollfd_t *poll, int ms)
        return nsds;
 }
 
+SWITCH_DECLARE(char *) switch_core_session_url_encode(switch_core_session_t *session, const char *url)
+{
+       return switch_core_url_encode_opt(switch_core_session_get_pool(session), url, SWITCH_FALSE);
+}
+
+SWITCH_DECLARE(char *) switch_core_session_url_encode_opt(switch_core_session_t *session, const char *url, switch_bool_t double_encode)
+{
+       return switch_core_url_encode_opt(switch_core_session_get_pool(session), url, double_encode);
+}
+
+SWITCH_DECLARE(char *) switch_core_url_encode(switch_memory_pool_t *pool, const char *url)
+{
+       return switch_core_url_encode_opt(pool, url, SWITCH_FALSE);
+}
+
+SWITCH_DECLARE(char *) switch_core_url_encode_opt(switch_memory_pool_t *pool, const char *url, switch_bool_t double_encode)
+{
+       const char hex[] = "0123456789ABCDEF";
+       switch_size_t len = 0;
+       switch_size_t slen = 0;
+       const char *p, *e = end_of_p(url);
+
+       if (!url) return NULL;
+       if (!pool) return NULL;
+
+       for (p = url; *p; p++) {
+               int ok = 0;
+
+               len++;
+               slen++;
+
+               if (!double_encode && *p == '%' && e-p > 1) {
+                       if (strchr(hex, *(p+1)) && strchr(hex, *(p+2))) {
+                               ok = 1;
+                       }
+               }
+
+               if (!ok && (*p < ' ' || *p > '~' || strchr(SWITCH_URL_UNSAFE, *p))) {
+                       len += 2;
+               }
+       }
+
+       slen++;
+       len++; /* NULL Terminatior */
+
+       if (slen == len) {
+               return switch_core_strdup(pool, url);
+       } else {
+               return switch_url_encode_opt(url, switch_core_alloc(pool, sizeof(char) * len), len, double_encode);
+       }
+}
+
 SWITCH_DECLARE(char *) switch_url_encode_opt(const char *url, char *buf, size_t len, switch_bool_t double_encode)
 {
        const char *p, *e = end_of_p(url);