From: Frédéric Marchal Date: Sat, 19 Dec 2009 21:20:20 +0000 (+0000) Subject: Sarg.conf can use multiple access_log lines. X-Git-Tag: v2_2_7~47 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0a4e18e109dac9b5cb5f1197d5650f2fecce6bbe;p=thirdparty%2Fsarg.git Sarg.conf can use multiple access_log lines. Some small optimizations. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index cce2a98..c3e0725 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,7 +61,9 @@ ADD_EXECUTABLE(sarg ${SRC}) SET_TARGET_PROPERTIES(sarg PROPERTIES VERSION "${sarg_VERSION}.${sarg_REVISION}.${sarg_BUILD}") -SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "${CFLAGS} -Wall -Wextra -Wno-sign-compare -Wno-unused-parameter") +SET_TARGET_PROPERTIES(sarg PROPERTIES COMPILE_FLAGS "$ENV{CFLAGS} -Wall -Wextra -Wno-sign-compare -Wno-unused-parameter") +SET_TARGET_PROPERTIES(sarg PROPERTIES LINK_FLAGS "$ENV{LDFLAGS}") + CHECK_C_COMPILER_FLAG("-Werror=implicit-function-declaration" HAVE_WERROR_IMPLICIT_FUNCTION) IF(HAVE_WERROR_IMPLICIT_FUNCTION) GET_TARGET_PROPERTY(TMPCFLAGS sarg COMPILE_FLAGS) diff --git a/authfail.c b/authfail.c index 191fc37..b27287d 100644 --- a/authfail.c +++ b/authfail.c @@ -49,7 +49,7 @@ void authfail_report(void) int cstatus; struct getwordstruct gwarea; - if(strlen(DataFile) > 0) return; + if(DataFile[0] != '\0') return; ouser[0]='\0'; diff --git a/datafile.c b/datafile.c index a3f6229..be22a41 100644 --- a/datafile.c +++ b/datafile.c @@ -111,8 +111,7 @@ void data_file(char *tmp) if(strcmp(oldurl,accurl) != 0 || strcmp(oldaccuser,accuser) != 0){ strcpy(oldmsg,"OK"); if(strstr(oldacccode,"DENIED") != 0) strcpy(oldmsg,text[46]); - strcpy(wdirname,dirname); - gravatmp(oldaccuser,wdirname,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache); + gravatmp(oldaccuser,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache); strcpy(wdirname,dirname); saverecs(wdirname,oldaccuser,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache); nacc=0; diff --git a/documentation/getconf.txt b/documentation/getconf.txt index 21e43b2..1b904d1 100644 --- a/documentation/getconf.txt +++ b/documentation/getconf.txt @@ -3,6 +3,19 @@ */ +/*! \fn static int isparam_string(const char *param,const char *buf) +Tell if the buffer contains a line defining the given parameter. + +\param param The name of the parameter to find. +\param buf The string read from the input file. + +\retval 1 Parameter match. +\retval 0 The line is not for that parameter. +*/ + + + + /*! \fn static int getparam_string(const char *param,char *buf,char *value,int value_size) Extract a string value from a line if it it the right parameter. diff --git a/documentation/util.txt b/documentation/util.txt index b52ee5d..04564a7 100644 --- a/documentation/util.txt +++ b/documentation/util.txt @@ -93,6 +93,21 @@ the function displays an error message and returns an error code. + +/*! \fn int getword_atoll(long long int *number, struct getwordstruct *gwarea, int stop) +Extract one number from the text line. + +\param number Where the store the extracted number. +\param gwarea The getword buffer initialized by getword_start(). +\param stop The character indicating the end of the word. + +\retval 0 The number is skipped. +\retval -1 The stop character was not found after the number. +*/ + + + + /*! \fn long long int my_atoll (const char *nptr) Convert a string into a long long. diff --git a/getconf.c b/getconf.c index 63ae654..9a85ae3 100644 --- a/getconf.c +++ b/getconf.c @@ -28,6 +28,17 @@ extern numlist hours, weekdays; +static int isparam_string(const char *param,const char *buf) +{ + int plen; + + plen=strlen(param); + if (strncmp(buf,param,plen) != 0) return(0); + buf+=plen; + if ((unsigned char)*buf>' ') return(0); + return(1); +} + static int getparam_string(const char *param,char *buf,char *value,int value_size) { int plen; @@ -219,7 +230,17 @@ static void parmtest(char *buf) if (getparam_2words("user_sort_field",buf,UserSortField,sizeof(UserSortField),UserSortOrder,sizeof(UserSortOrder))>0) return; - if (getparam_string("access_log",buf,AccessLog,sizeof(AccessLog))>0) return; + if (isparam_string("access_log",buf)>0) { + if (AccessLogFromCmdLine==0) { + if (NAccessLog>=MAXLOGS) { + fprintf(stderr,"SARG: Too many log files.\n"); + exit(1); + } + getparam_string("access_log",buf,AccessLog[NAccessLog],MAXLEN); + NAccessLog++; + } + return; + } if (getparam_string("useragent_log",buf,UserAgentLog,sizeof(UserAgentLog))>0) return; diff --git a/html.c b/html.c index 78955a2..56628f6 100644 --- a/html.c +++ b/html.c @@ -35,16 +35,19 @@ void htmlrel(void) long long int nnbytes=0, unbytes=0, tnbytes=0, totbytes=0, totbytes2=0; long long int totelap=0, totelap2=0, nnelap=0, unelap=0, tnelap=0; long long int incache=0, oucache=0, tnincache=0, tnoucache=0, twork=0, twork2=0; + long long int ltemp; + long long int ntotuser; + long long int userbytes, userelap; char arqin[MAXLEN], arqou[MAXLEN], arqper[MAXLEN], arqip[MAXLEN]; - char nacc[20], nbytes[20], url[MAXLEN], tmsg[50], nelap[20], csort[MAXLEN]; + char url[MAXLEN], tmsg[50], csort[MAXLEN]; char period[MAXLEN], usuario[MAXLEN], wusuario[MAXLEN], u2[MAXLEN], duser[MAXLEN]; - char userbytes[20], userelap[20], userurl[1024], userhora[9], userdia[9]; - char user_ip[MAXLEN], olduserip[MAXLEN], tmp2[MAXLEN], tmp3[MAXLEN], incac[20], oucac[20]; + char userurl[1024], userhora[9], userdia[9]; + char user_ip[MAXLEN], olduserip[MAXLEN], tmp2[MAXLEN], tmp3[MAXLEN]; char denied_report[255], name2[MAXLEN]; //char ttd1[3], ttd2[3], ttd3[5], ttt1[3], ttt2[3], ttt3[3]; char *str; char warea[MAXLEN]; - char wtemp[MAXLEN], totuser[8]; + char totuser[8]; long long int tnacc=0, ttnacc=0, unacc=0; float perc=0, perc2=0, ouperc=0, inperc=0; char *s; @@ -90,23 +93,23 @@ void htmlrel(void) while(fgets(buf,sizeof(buf),fp_in)!=NULL) { if(strstr(buf,"TOTAL") == 0) { getword_start(&gwarea,buf); - if (getword_skip(MAXLEN,&gwarea,'\t')<0) { + if (getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_atoll(<emp,&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqper); exit(1); } - ttnacc+=my_atoll(gwarea.current); - if (getword_skip(MAXLEN,&gwarea,'\t')<0 || getword(wtemp,sizeof(wtemp),&gwarea,'\t')<0) { + ttnacc+=ltemp; + if (getword_atoll(<emp,&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqper); exit(1); } - totbytes+=my_atoll(wtemp); + totbytes+=ltemp; if (getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_skip(MAXLEN,&gwarea,'\t')<0 || - getword(wtemp,sizeof(wtemp),&gwarea,'\t')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqper); + getword_atoll(<emp,&gwarea,'\t')<0) { + printf("SARG: Maybe you have a broken record or garbage in your %s file (%d).\n",arqper,__LINE__); exit(1); } - totelap+=my_atoll(wtemp); + totelap+=ltemp; } } @@ -183,32 +186,32 @@ void htmlrel(void) while(fgets(buf,sizeof(buf),fp_in)!=NULL) { getword_start(&gwarea,buf); - if (getword(wtemp,sizeof(wtemp),&gwarea,'\t')<0) { + if (getword_atoll(<emp,&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin); exit(1); } - tnacc+=my_atoll(wtemp); - if (getword(wtemp,sizeof(wtemp),&gwarea,'\t')<0) { + tnacc+=ltemp; + if (getword_atoll(<emp,&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin); exit(1); } - tnbytes+=my_atoll(wtemp); + tnbytes+=ltemp; if (getword_skip(MAXLEN,&gwarea,'\t')<0 || getword_skip(MAXLEN,&gwarea,'\t')<0 || - getword(wtemp,sizeof(wtemp),&gwarea,'\t')<0) { + getword_atoll(<emp,&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin); exit(1); } - tnelap+=my_atoll(wtemp); - if (getword(wtemp,sizeof(wtemp),&gwarea,'\t')<0) { + tnelap+=ltemp; + if (getword_atoll(<emp,&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin); exit(1); } - tnincache+=my_atoll(wtemp); - if (getword(wtemp,sizeof(wtemp),&gwarea,'\t')<0) { - printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",arqin); + tnincache+=ltemp; + if (getword_atoll(<emp,&gwarea,'\n')<0) { + printf("SARG: Maybe you have a broken record or garbage in your %s file (%d).\n",arqin,__LINE__); exit(1); } - tnoucache+=my_atoll(wtemp); + tnoucache+=ltemp; } rewind(fp_in); @@ -292,11 +295,11 @@ void htmlrel(void) while(fgets(buf,sizeof(buf),fp_in)!=NULL) { getword_start(&gwarea,buf); - if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0) { + if (getword_atoll(&twork,&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken number of access in your %s file.\n",arqin); exit(1); } - if (getword(nbytes,sizeof(nbytes),&gwarea,'\t')<0) { + if (getword_atoll(&nnbytes,&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",arqin); exit(1); } @@ -308,16 +311,16 @@ void htmlrel(void) printf("SARG: Maybe you have a broken status in your %s file.\n",arqin); exit(1); } - if (getword(nelap,sizeof(nelap),&gwarea,'\t')<0) { + if (getword_atoll(&nnelap,&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",arqin); exit(1); } - if (getword(incac,sizeof(incac),&gwarea,'\t')<0) { + if (getword_atoll(&incache,&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken in cache column in your %s file.\n",arqin); exit(1); } - if (getword(oucac,sizeof(oucac),&gwarea,'\t')<0) { - printf("SARG: Maybe you have a broken not in cache column in your %s file.\n",arqin); + if (getword_atoll(&oucache,&gwarea,'\n')<0) { + printf("SARG: Maybe you have a broken not in cache column in your %s file (%d).\n",arqin,__LINE__); exit(1); } @@ -325,11 +328,6 @@ void htmlrel(void) sprintf(tmsg,"%s",text[46]); else bzero(tmsg, 50); - nnbytes=my_atoll(nbytes); - nnelap=my_atoll(nelap); - incache=my_atoll(incac); - oucache=my_atoll(oucac); - if(nnbytes) { perc=nnbytes * 100; perc=perc / tnbytes; @@ -353,7 +351,6 @@ void htmlrel(void) ouperc=ouperc / nnbytes; } else ouperc=0; - twork=my_atoll(nacc); strcpy(wwork1,fixnum(twork,1)); strcpy(wwork2,fixnum(nnbytes,1)); strcpy(wwork3,fixnum2(nnelap,1)); @@ -506,12 +503,12 @@ void htmlrel(void) printf("SARG: Maybe you have a broken time in your %s file.\n",tmp3); exit(1); } - if (getword(userbytes,sizeof(userbytes),&gwarea,'\t')<0) { + if (getword_atoll(&userbytes,&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken size in your %s file.\n",tmp3); exit(1); } - if (getword(userelap,sizeof(userelap),&gwarea,'\t')<0) { - printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",tmp3); + if (getword_atoll(&userelap,&gwarea,'\t')<0) { + printf("SARG: Maybe you have a broken elapsed time in your %s file (%d).\n",tmp3,__LINE__); exit(1); } if(strcmp(user_ip,olduserip) != 0) { @@ -525,8 +522,8 @@ void htmlrel(void) unelap=0; } - unbytes=unbytes+my_atoll(userbytes); - unelap=unelap+my_atoll(userelap); + unbytes=unbytes+userbytes; + unelap=unelap+userelap; } fclose(fp_ip); @@ -676,14 +673,16 @@ void htmlrel(void) exit(1); } - if (!fgets(totuser,8,fp_in)) { + if (!fgets(totuser,sizeof(totuser),fp_in)) { fprintf(stderr,"SARG: (html11) read error in %s\n",arqper); exit(1); } fclose(fp_in); - totbytes2=totbytes/my_atoll(totuser); - totelap2=totelap/my_atoll(totuser); + ntotuser=my_atoll(totuser); + if (ntotuser<=0) ntotuser=1; + totbytes2=totbytes/ntotuser; + totelap2=totelap/ntotuser; if(totbytes2) { perc = totbytes / 100; @@ -695,7 +694,7 @@ void htmlrel(void) perc2 = totelap2 / perc2; } else perc2=0; - twork2=my_atoll(totuser); + twork2=ntotuser; twork=ttnacc/twork2; strcpy(wwork1,fixnum(twork,1)); diff --git a/include/conf.h b/include/conf.h index 32fddc3..4f158e0 100755 --- a/include/conf.h +++ b/include/conf.h @@ -128,6 +128,8 @@ int mkstemps(char *template, int suffixlen); #endif /*__MINGW32__*/ #define MAXLEN 20000 +#define MAXLOGS 255 + long long int my_atoll (const char *nptr); FILE *fp_tt; @@ -186,7 +188,9 @@ char LongUrl[20]; char Ip2Name[20]; char language[255]; char bufy[MAXLEN]; -char AccessLog[MAXLEN]; +int NAccessLog; +char AccessLog[MAXLOGS][MAXLEN]; +int AccessLogFromCmdLine; char Title[MAXLEN]; char BgColor[MAXLEN]; char BgImage[MAXLEN]; diff --git a/include/defs.h b/include/defs.h index 96afc89..1bc7f60 100755 --- a/include/defs.h +++ b/include/defs.h @@ -79,7 +79,7 @@ void realtime(void); void report_day(const char *user); // report.c -void gravatmp(const char *oldaccuser, const char *dirname, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache); +void gravatmp(const char *oldaccuser, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, int indexonly, long long int incache, long long int oucache); void gerarel(void); // siteuser.c @@ -125,6 +125,7 @@ void getword_restart(struct getwordstruct *gwarea); int getword(char *word, int limit, struct getwordstruct *gwarea, int stop); int getword_multisep(char *word, int limit, struct getwordstruct *gwarea, int stop); int getword_skip(int limit, struct getwordstruct *gwarea, int stop); +int getword_atoll(long long int *number, struct getwordstruct *gwarea, int stop); void name_month(char *month,int month_len); void conv_month_name(char *month); void buildymd(const char *dia, const char *mes, const char *ano, char *wdata); diff --git a/index.c b/index.c index 8e0277a..e11fb44 100644 --- a/index.c +++ b/index.c @@ -50,12 +50,11 @@ void make_index(void) char day[16], mon[16], year[40], hour[10]; char *str; int cstatus; - int iyear, imonth, iday, ihour, iminute, isecond; + int iyear, imonth, iday, ihour, iminute, isecond, idst; char y1[5], y2[5]; char d1[3], d2[3]; char m1[4], m2[4]; struct getwordstruct gwarea; - int iyear, imonth, iday, ihour, iminute, isecond, idst; if(LastLog[0] != '\0') mklastlog(outdir); diff --git a/log.c b/log.c index 268695e..a7a1002 100644 --- a/log.c +++ b/log.c @@ -93,7 +93,6 @@ int main(int argc,char *argv[]) char date[255]; char arq[255]; char arq_log[255]; - char warq[255][255]; char hm[15], hmf[15], hmr[15]; int chm=0; char uagent[MAXLEN]; @@ -117,7 +116,6 @@ int main(int argc,char *argv[]) int fuser=0; int idata=0; int mindate=0; - int narq=0; int iarq=0; int exstring=0; int isa_ncols=0,isa_cols[ISACOL_Last]; @@ -156,10 +154,8 @@ int main(int argc,char *argv[]) ExternalCSSFile[0]='\0'; SquidGuardLogFormat[0]='\0'; SquidGuardLogAlternate[0]='\0'; - arq[0]='\0'; for (ilf=0 ; ilf=sizeof(warq)/sizeof(warq[0])) { + if (NAccessLog>=MAXLOGS) { printf("SARG: Too many log files.\n"); exit(1); } - strcpy(warq[narq],optarg); - narq++; + strcpy(AccessLog[NAccessLog],optarg); + NAccessLog++; + AccessLogFromCmdLine++; break; case 'L': strcpy(SquidGuardLogAlternate,optarg); @@ -459,18 +458,18 @@ int main(int argc,char *argv[]) subs(UserReportFields,sizeof(UserReportFields),"%BYTES","SETYB"); - if(!narq) { - strcpy(warq[0],AccessLog); - narq++; + if(!NAccessLog) { + strcpy(AccessLog[0],"/var/log/squid/access.log"); + NAccessLog++; } if(strcmp(hexclude,"onvert") == 0 && strcmp(site,"plit") != 0) { - convlog(warq[0], df, dfrom, duntil); + convlog(AccessLog[0], df, dfrom, duntil); exit(0); } if(strcmp(site,"plit") == 0) { - splitlog(warq[0], df, dfrom, duntil, hexclude); + splitlog(AccessLog[0], df, dfrom, duntil, hexclude); exit(0); } @@ -517,9 +516,6 @@ int main(int argc,char *argv[]) if(strlen(outdir)<1) strcpy(outdir,OutputDir); strcat(outdir,"/"); - - if(arq[0] == '\0') strcpy(arq,AccessLog); - if(uagent[0] == '\0') strcpy(uagent,UserAgentLog); if(tmp[0] == '\0') strcpy(tmp,TempDir); @@ -586,9 +582,10 @@ int main(int argc,char *argv[]) fprintf(stderr, "SARG: %35s (-g) = %s (yyyy/ww)\n",text[25],text[85]); if(iprel) fprintf(stderr, "SARG: %35s (-i) = %s\n",text[28],text[1]); - else + else fprintf(stderr, "SARG: %35s (-i) = %s\n",text[28],text[2]); - fprintf(stderr, "SARG: %35s (-l) = %s\n",text[37],arq); + for (iarq=0 ; iarq=sizeof(wdirname)) { + fprintf(stderr,"SARG: Path too long %s/%s.utmp\n",tmp,oldaccuser); + exit(1); + } if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){ fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname); exit(1); } - my_lltoa(nacc,val1,15); - my_lltoa(nbytes,val2,15); - my_lltoa(nelap,val3,15); - my_lltoa(incache,val4,15); - my_lltoa(oucache,val5,15); + my_lltoa(nacc,val1,0); + my_lltoa(nbytes,val2,0); + my_lltoa(nelap,val3,0); + my_lltoa(incache,val4,0); + my_lltoa(oucache,val5,0); fprintf(fp_ou,"%s\t%s\t%s\t%s\t%s\t%s\t%s\n",val1,val2,oldurl,oldmsg,val3,val4,val5); fclose(fp_ou); @@ -484,10 +489,10 @@ static void gravatmp_hora(const char *dirname, const char *user, const char *dat if(indexonly || (strstr(ReportType,"users_sites") == 0)) return; - strcpy(wdirname,tmp); - strcat(wdirname,"/"); - strcat(wdirname,user); - strcat(wdirname,".htmp"); + if (snprintf(wdirname,sizeof(wdirname),"%s/%s.htmp",tmp,user)>=sizeof(wdirname)) { + fprintf(stderr,"SARG: Path too long %s/%s.htmp\n",tmp,user); + exit(1); + } if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){ fprintf(stderr, "SARG: (report-2) %s: %s - %s\n",text[45],wdirname,strerror(errno)); @@ -507,15 +512,14 @@ static void gravaporuser(const char *user, const char *dirname, const char *url, { FILE *fp_ou; - char wdirname[MAXLEN]; if(indexonly || (strstr(ReportType,"users_sites") == 0)) return; - strcpy(wdirname,tmp); - strcat(wdirname,"/"); - strcat(wdirname,user); - strcat(wdirname,".ip"); + if (snprintf(wdirname,sizeof(wdirname),"%s/%s.ip",tmp,user)>=sizeof(wdirname)) { + fprintf(stderr,"SARG: Path too long %s/%s.ip\n",tmp,user); + exit(1); + } if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){ fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname); @@ -535,26 +539,25 @@ static void gravatmpf(const char *oldaccuser, const char *dirname, const char *o { FILE *fp_ou; - char wdirname[MAXLEN]; if(indexonly || (strstr(ReportType,"users_sites") == 0)) return; - strcpy(wdirname,tmp); - strcat(wdirname,"/"); - strcat(wdirname,oldaccuser); - strcat(wdirname,".utmp"); + if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,oldaccuser)>=sizeof(wdirname)) { + fprintf(stderr,"SARG: Path too long %s/%s.utmp\n",tmp,oldaccuser); + exit(1); + } if((fp_ou=MY_FOPEN(wdirname,"a"))==NULL){ fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname); exit(1); } - my_lltoa(nacc,val1,15); - my_lltoa(nbytes,val2,15); - my_lltoa(nelap,val3,15); - my_lltoa(incache,val4,15); - my_lltoa(oucache,val5,15); + my_lltoa(nacc,val1,0); + my_lltoa(nbytes,val2,0); + my_lltoa(nelap,val3,0); + my_lltoa(incache,val4,0); + my_lltoa(oucache,val5,0); fprintf(fp_ou,"%s\t%s\t%s\t%s\t%s\t%s\t%s\n",val1,val2,oldurl,oldmsg,val3,val4,val5); fclose(fp_ou); @@ -572,27 +575,14 @@ static void gravatmpf(const char *oldaccuser, const char *dirname, const char *o } -static void gravager(char *dirname, const char *user, long long int nacc, const char *url, long long int nbytes, const char *ip, const char *hora, const char *dia, long long int nelap, long long int incache, long long int oucache) +static void gravager(FILE *fp_gen, const char *user, long long int nacc, const char *url, long long int nbytes, const char *ip, const char *hora, const char *dia, long long int nelap, long long int incache, long long int oucache) { - - FILE *fp_ou; - - strcat(dirname,"/"); - strcat(dirname,"sarg-general"); - - if((fp_ou=MY_FOPEN(dirname,"a"))==NULL){ - fprintf(stderr, "SARG: (report) %s: %s\n",text[45],dirname); - exit(1); - } - - my_lltoa(nacc,val1,15); - my_lltoa(nbytes,val2,15); - my_lltoa(nelap,val3,15); - my_lltoa(incache,val4,15); - my_lltoa(oucache,val5,15); - fprintf(fp_ou,"%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",user,val1,val2,url,ip,hora,dia,val3,val4,val5); - - fclose(fp_ou); + my_lltoa(nacc,val1,0); + my_lltoa(nbytes,val2,0); + my_lltoa(nelap,val3,0); + my_lltoa(incache,val4,0); + my_lltoa(oucache,val5,0); + fprintf(fp_gen,"%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n",user,val1,val2,url,ip,hora,dia,val3,val4,val5); return; } @@ -601,7 +591,6 @@ static void grava_SmartFilter(const char *dirname, const char *user, const char { FILE *fp_ou; - char wdirname[MAXLEN]; sprintf(wdirname,"%s/smartfilter.unsort",dirname); diff --git a/sort.c b/sort.c index fc0caef..93622da 100644 --- a/sort.c +++ b/sort.c @@ -74,7 +74,7 @@ void tmpsort(void) if (dlen>0) { if (dlen>=sizeof(wnome)) continue; strncpy(wnome,direntp->d_name,dlen); - wnome[dlen]=0; + wnome[dlen]='\0'; } else { wnome[0]='\0'; } diff --git a/util.c b/util.c index 1a82b6b..a7feedc 100644 --- a/util.c +++ b/util.c @@ -134,65 +134,51 @@ int getword_skip(int limit, struct getwordstruct *gwarea, int stop) return(0); } - -#ifdef LEGACY_MY_ATOLL - -// BMG (bguillory@email.com) -// 3 August 1999 -long long int my_atoll (const char *nptr) -#define MAXLLL 30 //maximum number of digits in long long (a guess) +int getword_atoll(long long int *number, struct getwordstruct *gwarea, int stop) { - int offset=0, x; - long long int returnval=0; - char one_digit[2]; - - one_digit[1]='\0'; - - // Soak up all the white space - while (isspace(nptr[offset])) { - offset++; - } //while - - //For each character left to right - //change the character to a single digit - //multiply what we had before by 10 and add the new digit - for(x=offset; x<=MAXLLL+offset && isdigit(nptr[x]); x++) { - sprintf(one_digit, "%c", nptr[x]); //I don't know how else to do this - returnval = (returnval * 10) + atoi(one_digit); - } //for + int x; - return returnval; + *number=0LL; + for(x=0;isdigit(gwarea->current[x]);x++) { + *number=(*number * 10) + gwarea->current[x]-'0'; + } + if(gwarea->current[x] && gwarea->current[x]!=stop) { + printf("SARG: getword_atoll loop detected after %d bytes.\n",x); + printf("SARG: Line=\"%s\"\n",gwarea->beginning); + printf("SARG: Record=\"%s\"\n",gwarea->current); + printf("SARG: searching for \'x%x\'\n",stop); + //printf("SARG: Maybe you have a broken record or garbage in your access.log file.\n"); + return(-1); + } -} //my_atoll + if (gwarea->current[x]) ++x; + gwarea->current+=x; + return(0); +} -#else #define MAXLLL 30 //!< Maximum number of digits in long long (a guess). long long int my_atoll (const char *nptr) { - long long int returnval=0; - const char * t = nptr ; + long long int returnval=0LL; int max_digits = MAXLLL ; // Soak up all the white space - while (isspace( *t )) { - t++; - } //while + while (isspace( *nptr )) { + nptr++; + } //For each character left to right //change the character to a single digit //multiply what we had before by 10 and add the new digit - for( ; --max_digits && isdigit( *t ) ; t++ ) + while (--max_digits && isdigit( *nptr )) { - returnval = ( returnval * 10 ) + ( *t - '0' ) ; + returnval = ( returnval * 10 ) + ( *nptr++ - '0' ) ; } return returnval; - -} //my_atoll - -#endif +} static int is_absolute(const char *path) { @@ -247,33 +233,53 @@ void my_mkdir(const char *name) void my_lltoa(unsigned long long int n, char s[], int len) { - int i = 0; - int x = 0; - char ww[50]; - do { - s[i++] = (n % 10) + '0'; - } while ((n /= 10) > 0); - s[i] = '\0'; - { - int c,i,j; - for (i = 0, j = strlen(s)-1; isizeof(ww)?sizeof(ww):i); - strcpy(s,ww); - } + do { + s[slen++] = (n % 10) + '0'; + } while ((n /= 10) > 0); + s[slen] = '\0'; + + for (i = 0, j = slen-1; islen) { + i=len-slen; + for(j=slen; j>=0; j--) + s[j+i]=s[j]; + for(j=0 ; j 0); + s[slen] = '\0'; + for (i = 0, j = slen-1; isizeof(ww)?sizeof(ww):i); + strcpy(s,ww); + } +#endif } @@ -748,8 +754,7 @@ void gperiod(const char *dirname, const char *period) char wdirname[MAXLEN]; strcpy(wdirname,dirname); - strcat(wdirname,"/"); - strcat(wdirname,"sarg-period"); + strcat(wdirname,"/sarg-period"); if((fp_ou=fopen(wdirname,"w"))==NULL){ fprintf(stderr, "SARG: (report) %s: %s\n",text[45],wdirname);