]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
submission: submission-client - Record and use protocol state in client object.
authorStephan Bosch <stephan.bosch@open-xchange.com>
Sun, 16 Feb 2020 20:08:08 +0000 (21:08 +0100)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 21 Feb 2020 06:39:59 +0000 (06:39 +0000)
src/submission/main.c
src/submission/submission-client.c
src/submission/submission-client.h

index 36ef9e0e68edfe56ed8947652c9ca276e3125ff5..a0eff439a55d15b675c0d1d0cebb7b6704b6b971 100644 (file)
@@ -75,7 +75,11 @@ void submission_refresh_proctitle(void)
                                   net_ip2addr(client->user->conn.remote_ip));
                }
                str_append_c(title, ' ');
-               str_append(title, client_state_get_name(client));
+               str_append(title, smtp_server_state_names[client->state.state]);
+               if (client->state.args != NULL && *client->state.args != '\0') {
+                       str_append_c(title, ' ');
+                       str_append(title, client->state.args);
+               }
                break;
        default:
                str_printfa(title, "%u connections", submission_client_count);
index ae45d86d7eaddc1949209ed7aedfa73d57ae7df6..cb688efccb9cc037e8ec33b17ef47d087dd8472f 100644 (file)
@@ -287,6 +287,7 @@ struct client *client_create(int fd_in, int fd_out,
 
 static void client_state_reset(struct client *client)
 {
+       i_free(client->state.args);
        i_stream_unref(&client->state.data_input);
        pool_unref(&client->state.pool);
 
@@ -378,9 +379,16 @@ client_default_trans_free(struct client *client,
 
 static void
 client_connection_state_changed(void *context ATTR_UNUSED,
-                               enum smtp_server_state new_state ATTR_UNUSED,
-                               const char *new_args ATTR_UNUSED)
+                               enum smtp_server_state new_state,
+                               const char *new_args)
 {
+       struct client *client = context;
+
+       i_free(client->state.args);
+
+       client->state.state = new_state;
+       client->state.args = i_strdup(new_args);
+
        if (submission_client_count == 1)
                submission_refresh_proctitle();
 }
@@ -394,8 +402,6 @@ static void client_connection_disconnect(void *context, const char *reason)
        if (conn != NULL) {
                stats = smtp_server_connection_get_stats(conn);
                client->stats = *stats;
-               client->last_state =
-                       smtp_server_connection_get_state(conn, NULL);
        }
        client_disconnect(client, NULL, reason);
 }
@@ -407,17 +413,6 @@ static void client_connection_destroy(void *context)
        client_destroy(client, NULL, NULL);
 }
 
-const char *client_state_get_name(struct client *client)
-{
-       enum smtp_server_state state;
-
-       if (client->conn == NULL)
-               state = client->last_state;
-       else
-               state = smtp_server_connection_get_state(client->conn, NULL);
-       return smtp_server_state_names[state];
-}
-
 static const char *client_stats(struct client *client)
 {
        const char *trans_id = (client->conn == NULL ? "" :
@@ -476,13 +471,11 @@ void client_disconnect(struct client *client, const char *enh_code,
        i_info("Disconnect from %s: %s %s (state=%s)",
               client_remote_id(client),
               log_reason, client_stats(client),
-              client_state_get_name(client));
+              smtp_server_state_names[client->state.state]);
 
        conn = client->conn;
        client->conn = NULL;
        if (conn != NULL) {
-               client->last_state =
-                       smtp_server_connection_get_state(conn, NULL);
                smtp_server_connection_terminate(&conn,
                        (enh_code == NULL ? "4.0.0" : enh_code), reason);
        }
index 6cd5a63d9a8ee753e0e119d9584e266306f5ca42..1c1c6ec80c4ecb69cd7877ff2f77543468017f44 100644 (file)
@@ -12,6 +12,8 @@ struct client;
 
 struct client_state {
        pool_t pool;
+       enum smtp_server_state state;
+       char *args;
 
        struct submission_backend *backend;
        struct istream *data_input;
@@ -85,7 +87,6 @@ struct client {
        const struct submission_settings *set;
 
        struct smtp_server_connection *conn;
-       enum smtp_server_state last_state;
        struct client_state state;
        ARRAY(struct submission_backend *) pending_backends;
        ARRAY(struct submission_recipient *) rcpt_to;
@@ -152,8 +153,6 @@ void client_apply_backend_capabilities(struct client *client);
 void client_default_backend_started(struct client *client,
                                    enum smtp_capability caps);
 
-const char *client_state_get_name(struct client *client);
-
 uoff_t client_get_max_mail_size(struct client *client);
 
 void client_add_extra_capability(struct client *client, const char *capability,