Commit a375d56f authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Give BAN_Add() an (option) cli argument so errors can be reported

but also give it a return value since we don't have a cli in VCL.

However, I'm not sure how we will report the error in VCL, so still
log the trouble in shmlog.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@2751 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 9a257ecc
...@@ -426,7 +426,7 @@ void VBE_AddHostHeader(struct sess *sp); ...@@ -426,7 +426,7 @@ void VBE_AddHostHeader(struct sess *sp);
void VBE_SelectBackend(struct sess *sp); void VBE_SelectBackend(struct sess *sp);
/* cache_ban.c */ /* cache_ban.c */
void BAN_Add(const char *, int hash); int BAN_Add(struct cli *cli, const char *regexp, int hash);
void BAN_Init(void); void BAN_Init(void);
void BAN_NewObj(struct object *o); void BAN_NewObj(struct object *o);
void BAN_DestroyObj(struct object *o); void BAN_DestroyObj(struct object *o);
......
...@@ -65,22 +65,29 @@ static MTX ban_mtx; ...@@ -65,22 +65,29 @@ static MTX ban_mtx;
*/ */
static struct ban * volatile ban_start; static struct ban * volatile ban_start;
void int
BAN_Add(const char *regexp, int hash) BAN_Add(struct cli *cli, const char *regexp, int hash)
{ {
struct ban *b; struct ban *b;
char buf[512];
int i; int i;
ALLOC_OBJ(b, BAN_MAGIC); ALLOC_OBJ(b, BAN_MAGIC);
XXXAN(b); if (b == NULL) {
cli_out(cli, "Out of Memory");
cli_result(cli, CLIS_CANT);
return (-1);
}
i = regcomp(&b->regexp, regexp, REG_EXTENDED | REG_ICASE | REG_NOSUB); i = regcomp(&b->regexp, regexp, REG_EXTENDED | REG_ICASE | REG_NOSUB);
if (i) { if (i) {
char buf[512];
(void)regerror(i, &b->regexp, buf, sizeof buf); (void)regerror(i, &b->regexp, buf, sizeof buf);
regfree(&b->regexp);
VSL(SLT_Debug, 0, "REGEX: <%s>", buf); VSL(SLT_Debug, 0, "REGEX: <%s>", buf);
return; cli_out(cli, "%s", buf);
cli_result(cli, CLIS_PARAM);
FREE_OBJ(b);
return (-1);
} }
b->hash = hash; b->hash = hash;
b->ban = strdup(regexp); b->ban = strdup(regexp);
...@@ -89,6 +96,7 @@ BAN_Add(const char *regexp, int hash) ...@@ -89,6 +96,7 @@ BAN_Add(const char *regexp, int hash)
VTAILQ_INSERT_HEAD(&ban_head, b, list); VTAILQ_INSERT_HEAD(&ban_head, b, list);
ban_start = b; ban_start = b;
UNLOCK(&ban_mtx); UNLOCK(&ban_mtx);
return (0);
} }
void void
...@@ -179,8 +187,7 @@ ccf_purge_url(struct cli *cli, const char * const *av, void *priv) ...@@ -179,8 +187,7 @@ ccf_purge_url(struct cli *cli, const char * const *av, void *priv)
{ {
(void)priv; (void)priv;
BAN_Add(av[2], 0); (void)BAN_Add(cli, av[2], 0);
cli_out(cli, "URL_PURGE %s\n", av[2]);
} }
static void static void
...@@ -188,8 +195,7 @@ ccf_purge_hash(struct cli *cli, const char * const *av, void *priv) ...@@ -188,8 +195,7 @@ ccf_purge_hash(struct cli *cli, const char * const *av, void *priv)
{ {
(void)priv; (void)priv;
BAN_Add(av[2], 1); (void)BAN_Add(cli, av[2], 1);
cli_out(cli, "HASH_PURGE %s\n", av[2]);
} }
static void static void
...@@ -211,7 +217,9 @@ ccf_purge_list(struct cli *cli, const char * const *av, void *priv) ...@@ -211,7 +217,9 @@ ccf_purge_list(struct cli *cli, const char * const *av, void *priv)
if (b0->refcount == 0 && VTAILQ_NEXT(b0, list) == NULL) if (b0->refcount == 0 && VTAILQ_NEXT(b0, list) == NULL)
break; break;
cli_out(cli, "%5u %s \"%s\"\n", cli_out(cli, "%5u %s \"%s\"\n",
b0->refcount, b0->hash ? "hash" : "url ", b0->ban); b0->refcount,
b0->hash ? "hash" : "url ",
b0->ban);
} }
} }
...@@ -236,5 +244,5 @@ BAN_Init(void) ...@@ -236,5 +244,5 @@ BAN_Init(void)
MTX_INIT(&ban_mtx); MTX_INIT(&ban_mtx);
CLI_AddFuncs(PUBLIC_CLI, ban_cmds); CLI_AddFuncs(PUBLIC_CLI, ban_cmds);
/* Add an initial ban, since the list can never be empty */ /* Add an initial ban, since the list can never be empty */
BAN_Add(".", 0); (void)BAN_Add(NULL, ".", 0);
} }
...@@ -638,7 +638,7 @@ void ...@@ -638,7 +638,7 @@ void
VRT_purge(const char *regexp, int hash) VRT_purge(const char *regexp, int hash)
{ {
BAN_Add(regexp, hash); (void)BAN_Add(NULL, regexp, hash);
} }
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment