From: Frédéric Marchal Date: Mon, 21 Dec 2009 20:29:39 +0000 (+0000) Subject: Use boolean to enable some options instead of string compares X-Git-Tag: v2_2_7~44 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=246c8489804e2c2d10c00d9d564c961278c1fe16;p=thirdparty%2Fsarg.git Use boolean to enable some options instead of string compares --- diff --git a/ChangeLog b/ChangeLog index b16d334..8213261 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,12 +1,16 @@ SARG ChangeLog -Dec-18-2009 Version 2.2.7 +Dec-21-2009 Version 2.2.7 - Extra compile and run time protection (FORTIFY_SOURCE) fixed in configure. - Use tabulations as columns separator in intermediary files to avoid problems when a field of the log contains a space. - Input log file type detection partly rewritten to clearly distinguish which type is processed where. - Read the input log file from standard input if log file name is -. - Use string pointers in getword instead of copying the strings over and over. - Use LC_TIME to format some dates and times in the report according to the selected locale. + - Sarg.conf can list up to 255 access.log files. + - Downloaded files suffixes are matched against a sorted list and use a dicchotomic search. + - Added getword_atoll to read a number directly from a file without an intermediary string storage. + - Use boolean to enable some options instead of string compares. Dec-17-2009 Version 2.2.6.1 - Remove unecessary dependency on off_t. diff --git a/authfail.c b/authfail.c index b27287d..3eb07b5 100644 --- a/authfail.c +++ b/authfail.c @@ -131,7 +131,7 @@ void authfail_report(void) fixip(user); } - if(strcmp(Ip2Name,"yes") == 0) + if(Ip2Name) ip2name(ip,sizeof(ip)); if(!z) { diff --git a/dansguardian_report.c b/dansguardian_report.c index 07b9161..35a6506 100644 --- a/dansguardian_report.c +++ b/dansguardian_report.c @@ -112,7 +112,7 @@ void dansguardian_report(void) exit(1); } - if(strcmp(UserIp,"yes") == 0) + if(UserIp) strcpy(user,ip); bzero(date, 15); @@ -135,7 +135,7 @@ void dansguardian_report(void) fixip(user); } - if(strcmp(Ip2Name,"yes") == 0) + if(Ip2Name) ip2name(ip,sizeof(ip)); if(!z) { diff --git a/datafile.c b/datafile.c index 01a3335..e9be885 100644 --- a/datafile.c +++ b/datafile.c @@ -90,7 +90,7 @@ void data_file(char *tmp) exit(1); } - if(strcmp(Ip2Name,"yes") == 0) { + if(Ip2Name) { if(strcmp(accip,ipantes) != 0) { strcpy(ipantes,accip); ip2name(accip,sizeof(accip)); diff --git a/denied.c b/denied.c index bf831ab..0d6aa3a 100644 --- a/denied.c +++ b/denied.c @@ -117,7 +117,7 @@ void gen_denied_report(void) fixip(user); } - if(strcmp(Ip2Name,"yes") == 0) + if(Ip2Name) ip2name(ip,sizeof(ip)); if(!z) { diff --git a/download.c b/download.c index d0a47a9..fe4894c 100644 --- a/download.c +++ b/download.c @@ -124,7 +124,7 @@ void download_report(void) fixip(user); } - if(strcmp(Ip2Name,"yes") == 0) + if(Ip2Name) ip2name(ip,sizeof(ip)); if(!z) { diff --git a/getconf.c b/getconf.c index 8bd916b..b872009 100644 --- a/getconf.c +++ b/getconf.c @@ -146,6 +146,30 @@ static int getparam_int(const char *param,char *buf,int *value) return(1); } +static int getparam_bool(const char *param,char *buf,int *value) +{ + int plen; + char *str; + int i; + + plen=strlen(param); + if (strncmp(buf,param,plen) != 0) return(0); + buf+=plen; + if ((unsigned char)*buf>' ') return(0); + while (*buf && (unsigned char)*buf<=' ') buf++; + + *value=0; + for (str=text[144] ; *str ; str+=i) { + for (i=0 ; str[i] && str[i]!=',' ; i++); + if (strncasecmp(str,buf,i)==0) { + *value=1; + break; + } + if (str[i]==',') i++; + } + return(1); +} + static void parmtest(char *buf) { char wbuf[50]; @@ -195,9 +219,9 @@ static void parmtest(char *buf) if (getparam_quoted("title",buf,Title,sizeof(Title))>0) return; - if (getparam_string("resolve_ip",buf,Ip2Name,sizeof(Ip2Name))>0) return; + if (getparam_bool("resolve_ip",buf,&Ip2Name)>0) return; - if (getparam_string("user_ip",buf,UserIp,sizeof(UserIp))>0) return; + if (getparam_bool("user_ip",buf,&UserIp)>0) return; if (getparam_string("max_elapsed",buf,MaxElapsed,sizeof(MaxElapsed))>0) return; @@ -290,7 +314,7 @@ static void parmtest(char *buf) if (getparam_2words("topsites_sort_order",buf,TopsitesSortField,sizeof(TopsitesSortField),TopsitesSortType,sizeof(TopsitesSortType))>0) return; - if (getparam_string("long_url",buf,LongUrl,sizeof(LongUrl))>0) return; + if (getparam_bool("long_url",buf,&LongUrl)>0) return; if (getparam_string("language",buf,language,sizeof(language))>0) return; diff --git a/grepday.c b/grepday.c index 9cd87de..8246e70 100644 --- a/grepday.c +++ b/grepday.c @@ -424,7 +424,7 @@ void greport_day(const char *user) if(strstr(wuser,"_") != 0) fixip(wuser); - if(strcmp(Ip2Name,"yes") == 0) + if(Ip2Name) if((str=(char *) strstr(name, ".")) != (char *) NULL) { if((str=(char *) strstr(str+1, ".")) != (char *) NULL) ip2name(wuser,sizeof(wuser)); diff --git a/html.c b/html.c index 56628f6..cb83883 100644 --- a/html.c +++ b/html.c @@ -170,7 +170,7 @@ void htmlrel(void) strcpy(u2,usuario); if(userip) fixip(u2); - if(strcmp(Ip2Name,"yes") == 0) + if(Ip2Name) ip2name(u2,sizeof(u2)); get_usertab_name(u2,name2,sizeof(name2)); @@ -355,7 +355,7 @@ void htmlrel(void) strcpy(wwork2,fixnum(nnbytes,1)); strcpy(wwork3,fixnum2(nnelap,1)); - if(strcmp(LongUrl,"yes") != 0) { + if(!LongUrl) { char *endofhost=strchr(url,'/'); if (endofhost) *endofhost='\0'; strcpy(urly,url); diff --git a/include/conf.h b/include/conf.h index d60edee..e22ac6a 100755 --- a/include/conf.h +++ b/include/conf.h @@ -184,8 +184,8 @@ char ReportType[255]; char UserTabFile[255]; char warea[MAXLEN]; char name[MAXLEN]; -char LongUrl[20]; -char Ip2Name[20]; +int LongUrl; +int Ip2Name; char language[255]; char bufy[MAXLEN]; int NAccessLog; @@ -221,7 +221,7 @@ char ExcludeUsers[255]; char DateFormat[2]; char PerUserLimitFile[255]; char PerUserLimit[20]; -char UserIp[5]; +int UserIp; char MaxElapsed[255]; char datetimeby[10]; char csort[255]; diff --git a/languages/Bulgarian_windows1251 b/languages/Bulgarian_windows1251 index 9042250..4df79e4 100644 --- a/languages/Bulgarian_windows1251 +++ b/languages/Bulgarian_windows1251 @@ -142,3 +142,4 @@ "unexpected end of file encountered in" "skipping to next file" "Log is from Microsoft ISA" +"yes,true,on,1" diff --git a/languages/Catalan b/languages/Catalan index d20522a..c1ad1de 100644 --- a/languages/Catalan +++ b/languages/Catalan @@ -142,3 +142,4 @@ "unexpected end of file encountered in" "skipping to next file" "Log is from Microsoft ISA" +"yes,true,on,1" diff --git a/languages/Czech b/languages/Czech index dfbda8f..f7d659b 100644 --- a/languages/Czech +++ b/languages/Czech @@ -142,3 +142,4 @@ "unexpected end of file encountered in" "skipping to next file" "Log is from Microsoft ISA" +"yes,true,on,1" diff --git a/languages/Czech_UTF8 b/languages/Czech_UTF8 index b05f092..ef028ff 100644 --- a/languages/Czech_UTF8 +++ b/languages/Czech_UTF8 @@ -142,3 +142,4 @@ "unexpected end of file encountered in" "skipping to next file" "Log is from Microsoft ISA" +"yes,true,on,1" diff --git a/languages/Dutch b/languages/Dutch index 85e978a..0b8a588 100644 --- a/languages/Dutch +++ b/languages/Dutch @@ -142,3 +142,4 @@ "unexpected end of file encountered in" "skipping to next file" "Log is from Microsoft ISA" +"yes,true,on,1" diff --git a/languages/English b/languages/English index ed66ad2..d9ae4d0 100644 --- a/languages/English +++ b/languages/English @@ -142,3 +142,4 @@ "unexpected end of file encountered in" "skipping to next file" "Log is from Microsoft ISA" +"yes,true,on,1" diff --git a/languages/French b/languages/French index 88b0abc..d3ec084 100644 --- a/languages/French +++ b/languages/French @@ -142,3 +142,4 @@ "fin du fichier atteinte prématurément pour" "analyse du fichier suivant" "Log produit par Microsoft ISA" +"yes,true,on,1,oui,vrai" diff --git a/languages/German b/languages/German index 77ed28d..c0b67e9 100644 --- a/languages/German +++ b/languages/German @@ -142,3 +142,4 @@ "unexpected end of file encountered in" "skipping to next file" "Log is from Microsoft ISA" +"yes,true,on,1" diff --git a/languages/Greek b/languages/Greek index 143d7ee..625efb3 100644 --- a/languages/Greek +++ b/languages/Greek @@ -142,3 +142,4 @@ "unexpected end of file encountered in" "skipping to next file" "Log is from Microsoft ISA" +"yes,true,on,1" diff --git a/languages/Hungarian b/languages/Hungarian index 28ee7ec..652062c 100644 --- a/languages/Hungarian +++ b/languages/Hungarian @@ -142,3 +142,4 @@ "unexpected end of file encountered in" "skipping to next file" "Log is from Microsoft ISA" +"yes,true,on,1" diff --git a/languages/Indonesian b/languages/Indonesian index 32f1968..f4990ec 100644 --- a/languages/Indonesian +++ b/languages/Indonesian @@ -142,3 +142,4 @@ "unexpected end of file encountered in" "skipping to next file" "Log is from Microsoft ISA" +"yes,true,on,1" diff --git a/languages/Italian b/languages/Italian index 4183505..743e500 100644 --- a/languages/Italian +++ b/languages/Italian @@ -142,3 +142,4 @@ "unexpected end of file encountered in" "skipping to next file" "Log is from Microsoft ISA" +"yes,true,on,1" diff --git a/languages/Japanese b/languages/Japanese index 690114a..320d082 100644 --- a/languages/Japanese +++ b/languages/Japanese @@ -142,3 +142,4 @@ "unexpected end of file encountered in" "skipping to next file" "Log is from Microsoft ISA" +"yes,true,on,1" diff --git a/languages/Latvian b/languages/Latvian index 769c421..3fca7bd 100644 --- a/languages/Latvian +++ b/languages/Latvian @@ -142,3 +142,4 @@ "unexpected end of file encountered in" "skipping to next file" "Log is from Microsoft ISA" +"yes,true,on,1" diff --git a/languages/Polish b/languages/Polish index f0f1aa1..1eb3f83 100644 --- a/languages/Polish +++ b/languages/Polish @@ -142,3 +142,4 @@ "unexpected end of file encountered in" "skipping to next file" "Log is from Microsoft ISA" +"yes,true,on,1" diff --git a/languages/Polish_windows1250 b/languages/Polish_windows1250 index 87bf355..d140934 100644 --- a/languages/Polish_windows1250 +++ b/languages/Polish_windows1250 @@ -142,3 +142,4 @@ "unexpected end of file encountered in" "skipping to next file" "Log is from Microsoft ISA" +"yes,true,on,1" diff --git a/languages/Portuguese b/languages/Portuguese index ed5f018..676ded1 100644 --- a/languages/Portuguese +++ b/languages/Portuguese @@ -142,3 +142,4 @@ "unexpected end of file encountered in" "skipping to next file" "Log is from Microsoft ISA" +"yes,true,on,1" diff --git a/languages/Romanian b/languages/Romanian index 8ff6942..0e92474 100644 --- a/languages/Romanian +++ b/languages/Romanian @@ -142,3 +142,4 @@ "unexpected end of file encountered in" "skipping to next file" "Log is from Microsoft ISA" +"yes,true,on,1" diff --git a/languages/Russian_UTF-8 b/languages/Russian_UTF-8 index f838563..f540b46 100755 --- a/languages/Russian_UTF-8 +++ b/languages/Russian_UTF-8 @@ -142,3 +142,4 @@ "unexpected end of file encountered in" "skipping to next file" "Log is from Microsoft ISA" +"yes,true,on,1" diff --git a/languages/Russian_koi8 b/languages/Russian_koi8 index fb33afd..30ccf03 100644 --- a/languages/Russian_koi8 +++ b/languages/Russian_koi8 @@ -142,3 +142,4 @@ "unexpected end of file encountered in" "skipping to next file" "Log is from Microsoft ISA" +"yes,true,on,1" diff --git a/languages/Russian_windows1251 b/languages/Russian_windows1251 index 9fbadb5..dbf1883 100644 --- a/languages/Russian_windows1251 +++ b/languages/Russian_windows1251 @@ -142,3 +142,4 @@ "unexpected end of file encountered in" "skipping to next file" "Log is from Microsoft ISA" +"yes,true,on,1" diff --git a/languages/Serbian b/languages/Serbian index b9d16bb..9bb0f68 100644 --- a/languages/Serbian +++ b/languages/Serbian @@ -142,3 +142,4 @@ "unexpected end of file encountered in" "skipping to next file" "Log is from Microsoft ISA" +"yes,true,on,1" diff --git a/languages/Slovak b/languages/Slovak index a2335b2..d831a3f 100644 --- a/languages/Slovak +++ b/languages/Slovak @@ -142,3 +142,4 @@ "unexpected end of file encountered in" "skipping to next file" "Log is from Microsoft ISA" +"yes,true,on,1" diff --git a/languages/Spanish b/languages/Spanish index 437e153..b02442a 100644 --- a/languages/Spanish +++ b/languages/Spanish @@ -142,3 +142,4 @@ "unexpected end of file encountered in" "skipping to next file" "Log is from Microsoft ISA" +"yes,true,on,1" diff --git a/languages/Turkish b/languages/Turkish index d3ca5ac..0f07619 100644 --- a/languages/Turkish +++ b/languages/Turkish @@ -142,3 +142,4 @@ "unexpected end of file encountered in" "skipping to next file" "Log is from Microsoft ISA" +"yes,true,on,1" diff --git a/languages/Ukrainian_windows1251 b/languages/Ukrainian_windows1251 index dd1acc4..505e85b 100644 --- a/languages/Ukrainian_windows1251 +++ b/languages/Ukrainian_windows1251 @@ -142,3 +142,4 @@ DansGuardian" "unexpected end of file encountered in" "skipping to next file" "Log is from Microsoft ISA" +"yes,true,on,1" diff --git a/log.c b/log.c index 033acd8..545ab69 100644 --- a/log.c +++ b/log.c @@ -140,14 +140,12 @@ int main(int argc,char *argv[]) LogoText[0]='\0'; PasswdFile[0]='\0'; OutputEmail[0]='\0'; - Ip2Name[0]='\0'; UserAgentLog[0]='\0'; ExcludeHosts[0]='\0'; ExcludeUsers[0]='\0'; ConfigFile[0]='\0'; code[0]='\0'; LastLog[0]='\0'; - UserIp[0]='\0'; ReportType[0]='\0'; UserTabFile[0]='\0'; BlockIt[0]='\0'; @@ -171,7 +169,7 @@ int main(int argc,char *argv[]) strcpy(FontSize,"9px"); strcpy(TempDir,"/tmp"); strcpy(OutputDir,"/var/www/html/squid-reports"); - strcpy(Ip2Name,"no"); + Ip2Name=0; strcpy(DateFormat,"u"); strcpy(OverwriteReport,"no"); strcpy(RemoveTempFiles,"yes"); @@ -181,14 +179,14 @@ int main(int argc,char *argv[]) strcpy(UseComma,"no"); strcpy(MailUtility,"mailx"); strcpy(TopSitesNum,"100"); - strcpy(UserIp,"no"); + UserIp=0; strcpy(TopuserSortField,"BYTES"); strcpy(UserSortField,"BYTES"); strcpy(TopuserSortOrder,"reverse"); strcpy(UserSortOrder,"reverse"); strcpy(TopsitesSortField,"CONNECT"); strcpy(TopsitesSortType,"D"); - strcpy(LongUrl,"no"); + LongUrl=0; strcpy(language,"English"); strcpy(FontFace,"Verdana,Tahoma,Arial"); strcpy(datetimeby,"elap"); @@ -507,9 +505,9 @@ int main(int argc,char *argv[]) if(strcmp(ExcludeUsers,"indexonly") == 0) indexonly++; if(strcmp(Index,"only") == 0) indexonly++; - if(dns) strcpy(Ip2Name,"yes"); + if(dns) Ip2Name=1; - if(strcmp(UserIp,"yes") == 0) userip++; + if(UserIp) userip++; if(strlen(MaxElapsed)>1) max_elapsed=atol(MaxElapsed); @@ -586,12 +584,12 @@ int main(int argc,char *argv[]) fprintf(stderr, "SARG: %35s (-i) = %s\n",text[28],text[2]); for (iarq=0 ; iarq