You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Amlaan Kar <am...@gmail.com> on 2016/07/19 10:29:29 UTC

[users@httpd] Use an Apache handler after declining another

I have two handlers to be accessed. My motive is to use the second handler
if the first handler returns DECLINED.

I have tried various combinations of SetHandler, AddHandler and AddType but
none has worked as overriding takes place in all of these combinations.

Is there any method in Apache to use more than one handler without
overriding?

Re: [users@httpd] Use an Apache handler after declining another

Posted by Amlaan Kar <am...@gmail.com>.
What the example5-handler does is that it parses the url entered and if the
url does not satisfy the given conditions, displays a message. However, if
the conditions are satisfied by the url entered the example5-handler
returns DECLINED.

This is where the example1-handler is called and executed.

Besides, can I execute a php handler in place of example1-handler?

If I am confusing you, should I share the example5-handler code with you?

On Tue, Jul 19, 2016 at 7:54 PM, Yann Ylavic <yl...@gmail.com> wrote:

> On Tue, Jul 19, 2016 at 4:21 PM, Yann Ylavic <yl...@gmail.com> wrote:
> >
> > There are other ways to do this (by setting an environment variable
> > with for example SetEnvIf, and checking it in your handler), in any
> > case a DECLINing handler should not have to deal with r->handler
> > unless it knows which handler to force next.
>
> By the way, your module is possibly not a handler, why not use the
> fixup hook or similar?
>
> >
> > Regards,
> > Yann.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

Re: [users@httpd] Use an Apache handler after declining another

Posted by Yann Ylavic <yl...@gmail.com>.
On Tue, Jul 19, 2016 at 4:21 PM, Yann Ylavic <yl...@gmail.com> wrote:
>
> There are other ways to do this (by setting an environment variable
> with for example SetEnvIf, and checking it in your handler), in any
> case a DECLINing handler should not have to deal with r->handler
> unless it knows which handler to force next.

By the way, your module is possibly not a handler, why not use the
fixup hook or similar?

>
> Regards,
> Yann.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Use an Apache handler after declining another

Posted by Yann Ylavic <yl...@gmail.com>.
On Tue, Jul 19, 2016 at 2:42 PM, Amlaan Kar <am...@gmail.com> wrote:
> example1_handler is as given below:
> module AP_MODULE_DECLARE_DATA example1_module;
>
> static int example1_handler(request_rec *r)
> {
>     if (!r->handler || strcmp(r->handler, "example1-handler")) return
> (DECLINED);

So it does nothing unless "SetHandler example1-handler" above is effective.

>     ap_set_content_type(r, "text/html");
>     ap_rprintf(r, "Hello, world!");
>     return OK;
> }
[]
>
> Their configuration directives are as given below:
> <Location "/example1">
>     SetHandler example1-handler
> </Location>
>
> <Location "/products.php">
>     SetHandler example5-handler
> </Location>

If you request "/products.php", the handler is set to
"example5-handler", and example1_handler() DECLINEs.

I can't tell about your goal, but if it is to code the first example5
like module only, it probably shouldn't rely on a SetHandler to run
(i.e. the value of r->handler), such that other SetHandler(s)
needed/set by/for other modules could be preserved (not mangled for
the need of your module).

If for example the goal is to activate your module on some specific
locations, those locations could be configured by a directive specific
to your module, like:

  MyModuleEnable "/products.php"

(either a string prefix, repeated as many times as needed, a regexp, whatever).

There are other ways to do this (by setting an environment variable
with for example SetEnvIf, and checking it in your handler), in any
case a DECLINing handler should not have to deal with r->handler
unless it knows which handler to force next.

Regards,
Yann.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Use an Apache handler after declining another

Posted by Amlaan Kar <am...@gmail.com>.
example1_handler is as given below:
module AP_MODULE_DECLARE_DATA example1_module;

static int example1_handler(request_rec *r)
{
    if (!r->handler || strcmp(r->handler, "example1-handler")) return
(DECLINED);
    ap_set_content_type(r, "text/html");
    ap_rprintf(r, "Hello, world!");
    return OK;
}

static void register_hooks(apr_pool_t *pool)
{
    ap_hook_handler(example_handler, NULL, NULL, APR_HOOK_MIDDLE);
}

AP_DECLARE_MODULE(example1) =
{
    STANDARD20_MODULE_STUFF,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    register_hooks
};

Their configuration directives are as given below:
<Location "/example1">
    SetHandler example1-handler
</Location>

<Location "/products.php">
    SetHandler example5-handler
</Location>

On Tue, Jul 19, 2016 at 6:01 PM, Yann Ylavic <yl...@gmail.com> wrote:

> On Tue, Jul 19, 2016 at 2:15 PM, Amlaan Kar <am...@gmail.com> wrote:
> > static void register_hooks(apr_pool_t *pool)
> > {
> >     static const char *const succs[] = {"mod_example1.c", NULL };
> >     ap_hook_handler(example5_handler, NULL, succs, APR_HOOK_FIRST);
> > }
> > AP_DECLARE_MODULE(example5) =
> > {
> >     STANDARD20_MODULE_STUFF,
> >     NULL,
> >     NULL,
> >     NULL,
> >     NULL,
> >     NULL,
> >     register_hooks};
> >
> >
> > Sorry, I can't share the remaining code. I hope you can help me with
> this.
>
> OK, so example5_handler() runs and returns DECLINED, but
> example1_handler() does not run at all?
>
> How is example1_handler hooked, which handler is taking the request?
> Any special configuration in httpd.conf (*Handler) for these modules?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

Re: [users@httpd] Use an Apache handler after declining another

Posted by Yann Ylavic <yl...@gmail.com>.
On Tue, Jul 19, 2016 at 2:15 PM, Amlaan Kar <am...@gmail.com> wrote:
> static void register_hooks(apr_pool_t *pool)
> {
>     static const char *const succs[] = {"mod_example1.c", NULL };
>     ap_hook_handler(example5_handler, NULL, succs, APR_HOOK_FIRST);
> }
> AP_DECLARE_MODULE(example5) =
> {
>     STANDARD20_MODULE_STUFF,
>     NULL,
>     NULL,
>     NULL,
>     NULL,
>     NULL,
>     register_hooks};
>
>
> Sorry, I can't share the remaining code. I hope you can help me with this.

OK, so example5_handler() runs and returns DECLINED, but
example1_handler() does not run at all?

How is example1_handler hooked, which handler is taking the request?
Any special configuration in httpd.conf (*Handler) for these modules?

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Use an Apache handler after declining another

Posted by Amlaan Kar <am...@gmail.com>.
static void register_hooks(apr_pool_t *pool)
{
    static const char *const succs[] = {"mod_example1.c", NULL };
    ap_hook_handler(example5_handler, NULL, succs, APR_HOOK_FIRST);
}
AP_DECLARE_MODULE(example5) =
{
    STANDARD20_MODULE_STUFF,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    register_hooks};


Sorry, I can't share the remaining code. I hope you can help me with this.
Thank you in advance

On Tue, Jul 19, 2016 at 5:37 PM, Yann Ylavic <yl...@gmail.com> wrote:

> On Tue, Jul 19, 2016 at 1:58 PM, Amlaan Kar <am...@gmail.com> wrote:
> > Thank You for answering. The method described above is not working.
>
> Please describe not working..
> Your handler does not run before the one you specified as successor ?
>
> > Do I
> > have to make any changes before using the above given code?
> > PS: Both the handlers work properly individually
>
> Sorry for asking but, did you replace "mod_running_after.c" with the
> name of the module you want to run after yours?
> Which is this module, an httpd builtin one?
>
> Please show the code you are using.
>
> Regards,
> Yann.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

Re: [users@httpd] Use an Apache handler after declining another

Posted by Amlaan Kar <am...@gmail.com>.
The first handler runs properly. However, the successor does not run.

The module I am using has been written by me and is not a built-in one.

Is there any separate method for httpd built-in handlers?

On Tue, Jul 19, 2016 at 5:37 PM, Yann Ylavic <yl...@gmail.com> wrote:

> On Tue, Jul 19, 2016 at 1:58 PM, Amlaan Kar <am...@gmail.com> wrote:
> > Thank You for answering. The method described above is not working.
>
> Please describe not working..
> Your handler does not run before the one you specified as successor ?
>
> > Do I
> > have to make any changes before using the above given code?
> > PS: Both the handlers work properly individually
>
> Sorry for asking but, did you replace "mod_running_after.c" with the
> name of the module you want to run after yours?
> Which is this module, an httpd builtin one?
>
> Please show the code you are using.
>
> Regards,
> Yann.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

Re: [users@httpd] Use an Apache handler after declining another

Posted by Yann Ylavic <yl...@gmail.com>.
On Tue, Jul 19, 2016 at 1:58 PM, Amlaan Kar <am...@gmail.com> wrote:
> Thank You for answering. The method described above is not working.

Please describe not working..
Your handler does not run before the one you specified as successor ?

> Do I
> have to make any changes before using the above given code?
> PS: Both the handlers work properly individually

Sorry for asking but, did you replace "mod_running_after.c" with the
name of the module you want to run after yours?
Which is this module, an httpd builtin one?

Please show the code you are using.

Regards,
Yann.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Use an Apache handler after declining another

Posted by Amlaan Kar <am...@gmail.com>.
Thank You for answering. The method described above is not working. Do I
have to make any changes before using the above given code?
PS: Both the handlers work properly individually

On Tue, Jul 19, 2016 at 4:44 PM, Yann Ylavic <yl...@gmail.com> wrote:

> On Tue, Jul 19, 2016 at 12:29 PM, Amlaan Kar <am...@gmail.com> wrote:
> > I have two handlers to be accessed. My motive is to use the second
> handler
> > if the first handler returns DECLINED.
> >
> > I have tried various combinations of SetHandler, AddHandler and AddType
> but
> > none has worked as overriding takes place in all of these combinations.
> >
> > Is there any method in Apache to use more than one handler without
> > overriding?
>
> If the first handler (returning DECLINED) is yours, you can hook it by
> specifying its successor(s), e.g.:
>
> static void my_register_hooks(apr_pool_t *p)
> {
>     static const char * const succs[] = { "mod_running_after.c", NULL };
>
>     ...
>     ap_hook_handler(my_handler, NULL, succs, APR_HOOK_<WHATEVER>);
>     ...
> }
>
> This works for any hook, also by specifying predecessor(s) instead of
> the above NULL.
>
> Regards,
> Yann.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

Re: [users@httpd] Use an Apache handler after declining another

Posted by Yann Ylavic <yl...@gmail.com>.
On Tue, Jul 19, 2016 at 12:29 PM, Amlaan Kar <am...@gmail.com> wrote:
> I have two handlers to be accessed. My motive is to use the second handler
> if the first handler returns DECLINED.
>
> I have tried various combinations of SetHandler, AddHandler and AddType but
> none has worked as overriding takes place in all of these combinations.
>
> Is there any method in Apache to use more than one handler without
> overriding?

If the first handler (returning DECLINED) is yours, you can hook it by
specifying its successor(s), e.g.:

static void my_register_hooks(apr_pool_t *p)
{
    static const char * const succs[] = { "mod_running_after.c", NULL };

    ...
    ap_hook_handler(my_handler, NULL, succs, APR_HOOK_<WHATEVER>);
    ...
}

This works for any hook, also by specifying predecessor(s) instead of
the above NULL.

Regards,
Yann.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org