]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Use array_foreach() more.
authorTimo Sirainen <tss@iki.fi>
Wed, 2 Dec 2009 21:35:51 +0000 (15:35 -0600)
committerTimo Sirainen <tss@iki.fi>
Wed, 2 Dec 2009 21:35:51 +0000 (15:35 -0600)
--HG--
branch : HEAD

21 files changed:
src/auth/auth-client-connection.c
src/auth/auth-master-connection.c
src/auth/auth-worker-server.c
src/auth/passdb.c
src/auth/password-scheme.c
src/auth/userdb.c
src/config/config-parser.c
src/imap/cmd-list.c
src/imap/imap-commands-util.c
src/imap/imap-search.c
src/imap/imap-sync.c
src/lib-dict/dict-file.c
src/lib-dict/dict.c
src/lib-index/mail-index-map.c
src/lmtp/lmtp-proxy.c
src/master/master-settings.c
src/master/service-listen.c
src/master/service-log.c
src/master/service-monitor.c
src/master/service.c
src/ssl-params/main.c

index 7166637287928a0eb30506e92e27dff02f3f5d82..44e3cda46c7969c6530f9b0bb987db47caded52b 100644 (file)
@@ -304,16 +304,17 @@ void auth_client_connection_destroy(struct auth_client_connection **_conn)
 {
         struct auth_client_connection *conn = *_conn;
        struct auth_client_connection *const *clients;
-       unsigned int i, count;
+       unsigned int idx;
 
        *_conn = NULL;
        if (conn->fd == -1)
                return;
 
-       clients = array_get(&auth_client_connections, &count);
-       for (i = 0; i < count; i++) {
-               if (clients[i] == conn) {
-                       array_delete(&auth_client_connections, i, 1);
+       array_foreach(&auth_client_connections, clients) {
+               if (*clients == conn) {
+                       idx = array_foreach_idx(&auth_client_connections,
+                                               clients);
+                       array_delete(&auth_client_connections, idx, 1);
                        break;
                }
        }
@@ -351,12 +352,12 @@ struct auth_client_connection *
 auth_client_connection_lookup(unsigned int pid)
 {
        struct auth_client_connection *const *clients;
-       unsigned int i, count;
 
-       clients = array_get(&auth_client_connections, &count);
-       for (i = 0; i < count; i++) {
-               if (clients[i]->pid == pid)
-                       return clients[i];
+       array_foreach(&auth_client_connections, clients) {
+               struct auth_client_connection *client = *clients;
+
+               if (client->pid == pid)
+                       return client;
        }
 
        return NULL;
@@ -365,13 +366,13 @@ auth_client_connection_lookup(unsigned int pid)
 static void request_timeout(void *context ATTR_UNUSED)
 {
        struct auth_client_connection *const *clients;
-       unsigned int i, count;
 
-       clients = array_get(&auth_client_connections, &count);
-       for (i = 0; i < count; i++) {
-               if (clients[i]->request_handler != NULL) {
+       array_foreach(&auth_client_connections, clients) {
+               struct auth_client_connection *client = *clients;
+
+               if (client->request_handler != NULL) {
                        auth_request_handler_check_timeouts(
-                               clients[i]->request_handler);
+                               client->request_handler);
                }
        }
 }
index 44c3f1a5004fc5d7bdc46018dc0e40fcac2f32a7..a0a90bd80e9772a8c05fe293a99eacfeda555cd8 100644 (file)
@@ -501,17 +501,18 @@ void auth_master_connection_destroy(struct auth_master_connection **_conn)
 {
         struct auth_master_connection *conn = *_conn;
         struct auth_master_connection *const *masters;
-       unsigned int i, count;
+       unsigned int idx;
 
        *_conn = NULL;
        if (conn->destroyed)
                return;
        conn->destroyed = TRUE;
 
-       masters = array_get(&auth_master_connections, &count);
-       for (i = 0; i < count; i++) {
-               if (masters[i] == conn) {
-                       array_delete(&auth_master_connections, i, 1);
+       array_foreach(&auth_master_connections, masters) {
+               if (*masters == conn) {
+                       idx = array_foreach_idx(&auth_master_connections,
+                                               masters);
+                       array_delete(&auth_master_connections, idx, 1);
                        break;
                }
        }
index d4ed50882032c96b0d3bcba1b6b42fe52445b6a5..bb656ee76063d95b74814352a9d0a051501f2ef7 100644 (file)
@@ -155,15 +155,15 @@ static void auth_worker_destroy(struct auth_worker_connection **_conn,
 {
        struct auth_worker_connection *conn = *_conn;
        struct auth *auth = conn->auth;
-       struct auth_worker_connection **connp;
-       unsigned int i, count;
+       struct auth_worker_connection *const *conns;
+       unsigned int idx;
 
        *_conn = NULL;
 
-       connp = array_get_modifiable(&connections, &count);
-       for (i = 0; i < count; i++) {
-               if (connp[i] == conn) {
-                       array_delete(&connections, i, 1);
+       array_foreach(&connections, conns) {
+               if (*conns == conn) {
+                       idx = array_foreach_idx(&connections, conns);
+                       array_delete(&connections, idx, 1);
                        break;
                }
        }
@@ -196,15 +196,15 @@ static void auth_worker_destroy(struct auth_worker_connection **_conn,
 static struct auth_worker_connection *auth_worker_find_free(void)
 {
        struct auth_worker_connection **conns;
-       unsigned int i, count;
 
        if (idle_count == 0)
                return NULL;
 
-       conns = array_get_modifiable(&connections, &count);
-       for (i = 0; i < count; i++) {
-               if (conns[i]->request == NULL)
-                       return conns[i];
+       array_foreach_modifiable(&connections, conns) {
+               struct auth_worker_connection *conn = *conns;
+
+               if (conn->request == NULL)
+                       return conn;
        }
        i_unreached();
        return NULL;
index b4d93ceda8c1c38a43a997e6667bdc8992e26667..f3a6b2bc89d2e11f4b909eed10d559bb3f7ff87a 100644 (file)
@@ -13,12 +13,12 @@ static ARRAY_DEFINE(passdb_interfaces, struct passdb_module_interface *);
 static struct passdb_module_interface *passdb_interface_find(const char *name)
 {
        struct passdb_module_interface *const *ifaces;
-       unsigned int i, count;
 
-       ifaces = array_get(&passdb_interfaces, &count);
-       for (i = 0; i < count; i++) {
-               if (strcmp(ifaces[i]->name, name) == 0)
-                       return ifaces[i];
+       array_foreach(&passdb_interfaces, ifaces) {
+               struct passdb_module_interface *iface = *ifaces;
+
+               if (strcmp(iface->name, name) == 0)
+                       return iface;
        }
        return NULL;
 }
@@ -41,12 +41,12 @@ void passdb_register_module(struct passdb_module_interface *iface)
 void passdb_unregister_module(struct passdb_module_interface *iface)
 {
        struct passdb_module_interface *const *ifaces;
-       unsigned int i, count;
+       unsigned int idx;
 
-       ifaces = array_get(&passdb_interfaces, &count);
-       for (i = 0; i < count; i++) {
-               if (ifaces[i] == iface) {
-                       array_delete(&passdb_interfaces, i, 1);
+       array_foreach(&passdb_interfaces, ifaces) {
+               if (*ifaces == iface) {
+                       idx = array_foreach_idx(&passdb_interfaces, ifaces);
+                       array_delete(&passdb_interfaces, idx, 1);
                        return;
                }
        }
index 5895c2e3e3bfd678a8b472b655c0ee917a3711ff..30f6a02e0fa82bef8b1aede7652fd415f1fbe4bb 100644 (file)
@@ -25,12 +25,12 @@ static const struct password_scheme *
 password_scheme_lookup_name(const char *name)
 {
        const struct password_scheme *const *schemes;
-       unsigned int i, count;
 
-       schemes = array_get(&password_schemes, &count);
-       for (i = 0; i < count; i++) {
-               if (strcasecmp(schemes[i]->name, name) == 0)
-                       return schemes[i];
+       array_foreach(&password_schemes, schemes) {
+               const struct password_scheme *scheme = *schemes;
+
+               if (strcasecmp(scheme->name, name) == 0)
+                       return scheme;
        }
        return NULL;
 }
@@ -230,7 +230,6 @@ bool password_generate_encoded(const char *plaintext, const char *user,
 bool password_scheme_is_alias(const char *scheme1, const char *scheme2)
 {
        const struct password_scheme *const *schemes, *s1 = NULL, *s2 = NULL;
-       unsigned int i, count;
 
        scheme1 = t_strcut(scheme1, '.');
        scheme2 = t_strcut(scheme2, '.');
@@ -238,12 +237,13 @@ bool password_scheme_is_alias(const char *scheme1, const char *scheme2)
        if (strcasecmp(scheme1, scheme2) == 0)
                return TRUE;
 
-       schemes = array_get(&password_schemes, &count);
-       for (i = 0; i < count; i++) {
-               if (strcasecmp(schemes[i]->name, scheme1) == 0)
-                       s1 = schemes[i];
-               else if (strcasecmp(schemes[i]->name, scheme2) == 0)
-                       s2 = schemes[i];
+       array_foreach(&password_schemes, schemes) {
+               const struct password_scheme *scheme = *schemes;
+
+               if (strcasecmp(scheme->name, scheme1) == 0)
+                       s1 = scheme;
+               else if (strcasecmp(scheme->name, scheme2) == 0)
+                       s2 = scheme;
        }
 
        /* if they've the same generate function, they're equivalent */
@@ -686,12 +686,12 @@ void password_scheme_register(const struct password_scheme *scheme)
 void password_scheme_unregister(const struct password_scheme *scheme)
 {
        const struct password_scheme *const *schemes;
-       unsigned int i, count;
+       unsigned int idx;
 
-       schemes = array_get(&password_schemes, &count);
-       for (i = 0; i < count; i++) {
-               if (strcasecmp(schemes[i]->name, scheme->name) == 0) {
-                       array_delete(&password_schemes, i, 1);
+       array_foreach(&password_schemes, schemes) {
+               if (strcasecmp((*schemes)->name, scheme->name) == 0) {
+                       idx = array_foreach_idx(&password_schemes, schemes);
+                       array_delete(&password_schemes, idx, 1);
                        return;
                }
        }
index 82bb4d4da21e452183e53dbbf28adf6b216f4de0..c1bbf3b187dc88289055614089f582f7edd33076 100644 (file)
@@ -14,12 +14,12 @@ static ARRAY_DEFINE(userdb_interfaces, struct userdb_module_interface *);
 static struct userdb_module_interface *userdb_interface_find(const char *name)
 {
        struct userdb_module_interface *const *ifaces;
-       unsigned int i, count;
 
-       ifaces = array_get(&userdb_interfaces, &count);
-       for (i = 0; i < count; i++) {
-               if (strcmp(ifaces[i]->name, name) == 0)
-                       return ifaces[i];
+       array_foreach(&userdb_interfaces, ifaces) {
+               struct userdb_module_interface *iface = *ifaces;
+
+               if (strcmp(iface->name, name) == 0)
+                       return iface;
        }
        return NULL;
 }
@@ -42,12 +42,12 @@ void userdb_register_module(struct userdb_module_interface *iface)
 void userdb_unregister_module(struct userdb_module_interface *iface)
 {
        struct userdb_module_interface *const *ifaces;
-       unsigned int i, count;
+       unsigned int idx;
 
-       ifaces = array_get(&userdb_interfaces, &count);
-       for (i = 0; i < count; i++) {
-               if (ifaces[i] == iface) {
-                       array_delete(&userdb_interfaces, i, 1);
+       array_foreach(&userdb_interfaces, ifaces) {
+               if (*ifaces == iface) {
+                       idx = array_foreach_idx(&userdb_interfaces, ifaces);
+                       array_delete(&userdb_interfaces, idx, 1);
                        return;
                }
        }
index 0af9499efcee5ee8a58c172d9f46263c97a700c2..784af21794c75d5caaa3eaa300f397865b2393fc 100644 (file)
@@ -201,12 +201,12 @@ config_filter_parser_find(struct parser_context *ctx,
                          const struct config_filter *filter)
 {
        struct config_filter_parser *const *parsers;
-       unsigned int i, count;
 
-       parsers = array_get(&ctx->all_parsers, &count);
-       for (i = 0; i < count; i++) {
-               if (config_filters_equal(&parsers[i]->filter, filter))
-                       return parsers[i];
+       array_foreach(&ctx->all_parsers, parsers) {
+               struct config_filter_parser *parser = *parsers;
+
+               if (config_filters_equal(&parser->filter, filter))
+                       return parser;
        }
        return NULL;
 }
index 393388577c6b625e1f1df3e87cfd5a8b70605a82..6ae387588ae90bc9314511ea7e074ca9991f3aa8 100644 (file)
@@ -247,7 +247,7 @@ static void
 list_namespace_send_prefix(struct cmd_list_context *ctx, bool have_children)
 {
        struct mail_namespace *const *listed;
-       unsigned int i, count, len;
+       unsigned int len;
        enum mailbox_info_flags flags;
        const char *name;
        string_t *str;
@@ -256,9 +256,8 @@ list_namespace_send_prefix(struct cmd_list_context *ctx, bool have_children)
 
        /* see if we already listed this as a valid mailbox in another
           namespace */
-       listed = array_get(&ctx->ns_prefixes_listed, &count);
-       for (i = 0; i < count; i++) {
-               if (listed[i] == ctx->ns)
+       array_foreach(&ctx->ns_prefixes_listed, listed) {
+               if (*listed == ctx->ns)
                        return;
        }
 
index ff6bea47aca8b06293e342005c2cebf5b1d3fc44..f79c8ce55153670a774bc26b0c69cfb4c319c21a 100644 (file)
@@ -307,13 +307,13 @@ static const char *get_keywords_string(const ARRAY_TYPE(keywords) *keywords)
 {
        string_t *str;
        const char *const *names;
-       unsigned int i, count;
 
        str = t_str_new(256);
-       names = array_get(keywords, &count);
-       for (i = 0; i < count; i++) {
+       array_foreach(keywords, names) {
+               const char *name = *names;
+
                str_append_c(str, ' ');
-               str_append(str, names[i]);
+               str_append(str, name);
        }
        return str_c(str);
 }
@@ -361,18 +361,18 @@ client_get_keyword_names(struct client *client, ARRAY_TYPE(keywords) *dest,
 {
        const unsigned int *kw_indexes;
        const char *const *all_names;
-       unsigned int i, kw_count, all_count;
+       unsigned int all_count;
 
        client_send_mailbox_flags(client, FALSE);
 
-       all_names = array_get(client->keywords.names, &all_count);
-       kw_indexes = array_get(src, &kw_count);
-
        /* convert indexes to names */
+       all_names = array_get(client->keywords.names, &all_count);
        array_clear(dest);
-       for (i = 0; i < kw_count; i++) {
-               i_assert(kw_indexes[i] < all_count);
-               array_append(dest, &all_names[kw_indexes[i]], 1);
+       array_foreach(src, kw_indexes) {
+               unsigned int kw_index = *kw_indexes;
+
+               i_assert(kw_index < all_count);
+               array_append(dest, &all_names[kw_index], 1);
        }
 
        (void)array_append_space(dest);
index 5d95ab8e9a8ab727a002708c6bc4fe86db5fb64b..4b3aa17da9d817fb3e43c80a670a86c2af065d76 100644 (file)
@@ -163,15 +163,13 @@ static void imap_search_result_save(struct imap_search_context *ctx)
 static void imap_search_send_result_standard(struct imap_search_context *ctx)
 {
        const struct seq_range *range;
-       unsigned int i, count;
        string_t *str;
        uint32_t seq;
 
        str = t_str_new(1024);
-       range = array_get(&ctx->result, &count);
        str_append(str, ctx->sorting ? "* SORT" : "* SEARCH");
-       for (i = 0; i < count; i++) {
-               for (seq = range[i].seq1; seq <= range[i].seq2; seq++)
+       array_foreach(&ctx->result, range) {
+               for (seq = range->seq1; seq <= range->seq2; seq++)
                        str_printfa(str, " %u", seq);
                if (str_len(str) >= 1024-32) {
                        o_stream_send(ctx->cmd->client->output,
index e749a4fc1cf4c991de986453327a3beaeabccf84..de743926b0c7605f6af02cb41b6586eaf20a6994 100644 (file)
@@ -47,18 +47,16 @@ static void uids_to_seqs(struct mailbox *box, ARRAY_TYPE(seq_range) *uids)
        T_BEGIN {
                ARRAY_TYPE(seq_range) seqs;
                const struct seq_range *range;
-               unsigned int i, count;
                uint32_t seq1, seq2;
 
-               range = array_get(uids, &count);
-               t_array_init(&seqs, count);
-               for (i = 0; i < count; i++) {
-                       mailbox_get_seq_range(box, range[i].seq1, range[i].seq2,
+               t_array_init(&seqs, array_count(uids));
+               array_foreach(uids, range) {
+                       mailbox_get_seq_range(box, range->seq1, range->seq2,
                                              &seq1, &seq2);
                        /* since we have to notify about expunged messages,
                           we expect that all the referenced UIDs exist */
                        i_assert(seq1 != 0);
-                       i_assert(seq2 - seq1 == range[i].seq2 - range[i].seq1);
+                       i_assert(seq2 - seq1 == range->seq2 - range->seq1);
 
                        seq_range_array_add_range(&seqs, seq1, seq2);
                }
@@ -109,8 +107,7 @@ imap_sync_send_search_update(struct imap_sync_context *ctx,
 
 static void imap_sync_send_search_updates(struct imap_sync_context *ctx)
 {
-       const struct imap_search_update *updates;
-       unsigned int i, count;
+       const struct imap_search_update *update;
 
        if (!array_is_created(&ctx->client->search_updates))
                return;
@@ -120,9 +117,8 @@ static void imap_sync_send_search_updates(struct imap_sync_context *ctx)
                i_array_init(&ctx->search_adds, 128);
        }
 
-       updates = array_get(&ctx->client->search_updates, &count);
-       for (i = 0; i < count; i++) T_BEGIN {
-               imap_sync_send_search_update(ctx, &updates[i]);
+       array_foreach(&ctx->client->search_updates, update) T_BEGIN {
+               imap_sync_send_search_update(ctx, update);
        } T_END;
 }
 
index 84e04ddd366c654e21d0717fbba6b967cb986e8e..6c4e8bbb52397ab4f10f827f56cc486cd95ec859 100644 (file)
@@ -236,13 +236,12 @@ static void file_dict_apply_changes(struct file_dict_transaction_context *ctx)
        const char *tmp;
        char *key, *value, *old_value;
        void *orig_key, *orig_value;
-       const struct file_dict_change *changes;
-       unsigned int i, count, new_len;
+       const struct file_dict_change *change;
+       unsigned int new_len;
        long long diff;
 
-       changes = array_get(&ctx->changes, &count);
-       for (i = 0; i < count; i++) {
-               if (hash_table_lookup_full(dict->hash, changes[i].key,
+       array_foreach(&ctx->changes, change) {
+               if (hash_table_lookup_full(dict->hash, change->key,
                                           &orig_key, &orig_value)) {
                        key = orig_key;
                        old_value = orig_value;
@@ -252,14 +251,14 @@ static void file_dict_apply_changes(struct file_dict_transaction_context *ctx)
                }
                value = NULL;
 
-               switch (changes[i].type) {
+               switch (change->type) {
                case FILE_DICT_CHANGE_TYPE_INC:
                        if (old_value == NULL) {
                                ctx->atomic_inc_not_found = TRUE;
                                break;
                        }
                        diff = strtoll(old_value, NULL, 10) +
-                               changes[i].value.diff;
+                               change->value.diff;
                        tmp = t_strdup_printf("%lld", diff);
                        new_len = strlen(tmp);
                        if (old_value == NULL || new_len > strlen(old_value))
@@ -271,10 +270,10 @@ static void file_dict_apply_changes(struct file_dict_transaction_context *ctx)
                        /* fall through */
                case FILE_DICT_CHANGE_TYPE_SET:
                        if (key == NULL)
-                               key = p_strdup(dict->hash_pool, changes[i].key);
+                               key = p_strdup(dict->hash_pool, change->key);
                        if (value == NULL) {
                                value = p_strdup(dict->hash_pool,
-                                                changes[i].value.str);
+                                                change->value.str);
                        }
                        hash_table_update(dict->hash, key, value);
                        break;
index 6d7d9435b08d19c7d0e7dd232a6add9313e650e8..0a5c1c30e904bcd804effe499e078469d8055e35 100644 (file)
@@ -10,12 +10,12 @@ static ARRAY_DEFINE(dict_drivers, struct dict *);
 static struct dict *dict_driver_lookup(const char *name)
 {
        struct dict *const *dicts;
-       unsigned int i, count;
 
-       dicts = array_get(&dict_drivers, &count);
-       for (i = 0; i < count; i++) {
-               if (strcmp(dicts[i]->name, name) == 0)
-                       return dicts[i];
+       array_foreach(&dict_drivers, dicts) {
+               struct dict *dict = *dicts;
+
+               if (strcmp(dict->name, name) == 0)
+                       return dict;
        }
        return NULL;
 }
@@ -35,17 +35,16 @@ void dict_driver_register(struct dict *driver)
 void dict_driver_unregister(struct dict *driver)
 {
        struct dict *const *dicts;
-       unsigned int i, count;
+       unsigned int idx = -1U;
 
-       dicts = array_get(&dict_drivers, &count);
-       for (i = 0; i < count; i++) {
-               if (dicts[i] == driver) {
-                       array_delete(&dict_drivers, i, 1);
+       array_foreach(&dict_drivers, dicts) {
+               if (*dicts == driver) {
+                       idx = array_foreach_idx(&dict_drivers, dicts);
                        break;
                }
        }
-
-       i_assert(i < count);
+       i_assert(idx != -1U);
+       array_delete(&dict_drivers, idx, 1);
 
        if (array_count(&dict_drivers) == 0)
                array_free(&dict_drivers);
index 9519d20a8a3aa4a9a55f35e1d22842e8d9c009b4..59af0ca89a6165f24a68ffe5d0bfa1bd563f004d 100644 (file)
@@ -43,17 +43,18 @@ void mail_index_map_init_extbufs(struct mail_index_map *map,
 bool mail_index_map_lookup_ext(struct mail_index_map *map, const char *name,
                               uint32_t *idx_r)
 {
-       const struct mail_index_ext *extensions;
-       unsigned int i, size;
-
-       if (array_is_created(&map->extensions)) {
-               extensions = array_get(&map->extensions, &size);
-               for (i = 0; i < size; i++) {
-                       if (strcmp(extensions[i].name, name) == 0) {
-                               if (idx_r != NULL)
-                                       *idx_r = i;
-                               return TRUE;
+       const struct mail_index_ext *ext;
+
+       if (!array_is_created(&map->extensions))
+               return FALSE;
+
+       array_foreach(&map->extensions, ext) {
+               if (strcmp(ext->name, name) == 0) {
+                       if (idx_r != NULL) {
+                               *idx_r = array_foreach_idx(&map->extensions,
+                                                          ext);
                        }
+                       return TRUE;
                }
        }
        return FALSE;
@@ -259,20 +260,21 @@ static void mail_index_record_map_free(struct mail_index_map *map,
 static void mail_index_record_map_unlink(struct mail_index_map *map)
 {
        struct mail_index_map *const *maps;
-       unsigned int i, count;
-
-       maps = array_get(&map->rec_map->maps, &count);
-       for (i = 0; i < count; i++) {
-               if (maps[i] == map) {
-                       array_delete(&map->rec_map->maps, i, 1);
-                       if (i == 0 && count == 1) {
-                               mail_index_record_map_free(map, map->rec_map);
-                               map->rec_map = NULL;
-                       }
-                       return;
+       unsigned int idx = -1U;
+
+       array_foreach(&map->rec_map->maps, maps) {
+               if (*maps == map) {
+                       idx = array_foreach_idx(&map->rec_map->maps, maps);
+                       break;
                }
        }
-       i_unreached();
+       i_assert(idx != -1U);
+
+       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;
+       }
 }
 
 void mail_index_unmap(struct mail_index_map **_map)
index e3a274087c5a5a5692aebf0f6e40a7e1c6daf66f..27315f349fcc037dea74405a593453f6a82423f5 100644 (file)
@@ -76,12 +76,12 @@ lmtp_proxy_init(const char *my_hostname, struct ostream *client_output)
 static void lmtp_proxy_connections_deinit(struct lmtp_proxy *proxy)
 {
        struct lmtp_proxy_connection *const *conns;
-       unsigned int i, count;
 
-       conns = array_get(&proxy->connections, &count);
-       for (i = 0; i < count; i++) {
-               lmtp_client_fail(conns[i]->client, "451 4.3.0 Aborting");
-               lmtp_client_deinit(&conns[i]->client);
+       array_foreach(&proxy->connections, conns) {
+               struct lmtp_proxy_connection *conn = *conns;
+
+               lmtp_client_fail(conn->client, "451 4.3.0 Aborting");
+               lmtp_client_deinit(&conn->client);
        }
 }
 
@@ -117,15 +117,15 @@ lmtp_proxy_get_connection(struct lmtp_proxy *proxy,
                          const struct lmtp_proxy_settings *set)
 {
        struct lmtp_proxy_connection *const *conns, *conn;
-       unsigned int i, count;
 
        i_assert(set->timeout_msecs > 0);
 
-       conns = array_get(&proxy->connections, &count);
-       for (i = 0; i < count; i++) {
-               if (conns[i]->set.port == set->port &&
-                   strcmp(conns[i]->set.host, set->host) == 0)
-                       return conns[i];
+       array_foreach(&proxy->connections, conns) {
+               conn = *conns;
+
+               if (conn->set.port == set->port &&
+                   strcmp(conn->set.host, set->host) == 0)
+                       return conn;
        }
 
        conn = p_new(proxy->pool, struct lmtp_proxy_connection, 1);
@@ -389,12 +389,10 @@ static bool lmtp_proxy_data_read(struct lmtp_proxy *proxy)
 static void lmtp_proxy_data_input(struct lmtp_proxy *proxy)
 {
        struct lmtp_proxy_connection *const *conns;
-       unsigned int i, count;
 
        do {
-               conns = array_get(&proxy->connections, &count);
-               for (i = 0; i < count; i++)
-                       lmtp_client_send_more(conns[i]->client);
+               array_foreach(&proxy->connections, conns);
+                       lmtp_client_send_more((*conns)->client);
        } while (lmtp_proxy_data_read(proxy));
 }
 
@@ -403,7 +401,6 @@ void lmtp_proxy_start(struct lmtp_proxy *proxy, struct istream *data_input,
                      lmtp_proxy_finish_callback_t *callback, void *context)
 {
        struct lmtp_proxy_connection *const *conns;
-       unsigned int i, count;
 
        proxy->finish_callback = callback;
        proxy->finish_context = context;
@@ -413,12 +410,13 @@ void lmtp_proxy_start(struct lmtp_proxy *proxy, struct istream *data_input,
        proxy->to_data_idle = timeout_add(LMTP_PROXY_DATA_INPUT_TIMEOUT_MSECS,
                                          lmtp_proxy_data_input_timeout, proxy);
 
-       conns = array_get(&proxy->connections, &count);
-       for (i = 0; i < count; i++) {
-               conns[i]->data_input =
+       array_foreach(&proxy->connections, conns) {
+               struct lmtp_proxy_connection *conn = *conns;
+
+               conn->data_input =
                        tee_i_stream_create_child(proxy->tee_data_input);
-               lmtp_client_set_data_header(conns[i]->client, header);
-               lmtp_client_send(conns[i]->client, conns[i]->data_input);
+               lmtp_client_set_data_header(conn->client, header);
+               lmtp_client_send(conn->client, conn->data_input);
        }
 
        lmtp_proxy_data_input(proxy);
index 1bff028011bf79d07b5f4a52046be736b12ea549..21b760d986bee1833bd93caa639acc2a3ff9e92f 100644 (file)
@@ -237,18 +237,18 @@ static void fix_file_listener_paths(ARRAY_TYPE(file_listener_settings) *l,
                                    ARRAY_TYPE(const_string) *all_listeners)
 {
        struct file_listener_settings *const *sets;
-       unsigned int i, count;
 
        if (!array_is_created(l))
                return;
 
-       sets = array_get(l, &count);
-       for (i = 0; i < count; i++) {
-               if (*sets[i]->path != '/') {
-                       sets[i]->path = p_strconcat(pool, base_dir, "/",
-                                                   sets[i]->path, NULL);
+       array_foreach(l, sets) {
+               struct file_listener_settings *set = *sets;
+
+               if (*set->path != '/') {
+                       set->path = p_strconcat(pool, base_dir, "/",
+                                               set->path, NULL);
                }
-               array_append(all_listeners, &sets[i]->path, 1);
+               array_append(all_listeners, &set->path, 1);
        }
 }
 
@@ -256,15 +256,15 @@ static void add_inet_listeners(ARRAY_TYPE(inet_listener_settings) *l,
                               ARRAY_TYPE(const_string) *all_listeners)
 {
        struct inet_listener_settings *const *sets;
-       unsigned int i, count;
        const char *str;
 
        if (!array_is_created(l))
                return;
 
-       sets = array_get(l, &count);
-       for (i = 0; i < count; i++) {
-               str = t_strdup_printf("%d:%s", sets[i]->port, sets[i]->address);
+       array_foreach(l, sets) {
+               struct inet_listener_settings *set = *sets;
+
+               str = t_strdup_printf("%d:%s", set->port, set->address);
                array_append(all_listeners, &str, 1);
        }
 }
@@ -405,21 +405,21 @@ static bool
 login_want_core_dumps(const struct master_settings *set, gid_t *gid_r)
 {
        struct service_settings *const *services;
-       unsigned int i, count;
        const char *error;
        bool cores = FALSE;
        uid_t uid;
 
        *gid_r = (gid_t)-1;
 
-       services = array_get(&set->services, &count);
-       for (i = 0; i < count; i++) {
-               if (services[i]->parsed_type == SERVICE_TYPE_LOGIN) {
-                       if (services[i]->login_dump_core)
+       array_foreach(&set->services, services) {
+               struct service_settings *service = *services;
+
+               if (service->parsed_type == SERVICE_TYPE_LOGIN) {
+                       if (service->login_dump_core)
                                cores = TRUE;
-                       (void)get_uidgid(services[i]->user, &uid, gid_r, &error);
-                       if (*services[i]->group != '\0')
-                               (void)get_gid(services[i]->group, gid_r, &error);
+                       (void)get_uidgid(service->user, &uid, gid_r, &error);
+                       if (*service->group != '\0')
+                               (void)get_gid(service->group, gid_r, &error);
                }
        }
        return cores;
@@ -430,15 +430,16 @@ settings_have_auth_unix_listeners_in(const struct master_settings *set,
                                     const char *dir)
 {
        struct service_settings *const *services;
-       struct file_listener_settings *const *u;
-       unsigned int i, j, count, count2;
+       struct file_listener_settings *const *uls;
 
-       services = array_get(&set->services, &count);
-       for (i = 0; i < count; i++) {
-               if (array_is_created(&services[i]->unix_listeners)) {
-                       u = array_get(&services[i]->unix_listeners, &count2);
-                       for (j = 0; j < count2; j++) {
-                               if (strncmp(u[j]->path, dir, strlen(dir)) == 0)
+       array_foreach(&set->services, services) {
+               struct service_settings *service = *services;
+
+               if (array_is_created(&service->unix_listeners)) {
+                       array_foreach(&service->unix_listeners, uls) {
+                               struct file_listener_settings *u = *uls;
+
+                               if (strncmp(u->path, dir, strlen(dir)) == 0)
                                        return TRUE;
                        }
                }
index fc91f58edeae97407faf5891c416155617e308e9..4b84d0ae42a55a141c561d7c9f30afc2fd66f08d 100644 (file)
@@ -143,42 +143,39 @@ static int service_inet_listener_listen(struct service_listener *l)
 static int service_listen(struct service *service)
 {
        struct service_listener *const *listeners;
-       unsigned int i, count;
        int ret = 1, ret2 = 0;
 
-       listeners = array_get(&service->listeners, &count);
-       for (i = 0; i < count; i++) {
-               if (listeners[i]->fd != -1)
+       array_foreach(&service->listeners, listeners) {
+               struct service_listener *l = *listeners;
+
+               if (l->fd != -1)
                        continue;
 
-               switch (listeners[i]->type) {
+               switch (l->type) {
                case SERVICE_LISTENER_UNIX:
-                       ret2 = service_unix_listener_listen(listeners[i]);
+                       ret2 = service_unix_listener_listen(l);
                        break;
                case SERVICE_LISTENER_FIFO:
-                       ret2 = service_fifo_listener_listen(listeners[i]);
+                       ret2 = service_fifo_listener_listen(l);
                        break;
                case SERVICE_LISTENER_INET:
-                       ret2 = service_inet_listener_listen(listeners[i]);
+                       ret2 = service_inet_listener_listen(l);
                        break;
                }
 
                if (ret2 < ret)
                        ret = ret2;
        }
-
        return ret;
 }
 
 int services_listen(struct service_list *service_list)
 {
        struct service *const *services;
-       unsigned int i, count;
        int ret = 1, ret2;
 
-       services = array_get(&service_list->services, &count);
-       for (i = 0; i < count; i++) {
-               ret2 = service_listen(services[i]);
+       array_foreach(&service_list->services, services) {
+               ret2 = service_listen(*services);
                if (ret2 < ret)
                        ret = ret2;
        }
index 3742179d73d7b5c4e5d7ea9c6410ed5cde07d3e5..54be49bf18706916001573c21a3f75f11c041c65 100644 (file)
@@ -150,19 +150,20 @@ void services_log_dup2(ARRAY_TYPE(dup2) *dups,
                       unsigned int first_fd, unsigned int *fd_count)
 {
        struct service *const *services;
-       unsigned int i, n = 0, count;
+       unsigned int n = 0;
 
        /* master log fd is always the first one */
        dup2_append(dups, service_list->master_log_fd[0], first_fd);
        n++; *fd_count += 1;
 
-       services = array_get(&service_list->services, &count);
-       for (i = 0; i < count; i++) {
-               if (services[i]->log_fd[1] == -1)
+       array_foreach(&service_list->services, services) {
+               struct service *service = *services;
+
+               if (service->log_fd[1] == -1)
                        continue;
 
-               i_assert((int)(first_fd + n) == services[i]->log_process_internal_fd);
-               dup2_append(dups, services[i]->log_fd[0], first_fd + n);
+               i_assert((int)(first_fd + n) == service->log_process_internal_fd);
+               dup2_append(dups, service->log_fd[0], first_fd + n);
                n++; *fd_count += 1;
        }
 }
index c0b072e7b840aebd4367e2d3e50176bb10efbb34..646aae9869c5754722c828e8b48c670d78edc287 100644 (file)
@@ -238,7 +238,6 @@ static void service_monitor_start_extra_avail(struct service *service)
 void service_monitor_listen_start(struct service *service)
 {
        struct service_listener *const *listeners;
-       unsigned int i, count;
 
        if (service->process_avail > 0 ||
            (service->process_count == service->process_limit &&
@@ -248,23 +247,20 @@ void service_monitor_listen_start(struct service *service)
        service->listening = TRUE;
        service->listen_pending = FALSE;
 
-       listeners = array_get(&service->listeners, &count);
-       for (i = 0; i < count; i++) {
-               if (listeners[i]->io == NULL && listeners[i]->fd != -1) {
-                       listeners[i]->io = io_add(listeners[i]->fd, IO_READ,
-                                                 service_accept, service);
-               }
+       array_foreach(&service->listeners, listeners) {
+               struct service_listener *l = *listeners;
+
+               if (l->io == NULL && l->fd != -1)
+                       l->io = io_add(l->fd, IO_READ, service_accept, service);
        }
 }
 
 void service_monitor_listen_stop(struct service *service)
 {
        struct service_listener *const *listeners;
-       unsigned int i, count;
 
-       listeners = array_get(&service->listeners, &count);
-       for (i = 0; i < count; i++) {
-               struct service_listener *l = listeners[i];
+       array_foreach(&service->listeners, listeners) {
+               struct service_listener *l = *listeners;
 
                if (l->io != NULL)
                        io_remove(&l->io);
@@ -307,36 +303,36 @@ static int service_login_create_notify_fd(struct service *service)
 void services_monitor_start(struct service_list *service_list)
 {
        struct service *const *services;
-       unsigned int i, count;
 
        services_log_init(service_list);
        service_anvil_monitor_start(service_list);
 
-       services = array_get(&service_list->services, &count);
-       for (i = 0; i < count; i++) {
-               if (services[i]->type == SERVICE_TYPE_LOGIN) {
-                       if (service_login_create_notify_fd(services[i]) < 0)
+       array_foreach(&service_list->services, services) {
+               struct service *service = *services;
+
+               if (service->type == SERVICE_TYPE_LOGIN) {
+                       if (service_login_create_notify_fd(service) < 0)
                                continue;
                }
-               if (services[i]->status_fd[0] == -1) {
+               if (service->status_fd[0] == -1) {
                        /* we haven't yet created status pipe */
-                       if (pipe(services[i]->status_fd) < 0) {
-                               service_error(services[i], "pipe() failed: %m");
+                       if (pipe(service->status_fd) < 0) {
+                               service_error(service, "pipe() failed: %m");
                                continue;
                        }
 
-                       net_set_nonblock(services[i]->status_fd[0], TRUE);
-                       fd_close_on_exec(services[i]->status_fd[0], TRUE);
-                       net_set_nonblock(services[i]->status_fd[1], TRUE);
-                       fd_close_on_exec(services[i]->status_fd[1], TRUE);
+                       net_set_nonblock(service->status_fd[0], TRUE);
+                       fd_close_on_exec(service->status_fd[0], TRUE);
+                       net_set_nonblock(service->status_fd[1], TRUE);
+                       fd_close_on_exec(service->status_fd[1], TRUE);
                }
-               if (services[i]->io_status == NULL) {
-                       services[i]->io_status =
-                               io_add(services[i]->status_fd[0], IO_READ,
-                                      service_status_input, services[i]);
+               if (service->io_status == NULL) {
+                       service->io_status =
+                               io_add(service->status_fd[0], IO_READ,
+                                      service_status_input, service);
                }
-               service_monitor_start_extra_avail(services[i]);
-               service_monitor_listen_start(services[i]);
+               service_monitor_start_extra_avail(service);
+               service_monitor_listen_start(service);
        }
 
        if (service_process_create(service_list->log) != NULL)
@@ -378,11 +374,9 @@ void service_monitor_stop(struct service *service)
 void services_monitor_stop(struct service_list *service_list)
 {
        struct service *const *services;
-       unsigned int i, count;
 
-       services = array_get(&service_list->services, &count);
-       for (i = 0; i < count; i++)
-               service_monitor_stop(services[i]);
+       array_foreach(&service_list->services, services)
+               service_monitor_stop(*services);
 
        services_log_deinit(service_list);
 }
index a70c716a94144ab5c7fc161b5fd2c903eda9392a..6508040c93e54565685289b1d0b878f0e1b2e4e9 100644 (file)
@@ -320,12 +320,12 @@ struct service *
 service_lookup(struct service_list *service_list, const char *name)
 {
        struct service *const *services;
-       unsigned int i, count;
 
-       services = array_get(&service_list->services, &count);
-       for (i = 0; i < count; i++) {
-               if (strcmp(services[i]->set->name, name) == 0)
-                       return services[i];
+       array_foreach(&service_list->services, services) {
+               struct service *service = *services;
+
+               if (strcmp(service->set->name, name) == 0)
+                       return service;
        }
        return NULL;
 }
@@ -334,12 +334,12 @@ struct service *
 service_lookup_type(struct service_list *service_list, enum service_type type)
 {
        struct service *const *services;
-       unsigned int i, count;
 
-       services = array_get(&service_list->services, &count);
-       for (i = 0; i < count; i++) {
-               if (services[i]->type == type)
-                       return services[i];
+       array_foreach(&service_list->services, services) {
+               struct service *service = *services;
+
+               if (service->type == type)
+                       return service;
        }
        return NULL;
 }
@@ -498,7 +498,6 @@ void service_login_notify(struct service *service, bool all_processes_full)
 static void services_kill_timeout(struct service_list *service_list)
 {
        struct service *const *services, *log_service;
-       unsigned int i, count;
        bool sigterm_log;
        int sig;
 
@@ -513,12 +512,13 @@ static void services_kill_timeout(struct service_list *service_list)
                  sig == SIGTERM ? "SIGTERM" : "SIGKILL");
 
        log_service = NULL;
-       services = array_get(&service_list->services, &count);
-       for (i = 0; i < count; i++) {
-               if (services[i]->type == SERVICE_TYPE_LOG)
-                       log_service = services[i];
+       array_foreach(&service_list->services, services) {
+               struct service *service = *services;
+
+               if (service->type == SERVICE_TYPE_LOG)
+                       log_service = service;
                else
-                       service_signal(services[i], sig);
+                       service_signal(service, sig);
        }
        /* kill log service later so it could still have a chance of logging
           something */
@@ -594,12 +594,12 @@ void services_throttle_time_sensitives(struct service_list *list,
                                       unsigned int secs)
 {
        struct service *const *services;
-       unsigned int i, count;
 
-       services = array_get(&list->services, &count);
-       for (i = 0; i < count; i++) {
-               if (services[i]->type == SERVICE_TYPE_UNKNOWN)
-                       service_throttle(services[i], secs);
+       array_foreach(&list->services, services) {
+               struct service *service = *services;
+
+               if (service->type == SERVICE_TYPE_UNKNOWN)
+                       service_throttle(service, secs);
        }
 }
 
index 37b3abeb2020cd8da77504830ca7c433efcf52a4..a275e188c239c38d3fa71b8f78b9703e9207c05e 100644 (file)
@@ -69,7 +69,6 @@ static void client_connected(const struct master_service_connection *conn)
 static void ssl_params_callback(const unsigned char *data, size_t size)
 {
        const int *fds;
-       unsigned int i, count;
 
        buffer_set_used_size(ssl_params, 0);
        buffer_append(ssl_params, data, size);
@@ -77,9 +76,8 @@ static void ssl_params_callback(const unsigned char *data, size_t size)
        if (!array_is_created(&delayed_fds))
                return;
 
-       fds = array_get(&delayed_fds, &count);
-       for (i = 0; i < count; i++)
-               client_handle(fds[i]);
+       array_foreach(&delayed_fds, fds)
+               client_handle(*fds);
        array_free(&delayed_fds);
 }