]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-smtp: server: Add APIs for halting and resuming connection command handling.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Wed, 27 Dec 2017 16:02:12 +0000 (17:02 +0100)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Thu, 28 Dec 2017 18:43:39 +0000 (20:43 +0200)
Also adds function to start the connection in a pending (halted) state. This way the greeting can already be sent (over SSL if needed), while deferring command handling until some external activity is completed.

src/lib-smtp/smtp-server-connection.c
src/lib-smtp/smtp-server-private.h
src/lib-smtp/smtp-server.h

index c411590b2d2afd331f60f65cde8553bd8e695728..b90453c70ce530620c28f9e983ade99601ea7794 100644 (file)
@@ -552,7 +552,13 @@ static void smtp_server_connection_input(struct connection *_conn)
                                "SSL Initialization failed");
                        return;
                }
+               if (conn->halted) {
+                       smtp_server_connection_input_lock(conn);
+                       return;
+               }
        }
+       i_assert(!conn->halted);
+
 
        if (conn->command_queue_count >
                conn->server->set.max_pipelined_commands) {
@@ -937,7 +943,7 @@ smtp_server_connection_create(struct smtp_server *server,
                conn->set.capabilities &= ~SMTP_CAPABILITY_STARTTLS;
 
        /* halt input until started */
-       smtp_server_connection_input_halt(conn);
+       smtp_server_connection_halt(conn);
 
        smtp_server_connection_debug(conn, "Connection created");
 
@@ -969,7 +975,7 @@ smtp_server_connection_create_from_streams(struct smtp_server *server,
        conn->created_from_streams = TRUE;
 
        /* halt input until started */
-       smtp_server_connection_input_halt(conn);
+       smtp_server_connection_halt(conn);
 
        smtp_server_connection_debug(conn, "Connection created");
 
@@ -1144,7 +1150,7 @@ void smtp_server_connection_login(struct smtp_server_connection *conn,
        }
 }
 
-void smtp_server_connection_start(struct smtp_server_connection *conn)
+void smtp_server_connection_start_pending(struct smtp_server_connection *conn)
 {
        i_assert(!conn->started);
        conn->started = TRUE;
@@ -1154,9 +1160,29 @@ void smtp_server_connection_start(struct smtp_server_connection *conn)
 
        if (!conn->ssl_start)
                smtp_server_connection_ready(conn);
+       else if (conn->ssl_iostream == NULL)
+               smtp_server_connection_input_unlock(conn);
+}
 
-       smtp_server_connection_timeout_start(conn);
-       smtp_server_connection_input_resume(conn);
+void smtp_server_connection_start(struct smtp_server_connection *conn)
+{
+       smtp_server_connection_start_pending(conn);
+       smtp_server_connection_resume(conn);
+}
+
+void smtp_server_connection_halt(struct smtp_server_connection *conn)
+{
+       conn->halted = TRUE;
+       smtp_server_connection_timeout_stop(conn);
+       if (!conn->started || !conn->ssl_start || conn->ssl_iostream != NULL)
+               smtp_server_connection_input_lock(conn);
+}
+
+void smtp_server_connection_resume(struct smtp_server_connection *conn)
+{
+       smtp_server_connection_input_unlock(conn);
+       smtp_server_connection_timeout_update(conn);
+       conn->halted = FALSE;
 }
 
 void smtp_server_connection_close(struct smtp_server_connection **_conn,
index ff96a2a2754d4444733b64f7f609be46dad8efb1..3263ebd522ba73d41010dd86c58657f4cd95a10a 100644 (file)
@@ -150,6 +150,7 @@ struct smtp_server_connection {
        struct smtp_server_stats stats;
 
        bool started:1;
+       bool halted:1;
        bool ssl_start:1;
        bool ssl_secured:1;
        bool authenticated:1;
index 99b4bf1d89d166bbe633df2e7400924ced589bbe..2884f0221e194a23d4672c498b3278c70f1431d8 100644 (file)
@@ -304,6 +304,15 @@ void smtp_server_connection_login(struct smtp_server_connection *conn,
 /* Start the connection. Establishes SSL layer immediately if instructed,
    and sends the greeting once the connection is ready for commands. */
 void smtp_server_connection_start(struct smtp_server_connection *conn);
+/* Start the connection, but only establish SSL layer and send greeting;
+   handling command input is held off until smtp_server_connection_resume() is
+   called. */
+void smtp_server_connection_start_pending(struct smtp_server_connection *conn);
+
+/* Halt connection command input and idle timeout entirely. */
+void smtp_server_connection_halt(struct smtp_server_connection *conn);
+/* Resume connection command input and idle timeout. */
+void smtp_server_connection_resume(struct smtp_server_connection *conn);
 
 void smtp_server_connection_input_lock(struct smtp_server_connection *conn);
 void smtp_server_connection_input_unlock(struct smtp_server_connection *conn);