Commit 6ba917d8 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add parsing for structured-fields `sf-bytes` to VCL.

Currently fails with "unsupported", later will turn into BLOB.
parent 6b0c55b7
......@@ -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
......
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==: } }
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment