| 1 | package Net::Gnutella::Connection; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use Net::Gnutella::Packet::Ping; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Net::Gnutella::Packet::Pong; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Net::Gnutella::Packet::Push; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Net::Gnutella::Packet::Query; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Net::Gnutella::Packet::Reply; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Net::Gnutella::Event; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use HTTP::Request; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use HTTP::Date; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use HTTP::Status; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use LWP::MediaTypes qw(guess_media_type); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use URI::URL; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use IO::File; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Carp qw(carp croak confess); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use vars qw/$VERSION $AUTOLOAD/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | $VERSION = $VERSION = "0.1"; | |||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # Use AUTOHANDLER to supply generic attribute methods | ||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 0 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | my $attr = $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | $attr =~ s/.*:://; | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | return unless $attr =~ /[^A-Z]/; # skip DESTROY and all-cap methods | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | confess sprintf "invalid attribute method: %s->%s()", ref($self), $attr unless exists $self->{_attr}->{lc $attr}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | ▶ | $self->{_attr}->{lc $attr} = shift if @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 0 | return $self->{_attr}->{lc $attr}; | |||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub disconnect { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
disconnect: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | my ($self, $type) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | printf STDERR "+ Disconnecting socket (%s)\n", $type if $self->debug; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if ($type) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my $event = Net::Gnutella::Event->new( | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | from => $self, | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | type => $type, | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | $self->parent->_handler($event); | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | $self->parent->_remove_fh($self->socket, "rw"); | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | $self->readbuf(""); | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | $self->writebuf(""); | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | $self->connected(0); | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | $self->socket(""); | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # ->forward( PACKET [, REPLY_PATH ] ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # Composes the packet and delivers it to all other ESTABLISHED connections | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | sub forward { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
forward: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | my ($self, $packet, $path) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | unless ($packet && ref $packet) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$packet and ref $packet
MC/DC0%0/2
$packet and ref $packet
$packet
ref $packet
Truth table0%0/3
A and B
A= $packetB= ref $packet
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | carp "Invalid argument to Net::Gnutella::Connection->forward"; | |||||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my $data = $packet->format; | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | my $head = pack("L4CCCL", @{ $packet->msgid }, $packet->function, $packet->ttl, $packet->hops, length $data); | |||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | if ($path) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if ($path ne $self) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | printf STDERR " - Returning down path to %s\n", $path->ip if $self->debug >= 2; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | $path->_write_wrapper($head.$data); | |||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | foreach my $conn ($self->parent->connections) { | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | next if $conn eq $self; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | next unless $conn->connected; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | printf STDERR " - Forwarding to %s\n", $conn->ip if $self->debug >= 2; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $conn->_write_wrapper($head.$data); | |||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub is_outgoing { $_[0]->connected == 1 } # Outgoing | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_outgoing: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub is_incoming { $_[0]->connected == 2 } # Incoming | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_incoming: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | sub is_established { $_[0]->connected == 3 } # Gnutella DATA Stream | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_established: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | sub is_http { $_[0]->connected == 4 } # HTTP Serving | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_http: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | sub is_upload { $_[0]->connected == 5 } # Sending file | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_upload: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my $proto = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | my $parent = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my $self = { | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | _handler => {}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 98 | _attr => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | parent => $parent, | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | debug => $parent->debug, | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | timeout => $parent->timeout, | ||||||||||||||||||||||||||||||||||||||||||||||
| 102 | socket => undef, | ||||||||||||||||||||||||||||||||||||||||||||||
| 103 | ip => '', | ||||||||||||||||||||||||||||||||||||||||||||||
| 104 | connected => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | readbuf => '', | ||||||||||||||||||||||||||||||||||||||||||||||
| 106 | writebuf => '', | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | error => '', | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | allow => 0, | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | msgid => [], | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | _msgid => {}, | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | bless $self, $proto; | |||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | foreach my $key (keys %args) { | |||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my $lkey = lc $key; | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | $self->$lkey($args{$key}); | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | if ($self->connected and $self->socket) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->connected and $self->socket
MC/DC0%0/2
$self->connected and $self->socket
$self->connected
$self->socket
Truth table0%0/3
A and B
A= $self->connectedB= $self->socket
| |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | $self->parent->_add_fh($self->socket, $self->can("_read_socket"), "r", $self); | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | sub send_error { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_error: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my ($self, $status, $error) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | unless ($self->is_http) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | croak "Invalid state for ->send_error"; | |||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | $status ||= RC_BAD_REQUEST; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$status ||= 400
MC/DC0%0/1
$status ||= 400
$status
Truth table0%0/2
A
A= $status
| |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | $error ||= ""; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$error ||= ""
MC/DC0%0/1
$error ||= ""
$error
Truth table0%0/2
A
A= $error
| |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | my $message = status_message($status); | |||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | my $CRLF = "\r\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | my $ip = "Unknown"; | |||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | my $port = "Unknown"; | |||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my $body = <<EOT; | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> | ||||||||||||||||||||||||||||||||||||||||||||||
| 147 | <HTML><HEAD> | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | <TITLE>$status $message</TITLE> | ||||||||||||||||||||||||||||||||||||||||||||||
| 149 | </HEAD><BODY> | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | <H1>$message</H1> | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | $error<BR><BR> | ||||||||||||||||||||||||||||||||||||||||||||||
| 152 | <ADDRESS><A HREF="http://gnutella.habitue.net">Net::Gnutella</A> $VERSION Server at $ip Port $port</ADDRESS> | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | </BODY></HTML> | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | EOT | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | my $head; | |||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | $head .= sprintf "%s %s %s%s", "HTTP/1.0", $status, $message, $CRLF; | |||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | $head .= sprintf "Date: %s%s", time2str(time), $CRLF; | |||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | $head .= sprintf "Server: %s/%s%s", "Net-Gnutella", $VERSION, $CRLF; | |||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | $head .= sprintf "Content-Type: %s%s", "text/html", $CRLF; | |||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | $head .= sprintf "Content-Length: %s%s", length($body), $CRLF; | |||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | $head .= sprintf "%s", $CRLF; | |||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | $self->_write_wrapper($head.$body); | |||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | sub send_file { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_file: not called CC=14 SCAR=53.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | my ($self, $file, $offset) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | unless ($self->is_http) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | croak "Invalid state for ->send_file"; | |||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | ▶ | if (-f $file) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | my ($ct, $ce) = guess_media_type($file); | |||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | my ($size, $mtime) = (stat _)[7,9]; | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | ▶ | my $fh = new IO::File $file or | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 181 | return $self->send_error(RC_FORBIDDEN); | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | binmode($fh); | |||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | if ($offset && $offset > $size) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
$offset and $offset > $size
MC/DC0%0/2
$offset and $offset > $size
$offset
$offset > $size
Truth table0%0/3
A and B
A= $offsetB= $offset > $size
| |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | $offset = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 187 | } elsif ($offset) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | $fh->seek($offset, 0) or $offset = 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | my $status = $offset ? RC_PARTIAL_CONTENT : RC_OK; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | my $message = status_message($status); | |||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | my $CRLF = "\r\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | my $head; | |||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | $head .= sprintf "%s %s %s%s", "HTTP/1.0", $status, $message, $CRLF; | |||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | $head .= sprintf "Date: %s%s", time2str(time), $CRLF; | |||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | $head .= sprintf "Server: %s/%s%s", "Net-Gnutella", $VERSION, $CRLF; | |||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | $head .= sprintf "Content-Type: %s%s", $ct, $CRLF; | |||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | $head .= sprintf "Content-Encoding: %s%s", $ce, $CRLF if $ce; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | $head .= sprintf "Content-Length: %d%s", $offset ? $size - $offset : $size, $CRLF if $size; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | $head .= sprintf "Content-Range: bytes %d-%d/%d%s", $offset, $size-1, $size, $CRLF if $offset; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | $head .= sprintf "Last-Modified: %s%s", time2str($mtime), $CRLF if $mtime; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | $head .= sprintf "%s", $CRLF; | |||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | $self->_write_wrapper($head, $fh); | |||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | $self->connected(5); | |||||||||||||||||||||||||||||||||||||||||||||
| 208 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | return $self->send_error(RC_NOT_FOUND); | |||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | sub send_packet { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_packet: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | my ($self, $packet) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | unless ($self->is_established) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | croak "Invalid state for ->send_packet"; | |||||||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | unless ($packet && ref $packet) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$packet and ref $packet
MC/DC0%0/2
$packet and ref $packet
$packet
ref $packet
Truth table0%0/3
A and B
A= $packetB= ref $packet
| |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | carp "Invalid argument to Net::Gnutella::Connection->send_packet"; | |||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | printf STDERR "+ Sending packet '%s'\n", ref($packet) if $self->debug >= 2; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | my @msgid = @{ $packet->msgid }; | |||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | unless (scalar @msgid) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | @msgid = $self->_new_msgid; | |||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | my $data = $packet->format; | |||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | my $head = pack("L4CCCL", @msgid, $packet->function, $packet->ttl, $packet->hops, length $data); | |||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | $self->parent->_msgid_source(\@msgid, $self); | |||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | $self->_write_wrapper($head.$data); | |||||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | return \@msgid; | |||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | sub send_page { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
send_page: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | my ($self, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | unless ($self->is_http) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | croak "Invalid state in ->send_page"; | |||||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | my $status = RC_OK; | |||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | my $message = status_message($status); | |||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | my $CRLF = "\r\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | my $head; | |||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | $head .= sprintf "%s %s %s%s", "HTTP/1.0", $status, $message, $CRLF; | |||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | $head .= sprintf "Date: %s%s", time2str(time), $CRLF; | |||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | $head .= sprintf "Server: %s/%s%s", "Net-Gnutella", $VERSION, $CRLF; | |||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | $head .= sprintf "Content-Type: %s%s", "text/html", $CRLF; | |||||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | $head .= sprintf "Content-Length: %d%s", length($data), $CRLF; | |||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | $head .= sprintf "%s", $CRLF; | |||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | $self->_write_wrapper($head.$data); | |||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | sub _default { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_default: not called CC=19 SCAR=59.4
| |||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | my $event = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | my $type = $event->type; | |||||||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | my $packet = $event->packet; | |||||||||||||||||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | printf STDERR "%s->%s: Handling event '%s'\n", ref($self), "_default", $type if $self->debug; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | unless ($packet and ref($packet) =~ /^Net::Gnutella::Packet::/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$packet and ref($packet) =~ /^Net::Gnutella::Packet::/
MC/DC0%0/2
$packet and ref($packet) =~ /^Net::Gnutella::Packet::/
$packet
ref($packet) =~ /^Net::Gnutella::Packet::/
Truth table0%0/3
A and B
A= $packetB= ref($packet) =~ /^Net::Gnutella::Packet::/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ▶ | if ($packet->hops > 7) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | printf STDERR "+ Not forwarding, large hop count (%s)\n", $packet->hops if $self->debug; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | if ($packet->ttl > 50) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | ▶ | printf STDERR "+ Not forwarding, large ttl (%s)\n", $packet->ttl if $self->debug; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | ▶ | if ($packet->ttl > 7) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | $packet->ttl(7); | |||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | ▶ | if ($packet->ttl <= 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | printf STDERR "+ Not forwarding, ttl <= 0 (%s)\n", $packet->ttl if $self->debug; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 296 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | $packet->ttl($packet->ttl - 1); | |||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | $packet->hops($packet->hops + 1); | |||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | if ($type eq "pong") { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | $self->parent->_host_cache( join(":", $packet->ip_as_string, $packet->port) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||
| 305 | # Drop any routed replies which we haven't seen | ||||||||||||||||||||||||||||||||||||||||||||||
| 306 | # Drop any duplicate packets | ||||||||||||||||||||||||||||||||||||||||||||||
| 307 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | ▶ | if ($type =~ /^(ping|query|push)$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | if ($self->parent->_msgid_source($packet->msgid)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | return; # duplicate | |||||||||||||||||||||||||||||||||||||||||||||
| 311 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | $self->parent->_msgid_source($packet->msgid, $self); | |||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 314 | } elsif ($type =~ /^(pong|reply)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | unless ($self->parent->_msgid_source($packet->msgid)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | ▶ | printf STDERR "+ Not forwarding, unseen msgid to routed type (%s)\n", join(":", @{$packet->msgid}) if $self->debug; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||
| 321 | # If the packet is a routed reply (pong and reply) and it didn't originate | ||||||||||||||||||||||||||||||||||||||||||||||
| 322 | # from this connection, forward it to the other connection. | ||||||||||||||||||||||||||||||||||||||||||||||
| 323 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 324 | # Otherwise, throw it at all the connections (broadcast). | ||||||||||||||||||||||||||||||||||||||||||||||
| 325 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | ▶ | if ($type =~ /^(pong|reply)$/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | my $conn = $self->parent->_msgid_source($packet->msgid); | |||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | $self->forward($packet, $conn); | |||||||||||||||||||||||||||||||||||||||||||||
| 330 | } elsif ($type =~ /^(ping|push|query)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | $self->forward($packet); | |||||||||||||||||||||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | sub _new_msgid { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_new_msgid: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | my $msgid = $self->msgid; | |||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | if (scalar @$msgid) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | $self->msgid([ $msgid->[0], $msgid->[1], $msgid->[2], ++$msgid->[3] ]); | |||||||||||||||||||||||||||||||||||||||||||||
| 343 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | $msgid = [ int rand(65536**2), int rand(65536**2), int rand(65536**2), int rand(65536**2) ]; | |||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 0 | $self->msgid($msgid); | |||||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | return wantarray ? @$msgid : $msgid; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | sub _read_socket { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_read_socket: not called CC=39 SCAR=73.5
| |||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | my $buf = $self->readbuf; | |||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | local $SIG{PIPE} = 'IGNORE'; | |||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | if ($self->is_outgoing) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | my $ret = $self->socket->sysread($buf, 13, length $buf); | |||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | ▶ | if ($ret == 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | $self->disconnect; | |||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | $self->readbuf($buf); | |||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | if ($buf eq "GNUTELLA OK\n\n") { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | $self->readbuf(""); | |||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | $self->connected(3); # ESTABLISHED | |||||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | my $event = Net::Gnutella::Event->new( | |||||||||||||||||||||||||||||||||||||||||||||
| 373 | from => $self, | ||||||||||||||||||||||||||||||||||||||||||||||
| 374 | type => "connected", | ||||||||||||||||||||||||||||||||||||||||||||||
| 375 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | $self->parent->_handler($event); | |||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | ▶ | if (length $buf >= 13) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | $self->error("Invalid response"); | |||||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | $self->disconnect; | |||||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 386 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 387 | } elsif ($self->is_incoming) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 0 | my $ret = $self->socket->sysread($buf, 1, length $buf); | |||||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | ▶ | if ($ret == 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | $self->disconnect; | |||||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | $self->readbuf($buf); | |||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | ▶ | if ($buf =~ /^\w+[^\012]+HTTP\/\d+\.\d+\015?\012/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | ▶ | if ($buf =~ /\015?\012\015?\012/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | ▶ | unless ($self->allow & 2) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | $self->disconnect; | |||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | $self->readbuf(""); | |||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | $self->connected(4); # HTTP | |||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | unless ($buf =~ s/^(\w+)[ \t]+(.+)[ \t]+(HTTP\/\d+\.\d+)[^\012]*\012//) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | $self->send_error(400); # BAD_REQUEST | |||||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | $self->error("Bad request line"); | |||||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | my $url = URI::URL->new($2); | |||||||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | my $request = HTTP::Request->new($1, $url); | |||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | my ($key, $val); | |||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | ▶ | HEADER: while ($buf =~ s/^([^\012]*)\012//) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | $_ = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | s/\015$//; | |||||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | ▶ | if (/^([\w\-]+)\s*:\s*(.*)/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | ▶ | $request->push_header($key, $val) if $key; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | ($key, $val) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||||||
| 425 | } elsif (/^\s+(.*)/) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | $val .= " $1"; | |||||||||||||||||||||||||||||||||||||||||||||
| 427 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | last HEADER; | |||||||||||||||||||||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 430 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | ▶ | $request->push_header($key, $val) if $key; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | my $event = Net::Gnutella::Event->new( | |||||||||||||||||||||||||||||||||||||||||||||
| 435 | from => $self, | ||||||||||||||||||||||||||||||||||||||||||||||
| 436 | type => "download_req", | ||||||||||||||||||||||||||||||||||||||||||||||
| 437 | packet => $request, | ||||||||||||||||||||||||||||||||||||||||||||||
| 438 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | $self->parent->_handler($event); | |||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 443 | } elsif (length($buf) > 1*1024) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | $self->disconnect; | |||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | $self->error("Very long header"); | |||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 448 | } elsif ($buf =~ /^GNUTELLA CONNECT\/(\d+\.\d+)\015?\012\015?\012/) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | if ($1 le "0.4") { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | ▶ | unless ($self->allow & 1) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | $self->disconnect; | |||||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | $self->readbuf(""); | |||||||||||||||||||||||||||||||||||||||||||||
| 456 | 0 | $self->connected(3); # ESTABLISHED | |||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | $self->_write_wrapper("GNUTELLA OK\n\n"); | |||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | my $event = Net::Gnutella::Event->new( | |||||||||||||||||||||||||||||||||||||||||||||
| 461 | from => $self, | ||||||||||||||||||||||||||||||||||||||||||||||
| 462 | type => "connected", | ||||||||||||||||||||||||||||||||||||||||||||||
| 463 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 0 | $self->parent->_handler($event); | |||||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 468 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | $self->disconnect; | |||||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 472 | } elsif (length($buf) > 1*1024) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 0 | $self->disconnect; | |||||||||||||||||||||||||||||||||||||||||||||
| 474 | 0 | $self->error("Very long first line"); | |||||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 477 | } elsif ($self->is_established) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 0 | my $ret = $self->socket->sysread($buf, 256, length $buf); | |||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | ▶ | if ($ret == 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 0 | $self->disconnect("disconnect"); | |||||||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | $self->readbuf($buf); | |||||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | ▶ | printf STDERR " - Read %d bytes, buffer has %d bytes\n", $ret, length $buf if $self->debug; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||||||
| 489 | PROCESS: { | ||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | ▶ | if (length $buf < 23) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | last PROCESS; | |||||||||||||||||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | my @msgid = unpack("L4", substr($buf, 0, 16)); | |||||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | my $func = unpack("C", substr($buf, 16, 1)); | |||||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | my $ttl = unpack("C", substr($buf, 17, 1)); | |||||||||||||||||||||||||||||||||||||||||||||
| 497 | 0 | my $hops = unpack("C", substr($buf, 18, 1)); | |||||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | my $len = unpack("L", substr($buf, 19, 4)); | |||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 0 | ▶ | if (length($buf) < 23+$len) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | last PROCESS; | |||||||||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | my $head = substr($buf, 0, 23, ''); | |||||||||||||||||||||||||||||||||||||||||||||
| 505 | 0 | my $data = substr($buf, 0, $len, ''); | |||||||||||||||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | ▶ | printf STDERR " - Full packet read, %d bytes left\n", length $buf if $self->debug; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 0 | my $class; | |||||||||||||||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | ▶ | if ($func == 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | ▶ | goto PROCESS if $len != 0; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | $class = "Net::Gnutella::Packet::Ping"; | |||||||||||||||||||||||||||||||||||||||||||||
| 514 | } elsif ($func == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | ▶ | goto PROCESS if $len != 14; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | $class = "Net::Gnutella::Packet::Pong"; | |||||||||||||||||||||||||||||||||||||||||||||
| 517 | } elsif ($func == 64) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | ▶ | goto PROCESS if $len != 26; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | $class = "Net::Gnutella::Packet::Push"; | |||||||||||||||||||||||||||||||||||||||||||||
| 520 | } elsif ($func == 128) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 0 | ▶ | goto PROCESS if $len >= 257; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | $class = "Net::Gnutella::Packet::Query"; | |||||||||||||||||||||||||||||||||||||||||||||
| 523 | } elsif ($func == 129) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | ▶ | goto PROCESS if $len >= 67_075; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | $class = "Net::Gnutella::Packet::Reply"; | |||||||||||||||||||||||||||||||||||||||||||||
| 526 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | goto PROCESS; | |||||||||||||||||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | my $packet = $class->new( | |||||||||||||||||||||||||||||||||||||||||||||
| 531 | Msgid => \@msgid, | ||||||||||||||||||||||||||||||||||||||||||||||
| 532 | Function => $func, | ||||||||||||||||||||||||||||||||||||||||||||||
| 533 | TTL => $ttl, | ||||||||||||||||||||||||||||||||||||||||||||||
| 534 | Hops => $hops, | ||||||||||||||||||||||||||||||||||||||||||||||
| 535 | Parse => $data, | ||||||||||||||||||||||||||||||||||||||||||||||
| 536 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | my $event = Net::Gnutella::Event->new( | |||||||||||||||||||||||||||||||||||||||||||||
| 539 | from => $self, | ||||||||||||||||||||||||||||||||||||||||||||||
| 540 | type => $func, | ||||||||||||||||||||||||||||||||||||||||||||||
| 541 | packet => $packet, | ||||||||||||||||||||||||||||||||||||||||||||||
| 542 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 0 | $self->parent->_handler($event); | |||||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | goto PROCESS; | |||||||||||||||||||||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | ▶ | printf STDERR " - buffer has %d bytes\n\n", length $buf if $self->debug; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | $self->readbuf($buf); | |||||||||||||||||||||||||||||||||||||||||||||
| 552 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | my $ret = $self->socket->sysread($buf, 16*1024, length($buf)); | |||||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | ▶ | if ($self->is_upload) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 0 | $self->disconnect("upload_error"); | |||||||||||||||||||||||||||||||||||||||||||||
| 557 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 0 | $self->disconnect; | |||||||||||||||||||||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 0 | ▶ | sub _write_socket { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_write_socket: not called CC=12 SCAR=50.5
| |||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | my ($self, $sock, $fh) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 567 | 0 | my $buf = $self->writebuf; | |||||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 0 | local $SIG{PIPE} = 'IGNORE'; | |||||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | ▶ | printf STDERR " - Writing to FH, bytes in buffer: %s\n", length($buf) if $self->debug; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | ▶ | if (length($buf) == 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 574 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | my $len = $self->socket->syswrite($buf, length $buf); | |||||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | ▶ | if ($len == 0) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 0 | $self->disconnect; | |||||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 0 | substr($buf, 0, $len, ''); | |||||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | ▶ | printf STDERR " - Wrote %d bytes, %d bytes left\n", $len, length($buf) if $self->debug; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 0 | ▶ | if ($self->is_upload and defined $fh) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->is_upload and defined $fh
MC/DC0%0/2
$self->is_upload and defined $fh
$self->is_upload
defined $fh
Truth table0%0/3
A and B
A= $self->is_uploadB= defined $fh
| |||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 0 | printf "Buf length %d, pos %d\n", length $buf, tell($fh); | |||||||||||||||||||||||||||||||||||||||||||||
| 590 | 0 | my $read = sysread($fh, $buf, (16*1024)-length($buf), length($buf)); | |||||||||||||||||||||||||||||||||||||||||||||
| 591 | 0 | printf "Reading [%s] [%d] [%d]\n", $fh, $read, tell($fh); | |||||||||||||||||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | $self->writebuf($buf); | |||||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | ▶ | if (length($buf)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 597 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 598 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 599 | |||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | $self->parent->_remove_fh($self->socket, "w"); | |||||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 0 | ▶ | if ($self->is_upload and $fh and ref($fh) eq "IO::File") { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/6
$self->is_upload and $fh and ref $fh eq "IO::File"
$self->is_upload and $fh
MC/DC0%0/3
$self->is_upload and $fh and ref $fh eq "IO::File"
$self->is_upload
$fh
ref $fh eq "IO::File"
Truth table0%0/4
A and B and C
A= $self->is_uploadB= $fhC= ref $fh eq "IO::File"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | $self->disconnect("download_complete"); | |||||||||||||||||||||||||||||||||||||||||||||
| 604 | } elsif ($self->is_http) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 0 | $self->disconnect; | |||||||||||||||||||||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 607 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 608 | |||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | ▶ | sub _write_wrapper { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_write_wrapper: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 0 | my ($self, $data, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 611 | 0 | my $buf = $self->writebuf; | |||||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | $self->writebuf($buf.$data); | |||||||||||||||||||||||||||||||||||||||||||||
| 614 | 0 | $self->parent->_add_fh($self->socket, $self->can("_write_socket"), "w", $self, @args); | |||||||||||||||||||||||||||||||||||||||||||||
| 615 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 616 | |||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||