summaryrefslogtreecommitdiff
path: root/res/ari/resource_channels.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/ari/resource_channels.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/ari/resource_channels.c')
-rw-r--r--res/ari/resource_channels.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/res/ari/resource_channels.c b/res/ari/resource_channels.c
index e6322a37c..ab8f5b42b 100644
--- a/res/ari/resource_channels.c
+++ b/res/ari/resource_channels.c
@@ -687,6 +687,43 @@ void ast_ari_channels_list(struct ast_variable *headers,
ast_ari_response_ok(response, ast_json_ref(json));
}
+static int ari_channels_set_channel_var(struct ast_channel *chan,
+ const char *variable, const char *value, struct ast_ari_response *response)
+{
+ if (pbx_builtin_setvar_helper(chan, variable, value)) {
+ ast_ari_response_error(
+ response, 400, "Bad Request",
+ "Unable to set channel variable %s=%s", variable, value);
+ return -1;
+ }
+
+ return 0;
+}
+
+static int ari_channels_set_channel_vars(struct ast_channel *chan,
+ struct ast_json *variables, struct ast_ari_response *response)
+{
+ struct ast_json_iter *i;
+
+ if (!variables) {
+ /* nothing to do */
+ return 0;
+ }
+
+ for (i = ast_json_object_iter(variables); i;
+ i = ast_json_object_iter_next(variables, i)) {
+ if (ari_channels_set_channel_var(
+ chan, ast_json_object_iter_key(i),
+ ast_json_string_get(ast_json_object_iter_value(i)),
+ response)) {
+ /* response filled in by called function */
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
void ast_ari_channels_originate(struct ast_variable *headers,
struct ast_ari_channels_originate_args *args,
struct ast_ari_response *response)
@@ -704,6 +741,7 @@ void ast_ari_channels_originate(struct ast_variable *headers,
char *stuff;
struct ast_channel *chan;
RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
+ struct ast_json *variable_list = NULL;
if (!cap) {
ast_ari_response_alloc_failed(response);
@@ -711,6 +749,12 @@ void ast_ari_channels_originate(struct ast_variable *headers,
}
ast_format_cap_add(cap, ast_format_set(&tmp_fmt, AST_FORMAT_SLINEAR, 0));
+ /* Parse any query parameters out of the body parameter */
+ if (args->variables) {
+ ast_ari_channels_originate_parse_body(args->variables, args);
+ variable_list = ast_json_object_get(args->variables, "variables");
+ }
+
if (ast_strlen_zero(args->endpoint)) {
ast_ari_response_error(response, 400, "Bad Request",
"Endpoint must be specified");
@@ -776,6 +820,11 @@ void ast_ari_channels_originate(struct ast_variable *headers,
return;
}
+ if (ari_channels_set_channel_vars(chan, variable_list, response)) {
+ /* response filled in by called function */
+ return;
+ }
+
snapshot = ast_channel_snapshot_create(chan);
ast_channel_unlock(chan);