summaryrefslogtreecommitdiff
path: root/res/stasis_http
diff options
context:
space:
mode:
authorJason Parker <jparker@digium.com>2013-07-08 14:46:20 +0000
committerJason Parker <jparker@digium.com>2013-07-08 14:46:20 +0000
commit87973eecffbf400da98b67eca1dbed038af40439 (patch)
tree792c79b81749434c8ead92c5e66708ef8897d87b /res/stasis_http
parent7422581b6d4921cebfcf177fc63b2ef852fdef58 (diff)
ARI: Add support for getting/setting channel and global variables.
This allows for reading and writing of functions on channels. (closes issue ASTERISK-21868) Review: https://reviewboard.asterisk.org/r/2641/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@393806 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/stasis_http')
-rw-r--r--res/stasis_http/resource_asterisk.c41
-rw-r--r--res/stasis_http/resource_asterisk.h28
-rw-r--r--res/stasis_http/resource_channels.c52
-rw-r--r--res/stasis_http/resource_channels.h32
4 files changed, 153 insertions, 0 deletions
diff --git a/res/stasis_http/resource_asterisk.c b/res/stasis_http/resource_asterisk.c
index b5e8b0f54..c2a0bc0cc 100644
--- a/res/stasis_http/resource_asterisk.c
+++ b/res/stasis_http/resource_asterisk.c
@@ -32,8 +32,49 @@
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "resource_asterisk.h"
+#include "asterisk/pbx.h"
void stasis_http_get_asterisk_info(struct ast_variable *headers, struct ast_get_asterisk_info_args *args, struct stasis_http_response *response)
{
ast_log(LOG_ERROR, "TODO: stasis_http_get_asterisk_info\n");
}
+
+void stasis_http_get_global_var(struct ast_variable *headers, struct ast_get_global_var_args *args, struct stasis_http_response *response)
+{
+ RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
+ RAII_VAR(struct ast_str *, tmp, ast_str_create(32), ast_free);
+
+ const char *value;
+
+ ast_assert(response != NULL);
+
+ if (!tmp) {
+ stasis_http_response_alloc_failed(response);
+ return;
+ }
+
+ value = ast_str_retrieve_variable(&tmp, 0, NULL, NULL, args->variable);
+
+ if (!(json = ast_json_pack("{s: s}", "value", S_OR(value, "")))) {
+ stasis_http_response_alloc_failed(response);
+ return;
+ }
+
+ stasis_http_response_ok(response, ast_json_ref(json));
+}
+
+void stasis_http_set_global_var(struct ast_variable *headers, struct ast_set_global_var_args *args, struct stasis_http_response *response)
+{
+ ast_assert(response != NULL);
+
+ if (ast_strlen_zero(args->variable)) {
+ stasis_http_response_error(
+ response, 400, "Bad Request",
+ "Variable name is required");
+ return;
+ }
+
+ pbx_builtin_setvar_helper(NULL, args->variable, args->value);
+
+ stasis_http_response_no_content(response);
+}
diff --git a/res/stasis_http/resource_asterisk.h b/res/stasis_http/resource_asterisk.h
index 0d373ccb2..e32e919ab 100644
--- a/res/stasis_http/resource_asterisk.h
+++ b/res/stasis_http/resource_asterisk.h
@@ -52,5 +52,33 @@ struct ast_get_asterisk_info_args {
* \param[out] response HTTP response
*/
void stasis_http_get_asterisk_info(struct ast_variable *headers, struct ast_get_asterisk_info_args *args, struct stasis_http_response *response);
+/*! \brief Argument struct for stasis_http_get_global_var() */
+struct ast_get_global_var_args {
+ /*! \brief The variable to get */
+ const char *variable;
+};
+/*!
+ * \brief Get the value of a global variable.
+ *
+ * \param headers HTTP headers
+ * \param args Swagger parameters
+ * \param[out] response HTTP response
+ */
+void stasis_http_get_global_var(struct ast_variable *headers, struct ast_get_global_var_args *args, struct stasis_http_response *response);
+/*! \brief Argument struct for stasis_http_set_global_var() */
+struct ast_set_global_var_args {
+ /*! \brief The variable to set */
+ const char *variable;
+ /*! \brief The value to set the variable to */
+ const char *value;
+};
+/*!
+ * \brief Set the value of a global variable.
+ *
+ * \param headers HTTP headers
+ * \param args Swagger parameters
+ * \param[out] response HTTP response
+ */
+void stasis_http_set_global_var(struct ast_variable *headers, struct ast_set_global_var_args *args, struct stasis_http_response *response);
#endif /* _ASTERISK_RESOURCE_ASTERISK_H */
diff --git a/res/stasis_http/resource_channels.c b/res/stasis_http/resource_channels.c
index 8db3b697c..1700b86ca 100644
--- a/res/stasis_http/resource_channels.c
+++ b/res/stasis_http/resource_channels.c
@@ -561,3 +561,55 @@ void stasis_http_originate(struct ast_variable *headers,
stasis_http_response_no_content(response);
}
+
+void stasis_http_get_channel_var(struct ast_variable *headers, struct ast_get_channel_var_args *args, struct stasis_http_response *response)
+{
+ RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
+ RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
+ RAII_VAR(char *, value, NULL, ast_free);
+
+ ast_assert(response != NULL);
+
+ control = find_control(response, args->channel_id);
+ if (control == NULL) {
+ return;
+ }
+
+ value = stasis_app_control_get_channel_var(control, args->variable);
+
+ if (!(json = ast_json_pack("{s: s}", "value", S_OR(value, "")))) {
+ stasis_http_response_alloc_failed(response);
+ return;
+ }
+
+ stasis_http_response_ok(response, ast_json_ref(json));
+}
+
+void stasis_http_set_channel_var(struct ast_variable *headers, struct ast_set_channel_var_args *args, struct stasis_http_response *response)
+{
+ RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
+
+ ast_assert(response != NULL);
+
+ control = find_control(response, args->channel_id);
+ if (control == NULL) {
+ return;
+ }
+
+ if (ast_strlen_zero(args->variable)) {
+ stasis_http_response_error(
+ response, 400, "Bad Request",
+ "Variable name is required");
+ return;
+ }
+
+ if (stasis_app_control_set_channel_var(control, args->variable, args->value)) {
+ stasis_http_response_error(
+ response, 400, "Bad Request",
+ "Failed to execute function");
+ return;
+ }
+
+ stasis_http_response_no_content(response);
+}
+
diff --git a/res/stasis_http/resource_channels.h b/res/stasis_http/resource_channels.h
index 7e8dc5dbe..999e16954 100644
--- a/res/stasis_http/resource_channels.h
+++ b/res/stasis_http/resource_channels.h
@@ -264,5 +264,37 @@ struct ast_record_channel_args {
* \param[out] response HTTP response
*/
void stasis_http_record_channel(struct ast_variable *headers, struct ast_record_channel_args *args, struct stasis_http_response *response);
+/*! \brief Argument struct for stasis_http_get_channel_var() */
+struct ast_get_channel_var_args {
+ /*! \brief Channel's id */
+ const char *channel_id;
+ /*! \brief The channel variable or function to get */
+ const char *variable;
+};
+/*!
+ * \brief Get the value of a channel variable or function.
+ *
+ * \param headers HTTP headers
+ * \param args Swagger parameters
+ * \param[out] response HTTP response
+ */
+void stasis_http_get_channel_var(struct ast_variable *headers, struct ast_get_channel_var_args *args, struct stasis_http_response *response);
+/*! \brief Argument struct for stasis_http_set_channel_var() */
+struct ast_set_channel_var_args {
+ /*! \brief Channel's id */
+ const char *channel_id;
+ /*! \brief The channel variable or function to set */
+ const char *variable;
+ /*! \brief The value to set the variable to */
+ const char *value;
+};
+/*!
+ * \brief Set the value of a channel variable or function.
+ *
+ * \param headers HTTP headers
+ * \param args Swagger parameters
+ * \param[out] response HTTP response
+ */
+void stasis_http_set_channel_var(struct ast_variable *headers, struct ast_set_channel_var_args *args, struct stasis_http_response *response);
#endif /* _ASTERISK_RESOURCE_CHANNELS_H */