Mercurial > dovecot > core-2.2
changeset 19877:46bd6c155469
doveadm-cmd: Support non-strings in compat wrapper
author | Aki Tuomi <aki.tuomi@dovecot.fi> |
---|---|
date | Sat, 27 Feb 2016 11:13:24 +0200 |
parents | 68601371950b |
children | 35af085fea50 |
files | src/doveadm/doveadm-cmd.c |
diffstat | 1 files changed, 31 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/doveadm/doveadm-cmd.c Sun Feb 28 18:33:01 2016 +0200 +++ b/src/doveadm/doveadm-cmd.c Sat Feb 27 11:13:24 2016 +0200 @@ -287,28 +287,42 @@ doveadm_cmd_params_to_argv(const char *name, int pargc, const struct doveadm_cmd_param* params, ARRAY_TYPE(const_string) *argv) { + bool array_add_opt; int i; const char * const * cptr; i_assert(array_count(argv) == 0); array_append(argv, &name, 1); for(i=0;i<pargc;i++) { - if (params[i].value_set && params[i].short_opt != '\0') { - const char *optarg = t_strdup_printf("-%c", params[i].short_opt); + const char *optarg = NULL; + /* istreams are special */ + i_assert(params[i].type != CMD_PARAM_ISTREAM); + if (params[i].value_set) { + array_add_opt = FALSE; + if (params[i].short_opt != '\0') { + if (params[i].type == CMD_PARAM_ARRAY) { + array_add_opt = TRUE; + } else { + optarg = t_strdup_printf("-%c", params[i].short_opt); + array_append(argv, &optarg, 1); + } + } + /* CMD_PARAM_BOOL is implicitly handled above */ if (params[i].type == CMD_PARAM_STR) { - array_append(argv, &optarg, 1); array_append(argv, ¶ms[i].value.v_string,1); + } else if (params[i].type == CMD_PARAM_INT64) { + const char *tmp = t_strdup_printf("%lld", + (long long)params[i].value.v_int64); + array_append(argv, &tmp, 1); + } else if (params[i].type == CMD_PARAM_IP) { + const char *tmp = net_ip2addr(¶ms[i].value.v_ip); + array_append(argv, &tmp, 1); } else if (params[i].type == CMD_PARAM_ARRAY) { array_foreach(¶ms[i].value.v_array, cptr) { - array_append(argv, &optarg, 1); + if (array_add_opt) + array_append(argv, &optarg, 1); array_append(argv, cptr, 1); } } - } else if (params[i].value_set) { - if (params[i].type == CMD_PARAM_ARRAY) { - array_append_array(argv, ¶ms[i].value.v_array); - } else { - array_append(argv, ¶ms[i].value.v_string,1); - } } } array_append_zero(argv); @@ -437,7 +451,12 @@ while((c = getopt_long(argc, (char*const*)argv, str_c(optbuf), array_idx(&opts, 0), &li)) > -1) { switch(c) { case 0: - doveadm_fill_param(array_idx_modifiable(&pargv,li), optarg, pool); + for(unsigned int i = 0; i < array_count(&pargv); i++) { + const struct option *opt = array_idx(&opts,li); + param = array_idx_modifiable(&pargv,i); + if (opt->name == param->name) + doveadm_fill_param(param, optarg, pool); + } break; case '?': case ':': @@ -457,7 +476,7 @@ while((cptr = strchr(cptr+1, ' ')) != NULL) optind++; /* process positional arguments */ - for(;optind<cctx->argc;optind++) { + for(;optind<argc;optind++) { struct doveadm_cmd_param *ptr; bool found = FALSE; array_foreach_modifiable(&pargv, ptr) {