[master] 82491c2a8 vcc: PRIV_ arguments can be named too

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Mon Jul 27 13:34:08 UTC 2020


commit 82491c2a8abd65fb72b5588afbf07e8fdeeeede0
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Mon Jul 27 15:19:51 2020 +0200

    vcc: PRIV_ arguments can be named too
    
    This otherwise doesn't work with [optional] arguments.

diff --git a/bin/varnishtest/tests/m00052.vtc b/bin/varnishtest/tests/m00052.vtc
new file mode 100644
index 000000000..580c01e1c
--- /dev/null
+++ b/bin/varnishtest/tests/m00052.vtc
@@ -0,0 +1,21 @@
+varnishtest "priv_task with [optional] argument"
+
+varnish v1 -vcl {
+	import debug;
+
+	backend be none;
+
+	sub vcl_deliver {
+		set resp.http.none = debug.priv_task_with_option();
+		set resp.http.one = debug.priv_task_with_option("one");
+		set resp.http.two = debug.priv_task_with_option("two");
+	}
+} -start
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.http.none == ""
+	expect resp.http.one == one
+	expect resp.http.two == one
+} -run
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index 67623e0b2..60a29b585 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -515,6 +515,9 @@ vcc_func(struct vcc *tl, struct expr **e, const void *priv,
 		vvp = VTAILQ_FIRST(&vv->children);
 		if (!memcmp(vvp->value, "PRIV_", 5)) {
 			fa->result = vcc_priv_arg(tl, vvp->value, sym);
+			vvp = VTAILQ_NEXT(vvp, list);
+			if (vvp != NULL)
+				fa->name = vvp->value;
 			continue;
 		}
 		fa->type = VCC_Type(vvp->value);
diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c
index 4dbc5ab3b..af7598b6b 100644
--- a/lib/libvmod_debug/vmod_debug.c
+++ b/lib/libvmod_debug/vmod_debug.c
@@ -1162,3 +1162,14 @@ xyzzy_re_quote(VRT_CTX, VCL_STRING s)
 		WS_MarkOverflow(ctx->ws);
 	return (q);
 }
+
+VCL_STRING v_matchproto_(td_xyzzy_priv_task_with_option)
+xyzzy_priv_task_with_option(VRT_CTX, struct VARGS(priv_task_with_option) *args)
+{
+
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	AN(args->priv);
+	if (args->priv->priv == NULL && args->valid_opt)
+		args->priv->priv = WS_Copy(ctx->ws, args->opt, -1);
+	return (args->priv->priv);
+}
diff --git a/lib/libvmod_debug/vmod_debug.vcc b/lib/libvmod_debug/vmod_debug.vcc
index 63c326cf4..094db5311 100644
--- a/lib/libvmod_debug/vmod_debug.vcc
+++ b/lib/libvmod_debug/vmod_debug.vcc
@@ -304,3 +304,7 @@ Allow rollbacks. Must be called before the end of the task.
 $Function STRING re_quote(STRING)
 
 Quote an input string to be usable for an exact match in a regular expression.
+
+$Function STRING priv_task_with_option(PRIV_TASK priv, [STRING opt])
+
+A function mixing a named PRIV_TASK with optional parameters.


More information about the varnish-commit mailing list