changeset 6473:bd886e12aaa0 HEAD

Don't cache dict to different users.
author Timo Sirainen <tss@iki.fi>
date Sat, 22 Sep 2007 18:33:02 +0300
parents 6afb29dc9273
children 46c3e1ee196f
files src/dict/dict-cache.c src/dict/dict-cache.h src/dict/dict-server.c
diffstat 3 files changed, 26 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/dict/dict-cache.c	Sat Sep 22 18:23:52 2007 +0300
+++ b/src/dict/dict-cache.c	Sat Sep 22 18:33:02 2007 +0300
@@ -7,7 +7,7 @@
 
 struct dict_entry {
 	int refcount;
-	char *uri;
+	char *user_uri;
 	struct dict *dict;
 };
 
@@ -36,30 +36,37 @@
 			    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, value_type, 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);
+	}
+	t_pop();
 }
--- a/src/dict/dict-cache.h	Sat Sep 22 18:23:52 2007 +0300
+++ b/src/dict/dict-cache.h	Sat Sep 22 18:33:02 2007 +0300
@@ -7,6 +7,7 @@
 struct dict *dict_cache_get(struct dict_cache *cache, const char *uri,
 			    enum dict_data_type value_type,
 			    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
--- a/src/dict/dict-server.c	Sat Sep 22 18:23:52 2007 +0300
+++ b/src/dict/dict-server.c	Sat Sep 22 18:33:02 2007 +0300
@@ -430,8 +430,10 @@
 	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);