Commit cad47bc5 authored by Pekka Pessi's avatar Pekka Pessi

sip_refer.c: sip_refer_d() now fixes URLs with headers but without <>.

Currently you lose if you have url parameters and headers but no <>.

darcs-hash:20061004134247-65a35-3a9768e74c809adb6d83ab3b41f195510d37ed3b.gz
parent 1a61a37d
......@@ -696,7 +696,7 @@ issize_t sip_name_addr_d(su_home_t *home,
* @RFC3261 section 20.10.
*/
if (return_params)
n = strcspn(s, " ,;?"); /* DO NOT accept ,;? in URL */
n = strcspn(s, " \t,;?"); /* DO NOT accept ,;? in URL */
else
/* P-Asserted-Identity and friends */
n = strcspn(s, " ,"); /* DO NOT accept , in URL */
......
......@@ -91,13 +91,32 @@ SIP_HEADER_CLASS(refer_to, "Refer-To", "r", r_params, single, refer_to);
issize_t sip_refer_to_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen)
{
sip_refer_to_t *r = h->sh_refer_to;
issize_t retval;
sip_refer_to_t *r = (sip_refer_to_t *)h;
retval = sip_name_addr_d(home, &s,
&r->r_display,
r->r_url,
&r->r_params,
NULL);
if (retval < 0)
return retval;
if (*s == '?' && !r->r_display && !r->r_url->url_headers) {
/* Missing <> around URL */
*s++ = '\0';
r->r_url->url_headers = s;
s += strcspn(s, " \t;,");
if (IS_LWS(*s))
*s++ = '\0', skip_lws(&s);
if (*s)
return -1;
r->r_display = s; /* Put empty string in display so that we encode using <> */
}
else if (*s)
return -1;
return sip_name_addr_d(home, &s,
&r->r_display,
r->r_url,
&r->r_params,
NULL);
return retval;
}
issize_t sip_refer_to_e(char b[], isize_t bsiz, sip_header_t const *h, int flags)
......
......@@ -1977,13 +1977,18 @@ int test_refer(void)
"Content-Length: 0\r\n"
"\r\n";
msg_t *msg;
sip_t *sip;
msg_iovec_t *iovec;
isize_t veclen, i, size;
char *back;
TEST_1(home = su_home_create());
msg = read_message(0, m); TEST_1(msg);
msg = read_message(0, m); TEST_1(msg); TEST_1(sip = sip_object(msg));
TEST_1(sip->sip_refer_to);
TEST_S(sip->sip_refer_to->r_url->url_headers,
"Replaces=7d84c014-321368da-efa90f41%40"
"10.3.3.8%3Bto-tag%3DpaNKgBB9vQe3D%3Bfrom-tag%3D93AC8D50-7CF6DAAF");
TEST(msg_prepare(msg), strlen(m));
TEST_1(veclen = msg_iovec(msg, NULL, ISIZE_MAX));
TEST_1(iovec = su_zalloc(msg_home(home), veclen * (sizeof iovec[0])));
......@@ -2034,17 +2039,21 @@ int test_refer(void)
TEST_S(r->r_params[0], "foo=bar");
TEST(r->r_params[1], NULL);
/* XXX */
/* Test bad replaces without <> */
{
char const s[] =
"<sip:2000@10.3.3.104?Replaces=7d84c014-321368da-efa90f41%4010.3.3.8"
"%3Bto-tag%3DpaNKgBB9vQe3D%3Bfrom-tag%3D93AC8D50-7CF6DAAF>";
"sip:2000@10.3.3.104?Replaces=7d84c014-321368da-efa90f41%4010.3.3.8"
"%3Bto-tag%3DpaNKgBB9vQe3D%3Bfrom-tag%3D93AC8D50-7CF6DAAF" "\r\n";
char *str;
TEST_1(r = r0 = sip_refer_to_make(home, s));
msg_fragment_clear(r->r_common);
TEST_1(str = sip_header_as_string(home, (void *)r));
TEST_S(str, s);
TEST_S(str,
"<"
"sip:2000@10.3.3.104?Replaces=7d84c014-321368da-efa90f41%4010.3.3.8"
"%3Bto-tag%3DpaNKgBB9vQe3D%3Bfrom-tag%3D93AC8D50-7CF6DAAF"
">");
}
su_home_destroy(home), su_free(NULL, home);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment