]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm dump: Change doveadm_cmd_dump.cmd() API to be simpler
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 9 Jun 2021 20:10:08 +0000 (23:10 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Wed, 21 Jul 2021 09:03:09 +0000 (09:03 +0000)
12 files changed:
src/doveadm/doveadm-dump-dbox.c
src/doveadm/doveadm-dump-dcrypt-file.c
src/doveadm/doveadm-dump-dcrypt-key.c
src/doveadm/doveadm-dump-index.c
src/doveadm/doveadm-dump-log.c
src/doveadm/doveadm-dump-mailboxlog.c
src/doveadm/doveadm-dump-thread.c
src/doveadm/doveadm-dump.c
src/doveadm/doveadm-dump.h
src/doveadm/doveadm-zlib.c
src/plugins/fts-lucene/doveadm-fts-lucene.c
src/plugins/fts/doveadm-dump-fts-expunge-log.c

index e17fcade392cd7983b81421735140702c5b76ce0..429b4a15f4e887460fd8e5948e3f16825a5cb790 100644 (file)
@@ -189,19 +189,19 @@ static bool dump_msg(struct istream *input, unsigned int hdr_size)
        return TRUE;
 }
 
-static void cmd_dump_dbox(int argc ATTR_UNUSED, char *argv[])
+static void cmd_dump_dbox(const char *path, const char *const *args ATTR_UNUSED)
 {
        struct istream *input;
        int fd;
        unsigned int hdr_size;
        bool ret;
 
-       fd = open(argv[1], O_RDONLY);
+       fd = open(path, O_RDONLY);
        if (fd < 0)
-               i_fatal("open(%s) failed: %m", argv[1]);
+               i_fatal("open(%s) failed: %m", path);
 
        input = i_stream_create_fd_autoclose(&fd, SIZE_MAX);
-       i_stream_set_name(input, argv[1]);
+       i_stream_set_name(input, path);
        hdr_size = dump_file_hdr(input);
        do {
                printf("\n");
index 539919beab41b243cb963f64c3d236eaf08b81aa..3703bf488eb3c426c922071253529c727c2fbbda 100644 (file)
@@ -77,12 +77,13 @@ static bool test_dump_dcrypt_file(const char *path)
        return ret;
 }
 
-static void cmd_dump_dcrypt_file(int argc ATTR_UNUSED, char *argv[])
+static void
+cmd_dump_dcrypt_file(const char *path, const char *const *args ATTR_UNUSED)
 {
        const char *error = NULL;
        if (!dcrypt_initialize("openssl", NULL, &error))
                i_fatal("dcrypt_initialize failed: %s", error);
-       (void)dcrypt_file_dump_metadata(argv[1], TRUE);
+       (void)dcrypt_file_dump_metadata(path, TRUE);
 }
 
 struct doveadm_cmd_dump doveadm_cmd_dump_dcrypt_file = {
index 9df2f17b5e9cfc8a1df7876e905768998a2da66d..cecd27f3d286b2f3c85ceee1e42649bf04bb88a4 100644 (file)
@@ -199,12 +199,13 @@ static bool test_dump_dcrypt_key(const char *path)
        return ret;
 }
 
-static void cmd_dump_dcrypt_key(int argc ATTR_UNUSED, char *argv[])
+static void
+cmd_dump_dcrypt_key(const char *path, const char *const *args ATTR_UNUSED)
 {
        const char *error = NULL;
        if (!dcrypt_initialize("openssl", NULL, &error))
                i_fatal("dcrypt_initialize: %s", error);
-       (void)dcrypt_key_dump_metadata(argv[1], TRUE);
+       (void)dcrypt_key_dump_metadata(path, TRUE);
 }
 
 struct doveadm_cmd_dump doveadm_cmd_dump_dcrypt_key = {
index c6648114372d4e5ca84906f86e35e5dbb5df2668..ec21406a4fef5bd9cabc5baa310315887fc39d23 100644 (file)
@@ -764,20 +764,21 @@ static struct mail_index *path_open_index(const char *path)
                return mail_index_alloc(NULL, ".", path);
 }
 
-static void cmd_dump_index(int argc ATTR_UNUSED, char *argv[])
+static void
+cmd_dump_index(const char *path, const char *const *args)
 {
        struct mail_index *index;
        struct mail_index_view *view;
        struct mail_cache_view *cache_view;
        unsigned int seq, uid = 0;
 
-       index = path_open_index(argv[1]);
+       index = path_open_index(path);
        if (index == NULL ||
            mail_index_open(index, MAIL_INDEX_OPEN_FLAG_READONLY) <= 0)
-               i_fatal("Couldn't open index %s", argv[1]);
-       if (argv[2] != NULL) {
-               if (str_to_uint(argv[2], &uid) < 0)
-                       i_fatal("Invalid uid number %s", argv[2]);
+               i_fatal("Couldn't open index %s", path);
+       if (args[0] != NULL) {
+               if (str_to_uint(args[0], &uid) < 0)
+                       i_fatal("Invalid uid number %s", args[0]);
        }
 
        view = mail_index_view_open(index);
index 4c1f6eef3bce5aa9d25228e757691fa1f752104b..0725b289ee038fc825a2490d9d29bdbb86d54006 100644 (file)
@@ -518,14 +518,14 @@ static int dump_record(struct istream *input, uint64_t *modseq,
        return 1;
 }
 
-static void cmd_dump_log(int argc ATTR_UNUSED, char *argv[])
+static void cmd_dump_log(const char *path, const char *const *args ATTR_UNUSED)
 {
        struct istream *input;
        uint64_t modseq;
        unsigned int version;
        int ret;
 
-       input = i_stream_create_file(argv[1], SIZE_MAX);
+       input = i_stream_create_file(path, SIZE_MAX);
        dump_hdr(input, &modseq, &version);
        do {
                T_BEGIN {
index 4f66da52e394213bd06e761e6e91a574589309b8..8ff5a5417634cbf4d3a3e9932409844d2b80a75a 100644 (file)
@@ -57,13 +57,14 @@ static int dump_record(int fd)
        return 1;
 }
 
-static void cmd_dump_mailboxlog(int argc ATTR_UNUSED, char *argv[])
+static void
+cmd_dump_mailboxlog(const char *path, const char *const *args ATTR_UNUSED)
 {
        int fd, ret;
 
-       fd = open(argv[1], O_RDONLY);
+       fd = open(path, O_RDONLY);
        if (fd < 0)
-               i_fatal("open(%s) failed: %m", argv[1]);
+               i_fatal("open(%s) failed: %m", path);
 
        do {
                T_BEGIN {
index e5d32b90e45c4f167cc21297e3a3e4f1548b9809..026b07fdb2ecbc65ddf9aa8183c0e2062c654ef1 100644 (file)
@@ -91,7 +91,8 @@ static int dump_block(const uint8_t *data, const uint8_t *end, uint32_t *uid)
        return p - data;
 }
 
-static void cmd_dump_thread(int argc ATTR_UNUSED, char *argv[])
+static void
+cmd_dump_thread(const char *path, const char *const *args ATTR_UNUSED)
 {
        unsigned int pos;
        const void *map, *end;
@@ -99,12 +100,12 @@ static void cmd_dump_thread(int argc ATTR_UNUSED, char *argv[])
        uint32_t uid;
        int fd, ret;
 
-       fd = open(argv[1], O_RDONLY);
+       fd = open(path, O_RDONLY);
        if (fd < 0)
-               i_fatal("open(%s) failed: %m", argv[1]);
+               i_fatal("open(%s) failed: %m", path);
 
        if (fstat(fd, &st) < 0)
-               i_fatal("fstat(%s) failed: %m", argv[1]);
+               i_fatal("fstat(%s) failed: %m", path);
        max_likely_index = (st.st_size / 8) * 2;
 
        map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
index 21966cbc09129fb323ab078bbffd3b733a81a745..1872931a3daf928c3506940bae05a640ec75acaf 100644 (file)
@@ -76,14 +76,15 @@ static void cmd_dump(int argc, char *argv[])
                if (type == NULL)
                        printf("Detected file type: %s\n", dump->name);
        }
-       dump->cmd(argc, argv);
+       dump->cmd(argv[1], (const char *const *)argv+2);
 }
 
 struct doveadm_cmd doveadm_cmd_dump = {
-       cmd_dump, "dump", "[-t <type>] <path>"
+       cmd_dump, "dump", "[-t <type>] <path> [<type-specific args>]"
 };
 
-static void cmd_dump_multiplex(int argc ATTR_UNUSED, char *argv[])
+static void
+cmd_dump_multiplex(const char *path, const char *const *args ATTR_UNUSED)
 {
        const unsigned int channels_count = 256;
        struct istream *file_input, *channels[channels_count];
@@ -91,7 +92,7 @@ static void cmd_dump_multiplex(int argc ATTR_UNUSED, char *argv[])
        size_t size;
        unsigned int i;
 
-       file_input = i_stream_create_file(argv[1], IO_BLOCK_SIZE);
+       file_input = i_stream_create_file(path, IO_BLOCK_SIZE);
        /* A bit kludgy: istream-multiplex returns 0 if a wrong channel is
           being read from. This causes a panic with blocking istreams.
           Work around this by assuming that the file istream isn't blocking. */
index c6cbc431ae7651cb2de61982bb2d8018990759bc..57762609ca41cbf6b1b20ea8020a1dfba09acc2c 100644 (file)
@@ -6,7 +6,7 @@
 struct doveadm_cmd_dump {
        const char *name;
        bool (*test)(const char *path);
-       doveadm_command_t *cmd;
+       void (*cmd)(const char *path, const char *const *args);
 };
 
 extern struct doveadm_cmd_dump doveadm_cmd_dump_dbox;
index a730561169db5c8b681e2145f1ed3ef126034359..f9bb233c64c42ebbf2a89848ee6b365c046d2823 100644 (file)
@@ -42,7 +42,8 @@ static bool test_dump_imapzlib(const char *path)
 }
 
 #ifdef HAVE_ZLIB
-static void cmd_dump_imapzlib(int argc ATTR_UNUSED, char *argv[])
+static void
+cmd_dump_imapzlib(const char *path, const char *const *args ATTR_UNUSED)
 {
        struct istream *input, *input2;
        const unsigned char *data;
@@ -50,9 +51,9 @@ static void cmd_dump_imapzlib(int argc ATTR_UNUSED, char *argv[])
        const char *line;
        int fd;
 
-       fd = open(argv[1], O_RDONLY);
+       fd = open(path, O_RDONLY);
        if (fd < 0)
-               i_fatal("open(%s) failed: %m", argv[1]);
+               i_fatal("open(%s) failed: %m", path);
        input = i_stream_create_fd_autoclose(&fd, 1024*32);
        while ((line = i_stream_read_next_line(input)) != NULL) {
                /* skip tag */
@@ -75,10 +76,8 @@ static void cmd_dump_imapzlib(int argc ATTR_UNUSED, char *argv[])
                        break;
                i_stream_skip(input2, size);
        }
-       if (input2->stream_errno != 0) {
-               i_error("read(%s) failed: %s",
-                       argv[1], i_stream_get_error(input));
-       }
+       if (input2->stream_errno != 0)
+               i_error("read(%s) failed: %s", path, i_stream_get_error(input));
        i_stream_unref(&input2);
        fflush(stdout);
 }
@@ -268,7 +267,9 @@ static void cmd_zlibconnect(struct doveadm_cmd_context *cctx)
                i_fatal("close() failed: %m");
 }
 #else
-static void cmd_dump_imapzlib(int argc ATTR_UNUSED, char *argv[] ATTR_UNUSED)
+static void
+cmd_dump_imapzlib(const char *path ATTR_UNUSED,
+                 const char *const *args ATTR_UNUSED)
 {
        i_fatal("Dovecot compiled without zlib support");
 }
index 136d4100ba96829330cc8d3dc8df0b657861830b..a761907009fddc332e5d94bf3c99b0b84678d990 100644 (file)
@@ -13,7 +13,8 @@ const char *doveadm_fts_lucene_plugin_version = DOVECOT_ABI_VERSION;
 void doveadm_fts_lucene_plugin_init(struct module *module);
 void doveadm_fts_lucene_plugin_deinit(void);
 
-static void cmd_dump_fts_lucene(int argc ATTR_UNUSED, char *argv[])
+static void
+cmd_dump_fts_lucene(const char *path, const char *const *args ATTR_UNUSED)
 {
        struct lucene_index *index;
        struct lucene_index_iter *iter;
@@ -22,7 +23,7 @@ static void cmd_dump_fts_lucene(int argc ATTR_UNUSED, char *argv[])
        bool first = TRUE;
 
        i_zero(&prev_guid);
-       index = lucene_index_init(argv[1], NULL, NULL);
+       index = lucene_index_init(path, NULL, NULL);
        iter = lucene_index_iter_init(index);
        while ((rec = lucene_index_iter_next(iter)) != NULL) {
                if (memcmp(prev_guid, rec->mailbox_guid,
index 9096daac59e2376fefb6c84ba0c5948c9494a251..7438bca8ad52bba68034352b6d87de702de14ed9 100644 (file)
@@ -73,14 +73,15 @@ static int dump_record(int fd, buffer_t *buf)
        return 1;
 }
 
-static void cmd_dump_fts_expunge_log(int argc ATTR_UNUSED, char *argv[])
+static void
+cmd_dump_fts_expunge_log(const char *path, const char *const *args ATTR_UNUSED)
 {
        buffer_t *buf;
        int fd, ret;
 
-       fd = open(argv[1], O_RDONLY);
+       fd = open(path, O_RDONLY);
        if (fd < 0)
-               i_fatal("open(%s) failed: %m", argv[1]);
+               i_fatal("open(%s) failed: %m", path);
 
        buf = buffer_create_dynamic(default_pool, 1024);
        do {