Ejemplo n.º 1
0
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);
}
Ejemplo n.º 2
0
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);
}
Ejemplo n.º 3
0
static int
vfp_esi_bytes_ug(struct worker *wrk, struct http_conn *htc, ssize_t bytes)
{
	ssize_t wl;
	char ibuf[cache_param->gzip_stack_buffer];
	struct vef_priv *vef;

	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
	CHECK_OBJ_NOTNULL(wrk->busyobj, BUSYOBJ_MAGIC);
	vef = wrk->busyobj->vef_priv;
	CHECK_OBJ_NOTNULL(vef, VEF_MAGIC);

	while (bytes > 0) {
		wl = vef_read(wrk, htc, ibuf, sizeof ibuf, bytes);
		if (wl <= 0)
			return (wl);
		bytes -= wl;
		vef->bufp = ibuf;
		VEP_Parse(wrk, ibuf, wl);
		assert(vef->bufp >= ibuf && vef->bufp <= ibuf + wl);
		if (vef->error) {
			errno = vef->error;
			return (-1);
		}
		if (vef->bufp < ibuf + wl) {
			wl = (ibuf + wl) - vef->bufp;
			assert(wl + vef->npend < sizeof vef->pending);
			memmove(vef->pending + vef->npend, vef->bufp, wl);
			vef->npend += wl;
		}
	}
	return (1);
}
Ejemplo n.º 4
0
vfp_esi_pull(struct vfp_ctx *vc, struct vfp_entry *vfe, void *p, ssize_t *lp)
{
	enum vfp_status vp;
	ssize_t d;
	struct vef_priv *vef;

	CHECK_OBJ_NOTNULL(vc, VFP_CTX_MAGIC);
	CHECK_OBJ_NOTNULL(vfe, VFP_ENTRY_MAGIC);
	CAST_OBJ_NOTNULL(vef, vfe->priv1, VEF_MAGIC);
	AN(p);
	AN(lp);
	if (DO_DEBUG(DBG_ESI_CHOP)) {
		d = (random() & 3) + 1;
		if (d < *lp)
			*lp = d;
	}
	vp = VFP_Suck(vc, p, lp);
	if (vp != VFP_ERROR && *lp > 0)
		VEP_Parse(vef->vep, p, *lp);
	if (vp == VFP_END) {
		vp = vfp_esi_end(vc, vef, vp);
		vfe->priv1 = NULL;
	}
	return (vp);
}
Ejemplo n.º 5
0
static int
vfp_esi_bytes_gg(struct worker *wrk, struct http_conn *htc, size_t bytes)
{
	ssize_t wl;
	char ibuf[cache_param->gzip_stack_buffer];
	char ibuf2[cache_param->gzip_stack_buffer];
	struct vef_priv *vef;
	size_t dl;
	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(sizeof ibuf >= 1024);
	ibuf2[0] = 0; /* For Flexelint */

	while (bytes > 0) {
		wl = vef_read(wrk, htc, ibuf, sizeof ibuf, bytes);
		if (wl <= 0)
			return (wl);
		bytes -= wl;

		vef->bufp = ibuf;
		VGZ_Ibuf(wrk->busyobj->vgz_rx, ibuf, wl);
		do {
			VGZ_Obuf(wrk->busyobj->vgz_rx, ibuf2, sizeof ibuf2);
			i = VGZ_Gunzip(wrk->busyobj->vgz_rx, &dp, &dl);
			/* XXX: check i */
			assert(i >= VGZ_OK);
			vef->bufp = ibuf2;
			if (dl > 0)
				VEP_Parse(wrk, ibuf2, dl);
			if (vef->error) {
				errno = vef->error;
				return (-1);
			}
			if (vef->bufp < ibuf2 + dl) {
				dl = (ibuf2 + dl) - vef->bufp;
				assert(dl + vef->npend < sizeof vef->pending);
				memmove(vef->pending + vef->npend,
				    vef->bufp, dl);
				vef->npend += dl;
			}
		} while (!VGZ_IbufEmpty(wrk->busyobj->vgz_rx));
	}
	return (1);
}
Ejemplo n.º 6
0
vfp_esi_gzip_pull(struct vfp_ctx *vc, struct vfp_entry *vfe, void *p,
   ssize_t *lp)
{
	enum vfp_status vp;
	ssize_t d, l;
	struct vef_priv *vef;

	CHECK_OBJ_NOTNULL(vc, VFP_CTX_MAGIC);
	CHECK_OBJ_NOTNULL(vfe, VFP_ENTRY_MAGIC);
	CAST_OBJ_NOTNULL(vef, vfe->priv1, VEF_MAGIC);
	AN(p);
	AN(lp);
	*lp = 0;
	l = vef->ibuf_sz - (vef->ibuf_i - vef->ibuf);
	if (DO_DEBUG(DBG_ESI_CHOP)) {
		d = (random() & 3) + 1;
		if (d < l)
			l = d;
	}
	vp = VFP_Suck(vc, vef->ibuf_i, &l);

	if (l > 0) {
		VEP_Parse(vef->vep, vef->ibuf_i, l);
		vef->ibuf_i += l;
		assert(vef->ibuf_o >= vef->ibuf && vef->ibuf_o <= vef->ibuf_i);
		if (vef->error) {
			errno = vef->error;
			return (VFP_ERROR);
		}
		l = vef->ibuf_i - vef->ibuf_o;
		if (l > 0)
			memmove(vef->ibuf, vef->ibuf_o, l);
		vef->ibuf_o = vef->ibuf;
		vef->ibuf_i = vef->ibuf + l;
	}
	if (vp == VFP_END) {
		vp = vfp_esi_end(vc, vef, vp);
		vfe->priv1 = NULL;
	}
	return (vp);
}
Ejemplo n.º 7
0
static int
vfp_vep_inject(const struct busyobj *bo, struct vef_priv *vef, ssize_t wl)
{

	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
	CHECK_OBJ_NOTNULL(vef, VEF_MAGIC);

	VEP_Parse(bo, vef->ibuf_i, wl);
	vef->ibuf_i += wl;
	assert(vef->ibuf_o >= vef->ibuf && vef->ibuf_o <= vef->ibuf_i);
	if (vef->error) {
		errno = vef->error;
		return (-1);
	}
	wl = vef->ibuf_i - vef->ibuf_o;
	if (wl > 0)
		memmove(vef->ibuf, vef->ibuf_o, wl);
	vef->ibuf_o = vef->ibuf;
	vef->ibuf_i = vef->ibuf + wl;
	return (0);
}
Ejemplo n.º 8
0
static int
vfp_esi_bytes_uu(struct worker *wrk, struct http_conn *htc, ssize_t bytes)
{
	ssize_t wl;
	struct storage *st;

	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);

	while (bytes > 0) {
		st = FetchStorage(wrk, 0);
		if (st == NULL)
			return (-1);
		wl = vef_read(wrk, htc,
		    st->ptr + st->len, st->space - st->len, bytes);
		if (wl <= 0)
			return (wl);
		VEP_Parse(wrk, (const char *)st->ptr + st->len, wl);
		st->len += wl;
		wrk->busyobj->fetch_obj->len += wl;
		bytes -= wl;
	}
	return (1);
}
Ejemplo n.º 9
0
static int
vfp_esi_bytes_uu(struct busyobj *bo, const struct vef_priv *vef,
    struct http_conn *htc, ssize_t bytes)
{
	ssize_t wl;
	struct storage *st;

	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
	CHECK_OBJ_NOTNULL(vef, VEF_MAGIC);

	while (bytes > 0) {
		st = VFP_GetStorage(bo, 0);
		if (st == NULL)
			return (-1);
		wl = vef_read(htc,
		    st->ptr + st->len, st->space - st->len, bytes);
		if (wl <= 0)
			return (wl);
		VEP_Parse(bo, (const char *)st->ptr + st->len, wl);
		VBO_extend(bo, wl);
		bytes -= wl;
	}
	return (1);
}