From: cecilihf Date: Wed, 25 Jul 2007 08:39:10 +0000 (+0000) Subject: Implemented http purge with regexp. Example vcl usage: X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=aecff48b28c94a3e734e3beca7421df6640eaa69;p=varnish Implemented http purge with regexp. Example vcl usage: sub vcl_recv { if (req.request == "REPURGE") { purge(req.url); error 404 "Purged"; } } git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1761 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache_ban.c b/varnish-cache/bin/varnishd/cache_ban.c index c16fc772..ffc60377 100644 --- a/varnish-cache/bin/varnishd/cache_ban.c +++ b/varnish-cache/bin/varnishd/cache_ban.c @@ -40,6 +40,7 @@ #include "shmlog.h" #include "cli_priv.h" #include "cache.h" +#include "vrt.h" struct ban { TAILQ_ENTRY(ban) list; @@ -114,3 +115,9 @@ BAN_Init(void) AddBan("a"); } + +void +VRT_repurge(const char *regexp) +{ + AddBan(regexp); +} diff --git a/varnish-cache/include/vrt.h b/varnish-cache/include/vrt.h index 7943e141..b3f7e090 100644 --- a/varnish-cache/include/vrt.h +++ b/varnish-cache/include/vrt.h @@ -70,6 +70,8 @@ int VRT_re_match(const char *, void *re); int VRT_re_test(struct vsb *, const char *, int sub); const char *VRT_regsub(struct sess *sp, const char *, void *, const char *); +void VRT_repurge(const char *); + void VRT_count(struct sess *, unsigned); int VRT_rewrite(const char *, const char *); void VRT_error(struct sess *, unsigned, const char *); diff --git a/varnish-cache/lib/libvcl/vcc_action.c b/varnish-cache/lib/libvcl/vcc_action.c index 5e5d8e90..de9a7e19 100644 --- a/varnish-cache/lib/libvcl/vcc_action.c +++ b/varnish-cache/lib/libvcl/vcc_action.c @@ -261,6 +261,28 @@ parse_remove(struct tokenlist *tl) vcc_NextToken(tl); } +/*--------------------------------------------------------------------*/ + +static void +parse_repurge(struct tokenlist *tl) +{ + vcc_NextToken(tl); + + Fb(tl, 0, "VRT_repurge("); + + Expect(tl, '('); + vcc_NextToken(tl); + + if (!vcc_StringVal(tl)) { + vcc_ExpectedStringval(tl); + } + + Expect(tl, ')'); + vcc_NextToken(tl); + Fb(tl, 0, ");"); +} + + /*--------------------------------------------------------------------*/ typedef void action_f(struct tokenlist *tl); @@ -277,6 +299,7 @@ static struct action_table { { "call", parse_call }, { "set", parse_set }, { "remove", parse_remove }, + { "purge", parse_repurge }, { NULL, NULL } }; diff --git a/varnish-cache/lib/libvcl/vcc_fixed_token.c b/varnish-cache/lib/libvcl/vcc_fixed_token.c index 0e533e73..630d2934 100644 --- a/varnish-cache/lib/libvcl/vcc_fixed_token.c +++ b/varnish-cache/lib/libvcl/vcc_fixed_token.c @@ -426,6 +426,8 @@ vcl_output_lang_h(struct vsb *sb) vsb_cat(sb, "int VRT_re_test(struct vsb *, const char *, int sub);\n"); vsb_cat(sb, "const char *VRT_regsub(struct sess *sp, const char *, void *, const char *);\n"); vsb_cat(sb, "\n"); + vsb_cat(sb, "void VRT_repurge(const char *);\n"); + vsb_cat(sb, "\n"); vsb_cat(sb, "void VRT_count(struct sess *, unsigned);\n"); vsb_cat(sb, "int VRT_rewrite(const char *, const char *);\n"); vsb_cat(sb, "void VRT_error(struct sess *, unsigned, const char *);\n");