Commit 6c4080c2 authored by Pekka Pessi's avatar Pekka Pessi

Added sip_add_tagis() and SIPTAG_END().

SIPTAG_END() allows grouping tags into blocks.

darcs-hash:20051128225013-65a35-cd5fbad6fa927867bcb8a4b92be3030a9e2f4a66.gz
parent f0bd4e66
......@@ -121,6 +121,9 @@ int sip_add_headers(msg_t *msg, sip_t *sip,
int sip_add_tl(msg_t *msg, sip_t *sip,
tag_type_t tag, tag_value_t value, ...);
/** Add duplicates of headers from taglist to the SIP message. */
int sip_add_tagis(msg_t *msg, sip_t *sip, tagi_t const **inout_list);
/** Add a header to the SIP message. */
int sip_add_make(msg_t *msg, sip_t *sip,
msg_hclass_t *hc, char const *s);
......
......@@ -57,13 +57,14 @@
#include <su_tagarg.h>
tag_typedef_t siptag_sip = SIPMSGTAG_TYPEDEF(sip);
tag_typedef_t siptag_header = {{ "sip", "header", siphdrtag_class, 0 }};
tag_typedef_t siptag_header_str = STRTAG_TYPEDEF(header_str);
tag_typedef_t siptag_end = TAG_TYPEDEF(tag_end, end);
/**@ingroup sip_#xxxxxx#
* Tag for #xxxxxxx_xxxxxxx# object.
......
......@@ -76,6 +76,10 @@ SIP_DLL extern tag_class_t sipmsgtag_class[1];
SIP_DLL extern tag_type_t sip_tag_list[], sip_tag_str_list[];
/** End of SIP headers */
#define SIPTAG_END() siptag_end, (tag_value_t)0
SIP_DLL extern tag_typedef_t siptag_end;
/**Tag list item for #sip_t object.
*
* The SIPTAG_SIP() macro is used to include a tag item for a #sip_t struct
......
......@@ -150,16 +150,42 @@ tagi_t *siptag_filter(tagi_t *dst,
}
/** Add duplicates of headers from taglist to the SIP message. */
int sip_add_tl(msg_t *msg, sip_t *sip,
tag_type_t tag, tag_value_t value, ...)
{
tagi_t const *t;
ta_list ta;
int sip_add_tl(msg_t *msg, sip_t *sip,
tag_type_t tag, tag_value_t value, ...)
{
tagi_t const *t;
ta_list ta;
int retval;
ta_start(ta, tag, value);
t = ta_args(ta);
retval = sip_add_tagis(msg, sip, &t);
ta_end(ta);
return retval;
}
/** Add duplicates of headers from taglist to the SIP message. */
int sip_add_tagis(msg_t *msg, sip_t *sip, tagi_t const **inout_list)
{
tagi_t const *t;
tag_type_t tag;
tag_value_t value;
ta_start(ta, tag, value);
if (!msg || !inout_list)
return -1;
for (t = ta_args(ta); t; t = tl_next(t)) {
if (!(tag = t->t_tag) || !(value = t->t_value))
for (t = *inout_list; t; t = tl_next(t)) {
tag = t->t_tag, value = t->t_value;
if (tag == NULL || tag == siptag_end) {
t = tl_next(t);
break;
}
if (!value)
continue;
if (SIPTAG_P(tag)) {
......@@ -183,15 +209,15 @@ int sip_add_tl(msg_t *msg, sip_t *sip,
msg_hclass_t *hc = (msg_hclass_t *)tag->tt_magic;
char const *s = (char const *)value;
if (s && msg_header_add_make(msg, (msg_pub_t *)sip, hc, s) < 0)
break;
return -1;
}
else if (tag == siptag_header_str) {
if (msg_header_add_str(msg, (msg_pub_t *)sip, (char const *)value) < 0)
break;
return -1;
}
}
ta_end(ta);
*inout_list = t;
return t ? -1 : 0;
return 0;
}
......@@ -1428,6 +1428,7 @@ static int sip_header_test(void)
su_home_t *home;
void const *x;
sip_via_t *v, *v0;
tagi_t const *tl, *tl0;
BEGIN();
......@@ -1547,6 +1548,8 @@ static int sip_header_test(void)
"\n"
"test payload\n"),
SIPTAG_TIMESTAMP(sip->sip_timestamp),
SIPTAG_END(),
SIPTAG_REFER_TO_STR("<sip:foo@bar>"),
TAG_END()), 0);
TEST_1(sip->sip_from == NULL);
TEST_1(sip->sip_via); TEST_1(sip->sip_via->v_next == NULL);
......@@ -1558,6 +1561,15 @@ static int sip_header_test(void)
TEST_1(sip->sip_timestamp);
TEST_S(sip->sip_timestamp->ts_stamp, "10.010");
TEST_S(sip->sip_timestamp->ts_delay, "0.000100");
TEST_1(!sip->sip_refer_to);
TEST_1(tl = tl0 = tl_list(SIPTAG_TO_STR("<sip:foo@bar>"),
SIPTAG_END(),
SIPTAG_REFER_TO_STR("<sip:foo@bar>"),
TAG_END()));
/* sip_add_tagis should stop after SIPTAG_END() */
TEST(sip_add_tagis(msg, sip, &tl), 0);
TEST(tl, tl0 + 2);
TEST(sip_timestamp_make(home, "+1"), NULL);
TEST(sip_timestamp_make(home, "1.0e6 13.0"), NULL);
......
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