Commit e890d8f4 authored by Pekka Pessi's avatar Pekka Pessi

url_tag.c: url_tag_class now supports t_scan().

torture_url.c: added test for url_tag_class->tc_scan.

darcs-hash:20060825114439-65a35-a392618944c6eaad68a22393c0a777dbb5f7f2b9.gz
parent 46f7c1d8
......@@ -870,11 +870,19 @@ int test_tags(void)
url_string_t *us0 = NULL;
tagi_t *lst, *dup;
tag_value_t value;
char *s;
su_home_t home[1] = { SU_HOME_INIT(home) };
BEGIN();
TEST(t_scan(urltag_url, home, c0, &value), 0);
TEST_S(s = url_as_string(home, (url_t *)value), c0);
TEST(t_scan(urltag_url, home, c3, &value), 0);
TEST_S(s = url_as_string(home, (url_t *)value), c3);
TEST_1(url_d(u0, c0) == 0);
lst = tl_list(URLTAG_URL(u0),
......
......@@ -41,6 +41,8 @@
#include <sofia-sip/url.h>
#include <string.h>
tag_typedef_t urltag_any = NSTAG_TYPEDEF(*);
tag_typedef_t urltag_url = URLTAG_TYPEDEF(url);
......@@ -97,6 +99,38 @@ tagi_t *urltag_dup(tagi_t *dst, tagi_t const *src, void **bb)
return dst + 1;
}
#define IS_EXCLUDED(u) \
(u <= ' ' \
|| u >= '\177' \
|| (u < 64 ? (0xb400000a & (1 << (63 - u))) \
: (u < 96 ? (0x0000001e & (1 << (95 - u))) \
: /*u < 128*/ (0x8000001d & (1 << (127 - u))))))
int urltag_scan(tag_type_t tt, su_home_t *home,
char const *str,
tag_value_t *return_value)
{
size_t len;
url_t *url;
char *s;
for (len = 0; !IS_EXCLUDED(str[len]); len++)
;
url = su_alloc(home, (sizeof *url) + len + 1);
if (!url)
return -1;
s = memcpy((char *)(url + 1), str, len);
s[len] = 0;
if (url_d(url, s) < 0)
return (void)su_free(home, url), -1;
*return_value = (tag_value_t)url;
return 0;
}
tag_class_t url_tag_class[1] =
{{
sizeof(url_tag_class),
......@@ -110,5 +144,6 @@ tag_class_t url_tag_class[1] =
/* tc_snprintf */ urltag_snprintf,
/* tc_filter */ NULL,
/* tc_ref_set */ t_ptr_ref_set,
/* tc_scan */ urltag_scan,
}};
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