]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm dump: Added imapzlib type to uncompress IMAP's COMPRESS DEFLATE I/O traffic.
authorTimo Sirainen <tss@iki.fi>
Wed, 3 Nov 2010 16:27:00 +0000 (16:27 +0000)
committerTimo Sirainen <tss@iki.fi>
Wed, 3 Nov 2010 16:27:00 +0000 (16:27 +0000)
src/plugins/zlib/Makefile.am
src/plugins/zlib/doveadm-zlib.c [new file with mode: 0644]

index d3bd9ab0fe0a47bedf6550b7207dfef2392654df..25fb034d3f821595c9b1ec490f468a71f2644967 100644 (file)
@@ -1,11 +1,15 @@
+doveadm_moduledir = $(moduledir)/doveadm
+
 AM_CPPFLAGS = \
        -I$(top_srcdir)/src/lib \
        -I$(top_srcdir)/src/lib-mail \
        -I$(top_srcdir)/src/lib-index \
        -I$(top_srcdir)/src/lib-storage \
        -I$(top_srcdir)/src/lib-storage/index \
-       -I$(top_srcdir)/src/lib-storage/index/dbox-common
+       -I$(top_srcdir)/src/lib-storage/index/dbox-common \
+       -I$(top_srcdir)/src/doveadm
 
+lib10_doveadm_zlib_plugin_la_LDFLAGS = -module -avoid-version
 lib20_zlib_plugin_la_LDFLAGS = -module -avoid-version
 
 module_LTLIBRARIES = \
@@ -32,3 +36,9 @@ noinst_HEADERS = \
        istream-zlib.h \
        ostream-zlib.h \
        zlib-plugin.h
+
+doveadm_module_LTLIBRARIES = \
+       lib10_doveadm_zlib_plugin.la
+
+lib10_doveadm_zlib_plugin_la_SOURCES = \
+       doveadm-zlib.c
diff --git a/src/plugins/zlib/doveadm-zlib.c b/src/plugins/zlib/doveadm-zlib.c
new file mode 100644 (file)
index 0000000..ac34ecc
--- /dev/null
@@ -0,0 +1,93 @@
+/* Copyright (c) 2010 Dovecot authors, see the included COPYING file */
+
+#include "lib.h"
+#include "istream.h"
+#include "istream-zlib.h"
+#include "module-dir.h"
+#include "doveadm-dump.h"
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+const char *doveadm_zlib_plugin_version = DOVECOT_VERSION;
+
+void doveadm_zlib_plugin_init(struct module *module);
+void doveadm_zlib_plugin_deinit(void);
+
+static void cmd_dump_imapzlib(int argc ATTR_UNUSED, char *argv[])
+{
+       struct istream *input, *input2;
+       const unsigned char *data;
+       size_t size;
+       const char *line;
+       int fd;
+
+       fd = open(argv[1], O_RDONLY);
+       if (fd < 0)
+               i_fatal("open(%s) failed: %m", argv[1]);
+       input = i_stream_create_fd(fd, 1024*32, TRUE);
+       while ((line = i_stream_read_next_line(input)) != NULL) {
+               /* skip tag */
+               printf("%s\r\n", line);
+               while (*line != ' ' && *line != '\0') line++;
+               if (*line == '\0')
+                       continue;
+               line++;
+
+               if (strcmp(line, "OK Begin compression.") == 0 ||
+                   strcasecmp(line, "COMPRESS DEFLATE") == 0)
+                       break;
+       }
+
+       input2 = i_stream_create_deflate(input, TRUE);
+       i_stream_unref(&input);
+
+       while (i_stream_read_data(input2, &data, &size, 0) != -1) {
+               fwrite(data, 1, size, stdout);
+               i_stream_skip(input2, size);
+       }
+       i_stream_unref(&input2);
+       fflush(stdout);
+}
+
+static bool test_dump_imapzlib(const char *path)
+{
+       const char *p;
+       char buf[4096];
+       int fd, ret;
+       bool match = FALSE;
+
+       p = strrchr(path, '.');
+       if (p == NULL || (strcmp(p, ".in") != 0 && strcmp(p, ".out") != 0))
+               return FALSE;
+
+       fd = open(path, O_RDONLY);
+       if (fd == -1)
+               return FALSE;
+
+       ret = read(fd, buf, sizeof(buf)-1);
+       if (ret > 0) {
+               buf[ret] = '\0';
+               str_lcase(buf);
+               match = strstr(buf, " ok begin compression.") != NULL ||
+                       strstr(buf, " compress deflate") != NULL;
+       }
+       (void)close(fd);
+       return match;
+}
+
+struct doveadm_cmd_dump doveadm_cmd_dump_zlib = {
+       "imapzlib",
+       test_dump_imapzlib,
+       cmd_dump_imapzlib
+};
+
+void doveadm_zlib_plugin_init(struct module *module ATTR_UNUSED)
+{
+       doveadm_dump_register(&doveadm_cmd_dump_zlib);
+}
+
+void doveadm_zlib_plugin_deinit(void)
+{
+}