]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Accept case insensitive regular expressions
authorFrederic Marchal <fmarchal@users.sourceforge.net>
Mon, 27 Jul 2015 18:09:38 +0000 (20:09 +0200)
committerFrederic Marchal <fmarchal@users.sourceforge.net>
Mon, 27 Jul 2015 18:09:38 +0000 (20:09 +0200)
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.

alias.c
sarg.conf

diff --git a/alias.c b/alias.c
index 089ec21d0e289c1cb0317491d261c39b5d4e9185..41fa1551203a9463689ba41f3a369a36ecb8d4bf 100644 (file)
--- 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);
index 18c8eb58a0965bae018be473b030a74b71c93114..ee755d455d631465844111e8b66e7f9dd2a85ce9 100644 (file)
--- a/sarg.conf
+++ b/sarg.conf
 #      *.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