ソースを参照

secfilter: simplify secf_get_contact()

Victor Seva 6 年 前
コミット
7b2175dde6
1 ファイル変更18 行追加26 行削除
  1. 18 26
      src/modules/secfilter/secfilter_hdr.c

+ 18 - 26
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;
 }