[master] 9a84137 Add code to cater for other vcl syntax numbers than 4.0, we will soon need them.
Poul-Henning Kamp
phk at FreeBSD.org
Mon Jun 20 12:31:07 CEST 2016
commit 9a84137847228d4feebbc19d7dfc247f5074d84e
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Jun 20 10:00:27 2016 +0000
Add code to cater for other vcl syntax numbers than 4.0, we will
soon need them.
diff --git a/bin/varnishtest/tests/v00049.vtc b/bin/varnishtest/tests/v00049.vtc
new file mode 100644
index 0000000..35a3efc
--- /dev/null
+++ b/bin/varnishtest/tests/v00049.vtc
@@ -0,0 +1,17 @@
+varnishtest "VCL syntax numbers"
+
+varnish v1 -vcl {backend b1 { .host = "127.0.0.1:8080"; }} -start
+
+varnish v1 -syntax 3.9 -errvcl "VCL version 3.9 not supported." {
+ backend b1 { .host = "127.0.0.1:8080"; }
+}
+
+varnish v1 -syntax 4.0 -errvcl "silly buggers" {
+ vcl 4.01;
+ backend b1 { .host = "127.0.0.1:8080"; }
+}
+
+varnish v1 -syntax 4.0 -errvcl "9.9 higher than the top level version" {
+ vcl 9.9;
+ backend b1 { .host = "127.0.0.1:8080"; }
+}
diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index a687cdc..9a1a72c 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -481,7 +481,7 @@ vcc_resolve_includes(struct vcc *tl)
continue;
t1 = VTAILQ_NEXT(t, list);
- assert(t1 != NULL); /* There's always an EOI */
+ AN(t1); /* There's always an EOI */
if (t1->tok != CSTR) {
VSB_printf(tl->sb,
"include not followed by string constant.\n");
@@ -489,7 +489,7 @@ vcc_resolve_includes(struct vcc *tl)
return;
}
t2 = VTAILQ_NEXT(t1, list);
- assert(t2 != NULL); /* There's always an EOI */
+ AN(t2); /* There's always an EOI */
if (t2->tok != ';') {
VSB_printf(tl->sb,
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index 22b30f2..fc263fd 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -70,6 +70,7 @@ struct symbol;
struct source {
VTAILQ_ENTRY(source) list;
+ float syntax;
char *name;
const char *b;
const char *e;
diff --git a/lib/libvcc/vcc_parse.c b/lib/libvcc/vcc_parse.c
index 869979e..c5caa62 100644
--- a/lib/libvcc/vcc_parse.c
+++ b/lib/libvcc/vcc_parse.c
@@ -279,13 +279,20 @@ vcc_ParseVcl(struct vcc *tl)
assert(vcc_IdIs(tl->t, "vcl"));
vcc_NextToken(tl);
tok = tl->t;
- tl->syntax = vcc_DoubleVal(tl);
+ tok->src->syntax = vcc_DoubleVal(tl);
ERRCHK(tl);
- if (tl->syntax != 4.0) {
- // see TODO above
- VSB_printf(tl->sb, "VCL version %.1f not supported.\n",
- tl->syntax);
- vcc_ErrWhere(tl, tok);
+ if (tl->t->e - tok->b > 4) {
+ VSB_printf(tl->sb,
+ "Don't play silly buggers with VCL version numbers\n");
+ vcc_ErrWhere2(tl, tok, tl->t);
+ ERRCHK(tl);
+ }
+ if (tl->syntax != 0.0 && tok->src->syntax > tl->syntax) {
+ VSB_printf(tl->sb,
+ "VCL version %.1f higher than"
+ " the top level version %.1f\n",
+ tok->src->syntax, tl->syntax);
+ vcc_ErrWhere2(tl, tok, tl->t);
ERRCHK(tl);
}
ExpectErr(tl, ';');
@@ -322,18 +329,27 @@ void
vcc_Parse(struct vcc *tl)
{
struct toplev *tp;
+ struct token *tok;
if (tl->t->tok != ID || !vcc_IdIs(tl->t, "vcl")) {
VSB_printf(tl->sb,
"VCL version declaration missing\n"
"Update your VCL to Version 4 syntax, and add\n"
"\tvcl 4.0;\n"
- "on the first line the VCL files.\n"
+ "on the first line of the VCL files.\n"
);
vcc_ErrWhere(tl, tl->t);
ERRCHK(tl);
}
+ tok = tl->t;
vcc_ParseVcl(tl);
+ if (tok->src->syntax != 4.0) {
+ VSB_printf(tl->sb, "VCL version %.1f not supported.\n",
+ tok->src->syntax);
+ vcc_ErrWhere2(tl, tok, tl->t);
+ ERRCHK(tl);
+ }
+ tl->syntax = tl->t->src->syntax;
ERRCHK(tl);
while (tl->t->tok != EOI) {
ERRCHK(tl);
More information about the varnish-commit
mailing list