On Wed, 03 Jan 2007 16:08:51 -0800
Drew Bertola <[EMAIL PROTECTED]> wrote:
> Hey everyone,
>
> I'm trying to create a demonstration filter that does nothing but pass
> buckets to the next filter.
Take a look at mod_diagnostics, which is a lot simpler than your code.
> typedef struct null_filter_context_t {
> apr_bucket_brigade *bb;
> } null_filter_context;
That's no part of a null filter. Neither is any use of f->ctx,
whose purpose is to save state.
> static int null_filter(ap_filter_t *f, apr_bucket_brigade *bb)
> {
> null_filter_context *ctx = f->ctx;
> apr_bucket *e;
>
> /*
> * if we don't have a context for this filter, let's create one and
> * create it's bucket brigade.
> */
> if ( ! ctx )
> {
> f->ctx = ctx = apr_pcalloc(f->r->pool, sizeof(*ctx));
> ctx->bb = apr_brigade_create(f->r->pool, f->c->bucket_alloc);
> }
>
> /*
> * let's loop through the buckets passed to us.
> */
> for( e = APR_BRIGADE_FIRST(bb);
> e != APR_BRIGADE_SENTINEL(bb);
> e = APR_BUCKET_NEXT(e) )
> {
> /*
> * if the bucket is an end of stream bucket or a flush bucket,
> * we can pass on what we have so far and be done with this
> brigade. */
> if ( APR_BUCKET_IS_EOS(e) || APR_BUCKET_IS_FLUSH(e) )
> {
> APR_BUCKET_REMOVE(e);
> APR_BRIGADE_INSERT_TAIL(ctx->bb, e);
> ap_pass_brigade(f->next, ctx->bb);
Oops, you just lost any errors coming down the chain.
> return APR_SUCCESS;
... and lied about it to the caller.
> }
>
> APR_BUCKET_REMOVE(e);
You just screwed up your APR_BUCKET_NEXT.
> APR_BRIGADE_INSERT_TAIL(ctx->bb, e);
... and pointed it at something different.
> }
>
> ap_pass_brigade(f->next, ctx->bb);
>
> return APR_SUCCESS;
... and killed off errors again.
I suggest you follow my .sig and read the tutorial on buckets&brigades.
--
Nick Kew
Application Development with Apache - the Apache Modules Book
http://www.apachetutor.org/