]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
pop3: move pop3 session locking out of client_create
authorJosef 'Jeff' Sipek <jeff.sipek@dovecot.fi>
Fri, 19 May 2017 07:42:03 +0000 (10:42 +0300)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Fri, 16 Jun 2017 06:16:54 +0000 (09:16 +0300)
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.

src/pop3/main.c
src/pop3/pop3-client.c
src/pop3/pop3-client.h

index cafe51ac6c4842bc0250478894ea1196f940b7c5..2b24ed9eea5ca222f908652bd4b29a551a69b445 100644 (file)
@@ -104,6 +104,7 @@ client_create_from_input(const struct mail_storage_service_input *input,
        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 @@ client_create_from_input(const struct mail_storage_service_input *input,
        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)
index 22c9c768fd536b1534a1e198596bcb18a60091cc..2aa09800b88b55c95f8c6fd5fa67cadfbbf7c44f 100644 (file)
@@ -332,7 +332,7 @@ static void pop3_lock_session_refresh(struct client *client)
        }
 }
 
-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 @@ static int pop3_lock_session(struct client *client)
        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 @@ int client_create(int fd_in, int fd_out, const char *session_id,
        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)
index 10e34b8d4251175ab7fdfb4a228c6fe20a807127..d2c6c0eda85e4d76707e810e682bbe49eeb0dd15 100644 (file)
@@ -120,10 +120,10 @@ extern unsigned int pop3_client_count;
 
 /* 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 @@ bool client_update_mails(struct client *client);
 
 void clients_destroy_all(struct mail_storage_service_ctx *storage_service);
 
+int pop3_lock_session(struct client *client);
+
 #endif