r2713 - in trunk/varnish-cache: bin/varnishtest include

phk at projects.linpro.no phk at projects.linpro.no
Tue Jun 17 09:24:20 CEST 2008


Author: phk
Date: 2008-06-17 09:24:20 +0200 (Tue, 17 Jun 2008)
New Revision: 2713

Modified:
   trunk/varnish-cache/bin/varnishtest/t001.vtc
   trunk/varnish-cache/bin/varnishtest/vtc_varnish.c
   trunk/varnish-cache/include/vsb.h
Log:
Add a vsb_newauto() macro



Modified: trunk/varnish-cache/bin/varnishtest/t001.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/t001.vtc	2008-06-17 07:10:14 UTC (rev 2712)
+++ trunk/varnish-cache/bin/varnishtest/t001.vtc	2008-06-17 07:24:20 UTC (rev 2713)
@@ -2,8 +2,10 @@
 #
 # $Id$
 
-varnish v1 -arg -launch
+varnish v1 -launch
 
+delay 1
+
 varnish v1 -vcl {
 	backend s1 {
 		.host = "localhost";
@@ -14,6 +16,10 @@
 	}
 }
 
+delay 1
+
+varnish v1 -start
+
 server s1 -repeat 1 {
 	rxreq 
 	txresp \

Modified: trunk/varnish-cache/bin/varnishtest/vtc_varnish.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc_varnish.c	2008-06-17 07:10:14 UTC (rev 2712)
+++ trunk/varnish-cache/bin/varnishtest/vtc_varnish.c	2008-06-17 07:24:20 UTC (rev 2713)
@@ -30,6 +30,7 @@
 #include <stdio.h>
 
 #include <stdio.h>
+#include <ctype.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
@@ -70,6 +71,7 @@
 	struct vss_addr		**vss_addr;
 
 	int			cli_fd;
+	int			vcl_nbr;
 };
 
 static VTAILQ_HEAD(, varnish)	varnishes =
@@ -234,6 +236,42 @@
 }
 
 /**********************************************************************
+ * Load a VCL program
+ */
+
+static void
+varnish_vcl(struct varnish *v, char *vcl)
+{
+	struct vsb *vsb;
+	unsigned u;
+
+	vsb = vsb_newauto();
+	AN(vsb);
+
+	v->vcl_nbr++;
+	vsb_printf(vsb, "vcl.inline vcl%d \"", v->vcl_nbr);
+	for (; *vcl != '\0'; vcl++) {
+		if (isgraph(*vcl) || *vcl == '\\' || *vcl == '"')
+			vsb_putc(vsb, *vcl);
+		else
+			vsb_printf(vsb, "\\x%02x", *vcl);
+	}
+	vsb_printf(vsb, "\"", *vcl);
+	vsb_finish(vsb);
+	AZ(vsb_overflowed(vsb));
+
+	u = varnish_ask_cli(v, vsb_data(vsb), NULL);
+	assert(u == CLIS_OK);
+	vsb_clear(vsb);
+	vsb_printf(vsb, "vcl.use vcl%d \"", v->vcl_nbr);
+	vsb_finish(vsb);
+	AZ(vsb_overflowed(vsb));
+	u = varnish_ask_cli(v, vsb_data(vsb), NULL);
+	assert(u == CLIS_OK);
+	vsb_delete(vsb);
+}
+
+/**********************************************************************
  * Varnish server cmd dispatch
  */
 
@@ -288,11 +326,16 @@
 			varnish_start(v);
 			continue;
 		}
+		if (!strcmp(*av, "-vcl")) {
+			varnish_vcl(v, av[1]);
+			av++;
+			continue;
+		}
 		if (!strcmp(*av, "-stop")) {
 			varnish_stop(v);
 			continue;
 		}
-		fprintf(stderr, "Unknown client argument: %s\n", *av);
+		fprintf(stderr, "Unknown varnish argument: %s\n", *av);
 		exit (1);
 	}
 }

Modified: trunk/varnish-cache/include/vsb.h
===================================================================
--- trunk/varnish-cache/include/vsb.h	2008-06-17 07:10:14 UTC (rev 2712)
+++ trunk/varnish-cache/include/vsb.h	2008-06-17 07:24:20 UTC (rev 2713)
@@ -57,6 +57,7 @@
  * API functions
  */
 struct vsb	*vsb_new(struct vsb *, char *, int, int);
+#define vsb_newauto()	vsb_new(NULL, NULL, 0, VSB_AUTOEXTEND)
 void		 vsb_clear(struct vsb *);
 int		 vsb_setpos(struct vsb *, int);
 int		 vsb_bcat(struct vsb *, const void *, size_t);




More information about the varnish-commit mailing list