X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=download.c;h=f826e7014bbb851eb398fd019299ea66bad56e51;hb=82aba1f76795d95bed1c1b948e2e521168e97fc9;hp=0ff44e76fcf90fbe5cf1a70fe98438a6d2ad80e9;hpb=67302a9e4d122b09b6f94819bc62ec15faadad42;p=thirdparty%2Fsarg.git diff --git a/download.c b/download.c index 0ff44e7..f826e70 100644 --- a/download.c +++ b/download.c @@ -1,6 +1,6 @@ /* * SARG Squid Analysis Report Generator http://sarg.sourceforge.net - * 1998, 2013 + * 1998, 2015 * * SARG donations: * please look at http://sarg.sourceforge.net/donations.php @@ -26,6 +26,7 @@ #include "include/conf.h" #include "include/defs.h" +#include "include/readlog.h" /*! The buffer to store the list of the suffixes to take into account when generating @@ -60,17 +61,17 @@ Open a file to store the denied accesses. void download_open(void) { if ((ReportType & REPORT_TYPE_DOWNLOADS) == 0) { - if (debugz) debugaz(_("Download report not produced as it is not requested\n")); + if (debugz>=LogLevel_Process) debugaz(__FILE__,__LINE__,_("Download report not produced as it is not requested\n")); return; } if (Privacy) { - if (debugz) debugaz(_("Download report not produced because privacy option is active\n")); + if (debugz>=LogLevel_Process) debugaz(__FILE__,__LINE__,_("Download report not produced because privacy option is active\n")); return; } snprintf(download_unsort,sizeof(download_unsort),"%s/download.int_unsort",tmp); if ((fp_download=MY_FOPEN(download_unsort,"w"))==NULL) { - debuga(_("(log) Cannot open file %s: %s\n"),download_unsort,strerror(errno)); + debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),download_unsort,strerror(errno)); exit(EXIT_FAILURE); } return; @@ -86,7 +87,7 @@ void download_write(const struct ReadLogStruct *log_entry,const char *url) { char date[80]; - if (fp_download && strstr(log_entry->HttpCode,"DENIED") != 0) { + if (fp_download && strstr(log_entry->HttpCode,"DENIED") == 0) { strftime(date,sizeof(date),"%d/%m/%Y\t%H:%M:%S",&log_entry->EntryTime); fprintf(fp_download,"%s\t%s\t%s\t%s\n",date,log_entry->User,log_entry->Ip,url); download_exists=true; @@ -101,7 +102,7 @@ void download_close(void) if (fp_download) { if (fclose(fp_download)==EOF) { - debuga(_("Write error in %s: %s\n"),download_unsort,strerror(errno)); + debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),download_unsort,strerror(errno)); exit(EXIT_FAILURE); } fp_download=NULL; @@ -136,18 +137,18 @@ static void download_sort(const char *report_in) clen=snprintf(csort,sizeof(csort),"sort -T \"%s\" -t \"\t\" -k 3,3 -k 1,1 -k 2,2 -k 5,5 -o \"%s\" \"%s\"", tmp, report_in, download_unsort); if (clen>=sizeof(csort)) { - debuga(_("Path too long to sort the file: %s\n"),download_unsort); + debuga(__FILE__,__LINE__,_("Path too long to sort file \"%s\"\n"),download_unsort); exit(EXIT_FAILURE); } cstatus=system(csort); if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) { - debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus)); - debuga(_("sort command: %s\n"),csort); + debuga(__FILE__,__LINE__,_("sort command return status %d\n"),WEXITSTATUS(cstatus)); + debuga(__FILE__,__LINE__,_("sort command: %s\n"),csort); exit(EXIT_FAILURE); } if (!KeepTempLog) { if (unlink(download_unsort)) { - debuga(_("Cannot delete \"%s\": %s\n"),download_unsort,strerror(errno)); + debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),download_unsort,strerror(errno)); exit(EXIT_FAILURE); } download_unsort[0]='\0'; @@ -160,7 +161,8 @@ is set with set_download_suffix(). */ void download_report(void) { - FILE *fp_in = NULL, *fp_ou = NULL; + FileObject *fp_in = NULL; + FILE *fp_ou = NULL; char *buf; char *url; @@ -185,12 +187,14 @@ void download_report(void) if (!download_exists) { if (!KeepTempLog && download_unsort[0]!='\0' && unlink(download_unsort)) - debuga(_("Cannot delete \"%s\": %s\n"),download_unsort,strerror(errno)); + debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),download_unsort,strerror(errno)); download_unsort[0]='\0'; - if (debugz) debugaz(_("No downloaded files to report\n")); + if (debugz>=LogLevel_Process) debugaz(__FILE__,__LINE__,_("No downloaded files to report\n")); return; } + if (debugz>=LogLevel_Process) + debuga(__FILE__,__LINE__,_("Creating download report...\n")); ouser[0]='\0'; ouser2[0]='\0'; @@ -201,13 +205,13 @@ void download_report(void) // produce the report. snprintf(report,sizeof(report),"%s/download.html",outdirname); - if((fp_in=MY_FOPEN(report_in,"r"))==NULL) { - debuga(_("(download) Cannot open log file %s: %s\n"),report_in,strerror(errno)); + if((fp_in=FileObject_Open(report_in))==NULL) { + debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),report_in,FileObject_GetLastOpenError()); exit(EXIT_FAILURE); } if((fp_ou=MY_FOPEN(report,"w"))==NULL) { - debuga(_("(download) Cannot open log file %s: %s\n"),report,strerror(errno)); + debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),report,strerror(errno)); exit(EXIT_FAILURE); } @@ -222,7 +226,7 @@ void download_report(void) fprintf(fp_ou,"