From: Timo Sirainen Date: Wed, 9 Jun 2021 20:10:08 +0000 (+0300) Subject: doveadm dump: Change doveadm_cmd_dump.cmd() API to be simpler X-Git-Tag: 2.3.17~319 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4a508ba07a911f3f1f8c19b6b10c25306f01ca09;p=thirdparty%2Fdovecot%2Fcore.git doveadm dump: Change doveadm_cmd_dump.cmd() API to be simpler --- diff --git a/src/doveadm/doveadm-dump-dbox.c b/src/doveadm/doveadm-dump-dbox.c index e17fcade39..429b4a15f4 100644 --- a/src/doveadm/doveadm-dump-dbox.c +++ b/src/doveadm/doveadm-dump-dbox.c @@ -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"); diff --git a/src/doveadm/doveadm-dump-dcrypt-file.c b/src/doveadm/doveadm-dump-dcrypt-file.c index 539919beab..3703bf488e 100644 --- a/src/doveadm/doveadm-dump-dcrypt-file.c +++ b/src/doveadm/doveadm-dump-dcrypt-file.c @@ -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 = { diff --git a/src/doveadm/doveadm-dump-dcrypt-key.c b/src/doveadm/doveadm-dump-dcrypt-key.c index 9df2f17b5e..cecd27f3d2 100644 --- a/src/doveadm/doveadm-dump-dcrypt-key.c +++ b/src/doveadm/doveadm-dump-dcrypt-key.c @@ -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 = { diff --git a/src/doveadm/doveadm-dump-index.c b/src/doveadm/doveadm-dump-index.c index c664811437..ec21406a4f 100644 --- a/src/doveadm/doveadm-dump-index.c +++ b/src/doveadm/doveadm-dump-index.c @@ -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); diff --git a/src/doveadm/doveadm-dump-log.c b/src/doveadm/doveadm-dump-log.c index 4c1f6eef3b..0725b289ee 100644 --- a/src/doveadm/doveadm-dump-log.c +++ b/src/doveadm/doveadm-dump-log.c @@ -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 { diff --git a/src/doveadm/doveadm-dump-mailboxlog.c b/src/doveadm/doveadm-dump-mailboxlog.c index 4f66da52e3..8ff5a54176 100644 --- a/src/doveadm/doveadm-dump-mailboxlog.c +++ b/src/doveadm/doveadm-dump-mailboxlog.c @@ -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 { diff --git a/src/doveadm/doveadm-dump-thread.c b/src/doveadm/doveadm-dump-thread.c index e5d32b90e4..026b07fdb2 100644 --- a/src/doveadm/doveadm-dump-thread.c +++ b/src/doveadm/doveadm-dump-thread.c @@ -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); diff --git a/src/doveadm/doveadm-dump.c b/src/doveadm/doveadm-dump.c index 21966cbc09..1872931a3d 100644 --- a/src/doveadm/doveadm-dump.c +++ b/src/doveadm/doveadm-dump.c @@ -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 ] " + cmd_dump, "dump", "[-t ] []" }; -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. */ diff --git a/src/doveadm/doveadm-dump.h b/src/doveadm/doveadm-dump.h index c6cbc431ae..57762609ca 100644 --- a/src/doveadm/doveadm-dump.h +++ b/src/doveadm/doveadm-dump.h @@ -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; diff --git a/src/doveadm/doveadm-zlib.c b/src/doveadm/doveadm-zlib.c index a730561169..f9bb233c64 100644 --- a/src/doveadm/doveadm-zlib.c +++ b/src/doveadm/doveadm-zlib.c @@ -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"); } diff --git a/src/plugins/fts-lucene/doveadm-fts-lucene.c b/src/plugins/fts-lucene/doveadm-fts-lucene.c index 136d4100ba..a761907009 100644 --- a/src/plugins/fts-lucene/doveadm-fts-lucene.c +++ b/src/plugins/fts-lucene/doveadm-fts-lucene.c @@ -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, diff --git a/src/plugins/fts/doveadm-dump-fts-expunge-log.c b/src/plugins/fts/doveadm-dump-fts-expunge-log.c index 9096daac59..7438bca8ad 100644 --- a/src/plugins/fts/doveadm-dump-fts-expunge-log.c +++ b/src/plugins/fts/doveadm-dump-fts-expunge-log.c @@ -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 {