Commit ab76cb9a authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add VGZ_ flags to pass to Gzip function to insulate from zlib

parent 5ef82382
......@@ -626,12 +626,13 @@ void Fetch_Init(void);
/* cache_gzip.c */
struct vgz;
enum vgz_flag { VGZ_NORMAL, VGZ_ALIGN, VGZ_RESET, VGZ_FINISH };
struct vgz *VGZ_NewUngzip(const struct sess *sp, struct ws *tmp);
struct vgz *VGZ_NewGzip(const struct sess *sp, struct ws *tmp);
void VGZ_Ibuf(struct vgz *, const void *, ssize_t len);
int VGZ_IbufEmpty(struct vgz *vg);
void VGZ_Obuf(struct vgz *, const void *, ssize_t len);
int VGZ_Gzip(struct vgz *, const void **, size_t *len, int flag);
int VGZ_Gzip(struct vgz *, const void **, size_t *len, enum vgz_flag);
int VGZ_Gunzip(struct vgz *, const void **, size_t *len);
void VGZ_Destroy(struct vgz **);
......
......@@ -38,9 +38,8 @@
#define VEC_S8 (0x60 + 8)
#define VEC_INCL 'I'
enum vep_flg { VEP_NORMAL, VEP_ALIGN, VEP_RESET, VEP_FINISH };
typedef ssize_t vep_callback_t(const struct sess *sp,
ssize_t l, enum vep_flg flg);
ssize_t l, enum vgz_flag flg);
void VEP_Init(const struct sess *sp, vep_callback_t *cb);
void VEP_parse(const struct sess *sp, const char *p, size_t l);
......
......@@ -329,7 +329,7 @@ vep_mark_common(struct vep_state *vep, const char *p, enum vep_mark mark)
if (vep->last_mark != mark && vep->o_wait > 0) {
lcb = vep->cb(vep->sp, 0,
mark == VERBATIM ? VEP_RESET : VEP_ALIGN);
mark == VERBATIM ? VGZ_RESET : VGZ_ALIGN);
vep_emit_common(vep, lcb - vep->o_last, vep->last_mark);
vep->o_last = lcb;
vep->o_wait = 0;
......@@ -337,7 +337,7 @@ vep_mark_common(struct vep_state *vep, const char *p, enum vep_mark mark)
/* Transfer pending bytes CRC into active mode CRC */
if (vep->o_pending) {
(void)vep->cb(vep->sp, vep->o_pending, VEP_NORMAL);
(void)vep->cb(vep->sp, vep->o_pending, VGZ_NORMAL);
if (vep->o_crc == 0) {
vep->crc = vep->crcp;
vep->o_crc = vep->o_pending;
......@@ -361,7 +361,7 @@ vep_mark_common(struct vep_state *vep, const char *p, enum vep_mark mark)
vep->o_wait += l;
vep->last_mark = mark;
(void)vep->cb(vep->sp, l, VEP_NORMAL);
(void)vep->cb(vep->sp, l, VGZ_NORMAL);
}
static void
......@@ -966,7 +966,7 @@ VEP_parse(const struct sess *sp, const char *p, size_t l)
*/
static ssize_t
vep_default_cb(const struct sess *sp, ssize_t l, enum vep_flg flg)
vep_default_cb(const struct sess *sp, ssize_t l, enum vgz_flag flg)
{
(void)flg;
......@@ -1020,7 +1020,7 @@ VEP_Finish(const struct sess *sp)
if (vep->o_pending)
vep_mark_common(vep, vep->ver_p, vep->last_mark);
if (vep->o_wait > 0) {
lcb = vep->cb(vep->sp, 0, VEP_FINISH);
lcb = vep->cb(vep->sp, 0, VGZ_FINISH);
vep_emit_common(vep, lcb - vep->o_last, vep->last_mark);
}
......
......@@ -66,6 +66,7 @@
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include "svnid.h"
SVNID("$Id$")
......@@ -251,9 +252,10 @@ VGZ_Gunzip(struct vgz *vg, const void **pptr, size_t *plen)
/*--------------------------------------------------------------------*/
int
VGZ_Gzip(struct vgz *vg, const void **pptr, size_t *plen, int flags)
VGZ_Gzip(struct vgz *vg, const void **pptr, size_t *plen, enum vgz_flag flags)
{
int i;
int zflg;
CHECK_OBJ_NOTNULL(vg, VGZ_MAGIC);
......@@ -262,7 +264,14 @@ VGZ_Gzip(struct vgz *vg, const void **pptr, size_t *plen, int flags)
AN(vg->vz.next_out);
AN(vg->vz.avail_out);
vg->before = vg->vz.next_out;
i = deflate(&vg->vz, flags);
switch(flags) {
case VGZ_NORMAL: zflg = Z_NO_FLUSH; break;
case VGZ_ALIGN: zflg = Z_SYNC_FLUSH; break;
case VGZ_RESET: zflg = Z_FULL_FLUSH; break;
case VGZ_FINISH: zflg = Z_FINISH; break;
default: INCOMPL();
}
i = deflate(&vg->vz, zflg);
if (i == Z_OK || i == Z_STREAM_END) {
*pptr = vg->before;
*plen = (const uint8_t *)vg->vz.next_out - (const uint8_t*)vg->before;
......@@ -436,7 +445,8 @@ vfp_gzip_bytes(struct sess *sp, struct http_conn *htc, size_t bytes)
bytes -= w;
}
i = VGZ_Gzip(vg, &dp, &dl, bytes == 0 ? Z_FINISH : 0);
i = VGZ_Gzip(vg, &dp, &dl,
bytes == 0 ? VGZ_FINISH : VGZ_NORMAL);
assert(i == Z_OK || i == Z_STREAM_END);
st->len = st->space - dl;
if (st->len == st->space) {
......
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