From 3b5127ba6966679d4ee10ca756cdd065afbdfebc Mon Sep 17 00:00:00 2001 From: Richard Mudgett Date: Tue, 19 Aug 2014 16:11:38 +0000 Subject: 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/ ........ Merged revisions 421400 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@421403 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channels/chan_pjsip.c | 59 ++++++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 27 deletions(-) (limited to 'channels/chan_pjsip.c') diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c index c958f8086..ac7543c3e 100644 --- a/channels/chan_pjsip.c +++ b/channels/chan_pjsip.c @@ -381,11 +381,13 @@ static struct ast_channel *chan_pjsip_new(struct ast_sip_session *session, int s 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) { ao2_ref(caps, -1); return NULL; @@ -432,6 +434,9 @@ static struct ast_channel *chan_pjsip_new(struct ast_sip_session *session, int s 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")); ast_channel_priority_set(chan, 1); @@ -1042,7 +1047,6 @@ static int transmit_info_with_vidupdate(void *data) 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; @@ -1062,12 +1066,20 @@ static int update_connected_line_information(void *data) } } 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 && @@ -1492,33 +1504,26 @@ static int chan_pjsip_digit_end(struct ast_channel *ast, char digit, unsigned in 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) @@ -1549,7 +1554,7 @@ static int chan_pjsip_call(struct ast_channel *ast, const char *dest, int timeou 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; } -- cgit v1.2.3