You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Bogdan Ribic <ri...@yahoo.com> on 2007/02/01 02:37:08 UTC
I need a working example of connection-level input filter
Hi all,
I'm having lots of fun with connection-level input filter. Idea is to modify headers before apache starts processing them. I adapted example from mod_case_filter_in and it all works until I try to use it with AP_FTYPE_CONNECTION. Specifically, this piece of code:
while (!APR_BRIGADE_EMPTY(ctx->bb)) {
apr_bucket * bkt_in = APR_BRIGADE_FIRST(ctx->bb);
will set bkt_in to NULL even though bucket is not empty, and it will only do so when filter is registered as AP_FTYPE_CONNECTION. If it is AP_FTYPE_RESOURCE it works as expected.
So, I guess I need a very simple example where it all works.
Whole filter function is adapted from example in case_filter, and looks like this:
apr_status_t input_filter(ap_filter_t *f, apr_bucket_brigade *bb_out,
ap_input_mode_t mode, apr_read_type_e block, apr_off_t nbytes)
{
int size;
const char * str;
apr_status_t rv;
hpfilter_ctx_t * ctx = NULL;
request_rec *r = f->r;
conn_rec *c = r->connection;
if (!(ctx = f->ctx == NULL)) {
f->ctx = ctx = apr_pcalloc(r->pool, sizeof *ctx);
ctx->bb = apr_brigade_create(r->pool, c->bucket_alloc);
}
if (APR_BRIGADE_EMPTY(ctx->bb)) {
rv = ap_get_brigade(f->next, ctx->bb, mode, block, nbytes);
if (mode == AP_MODE_EATCRLF || rv != APR_SUCCESS)
return rv;
}
while (!APR_BRIGADE_EMPTY(ctx->bb)) {
apr_bucket * bkt_in = APR_BRIGADE_FIRST(ctx->bb);
apr_bucket * bkt_out;
const char * data;
apr_size_t len;
char * buf;
int i;
if (APR_BUCKET_IS_EOS(bkt_in)) {
APR_BUCKET_REMOVE(bkt_in);
APR_BRIGADE_INSERT_TAIL(bb_out, bkt_in);
break;
}
rv = apr_bucket_read(bkt_in, &data, &len, block);
if (rv != APR_SUCCESS)
return rv;
buf = malloc(len);
for(i = 0; i < len; i++)
buf[i] = data[i];
bkt_out = apr_bucket_heap_create(buf, len, 0, c->bucket_alloc);
APR_BRIGADE_INSERT_TAIL(bb_out, bkt_out);
apr_bucket_delete(bkt_in);
}
return rv;
}
____________________________________________________________________________________
Sucker-punch spam with award-winning protection.
Try the free Yahoo! Mail Beta.
http://advision.webevents.yahoo.com/mailbeta/features_spam.html
Re: I need a working example of connection-level input filter
Posted by Nick Kew <ni...@webthing.com>.
On Wed, 31 Jan 2007 17:37:08 -0800 (PST)
Bogdan Ribic <ri...@yahoo.com> wrote:
> it with AP_FTYPE_CONNECTION. Specifically, this piece of code:
> [chop]
> request_rec *r = f->r;
You can't do that. There's no request_rec in a connection filter
(except by coincidence).
--
Nick Kew
Application Development with Apache - the Apache Modules Book
http://www.apachetutor.org/