You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Glenn Martin <li...@yahoo.com> on 2006/03/01 22:44:01 UTC

Perl Script using MapToStorageHandler

Ive got a script im wokring on that uses the
"PerlMapToStorageHandler" at that point it adds to the
Apache Configuration using the Incomming URI, creating
Location/Directory Sections, and an Alias or two... 

However, i need to be able to remove these changes
after the request is completed... How would i remove
theses changes and what handler would you suggest for
me to tie in to?

Thank You
Glenn R. Martin

Re: Perl Script using MapToStorageHandler

Posted by Glenn Martin <li...@yahoo.com>.
If i am doing this wrong, how would you suggest doing
it?

Glenn R. Martin

--- Andy Armstrong <an...@hexten.net> wrote:

> On 1 Mar 2006, at 21:44, Glenn Martin wrote:
> > Ive got a script im wokring on that uses the
> > "PerlMapToStorageHandler" at that point it adds to
> the
> > Apache Configuration using the Incomming URI,
> creating
> > Location/Directory Sections, and an Alias or
> two...
> >
> > However, i need to be able to remove these changes
> > after the request is completed... How would i
> remove
> > theses changes and what handler would you suggest
> for
> > me to tie in to?
> 
> You're doing it wrong I'm afraid. Why do you want to
> change the  
> server config during a request?
> 
> -- 
> Andy Armstrong, hexten.net
> 
> 


Re: Perl Script using MapToStorageHandler

Posted by Andy Armstrong <an...@hexten.net>.
On 1 Mar 2006, at 22:13, Philippe M. Chiasson wrote:
> And you get pre-request behaviour just like you wanted. And it's  
> tons faster too ;-)

Yup, what he said.

-- 
Andy Armstrong, hexten.net


Re: Perl Script using MapToStorageHandler

Posted by Torsten Foertsch <to...@gmx.net>.
On Thursday 02 March 2006 15:34, Geoffrey Young wrote:
> thanks for the detailed explanations.  torsten++ :)
>
> > That leads to an error saying that "<Directory" is not allowed at that
> > point.
> >
> > But, a few thing cannot be applied by means of $r->add_config. For
> > example "AllowOverride" needs a "Directory" block
>
> I think what most people don't understand about $r->add_config() is that
> it's .htaccess-style configuration injection.  so, if you can't use a given
> config from an .htaccess file you can't use add_config() for it either.

Well, that is not entirely true at least if the mentioned patch is applied. 
For example AllowOverride cannot be used in a .htaccess. But with the patch 
you can say:

  $r->add_config( ['<Directory />',
                   'AllowOverride AuthConfig Options=Indexes,ExecCGI',
                   '</Directory>',
                  ], ~0, '' );

If done in a MapToStorage handler that returns DECLINED it even affects the 
subsequent processing of a .htaccess file.

Or to do something like .htaccess processing:

use Apache2::Access;
use Apache2::RequestUtil;

{
  local @ARGV=($htaccess_file_name);
  $r->add_config( [<>], $r->allow_override, '/', $r->allow_override_opts );
}

Torsten

Re: Perl Script using MapToStorageHandler

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
thanks for the detailed explanations.  torsten++ :)

> That leads to an error saying that "<Directory" is not allowed at that point. 

> But, a few thing cannot be applied by means of $r->add_config. For example 
> "AllowOverride" needs a "Directory" block

I think what most people don't understand about $r->add_config() is that
it's .htaccess-style configuration injection.  so, if you can't use a given
config from an .htaccess file you can't use add_config() for it either.

all the rest is good stuff and on target :)

--Geoff

Re: Perl Script using MapToStorageHandler

Posted by Glenn Martin <li...@yahoo.com>.
Sure id love to see that script... to be completely
hones im still kinda new to perl even... Im getting it
slowly... Anyway, im just looking to achieve my goal
and that is to have a working script/perl module that
can switchout config based on incomming URI... a
perfect example would be the one im working on now...
the Subversion/Dav one...

Glenn

--- Torsten Foertsch <to...@gmx.net> wrote:

> On Wednesday 01 March 2006 23:20, Glenn Martin
> wrote:
> > Sounds great, but how would i do something simular
> to:
> >
> >       $r->add_config([sprintf('<LocationMatch
> > "%s/?">', $uripath),
> >                           'DirectoryIndex .',
> >                           'Options +Indexes',
> >                           'Dav svn',
> >                           sprintf("SVNPath %s",
> > $localpath),
> >                           '</LocationMatch>']);
> >
> >
> > and
> >
> >       $r->add_config([sprintf('<Directory "%s">',
> > $localpath), 'DirectoryIndex .', 'Options
> +Indexes',
> > 'Dav On', '</Directory>']);
> 
> That leads to an error saying that "<Directory" is
> not allowed at that point. 
> In your case I think you don't need the "Directory"
> around your 
> configuration, I think. But, let me explain how the
> configuration is applied 
> to a request. After startup when the configuration
> has been parsed you have a 
> server/vhost-specific default configuration. That is
> everything outside 
> "Directory", "Location" and so on. Just before
> MapToStorage a copy of this 
> config is made. Then the core-MapToStorage handler
> applies "Location", 
> "Directory" etc blocks to that copy. At the end of
> the request this copy is 
> thrown away.
> 
> The mod_perl MapToStorage handler comes in after the
> server-specific config is 
> loaded but before the core handler. In fact if the
> mp-handler returns OK the 
> core-handler is skipped.
> 
> When $r->add_config(\@lines, $override) is applied
> in MapToStorage it is very 
> similar to
> 
> AllowOverride $override
> <Location />
> @lines
> </Location>
> 
> Only this location block is applied *before* any
> Directory block.
> 
> That means
> 
> 1) If your mp-handler returns DECLINED, your current
> configuration can be 
> overridden by the core-handler, because it comes
> after you.
> 
> 2) Anything you apply to the config in MapToStorage
> applies to a copy. Hence, 
> nothing is needed to undo the changes.
> 
> 3) Your config can be applied by
> 
> $r->add_config([
>                 'DirectoryIndex .',
>                 'Options Indexes',
>                 'Dav svn',
>                 sprintf("SVNPath %s", $localpath),  
>               
>                ], ~0)     # ~0 == AllowOverride All
> 
> 
> But, a few thing cannot be applied by means of
> $r->add_config. For example 
> "AllowOverride" needs a "Directory" block or
> "ProxyPassReverse" does 
> different things if it appears outside or inside a
> "Location" block. Further, 
> mod_perl-2.0.2 cannot apply "Options" if working
> under Apache 2.2. For these 
> situations I have posted a patch a few days ago
> (last Friday I think). I hope 
> it will make it into mod_perl 2.0.3 see
> 
>  
>
http://www.gossamer-threads.com/lists/modperl/modperl/87401
> 
> In fact, I am currently working on a module that can
> read the configuration 
> from a database and apply it on the fly. It already
> works pretty good. If you 
> want I can send you a current copy. I think of
> releasing it on CPAN later 
> this week or early next week.
> 
> Torsten
> 


Re: Perl Script using MapToStorageHandler

Posted by Torsten Foertsch <to...@gmx.net>.
On Wednesday 01 March 2006 23:20, Glenn Martin wrote:
> Sounds great, but how would i do something simular to:
>
>       $r->add_config([sprintf('<LocationMatch
> "%s/?">', $uripath),
>                           'DirectoryIndex .',
>                           'Options +Indexes',
>                           'Dav svn',
>                           sprintf("SVNPath %s",
> $localpath),
>                           '</LocationMatch>']);
>
>
> and
>
>       $r->add_config([sprintf('<Directory "%s">',
> $localpath), 'DirectoryIndex .', 'Options +Indexes',
> 'Dav On', '</Directory>']);

That leads to an error saying that "<Directory" is not allowed at that point. 
In your case I think you don't need the "Directory" around your 
configuration, I think. But, let me explain how the configuration is applied 
to a request. After startup when the configuration has been parsed you have a 
server/vhost-specific default configuration. That is everything outside 
"Directory", "Location" and so on. Just before MapToStorage a copy of this 
config is made. Then the core-MapToStorage handler applies "Location", 
"Directory" etc blocks to that copy. At the end of the request this copy is 
thrown away.

The mod_perl MapToStorage handler comes in after the server-specific config is 
loaded but before the core handler. In fact if the mp-handler returns OK the 
core-handler is skipped.

When $r->add_config(\@lines, $override) is applied in MapToStorage it is very 
similar to

AllowOverride $override
<Location />
@lines
</Location>

Only this location block is applied *before* any Directory block.

That means

1) If your mp-handler returns DECLINED, your current configuration can be 
overridden by the core-handler, because it comes after you.

2) Anything you apply to the config in MapToStorage applies to a copy. Hence, 
nothing is needed to undo the changes.

3) Your config can be applied by

$r->add_config([
                'DirectoryIndex .',
                'Options Indexes',
                'Dav svn',
                sprintf("SVNPath %s", $localpath),                 
               ], ~0)     # ~0 == AllowOverride All


But, a few thing cannot be applied by means of $r->add_config. For example 
"AllowOverride" needs a "Directory" block or "ProxyPassReverse" does 
different things if it appears outside or inside a "Location" block. Further, 
mod_perl-2.0.2 cannot apply "Options" if working under Apache 2.2. For these 
situations I have posted a patch a few days ago (last Friday I think). I hope 
it will make it into mod_perl 2.0.3 see

  http://www.gossamer-threads.com/lists/modperl/modperl/87401

In fact, I am currently working on a module that can read the configuration 
from a database and apply it on the fly. It already works pretty good. If you 
want I can send you a current copy. I think of releasing it on CPAN later 
this week or early next week.

Torsten

Re: Perl Script using MapToStorageHandler

Posted by Glenn Martin <li...@yahoo.com>.
Sounds great, but how would i do something simular to:

      $r->add_config([sprintf('<LocationMatch
"%s/?">', $uripath),
                          'DirectoryIndex .',
                          'Options +Indexes',
                          'Dav svn',
                          sprintf("SVNPath %s",
$localpath),
                          '</LocationMatch>']);


and

      $r->add_config([sprintf('<Directory "%s">',
$localpath), 'DirectoryIndex .', 'Options +Indexes',
'Dav On', '</Directory>']);


--- "Philippe M. Chiasson" <go...@ectoplasm.org>
wrote:

> Glenn Martin wrote:
> > Actually if i read the documentation correctly, im
> > doing it just right. Map to Storage is right
> before it
> > get mapped to a Location/Directory... and thus
> this is
> > where id want to add Directory/Location and Alias
> > directives based off of the incomming URI... Im
> trying
> > to control DAV input. Take the URI, translate it
> to a
> > Folder, Check the folders contents to see if it
> > matches a Subversion repository and if it does map
> the
> > Location to SVN Dav and that repository otherwise
> Map
> > the Directory to the URI using an Alias and a
> > Directory and turn on normal WebDAV... Then return
> > Decline to Apache then tries to Match the URI to
> the
> > Modified Config. Which will active the correct
> module
> > for the correct folder...
> 
> I hope I understood this correctly, so apologies if
> I didn't.
> 
> > However i need this configuration change to be
> > Temporary... Per request only... I need the Alias'
> or
> > Location/Directory sections to no longer exist..
> 
> You can't 'remove' configuration directives you've
> injected
> in httpd. And those are very *global* and would
> affect
> much more than the current request.
> 
> > What handler do i use? and how do i reset the
> > configuration?
> 
> You don't reset the configuration, but you simply
> take a different
> approach.
> 
> Instead of trying to inject httpd configuration,
> your MapToStorage handler
> needs to emulate Alias/Location directives. For
> instance, if you needed
> to Alias /foo to /var/www/foo, instead of doing what
> I believe you are currently
> doing:
> 
> $r->add_config(["Alias /foo /var/www/foo"]);
> 
> Simply do what mod_alias would have done...
> 
> $r->filename(File::Spec->catfile("/var/www",
> $r->uri));
> 
> And you get pre-request behaviour just like you
> wanted. And it's tons faster too ;-)
> 
>
--------------------------------------------------------------------------------
> Philippe M. Chiasson
> m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID :
> 88C3A5A5
> http://gozer.ectoplasm.org/     F9BF E0C2 480E 7680
> 1AE5 3631 CB32 A107 88C3A5A5
> 


Re: Perl Script using MapToStorageHandler

Posted by Glenn Martin <li...@yahoo.com>.
Sounds great, but how would i do something simular to:

      $r->add_config([sprintf('<LocationMatch
"%s/?">', $uripath),
                          'DirectoryIndex .',
                          'Options +Indexes',
                          'Dav svn',
                          sprintf("SVNPath %s",
$localpath),
                          '</LocationMatch>']);


and

      $r->add_config([sprintf('<Directory "%s">',
$localpath), 'DirectoryIndex .', 'Options +Indexes',
'Dav On', '</Directory>']);


--- "Philippe M. Chiasson" <go...@ectoplasm.org>
wrote:

> Glenn Martin wrote:
> > Actually if i read the documentation correctly, im
> > doing it just right. Map to Storage is right
> before it
> > get mapped to a Location/Directory... and thus
> this is
> > where id want to add Directory/Location and Alias
> > directives based off of the incomming URI... Im
> trying
> > to control DAV input. Take the URI, translate it
> to a
> > Folder, Check the folders contents to see if it
> > matches a Subversion repository and if it does map
> the
> > Location to SVN Dav and that repository otherwise
> Map
> > the Directory to the URI using an Alias and a
> > Directory and turn on normal WebDAV... Then return
> > Decline to Apache then tries to Match the URI to
> the
> > Modified Config. Which will active the correct
> module
> > for the correct folder...
> 
> I hope I understood this correctly, so apologies if
> I didn't.
> 
> > However i need this configuration change to be
> > Temporary... Per request only... I need the Alias'
> or
> > Location/Directory sections to no longer exist..
> 
> You can't 'remove' configuration directives you've
> injected
> in httpd. And those are very *global* and would
> affect
> much more than the current request.
> 
> > What handler do i use? and how do i reset the
> > configuration?
> 
> You don't reset the configuration, but you simply
> take a different
> approach.
> 
> Instead of trying to inject httpd configuration,
> your MapToStorage handler
> needs to emulate Alias/Location directives. For
> instance, if you needed
> to Alias /foo to /var/www/foo, instead of doing what
> I believe you are currently
> doing:
> 
> $r->add_config(["Alias /foo /var/www/foo"]);
> 
> Simply do what mod_alias would have done...
> 
> $r->filename(File::Spec->catfile("/var/www",
> $r->uri));
> 
> And you get pre-request behaviour just like you
> wanted. And it's tons faster too ;-)
> 
>
--------------------------------------------------------------------------------
> Philippe M. Chiasson
> m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID :
> 88C3A5A5
> http://gozer.ectoplasm.org/     F9BF E0C2 480E 7680
> 1AE5 3631 CB32 A107 88C3A5A5
> 


Re: Perl Script using MapToStorageHandler

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
Glenn Martin wrote:
> Actually if i read the documentation correctly, im
> doing it just right. Map to Storage is right before it
> get mapped to a Location/Directory... and thus this is
> where id want to add Directory/Location and Alias
> directives based off of the incomming URI... Im trying
> to control DAV input. Take the URI, translate it to a
> Folder, Check the folders contents to see if it
> matches a Subversion repository and if it does map the
> Location to SVN Dav and that repository otherwise Map
> the Directory to the URI using an Alias and a
> Directory and turn on normal WebDAV... Then return
> Decline to Apache then tries to Match the URI to the
> Modified Config. Which will active the correct module
> for the correct folder...

I hope I understood this correctly, so apologies if I didn't.

> However i need this configuration change to be
> Temporary... Per request only... I need the Alias' or
> Location/Directory sections to no longer exist..

You can't 'remove' configuration directives you've injected
in httpd. And those are very *global* and would affect
much more than the current request.

> What handler do i use? and how do i reset the
> configuration?

You don't reset the configuration, but you simply take a different
approach.

Instead of trying to inject httpd configuration, your MapToStorage handler
needs to emulate Alias/Location directives. For instance, if you needed
to Alias /foo to /var/www/foo, instead of doing what I believe you are currently
doing:

$r->add_config(["Alias /foo /var/www/foo"]);

Simply do what mod_alias would have done...

$r->filename(File::Spec->catfile("/var/www", $r->uri));

And you get pre-request behaviour just like you wanted. And it's tons faster too ;-)

--------------------------------------------------------------------------------
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/     F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5

Re: Perl Script using MapToStorageHandler

Posted by Glenn Martin <li...@yahoo.com>.
Actually if i read the documentation correctly, im
doing it just right. Map to Storage is right before it
get mapped to a Location/Directory... and thus this is
where id want to add Directory/Location and Alias
directives based off of the incomming URI... Im trying
to control DAV input. Take the URI, translate it to a
Folder, Check the folders contents to see if it
matches a Subversion repository and if it does map the
Location to SVN Dav and that repository otherwise Map
the Directory to the URI using an Alias and a
Directory and turn on normal WebDAV... Then return
Decline to Apache then tries to Match the URI to the
Modified Config. Which will active the correct module
for the correct folder...

However i need this configuration change to be
Temporary... Per request only... I need the Alias' or
Location/Directory sections to no longer exist..

What handler do i use? and how do i reset the
configuration?

--- Andy Armstrong <an...@hexten.net> wrote:

> On 1 Mar 2006, at 21:44, Glenn Martin wrote:
> > Ive got a script im wokring on that uses the
> > "PerlMapToStorageHandler" at that point it adds to
> the
> > Apache Configuration using the Incomming URI,
> creating
> > Location/Directory Sections, and an Alias or
> two...
> >
> > However, i need to be able to remove these changes
> > after the request is completed... How would i
> remove
> > theses changes and what handler would you suggest
> for
> > me to tie in to?
> 
> You're doing it wrong I'm afraid. Why do you want to
> change the  
> server config during a request?
> 
> -- 
> Andy Armstrong, hexten.net
> 
> 


Re: Perl Script using MapToStorageHandler

Posted by Andy Armstrong <an...@hexten.net>.
On 1 Mar 2006, at 21:44, Glenn Martin wrote:
> Ive got a script im wokring on that uses the
> "PerlMapToStorageHandler" at that point it adds to the
> Apache Configuration using the Incomming URI, creating
> Location/Directory Sections, and an Alias or two...
>
> However, i need to be able to remove these changes
> after the request is completed... How would i remove
> theses changes and what handler would you suggest for
> me to tie in to?

You're doing it wrong I'm afraid. Why do you want to change the  
server config during a request?

-- 
Andy Armstrong, hexten.net