Module: kamailio
Branch: master
Commit: 7b2175dde6335926934e88b21533f8fa4cc5e7e3
URL:
https://github.com/kamailio/kamailio/commit/7b2175dde6335926934e88b21533f8f…
Author: Victor Seva <linuxmaniac(a)torreviejawireless.org>
Committer: Jose Luis Verdeguer <pepeluxx(a)gmail.com>
Date: 2018-12-20T10:51:03+01:00
secfilter: simplify secf_get_contact()
---
Modified: src/modules/secfilter/secfilter_hdr.c
---
Diff:
https://github.com/kamailio/kamailio/commit/7b2175dde6335926934e88b21533f8f…
Patch:
https://github.com/kamailio/kamailio/commit/7b2175dde6335926934e88b21533f8f…
---
diff --git a/src/modules/secfilter/secfilter_hdr.c
b/src/modules/secfilter/secfilter_hdr.c
index 4880b6a534..7e3a4feeb4 100644
--- a/src/modules/secfilter/secfilter_hdr.c
+++ b/src/modules/secfilter/secfilter_hdr.c
@@ -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;
}