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;
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);
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);
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,
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);
}
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);
}
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);
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);
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)
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);
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);
}
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;
}
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");
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);
}
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;
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 &&
}
/* 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
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;
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)",
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);
}
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,
/* 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,
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++;
}
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;
}
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");
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 */
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)
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);
}
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;
}
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);
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);
}
/* 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;
}
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;
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;
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;
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);
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);
}
}
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)