From 88ff981df1109a7f72c0e5889ce101c0c5b3cb7f Mon Sep 17 00:00:00 2001 From: Stephan Bosch Date: Thu, 28 Feb 2019 09:55:17 +0100 Subject: [PATCH] lib: connection - Use the connection event for all connection types directly. This way, the common event fields for the connection are available to each connection type and its descendant events for objects like commands, requests, and transactions. This also creates a standard log prefix used by all connection types. --- src/lib-auth/auth-client-connection.c | 7 ++----- src/lib-http/http-client-connection.c | 12 ++++-------- src/lib-smtp/smtp-client-connection.c | 12 ++---------- src/lib/connection.c | 18 +++++++++++++++--- src/lib/connection.h | 3 +++ 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/lib-auth/auth-client-connection.c b/src/lib-auth/auth-client-connection.c index 63cf808d37..0212e0cba6 100644 --- a/src/lib-auth/auth-client-connection.c +++ b/src/lib-auth/auth-client-connection.c @@ -329,12 +329,10 @@ auth_client_connection_init(struct auth_client *client) conn->client = client; - conn->event = client->event; - event_ref(conn->event); - - conn->conn.event_parent = conn->event; + conn->conn.event_parent = client->event; connection_init_client_unix(client->clist, &conn->conn, client->auth_socket_path); + conn->event = conn->conn.event; hash_table_create_direct(&conn->requests, pool, 100); i_array_init(&conn->available_auth_mechs, 8); @@ -465,7 +463,6 @@ void auth_client_connection_deinit(struct auth_client_connection **_conn) timeout_remove(&conn->to); array_free(&conn->available_auth_mechs); connection_deinit(&conn->conn); - event_unref(&conn->event); pool_unref(&conn->pool); } diff --git a/src/lib-http/http-client-connection.c b/src/lib-http/http-client-connection.c index f43372e311..89a60596c3 100644 --- a/src/lib-http/http-client-connection.c +++ b/src/lib-http/http-client-connection.c @@ -1709,13 +1709,10 @@ http_client_connection_create(struct http_client_peer *peer) i_array_init(&conn->request_wait_list, 16); conn->io_wait_timer = io_wait_timer_add_to(cctx->ioloop); - conn->event = event_create(ppool->peer->cctx->event); - - conn->conn.event_parent = conn->event; - connection_init(cctx->conn_list, &conn->conn, NULL); - - event_set_append_log_prefix( - conn->event, t_strdup_printf("conn %s: ", conn->conn.label)); + conn->conn.event_parent = ppool->peer->cctx->event; + connection_init(cctx->conn_list, &conn->conn, + http_client_peer_shared_label(pshared)); + conn->event = conn->conn.event; switch (pshared->addr.type) { case HTTP_CLIENT_PEER_ADDR_HTTPS_TUNNEL: @@ -1844,7 +1841,6 @@ bool http_client_connection_unref(struct http_client_connection **_conn) connection_deinit(&conn->conn); io_wait_timer_remove(&conn->io_wait_timer); - event_unref(&conn->event); i_free(conn); http_client_peer_pool_unref(&ppool); diff --git a/src/lib-smtp/smtp-client-connection.c b/src/lib-smtp/smtp-client-connection.c index 0d3bb44064..81908e47ee 100644 --- a/src/lib-smtp/smtp-client-connection.c +++ b/src/lib-smtp/smtp-client-connection.c @@ -1838,15 +1838,11 @@ smtp_client_connection_do_create(struct smtp_client *client, const char *name, smtp_protocol_name(conn->protocol)); event_set_forced_debug(conn_event, (set != NULL && set->debug)); - conn->event = event_create(conn_event); - - conn->conn.event_parent = conn->event; + conn->conn.event_parent = conn_event; connection_init(conn->client->conn_list, &conn->conn, name); + conn->event = conn->conn.event; event_unref(&conn_event); - event_set_append_log_prefix( - conn->event, t_strdup_printf("conn %s: ", conn->conn.label)); - return conn; } @@ -1865,7 +1861,6 @@ smtp_client_connection_create(struct smtp_client *client, conn->ssl_mode = ssl_mode; event_add_str(conn->event, "host", host); - event_add_int(conn->event, "port", port); e_debug(conn->event, "Connection created"); @@ -1907,8 +1902,6 @@ smtp_client_connection_create_unix(struct smtp_client *client, conn = smtp_client_connection_do_create(client, name, protocol, set); conn->path = p_strdup(conn->pool, path); - event_add_str(conn->event, "socket_path", path); - e_debug(conn->event, "Connection created"); return conn; @@ -1955,7 +1948,6 @@ void smtp_client_connection_unref(struct smtp_client_connection **_conn) connection_deinit(&conn->conn); - event_unref(&conn->event); i_free(conn->ips); pool_unref(&conn->cap_pool); pool_unref(&conn->pool); diff --git a/src/lib/connection.c b/src/lib/connection.c index 151e11f849..8947b817a6 100644 --- a/src/lib/connection.c +++ b/src/lib/connection.c @@ -339,6 +339,20 @@ static void connection_update_stream_names(struct connection *conn) } } +void connection_update_event(struct connection *conn) +{ + string_t *prefix; + + prefix = t_str_new(64); + str_append(prefix, "conn"); + if (strlen(conn->label) > 0) { + str_append_c(prefix, ' '); + str_append(prefix, conn->label); + } + str_append(prefix, ": "); + event_set_append_log_prefix(conn->event, str_c(prefix)); +} + static void connection_update_properties(struct connection *conn) { @@ -373,6 +387,7 @@ connection_update_properties(struct connection *conn) connection_update_property_label(conn); connection_update_label(conn); connection_update_stream_names(conn); + connection_update_event(conn); } static void connection_init_streams(struct connection *conn) @@ -564,9 +579,6 @@ void connection_init_client_ip_from(struct connection_list *list, { i_assert(list->set.client); - if (name == NULL) - name = t_strdup_printf("%s:%u", net_ip2addr(ip), port); - conn->remote_ip = *ip; conn->remote_port = port; diff --git a/src/lib/connection.h b/src/lib/connection.h index db727d7dcd..478598e52f 100644 --- a/src/lib/connection.h +++ b/src/lib/connection.h @@ -202,6 +202,9 @@ void connection_deinit(struct connection *conn); void connection_input_halt(struct connection *conn); void connection_input_resume(struct connection *conn); +/* Update event fields and log prefix based on connection properties. */ +void connection_update_event(struct connection *conn); + /* This needs to be called if the input/output streams are changed */ void connection_streams_changed(struct connection *conn);