doveadm-dump.c (dovecot-2.3.16) | : | doveadm-dump.c (dovecot-2.3.17) | ||
---|---|---|---|---|
skipping to change at line 44 | skipping to change at line 44 | |||
{ | { | |||
const struct doveadm_cmd_dump *dump; | const struct doveadm_cmd_dump *dump; | |||
array_foreach_elem(&dumps, dump) { | array_foreach_elem(&dumps, dump) { | |||
if (dump->test != NULL && dump->test(path)) | if (dump->test != NULL && dump->test(path)) | |||
return dump; | return dump; | |||
} | } | |||
return NULL; | return NULL; | |||
} | } | |||
static void cmd_dump(int argc, char *argv[]) | static void cmd_dump(struct doveadm_cmd_context *cctx) | |||
{ | { | |||
const struct doveadm_cmd_dump *dump; | const struct doveadm_cmd_dump *dump; | |||
const char *type = NULL; | const char *path, *type = NULL, *const *args = NULL; | |||
int c; | const char *no_args = NULL; | |||
while ((c = getopt(argc, argv, "t:")) > 0) { | if (!doveadm_cmd_param_str(cctx, "path", &path)) | |||
switch (c) { | help_ver2(&doveadm_cmd_dump); | |||
case 't': | (void)doveadm_cmd_param_str(cctx, "type", &type); | |||
type = optarg; | (void)doveadm_cmd_param_array(cctx, "args", &args); | |||
break; | ||||
default: | ||||
help(&doveadm_cmd_dump); | ||||
} | ||||
} | ||||
if (optind == argc) | ||||
help(&doveadm_cmd_dump); | ||||
optind--; | ||||
argc -= optind; | ||||
argv += optind; | ||||
dump = type != NULL ? dump_find_name(type) : dump_find_test(argv[1]); | dump = type != NULL ? dump_find_name(type) : dump_find_test(path); | |||
if (dump == NULL) { | if (dump == NULL) { | |||
if (type != NULL) { | if (type != NULL) { | |||
print_dump_types(); | print_dump_types(); | |||
i_fatal_status(EX_USAGE, "Unknown type: %s", type); | i_fatal_status(EX_USAGE, "Unknown type: %s", type); | |||
} else { | } else { | |||
i_fatal_status(EX_DATAERR, | i_fatal_status(EX_DATAERR, | |||
"Can't autodetect file type: %s", argv[1]); | "Can't autodetect file type: %s", path); | |||
} | } | |||
} else { | } else { | |||
if (type == NULL) | if (type == NULL) | |||
printf("Detected file type: %s\n", dump->name); | printf("Detected file type: %s\n", dump->name); | |||
} | } | |||
dump->cmd(argc, argv); | dump->cmd(path, args != NULL ? args : &no_args); | |||
} | } | |||
struct doveadm_cmd doveadm_cmd_dump = { | struct doveadm_cmd_ver2 doveadm_cmd_dump = { | |||
cmd_dump, "dump", "[-t <type>] <path>" | .name = "dump", | |||
.cmd = cmd_dump, | ||||
.usage = "[-t <type>] <path> [<type-specific args>]", | ||||
DOVEADM_CMD_PARAMS_START | ||||
DOVEADM_CMD_PARAM('t', "type", CMD_PARAM_STR, 0) | ||||
DOVEADM_CMD_PARAM('\0', "path", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | ||||
DOVEADM_CMD_PARAM('\0', "args", CMD_PARAM_ARRAY, CMD_PARAM_FLAG_POSITIONAL) | ||||
DOVEADM_CMD_PARAMS_END | ||||
}; | }; | |||
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; | const unsigned int channels_count = 256; | |||
struct istream *file_input, *channels[channels_count]; | struct istream *file_input, *channels[channels_count]; | |||
const unsigned char *data; | const unsigned char *data; | |||
size_t size; | size_t size; | |||
unsigned int i; | 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 | /* A bit kludgy: istream-multiplex returns 0 if a wrong channel is | |||
being read from. This causes a panic with blocking istreams. | being read from. This causes a panic with blocking istreams. | |||
Work around this by assuming that the file istream isn't blocking. */ | Work around this by assuming that the file istream isn't blocking. */ | |||
file_input->blocking = FALSE; | file_input->blocking = FALSE; | |||
channels[0] = i_stream_create_multiplex(file_input, IO_BLOCK_SIZE); | channels[0] = i_stream_create_multiplex(file_input, IO_BLOCK_SIZE); | |||
i_stream_unref(&file_input); | i_stream_unref(&file_input); | |||
for (i = 1; i < channels_count; i++) | for (i = 1; i < channels_count; i++) | |||
channels[i] = i_stream_multiplex_add_channel(channels[0], i); | channels[i] = i_stream_multiplex_add_channel(channels[0], i); | |||
End of changes. 9 change blocks. | ||||
25 lines changed or deleted | 22 lines changed or added |