]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dict-client: Support multiple values for lookups
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 12 Jan 2017 18:35:12 +0000 (20:35 +0200)
committerGitLab <gitlab@git.dovecot.net>
Sun, 15 Jan 2017 00:10:11 +0000 (02:10 +0200)
src/dict/dict-commands.c
src/lib-dict/dict-client.c
src/lib-dict/dict-client.h

index c4f2e8216fdf56daabc38878044e7faba03e4ec8..4fe78572ac0077345a6a340844484f8854a62206 100644 (file)
@@ -162,6 +162,31 @@ dict_cmd_reply_handle_timings(struct dict_connection_cmd *cmd,
                    (unsigned int)ioloop_timeval.tv_usec);
 }
 
+static void
+cmd_lookup_write_reply(struct dict_connection_cmd *cmd,
+                      const char *const *values, string_t *str)
+{
+       string_t *tmp;
+
+       i_assert(values[0] != NULL);
+
+       if (cmd->conn->minor_version < DICT_CLIENT_PROTOCOL_VERSION_MIN_MULTI_OK ||
+           values[1] == NULL) {
+               str_append_c(str, DICT_PROTOCOL_REPLY_OK);
+               str_append_tabescaped(str, values[0]);
+               return;
+       }
+       /* the results get double-tabescaped so they end up becoming a single
+          parameter */
+       tmp = t_str_new(128);
+       for (unsigned int i = 0; values[i] != NULL; i++) {
+               str_append_c(tmp, '\t');
+               str_append_tabescaped(tmp, values[i]);
+       }
+       str_append_c(str, DICT_PROTOCOL_REPLY_MULTI_OK);
+       str_append_tabescaped(str, str_c(tmp) + 1);
+}
+
 static void
 cmd_lookup_callback(const struct dict_lookup_result *result, void *context)
 {
@@ -169,8 +194,7 @@ cmd_lookup_callback(const struct dict_lookup_result *result, void *context)
        string_t *str = t_str_new(128);
 
        if (result->ret > 0) {
-               str_append_c(str, DICT_PROTOCOL_REPLY_OK);
-               str_append_tabescaped(str, result->value);
+               cmd_lookup_write_reply(cmd, result->values, str);
        } else if (result->ret == 0) {
                str_append_c(str, DICT_PROTOCOL_REPLY_NOTFOUND);
        } else {
index a72506c53de6e392333b17b891418ea515664393..158fed13639b5d857f7760deb855ef1e5d06a860 100644 (file)
@@ -938,6 +938,11 @@ client_dict_lookup_async_callback(struct client_dict_cmd *cmd,
                result.values = values;
                result.ret = 1;
                break;
+       case DICT_PROTOCOL_REPLY_MULTI_OK:
+               result.values = t_strsplit_tabescaped(value);
+               result.value = result.values[0];
+               result.ret = 1;
+               break;
        case DICT_PROTOCOL_REPLY_NOTFOUND:
                result.ret = 0;
                break;
index 47028342ba3fcb7a7bdeb8b142d1fcb072af51bf..dfd391a2fbc59ccf5403370af3ef15307edad557 100644 (file)
@@ -6,7 +6,9 @@
 #define DEFAULT_DICT_SERVER_SOCKET_FNAME "dict"
 
 #define DICT_CLIENT_PROTOCOL_MAJOR_VERSION 2
-#define DICT_CLIENT_PROTOCOL_MINOR_VERSION 1
+#define DICT_CLIENT_PROTOCOL_MINOR_VERSION 2
+
+#define DICT_CLIENT_PROTOCOL_VERSION_MIN_MULTI_OK 2
 
 #define DICT_CLIENT_MAX_LINE_LENGTH (64*1024)
 
@@ -32,6 +34,7 @@ enum dict_protocol_reply {
        DICT_PROTOCOL_REPLY_ERROR = -1,
 
        DICT_PROTOCOL_REPLY_OK = 'O', /* <value> */
+       DICT_PROTOCOL_REPLY_MULTI_OK = 'M', /* protocol v2.2+ */
        DICT_PROTOCOL_REPLY_NOTFOUND = 'N',
        DICT_PROTOCOL_REPLY_FAIL = 'F',
        DICT_PROTOCOL_REPLY_WRITE_UNCERTAIN = 'W',