[master] a3ee09b fix the tiny bit necessary for PRIV_* to work with methods and add tests

Nils Goroll nils.goroll at uplex.de
Mon Sep 12 11:24:14 CEST 2016


commit a3ee09b8cba977bb71c4f776d757c0d49c170527
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Tue Aug 30 21:49:47 2016 +0200

    fix the tiny bit necessary for PRIV_* to work with methods and add tests
    
    ... demonstrating that the PRIV_* states are per vmod, no matter if accessed
    from a function or method
    
    Fixes #1800
    
    part of #2061

diff --git a/bin/varnishtest/tests/m00000.vtc b/bin/varnishtest/tests/m00000.vtc
index 6028b0b..999b39f 100644
--- a/bin/varnishtest/tests/m00000.vtc
+++ b/bin/varnishtest/tests/m00000.vtc
@@ -10,6 +10,10 @@ varnish v1 -vcl+backend {
 	import std;
 	import debug;
 
+	sub vcl_init {
+		new obj = debug.obj();
+	}
+
 	sub vcl_recv {
 		debug.rot52(req);
 	}
@@ -20,6 +24,8 @@ varnish v1 -vcl+backend {
 		set resp.http.who = debug.author(phk);
 		debug.test_priv_call();
 		debug.test_priv_vcl();
+		obj.test_priv_call();
+		obj.test_priv_vcl();
 		std.log("VCL" + " initiated " + "log");
 		std.syslog(8 + 7, "Somebody runs varnishtest");
 		debug.rot52(resp);
diff --git a/bin/varnishtest/tests/v00041.vtc b/bin/varnishtest/tests/v00041.vtc
index b111796..7678798 100644
--- a/bin/varnishtest/tests/v00041.vtc
+++ b/bin/varnishtest/tests/v00041.vtc
@@ -12,9 +12,14 @@ varnish v1 -vcl+backend {
 	import std;
 
 	sub vcl_init {
+		new obj = debug.obj();
+	}
+
+	sub vcl_init {
 		debug.test_priv_task("something");
 		debug.test_priv_task("to remember");
-		std.log(debug.test_priv_task());
+		std.log("func " + debug.test_priv_task());
+		std.log("obj "  + obj.test_priv_task());
 	}
 
 	sub vcl_recv {
@@ -26,9 +31,11 @@ varnish v1 -vcl+backend {
 	sub vcl_deliver {
 		set resp.http.x0 = req.http.x0;
 		set resp.http.x1 = debug.test_priv_task();
+		set resp.http.o1 = obj.test_priv_task();
 	}
 
 	sub vcl_backend_fetch {
+		obj.test_priv_task("b");
 		std.log("foo");
 		set bereq.http.bx0 = debug.test_priv_task(bereq.url);
 		std.log("bar");
@@ -37,23 +44,25 @@ varnish v1 -vcl+backend {
 	sub vcl_backend_response {
 		set beresp.http.bx0 = bereq.http.bx0;
 		set beresp.http.bx1 = debug.test_priv_task("");
+		set beresp.http.bo1 = obj.test_priv_task("");
 	}
 } -start
 
 logexpect l1 -v v1 -g raw -d 1 {
 	expect 0 0    CLI		{^Rd vcl.load}
-	expect 0 =    VCL_Log		{^something to remember}
+	expect 0 =    VCL_Log		{^func something to remember}
+	expect 0 =    VCL_Log		{^obj something to remember}
 
 	expect * 1002 Begin		fetch$
 	expect * =    VCL_call		^BACKEND_FETCH
 	expect 0 =    VCL_Log		^foo
-	expect 0 =    BereqHeader	{^bx0: /foobar}
+	expect 0 =    BereqHeader	{^bx0: b /foobar}
 	expect 0 =    VCL_Log		^bar
 
 	expect * 1004 Begin		fetch$
 	expect * =    VCL_call		^BACKEND_FETCH
 	expect 0 =    VCL_Log		^foo
-	expect 0 =    BereqHeader	{^bx0: /snafu}
+	expect 0 =    BereqHeader	{^bx0: b /snafu}
 	expect 0 =    VCL_Log		^bar
 } -start
 
@@ -62,15 +71,19 @@ client c1 {
 	rxresp
 	expect resp.http.x0 == /foobar
 	expect resp.http.x1 == "/foobar bazz"
-	expect resp.http.bx0 == /foobar
-	expect resp.http.bx1 == /foobar
+	expect resp.http.o1 == "/foobar bazz"
+	expect resp.http.bx0 == "b /foobar"
+	expect resp.http.bx1 == "b /foobar"
+	expect resp.http.bo1 == "b /foobar"
 
 	txreq -url /snafu
 	rxresp
 	expect resp.http.x0 == /snafu
 	expect resp.http.x1 == "/snafu bazz"
-	expect resp.http.bx0 == /snafu
-	expect resp.http.bx1 == /snafu
+	expect resp.http.o1 == "/snafu bazz"
+	expect resp.http.bx0 == "b /snafu"
+	expect resp.http.bx1 == "b /snafu"
+	expect resp.http.bo1 == "b /snafu"
 } -run
 
 logexpect l1 -wait
diff --git a/bin/varnishtest/tests/v00042.vtc b/bin/varnishtest/tests/v00042.vtc
index 6b7ed9c..e7901b1 100644
--- a/bin/varnishtest/tests/v00042.vtc
+++ b/bin/varnishtest/tests/v00042.vtc
@@ -36,6 +36,10 @@ server s1 {
 varnish v1 -vcl+backend {
 	import debug;
 
+	sub vcl_init {
+		new o = debug.obj();
+	}
+
 	sub vcl_recv {
 		set req.http.x0 = debug.test_priv_task(req.url + req.esi_level);
 	}
@@ -51,6 +55,7 @@ varnish v1 -vcl+backend {
 
 	sub vcl_deliver {
 		set resp.http.x1 = debug.test_priv_task("");
+		set resp.http.o1 = o.test_priv_task("");
 	}
 } -start
 
@@ -59,10 +64,12 @@ client c1 {
 	txreq -url /a
 	rxresp
 	expect resp.http.x1 == "/a0"
+	expect resp.http.o1 == "/a0"
 
 	txreq -url /b
 	rxresp
 	expect resp.http.x1 == "/b0"
+	expect resp.http.o1 == "/b0"
 } -run
 
 varnish v1 -expect s_req == 2
diff --git a/bin/varnishtest/tests/v00043.vtc b/bin/varnishtest/tests/v00043.vtc
index 9bf7b47..7e7a4f9 100644
--- a/bin/varnishtest/tests/v00043.vtc
+++ b/bin/varnishtest/tests/v00043.vtc
@@ -38,6 +38,10 @@ server s1 {
 varnish v1 -cliok "param.set debug +syncvsl" -vcl+backend {
 	import debug;
 
+	sub vcl_init {
+		new o = debug.obj();
+	}
+
 	sub vcl_recv {
 		set req.http.x0 = debug.test_priv_top(req.url + req.esi_level);
 	}
@@ -53,6 +57,7 @@ varnish v1 -cliok "param.set debug +syncvsl" -vcl+backend {
 
 	sub vcl_deliver {
 		set resp.http.x1 = debug.test_priv_top("");
+		set resp.http.o1 = o.test_priv_top("");
 	}
 } -start
 
@@ -61,10 +66,12 @@ client c1 {
 	txreq -url /a
 	rxresp
 	expect resp.http.x1 == "/a0"
+	expect resp.http.o1 == "/a0"
 
 	txreq -url /b
 	rxresp
 	expect resp.http.x1 == "/b0"
+	expect resp.http.o1 == "/b0"
 } -run
 
 varnish v1 -expect s_req == 2
diff --git a/lib/libvcc/vcc_vmod.c b/lib/libvcc/vcc_vmod.c
index cf7fa91..efc3dcd 100644
--- a/lib/libvcc/vcc_vmod.c
+++ b/lib/libvcc/vcc_vmod.c
@@ -333,6 +333,7 @@ vcc_ParseNew(struct vcc *tl)
 		sy3->eval_priv = p;
 		sy3->fmt = VCC_Type(p);
 		sy3->extra = TlDup(tl, buf1);
+		sy3->vmod = sy2->vmod;
 		while (p[0] != '\0' || p[1] != '\0' || p[2] != '\0')
 			p++;
 		p += 3;
diff --git a/lib/libvmod_debug/vmod.vcc b/lib/libvmod_debug/vmod.vcc
index f20c127..82e264f 100644
--- a/lib/libvmod_debug/vmod.vcc
+++ b/lib/libvmod_debug/vmod.vcc
@@ -97,6 +97,29 @@ $Method TIME .date()
 
 You never know when you need a date.
 
+$Method VOID .test_priv_call(PRIV_CALL)
+
+Test method for call private pointers
+
+Objects share the PRIV_* state with other objects and methods from the
+same vmod - IOW the PRIV_* state is per vmod, not per object.
+
+$Method VOID .test_priv_vcl(PRIV_VCL)
+
+Test method for VCL private pointers
+
+Objects share the PRIV_* state with other objects and methods from the
+same vmod - IOW the PRIV_* state is per vmod, not per object.
+
+$Method STRING .test_priv_task(PRIV_TASK, STRING s="")
+
+Test method for TASK private pointers
+
+Objects share the PRIV_* state with other objects and methods from the
+same vmod - IOW the PRIV_* state is per vmod, not per object.
+
+$Method STRING .test_priv_top(PRIV_TOP, STRING)
+
 $Function VOID rot52(HTTP hdr)
 
 Encrypt the HTTP header with quad-ROT13 encryption,
diff --git a/lib/libvmod_debug/vmod_debug_obj.c b/lib/libvmod_debug/vmod_debug_obj.c
index 0028de0..f503943 100644
--- a/lib/libvmod_debug/vmod_debug_obj.c
+++ b/lib/libvmod_debug/vmod_debug_obj.c
@@ -120,3 +120,32 @@ vmod_obj_number(VRT_CTX, struct vmod_debug_obj *o)
 	assert(o->foobar == 42);
 	return (o->number);
 }
+
+VCL_VOID __match_proto__()
+vmod_obj_test_priv_call(VRT_CTX,
+    struct vmod_debug_obj *o, struct vmod_priv *priv)
+{
+	(void) o;
+	vmod_test_priv_call(ctx, priv);
+}
+VCL_VOID __match_proto__()
+vmod_obj_test_priv_vcl(VRT_CTX,
+    struct vmod_debug_obj *o, struct vmod_priv *priv)
+{
+	(void) o;
+	vmod_test_priv_vcl(ctx, priv);
+}
+VCL_STRING __match_proto__()
+vmod_obj_test_priv_task(VRT_CTX,
+    struct vmod_debug_obj *o, struct vmod_priv *priv, VCL_STRING s)
+{
+	(void) o;
+	return (vmod_test_priv_task(ctx, priv, s));
+}
+VCL_STRING __match_proto__()
+vmod_obj_test_priv_top(VRT_CTX,
+    struct vmod_debug_obj *o, struct vmod_priv *priv, VCL_STRING s)
+{
+	(void) o;
+	return (vmod_test_priv_top(ctx, priv, s));
+}



More information about the varnish-commit mailing list