X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=index.c;h=d7ba1e72796be783d6021de64091cd9c9d7af89f;hb=976c5bb742e00e163caa261e41c7f668cce5f1b3;hp=675d16754bbf3628a90b74cb69d7b81757f93e1f;hpb=7a9d0965d388bfd1246bfb2518d87b47a755dde0;p=thirdparty%2Fsarg.git diff --git a/index.c b/index.c index 675d167..d7ba1e7 100644 --- 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) { @@ -107,6 +107,7 @@ void make_index(void) */ static long long int get_file_size(struct stat *statb) { +#ifdef __linux__ long long int blocks; //return(statb->st_size);//the size of the file content @@ -114,6 +115,9 @@ static long long int get_file_size(struct stat *statb) if (statb->st_blksize==0) return(statb->st_size); blocks=(statb->st_size+statb->st_blksize-1)/statb->st_blksize; return(blocks*statb->st_blksize);//how many bytes occupied on disk +#else + return(statb->st_size); +#endif } /*! @@ -144,11 +148,12 @@ static long long int get_size(char *path,int path_size) path_len=strlen(path); if (path_len+2>=path_size) { - debuga(_("Directory entry \"%s\" too long\n"),path); + 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++]='/'; @@ -156,12 +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(_("Directory entry \"%s%s\" too long\n"),path,direntp->d_name); + 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)) @@ -173,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); } } @@ -240,12 +246,13 @@ 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(_("Directory path too long: %s/%s\n"),monthdir,INDEX_HTML_FILE); + debuga(__FILE__,__LINE__,_("Path too long: ")); + debuga_more("%s/%s\n",monthdir,INDEX_HTML_FILE); exit(EXIT_FAILURE); } monthdir[monthdir_len++]='/'; @@ -253,12 +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(_("Directory entry \"%s%s\" too long\n"),monthdir,direntp->d_name); + 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)) @@ -274,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; @@ -294,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(_("(index) 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); @@ -334,10 +342,10 @@ static long long int make_date_index_day(char *monthdir,int monthdir_size,int or } fputs("\n",fp_ou); monthdir[monthdir_len-1]='\0'; - if (write_html_trailer(fp_ou)<0) - debuga(_("Write error in the index %s/%s\n"),monthdir,INDEX_HTML_FILE); + 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); @@ -356,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); @@ -398,12 +406,13 @@ 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(_("Directory path too long: %s/%s\n"),yeardir,INDEX_HTML_FILE); + debuga(__FILE__,__LINE__,_("Path too long: ")); + debuga_more("%s/%s\n",yeardir,INDEX_HTML_FILE); exit(EXIT_FAILURE); } yeardir[yeardir_len++]='/'; @@ -411,12 +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(_("Directory entry \"%s%s\" too long\n"),yeardir,direntp->d_name); + 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)) @@ -432,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; @@ -452,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(_("(index) 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); @@ -481,7 +491,8 @@ 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(_("Directory path too long: %s%s\n"),yeardir,monthnum); + debuga(__FILE__,__LINE__,_("Path too long: ")); + debuga_more("%s%s\n",yeardir,monthnum); exit(EXIT_FAILURE); } strcpy(yeardir+yeardir_len,monthnum); @@ -501,11 +512,10 @@ static long long int make_date_index_month(char *yeardir,int yeardir_size,int or } fputs("\n",fp_ou); yeardir[yeardir_len-1]='\0'; - if (write_html_trailer(fp_ou)<0) { - debuga(_("Write error in the index %s/%s\n"),yeardir,INDEX_HTML_FILE); - } + 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); @@ -532,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) { @@ -574,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(_("(index) 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); @@ -591,7 +601,8 @@ static void make_date_index(void) yeardirlen=strlen(outdir); if (yeardirlen>=sizeof(yeardir)) { - debuga(_("Output directory too long: %s"),outdir); + debuga(__FILE__,__LINE__,_("Path too long: ")); + debuga_more("%s",outdir); exit(EXIT_FAILURE); } strcpy(yeardir,outdir); @@ -621,10 +632,9 @@ static void make_date_index(void) } fputs("\n",fp_ou); - if (write_html_trailer(fp_ou)<0) - debuga(_("Write error in the index %s\n"),yearindex); + 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); } } @@ -661,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); } @@ -671,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') { @@ -698,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)); @@ -728,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)); @@ -736,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; @@ -755,7 +765,7 @@ static void make_file_index(void) closedir( dirp ); if((fp_ou=fopen(wdir,"w"))==NULL) { - debuga(_("(index) 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); @@ -787,10 +797,9 @@ static void make_file_index(void) fprintf(fp_ou,">%s\n",fixnum(media,1)); } fputs("\n",fp_ou); - if (write_html_trailer(fp_ou)<0) - debuga(_("Write error in the index %s\n"),wdir); + 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 ; id_name,direntp3->d_name); if(rename(olddir,newdir)) { - debuga(_("(index) rename error from \"%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); } }