dovecot-2.0: Use array_foreach() more.
dovecot at dovecot.org
dovecot at dovecot.org
Wed Dec 2 23:35:58 EET 2009
details: http://hg.dovecot.org/dovecot-2.0/rev/ad3fb3f929fc
changeset: 10406:ad3fb3f929fc
user: Timo Sirainen <tss at iki.fi>
date: Wed Dec 02 15:35:51 2009 -0600
description:
Use array_foreach() more.
diffstat:
21 files changed, 274 insertions(+), 290 deletions(-)
src/auth/auth-client-connection.c | 35 +++++++++----------
src/auth/auth-master-connection.c | 11 +++--
src/auth/auth-worker-server.c | 22 +++++------
src/auth/passdb.c | 24 ++++++-------
src/auth/password-scheme.c | 38 ++++++++++----------
src/auth/userdb.c | 20 +++++-----
src/config/config-parser.c | 12 +++---
src/imap/cmd-list.c | 7 +--
src/imap/imap-commands-util.c | 22 +++++------
src/imap/imap-search.c | 6 +--
src/imap/imap-sync.c | 18 +++------
src/lib-dict/dict-file.c | 17 ++++-----
src/lib-dict/dict.c | 23 +++++-------
src/lib-index/mail-index-map.c | 50 ++++++++++++++-------------
src/lmtp/lmtp-proxy.c | 42 ++++++++++------------
src/master/master-settings.c | 59 ++++++++++++++++----------------
src/master/service-listen.c | 23 +++++-------
src/master/service-log.c | 13 +++----
src/master/service-monitor.c | 68 ++++++++++++++++---------------------
src/master/service.c | 48 +++++++++++++-------------
src/ssl-params/main.c | 6 +--
diffs (truncated from 1116 to 300 lines):
diff -r cc4e9d1fef7e -r ad3fb3f929fc src/auth/auth-client-connection.c
--- a/src/auth/auth-client-connection.c Wed Dec 02 15:35:32 2009 -0600
+++ b/src/auth/auth-client-connection.c Wed Dec 02 15:35:51 2009 -0600
@@ -304,16 +304,17 @@ void auth_client_connection_destroy(stru
{
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 @@ auth_client_connection_lookup(unsigned i
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 @@ static void request_timeout(void *contex
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);
}
}
}
diff -r cc4e9d1fef7e -r ad3fb3f929fc src/auth/auth-master-connection.c
--- a/src/auth/auth-master-connection.c Wed Dec 02 15:35:32 2009 -0600
+++ b/src/auth/auth-master-connection.c Wed Dec 02 15:35:51 2009 -0600
@@ -501,17 +501,18 @@ void auth_master_connection_destroy(stru
{
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;
}
}
diff -r cc4e9d1fef7e -r ad3fb3f929fc src/auth/auth-worker-server.c
--- a/src/auth/auth-worker-server.c Wed Dec 02 15:35:32 2009 -0600
+++ b/src/auth/auth-worker-server.c Wed Dec 02 15:35:51 2009 -0600
@@ -155,15 +155,15 @@ static void auth_worker_destroy(struct a
{
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 struct auth_worker_connection *au
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;
diff -r cc4e9d1fef7e -r ad3fb3f929fc src/auth/passdb.c
--- a/src/auth/passdb.c Wed Dec 02 15:35:32 2009 -0600
+++ b/src/auth/passdb.c Wed Dec 02 15:35:51 2009 -0600
@@ -13,12 +13,12 @@ static struct passdb_module_interface *p
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_unregister_module(struct pas
void passdb_unregister_module(struct passdb_module_interface *iface)
{
struct passdb_module_interface *const *ifaces;
- unsigned int i, count;
-
- ifaces = array_get(&passdb_interfaces, &count);
- for (i = 0; i < count; i++) {
- if (ifaces[i] == iface) {
- array_delete(&passdb_interfaces, i, 1);
+ 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;
}
}
diff -r cc4e9d1fef7e -r ad3fb3f929fc src/auth/password-scheme.c
--- a/src/auth/password-scheme.c Wed Dec 02 15:35:32 2009 -0600
+++ b/src/auth/password-scheme.c Wed Dec 02 15:35:51 2009 -0600
@@ -25,12 +25,12 @@ password_scheme_lookup_name(const char *
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_scheme_is_alias(const char
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
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_unregister(const st
void password_scheme_unregister(const struct password_scheme *scheme)
{
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, scheme->name) == 0) {
- array_delete(&password_schemes, i, 1);
+ unsigned int idx;
+
+ 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;
}
}
diff -r cc4e9d1fef7e -r ad3fb3f929fc src/auth/userdb.c
--- a/src/auth/userdb.c Wed Dec 02 15:35:32 2009 -0600
+++ b/src/auth/userdb.c Wed Dec 02 15:35:51 2009 -0600
@@ -14,12 +14,12 @@ static struct userdb_module_interface *u
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_unregister_module(struct use
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;
}
}
diff -r cc4e9d1fef7e -r ad3fb3f929fc src/config/config-parser.c
--- a/src/config/config-parser.c Wed Dec 02 15:35:32 2009 -0600
+++ b/src/config/config-parser.c Wed Dec 02 15:35:51 2009 -0600
@@ -201,12 +201,12 @@ config_filter_parser_find(struct parser_
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];
More information about the dovecot-cvs
mailing list