From: Jeff Trawick Date: Thu, 1 Aug 2002 23:26:43 +0000 (+0000) Subject: mod_ext_filter: Add the ability to enable or disable a filter via X-Git-Tag: 2.0.40~44 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=569ab1642f6cd1f04e7b1d2b55cf0a2b7bda58c4;p=apache mod_ext_filter: Add the ability to enable or disable a filter via an environment variable. Add the ability to register a filter of type other than AP_FTYPE_RESOURCE. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@96283 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index ffc740db47..b7bc318884 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,9 @@ Changes with Apache 2.0.40 + *) mod_ext_filter: Add the ability to enable or disable a filter via + an environment variable. Add the ability to register a filter of + type other than AP_FTYPE_RESOURCE. [Jeff Trawick] + *) Restore the ability to specify host names on Listen directives. PR 11030. [Jeff Trawick, David Shane Holden ] diff --git a/docs/manual/mod/mod_ext_filter.html.en b/docs/manual/mod/mod_ext_filter.html.en index 13841d687d..3a6320b95d 100644 --- a/docs/manual/mod/mod_ext_filter.html.en +++ b/docs/manual/mod/mod_ext_filter.html.en @@ -126,6 +126,46 @@ +

Tracing another filter

+
+
+  # Trace the data read and written by mod_deflate for a particuar
+  # client (IP 192.168.1.31) experiencing compression problems.
+  # This filter will trace what goes into mod_deflate.
+  ExtFilterDefine tracebefore cmd="/bin/tracefilter.pl /tmp/tracebefore" \
+    EnableEnv=trace_this_client
+  # This filter will trace what goes after mod_deflate.  Note that without
+  # the ftype parameter, the default filter type of AP_FTYPE_RESOURCE would
+  # cause the filter to be placed *before* mod_deflate in the filter 
+  # chain.  Giving it a numeric value slightly higher than 
+  # AP_FTYPE_CONTENT_SET will ensure that it is placed after mod_deflate.
+  ExtFilterDefine traceafter  cmd="/bin/tracefilter.pl /tmp/traceafter" \
+    EnableEnv=trace_this_client ftype=21
+
+  <Directory /usr/local/docs>
+    SetEnvIf Remote_Addr 192.168.1.31 trace_this_client
+    SetOutputFilter tracebefore;deflate;traceafter
+  </Directory>
+
+Here is the filter which traces the data: +
+#!/usr/local/bin/perl -w
+
+use strict;
+
+open(SAVE, ">$ARGV[0]") or die "can't open $ARGV[0]: $?";
+
+while (<STDIN>)
+{
+  print SAVE $_;
+  print $_;
+}
+
+close(SAVE);
+
+
+ +

ExtFilterDefine Directive

Description:
Syntax: ExtFilterDefine filtername parameters
Context: @@ -190,6 +230,27 @@ default, as most filters change the content length. In the event that the filter doesn't modify the length, this keyword should be specified. + +
ftype=filtertype
+ +
This parameter specifies the numeric value for filter type + that the filter should be registered as. The default value, + AP_FTYPE_RESOURCE, is sufficient in most cases. If the filter + needs to operate at a different point in the filter chain than + resource filters, then this parameter will be necessary. See + the AP_FTYPE_foo definitions in util_filter.h for appropriate + values.
+ +
disableenv=env
+ +
This parameter specifies the name of an environment variable + which, if set, will disable the filter.
+ +
enableenv=env
+ +
This parameter specifies the name of an environment variable + which must be set, or the filter will be disabled.
+

ExtFilterOptions Directive

Description:
Syntax: diff --git a/docs/manual/mod/mod_ext_filter.xml b/docs/manual/mod/mod_ext_filter.xml index de26a30319..970d84bb68 100644 --- a/docs/manual/mod/mod_ext_filter.xml +++ b/docs/manual/mod/mod_ext_filter.xml @@ -132,6 +132,46 @@ +
Tracing another filter + +
+  # Trace the data read and written by mod_deflate for a particuar
+  # client (IP 192.168.1.31) experiencing compression problems.
+  # This filter will trace what goes into mod_deflate.
+  ExtFilterDefine tracebefore cmd="/bin/tracefilter.pl /tmp/tracebefore" \
+    EnableEnv=trace_this_client
+  # This filter will trace what goes after mod_deflate.  Note that without
+  # the ftype parameter, the default filter type of AP_FTYPE_RESOURCE would
+  # cause the filter to be placed *before* mod_deflate in the filter 
+  # chain.  Giving it a numeric value slightly higher than 
+  # AP_FTYPE_CONTENT_SET will ensure that it is placed after mod_deflate.
+  ExtFilterDefine traceafter  cmd="/bin/tracefilter.pl /tmp/traceafter" \
+    EnableEnv=trace_this_client ftype=21
+
+  <Directory /usr/local/docs>
+    SetEnvIf Remote_Addr 192.168.1.31 trace_this_client
+    SetOutputFilter tracebefore;deflate;traceafter
+  </Directory>
+
+Here is the filter which traces the data: +
+#!/usr/local/bin/perl -w
+
+use strict;
+
+open(SAVE, ">$ARGV[0]") or die "can't open $ARGV[0]: $?";
+
+while (<STDIN>)
+{
+  print SAVE $_;
+  print $_;
+}
+
+close(SAVE);
+
+
+
+ @@ -198,6 +238,27 @@ default, as most filters change the content length. In the event that the filter doesn't modify the length, this keyword should be specified. + +
ftype=filtertype
+ +
This parameter specifies the numeric value for filter type + that the filter should be registered as. The default value, + AP_FTYPE_RESOURCE, is sufficient in most cases. If the filter + needs to operate at a different point in the filter chain than + resource filters, then this parameter will be necessary. See + the AP_FTYPE_foo definitions in util_filter.h for appropriate + values.
+ +
disableenv=env
+ +
This parameter specifies the name of an environment variable + which, if set, will disable the filter.
+ +
enableenv=env
+ +
This parameter specifies the name of an environment variable + which must be set, or the filter will be disabled.
+
diff --git a/modules/experimental/mod_ext_filter.c b/modules/experimental/mod_ext_filter.c index eafe3adb06..fb7bc5fb73 100644 --- a/modules/experimental/mod_ext_filter.c +++ b/modules/experimental/mod_ext_filter.c @@ -84,7 +84,10 @@ typedef struct ef_server_t { typedef struct ef_filter_t { const char *name; enum {INPUT_FILTER=1, OUTPUT_FILTER} mode; + ap_filter_type ftype; const char *command; + const char *enable_env; + const char *disable_env; int numArgs; char *args[30]; const char *intype; /* list of IMTs we process (well, just one for now) */ @@ -246,6 +249,7 @@ static const char *define_filter(cmd_parms *cmd, void *dummy, const char *args) filter = (ef_filter_t *)apr_pcalloc(conf->p, sizeof(ef_filter_t)); filter->name = name; filter->mode = OUTPUT_FILTER; + filter->ftype = AP_FTYPE_RESOURCE; apr_hash_set(conf->h, name, APR_HASH_KEY_STRING, filter); while (*args) { @@ -286,6 +290,27 @@ static const char *define_filter(cmd_parms *cmd, void *dummy, const char *args) continue; } + if (!strncasecmp(args, "ftype=", 6)) { + args += 6; + token = ap_getword_white(cmd->pool, &args); + filter->ftype = atoi(token); + continue; + } + + if (!strncasecmp(args, "enableenv=", 10)) { + args += 10; + token = ap_getword_white(cmd->pool, &args); + filter->enable_env = token; + continue; + } + + if (!strncasecmp(args, "disableenv=", 11)) { + args += 11; + token = ap_getword_white(cmd->pool, &args); + filter->disable_env = token; + continue; + } + if (!strncasecmp(args, "intype=", 7)) { args += 7; filter->intype = ap_getword_white(cmd->pool, &args); @@ -314,7 +339,7 @@ static const char *define_filter(cmd_parms *cmd, void *dummy, const char *args) */ if (filter->mode == OUTPUT_FILTER) { /* XXX need a way to ensure uniqueness among all filters */ - ap_register_output_filter(filter->name, ef_output_filter, NULL, AP_FTYPE_RESOURCE); + ap_register_output_filter(filter->name, ef_output_filter, NULL, filter->ftype); } #if 0 /* no input filters yet */ else if (filter->mode == INPUT_FILTER) { @@ -550,6 +575,16 @@ static apr_status_t init_filter_instance(ap_filter_t *f) } } } + if (ctx->filter->enable_env && + !apr_table_get(f->r->subprocess_env, ctx->filter->enable_env)) { + /* an environment variable that enables the filter isn't set; bail */ + ctx->noop = 1; + } + if (ctx->filter->disable_env && + apr_table_get(f->r->subprocess_env, ctx->filter->disable_env)) { + /* an environment variable that disables the filter is set; bail */ + ctx->noop = 1; + } if (!ctx->noop) { rv = init_ext_filter_process(f); if (rv != APR_SUCCESS) {