From de669ead802049bb06f9672aa873b424b8201727 Mon Sep 17 00:00:00 2001 From: "Evgeny Grin (Karlson2k)" Date: Mon, 5 Jun 2017 22:31:48 +0300 Subject: [PATCH] Merged MHD_tls_connection_handle_read() into MHD_connection_handle_read() --- src/microhttpd/connection.c | 12 ++++++++++- src/microhttpd/connection_https.c | 35 +++---------------------------- src/microhttpd/connection_https.h | 13 ++++++++++++ src/microhttpd/daemon.c | 2 +- src/microhttpd/internal.h | 6 ------ 5 files changed, 28 insertions(+), 40 deletions(-) diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c index 1a692618..c0fb687b 100644 --- a/src/microhttpd/connection.c +++ b/src/microhttpd/connection.c @@ -2667,6 +2667,17 @@ MHD_connection_handle_read (struct MHD_Connection *connection) if ( (MHD_CONNECTION_CLOSED == connection->state) || (connection->suspended) ) return MHD_YES; +#ifdef HTTPS_SUPPORT + if (MHD_TLS_CONN_NO_TLS != connection->tls_state) + { /* HTTPS connection. */ + if (MHD_TLS_CONN_CONNECTED > connection->tls_state) + { + if (!MHD_run_tls_handshake_ (connection)) + return MHD_YES; + } + } +#endif /* HTTPS_SUPPORT */ + /* make sure "read" has a reasonable number of bytes in buffer to use per system call (if possible) */ if (connection->read_buffer_offset + connection->daemon->pool_increment > @@ -3624,7 +3635,6 @@ MHD_connection_epoll_update_ (struct MHD_Connection *connection) void MHD_set_http_callbacks_ (struct MHD_Connection *connection) { - connection->read_handler = &MHD_connection_handle_read; connection->write_handler = &MHD_connection_handle_write; connection->recv_cls = &recv_param_adapter; connection->send_cls = &send_param_adapter; diff --git a/src/microhttpd/connection_https.c b/src/microhttpd/connection_https.c index 9e7c1953..c168d543 100644 --- a/src/microhttpd/connection_https.c +++ b/src/microhttpd/connection_https.c @@ -143,8 +143,8 @@ send_tls_adapter (struct MHD_Connection *connection, * false is handshake in progress or in case * of error */ -static bool -run_tls_handshake (struct MHD_Connection *connection) +bool +MHD_run_tls_handshake_ (struct MHD_Connection *connection) { int ret; @@ -180,34 +180,6 @@ run_tls_handshake (struct MHD_Connection *connection) } -/** - * This function handles a particular SSL/TLS connection when - * it has been determined that there is data to be read off a - * socket. Message processing is done by message type which is - * determined by peeking into the first message type byte of the - * stream. - * - * Error message handling: all fatal level messages cause the - * connection to be terminated. - * - * Application data is forwarded to the underlying daemon for - * processing. - * - * @param connection the source connection - * @return always #MHD_YES (we should continue to process the connection) - */ -static int -MHD_tls_connection_handle_read (struct MHD_Connection *connection) -{ - if (MHD_TLS_CONN_CONNECTED > connection->tls_state) - { - if (!run_tls_handshake(connection)) - return MHD_YES; - } - return MHD_connection_handle_read (connection); -} - - /** * This function was created to handle writes to sockets when it has * been determined that the socket can be written to. This function @@ -221,7 +193,7 @@ MHD_tls_connection_handle_write (struct MHD_Connection *connection) { if (MHD_TLS_CONN_CONNECTED > connection->tls_state) { - if (!run_tls_handshake(connection)) + if (!MHD_run_tls_handshake_(connection)) return MHD_YES; } return MHD_connection_handle_write (connection); @@ -237,7 +209,6 @@ MHD_tls_connection_handle_write (struct MHD_Connection *connection) void MHD_set_https_callbacks (struct MHD_Connection *connection) { - connection->read_handler = &MHD_tls_connection_handle_read; connection->write_handler = &MHD_tls_connection_handle_write; connection->recv_cls = &recv_tls_adapter; connection->send_cls = &send_tls_adapter; diff --git a/src/microhttpd/connection_https.h b/src/microhttpd/connection_https.h index b9686870..1c12ea9f 100644 --- a/src/microhttpd/connection_https.h +++ b/src/microhttpd/connection_https.h @@ -39,6 +39,19 @@ void MHD_set_https_callbacks (struct MHD_Connection *connection); +/** + * Give gnuTLS chance to work on the TLS handshake. + * + * @param connection connection to handshake on + * @return true if the handshake has completed successfully + * and we should start to read/write data, + * false is handshake in progress or in case + * of error + */ +bool +MHD_run_tls_handshake_ (struct MHD_Connection *connection); + + /** * Initiate shutdown of TLS layer of connection. * diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c index 48fe6856..d54cdbf5 100644 --- a/src/microhttpd/daemon.c +++ b/src/microhttpd/daemon.c @@ -1043,7 +1043,7 @@ call_handlers (struct MHD_Connection *con, if ( (MHD_EVENT_LOOP_INFO_READ == con->event_loop_info) && read_ready) { - con->read_handler (con); + MHD_connection_handle_read (con); ret = MHD_connection_handle_idle (con); states_info_processed = true; } diff --git a/src/microhttpd/internal.h b/src/microhttpd/internal.h index eaed1580..90c7259f 100644 --- a/src/microhttpd/internal.h +++ b/src/microhttpd/internal.h @@ -930,12 +930,6 @@ struct MHD_Connection */ uint64_t current_chunk_offset; - /** - * Handler used for processing read connection operations - * @sa #MHD_connection_handle_read, #MHD_tls_connection_handle_read - */ - int (*read_handler) (struct MHD_Connection *connection); - /** * Handler used for processing write connection operations * @sa #MHD_connection_handle_write, #MHD_tls_connection_handle_write