From 100dfaa3f3785704d2df264e27ab698e27272687 Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Wed, 8 Jan 2020 23:53:06 -0500 Subject: [PATCH] [core] move plugin_ctx into (request_st *) NB: in the future, a separate plugin_ctx may be needed for connection-level plugins to keep state across multiple requests --- src/base.h | 1 - src/connections.c | 12 ++++++------ src/gw_backend.c | 10 +++++----- src/mod_authn_gssapi.c | 6 +++--- src/mod_cgi.c | 8 ++++---- src/mod_deflate.c | 6 +++--- src/mod_extforward.c | 20 ++++++++++---------- src/mod_fastcgi.c | 2 +- src/mod_maxminddb.c | 8 ++++---- src/mod_mysql_vhost.c | 8 ++++---- src/mod_openssl.c | 20 ++++++++++---------- src/mod_proxy.c | 2 +- src/mod_rewrite.c | 8 ++++---- src/mod_scgi.c | 2 +- src/mod_setenv.c | 10 +++++----- src/mod_sockproxy.c | 2 +- src/mod_ssi.c | 8 ++++---- src/mod_vhostdb.c | 8 ++++---- src/mod_webdav.c | 11 ++++++----- src/mod_wstunnel.c | 4 ++-- src/request.h | 1 + 21 files changed, 79 insertions(+), 78 deletions(-) diff --git a/src/base.h b/src/base.h index 518e359d..c5f44cec 100644 --- a/src/base.h +++ b/src/base.h @@ -115,7 +115,6 @@ struct connection { server *srv; void *plugin_slots; - void **plugin_ctx; /* plugin connection specific config */ request_config conf; void *config_data_base; diff --git a/src/connections.c b/src/connections.c index 094a97fc..6359d31b 100644 --- a/src/connections.c +++ b/src/connections.c @@ -101,10 +101,10 @@ static void connection_plugin_ctx_check(server *srv, connection *con) { for (uint32_t i = 0; i < srv->plugins.used; ++i) { plugin *p = ((plugin **)(srv->plugins.ptr))[i]; plugin_data_base *pd = p->data; - if (!pd || NULL == con->plugin_ctx[pd->id]) continue; + if (!pd || NULL == con->request.plugin_ctx[pd->id]) continue; log_error(con->conf.errh, __FILE__, __LINE__, "missing cleanup in %s", p->name); - con->plugin_ctx[pd->id] = NULL; + con->request.plugin_ctx[pd->id] = NULL; } } @@ -139,7 +139,7 @@ static int connection_close(connection *con) { /* plugins should have cleaned themselves up */ for (uint32_t i = 0; i < srv->plugins.used; ++i) { - if (NULL != con->plugin_ctx[i]) { + if (NULL != con->request.plugin_ctx[i]) { connection_plugin_ctx_check(srv, con); break; } @@ -574,8 +574,8 @@ static connection *connection_init(server *srv) { /* init plugin specific connection structures */ - con->plugin_ctx = calloc(1, (srv->plugins.used + 1) * sizeof(void *)); - force_assert(NULL != con->plugin_ctx); + con->request.plugin_ctx = calloc(1, (srv->plugins.used + 1) * sizeof(void *)); + force_assert(NULL != con->request.plugin_ctx); con->request.cond_cache = calloc(srv->config_context->used, sizeof(cond_cache_t)); force_assert(NULL != con->request.cond_cache); @@ -628,7 +628,7 @@ void connections_free(server *srv) { CLEAN(request.server_name_buf); CLEAN(dst_addr_buf); #undef CLEAN - free(con->plugin_ctx); + free(con->request.plugin_ctx); free(con->request.cond_cache); free(con->request.cond_match); diff --git a/src/gw_backend.c b/src/gw_backend.c index ade73086..607b2725 100644 --- a/src/gw_backend.c +++ b/src/gw_backend.c @@ -1756,7 +1756,7 @@ static void gw_connection_close(gw_handler_ctx *hctx, connection *con) { gw_backend_close(hctx, con); handler_ctx_free(hctx); - con->plugin_ctx[p->id] = NULL; + con->request.plugin_ctx[p->id] = NULL; if (con->mode == p->id) { http_response_backend_done(con); @@ -1780,7 +1780,7 @@ static handler_t gw_reconnect(gw_handler_ctx *hctx, connection *con) { handler_t gw_connection_reset(connection *con, void *p_d) { gw_plugin_data *p = p_d; - gw_handler_ctx *hctx = con->plugin_ctx[p->id]; + gw_handler_ctx *hctx = con->request.plugin_ctx[p->id]; if (hctx) gw_connection_close(hctx, con); return HANDLER_GO_ON; @@ -2007,7 +2007,7 @@ static handler_t gw_recv_response(gw_handler_ctx *hctx, connection *con); handler_t gw_handle_subrequest(connection *con, void *p_d) { gw_plugin_data *p = p_d; - gw_handler_ctx *hctx = con->plugin_ctx[p->id]; + gw_handler_ctx *hctx = con->request.plugin_ctx[p->id]; if (NULL == hctx) return HANDLER_GO_ON; if (con->mode != p->id) return HANDLER_GO_ON; /* not my job */ @@ -2311,7 +2311,7 @@ handler_t gw_check_extension(connection *con, gw_plugin_data *p, int uri_path_ha /* check p->conf.exts_auth list and then p->conf.ext_resp list * (skip p->conf.exts_auth if array is empty * or if GW_AUTHORIZER already ran in this request) */ - hctx = con->plugin_ctx[p->id]; + hctx = con->request.plugin_ctx[p->id]; /*(hctx not NULL if GW_AUTHORIZER ran; hctx->ext_auth check is redundant)*/ gw_mode = (NULL == hctx || NULL == hctx->ext_auth) ? 0 /*GW_AUTHORIZER p->conf.exts_auth will be searched next*/ @@ -2495,7 +2495,7 @@ handler_t gw_check_extension(connection *con, gw_plugin_data *p, int uri_path_ha hctx->opts.xsendfile_allow = host->xsendfile_allow; hctx->opts.xsendfile_docroot = host->xsendfile_docroot; - con->plugin_ctx[p->id] = hctx; + con->request.plugin_ctx[p->id] = hctx; con->mode = p->id; diff --git a/src/mod_authn_gssapi.c b/src/mod_authn_gssapi.c index 20dc27b1..84f7de2a 100644 --- a/src/mod_authn_gssapi.c +++ b/src/mod_authn_gssapi.c @@ -217,7 +217,7 @@ static int mod_authn_gssapi_create_krb5_ccache(connection *con, plugin_data *p, break; } - con->plugin_ctx[p->id] = kccname; + con->request.plugin_ctx[p->id] = kccname; http_header_env_set(con, CONST_STR_LEN("KRB5CCNAME"), ccname, ccnamelen); http_header_request_set(con, HTTP_HEADER_OTHER, CONST_STR_LEN("X-Forwarded-Keytab"), ccname, ccnamelen); @@ -767,9 +767,9 @@ static handler_t mod_authn_gssapi_basic(connection *con, void *p_d, const http_a CONNECTION_FUNC(mod_authn_gssapi_handle_reset) { plugin_data *p = (plugin_data *)p_d; - buffer *kccname = (buffer *)con->plugin_ctx[p->id]; + buffer *kccname = (buffer *)con->request.plugin_ctx[p->id]; if (NULL != kccname) { - con->plugin_ctx[p->id] = NULL; + con->request.plugin_ctx[p->id] = NULL; unlink(kccname->ptr+sizeof("FILE:")-1); buffer_free(kccname); } diff --git a/src/mod_cgi.c b/src/mod_cgi.c index b1e4042a..d973a7c2 100644 --- a/src/mod_cgi.c +++ b/src/mod_cgi.c @@ -329,7 +329,7 @@ static void cgi_connection_close(connection *con, handler_ctx *hctx) { cgi_pid_kill(p, hctx->pid); } - con->plugin_ctx[p->id] = NULL; + con->request.plugin_ctx[p->id] = NULL; cgi_handler_ctx_free(hctx); @@ -341,7 +341,7 @@ static void cgi_connection_close(connection *con, handler_ctx *hctx) { static handler_t cgi_connection_close_callback(connection *con, void *p_d) { plugin_data *p = p_d; - handler_ctx *hctx = con->plugin_ctx[p->id]; + handler_ctx *hctx = con->request.plugin_ctx[p->id]; if (hctx) cgi_connection_close(con, hctx); return HANDLER_GO_ON; @@ -914,7 +914,7 @@ URIHANDLER_FUNC(cgi_is_handled) { hctx->opts.xsendfile_docroot = hctx->conf.xsendfile_docroot; hctx->opts.pdata = hctx; hctx->opts.headers = cgi_response_headers; - con->plugin_ctx[p->id] = hctx; + con->request.plugin_ctx[p->id] = hctx; con->mode = p->id; } @@ -928,7 +928,7 @@ URIHANDLER_FUNC(cgi_is_handled) { */ SUBREQUEST_FUNC(mod_cgi_handle_subrequest) { plugin_data * const p = p_d; - handler_ctx * const hctx = con->plugin_ctx[p->id]; + handler_ctx * const hctx = con->request.plugin_ctx[p->id]; if (con->mode != p->id) return HANDLER_GO_ON; if (NULL == hctx) return HANDLER_GO_ON; diff --git a/src/mod_deflate.c b/src/mod_deflate.c index b5033e7b..0716f438 100644 --- a/src/mod_deflate.c +++ b/src/mod_deflate.c @@ -737,7 +737,7 @@ static int mod_deflate_stream_end(handler_ctx *hctx) { static void deflate_compress_cleanup(connection *con, handler_ctx *hctx) { const plugin_data *p = hctx->plugin_data; - con->plugin_ctx[p->id] = NULL; + con->request.plugin_ctx[p->id] = NULL; if (0 != mod_deflate_stream_end(hctx)) { log_error(con->conf.errh, __FILE__, __LINE__, "error closing stream"); @@ -1230,7 +1230,7 @@ CONNECTION_FUNC(mod_deflate_handle_response_start) { if (con->response.htags & HTTP_HEADER_CONTENT_LENGTH) { http_header_response_unset(con, HTTP_HEADER_CONTENT_LENGTH, CONST_STR_LEN("Content-Length")); } - con->plugin_ctx[p->id] = hctx; + con->request.plugin_ctx[p->id] = hctx; rc = deflate_compress_response(con, hctx); if (HANDLER_GO_ON != rc) { @@ -1246,7 +1246,7 @@ CONNECTION_FUNC(mod_deflate_handle_response_start) { static handler_t mod_deflate_cleanup(connection *con, void *p_d) { plugin_data *p = p_d; - handler_ctx *hctx = con->plugin_ctx[p->id]; + handler_ctx *hctx = con->request.plugin_ctx[p->id]; if (NULL != hctx) deflate_compress_cleanup(con, hctx); diff --git a/src/mod_extforward.c b/src/mod_extforward.c index 7e301d87..9793f59e 100644 --- a/src/mod_extforward.c +++ b/src/mod_extforward.c @@ -532,7 +532,7 @@ static const char *last_not_in_array(array *a, plugin_data *p) static int mod_extforward_set_addr(connection *con, plugin_data *p, const char *addr) { sock_addr sock; - handler_ctx *hctx = con->plugin_ctx[p->id]; + handler_ctx *hctx = con->request.plugin_ctx[p->id]; if (con->conf.log_request_handling) { log_error(con->conf.errh, __FILE__, __LINE__, "using address: %s", addr); @@ -555,7 +555,7 @@ static int mod_extforward_set_addr(connection *con, plugin_data *p, const char * hctx->saved_remote_addr_buf = NULL; } } else { - con->plugin_ctx[p->id] = hctx = handler_ctx_init(); + con->request.plugin_ctx[p->id] = hctx = handler_ctx_init(); } /* save old address */ if (extforward_check_proxy) { @@ -1032,7 +1032,7 @@ static handler_t mod_extforward_Forwarded (connection *con, plugin_data *p, cons URIHANDLER_FUNC(mod_extforward_uri_handler) { plugin_data *p = p_d; const buffer *forwarded = NULL; - handler_ctx *hctx = con->plugin_ctx[p->id]; + handler_ctx *hctx = con->request.plugin_ctx[p->id]; int is_forwarded_header = 0; mod_extforward_patch_config(con, p); @@ -1102,7 +1102,7 @@ URIHANDLER_FUNC(mod_extforward_uri_handler) { CONNECTION_FUNC(mod_extforward_handle_request_env) { plugin_data *p = p_d; - handler_ctx *hctx = con->plugin_ctx[p->id]; + handler_ctx *hctx = con->request.plugin_ctx[p->id]; if (NULL == hctx || NULL == hctx->env) return HANDLER_GO_ON; for (uint32_t i=0; i < hctx->env->used; ++i) { /* note: replaces values which may have been set by mod_openssl @@ -1117,7 +1117,7 @@ CONNECTION_FUNC(mod_extforward_handle_request_env) { CONNECTION_FUNC(mod_extforward_restore) { plugin_data *p = p_d; - handler_ctx *hctx = con->plugin_ctx[p->id]; + handler_ctx *hctx = con->request.plugin_ctx[p->id]; if (!hctx) return HANDLER_GO_ON; @@ -1137,7 +1137,7 @@ CONNECTION_FUNC(mod_extforward_restore) { if (NULL == hctx->env) { handler_ctx_free(hctx); - con->plugin_ctx[p->id] = NULL; + con->request.plugin_ctx[p->id] = NULL; } return HANDLER_GO_ON; @@ -1147,7 +1147,7 @@ CONNECTION_FUNC(mod_extforward_restore) { CONNECTION_FUNC(mod_extforward_handle_con_close) { plugin_data *p = p_d; - handler_ctx *hctx = con->plugin_ctx[p->id]; + handler_ctx *hctx = con->request.plugin_ctx[p->id]; if (NULL != hctx) { if (NULL != hctx->saved_network_read) { con->network_read = hctx->saved_network_read; @@ -1161,7 +1161,7 @@ CONNECTION_FUNC(mod_extforward_handle_con_close) array_free(hctx->env); } handler_ctx_free(hctx); - con->plugin_ctx[p->id] = NULL; + con->request.plugin_ctx[p->id] = NULL; } return HANDLER_GO_ON; @@ -1178,7 +1178,7 @@ CONNECTION_FUNC(mod_extforward_handle_con_accept) if (NULL == p->conf.forwarder) return HANDLER_GO_ON; if (is_connection_trusted(con, p)) { handler_ctx *hctx = handler_ctx_init(); - con->plugin_ctx[p->id] = hctx; + con->request.plugin_ctx[p->id] = hctx; hctx->saved_network_read = con->network_read; con->network_read = mod_extforward_network_read; } @@ -1578,7 +1578,7 @@ static int mod_extforward_hap_PROXY_v2 (connection * const con, case PP2_TYPE_SSL: { static const uint32_t zero = 0; handler_ctx *hctx = - con->plugin_ctx[mod_extforward_plugin_data_singleton->id]; + con->request.plugin_ctx[mod_extforward_plugin_data_singleton->id]; struct pp2_tlv_ssl *tlv_ssl = (struct pp2_tlv_ssl *)(void *)((char *)tlv+3); struct pp2_tlv *subtlv = tlv; diff --git a/src/mod_fastcgi.c b/src/mod_fastcgi.c index 2e1a174a..873ed738 100644 --- a/src/mod_fastcgi.c +++ b/src/mod_fastcgi.c @@ -504,7 +504,7 @@ static handler_t fcgi_check_extension(connection *con, void *p_d, int uri_path_h if (HANDLER_GO_ON != rc) return rc; if (con->mode == p->id) { - handler_ctx *hctx = con->plugin_ctx[p->id]; + handler_ctx *hctx = con->request.plugin_ctx[p->id]; hctx->opts.backend = BACKEND_FASTCGI; hctx->opts.parse = fcgi_recv_parse; hctx->opts.pdata = hctx; diff --git a/src/mod_maxminddb.c b/src/mod_maxminddb.c index aadb8a17..28939408 100644 --- a/src/mod_maxminddb.c +++ b/src/mod_maxminddb.c @@ -423,9 +423,9 @@ CONNECTION_FUNC(mod_maxminddb_request_env_handler) /* check that mod_maxmind is activated and env fields were requested */ if (!pconf.activate || NULL == pconf.env) return HANDLER_GO_ON; - array *env = con->plugin_ctx[p->id]; + array *env = con->request.plugin_ctx[p->id]; if (NULL == env) { - env = con->plugin_ctx[p->id] = array_init(pconf.env->used); + env = con->request.plugin_ctx[p->id] = array_init(pconf.env->used); if (pconf.mmdb) mod_maxmind_geoip2(env, &con->dst_addr, &pconf); } @@ -445,10 +445,10 @@ CONNECTION_FUNC(mod_maxminddb_request_env_handler) CONNECTION_FUNC(mod_maxminddb_handle_con_close) { plugin_data *p = p_d; - array *env = con->plugin_ctx[p->id]; + array *env = con->request.plugin_ctx[p->id]; if (NULL != env) { array_free(env); - con->plugin_ctx[p->id] = NULL; + con->request.plugin_ctx[p->id] = NULL; } return HANDLER_GO_ON; diff --git a/src/mod_mysql_vhost.c b/src/mod_mysql_vhost.c index 05b765cc..a92a96e2 100644 --- a/src/mod_mysql_vhost.c +++ b/src/mod_mysql_vhost.c @@ -67,7 +67,7 @@ FREE_FUNC(mod_mysql_vhost_cleanup) { static void* mod_mysql_vhost_connection_data(connection *con, void *p_d) { plugin_data *p = p_d; - plugin_connection_data *c = con->plugin_ctx[p->id]; + plugin_connection_data *c = con->request.plugin_ctx[p->id]; if (c) return c; c = calloc(1, sizeof(*c)); @@ -75,12 +75,12 @@ static void* mod_mysql_vhost_connection_data(connection *con, void *p_d) c->server_name = buffer_init(); c->document_root = buffer_init(); - return con->plugin_ctx[p->id] = c; + return con->request.plugin_ctx[p->id] = c; } CONNECTION_FUNC(mod_mysql_vhost_handle_connection_reset) { plugin_data *p = p_d; - plugin_connection_data *c = con->plugin_ctx[p->id]; + plugin_connection_data *c = con->request.plugin_ctx[p->id]; if (!c) return HANDLER_GO_ON; @@ -89,7 +89,7 @@ CONNECTION_FUNC(mod_mysql_vhost_handle_connection_reset) { free(c); - con->plugin_ctx[p->id] = NULL; + con->request.plugin_ctx[p->id] = NULL; return HANDLER_GO_ON; } diff --git a/src/mod_openssl.c b/src/mod_openssl.c index 93dc8f1d..0075a774 100644 --- a/src/mod_openssl.c +++ b/src/mod_openssl.c @@ -110,7 +110,7 @@ typedef struct { static int ssl_is_init; /* need assigned p->id for deep access of module handler_ctx for connection - * i.e. handler_ctx *hctx = con->plugin_ctx[plugin_data_singleton->id]; */ + * i.e. handler_ctx *hctx = con->request.plugin_ctx[plugin_data_singleton->id]; */ static plugin_data *plugin_data_singleton; #define LOCAL_SEND_BUFSIZE (16 * 1024) static char *local_send_buffer; @@ -1780,7 +1780,7 @@ mod_openssl_close_notify(handler_ctx *hctx); static int connection_write_cq_ssl (connection *con, chunkqueue *cq, off_t max_bytes) { - handler_ctx *hctx = con->plugin_ctx[plugin_data_singleton->id]; + handler_ctx *hctx = con->request.plugin_ctx[plugin_data_singleton->id]; SSL *ssl = hctx->ssl; if (0 != hctx->close_notify) return mod_openssl_close_notify(hctx); @@ -1878,7 +1878,7 @@ connection_write_cq_ssl (connection *con, chunkqueue *cq, off_t max_bytes) static int connection_read_cq_ssl (connection *con, chunkqueue *cq, off_t max_bytes) { - handler_ctx *hctx = con->plugin_ctx[plugin_data_singleton->id]; + handler_ctx *hctx = con->request.plugin_ctx[plugin_data_singleton->id]; int len; char *mem = NULL; size_t mem_len = 0; @@ -2033,7 +2033,7 @@ CONNECTION_FUNC(mod_openssl_handle_con_accept) handler_ctx * const hctx = handler_ctx_init(); hctx->con = con; hctx->srv = con->srv; - con->plugin_ctx[p->id] = hctx; + con->request.plugin_ctx[p->id] = hctx; plugin_ssl_ctx * const s = p->ssl_ctxs + srv_sock->sidx; hctx->conf.ssl_pemfile_pkey = s->ssl_pemfile_pkey; @@ -2072,7 +2072,7 @@ mod_openssl_detach(handler_ctx *hctx) CONNECTION_FUNC(mod_openssl_handle_con_shut_wr) { plugin_data *p = p_d; - handler_ctx *hctx = con->plugin_ctx[p->id]; + handler_ctx *hctx = con->request.plugin_ctx[p->id]; if (NULL == hctx) return HANDLER_GO_ON; hctx->close_notify = -2; @@ -2198,10 +2198,10 @@ mod_openssl_close_notify(handler_ctx *hctx) CONNECTION_FUNC(mod_openssl_handle_con_close) { plugin_data *p = p_d; - handler_ctx *hctx = con->plugin_ctx[p->id]; + handler_ctx *hctx = con->request.plugin_ctx[p->id]; if (NULL != hctx) { handler_ctx_free(hctx); - con->plugin_ctx[p->id] = NULL; + con->request.plugin_ctx[p->id] = NULL; } return HANDLER_GO_ON; @@ -2343,7 +2343,7 @@ http_cgi_ssl_env (connection *con, handler_ctx *hctx) CONNECTION_FUNC(mod_openssl_handle_request_env) { plugin_data *p = p_d; - handler_ctx *hctx = con->plugin_ctx[p->id]; + handler_ctx *hctx = con->request.plugin_ctx[p->id]; if (NULL == hctx) return HANDLER_GO_ON; if (hctx->request_env_patched) return HANDLER_GO_ON; hctx->request_env_patched = 1; @@ -2367,7 +2367,7 @@ CONNECTION_FUNC(mod_openssl_handle_uri_raw) * is enabled with extforward.hap-PROXY = "enable", in which case the * reverse is true: mod_extforward must be loaded after mod_openssl */ plugin_data *p = p_d; - handler_ctx *hctx = con->plugin_ctx[p->id]; + handler_ctx *hctx = con->request.plugin_ctx[p->id]; if (NULL == hctx) return HANDLER_GO_ON; mod_openssl_patch_config(con, &hctx->conf); @@ -2382,7 +2382,7 @@ CONNECTION_FUNC(mod_openssl_handle_uri_raw) CONNECTION_FUNC(mod_openssl_handle_request_reset) { plugin_data *p = p_d; - handler_ctx *hctx = con->plugin_ctx[p->id]; + handler_ctx *hctx = con->request.plugin_ctx[p->id]; if (NULL == hctx) return HANDLER_GO_ON; hctx->request_env_patched = 0; diff --git a/src/mod_proxy.c b/src/mod_proxy.c index 0dc3c738..a6aa7f14 100644 --- a/src/mod_proxy.c +++ b/src/mod_proxy.c @@ -1031,7 +1031,7 @@ static handler_t mod_proxy_check_extension(connection *con, void *p_d) { if (HANDLER_GO_ON != rc) return rc; if (con->mode == p->id) { - handler_ctx *hctx = con->plugin_ctx[p->id]; + handler_ctx *hctx = con->request.plugin_ctx[p->id]; hctx->gw.create_env = proxy_create_env; hctx->gw.response = chunk_buffer_acquire(); hctx->gw.opts.backend = BACKEND_PROXY; diff --git a/src/mod_rewrite.c b/src/mod_rewrite.c index 27e55d91..0bf7c331 100644 --- a/src/mod_rewrite.c +++ b/src/mod_rewrite.c @@ -241,7 +241,7 @@ SETDEFAULTS_FUNC(mod_rewrite_set_defaults) { } URIHANDLER_FUNC(mod_rewrite_con_reset) { - con->plugin_ctx[((plugin_data *)p_d)->id] = NULL; + con->request.plugin_ctx[((plugin_data *)p_d)->id] = NULL; return HANDLER_GO_ON; } @@ -250,8 +250,8 @@ static handler_t process_rewrite_rules(connection *con, plugin_data *p, const pc pcre_keyvalue_ctx ctx; handler_t rc; - if (con->plugin_ctx[p->id]) { - uintptr_t * const hctx = (uintptr_t *)(con->plugin_ctx + p->id); + if (con->request.plugin_ctx[p->id]) { + uintptr_t * const hctx = (uintptr_t *)(con->request.plugin_ctx + p->id); if (((++*hctx) & 0x1FF) > 100) { if (0 != kvb->x0) { @@ -292,7 +292,7 @@ static handler_t process_rewrite_rules(connection *con, plugin_data *p, const pc rc = pcre_keyvalue_buffer_process(kvb, &ctx, con->request.target, tb); if (HANDLER_FINISHED == rc && !buffer_is_empty(tb) && tb->ptr[0] == '/') { buffer_copy_buffer(con->request.target, tb); - uintptr_t * const hctx = (uintptr_t *)(con->plugin_ctx + p->id); + uintptr_t * const hctx = (uintptr_t *)(con->request.plugin_ctx + p->id); *hctx |= REWRITE_STATE_REWRITTEN; /*(kvb->x1 is repeat_idx)*/ if (ctx.m < kvb->x1) *hctx |= REWRITE_STATE_FINISHED; diff --git a/src/mod_scgi.c b/src/mod_scgi.c index 39bf460b..5cdddba9 100644 --- a/src/mod_scgi.c +++ b/src/mod_scgi.c @@ -292,7 +292,7 @@ static handler_t scgi_check_extension(connection *con, void *p_d, int uri_path_h if (HANDLER_GO_ON != rc) return rc; if (con->mode == p->id) { - handler_ctx *hctx = con->plugin_ctx[p->id]; + handler_ctx *hctx = con->request.plugin_ctx[p->id]; hctx->opts.backend = BACKEND_SCGI; hctx->create_env = scgi_create_env; hctx->response = chunk_buffer_acquire(); diff --git a/src/mod_setenv.c b/src/mod_setenv.c index f08b3d87..1fddb06e 100644 --- a/src/mod_setenv.c +++ b/src/mod_setenv.c @@ -149,9 +149,9 @@ SETDEFAULTS_FUNC(mod_setenv_set_defaults) { URIHANDLER_FUNC(mod_setenv_uri_handler) { plugin_data *p = p_d; - handler_ctx *hctx = con->plugin_ctx[p->id]; + handler_ctx *hctx = con->request.plugin_ctx[p->id]; if (!hctx) - con->plugin_ctx[p->id] = hctx = handler_ctx_init(); + con->request.plugin_ctx[p->id] = hctx = handler_ctx_init(); else if (hctx->handled) return HANDLER_GO_ON; hctx->handled = 1; @@ -188,7 +188,7 @@ URIHANDLER_FUNC(mod_setenv_uri_handler) { CONNECTION_FUNC(mod_setenv_handle_request_env) { plugin_data *p = p_d; - handler_ctx *hctx = con->plugin_ctx[p->id]; + handler_ctx *hctx = con->request.plugin_ctx[p->id]; if (NULL == hctx) return HANDLER_GO_ON; if (hctx->handled > 1) return HANDLER_GO_ON; hctx->handled = 2; @@ -217,7 +217,7 @@ CONNECTION_FUNC(mod_setenv_handle_request_env) { CONNECTION_FUNC(mod_setenv_handle_response_start) { plugin_data *p = p_d; - handler_ctx *hctx = con->plugin_ctx[p->id]; + handler_ctx *hctx = con->request.plugin_ctx[p->id]; if (NULL == hctx) return HANDLER_GO_ON; const array * const aa = hctx->conf.response_header; @@ -249,7 +249,7 @@ CONNECTION_FUNC(mod_setenv_handle_response_start) { } CONNECTION_FUNC(mod_setenv_reset) { - void ** const hctx = con->plugin_ctx + ((plugin_data_base *)p_d)->id; + void ** const hctx = con->request.plugin_ctx+((plugin_data_base *)p_d)->id; if (*hctx) { handler_ctx_free(*hctx); *hctx = NULL; } return HANDLER_GO_ON; } diff --git a/src/mod_sockproxy.c b/src/mod_sockproxy.c index 949d1cd4..c54d1552 100644 --- a/src/mod_sockproxy.c +++ b/src/mod_sockproxy.c @@ -151,7 +151,7 @@ static handler_t mod_sockproxy_connection_accept(connection *con, void *p_d) { if (HANDLER_GO_ON != rc) return rc; if (con->mode == p->id) { - handler_ctx *hctx = con->plugin_ctx[p->id]; + handler_ctx *hctx = con->request.plugin_ctx[p->id]; hctx->opts.backend = BACKEND_PROXY; hctx->create_env = sockproxy_create_env_connect; hctx->response = chunk_buffer_acquire(); diff --git a/src/mod_ssi.c b/src/mod_ssi.c index ac1f29f9..2ccd2524 100644 --- a/src/mod_ssi.c +++ b/src/mod_ssi.c @@ -1254,7 +1254,7 @@ URIHANDLER_FUNC(mod_ssi_physical_path) { if (NULL == p->conf.ssi_extension) return HANDLER_GO_ON; if (array_match_value_suffix(p->conf.ssi_extension, con->physical.path)) { - con->plugin_ctx[p->id] = handler_ctx_init(p, con->conf.errh); + con->request.plugin_ctx[p->id] = handler_ctx_init(p, con->conf.errh); con->mode = p->id; } @@ -1263,7 +1263,7 @@ URIHANDLER_FUNC(mod_ssi_physical_path) { SUBREQUEST_FUNC(mod_ssi_handle_subrequest) { plugin_data *p = p_d; - handler_ctx *hctx = con->plugin_ctx[p->id]; + handler_ctx *hctx = con->request.plugin_ctx[p->id]; if (NULL == hctx) return HANDLER_GO_ON; if (con->mode != p->id) return HANDLER_GO_ON; /* not my job */ /* @@ -1285,10 +1285,10 @@ SUBREQUEST_FUNC(mod_ssi_handle_subrequest) { static handler_t mod_ssi_connection_reset(connection *con, void *p_d) { plugin_data *p = p_d; - handler_ctx *hctx = con->plugin_ctx[p->id]; + handler_ctx *hctx = con->request.plugin_ctx[p->id]; if (hctx) { handler_ctx_free(hctx); - con->plugin_ctx[p->id] = NULL; + con->request.plugin_ctx[p->id] = NULL; } return HANDLER_GO_ON; diff --git a/src/mod_vhostdb.c b/src/mod_vhostdb.c index 03912358..df6869cb 100644 --- a/src/mod_vhostdb.c +++ b/src/mod_vhostdb.c @@ -131,8 +131,8 @@ CONNECTION_FUNC(mod_vhostdb_handle_connection_close) { plugin_data *p = p_d; vhostdb_entry *ve; - if ((ve = con->plugin_ctx[p->id])) { - con->plugin_ctx[p->id] = NULL; + if ((ve = con->request.plugin_ctx[p->id])) { + con->request.plugin_ctx[p->id] = NULL; vhostdb_entry_free(ve); } @@ -169,7 +169,7 @@ CONNECTION_FUNC(mod_vhostdb_handle_docroot) { * of database responses (positive and negative) */ /* check if cached this connection */ - ve = con->plugin_ctx[p->id]; + ve = con->request.plugin_ctx[p->id]; if (ve && buffer_is_equal(ve->server_name, con->uri.authority)) { return mod_vhostdb_found(con, ve); /* HANDLER_GO_ON */ } @@ -202,7 +202,7 @@ CONNECTION_FUNC(mod_vhostdb_handle_docroot) { } /* cache the data */ - if (!ve) con->plugin_ctx[p->id] = ve = vhostdb_entry_init(); + if (!ve) con->request.plugin_ctx[p->id] = ve = vhostdb_entry_init(); buffer_copy_buffer(ve->server_name, con->uri.authority); buffer_copy_buffer(ve->document_root, b); diff --git a/src/mod_webdav.c b/src/mod_webdav.c index b92f2fb2..c2c4cc2a 100644 --- a/src/mod_webdav.c +++ b/src/mod_webdav.c @@ -5536,7 +5536,7 @@ mod_webdav_unlock (connection * const con, const plugin_config * const pconf) SUBREQUEST_FUNC(mod_webdav_subrequest_handler) { const plugin_config * const pconf = - (plugin_config *)con->plugin_ctx[((plugin_data *)p_d)->id]; + (plugin_config *)con->request.plugin_ctx[((plugin_data *)p_d)->id]; if (NULL == pconf) return HANDLER_GO_ON; /*(should not happen)*/ switch (con->request.http_method) { @@ -5641,17 +5641,17 @@ PHYSICALPATH_FUNC(mod_webdav_physical_handler) con->mode = ((plugin_data *)p_d)->id; con->conf.stream_request_body = 0; - con->plugin_ctx[((plugin_data *)p_d)->id] = &pconf; + con->request.plugin_ctx[((plugin_data *)p_d)->id] = &pconf; const handler_t rc = mod_webdav_subrequest_handler(con, p_d); /*p->handle_subrequest()*/ if (rc == HANDLER_FINISHED || rc == HANDLER_ERROR) - con->plugin_ctx[((plugin_data *)p_d)->id] = NULL; + con->request.plugin_ctx[((plugin_data *)p_d)->id] = NULL; else { /* e.g. HANDLER_WAIT_FOR_RD */ plugin_config * const save_pconf = (plugin_config *)malloc(sizeof(pconf)); force_assert(save_pconf); memcpy(save_pconf, &pconf, sizeof(pconf)); - con->plugin_ctx[((plugin_data *)p_d)->id] = save_pconf; + con->request.plugin_ctx[((plugin_data *)p_d)->id] = save_pconf; } return rc; } @@ -5659,7 +5659,8 @@ PHYSICALPATH_FUNC(mod_webdav_physical_handler) CONNECTION_FUNC(mod_webdav_handle_reset) { /* free plugin_config if allocated and saved to per-request storage */ - void ** const restrict dptr = &con->plugin_ctx[((plugin_data *)p_d)->id]; + void ** const restrict dptr = + &con->request.plugin_ctx[((plugin_data *)p_d)->id]; if (*dptr) { free(*dptr); *dptr = NULL; diff --git a/src/mod_wstunnel.c b/src/mod_wstunnel.c index 7064188a..b1ac1105 100644 --- a/src/mod_wstunnel.c +++ b/src/mod_wstunnel.c @@ -479,7 +479,7 @@ static void wstunnel_handler_ctx_free(void *gwhctx) { } static handler_t wstunnel_handler_setup (connection *con, plugin_data *p) { - handler_ctx *hctx = con->plugin_ctx[p->id]; + handler_ctx *hctx = con->request.plugin_ctx[p->id]; int hybivers; hctx->srv = con->srv; hctx->errh = con->conf.errh;/*(for mod_wstunnel-specific DEBUG_* macros)*/ @@ -595,7 +595,7 @@ TRIGGER_FUNC(mod_wstunnel_handle_trigger) { for (uint32_t i = 0; i < srv->conns.used; ++i) { connection *con = srv->conns.ptr[i]; - handler_ctx *hctx = con->plugin_ctx[p->id]; + handler_ctx *hctx = con->request.plugin_ctx[p->id]; if (NULL == hctx || con->mode != p->id) continue; diff --git a/src/request.h b/src/request.h index 82020e6a..76bc7cf5 100644 --- a/src/request.h +++ b/src/request.h @@ -86,6 +86,7 @@ struct request_st { http_method_t http_method; http_version_t http_version; + void **plugin_ctx; /* plugin connection specific config */ /* strings to the header */ buffer *http_host; /* not alloced */