libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit de669ead802049bb06f9672aa873b424b8201727
parent 1d356a1f480dc11eef0bfe374ee21ea2ecc5ca7a
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Mon,  5 Jun 2017 22:31:48 +0300

Merged MHD_tls_connection_handle_read() into MHD_connection_handle_read()

Diffstat:
Msrc/microhttpd/connection.c | 12+++++++++++-
Msrc/microhttpd/connection_https.c | 35+++--------------------------------
Msrc/microhttpd/connection_https.h | 13+++++++++++++
Msrc/microhttpd/daemon.c | 2+-
Msrc/microhttpd/internal.h | 6------
5 files changed, 28 insertions(+), 40 deletions(-)

diff --git 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 @@ -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; @@ -181,34 +181,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 * will forward all write requests to the underlying daemon unless @@ -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 @@ -40,6 +40,19 @@ 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. * * @param connection to use diff --git 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 @@ -931,12 +931,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 */