varnishd_SOURCES = \
cache_acceptor.c \
cache_backend.c \
+ cache_ban.c \
cache_expire.c \
cache_fetch.c \
cache_hash.c \
#define VCA_ADDRBUFSIZE 32 /* Sizeof ascii network address */
struct event_base;
+struct cli;
struct sbuf;
struct sess;
struct object;
struct objhead *objhead;
pthread_cond_t cv;
+ unsigned ban_seq;
+
unsigned valid;
unsigned cacheable;
void VBE_ClosedFd(void *ptr);
void VBE_RecycleFd(void *ptr);
+/* cache_ban.c */
+void BAN_Init(void);
+void cli_func_url_purge(struct cli *cli, char **av, void *priv);
+void BAN_NewObj(struct object *o);
+int BAN_CheckObject(struct object *o, const char *url);
+
/* cache_expiry.c */
void EXP_Insert(struct object *o);
void EXP_Init(void);
--- /dev/null
+/*
+ * $Id$
+ *
+ * Ban processing
+ */
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include <regex.h>
+
+#include "shmlog.h"
+#include "cli_priv.h"
+#include "cache.h"
+
+struct ban {
+ TAILQ_ENTRY(ban) list;
+ unsigned gen;
+ regex_t regexp;
+ char *ban;
+};
+
+static TAILQ_HEAD(,ban) ban_head = TAILQ_HEAD_INITIALIZER(ban_head);
+static unsigned ban_next;
+static struct ban *ban_start;
+
+static void
+AddBan(const char *regexp)
+{
+ struct ban *b;
+ int i;
+
+ b = calloc(sizeof *b, 1);
+ assert(b != NULL);
+
+ i = regcomp(&b->regexp, regexp, REG_EXTENDED | REG_NOSUB);
+ if (i) {
+ char buf[512];
+
+ regerror(i, &b->regexp, buf, sizeof buf);
+ VSL(SLT_Debug, 0, "REGEX: <%s>", buf);
+ }
+ b->gen = ++ban_next;
+ b->ban = strdup(regexp);
+ TAILQ_INSERT_HEAD(&ban_head, b, list);
+ ban_start = b;
+}
+
+void
+BAN_NewObj(struct object *o)
+{
+
+ o->ban_seq = ban_next;
+}
+
+int
+BAN_CheckObject(struct object *o, const char *url)
+{
+ struct ban *b, *b0;
+ int i;
+
+ b0 = ban_start;
+ for (b = b0;
+ b != NULL && b->gen > o->ban_seq;
+ b = TAILQ_NEXT(b, list)) {
+ i = regexec(&b->regexp, url, 0, NULL, 0);
+ if (!i)
+ return (1);
+ }
+ o->ban_seq = b0->gen;
+ return (0);
+}
+
+void
+cli_func_url_purge(struct cli *cli, char **av, void *priv)
+{
+
+ AddBan(av[2]);
+ cli_out(cli, "PURGE %s\n", av[2]);
+}
+
+void
+BAN_Init(void)
+{
+
+ AddBan("a");
+}
#include <pthread.h>
#include "libvarnish.h"
+#include "shmlog.h"
#include "cache.h"
static struct hash_slinger *hash;
o->refcnt++;
if (o->busy)
AZ(pthread_cond_wait(&o->cv, &oh->mtx));
- /* XXX: do Vary: comparison */
- if (1)
+ /* XXX: check TTL */
+ if (o->ttl == 0) {
+ VSL(SLT_Debug, 0, "Object %p had 0 ttl", o);
+ } else if (BAN_CheckObject(o, b)) {
+ o->ttl = 0;
+ VSL(SLT_Debug, 0, "Object %p was banned", o);
+ } else
break;
o->refcnt--;
}
TAILQ_INSERT_TAIL(&oh->objects, o, list);
/* NB: do not deref objhead the new object inherits our reference */
AZ(pthread_mutex_unlock(&oh->mtx));
+ BAN_NewObj(o);
return (o);
}
static struct cli_proto cli_proto[] = {
{ CLI_URL_QUERY, cli_func_url_query },
+ { CLI_URL_PURGE, cli_func_url_purge },
{ CLI_CONFIG_LOAD, cli_func_config_load },
{ CLI_CONFIG_LIST, cli_func_config_list },
{ CLI_CONFIG_UNLOAD, cli_func_config_unload },
VCA_Init();
EXP_Init();
HSH_Init();
+ BAN_Init();
eb = event_init();
assert(eb != NULL);