From: Timo Sirainen Date: Wed, 10 Feb 2021 18:58:20 +0000 (+0200) Subject: lib-http: Use array_foreach_elem() where possible X-Git-Tag: 2.3.16~197 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d97ca599fa5d1ef0eab8a00c7bc813511d924e6e;p=thirdparty%2Fdovecot%2Fcore.git lib-http: Use array_foreach_elem() where possible --- diff --git a/src/lib-http/http-client-host.c b/src/lib-http/http-client-host.c index 1445d0de11..647ab663a1 100644 --- a/src/lib-http/http-client-host.c +++ b/src/lib-http/http-client-host.c @@ -365,7 +365,7 @@ static void http_client_host_free_shared(struct http_client_host **_host) struct http_client_host *host = *_host; struct http_client *client = host->client; struct http_client_host_shared *hshared = host->shared; - struct http_client_queue *const *queue_idx; + struct http_client_queue *queue; ARRAY_TYPE(http_client_queue) queues; *_host = NULL; @@ -382,8 +382,8 @@ static void http_client_host_free_shared(struct http_client_host **_host) array_copy(&queues.arr, 0, &host->queues.arr, 0, array_count(&host->queues)); array_clear(&host->queues); - array_foreach(&queues, queue_idx) - http_client_queue_free(*queue_idx); + array_foreach_elem(&queues, queue) + http_client_queue_free(queue); array_free(&host->queues); i_free(host); @@ -402,12 +402,12 @@ void http_client_host_free(struct http_client_host **_host) static void http_client_host_lookup_done(struct http_client_host *host) { struct http_client *client = host->client; - struct http_client_queue *const *queue_idx; + struct http_client_queue *queue; unsigned int requests = 0; /* Notify all queues */ - array_foreach_modifiable(&host->queues, queue_idx) - requests += http_client_queue_host_lookup_done(*queue_idx); + array_foreach_elem(&host->queues, queue) + requests += http_client_queue_host_lookup_done(queue); if (requests == 0 && client->waiting) io_loop_stop(client->ioloop); @@ -417,10 +417,10 @@ static void http_client_host_lookup_failure(struct http_client_host *host, const char *error) { - struct http_client_queue *const *queue_idx; + struct http_client_queue *queue; - array_foreach_modifiable(&host->queues, queue_idx) - http_client_queue_host_lookup_failure(*queue_idx, error); + array_foreach_elem(&host->queues, queue) + http_client_queue_host_lookup_failure(queue, error); } void http_client_host_submit_request(struct http_client_host *host, @@ -457,11 +457,11 @@ void http_client_host_submit_request(struct http_client_host *host, static bool http_client_host_is_idle(struct http_client_host *host) { - struct http_client_queue *const *queue_idx; + struct http_client_queue *queue; unsigned int requests = 0; - array_foreach(&host->queues, queue_idx) - requests += http_client_queue_requests_active(*queue_idx); + array_foreach_elem(&host->queues, queue) + requests += http_client_queue_requests_active(queue); return (requests == 0); } @@ -493,8 +493,8 @@ bool http_client_host_get_ip_idx(struct http_client_host *host, void http_client_host_switch_ioloop(struct http_client_host *host) { - struct http_client_queue *const *queue_idx; + struct http_client_queue *queue; - array_foreach(&host->queues, queue_idx) - http_client_queue_switch_ioloop(*queue_idx); + array_foreach_elem(&host->queues, queue) + http_client_queue_switch_ioloop(queue); } diff --git a/src/lib-http/http-client-peer.c b/src/lib-http/http-client-peer.c index d11159f869..2b1eca1fc0 100644 --- a/src/lib-http/http-client-peer.c +++ b/src/lib-http/http-client-peer.c @@ -138,7 +138,7 @@ void http_client_peer_pool_ref(struct http_client_peer_pool *ppool) void http_client_peer_pool_close(struct http_client_peer_pool **_ppool) { struct http_client_peer_pool *ppool = *_ppool; - struct http_client_connection **conn; + struct http_client_connection *conn; ARRAY_TYPE(http_client_connection) conns; http_client_peer_pool_ref(ppool); @@ -147,8 +147,8 @@ void http_client_peer_pool_close(struct http_client_peer_pool **_ppool) t_array_init(&conns, array_count(&ppool->conns)); array_copy(&conns.arr, 0, &ppool->conns.arr, 0, array_count(&ppool->conns)); - array_foreach_modifiable(&conns, conn) - http_client_connection_unref(conn); + array_foreach_elem(&conns, conn) + http_client_connection_unref(&conn); i_assert(array_count(&ppool->idle_conns) == 0); i_assert(array_count(&ppool->pending_conns) == 0); i_assert(array_count(&ppool->conns) == 0); @@ -620,10 +620,10 @@ void http_client_peer_ref(struct http_client_peer *peer) static void http_client_peer_disconnect(struct http_client_peer *peer) { - struct http_client_queue *const *queue; + struct http_client_queue *queue; struct http_client *client = peer->client; struct http_client_peer_shared *pshared = peer->shared; - struct http_client_connection **conn; + struct http_client_connection *conn; ARRAY_TYPE(http_client_connection) conns; if (peer->disconnected) @@ -636,8 +636,8 @@ static void http_client_peer_disconnect(struct http_client_peer *peer) t_array_init(&conns, array_count(&peer->conns)); array_copy(&conns.arr, 0, &peer->conns.arr, 0, array_count(&peer->conns)); - array_foreach_modifiable(&conns, conn) - http_client_connection_lost_peer(*conn); + array_foreach_elem(&conns, conn) + http_client_connection_lost_peer(conn); i_assert(array_count(&peer->conns) == 0); array_clear(&peer->pending_conns); @@ -652,8 +652,8 @@ static void http_client_peer_disconnect(struct http_client_peer *peer) pshared->peers_count--; /* Unlink all queues */ - array_foreach(&peer->queues, queue) - http_client_queue_peer_disconnected(*queue, peer); + array_foreach_elem(&peer->queues, queue) + http_client_queue_peer_disconnected(queue, peer); array_clear(&peer->queues); } @@ -829,13 +829,13 @@ http_client_peer_connect(struct http_client_peer *peer, unsigned int count) bool http_client_peer_is_connected(struct http_client_peer *peer) { - struct http_client_connection *const *conn_idx; + struct http_client_connection *conn; if (array_count(&peer->ppool->idle_conns) > 0) return TRUE; - array_foreach(&peer->conns, conn_idx) { - if ((*conn_idx)->connected) + array_foreach_elem(&peer->conns, conn) { + if (conn->connected) return TRUE; } @@ -845,7 +845,7 @@ bool http_client_peer_is_connected(struct http_client_peer *peer) static void http_client_peer_cancel(struct http_client_peer *peer) { - struct http_client_connection **conn; + struct http_client_connection *conn; ARRAY_TYPE(http_client_connection) conns; e_debug(peer->event, "Peer cancel"); @@ -854,9 +854,9 @@ http_client_peer_cancel(struct http_client_peer *peer) t_array_init(&conns, array_count(&peer->conns)); array_copy(&conns.arr, 0, &peer->conns.arr, 0, array_count(&peer->conns)); - array_foreach_modifiable(&conns, conn) { - if (!http_client_connection_is_active(*conn)) - http_client_connection_close(conn); + array_foreach_elem(&conns, conn) { + if (!http_client_connection_is_active(conn)) + http_client_connection_close(&conn); } i_assert(array_count(&peer->pending_conns) == 0); } @@ -865,11 +865,11 @@ static unsigned int http_client_peer_requests_pending(struct http_client_peer *peer, unsigned int *num_urgent_r) { - struct http_client_queue *const *queue; + struct http_client_queue *queue; unsigned int num_requests = 0, num_urgent = 0, requests, urgent; - array_foreach(&peer->queues, queue) { - requests = http_client_queue_requests_pending(*queue, &urgent); + array_foreach_elem(&peer->queues, queue) { + requests = http_client_queue_requests_pending(queue, &urgent); num_requests += requests; num_urgent += urgent; @@ -880,7 +880,7 @@ http_client_peer_requests_pending(struct http_client_peer *peer, static void http_client_peer_check_idle(struct http_client_peer *peer) { - struct http_client_connection *const *conn_idx; + struct http_client_connection *conn; unsigned int num_urgent = 0; if (array_count(&peer->conns) == 0 && @@ -891,8 +891,8 @@ static void http_client_peer_check_idle(struct http_client_peer *peer) } /* Check all connections for idle status */ - array_foreach(&peer->conns, conn_idx) - http_client_connection_check_idle(*conn_idx); + array_foreach_elem(&peer->conns, conn) + http_client_connection_check_idle(conn); } static void @@ -1223,12 +1223,12 @@ void http_client_peer_unlink_queue(struct http_client_peer *peer, struct http_client_request * http_client_peer_claim_request(struct http_client_peer *peer, bool no_urgent) { - struct http_client_queue *const *queue_idx; + struct http_client_queue *queue; struct http_client_request *req; - array_foreach(&peer->queues, queue_idx) { + array_foreach_elem(&peer->queues, queue) { req = http_client_queue_claim_request( - *queue_idx, &peer->shared->addr, no_urgent); + queue, &peer->shared->addr, no_urgent); if (req != NULL) { req->peer = peer; return req; @@ -1241,7 +1241,7 @@ http_client_peer_claim_request(struct http_client_peer *peer, bool no_urgent) void http_client_peer_connection_success(struct http_client_peer *peer) { struct http_client_peer_pool *ppool = peer->ppool; - struct http_client_queue *const *queue; + struct http_client_queue *queue; e_debug(peer->event, "Successfully connected " "(%u connections exist, %u pending)", @@ -1249,8 +1249,8 @@ void http_client_peer_connection_success(struct http_client_peer *peer) http_client_peer_pool_connection_success(ppool); - array_foreach(&peer->queues, queue) - http_client_queue_connection_success(*queue, peer); + array_foreach_elem(&peer->queues, queue) + http_client_queue_connection_success(queue, peer); http_client_peer_trigger_request_handler(peer); } @@ -1291,7 +1291,7 @@ static void http_client_peer_connection_failed_pool(struct http_client_peer *peer, const char *reason) { - struct http_client_queue *const *queuep; + struct http_client_queue *queue; ARRAY_TYPE(http_client_queue) queues; e_debug(peer->event, @@ -1310,8 +1310,8 @@ http_client_peer_connection_failed_pool(struct http_client_peer *peer, /* Failed to make any connection. a second connect will probably also fail, so just try another IP for the hosts(s) or abort all requests if this was the only/last option. */ - array_foreach(&queues, queuep) - http_client_queue_connection_failure(*queuep, peer, reason); + array_foreach_elem(&queues, queue) + http_client_queue_connection_failure(queue, peer, reason); } void http_client_peer_connection_lost(struct http_client_peer *peer, @@ -1354,12 +1354,12 @@ void http_client_peer_connection_lost(struct http_client_peer *peer, unsigned int http_client_peer_active_connections(struct http_client_peer *peer) { - struct http_client_connection *const *conn_idx; + struct http_client_connection *conn; unsigned int active = 0; /* Find idle connections */ - array_foreach(&peer->conns, conn_idx) { - if (http_client_connection_is_active(*conn_idx)) + array_foreach_elem(&peer->conns, conn) { + if (http_client_connection_is_active(conn)) active++; } diff --git a/src/lib-http/http-client-queue.c b/src/lib-http/http-client-queue.c index 9032b2a45a..5c7915a7ec 100644 --- a/src/lib-http/http-client-queue.c +++ b/src/lib-http/http-client-queue.c @@ -37,11 +37,9 @@ static struct http_client_queue * http_client_queue_find(struct http_client_host *host, const struct http_client_peer_addr *addr) { - struct http_client_queue *const *queue_idx; - - array_foreach_modifiable(&host->queues, queue_idx) { - struct http_client_queue *queue = *queue_idx; + struct http_client_queue *queue; + array_foreach_elem(&host->queues, queue) { if (http_client_peer_addr_cmp(&queue->addr, addr) == 0) return queue; } @@ -117,7 +115,7 @@ http_client_queue_get(struct http_client_host *host, void http_client_queue_free(struct http_client_queue *queue) { - struct http_client_peer *const *peer_idx; + struct http_client_peer *peer; ARRAY_TYPE(http_client_peer) peers; e_debug(queue->event, "Destroy"); @@ -135,8 +133,8 @@ void http_client_queue_free(struct http_client_queue *queue) t_array_init(&peers, array_count(&queue->pending_peers)); array_copy(&peers.arr, 0, &queue->pending_peers.arr, 0, array_count(&queue->pending_peers)); - array_foreach(&peers, peer_idx) - http_client_peer_unlink_queue(*peer_idx, queue); + array_foreach_elem(&peers, peer) + http_client_peer_unlink_queue(peer, queue); array_free(&queue->pending_peers); /* Abort all requests */ @@ -167,16 +165,14 @@ http_client_queue_fail_full(struct http_client_queue *queue, unsigned int status, const char *error, bool all) { ARRAY_TYPE(http_client_request) *req_arr, treqs; - struct http_client_request **req_idx; + struct http_client_request *req; unsigned int retained = 0; /* Abort requests */ req_arr = &queue->requests; t_array_init(&treqs, array_count(req_arr)); array_copy(&treqs.arr, 0, &req_arr->arr, 0, array_count(req_arr)); - array_foreach_modifiable(&treqs, req_idx) { - struct http_client_request *req = *req_idx; - + array_foreach_elem(&treqs, req) { i_assert(req->state >= HTTP_REQUEST_STATE_QUEUED); if (!all && req->state != HTTP_REQUEST_STATE_QUEUED) @@ -373,17 +369,17 @@ http_client_queue_connection_attempt(struct http_client_queue *queue) if (http_client_peer_is_connected(peer)) { /* Drop any pending peers */ if (array_count(&queue->pending_peers) > 0) { - struct http_client_peer *const *peer_idx; + struct http_client_peer *pending_peer; - array_foreach(&queue->pending_peers, peer_idx) { - if (*peer_idx == peer) { + array_foreach_elem(&queue->pending_peers, pending_peer) { + if (pending_peer == peer) { /* This can happen with shared clients */ continue; } i_assert(http_client_peer_addr_cmp( - &(*peer_idx)->shared->addr, addr) != 0); - http_client_peer_unlink_queue(*peer_idx, queue); + &pending_peer->shared->addr, addr) != 0); + http_client_peer_unlink_queue(pending_peer, queue); } array_clear(&queue->pending_peers); } @@ -392,17 +388,17 @@ http_client_queue_connection_attempt(struct http_client_queue *queue) http_client_peer_trigger_request_handler(queue->cur_peer); } else { - struct http_client_peer *const *peer_idx; + struct http_client_peer *pending_peer; unsigned int msecs; bool new_peer = TRUE; /* Not already connected, wait for connections */ /* We may be waiting for this peer already */ - array_foreach(&queue->pending_peers, peer_idx) { + array_foreach_elem(&queue->pending_peers, pending_peer) { if (http_client_peer_addr_cmp( - &(*peer_idx)->shared->addr, addr) == 0) { - i_assert(*peer_idx == peer); + &pending_peer->shared->addr, addr) == 0) { + i_assert(pending_peer == peer); new_peer = FALSE; break; } @@ -483,23 +479,23 @@ void http_client_queue_connection_success(struct http_client_queue *queue, a connection is successfully created, so pending_peers array may be empty. */ if (array_count(&queue->pending_peers) > 0) { - struct http_client_peer *const *peer_idx; + struct http_client_peer *pending_peer; - array_foreach(&queue->pending_peers, peer_idx) { - if (*peer_idx == peer) { + array_foreach_elem(&queue->pending_peers, pending_peer) { + if (pending_peer == peer) { /* Don't drop any connections to the successfully connected peer, even if some of the connections are pending. they may be intended for urgent requests. */ i_assert(queue->cur_peer == NULL); - queue->cur_peer = *peer_idx; + queue->cur_peer = pending_peer; continue; } /* Unlink this queue from the peer; if this was the last/only queue, the peer will be freed, closing all connections. */ - http_client_peer_unlink_queue(*peer_idx, queue); + http_client_peer_unlink_queue(pending_peer, queue); } array_clear(&queue->pending_peers); diff --git a/src/lib-http/http-client.c b/src/lib-http/http-client.c index 909b71fd4c..61f69c2b7c 100644 --- a/src/lib-http/http-client.c +++ b/src/lib-http/http-client.c @@ -384,13 +384,11 @@ int http_client_init_ssl_ctx(struct http_client *client, const char **error_r) static void http_client_handle_request_errors(struct http_client *client) { - struct http_client_request *const *req_idx; + struct http_client_request *req; timeout_remove(&client->to_failing_requests); - array_foreach(&client->delayed_failing_requests, req_idx) { - struct http_client_request *req = *req_idx; - + array_foreach_elem(&client->delayed_failing_requests, req) { i_assert(req->refcount == 1); http_client_request_error_delayed(&req); } diff --git a/src/lib-http/http-message-parser.c b/src/lib-http/http-message-parser.c index e5eb7a76ee..a42bddde1f 100644 --- a/src/lib-http/http-message-parser.c +++ b/src/lib-http/http-message-parser.c @@ -434,12 +434,12 @@ static int http_message_parse_eoh(struct http_message_parser *parser) /* handle HTTP/1.0 persistence */ if (msg->version_major == 1 && msg->version_minor == 0 && !msg->connection_close) { - const char *const *option; + const char *option; msg->connection_close = TRUE; if (array_is_created(&msg->connection_options)) { - array_foreach(&msg->connection_options, option) { - if (strcasecmp(*option, "Keep-Alive") == 0) { + array_foreach_elem(&msg->connection_options, option) { + if (strcasecmp(option, "Keep-Alive") == 0) { msg->connection_close = FALSE; break; } diff --git a/src/lib-http/http-request.c b/src/lib-http/http-request.c index 7ea9cfc1aa..aed9975201 100644 --- a/src/lib-http/http-request.c +++ b/src/lib-http/http-request.c @@ -9,12 +9,12 @@ bool http_request_has_connection_option(const struct http_request *req, const char *option) { - const char *const *opt_idx; + const char *opt; if (!array_is_created(&req->connection_options)) return FALSE; - array_foreach(&req->connection_options, opt_idx) { - if (strcasecmp(*opt_idx, option) == 0) + array_foreach_elem(&req->connection_options, opt) { + if (strcasecmp(opt, option) == 0) return TRUE; } return FALSE; diff --git a/src/lib-http/http-response.c b/src/lib-http/http-response.c index a9485aeb6b..e85a73029f 100644 --- a/src/lib-http/http-response.c +++ b/src/lib-http/http-response.c @@ -22,12 +22,12 @@ http_response_init(struct http_response *resp, bool http_response_has_connection_option(const struct http_response *resp, const char *option) { - const char *const *opt_idx; + const char *opt; if (!array_is_created(&resp->connection_options)) return FALSE; - array_foreach(&resp->connection_options, opt_idx) { - if (strcasecmp(*opt_idx, option) == 0) + array_foreach_elem(&resp->connection_options, opt) { + if (strcasecmp(opt, option) == 0) return TRUE; } return FALSE; diff --git a/src/lib-http/http-server-resource.c b/src/lib-http/http-server-resource.c index 48e946b8f9..27a88fe62b 100644 --- a/src/lib-http/http-server-resource.c +++ b/src/lib-http/http-server-resource.c @@ -163,7 +163,7 @@ http_server_resource_create(struct http_server *server, pool_t pool, void http_server_resource_free(struct http_server_resource **_res) { struct http_server_resource *res = *_res; - struct http_server_location *const *locp; + struct http_server_location *loc; if (res == NULL) return; @@ -177,8 +177,8 @@ void http_server_resource_free(struct http_server_resource **_res) res->destroy_callback = NULL; } - array_foreach(&res->locations, locp) - http_server_location_remove(res->server, *locp); + array_foreach_elem(&res->locations, loc) + http_server_location_remove(res->server, loc); event_unref(&res->event); pool_unref(&res->pool); diff --git a/src/lib-http/http-server-response.c b/src/lib-http/http-server-response.c index f4b7f55bdf..eaa1af2369 100644 --- a/src/lib-http/http-server-response.c +++ b/src/lib-http/http-server-response.c @@ -85,10 +85,10 @@ void http_server_response_request_free(struct http_server_response *resp) str_free(&resp->headers); if (array_is_created(&resp->perm_headers)) { - char **headers; + char *headers; - array_foreach_modifiable(&resp->perm_headers, headers) - i_free(*headers); + array_foreach_elem(&resp->perm_headers, headers) + i_free(headers); array_free(&resp->perm_headers); } } diff --git a/src/lib-http/http-server.c b/src/lib-http/http-server.c index 1970ae76f9..dd89a168c9 100644 --- a/src/lib-http/http-server.c +++ b/src/lib-http/http-server.c @@ -67,14 +67,14 @@ struct http_server *http_server_init(const struct http_server_settings *set) void http_server_deinit(struct http_server **_server) { struct http_server *server = *_server; - struct http_server_resource **resp; + struct http_server_resource *res; *_server = NULL; connection_list_deinit(&server->conn_list); - array_foreach_modifiable(&server->resources, resp) - http_server_resource_free(resp); + array_foreach_elem(&server->resources, res) + http_server_resource_free(&res); i_assert(array_count(&server->locations) == 0); if (server->ssl_ctx != NULL)