From 4c1995d28fb09156e89e54e437ffedb16ca945b7 Mon Sep 17 00:00:00 2001 From: Javier Hernandez Date: Fri, 3 Nov 2023 20:44:37 +0100 Subject: rest: Add error check to delete commands Every time a delete operation is performed it needs to be checked that a row has been deleted. If no rows are deleted, then ogserver reports an error. Previous to this change, it only checks that the connection to db was succesful. For example, previously, if a user deletes a client that did not exist, ogserver responds with no errors. After this change, it responds with an error. This error check has been implemented when deleting: - A client - An image - A center - A repo - A room - A server --- src/rest.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/rest.c b/src/rest.c index 4c7c927..6e4ba04 100644 --- a/src/rest.c +++ b/src/rest.c @@ -1834,6 +1834,11 @@ static int og_cmd_post_client_delete(json_t *element, og_dbi_close(dbi); return -1; } + if (dbi_result_get_numrows_affected(result) < 1) { + dbi_result_free(result); + og_dbi_close(dbi); + return -1; + } dbi_result_free(result); } @@ -2580,6 +2585,11 @@ static int og_cmd_delete_image(json_t *element, struct og_msg_params *params) syslog(LOG_ERR, "failed to query database\n"); return -1; } + if (dbi_result_get_numrows_affected(result) < 1) { + dbi_result_free(result); + og_dbi_close(dbi); + return -1; + } dbi_result_free(result); rval = unlink(filename); @@ -4742,6 +4752,12 @@ static int og_cmd_post_center_delete(json_t *element, return -1; } + if (dbi_result_get_numrows_affected(result) < 1) { + dbi_result_free(result); + og_dbi_close(dbi); + return -1; + } + dbi_result_free(result); og_dbi_close(dbi); @@ -5332,6 +5348,11 @@ static int og_cmd_post_repository_delete(json_t *element, og_dbi_close(dbi); return -1; } + if (dbi_result_get_numrows_affected(result) < 1) { + dbi_result_free(result); + og_dbi_close(dbi); + return -1; + } dbi_result_free(result); og_dbi_close(dbi); @@ -5487,6 +5508,11 @@ static int og_cmd_post_room_delete(json_t *element, og_dbi_close(dbi); return -1; } + if (dbi_result_get_numrows_affected(result) < 1) { + dbi_result_free(result); + og_dbi_close(dbi); + return -1; + } dbi_result_free(result); @@ -5953,6 +5979,11 @@ static int og_cmd_delete_server(json_t *element, og_dbi_close(dbi); return -1; } + if (dbi_result_get_numrows_affected(result) < 1) { + dbi_result_free(result); + og_dbi_close(dbi); + return -1; + } dbi_result_free(result); og_dbi_close(dbi); -- cgit v1.2.3-18-g5258