Commit 76a59341 authored by Geoff Simmons's avatar Geoff Simmons

add the blob object interface

parent a2326dfb
# looks like -*- perl -*-
varnishtest "blob object interface"
server s1 {} -start
varnish v1 -arg "-i serverid" -vcl+backend {
import convert from "${vmod_topbuild}/src/.libs/libvmod_convert.so";
sub vcl_init {
new id = convert.blob(IDENTITY,
"The quick brown fox jumps over the lazy dog");
new idpieces
= convert.blob(IDENTITY, "" + server.identity + " "
+ server.identity + "");
new idempty = convert.blob(IDENTITY, "");
new hexuc = convert.blob(HEX, "666F6F206261722062617A2071757578");
new hexlc = convert.blob(HEX, "666f6f206261722062617a2071757578");
new hexmix = convert.blob(HEX, "666F6F206261722062617a2071757578");
new b64 = convert.blob(BASE64, "L0hlbGxvIHdvcmxkLw==");
new b64nopad = convert.blob(BASE64URLNOPAD, "L0hlbGxvIHdvcmxkLw");
}
sub vcl_recv {
return(synth(200));
}
sub vcl_synth {
set resp.http.id = convert.encode(IDENTITY, id.get());
set resp.http.idpieces = convert.encode(IDENTITY, idpieces.get());
set resp.http.idempty = convert.encode(IDENTITY, idempty.get());
set resp.http.hexuc = convert.encode(IDENTITY, hexuc.get());
set resp.http.hexlc = convert.encode(IDENTITY, hexlc.get());
set resp.http.hexmix = convert.encode(IDENTITY, hexmix.get());
set resp.http.b64 = convert.encode(IDENTITY, b64.get());
set resp.http.b64nopad = convert.encode(IDENTITY, b64nopad.get());
}
} -start
client c1 {
txreq
rxresp
expect resp.http.id == "The quick brown fox jumps over the lazy dog"
expect resp.http.idpieces == "serverid serverid"
expect resp.http.idempty == ""
expect resp.http.hexuc == "foo bar baz quux"
expect resp.http.hexlc == "foo bar baz quux"
expect resp.http.hexmix == "foo bar baz quux"
expect resp.http.b64 == "/Hello world/"
expect resp.http.b64nopad == "/Hello world/"
}
client c1 -run
......@@ -33,6 +33,12 @@
#include "vmod_convert.h"
#include "wb.h"
struct vmod_convert_blob {
unsigned magic;
#define VMOD_CONVERT_BLOB_MAGIC 0xfade4fa9
struct vmod_priv blob;
};
static const struct vmod_priv const null_blob[1] =
{
{
......@@ -159,6 +165,80 @@ event(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e event)
return (0);
}
/* Objects */
VCL_VOID __match_proto__(td_convert_blob__init)
vmod_blob__init(VRT_CTX, struct vmod_convert_blob **blobp, const char *vcl_name,
VCL_ENUM decs, const char *p, ...)
{
struct vmod_convert_blob *b;
enum encoding dec = parse_encoding(decs);
va_list ap;
ssize_t len;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
AN(blobp);
AZ(*blobp);
AN(vcl_name);
ALLOC_OBJ(b, VMOD_CONVERT_BLOB_MAGIC);
AN(b);
*blobp = b;
b->blob.free = NULL;
va_start(ap, p);
len = decode_l_va(dec, p, ap);
va_end(ap);
if (len == 0) {
b->blob.len = 0;
b->blob.priv = NULL;
return;
}
assert(len > 0);
b->blob.priv = malloc(len);
AN(b->blob.priv);
va_start(ap, p);
len = decode(dec, b->blob.priv, len, p, ap);
va_end(ap);
if (len == -1) {
/* XXX: error msg in ctx->msg and fail */
free(b->blob.priv);
FREE_OBJ(b);
*blobp = NULL;
return;
}
if (len == 0) {
b->blob.len = 0;
free(b->blob.priv);
b->blob.priv = NULL;
return;
}
b->blob.len = len;
}
VCL_BLOB __match_proto__(td_convert_blob_get)
vmod_blob_get(VRT_CTX, struct vmod_convert_blob *b)
{
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(b, VMOD_CONVERT_BLOB_MAGIC);
return &b->blob;
}
VCL_VOID __match_proto__(td_convert_blob__fini)
vmod_blob__fini(struct vmod_convert_blob **blobp)
{
struct vmod_convert_blob *b;
AN(*blobp);
b = *blobp;
*blobp = NULL;
CHECK_OBJ_NOTNULL(b, VMOD_CONVERT_BLOB_MAGIC);
if (b->blob.priv != NULL)
free(b->blob.priv);
FREE_OBJ(b);
}
/* Functions */
VCL_BLOB __match_proto__(td_convert_decode)
......
......@@ -14,6 +14,10 @@ XXX gen ENUMs
$Event event
$Object blob(ENUM { IDENTITY, BASE64, BASE64URL, BASE64URLNOPAD, HEX}, STRING_LIST)
$Method BLOB .get()
$Function BLOB decode(ENUM { IDENTITY, BASE64, BASE64URL, BASE64URLNOPAD, HEX}, STRING_LIST)
XXX DOC
$Function STRING encode(ENUM { IDENTITY, BASE64, BASE64URL, BASE64URLNOPAD, HEX, HEXLC}, BLOB)
......
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