"Fossies" - the Fresh Open Source Software Archive  

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

About: SARG ia a Squid Analysis Report Generator.

totday.c  (sarg-2.3.11):totday.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 53 skipping to change at line 53
\return The object to pass to other functions in this module. \return The object to pass to other functions in this module.
The object must be freed with a call to day_cleanup(). The object must be freed with a call to day_cleanup().
*/ */
DayObject day_prepare(void) DayObject day_prepare(void)
{ {
DayObject ddata; DayObject ddata;
ddata=(DayObject)malloc(sizeof(*ddata)); ddata=(DayObject)malloc(sizeof(*ddata));
if (!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); exit(EXIT_FAILURE);
} }
return(ddata); return(ddata);
} }
/*! /*!
Free the memory allocated by day_prepare(). Free the memory allocated by day_prepare().
\param ddata The object returned by day_prepare(). \param ddata The object returned by day_prepare().
skipping to change at line 103 skipping to change at line 103
\param bytes The number of bytes transfered by the user. \param bytes The number of bytes transfered by the user.
*/ */
void day_addpoint(DayObject ddata,const char *date, const char *time, long long int elap, long long int bytes) void day_addpoint(DayObject ddata,const char *date, const char *time, long long int elap, long long int bytes)
{ {
int hour; int hour;
int day,month,year; int day,month,year;
int daynum; int daynum;
int dayidx; int dayidx;
int i; int i;
if (!ddata) return;
if (sscanf(date,"%d/%d/%d",&day,&month,&year)!=3) { 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 st atistics\n"),date);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (day<1 || day>31 || month<1 || month>12 || year>9999) { if (day<1 || day>31 || month<1 || month>12 || year>9999) {
debuga(_("Invalid date component in \"%s\" for the hourly statist ics\n"),date); debuga(__FILE__,__LINE__,_("Invalid date component in \"%s\" for the hourly statistics\n"),date);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
hour=atoi(time); hour=atoi(time);
if (hour<0 || hour>=24) { if (hour<0 || hour>=24) {
debuga(_("Invalid hour %d for the hourly statistics\n"),hour); debuga(__FILE__,__LINE__,_("Invalid hour %d for the hourly statis tics\n"),hour);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
daynum=(year*10000)+(month*100)+day; daynum=(year*10000)+(month*100)+day;
for (dayidx=ddata->ndaylist-1 ; dayidx>=0 && daynum!=ddata->daylist[dayid x] ; dayidx--); for (dayidx=ddata->ndaylist-1 ; dayidx>=0 && daynum!=ddata->daylist[dayid x] ; dayidx--);
if (dayidx<0) { if (dayidx<0) {
dayidx=ddata->ndaylist++; dayidx=ddata->ndaylist++;
if (dayidx>=sizeof(ddata->daylist)/sizeof(*ddata->daylist)) { if (dayidx>=sizeof(ddata->daylist)/sizeof(*ddata->daylist)) {
debuga(_("Too many different dates for the hourly statist ics\n")); debuga(__FILE__,__LINE__,_("Too many different dates for the hourly statistics\n"));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
ddata->daylist[dayidx]=daynum; ddata->daylist[dayidx]=daynum;
} }
i=dayidx*24+hour; i=dayidx*24+hour;
if (i>=ddata->maxindex) ddata->maxindex=i+1; if (i>=ddata->maxindex) ddata->maxindex=i+1;
ddata->bytes[i]+=bytes; ddata->bytes[i]+=bytes;
ddata->elap[i]+=elap; ddata->elap[i]+=elap;
} }
skipping to change at line 148 skipping to change at line 149
*/ */
void day_totalize(DayObject ddata,const char *tmp, const struct userinfostruct * uinfo) void day_totalize(DayObject ddata,const char *tmp, const struct userinfostruct * uinfo)
{ {
FILE *fp_ou; FILE *fp_ou;
int hour; int hour;
int day,month,year; int day,month,year;
int i; int i;
int daynum; int daynum;
int dayidx; int dayidx;
char arqout[2048]; char arqout[2048];
#ifdef ENABLE_DOUBLE_CHECK_DATA
long long int tt=0;
#endif
if (datetimeby==0) return; if (datetimeby==0) return;
if (!ddata) return; if (!ddata) return;
if (snprintf(arqout,sizeof(arqout),"%s/%s.day",tmp,uinfo->filename)>=size of(arqout)) { if (snprintf(arqout,sizeof(arqout),"%s/%s.day",tmp,uinfo->filename)>=size of(arqout)) {
debuga(_("Path too long: ")); debuga(__FILE__,__LINE__,_("Path too long: "));
debuga_more("%s/%s%s\n",tmp,uinfo->filename,".day"); debuga_more("%s/%s%s\n",tmp,uinfo->filename,".day");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if((fp_ou=fopen(arqout,"w"))==NULL) { if ((fp_ou=fopen(arqout,"w"))==NULL) {
debugapos("totday",_("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);
} }
for (i=0 ; i<ddata->maxindex ; i++) { for (i=0 ; i<ddata->maxindex ; i++) {
if (ddata->bytes[i]==0 && ddata->elap[i]==0) continue; if (ddata->bytes[i]==0 && ddata->elap[i]==0) continue;
dayidx=i/24; dayidx=i/24;
if (dayidx>=sizeof(ddata->daylist)/sizeof(*ddata->daylist)) { if (dayidx>=sizeof(ddata->daylist)/sizeof(*ddata->daylist)) {
debuga(_("Invalid day index found in the hourly statistic s\n")); debuga(__FILE__,__LINE__,_("Invalid day index found in th e hourly statistics\n"));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
hour=i%24; hour=i%24;
daynum=ddata->daylist[dayidx]; daynum=ddata->daylist[dayidx];
day=daynum%100; day=daynum%100;
month=(daynum/100)%100; month=(daynum/100)%100;
year=daynum/10000; year=daynum/10000;
fprintf(fp_ou,"%d/%d/%d\t%d",day,month,year,hour); fprintf(fp_ou,"%d/%d/%d\t%d",day,month,year,hour);
if ((datetimeby & DATETIME_BYTE)!=0) fprintf(fp_ou,"\t%"PRIu64"", (uint64_t)ddata->bytes[i]); if ((datetimeby & DATETIME_BYTE)!=0) fprintf(fp_ou,"\t%"PRIu64"", (uint64_t)ddata->bytes[i]);
if ((datetimeby & DATETIME_ELAP)!=0) fprintf(fp_ou,"\t%"PRIu64"", (uint64_t)ddata->elap[i]); if ((datetimeby & DATETIME_ELAP)!=0) fprintf(fp_ou,"\t%"PRIu64"", (uint64_t)ddata->elap[i]);
fputs("\n",fp_ou); fputs("\n",fp_ou);
#ifdef ENABLE_DOUBLE_CHECK_DATA
tt+=ddata->bytes[i];
#endif
} }
if (fclose(fp_ou)==EOF) { if (fclose(fp_ou)==EOF) {
debuga(_("Failed to close file \"%s\": %s\n"),arqout,strerror(err no)); debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),arqout, strerror(errno));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#ifdef ENABLE_DOUBLE_CHECK_DATA return;
if (tt!=uinfo->nbytes) { }
debuga(_("Total downloaded bytes is %"PRIi64" instead of %"PRIi64
" in the hourly report of user %s\n"), /*!
(int64_t)tt,(int64_t)uinfo->nbytes,uinfo Delete the temporary file generated by day_totalize().
->label);
\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)>=size
of(arqout)) {
debuga(__FILE__,__LINE__,_("Path too long: "));
debuga_more("%s/%s%s\n",tmp,uinfo->filename,".day");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
#endif
return; if (unlink(arqout))
debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),arqout,s
trerror(errno));
} }
 End of changes. 15 change blocks. 
26 lines changed or deleted 35 lines changed or added

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