You are viewing a plain text version of this content. The canonical link for it is here.
Posted to test-cvs@httpd.apache.org by do...@apache.org on 2001/11/17 03:09:31 UTC
cvs commit: httpd-test/perl-framework/Apache-Test/lib/Apache TestConfig.pm TestConfigPerl.pm
dougm 01/11/16 18:09:30
Modified: perl-framework/Apache-Test/lib/Apache TestConfig.pm
TestConfigPerl.pm
Log:
move vhost parsing/configuring into a single function
that is now used in both *.conf.in and *.{pm,c} parsing
Revision Changes Path
1.84 +51 -10 httpd-test/perl-framework/Apache-Test/lib/Apache/TestConfig.pm
Index: TestConfig.pm
===================================================================
RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestConfig.pm,v
retrieving revision 1.83
retrieving revision 1.84
diff -u -r1.83 -r1.84
--- TestConfig.pm 2001/11/16 19:43:27 1.83
+++ TestConfig.pm 2001/11/17 02:09:30 1.84
@@ -726,10 +726,18 @@
s/@(\w+)@/$self->{vars}->{lc $1}/g;
}
-#XXX: probably have too many ways todo this by now, ho-hum
-sub configure_vhost {
- my($self, $pre, $module, $post) = @_;
+sub parse_vhost {
+ my($self, $line) = @_;
+ my($indent, $module);
+ if ($line =~ /^(\s*)<VirtualHost\s+(?:_default_:)?(\D+)\s*>\s*$/) {
+ $indent = $1 || "";
+ $module = $2;
+ }
+ else {
+ return undef;
+ }
+
#if module ends with _ssl it is either the ssl module itself
#or another module that has a port for itself and another
#for itself with SSLEngine On, see mod_echo in extra.conf.in for example
@@ -738,21 +746,54 @@
#don't allocate a port if this module is not configured
if ($module =~ /^mod_/ and not $self->{modules}->{$have_module}) {
- return join '', $pre, $module, $post;
+ return undef;
}
+ #allocate a port and configure this module into $self->{vhosts}
my $port = $self->new_vhost($module);
+
+ #extra config that should go *inside* the <VirtualHost ...>
+ my @in_config = ();
+
+ #extra config that should go *outside* the <VirtualHost ...>
+ my @out_config = ([Listen => $port]);
- join '', "Listen $port\n", $pre, $port, $post;
+ #there are two ways of building a vhost
+ #first is when we parse test .pm and .c files
+ #second is when we scan *.conf.in
+ my $form_postamble = sub {
+ for my $pair (@_) {
+ $self->postamble(@$pair);
+ }
+ };
+
+ my $form_string = sub {
+ my $indent = shift;
+ join "\n", map { "$indent@$_\n" } @_;
+ };
+
+ return {
+ port => $port,
+ #used when parsing .pm and .c test modules
+ in_postamble => sub { $form_postamble->(@in_config) },
+ out_postamble => sub { $form_postamble->(@out_config) },
+ #used when parsing *.conf.in files
+ in_string => $form_string->($indent x 2, @in_config),
+ out_string => $form_string->($indent, @out_config),
+ line => "$indent<VirtualHost _default_:$port>",
+ };
}
sub replace_vhost_modules {
my $self = shift;
- #example: <VirtualHost _default_:mod_proxy>
- s{^(\s*<VirtualHost\s+_default_:)(\D+)(\s*>\s*)}
- {
- $self->configure_vhost($1, $2, $3);
- }ie;
+
+ if (my $cfg = $self->parse_vhost($_)) {
+ $_ = '';
+ for my $key (qw(out_string line in_string)) {
+ next unless $cfg->{$key};
+ $_ .= "$cfg->{$key}\n";
+ }
+ }
}
sub replace_vars {
1.40 +7 -4 httpd-test/perl-framework/Apache-Test/lib/Apache/TestConfigPerl.pm
Index: TestConfigPerl.pm
===================================================================
RCS file: /home/cvs/httpd-test/perl-framework/Apache-Test/lib/Apache/TestConfigPerl.pm,v
retrieving revision 1.39
retrieving revision 1.40
diff -u -r1.39 -r1.40
--- TestConfigPerl.pm 2001/10/22 05:12:44 1.39
+++ TestConfigPerl.pm 2001/11/17 02:09:30 1.40
@@ -214,13 +214,16 @@
}
}
elsif ($directive =~ m/^<(\w+)/) {
+ my $cfg;
if ($directive eq '<VirtualHost') {
- $rest =~ s/>$//;
- my $port = $self->new_vhost($rest);
- $self->postamble(Listen => $port);
- $rest = "_default_:$port>";
+ if ($cfg = $self->parse_vhost($_)) {
+ my $port = $cfg->{port};
+ $rest = "_default_:$port>";
+ $cfg->{out_postamble}->();
+ }
}
$self->postamble($directive => $rest);
+ $cfg->{in_postamble}->() if $cfg;
my $end = "</$1>";
while (<$fh>) {
chomp;