]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: client: Improved labeling of debug messages.
authorStephan Bosch <stephan@dovecot.fi>
Mon, 23 May 2016 00:36:10 +0000 (02:36 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 9 Nov 2016 12:23:38 +0000 (14:23 +0200)
Request label is corrected.
Labels are now pre-composed and stored.

src/lib-http/http-client-connection.c
src/lib-http/http-client-peer.c
src/lib-http/http-client-private.h
src/lib-http/http-client-request.c

index e9f181eecbe09e74b270efc33b3ba7fd00193e96..61e0b00509a65fa545b8be63dc3a514f34d1e15c 100644 (file)
@@ -36,7 +36,7 @@ http_client_connection_debug(struct http_client_connection *conn,
 
                va_start(args, format); 
                i_debug("http-client: conn %s: %s",
-                       http_client_connection_label(conn),     t_strdup_vprintf(format, args));
+                       conn->label, t_strdup_vprintf(format, args));
                va_end(args);
        }
 }
@@ -1440,6 +1440,9 @@ http_client_connection_create(struct http_client_peer *peer)
        if (peer->addr.type != HTTP_CLIENT_PEER_ADDR_RAW)
                i_array_init(&conn->request_wait_list, 16);
 
+       conn->label = i_strdup_printf("%s [%d]",
+               http_client_peer_label(peer), conn->id);
+
        switch (peer->addr.type) {
        case HTTP_CLIENT_PEER_ADDR_HTTPS_TUNNEL:
                http_client_connection_connect_tunnel
index c20a1e89cbb999cbf787f309d9c07f3c73b9b4f6..f4d14e573d462195244e55bc60970dacba36a6e4 100644 (file)
@@ -104,6 +104,23 @@ int http_client_peer_addr_cmp
  * Peer
  */
 
+const char *
+http_client_peer_label(struct http_client_peer *peer)
+{
+       if (peer->label == NULL) {
+               switch (peer->addr.type) {
+               case HTTP_CLIENT_PEER_ADDR_HTTPS_TUNNEL:
+                       peer->label = i_strconcat
+                               (http_client_peer_addr2str(&peer->addr), " (tunnel)", NULL);
+                       break;
+               default:
+                       peer->label = i_strdup
+                               (http_client_peer_addr2str(&peer->addr));
+               }
+       }
+       return peer->label;
+}
+
 static void
 http_client_peer_do_connect(struct http_client_peer *peer,
        unsigned int count)
@@ -595,6 +612,7 @@ bool http_client_peer_unref(struct http_client_peer **_peer)
        array_free(&peer->conns);
        array_free(&peer->queues);
        i_free(peer->addr_name);
+       i_free(peer->label);
        i_free(peer);
        return FALSE;
 }
index 0926f630e25c742caef2574c7676e97448a0592f..7696d7157eae60fad7d1a7a1a0f8cf1e072c5139 100644 (file)
@@ -148,9 +148,9 @@ struct http_client_connection {
        struct http_client *client;
        unsigned int refcount;
 
-       const char *label;
-
+       char *label;
        unsigned int id; // DEBUG: identify parallel connections
+
        int connect_errno;
        struct timeval connect_start_timestamp;
        struct timeval connected_timestamp;
@@ -187,6 +187,8 @@ struct http_client_peer {
        struct http_client_peer_addr addr;
        char *addr_name;
 
+       char *label;
+
        struct http_client *client;
        struct http_client_peer *prev, *next;
 
@@ -347,22 +349,15 @@ http_client_peer_addr2str(const struct http_client_peer_addr *addr)
  * Request
  */
 
-static inline const char *
-http_client_request_label(struct http_client_request *req)
-{
-       if (req->label == NULL) {
-               return t_strdup_printf("[Req%u: %s %s%s]", req->id,
-                       req->method, http_url_create(&req->origin_url), req->target);
-       }
-       return req->label;
-}
-
 static inline bool
 http_client_request_to_proxy(const struct http_client_request *req)
 {
        return (req->host_url != &req->origin_url);
 }
 
+const char *
+http_client_request_label(struct http_client_request *req);
+
 void http_client_request_ref(struct http_client_request *req);
 /* Returns FALSE if unrefing destroyed the request entirely */
 bool http_client_request_unref(struct http_client_request **_req);
@@ -397,15 +392,6 @@ void http_client_request_finish(struct http_client_request *req);
  * Connection
  */
 
-static inline const char *
-http_client_connection_label(struct http_client_connection *conn)
-{
-       return t_strdup_printf("%s%s [%d]",
-               http_client_peer_addr2str(&conn->peer->addr),
-               (conn->peer->addr.type == HTTP_CLIENT_PEER_ADDR_HTTPS_TUNNEL ?
-                       " (tunnel)" : ""), conn->id);
-}
-
 struct connection_list *http_client_connection_list_init(void);
 
 struct http_client_connection *
@@ -439,22 +425,15 @@ void http_client_connection_start_tunnel(struct http_client_connection **_conn,
  * Peer
  */
 
-static inline const char *
-http_client_peer_label(struct http_client_peer *peer)
-{
-       if (peer->addr.type == HTTP_CLIENT_PEER_ADDR_HTTPS_TUNNEL) {
-               return t_strconcat
-                       (http_client_peer_addr2str(&peer->addr), " (tunnel)", NULL);
-       }
-       return http_client_peer_addr2str(&peer->addr);
-}
-
 unsigned int http_client_peer_addr_hash
        (const struct http_client_peer_addr *peer) ATTR_PURE;
 int http_client_peer_addr_cmp
        (const struct http_client_peer_addr *peer1,
                const struct http_client_peer_addr *peer2) ATTR_PURE;
 
+const char *
+http_client_peer_label(struct http_client_peer *peer);
+
 struct http_client_peer *
        http_client_peer_get(struct http_client *client,
                const struct http_client_peer_addr *addr);
index 813cb1218b5edc73eedca261f2d33ca83ecb1426..87de47a7f946c5889c6edac2a38c8557237cd1ea 100644 (file)
@@ -60,6 +60,17 @@ static bool
 http_client_request_send_error(struct http_client_request *req,
                               unsigned int status, const char *error);
 
+const char *
+http_client_request_label(struct http_client_request *req)
+{
+       if (req->label == NULL) {
+               req->label = p_strdup_printf(req->pool,
+                       "[Req%u: %s %s%s]", req->id,
+                       req->method, http_url_create(&req->origin_url), req->target);
+       }
+       return req->label;
+}
+
 static struct http_client_request *
 http_client_request_new(struct http_client *client, const char *method, 
                    http_client_request_callback_t *callback, void *context)