mirror of https://git.48k.eu/ogserver
#941 use dbi layer from procesoInclusionCliente()
parent
1d801be52c
commit
0fde10b973
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue