lib/Apache/TestConfigParse.pm

filter: Statementstmt 11.0% 29 / 262 Branchbran 0.0% 0 / 114 Conditioncond 0.0% 0 / 45 MC/DCmcdc 0.0% 0 / 27 Subroutinesub 20.6% 6 / 29 Podpod 0.0% 0 / 20 totaltotal 7.0% 35 / 497 CC 84 SCAR 53.3
CC
84
Cov
7%
inherit_config
650.0
get_httpd_defines
210.0
inherit_config_file_or_directory
132.9
CRAP 207.0
↑ Summary lib/Apache/TestSmoke.pm »
1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements. See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16 package Apache::TestConfig; #not TestConfigParse on purpose
17  
18 #dont really want/need a full-blown parser
19 #but do want something somewhat generic
20  
21 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 1 ▶use Apache::TestTrace;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 1 ▶use File::Spec::Functions qw(rel2abs splitdir file_name_is_absolute);
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use File::Basename qw(dirname basename);
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 0 ▶sub strip_quotes {
Subroutine strip_quotes: not called CC=2 SCAR=17.9
Pod undocumented
30 0 ▶ local $_ = shift || $_;
Condition0%0/3
shift() || $_
l!l&&r!l&&!r
000
MC/DC0%0/2
shift() || $_
shift() $_
Truth table0%0/3
A || B
A= shift()B= $_
ABresult
1X1
011
000
31 0 s/^\"//; s/\"$//; $_;
32 }
33  
34 my %wanted_config = (
35 4 TAKE1 => {map { $_, 1 } qw(ServerRoot ServerAdmin TypesConfig DocumentRoot)},
36 1 TAKE2 => {map { $_, 1 } qw(LoadModule LoadFile)},
37 );
38  
39 my %spec_init = (
40 0 ▶ TAKE1 => sub { shift->{+shift} = "" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
41 0 ▶ TAKE2 => sub { shift->{+shift} = [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
42 1 );
43  
44 my %spec_apply = (
45 TypesConfig => \&inherit_server_file,
46 0 ▶ ServerRoot => sub {}, #dont override $self->{vars}->{serverroot}
Subroutine __ANON__: not called CC=1 SCAR=0.0
47 1 DocumentRoot => \&inherit_directive_var,
48 LoadModule => \&inherit_load_module,
49 LoadFile => \&inherit_load_file,
50 );
51  
52 #where to add config, default is preamble
53 1 my %spec_postamble = map { $_, 'postamble' } qw(TypesConfig);
54  
55 # need to enclose the following directives into <IfModule
56 # mod_foo.c>..</IfModule>, since mod_foo might be unavailable
57 1 my %ifmodule = (
58 TypesConfig => 'mod_mime.c',
59 );
60  
61 0 ▶sub spec_add_config {
Subroutine spec_add_config: not called CC=3 SCAR=24.8
Pod undocumented
62 0 my($self, $directive, $val) = @_;
63  
64 0 ▶ my $where = $spec_postamble{$directive} || 'preamble';
Condition0%0/2
$spec_postamble{$directive} || 'preamble'
l!l
00
MC/DC0%0/1
$spec_postamble{$directive} || 'preamble'
$spec_postamble{$directive}
Truth table0%0/2
A
A= $spec_postamble{$directive}
Aresult
11
00
65  
66 0 ▶ if (my $ifmodule = $ifmodule{TypesConfig}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ifmodule = $ifmodule{'TypesConfig'}) { } 0 0 0
67 0 $self->postamble(<<EOI);
68 <IfModule $ifmodule>
69 $directive $val
70 </IfModule>
71 EOI
72 }
73 else {
74 0 $self->$where($directive => $val);
75 }
76 }
77  
78 # resolve relative files like Apache->server_root_relative
79 # this function doesn't test whether the resolved file exists
80 0 ▶sub server_file_rel2abs {
Subroutine server_file_rel2abs: not called CC=11 SCAR=48.8
Pod undocumented
81 0 my($self, $file, $base) = @_;
82  
83 0 my ($serverroot, $result) = ();
84  
85 # order search sequence
86 my @tries = ([ $base,
87 'user-supplied $base' ],
88 [ $self->{inherit_config}->{ServerRoot},
89 0 'httpd.conf inherited ServerRoot' ],
90 [ $self->apxs('PREFIX', 1),
91 'apxs-derived ServerRoot' ]);
92  
93 # remove surrounding quotes if any
94 # e.g. Include "/tmp/foo.html"
95 0 $file =~ s/^\s*["']?//;
96 0 $file =~ s/["']?\s*$//;
97  
98 0 ▶ if (file_name_is_absolute($file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (file_name_is_absolute($file)) { } 0 0 0
99 0 debug "$file is already absolute";
100 0 $result = $file;
101 }
102 else {
103 0 foreach my $try (@tries) {
104 0 ▶ next unless defined $try->[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $try->[0] 0 0 0
105  
106 0 ▶ if (-d $try->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $try->[0]) 0 0 0
107 0 $serverroot = $try->[0];
108 0 debug "using $try->[1] to resolve $file";
109 0 last;
110 }
111 }
112  
113 0 ▶ if ($serverroot) {
Branch: 1 branch
BranchTrueFalseTotal
if ($serverroot) { } 0 0 0
114 0 $result = rel2abs $file, $serverroot;
115 }
116 else {
117 0 warning "unable to resolve $file - cannot find a suitable ServerRoot";
118 0 warning "please specify a ServerRoot in your httpd.conf or use apxs";
119  
120 # return early, skipping file test below
121 0 return $file;
122 }
123 }
124  
125 0 my $dir = dirname $result;
126 # $file might not exist (e.g. if it's a glob pattern like
127 # "conf/*.conf" but what we care about here is to check whether
128 # the base dir was successfully resolved. we don't check whether
129 # the file exists at all. it's the responsibility of the caller to
130 # do this check
131 0 ▶ if (defined $dir && -e $dir && -d _) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dir and -e $dir and -d _) { } 0 0 0
Condition0%0/6
defined $dir and -e $dir and -d _
!ll&&!rl&&r
000
defined $dir and -e $dir
!ll&&!rl&&r
000
MC/DC0%0/3
defined $dir and -e $dir and -d _
defined $dir -e $dir -d _
Truth table0%0/4
A and B and C
A= defined $dirB= -e $dirC= -d _
ABCresult
0XX0
10X0
1100
1111
132 0 ▶ if (-e $result) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $result) { } 0 0 0
133 0 debug "$file successfully resolved to existing file $result";
134 }
135 else {
136 0 debug "base dir of '$file' successfully resolved to $dir";
137 }
138  
139 }
140 else {
141 0 ▶ $dir ||= '';
Condition0%0/2
$dir ||= ""
l!l
00
MC/DC0%0/1
$dir ||= ""
$dir
Truth table0%0/2
A
A= $dir
Aresult
11
00
142 0 warning "dir '$dir' does not exist (while resolving '$file')";
143  
144 # old behavior was to return the resolved but non-existent
145 # file. preserve that behavior and return $result anyway.
146 }
147  
148 0 return $result;
149 }
150  
151 0 ▶sub server_file {
Subroutine server_file: not called CC=1 SCAR=6.9
Pod undocumented
152 0 my $f = shift->server_file_rel2abs(@_);
153 0 return qq("$f");
154 }
155  
156 0 ▶sub inherit_directive_var {
Subroutine inherit_directive_var: not called CC=1 SCAR=6.9
Pod undocumented
157 0 my($self, $c, $directive) = @_;
158  
159 0 $self->{vars}->{"inherit_\L$directive"} = $c->{$directive};
160 }
161  
162 0 ▶sub inherit_server_file {
Subroutine inherit_server_file: not called CC=1 SCAR=6.9
Pod undocumented
163 0 my($self, $c, $directive) = @_;
164  
165 $self->spec_add_config($directive,
166 0 $self->server_file($c->{$directive}));
167 }
168  
169 #so we have the same names if these modules are linked static or shared
170 1 my %modname_alias = (
171 'mod_pop.c' => 'pop_core.c',
172 'mod_proxy_ajp.c' => 'proxy_ajp.c',
173 'mod_proxy_http.c' => 'proxy_http.c',
174 'mod_proxy_ftp.c' => 'proxy_ftp.c',
175 'mod_proxy_balancer.c' => 'proxy_balancer.c',
176 'mod_proxy_connect.c' => 'proxy_connect.c',
177 'mod_modperl.c' => 'mod_perl.c',
178 );
179  
180 # Block modules which inhibit testing:
181 # - mod_jk requires JkWorkerFile or JkWorker to be configured
182 # skip it for now, tomcat has its own test suite anyhow.
183 # - mod_casp2 requires other settings in addition to LoadModule
184 # - mod_bwshare and mod_evasive20 block fast requests that tests are doing
185 # - mod_fcgid causes https://rt.cpan.org/Public/Bug/Display.html?id=54476
186 # - mod_modnss.c and mod_rev.c require further configuration
187 1 my @autoconfig_skip_module = qw(mod_jk.c mod_casp2.c mod_bwshare.c
188 mod_fcgid.c mod_evasive20.c mod_modnss.c mod_rev.c);
189  
190 # add modules to be not inherited from the existing config.
191 # e.g. prevent from LoadModule perl_module to be included twice, when
192 # mod_perl already configures LoadModule and it's certainly found in
193 # the existing httpd.conf installed system-wide.
194 0 ▶sub autoconfig_skip_module_add {
Subroutine autoconfig_skip_module_add: not called CC=1 SCAR=6.9
Pod undocumented
195 0 push @autoconfig_skip_module, @_;
196 }
197  
198 0 ▶sub should_skip_module {
Subroutine should_skip_module: not called CC=5 SCAR=34.0
Pod undocumented
199 0 my($self, $name) = @_;
200  
201 0 for (@autoconfig_skip_module) {
202 0 ▶ if (UNIVERSAL::isa($_, 'Regexp')) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($_, 'Regexp')) { } 0 0 0
203 0 ▶ return 1 if $name =~ /$_/;
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ /$_/ 0 0 0
204 }
205 else {
206 0 ▶ return 1 if $name eq $_;
Branch: 1 branch
BranchTrueFalseTotal
if $name eq $_ 0 0 0
207 }
208 }
209 0 return 0;
210 }
211  
212 #inherit LoadModule
213 0 ▶sub inherit_load_module {
Subroutine inherit_load_module: not called CC=5 SCAR=34.0
Pod undocumented
214 0 my($self, $c, $directive) = @_;
215  
216 0 for my $args (@{ $c->{$directive} }) {
217 0 my $modname = $args->[0];
218 0 my $file = $self->server_file_rel2abs($args->[1]);
219  
220 0 ▶ unless (-e $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $file) 0 0 0
221 0 debug "$file does not exist, skipping LoadModule";
222 0 next;
223 }
224  
225 0 my $name = basename $args->[1];
226 0 $name =~ s/\.(s[ol]|dll)$/.c/; #mod_info.so => mod_info.c
227 0 $name =~ s/^lib/mod_/; #libphp4.so => mod_php4.c
228  
229 0 ▶ $name = $modname_alias{$name} if $modname_alias{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $modname_alias{$name} 0 0 0
230  
231 # remember all found modules
232 0 $self->{modules}->{$name} = $file;
233 0 debug "Found: $modname => $name";
234  
235 0 ▶ if ($self->should_skip_module($name)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->should_skip_module($name)) 0 0 0
236 0 debug "Skipping LoadModule of $name";
237 0 next;
238 }
239  
240 0 debug "LoadModule $modname $name";
241  
242 # sometimes people have broken system-wide httpd.conf files,
243 # which include LoadModule of modules, which are built-in, but
244 # won't be skipped above if they are found in the modules/
245 # directory. this usually happens when httpd is built once
246 # with its modules built as shared objects and then again with
247 # static ones: the old httpd.conf still has the LoadModule
248 # directives, even though the modules are now built-in
249 # so we try to workaround this problem using <IfModule>
250 0 $self->preamble(IfModule => "!$name",
251 qq{LoadModule $modname "$file"\n});
252 }
253 }
254  
255 #inherit LoadFile
256 0 ▶sub inherit_load_file {
Subroutine inherit_load_file: not called CC=4 SCAR=30.0
Pod undocumented
257 0 my($self, $c, $directive) = @_;
258  
259 0 for my $args (@{ $c->{$directive} }) {
260 0 my $file = $self->server_file_rel2abs($args->[0]);
261  
262 0 ▶ unless (-e $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $file) 0 0 0
263 0 debug "$file does not exist, skipping LoadFile";
264 0 next;
265 }
266  
267 0 ▶ if ($self->should_skip_module($args->[0])) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->should_skip_module($args->[0])) 0 0 0
268 0 debug "Skipping LoadFile of $args->[0]";
269 0 next;
270 }
271  
272 # remember all found modules
273 0 push @{$self->{load_file}}, $file;
274  
275 0 debug "LoadFile $file";
276  
277 0 $self->preamble_first(qq{LoadFile "$file"\n});
278 }
279 }
280  
281 0 ▶sub parse_take1 {
Subroutine parse_take1: not called CC=1 SCAR=6.9
Pod undocumented
282 0 my($self, $c, $directive) = @_;
283 0 $c->{$directive} = strip_quotes;
284 }
285  
286 0 ▶sub parse_take2 {
Subroutine parse_take2: not called CC=1 SCAR=6.9
Pod undocumented
287 0 my($self, $c, $directive) = @_;
288 0 push @{ $c->{$directive} }, [map { strip_quotes } split];
289 }
290  
291 0 ▶sub apply_take1 {
Subroutine apply_take1: not called CC=2 SCAR=17.9
Pod undocumented
292 0 my($self, $c, $directive) = @_;
293  
294 0 ▶ if (exists $self->{vars}->{lc $directive}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'vars'}{lc $directive}) { } 0 0 0
295 #override replacement @Variables@
296 0 $self->{vars}->{lc $directive} = $c->{$directive};
297 }
298 else {
299 0 $self->spec_add_config($directive, qq("$c->{$directive}"));
300 }
301 }
302  
303 0 ▶sub apply_take2 {
Subroutine apply_take2: not called CC=2 SCAR=17.9
Pod undocumented
304 0 my($self, $c, $directive) = @_;
305  
306 0 for my $args (@{ $c->{$directive} }) {
307 0 $self->spec_add_config($directive => [map { qq("$_") } @$args]);
308 }
309 }
310  
311 0 ▶sub inherit_config_file_or_directory {
Subroutine inherit_config_file_or_directory: not called CC=12 SCAR=48.9
Pod undocumented
312 0 my ($self, $item) = @_;
313  
314 0 ▶ if (-d $item) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $item) 0 0 0
315 0 my $dir = $item;
316 0 debug "descending config directory: $dir";
317  
318 0 ▶ for my $entry (glob "$dir/*") {
Subroutine BEGIN: called CC=1 SCAR=0.2
319 0 $self->inherit_config_file_or_directory($entry);
320 }
321 0 return;
322 }
323  
324 0 my $file = $item;
325 0 debug "inheriting config file: $file";
326  
327 0 my $fh = Symbol::gensym();
328 0 ▶ open($fh, $file) or return;
Branch: 1 branch
BranchTrueFalseTotal
open $fh, $file or return 0 0 0
329  
330 0 my $c = $self->{inherit_config};
331 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
332 0 s/^\s*//; s/\s*$//; s/^\#.*//;
333 0 ▶ next if /^$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^$/ 0 0 0
334  
335 # support continuous config lines (which use \ to break the line)
336 0 ▶ while (s/\\$//) {
Branch: 1 branch
BranchTrueFalseTotal
if (s/\\$//) 0 0 0
337 0 my $cont = <$fh>;
338 0 $cont =~ s/^\s*//;
339 0 $cont =~ s/\s*$//;
340 0 $_ .= $cont;
341 }
342  
343 0 (my $directive, $_) = split /\s+/, $_, 2;
344  
345 0 ▶ if ($directive eq "Include" or $directive eq "IncludeOptional") {
Branch: 1 branch
BranchTrueFalseTotal
if ($directive eq "Include" or $directive eq "IncludeOptional") 0 0 0
Condition0%0/3
$directive eq "Include" or $directive eq "IncludeOptional"
l!l&&r!l&&!r
000
MC/DC0%0/2
$directive eq "Include" or $directive eq "IncludeOptional"
$directive eq "Include" $directive eq "IncludeOptional"
Truth table0%0/3
A or B
A= $directive eq "Include"B= $directive eq "IncludeOptional"
ABresult
1X1
011
000
346 0 foreach my $include (glob($self->server_file_rel2abs($_))) {
347 0 $self->inherit_config_file_or_directory($include);
348 }
349 }
350  
351 #parse what we want
352 0 ▶ while (my($spec, $wanted) = each %wanted_config) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %wanted_config) 0 0 0
353 0 ▶ next unless $wanted->{$directive};
Branch: 1 branch
BranchTrueFalseTotal
unless $wanted->{$directive} 0 0 0
354 0 my $method = "parse_\L$spec";
355 0 $self->$method($c, $directive);
356 }
357 }
358  
359 0 close $fh;
360 }
361  
362 0 ▶sub inherit_config {
Subroutine inherit_config: not called CC=25 SCAR=64.8
Pod undocumented
363 0 my $self = shift;
364  
365 0 $self->get_httpd_static_modules;
366 0 $self->get_httpd_defines;
367  
368 #may change after parsing httpd.conf
369 $self->{vars}->{inherit_documentroot} =
370 0 catfile $self->{httpd_basedir}, 'htdocs';
371  
372 0 my $file = $self->{vars}->{httpd_conf};
373 0 my $extra_file = $self->{vars}->{httpd_conf_extra};
374  
375 0 ▶ unless ($file and -e $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($file and -e $file) 0 0 0
Condition0%0/3
$file and -e $file
!ll&&!rl&&r
000
MC/DC0%0/2
$file and -e $file
$file -e $file
Truth table0%0/3
A and B
A= $fileB= -e $file
ABresult
0X0
100
111
376 0 ▶ if (my $base = $self->{httpd_basedir}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $base = $self->{"httpd_basedir"}) 0 0 0
377 0 my $default_conf = $self->{httpd_defines}->{SERVER_CONFIG_FILE};
378 0 ▶ $default_conf ||= catfile qw(conf httpd.conf);
Condition0%0/3
$default_conf ||= catfile(("conf", "httpd.conf"))
l!l&&r!l&&!r
000
MC/DC0%0/2
$default_conf ||= catfile(("conf", "httpd.conf"))
$default_conf catfile(("conf", "httpd.conf"))
Truth table0%0/3
A ||= B
A= $default_confB= catfile(("conf", "httpd.conf"))
ABresult
1X1
011
000
379 0 $file = catfile $base, $default_conf;
380  
381 # SERVER_CONFIG_FILE might be an absolute path
382 0 ▶ unless (-e $file) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $file) 0 0 0
383 0 ▶ if (-e $default_conf) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $default_conf) { } 0 0 0
384 0 $file = $default_conf;
385 }
386 else {
387 # try a little harder
388 0 ▶ if (my $root = $self->{httpd_defines}->{HTTPD_ROOT}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $root = $self->{"httpd_defines"}{"HTTPD_ROOT"}) 0 0 0
389 0 debug "using HTTPD_ROOT to resolve $default_conf";
390 0 $file = catfile $root, $default_conf;
391 }
392 }
393 }
394 }
395 }
396  
397 0 ▶ unless ($extra_file and -e $extra_file) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($extra_file and -e $extra_file) 0 0 0
Condition0%0/3
$extra_file and -e $extra_file
!ll&&!rl&&r
000
MC/DC0%0/2
$extra_file and -e $extra_file
$extra_file -e $extra_file
Truth table0%0/3
A and B
A= $extra_fileB= -e $extra_file
ABresult
0X0
100
111
398 0 ▶ if ($extra_file and my $base = $self->{httpd_basedir}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($extra_file and my $base = $self->{"httpd_basedir"}) 0 0 0
Condition0%0/3
$extra_file and my $base = $self->{"httpd_basedir"}
!ll&&!rl&&r
000
MC/DC0%0/2
$extra_file and my $base = $self->{"httpd_basedir"}
$extra_file my $base = $self->{"httpd_basedir"}
Truth table0%0/3
A and B
A= $extra_fileB= my $base = $self->{"httpd_basedir"}
ABresult
0X0
100
111
399 0 my $default_conf = catfile qw(conf $extra_file);
400 0 $extra_file = catfile $base, $default_conf;
401 # SERVER_CONFIG_FILE might be an absolute path
402 0 ▶ $extra_file = $default_conf if !-e $extra_file and -e $default_conf;
Branch: 1 branch
BranchTrueFalseTotal
if not -e $extra_file and -e $default_conf 0 0 0
Condition0%0/3
not -e $extra_file and -e $default_conf
!ll&&!rl&&r
000
MC/DC0%0/2
not -e $extra_file and -e $default_conf
not -e $extra_file -e $default_conf
Truth table0%0/3
not(A) and B
A= not -e $extra_fileB= -e $default_conf
ABresult
0X0
100
111
403 }
404 }
405  
406 0 ▶ return unless $file or $extra_file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file or $extra_file 0 0 0
Condition0%0/3
$file or $extra_file
l!l&&r!l&&!r
000
MC/DC0%0/2
$file or $extra_file
$file $extra_file
Truth table0%0/3
A or B
A= $fileB= $extra_file
ABresult
1X1
011
000
407  
408 0 my $c = $self->{inherit_config};
409  
410 #initialize array refs and such
411 0 ▶ while (my($spec, $wanted) = each %wanted_config) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %wanted_config) 0 0 0
412 0 for my $directive (keys %$wanted) {
413 0 $spec_init{$spec}->($c, $directive);
414 }
415 }
416  
417 0 ▶ $self->inherit_config_file_or_directory($file) if $file;
Branch: 1 branch
BranchTrueFalseTotal
if $file 0 0 0
418 0 ▶ $self->inherit_config_file_or_directory($extra_file) if $extra_file;
Branch: 1 branch
BranchTrueFalseTotal
if $extra_file 0 0 0
419  
420 #apply what we parsed
421 0 ▶ while (my($spec, $wanted) = each %wanted_config) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %wanted_config) 0 0 0
422 0 for my $directive (keys %$wanted) {
423 0 ▶ next unless $c->{$directive};
Branch: 1 branch
BranchTrueFalseTotal
unless $c->{$directive} 0 0 0
424 0 ▶ my $cv = $spec_apply{$directive} ||
Condition0%0/6
$spec_apply{$directive} || $self->can("apply_\L$directive\E") || $self->can("apply_\L$spec\E")
l!l&&r!l&&!r
000
$spec_apply{$directive} or $self->can("apply_\L$directive\E")
l!l&&r!l&&!r
000
MC/DC0%0/3
$spec_apply{$directive} || $self->can("apply_\L$directive\E") || $self->can("apply_\L$spec\E")
$spec_apply{$directive} $self->can("apply_\L$directive\E") $self->can("apply_\L$spec\E")
Truth table0%0/4
A or B || C
A= $spec_apply{$directive}B= $self->can("apply_\L$directive\E")C= $self->can("apply_\L$spec\E")
ABCresult
1XX1
01X1
0011
0000
425 $self->can("apply_\L$directive") ||
426 $self->can("apply_\L$spec");
427 0 $cv->($self, $c, $directive);
428 }
429 }
430 }
431  
432 0 ▶sub get_httpd_static_modules {
Subroutine get_httpd_static_modules: not called CC=4 SCAR=30.0
Pod undocumented
433 0 my $self = shift;
434  
435 0 my $httpd = $self->{vars}->{httpd};
436 0 ▶ return unless $httpd;
Branch: 1 branch
BranchTrueFalseTotal
unless $httpd 0 0 0
437  
438 0 $httpd = shell_ready($httpd);
439 0 my $cmd = "$httpd -l";
440 0 my $list = $self->open_cmd($cmd);
441  
442 0 ▶ while (<$list>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $list)) 0 0 0
443 0 s/\s+$//;
444 0 ▶ next unless /\.c$/;
Branch: 1 branch
BranchTrueFalseTotal
unless /\.c$/ 0 0 0
445 0 chomp;
446 0 s/^\s+//;
447 0 $self->{modules}->{$_} = 1;
448 }
449  
450 0 close $list;
451 }
452  
453 0 ▶sub get_httpd_defines {
Subroutine get_httpd_defines: not called CC=14 SCAR=53.5
Pod undocumented
454 0 my $self = shift;
455  
456 0 my $httpd = $self->{vars}->{httpd};
457 0 ▶ return unless $httpd;
Branch: 1 branch
BranchTrueFalseTotal
unless $httpd 0 0 0
458  
459 0 $httpd = shell_ready($httpd);
460 0 my $cmd = "$httpd -V";
461  
462 0 my $httpdconf = $self->{vars}->{httpd_conf};
463 0 ▶ $cmd .= " -f $httpdconf" if $httpdconf;
Branch: 1 branch
BranchTrueFalseTotal
if $httpdconf 0 0 0
464  
465 0 my $serverroot = $self->{vars}->{serverroot};
466 0 ▶ $cmd .= " -d $serverroot" if $serverroot;
Branch: 1 branch
BranchTrueFalseTotal
if $serverroot 0 0 0
467  
468 0 my $proc = $self->open_cmd($cmd);
469  
470 0 ▶ while (<$proc>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $proc)) 0 0 0
471 0 chomp;
472 0 ▶ if( s/^\s*-D\s*//) {
Branch: 2 branches
BranchTrueFalseTotal
if (s/^\s*-D\s*//) { } 0 0 0
elsif (/(version|built|module magic number|server mpm):\s+(.*)/i) { } 0 0 0
473 0 s/\s+$//;
474 0 my($key, $val) = split '=', $_, 2;
475 0 ▶ $self->{httpd_defines}->{$key} = $val ? strip_quotes($val) : 1;
Branch: 1 branch
BranchTrueFalseTotal
$val ? : 0 0 0
476 0 debug "isolated httpd_defines $key = " . $self->{httpd_defines}->{$key};
477 }
478 elsif (/(version|built|module magic number|server mpm):\s+(.*)/i) {
479 0 my $val = $2;
480 0 (my $key = uc $1) =~ s/\s/_/g;
481 0 $self->{httpd_info}->{$key} = $val;
482 0 debug "isolated httpd_info $key = " . $val;
483 }
484 }
485  
486 0 close $proc;
487  
488 0 ▶ if (my $mmn = $self->{httpd_info}->{MODULE_MAGIC_NUMBER}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $mmn = $self->{"httpd_info"}{"MODULE_MAGIC_NUMBER"}) 0 0 0
489 0 @{ $self->{httpd_info} }
490 0 {qw(MODULE_MAGIC_NUMBER_MAJOR
491 MODULE_MAGIC_NUMBER_MINOR)} = split ':', $mmn;
492 }
493  
494 # get the mpm information where available
495 # lowercase for consistency across the two extraction methods
496 # XXX or maybe consider making have_apache_mpm() case-insensitive?
497 0 ▶ if (my $mpm = $self->{httpd_info}->{SERVER_MPM}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $mpm = $self->{'httpd_info'}{'SERVER_MPM'}) { } 0 0 0
elsif (my $mpm_dir = $self->{'httpd_defines'}{'APACHE_MPM_DIR'}) { } 0 0 0
498 # 2.1
499 0 $self->{mpm} = lc $mpm;
500 }
501 elsif (my $mpm_dir = $self->{httpd_defines}->{APACHE_MPM_DIR}) {
502 # 2.0
503 0 $self->{mpm} = lc basename $mpm_dir;
504 }
505 else {
506 # Apache 1.3 - no mpm to speak of
507 0 $self->{mpm} = '';
508 }
509  
510 0 ▶ my $version = $self->{httpd_info}->{VERSION} || '';
Condition0%0/2
$self->{'httpd_info'}{'VERSION'} || ''
l!l
00
MC/DC0%0/1
$self->{'httpd_info'}{'VERSION'} || ''
$self->{'httpd_info'}{'VERSION'}
Truth table0%0/2
A
A= $self->{'httpd_info'}{'VERSION'}
Aresult
11
00
511  
512 0 ▶ if ($version =~ qr,Apache/2,) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version =~ qr"Apache/2") 0 0 0
513 # PHP 4.x on httpd-2.x needs a special modname alias:
514 0 $modname_alias{'mod_php4.c'} = 'sapi_apache2.c';
515 }
516  
517 0 ▶ unless ($version =~ qr,Apache/(2.0|1.3),) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($version =~ qr"Apache/(2.0|1.3)") 0 0 0
518 # for 2.1 and later, mod_proxy_* are really called mod_proxy_*
519 0 delete @modname_alias{grep {/^mod_proxy_/} keys %modname_alias};
520 }
521 }
522  
523 0 ▶sub httpd_version {
Subroutine httpd_version: not called CC=7 SCAR=40.3
Pod undocumented
524 0 my $self = shift;
525  
526 0 my $httpd = $self->{vars}->{httpd};
527 0 ▶ return unless $httpd;
Branch: 1 branch
BranchTrueFalseTotal
unless $httpd 0 0 0
528  
529 0 my $version;
530 0 $httpd = shell_ready($httpd);
531 0 my $cmd = "$httpd -v";
532  
533 0 my $v = $self->open_cmd($cmd);
534  
535 0 local $_;
536 0 ▶ while (<$v>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $v)) 0 0 0
537 0 ▶ next unless s/^Server\s+version:\s*//i;
Branch: 1 branch
BranchTrueFalseTotal
unless s/^Server\s+version:\s*//i 0 0 0
538 0 chomp;
539 0 my @parts = split;
540 0 foreach (@parts) {
541 0 ▶ next unless /^Apache\//;
Branch: 1 branch
BranchTrueFalseTotal
unless m[^Apache/] 0 0 0
542 0 $version = $_;
543 0 last;
544 }
545 0 ▶ $version ||= $parts[0];
Condition0%0/3
$version ||= $parts[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
$version ||= $parts[0]
$version $parts[0]
Truth table0%0/3
A ||= B
A= $versionB= $parts[0]
ABresult
1X1
011
000
546 0 last;
547 }
548  
549 0 close $v;
550  
551 0 return $version;
552 }
553  
554 0 ▶sub httpd_mpm {
Subroutine httpd_mpm: not called CC=1 SCAR=6.9
Pod undocumented
555 0 return shift->{mpm};
556 }
557  
558 1 1;
↑ Summary lib/Apache/TestSmoke.pm »