| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Apache::GopherHandler; |
|
3
|
1
|
|
|
1
|
|
4168
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
39
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
45
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = 0.1; |
|
7
|
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
455
|
use Apache::Connection (); |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use APR::Socket (); |
|
10
|
|
|
|
|
|
|
use Apache::Const -compile => 'OK'; |
|
11
|
|
|
|
|
|
|
use Gopher::Server::ParseRequest; |
|
12
|
|
|
|
|
|
|
#use Gopher::Server::RequestHandler::File; |
|
13
|
|
|
|
|
|
|
use Apache::GopherHandler::TiedSocket; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my ( $doc_root, $server, $port ) = |
|
16
|
|
|
|
|
|
|
( '/noexists/', 'localhost', 70, ); |
|
17
|
|
|
|
|
|
|
my ( $handler ) = 'Gopher::Server::RequestHandler::File'; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
( $doc_root, $handler, $server, $port ) = |
|
20
|
|
|
|
|
|
|
map $Apache::GopherHandler::Config{$_}, |
|
21
|
|
|
|
|
|
|
qw( doc_root handler server port ); |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# A little sanity checking |
|
25
|
|
|
|
|
|
|
eval " require $handler "; |
|
26
|
|
|
|
|
|
|
die "Couldn't load a handler named '$handler': $@\n" if $@; |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
die "No directory '$doc_root'\n" unless -d $doc_root; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub handler |
|
32
|
|
|
|
|
|
|
{ |
|
33
|
|
|
|
|
|
|
my $c = shift; |
|
34
|
|
|
|
|
|
|
my $socket = $c->client_socket; |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $request_str = ''; |
|
37
|
|
|
|
|
|
|
while(1) { |
|
38
|
|
|
|
|
|
|
my $rlen = 1024; |
|
39
|
|
|
|
|
|
|
$socket->recv( my $buff, $rlen ); |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
last if $rlen <= 0; |
|
42
|
|
|
|
|
|
|
$request_str .= $buff; |
|
43
|
|
|
|
|
|
|
last if $buff =~ /[\r\n]+$/; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$request_str =~ tr/\r\n//d; |
|
47
|
|
|
|
|
|
|
my $request = Gopher::Server::ParseRequest->parse( $request_str ); |
|
48
|
|
|
|
|
|
|
my $handler = $handler->new({ |
|
49
|
|
|
|
|
|
|
root => $doc_root, |
|
50
|
|
|
|
|
|
|
host => $server, |
|
51
|
|
|
|
|
|
|
port => $port, |
|
52
|
|
|
|
|
|
|
}); |
|
53
|
|
|
|
|
|
|
my $response = $handler->process( $request ); |
|
54
|
|
|
|
|
|
|
tie *OUT, 'Apache::GopherHandler::TiedSocket' => $socket; |
|
55
|
|
|
|
|
|
|
$response->print_to( *OUT ); |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
return Apache::OK; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
|
61
|
|
|
|
|
|
|
__END__ |