]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-dict, global: Add type safety to dict_lookup_async() callback context
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 23 Feb 2021 09:08:03 +0000 (11:08 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Thu, 4 Mar 2021 12:25:48 +0000 (12:25 +0000)
src/dict/dict-commands.c
src/doveadm/doveadm-dict.c
src/lib-dict/dict-client.c
src/lib-dict/dict.c
src/lib-dict/dict.h

index 2639e5d53a045464ce110ba5a32a9645668cc76f..f8d8ed2ad02b74f7690bbf55b34d5e4d2e2656dd 100644 (file)
@@ -193,9 +193,9 @@ cmd_lookup_write_reply(struct dict_connection_cmd *cmd,
 }
 
 static void
-cmd_lookup_callback(const struct dict_lookup_result *result, void *context)
+cmd_lookup_callback(const struct dict_lookup_result *result,
+                   struct dict_connection_cmd *cmd)
 {
-       struct dict_connection_cmd *cmd = context;
        string_t *str = t_str_new(128);
 
        event_set_name(cmd->event, "dict_server_lookup_finished");
index add069ccf909cde316cb96cb9b70b9b0060fca89..2e88a0c3884e0fb25a28624f1d1372cdfcfdb48d 100644 (file)
@@ -79,10 +79,8 @@ struct doveadm_dict_ctx {
 };
 
 static void dict_lookup_callback(const struct dict_lookup_result *result,
-                                void *context)
+                                struct doveadm_dict_ctx *ctx)
 {
-       struct doveadm_dict_ctx *ctx = context;
-
        ctx->ret = result->ret;
        ctx->values = result->values == NULL ? NULL :
                p_strarray_dup(ctx->pool, result->values);
index 546bcf4f9b597a25880a7af86b99df9ca6c00202..0aa61161286c667e3819901c7ac0de0047bb9936 100644 (file)
@@ -984,10 +984,8 @@ struct client_dict_sync_lookup {
 };
 
 static void client_dict_lookup_callback(const struct dict_lookup_result *result,
-                                       void *context)
+                                       struct client_dict_sync_lookup *lookup)
 {
-       struct client_dict_sync_lookup *lookup = context;
-
        lookup->ret = result->ret;
        if (result->ret == -1)
                lookup->error = i_strdup(result->error);
index d43e2e5072097ffa42a051b3ad181cdcfe29729c..7313a9ad62a624cdfc565eaa44a4e2d75e59e1ff 100644 (file)
@@ -311,6 +311,7 @@ int dict_lookup(struct dict *dict, pool_t pool, const char *key,
        return ret;
 }
 
+#undef dict_lookup_async
 void dict_lookup_async(struct dict *dict, const char *key,
                       dict_lookup_callback_t *callback, void *context)
 {
index ed9c1c36db3167cd7091c8d81937e958c58f112f..b7e46e685fa829344f9581f1498fbed2f040d3b6 100644 (file)
@@ -102,6 +102,11 @@ int dict_lookup(struct dict *dict, pool_t pool,
                const char *key, const char **value_r, const char **error_r);
 void dict_lookup_async(struct dict *dict, const char *key,
                       dict_lookup_callback_t *callback, void *context);
+#define dict_lookup_async(dict, key, callback, context) \
+       dict_lookup_async(dict, key, (dict_lookup_callback_t *)(callback), \
+               1 ? (context) : \
+               CALLBACK_TYPECHECK(callback, \
+                       void (*)(const struct dict_lookup_result *, typeof(context))))
 
 /* Iterate through all values in a path. flag indicates how iteration
    is carried out */