rest: add and use http error code to improve error reporting

Use http error code to improve better error reporting:

- 404 Not Found
  + object is not found

- 409 Conflict
  + object already exists

- 423 Locked
  + object is in use

- 500 Internal Server Error:
  + database query fails
  + out of memory

- 501 Service Unavailable
  + Cannot connect to database

- 507 Insufficient Storage
  + Disk is full
master
OpenGnSys Support Team 2024-12-05 16:38:25 +01:00
parent 8f52b8911e
commit e3188191d9
1 changed files with 134 additions and 5 deletions

View File

@ -469,6 +469,7 @@ static int og_cmd_get_clients(struct og_rest_ctx *ctx)
list_for_each_entry(cli_wol, &client_wol_list, list) {
if (og_json_client_wol_append(array, cli_wol) < 0) {
json_decref(array);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
}
@ -479,6 +480,7 @@ static int og_cmd_get_clients(struct og_rest_ctx *ctx)
if (og_json_client_append(array, client) < 0) {
json_decref(array);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
}
@ -486,11 +488,13 @@ static int og_cmd_get_clients(struct og_rest_ctx *ctx)
root = json_pack("{s:o}", "clients", array);
if (!root) {
json_decref(array);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
if (json_dump_callback(root, og_json_dump_clients, &og_buffer, JSON_ENSURE_ASCII)) {
json_decref(root);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
@ -576,6 +580,7 @@ static int og_cmd_wol(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -592,6 +597,7 @@ static int og_cmd_wol(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
__func__, __LINE__, msglog);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
@ -619,6 +625,7 @@ static int og_cmd_wol(struct og_rest_ctx *ctx)
if (sd < 0) {
syslog(LOG_ERR, "cannot open wol socket (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
goto err_free_params;
}
@ -636,8 +643,10 @@ static int og_cmd_wol(struct og_rest_ctx *ctx)
}
cli_wol = og_client_wol_create(&addr);
if (!cli_wol)
if (!cli_wol) {
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
goto err_out;
}
list_add_tail(&cli_wol->list, &client_wol_list);
@ -1014,12 +1023,14 @@ static int og_cmd_get_session(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
array = json_array();
if (!array) {
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
@ -1028,6 +1039,7 @@ static int og_cmd_get_session(struct og_rest_ctx *ctx)
if (!client_data) {
json_decref(array);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
json_object_set_new(client_data, "addr", json_string(params->ips_array[i]));
@ -1037,6 +1049,7 @@ static int og_cmd_get_session(struct og_rest_ctx *ctx)
json_decref(client_data);
json_decref(array);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
@ -1045,6 +1058,7 @@ static int og_cmd_get_session(struct og_rest_ctx *ctx)
json_decref(client_data);
json_decref(array);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_404_NOT_FOUND;
return -1;
}
json_object_set_new(client_data, "partitions", partitions);
@ -1056,6 +1070,7 @@ static int og_cmd_get_session(struct og_rest_ctx *ctx)
root = json_object();
if (!root){
json_decref(array);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
@ -1063,6 +1078,7 @@ static int og_cmd_get_session(struct og_rest_ctx *ctx)
if (json_dump_callback(root, og_json_dump_clients, &og_buffer, JSON_ENSURE_ASCII)) {
json_decref(root);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
@ -1218,18 +1234,22 @@ static int og_cmd_get_modes(struct og_rest_ctx *ctx)
int ret;
root = json_object();
if (!root)
if (!root) {
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
modes = json_array();
if (!modes) {
json_decref(root);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
if (og_get_boot_modes(&boot_mode_list) < 0) {
json_decref(modes);
json_decref(root);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -1777,6 +1797,7 @@ static int og_cmd_post_modes(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -1789,6 +1810,7 @@ static int og_cmd_post_modes(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
__func__, __LINE__, msglog);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
if (!dbi_result_next_row(result)) {
@ -1796,6 +1818,7 @@ static int og_cmd_post_modes(struct og_rest_ctx *ctx)
params->ips_array[i], __func__, __LINE__);
dbi_result_free(result);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_404_NOT_FOUND;
return -1;
}
mac = dbi_result_get_string(result, "mac");
@ -1806,6 +1829,7 @@ static int og_cmd_post_modes(struct og_rest_ctx *ctx)
params->ips_array[i], __func__, __LINE__);
dbi_result_free(result);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_507_INSUFFICIENT_STORAGE;
return -1;
}
@ -1858,12 +1882,15 @@ static int og_cmd_get_client_setup(struct og_rest_ctx *ctx)
return -1;
root = json_object();
if (!root)
if (!root) {
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
partitions_array = json_array();
if (!partitions_array) {
json_decref(root);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
json_object_set_new(root, "partitions", partitions_array);
@ -1873,6 +1900,7 @@ static int og_cmd_get_client_setup(struct og_rest_ctx *ctx)
json_decref(root);
syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -1891,6 +1919,7 @@ static int og_cmd_get_client_setup(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
__func__, __LINE__, msglog);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
@ -1913,6 +1942,7 @@ static int og_cmd_get_client_setup(struct og_rest_ctx *ctx)
json_decref(root);
dbi_result_free(result);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
@ -1946,6 +1976,7 @@ static int og_cmd_get_client_setup(struct og_rest_ctx *ctx)
if (json_dump_callback(root, og_json_dump_clients, &og_buffer, JSON_ENSURE_ASCII)) {
json_decref(root);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
@ -2007,6 +2038,7 @@ static int og_cmd_post_client_repo(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -2025,6 +2057,7 @@ static int og_cmd_post_client_repo(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
__func__, __LINE__, msglog);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
@ -2034,6 +2067,7 @@ static int og_cmd_post_client_repo(struct og_rest_ctx *ctx)
if (err != 0) {
dbi_result_free(result);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_404_NOT_FOUND;
return -1;
}
}
@ -2071,11 +2105,13 @@ static int og_cmd_get_center_info(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
if (og_dbi_get_center_info(dbi, &center)) {
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_404_NOT_FOUND;
return -1;
}
og_dbi_close(dbi);
@ -2133,19 +2169,23 @@ static int og_cmd_get_client_info(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
if (og_dbi_get_computer_info(dbi, &computer, addr)) {
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_404_NOT_FOUND;
return -1;
}
og_dbi_close(dbi);
root = json_object();
if (!root)
if (!root) {
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
json_object_set_new(root, "serial_number",
json_string(computer.serial_number));
@ -2168,6 +2208,7 @@ static int og_cmd_get_client_info(struct og_rest_ctx *ctx)
if (json_dump_callback(root, og_json_dump_clients, &og_buffer, JSON_ENSURE_ASCII)) {
json_decref(root);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
@ -2209,6 +2250,7 @@ static int og_cmd_post_center_update(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -2220,6 +2262,7 @@ static int og_cmd_post_center_update(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
__func__, __LINE__, msglog);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
if (dbi_result_get_numrows(result) == 0) {
@ -2240,6 +2283,7 @@ static int og_cmd_post_center_update(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
__func__, __LINE__, msglog);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
if (dbi_result_next_row(result)) {
@ -2248,6 +2292,7 @@ static int og_cmd_post_center_update(struct og_rest_ctx *ctx)
center_id, params->name);
dbi_result_free(result);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_409_CONFLICT;
return -1;
}
dbi_result_free(result);
@ -2263,6 +2308,7 @@ static int og_cmd_post_center_update(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "failed to update center in database (%s:%d) %s\n",
__func__, __LINE__, msglog);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_404_NOT_FOUND;
return -1;
}
dbi_result_free(result);
@ -2336,6 +2382,7 @@ static int og_cmd_post_client_update(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -2347,6 +2394,7 @@ static int og_cmd_post_client_update(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
__func__, __LINE__, msglog);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
if (dbi_result_get_numrows(result) > 0) {
@ -2354,6 +2402,7 @@ static int og_cmd_post_client_update(struct og_rest_ctx *ctx)
computer.ip);
dbi_result_free(result);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_409_CONFLICT;
return -1;
}
@ -2367,6 +2416,7 @@ static int og_cmd_post_client_update(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
__func__, __LINE__, msglog);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
if (dbi_result_next_row(result)) {
@ -2375,6 +2425,7 @@ static int og_cmd_post_client_update(struct og_rest_ctx *ctx)
computer.mac, client_ip);
dbi_result_free(result);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_409_CONFLICT;
return -1;
}
@ -2410,6 +2461,7 @@ static int og_cmd_post_client_update(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "failed to update client in database (%s:%d) %s\n",
__func__, __LINE__, msglog);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_404_NOT_FOUND;
return -1;
}
@ -2419,6 +2471,7 @@ static int og_cmd_post_client_update(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "failed to set client boot mode (%s:%d)\n",
__func__, __LINE__);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
@ -2663,6 +2716,7 @@ static int og_cmd_post_folder_update(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
if (folder.id & OG_COMPUTER_FOLDER_MARKER) {
@ -2713,6 +2767,7 @@ static int og_cmd_post_folder_add(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
if (params->flags & OG_REST_PARAM_ROOM)
@ -2722,6 +2777,9 @@ static int og_cmd_post_folder_add(struct og_rest_ctx *ctx)
else
err = -1;
if (err < 0)
ctx->http_error = OG_HTTP_409_CONFLICT;
og_dbi_close(dbi);
return err;
@ -2833,6 +2891,7 @@ static int og_cmd_post_folder_delete(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -2842,6 +2901,9 @@ static int og_cmd_post_folder_delete(struct og_rest_ctx *ctx)
err = og_delete_room_folder(dbi, folder_id);
}
if (err < 0)
ctx->http_error = OG_HTTP_404_NOT_FOUND;
og_dbi_close(dbi);
return err;
}
@ -2918,6 +2980,7 @@ static int og_cmd_post_client_add(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -2930,6 +2993,7 @@ static int og_cmd_post_client_add(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
__func__, __LINE__, msglog);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
@ -2938,6 +3002,7 @@ static int og_cmd_post_client_add(struct og_rest_ctx *ctx)
computer.ip);
dbi_result_free(result);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_409_CONFLICT;
return -1;
}
dbi_result_free(result);
@ -2954,6 +3019,7 @@ static int og_cmd_post_client_add(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
__func__, __LINE__, msglog);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
@ -3044,6 +3110,7 @@ static int og_cmd_post_client_delete(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -3109,6 +3176,7 @@ static int og_cmd_post_client_move(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -3172,6 +3240,7 @@ static int og_cmd_get_room_info(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -3277,6 +3346,7 @@ static int og_cmd_get_hardware(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -3423,6 +3493,7 @@ static int og_cmd_get_software(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -3443,6 +3514,7 @@ static int og_cmd_get_software(struct og_rest_ctx *ctx)
dbi_conn_error(dbi->conn, &msglog);
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
__func__, __LINE__, msglog);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
software = json_array();
@ -3632,6 +3704,7 @@ static int og_cmd_images(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
json_decref(root);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -3783,6 +3856,7 @@ static int og_cmd_add_image(struct og_rest_ctx *ctx, bool update)
syslog(LOG_ERR,
"cannot open connection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -3915,6 +3989,7 @@ static int og_cmd_restore_image(struct og_rest_ctx *ctx)
syslog(LOG_ERR,
"cannot open connection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -3967,6 +4042,7 @@ static int og_cmd_delete_image(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -4071,6 +4147,7 @@ static int og_cmd_image_scope_update(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
og_scope_image_list_free(&scope_list);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -4185,6 +4262,7 @@ static int og_cmd_image_scope_list(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -4326,6 +4404,7 @@ static int og_cmd_cache_list(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
json_decref(clients);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -4463,6 +4542,7 @@ static int og_cmd_efi_list(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
json_decref(clients);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -4568,6 +4648,7 @@ static int og_cmd_cache_fetch(struct og_rest_ctx *ctx)
syslog(LOG_ERR,
"cannot open connection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -4658,6 +4739,7 @@ static int og_cmd_scope_get(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
json_decref(root);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -4712,6 +4794,7 @@ static int og_cmd_oglive_list(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
__func__, __LINE__);
json_decref(root);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -4726,6 +4809,7 @@ static int og_cmd_oglive_list(struct og_rest_ctx *ctx)
__func__, __LINE__, msglog);
og_dbi_close(dbi);
json_decref(root);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
@ -4740,6 +4824,7 @@ static int og_cmd_oglive_list(struct og_rest_ctx *ctx)
dbi_result_free(result);
og_dbi_close(dbi);
json_decref(root);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
@ -4792,6 +4877,7 @@ static int og_cmd_post_center_add(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -4804,6 +4890,7 @@ static int og_cmd_post_center_add(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
__func__, __LINE__, msglog);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
@ -4812,6 +4899,7 @@ static int og_cmd_post_center_add(struct og_rest_ctx *ctx)
params->name);
dbi_result_free(result);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_409_CONFLICT;
return -1;
}
dbi_result_free(result);
@ -4862,6 +4950,7 @@ static int og_cmd_post_center_delete(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -4962,6 +5051,7 @@ static int og_cmd_post_repository_update(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -5050,6 +5140,7 @@ static int og_cmd_post_repository_add(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -5119,6 +5210,7 @@ static int og_cmd_post_repository_delete(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -5191,6 +5283,7 @@ static int og_cmd_post_room_update(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -5202,6 +5295,7 @@ static int og_cmd_post_room_update(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
__func__, __LINE__, msglog);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
if (!dbi_result_next_row(result)) {
@ -5209,6 +5303,7 @@ static int og_cmd_post_room_update(struct og_rest_ctx *ctx)
room.id);
dbi_result_free(result);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_404_NOT_FOUND;
return -1;
}
room.center = dbi_result_get_uint(result, "idcentro");
@ -5224,6 +5319,7 @@ static int og_cmd_post_room_update(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
__func__, __LINE__, msglog);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
@ -5233,6 +5329,7 @@ static int og_cmd_post_room_update(struct og_rest_ctx *ctx)
room.name, room.center);
dbi_result_free(result);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_404_NOT_FOUND;
return -1;
}
dbi_result_free(result);
@ -5249,6 +5346,7 @@ static int og_cmd_post_room_update(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "failed to update room in database (%s:%d) %s\n",
__func__, __LINE__, msglog);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
dbi_result_free(result);
@ -5309,6 +5407,7 @@ static int og_cmd_post_room_add(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -5322,6 +5421,7 @@ static int og_cmd_post_room_add(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
__func__, __LINE__, msglog);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
@ -5331,6 +5431,7 @@ static int og_cmd_post_room_add(struct og_rest_ctx *ctx)
room.name, room.center);
dbi_result_free(result);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_409_CONFLICT;
return -1;
}
dbi_result_free(result);
@ -5357,6 +5458,7 @@ static int og_cmd_post_room_add(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "failed to add room to database (%s:%d) %s\n",
__func__, __LINE__, msglog);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
@ -5390,6 +5492,7 @@ static int og_cmd_post_room_delete(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -5402,6 +5505,7 @@ static int og_cmd_post_room_delete(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
__func__, __LINE__, msglog);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
if (dbi_result_get_numrows_affected(result) < 1) {
@ -5409,6 +5513,7 @@ static int og_cmd_post_room_delete(struct og_rest_ctx *ctx)
__func__, __LINE__);
dbi_result_free(result);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_404_NOT_FOUND;
return -1;
}
@ -5439,12 +5544,12 @@ static int og_cmd_get_servers(struct og_rest_ctx *ctx)
return -1;
}
dbi = og_dbi_open(&ogconfig.db);
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
json_decref(root);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -5504,6 +5609,7 @@ static int og_cmd_post_server(struct og_rest_ctx *ctx)
if (inet_pton(AF_INET, params->name, &addr) <= 0) {
syslog(LOG_ERR, "invalid server ip address (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
@ -5511,6 +5617,7 @@ static int og_cmd_post_server(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -5523,6 +5630,7 @@ static int og_cmd_post_server(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
__func__, __LINE__, msglog);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
@ -5531,6 +5639,7 @@ static int og_cmd_post_server(struct og_rest_ctx *ctx)
params->name);
dbi_result_free(result);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_409_CONFLICT;
return -1;
}
dbi_result_free(result);
@ -5547,6 +5656,7 @@ static int og_cmd_post_server(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "failed to add new ogserver address to database (%s:%d) %s\n",
__func__, __LINE__, msglog);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
@ -5556,6 +5666,7 @@ static int og_cmd_post_server(struct og_rest_ctx *ctx)
__func__, __LINE__);
dbi_result_free(result);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
id = dbi_conn_sequence_last(dbi->conn, NULL);
@ -5596,6 +5707,7 @@ static int og_cmd_delete_server(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open conection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -5608,6 +5720,7 @@ static int og_cmd_delete_server(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "failed to delete server (%s:%d) %s\n",
__func__, __LINE__, msglog);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
if (dbi_result_get_numrows_affected(result) < 1) {
@ -5615,6 +5728,7 @@ static int og_cmd_delete_server(struct og_rest_ctx *ctx)
__func__, __LINE__);
dbi_result_free(result);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_404_NOT_FOUND;
return -1;
}
@ -5684,6 +5798,7 @@ static int og_cmd_oglive_set(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -5696,6 +5811,7 @@ static int og_cmd_oglive_set(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
__func__, __LINE__, msglog);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
if (!dbi_result_next_row(result)) {
@ -5703,6 +5819,7 @@ static int og_cmd_oglive_set(struct og_rest_ctx *ctx)
params->ips_array[i], __func__, __LINE__);
dbi_result_free(result);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_404_NOT_FOUND;
return -1;
}
mode_str = dbi_result_get_string(result, "arranque");
@ -5714,6 +5831,7 @@ static int og_cmd_oglive_set(struct og_rest_ctx *ctx)
__func__, __LINE__);
dbi_result_free(result);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
@ -5721,6 +5839,7 @@ static int og_cmd_oglive_set(struct og_rest_ctx *ctx)
if (err < 0) {
dbi_result_free(result);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
@ -5764,6 +5883,7 @@ static int og_cmd_oglive_add(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -5775,6 +5895,7 @@ static int og_cmd_oglive_add(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
__func__, __LINE__, msglog);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
@ -5804,6 +5925,7 @@ static int og_cmd_oglive_add(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
__func__, __LINE__, msglog);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
@ -5843,6 +5965,7 @@ static int og_cmd_oglive_delete(struct og_rest_ctx *ctx)
if (!dbi) {
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
__func__, __LINE__);
ctx->http_error = OG_HTTP_501_SERVICE_UNAVAILABLE;
return -1;
}
@ -5854,6 +5977,7 @@ static int og_cmd_oglive_delete(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
__func__, __LINE__, msglog);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
@ -5861,6 +5985,7 @@ static int og_cmd_oglive_delete(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "failed to delete oglive '%s', live in use by a client", oglive_str);
dbi_result_free(result);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_423_LOCKED;
return -1;
}
@ -5874,6 +5999,7 @@ static int og_cmd_oglive_delete(struct og_rest_ctx *ctx)
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
__func__, __LINE__, msglog);
og_dbi_close(dbi);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
@ -5909,6 +6035,7 @@ static int og_cmd_get_server_stats(struct og_rest_ctx *ctx)
if (!memory) {
json_decref(root);
json_decref(time_obj);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
swap = json_object();
@ -5916,6 +6043,7 @@ static int og_cmd_get_server_stats(struct og_rest_ctx *ctx)
json_decref(root);
json_decref(time_obj);
json_decref(memory);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}
@ -5935,6 +6063,7 @@ static int og_cmd_get_server_stats(struct og_rest_ctx *ctx)
if (json_dump_callback(root, og_json_dump_clients, &og_buffer, JSON_ENSURE_ASCII)) {
json_decref(root);
ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
return -1;
}