"Fossies" - the Fresh Open Source Software Archive  

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

About: SARG ia a Squid Analysis Report Generator.

repday.c  (sarg-2.3.11):repday.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 30 skipping to change at line 30
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
* *
*/ */
#include "include/conf.h" #include "include/conf.h"
#include "include/defs.h" #include "include/defs.h"
extern numlist hours; extern int hours[24];
void report_day(const struct userinfostruct *uinfo) void report_day(const struct userinfostruct *uinfo)
{ {
FILE *fp_in, *fp_ou; FILE *fp_in, *fp_ou;
char buf[200]; char buf[200];
char data[20]; char data[20];
long long int hour; long long int hour;
const char *label; const char *label;
char arqout[MAXLEN]; char arqout[MAXLEN];
skipping to change at line 60 skipping to change at line 60
long long int bytes; long long int bytes;
long long int elap; long long int elap;
long long int tbytes[MAX_DATETIME_DAYS*24]; long long int tbytes[MAX_DATETIME_DAYS*24];
long long int telap[MAX_DATETIME_DAYS*24]; long long int telap[MAX_DATETIME_DAYS*24];
long long int tt; long long int tt;
long long int tttime[24]; long long int tttime[24];
int i, j; int i, j;
struct getwordstruct gwarea; struct getwordstruct gwarea;
struct tm t; struct tm t;
snprintf(wdirname,sizeof(wdirname),"%s/%s.day",tmp,uinfo->filename); if (datetimeby==0) return;
if(access(wdirname, R_OK) != 0) return; format_path(__FILE__, __LINE__, 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->fil ename,uinfo->filename)>=sizeof(arqout)) { if (snprintf(arqout,sizeof(arqout),"%s/%s/d%s.html",outdirname,uinfo->fil ename,uinfo->filename)>=sizeof(arqout)) {
debuga(_("Path too long: ")); debuga(__FILE__,__LINE__,_("Path too long: "));
debuga_more("%s/%s/d%s.html\n",outdirname,uinfo->filename,uinfo-> filename); debuga_more("%s/%s/d%s.html\n",outdirname,uinfo->filename,uinfo-> filename);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if((fp_in=fopen(wdirname,"r"))==NULL) { if ((fp_in=fopen(wdirname,"r"))==NULL) {
debugapos("repday",_("Cannot open file \"%s\": %s\n"),wdirname,st debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),wdirn
rerror(errno)); ame,strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
memset(tbytes,0,sizeof(tbytes)); memset(tbytes,0,sizeof(tbytes));
memset(telap,0,sizeof(telap)); memset(telap,0,sizeof(telap));
ndaylist=0; ndaylist=0;
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(data,sizeof(data),&gwarea,'\t')<0) { 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); exit(EXIT_FAILURE);
} }
if (sscanf(data,"%d/%d/%d",&day,&month,&year)!=3) continue; if (sscanf(data,"%d/%d/%d",&day,&month,&year)!=3) continue;
if (day<1 || day>31 || month<1 || month>12 || year>9999) continue ; if (day<1 || day>31 || month<1 || month>12 || year>9999) continue ;
daynum=(year*10000)+(month*100)+day; daynum=(year*10000)+(month*100)+day;
for (dayidx=0 ; dayidx<ndaylist && daynum!=daylist[dayidx] ; dayi dx++); for (dayidx=0 ; dayidx<ndaylist && daynum!=daylist[dayidx] ; dayi dx++);
if (dayidx>=ndaylist) { if (dayidx>=ndaylist) {
if (dayidx>=sizeof(daylist)/sizeof(*daylist)) { if (dayidx>=sizeof(daylist)/sizeof(*daylist)) {
debuga(_("Too many different dates in \"%s\"\n"), wdirname); debuga(__FILE__,__LINE__,_("Too many different da tes in file \"%s\"\n"),wdirname);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
daylist[ndaylist++]=daynum; daylist[ndaylist++]=daynum;
} }
if (getword_atoll(&hour,&gwarea,'\t')<0) { 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); exit(EXIT_FAILURE);
} }
ihour=(int)hour; ihour=(int)hour;
i=dayidx*24+ihour; i=dayidx*24+ihour;
if ((datetimeby & DATETIME_BYTE)!=0) { if ((datetimeby & DATETIME_BYTE)!=0) {
colsep=((datetimeby & DATETIME_ELAP)!=0) ? '\t' : '\0'; colsep=((datetimeby & DATETIME_ELAP)!=0) ? '\t' : '\0';
if (getword_atoll(&bytes,&gwarea,colsep)<0) { if (getword_atoll(&bytes,&gwarea,colsep)<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);
} }
tbytes[i]+=bytes; tbytes[i]+=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);
} }
telap[i]+=elap; 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) { if ((fp_ou=fopen(arqout,"w"))==NULL) {
debugapos("repday",_("Cannot open file \"%s\": %s\n"),arqout,stre debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),arqou
rror(errno)); t,strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("Day rep ort"),HTML_JS_NONE); write_html_header(fp_ou,(IndexTree == INDEX_TREE_DATE) ? 4 : 2,_("Day rep ort"),HTML_JS_NONE);
fprintf(fp_ou,"<tr><td class=\"header_c\" colspan=\"2\">%s:&nbsp;%s</td>< /tr>\n",_("Period"),period.html); fprintf(fp_ou,"<tr><td class=\"header_c\" colspan=\"2\">%s:&nbsp;%s</td>< /tr>\n",_("Period"),period.html);
fprintf(fp_ou,"<tr><th class=\"header_c\" colspan=\"2\">%s:&nbsp;%s</th>< /tr>\n",_("User"),uinfo->label); fprintf(fp_ou,"<tr><th class=\"header_c\" colspan=\"2\">%s:&nbsp;%s</th>< /tr>\n",_("User"),uinfo->label);
close_html_header(fp_ou); close_html_header(fp_ou);
dayidx=0; dayidx=0;
for (i=0 ; i<ndaylist ; i++) { for (i=0 ; i<ndaylist ; i++) {
daynum=daylist[i]; daynum=daylist[i];
for (j=dayidx ; j>0 && daynum<daylist[daysort[j-1]] ; j--) daysor t[j]=daysort[j-1]; for (j=dayidx ; j>0 && daynum<daylist[daysort[j-1]] ; j--) daysor t[j]=daysort[j-1];
daysort[j]=i; daysort[j]=i;
dayidx++; dayidx++;
} }
if((datetimeby & DATETIME_BYTE)!=0) { if ((datetimeby & DATETIME_BYTE)!=0) {
label=_("BYTES"); label=_("BYTES");
fputs("<table class=\"report\" cellpadding=\"0\" cellspacing=\"2\ ">\n", fp_ou); fputs("<table class=\"report\" cellpadding=\"0\" cellspacing=\"2\ ">\n", fp_ou);
fputs("<tr><th class=\"header_c\"></th>",fp_ou); fputs("<tr><th class=\"header_c\"></th>",fp_ou);
for( i = 0; i < hours.len; i++ ) { for (i=0 ; i<24 ; i++)
/* TRANSLATORS: It is an hour in the hourly report */ {
sprintf(data,_("%02dH"),hours.list[ i ]); if (hours[i])
fprintf(fp_ou, "<td class=\"header_c\">%s<br>%s</td>\n", {
data, label ); /* TRANSLATORS: It is an hour in the hourly repor
t */
sprintf(data,_("%02dH"),i);
fprintf(fp_ou, "<td class=\"header_c\">%s<br>%s</
td>\n", data, label );
}
} }
fprintf(fp_ou, "<td class=\"header_c\">%s<br>%s</td></tr>\n", _(" TOTAL"), label ); fprintf(fp_ou, "<td class=\"header_c\">%s<br>%s</td></tr>\n", _(" TOTAL"), label );
memset(tttime,0,sizeof(tttime)); memset(tttime,0,sizeof(tttime));
for (dayidx=0 ; dayidx<ndaylist ; dayidx++) { for (dayidx=0 ; dayidx<ndaylist ; dayidx++) {
daynum=daysort[dayidx]; daynum=daysort[dayidx];
day=daylist[daynum]%100; day=daylist[daynum]%100;
month=(daylist[daynum]/100)%100; month=(daylist[daynum]/100)%100;
year=daylist[daynum]/10000; year=daylist[daynum]/10000;
computedate(year,month,day,&t); computedate(year,month,day,&t);
strftime(data,sizeof(data),"%x",&t); strftime(data,sizeof(data),"%x",&t);
fprintf(fp_ou, "<tr><td class=\"data\">%s</td>\n", data ) ; fprintf(fp_ou, "<tr><td class=\"data\">%s</td>\n", data ) ;
tt=0; tt=0;
for( i = 0; i < hours.len; i++ ) { for (i=0 ; i<24 ; i++)
ihour=hours.list[i]; {
if (tbytes[daynum*24+ihour]>0) { if (!hours[i]) continue;
ihour=i;
if (tbytes[daynum*24+ihour]>0)
{
fprintf(fp_ou, "<td class=\"data\">%s</td >\n",fixnum(tbytes[daynum*24+ihour],1)); fprintf(fp_ou, "<td class=\"data\">%s</td >\n",fixnum(tbytes[daynum*24+ihour],1));
tt+=tbytes[daynum*24+ihour]; tt+=tbytes[daynum*24+ihour];
tttime[ihour]+=tbytes[daynum*24+ihour]; tttime[ihour]+=tbytes[daynum*24+ihour];
} else }
else
fputs("<td class=\"data\"></td>\n",fp_ou) ; fputs("<td class=\"data\"></td>\n",fp_ou) ;
} }
fprintf(fp_ou, "<td class=\"data\">%s</td></tr>\n",fixnum (tt,1)); fprintf(fp_ou, "<td class=\"data\">%s</td></tr>\n",fixnum (tt,1));
} }
fprintf(fp_ou, "<tr><td class=\"header_l\">%s</td>\n", _("TOTAL") ); fprintf(fp_ou, "<tr><td class=\"header_l\">%s</td>\n", _("TOTAL") );
tt=0; tt=0;
for( i = 0; i < hours.len; i++ ) { for (i=0 ; i<24 ; i++)
if (tttime[i]>0) { {
if (!hours[i]) continue;
if (tttime[i]>0)
{
fprintf(fp_ou, "<td class=\"header_r\">%s</td>\n" ,fixnum(tttime[i],1)); fprintf(fp_ou, "<td class=\"header_r\">%s</td>\n" ,fixnum(tttime[i],1));
tt+=tttime[i]; tt+=tttime[i];
} else }
else
fputs("<td class=\"header_r\"></td>\n",fp_ou); fputs("<td class=\"header_r\"></td>\n",fp_ou);
} }
fprintf(fp_ou, "<td class=\"header_r\">%s</td></tr>\n",fixnum(tt, 1)); fprintf(fp_ou, "<td class=\"header_r\">%s</td></tr>\n",fixnum(tt, 1));
fputs("</table>\n",fp_ou); fputs("</table>\n",fp_ou);
#ifdef ENABLE_DOUBLE_CHECK_DATA #ifdef ENABLE_DOUBLE_CHECK_DATA
if (tt!=uinfo->nbytes) { 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 %"P RIi64" instead of %"PRIi64" in the hourly report of user %s\n"),
(int64_t)tt,(int64_t)uinfo->nbyt es,uinfo->label); (int64_t)tt,(int64_t)uinfo->nbyt es,uinfo->label);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#endif #endif
} }
if((datetimeby & DATETIME_ELAP)!=0) { if ((datetimeby & DATETIME_ELAP)!=0) {
label=_("H:M:S"); label=_("H:M:S");
fputs("<table class=\"report\" cellpadding=\"0\" cellspacing=\"2\ ">\n", fp_ou); fputs("<table class=\"report\" cellpadding=\"0\" cellspacing=\"2\ ">\n", fp_ou);
fputs("<tr><th class=\"header_c\"></th>",fp_ou); fputs("<tr><th class=\"header_c\"></th>",fp_ou);
for( i = 0; i < hours.len; i++ ) { for (i=0 ; i<24 ; i++)
sprintf(data,_("%02dH"),hours.list[ i ]); {
fprintf(fp_ou, "<td class=\"header_c\">%s<br>%s</td>\n", if (hours[i])
data, label ); {
sprintf(data,_("%02dH"),i);
fprintf(fp_ou, "<td class=\"header_c\">%s<br>%s</
td>\n", data, label );
}
} }
fprintf(fp_ou, "<td class=\"header_c\">%s<br>%s</td></tr>\n", _(" TOTAL"), label ); fprintf(fp_ou, "<td class=\"header_c\">%s<br>%s</td></tr>\n", _(" TOTAL"), label );
memset(tttime,0,sizeof(tttime)); memset(tttime,0,sizeof(tttime));
for (dayidx=0 ; dayidx<ndaylist ; dayidx++) { for (dayidx=0 ; dayidx<ndaylist ; dayidx++) {
daynum=daysort[dayidx]; daynum=daysort[dayidx];
day=daylist[daynum]%100; day=daylist[daynum]%100;
month=(daylist[daynum]/100)%100; month=(daylist[daynum]/100)%100;
year=daylist[daynum]/10000; year=daylist[daynum]/10000;
computedate(year,month,day,&t); computedate(year,month,day,&t);
strftime(data,sizeof(data),"%x",&t); strftime(data,sizeof(data),"%x",&t);
fprintf(fp_ou, "<tr><td class=\"data\">%s</td>\n", data ) ; fprintf(fp_ou, "<tr><td class=\"data\">%s</td>\n", data ) ;
tt=0; tt=0;
for( i = 0; i < hours.len; i++ ) { for (i=0 ; i<24 ; i++)
ihour=hours.list[i]; {
if (!hours[i]) continue;
ihour=i;
if (telap[daynum*24+ihour]>0) { if (telap[daynum*24+ihour]>0) {
fprintf(fp_ou, "<td class=\"data\">%s</td >\n",fixtime(telap[daynum*24+ihour])); fprintf(fp_ou, "<td class=\"data\">%s</td >\n",fixtime(telap[daynum*24+ihour]));
tt+=telap[daynum*24+ihour]; tt+=telap[daynum*24+ihour];
tttime[ihour]+=telap[daynum*24+ihour]; tttime[ihour]+=telap[daynum*24+ihour];
} else } else
fputs("<td class=\"data\"></td>\n",fp_ou) ; fputs("<td class=\"data\"></td>\n",fp_ou) ;
} }
fprintf(fp_ou, "<td class=\"data\">%s</td></tr>\n",fixtim e(tt)); fprintf(fp_ou, "<td class=\"data\">%s</td></tr>\n",fixtim e(tt));
} }
fprintf(fp_ou, "<tr><td class=\"header_l\">%s</td>\n", _("TOTAL") ); fprintf(fp_ou, "<tr><td class=\"header_l\">%s</td>\n", _("TOTAL") );
tt=0; tt=0;
for( i = 0; i < hours.len; i++ ) { for (i=0 ; i<24 ; i++)
if (tttime[i]>0) { {
if (!hours[i]) continue;
if (tttime[i]>0)
{
fprintf(fp_ou, "<td class=\"header_r\">%s</td>\n" ,fixtime(tttime[i])); fprintf(fp_ou, "<td class=\"header_r\">%s</td>\n" ,fixtime(tttime[i]));
tt+=tttime[i]; tt+=tttime[i];
} else }
else
fputs("<td class=\"header_r\"></td>\n",fp_ou); fputs("<td class=\"header_r\"></td>\n",fp_ou);
} }
fprintf(fp_ou, "<td class=\"header_r\">%s</td></tr>\n",fixtime(tt )); fprintf(fp_ou, "<td class=\"header_r\">%s</td></tr>\n",fixtime(tt ));
fputs("</table>\n",fp_ou); fputs("</table>\n",fp_ou);
#ifdef ENABLE_DOUBLE_CHECK_DATA #ifdef ENABLE_DOUBLE_CHECK_DATA
if (tt!=uinfo->elap) { if (tt!=uinfo->elap) {
debuga(_("Total elapsed time is %"PRIi64" instead of %"PR Ii64" in the hourly report of user %s\n"), debuga(__FILE__,__LINE__,_("Total elapsed time is %"PRIi6 4" instead of %"PRIi64" in the hourly report of user %s\n"),
(int64_t)tt,(int64_t)uinfo->elap ,uinfo->label); (int64_t)tt,(int64_t)uinfo->elap ,uinfo->label);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#endif #endif
} }
if (write_html_trailer(fp_ou)<0) write_html_trailer(fp_ou);
debuga(_("Write error in file \"%s\"\n"),arqout); if (fclose(fp_ou)==EOF) {
if (fclose(fp_ou)==EOF) debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),arqout,
debuga(_("Failed to close file \"%s\": %s\n"),arqout,strerror(err strerror(errno));
no)); exit(EXIT_FAILURE);
}
return; return;
} }
 End of changes. 26 change blocks. 
47 lines changed or deleted 77 lines changed or added

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