void passdb_unregister_module(struct passdb_module_interface *iface)
{
- struct passdb_module_interface *const *ifaces;
unsigned int idx;
- array_foreach(&passdb_interfaces, ifaces) {
- if (*ifaces == iface) {
- idx = array_foreach_idx(&passdb_interfaces, ifaces);
- array_delete(&passdb_interfaces, idx, 1);
- return;
- }
- }
- i_panic("passdb_unregister_module(%s): Not registered", iface->name);
+ if (!array_lsearch_ptr_idx(&passdb_interfaces, iface, &idx))
+ i_panic("passdb_unregister_module(%s): Not registered", iface->name);
+ array_delete(&passdb_interfaces, idx, 1);
}
bool passdb_get_credentials(struct auth_request *auth_request,
if (--passdb->init_refcount > 0)
return;
- struct passdb_module *const *passdbs;
- unsigned int i, count;
-
- passdbs = array_get(&passdb_modules, &count);
- for (i = 0; i < count; i++) {
- if (passdbs[i] == passdb) {
- array_delete(&passdb_modules, i, 1);
- break;
- }
- }
- i_assert(i < count);
+ unsigned int i;
+ if (!array_lsearch_ptr_idx(&passdb_modules, passdb, &i))
+ i_unreached();
+ array_delete(&passdb_modules, i, 1);
if (passdb->iface.deinit != NULL)
passdb->iface.deinit(passdb);
void userdb_unregister_module(struct userdb_module_interface *iface)
{
- struct userdb_module_interface *const *ifaces;
unsigned int idx;
- array_foreach(&userdb_interfaces, ifaces) {
- if (*ifaces == iface) {
- idx = array_foreach_idx(&userdb_interfaces, ifaces);
- array_delete(&userdb_interfaces, idx, 1);
- return;
- }
- }
- i_panic("userdb_unregister_module(%s): Not registered", iface->name);
+ if (!array_lsearch_ptr_idx(&userdb_interfaces, iface, &idx))
+ i_panic("userdb_unregister_module(%s): Not registered", iface->name);
+ array_delete(&userdb_interfaces, idx, 1);
}
uid_t userdb_parse_uid(struct auth_request *request, const char *str)
if (--userdb->init_refcount > 0)
return;
- struct userdb_module *const *userdbs;
- unsigned int i, count;
-
- userdbs = array_get(&userdb_modules, &count);
- for (i = 0; i < count; i++) {
- if (userdbs[i] == userdb) {
- array_delete(&userdb_modules, i, 1);
- break;
- }
- }
- i_assert(i < count);
+ unsigned int i;
+ if (!array_lsearch_ptr_idx(&userdb_modules, userdb, &i))
+ i_unreached();
+ array_delete(&userdb_modules, i, 1);
if (userdb->iface->deinit != NULL)
userdb->iface->deinit(userdb);
void dict_driver_unregister(struct dict *driver)
{
- struct dict *const *dicts;
- unsigned int idx = UINT_MAX;
+ unsigned int idx;
- array_foreach(&dict_drivers, dicts) {
- if (*dicts == driver) {
- idx = array_foreach_idx(&dict_drivers, dicts);
- break;
- }
- }
- i_assert(idx != UINT_MAX);
+ if (!array_lsearch_ptr_idx(&dict_drivers, driver, &idx))
+ i_unreached();
array_delete(&dict_drivers, idx, 1);
if (array_count(&dict_drivers) == 0)
{
struct http_client_peer *peer = conn->peer;
struct http_client_peer_pool *ppool = conn->ppool;
- ARRAY_TYPE(http_client_connection) *conn_arr;
- struct http_client_connection *const *conn_idx;
+ unsigned int idx;
/* Remove from pending lists */
- conn_arr = &ppool->pending_conns;
- array_foreach(conn_arr, conn_idx) {
- if (*conn_idx == conn) {
- array_delete(conn_arr,
- array_foreach_idx(conn_arr, conn_idx), 1);
- break;
- }
- }
+ if (!array_lsearch_ptr_idx(&ppool->pending_conns, conn, &idx))
+ i_unreached();
+ array_delete(&ppool->pending_conns, idx, 1);
if (peer == NULL)
return;
- conn_arr = &peer->pending_conns;
- array_foreach(conn_arr, conn_idx) {
- if (*conn_idx == conn) {
- array_delete(conn_arr,
- array_foreach_idx(conn_arr, conn_idx), 1);
- break;
- }
- }
+ if (!array_lsearch_ptr_idx(&peer->pending_conns, conn, &idx))
+ i_unreached();
+ array_delete(&peer->pending_conns, idx, 1);
}
static inline void
http_client_connection_detach_peer(struct http_client_connection *conn)
{
struct http_client_peer *peer = conn->peer;
- struct http_client_connection *const *conn_idx;
- ARRAY_TYPE(http_client_connection) *conn_arr;
- bool found = FALSE;
+ unsigned int idx;
if (peer == NULL)
return;
http_client_peer_ref(peer);
- conn_arr = &peer->conns;
- array_foreach(conn_arr, conn_idx) {
- if (*conn_idx == conn) {
- array_delete(conn_arr,
- array_foreach_idx(conn_arr, conn_idx), 1);
- found = TRUE;
- break;
- }
- }
- i_assert(found);
+ if (!array_lsearch_ptr_idx(&peer->conns, conn, &idx))
+ i_unreached();
+ array_delete(&peer->conns, idx, 1);
- conn_arr = &peer->pending_conns;
- array_foreach(conn_arr, conn_idx) {
- if (*conn_idx == conn) {
- array_delete(conn_arr,
- array_foreach_idx(conn_arr, conn_idx), 1);
- break;
- }
- }
+ if (array_lsearch_ptr_idx(&peer->pending_conns, conn, &idx))
+ array_delete(&peer->pending_conns, idx, 1);
conn->peer = NULL;
e_debug(conn->event, "Detached peer");
static void
http_client_connection_stop_idle(struct http_client_connection *conn)
{
- struct http_client_connection *const *conn_idx;
- ARRAY_TYPE(http_client_connection) *conn_arr;
+ unsigned int idx;
timeout_remove(&conn->to_idle);
conn->idle = FALSE;
- conn_arr = &conn->ppool->idle_conns;
- array_foreach(conn_arr, conn_idx) {
- if (*conn_idx == conn) {
- array_delete(conn_arr,
- array_foreach_idx(conn_arr, conn_idx), 1);
- break;
- }
- }
+ if (array_lsearch_ptr_idx(&conn->ppool->idle_conns, conn, &idx))
+ array_delete(&conn->ppool->idle_conns, idx, 1);
}
void http_client_connection_claim_idle(struct http_client_connection *conn,
http_client_connection_disconnect(struct http_client_connection *conn)
{
struct http_client_peer_pool *ppool = conn->ppool;
- ARRAY_TYPE(http_client_connection) *conn_arr;
- struct http_client_connection *const *conn_idx;
+ unsigned int idx;
if (conn->disconnected)
return;
timeout_remove(&conn->to_response);
/* Remove this connection from the lists */
- conn_arr = &ppool->conns;
- array_foreach(conn_arr, conn_idx) {
- if (*conn_idx == conn) {
- array_delete(conn_arr,
- array_foreach_idx(conn_arr, conn_idx), 1);
- break;
- }
- }
- conn_arr = &ppool->pending_conns;
- array_foreach(conn_arr, conn_idx) {
- if (*conn_idx == conn) {
- array_delete(conn_arr,
- array_foreach_idx(conn_arr, conn_idx), 1);
- break;
- }
- }
+ if (!array_lsearch_ptr_idx(&ppool->conns, conn, &idx))
+ i_unreached();
+ array_delete(&ppool->conns, idx, 1);
+
+ if (array_lsearch_ptr_idx(&ppool->pending_conns, conn, &idx))
+ array_delete(&ppool->pending_conns, idx, 1);
http_client_connection_detach_peer(conn);
bool http_client_peer_have_queue(struct http_client_peer *peer,
struct http_client_queue *queue)
{
- struct http_client_queue *const *queue_idx;
-
- array_foreach(&peer->queues, queue_idx) {
- if (*queue_idx == queue)
- return TRUE;
- }
- return FALSE;
+ return array_lsearch_ptr(&peer->queues, queue) != NULL;
}
void http_client_peer_link_queue(struct http_client_peer *peer,
void http_client_peer_unlink_queue(struct http_client_peer *peer,
struct http_client_queue *queue)
{
- struct http_client_queue *const *queue_idx;
+ unsigned int idx;
- array_foreach(&peer->queues, queue_idx) {
- if (*queue_idx == queue) {
- array_delete(&peer->queues,
- array_foreach_idx(&peer->queues, queue_idx), 1);
+ if (array_lsearch_ptr_idx(&peer->queues, queue, &idx))
+ array_delete(&peer->queues, idx, 1);
- e_debug(peer->event,
- "Unlinked queue %s (%d queues linked)",
- queue->name, array_count(&peer->queues));
+ e_debug(peer->event,
+ "Unlinked queue %s (%d queues linked)",
+ queue->name, array_count(&peer->queues));
- if (array_count(&peer->queues) == 0)
- http_client_peer_check_idle(peer);
- return;
- }
- }
+ if (array_count(&peer->queues) == 0)
+ http_client_peer_check_idle(peer);
}
struct http_client_request *
const char *https_name = http_client_peer_addr_get_https_name(addr);
struct http_client_host *host = queue->host;
unsigned int ips_count = http_client_host_get_ips_count(host);
- struct http_client_peer *const *peer_idx;
unsigned int num_requests =
array_count(&queue->queued_requests) +
array_count(&queue->queued_urgent_requests);
i_assert(queue->cur_peer == NULL || queue->cur_peer == peer);
queue->cur_peer = NULL;
} else {
- bool found = FALSE;
+ unsigned int idx;
i_assert(queue->cur_peer == NULL);
/* We're still doing the initial connections to this hport. if
we're also doing parallel connections with soft timeouts
(pending_peer_count>1), wait for them to finish first. */
- array_foreach(&queue->pending_peers, peer_idx) {
- if (*peer_idx == peer) {
- array_delete(&queue->pending_peers,
- array_foreach_idx(
- &queue->pending_peers,
- peer_idx), 1);
- found = TRUE;
- break;
- }
- }
- i_assert(found);
+ if (!array_lsearch_ptr_idx(&queue->pending_peers, peer, &idx))
+ i_unreached();
+ array_delete(&queue->pending_peers, idx, 1);
if (array_count(&queue->pending_peers) > 0) {
e_debug(queue->event,
"Waiting for remaining pending peers.");
void http_client_queue_peer_disconnected(struct http_client_queue *queue,
struct http_client_peer *peer)
{
- struct http_client_peer *const *peer_idx;
+ unsigned int idx;
if (queue->cur_peer == peer) {
queue->cur_peer = NULL;
return;
}
- array_foreach(&queue->pending_peers, peer_idx) {
- if (*peer_idx == peer) {
- array_delete(&queue->pending_peers,
- array_foreach_idx(&queue->pending_peers,
- peer_idx), 1);
- break;
- }
- }
+ if (!array_lsearch_ptr_idx(&queue->pending_peers, peer, &idx))
+ i_unreached();
+ array_delete(&queue->pending_peers, idx, 1);
}
/*
/* Drop from queue */
if (req->urgent) {
- reqs = array_get_modifiable(&queue->queued_urgent_requests,
- &count);
- for (i = 0; i < count; i++) {
- if (reqs[i] == req) {
- array_delete(&queue->queued_urgent_requests,
- i, 1);
- break;
- }
- }
+ if (array_lsearch_ptr_idx(&queue->queued_urgent_requests,
+ req, &i))
+ array_delete(&queue->queued_urgent_requests, i, 1);
} else {
- reqs = array_get_modifiable(&queue->queued_requests, &count);
- for (i = 0; i < count; i++) {
- if (reqs[i] == req) {
- array_delete(&queue->queued_requests, i, 1);
- break;
- }
- }
+ if (array_lsearch_ptr_idx(&queue->queued_requests, req, &i))
+ array_delete(&queue->queued_requests, i, 1);
}
/* Drop from delay queue */
void http_client_remove_request_error(struct http_client *client,
struct http_client_request *req)
{
- struct http_client_request *const *reqs;
- unsigned int i, count;
-
- reqs = array_get(&client->delayed_failing_requests, &count);
- for (i = 0; i < count; i++) {
- if (reqs[i] == req) {
- array_delete(&client->delayed_failing_requests, i, 1);
- return;
- }
- }
+ unsigned int i;
+
+ if (!array_lsearch_ptr_idx(&client->delayed_failing_requests,
+ req, &i))
+ i_unreached();
+ array_delete(&client->delayed_failing_requests, i, 1);
}
/*
http_server_location_remove(struct http_server *server,
struct http_server_location *loc)
{
- struct http_server_location *const *locp;
-
- array_foreach(&server->locations, locp) {
- if (*locp == loc) {
- array_delete(
- &server->locations,
- array_foreach_idx(&server->locations, locp), 1);
- return;
- }
- }
+ unsigned int idx;
+
+ if (!array_lsearch_ptr_idx(&server->locations, loc, &idx))
+ i_unreached();
+ array_delete(&server->locations, idx, 1);
}
/*
static void mail_index_record_map_unlink(struct mail_index_map *map)
{
- struct mail_index_map *const *maps;
- unsigned int idx = UINT_MAX;
-
- array_foreach(&map->rec_map->maps, maps) {
- if (*maps == map) {
- idx = array_foreach_idx(&map->rec_map->maps, maps);
- break;
- }
- }
- i_assert(idx != UINT_MAX);
+ unsigned int idx;
+ if (!array_lsearch_ptr_idx(&map->rec_map->maps, map, &idx))
+ i_unreached();
array_delete(&map->rec_map->maps, idx, 1);
+
if (array_count(&map->rec_map->maps) == 0) {
mail_index_record_map_free(map, map->rec_map);
map->rec_map = NULL;
static void driver_cassandra_result_unlink(struct cassandra_db *db,
struct cassandra_result *result)
{
- struct cassandra_result *const *results;
- unsigned int i, count;
+ unsigned int i;
- results = array_get(&db->results, &count);
- for (i = 0; i < count; i++) {
- if (results[i] == result) {
- array_delete(&db->results, i, 1);
- return;
- }
- }
- i_unreached();
+ if (!array_lsearch_ptr_idx(&db->results, result, &i))
+ i_unreached();
+ array_delete(&db->results, i, 1);
}
static void driver_cassandra_log_result(struct cassandra_result *result,
cassandra_prepared_statement_remove_pending(struct cassandra_sql_statement *stmt)
{
struct cassandra_sql_prepared_statement *prep = stmt->prep;
- struct cassandra_sql_statement *const *iter_stmt;
+ unsigned int idx;
if (prep == NULL)
return;
- array_foreach(&prep->pending_statements, iter_stmt) {
- if (stmt == *iter_stmt) {
- array_delete(&prep->pending_statements,
- array_foreach_idx(&prep->pending_statements, iter_stmt), 1);
- break;
- }
- }
+ if (array_lsearch_ptr_idx(&prep->pending_statements, stmt, &idx))
+ array_delete(&prep->pending_statements, idx, 1);
}
static void cassandra_sql_statement_free(struct cassandra_sql_statement *stmt)
void sql_driver_unregister(const struct sql_db *driver)
{
- const struct sql_db *const *drivers;
- unsigned int i, count;
+ unsigned int i;
- drivers = array_get(&sql_drivers, &count);
- for (i = 0; i < count; i++) {
- if (drivers[i] == driver) {
- array_delete(&sql_drivers, i, 1);
- break;
- }
- }
+ if (!array_lsearch_ptr_idx(&sql_drivers, driver, &i))
+ i_unreached();
+ array_delete(&sql_drivers, i, 1);
}
int sql_init_auto(struct event *event, struct sql_db **db_r,
void *context)
{
struct imapc_fetch_request *request = context;
- struct imapc_fetch_request *const *requests;
struct imapc_mail *mail;
struct imapc_mailbox *mbox = NULL;
- unsigned int i, count;
+ unsigned int i;
array_foreach_elem(&request->mails, mail) {
i_assert(mail->fetch_count > 0);
}
i_assert(mbox != NULL);
- requests = array_get(&mbox->fetch_requests, &count);
- for (i = 0; i < count; i++) {
- if (requests[i] == request) {
- array_delete(&mbox->fetch_requests, i, 1);
- break;
- }
- }
- i_assert(i < count);
+ if (!array_lsearch_ptr_idx(&mbox->fetch_requests, request, &i))
+ i_unreached();
+ array_delete(&mbox->fetch_requests, i, 1);
array_free(&request->mails);
i_free(request);
void mail_storage_hooks_remove_internal(const struct mail_storage_hooks *hooks)
{
- const struct mail_storage_hooks *const *old_hooks;
- unsigned int idx = UINT_MAX;
-
- array_foreach(&internal_hooks, old_hooks) {
- if (*old_hooks == hooks) {
- idx = array_foreach_idx(&internal_hooks, old_hooks);
- break;
- }
- }
- i_assert(idx != UINT_MAX);
+ unsigned int idx;
+ if (!array_lsearch_ptr_idx(&internal_hooks, hooks, &idx))
+ i_unreached();
array_delete(&internal_hooks, idx, 1);
}
void mail_storage_class_unregister(struct mail_storage *storage_class)
{
- struct mail_storage *const *classes;
- unsigned int i, count;
+ unsigned int i;
- classes = array_get(&mail_storage_classes, &count);
- for (i = 0; i < count; i++) {
- if (classes[i] == storage_class) {
- array_delete(&mail_storage_classes, i, 1);
- break;
- }
- }
+ if (!array_lsearch_ptr_idx(&mail_storage_classes, storage_class, &i))
+ i_unreached();
+ array_delete(&mail_storage_classes, i, 1);
}
struct mail_storage *mail_storage_find_class(const char *name)
{
struct mail_private *pmail =
container_of(mail, struct mail_private, mail);
- struct mail *const *mailp;
-
- array_foreach(&ctx->mails, mailp) {
- if (*mailp == mail) {
- pmail->search_mail = FALSE;
- array_delete(&ctx->mails,
- array_foreach_idx(&ctx->mails, mailp), 1);
- return;
- }
- }
- i_unreached();
+ unsigned int idx;
+
+ if (!array_lsearch_ptr_idx(&ctx->mails, mail, &idx))
+ i_unreached();
+ pmail->search_mail = FALSE;
+ array_delete(&ctx->mails, idx, 1);
}
int mailbox_search_result_build(struct mailbox_transaction_context *t,
void mailbox_search_result_free(struct mail_search_result **_result)
{
struct mail_search_result *result = *_result;
- struct mail_search_result *const *results;
- unsigned int i, count;
+ unsigned int i;
*_result = NULL;
- results = array_get(&result->box->search_results, &count);
- for (i = 0; i < count; i++) {
- if (results[i] == result) {
- array_delete(&result->box->search_results, i, 1);
- break;
- }
- }
- i_assert(i != count);
+ if (!array_lsearch_ptr_idx(&result->box->search_results, result, &i))
+ i_unreached();
+ array_delete(&result->box->search_results, i, 1);
if (result->search_args != NULL)
mail_search_args_unref(&result->search_args);
if (timeout->item.idx != UINT_MAX)
priorityq_remove(timeout->ioloop->timeouts, &timeout->item);
else if (!timeout->one_shot && timeout->msecs > 0) {
- struct timeout *const *to_idx;
- array_foreach(&ioloop->timeouts_new, to_idx) {
- if (*to_idx == timeout) {
- array_delete(&ioloop->timeouts_new,
- array_foreach_idx(&ioloop->timeouts_new, to_idx), 1);
- break;
- }
- }
+ unsigned int idx;
+
+ if (!array_lsearch_ptr_idx(&ioloop->timeouts_new, timeout, &idx))
+ i_unreached();
+ array_delete(&ioloop->timeouts_new, idx, 1);
}
timeout_free(timeout);
}
void io_loop_remove_switch_callback(io_switch_callback_t *callback)
{
- io_switch_callback_t *const *callbackp;
unsigned int idx;
- array_foreach(&io_switch_callbacks, callbackp) {
- if (*callbackp == callback) {
- idx = array_foreach_idx(&io_switch_callbacks, callbackp);
- array_delete(&io_switch_callbacks, idx, 1);
- return;
- }
- }
- i_unreached();
+ if (!array_lsearch_ptr_idx(&io_switch_callbacks, callback, &idx))
+ i_unreached();
+ array_delete(&io_switch_callbacks, idx, 1);
}
void io_loop_add_destroy_callback(io_destroy_callback_t *callback)
void io_loop_remove_destroy_callback(io_destroy_callback_t *callback)
{
- io_destroy_callback_t *const *callbackp;
unsigned int idx;
- array_foreach(&io_destroy_callbacks, callbackp) {
- if (*callbackp == callback) {
- idx = array_foreach_idx(&io_destroy_callbacks, callbackp);
- array_delete(&io_destroy_callbacks, idx, 1);
- return;
- }
- }
- i_unreached();
+ if (!array_lsearch_ptr_idx(&io_destroy_callbacks, callback, &idx))
+ i_unreached();
+ array_delete(&io_destroy_callbacks, idx, 1);
}
struct ioloop_context *io_loop_context_new(struct ioloop *ioloop)
const struct event_category *category)
{
struct event_internal_category *internal = category->internal;
- struct event_category *cat;
/* make sure we're always looking for a representative */
i_assert(category == &internal->representative);
- array_foreach_elem(&event->categories, cat) {
- if (cat == category)
- return TRUE;
- }
- return FALSE;
+ return array_lsearch_ptr(&event->categories, category) != NULL;
}
struct event *
void event_unregister_callback(event_callback_t *callback)
{
- event_callback_t *const *callbackp;
+ unsigned int idx;
- array_foreach(&event_handlers, callbackp) {
- if (*callbackp == callback) {
- unsigned int idx =
- array_foreach_idx(&event_handlers, callbackp);
- array_delete(&event_handlers, idx, 1);
- return;
- }
- }
- i_unreached();
+ if (!array_lsearch_ptr_idx(&event_handlers, callback, &idx))
+ i_unreached();
+ array_delete(&event_handlers, idx, 1);
}
void event_category_register_callback(event_category_callback_t *callback)
void event_category_unregister_callback(event_category_callback_t *callback)
{
- event_category_callback_t *const *callbackp;
+ unsigned int idx;
- array_foreach(&event_category_callbacks, callbackp) {
- if (*callbackp == callback) {
- unsigned int idx =
- array_foreach_idx(&event_category_callbacks,
- callbackp);
- array_delete(&event_category_callbacks, idx, 1);
- return;
- }
- }
- i_unreached();
+ if (!array_lsearch_ptr_idx(&event_category_callbacks, callback, &idx))
+ i_unreached();
+ array_delete(&event_category_callbacks, idx, 1);
}
static struct event_passthrough *
{
struct quota *quota;
struct quota_root *root;
- struct mail_namespace *const *namespaces;
- unsigned int i, count;
+ unsigned int i;
quota = ns->owner != NULL ?
quota_get_mail_user_quota(ns->owner) :
}
array_foreach_elem("a->all_roots, root) {
- namespaces = array_get(&root->namespaces, &count);
- for (i = 0; i < count; i++) {
- if (namespaces[i] == ns) {
- array_delete(&root->namespaces, i, 1);
- break;
- }
- }
+ if (array_lsearch_ptr_idx(&root->namespaces, ns, &i))
+ array_delete(&root->namespaces, i, 1);
}
}
submission_backend_add_pending(struct submission_backend *backend)
{
struct client *client = backend->client;
- struct submission_backend *pending_backend;
- array_foreach_elem(&client->pending_backends, pending_backend) {
- if (backend == pending_backend)
- return;
- }
+ if (array_lsearch_ptr(&client->pending_backends, backend) != NULL)
+ return;
array_push_back(&client->pending_backends, &backend);
}
{
struct submission_backend *backend = srcpt->backend;
struct client *client = backend->client;
- struct submission_backend *rcpt_backend;
- bool backend_found = FALSE;
array_push_back(&client->rcpt_to, &srcpt);
- array_foreach_elem(&client->rcpt_backends, rcpt_backend) {
- if (rcpt_backend == backend) {
- backend_found = TRUE;
- break;
- }
- }
- if (!backend_found)
+ if (array_lsearch_ptr(&client->rcpt_backends, backend) == NULL)
array_push_back(&client->rcpt_backends, &backend);
}