]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
submission: Simplify client_destroy() handling
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 2 Mar 2021 14:00:24 +0000 (16:00 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Thu, 11 Mar 2021 11:19:09 +0000 (11:19 +0000)
Now it simply calls smtp_server_connection_terminate() and the
conn_free() callback does the actual destroying.

src/submission/submission-backend.c
src/submission/submission-client.c
src/submission/submission-client.h

index 6f822a9f77da77eec533ff18a4f6150ecd72924f..5bbcdc4e6a5e1f21b008e07b4afa4315c0a0f617 100644 (file)
@@ -137,7 +137,7 @@ void submission_backend_fail(struct submission_backend *backend,
 
        if (backend == client->backend_default) {
                /* default backend: fail the whole client */
-               client_destroy(client, enh_code, reason);
+               client_destroy(&client, enh_code, reason);
                return;
        }
 
index 43299fb727f74115daf000c32b8c781eadb2d6d2..e4503ae9c1c0ceddab3f9c0c69c10f9eae0f25f7 100644 (file)
@@ -294,25 +294,26 @@ static void client_state_reset(struct client *client)
        i_zero(&client->state);
 }
 
-void client_destroy(struct client *client, const char *prefix,
+void client_destroy(struct client **_client, const char *prefix,
                    const char *reason)
 {
-       client->v.destroy(client, prefix, reason);
+       struct client *client = *_client;
+
+       *_client = NULL;
+
+       smtp_server_connection_terminate(&client->conn,
+               (prefix == NULL ? "4.0.0" : prefix), reason);
 }
 
 static void
-client_default_destroy(struct client *client, const char *prefix,
-                      const char *reason)
+client_default_destroy(struct client *client)
 {
+       i_assert(client->disconnected);
+
        if (client->destroyed)
                return;
        client->destroyed = TRUE;
 
-       if (client->conn != NULL) {
-               smtp_server_connection_terminate(&client->conn,
-                       (prefix == NULL ? "4.0.0" : prefix), reason);
-       }
-
        submission_backends_destroy_all(client);
        array_free(&client->pending_backends);
        array_free(&client->rcpt_to);
@@ -459,7 +460,7 @@ static void client_connection_free(void *context)
 {
        struct client *client = context;
 
-       client_destroy(client, NULL, NULL);
+       client->v.destroy(client);
 }
 
 uoff_t client_get_max_mail_size(struct client *client)
@@ -512,9 +513,10 @@ void client_add_extra_capability(struct client *client, const char *capability,
 void clients_destroy_all(void)
 {
        while (submission_clients != NULL) {
-               mail_storage_service_io_activate_user(submission_clients->service_user);
-               client_destroy(submission_clients,
-                       "4.3.2", "Shutting down");
+               struct client *client = submission_clients;
+
+               mail_storage_service_io_activate_user(client->service_user);
+               client_destroy(&client, "4.3.2", "Shutting down");
        }
 }
 
index e24efd8ef352162ef7602cbb7adc12fd236e5e4c..37752685f4dab4af51bd9992e73b8b131eadf420 100644 (file)
@@ -28,8 +28,7 @@ struct client_extra_capability {
 };
 
 struct submission_client_vfuncs {
-       void (*destroy)(struct client *client, const char *prefix,
-                       const char *reason);
+       void (*destroy)(struct client *client);
 
        void (*trans_start)(struct client *client,
                            struct smtp_server_transaction *trans);
@@ -142,7 +141,7 @@ struct client *client_create(int fd_in, int fd_out,
                             const char *helo,
                             const unsigned char *pdata,
                             unsigned int pdata_len);
-void client_destroy(struct client *client, const char *prefix,
+void client_destroy(struct client **client, const char *prefix,
                    const char *reason) ATTR_NULL(2, 3);
 
 typedef void (*client_input_callback_t)(struct client *context);