You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Nathan Wiger <na...@wiger.org> on 2000/06/27 16:41:00 UTC

Apache::Config module

Hi all-

I've written a module that can parse the Apache httpd.conf config file
(and in fact any Apache-like config file). It will take a set of
directive like:

     ServerName         www.mydomain.com
     UseCanonicalName   Off
 
And parse it case-insensitively, returning a ref to a hash:

    my $ac = new Apache::Config;
    my $conf = $ac->readconf($configfile);
    print $conf->{servername};       # = "www.mydomain.com";
    print $conf->{usecanonicalname}; # = 0   (not undef so can test
                                     #        for defined() still)

I am also finishing up the ability to parse within contexts, such as
<Directory> and <Location>. I am still unsure of the interface, I have
two ideas:
 
    1. multi-level hash, i.e.
          $conf->{"directory /"}->{sethandler}
 
    2. individual functions, i.e.
          $conf->directory("/")->{sethandler}

If anyone has any input, I'm all ears. Right now I'm leaning towards the
second one, if I can get it working. The first one is really flexible
and easy, the problem is that it's difficult to search. The second one
helps with this issue, but the downside is that new functions have to be
added if new Apache contexts are defined. I'm trying to play some tricks
with the AutoLoader ala Shell to get new functions defined on the fly.
If anyone has good ideas for a better interface, I'd also like to hear
them.

In any case, I have several questions:
 
    1. Does a module like this exist anywhere?  I saw Doug's
       Apache::httpd_conf, but this only takes care of writing
       a very minimal config file. I looked thru all the
       Apache:: modules but didn't see one.
 
    2. Is the name Apache::Config a good name for this module?
       It seems like the obvious choice to me, and doesn't
       look like it's taken. I've also played around with
       Apache::ConfigFile and Apache::ReadConf, either of
       which I'm open to as well (or other suggestions?).

I'm aware of the Apache and Apache::Constants modules, which do provide
Apache API methods for getting to this data that work great for
mod_perl. My goal with this module was to make it general enough to be
used to parse any Apache-style config file. That way, if you wanted (a)
write a CGI script outside of mod_perl that used httpd.conf data, or (b)
wrote a custom (maybe non-web) app that used an Apache-like config file,
you could get at the data quickly. In this way it would be like
Apache::Session, where it can work either in a CGI or mod_perl context.
 
Thanks for your help and input.

-Nate

Re: Apache::Config module

Posted by Hasanuddin Tamir <ha...@trabas.com>.
>> No wonder Nathan Wiger on Jun 29 said that,

NW] > NW] In any case, I have several questions:
NW] > NW]
NW] > NW]     1. Does a module like this exist anywhere? 
NW] > 
NW] > You may want to take a look at AppConfig module. It does provide
NW] > generic capability to parse various kinds of config file. But I'll
NW] > be a happy user to have more spesific Apache related in this regard.
NW] 
NW] Yeah, I checked out AppConfig, and I actually emailed the author about
NW] modifying it a little so I could use it as a base class possibly for
NW] Apache::Config. Unfortunately, I haven't heard anything back yet.
NW] AppConfig would be a great base class, the only problem is that:
NW] 
NW] # it handles comments like this
NW] 
NW]      # but not like this
NW] 
NW] that's the only sticking point to not being able to extend AppConfig.
NW] Hopefully I'll hear something back from him. The fix is just the
NW] addition of a \s* to a regexp.

Yeah, at least the author could let the subclass to override
some aspects. The comment for example, smb.conf and php.ini
use `;' as well.

NW] > Apache::Config will be sufficient, IMHO, as later someone might
NW] > write another module, say Apache::Config::Deploy, that syncronize
NW] > the configuration of some httpds across some networks.
NW] 
NW] Not bad - I like the idea for an extension.
NW] 
NW] I'll keep plugging away on it then, hopefully the author of AppConfig
NW] will get back to me as that would help save some work, but regardless
NW] the parsing of the httpd.conf is not really that hard in and of itself.
NW] I'll use the name Apache::Config unless I hear otherwise.

So you may want to take a time to confirm the name to modules@perl.org.


NW] Thanks again to everyone who responded for their input!

Good luck with the project!


san
-- 
trabasLabs * hasant@trabas.com * http://www.trabas.com
Zero Point * hasant@zp.f2s.com * http://www.zp.f2s.com
------------------------------------------------------
Kesenian hanyalah dusta, dusta yang mengungkap kebenaran
   --Plato, kurang lebih



Re: Apache::Config module

Posted by Nathan Wiger <na...@wiger.org>.
> NW] In any case, I have several questions:
> NW]
> NW]     1. Does a module like this exist anywhere? 
> 
> You may want to take a look at AppConfig module. It does provide
> generic capability to parse various kinds of config file. But I'll
> be a happy user to have more spesific Apache related in this regard.

Yeah, I checked out AppConfig, and I actually emailed the author about
modifying it a little so I could use it as a base class possibly for
Apache::Config. Unfortunately, I haven't heard anything back yet.
AppConfig would be a great base class, the only problem is that:

# it handles comments like this

     # but not like this

that's the only sticking point to not being able to extend AppConfig.
Hopefully I'll hear something back from him. The fix is just the
addition of a \s* to a regexp.

> Apache::Config will be sufficient, IMHO, as later someone might
> write another module, say Apache::Config::Deploy, that syncronize
> the configuration of some httpds across some networks.

Not bad - I like the idea for an extension.

I'll keep plugging away on it then, hopefully the author of AppConfig
will get back to me as that would help save some work, but regardless
the parsing of the httpd.conf is not really that hard in and of itself.
I'll use the name Apache::Config unless I hear otherwise.

Thanks again to everyone who responded for their input!

-Nate

Re: Apache::Config module

Posted by Hasanuddin Tamir <ha...@trabas.com>.
>> No wonder Nathan Wiger on Jun 27 said that,

NW] Hi all-
NW] 
NW] I've written a module that can parse the Apache httpd.conf config file
NW] (and in fact any Apache-like config file). It will take a set of
NW] directive like:
NW] 
NW]      ServerName         www.mydomain.com
NW]      UseCanonicalName   Off
NW]  
NW] And parse it case-insensitively, returning a ref to a hash:
NW] 
NW]     my $ac = new Apache::Config;
NW]     my $conf = $ac->readconf($configfile);
NW]     print $conf->{servername};       # = "www.mydomain.com";
NW]     print $conf->{usecanonicalname}; # = 0   (not undef so can test
NW]                                      #        for defined() still)
NW] 
NW] I am also finishing up the ability to parse within contexts, such as
NW] <Directory> and <Location>. I am still unsure of the interface, I have
NW] two ideas:
NW]  
NW]     1. multi-level hash, i.e.
NW]           $conf->{"directory /"}->{sethandler}
NW]  
NW]     2. individual functions, i.e.
NW]           $conf->directory("/")->{sethandler}
NW] 
NW] If anyone has any input, I'm all ears. Right now I'm leaning towards the
NW] second one, if I can get it working. The first one is really flexible
NW] and easy, the problem is that it's difficult to search. The second one
NW] helps with this issue, but the downside is that new functions have to be
NW] added if new Apache contexts are defined. I'm trying to play some tricks
NW] with the AutoLoader ala Shell to get new functions defined on the fly.
NW] If anyone has good ideas for a better interface, I'd also like to hear
NW] them.
NW] 
NW] In any case, I have several questions:
NW]  
NW]     1. Does a module like this exist anywhere?  I saw Doug's
NW]        Apache::httpd_conf, but this only takes care of writing
NW]        a very minimal config file. I looked thru all the
NW]        Apache:: modules but didn't see one.

You may want to take a look at AppConfig module. It does provide
generic capability to parse various kinds of config file. But I'll
be a happy user to have more spesific Apache related in this regard.

NW]  
NW]     2. Is the name Apache::Config a good name for this module?
NW]        It seems like the obvious choice to me, and doesn't
NW]        look like it's taken. I've also played around with
NW]        Apache::ConfigFile and Apache::ReadConf, either of
NW]        which I'm open to as well (or other suggestions?).

Apache::Config will be sufficient, IMHO, as later someone might
write another module, say Apache::Config::Deploy, that syncronize
the configuration of some httpds across some networks.

[snip]


san
-- 
trabasLabs * hasant@trabas.com * http://www.trabas.com
Zero Point * hasant@zp.f2s.com * http://www.zp.f2s.com
------------------------------------------------------
....bahkan mahasiswa yang memperjuangkan reformasi
pun masih menempatkan wanita pada posisi inferior
   --Sudjiwo Tejo 14/12/1998
     tentang kiriman ayam betina kepada Jaksa Agung


Re: Apache::Config module

Posted by Doug MacEachern <do...@covalent.net>.
On Tue, 27 Jun 2000, Nathan Wiger wrote:

> Hi all-
> 
> I've written a module that can parse the Apache httpd.conf config file
> (and in fact any Apache-like config file). It will take a set of
> directive like:
> 
>      ServerName         www.mydomain.com
>      UseCanonicalName   Off
>  
> And parse it case-insensitively, returning a ref to a hash:
> 
>     my $ac = new Apache::Config;
>     my $conf = $ac->readconf($configfile);
>     print $conf->{servername};       # = "www.mydomain.com";
>     print $conf->{usecanonicalname}; # = 0   (not undef so can test
>                                      #        for defined() still)

it would be really cool if this module could support dumping of a parsed
config file into the same format that <Perl> sections understand.  and the
other way around, dumping a <Perl> section back into a .conf that Apache
can read without <Perl> sections.

> In any case, I have several questions:
>  
>     1. Does a module like this exist anywhere?  I saw Doug's
>        Apache::httpd_conf, but this only takes care of writing
>        a very minimal config file. I looked thru all the
>        Apache:: modules but didn't see one.

yeah, Apache::httpd_conf was something that was started and never
finished.  i think ken williams is working on something in this area, for
modules to write test config files.
  
>     2. Is the name Apache::Config a good name for this module?
>        It seems like the obvious choice to me, and doesn't
>        look like it's taken. I've also played around with
>        Apache::ConfigFile and Apache::ReadConf, either of
>        which I'm open to as well (or other suggestions?).

i'd go with Apache::ConfigFile.