]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-dict: Add dict_lookup_values()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 25 Nov 2021 10:59:48 +0000 (12:59 +0200)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Mon, 17 Jan 2022 11:52:09 +0000 (13:52 +0200)
This is the same as dict_lookup(), except it returns all values instead of
just the first.

src/lib-dict/dict.c
src/lib-dict/dict.h

index a5e523adf353dafa8e0d56daf6d070534ad24f76..1e8332812e5b326ce6601467a8c72e69aabe208d 100644 (file)
@@ -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;
index f4dbca19de001cd45e2bbb7e1a7a8151c8a86626..a985661eb290262add9e2aafdeecf6117fadd169 100644 (file)
@@ -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);