]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - topsites.c
Add support to decompress xz files
[thirdparty/sarg.git] / topsites.c
index a4234cfbefb134ec222d92ec79b06e5756f3393f..5992cef520e38c3b672b299095ffddff01137106 100644 (file)
@@ -33,7 +33,8 @@ extern struct globalstatstruct globstat;
 
 void topsites(void)
 {
-       FILE *fp_in, *fp_ou;
+       FileObject *fp_in;
+       FILE *fp_ou;
 
        char *buf;
        char *url;
@@ -69,11 +70,11 @@ void topsites(void)
        struct generalitemstruct item;
 
        if(Privacy) {
-               if (debugz>=LogLevel_Process) debugaz(_("Top sites report not produced because privacy option is on\n"));
+               if (debugz>=LogLevel_Process) debugaz(__FILE__,__LINE__,_("Top sites report not produced because privacy option is on\n"));
                return;
        }
        if (debugz>=LogLevel_Process)
-               debuga(_("Creating top sites report...\n"));
+               debuga(__FILE__,__LINE__,_("Creating top sites report...\n"));
 
        sprintf(general,"%s/sarg-general",outdirname);
        sprintf(sites,"%s/sarg-sites",outdirname);
@@ -83,29 +84,29 @@ void topsites(void)
        sprintf(report,"%s/topsites.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(general3,"w"))==NULL) {
-               debuga(_("Cannot open file \"%s\": %s\n"),general3,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),general3,strerror(errno));
                exit(EXIT_FAILURE);
        }
 
        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);
        }
 
@@ -119,7 +120,7 @@ void topsites(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);
                                }
                        }
@@ -138,7 +139,7 @@ void topsites(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);
                                }
                        }
@@ -162,8 +163,8 @@ void topsites(void)
                ttntime+=item.nelap;
 #endif
        }
-       if (fclose(fp_in)==EOF) {
-               debuga(_("Read error in \"%s\": %s\n"),general2,strerror(errno));
+       if (FileObject_Close(fp_in)) {
+               debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),general2,FileObject_GetLastCloseError());
                exit(EXIT_FAILURE);
        }
        longline_destroy(&line);
@@ -178,19 +179,19 @@ void topsites(void)
        }
 
        if (fclose(fp_ou)==EOF) {
-               debuga(_("Write error in \"%s\": %s\n"),general3,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),general3,strerror(errno));
                exit(EXIT_FAILURE);
        }
 
 #ifdef ENABLE_DOUBLE_CHECK_DATA
        if (ttnacc!=globstat.nacc || ttnbytes!=globstat.nbytes || ttntime!=globstat.elap) {
-               debuga(_("Total statistics mismatch when reading %s to produce the top sites\n"),general2);
+               debuga(__FILE__,__LINE__,_("Total statistics mismatch when reading \"%s\" to produce the top sites\n"),general2);
                exit(EXIT_FAILURE);
        }
 #endif
 
        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);
        }
 
@@ -212,28 +213,28 @@ void topsites(void)
        }
 
        if (snprintf(csort,sizeof(csort),"sort -t \"\t\" %s -n %s -o \"%s\" \"%s\"",sortt,sortf,sites,general3)>=sizeof(csort)) {
-               debuga(_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),general3,sites);
+               debuga(__FILE__,__LINE__,_("Sort command too long when sorting file \"%s\" to \"%s\"\n"),general3,sites);
                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(sites,"r"))==NULL) {
-               debuga(_("Cannot open file \"%s\": %s\n"),sites,strerror(errno));
-               debuga(_("sort command: %s\n"),csort);
+       if((fp_in=FileObject_Open(sites))==NULL) {
+               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),sites,FileObject_GetLastOpenError());
+               debuga(__FILE__,__LINE__,_("sort command: %s\n"),csort);
                exit(EXIT_FAILURE);
        }
 
        if (!KeepTempLog && unlink(general3)) {
-               debuga(_("Cannot delete \"%s\": %s\n"),general3,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),general3,strerror(errno));
                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);
        }
 
@@ -269,27 +270,27 @@ void topsites(void)
        ntopsites = 0;
 
        if ((line=longline_create())==NULL) {
-               debuga(_("Not enough memory to read file %s\n"),sites);
+               debuga(__FILE__,__LINE__,_("Not enough memory to read file \"%s\"\n"),sites);
                exit(EXIT_FAILURE);
        }
 
        while(regs<TopSitesNum && (buf=longline_read(fp_in,line))!=NULL) {
                getword_start(&gwarea,buf);
                if (getword_atoll(&nacc,&gwarea,'\t')<0) {
-                       debuga(_("Maybe you have a broken record or garbage in your %s file\n"),sites);
+                       debuga(__FILE__,__LINE__,_("Invalid record in file \"%s\"\n"),sites);
                        exit(EXIT_FAILURE);
                }
                if (nacc == 0) continue;
                if (getword_atoll(&nbytes,&gwarea,'\t')<0 || getword_atoll(&ntime,&gwarea,'\t')<0) {
-                       debuga(_("Maybe you have a broken record or garbage in your %s file\n"),sites);
+                       debuga(__FILE__,__LINE__,_("Invalid record in file \"%s\"\n"),sites);
                        exit(EXIT_FAILURE);
                }
                if (getword_atoi(&nusers,&gwarea,'\t')<0) {
-                       debuga(_("The number of users is invalid in file %s\n"),sites);
+                       debuga(__FILE__,__LINE__,_("Invalid number of users in file \"%s\"\n"),sites);
                        exit(EXIT_FAILURE);
                }
                if (getword_ptr(buf,&url,&gwarea,'\t')<0) {
-                       debuga(_("The url is invalid in file %s\n"),sites);
+                       debuga(__FILE__,__LINE__,_("Invalid url in file \"%s\"\n"),sites);
                        exit(EXIT_FAILURE);
                }
 
@@ -319,8 +320,8 @@ void topsites(void)
                if (SortTableJs[0]) fprintf(fp_ou," sorttable_customkey=\"%d\"",nusers);
                fprintf(fp_ou,">%s</td></tr>\n",fixnum(nusers,1));
        }
-       if (fclose(fp_in)==EOF) {
-               debuga(_("Read error in \"%s\": %s\n"),sites,strerror(errno));
+       if (FileObject_Close(fp_in)) {
+               debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),sites,FileObject_GetLastCloseError());
                exit(EXIT_FAILURE);
        }
        longline_destroy(&line);
@@ -328,7 +329,7 @@ void topsites(void)
        fputs("</table></div>\n",fp_ou);
        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);
        }