r3723 - in branches/2.0/varnish-cache: bin/varnishd include lib/libvcl
tfheen at projects.linpro.no
tfheen at projects.linpro.no
Tue Feb 10 15:50:53 CET 2009
Author: tfheen
Date: 2009-02-10 15:50:53 +0100 (Tue, 10 Feb 2009)
New Revision: 3723
Modified:
branches/2.0/varnish-cache/bin/varnishd/cache.h
branches/2.0/varnish-cache/bin/varnishd/cache_ban.c
branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c
branches/2.0/varnish-cache/include/vrt.h
branches/2.0/varnish-cache/lib/libvcl/vcc_action.c
branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c
Log:
Merge r3541: First cut at VCL support for new-purge.
Modified: branches/2.0/varnish-cache/bin/varnishd/cache.h
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-10 14:47:36 UTC (rev 3722)
+++ branches/2.0/varnish-cache/bin/varnishd/cache.h 2009-02-10 14:50:53 UTC (rev 3723)
@@ -417,7 +417,10 @@
void VBP_Init(void);
/* cache_ban.c */
-int BAN_Add(struct cli *cli, const char *regexp, int hash);
+struct ban *BAN_New(void);
+int BAN_AddTest(struct cli *, struct ban *, const char *, const char *, const char *);
+void BAN_Free(struct ban *b);
+void BAN_Insert(struct ban *b);
void BAN_Init(void);
void BAN_NewObj(struct object *o);
void BAN_DestroyObj(struct object *o);
Modified: branches/2.0/varnish-cache/bin/varnishd/cache_ban.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-10 14:47:36 UTC (rev 3722)
+++ branches/2.0/varnish-cache/bin/varnishd/cache_ban.c 2009-02-10 14:50:53 UTC (rev 3723)
@@ -95,8 +95,8 @@
* Manipulation of bans
*/
-static struct ban *
-ban_new_ban(void)
+struct ban *
+BAN_New(void)
{
struct ban *b;
ALLOC_OBJ(b, BAN_MAGIC);
@@ -140,8 +140,8 @@
} while (i);
}
-static void
-ban_free_ban(struct ban *b)
+void
+BAN_Free(struct ban *b)
{
struct ban_test *bt;
@@ -308,8 +308,8 @@
{ 0, 0, 0}
};
-static int
-ban_parse_test(struct cli *cli, struct ban *b, const char *a1, const char *a2, const char *a3)
+int
+BAN_AddTest(struct cli *cli, struct ban *b, const char *a1, const char *a2, const char *a3)
{
struct ban_test *bt;
struct vsb *sb;
@@ -387,7 +387,7 @@
*/
static struct ban * volatile ban_start;
-static void
+void
BAN_Insert(struct ban *b)
{
struct ban *bi, *be;
@@ -476,7 +476,7 @@
b = BAN_CheckLast();
Lck_Unlock(&ban_mtx);
if (b != NULL)
- ban_free_ban(b);
+ BAN_Free(b);
}
@@ -564,38 +564,20 @@
}
}
- b = ban_new_ban();
+ b = BAN_New();
if (b == NULL) {
cli_out(cli, "Out of Memory");
cli_result(cli, CLIS_CANT);
return;
}
for (i = 0; i < narg; i += 4)
- if (ban_parse_test(cli, b, av[i + 2], av[i + 3], av[i + 4])) {
- ban_free_ban(b);
+ if (BAN_AddTest(cli, b, av[i + 2], av[i + 3], av[i + 4])) {
+ BAN_Free(b);
return;
}
BAN_Insert(b);
}
-int
-BAN_Add(struct cli *cli, const char *regexp, int hash)
-{
- const char *aav[6];
-
- aav[0] = NULL;
- aav[1] = "purge";
- if (hash)
- aav[2] = "obj.hash";
- else
- aav[2] = "req.url";
- aav[3] = "~";
- aav[4] = regexp;
- aav[5] = NULL;
- ccf_purge(cli, aav, NULL);
- return (0);
-}
-
static void
ccf_purge_url(struct cli *cli, const char * const *av, void *priv)
{
@@ -651,7 +633,7 @@
VTAILQ_LAST(&ban_head, banhead)->refcount++;
Lck_Unlock(&ban_mtx);
if (b != NULL)
- ban_free_ban(b);
+ BAN_Free(b);
} while (b != NULL);
VTAILQ_FOREACH(b, &ban_head, list) {
@@ -692,9 +674,17 @@
void
BAN_Init(void)
{
+ const char *aav[6];
Lck_New(&ban_mtx);
CLI_AddFuncs(PUBLIC_CLI, ban_cmds);
+
/* Add an initial ban, since the list can never be empty */
- (void)BAN_Add(NULL, ".", 0);
+ aav[0] = NULL;
+ aav[1] = "purge";
+ aav[2] = "req.url";
+ aav[3] = "~";
+ aav[4] = ".";
+ aav[5] = NULL;
+ ccf_purge(NULL, aav, NULL);
}
Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c 2009-02-10 14:47:36 UTC (rev 3722)
+++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c 2009-02-10 14:50:53 UTC (rev 3723)
@@ -762,11 +762,35 @@
/*--------------------------------------------------------------------*/
void
-VRT_purge(const char *regexp, int hash)
+VRT_purge(struct sess *sp, char *cmds, ...)
{
+ char *a1, *a2, *a3;
+ va_list ap;
+ struct ban *b;
+ int good;
- if (regexp != NULL)
- (void)BAN_Add(NULL, regexp, hash);
+ (void)sp;
+ b = BAN_New();
+ va_start(ap, cmds);
+ a1 = cmds;
+ good = 0;
+ while (a1 != NULL) {
+ good = 0;
+ a2 = va_arg(ap, char *);
+ if (a2 == NULL)
+ break;
+ a3 = va_arg(ap, char *);
+ if (a3 == NULL)
+ break;
+ if (BAN_AddTest(NULL, b, a1, a2, a3))
+ break;
+ a1 = va_arg(ap, char *);
+ good = 1;
+ }
+ if (!good)
+ BAN_Free(b);
+ else
+ BAN_Insert(b);
}
/*--------------------------------------------------------------------
Modified: branches/2.0/varnish-cache/include/vrt.h
===================================================================
--- branches/2.0/varnish-cache/include/vrt.h 2009-02-10 14:47:36 UTC (rev 3722)
+++ branches/2.0/varnish-cache/include/vrt.h 2009-02-10 14:50:53 UTC (rev 3723)
@@ -141,8 +141,8 @@
const char *VRT_regsub(const struct sess *sp, int all, const char *,
void *, const char *);
-void VRT_panic(struct sess *sp, const char *, ...);
-void VRT_purge(const char *, int hash);
+void VRT_panic(struct sess *sp, const char *, ...);
+void VRT_purge(struct sess *sp, char *, ...);
void VRT_count(const struct sess *, unsigned);
int VRT_rewrite(const char *, const char *);
Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_action.c
===================================================================
--- branches/2.0/varnish-cache/lib/libvcl/vcc_action.c 2009-02-10 14:47:36 UTC (rev 3722)
+++ branches/2.0/varnish-cache/lib/libvcl/vcc_action.c 2009-02-10 14:50:53 UTC (rev 3723)
@@ -348,27 +348,86 @@
/*--------------------------------------------------------------------*/
static void
-parse_purge_url(struct tokenlist *tl)
+parse_purge(struct tokenlist *tl)
{
vcc_NextToken(tl);
- Fb(tl, 1, "VRT_purge(");
Expect(tl, '(');
vcc_NextToken(tl);
+ if (tl->t->tok == VAR) {
+ Fb(tl, 1, "VRT_purge(sp,\n");
+ tl->indent += INDENT;
+ while (1) {
+ ExpectErr(tl, VAR);
+ Fb(tl, 1, " \"%.*s\",\n", PF(tl->t));
+ vcc_NextToken(tl);
+ switch(tl->t->tok) {
+ case '~':
+ case T_NOMATCH:
+ case T_EQ:
+ case T_NEQ:
+ Fb(tl, 1, " \"%.*s\",\n", PF(tl->t));
+ break;
+ default:
+ vsb_printf(tl->sb,
+ "Expected ~, !~, == or !=.\n");
+ vcc_ErrWhere(tl, tl->t);
+ return;
+ }
+ vcc_NextToken(tl);
+ Fb(tl, 1, " ");
+ if (!vcc_StringVal(tl)) {
+ vcc_ExpectedStringval(tl);
+ return;
+ }
+ Fb(tl, 0, ",\n");
+ if (tl->t->tok == ')')
+ break;
+ ExpectErr(tl, T_CAND);
+ Fb(tl, 1, "\"%.*s\",\n", PF(tl->t));
+ vcc_NextToken(tl);
+ }
+ Fb(tl, 1, "0);\n");
+ tl->indent -= INDENT;
+ } else {
+ Fb(tl, 1, "VRT_purge_string(sp, ");
+ if (!vcc_StringVal(tl)) {
+ vcc_ExpectedStringval(tl);
+ return;
+ }
+ do
+ Fb(tl, 0, ", ");
+ while (vcc_StringVal(tl));
+ Fb(tl, 0, ", 0);\n");
+ }
+
+ Expect(tl, ')');
+ vcc_NextToken(tl);
+}
+
+/*--------------------------------------------------------------------*/
+
+static void
+parse_purge_url(struct tokenlist *tl)
+{
+
+ vcc_NextToken(tl);
+ Expect(tl, '(');
+ vcc_NextToken(tl);
+
+ Fb(tl, 1, "VRT_purge(sp, \"req.url\", \"~\", ");
if (!vcc_StringVal(tl)) {
vcc_ExpectedStringval(tl);
return;
}
-
Expect(tl, ')');
vcc_NextToken(tl);
Fb(tl, 0, ", 0);\n");
}
-
/*--------------------------------------------------------------------*/
static void
@@ -376,22 +435,21 @@
{
vcc_NextToken(tl);
-
- Fb(tl, 1, "VRT_purge(");
-
Expect(tl, '(');
vcc_NextToken(tl);
+ Fb(tl, 1, "VRT_purge(sp, \"obj.hash\", \"~\", ");
if (!vcc_StringVal(tl)) {
vcc_ExpectedStringval(tl);
return;
}
-
Expect(tl, ')');
vcc_NextToken(tl);
- Fb(tl, 0, ", 1);\n");
+ Fb(tl, 0, ", 0);\n");
}
+/*--------------------------------------------------------------------*/
+
static void
parse_esi(struct tokenlist *tl)
{
@@ -470,6 +528,7 @@
{ "call", parse_call },
{ "esi", parse_esi },
{ "panic", parse_panic },
+ { "purge", parse_purge },
{ "purge_hash", parse_purge_hash },
{ "purge_url", parse_purge_url },
{ "remove", parse_unset }, /* backward compatibility */
Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c
===================================================================
--- branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-10 14:47:36 UTC (rev 3722)
+++ branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-10 14:50:53 UTC (rev 3723)
@@ -159,8 +159,8 @@
/* ../../include/vcl.h */
- vsb_cat(sb, "/*\n * $Id: vcc_gen_fixed_token.tcl 3676 2009-02-06 14");
- vsb_cat(sb, ":18:21Z tfheen $\n *\n * NB: This file is machine gen");
+ vsb_cat(sb, "/*\n * $Id: vcc_gen_fixed_token.tcl 3718 2009-02-10 14");
+ vsb_cat(sb, ":25:49Z tfheen $\n *\n * NB: This file is machine gen");
vsb_cat(sb, "erated, DO NOT EDIT!\n *\n * Edit and run vcc_gen_fixe");
vsb_cat(sb, "d_token.tcl instead\n */\n\nstruct sess;\n");
vsb_cat(sb, "struct cli;\n\ntypedef void vcl_init_f(struct cli *);\n");
@@ -287,8 +287,8 @@
vsb_cat(sb, "int VRT_re_match(const char *, void *re);\n");
vsb_cat(sb, "const char *VRT_regsub(const struct sess *sp, int all,");
vsb_cat(sb, " const char *,\n void *, const char *);\n");
- vsb_cat(sb, "\nvoid VRT_panic(struct sess *sp, const char *, ...);");
- vsb_cat(sb, "\nvoid VRT_purge(const char *, int hash);\n");
+ vsb_cat(sb, "\nvoid VRT_panic(struct sess *sp, const char *, ...);\n");
+ vsb_cat(sb, "void VRT_purge(struct sess *sp, char *, ...);\n");
vsb_cat(sb, "\nvoid VRT_count(const 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 *);");
More information about the varnish-commit
mailing list