#include "dict-commands.h"
#include "main.h"
-#define DICT_CLIENT_PROTOCOL_TIMINGS_MIN_VERSION 1
-#define DICT_CLIENT_PROTOCOL_UNORDERED_MIN_VERSION 1
#define DICT_OUTPUT_OPTIMAL_SIZE 1024
struct dict_cmd_func {
static int cmd_iterate_flush(struct dict_connection_cmd *cmd);
-static bool dict_connection_cmd_output_more(struct dict_connection_cmd *cmd);
+static bool dict_connection_cmds_try_output_more(struct dict_connection *conn);
static void dict_connection_cmd_free(struct dict_connection_cmd *cmd)
{
i_unreached();
}
-static void dict_connection_cmds_flush(struct dict_connection *conn)
-{
- struct dict_connection_cmd *cmd, *const *first_cmdp;
-
- i_assert(conn->conn.minor_version < DICT_CLIENT_PROTOCOL_UNORDERED_MIN_VERSION);
-
- dict_connection_ref(conn);
- while (array_count(&conn->cmds) > 0) {
- first_cmdp = array_front(&conn->cmds);
- cmd = *first_cmdp;
-
- i_assert(cmd->async_reply_id == 0);
-
- /* we may be able to start outputting iterations now. */
- if (cmd->iter != NULL)
- (void)cmd_iterate_flush(cmd);
-
- if (cmd->reply == NULL) {
- /* command not finished yet */
- break;
- }
-
- o_stream_nsend_str(conn->conn.output, cmd->reply);
- dict_connection_cmd_remove(cmd);
- }
- dict_connection_unref_safe(conn);
-}
-
static void dict_connection_cmd_try_flush(struct dict_connection_cmd **_cmd)
{
struct dict_connection_cmd *cmd = *_cmd;
*_cmd = NULL;
- if (cmd->conn->conn.minor_version < DICT_CLIENT_PROTOCOL_UNORDERED_MIN_VERSION) {
- dict_connection_cmds_flush(cmd->conn);
- return;
- }
+
i_assert(cmd->async_reply_id != 0);
i_assert(cmd->reply != NULL);
static void dict_connection_cmd_async(struct dict_connection_cmd *cmd)
{
- if (cmd->conn->conn.minor_version < DICT_CLIENT_PROTOCOL_UNORDERED_MIN_VERSION)
- return;
-
i_assert(cmd->async_reply_id == 0);
cmd->async_reply_id = ++cmd->conn->async_id_counter;
if (cmd->async_reply_id == 0)
io_loop_time_refresh();
cmd_stats_update(cmd, stats);
- if (cmd->conn->conn.minor_version < DICT_CLIENT_PROTOCOL_TIMINGS_MIN_VERSION)
- return;
str_printfa(str, "\t%ld\t%u\t%ld\t%u",
(long)cmd->start_timeval.tv_sec,
(unsigned int)cmd->start_timeval.tv_usec,
}
static void
-cmd_lookup_write_reply(struct dict_connection_cmd *cmd,
- const char *const *values, string_t *str)
+cmd_lookup_write_reply(const char *const *values, string_t *str)
{
string_t *tmp;
i_assert(values[0] != NULL);
- if (cmd->conn->conn.minor_version < DICT_CLIENT_PROTOCOL_VERSION_MIN_MULTI_OK ||
- values[1] == NULL) {
+ if (values[1] == NULL) {
str_append_c(str, DICT_PROTOCOL_REPLY_OK);
str_append_tabescaped(str, values[0]);
return;
event_set_name(cmd->event, "dict_server_lookup_finished");
if (result->ret > 0) {
- cmd_lookup_write_reply(cmd, result->values, str);
+ cmd_lookup_write_reply(result->values, str);
e_debug(cmd->event, "Lookup finished");
} else if (result->ret == 0) {
event_add_str(cmd->event, "key_not_found", "yes");
cork. */
conn->iter_flush_pending = FALSE;
cmd->uncork_pending = FALSE;
- if (dict_connection_cmd_output_more(cmd)) {
+ if (dict_connection_cmds_try_output_more(conn)) {
/* NOTE: cmd may be freed now */
o_stream_uncork(conn->conn.output);
} else if (conn->iter_flush_pending) {
if (max_rows > 0)
dict_iterate_set_limit(cmd->iter, max_rows);
dict_iterate_set_async_callback(cmd->iter, cmd_iterate_callback, cmd);
- (void)dict_connection_cmd_output_more(cmd);
+ (void)dict_connection_cmds_try_output_more(cmd->conn);
return 1;
}
/* cmd should be freed now, restart output */
return TRUE;
}
- if (conn->conn.minor_version < DICT_CLIENT_PROTOCOL_TIMINGS_MIN_VERSION)
- break;
/* try to flush the rest */
}
return FALSE;
}
}
-static bool dict_connection_cmd_output_more(struct dict_connection_cmd *cmd)
-{
- struct dict_connection_cmd *const *first_cmdp;
-
- if (cmd->conn->conn.minor_version < DICT_CLIENT_PROTOCOL_TIMINGS_MIN_VERSION) {
- first_cmdp = array_front(&cmd->conn->cmds);
- if (*first_cmdp != cmd)
- return TRUE;
- }
- return dict_connection_cmds_try_output_more(cmd->conn);
-}
-
void dict_commands_init(void)
{
cmd_stats.lookups = stats_dist_init();