r3534 - in trunk/varnish-cache: bin/varnishtest/tests lib/libvcl

phk at projects.linpro.no phk at projects.linpro.no
Mon Jan 19 14:46:31 CET 2009


Author: phk
Date: 2009-01-19 14:46:31 +0100 (Mon, 19 Jan 2009)
New Revision: 3534

Added:
   trunk/varnish-cache/bin/varnishtest/tests/b00028.vtc
Modified:
   trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
   trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl
   trunk/varnish-cache/lib/libvcl/vcc_parse.c
   trunk/varnish-cache/lib/libvcl/vcc_token_defs.h
Log:
Add "no match" operator !~ to VCL regexps



Added: trunk/varnish-cache/bin/varnishtest/tests/b00028.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/b00028.vtc	                        (rev 0)
+++ trunk/varnish-cache/bin/varnishtest/tests/b00028.vtc	2009-01-19 13:46:31 UTC (rev 3534)
@@ -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

Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c	2009-01-19 13:45:10 UTC (rev 3533)
+++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c	2009-01-19 13:46:31 UTC (rev 3534)
@@ -22,6 +22,7 @@
 
 	switch (p[0]) {
 	case '!':
+		M2('~', T_NOMATCH);
 		M2('=', T_NEQ);
 		M1();
 	case '%':
@@ -146,6 +147,7 @@
 	[T_LEQ] = "<=",
 	[T_MUL] = "*=",
 	[T_NEQ] = "!=",
+	[T_NOMATCH] = "!~",
 	[T_SHL] = "<<",
 	[T_SHR] = ">>",
 	[VAR] = "VAR",

Modified: trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl	2009-01-19 13:45:10 UTC (rev 3533)
+++ trunk/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl	2009-01-19 13:46:31 UTC (rev 3534)
@@ -88,6 +88,7 @@
 	{"-="	DECR}
 	{"*="	MUL}
 	{"/="	DIV}
+	{"!~"	NOMATCH}
 }
 
 # Single char tokens

Modified: trunk/varnish-cache/lib/libvcl/vcc_parse.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_parse.c	2009-01-19 13:45:10 UTC (rev 3533)
+++ trunk/varnish-cache/lib/libvcl/vcc_parse.c	2009-01-19 13:46:31 UTC (rev 3534)
@@ -248,12 +248,15 @@
 
 	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:

Modified: trunk/varnish-cache/lib/libvcl/vcc_token_defs.h
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_token_defs.h	2009-01-19 13:45:10 UTC (rev 3533)
+++ trunk/varnish-cache/lib/libvcl/vcc_token_defs.h	2009-01-19 13:46:31 UTC (rev 3534)
@@ -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



More information about the varnish-commit mailing list