]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: connection - Add connection_set_handshake_ready()
authorAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 28 Feb 2024 11:27:39 +0000 (13:27 +0200)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Thu, 29 Feb 2024 12:28:25 +0000 (14:28 +0200)
src/lib/connection.c
src/lib/connection.h

index e7dfba3694b40e7b0204fd5e7f06cff49c46eb73..f036ab154ac7cba203fa1481f875051b1a2d0735 100644 (file)
@@ -16,8 +16,9 @@
 
 #include <unistd.h>
 
-static void connection_handshake_ready(struct connection *conn)
+void connection_set_handshake_ready(struct connection *conn)
 {
+       i_assert(conn->handshake_finished.tv_sec == 0);
        conn->handshake_received = TRUE;
        conn->handshake_finished = ioloop_timeval;
        if (conn->v.handshake_ready != NULL)
@@ -108,7 +109,7 @@ static int connection_input_parse_lines(struct connection *conn)
                            conn->v.handshake_line != NULL) {
                                ret = conn->v.handshake_line(conn, line);
                                if (ret > 0)
-                                       connection_handshake_ready(conn);
+                                       connection_set_handshake_ready(conn);
                                else if (ret == 0)
                                        /* continue reading */
                                        ret = 1;
@@ -160,7 +161,7 @@ void connection_input_default(struct connection *conn)
                } else if (ret == 0) {
                        return;
                } else {
-                       connection_handshake_ready(conn);
+                       connection_set_handshake_ready(conn);
                }
        }
 
@@ -244,7 +245,7 @@ int connection_input_line_default(struct connection *conn, const char *line)
                if ((ret = conn->v.handshake_args(conn, args)) == 0)
                        ret = 1; /* continue reading */
                else if (ret > 0)
-                       connection_handshake_ready(conn);
+                       connection_set_handshake_ready(conn);
                else {
                        conn->disconnect_reason =
                                CONNECTION_DISCONNECT_HANDSHAKE_FAILED;
@@ -252,7 +253,7 @@ int connection_input_line_default(struct connection *conn, const char *line)
                return ret;
        } else if (!conn->handshake_received) {
                /* we don't do handshakes */
-               connection_handshake_ready(conn);
+               connection_set_handshake_ready(conn);
        }
 
        /* version must be handled though, by something */
index cfdde7e897e53820a7ae43264fb5a26372e7f782..8fbb913ba4a3bc5582755b38dac8c007e58eb8d0 100644 (file)
@@ -275,6 +275,11 @@ void connection_update_counters(struct connection *conn);
 /* This needs to be called if the input/output streams are changed */
 void connection_streams_changed(struct connection *conn);
 
+/* This function must be called if handshaking is handled without
+   connection API. This is automatically called once handshake
+   vfunctions return success and will call the handshake_ready() vfunction. */
+void connection_set_handshake_ready(struct connection *conn);
+
 /* Returns -1 = disconnected, 0 = nothing new, 1 = something new.
    If input_full_behavior is ALLOW, may return also -2 = buffer full. */
 int connection_input_read(struct connection *conn);