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)
|
bool procesoInclusionCliente(struct og_client *cli, TRAMA *ptrTrama)
|
||||||
{
|
{
|
||||||
int socket_c = og_client_socket(cli);
|
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;
|
Database db;
|
||||||
Table tbl;
|
Table tbl;
|
||||||
|
|
||||||
char *iph, *cfg;
|
char *iph, *cfg;
|
||||||
char nombreordenador[LONFIL];
|
char nombreordenador[LONFIL];
|
||||||
int lon, resul, idordenador, idmenu, cache, idproautoexec, idaula, idcentro;
|
int lon, resul, idordenador, cache, idproautoexec, idaula, idcentro;
|
||||||
|
|
||||||
// Toma parámetros
|
// Toma parámetros
|
||||||
iph = copiaParametro("iph",ptrTrama); // Toma ip
|
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)) {
|
if (!db.Open(usuario, pasguor, datasource, catalog)) {
|
||||||
liberaMemoria(iph);
|
liberaMemoria(iph);
|
||||||
liberaMemoria(cfg);
|
liberaMemoria(cfg);
|
||||||
db.GetErrorErrStr(msglog);
|
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
|
||||||
syslog(LOG_ERR, "cannot open connection database (%s:%d) %s\n",
|
__func__, __LINE__);
|
||||||
__func__, __LINE__, msglog);
|
|
||||||
return false;
|
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
|
// Recupera los datos del cliente
|
||||||
sprintf(sqlstr,
|
result = dbi_conn_queryf(dbi->conn,
|
||||||
"SELECT ordenadores.*,aulas.idaula,centros.idcentro FROM ordenadores "
|
"SELECT ordenadores.*,aulas.idaula,centros.idcentro FROM ordenadores "
|
||||||
" INNER JOIN aulas ON aulas.idaula=ordenadores.idaula"
|
" INNER JOIN aulas ON aulas.idaula=ordenadores.idaula"
|
||||||
" INNER JOIN centros ON centros.idcentro=aulas.idcentro"
|
" INNER JOIN centros ON centros.idcentro=aulas.idcentro"
|
||||||
" WHERE ordenadores.ip = '%s'", iph);
|
" WHERE ordenadores.ip = '%s'", iph);
|
||||||
|
|
||||||
if (!db.Execute(sqlstr, tbl)) {
|
if (!result) {
|
||||||
db.GetErrorErrStr(msglog);
|
dbi_conn_error(dbi->conn, &msglog);
|
||||||
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
|
syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
|
||||||
__func__, __LINE__, msglog);
|
__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",
|
syslog(LOG_ERR, "client does not exist in database (%s:%d)\n",
|
||||||
__func__, __LINE__);
|
__func__, __LINE__);
|
||||||
return false;
|
dbi_result_free(result);
|
||||||
|
goto err_query_fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
syslog(LOG_DEBUG, "Client %s requesting inclusion\n", iph);
|
syslog(LOG_DEBUG, "Client %s requesting inclusion\n", iph);
|
||||||
|
|
||||||
if (!tbl.Get("idordenador", idordenador)) {
|
idordenador = dbi_result_get_uint(result, "idordenador");
|
||||||
tbl.GetErrorErrStr(msglog);
|
str = (char *)dbi_result_get_string(result, "nombreordenador");
|
||||||
og_info(msglog);
|
sprintf(nombreordenador, "%s", str);
|
||||||
return false;
|
cache = dbi_result_get_uint(result, "cache");
|
||||||
}
|
idproautoexec = dbi_result_get_uint(result, "idproautoexec");
|
||||||
if (!tbl.Get("nombreordenador", nombreordenador)) {
|
idaula = dbi_result_get_uint(result, "idaula");
|
||||||
tbl.GetErrorErrStr(msglog);
|
idcentro = dbi_result_get_uint(result, "idcentro");
|
||||||
og_info(msglog);
|
dbi_result_free(result);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
resul = actualizaConfiguracion(db, tbl, cfg, idordenador); // Actualiza la configuración del ordenador
|
resul = actualizaConfiguracion(db, tbl, cfg, idordenador); // Actualiza la configuración del ordenador
|
||||||
liberaMemoria(cfg);
|
liberaMemoria(cfg);
|
||||||
|
og_dbi_close(dbi);
|
||||||
db.Close();
|
db.Close();
|
||||||
|
|
||||||
if (!resul) {
|
if (!resul) {
|
||||||
|
@ -502,6 +485,13 @@ bool procesoInclusionCliente(struct og_client *cli, TRAMA *ptrTrama)
|
||||||
}
|
}
|
||||||
liberaMemoria(iph);
|
liberaMemoria(iph);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
err_query_fail:
|
||||||
|
og_dbi_close(dbi);
|
||||||
|
err_dbi_open:
|
||||||
|
liberaMemoria(iph);
|
||||||
|
liberaMemoria(cfg);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
// ________________________________________________________________________________________________________
|
// ________________________________________________________________________________________________________
|
||||||
// Función: actualizaConfiguracion
|
// Función: actualizaConfiguracion
|
||||||
|
|
Loading…
Reference in New Issue