mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-06 12:36:58 +00:00
Add the ability to continue and originate using priority labels.
With this patch, the following two ARI commands POST /channels POST /channels/{id}/continue Accept a new parameter, label, that can be used to continue to or originate to a priority label in the dialplan. Because this is adding a new parameter to ARI commands, the API version of ARI has been bumped from 1.6.0 to 1.7.0. This patch comes courtesy of Nir Simionovich from Greenfield Tech. Thanks! ASTERISK-24412 #close Reported by Nir Simionovich Review: https://reviewboard.asterisk.org/r/4285 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@430337 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
5
CHANGES
5
CHANGES
@@ -49,6 +49,11 @@ ARI
|
|||||||
* "language" (the default spoken language for the channel) is now included in
|
* "language" (the default spoken language for the channel) is now included in
|
||||||
the standard channel state output for suitable events.
|
the standard channel state output for suitable events.
|
||||||
|
|
||||||
|
* The POST channels/{id} operation and the POST channels/{id}/continue operation
|
||||||
|
now have a new "label" parameter. This allows for origination or continuation
|
||||||
|
to a labeled priority in the dialplan instead of requiring a specific priority
|
||||||
|
number. The ARI version has been bumped to 1.7.0 as a result.
|
||||||
|
|
||||||
AMI
|
AMI
|
||||||
------------------
|
------------------
|
||||||
* "Language" (the default spoken language for the channel) is now included in
|
* "Language" (the default spoken language for the channel) is now included in
|
||||||
|
@@ -91,6 +91,10 @@ void ast_ari_channels_continue_in_dialplan(
|
|||||||
struct ast_ari_response *response)
|
struct ast_ari_response *response)
|
||||||
{
|
{
|
||||||
RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
|
RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
|
||||||
|
RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
|
||||||
|
int ipri;
|
||||||
|
const char *context;
|
||||||
|
const char *exten;
|
||||||
|
|
||||||
ast_assert(response != NULL);
|
ast_assert(response != NULL);
|
||||||
|
|
||||||
@@ -99,7 +103,52 @@ void ast_ari_channels_continue_in_dialplan(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stasis_app_control_continue(control, args->context, args->extension, args->priority)) {
|
snapshot = stasis_app_control_get_snapshot(control);
|
||||||
|
if (!snapshot) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ast_strlen_zero(args->context)) {
|
||||||
|
context = snapshot->context;
|
||||||
|
exten = S_OR(args->extension, snapshot->exten);
|
||||||
|
} else {
|
||||||
|
context = args->context;
|
||||||
|
exten = S_OR(args->extension, "s");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ast_strlen_zero(args->label)) {
|
||||||
|
/* A label was provided in the request, use that */
|
||||||
|
|
||||||
|
if (sscanf(args->label, "%30d", &ipri) != 1) {
|
||||||
|
ipri = ast_findlabel_extension(NULL, context, exten, args->label, NULL);
|
||||||
|
if (ipri == -1) {
|
||||||
|
ast_log(AST_LOG_ERROR, "Requested label: %s can not be found in context: %s\n", args->label, context);
|
||||||
|
ast_ari_response_error(response, 404, "Not Found", "Requested label can not be found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ast_debug(3, "Numeric value provided for label, jumping to that priority\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ipri == 0) {
|
||||||
|
ast_log(AST_LOG_ERROR, "Invalid priority label '%s' specified for extension %s in context: %s\n",
|
||||||
|
args->label, exten, context);
|
||||||
|
ast_ari_response_error(response, 400, "Bad Request", "Requested priority is illegal");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (args->priority) {
|
||||||
|
/* No label provided, use provided priority */
|
||||||
|
ipri = args->priority;
|
||||||
|
} else if (ast_strlen_zero(args->context) && ast_strlen_zero(args->extension)) {
|
||||||
|
/* Special case. No exten, context, or priority provided, then move on to the next priority */
|
||||||
|
ipri = snapshot->priority + 1;
|
||||||
|
} else {
|
||||||
|
ipri = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (stasis_app_control_continue(control, context, exten, ipri)) {
|
||||||
ast_ari_response_alloc_failed(response);
|
ast_ari_response_alloc_failed(response);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -791,6 +840,7 @@ static void ari_channels_handle_originate_with_id(const char *args_endpoint,
|
|||||||
const char *args_extension,
|
const char *args_extension,
|
||||||
const char *args_context,
|
const char *args_context,
|
||||||
long args_priority,
|
long args_priority,
|
||||||
|
const char *args_label,
|
||||||
const char *args_app,
|
const char *args_app,
|
||||||
const char *args_app_args,
|
const char *args_app_args,
|
||||||
const char *args_caller_id,
|
const char *args_caller_id,
|
||||||
@@ -811,7 +861,7 @@ static void ari_channels_handle_originate_with_id(const char *args_endpoint,
|
|||||||
ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT), ao2_cleanup);
|
ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT), ao2_cleanup);
|
||||||
char *stuff;
|
char *stuff;
|
||||||
struct ast_channel *other = NULL;
|
struct ast_channel *other = NULL;
|
||||||
struct ast_channel *chan;
|
struct ast_channel *chan = NULL;
|
||||||
RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
|
RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
|
||||||
struct ast_assigned_ids assignedids = {
|
struct ast_assigned_ids assignedids = {
|
||||||
.uniqueid = args_channel_id,
|
.uniqueid = args_channel_id,
|
||||||
@@ -880,7 +930,36 @@ static void ari_channels_handle_originate_with_id(const char *args_endpoint,
|
|||||||
|
|
||||||
ast_copy_string(origination->context, S_OR(args_context, "default"), sizeof(origination->context));
|
ast_copy_string(origination->context, S_OR(args_context, "default"), sizeof(origination->context));
|
||||||
ast_copy_string(origination->exten, args_extension, sizeof(origination->exten));
|
ast_copy_string(origination->exten, args_extension, sizeof(origination->exten));
|
||||||
origination->priority = args_priority ? args_priority : 1;
|
|
||||||
|
if (!ast_strlen_zero(args_label)) {
|
||||||
|
/* A label was provided in the request, use that */
|
||||||
|
int ipri = 1;
|
||||||
|
if (sscanf(args_label, "%30d", &ipri) != 1) {
|
||||||
|
ipri = ast_findlabel_extension(chan, origination->context, origination->exten, args_label, args_caller_id);
|
||||||
|
|
||||||
|
if (ipri == -1) {
|
||||||
|
ast_log(AST_LOG_ERROR, "Requested label: %s can not be found in context: %s\n", args_label, args_context);
|
||||||
|
ast_ari_response_error(response, 404, "Not Found", "Requested label can not be found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ast_debug(3, "Numeric value provided for label, jumping to that priority\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ipri == 0) {
|
||||||
|
ast_log(AST_LOG_ERROR, "Invalid priority label '%s' specified for extension %s in context: %s\n",
|
||||||
|
args_label, args_extension, args_context);
|
||||||
|
ast_ari_response_error(response, 400, "Bad Request", "Requested priority is illegal");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Our priority was provided by a label */
|
||||||
|
origination->priority = ipri;
|
||||||
|
} else {
|
||||||
|
/* No label provided, use provided priority */
|
||||||
|
origination->priority = args_priority ? args_priority : 1;
|
||||||
|
}
|
||||||
|
|
||||||
origination->appdata[0] = '\0';
|
origination->appdata[0] = '\0';
|
||||||
} else {
|
} else {
|
||||||
ast_ari_response_error(response, 400, "Bad Request",
|
ast_ari_response_error(response, 400, "Bad Request",
|
||||||
@@ -1042,6 +1121,7 @@ void ast_ari_channels_originate_with_id(struct ast_variable *headers,
|
|||||||
args->extension,
|
args->extension,
|
||||||
args->context,
|
args->context,
|
||||||
args->priority,
|
args->priority,
|
||||||
|
args->label,
|
||||||
args->app,
|
args->app,
|
||||||
args->app_args,
|
args->app_args,
|
||||||
args->caller_id,
|
args->caller_id,
|
||||||
@@ -1079,6 +1159,7 @@ void ast_ari_channels_originate(struct ast_variable *headers,
|
|||||||
args->extension,
|
args->extension,
|
||||||
args->context,
|
args->context,
|
||||||
args->priority,
|
args->priority,
|
||||||
|
args->label,
|
||||||
args->app,
|
args->app,
|
||||||
args->app_args,
|
args->app_args,
|
||||||
args->caller_id,
|
args->caller_id,
|
||||||
|
@@ -60,6 +60,8 @@ struct ast_ari_channels_originate_args {
|
|||||||
const char *context;
|
const char *context;
|
||||||
/*! The priority to dial after the endpoint answers. If omitted, uses 1 */
|
/*! The priority to dial after the endpoint answers. If omitted, uses 1 */
|
||||||
long priority;
|
long priority;
|
||||||
|
/*! The label to dial after the endpoint answers. Will supersede 'priority' if provided. */
|
||||||
|
const char *label;
|
||||||
/*! The application that is subscribed to the originated channel, and passed to the Stasis application. */
|
/*! The application that is subscribed to the originated channel, and passed to the Stasis application. */
|
||||||
const char *app;
|
const char *app;
|
||||||
/*! The application arguments to pass to the Stasis application. */
|
/*! The application arguments to pass to the Stasis application. */
|
||||||
@@ -123,6 +125,8 @@ struct ast_ari_channels_originate_with_id_args {
|
|||||||
const char *context;
|
const char *context;
|
||||||
/*! The priority to dial after the endpoint answers. If omitted, uses 1 */
|
/*! The priority to dial after the endpoint answers. If omitted, uses 1 */
|
||||||
long priority;
|
long priority;
|
||||||
|
/*! The label to dial after the endpoint answers. Will supersede priority, if provided */
|
||||||
|
const char *label;
|
||||||
/*! The application that is subscribed to the originated channel, and passed to the Stasis application. */
|
/*! The application that is subscribed to the originated channel, and passed to the Stasis application. */
|
||||||
const char *app;
|
const char *app;
|
||||||
/*! The application arguments to pass to the Stasis application. */
|
/*! The application arguments to pass to the Stasis application. */
|
||||||
@@ -195,6 +199,8 @@ struct ast_ari_channels_continue_in_dialplan_args {
|
|||||||
const char *extension;
|
const char *extension;
|
||||||
/*! The priority to continue to. */
|
/*! The priority to continue to. */
|
||||||
int priority;
|
int priority;
|
||||||
|
/*! The label to continue to - will supersede 'priority' if both are provided. */
|
||||||
|
const char *label;
|
||||||
};
|
};
|
||||||
/*!
|
/*!
|
||||||
* \brief Body parsing function for /channels/{channelId}/continue.
|
* \brief Body parsing function for /channels/{channelId}/continue.
|
||||||
|
@@ -124,6 +124,10 @@ int ast_ari_channels_originate_parse_body(
|
|||||||
if (field) {
|
if (field) {
|
||||||
args->priority = ast_json_integer_get(field);
|
args->priority = ast_json_integer_get(field);
|
||||||
}
|
}
|
||||||
|
field = ast_json_object_get(body, "label");
|
||||||
|
if (field) {
|
||||||
|
args->label = ast_json_string_get(field);
|
||||||
|
}
|
||||||
field = ast_json_object_get(body, "app");
|
field = ast_json_object_get(body, "app");
|
||||||
if (field) {
|
if (field) {
|
||||||
args->app = ast_json_string_get(field);
|
args->app = ast_json_string_get(field);
|
||||||
@@ -188,6 +192,9 @@ static void ast_ari_channels_originate_cb(
|
|||||||
if (strcmp(i->name, "priority") == 0) {
|
if (strcmp(i->name, "priority") == 0) {
|
||||||
args.priority = atol(i->value);
|
args.priority = atol(i->value);
|
||||||
} else
|
} else
|
||||||
|
if (strcmp(i->name, "label") == 0) {
|
||||||
|
args.label = (i->value);
|
||||||
|
} else
|
||||||
if (strcmp(i->name, "app") == 0) {
|
if (strcmp(i->name, "app") == 0) {
|
||||||
args.app = (i->value);
|
args.app = (i->value);
|
||||||
} else
|
} else
|
||||||
@@ -341,6 +348,10 @@ int ast_ari_channels_originate_with_id_parse_body(
|
|||||||
if (field) {
|
if (field) {
|
||||||
args->priority = ast_json_integer_get(field);
|
args->priority = ast_json_integer_get(field);
|
||||||
}
|
}
|
||||||
|
field = ast_json_object_get(body, "label");
|
||||||
|
if (field) {
|
||||||
|
args->label = ast_json_string_get(field);
|
||||||
|
}
|
||||||
field = ast_json_object_get(body, "app");
|
field = ast_json_object_get(body, "app");
|
||||||
if (field) {
|
if (field) {
|
||||||
args->app = ast_json_string_get(field);
|
args->app = ast_json_string_get(field);
|
||||||
@@ -401,6 +412,9 @@ static void ast_ari_channels_originate_with_id_cb(
|
|||||||
if (strcmp(i->name, "priority") == 0) {
|
if (strcmp(i->name, "priority") == 0) {
|
||||||
args.priority = atol(i->value);
|
args.priority = atol(i->value);
|
||||||
} else
|
} else
|
||||||
|
if (strcmp(i->name, "label") == 0) {
|
||||||
|
args.label = (i->value);
|
||||||
|
} else
|
||||||
if (strcmp(i->name, "app") == 0) {
|
if (strcmp(i->name, "app") == 0) {
|
||||||
args.app = (i->value);
|
args.app = (i->value);
|
||||||
} else
|
} else
|
||||||
@@ -592,6 +606,10 @@ int ast_ari_channels_continue_in_dialplan_parse_body(
|
|||||||
if (field) {
|
if (field) {
|
||||||
args->priority = ast_json_integer_get(field);
|
args->priority = ast_json_integer_get(field);
|
||||||
}
|
}
|
||||||
|
field = ast_json_object_get(body, "label");
|
||||||
|
if (field) {
|
||||||
|
args->label = ast_json_string_get(field);
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -625,6 +643,9 @@ static void ast_ari_channels_continue_in_dialplan_cb(
|
|||||||
if (strcmp(i->name, "priority") == 0) {
|
if (strcmp(i->name, "priority") == 0) {
|
||||||
args.priority = atoi(i->value);
|
args.priority = atoi(i->value);
|
||||||
} else
|
} else
|
||||||
|
if (strcmp(i->name, "label") == 0) {
|
||||||
|
args.label = (i->value);
|
||||||
|
} else
|
||||||
{}
|
{}
|
||||||
}
|
}
|
||||||
for (i = path_vars; i; i = i->next) {
|
for (i = path_vars; i; i = i->next) {
|
||||||
|
@@ -56,6 +56,14 @@
|
|||||||
"allowMultiple": false,
|
"allowMultiple": false,
|
||||||
"dataType": "long"
|
"dataType": "long"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "label",
|
||||||
|
"description": "The label to dial after the endpoint answers. Will supersede 'priority' if provided.",
|
||||||
|
"paramType": "query",
|
||||||
|
"required": false,
|
||||||
|
"allowMultiple": false,
|
||||||
|
"dataType": "string"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "app",
|
"name": "app",
|
||||||
"description": "The application that is subscribed to the originated channel, and passed to the Stasis application.",
|
"description": "The application that is subscribed to the originated channel, and passed to the Stasis application.",
|
||||||
@@ -204,6 +212,14 @@
|
|||||||
"allowMultiple": false,
|
"allowMultiple": false,
|
||||||
"dataType": "long"
|
"dataType": "long"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "label",
|
||||||
|
"description": "The label to dial after the endpoint answers. Will supersede priority, if provided",
|
||||||
|
"paramType": "query",
|
||||||
|
"required": false,
|
||||||
|
"allowMultiple": false,
|
||||||
|
"dataType": "string"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "app",
|
"name": "app",
|
||||||
"description": "The application that is subscribed to the originated channel, and passed to the Stasis application.",
|
"description": "The application that is subscribed to the originated channel, and passed to the Stasis application.",
|
||||||
@@ -356,6 +372,14 @@
|
|||||||
"required": false,
|
"required": false,
|
||||||
"allowMultiple": false,
|
"allowMultiple": false,
|
||||||
"dataType": "int"
|
"dataType": "int"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "label",
|
||||||
|
"description": "The label to continue to - will supersede 'priority' if both are provided.",
|
||||||
|
"paramType": "query",
|
||||||
|
"required": false,
|
||||||
|
"allowMultiple": false,
|
||||||
|
"dataType": "string"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"errorResponses": [
|
"errorResponses": [
|
||||||
|
@@ -2,7 +2,7 @@
|
|||||||
"_copyright": "Copyright (C) 2012 - 2013, Digium, Inc.",
|
"_copyright": "Copyright (C) 2012 - 2013, Digium, Inc.",
|
||||||
"_author": "David M. Lee, II <dlee@digium.com>",
|
"_author": "David M. Lee, II <dlee@digium.com>",
|
||||||
"_svn_revision": "$Revision$",
|
"_svn_revision": "$Revision$",
|
||||||
"apiVersion": "1.6.0",
|
"apiVersion": "1.7.0",
|
||||||
"swaggerVersion": "1.1",
|
"swaggerVersion": "1.1",
|
||||||
"basePath": "http://localhost:8088/ari",
|
"basePath": "http://localhost:8088/ari",
|
||||||
"apis": [
|
"apis": [
|
||||||
|
Reference in New Issue
Block a user