vfp_gzip_end(struct busyobj *bo) { struct vgz *vg; size_t dl; const void *dp; int i; CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); vg = bo->vgz_rx; CHECK_OBJ_NOTNULL(vg, VGZ_MAGIC); bo->vgz_rx = NULL; if (bo->state == BOS_FAILED) { (void)VGZ_Destroy(&vg); return(0); } do { VGZ_Ibuf(vg, "", 0); if (VGZ_ObufStorage(bo, vg)) return(-1); i = VGZ_Gzip(vg, &dp, &dl, VGZ_FINISH); VBO_extend(bo, dl); } while (i != Z_STREAM_END); VGZ_UpdateObj(vg, bo->fetch_obj); if (VGZ_Destroy(&vg) != VGZ_END) return(VFP_Error(bo, "Gzip error at the very end")); return (0); }
vfp_gzip_bytes(struct busyobj *bo, struct http_conn *htc, ssize_t bytes) { struct vgz *vg; ssize_t l, wl; int i = -100; size_t dl; const void *dp; CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); vg = bo->vgz_rx; CHECK_OBJ_NOTNULL(vg, VGZ_MAGIC); AZ(vg->vz.avail_in); while (bytes > 0 || !VGZ_IbufEmpty(vg)) { if (VGZ_IbufEmpty(vg) && bytes > 0) { l = vg->m_sz; if (l > bytes) l = bytes; wl = htc->read(htc, vg->m_buf, l); if (wl <= 0) return (wl); VGZ_Ibuf(vg, vg->m_buf, wl); bytes -= wl; } if (VGZ_ObufStorage(bo, vg)) return(-1); i = VGZ_Gzip(vg, &dp, &dl, VGZ_NORMAL); assert(i == Z_OK); VBO_extend(bo, dl); } return (1); }
static ssize_t vfp_vep_callback(struct vfp_ctx *vc, void *priv, ssize_t l, enum vgz_flag flg) { struct vef_priv *vef; ssize_t dl; const void *dp; uint8_t *ptr; int i; CHECK_OBJ_NOTNULL(vc, VFP_CTX_MAGIC); CAST_OBJ_NOTNULL(vef, priv, VEF_MAGIC); assert(l >= 0); if (vef->error) { vef->tot += l; return (vef->tot); } /* * l == 0 is valid when 'flg' calls for action, but in the * normal case we can just ignore a l==0 request. * (It would cause Z_BUF_ERROR anyway) */ if (l == 0 && flg == VGZ_NORMAL) return (vef->tot); CHECK_OBJ_NOTNULL(vc->bo, BUSYOBJ_MAGIC); VGZ_Ibuf(vef->vgz, vef->ibuf_o, l); do { dl = 0; if (VFP_GetStorage(vc, &dl, &ptr) != VFP_OK) { vef->error = ENOMEM; vef->tot += l; return (vef->tot); } VGZ_Obuf(vef->vgz, ptr, dl); i = VGZ_Gzip(vef->vgz, &dp, &dl, flg); VGZ_UpdateObj(vc, vef->vgz, VUA_UPDATE); if (dl > 0) { vef->tot += dl; VFP_Extend(vc, dl); } } while (i != VGZ_ERROR && (!VGZ_IbufEmpty(vef->vgz) || VGZ_ObufFull(vef->vgz))); assert(i == VGZ_ERROR || VGZ_IbufEmpty(vef->vgz)); vef->ibuf_o += l; return (vef->tot); }
vfp_gzip_pull(struct vfp_ctx *vc, struct vfp_entry *vfe, void *p, ssize_t *lp) { ssize_t l; struct vgz *vg; enum vgzret_e vr = VGZ_ERROR; const void *dp; ssize_t dl; enum vfp_status vp = VFP_ERROR; CHECK_OBJ_NOTNULL(vc, VFP_CTX_MAGIC); CHECK_OBJ_NOTNULL(vfe, VFP_ENTRY_MAGIC); CAST_OBJ_NOTNULL(vg, vfe->priv1, VGZ_MAGIC); AN(p); AN(lp); l = *lp; *lp = 0; VGZ_Obuf(vg, p, l); do { if (VGZ_IbufEmpty(vg)) { l = vg->m_sz; vp = VFP_Suck(vc, vg->m_buf, &l); if (vp == VFP_ERROR) break; if (vp == VFP_END) vg->flag = VGZ_FINISH; VGZ_Ibuf(vg, vg->m_buf, l); } if (!VGZ_IbufEmpty(vg) || vg->flag == VGZ_FINISH) { vr = VGZ_Gzip(vg, &dp, &dl, vg->flag); 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); } } AN(VGZ_IbufEmpty(vg)); } while (vg->flag != VGZ_FINISH); if (vr != VGZ_END) return (VFP_Error(vc, "Gzip failed")); VGZ_UpdateObj(vc, vg, VUA_END_GZIP); return (VFP_END); }
static ssize_t vfp_vep_callback(struct busyobj *bo, ssize_t l, enum vgz_flag flg) { struct vef_priv *vef; size_t dl; const void *dp; int i; CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); vef = bo->vef_priv; CHECK_OBJ_NOTNULL(vef, VEF_MAGIC); assert(l >= 0); if (vef->error) { vef->tot += l; return (vef->tot); } /* * l == 0 is valid when 'flg' calls for action, but in the * normal case we can just ignore a l==0 request. * (It would cause Z_BUF_ERROR anyway) */ if (l == 0 && flg == VGZ_NORMAL) return (vef->tot); VGZ_Ibuf(vef->vgz, vef->ibuf_o, l); do { if (VGZ_ObufStorage(bo, vef->vgz)) { vef->error = ENOMEM; vef->tot += l; return (vef->tot); } i = VGZ_Gzip(vef->vgz, &dp, &dl, flg); vef->tot += dl; VBO_extend(bo, dl); } while (!VGZ_IbufEmpty(vef->vgz) || (flg != VGZ_NORMAL && VGZ_ObufFull(vef->vgz))); assert(VGZ_IbufEmpty(vef->vgz)); vef->ibuf_o += l; if (flg == VGZ_FINISH) assert(i == 1); /* XXX */ else assert(i == 0); /* XXX */ return (vef->tot); }
static ssize_t vfp_vep_callback(struct busyobj *bo, void *priv, ssize_t l, enum vgz_flag flg) { struct vef_priv *vef; size_t dl; const void *dp; struct storage *st; int i; CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); CAST_OBJ_NOTNULL(vef, priv, VEF_MAGIC); assert(l >= 0); if (vef->error) { vef->tot += l; return (vef->tot); } /* * l == 0 is valid when 'flg' calls for action, but in the * normal case we can just ignore a l==0 request. * (It would cause Z_BUF_ERROR anyway) */ if (l == 0 && flg == VGZ_NORMAL) return (vef->tot); VGZ_Ibuf(vef->vgz, vef->ibuf_o, l); do { st = VFP_GetStorage(bo, 0); if (st == NULL) { vef->error = ENOMEM; vef->tot += l; return (vef->tot); } VGZ_Obuf(vef->vgz, st->ptr + st->len, st->space - st->len); i = VGZ_Gzip(vef->vgz, &dp, &dl, flg); vef->tot += dl; VBO_extend(bo, dl); } while (i != VGZ_ERROR && (!VGZ_IbufEmpty(vef->vgz) || VGZ_ObufFull(vef->vgz))); assert(i == VGZ_ERROR || VGZ_IbufEmpty(vef->vgz)); vef->ibuf_o += l; return (vef->tot); }
static ssize_t vfp_vep_callback(struct worker *wrk, ssize_t l, enum vgz_flag flg) { struct vef_priv *vef; size_t dl, px; const void *dp; int i; CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); CHECK_OBJ_NOTNULL(wrk->busyobj, BUSYOBJ_MAGIC); vef = wrk->busyobj->vef_priv; CHECK_OBJ_NOTNULL(vef, VEF_MAGIC); assert(l >= 0); if (vef->error) { vef->tot += l; return (vef->tot); } /* * l == 0 is valid when 'flg' calls for action, but in the * normal case we can just ignore a l==0 request. * (It would cause Z_BUF_ERROR anyway) */ if (l == 0 && flg == VGZ_NORMAL) return (vef->tot); do { px = vef->npend; if (l < px) px = l; if (px != 0) { VGZ_Ibuf(vef->vgz, vef->pending, px); l -= px; } else { VGZ_Ibuf(vef->vgz, vef->bufp, l); vef->bufp += l; l = 0; } do { if (VGZ_ObufStorage(wrk, vef->vgz)) { vef->error = ENOMEM; vef->tot += l; return (vef->tot); } i = VGZ_Gzip(vef->vgz, &dp, &dl, flg); vef->tot += dl; wrk->busyobj->fetch_obj->len += dl; } while (!VGZ_IbufEmpty(vef->vgz) || (flg != VGZ_NORMAL && VGZ_ObufFull(vef->vgz))); if (px != 0) { memmove(vef->pending, vef->pending + px, vef->npend - px); vef->npend -= px; } } while (l > 0); if (flg == VGZ_FINISH) assert(i == 1); /* XXX */ else assert(i == 0); /* XXX */ return (vef->tot); }