line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# Apache::Layer |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# Layer is designed to allow content trees to be overlayed. This means that |
5
|
|
|
|
|
|
|
# you can have more than one directory searched when looking for a file to |
6
|
|
|
|
|
|
|
# be returned by the server. |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# Author: Simon Matthews |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
# Copyright (C) 1998 Simon Matthews. All Rights Reserved. |
11
|
|
|
|
|
|
|
# |
12
|
|
|
|
|
|
|
# This module is free software; you can distribute it and/or modify is under |
13
|
|
|
|
|
|
|
# the same terms as Perl itself. |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
package Apache::Layer; |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
1159
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# get the DECLINED and OK constants |
21
|
1
|
|
|
1
|
|
1860
|
use Apache::Constants qw(REDIRECT DECLINED OK); |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use vars qw($VERSION $DEBUG); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$VERSION = sprintf("%d.%02d", q$Revision: 1.7 $ =~ /(\d+)\.(\d+)/); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$DEBUG = 0; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub handler { |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my ($r) = @_; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $LAYER_PATH; |
34
|
|
|
|
|
|
|
my $LOCATION; |
35
|
|
|
|
|
|
|
my $turi; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# get our configuration or return DECLINED as we will not process |
38
|
|
|
|
|
|
|
# this request |
39
|
|
|
|
|
|
|
$LAYER_PATH = $r->dir_config("apache_layer_path") || return DECLINED; |
40
|
|
|
|
|
|
|
$LOCATION = $r->dir_config("apache_layer_location") || return DECLINED; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
print STDERR "Apache::Layer called translating.....\n" if $DEBUG; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# get a copy of the URI |
45
|
|
|
|
|
|
|
$turi = $r->uri || ''; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# no URI is a really strange error |
48
|
|
|
|
|
|
|
return DECLINED unless $turi; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
print STDERR "Trans URI = [$turi]\n" if $DEBUG; |
51
|
|
|
|
|
|
|
print STDERR "Location = [$LOCATION]\n" if $DEBUG; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# chop off the location from the uri before we look it up. |
54
|
|
|
|
|
|
|
# we do this as we are passed in stuff like /images/icons/foo.gif |
55
|
|
|
|
|
|
|
# and we want to look up stuff like /usr/www/images/icons/foo.gif |
56
|
|
|
|
|
|
|
# where the path part is /usr/www/images |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$turi =~ s/^${LOCATION}//; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
my $file = ''; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
foreach (split(/[:,;]+/,$LAYER_PATH)) { |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
next unless defined($_); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# build a full path to the file / directory so that we can check it |
67
|
|
|
|
|
|
|
$file = "$_$turi"; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
print STDERR "Trans checking [$file]\n" if $DEBUG; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
if ( -r $file ) { |
72
|
|
|
|
|
|
|
last; |
73
|
|
|
|
|
|
|
} else { |
74
|
|
|
|
|
|
|
$file = ''; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# when we fall out of the loop $file will be set with the file we matched |
80
|
|
|
|
|
|
|
# otherwise we failed to translate the file so return DECLINED |
81
|
|
|
|
|
|
|
return DECLINED unless $file; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# set the file for the request and return OK |
84
|
|
|
|
|
|
|
$r->filename($file); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
print STDERR "Trans now has filename ", $r->filename() , "\n" if $DEBUG; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
return OK; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub version { |
94
|
|
|
|
|
|
|
return $VERSION; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
1; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 NAME |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Apache::Layer - Layer content tree over one or more others. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 SYNOPSIS |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
#httpd.conf |
106
|
|
|
|
|
|
|
PerlTransHandler Apache::Layer |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# anywhere you can configure a location |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
PerlSetVar apache_layer_location /project/images |
111
|
|
|
|
|
|
|
PerlSetVar apache_layer_path /dir1/root;/dir2/root |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 DESCRIPTION |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This module is designed to allow multiple content trees to be layered on top |
117
|
|
|
|
|
|
|
of each other within the Apache server. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
I developed this module because we produce lots of web sites where a high |
120
|
|
|
|
|
|
|
proportion of the site content is common. But where specific pages / images |
121
|
|
|
|
|
|
|
are tailored to the specific project. This module allows us to layer a sparse |
122
|
|
|
|
|
|
|
directory tree on top of the main complete tree without requiring redirects. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
The essence is that it will cause Apache to deliver content from a series of |
125
|
|
|
|
|
|
|
directories in turn. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
In some ways Apache::Layer is similar to Apache::Stage however it does not |
128
|
|
|
|
|
|
|
require redirects. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 COMMON PROBLEMS |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Apache::Layer is relatively simple. The most common problem is not setting the |
133
|
|
|
|
|
|
|
apache_layer_location parameter correctly. As a rule this parameter should |
134
|
|
|
|
|
|
|
ALWAYS match the parameter within the location i.e. . |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 AUTHOR |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Simon Matthews Esam@peritas.comE |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 REVISION |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
$Revision: 1.7 $ |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 COPYRIGHT |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Copyright (C) 1998 Simon Matthews. All Rights Reserved. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
This module is free software; you can distribute it and/or modify |
149
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head1 SEE ALSO |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Apache::Stage |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=cut |