Skip to content

Commit

Permalink
pop3: move pop3 session locking out of client_create
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Josef 'Jeff' Sipek authored and villesavolainen committed Jun 16, 2017
1 parent e9799f2 commit 2e2048d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
15 changes: 12 additions & 3 deletions src/pop3/main.c
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down
23 changes: 6 additions & 17 deletions src/pop3/pop3-client.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions src/pop3/pop3-client.h
Expand Up @@ -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);

Expand All @@ -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

0 comments on commit 2e2048d

Please sign in to comment.