Commit 027d1108 authored by Pekka Pessi's avatar Pekka Pessi

sip: use msg_parse_header_fields()

parent c8e73200
......@@ -1386,23 +1386,19 @@ msg_hclass_t sip_contact_class[] =
/* hc_critical: */ 0
}};
issize_t sip_contact_d(su_home_t *home,
sip_header_t *h,
char *s,
isize_t slen)
issize_t
sip_contact_one_d(su_home_t *home, sip_header_t *h, char **ss)
{
sip_contact_t *m = (sip_contact_t *)h;
assert(h);
while (*s == ',') /* Ignore empty entries (comma-whitespace) */
*s = '\0', s += span_lws(s + 1) + 1;
if (sip_name_addr_d(home, &s, &m->m_display, m->m_url,
&m->m_params, &m->m_comment) == -1)
return -1;
return sip_name_addr_d(home, ss, &m->m_display, m->m_url,
&m->m_params, &m->m_comment);
}
return msg_parse_next_field(home, h, s, slen);
issize_t
sip_contact_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen)
{
return msg_parse_header_fields(home, h, s, sip_contact_one_d);
}
......@@ -2096,28 +2092,24 @@ static int sip_retry_after_update(msg_common_t *h,
/* ====================================================================== */
static issize_t
sip_any_route_field_d(su_home_t *home, sip_header_t *h, char **ss)
{
sip_route_t *r = (sip_route_t *)h;
return sip_name_addr_d(home, ss, &r->r_display,
r->r_url, &r->r_params, NULL);
}
/**Parse a @Route or a @RecordRoute header.
*
* @retval 0 when successful,
* @retval -1 upon an error.
*/
issize_t sip_any_route_d(su_home_t *home,
sip_header_t *h,
char *s,
isize_t slen)
issize_t
sip_any_route_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen)
{
sip_route_t *r = (sip_route_t *)h;
assert(h);
while (*s == ',') /* Ignore empty entries (comma-whitespace) */
*s = '\0', s += span_lws(s + 1) + 1;
if (sip_name_addr_d(home, &s, &r->r_display,
r->r_url, &r->r_params, NULL) < 0)
return -1;
return msg_parse_next_field(home, h, s, slen);
return msg_parse_header_fields(home, h, s, sip_any_route_field_d);
}
issize_t sip_any_route_e(char b[], isize_t bsiz, sip_header_t const *h, int flags)
......@@ -2532,31 +2524,33 @@ static msg_update_f sip_via_update;
msg_hclass_t sip_via_class[] =
SIP_HEADER_CLASS(via, "Via", "v", v_params, prepend, via);
issize_t sip_via_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen)
static issize_t
sip_via_field_d(su_home_t *home, sip_header_t *h, char **ss)
{
sip_via_t *v = (sip_via_t *)h;
assert(h);
while (*s == ',') /* Ignore empty entries (comma-whitespace) */
*s = '\0', s += span_lws(s + 1) + 1;
/* sent-protocol sent-by *( ";" via-params ) [ comment ] */
/* Parse protocol */
if (sip_transport_d(&s, &v->v_protocol) == -1)
if (sip_transport_d(ss, &v->v_protocol) == -1)
return -1;
/* Host (and port) */
if (msg_hostport_d(&s, &v->v_host, &v->v_port) == -1)
if (msg_hostport_d(ss, &v->v_host, &v->v_port) == -1)
return -1;
/* Parameters */
if (*s == ';' && msg_params_d(home, &s, &v->v_params) == -1)
if (**ss == ';' && msg_params_d(home, ss, &v->v_params) == -1)
return -1;
/* Comment */
if (*s == '(' && msg_comment_d(&s, &v->v_comment) == -1)
if (**ss == '(' && msg_comment_d(ss, &v->v_comment) == -1)
return -1;
return msg_parse_next_field(home, h, s, slen);
return 0;
}
issize_t
sip_via_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen)
{
return msg_parse_header_fields(home, h, s, sip_via_field_d);
}
issize_t sip_via_e(char b[], isize_t bsiz, sip_header_t const *h, int flags)
......
......@@ -190,43 +190,46 @@ size_t span_attribute_value(char *s)
return n;
}
static
issize_t sip_caller_prefs_d(su_home_t *home, sip_header_t *h,
char *s, isize_t slen)
static issize_t
sip_caller_prefs_field_d(su_home_t *home, sip_header_t *h, char **ss)
{
sip_caller_prefs_t *cp = (sip_caller_prefs_t *)h;
url_t url[1];
char const *ignore = NULL;
int kludge = 0;
assert(h);
while (*s == ',') /* Ignore empty entries (comma-whitespace) */
*s = '\0', s += span_lws(s + 1) + 1;
/* Kludge: support PoC IS spec with a typo... */
if (su_casenmatch(s, "*,", 2))
s[1] = ';', kludge = 0;
else if (s[0] != '*' && s[0] != '<') {
if (su_strnmatch(*ss, "*,", 2)) {
/* Kludge: support PoC IS spec with a typo... */
(*ss)[1] = ';', kludge = 0;
}
else if (**ss != '*' && **ss != '<') {
/* Kludge: missing URL - */
size_t n = span_attribute_value(s);
kludge = n > 0 && (s[n] == '\0' || s[n] == ',' || s[n] == ';');
size_t n = span_attribute_value(*ss);
if (n > 0) {
char end = (*ss)[n];
kludge = end == '\0' || end == ',' || end == ';';
}
}
if (kludge) {
if (msg_any_list_d(home, &s, (msg_param_t **)&cp->cp_params,
msg_attribute_value_scanner, ';') == -1)
return -1;
return msg_any_list_d(home, ss, (msg_param_t **)&cp->cp_params,
msg_attribute_value_scanner, ';');
}
/* Parse params (and ignore display name and url) */
else if (sip_name_addr_d(home, &s, &ignore, url, &cp->cp_params, NULL)
== -1)
return -1;
/* Be liberal... */
/* if (url->url_type != url_any)
return -1; */
return msg_parse_next_field(home, h, s, slen);
else {
return sip_name_addr_d(home, ss, &ignore, url, &cp->cp_params, NULL);
/* Be liberal... */
/* if (url->url_type != url_any)
return -1; */
}
}
static issize_t
sip_caller_prefs_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen)
{
return msg_parse_header_fields(home, h, s, sip_caller_prefs_field_d);
}
static
......
......@@ -881,22 +881,18 @@ issize_t sip_if_match_e(char b[], isize_t bsiz, sip_header_t const *h, int f)
/* ====================================================================== */
/** Parsing @CallInfo, @ErrorInfo. */
static
issize_t sip_info_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen)
static issize_t
sip_info_field_d(su_home_t *home, sip_header_t *h, char **ss)
{
sip_call_info_t *ci = h->sh_call_info;
char *end = s + slen;
assert(h);
while (*s == ',')
s += span_lws(s + 1) + 1;
if (sip_name_addr_d(home, &s, NULL, ci->ci_url, &ci->ci_params, NULL) < 0)
return -1;
return sip_name_addr_d(home, ss, NULL, ci->ci_url, &ci->ci_params, NULL);
}
/* Recurse */
return msg_parse_next_field(home, h, s, end - s);
static issize_t
sip_info_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen)
{
return msg_parse_header_fields(home, h, s, sip_info_field_d);
}
isize_t sip_info_dup_xtra(sip_header_t const *h, isize_t offset)
......@@ -1145,21 +1141,22 @@ msg_hclass_t sip_remote_party_id_class[] =
SIP_HEADER_CLASS(remote_party_id, "Remote-Party-ID", "",
rpid_params, append, remote_party_id);
issize_t sip_remote_party_id_d(su_home_t *home, sip_header_t *h,
char *s, isize_t slen)
static issize_t
sip_remote_party_id_field_d(su_home_t *home, sip_header_t *h, char **ss)
{
sip_remote_party_id_t *rpid = (sip_remote_party_id_t *)h;
while (*s == ',') /* Ignore empty entries (comma-whitespace) */
*s = '\0', s += span_lws(s + 1) + 1;
if (sip_name_addr_d(home, &s,
&rpid->rpid_display,
rpid->rpid_url,
&rpid->rpid_params, NULL) == -1)
return -1;
return sip_name_addr_d(home, ss,
&rpid->rpid_display,
rpid->rpid_url,
&rpid->rpid_params, NULL);
}
return msg_parse_next_field(home, h, s, slen);
issize_t
sip_remote_party_id_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen)
{
return msg_parse_header_fields(home, h, s, sip_remote_party_id_field_d);
}
issize_t sip_remote_party_id_e(char b[], isize_t bsiz,
......@@ -1285,21 +1282,22 @@ msg_hclass_t sip_p_asserted_identity_class[] =
SIP_HEADER_CLASS(p_asserted_identity, "P-Asserted-Identity", "",
paid_common, append, p_asserted_identity);
issize_t sip_p_asserted_identity_d(su_home_t *home, sip_header_t *h,
char *s, isize_t slen)
static issize_t
sip_p_asserted_identity_field_d(su_home_t *home, sip_header_t *h, char **ss)
{
sip_p_asserted_identity_t *paid = (sip_p_asserted_identity_t *)h;
while (*s == ',') /* Ignore empty entries (comma-whitespace) */
*s = '\0', s += span_lws(s + 1) + 1;
if (sip_name_addr_d(home, &s,
&paid->paid_display,
paid->paid_url,
NULL, NULL) == -1)
return -1;
return sip_name_addr_d(home, ss,
&paid->paid_display,
paid->paid_url,
NULL, NULL);
}
return msg_parse_next_field(home, h, s, slen);
issize_t
sip_p_asserted_identity_d(su_home_t *home, sip_header_t *h,
char *s, isize_t slen)
{
return msg_parse_header_fields(home, h, s, sip_p_asserted_identity_field_d);
}
issize_t sip_p_asserted_identity_e(char b[], isize_t bsiz,
......
......@@ -133,26 +133,29 @@ msg_hclass_t sip_accept_disposition_class[] =
SIP_HEADER_CLASS(accept_disposition, "Accept-Disposition", "",
ad_params, apndlist, accept_disposition);
issize_t sip_accept_disposition_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen)
static issize_t
sip_accept_disposition_field_d(su_home_t *home, sip_header_t *h, char **ss)
{
sip_accept_disposition_t *ad = (sip_accept_disposition_t *)h;
assert(h);
if (sip_version_d(ss, &ad->ad_type) == -1) ||
return -1;
/* Ignore empty entries (comma-whitespace) */
while (*s == ',')
s += span_lws(s + 1) + 1;
ad->ad_subtype = strchr(ad->ad_type, '/'):
if (ad->ad_subtype)
ad->ad_subtype++;
/* "Accept:" #(type/subtyp ; *(parameters))) */
if (/* Parse protocol */
sip_version_d(&s, &ad->ad_type) == -1 ||
(ad->ad_subtype = strchr(ad->ad_type, '/')) == NULL ||
(*s == ';' && msg_params_d(home, &s, &ad->ad_params) == -1))
return -1;
if (**ss == ';')
return msg_params_d(home, &s, &ad->ad_params);
if (ad->ad_subtype) ad->ad_subtype++;
return 0;
}
return msg_parse_next_field(home, h, s, slen);
issize_t
sip_accept_disposition_d(su_home_t *home, sip_header_t *h,
char *s, isize_t slen)
{
return msg_parse_header_fields(home, h, s, sip_accept_disposition_field_d);
}
issize_t sip_accept_disposition_e(char b[], isize_t bsiz, sip_header_t const *h, int flags)
......
......@@ -94,22 +94,24 @@ static msg_update_f sip_reason_update;
msg_hclass_t sip_reason_class[] =
SIP_HEADER_CLASS(reason, "Reason", "", re_params, append, reason);
issize_t sip_reason_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen)
static issize_t
sip_reason_field_d(su_home_t *home, sip_header_t *h, char **ss)
{
sip_reason_t *re = (sip_reason_t *)h;
size_t n;
while (*s == ',') /* Ignore empty entries (comma-whitespace) */
*s = '\0', s += span_lws(s + 1) + 1;
re->re_protocol = s;
if ((n = span_token(s)) == 0)
return -1;
s += n; while (IS_LWS(*s)) *s++ = '\0';
if (*s == ';' && msg_params_d(home, &s, &re->re_params) < 0)
if (msg_token_d(ss, &re->re_protocol) == -1)
return -1;
return msg_parse_next_field(home, h, s, slen);
if (**ss == ';')
return msg_params_d(home, ss, &re->re_params);
return 0;
}
issize_t
sip_reason_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen)
{
return msg_parse_header_fields(home, h, s, sip_reason_field_d);
}
issize_t sip_reason_e(char b[], isize_t bsiz, sip_header_t const *h, int f)
......
......@@ -455,23 +455,24 @@ issize_t sip_proxy_authentication_info_e(char b[], isize_t bsiz,
typedef struct sip_security_agree_s sip_security_agree_t;
#define sh_security_agree sh_security_client
static
issize_t sip_security_agree_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen)
static issize_t
sip_security_agree_field_d(su_home_t *home, sip_header_t *h, char **ss)
{
sip_security_agree_t *sa = (sip_security_agree_t *)h;
isize_t n;
if (msg_token_d(ss, &sa->sa_mec) == -1)
return -1;
while (*s == ',') /* Ignore empty entries (comma-whitespace) */
*s = '\0', s += span_lws(s + 1) + 1;
if (**ss == ';')
return msg_params_d(home, ss, &sa->sa_params);
if ((n = span_token(s)) == 0)
return -1;
sa->sa_mec = s; s += n; while (IS_LWS(*s)) *s++ = '\0';
if (*s == ';' && msg_params_d(home, &s, &sa->sa_params) < 0)
return -1;
return 0;
}
return msg_parse_next_field(home, h, s, slen);
static issize_t
sip_security_agree_d(su_home_t *home, sip_header_t *h, char *s, isize_t slen)
{
return msg_parse_header_fields(home, h, s, sip_security_agree_field_d);
}
static
......
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