From a705b5e4bea39a010ee9c2fef4a5c18fda558d67 Mon Sep 17 00:00:00 2001 From: phk Date: Mon, 7 Jul 2008 21:49:21 +0000 Subject: [PATCH] More polishing of backend parsing/syntax error messages git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2894 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- .../bin/varnishtest/tests/v00002.vtc | 14 ++++++++ .../bin/varnishtest/tests/v00003.vtc | 31 ++++++++++++++++ varnish-cache/lib/libvcl/vcc_backend.c | 35 ++++++++++++------- varnish-cache/lib/libvcl/vcc_compile.h | 2 +- varnish-cache/lib/libvcl/vcc_dir_random.c | 6 ++-- 5 files changed, 72 insertions(+), 16 deletions(-) create mode 100644 varnish-cache/bin/varnishtest/tests/v00003.vtc diff --git a/varnish-cache/bin/varnishtest/tests/v00002.vtc b/varnish-cache/bin/varnishtest/tests/v00002.vtc index 33a5718e..9288e9a2 100644 --- a/varnish-cache/bin/varnishtest/tests/v00002.vtc +++ b/varnish-cache/bin/varnishtest/tests/v00002.vtc @@ -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"; } +} diff --git a/varnish-cache/bin/varnishtest/tests/v00003.vtc b/varnish-cache/bin/varnishtest/tests/v00003.vtc new file mode 100644 index 00000000..706f160c --- /dev/null +++ b/varnish-cache/bin/varnishtest/tests/v00003.vtc @@ -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; } + } +} diff --git a/varnish-cache/lib/libvcl/vcc_backend.c b/varnish-cache/lib/libvcl/vcc_backend.c index 2a83988a..f054dba3 100644 --- a/varnish-cache/lib/libvcl/vcc_backend.c +++ b/varnish-cache/lib/libvcl/vcc_backend.c @@ -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); diff --git a/varnish-cache/lib/libvcl/vcc_compile.h b/varnish-cache/lib/libvcl/vcc_compile.h index 3f800cfc..6f6ac64c 100644 --- a/varnish-cache/lib/libvcl/vcc_compile.h +++ b/varnish-cache/lib/libvcl/vcc_compile.h @@ -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 */ diff --git a/varnish-cache/lib/libvcl/vcc_dir_random.c b/varnish-cache/lib/libvcl/vcc_dir_random.c index 2525a1c4..63caf513 100644 --- a/varnish-cache/lib/libvcl/vcc_dir_random.c +++ b/varnish-cache/lib/libvcl/vcc_dir_random.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); -- 2.39.5