mirror of https://git.48k.eu/ogserver
#941 use dbi layer from envioProgramacion
parent
03f1941b37
commit
39918fa970
2
Makefile
2
Makefile
|
@ -15,7 +15,7 @@ CPPFLAGS := $(CFLAGS)
|
||||||
LDFLAGS := -Wl,--no-as-needed $(shell mysql_config --libs) -lev -ljansson -ldbi
|
LDFLAGS := -Wl,--no-as-needed $(shell mysql_config --libs) -lev -ljansson -ldbi
|
||||||
|
|
||||||
# Ficheros objetos
|
# Ficheros objetos
|
||||||
OBJS := ../../Includes/Database.o sources/ogAdmServer.o sources/dbi.o
|
OBJS := sources/ogAdmServer.o sources/dbi.o
|
||||||
|
|
||||||
|
|
||||||
all: $(PROYECTO)
|
all: $(PROYECTO)
|
||||||
|
|
|
@ -2641,36 +2641,35 @@ static bool recibeArchivo(TRAMA *ptrTrama, struct og_client *cli)
|
||||||
static bool envioProgramacion(TRAMA *ptrTrama, struct og_client *cli)
|
static bool envioProgramacion(TRAMA *ptrTrama, struct og_client *cli)
|
||||||
{
|
{
|
||||||
char *ptrIP[MAXIMOS_CLIENTES],*ptrMacs[MAXIMOS_CLIENTES];
|
char *ptrIP[MAXIMOS_CLIENTES],*ptrMacs[MAXIMOS_CLIENTES];
|
||||||
char sqlstr[LONSQL], msglog[LONSTD];
|
char *idp, *iph, *mac;
|
||||||
char *idp,iph[LONIP],mac[LONMAC];
|
|
||||||
Database db;
|
|
||||||
Table tbl;
|
|
||||||
int idx,idcomando,lon;
|
int idx,idcomando,lon;
|
||||||
|
const char *msglog;
|
||||||
|
struct og_dbi *dbi;
|
||||||
|
dbi_result result;
|
||||||
|
|
||||||
if (!db.Open(usuario, pasguor, datasource, catalog)) {
|
dbi = og_dbi_open(&dbi_config);
|
||||||
db.GetErrorErrStr(msglog);
|
if (!dbi) {
|
||||||
syslog(LOG_ERR, "cannot open connection database (%s:%d) %s\n",
|
syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
|
||||||
__func__, __LINE__, msglog);
|
__func__, __LINE__);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
idp = copiaParametro("idp",ptrTrama); // Toma identificador de la programación de la tabla acciones
|
idp = copiaParametro("idp",ptrTrama); // Toma identificador de la programación de la tabla acciones
|
||||||
|
|
||||||
sprintf(sqlstr, "SELECT ordenadores.ip,ordenadores.mac,acciones.idcomando FROM acciones "\
|
result = dbi_conn_queryf(dbi->conn,
|
||||||
|
"SELECT ordenadores.ip,ordenadores.mac,acciones.idcomando FROM acciones "\
|
||||||
" INNER JOIN ordenadores ON ordenadores.ip=acciones.ip"\
|
" INNER JOIN ordenadores ON ordenadores.ip=acciones.ip"\
|
||||||
" WHERE acciones.idprogramacion=%s",idp);
|
" WHERE acciones.idprogramacion=%s",idp);
|
||||||
|
|
||||||
liberaMemoria(idp);
|
liberaMemoria(idp);
|
||||||
|
|
||||||
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);
|
||||||
|
og_dbi_close(dbi);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
db.Close();
|
|
||||||
if(tbl.ISEOF())
|
|
||||||
return true; // No existen registros
|
|
||||||
|
|
||||||
/* Prepara la trama de actualizacion */
|
/* Prepara la trama de actualizacion */
|
||||||
|
|
||||||
|
@ -2678,36 +2677,27 @@ static bool envioProgramacion(TRAMA *ptrTrama, struct og_client *cli)
|
||||||
ptrTrama->tipo=MSG_COMANDO;
|
ptrTrama->tipo=MSG_COMANDO;
|
||||||
sprintf(ptrTrama->parametros, "nfn=Actualizar\r");
|
sprintf(ptrTrama->parametros, "nfn=Actualizar\r");
|
||||||
|
|
||||||
while (!tbl.ISEOF()) { // Recorre particiones
|
while (dbi_result_next_row(result)) {
|
||||||
if (!tbl.Get("ip", iph)) {
|
iph = (char *)dbi_result_get_string(result, "ip");
|
||||||
tbl.GetErrorErrStr(msglog);
|
idcomando = dbi_result_get_uint(result, "idcomando");
|
||||||
syslog(LOG_ERR, "cannot find ip column in table: %s\n",
|
|
||||||
msglog);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!tbl.Get("idcomando", idcomando)) {
|
|
||||||
tbl.GetErrorErrStr(msglog);
|
|
||||||
syslog(LOG_ERR, "cannot find idcomando column in table: %s\n",
|
|
||||||
msglog);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if(idcomando==1){ // Arrancar
|
|
||||||
if (!tbl.Get("mac", mac)) {
|
|
||||||
tbl.GetErrorErrStr(msglog);
|
|
||||||
syslog(LOG_ERR, "cannot find mac column in table: %s\n",
|
|
||||||
msglog);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (idcomando == 1){ // Arrancar
|
||||||
|
mac = (char *)dbi_result_get_string(result, "mac");
|
||||||
lon = splitCadena(ptrIP, iph, ';');
|
lon = splitCadena(ptrIP, iph, ';');
|
||||||
lon = splitCadena(ptrMacs, mac, ';');
|
lon = splitCadena(ptrMacs, mac, ';');
|
||||||
|
|
||||||
// Se manda por broadcast y por unicast
|
// Se manda por broadcast y por unicast
|
||||||
if (!Levanta(ptrIP, ptrMacs, lon, (char*)"1"))
|
if (!Levanta(ptrIP, ptrMacs, lon, (char*)"1")) {
|
||||||
|
dbi_result_free(result);
|
||||||
|
og_dbi_close(dbi);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!Levanta(ptrIP, ptrMacs, lon, (char*)"2"))
|
if (!Levanta(ptrIP, ptrMacs, lon, (char*)"2")) {
|
||||||
|
dbi_result_free(result);
|
||||||
|
og_dbi_close(dbi);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (clienteDisponible(iph, &idx)) { // Si el cliente puede recibir comandos
|
if (clienteDisponible(iph, &idx)) { // Si el cliente puede recibir comandos
|
||||||
|
@ -2720,8 +2710,10 @@ static bool envioProgramacion(TRAMA *ptrTrama, struct og_client *cli)
|
||||||
}
|
}
|
||||||
//close(tbsockets[idx].sock); // Cierra el socket del cliente hasta nueva disponibilidad
|
//close(tbsockets[idx].sock); // Cierra el socket del cliente hasta nueva disponibilidad
|
||||||
}
|
}
|
||||||
tbl.MoveNext();
|
|
||||||
}
|
}
|
||||||
|
dbi_result_free(result);
|
||||||
|
og_dbi_close(dbi);
|
||||||
|
|
||||||
return true; // No existen registros
|
return true; // No existen registros
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include </usr/include/mysql/mysql.h>
|
#include </usr/include/mysql/mysql.h>
|
||||||
#include "Database.h"
|
|
||||||
#include "ogAdmLib.h"
|
#include "ogAdmLib.h"
|
||||||
// ________________________________________________________________________________________________________
|
// ________________________________________________________________________________________________________
|
||||||
// Variables globales
|
// Variables globales
|
||||||
|
|
Loading…
Reference in New Issue