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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Apr 1 15:46:55 CDT 2013


Author: mmichelson
Date: Mon Apr  1 15:46:51 2013
New Revision: 384510

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=384510
Log:
Further progress for caller ID and connected line.

We'll now read and set P-Asserted-Identity as necessary
on the initial INVITE transaction. We don't have mid-call
connected line change support here in its entirety, but we
will queue the appropriate frame at times.


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=384510&r1=384509&r2=384510
==============================================================================
--- team/mmichelson/caller_id/res/res_sip_caller_id.c (original)
+++ team/mmichelson/caller_id/res/res_sip_caller_id.c Mon Apr  1 15:46:51 2013
@@ -30,6 +30,7 @@
 #include "asterisk/res_sip_session.h"
 #include "asterisk/channel.h"
 #include "asterisk/module.h"
+#include "asterisk/callerid.h"
 
 static void set_id_from_nameaddr(pjsip_name_addr *id_name_addr, struct ast_party_id *id)
 {
@@ -42,9 +43,13 @@
 	ast_copy_pj_str(cid_num, &uri->user, sizeof(cid_num));
 
 	id->name.str = ast_strdup(cid_name);
-	id->name.valid = 1;
+	if (!ast_strlen_zero(cid_name)) {
+		id->name.valid = 1;
+	}
 	id->number.str = ast_strdup(cid_num);
-	id->number.valid = 1;
+	if (!ast_strlen_zero(cid_num)) {
+		id->number.valid = 1;
+	}
 }
 
 static int get_id_from_from(struct pjsip_rx_data *rdata, struct ast_party_id *id)
@@ -61,7 +66,7 @@
 	id_name_addr = (pjsip_name_addr *)from->uri;
 	set_id_from_nameaddr(id_name_addr, id);
 
-	if (!id->name.str || !id->number.str) {
+	if (!id->number.valid) {
 		return -1;
 	}
 
@@ -93,7 +98,7 @@
 
 	set_id_from_nameaddr(id_name_addr, id);
 
-	if (!id->name.str || !id->number.str) {
+	if (!id->number.valid) {
 		return -1;
 	}
 
@@ -102,12 +107,26 @@
 
 static void caller_id_incoming_response(struct ast_sip_session *session, pjsip_rx_data *rdata)
 {
-	struct ast_party_id id;
-
-	ast_party_id_init(&id);
-	get_id_from_pai(rdata, &id);
-
-	ast_party_id_free(&id);
+	struct ast_party_connected_line connected;
+	struct ast_set_party_connected_line update_connected;
+
+	if (!session->channel) {
+		return;
+	}
+
+	ast_party_connected_line_init(&connected);
+	if (!get_id_from_pai(rdata, &connected.id)) {
+		memset(&update_connected, 0, sizeof(update_connected));
+
+		update_connected.id.number = 1;
+		update_connected.id.name = 1;
+		
+		ast_set_party_id_all(&update_connected.priv);
+		connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
+		ast_channel_queue_connected_line_update(session->channel, &connected, &update_connected);
+	}
+
+	ast_party_connected_line_free(&connected);
 }
 
 static void set_from_header(pj_pool_t *pool, pjsip_fromto_hdr *from, struct ast_party_id *caller)
@@ -117,6 +136,44 @@
 
 	pj_strdup2(pool, &id_name_addr->display, caller->name.str);
 	pj_strdup2(pool, &from_uri->user, caller->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);
+
+	if (!id->number.valid) {
+		return;
+	}
+
+	if (!pai_value) {
+		return;
+	}
+
+	if (id->name.valid) {
+		ast_str_append(&pai_value, 0, "\"%s\" ", id->name.str);
+	}
+
+	ast_str_append(&pai_value, 0, "<%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);
 }
 
 static void caller_id_outgoing_request(struct ast_sip_session *session, pjsip_tx_data *tdata)
@@ -134,14 +191,14 @@
 	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);
-}
-
-static void add_pai_header(pjsip_tx_data *tdata, struct ast_party_id *connected)
-{
+	add_pai_header(tdata, &ast_channel_connected(session->channel)->id);
 }
 
 static void caller_id_outgoing_response(struct ast_sip_session *session, pjsip_tx_data *tdata)
 {
+	if (!session->channel) {
+		return;
+	}
 	add_pai_header(tdata, &ast_channel_connected(session->channel)->id);
 }
 




More information about the asterisk-commits mailing list