diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/rest.c | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -2116,6 +2116,7 @@ static int og_cmd_post_client_add(json_t *element, struct og_msg_params *params, char *buffer_reply) { + const char *room_name, *computer_name, *computer_ip, *hwaddr; struct og_computer computer = {}; const char *key, *msglog; struct og_dbi *dbi; @@ -2210,6 +2211,34 @@ static int og_cmd_post_client_add(json_t *element, dbi_result_free(result); result = dbi_conn_queryf(dbi->conn, + "SELECT nombreordenador, ip, nombreaula" + " FROM ordenadores" + " INNER JOIN aulas on ordenadores.idaula = aulas.idaula" + " WHERE mac='%s'", + computer.mac); + + if (!result) { + dbi_conn_error(dbi->conn, &msglog); + syslog(LOG_ERR, "failed to query database (%s:%d) %s\n", + __func__, __LINE__, msglog); + og_dbi_close(dbi); + return -1; + } + + if (dbi_result_next_row(result)) { + room_name = dbi_result_get_string(result, "nombreaula"); + computer_name = dbi_result_get_string(result, "nombreordenador"); + computer_ip = dbi_result_get_string(result, "ip"); + hwaddr = dbi_result_get_string(result, "mac"); + syslog(LOG_ERR, "Failed to add client %s because %s (%s) in room %s already owns MAC address %s\n", + computer.ip, computer_ip, computer_name, room_name, hwaddr); + dbi_result_free(result); + og_dbi_close(dbi); + return -1; + } + dbi_result_free(result); + + result = dbi_conn_queryf(dbi->conn, "INSERT INTO ordenadores(" " nombreordenador," " numserie," |