secfilter: simplify secf_get_contact()
authorVictor Seva <linuxmaniac@torreviejawireless.org>
Wed, 19 Dec 2018 18:27:56 +0000 (19:27 +0100)
committerJose Luis Verdeguer <pepeluxx@gmail.com>
Thu, 20 Dec 2018 09:51:03 +0000 (10:51 +0100)
src/modules/secfilter/secfilter_hdr.c

index 4880b6a..7e3a4fe 100644 (file)
@@ -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;
 }