summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Colp <jcolp@digium.com>2014-02-26 17:04:38 +0000
committerJoshua Colp <jcolp@digium.com>2014-02-26 17:04:38 +0000
commit0e279c215e1935379f9a62c91f59f83c961c9c88 (patch)
tree5978cd5f02a7cc6f518245340d3096ae1d9dd3a0
parent801cb712546dee1136a7575e7ff955583ec4ae7c (diff)
res_ari: Make some additional error responses consistent with the rest of the system.
This change makes some error cases use ast_ari_response_error to construct their error responses instead of manually doing it. This ensures they are consistent with the other error responses. Based on the original patch as done by Paul Belanger on the associated review. Review: https://reviewboard.asterisk.org/r/2904/ ........ Merged revisions 408957 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@408958 65c4cc65-6c06-0410-ace0-fbb531ad65f3
-rw-r--r--res/res_ari.c21
1 files changed, 4 insertions, 17 deletions
diff --git a/res/res_ari.c b/res/res_ari.c
index f36b82935..66bc4280a 100644
--- a/res/res_ari.c
+++ b/res/res_ari.c
@@ -908,8 +908,7 @@ static int ast_ari_callback(struct ast_tcptls_session_instance *ser,
* WWW-Authenticate header field containing at least one
* challenge applicable to the requested resource.
*/
- response.response_code = 401;
- response.response_text = "Unauthorized";
+ ast_ari_response_error(&response, 401, "Unauthorized", "Authentication required");
/* Section 1.2:
* realm = "realm" "=" realm-value
@@ -920,28 +919,16 @@ static int ast_ari_callback(struct ast_tcptls_session_instance *ser,
ast_str_append(&response.headers, 0,
"WWW-Authenticate: Basic realm=\"%s\"\r\n",
conf->general->auth_realm);
- response.message = ast_json_pack("{s: s}",
- "error", "Authentication required");
} else if (!ast_fully_booted) {
- response.response_code = 503;
- response.response_text = "Service Unavailable";
- response.message = ast_json_pack("{s: s}",
- "error", "Asterisk not booted");
+ ast_ari_response_error(&response, 503, "Service Unavailable", "Asterisk not booted");
} else if (user->read_only && method != AST_HTTP_GET && method != AST_HTTP_OPTIONS) {
- response.message = ast_json_pack("{s: s}",
- "error", "Write access denied");
- response.response_code = 403;
- response.response_text = "Forbidden";
+ ast_ari_response_error(&response, 403, "Forbidden", "Write access denied");
} else if (ast_ends_with(uri, "/")) {
remove_trailing_slash(uri, &response);
} else if (ast_begins_with(uri, "api-docs/")) {
/* Serving up API docs */
if (method != AST_HTTP_GET) {
- response.message =
- ast_json_pack("{s: s}",
- "message", "Unsupported method");
- response.response_code = 405;
- response.response_text = "Method Not Allowed";
+ ast_ari_response_error(&response, 405, "Method Not Allowed", "Unsupported method");
} else {
/* Skip the api-docs prefix */
ast_ari_get_docs(strchr(uri, '/') + 1, headers, &response);