]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: use struct comp_ctx instead of union
authorWilliam Lallemand <wlallemand@exceliance.fr>
Tue, 30 Oct 2012 14:52:53 +0000 (15:52 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 5 Nov 2012 09:23:16 +0000 (10:23 +0100)
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.

include/proto/compression.h
include/types/compression.h
include/types/session.h
src/compression.c
src/proto_http.c
src/session.c

index 6f1a26a0b00df763176e3f384a25437041b2ec50..fa4c7b743679beff6de2c249d069a20116852e7e 100644 (file)
@@ -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_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 */
 
index 10ac4b1159768f0304d5b738c2b6828760353766..dfff2f97e992365c0bcf16f9266649e88f359360 100644 (file)
@@ -31,21 +31,21 @@ struct comp {
        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;
index 4726a19a205e666abb60f31708c3becc9fd6db29..5546be8c83d84a96257382b137227a60356a5a50 100644 (file)
@@ -156,8 +156,8 @@ struct session {
        void (*srv_error)(struct session *s,    /* the function to call upon unrecoverable server errors (or NULL) */
                          struct stream_interface *si);
        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 */
-       union comp_ctx comp_ctx;                /* HTTP compression context */
        char *unique_id;                        /* custom unique ID */
 };
 
index 3ff3aea9a79632f2c1d49001aa62dd1d3cadf622..2c0e4f99eeea16d5d84f75ff4886fd4430761100 100644 (file)
@@ -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);
        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 @@ int http_compression_buffer_add_data(struct session *s, struct buffer *in, struc
                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 @@ int http_compression_buffer_end(struct session *s, struct buffer **in, struct bu
 /*
  * 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 @@ int identity_init(void *v, int level)
  * 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 @@ int identity_add_data(void *comp_ctx, const char *in_data, int in_len, char *out
        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 @@ int identity_reset(void *comp_ctx)
 /*
  * Deinit the algorithm
  */
-int identity_end(void *comp_ctx)
+int identity_end(struct comp_ctx *comp_ctx)
 {
        return 0;
 }
@@ -315,17 +315,15 @@ int identity_end(void *comp_ctx)
 /**************************
 ****  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 @@ int gzip_init(void *v, int level)
 **** 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 @@ int deflate_add_data(void *comp_ctx, const char *in_data, int in_len, char *out_
        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 @@ int deflate_add_data(void *comp_ctx, const char *in_data, int in_len, char *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;
-       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 @@ int deflate_flush(void *comp_ctx, struct buffer *out, int flag)
        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;
 
index cb24eb030cfb9749d4e882e9bd4f40933f566c84..7f2c8061c5b38af80dbe046399b21f95abbe61c4 100644 (file)
@@ -2111,14 +2111,14 @@ int select_compression_response_header(struct session *s, struct buffer *res)
        }
 
        /* 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;
index 9d727034b418101207e245c4e7beedd68f422c17..55f976ba1fca5b593463d1a36c584bcefcb04feb 100644 (file)
@@ -565,7 +565,7 @@ static void session_free(struct session *s)
        }
 
        if (s->comp_algo) {
-               s->comp_algo->end(&s->comp_ctx.strm);
+               s->comp_algo->end(&s->comp_ctx);
                s->comp_algo = NULL;
        }