[asterisk-commits] mmichelson: branch mmichelson/caller_id r384614 - /team/mmichelson/caller_id/...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Apr 3 10:29:48 CDT 2013


Author: mmichelson
Date: Wed Apr  3 10:29:45 2013
New Revision: 384614

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=384614
Log:
Factor P-Asserted-Identity and Remote-Party-ID parsing into a common function.


Modified:
    team/mmichelson/caller_id/res/res_sip_caller_id.c

Modified: team/mmichelson/caller_id/res/res_sip_caller_id.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/caller_id/res/res_sip_caller_id.c?view=diff&rev=384614&r1=384613&r2=384614
==============================================================================
--- team/mmichelson/caller_id/res/res_sip_caller_id.c (original)
+++ team/mmichelson/caller_id/res/res_sip_caller_id.c Wed Apr  3 10:29:45 2013
@@ -52,19 +52,18 @@
 	}
 }
 
-static int get_id_from_pai(pjsip_rx_data *rdata, struct ast_party_id *id)
-{
-	pj_str_t pai_str = { "P-Asserted-Identity", 19 };
-	pjsip_generic_string_hdr *pai = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg,
-			&pai_str, rdata->msg_info.msg->hdr.next);
+static int get_id_from_header(pjsip_rx_data *rdata, const pj_str_t *header_name, struct ast_party_id *id)
+{
+	pjsip_generic_string_hdr *ident = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg,
+			header_name, rdata->msg_info.msg->hdr.next);
 	pj_str_t header_content;
 	pjsip_name_addr *id_name_addr;
 
-	if (!pai) {
-		return -1;
-	}
-
-	pj_strdup_with_null(rdata->tp_info.pool, &header_content, &pai->hvalue);
+	if (!ident) {
+		return -1;
+	}
+
+	pj_strdup_with_null(rdata->tp_info.pool, &header_content, &ident->hvalue);
 
 	id_name_addr = (pjsip_name_addr *)pjsip_parse_uri(rdata->tp_info.pool,
 			header_content.ptr, header_content.slen, PJSIP_PARSE_URI_AS_NAMEADDR);
@@ -78,38 +77,19 @@
 	if (!id->number.valid) {
 		return -1;
 	}
-
-	return 0;
+	return 0;
+}
+
+static int get_id_from_pai(pjsip_rx_data *rdata, struct ast_party_id *id)
+{
+	pj_str_t pai_str = { "P-Asserted-Identity", 19 };
+	return get_id_from_header(rdata, &pai_str, id);
 }
 
 static int get_id_from_rpid(pjsip_rx_data *rdata, struct ast_party_id *id)
 {
 	pj_str_t rpid_str = { "Remote-Party-ID", 15 };
-	pjsip_generic_string_hdr *rpid = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg,
-			&rpid_str, rdata->msg_info.msg->hdr.next);
-	pj_str_t header_content;
-	pjsip_name_addr *id_name_addr;
-
-	if (!rpid) {
-		return -1;
-	}
-
-	pj_strdup_with_null(rdata->tp_info.pool, &header_content, &rpid->hvalue);
-
-	id_name_addr = (pjsip_name_addr *)pjsip_parse_uri(rdata->tp_info.pool,
-			header_content.ptr, header_content.slen, PJSIP_PARSE_URI_AS_NAMEADDR);
-
-	if (!id_name_addr) {
-		return -1;
-	}
-
-	set_id_from_nameaddr(id_name_addr, id);
-
-	if (!id->number.valid) {
-		return -1;
-	}
-
-	return 0;
+	return get_id_from_header(rdata, &rpid_str, id);
 }
 
 static int get_id_from_from(struct pjsip_rx_data *rdata, struct ast_party_id *id)




More information about the asterisk-commits mailing list