]> err.no Git - varnish/commitdiff
Test that we know the purge variable when it is compiled in.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sat, 24 Jan 2009 12:56:27 +0000 (12:56 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sat, 24 Jan 2009 12:56:27 +0000 (12:56 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3543 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishtest/tests/c00022.vtc
varnish-cache/lib/libvcl/vcc_action.c

index d8f0b8a7e349ca887d2c950fe0a112b207ca5b38..d893e953e03e07bbc4f0eca807babe867f51cb28 100644 (file)
@@ -33,6 +33,26 @@ varnish v1 -vcl+backend {
        }
 } -start
 
+# Trigger syntax check 
+varnish v1 -badvcl {
+       backend foo {
+               .host = "127.0.0.1";
+       }
+       sub vcl_recv {
+               purge (req.foo == req.url);
+       }
+}
+
+# Trigger syntax check 
+varnish v1 -badvcl {
+       backend foo {
+               .host = "127.0.0.1";
+       }
+       sub vcl_recv {
+               purge (req.http. == req.url);
+       }
+}
+
 # Fetch into cache
 client c1 {
        txreq -url "/foo"
index d6dd0c9e5d2eacd882dd49bf599ee9ea5c366ebe..aa5460936ce01f33b3f42d6212b5de3fce1fe959 100644 (file)
@@ -32,6 +32,7 @@
 #include "config.h"
 
 #include <stdio.h>
+#include <string.h>
 
 #include "vsb.h"
 
@@ -347,13 +348,23 @@ parse_unset(struct tokenlist *tl)
 
 /*--------------------------------------------------------------------*/
 
+static const struct purge_var {
+       const char      *name;
+       unsigned        flag;
+} purge_var[] = {
+#define PVAR(a, b, c)   { a, b },
+#include "purge_vars.h"
+#undef PVAR     
+        { 0, 0 }
+};
+
 static void
 parse_purge(struct tokenlist *tl)
 {
+       const struct purge_var *pv;
 
        vcc_NextToken(tl);
 
-
        Expect(tl, '(');
        vcc_NextToken(tl);
 
@@ -362,6 +373,25 @@ parse_purge(struct tokenlist *tl)
                tl->indent += INDENT;
                while (1) {
                        ExpectErr(tl, VAR);
+
+                       /* Check valididity of purge variable */
+                       for (pv = purge_var; pv->name != NULL; pv++) {
+                               if (!strncmp(pv->name, tl->t->b,
+                                   strlen(pv->name)))
+                                       break;
+                       }
+                       if (pv->name == NULL) {
+                               vsb_printf(tl->sb, "Unknown purge variable.");
+                               vcc_ErrWhere(tl, tl->t);
+                               return;
+                       }
+                       if (pv->flag &&
+                           tl->t->b + strlen(pv->name) >= tl->t->e) {
+                               vsb_printf(tl->sb, "Missing header name.");
+                               vcc_ErrWhere(tl, tl->t);
+                               return;
+                       }
+
                        Fb(tl, 1, "  \"%.*s\",\n", PF(tl->t));
                        vcc_NextToken(tl);
                        switch(tl->t->tok) {