From 9c295f8e68c709bbe859e211397c7d22bbb2273e Mon Sep 17 00:00:00 2001 From: Ryan Bloom Date: Wed, 13 Sep 2000 23:13:20 +0000 Subject: [PATCH] Add the AddFilter directive. This directive takes a list of filter names that have been previously registered with the server. Currently the directive is only valid inside the config file, but once the Options directive is tweaked a bit, I would feel more comfortable exposing this directive to htaccess files. As a part of making adding this filter, I removed the ctx pointer from the ap_add_filter prototype. The problem is that the core is the thing that is actually inserting the filter into the filter stack, but the core doesn't know how to allocate memory for each filter. The solution is to have the filters themselves be responsible for allocating the ctx memory whenever it is required. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@86220 13f79535-47bb-0310-9956-ffa450edef68 --- include/http_core.h | 3 ++- include/util_filter.h | 5 ++--- modules/http/http_core.c | 32 +++++++++++++++++++++++++++++++- modules/http/http_protocol.c | 2 +- server/util_filter.c | 4 ++-- 5 files changed, 38 insertions(+), 8 deletions(-) diff --git a/include/http_core.h b/include/http_core.h index 746f01ccc7..73274f4e76 100644 --- a/include/http_core.h +++ b/include/http_core.h @@ -421,7 +421,8 @@ typedef struct { /* Where to find interpreter to run scripts */ interpreter_source_e script_interpreter_source; #endif - + + apr_array_header_t *filters; } core_dir_config; /* Per-server core configuration */ diff --git a/include/util_filter.h b/include/util_filter.h index 2ce9eeac19..d19e4eff2c 100644 --- a/include/util_filter.h +++ b/include/util_filter.h @@ -262,11 +262,10 @@ API_EXPORT(void) ap_register_filter(const char *name, * Add a filter to the current request. Filters are added in a FIFO manner. * The first filter added will be the first filter called. * @param name The name of the filter to add - * @param ctx Any filter specific data to associate with the filter * @param r The request to add this filter for. - * @deffunc void ap_add_filter(const char *name, void *ctx, request_rec *r) + * @deffunc void ap_add_filter(const char *name, request_rec *r) */ -API_EXPORT(void) ap_add_filter(const char *name, void *ctx, request_rec *r); +API_EXPORT(void) ap_add_filter(const char *name, request_rec *r); /* The next two filters are for abstraction purposes only. They could be * done away with, but that would require that we break modules if we ever diff --git a/modules/http/http_core.c b/modules/http/http_core.c index 55aa71805c..b533a80f98 100644 --- a/modules/http/http_core.c +++ b/modules/http/http_core.c @@ -186,6 +186,7 @@ static void *create_core_dir_config(apr_pool_t *a, char *dir) conf->add_default_charset = ADD_DEFAULT_CHARSET_UNSET; conf->add_default_charset_name = DEFAULT_ADD_DEFAULT_CHARSET_NAME; + conf->filters = apr_make_array(a, 40, sizeof(void *)); return (void *)conf; } @@ -325,6 +326,7 @@ static void *merge_core_dir_configs(apr_pool_t *a, void *basev, void *newv) conf->add_default_charset_name = new->add_default_charset_name; } } + conf->filters = apr_append_arrays(a, base->filters, new->filters); return (void*)conf; } @@ -1872,6 +1874,16 @@ static const char *set_server_alias(cmd_parms *cmd, void *dummy, return NULL; } +static const char *add_filter(cmd_parms *cmd, void *dummy, const char *arg) +{ + core_dir_config *conf = dummy; + char **newfilter; + + newfilter = (char **)apr_push_array(conf->filters); + *newfilter = apr_pstrdup(cmd->pool, arg); + return NULL; +} + static const char *add_module_command(cmd_parms *cmd, void *dummy, const char *arg) { @@ -2685,6 +2697,13 @@ AP_INIT_TAKE12("RLimitNPROC", set_limit_nproc, AP_INIT_TAKE12("RLimitNPROC", no_set_limit, NULL, OR_ALL, "soft/hard limits for max number of processes per uid"), #endif +/* XXX This should be allowable in .htaccess files, but currently it won't + * play well with the Options stuff. Until that is fixed, I would prefer + * to leave it just in the conf file. Other should feel free to disagree + * with me. Rbb. + */ +AP_INIT_ITERATE("AddFilter", add_filter, NULL, ACCESS_CONF, + "filters to be run"), { NULL } }; @@ -3111,7 +3130,18 @@ static unsigned short core_port(const request_rec *r) static void core_register_filter(request_rec *r) { - ap_add_filter("CORE", NULL, r); + int i; + core_dir_config *conf = (core_dir_config *) + ap_get_module_config(r->per_dir_config, + &core_module); + char **items = (char **)conf->filters->elts; + + for (i = 0; i < conf->filters->nelts; i++) { + char *foobar = items[i]; + ap_add_filter(foobar, r); + } + + ap_add_filter("CORE", r); } static void register_hooks(void) diff --git a/modules/http/http_protocol.c b/modules/http/http_protocol.c index 4ce47e6120..8589c82954 100644 --- a/modules/http/http_protocol.c +++ b/modules/http/http_protocol.c @@ -2064,7 +2064,7 @@ API_EXPORT(void) ap_send_http_header(request_rec *r) if (r->chunked) { apr_table_mergen(r->headers_out, "Transfer-Encoding", "chunked"); apr_table_unset(r->headers_out, "Content-Length"); - ap_add_filter("CHUNK", NULL, r); + ap_add_filter("CHUNK", r); } if (r->byterange > 1) { diff --git a/server/util_filter.c b/server/util_filter.c index 73aa7cfcf8..64d8baff0f 100644 --- a/server/util_filter.c +++ b/server/util_filter.c @@ -117,7 +117,7 @@ API_EXPORT(void) ap_register_filter(const char *name, apr_register_cleanup(FILTER_POOL, NULL, filter_cleanup, apr_null_cleanup); } -API_EXPORT(void) ap_add_filter(const char *name, void *ctx, request_rec *r) +API_EXPORT(void) ap_add_filter(const char *name, request_rec *r) { ap_filter_rec_t *frec = registered_filters; @@ -126,7 +126,7 @@ API_EXPORT(void) ap_add_filter(const char *name, void *ctx, request_rec *r) ap_filter_t *f = apr_pcalloc(r->pool, sizeof(*f)); f->filter_func = frec->filter_func; - f->ctx = ctx; + f->ctx = NULL; f->ftype = frec->ftype; f->r = r; -- 2.50.1