Commit 29156901 authored by Geoff Simmons's avatar Geoff Simmons

consolidate the encode step of transcode

Patch by Nils Goroll
parent 8e1e5501
......@@ -522,9 +522,9 @@ transcode(VRT_CTX, VCL_INT n, VCL_ENUM decs, VCL_ENUM encs,
const char *restrict const p, va_list ap) {
enum encoding dec = parse_encoding(decs);
enum encoding enc = parse_encoding(encs);
struct wb_s wb;
ssize_t len;
va_list aq;
struct vmod_priv b;
VCL_STRING r;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (INIT_FINI(ctx)) {
......@@ -537,12 +537,11 @@ transcode(VRT_CTX, VCL_INT n, VCL_ENUM decs, VCL_ENUM encs,
AENC(enc);
if (dec == IDENTITY) {
struct vmod_priv b;
va_copy(aq, ap);
const struct vmod_priv *bb = decode_id_inplace(&b, n, p, aq);
va_end(aq);
if (bb != NULL) {
VCL_STRING r = encode(ctx, enc, bb);
r = encode(ctx, enc, bb);
return (r);
}
}
......@@ -558,13 +557,15 @@ transcode(VRT_CTX, VCL_INT n, VCL_ENUM decs, VCL_ENUM encs,
return "";
/* XXX: handle stack overflow? */
char buf[l];
b.free = NULL;
b.priv = buf;
errno = 0;
va_copy(aq, ap);
len = func[dec].decode(dec, buf, l, n, p, aq);
b.len = func[dec].decode(dec, buf, l, n, p, aq);
va_end(aq);
if (len == -1) {
if (b.len == -1) {
err_decode(ctx, p);
return NULL;
}
......@@ -574,28 +575,12 @@ transcode(VRT_CTX, VCL_INT n, VCL_ENUM decs, VCL_ENUM encs,
* legal, just return the concatenated string.
*/
if (n == -1 && enc == dec) {
VCL_STRING s;
s = VRT_String(ctx->ws, NULL, p, ap);
return s;
}
if (wb_create(ctx->ws, &wb) == NULL) {
ERRNOMEM(ctx, "cannot encode after decode");
return NULL;
r = VRT_String(ctx->ws, NULL, p, ap);
return r;
}
len = func[enc].encode(enc, wb_buf(&wb), wb_space(&wb), buf, len);
if (len == -1) {
ERRNOMEM(ctx, "cannot encode after decode");
wb_reset(&wb);
return NULL;
}
if (len == 0) {
wb_reset(&wb);
return "";
}
wb_advance(&wb, len);
return wb_finish(&wb, NULL);
r = encode(ctx, enc, &b);
return (r);
}
VCL_STRING __match_proto__(td_blobcode_transcode)
......
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