diff options
author | Matthew Jordan <mjordan@digium.com> | 2015-02-12 20:34:37 +0000 |
---|---|---|
committer | Matthew Jordan <mjordan@digium.com> | 2015-02-12 20:34:37 +0000 |
commit | 29f66b0429f4314e082bebcf0630b016b317cba3 (patch) | |
tree | ef1ca239afe19ed5ac43cee1bd46c4678393dd21 /channels | |
parent | 9d081ed06cc32380d541ce4cb317bc23c32dee56 (diff) |
ARI/PJSIP: Add the ability to redirect (transfer) a channel in a Stasis app
This patch adds a new feature to ARI to redirect a channel to another server,
and fixes a few bugs in PJSIP's handling of the Transfer dialplan
application/ARI redirect capability.
*New Feature*
A new operation has been added to the ARI channels resource, redirect. With
this, a channel in a Stasis application can be redirected to another endpoint
of the same underlying channel technology.
*Bug fixes*
In the process of writing this new feature, two bugs were fixed in the PJSIP
stack:
(1) The existing .transfer channel callback had the limitation that it could
only transfer channels to a SIP URI, i.e., you had to pass
'PJSIP/sip:foo@my_provider.com' to the dialplan application. While this is
still supported, it is somewhat unintuitive - particularly in a world full
of endpoints. As such, we now also support specifying the PJSIP endpoint to
transfer to.
(2) res_pjsip_multihomed was, unfortunately, trying to 'help' a 302 redirect by
updating its Contact header. Alas, that resulted in the forwarding
destination set by the dialplan application/ARI resource/whatever being
rewritten with very incorrect information. Hence, we now don't bother
updating an outgoing response if it is a 302. Since this took a looong time
to find, some additional debug statements have been added to those modules
that update the Contact headers.
Review: https://reviewboard.asterisk.org/r/4316/
ASTERISK-24015 #close
Reported by: Private Name
ASTERISK-24703 #close
Reported by: Matt Jordan
........
Merged revisions 431717 from http://svn.asterisk.org/svn/asterisk/branches/13
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@431718 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'channels')
-rw-r--r-- | channels/chan_pjsip.c | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c index 3e2e9e22e..eaeb9bc0a 100644 --- a/channels/chan_pjsip.c +++ b/channels/chan_pjsip.c @@ -1378,6 +1378,8 @@ static void transfer_redirect(struct ast_sip_session *session, const char *targe pj_str_t tmp; if (pjsip_inv_end_session(session->inv_session, 302, NULL, &packet) != PJ_SUCCESS) { + ast_log(LOG_WARNING, "Failed to redirect PJSIP session for channel %s\n", + ast_channel_name(session->channel)); message = AST_TRANSFER_FAILED; ast_queue_control_data(session->channel, AST_CONTROL_TRANSFER, &message, sizeof(message)); @@ -1390,6 +1392,8 @@ static void transfer_redirect(struct ast_sip_session *session, const char *targe pj_strdup2_with_null(packet->pool, &tmp, target); if (!(contact->uri = pjsip_parse_uri(packet->pool, tmp.ptr, tmp.slen, PJSIP_PARSE_URI_AS_NAMEADDR))) { + ast_log(LOG_WARNING, "Failed to parse destination URI '%s' for channel %s\n", + target, ast_channel_name(session->channel)); message = AST_TRANSFER_FAILED; ast_queue_control_data(session->channel, AST_CONTROL_TRANSFER, &message, sizeof(message)); pjsip_tx_data_dec_ref(packet); @@ -1431,14 +1435,28 @@ static void transfer_refer(struct ast_sip_session *session, const char *target) static int transfer(void *data) { struct transfer_data *trnf_data = data; + struct ast_sip_endpoint *endpoint = NULL; + struct ast_sip_contact *contact = NULL; + const char *target = trnf_data->target; + + /* See if we have an endpoint; if so, use its contact */ + endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", target); + if (endpoint) { + contact = ast_sip_location_retrieve_contact_from_aor_list(endpoint->aors); + if (contact && !ast_strlen_zero(contact->uri)) { + target = contact->uri; + } + } if (ast_channel_state(trnf_data->session->channel) == AST_STATE_RING) { - transfer_redirect(trnf_data->session, trnf_data->target); + transfer_redirect(trnf_data->session, target); } else { - transfer_refer(trnf_data->session, trnf_data->target); + transfer_refer(trnf_data->session, target); } ao2_ref(trnf_data, -1); + ao2_cleanup(endpoint); + ao2_cleanup(contact); return 0; } |