From: Timo Sirainen Date: Tue, 26 Nov 2024 14:14:58 +0000 (+0200) Subject: lib-compression: Remove legacy ostream_create() API X-Git-Tag: 2.4.0~85 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e8de6fdadcd8b8b1bfa7bbb975570cda2c92cfa1;p=thirdparty%2Fdovecot%2Fcore.git lib-compression: Remove legacy ostream_create() API --- diff --git a/src/lib-compression/compression.c b/src/lib-compression/compression.c index 00821f7793..fde804dcb7 100644 --- a/src/lib-compression/compression.c +++ b/src/lib-compression/compression.c @@ -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", diff --git a/src/lib-compression/compression.h b/src/lib-compression/compression.h index 61c860f2db..05857146b4 100644 --- a/src/lib-compression/compression.h +++ b/src/lib-compression/compression.h @@ -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[]; diff --git a/src/lib-compression/ostream-bzlib.c b/src/lib-compression/ostream-bzlib.c index e1a00da1cb..839fd22138 100644 --- a/src/lib-compression/ostream-bzlib.c +++ b/src/lib-compression/ostream-bzlib.c @@ -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; diff --git a/src/lib-compression/ostream-lz4.c b/src/lib-compression/ostream-lz4.c index 073a85ca95..65961603ae 100644 --- a/src/lib-compression/ostream-lz4.c +++ b/src/lib-compression/ostream-lz4.c @@ -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 diff --git a/src/lib-compression/ostream-zlib.c b/src/lib-compression/ostream-zlib.c index 32f8c125c3..a82750b772 100644 --- a/src/lib-compression/ostream-zlib.c +++ b/src/lib-compression/ostream-zlib.c @@ -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) { diff --git a/src/lib-compression/ostream-zlib.h b/src/lib-compression/ostream-zlib.h index 6ae8822e72..9738e36cc0 100644 --- a/src/lib-compression/ostream-zlib.h +++ b/src/lib-compression/ostream-zlib.h @@ -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 diff --git a/src/lib-compression/ostream-zstd.c b/src/lib-compression/ostream-zstd.c index 4984682ce7..786765f137 100644 --- a/src/lib-compression/ostream-zstd.c +++ b/src/lib-compression/ostream-zstd.c @@ -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();