From 7b8c5ebc15cce4351f9e01a12da50a9fc022e38a Mon Sep 17 00:00:00 2001 From: phk Date: Mon, 19 Jan 2009 13:46:31 +0000 Subject: [PATCH] Add "no match" operator !~ to VCL regexps git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3534 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- .../bin/varnishtest/tests/b00028.vtc | 28 +++++++++++++++++++ varnish-cache/lib/libvcl/vcc_fixed_token.c | 2 ++ .../lib/libvcl/vcc_gen_fixed_token.tcl | 1 + varnish-cache/lib/libvcl/vcc_parse.c | 5 +++- varnish-cache/lib/libvcl/vcc_token_defs.h | 13 +++++---- 5 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 varnish-cache/bin/varnishtest/tests/b00028.vtc diff --git a/varnish-cache/bin/varnishtest/tests/b00028.vtc b/varnish-cache/bin/varnishtest/tests/b00028.vtc new file mode 100644 index 00000000..95fd593d --- /dev/null +++ b/varnish-cache/bin/varnishtest/tests/b00028.vtc @@ -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 diff --git a/varnish-cache/lib/libvcl/vcc_fixed_token.c b/varnish-cache/lib/libvcl/vcc_fixed_token.c index d2ed3db1..69d8a2fd 100644 --- a/varnish-cache/lib/libvcl/vcc_fixed_token.c +++ b/varnish-cache/lib/libvcl/vcc_fixed_token.c @@ -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", diff --git a/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl b/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl index 2d288bdf..648a8257 100755 --- a/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl +++ b/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl @@ -88,6 +88,7 @@ set magic { {"-=" DECR} {"*=" MUL} {"/=" DIV} + {"!~" NOMATCH} } # Single char tokens diff --git a/varnish-cache/lib/libvcl/vcc_parse.c b/varnish-cache/lib/libvcl/vcc_parse.c index 2e805a31..1399c90f 100644 --- a/varnish-cache/lib/libvcl/vcc_parse.c +++ b/varnish-cache/lib/libvcl/vcc_parse.c @@ -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: diff --git a/varnish-cache/lib/libvcl/vcc_token_defs.h b/varnish-cache/lib/libvcl/vcc_token_defs.h index 26b0b1bd..3acc1a03 100644 --- a/varnish-cache/lib/libvcl/vcc_token_defs.h +++ b/varnish-cache/lib/libvcl/vcc_token_defs.h @@ -26,9 +26,10 @@ #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 -- 2.39.5