You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Torsten Foertsch <to...@gmx.net> on 2005/05/23 17:08:54 UTC

[MP2] Accessing custom config directives from an PostConfig handler

Hi,

I have created my own configuration directives with Apache2::Module::add. How 
can I access the values from an PostConfig handler?

I have got it working with the main server. But if my directives are inside a 
VirtualHost they are not accessible.

sub set_fn {
  my($I, $parms, $arg)=@_;
  local $_;

  Apache2::Module::get_config( __PACKAGE__, Apache2::ServerUtil->server )
      ->{"Directive"}=$arg;
}

sub postconfig {
  my($conf_pool, $log_pool, $temp_pool, $s) = @_;

  my $cfg=Apache2::Module::get_config( __PACKAGE__, 
                                       Apache2::ServerUtil->server );
  use Data::Dumper; warn "\npostconfig: ".Dumper( $cfg );

  return Apache2::Const::OK;
}

That works if "Directive" is placed outside a VirtualHost. Inside a 
VirtualHost the get_config in set_fn returns undef.

Torsten

Re: [MP2] Accessing custom config directives from an PostConfig handler

Posted by Stas Bekman <st...@stason.org>.
Torsten Foertsch wrote:
[...]
> I think a document explaining the fundamental Apache/mod_perl data structures 
> in terms of C _and_ mod_perl would be good. Then it can be linked from the 
> rest of the docs. BTW, is there somewhere a good Apache API documentation? 
> All my knowledge about it comes from looking at mod_perl, mod_dir, 
> mod_rewrite, mod_ssl, etc.

As you know such a doc patch would be very welcome, Torsten.


-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

Re: [MP2] Accessing custom config directives from an PostConfig handler

Posted by Torsten Foertsch <to...@gmx.net>.
On Monday 23 May 2005 19:54, Stas Bekman wrote:
> Geoffrey Young wrote:
> > Torsten Foertsch wrote:
> >>Hi,
> >>
> >>I have created my own configuration directives with Apache2::Module::add.
> >> How can I access the values from an PostConfig handler?
> >>
> >>I have got it working with the main server. But if my directives are
> >> inside a VirtualHost they are not accessible.
> >>
> >>
> >>Apache2::ServerUtil->server
> >
> > IIRC the issue is that in post-config you aren't actually attached to a
> > server, so you need to iterate the list of servers and find the one (by
> > name I guess) that you are intersted in.  IIRC there were some examples
> > in the archives of how to do this.  at the very least you can check out
> > mod_rewrite, which I belive does exactly that (in C though :)
>
> It's documented:
> http://perl.apache.org/docs/2.0/api/Apache2/ServerRec.html#C_next_
> http://perl.apache.org/docs/2.0/user/handlers/server.html#C_PerlOpenLogsHan
>dler_
>
> Torsten, if you think we could add a xref to this technique elsewhere that
> it'd make it easier to find it, please suggest. I agree that it's not easy
> to do now, unless you know things well.
>
> e.g. may be a xref from:
> http://perl.apache.org/docs/2.0/user/handlers/server.html#C_PerlPostConfigH
>andler_ to:
> http://perl.apache.org/docs/2.0/user/handlers/server.html#C_PerlOpenLogsHan
>dler_ will help? e.g.:
>
> If you want to traverse the configured virtual hosts, you can accomplish
> that using a simple loop (see PerlOpenLogsHandler for an example)


I already had had a loop

for( my $srv=Apache2::ServerUtil->server; $srv; $srv=$srv->next ) {...}

But in the same function I had a variable named $s that also was a server 
object. Now due to a simple spelling mistake inside the loop I had looked 5 
times at $s instead of $srv wondering why my configuration was undef all the 
time, ;-).

I think a document explaining the fundamental Apache/mod_perl data structures 
in terms of C _and_ mod_perl would be good. Then it can be linked from the 
rest of the docs. BTW, is there somewhere a good Apache API documentation? 
All my knowledge about it comes from looking at mod_perl, mod_dir, 
mod_rewrite, mod_ssl, etc.

Torsten

Re: [MP2] Accessing custom config directives from an PostConfig handler

Posted by Stas Bekman <st...@stason.org>.
Geoffrey Young wrote:
> 
> Torsten Foertsch wrote:
> 
>>Hi,
>>
>>I have created my own configuration directives with Apache2::Module::add. How 
>>can I access the values from an PostConfig handler?
>>
>>I have got it working with the main server. But if my directives are inside a 
>>VirtualHost they are not accessible.
> 
> 
>>Apache2::ServerUtil->server
> 
> 
> IIRC the issue is that in post-config you aren't actually attached to a
> server, so you need to iterate the list of servers and find the one (by name
> I guess) that you are intersted in.  IIRC there were some examples in the
> archives of how to do this.  at the very least you can check out
> mod_rewrite, which I belive does exactly that (in C though :)

It's documented:
http://perl.apache.org/docs/2.0/api/Apache2/ServerRec.html#C_next_
http://perl.apache.org/docs/2.0/user/handlers/server.html#C_PerlOpenLogsHandler_

Torsten, if you think we could add a xref to this technique elsewhere that 
it'd make it easier to find it, please suggest. I agree that it's not easy 
to do now, unless you know things well.

e.g. may be a xref from:
http://perl.apache.org/docs/2.0/user/handlers/server.html#C_PerlPostConfigHandler_
to:
http://perl.apache.org/docs/2.0/user/handlers/server.html#C_PerlOpenLogsHandler_
will help? e.g.:

If you want to traverse the configured virtual hosts, you can accomplish 
that using a simple loop (see PerlOpenLogsHandler for an example)


-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

Re: [MP2] Accessing custom config directives from an PostConfig handler

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Torsten Foertsch wrote:
> Hi,
> 
> I have created my own configuration directives with Apache2::Module::add. How 
> can I access the values from an PostConfig handler?
> 
> I have got it working with the main server. But if my directives are inside a 
> VirtualHost they are not accessible.

> Apache2::ServerUtil->server

IIRC the issue is that in post-config you aren't actually attached to a
server, so you need to iterate the list of servers and find the one (by name
I guess) that you are intersted in.  IIRC there were some examples in the
archives of how to do this.  at the very least you can check out
mod_rewrite, which I belive does exactly that (in C though :)

HTH

--Geoff