/*
* SARG Squid Analysis Report Generator http://sarg.sourceforge.net
- * 1998, 2013
+ * 1998, 2015
*
* SARG donations:
* please look at http://sarg.sourceforge.net/donations.php
void topsites(void)
{
- FILE *fp_in, *fp_ou;
+ FileObject *fp_in;
+ FILE *fp_ou;
char *buf;
char *url;
struct generalitemstruct item;
if(Privacy) {
- if (debugz>=LogLevel_Process) debugaz(_("Top sites report not produced because privacy option is on\n"));
+ if (debugz>=LogLevel_Process) debugaz(__FILE__,__LINE__,_("Top sites report not produced because privacy option is on\n"));
return;
}
if (debugz>=LogLevel_Process)
- debuga(_("Creating top sites report...\n"));
+ debuga(__FILE__,__LINE__,_("Creating top sites report...\n"));
sprintf(general,"%s/sarg-general",outdirname);
sprintf(sites,"%s/sarg-sites",outdirname);
sprintf(report,"%s/topsites.html",outdirname);
if (snprintf(csort,sizeof(csort),"sort -t \"\t\" -k 4,4 -k 1,1 -o \"%s\" \"%s\"",general2,general)>=sizeof(csort)) {
- debuga(_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),general,general2);
+ debuga(__FILE__,__LINE__,_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),general,general2);
exit(EXIT_FAILURE);
}
cstatus=system(csort);
if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
- debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
- debuga(_("sort command: %s\n"),csort);
+ debuga(__FILE__,__LINE__,_("sort command return status %d\n"),WEXITSTATUS(cstatus));
+ debuga(__FILE__,__LINE__,_("sort command: %s\n"),csort);
exit(EXIT_FAILURE);
}
- if((fp_in=fopen(general2,"r"))==NULL) {
- debuga(_("Cannot open file \"%s\": %s\n"),general2,strerror(errno));
- debuga(_("sort command: %s\n"),csort);
+ if((fp_in=FileObject_Open(general2))==NULL) {
+ debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),general2,FileObject_GetLastOpenError());
+ debuga(__FILE__,__LINE__,_("sort command: %s\n"),csort);
exit(EXIT_FAILURE);
}
if((fp_ou=fopen(general3,"w"))==NULL) {
- debuga(_("Cannot open file \"%s\": %s\n"),general3,strerror(errno));
+ debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),general3,strerror(errno));
exit(EXIT_FAILURE);
}
if ((line=longline_create())==NULL) {
- debuga(_("Not enough memory to read file %s\n"),general2);
+ debuga(__FILE__,__LINE__,_("Not enough memory to read file \"%s\"\n"),general2);
exit(EXIT_FAILURE);
}
ourl_size=url_len+1;
ourl=realloc(ourl,ourl_size);
if (!ourl) {
- debuga(_("Not enough memory to store the url\n"));
+ debuga(__FILE__,__LINE__,_("Not enough memory to store the url\n"));
exit(EXIT_FAILURE);
}
}
ourl_size=url_len+1;
ourl=realloc(ourl,ourl_size);
if (!ourl) {
- debuga(_("Not enough memory to store the url\n"));
+ debuga(__FILE__,__LINE__,_("Not enough memory to store the url\n"));
exit(EXIT_FAILURE);
}
}
ttntime+=item.nelap;
#endif
}
- fclose(fp_in);
+ if (FileObject_Close(fp_in)) {
+ debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),general2,FileObject_GetLastCloseError());
+ exit(EXIT_FAILURE);
+ }
longline_destroy(&line);
if (ourl) {
}
if (fclose(fp_ou)==EOF) {
- debuga(_("Write error in \"%s\": %s\n"),general3,strerror(errno));
+ debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),general3,strerror(errno));
exit(EXIT_FAILURE);
}
#ifdef ENABLE_DOUBLE_CHECK_DATA
if (ttnacc!=globstat.nacc || ttnbytes!=globstat.nbytes || ttntime!=globstat.elap) {
- debuga(_("Total statistics mismatch when reading %s to produce the top sites\n"),general2);
+ debuga(__FILE__,__LINE__,_("Total statistics mismatch when reading \"%s\" to produce the top sites\n"),general2);
exit(EXIT_FAILURE);
}
#endif
if (!KeepTempLog && unlink(general2)) {
- debuga(_("Cannot delete \"%s\": %s\n"),general2,strerror(errno));
+ debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),general2,strerror(errno));
exit(EXIT_FAILURE);
}
}
if (snprintf(csort,sizeof(csort),"sort -t \"\t\" %s -n %s -o \"%s\" \"%s\"",sortt,sortf,sites,general3)>=sizeof(csort)) {
- debuga(_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),general3,sites);
+ debuga(__FILE__,__LINE__,_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),general3,sites);
exit(EXIT_FAILURE);
}
cstatus=system(csort);
if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
- debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus));
- debuga(_("sort command: %s\n"),csort);
+ debuga(__FILE__,__LINE__,_("sort command return status %d\n"),WEXITSTATUS(cstatus));
+ debuga(__FILE__,__LINE__,_("sort command: %s\n"),csort);
exit(EXIT_FAILURE);
}
- if((fp_in=fopen(sites,"r"))==NULL) {
- debuga(_("Cannot open file \"%s\": %s\n"),sites,strerror(errno));
- debuga(_("sort command: %s\n"),csort);
+ if((fp_in=FileObject_Open(sites))==NULL) {
+ debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),sites,FileObject_GetLastOpenError());
+ debuga(__FILE__,__LINE__,_("sort command: %s\n"),csort);
exit(EXIT_FAILURE);
}
if (!KeepTempLog && unlink(general3)) {
- debuga(_("Cannot delete \"%s\": %s\n"),general3,strerror(errno));
+ debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),general3,strerror(errno));
exit(EXIT_FAILURE);
}
if((fp_ou=fopen(report,"w"))==NULL) {
- debuga(_("Cannot open file \"%s\": %s\n"),report,strerror(errno));
+ debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),report,strerror(errno));
exit(EXIT_FAILURE);
}
ntopsites = 0;
if ((line=longline_create())==NULL) {
- debuga(_("Not enough memory to read file %s\n"),sites);
+ debuga(__FILE__,__LINE__,_("Not enough memory to read file \"%s\"\n"),sites);
exit(EXIT_FAILURE);
}
while(regs<TopSitesNum && (buf=longline_read(fp_in,line))!=NULL) {
getword_start(&gwarea,buf);
if (getword_atoll(&nacc,&gwarea,'\t')<0) {
- debuga(_("Maybe you have a broken record or garbage in your %s file\n"),sites);
+ debuga(__FILE__,__LINE__,_("Invalid record in file \"%s\"\n"),sites);
exit(EXIT_FAILURE);
}
if (nacc == 0) continue;
if (getword_atoll(&nbytes,&gwarea,'\t')<0 || getword_atoll(&ntime,&gwarea,'\t')<0) {
- debuga(_("Maybe you have a broken record or garbage in your %s file\n"),sites);
+ debuga(__FILE__,__LINE__,_("Invalid record in file \"%s\"\n"),sites);
exit(EXIT_FAILURE);
}
if (getword_atoi(&nusers,&gwarea,'\t')<0) {
- debuga(_("The number of users is invalid in file %s\n"),sites);
+ debuga(__FILE__,__LINE__,_("Invalid number of users in file \"%s\"\n"),sites);
exit(EXIT_FAILURE);
}
if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
- debuga(_("The url is invalid in file %s\n"),sites);
+ debuga(__FILE__,__LINE__,_("Invalid url in file \"%s\"\n"),sites);
exit(EXIT_FAILURE);
}
if (SortTableJs[0]) fprintf(fp_ou," sorttable_customkey=\"%d\"",nusers);
fprintf(fp_ou,">%s</td></tr>\n",fixnum(nusers,1));
}
- fclose(fp_in);
+ if (FileObject_Close(fp_in)) {
+ debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),sites,FileObject_GetLastCloseError());
+ exit(EXIT_FAILURE);
+ }
longline_destroy(&line);
fputs("</table></div>\n",fp_ou);
write_html_trailer(fp_ou);
if (fclose(fp_ou)==EOF) {
- debuga(_("Write error in \"%s\": %s\n"),report,strerror(errno));
+ debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),report,strerror(errno));
exit(EXIT_FAILURE);
}