diff options
author | OpenGnSys Support Team <soporte-og@soleta.eu> | 2019-05-17 18:03:31 +0200 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2020-03-04 14:54:52 +0100 |
commit | da48c98a451443b9136d2d31547d40deb749fac7 (patch) | |
tree | 50a134e6e7341c134f183cb7ef38db556f26af60 | |
parent | 8a2ae26f2b4a1b0f1010dd9e825a2a71dd9fe4a5 (diff) |
#941 use dbi layer from procesoInclusionCliente()
-rw-r--r-- | admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp | 82 |
1 files changed, 36 insertions, 46 deletions
diff --git a/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp b/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp index 49b90ab5..6416a415 100644 --- a/admin/Sources/Services/ogAdmServer/sources/ogAdmServer.cpp +++ b/admin/Sources/Services/ogAdmServer/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 |