ARI: Implement channel dial.

This creates a new outbound channel, and bridges it to a channel already in
the Stasis application.

(closes issue ASTERISK-21620)

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


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393326 65c4cc65-6c06-0410-ace0-fbb531ad65f3
changes/78/78/1
Jason Parker 12 years ago
parent f306dbd841
commit f41faf0b7d

@ -136,6 +136,20 @@ struct stasis_app_control *stasis_app_control_find_by_channel_id(
const char *stasis_app_control_get_channel_id(
const struct stasis_app_control *control);
/*!
* \brief Dial an endpoint and bridge it to a channel in \c res_stasis
*
* If the channel is no longer in \c res_stasis, this function does nothing.
*
* \param control Control for \c res_stasis
* \param endpoint The endpoint to dial.
* \param timeout The amount of time to wait for answer, before giving up.
*
* \return 0 for success
* \return -1 for error.
*/
int stasis_app_control_dial(struct stasis_app_control *control, const char *endpoint, int timeout);
/*!
* \brief Exit \c res_stasis and continue execution in the dialplan.
*

@ -170,6 +170,9 @@ static void stasis_http_dial_cb(
if (strcmp(i->name, "context") == 0) {
args.context = (i->value);
} else
if (strcmp(i->name, "timeout") == 0) {
args.timeout = atoi(i->value);
} else
{}
}
for (i = path_vars; i; i = i->next) {

@ -31,7 +31,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "command.h"
#include "control.h"
#include "asterisk/dial.h"
#include "asterisk/bridging.h"
#include "asterisk/bridging_basic.h"
#include "asterisk/bridging_features.h"
#include "asterisk/pbx.h"
@ -86,6 +88,80 @@ static struct stasis_app_command *exec_command(
return command;
}
struct stasis_app_control_dial_data {
char endpoint[AST_CHANNEL_NAME];
int timeout;
};
static void *app_control_dial(struct stasis_app_control *control,
struct ast_channel *chan, void *data)
{
RAII_VAR(struct ast_dial *, dial, ast_dial_create(), ast_dial_destroy);
RAII_VAR(struct stasis_app_control_dial_data *, dial_data, data, ast_free);
enum ast_dial_result res;
char *tech, *resource;
struct ast_channel *new_chan;
struct ast_bridge *bridge;
tech = dial_data->endpoint;
if (!(resource = strchr(tech, '/'))) {
return NULL;
}
*resource++ = '\0';
if (!dial) {
ast_log(LOG_ERROR, "Failed to create dialing structure.\n");
return NULL;
}
if (ast_dial_append(dial, tech, resource) < 0) {
ast_log(LOG_ERROR, "Failed to add %s/%s to dialing structure.\n", tech, resource);
return NULL;
}
ast_dial_set_global_timeout(dial, dial_data->timeout);
res = ast_dial_run(dial, NULL, 0);
if (res != AST_DIAL_RESULT_ANSWERED || !(new_chan = ast_dial_answered_steal(dial))) {
return NULL;
}
if (!(bridge = ast_bridge_basic_new())) {
ast_log(LOG_ERROR, "Failed to create basic bridge.\n");
return NULL;
}
ast_bridge_impart(bridge, new_chan, NULL, NULL, 1);
stasis_app_control_add_channel_to_bridge(control, bridge);
return NULL;
}
int stasis_app_control_dial(struct stasis_app_control *control, const char *endpoint, int timeout)
{
struct stasis_app_control_dial_data *dial_data;
if (!(dial_data = ast_calloc(1, sizeof(*dial_data)))) {
return -1;
}
ast_copy_string(dial_data->endpoint, endpoint, sizeof(dial_data->endpoint));
if (timeout > 0) {
dial_data->timeout = timeout * 1000;
} else if (timeout == -1) {
dial_data->timeout = -1;
} else {
dial_data->timeout = 30000;
}
stasis_app_send_command_async(control, app_control_dial, dial_data);
return 0;
}
int control_is_done(struct stasis_app_control *control)
{
/* Called from stasis_app_exec thread; no lock needed */

@ -34,6 +34,8 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/file.h"
#include "asterisk/pbx.h"
#include "asterisk/dial.h"
#include "asterisk/bridging.h"
#include "asterisk/callerid.h"
#include "asterisk/stasis_app.h"
#include "asterisk/stasis_app_playback.h"
@ -80,7 +82,19 @@ static struct stasis_app_control *find_control(
void stasis_http_dial(struct ast_variable *headers, struct ast_dial_args *args, struct stasis_http_response *response)
{
ast_log(LOG_ERROR, "TODO: stasis_http_dial\n");
struct stasis_app_control *control;
control = find_control(response, args->channel_id);
if (control == NULL) {
return;
}
if (stasis_app_control_dial(control, args->endpoint, args->timeout)) {
stasis_http_response_alloc_failed(response);
return;
}
stasis_http_response_no_content(response);
}
void stasis_http_continue_in_dialplan(

@ -113,6 +113,8 @@ struct ast_dial_args {
const char *extension;
/*! \brief When routing via dialplan, the context use. If omitted, uses 'default' */
const char *context;
/*! \brief Timeout (in seconds) before giving up dialing, or -1 for no timeout. */
int timeout;
};
/*!
* \brief Create a new channel (originate) and bridge to this channel.

@ -183,6 +183,15 @@
"required": false,
"allowMultiple": false,
"dataType": "string"
},
{
"name": "timeout",
"description": "Timeout (in seconds) before giving up dialing, or -1 for no timeout.",
"paramType": "query",
"required": false,
"allowMultiple": false,
"dataType": "int",
"defaultValue": 30
}
],
"errorResponses": [

Loading…
Cancel
Save