int http_compression_buffer_add_data(struct session *s, struct buffer *in, struct buffer *out);
int http_compression_buffer_end(struct session *s, struct buffer **in, struct buffer **out, int end);
-int identity_init(void *v, int level);
-int identity_add_data(void *v, const char *in_data, int in_len, char *out_data, int out_len);
-int identity_flush(void *comp_ctx, struct buffer *out, int flag);
-int identity_reset(void *comp_ctx);
-int identity_end(void *comp_ctx);
+int identity_init(struct comp_ctx *comp_ctx, int level);
+int identity_add_data(struct comp_ctx *comp_ctx, const char *in_data, int in_len, char *out_data, int out_len);
+int identity_flush(struct comp_ctx *comp_ctx, struct buffer *out, int flag);
+int identity_reset(struct comp_ctx *comp_ctx);
+int identity_end(struct comp_ctx *comp_ctx);
#ifdef USE_ZLIB
-int deflate_init(void *comp_ctx, int level);
-int deflate_add_data(void *v, const char *in_data, int in_len, char *out_data, int out_len);
-int deflate_flush(void *comp_ctx, struct buffer *out, int flag);
-int deflate_reset(void *comp_ctx);
-int deflate_end(void *comp_ctx);
+int deflate_init(struct comp_ctx *comp_ctx, int level);
+int deflate_add_data(struct comp_ctx *comp_ctx, const char *in_data, int in_len, char *out_data, int out_len);
+int deflate_flush(struct comp_ctx *comp_ctx, struct buffer *out, int flag);
+int deflate_reset(struct comp_ctx *comp_ctx);
+int deflate_end(struct comp_ctx *comp_ctx);
-int gzip_init(void *comp_ctx, int level);
-int gzip_add_data(void *v, const char *in_data, int in_len, char *out_data, int out_len);
-int gzip_flush(void *comp_ctx, struct buffer *out, int flag);
-int gzip_reset(void *comp_ctx);
-int gzip_end(void *comp_ctx);
+int gzip_init(struct comp_ctx *comp_ctx, int level);
+int gzip_add_data(struct comp_ctx *comp_ctx, const char *in_data, int in_len, char *out_data, int out_len);
+int gzip_flush(struct comp_ctx *comp_ctx, struct buffer *out, int flag);
+int gzip_reset(struct comp_ctx *comp_ctx);
+int gzip_end(struct comp_ctx *comp_ctx);
#endif /* USE_ZLIB */
unsigned int offload;
};
+struct comp_ctx {
+ z_stream strm; /* zlib stream */
+};
+
struct comp_algo {
char *name;
int name_len;
- int (*init)(void *, int);
- int (*add_data)(void *v, const char *in_data, int in_len, char *out_data, int out_len);
- int (*flush)(void *v, struct buffer *out, int flag);
- int (*reset)(void *v);
- int (*end)(void *v);
+ int (*init)(struct comp_ctx *comp_ctx, int);
+ int (*add_data)(struct comp_ctx *comp_ctx, const char *in_data, int in_len, char *out_data, int out_len);
+ int (*flush)(struct comp_ctx *comp_ctx, struct buffer *out, int flag);
+ int (*reset)(struct comp_ctx *comp_ctx);
+ int (*end)(struct comp_ctx *comp_ctx);
struct comp_algo *next;
};
-union comp_ctx {
- z_stream strm; /* zlib */
-};
-
struct comp_type {
char *name;
int name_len;
left = data_process_len - bi_contig_data(in);
if (left <= 0) {
- ret = s->comp_algo->add_data(&s->comp_ctx.strm, bi_ptr(in),
+ ret = s->comp_algo->add_data(&s->comp_ctx, bi_ptr(in),
data_process_len, bi_end(out),
out->size - buffer_len(out));
if (ret < 0)
out->i += ret;
} else {
- ret = s->comp_algo->add_data(&s->comp_ctx.strm, bi_ptr(in), bi_contig_data(in), bi_end(out), out->size - buffer_len(out));
+ ret = s->comp_algo->add_data(&s->comp_ctx, bi_ptr(in), bi_contig_data(in), bi_end(out), out->size - buffer_len(out));
if (ret < 0)
return -1;
out->i += ret;
- ret = s->comp_algo->add_data(&s->comp_ctx.strm, in->data, left, bi_end(out), out->size - buffer_len(out));
+ ret = s->comp_algo->add_data(&s->comp_ctx, in->data, left, bi_end(out), out->size - buffer_len(out));
if (ret < 0)
return -1;
out->i += ret;
/*
* Init the identity algorithm
*/
-int identity_init(void *v, int level)
+int identity_init(struct comp_ctx *comp_ctx, int level)
{
return 0;
}
* Process data
* Return size of processed data or -1 on error
*/
-int identity_add_data(void *comp_ctx, const char *in_data, int in_len, char *out_data, int out_len)
+int identity_add_data(struct comp_ctx *comp_ctx, const char *in_data, int in_len, char *out_data, int out_len)
{
if (out_len < in_len)
return -1;
return in_len;
}
-int identity_flush(void *comp_ctx, struct buffer *out, int flag)
+int identity_flush(struct comp_ctx *comp_ctx, struct buffer *out, int flag)
{
return 0;
}
-int identity_reset(void *comp_ctx)
+int identity_reset(struct comp_ctx *comp_ctx)
{
return 0;
}
/*
* Deinit the algorithm
*/
-int identity_end(void *comp_ctx)
+int identity_end(struct comp_ctx *comp_ctx)
{
return 0;
}
/**************************
**** gzip algorithm ****
***************************/
-int gzip_init(void *v, int level)
+int gzip_init(struct comp_ctx *comp_ctx, int level)
{
- z_stream *strm;
-
- strm = v;
+ z_stream *strm = &comp_ctx->strm;
strm->zalloc = Z_NULL;
strm->zfree = Z_NULL;
strm->opaque = Z_NULL;
- if (deflateInit2(strm, level, Z_DEFLATED, MAX_WBITS + 16, 8, Z_DEFAULT_STRATEGY) != Z_OK)
+ if (deflateInit2(&comp_ctx->strm, level, Z_DEFLATED, MAX_WBITS + 16, 8, Z_DEFAULT_STRATEGY) != Z_OK)
return -1;
return 0;
**** Deflate algorithm ****
***************************/
-int deflate_init(void *comp_ctx, int level)
+int deflate_init(struct comp_ctx *comp_ctx, int level)
{
- z_stream *strm;
-
- strm = comp_ctx;
+ z_stream *strm = &comp_ctx->strm;
strm->zalloc = Z_NULL;
strm->zfree = Z_NULL;
strm->opaque = Z_NULL;
- if (deflateInit(strm, level) != Z_OK)
+ if (deflateInit(&comp_ctx->strm, level) != Z_OK)
return -1;
return 0;
}
-int deflate_add_data(void *comp_ctx, const char *in_data, int in_len, char *out_data, int out_len)
+int deflate_add_data(struct comp_ctx *comp_ctx, const char *in_data, int in_len, char *out_data, int out_len)
{
- z_stream *strm;
+ z_stream *strm = &comp_ctx->strm;
int ret;
if (in_len <= 0)
if (out_len <= 0)
return -1;
- strm = comp_ctx;
-
strm->next_in = (unsigned char *)in_data;
strm->avail_in = in_len;
strm->next_out = (unsigned char *)out_data;
return out_len - strm->avail_out;
}
-int deflate_flush(void *comp_ctx, struct buffer *out, int flag)
+int deflate_flush(struct comp_ctx *comp_ctx, struct buffer *out, int flag)
{
int ret;
- z_stream *strm;
int out_len = 0;
+ z_stream *strm = &comp_ctx->strm;
- strm = comp_ctx;
strm->next_out = (unsigned char *)bi_end(out);
strm->avail_out = out->size - buffer_len(out);
return out_len;
}
-int deflate_reset(void *comp_ctx)
+int deflate_reset(struct comp_ctx *comp_ctx)
{
- z_stream *strm;
+ z_stream *strm = &comp_ctx->strm;
- strm = comp_ctx;
if (deflateReset(strm) == Z_OK)
return 0;
return -1;
}
-int deflate_end(void *comp_ctx)
+int deflate_end(struct comp_ctx *comp_ctx)
{
- z_stream *strm;
+ z_stream *strm = &comp_ctx->strm;
- strm = comp_ctx;
if (deflateEnd(strm) == Z_OK)
return 0;