Merge "rtp_engine/res_rtp_asterisk: Fix RTP struct reentrancy crashes."
[asterisk/asterisk.git] / res / res_ari_applications.c
index 7ce9722..21d9f56 100644 (file)
@@ -40,8 +40,6 @@
 
 #include "asterisk.h"
 
-ASTERISK_REGISTER_FILE()
-
 #include "asterisk/app.h"
 #include "asterisk/module.h"
 #include "asterisk/stasis_app.h"
@@ -62,10 +60,9 @@ ASTERISK_REGISTER_FILE()
 static void ast_ari_applications_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_applications_list_args args = {};
-       RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
 #if defined(AST_DEVMODE)
        int is_valid;
        int code;
@@ -113,11 +110,10 @@ fin: __attribute__((unused))
 static void ast_ari_applications_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_applications_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;
@@ -210,11 +206,10 @@ int ast_ari_applications_subscribe_parse_body(
 static void ast_ari_applications_subscribe_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_applications_subscribe_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;
@@ -272,21 +267,6 @@ static void ast_ari_applications_subscribe_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_applications_subscribe_parse_body(body, &args)) {
                ast_ari_response_alloc_failed(response);
                goto fin;
@@ -376,11 +356,10 @@ int ast_ari_applications_unsubscribe_parse_body(
 static void ast_ari_applications_unsubscribe_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_applications_unsubscribe_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;
@@ -438,21 +417,6 @@ static void ast_ari_applications_unsubscribe_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_applications_unsubscribe_parse_body(body, &args)) {
                ast_ari_response_alloc_failed(response);
                goto fin;
@@ -526,19 +490,24 @@ static struct stasis_rest_handlers applications = {
        .children = { &applications_applicationName, }
 };
 
+static int unload_module(void)
+{
+       ast_ari_remove_handler(&applications);
+       stasis_app_unref();
+       return 0;
+}
+
 static int load_module(void)
 {
        int res = 0;
        stasis_app_ref();
        res |= ast_ari_add_handler(&applications);
-       return res;
-}
+       if (res) {
+               unload_module();
+               return AST_MODULE_LOAD_DECLINE;
+       }
 
-static int unload_module(void)
-{
-       ast_ari_remove_handler(&applications);
-       stasis_app_unref();
-       return 0;
+       return AST_MODULE_LOAD_SUCCESS;
 }
 
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "RESTful API module - Stasis application resources",