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);
}
- 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);
--- /dev/null
+/*-
+ * 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)