]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-compression: Remove legacy ostream_create() API
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 26 Nov 2024 14:14:58 +0000 (16:14 +0200)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Fri, 17 Jan 2025 08:40:01 +0000 (10:40 +0200)
src/lib-compression/compression.c
src/lib-compression/compression.h
src/lib-compression/ostream-bzlib.c
src/lib-compression/ostream-lz4.c
src/lib-compression/ostream-zlib.c
src/lib-compression/ostream-zlib.h
src/lib-compression/ostream-zstd.c

index 00821f7793517da1bf5a9d08619c7125220e0270..fde804dcb73872edd063d608284bbd12e9e9b612 100644 (file)
@@ -9,27 +9,15 @@
 
 #ifndef HAVE_BZLIB
 #  define i_stream_create_bz2 NULL
-#  define o_stream_create_bz2 NULL
 #  define o_stream_create_bz2_auto NULL
-#  define compression_get_min_level_bz2 NULL
-#  define compression_get_default_level_bz2 NULL
-#  define compression_get_max_level_bz2 NULL
 #endif
 #ifndef HAVE_LZ4
 #  define i_stream_create_lz4 NULL
-#  define o_stream_create_lz4 NULL
 #  define o_stream_create_lz4_auto NULL
-#  define compression_get_min_level_lz4 NULL
-#  define compression_get_default_level_lz4 NULL
-#  define compression_get_max_level_lz4 NULL
 #endif
 #ifndef HAVE_ZSTD
 #  define i_stream_create_zstd NULL
-#  define o_stream_create_zstd NULL
 #  define o_stream_create_zstd_auto NULL
-#  define compression_get_min_level_zstd NULL
-#  define compression_get_default_level_zstd NULL
-#  define compression_get_max_level_zstd NULL
 #endif
 
 static bool is_compressed_zlib(struct istream *input)
@@ -97,7 +85,7 @@ int compression_lookup_handler(const char *name,
        for (i = 0; compression_handlers[i].name != NULL; i++) {
                if (strcmp(name, compression_handlers[i].name) == 0) {
                        if (compression_handlers[i].create_istream == NULL ||
-                           compression_handlers[i].create_ostream == NULL) {
+                           compression_handlers[i].create_ostream_auto == NULL) {
                                /* Handler is known but not compiled in */
                                return 0;
                        }
@@ -135,7 +123,7 @@ int compression_lookup_handler_from_ext(const char *path,
                if (path_len > len &&
                    strcmp(path + path_len - len, compression_handlers[i].ext) == 0) {
                        if (compression_handlers[i].create_istream == NULL ||
-                           compression_handlers[i].create_ostream == NULL) {
+                           compression_handlers[i].create_ostream_auto == NULL) {
                                /* Handler is known but not compiled in */
                                return 0;
                        }
@@ -152,55 +140,35 @@ const struct compression_handler compression_handlers[] = {
                .ext = ".gz",
                .is_compressed = is_compressed_zlib,
                .create_istream = i_stream_create_gz,
-               .create_ostream = o_stream_create_gz,
                .create_ostream_auto = o_stream_create_gz_auto,
-               .get_min_level = compression_get_min_level_gz,
-               .get_default_level = compression_get_default_level_gz,
-               .get_max_level = compression_get_max_level_gz,
        },
        {
                .name = "bz2",
                .ext = ".bz2",
                .is_compressed = is_compressed_bzlib,
                .create_istream = i_stream_create_bz2,
-               .create_ostream = o_stream_create_bz2,
                .create_ostream_auto = o_stream_create_bz2_auto,
-               .get_min_level = compression_get_min_level_bz2,
-               .get_default_level = compression_get_default_level_bz2,
-               .get_max_level = compression_get_max_level_bz2,
        },
        {
                .name = "deflate",
                .ext = NULL,
                .is_compressed = NULL,
                .create_istream = i_stream_create_deflate,
-               .create_ostream = o_stream_create_deflate,
                .create_ostream_auto = o_stream_create_deflate_auto,
-               .get_min_level = compression_get_min_level_gz,
-               .get_default_level = compression_get_default_level_gz,
-               .get_max_level = compression_get_max_level_gz,
        },
        {
                .name = "lz4",
                .ext = ".lz4",
                .is_compressed = is_compressed_lz4,
                .create_istream = i_stream_create_lz4,
-               .create_ostream = o_stream_create_lz4,
                .create_ostream_auto = o_stream_create_lz4_auto,
-               .get_min_level = compression_get_min_level_lz4, /* does not actually support any of this */
-               .get_default_level = compression_get_default_level_lz4,
-               .get_max_level = compression_get_max_level_lz4,
        },
        {
                .name = "zstd",
                .ext = ".zstd",
                .is_compressed = is_compressed_zstd,
                .create_istream = i_stream_create_zstd,
-               .create_ostream = o_stream_create_zstd,
                .create_ostream_auto = o_stream_create_zstd_auto,
-               .get_min_level = compression_get_min_level_zstd,
-               .get_default_level = compression_get_default_level_zstd,
-               .get_max_level = compression_get_max_level_zstd,
        },
        {
                .name = "unsupported",
index 61c860f2db70b63c3a1527731bad25d6509720ed..05857146b4e4f5a4ddd159f7530bad33b590c5c3 100644 (file)
@@ -12,15 +12,7 @@ struct compression_handler {
        const char *ext;
        bool (*is_compressed)(struct istream *input);
        struct istream *(*create_istream)(struct istream *input);
-       struct ostream *(*create_ostream)(struct ostream *output, int level);
        struct ostream *(*create_ostream_auto)(struct ostream *output, struct event *event);
-       /* returns minimum level */
-       int (*get_min_level)(void);
-       /* the default can be -1 (e.g. gz), so the return value of this has to
-          be used as-is. */
-       int (*get_default_level)(void);
-       /* returns maximum level */
-       int (*get_max_level)(void);
 };
 
 extern const struct compression_handler compression_handlers[];
index e1a00da1cb123a6bb96c0791012882726a298d26..839fd22138995f6b457b7a20c62086546ec0ac36 100644 (file)
@@ -66,52 +66,6 @@ static bool bzlib_settings_check(void *_set, pool_t pool ATTR_UNUSED,
        return TRUE;
 }
 
-/* in bzlib, level is actually block size. From bzlib manual:
-
-   The block size affects both the compression ratio achieved,
-   and the amount of memory needed for compression and decompression.
-
-   BlockSize 1 through BlockSize 9 specify the block size to be 100,000 bytes
-   through 900,000 bytes respectively. The default is to use the maximum block
-   size.
-
-   Larger block sizes give rapidly diminishing marginal returns.
-   Most of the compression comes from the first two or three hundred k of
-   block size, a fact worth bearing in mind when using bzip2 on small machines.
-   It is also important to appreciate that the decompression memory
-   requirement is set at compression time by the choice of block size.
-
-   * In general, try and use the largest block size memory constraints
-     allow, since that maximises the compression achieved.
-   * Compression and decompression speed are virtually unaffected by block
-     size.
-
-   Another significant point applies to files which fit in a single block -
-   that means most files you'd encounter using a large block size. The
-   amount of real memory touched is proportional to the size of the file,
-   since the file is smaller than a block. For example, compressing a file
-   20,000 bytes long with the flag BlockSize 9 will cause the compressor to
-   allocate around 7600k of memory, but only touch 400k + 20000 * 8 = 560 kbytes
-   of it. Similarly, the decompressor will allocate 3700k but only
-   touch 100k + 20000 * 4 = 180 kbytes.
-*/
-
-int compression_get_min_level_bz2(void)
-{
-       return 1;
-}
-
-int compression_get_default_level_bz2(void)
-{
-       /* default is maximum level */
-       return 9;
-}
-
-int compression_get_max_level_bz2(void)
-{
-       return 9;
-}
-
 static void o_stream_bzlib_close(struct iostream_private *stream,
                                 bool close_parent)
 {
@@ -314,7 +268,7 @@ o_stream_bzlib_sendv(struct ostream_private *stream,
        return bytes;
 }
 
-struct ostream *o_stream_create_bz2(struct ostream *output, int level)
+static struct ostream *o_stream_create_bz2(struct ostream *output, int level)
 {
        struct bzlib_ostream *zstream;
        int ret;
index 073a85ca9592aa903e5e9c731e1b8078a0260418..65961603aeb6d3f0606d603f4541a86b01a6b8d1 100644 (file)
@@ -23,23 +23,6 @@ struct lz4_ostream {
        unsigned int outbuf_offset, outbuf_used;
 };
 
-/* There is no actual compression level in LZ4, so for legacy
-   reasons we allow 1-9 to avoid breaking anyone's config. */
-int compression_get_min_level_lz4(void)
-{
-       return 1;
-}
-
-int compression_get_default_level_lz4(void)
-{
-       return 1;
-}
-
-int compression_get_max_level_lz4(void)
-{
-       return 9;
-}
-
 static void o_stream_lz4_close(struct iostream_private *stream,
                               bool close_parent)
 {
@@ -215,13 +198,13 @@ o_stream_lz4_sendv(struct ostream_private *stream,
        return bytes;
 }
 
-struct ostream *o_stream_create_lz4(struct ostream *output, int level)
+struct ostream *
+o_stream_create_lz4_auto(struct ostream *output,
+                        struct event *event ATTR_UNUSED)
 {
        struct iostream_lz4_header *hdr;
        struct lz4_ostream *zstream;
 
-       i_assert(level >= 1 && level <= 9);
-
        zstream = i_new(struct lz4_ostream, 1);
        zstream->ostream.sendv = o_stream_lz4_sendv;
        zstream->ostream.flush = o_stream_lz4_flush;
@@ -247,11 +230,4 @@ struct ostream *o_stream_create_lz4(struct ostream *output, int level)
                               o_stream_get_fd(output));
 }
 
-struct ostream *
-o_stream_create_lz4_auto(struct ostream *output,
-                        struct event *event ATTR_UNUSED)
-{
-       return o_stream_create_lz4(output, 1);
-}
-
 #endif
index 32f8c125c35a8fc8f8d77bded1d6b3a272a94627..a82750b7724675c485568ae0c612f05d4e69afa4 100644 (file)
@@ -80,21 +80,6 @@ static bool zlib_settings_check(void *_set, pool_t pool ATTR_UNUSED,
        return TRUE;
 }
 
-int compression_get_min_level_gz(void)
-{
-       return Z_NO_COMPRESSION;
-}
-
-int compression_get_default_level_gz(void)
-{
-       return Z_DEFAULT_COMPRESSION;
-}
-
-int compression_get_max_level_gz(void)
-{
-       return Z_BEST_COMPRESSION;
-}
-
 static void o_stream_zlib_close(struct iostream_private *stream,
                                bool close_parent)
 {
@@ -433,16 +418,6 @@ o_stream_create_zlib(struct ostream *output, int level, bool gz)
                               o_stream_get_fd(output));
 }
 
-struct ostream *o_stream_create_gz(struct ostream *output, int level)
-{
-       return o_stream_create_zlib(output, level, TRUE);
-}
-
-struct ostream *o_stream_create_deflate(struct ostream *output, int level)
-{
-       return o_stream_create_zlib(output, level, FALSE);
-}
-
 static struct ostream *
 o_stream_create_zlib_auto(struct ostream *output, struct event *event, bool gz)
 {
index 6ae8822e72cd1ecee5adc4597d09e4eb97227945..9738e36cc0e7872810293657889e4baa628e9414 100644 (file)
@@ -1,32 +1,10 @@
 #ifndef OSTREAM_ZLIB_H
 #define OSTREAM_ZLIB_H
 
-struct ostream *o_stream_create_gz(struct ostream *output, int level);
-struct ostream *o_stream_create_deflate(struct ostream *output, int level);
-struct ostream *o_stream_create_bz2(struct ostream *output, int level);
-struct ostream *o_stream_create_lz4(struct ostream *output, int level);
-struct ostream *o_stream_create_zstd(struct ostream *output, int level);
-
 struct ostream *o_stream_create_gz_auto(struct ostream *output, struct event *event);
 struct ostream *o_stream_create_deflate_auto(struct ostream *output, struct event *event);
 struct ostream *o_stream_create_bz2_auto(struct ostream *output, struct event *event);
 struct ostream *o_stream_create_lz4_auto(struct ostream *output, struct event *event);
 struct ostream *o_stream_create_zstd_auto(struct ostream *output, struct event *event);
 
-int compression_get_min_level_gz(void);
-int compression_get_default_level_gz(void);
-int compression_get_max_level_gz(void);
-
-int compression_get_min_level_bz2(void);
-int compression_get_default_level_bz2(void);
-int compression_get_max_level_bz2(void);
-
-int compression_get_min_level_lz4(void);
-int compression_get_default_level_lz4(void);
-int compression_get_max_level_lz4(void);
-
-int compression_get_min_level_zstd(void);
-int compression_get_default_level_zstd(void);
-int compression_get_max_level_zstd(void);
-
 #endif
index 4984682ce728862f37994d1b13c176ae7f3f200f..786765f1376a43bbf3d70ee7a2c364f8dd4cf8a3 100644 (file)
@@ -77,26 +77,6 @@ static bool zstd_settings_check(void *_set, pool_t pool ATTR_UNUSED,
        return TRUE;
 }
 
-int compression_get_min_level_zstd(void)
-{
-       return ZSTD_minCLevel();
-}
-
-int compression_get_default_level_zstd(void)
-{
-#ifdef ZSTD_CLEVEL_DEFAULT
-       return ZSTD_CLEVEL_DEFAULT;
-#else
-       /* Documentation says 3 is default */
-       return 3;
-#endif
-}
-
-int compression_get_max_level_zstd(void)
-{
-       return ZSTD_maxCLevel();
-}
-
 static void o_stream_zstd_write_error(struct zstd_ostream *zstream, size_t err)
 {
        ZSTD_ErrorCode errcode = zstd_version_errcode(ZSTD_getErrorCode(err));
@@ -258,14 +238,13 @@ static void o_stream_zstd_close(struct iostream_private *stream,
                o_stream_close(zstream->ostream.parent);
 }
 
-struct ostream *
+static struct ostream *
 o_stream_create_zstd(struct ostream *output, int level)
 {
        struct zstd_ostream *zstream;
        size_t ret;
 
-       i_assert(level >= compression_get_min_level_zstd() &&
-                level <= compression_get_max_level_zstd());
+       i_assert(level >= ZSTD_minCLevel() && level <= ZSTD_maxCLevel());
 
        zstd_version_check();