From dd7f5beff9da8bb7501aa1aaf6df226789dbdcba Mon Sep 17 00:00:00 2001 From: Markus Valentin Date: Thu, 1 Dec 2022 11:13:16 +0100 Subject: [PATCH] dict: Implement DICT_PROTOCOL_CMD_HIDE_LOG_VALUES for dict and dict-proxy --- src/dict/dict-commands.c | 29 +++++++++++++++++++++++++++++ src/lib-dict/dict-client.c | 16 ++++++++++++++++ src/lib-dict/dict-client.h | 1 + 3 files changed, 46 insertions(+) diff --git a/src/dict/dict-commands.c b/src/dict/dict-commands.c index df31ac3893..da6accedc3 100644 --- a/src/dict/dict-commands.c +++ b/src/dict/dict-commands.c @@ -656,6 +656,34 @@ static int cmd_timestamp(struct dict_connection_cmd *cmd, const char *const *arg return 0; } +static int +cmd_hide_log_values(struct dict_connection_cmd *cmd, const char *const *args) +{ + struct dict_connection_transaction *trans; + bool value; + + /* */ + if (str_array_length(args) != 2 ) { + e_error(cmd->event, "HIDE_LOG_VALUES: broken input"); + return -1; + } + if (strcasecmp(args[1], "yes") == 0 || strcasecmp(args[1], "y") == 0 || + strcmp(args[1], "1") == 0) + value = TRUE; + else if (strcasecmp(args[1], "no") == 0) + value = FALSE; + else { + e_error(cmd->event, "HIDE_LOG_VALUES: broken input"); + return -1; + } + + if (dict_connection_transaction_lookup_parse(cmd->conn, args[0], &trans) < 0) + return -1; + + dict_transaction_set_hide_log_values(trans->ctx, value); + return 0; +} + static const struct dict_cmd_func cmds[] = { { DICT_PROTOCOL_CMD_LOOKUP, cmd_lookup }, { DICT_PROTOCOL_CMD_ITERATE, cmd_iterate }, @@ -667,6 +695,7 @@ static const struct dict_cmd_func cmds[] = { { DICT_PROTOCOL_CMD_UNSET, cmd_unset }, { DICT_PROTOCOL_CMD_ATOMIC_INC, cmd_atomic_inc }, { DICT_PROTOCOL_CMD_TIMESTAMP, cmd_timestamp }, + { DICT_PROTOCOL_CMD_HIDE_LOG_VALUES, cmd_hide_log_values }, { 0, NULL } }; diff --git a/src/lib-dict/dict-client.c b/src/lib-dict/dict-client.c index 32b2da1108..2c688efa54 100644 --- a/src/lib-dict/dict-client.c +++ b/src/lib-dict/dict-client.c @@ -1468,6 +1468,21 @@ static void client_dict_set_timestamp(struct dict_transaction_context *_ctx, client_dict_send_transaction_query(ctx, query); } +static void client_dict_set_hide_log_values(struct dict_transaction_context *_ctx, + bool hide_log_values) +{ + struct client_dict_transaction_context *ctx = + container_of(_ctx, struct client_dict_transaction_context, ctx); + const char *query; + + query = t_strdup_printf("%c%u\t%s", + DICT_PROTOCOL_CMD_HIDE_LOG_VALUES, + ctx->id, + hide_log_values ? "yes" : "no"); + + client_dict_send_transaction_query(ctx, query); +} + struct dict dict_driver_client = { .name = "proxy", @@ -1488,5 +1503,6 @@ struct dict dict_driver_client = { .lookup_async = client_dict_lookup_async, .switch_ioloop = client_dict_switch_ioloop, .set_timestamp = client_dict_set_timestamp, + .set_hide_log_values = client_dict_set_hide_log_values, } }; diff --git a/src/lib-dict/dict-client.h b/src/lib-dict/dict-client.h index 5c14f73a6e..95e2fb09c9 100644 --- a/src/lib-dict/dict-client.h +++ b/src/lib-dict/dict-client.h @@ -28,6 +28,7 @@ enum dict_protocol_cmd { DICT_PROTOCOL_CMD_UNSET = 'U', /* */ DICT_PROTOCOL_CMD_ATOMIC_INC = 'A', /* */ DICT_PROTOCOL_CMD_TIMESTAMP = 'T', /* */ + DICT_PROTOCOL_CMD_HIDE_LOG_VALUES = 'V', /* */ }; enum dict_protocol_reply { -- 2.47.3