]> err.no Git - varnish/commitdiff
More polishing of backend parsing/syntax error messages
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 7 Jul 2008 21:49:21 +0000 (21:49 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 7 Jul 2008 21:49:21 +0000 (21:49 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2894 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishtest/tests/v00002.vtc
varnish-cache/bin/varnishtest/tests/v00003.vtc [new file with mode: 0644]
varnish-cache/lib/libvcl/vcc_backend.c
varnish-cache/lib/libvcl/vcc_compile.h
varnish-cache/lib/libvcl/vcc_dir_random.c

index 33a5718e03b091207b0425a22728e790fc5c61ba..9288e9a2ce126add2ac224866620a764668b3b83 100644 (file)
@@ -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 (file)
index 0000000..706f160
--- /dev/null
@@ -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; }
+       }
+}
index 2a83988a7cfc99c16eb6126aa5ebf853bae30716..f054dba35b3e8096ab23cb3758688305c9cd583d 100644 (file)
@@ -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);
 
index 3f800cfc59bb1ef4ae7094ffc227ddf40fdf4852..6f6ac64c52f043d75fd57dfadfae39ec6ff0a303 100644 (file)
@@ -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 */
index 2525a1c4dab983fac1b88e620b4cbf08353ba78e..63caf513bef3f18df115c3f975dced1c0de4853f 100644 (file)
@@ -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);