Commit 7c24567d authored by Dridi Boukelmoune's avatar Dridi Boukelmoune Committed by Pål Hermunn Johansen

Remove blob operations from vmod-vtc

They were inherited from vmod-debug, from a time when vmod-blob didn't
exist in the source tree.

Refs #2362
Refs #2402
Refs #2407
parent 8d3e711e
...@@ -6,12 +6,13 @@ server s1 { ...@@ -6,12 +6,13 @@ server s1 {
} -start } -start
varnish v1 -vcl+backend { varnish v1 -vcl+backend {
import vtc; import blob;
sub vcl_backend_response { sub vcl_backend_response {
set beresp.http.bereq_hash = vtc.blob2hex(bereq.hash); set beresp.http.bereq_hash = blob.encode(HEXLC, bereq.hash);
} }
sub vcl_deliver { sub vcl_deliver {
set resp.http.req_hash = vtc.blob2hex(req.hash); set resp.http.req_hash = blob.encode(HEXLC, req.hash);
} }
} -start } -start
......
varnishtest "Test VMOD BLOBS" varnishtest "Test VMOD BLOBS"
server s1 {
rxreq
txresp
} -start
varnish v1 -vcl+backend {
import vtc;
sub vcl_deliver {
set resp.http.foo = vtc.blob2hex(vtc.str2blob("gunk"));
}
} -start
client c1 {
txreq
rxresp
expect resp.http.foo == 67756e6b
} -run
delay .1
varnish v1 -errvcl {BLOBs can only be used as arguments to VMOD functions.} { varnish v1 -errvcl {BLOBs can only be used as arguments to VMOD functions.} {
backend b1 {.host = "127.0.0.1";} backend b1 {.host = "${bad_backend}";}
import vtc;
sub vcl_deliver { sub vcl_deliver {
set resp.http.foo = vtc.str2blob("gunk"); set resp.http.foo = req.hash;
} }
} }
varnish v1 -errvcl {Wrong argument type. Expected BLOB. Got STRING.} { varnish v1 -errvcl {Wrong argument type. Expected BLOB. Got STRING.} {
backend b1 {.host = "127.0.0.1";} backend b1 {.host = "${bad_backend}";}
import vtc; import blob;
sub vcl_deliver { sub vcl_deliver {
set resp.http.foo = vtc.blob2hex("gunk"); blob.encode(blob = "blob");
} }
} }
...@@ -219,18 +219,18 @@ varnish v1 -errvcl {Function returns VOID} { ...@@ -219,18 +219,18 @@ varnish v1 -errvcl {Function returns VOID} {
} }
varnish v1 -errvcl {'req.hash': Not available in method 'vcl_recv'.} { varnish v1 -errvcl {'req.hash': Not available in method 'vcl_recv'.} {
import blob;
backend b { .host = "127.0.0.1"; } backend b { .host = "127.0.0.1"; }
import vtc;
sub vcl_recv { sub vcl_recv {
set req.http.foo = vtc.blob2hex(req.hash); blob.encode(HEXLC, req.hash);
} }
} }
varnish v1 -errvcl {'req.hash': Not available in method 'vcl_hash'.} { varnish v1 -errvcl {'req.hash': Not available in method 'vcl_hash'.} {
import blob;
backend b { .host = "127.0.0.1"; } backend b { .host = "127.0.0.1"; }
import vtc;
sub vcl_hash { sub vcl_hash {
set req.http.foo = vtc.blob2hex(req.hash); blob.encode(HEXLC, req.hash);
} }
} }
...@@ -255,9 +255,9 @@ varnish v1 -errvcl {Expected 'from path ...'} { ...@@ -255,9 +255,9 @@ varnish v1 -errvcl {Expected 'from path ...'} {
} }
varnish v1 -errvcl {INT * BLOB not possible.} { varnish v1 -errvcl {INT * BLOB not possible.} {
import vtc; import blob;
sub vcl_deliver { sub vcl_deliver {
set resp.status = 100 * vtc.str2blob("a"); set resp.status = 100 * blob.decode(HEX, "a");
} }
} }
......
...@@ -128,20 +128,6 @@ Returns the size in bytes of a collection of C-datatypes: ...@@ -128,20 +128,6 @@ Returns the size in bytes of a collection of C-datatypes:
This can be useful for VMOD authors in conjunction with workspace operations. This can be useful for VMOD authors in conjunction with workspace operations.
BLOBS
=====
For VMODs dealing with BLOB arguments or return values, the following functions
offer convenience conversions to and from STRING.
$Function BLOB str2blob(STRING src)
Turn a string into a blob.
$Function STRING blob2hex(BLOB src)
Hexdump a blob.
SEE ALSO SEE ALSO
======== ========
......
...@@ -221,42 +221,3 @@ vmod_typesize(VRT_CTX, VCL_STRING s) ...@@ -221,42 +221,3 @@ vmod_typesize(VRT_CTX, VCL_STRING s)
} }
return (i); return (i);
} }
/*--------------------------------------------------------------------*/
VCL_BLOB __match_proto__(td_vtc_str2blob)
vmod_str2blob(VRT_CTX, VCL_STRING s)
{
struct vmod_priv *p;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
p = WS_Alloc(ctx->ws, sizeof *p);
AN(p);
memset(p, 0, sizeof *p);
p->len = strlen(s);
p->priv = WS_Copy(ctx->ws, s, -1);
return (p);
}
VCL_STRING __match_proto__(td_vtc_blob2hex)
vmod_blob2hex(VRT_CTX, VCL_BLOB b)
{
char *s, *p;
uint8_t *q;
int i;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
s = WS_Alloc(ctx->ws, b->len * 2 + 2);
AN(s);
p = s;
q = b->priv;
for (i = 0; i < b->len; i++) {
assert(snprintf(p, 3, "%02x", *q) == 2);
p += 2;
q += 1;
}
VRT_priv_fini(b);
return (s);
}
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