Changeset 422
- Timestamp:
- 09/04/09 20:45:38 (15 years ago)
- Location:
- branches/merlin
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/merlin/include/log.h
r395 r422 14 14 void log_statistics(int); 15 15 16 void log_cwl_write_to_file(ECM_REQUEST *); 17 16 18 #endif // __LOG_H__ -
branches/merlin/src/log.c
r412 r422 346 346 } 347 347 } 348 349 void log_cwl_write_to_file(ECM_REQUEST *er) 350 { 351 /* This function writes the current CW from ECM struct to a cwl file. 352 The filename is re-calculated and file re-opened every time. 353 This will consume a bit cpu time, but nothing has to be stored between 354 each call. If not file exists, a header is prepended */ 355 356 FILE *pfCWL; 357 char srvname[23]; 358 359 /* %s / %s _I %04X _ %s .cwl */ 360 char buf[sizeof (cfg->cwlogdir) + 1 + 6 + 2 + 4 + 1 + sizeof (srvname) + 5]; 361 char date[7]; 362 unsigned char i, parity, writeheader = 0; 363 time_t t; 364 struct tm *timeinfo; 365 struct s_srvid *this; 366 367 if (cfg->cwlogdir[0]) { /* CWL logging only if cwlogdir is set in config */ 368 /* search service name for that id and change characters 369 causing problems in file name */ 370 srvname[0] = 0; 371 for (this = cfg->srvid; this; this = this->next) { 372 if (this->srvid == er->srvid) { 373 strncpy(srvname, this->name, sizeof (srvname)); 374 srvname[sizeof (srvname) - 1] = 0; 375 for (i = 0; srvname[i]; i++) 376 if (srvname[i] == ' ') 377 srvname[i] = '_'; 378 break; 379 } 380 } 381 382 /* calc log file name */ 383 time(&t); 384 timeinfo = localtime(&t); 385 strftime(date, sizeof (date), "%y%m%d", timeinfo); 386 sprintf(buf, "%s/%s_I%04X_%s.cwl", cfg->cwlogdir, date, er->srvid, srvname); 387 388 if ((pfCWL = fopen(buf, "r")) == NULL) { 389 /* open failed, assuming file does not exist, yet */ 390 writeheader = 1; 391 } else { 392 /* we need to close the file if it was opened correctly */ 393 fclose(pfCWL); 394 } 395 396 if ((pfCWL = fopen(buf, "a+")) == NULL) { 397 /* maybe this fails because the subdir does not exist. Is there a common function to create it? */ 398 /* for the moment do not print to log on every ecm 399 log_normal(""error opening cw logfile for writing: %s (errno %d)", buf, errno); */ 400 return; 401 } 402 if (writeheader) { 403 /* no global macro for cardserver name :( */ 404 fprintf(pfCWL, "# OSCam cardserver v%s - http://streamboard.gmc.to:8001/oscam/wiki\n", CS_VERSION); 405 fprintf(pfCWL, "# control word log file for use with tsdec offline decrypter\n"); 406 strftime(buf, sizeof (buf), "DATE %Y-%m-%d, TIME %H:%M:%S, TZ %Z\n", timeinfo); 407 fprintf(pfCWL, "# %s", buf); 408 fprintf(pfCWL, "# CAID 0x%04X, SID 0x%04X, SERVICE \"%s\"\n", er->caid, er->srvid, srvname); 409 } 410 411 parity = er->ecm[0] & 1; 412 fprintf(pfCWL, "%d ", parity); 413 for (i = parity * 8; i < 8 + parity * 8; i++) 414 fprintf(pfCWL, "%02X ", er->cw[i]); 415 /* better use incoming time er->tps rather than current time? */ 416 strftime(buf, sizeof (buf), "%H:%M:%S\n", timeinfo); 417 fprintf(pfCWL, "# %s", buf); 418 fflush(pfCWL); 419 fclose(pfCWL); 420 } /* if (cfg->pidfile[0]) */ 421 } 422 -
branches/merlin/src/oscam.c
r421 r422 1331 1331 */ 1332 1332 1333 static void oscam_log_cw_to_file(ECM_REQUEST * er)1334 {1335 /* This function writes the current CW from ECM struct to a cwl file.1336 The filename is re-calculated and file re-opened every time.1337 This will consume a bit cpu time, but nothing has to be stored between1338 each call. If not file exists, a header is prepended */1339 1340 FILE *pfCWL;1341 char srvname[23];1342 1343 /* %s / %s _I %04X _ %s .cwl */1344 char buf[sizeof (cfg->cwlogdir) + 1 + 6 + 2 + 4 + 1 + sizeof (srvname) + 5];1345 char date[7];1346 unsigned char i, parity, writeheader = 0;1347 time_t t;1348 struct tm *timeinfo;1349 struct s_srvid *this;1350 1351 if (cfg->cwlogdir[0]) { /* CWL logging only if cwlogdir is set in config */1352 /* search service name for that id and change characters1353 causing problems in file name */1354 srvname[0] = 0;1355 for (this = cfg->srvid; this; this = this->next) {1356 if (this->srvid == er->srvid) {1357 strncpy(srvname, this->name, sizeof (srvname));1358 srvname[sizeof (srvname) - 1] = 0;1359 for (i = 0; srvname[i]; i++)1360 if (srvname[i] == ' ')1361 srvname[i] = '_';1362 break;1363 }1364 }1365 1366 /* calc log file name */1367 time(&t);1368 timeinfo = localtime(&t);1369 strftime(date, sizeof (date), "%y%m%d", timeinfo);1370 sprintf(buf, "%s/%s_I%04X_%s.cwl", cfg->cwlogdir, date, er->srvid, srvname);1371 1372 if ((pfCWL = fopen(buf, "r")) == NULL) {1373 /* open failed, assuming file does not exist, yet */1374 writeheader = 1;1375 } else {1376 /* we need to close the file if it was opened correctly */1377 fclose(pfCWL);1378 }1379 1380 if ((pfCWL = fopen(buf, "a+")) == NULL) {1381 /* maybe this fails because the subdir does not exist. Is there a common function to create it? */1382 /* for the moment do not print to log on every ecm1383 log_normal(""error opening cw logfile for writing: %s (errno %d)", buf, errno); */1384 return;1385 }1386 if (writeheader) {1387 /* no global macro for cardserver name :( */1388 fprintf(pfCWL, "# OSCam cardserver v%s - http://streamboard.gmc.to:8001/oscam/wiki\n", CS_VERSION);1389 fprintf(pfCWL, "# control word log file for use with tsdec offline decrypter\n");1390 strftime(buf, sizeof (buf), "DATE %Y-%m-%d, TIME %H:%M:%S, TZ %Z\n", timeinfo);1391 fprintf(pfCWL, "# %s", buf);1392 fprintf(pfCWL, "# CAID 0x%04X, SID 0x%04X, SERVICE \"%s\"\n", er->caid, er->srvid, srvname);1393 }1394 1395 parity = er->ecm[0] & 1;1396 fprintf(pfCWL, "%d ", parity);1397 for (i = parity * 8; i < 8 + parity * 8; i++)1398 fprintf(pfCWL, "%02X ", er->cw[i]);1399 /* better use incoming time er->tps rather than current time? */1400 strftime(buf, sizeof (buf), "%H:%M:%S\n", timeinfo);1401 fprintf(pfCWL, "# %s", buf);1402 fflush(pfCWL);1403 fclose(pfCWL);1404 } /* if (cfg->pidfile[0]) */1405 }1406 1407 1333 int oscam_write_ecm_answer(int fd, ECM_REQUEST * er) 1408 1334 { … … 1425 1351 if (er->rc == 1 || (er->gbxRidx && er->rc == 0)) { 1426 1352 cache_store_ecm(er); 1427 oscam_log_cw_to_file(er);1353 log_cwl_write_to_file(er); 1428 1354 } 1429 1355
Note:
See TracChangeset
for help on using the changeset viewer.