dovecot-2.0: director: Avoid potential problems by making sure u...

dovecot at dovecot.org dovecot at dovecot.org
Wed May 11 16:20:24 EEST 2011


details:   http://hg.dovecot.org/dovecot-2.0/rev/dab7043e8263
changeset: 12796:dab7043e8263
user:      Timo Sirainen <tss at iki.fi>
date:      Wed May 11 15:57:47 2011 +0300
description:
director: Avoid potential problems by making sure users list is always sorted by timestamp.

diffstat:

 src/director/user-directory.c |  21 +++++++++++++++++++--
 1 files changed, 19 insertions(+), 2 deletions(-)

diffs (37 lines):

diff -r a6db801253c6 -r dab7043e8263 src/director/user-directory.c
--- a/src/director/user-directory.c	Wed May 11 15:35:20 2011 +0300
+++ b/src/director/user-directory.c	Wed May 11 15:57:47 2011 +0300
@@ -68,14 +68,31 @@
 user_directory_add(struct user_directory *dir, unsigned int username_hash,
 		   struct mail_host *host, time_t timestamp)
 {
-	struct user *user;
+	struct user *user, *pos;
 
 	user = i_new(struct user, 1);
 	user->username_hash = username_hash;
 	user->host = host;
 	user->host->user_count++;
 	user->timestamp = timestamp;
-	DLLIST2_APPEND(&dir->head, &dir->tail, user);
+
+	if (dir->tail == NULL || dir->tail->timestamp <= timestamp)
+		DLLIST2_APPEND(&dir->head, &dir->tail, user);
+	else {
+		/* need to insert to correct position */
+		for (pos = dir->tail; pos != NULL; pos = pos->prev) {
+			if (pos->timestamp <= timestamp)
+				break;
+		}
+		if (pos == NULL)
+			DLLIST2_PREPEND(&dir->head, &dir->tail, user);
+		else {
+			user->prev = pos;
+			user->next = pos->next;
+			user->prev->next = user;
+			user->next->prev = user;
+		}
+	}
 
 	hash_table_insert(dir->hash, POINTER_CAST(user->username_hash), user);
 	return user;


More information about the dovecot-cvs mailing list