Skip to content

Commit

Permalink
secfilter: simplify secf_get_contact()
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxmaniac authored and Pepelux committed Dec 20, 2018
1 parent 6180cf1 commit 7b2175d
Showing 1 changed file with 18 additions and 26 deletions.
44 changes: 18 additions & 26 deletions src/modules/secfilter/secfilter_hdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,40 +141,32 @@ int secf_get_to(struct sip_msg *msg, str *name, str *user, str *domain)
/* get 'contact' header */
int secf_get_contact(struct sip_msg *msg, str *user, str *domain)
{
str contact = {NULL, 0};
struct sip_uri parsed_uri;
struct sip_uri uri;
contact_t *contact;

if(msg == NULL)
return -1;
if(msg->contact == NULL)
if((parse_headers(msg, HDR_CONTACT_F, 0) == -1) || !msg->contact)
return 1;

if(!msg->contact->parsed && parse_contact(msg->contact) < 0) {
LM_ERR("cannot parse the Contact header\n");
return 1;
if(!msg->contact->parsed && (parse_contact(msg->contact) < 0)) {
LM_ERR("Error parsing contact header (%.*s)\n", msg->contact->body.len,
msg->contact->body.s);
return -1;
}
if(((contact_body_t *)msg->contact->parsed)->contacts
&& ((contact_body_t *)msg->contact->parsed)->contacts->uri.s != NULL
&& ((contact_body_t *)msg->contact->parsed)->contacts->uri.len
> 0) {
contact.s = ((contact_body_t *)msg->contact->parsed)->contacts->uri.s;
contact.len =
((contact_body_t *)msg->contact->parsed)->contacts->uri.len;
}
if(contact.s == NULL)

contact = ((contact_body_t *)msg->contact->parsed)->contacts;
if(!contact) {
return 1;
}

if(parse_uri(contact.s, contact.len, &parsed_uri) < 0) {
LM_ERR("Error parsing contact uri header (%.*s)\n", contact.len,
contact.s);
return -1;
if(parse_uri(contact->uri.s, contact->uri.len, &uri) < 0) {
LM_ERR("cannot parse the Contact URI\n");
return 1;
}

user->s = parsed_uri.user.s;
user->len = parsed_uri.user.len;
user->s = uri.user.s;
user->len = uri.user.len;

domain->s = parsed_uri.host.s;
domain->len = parsed_uri.host.len;
domain->s = uri.host.s;
domain->len = uri.host.len;

return 0;
}

0 comments on commit 7b2175d

Please sign in to comment.