[master] 6ba917d81 Add parsing for structured-fields `sf-bytes` to VCL.
Poul-Henning Kamp
phk at FreeBSD.org
Mon Jul 13 13:16:07 UTC 2020
commit 6ba917d81d4df3ab9f4d4483c5a62a7851184bba
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Jul 13 13:10:43 2020 +0000
Add parsing for structured-fields `sf-bytes` to VCL.
Currently fails with "unsupported", later will turn into BLOB.
diff --git a/bin/varnishtest/tests/README b/bin/varnishtest/tests/README
index 35d598dd2..1d01105de 100644
--- a/bin/varnishtest/tests/README
+++ b/bin/varnishtest/tests/README
@@ -22,6 +22,7 @@ Naming scheme
id ~ ^f --> Security related tests
id ~ ^g --> GZIP tests
id ~ ^h --> HAproxy tests
+ id ~ ^i --> Interoperability and standards compliance
id ~ ^j --> JAIL tests
id ~ ^l --> VSL tests
id ~ ^m --> VMOD tests excluding director
diff --git a/bin/varnishtest/tests/i00000.vtc b/bin/varnishtest/tests/i00000.vtc
new file mode 100644
index 000000000..14849f336
--- /dev/null
+++ b/bin/varnishtest/tests/i00000.vtc
@@ -0,0 +1,10 @@
+varnishtest "SF-blob parsing in VCL"
+
+varnish v1 -errvcl "BLOB must have n*3 base64 characters" { sub vcl_recv { :a: } }
+varnish v2 -errvcl "BLOB must have n*3 base64 characters" { sub vcl_recv { :aa: } }
+varnish v3 -errvcl "Illegal BLOB character:" { sub vcl_recv { :aa?: } }
+varnish v4 -errvcl "BLOB must have n*3 base64 characters" { sub vcl_recv { :aaaa: } }
+varnish v5 -errvcl "Wrong padding ('=') in BLOB" { sub vcl_recv { :aaa=aa: } }
+varnish v6 -errvcl "Wrong padding ('=') in BLOB" { sub vcl_recv { :aaa==a: } }
+varnish v7 -errvcl "Wrong padding ('=') in BLOB" { sub vcl_recv { :aaaa=a: } }
+varnish v8 -errvcl "BLOB is not supported yet" { sub vcl_recv { :aaaa==: } }
diff --git a/lib/libvcc/vcc_token.c b/lib/libvcc/vcc_token.c
index 176b74eab..fa2d504cf 100644
--- a/lib/libvcc/vcc_token.c
+++ b/lib/libvcc/vcc_token.c
@@ -388,7 +388,7 @@ vcc_addtoken(struct vcc *tl, unsigned tok,
void
vcc_Lexer(struct vcc *tl, const struct source *sp, int eoi)
{
- const char *p, *q;
+ const char *p, *q, *r;
unsigned u;
for (p = sp->b; p < sp->e; ) {
@@ -483,6 +483,49 @@ vcc_Lexer(struct vcc *tl, const struct source *sp, int eoi)
return;
}
+ /* Recognize BLOB (= SF-binary) */
+ if (*p == ':') {
+ r = NULL;
+ for (q = p + 1; q < sp->e && vct_isbase64(*q); q++) {
+ if (r == NULL && *q == '=')
+ r = q;
+ }
+ if (q == sp->e || *q != ':') {
+ VSB_cat(tl->sb,
+ "Illegal BLOB character:\n");
+ vcc_addtoken(tl, EOI, sp, q, q+1);
+ vcc_ErrWhere(tl, tl->t);
+ return;
+ }
+ if ((q - p) % 3 != 1) {
+ u = ((q - 1) - p) / 3;
+ vcc_addtoken(tl, EOI, sp, p + u * 3 + 1, q);
+ VSB_cat(tl->sb,
+ "BLOB must have n*3 base64 characters\n");
+ vcc_ErrWhere(tl, tl->t);
+ return;
+ }
+ if (r == NULL) {
+ /* No padding; */
+ } else if (r + 1 == q) {
+ /* One pad char */
+ } else if (r + 2 == q && r[1] == '=') {
+ /* Two (valid) pad chars */
+ } else {
+ VSB_cat(tl->sb,
+ "Wrong padding ('=') in BLOB:\n");
+ vcc_addtoken(tl, EOI, sp, r, r+1);
+ vcc_ErrWhere(tl, tl->t);
+ return;
+ }
+ p = q + 1;
+ vcc_addtoken(tl, EOI, sp, p, q);
+ VSB_cat(tl->sb,
+ "BLOB is not supported yet.\n");
+ vcc_ErrWhere(tl, tl->t);
+ return;
+ }
+
/* Match for the fixed tokens (see generate.py) */
u = vcl_fixed_token(p, &q);
if (u != 0) {
More information about the varnish-commit
mailing list