[asterisk-commits] kharwell: branch kharwell/pimp_sip_diversion r386331 - in /team/kharwell/pimp...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Apr 22 18:12:51 CDT 2013


Author: kharwell
Date: Mon Apr 22 18:12:48 2013
New Revision: 386331

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=386331
Log:
fixes from some testing done.  also added a check to see if the caller id was set on the session and if so use that instead of To header

Modified:
    team/kharwell/pimp_sip_diversion/include/asterisk/res_sip.h
    team/kharwell/pimp_sip_diversion/res/res_sip/sip_configuration.c
    team/kharwell/pimp_sip_diversion/res/res_sip_diversion.c

Modified: team/kharwell/pimp_sip_diversion/include/asterisk/res_sip.h
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_sip_diversion/include/asterisk/res_sip.h?view=diff&rev=386331&r1=386330&r2=386331
==============================================================================
--- team/kharwell/pimp_sip_diversion/include/asterisk/res_sip.h (original)
+++ team/kharwell/pimp_sip_diversion/include/asterisk/res_sip.h Mon Apr 22 18:12:48 2013
@@ -328,6 +328,8 @@
 	unsigned int send_pai;
 	/*! Do we send Remote-Party-ID headers to this endpoint? */
 	unsigned int send_rpid;
+	/*! Do we add Diversion headers to applicable outgoing requests/responses? */
+	unsigned int send_diversion;
 };
 
 /*!

Modified: team/kharwell/pimp_sip_diversion/res/res_sip/sip_configuration.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_sip_diversion/res/res_sip/sip_configuration.c?view=diff&rev=386331&r1=386330&r2=386331
==============================================================================
--- team/kharwell/pimp_sip_diversion/res/res_sip/sip_configuration.c (original)
+++ team/kharwell/pimp_sip_diversion/res/res_sip/sip_configuration.c Mon Apr 22 18:12:48 2013
@@ -349,6 +349,7 @@
 	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "trust_id_outbound", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, trust_id_outbound));
 	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "send_pai", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, send_pai));
 	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "send_rpid", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, send_rpid));
+	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "send_diversion", "yes", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, send_diversion));
 
 	if (ast_sip_initialize_sorcery_transport(sip_sorcery)) {
 		ast_log(LOG_ERROR, "Failed to register SIP transport support with sorcery\n");

Modified: team/kharwell/pimp_sip_diversion/res/res_sip_diversion.c
URL: http://svnview.digium.com/svn/asterisk/team/kharwell/pimp_sip_diversion/res/res_sip_diversion.c?view=diff&rev=386331&r1=386330&r2=386331
==============================================================================
--- team/kharwell/pimp_sip_diversion/res/res_sip_diversion.c (original)
+++ team/kharwell/pimp_sip_diversion/res/res_sip_diversion.c Mon Apr 22 18:12:48 2013
@@ -37,7 +37,7 @@
 
 #define DIV_HDR_MAX_SIZE 256
 
-static const pj_str_t diversion_name = { "Diversion", 8 };
+static const pj_str_t diversion_name = { "Diversion", 9 };
 
 /*! \brief Diversion header reasons
  *
@@ -122,12 +122,13 @@
 {
 	ast_free(*dst);
 	*dst = ast_malloc(pj_strlen(src) + 1);
-	ast_copy_pj_str(*dst, src, pj_strlen(src));
+	ast_copy_pj_str(*dst, src, pj_strlen(src) + 1);
 }
 
 static void set_redirecting_id(pjsip_name_addr *uri, struct ast_party_id *data,
 			       struct ast_set_party_id *update)
 {
+	pjsip_fromto_hdr *hdr = (pjsip_fromto_hdr *)uri;
 	pjsip_sip_uri *sip_uri = pjsip_uri_get_uri(uri->uri);
 
 	if (pj_strlen(&sip_uri->user)) {
@@ -142,12 +143,9 @@
 		set_redirecting_value(&data->name.str, &uri->display);
 	}
 
-	/* if (!ast_strlen_zero(p->cid_tag)) { */
-	/* 	ast_free(redirecting->from.tag); */
-	/* 	redirecting->from.tag = ast_strdup(p->cid_tag); */
-	/* 	ast_free(redirecting->to.tag); */
-	/* 	redirecting->to.tag = ast_strdup(p->cid_tag); */
-	/* } */
+	if (pj_strlen(&hdr->tag)) {
+		set_redirecting_value(&data->tag, &hdr->tag);
+	}
 }
 
 static void set_redirecting_reason(pjsip_name_addr *uri,
@@ -167,7 +165,7 @@
 }
 
 static void set_redirecting(struct ast_sip_session *session,
-			    pjsip_name_addr *div_uri,
+			    pjsip_name_addr *from_uri,
 			    pjsip_name_addr *to_uri)
 {
 	struct ast_party_redirecting data;
@@ -180,13 +178,21 @@
 	ast_party_redirecting_init(&data);
 	memset(&update, 0, sizeof(update));
 
-	set_redirecting_id(div_uri, &data.from, &update.from);
-	set_redirecting_id(to_uri, &data.to, &update.to);
-	set_redirecting_reason(div_uri, &data.reason);
+	set_redirecting_id(from_uri, &data.from, &update.from);
+
+	/* give priority to the session id */
+	if (session->id.number.valid) {
+		ast_party_id_copy(&data.to, &session->id);
+	} else {
+		set_redirecting_id(to_uri, &data.to, &update.to);
+	}
+
+	set_redirecting_reason(from_uri, &data.reason);
 
 	ast_set_party_id_all(&update.priv_orig);
 	ast_set_party_id_all(&update.priv_from);
 	ast_set_party_id_all(&update.priv_to);
+	++data.count;
 
 	ast_channel_set_redirecting(session->channel, &data, &update); /* ast_channel_queue_redirecting_update */
 	ast_party_redirecting_free(&data);
@@ -194,7 +200,6 @@
 
 static int diversion_incoming_request(struct ast_sip_session *session, pjsip_rx_data *rdata)
 {
-	/* check if diversion header is present, if so update channel's redirecting info */
 	pjsip_fromto_hdr *div_hdr = get_diversion_header(rdata);
 	
 	if (div_hdr) {
@@ -207,34 +212,20 @@
 
 static void diversion_incoming_response(struct ast_sip_session *session, pjsip_rx_data *rdata)
 {
-	/* check if diversion header is present, if so update channel's redirecting info */
-	/* if 3xx and not present then update channel redirect info */
 	struct pjsip_status_line status = rdata->msg_info.msg->line.status;
-	pjsip_fromto_hdr *div_hdr;
-
-	if (status.code != 302 || (!(div_hdr = get_diversion_header(rdata)))) {
+	pjsip_fromto_hdr *to_hdr;
+
+	if ((status.code != 302) && (status.code != 181)) {
 		return;
 	}
 
-	set_redirecting(session, (pjsip_name_addr*)div_hdr->uri,
-			(pjsip_name_addr*)PJSIP_MSG_TO_HDR(rdata->msg_info.msg)->uri);
-}
-
-static pjsip_fromto_hdr *create_hdr(pjsip_tx_data *tdata, const pj_str_t *hdr_name)
-{
-	pjsip_fromto_hdr *hdr;
-
-	/* if request base off 'msg line' otherwise use 'from' (e.g. response) */
-	pjsip_uri *base = tdata->msg->type == PJSIP_REQUEST_MSG ?
-		tdata->msg->line.req.uri : PJSIP_MSG_FROM_HDR(tdata->msg)->uri;
-
-	hdr = pjsip_from_hdr_create(tdata->pool);
-	hdr->type = PJSIP_H_OTHER;
-	pj_strdup(tdata->pool, &hdr->name, hdr_name);
-	hdr->sname.slen = 0;
-	hdr->uri = pjsip_uri_clone(tdata->pool, base);
-
-	return hdr;
+	/* use the diversion header, if not then default to the 'To' header */
+	if (!(to_hdr = get_diversion_header(rdata))) {
+		to_hdr = PJSIP_MSG_TO_HDR(rdata->msg_info.msg);
+	}
+
+	set_redirecting(session, (pjsip_name_addr*)PJSIP_MSG_FROM_HDR(
+				rdata->msg_info.msg)->uri, (pjsip_name_addr*)to_hdr->uri);
 }
 
 #define param_add(pool,list,pname,pvalue) \
@@ -246,28 +237,6 @@
 	    pj_list_insert_before(&list, param); \
 	} while (0)
 
-static pjsip_fromto_hdr *update_hdr(pjsip_tx_data *tdata, pjsip_fromto_hdr *hdr,
-				    struct ast_party_redirecting *data)
-{
-	pjsip_name_addr *name_addr = (pjsip_name_addr*)hdr;
-	pjsip_sip_uri *uri = pjsip_uri_get_uri(name_addr->uri);
-
-	struct ast_party_id *id = tdata->msg->type == PJSIP_REQUEST_MSG ?
-		&data->to : &data->from;
-
-	if (!id->number.valid || ast_strlen_zero(id->number.str)) {
-		return hdr;
-	}
-
-	pj_strdup2(tdata->pool, &name_addr->display, id->name.str);
-	pj_strdup2(tdata->pool, &uri->user, id->number.str);
-
-	param_add(tdata->pool, uri->other_param, "reason",
-		  (char*)reason_code_to_str(&data->reason));
-
-	return hdr;
-}
-
 /*!
  * \internal
  * \brief Adds diversion header information to an outbound SIP message
@@ -277,15 +246,47 @@
  */
 static void add_diversion_header(pjsip_tx_data *tdata, struct ast_party_redirecting *data)
 {
-	pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *)update_hdr(tdata,
-				  create_hdr(tdata, &diversion_name), data));
+	pjsip_uri *base;
+	pjsip_fromto_hdr *hdr;
+	pjsip_name_addr *name_addr;
+	pjsip_sip_uri *uri;
+	struct ast_party_id *id;
+
+	if (tdata->msg->type == PJSIP_REQUEST_MSG) {
+		id = &data->to;
+		base = PJSIP_MSG_FROM_HDR(tdata->msg)->uri;
+	} else {
+		id = &data->from;
+		base = tdata->msg->line.req.uri;
+	}
+
+	hdr = pjsip_from_hdr_create(tdata->pool);
+	hdr->type = PJSIP_H_OTHER;
+	pj_strdup(tdata->pool, &hdr->name, &diversion_name);
+	hdr->sname.slen = 0;
+
+	name_addr = pjsip_uri_clone(tdata->pool, base);
+	uri = pjsip_uri_get_uri(name_addr->uri);
+
+	if (!id->number.valid || ast_strlen_zero(id->number.str)) {
+		return;
+	}
+
+	pj_strdup2(tdata->pool, &name_addr->display, id->name.str);
+	pj_strdup2(tdata->pool, &uri->user, id->number.str);
+
+	param_add(tdata->pool, uri->other_param, "reason",
+		  (char*)reason_code_to_str(&data->reason));
+
+	hdr->uri = (pjsip_uri *) name_addr;
+	pjsip_msg_add_hdr(tdata->msg, (pjsip_hdr *)hdr);
 }
 
 static void get_redirecting_add_diversion(struct ast_sip_session *session, pjsip_tx_data *tdata)
 {
 	struct ast_party_redirecting *data;
 
-	if (session->channel && 
+	if (session->channel && session->endpoint->send_diversion &&
 	    (data = ast_channel_redirecting(session->channel))->count) {
 		add_diversion_header(tdata, data);
 	}
@@ -323,7 +324,8 @@
 
 static struct ast_sip_session_supplement diversion_supplement = {
 	.method = "INVITE",
-	.priority = AST_SIP_SESSION_SUPPLEMENT_PRIORITY_CHANNEL - 1000,
+	/* this supplement needs to be called after caller id */
+	.priority = AST_SIP_SESSION_SUPPLEMENT_PRIORITY_CHANNEL - 800,
 	.incoming_request = diversion_incoming_request,
 	.incoming_response = diversion_incoming_response,
 	.outgoing_request = diversion_outgoing_request,




More information about the asterisk-commits mailing list