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

More polishing of backend parsing/syntax error messages



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@2894 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 15d6a17b
......@@ -92,3 +92,17 @@ varnish v1 -badvcl {
set host = "localhost";
}
}
# Too many .connect_timeout
varnish v1 -badvcl {
backend b1 {
.host = k"foo";
.connect_timeout = 1 q;
}
}
# Two clashing backends
varnish v1 -badvcl {
backend b1 { .host = "127.0.0.1"; }
backend b1 { .host = "127.0.0.1"; }
}
# $Id$
test "VCL: test syntax/semantic checks on director decls."
# syntax in inline backend
varnish v1 -badvcl {
director r1 random {
{ .backend = { .foo = 2; }; .weight = 1;}
}
}
# reference to unknown backend host
varnish v1 -badvcl {
director r1 random {
{ .backend = b2; .weight = 1; }
}
}
# missing backend
varnish v1 -badvcl {
director r1 random {
{ .weight = 1; }
}
}
# invalid weight
varnish v1 -badvcl {
director r1 random {
{ .backend = {.host = "127.0.0.1";} .weight = k; }
}
}
......@@ -200,19 +200,17 @@ vcc_IsField(struct tokenlist *tl, struct token **t, struct fld_spec *fs)
return;
}
int
void
vcc_FieldsOk(struct tokenlist *tl, const struct fld_spec *fs)
{
int ok = 1;
for (; fs->name != NULL; fs++) {
if (*fs->name == '!' && fs->found == NULL) {
vsb_printf(tl->sb,
"Mandatory field '%s' missing.\n", fs->name + 1);
ok = 0;
tl->err = 1;
}
}
return (ok);
}
/*--------------------------------------------------------------------
......@@ -267,6 +265,7 @@ vcc_ParseHostDef(struct tokenlist *tl, int *nbh, const struct token *name, const
while (tl->t->tok != '}') {
vcc_IsField(tl, &t_field, fs);
ERRCHK(tl);
if (tl->err)
break;
if (vcc_IdIs(t_field, "host")) {
......@@ -294,12 +293,9 @@ vcc_ParseHostDef(struct tokenlist *tl, int *nbh, const struct token *name, const
ExpectErr(tl, ';');
vcc_NextToken(tl);
}
if (tl->err || !vcc_FieldsOk(tl, fs)) {
vsb_printf(tl->sb,
"\nIn backend host specfication starting at:\n");
vcc_ErrWhere(tl, t_first);
return;
}
vcc_FieldsOk(tl, fs);
ERRCHK(tl);
/* Check that the hostname makes sense */
assert(t_host != NULL);
......@@ -354,6 +350,7 @@ void
vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *name, const char *qual, int serial)
{
struct host *h;
struct token *t;
if (tl->t->tok == ID) {
VTAILQ_FOREACH(h, &tl->hosts, list) {
......@@ -373,11 +370,18 @@ vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *name, c
vcc_NextToken(tl);
*nbh = h->hnum;
} else if (tl->t->tok == '{') {
t = tl->t;
vcc_ParseHostDef(tl, nbh, name, qual, serial);
if (tl->err) {
vsb_printf(tl->sb,
"\nIn backend host specfication starting at:\n");
vcc_ErrWhere(tl, t);
}
return;
} else {
vsb_printf(tl->sb,
"Expected a backend specification here, either by name "
"or by {...}\n");
"Expected a backend host specification here, "
"either by name or by {...}\n");
vcc_ErrToken(tl, tl->t);
vsb_printf(tl->sb, " at\n");
vcc_ErrWhere(tl, tl->t);
......@@ -404,7 +408,12 @@ vcc_ParseBackend(struct tokenlist *tl)
vcc_NextToken(tl);
vcc_ParseHostDef(tl, &h->hnum, h->name, "backend", 0);
ERRCHK(tl);
if (tl->err) {
vsb_printf(tl->sb,
"\nIn backend specfication starting at:\n");
vcc_ErrWhere(tl, h->name);
return;
}
VTAILQ_INSERT_TAIL(&tl->hosts, h, list);
......
......@@ -158,7 +158,7 @@ void vcc_ParseDirector(struct tokenlist *tl);
struct fld_spec * vcc_FldSpec(struct tokenlist *tl, const char *first, ...);
void vcc_ResetFldSpec(struct fld_spec *f);
void vcc_IsField(struct tokenlist *tl, struct token **t, struct fld_spec *fs);
int vcc_FieldsOk(struct tokenlist *tl, const struct fld_spec *fs);
void vcc_FieldsOk(struct tokenlist *tl, const struct fld_spec *fs);
void vcc_ParseBackendHost(struct tokenlist *tl, int *nbr, const struct token *name, const char *qual, int serial);
/* vcc_compile.c */
......
......@@ -94,7 +94,8 @@ vcc_ParseRandomDirector(struct tokenlist *tl, struct token *t_dir)
u = vcc_UintVal(tl);
if (u == 0) {
vsb_printf(tl->sb,
"The .weight must be higher than zero.");
"The .weight must be higher "
"than zero.");
vcc_ErrToken(tl, tl->t);
vsb_printf(tl->sb, " at\n");
vcc_ErrWhere(tl, tl->t);
......@@ -108,7 +109,8 @@ vcc_ParseRandomDirector(struct tokenlist *tl, struct token *t_dir)
ErrInternal(tl);
}
}
if (!vcc_FieldsOk(tl, fs)) {
vcc_FieldsOk(tl, fs);
if (tl->err) {
vsb_printf(tl->sb,
"\nIn member host specfication starting at:\n");
vcc_ErrWhere(tl, t_be);
......
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