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