]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: compression: split deflate_flush() into flush and finish
authorWilly Tarreau <w@1wt.eu>
Sat, 28 Mar 2015 18:17:31 +0000 (19:17 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 28 Mar 2015 18:17:31 +0000 (19:17 +0100)
This function used to take a zlib-specific flag as argument to indicate
whether a buffer flush or end of contents was met, let's split it in two
so that we don't depend on zlib anymore.

include/types/compression.h
src/compression.c

index ae1e87df8e5d6263e8968f0b47665a43810ae26f..376eea9ef8923817b692ab609b7e2d26fb3762da 100644 (file)
@@ -62,7 +62,8 @@ struct comp_algo {
 
        int (*init)(struct comp_ctx **comp_ctx, int level);
        int (*add_data)(struct comp_ctx *comp_ctx, const char *in_data, int in_len, struct buffer *out);
-       int (*flush)(struct comp_ctx *comp_ctx, struct buffer *out, int flag);
+       int (*flush)(struct comp_ctx *comp_ctx, struct buffer *out);
+       int (*finish)(struct comp_ctx *comp_ctx, struct buffer *out);
        int (*reset)(struct comp_ctx *comp_ctx);
        int (*end)(struct comp_ctx **comp_ctx);
        struct comp_algo *next;
index cb061919d3a79c713afdc8c6b83a8b23a3f201f6..fd053d5409be3ec23b4204f0299feaa3bc186748 100644 (file)
@@ -57,7 +57,8 @@ static struct pool_head *pool_comp_ctx = NULL;
 
 static int identity_init(struct comp_ctx **comp_ctx, int level);
 static int identity_add_data(struct comp_ctx *comp_ctx, const char *in_data, int in_len, struct buffer *out);
-static int identity_flush(struct comp_ctx *comp_ctx, struct buffer *out, int flag);
+static int identity_flush(struct comp_ctx *comp_ctx, struct buffer *out);
+static int identity_finish(struct comp_ctx *comp_ctx, struct buffer *out);
 static int identity_reset(struct comp_ctx *comp_ctx);
 static int identity_end(struct comp_ctx **comp_ctx);
 
@@ -66,7 +67,8 @@ static int gzip_init(struct comp_ctx **comp_ctx, int level);
 static int raw_def_init(struct comp_ctx **comp_ctx, int level);
 static int deflate_init(struct comp_ctx **comp_ctx, int level);
 static int deflate_add_data(struct comp_ctx *comp_ctx, const char *in_data, int in_len, struct buffer *out);
-static int deflate_flush(struct comp_ctx *comp_ctx, struct buffer *out, int flag);
+static int deflate_flush(struct comp_ctx *comp_ctx, struct buffer *out);
+static int deflate_finish(struct comp_ctx *comp_ctx, struct buffer *out);
 static int deflate_reset(struct comp_ctx *comp_ctx);
 static int deflate_end(struct comp_ctx **comp_ctx);
 #endif /* USE_ZLIB */
@@ -74,11 +76,11 @@ static int deflate_end(struct comp_ctx **comp_ctx);
 
 const struct comp_algo comp_algos[] =
 {
-       { "identity",     8, "identity", 8, identity_init, identity_add_data, identity_flush, identity_reset, identity_end },
+       { "identity",     8, "identity", 8, identity_init, identity_add_data, identity_flush, identity_finish, identity_reset, identity_end },
 #ifdef USE_ZLIB
-       { "deflate",      7, "deflate",  7, deflate_init,  deflate_add_data,  deflate_flush,  deflate_reset,  deflate_end },
-       { "raw-deflate", 11, "deflate",  7, raw_def_init,  deflate_add_data,  deflate_flush,  deflate_reset,  deflate_end },
-       { "gzip",         4, "gzip",     4, gzip_init,     deflate_add_data,  deflate_flush,  deflate_reset,  deflate_end },
+       { "deflate",      7, "deflate",  7, deflate_init,  deflate_add_data,  deflate_flush,  deflate_finish,  deflate_reset,  deflate_end },
+       { "raw-deflate", 11, "deflate",  7, raw_def_init,  deflate_add_data,  deflate_flush,  deflate_finish,  deflate_reset,  deflate_end },
+       { "gzip",         4, "gzip",     4, gzip_init,     deflate_add_data,  deflate_flush,  deflate_finish,  deflate_reset,  deflate_end },
 #endif /* USE_ZLIB */
        { NULL,       0, NULL,          0, NULL ,         NULL,              NULL,           NULL,           NULL }
 };
@@ -225,9 +227,9 @@ int http_compression_buffer_end(struct session *s, struct buffer **in, struct bu
        /* flush data here */
 
        if (end)
-               ret = s->comp_algo->flush(s->comp_ctx, ob, Z_FINISH); /* end of data */
+               ret = s->comp_algo->finish(s->comp_ctx, ob); /* end of data */
        else
-               ret = s->comp_algo->flush(s->comp_ctx, ob, Z_SYNC_FLUSH); /* end of buffer */
+               ret = s->comp_algo->flush(s->comp_ctx, ob); /* end of buffer */
 
        if (ret < 0)
                return -1; /* flush failed */
@@ -415,7 +417,12 @@ static int identity_add_data(struct comp_ctx *comp_ctx, const char *in_data, int
        return in_len;
 }
 
-static int identity_flush(struct comp_ctx *comp_ctx, struct buffer *out, int flag)
+static int identity_flush(struct comp_ctx *comp_ctx, struct buffer *out)
+{
+       return 0;
+}
+
+static int identity_finish(struct comp_ctx *comp_ctx, struct buffer *out)
 {
        return 0;
 }
@@ -614,7 +621,7 @@ static int deflate_add_data(struct comp_ctx *comp_ctx, const char *in_data, int
        return in_len - strm->avail_in;
 }
 
-static int deflate_flush(struct comp_ctx *comp_ctx, struct buffer *out, int flag)
+static int deflate_flush_or_finish(struct comp_ctx *comp_ctx, struct buffer *out, int flag)
 {
        int ret;
        int out_len = 0;
@@ -648,6 +655,16 @@ static int deflate_flush(struct comp_ctx *comp_ctx, struct buffer *out, int flag
        return out_len;
 }
 
+static int deflate_flush(struct comp_ctx *comp_ctx, struct buffer *out)
+{
+       return deflate_flush_or_finish(comp_ctx, out, Z_SYNC_FLUSH);
+}
+
+static int deflate_finish(struct comp_ctx *comp_ctx, struct buffer *out)
+{
+       return deflate_flush_or_finish(comp_ctx, out, Z_FINISH);
+}
+
 static int deflate_reset(struct comp_ctx *comp_ctx)
 {
        z_stream *strm = &comp_ctx->strm;