]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: Fixed client connection and peer log labels to show proper IPv6 peers.
authorStephan Bosch <stephan@rename-it.nl>
Sun, 15 Sep 2013 00:33:04 +0000 (03:33 +0300)
committerStephan Bosch <stephan@rename-it.nl>
Sun, 15 Sep 2013 00:33:04 +0000 (03:33 +0300)
The labels did not put IPv6 addresses in square brackets.

src/lib-http/http-client-host.c
src/lib-http/http-client-peer.c
src/lib-http/http-client-private.h

index ed4363f330f8bc98fb5b5a0cec533d93b8a758a4..33247b3b0d91a8dc2a847097b9a775604137c13f 100644 (file)
@@ -134,6 +134,7 @@ static void
 http_client_host_port_soft_connect_timeout(struct http_client_host_port *hport)
 {
        struct http_client_host *host = hport->host;
+       const struct http_client_peer_addr *addr = &hport->addr;
 
        if (hport->to_connect != NULL)
                timeout_remove(&hport->to_connect);
@@ -146,12 +147,10 @@ http_client_host_port_soft_connect_timeout(struct http_client_host_port *hport)
        /* if our our previous connection attempt takes longer than the
           soft_connect_timeout, we start a connection attempt to the next IP in
           parallel */
-
-       http_client_host_debug(host, "Connection to %s:%u%s is taking a long time; "
+       http_client_host_debug(host, "Connection to %s%s is taking a long time; "
                "starting parallel connection attempt to next IP",
-               net_ip2addr(&hport->addr.ip), hport->addr.port,
-               hport->addr.https_name == NULL ? "" :
-                       t_strdup_printf(" (SSL=%s)", hport->addr.https_name));
+               http_client_peer_addr2str(addr), addr->https_name == NULL ? "" :
+                       t_strdup_printf(" (SSL=%s)", addr->https_name)); 
 
        /* next IP */
        hport->ips_connect_idx = (hport->ips_connect_idx + 1) % host->ips_count;
@@ -174,10 +173,10 @@ http_client_host_port_connection_setup(struct http_client_host_port *hport)
        /* update our peer address */
        hport->addr.ip = host->ips[hport->ips_connect_idx];
 
-       http_client_host_debug(host, "Setting up connection to %s:%u%s "
-               "(%u requests pending)", net_ip2addr(&addr->ip), addr->port,
-               addr->https_name == NULL ? "" :
-                       t_strdup_printf(" (SSL=%s)", addr->https_name), num_requests);
+       http_client_host_debug(host, "Setting up connection to %s%s "
+               "(%u requests pending)", http_client_peer_addr2str(addr),
+               (addr->https_name == NULL ? "" :
+                       t_strdup_printf(" (SSL=%s)", addr->https_name)), num_requests);
 
        /* create/get peer */
        peer = http_client_peer_get(host->client, addr);
@@ -307,8 +306,8 @@ void http_client_host_connection_success(struct http_client_host *host,
 {
        struct http_client_host_port *hport;
 
-       http_client_host_debug(host, "Successfully connected to %s:%u",
-               net_ip2addr(&addr->ip), addr->port);
+       http_client_host_debug(host, "Successfully connected to %s",
+               http_client_peer_addr2str(addr));
 
        hport = http_client_host_port_find(host, addr->port, addr->https_name);
        if (hport == NULL)
@@ -322,8 +321,8 @@ void http_client_host_connection_failure(struct http_client_host *host,
 {
        struct http_client_host_port *hport;
 
-       http_client_host_debug(host, "Failed to connect to %s:%u: %s",
-               net_ip2addr(&addr->ip), addr->port, reason);
+       http_client_host_debug(host, "Failed to connect to %s: %s",
+               http_client_peer_addr2str(addr), reason);
 
        hport = http_client_host_port_find(host, addr->port, addr->https_name);
        if (hport == NULL)
@@ -513,8 +512,8 @@ http_client_host_claim_request(struct http_client_host *host,
        array_delete(&hport->request_queue, i, 1);
 
        http_client_host_debug(host,
-               "Connection to peer %s:%u claimed request %s %s",
-               net_ip2addr(&addr->ip), addr->port, http_client_request_label(req),
+               "Connection to peer %s claimed request %s %s",
+               http_client_peer_addr2str(addr), http_client_request_label(req),
                (req->urgent ? "(urgent)" : ""));
 
        return req;
index c06b98c6fbf7492d08f9f77bcb7f771e32f6cd4f..e4791122b60bad7b3118f46aad9dfb89cf5e23dc 100644 (file)
@@ -29,9 +29,8 @@ http_client_peer_debug(struct http_client_peer *peer,
 
        if (peer->client->set.debug) {
                va_start(args, format); 
-               i_debug("http-client: peer %s:%u: %s", 
-                       net_ip2addr(&peer->addr.ip), peer->addr.port,
-                       t_strdup_vprintf(format, args));
+               i_debug("http-client: peer %s: %s", 
+                       http_client_peer_label(peer), t_strdup_vprintf(format, args));
                va_end(args);
        }
 }
index bcd010ea3894fc5dc448a0a856814e849c1ffe1b..d80d09583e79d35bf4fff5586e8115b78dd840a1 100644 (file)
@@ -189,6 +189,14 @@ struct http_client {
        unsigned int pending_requests;
 };
 
+static inline const char *
+http_client_peer_addr2str(const struct http_client_peer_addr *addr)
+{
+       if (addr->ip.family == AF_INET6)
+               return t_strdup_printf("[%s]:%u", net_ip2addr(&addr->ip), addr->port);
+       return t_strdup_printf("%s:%u", net_ip2addr(&addr->ip), addr->port);
+}
+
 static inline const char *
 http_client_request_label(struct http_client_request *req)
 {
@@ -199,8 +207,14 @@ http_client_request_label(struct http_client_request *req)
 static inline const char *
 http_client_connection_label(struct http_client_connection *conn)
 {
-       return t_strdup_printf("%s:%u [%d]",
-               net_ip2addr(&conn->conn.ip), conn->conn.port, conn->id);
+       return t_strdup_printf("%s [%d]",
+                http_client_peer_addr2str(&conn->peer->addr), conn->id);
+}
+
+static inline const char *
+http_client_peer_label(struct http_client_peer *peer)
+{
+       return http_client_peer_addr2str(&peer->addr);
 }
 
 int http_client_init_ssl_ctx(struct http_client *client, const char **error_r);