Commit 6eb3f1eb authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Update the magic gzip bit positions whenever we spot them changing.

parent 3bd29b4d
......@@ -822,7 +822,14 @@ enum vgzret_e VGZ_Gzip(struct vgz *, const void **, ssize_t *len,
enum vgz_flag);
// enum vgzret_e VGZ_Gunzip(struct vgz *, const void **, ssize_t *len);
enum vgzret_e VGZ_Destroy(struct vgz **);
void VGZ_UpdateObj(const struct vfp_ctx *, const struct vgz*, int input);
enum vgz_ua_e {
VUA_UPDATE, // Update start/stop/last bits if changed
VUA_END_GZIP, // Record uncompressed size
VUA_END_GUNZIP, // Record uncompressed size
};
void VGZ_UpdateObj(const struct vfp_ctx *, struct vgz*, enum vgz_ua_e);
/* cache_http.c */
unsigned HTTP_estimate(unsigned nhttp);
......
......@@ -94,6 +94,7 @@ vfp_vep_callback(struct vfp_ctx *vc, void *priv, ssize_t l, enum vgz_flag flg)
}
VGZ_Obuf(vef->vgz, ptr, dl);
i = VGZ_Gzip(vef->vgz, &dp, &dl, flg);
VGZ_UpdateObj(vc, vef->vgz, VUA_UPDATE);
vef->tot += dl;
VBO_extend(vc->bo, dl);
} while (i != VGZ_ERROR &&
......@@ -131,7 +132,7 @@ vfp_esi_end(struct vfp_ctx *vc, struct vef_priv *vef,
}
if (vef->vgz != NULL) {
VGZ_UpdateObj(vc, vef->vgz, 1);
VGZ_UpdateObj(vc, vef->vgz, VUA_END_GZIP);
if (VGZ_Destroy(&vef->vgz) != VGZ_END)
retval = VFP_Error(vc,
"ESI+Gzip Failed at the very end");
......
......@@ -59,6 +59,8 @@ struct vgz {
ssize_t m_sz;
ssize_t m_len;
intmax_t bits;
z_stream vz;
};
......@@ -348,19 +350,24 @@ VDP_gunzip(struct req *req, enum vdp_action act, void **priv,
/*--------------------------------------------------------------------*/
void
VGZ_UpdateObj(const struct vfp_ctx *vc, const struct vgz *vg, int input)
VGZ_UpdateObj(const struct vfp_ctx *vc, struct vgz *vg, enum vgz_ua_e e)
{
char *p;
intmax_t ii;
CHECK_OBJ_NOTNULL(vg, VGZ_MAGIC);
ii = vg->vz.start_bit + vg->vz.last_bit + vg->vz.stop_bit;
if (e == VUA_UPDATE && ii == vg->bits)
return;
vg->bits = ii;
p = ObjSetattr(vc->wrk, vc->oc, OA_GZIPBITS, 32, NULL);
AN(p);
vbe64enc(p, vg->vz.start_bit);
vbe64enc(p + 8, vg->vz.last_bit);
vbe64enc(p + 16, vg->vz.stop_bit);
if (input)
if (e == VUA_END_GZIP)
vbe64enc(p + 24, vg->vz.total_in);
else
if (e == VUA_END_GUNZIP)
vbe64enc(p + 24, vg->vz.total_out);
}
......@@ -553,6 +560,7 @@ vfp_gzip_pull(struct vfp_ctx *vc, struct vfp_entry *vfe, void *p,
if (vr < VGZ_OK)
return (VFP_Error(vc, "Gzip failed"));
if (dl > 0) {
VGZ_UpdateObj(vc, vg, VUA_UPDATE);
*lp = dl;
assert(dp == p);
return (VFP_OK);
......@@ -563,7 +571,7 @@ vfp_gzip_pull(struct vfp_ctx *vc, struct vfp_entry *vfe, void *p,
if (vr != VGZ_END)
return (VFP_Error(vc, "Gzip failed"));
VGZ_UpdateObj(vc, vg, 1);
VGZ_UpdateObj(vc, vg, VUA_END_GZIP);
return (VFP_END);
}
......@@ -605,10 +613,11 @@ vfp_testgunzip_pull(struct vfp_ctx *vc, struct vfp_entry *vfe, void *p,
"Invalid Gzip data: %s", vg->vz.msg));
} while (!VGZ_IbufEmpty(vg));
}
VGZ_UpdateObj(vc, vg, VUA_UPDATE);
if (vp == VFP_END) {
if (vr != VGZ_END)
return (VFP_Error(vc, "tGunzip failed"));
VGZ_UpdateObj(vc, vg, 0);
VGZ_UpdateObj(vc, vg, VUA_END_GUNZIP);
}
return (vp);
}
......
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