From: Timo Sirainen Date: Thu, 25 Nov 2021 10:59:48 +0000 (+0200) Subject: lib-dict: Add dict_lookup_values() X-Git-Tag: 2.4.0~4701 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fccf3c5679db8f49cb5e7299128ea333fc2f25b4;p=thirdparty%2Fdovecot%2Fcore.git lib-dict: Add dict_lookup_values() This is the same as dict_lookup(), except it returns all values instead of just the first. --- diff --git a/src/lib-dict/dict.c b/src/lib-dict/dict.c index a5e523adf3..1e8332812e 100644 --- a/src/lib-dict/dict.c +++ b/src/lib-dict/dict.c @@ -322,18 +322,28 @@ int dict_lookup(struct dict *dict, const struct dict_op_settings *set, pool_t pool, const char *key, const char **value_r, const char **error_r) { - struct event *event = dict_event_create(dict, set); const char *const *values; + int ret = dict_lookup_values(dict, set, pool, key, &values, error_r); + if (ret > 0) + *value_r = values[0]; + else if (ret == 0) + *value_r = NULL; + return ret; +} + +int dict_lookup_values(struct dict *dict, const struct dict_op_settings *set, + pool_t pool, const char *key, + const char *const **values_r, const char **error_r) +{ + struct event *event = dict_event_create(dict, set); int ret; i_assert(dict_key_prefix_is_valid(key, set->username)); e_debug(event, "Looking up '%s'", key); event_add_str(event, "key", key); - ret = dict->v.lookup(dict, set, pool, key, &values, error_r); - if (ret > 0) - *value_r = values[0]; - else if (ret == 0) - *value_r = NULL; + ret = dict->v.lookup(dict, set, pool, key, values_r, error_r); + if (ret == 0) + *values_r = NULL; dict_lookup_finished(event, ret, *error_r); event_unref(&event); return ret; diff --git a/src/lib-dict/dict.h b/src/lib-dict/dict.h index f4dbca19de..a985661eb2 100644 --- a/src/lib-dict/dict.h +++ b/src/lib-dict/dict.h @@ -100,10 +100,16 @@ bool dict_have_async_operations(struct dict *dict); be waited on. */ bool dict_switch_ioloop(struct dict *dict) ATTR_NOWARN_UNUSED_RESULT; -/* Lookup value for key. Set it to NULL if it's not found. +/* Lookup the first value for the key. Set it to NULL if it's not found. Returns 1 if found, 0 if not found and -1 if lookup failed. */ int dict_lookup(struct dict *dict, const struct dict_op_settings *set, pool_t pool, const char *key, const char **value_r, const char **error_r); +/* Lookup all the values for the key. Set it to NULL if it's not found. + Returns 1 if found, 0 if not found and -1 if lookup failed. */ +int dict_lookup_values(struct dict *dict, const struct dict_op_settings *set, + pool_t pool, const char *key, + const char *const **values_r, const char **error_r); +/* Asynchronously lookup values for the key. */ void dict_lookup_async(struct dict *dict, const struct dict_op_settings *set, const char *key, dict_lookup_callback_t *callback, void *context);