dovecot-1.0: Don't cache dict to different users.

dovecot at dovecot.org dovecot at dovecot.org
Sat Sep 22 18:33:09 EEST 2007


details:   http://hg.dovecot.org/dovecot-1.0/rev/d0dfd5ad40d4
changeset: 5415:d0dfd5ad40d4
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Sep 22 18:32:55 2007 +0300
description:
Don't cache dict to different users.

diffstat:

3 files changed, 25 insertions(+), 16 deletions(-)
src/dict/dict-cache.c  |   32 +++++++++++++++++++-------------
src/dict/dict-cache.h  |    3 ++-
src/dict/dict-server.c |    6 ++++--

diffs (89 lines):

diff -r 5c798e920045 -r d0dfd5ad40d4 src/dict/dict-cache.c
--- a/src/dict/dict-cache.c	Sat Sep 22 18:07:20 2007 +0300
+++ b/src/dict/dict-cache.c	Sat Sep 22 18:32:55 2007 +0300
@@ -7,7 +7,7 @@
 
 struct dict_entry {
 	int refcount;
-	char *uri;
+	char *user_uri;
 	struct dict *dict;
 };
 
@@ -35,30 +35,36 @@ struct dict *dict_cache_get(struct dict_
 			    const char *username)
 {
 	struct dict_entry *entry;
+	char *user_uri;
 
-	entry = hash_lookup(cache->dicts, uri);
+	user_uri = i_strdup_printf("%s\t%s", username, uri);
+	entry = hash_lookup(cache->dicts, user_uri);
 	if (entry == NULL) {
 		entry = i_new(struct dict_entry, 1);
 		entry->dict = dict_init(uri, username);
-		entry->uri = i_strdup(uri);
-		hash_insert(cache->dicts, entry->uri, entry);
+		entry->user_uri = user_uri;
+		hash_insert(cache->dicts, entry->user_uri, entry);
+	} else {
+		i_free(user_uri);
 	}
 	entry->refcount++;
 	return entry->dict;
 }
 
-void dict_cache_unref(struct dict_cache *cache, const char *uri)
+void dict_cache_unref(struct dict_cache *cache, const char *uri,
+		      const char *username)
 {
 	struct dict_entry *entry;
 
-	entry = hash_lookup(cache->dicts, uri);
+	t_push();
+	entry = hash_lookup(cache->dicts,
+			    t_strdup_printf("%s\t%s", username, uri));
 	i_assert(entry != NULL && entry->refcount > 0);
 
-	if (--entry->refcount > 0)
-		return;
-
-	hash_remove(cache->dicts, uri);
-	dict_deinit(&entry->dict);
-	i_free(entry->uri);
-	i_free(entry);
+	if (--entry->refcount == 0) {
+		hash_remove(cache->dicts, entry->user_uri);
+		dict_deinit(&entry->dict);
+		i_free(entry->user_uri);
+		i_free(entry);
+	}
 }
diff -r 5c798e920045 -r d0dfd5ad40d4 src/dict/dict-cache.h
--- a/src/dict/dict-cache.h	Sat Sep 22 18:07:20 2007 +0300
+++ b/src/dict/dict-cache.h	Sat Sep 22 18:32:55 2007 +0300
@@ -6,6 +6,7 @@ void dict_cache_deinit(struct dict_cache
 
 struct dict *dict_cache_get(struct dict_cache *cache, const char *uri,
 			    const char *username);
-void dict_cache_unref(struct dict_cache *cache, const char *uri);
+void dict_cache_unref(struct dict_cache *cache, const char *uri,
+		      const char *username);
 
 #endif
diff -r 5c798e920045 -r d0dfd5ad40d4 src/dict/dict-server.c
--- a/src/dict/dict-server.c	Sat Sep 22 18:07:20 2007 +0300
+++ b/src/dict/dict-server.c	Sat Sep 22 18:32:55 2007 +0300
@@ -405,8 +405,10 @@ static void dict_client_connection_deini
 	if (close(conn->fd) < 0)
 		i_error("close(dict client) failed: %m");
 
-	if (conn->dict != NULL)
-		dict_cache_unref(conn->server->cache, conn->uri);
+	if (conn->dict != NULL) {
+		dict_cache_unref(conn->server->cache, conn->uri,
+				 conn->username);
+	}
 	i_free(conn->name);
 	i_free(conn->uri);
 	i_free(conn->username);


More information about the dovecot-cvs mailing list