]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: client: Created separate http_client_queue_get() function.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sun, 4 Dec 2016 11:03:18 +0000 (12:03 +0100)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Thu, 7 Dec 2017 16:40:45 +0000 (18:40 +0200)
Before, this was combined in http_client_queue_create() which caused a large code block to be indentet.
Separating creation and obtaining the current instance makes the code cleaner.

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

index d3c3a63e4e392eda6e1c3921329d731688e95c58..2d1f3f2f236d2b4203ba495df0181235208b2134 100644 (file)
@@ -251,7 +251,7 @@ void http_client_host_submit_request(struct http_client_host *host,
        }
 
        /* add request to queue (grouped by tcp port) */
-       queue = http_client_queue_create(host, &addr);
+       queue = http_client_queue_get(host, &addr);
        http_client_queue_submit_request(queue, req);
 
        /* cancel host idle timeout */
index 270f4dfed7a7548fdd39c6927ecde8f03a21f92c..47c07b111f4cb58683467a3fafa7071e1e5f5780 100644 (file)
@@ -484,7 +484,7 @@ void http_client_peer_switch_ioloop(struct http_client_peer *peer);
  */
 
 struct http_client_queue *
-http_client_queue_create(struct http_client_host *host,
+http_client_queue_get(struct http_client_host *host,
        const struct http_client_peer_addr *addr);
 void http_client_queue_free(struct http_client_queue *queue);
 void http_client_queue_connection_setup(struct http_client_queue *queue);
index 8e6883f3b0987dc2f040c9d771c9e8282b302f4a..2c62c1816f0932b65c40d7d3fac430f468473043 100644 (file)
@@ -71,55 +71,66 @@ http_client_queue_find(struct http_client_host *host,
        return NULL;
 }
 
-struct http_client_queue *
+static struct http_client_queue *
 http_client_queue_create(struct http_client_host *host,
        const struct http_client_peer_addr *addr)
 {
+       const char *hostname = host->name;
        struct http_client_queue *queue;
 
-       queue = http_client_queue_find(host, addr);
-       if (queue == NULL) {
-               queue = i_new(struct http_client_queue, 1);
-               queue->client = host->client;
-               queue->host = host;
-               queue->addr = *addr;
-
-               switch (addr->type) {
-               case HTTP_CLIENT_PEER_ADDR_RAW:
-                       queue->name =
-                               i_strdup_printf("raw://%s:%u", host->name, addr->a.tcp.port);
-                       queue->addr.a.tcp.https_name = NULL;
-                       break;
-               case HTTP_CLIENT_PEER_ADDR_HTTPS_TUNNEL:
-               case HTTP_CLIENT_PEER_ADDR_HTTPS:
-                       queue->name =
-                               i_strdup_printf("https://%s:%u", host->name, addr->a.tcp.port);
-                       queue->addr_name = i_strdup(addr->a.tcp.https_name);
-                       queue->addr.a.tcp.https_name = queue->addr_name;
-                       break;
-               case HTTP_CLIENT_PEER_ADDR_HTTP:
-                       queue->name =
-                               i_strdup_printf("http://%s:%u", host->name, addr->a.tcp.port);
-                       queue->addr.a.tcp.https_name = NULL;
-                       break;
-               case HTTP_CLIENT_PEER_ADDR_UNIX:
-                       queue->name = i_strdup_printf("unix:%s", addr->a.un.path);
-                       queue->addr_name = i_strdup(addr->a.un.path);
-                       queue->addr.a.un.path = queue->addr_name;
-                       break;
-               default:
-                       i_unreached();
-               }
-
-               queue->ips_connect_idx = 0;
-               i_array_init(&queue->pending_peers, 8);
-               i_array_init(&queue->requests, 16);
-               i_array_init(&queue->queued_requests, 16);
-               i_array_init(&queue->queued_urgent_requests, 16);
-               i_array_init(&queue->delayed_requests, 4);
-               array_append(&host->queues, &queue, 1);
+       queue = i_new(struct http_client_queue, 1);
+       queue->client = host->client;
+       queue->host = host;
+       queue->addr = *addr;
+
+       switch (addr->type) {
+       case HTTP_CLIENT_PEER_ADDR_RAW:
+               queue->name =
+                       i_strdup_printf("raw://%s:%u", hostname, addr->a.tcp.port);
+               queue->addr.a.tcp.https_name = NULL;
+               break;
+       case HTTP_CLIENT_PEER_ADDR_HTTPS_TUNNEL:
+       case HTTP_CLIENT_PEER_ADDR_HTTPS:
+               queue->name =
+                       i_strdup_printf("https://%s:%u", hostname, addr->a.tcp.port);
+               queue->addr_name = i_strdup(addr->a.tcp.https_name);
+               queue->addr.a.tcp.https_name = queue->addr_name;
+               break;
+       case HTTP_CLIENT_PEER_ADDR_HTTP:
+               queue->name =
+                       i_strdup_printf("http://%s:%u", hostname, addr->a.tcp.port);
+               queue->addr.a.tcp.https_name = NULL;
+               break;
+       case HTTP_CLIENT_PEER_ADDR_UNIX:
+               queue->name = i_strdup_printf("unix:%s", addr->a.un.path);
+               queue->addr_name = i_strdup(addr->a.un.path);
+               queue->addr.a.un.path = queue->addr_name;
+               break;
+       default:
+               i_unreached();
        }
 
+       queue->ips_connect_idx = 0;
+       i_array_init(&queue->pending_peers, 8);
+       i_array_init(&queue->requests, 16);
+       i_array_init(&queue->queued_requests, 16);
+       i_array_init(&queue->queued_urgent_requests, 16);
+       i_array_init(&queue->delayed_requests, 4);
+       array_append(&host->queues, &queue, 1);
+
+       return queue;
+}
+
+struct http_client_queue *
+http_client_queue_get(struct http_client_host *host,
+       const struct http_client_peer_addr *addr)
+{
+       struct http_client_queue *queue;
+
+       queue = http_client_queue_find(host, addr);
+       if (queue == NULL)
+               queue = http_client_queue_create(host, addr);
+
        return queue;
 }