diff options
author | Benjamin Ford <bford@digium.com> | 2015-07-13 10:54:51 -0500 |
---|---|---|
committer | Benjamin Keith Ford <bford@digium.com> | 2015-07-13 14:29:27 -0500 |
commit | 6a764db3700b31847138fcbfc7d811b96f99aca2 (patch) | |
tree | 95b8e5a4488fd4b59ab0ffa1d420b8a533196544 /res/ari/resource_asterisk.c | |
parent | 66b57b10f65bee8600c01a0fc03fb491edb7ad76 (diff) |
ARI: Added new functionality to get information on a single module.
An http request can be sent to retrieve information on a single
module, including the resource name, description, use count, status,
and support level.
The command "curl -v -u user:pass -X GET 'http://localhost:8088/ari
/asterisk/modules/{moduleName}'" (or something similar, depending on
configuration) can be run in the terminal to access this new
functionality.
For more information, see:
https://wiki.asterisk.org/wiki.display/~bford/Asterisk+ARI+Resource
* Added new ARI functionality
* Information on a single module can now be retrieved
ASTERISK-25173
Change-Id: Ibce5a94e70ecdf4e90329cf0ba66c33a62d37463
Diffstat (limited to 'res/ari/resource_asterisk.c')
-rw-r--r-- | res/ari/resource_asterisk.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/res/ari/resource_asterisk.c b/res/ari/resource_asterisk.c index cc80d0ca3..ea1a073b0 100644 --- a/res/ari/resource_asterisk.c +++ b/res/ari/resource_asterisk.c @@ -185,6 +185,79 @@ void ast_ari_asterisk_list_modules(struct ast_variable *headers, ast_ari_response_ok(response, json); } +/*! + * \brief Identify module by name and process resource information + * \param module Resource name + * \param description Resource description + * \param usecnt Resource use count + * \param status Resource running status + * \param like + * \param support_level Resource support level + * \param data JSON body for resource + * \param condition Name to match resource to + * + * \retval 0 if no resource exists + * \retval 1 if resource exists + */ +static int identify_module(const char *module, const char *description, int usecnt, + const char *status, const char *like, + enum ast_module_support_level support_level, void *data, + const char *condition) +{ + int json_obj_set = 0; + + if (strcmp(condition, module) != 0) { + return 0; + } + + json_obj_set += ast_json_object_set(data, "name", ast_json_string_create(module)); + json_obj_set += ast_json_object_set(data, "description", ast_json_string_create(description)); + json_obj_set += ast_json_object_set(data, "use_count", ast_json_integer_create(usecnt)); + json_obj_set += ast_json_object_set(data, "status", ast_json_string_create(status)); + json_obj_set += ast_json_object_set(data, "support_level", ast_json_string_create( + ast_module_support_level_to_string(support_level))); + + if (json_obj_set != 0) { + return 0; + } + + return 1; +} + +void ast_ari_asterisk_get_module(struct ast_variable *headers, + struct ast_ari_asterisk_get_module_args *args, + struct ast_ari_response *response) +{ + struct ast_json *json; + int module_retrieved = 0; + + ast_assert(response != NULL); + + if (!ast_module_check(args->module_name)) { + ast_ari_response_error( + response, 404, "Not Found", + "Module could not be found in running modules"); + return; + } + + json = ast_json_object_create(); + if (!json) { + ast_ari_response_alloc_failed(response); + return; + } + + module_retrieved = ast_update_module_list_condition(&identify_module, NULL, json, + args->module_name); + if (!module_retrieved) { + ast_ari_response_error( + response, 409, "Conflict", + "Module information could not be retrieved"); + return; + } + + ast_ari_response_ok(response, json); +} + void ast_ari_asterisk_get_global_var(struct ast_variable *headers, struct ast_ari_asterisk_get_global_var_args *args, struct ast_ari_response *response) |