From 69c45c646de984631e3603a44898a5769ba090b4 Mon Sep 17 00:00:00 2001 From: phk Date: Thu, 22 Jan 2009 10:42:58 +0000 Subject: [PATCH] Move the purgable variables into a CPP table, so we can share them with 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 | 32 +++++++++++++++-------- varnish-cache/include/purge_vars.h | 36 ++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 11 deletions(-) create mode 100644 varnish-cache/include/purge_vars.h diff --git a/varnish-cache/bin/varnishd/cache_ban.c b/varnish-cache/bin/varnishd/cache_ban.c index 39732c8d..ade27a1b 100644 --- a/varnish-cache/bin/varnishd/cache_ban.c +++ b/varnish-cache/bin/varnishd/cache_ban.c @@ -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 index 00000000..775af7d9 --- /dev/null +++ b/varnish-cache/include/purge_vars.h @@ -0,0 +1,36 @@ +/*- + * Copyright (c) 2008 Linpro AS + * All rights reserved. + * + * Author: Poul-Henning Kamp + * + * 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) -- 2.39.5