提交 3bf22f4a authored 作者: Mike Jerris's avatar Mike Jerris

FS-9809: [mod_sofia] url encode caller id number before sticking it in the from…

FS-9809: [mod_sofia] url encode caller id number before sticking it in the from header in case we have non url safe chars in the cid number in the caller profile
上级 eea2b139
......@@ -1061,6 +1061,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,
......
......@@ -858,6 +858,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;
......@@ -871,7 +872,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) {
......
......@@ -3199,6 +3199,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);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论