]> git.ipfire.org Git - thirdparty/sarg.git/blobdiff - index.c
Add support to decompress xz files
[thirdparty/sarg.git] / index.c
diff --git a/index.c b/index.c
index 9acb8a598a9ce4f50bda8d5d258fe99d4efea593..d7ba1e72796be783d6021de64091cd9c9d7af89f 100644 (file)
--- a/index.c
+++ b/index.c
@@ -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
@@ -51,7 +51,7 @@ void make_index(void)
                sprintf(wdir,"%s"INDEX_HTML_FILE,outdir);
                if(access(wdir, R_OK) == 0) {
                        if (unlink(wdir)) {
-                               debuga(_("Cannot delete \"%s\": %s\n"),wdir,strerror(errno));
+                               debuga(__FILE__,__LINE__,_("Cannot delete \"%s\": %s\n"),wdir,strerror(errno));
                                exit(EXIT_FAILURE);
                        }
                }
@@ -60,12 +60,12 @@ void make_index(void)
 
        if(debug) {
                // TRANSLATORS: The %s is the name of the html index file (index.html).
-               debuga(_("Making %s\n"),INDEX_HTML_FILE);
+               debuga(__FILE__,__LINE__,_("Making %s\n"),INDEX_HTML_FILE);
        }
 
        // convert any old report hierarchy
        if ((dirp = opendir(outdir)) == NULL) {
-               debuga(_("Failed to open directory %s - %s\n"),outdir,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Cannot open directory \"%s\": %s\n"),outdir,strerror(errno));
                exit(EXIT_FAILURE);
        }
        while ((direntp = readdir( dirp )) != NULL) {
@@ -148,12 +148,12 @@ static long long int get_size(char *path,int path_size)
 
        path_len=strlen(path);
        if (path_len+2>=path_size) {
-               debuga(_("Path too long: "));
+               debuga(__FILE__,__LINE__,_("Path too long: "));
                debuga_more("%s\n",path);
                exit(EXIT_FAILURE);
        }
        if ((dirp=opendir(path))==NULL) {
-               debuga(_("Cannot open directory \"%s\": %s\n"),path,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Cannot open directory \"%s\": %s\n"),path,strerror(errno));
                exit(EXIT_FAILURE);
        }
        path[path_len++]='/';
@@ -161,13 +161,13 @@ static long long int get_size(char *path,int path_size)
                if (direntp->d_name[0]=='.' && (direntp->d_name[1]=='\0' || (direntp->d_name[1]=='.' && direntp->d_name[2]=='\0'))) continue;
                name_len=strlen(direntp->d_name);
                if (path_len+name_len+1>=path_size) {
-                       debuga(_("Path too long "));
+                       debuga(__FILE__,__LINE__,_("Path too long: "));
                        debuga_more("%s%s\n",path,direntp->d_name);
                        exit(EXIT_FAILURE);
                }
                strcpy(path+path_len,direntp->d_name);
                if (MY_LSTAT(path,&statb) == -1) {
-                       debuga(_("Failed to get the file statistics of %s: %s\n"),path,strerror(errno));
+                       debuga(__FILE__,__LINE__,_("Failed to get the statistics of file \"%s\": %s\n"),path,strerror(errno));
                        continue;
                }
                if (S_ISDIR(statb.st_mode))
@@ -179,7 +179,7 @@ static long long int get_size(char *path,int path_size)
                                dir_allocated+=size;
                                dir_list=realloc(dir_list,dir_allocated);
                                if (!dir_list) {
-                                       debuga(_("Not enough memory to recurse into subdirectory\n"));
+                                       debuga(__FILE__,__LINE__,_("Not enough memory to recurse into subdirectory \"%s\"\n"),path);
                                        exit(EXIT_FAILURE);
                                }
                        }
@@ -246,12 +246,12 @@ static long long int make_date_index_day(char *monthdir,int monthdir_size,int or
 
        ndays=0;
        if ((dirp3 = opendir(monthdir)) == NULL) {
-               debuga(_("Failed to open directory %s - %s\n"),monthdir,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Cannot open directory \"%s\": %s\n"),monthdir,strerror(errno));
                exit(EXIT_FAILURE);
        }
        monthdir_len=strlen(monthdir);
        if (monthdir_len+strlen(INDEX_HTML_FILE)+2>=monthdir_size) {
-               debuga(_("Path too long: "));
+               debuga(__FILE__,__LINE__,_("Path too long: "));
                debuga_more("%s/%s\n",monthdir,INDEX_HTML_FILE);
                exit(EXIT_FAILURE);
        }
@@ -260,13 +260,13 @@ static long long int make_date_index_day(char *monthdir,int monthdir_size,int or
                if (direntp->d_name[0]=='.' && (direntp->d_name[1]=='\0' || (direntp->d_name[1]=='.' && direntp->d_name[2]=='\0'))) continue;
                name_len=strlen(direntp->d_name);
                if (monthdir_len+name_len+1>=monthdir_size) {
-                       debuga(_("Path too long: "));
+                       debuga(__FILE__,__LINE__,_("Path too long: "));
                        debuga_more("%s%s\n",monthdir,direntp->d_name);
                        exit(EXIT_FAILURE);
                }
                strcpy(monthdir+monthdir_len,direntp->d_name);
                if (MY_LSTAT(monthdir,&statb) == -1) {
-                       debuga(_("Failed to get the file statistics of %s: %s\n"),monthdir,strerror(errno));
+                       debuga(__FILE__,__LINE__,_("Failed to get the statistics of file \"%s\": %s\n"),monthdir,strerror(errno));
                        continue;
                }
                if (S_ISDIR(statb.st_mode))
@@ -282,7 +282,7 @@ static long long int make_date_index_day(char *monthdir,int monthdir_size,int or
                                d2=0;
                        }
                        if (ndays>=sizeof(daysort)/sizeof(daysort[0])) {
-                               debuga(_("Too many day directories in %s\nSupernumerary entries are ignored\n"),monthdir);
+                               debuga(__FILE__,__LINE__,_("Too many day directories in %s\nSupernumerary entries are ignored\n"),monthdir);
                                break;
                        }
                        day=(d1 << 5) | d2;
@@ -302,7 +302,7 @@ static long long int make_date_index_day(char *monthdir,int monthdir_size,int or
 
        strcpy(monthdir+monthdir_len,INDEX_HTML_FILE);
        if((fp_ou=fopen(monthdir,"w"))==NULL) {
-               debuga(_("Cannot open file \"%s\": %s\n"),monthdir,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),monthdir,strerror(errno));
                exit(EXIT_FAILURE);
        }
        snprintf(title,sizeof(title),ngettext("SARG: report for %s/%s","SARG: reports for %s/%s",ndays),yearnum,monthnum);
@@ -344,7 +344,8 @@ static long long int make_date_index_day(char *monthdir,int monthdir_size,int or
        monthdir[monthdir_len-1]='\0';
        write_html_trailer(fp_ou);
        if (fclose(fp_ou)==EOF) {
-               debuga(_("Write error in %s/%s: %s\n"),monthdir,INDEX_HTML_FILE,strerror(errno));
+               strcpy(monthdir+monthdir_len,INDEX_HTML_FILE);
+               debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),monthdir,strerror(errno));
                exit(EXIT_FAILURE);
        }
        return(total_size);
@@ -363,7 +364,7 @@ static void name_month(int month,char *month_name,int month_size)
                                           N_("August"),N_("September"),N_("October"),N_("November"),N_("December")};
 
        if (month<1 || month>12) {
-               debuga(_("The internal list of month names is invalid. Please report this bug to the translator.\n"));
+               debuga(__FILE__,__LINE__,_("The internal list of month names is invalid. Please report this bug to the translator.\n"));
                exit(EXIT_FAILURE);
        }
        strncpy(month_name,_(m[month-1]),month_size-1);
@@ -405,12 +406,12 @@ static long long int make_date_index_month(char *yeardir,int yeardir_size,int or
 
        nmonths=0;
        if ((dirp2 = opendir(yeardir)) == NULL) {
-               debuga(_("Failed to open directory %s - %s\n"),yeardir,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Cannot open directory \"%s\": %s\n"),yeardir,strerror(errno));
                exit(EXIT_FAILURE);
        }
        yeardir_len=strlen(yeardir);
        if (yeardir_len+strlen(INDEX_HTML_FILE)+2>=yeardir_size) {
-               debuga(_("Path too long: "));
+               debuga(__FILE__,__LINE__,_("Path too long: "));
                debuga_more("%s/%s\n",yeardir,INDEX_HTML_FILE);
                exit(EXIT_FAILURE);
        }
@@ -419,13 +420,13 @@ static long long int make_date_index_month(char *yeardir,int yeardir_size,int or
                if (direntp->d_name[0]=='.' && (direntp->d_name[1]=='\0' || (direntp->d_name[1]=='.' && direntp->d_name[2]=='\0'))) continue;
                name_len=strlen(direntp->d_name);
                if (yeardir_len+name_len+1>=yeardir_size) {
-                       debuga(_("Path too long: "));
+                       debuga(__FILE__,__LINE__,_("Path too long: "));
                        debuga_more("%s%s\n",yeardir,direntp->d_name);
                        exit(EXIT_FAILURE);
                }
                strcpy(yeardir+yeardir_len,direntp->d_name);
                if (MY_LSTAT(yeardir,&statb) == -1) {
-                       debuga(_("Failed to get the file statistics of %s: %s\n"),yeardir,strerror(errno));
+                       debuga(__FILE__,__LINE__,_("Failed to get the statistics of file \"%s\": %s\n"),yeardir,strerror(errno));
                        continue;
                }
                if (S_ISDIR(statb.st_mode))
@@ -441,7 +442,7 @@ static long long int make_date_index_month(char *yeardir,int yeardir_size,int or
                                m2=0;
                        }
                        if (nmonths>=sizeof(monthsort)/sizeof(monthsort[0])) {
-                               debuga(_("Too many month directories in %s\nSupernumerary entries are ignored\n"),yeardir);
+                               debuga(__FILE__,__LINE__,_("Too many month directories in %s\nSupernumerary entries are ignored\n"),yeardir);
                                break;
                        }
                        month=(m1<<4) | m2;
@@ -461,7 +462,7 @@ static long long int make_date_index_month(char *yeardir,int yeardir_size,int or
 
        strcpy(yeardir+yeardir_len,INDEX_HTML_FILE);
        if((fp_ou=fopen(yeardir,"w"))==NULL) {
-               debuga(_("Cannot open file \"%s\": %s\n"),yeardir,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),yeardir,strerror(errno));
                exit(EXIT_FAILURE);
        }
        snprintf(title,sizeof(title),ngettext("SARG: report for %s","SARG: reports for %s",nmonths),yearnum);
@@ -490,7 +491,7 @@ static long long int make_date_index_month(char *yeardir,int yeardir_size,int or
                }
                if (yeardir_len+strlen(monthnum)+1>=yeardir_size) {
                        yeardir[yeardir_len]='\0';
-                       debuga(_("Path too long: "));
+                       debuga(__FILE__,__LINE__,_("Path too long: "));
                        debuga_more("%s%s\n",yeardir,monthnum);
                        exit(EXIT_FAILURE);
                }
@@ -513,7 +514,8 @@ static long long int make_date_index_month(char *yeardir,int yeardir_size,int or
        yeardir[yeardir_len-1]='\0';
        write_html_trailer(fp_ou);
        if (fclose(fp_ou)==EOF) {
-               debuga(_("Write error in %s/%s: %s\n"),yeardir,INDEX_HTML_FILE,strerror(errno));
+               strcpy(yeardir+yeardir_len,INDEX_HTML_FILE);
+               debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),yeardir,strerror(errno));
                exit(EXIT_FAILURE);
        }
        return(total_size);
@@ -540,7 +542,7 @@ static void make_date_index(void)
 
        nyears=0;
        if ((dirp = opendir(outdir)) == NULL) {
-               debuga(_("Failed to open directory %s - %s\n"),outdir,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Cannot open directory \"%s\": %s\n"),outdir,strerror(errno));
                exit(EXIT_FAILURE);
        }
        while ((direntp = readdir( dirp )) != NULL) {
@@ -582,11 +584,11 @@ static void make_date_index(void)
        order=(strcmp(IndexSortOrder,"A") == 0) ? 1 : -1;
 
        if (snprintf(yearindex,sizeof(yearindex),"%s"INDEX_HTML_FILE,outdir)>=sizeof(yearindex)) {
-               debuga(_("Resulting index file name too long: %s/%s"),outdir,INDEX_HTML_FILE);
+               debuga(__FILE__,__LINE__,_("Resulting index file name too long. File name is \"%s/%s\""),outdir,INDEX_HTML_FILE);
                exit(EXIT_FAILURE);
        }
        if((fp_ou=fopen(yearindex,"w"))==NULL) {
-               debuga(_("Cannot open file \"%s\": %s\n"),yearindex,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),yearindex,strerror(errno));
                exit(EXIT_FAILURE);
        }
        write_html_header(fp_ou,0,ngettext("SARG report","SARG reports",nyears),HTML_JS_NONE);
@@ -599,7 +601,7 @@ static void make_date_index(void)
 
        yeardirlen=strlen(outdir);
        if (yeardirlen>=sizeof(yeardir)) {
-               debuga(_("Path too long: "));
+               debuga(__FILE__,__LINE__,_("Path too long: "));
                debuga_more("%s",outdir);
                exit(EXIT_FAILURE);
        }
@@ -632,7 +634,7 @@ static void make_date_index(void)
        fputs("</table></div>\n",fp_ou);
        write_html_trailer(fp_ou);
        if (fclose(fp_ou)==EOF) {
-               debuga(_("Write error in \"%s\": %s\n"),yearindex,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),yearindex,strerror(errno));
                exit(EXIT_FAILURE);
        }
 }
@@ -669,7 +671,7 @@ static void make_file_index(void)
        order=(strcmp(IndexSortOrder,"A") == 0) ? 1 : -1;
 
        if ((dirp = opendir(outdir)) == NULL) {
-               debuga(_("Failed to open directory %s - %s\n"),outdir,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Cannot open directory \"%s\": %s\n"),outdir,strerror(errno));
                exit(EXIT_FAILURE);
        }
 
@@ -679,12 +681,12 @@ static void make_file_index(void)
        while ((direntp = readdir( dirp )) != NULL) {
                if (strchr(direntp->d_name,'-') == 0) continue;
                if (obtdate(outdir,direntp->d_name,data)<0) {
-                       debuga(_("The directory \"%s%s\" looks like a report directory but doesn't contain a sarg-date file. You should delete it\n"),outdir,direntp->d_name);
+                       debuga(__FILE__,__LINE__,_("The directory \"%s%s\" looks like a report directory but doesn't contain a sarg-date file. You should delete it\n"),outdir,direntp->d_name);
                        continue;
                }
                item=malloc(sizeof(*item));
                if (!item) {
-                       debuga(_("not enough memory to sort the index\n"));
+                       debuga(__FILE__,__LINE__,_("not enough memory to sort the index\n"));
                        exit(EXIT_FAILURE);
                }
                if (df=='u') {
@@ -706,29 +708,29 @@ static void make_file_index(void)
                        */
                        getword_start(&gwarea,data);
                        if (getword_skip(16,&gwarea,' ')<0) {
-                               debuga(_("Maybe you have a broken week day in your %s%s/sarg-date file\n"),outdir,direntp->d_name);
+                               debuga(__FILE__,__LINE__,_("Invalid date in file \"%s%s/sarg-date\"\n"),outdir,direntp->d_name);
                                exit(EXIT_FAILURE);
                        }
                        if (getword_multisep(mon,sizeof(mon),&gwarea,' ')<0) {
-                               debuga(_("Maybe you have a broken month in your %s%s/sarg-date file\n"),outdir,direntp->d_name);
+                               debuga(__FILE__,__LINE__,_("Invalid date in file \"%s%s/sarg-date\"\n"),outdir,direntp->d_name);
                                exit(EXIT_FAILURE);
                        }
                        if (getword_multisep(day,sizeof(day),&gwarea,' ')<0) {
-                               debuga(_("Maybe you have a broken day in your %s%s/sarg-date file\n"),outdir,direntp->d_name);
+                               debuga(__FILE__,__LINE__,_("Invalid date in file \"%s%s/sarg-date\"\n"),outdir,direntp->d_name);
                                exit(EXIT_FAILURE);
                        }
                        if (getword_multisep(hour,sizeof(hour),&gwarea,' ')<0) {
-                               debuga(_("Maybe you have a broken time in your %s%s/sarg-date file\n"),outdir,direntp->d_name);
+                               debuga(__FILE__,__LINE__,_("Invalid time in file \"%s%s/sarg-date\"\n"),outdir,direntp->d_name);
                                exit(EXIT_FAILURE);
                        }
                        do {
                                if (getword_multisep(year,sizeof(year),&gwarea,' ')<0) {
-                                       debuga(_("Maybe you have a broken year in your %s%s/sarg-date file\n"),outdir,direntp->d_name);
+                                       debuga(__FILE__,__LINE__,_("Invalid date in file \"%s%s/sarg-date\"\n"),outdir,direntp->d_name);
                                        exit(EXIT_FAILURE);
                                }
                        } while (year[0] && !isdigit(year[0])); //skip time zone information with spaces until the year is found
                        if (sscanf(hour,"%d:%d:%d",&ihour,&iminute,&isecond)!=3) {
-                               debuga(_("Maybe you have a broken time in your %s%s/sarg-date file\n"),outdir,direntp->d_name);
+                               debuga(__FILE__,__LINE__,_("Invalid time in file \"%s%s/sarg-date\"\n"),outdir,direntp->d_name);
                                exit(EXIT_FAILURE);
                        }
                        buildymd(day,mon,year,ftime,sizeof(ftime));
@@ -736,7 +738,7 @@ static void make_file_index(void)
                }
                item->dirname=strdup(direntp->d_name);
                if (!item->dirname) {
-                       debuga(_("Not enough memory to store the directory name \"%s\" in the index\n"),direntp->d_name);
+                       debuga(__FILE__,__LINE__,_("Not enough memory to store the directory name \"%s\" in the index\n"),direntp->d_name);
                        exit(EXIT_FAILURE);
                }
                safe_strcpy(item->date,data,sizeof(item->date));
@@ -744,7 +746,7 @@ static void make_file_index(void)
                        nallocated+=10;
                        tempsort=realloc(sortlist,nallocated*sizeof(*item));
                        if (!tempsort) {
-                               debuga(_("not enough memory to sort the index\n"));
+                               debuga(__FILE__,__LINE__,_("not enough memory to sort the index\n"));
                                exit(EXIT_FAILURE);
                        }
                        sortlist=tempsort;
@@ -763,7 +765,7 @@ static void make_file_index(void)
        closedir( dirp );
 
        if((fp_ou=fopen(wdir,"w"))==NULL) {
-               debuga(_("Cannot open file \"%s\": %s\n"),wdir,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),wdir,strerror(errno));
                exit(EXIT_FAILURE);
        }
        write_html_header(fp_ou,0,ngettext("SARG report","SARG reports",nsort),HTML_JS_SORTTABLE);
@@ -797,7 +799,7 @@ static void make_file_index(void)
        fputs("</table></div>\n",fp_ou);
        write_html_trailer(fp_ou);
        if (fclose(fp_ou)==EOF)
-               debuga(_("Failed to close the index file %s - %s\n"),wdir,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),wdir,strerror(errno));
 
        if (sortlist) {
                for (i=0 ; i<nsort ; i++) {
@@ -882,7 +884,7 @@ static void file_index_to_date_index(const char *entry)
        ndirlen=sprintf(newdir,"%s%04d",outdir,y1);
        if (access(newdir, R_OK) != 0) {
                if (PortableMkDir(newdir,0755)) {
-                       debuga(_("Cannot create directory \"%s\": %s\n"),newdir,strerror(errno));
+                       debuga(__FILE__,__LINE__,_("Cannot create directory \"%s\": %s\n"),newdir,strerror(errno));
                        exit(EXIT_FAILURE);
                }
        }
@@ -890,7 +892,7 @@ static void file_index_to_date_index(const char *entry)
        else ndirlen+=sprintf(newdir+ndirlen,"/%02d",m1);
        if (access(newdir, R_OK) != 0) {
                if (PortableMkDir(newdir,0755)) {
-                       debuga(_("Cannot create directory \"%s\": %s\n"),newdir,strerror(errno));
+                       debuga(__FILE__,__LINE__,_("Cannot create directory \"%s\": %s\n"),newdir,strerror(errno));
                        exit(EXIT_FAILURE);
                }
        }
@@ -900,7 +902,7 @@ static void file_index_to_date_index(const char *entry)
 
        sprintf(olddir,"%s%s",outdir,entry);
        if (rename(olddir,newdir)) {
-               debuga(_("Error renaming \"%s\" to \"%s\": %s\n"),olddir,newdir,strerror(errno));
+               debuga(__FILE__,__LINE__,_("Error renaming \"%s\" to \"%s\": %s\n"),olddir,newdir,strerror(errno));
                exit(EXIT_FAILURE);
        }
 
@@ -911,7 +913,7 @@ static void file_index_to_date_index(const char *entry)
 
                sprintf(linkdir,"%simages",outdir);
                if (symlink(linkdir,newdir)) {
-                       debuga(_("Failed to create link \"%s\" to \"%s\": %s\n"),linkdir,newdir,strerror(errno));
+                       debuga(__FILE__,__LINE__,_("Failed to create link \"%s\" to \"%s\": %s\n"),linkdir,newdir,strerror(errno));
                        exit(EXIT_FAILURE);
                }
 #else
@@ -921,8 +923,8 @@ static void file_index_to_date_index(const char *entry)
                sprintf(cmd,"ln -s \"%simages\" \"%s/images\"",outdir,newdir);
                cstatus=system(cmd);
                if (!WIFEXITED(cstatus) || WEXITSTATUS(cstatus)) {
-                       debuga(_("command return status %d\n"),WEXITSTATUS(cstatus));
-                       debuga(_("command: %s\n"),cmd);
+                       debuga(__FILE__,__LINE__,_("command return status %d\n"),WEXITSTATUS(cstatus));
+                       debuga(__FILE__,__LINE__,_("command: %s\n"),cmd);
                        exit(EXIT_FAILURE);
                }
 #endif
@@ -1002,7 +1004,7 @@ static void date_index_to_file_index(const char *entry)
                        else continue;
                        sprintf(olddir,"%s%04d/%s/%s",outdir,y1,direntp2->d_name,direntp3->d_name);
                        if(rename(olddir,newdir)) {
-                               debuga(_("Error renaming \"%s\" to \"%s\": %s\n"),olddir,newdir,strerror(errno));
+                               debuga(__FILE__,__LINE__,_("Error renaming \"%s\" to \"%s\": %s\n"),olddir,newdir,strerror(errno));
                                exit(EXIT_FAILURE);
                        }
                }