]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - topuser.c
Read compressed useragent logs
[thirdparty/sarg.git] / topuser.c
index f272fa529afa9528fb03d8e42eeae2d46ba13e80..42a5f4976cb36ed87fee84f268831967b9cd00d6 100644 (file)
--- a/topuser.c
+++ b/topuser.c
 
 #include "include/conf.h"
 #include "include/defs.h"
+#include "include/filelist.h"
 
 extern struct globalstatstruct globstat;
 extern bool smartfilter;
+extern FileListObject UserAgentLog;
 
 /*!
 Save the total number of users. The number is written in sarg-users and set
@@ -56,7 +58,9 @@ static void set_total_users(int totuser)
 
 void topuser(void)
 {
-       FILE *fp_in = NULL, *fp_top1 = NULL, *fp_top2 = NULL, *fp_top3 = NULL;
+       FileObject *fp_in = NULL;
+       FileObject *fp_top1 = NULL;
+       FILE *fp_top2 = NULL, *fp_top3 = NULL;
        long long int ttnbytes=0, ttnacc=0, tnacc=0;
        long long int tnbytes=0, ttnelap=0, tnelap=0;
        long long int tnincache=0, tnoucache=0, ttnincache=0, ttnoucache=0;
@@ -88,8 +92,8 @@ void topuser(void)
                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(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),wger,strerror(errno));
+       if((fp_in=FileObject_Open(wger))==NULL) {
+               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),wger,FileObject_GetLastOpenError());
                exit(EXIT_FAILURE);
        }
 
@@ -140,8 +144,8 @@ void topuser(void)
                tnincache+=item.incache;
                tnoucache+=item.oucache;
        }
-       if (fclose(fp_in)==EOF) {
-               debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),wger,strerror(errno));
+       if (FileObject_Close(fp_in)) {
+               debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),wger,FileObject_GetLastCloseError());
                exit(EXIT_FAILURE);
        }
        longline_destroy(&line);
@@ -207,8 +211,8 @@ void topuser(void)
                exit(EXIT_FAILURE);
        }
 
-       if((fp_top1=fopen(top1,"r"))==NULL) {
-               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),top1,strerror(errno));
+       if((fp_top1=FileObject_Open(top1))==NULL) {
+               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),top1,FileObject_GetLastOpenError());
                exit(EXIT_FAILURE);
        }
 
@@ -251,7 +255,7 @@ void topuser(void)
                if (is_denied()) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"denied.html\">%s</a></td></tr>\n",_("Denied accesses"));
                if (is_authfail()) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"authfail.html\">%s</a></td></tr>\n",_("Authentication Failures"));
                if(smartfilter) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"smartfilter.html\">%s</a></td></tr>\n",_("SmartFilter"));
-               if(UserAgentLog[0] != '\0' && useragent_count) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"useragent.html\">%s</a></td></tr>\n",_("Useragent"));
+               if (!FileList_IsEmpty(UserAgentLog) && useragent_count) fprintf(fp_top3,"<tr><td class=\"link\" colspan=\"0\"><a href=\"useragent.html\">%s</a></td></tr>\n",_("Useragent"));
                fputs("<tr><td></td></tr>\n</table></div>\n",fp_top3);
        }
 
@@ -426,8 +430,8 @@ void topuser(void)
 
                topcount++;
        }
-       if (fclose(fp_top1)==EOF) {
-               debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),top1,strerror(errno));
+       if (FileObject_Close(fp_top1)) {
+               debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),top1,FileObject_GetLastCloseError());
                exit(EXIT_FAILURE);
        }
        if (!KeepTempLog && unlink(top1)) {