You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Fabian Fagerholm <fa...@paniq.net> on 2006/09/25 16:32:51 UTC

Hooking into arbitrary ap_hook_* functions

Hi!

I'm trying to port some Apache2 modules written in C to mod_perl, to
reduce the time and effort required to maintain them. The modules do
various small things, such as providing custom hooks for suExec and URL
translation. They hook extensively into Apache2 using ap_hook_*
functions.

The mod_perl 2.0 design document says:
        "Access to all hooks will be provided by mod_perl in both the
        traditional Perl*Handler configuration fashion and via dynamic
        registration methods (the ap_hook_* functions)."
        http://perl.apache.org/docs/2.0/user/design/design.html

However, I can't seem to find which ones are available as Perl*Handler
directives and how to access those that aren't.

Let's take a small example. I have C code that looks something like this
(trimmed down to show only what is needed here):

static void register_hooks(apr_pool_t * p)
{
    ap_hook_get_suexec_identity(my_suxec_id_doer, NULL, NULL,
                                APR_HOOK_FIRST + 1);
}

AP_DECLARE_DATA module my_nice_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 */
};

Obviously, get_suexec_id_doer is a function that returns a pointer to a
ap_unix_identity_t structure. How it works is irrelevant here.

The question is, how do I implement the above in mod_perl? More
generally, how do I implement an arbitrary ap_hook_* function in Perl
and register it with Apache2?

TIA,
-- 
Fabian Fagerholm <fa...@paniq.net>

Re: Hooking into arbitrary ap_hook_* functions

Posted by Srebrenko Sehic <ss...@gmail.com>.
On 9/25/06, Fabian Fagerholm <fa...@paniq.net> wrote:

> The question is, how do I implement the above in mod_perl? More
> generally, how do I implement an arbitrary ap_hook_* function in Perl
> and register it with Apache2?

AFAIK, I don't think you can, unless you hack the mod_perl sources. If
I remember correctly, the hook ordering is hardcoded for various
phases.

Re: Hooking into arbitrary ap_hook_* functions

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
Fabian Fagerholm wrote:
> By "this functionality", do you mean "implementing an arbitrary
> ap_hook_* function in mod_perl" or "implementing an
> ap_hook_get_suexec_identity function in mod_perl"? :)
The latter.


-- 
------------------------------------------------------------------------
Philip M. Gollucci (pgollucci@p6m7g8.com) 323.219.4708
Consultant / http://p6m7g8.net/Resume/resume.shtml
Senior Software Engineer - TicketMaster - http://ticketmaster.com
1024D/A79997FA F357 0FDD 2301 6296 690F  6A47 D55A 7172 A799 97F

When I call your name, Girl, it starts to flame
Burning in my heart, Tearing it all apart..
No matter how I try My love I cannot hide....

Re: Hooking into arbitrary ap_hook_* functions

Posted by Fabian Fagerholm <fa...@paniq.net>.
On Mon, 2006-09-25 at 22:09 -0700, Philip M. Gollucci wrote:
> I believe you want this file:
> xs/maps/apache2_functions.map
[...]
> see src/modules/perl/mod_perl.c:modperl_register_hooks()

Excellent, this helps understanding the mod_perl internals. Apparently
the hooks really are hardcoded, and I count around 20 implemented hook
functions and around 30 unimplemented hook functions in the map file.

> I don't think it would be terribly hard to add this functionality, but
> there might be some reason why we don't already do it ?????

By "this functionality", do you mean "implementing an arbitrary
ap_hook_* function in mod_perl" or "implementing an
ap_hook_get_suexec_identity function in mod_perl"? :)

Anyway, it looks like I can't implement all the functionality of the
modules in question in mod_perl right now. I'll probably look at
isolating the stuff that requires C into a few small modules and write
the rest in mod_perl.

Thanks for the pointers!

-- 
Fabian Fagerholm <fa...@paniq.net>

Re: Hooking into arbitrary ap_hook_* functions

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
Fabian Fagerholm wrote:
> However, I can't seem to find which ones are available as Perl*Handler
> directives and how to access those that aren't.
I believe you want this file:
xs/maps/apache2_functions.map


> static void register_hooks(apr_pool_t * p)
> {
>     ap_hook_get_suexec_identity(my_suxec_id_doer, NULL, NULL,
>                                 APR_HOOK_FIRST + 1);
> }

> 
> The question is, how do I implement the above in mod_perl? More
> generally, how do I implement an arbitrary ap_hook_* function in Perl
> and register it with Apache2?
Fabian is correct here,
see src/modules/perl/mod_perl.c:modperl_register_hooks()

I don't think it would be terribly hard to add this functionality, but there might be some reason why
we don't already do it ?????



-- 
------------------------------------------------------------------------
Philip M. Gollucci (pgollucci@p6m7g8.com) 323.219.4708
Consultant / http://p6m7g8.net/Resume/resume.shtml
Senior Software Engineer - TicketMaster - http://ticketmaster.com
1024D/A79997FA F357 0FDD 2301 6296 690F  6A47 D55A 7172 A799 97F

When I call your name, Girl, it starts to flame
Burning in my heart, Tearing it all apart..
No matter how I try My love I cannot hide....