From b03492249bb857f083349f27beff0ac70ec5a7d3 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Mon, 19 Nov 2001 22:37:57 +0000 Subject: [PATCH] add input filter AP_MODE_INIT support to handshake before reading request data from the client. PR: Obtained from: Submitted by: dougm Reviewed by: wrowe git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@92043 13f79535-47bb-0310-9956-ffa450edef68 --- modules/ssl/ssl_engine_io.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/modules/ssl/ssl_engine_io.c b/modules/ssl/ssl_engine_io.c index 249116423a..52e3680e3a 100644 --- a/modules/ssl/ssl_engine_io.c +++ b/modules/ssl/ssl_engine_io.c @@ -202,6 +202,15 @@ static apr_status_t churn_input(SSLFilterRec *pRec, ap_input_mode_t eMode, int found_eos = 0, n; char buf[1024]; apr_status_t rv; + int do_handshake = (eMode == AP_MODE_INIT); + + if (do_handshake) { + /* protocol module needs to handshake before sending + * data to client (e.g. NNTP or FTP) + */ + *readbytes = AP_IOBUFSIZE; + eMode = AP_MODE_NONBLOCKING; + } /* Flush the output buffers. */ churn_output(pRec); @@ -213,6 +222,13 @@ static apr_status_t churn_input(SSLFilterRec *pRec, ap_input_mode_t eMode, /* If we have nothing in the raw brigade, get some more. */ if (APR_BRIGADE_EMPTY(ctx->rawb)) { + if (do_handshake) { + /* + * ap_get_brigade with AP_MODE_INIT should always be called + * in non-blocking mode, but we need to block here + */ + eMode = AP_MODE_BLOCKING; + } rv = ap_get_brigade(f->next, ctx->rawb, eMode, readbytes); if (rv != APR_SUCCESS) @@ -289,6 +305,11 @@ static apr_status_t churn_input(SSLFilterRec *pRec, ap_input_mode_t eMode, */ rv = ssl_hook_process_connection(pRec); + if (do_handshake && (rv == APR_SUCCESS)) { + /* don't block after the handshake */ + eMode = AP_MODE_NONBLOCKING; + } + /* Flush again. */ churn_output(pRec); @@ -322,8 +343,12 @@ static apr_status_t churn_input(SSLFilterRec *pRec, ap_input_mode_t eMode, return APR_SUCCESS; } if (rv == SSL_ERROR_WANT_READ) { + /* if eMode was originally AP_MODE_INIT, + * need to reset before we recurse + */ + ap_input_mode_t mode = do_handshake ? AP_MODE_INIT : eMode; apr_off_t tempread = AP_IOBUFSIZE; - return churn_input(pRec, eMode, &tempread); + return churn_input(pRec, mode, &tempread); } return rv; } -- 2.40.0