[4.1] 241a64d Make event handling more readable in vmod-debug

Lasse Karstensen lkarsten at varnish-software.com
Thu Jan 14 15:15:08 CET 2016


commit 241a64dcdf009096acd6ac47f84eda146621dbe6
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Sat Dec 5 15:48:30 2015 +0100

    Make event handling more readable in vmod-debug

diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c
index b065b7f..9b3449c 100644
--- a/lib/libvmod_debug/vmod_debug.c
+++ b/lib/libvmod_debug/vmod_debug.c
@@ -249,23 +249,10 @@ priv_vcl_free(void *priv)
 	AZ(priv_vcl);
 }
 
-int __match_proto__(vmod_event_f)
-event_function(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e e)
+static int
+event_load(VRT_CTX, struct vmod_priv *priv)
 {
 	struct priv_vcl *priv_vcl;
-	const char *ev;
-
-	switch (e) {
-		case VCL_EVENT_COLD: ev = "VCL_EVENT_COLD"; break;
-		case VCL_EVENT_WARM: ev = "VCL_EVENT_WARM"; break;
-		default: ev = NULL;
-	}
-
-	if (ev != NULL)
-		VSL(SLT_Debug, 0, "%s: %s", VCL_Name(ctx->vcl), ev);
-
-	if (e != VCL_EVENT_LOAD)
-		return (0);
 
 	AN(ctx->msg);
 	if (cache_param->nuke_limit == 42) {
@@ -282,6 +269,40 @@ event_function(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e e)
 	return (0);
 }
 
+static int
+event_warm(VRT_CTX)
+{
+
+	VSL(SLT_Debug, 0, "%s: VCL_EVENT_WARM", VCL_Name(ctx->vcl));
+
+	if (cache_param->max_esi_depth == 42) {
+		VSB_printf(ctx->msg, "max_esi_depth is not the answer.");
+		return (-1);
+	}
+
+	return (0);
+}
+
+static int
+event_cold(VRT_CTX)
+{
+
+	VSL(SLT_Debug, 0, "%s: VCL_EVENT_COLD", VCL_Name(ctx->vcl));
+	return (0);
+}
+
+int __match_proto__(vmod_event_f)
+event_function(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e e)
+{
+
+	switch (e) {
+		case VCL_EVENT_LOAD: return event_load(ctx, priv);
+		case VCL_EVENT_COLD: return event_cold(ctx);
+		case VCL_EVENT_WARM: return event_warm(ctx);
+		default: return (0);
+	}
+}
+
 VCL_VOID __match_proto__(td_debug_sleep)
 vmod_sleep(VRT_CTX, VCL_DURATION t)
 {



More information about the varnish-commit mailing list