static void director_assign_left(struct director *dir)
{
- struct director_connection *conn, *const *connp;
-
- array_foreach(&dir->connections, connp) {
- conn = *connp;
+ struct director_connection *conn;
+ array_foreach_elem(&dir->connections, conn) {
if (conn->in && conn->handshake_received &&
conn->to_disconnect == NULL && conn != dir->left) {
/* either use this or disconnect it */
static bool director_has_outgoing_connections(struct director *dir)
{
- struct director_connection *const *connp;
+ struct director_connection *conn;
- array_foreach(&dir->connections, connp) {
- if (!(*connp)->in && (*connp)->to_disconnect == NULL)
+ array_foreach_elem(&dir->connections, conn) {
+ if (!conn->in && conn->to_disconnect == NULL)
return TRUE;
}
return FALSE;
static void director_send_delayed_syncs(struct director *dir)
{
- struct director_host *const *hostp;
+ struct director_host *host;
i_assert(dir->right != NULL);
e_debug(dir->right->event, "Sending delayed SYNCs");
- array_foreach(&dir->dir_hosts, hostp) {
- if ((*hostp)->delayed_sync_seq == 0)
+ array_foreach_elem(&dir->dir_hosts, host) {
+ if (host->delayed_sync_seq == 0)
continue;
- director_sync_send(dir, *hostp, (*hostp)->delayed_sync_seq,
- (*hostp)->delayed_sync_minor_version,
- (*hostp)->delayed_sync_timestamp,
- (*hostp)->delayed_sync_hosts_hash);
- (*hostp)->delayed_sync_seq = 0;
+ director_sync_send(dir, host, host->delayed_sync_seq,
+ host->delayed_sync_minor_version,
+ host->delayed_sync_timestamp,
+ host->delayed_sync_hosts_hash);
+ host->delayed_sync_seq = 0;
}
}
static void director_disconnect_wrong_lefts(struct director *dir)
{
- struct director_connection *const *connp, *conn;
-
- array_foreach(&dir->connections, connp) {
- conn = *connp;
+ struct director_connection *conn;
+ array_foreach_elem(&dir->connections, conn) {
if (conn->in && conn != dir->left && conn->me_received &&
conn->to_disconnect == NULL &&
director_host_cmp_to_self(dir->left->host, conn->host,
static void director_connection_send_directors(struct director_connection *conn)
{
- struct director_host *const *hostp;
+ struct director_host *host;
string_t *str = t_str_new(64);
- array_foreach(&conn->dir->dir_hosts, hostp) {
- if ((*hostp)->removed)
+ array_foreach_elem(&conn->dir->dir_hosts, host) {
+ if (host->removed)
continue;
str_truncate(str, 0);
str_printfa(str, "DIRECTOR\t%s\t%u\n",
- (*hostp)->ip_str, (*hostp)->port);
+ host->ip_str, host->port);
director_connection_send(conn, str_c(str));
}
}
static void
director_connection_send_hosts(struct director_connection *conn)
{
- struct mail_host *const *hostp;
+ struct mail_host *host;
bool send_updowns;
string_t *str = t_str_new(128);
str_printfa(str, "HOST-HAND-START\t%u\n",
conn->dir->ring_handshaked ? 1 : 0);
- array_foreach(mail_hosts_get(conn->dir->mail_hosts), hostp) {
- struct mail_host *host = *hostp;
+ array_foreach_elem(mail_hosts_get(conn->dir->mail_hosts), host) {
const char *host_tag = mail_host_get_tag(host);
str_printfa(str, "HOST\t%s\t%u",
director_host_lookup(struct director *dir, const struct ip_addr *ip,
in_port_t port)
{
- struct director_host *const *hostp;
+ struct director_host *host;
- array_foreach(&dir->dir_hosts, hostp) {
- if (net_ip_compare(&(*hostp)->ip, ip) &&
- (*hostp)->port == port)
- return *hostp;
+ array_foreach_elem(&dir->dir_hosts, host) {
+ if (net_ip_compare(&host->ip, ip) && host->port == port)
+ return host;
}
return NULL;
}
struct director_host *
director_host_lookup_ip(struct director *dir, const struct ip_addr *ip)
{
- struct director_host *const *hostp;
+ struct director_host *host;
- array_foreach(&dir->dir_hosts, hostp) {
- if (net_ip_compare(&(*hostp)->ip, ip))
- return *hostp;
+ array_foreach_elem(&dir->dir_hosts, host) {
+ if (net_ip_compare(&host->ip, ip))
+ return host;
}
return NULL;
}
director_has_outgoing_connection(struct director *dir,
struct director_host *host)
{
- struct director_connection *const *connp;
+ struct director_connection *conn;
- array_foreach(&dir->connections, connp) {
- if (director_connection_get_host(*connp) == host &&
- !director_connection_is_incoming(*connp))
+ array_foreach_elem(&dir->connections, conn) {
+ if (director_connection_get_host(conn) == host &&
+ !director_connection_is_incoming(conn))
return TRUE;
}
return FALSE;
static bool director_wait_for_others(struct director *dir)
{
- struct director_host *const *hostp;
+ struct director_host *host;
/* don't assume we're alone until we've attempted to connect
to others for a while */
if (dir->ring_first_alone == 0)
dir->ring_first_alone = ioloop_time;
/* reset all failures and try again */
- array_foreach(&dir->dir_hosts, hostp) {
- (*hostp)->last_network_failure = 0;
- (*hostp)->last_protocol_failure = 0;
+ array_foreach_elem(&dir->dir_hosts, host) {
+ host->last_network_failure = 0;
+ host->last_protocol_failure = 0;
}
timeout_remove(&dir->to_reconnect);
dir->to_reconnect = timeout_add(DIRECTOR_QUICK_RECONNECT_TIMEOUT_MSECS,
static bool
director_has_any_outgoing_connections(struct director *dir)
{
- struct director_connection *const *connp;
+ struct director_connection *conn;
- array_foreach(&dir->connections, connp) {
- if (!director_connection_is_incoming(*connp))
+ array_foreach_elem(&dir->connections, conn) {
+ if (!director_connection_is_incoming(conn))
return TRUE;
}
return FALSE;
void director_sync_freeze(struct director *dir)
{
- struct director_connection *const *connp;
+ struct director_connection *conn;
i_assert(!dir->sync_frozen);
i_assert(!dir->sync_pending);
- array_foreach(&dir->connections, connp)
- director_connection_cork(*connp);
+ array_foreach_elem(&dir->connections, conn)
+ director_connection_cork(conn);
dir->sync_frozen = TRUE;
}
void director_sync_thaw(struct director *dir)
{
- struct director_connection *const *connp;
+ struct director_connection *conn;
i_assert(dir->sync_frozen);
dir->sync_pending = FALSE;
director_sync(dir);
}
- array_foreach(&dir->connections, connp)
- director_connection_uncork(*connp);
+ array_foreach_elem(&dir->connections, conn)
+ director_connection_uncork(conn);
}
void director_notify_ring_added(struct director_host *added_host,
void director_resend_hosts(struct director *dir)
{
- struct mail_host *const *hostp;
+ struct mail_host *host;
- array_foreach(mail_hosts_get(dir->mail_hosts), hostp)
- director_send_host(dir, dir->self_host, NULL, *hostp);
+ array_foreach_elem(mail_hosts_get(dir->mail_hosts), host)
+ director_send_host(dir, dir->self_host, NULL, host);
}
void director_update_host(struct director *dir, struct director_host *src,
void director_update_user(struct director *dir, struct director_host *src,
struct user *user)
{
- struct director_connection *const *connp;
+ struct director_connection *conn;
i_assert(src != NULL);
i_assert(!user->weak);
- array_foreach(&dir->connections, connp) {
- if (director_connection_get_host(*connp) == src)
+ array_foreach_elem(&dir->connections, conn) {
+ if (director_connection_get_host(conn) == src)
continue;
- if (director_connection_get_minor_version(*connp) >= DIRECTOR_VERSION_USER_TIMESTAMP) {
- director_connection_send(*connp, t_strdup_printf(
+ if (director_connection_get_minor_version(conn) >= DIRECTOR_VERSION_USER_TIMESTAMP) {
+ director_connection_send(conn, t_strdup_printf(
"USER\t%u\t%s\t%u\n", user->username_hash, user->host->ip_str,
user->timestamp));
} else {
- director_connection_send(*connp, t_strdup_printf(
+ director_connection_send(conn, t_strdup_printf(
"USER\t%u\t%s\n", user->username_hash, user->host->ip_str));
}
}
void director_user_killed(struct director *dir, unsigned int username_hash)
{
- struct mail_tag *const *tagp;
+ struct mail_tag *tag;
- array_foreach(mail_hosts_get_tags(dir->mail_hosts), tagp)
- director_user_tag_killed(dir, *tagp, username_hash);
+ array_foreach_elem(mail_hosts_get_tags(dir->mail_hosts), tag)
+ director_user_tag_killed(dir, tag, username_hash);
}
static void
struct director_host *orig_src,
unsigned int username_hash)
{
- struct mail_tag *const *tagp;
+ struct mail_tag *tag;
- array_foreach(mail_hosts_get_tags(dir->mail_hosts), tagp) {
- director_user_tag_killed_everywhere(dir, *tagp, src, orig_src,
+ array_foreach_elem(mail_hosts_get_tags(dir->mail_hosts), tag) {
+ director_user_tag_killed_everywhere(dir, tag, src, orig_src,
username_hash);
}
}
struct director_host *src,
unsigned int min_version, const char *cmd)
{
- struct director_connection *const *connp;
+ struct director_connection *conn;
i_assert(src != NULL);
- array_foreach(&dir->connections, connp) {
- if (director_connection_get_host(*connp) != src &&
- director_connection_get_minor_version(*connp) >= min_version)
- director_connection_send(*connp, cmd);
+ array_foreach_elem(&dir->connections, conn) {
+ if (director_connection_get_host(conn) != src &&
+ director_connection_get_minor_version(conn) >= min_version)
+ director_connection_send(conn, cmd);
}
}
doveadm_cmd_host_list(struct doveadm_connection *conn,
const char *const *args ATTR_UNUSED)
{
- struct mail_host *const *hostp;
+ struct mail_host *host;
string_t *str = t_str_new(1024);
- array_foreach(mail_hosts_get(conn->dir->mail_hosts), hostp) {
+ array_foreach_elem(mail_hosts_get(conn->dir->mail_hosts), host) {
str_printfa(str, "%s\t%u\t%u\t",
- (*hostp)->ip_str, (*hostp)->vhost_count,
- (*hostp)->user_count);
- str_append_tabescaped(str, mail_host_get_tag(*hostp));
- str_printfa(str, "\t%c\t%ld", (*hostp)->down ? 'D' : 'U',
- (long)(*hostp)->last_updown_change);
+ host->ip_str, host->vhost_count,
+ host->user_count);
+ str_append_tabescaped(str, mail_host_get_tag(host));
+ str_printfa(str, "\t%c\t%ld", host->down ? 'D' : 'U',
+ (long)host->last_updown_change);
str_append_c(str, '\n');
}
str_append_c(str, '\n');
const char *const *args ATTR_UNUSED)
{
struct director *dir = conn->dir;
- struct director_host *const *hostp;
+ struct director_host *host;
string_t *str = t_str_new(1024);
- struct director_connection *const *connp;
+ struct director_connection *dir_conn;
ARRAY(struct director_host *) hosts;
t_array_init(&hosts, array_count(&dir->dir_hosts));
array_sort(&hosts, director_host_cmp_p);
/* first show incoming connections that have no known host yet */
- array_foreach(&dir->connections, connp) {
- if (director_connection_get_host(*connp) == NULL)
- doveadm_director_connection_append(dir, *connp, NULL, str);
+ array_foreach_elem(&dir->connections, dir_conn) {
+ if (director_connection_get_host(dir_conn) == NULL)
+ doveadm_director_connection_append(dir, dir_conn, NULL, str);
}
/* show other connections and host without connections sorted by host */
- array_foreach(&hosts, hostp) {
- const struct director_host *host = *hostp;
+ array_foreach_elem(&hosts, host) {
bool have_connections = FALSE;
- array_foreach(&dir->connections, connp) {
+ array_foreach_elem(&dir->connections, dir_conn) {
const struct director_host *conn_host =
- director_connection_get_host(*connp);
+ director_connection_get_host(dir_conn);
if (conn_host != host)
continue;
have_connections = TRUE;
- doveadm_director_connection_append(dir, *connp, host, str);
+ doveadm_director_connection_append(dir, dir_conn, host, str);
}
if (!have_connections)
doveadm_director_host_append(dir, host, str);
static void
doveadm_cmd_host_flush_all(struct doveadm_connection *conn)
{
- struct mail_host *const *hostp;
+ struct mail_host *host;
unsigned int total_user_count = 0;
- array_foreach(mail_hosts_get(conn->dir->mail_hosts), hostp) {
- total_user_count += (*hostp)->user_count;
+ array_foreach_elem(mail_hosts_get(conn->dir->mail_hosts), host) {
+ total_user_count += host->user_count;
director_flush_host(conn->dir, conn->dir->self_host,
- NULL, *hostp);
+ NULL, host);
}
e_warning(conn->dir->event,
"Flushed all backend hosts with %u users. This is an unsafe "
static void
mail_tag_vhosts_sort_ring(struct mail_host_list *list, struct mail_tag *tag)
{
- struct mail_host *const *hostp;
+ struct mail_host *host;
/* rebuild vhosts */
array_clear(&tag->vhosts);
- array_foreach(&list->hosts, hostp)
- mail_vhost_add(tag, *hostp);
+ array_foreach_elem(&list->hosts, host)
+ mail_vhost_add(tag, host);
array_sort(&tag->vhosts, mail_vhost_cmp);
}
static void
mail_hosts_sort(struct mail_host_list *list)
{
- struct mail_host *const *hostp;
- struct mail_tag *const *tagp;
+ struct mail_host *host;
+ struct mail_tag *tag;
uint32_t num;
array_sort(&list->hosts, mail_host_cmp);
list->have_vhosts = FALSE;
- array_foreach(&list->tags, tagp) {
- mail_tag_vhosts_sort_ring(list, *tagp);
- if (array_count(&(*tagp)->vhosts) > 0)
+ array_foreach_elem(&list->tags, tag) {
+ mail_tag_vhosts_sort_ring(list, tag);
+ if (array_count(&tag->vhosts) > 0)
list->have_vhosts = TRUE;
}
list->vhosts_unsorted = FALSE;
/* recalculate the hosts_hash */
list->hosts_hash = 0;
- array_foreach(&list->hosts, hostp) {
- num = ((*hostp)->down ? 1 : 0) ^ (*hostp)->vhost_count;
+ array_foreach_elem(&list->hosts, host) {
+ num = (host->down ? 1 : 0) ^ host->vhost_count;
list->hosts_hash = crc32_data_more(list->hosts_hash,
&num, sizeof(num));
- num = net_ip_hash(&(*hostp)->ip);
+ num = net_ip_hash(&host->ip);
list->hosts_hash = crc32_data_more(list->hosts_hash,
&num, sizeof(num));
list->hosts_hash = crc32_str_more(list->hosts_hash,
- (*hostp)->tag->name);
+ host->tag->name);
}
}
struct mail_tag *
mail_tag_find(struct mail_host_list *list, const char *tag_name)
{
- struct mail_tag *const *tagp;
+ struct mail_tag *tag;
- array_foreach(&list->tags, tagp) {
- if (strcmp((*tagp)->name, tag_name) == 0)
- return *tagp;
+ array_foreach_elem(&list->tags, tag) {
+ if (strcmp(tag->name, tag_name) == 0)
+ return tag;
}
return NULL;
}
struct mail_host *
mail_host_lookup(struct mail_host_list *list, const struct ip_addr *ip)
{
- struct mail_host *const *hostp;
+ struct mail_host *host;
if (list->vhosts_unsorted)
mail_hosts_sort(list);
- array_foreach(&list->hosts, hostp) {
- if (net_ip_compare(&(*hostp)->ip, ip))
- return *hostp;
+ array_foreach_elem(&list->hosts, host) {
+ if (net_ip_compare(&host->ip, ip))
+ return host;
}
return NULL;
}
void mail_hosts_set_synced(struct mail_host_list *list)
{
- struct mail_host *const *hostp;
+ struct mail_host *host;
- array_foreach(&list->hosts, hostp)
- (*hostp)->desynced = FALSE;
+ array_foreach_elem(&list->hosts, host)
+ host->desynced = FALSE;
}
unsigned int mail_hosts_hash(struct mail_host_list *list)
bool mail_hosts_have_tags(struct mail_host_list *list)
{
- struct mail_tag *const *tagp;
+ struct mail_tag *tag;
if (list->vhosts_unsorted)
mail_hosts_sort(list);
- array_foreach(&list->tags, tagp) {
- if ((*tagp)->name[0] != '\0' && array_count(&(*tagp)->vhosts) > 0)
+ array_foreach_elem(&list->tags, tag) {
+ if (tag->name[0] != '\0' && array_count(&tag->vhosts) > 0)
return TRUE;
}
return FALSE;
void mail_hosts_deinit(struct mail_host_list **_list)
{
struct mail_host_list *list = *_list;
- struct mail_host *const *hostp;
- struct mail_tag *const *tagp;
+ struct mail_host *host;
+ struct mail_tag *tag;
*_list = NULL;
- array_foreach(&list->tags, tagp)
- mail_tag_free(*tagp);
- array_foreach(&list->hosts, hostp)
- mail_host_free(*hostp);
+ array_foreach_elem(&list->tags, tag)
+ mail_tag_free(tag);
+ array_foreach_elem(&list->hosts, host)
+ mail_host_free(host);
array_free(&list->hosts);
array_free(&list->tags);
i_free(list);
struct mail_host_list *mail_hosts_dup(const struct mail_host_list *src)
{
struct mail_host_list *dest;
- struct mail_host *const *hostp, *dest_host;
+ struct mail_host *host, *dest_host;
dest = mail_hosts_init(src->dir, src->user_expire_secs, src->user_free_hook);
- array_foreach(&src->hosts, hostp) {
- dest_host = mail_host_dup(dest, *hostp);
+ array_foreach_elem(&src->hosts, host) {
+ dest_host = mail_host_dup(dest, host);
array_push_back(&dest->hosts, &dest_host);
}
mail_hosts_sort(dest);
void mail_hosts_sort_users(struct mail_host_list *list)
{
- struct mail_tag *const *tagp;
+ struct mail_tag *tag;
- array_foreach(&list->tags, tagp)
- user_directory_sort((*tagp)->users);
+ array_foreach_elem(&list->tags, tag)
+ user_directory_sort(tag->users);
}
static unsigned int director_total_users_count(void)
{
- struct mail_tag *const *tagp;
+ struct mail_tag *tag;
unsigned int count = 0;
- array_foreach(mail_hosts_get_tags(director->mail_hosts), tagp)
- count += user_directory_count((*tagp)->users);
+ array_foreach_elem(mail_hosts_get_tags(director->mail_hosts), tag)
+ count += user_directory_count(tag->users);
return count;
}
static void director_state_changed(struct director *dir)
{
- struct director_request *const *requestp;
+ struct director_request *request;
ARRAY(struct director_request *) new_requests;
bool ret;
/* if there are any pending client requests, finish them now */
t_array_init(&new_requests, 8);
- array_foreach(&dir->pending_requests, requestp) {
- ret = director_request_continue(*requestp);
+ array_foreach_elem(&dir->pending_requests, request) {
+ ret = director_request_continue(request);
if (!ret) {
/* a) request for a user being killed
b) user is weak */
- array_push_back(&new_requests, requestp);
+ array_push_back(&new_requests, &request);
}
}
array_clear(&dir->pending_requests);
static void notify_connection_input(struct notify_connection *conn)
{
- struct mail_tag *const *tagp;
+ struct mail_tag *tag;
const char *line;
unsigned int hash;
while ((line = i_stream_read_next_line(conn->input)) != NULL) {
if (!director_get_username_hash(conn->dir, line, &hash))
continue;
- array_foreach(mail_hosts_get_tags(conn->dir->mail_hosts), tagp)
- notify_update_user(conn->dir, *tagp, line, hash);
+ array_foreach_elem(mail_hosts_get_tags(conn->dir->mail_hosts), tag)
+ notify_update_user(conn->dir, tag, line, hash);
}
if (conn->input->eof) {
if (conn->fifo)
static void user_move_iters(struct user_directory *dir, struct user *user)
{
- struct user_directory_iter *const *iterp;
+ struct user_directory_iter *iter;
- array_foreach(&dir->iters, iterp) {
- if ((*iterp)->pos == user)
- (*iterp)->pos = user->next;
- if ((*iterp)->stop_after_tail == user) {
- (*iterp)->stop_after_tail =
+ array_foreach_elem(&dir->iters, iter) {
+ if (iter->pos == user)
+ iter->pos = user->next;
+ if (iter->stop_after_tail == user) {
+ iter->stop_after_tail =
user->prev != NULL ? user->prev : user->next;
}
}
void user_directory_sort(struct user_directory *dir)
{
ARRAY(struct user *) users;
- struct user *user, *const *userp;
+ struct user *user;
unsigned int i, users_count = hash_table_count(dir->hash);
dir->sort_pending = FALSE;
/* recreate the linked list */
dir->head = dir->tail = NULL;
- array_foreach(&users, userp)
- DLLIST2_APPEND(&dir->head, &dir->tail, *userp);
+ array_foreach_elem(&users, user)
+ DLLIST2_APPEND(&dir->head, &dir->tail, user);
i_assert(dir->head != NULL &&
dir->head->timestamp <= dir->tail->timestamp);
array_free(&users);