Mercurial > dovecot > core-2.2
changeset 22687:e024078c62c9
director: DIRECTOR-LIST - Return results sorted by host
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Sun, 26 Nov 2017 12:33:33 +0200 |
parents | 7347dab76be0 |
children | 09f5d34ff1fc |
files | src/director/doveadm-connection.c |
diffstat | 1 files changed, 19 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/src/director/doveadm-connection.c Sun Nov 26 12:26:27 2017 +0200 +++ b/src/director/doveadm-connection.c Sun Nov 26 12:33:33 2017 +0200 @@ -263,28 +263,31 @@ t_array_init(&hosts, array_count(&dir->dir_hosts)); array_append_array(&hosts, &dir->dir_hosts); - - /* show each individual connection */ - array_foreach(&dir->connections, connp) { - const struct director_host *host = - director_connection_get_host(*connp); - /* NOTE: for incoming connections host is initially NULL */ + array_sort(&hosts, director_host_cmp_p); - 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); + /* first show incoming connections that have no known host yet */ + array_foreach(&dir->connections, connp) { + 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;