doveadm-mail-batch.c (dovecot-2.3.16) | : | doveadm-mail-batch.c (dovecot-2.3.17) | ||
---|---|---|---|---|
skipping to change at line 58 | skipping to change at line 58 | |||
} | } | |||
return ret; | return ret; | |||
} | } | |||
static void | static void | |||
cmd_batch_add(struct batch_cmd_context *batchctx, | cmd_batch_add(struct batch_cmd_context *batchctx, | |||
int argc, const char *const *argv) | int argc, const char *const *argv) | |||
{ | { | |||
struct doveadm_mail_cmd_context *subctx; | struct doveadm_mail_cmd_context *subctx; | |||
const struct doveadm_cmd_ver2 *cmd_ver2; | const struct doveadm_cmd_ver2 *cmd_ver2; | |||
struct doveadm_mail_cmd tmpcmd; | ||||
const struct doveadm_mail_cmd *cmd; | const struct doveadm_mail_cmd *cmd; | |||
const char *getopt_args; | const char *getopt_args; | |||
int c; | int c; | |||
cmd_ver2 = doveadm_cmd_find_with_args_ver2(argv[0], &argc, &argv); | cmd_ver2 = doveadm_cmd_find_with_args_ver2(argv[0], &argc, &argv); | |||
if (cmd_ver2 == NULL) | if (cmd_ver2 == NULL) | |||
cmd = doveadm_mail_cmd_find_from_argv(argv[0], &argc, &argv); | ||||
else { | ||||
i_zero(&tmpcmd); | ||||
tmpcmd.usage_args = cmd_ver2->usage; | ||||
tmpcmd.name = cmd_ver2->name; | ||||
tmpcmd.alloc = cmd_ver2->mail_cmd; | ||||
cmd = &tmpcmd; | ||||
} | ||||
if (cmd == NULL) | ||||
i_fatal_status(EX_USAGE, "doveadm batch: '%s' mail command doesn' t exist", argv[0]); | i_fatal_status(EX_USAGE, "doveadm batch: '%s' mail command doesn' t exist", argv[0]); | |||
struct doveadm_mail_cmd *dyncmd = | ||||
p_new(batchctx->ctx.pool, struct doveadm_mail_cmd, 1); | ||||
dyncmd->usage_args = cmd_ver2->usage; | ||||
dyncmd->name = cmd_ver2->name; | ||||
dyncmd->alloc = cmd_ver2->mail_cmd; | ||||
cmd = dyncmd; | ||||
subctx = doveadm_mail_cmd_init(cmd, doveadm_settings); | subctx = doveadm_mail_cmd_init(cmd, doveadm_settings); | |||
subctx->full_args = argv + 1; | subctx->full_args = argv + 1; | |||
subctx->service_flags |= batchctx->ctx.service_flags; | subctx->service_flags |= batchctx->ctx.service_flags; | |||
i_getopt_reset(); | i_getopt_reset(); | |||
getopt_args = subctx->getopt_args != NULL ? subctx->getopt_args : ""; | getopt_args = subctx->getopt_args != NULL ? subctx->getopt_args : ""; | |||
while ((c = getopt(argc, (void *)argv, getopt_args)) > 0) { | while ((c = getopt(argc, (void *)argv, getopt_args)) > 0) { | |||
if (subctx->v.parse_arg == NULL || | if (subctx->v.parse_arg == NULL || | |||
!subctx->v.parse_arg(subctx, c)) | !subctx->v.parse_arg(subctx, c)) | |||
doveadm_mail_help(cmd); | doveadm_mail_help(cmd); | |||
skipping to change at line 157 | skipping to change at line 152 | |||
subctx->ctx.v.init(&subctx->ctx, subctx->ctx.args); | subctx->ctx.v.init(&subctx->ctx, subctx->ctx.args); | |||
} | } | |||
} | } | |||
static void cmd_batch_deinit(struct doveadm_mail_cmd_context *_ctx) | static void cmd_batch_deinit(struct doveadm_mail_cmd_context *_ctx) | |||
{ | { | |||
struct batch_cmd_context *ctx = (struct batch_cmd_context *)_ctx; | struct batch_cmd_context *ctx = (struct batch_cmd_context *)_ctx; | |||
struct doveadm_mail_cmd_context *cmd; | struct doveadm_mail_cmd_context *cmd; | |||
array_foreach_elem(&ctx->commands, cmd) { | array_foreach_elem(&ctx->commands, cmd) { | |||
if (cmd->v.deinit != NULL) | doveadm_mail_cmd_deinit(cmd); | |||
cmd->v.deinit(cmd); | doveadm_mail_cmd_free(cmd); | |||
} | } | |||
} | } | |||
static struct doveadm_mail_cmd_context *cmd_batch_alloc(void) | static struct doveadm_mail_cmd_context *cmd_batch_alloc(void) | |||
{ | { | |||
struct batch_cmd_context *ctx; | struct batch_cmd_context *ctx; | |||
ctx = doveadm_mail_cmd_alloc(struct batch_cmd_context); | ctx = doveadm_mail_cmd_alloc(struct batch_cmd_context); | |||
ctx->ctx.getopt_args = "+"; /* disable processing -args in the middle */ | ctx->ctx.getopt_args = "+"; /* disable processing -args in the middle */ | |||
ctx->ctx.v.preinit = cmd_batch_preinit; | ctx->ctx.v.preinit = cmd_batch_preinit; | |||
ctx->ctx.v.init = cmd_batch_init; | ctx->ctx.v.init = cmd_batch_init; | |||
ctx->ctx.v.prerun = cmd_batch_prerun; | ctx->ctx.v.prerun = cmd_batch_prerun; | |||
ctx->ctx.v.run = cmd_batch_run; | ctx->ctx.v.run = cmd_batch_run; | |||
ctx->ctx.v.deinit = cmd_batch_deinit; | ctx->ctx.v.deinit = cmd_batch_deinit; | |||
return &ctx->ctx; | return &ctx->ctx; | |||
} | } | |||
struct doveadm_mail_cmd cmd_batch = { | struct doveadm_cmd_ver2 doveadm_cmd_batch = { | |||
cmd_batch_alloc, "batch", "<sep> <cmd1> [<sep> <cmd2> [..]]" | .name = "batch", | |||
.mail_cmd = cmd_batch_alloc, | ||||
.usage = "<sep> <cmd1> [<sep> <cmd2> [..]]", | ||||
.flags = CMD_FLAG_NO_UNORDERED_OPTIONS, | ||||
DOVEADM_CMD_PARAMS_START | ||||
DOVEADM_CMD_MAIL_COMMON | ||||
DOVEADM_CMD_PARAM('\0', "separator", CMD_PARAM_STR, CMD_PARAM_FLAG_POSITIONAL) | ||||
DOVEADM_CMD_PARAM('\0', "args", CMD_PARAM_ARRAY, CMD_PARAM_FLAG_POSITIONAL) | ||||
DOVEADM_CMD_PARAMS_END | ||||
}; | }; | |||
End of changes. 6 change blocks. | ||||
16 lines changed or deleted | 19 lines changed or added |