From: Frédéric Marchal Date: Thu, 27 Jan 2011 15:26:45 +0000 (+0000) Subject: Factorisation of the usage of indexonly X-Git-Tag: v2.3.2~88 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6588b1372885d667b40e0af155342bf46b42e2fa;p=thirdparty%2Fsarg.git Factorisation of the usage of indexonly Several functions were called and then decided to return immediately if indexonly was set. Most of those functions were called once or twice but never from more than one place. This change let the calling function decide if the call must be made based on the value of indexonly which is always known. The gain is mainly a reduction of the number of parameters passed to a few functions. It also makes the code more readable as it is not necessary to dig into the function to discover that it does nothing in that case. --- diff --git a/include/conf.h b/include/conf.h index 2d5546c..c486c45 100755 --- a/include/conf.h +++ b/include/conf.h @@ -442,7 +442,7 @@ int isalog; int dfrom; int duntil; int dataonly; -int indexonly; +bool indexonly; bool iprel; int langcode; int debug; diff --git a/include/defs.h b/include/defs.h index 72ee35e..de69ec5 100755 --- a/include/defs.h +++ b/include/defs.h @@ -188,7 +188,7 @@ void topsites(void); void topuser(void); // totday.c -void day_totalize(const char *tmp, const struct userinfostruct *uinfo, int indexonly); +void day_totalize(const char *tmp, const struct userinfostruct *uinfo); // usage.c void usage(const char *prog); diff --git a/log.c b/log.c index 71a7aeb..6298e8e 100644 --- a/log.c +++ b/log.c @@ -605,13 +605,13 @@ int main(int argc,char *argv[]) fuser=true; } - indexonly=0; + indexonly=false; if(fuser) { if(is_indexonly()) - indexonly++; + indexonly=true; } - if(strcmp(ExcludeUsers,"indexonly") == 0) indexonly++; - if(Index == INDEX_ONLY) indexonly++; + if(strcmp(ExcludeUsers,"indexonly") == 0) indexonly=true; + if(Index == INDEX_ONLY) indexonly=true; if(MaxElapsed[0] != '\0') max_elapsed=atol(MaxElapsed); diff --git a/report.c b/report.c index 5671cdf..2f86740 100644 --- a/report.c +++ b/report.c @@ -32,11 +32,11 @@ struct globalstatstruct globstat; static FILE *fp_tt=NULL; -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 struct userinfostruct *uinfo, const char *data, const char *hora, long long int elap, long long int accbytes, int indexonly); -static void gravatmp(const struct userinfostruct *uinfo, 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 struct userinfostruct *uinfo, 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 maketmp(const char *user, const char *dirname, int debug); +static void maketmp_hour(const char *user, const char *dirname); +static void gravatmp_hora(const char *dirname, const struct userinfostruct *uinfo, const char *data, const char *hora, long long int elap, long long int accbytes); +static void gravatmp(const struct userinfostruct *uinfo, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, long long int incache, long long int oucache); +static void gravaporuser(const struct userinfostruct *uinfo, const char *dirname, const char *url, const char *ip, const char *data, const char *hora, long long int tam, long long int elap); static void gravager(FILE *fp_gen,const char *filename, const struct userinfostruct *uinfo, 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); @@ -131,8 +131,10 @@ void gerarel(void) } user_find(uinfo->label,MAX_USER_LEN, u2); - maketmp(user,tmp,debug,indexonly); - maketmp_hour(user,tmp,indexonly); + if (!indexonly) { + maketmp(user,tmp,debug); + maketmp_hour(user,tmp); + } ttopen=0; oldurltt=NULL; @@ -178,10 +180,10 @@ void gerarel(void) } else strcpy(accip,nameantes); } - gravatmp_hora(outdirname,uinfo,accdia,acchora,accelap,accbytes,indexonly); + if (!indexonly) { + gravatmp_hora(outdirname,uinfo,accdia,acchora,accelap,accbytes); - if(iprel){ - gravaporuser(uinfo,outdirname,accurl,accip,accdia,acchora,accbytes,accelap,indexonly); + if(iprel) gravaporuser(uinfo,outdirname,accurl,accip,accdia,acchora,accbytes,accelap); } if(!rtotal){ @@ -211,7 +213,7 @@ void gerarel(void) strcpy(oldmsg,"DENIED"); else strcpy(oldmsg,"OK"); - gravatmp(puinfo,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache); + if (!indexonly) gravatmp(puinfo,oldurl,nacc,nbytes,oldmsg,nelap,incache,oucache); gravager(fp_gen,wdirname,puinfo,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache); nacc=0; nbytes=0; @@ -225,7 +227,7 @@ void gerarel(void) strcpy(oldmsg,"DENIED"); else strcpy(oldmsg,"OK"); - gravatmp(puinfo,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache); + if (!indexonly) gravatmp(puinfo,oldurl,nacc,nbytes,oldmsg,nelap,incache,oucache); gravager(fp_gen,wdirname,puinfo,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache); nacc=0; nbytes=0; @@ -302,7 +304,7 @@ void gerarel(void) if(new_user) { new_user=0; - day_totalize(tmp,puinfo,indexonly); + if (!indexonly) day_totalize(tmp,puinfo); } puinfo=uinfo; @@ -339,15 +341,15 @@ void gerarel(void) strcpy(oldmsg,"DENIED"); else strcpy(oldmsg,"OK"); - gravatmp(puinfo,oldurl,nacc,nbytes,oldmsg,nelap,indexonly,incache,oucache); + if (!indexonly) gravatmp(puinfo,oldurl,nacc,nbytes,oldmsg,nelap,incache,oucache); gravager(fp_gen,wdirname,puinfo,nacc,oldurl,nbytes,oldaccip,oldacchora,oldaccdia,nelap,incache,oucache); free(oldurl); } totalger(fp_gen,wdirname); fclose(fp_gen); - if (puinfo) day_totalize(tmp,puinfo,indexonly); + if (puinfo && !indexonly) day_totalize(tmp,puinfo); - tmpsort(); + if (!indexonly) tmpsort(); if(email[0] == '\0') { if((ReportType & REPORT_TYPE_DOWNLOADS) != 0) download_report(); @@ -385,20 +387,17 @@ void gerarel(void) debuga(_("Successful report generated and sent to %s\n"),email); } - if(indexonly) { - index_only(outdirname, debug); - } + if(indexonly) index_only(outdirname, debug); removetmp(outdirname); return; } -static void maketmp(const char *user, const char *dirname, int debug, int indexonly) +static void maketmp(const char *user, const char *dirname, int debug) { FILE *fp_ou; char wdirname[MAXLEN]; - if(indexonly) return; if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return; if(debug) debuga(_("Making file: %s/%s\n"),tmp,user); @@ -417,12 +416,11 @@ static void maketmp(const char *user, const char *dirname, int debug, int indexo } -static void maketmp_hour(const char *user, const char *dirname, int indexonly) +static void maketmp_hour(const char *user, const char *dirname) { FILE *fp_ou; char wdirname[MAXLEN]; - if(indexonly) return; if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return; if(datetimeby==0) return; @@ -441,12 +439,11 @@ static void maketmp_hour(const char *user, const char *dirname, int indexonly) } -static void gravatmp(const struct userinfostruct *uinfo, 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 gravatmp(const struct userinfostruct *uinfo, const char *oldurl, long long int nacc, long long int nbytes, const char *oldmsg, long long int nelap, long long int incache, long long int oucache) { FILE *fp_ou; char wdirname[MAXLEN]; - if(indexonly) return; if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return; if (snprintf(wdirname,sizeof(wdirname),"%s/%s.utmp",tmp,uinfo->filename)>=sizeof(wdirname)) { @@ -481,13 +478,13 @@ static void gravatmp(const struct userinfostruct *uinfo, const char *oldurl, lon return; } -static void gravatmp_hora(const char *dirname, const struct userinfostruct *uinfo, const char *data, const char *hora, long long int elap, long long int bytes, int indexonly) +static void gravatmp_hora(const char *dirname, const struct userinfostruct *uinfo, const char *data, const char *hora, long long int elap, long long int bytes) { FILE *fp_ou; char wdirname[MAXLEN]; int hour; - if(indexonly || ((ReportType & REPORT_TYPE_USERS_SITES) == 0) || datetimeby==0) return; + if(((ReportType & REPORT_TYPE_USERS_SITES) == 0) || datetimeby==0) return; if (snprintf(wdirname,sizeof(wdirname),"%s/%s.htmp",tmp,uinfo->filename)>=sizeof(wdirname)) { debuga(_("Path too long %s/%s.htmp\n"),tmp,uinfo->filename); @@ -514,12 +511,12 @@ static void gravatmp_hora(const char *dirname, const struct userinfostruct *uinf } -static void gravaporuser(const struct userinfostruct *uinfo, 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 gravaporuser(const struct userinfostruct *uinfo, const char *dirname, const char *url, const char *ip, const char *data, const char *hora, long long int tam, long long int elap) { FILE *fp_ou; char wdirname[MAXLEN]; - if(indexonly || ((ReportType & REPORT_TYPE_USERS_SITES) == 0)) return; + if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return; if (snprintf(wdirname,sizeof(wdirname),"%s/%s.ip",tmp,uinfo->filename)>=sizeof(wdirname)) { debuga(_("Path too long %s/%s.ip\n"),tmp,uinfo->filename); diff --git a/sort.c b/sort.c index 3a855d5..1247c67 100644 --- a/sort.c +++ b/sort.c @@ -39,7 +39,6 @@ void tmpsort(void) const char *field3="3,3"; const char *order; - if(indexonly) return; if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return; if((UserSort & USER_SORT_CONNECT) != 0) { diff --git a/totday.c b/totday.c index 10d8a0e..0b7ca3a 100644 --- a/totday.c +++ b/totday.c @@ -27,7 +27,7 @@ #include "include/conf.h" #include "include/defs.h" -void day_totalize(const char *tmp, const struct userinfostruct *uinfo, int indexonly) +void day_totalize(const char *tmp, const struct userinfostruct *uinfo) { FILE *fp_in, *fp_ou; @@ -49,7 +49,6 @@ void day_totalize(const char *tmp, const struct userinfostruct *uinfo, int index char colsep; struct getwordstruct gwarea; - if(indexonly) return; if((ReportType & REPORT_TYPE_USERS_SITES) == 0) return; if (datetimeby==0) return;