Thread overview
Apache Module with D
Jan 26, 2007
Robert M. Münch
Jan 26, 2007
Pragma
Jan 27, 2007
Robert M. Münch
Jan 29, 2007
Pragma
January 26, 2007
Hi, has anyone here tried to write a simple Apache module using D?

I have found very few information about how to write Apache modules in C/C++. As I have to write one, I really would like to use D instead of C/C++.

Maybe it's a good showcase for D.

-- 
Robert M. Münch
Management & IT Freelancer
http://www.robertmuench.de
January 26, 2007
Robert M. Münch wrote:
> Hi, has anyone here tried to write a simple Apache module using D?
> 
> I have found very few information about how to write Apache modules in C/C++. As I have to write one, I really would like to use D instead of C/C++.
> 
> Maybe it's a good showcase for D.
> 
> --Robert M. Münch
> Management & IT Freelancer
> http://www.robertmuench.de

I tried a few years ago (using DMD 0.97 I think), and didn't get very far.  The major stumbling block was figuring out how to mimic Apache's endless use for macros in the C version of their dev kit.  It made for a *very* unfriendly porting effort as I had to manually unroll all those macros into D functions.

But I'm not at all saying that you're stuck with C - it's just that you won't be able to easily get away from it completely.  If I had to try this again, I'd definitely go with making a generic Apache module in C that is more easily used by D as a .lib.  That might also be a good place to handle the various memory management issues that come up when you mesh D's GC with a non-gc* managed environment.

That said, I know that there are a few decent tutorials out there to write Apache1 and Apache2 modules floating around out there for C.  Everything else I've ever read on the topic, came straight out of the source code comments, and a few posts scattered around on Usenet.

(* Apache does have memory pools that are kind of like a crude GC, and shouldn't be at all in the way of D.  Just be careful when passing memory back from the D side to C, such that it isn't freed/deleted outside of D.)

-- 
- EricAnderton at yahoo
January 27, 2007
On Fri, 26 Jan 2007 20:34:52 +0100, Pragma <ericanderton@yahoo.removeme.com> wrote:

> I tried a few years ago (using DMD 0.97 I think), and didn't get very far.  The major stumbling block was figuring out how to mimic Apache's endless use for macros in the C version of their dev kit.

Hi, yes that was my impression as well. I haven't seen code that uses macros in such an intense way. And, IMO this code is horrible...

> But I'm not at all saying that you're stuck with C - it's just that you won't be able to easily get away from it completely.  If I had to try this again, I'd definitely go with making a generic Apache module in C that is more easily used by D as a .lib.

What would such a generic module provide? Just hooks or some standard function implementations?

> That said, I know that there are a few decent tutorials out there to write Apache1 and Apache2 modules floating around out there for C.

Do you have any reference at hand? I just want to cross-check with what I have found.

> Everything else I've ever read on the topic, came straight out of the source code comments, and a few posts scattered around on Usenet.

Ok, I haven't checked Usenet yet.

Thanks for the feedback. Robert
January 29, 2007
Robert M. Münch wrote:
> On Fri, 26 Jan 2007 20:34:52 +0100, Pragma <ericanderton@yahoo.removeme.com> wrote:
> 
>> I tried a few years ago (using DMD 0.97 I think), and didn't get very far.  The major stumbling block was figuring out how to mimic Apache's endless use for macros in the C version of their dev kit.
> 
> Hi, yes that was my impression as well. I haven't seen code that uses macros in such an intense way. And, IMO this code is horrible...
> 
>> But I'm not at all saying that you're stuck with C - it's just that you won't be able to easily get away from it completely.  If I had to try this again, I'd definitely go with making a generic Apache module in C that is more easily used by D as a .lib.
> 
> What would such a generic module provide? Just hooks or some standard function implementations?

You got it.  Something that would map each kind of Apache callback function to something D can consume, should net you a bridge that you'll never have to modify once it's working.

> 
>> That said, I know that there are a few decent tutorials out there to write Apache1 and Apache2 modules floating around out there for C.
> 
> Do you have any reference at hand? I just want to cross-check with what I have found.

Well, all I did before was some very simple googling to dig these up:

http://httpd.apache.org/docs/2.0/developer/
http://threebit.net/tutorials/
http://www-128.ibm.com/developerworks/linux/library/l-apache/

another thing I did was google around for the source to some of the more simple modules like mod_rewrite.c and mod_cgi.c.  A longer shot, would be to drop any of the apache API calls into a code search engine (like google code search or koders) and manually scan the results for practical examples.

> 
>> Everything else I've ever read on the topic, came straight out of the source code comments, and a few posts scattered around on Usenet.
> 
> Ok, I haven't checked Usenet yet.

Try "apache module tutorial" on groups.google.com. ;)

> 
> Thanks for the feedback. Robert


-- 
- EricAnderton at yahoo