[master] bdf2f6394 Fix a copy/paste error in VCL_StackVDP.

Geoff Simmons geoff at uplex.de
Thu Apr 18 16:26:08 UTC 2019


commit bdf2f63946e5abd4379f6a86ec0a273b387a4e59
Author: Geoff Simmons <geoff at uplex.de>
Date:   Thu Apr 18 18:23:34 2019 +0200

    Fix a copy/paste error in VCL_StackVDP.
    
    It had been iterating through the vfps list, as VCL_StackVFP does,
    rather than the vdps.
    
    Add a test for a VMOD-defined VDP.

diff --git a/bin/varnishd/cache/cache_vrt_filter.c b/bin/varnishd/cache/cache_vrt_filter.c
index 2f57572aa..ddc0f2510 100644
--- a/bin/varnishd/cache/cache_vrt_filter.c
+++ b/bin/varnishd/cache/cache_vrt_filter.c
@@ -212,7 +212,7 @@ VCL_StackVDP(struct req *req, const struct vcl *vcl, const char *fl)
 	AN(fl);
 	VSLb(req->vsl, SLT_Filters, "%s", fl);
 	while (1) {
-		vp = vcl_filter_list_iter(&vdp_filters, &vcl->vfps, &fl);
+		vp = vcl_filter_list_iter(&vdp_filters, &vcl->vdps, &fl);
 		if (vp == NULL)
 			return (0);
 		if (vp == vfilter_error) {
diff --git a/bin/varnishtest/tests/m00048.vtc b/bin/varnishtest/tests/m00048.vtc
index bb78fdfae..3b2c3d78c 100644
--- a/bin/varnishtest/tests/m00048.vtc
+++ b/bin/varnishtest/tests/m00048.vtc
@@ -1,4 +1,4 @@
-varnishtest "VMOD vfp"
+varnishtest "VMOD vfp & vdp"
 
 server s1 {
 	rxreq
@@ -55,3 +55,27 @@ client c1 {
 	expect resp.status == 503
 } -run
 
+server s1 -wait
+server s1 {
+	rxreq
+	txresp -body "Ponto Facto, Caesar Transit!"
+} -start
+
+varnish v1 -vcl+backend {
+	import debug;
+
+	sub vcl_deliver {
+		if (req.http.Rot13) {
+			set resp.filters = "rot13";
+		}
+	}
+}
+
+client c1 -repeat 2 {
+	txreq
+	rxresp
+	expect resp.body == "Ponto Facto, Caesar Transit!"
+	txreq -hdr "Rot13: please"
+	rxresp
+	expect resp.body == "Cbagb Snpgb, Pnrfne Genafvg!"
+} -run
diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c
index aa94579fe..7832f4ffb 100644
--- a/lib/libvmod_debug/vmod_debug.c
+++ b/lib/libvmod_debug/vmod_debug.c
@@ -89,6 +89,74 @@ static const struct vfp xyzzy_rot13 = {
 
 /**********************************************************************/
 
+#define ROT13_BUFSZ (1 << 13)
+
+static int v_matchproto_(vdp_init_f)
+xyzzy_rot13_init(struct req *req, void **priv)
+{
+	(void)req;
+	AN(priv);
+	*priv = malloc(ROT13_BUFSZ);
+	if (*priv == NULL)
+		return (-1);
+	return (0);
+}
+
+static int v_matchproto_(vdp_bytes_f)
+xyzzy_rot13_bytes(struct req *req, enum vdp_action act, void **priv,
+    const void *ptr, ssize_t len)
+{
+	char *q;
+	const char *pp;
+	int i, j, retval = 0;
+
+	(void)act;
+	AN(priv);
+	AN(*priv);
+	AN(ptr);
+	if (len <= 0)
+		return (0);
+	q = *priv;
+	pp = ptr;
+
+	for (i = 0, j = 0; j < len; i++, j++) {
+		if (pp[j] >= 'A' && pp[j] <= 'Z')
+			q[i] = (((pp[j] - 'A') + 13) % 26) + 'A';
+		else if (pp[j] >= 'a' && pp[j] <= 'z')
+			q[i] = (((pp[j] - 'a') + 13) % 26) + 'a';
+		else
+			q[i] = pp[j];
+		if (i == ROT13_BUFSZ - 1) {
+			retval = VDP_bytes(req, VDP_FLUSH, q, ROT13_BUFSZ);
+			if (retval != 0)
+				return (retval);
+			i = -1;
+		}
+	}
+	if (j > 0 && i >= 0)
+		retval = VDP_bytes(req, VDP_FLUSH, q, i + 1);
+	return (retval);
+}
+
+static int v_matchproto_(vdp_fini_f)
+xyzzy_rot13_fini(struct req *req, void **priv)
+{
+	(void)req;
+	AN(priv);
+	free(*priv);
+	*priv = NULL;
+	return (0);
+}
+
+static const struct vdp xyzzy_vdp_rot13 = {
+	.name  = "rot13",
+	.init  = xyzzy_rot13_init,
+	.bytes = xyzzy_rot13_bytes,
+	.fini  = xyzzy_rot13_fini,
+};
+
+/**********************************************************************/
+
 VCL_STRING v_matchproto_(td_debug_author)
 xyzzy_author(VRT_CTX, VCL_ENUM person, VCL_ENUM someone)
 {
@@ -305,6 +373,8 @@ event_load(VRT_CTX, struct vmod_priv *priv)
 	 * API should look like, do NOT do this anywhere else.
 	 */
 	VRT_AddVFP(ctx, &xyzzy_rot13);
+
+	VRT_AddVDP(ctx, &xyzzy_vdp_rot13);
 	return (0);
 }
 
@@ -381,6 +451,7 @@ event_discard(VRT_CTX, void *priv)
 	(void)priv;
 
 	VRT_RemoveVFP(ctx, &xyzzy_rot13);
+	VRT_RemoveVDP(ctx, &xyzzy_vdp_rot13);
 
 	if (--loads)
 		return (0);


More information about the varnish-commit mailing list