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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Apr 2 12:46:22 CDT 2013


Author: mmichelson
Date: Tue Apr  2 12:46:18 2013
New Revision: 384547

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=384547
Log:
Logic adjustments for the most part

* Added parentheses to an if to better group statements.
* Remove old P-Asserted-Identity header if we're going to add a new one.
* Other minor adjustments.


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=384547&r1=384546&r2=384547
==============================================================================
--- team/mmichelson/caller_id/res/res_sip_caller_id.c (original)
+++ team/mmichelson/caller_id/res/res_sip_caller_id.c Tue Apr  2 12:46:18 2013
@@ -107,12 +107,12 @@
 	if (get_id_from_pai(rdata, &connected.id)) {
 		return;
 	}
-	if (connected.id.number.valid &&
+	if ((connected.id.number.valid &&
 			(ast_strlen_zero(session->id.number.str) ||
-			 strcmp(session->id.number.str, connected.id.number.str)) ||
-		connected.id.name.valid &&
+			 strcmp(session->id.number.str, connected.id.number.str))) ||
+		(connected.id.name.valid &&
 			(ast_strlen_zero(session->id.name.str) ||
-		 	strcmp(session->id.name.str, connected.id.name.str))) {
+		 	strcmp(session->id.name.str, connected.id.name.str)))) {
 		struct ast_set_party_connected_line update_connected;
 		memset(&update_connected, 0, sizeof(update_connected));
 		update_connected.id.number = 1;
@@ -120,6 +120,7 @@
 
 		ast_set_party_id_all(&update_connected.priv);
 		connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
+		ast_party_id_copy(&session->id, &connected.id);
 		ast_channel_queue_connected_line_update(session->channel, &connected, &update_connected);
 	}
 
@@ -144,9 +145,6 @@
 
 static void caller_id_incoming_response(struct ast_sip_session *session, pjsip_rx_data *rdata)
 {
-	struct ast_party_connected_line connected;
-	struct ast_set_party_connected_line update_connected;
-
 	if (!session->channel) {
 		return;
 	}
@@ -172,6 +170,7 @@
 	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;
 
 	if (!id->number.valid) {
 		return;
@@ -179,6 +178,15 @@
 
 	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.
+	 */
+	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);
 	}
 
 	if (id->name.valid) {
@@ -203,19 +211,24 @@
 
 static void caller_id_outgoing_request(struct ast_sip_session *session, pjsip_tx_data *tdata)
 {
-	pjsip_fromto_hdr *from;
-	pjsip_dialog *dlg;
-
 	if (!session->channel) {
 		return;
 	}
 
-	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,
-			&ast_channel_connected(session->channel)->id);
+	if (session->inv_session->state < PJSIP_INV_STATE_CONFIRMED) {
+		/* Only change the From header on the initial outbound INVITE. Switching it
+		 * mid-call might confuse some UAs.
+		 */
+		pjsip_fromto_hdr *from;
+		pjsip_dialog *dlg;
+
+		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,
+				&ast_channel_connected(session->channel)->id);
+	}
 	add_pai_header(tdata, &ast_channel_connected(session->channel)->id);
 }
 




More information about the asterisk-commits mailing list