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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Apr 3 16:39:33 CDT 2013


Author: mmichelson
Date: Wed Apr  3 16:39:30 2013
New Revision: 384732

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=384732
Log:
Switch to using a fromto header for outgoing P-Asserted-Identity.


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=384732&r1=384731&r2=384732
==============================================================================
--- team/mmichelson/caller_id/res/res_sip_caller_id.c (original)
+++ team/mmichelson/caller_id/res/res_sip_caller_id.c Wed Apr  3 16:39:30 2013
@@ -205,52 +205,61 @@
 	pj_strdup2(pool, &from_uri->user, caller->number.str);
 }
 
+static void modify_pai_header(pjsip_tx_data *tdata, pjsip_fromto_hdr *pai_hdr, struct ast_party_id *id)
+{
+	pjsip_name_addr *pai_name_addr;
+	pjsip_sip_uri *pai_uri;
+
+	pai_name_addr = (pjsip_name_addr *) pai_hdr->uri;
+	pai_uri = pjsip_uri_get_uri(pai_name_addr->uri);
+
+	if (id->name.valid) {
+		pj_strdup2(tdata->pool, &pai_name_addr->display, id->name.str);
+	}
+
+	pj_strdup2(tdata->pool, &pai_uri->user, id->number.str);
+}
+
 static void add_pai_header(pjsip_tx_data *tdata, struct ast_party_id *id)
 {
-	RAII_VAR(struct ast_str *, pai_value, ast_str_create(64), ast_free_ptr);
 	static const pj_str_t pj_pai_name = { "P-Asserted-Identity", 19 };
-	pj_str_t pj_pai_value;
-	pjsip_generic_string_hdr *hdr;
-	pjsip_fromto_hdr *base = tdata->msg->type == PJSIP_REQUEST_MSG ?
-		PJSIP_MSG_FROM_HDR(tdata->msg) : PJSIP_MSG_TO_HDR(tdata->msg);
-	pjsip_sip_uri *uri = pjsip_uri_get_uri(base->uri);
-	pjsip_hdr *old_pai;
+	pjsip_fromto_hdr *pai_hdr;
+	pjsip_fromto_hdr *old_pai;
+	pjsip_name_addr *pai_name_addr;
+	pjsip_sip_uri *pai_uri;
+	pjsip_fromto_hdr *base;
 
 	if (!id->number.valid) {
 		return;
 	}
 
-	if (!pai_value) {
-		return;
-	}
-
 	/* Since inv_session reuses responses, we have to make sure there's not already
-	 * a P-Asserted-Identity present. If there is, we need to remove it so we can
-	 * add our new one.
+	 * a P-Asserted-Identity present. If there is, we just modify the old one.
 	 */
 	old_pai = pjsip_msg_find_hdr_by_name(tdata->msg, &pj_pai_name, tdata->msg->hdr.next);
 	if (old_pai) {
-		pj_list_erase(old_pai);
-	}
+		modify_pai_header(tdata, old_pai, id);
+		return;
+	}
+
+	base = tdata->msg->type == PJSIP_REQUEST_MSG ? PJSIP_MSG_FROM_HDR(tdata->msg) :
+		PJSIP_MSG_TO_HDR(tdata->msg);
+	pai_hdr = pjsip_from_hdr_create(tdata->pool);
+	pai_hdr->type = PJSIP_H_OTHER;
+	pj_strdup(tdata->pool, &pai_hdr->name, &pj_pai_name);
+	pai_hdr->sname.slen = 0;
+
+	pai_name_addr = pjsip_uri_clone(tdata->pool, base->uri);
+	pai_uri = pjsip_uri_get_uri(pai_name_addr->uri);
 
 	if (id->name.valid) {
-		ast_str_append(&pai_value, 0, "\"%s\" ", id->name.str);
-	}
-
-	ast_str_append(&pai_value, 0, "<sip:%s@%.*s", id->number.str, (int) pj_strlen(&uri->host),
-			pj_strbuf(&uri->host));
-
-	if (uri->port) {
-		ast_str_append(&pai_value, 0, ":%d", uri->port);
-	}
-
-	ast_str_append(&pai_value, 0, ">");
-
-	pj_cstr(&pj_pai_value, ast_str_buffer(pai_value));
-
-	hdr = pjsip_generic_string_hdr_create(tdata->pool,
-			&pj_pai_name, &pj_pai_value);
-	pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *)hdr);
+		pj_strdup2(tdata->pool, &pai_name_addr->display, id->name.str);
+	}
+
+	pj_strdup2(tdata->pool, &pai_uri->user, id->number.str);
+
+	pai_hdr->uri = (pjsip_uri *) pai_name_addr;
+	pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *)pai_hdr);
 }
 
 static void caller_id_outgoing_request(struct ast_sip_session *session, pjsip_tx_data *tdata)




More information about the asterisk-commits mailing list