DirectConnect/http.pm

filter: Statementstmt 33.3% 20 / 60 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 25 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 60.0% 6 / 10 Podpod 0.0% 0 / 1 totaltotal 19.4% 26 / 134 CC 24 SCAR 47.4
CC
24
Cov
19%
__ANON__
210.0
init
90.0
__ANON__
6.0
CRAP 114.5
« DirectConnect/clihub.pm ↑ Summary DirectConnect/nmdc.pm »
1 #$Id: http.pm 998 2013-08-14 12:21:20Z pro $ $URL: svn://svn.setun.net/dcppp/trunk/lib/Net/DirectConnect/http.pm $
2 package #hide from cpan
3 Net::DirectConnect::http;
4 1 ▶use Data::Dumper; #dev only
Subroutine BEGIN: called CC=1 SCAR=0.0
5 #$Data::Dumper::Sortkeys = 1;
6 #$Data::Dumper::Sortkeys = $Data::Dumper::Useqq = $Data::Dumper::Indent = 1;
7 1 ▶use Net::DirectConnect;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 #use Net::DirectConnect::hubcli;
9 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶no warnings qw(uninitialized);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶no if $] >= 5.017011, warnings => 'experimental::smartmatch';
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 our $VERSION = ( split( ' ', '$Revision: 998 $' ) )[1];
13 #our @ISA = ('Net::DirectConnect');
14 1 ▶use base 'Net::DirectConnect';
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 0 ▶sub init {
Subroutine init: not called CC=9 SCAR=45.0
Pod undocumented
17 0 my $self = shift;
18 #$self->log( 'dev', 'httpcli init' );
19 #%$self = ( %$self,
20 0 local %_ = (
21 #'incomingclass' => 'Net:DirectConnect::httpcli',
22 'auto_connect' => 0,
23 'auto_listen' => 0,
24 'protocol' => 'http',
25 #); $self->{$_} = $_{$_} for keys %_;
26 # local %_ = (
27 #'myport' => 80,
28 #'myport' => 443,
29 #modules => [],
30 #'myport_base' => 8000,
31 #'myport_random' => 99,
32 #'myport_tries' => 5,
33 'myport_inc' => 1,
34 #'HubName' => 'Net::DirectConnect test hub',
35 'allow' => '127.0.0.1',
36 'cmd_bef' => undef,
37 'cmd_aft' => "\n",
38 );
39 0 ▶ $self->{$_} //= $_{$_} for keys %_;
Condition0%0/3
$self->{$_} //= $_{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{$_} //= $_{$_}
$self->{$_} $_{$_}
Truth table0%0/3
A //= B
A= $self->{$_}B= $_{$_}
ABresult
1X1
011
000
40 0 local %_ = @_;
41 #warn "$_=$_{$_}";
42 0 $self->{$_} = $_{$_} for keys %_;
43 #$self->{$_} ||= $self->{'parent'}{$_} ||= {} for qw(peers peers_sid peers_cid want share_full share_tth);
44 0 ▶ $self->{$_} ||= $self->{'parent'}{$_} for qw(http_download http_control http_allow); #allow
Condition0%0/3
$self->{$_} ||= $self->{"parent"}{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{$_} ||= $self->{"parent"}{$_}
$self->{$_} $self->{"parent"}{$_}
Truth table0%0/3
A ||= B
A= $self->{$_}B= $self->{"parent"}{$_}
ABresult
1X1
011
000
45 #$self->baseinit();
46 #$self->{'parse'} ||= $self->{'parent'}{'parse'};
47 #$self->{'cmd'} ||= $self->{'parent'}{'cmd'};
48 0 ▶ $self->{'allow'} = $self->{http_allow} if defined $self->{http_allow};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"http_allow"} 0 0 0
49 0 ▶ $self->{'handler_int'}{'unknown'} ||= sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
50 0 ▶ my $self = shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
51 #$self->log( 'dev', "unknown1", Dumper \@_ );
52 0 ( $self->{http_headers}{ $_[0] } = $_[1] ) =~ s/^: |\s+$//g;
53 #};
54 0 ▶ };
Condition0%0/3
$self->{"handler_int"}{"unknown"} ||= sub { my $self = shift() if ref $_[0]; ($self->{"http_headers"}{$_[0]} = $_[1]) =~ s/^: |\s+$//g; }
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"handler_int"}{"unknown"} ||= sub { my $self = shift() if ref $_[0]; ($self->{"http_headers"}{$_[0]} = $_[1]) =~ s/^: |\s+$//g; }
$self->{"handler_int"}{"unknown"} sub { my $self = shift() if ref $_[0]; ($self->{"http_headers"}{$_[0]} = $_[1]) =~ s/^: |\s+$//g; }
Truth table0%0/3
A ||= B
A= $self->{"handler_int"}{"unknown"}B= sub { my $self = shift() if ref $_[0]; ($self->{"http_headers"}{$_[0]} = $_[1]) =~ s/^: |\s+$//g; }
ABresult
1X1
011
000
55 #$self->{'handler'}{ 'unknown'}||=sub {
56 #my $self = shift if ref $_[0];
57 #$self->log( 'dev', "unknown2", @_ );
58 #};
59 #};
60 #'GET' => sub {
61 $self->{'parse'} ||= {
62 0 ▶ 'DELLLLLLLnoGET' => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
63 0 ▶ my $self = shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
64 0 my ( $url, $prot ) = split /\s/, $_[0];
65 0 $self->log( 'dev', "get $url : $prot" );
66 0 $self->{'http_geturl'} = $url;
67 },
68 0 ▶ "\x0D" => sub { #$self->log('dev', 'can send'); },
Subroutine __ANON__: not called CC=14 SCAR=53.5
69 #'' => sub {
70 0 ▶ my $self = shift if ref $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] 0 0 0
71 #$self->log( 'dev', 'can send2', Dumper $self->{'handler_int'}, $self->{http_headers} );
72 0 ( $self->{'http_geturl'} ) = split ' ', $self->{http_headers}{GET};
73 0 ( $self->{'http_getfile'} ) = $self->{'http_geturl'} =~ m{^/(.+)};
74 0 my $c = "HTTP/1.1 200 OK" . "\nContent-Type: text/html; charset=utf-8\n\n";
75 0 ▶ if ( $self->{'http_control'} and $self->{'http_geturl'} eq '/' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->{'http_control'} and $self->{'http_geturl'} eq '/') { } 0 0 0
elsif ($self->{'http_download'} and my $full = $self->{'share_full'}{$self->{'http_getfile'}}) { } 0 0 0
elsif ($self->{'http_control'} and $self->{'http_geturl'} =~ m[^/dl/(.+)$]) { } 0 0 0
Condition0%0/3
$self->{"http_control"} and $self->{"http_geturl"} eq "/"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"http_control"} and $self->{"http_geturl"} eq "/"
$self->{"http_control"} $self->{"http_geturl"} eq "/"
Truth table0%0/3
A and B
A= $self->{"http_control"}B= $self->{"http_geturl"} eq "/"
ABresult
0X0
100
111
76 $c .= "<html><body>" . "clients:<br/>" . (
77 join ', ',
78 map {
79 "$_($self->{clients}{$_}{status}"
80 . (
81 0 ▶ !$self->{clients}{$_}{'filebytes'} ? () : ":$self->{clients}{$_}{'filebytes'}/$self->{clients}{$_}{'filetotal'}" )
Branch: 1 branch
BranchTrueFalseTotal
!$self->{'clients'}{$_}{'filebytes'} ? : 0 0 0
82 . ")"
83 0 } sort keys %{ $self->{clients} }
84 )
85 . "<hr/>peers:<br/>"
86 . (
87 join '<br/> ',
88 map {
89 join ' ', $_->{INF}{NI}, $_->{INF}{SS}, $_->{INF}{I4},
90 0 } sort {
91 $b->{INF}{SS} <=> $a->{INF}{SS}
92 0 } values %{ $self->{peers_cid} }
93 )
94 . "<pre>" #.Dumper($self->{peers})
95 #. "<pre>" . Dumper($self)
96 . "</html>";
97 ▶ } elsif ( $self->{'http_download'} and my $full = $self->{"share_full"}{ $self->{'http_getfile'} } ) {
Condition0%0/3
$self->{"http_download"} and my $full = $self->{"share_full"}{$self->{"http_getfile"}}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"http_download"} and my $full = $self->{"share_full"}{$self->{"http_getfile"}}
$self->{"http_download"} my $full = $self->{"share_full"}{$self->{"http_getfile"}}
Truth table0%0/3
A and B
A= $self->{"http_download"}B= my $full = $self->{"share_full"}{$self->{"http_getfile"}}
ABresult
0X0
100
111
98 0 my ($name) = $full =~ m{([^/]+)$};
99 0 my $size = -s $full;
100 0 my $sizep = $size + 1;
101 0 my ( $from, $to ) = $self->{http_headers}{Range} =~ /^bytes=(\d+)\-(\d*)/;
102 0 ▶ $to ||= $size if $from;
Branch: 1 branch
BranchTrueFalseTotal
if $from 0 0 0
Condition0%0/3
$to ||= $size
l!l&&r!l&&!r
000
MC/DC0%0/2
$to ||= $size
$to $size
Truth table0%0/3
A ||= B
A= $toB= $size
ABresult
1X1
011
000
103 0 ▶ my $type = { xml => 'text/xml' }->{ lc +( $name =~ m/\.(\w+)/ )[0] } || 'binary/octet-stream';
Condition0%0/2
{'xml', 'text/xml'}->{lc(($name =~ /\.(\w+)/)[0])} || 'binary/octet-stream'
l!l
00
MC/DC0%0/1
{'xml', 'text/xml'}->{lc(($name =~ /\.(\w+)/)[0])} || 'binary/octet-stream'
{'xml', 'text/xml'}->{lc(($name =~ /\.(\w+)/)[0])}
Truth table0%0/2
A
A= {'xml', 'text/xml'}->{lc(($name =~ /\.(\w+)/)[0])}
Aresult
11
00
104 0 ▶ $c =
Branch: 2 branches
BranchTrueFalseTotal
$from ? : 0 0 0
!$from ? : 0 0 0
105 "HTTP/1.1 "
106 . ( $from ? "206 Partial Content" : "200 OK" )
107 . "\nContent-Type: $type"
108 . "\nContent-Length: $size"
109 . "\nAccept-Ranges: bytes\n"
110 . ( !$from ? () : "Content-Range: bytes $from-$to/$sizep\n" )
111 . "Content-Disposition: attachment; filename=$name\n\n";
112 #$self->log( 'dev', "hdr[$c]" );
113 0 $self->send( Encode::encode 'utf8', $c, Encode::FB_WARN );
114 0 $self->file_send( $self->{"share_full"}{ $self->{'http_getfile'} }, $from, $to );
115 0 return;
116 #$c .= "gettii[$self->{'http_getfile'}]";
117 ▶ } elsif ( $self->{'http_control'} and $self->{'http_geturl'} =~ m{^/dl/(.+)$} ) {
Condition0%0/3
$self->{"http_control"} and $self->{"http_geturl"} =~ m[^/dl/(.+)$]
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"http_control"} and $self->{"http_geturl"} =~ m[^/dl/(.+)$]
$self->{"http_control"} $self->{"http_geturl"} =~ m[^/dl/(.+)$]
Truth table0%0/3
A and B
A= $self->{"http_control"}B= $self->{"http_geturl"} =~ m[^/dl/(.+)$]
ABresult
0X0
100
111
118 0 $self->{parent}{parent}->download($1);
119 0 $c .= "try dl [$1]";
120 }
121 #$c .= "<hr/><pre>" . Dumper( $self->{http_headers} );
122 0 $self->send( Encode::encode 'utf8', $c, Encode::FB_WARN );
123 0 $self->destroy();
124 },
125 0 ▶ };
Condition0%0/2
$self->{"parse"} ||= {"DELLLLLLLnoGET", sub { my $self = shift() if ref $_[0]; my($url, $prot) = split(/\s/, $_[0], 3); $self->log("dev", "get $url : $prot"); $self->{"http_geturl"} = $url; } , "\r", sub { my $self = shift() if ref $_[0]; ($self->{"http_geturl"}) = split(' ', $self->{"http_headers"}{"GET"}, 2); ($self->{"http_getfile"}) = $self->{"http_geturl"} =~ m[^/(.+)]; my $c = "HTTP/1.1 200 OK\nContent-Type: text/html; charset=utf-8\n\n"; if ($self->{"http_control"} and $self->{"http_geturl"} eq "/") { $c .= '<html><body>clients:<br/>' . join(", ", map({qq[$_($self->{"clients"}{$_}{"status"}] . (!$self->{"clients"}{$_}{"filebytes"} ? () : qq[:$self->{"clients"}{$_}{"filebytes"}/$self->{"clients"}{$_}{"filetotal"}]) . ')';} sort(keys %{$$self{"clients"};}))) . '<hr/>peers:<br/>' . join("<br/> ", map({join " ", $_->{"INF"}{"NI"}, $_->{"INF"}{"SS"}, $_->{"INF"}{"I4"};} (sort {$Net::DirectConnect::http::b->{"INF"}{"SS"} <=> $Net::DirectConnect::http::a->{"INF"}{"SS"};} values %{$$self{"peers_cid"};}))) . '<pre>' . "</html>"; } elsif ($self->{"http_download"} and my $full = $self->{"share_full"}{$self->{"http_getfile"}}) { my($name) = $full =~ m[([^/]+)$]; my $size = -s $full; my $sizep = $size + 1; my($from, $to) = $self->{"http_headers"}{"Range"} =~ /^bytes=(\d+)\-(\d*)/; $to ||= $size if $from; my $type = {"xml", "text/xml"}->{lc(($name =~ /\.(\w+)/)[0])} || "binary/octet-stream"; $c = 'HTTP/1.1 ' . ($from ? "206 Partial Content" : "200 OK") . "\nContent-Type: $type" . "\nContent-Length: $size" . "\nAccept-Ranges: bytes\n" . (!$from ? () : "Content-Range: bytes $from-$to/$sizep\n") . "Content-Disposition: attachment; filename=$name\n\n"; $self->send(&Encode::encode("utf8", $c, 6)); $self->file_send($self->{"share_full"}{$self->{"http_getfile"}}, $from, $to); return; } elsif ($self->{"http_control"} and $self->{"http_geturl"} =~ m[^/dl/(.+)$]) { $self->{"parent"}{"parent"}->download($1); $c .= "try dl [$1]"; } ; $self->send(&Encode::encode("utf8", $c, 6)); $self->destroy; } }
l!l
00
MC/DC0%0/1
$self->{"parse"} ||= {"DELLLLLLLnoGET", sub { my $self = shift() if ref $_[0]; my($url, $prot) = split(/\s/, $_[0], 3); $self->log("dev", "get $url : $prot"); $self->{"http_geturl"} = $url; } , "\r", sub { my $self = shift() if ref $_[0]; ($self->{"http_geturl"}) = split(' ', $self->{"http_headers"}{"GET"}, 2); ($self->{"http_getfile"}) = $self->{"http_geturl"} =~ m[^/(.+)]; my $c = "HTTP/1.1 200 OK\nContent-Type: text/html; charset=utf-8\n\n"; if ($self->{"http_control"} and $self->{"http_geturl"} eq "/") { $c .= '<html><body>clients:<br/>' . join(", ", map({qq[$_($self->{"clients"}{$_}{"status"}] . (!$self->{"clients"}{$_}{"filebytes"} ? () : qq[:$self->{"clients"}{$_}{"filebytes"}/$self->{"clients"}{$_}{"filetotal"}]) . ')';} sort(keys %{$$self{"clients"};}))) . '<hr/>peers:<br/>' . join("<br/> ", map({join " ", $_->{"INF"}{"NI"}, $_->{"INF"}{"SS"}, $_->{"INF"}{"I4"};} (sort {$Net::DirectConnect::http::b->{"INF"}{"SS"} <=> $Net::DirectConnect::http::a->{"INF"}{"SS"};} values %{$$self{"peers_cid"};}))) . '<pre>' . "</html>"; } elsif ($self->{"http_download"} and my $full = $self->{"share_full"}{$self->{"http_getfile"}}) { my($name) = $full =~ m[([^/]+)$]; my $size = -s $full; my $sizep = $size + 1; my($from, $to) = $self->{"http_headers"}{"Range"} =~ /^bytes=(\d+)\-(\d*)/; $to ||= $size if $from; my $type = {"xml", "text/xml"}->{lc(($name =~ /\.(\w+)/)[0])} || "binary/octet-stream"; $c = 'HTTP/1.1 ' . ($from ? "206 Partial Content" : "200 OK") . "\nContent-Type: $type" . "\nContent-Length: $size" . "\nAccept-Ranges: bytes\n" . (!$from ? () : "Content-Range: bytes $from-$to/$sizep\n") . "Content-Disposition: attachment; filename=$name\n\n"; $self->send(&Encode::encode("utf8", $c, 6)); $self->file_send($self->{"share_full"}{$self->{"http_getfile"}}, $from, $to); return; } elsif ($self->{"http_control"} and $self->{"http_geturl"} =~ m[^/dl/(.+)$]) { $self->{"parent"}{"parent"}->download($1); $c .= "try dl [$1]"; } ; $self->send(&Encode::encode("utf8", $c, 6)); $self->destroy; } }
$self->{"parse"}
Truth table0%0/2
A
A= $self->{"parse"}
Aresult
11
00
126 #$self->{'parser'} = sub { my $self = shift;$self->log('dev', 'myparser', Dumper @_); };
127 #$self->log( 'dev', 'httpcli inited' );
128 }
129 1 1;
« DirectConnect/clihub.pm ↑ Summary DirectConnect/nmdc.pm »