bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2010-2018 Dovecot authors, see the included COPYING file */
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainenstatic ARRAY(const struct doveadm_cmd_dump *) dumps;
134582c78f038b4d9b9fde127399aefa50935a53Timo Sirainenvoid doveadm_dump_register(const struct doveadm_cmd_dump *dump)
c664d0da658c8d3200d88ea3c4cd580afd33fa73Timo Sirainenstatic const struct doveadm_cmd_dump *
c664d0da658c8d3200d88ea3c4cd580afd33fa73Timo Sirainenstatic const struct doveadm_cmd_dump *
8fe0b13a23c5e98d090f94399581fe2c7b5239edTimo Sirainen if ((*dumpp)->test != NULL && (*dumpp)->test(path))
c664d0da658c8d3200d88ea3c4cd580afd33fa73Timo Sirainen dump = type != NULL ? dump_find_name(type) : dump_find_test(argv[1]);
5fbccc935e3f7b916aa7c6e302a212821072e83aTimo Sirainen i_fatal_status(EX_USAGE, "Unknown type: %s", type);
c664d0da658c8d3200d88ea3c4cd580afd33fa73Timo Sirainen printf("Detected file type: %s\n", dump->name);
b712b80422b22103c222132b4db9e00811dadeaeTimo Sirainenstatic void cmd_dump_multiplex(int argc ATTR_UNUSED, char *argv[])
b712b80422b22103c222132b4db9e00811dadeaeTimo Sirainen struct istream *file_input, *channels[channels_count];
b712b80422b22103c222132b4db9e00811dadeaeTimo Sirainen unsigned int i;
b712b80422b22103c222132b4db9e00811dadeaeTimo Sirainen file_input = i_stream_create_file(argv[1], IO_BLOCK_SIZE);
b712b80422b22103c222132b4db9e00811dadeaeTimo Sirainen /* A bit kludgy: istream-multiplex returns 0 if a wrong channel is
b712b80422b22103c222132b4db9e00811dadeaeTimo Sirainen being read from. This causes a panic with blocking istreams.
b712b80422b22103c222132b4db9e00811dadeaeTimo Sirainen Work around this by assuming that the file istream isn't blocking. */
b712b80422b22103c222132b4db9e00811dadeaeTimo Sirainen channels[0] = i_stream_create_multiplex(file_input, IO_BLOCK_SIZE);
b712b80422b22103c222132b4db9e00811dadeaeTimo Sirainen channels[i] = i_stream_multiplex_add_channel(channels[0], i);
b712b80422b22103c222132b4db9e00811dadeaeTimo Sirainen for (i = 0; i < channels_count; i++) {
b712b80422b22103c222132b4db9e00811dadeaeTimo Sirainen if (i_stream_read_more(channels[i], &data, &size) > 0) {
b712b80422b22103c222132b4db9e00811dadeaeTimo Sirainen i_error("read() failed: %s", i_stream_get_error(channels[0]));
b712b80422b22103c222132b4db9e00811dadeaeTimo Sirainen for (i = 0; i < channels_count; i++)
b712b80422b22103c222132b4db9e00811dadeaeTimo Sirainenstruct doveadm_cmd_dump doveadm_cmd_dump_multiplex = {
134582c78f038b4d9b9fde127399aefa50935a53Timo Sirainenstatic const struct doveadm_cmd_dump *dumps_builtin[] = {
4f77d2f0f0743ad09d2a34e18be8eacf8014b7e0Pascal Volk unsigned int i;
4f77d2f0f0743ad09d2a34e18be8eacf8014b7e0Pascal Volk fprintf(stderr, "Available dump types: %s", dumps_builtin[0]->name);
134582c78f038b4d9b9fde127399aefa50935a53Timo Sirainen unsigned int i;
134582c78f038b4d9b9fde127399aefa50935a53Timo Sirainen i_array_init(&dumps, N_ELEMENTS(dumps_builtin) + 8);
134582c78f038b4d9b9fde127399aefa50935a53Timo Sirainen for (i = 0; i < N_ELEMENTS(dumps_builtin); i++)