dovecot-2.2: Moved zlib/bzlib code to lib-compression library.
dovecot at dovecot.org
dovecot at dovecot.org
Wed Aug 1 18:30:52 EEST 2012
details: http://hg.dovecot.org/dovecot-2.2/rev/378ba560ea9f
changeset: 14739:378ba560ea9f
user: Timo Sirainen <tss at iki.fi>
date: Wed Aug 01 18:30:40 2012 +0300
description:
Moved zlib/bzlib code to lib-compression library.
diffstat:
Makefile.am | 1 +
configure.in | 16 +-
dovecot-config.in.in | 5 +-
dovecot.m4 | 8 +-
src/Makefile.am | 1 +
src/lib-compression/Makefile.am | 25 +
src/lib-compression/compression.c | 99 +++++
src/lib-compression/compression.h | 24 +
src/lib-compression/istream-bzlib.c | 345 ++++++++++++++++++++
src/lib-compression/istream-zlib.c | 516 +++++++++++++++++++++++++++++++
src/lib-compression/istream-zlib.h | 8 +
src/lib-compression/ostream-bzlib.c | 222 +++++++++++++
src/lib-compression/ostream-zlib.c | 325 +++++++++++++++++++
src/lib-compression/ostream-zlib.h | 8 +
src/plugins/imap-zlib/Makefile.am | 8 +-
src/plugins/imap-zlib/imap-zlib-plugin.c | 11 +-
src/plugins/zlib/Makefile.am | 16 +-
src/plugins/zlib/istream-bzlib.c | 345 --------------------
src/plugins/zlib/istream-zlib.c | 516 -------------------------------
src/plugins/zlib/istream-zlib.h | 8 -
src/plugins/zlib/ostream-bzlib.c | 222 -------------
src/plugins/zlib/ostream-zlib.c | 325 -------------------
src/plugins/zlib/ostream-zlib.h | 8 -
src/plugins/zlib/zlib-plugin.c | 107 +-----
src/plugins/zlib/zlib-plugin.h | 13 -
25 files changed, 1611 insertions(+), 1571 deletions(-)
diffs (truncated from 3535 to 300 lines):
diff -r c3a781ef0aeb -r 378ba560ea9f Makefile.am
--- a/Makefile.am Tue Jul 31 19:32:03 2012 +0300
+++ b/Makefile.am Wed Aug 01 18:30:40 2012 +0300
@@ -66,6 +66,7 @@
-e "s|^\(LIBDOVECOT_LOGIN\)=.*$$|\1=-ldovecot-login|" \
-e "s|^\(LIBDOVECOT_SQL\)=.*$$|\1=-ldovecot-sql|" \
-e "s|^\(LIBDOVECOT_SSL\)=.*$$|\1=-ldovecot-ssl|" \
+ -e "s|^\(LIBDOVECOT_COMPRESS\)=.*$$|\1=-ldovecot-compress|" \
-e "s|^\(LIBDOVECOT_LDA\)=.*$$|\1=-ldovecot-lda|" \
-e "s|^\(LIBDOVECOT_STORAGE\)=.*$$|\1=-ldovecot-storage|" \
-e "s|^\(LIBDOVECOT_INCLUDE\)=.*$$|\1=-I$(pkgincludedir)|" \
diff -r c3a781ef0aeb -r 378ba560ea9f configure.in
--- a/configure.in Tue Jul 31 19:32:03 2012 +0300
+++ b/configure.in Wed Aug 01 18:30:40 2012 +0300
@@ -2515,6 +2515,7 @@
LIBDOVECOT_STORAGE_DEPS='$(top_builddir)/src/lib-storage/libdovecot-storage.la $(top_builddir)/src/lib-imap-storage/libimap-storage.la'
LIBDOVECOT_LOGIN='$(top_builddir)/src/login-common/libdovecot-login.la'
LIBDOVECOT_SSL='$(top_builddir)/src/lib-master/libmaster_ssl.la $(top_builddir)/src/lib-ssl-iostream/libssl_iostream.la'
+ LIBDOVECOT_COMPRESS='$(top_builddir)/src/lib-compression/libcompression.la'
LIBDOVECOT_LDA='$(top_builddir)/src/lib-lda/libdovecot-lda.la'
else
LIBDOVECOT_DEPS='$(top_builddir)/src/lib-master/libmaster.la $(top_builddir)/src/lib-settings/libsettings.la $(top_builddir)/src/lib-dict/libdict.la $(top_builddir)/src/lib-dns/libdns.la $(top_builddir)/src/lib-fs/libfs.la $(top_builddir)/src/lib-imap/libimap.la $(top_builddir)/src/lib-mail/libmail.la $(top_builddir)/src/lib-auth/libauth.la $(top_builddir)/src/lib-charset/libcharset.la $(top_builddir)/src/lib/liblib.la'
@@ -2524,6 +2525,7 @@
LIBDOVECOT_STORAGE_DEPS="$LIBDOVECOT_STORAGE_FIRST $LINKED_STORAGE_LIBS $LIBDOVECOT_STORAGE_LAST"
LIBDOVECOT_LOGIN='$(top_builddir)/src/login-common/liblogin.la $(top_builddir)/src/lib-ssl-iostream/libssl_iostream.la'
LIBDOVECOT_SSL='$(top_builddir)/src/lib-master/libmaster_ssl.la $(top_builddir)/src/lib-ssl-iostream/libssl_iostream.la'
+ LIBDOVECOT_COMPRESS='$(top_builddir)/src/lib-compression/libcompression.la'
LIBDOVECOT_LDA='$(top_builddir)/src/lib-lda/liblda.la'
fi
LIBDOVECOT_STORAGE="$LIBDOVECOT_STORAGE_DEPS $LINKED_STORAGE_LDADD"
@@ -2535,6 +2537,7 @@
AC_SUBST(LIBDOVECOT_LOGIN)
AC_SUBST(LIBDOVECOT_SQL)
AC_SUBST(LIBDOVECOT_SSL)
+AC_SUBST(LIBDOVECOT_COMPRESS)
AC_SUBST(LIBDOVECOT_LDA)
dnl **
@@ -2576,25 +2579,27 @@
dnl ** Plugins
dnl **
+COMPRESS_LIBS=
if test "$want_zlib" != "no"; then
AC_CHECK_HEADER(zlib.h, [
have_zlib=yes
- have_zlib_plugin=yes
+ have_compress_lib=yes
AC_DEFINE(HAVE_ZLIB,, Define if you have zlib library)
+ COMPRESS_LIBS="$COMPRESS_LIBS -lz"
], [
if test "$want_zlib" = "yes"; then
AC_ERROR([Can't build with zlib support: zlib.h not found])
fi
])
fi
-AM_CONDITIONAL(BUILD_ZLIB, test "$have_zlib" = "yes")
if test "$want_bzlib" != "no"; then
AC_CHECK_HEADER(bzlib.h, [
AC_CHECK_LIB(bz2, BZ2_bzdopen, [
have_bzlib=yes
- have_zlib_plugin=yes
+ have_compress_lib=yes
AC_DEFINE(HAVE_BZLIB,, Define if you have bzlib library)
+ COMPRESS_LIBS="$COMPRESS_LIBS -lbz2"
], [
if test "$want_bzlib" = "yes"; then
AC_ERROR([Can't build with bzlib support: libbz2 not found])
@@ -2606,8 +2611,8 @@
fi
])
fi
-AM_CONDITIONAL(BUILD_BZLIB, test "$have_bzlib" = "yes")
-AM_CONDITIONAL(BUILD_ZLIB_PLUGIN, test "$have_zlib_plugin" = "yes")
+AC_SUBST(COMPRESS_LIBS)
+AM_CONDITIONAL(BUILD_ZLIB_PLUGIN, test "$have_compress_lib" = "yes")
RPCGEN=${RPCGEN-rpcgen}
if ! $RPCGEN -c /dev/null > /dev/null; then
@@ -2747,6 +2752,7 @@
src/lib-sql/Makefile
src/lib-auth/Makefile
src/lib-charset/Makefile
+src/lib-compression/Makefile
src/lib-dict/Makefile
src/lib-dns/Makefile
src/lib-fs/Makefile
diff -r c3a781ef0aeb -r 378ba560ea9f dovecot-config.in.in
--- a/dovecot-config.in.in Tue Jul 31 19:32:03 2012 +0300
+++ b/dovecot-config.in.in Wed Aug 01 18:30:40 2012 +0300
@@ -2,11 +2,13 @@
DOVECOT_LIBS="@LIBS@"
DOVECOT_SSL_LIBS="@SSL_LIBS@"
DOVECOT_SQL_LIBS="@SQL_LIBS@"
+DOVECOT_COMPRESS_LIBS="@COMPRESS_LIBS@"
LIBDOVECOT="@LIBDOVECOT@ @MODULE_LIBS@"
LIBDOVECOT_LOGIN="@LIBDOVECOT_LOGIN@ @SSL_LIBS@"
LIBDOVECOT_SQL="@LIBDOVECOT_SQL@"
LIBDOVECOT_SSL="@LIBDOVECOT_SSL@"
+LIBDOVECOT_COMPRESS="@LIBDOVECOT_COMPRESS@"
LIBDOVECOT_LDA="@LIBDOVECOT_LDA@"
LIBDOVECOT_STORAGE="@LIBDOVECOT_STORAGE@"
@@ -14,10 +16,11 @@
LIBDOVECOT_LOGIN_DEPS="@LIBDOVECOT_LOGIN@"
LIBDOVECOT_SQL_DEPS="@LIBDOVECOT_SQL@"
LIBDOVECOT_SSL_DEPS="@LIBDOVECOT_SSL@"
+LIBDOVECOT_COMPRESS_DEPS="@LIBDOVECOT_COMPRESS@"
LIBDOVECOT_LDA_DEPS="@LIBDOVECOT_LDA@"
LIBDOVECOT_STORAGE_DEPS="@LIBDOVECOT_STORAGE_DEPS@"
-LIBDOVECOT_INCLUDE="-I$(incdir) -I$(incdir)/src/lib -I$(incdir)/src/lib-dict -I$(incdir)/src/lib-dns -I$(incdir)/src/lib-mail -I$(incdir)/src/lib-imap -I$(incdir)/src/lib-fs -I$(incdir)/src/lib-charset -I$(incdir)/src/lib-auth -I$(incdir)/src/lib-master -I$(incdir)/src/lib-ssl-iostream -I$(incdir)/src/lib-settings"
+LIBDOVECOT_INCLUDE="-I$(incdir) -I$(incdir)/src/lib -I$(incdir)/src/lib-dict -I$(incdir)/src/lib-dns -I$(incdir)/src/lib-mail -I$(incdir)/src/lib-imap -I$(incdir)/src/lib-fs -I$(incdir)/src/lib-charset -I$(incdir)/src/lib-auth -I$(incdir)/src/lib-master -I$(incdir)/src/lib-ssl-iostream -I$(incdir)/src/lib-compression -I$(incdir)/src/lib-settings"
LIBDOVECOT_LDA_INCLUDE="-I$(incdir)/src/lib-lda -I$(incdir)/src/lda"
LIBDOVECOT_STORAGE_INCLUDE="-I$(incdir)/src/lib-index -I$(incdir)/src/lib-storage -I$(incdir)/src/lib-storage/index -I$(incdir)/src/lib-storage/index/raw"
LIBDOVECOT_LOGIN_INCLUDE="-I$(incdir)/src/login-common"
diff -r c3a781ef0aeb -r 378ba560ea9f dovecot.m4
--- a/dovecot.m4 Tue Jul 31 19:32:03 2012 +0300
+++ b/dovecot.m4 Wed Aug 01 18:30:40 2012 +0300
@@ -6,7 +6,7 @@
# unlimited permission to copy and/or distribute it, with or without
# modifications, as long as this notice is preserved.
-# serial 7
+# serial 8
AC_DEFUN([DC_DOVECOT_MODULEDIR],[
AC_ARG_WITH(moduledir,
@@ -84,9 +84,9 @@
fi
AX_SUBST_L([DISTCHECK_CONFIGURE_FLAGS], [dovecotdir], [dovecot_moduledir], [dovecot_pkgincludedir], [dovecot_pkglibexecdir], [dovecot_pkglibdir], [dovecot_docdir])
- AX_SUBST_L([DOVECOT_CFLAGS], [DOVECOT_LIBS], [DOVECOT_SSL_LIBS], [DOVECOT_SQL_LIBS])
- AX_SUBST_L([LIBDOVECOT], [LIBDOVECOT_LOGIN], [LIBDOVECOT_SQL], [LIBDOVECOT_SSL], [LIBDOVECOT_LDA], [LIBDOVECOT_STORAGE])
- AX_SUBST_L([LIBDOVECOT_DEPS], [LIBDOVECOT_LOGIN_DEPS], [LIBDOVECOT_SQL_DEPS], [LIBDOVECOT_SSL_DEPS], [LIBDOVECOT_LDA_DEPS], [LIBDOVECOT_STORAGE_DEPS])
+ AX_SUBST_L([DOVECOT_CFLAGS], [DOVECOT_LIBS], [DOVECOT_SSL_LIBS], [DOVECOT_SQL_LIBS], [DOVECOT_COMPRESS_LIBS])
+ AX_SUBST_L([LIBDOVECOT], [LIBDOVECOT_LOGIN], [LIBDOVECOT_SQL], [LIBDOVECOT_SSL], [LIBDOVECOT_COMPRESS], [LIBDOVECOT_LDA], [LIBDOVECOT_STORAGE])
+ AX_SUBST_L([LIBDOVECOT_DEPS], [LIBDOVECOT_LOGIN_DEPS], [LIBDOVECOT_SQL_DEPS], [LIBDOVECOT_SSL_DEPS], [LIBDOVECOT_COMPRESS_DEPS], [LIBDOVECOT_LDA_DEPS], [LIBDOVECOT_STORAGE_DEPS])
AX_SUBST_L([LIBDOVECOT_INCLUDE], [LIBDOVECOT_LDA_INCLUDE], [LIBDOVECOT_SERVICE_INCLUDE], [LIBDOVECOT_STORAGE_INCLUDE], [LIBDOVECOT_LOGIN_INCLUDE], [LIBDOVECOT_CONFIG_INCLUDE], [LIBDOVECOT_IMAP_INCLUDE])
DC_PLUGIN_DEPS
diff -r c3a781ef0aeb -r 378ba560ea9f src/Makefile.am
--- a/src/Makefile.am Tue Jul 31 19:32:03 2012 +0300
+++ b/src/Makefile.am Wed Aug 01 18:30:40 2012 +0300
@@ -16,6 +16,7 @@
lib-test \
$(LIBDOVECOT_SUBDIRS) \
lib-imap-client \
+ lib-compression \
lib-dovecot \
lib-index \
lib-storage \
diff -r c3a781ef0aeb -r 378ba560ea9f src/lib-compression/Makefile.am
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-compression/Makefile.am Wed Aug 01 18:30:40 2012 +0300
@@ -0,0 +1,25 @@
+noinst_LTLIBRARIES = libcompression.la
+
+AM_CPPFLAGS = \
+ -I$(top_srcdir)/src/lib \
+ -I$(top_srcdir)/src/lib-test
+
+libcompression_la_SOURCES = \
+ compression.c \
+ istream-zlib.c \
+ istream-bzlib.c \
+ ostream-zlib.c \
+ ostream-bzlib.c
+libcompression_la_LIBADD = \
+ $(COMPRESS_LIBS)
+
+pkginc_libdir = $(pkgincludedir)
+ compression.h \
+ istream-zlib.h \
+ ostream-zlib.h
+
+pkglib_LTLIBRARIES = libdovecot-compression.la
+libdovecot_compression_la_SOURCES =
+libdovecot_compression_la_LIBADD = libcompression.la ../lib/liblib.la $(MODULE_LIBS) $(COMPRESS_LIBS)
+libdovecot_compression_la_DEPENDENCIES = libcompression.la
+libdovecot_compression_la_LDFLAGS = -export-dynamic
diff -r c3a781ef0aeb -r 378ba560ea9f src/lib-compression/compression.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-compression/compression.c Wed Aug 01 18:30:40 2012 +0300
@@ -0,0 +1,99 @@
+/* Copyright (c) 2010-2012 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "istream.h"
+#include "istream-zlib.h"
+#include "ostream-zlib.h"
+#include "compression.h"
+
+#ifndef HAVE_ZLIB
+# define i_stream_create_gz NULL
+# define o_stream_create_gz NULL
+#endif
+#ifndef HAVE_BZLIB
+# define i_stream_create_bz2 NULL
+# define o_stream_create_bz2 NULL
+#endif
+
+static bool is_compressed_zlib(struct istream *input)
+{
+ const unsigned char *data;
+ size_t size;
+
+ /* Peek in to the stream and see if it looks like it's compressed
+ (based on its header). This also means that users can try to exploit
+ security holes in the uncompression library by APPENDing a specially
+ crafted mail. So let's hope zlib is free of holes. */
+ if (i_stream_read_data(input, &data, &size, 1) <= 0)
+ return FALSE;
+ i_assert(size >= 2);
+
+ return data[0] == 31 && data[1] == 139;
+}
+
+static bool is_compressed_bzlib(struct istream *input)
+{
+ const unsigned char *data;
+ size_t size;
+
+ if (i_stream_read_data(input, &data, &size, 4+6 - 1) <= 0)
+ return FALSE;
+ if (data[0] != 'B' || data[1] != 'Z')
+ return FALSE;
+ if (data[2] != 'h' && data[2] != '0')
+ return FALSE;
+ if (data[3] < '1' || data[3] > '9')
+ return FALSE;
+ return memcmp(data + 4, "\x31\x41\x59\x26\x53\x59", 6) == 0;
+}
+
+const struct compression_handler *compression_lookup_handler(const char *name)
+{
+ unsigned int i;
+
+ for (i = 0; compression_handlers[i].name != NULL; i++) {
+ if (strcmp(name, compression_handlers[i].name) == 0)
+ return &compression_handlers[i];
+ }
+ return NULL;
+}
+
+const struct compression_handler *
+compression_detect_handler(struct istream *input)
+{
+ unsigned int i;
+
+ for (i = 0; compression_handlers[i].name != NULL; i++) {
+ if (compression_handlers[i].is_compressed != NULL &&
+ compression_handlers[i].is_compressed(input))
+ return &compression_handlers[i];
+ }
+ return NULL;
+}
+
+const struct compression_handler *
+compression_lookup_handler_from_ext(const char *path)
+{
+ unsigned int i, len, path_len = strlen(path);
+
+ for (i = 0; compression_handlers[i].name != NULL; i++) {
+ if (compression_handlers[i].ext == NULL)
+ continue;
+
+ len = strlen(compression_handlers[i].ext);
+ if (path_len > len &&
+ strcmp(path + path_len - len, compression_handlers[i].ext) == 0)
+ return &compression_handlers[i];
+ }
+ return NULL;
+}
+
+const struct compression_handler compression_handlers[] = {
+ { "gz", ".gz", is_compressed_zlib,
+ i_stream_create_gz, o_stream_create_gz },
+ { "bz2", ".bz2", is_compressed_bzlib,
+ i_stream_create_bz2, o_stream_create_bz2 },
+ { "deflate", NULL, NULL,
+ i_stream_create_deflate, o_stream_create_deflate },
+ { NULL, NULL, NULL, NULL, NULL }
+};
diff -r c3a781ef0aeb -r 378ba560ea9f src/lib-compression/compression.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/lib-compression/compression.h Wed Aug 01 18:30:40 2012 +0300
@@ -0,0 +1,24 @@
+#ifndef COMPRESSION_H
+#define COMPRESSION_H
+
+struct compression_handler {
+ const char *name;
+ const char *ext;
+ bool (*is_compressed)(struct istream *input);
+ struct istream *(*create_istream)(struct istream *input,
+ bool log_errors);
+ struct ostream *(*create_ostream)(struct ostream *output, int level);
More information about the dovecot-cvs
mailing list