]> err.no Git - varnish/commitdiff
Add a vsb_newauto() macro
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 17 Jun 2008 07:24:20 +0000 (07:24 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 17 Jun 2008 07:24:20 +0000 (07:24 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2713 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishtest/t001.vtc
varnish-cache/bin/varnishtest/vtc_varnish.c
varnish-cache/include/vsb.h

index 347aa98a959d39e98d4108ed3bb7a27ebbd10b04..4fd00402c70e5ef9775931fc4a32aaab9f85646a 100644 (file)
@@ -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 \
index f48504fafde27fb2af183dd6af0f5ba48945d338..ffa438faf50143835882e5e078a871de1ee25c5f 100644 (file)
@@ -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);
        }
 }
index 8269944723ede5018b63b0000dc23c3621d7c37e..aa1836c7127c985ffda1f62d3f8062163eae1948 100644 (file)
@@ -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);