]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - siteuser.c
Add support to decompress xz files
[thirdparty/sarg.git] / siteuser.c
index 1904afe192cf7718119f00cce2c038dab1e58456..a582b09277c4d8c8167343c7a7c725de304d51b3 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
 
 void siteuser(void)
 {
-       FILE *fp_in, *fp_ou;
+       FileObject *fp_in;
+       FILE *fp_ou;
 
        char *buf;
        char *ourl;
-       char csort[255];
+       char csort[4096];
        char general[MAXLEN];
        char general2[MAXLEN];
        char sites[MAXLEN];
@@ -49,10 +50,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 +63,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);
+       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(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);
        }
 
@@ -97,6 +100,7 @@ void siteuser(void)
                fprintf(fp_ou,"<th class=\"header_l\">%s</th>",_("BYTES"));
        fputs("<th class=\"header_l",fp_ou);
        if (SortTableJs[0]) fputs(" sorttable_alpha",fp_ou);
+       /* TRANSLATORS: This is a column header showing the users who visited each site. */
        fprintf(fp_ou,"\">%s</th></tr></thead>\n",_("USERS"));
 
        ourl=NULL;
@@ -106,7 +110,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);
        }
 
@@ -115,7 +119,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);
                }
 
@@ -135,12 +139,12 @@ 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);
                                }
                        }
                        strcpy(ourl,item.url);
-                       
+
                        if(BlockIt[0]!='\0' && ourl[0]!=ALIAS_PREFIX) {
                                fprintf(fp_ou,"<a href=\"%s%s?url=",wwwDocumentRoot,BlockIt);
                                output_html_url(fp_ou,ourl);
@@ -172,7 +176,10 @@ void siteuser(void)
                }
 
        }
-       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(regs>0) {
@@ -181,15 +188,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;
 }