[master] 4f4b550 Enable -b and -c options to VSL

Martin Blix Grydeland martin at varnish-cache.org
Wed Oct 2 17:05:01 CEST 2013


commit 4f4b5503815484773a774fdd50c1503e4397c115
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Wed Oct 2 16:57:38 2013 +0200

    Enable -b and -c options to VSL

diff --git a/include/vapi/vapi_options.h b/include/vapi/vapi_options.h
index c9e6e02..fae7fdd 100644
--- a/include/vapi/vapi_options.h
+++ b/include/vapi/vapi_options.h
@@ -53,6 +53,18 @@
 	    " than overwrite it."					\
 	)
 
+#define VSL_OPT_b							\
+	VOPT("b", "[-b]", "Only display backend records",		\
+	    "Only display transactions and log records coming from"	\
+	    " backend communication."					\
+	)
+
+#define VSL_OPT_c							\
+	VOPT("c", "[-c]", "Only display client records",		\
+	    "Only display transactions and log records coming from"	\
+	    " client communication."					\
+	)
+
 #define VSL_OPT_d \
 	VOPT("d", "[-d]", "Process old log entries on startup",		\
 	    "Start processing log records at the head of the log"	\
diff --git a/lib/libvarnishapi/vsl.c b/lib/libvarnishapi/vsl.c
index fb8e67a..93e731a 100644
--- a/lib/libvarnishapi/vsl.c
+++ b/lib/libvarnishapi/vsl.c
@@ -188,6 +188,10 @@ VSL_Match(struct VSL_data *vsl, const struct VSL_cursor *c)
 	tag = VSL_TAG(c->rec.ptr);
 	if (tag <= SLT__Bogus || tag >= SLT__Reserved)
 		return (0);
+	if (vsl->c_opt && !VSL_CLIENT(c->rec.ptr))
+		return (0);
+	if (vsl->b_opt && !VSL_BACKEND(c->rec.ptr))
+		return (0);
 	if (!VTAILQ_EMPTY(&vsl->vslf_select) &&
 	    vsl_match_IX(vsl, &vsl->vslf_select, c))
 		return (1);
@@ -323,8 +327,25 @@ VSL_PrintTransactions(struct VSL_data *vsl, struct VSL_transaction * const pt[],
 	if (pt[0] == NULL)
 		return (0);
 
-	t = pt[0];
-	while (t) {
+	for (t = pt[0]; t != NULL; t = *++pt) {
+		if (vsl->c_opt || vsl->b_opt) {
+			switch (t->type) {
+			case VSL_t_req:
+			case VSL_t_esireq:
+				if (!vsl->c_opt)
+					continue;
+				break;
+			case VSL_t_bereq:
+				if (!vsl->b_opt)
+					continue;
+				break;
+			case VSL_t_raw:
+				break;
+			default:
+				continue;
+			}
+		}
+
 		verbose = 0;
 		if (t->level == 0 || vsl->v_opt)
 			verbose = 1;
@@ -363,7 +384,6 @@ VSL_PrintTransactions(struct VSL_data *vsl, struct VSL_transaction * const pt[],
 			if (i != 0)
 				return (i);
 		}
-		t = *++pt;
 	}
 
 	if (delim)
diff --git a/lib/libvarnishapi/vsl_api.h b/lib/libvarnishapi/vsl_api.h
index 65007fd..53984c3 100644
--- a/lib/libvarnishapi/vsl_api.h
+++ b/lib/libvarnishapi/vsl_api.h
@@ -88,6 +88,8 @@ struct VSL_data {
 	vslf_list			vslf_select;
 	vslf_list			vslf_suppress;
 
+	int				b_opt;
+	int				c_opt;
 	int				v_opt;
 };
 
diff --git a/lib/libvarnishapi/vsl_arg.c b/lib/libvarnishapi/vsl_arg.c
index 6babd06..dad558d 100644
--- a/lib/libvarnishapi/vsl_arg.c
+++ b/lib/libvarnishapi/vsl_arg.c
@@ -320,6 +320,8 @@ VSL_Arg(struct VSL_data *vsl, int opt, const char *arg)
 			vbit_set(vsl->vbm_supress, i);
 
 	switch (opt) {
+	case 'b': vsl->b_opt = 1; return (1);
+	case 'c': vsl->c_opt = 1; return (1);
 	case 'i': case 'x': return (vsl_ix_arg(vsl, opt, arg));
 	case 'I': case 'X': return (vsl_IX_arg(vsl, opt, arg));
 	case 'v': vsl->v_opt = 1; return (1);



More information about the varnish-commit mailing list