Re: Apache 2.2 Output Filter simple C example

2007-08-08 Thread Amlan Samuil Warman

/*

TODO:

- to compile:
apxs -c mod_myoutfilter.c

- copy mod_myoutfilter.so to $APACHE_HOME/modules


- httpd.conf implementation:

LoadModule myoutfilter_module modules/mod_myoutfilter.so
Location /myfile.html
SetOutputFilter myoutfilter
/Location


myfile.html:

bthis is content/b


after filtered:

XMP%START%

%DATA%
bthis is content/b
%/DATA%

%/END%/XMP



*/

#include httpd.h
#include http_config.h
#include apr_buckets.h
#include util_filter.h
#include apr_strings.h


//---
static const char module_name[] = myoutfilter;
module AP_MODULE_DECLARE_DATA myoutfilter_module;

//---
void write_brigade(apr_bucket_brigade *bb_out,request_rec *r,char *data){
APR_BRIGADE_INSERT_TAIL(
 bb_out,
 apr_bucket_pool_create(
  data,
  strlen(data),
  r-pool,
  r-connection-bucket_alloc
 )
);
}


//---
static apr_status_t out_filter(ap_filter_t *f,apr_bucket_brigade *bb_in){
apr_bucket *bucket_in;
apr_bucket_brigade *bb_out;

request_rec *r = f-r;
conn_rec *c = r-connection;
 apr_pool_t *p = r-pool;

const char *data_in;
apr_size_t len_in;


int decision = 0;


//--- example if we just do nothing
//--- do something to set 'decision' to true(1) or false(0)
if(decision){
 ap_remove_output_filter(f);
 return ap_pass_brigade(f-next, bb_in);
}

  bb_out = apr_brigade_create(p, c-bucket_alloc);


//--- maybe we want write HTML header
write_brigade(bb_out,r,XMP);
write_brigade(bb_out,r,%START%\n\n);


while(!APR_BRIGADE_EMPTY(bb_in)){

 bucket_in = APR_BRIGADE_FIRST(bb_in);

 //--- if FLUSH requested ? I don't really know when, just follow other 
sample.

 //--- maybe you need it.
 /* --
 if (APR_BUCKET_IS_FLUSH(bucket_in)){
  APR_BRIGADE_INSERT_TAIL(bb_out, 
apr_bucket_flush_create(c-bucket_alloc));

  if (ap_pass_brigade(f-next, bb_out) != APR_SUCCESS){return APR_SUCCESS;}
 bb_out = apr_brigade_create(p, c-bucket_alloc);
  continue;
 }
 -- */


 if (APR_BUCKET_IS_EOS(bucket_in)){
  //--- do we want do something when we know there is no data anymore ?
break;
 }

 // fetch the data
 apr_bucket_read(bucket_in, data_in, len_in, APR_BLOCK_READ);

  //--- do something with data_in

  write_brigade(bb_out,r,%DATA%\n);
  write_brigade(bb_out,r,apr_pstrdup(p,data_in));
  write_brigade(bb_out,r,\n%/DATA%\n );

 //--- end fetch
 apr_bucket_delete(bucket_in);
}

  //-- we don't need bb_in anymore
  apr_brigade_destroy(bb_in);


//--- maybe we want write HTML footer
write_brigade(bb_out,r,\n%/END%);
write_brigade(bb_out,r,/XMP);


//--- send EOS to bb_out to finish inserting data to bb_out
APR_BRIGADE_INSERT_TAIL(bb_out,apr_bucket_eos_create(c-bucket_alloc));


//--- pass bb_out to next filter
ap_remove_output_filter(f);
return ap_pass_brigade(f-next, bb_out);
}

//---
static void register_hooks(apr_pool_t *p){
   ap_register_output_filter(module_name, out_filter, NULL,
 AP_FTYPE_CONTENT_SET);
}

//---
module AP_MODULE_DECLARE_DATA myoutfilter_module = {
   STANDARD20_MODULE_STUFF,
   NULL, /* dir config creater */
   NULL, /* dir merger --- default is to override 
*/

   NULL, /* server config */
   NULL, /* merge server config */
   NULL, /* command table */
   register_hooks/* register hooks */
};



//--

note:
hope you understand this code
hope this code work for you

sorry for my bad english

asw,
Indonesia

- Original Message - 
From: Zvi Kave [EMAIL PROTECTED]

To: modules-dev@httpd.apache.org
Sent: Wednesday, August 08, 2007 08:58
Subject: Apache 2.2 Output Filter simple C example


Dear friends,

I need an simple apache 2.2 example in C that let's me check the output
characters to manipulate them.
Please help,

Zvi 


Re: Apache 2.2 Output Filter simple C example

2007-08-08 Thread Mads Toftum
On Wed, Aug 08, 2007 at 04:58:33PM +0300, Zvi Kave wrote:
 Dear friends,
 
 I need an simple apache 2.2 example in C that let's me check the output 
 characters to manipulate them.
 Please help,
 
There's plenty of examples in the httpd code - one example would be:
http://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x/modules/experimental/mod_case_filter.c

vh

Mads Toftum
-- 
http://soulfood.dk


Re: Apache 2.2 Output Filter simple C example

2007-08-08 Thread Joe Lewis
Zvi Kave wrote:
 Dear friends,

 I need an simple apache 2.2 example in C that let's me check the output 
 characters to manipulate them.
 Please help,

 Zvi
   
Just for kicks and giggles, I went out and put ryan bloom apache output
filter into google to see if his 2.0 example still exist.  The 4th hit
was called Articles (by Author), and that contained a link to an
article that he wrote specifically about building an output filter. 
That is the starting point that I used.  Try that one!

Joe
-- 
Joseph Lewis http://sharktooth.org/
Divide the fire, and you will sooner put it out. - Publius Syrus


Re: Apache 2.2 Output Filter simple C example

2007-08-08 Thread Arturo 'Buanzo' Busleiman
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512

Joe Lewis wrote:
 Just for kicks and giggles, I went out and put ryan bloom apache output

Talking about Ryan, where is he?

- --
Arturo Buanzo Busleiman - Consultor Independiente en Seguridad Informatica
SHOW DE FUTURABANDA - Sabado 18 de Agosto 2007 (Speed King, Capital Federal)
Entradas anticipadas a traves de www.futurabanda.com.ar - Punk Rock Melodico


-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGuc7oAlpOsGhXcE0RCtv6AJ4mZ8vG6vwpZyPfr7cbDr7B6EH6UQCfdCWV
95rzwweQTBNBiSY7HWgFCBk=
=wbwi
-END PGP SIGNATURE-


Re: Apache 2.2 Output Filter simple C example

2007-08-08 Thread Joe Lewis
Arturo 'Buanzo' Busleiman wrote:
 Joe Lewis wrote:
  Just for kicks and giggles, I went out and put ryan bloom apache output

 Talking about Ryan, where is he?

Rather inactive when it comes to the ASF.

http://rkbloom.net/

:)

Joe
-- 
Joseph Lewis http://sharktooth.org/
Divide the fire, and you will sooner put it out. - Publius Syrus



Re: Apache 2.2 Output Filter simple C example

2007-08-08 Thread Arturo 'Buanzo' Busleiman
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512

Joe Lewis wrote:
 Rather inactive when it comes to the ASF.

Ouch :)

- --
Arturo Buanzo Busleiman - Consultor Independiente en Seguridad Informatica
SHOW DE FUTURABANDA - Sabado 18 de Agosto 2007 (Speed King, Capital Federal)
Entradas anticipadas a traves de www.futurabanda.com.ar - Punk Rock Melodico


-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGudK6AlpOsGhXcE0RCtN7AJ9++m3MQE0IXrn0x2Vv/a0jjpSAXgCfVvTi
R7NW9XcsU8nILJd3Z1nGMto=
=RIve
-END PGP SIGNATURE-


Re: Apache 2.2 Output Filter simple C example

2007-08-08 Thread Joe Lewis
Arturo 'Buanzo' Busleiman wrote:
 Joe Lewis wrote:
  Rather inactive when it comes to the ASF.

 Ouch :)

Well, he's got family to worry about now.  Yes, it's a blow to the ASF,
but what he does contribute more than makes up for it.

Joe
-- 
Joseph Lewis http://sharktooth.org/
Divide the fire, and you will sooner put it out. - Publius Syrus