From: Josef 'Jeff' Sipek Date: Fri, 19 May 2017 07:42:03 +0000 (+0300) Subject: pop3: move pop3 session locking out of client_create X-Git-Tag: 2.2.31.rc1~43 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2e2048d874fdb1887026a894e28ef975803f110d;p=thirdparty%2Fdovecot%2Fcore.git 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. --- diff --git a/src/pop3/main.c b/src/pop3/main.c index cafe51ac6c..2b24ed9eea 100644 --- a/src/pop3/main.c +++ b/src/pop3/main.c @@ -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) diff --git a/src/pop3/pop3-client.c b/src/pop3/pop3-client.c index 22c9c768fd..2aa09800b8 100644 --- a/src/pop3/pop3-client.c +++ b/src/pop3/pop3-client.c @@ -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) diff --git a/src/pop3/pop3-client.h b/src/pop3/pop3-client.h index 10e34b8d42..d2c6c0eda8 100644 --- a/src/pop3/pop3-client.h +++ b/src/pop3/pop3-client.h @@ -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