summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJavier Hernandez <jhernandez@soleta.eu>2023-11-03 20:44:37 +0100
committerOpenGnSys Support Team <soporte-og@soleta.eu>2023-11-06 10:11:44 +0100
commit4c1995d28fb09156e89e54e437ffedb16ca945b7 (patch)
tree84b6588cf1c65993d36b6d361f8529adbbedd28b
parentebd31b97b0d68e911c35a5c0435ba64fb9d6c5c7 (diff)
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
-rw-r--r--src/rest.c31
1 files changed, 31 insertions, 0 deletions
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);