r2894 - in trunk/varnish-cache: bin/varnishtest/tests lib/libvcl
phk at projects.linpro.no
phk at projects.linpro.no
Mon Jul 7 23:49:22 CEST 2008
Author: phk
Date: 2008-07-07 23:49:21 +0200 (Mon, 07 Jul 2008)
New Revision: 2894
Added:
trunk/varnish-cache/bin/varnishtest/tests/v00003.vtc
Modified:
trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc
trunk/varnish-cache/lib/libvcl/vcc_backend.c
trunk/varnish-cache/lib/libvcl/vcc_compile.h
trunk/varnish-cache/lib/libvcl/vcc_dir_random.c
Log:
More polishing of backend parsing/syntax error messages
Modified: trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc 2008-07-07 21:22:20 UTC (rev 2893)
+++ trunk/varnish-cache/bin/varnishtest/tests/v00002.vtc 2008-07-07 21:49:21 UTC (rev 2894)
@@ -92,3 +92,17 @@
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"; }
+}
Added: trunk/varnish-cache/bin/varnishtest/tests/v00003.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/v00003.vtc (rev 0)
+++ trunk/varnish-cache/bin/varnishtest/tests/v00003.vtc 2008-07-07 21:49:21 UTC (rev 2894)
@@ -0,0 +1,31 @@
+# $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; }
+ }
+}
Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-07 21:22:20 UTC (rev 2893)
+++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-07 21:49:21 UTC (rev 2894)
@@ -200,19 +200,17 @@
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 @@
while (tl->t->tok != '}') {
vcc_IsField(tl, &t_field, fs);
+ ERRCHK(tl);
if (tl->err)
break;
if (vcc_IdIs(t_field, "host")) {
@@ -294,13 +293,10 @@
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);
ep = CheckHostPort(t_host->dec, "80");
@@ -354,6 +350,7 @@
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_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_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);
Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2008-07-07 21:22:20 UTC (rev 2893)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2008-07-07 21:49:21 UTC (rev 2894)
@@ -158,7 +158,7 @@
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 */
Modified: trunk/varnish-cache/lib/libvcl/vcc_dir_random.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_dir_random.c 2008-07-07 21:22:20 UTC (rev 2893)
+++ trunk/varnish-cache/lib/libvcl/vcc_dir_random.c 2008-07-07 21:49:21 UTC (rev 2894)
@@ -94,7 +94,8 @@
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 @@
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);
More information about the varnish-commit
mailing list