]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - siteuser.c
Add support to decompress xz files
[thirdparty/sarg.git] / siteuser.c
index 3dde6e3c436a655d4a5b1c1e4abe5d3fda12f4aa..a582b09277c4d8c8167343c7a7c725de304d51b3 100644 (file)
@@ -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
@@ -29,7 +29,8 @@
 
 void siteuser(void)
 {
-       FILE *fp_in, *fp_ou;
+       FileObject *fp_in;
+       FILE *fp_ou;
 
        char *buf;
        char *ourl;
@@ -49,12 +50,12 @@ void siteuser(void)
        struct userinfostruct *uinfo;
 
        if(Privacy) {
-               if (debugz>=LogLevel_Process) 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(_("Creating report to list who visisted what site...\n"));
+               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);
@@ -62,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(_("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(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);
        }
 
@@ -109,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);
        }
 
@@ -118,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);
                }
 
@@ -138,7 +139,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);
                                }
                        }
@@ -175,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) {
@@ -184,15 +188,14 @@ 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);
+       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);
        }