"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "grepday.c" between
sarg-2.3.11.tar.gz and sarg-2.4.0.tar.gz

About: SARG ia a Squid Analysis Report Generator.

grepday.c  (sarg-2.3.11):grepday.c  (sarg-2.4.0)
/* /*
* SARG Squid Analysis Report Generator http://sarg.sourceforge.net * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
* 1998, 2013 * 1998, 2015
* *
* SARG donations: * SARG donations:
* please look at http://sarg.sourceforge.net/donations.php * please look at http://sarg.sourceforge.net/donations.php
* Support: * Support:
* http://sourceforge.net/projects/sarg/forums/forum/363374 * http://sourceforge.net/projects/sarg/forums/forum/363374
* --------------------------------------------------------------------- * ---------------------------------------------------------------------
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
skipping to change at line 124 skipping to change at line 124
TRP_CenterLeft, TRP_CenterLeft,
TRP_Center, TRP_Center,
TRP_CenterRight, TRP_CenterRight,
}; };
#ifdef USE_ICONV #ifdef USE_ICONV
//! The iconv object to convert the text from the locale character set to UTF-8. //! The iconv object to convert the text from the locale character set to UTF-8.
iconv_t localtoutf=(iconv_t)-1; iconv_t localtoutf=(iconv_t)-1;
#endif #endif
extern char GraphConfigFile[MAXLEN];
static void Sarg_gdImageStringFT (struct GraphDataStruct *gdata, int fg, char *f ontlist, static void Sarg_gdImageStringFT (struct GraphDataStruct *gdata, int fg, char *f ontlist,
double ptsize, double angle, int x, int y, const char *string,enum Text RefPos RefPos) double ptsize, double angle, int x, int y, const char *string,enum Text RefPos RefPos)
{ {
char *sstring; char *sstring;
char *retval; char *retval;
int brect[8]; int brect[8];
int minx,miny,maxx,maxy; int minx,miny,maxx,maxy;
int i; int i;
#ifdef USE_ICONV #ifdef USE_ICONV
if (localtoutf!=(iconv_t)-1) { if (localtoutf!=(iconv_t)-1) {
const char *str; const char *str;
char *sstr; char *sstr;
size_t slen, sslen; size_t slen, sslen;
slen = strlen(string) + 1; // We must include string termination character slen = strlen(string) + 1; // We must include string termination character
sslen = slen * 3; // We assume that the UTF8 string will not be bigger than 3 times the original size. sslen = slen * 3; // We assume that the UTF8 string will not be bigger than 3 times the original size.
if (sslen>gdata->string_size) { if (sslen>gdata->string_size) {
sstring = (char *)realloc(gdata->string,sslen); sstring = (char *)realloc(gdata->string,sslen);
if (!sstring) { if (!sstring) {
debuga(_("realloc error (%"PRIu64" bytes required )\n"),(uint64_t)sslen); debuga(__FILE__,__LINE__,_("realloc error (%"PRIu 64" bytes required)\n"),(uint64_t)sslen);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
gdata->string=(char *)sstring; gdata->string=(char *)sstring;
gdata->string_size=sslen; gdata->string_size=sslen;
} else { } else {
sstring=gdata->string; sstring=gdata->string;
sslen=gdata->string_size; sslen=gdata->string_size;
} }
str = string; str = string;
sstr = sstring; sstr = sstring;
if (iconv (localtoutf, (ICONV_CONST char **)&str, &slen, &sstr, & sslen)==-1) { if (iconv (localtoutf, (ICONV_CONST char **)&str, &slen, &sstr, & sslen)==-1) {
/* TRANSLATORS: First %s is the string that failed to con debuga(__FILE__,__LINE__,_("iconv failed to convert strin
vert. Second %s is the input g \"%s\" from %s to UTF-8: %s\n"),string,CharSet,strerror(errno));
* character encoding. Last %s is the reason for the fail
ure.
*/
debugapos("grepday",_("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 sstring=(char *)string; //show something sensible on the graph
} }
} else { } else {
sstring=(char *)string; //show something sensible on the graph sstring=(char *)string; //show something sensible on the graph
} }
#else #else
sstring=(char *)string; sstring=(char *)string;
#endif #endif
if (RefPos!=TRP_BottomLeft) { if (RefPos!=TRP_BottomLeft) {
retval = gdImageStringFTEx (NULL, brect, fg, fontlist, ptsize, an gle, 0, 0, sstring, gdFTEX_Unicode); retval = gdImageStringFTEx (NULL, brect, fg, fontlist, ptsize, an gle, 0, 0, sstring, gdFTEX_Unicode);
if (retval) { if (retval) {
debuga(_("libgd failed to calculate the bounding box of t he 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); exit(EXIT_FAILURE);
} }
/* /*
From libgd documentation, brect contains this without taking into account the angle: From libgd documentation, brect contains this without taking into account the angle:
0 lower left corner, X position 0 lower left corner, X position
1 lower left corner, Y position 1 lower left corner, Y position
2 lower right corner, X position 2 lower right corner, X position
3 lower right corner, Y position 3 lower right corner, Y position
4 upper right corner, X position 4 upper right corner, X position
5 upper right corner, Y position 5 upper right corner, Y position
skipping to change at line 240 skipping to change at line 239
y+=(maxy-miny)/2; y+=(maxy-miny)/2;
break; break;
case TRP_CenterRight: case TRP_CenterRight:
x-=maxx; x-=maxx;
y+=(maxy-miny)/2; y+=(maxy-miny)/2;
break; break;
} }
retval = gdImageStringFTEx (gdata->im, brect, fg, fontlist, ptsize, angle , x, y, sstring, gdFTEX_Unicode); retval = gdImageStringFTEx (gdata->im, brect, fg, fontlist, ptsize, angle , x, y, sstring, gdFTEX_Unicode);
if (retval) { 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); exit(EXIT_FAILURE);
} }
} }
static void bar(struct GraphDataStruct *gdata,int x1,double y,const char *label) static void bar(struct GraphDataStruct *gdata,int x1,double y,const char *label)
{ {
gdPoint points[4]; gdPoint points[4];
int val=0; int val=0;
int width2; int width2;
skipping to change at line 298 skipping to change at line 297
return; return;
} }
static int greport_compute_yaxis(struct PlotStruct *pdata,struct GraphDataStruct *gdata) static int greport_compute_yaxis(struct PlotStruct *pdata,struct GraphDataStruct *gdata)
{ {
double symin,symax; double symin,symax;
double range; double range;
double yscale; double yscale;
if (pdata->ymin<0.) { if (pdata->ymin<0.) {
debuga(_("Minimum for Y scale of the graph is out of range: %"PRI d64"\n"),(int64_t)pdata->ymin); debuga(__FILE__,__LINE__,_("Minimum for Y scale of the graph is o ut of range: %"PRId64"\n"),(int64_t)pdata->ymin);
return(-1); return(-1);
} }
if (pdata->ymax<=0.) { if (pdata->ymax<=0.) {
debuga(_("Maximum for Y scale of the graph is out of range: %"PRI d64"\n"),(int64_t)pdata->ymax); debuga(__FILE__,__LINE__,_("Maximum for Y scale of the graph is o ut of range: %"PRId64"\n"),(int64_t)pdata->ymax);
return(-1); return(-1);
} }
switch(pdata->ytype) switch(pdata->ytype)
{ {
case PTG_LinBin: case PTG_LinBin:
symin=(double)pdata->ymin; symin=(double)pdata->ymin;
symax=(double)pdata->ymax; symax=(double)pdata->ymax;
break; break;
skipping to change at line 327 skipping to change at line 326
symin=0.; symin=0.;
symax=log(pdata->ymax); symax=log(pdata->ymax);
break; break;
case PTG_Time: case PTG_Time:
symin=(double)pdata->ymin; symin=(double)pdata->ymin;
symax=(double)pdata->ymax; symax=(double)pdata->ymax;
break; break;
default: default:
debuga(_("Unknown type %d for Y axis scale\n"),pdata->yty pe); debuga(__FILE__,__LINE__,_("Unknown type %d for Y axis sc ale\n"),pdata->ytype);
return(-1); return(-1);
} }
gdata->YTickSpace=10; gdata->YTickSpace=10;
range=symax-symin; range=symax-symin;
yscale=(double)(gdata->BottomGraph-gdata->TopGraph)/range; yscale=(double)(gdata->BottomGraph-gdata->TopGraph)/range;
gdata->YScale=yscale; gdata->YScale=yscale;
return(0); return(0);
} }
skipping to change at line 381 skipping to change at line 380
char YLabel[50]; char YLabel[50];
int xexterior; int xexterior;
int xinterior; int xinterior;
int xtick; int xtick;
y0=gdata->BottomGraph; y0=gdata->BottomGraph;
yt=gdata->BottomDepth-gdata->BottomGraph; yt=gdata->BottomDepth-gdata->BottomGraph;
xexterior=gdata->LeftGraph-10; xexterior=gdata->LeftGraph-10;
xinterior=gdata->LeftGraph; xinterior=gdata->LeftGraph;
xtick=gdata->LeftGraph-10-gdata->TickLength; xtick=gdata->LeftGraph-10-gdata->TickLength;
for(y=y0-gdata->YTickSpace ; y>=gdata->TopGraph ; y-=gdata->YTickSpace) { for (y=y0-gdata->YTickSpace ; y>=gdata->TopGraph ; y-=gdata->YTickSpace) {
gdImageLine(gdata->im, xtick, y+yt, xexterior, y+yt, gdata->dimgr ay); gdImageLine(gdata->im, xtick, y+yt, xexterior, y+yt, gdata->dimgr ay);
gdImageLine(gdata->im, xexterior, y+yt, xinterior, y, gdata->dimg ray); gdImageLine(gdata->im, xexterior, y+yt, xinterior, y, gdata->dimg ray);
gdImageLine(gdata->im, xinterior, y, gdata->RightGraph, y, gdata- >dimgray); gdImageLine(gdata->im, xinterior, y, gdata->RightGraph, y, gdata- >dimgray);
switch (pdata->ytype) switch (pdata->ytype)
{ {
case PTG_LinBin: case PTG_LinBin:
yval=(double)(y0-y)/gdata->YScale+(double)pdata-> ymin; yval=(double)(y0-y)/gdata->YScale+(double)pdata-> ymin;
greport_formatbin(yval,2,YLabel,sizeof(YLabel)); greport_formatbin(yval,2,YLabel,sizeof(YLabel));
break; break;
skipping to change at line 458 skipping to change at line 457
// first allocated color is the background // first allocated color is the background
gdata.lavender = gdImageColorAllocate(gdata.im, 230, 230, 250); gdata.lavender = gdImageColorAllocate(gdata.im, 230, 230, 250);
gdata.gray = gdImageColorAllocate(gdata.im, 192, 192, 192); gdata.gray = gdImageColorAllocate(gdata.im, 192, 192, 192);
gdata.silver = gdImageColorAllocate(gdata.im, 211, 211, 211); gdata.silver = gdImageColorAllocate(gdata.im, 211, 211, 211);
gdata.black = gdImageColorAllocate(gdata.im, 0, 0, 0); gdata.black = gdImageColorAllocate(gdata.im, 0, 0, 0);
gdata.dimgray = gdImageColorAllocate(gdata.im, 105, 105, 105); gdata.dimgray = gdImageColorAllocate(gdata.im, 105, 105, 105);
gdata.darkblue = gdImageColorAllocate(gdata.im, 0, 0, 139); gdata.darkblue = gdImageColorAllocate(gdata.im, 0, 0, 139);
gdata.goldenrod = gdImageColorAllocate(gdata.im, 234, 234, 174); gdata.goldenrod = gdImageColorAllocate(gdata.im, 234, 234, 174);
gdata.goldenrod2 = gdImageColorAllocate(gdata.im, 207, 181, 59); gdata.goldenrod2 = gdImageColorAllocate(gdata.im, 207, 181, 59);
if(strcmp(GraphDaysBytesBarColor,"orange") == 0) { if (strcmp(GraphDaysBytesBarColor,"orange") == 0) {
gdata.color1 = gdImageColorAllocate(gdata.im, 255, 233, 142); gdata.color1 = gdImageColorAllocate(gdata.im, 255, 233, 142);
gdata.color2 = gdImageColorAllocate(gdata.im, 220, 163, 72); gdata.color2 = gdImageColorAllocate(gdata.im, 220, 163, 72);
gdata.color3 = gdImageColorAllocate(gdata.im, 255, 198, 107); gdata.color3 = gdImageColorAllocate(gdata.im, 255, 198, 107);
} }
else if(strcmp(GraphDaysBytesBarColor,"blue") == 0) { else if (strcmp(GraphDaysBytesBarColor,"blue") == 0) {
gdata.color1 = gdImageColorAllocate(gdata.im, 62, 80, 167); gdata.color1 = gdImageColorAllocate(gdata.im, 62, 80, 167);
gdata.color2 = gdImageColorAllocate(gdata.im, 40, 51, 101); gdata.color2 = gdImageColorAllocate(gdata.im, 40, 51, 101);
gdata.color3 = gdImageColorAllocate(gdata.im, 57, 73, 150); gdata.color3 = gdImageColorAllocate(gdata.im, 57, 73, 150);
} }
else if(strcmp(GraphDaysBytesBarColor,"green") == 0) { else if (strcmp(GraphDaysBytesBarColor,"green") == 0) {
gdata.color1 = gdImageColorAllocate(gdata.im,120,166,129); gdata.color1 = gdImageColorAllocate(gdata.im,120,166,129);
gdata.color2 = gdImageColorAllocate(gdata.im,84,113,82); gdata.color2 = gdImageColorAllocate(gdata.im,84,113,82);
gdata.color3 = gdImageColorAllocate(gdata.im,158,223,167); gdata.color3 = gdImageColorAllocate(gdata.im,158,223,167);
} }
else if(strcmp(GraphDaysBytesBarColor,"yellow") == 0) { else if (strcmp(GraphDaysBytesBarColor,"yellow") == 0) {
gdata.color1 = gdImageColorAllocate(gdata.im,185,185,10); gdata.color1 = gdImageColorAllocate(gdata.im,185,185,10);
gdata.color2 = gdImageColorAllocate(gdata.im,111,111,10); gdata.color2 = gdImageColorAllocate(gdata.im,111,111,10);
gdata.color3 = gdImageColorAllocate(gdata.im,166,166,10); gdata.color3 = gdImageColorAllocate(gdata.im,166,166,10);
} }
else if(strcmp(GraphDaysBytesBarColor,"brown") == 0) { else if (strcmp(GraphDaysBytesBarColor,"brown") == 0) {
gdata.color1 = gdImageColorAllocate(gdata.im,97,45,27); gdata.color1 = gdImageColorAllocate(gdata.im,97,45,27);
gdata.color2 = gdImageColorAllocate(gdata.im,60,30,20); gdata.color2 = gdImageColorAllocate(gdata.im,60,30,20);
gdata.color3 = gdImageColorAllocate(gdata.im,88,41,26); gdata.color3 = gdImageColorAllocate(gdata.im,88,41,26);
} }
else if(strcmp(GraphDaysBytesBarColor,"red") == 0){ else if (strcmp(GraphDaysBytesBarColor,"red") == 0){
gdata.color1 = gdImageColorAllocate(gdata.im,185,10,10); gdata.color1 = gdImageColorAllocate(gdata.im,185,10,10);
gdata.color2 = gdImageColorAllocate(gdata.im,111,10,10); gdata.color2 = gdImageColorAllocate(gdata.im,111,10,10);
gdata.color3 = gdImageColorAllocate(gdata.im,166,10,10); gdata.color3 = gdImageColorAllocate(gdata.im,166,10,10);
} else { } else {
debuga(_("Unknown color \"%s\" requested for the graph. Using ora nge instead\n"),GraphDaysBytesBarColor); debuga(__FILE__,__LINE__,_("Unknown color \"%s\" requested for th e graph. Using orange instead\n"),GraphDaysBytesBarColor);
gdata.color1 = gdImageColorAllocate(gdata.im, 255, 233, 142); gdata.color1 = gdImageColorAllocate(gdata.im, 255, 233, 142);
gdata.color2 = gdImageColorAllocate(gdata.im, 220, 163, 72); gdata.color2 = gdImageColorAllocate(gdata.im, 220, 163, 72);
gdata.color3 = gdImageColorAllocate(gdata.im, 255, 198, 107); gdata.color3 = gdImageColorAllocate(gdata.im, 255, 198, 107);
} }
// rectangle around the image // rectangle around the image
gdImageRectangle(gdata.im, 0, 0, ImgXSize-1, ImgYSize-1, gdata.dimgray); gdImageRectangle(gdata.im, 0, 0, ImgXSize-1, ImgYSize-1, gdata.dimgray);
// backtround of the graph // backtround of the graph
gdImageFilledRectangle(gdata.im, LeftMargin, gdata.TopGraph, gdata.RightG raph, gdata.BottomGraph, gdata.silver); gdImageFilledRectangle(gdata.im, LeftMargin, gdata.TopGraph, gdata.RightG raph, gdata.BottomGraph, gdata.silver);
skipping to change at line 540 skipping to change at line 539
gdImageLine(gdata.im, LeftMargin, gdata.BottomGraph, gdata.RightGraph, gd ata.BottomGraph, gdata.black); gdImageLine(gdata.im, LeftMargin, gdata.BottomGraph, gdata.RightGraph, gd ata.BottomGraph, gdata.black);
// vertical right line of the graph // vertical right line of the graph
gdImageLine(gdata.im, gdata.RightGraph, gdata.TopGraph, gdata.RightGraph, gdata.BottomGraph, gdata.black); gdImageLine(gdata.im, gdata.RightGraph, gdata.TopGraph, gdata.RightGraph, gdata.BottomGraph, gdata.black);
// diagonal line to close the right of the bottom depth // diagonal line to close the right of the bottom depth
gdImageLine(gdata.im, gdata.RightGraph-10, gdata.BottomDepth, gdata.Right Graph, gdata.BottomGraph, gdata.black); gdImageLine(gdata.im, gdata.RightGraph-10, gdata.BottomDepth, gdata.Right Graph, gdata.BottomGraph, gdata.black);
// Y axis ticks // Y axis ticks
greport_draw_yaxis(pdata,&gdata); greport_draw_yaxis(pdata,&gdata);
// X axis ticks and labels // X axis ticks and labels
for(y=1; y<=pdata->npoints; y++) { for (y=1; y<=pdata->npoints; y++) {
x=gdata.LeftGraph-10+(int)((double)y*gdata.XScale+0.5); x=gdata.LeftGraph-10+(int)((double)y*gdata.XScale+0.5);
gdImageLine(gdata.im, x, gdata.BottomDepth, x, gdata.BottomDepth+ TickLength, gdata.dimgray); gdImageLine(gdata.im, x, gdata.BottomDepth, x, gdata.BottomDepth+ TickLength, gdata.dimgray);
sprintf(s,"%02d",y); sprintf(s,"%02d",y);
Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,x,gdata .BottomDepth+TickLength+1,s,TRP_TopCenter); Sarg_gdImageStringFT(&gdata,gdata.dimgray,GraphFont,7,0.0,x,gdata .BottomDepth+TickLength+1,s,TRP_TopCenter);
} }
t = time(NULL); t = time(NULL);
local = localtime(&t); local = localtime(&t);
if(DateFormat[0]=='u') if (df=='u')
strftime(ftime, sizeof(ftime), "%b/%d/%Y %H:%M", local); strftime(ftime, sizeof(ftime), "%b/%d/%Y %H:%M", local);
if(DateFormat[0]=='e') if (df=='e')
strftime(ftime, sizeof(ftime), "%d/%b/%Y-%H:%M", local); strftime(ftime, sizeof(ftime), "%d/%b/%Y-%H:%M", local);
x=ImgXSize*5/12; x=ImgXSize*5/12;
Sarg_gdImageStringFT(&gdata,gdata.darkblue,GraphFont,7,0.0,ImgXSize-10,Im gYSize-10,ftime,TRP_BottomRight); Sarg_gdImageStringFT(&gdata,gdata.darkblue,GraphFont,7,0.0,ImgXSize-10,Im gYSize-10,ftime,TRP_BottomRight);
if(ShowSargInfo) Sarg_gdImageStringFT(&gdata,gdata.darkblue,GraphFont,10, 0.0,x,15,_("SARG, "),TRP_BottomRight); if (ShowSargInfo) Sarg_gdImageStringFT(&gdata,gdata.darkblue,GraphFont,10 ,0.0,x,15,_("SARG, "),TRP_BottomRight);
Sarg_gdImageStringFT(&gdata,gdata.darkblue,GraphFont,10,0.0,x,15,Title,TR P_BottomLeft); Sarg_gdImageStringFT(&gdata,gdata.darkblue,GraphFont,10,0.0,x,15,Title,TR P_BottomLeft);
sprintf(warea,_("Period: %s"),period.text); sprintf(warea,_("Period: %s"),period.text);
Sarg_gdImageStringFT(&gdata,gdata.darkblue,GraphFont,9,0.0,x,27,warea,TRP _BottomLeft); Sarg_gdImageStringFT(&gdata,gdata.darkblue,GraphFont,9,0.0,x,27,warea,TRP _BottomLeft);
sprintf(warea,_("User: %s"),uinfo->label); sprintf(warea,_("User: %s"),uinfo->label);
Sarg_gdImageStringFT(&gdata,gdata.darkblue,GraphFont,9,0.0,x,38,warea,TRP _BottomLeft); Sarg_gdImageStringFT(&gdata,gdata.darkblue,GraphFont,9,0.0,x,38,warea,TRP _BottomLeft);
Sarg_gdImageStringFT(&gdata,gdata.black,GraphFont,10,3.141592/2,15,ImgYSi ze/2,pdata->YLabel,TRP_CenterLeft); Sarg_gdImageStringFT(&gdata,gdata.black,GraphFont,10,3.141592/2,15,ImgYSi ze/2,pdata->YLabel,TRP_CenterLeft);
Sarg_gdImageStringFT(&gdata,gdata.black,GraphFont,10,0.0,ImgXSize/2,ImgYS ize-20,pdata->XLabel,TRP_BottomCenter); Sarg_gdImageStringFT(&gdata,gdata.black,GraphFont,10,0.0,ImgXSize/2,ImgYS ize-20,pdata->XLabel,TRP_BottomCenter);
logpmin=(pdata->ytype==PTG_LogBin && pdata->ymin>0.) ? log(pdata->ymin) : 0.; logpmin=(pdata->ytype==PTG_LogBin && pdata->ymin>0.) ? log(pdata->ymin) : 0.;
skipping to change at line 617 skipping to change at line 616
default: default:
yval=-1.; yval=-1.;
break; break;
} }
if (yval>=0.) bar(&gdata,x1,yval,blabel); if (yval>=0.) bar(&gdata,x1,yval,blabel);
} }
} }
if (snprintf(graph,sizeof(graph),"%s/%s/%s",outdirname,uinfo->filename,pd ata->pngfile)>=sizeof(graph)) { if (snprintf(graph,sizeof(graph),"%s/%s/%s",outdirname,uinfo->filename,pd ata->pngfile)>=sizeof(graph)) {
/* TRANSLATORS: The message is followed by the path that is too l ong. */ /* TRANSLATORS: The message is followed by the path that is too l ong. */
debuga(_("User name too long to manufacture file name ")); debuga(__FILE__,__LINE__,_("User name too long to manufacture fil e name "));
debuga_more("%s/%s/%s\n",outdirname,uinfo->filename,pdata->pngfil e); debuga_more("%s/%s/%s\n",outdirname,uinfo->filename,pdata->pngfil e);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if((pngout=fopen(graph,"wb"))==NULL) { if ((pngout=fopen(graph,"wb"))==NULL) {
debugapos("grepday",_("Cannot open file \"%s\": %s\n"),graph,stre debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),graph
rror(errno)); ,strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
gdImagePng(gdata.im, pngout); gdImagePng(gdata.im, pngout);
fclose(pngout); if (fclose(pngout)==EOF) {
debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),graph,s
trerror(errno));
}
gdImageDestroy(gdata.im); gdImageDestroy(gdata.im);
if (gdata.string) free(gdata.string); if (gdata.string) free(gdata.string);
} }
#endif //HAVE_GD #endif //HAVE_GD
void greport_prepare(void) void greport_prepare(void)
{ {
#ifdef HAVE_GD #ifdef HAVE_GD
if (!Graphs) { if (!Graphs) {
if (debugz) { if (debugz>=LogLevel_Process)
/* TRANSLATORS: %s is the name of the configuration file debugaz(__FILE__,__LINE__,_("Graphs disabled as requested
providing in \"%s\"\n"),GraphConfigFile);
* the graph option.
*/
debugaz(_("Graphs disabled as requested in \"%s\"\n"),Con
figFile);
}
return; return;
} }
if (GraphFont[0]=='\0') { if (GraphFont[0]=='\0') {
if (debugz) { if (debugz>=LogLevel_Process) {
/* TRANSLATORS: %s is the name of the configuration file const char *File=(GraphConfigFile[0]) ? GraphConfigFile :
providing ConfigFile;
* the graph option. debugaz(__FILE__,__LINE__,_("Graphs disabled as no font n
*/ ames were provided in \"%s\"\n"),File);
debugaz(_("Graphs disabled as no font names were provided
in \"%s\"\n"),ConfigFile);
} }
return; return;
} }
if(access(GraphFont, R_OK) != 0) { if (access(GraphFont, R_OK) != 0) {
debugapos("grepday",_("Fontname \"%s\" not found\n"),GraphFont); debuga(__FILE__,__LINE__,_("Font name \"%s\" not found\n"),GraphF
ont);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#ifdef USE_ICONV #ifdef USE_ICONV
localtoutf = iconv_open ("UTF-8", CharSet); localtoutf = iconv_open ("UTF-8", CharSet);
if (localtoutf==(iconv_t)-1) { if (localtoutf==(iconv_t)-1) {
debugapos("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 #endif
#endif //HAVE_GD #endif //HAVE_GD
} }
void greport_day(const struct userinfostruct *uinfo) void greport_day(const struct userinfostruct *uinfo)
{ {
#ifdef HAVE_GD #ifdef HAVE_GD
FILE *fp_in, *fp_ou; FILE *fp_in, *fp_ou;
skipping to change at line 686 skipping to change at line 681
char buf[MAXLEN]; char buf[MAXLEN];
int day; int day;
long long int llday; long long int llday;
long long int bytes; long long int bytes;
long long int elap; long long int elap;
long long int bytespoints[31]; long long int bytespoints[31];
long long int elappoints[31]; long long int elappoints[31];
struct getwordstruct gwarea; struct getwordstruct gwarea;
struct PlotStruct pdata; struct PlotStruct pdata;
if (datetimeby==0) return;
if (!Graphs || GraphFont[0]=='\0') return;
if (snprintf(wdirname,sizeof(wdirname),"%s/%s.day",tmp,uinfo->filename)>= sizeof(wdirname)) { if (snprintf(wdirname,sizeof(wdirname),"%s/%s.day",tmp,uinfo->filename)>= sizeof(wdirname)) {
debuga(_("User name too long to manufacture file name ")); debuga(__FILE__,__LINE__,_("User name too long to manufacture fil e name "));
debuga_more("%s/%s.day\n",tmp,uinfo->filename); debuga_more("%s/%s.day\n",tmp,uinfo->filename);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if(access(wdirname, R_OK) != 0) { if (access(wdirname, R_OK) != 0) {
return;
}
if(!Graphs || GraphFont[0]=='\0') {
if (!KeepTempLog && unlink(wdirname))
debuga(_("Cannot delete \"%s\": %s\n"),wdirname,strerror(
errno));
return; return;
} }
if((fp_in=fopen(wdirname,"r"))==NULL) { if ((fp_in=fopen(wdirname,"r"))==NULL) {
debugapos("grepday",_("Cannot open file \"%s\": %s\n"),wdirname,s debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),wdirn
trerror(errno)); ame,strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
memset(bytespoints,0,sizeof(bytespoints)); memset(bytespoints,0,sizeof(bytespoints));
memset(elappoints,0,sizeof(elappoints)); memset(elappoints,0,sizeof(elappoints));
while(fgets(buf,sizeof(buf),fp_in)!=NULL) { while(fgets(buf,sizeof(buf),fp_in)!=NULL) {
fixendofline(buf); fixendofline(buf);
getword_start(&gwarea,buf); getword_start(&gwarea,buf);
if (getword_atoll(&llday,&gwarea,'/')<0) { 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); exit(EXIT_FAILURE);
} }
day=(int)llday; day=(int)llday;
if (day<1 || day>31) continue; if (day<1 || day>31) continue;
if (getword_skip(20,&gwarea,'\t')<0 || getword_skip(20,&gwarea,'\ t')<0) { 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); exit(EXIT_FAILURE);
} }
if ((datetimeby & DATETIME_BYTE)!=0) { if ((datetimeby & DATETIME_BYTE)!=0) {
if (getword_atoll(&bytes,&gwarea,'\t')<0) { if (getword_atoll(&bytes,&gwarea,'\t')<0) {
debuga(_("Invalid number of bytes in file \"%s\"\ n"),wdirname); debuga(__FILE__,__LINE__,_("Invalid number of byt es in file \"%s\"\n"),wdirname);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
bytespoints[day-1]+=bytes; bytespoints[day-1]+=bytes;
} }
if ((datetimeby & DATETIME_ELAP)!=0) { if ((datetimeby & DATETIME_ELAP)!=0) {
if (getword_atoll(&elap,&gwarea,'\0')<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); exit(EXIT_FAILURE);
} }
elappoints[day-1]+=elap; elappoints[day-1]+=elap;
} }
} }
fclose(fp_in); if (fclose(fp_in)==EOF) {
if (!KeepTempLog && unlink(wdirname)) { debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),wdirname
debuga(_("Cannot delete \"%s\": %s\n"),wdirname,strerror(errno)); ,strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (snprintf(wdirname,sizeof(wdirname),"%s/%s/graph.html",outdirname,uinf o->filename)>=sizeof(wdirname)) { if (snprintf(wdirname,sizeof(wdirname),"%s/%s/graph.html",outdirname,uinf o->filename)>=sizeof(wdirname)) {
debuga(_("User name too long to manufacture file name ")); debuga(__FILE__,__LINE__,_("User name too long to manufacture fil e name "));
debuga_more("%s/%s/%s\n",outdirname,uinfo->filename,"graph.html") ; debuga_more("%s/%s/%s\n",outdirname,uinfo->filename,"graph.html") ;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if ((fp_ou=fopen(wdirname,"wt"))==NULL) { if ((fp_ou=fopen(wdirname,"wt"))==NULL) {
debugapos("grepday",_("Cannot open file \"%s\": %s\n"),wdirname,s trerror(errno)); debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),wdirn ame,strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
write_html_head(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("Graph rep ort"),HTML_JS_NONE); write_html_head(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("Graph rep ort"),HTML_JS_NONE);
fputs("<table class=\"report\" cellpadding=\"0\" cellspacing=\"2\">\n", f p_ou); fputs("<table class=\"report\" cellpadding=\"0\" cellspacing=\"2\">\n", f p_ou);
if((datetimeby & DATETIME_BYTE)!=0) { if ((datetimeby & DATETIME_BYTE)!=0) {
memset(&pdata,0,sizeof(pdata)); memset(&pdata,0,sizeof(pdata));
pdata.datapoints=bytespoints; pdata.datapoints=bytespoints;
pdata.npoints=31; pdata.npoints=31;
pdata.XLabel=_("DAYS"); pdata.XLabel=_("DAYS");
pdata.ymin=50LL*1000LL; pdata.ymin=50LL*1000LL;
pdata.ymax=5LL*1000LL*1000LL*1000LL; pdata.ymax=5LL*1000LL*1000LL*1000LL;
pdata.ytype=PTG_LogBin; pdata.ytype=PTG_LogBin;
pdata.YLabel=_("BYTES"); pdata.YLabel=_("BYTES");
pdata.pngfile="graph_day_byte.png"; pdata.pngfile="graph_day_byte.png";
greport_plot(uinfo,&pdata); greport_plot(uinfo,&pdata);
fprintf(fp_ou,"<tr><td><img src=\"%s\" alt=\"B\"></td></tr>\n",pd ata.pngfile); fprintf(fp_ou,"<tr><td><img src=\"%s\" alt=\"B\"></td></tr>\n",pd ata.pngfile);
} }
if((datetimeby & DATETIME_ELAP)!=0) { if ((datetimeby & DATETIME_ELAP)!=0) {
memset(&pdata,0,sizeof(pdata)); memset(&pdata,0,sizeof(pdata));
pdata.datapoints=elappoints; pdata.datapoints=elappoints;
pdata.npoints=31; pdata.npoints=31;
pdata.XLabel=_("DAYS"); pdata.XLabel=_("DAYS");
pdata.ymin=0; pdata.ymin=0;
pdata.ymax=86400000; pdata.ymax=86400000;
pdata.ytype=PTG_Time; pdata.ytype=PTG_Time;
pdata.YLabel=_("ELAPSED TIME"); pdata.YLabel=_("ELAPSED TIME");
pdata.pngfile="graph_day_elap.png"; pdata.pngfile="graph_day_elap.png";
greport_plot(uinfo,&pdata); greport_plot(uinfo,&pdata);
fprintf(fp_ou,"<tr><td><img src=\"%s\" alt=\"E\"></td></tr>\n",pd ata.pngfile); fprintf(fp_ou,"<tr><td><img src=\"%s\" alt=\"E\"></td></tr>\n",pd ata.pngfile);
} }
fputs("</table>\n",fp_ou); fputs("</table>\n",fp_ou);
if (write_html_trailer(fp_ou)<0) write_html_trailer(fp_ou);
debuga(_("Write error in file \"%s\"\n"),wdirname); if (fclose(fp_ou)==EOF) {
if (fclose(fp_ou)==EOF) debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),wdirnam
debuga(_("Failed to close file \"%s\": %s\n"),wdirname,strerror(e e,strerror(errno));
rrno)); exit(EXIT_FAILURE);
}
#endif //HAVE_GD #endif //HAVE_GD
return; return;
} }
void greport_cleanup(void) void greport_cleanup(void)
{ {
#ifdef HAVE_GD #ifdef HAVE_GD
gdFontCacheShutdown(); gdFontCacheShutdown();
 End of changes. 42 change blocks. 
76 lines changed or deleted 67 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)