res_ari: Fix some off-nominal paths just dropping the HTTP connection.

* Removed some incorrect newlines on ast_http_error() messages in
manager.c.

* Removed an incorrect newline in res_ari_channels.c.

Addendum to ASTERISK-23552
........

Merged revisions 417932 from http://svn.asterisk.org/svn/asterisk/branches/12


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@417933 65c4cc65-6c06-0410-ace0-fbb531ad65f3
changes/97/197/1
Richard Mudgett 11 years ago
parent bc4b236d71
commit 9b10813a2b

@ -6873,7 +6873,7 @@ static int generic_http_callback(struct ast_tcptls_session_instance *ser,
*/ */
if (!(session = build_mansession(remote_address))) { if (!(session = build_mansession(remote_address))) {
ast_http_request_close_on_completion(ser); ast_http_request_close_on_completion(ser);
ast_http_error(ser, 500, "Server Error", "Internal Server Error (out of memory)\n"); ast_http_error(ser, 500, "Server Error", "Internal Server Error (out of memory)");
return 0; return 0;
} }
ao2_lock(session); ao2_lock(session);
@ -6899,7 +6899,7 @@ static int generic_http_callback(struct ast_tcptls_session_instance *ser,
if (http_header == NULL || out == NULL) { if (http_header == NULL || out == NULL) {
ast_http_request_close_on_completion(ser); ast_http_request_close_on_completion(ser);
ast_http_error(ser, 500, "Server Error", "Internal Server Error (ast_str_create() out of memory)\n"); ast_http_error(ser, 500, "Server Error", "Internal Server Error (ast_str_create() out of memory)");
goto generic_callback_out; goto generic_callback_out;
} }
@ -6907,13 +6907,13 @@ static int generic_http_callback(struct ast_tcptls_session_instance *ser,
s.fd = mkstemp(template); /* create a temporary file for command output */ s.fd = mkstemp(template); /* create a temporary file for command output */
unlink(template); unlink(template);
if (s.fd <= -1) { if (s.fd <= -1) {
ast_http_error(ser, 500, "Server Error", "Internal Server Error (mkstemp failed)\n"); ast_http_error(ser, 500, "Server Error", "Internal Server Error (mkstemp failed)");
goto generic_callback_out; goto generic_callback_out;
} }
s.f = fdopen(s.fd, "w+"); s.f = fdopen(s.fd, "w+");
if (!s.f) { if (!s.f) {
ast_log(LOG_WARNING, "HTTP Manager, fdopen failed: %s!\n", strerror(errno)); ast_log(LOG_WARNING, "HTTP Manager, fdopen failed: %s!\n", strerror(errno));
ast_http_error(ser, 500, "Server Error", "Internal Server Error (fdopen failed)\n"); ast_http_error(ser, 500, "Server Error", "Internal Server Error (fdopen failed)");
close(s.fd); close(s.fd);
goto generic_callback_out; goto generic_callback_out;
} }
@ -7109,7 +7109,7 @@ static int auth_http_callback(struct ast_tcptls_session_instance *ser,
/* Digest found - parse */ /* Digest found - parse */
if (ast_string_field_init(&d, 128)) { if (ast_string_field_init(&d, 128)) {
ast_http_request_close_on_completion(ser); ast_http_request_close_on_completion(ser);
ast_http_error(ser, 500, "Server Error", "Internal Server Error (out of memory)\n"); ast_http_error(ser, 500, "Server Error", "Internal Server Error (out of memory)");
return 0; return 0;
} }
@ -7138,7 +7138,7 @@ static int auth_http_callback(struct ast_tcptls_session_instance *ser,
AST_RWLIST_UNLOCK(&users); AST_RWLIST_UNLOCK(&users);
ast_log(LOG_NOTICE, "%s failed to pass IP ACL as '%s'\n", ast_sockaddr_stringify_addr(&session->addr), d.username); ast_log(LOG_NOTICE, "%s failed to pass IP ACL as '%s'\n", ast_sockaddr_stringify_addr(&session->addr), d.username);
ast_http_request_close_on_completion(ser); ast_http_request_close_on_completion(ser);
ast_http_error(ser, 403, "Permission denied", "Permission denied\n"); ast_http_error(ser, 403, "Permission denied", "Permission denied");
return 0; return 0;
} }
@ -7189,7 +7189,7 @@ static int auth_http_callback(struct ast_tcptls_session_instance *ser,
*/ */
if (!(session = build_mansession(remote_address))) { if (!(session = build_mansession(remote_address))) {
ast_http_request_close_on_completion(ser); ast_http_request_close_on_completion(ser);
ast_http_error(ser, 500, "Server Error", "Internal Server Error (out of memory)\n"); ast_http_error(ser, 500, "Server Error", "Internal Server Error (out of memory)");
return 0; return 0;
} }
ao2_lock(session); ao2_lock(session);
@ -7257,13 +7257,13 @@ static int auth_http_callback(struct ast_tcptls_session_instance *ser,
s.fd = mkstemp(template); /* create a temporary file for command output */ s.fd = mkstemp(template); /* create a temporary file for command output */
unlink(template); unlink(template);
if (s.fd <= -1) { if (s.fd <= -1) {
ast_http_error(ser, 500, "Server Error", "Internal Server Error (mkstemp failed)\n"); ast_http_error(ser, 500, "Server Error", "Internal Server Error (mkstemp failed)");
goto auth_callback_out; goto auth_callback_out;
} }
s.f = fdopen(s.fd, "w+"); s.f = fdopen(s.fd, "w+");
if (!s.f) { if (!s.f) {
ast_log(LOG_WARNING, "HTTP Manager, fdopen failed: %s!\n", strerror(errno)); ast_log(LOG_WARNING, "HTTP Manager, fdopen failed: %s!\n", strerror(errno));
ast_http_error(ser, 500, "Server Error", "Internal Server Error (fdopen failed)\n"); ast_http_error(ser, 500, "Server Error", "Internal Server Error (fdopen failed)");
close(s.fd); close(s.fd);
goto auth_callback_out; goto auth_callback_out;
} }
@ -7321,7 +7321,7 @@ static int auth_http_callback(struct ast_tcptls_session_instance *ser,
out = ast_str_create(result_size * 2 + 512); out = ast_str_create(result_size * 2 + 512);
if (http_header == NULL || out == NULL) { if (http_header == NULL || out == NULL) {
ast_http_request_close_on_completion(ser); ast_http_request_close_on_completion(ser);
ast_http_error(ser, 500, "Server Error", "Internal Server Error (ast_str_create() out of memory)\n"); ast_http_error(ser, 500, "Server Error", "Internal Server Error (ast_str_create() out of memory)");
close_mansession_file(&s); close_mansession_file(&s);
goto auth_callback_out; goto auth_callback_out;
} }

@ -790,7 +790,7 @@ static void ari_channels_handle_originate_with_id(const char *args_endpoint,
if ((assignedids.uniqueid && AST_MAX_PUBLIC_UNIQUEID < strlen(assignedids.uniqueid)) if ((assignedids.uniqueid && AST_MAX_PUBLIC_UNIQUEID < strlen(assignedids.uniqueid))
|| (assignedids.uniqueid2 && AST_MAX_PUBLIC_UNIQUEID < strlen(assignedids.uniqueid2))) { || (assignedids.uniqueid2 && AST_MAX_PUBLIC_UNIQUEID < strlen(assignedids.uniqueid2))) {
ast_ari_response_error(response, 400, "Bad Request", ast_ari_response_error(response, 400, "Bad Request",
"Uniqueid length exceeds maximum of %d\n", AST_MAX_PUBLIC_UNIQUEID); "Uniqueid length exceeds maximum of %d", AST_MAX_PUBLIC_UNIQUEID);
return; return;
} }

@ -860,22 +860,27 @@ static int ast_ari_callback(struct ast_tcptls_session_instance *ser,
RAII_VAR(struct ast_str *, response_body, ast_str_create(256), ast_free); RAII_VAR(struct ast_str *, response_body, ast_str_create(256), ast_free);
RAII_VAR(struct ast_ari_conf_user *, user, NULL, ao2_cleanup); RAII_VAR(struct ast_ari_conf_user *, user, NULL, ao2_cleanup);
struct ast_ari_response response = {}; struct ast_ari_response response = {};
int ret = 0;
RAII_VAR(struct ast_variable *, post_vars, NULL, ast_variables_destroy); RAII_VAR(struct ast_variable *, post_vars, NULL, ast_variables_destroy);
if (!response_body) { if (!response_body) {
return -1; ast_http_request_close_on_completion(ser);
ast_http_error(ser, 500, "Server Error", "Out of memory");
return 0;
} }
response.headers = ast_str_create(40); response.headers = ast_str_create(40);
if (!response.headers) { if (!response.headers) {
return -1; ast_http_request_close_on_completion(ser);
ast_http_error(ser, 500, "Server Error", "Out of memory");
return 0;
} }
conf = ast_ari_config_get(); conf = ast_ari_config_get();
if (!conf || !conf->general) { if (!conf || !conf->general) {
ast_free(response.headers); ast_free(response.headers);
return -1; ast_http_request_close_on_completion(ser);
ast_http_error(ser, 500, "Server Error", "URI handler config missing");
return 0;
} }
process_cors_request(headers, &response); process_cors_request(headers, &response);
@ -893,9 +898,10 @@ static int ast_ari_callback(struct ast_tcptls_session_instance *ser,
"Request body too large"); "Request body too large");
goto request_failed; goto request_failed;
case ENOMEM: case ENOMEM:
ast_http_request_close_on_completion(ser);
ast_ari_response_error(&response, 500, ast_ari_response_error(&response, 500,
"Internal Server Error", "Internal Server Error",
"Error processing request"); "Out of memory");
goto request_failed; goto request_failed;
case EIO: case EIO:
ast_ari_response_error(&response, 400, ast_ari_response_error(&response, 400,
@ -940,6 +946,7 @@ static int ast_ari_callback(struct ast_tcptls_session_instance *ser,
"WWW-Authenticate: Basic realm=\"%s\"\r\n", "WWW-Authenticate: Basic realm=\"%s\"\r\n",
conf->general->auth_realm); conf->general->auth_realm);
} else if (!ast_fully_booted) { } else if (!ast_fully_booted) {
ast_http_request_close_on_completion(ser);
ast_ari_response_error(&response, 503, "Service Unavailable", "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) { } else if (user->read_only && method != AST_HTTP_GET && method != AST_HTTP_OPTIONS) {
ast_ari_response_error(&response, 403, "Forbidden", "Write access denied"); ast_ari_response_error(&response, 403, "Forbidden", "Write access denied");
@ -986,7 +993,6 @@ request_failed:
response.response_text = "Internal Server Error"; response.response_text = "Internal Server Error";
ast_str_set(&response_body, 0, "%s", ""); ast_str_set(&response_body, 0, "%s", "");
ast_str_set(&response.headers, 0, "%s", ""); ast_str_set(&response.headers, 0, "%s", "");
ret = -1;
} }
} }
@ -999,7 +1005,7 @@ request_failed:
response_body = NULL; response_body = NULL;
ast_json_unref(response.message); ast_json_unref(response.message);
return ret; return 0;
} }
static struct ast_http_uri http_uri = { static struct ast_http_uri http_uri = {

Loading…
Cancel
Save