INET6Glue/FTP.pm

filter: Statementstmt 28.8% 26 / 90 Branchbran 7.1% 2 / 28 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 53.3% 8 / 15 Podpod n/a totaltotal 21.6% 36 / 166 CC 21 SCAR 31.3
CC
21
Cov
20%
__ANON__
56.0
__ANON__
30.0
__ANON__
20.0
CRAP 22.8
↑ Summary INET6Glue.pm »
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Net::INET6Glue::FTP;
4 1 our $VERSION = 0.5;
5  
6 ############################################################################
7 # implement EPRT, EPSV for Net::FTP to support IPv6
8 ############################################################################
9  
10 1 ▶use Net::INET6Glue::INET_is_INET6;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Net::FTP; # tested with version 2.77
Subroutine BEGIN: called CC=1 SCAR=0.0
12 BEGIN {
13 1 ▶ $Net::FTP::VERSION eq '2.77'
Subroutine BEGIN: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$Net::FTP::VERSION eq "2.77" or warn "Not tested with Net::FTP version $Net::FTP::VERSION" 1 0 1
14 or warn "Not tested with Net::FTP version $Net::FTP::VERSION";
15 }
16  
17 1 ▶use Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 ▶if ( defined &Net::FTP::_EPRT ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined &Net::FTP::_EPRT) { } 1 0 1
21 # Net::SSLGlue::FTP implements IPv6 too
22 1 warn "somebody else already implements FTP IPv6 support - skipping ".
23 __PACKAGE__."\n";
24  
25 } else {
26 # implement EPRT
27 *Net::FTP::_EPRT = sub {
28 0 ▶ shift->command("EPRT", @_)->response() == Net::FTP::CMD_OK
Subroutine __ANON__: not called CC=1 SCAR=6.9
29 0 };
30 *Net::FTP::eprt = sub {
31 0 ▶ @_ == 1 || @_ == 2 or croak 'usage: $ftp->eprt([PORT])';
Subroutine __ANON__: not called CC=7 SCAR=40.3
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 or @_ == 2 or croak("usage: \$ftp->eprt([PORT])") 0 0 0
Condition0%0/3
@_ == 1 or @_ == 2
l!l&&r!l&&!r
000
MC/DC0%0/2
@_ == 1 or @_ == 2
@_ == 1 @_ == 2
Truth table0%0/3
A or B
A= @_ == 1B= @_ == 2
ABresult
1X1
011
000
32 0 my ($ftp,$port) = @_;
33 0 delete ${*$ftp}{net_ftp_intern_port};
34 0 ▶ unless ($port) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($port) 0 0 0
35 0 my $listen = ${*$ftp}{net_ftp_listen} ||=
36 0 ▶ $Net::INET6Glue::INET_is_INET6::INET6CLASS->new(
Condition0%0/3
do { *$ftp }->{"net_ftp_listen"} ||= $Net::INET6Glue::INET_is_INET6::INET6CLASS->new("Listen", 1, "Timeout", $ftp->timeout, "LocalAddr", $ftp->sockhost)
l!l&&r!l&&!r
000
MC/DC0%0/2
do { *$ftp }->{"net_ftp_listen"} ||= $Net::INET6Glue::INET_is_INET6::INET6CLASS->new("Listen", 1, "Timeout", $ftp->timeout, "LocalAddr", $ftp->sockhost)
do { *$ftp }->{"net_ftp_listen"} $Net::INET6Glue::INET_is_INET6::INET6CLASS->new("Listen", 1, "Timeout", $ftp->timeout, "LocalAddr", $ftp->sockhost)
Truth table0%0/3
A ||= B
A= do { *$ftp }->{"net_ftp_listen"}B= $Net::INET6Glue::INET_is_INET6::INET6CLASS->new("Listen", 1, "Timeout", $ftp->timeout, "LocalAddr", $ftp->sockhost)
ABresult
1X1
011
000
37 Listen => 1,
38 Timeout => $ftp->timeout,
39 LocalAddr => $ftp->sockhost,
40 );
41 0 ${*$ftp}{net_ftp_intern_port} = 1;
42 0 ▶ my $fam = ($listen->sockdomain == AF_INET) ? 1:2;
Branch: 1 branch
BranchTrueFalseTotal
$listen->sockdomain == 2 ? : 0 0 0
43 0 $port = "|$fam|".$listen->sockhost."|".$listen->sockport."|";
44 }
45 0 my $ok = $ftp->_EPRT($port);
46 0 ▶ ${*$ftp}{net_ftp_port} = $port if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 0 0 0
47 0 return $ok;
48 0 };
49  
50 # implement EPSV
51 *Net::FTP::_EPSV = sub {
52 0 ▶ shift->command("EPSV", @_)->response() == Net::FTP::CMD_OK
Subroutine __ANON__: not called CC=1 SCAR=6.9
53 0 };
54 *Net::FTP::epsv = sub {
55 0 ▶ my $ftp = shift;
Subroutine __ANON__: not called CC=4 SCAR=30.0
56 0 ▶ @_ and croak 'usage: $ftp->epsv()';
Branch: 1 branch
BranchTrueFalseTotal
@_ and croak("usage: \$ftp->epsv()") 0 0 0
57 0 delete ${*$ftp}{net_ftp_intern_port};
58  
59 $ftp->_EPSV && $ftp->message =~ m{\(([\x33-\x7e])\1\1(\d+)\1\)}
60 0 ▶ ? ${*$ftp}{'net_ftp_pasv'} = $2
Branch: 1 branch
BranchTrueFalseTotal
$ftp->_EPSV && $ftp->message =~ /\(([\x33-\x7e])\1\1(\d+)\1\)/ ? : 0 0 0
Condition0%0/3
$ftp->_EPSV and $ftp->message =~ /\(([\x33-\x7e])\1\1(\d+)\1\)/
!ll&&!rl&&r
000
MC/DC0%0/2
$ftp->_EPSV and $ftp->message =~ /\(([\x33-\x7e])\1\1(\d+)\1\)/
$ftp->_EPSV $ftp->message =~ /\(([\x33-\x7e])\1\1(\d+)\1\)/
Truth table0%0/3
A and B
A= $ftp->_EPSVB= $ftp->message =~ /\(([\x33-\x7e])\1\1(\d+)\1\)/
ABresult
0X0
100
111
61 : undef;
62 0 };
63  
64 # redefine PORT and PASV so that they use EPRT and EPSV if necessary
65 1 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
66 0 my $old_port = \&Net::FTP::port;
67 *Net::FTP::port =sub {
68 0 ▶ goto &$old_port if $_[0]->sockdomain == AF_INET or @_<1 or @_>2;
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]->sockdomain == 2 or @_ < 1 or @_ > 2 0 0 0
Condition0%0/6
$_[0]->sockdomain == 2 or @_ < 1 or @_ > 2
l!l&&r!l&&!r
000
$_[0]->sockdomain == 2 or @_ < 1
l!l&&r!l&&!r
000
MC/DC0%0/3
$_[0]->sockdomain == 2 or @_ < 1 or @_ > 2
$_[0]->sockdomain == 2 @_ < 1 @_ > 2
Truth table0%0/4
A or B or C
A= $_[0]->sockdomain == 2B= @_ < 1C= @_ > 2
ABCresult
1XX1
01X1
0011
0000
69 0 goto &Net::FTP::eprt;
70 0 };
71  
72 0 my $old_pasv = \&Net::FTP::pasv;
73 *Net::FTP::pasv = sub {
74 0 ▶ goto &$old_pasv if $_[0]->sockdomain == AF_INET or @_<1 or @_>2;
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]->sockdomain == 2 or @_ < 1 or @_ > 2 0 0 0
Condition0%0/6
$_[0]->sockdomain == 2 or @_ < 1 or @_ > 2
l!l&&r!l&&!r
000
$_[0]->sockdomain == 2 or @_ < 1
l!l&&r!l&&!r
000
MC/DC0%0/3
$_[0]->sockdomain == 2 or @_ < 1 or @_ > 2
$_[0]->sockdomain == 2 @_ < 1 @_ > 2
Truth table0%0/4
A or B or C
A= $_[0]->sockdomain == 2B= @_ < 1C= @_ > 2
ABCresult
1XX1
01X1
0011
0000
75 0 goto &Net::FTP::epsv;
76 0 };
77  
78 # redefined _dataconn to make use of the data it got from EPSV
79 # copied and adapted from Net::FTP::_dataconn
80 0 my $old_dataconn = \&Net::FTP::_dataconn;
81 *Net::FTP::_dataconn = sub {
82 0 ▶ goto &$old_dataconn if $_[0]->sockdomain == AF_INET;
Subroutine __ANON__: not called CC=5 SCAR=34.0
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]->sockdomain == 2 0 0 0
83 0 my $ftp = shift;
84  
85 0 my $pkg = "Net::FTP::" . $ftp->type;
86 0 eval "require $pkg";
87 0 $pkg =~ s/ /_/g;
88 0 delete ${*$ftp}{net_ftp_dataconn};
89  
90 0 my $data;
91 0 ▶ if ( my $port = ${*$ftp}{net_ftp_pasv} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $port = do { *$ftp }->{'net_ftp_pasv'}) { } 0 0 0
elsif (my $listen = delete do { *$ftp }->{'net_ftp_listen'}) { } 0 0 0
92 $data = $pkg->new(
93 PeerAddr => $ftp->peerhost,
94 PeerPort => $port,
95 0 LocalAddr => ${*$ftp}{net_ftp_localaddr},
96 0 );
97 0 } elsif (my $listen = delete ${*$ftp}{net_ftp_listen}) {
98 0 $data = $listen->accept($pkg);
99 0 close($listen);
100 }
101  
102 0 ▶ return if ! $data;
Branch: 1 branch
BranchTrueFalseTotal
unless $data 0 0 0
103  
104 0 $data->timeout($ftp->timeout);
105 0 ${*$ftp}{net_ftp_dataconn} = $data;
106 0 ${*$data} = "";
107 0 ${*$data}{net_ftp_cmd} = $ftp;
108 0 ${*$data}{net_ftp_blksize} = ${*$ftp}{net_ftp_blksize};
109 0 return $data;
110 0 };
111 }
112  
113 1 1;
114  
115 =head1 NAME
116  
117 Net::INET6Glue::FTP - adds IPv6 support to L<Net::FTP> by hotpatching
118  
119 =head1 SYNOPSIS
120  
121 use Net::INET6Glue::FTP;
122 use Net::FTP;
123 my $ftp = Net::FTP->new( '::1' );
124 $ftp->login(...)
125  
126 =head1 DESCRIPTION
127  
128 This module adds support for IPv6 by hotpatching support for EPRT and EPSV
129 commands into L<Net::FTP> and hotpatching B<pasv>, B<port> and B<_dataconn>
130 methods to make use of EPRT and EPSV on IPv6 connections.
131  
132 It also includes L<Net::INET6Glue::INET_is_INET6> to make the L<Net::FTP>
133 sockets IPv6 capable.
134  
135 =head1 COPYRIGHT
136  
137 This module is copyright (c) 2008..2014, Steffen Ullrich.
138 All Rights Reserved.
139 This module is free software. It may be used, redistributed and/or modified
140 under the same terms as Perl itself.
↑ Summary INET6Glue.pm »