summaryrefslogtreecommitdiff
path: root/res/res_ari_applications.c
diff options
context:
space:
mode:
authorKinsey Moore <kmoore@digium.com>2014-01-21 14:27:21 +0000
committerKinsey Moore <kmoore@digium.com>2014-01-21 14:27:21 +0000
commit1590d32ab0a5b6797c96244a47f18f868574e970 (patch)
tree3cc0717778b4d2b816ba4df12bb76a75716631b3 /res/res_ari_applications.c
parent4bc84b1b9f25b6bdfab7daef9c08000fb31d5a43 (diff)
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 ........ Merged revisions 406003 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@406006 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/res_ari_applications.c')
-rw-r--r--res/res_ari_applications.c146
1 files changed, 82 insertions, 64 deletions
diff --git a/res/res_ari_applications.c b/res/res_ari_applications.c
index 1f021c41d..9195d4c83 100644
--- a/res/res_ari_applications.c
+++ b/res/res_ari_applications.c
@@ -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)