]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap-client: Add const char *disconnect_reason to client
authorMartti Rannanjärvi <martti.rannanjarvi@dovecot.fi>
Tue, 4 Jul 2017 06:25:21 +0000 (09:25 +0300)
committerAki Tuomi <aki.tuomi@dovecot.fi>
Thu, 20 Jul 2017 10:04:21 +0000 (13:04 +0300)
This is to allow using reason given to client_disconnect() via timeout
context.

src/imap/imap-client.c
src/imap/imap-client.h

index c22a12f55edca3745864a650f6a6db78e4cabd68..566c57d0ed5d0761ceeb6aca813db6c1990ead07 100644 (file)
@@ -386,14 +386,7 @@ static const char *client_get_commands_status(struct client *client)
 
 static void client_log_disconnect(struct client *client, const char *reason)
 {
-       const char *cmd_status = "";
-
-       if (reason == NULL) {
-               reason = io_stream_get_disconnect_reason(client->input,
-                                                        client->output);
-               cmd_status = client_get_commands_status(client);
-       }
-       i_info("%s%s %s", reason, cmd_status, client_stats(client));
+       i_info("%s %s", reason, client_stats(client));
 }
 
 static void client_default_destroy(struct client *client, const char *reason)
@@ -402,11 +395,15 @@ static void client_default_destroy(struct client *client, const char *reason)
 
        i_assert(!client->destroyed);
        client->destroyed = TRUE;
+       client->disconnected = TRUE;
 
-       if (!client->disconnected) {
-               client->disconnected = TRUE;
-               client_log_disconnect(client, reason);
-       }
+       if (client->disconnect_reason != NULL)
+               reason = client->disconnect_reason;
+       if (reason == NULL)
+               reason = t_strconcat(
+                       io_stream_get_disconnect_reason(client->input,
+                                                       client->output),
+                       client_get_commands_status(client), NULL);
 
        i_stream_close(client->input);
        o_stream_close(client->output);
@@ -461,8 +458,10 @@ static void client_default_destroy(struct client *client, const char *reason)
           different from the non-hibernating IDLE case. For frequent
           hibernations it could also be doing unnecessarily much work. */
        imap_refresh_proctitle();
-       if (!client->hibernated)
+       if (!client->hibernated) {
                mail_user_autoexpunge(client->user);
+               client_log_disconnect(client, reason);
+       }
        mail_user_unref(&client->user);
 
        /* free the i/ostreams after mail_user_unref(), which could trigger
@@ -497,8 +496,8 @@ void client_disconnect(struct client *client, const char *reason)
        if (client->disconnected)
                return;
 
-       client_log_disconnect(client, reason);
        client->disconnected = TRUE;
+       client->disconnect_reason = p_strdup(client->pool, reason);
        o_stream_nflush(client->output);
        o_stream_uncork(client->output);
 
index 29a6828c40981787ee45d2a623705fa07daf5404..935f2423c6aa4e8947d56821cb35c6a812476765 100644 (file)
@@ -157,6 +157,7 @@ struct client {
        const struct imap_settings *set;
        const struct lda_settings *lda_set;
        string_t *capability_string;
+       const char *disconnect_reason;
 
         struct mail_user *user;
        struct mailbox *mailbox;