]> err.no Git - varnish/commitdiff
Move the purgable variables into a CPP table, so we can share them with
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Thu, 22 Jan 2009 10:42:58 +0000 (10:42 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Thu, 22 Jan 2009 10:42:58 +0000 (10:42 +0000)
the VCL compiler

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@3538 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache_ban.c
varnish-cache/include/purge_vars.h [new file with mode: 0644]

index 39732c8dde888a765903afc1d8c0504d7304d97b..ade27a1bfd9f07348bafea816014b55093d410c1 100644 (file)
@@ -297,11 +297,23 @@ ban_parse_http(struct ban_test *bt, const char *a1)
        bt->src[l + 2] = '\0';
 }
 
+static const struct pvar {
+       const char              *name;
+       unsigned                flag;
+       ban_cond_f              *func;
+} pvars[] = {
+#define PVAR(a, b, c)  { a, b, c },
+#include "purge_vars.h"
+#undef PVAR
+       { 0, 0, 0}
+};
+
 static int
 ban_parse_test(struct cli *cli, struct ban *b, const char *a1, const char *a2, const char *a3)
 {
        struct ban_test *bt;
        struct vsb *sb;
+       const struct pvar *pv;
        int i;
 
        CHECK_OBJ_NOTNULL(b, BAN_MAGIC);
@@ -336,17 +348,15 @@ ban_parse_test(struct cli *cli, struct ban *b, const char *a1, const char *a2, c
        }
 
 
-       if (!strcmp(a1, "req.url"))
-               bt->func = ban_cond_url;
-       else if (!strcmp(a1, "obj.hash"))
-               bt->func = ban_cond_hash;
-       else if (!strncmp(a1, "req.http.", 9)) {
-               bt->func = ban_cond_req_http;
-               ban_parse_http(bt, a1 + 9);
-       } else if (!strncmp(a1, "obj.http.", 9)) {
-               bt->func = ban_cond_obj_http;
-               ban_parse_http(bt, a1 + 9);
-       } else {
+       for (pv = pvars; pv->name != NULL; pv++) {
+               if (strncmp(a1, pv->name, strlen(pv->name)))
+                       continue;
+               bt->func = pv->func;
+               if (pv->flag & 1) 
+                       ban_parse_http(bt, a1 + strlen(pv->name));
+               break;
+       }
+       if (pv->name == NULL) {
                cli_out(cli, "unknown or unsupported field \"%s\"", a1);
                cli_result(cli, CLIS_PARAM);
                return (-1);
diff --git a/varnish-cache/include/purge_vars.h b/varnish-cache/include/purge_vars.h
new file mode 100644 (file)
index 0000000..775af7d
--- /dev/null
@@ -0,0 +1,36 @@
+/*-
+ * Copyright (c) 2008 Linpro AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $Id$
+ *
+ * Define which variables we can purge on, and which function does it.
+ */
+
+PVAR("req.url",                0, ban_cond_url)
+PVAR("obj.hash",       0, ban_cond_hash)
+PVAR("req.http.",      1, ban_cond_req_http)
+PVAR("obj.http.",      1, ban_cond_obj_http)