summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOpenGnSys Support Team <soporte-og@soleta.eu>2019-05-17 18:03:31 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2020-03-04 14:54:52 +0100
commit0fde10b973a88ae073bf721225297564b610eb10 (patch)
treeb250a176b27e3d0c71c89da6536add77955cc767
parent1d801be52c05e89532b945f58b2d302d15a55297 (diff)
#941 use dbi layer from procesoInclusionCliente()
-rw-r--r--sources/ogAdmServer.cpp82
1 files changed, 36 insertions, 46 deletions
diff --git a/sources/ogAdmServer.cpp b/sources/ogAdmServer.cpp
index 49b90ab..6416a41 100644
--- a/sources/ogAdmServer.cpp
+++ b/sources/ogAdmServer.cpp
@@ -385,13 +385,15 @@ static bool InclusionCliente(TRAMA *ptrTrama, struct og_client *cli)
bool procesoInclusionCliente(struct og_client *cli, TRAMA *ptrTrama)
{
int socket_c = og_client_socket(cli);
- char msglog[LONSTD], sqlstr[LONSQL];
+ const char *msglog, *str;
+ struct og_dbi *dbi;
+ dbi_result result;
Database db;
Table tbl;
char *iph, *cfg;
char nombreordenador[LONFIL];
- int lon, resul, idordenador, idmenu, cache, idproautoexec, idaula, idcentro;
+ int lon, resul, idordenador, cache, idproautoexec, idaula, idcentro;
// Toma parámetros
iph = copiaParametro("iph",ptrTrama); // Toma ip
@@ -400,72 +402,53 @@ bool procesoInclusionCliente(struct og_client *cli, TRAMA *ptrTrama)
if (!db.Open(usuario, pasguor, datasource, catalog)) {
liberaMemoria(iph);
liberaMemoria(cfg);
- db.GetErrorErrStr(msglog);
- syslog(LOG_ERR, "cannot open connection database (%s:%d) %s\n",
- __func__, __LINE__, msglog);
+ syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
+ __func__, __LINE__);
return false;
}
+ dbi = og_dbi_open(&dbi_config);
+ if (!dbi) {
+ syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
+ __func__, __LINE__);
+ goto err_dbi_open;
+ }
+
// Recupera los datos del cliente
- sprintf(sqlstr,
+ result = dbi_conn_queryf(dbi->conn,
"SELECT ordenadores.*,aulas.idaula,centros.idcentro FROM ordenadores "
" INNER JOIN aulas ON aulas.idaula=ordenadores.idaula"
" INNER JOIN centros ON centros.idcentro=aulas.idcentro"
" WHERE ordenadores.ip = '%s'", iph);
- if (!db.Execute(sqlstr, tbl)) {
- db.GetErrorErrStr(msglog);
+ if (!result) {
+ dbi_conn_error(dbi->conn, &msglog);
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
__func__, __LINE__, msglog);
- return false;
+ goto err_query_fail;
}
- if (tbl.ISEOF()) {
+ if (!dbi_result_next_row(result)) {
syslog(LOG_ERR, "client does not exist in database (%s:%d)\n",
__func__, __LINE__);
- return false;
+ dbi_result_free(result);
+ goto err_query_fail;
}
syslog(LOG_DEBUG, "Client %s requesting inclusion\n", iph);
- if (!tbl.Get("idordenador", idordenador)) {
- tbl.GetErrorErrStr(msglog);
- og_info(msglog);
- return false;
- }
- if (!tbl.Get("nombreordenador", nombreordenador)) {
- tbl.GetErrorErrStr(msglog);
- og_info(msglog);
- return false;
- }
- if (!tbl.Get("idmenu", idmenu)) {
- tbl.GetErrorErrStr(msglog);
- og_info(msglog);
- return false;
- }
- if (!tbl.Get("cache", cache)) {
- tbl.GetErrorErrStr(msglog);
- og_info(msglog);
- return false;
- }
- if (!tbl.Get("idproautoexec", idproautoexec)) {
- tbl.GetErrorErrStr(msglog);
- og_info(msglog);
- return false;
- }
- if (!tbl.Get("idaula", idaula)) {
- tbl.GetErrorErrStr(msglog);
- og_info(msglog);
- return false;
- }
- if (!tbl.Get("idcentro", idcentro)) {
- tbl.GetErrorErrStr(msglog);
- og_info(msglog);
- return false;
- }
+ idordenador = dbi_result_get_uint(result, "idordenador");
+ str = (char *)dbi_result_get_string(result, "nombreordenador");
+ sprintf(nombreordenador, "%s", str);
+ cache = dbi_result_get_uint(result, "cache");
+ idproautoexec = dbi_result_get_uint(result, "idproautoexec");
+ idaula = dbi_result_get_uint(result, "idaula");
+ idcentro = dbi_result_get_uint(result, "idcentro");
+ dbi_result_free(result);
resul = actualizaConfiguracion(db, tbl, cfg, idordenador); // Actualiza la configuración del ordenador
liberaMemoria(cfg);
+ og_dbi_close(dbi);
db.Close();
if (!resul) {
@@ -502,6 +485,13 @@ bool procesoInclusionCliente(struct og_client *cli, TRAMA *ptrTrama)
}
liberaMemoria(iph);
return true;
+
+err_query_fail:
+ og_dbi_close(dbi);
+err_dbi_open:
+ liberaMemoria(iph);
+ liberaMemoria(cfg);
+ return false;
}
// ________________________________________________________________________________________________________
// Función: actualizaConfiguracion