static int vfp_esi_bytes_gu(struct worker *wrk, struct http_conn *htc, ssize_t bytes) { struct vgz *vg; ssize_t wl; uint8_t ibuf[cache_param->gzip_stack_buffer]; int i; size_t dl; const void *dp; CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC); vg = wrk->busyobj->vgz_rx; while (bytes > 0) { if (VGZ_IbufEmpty(vg) && bytes > 0) { wl = vef_read(wrk, htc, ibuf, sizeof ibuf, bytes); if (wl <= 0) return (wl); VGZ_Ibuf(vg, ibuf, wl); bytes -= wl; } if (VGZ_ObufStorage(wrk, vg)) return(-1); i = VGZ_Gunzip(vg, &dp, &dl); xxxassert(i == VGZ_OK || i == VGZ_END); VEP_Parse(wrk, dp, dl); wrk->busyobj->fetch_obj->len += dl; } return (1); }
static int vfp_esi_bytes_gu(struct busyobj *bo, const struct vef_priv *vef, struct http_conn *htc, ssize_t bytes) { struct vgz *vg; ssize_t wl; enum vgzret_e vr; size_t dl; const void *dp; CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC); CHECK_OBJ_NOTNULL(vef, VEF_MAGIC); vg = bo->vgz_rx; while (bytes > 0) { if (VGZ_IbufEmpty(vg) && bytes > 0) { wl = vef_read(htc, vef->ibuf, vef->ibuf_sz, bytes); if (wl <= 0) return (wl); VGZ_Ibuf(vg, vef->ibuf, wl); bytes -= wl; } if (VGZ_ObufStorage(bo, vg)) return(-1); vr = VGZ_Gunzip(vg, &dp, &dl); if (vr < VGZ_OK) return (-1); if (dl > 0) { VEP_Parse(bo, dp, dl); VBO_extend(bo, dl); } } return (1); }
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); }
vfp_gunzip_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 || vg->vz.avail_in > 0) { if (vg->vz.avail_in == 0 && 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_Gunzip(vg, &dp, &dl); if (i != VGZ_OK && i != VGZ_END) return(FetchError(bo, "Gunzip data error")); bo->fetch_obj->len += dl; } assert(i == Z_OK || i == Z_STREAM_END); return (1); }
vfp_esi_bytes_gu(struct sess *sp, struct http_conn *htc, ssize_t bytes) { struct vgz *vg; ssize_t w; uint8_t ibuf[params->gzip_stack_buffer]; int i; size_t dl; const void *dp; CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); vg = sp->wrk->vgz_rx; while (bytes > 0) { if (VGZ_IbufEmpty(vg) && bytes > 0) { w = vef_read(htc, ibuf, sizeof ibuf, bytes); if (w <= 0) return (w); VGZ_Ibuf(vg, ibuf, w); bytes -= w; } if (VGZ_ObufStorage(sp, vg)) return (-1); i = VGZ_Gunzip(vg, &dp, &dl); xxxassert(i == VGZ_OK || i == VGZ_END); VEP_parse(sp, dp, dl); sp->obj->len += dl; } return (1); }
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 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); }