[master] a20b6af Add a new VMOD.debug and move the stuff varnishtest uses to get out into the obscure corners over there, making vmod.std a better copy& paste example and removing things like "panic" from the VCC.

Poul-Henning Kamp phk at varnish-cache.org
Mon Jun 18 11:51:11 CEST 2012


commit a20b6af4f1d5353132d07d4baae6d9e9c822f896
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Jun 18 09:50:18 2012 +0000

    Add a new VMOD.debug and move the stuff varnishtest uses to get out
    into the obscure corners over there, making vmod.std a better copy&
    paste example and removing things like "panic" from the VCC.

diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index d227949..f172769 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -385,21 +385,6 @@ VRT_Rollback(const struct sess *sp)
 /*--------------------------------------------------------------------*/
 
 void
-VRT_panic(struct req *req, const char *str, ...)
-{
-	va_list ap;
-	char *b;
-
-	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
-	va_start(ap, str);
-	b = VRT_String(req->http->ws, "PANIC: ", str, ap);
-	va_end(ap);
-	VAS_Fail("VCL", "", 0, b, 0, 2);
-}
-
-/*--------------------------------------------------------------------*/
-
-void
 VRT_synth_page(struct req *req, unsigned flags, const char *str, ...)
 {
 	va_list ap;
diff --git a/bin/varnishd/flint.sh b/bin/varnishd/flint.sh
index 9067263..c32c01b 100755
--- a/bin/varnishd/flint.sh
+++ b/bin/varnishd/flint.sh
@@ -25,6 +25,7 @@ flexelint \
 	../../lib/libvarnishcompat/execinfo.c \
 	../../lib/libvcl/*.c \
 	../../lib/libvmod_std/*.c \
+	../../lib/libvmod_debug/*.c \
 	2>&1 | tee _.fl
 
 if [ -f _.fl.old ] ; then
diff --git a/bin/varnishtest/tests/m00000.vtc b/bin/varnishtest/tests/m00000.vtc
index 7fe2b8c..504601b 100644
--- a/bin/varnishtest/tests/m00000.vtc
+++ b/bin/varnishtest/tests/m00000.vtc
@@ -1,4 +1,4 @@
-varnishtest "Test std vmod"
+varnishtest "Test std & debug vmod"
 
 server s1 {
 	rxreq 
@@ -7,11 +7,14 @@ server s1 {
 
 varnish v1 -vcl+backend {
 	import std from "${topbuild}/lib/libvmod_std/.libs/libvmod_std.so" ;
+	import debug from "${topbuild}/lib/libvmod_debug/.libs/libvmod_debug.so" ;
 
 	sub vcl_deliver {
 		set resp.http.foo = std.toupper(resp.http.foo);
 		set resp.http.bar = std.tolower(resp.http.bar);
-		set resp.http.who = std.author(phk);
+		set resp.http.who = debug.author(phk);
+		debug.test_priv_call();
+		debug.test_priv_vcl();
 		std.log("VCL initiated log");
 		std.syslog(8 + 7, "Somebody runs varnishtest");
 	}
@@ -27,9 +30,9 @@ client c1 {
 } -run
 
 varnish v1 -badvcl {
-	import std from "${topbuild}/lib/libvmod_std/.libs/libvmod_std.so.1" ;
+	import debug from "${topbuild}/lib/libvmod_debug/.libs/libvmod_debug.so.1" ;
 	sub vcl_deliver {
-		set resp.http.who = std.author(jfk);
+		set resp.http.who = debug.author(jfk);
 	}
 }
 
diff --git a/bin/varnishtest/tests/r00878.vtc b/bin/varnishtest/tests/r00878.vtc
index 6997189..55106c9 100644
--- a/bin/varnishtest/tests/r00878.vtc
+++ b/bin/varnishtest/tests/r00878.vtc
@@ -6,9 +6,9 @@ server s1 {
 } -start
 
 varnish v1 -vcl+backend {
-        import std from "${topbuild}/lib/libvmod_std/.libs/libvmod_std.so" ;
+        import debug from "${topbuild}/lib/libvmod_debug/.libs/libvmod_debug.so" ;
 	sub vcl_deliver {
-		set resp.http.who = std.author(phk);
+		set resp.http.who = debug.author(phk);
 	}
 } -start
 
@@ -18,9 +18,9 @@ client c1 {
 	rxresp
 } -run
 varnish v1 -vcl+backend {
-        import std from "${topbuild}/lib/libvmod_std/.libs/libvmod_std.so" ;
+        import debug from "${topbuild}/lib/libvmod_debug/.libs/libvmod_debug.so" ;
 	sub vcl_deliver {
-		set resp.http.who = std.author(des);
+		set resp.http.who = debug.author(des);
 	}
 }
 
@@ -30,9 +30,9 @@ client c1 {
 } -run
 
 varnish v1 -vcl+backend {
-        import std from "${topbuild}/lib/libvmod_std/.libs/libvmod_std.so" ;
+        import debug from "${topbuild}/lib/libvmod_debug/.libs/libvmod_debug.so" ;
 	sub vcl_deliver {
-		set resp.http.who = std.author(kristian);
+		set resp.http.who = debug.author(kristian);
 	}
 }
 
diff --git a/bin/varnishtest/tests/v00010.vtc b/bin/varnishtest/tests/v00010.vtc
index b44fc13..46d778c 100644
--- a/bin/varnishtest/tests/v00010.vtc
+++ b/bin/varnishtest/tests/v00010.vtc
@@ -15,9 +15,11 @@ server s1 {
 
 varnish v1 -storage "-smalloc,1m" -vcl+backend {
 
+	import debug from "${topbuild}/lib/libvmod_debug/.libs/libvmod_debug.so";
+
 	sub vcl_deliver {
 		if (resp.http.panic) {
-			panic "Had Panic header: " + resp.http.panic;
+			debug.panic("Had Panic header: " + resp.http.panic);
 		}
 	}
 } -start
diff --git a/bin/varnishtest/tests/v00018.vtc b/bin/varnishtest/tests/v00018.vtc
index 2c129d7..d1c0d5f 100644
--- a/bin/varnishtest/tests/v00018.vtc
+++ b/bin/varnishtest/tests/v00018.vtc
@@ -101,11 +101,6 @@ varnish v1 -vcl {
 
 varnish v1 -badvcl {
 	backend b { .host = "127.0.0.1"; }
-	sub vcl_recv { panic if; }
-}
-
-varnish v1 -badvcl {
-	backend b { .host = "127.0.0.1"; }
 	sub vcl_recv { kluf ; }
 }
 
diff --git a/configure.ac b/configure.ac
index 3df1e7d..2791fd9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -550,6 +550,7 @@ AC_CONFIG_FILES([
     lib/libvarnishcompat/Makefile
     lib/libvcl/Makefile
     lib/libvgz/Makefile
+    lib/libvmod_debug/Makefile
     lib/libvmod_std/Makefile
     lib/libjemalloc/Makefile
     man/Makefile
diff --git a/include/vrt.h b/include/vrt.h
index 50d4d8b..834f972 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -150,7 +150,6 @@ int VRT_re_match(struct req *, const char *, void *re);
 const char *VRT_regsub(struct req *, int all, const char *,
     void *, const char *);
 
-void VRT_panic(struct req *req, const char *, ...);
 void VRT_ban(struct sess *sp, char *, ...);
 void VRT_ban_string(struct sess *sp, const char *);
 void VRT_purge(const struct sess *sp, double ttl, double grace);
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 21146dc..72bc0f8 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -6,6 +6,7 @@ SUBDIRS = \
 	libvarnishapi \
 	libvcl \
 	libvgz \
+	libvmod_debug \
 	libvmod_std \
 	@JEMALLOC_SUBDIR@
 
diff --git a/lib/libvcl/vcc_action.c b/lib/libvcl/vcc_action.c
index d60b885..81cf597 100644
--- a/lib/libvcl/vcc_action.c
+++ b/lib/libvcl/vcc_action.c
@@ -234,19 +234,6 @@ parse_hash_data(struct vcc *tl)
 /*--------------------------------------------------------------------*/
 
 static void
-parse_panic(struct vcc *tl)
-{
-	vcc_NextToken(tl);
-
-	Fb(tl, 1, "VRT_panic(req, ");
-	vcc_Expr(tl, STRING);
-	ERRCHK(tl);
-	Fb(tl, 0, ", vrt_magic_string_end);\n");
-}
-
-/*--------------------------------------------------------------------*/
-
-static void
 parse_return(struct vcc *tl)
 {
 	int retval = 0;
@@ -331,7 +318,6 @@ static struct action_table {
 	/* Keep list sorted from here */
 	{ "call",		parse_call },
 	{ "hash_data",		parse_hash_data, VCL_MET_HASH },
-	{ "panic",		parse_panic },
 	{ "ban",		parse_ban },
 	{ "ban_url",		parse_ban_url },
 	{ "remove",		parse_unset }, /* backward compatibility */
diff --git a/lib/libvmod_debug/Makefile.am b/lib/libvmod_debug/Makefile.am
new file mode 100644
index 0000000..3a342b5
--- /dev/null
+++ b/lib/libvmod_debug/Makefile.am
@@ -0,0 +1,25 @@
+#
+
+INCLUDES = \
+	-I$(top_srcdir)/include \
+	-I$(top_srcdir)/bin/varnishd \
+	-I$(top_builddir)/include
+
+vmoddir = $(pkglibdir)/vmods
+vmod_srcdir = $(top_srcdir)/lib/libvmod_debug
+vmodtool = $(top_srcdir)/lib/libvcl/vmodtool.py
+vmod_LTLIBRARIES = libvmod_debug.la
+
+libvmod_debug_la_LDFLAGS = -module -export-dynamic -avoid-version
+
+libvmod_debug_la_SOURCES = \
+	vcc_if.c \
+	vcc_if.h \
+	vmod_debug.c
+
+vcc_if.c vcc_if.h: $(vmodtool) $(vmod_srcdir)/vmod.vcc
+	@PYTHON@ $(vmodtool) $(vmod_srcdir)/vmod.vcc
+
+EXTRA_DIST = vmod.vcc
+
+CLEANFILES = $(builddir)/vcc_if.c $(builddir)/vcc_if.h
diff --git a/lib/libvmod_debug/vmod.vcc b/lib/libvmod_debug/vmod.vcc
new file mode 100644
index 0000000..2e3c33e
--- /dev/null
+++ b/lib/libvmod_debug/vmod.vcc
@@ -0,0 +1,33 @@
+#-
+# Copyright (c) 2010-2011 Varnish Software AS
+# All rights reserved.
+#
+# Author: Poul-Henning Kamp <phk at FreeBSD.org>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+
+Module debug
+Init init_function
+Function VOID panic(STRING_LIST)
+Function STRING author(ENUM { phk, des, kristian, mithrandir })
+Function VOID test_priv_call(PRIV_CALL)
+Function VOID test_priv_vcl(PRIV_VCL)
diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c
new file mode 100644
index 0000000..309664a
--- /dev/null
+++ b/lib/libvmod_debug/vmod_debug.c
@@ -0,0 +1,97 @@
+/*-
+ * Copyright (c) 2012 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at FreeBSD.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+
+#include "cache/cache.h"
+
+#include "vrt.h"
+#include "vcc_if.h"
+
+void
+vmod_panic(struct sess *sp, const char *str, ...)
+{
+	va_list ap;
+	char *b;
+
+	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+	va_start(ap, str);
+	b = VRT_String(sp->req->http->ws, "PANIC: ", str, ap);
+	va_end(ap);
+	VAS_Fail("VCL", "", 0, b, 0, 2);
+}
+
+const char * __match_proto__()
+vmod_author(struct sess *sp, const char *id)
+{
+
+	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+	if (!strcmp(id, "phk"))
+		return ("Poul-Henning");
+	if (!strcmp(id, "des"))
+		return ("Dag-Erling");
+	if (!strcmp(id, "kristian"))
+		return ("Kristian");
+	if (!strcmp(id, "mithrandir"))
+		return ("Tollef");
+	WRONG("Illegal VMOD enum");
+}
+
+int
+init_function(struct vmod_priv *priv, const struct VCL_conf *cfg)
+{
+	(void)cfg;
+
+	priv->priv = strdup("FOO");
+	priv->free = free;
+	return (0);
+}
+
+void
+vmod_test_priv_call(struct sess *sp, struct vmod_priv *priv)
+{
+
+	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+	if (priv->priv == NULL) {
+		priv->priv = strdup("BAR");
+		priv->free = free;
+	} else {
+		assert(!strcmp(priv->priv, "BAR"));
+	}
+}
+
+void
+vmod_test_priv_vcl(struct sess *sp, struct vmod_priv *priv)
+{
+
+        CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+        assert(!strcmp(priv->priv, "FOO"));
+}
+
diff --git a/lib/libvmod_std/vmod.vcc b/lib/libvmod_std/vmod.vcc
index 0a71e5b..3238164 100644
--- a/lib/libvmod_std/vmod.vcc
+++ b/lib/libvmod_std/vmod.vcc
@@ -26,15 +26,13 @@
 # SUCH DAMAGE.
 
 Module std
-Init init_function
-Function STRING toupper(PRIV_CALL, STRING_LIST)
-Function STRING tolower(PRIV_VCL, STRING_LIST)
+Function STRING toupper(STRING_LIST)
+Function STRING tolower(STRING_LIST)
 Function VOID set_ip_tos(INT)
 Function REAL random(REAL, REAL)
 Function VOID log(STRING_LIST)
 Function VOID syslog(INT, STRING_LIST)
 Function STRING fileread(PRIV_CALL, STRING)
-Function STRING author(ENUM { phk, des, kristian, mithrandir })
 Function DURATION duration(STRING, DURATION)
 Function INT integer(STRING, INT)
 Function VOID collect(HEADER)
diff --git a/lib/libvmod_std/vmod_std.c b/lib/libvmod_std/vmod_std.c
index 8ae9ec1..c8937f6 100644
--- a/lib/libvmod_std/vmod_std.c
+++ b/lib/libvmod_std/vmod_std.c
@@ -89,18 +89,12 @@ vmod_updown(struct sess *sp, int up, const char *s, va_list ap)
 }
 
 const char * __match_proto__()
-vmod_toupper(struct sess *sp, struct vmod_priv *priv, const char *s, ...)
+vmod_toupper(struct sess *sp, const char *s, ...)
 {
 	const char *p;
 	va_list ap;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	if (priv->priv == NULL) {
-		priv->priv = strdup("BAR");
-		priv->free = free;
-	} else {
-		assert(!strcmp(priv->priv, "BAR"));
-	}
 	va_start(ap, s);
 	p = vmod_updown(sp, 1, s, ap);
 	va_end(ap);
@@ -108,29 +102,18 @@ vmod_toupper(struct sess *sp, struct vmod_priv *priv, const char *s, ...)
 }
 
 const char * __match_proto__()
-vmod_tolower(struct sess *sp, struct vmod_priv *priv, const char *s, ...)
+vmod_tolower(struct sess *sp, const char *s, ...)
 {
 	const char *p;
 	va_list ap;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	assert(!strcmp(priv->priv, "FOO"));
 	va_start(ap, s);
 	p = vmod_updown(sp, 0, s, ap);
 	va_end(ap);
 	return (p);
 }
 
-int
-init_function(struct vmod_priv *priv, const struct VCL_conf *cfg)
-{
-	(void)cfg;
-
-	priv->priv = strdup("FOO");
-	priv->free = free;
-	return (0);
-}
-
 double
 vmod_random(struct sess *sp, double lo, double hi)
 {
@@ -181,21 +164,6 @@ vmod_syslog(struct sess *sp, int fac, const char *fmt, ...)
 	WS_Release(sp->req->ws, 0);
 }
 
-const char * __match_proto__()
-vmod_author(struct sess *sp, const char *id)
-{
-	(void)sp;
-	if (!strcmp(id, "phk"))
-		return ("Poul-Henning");
-	if (!strcmp(id, "des"))
-		return ("Dag-Erling");
-	if (!strcmp(id, "kristian"))
-		return ("Kristian");
-	if (!strcmp(id, "mithrandir"))
-		return ("Tollef");
-	WRONG("Illegal VMOD enum");
-}
-
 void __match_proto__()
 vmod_collect(struct sess *sp, enum gethdr_e e, const char *h)
 {



More information about the varnish-commit mailing list