From: Timo Sirainen Date: Sun, 26 Nov 2017 10:33:33 +0000 (+0200) Subject: director: DIRECTOR-LIST - Return results sorted by host X-Git-Tag: 2.2.34~202 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=82100b01c91cee629200e15bb1a76b8e0e788fe6;p=thirdparty%2Fdovecot%2Fcore.git director: DIRECTOR-LIST - Return results sorted by host --- diff --git a/src/director/doveadm-connection.c b/src/director/doveadm-connection.c index c970af330b..ede9cd21dd 100644 --- a/src/director/doveadm-connection.c +++ b/src/director/doveadm-connection.c @@ -263,28 +263,31 @@ doveadm_cmd_director_list(struct doveadm_connection *conn, t_array_init(&hosts, array_count(&dir->dir_hosts)); array_append_array(&hosts, &dir->dir_hosts); + array_sort(&hosts, director_host_cmp_p); - /* show each individual connection */ + /* first show incoming connections that have no known host yet */ array_foreach(&dir->connections, connp) { - const struct director_host *host = - director_connection_get_host(*connp); - /* NOTE: for incoming connections host is initially NULL */ - - array_foreach(&hosts, hostp) { - if (*hostp == host) { - array_delete(&hosts, - array_foreach_idx(&hosts, hostp), 1); - break; - } - } - doveadm_director_connection_append(dir, *connp, host, str); + if (director_connection_get_host(*connp) == NULL) + doveadm_director_connection_append(dir, *connp, NULL, str); } - /* show the rest of the hosts that don't have any connections */ + /* show other connections and host without connections sorted by host */ array_foreach(&hosts, hostp) { const struct director_host *host = *hostp; - doveadm_director_host_append(dir, host, str); + bool have_connections = FALSE; + + array_foreach(&dir->connections, connp) { + const struct director_host *conn_host = + director_connection_get_host(*connp); + if (conn_host != host) + continue; + have_connections = TRUE; + doveadm_director_connection_append(dir, *connp, host, str); + } + if (!have_connections) + doveadm_director_host_append(dir, host, str); } + str_append_c(str, '\n'); o_stream_nsend(conn->output, str_data(str), str_len(str)); return DOVEADM_DIRECTOR_CMD_RET_OK;