]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_ari: Fix create request body parameter parsing.
authorsungtae kim <sungtae@messagebird.com>
Tue, 9 Jun 2020 11:57:24 +0000 (11:57 +0000)
committerJoshua C. Colp <jcolp@sangoma.com>
Tue, 9 Jun 2020 12:27:04 +0000 (09:27 -0300)
If parameters were passed in the body as JSON to the
create route they were not being parsed before checking
to ensure that required fields were set.

This change moves the parsing so it occurs before
checking.

ASTERISK-28940

Change-Id: I898b4c3c7ae1cde19a6840e59f498822701cf5cf

res/ari/resource_channels.c

index e59c74ffbb665c1a011eb40c9d09aaa7e9970079..6c1b8e564d29ff5c6aac88615c0d15e661d60654 100644 (file)
@@ -1794,18 +1794,6 @@ void ast_ari_channels_create(struct ast_variable *headers,
        struct ast_format_cap *request_cap;
        struct ast_channel *originator;
 
-       if (!ast_strlen_zero(args->originator) && !ast_strlen_zero(args->formats)) {
-               ast_ari_response_error(response, 400, "Bad Request",
-                       "Originator and formats can't both be specified");
-               return;
-       }
-
-       if (ast_strlen_zero(args->endpoint)) {
-               ast_ari_response_error(response, 400, "Bad Request",
-                       "Endpoint must be specified");
-               return;
-       }
-
        /* Parse any query parameters out of the body parameter */
        if (args->variables) {
                struct ast_json *json_variables;
@@ -1818,6 +1806,18 @@ void ast_ari_channels_create(struct ast_variable *headers,
                }
        }
 
+       if (!ast_strlen_zero(args->originator) && !ast_strlen_zero(args->formats)) {
+               ast_ari_response_error(response, 400, "Bad Request",
+                       "Originator and formats can't both be specified");
+               return;
+       }
+
+       if (ast_strlen_zero(args->endpoint)) {
+               ast_ari_response_error(response, 400, "Bad Request",
+                       "Endpoint must be specified");
+               return;
+       }
+
        chan_data = ast_calloc(1, sizeof(*chan_data));
        if (!chan_data) {
                ast_ari_response_alloc_failed(response);