Refactor vmod_digest_update()

Remove duplicate call to update() using a local variable for the hash ctx.

This also adds a check for finalization from vcl_init/vcl_fini
parent 9802ffbb
...@@ -425,6 +425,7 @@ VCL_BOOL ...@@ -425,6 +425,7 @@ VCL_BOOL
vmod_digest_update(VRT_CTX, struct vmod_blobdigest_digest *h, VCL_BLOB b) vmod_digest_update(VRT_CTX, struct vmod_blobdigest_digest *h, VCL_BLOB b)
{ {
struct digest_task *task; struct digest_task *task;
hash_ctx *hctx;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(h, VMOD_BLOBDIGEST_DIGEST_MAGIC); CHECK_OBJ_NOTNULL(h, VMOD_BLOBDIGEST_DIGEST_MAGIC);
...@@ -443,18 +444,14 @@ vmod_digest_update(VRT_CTX, struct vmod_blobdigest_digest *h, VCL_BLOB b) ...@@ -443,18 +444,14 @@ vmod_digest_update(VRT_CTX, struct vmod_blobdigest_digest *h, VCL_BLOB b)
return (0); return (0);
} }
if (INIT_FINI(ctx)) { hctx = INIT_FINI(ctx) ? &h->ctx : &task->ctx;
if (b->len > 0 && b->blob != NULL)
update(h->hash, &h->ctx, b->blob, b->len);
return (1);
}
if (task->result != NULL) { if (task->result != NULL) {
VERR(ctx, "already finalized in %s.update()", h->vcl_name); VERR(ctx, "already finalized in %s.update()", h->vcl_name);
return (0); return (0);
} }
if (b->len > 0 && b->blob != NULL) if (b->len > 0 && b->blob != NULL)
update(h->hash, &task->ctx, b->blob, b->len); update(h->hash, hctx, b->blob, b->len);
return (1); return (1);
} }
......
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