last GET_CHILD ;
}
unless (-r $childfname) {
push(@$errlist, [{'path' => $childfname, 'tag' => $tagst,
'errmsg' => 'File is not readable by'
. ' current user.' } ] ) ;
last GET_CHILD ;
}
# Guard against include loops
if ($parents->{$childfname}) {
push(@$errlist, [{'path' => $childfname, 'tag' => $tagst,
'errmsg' => 'An "include" loop exists'
. ' involving this file.' } ] ) ;
last GET_CHILD ;
}
# Get the included file, with any error data
($childHTML, $childerrlist, $childiscgi)=
&read_expanded_file($childfname, $childURL, $parents) ;
# Log if there was any error reading the file
push(@$errlist, [{'path' => $childfname, 'tag' => $tagst,
'errmsg' => "Can't read file: $!." } ] )
unless defined($childHTML) ;
# Add any errors to the current (parent) error list
foreach my $error (@$childerrlist) {
unshift(@$error,
{ 'path' => $childfname, 'tag' => $tagst } ) ;
}
push(@$errlist, @$childerrlist) ;
# Parent is a CGI if any of its children is a CGI
$iscgi||= $childiscgi ;
} # GET_CHILD
$childHTML ; # final value to replace in main s/// construct
} # do {}
}gie ; # $HTML=~ s{} {}
} # if ($isshtml)
delete $parents->{$fname} ;
return($HTML, $errlist, $iscgi) ;
}
# Returns the contents of the named file, or undef on error.
sub read_file {
my($fname)= @_ ;
local(*F, $/) ;
undef $/ ;
open(F, "<$fname") || return undef ;
my($ret)= <F> ;
close(F) ;
return $ret ;
}
# Try to get the given URL with the given HTTP method, and return the
# status line, headers, and body.
# Set $url->{'status'} accordingly, and set $url->{'ishtml'} accordingly
# if Content-Type: header is returned.
# This is specific to this program, and calls the more general &get_url().
# This could be slightly more efficient if 302 or 303 was handled in the
# calling routine, where it could take advantage of a new URL being local.
sub load_url_using_HTTP {
my($url, $method)= @_ ;
my($status_line, $headers, $body) ;
# We should not get here if $file_check is set
die "mistakenly called load_url_using_HTTP($url->{'URL'})" if $file_check ;
GETFILE: {
($status_line, $headers, $body)=
&get_url( ($url->{'location'} || $url->{'URL'}), $method) ;
# If HEAD failed (as on some servers), sigh and use GET
($status_line, $headers, $body)=
&get_url( ($url->{'location'} || $url->{'URL'}), 'GET')
unless length($status_line) ;
($url->{'status'})= $status_line=~ m#^HTTP/[\d.]+\s+(.*)# ;
# 2-27-00 JSM: Allow old NCSA servers to not include the HTTP version.
if ($SUPPORT_NCSA_BUG and $url->{'status'} eq '') {
($url->{'status'})= $status_line=~ m#^HTTP(?:/[\d.]+)?\s+(.*)# ;
}
# Redirect to new location if status is 302 or 303
=10= |