From 3817a323906d3b8df9fce3acc4e0da3d1742a6f0 Mon Sep 17 00:00:00 2001 From: phk Date: Tue, 17 Jun 2008 07:24:20 +0000 Subject: [PATCH] Add a vsb_newauto() macro git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2713 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishtest/t001.vtc | 8 +++- varnish-cache/bin/varnishtest/vtc_varnish.c | 45 ++++++++++++++++++++- varnish-cache/include/vsb.h | 1 + 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/varnish-cache/bin/varnishtest/t001.vtc b/varnish-cache/bin/varnishtest/t001.vtc index 347aa98a..4fd00402 100644 --- a/varnish-cache/bin/varnishtest/t001.vtc +++ b/varnish-cache/bin/varnishtest/t001.vtc @@ -2,7 +2,9 @@ # # $Id$ -varnish v1 -arg -launch +varnish v1 -launch + +delay 1 varnish v1 -vcl { backend s1 { @@ -14,6 +16,10 @@ varnish v1 -vcl { } } +delay 1 + +varnish v1 -start + server s1 -repeat 1 { rxreq txresp \ diff --git a/varnish-cache/bin/varnishtest/vtc_varnish.c b/varnish-cache/bin/varnishtest/vtc_varnish.c index f48504fa..ffa438fa 100644 --- a/varnish-cache/bin/varnishtest/vtc_varnish.c +++ b/varnish-cache/bin/varnishtest/vtc_varnish.c @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -70,6 +71,7 @@ struct varnish { struct vss_addr **vss_addr; int cli_fd; + int vcl_nbr; }; static VTAILQ_HEAD(, varnish) varnishes = @@ -233,6 +235,42 @@ varnish_stop(struct varnish *v) close(v->fds[1]); } +/********************************************************************** + * 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 @@ cmd_varnish(char **av, void *priv) 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); } } diff --git a/varnish-cache/include/vsb.h b/varnish-cache/include/vsb.h index 82699447..aa1836c7 100644 --- a/varnish-cache/include/vsb.h +++ b/varnish-cache/include/vsb.h @@ -57,6 +57,7 @@ extern "C" { * 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); -- 2.39.5