]> err.no Git - varnish/commitdiff
Add "no match" operator !~ to VCL regexps
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 19 Jan 2009 13:46:31 +0000 (13:46 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 19 Jan 2009 13:46:31 +0000 (13:46 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3534 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishtest/tests/b00028.vtc [new file with mode: 0644]
varnish-cache/lib/libvcl/vcc_fixed_token.c
varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl
varnish-cache/lib/libvcl/vcc_parse.c
varnish-cache/lib/libvcl/vcc_token_defs.h

diff --git a/varnish-cache/bin/varnishtest/tests/b00028.vtc b/varnish-cache/bin/varnishtest/tests/b00028.vtc
new file mode 100644 (file)
index 0000000..95fd593
--- /dev/null
@@ -0,0 +1,28 @@
+# $Id$
+
+test "regexp match and no-match"
+
+server s1 {
+       rxreq
+       txresp -hdr "Foo: bar" -hdr "Bar: foo" -body "1111\n"
+} -start
+
+varnish v1 -vcl+backend {
+
+       sub vcl_fetch {
+               if (obj.http.foo ~ "bar") {
+                       set obj.http.foo1 = "1";
+               }
+               if (obj.http.bar !~ "bar") {
+                       set obj.http.bar1 = "1";
+               }
+       }
+
+} -start
+
+client c1 {
+       txreq
+       rxresp
+       expect resp.http.foo1 == "1"
+       expect resp.http.bar1 == "1"
+} -run
index d2ed3db1684114ff13cb3cae05327826f167812d..69d8a2fd783cb50e9c95dbdaea5d7b53eef8e49b 100644 (file)
@@ -22,6 +22,7 @@ vcl_fixed_token(const char *p, const char **q)
 
        switch (p[0]) {
        case '!':
+               M2('~', T_NOMATCH);
                M2('=', T_NEQ);
                M1();
        case '%':
@@ -146,6 +147,7 @@ const char * const vcl_tnames[256] = {
        [T_LEQ] = "<=",
        [T_MUL] = "*=",
        [T_NEQ] = "!=",
+       [T_NOMATCH] = "!~",
        [T_SHL] = "<<",
        [T_SHR] = ">>",
        [VAR] = "VAR",
index 2d288bdff4dcc11f224c7c72f2b364844088669c..648a8257942f82558f40f5d6c2cd9ef7ecdf975e 100755 (executable)
@@ -88,6 +88,7 @@ set magic {
        {"-="   DECR}
        {"*="   MUL}
        {"/="   DIV}
+       {"!~"   NOMATCH}
 }
 
 # Single char tokens
index 2e805a317da7d70251e3b9f1d4f72cdac3f90cd9..1399c90f9c279f80a0ae8e093d107ef97f19f0b8 100644 (file)
@@ -248,12 +248,15 @@ Cond_String(const struct var *vp, struct tokenlist *tl)
 
        switch (tl->t->tok) {
        case '~':
+       case T_NOMATCH:
+               Fb(tl, 1, "%sVRT_re_match(",
+                    tl->t->tok == '~' ? "" : "!");
                vcc_NextToken(tl);
                ExpectErr(tl, CSTR);
                p = vcc_regexp(tl, 0);
                ERRCHK(tl);
                vcc_NextToken(tl);
-               Fb(tl, 1, "VRT_re_match(%s, %s)\n", vp->rname, p);
+               Fb(tl, 1, "%s, %s)\n", vp->rname, p);
                break;
        case T_EQ:
        case T_NEQ:
index 26b0b1bd5f5ec0b9419acdd0087540e3b8392010..3acc1a03ea2d0cb645e1c50fdc3cc58de95f9433 100644 (file)
 #define T_DECR 144
 #define T_MUL 145
 #define T_DIV 146
-#define ID 147
-#define VAR 148
-#define CNUM 149
-#define CSTR 150
-#define EOI 151
-#define CSRC 152
+#define T_NOMATCH 147
+#define ID 148
+#define VAR 149
+#define CNUM 150
+#define CSTR 151
+#define EOI 152
+#define CSRC 153