]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - topuser.c
Rename configure.in as configure.ac
[thirdparty/sarg.git] / topuser.c
index 8266cf5108234f0c7ebfec895fca2dd33f4b1de8..f272fa529afa9528fb03d8e42eeae2d46ba13e80 100644 (file)
--- a/topuser.c
+++ b/topuser.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
@@ -43,12 +43,12 @@ static void set_total_users(int totuser)
 
        snprintf(tusr,sizeof(tusr),"%s/sarg-users",outdirname);
        if((fp_ou=fopen(tusr,"w"))==NULL) {
-               debuga(_("(topuser) Cannot open file %s: %s\n"),tusr,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),tusr,strerror(errno));
                exit(EXIT_FAILURE);
        }
        fprintf(fp_ou,"%d\n",totuser);
        if (fclose(fp_ou)==EOF) {
-               debuga(_("Write error in %s: %s\n"),tusr,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),tusr,strerror(errno));
                exit(EXIT_FAILURE);
        }
        globstat.totuser=totuser;
@@ -84,16 +84,18 @@ void topuser(void)
        struct generalitemstruct item;
        struct userinfostruct *uinfo;
 
+       if (debugz>=LogLevel_Process)
+               debuga(__FILE__,__LINE__,_("Creating top users report...\n"));
        ntopuser = 0;
        snprintf(wger,sizeof(wger),"%s/sarg-general",outdirname);
        if((fp_in=fopen(wger,"r"))==NULL) {
-               debuga(_("(topuser) Cannot open file %s: %s\n"),wger,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),wger,strerror(errno));
                exit(EXIT_FAILURE);
        }
 
        snprintf(top2,sizeof(top2),"%s/top.tmp",outdirname);
        if((fp_top2=fopen(top2,"w"))==NULL) {
-               debuga(_("(topuser) Cannot open file %s: %s\n"),top2,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),top2,strerror(errno));
                exit(EXIT_FAILURE);
        }
 
@@ -101,7 +103,7 @@ void topuser(void)
        totuser=0;
 
        if ((line=longline_create())==NULL) {
-               debuga(_("Not enough memory to read the file %s\n"),wger);
+               debuga(__FILE__,__LINE__,_("Not enough memory to read file \"%s\"\n"),wger);
                exit(EXIT_FAILURE);
        }
 
@@ -138,7 +140,10 @@ void topuser(void)
                tnincache+=item.incache;
                tnoucache+=item.oucache;
        }
-       fclose(fp_in);
+       if (fclose(fp_in)==EOF) {
+               debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),wger,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
        longline_destroy(&line);
 
        if (olduser[0] != '\0') {
@@ -155,14 +160,14 @@ void topuser(void)
                ttnoucache+=tnoucache;
        }
        if (fclose(fp_top2)==EOF) {
-               debuga(_("Write error in %s: %s\n"),top2,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),top2,strerror(errno));
                exit(EXIT_FAILURE);
        }
 
 #ifdef ENABLE_DOUBLE_CHECK_DATA
        if (ttnacc!=globstat.nacc || ttnbytes!=globstat.nbytes || ttnelap!=globstat.elap ||
            ttnincache!=globstat.incache || ttnoucache!=globstat.oucache) {
-               debuga(_("Total statistics mismatch when reading %s to produce the top users\n"),wger);
+               debuga(__FILE__,__LINE__,_("Total statistics mismatch when reading \"%s\" to produce the top users\n"),wger);
                exit(EXIT_FAILURE);
        }
 #endif
@@ -192,29 +197,29 @@ void topuser(void)
 
        snprintf(top1,sizeof(top1),"%s/top",outdirname);
        if (snprintf(csort,sizeof(csort),"sort -T \"%s\" -t \"\t\" %s %s -o \"%s\" \"%s\"", tmp, order, sfield, top1, top2)>=sizeof(csort)) {
-               debuga(_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),top2,top1);
+               debuga(__FILE__,__LINE__,_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),top2,top1);
                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_top1=fopen(top1,"r"))==NULL) {
-               debuga(_("(topuser) Cannot open file %s: %s\n"),top1,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),top1,strerror(errno));
                exit(EXIT_FAILURE);
        }
 
        if (!KeepTempLog && unlink(top2)) {
-               debuga(_("Cannot delete \"%s\": %s\n"),top2,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),top2,strerror(errno));
                exit(EXIT_FAILURE);
        }
 
        snprintf(top3,sizeof(top3),"%s/"INDEX_HTML_FILE,outdirname);
        if((fp_top3=fopen(top3,"w"))==NULL) {
-               debuga(_("(topuser) Cannot open file %s: %s\n"),top3,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),top3,strerror(errno));
                exit(EXIT_FAILURE);
        }
 
@@ -253,10 +258,10 @@ void topuser(void)
        if ((ReportType & REPORT_TYPE_TOPUSERS) == 0) {
                fputs("</body>\n</html>\n",fp_top3);
                if (fclose (fp_top3)==EOF) {
-                       debuga(_("Write error in %s: %s\n"),top3,strerror(errno));
+                       debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),top3,strerror(errno));
                        exit(EXIT_FAILURE);
                }
-               if (debugz>=LogLevel_Process) debugaz(_("No top users report because it is not configured in report_type\n"));
+               if (debugz>=LogLevel_Process) debugaz(__FILE__,__LINE__,_("No top users report because it is not configured in report_type\n"));
                return;
        }
 
@@ -304,34 +309,34 @@ void topuser(void)
        ntopuser = 0;
 
        if ((line=longline_create())==NULL) {
-               debuga(_("Not enough memory to read the downloaded files\n"));
+               debuga(__FILE__,__LINE__,_("Not enough memory to read file \"%s\"\n"),top1);
                exit(EXIT_FAILURE);
        }
 
        while((warea=longline_read(fp_top1,line))!=NULL) {
                getword_start(&gwarea,warea);
                if (getword(user,sizeof(user),&gwarea,'\t')<0) {
-                       debuga(_("There is a broken user in file %s\n"),top1);
+                       debuga(__FILE__,__LINE__,_("Invalid user in file \"%s\"\n"),top1);
                        exit(EXIT_FAILURE);
                }
                if (getword_atoll(&nbytes,&gwarea,'\t')<0) {
-                       debuga(_("There is a broken number of bytes in file %s\n"),top1);
+                       debuga(__FILE__,__LINE__,_("Invalid number of bytes in file \"%s\"\n"),top1);
                        exit(EXIT_FAILURE);
                }
                if (getword_atoll(&nacc,&gwarea,'\t')<0) {
-                       debuga(_("There is a broken number of access in file %s\n"),top1);
+                       debuga(__FILE__,__LINE__,_("Invalid number of accesses in file \"%s\"\n"),top1);
                        exit(EXIT_FAILURE);
                }
                if (getword_atoll(&elap,&gwarea,'\t')<0) {
-                       debuga(_("There is a broken elpased time in file %s\n"),top1);
+                       debuga(__FILE__,__LINE__,_("Invalid elapsed time in file \"%s\"\n"),top1);
                        exit(EXIT_FAILURE);
                }
                if (getword_atoll(&incac,&gwarea,'\t')<0) {
-                       debuga(_("There is a broken in-cache size in file %s\n"),top1);
+                       debuga(__FILE__,__LINE__,_("Invalid in-cache size in file \"%s\"\n"),top1);
                        exit(EXIT_FAILURE);
                }
                if (getword_atoll(&oucac,&gwarea,'\n')<0) {
-                       debuga(_("There is a broken out-of-cache size in file %s\n"),top1);
+                       debuga(__FILE__,__LINE__,_("Invalid out-of-cache size in file \"%s\"\n"),top1);
                        exit(EXIT_FAILURE);
                }
                if(nacc < 1)
@@ -343,7 +348,7 @@ void topuser(void)
 
                uinfo=userinfo_find_from_id(user);
                if (!uinfo) {
-                       debuga(_("Unknown user ID %s in file %s\n"),user,top1);
+                       debuga(__FILE__,__LINE__,_("Unknown user ID %s in file \"%s\"\n"),user,top1);
                        exit(EXIT_FAILURE);
                }
                uinfo->topuser=1;
@@ -398,7 +403,7 @@ void topuser(void)
                        fprintf(fp_top3,"<td class=\"data\">%3.2lf%%</td><td class=\"data\">%3.2lf%%</td>",inperc,ouperc);
 #ifdef ENABLE_DOUBLE_CHECK_DATA
                        if ((inperc!=0. || ouperc!=0.) && fabs(inperc+ouperc-100.)>=0.01) {
-                               debuga(_("The total of the in-cache and cache-miss is not 100%% at position %d (user %s)\n"),posicao,uinfo->label);
+                               debuga(__FILE__,__LINE__,_("The total of the in-cache and cache-miss is not 100%% at position %d (user %s)\n"),posicao,uinfo->label);
                        }
 #endif
                }
@@ -421,9 +426,12 @@ void topuser(void)
 
                topcount++;
        }
-       fclose(fp_top1);
+       if (fclose(fp_top1)==EOF) {
+               debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),top1,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
        if (!KeepTempLog && unlink(top1)) {
-               debuga(_("Cannot delete \"%s\": %s\n"),top1,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),top1,strerror(errno));
                exit(EXIT_FAILURE);
        }
        longline_destroy(&line);
@@ -452,7 +460,7 @@ void topuser(void)
                        fprintf(fp_top3,"<th class=\"header_r\">%3.2lf%%</th><th class=\"header_r\">%3.2lf%%</th>",inperc,ouperc);
 #ifdef ENABLE_DOUBLE_CHECK_DATA
                        if (fabs(inperc+ouperc-100.)>=0.01) {
-                               debuga(_("The total of the in-cache and cache-miss is not 100%%\n"));
+                               debuga(__FILE__,__LINE__,_("The total of the in-cache and cache-miss is not 100%%\n"));
                        }
 #endif
                }
@@ -494,10 +502,9 @@ void topuser(void)
        }
 
        fputs("</table></div>\n",fp_top3);
-       if (write_html_trailer(fp_top3)<0)
-               debuga(_("Write error in top user list %s\n"),top3);
+       write_html_trailer(fp_top3);
        if (fclose(fp_top3)==EOF) {
-               debuga(_("Write error in %s: %s\n"),top3,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),top3,strerror(errno));
                exit(EXIT_FAILURE);
        }