dovecot-2.2: Hash table API is now (mostly) type safe.
dovecot at dovecot.org
dovecot at dovecot.org
Sun Aug 19 13:55:45 EEST 2012
details: http://hg.dovecot.org/dovecot-2.2/rev/8eae4e205c82
changeset: 14918:8eae4e205c82
user: Timo Sirainen <tss at iki.fi>
date: Sun Aug 19 13:55:34 2012 +0300
description:
Hash table API is now (mostly) type safe.
diffstat:
src/anvil/connect-limit.c | 66 +++----
src/anvil/penalty.c | 6 +-
src/auth/auth-cache.c | 14 +-
src/auth/auth-request-handler.c | 19 +-
src/auth/db-checkpassword.c | 14 +-
src/auth/db-ldap.c | 18 +-
src/auth/db-passwd-file.c | 21 +-
src/auth/db-passwd-file.h | 6 +-
src/auth/mech-otp-skey-common.c | 9 +-
src/config/config-request.c | 5 +-
src/director/director-test.c | 11 +-
src/director/user-directory.c | 12 +-
src/doveadm/doveadm-director.c | 21 +-
src/doveadm/doveadm-kick.c | 17 +-
src/doveadm/doveadm-log.c | 5 +-
src/doveadm/doveadm-mail-server.c | 16 +-
src/doveadm/doveadm-stats.c | 15 +-
src/doveadm/doveadm-who.c | 12 +-
src/doveadm/doveadm-who.h | 2 +-
src/doveadm/dsync/dsync-brain-mailbox.c | 5 +-
src/doveadm/dsync/dsync-brain-private.h | 3 +-
src/doveadm/dsync/dsync-brain.c | 4 +-
src/doveadm/dsync/dsync-mailbox-export.c | 26 +-
src/doveadm/dsync/dsync-mailbox-import.c | 63 +++++--
src/doveadm/dsync/dsync-mailbox-tree-fill.c | 7 +-
src/doveadm/dsync/dsync-mailbox-tree-private.h | 6 +-
src/doveadm/dsync/dsync-mailbox-tree-sync.c | 22 +-
src/doveadm/dsync/dsync-mailbox-tree.c | 51 +++---
src/doveadm/dsync/dsync-transaction-log-scan.c | 13 +-
src/doveadm/dsync/dsync-transaction-log-scan.h | 5 +-
src/indexer/indexer-queue.c | 17 +-
src/lib-auth/auth-server-connection.c | 8 +-
src/lib-auth/auth-server-connection.h | 2 +-
src/lib-dict/dict-file.c | 22 +-
src/lib-index/mail-cache-fields.c | 5 +-
src/lib-index/mail-cache-private.h | 2 +-
src/lib-index/mail-cache.c | 5 +-
src/lib-index/mail-index-private.h | 2 +-
src/lib-index/mail-index.c | 10 +-
src/lib-lda/duplicate.c | 18 +-
src/lib-master/master-auth.c | 14 +-
src/lib-master/master-login-auth.c | 12 +-
src/lib-master/master-service-settings-cache.c | 28 +--
src/lib-settings/settings-parser.c | 25 +-
src/lib-sql/sql-db-cache.c | 5 +-
src/lib-storage/index/dbox-multi/mdbox-purge.c | 23 +-
src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c | 18 +-
src/lib-storage/index/index-thread-finish.c | 15 +-
src/lib-storage/index/maildir/maildir-filename.c | 7 +-
src/lib-storage/index/maildir/maildir-filename.h | 4 +-
src/lib-storage/index/maildir/maildir-keywords.c | 21 +-
src/lib-storage/index/maildir/maildir-uidlist.c | 23 +-
src/lib-storage/list/mailbox-list-index-sync.c | 9 +-
src/lib-storage/list/mailbox-list-index.c | 15 +-
src/lib-storage/list/mailbox-list-index.h | 8 +-
src/lib-storage/mailbox-guid-cache.c | 20 +-
src/lib-storage/mailbox-list-private.h | 2 +-
src/lib-storage/mailbox-list.c | 2 +-
src/lib/child-wait.c | 15 +-
src/lib/guid.c | 10 +-
src/lib/guid.h | 4 +-
src/lib/hash.c | 74 ++++++---
src/lib/hash.h | 118 +++++++++++++-
src/lib/lib.h | 1 +
src/lib/macros.h | 7 +-
src/log/log-connection.c | 18 +-
src/login-common/login-proxy-state.c | 18 +-
src/login-common/ssl-proxy-openssl.c | 23 +-
src/master/service-monitor.c | 4 +-
src/master/service-process.c | 4 +-
src/master/service.c | 20 +--
src/master/service.h | 3 +-
src/plugins/acl/acl-cache.c | 33 +--
src/plugins/expire/doveadm-expire.c | 23 +-
src/plugins/fts-lucene/fts-backend-lucene.c | 11 +-
src/plugins/fts-lucene/lucene-wrapper.cc | 36 ++--
src/plugins/fts-lucene/lucene-wrapper.h | 5 +-
src/plugins/fts-solr/fts-backend-solr-old.c | 5 +-
src/plugins/fts-solr/fts-backend-solr.c | 5 +-
src/plugins/fts-solr/solr-connection.c | 7 +-
src/plugins/fts/fts-expunge-log.c | 19 +-
src/pop3/pop3-commands.c | 23 +-
src/replication/aggregator/replicator-connection.c | 10 +-
src/replication/replicator/replicator-queue.c | 6 +-
src/stats/mail-domain.c | 6 +-
src/stats/mail-ip.c | 8 +-
src/stats/mail-session.c | 26 ++-
src/stats/mail-user.c | 6 +-
88 files changed, 729 insertions(+), 655 deletions(-)
diffs (truncated from 4261 to 300 lines):
diff -r 1ce71b5bc94a -r 8eae4e205c82 src/anvil/connect-limit.c
--- a/src/anvil/connect-limit.c Sun Aug 19 07:20:13 2012 +0300
+++ b/src/anvil/connect-limit.c Sun Aug 19 13:55:34 2012 +0300
@@ -16,22 +16,18 @@
struct connect_limit {
/* ident => refcount */
- struct hash_table *ident_hash;
+ HASH_TABLE(char *, unsigned int) ident_hash;
/* struct ident_pid => struct ident_pid */
- struct hash_table *ident_pid_hash;
+ HASH_TABLE(struct ident_pid *, struct ident_pid *) ident_pid_hash;
};
-static unsigned int ident_pid_hash(const void *p)
+static unsigned int ident_pid_hash(const struct ident_pid *i)
{
- const struct ident_pid *i = p;
-
return str_hash(i->ident) ^ i->pid;
}
-static int ident_pid_cmp(const void *p1, const void *p2)
+static int ident_pid_cmp(const struct ident_pid *i1, const struct ident_pid *i2)
{
- const struct ident_pid *i1 = p1, *i2 = p2;
-
if (i1->pid < i2->pid)
return -1;
else if (i1->pid > i2->pid)
@@ -45,12 +41,9 @@
struct connect_limit *limit;
limit = i_new(struct connect_limit, 1);
- limit->ident_hash =
- hash_table_create(default_pool, 0,
- str_hash, (hash_cmp_callback_t *)strcmp);
- limit->ident_pid_hash =
- hash_table_create(default_pool, 0,
- ident_pid_hash, ident_pid_cmp);
+ hash_table_create(&limit->ident_hash, default_pool, 0, str_hash, strcmp);
+ hash_table_create(&limit->ident_pid_hash, default_pool, 0,
+ ident_pid_hash, ident_pid_cmp);
return limit;
}
@@ -67,27 +60,24 @@
unsigned int connect_limit_lookup(struct connect_limit *limit,
const char *ident)
{
- void *value;
-
- value = hash_table_lookup(limit->ident_hash, ident);
- if (value == NULL)
- return 0;
-
- return POINTER_CAST_TO(value, unsigned int);
+ return hash_table_lookup(limit->ident_hash, ident);
}
void connect_limit_connect(struct connect_limit *limit, pid_t pid,
const char *ident)
{
struct ident_pid *i, lookup_i;
- void *key, *value;
+ void *orig_key, *orig_value;
+ char *key;
+ unsigned int value;
- if (!hash_table_lookup_full(limit->ident_hash, ident, &key, &value)) {
+ if (!hash_table_lookup_full(limit->ident_hash, ident,
+ &orig_key, &orig_value)) {
key = i_strdup(ident);
- value = POINTER_CAST(1);
- hash_table_insert(limit->ident_hash, key, value);
+ hash_table_insert(limit->ident_hash, key, 1U);
} else {
- value = POINTER_CAST(POINTER_CAST_TO(value, unsigned int) + 1);
+ key = orig_key;
+ value = POINTER_CAST_TO(orig_value, unsigned int) + 1;
hash_table_update(limit->ident_hash, key, value);
}
@@ -108,16 +98,18 @@
static void
connect_limit_ident_hash_unref(struct connect_limit *limit, const char *ident)
{
- void *key, *value;
+ void *orig_key, *orig_value;
+ char *key;
unsigned int new_refcount;
- if (!hash_table_lookup_full(limit->ident_hash, ident, &key, &value))
+ if (!hash_table_lookup_full(limit->ident_hash, ident,
+ &orig_key, &orig_value))
i_panic("connect limit hash tables are inconsistent");
- new_refcount = POINTER_CAST_TO(value, unsigned int) - 1;
+ key = orig_key;
+ new_refcount = POINTER_CAST_TO(orig_value, unsigned int) - 1;
if (new_refcount > 0) {
- value = POINTER_CAST(new_refcount);
- hash_table_update(limit->ident_hash, key, value);
+ hash_table_update(limit->ident_hash, key, new_refcount);
} else {
hash_table_remove(limit->ident_hash, key);
i_free(key);
@@ -150,14 +142,12 @@
void connect_limit_disconnect_pid(struct connect_limit *limit, pid_t pid)
{
struct hash_iterate_context *iter;
- struct ident_pid *i;
- void *key, *value;
+ struct ident_pid *i, *value;
/* this should happen rarely (or never), so this slow implementation
should be fine. */
iter = hash_table_iterate_init(limit->ident_pid_hash);
- while (hash_table_iterate(iter, &key, &value)) {
- i = key;
+ while (hash_table_iterate_t(iter, limit->ident_pid_hash, &i, &value)) {
if (i->pid == pid) {
hash_table_remove(limit->ident_pid_hash, i);
for (; i->refcount > 0; i->refcount--)
@@ -171,13 +161,11 @@
void connect_limit_dump(struct connect_limit *limit, struct ostream *output)
{
struct hash_iterate_context *iter;
- void *key, *value;
+ struct ident_pid *i, *value;
string_t *str = t_str_new(256);
iter = hash_table_iterate_init(limit->ident_pid_hash);
- while (hash_table_iterate(iter, &key, &value)) {
- struct ident_pid *i = key;
-
+ while (hash_table_iterate_t(iter, limit->ident_pid_hash, &i, &value)) {
str_truncate(str, 0);
str_tabescape_write(str, i->ident);
str_printfa(str, "\t%ld\t%u\n", (long)i->pid, i->refcount);
diff -r 1ce71b5bc94a -r 8eae4e205c82 src/anvil/penalty.c
--- a/src/anvil/penalty.c Sun Aug 19 07:20:13 2012 +0300
+++ b/src/anvil/penalty.c Sun Aug 19 13:55:34 2012 +0300
@@ -38,7 +38,7 @@
struct penalty {
/* ident => penalty_rec */
- struct hash_table *hash;
+ HASH_TABLE(char *, struct penalty_rec *) hash;
struct penalty_rec *oldest, *newest;
unsigned int expire_secs;
@@ -50,9 +50,7 @@
struct penalty *penalty;
penalty = i_new(struct penalty, 1);
- penalty->hash =
- hash_table_create(default_pool, 0,
- str_hash, (hash_cmp_callback_t *)strcmp);
+ hash_table_create(&penalty->hash, default_pool, 0, str_hash, strcmp);
penalty->expire_secs = PENALTY_DEFAULT_EXPIRE_SECS;
return penalty;
}
diff -r 1ce71b5bc94a -r 8eae4e205c82 src/auth/auth-cache.c
--- a/src/auth/auth-cache.c Sun Aug 19 07:20:13 2012 +0300
+++ b/src/auth/auth-cache.c Sun Aug 19 13:55:34 2012 +0300
@@ -12,7 +12,7 @@
#include <time.h>
struct auth_cache {
- struct hash_table *hash;
+ HASH_TABLE(char *, struct auth_cache_node *) hash;
struct auth_cache_node *head, *tail;
size_t size_left;
@@ -178,10 +178,12 @@
static void
auth_cache_node_destroy(struct auth_cache *cache, struct auth_cache_node *node)
{
+ char *key = node->data;
+
auth_cache_node_unlink(cache, node);
cache->size_left += node->alloc_size;
- hash_table_remove(cache->hash, node->data);
+ hash_table_remove(cache->hash, key);
i_free(node);
}
@@ -221,8 +223,7 @@
struct auth_cache *cache;
cache = i_new(struct auth_cache, 1);
- cache->hash = hash_table_create(default_pool, 0, str_hash,
- (hash_cmp_callback_t *)strcmp);
+ hash_table_create(&cache->hash, default_pool, 0, str_hash, strcmp);
cache->size_left = max_size;
cache->ttl_secs = ttl_secs;
cache->neg_ttl_secs = neg_ttl_secs;
@@ -386,7 +387,7 @@
{
struct auth_cache_node *node;
size_t data_size, alloc_size, key_len, value_len = strlen(value);
- char *current_username;
+ char *hash_key, *current_username;
if (*value == '\0' && cache->neg_ttl_secs == 0) {
/* we're not caching negative entries */
@@ -430,7 +431,8 @@
auth_cache_node_link_head(cache, node);
cache->size_left -= alloc_size;
- hash_table_insert(cache->hash, node->data, node);
+ hash_key = node->data;
+ hash_table_insert(cache->hash, hash_key, node);
if (*value != '\0') {
cache->pos_entries++;
diff -r 1ce71b5bc94a -r 8eae4e205c82 src/auth/auth-request-handler.c
--- a/src/auth/auth-request-handler.c Sun Aug 19 07:20:13 2012 +0300
+++ b/src/auth/auth-request-handler.c Sun Aug 19 13:55:34 2012 +0300
@@ -21,7 +21,7 @@
struct auth_request_handler {
int refcount;
pool_t pool;
- struct hash_table *requests;
+ HASH_TABLE(unsigned int, struct auth_request *) requests;
unsigned int connect_uid, client_pid;
@@ -52,7 +52,7 @@
handler = p_new(pool, struct auth_request_handler, 1);
handler->refcount = 1;
handler->pool = pool;
- handler->requests = hash_table_create(pool, 0, NULL, NULL);
+ hash_table_create_direct(&handler->requests, pool, 0);
handler->callback = callback;
handler->context = context;
handler->master_callback = master_callback;
@@ -72,6 +72,7 @@
iter = hash_table_iterate_init(handler->requests);
while (hash_table_iterate(iter, &key, &value)) {
+ unsigned int id = POINTER_CAST_TO(key, unsigned int);
struct auth_request *auth_request = value;
switch (auth_request->state) {
@@ -79,7 +80,7 @@
case AUTH_REQUEST_STATE_MECH_CONTINUE:
case AUTH_REQUEST_STATE_FINISHED:
auth_request_unref(&auth_request);
- hash_table_remove(handler->requests, key);
+ hash_table_remove(handler->requests, id);
break;
case AUTH_REQUEST_STATE_PASSDB:
case AUTH_REQUEST_STATE_USERDB:
@@ -146,7 +147,7 @@
request, so make sure we don't get back here. */
timeout_remove(&request->to_abort);
- hash_table_remove(handler->requests, POINTER_CAST(request->id));
+ hash_table_remove(handler->requests, request->id);
auth_request_unref(&request);
}
@@ -513,7 +514,7 @@
auth_request_unref(&request);
return FALSE;
}
- if (hash_table_lookup(handler->requests, POINTER_CAST(id)) != NULL) {
+ if (hash_table_lookup(handler->requests, id) != NULL) {
i_error("BUG: Authentication client %u "
"sent a duplicate ID %u", handler->client_pid, id);
auth_request_unref(&request);
@@ -523,7 +524,7 @@
request->to_abort = timeout_add(MASTER_AUTH_SERVER_TIMEOUT_SECS * 1000,
auth_request_timeout, request);
- hash_table_insert(handler->requests, POINTER_CAST(id), request);
+ hash_table_insert(handler->requests, id, request);
if (request->set->ssl_require_client_cert &&
!request->valid_client_cert) {
@@ -578,7 +579,7 @@
}
data++;
- request = hash_table_lookup(handler->requests, POINTER_CAST(id));
+ request = hash_table_lookup(handler->requests, id);
if (request == NULL) {
struct auth_stream_reply *reply;
@@ -685,7 +686,7 @@
reply = auth_stream_reply_init(pool_datastack_create());
- request = hash_table_lookup(handler->requests, POINTER_CAST(client_id));
+ request = hash_table_lookup(handler->requests, client_id);
if (request == NULL) {
i_error("Master request %u.%u not found",
More information about the dovecot-cvs
mailing list