changeset 21074:6543f5b25252

director: Code cleanup - use temporary users variables This will shrink the diff for the following changes.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 20 Oct 2016 19:17:11 +0300
parents c95c7b811595
children 6a363cb51d7f
files src/director/director-connection.c src/director/director-request.c src/director/director.c src/director/doveadm-connection.c
diffstat 4 files changed, 31 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/director/director-connection.c	Thu Oct 20 16:14:36 2016 +0300
+++ b/src/director/director-connection.c	Thu Oct 20 19:17:11 2016 +0300
@@ -503,12 +503,13 @@
 	struct director *dir = conn->dir;
 	struct user *user;
 	bool ret = FALSE, unset_weak_user = FALSE;
+	struct user_directory *users = dir->users;
 
 	*forced_r = FALSE;
 
-	user = user_directory_lookup(dir->users, username_hash);
+	user = user_directory_lookup(users, username_hash);
 	if (user == NULL) {
-		*user_r = user_directory_add(dir->users, username_hash,
+		*user_r = user_directory_add(users, username_hash,
 					     host, timestamp);
 		(*user_r)->weak = weak;
 		dir_debug("user refresh: %u added", username_hash);
@@ -527,7 +528,7 @@
 			/* weak user marked again as weak */
 		}
 	} else if (weak &&
-		   !user_directory_user_is_recently_updated(dir->users, user)) {
+		   !user_directory_user_is_recently_updated(users, user)) {
 		/* mark the user as weak */
 		dir_debug("user refresh: %u set weak", username_hash);
 		user->weak = TRUE;
@@ -541,7 +542,7 @@
 		ret = TRUE;
 	} else if (user->host == host) {
 		/* update to the same host */
-	} else if (user_directory_user_is_near_expiring(dir->users, user)) {
+	} else if (user_directory_user_is_near_expiring(users, user)) {
 		/* host conflict for a user that is already near expiring. we can
 		   assume that the other director had already dropped this user
 		   and we should have as well. use the new host. */
@@ -609,7 +610,7 @@
 		ret = TRUE;
 	}
 	if (timestamp == ioloop_time && (time_t)user->timestamp != timestamp) {
-		user_directory_refresh(dir->users, user);
+		user_directory_refresh(users, user);
 		ret = TRUE;
 	}
 	dir_debug("user refresh: %u refreshed timeout to %ld",
--- a/src/director/director-request.c	Thu Oct 20 16:14:36 2016 +0300
+++ b/src/director/director-request.c	Thu Oct 20 19:17:11 2016 +0300
@@ -177,6 +177,7 @@
 			  const char *tag)
 {
 	struct director *dir = request->dir;
+	struct user_directory *users = dir->users;
 	struct mail_host *host;
 
 	if (USER_IS_BEING_KILLED(user)) {
@@ -203,7 +204,7 @@
 			  request->username_hash);
 		return FALSE;
 	}
-	if (!user_directory_user_is_near_expiring(dir->users, user))
+	if (!user_directory_user_is_near_expiring(users, user))
 		return TRUE;
 
 	/* user is close to being expired. another director may have
@@ -267,6 +268,7 @@
 bool director_request_continue(struct director_request *request)
 {
 	struct director *dir = request->dir;
+	struct user_directory *users = dir->users;
 	struct mail_host *host;
 	struct user *user;
 	const char *tag;
@@ -280,12 +282,12 @@
 		return FALSE;
 	}
 
-	user = user_directory_lookup(dir->users, request->username_hash);
+	user = user_directory_lookup(users, request->username_hash);
 	tag = request->username_tag == NULL ? "" : request->username_tag;
 	if (user != NULL) {
 		if (!director_request_existing(request, user, tag))
 			return FALSE;
-		user_directory_refresh(dir->users, user);
+		user_directory_refresh(users, user);
 		dir_debug("request: %u refreshed timeout to %u",
 			  request->username_hash, user->timestamp);
 	} else {
@@ -306,7 +308,7 @@
 				  request->username_hash);
 			return FALSE;
 		}
-		user = user_directory_add(dir->users, request->username_hash,
+		user = user_directory_add(users, request->username_hash,
 					  host, ioloop_time);
 		dir_debug("request: %u added timeout to %u (hosts_hash=%u)",
 			  request->username_hash, user->timestamp,
--- a/src/director/director.c	Thu Oct 20 16:14:36 2016 +0300
+++ b/src/director/director.c	Thu Oct 20 19:17:11 2016 +0300
@@ -628,6 +628,8 @@
 			  struct director_host *orig_src,
 			  struct mail_host *host)
 {
+	struct user_directory *users = dir->users;
+
 	if (src != NULL) {
 		if (orig_src == NULL) {
 			orig_src = dir->self_host;
@@ -640,7 +642,7 @@
 			orig_src->last_seq, net_ip2addr(&host->ip)));
 	}
 
-	user_directory_remove_host(dir->users, host);
+	user_directory_remove_host(users, host);
 	mail_host_remove(host);
 	director_sync(dir);
 }
@@ -649,6 +651,8 @@
 			 struct director_host *orig_src,
 			 struct mail_host *host)
 {
+	struct user_directory *users = dir->users;
+
 	if (orig_src == NULL) {
 		orig_src = dir->self_host;
 		orig_src->last_seq++;
@@ -658,7 +662,7 @@
 		"HOST-FLUSH\t%s\t%u\t%u\t%s\n",
 		net_ip2addr(&orig_src->ip), orig_src->port, orig_src->last_seq,
 		net_ip2addr(&host->ip)));
-	user_directory_remove_host(dir->users, host);
+	user_directory_remove_host(users, host);
 	director_sync(dir);
 }
 
@@ -913,6 +917,7 @@
 					const char *data, void *context)
 {
 	struct director_kill_context *ctx = context;
+	struct user_directory *users = ctx->dir->users;
 	struct user *user;
 
 	/* this is an asynchronous notification about user being killed.
@@ -935,7 +940,7 @@
 
 	ctx->callback_pending = FALSE;
 
-	user = user_directory_lookup(ctx->dir->users, ctx->username_hash);
+	user = user_directory_lookup(users, ctx->username_hash);
 	if (!DIRECTOR_KILL_CONTEXT_IS_VALID(user, ctx)) {
 		/* user was already freed - ignore */
 		i_assert(ctx->to_move == NULL);
@@ -1018,6 +1023,7 @@
 			struct director_host *orig_src,
 			unsigned int username_hash, struct mail_host *host)
 {
+	struct user_directory *users = dir->users;
 	struct user *user;
 
 	/* 1. move this user's host, and set its "killing" flag to delay all of
@@ -1036,9 +1042,9 @@
 	   5. after receiving USER-KILLED-EVERYWHERE notification,
 	   new connections are again allowed for the user.
 	*/
-	user = user_directory_lookup(dir->users, username_hash);
+	user = user_directory_lookup(users, username_hash);
 	if (user == NULL) {
-		user = user_directory_add(dir->users, username_hash,
+		user = user_directory_add(users, username_hash,
 					  host, ioloop_time);
 		director_kill_user(dir, src, user, NULL);
 	} else {
@@ -1159,9 +1165,10 @@
 
 void director_user_killed(struct director *dir, unsigned int username_hash)
 {
+	struct user_directory *users = dir->users;
 	struct user *user;
 
-	user = user_directory_lookup(dir->users, username_hash);
+	user = user_directory_lookup(users, username_hash);
 	if (user == NULL || !USER_IS_BEING_KILLED(user))
 		return;
 
--- a/src/director/doveadm-connection.c	Thu Oct 20 16:14:36 2016 +0300
+++ b/src/director/doveadm-connection.c	Thu Oct 20 19:17:11 2016 +0300
@@ -551,6 +551,7 @@
 doveadm_cmd_user_lookup(struct doveadm_connection *conn,
 			const char *const *args)
 {
+	struct user_directory *users = conn->dir->users;
 	struct user *user;
 	struct mail_host *host;
 	const char *username, *tag;
@@ -565,10 +566,10 @@
 		tag = args[1] != NULL ? args[1] : "";
 	}
 	if (str_to_uint(username, &username_hash) < 0)
-		username_hash = user_directory_get_username_hash(conn->dir->users, username);
+		username_hash = user_directory_get_username_hash(users, username);
 
 	/* get user's current host */
-	user = user_directory_lookup(conn->dir->users, username_hash);
+	user = user_directory_lookup(users, username_hash);
 	if (user == NULL)
 		str_append(str, "\t0");
 	else {
@@ -632,6 +633,7 @@
 static int
 doveadm_cmd_user_move(struct doveadm_connection *conn, const char *const *args)
 {
+	struct user_directory *users = conn->dir->users;
 	unsigned int username_hash;
 	struct user *user;
 	struct mail_host *host;
@@ -649,8 +651,8 @@
 	}
 
 	if (str_to_uint(args[0], &username_hash) < 0)
-		username_hash = user_directory_get_username_hash(conn->dir->users, args[0]);
-	user = user_directory_lookup(conn->dir->users, username_hash);
+		username_hash = user_directory_get_username_hash(users, args[0]);
+	user = user_directory_lookup(users, username_hash);
 	if (user != NULL && USER_IS_BEING_KILLED(user)) {
 		o_stream_nsend_str(conn->output, "TRYAGAIN\n");
 		return 1;