[master] df22bd2 Add special parsing of ENUM in vmod object method argument spec

Martin Blix Grydeland martin at varnish-cache.org
Tue Aug 13 10:37:59 CEST 2013


commit df22bd225a437abdd4e9742f8593a81128852407
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Mon Aug 12 15:37:46 2013 +0200

    Add special parsing of ENUM in vmod object method argument spec
    
    The missing handler would end the object spec prematurily, hiding the
    rest of the methods.
    
    Fixes: #1332

diff --git a/bin/varnishtest/tests/r01332.vtc b/bin/varnishtest/tests/r01332.vtc
new file mode 100644
index 0000000..062e334
--- /dev/null
+++ b/bin/varnishtest/tests/r01332.vtc
@@ -0,0 +1,26 @@
+varnishtest "#1332 - Check enum as argument in vmod object"
+
+server s1 {
+	rxreq
+	txresp
+} -start
+
+varnish v1 -vcl+backend {
+	import debug from "${topbuild}/lib/libvmod_debug/.libs/libvmod_debug.so";
+
+	sub vcl_init {
+		new obj = debug.obj("don't care");
+	}
+
+	sub vcl_deliver {
+		obj.enum(martin);
+		set resp.http.foo = obj.foo("");
+	}
+} -start
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.status == 200
+	expect resp.http.foo == "BOO"
+} -run
diff --git a/lib/libvcl/vcc_action.c b/lib/libvcl/vcc_action.c
index e6a3f6c..6b08b34 100644
--- a/lib/libvcl/vcc_action.c
+++ b/lib/libvcl/vcc_action.c
@@ -234,8 +234,19 @@ parse_new(struct vcc *tl)
 
 		sy3->args = p;
 		sy3->extra = TlDup(tl, buf1);
-		while (p[0] != '\0' || p[1] != '\0')
+		while (p[0] != '\0' || p[1] != '\0') {
+			if (!memcmp(p, "ENUM\0", 5)) {
+				/* XXX: Special case for ENUM that has
+				   it's own \0\0 end marker. Not exactly
+				   elegant, we should consider
+				   alternatives here. Maybe runlength
+				   encode the entire block? */
+				p += strlen(p) + 1;
+				while (p[0] != '\0' || p[1] != '\0')
+					p++;
+			}
 			p++;
+		}
 		p += 2;
 	}
 	/*lint -restore */
diff --git a/lib/libvmod_debug/vmod.vcc b/lib/libvmod_debug/vmod.vcc
index 57d8721..a27e998 100644
--- a/lib/libvmod_debug/vmod.vcc
+++ b/lib/libvmod_debug/vmod.vcc
@@ -32,6 +32,8 @@ Function STRING author(ENUM { phk, des, kristian, mithrandir })
 Function VOID test_priv_call(PRIV_CALL)
 Function VOID test_priv_vcl(PRIV_VCL)
 Object obj(STRING) {
+	# NOTE: .enum before .foo as part of test r01332.vtc
+	Method VOID .enum(ENUM { phk, des, kristian, mithrandir, martin })
 	Method STRING .foo(STRING why)
 	Method TIME .date()
 }
diff --git a/lib/libvmod_debug/vmod_debug_obj.c b/lib/libvmod_debug/vmod_debug_obj.c
index c27b6db..ad24578 100644
--- a/lib/libvmod_debug/vmod_debug_obj.c
+++ b/lib/libvmod_debug/vmod_debug_obj.c
@@ -69,6 +69,15 @@ vmod_obj__fini(struct vmod_debug_obj **op)
 	*op = NULL;
 }
 
+VCL_VOID __match_proto__()
+vmod_obj_enum(const struct vrt_ctx *ctx, struct vmod_debug_obj *o, VCL_ENUM e)
+{
+
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	CHECK_OBJ_NOTNULL(o, VMOD_DEBUG_OBJ_MAGIC);
+	assert(!strcmp(e, "martin"));
+}
+
 VCL_STRING __match_proto__()
 vmod_obj_foo(const struct vrt_ctx *ctx, struct vmod_debug_obj *o, VCL_STRING s)
 {



More information about the varnish-commit mailing list