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