static void cmd_dict_iter(int argc, char *argv[]) { struct dict *dict; struct dict_iterate_context *iter; enum dict_iterate_flags iter_flags = 0; const char *key, *value; dict = cmd_dict_init_full(&argc, &argv, 1, 0, cmd_dict_iter, &iter_flags); doveadm_print_init(DOVEADM_PRINT_TYPE_TAB); doveadm_print_header_simple("key"); if ((iter_flags & DICT_ITERATE_FLAG_NO_VALUE) == 0) doveadm_print_header_simple("value"); iter = dict_iterate_init(dict, argv[0], iter_flags); while (dict_iterate(iter, &key, &value)) { doveadm_print(key); if ((iter_flags & DICT_ITERATE_FLAG_NO_VALUE) == 0) doveadm_print(value); } if (dict_iterate_deinit(&iter) < 0) { i_error("dict_iterate_deinit(%s) failed", argv[0]); doveadm_exit_code = EX_TEMPFAIL; } dict_deinit(&dict); }
static struct userdb_iterate_context * userdb_dict_iterate_init(struct auth_request *auth_request, userdb_iter_callback_t *callback, void *context) { struct userdb_module *_module = auth_request->userdb->userdb; struct dict_userdb_module *module = (struct dict_userdb_module *)_module; struct dict_userdb_iterate_context *ctx; string_t *path; const char *error; ctx = i_new(struct dict_userdb_iterate_context, 1); ctx->ctx.auth_request = auth_request; ctx->ctx.callback = callback; ctx->ctx.context = context; auth_request_ref(auth_request); if (*module->conn->set.iterate_prefix == '\0') { if (!module->conn->set.iterate_disable) { auth_request_log_error(auth_request, AUTH_SUBSYS_DB, "iterate: iterate_prefix not set"); ctx->ctx.failed = TRUE; } return &ctx->ctx; } path = t_str_new(128); str_append(path, DICT_PATH_SHARED); if (auth_request_var_expand(path, module->conn->set.iterate_prefix, auth_request, NULL, &error) <= 0) { auth_request_log_error(auth_request, AUTH_SUBSYS_DB, "Failed to expand iterate_prefix=%s: %s", module->conn->set.iterate_prefix, error); ctx->ctx.failed = TRUE; return &ctx->ctx; } ctx->key_prefix = p_strdup(auth_request->pool, str_c(path)); ctx->key_prefix_len = strlen(ctx->key_prefix); ctx->iter = dict_iterate_init(module->conn->dict, ctx->key_prefix, 0); auth_request_log_debug(auth_request, AUTH_SUBSYS_DB, "iterate: prefix=%s", ctx->key_prefix); return &ctx->ctx; }
struct mailbox_attribute_iter * index_storage_attribute_iter_init(struct mailbox *box, enum mail_attribute_type type, const char *prefix) { struct index_storage_attribute_iter *iter; struct dict *dict; const char *mailbox_prefix; iter = i_new(struct index_storage_attribute_iter, 1); iter->iter.box = box; if (index_storage_get_dict(box, type, &dict, &mailbox_prefix) < 0) { if (mailbox_get_last_mail_error(box) == MAIL_ERROR_NOTPOSSIBLE) iter->dict_disabled = TRUE; } else { iter->prefix = i_strdup(key_get_prefixed(type, mailbox_prefix, prefix)); iter->prefix_len = strlen(iter->prefix); iter->diter = dict_iterate_init(dict, iter->prefix, DICT_ITERATE_FLAG_RECURSE | DICT_ITERATE_FLAG_NO_VALUE); } return &iter->iter; }