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

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


Author: mmichelson
Date: Wed Apr  3 17:19:44 2013
New Revision: 384734

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=384734
Log:
Add ability to add Remote-Party-ID to outbound requests/responses.

This also factors common operations into their own functions.

At this point the only task left to tackle is privacy. And that's
no fun at all.


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=384734&r1=384733&r2=384734
==============================================================================
--- team/mmichelson/caller_id/res/res_sip_caller_id.c (original)
+++ team/mmichelson/caller_id/res/res_sip_caller_id.c Wed Apr  3 17:19:44 2013
@@ -196,28 +196,46 @@
 	update_incoming_connected_line(session, rdata);
 }
 
-static void set_from_header(pj_pool_t *pool, pjsip_fromto_hdr *from, struct ast_party_id *caller)
-{
-	pjsip_name_addr *id_name_addr = (pjsip_name_addr *)from->uri;
-	pjsip_sip_uri *from_uri = pjsip_uri_get_uri(id_name_addr);
-
-	pj_strdup2(pool, &id_name_addr->display, caller->name.str);
-	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);
+static void modify_id_header(pj_pool_t *pool, pjsip_fromto_hdr *id_hdr, struct ast_party_id *id)
+{
+	pjsip_name_addr *id_name_addr;
+	pjsip_sip_uri *id_uri;
+
+	id_name_addr = (pjsip_name_addr *) id_hdr->uri;
+	id_uri = pjsip_uri_get_uri(id_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);
+		pj_strdup2(pool, &id_name_addr->display, id->name.str);
+	}
+
+	pj_strdup2(pool, &id_uri->user, id->number.str);
+}
+
+static pjsip_fromto_hdr *create_new_id_hdr(const pj_str_t *hdr_name, pjsip_tx_data *tdata, struct ast_party_id *id)
+{
+	pjsip_fromto_hdr *id_hdr;
+	pjsip_fromto_hdr *base;
+	pjsip_name_addr *id_name_addr;
+	pjsip_sip_uri *id_uri;
+
+	base = tdata->msg->type == PJSIP_REQUEST_MSG ? PJSIP_MSG_FROM_HDR(tdata->msg) :
+		PJSIP_MSG_TO_HDR(tdata->msg);
+	id_hdr = pjsip_from_hdr_create(tdata->pool);
+	id_hdr->type = PJSIP_H_OTHER;
+	pj_strdup(tdata->pool, &id_hdr->name, hdr_name);
+	id_hdr->sname.slen = 0;
+
+	id_name_addr = pjsip_uri_clone(tdata->pool, base->uri);
+	id_uri = pjsip_uri_get_uri(id_name_addr->uri);
+
+	if (id->name.valid) {
+		pj_strdup2(tdata->pool, &id_name_addr->display, id->name.str);
+	}
+
+	pj_strdup2(tdata->pool, &id_uri->user, id->number.str);
+
+	id_hdr->uri = (pjsip_uri *) id_name_addr;
+	return id_hdr;
 }
 
 static void add_pai_header(pjsip_tx_data *tdata, struct ast_party_id *id)
@@ -225,9 +243,6 @@
 	static const pj_str_t pj_pai_name = { "P-Asserted-Identity", 19 };
 	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;
@@ -238,28 +253,42 @@
 	 */
 	old_pai = pjsip_msg_find_hdr_by_name(tdata->msg, &pj_pai_name, tdata->msg->hdr.next);
 	if (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) {
-		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;
+		modify_id_header(tdata->pool, old_pai, id);
+		return;
+	}
+
+	pai_hdr = create_new_id_hdr(&pj_pai_name, tdata, id);
+	if (!pai_hdr) {
+		return;
+	}
+
 	pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *)pai_hdr);
+}
+
+static void add_rpid_header(pjsip_tx_data *tdata, struct ast_party_id *id)
+{
+	static const pj_str_t pj_rpid_name = { "Remote-Party-ID", 15 };
+	pjsip_fromto_hdr *rpid_hdr;
+	pjsip_fromto_hdr *old_rpid;
+
+	if (!id->number.valid) {
+		return;
+	}
+
+	/* Since inv_session reuses responses, we have to make sure there's not already
+	 * a P-Asserted-Identity present. If there is, we just modify the old one.
+	 */
+	old_rpid = pjsip_msg_find_hdr_by_name(tdata->msg, &pj_rpid_name, tdata->msg->hdr.next);
+	if (old_rpid) {
+		modify_id_header(tdata->pool, old_rpid, id);
+		return;
+	}
+
+	rpid_hdr = create_new_id_hdr(&pj_rpid_name, tdata, id);
+	if (!rpid_hdr) {
+		return;
+	}
+	pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *)rpid_hdr);
 }
 
 static void caller_id_outgoing_request(struct ast_sip_session *session, pjsip_tx_data *tdata)
@@ -278,13 +307,16 @@
 		from = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_FROM, tdata->msg->hdr.next);
 		dlg = session->inv_session->dlg;
 
-		set_from_header(tdata->pool, from, &ast_channel_connected(session->channel)->id);
-		set_from_header(dlg->pool, dlg->local.info,
+		modify_id_header(tdata->pool, from, &ast_channel_connected(session->channel)->id);
+		modify_id_header(dlg->pool, dlg->local.info,
 				&ast_channel_connected(session->channel)->id);
 	}
 	if (session->endpoint->send_pai) {
 		add_pai_header(tdata, &ast_channel_connected(session->channel)->id);
 	}
+	if (session->endpoint->send_rpid) {
+		add_rpid_header(tdata, &ast_channel_connected(session->channel)->id);
+	}
 }
 
 static void caller_id_outgoing_response(struct ast_sip_session *session, pjsip_tx_data *tdata)
@@ -294,6 +326,9 @@
 	}
 	if (session->endpoint->send_pai) {
 		add_pai_header(tdata, &ast_channel_connected(session->channel)->id);
+	}
+	if (session->endpoint->send_rpid) {
+		add_rpid_header(tdata, &ast_channel_connected(session->channel)->id);
 	}
 }
 




More information about the asterisk-commits mailing list