summaryrefslogtreecommitdiff
path: root/res/ari/resource_channels.c
diff options
context:
space:
mode:
authorMatthew Jordan <mjordan@digium.com>2015-02-12 20:34:37 +0000
committerMatthew Jordan <mjordan@digium.com>2015-02-12 20:34:37 +0000
commit29f66b0429f4314e082bebcf0630b016b317cba3 (patch)
treeef1ca239afe19ed5ac43cee1bd46c4678393dd21 /res/ari/resource_channels.c
parent9d081ed06cc32380d541ce4cb317bc23c32dee56 (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 'res/ari/resource_channels.c')
-rw-r--r--res/ari/resource_channels.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/res/ari/resource_channels.c b/res/ari/resource_channels.c
index 24aabe588..67498af9f 100644
--- a/res/ari/resource_channels.c
+++ b/res/ari/resource_channels.c
@@ -156,6 +156,64 @@ void ast_ari_channels_continue_in_dialplan(
ast_ari_response_no_content(response);
}
+void ast_ari_channels_redirect(struct ast_variable *headers,
+ struct ast_ari_channels_redirect_args *args,
+ struct ast_ari_response *response)
+{
+ RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
+ RAII_VAR(struct ast_channel_snapshot *, chan_snapshot, NULL, ao2_cleanup);
+ char *tech;
+ char *resource;
+ int tech_len;
+
+ control = find_control(response, args->channel_id);
+ if (!control) {
+ return;
+ }
+
+ if (ast_strlen_zero(args->endpoint)) {
+ ast_ari_response_error(response, 400, "Not Found",
+ "Required parameter 'endpoint' not provided.");
+ return;
+ }
+
+ tech = ast_strdupa(args->endpoint);
+ if (!(resource = strchr(tech, '/')) || !(tech_len = resource - tech)) {
+ ast_ari_response_error(response, 422, "Unprocessable Entity",
+ "Endpoint parameter '%s' does not contain tech/resource", args->endpoint);
+ return;
+ }
+
+ *resource++ = '\0';
+ if (ast_strlen_zero(resource)) {
+ ast_ari_response_error(response, 422, "Unprocessable Entity",
+ "No resource provided in endpoint parameter '%s'", args->endpoint);
+ return;
+ }
+
+ chan_snapshot = ast_channel_snapshot_get_latest(args->channel_id);
+ if (!chan_snapshot) {
+ ast_ari_response_error(response, 500, "Internal Server Error",
+ "Unable to find channel snapshot for '%s'", args->channel_id);
+ return;
+ }
+
+ if (strncasecmp(chan_snapshot->type, tech, tech_len)) {
+ ast_ari_response_error(response, 422, "Unprocessable Entity",
+ "Endpoint technology '%s' does not match channel technology '%s'",
+ tech, chan_snapshot->type);
+ return;
+ }
+
+ if (stasis_app_control_redirect(control, resource)) {
+ ast_ari_response_error(response, 500, "Internal Server Error",
+ "Failed to redirect channel");
+ return;
+ }
+
+ ast_ari_response_no_content(response);
+}
+
void ast_ari_channels_answer(struct ast_variable *headers,
struct ast_ari_channels_answer_args *args,
struct ast_ari_response *response)