mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-30 10:11:41 +02:00
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.
This commit is contained in:
parent
e715304e83
commit
1c2d622d82
@ -33,26 +33,26 @@ int http_compression_buffer_init(struct session *s, struct buffer *in, struct bu
|
|||||||
int http_compression_buffer_add_data(struct session *s, struct buffer *in, struct buffer *out);
|
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 http_compression_buffer_end(struct session *s, struct buffer **in, struct buffer **out, int end);
|
||||||
|
|
||||||
int identity_init(void *v, int level);
|
int identity_init(struct comp_ctx *comp_ctx, int level);
|
||||||
int identity_add_data(void *v, 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);
|
||||||
int identity_flush(void *comp_ctx, struct buffer *out, int flag);
|
int identity_flush(struct comp_ctx *comp_ctx, struct buffer *out, int flag);
|
||||||
int identity_reset(void *comp_ctx);
|
int identity_reset(struct comp_ctx *comp_ctx);
|
||||||
int identity_end(void *comp_ctx);
|
int identity_end(struct comp_ctx *comp_ctx);
|
||||||
|
|
||||||
|
|
||||||
#ifdef USE_ZLIB
|
#ifdef USE_ZLIB
|
||||||
|
|
||||||
int deflate_init(void *comp_ctx, int level);
|
int deflate_init(struct comp_ctx *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_add_data(struct comp_ctx *comp_ctx, 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_flush(struct comp_ctx *comp_ctx, struct buffer *out, int flag);
|
||||||
int deflate_reset(void *comp_ctx);
|
int deflate_reset(struct comp_ctx *comp_ctx);
|
||||||
int deflate_end(void *comp_ctx);
|
int deflate_end(struct comp_ctx *comp_ctx);
|
||||||
|
|
||||||
int gzip_init(void *comp_ctx, int level);
|
int gzip_init(struct comp_ctx *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_add_data(struct comp_ctx *comp_ctx, 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_flush(struct comp_ctx *comp_ctx, struct buffer *out, int flag);
|
||||||
int gzip_reset(void *comp_ctx);
|
int gzip_reset(struct comp_ctx *comp_ctx);
|
||||||
int gzip_end(void *comp_ctx);
|
int gzip_end(struct comp_ctx *comp_ctx);
|
||||||
|
|
||||||
#endif /* USE_ZLIB */
|
#endif /* USE_ZLIB */
|
||||||
|
|
||||||
|
@ -31,21 +31,21 @@ struct comp {
|
|||||||
unsigned int offload;
|
unsigned int offload;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct comp_ctx {
|
||||||
|
z_stream strm; /* zlib stream */
|
||||||
|
};
|
||||||
|
|
||||||
struct comp_algo {
|
struct comp_algo {
|
||||||
char *name;
|
char *name;
|
||||||
int name_len;
|
int name_len;
|
||||||
int (*init)(void *, int);
|
int (*init)(struct comp_ctx *comp_ctx, int);
|
||||||
int (*add_data)(void *v, const char *in_data, int in_len, char *out_data, int out_len);
|
int (*add_data)(struct comp_ctx *comp_ctx, const char *in_data, int in_len, char *out_data, int out_len);
|
||||||
int (*flush)(void *v, struct buffer *out, int flag);
|
int (*flush)(struct comp_ctx *comp_ctx, struct buffer *out, int flag);
|
||||||
int (*reset)(void *v);
|
int (*reset)(struct comp_ctx *comp_ctx);
|
||||||
int (*end)(void *v);
|
int (*end)(struct comp_ctx *comp_ctx);
|
||||||
struct comp_algo *next;
|
struct comp_algo *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
union comp_ctx {
|
|
||||||
z_stream strm; /* zlib */
|
|
||||||
};
|
|
||||||
|
|
||||||
struct comp_type {
|
struct comp_type {
|
||||||
char *name;
|
char *name;
|
||||||
int name_len;
|
int name_len;
|
||||||
|
@ -156,8 +156,8 @@ struct session {
|
|||||||
void (*srv_error)(struct session *s, /* the function to call upon unrecoverable server errors (or NULL) */
|
void (*srv_error)(struct session *s, /* the function to call upon unrecoverable server errors (or NULL) */
|
||||||
struct stream_interface *si);
|
struct stream_interface *si);
|
||||||
unsigned int uniq_id; /* unique ID used for the traces */
|
unsigned int uniq_id; /* unique ID used for the traces */
|
||||||
|
struct comp_ctx comp_ctx; /* HTTP compression context */
|
||||||
struct comp_algo *comp_algo; /* HTTP compression algorithm if not NULL */
|
struct comp_algo *comp_algo; /* HTTP compression algorithm if not NULL */
|
||||||
union comp_ctx comp_ctx; /* HTTP compression context */
|
|
||||||
char *unique_id; /* custom unique ID */
|
char *unique_id; /* custom unique ID */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@ int http_compression_buffer_add_data(struct session *s, struct buffer *in, struc
|
|||||||
|
|
||||||
left = data_process_len - bi_contig_data(in);
|
left = data_process_len - bi_contig_data(in);
|
||||||
if (left <= 0) {
|
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),
|
data_process_len, bi_end(out),
|
||||||
out->size - buffer_len(out));
|
out->size - buffer_len(out));
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
@ -174,11 +174,11 @@ int http_compression_buffer_add_data(struct session *s, struct buffer *in, struc
|
|||||||
out->i += ret;
|
out->i += ret;
|
||||||
|
|
||||||
} else {
|
} 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)
|
if (ret < 0)
|
||||||
return -1;
|
return -1;
|
||||||
out->i += ret;
|
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)
|
if (ret < 0)
|
||||||
return -1;
|
return -1;
|
||||||
out->i += ret;
|
out->i += ret;
|
||||||
@ -271,7 +271,7 @@ int http_compression_buffer_end(struct session *s, struct buffer **in, struct bu
|
|||||||
/*
|
/*
|
||||||
* Init the identity algorithm
|
* Init the identity algorithm
|
||||||
*/
|
*/
|
||||||
int identity_init(void *v, int level)
|
int identity_init(struct comp_ctx *comp_ctx, int level)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -280,7 +280,7 @@ int identity_init(void *v, int level)
|
|||||||
* Process data
|
* Process data
|
||||||
* Return size of processed data or -1 on error
|
* 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)
|
if (out_len < in_len)
|
||||||
return -1;
|
return -1;
|
||||||
@ -290,13 +290,13 @@ int identity_add_data(void *comp_ctx, const char *in_data, int in_len, char *out
|
|||||||
return in_len;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int identity_reset(void *comp_ctx)
|
int identity_reset(struct comp_ctx *comp_ctx)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -304,7 +304,7 @@ int identity_reset(void *comp_ctx)
|
|||||||
/*
|
/*
|
||||||
* Deinit the algorithm
|
* Deinit the algorithm
|
||||||
*/
|
*/
|
||||||
int identity_end(void *comp_ctx)
|
int identity_end(struct comp_ctx *comp_ctx)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -315,17 +315,15 @@ int identity_end(void *comp_ctx)
|
|||||||
/**************************
|
/**************************
|
||||||
**** gzip algorithm ****
|
**** gzip algorithm ****
|
||||||
***************************/
|
***************************/
|
||||||
int gzip_init(void *v, int level)
|
int gzip_init(struct comp_ctx *comp_ctx, int level)
|
||||||
{
|
{
|
||||||
z_stream *strm;
|
z_stream *strm = &comp_ctx->strm;
|
||||||
|
|
||||||
strm = v;
|
|
||||||
|
|
||||||
strm->zalloc = Z_NULL;
|
strm->zalloc = Z_NULL;
|
||||||
strm->zfree = Z_NULL;
|
strm->zfree = Z_NULL;
|
||||||
strm->opaque = 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 -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -334,25 +332,23 @@ int gzip_init(void *v, int level)
|
|||||||
**** Deflate algorithm ****
|
**** Deflate algorithm ****
|
||||||
***************************/
|
***************************/
|
||||||
|
|
||||||
int deflate_init(void *comp_ctx, int level)
|
int deflate_init(struct comp_ctx *comp_ctx, int level)
|
||||||
{
|
{
|
||||||
z_stream *strm;
|
z_stream *strm = &comp_ctx->strm;
|
||||||
|
|
||||||
strm = comp_ctx;
|
|
||||||
|
|
||||||
strm->zalloc = Z_NULL;
|
strm->zalloc = Z_NULL;
|
||||||
strm->zfree = Z_NULL;
|
strm->zfree = Z_NULL;
|
||||||
strm->opaque = Z_NULL;
|
strm->opaque = Z_NULL;
|
||||||
|
|
||||||
if (deflateInit(strm, level) != Z_OK)
|
if (deflateInit(&comp_ctx->strm, level) != Z_OK)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
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;
|
int ret;
|
||||||
|
|
||||||
if (in_len <= 0)
|
if (in_len <= 0)
|
||||||
@ -362,8 +358,6 @@ int deflate_add_data(void *comp_ctx, const char *in_data, int in_len, char *out_
|
|||||||
if (out_len <= 0)
|
if (out_len <= 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
strm = comp_ctx;
|
|
||||||
|
|
||||||
strm->next_in = (unsigned char *)in_data;
|
strm->next_in = (unsigned char *)in_data;
|
||||||
strm->avail_in = in_len;
|
strm->avail_in = in_len;
|
||||||
strm->next_out = (unsigned char *)out_data;
|
strm->next_out = (unsigned char *)out_data;
|
||||||
@ -378,13 +372,12 @@ int deflate_add_data(void *comp_ctx, const char *in_data, int in_len, char *out_
|
|||||||
return out_len - strm->avail_out;
|
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;
|
int ret;
|
||||||
z_stream *strm;
|
|
||||||
int out_len = 0;
|
int out_len = 0;
|
||||||
|
z_stream *strm = &comp_ctx->strm;
|
||||||
|
|
||||||
strm = comp_ctx;
|
|
||||||
strm->next_out = (unsigned char *)bi_end(out);
|
strm->next_out = (unsigned char *)bi_end(out);
|
||||||
strm->avail_out = out->size - buffer_len(out);
|
strm->avail_out = out->size - buffer_len(out);
|
||||||
|
|
||||||
@ -398,21 +391,19 @@ int deflate_flush(void *comp_ctx, struct buffer *out, int flag)
|
|||||||
return out_len;
|
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)
|
if (deflateReset(strm) == Z_OK)
|
||||||
return 0;
|
return 0;
|
||||||
return -1;
|
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)
|
if (deflateEnd(strm) == Z_OK)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -2111,14 +2111,14 @@ int select_compression_response_header(struct session *s, struct buffer *res)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* initialize compression */
|
/* 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;
|
goto fail;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
fail:
|
fail:
|
||||||
if (s->comp_algo) {
|
if (s->comp_algo) {
|
||||||
s->comp_algo->end(&s->comp_ctx.strm);
|
s->comp_algo->end(&s->comp_ctx);
|
||||||
s->comp_algo = NULL;
|
s->comp_algo = NULL;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -565,7 +565,7 @@ static void session_free(struct session *s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (s->comp_algo) {
|
if (s->comp_algo) {
|
||||||
s->comp_algo->end(&s->comp_ctx.strm);
|
s->comp_algo->end(&s->comp_ctx);
|
||||||
s->comp_algo = NULL;
|
s->comp_algo = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user