]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - siteuser.c
Rename configure.in as configure.ac
[thirdparty/sarg.git] / siteuser.c
index 58d195fef96448988db014e79c0c23f59da81e75..31cecc493242167cf63f7397f66d7d97dd8359d2 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * SARG Squid Analysis Report Generator      http://sarg.sourceforge.net
- *                                                            1998, 2012
+ *                                                            1998, 2015
  *
  * SARG donations:
  *      please look at http://sarg.sourceforge.net/donations.php
@@ -33,7 +33,7 @@ void siteuser(void)
 
        char *buf;
        char *ourl;
-       char csort[255];
+       char csort[4096];
        char general[MAXLEN];
        char general2[MAXLEN];
        char sites[MAXLEN];
@@ -49,10 +49,12 @@ void siteuser(void)
        struct userinfostruct *uinfo;
 
        if(Privacy) {
-               if (debugz) debugaz(_("Sites and users report not generated because privacy option is on\n"));
+               if (debugz>=LogLevel_Process) debugaz(__FILE__,__LINE__,_("Sites & users report not generated because privacy option is on\n"));
                return;
        }
 
+       if (debugz>=LogLevel_Process)
+               debuga(__FILE__,__LINE__,_("Creating report to list who visisted what site...\n"));
        nsitesusers = 0;
        sprintf(general,"%s/sarg-general",outdirname);
        sprintf(sites,"%s/sarg-sites",outdirname);
@@ -60,24 +62,24 @@ void siteuser(void)
        sprintf(report,"%s/siteuser.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(_("(siteuser) Cannot open log file %s\n"),general2);
-               debuga(_("sort command: %s\n"),csort);
+               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),general2,strerror(errno));
+               debuga(__FILE__,__LINE__,_("sort command: %s\n"),csort);
                exit(EXIT_FAILURE);
        }
 
        if((fp_ou=fopen(report,"w"))==NULL) {
-               debuga(_("(siteuser) Cannot open log file %s\n"),report);
+               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),report,strerror(errno));
                exit(EXIT_FAILURE);
        }
 
@@ -107,7 +109,7 @@ void siteuser(void)
        topuser_link=((ReportType & REPORT_TYPE_USERS_SITES) != 0 && !indexonly);
 
        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);
        }
 
@@ -116,7 +118,7 @@ void siteuser(void)
                if(item.total) continue;
                uinfo=userinfo_find_from_id(item.user);
                if (!uinfo) {
-                       debuga(_("Unknown user ID %s in file %s\n"),item.user,general2);
+                       debuga(__FILE__,__LINE__,_("Unknown user ID %s in file \"%s\"\n"),item.user,general2);
                        exit(EXIT_FAILURE);
                }
 
@@ -136,7 +138,7 @@ void siteuser(void)
                                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);
                                }
                        }
@@ -173,7 +175,10 @@ void siteuser(void)
                }
 
        }
-       fclose(fp_in);
+       if (fclose(fp_in)==EOF) {
+               debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),general2,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
        longline_destroy(&line);
 
        if(regs>0) {
@@ -182,15 +187,16 @@ void siteuser(void)
        if (ourl) free(ourl);
 
        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);
        }
 
        fputs("</table></div>\n",fp_ou);
-       if (write_html_trailer(fp_ou)<0)
-               debuga(_("Write error in file %s\n"),report);
-       if (fclose(fp_ou)==EOF)
-               debuga(_("Failed to close file %s - %s\n"),report,strerror(errno));
+       write_html_trailer(fp_ou);
+       if (fclose(fp_ou)==EOF) {
+               debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),report,strerror(errno));
+               exit(EXIT_FAILURE);
+       }
 
        return;
 }