]> granicus.if.org Git - apache/commitdiff
Add the AddFilter directive. This directive takes a list of filter names
authorRyan Bloom <rbb@apache.org>
Wed, 13 Sep 2000 23:13:20 +0000 (23:13 +0000)
committerRyan Bloom <rbb@apache.org>
Wed, 13 Sep 2000 23:13:20 +0000 (23:13 +0000)
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
include/util_filter.h
modules/http/http_core.c
modules/http/http_protocol.c
server/util_filter.c

index 746f01ccc75ce1a10e4731b3c24bada50516fb97..73274f4e76147b7503a8c0af1317a25368896bb5 100644 (file)
@@ -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 */
index 2ce9eeac19dbb5238827b015358d723796a52ec9..d19e4eff2c211b15b353f373941da0958963a242 100644 (file)
@@ -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
index 55aa71805c46693cf37522e70ebdcdf403f5a05a..b533a80f98db9667863b9736af17f19db0adde02 100644 (file)
@@ -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)
index 4ce47e612066aab729be39a6105d717b0446084c..8589c82954a181a20b2040becd3abe6aa77c9053 100644 (file)
@@ -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) {
index 73aa7cfcf822e0696372ca46d9878f7ff7b1f330..64d8baff0ff6ed77e987835c7135555146522aa2 100644 (file)
@@ -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;