Changeset 1631
- Timestamp:
- 02/20/10 15:19:18 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/oscam.c
r1628 r1631 1395 1395 } 1396 1396 1397 /* 1398 * This function writes the current CW from ECM struct to a cwl file. 1399 * The filename is re-calculated and file re-opened every time. 1400 * This will consume a bit cpu time, but nothing has to be stored between 1401 * each call. If not file exists, a header is prepended 1402 */ 1397 1403 void logCWtoFile(ECM_REQUEST *er) 1398 1404 { 1399 /* This function writes the current CW from ECM struct to a cwl file. 1400 The filename is re-calculated and file re-opened every time. 1401 This will consume a bit cpu time, but nothing has to be stored between 1402 each call. If not file exists, a header is prepended */ 1403 1404 FILE *pfCWL; 1405 char srvname[128]; 1406 /* %s / %s _I %04X _ %s .cwl */ 1407 char buf[256+sizeof(srvname)]; 1408 char date[7]; 1409 unsigned char i, parity, writeheader = 0; 1410 time_t t; 1411 struct tm *timeinfo; 1412 struct s_srvid *this; 1413 1414 /* search service name for that id and change characters 1415 causing problems in file name */ 1416 srvname[0] = 0; 1417 for (this=cfg->srvid; this; this=this->next) { 1418 if (this->srvid==er->srvid) { 1419 strncpy(srvname, this->name, sizeof(srvname)); 1420 srvname[sizeof(srvname)-1] = 0; 1421 for (i=0;srvname[i];i++) 1422 if (srvname[i]==' ') srvname[i]='_'; 1423 break; 1424 } 1425 } 1426 1427 /* calc log file name */ 1428 time(&t); 1429 timeinfo = localtime(&t); 1430 strftime(date,sizeof(date),"%y%m%d",timeinfo); 1431 sprintf(buf, "%s/%s_I%04X_%s.cwl", cfg->cwlogdir, date, er->srvid, srvname); 1432 1433 if((pfCWL=fopen(buf,"r")) == NULL) 1434 { 1435 /* open failed, assuming file does not exist, yet */ 1436 writeheader = 1; 1437 } else 1438 { 1439 /* we need to close the file if it was opened correctly */ 1440 fclose(pfCWL); 1441 } 1442 1443 if ((pfCWL=fopen(buf, "a+")) == NULL) 1444 { 1445 /* maybe this fails because the subdir does not exist. Is there a common function to create it? */ 1446 /* for the moment do not print to log on every ecm 1447 cs_log(""error opening cw logfile for writing: %s (errno %d)", buf, errno); */ 1448 return; 1449 } 1450 if (writeheader) 1451 { 1452 /* no global macro for cardserver name :( */ 1453 fprintf(pfCWL, "# OSCam cardserver v%s - http://streamboard.gmc.to:8001/wiki\n", CS_VERSION_X); 1454 fprintf(pfCWL, "# control word log file for use with tsdec offline decrypter\n"); 1455 strftime(buf,sizeof(buf),"DATE %Y-%m-%d, TIME %H:%M:%S, TZ %Z\n",timeinfo); 1456 fprintf(pfCWL, "# %s",buf); 1457 fprintf(pfCWL, "# CAID 0x%04X, SID 0x%04X, SERVICE \"%s\"\n", er->caid, er->srvid, srvname); 1458 } 1459 1460 parity = er->ecm[0]&1; 1461 fprintf(pfCWL, "%d ",parity); 1462 for (i=parity*8; i<8+parity*8; i++) 1463 fprintf(pfCWL, "%02X ",er->cw[i]); 1464 /* better use incoming time er->tps rather than current time? */ 1465 strftime(buf,sizeof(buf),"%H:%M:%S\n",timeinfo); 1466 fprintf(pfCWL, "# %s",buf); 1467 fflush(pfCWL); 1468 fclose(pfCWL); 1405 FILE *pfCWL; 1406 char srvname[128]; 1407 /* %s / %s _I %04X _ %s .cwl */ 1408 char buf[256 + sizeof(srvname)]; 1409 char date[7]; 1410 unsigned char i, parity, writeheader = 0; 1411 time_t t; 1412 struct tm *timeinfo; 1413 struct s_srvid *this; 1414 1415 /* 1416 * search service name for that id and change characters 1417 * causing problems in file name 1418 */ 1419 srvname[0] = 0; 1420 for (this=cfg->srvid; this; this = this->next) { 1421 if (this->srvid == er->srvid) { 1422 strncpy(srvname, this->name, sizeof(srvname)); 1423 srvname[sizeof(srvname)-1] = 0; 1424 for (i = 0; srvname[i]; i++) 1425 if (srvname[i] == ' ') srvname[i] = '_'; 1426 break; 1427 } 1428 } 1429 1430 /* calc log file name */ 1431 time(&t); 1432 timeinfo = localtime(&t); 1433 strftime(date, sizeof(date), "%y%m%d", timeinfo); 1434 sprintf(buf, "%s/%s_I%04X_%s.cwl", cfg->cwlogdir, date, er->srvid, srvname); 1435 1436 /* open failed, assuming file does not exist, yet */ 1437 if((pfCWL = fopen(buf, "r")) == NULL) { 1438 writeheader = 1; 1439 } else { 1440 /* we need to close the file if it was opened correctly */ 1441 fclose(pfCWL); 1442 } 1443 1444 if ((pfCWL = fopen(buf, "a+")) == NULL) { 1445 /* maybe this fails because the subdir does not exist. Is there a common function to create it? 1446 for the moment do not print to log on every ecm 1447 cs_log(""error opening cw logfile for writing: %s (errno %d)", buf, errno); */ 1448 return; 1449 } 1450 if (writeheader) { 1451 /* no global macro for cardserver name :( */ 1452 fprintf(pfCWL, "# OSCam cardserver v%s - http://streamboard.gmc.to:8001/oscam/wiki\n", CS_VERSION_X); 1453 fprintf(pfCWL, "# control word log file for use with tsdec offline decrypter\n"); 1454 strftime(buf, sizeof(buf),"DATE %Y-%m-%d, TIME %H:%M:%S, TZ %Z\n", timeinfo); 1455 fprintf(pfCWL, "# %s", buf); 1456 fprintf(pfCWL, "# CAID 0x%04X, SID 0x%04X, SERVICE \"%s\"\n", er->caid, er->srvid, srvname); 1457 } 1458 1459 parity = er->ecm[0]&1; 1460 fprintf(pfCWL, "%d ", parity); 1461 for (i = parity * 8; i < 8 + parity * 8; i++) 1462 fprintf(pfCWL, "%02X ", er->cw[i]); 1463 /* better use incoming time er->tps rather than current time? */ 1464 strftime(buf,sizeof(buf),"%H:%M:%S\n", timeinfo); 1465 fprintf(pfCWL, "# %s", buf); 1466 fflush(pfCWL); 1467 fclose(pfCWL); 1469 1468 } 1470 1469
Note:
See TracChangeset
for help on using the changeset viewer.