Hi,

I am facing problem about how to share context between input filter and
output filter which are registered through different hooks.

Here is description of the problem:
====================

static void
mod_realsecure_register_hooks (apr_pool_t * p)
{
ap_hook_child_init (realsecure_child_init, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_create_request(realsecure_hook_insertfilter , NULL, NULL,
APR_HOOK_MIDDLE);
ap_hook_insert_filter(realsecure_hook_insertoutputfilter , NULL, NULL,
APR_HOOK_MIDDLE);
};

static int realsecure_hook_insertfilter(request_rec *r)
{
   PamReqRspCtx *ctxPam1;
   ctxPam1 = (PamReqRspCtx *)apr_palloc(r->pool,sizeof(PamReqRspCtx));
   ap_add_input_filter("REALSECURE_READ_INPUT_1", (void *) ctxPam1, r,
r->connection);
   ap_add_output_filter("REALSECURE_READ_OUTPUT_1",(void *) ctxPam1, r,
r->connection);
   return OK;
}

static void realsecure_hook_insertoutputfilter(request_rec *r)
{
   PamReqRspCtx *ctxPam2;
   ctxPam2 = (PamReqRspCtx *)apr_palloc(r->pool,sizeof(PamReqRspCtx));
   ap_add_input_filter("REALSECURE_READ_INPUT_2", (void *) ctxPam2, r,
r->connection);
   ap_add_output_filter("REALSECURE_READ_OUTPUT_2",(void *) ctxPam2, r,
r->connection);
   return OK;
}

Now my problem is the context(ctxPam1) which I have created in
realsecure_hook_insertfilter(request_rec *r)  function and stored some data
how to access that context and data (ctxPam1) in
realsecure_hook_insertoutputfilter(request_rec *r) function


Please let me know about the solution.

-Ashish

On Tue, Dec 2, 2008 at 6:19 PM, Sorin Manolache <sor...@gmail.com> wrote:

> On Tue, Dec 2, 2008 at 10:58, Ashish Khare <ashis...@gmail.com> wrote:
> > Hi,
> >
> > I have tried with this option AP_FTYPE_PROTOCOL.
> > But my input filter is not called.
> > But when I change the type to AP_FTYPE_RESOURCE, my filter did get called
> > but no header.
> >
> > I have checked the Apache code where following modules filters are
> > registered with this option.
> >
> > ap_register_input_filter("HTTP_IN", ap_http_filter,NULL,
> AP_FTYPE_PROTOCOL);
> > ap_register_input_filter  (ssl_io_buffer, ssl_io_filter_buffer, NULL,
> > AP_FTYPE_PROTOCOL - 1);
> > ap_register_input_filter("NET_TIME", net_time_filter, NULL,
> > AP_FTYPE_PROTOCOL);
> >
> >
> > Please find my code snippet below to check if I am doing correct or not.
> > Let me know if I am doing correct or not.
>
> Hello,
>
> The apache2 call sequence is:
>
> ap_process_http_connection->ap_read_request->create_request callbacks
>
> ->ap_get_mime_headers_core
>
> ->ap_process_request->insert_filter callbacks
>
> As you see, ap_get_mime_headers_core is called before the
> insert_filter callbacks. Thus, the headers are consumed by
> ap_http_filter and they do not reach your filter.
>
> Instead of calling ap_add_input_filter_handle from a insert_filter
> callback, call it from a create_request callback. Thus, it will be
> called before ap_http_filter.
>
> I've attached the code.
>
> S
>
> >
> > code snippet
> > ============
> >
> > module AP_MODULE_DECLARE_DATA input_module = {
> >  STANDARD20_MODULE_STUFF,
> >  NULL,                         /* module initializer                  */
> >  NULL,                         /* create per-dir    config structures */
> >  NULL,                         /* merge  per-dir    config structures */
> >  NULL,                         /* create per-server config structures */
> >  my_table,            /* merge  per-server config structures */
> >  mod_my_register_hooks,
> > };
> >
> > static ap_filter_rec_t * globalInputFilter;
> >
> > static void
> > mod_my_register_hooks (apr_pool_t * p)
> > {
> >  ap_hook_child_init (my_child_init, NULL, NULL, APR_HOOK_MIDDLE);
> >  ap_hook_insert_filter(my_insertfilter , NULL, NULL, APR_HOOK_MIDDLE);
> >  globalInputFilter= ap_register_input_filter("MY_READ_INPUT",
> > my_input_filter ,NULL, AP_FTYPE_PROTOCOL );
> > };
> >
> > static void my_insertfilter (request_rec * r)
> > {
> >   ReqRspCtx *ctx;
> >   ctx = (ReqRspCtx *)apr_palloc(r->pool,sizeof(ReqRspCtx));
> >   ap_add_input_filter_handle ( globalInputFilter, (void *)ctx, r,
> > r->connection);
> > }
> >
> > static apr_status_t my_input_filter (ap_filter_t * f, apr_bucket_brigade
> *
> > bb,
> >                                     ap_input_mode_t mode,apr_read_type_e
> > block,
> >                                     apr_off_t readbytes)
> > {
> > //Function Body.
> > }
> >
> >
> >
> > Regards,
> > Ashish
> >
> >
> > On Tue, Dec 2, 2008 at 2:50 PM, Sorin Manolache <sor...@gmail.com>
> wrote:
> >
> >> On Tue, Dec 2, 2008 at 10:12, Ashish Khare <ashis...@gmail.com> wrote:
> >> > Hi Ryan,
> >> >
> >> > I need to access header in the input filter.
> >> >
> >> > I means all the unparsed data sent by the client in the request which
> >> > contains header information also.
> >> >
> >> > Please let me know how to do this.
> >> >
> >> > I have tried implementing the input filter but ap_get_brigade() call
> >> returns
> >> > empty brigade, which means it is returning only body and no headers.
> >> >
> >> > But i want to access header data.
> >> >
> >> > Please help me in this.
> >> >
> >>
> >> Make your filter of type AP_FTYPE_PROTOCOL.
> >>
> >> S
> >>
> >
>

Reply via email to