[svn-commits] rmudgett: branch 12 r421400 - in /branches/12: channels/ res/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Aug 19 11:07:01 CDT 2014


Author: rmudgett
Date: Tue Aug 19 11:06:58 2014
New Revision: 421400

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=421400
Log:
chan_pjsip: Fix attended transfer connected line name update.

A calls B
B answers
B SIP attended transfers to C
C answers, B and C can see each other's connected line information
B completes the transfer
A has number but no name connected line information about C
  while C has the full information about A

I examined the incoming and outgoing party id information handling of
chan_pjsip and found several issues:

* Fixed ast_sip_session_create_outgoing() not setting up the configured
endpoint id as the new channel's caller id.  This is why party A got
default connected line information.

* Made update_initial_connected_line() use the channel's CALLERID(id)
information.  The core, app_dial, or predial routine may have filled in or
changed the endpoint caller id information.

* Fixed chan_pjsip_new() not setting the full party id information
available on the caller id and ANI party id.  This includes the configured
callerid_tag string and other party id fields.

* Fixed accessing channel party id information without the channel lock
held.

* Fixed using the effective connected line id without doing a deep copy
outside of holding the channel lock.  Shallow copy string pointers can
become stale if the channel lock is not held.

* Made queue_connected_line_update() also update the channel's
CALLERID(id) information.  Moving the channel to another bridge would need
the information there for the new bridge peer.

* Fixed off nominal memory leak in update_incoming_connected_line().

* Added pjsip.conf callerid_tag string to party id information from
enabled trust_inbound endpoint in caller_id_incoming_request().

AFS-98 #close
Reported by: Mark Michelson

Review: https://reviewboard.asterisk.org/r/3913/

Modified:
    branches/12/channels/chan_pjsip.c
    branches/12/res/res_pjsip_caller_id.c
    branches/12/res/res_pjsip_session.c

Modified: branches/12/channels/chan_pjsip.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/channels/chan_pjsip.c?view=diff&rev=421400&r1=421399&r2=421400
==============================================================================
--- branches/12/channels/chan_pjsip.c (original)
+++ branches/12/channels/chan_pjsip.c Tue Aug 19 11:06:58 2014
@@ -374,11 +374,13 @@
 		return NULL;
 	}
 
-	chan = ast_channel_alloc_with_endpoint(1, state, S_OR(session->id.number.str, ""),
-	                         S_OR(session->id.name.str, ""), session->endpoint->accountcode, "",
-	                         "", assignedids, requestor, 0, session->endpoint->persistent,
-	                         "PJSIP/%s-%08x", ast_sorcery_object_get_id(session->endpoint),
-	                         (unsigned)ast_atomic_fetchadd_int((int *)&chan_idx, +1));
+	chan = ast_channel_alloc_with_endpoint(1, state,
+		S_COR(session->id.number.valid, session->id.number.str, ""),
+		S_COR(session->id.name.valid, session->id.name.str, ""),
+		session->endpoint->accountcode, "", "", assignedids, requestor, 0,
+		session->endpoint->persistent, "PJSIP/%s-%08x",
+		ast_sorcery_object_get_id(session->endpoint),
+		(unsigned) ast_atomic_fetchadd_int((int *) &chan_idx, +1));
 	if (!chan) {
 		return NULL;
 	}
@@ -418,6 +420,9 @@
 	}
 
 	ast_channel_adsicpe_set(chan, AST_ADSI_UNAVAILABLE);
+
+	ast_party_id_copy(&ast_channel_caller(chan)->id, &session->id);
+	ast_party_id_copy(&ast_channel_caller(chan)->ani, &session->id);
 
 	ast_channel_context_set(chan, session->endpoint->context);
 	ast_channel_exten_set(chan, S_OR(exten, "s"));
@@ -1023,7 +1028,6 @@
 static int update_connected_line_information(void *data)
 {
 	RAII_VAR(struct ast_sip_session *, session, data, ao2_cleanup);
-	struct ast_party_id connected_id;
 
 	if ((ast_channel_state(session->channel) != AST_STATE_UP) && (session->inv_session->role == PJSIP_UAS_ROLE)) {
 		int response_code = 0;
@@ -1043,12 +1047,20 @@
 		}
 	} else {
 		enum ast_sip_session_refresh_method method = session->endpoint->id.refresh_method;
+		struct ast_party_id connected_id;
 
 		if (session->inv_session->invite_tsx && (session->inv_session->options & PJSIP_INV_SUPPORT_UPDATE)) {
 			method = AST_SIP_SESSION_REFRESH_METHOD_UPDATE;
 		}
 
+		/*
+		 * We can get away with a shallow copy here because we are
+		 * not looking at strings.
+		 */
+		ast_channel_lock(session->channel);
 		connected_id = ast_channel_connected_effective_id(session->channel);
+		ast_channel_unlock(session->channel);
+
 		if ((session->endpoint->id.send_pai || session->endpoint->id.send_rpid) &&
 		    (session->endpoint->id.trust_outbound ||
 		     ((connected_id.name.presentation & AST_PRES_RESTRICTION) == AST_PRES_ALLOWED &&
@@ -1475,33 +1487,26 @@
 static void update_initial_connected_line(struct ast_sip_session *session)
 {
 	struct ast_party_connected_line connected;
-	struct ast_set_party_connected_line update_connected;
-	struct ast_sip_endpoint_id_configuration *id = &session->endpoint->id;
-
-	if (!id->self.number.valid && !id->self.name.valid) {
+
+	/*
+	 * Use the channel CALLERID() as the initial connected line data.
+	 * The core or a predial handler may have supplied missing values
+	 * from the session->endpoint->id.self about who we are calling.
+	 */
+	ast_channel_lock(session->channel);
+	ast_party_id_copy(&session->id, &ast_channel_caller(session->channel)->id);
+	ast_channel_unlock(session->channel);
+
+	/* Supply initial connected line information if available. */
+	if (!session->id.number.valid && !session->id.name.valid) {
 		return;
 	}
 
-	/* Supply initial connected line information if available. */
-	memset(&update_connected, 0, sizeof(update_connected));
 	ast_party_connected_line_init(&connected);
-	connected.id.number = id->self.number;
-	connected.id.name = id->self.name;
-	connected.id.tag = id->self.tag;
+	connected.id = session->id;
 	connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
 
-	if (connected.id.number.valid) {
-		update_connected.id.number = 1;
-	}
-
-	if (connected.id.name.valid) {
-		update_connected.id.name = 1;
-	}
-
-	/* Invalidate any earlier private connected id representation */
-	ast_set_party_id_all(&update_connected.priv);
-
-	ast_channel_queue_connected_line_update(session->channel, &connected, &update_connected);
+	ast_channel_queue_connected_line_update(session->channel, &connected, NULL);
 }
 
 static int call(void *data)
@@ -1532,7 +1537,7 @@
 
 	ao2_ref(channel, +1);
 	if (ast_sip_push_task(channel->session->serializer, call, channel)) {
-		ast_log(LOG_WARNING, "Error attempting to place outbound call to call '%s'\n", dest);
+		ast_log(LOG_WARNING, "Error attempting to place outbound call to '%s'\n", dest);
 		ao2_cleanup(channel);
 		return -1;
 	}

Modified: branches/12/res/res_pjsip_caller_id.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/res_pjsip_caller_id.c?view=diff&rev=421400&r1=421399&r2=421400
==============================================================================
--- branches/12/res/res_pjsip_caller_id.c (original)
+++ branches/12/res/res_pjsip_caller_id.c Tue Aug 19 11:06:58 2014
@@ -281,21 +281,26 @@
 static void queue_connected_line_update(struct ast_sip_session *session, const struct ast_party_id *id)
 {
 	struct ast_party_connected_line connected;
-	struct ast_set_party_connected_line update_connected;
-
+	struct ast_party_caller caller;
+
+	/* Fill connected line information */
 	ast_party_connected_line_init(&connected);
-	ast_party_id_copy(&connected.id, 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.id = *id;
+	connected.id.tag = session->endpoint->id.self.tag;
 	connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER;
+
+	/* Save to channel driver copy */
 	ast_party_id_copy(&session->id, &connected.id);
-	ast_channel_queue_connected_line_update(session->channel, &connected, &update_connected);
-
-	ast_party_connected_line_free(&connected);
+
+	/* Update our channel CALLERID() */
+	ast_party_caller_init(&caller);
+	caller.id = connected.id;
+	caller.ani = connected.id;
+	caller.ani2 = ast_channel_caller(session->channel)->ani2;
+	ast_channel_set_caller_event(session->channel, &caller, NULL);
+
+	/* Tell peer about the new connected line information. */
+	ast_channel_queue_connected_line_update(session->channel, &connected, NULL);
 }
 
 /*!
@@ -318,13 +323,11 @@
 	}
 
 	ast_party_id_init(&id);
-	if (set_id_from_pai(rdata, &id) && set_id_from_rpid(rdata, &id)) {
-		return;
-	}
-	if (should_queue_connected_line_update(session, &id)) {
-		queue_connected_line_update(session, &id);
-	}
-
+	if (!set_id_from_pai(rdata, &id) || !set_id_from_rpid(rdata, &id)) {
+		if (should_queue_connected_line_update(session, &id)) {
+			queue_connected_line_update(session, &id);
+		}
+	}
 	ast_party_id_free(&id);
 }
 
@@ -343,9 +346,15 @@
 static int caller_id_incoming_request(struct ast_sip_session *session, pjsip_rx_data *rdata)
 {
 	if (session->inv_session->state < PJSIP_INV_STATE_CONFIRMED) {
-		/* Initial inbound INVITE. Set the session ID directly */
-		if (session->endpoint->id.trust_inbound &&
-				(!set_id_from_pai(rdata, &session->id) || !set_id_from_rpid(rdata, &session->id))) {
+		/*
+		 * Initial inbound INVITE.  Set the session ID directly
+		 * because the channel has not been created yet.
+		 */
+		if (session->endpoint->id.trust_inbound
+			&& (!set_id_from_pai(rdata, &session->id)
+				|| !set_id_from_rpid(rdata, &session->id))) {
+			ast_free(session->id.tag);
+			session->id.tag = ast_strdup(session->endpoint->id.self.tag);
 			return 0;
 		}
 		ast_party_id_copy(&session->id, &session->endpoint->id.self);
@@ -640,13 +649,20 @@
  */
 static void caller_id_outgoing_request(struct ast_sip_session *session, pjsip_tx_data *tdata)
 {
+	struct ast_party_id effective_id;
 	struct ast_party_id connected_id;
 
 	if (!session->channel) {
 		return;
 	}
 
-	connected_id = ast_channel_connected_effective_id(session->channel);
+	/* Must do a deep copy unless we hold the channel lock the entire time. */
+	ast_party_id_init(&connected_id);
+	ast_channel_lock(session->channel);
+	effective_id = ast_channel_connected_effective_id(session->channel);
+	ast_party_id_copy(&connected_id, &effective_id);
+	ast_channel_unlock(session->channel);
+
 	if (session->inv_session->state < PJSIP_INV_STATE_CONFIRMED &&
 			ast_strlen_zero(session->endpoint->fromuser) &&
 			(session->endpoint->id.trust_outbound ||
@@ -665,6 +681,7 @@
 		modify_id_header(dlg->pool, dlg->local.info, &connected_id);
 	}
 	add_id_headers(session, tdata, &connected_id);
+	ast_party_id_free(&connected_id);
 }
 
 /*!
@@ -678,13 +695,22 @@
  */
 static void caller_id_outgoing_response(struct ast_sip_session *session, pjsip_tx_data *tdata)
 {
+	struct ast_party_id effective_id;
 	struct ast_party_id connected_id;
 
 	if (!session->channel) {
 		return;
 	}
-	connected_id = ast_channel_connected_effective_id(session->channel);
+
+	/* Must do a deep copy unless we hold the channel lock the entire time. */
+	ast_party_id_init(&connected_id);
+	ast_channel_lock(session->channel);
+	effective_id = ast_channel_connected_effective_id(session->channel);
+	ast_party_id_copy(&connected_id, &effective_id);
+	ast_channel_unlock(session->channel);
+
 	add_id_headers(session, tdata, &connected_id);
+	ast_party_id_free(&connected_id);
 }
 
 static struct ast_sip_session_supplement caller_id_supplement = {

Modified: branches/12/res/res_pjsip_session.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/res_pjsip_session.c?view=diff&rev=421400&r1=421399&r2=421400
==============================================================================
--- branches/12/res/res_pjsip_session.c (original)
+++ branches/12/res/res_pjsip_session.c Tue Aug 19 11:06:58 2014
@@ -1272,6 +1272,7 @@
 		pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
 		return NULL;
 	}
+	ast_party_id_copy(&session->id, &endpoint->id.self);
 
 	if (!ast_format_cap_is_empty(req_caps)) {
 		ast_format_cap_copy(session->req_caps, session->endpoint->media.codecs);




More information about the svn-commits mailing list