[asterisk-commits] mmichelson: branch mmichelson/caller_id r383789 - in /team/mmichelson/caller_...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Mar 25 17:17:03 CDT 2013


Author: mmichelson
Date: Mon Mar 25 17:16:59 2013
New Revision: 383789

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=383789
Log:
Add some progress towards using P-Asserted-Identity for connected line.

This is a half-effort here because I wanted to go down the path of writing
an actual parser for the header that PJSIP could automatically use when it
encounters the header. Unfortunately, it is not an easy task since most of
the handy functions for parsing are hidden away as private functions in
the PJSIP parsing code.


Modified:
    team/mmichelson/caller_id/channels/chan_gulp.c
    team/mmichelson/caller_id/include/asterisk/res_sip_session.h
    team/mmichelson/caller_id/res/res_sip_caller_id.c
    team/mmichelson/caller_id/res/res_sip_session.c

Modified: team/mmichelson/caller_id/channels/chan_gulp.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/caller_id/channels/chan_gulp.c?view=diff&rev=383789&r1=383788&r2=383789
==============================================================================
--- team/mmichelson/caller_id/channels/chan_gulp.c (original)
+++ team/mmichelson/caller_id/channels/chan_gulp.c Mon Mar 25 17:16:59 2013
@@ -401,7 +401,7 @@
 		return NULL;
 	}
 
-	if (!(chan = ast_channel_alloc(1, state, S_OR(session->caller.number.str, ""), S_OR(session->caller.name.str, ""), "", "", "", linkedid, 0, "Gulp/%s-%.*s", ast_sorcery_object_get_id(session->endpoint),
+	if (!(chan = ast_channel_alloc(1, state, S_OR(session->id.number.str, ""), S_OR(session->id.name.str, ""), "", "", "", linkedid, 0, "Gulp/%s-%.*s", ast_sorcery_object_get_id(session->endpoint),
 		(int)session->inv_session->dlg->call_id->id.slen, session->inv_session->dlg->call_id->id.ptr))) {
 		ao2_cleanup(pvt);
 		return NULL;

Modified: team/mmichelson/caller_id/include/asterisk/res_sip_session.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/caller_id/include/asterisk/res_sip_session.h?view=diff&rev=383789&r1=383788&r2=383789
==============================================================================
--- team/mmichelson/caller_id/include/asterisk/res_sip_session.h (original)
+++ team/mmichelson/caller_id/include/asterisk/res_sip_session.h Mon Mar 25 17:16:59 2013
@@ -97,8 +97,8 @@
 	pj_timer_entry rescheduled_reinvite;
 	/* Format capabilities pertaining to direct media */
 	struct ast_format_cap *direct_media_cap;
-	/* Identity of calling party */
-	struct ast_party_id caller;
+	/* Identity of endpoint this session deals with */
+	struct ast_party_id id;
 };
 
 typedef int (*ast_sip_session_request_creation_cb)(struct ast_sip_session *session, pjsip_tx_data *tdata);

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=383789&r1=383788&r2=383789
==============================================================================
--- team/mmichelson/caller_id/res/res_sip_caller_id.c (original)
+++ team/mmichelson/caller_id/res/res_sip_caller_id.c Mon Mar 25 17:16:59 2013
@@ -31,14 +31,27 @@
 #include "asterisk/channel.h"
 #include "asterisk/module.h"
 
+static void set_id_from_nameaddr(pjsip_name_addr *id_name_addr, struct ast_party_id *id)
+{
+	char cid_name[AST_CHANNEL_NAME];
+	char cid_num[AST_CHANNEL_NAME];
+	pjsip_sip_uri *uri;
+
+	uri = pjsip_uri_get_uri(id_name_addr);
+	ast_copy_pj_str(cid_name, &id_name_addr->display, sizeof(cid_name));
+	ast_copy_pj_str(cid_num, &uri->user, sizeof(cid_num));
+
+	id->name.str = ast_strdup(cid_name);
+	id->name.valid = 1;
+	id->number.str = ast_strdup(cid_num);
+	id->number.valid = 1;
+}
+
 static int get_id_from_from(struct pjsip_rx_data *rdata, struct ast_party_id *id)
 {
 	pjsip_fromto_hdr *from = pjsip_msg_find_hdr(rdata->msg_info.msg,
 			PJSIP_H_FROM, rdata->msg_info.msg->hdr.next);
 	pjsip_name_addr *id_name_addr;
-	pjsip_sip_uri *from_uri;
-	char cid_name[AST_CHANNEL_NAME];
-	char cid_num[AST_CHANNEL_NAME];
 
 	if (!from) {
 		/* This had better not happen */
@@ -46,14 +59,7 @@
 	}
 
 	id_name_addr = (pjsip_name_addr *)from->uri;
-	from_uri = pjsip_uri_get_uri(id_name_addr);
-	ast_copy_pj_str(cid_name, &id_name_addr->display, sizeof(cid_name));
-	ast_copy_pj_str(cid_num, &from_uri->user, sizeof(cid_num));
-
-	id->name.str = ast_strdup(cid_name);
-	id->name.valid = 1;
-	id->number.str = ast_strdup(cid_num);
-	id->number.valid = 1;
+	set_id_from_nameaddr(id_name_addr, id);
 
 	if (!id->name.str || !id->number.str) {
 		return -1;
@@ -62,11 +68,46 @@
 	return 0;
 }
 
-static int caller_id_incoming_request(struct ast_sip_session *session,
-		struct pjsip_rx_data *rdata)
+static int caller_id_incoming_request(struct ast_sip_session *session, pjsip_rx_data *rdata)
 {
-	get_id_from_from(rdata, &session->caller);
+	get_id_from_from(rdata, &session->id);
 	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 };
+	pjsip_generic_string_hdr *pai = pjsip_msg_find_hdr_by_name(rdata->msg_info.msg,
+			&pai_str, 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);
+
+	id_name_addr = (pjsip_name_addr *)pjsip_parse_uri(rdata->tp_info.pool,
+			header_content.ptr, header_content.slen, PJSIP_PARSE_URI_AS_NAMEADDR);
+
+	set_id_from_nameaddr(id_name_addr, id);
+
+	if (!id->name.str || !id->number.str) {
+		return -1;
+	}
+
+	return 0;
+}
+
+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);
 }
 
 static void set_from_header(pj_pool_t *pool, pjsip_fromto_hdr *from, struct ast_party_id *caller)
@@ -78,8 +119,7 @@
 	pj_strdup2(pool, &from_uri->user, caller->number.str);
 }
 
-static void caller_id_outgoing_request(struct ast_sip_session *session,
-		struct pjsip_tx_data *tdata)
+static void caller_id_outgoing_request(struct ast_sip_session *session, pjsip_tx_data *tdata)
 {
 	pjsip_fromto_hdr *from;
 	pjsip_dialog *dlg;
@@ -91,16 +131,27 @@
 	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_caller(session->channel)->id);
+	set_from_header(tdata->pool, from, &ast_channel_connected(session->channel)->id);
 	set_from_header(dlg->pool, dlg->local.info,
-			&ast_channel_caller(session->channel)->id);
+			&ast_channel_connected(session->channel)->id);
+}
+
+static void add_pai_header(pjsip_tx_data *tdata, struct ast_party_id *connected)
+{
+}
+
+static void caller_id_outgoing_response(struct ast_sip_session *session, pjsip_tx_data *tdata)
+{
+	add_pai_header(tdata, &ast_channel_connected(session->channel)->id);
 }
 
 static struct ast_sip_session_supplement caller_id_supplement = {
 	.method = "INVITE",
 	.priority = 0,
 	.incoming_request = caller_id_incoming_request,
+	.incoming_response = caller_id_incoming_response,
 	.outgoing_request = caller_id_outgoing_request,
+	.outgoing_response = caller_id_outgoing_response,
 };
 
 static int load_module(void)

Modified: team/mmichelson/caller_id/res/res_sip_session.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/caller_id/res/res_sip_session.c?view=diff&rev=383789&r1=383788&r2=383789
==============================================================================
--- team/mmichelson/caller_id/res/res_sip_session.c (original)
+++ team/mmichelson/caller_id/res/res_sip_session.c Mon Mar 25 17:16:59 2013
@@ -884,7 +884,7 @@
 	while ((delay = AST_LIST_REMOVE_HEAD(&session->delayed_requests, next))) {
 		ast_free(delay);
 	}
-	ast_party_id_free(&session->caller);
+	ast_party_id_free(&session->id);
 	ao2_cleanup(session->endpoint);
 }
 
@@ -958,7 +958,7 @@
 	}
 	session->direct_media_cap = ast_format_cap_alloc_nolock();
 	AST_LIST_HEAD_INIT_NOLOCK(&session->delayed_requests);
-	ast_party_id_init(&session->caller);
+	ast_party_id_init(&session->id);
 	ao2_ref(session, +1);
 	return session;
 }




More information about the asterisk-commits mailing list