From: Stephan Bosch Date: Sun, 4 Dec 2016 11:03:18 +0000 (+0100) Subject: lib-http: client: Created separate http_client_queue_get() function. X-Git-Tag: 2.3.0.rc1~272 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8149ed57ae5abbb0c4ccfe88c1d7c58255dc85cf;p=thirdparty%2Fdovecot%2Fcore.git lib-http: client: Created separate http_client_queue_get() function. 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. --- diff --git a/src/lib-http/http-client-host.c b/src/lib-http/http-client-host.c index d3c3a63e4e..2d1f3f2f23 100644 --- a/src/lib-http/http-client-host.c +++ b/src/lib-http/http-client-host.c @@ -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 */ diff --git a/src/lib-http/http-client-private.h b/src/lib-http/http-client-private.h index 270f4dfed7..47c07b111f 100644 --- a/src/lib-http/http-client-private.h +++ b/src/lib-http/http-client-private.h @@ -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); diff --git a/src/lib-http/http-client-queue.c b/src/lib-http/http-client-queue.c index 8e6883f3b0..2c62c1816f 100644 --- a/src/lib-http/http-client-queue.c +++ b/src/lib-http/http-client-queue.c @@ -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; }