diff options
Diffstat (limited to 'res/stasis_http/resource_asterisk.c')
-rw-r--r-- | res/stasis_http/resource_asterisk.c | 41 |
1 files changed, 41 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); +} |