You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by tr...@apache.org on 2002/08/02 01:26:43 UTC
cvs commit: httpd-2.0/modules/experimental mod_ext_filter.c
trawick 2002/08/01 16:26:43
Modified: . CHANGES
docs/manual/mod mod_ext_filter.html.en mod_ext_filter.xml
modules/experimental mod_ext_filter.c
Log:
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.
Revision Changes Path
1.877 +4 -0 httpd-2.0/CHANGES
Index: CHANGES
===================================================================
RCS file: /home/cvs/httpd-2.0/CHANGES,v
retrieving revision 1.876
retrieving revision 1.877
diff -u -r1.876 -r1.877
--- CHANGES 31 Jul 2002 12:44:54 -0000 1.876
+++ CHANGES 1 Aug 2002 23:26:43 -0000 1.877
@@ -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 <dp...@yahoo.com>]
1.6 +61 -0 httpd-2.0/docs/manual/mod/mod_ext_filter.html.en
Index: mod_ext_filter.html.en
===================================================================
RCS file: /home/cvs/httpd-2.0/docs/manual/mod/mod_ext_filter.html.en,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- mod_ext_filter.html.en 31 Jul 2002 20:50:23 -0000 1.5
+++ mod_ext_filter.html.en 1 Aug 2002 23:26:43 -0000 1.6
@@ -126,6 +126,46 @@
</code></td></tr></table></blockquote>
+<h3>Tracing another filter</h3>
+<blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
+<pre>
+ # 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>
+</pre>
+Here is the filter which traces the data:
+<pre>
+#!/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);
+</pre>
+</code></td></tr></table></blockquote>
+
+
<hr/><h2><a name="ExtFilterDefine">ExtFilterDefine</a> <a name="extfilterdefine">Directive</a></h2><table cellpadding="1" cellspacing="0" border="0" bgcolor="#cccccc"><tr><td><table bgcolor="#ffffff"><tr><td nowrap="nowrap"><strong>Description:
</strong></td><td/></tr><tr><td nowrap="nowrap"><a href="directive-dict.html#Syntax" class="help">Syntax:
</a></td><td>ExtFilterDefine <em>filtername</em> <em>parameters</em></td></tr><tr><td nowrap="nowrap"><a href="directive-dict.html#Context" class="help">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.</dd>
+
+ <dt>ftype=<em>filtertype</em></dt>
+
+ <dd>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.</dd>
+
+ <dt>disableenv=<em>env</em></dt>
+
+ <dd>This parameter specifies the name of an environment variable
+ which, if set, will disable the filter.</dd>
+
+ <dt>enableenv=<em>env</em></dt>
+
+ <dd>This parameter specifies the name of an environment variable
+ which must be set, or the filter will be disabled.</dd>
+
</dl>
<hr/><h2><a name="ExtFilterOptions">ExtFilterOptions</a> <a name="extfilteroptions">Directive</a></h2><table cellpadding="1" cellspacing="0" border="0" bgcolor="#cccccc"><tr><td><table bgcolor="#ffffff"><tr><td nowrap="nowrap"><strong>Description:
</strong></td><td/></tr><tr><td nowrap="nowrap"><a href="directive-dict.html#Syntax" class="help">Syntax:
1.5 +61 -0 httpd-2.0/docs/manual/mod/mod_ext_filter.xml
Index: mod_ext_filter.xml
===================================================================
RCS file: /home/cvs/httpd-2.0/docs/manual/mod/mod_ext_filter.xml,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- mod_ext_filter.xml 18 Jul 2002 12:25:24 -0000 1.4
+++ mod_ext_filter.xml 1 Aug 2002 23:26:43 -0000 1.5
@@ -132,6 +132,46 @@
</example>
</section>
+<section><title>Tracing another filter</title>
+<example>
+<pre>
+ # 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>
+</pre>
+Here is the filter which traces the data:
+<pre>
+#!/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);
+</pre>
+</example>
+</section>
+
</section> <!-- Examples -->
<directivesynopsis>
@@ -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.</dd>
+
+ <dt>ftype=<em>filtertype</em></dt>
+
+ <dd>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.</dd>
+
+ <dt>disableenv=<em>env</em></dt>
+
+ <dd>This parameter specifies the name of an environment variable
+ which, if set, will disable the filter.</dd>
+
+ <dt>enableenv=<em>env</em></dt>
+
+ <dd>This parameter specifies the name of an environment variable
+ which must be set, or the filter will be disabled.</dd>
+
</dl>
</usage>
</directivesynopsis>
1.36 +36 -1 httpd-2.0/modules/experimental/mod_ext_filter.c
Index: mod_ext_filter.c
===================================================================
RCS file: /home/cvs/httpd-2.0/modules/experimental/mod_ext_filter.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -r1.35 -r1.36
--- mod_ext_filter.c 18 Jul 2002 20:31:14 -0000 1.35
+++ mod_ext_filter.c 1 Aug 2002 23:26:43 -0000 1.36
@@ -84,7 +84,10 @@
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 @@
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 @@
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 @@
*/
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) {
@@ -549,6 +574,16 @@
ctx->noop = 1;
}
}
+ }
+ 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);