Commit 01835f40 authored by Geoff Simmons's avatar Geoff Simmons

VMOD blob: remove the *UC and *LC encoding schemes.

For HEX and URL, there is now an ENUM case in {LOWER, UPPER} to
determine the case of hex digits produced for an encoding, default
LOWER.
parent da91fec9
......@@ -9,10 +9,10 @@ varnish v1 -vcl+backend {
import blob;
sub vcl_backend_response {
set beresp.http.bereq_hash = blob.encode(HEXLC, bereq.hash);
set beresp.http.bereq_hash = blob.encode(HEX, blob=bereq.hash);
}
sub vcl_deliver {
set resp.http.req_hash = blob.encode(HEXLC, req.hash);
set resp.http.req_hash = blob.encode(HEX, blob=req.hash);
}
} -start
......
......@@ -10,29 +10,29 @@ varnish v1 -vcl {
sub vcl_synth {
set resp.http.id =
blob.encode(IDENTITY, blob.decode(IDENTITY,
blob.encode(IDENTITY, blob=blob.decode(IDENTITY,
"The quick brown fox jumps over the lazy dog"));
set resp.http.hobbes =
blob.encode(IDENTITY, blob.decode(IDENTITY,
blob.encode(IDENTITY, blob=blob.decode(IDENTITY,
{"Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure."}));
set resp.http.list =
blob.encode(IDENTITY, blob.decode(IDENTITY,
blob.encode(IDENTITY, blob=blob.decode(IDENTITY,
"" + req.http.unset + req.url +
"The quick brown fox jumps over " +
req.http.unset + "" + req.http.unset + "" +
"the lazy dog" + req.url + req.http.unset + ""));
set resp.http.empty =
blob.encode(IDENTITY, blob.decode(IDENTITY, ""));
blob.encode(IDENTITY, blob=blob.decode(IDENTITY, ""));
set resp.http.undef =
blob.encode(IDENTITY, blob.decode(IDENTITY,
blob.encode(IDENTITY, blob=blob.decode(IDENTITY,
req.http.unset));
set resp.http.emptylist =
blob.encode(IDENTITY, blob.decode(IDENTITY,
blob.encode(IDENTITY, blob=blob.decode(IDENTITY,
req.http.unset + "" + req.http.unset + ""));
set resp.http.param =
......@@ -43,7 +43,7 @@ varnish v1 -vcl {
encoding=IDENTITY);
set resp.http.paramlist =
blob.encode(IDENTITY, blob.decode(encoded=
blob.encode(IDENTITY, blob=blob.decode(encoded=
"" + req.http.unset + req.url +
"The quick brown fox jumps over " +
req.http.unset + "" + req.http.unset + "" +
......@@ -51,7 +51,13 @@ varnish v1 -vcl {
decoding=IDENTITY));
set resp.http.truncated =
blob.encode(IDENTITY, blob.decode(HEX, "666f6f00626172"));
blob.encode(IDENTITY, blob=blob.decode(HEX, "666f6f00626172"));
set resp.http.lc =
blob.encode(IDENTITY, LOWER, blob.decode(IDENTITY, "Don't care"));
set resp.http.uc =
blob.encode(IDENTITY, UPPER, blob.decode(IDENTITY, "Don't care"));
}
} -start
......@@ -67,4 +73,6 @@ client c1 {
expect resp.http.param == "The quick brown fox jumps over the lazy dog"
expect resp.http.paramlist == "/The quick brown fox jumps over the lazy dog/"
expect resp.http.truncated == "foo"
expect resp.http.lc == "Don't care"
expect resp.http.uc == "Don't care"
} -run
......@@ -10,29 +10,29 @@ varnish v1 -vcl {
sub vcl_synth {
set resp.http.id =
blob.encode(IDENTITY, blob.decode_n(5, IDENTITY,
blob.encode(IDENTITY, blob=blob.decode_n(5, IDENTITY,
"The quick brown fox jumps over the lazy dog"));
set resp.http.hobbes =
blob.encode(IDENTITY, blob.decode_n(5, IDENTITY,
blob.encode(IDENTITY, blob=blob.decode_n(5, IDENTITY,
{"Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure."}));
set resp.http.list =
blob.encode(IDENTITY, blob.decode_n(6, IDENTITY,
blob.encode(IDENTITY, blob=blob.decode_n(6, IDENTITY,
"" + req.http.unset + req.url +
"The quick brown fox jumps over " +
req.http.unset + "" + req.http.unset + "" +
"the lazy dog" + req.url + req.http.unset + ""));
set resp.http.empty =
blob.encode(IDENTITY, blob.decode_n(5, IDENTITY, ""));
blob.encode(IDENTITY, blob=blob.decode_n(5, IDENTITY, ""));
set resp.http.undef =
blob.encode(IDENTITY, blob.decode_n(5, IDENTITY,
blob.encode(IDENTITY, blob=blob.decode_n(5, IDENTITY,
req.http.unset));
set resp.http.emptylist =
blob.encode(IDENTITY, blob.decode_n(5, IDENTITY,
blob.encode(IDENTITY, blob=blob.decode_n(5, IDENTITY,
req.http.unset + "" + req.http.unset + ""));
set resp.http.param =
......@@ -43,7 +43,7 @@ varnish v1 -vcl {
encoding=IDENTITY);
set resp.http.paramlist =
blob.encode(IDENTITY, blob.decode_n(encoded=
blob.encode(IDENTITY, blob=blob.decode_n(encoded=
"" + req.http.unset + req.url +
"The quick brown fox jumps over " +
req.http.unset + "" + req.http.unset + "" +
......
This diff is collapsed.
......@@ -18,38 +18,41 @@ varnish v1 -vcl {
{"AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w=="};
set resp.http.hexlc =
blob.encode(HEXLC,
blob.decode_n(5, IDENTITY, req.http.pangram));
blob.encode(HEX,
blob=blob.decode_n(5, IDENTITY, req.http.pangram));
set resp.http.hexuc =
blob.encode(HEXUC,
blob.decode_n(5, IDENTITY, req.http.pangram));
blob.encode(HEX, UPPER,
blob.decode_n(5, IDENTITY, req.http.pangram));
set resp.http.hobbeslc =
blob.encode(HEXLC, blob.decode_n(5, IDENTITY, req.http.hobbes));
blob.encode(HEX,
blob=blob.decode_n(5, IDENTITY, req.http.hobbes));
set resp.http.hobbesuc =
blob.encode(HEXUC, blob.decode_n(5, IDENTITY, req.http.hobbes));
blob.encode(HEX, UPPER,
blob.decode_n(5, IDENTITY, req.http.hobbes));
set resp.http.all-lc =
blob.encode(HEXLC, blob.decode_n(8, BASE64, req.http.b64all));
blob.encode(HEX, blob=blob.decode_n(8, BASE64, req.http.b64all));
set resp.http.all-uc =
blob.encode(HEXUC, blob.decode_n(8, BASE64, req.http.b64all));
blob.encode(HEX, UPPER,
blob.decode_n(8, BASE64, req.http.b64all));
set resp.http.empty-lc =
blob.encode(HEXLC, blob.decode_n(5, IDENTITY, ""));
blob.encode(HEX, blob=blob.decode_n(5, IDENTITY, ""));
set resp.http.empty-uc =
blob.encode(HEXUC, blob.decode_n(5, IDENTITY, ""));
blob.encode(HEX, UPPER, blob.decode_n(5, IDENTITY, ""));
set resp.http.hexlcparam =
blob.encode(blob=blob.decode_n(5, IDENTITY, req.http.pangram),
encoding=HEXLC);
encoding=HEX, case=LOWER);
set resp.http.hexucparam =
blob.encode(blob=blob.decode_n(5, IDENTITY, req.http.pangram),
encoding=HEXUC);
encoding=HEX, case=UPPER);
set req.http.hexucfoobar = "666F6F206261722062617A2071757578";
set req.http.hexlcfoobar = std.tolower(req.http.hexucfoobar);
......@@ -63,51 +66,53 @@ varnish v1 -vcl {
set resp.http.decuc =
blob.encode(IDENTITY,
blob.decode_n(10, HEX, req.http.hexucfoobar));
blob=blob.decode_n(10, HEX, req.http.hexucfoobar));
set resp.http.declc =
blob.encode(IDENTITY,
blob.decode_n(10, HEX, req.http.hexlcfoobar));
blob=blob.decode_n(10, HEX, req.http.hexlcfoobar));
set resp.http.dechobbesuc =
blob.encode(IDENTITY,
blob.decode_n(12, HEX, req.http.hexhobbesuc));
blob=blob.decode_n(12, HEX, req.http.hexhobbesuc));
set resp.http.dechobbeslc =
blob.encode(IDENTITY,
blob.decode_n(12, HEX, req.http.hexhobbeslc));
blob=blob.decode_n(12, HEX, req.http.hexhobbeslc));
set resp.http.decalluc =
blob.encode(BASE64, blob.decode_n(12, HEX, req.http.hexalluc));
blob.encode(BASE64,
blob=blob.decode_n(12, HEX, req.http.hexalluc));
set resp.http.decalllc =
blob.encode(BASE64, blob.decode_n(12, HEX, req.http.hexalllc));
blob.encode(BASE64,
blob=blob.decode_n(12, HEX, req.http.hexalllc));
set resp.http.decallucodd =
blob.encode(BASE64, blob.decode_n(11, HEX,
req.http.hexallucodd));
blob.encode(BASE64, blob=blob.decode_n(11, HEX,
req.http.hexallucodd));
set resp.http.decalllcodd =
blob.encode(BASE64, blob.decode_n(11, HEX,
req.http.hexalllcodd));
blob.encode(BASE64, blob=blob.decode_n(11, HEX,
req.http.hexalllcodd));
set resp.http.decempty =
blob.encode(IDENTITY, blob.decode_n(5, HEX, ""));
blob.encode(IDENTITY, blob=blob.decode_n(5, HEX, ""));
set resp.http.decemptybyte =
blob.encode(IDENTITY, blob.decode_n(1, HEX, "00"));
blob.encode(IDENTITY, blob=blob.decode_n(1, HEX, "00"));
set resp.http.decemptynibble =
blob.encode(IDENTITY, blob.decode_n(2, HEX, "0"));
blob.encode(IDENTITY, blob=blob.decode_n(2, HEX, "0"));
set resp.http.decemptypieces =
blob.encode(IDENTITY,
blob.decode_n(5, HEX, req.http.unset + ""
+ req.http.unset + ""));
blob=blob.decode_n(5, HEX, req.http.unset + ""
+ req.http.unset + ""));
set req.http.part1 = "666";
set resp.http.dec2pieces =
blob.encode(IDENTITY, blob.decode_n(6, HEX, req.http.part1 +
blob.encode(IDENTITY, blob=blob.decode_n(6, HEX, req.http.part1 +
"F6F206261722062617A2071757578"));
set req.http.part2 = "57578";
......@@ -118,11 +123,12 @@ varnish v1 -vcl {
encoding=IDENTITY);
set resp.http.dec3pieces =
blob.encode(IDENTITY, blob.decode_n(30, HEX, req.http.part1 +
blob.encode(IDENTITY, blob=blob.decode_n(30, HEX, req.http.part1 +
"F6F206261722062617A20717" + req.http.part2));
set resp.http.decmanypieces =
blob.encode(IDENTITY, blob.decode_n(20, HEX, "" + req.http.unset
blob.encode(IDENTITY, blob=blob.decode_n(20, HEX, ""
+ req.http.unset
+ req.http.part1 + req.http.unset + ""
+ req.http.unset + "" + "F6F206261722062617A20717"
+ "" + req.http.unset + req.http.part2
......@@ -173,7 +179,7 @@ varnish v1 -vcl+backend {
sub vcl_deliver {
set req.http.foo = "123";
set resp.http.badhex = blob.encode(HEXUC,
set resp.http.badhex = blob.encode(HEX, UPPER,
blob.decode_n(2, HEX, "g" + req.http.foo));
}
}
......
This diff is collapsed.
......@@ -22,82 +22,80 @@ varnish v1 -vcl {
set resp.http.dec
= blob.encode(IDENTITY,
blob.decode_n(8, BASE64,
blob=blob.decode_n(8, BASE64,
req.http.foobarbazquux));
set resp.http.deceq
= blob.encode(IDENTITY,
blob.decode_n(20, BASE64,
blob=blob.decode_n(20, BASE64,
req.http.foobarbazquux));
set resp.http.declong
= blob.encode(IDENTITY,
blob.decode_n(30, BASE64,
blob=blob.decode_n(30, BASE64,
req.http.foobarbazquux));
set resp.http.dec2
= blob.encode(IDENTITY,
blob.decode_n(12, BASE64, req.http.pangram));
blob=blob.decode_n(12, BASE64, req.http.pangram));
set resp.http.b64dechobbes =
blob.encode(IDENTITY,
blob.decode_n(24, BASE64, req.http.hobbes));
blob=blob.decode_n(24, BASE64, req.http.hobbes));
set resp.http.b64decall =
blob.encode(HEXLC, blob.decode_n(128, BASE64,
req.http.all));
blob.encode(HEX, blob=blob.decode_n(128, BASE64, req.http.all));
set resp.http.urldechobbes =
blob.encode(IDENTITY, blob.decode_n(180, BASE64URL,
blob.encode(IDENTITY, blob=blob.decode_n(180, BASE64URL,
req.http.hobbes));
set resp.http.urldecall =
blob.encode(HEXLC,
blob.decode_n(256, BASE64URL,
blob.encode(HEX,
blob=blob.decode_n(256, BASE64URL,
req.http.allurl));
set resp.http.nopaddechobbes =
blob.encode(IDENTITY,
blob.decode_n(500, BASE64URLNOPAD,
blob=blob.decode_n(500, BASE64URLNOPAD,
req.http.hobbesnopad));
set resp.http.nopaddecall =
blob.encode(HEXLC,
blob.decode_n(256, BASE64URLNOPAD,
req.http.allurl));
blob.encode(HEX, blob=blob.decode_n(256, BASE64URLNOPAD,
req.http.allurl));
set resp.http.b64empty =
blob.encode(IDENTITY, blob.decode_n(0, BASE64, ""));
blob.encode(IDENTITY, blob=blob.decode_n(0, BASE64, ""));
set resp.http.urlempty =
blob.encode(IDENTITY, blob.decode_n(1, BASE64URL, ""));
blob.encode(IDENTITY, blob=blob.decode_n(1, BASE64URL, ""));
set resp.http.nopadempty =
blob.encode(IDENTITY,
blob.decode_n(0, BASE64URLNOPAD, ""));
blob=blob.decode_n(0, BASE64URLNOPAD, ""));
set resp.http.emptypieces =
blob.encode(IDENTITY,
blob.decode_n(0, BASE64, req.http.unset + "" + req.http.unset
blob=blob.decode_n(0, BASE64, req.http.unset + "" + req.http.unset
+ "" + req.http.unset + ""));
set resp.http.decenc
= blob.encode(BASE64,
blob.decode_n(20, BASE64,
blob=blob.decode_n(20, BASE64,
req.http.foobarbazquux));
set resp.http.l = "L";
set resp.http.dec2pieces
= blob.encode(IDENTITY, blob.decode_n(8, BASE64,
= blob.encode(IDENTITY, blob=blob.decode_n(8, BASE64,
resp.http.l + "0hlbGxvIHdvcmxkLw=="));
set resp.http.pad = "==";
set resp.http.dec3pieces
= blob.encode(IDENTITY, blob.decode_n(12, BASE64,
= blob.encode(IDENTITY, blob=blob.decode_n(12, BASE64,
resp.http.l + "0hlbGxvIHdvcmxkLw"
+ resp.http.pad));
set resp.http.mid1 = "GxvI";
set resp.http.mid2 = "dvcmx";
set resp.http.dec7pieces
= blob.encode(IDENTITY, blob.decode_n(16, BASE64,
= blob.encode(IDENTITY, blob=blob.decode_n(16, BASE64,
resp.http.l + "0hlb" + resp.http.mid1
+ "H" + resp.http.mid2 + "kLw"
+ resp.http.pad));
......@@ -109,21 +107,21 @@ varnish v1 -vcl {
encoding=IDENTITY);
set resp.http.decnopad = blob.encode(IDENTITY,
blob.decode_n(18, BASE64URLNOPAD,
"L0hlbGxvIHdvcmxkLw"));
blob=blob.decode_n(18, BASE64URLNOPAD,
"L0hlbGxvIHdvcmxkLw"));
set resp.http.decnopad2pieces
= blob.encode(IDENTITY, blob.decode_n(19, BASE64URLNOPAD,
= blob.encode(IDENTITY, blob=blob.decode_n(19, BASE64URLNOPAD,
resp.http.l + "0hlbGxvIHdvcmxkLw"));
set resp.http.decnopad6pieces
= blob.encode(IDENTITY, blob.decode_n(18, BASE64URLNOPAD,
= blob.encode(IDENTITY, blob=blob.decode_n(18, BASE64URLNOPAD,
resp.http.l + "0hlb" + resp.http.mid1
+ "H" + resp.http.mid2 + "kLw"));
set resp.http.decnopadlong
= blob.encode(IDENTITY,
blob.decode_n(60, BASE64URLNOPAD,
blob=blob.decode_n(60, BASE64URLNOPAD,
"VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw"
));
......@@ -172,16 +170,16 @@ varnish v1 -vcl+backend {
set req.http.foo = "AAA=";
if (req.url == "/base64") {
set resp.http.bad64 = blob.encode(IDENTITY,
blob.decode_n(8, BASE64, "-_-_" + req.http.foo));
blob=blob.decode_n(8, BASE64, "-_-_" + req.http.foo));
}
elsif (req.url == "/base64url") {
set resp.http.badurl = blob.encode(IDENTITY,
blob.decode_n(8, BASE64URL, "+/+/" + req.http.foo));
blob=blob.decode_n(8, BASE64URL, "+/+/" + req.http.foo));
}
elsif (req.url == "/base64urlnopad") {
set resp.http.badpad = blob.encode(IDENTITY,
blob.decode_n(8, BASE64URLNOPAD,
"TWFu" + req.http.foo));
blob=blob.decode_n(8, BASE64URLNOPAD,
"TWFu" + req.http.foo));
}
}
}
......
This diff is collapsed.
......@@ -25,69 +25,67 @@ varnish v1 -vcl {
set resp.http.decuc =
blob.encode(IDENTITY,
blob.decode_n(9, URL, req.http.urlucfoobar));
blob=blob.decode_n(9, URL, req.http.urlucfoobar));
set resp.http.declc =
blob.encode(IDENTITY,
blob.decode_n(12, URL, req.http.urllcfoobar));
blob=blob.decode_n(12, URL, req.http.urllcfoobar));
set resp.http.dechobbesuc =
blob.encode(IDENTITY,
blob.decode_n(27, URL, req.http.urlhobbesuc));
blob=blob.decode_n(27, URL, req.http.urlhobbesuc));
set resp.http.dechobbeslc =
blob.encode(IDENTITY,
blob.decode_n(27, URL, req.http.urlhobbeslc));
blob=blob.decode_n(27, URL, req.http.urlhobbeslc));
set resp.http.decumlautsuc =
blob.encode(IDENTITY,
blob.decode_n(17, URL,
req.http.urlucumlauts));
blob=blob.decode_n(17, URL, req.http.urlucumlauts));
set resp.http.decumlautslc =
blob.encode(IDENTITY,
blob.decode_n(25, URL,
req.http.urllcumlauts));
blob=blob.decode_n(25, URL, req.http.urllcumlauts));
set resp.http.decphkuc =
blob.encode(IDENTITY,
blob.decode_n(18, URL, req.http.urlucphk));
blob=blob.decode_n(18, URL, req.http.urlucphk));
set resp.http.decphklc =
blob.encode(IDENTITY,
blob.decode_n(30, URL, req.http.urllcphk));
blob=blob.decode_n(30, URL, req.http.urllcphk));
set resp.http.decutf8uc =
blob.encode(IDENTITY,
blob.decode_n(9, URL, req.http.urlucutf8));
blob=blob.decode_n(9, URL, req.http.urlucutf8));
set resp.http.decutf8lc =
blob.encode(IDENTITY,
blob.decode_n(18, URL, req.http.urllcutf8));
blob=blob.decode_n(18, URL, req.http.urllcutf8));
set resp.http.decalluc =
blob.encode(HEXLC,
blob.decode_n(252, URL, req.http.urlalluc));
blob.encode(HEX,
blob=blob.decode_n(252, URL, req.http.urlalluc));
set resp.http.decalllc =
blob.encode(HEXUC,
blob.decode_n(252, URL, req.http.urlalllc));
blob.encode(HEX, UPPER,
blob.decode_n(252, URL, req.http.urlalllc));
set resp.http.decempty =
blob.encode(IDENTITY, blob.decode_n(10, URL, ""));
blob.encode(IDENTITY, blob=blob.decode_n(10, URL, ""));
set resp.http.decemptybyte =
blob.encode(IDENTITY, blob.decode_n(3, URL, "%00"));
blob.encode(IDENTITY, blob=blob.decode_n(3, URL, "%00"));
set resp.http.decemptypieces =
blob.encode(IDENTITY,
blob.decode_n(1, URL, req.http.unset + ""
blob=blob.decode_n(1, URL, req.http.unset + ""
+ req.http.unset + ""));
set req.http.part1 = "foo%";
set resp.http.dec2pieces =
blob.encode(IDENTITY,
blob.decode_n(6, URL, req.http.part1 +
blob=blob.decode_n(6, URL, req.http.part1 +
"20bar%20baz%20quux"));
set req.http.part2 = "0quux";
......@@ -99,13 +97,13 @@ varnish v1 -vcl {
set resp.http.dec3pieces =
blob.encode(IDENTITY,
blob.decode_n(18, URL, req.http.part1
blob=blob.decode_n(18, URL, req.http.part1
+ "20bar%20baz%2"
+ req.http.part2));
set resp.http.decmanypieces =
blob.encode(IDENTITY,
blob.decode_n(24, URL, "" + req.http.unset
blob=blob.decode_n(24, URL, "" + req.http.unset
+ req.http.part1 + req.http.unset + ""
+ req.http.unset + "" + "20bar%20baz%2"
+ "" + req.http.unset + req.http.part2
......@@ -149,20 +147,20 @@ varnish v1 -vcl+backend {
sub vcl_deliver {
if (req.url == "/percent") {
set resp.http.bad = blob.encode(URLUC,
set resp.http.bad = blob.encode(URL, UPPER,
blob.decode_n(1, URL, "%20"));
}
elsif (req.url == "/percent-two") {
set resp.http.bad = blob.encode(URLUC,
set resp.http.bad = blob.encode(URL, UPPER,
blob.decode_n(2, URL, "%20"));
}
elsif (req.url == "/comma") {
set resp.http.good = blob.encode(IDENTITY,
blob.decode_n(3, URL, "%2c%q"));
set resp.http.good = blob.encode(IDENTITY, blob=
blob.decode_n(3, URL, "%2c%q"));
}
elsif (req.url == "/colon") {
set resp.http.good = blob.encode(IDENTITY,
blob.decode_n(3, URL, "%3a%2q"));
set resp.http.good = blob.encode(IDENTITY, blob=
blob.decode_n(3, URL, "%3a%2q"));
}
}
}
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -20,7 +20,7 @@ varnish v1 -arg "-p http_max_hdr=128" -vcl+backend {
sub vcl_deliver {
# The .get() method retrieves the BLOB from an object.
set resp.http.MyBlob-As-Hex
= blob.encode(blob=myblob.get(), encoding=HEXLC);
= blob.encode(blob=myblob.get(), encoding=HEX);
# The .encode() method efficiently retrieves an encoding.
set resp.http.YourBlob-As-Base64 = yourblob.encode(BASE64);
......@@ -29,19 +29,20 @@ varnish v1 -arg "-p http_max_hdr=128" -vcl+backend {
# vice versa at runtime.
set resp.http.Base64-Encoded
= blob.encode(BASE64,
blob.decode(HEX, req.http.Hex-Encoded));
blob=blob.decode(HEX, req.http.Hex-Encoded));
}
sub vcl_recv {
# transcode() converts from one encoding to another.
set req.http.Hex-Encoded
= blob.transcode(decoding=BASE64, encoding=HEXUC, encoded="YmF6");
= blob.transcode(decoding=BASE64, encoding=HEX, case=UPPER,
encoded="YmF6");
# transcode() can replace other specific encoding/deconding
# vmods - e.g. vmod_urlcode
set req.url = blob.transcode(encoded=req.url, decoding=URL);
set req.http.url_urlcoded
= blob.transcode(encoded=req.url, encoding=URLLC);
= blob.transcode(encoded=req.url, encoding=URL);
}
# get output from recv
sub vcl_deliver {
......@@ -52,7 +53,7 @@ varnish v1 -arg "-p http_max_hdr=128" -vcl+backend {
# IDENTITY
sub vcl_deliver {
set resp.http.Trunced-Foo1
= blob.encode(IDENTITY, blob.decode(HEX, "666f6f00626172"));
= blob.encode(IDENTITY, blob=blob.decode(HEX, "666f6f00626172"));
set resp.http.Trunced-Foo2
= blob.encode(blob=blob.decode(HEX, "666f6f00626172"));
}
......@@ -63,21 +64,21 @@ varnish v1 -arg "-p http_max_hdr=128" -vcl+backend {
set resp.http.First = "abc";
set resp.http.Second = "def0";
set resp.http.Hex-Decoded = blob.encode(
HEXLC,
blob.decode(HEX, resp.http.First + resp.http.Second));
HEX,
blob=blob.decode(HEX, resp.http.First + resp.http.Second));
}
############################################################
# encode - also contains decode examples
sub vcl_deliver {
set resp.http.encode1
= blob.encode(HEXLC, blob.decode(BASE64, "Zm9vYmFyYmF6"));
= blob.encode(HEX, blob=blob.decode(BASE64, "Zm9vYmFyYmF6"));
# same with named parameters
set resp.http.encode2
= blob.encode(blob=blob.decode(encoded="Zm9vYmFyYmF6",
decoding=BASE64),
encoding=HEXLC);
encoding=HEX);
# convert blob to string
set resp.http.encode3
......@@ -87,7 +88,8 @@ varnish v1 -arg "-p http_max_hdr=128" -vcl+backend {
############################################################
# transcode
sub vcl_deliver {
set resp.http.Hex2Base64-1 = blob.transcode(HEX, BASE64, "666f6f");
set resp.http.Hex2Base64-1
= blob.transcode(HEX, BASE64, encoded="666f6f");
# same with named parameters
set resp.http.Hex2Base64-2
......@@ -100,7 +102,7 @@ varnish v1 -arg "-p http_max_hdr=128" -vcl+backend {
# replacement for urlcode.encode("foo bar")
set resp.http.urlencoded
= blob.transcode(encoded="foo bar", encoding=URLLC);
= blob.transcode(encoded="foo bar", encoding=URL);
}
############################################################
......
......@@ -183,19 +183,21 @@ varnish v1 -vcl {
sub vcl_synth {
set resp.http.up03
= blob.encode(BASE64, blob.subblob(up07.get(), 4B));
= blob.encode(BASE64, blob=blob.subblob(up07.get(), 4B));
set resp.http.down07060504
= blob.encode(BASE64, blob.subblob(down07.get(), 4B));
= blob.encode(BASE64, blob=blob.subblob(down07.get(), 4B));
set resp.http.up04050607
= blob.encode(BASE64, blob.subblob(up07.get(), 4B, 4B));
= blob.encode(BASE64,
blob=blob.subblob(up07.get(), 4B, 4B));
set resp.http.down03
= blob.encode(BASE64, blob.subblob(down07.get(), 4B, 4B));
= blob.encode(BASE64,
blob=blob.subblob(down07.get(), 4B, 4B));
set resp.http.up07
= blob.encode(BASE64, blob.subblob(up07.get(), 8B));
= blob.encode(BASE64, blob=blob.subblob(up07.get(), 8B));
set resp.http.down07
= blob.encode(BASE64, blob.subblob(down07.get(), 8B));
= blob.encode(BASE64, blob=blob.subblob(down07.get(), 8B));
set resp.http.zerobytes
= blob.encode(BASE64, blob.subblob(down07.get(), 0B));
= blob.encode(BASE64, blob=blob.subblob(down07.get(), 0B));
set resp.http.zerolen
= blob.length(blob.subblob(down07.get(), 0B));
}
......@@ -231,16 +233,17 @@ varnish v1 -vcl+backend {
sub vcl_deliver {
if (req.url == "/empty") {
set resp.http.empty = blob.encode(BASE64,
set resp.http.empty = blob.encode(BASE64, blob=
blob.subblob(empty.get(), 1B));
}
elsif (req.url == "/toolong") {
set resp.http.toolong
= blob.encode(BASE64, blob.subblob(up07.get(), 9B));
= blob.encode(BASE64,
blob=blob.subblob(up07.get(), 9B));
}
elsif (req.url == "/badoffset") {
set resp.http.badoffset = blob.encode(BASE64,
blob.subblob(up07.get(), 4B, 5B));
blob=blob.subblob(up07.get(), 4B, 5B));
}
}
}
......
......@@ -222,7 +222,7 @@ varnish v1 -errvcl {'req.hash': Not available in method 'vcl_recv'.} {
import blob;
backend b { .host = "127.0.0.1"; }
sub vcl_recv {
blob.encode(HEXLC, req.hash);
blob.encode(HEX, LOWER, req.hash);
}
}
......@@ -230,7 +230,7 @@ varnish v1 -errvcl {'req.hash': Not available in method 'vcl_hash'.} {
import blob;
backend b { .host = "127.0.0.1"; }
sub vcl_hash {
blob.encode(HEXLC, req.hash);
blob.encode(HEX, LOWER, req.hash);
}
}
......
......@@ -80,15 +80,16 @@ decode(char *restrict *restrict dest, char *restrict const buf,
}
ssize_t
base64_encode(const enum encoding enc, char *restrict const buf,
const size_t buflen, const char *restrict const inbuf,
const size_t inlength)
base64_encode(const enum encoding enc, const enum case_e kase,
char *restrict const buf, const size_t buflen,
const char *restrict const inbuf, const size_t inlength)
{
const struct b64_alphabet *alpha = &b64_alphabet[enc];
char *p = buf;
const uint8_t *in = (const uint8_t *)inbuf;
const uint8_t * const end = in + inlength;
(void) kase;
AN(buf);
AN(alpha);
if (in == NULL || inlength == 0)
......
......@@ -75,21 +75,21 @@ hex2byte(const unsigned char hi, const unsigned char lo)
}
ssize_t
hex_encode(const enum encoding enc, char *restrict const buf,
const size_t buflen, const char *restrict const in,
const size_t inlen)
hex_encode(const enum encoding enc, const enum case_e kase,
char *restrict const buf, const size_t buflen,
const char *restrict const in, const size_t inlen)
{
char *p = buf;
const char *alphabet = hex_alphabet[0];
AN(buf);
assert(enc == HEXUC || enc == HEXLC);
assert(enc == HEX);
if (in == NULL || inlen == 0)
return 0;
if (buflen < hex_encode_l(inlen))
return -1;
if (enc != HEXLC)
if (kase == UPPER)
alphabet = hex_alphabet[1];
for (int i = 0; i < inlen; i++) {
......
......@@ -50,11 +50,12 @@ id_decode_l(size_t l)
}
ssize_t
id_encode(const enum encoding enc, char *restrict const buf,
const size_t buflen, const char *restrict const in,
const size_t inlen)
id_encode(const enum encoding enc, const enum case_e kase,
char *restrict const buf, const size_t buflen,
const char *restrict const in, const size_t inlen)
{
(void) enc;
(void) kase;
AN(buf);
if (buflen < inlen + 1)
......
......@@ -17,9 +17,9 @@ parse_encoding (const char *m) {
switch (m[0]) {
case 'B': goto _0B; // BASE64, BASE64URL, BASE64URLNOPAD
case 'H': goto _0H; // HEX, HEXLC, HEXUC
case 'H': goto _0H; // HEX
case 'I': goto _0I; // IDENTITY
case 'U': goto _0U; // URL, URLLC, URLUC
case 'U': goto _0U; // URL
default: goto invalid;
}
_0B:
......@@ -85,39 +85,11 @@ parse_encoding (const char *m) {
}
goto invalid;
_0H:
switch (m[1]) {
case 'E': goto _1HE; // HEX, HEXLC, HEXUC
default: goto invalid;
}
_1HE:
switch (m[2]) {
case 'X': goto _2HEX; // HEX, HEXLC, HEXUC
default: goto invalid;
}
_2HEX:
//HEX
if (term(m[3])) {
if ((m[1] == 'E') && (m[2] == 'X') && (term(m[3]))) {
r = HEX;
goto ok;
}
switch (m[3]) {
case 'L': goto _3HEXL; // HEXLC
case 'U': goto _3HEXU; // HEXUC
default: goto invalid;
}
_3HEXL:
//HEXLC
if ((m[4] == 'C') && (term(m[5]))) {
r = HEXLC;
goto ok;
}
goto invalid;
_3HEXU:
//HEXUC
if ((m[4] == 'C') && (term(m[5]))) {
r = HEXUC;
goto ok;
}
goto invalid;
_0I:
//IDENTITY
......@@ -127,39 +99,11 @@ parse_encoding (const char *m) {
}
goto invalid;
_0U:
switch (m[1]) {
case 'R': goto _1UR; // URL, URLLC, URLUC
default: goto invalid;
}
_1UR:
switch (m[2]) {
case 'L': goto _2URL; // URL, URLLC, URLUC
default: goto invalid;
}
_2URL:
//URL
if (term(m[3])) {
if ((m[1] == 'R') && (m[2] == 'L') && (term(m[3]))) {
r = URL;
goto ok;
}
switch (m[3]) {
case 'L': goto _3URLL; // URLLC
case 'U': goto _3URLU; // URLUC
default: goto invalid;
}
_3URLL:
//URLLC
if ((m[4] == 'C') && (term(m[5]))) {
r = URLLC;
goto ok;
}
goto invalid;
_3URLU:
//URLUC
if ((m[4] == 'C') && (term(m[5]))) {
r = URLUC;
goto ok;
}
goto invalid;
ok:
return r;
......
......@@ -14,11 +14,7 @@ enum encoding {
BASE64URL,
BASE64URLNOPAD,
HEX,
HEXUC,
HEXLC,
URL,
URLLC,
URLUC,
__MAX_ENCODING
};
......
......@@ -79,20 +79,20 @@ isoutofrange(const uint8_t c)
}
ssize_t
url_encode(const enum encoding enc, char *restrict const buf,
const size_t buflen, const char *restrict const in,
const size_t inlen)
url_encode(const enum encoding enc, const enum case_e kase,
char *restrict const buf, const size_t buflen,
const char *restrict const in, const size_t inlen)
{
char *p = buf;
const char * const end = buf + buflen;
const char *alphabet = hex_alphabet[0];
AN(buf);
assert(enc == URLUC || enc == URLLC);
assert(enc == URL);
if (in == NULL || inlen == 0)
return 0;
if (enc != URLLC)
if (kase == UPPER)
alphabet = hex_alphabet[1];
for (int i = 0; i < inlen; i++) {
......
This diff is collapsed.
......@@ -42,7 +42,7 @@ struct vmod_blob_blob {
unsigned magic;
#define VMOD_BLOB_MAGIC 0xfade4fa9
struct vmod_priv blob;
char *encoding[__MAX_ENCODING];
char *encoding[__MAX_ENCODING][2];
pthread_mutex_t lock;
};
......@@ -51,18 +51,6 @@ struct vmod_blob_blob {
.decode = base64_decode, \
.encode = base64_encode
#define HEX_FUNCS \
.decode_l = hex_decode_l, \
.decode = hex_decode, \
.encode_l = hex_encode_l, \
.encode = hex_encode
#define URL_FUNCS \
.decode_l = url_decode_l, \
.decode = url_decode, \
.encode_l = url_encode_l, \
.encode = url_encode
static const struct vmod_blob_fptr {
len_f *const decode_l;
decode_f *const decode;
......@@ -95,28 +83,20 @@ static const struct vmod_blob_fptr {
.encode_l = base64nopad_encode_l
},
[HEX] = {
HEX_FUNCS
},
[HEXUC] = {
HEX_FUNCS
},
[HEXLC] = {
HEX_FUNCS
.decode_l = hex_decode_l,
.decode = hex_decode,
.encode_l = hex_encode_l,
.encode = hex_encode
},
[URL] = {
URL_FUNCS
},
[URLUC] = {
URL_FUNCS
.decode_l = url_decode_l,
.decode = url_decode,
.encode_l = url_encode_l,
.encode = url_encode
},
[URLLC] = {
URL_FUNCS
}
};
#undef B64_FUNCS
#undef HEX_FUNCS
#undef URL_FUNCS
#define ERR(ctx, msg) \
VRT_fail((ctx), "vmod blob error: " msg)
......@@ -175,6 +155,21 @@ err_decode(VRT_CTX, const char *enc)
}
}
static inline enum case_e
parse_case(VCL_ENUM case_s)
{
switch(*case_s) {
case 'L':
AZ(strcmp(case_s + 1, "OWER"));
return LOWER;
case 'U':
AZ(strcmp(case_s + 1, "PPER"));
return UPPER;
default:
WRONG("illegal case enum");
}
}
/* Objects */
VCL_VOID __match_proto__(td_blob_blob__init)
......@@ -245,10 +240,12 @@ vmod_blob_get(VRT_CTX, struct vmod_blob_blob *b)
}
VCL_STRING __match_proto__(td_blob_blob_encode)
vmod_blob_encode(VRT_CTX, struct vmod_blob_blob *b, VCL_ENUM encs)
vmod_blob_encode(VRT_CTX, struct vmod_blob_blob *b, VCL_ENUM encs,
VCL_ENUM case_s)
{
enum encoding enc = parse_encoding(encs);
AENC(enc);
enum case_e kase = parse_case(case_s);
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(b, VMOD_BLOB_MAGIC);
......@@ -256,29 +253,29 @@ vmod_blob_encode(VRT_CTX, struct vmod_blob_blob *b, VCL_ENUM encs)
if (b->blob.len == 0)
return "";
if (b->encoding[enc] == NULL) {
if (b->encoding[enc][kase] == NULL) {
AZ(pthread_mutex_lock(&b->lock));
if (b->encoding[enc] == NULL) {
if (b->encoding[enc][kase] == NULL) {
ssize_t len = func[enc].encode_l(b->blob.len);
assert(len >= 0);
if (len == 0)
b->encoding[enc] = empty;
b->encoding[enc][kase] = empty;
else {
b->encoding[enc] = malloc(len);
if (b->encoding[enc] == NULL)
b->encoding[enc][kase] = malloc(len);
if (b->encoding[enc][kase] == NULL)
ERRNOMEM(ctx, "cannot encode");
else {
char *s = b->encoding[enc];
char *s = b->encoding[enc][kase];
len =
func[enc].encode(
enc, s, len,
enc, kase, s, len,
b->blob.priv,
b->blob.len);
assert(len >= 0);
if (len == 0) {
free(s);
b->encoding[enc] = empty;
b->encoding[enc][kase] = empty;
}
else
s[len] = '\0';
......@@ -287,7 +284,7 @@ vmod_blob_encode(VRT_CTX, struct vmod_blob_blob *b, VCL_ENUM encs)
}
AZ(pthread_mutex_unlock(&b->lock));
}
return b->encoding[enc];
return b->encoding[enc][kase];
}
VCL_VOID __match_proto__(td_blob_blob__fini)
......@@ -306,9 +303,12 @@ vmod_blob__fini(struct vmod_blob_blob **blobp)
b->blob.priv = NULL;
}
for (int i = 0; i < __MAX_ENCODING; i++)
if (b->encoding[i] != NULL && b->encoding[i] != empty) {
free(b->encoding[i]);
b->encoding[i] = NULL;
for (int j = 0; j < 2; j++) {
char *s = b->encoding[i][j];
if (s != NULL && s != empty) {
free(s);
b->encoding[i][j] = NULL;
}
}
AZ(pthread_mutex_destroy(&b->lock));
FREE_OBJ(b);
......@@ -413,7 +413,7 @@ vmod_decode_n(VRT_CTX, VCL_INT n, VCL_ENUM decs, const char *p, ...)
}
static VCL_STRING
encode(VRT_CTX, enum encoding enc, VCL_BLOB b)
encode(VRT_CTX, enum encoding enc, enum case_e kase, VCL_BLOB b)
{
struct wb_s wb;
ssize_t len;
......@@ -430,7 +430,7 @@ encode(VRT_CTX, enum encoding enc, VCL_BLOB b)
return NULL;
}
len = func[enc].encode(enc,
len = func[enc].encode(enc, kase,
wb_buf(&wb), wb_space(&wb), b->priv, b->len);
if (len == -1) {
......@@ -447,18 +447,26 @@ encode(VRT_CTX, enum encoding enc, VCL_BLOB b)
}
VCL_STRING __match_proto__(td_blob_encode)
vmod_encode(VRT_CTX, VCL_ENUM encs, VCL_BLOB b)
vmod_encode(VRT_CTX, VCL_ENUM encs, VCL_ENUM case_s, VCL_BLOB b)
{
enum encoding enc = parse_encoding(encs);
return encode(ctx, enc, b);
enum case_e kase = parse_case(case_s);
return encode(ctx, enc, kase, b);
}
static inline int
encodes_hex(enum encoding enc)
{
return (enc == HEX || enc == URL);
}
static VCL_STRING
transcode(VRT_CTX, VCL_INT n, VCL_ENUM decs, VCL_ENUM encs,
transcode(VRT_CTX, VCL_INT n, VCL_ENUM decs, VCL_ENUM encs, VCL_ENUM case_s,
const char *restrict const p, va_list ap)
{
enum encoding dec = parse_encoding(decs);
enum encoding enc = parse_encoding(encs);
enum case_e kase = parse_case(case_s);
va_list aq;
struct vmod_priv b;
VCL_STRING r;
......@@ -497,8 +505,11 @@ transcode(VRT_CTX, VCL_INT n, VCL_ENUM decs, VCL_ENUM encs,
* If the encoding and decoding are the same, and the decoding was
* legal, just return the string, if there was only one in the
* STRING_LIST, or else the concatenated string.
* For encodings with hex digits, we cannot assume the same result.
* since the call may specify upper- or lower-case that differs
* from the encoded string.
*/
if (n == -1 && enc == dec) {
if (n == -1 && enc == dec && !encodes_hex(enc)) {
const char *q, *pp = p;
va_copy(aq, ap);
q = find_nonempty_va(&pp, ap);
......@@ -514,19 +525,19 @@ transcode(VRT_CTX, VCL_INT n, VCL_ENUM decs, VCL_ENUM encs,
return r;
}
r = encode(ctx, enc, &b);
r = encode(ctx, enc, kase, &b);
return (r);
}
VCL_STRING __match_proto__(td_blob_transcode)
vmod_transcode(VRT_CTX, VCL_ENUM decs, VCL_ENUM encs,
vmod_transcode(VRT_CTX, VCL_ENUM decs, VCL_ENUM encs, VCL_ENUM case_s,
const char *p, ...)
{
va_list ap;
VCL_STRING r;
va_start(ap, p);
r = transcode(ctx, -1, decs, encs, p, ap);
r = transcode(ctx, -1, decs, encs, case_s, p, ap);
va_end(ap);
return (r);
......@@ -534,13 +545,13 @@ vmod_transcode(VRT_CTX, VCL_ENUM decs, VCL_ENUM encs,
VCL_STRING __match_proto__(td_blob_transcode_n)
vmod_transcode_n(VRT_CTX, VCL_INT n, VCL_ENUM decs, VCL_ENUM encs,
const char *p, ...)
VCL_ENUM case_s, const char *p, ...)
{
va_list ap;
VCL_STRING r;
va_start(ap, p);
r = transcode(ctx, n, decs, encs, p, ap);
r = transcode(ctx, n, decs, encs, case_s, p, ap);
va_end(ap);
return (r);
......
......@@ -34,6 +34,11 @@
#define AENC(enc) assert((enc) > _INVALID && (enc) < __MAX_ENCODING)
enum case_e {
LOWER,
UPPER,
};
/*
* Length estimate interface
*/
......@@ -46,6 +51,7 @@ size_t len_f(size_t);
* encoding.
*
* enc: encoding enum (from parse_encoding.h)
* kase: case enum (for encodings with hex digits)
* buf: destination of the encoded string
* buflen: maximum length available at buf
* in: source of data to be encoded
......@@ -65,9 +71,9 @@ size_t len_f(size_t);
* include any terminating null byte)
*/
typedef
ssize_t encode_f(const enum encoding enc, char *restrict const buf,
const size_t buflen, const char *restrict const in,
const size_t inlen);
ssize_t encode_f(const enum encoding enc, const enum case_e kase,
char *restrict const buf, const size_t buflen,
const char *restrict const in, const size_t inlen);
/*
* General interface for a decoder: decode the concatenation of strings
......
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