]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - grepday.c
Add support to decompress xz files
[thirdparty/sarg.git] / grepday.c
index e7bc8cd224f43b1bff829a104a027822cd83e076..8b409f1010dc1df0a3adbe164491cba075aeaf5d 100644 (file)
--- a/grepday.c
+++ b/grepday.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
@@ -121,6 +121,8 @@ enum TextRefPos
 iconv_t localtoutf=(iconv_t)-1;
 #endif
 
+extern char GraphConfigFile[MAXLEN];
+
 static void Sarg_gdImageStringFT (struct GraphDataStruct *gdata, int fg, char *fontlist,
          double ptsize, double angle, int x, int y, const char *string,enum TextRefPos RefPos)
 {
@@ -141,7 +143,7 @@ static void Sarg_gdImageStringFT (struct GraphDataStruct *gdata, int fg, char *f
                if (sslen>gdata->string_size) {
                        sstring = (char *)realloc(gdata->string,sslen);
                        if (!sstring) {
-                               debuga(_("realloc error (%"PRIu64" bytes required)\n"),(uint64_t)sslen);
+                               debuga(__FILE__,__LINE__,_("realloc error (%"PRIu64" bytes required)\n"),(uint64_t)sslen);
                                exit(EXIT_FAILURE);
                        }
                        gdata->string=(char *)sstring;
@@ -154,7 +156,7 @@ static void Sarg_gdImageStringFT (struct GraphDataStruct *gdata, int fg, char *f
                str = string;
                sstr = sstring;
                if (iconv (localtoutf, (ICONV_CONST char **)&str, &slen, &sstr, &sslen)==-1) {
-                       debuga(_("(grepday) iconv failed to convert string \"%s\" from %s to UTF-8 - %s\n"),string,CharSet,strerror(errno));
+                       debuga(__FILE__,__LINE__,_("iconv failed to convert string \"%s\" from %s to UTF-8: %s\n"),string,CharSet,strerror(errno));
                        sstring=(char *)string; //show something sensible on the graph
                }
        } else {
@@ -167,7 +169,7 @@ static void Sarg_gdImageStringFT (struct GraphDataStruct *gdata, int fg, char *f
        if (RefPos!=TRP_BottomLeft) {
                retval = gdImageStringFTEx (NULL, brect, fg, fontlist, ptsize, angle, 0, 0, sstring, gdFTEX_Unicode);
                if (retval) {
-                       debuga(_("libgd failed to calculate the bounding box of the text \"%s\": %s\n"),sstring,retval);
+                       debuga(__FILE__,__LINE__,_("libgd failed to calculate the bounding box of the text \"%s\": %s\n"),sstring,retval);
                        exit(EXIT_FAILURE);
                }
                /*
@@ -234,7 +236,7 @@ static void Sarg_gdImageStringFT (struct GraphDataStruct *gdata, int fg, char *f
        }
        retval = gdImageStringFTEx (gdata->im, brect, fg, fontlist, ptsize, angle, x, y, sstring, gdFTEX_Unicode);
        if (retval) {
-               debuga(_("libgd failed to render the text \"%s\": %s\n"),sstring,retval);
+               debuga(__FILE__,__LINE__,_("libgd failed to render the text \"%s\": %s\n"),sstring,retval);
                exit(EXIT_FAILURE);
        }
 }
@@ -292,11 +294,11 @@ static int greport_compute_yaxis(struct PlotStruct *pdata,struct GraphDataStruct
        double yscale;
 
        if (pdata->ymin<0.) {
-               debuga(_("Minimum for Y scale of the graph is out of range: %"PRId64"\n"),(int64_t)pdata->ymin);
+               debuga(__FILE__,__LINE__,_("Minimum for Y scale of the graph is out of range: %"PRId64"\n"),(int64_t)pdata->ymin);
                return(-1);
        }
        if (pdata->ymax<=0.) {
-               debuga(_("Maximum for Y scale of the graph is out of range: %"PRId64"\n"),(int64_t)pdata->ymax);
+               debuga(__FILE__,__LINE__,_("Maximum for Y scale of the graph is out of range: %"PRId64"\n"),(int64_t)pdata->ymax);
                return(-1);
        }
 
@@ -321,7 +323,7 @@ static int greport_compute_yaxis(struct PlotStruct *pdata,struct GraphDataStruct
                        break;
 
                default:
-                       debuga(_("Unknown type %d for Y axis scale\n"),pdata->ytype);
+                       debuga(__FILE__,__LINE__,_("Unknown type %d for Y axis scale\n"),pdata->ytype);
                        return(-1);
        }
        gdata->YTickSpace=10;
@@ -482,7 +484,7 @@ static void greport_plot(const struct userinfostruct *uinfo,struct PlotStruct *p
                gdata.color2 = gdImageColorAllocate(gdata.im,111,10,10);
                gdata.color3 = gdImageColorAllocate(gdata.im,166,10,10);
        } else {
-               debuga(_("Unknown color \"%s\" requested for the graph. Using orange instead\n"),GraphDaysBytesBarColor);
+               debuga(__FILE__,__LINE__,_("Unknown color \"%s\" requested for the graph. Using orange instead\n"),GraphDaysBytesBarColor);
                gdata.color1 = gdImageColorAllocate(gdata.im, 255, 233, 142);
                gdata.color2 = gdImageColorAllocate(gdata.im, 220, 163, 72);
                gdata.color3 = gdImageColorAllocate(gdata.im, 255, 198, 107);
@@ -610,16 +612,18 @@ static void greport_plot(const struct userinfostruct *uinfo,struct PlotStruct *p
        }
 
        if (snprintf(graph,sizeof(graph),"%s/%s/%s",outdirname,uinfo->filename,pdata->pngfile)>=sizeof(graph)) {
-               debuga(_("user name too long for %s/%s/%s\n"),outdirname,uinfo->filename,pdata->pngfile);
+               /* TRANSLATORS: The message is followed by the path that is too long. */
+               debuga(__FILE__,__LINE__,_("User name too long to manufacture file name "));
+               debuga_more("%s/%s/%s\n",outdirname,uinfo->filename,pdata->pngfile);
                exit(EXIT_FAILURE);
        }
        if((pngout=fopen(graph,"wb"))==NULL) {
-               debuga(_("(grepday) Cannot open log file %s: %s\n"),graph,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),graph,strerror(errno));
                exit(EXIT_FAILURE);
        }
        gdImagePng(gdata.im, pngout);
        if (fclose(pngout)==EOF) {
-               debuga(_("Write error in %s: %s\n"),graph,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),graph,strerror(errno));
        }
        gdImageDestroy(gdata.im);
 
@@ -633,24 +637,26 @@ void greport_prepare(void)
 #ifdef HAVE_GD
        if (!Graphs) {
                if (debugz>=LogLevel_Process)
-                       debugaz(_("Graphs disabled as requested in %s\n"),ConfigFile);
+                       debugaz(__FILE__,__LINE__,_("Graphs disabled as requested in %s\n"),GraphConfigFile);
                return;
        }
        if (GraphFont[0]=='\0') {
-               if (debugz>=LogLevel_Process)
-                       debugaz(_("Graphs disabled as no font names were provided in %s\n"),ConfigFile);
+               if (debugz>=LogLevel_Process) {
+                       const char *File=(GraphConfigFile[0]) ? GraphConfigFile : ConfigFile;
+                       debugaz(__FILE__,__LINE__,_("Graphs disabled as no font names were provided in %s\n"),File);
+               }
                return;
        }
 
        if(access(GraphFont, R_OK) != 0) {
-               debuga(_("(grepday) Fontname %s not found\n"),GraphFont);
+               debuga(__FILE__,__LINE__,_("Font name %s not found\n"),GraphFont);
                exit(EXIT_FAILURE);
        }
 
 #ifdef USE_ICONV
        localtoutf = iconv_open ("UTF-8", CharSet);
        if (localtoutf==(iconv_t)-1) {
-               debuga(_("(grepday) iconv cannot convert from %s to UTF-8 - %s\n"),CharSet,strerror(errno));
+               debuga(__FILE__,__LINE__,_("iconv cannot convert from %s to UTF-8: %s\n"),CharSet,strerror(errno));
        }
 #endif
 
@@ -675,7 +681,8 @@ void greport_day(const struct userinfostruct *uinfo)
        if (datetimeby==0) return;
        if (!Graphs || GraphFont[0]=='\0') return;
        if (snprintf(wdirname,sizeof(wdirname),"%s/%s.day",tmp,uinfo->filename)>=sizeof(wdirname)) {
-               debuga(_("user name too long for %s/%s.day\n"),tmp,uinfo->filename);
+               debuga(__FILE__,__LINE__,_("User name too long to manufacture file name "));
+               debuga_more("%s/%s.day\n",tmp,uinfo->filename);
                exit(EXIT_FAILURE);
        }
        if(access(wdirname, R_OK) != 0) {
@@ -683,7 +690,7 @@ void greport_day(const struct userinfostruct *uinfo)
        }
 
        if((fp_in=fopen(wdirname,"r"))==NULL) {
-               debuga(_("(grepday) 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);
        }
 
@@ -693,38 +700,42 @@ void greport_day(const struct userinfostruct *uinfo)
                fixendofline(buf);
                getword_start(&gwarea,buf);
                if (getword_atoll(&llday,&gwarea,'/')<0) {
-                       debuga(_("Invalid date in file %s\n"),wdirname);
+                       debuga(__FILE__,__LINE__,_("Invalid date in file \"%s\"\n"),wdirname);
                        exit(EXIT_FAILURE);
                }
                day=(int)llday;
                if (day<1 || day>31) continue;
                if (getword_skip(20,&gwarea,'\t')<0 || getword_skip(20,&gwarea,'\t')<0) {
-                       debuga(_("Invalid entry in file %s\n"),wdirname);
+                       debuga(__FILE__,__LINE__,_("Invalid entry in file \"%s\"\n"),wdirname);
                        exit(EXIT_FAILURE);
                }
                if ((datetimeby & DATETIME_BYTE)!=0) {
                        if (getword_atoll(&bytes,&gwarea,'\t')<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);
                        }
                        bytespoints[day-1]+=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);
                        }
                        elappoints[day-1]+=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 (snprintf(wdirname,sizeof(wdirname),"%s/%s/graph.html",outdirname,uinfo->filename)>=sizeof(wdirname)) {
-               debuga(_("user name too long for %s/%s/%s\n"),outdirname,uinfo->filename,"graph.html");
+               debuga(__FILE__,__LINE__,_("User name too long to manufacture file name "));
+               debuga_more("%s/%s/%s\n",outdirname,uinfo->filename,"graph.html");
                exit(EXIT_FAILURE);
        }
        if ((fp_ou=fopen(wdirname,"wt"))==NULL) {
-               debuga(_("(grepday) Cannot open output file %s: %s\n"),wdirname,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),wdirname,strerror(errno));
                exit(EXIT_FAILURE);
        }
        write_html_head(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("Graph report"),HTML_JS_NONE);
@@ -758,10 +769,11 @@ void greport_day(const struct userinfostruct *uinfo)
        }
        fputs("</table>\n",fp_ou);
 
-       if (write_html_trailer(fp_ou)<0)
-               debuga(_("Write error in file %s\n"),wdirname);
-       if (fclose(fp_ou)==EOF)
-               debuga(_("Write error in %s: %s\n"),wdirname,strerror(errno));
+       write_html_trailer(fp_ou);
+       if (fclose(fp_ou)==EOF) {
+               debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),wdirname,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
 #endif //HAVE_GD
 
        return;