[3ec149c] | 1 | // ********************************************************************************************************
|
---|
| 2 | // Servicio: ogAdmAgent
|
---|
| 3 | // Autor: José Manuel Alonso (E.T.S.I.I.) Universidad de Sevilla
|
---|
| 4 | // Fecha Creación: Marzo-2010
|
---|
| 5 | // Fecha Última modificación: Marzo-2010
|
---|
| 6 | // Nombre del fichero: ogAdmAgent.cpp
|
---|
| 7 | // Descripción: Este fichero implementa el servicio agente del sistema. Revisa a intervalos
|
---|
| 8 | // regulares la base de datos para comprobar si existen acciones programadas.
|
---|
| 9 | // ********************************************************************************************************
|
---|
| 10 | #include "ogAdmAgent.h"
|
---|
| 11 | #include "ogAdmLib.c"
|
---|
| 12 | //________________________________________________________________________________________________________
|
---|
| 13 | // Función: tomaConfiguracion
|
---|
| 14 | //
|
---|
| 15 | // Descripción:
|
---|
| 16 | // Lee el fichero de configuración del servicio
|
---|
| 17 | // Parámetros:
|
---|
| 18 | // filecfg : Ruta completa al fichero de configuración
|
---|
| 19 | // Devuelve:
|
---|
| 20 | // TRUE: Si el proceso es correcto
|
---|
| 21 | // FALSE: En caso de ocurrir algún error
|
---|
| 22 | //________________________________________________________________________________________________________
|
---|
| 23 | BOOLEAN tomaConfiguracion(char* filecfg)
|
---|
| 24 | {
|
---|
| 25 | char modulo[] = "tomaConfiguracion()";
|
---|
| 26 |
|
---|
| 27 | if (filecfg == NULL || strlen(filecfg) == 0) {
|
---|
| 28 | errorLog(modulo, 1, FALSE); // Fichero de configuración del servicio vacío
|
---|
| 29 | return (FALSE);
|
---|
| 30 | }
|
---|
| 31 | FILE *fcfg;
|
---|
| 32 | long lSize;
|
---|
| 33 | char * buffer, *lineas[MAXPRM], *dualparametro[2];
|
---|
| 34 | int i, numlin, resul;
|
---|
| 35 |
|
---|
| 36 | fcfg = fopen(filecfg, "rt");
|
---|
| 37 | if (fcfg == NULL) {
|
---|
| 38 | errorLog(modulo, 2, FALSE); // No existe fichero de configuración del servicio
|
---|
| 39 | return (FALSE);
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | fseek(fcfg, 0, SEEK_END);
|
---|
| 43 | lSize = ftell(fcfg); // Obtiene tamaño del fichero.
|
---|
| 44 | rewind(fcfg);
|
---|
| 45 | buffer = (char*) reservaMemoria(lSize + 1); // Toma memoria para el buffer de lectura.
|
---|
| 46 | if (buffer == NULL) { // No hay memoria suficiente para el buffer
|
---|
| 47 | errorLog(modulo, 3, FALSE);
|
---|
| 48 | return (FALSE);
|
---|
| 49 | }
|
---|
| 50 | fread(buffer, 1, lSize, fcfg); // Lee contenido del fichero
|
---|
| 51 | buffer[lSize] = (char) NULL;
|
---|
| 52 | fclose(fcfg);
|
---|
| 53 |
|
---|
| 54 | servidoradm[0] = (char) NULL; //inicializar variables globales
|
---|
| 55 | puerto[0] = (char) NULL;
|
---|
| 56 | usuario[0] = (char) NULL;
|
---|
| 57 | pasguor[0] = (char) NULL;
|
---|
| 58 | datasource[0] = (char) NULL;
|
---|
| 59 | catalog[0] = (char) NULL;
|
---|
| 60 |
|
---|
| 61 | numlin = splitCadena(lineas, buffer, '\n');
|
---|
[fc480f2] | 62 | liberaMemoria(buffer);
|
---|
[3ec149c] | 63 | for (i = 0; i < numlin; i++) {
|
---|
| 64 | splitCadena(dualparametro, lineas[i], '=');
|
---|
| 65 | resul = strcmp(StrToUpper(dualparametro[0]), "SERVIDORADM");
|
---|
| 66 | if (resul == 0)
|
---|
| 67 | strcpy(servidoradm, dualparametro[1]);
|
---|
| 68 | resul = strcmp(StrToUpper(dualparametro[0]), "PUERTO");
|
---|
| 69 | if (resul == 0)
|
---|
| 70 | strcpy(puerto, dualparametro[1]);
|
---|
| 71 | resul = strcmp(StrToUpper(dualparametro[0]), "USUARIO");
|
---|
| 72 | if (resul == 0)
|
---|
| 73 | strcpy(usuario, dualparametro[1]);
|
---|
| 74 | resul = strcmp(StrToUpper(dualparametro[0]), "PASSWORD");
|
---|
| 75 | if (resul == 0)
|
---|
| 76 | strcpy(pasguor, dualparametro[1]);
|
---|
| 77 | resul = strcmp(StrToUpper(dualparametro[0]), "DATASOURCE");
|
---|
| 78 | if (resul == 0)
|
---|
| 79 | strcpy(datasource, dualparametro[1]);
|
---|
| 80 | resul = strcmp(StrToUpper(dualparametro[0]), "CATALOG");
|
---|
| 81 | if (resul == 0)
|
---|
| 82 | strcpy(catalog, dualparametro[1]);
|
---|
| 83 | }
|
---|
| 84 | if (servidoradm[0] == (char) NULL) {
|
---|
| 85 | errorLog(modulo, 4, FALSE); // Falta parámetro SERVIDORADM
|
---|
| 86 | return (FALSE);
|
---|
| 87 | }
|
---|
| 88 | if (puerto[0] == (char) NULL) {
|
---|
| 89 | errorLog(modulo, 5, FALSE); // Falta parámetro PUERTO
|
---|
| 90 | return (FALSE);
|
---|
| 91 | }
|
---|
| 92 | if (usuario[0] == (char) NULL) {
|
---|
| 93 | errorLog(modulo, 6, FALSE); // Falta parámetro USUARIO
|
---|
| 94 | return (FALSE);
|
---|
| 95 | }
|
---|
| 96 | if (pasguor[0] == (char) NULL) {
|
---|
| 97 | errorLog(modulo, 7, FALSE); // Falta parámetro PASSWORD
|
---|
| 98 | return (FALSE);
|
---|
| 99 | }
|
---|
| 100 | if (datasource[0] == (char) NULL) {
|
---|
| 101 | errorLog(modulo, 8, FALSE); // Falta parámetro DATASOURCE
|
---|
| 102 | return (FALSE);
|
---|
| 103 | }
|
---|
| 104 | if (catalog[0] == (char) NULL) {
|
---|
| 105 | errorLog(modulo, 9, FALSE); // Falta parámetro CATALOG
|
---|
| 106 | return (FALSE);
|
---|
| 107 | }
|
---|
| 108 | return (TRUE);
|
---|
| 109 | }
|
---|
| 110 | // ________________________________________________________________________________________________________
|
---|
| 111 | //
|
---|
| 112 | // Función: diadelaSemana
|
---|
| 113 | //
|
---|
| 114 | // Descripción:
|
---|
| 115 | // Calcula el número del día de la semana que corresponde a una fecha
|
---|
| 116 | // Parámetros:
|
---|
| 117 | // - dia: Un día
|
---|
| 118 | // - mes: Un mes
|
---|
| 119 | // - anno: Un año
|
---|
| 120 | // Devuelve:
|
---|
| 121 | // El número del día de la semana: 1=Lunes, 2=martes ... 6=sábado 7=domingo
|
---|
| 122 | // ________________________________________________________________________________________________________
|
---|
| 123 |
|
---|
| 124 | int diadelaSemana(WORD dia,WORD mes,WORD anno)
|
---|
| 125 | {
|
---|
| 126 | int i,cont,dias_anuales;
|
---|
| 127 | int desplazamiento_dias=6;
|
---|
| 128 | int orddiasem;
|
---|
| 129 |
|
---|
| 130 | cont =0;
|
---|
| 131 | for (i=1900;i<anno;i++){
|
---|
| 132 | if (bisiesto(i)) dias_anuales=366; else dias_anuales=365;
|
---|
| 133 | cont+=dias_anuales;
|
---|
| 134 | }
|
---|
| 135 | for (i=1;i<mes;i++){
|
---|
| 136 | if (i!=2)
|
---|
| 137 | cont+=dias_meses[i];
|
---|
| 138 | else{
|
---|
| 139 | if (bisiesto(anno))
|
---|
| 140 | cont+=29;
|
---|
| 141 | else
|
---|
| 142 | cont+=28;
|
---|
| 143 | }
|
---|
| 144 | }
|
---|
| 145 | cont+=dia+desplazamiento_dias;
|
---|
| 146 | orddiasem=(cont%7);
|
---|
| 147 | if(orddiasem==0) orddiasem=7;
|
---|
| 148 | return(orddiasem);
|
---|
| 149 | }
|
---|
| 150 | // ________________________________________________________________________________________________________
|
---|
| 151 | //
|
---|
| 152 | // Función: bisiesto
|
---|
| 153 | //
|
---|
| 154 | // Descripción:
|
---|
| 155 | // Calcula si un año es bisiesto o no lo es
|
---|
| 156 | // Parámetros:
|
---|
| 157 | // - anno: Un año
|
---|
| 158 | // Devuelve:
|
---|
| 159 | // TRUE si el año es bisiesto
|
---|
| 160 | // FALSE si no es bisiesto
|
---|
| 161 | // ________________________________________________________________________________________________________
|
---|
| 162 |
|
---|
| 163 | BOOLEAN bisiesto(WORD anno){
|
---|
| 164 | return(anno%4==0);
|
---|
| 165 | }
|
---|
| 166 | // ________________________________________________________________________________________________________
|
---|
| 167 | //
|
---|
| 168 | // Función: semanadelMes
|
---|
| 169 | //
|
---|
| 170 | // Descripción:
|
---|
| 171 | // Calcula el número de semana perteneciente a un día del mes
|
---|
| 172 | // Parámetros:
|
---|
| 173 | // - ordiasem_1: Orden semanal (1,2...) del primer dia del mes que se pasa como parámetro
|
---|
| 174 | // - diames: El mes concreto
|
---|
| 175 | // Devuelve:
|
---|
| 176 | // El número del día de la semana: 1=Lunes, 2=martes ... 6=sábado 7=domingo , de ese mes
|
---|
| 177 | // ________________________________________________________________________________________________________
|
---|
| 178 |
|
---|
| 179 | int semanadelMes(int ordiasem_1,int diames)
|
---|
| 180 | {
|
---|
| 181 | int nwdia,resto,cociente;
|
---|
| 182 |
|
---|
| 183 | nwdia=diames+ordiasem_1-1;
|
---|
| 184 | cociente=nwdia/7;
|
---|
| 185 | resto=nwdia%7;
|
---|
| 186 | if(resto>0) cociente++;
|
---|
| 187 | return(cociente);
|
---|
| 188 | }
|
---|
| 189 | // ________________________________________________________________________________________________________
|
---|
| 190 | //
|
---|
| 191 | // Función: buscaAccion
|
---|
| 192 | //
|
---|
| 193 | // Descripción:
|
---|
| 194 | // Busca en la base de datos, acciones programadas
|
---|
| 195 | // Parámetros:
|
---|
| 196 | // - db: Objeto base de datos (operativo)
|
---|
| 197 | // - dia : Día actual del mes
|
---|
| 198 | // - mes : mes en curso
|
---|
| 199 | // - anno : Año en curso
|
---|
| 200 | // - hora : Hora actual
|
---|
| 201 | // - minutos : Minutos actuales
|
---|
| 202 | // - diasemana : Dia de la semana 1=lunes,2=martes ... ( 0 Domingo)
|
---|
| 203 | // Devuelve:
|
---|
| 204 | // TRUE: Si el proceso es correcto
|
---|
| 205 | // FALSE: En caso de ocurrir algún error
|
---|
| 206 | // ________________________________________________________________________________________________________
|
---|
| 207 |
|
---|
| 208 | BOOLEAN buscaAccion(Database db,WORD dia,WORD mes,WORD anno,WORD hora,WORD minutos,WORD diasemana)
|
---|
| 209 | {
|
---|
| 210 | char msglog[LONSTD], sqlstr[LONSQL];
|
---|
| 211 | Table tbl;
|
---|
| 212 | BYTE swampm,bitsemana;
|
---|
| 213 | int ordsem,ordulsem,ordiasem_1,maxdias;
|
---|
| 214 | int sesionprog;
|
---|
| 215 | char modulo[] = "buscaAccion()";
|
---|
| 216 |
|
---|
| 217 | /* Año de comienzo */
|
---|
| 218 | anno=anno-ANNOREF; //
|
---|
| 219 | /* Preparación hora */
|
---|
| 220 | if(hora>11){
|
---|
| 221 | hora-=12;
|
---|
| 222 | swampm=1; // Es P.M.
|
---|
| 223 | }
|
---|
| 224 | else
|
---|
| 225 | swampm=0; // Es am
|
---|
| 226 | /* Preparación semana */
|
---|
| 227 | if(diasemana==0) diasemana=7; // El domingo
|
---|
| 228 |
|
---|
| 229 | // Cuestión semanas
|
---|
| 230 | ordiasem_1=diadelaSemana(1,mes,anno+2009);
|
---|
| 231 | ordsem=semanadelMes(ordiasem_1,dia); // Calcula el número de la semana
|
---|
| 232 | if (mes!=2) // Toma el último día de ese mes
|
---|
| 233 | maxdias=dias_meses[mes];
|
---|
| 234 | else{
|
---|
| 235 | if (bisiesto(anno+ANNOREF))
|
---|
| 236 | maxdias=29;
|
---|
| 237 | else
|
---|
| 238 | maxdias=28;
|
---|
| 239 | }
|
---|
| 240 | ordulsem=semanadelMes(ordiasem_1,maxdias); // Calcula el número de la última semana
|
---|
| 241 | bitsemana=HEX_semanas[ordsem];
|
---|
| 242 | if(ordsem==ordulsem) // Si es la última semana del mes
|
---|
| 243 | bitsemana|=HEX_semanas[6];
|
---|
| 244 |
|
---|
| 245 | sprintf(sqlstr,"SELECT DISTINCT idprogramacion,tipoaccion,identificador,sesion,idcentro,"\
|
---|
| 246 | "tareas.descripcion as descritarea"\
|
---|
| 247 | " FROM programaciones"\
|
---|
| 248 | " LEFT OUTER JOIN tareas ON tareas.idtarea=programaciones.identificador"\
|
---|
| 249 | " WHERE suspendida=0 "\
|
---|
| 250 | " AND (annos & %d <> 0) "\
|
---|
| 251 | " AND (meses & %d<>0) "\
|
---|
| 252 | " AND ((diario & %d<>0) OR (dias & %d<>0) OR (semanas & %d<>0))"\
|
---|
| 253 | " AND (horas & %d<>0) AND ampm=%d AND minutos=%d",\
|
---|
| 254 | HEX_annos[anno],\
|
---|
| 255 | HEX_meses[mes],\
|
---|
| 256 | HEX_dias[dia],\
|
---|
| 257 | HEX_diasemana[diasemana],\
|
---|
| 258 | bitsemana,\
|
---|
| 259 | HEX_horas[hora],\
|
---|
| 260 | swampm,minutos);
|
---|
| 261 |
|
---|
| 262 | if (!db.Execute(sqlstr, tbl)) { // Error al leer
|
---|
| 263 | errorLog(modulo, 21, FALSE);
|
---|
| 264 | db.GetErrorErrStr(msglog);
|
---|
| 265 | errorInfo(modulo, msglog);
|
---|
| 266 | return (FALSE);
|
---|
| 267 | }
|
---|
| 268 | if(tbl.ISEOF()){
|
---|
| 269 | return(TRUE); // No hay acciones programadas
|
---|
| 270 | }
|
---|
| 271 |
|
---|
| 272 | while(!tbl.ISEOF()){
|
---|
| 273 | if(!tbl.Get("idprogramacion",idprogramacion)){
|
---|
| 274 | tbl.GetErrorErrStr(msglog);
|
---|
| 275 | errorInfo(modulo, msglog);
|
---|
| 276 | return (FALSE);
|
---|
| 277 | }
|
---|
| 278 | if(!tbl.Get("tipoaccion",tipoaccion)){
|
---|
| 279 | tbl.GetErrorErrStr(msglog);
|
---|
| 280 | errorInfo(modulo, msglog);
|
---|
| 281 | return (FALSE);
|
---|
| 282 | }
|
---|
| 283 | if(!tbl.Get("identificador",idtipoaccion)){
|
---|
| 284 | tbl.GetErrorErrStr(msglog);
|
---|
| 285 | errorInfo(modulo, msglog);
|
---|
| 286 | return (FALSE);
|
---|
| 287 | }
|
---|
| 288 | if(!tbl.Get("sesion",sesionprog)){
|
---|
| 289 | tbl.GetErrorErrStr(msglog);
|
---|
| 290 | errorInfo(modulo, msglog);
|
---|
| 291 | return (FALSE);
|
---|
| 292 | }
|
---|
| 293 | if(!tbl.Get("idcentro",idcentro)){
|
---|
| 294 | tbl.GetErrorErrStr(msglog);
|
---|
| 295 | errorInfo(modulo, msglog);
|
---|
| 296 | return (FALSE);
|
---|
| 297 | }
|
---|
| 298 |
|
---|
| 299 | if(tipoaccion==EJECUCION_COMANDO){ // Es una programación de un comando
|
---|
| 300 | return(ejecutarComando(db,idprogramacion,sesionprog));
|
---|
| 301 | }
|
---|
| 302 | else{
|
---|
| 303 |
|
---|
| 304 | if(tipoaccion==EJECUCION_TAREA){
|
---|
| 305 | if(!tbl.Get("descritarea",descriaccion)){
|
---|
| 306 | tbl.GetErrorErrStr(msglog);
|
---|
| 307 | errorInfo(modulo, msglog);
|
---|
| 308 | return (FALSE);
|
---|
| 309 | }
|
---|
| 310 | return(ejecutarTarea(db,idprogramacion,idtipoaccion));
|
---|
| 311 | }
|
---|
| 312 | else{
|
---|
| 313 | if(tipoaccion==EJECUCION_RESERVA){
|
---|
| 314 | EjecutarReserva(idtipoaccion,db); // Es una programación de un trabajo
|
---|
| 315 | }
|
---|
| 316 | }
|
---|
| 317 | }
|
---|
| 318 | tbl.MoveNext();
|
---|
| 319 | }
|
---|
| 320 | return(TRUE);
|
---|
| 321 | }
|
---|
| 322 | // ________________________________________________________________________________________________________
|
---|
| 323 | //
|
---|
| 324 | // Función: ejecutarComando
|
---|
| 325 | //
|
---|
| 326 | // Descripción:
|
---|
| 327 | // Ejecuta un comando programado
|
---|
| 328 | // Parámetros:
|
---|
| 329 | // - db: Objeto base de datos (operativo)
|
---|
| 330 | // - idcomando: Identificador del comando
|
---|
| 331 | // - sesion: Sesión correspondiente al comando cuando se grabó en la tabla acciones
|
---|
| 332 | // Devuelve:
|
---|
| 333 | // TRUE: Si el proceso es correcto
|
---|
| 334 | // FALSE: En caso de ocurrir algún error
|
---|
| 335 | // ________________________________________________________________________________________________________
|
---|
| 336 |
|
---|
| 337 | BOOLEAN ejecutarComando(Database db,int idprogramacion,int sesion )
|
---|
| 338 | {
|
---|
| 339 | struct tm* st;
|
---|
| 340 | char msglog[LONSTD], sqlstr[LONSQL];
|
---|
| 341 | char fechahorareg[24];
|
---|
| 342 | char modulo[] = "ejecutarComando()";
|
---|
| 343 |
|
---|
| 344 | st = tomaHora();
|
---|
| 345 | sprintf(fechahorareg,"%d/%d/%d %d:%d:%d", st->tm_year + 1900, st->tm_mon + 1,
|
---|
| 346 | st->tm_mday, st->tm_hour, st->tm_min, st->tm_sec);
|
---|
| 347 |
|
---|
| 348 | sprintf(sqlstr,"UPDATE acciones SET estado=%d,idprogramacion=%d,fechahorareg='%s'"\
|
---|
| 349 | " WHERE sesion=%d", ACCION_INICIADA,idprogramacion,fechahorareg,sesion);
|
---|
| 350 |
|
---|
| 351 | if (!db.Execute(sqlstr)) { // Error al recuperar los datos
|
---|
| 352 | errorLog(modulo, 21, FALSE);
|
---|
| 353 | db.GetErrorErrStr(msglog);
|
---|
| 354 | errorInfo(modulo, msglog);
|
---|
| 355 | return (FALSE);
|
---|
| 356 | }
|
---|
| 357 | return(enviaPeticion(idprogramacion));
|
---|
| 358 | }
|
---|
| 359 | // ________________________________________________________________________________________________________
|
---|
| 360 | //
|
---|
| 361 | // Función: ejecutarProcedimiento
|
---|
| 362 | //
|
---|
| 363 | // Descripción:
|
---|
| 364 | // Ejecuta un procedimiento programado
|
---|
| 365 | // Parámetros:
|
---|
| 366 | // - db: Objeto base de datos (operativo)
|
---|
| 367 | // - idprocedimiento: Identificador del procedimiento
|
---|
| 368 | // - ambito: Ámbito de aplicación
|
---|
| 369 | // - idambito: Identificador del ámbito
|
---|
| 370 | // - restrambito: cadena con los identificadores de los ordenadores a los que se aplica la acción
|
---|
| 371 | // Devuelve:
|
---|
| 372 | // TRUE: Si el proceso es correcto
|
---|
| 373 | // FALSE: En caso de ocurrir algún error
|
---|
| 374 | // ________________________________________________________________________________________________________
|
---|
| 375 |
|
---|
| 376 | BOOLEAN ejecutarProcedimiento(Database db,int idprocedimiento,int ambito,int idambito,char* restrambito)
|
---|
| 377 | {
|
---|
| 378 | char msglog[LONSTD], sqlstr[LONSQL],*parametros;
|
---|
| 379 | Table tbl;
|
---|
| 380 | int procedimientoid,idcomando,lonprm;
|
---|
| 381 | char modulo[] = "ejecutarProcedimiento()";
|
---|
| 382 |
|
---|
| 383 | sprintf(sqlstr,"SELECT idcomando,procedimientoid,parametros,length(parametros) as lonprm"\
|
---|
| 384 | " FROM procedimientos_acciones"\
|
---|
| 385 | " WHERE idprocedimiento=%d ORDER BY orden",idprocedimiento);
|
---|
| 386 |
|
---|
| 387 | if (!db.Execute(sqlstr, tbl)) { // Error al leer
|
---|
| 388 | errorLog(modulo, 21, FALSE);
|
---|
| 389 | db.GetErrorErrStr(msglog);
|
---|
| 390 | errorInfo(modulo, msglog);
|
---|
| 391 | return (FALSE);
|
---|
| 392 | }
|
---|
| 393 |
|
---|
| 394 | if(tbl.ISEOF()){
|
---|
| 395 | return(TRUE); // No exustde tarea
|
---|
| 396 | }
|
---|
| 397 | while(!tbl.ISEOF()){
|
---|
| 398 | if(!tbl.Get("procedimientoid",procedimientoid)){
|
---|
| 399 | tbl.GetErrorErrStr(msglog);
|
---|
| 400 | errorInfo(modulo, msglog);
|
---|
| 401 | return (FALSE);
|
---|
| 402 | }
|
---|
| 403 | if(procedimientoid>0){ // Procedimiento recursivo
|
---|
| 404 | if(!ejecutarProcedimiento(db,procedimientoid,ambito,idambito,restrambito)){
|
---|
| 405 | return(false);
|
---|
| 406 | }
|
---|
| 407 | }
|
---|
| 408 | else{
|
---|
| 409 | if(!tbl.Get("lonprm",lonprm)){
|
---|
| 410 | tbl.GetErrorErrStr(msglog);
|
---|
| 411 | errorInfo(modulo, msglog);
|
---|
| 412 | return (FALSE);
|
---|
| 413 | }
|
---|
| 414 | parametros = reservaMemoria(lonprm+1); // Reserva para almacenar los parametros del procedimiento
|
---|
| 415 | if (parametros == NULL) {
|
---|
| 416 | errorLog(modulo, 3, FALSE);
|
---|
| 417 | return (FALSE);
|
---|
| 418 | }
|
---|
| 419 | if(!tbl.Get("parametros",parametros)){
|
---|
| 420 | tbl.GetErrorErrStr(msglog);
|
---|
| 421 | errorInfo(modulo, msglog);
|
---|
[fc480f2] | 422 | liberaMemoria(parametros);
|
---|
[3ec149c] | 423 | return (FALSE);
|
---|
[fc480f2] | 424 | }
|
---|
| 425 | liberaMemoria(parametros);
|
---|
[3ec149c] | 426 | if(!tbl.Get("idcomando",idcomando)){
|
---|
| 427 | tbl.GetErrorErrStr(msglog);
|
---|
| 428 | errorInfo(modulo, msglog);
|
---|
| 429 | return (FALSE);
|
---|
[fc480f2] | 430 | }
|
---|
[3ec149c] | 431 |
|
---|
| 432 | if(!insertaComando(db,idcomando,parametros,idprocedimiento,ambito,idambito,restrambito))
|
---|
| 433 | return(false);
|
---|
| 434 | }
|
---|
| 435 | tbl.MoveNext();
|
---|
| 436 | }
|
---|
| 437 | return(TRUE);
|
---|
| 438 | }
|
---|
| 439 | // ________________________________________________________________________________________________________
|
---|
| 440 | //
|
---|
| 441 | // Función: ejecutarTarea
|
---|
| 442 | //
|
---|
| 443 | // Descripción:
|
---|
| 444 | // Ejecuta una tarea programada
|
---|
| 445 | // Parámetros:
|
---|
| 446 | // - db: Objeto base de datos (operativo)
|
---|
| 447 | // - idtarea: Identificador de la tarea
|
---|
| 448 | // - idprogramacion: Identificador de la programación
|
---|
| 449 | // Devuelve:
|
---|
| 450 | // TRUE: Si el proceso es correcto
|
---|
| 451 | // FALSE: En caso de ocurrir algún error
|
---|
| 452 | // ________________________________________________________________________________________________________
|
---|
| 453 |
|
---|
| 454 | BOOLEAN ejecutarTarea(Database db, int idprogramacion, int idtarea)
|
---|
| 455 | {
|
---|
| 456 | char msglog[LONSTD], sqlstr[LONSQL];
|
---|
| 457 | Table tbl;
|
---|
| 458 | int tareaid,ambito,idambito,idprocedimiento,lonrestrambito;
|
---|
| 459 | char* restrambito;
|
---|
| 460 | char modulo[] = "ejecutarTarea()";
|
---|
| 461 |
|
---|
| 462 | sprintf(sqlstr,"SELECT tareas_acciones.orden,tareas_acciones.idprocedimiento,tareas_acciones.tareaid,"\
|
---|
[fc480f2] | 463 | " tareas.ambito,tareas.idambito,tareas.restrambito,length(tareas.restrambito) as lonrestrambito"\
|
---|
| 464 | " FROM tareas"\
|
---|
| 465 | " INNER JOIN tareas_acciones ON tareas_acciones.idtarea=tareas.idtarea"\
|
---|
| 466 | " WHERE tareas_acciones.idtarea=%d ORDER BY tareas_acciones.orden",idtarea);
|
---|
[3ec149c] | 467 |
|
---|
| 468 | if (!db.Execute(sqlstr, tbl)) { // Error al leer
|
---|
| 469 | errorLog(modulo, 21, FALSE);
|
---|
| 470 | db.GetErrorErrStr(msglog);
|
---|
| 471 | errorInfo(modulo, msglog);
|
---|
| 472 | return (FALSE);
|
---|
| 473 | }
|
---|
| 474 |
|
---|
| 475 | if(tbl.ISEOF()){
|
---|
| 476 | return(TRUE); // No existe tarea
|
---|
| 477 | }
|
---|
| 478 |
|
---|
| 479 | while(!tbl.ISEOF()){
|
---|
| 480 | if(!tbl.Get("tareaid",tareaid)){
|
---|
| 481 | tbl.GetErrorErrStr(msglog);
|
---|
| 482 | errorInfo(modulo, msglog);
|
---|
| 483 | return (FALSE);
|
---|
| 484 | }
|
---|
| 485 | if(tareaid>0){ // Tarea recursiva
|
---|
| 486 | if(!ejecutarTarea(db,idprogramacion,tareaid)){
|
---|
| 487 | return(false);
|
---|
| 488 | }
|
---|
| 489 | }
|
---|
| 490 | else{
|
---|
| 491 | if(!tbl.Get("ambito",ambito)){
|
---|
| 492 | tbl.GetErrorErrStr(msglog);
|
---|
| 493 | errorInfo(modulo, msglog);
|
---|
| 494 | return (FALSE);
|
---|
| 495 | }
|
---|
| 496 | if(!tbl.Get("idambito",idambito)){
|
---|
| 497 | tbl.GetErrorErrStr(msglog);
|
---|
| 498 | errorInfo(modulo, msglog);
|
---|
| 499 | return (FALSE);
|
---|
| 500 | }
|
---|
| 501 | if(!tbl.Get("lonrestrambito",lonrestrambito)){
|
---|
| 502 | tbl.GetErrorErrStr(msglog);
|
---|
| 503 | errorInfo(modulo, msglog);
|
---|
| 504 | return (FALSE);
|
---|
| 505 | }
|
---|
| 506 | restrambito = reservaMemoria(lonrestrambito+1);
|
---|
| 507 | if (restrambito == NULL) {
|
---|
| 508 | errorLog(modulo, 3, FALSE);
|
---|
| 509 | return (FALSE);
|
---|
| 510 | }
|
---|
| 511 | if(!tbl.Get("restrambito",restrambito)){
|
---|
| 512 | tbl.GetErrorErrStr(msglog);
|
---|
| 513 | errorInfo(modulo, msglog);
|
---|
[fc480f2] | 514 | liberaMemoria(restrambito);
|
---|
[3ec149c] | 515 | return (FALSE);
|
---|
| 516 | }
|
---|
[fc480f2] | 517 | liberaMemoria(restrambito);
|
---|
[3ec149c] | 518 | RecopilaIpesMacs(db,ambito,idambito,restrambito); // Recopila Ipes del ámbito
|
---|
| 519 | if(!tbl.Get("idprocedimiento",idprocedimiento)){
|
---|
| 520 | tbl.GetErrorErrStr(msglog);
|
---|
| 521 | errorInfo(modulo, msglog);
|
---|
| 522 | return (FALSE);
|
---|
[fc480f2] | 523 | }
|
---|
[3ec149c] | 524 | sesion=time(NULL);
|
---|
| 525 |
|
---|
| 526 | if(!ejecutarProcedimiento(db,idprocedimiento,ambito,idambito,restrambito))
|
---|
| 527 | return(FALSE);
|
---|
| 528 | }
|
---|
| 529 | tbl.MoveNext();
|
---|
| 530 | }
|
---|
| 531 | return(enviaPeticion(idprogramacion));
|
---|
| 532 | }
|
---|
| 533 | // ________________________________________________________________________________________________________
|
---|
| 534 | //
|
---|
| 535 | // Función: ejecutarTarea
|
---|
| 536 | //
|
---|
| 537 | // Descripción:
|
---|
| 538 | // Registra un procedimiento para un ambito concreto
|
---|
| 539 | // Parámetros:
|
---|
| 540 | // - db: Objeto base de datos (operativo)
|
---|
| 541 | // - idcomando: Identificador del comando
|
---|
| 542 | // - idprocedimiento: Identificador del procedimiento
|
---|
| 543 | // - ambito: Ámbito de aplicación
|
---|
| 544 | // - idambito: Identificador del ámbito
|
---|
| 545 | // - restrambito: cadena con los identificadores de los ordenadores a los que se aplica la acción
|
---|
| 546 | // Devuelve:
|
---|
| 547 | // TRUE: Si el proceso es correcto
|
---|
| 548 | // FALSE: En caso de ocurrir algún error
|
---|
| 549 | //________________________________________________________________________________________________________
|
---|
| 550 | BOOLEAN insertaComando(Database db,int idcomando,char*parametros,int idprocedimiento,int ambito,int idambito,char*restrambito)
|
---|
| 551 | {
|
---|
| 552 | char msglog[LONSTD], sqlstr[LONSQL];
|
---|
| 553 | struct tm* st;
|
---|
| 554 | char *auxID[MAXIMOS_CLIENTES],*auxIP[MAXIMOS_CLIENTES];
|
---|
| 555 | char fechahorareg[24];
|
---|
| 556 | int i;
|
---|
| 557 | char modulo[] = "insertaComando()";
|
---|
| 558 |
|
---|
| 559 | if(concli==0) return(TRUE); // No hay ordenadores en el ámbito
|
---|
| 560 |
|
---|
| 561 | st = tomaHora();
|
---|
| 562 | sprintf(fechahorareg,"%d/%d/%d %d:%d:%d", st->tm_year + 1900, st->tm_mon + 1, st->tm_mday, st->tm_hour, st->tm_min, st->tm_sec);
|
---|
| 563 |
|
---|
| 564 | splitCadena(auxID,cadenaid,',');
|
---|
| 565 | splitCadena(auxIP,cadenaip,';');
|
---|
| 566 |
|
---|
| 567 | for (i=0;i<concli;i++){
|
---|
| 568 | sprintf(sqlstr,"INSERT INTO acciones (idordenador,tipoaccion,idtipoaccion,descriaccion,ip,"\
|
---|
| 569 | "sesion,idcomando,parametros,fechahorareg,estado,resultado,ambito,idambito,"\
|
---|
| 570 | "restrambito,idprocedimiento,idcentro,idprogramacion)"\
|
---|
| 571 | " VALUES (%s,%d,%d,'%s','%s',%d,%d,'%s','%s',%d,%d,%d,%d,'%s',%d,%d,%d)",\
|
---|
| 572 | auxID[i],tipoaccion,idtipoaccion,descriaccion,auxIP[i],sesion,idcomando,parametros,fechahorareg,\
|
---|
| 573 | ACCION_INICIADA,ACCION_SINRESULTADO,ambito,idambito,restrambito,idprocedimiento,idcentro,idprogramacion);
|
---|
| 574 | if (!db.Execute(sqlstr)) { // Error al recuperar los datos
|
---|
| 575 | errorLog(modulo, 21, FALSE);
|
---|
| 576 | db.GetErrorErrStr(msglog);
|
---|
| 577 | errorInfo(modulo, msglog);
|
---|
| 578 | return (FALSE);
|
---|
| 579 | }
|
---|
| 580 | }
|
---|
| 581 | return(TRUE);
|
---|
| 582 | }
|
---|
| 583 | // _____________________________________________________________________________________________________________
|
---|
| 584 | // Función: EjecutarReserva
|
---|
| 585 | //
|
---|
| 586 | // Descripción:
|
---|
| 587 | // Registra una acción (Tarea) y la envía para su ejecución
|
---|
| 588 | // Parámetros:
|
---|
| 589 | // - idreserva : Identificador de la reserva
|
---|
| 590 | // - db: una conexion ADO operativa
|
---|
| 591 | // - parametros: Parámetros de la acción
|
---|
| 592 | // _____________________________________________________________________________________________________________
|
---|
| 593 | BOOLEAN EjecutarReserva(int idreserva,Database db )
|
---|
| 594 | {
|
---|
| 595 |
|
---|
| 596 |
|
---|
| 597 | return(true);
|
---|
| 598 | }
|
---|
| 599 | // _____________________________________________________________________________________________________________
|
---|
| 600 | // Función: enviaPeticion
|
---|
| 601 | //
|
---|
| 602 | // Descripción:
|
---|
| 603 | // Hace una petición al servidor para que actualice los ordenadores implicados en la programación
|
---|
| 604 | // Parámetros:
|
---|
| 605 | // - idprogramacion: Identificador de la programación
|
---|
| 606 | // _____________________________________________________________________________________________________________
|
---|
| 607 | BOOLEAN enviaPeticion(int idprogramacion)
|
---|
| 608 | {
|
---|
| 609 | int lon;
|
---|
| 610 | TRAMA *ptrTrama;
|
---|
| 611 | SOCKET socket_c;
|
---|
| 612 | char modulo[] = "enviaPeticion()";
|
---|
| 613 |
|
---|
| 614 | /* Envio de comandos a clientes */
|
---|
| 615 | ptrTrama=(TRAMA *)reservaMemoria(sizeof(TRAMA));
|
---|
| 616 | if (ptrTrama == NULL) { // No hay memoria suficiente para el bufer de las tramas
|
---|
| 617 | errorLog(modulo, 3, FALSE);
|
---|
| 618 | return(FALSE);
|
---|
| 619 | }
|
---|
| 620 | initParametros(ptrTrama,0);
|
---|
| 621 | lon=sprintf(ptrTrama->parametros,"nfn=envioProgramacion\r"); // Nombre de la función a ejecutar en el servidor
|
---|
| 622 | lon+=sprintf(ptrTrama->parametros+lon,"idp=%d\r",idprogramacion); // Configuración de los Sistemas Operativos del cliente
|
---|
| 623 |
|
---|
| 624 | if(!enviaMensaje(&socket_c,ptrTrama,MSG_PETICION)){
|
---|
| 625 | errorLog(modulo,91,FALSE);
|
---|
[fc480f2] | 626 | liberaMemoria(ptrTrama);
|
---|
[3ec149c] | 627 | return(FALSE);
|
---|
| 628 | }
|
---|
[fc480f2] | 629 | liberaMemoria(ptrTrama);
|
---|
[3ec149c] | 630 | return(TRUE);
|
---|
| 631 | }
|
---|
| 632 | // _____________________________________________________________________________________________________________
|
---|
| 633 | //
|
---|
| 634 | // Función: RecopilaIpesMacs
|
---|
| 635 | //
|
---|
| 636 | // Descripción :
|
---|
| 637 | // Recopila las IPes, las Macs y los identificadores de ordenadores de un ámbito determinado
|
---|
| 638 | //
|
---|
| 639 | // Especificaciones:
|
---|
| 640 | // Esta Función recibe tres parámatros:
|
---|
| 641 | // db : Un objeto Base de datos totalmente operativo
|
---|
| 642 | // ambito: Tipo de ámbito
|
---|
| 643 | // idambito: Identificador del ámbito
|
---|
| 644 | // Devuelve:
|
---|
| 645 | // Todas los identificadores de ordenadores , las ipes y las macs de los ordenadores que componen el ámbito
|
---|
| 646 | // Para ellos habrá que tener declarada tres variables globales :
|
---|
| 647 | // cadenaid,cadenaip y cadenamac
|
---|
| 648 | // _____________________________________________________________________________________________________________
|
---|
| 649 |
|
---|
| 650 | BOOLEAN RecopilaIpesMacs(Database db,int ambito,int idambito,char *restrambito)
|
---|
| 651 | {
|
---|
| 652 | char sqlstr[LONSQL];
|
---|
| 653 |
|
---|
| 654 | concli=0;
|
---|
| 655 | /* Reserva memoria al meno para caracter nulo */
|
---|
| 656 | cadenaid=(char*) reservaMemoria(1);
|
---|
| 657 | cadenaip=(char*) reservaMemoria(1);
|
---|
| 658 | cadenamac=(char*) reservaMemoria(1);
|
---|
| 659 |
|
---|
| 660 | switch(ambito){
|
---|
| 661 | case AMBITO_CENTROS :
|
---|
| 662 | sprintf(sqlstr,"SELECT idcentro FROM centros WHERE idcentro=%d",idambito);
|
---|
| 663 | RecorreCentro(db,sqlstr);
|
---|
| 664 | break;
|
---|
| 665 | case AMBITO_GRUPOSAULAS :
|
---|
| 666 | sprintf(sqlstr,"SELECT idgrupo FROM grupos WHERE idgrupo=%d AND tipo=%d",idambito,AMBITO_GRUPOSAULAS);
|
---|
| 667 | RecorreGruposAulas(db,sqlstr);
|
---|
| 668 | break;
|
---|
| 669 | case AMBITO_AULAS :
|
---|
| 670 | sprintf(sqlstr,"SELECT idaula FROM aulas WHERE idaula=%d",idambito);
|
---|
| 671 | RecorreAulas(db,sqlstr);
|
---|
| 672 | break;
|
---|
| 673 | case AMBITO_GRUPOSORDENADORES :
|
---|
| 674 | sprintf(sqlstr,"SELECT idgrupo FROM gruposordenadores WHERE idgrupo=%d",idambito);
|
---|
| 675 | RecorreGruposOrdenadores(db,sqlstr);
|
---|
| 676 | break;
|
---|
| 677 | case AMBITO_ORDENADORES :
|
---|
| 678 | sprintf(sqlstr,"SELECT ip,mac,idordenador FROM ordenadores WHERE idordenador=%d",idambito);
|
---|
| 679 | RecorreOrdenadores(db,sqlstr);
|
---|
| 680 | break;
|
---|
| 681 | default: // Se trata de un conjunto aleatorio de ordenadores
|
---|
| 682 | sprintf(sqlstr,"SELECT ip,mac,idordenador FROM ordenadores WHERE idordenador IN (%s)",restrambito);
|
---|
| 683 | RecorreOrdenadores(db,sqlstr);
|
---|
| 684 |
|
---|
| 685 | }
|
---|
| 686 | return (TRUE);
|
---|
| 687 | }
|
---|
| 688 | //________________________________________________________________________________________________________
|
---|
| 689 |
|
---|
| 690 | BOOLEAN RecorreCentro(Database db, char* sqlstr)
|
---|
| 691 | {
|
---|
| 692 | char msglog[LONSTD];
|
---|
| 693 | Table tbl;
|
---|
| 694 | int idcentro;
|
---|
| 695 | char modulo[] = "RecorreCentro()";
|
---|
| 696 |
|
---|
| 697 | if (!db.Execute(sqlstr, tbl)) { // Error al leer
|
---|
| 698 | errorLog(modulo, 21, FALSE);
|
---|
| 699 | db.GetErrorErrStr(msglog);
|
---|
| 700 | errorInfo(modulo, msglog);
|
---|
| 701 | return (FALSE);
|
---|
| 702 | }
|
---|
| 703 | if(!tbl.ISEOF()){
|
---|
| 704 | if(!tbl.Get("idcentro",idcentro)){
|
---|
| 705 | tbl.GetErrorErrStr(msglog);
|
---|
| 706 | errorInfo(modulo, msglog);
|
---|
| 707 | return (FALSE);
|
---|
| 708 | }
|
---|
| 709 | sprintf(sqlstr,"SELECT idgrupo FROM grupos WHERE idcentro=%d AND grupoid=0 AND tipo=%d",idcentro,AMBITO_GRUPOSAULAS);
|
---|
| 710 | RecorreGruposAulas(db,sqlstr);
|
---|
| 711 | sprintf(sqlstr,"SELECT idaula FROM aulas WHERE idcentro=%d AND grupoid=0",idcentro);
|
---|
| 712 | RecorreAulas(db,sqlstr);
|
---|
| 713 | }
|
---|
| 714 | return (TRUE);
|
---|
| 715 | }
|
---|
| 716 | //________________________________________________________________________________________________________
|
---|
| 717 |
|
---|
| 718 | BOOLEAN RecorreGruposAulas(Database db, char* sqlstr)
|
---|
| 719 | {
|
---|
| 720 | char msglog[LONSTD];
|
---|
| 721 | Table tbl;
|
---|
| 722 | int idgrupo;
|
---|
| 723 | char modulo[] = "RecorreGruposAulas()";
|
---|
| 724 |
|
---|
| 725 | if (!db.Execute(sqlstr, tbl)) { // Error al leer
|
---|
| 726 | errorLog(modulo, 21, FALSE);
|
---|
| 727 | db.GetErrorErrStr(msglog);
|
---|
| 728 | errorInfo(modulo, msglog);
|
---|
| 729 | return (FALSE);
|
---|
| 730 | }
|
---|
| 731 | while(!tbl.ISEOF()){
|
---|
| 732 | if(!tbl.Get("idgrupo",idgrupo)){
|
---|
| 733 | tbl.GetErrorErrStr(msglog);
|
---|
| 734 | errorInfo(modulo, msglog);
|
---|
| 735 | return (FALSE);
|
---|
| 736 | }
|
---|
| 737 | sprintf(sqlstr,"SELECT idgrupo FROM grupos WHERE grupoid=%d AND tipo=%d",idgrupo,AMBITO_GRUPOSAULAS);
|
---|
| 738 | RecorreGruposAulas(db,sqlstr);
|
---|
| 739 | sprintf(sqlstr,"SELECT idaula FROM aulas WHERE grupoid=%d",idgrupo);
|
---|
| 740 | RecorreAulas(db,sqlstr);
|
---|
| 741 | tbl.MoveNext();
|
---|
| 742 | }
|
---|
| 743 | return (TRUE);
|
---|
| 744 | }
|
---|
| 745 | //________________________________________________________________________________________________________
|
---|
| 746 |
|
---|
| 747 | BOOLEAN RecorreAulas(Database db, char* sqlstr)
|
---|
| 748 | {
|
---|
| 749 | char msglog[LONSTD];
|
---|
| 750 | Table tbl;
|
---|
| 751 | int idaula;
|
---|
| 752 | char modulo[] = "RecorreAulas()";
|
---|
| 753 |
|
---|
| 754 | if (!db.Execute(sqlstr, tbl)) { // Error al leer
|
---|
| 755 | errorLog(modulo, 21, FALSE);
|
---|
| 756 | db.GetErrorErrStr(msglog);
|
---|
| 757 | errorInfo(modulo, msglog);
|
---|
| 758 | return (FALSE);
|
---|
| 759 | }
|
---|
| 760 | while(!tbl.ISEOF()){
|
---|
| 761 | if(!tbl.Get("idaula",idaula)){
|
---|
| 762 | tbl.GetErrorErrStr(msglog);
|
---|
| 763 | errorInfo(modulo, msglog);
|
---|
| 764 | return (FALSE);
|
---|
| 765 | }
|
---|
| 766 | sprintf(sqlstr,"SELECT idgrupo FROM gruposordenadores WHERE idaula=%d AND grupoid=0",idaula);
|
---|
| 767 | RecorreGruposOrdenadores(db,sqlstr);
|
---|
| 768 | sprintf(sqlstr,"SELECT ip,mac,idordenador FROM ordenadores WHERE idaula=%d AND grupoid=0",idaula);
|
---|
| 769 | RecorreOrdenadores(db,sqlstr);
|
---|
| 770 | tbl.MoveNext();
|
---|
| 771 | }
|
---|
| 772 | return (TRUE);
|
---|
| 773 | }
|
---|
| 774 | //________________________________________________________________________________________________________
|
---|
| 775 |
|
---|
| 776 | BOOLEAN RecorreGruposOrdenadores(Database db, char* sqlstr)
|
---|
| 777 | {
|
---|
| 778 | char msglog[LONSTD];
|
---|
| 779 | Table tbl;
|
---|
| 780 | int idgrupo;
|
---|
| 781 | char modulo[] = "RecorreGruposOrdenadores()";
|
---|
| 782 |
|
---|
| 783 | if (!db.Execute(sqlstr, tbl)) { // Error al leer
|
---|
| 784 | errorLog(modulo, 21, FALSE);
|
---|
| 785 | db.GetErrorErrStr(msglog);
|
---|
| 786 | errorInfo(modulo, msglog);
|
---|
| 787 | return (FALSE);
|
---|
| 788 | }
|
---|
| 789 | while(!tbl.ISEOF()){
|
---|
| 790 | if(!tbl.Get("idgrupo",idgrupo)){
|
---|
| 791 | tbl.GetErrorErrStr(msglog);
|
---|
| 792 | errorInfo(modulo, msglog);
|
---|
| 793 | return (FALSE);
|
---|
| 794 | }
|
---|
| 795 | sprintf(sqlstr,"SELECT idgrupo FROM gruposordenadores WHERE grupoid=%d",idgrupo);
|
---|
| 796 | RecorreGruposOrdenadores(db,sqlstr);
|
---|
| 797 | sprintf(sqlstr,"SELECT ip,mac,idordenador FROM ordenadores WHERE grupoid=%d",idgrupo);
|
---|
| 798 | RecorreOrdenadores(db,sqlstr);
|
---|
| 799 | tbl.MoveNext();
|
---|
| 800 | }
|
---|
| 801 | return (TRUE);
|
---|
| 802 | }
|
---|
| 803 | //________________________________________________________________________________________________________
|
---|
| 804 |
|
---|
| 805 | BOOLEAN RecorreOrdenadores(Database db, char* sqlstr)
|
---|
| 806 | {
|
---|
| 807 | char msglog[LONSTD];
|
---|
| 808 | Table tbl;
|
---|
| 809 | int idordenador,o,p,m,lon;
|
---|
| 810 | char ido[16],ip[LONIP],mac[LONMAC];
|
---|
| 811 | char modulo[] = "RecorreOrdenadores()";
|
---|
| 812 |
|
---|
| 813 | if (!db.Execute(sqlstr, tbl)) { // Error al leer
|
---|
| 814 | errorLog(modulo, 21, FALSE);
|
---|
| 815 | db.GetErrorErrStr(msglog);
|
---|
| 816 | errorInfo(modulo, msglog);
|
---|
| 817 | return (FALSE);
|
---|
| 818 | }
|
---|
| 819 | o=p=m=0;
|
---|
| 820 | while(!tbl.ISEOF()){
|
---|
| 821 | if(!tbl.Get("idordenador",idordenador)){
|
---|
| 822 | tbl.GetErrorErrStr(msglog);
|
---|
| 823 | errorInfo(modulo, msglog);
|
---|
| 824 | return (FALSE);
|
---|
| 825 | }
|
---|
| 826 | if(!tbl.Get("ip",ip)){
|
---|
| 827 | tbl.GetErrorErrStr(msglog);
|
---|
| 828 | errorInfo(modulo, msglog);
|
---|
| 829 | return (FALSE);
|
---|
| 830 | }
|
---|
| 831 | if(!tbl.Get("mac",mac)){
|
---|
| 832 | tbl.GetErrorErrStr(msglog);
|
---|
| 833 | errorInfo(modulo, msglog);
|
---|
| 834 | return (FALSE);
|
---|
| 835 | }
|
---|
| 836 | sprintf(ido,"%d",idordenador);
|
---|
| 837 | lon=strlen(ido);
|
---|
| 838 | if(lon>16) lon=16;
|
---|
| 839 | cadenaid=(char*) ampliaMemoria(cadenaid,o+lon+1);
|
---|
| 840 | memcpy(&cadenaid[o],ido,lon);
|
---|
| 841 | o+=lon;
|
---|
| 842 | cadenaid[o++]=',';
|
---|
| 843 |
|
---|
| 844 | lon=strlen(ip);
|
---|
| 845 | if(lon>16) lon=LONIP;
|
---|
| 846 | cadenaip=(char*) ampliaMemoria(cadenaip,p+lon+1);
|
---|
| 847 | memcpy(&cadenaip[p],ip,lon);
|
---|
| 848 | p+=lon;
|
---|
| 849 | cadenaip[p++]=';';
|
---|
| 850 |
|
---|
| 851 | lon=strlen(mac);
|
---|
| 852 | if(lon>16) lon=LONMAC;
|
---|
| 853 | cadenamac=(char*) ampliaMemoria(cadenamac,m+lon+1);
|
---|
| 854 | memcpy(&cadenamac[m],mac,lon);
|
---|
| 855 | m+=lon;
|
---|
| 856 | cadenamac[m++]=';';
|
---|
| 857 |
|
---|
| 858 | concli++;
|
---|
| 859 | tbl.MoveNext();
|
---|
| 860 | }
|
---|
| 861 | if(o>0) o--;
|
---|
| 862 | if(p>0) p--;
|
---|
| 863 | if(m>0) m--;
|
---|
| 864 | cadenaid[o]='\0';
|
---|
| 865 | cadenaip[p]='\0';
|
---|
| 866 | cadenamac[m]='\0';
|
---|
| 867 |
|
---|
| 868 | return (TRUE);
|
---|
| 869 | }
|
---|
| 870 | // ********************************************************************************************************
|
---|
| 871 | // PROGRAMA PRINCIPAL (SERVICIO)
|
---|
| 872 | // ********************************************************************************************************
|
---|
| 873 | int main(int argc, char *argv[])
|
---|
| 874 | {
|
---|
| 875 | int pseg;
|
---|
| 876 | char msglog[LONSTD];
|
---|
| 877 | struct tm* st;
|
---|
| 878 | Database db;
|
---|
| 879 | char modulo[] = "main()";
|
---|
| 880 |
|
---|
| 881 | /* Validación de parámetros de ejecución y lectura del fichero de configuración del servicio */
|
---|
| 882 |
|
---|
| 883 | if (!validacionParametros(argc, argv, 5)) // Valida parámetros de ejecución
|
---|
| 884 | exit(EXIT_FAILURE);
|
---|
| 885 |
|
---|
| 886 | if (!tomaConfiguracion(szPathFileCfg)) { // Toma parametros de configuracion
|
---|
| 887 | exit(EXIT_FAILURE);
|
---|
| 888 | }
|
---|
| 889 |
|
---|
| 890 | /* Bucle principal del servicio */
|
---|
| 891 |
|
---|
| 892 | while (TRUE){
|
---|
| 893 | st = tomaHora();
|
---|
| 894 | pseg=65-st->tm_sec; // Calcula segundos de inactividad de la hebra
|
---|
| 895 | sleep(pseg);
|
---|
| 896 |
|
---|
| 897 | // Toma la hora
|
---|
| 898 | st = tomaHora();
|
---|
| 899 |
|
---|
| 900 | if (!db.Open(usuario, pasguor, datasource, catalog)) { // Error de conexion
|
---|
| 901 | errorLog(modulo, 20, FALSE);
|
---|
| 902 | db.GetErrorErrStr(msglog);
|
---|
| 903 | errorInfo(modulo, msglog);
|
---|
| 904 | exit(EXIT_FAILURE);
|
---|
| 905 | }
|
---|
| 906 | buscaAccion(db,st->tm_mday,st->tm_mon+1,st->tm_year+1900,st->tm_hour,st->tm_min,st->tm_wday );
|
---|
| 907 | db.Close(); // Cierra conexión
|
---|
| 908 | }
|
---|
| 909 | exit(EXIT_SUCCESS);
|
---|
| 910 | }
|
---|
| 911 |
|
---|
| 912 |
|
---|