From: Joshua Colp Date: Sat, 19 Oct 2013 14:43:41 +0000 (+0000) Subject: Return a channel snapshot when originating using ARI, and subscribe the Stasis applic... X-Git-Tag: 12.0.0-beta2~116 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=abcc1c0c15ddd40027c0ff46be17e4da49b7a324;p=thirdparty%2Fasterisk.git Return a channel snapshot when originating using ARI, and subscribe the Stasis application to it. This change allows a user of ARI to know what channel it has originated and also follow any progress. If a Stasis application is provided it will be automatically subscribed to the originated channel immediately. (closes issue ASTERISK-22485) Reported by: David Lee Review: https://reviewboard.asterisk.org/r/2910/ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/12@401281 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/main/pbx.c b/main/pbx.c index a5ac9100b1..c3fc85145a 100644 --- a/main/pbx.c +++ b/main/pbx.c @@ -10115,7 +10115,7 @@ static int pbx_outgoing_attempt(const char *type, struct ast_format_cap *cap, co } /* Wait for dialing to complete */ - if (channel || synchronous) { + if (synchronous) { if (channel && *channel) { ast_channel_unlock(*channel); } diff --git a/res/ari/resource_channels.c b/res/ari/resource_channels.c index aaf04a3f88..bdca21cdbf 100644 --- a/res/ari/resource_channels.c +++ b/res/ari/resource_channels.c @@ -585,6 +585,8 @@ void ast_ari_originate(struct ast_variable *headers, int timeout = 30000; char *stuff; + struct ast_channel *chan; + RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup); if (ast_strlen_zero(args->endpoint)) { ast_ari_response_error(response, 400, "Bad Request", @@ -635,13 +637,13 @@ void ast_ari_originate(struct ast_variable *headers, } /* originate a channel, putting it into an application */ - if (ast_pbx_outgoing_app(dialtech, NULL, dialdevice, timeout, app, ast_str_buffer(appdata), NULL, 0, cid_num, cid_name, NULL, NULL, NULL)) { + if (ast_pbx_outgoing_app(dialtech, NULL, dialdevice, timeout, app, ast_str_buffer(appdata), NULL, 0, cid_num, cid_name, NULL, NULL, &chan)) { ast_ari_response_alloc_failed(response); return; } } else if (!ast_strlen_zero(args->extension)) { /* originate a channel, sending it to an extension */ - if (ast_pbx_outgoing_exten(dialtech, NULL, dialdevice, timeout, S_OR(args->context, "default"), args->extension, args->priority ? args->priority : 1, NULL, 0, cid_num, cid_name, NULL, NULL, NULL, 0)) { + if (ast_pbx_outgoing_exten(dialtech, NULL, dialdevice, timeout, S_OR(args->context, "default"), args->extension, args->priority ? args->priority : 1, NULL, 0, cid_num, cid_name, NULL, NULL, &chan, 0)) { ast_ari_response_alloc_failed(response); return; } @@ -651,7 +653,20 @@ void ast_ari_originate(struct ast_variable *headers, return; } - ast_ari_response_no_content(response); + if (!ast_strlen_zero(args->app)) { + /* channel: + channel ID + null terminator */ + char uri[9 + strlen(ast_channel_uniqueid(chan))]; + const char *uris[1] = { uri, }; + + sprintf(uri, "channel:%s", ast_channel_uniqueid(chan)); + stasis_app_subscribe(args->app, uris, 1, NULL); + } + + snapshot = ast_channel_snapshot_create(chan); + ast_ari_response_ok(response, ast_channel_snapshot_to_json(snapshot)); + + ast_channel_unlock(chan); + ast_channel_unref(chan); } void ast_ari_get_channel_var(struct ast_variable *headers, struct ast_get_channel_var_args *args, struct ast_ari_response *response) diff --git a/res/ari/resource_channels.h b/res/ari/resource_channels.h index b7f1ef282f..a65bb981bc 100644 --- a/res/ari/resource_channels.h +++ b/res/ari/resource_channels.h @@ -60,7 +60,7 @@ struct ast_originate_args { const char *context; /*! \brief The priority to dial after the endpoint answers. If omitted, uses 1 */ long priority; - /*! \brief The application name to pass to the Stasis application. */ + /*! \brief The application that is subscribed to the originated channel, and passed to the Stasis application. */ const char *app; /*! \brief The application arguments to pass to the Stasis application. */ const char *app_args; @@ -72,7 +72,7 @@ struct ast_originate_args { /*! * \brief Create a new channel (originate). * - * The new channel is not created until the dialed party picks up. Not wanting to block this request indefinitely, this request returns immediately with a 204 No Content. When the channel is created, a StasisStart event is sent with the provided app and appArgs. In the event of a failure (timeout, busy, etc.), an OriginationFailed event is sent. + * The new channel is created immediately and a snapshot of it returned. If a Stasis application is provided it will be automatically subscribed to the originated channel for further events and updates. * * \param headers HTTP headers * \param args Swagger parameters diff --git a/res/res_ari_channels.c b/res/res_ari_channels.c index dced6d65af..af7f17df21 100644 --- a/res/res_ari_channels.c +++ b/res/res_ari_channels.c @@ -160,7 +160,7 @@ static void ast_ari_originate_cb( break; default: if (200 <= code && code <= 299) { - is_valid = ast_ari_validate_void( + is_valid = ast_ari_validate_channel( response->message); } else { ast_log(LOG_ERROR, "Invalid error response %d for /channels\n", code); diff --git a/rest-api/api-docs/channels.json b/rest-api/api-docs/channels.json index 40ccda7404..65cdb586dc 100644 --- a/rest-api/api-docs/channels.json +++ b/rest-api/api-docs/channels.json @@ -20,9 +20,9 @@ { "httpMethod": "POST", "summary": "Create a new channel (originate).", - "notes": "The new channel is not created until the dialed party picks up. Not wanting to block this request indefinitely, this request returns immediately with a 204 No Content. When the channel is created, a StasisStart event is sent with the provided app and appArgs. In the event of a failure (timeout, busy, etc.), an OriginationFailed event is sent.", + "notes": "The new channel is created immediately and a snapshot of it returned. If a Stasis application is provided it will be automatically subscribed to the originated channel for further events and updates.", "nickname": "originate", - "responseClass": "void", + "responseClass": "channel", "parameters": [ { "name": "endpoint", @@ -58,7 +58,7 @@ }, { "name": "app", - "description": "The application name to pass to the Stasis application.", + "description": "The application that is subscribed to the originated channel, and passed to the Stasis application.", "paramType": "query", "required": false, "allowMultiple": false,