summaryrefslogtreecommitdiffstats
path: root/src/dbi.c
diff options
context:
space:
mode:
authorRoberto Hueso Gómez <rhueso@soleta.eu>2020-09-18 15:21:19 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2020-09-22 15:20:57 +0200
commitcbd9421bae01c62c249cc390af5dfcdf19930e46 (patch)
treeec9726a3956d1da0079cae54b3575d945c3d732d /src/dbi.c
parentd7e2022bdd1626fbcb614710bec20b4a42278f9a (diff)
#941 Extend og_dbi_get_computer_info(...)
For the strings in og_computer we do not need to know the max size in advance but instead we need to free up memmory using og_dbi_free_computer_info(...) function.
Diffstat (limited to 'src/dbi.c')
-rw-r--r--src/dbi.c53
1 files changed, 45 insertions, 8 deletions
diff --git a/src/dbi.c b/src/dbi.c
index 94f3de8..7d7ba64 100644
--- a/src/dbi.c
+++ b/src/dbi.c
@@ -11,6 +11,8 @@
#include <arpa/inet.h>
#include <string.h>
#include "dbi.h"
+#include <syslog.h>
+#include <string.h>
struct og_dbi *og_dbi_open(struct og_dbi_config *config)
{
@@ -57,10 +59,23 @@ int og_dbi_get_computer_info(struct og_dbi *dbi, struct og_computer *computer,
result = dbi_conn_queryf(dbi->conn,
"SELECT ordenadores.idordenador,"
- " ordenadores.nombreordenador,"
- " ordenadores.idaula,"
- " ordenadores.idproautoexec,"
- " centros.idcentro FROM ordenadores "
+ " ordenadores.nombreordenador,"
+ " ordenadores.numserie,"
+ " ordenadores.ip,"
+ " ordenadores.mac,"
+ " ordenadores.idaula,"
+ " ordenadores.idperfilhard,"
+ " ordenadores.idrepositorio,"
+ " ordenadores.mascara,"
+ " ordenadores.arranque,"
+ " ordenadores.netiface,"
+ " ordenadores.netdriver,"
+ " ordenadores.idproautoexec,"
+ " ordenadores.oglivedir,"
+ " ordenadores.inremotepc,"
+ " ordenadores.maintenance,"
+ " centros.idcentro "
+ "FROM ordenadores "
"INNER JOIN aulas ON aulas.idaula=ordenadores.idaula "
"INNER JOIN centros ON centros.idcentro=aulas.idcentro "
"WHERE ordenadores.ip='%s'", inet_ntoa(addr));
@@ -78,14 +93,36 @@ int og_dbi_get_computer_info(struct og_dbi *dbi, struct og_computer *computer,
}
computer->id = dbi_result_get_uint(result, "idordenador");
- computer->center = dbi_result_get_uint(result, "idcentro");
+ computer->name = strdup(dbi_result_get_string(result, "nombreordenador"));
+ computer->serial_number = strdup(dbi_result_get_string(result, "numserie"));
+ computer->ip = strdup(dbi_result_get_string(result, "ip"));
+ computer->mac = strdup(dbi_result_get_string(result, "mac"));
computer->room = dbi_result_get_uint(result, "idaula");
+ computer->hardware_id = dbi_result_get_uint(result, "idperfilhard");
+ computer->repo_id = dbi_result_get_uint(result, "idrepositorio");
+ computer->netmask = strdup(dbi_result_get_string(result, "mascara"));
+ computer->boot = strdup(dbi_result_get_string(result, "arranque"));
+ computer->netiface = strdup(dbi_result_get_string(result, "netiface"));
+ computer->netdriver = strdup(dbi_result_get_string(result, "netdriver"));
computer->procedure_id = dbi_result_get_uint(result, "idproautoexec");
- strncpy(computer->name,
- dbi_result_get_string(result, "nombreordenador"),
- OG_DB_COMPUTER_NAME_MAXLEN);
+ computer->livedir = strdup(dbi_result_get_string(result, "oglivedir"));
+ computer->remote = dbi_result_get_uint(result, "inremotepc") != 0;
+ computer->maintenance = dbi_result_get_uint(result, "maintenance") != 0;
dbi_result_free(result);
return 0;
}
+
+void og_dbi_free_computer_info(struct og_computer *computer)
+{
+ free(computer->serial_number);
+ free(computer->netdriver);
+ free(computer->netiface);
+ free(computer->netmask);
+ free(computer->livedir);
+ free(computer->name);
+ free(computer->boot);
+ free(computer->mac);
+ free(computer->ip);
+}