summaryrefslogtreecommitdiff
path: root/res/ari
diff options
context:
space:
mode:
authorKevin Harwell <kharwell@digium.com>2013-12-13 17:19:23 +0000
committerKevin Harwell <kharwell@digium.com>2013-12-13 17:19:23 +0000
commitf425c4a086526d8f4da91d62a5e02121c09609b8 (patch)
tree9c7c9ca6947d63c5037287e7bbbe4d074c7e777e /res/ari
parentce18946de46a6f16463391a9c07af02b8ee4e925 (diff)
ARI: Allow specifying channel variables during a POST /channels
Added the ability to specify channel variables when creating/originating a channel in ARI. The variables are sent in the body of the request and should be formatted as a single level JSON object. No nested objects allowed. For example: {"variable1": "foo", "variable2": "bar"}. (closes issue ASTERISK-22872) Reported by: Matt Jordan Review: https://reviewboard.asterisk.org/r/3052/ ........ Merged revisions 403752 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@403757 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/ari')
-rw-r--r--res/ari/resource_channels.c44
-rw-r--r--res/ari/resource_channels.h2
2 files changed, 45 insertions, 1 deletions
diff --git a/res/ari/resource_channels.c b/res/ari/resource_channels.c
index 824c5e660..6d85781da 100644
--- a/res/ari/resource_channels.c
+++ b/res/ari/resource_channels.c
@@ -688,6 +688,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)
@@ -768,6 +805,11 @@ void ast_ari_channels_originate(struct ast_variable *headers,
return;
}
+ if (ari_channels_set_channel_vars(chan, args->variables, response)) {
+ /* response filled in by called function */
+ return;
+ }
+
snapshot = ast_channel_snapshot_create(chan);
ast_channel_unlock(chan);
@@ -917,4 +959,4 @@ void ast_ari_channels_snoop_channel(struct ast_variable *headers, struct ast_ari
snapshot = ast_channel_snapshot_create(snoop);
ast_ari_response_ok(response, ast_channel_snapshot_to_json(snapshot, NULL));
-} \ No newline at end of file
+}
diff --git a/res/ari/resource_channels.h b/res/ari/resource_channels.h
index 49ab8eb34..36c7339ba 100644
--- a/res/ari/resource_channels.h
+++ b/res/ari/resource_channels.h
@@ -68,6 +68,8 @@ struct ast_ari_channels_originate_args {
const char *caller_id;
/*! \brief Timeout (in seconds) before giving up dialing, or -1 for no timeout. */
int timeout;
+ /*! \brief Variables to be set on the channel. */
+ struct ast_json *variables;
};
/*!
* \brief Create a new channel (originate).