From: Frédéric Marchal Date: Sun, 20 Dec 2009 20:06:18 +0000 (+0000) Subject: Download suffix stored in index with dichotomic search for efficiency. X-Git-Tag: v2_2_7~46 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6e792ade63afab731225ba993bf0f41526b81861;p=thirdparty%2Fsarg.git Download suffix stored in index with dichotomic search for efficiency. Added getword_atoll to extract a number without requiring an additionnal string buffer. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index c3e0725..7ab1455 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ PROJECT(sarg C) SET(sarg_VERSION 2) SET(sarg_REVISION 2) SET(sarg_BUILD "7rc1") -SET(sarg_BUILDDATE "Dec-18-2009") +SET(sarg_BUILDDATE "Dec-20-2009") INCLUDE(AddFileDependencies) INCLUDE(CheckIncludeFile) diff --git a/datafile.c b/datafile.c index be22a41..01a3335 100644 --- a/datafile.c +++ b/datafile.c @@ -33,10 +33,10 @@ void data_file(char *tmp) FILE *fp_in; - char accdia[11], acchora[9], accuser[MAXLEN], accip[MAXLEN], accurl[MAXLEN], accbytes[12], accelap[10]; + char accdia[11], acchora[9], accuser[MAXLEN], accip[MAXLEN], accurl[MAXLEN]; char oldaccdia[11], oldacchora[9], oldaccip[MAXLEN]; char dirname[MAXLEN], wdirname[MAXLEN], oldurl[MAXLEN], oldaccuser[MAXLEN]; - char olduser[MAXLEN], oldmsg[50], acccode[50], oldaccelap[10], oldacccode[50]; + char olduser[MAXLEN], oldmsg[50], acccode[50], oldacccode[50]; char ipantes[MAXLEN], nameantes[MAXLEN]; char accsmart[MAXLEN]; char crc2[50]; @@ -50,6 +50,8 @@ void data_file(char *tmp) long long int rtotal=0; long long int incache=0; long long int oucache=0; + long long int accbytes; + long long int accelap; struct getwordstruct gwarea; ipantes[0]='\0'; @@ -81,8 +83,8 @@ void data_file(char *tmp) getword_start(&gwarea,buf); if (getword(accdia,sizeof(accdia),&gwarea,' ')<0 || getword(acchora,sizeof(acchora),&gwarea,' ')<0 || getword(accuser,sizeof(accuser),&gwarea,' ')<0 || getword(accip,sizeof(accip),&gwarea,' ')<0 || - getword(accurl,sizeof(accurl),&gwarea,' ')<0 || getword(accbytes,sizeof(accbytes),&gwarea,' ')<0 || - getword(acccode,sizeof(acccode),&gwarea,' ')<0 || getword(accelap,sizeof(accelap),&gwarea,' ')<0 || + getword(accurl,sizeof(accurl),&gwarea,' ')<0 || getword_atoll(&accbytes,&gwarea,' ')<0 || + getword(acccode,sizeof(acccode),&gwarea,' ')<0 || getword_atoll(&accelap,&gwarea,' ')<0 || getword_skip(20000,&gwarea,' ')<0 || getword(accsmart,sizeof(accsmart),&gwarea,'"')<0) { printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp3); exit(1); @@ -100,7 +102,6 @@ void data_file(char *tmp) if(!rtotal){ strcpy(oldurl,accurl); strcpy(oldacccode,acccode); - strcpy(oldaccelap,accelap); strcpy(oldaccuser,accuser); strcpy(oldaccip,accip); strcpy(oldaccdia,accdia); @@ -123,20 +124,19 @@ void data_file(char *tmp) } nacc++; - nbytes+=my_atoll(accbytes); - nelap+=my_atoll(accelap); + nbytes+=accbytes; + nelap+=accelap; strcpy(crc2,acccode); str=strchr(crc2,'/'); if (str) *str='\0'; - if(strstr(crc2,"MISS") != 0) oucache+=my_atoll(accbytes); - else incache+=my_atoll(accbytes); + if(strstr(crc2,"MISS") != 0) oucache+=accbytes; + else incache+=accbytes; strcpy(oldurl,accurl); strcpy(oldaccuser,accuser); strcpy(oldacccode,acccode); - strcpy(oldaccelap,accelap); strcpy(oldaccip,accip); strcpy(oldaccdia,accdia); strcpy(oldacchora,acchora); diff --git a/documentation/download.txt b/documentation/download.txt new file mode 100644 index 0000000..7b500b1 --- /dev/null +++ b/documentation/download.txt @@ -0,0 +1,72 @@ +/*!\file download.c +\brief Report the downloaded files +*/ + + +/*! \var static char *DownloadSuffix=NULL; +The buffer to store the list of the suffixes to take into account when generating +the report of the downloaded files. The suffixes in the list are separated by the ASCII +null. +*/ + + + +/*! \var static char **DownloadSuffixIndex=NULL; +The index of all the suffixes stored in ::DownloadSuffix. The list is sorted alphabetically. +to speed up the search. +*/ + + +/*! \var static int NDownloadSuffix=0; +The number of suffixes in ::DownloadSuffixIndex. +*/ + + + +/*! \fn void download_report(void) +Generate the report of the downloaded files. The list of the suffixes to take into account +is set with set_download_suffix(). +*/ + + + +/*! \fn void free_download(void) +Free the memory allocated by set_download_suffix(). +*/ + + + +/*! \fn void set_download_suffix(const char *list) +Set the list of the suffixes corresponding to the download of files you want to detect with +is_download_suffix(). The list is sorted to make the search faster. + +\param list A comma separated list of the suffixes to set in ::DownloadSuffix. + +\note The memory allocated by this function must be freed by free_download(). +*/ + + + + + +/*! \fn int is_download_suffix(const char *url) +Tell if the URL correspond to a downloaded file. The function takes the extension at the end of the +URL with a maximum of 9 characters and compare it to the list of the download suffix in +::DownloadSuffix. If the suffix is found in the list, the function reports the URL as the download +of a file. + +\param url The URL to test. + +\retval 1 The URL matches a suffix of a download. +\retval 0 The URL is not a known download. + +\note A downloaded file cannot be detected if the file name is embedded in a GET or POST request. Only requests +that ends with the file name can be detected. + +\note A URL embedding another web site's address ending by .com at the end of the URL will match the download +extension com if it is defined in the ::DownloadSuffix. +*/ + + + + diff --git a/documentation/getconf.txt b/documentation/getconf.txt index 1b904d1..795b774 100644 --- a/documentation/getconf.txt +++ b/documentation/getconf.txt @@ -3,7 +3,7 @@ */ -/*! \fn static int isparam_string(const char *param,const char *buf) +/*! \fn static int is_param(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. diff --git a/documentation/util.txt b/documentation/util.txt index 04564a7..a61998f 100644 --- a/documentation/util.txt +++ b/documentation/util.txt @@ -396,7 +396,7 @@ bytes long. -/*! \fn void obttotal(const char *dirname, const char *name, char *tbytes, char *tuser, char *media) +/*! \fn void obttotal(const char *dirname, const char *name, char *tbytes, const char *tuser, char *media) Count the total size transfered in a connection directory and compute the average number of bytes per entry. @@ -802,28 +802,6 @@ The usertab file must have been read by read_usertab(). - -/*! \fn int is_download_suffix(const char *url) -Tell if the URL correspond to a downloaded file. The function takes the extension at the end of the -URL with a maximum of 9 characters and compare it to the list of the download suffix in -::DownloadSuffix. If the suffix is found in the list, the function reports the URL as the download -of a file. - -\param url The URL to test. - -\retval 1 The URL matches a suffix of a download. -\retval 0 The URL is not a known download. - -\note A downloaded file cannot be detected if the file name is embedded in a GET or POST request. Only requests -that ends with the file name can be detected. - -\note A URL embedding another web site's address ending by .com at the end of the URL will match the download -extension com if it is defined in the ::DownloadSuffix. -*/ - - - - /*! \fn void write_logo_image(FILE *fp_ou) Write a link of the logo of the organisation that generate the report in the HTML file. The logo is written in a centered table. diff --git a/download.c b/download.c index f0c61d5..92afee2 100644 --- a/download.c +++ b/download.c @@ -26,6 +26,10 @@ #include "include/conf.h" #include "include/defs.h" +static char *DownloadSuffix=NULL; +static char **DownloadSuffixIndex=NULL; +static int NDownloadSuffix=0; + void download_report(void) { @@ -177,3 +181,101 @@ void download_report(void) return; } + +void free_download(void) +{ + if (DownloadSuffix) { + free(DownloadSuffix); + DownloadSuffix=NULL; + } + if (DownloadSuffixIndex) { + free(DownloadSuffixIndex); + DownloadSuffixIndex=NULL; + } + NDownloadSuffix=0; +} + +void set_download_suffix(const char *list) +{ + char *str; + int i, j, k; + int cmp; + + free_download(); + + DownloadSuffix=strdup(list); + if (!DownloadSuffix) { + fprintf(stderr,"SARG: Download suffix list too long\n"); + exit(1); + } + j = 1; + for (i=0 ; list[i] ; i++) + if (list[i] == ',') j++; + DownloadSuffixIndex=malloc(j*sizeof(char *)); + if (!DownloadSuffixIndex) { + fprintf(stderr,"SARG: Too many download suffixes\n"); + exit(1); + } + + str = DownloadSuffix; + for (i=0 ; DownloadSuffix[i] ; i++) { + if (DownloadSuffix[i] == ',') { + DownloadSuffix[i] = '\0'; + if (*str) { + for (j=0 ; j0 ; j++); + if (cmp != 0) { + for (k=NDownloadSuffix ; k>j ; k--) + DownloadSuffixIndex[k]=DownloadSuffixIndex[k-1]; + NDownloadSuffix++; + DownloadSuffixIndex[j]=str; + } + } + str=DownloadSuffix+i+1; + } + } + + if (*str) { + for (j=0 ; j0 ; j++); + if (cmp != 0) { + for (k=NDownloadSuffix ; k>j ; k--) + DownloadSuffixIndex[k]=DownloadSuffixIndex[k-1]; + NDownloadSuffix++; + DownloadSuffixIndex[j]=str; + } + } +} + +int is_download_suffix(const char *url) +{ + int urllen; + int i; + int down, up, center; + const char *suffix; + int cmp; + const int max_suffix=10; + + if(DownloadSuffix == NULL || NDownloadSuffix == 0) return(0); + + urllen=strlen(url)-1; + if (urllen<=0) return(0); + if (url[urllen] == '.') return(0); //reject a single trailing dot + + for (i=0 ; i<=max_suffix && imax_suffix || i>=urllen) return(0); + + suffix=url+urllen-i+1; + down=0; + up=NDownloadSuffix-1; + while (down<=up) { + center=(down+up)/2; + cmp=strcasecmp(suffix,DownloadSuffixIndex[center]); + if (cmp == 0) return(1); + if (cmp < 0) + up = center-1; + else + down = center+1; + } + return(0); +} + diff --git a/getconf.c b/getconf.c index 9a85ae3..8bd916b 100644 --- a/getconf.c +++ b/getconf.c @@ -28,7 +28,7 @@ extern numlist hours, weekdays; -static int isparam_string(const char *param,const char *buf) +static int is_param(const char *param,const char *buf) { int plen; @@ -230,7 +230,7 @@ static void parmtest(char *buf) if (getparam_2words("user_sort_field",buf,UserSortField,sizeof(UserSortField),UserSortOrder,sizeof(UserSortOrder))>0) return; - if (isparam_string("access_log",buf)>0) { + if (is_param("access_log",buf)>0) { if (AccessLogFromCmdLine==0) { if (NAccessLog>=MAXLOGS) { fprintf(stderr,"SARG: Too many log files.\n"); @@ -377,7 +377,12 @@ static void parmtest(char *buf) if (getparam_string("Require",buf,Require,sizeof(Require))>0) return; - if (getparam_quoted("download_suffix",buf,DownloadSuffix,sizeof(DownloadSuffix))>0) return; + if (is_param("download_suffix",buf)) { + char warea[MAXLEN]; + + getparam_quoted("download_suffix",buf,warea,sizeof(warea)); + set_download_suffix(warea); + } if (getparam_string("graphs",buf,Graphs,sizeof(Graphs))>0) return; diff --git a/include/conf.h b/include/conf.h index 4f158e0..d60edee 100755 --- a/include/conf.h +++ b/include/conf.h @@ -280,7 +280,6 @@ char AuthUserFile[255]; char AuthName[512]; char AuthType[255]; char Require[512]; -char DownloadSuffix[MAXLEN]; char *userfile; char *str; char *str2; diff --git a/include/defs.h b/include/defs.h index 1bc7f60..7bebcf2 100755 --- a/include/defs.h +++ b/include/defs.h @@ -38,6 +38,9 @@ void gen_denied_report(void); // download.c void download_report(void); +void free_download(void); +void set_download_suffix(const char *list); +int is_download_suffix(const char *url); // email.c int geramail(const char *dirname, int debug, const char *outdir, int userip, const char *email, const char *TempDir); @@ -156,7 +159,7 @@ char *buildtime(long long int elap); void obtdate(const char *dirname, const char *name, char *data); void formatdate(char *date,int date_size,int year,int month,int day,int hour,int minute,int second,int dst); void obtuser(const char *dirname, const char *name, char *tuser); -void obttotal(const char *dirname, const char *name, char *tbytes, char *tuser, char *media); +void obttotal(const char *dirname, const char *name, char *tbytes, const char *tuser, char *media); void version(void); int vercode(const char *code); void load_excludecodes(const char *ExcludeCodes); @@ -175,4 +178,3 @@ char *get_param_value(const char *param,char *line); void read_usertab(const char *UserTabFile); void get_usertab_name(const char *user,char *name,int namelen); int compar( const void *, const void * ); -int is_download_suffix(const char *url); diff --git a/include/info.h b/include/info.h index c26ef74..e302479 100755 --- a/include/info.h +++ b/include/info.h @@ -1,3 +1,3 @@ -#define VERSION PACKAGE_VERSION" Dec-18-2009" +#define VERSION PACKAGE_VERSION" Dec-20-2009" #define PGM PACKAGE_NAME #define URL "http://sarg.sourceforge.net" diff --git a/log.c b/log.c index a7a1002..033acd8 100644 --- a/log.c +++ b/log.c @@ -215,7 +215,7 @@ int main(int argc,char *argv[]) strcpy(AuthName,"SARG, Restricted Access"); strcpy(AuthType,"basic"); strcpy(Require,"require user admin %u"); - strcpy(DownloadSuffix,"7z,ace,arj,avi,bat,bin,bz2,bzip,cab,com,cpio,dll,doc,dot,exe,gz,iso,lha,lzh,mdb,mov,mp3,mpeg,mpg,mso,nrg,ogg,ppt,rar,rtf,shs,src,sys,tar,tgz,vcd,vob,wma,wmv,zip"); + set_download_suffix("7z,ace,arj,avi,bat,bin,bz2,bzip,cab,com,cpio,dll,doc,dot,exe,gz,iso,lha,lzh,mdb,mov,mp3,mpeg,mpg,mso,nrg,ogg,ppt,rar,rtf,shs,src,sys,tar,tgz,vcd,vob,wma,wmv,zip"); strcpy(Graphs,"yes"); strcpy(Ulimit,"20000"); strcpy(NtlmUserFormat,"domainname+username"); @@ -1471,6 +1471,7 @@ int main(int argc,char *argv[]) free(excludefile); if(excludeuser) free(excludeuser); + free_download(); unlink(tmp4); unlink(tmp6); unlink(tmp3); @@ -1493,6 +1494,7 @@ int main(int argc,char *argv[]) free(excludefile); if(excludeuser) free(excludeuser); + free_download(); exit(0); } @@ -1597,6 +1599,7 @@ int main(int argc,char *argv[]) free(excludefile); if(excludeuser) free(excludeuser); + free_download(); if(debug) debuga("%s",text[21]); diff --git a/repday.c b/repday.c index bc61665..4cf2dae 100644 --- a/repday.c +++ b/repday.c @@ -36,8 +36,6 @@ void report_day(const char *user) char data[20]; char odata[20]; char hour[20]; - char elap[20]; - char oelap[20]; char html[8000]; char arqout[MAXLEN]; char wdirname[MAXLEN]; @@ -45,6 +43,7 @@ void report_day(const char *user) char c[ 24 ][20]; int count=0; int ihour=0; + long long int elap; long long int v[ 24 ] = { 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L }; long long int t[ 24 ] = { 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, @@ -136,14 +135,12 @@ void report_day(const char *user) count++; } - if (getword(hour,sizeof(hour),&gwarea,'\t')<0 || getword(elap,sizeof(elap),&gwarea,'\t')<0) { + if (getword(hour,sizeof(hour),&gwarea,'\t')<0 || getword_atoll(&elap,&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdirname); exit(1); } if(strcmp(data,odata) != 0) { - strcpy(oelap,elap); - for( i = 0; i < hours.len; i++ ) sprintf(c[ hours.list[ i ] ],"%s",fixtime(v[ hours.list[ i ] ])); @@ -159,15 +156,14 @@ void report_day(const char *user) tt=0; for( i = 0; i < hours.len; i++ ) v[ hours.list[ i ] ]=0; strcpy(odata,data); - strcpy(elap,oelap); } ihour=atoi(hour); - v[ ihour ]+=my_atoll(elap); - tt+=my_atoll(elap); - t[ ihour ]+=my_atoll(elap); - ttt+=my_atoll(elap); + v[ ihour ]+=elap; + tt+=elap; + t[ ihour ]+=elap; + ttt+=elap; } diff --git a/report.c b/report.c index f5e7d17..79e42dc 100644 --- a/report.c +++ b/report.c @@ -28,9 +28,9 @@ static void maketmp(const char *user, const char *dirname, int debug, int indexonly); static void maketmp_hour(const char *user, const char *dirname, int indexonly); -static void gravatmp_hora(const char *dirname, const char *user, const char *data, const char *hora, const char *elap, const char *accbytes, int indexonly); +static void gravatmp_hora(const char *dirname, const char *user, const char *data, const char *hora, long long int elap, long long int accbytes, int indexonly); static void gravatmpf(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); -static void gravaporuser(const char *user, const char *dirname, const char *url, const char *ip, const char *data, const char *hora, const char *tam, const char *elap, int indexonly); +static void gravaporuser(const char *user, const char *dirname, const char *url, const char *ip, const char *data, const char *hora, long long int tam, long long int elap, int indexonly); 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); static void grava_SmartFilter(const char *dirname, const char *user, const char *ip, const char *data, const char *hora, const char *url, const char *smart); @@ -40,10 +40,10 @@ void gerarel(void) FILE *fp_in; FILE *fp_gen; - char accdia[11], acchora[9], accuser[MAXLEN], accip[MAXLEN], accurl[MAXLEN], accbytes[12], accelap[10]; + char accdia[11], acchora[9], accuser[MAXLEN], accip[MAXLEN], accurl[MAXLEN]; char oldaccdia[11], oldacchora[9], oldaccip[MAXLEN], wdir[MAXLEN], per1[MAXLEN]; char wdirname[MAXLEN], oldurl[MAXLEN], oldaccuser[MAXLEN]; - char olduser[MAXLEN], oldmsg[50], acccode[MAXLEN/2 - 1], oldaccelap[10], oldacccode[MAXLEN/2 - 1], user[MAXLEN]; + char olduser[MAXLEN], oldmsg[50], acccode[MAXLEN/2 - 1], oldacccode[MAXLEN/2 - 1], user[MAXLEN]; char ipantes[MAXLEN], nameantes[MAXLEN]; char accsmart[MAXLEN]; char crc2[MAXLEN/2 -1]; @@ -54,6 +54,7 @@ void gerarel(void) long long int rtotal=0; long long int incache=0; long long int oucache=0; + long long int accbytes, accelap; char *str; DIR *dirp; struct dirent *direntp; @@ -135,13 +136,13 @@ void gerarel(void) getword_start(&gwarea,buf); if (getword(accdia,sizeof(accdia),&gwarea,'\t')<0 || getword(acchora,sizeof(acchora),&gwarea,'\t')<0 || getword(accuser,sizeof(accuser),&gwarea,'\t')<0 || getword(accip,sizeof(accip),&gwarea,'\t')<0 || - getword(accurl,sizeof(accurl),&gwarea,'\t')<0 || getword(accbytes,sizeof(accbytes),&gwarea,'\t')<0 || + getword(accurl,sizeof(accurl),&gwarea,'\t')<0 || getword_atoll(&accbytes,&gwarea,'\t')<0 || getword(acccode,sizeof(acccode),&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp3); exit(1); } if(strncmp(acccode,"TCP_DENIED/407",14) == 0) continue; - if (getword(accelap,sizeof(accelap),&gwarea,'\t')<0 || getword_skip(20000,&gwarea,'\t')<0 || + if (getword_atoll(&accelap,&gwarea,'\t')<0 || getword_skip(20000,&gwarea,'\t')<0 || getword(accsmart,sizeof(accsmart),&gwarea,'"')<0) { printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",tmp3); exit(1); @@ -172,7 +173,6 @@ void gerarel(void) if(!rtotal){ strcpy(oldurl,accurl); strcpy(oldacccode,acccode); - strcpy(oldaccelap,accelap); strcpy(oldaccuser,accuser); strcpy(oldaccip,accip); strcpy(oldaccdia,accdia); @@ -210,8 +210,8 @@ void gerarel(void) } } nacc++; - nbytes+=my_atoll(accbytes); - nelap+=my_atoll(accelap); + nbytes+=accbytes; + nelap+=accelap; if(strstr(ReportType,"site_user_time_date") != 0) { if(!ttopen) { @@ -286,8 +286,8 @@ void gerarel(void) if (str) *str='\0'; if(strstr(crc2,"MISS") != 0) - oucache+=my_atoll(accbytes); - else incache+=my_atoll(accbytes); + oucache+=accbytes; + else incache+=accbytes; strcpy(oldurl,accurl); @@ -298,7 +298,6 @@ void gerarel(void) strcpy(oldaccuser,accuser); strcpy(oldacccode,acccode); - strcpy(oldaccelap,accelap); strcpy(oldaccip,accip); strcpy(oldaccdia,accdia); strcpy(oldacchora,acchora); @@ -481,7 +480,7 @@ void gravatmp(const char *oldaccuser, const char *oldurl, long long int nacc, lo } -static void gravatmp_hora(const char *dirname, const char *user, const char *data, const char *hora, const char *elap, const char *bytes, int indexonly) +static void gravatmp_hora(const char *dirname, const char *user, const char *data, const char *hora, long long int elap, long long int bytes, int indexonly) { FILE *fp_ou; @@ -499,8 +498,8 @@ static void gravatmp_hora(const char *dirname, const char *user, const char *dat exit(1); } - if(strcmp(datetimeby,"bytes") == 0) fprintf(fp_ou,"%s\t%s\t%s\n",data,hora,bytes); - else fprintf(fp_ou,"%s\t%s\t%s\n",data,hora,elap); + if(strcmp(datetimeby,"bytes") == 0) fprintf(fp_ou,"%s\t%s\t%lld\n",data,hora,bytes); + else fprintf(fp_ou,"%s\t%s\t%lld\n",data,hora,elap); fclose(fp_ou); @@ -508,7 +507,7 @@ static void gravatmp_hora(const char *dirname, const char *user, const char *dat } -static void gravaporuser(const char *user, const char *dirname, const char *url, const char *ip, const char *data, const char *hora, const char *tam, const char *elap, int indexonly) +static void gravaporuser(const char *user, const char *dirname, const char *url, const char *ip, const char *data, const char *hora, long long int tam, long long int elap, int indexonly) { FILE *fp_ou; @@ -526,7 +525,7 @@ static void gravaporuser(const char *user, const char *dirname, const char *url, exit(1); } - fprintf(fp_ou,"%s\t%s\t%s\t%s\t%s\t%s\n",ip,url,data,hora,tam,elap); + fprintf(fp_ou,"%s\t%s\t%s\t%s\t%lld\t%lld\n",ip,url,data,hora,tam,elap); fclose(fp_ou); diff --git a/siteuser.c b/siteuser.c index 6afde00..be36d9a 100644 --- a/siteuser.c +++ b/siteuser.c @@ -35,9 +35,6 @@ void siteuser(void) char url[MAXLEN]; char wuser[MAXLEN]; char ourl[MAXLEN]; - char nacc[20]; - char nbytes[20]; - char obytes[20]; char csort[255]; char general[MAXLEN]; char general2[MAXLEN]; @@ -48,7 +45,9 @@ void siteuser(void) int regs=0; int ucount=0; char *users; - long long int llbytes=0; + long long int nbytes; + long long int obytes; + long long int nacc; int cstatus; struct getwordstruct gwarea; @@ -120,7 +119,7 @@ void siteuser(void) user[0]='\0'; ourl[0]='\0'; - obytes[0]='\0'; + obytes=0; if((users=(char *) malloc(204800))==NULL){ fprintf(stderr, "SARG: ERROR: %s",text[87]); @@ -160,12 +159,12 @@ void siteuser(void) ip2name(user,sizeof(user)); */ - if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0){ + if (getword_atoll(&nacc,&gwarea,'\t')<0){ printf("SARG: Maybe you have an invalid number of access in your %s file of the siteuser.\n",general2); exit(1); } - if (atoi(nacc) > 0) nsitesusers = 1; - if (getword(nbytes,sizeof(nbytes),&gwarea,'\t')<0){ + if (nacc > 0) nsitesusers = 1; + if (getword_atoll(&nbytes,&gwarea,'\t')<0){ printf("SARG: Maybe you have an invalid number of bytes in your %s file of the siteuser.\n",general2); exit(1); } @@ -176,7 +175,7 @@ void siteuser(void) if(!regs) { strcpy(ourl,url); - strcpy(obytes,nbytes); + obytes=nbytes; regs++; } @@ -202,8 +201,7 @@ void siteuser(void) if(strcmp(url,ourl) != 0 && nsitesusers) { if(strncmp(strlow(BytesInSitesUsersReport),"yes",3) == 0) { - llbytes=my_atoll(obytes); - sprintf(wwork2,"%s",fixnum(llbytes,1)); + sprintf(wwork2,"%s",fixnum(obytes,1)); fprintf(fp_ou,"%d%s%s%s%s\n",regs,BlockImage,ourl,ourl,wwork2,users); } else fprintf(fp_ou,"%d%s%s%s\n",regs,BlockImage,ourl,ourl,users); @@ -212,7 +210,7 @@ void siteuser(void) strcpy(users,name); strcat(users," "); strcpy(ourl,url); - strcpy(obytes,nbytes); + obytes=nbytes; } } diff --git a/topsites.c b/topsites.c index f9c6739..36a76f4 100644 --- a/topsites.c +++ b/topsites.c @@ -33,9 +33,6 @@ void topsites(void) char url[MAXLEN]; char ourl[MAXLEN]; - char nacc[20]; - char nbytes[20]; - char ntime[20]; char ntemp[255]; char ttnacc[20]; char ttnbytes[20]; @@ -50,6 +47,9 @@ void topsites(void) char period[100]; char sortf[10]; char sortt[10]; + long long int nacc; + long long int nbytes; + long long int ntime; long long int tnacc=0; long long int tnbytes=0; long long int tntime=0; @@ -123,11 +123,11 @@ void topsites(void) } continue; } - if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0) { + if (getword_atoll(&nacc,&gwarea,'\t')<0) { printf("SARG: Maybe you have an invalid number of access in your %s file of the topsites.\n",general2); exit(1); } - if (getword(nbytes,sizeof(nbytes),&gwarea,'\t')<0) { + if (getword_atoll(&nbytes,&gwarea,'\t')<0) { printf("SARG: Maybe you have an invalid number of bytes in your %s file of the topsites.\n",general2); exit(1); } @@ -147,7 +147,7 @@ void topsites(void) printf("SARG: Maybe you have a broken record or garbage in column 7 in your %s file of the topsites.\n",general2); exit(1); } - if (getword(ntime,sizeof(ntime),&gwarea,'\t')<0) { + if (getword_atoll(&ntime,&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken record or garbage in column 8 in your %s file of the topsites.\n",general2); exit(1); } @@ -168,9 +168,9 @@ void topsites(void) tntime=0; } - tnacc+=my_atoll(nacc); - tnbytes+=my_atoll(nbytes); - tntime+=my_atoll(ntime); + tnacc+=nacc; + tnbytes+=nbytes; + tntime+=ntime; } my_lltoa(tnacc,val1,15); @@ -249,20 +249,20 @@ void topsites(void) if(regs>atoi(TopSitesNum)) break; getword_start(&gwarea,buf); - if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0) { + if (getword_atoll(&nacc,&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",sites); exit(1); } - if (atoi(nacc) == 0) continue; - if (getword(nbytes,sizeof(nbytes),&gwarea,'\t')<0 || - getword(ntime,sizeof(ntime),&gwarea,'\t')<0 || getword(url,sizeof(url),&gwarea,'\t')<0) { + if (nacc == 0) continue; + if (getword_atoll(&nbytes,&gwarea,'\t')<0 || + getword_atoll(&ntime,&gwarea,'\t')<0 || getword(url,sizeof(url),&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",sites); exit(1); } - twork1=my_atoll(nacc); - twork2=my_atoll(nbytes); - twork3=my_atoll(ntime); + twork1=nacc; + twork2=nbytes; + twork3=ntime; strcpy(wwork1,fixnum(twork1,1)); strcpy(wwork2,fixnum(twork2,1)); diff --git a/topuser.c b/topuser.c index be3b717..bf64787 100644 --- a/topuser.c +++ b/topuser.c @@ -35,14 +35,17 @@ void topuser(void) long long int tnincache=0, tnoucache=0, ttnincache=0, ttnoucache=0; long long int twork; long long int twork2; + long long int nbytes; + long long int nacc; + long long int elap, incac, oucac; float perc=0.00; float perc2=0.00; float inperc=0.00, ouperc=0.00; int posicao=0; char olduser[MAXLEN], csort[MAXLEN], period[MAXLEN], arqper[MAXLEN]; char wger[MAXLEN], top1[MAXLEN], top2[MAXLEN], top3[MAXLEN]; - char user[MAXLEN], nacc[20], nbytes[20], preg[MAXLEN], tusr[MAXLEN]; - char ip[MAXLEN], time[30], date[30], elap[30], incac[30], oucac[30]; + char user[MAXLEN], preg[MAXLEN], tusr[MAXLEN]; + char ip[MAXLEN], time[30], date[30]; char ipantes[MAXLEN], nameantes[MAXLEN]; char sfield[10]="2,2"; char order[255]="-r"; @@ -99,11 +102,11 @@ void topuser(void) if(strcmp(user,"TOTAL") == 0) { continue; } - if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0) { + if (getword_atoll(&nacc,&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken number of access in your %s file.\n",wger); exit(1); } - if (getword(nbytes,sizeof(nbytes),&gwarea,'\t')<0) { + if (getword_atoll(&nbytes,&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",wger); exit(1); } @@ -123,15 +126,15 @@ void topuser(void) printf("SARG: Maybe you have a broken date in your %s file.\n",wger); exit(1); } - if (getword(elap,sizeof(elap),&gwarea,'\t')<0) { + if (getword_atoll(&elap,&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken download duration in your %s file.\n",wger); exit(1); } - if (getword(incac,sizeof(incac),&gwarea,'\t')<0) { + if (getword_atoll(&incac,&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken in cache download in your %s file.\n",wger); exit(1); } - if (getword(oucac,sizeof(oucac),&gwarea,'\t')<0) { + if (getword_atoll(&oucac,&gwarea,'\n')<0) { printf("SARG: Maybe you have a broken not in cache download in your %s file.\n",wger); exit(1); } @@ -160,11 +163,11 @@ void topuser(void) tnoucache=0; } - tnbytes+=my_atoll(nbytes); - tnacc+=my_atoll(nacc); - tnelap+=my_atoll(elap); - tnincache+=my_atoll(incac); - tnoucache+=my_atoll(oucac); + tnbytes+=nbytes; + tnacc+=nacc; + tnelap+=elap; + tnincache+=incac; + tnoucache+=oucac; } if (olduser[0] != '\0') { @@ -373,51 +376,51 @@ void topuser(void) printf("SARG: Maybe you have a broken user in your %s file.\n",top1); exit(1); } - if (getword(nbytes,sizeof(nbytes),&gwarea,'\t')<0) { + if (getword_atoll(&nbytes,&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",top1); exit(1); } - if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0) { + if (getword_atoll(&nacc,&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken number of access in your %s file.\n",top1); exit(1); } - if (getword(elap,sizeof(elap),&gwarea,'\t')<0) { + if (getword_atoll(&elap,&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken elpased time in your %s file.\n",wger); exit(1); } - if (getword(incac,sizeof(incac),&gwarea,'\t')<0) { + if (getword_atoll(&incac,&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken in-cache size in your %s file.\n",wger); exit(1); } - if (getword(oucac,sizeof(oucac),&gwarea,'\t')<0) { + if (getword_atoll(&oucac,&gwarea,'\n')<0) { printf("SARG: Maybe you have a broken out-of-cache size in your %s file.\n",wger); exit(1); } - if(atoi(nacc) < 1) { + if(nacc < 1) { continue; } ntopuser = 1; if(TopUsersNum > 0 && topcount >= TopUsersNum) goto final; strcpy(user2,user); - tnbytes=my_atoll(nbytes); + tnbytes=nbytes; if(tnbytes) { perc=tnbytes * 100; perc=perc / ttnbytes; } else perc = 0; - if(atol(elap)) { - perc2=atol(elap); + if(elap) { + perc2=elap; perc2=((perc2 * 100) / ttnelap); } else perc2 = 0; - if(atol(incac)) { - inperc=atol(incac); + if(incac) { + inperc=incac; inperc=((inperc * 100) / tnbytes); } else inperc = 0; - if(atol(oucac)) { - ouperc=atol(oucac); + if(oucac) { + ouperc=oucac; ouperc=((ouperc * 100) / tnbytes); } else ouperc = 0; @@ -443,7 +446,7 @@ void topuser(void) strcpy(href3end,""); } - tnelap=my_atoll(elap); + tnelap=elap; if(userip) { fixip(user2); @@ -479,9 +482,7 @@ void topuser(void) name[0]='\0'; } - twork=my_atoll(nacc); - my_lltoa(twork,nacc,0); - strcpy(wwork1,fixnum(twork,1)); + strcpy(wwork1,fixnum(nacc,1)); strcpy(wwork2,fixnum(tnbytes,1)); strcpy(wwork3,fixnum2(tnelap,1)); @@ -564,14 +565,14 @@ void topuser(void) if(strstr(user,"TOTAL") != 0) { - if(atol(incac)) { + if(incac) { inperc=ttnbytes / 100; - inperc=atol(incac) / inperc; + inperc=incac / inperc; } else inperc = 0; - if(atol(oucac)) { + if(oucac) { ouperc=ttnbytes / 100; - ouperc=atol(oucac) / ouperc; + ouperc=oucac / ouperc; } else ouperc = 0; sprintf(wwork1,"%s",fixnum(ttnacc,1)); diff --git a/totger.c b/totger.c index 1324072..5bd886d 100644 --- a/totger.c +++ b/totger.c @@ -33,9 +33,11 @@ int totalger(const char *dirname, int debug, const char *outdir) long long int tnbytes=0; long long int telap=0; long long int tincache=0, toucache=0; - char wger[MAXLEN], user[MAXLEN], nacc[16], nbytes[16], url[MAXLEN]; - char ip[MAXLEN], hora[9], data[15], elap[16]; - char incac[30], oucac[30]; + long long int nacc, nbytes; + long long int elap; + long long int incac, oucac; + char wger[MAXLEN], user[MAXLEN], url[MAXLEN]; + char ip[MAXLEN], hora[9], data[15]; char warea[MAXLEN]; struct getwordstruct gwarea; @@ -55,11 +57,11 @@ int totalger(const char *dirname, int debug, const char *outdir) printf("SARG: Maybe you have a broken user in your %s file.\n",wger); exit(1); } - if (getword(nacc,sizeof(nacc),&gwarea,'\t')<0) { + if (getword_atoll(&nacc,&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken number of access in your %s file.\n",wger); exit(1); } - if (getword(nbytes,sizeof(nbytes),&gwarea,'\t')<0) { + if (getword_atoll(&nbytes,&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken number of bytes in your %s file.\n",wger); exit(1); } @@ -79,23 +81,23 @@ int totalger(const char *dirname, int debug, const char *outdir) printf("SARG: Maybe you have a broken date in your %s file.\n",wger); exit(1); } - if (getword(elap,sizeof(elap),&gwarea,'\t')<0) { + if (getword_atoll(&elap,&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken elapsed time in your %s file.\n",wger); exit(1); } - if (getword(incac,sizeof(incac),&gwarea,'\t')<0) { + if (getword_atoll(&incac,&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken in cache column in your %s file.\n",wger); exit(1); } - if (getword(oucac,sizeof(oucac),&gwarea,0)<0) { + if (getword_atoll(&oucac,&gwarea,'\n')<0) { printf("SARG: Maybe you have a broken not in cache column in your %s file.\n",wger); exit(1); } - tnacc+=my_atoll(nacc); - tnbytes+=my_atoll(nbytes); - telap+=my_atoll(elap); - tincache+=my_atoll(incac); - toucache+=my_atoll(oucac); + tnacc+=nacc; + tnbytes+=nbytes; + telap+=elap; + tincache+=incac; + toucache+=oucac; } fclose(fp_in); diff --git a/util.c b/util.c index a7feedc..f48754c 100644 --- a/util.c +++ b/util.c @@ -256,30 +256,6 @@ void my_lltoa(unsigned long long int n, char s[], int len) for(j=0 ; j 0); - s[slen] = '\0'; - - for (i = 0, j = slen-1; isizeof(ww)?sizeof(ww):i); - strcpy(s,ww); - } -#endif } @@ -692,12 +668,12 @@ void obtuser(const char *dirname, const char *name, char *tuser) } -void obttotal(const char *dirname, const char *name, char *tbytes, char *tuser, char *media) +void obttotal(const char *dirname, const char *name, char *tbytes, const char *tuser, char *media) { - FILE *fp_in; char buf[MAXLEN]; char wdir[MAXLEN]; + char warea[MAXLEN]; long long int med=0; long long int wtuser=0; long long int twork; @@ -707,7 +683,8 @@ void obttotal(const char *dirname, const char *name, char *tbytes, char *tuser, if ((fp_in = fopen(wdir, "r")) == 0) { sprintf(wdir,"%s%s/general",dirname,name); if ((fp_in = fopen(wdir, "r")) == 0) { - tbytes=0; + tbytes[0]='\0'; + media[0]='\0'; return; } } @@ -724,12 +701,12 @@ void obttotal(const char *dirname, const char *name, char *tbytes, char *tuser, printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir); exit(1); } - if (getword(warea,sizeof(warea),&gwarea,'\t')<0) { + if (getword_atoll(&twork,&gwarea,'\t')<0) { printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",wdir); exit(1); } - twork=my_atoll(warea); strcpy(tbytes,fixnum(twork,1)); + break; } fclose(fp_in); @@ -739,11 +716,10 @@ void obttotal(const char *dirname, const char *name, char *tbytes, char *tuser, return; } - med=my_atoll(warea) / wtuser; + med=twork / wtuser; strcpy(media,fixnum(med,1)); return; - } @@ -1606,31 +1582,3 @@ void get_usertab_name(const char *user,char *name,int namelen) } } } - -int is_download_suffix(const char *url) -{ - int urllen; - int i; - char suffix[10]; - const char *str; - int suflen; - - if(DownloadSuffix[0]==0) return(0); - - urllen=strlen(url)-1; - for (i=0 ; i