mirror of https://git.48k.eu/ogserver
#941 use dbi layer from procesoInclusionClienteWinLnx()
parent
2629906b6d
commit
0fbdcf260c
|
@ -8,6 +8,7 @@
|
||||||
// *******************************************************************************************************
|
// *******************************************************************************************************
|
||||||
#include "ogAdmServer.h"
|
#include "ogAdmServer.h"
|
||||||
#include "ogAdmLib.c"
|
#include "ogAdmLib.c"
|
||||||
|
#include "dbi.h"
|
||||||
#include <ev.h>
|
#include <ev.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
@ -24,6 +25,13 @@ static char catalog[LONPRM]; // Nombre de la base de datos
|
||||||
static char interface[LONPRM]; // Interface name
|
static char interface[LONPRM]; // Interface name
|
||||||
static char auth_token[LONPRM]; // API token
|
static char auth_token[LONPRM]; // API token
|
||||||
|
|
||||||
|
static struct og_dbi_config dbi_config = {
|
||||||
|
.user = usuario,
|
||||||
|
.passwd = pasguor,
|
||||||
|
.host = datasource,
|
||||||
|
.database = catalog,
|
||||||
|
};
|
||||||
|
|
||||||
//________________________________________________________________________________________________________
|
//________________________________________________________________________________________________________
|
||||||
// Función: tomaConfiguracion
|
// Función: tomaConfiguracion
|
||||||
//
|
//
|
||||||
|
@ -279,65 +287,45 @@ static bool InclusionClienteWinLnx(TRAMA *ptrTrama, struct og_client *cli)
|
||||||
// ________________________________________________________________________________________________________
|
// ________________________________________________________________________________________________________
|
||||||
bool procesoInclusionClienteWinLnx(int socket_c, TRAMA *ptrTrama, int *idordenador, char *nombreordenador)
|
bool procesoInclusionClienteWinLnx(int socket_c, TRAMA *ptrTrama, int *idordenador, char *nombreordenador)
|
||||||
{
|
{
|
||||||
char msglog[LONSTD], sqlstr[LONSQL];
|
struct og_dbi *dbi;
|
||||||
Database db;
|
const char *msglog;
|
||||||
Table tbl;
|
dbi_result result;
|
||||||
char *iph;
|
char *iph;
|
||||||
|
|
||||||
// Toma parámetros
|
// Toma parámetros
|
||||||
iph = copiaParametro("iph",ptrTrama); // Toma ip
|
iph = copiaParametro("iph",ptrTrama); // Toma ip
|
||||||
|
|
||||||
if (!db.Open(usuario, pasguor, datasource, catalog)) {
|
dbi = og_dbi_open(&dbi_config);
|
||||||
liberaMemoria(iph);
|
if (!dbi) {
|
||||||
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);
|
goto err_dbi_open;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recupera los datos del cliente
|
result = dbi_conn_queryf(dbi->conn,
|
||||||
sprintf(sqlstr,
|
|
||||||
"SELECT idordenador,nombreordenador FROM ordenadores "
|
"SELECT idordenador,nombreordenador FROM ordenadores "
|
||||||
" WHERE ordenadores.ip = '%s'", iph);
|
" WHERE ordenadores.ip = '%s'", iph);
|
||||||
|
if (!result) {
|
||||||
if (!db.Execute(sqlstr, tbl)) {
|
dbi_conn_error(dbi->conn, &msglog);
|
||||||
liberaMemoria(iph);
|
|
||||||
db.GetErrorErrStr(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);
|
||||||
db.Close();
|
goto err_query_fail;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tbl.ISEOF()) {
|
if (!dbi_result_next_row(result)) {
|
||||||
liberaMemoria(iph);
|
|
||||||
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__);
|
||||||
db.liberaResult(tbl);
|
dbi_result_free(result);
|
||||||
db.Close();
|
goto err_query_fail;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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");
|
||||||
liberaMemoria(iph);
|
nombreordenador = (char *)dbi_result_get_string(result, "nombreordenador");
|
||||||
db.liberaResult(tbl);
|
|
||||||
tbl.GetErrorErrStr(msglog);
|
dbi_result_free(result);
|
||||||
og_info(msglog);
|
og_dbi_close(dbi);
|
||||||
db.Close();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!tbl.Get("nombreordenador", nombreordenador)) {
|
|
||||||
liberaMemoria(iph);
|
|
||||||
db.liberaResult(tbl);
|
|
||||||
tbl.GetErrorErrStr(msglog);
|
|
||||||
og_info(msglog);
|
|
||||||
db.Close();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
db.liberaResult(tbl);
|
|
||||||
db.Close();
|
|
||||||
|
|
||||||
if (!registraCliente(iph)) { // Incluyendo al cliente en la tabla de sokets
|
if (!registraCliente(iph)) { // Incluyendo al cliente en la tabla de sokets
|
||||||
liberaMemoria(iph);
|
liberaMemoria(iph);
|
||||||
|
@ -346,6 +334,12 @@ bool procesoInclusionClienteWinLnx(int socket_c, TRAMA *ptrTrama, int *idordenad
|
||||||
}
|
}
|
||||||
liberaMemoria(iph);
|
liberaMemoria(iph);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
err_query_fail:
|
||||||
|
og_dbi_close(dbi);
|
||||||
|
err_dbi_open:
|
||||||
|
liberaMemoria(iph);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
// ________________________________________________________________________________________________________
|
// ________________________________________________________________________________________________________
|
||||||
// Función: InclusionCliente
|
// Función: InclusionCliente
|
||||||
|
|
Loading…
Reference in New Issue