From 8940fec89481f4931b23f460cd4716f44974f079 Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Mon, 10 Aug 2020 23:06:15 -0400 Subject: [PATCH] [multiple] modules read reqbody via fn ptr r->con->reqbody_read() replaces connection_handle_read_post_state() future: might provide different callbacks for request body with Content-Length versus request body sent via Transfer-Encoding: chunked --- src/base.h | 1 + src/connections.c | 1 + src/gw_backend.c | 2 +- src/mod_cgi.c | 2 +- src/mod_webdav.c | 9 ++++----- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/base.h b/src/base.h index 07a117d1..d0a5e7ba 100644 --- a/src/base.h +++ b/src/base.h @@ -45,6 +45,7 @@ struct connection { int (* network_write)(struct connection *con, chunkqueue *cq, off_t max_bytes); int (* network_read)(struct connection *con, chunkqueue *cq, off_t max_bytes); + handler_t (* reqbody_read)(struct request_st *r); server *srv; void *plugin_slots; diff --git a/src/connections.c b/src/connections.c index bb83f9ab..c913ad1e 100644 --- a/src/connections.c +++ b/src/connections.c @@ -1048,6 +1048,7 @@ connection *connection_accepted(server *srv, server_socket *srv_socket, sock_add con->fdn = fdevent_register(srv->ev, con->fd, connection_handle_fdevent, con); con->network_read = connection_read_cq; con->network_write = connection_write_cq; + con->reqbody_read = connection_handle_read_post_state; request_st * const r = &con->request; connection_set_state(r, CON_STATE_REQUEST_START); diff --git a/src/gw_backend.c b/src/gw_backend.c index f5522d39..ab751a40 100644 --- a/src/gw_backend.c +++ b/src/gw_backend.c @@ -2063,7 +2063,7 @@ handler_t gw_handle_subrequest(request_st * const r, void *p_d) { if (0 != hctx->wb->bytes_in) return HANDLER_WAIT_FOR_EVENT; } else { - handler_t rc = connection_handle_read_post_state(r); + handler_t rc = r->con->reqbody_read(r); /* XXX: create configurable flag */ /* CGI environment requires that Content-Length be set. diff --git a/src/mod_cgi.c b/src/mod_cgi.c index adfda4be..4de0b48d 100644 --- a/src/mod_cgi.c +++ b/src/mod_cgi.c @@ -967,7 +967,7 @@ SUBREQUEST_FUNC(mod_cgi_handle_subrequest) { r->conf.stream_request_body &= ~FDEVENT_STREAM_REQUEST_POLLIN; if (-1 != hctx->fd) return HANDLER_WAIT_FOR_EVENT; } else { - handler_t rc = connection_handle_read_post_state(r); + handler_t rc = r->con->reqbody_read(r); if (!chunkqueue_is_empty(cq)) { if (fdevent_fdnode_interest(hctx->fdntocgi) & FDEVENT_OUT) { return (rc == HANDLER_GO_ON) ? HANDLER_WAIT_FOR_EVENT : rc; diff --git a/src/mod_webdav.c b/src/mod_webdav.c index 34071886..21232119 100644 --- a/src/mod_webdav.c +++ b/src/mod_webdav.c @@ -211,7 +211,6 @@ #include "http_header.h" #include "etag.h" #include "log.h" -#include "connections.h"/* connection_handle_read_post_state() */ #include "request.h" #include "response.h" /* http_response_redirect_to_directory() */ #include "stat_cache.h" /* stat_cache_mimetype_by_ext() */ @@ -3809,7 +3808,7 @@ mod_webdav_propfind (request_st * const r, const plugin_config * const pconf) if (r->reqbody_length) { #ifdef USE_PROPPATCH if (r->state == CON_STATE_READ_POST) { - handler_t rc = connection_handle_read_post_state(r); + handler_t rc = r->con->reqbody_read(r); if (rc != HANDLER_GO_ON) return rc; } #else @@ -4530,7 +4529,7 @@ mod_webdav_put (request_st * const r, const plugin_config * const pconf) { if (r->state == CON_STATE_READ_POST) { int first_read = chunkqueue_is_empty(r->reqbody_queue); - handler_t rc = connection_handle_read_post_state(r); + handler_t rc = r->con->reqbody_read(r); if (rc != HANDLER_GO_ON) { if (first_read && rc == HANDLER_WAIT_FOR_EVENT && 0 != webdav_if_match_or_unmodified_since(r, NULL)) { @@ -5068,7 +5067,7 @@ mod_webdav_proppatch (request_st * const r, const plugin_config * const pconf) } if (r->state == CON_STATE_READ_POST) { - handler_t rc = connection_handle_read_post_state(r); + handler_t rc = r->con->reqbody_read(r); if (rc != HANDLER_GO_ON) return rc; } @@ -5284,7 +5283,7 @@ mod_webdav_lock (request_st * const r, const plugin_config * const pconf) if (r->reqbody_length) { if (r->state == CON_STATE_READ_POST) { - handler_t rc = connection_handle_read_post_state(r); + handler_t rc = r->con->reqbody_read(r); if (rc != HANDLER_GO_ON) return rc; } }