]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-dict: Add support for lookup to return multiple values
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 12 Jan 2017 18:22:38 +0000 (20:22 +0200)
committerGitLab <gitlab@git.dovecot.net>
Sun, 15 Jan 2017 00:10:11 +0000 (02:10 +0200)
Implements only the initial stubs to the drivers.

src/lib-dict/dict-client.c
src/lib-dict/dict-sql.c
src/lib-dict/dict.c
src/lib-dict/dict.h
src/plugins/dict-ldap/dict-ldap.c

index b9cead612f42f62536caeaa87ce47c0dc583e76a..a72506c53de6e392333b17b891418ea515664393 100644 (file)
@@ -926,6 +926,7 @@ client_dict_lookup_async_callback(struct client_dict_cmd *cmd,
 {
        struct client_dict *dict = cmd->dict;
        struct dict_lookup_result result;
+       const char *const values[] = { value, NULL };
 
        i_zero(&result);
        if (error != NULL) {
@@ -934,6 +935,7 @@ client_dict_lookup_async_callback(struct client_dict_cmd *cmd,
        } else switch (reply) {
        case DICT_PROTOCOL_REPLY_OK:
                result.value = value;
+               result.values = values;
                result.ret = 1;
                break;
        case DICT_PROTOCOL_REPLY_NOTFOUND:
index b1000c56a292736bbfd1e9bfd7382eedef89553e..54a91c9d824b1dfaac13c3d33b913e1fb6cf11cf 100644 (file)
@@ -467,6 +467,7 @@ sql_dict_lookup_async_callback(struct sql_result *sql_result,
                               struct sql_dict_lookup_context *ctx)
 {
        struct dict_lookup_result result;
+       const char *values[2] = { NULL, NULL };
 
        i_zero(&result);
        result.ret = sql_result_next_row(sql_result);
@@ -480,6 +481,9 @@ sql_dict_lookup_async_callback(struct sql_result *sql_result,
                           "not found", which is probably what is usually
                           wanted. */
                        result.ret = 0;
+               } else {
+                       values[0] = result.value;
+                       result.values = values;
                }
        }
        ctx->callback(&result, ctx->context);
index 5e660454ef3c4a1ae48922d8a84bd35441c80010..bfefc0f1772551cbc8ddf141a43ba7001ef97be2 100644 (file)
@@ -131,6 +131,8 @@ void dict_lookup_async(struct dict *dict, const char *key,
                i_zero(&result);
                result.ret = dict_lookup(dict, pool_datastack_create(),
                                         key, &result.value, &result.error);
+               const char *const values[] = { result.value, NULL };
+               result.values = values;
                callback(&result, context);
                return;
        }
index 05d1bfea2a53f11ee62b42716f9c75ab9380854e..ee864ef4ab2011d3e6eccd3c33ce108a5064ef13 100644 (file)
@@ -40,7 +40,13 @@ struct dict_settings {
 
 struct dict_lookup_result {
        int ret;
+
+       /* First returned value (ret > 0) */
        const char *value;
+       /* NULL-terminated list of all returned values (ret > 0) */
+       const char *const *values;
+
+       /* Error message for a failed lookup (ret < 0) */
        const char *error;
 };
 
index 4d60e51f323b2b4b0d23b1b64348e753f5681ffd..bb7faff7b392b8f878907c6ecc506decf4fa8f11 100644 (file)
@@ -299,10 +299,15 @@ ldap_dict_lookup_callback(struct ldap_result *result, struct dict_ldap_op *op)
                        /* try extract value */
                        const char *const *values = ldap_entry_get_attribute(entry, op->map->value_attribute);
                        if (values != NULL) {
+                               const char **new_values;
+
                                if (op->dict->set->debug > 0)
                                        i_debug("ldap_dict_lookup_callback got attribute %s", op->map->value_attribute);
                                op->res.ret = 1;
-                               op->res.value = p_strdup(op->pool, values[0]);
+                               new_values = p_new(op->pool, const char *, 2);
+                               new_values[0] = p_strdup(op->pool, values[0]);
+                               op->res.values = new_values;
+                               op->res.value = op->res.values[0];
                        } else {
                                if (op->dict->set->debug > 0)
                                        i_debug("ldap_dict_lookup_callback dit not get attribute %s", op->map->value_attribute);