]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - splitlog.c
Add support to decompress xz files
[thirdparty/sarg.git] / splitlog.c
index dc2e1386bd67ab4b691d98c2f021be4062c34f83..3e8d40c75d978806a1f5c49ab955457993f6fb78 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
@@ -46,7 +46,7 @@ the files are named after the day they contain prefixed with the string containe
 */
 void splitlog(const char *arq, char df, int dfrom, int duntil, int convert, const char *splitprefix)
 {
-       FILE *fp_in;
+       FileObject *fp_in;
        FILE *fp_ou=NULL;
        char *buf;
        char data[30];
@@ -67,7 +67,8 @@ void splitlog(const char *arq, char df, int dfrom, int duntil, int convert, cons
                // '/' + '-YYYY-mm-dd' + '\0' == 13
                output_prefix_len=snprintf(output_file,sizeof(output_file)-12,"%s%s",outdir,splitprefix);
                if (output_prefix_len>=sizeof(output_file)-12) {
-                       debuga(_("(splitlog) Output path is too long: %s%s-YYYY-mm-dd\n"),outdir,splitprefix);
+                       debuga(__FILE__,__LINE__,_("Path too long: "));
+                       debuga_more("%s%s-YYYY-mm-dd\n",outdir,splitprefix);
                        exit(EXIT_FAILURE);
                }
                autosplit=1;
@@ -78,13 +79,13 @@ void splitlog(const char *arq, char df, int dfrom, int duntil, int convert, cons
        if(arq[0] == '\0')
                arq="/var/log/squid/access.log";
 
-       if((fp_in=MY_FOPEN(arq,"r"))==NULL) {
-               debuga(_("(splitlog) Cannot open log file %s: %s\n"),arq,strerror(errno));
+       if((fp_in=decomp(arq))==NULL) {
+               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),arq,FileObject_GetLastOpenError());
                exit(EXIT_FAILURE);
        }
 
        if ((line=longline_create())==NULL) {
-               debuga(_("Not enough memory to read the log file %s\n"),arq);
+               debuga(__FILE__,__LINE__,_("Not enough memory to read file \"%s\"\n"),arq);
                exit(EXIT_FAILURE);
        }
        time(&min_tt);
@@ -92,7 +93,7 @@ void splitlog(const char *arq, char df, int dfrom, int duntil, int convert, cons
        while((buf=longline_read(fp_in,line))!=NULL) {
                getword_start(&gwarea,buf);
                if (getword(data,sizeof(data),&gwarea,' ')<0) {
-                       debuga(_("Invalid date found in file %s\n"),arq);
+                       debuga(__FILE__,__LINE__,_("Invalid date in file \"%s\"\n"),arq);
                        exit(EXIT_FAILURE);
                }
                tt=atoi(data);
@@ -109,7 +110,7 @@ void splitlog(const char *arq, char df, int dfrom, int duntil, int convert, cons
                        prev_month=t->tm_mon;
                        prev_day=t->tm_mday;
                        if (fp_ou && fclose(fp_ou)==EOF) {
-                               debuga(_("Write error in %s: %s\n"),output_file,strerror(errno));
+                               debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),output_file,strerror(errno));
                                exit(EXIT_FAILURE);
                        }
                        strftime(output_file+output_prefix_len, sizeof(output_file)-output_prefix_len, "-%Y-%m-%d", t);
@@ -119,7 +120,7 @@ void splitlog(const char *arq, char df, int dfrom, int duntil, int convert, cons
                        a second time.
                        */
                        if ((fp_ou=MY_FOPEN(output_file,(tt>=min_tt && tt<=max_tt) ? "a" : "w"))==NULL) {
-                               debuga(_("(splitlog) Cannot open output log file %s: %s\n"),output_file,strerror(errno));
+                               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),output_file,strerror(errno));
                                exit(EXIT_FAILURE);
                        }
                        if (tt<min_tt) min_tt=tt;
@@ -139,12 +140,13 @@ void splitlog(const char *arq, char df, int dfrom, int duntil, int convert, cons
        }
 
        longline_destroy(&line);
-       if (fclose(fp_in)==EOF) {
-               debuga(_("Failed to close file %s - %s\n"),arq,strerror(errno));
+       if (FileObject_Close(fp_in)) {
+               debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),arq,FileObject_GetLastCloseError());
+               exit(EXIT_FAILURE);
        }
        if (autosplit && fp_ou) {
                if (fclose(fp_ou)==EOF) {
-                       debuga(_("Write error in %s: %s\n"),output_file,strerror(errno));
+                       debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),output_file,strerror(errno));
                        exit(EXIT_FAILURE);
                }
        }