[Asterisk-code-review] res_ari: Fix create request body parameter parsing. (asterisk[16.11])

Joshua Colp asteriskteam at digium.com
Tue Jun 9 09:09:52 CDT 2020


Joshua Colp has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/14538 )

Change subject: res_ari: Fix create request body parameter parsing.
......................................................................

res_ari: Fix create request body parameter parsing.

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
---
M res/ari/resource_channels.c
1 file changed, 12 insertions(+), 12 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve; Approved for Submit
  George Joseph: Looks good to me, approved



diff --git a/res/ari/resource_channels.c b/res/ari/resource_channels.c
index 7cf4137..81944f8 100644
--- a/res/ari/resource_channels.c
+++ b/res/ari/resource_channels.c
@@ -1790,18 +1790,6 @@
 	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;
@@ -1814,6 +1802,18 @@
 		}
 	}
 
+	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);

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/14538
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16.11
Gerrit-Change-Id: I898b4c3c7ae1cde19a6840e59f498822701cf5cf
Gerrit-Change-Number: 14538
Gerrit-PatchSet: 1
Gerrit-Owner: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: sungtae kim <pchero21 at gmail.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200609/01f7c125/attachment.html>


More information about the asterisk-code-review mailing list