From 46cc92aa6c3a9c36616f4a5bddfb661c49967d3f Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Tue, 23 Feb 2021 11:08:03 +0200 Subject: [PATCH] lib-dict, global: Add type safety to dict_lookup_async() callback context --- src/dict/dict-commands.c | 4 ++-- src/doveadm/doveadm-dict.c | 4 +--- src/lib-dict/dict-client.c | 4 +--- src/lib-dict/dict.c | 1 + src/lib-dict/dict.h | 5 +++++ 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/dict/dict-commands.c b/src/dict/dict-commands.c index 2639e5d53a..f8d8ed2ad0 100644 --- a/src/dict/dict-commands.c +++ b/src/dict/dict-commands.c @@ -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"); diff --git a/src/doveadm/doveadm-dict.c b/src/doveadm/doveadm-dict.c index add069ccf9..2e88a0c388 100644 --- a/src/doveadm/doveadm-dict.c +++ b/src/doveadm/doveadm-dict.c @@ -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); diff --git a/src/lib-dict/dict-client.c b/src/lib-dict/dict-client.c index 546bcf4f9b..0aa6116128 100644 --- a/src/lib-dict/dict-client.c +++ b/src/lib-dict/dict-client.c @@ -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); diff --git a/src/lib-dict/dict.c b/src/lib-dict/dict.c index d43e2e5072..7313a9ad62 100644 --- a/src/lib-dict/dict.c +++ b/src/lib-dict/dict.c @@ -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) { diff --git a/src/lib-dict/dict.h b/src/lib-dict/dict.h index ed9c1c36db..b7e46e685f 100644 --- a/src/lib-dict/dict.h +++ b/src/lib-dict/dict.h @@ -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 */ -- 2.47.3