summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-07-08 12:22:55 +0200
committerAlejandro Sirgo Rica <asirgo@soleta.eu>2024-07-18 09:26:11 +0200
commit8a23579cabb747cc6662b1b1bafefb7ba79e22b8 (patch)
treee500e3e627e2d5ec0aaae2d47f8de6665d37ae81 /src
parente9a8f467f1d805348df66c6a4bee1d145fdd85db (diff)
rest: update client ip in /client/update
Use idordenador as discriminator value instead of the client's ip. Update client ip if the new ip is not used by other clients.
Diffstat (limited to 'src')
-rw-r--r--src/rest.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/rest.c b/src/rest.c
index 8563fd2..48caf3b 100644
--- a/src/rest.c
+++ b/src/rest.c
@@ -2199,6 +2199,8 @@ static int og_cmd_post_client_update(json_t *element,
computer.ip,
sizeof(computer.ip));
params->flags |= OG_REST_PARAM_ADDR;
+ } else if (!strcmp(key, "id")) {
+ err = og_json_parse_uint(value, &computer.id);
} else if (!strcmp(key, "serial_number")) {
err = og_json_parse_string_copy(value,
computer.serial_number,
@@ -2251,8 +2253,8 @@ static int og_cmd_post_client_update(json_t *element,
}
result = dbi_conn_queryf(dbi->conn,
- "SELECT ip FROM ordenadores WHERE ip='%s'",
- computer.ip);
+ "SELECT ip FROM ordenadores WHERE ip='%s' AND idordenador<>'%u'",
+ computer.ip, computer.id);
if (!result) {
dbi_conn_error(dbi->conn, &msglog);
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
@@ -2260,8 +2262,8 @@ static int og_cmd_post_client_update(json_t *element,
og_dbi_close(dbi);
return -1;
}
- if (dbi_result_get_numrows(result) == 0) {
- syslog(LOG_ERR, "client with that IP does not exist: %s\n",
+ if (dbi_result_get_numrows(result) > 0) {
+ syslog(LOG_ERR, "client with IP %s already exist\n",
computer.ip);
dbi_result_free(result);
og_dbi_close(dbi);
@@ -2271,8 +2273,8 @@ static int og_cmd_post_client_update(json_t *element,
dbi_result_free(result);
result = dbi_conn_queryf(dbi->conn,
- "SELECT ip FROM ordenadores WHERE ip<>'%s' AND mac='%s'",
- computer.ip, computer.mac);
+ "SELECT ip FROM ordenadores WHERE mac='%s' AND idordenador<>'%u'",
+ computer.mac, computer.id);
if (!result) {
dbi_conn_error(dbi->conn, &msglog);
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
@@ -2294,6 +2296,7 @@ static int og_cmd_post_client_update(json_t *element,
result = dbi_conn_queryf(dbi->conn,
"UPDATE ordenadores"
" SET numserie='%s',"
+ " ip='%s',"
" netdriver='%s',"
" maintenance=%u,"
" netiface='%s',"
@@ -2304,14 +2307,15 @@ static int og_cmd_post_client_update(json_t *element,
" nombreordenador='%s',"
" mac='%s',"
" arranque='%s'"
- " WHERE ip='%s';",
+ " WHERE idordenador='%u';",
computer.serial_number,
+ computer.ip,
computer.netdriver, computer.maintenance,
computer.netiface, computer.repo_id,
computer.netmask, computer.remote,
computer.room, computer.name,
computer.mac, computer.boot,
- computer.ip);
+ computer.id);
if (!result) {
dbi_conn_error(dbi->conn, &msglog);
syslog(LOG_ERR, "failed to update client in database (%s:%d) %s\n",