Mercurial > dovecot > core-2.2
changeset 19768:603fdee3685f
doveadm: Code cleanup - moved code to client_connection_init()
No functional changes.
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Fri, 19 Feb 2016 14:40:59 +0200 |
parents | a9fd771f2cae |
children | 9324bdd97612 |
files | src/doveadm/client-connection.c |
diffstat | 1 files changed, 26 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/src/doveadm/client-connection.c Mon Feb 15 14:02:19 2016 +0200 +++ b/src/doveadm/client-connection.c Fri Feb 19 14:40:59 2016 +0200 @@ -482,36 +482,47 @@ } } -struct client_connection * -client_connection_create(int fd, int listen_fd, bool ssl) +static int client_connection_init(struct client_connection *conn, int fd) { - struct client_connection *conn; const char *ip; - pool_t pool; - pool = pool_alloconly_create("doveadm client", 1024*16); - conn = p_new(pool, struct client_connection, 1); - conn->pool = pool; conn->fd = fd; - conn->io = io_add(fd, IO_READ, client_connection_input, conn); - conn->input = i_stream_create_fd(fd, MAX_INBUF_SIZE, FALSE); - conn->output = o_stream_create_fd(fd, (size_t)-1, FALSE); - o_stream_set_no_error_handling(conn->output, TRUE); (void)net_getsockname(fd, &conn->local_ip, &conn->local_port); (void)net_getpeername(fd, &conn->remote_ip, &conn->remote_port); - i_stream_set_name(conn->input, net_ip2addr(&conn->remote_ip)); - o_stream_set_name(conn->output, net_ip2addr(&conn->remote_ip)); - ip = net_ip2addr(&conn->remote_ip); if (ip[0] != '\0') i_set_failure_prefix("doveadm(%s): ", ip); if (client_connection_read_settings(conn) < 0) { client_connection_destroy(&conn); + return -1; + } + return 0; +} + +struct client_connection * +client_connection_create(int fd, int listen_fd, bool ssl) +{ + struct client_connection *conn; + pool_t pool; + + pool = pool_alloconly_create("doveadm client", 1024*16); + conn = p_new(pool, struct client_connection, 1); + conn->pool = pool; + + if (client_connection_init(conn, fd) < 0) return NULL; - } + doveadm_print_init(DOVEADM_PRINT_TYPE_SERVER); + + conn->io = io_add(fd, IO_READ, client_connection_input, conn); + conn->input = i_stream_create_fd(fd, MAX_INBUF_SIZE, FALSE); + conn->output = o_stream_create_fd(fd, (size_t)-1, FALSE); + i_stream_set_name(conn->input, net_ip2addr(&conn->remote_ip)); + o_stream_set_name(conn->output, net_ip2addr(&conn->remote_ip)); + o_stream_set_no_error_handling(conn->output, TRUE); + if (ssl) { if (client_connection_init_ssl(conn) < 0) { client_connection_destroy(&conn);