]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - totday.c
Optimize away a useless strcpy.
[thirdparty/sarg.git] / totday.c
index e2cee78b6bbfca4fc03ec1fe541ea3a0a1d97a79..9d80b8ba74b7bd67f8da470273329594f045eb41 100644 (file)
--- a/totday.c
+++ b/totday.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
@@ -50,7 +50,7 @@ DayObject day_prepare(void)
        ddata=(DayObject)malloc(sizeof(*ddata));
        if (!ddata)
        {
-               debuga(_("Not enough memory to store the daily statistics\n"));
+               debuga(__FILE__,__LINE__,_("Not enough memory to store the daily statistics\n"));
                exit(EXIT_FAILURE);
        }
 
@@ -102,16 +102,16 @@ void day_addpoint(DayObject ddata,const char *date, const char *time, long long
 
        if (!ddata) return;
        if (sscanf(date,"%d/%d/%d",&day,&month,&year)!=3) {
-               debuga(_("Invalid date \"%s\" for the hourly statistics\n"),date);
+               debuga(__FILE__,__LINE__,_("Invalid date \"%s\" for the hourly statistics\n"),date);
                exit(EXIT_FAILURE);
        }
        if (day<1 || day>31 || month<1 || month>12 || year>9999) {
-               debuga(_("Invalid date component in \"%s\" for the hourly statistics\n"),date);
+               debuga(__FILE__,__LINE__,_("Invalid date component in \"%s\" for the hourly statistics\n"),date);
                exit(EXIT_FAILURE);
        }
        hour=atoi(time);
        if (hour<0 || hour>=24) {
-               debuga(_("Invalid hour %d for the hourly statistics\n"),hour);
+               debuga(__FILE__,__LINE__,_("Invalid hour %d for the hourly statistics\n"),hour);
                exit(EXIT_FAILURE);
        }
        daynum=(year*10000)+(month*100)+day;
@@ -119,7 +119,7 @@ void day_addpoint(DayObject ddata,const char *date, const char *time, long long
        if (dayidx<0) {
                dayidx=ddata->ndaylist++;
                if (dayidx>=sizeof(ddata->daylist)/sizeof(*ddata->daylist)) {
-                       debuga(_("Too many different dates for the hourly statistics\n"));
+                       debuga(__FILE__,__LINE__,_("Too many different dates for the hourly statistics\n"));
                        exit(EXIT_FAILURE);
                }
                ddata->daylist[dayidx]=daynum;
@@ -151,12 +151,13 @@ void day_totalize(DayObject ddata,const char *tmp, const struct userinfostruct *
        if (!ddata) return;
 
        if (snprintf(arqout,sizeof(arqout),"%s/%s.day",tmp,uinfo->filename)>=sizeof(arqout)) {
-               debuga(_("File name too long: %s/%s%s\n"),tmp,uinfo->filename,".day");
+               debuga(__FILE__,__LINE__,_("Path too long: "));
+               debuga_more("%s/%s%s\n",tmp,uinfo->filename,".day");
                exit(EXIT_FAILURE);
        }
 
        if((fp_ou=fopen(arqout,"w"))==NULL) {
-               debuga(_("(totday) 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);
        }
 
@@ -164,7 +165,7 @@ void day_totalize(DayObject ddata,const char *tmp, const struct userinfostruct *
                if (ddata->bytes[i]==0 && ddata->elap[i]==0) continue;
                dayidx=i/24;
                if (dayidx>=sizeof(ddata->daylist)/sizeof(*ddata->daylist)) {
-                       debuga(_("Invalid day index found in the hourly statistics\n"));
+                       debuga(__FILE__,__LINE__,_("Invalid day index found in the hourly statistics\n"));
                        exit(EXIT_FAILURE);
                }
                hour=i%24;
@@ -179,8 +180,30 @@ void day_totalize(DayObject ddata,const char *tmp, const struct userinfostruct *
        }
 
        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;
 }
+
+/*!
+Delete the temporary file generated by day_totalize().
+
+\param uinfo The user whose daily statistics are to be deleted.
+*/
+void day_deletefile(const struct userinfostruct *uinfo)
+{
+       char arqout[2048];
+
+       if (KeepTempLog) return;
+
+       if (snprintf(arqout,sizeof(arqout),"%s/%s.day",tmp,uinfo->filename)>=sizeof(arqout)) {
+               debuga(__FILE__,__LINE__,_("Path too long: "));
+               debuga_more("%s/%s%s\n",tmp,uinfo->filename,".day");
+               exit(EXIT_FAILURE);
+       }
+
+       if (unlink(arqout))
+               debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),arqout,strerror(errno));
+}
+