]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - repday.c
Add support to decompress xz files
[thirdparty/sarg.git] / repday.c
index 9a412609b0c2a3f6ce7c2519dd4a848158ec7ace..bed4b7cb89d77f683ec642089cdeab7f25793d93 100644 (file)
--- a/repday.c
+++ b/repday.c
@@ -1,6 +1,6 @@
 /*
  * SARG Squid Analysis Report Generator      http://sarg.sourceforge.net
- *                                                            1998, 2012
+ *                                                            1998, 2015
  *
  * SARG donations:
  *      please look at http://sarg.sourceforge.net/donations.php
@@ -57,16 +57,18 @@ void report_day(const struct userinfostruct *uinfo)
        struct getwordstruct gwarea;
        struct tm t;
 
+       if (datetimeby==0) return;
        snprintf(wdirname,sizeof(wdirname),"%s/%s.day",tmp,uinfo->filename);
        if(access(wdirname, R_OK) != 0) return;
 
        if (snprintf(arqout,sizeof(arqout),"%s/%s/d%s.html",outdirname,uinfo->filename,uinfo->filename)>=sizeof(arqout)) {
-               debuga(_("Output file name too long: %s/%s/d%s.html\n"),outdirname,uinfo->filename,uinfo->filename);
+               debuga(__FILE__,__LINE__,_("Path too long: "));
+               debuga_more("%s/%s/d%s.html\n",outdirname,uinfo->filename,uinfo->filename);
                exit(EXIT_FAILURE);
        }
 
        if((fp_in=fopen(wdirname,"r"))==NULL) {
-               debuga(_("(repday) Cannot open log file %s: %s\n"),wdirname,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),wdirname,strerror(errno));
                exit(EXIT_FAILURE);
        }
 
@@ -78,7 +80,7 @@ void report_day(const struct userinfostruct *uinfo)
                fixendofline(buf);
                getword_start(&gwarea,buf);
                if (getword(data,sizeof(data),&gwarea,'\t')<0) {
-                       debuga(_("Invalid date in file %s\n"),wdirname);
+                       debuga(__FILE__,__LINE__,_("Invalid date in file \"%s\"\n"),wdirname);
                        exit(EXIT_FAILURE);
                }
                if (sscanf(data,"%d/%d/%d",&day,&month,&year)!=3) continue;
@@ -87,14 +89,14 @@ void report_day(const struct userinfostruct *uinfo)
                for (dayidx=0 ; dayidx<ndaylist && daynum!=daylist[dayidx] ; dayidx++);
                if (dayidx>=ndaylist) {
                        if (dayidx>=sizeof(daylist)/sizeof(*daylist)) {
-                               debuga(_("Too many different dates in %s\n"),wdirname);
+                               debuga(__FILE__,__LINE__,_("Too many different dates in file \"%s\"\n"),wdirname);
                                exit(EXIT_FAILURE);
                        }
                        daylist[ndaylist++]=daynum;
                }
 
                if (getword_atoll(&hour,&gwarea,'\t')<0) {
-                       debuga(_("Invalid time in file %s\n"),wdirname);
+                       debuga(__FILE__,__LINE__,_("Invalid time in file \"%s\"\n"),wdirname);
                        exit(EXIT_FAILURE);
                }
                ihour=(int)hour;
@@ -103,23 +105,26 @@ void report_day(const struct userinfostruct *uinfo)
                if ((datetimeby & DATETIME_BYTE)!=0) {
                        colsep=((datetimeby & DATETIME_ELAP)!=0) ? '\t' : '\0';
                        if (getword_atoll(&bytes,&gwarea,colsep)<0) {
-                               debuga(_("Invalid number of bytes in file %s\n"),wdirname);
+                               debuga(__FILE__,__LINE__,_("Invalid number of bytes in file \"%s\"\n"),wdirname);
                                exit(EXIT_FAILURE);
                        }
                        tbytes[i]+=bytes;
                }
                if ((datetimeby & DATETIME_ELAP)!=0) {
                        if (getword_atoll(&elap,&gwarea,'\0')<0) {
-                               debuga(_("Invalid elapsed time in file %s\n"),wdirname);
+                               debuga(__FILE__,__LINE__,_("Invalid elapsed time in file \"%s\"\n"),wdirname);
                                exit(EXIT_FAILURE);
                        }
                        telap[i]+=elap;
                }
        }
-       fclose(fp_in);
+       if (fclose(fp_in)==EOF) {
+               debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),wdirname,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
 
        if((fp_ou=fopen(arqout,"w"))==NULL) {
-               debuga(_("(repday) Cannot open log file %s: %s\n"),arqout,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),arqout,strerror(errno));
                exit(EXIT_FAILURE);
        }
 
@@ -182,7 +187,7 @@ void report_day(const struct userinfostruct *uinfo)
                fputs("</table>\n",fp_ou);
 #ifdef ENABLE_DOUBLE_CHECK_DATA
                if (tt!=uinfo->nbytes) {
-                       debuga(_("Total downloaded bytes is %"PRIi64" instead of %"PRIi64" in the hourly report of user %s\n"),
+                       debuga(__FILE__,__LINE__,_("Total downloaded bytes is %"PRIi64" instead of %"PRIi64" in the hourly report of user %s\n"),
                                                 (int64_t)tt,(int64_t)uinfo->nbytes,uinfo->label);
                        exit(EXIT_FAILURE);
                }
@@ -234,17 +239,16 @@ void report_day(const struct userinfostruct *uinfo)
                fputs("</table>\n",fp_ou);
 #ifdef ENABLE_DOUBLE_CHECK_DATA
                if (tt!=uinfo->elap) {
-                       debuga(_("Total elapsed time is %"PRIi64" instead of %"PRIi64" in the hourly report of user %s\n"),
+                       debuga(__FILE__,__LINE__,_("Total elapsed time is %"PRIi64" instead of %"PRIi64" in the hourly report of user %s\n"),
                                                 (int64_t)tt,(int64_t)uinfo->elap,uinfo->label);
                        exit(EXIT_FAILURE);
                }
 #endif
        }
 
-       if (write_html_trailer(fp_ou)<0)
-               debuga(_("Write error in file %s\n"),arqout);
+       write_html_trailer(fp_ou);
        if (fclose(fp_ou)==EOF) {
-               debuga(_("Write error in %s: %s\n"),arqout,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),arqout,strerror(errno));
                exit(EXIT_FAILURE);
        }
        return;