httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Drew Bertola <>
Subject help with filter example: null_filter...
Date Thu, 04 Jan 2007 00:08:51 GMT
Hey everyone,

I'm trying to create a demonstration filter that does nothing but pass
buckets to the next filter.  I'll extend this later to include reading
configuration data, and other standard tasks.

Right now, it's not working and I could use some expert help.  Since
this will be a demonstration filter, I'll gladly create a tutorial for
others to see.  Hopefully, we can document some best practices this way.

The problem right now looks like it doesn't finish.  Requesting a test
page that uses this filter never completes.

I've gotten this far by looking at examples, and discussing here some of
the problems I'm having with a real (usable) filter I'm writing.

Here's the code so far:
 * file: null_filter.c
 * description: a null output filter module for apache2.x that will pass
 * all data through to the next filter.  This will also be used to
 * test configuration handling and file handling.
#define DEBUG 1

#include "httpd.h"
#include "http_config.h"
#include "http_log.h"
#include "http_request.h"
#include "apr_general.h"
#include "apr_strings.h"
#include "apr_strmatch.h"
#include "apr_buckets.h"
#include "apr_pools.h"
#include "apr_file_io.h"
#include "util_filter.h"

module AP_MODULE_DECLARE_DATA null_filter_module;

typedef struct null_filter_context_t {
  apr_bucket_brigade *bb;
} null_filter_context;

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.
          APR_BRIGADE_INSERT_TAIL(ctx->bb, e);
          ap_pass_brigade(f->next, ctx->bb);
          return APR_SUCCESS;

      APR_BRIGADE_INSERT_TAIL(ctx->bb, e);

  ap_pass_brigade(f->next, ctx->bb);
  return APR_SUCCESS;

static void register_hooks(apr_pool_t *p)

module AP_MODULE_DECLARE_DATA null_filter_module =
    NULL,                    /* create per-directory config structure */
    NULL,                    /* merge per-directory config structures */
    NULL,                    /* create per-server config structure    */
    NULL,                    /* merge per-server config structures    */
    NULL,                    /* command apr_table_t                   */
    register_hooks           /* register hooks                        */



View raw message