mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-22 13:25:17 +00:00
Change ARI originate to also allow dialing an exten/context/priority.
The old way didn't make much sense, so some of the fields were repurposed. (closes issue ASTERISK-21658) Review: https://reviewboard.asterisk.org/r/2626/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393144 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -83,11 +83,8 @@ static void stasis_http_originate_cb(
|
|||||||
if (strcmp(i->name, "context") == 0) {
|
if (strcmp(i->name, "context") == 0) {
|
||||||
args.context = (i->value);
|
args.context = (i->value);
|
||||||
} else
|
} else
|
||||||
if (strcmp(i->name, "callerId") == 0) {
|
if (strcmp(i->name, "priority") == 0) {
|
||||||
args.caller_id = (i->value);
|
args.priority = atol(i->value);
|
||||||
} else
|
|
||||||
if (strcmp(i->name, "timeout") == 0) {
|
|
||||||
args.timeout = atoi(i->value);
|
|
||||||
} else
|
} else
|
||||||
if (strcmp(i->name, "app") == 0) {
|
if (strcmp(i->name, "app") == 0) {
|
||||||
args.app = (i->value);
|
args.app = (i->value);
|
||||||
@@ -95,6 +92,12 @@ static void stasis_http_originate_cb(
|
|||||||
if (strcmp(i->name, "appArgs") == 0) {
|
if (strcmp(i->name, "appArgs") == 0) {
|
||||||
args.app_args = (i->value);
|
args.app_args = (i->value);
|
||||||
} else
|
} else
|
||||||
|
if (strcmp(i->name, "callerId") == 0) {
|
||||||
|
args.caller_id = (i->value);
|
||||||
|
} else
|
||||||
|
if (strcmp(i->name, "timeout") == 0) {
|
||||||
|
args.timeout = atoi(i->value);
|
||||||
|
} else
|
||||||
{}
|
{}
|
||||||
}
|
}
|
||||||
stasis_http_originate(headers, &args, response);
|
stasis_http_originate(headers, &args, response);
|
||||||
|
@@ -320,24 +320,31 @@ void stasis_http_originate(struct ast_variable *headers,
|
|||||||
struct ast_originate_args *args,
|
struct ast_originate_args *args,
|
||||||
struct stasis_http_response *response)
|
struct stasis_http_response *response)
|
||||||
{
|
{
|
||||||
const char *dialtech = NULL;
|
char *dialtech;
|
||||||
char dialdevice[AST_CHANNEL_NAME];
|
char dialdevice[AST_CHANNEL_NAME];
|
||||||
char *caller_id = NULL;
|
char *caller_id = NULL;
|
||||||
char *cid_num = NULL;
|
char *cid_num = NULL;
|
||||||
char *cid_name = NULL;
|
char *cid_name = NULL;
|
||||||
int timeout = 30000;
|
int timeout = 30000;
|
||||||
|
|
||||||
const char *app = "Stasis";
|
char *stuff;
|
||||||
RAII_VAR(struct ast_str *, appdata, ast_str_create(64), ast_free);
|
|
||||||
|
|
||||||
if (!appdata) {
|
if (ast_strlen_zero(args->endpoint)) {
|
||||||
stasis_http_response_alloc_failed(response);
|
stasis_http_response_error(response, 400, "Bad Request",
|
||||||
|
"Endpoint must be specified");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ast_str_set(&appdata, 0, "%s", args->app);
|
dialtech = ast_strdupa(args->endpoint);
|
||||||
if (!ast_strlen_zero(args->app_args)) {
|
if ((stuff = strchr(dialtech, '/'))) {
|
||||||
ast_str_append(&appdata, 0, ",%s", args->app_args);
|
*stuff++ = '\0';
|
||||||
|
ast_copy_string(dialdevice, stuff, sizeof(dialdevice));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ast_strlen_zero(dialtech) || ast_strlen_zero(dialdevice)) {
|
||||||
|
stasis_http_response_error(response, 400, "Bad Request",
|
||||||
|
"Invalid endpoint specified");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args->timeout > 0) {
|
if (args->timeout > 0) {
|
||||||
@@ -346,27 +353,6 @@ void stasis_http_originate(struct ast_variable *headers,
|
|||||||
timeout = -1;
|
timeout = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ast_strlen_zero(args->endpoint)) {
|
|
||||||
char *tmp = ast_strdupa(args->endpoint);
|
|
||||||
char *stuff;
|
|
||||||
|
|
||||||
if ((stuff = strchr(tmp, '/'))) {
|
|
||||||
*stuff++ = '\0';
|
|
||||||
dialtech = tmp;
|
|
||||||
ast_copy_string(dialdevice, stuff, sizeof(dialdevice));
|
|
||||||
}
|
|
||||||
} else if (!ast_strlen_zero(args->extension) && !ast_strlen_zero(args->context)) {
|
|
||||||
dialtech = "Local";
|
|
||||||
snprintf(dialdevice, sizeof(dialdevice), "%s@%s", args->extension, args->context);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ast_strlen_zero(dialtech) || ast_strlen_zero(dialdevice)) {
|
|
||||||
stasis_http_response_error(
|
|
||||||
response, 500, "Internal server error",
|
|
||||||
"Invalid endpoint or extension and context specified");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ast_strlen_zero(args->caller_id)) {
|
if (!ast_strlen_zero(args->caller_id)) {
|
||||||
caller_id = ast_strdupa(args->caller_id);
|
caller_id = ast_strdupa(args->caller_id);
|
||||||
ast_callerid_parse(caller_id, &cid_name, &cid_num);
|
ast_callerid_parse(caller_id, &cid_name, &cid_num);
|
||||||
@@ -376,11 +362,35 @@ void stasis_http_originate(struct ast_variable *headers,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ast_debug(1, "Dialing %s/%s\n", dialtech, dialdevice);
|
if (!ast_strlen_zero(args->app)) {
|
||||||
|
const char *app = "Stasis";
|
||||||
|
|
||||||
/* originate a channel, putting it into an application */
|
RAII_VAR(struct ast_str *, appdata, ast_str_create(64), ast_free);
|
||||||
if (ast_pbx_outgoing_app(dialtech, NULL, dialdevice, timeout, app, ast_str_buffer(appdata), NULL, 0, cid_num, cid_name, NULL, NULL, NULL)) {
|
|
||||||
stasis_http_response_alloc_failed(response);
|
if (!appdata) {
|
||||||
|
stasis_http_response_alloc_failed(response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ast_str_set(&appdata, 0, "%s", args->app);
|
||||||
|
if (!ast_strlen_zero(args->app_args)) {
|
||||||
|
ast_str_append(&appdata, 0, ",%s", args->app_args);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 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)) {
|
||||||
|
stasis_http_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)) {
|
||||||
|
stasis_http_response_alloc_failed(response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
stasis_http_response_error(response, 400, "Bad Request",
|
||||||
|
"Application or extension must be specified");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -52,20 +52,22 @@ struct ast_get_channels_args {
|
|||||||
void stasis_http_get_channels(struct ast_variable *headers, struct ast_get_channels_args *args, struct stasis_http_response *response);
|
void stasis_http_get_channels(struct ast_variable *headers, struct ast_get_channels_args *args, struct stasis_http_response *response);
|
||||||
/*! \brief Argument struct for stasis_http_originate() */
|
/*! \brief Argument struct for stasis_http_originate() */
|
||||||
struct ast_originate_args {
|
struct ast_originate_args {
|
||||||
/*! \brief Endpoint to call. If not specified, originate is routed via dialplan */
|
/*! \brief Endpoint to call. */
|
||||||
const char *endpoint;
|
const char *endpoint;
|
||||||
/*! \brief When routing via dialplan, the extension to dial */
|
/*! \brief The extension to dial after the endpoint answers */
|
||||||
const char *extension;
|
const char *extension;
|
||||||
/*! \brief When routing via dialplan, the context to use. If omitted, uses 'default' */
|
/*! \brief The context to dial after the endpoint answers. If omitted, uses 'default' */
|
||||||
const char *context;
|
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. */
|
||||||
|
const char *app;
|
||||||
|
/*! \brief The application arguments to pass to the Stasis application. */
|
||||||
|
const char *app_args;
|
||||||
/*! \brief CallerID to use when dialing the endpoint or extension. */
|
/*! \brief CallerID to use when dialing the endpoint or extension. */
|
||||||
const char *caller_id;
|
const char *caller_id;
|
||||||
/*! \brief Timeout (in seconds) before giving up dialing, or -1 for no timeout. */
|
/*! \brief Timeout (in seconds) before giving up dialing, or -1 for no timeout. */
|
||||||
int timeout;
|
int timeout;
|
||||||
/*! \brief Application name to pass to the Stasis application. */
|
|
||||||
const char *app;
|
|
||||||
/*! \brief Application arguments to pass to the Stasis application. */
|
|
||||||
const char *app_args;
|
|
||||||
};
|
};
|
||||||
/*!
|
/*!
|
||||||
* \brief Create a new channel (originate).
|
* \brief Create a new channel (originate).
|
||||||
|
@@ -25,15 +25,15 @@
|
|||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"name": "endpoint",
|
"name": "endpoint",
|
||||||
"description": "Endpoint to call. If not specified, originate is routed via dialplan",
|
"description": "Endpoint to call.",
|
||||||
"paramType": "query",
|
"paramType": "query",
|
||||||
"required": false,
|
"required": true,
|
||||||
"allowMultiple": false,
|
"allowMultiple": false,
|
||||||
"dataType": "string"
|
"dataType": "string"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "extension",
|
"name": "extension",
|
||||||
"description": "When routing via dialplan, the extension to dial",
|
"description": "The extension to dial after the endpoint answers",
|
||||||
"paramType": "query",
|
"paramType": "query",
|
||||||
"required": false,
|
"required": false,
|
||||||
"allowMultiple": false,
|
"allowMultiple": false,
|
||||||
@@ -41,7 +41,31 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "context",
|
"name": "context",
|
||||||
"description": "When routing via dialplan, the context to use. If omitted, uses 'default'",
|
"description": "The context to dial after the endpoint answers. If omitted, uses 'default'",
|
||||||
|
"paramType": "query",
|
||||||
|
"required": false,
|
||||||
|
"allowMultiple": false,
|
||||||
|
"dataType": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "priority",
|
||||||
|
"description": "The priority to dial after the endpoint answers. If omitted, uses 1",
|
||||||
|
"paramType": "query",
|
||||||
|
"required": false,
|
||||||
|
"allowMultiple": false,
|
||||||
|
"dataType": "long"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "app",
|
||||||
|
"description": "The application name to pass to the Stasis application.",
|
||||||
|
"paramType": "query",
|
||||||
|
"required": false,
|
||||||
|
"allowMultiple": false,
|
||||||
|
"dataType": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "appArgs",
|
||||||
|
"description": "The application arguments to pass to the Stasis application.",
|
||||||
"paramType": "query",
|
"paramType": "query",
|
||||||
"required": false,
|
"required": false,
|
||||||
"allowMultiple": false,
|
"allowMultiple": false,
|
||||||
@@ -63,22 +87,6 @@
|
|||||||
"allowMultiple": false,
|
"allowMultiple": false,
|
||||||
"dataType": "int",
|
"dataType": "int",
|
||||||
"defaultValue": 30
|
"defaultValue": 30
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "app",
|
|
||||||
"description": "Application name to pass to the Stasis application.",
|
|
||||||
"paramType": "query",
|
|
||||||
"required": true,
|
|
||||||
"allowMultiple": false,
|
|
||||||
"dataType": "string"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "appArgs",
|
|
||||||
"description": "Application arguments to pass to the Stasis application.",
|
|
||||||
"paramType": "query",
|
|
||||||
"required": false,
|
|
||||||
"allowMultiple": false,
|
|
||||||
"dataType": "string"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user