ARI: Support channel variables in originate

This adds back in support for specifying channel variables during an
originate without compromising the ability to specify query parameters
in the JSON body. This was accomplished by generating the body-parsing
code in a separate function instead of being integrated with the URI
query parameter parsing code such that it could be called by paths with
body parameters. This is transparent to the user of the API and
prevents manual duplication of code or data structures.

(closes issue ASTERISK-23051)
Review: https://reviewboard.asterisk.org/r/3122/
Reported by: Matt Jordan


git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/12@406003 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Kinsey Moore
2014-01-21 14:15:21 +00:00
parent 7affb5d332
commit bf97a4c8d7
23 changed files with 1161 additions and 474 deletions

View File

@@ -161,6 +161,44 @@ static void ast_ari_applications_get_cb(
fin: __attribute__((unused))
return;
}
int ast_ari_applications_subscribe_parse_body(
struct ast_json *body,
struct ast_ari_applications_subscribe_args *args)
{
struct ast_json *field;
/* Parse query parameters out of it */
field = ast_json_object_get(body, "eventSource");
if (field) {
/* If they were silly enough to both pass in a query param and a
* JSON body, free up the query value.
*/
ast_free(args->event_source);
if (ast_json_typeof(field) == AST_JSON_ARRAY) {
/* Multiple param passed as array */
size_t i;
args->event_source_count = ast_json_array_size(field);
args->event_source = ast_malloc(sizeof(*args->event_source) * args->event_source_count);
if (!args->event_source) {
return -1;
}
for (i = 0; i < args->event_source_count; ++i) {
args->event_source[i] = ast_json_string_get(ast_json_array_get(field, i));
}
} else {
/* Multiple param passed as single value */
args->event_source_count = 1;
args->event_source = ast_malloc(sizeof(*args->event_source) * args->event_source_count);
if (!args->event_source) {
return -1;
}
args->event_source[0] = ast_json_string_get(field);
}
}
return 0;
}
/*!
* \brief Parameter parsing callback for /applications/{applicationName}/subscription.
* \param get_params GET parameters in the HTTP request.
@@ -176,7 +214,6 @@ static void ast_ari_applications_subscribe_cb(
struct ast_ari_applications_subscribe_args args = {};
struct ast_variable *i;
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
struct ast_json *field;
#if defined(AST_DEVMODE)
int is_valid;
int code;
@@ -249,37 +286,9 @@ static void ast_ari_applications_subscribe_cb(
goto fin;
}
}
/* Parse query parameters out of it */
field = ast_json_object_get(body, "eventSource");
if (field) {
/* If they were silly enough to both pass in a query param and a
* JSON body, free up the query value.
*/
ast_free(args.event_source);
if (ast_json_typeof(field) == AST_JSON_ARRAY) {
/* Multiple param passed as array */
size_t i;
args.event_source_count = ast_json_array_size(field);
args.event_source = ast_malloc(sizeof(*args.event_source) * args.event_source_count);
if (!args.event_source) {
ast_ari_response_alloc_failed(response);
goto fin;
}
for (i = 0; i < args.event_source_count; ++i) {
args.event_source[i] = ast_json_string_get(ast_json_array_get(field, i));
}
} else {
/* Multiple param passed as single value */
args.event_source_count = 1;
args.event_source = ast_malloc(sizeof(*args.event_source) * args.event_source_count);
if (!args.event_source) {
ast_ari_response_alloc_failed(response);
goto fin;
}
args.event_source[0] = ast_json_string_get(field);
}
if (ast_ari_applications_subscribe_parse_body(body, &args)) {
ast_ari_response_alloc_failed(response);
goto fin;
}
ast_ari_applications_subscribe(headers, &args, response);
#if defined(AST_DEVMODE)
@@ -318,6 +327,44 @@ fin: __attribute__((unused))
ast_free(args.event_source);
return;
}
int ast_ari_applications_unsubscribe_parse_body(
struct ast_json *body,
struct ast_ari_applications_unsubscribe_args *args)
{
struct ast_json *field;
/* Parse query parameters out of it */
field = ast_json_object_get(body, "eventSource");
if (field) {
/* If they were silly enough to both pass in a query param and a
* JSON body, free up the query value.
*/
ast_free(args->event_source);
if (ast_json_typeof(field) == AST_JSON_ARRAY) {
/* Multiple param passed as array */
size_t i;
args->event_source_count = ast_json_array_size(field);
args->event_source = ast_malloc(sizeof(*args->event_source) * args->event_source_count);
if (!args->event_source) {
return -1;
}
for (i = 0; i < args->event_source_count; ++i) {
args->event_source[i] = ast_json_string_get(ast_json_array_get(field, i));
}
} else {
/* Multiple param passed as single value */
args->event_source_count = 1;
args->event_source = ast_malloc(sizeof(*args->event_source) * args->event_source_count);
if (!args->event_source) {
return -1;
}
args->event_source[0] = ast_json_string_get(field);
}
}
return 0;
}
/*!
* \brief Parameter parsing callback for /applications/{applicationName}/subscription.
* \param get_params GET parameters in the HTTP request.
@@ -333,7 +380,6 @@ static void ast_ari_applications_unsubscribe_cb(
struct ast_ari_applications_unsubscribe_args args = {};
struct ast_variable *i;
RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
struct ast_json *field;
#if defined(AST_DEVMODE)
int is_valid;
int code;
@@ -406,37 +452,9 @@ static void ast_ari_applications_unsubscribe_cb(
goto fin;
}
}
/* Parse query parameters out of it */
field = ast_json_object_get(body, "eventSource");
if (field) {
/* If they were silly enough to both pass in a query param and a
* JSON body, free up the query value.
*/
ast_free(args.event_source);
if (ast_json_typeof(field) == AST_JSON_ARRAY) {
/* Multiple param passed as array */
size_t i;
args.event_source_count = ast_json_array_size(field);
args.event_source = ast_malloc(sizeof(*args.event_source) * args.event_source_count);
if (!args.event_source) {
ast_ari_response_alloc_failed(response);
goto fin;
}
for (i = 0; i < args.event_source_count; ++i) {
args.event_source[i] = ast_json_string_get(ast_json_array_get(field, i));
}
} else {
/* Multiple param passed as single value */
args.event_source_count = 1;
args.event_source = ast_malloc(sizeof(*args.event_source) * args.event_source_count);
if (!args.event_source) {
ast_ari_response_alloc_failed(response);
goto fin;
}
args.event_source[0] = ast_json_string_get(field);
}
if (ast_ari_applications_unsubscribe_parse_body(body, &args)) {
ast_ari_response_alloc_failed(response);
goto fin;
}
ast_ari_applications_unsubscribe(headers, &args, response);
#if defined(AST_DEVMODE)