From: Frederic Marchal Date: Mon, 27 Jul 2015 18:09:38 +0000 (+0200) Subject: Accept case insensitive regular expressions X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7abbda48c68d20c77ebc5674928569e8c60b0749;p=thirdparty%2Fsarg.git Accept case insensitive regular expressions Such a regex must be suffixed with the lower case "i". As a consequence, a regex must now be separated from the alias by at least one space or tab in the definition file. --- diff --git a/alias.c b/alias.c index 089ec21..41fa155 100644 --- a/alias.c +++ b/alias.c @@ -497,6 +497,7 @@ static int Alias_StoreRegexp(struct AliasStruct *AliasData,char *buf) int len; char *tmp; int i; + int ReOption=0; // find the pattern Delimiter=*buf++; @@ -515,6 +516,17 @@ static int Alias_StoreRegexp(struct AliasStruct *AliasData,char *buf) } *End++='\0'; + // get option: currently supported: i=case insensitive + while (*End && isalpha(*End)) { + if (*End=='i') { + ReOption|=PCRE_CASELESS; + } else { + debuga(__FILE__,__LINE__,_("Invalid option character %c found after regular expression\n"),*End); + return(-1); + } + End++; + } + // find the alias for (Replace=End ; *Replace==' ' || *Replace=='\t' ; Replace++); for (End=Replace ; *End && (unsigned char)*End>' ' ; End++); @@ -528,7 +540,7 @@ static int Alias_StoreRegexp(struct AliasStruct *AliasData,char *buf) } new_alias->Type=ALIASTYPE_Pcre; new_alias->Next=NULL; - new_alias->Regex.Re=pcre_compile(buf,0,&PcreError,&ErrorOffset,NULL); + new_alias->Regex.Re=pcre_compile(buf,ReOption,&PcreError,&ErrorOffset,NULL); if (new_alias->Regex.Re==NULL) { debuga(__FILE__,__LINE__,_("Failed to compile the regular expression \"%s\": %s\n"),buf,PcreError); free(new_alias); diff --git a/sarg.conf b/sarg.conf index 18c8eb5..ee755d4 100644 --- a/sarg.conf +++ b/sarg.conf @@ -861,7 +861,7 @@ # *.mail.live.com # 65.52.00.00/14 *.mail.live.com # re:/\.dropbox\.com(:443)?/ dropbox -# re:/([\w-]+)\.(\w*[a-zA-Z]\w*)(?::\d+)?$/\1.\2 +# re:/([\w-]+)\.(\w*[a-zA-Z]\w*)(?::\d+)?$/ \1.\2 #hostalias /usr/local/sarg/hostalias # TAG: useralias