changeset 22216:415130854a53

pop3: move pop3 session locking out of client_create As a result, we can directly return the client structure (instead of passing it back via a _r arg). This makes the pop3 client_create look more like the imap version.
author Josef 'Jeff' Sipek <jeff.sipek@dovecot.fi>
date Fri, 19 May 2017 10:42:03 +0300
parents 05aff1909f97
children d39bef1e08a2
files src/pop3/main.c src/pop3/pop3-client.c src/pop3/pop3-client.h
diffstat 3 files changed, 24 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/pop3/main.c	Tue May 30 16:57:45 2017 +0300
+++ b/src/pop3/main.c	Fri May 19 10:42:03 2017 +0300
@@ -104,6 +104,7 @@
 	struct client *client;
 	const struct pop3_settings *set;
 	const char *error;
+	int ret;
 
 	if (mail_storage_service_lookup_next(storage_service, input,
 					     &user, &mail_user, error_r) <= 0) {
@@ -118,9 +119,17 @@
 	if (set->verbose_proctitle)
 		verbose_proctitle = TRUE;
 
-	if (client_create(fd_in, fd_out, input->session_id,
-			  mail_user, user, set, &client) < 0)
-		return 0;
+	client = client_create(fd_in, fd_out, input->session_id,
+			       mail_user, user, set);
+
+	if (set->pop3_lock_session && (ret = pop3_lock_session(client)) <= 0) {
+		client_send_line(client, ret < 0 ?
+			"-ERR [SYS/TEMP] Failed to create POP3 session lock." :
+			"-ERR [IN-USE] Mailbox is locked by another POP3 session.");
+		client_destroy(client, "Couldn't lock POP3 session");
+		return -1;
+	}
+
 	if (!IS_STANDALONE())
 		client_send_line(client, "+OK Logged in.");
 	if (client_init_mailbox(client, &error) == 0)
--- a/src/pop3/pop3-client.c	Tue May 30 16:57:45 2017 +0300
+++ b/src/pop3/pop3-client.c	Fri May 19 10:42:03 2017 +0300
@@ -332,7 +332,7 @@
 	}
 }
 
-static int pop3_lock_session(struct client *client)
+int pop3_lock_session(struct client *client)
 {
 	const struct mail_storage_settings *mail_set =
 		mail_storage_service_user_get_mail_set(client->service_user);
@@ -375,14 +375,13 @@
 	return ret;
 }
 
-int client_create(int fd_in, int fd_out, const char *session_id,
-		  struct mail_user *user,
-		  struct mail_storage_service_user *service_user,
-		  const struct pop3_settings *set, struct client **client_r)
+struct client *client_create(int fd_in, int fd_out, const char *session_id,
+			     struct mail_user *user,
+			     struct mail_storage_service_user *service_user,
+			     const struct pop3_settings *set)
 {
 	struct client *client;
 	pool_t pool;
-	int ret;
 
 	/* always use nonblocking I/O */
 	net_set_nonblock(fd_in, TRUE);
@@ -441,17 +440,7 @@
 	if (hook_client_created != NULL)
 		hook_client_created(&client);
 
-	if (set->pop3_lock_session && (ret = pop3_lock_session(client)) <= 0) {
-		client_send_line(client, ret < 0 ?
-			"-ERR [SYS/TEMP] Failed to create POP3 session lock." :
-			"-ERR [IN-USE] Mailbox is locked by another POP3 session.");
-		client_destroy(client, "Couldn't lock POP3 session");
-		return -1;
-	}
-
-	*client_r = client;
-	return 0;
-
+	return client;
 }
 
 int client_init_mailbox(struct client *client, const char **error_r)
--- a/src/pop3/pop3-client.h	Tue May 30 16:57:45 2017 +0300
+++ b/src/pop3/pop3-client.h	Fri May 19 10:42:03 2017 +0300
@@ -120,10 +120,10 @@
 
 /* Create new client with specified input/output handles. socket specifies
    if the handle is a socket. */
-int client_create(int fd_in, int fd_out, const char *session_id,
-		  struct mail_user *user,
-		  struct mail_storage_service_user *service_user,
-		  const struct pop3_settings *set, struct client **client_r);
+struct client *client_create(int fd_in, int fd_out, const char *session_id,
+			     struct mail_user *user,
+			     struct mail_storage_service_user *service_user,
+			     const struct pop3_settings *set);
 int client_init_mailbox(struct client *client, const char **error_r);
 void client_destroy(struct client *client, const char *reason) ATTR_NULL(2);
 
@@ -140,4 +140,6 @@
 
 void clients_destroy_all(struct mail_storage_service_ctx *storage_service);
 
+int pop3_lock_session(struct client *client);
+
 #endif