You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Ben Laurie <be...@algroup.co.uk> on 2001/01/01 18:21:56 UTC

Typesafe generic hooks - done!

Here we go. Rather than show the implementation, which is the usual
nasty mess of macros, I'll show you how its used. Here are two modules,
a hook exporter, and a hook importer. If the hook exporter is not
present, then the hook importer's hook is not called. If it is, then it
is. The hook importer's hook _is_ typesafe. And, err, that's it. So,
without further ado, here's mod_generic_hook_export.h:

AP_DECLARE_HOOK(int,generic_hook_test,(const char *))

and mod_generic_export.c:

#include "httpd.h"
#include "http_config.h"
#include "ap_generic_hook.h"
#include "mod_generic_hook_export.h"
#include "http_protocol.h"

AP_IMPLEMENT_GENERIC_HOOK_RUN_ALL(int,generic_hook_test,(const char
*szStr),
				  (szStr),OK,DECLINED)

static int ExportLogTransaction(request_rec *r)
    {
    return ap_run_generic_hook_test(r->the_request);
    }

static void ExportRegisterHooks(void)
    {
   
ap_hook_log_transaction(ExportLogTransaction,NULL,NULL,AP_HOOK_MIDDLE);
    }

module generic_hook_export_module =
    {
    STANDARD20_MODULE_STUFF,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    ExportRegisterHooks
    };

and finally, mod_generic_hook_import.c:

#include "httpd.h"
#include "http_config.h"
#include "ap_generic_hook.h"
#include "http_log.h"
#include "mod_generic_hook_export.h"

static int ImportGenericHookTestHook(const char *szStr)
    {
    ap_log_error(APLOG_MARK,APLOG_ERR,OK,NULL,"Generic hook test said:
%s",
		 szStr);

    return OK;
    }

static void ImportRegisterHooks(void)
    {
   
AP_HOOK_GENERIC(generic_hook_test,ImportGenericHookTestHook,NULL,NULL,
		    AP_HOOK_MIDDLE);
    }

module generic_hook_import_module=
    {
    STANDARD20_MODULE_STUFF,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    ImportRegisterHooks
    };

Tested. Works. Shall I commit it?

BTW, I was wondering if I should start an "examples" module directory,
instead of them living in "experimental" as they currently do.

Cheers,

Ben.

--
http://www.apache-ssl.org/ben.html

"There is no limit to what a man can do or how far he can go if he
doesn't mind who gets the credit." - Robert Woodruff

Re: Typesafe generic hooks - done!

Posted by Ben Laurie <be...@algroup.co.uk>.
Tony Finch wrote:
> 
> Ben Laurie <be...@algroup.co.uk> wrote:
> >
> >Well, we do have a style guide for this very reason. Which I'm happy to
> >follow, even though I do forget sometimes.
> 
> No, we have a whitespace style guide. The variable naming style is not
> documented because it was assumed that everyone would use the unixish
> style followed in most of the code.
> 
> >I object to names that don't give you any clue what the variable
> >holds, but the Apache code is rife with them.
> 
> Just because other people are crap doesn't mean you should be :-)

Quite.

Cheers,

Ben.

--
http://www.apache-ssl.org/ben.html

"There is no limit to what a man can do or how far he can go if he
doesn't mind who gets the credit." - Robert Woodruff

Re: Typesafe generic hooks - done!

Posted by Tony Finch <do...@dotat.at>.
Ben Laurie <be...@algroup.co.uk> wrote:
>
>Well, we do have a style guide for this very reason. Which I'm happy to
>follow, even though I do forget sometimes.

No, we have a whitespace style guide. The variable naming style is not
documented because it was assumed that everyone would use the unixish
style followed in most of the code.

>I object to names that don't give you any clue what the variable
>holds, but the Apache code is rife with them.

Just because other people are crap doesn't mean you should be :-)

Tony.
-- 
f.a.n.finch    fanf@covalent.net    dot@dotat.at
"Because all you of Earth are idiots!"

Re: Typesafe generic hooks - done!

Posted by Ben Laurie <be...@algroup.co.uk>.
Greg Stein wrote:
> 
> On Tue, Jan 02, 2001 at 11:11:38AM +0000, Ben Laurie wrote:
> > "Roy T. Fielding" wrote:
> > >
> > > Please use the Apache style, and lose the hungarian accent.
> >
> > OK, and why should I?
> 
> Because you're playing in the sandbox with other people. To play nice, your
> code should be similar. If it is too different, then it is much more
> difficult for us to jump in and help maintain/update/change the code.
> 
> I'm sure you're aware, but to be obvious: in a group dev effort, consistency
> of coding style is very important. The actual style is pretty moot, but the
> consistent application is necessary.

Well, we do have a style guide for this very reason. Which I'm happy to
follow, even though I do forget sometimes.

> So Roy is saying, "play nice". I agree.

I'm more than happy to play nice, but there is no discernable style to
internal variable names in Apache. I know that some people have some
weird religious objection to Hungarian, but I'm an atheist. I object to
names that don't give you any clue what the variable holds, but the
Apache code is rife with them.

I find it hard to believe that calling a variable "szStr" instead of
"str" is going to present a significant barrier to maintenance for
anyone!

Cheers,

Ben.

--
http://www.apache-ssl.org/ben.html

"There is no limit to what a man can do or how far he can go if he
doesn't mind who gets the credit." - Robert Woodruff

Re: Typesafe generic hooks - done!

Posted by Greg Stein <gs...@lyra.org>.
On Tue, Jan 02, 2001 at 11:11:38AM +0000, Ben Laurie wrote:
> "Roy T. Fielding" wrote:
> > 
> > Please use the Apache style, and lose the hungarian accent.
> 
> OK, and why should I?

Because you're playing in the sandbox with other people. To play nice, your
code should be similar. If it is too different, then it is much more
difficult for us to jump in and help maintain/update/change the code.

I'm sure you're aware, but to be obvious: in a group dev effort, consistency
of coding style is very important. The actual style is pretty moot, but the
consistent application is necessary.

So Roy is saying, "play nice". I agree.

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/

Re: Typesafe generic hooks - done!

Posted by Ben Laurie <be...@algroup.co.uk>.
"Roy T. Fielding" wrote:
> 
> Please use the Apache style, and lose the hungarian accent.

OK, and why should I?

> > Tested. Works. Shall I commit it?
> 
> *shrug* I have no idea what it does (and I've been reading this thread).
> A little code documentation would be helpful.

The code is documented - but you didn't see it. The example was pretty
self-explanatory if you know the existing hooking system.

What it does is provide type-safe hooks (i.e. just like ordinary hooks)
that can be hooked even if the exporter of the hook isn't linked in
(unlike ordinary hooks) - in which case the hooks simply aren't called.

> > BTW, I was wondering if I should start an "examples" module directory,
> > instead of them living in "experimental" as they currently do.
> 
> No.  I removed it because all of our code are examples (far better ones
> than what was found in that directory).  Anything that isn't expected
> to be inserted into a production server should be in experimental.

Whatever.

Cheers,

Ben.

--
http://www.apache-ssl.org/ben.html

"There is no limit to what a man can do or how far he can go if he
doesn't mind who gets the credit." - Robert Woodruff

Re: Typesafe generic hooks - done!

Posted by "Roy T. Fielding" <fi...@ebuilt.com>.
Please use the Apache style, and lose the hungarian accent.

> Tested. Works. Shall I commit it?

*shrug* I have no idea what it does (and I've been reading this thread).
A little code documentation would be helpful.

> BTW, I was wondering if I should start an "examples" module directory,
> instead of them living in "experimental" as they currently do.

No.  I removed it because all of our code are examples (far better ones
than what was found in that directory).  Anything that isn't expected
to be inserted into a production server should be in experimental.

....Roy

Re: Typesafe generic hooks - done!

Posted by Ben Laurie <be...@algroup.co.uk>.
rbb@covalent.net wrote:
> 
> > > >     STANDARD20_MODULE_STUFF,
> > > >     NULL,
> > > >     NULL,
> > > >     NULL,
> > > >     NULL,
> > > >     NULL,
> > > >     NULL,
> > > >     ExportRegisterHooks
> > > >     };
> > >
> > > I assume ExportRegisterHooks is really just register_hooks, named for
> > > clarity, correct?
> >
> > WTF? Its a pointer to a function that registers hooks. I can call it
> > what I want.
> 
> I know.  The problem was all the NULLs.  :-)  I counted, and I was 99.9%
> sure that this was the register hooks function, but I wanted to be 100%
> sure that you hadn't just added another function to the structure.  It was
> me not being clear on what was happening, and then having lingering doubt
> when I really understood it.

:-) I added nothing to the structures.

Cheers,

Ben.

--
http://www.apache-ssl.org/ben.html

"There is no limit to what a man can do or how far he can go if he
doesn't mind who gets the credit." - Robert Woodruff

Re: Typesafe generic hooks - done!

Posted by rb...@covalent.net.
> > >     STANDARD20_MODULE_STUFF,
> > >     NULL,
> > >     NULL,
> > >     NULL,
> > >     NULL,
> > >     NULL,
> > >     NULL,
> > >     ExportRegisterHooks
> > >     };
> > 
> > I assume ExportRegisterHooks is really just register_hooks, named for
> > clarity, correct?
> 
> WTF? Its a pointer to a function that registers hooks. I can call it
> what I want.

I know.  The problem was all the NULLs.  :-)  I counted, and I was 99.9%
sure that this was the register hooks function, but I wanted to be 100%
sure that you hadn't just added another function to the structure.  It was
me not being clear on what was happening, and then having lingering doubt
when I really understood it.

Ryan

_______________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------


Re: Typesafe generic hooks - done!

Posted by Ben Laurie <be...@algroup.co.uk>.
rbb@covalent.net wrote:
> 
> > Here we go. Rather than show the implementation, which is the usual
> > nasty mess of macros, I'll show you how its used. Here are two modules,
> > a hook exporter, and a hook importer. If the hook exporter is not
> > present, then the hook importer's hook is not called. If it is, then it
> > is. The hook importer's hook _is_ typesafe. And, err, that's it. So,
> > without further ado, here's mod_generic_hook_export.h:
> 
> This looks good, but I have one question.
> 
> > module generic_hook_export_module =
> >     {
> >     STANDARD20_MODULE_STUFF,
> >     NULL,
> >     NULL,
> >     NULL,
> >     NULL,
> >     NULL,
> >     NULL,
> >     ExportRegisterHooks
> >     };
> 
> I assume ExportRegisterHooks is really just register_hooks, named for
> clarity, correct?

WTF? Its a pointer to a function that registers hooks. I can call it
what I want.

> > Tested. Works. Shall I commit it?
> 
> If you can commit, go for it.  I can't currently ssh into apache.org.

I'll do it when I can, of course. :-)

>  If
> you don't mind, once you have committed this stuff, I would like to modify
> mod_cache to use it.  I want to do it to make sure I understand how this
> all works.  Once I'm done, I'm hoping you will make sure I get it
> right.  :-)

Sure!

> > BTW, I was wondering if I should start an "examples" module directory,
> > instead of them living in "experimental" as they currently do.
> 
> +1.

Cool. I'll do it.

Cheers,

Ben.

--
http://www.apache-ssl.org/ben.html

"There is no limit to what a man can do or how far he can go if he
doesn't mind who gets the credit." - Robert Woodruff

Re: Typesafe generic hooks - done!

Posted by rb...@covalent.net.
> Here we go. Rather than show the implementation, which is the usual
> nasty mess of macros, I'll show you how its used. Here are two modules,
> a hook exporter, and a hook importer. If the hook exporter is not
> present, then the hook importer's hook is not called. If it is, then it
> is. The hook importer's hook _is_ typesafe. And, err, that's it. So,
> without further ado, here's mod_generic_hook_export.h:

This looks good, but I have one question.

> module generic_hook_export_module =
>     {
>     STANDARD20_MODULE_STUFF,
>     NULL,
>     NULL,
>     NULL,
>     NULL,
>     NULL,
>     NULL,
>     ExportRegisterHooks
>     };

I assume ExportRegisterHooks is really just register_hooks, named for
clarity, correct?

> Tested. Works. Shall I commit it?

If you can commit, go for it.  I can't currently ssh into apache.org.  If
you don't mind, once you have committed this stuff, I would like to modify
mod_cache to use it.  I want to do it to make sure I understand how this
all works.  Once I'm done, I'm hoping you will make sure I get it
right.  :-)

> BTW, I was wondering if I should start an "examples" module directory,
> instead of them living in "experimental" as they currently do.

+1.

Ryan

_______________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------