httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Drew Bertola <d...@jupiterhosting.com>
Subject Re: help with filter example: null_filter...
Date Thu, 04 Jan 2007 06:12:35 GMT
Thanks Joachim and Nick.  I'm finally getting the idea.

Nick, it's not obvious where to find the files and tutorials on your
site.  I tried yesterday, but gave up after a couple minutes, choosing
instead to continue w/ some other work.  I looked again today and found
the buckets tutorial you suggested I read.  That really helped, so thanks.

I worked over the areas you both pointed out, and everything works fine
now - that is, it does absolutely nothing but shuffle buckets along. 
I've even got proper messages being returned.

Beyond this, I'll be adding some logging, per server config handling,
and file handling.  Not as detailed as your bucket tutorial, Nick, but a
bit broader.

Below is the corrected null_filter:

--
Drew



/*
 * 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_buckets.h"
#include "apr_pools.h"
#include "apr_file_io.h"
#include "util_filter.h"

module AP_MODULE_DECLARE_DATA null_filter_module;

static int null_filter(ap_filter_t *f, apr_bucket_brigade *bb)
{
  apr_bucket *e;
  apr_status_t rv;

  /*
   * 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) )
        {
          rv = ap_pass_brigade(f->next, bb);
          return rv;
        }
    }

  rv = ap_pass_brigade(f->next, bb);
 
  return rv;
}

static void register_hooks(apr_pool_t *p)
{
  ap_register_output_filter("NULL_FILTER",
                            null_filter,
                            NULL,
                            AP_FTYPE_CONTENT_SET);
}

module AP_MODULE_DECLARE_DATA null_filter_module =
  {
    STANDARD20_MODULE_STUFF,
    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                        */
  };


Mime
View raw message