--- /dev/null
+# $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; }
+ }
+}
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);
}
/*--------------------------------------------------------------------
while (tl->t->tok != '}') {
vcc_IsField(tl, &t_field, fs);
+ ERRCHK(tl);
if (tl->err)
break;
if (vcc_IdIs(t_field, "host")) {
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);
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) {
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);
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);
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 */