GuidesFiltering I/O in Apache 2.0 Page 3

Filtering I/O in Apache 2.0 Page 3




The
first argument is a name for the filter. This
name is used throughout the
server to reference
that filter fuction. The second is the filter
function
we are registering. The final
argument is the type of filter. There are

currently two filter types, content and
connection. Content filters are any
filter
that modifies the data being sent. Connection
filters refer to filters
that dictate how the
data is sent over the network. For example, a
SSI filter
is a content filter while an SSL
filter is a connection filter.

Once the
filter has been registered, it must be added to
the current request’s
filter stack before it
will actually be called. This is done by
calling
ap_add_filter.

void
ap_add_filter(const char *name, void *ctx,
request_rec *r);

The first argument is
the name of the filter to add. This should be
the name
that was registered for the desired
filter. The second is a pointer to a
structure
that should be passed to the filter whenever it
is called. This
provides with a location to
store any data that they may need to save between

calls. The final argument is the request_rec
to pass to the filter when it is
called.

There are two more functions prototypes that must
be discussed. The first is
the prototype for
filters themselves.

apr_status_t
ap_filter_func(ap_filter_t *f, ap_bucket_brigade
*b);

The first argument is a pointer
to the current filter structure. This is where

the ctx passed to ap_add_filter is stored, as
well as a pointer to the next filter
on the
stack. The second is the current bucket brigade
to filter.

The second function is
ap_pass_brigade. This function passes bucket
brigades
from the current filter to the next
filter. The prototype is:

apr_status_t
ap_pass_brigade(ap_filter_t *filter,

ap_bucket_brigade
*bucket);

The first argument is a
pointer to the next filter to call, and the
second is the
bucket brigade to pass to that
filter.

That covers all of the basic
concepts for writing filters. In next month’s

article we will actually write a filter that can
be inserted into an Apache 2.0
server.

Latest Posts

Related Stories