Commit 90dfbbc3 authored by Geoff Simmons's avatar Geoff Simmons

Revert "support use of decode/encode/transcode for varnish >= 5.0"

This reverts commit 79de4cf9.

Will solve this instead by maintaining a 4.1 branch, for versions
not compatible with Varnish < 5.0
parent 8833dfe0
...@@ -4,13 +4,53 @@ varnishtest "test permitted use of functions in vcl_subs" ...@@ -4,13 +4,53 @@ varnishtest "test permitted use of functions in vcl_subs"
varnish v1 -vcl { backend b { .host="${bad_ip}"; } } -start varnish v1 -vcl { backend b { .host="${bad_ip}"; } } -start
# for varnish < 5.0, we have no workspace in init/fini, so we cannot varnish v1 -errvcl {vmod blobcode error: decode() is illegal in vcl_init() and vcl_fini().vmod blobcode error: encode() is illegal in vcl_init() and vcl_fini().} {
# use the *code() functions there import blobcode from "${vmod_topbuild}/src/.libs/libvmod_blobcode.so";
# We could have separate tests for those versions, but looking forward, backend b { .host="${bad_ip}"; }
# this appears to be wasted effort. sub vcl_init {
# The *code() functions are legal in every other VCL sub for all supported new err = blobcode.blob(IDENTITY, blobcode.encode(IDENTITY,
# varnish versions blobcode.decode(IDENTITY, "x")));
}
}
varnish v1 -errvcl {vmod blobcode error: transcode() is illegal in vcl_init() and vcl_fini().} {
import blobcode from "${vmod_topbuild}/src/.libs/libvmod_blobcode.so";
backend b { .host="${bad_ip}"; }
sub vcl_init {
new err = blobcode.blob(IDENTITY,
blobcode.transcode(IDENTITY, IDENTITY, "x"));
}
}
varnish v1 -errvcl {vmod blobcode error: encode() is illegal in vcl_init() and vcl_fini().} {
import blobcode from "${vmod_topbuild}/src/.libs/libvmod_blobcode.so";
backend b { .host="${bad_ip}"; }
sub vcl_init {
new b1 = blobcode.blob(IDENTITY, "foo");
new b2 = blobcode.blob(IDENTITY, blobcode.encode(IDENTITY, b1.get()));
}
}
varnish v1 -errvcl {vmod blobcode error: decode() is illegal in vcl_init() and vcl_fini().vmod blobcode error: encode() is illegal in vcl_init() and vcl_fini().} {
import blobcode from "${vmod_topbuild}/src/.libs/libvmod_blobcode.so";
backend b { .host="${bad_ip}"; }
sub vcl_init {
new err = blobcode.blob(IDENTITY, blobcode.encode(IDENTITY,
blobcode.decode_n(1, IDENTITY, "x")));
}
}
varnish v1 -errvcl {vmod blobcode error: transcode() is illegal in vcl_init() and vcl_fini().} {
import blobcode from "${vmod_topbuild}/src/.libs/libvmod_blobcode.so";
backend b { .host="${bad_ip}"; }
sub vcl_init {
new err = blobcode.blob(IDENTITY,
blobcode.transcode_n(1, IDENTITY, IDENTITY,
"x"));
}
}
# The *code() functions are legal in every other VCL sub
varnish v1 -vcl { varnish v1 -vcl {
import blobcode from "${vmod_topbuild}/src/.libs/libvmod_blobcode.so"; import blobcode from "${vmod_topbuild}/src/.libs/libvmod_blobcode.so";
backend b { .host="${bad_ip}"; } backend b { .host="${bad_ip}"; }
......
...@@ -136,6 +136,9 @@ static const struct vmod_blobcode_fptr { ...@@ -136,6 +136,9 @@ static const struct vmod_blobcode_fptr {
#define INIT_FINI(ctx) (((ctx)->method & (VCL_MET_INIT | VCL_MET_FINI)) != 0) #define INIT_FINI(ctx) (((ctx)->method & (VCL_MET_INIT | VCL_MET_FINI)) != 0)
#define ILLEGAL(ctx, m) \
ERR((ctx), m " is illegal in vcl_init() and vcl_fini().")
static const struct vmod_priv null_blob[1] = static const struct vmod_priv null_blob[1] =
{ {
{ {
...@@ -395,17 +398,6 @@ decode_id_inplace(struct vmod_priv *b, VCL_INT n, const char *restrict p, ...@@ -395,17 +398,6 @@ decode_id_inplace(struct vmod_priv *b, VCL_INT n, const char *restrict p,
return (b); return (b);
} }
static int
has_ws(VRT_CTX, const char * const msg)
{
if (VRT_MAJOR_VERSION < 5 && INIT_FINI(ctx)) {
VERR(ctx, "%s", msg);
return 0;
}
return 1;
}
static VCL_BLOB static VCL_BLOB
decode(VRT_CTX, VCL_INT n, VCL_ENUM decs, decode(VRT_CTX, VCL_INT n, VCL_ENUM decs,
const char *restrict const p, va_list ap) { const char *restrict const p, va_list ap) {
...@@ -418,9 +410,10 @@ decode(VRT_CTX, VCL_INT n, VCL_ENUM decs, ...@@ -418,9 +410,10 @@ decode(VRT_CTX, VCL_INT n, VCL_ENUM decs,
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
AENC(dec); AENC(dec);
if (! has_ws(ctx, __func__)) if (INIT_FINI(ctx)) {
ILLEGAL(ctx, "decode()");
return NULL; return NULL;
}
CHECK_OBJ_NOTNULL(ctx->ws, WS_MAGIC); CHECK_OBJ_NOTNULL(ctx->ws, WS_MAGIC);
snap = WS_Snapshot(ctx->ws); snap = WS_Snapshot(ctx->ws);
...@@ -501,14 +494,14 @@ encode(VRT_CTX, enum encoding enc, VCL_BLOB b) { ...@@ -501,14 +494,14 @@ encode(VRT_CTX, enum encoding enc, VCL_BLOB b) {
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
AENC(enc); AENC(enc);
if (! has_ws(ctx, __func__)) if (INIT_FINI(ctx)) {
ILLEGAL(ctx, "encode()");
return NULL; return NULL;
}
CHECK_OBJ_NOTNULL(ctx->ws, WS_MAGIC);
if (b == NULL) if (b == NULL)
return NULL; return NULL;
CHECK_OBJ_NOTNULL(ctx->ws, WS_MAGIC);
if (wb_create(ctx->ws, &wb) == NULL) { if (wb_create(ctx->ws, &wb) == NULL) {
ERRNOMEM(ctx, "cannot encode"); ERRNOMEM(ctx, "cannot encode");
return NULL; return NULL;
...@@ -546,10 +539,10 @@ transcode(VRT_CTX, VCL_INT n, VCL_ENUM decs, VCL_ENUM encs, ...@@ -546,10 +539,10 @@ transcode(VRT_CTX, VCL_INT n, VCL_ENUM decs, VCL_ENUM encs,
VCL_STRING r; VCL_STRING r;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (INIT_FINI(ctx)) {
if (! has_ws(ctx, __func__)) ILLEGAL(ctx, "transcode()");
return NULL; return NULL;
}
CHECK_OBJ_NOTNULL(ctx->ws, WS_MAGIC); CHECK_OBJ_NOTNULL(ctx->ws, WS_MAGIC);
AENC(dec); AENC(dec);
......
...@@ -338,11 +338,10 @@ string is an illegal format for the decoding scheme. ...@@ -338,11 +338,10 @@ string is an illegal format for the decoding scheme.
If the ``blob`` object constructor fails, then the VCL program will If the ``blob`` object constructor fails, then the VCL program will
fail to load, and the VCC compiler will emit an error message. fail to load, and the VCC compiler will emit an error message.
For varnish versions before 5.0, the VMOD functions -- ``encode()``, The VMOD functions -- ``encode()``, ``decode()`` and ``transcode()``
``decode()`` and ``transcode()`` -- may not be called in -- may not be called in ``vcl_init()`` or ``vcl_fini()`` (since a
``vcl_init()`` or ``vcl_fini()`` (since a workspace must be workspace must be available). Use in ``vcl_init()`` will also cause
available). Use in ``vcl_init()`` will also cause the VCL program to the VCL program to fail with a VCC compiler error.
fail with a VCC compiler error.
If any of the VMOD's methods or functions fail at runtime, then an If any of the VMOD's methods or functions fail at runtime, then an
error message will be written to the Varnish log using the tag error message will be written to the Varnish log using the tag
......
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