Commit e0ae8e73 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add a vsb_newauto() macro



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@2713 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 007a381d
......@@ -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 \
......
......@@ -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 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);
}
}
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment