CLEANUP: use struct comp_ctx instead of union
Replace union comp_ctx by struct comp_ctx.
Use struct comp_ctx * in the init/add_data/flush/reset/end prototypes of
compression.h functions.
diff --git a/src/compression.c b/src/compression.c
index 3ff3aea..2c0e4f9 100644
--- a/src/compression.c
+++ b/src/compression.c
@@ -166,7 +166,7 @@
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)
@@ -174,11 +174,11 @@
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;
@@ -271,7 +271,7 @@
/*
* Init the identity algorithm
*/
-int identity_init(void *v, int level)
+int identity_init(struct comp_ctx *comp_ctx, int level)
{
return 0;
}
@@ -280,7 +280,7 @@
* 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;
@@ -290,13 +290,13 @@
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;
}
@@ -304,7 +304,7 @@
/*
* Deinit the algorithm
*/
-int identity_end(void *comp_ctx)
+int identity_end(struct comp_ctx *comp_ctx)
{
return 0;
}
@@ -315,17 +315,15 @@
/**************************
**** 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;
@@ -334,25 +332,23 @@
**** 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)
@@ -362,8 +358,6 @@
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;
@@ -378,13 +372,12 @@
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);
@@ -398,21 +391,19 @@
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;
diff --git a/src/proto_http.c b/src/proto_http.c
index cb24eb0..7f2c806 100644
--- a/src/proto_http.c
+++ b/src/proto_http.c
@@ -2111,14 +2111,14 @@
}
/* initialize compression */
- if (s->comp_algo->init(&s->comp_ctx.strm, 1) < 0)
+ if (s->comp_algo->init(&s->comp_ctx, 1) < 0)
goto fail;
return 1;
fail:
if (s->comp_algo) {
- s->comp_algo->end(&s->comp_ctx.strm);
+ s->comp_algo->end(&s->comp_ctx);
s->comp_algo = NULL;
}
return 0;
diff --git a/src/session.c b/src/session.c
index 9d72703..55f976b 100644
--- a/src/session.c
+++ b/src/session.c
@@ -565,7 +565,7 @@
}
if (s->comp_algo) {
- s->comp_algo->end(&s->comp_ctx.strm);
+ s->comp_algo->end(&s->comp_ctx);
s->comp_algo = NULL;
}