r3720 - in branches/2.0/varnish-cache: bin/varnishd include

tfheen at projects.linpro.no tfheen at projects.linpro.no
Tue Feb 10 15:35:50 CET 2009


Author: tfheen
Date: 2009-02-10 15:35:50 +0100 (Tue, 10 Feb 2009)
New Revision: 3720

Added:
   branches/2.0/varnish-cache/include/purge_vars.h
Modified:
   branches/2.0/varnish-cache/bin/varnishd/cache_ban.c
Log:
Merge r3538: 

Move the purgable variables into a CPP table, so we can share them with
the VCL compiler



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:32:10 UTC (rev 3719)
+++ branches/2.0/varnish-cache/bin/varnishd/cache_ban.c	2009-02-10 14:35:50 UTC (rev 3720)
@@ -297,11 +297,23 @@
 	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 @@
 	}
 
 
-	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);

Copied: branches/2.0/varnish-cache/include/purge_vars.h (from rev 3538, trunk/varnish-cache/include/purge_vars.h)
===================================================================
--- branches/2.0/varnish-cache/include/purge_vars.h	                        (rev 0)
+++ branches/2.0/varnish-cache/include/purge_vars.h	2009-02-10 14:35:50 UTC (rev 3720)
@@ -0,0 +1,36 @@
+/*-
+ * Copyright (c) 2008 Linpro AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at 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)



More information about the varnish-commit mailing list