Merge "res_pjsip_caller_id: Add "party" parameter to RPID header."
[asterisk/asterisk.git] / res / res_ari_device_states.c
index 5576a18..12962b6 100644 (file)
 
 /*** MODULEINFO
        <depend type="module">res_ari</depend>
+       <depend type="module">res_ari_model</depend>
        <depend type="module">res_stasis</depend>
+       <depend type="module">res_stasis_device_state</depend>
        <support_level>core</support_level>
  ***/
 
 #include "asterisk.h"
 
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-
 #include "asterisk/app.h"
 #include "asterisk/module.h"
 #include "asterisk/stasis_app.h"
@@ -61,10 +61,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 static void ast_ari_device_states_list_cb(
        struct ast_tcptls_session_instance *ser,
        struct ast_variable *get_params, struct ast_variable *path_vars,
-       struct ast_variable *headers, struct ast_ari_response *response)
+       struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
 {
        struct ast_ari_device_states_list_args args = {};
-       RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
 #if defined(AST_DEVMODE)
        int is_valid;
        int code;
@@ -112,11 +111,10 @@ fin: __attribute__((unused))
 static void ast_ari_device_states_get_cb(
        struct ast_tcptls_session_instance *ser,
        struct ast_variable *get_params, struct ast_variable *path_vars,
-       struct ast_variable *headers, struct ast_ari_response *response)
+       struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
 {
        struct ast_ari_device_states_get_args args = {};
        struct ast_variable *i;
-       RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
 #if defined(AST_DEVMODE)
        int is_valid;
        int code;
@@ -183,11 +181,10 @@ int ast_ari_device_states_update_parse_body(
 static void ast_ari_device_states_update_cb(
        struct ast_tcptls_session_instance *ser,
        struct ast_variable *get_params, struct ast_variable *path_vars,
-       struct ast_variable *headers, struct ast_ari_response *response)
+       struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
 {
        struct ast_ari_device_states_update_args args = {};
        struct ast_variable *i;
-       RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
 #if defined(AST_DEVMODE)
        int is_valid;
        int code;
@@ -205,21 +202,6 @@ static void ast_ari_device_states_update_cb(
                } else
                {}
        }
-       /* Look for a JSON request entity */
-       body = ast_http_get_json(ser, headers);
-       if (!body) {
-               switch (errno) {
-               case EFBIG:
-                       ast_ari_response_error(response, 413, "Request Entity Too Large", "Request body too large");
-                       goto fin;
-               case ENOMEM:
-                       ast_ari_response_error(response, 500, "Internal Server Error", "Error processing request");
-                       goto fin;
-               case EIO:
-                       ast_ari_response_error(response, 400, "Bad Request", "Error parsing request body");
-                       goto fin;
-               }
-       }
        if (ast_ari_device_states_update_parse_body(body, &args)) {
                ast_ari_response_alloc_failed(response);
                goto fin;
@@ -268,11 +250,10 @@ fin: __attribute__((unused))
 static void ast_ari_device_states_delete_cb(
        struct ast_tcptls_session_instance *ser,
        struct ast_variable *get_params, struct ast_variable *path_vars,
-       struct ast_variable *headers, struct ast_ari_response *response)
+       struct ast_variable *headers, struct ast_json *body, struct ast_ari_response *response)
 {
        struct ast_ari_device_states_delete_args args = {};
        struct ast_variable *i;
-       RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
 #if defined(AST_DEVMODE)
        int is_valid;
        int code;
@@ -319,7 +300,7 @@ fin: __attribute__((unused))
        return;
 }
 
-/*! \brief REST handler for /api-docs/deviceStates.{format} */
+/*! \brief REST handler for /api-docs/deviceStates.json */
 static struct stasis_rest_handlers deviceStates_deviceName = {
        .path_segment = "deviceName",
        .is_wildcard = 1,
@@ -331,7 +312,7 @@ static struct stasis_rest_handlers deviceStates_deviceName = {
        .num_children = 0,
        .children = {  }
 };
-/*! \brief REST handler for /api-docs/deviceStates.{format} */
+/*! \brief REST handler for /api-docs/deviceStates.json */
 static struct stasis_rest_handlers deviceStates = {
        .path_segment = "deviceStates",
        .callbacks = {
@@ -341,23 +322,29 @@ static struct stasis_rest_handlers deviceStates = {
        .children = { &deviceStates_deviceName, }
 };
 
+static int unload_module(void)
+{
+       ast_ari_remove_handler(&deviceStates);
+       return 0;
+}
+
 static int load_module(void)
 {
        int res = 0;
-       stasis_app_ref();
+
+
        res |= ast_ari_add_handler(&deviceStates);
-       return res;
-}
+       if (res) {
+               unload_module();
+               return AST_MODULE_LOAD_DECLINE;
+       }
 
-static int unload_module(void)
-{
-       ast_ari_remove_handler(&deviceStates);
-       stasis_app_unref();
-       return 0;
+       return AST_MODULE_LOAD_SUCCESS;
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - Device state resources",
+       .support_level = AST_MODULE_SUPPORT_CORE,
        .load = load_module,
        .unload = unload_module,
-       .nonoptreq = "res_ari,res_stasis",
-       );
+       .requires = "res_ari,res_ari_model,res_stasis,res_stasis_device_state",
+);