You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Erik Norgaard <no...@locolomo.org> on 2006/09/28 22:38:55 UTC
Reading custom configuration parameters
Hi:
I have successfully created a module that declares some configuration
parameters which should be available to the handler: dbDriver, dbHost,
dbName, dbUser and dbPassword. Or so I think, I followed this guide:
http://perl.apache.org/docs/2.0/user/config/custom.html
But there is one thing I don't get:
What is the scope of these variables? They are declared for a virtual
host, but can I make sure that they will not be accessible for other
virtual hosts?
The handler is also defined for the individual virtual host, but what if
I have multiple virtual hosts each with the same handler defined?
Thanks, Erik
--
Ph: +34.666334818 web: http://www.locolomo.org
X.509 Certificate: http://www.locolomo.org/crt/8D03551FFCE04F0C.crt
Key ID: 69:79:B8:2C:E3:8F:E7:BE:5D:C3:C3:B1:74:62:B8:3F:9F:1F:69:B9
Re: Reading custom configuration parameters
Posted by Fred Moyer <fr...@redhotpenguin.com>.
Erik Norgaard wrote:
> Erik Norgaard wrote:
>
>> I have successfully created a module that declares some configuration
>> parameters which should be available to the handler: dbDriver, dbHost,
>> dbName, dbUser and dbPassword. Or so I think, I followed this guide:
>>
>> http://perl.apache.org/docs/2.0/user/config/custom.html
>
> Something is wrong, I can't read the variables, or they are undefined.
> What am I missing?
> my $r = shift;
> my $conf = Apache2::Module::get_config('XCMS::Config', $r->server);
my $conf = Apache2::Module::get_config('XCMS::Config',$r->server,
$r->per_dir_config);
^^^^^^^
Should do the trick. That detail is subtle and has gotten me also in
the past. I put a quick test together using Geoff's bug reporting
skeleton [1] and a few tweaks based on your examples. Let me know if it
doesn't work and I'll send you the tarball.
[1]
http://perl.apache.org/~geoff/bug-reporting-skeleton-apache.tar.gz
Re: Reading custom configuration parameters
Posted by Erik Norgaard <no...@locolomo.org>.
Erik Norgaard wrote:
> I have successfully created a module that declares some configuration
> parameters which should be available to the handler: dbDriver, dbHost,
> dbName, dbUser and dbPassword. Or so I think, I followed this guide:
>
> http://perl.apache.org/docs/2.0/user/config/custom.html
Something is wrong, I can't read the variables, or they are undefined.
What am I missing?
I have in the handler-module declared variables $dbDriver, $dbHost etc.
and use this method to set them:
use Apache2::Module;
my $dbDriver;
my $dbHost;
sub handler { # basicly this:
my $r = shift;
config($r);
print $dbHost;
}
sub config {
my $r = shift;
my $conf = Apache2::Module::get_config('XCMS::Config', $r->server);
$dbDriver = $conf->{'XCMSdbDriver'};
$dbHost = $conf->{'XCMSdbHost'};
}
The config($r) is called from the handler, and for testing I just print
the value of the $dbHost.
And this is in XCMS::Config:
use Apache2::CmdParms;
use Apache2::Module;
use Apache2::Directive;
my @directives = (
{ name => 'XCMSdbDriver', args_how => "Apache2::Const::RAW_ARGS" },
{ name => 'XCMSdbHost', args_how => "Apache2::Const::RAW_ARGS" },
);
Apache2::Module::add(__PACKAGE__, \@directives);
...
sub XCMSdbHost {
my ($self, $parms, $val) = @_;
$self->{'XCMSdbHost'} = $val;
};
And this in the configuration of the virtual host
PerlLoadModule XCMS::Config
XCMSdbDriver Pg
XCMSdbHost localhost
But the variable remain undefined...
Thanks, Erik
--
Ph: +34.666334818 web: http://www.locolomo.org
X.509 Certificate: http://www.locolomo.org/crt/8D03551FFCE04F0C.crt
Key ID: 69:79:B8:2C:E3:8F:E7:BE:5D:C3:C3:B1:74:62:B8:3F:9F:1F:69:B9
Re: Reading custom configuration parameters
Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
Erik Norgaard wrote:
> Philip M. Gollucci wrote:
>> Erik Norgaard wrote:
>>> Hi:
>>>
>>> I have successfully created a module that declares some configuration
>>> parameters which should be available to the handler: dbDriver,
>>> dbHost, dbName, dbUser and dbPassword. Or so I think, I followed this
>>> guide:
>>>
>>> http://perl.apache.org/docs/2.0/user/config/custom.html
>> This section of it doesn't answer that for you ?
>> http://perl.apache.org/docs/2.0/user/config/custom.html#toc_Directive_Callback_Subroutine
>>
>>
>> The simple answer is try it :)
>
> The yet simpler ? :) Well, what confuses me is the merging example in
> the end of the text. Anyway, the text you refer to tells how I can get
> global/serverwide parameters, but I don't see any mention of whether or
> not parameters defined for a different virtual host is possible. I
> prefer not for security.
I believe you can get to anything:
If a request is made to a resource inside a virtual host, $srv_cfg will contain the object of the virtual host's server.
my $srv_cfg = Apache2::Module::get_config('MyApache2::MyParameters', $s);
To reach the main server's configuration object use:
use Apache2::Module ();
use Apache2::ServerRec ();
use Apache2::ServerUtil ();
...
if ($s->is_virtual) {
my $base_srv_cfg = Apache2::Module::get_config('MyApache2::MyParameters',
Apache2::ServerUtil->server);
print $base_srv_cfg->{name};
}
However, I think you can still get to anything you want:
my $tree = Apache2::Directive::conftree();
by traversing this far enough down. (see t/response/TestApache/conftree.pm)
--
------------------------------------------------------------------------
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: Reading custom configuration parameters
Posted by Erik Norgaard <no...@locolomo.org>.
Philip M. Gollucci wrote:
> Erik Norgaard wrote:
>> Hi:
>>
>> I have successfully created a module that declares some configuration
>> parameters which should be available to the handler: dbDriver, dbHost,
>> dbName, dbUser and dbPassword. Or so I think, I followed this guide:
>>
>> http://perl.apache.org/docs/2.0/user/config/custom.html
> This section of it doesn't answer that for you ?
> http://perl.apache.org/docs/2.0/user/config/custom.html#toc_Directive_Callback_Subroutine
>
> The simple answer is try it :)
The yet simpler ? :) Well, what confuses me is the merging example in
the end of the text. Anyway, the text you refer to tells how I can get
global/serverwide parameters, but I don't see any mention of whether or
not parameters defined for a different virtual host is possible. I
prefer not for security.
Thanks again, Erik
--
Ph: +34.666334818 web: http://www.locolomo.org
X.509 Certificate: http://www.locolomo.org/crt/8D03551FFCE04F0C.crt
Key ID: 69:79:B8:2C:E3:8F:E7:BE:5D:C3:C3:B1:74:62:B8:3F:9F:1F:69:B9
Re: Reading custom configuration parameters
Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
Philip M. Gollucci wrote:
> Erik Norgaard wrote:
>> Hi:
>>
>> I have successfully created a module that declares some configuration
>> parameters which should be available to the handler: dbDriver, dbHost,
>> dbName, dbUser and dbPassword. Or so I think, I followed this guide:
>>
>> http://perl.apache.org/docs/2.0/user/config/custom.html
> This section of it doesn't answer that for you ?
> http://perl.apache.org/docs/2.0/user/config/custom.html#toc_Directive_Callback_Subroutine
Sorry, wrong link
http://perl.apache.org/docs/2.0/user/config/custom.html#C_SERVER_CREATE_
--
------------------------------------------------------------------------
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: Reading custom configuration parameters
Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
Erik Norgaard wrote:
> Hi:
>
> I have successfully created a module that declares some configuration
> parameters which should be available to the handler: dbDriver, dbHost,
> dbName, dbUser and dbPassword. Or so I think, I followed this guide:
>
> http://perl.apache.org/docs/2.0/user/config/custom.html
This section of it doesn't answer that for you ?
http://perl.apache.org/docs/2.0/user/config/custom.html#toc_Directive_Callback_Subroutine
The simple answer is try 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....