Raw.pm

filter: Statementstmt 56.9% 152 / 267 Branchbran 37.5% 51 / 136 Conditioncond 33.0% 33 / 100 MC/DCmcdc 5.6% 3 / 53 Subroutinesub 76.9% 20 / 26 Podpod 27.2% 3 / 11 totaltotal 44.1% 262 / 593 CC 111 SCAR 46.2
CC
111
Cov
47%
www_whois_query
306.0
recursive_whois
173.1
whois_query
75.3
CRAP 101.5
« Raw/Common.pm ↑ Summary Raw/Data.pm »
1 package Net::Whois::Raw;
2 4 $Net::Whois::Raw::VERSION = '2.99044';
3 # ABSTRACT: Get Whois information of domains and IP addresses.
4  
5 4 require 5.008_001;
6 4 ▶use Net::Whois::Raw::Common ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Net::Whois::Raw::Data ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use IO::Socket::IP;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 4 our @EXPORT = qw( whois get_whois );
18  
19 4 our ($OMIT_MSG, $CHECK_FAIL, $CHECK_EXCEED, $CACHE_DIR, $TIMEOUT, $DEBUG) = (0) x 7;
20  
21 4 our $CACHE_TIME = 60;
22 4 our $SET_CODEPAGE = '';
23 4 our $SILENT_MODE = 0;
24 4 our $QUERY_SUFFIX = '';
25  
26 4 our (%notfound, %strip, @SRC_IPS, %POSTPROCESS);
27  
28 # internal variable, used for save whois_server->ip relations
29 4 my $_IPS = {};
30  
31 4 our $class = __PACKAGE__;
32  
33 4 my $last_cache_clear_time;
34  
35 0 ▶sub whois_config {
Subroutine whois_config: not called CC=3 SCAR=18.7
Pod undocumented
36 0 my ($par) = @_;
37 0 my @parnames = qw(OMIT_MSG CHECK_FAIL CHECK_EXCEED CACHE_DIR CACHE_TIME TIMEOUT @SRC_IPS);
38 0 foreach my $parname (@parnames) {
39 0 ▶ if (exists($par->{$parname})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $par->{$parname}) 0 0 0
40 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
41 0 ${$parname} = $par->{$parname};
42 }
43 }
44 }
45  
46 0 ▶sub whois_config_data {
Subroutine whois_config_data: not called CC=3 SCAR=18.7
Pod undocumented
47 0 my $net_whois_raw_data = shift;
48  
49 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
50  
51 0 foreach my $k (keys %$net_whois_raw_data) {
52 0 %{'Net::Whois::Raw::Data::'.$k} = (
53 0 %{'Net::Whois::Raw::Data::'.$k},
54 0 ▶ %{ $net_whois_raw_data->{ $k } || {} },
Condition0%0/2
$net_whois_raw_data->{$k} || {}
l!l
00
MC/DC0%0/1
$net_whois_raw_data->{$k} || {}
$net_whois_raw_data->{$k}
Truth table0%0/2
A
A= $net_whois_raw_data->{$k}
Aresult
11
00
55 );
56 }
57 }
58  
59 # get cached whois
60 2 ▶sub whois {
Subroutine whois: called CC=13 SCAR=34.5
Pod documented
61 2 my ($dom, $server, $which_whois) = @_;
62  
63 2 ▶ $which_whois ||= 'QRY_LAST';
Condition50%1/2
$which_whois ||= "QRY_LAST"
l!l
20
MC/DC0%0/1
$which_whois ||= "QRY_LAST"
$which_whois
Truth table50%1/2
A
A= $which_whois
Aresult
11
00
64  
65 2 my $res = Net::Whois::Raw::Common::get_from_cache( "$dom-$which_whois", $CACHE_DIR, $CACHE_TIME );
66  
67 2 my ($res_text, $res_srv, $res_text2);
68  
69 2 ▶ if ($res) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res) { } 1 1 2
70 1 ▶ if ($which_whois eq 'QRY_FIRST') {
Branch: 3 branches
BranchTrueFalseTotal
if ($which_whois eq 'QRY_FIRST') { } 0 1 1
elsif ($which_whois eq 'QRY_LAST' or not defined $which_whois) { } 0 1 1
elsif ($which_whois eq 'QRY_ALL') { } 1 0 1
71 0 $res_text = $res->[0]->{text};
72 0 $res_srv = $res->[0]->{srv};
73 ▶ } elsif ($which_whois eq 'QRY_LAST' || !defined($which_whois)) {
Condition33%1/3
$which_whois eq "QRY_LAST" or not defined $which_whois
l!l&&r!l&&!r
001
MC/DC0%0/2
$which_whois eq "QRY_LAST" or not defined $which_whois
$which_whois eq "QRY_LAST" not defined $which_whois
Truth table33%1/3
A or not(B)
A= $which_whois eq "QRY_LAST"B= not defined $which_whois
ABresult
1X1
011
000
74 0 $res_text = $res->[-1]->{text};
75 0 $res_srv = $res->[-1]->{srv};
76 } elsif ($which_whois eq 'QRY_ALL') {
77 1 return $res;
78 }
79 }
80 else {
81 1 ($res_text, $res_srv) = get_whois($dom, $server, $which_whois);
82 }
83  
84 1 ▶ $res_srv = '' if $res_srv && $res_srv eq 'www_whois';
Branch: 1 branch
BranchTrueFalseTotal
if $res_srv and $res_srv eq "www_whois" 0 1 1
Condition33%1/3
$res_srv and $res_srv eq "www_whois"
!ll&&!rl&&r
100
MC/DC0%0/2
$res_srv and $res_srv eq "www_whois"
$res_srv $res_srv eq "www_whois"
Truth table33%1/3
A and B
A= $res_srvB= $res_srv eq "www_whois"
ABresult
0X0
100
111
85  
86 1 ▶ if ( defined $res_text && $which_whois ne 'QRY_ALL' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $res_text and $which_whois ne "QRY_ALL") 0 1 1
Condition33%1/3
defined $res_text and $which_whois ne "QRY_ALL"
!ll&&!rl&&r
010
MC/DC0%0/2
defined $res_text and $which_whois ne "QRY_ALL"
defined $res_text $which_whois ne "QRY_ALL"
Truth table33%1/3
A and B
A= defined $res_textB= $which_whois ne "QRY_ALL"
ABresult
0X0
100
111
87 0 utf8::decode( $res_text ); # Perl whyly loss utf8 flag
88  
89 0 ▶ $res_text = encode( $SET_CODEPAGE, $res_text ) if $SET_CODEPAGE;
Branch: 1 branch
BranchTrueFalseTotal
if $Net::Whois::Raw::SET_CODEPAGE 0 0 0
90 }
91  
92 1 ▶ return wantarray ? ($res_text, $res_srv) : $res_text;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
93 }
94  
95 # obtain whois
96 1 ▶sub get_whois {
Subroutine get_whois: called CC=7 SCAR=27.0
Pod documented
97 1 my ($dom, $srv, $which_whois) = @_;
98 1 ▶ $which_whois ||= 'QRY_LAST';
Condition50%1/2
$which_whois ||= "QRY_LAST"
l!l
10
MC/DC0%0/1
$which_whois ||= "QRY_LAST"
$which_whois
Truth table50%1/2
A
A= $which_whois
Aresult
11
00
99  
100 1 ▶ my $whois = get_all_whois( $dom, $srv, $which_whois eq 'QRY_FIRST' )
Branch: 1 branch
BranchTrueFalseTotal
my $whois = get_all_whois($dom, $srv, $which_whois eq "QRY_FIRST") or return undef 1 0 1
101 or return undef;
102  
103 1 Net::Whois::Raw::Common::write_to_cache( "$dom-$which_whois", $whois, $CACHE_DIR );
104  
105 1 ▶ if ($which_whois eq 'QRY_LAST') {
Branch: 2 branches
BranchTrueFalseTotal
if ($which_whois eq 'QRY_LAST') { } 0 1 1
elsif ($which_whois eq 'QRY_FIRST') { } 0 1 1
106 0 my $thewhois = $whois->[-1];
107 0 ▶ return wantarray ? ($thewhois->{text}, $thewhois->{srv}) : $thewhois->{text};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
108 }
109 elsif ($which_whois eq 'QRY_FIRST') {
110 0 my $thewhois = $whois->[0];
111 0 ▶ return wantarray ? ($thewhois->{text}, $thewhois->{srv}) : $thewhois->{text};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
112 }
113 else {
114 1 return $whois;
115 }
116 }
117  
118 1 ▶sub get_all_whois {
Subroutine get_all_whois: called CC=5 SCAR=19.3
Pod undocumented
119 1 my ($dom, $srv, $norecurse) = @_;
120  
121 1 my $is_ns = 0;
122 1 ▶ $is_ns = 1 if $dom =~ s/[.]NS$//i;
Branch: 1 branch
BranchTrueFalseTotal
if $dom =~ s/[.]NS$//i 0 1 1
123  
124 1 ▶ $srv ||= Net::Whois::Raw::Common::get_server( $dom, $is_ns );
Condition33%1/3
$srv ||= Net::Whois::Raw::Common::get_server($dom, $is_ns)
l!l&&r!l&&!r
010
MC/DC0%0/2
$srv ||= Net::Whois::Raw::Common::get_server($dom, $is_ns)
$srv Net::Whois::Raw::Common::get_server($dom, $is_ns)
Truth table33%1/3
A ||= B
A= $srvB= Net::Whois::Raw::Common::get_server($dom, $is_ns)
ABresult
1X1
011
000
125  
126 1 ▶ if ($srv eq 'www_whois') {
Branch: 1 branch
BranchTrueFalseTotal
if ($srv eq "www_whois") 0 1 1
127 0 my ($responce, $ishtml) = www_whois_query( $dom );
128 0 ▶ return $responce ? [ { text => $responce, srv => $srv } ] : $responce;
Branch: 1 branch
BranchTrueFalseTotal
$responce ? : 0 0 0
129 }
130  
131 1 my @whois = recursive_whois( $dom, $srv, [], $norecurse, $is_ns );
132  
133 1 my $whois_answers = process_whois_answers( \@whois, $dom );
134  
135 1 return $whois_answers;
136 }
137  
138 1 ▶sub process_whois_answers {
Subroutine process_whois_answers: called CC=8 SCAR=24.7
Pod undocumented
139 1 my ( $raw_whois, $dom ) = @_;
140  
141 1 my @processed_whois;
142  
143 1 my $level = 0;
144 1 for my $whois_rec ( @$raw_whois ) {
145 2 $whois_rec->{level} = $level;
146 my ( $text, $error ) = Net::Whois::Raw::Common::process_whois(
147 $dom,
148 $whois_rec->{srv},
149 $whois_rec->{text},
150 2 $CHECK_FAIL, $OMIT_MSG, $CHECK_EXCEED,
151 );
152  
153 2 ▶ die $error if $error && $error eq 'Connection rate exceeded'
Branch: 1 branch
BranchTrueFalseTotal
if $error and $error eq "Connection rate exceeded" and $level == 0 || $Net::Whois::Raw::CHECK_EXCEED == 2 0 2 2
Condition22%2/9
$error and $error eq "Connection rate exceeded" and $level == 0 || $Net::Whois::Raw::CHECK_EXCEED == 2
!ll&&!rl&&r
200
$error and $error eq "Connection rate exceeded"
!ll&&!rl&&r
200
$level == 0 or $Net::Whois::Raw::CHECK_EXCEED == 2
l!l&&r!l&&!r
000
MC/DC0%0/4
$error and $error eq "Connection rate exceeded" and $level == 0 || $Net::Whois::Raw::CHECK_EXCEED == 2
$error $error eq "Connection rate exceeded" $level == 0 $Net::Whois::Raw::CHECK_EXCEED == 2
Truth table20%1/5
A and B and C or D
A= $errorB= $error eq "Connection rate exceeded"C= $level == 0D= $Net::Whois::Raw::CHECK_EXCEED == 2
ABCDresult
0XXX0
10XX0
11000
111X1
11011
154 && ( $level == 0 || $CHECK_EXCEED == 2 );
155  
156 2 ▶ if ( $text || $level == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text or $level == 0) 2 0 2
Condition33%1/3
$text or $level == 0
l!l&&r!l&&!r
200
MC/DC0%0/2
$text or $level == 0
$text $level == 0
Truth table33%1/3
A or B
A= $textB= $level == 0
ABresult
1X1
011
000
157 2 $whois_rec->{text} = $text;
158 2 push @processed_whois, $whois_rec;
159 }
160 2 $level++;
161 }
162  
163 1 return \@processed_whois;
164 }
165  
166 104 ▶sub _referral_server {
Subroutine _referral_server: called CC=1 SCAR=0.0
167 104 /ReferralServer:\s*r?whois:\/\/([-.\w]+(?:\:\d+)?)/
168 }
169  
170 2 ▶sub recursive_whois {
Subroutine recursive_whois: called CC=35 SCAR=51.5
Pod undocumented
171 2 my ( $dom, $srv, $was_srv, $norecurse, $is_ns ) = @_;
172  
173 2 my $lines = whois_query( $dom, $srv, $is_ns );
174 2 my $whois = join '', @$lines;
175  
176 2 my ( $newsrv, $registrar );
177 2 for ( @$lines ) {
178 104 ▶ $registrar ||= /Registrar/ || /Registered through/;
Condition83%5/6
$registrar ||= /Registrar/ || /Registered through/
l!l&&r!l&&!r
9824
/Registrar/ || /Registered through/
l!l&&r!l&&!r
204
MC/DC0%0/3
$registrar ||= /Registrar/ || /Registered through/
$registrar /Registrar/ /Registered through/
Truth table0%0/4
A ||= B || C
A= $registrarB= /Registrar/C= /Registered through/
ABCresult
1XX1
01X1
0011
0000
179  
180 # Skip urls as recursive whois servers
181 104 ▶ if ( $registrar && !$norecurse && /whois server:\s*(?:https?:\/\/)?([a-z0-9\-_\.]+)\b/i ) {
Branch: 7 branches
BranchTrueFalseTotal
if ($registrar and not $norecurse and m[whois server:\s*(?:https?://)?([a-z0-9\-_\.]+)\b]i) { } 2 102 104
elsif ($whois =~ /To single out one record, look it up with \"xxx\",/s) { } 0 102 102
elsif (not $norecurse and my($rs) = _referral_server()) { } 0 102 102
elsif (/Contact information can be found in the (\S+)\s+database/) { } 0 102 102
elsif (/OrgID:\s+(\w+)/i || /descr:\s+(\w+)/ and Net::Whois::Raw::Common::is_ipaddr($dom)) { } 0 102 102
elsif (/^\s+Maintainer:\s+RIPE\b/ and Net::Whois::Raw::Common::is_ipaddr($dom)) { } 0 102 102
elsif ($is_ns and $srv ne $Net::Whois::Raw::Data::servers{'NS'}) { } 0 204 204
Condition83%5/6
$registrar and not $norecurse and m[whois server:\s*(?:https?://)?([a-z0-9\-_\.]+)\b]i
!ll&&!rl&&r
4982
$registrar and not $norecurse
!ll&&!rl&&r
40100
MC/DC66%2/3
$registrar and not $norecurse and m[whois server:\s*(?:https?://)?([a-z0-9\-_\.]+)\b]i
$registrar not $norecurse m[whois server:\s*(?:https?://)?([a-z0-9\-_\.]+)\b]i
Truth table75%3/4
A and not(B) and C
A= $registrarB= not $norecurseC= m[whois server:\s*(?:https?://)?([a-z0-9\-_\.]+)\b]i
ABCresult
0XX0
10X0
1100
1111
182 2 $newsrv = lc $1;
183 }
184 elsif ( $whois =~ /To single out one record, look it up with \"xxx\",/s ) {
185 0 return recursive_whois( "=$dom", $srv, $was_srv );
186 }
187 ▶ elsif ( !$norecurse && ( my ( $rs ) = _referral_server() ) ) {
Condition33%1/3
not $norecurse and my($rs) = _referral_server()
!ll&&!rl&&r
01020
MC/DC0%0/2
not $norecurse and my($rs) = _referral_server()
not $norecurse my($rs) = _referral_server()
Truth table33%1/3
not(A) and B
A= not $norecurseB= my($rs) = _referral_server()
ABresult
0X0
100
111
188 0 $newsrv = $rs;
189 0 last;
190 }
191 elsif ( /Contact information can be found in the (\S+)\s+database/ ) {
192 0 $newsrv = $Net::Whois::Raw::Data::ip_whois_servers{ $1 };
193 }
194 ▶ elsif ( ( /OrgID:\s+(\w+)/i || /descr:\s+(\w+)/ ) && Net::Whois::Raw::Common::is_ipaddr( $dom ) ) {
Condition33%2/6
/OrgID:\s+(\w+)/i || /descr:\s+(\w+)/ and Net::Whois::Raw::Common::is_ipaddr($dom)
!ll&&!rl&&r
10200
/OrgID:\s+(\w+)/i or /descr:\s+(\w+)/
l!l&&r!l&&!r
00102
MC/DC0%0/3
/OrgID:\s+(\w+)/i || /descr:\s+(\w+)/ and Net::Whois::Raw::Common::is_ipaddr($dom)
/OrgID:\s+(\w+)/i /descr:\s+(\w+)/ Net::Whois::Raw::Common::is_ipaddr($dom)
Truth table20%1/5
A or B and C
A= /OrgID:\s+(\w+)/iB= /descr:\s+(\w+)/C= Net::Whois::Raw::Common::is_ipaddr($dom)
ABCresult
00X0
1X00
0100
1X11
0111
195 0 my $val = $1;
196 0 ▶ if ( $val =~ /^(?:RIPE|APNIC|KRNIC|LACNIC)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($val =~ /^(?:RIPE|APNIC|KRNIC|LACNIC)$/) 0 0 0
197 0 $newsrv = $Net::Whois::Raw::Data::ip_whois_servers{ $val };
198 0 last;
199 }
200 }
201 ▶ elsif ( /^\s+Maintainer:\s+RIPE\b/ && Net::Whois::Raw::Common::is_ipaddr( $dom ) ) {
Condition33%1/3
/^\s+Maintainer:\s+RIPE\b/ and Net::Whois::Raw::Common::is_ipaddr($dom)
!ll&&!rl&&r
10200
MC/DC0%0/2
/^\s+Maintainer:\s+RIPE\b/ and Net::Whois::Raw::Common::is_ipaddr($dom)
/^\s+Maintainer:\s+RIPE\b/ Net::Whois::Raw::Common::is_ipaddr($dom)
Truth table33%1/3
A and B
A= /^\s+Maintainer:\s+RIPE\b/B= Net::Whois::Raw::Common::is_ipaddr($dom)
ABresult
0X0
100
111
202 0 $newsrv = $Net::Whois::Raw::Data::servers{RIPE};
203 }
204 ▶ elsif ( $is_ns && $srv ne $Net::Whois::Raw::Data::servers{NS} ) {
Condition33%1/3
$is_ns and $srv ne $Net::Whois::Raw::Data::servers{"NS"}
!ll&&!rl&&r
10200
MC/DC0%0/2
$is_ns and $srv ne $Net::Whois::Raw::Data::servers{"NS"}
$is_ns $srv ne $Net::Whois::Raw::Data::servers{"NS"}
Truth table33%1/3
A and B
A= $is_nsB= $srv ne $Net::Whois::Raw::Data::servers{"NS"}
ABresult
0X0
100
111
205 0 $newsrv = $Net::Whois::Raw::Data::servers{NS};
206 }
207 }
208  
209 2 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $newsrv and $Net::Whois::Raw::Data::whois_servers_no_recurse{$newsrv} || $dom =~ /^xn--/i && $newsrv && $Net::Whois::Raw::Data::whois_servers_with_no_idn_support{$newsrv}) 0 2 2
Condition33%4/12
defined $newsrv and $Net::Whois::Raw::Data::whois_servers_no_recurse{$newsrv} || $dom =~ /^xn--/i && $newsrv && $Net::Whois::Raw::Data::whois_servers_with_no_idn_support{$newsrv}
!ll&&!rl&&r
020
$Net::Whois::Raw::Data::whois_servers_no_recurse{$newsrv} or $dom =~ /^xn--/i and $newsrv and $Net::Whois::Raw::Data::whois_servers_with_no_idn_support{$newsrv}
l!l&&r!l&&!r
002
$dom =~ /^xn--/i and $newsrv and $Net::Whois::Raw::Data::whois_servers_with_no_idn_support{$newsrv}
!ll&&!rl&&r
200
$dom =~ /^xn--/i and $newsrv
!ll&&!rl&&r
200
MC/DC0%0/5
defined $newsrv and $Net::Whois::Raw::Data::whois_servers_no_recurse{$newsrv} || $dom =~ /^xn--/i && $newsrv && $Net::Whois::Raw::Data::whois_servers_with_no_idn_support{$newsrv}
defined $newsrv $Net::Whois::Raw::Data::whois_servers_no_recurse{$newsrv} $dom =~ /^xn--/i $newsrv $Net::Whois::Raw::Data::whois_servers_with_no_idn_support{$newsrv}
Truth table16%1/6
A and B or C and D and E
A= defined $newsrvB= $Net::Whois::Raw::Data::whois_servers_no_recurse{$newsrv}C= $dom =~ /^xn--/iD= $newsrvE= $Net::Whois::Raw::Data::whois_servers_with_no_idn_support{$newsrv}
ABCDEresult
0XXXX0
100XX0
1010X0
101100
11XXX1
101111
210 defined $newsrv && (
211 # Bypass recursing to custom servers
212 $Net::Whois::Raw::Data::whois_servers_no_recurse{ $newsrv }
213 # Bypass recursing to WHOIS servers with no IDN support
214 || $dom =~ /^xn--/i && $newsrv && $Net::Whois::Raw::Data::whois_servers_with_no_idn_support{ $newsrv }
215 )
216 ) {
217 0 $newsrv = undef;
218 }
219  
220 2 my @whois_recs = ( { text => $whois, srv => $srv } );
221 2 ▶ if ( $newsrv && $newsrv ne $srv ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newsrv and $newsrv ne $srv) 1 1 2
Condition66%2/3
$newsrv and $newsrv ne $srv
!ll&&!rl&&r
011
MC/DC50%1/2
$newsrv and $newsrv ne $srv
$newsrv $newsrv ne $srv
Truth table66%2/3
A and B
A= $newsrvB= $newsrv ne $srv
ABresult
0X0
100
111
222 1 ▶ warn "recurse to $newsrv\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Net::Whois::Raw::DEBUG 0 1 1
223  
224 0 ▶ return () if grep { $_ eq $newsrv } @$was_srv;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $newsrv;} @$was_srv 0 1 1
225  
226 1 my @new_whois_recs = eval { recursive_whois( $dom, $newsrv, [ @$was_srv, $srv ], 0, $is_ns ) };
227 1 ▶ my $new_whois = scalar @new_whois_recs ? $new_whois_recs[0]->{text} : '';
Branch: 1 branch
BranchTrueFalseTotal
scalar @new_whois_recs ? : 1 0 1
228 1 my $notfound = $Net::Whois::Raw::Data::notfound{ $newsrv };
229  
230 1 ▶ if ( $new_whois && !$@ && not ( $notfound && $new_whois =~ /$notfound/im ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_whois and not $@ and not $notfound && $new_whois =~ /$notfound/im) { } 1 0 1
Condition33%3/9
$new_whois and not $@ and not $notfound && $new_whois =~ /$notfound/im
!ll&&!rl&&r
001
$new_whois and not $@
!ll&&!rl&&r
001
$notfound && $new_whois =~ /$notfound/im
!ll&&!rl&&r
010
MC/DC0%0/4
$new_whois and not $@ and not $notfound && $new_whois =~ /$notfound/im
$new_whois not $@ $notfound $new_whois =~ /$notfound/im
Truth table20%1/5
A and not(B) and not(C && D)
A= $new_whoisB= not $@C= $notfoundD= $new_whois =~ /$notfound/im
ABCDresult
0XXX0
10XX0
11110
110X1
11101
231 1 ▶ if ( $is_ns ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_ns) { } 0 1 1
232 0 unshift @whois_recs, @new_whois_recs;
233 }
234 else {
235 1 push @whois_recs, @new_whois_recs;
236 }
237 }
238 else {
239 0 ▶ warn "recursive query failed\n" if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Net::Whois::Raw::DEBUG 0 0 0
240 }
241 }
242  
243 2 return @whois_recs;
244 }
245  
246 2 ▶sub whois_query {
Subroutine whois_query: called CC=24 SCAR=43.2
Pod undocumented
247 2 my ($dom, $srv, $is_ns) = @_;
248  
249 # Prepare query
250 2 my $whoisquery = Net::Whois::Raw::Common::get_real_whois_query($dom, $srv, $is_ns);
251  
252 # Prepare for query
253  
254 2 my (@sockparams, $sock);
255 2 my (undef, $tld) = Net::Whois::Raw::Common::split_domain($dom);
256  
257 2 $tld = uc $tld;
258 2 my $rotate_reference = undef;
259  
260 ### get server for query
261 2 my $server4query = Net::Whois::Raw::Common::get_server($dom);
262  
263 2 ▶ if ( Net::Whois::Raw::Common::is_ip6addr( $srv ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (Net::Whois::Raw::Common::is_ip6addr($srv)) 0 2 2
264 0 $srv = "[$srv]";
265 }
266  
267 2 ▶ my $srv_and_port = $srv =~ /\:\d+$/ ? $srv : "$srv:43";
Branch: 1 branch
BranchTrueFalseTotal
$srv =~ /\:\d+$/ ? : 0 2 2
268 2 ▶ if ($class->can('whois_query_sockparams')) {
Branch: 4 branches
BranchTrueFalseTotal
if ($Net::Whois::Raw::class->can('whois_query_sockparams')) { } 0 2 2
elsif ($Net::Whois::Raw::class->can('whois_query_socket')) { } 0 2 2
elsif (my $ips_arrayref = get_ips_for_query($server4query)) { } 0 2 2
elsif (scalar @Net::Whois::Raw::SRC_IPS) { } 0 2 2
269 0 @sockparams = $class->whois_query_sockparams ($dom, $srv);
270 }
271 # hook for outside defined socket
272 elsif ($class->can('whois_query_socket')) {
273 0 $sock = $class->whois_query_socket ($dom, $srv);
274 }
275 elsif (my $ips_arrayref = get_ips_for_query($server4query)) {
276 0 $rotate_reference = $ips_arrayref;
277 }
278 elsif (scalar(@SRC_IPS)) {
279 0 $rotate_reference = \@SRC_IPS;
280 }
281 else {
282 2 @sockparams = $srv_and_port;
283 }
284  
285  
286 2 ▶ if ($rotate_reference) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rotate_reference) 0 2 2
287 0 my $src_ip = $rotate_reference->[0];
288 0 push @$rotate_reference, shift @$rotate_reference; # rotate ips
289 0 @sockparams = (PeerAddr => $srv_and_port, LocalAddr => $src_ip);
290 }
291  
292 2 ▶ print "QUERY: $whoisquery; SRV: $srv, ".
Branch: 1 branch
BranchTrueFalseTotal
if $Net::Whois::Raw::DEBUG >= 2 0 2 2
293 "OMIT_MSG: $OMIT_MSG, CHECK_FAIL: $CHECK_FAIL, CACHE_DIR: $CACHE_DIR, ".
294 "CACHE_TIME: $CACHE_TIME, TIMEOUT: $TIMEOUT\n" if $DEBUG >= 2;
295  
296 2 my $prev_alarm = undef;
297 2 my $t0 = time();
298  
299 2 my @lines;
300  
301 # Make query
302  
303 {
304 0 ▶ local $SIG{'ALRM'} = sub { die "Connection timeout to $srv" };
Subroutine __ANON__: not called CC=1 SCAR=0.4
305 2 eval {
306  
307 2 ▶ $prev_alarm = alarm $TIMEOUT if $TIMEOUT;
Branch: 1 branch
BranchTrueFalseTotal
if $Net::Whois::Raw::TIMEOUT 0 2 2
308  
309 2 ▶ unless ( $sock ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sock) 2 0 2
310 $sock = eval {
311 2 IO::Socket::IP->new( @sockparams )
312 }
313 2 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
$sock = eval { do { "IO::Socket::IP"->new(@sockparams) } } or do { my $errstr = $IO::Socket::errstr || "<empty error>"; die "${srv}: ${errstr}: " . join(", ", @sockparams) } 2 0 2
314 0 ▶ my $errstr = $IO::Socket::errstr || '<empty error>';
Condition0%0/2
$IO::Socket::errstr || '<empty error>'
l!l
00
MC/DC0%0/1
$IO::Socket::errstr || '<empty error>'
$IO::Socket::errstr
Truth table0%0/2
A
A= $IO::Socket::errstr
Aresult
11
00
315 0 die "$srv: $errstr: " . join( ', ', @sockparams );
316 };
317 }
318  
319 2 ▶ if ($class->can ('whois_socket_fixup')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::Whois::Raw::class->can("whois_socket_fixup")) 0 2 2
320 0 my $new_sock = $class->whois_socket_fixup ($sock);
321 0 ▶ $sock = $new_sock if $new_sock;
Branch: 1 branch
BranchTrueFalseTotal
if $new_sock 0 0 0
322 }
323  
324 2 ▶ if ($DEBUG > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::Whois::Raw::DEBUG > 2) 0 2 2
325 0 require Data::Dumper;
326 0 print "Socket: ". Data::Dumper::Dumper($sock);
327 }
328  
329 2 ▶ if ($QUERY_SUFFIX) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::Whois::Raw::QUERY_SUFFIX) 0 2 2
330 0 $whoisquery .= $QUERY_SUFFIX;
331 }
332  
333 2 $sock->print( $whoisquery, "\r\n" );
334 # TODO: $soc->read, parameters for read chunk size, max content length
335 # Now you can redefine SOCK_CLASS::getline method as you want
336 2 ▶ while (my $str = $sock->getline) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $str = $sock->getline) 104 2 106
337 104 push @lines, $str;
338 }
339 2 $sock->close;
340 };
341 {
342 2 local $@; # large code block below, so preserve previous exception.
343 2 ▶ if (defined $prev_alarm) { # if we ever set new alarm
Branch: 1 branch
BranchTrueFalseTotal
if (defined $prev_alarm) 0 2 2
344 0 ▶ if ($prev_alarm == 0) { # there was no alarm previously
Branch: 1 branch
BranchTrueFalseTotal
if ($prev_alarm == 0) { } 0 0 0
345 0 alarm 0; # clear it
346 } else { # there was an alarm previously
347 0 $prev_alarm -= (time()- $t0); # try best to substract time elapsed
348 0 ▶ $prev_alarm = 1 if $prev_alarm < 1; # we still need set it to something non-zero
Branch: 1 branch
BranchTrueFalseTotal
if $prev_alarm < 1 0 0 0
349 0 alarm $prev_alarm; # set it
350 }
351 }
352 }
353 2 ▶ Carp::confess $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
354 }
355  
356 2 foreach (@lines) { s/\r//g; }
357  
358 2 ▶ print "Received ".scalar(@lines)." lines\n" if $DEBUG >= 2;
Branch: 1 branch
BranchTrueFalseTotal
if $Net::Whois::Raw::DEBUG >= 2 0 2 2
359  
360 2 return \@lines;
361 }
362  
363 0 ▶sub www_whois_query {
Subroutine www_whois_query: not called CC=17 SCAR=57.2
Pod undocumented
364 0 my ($dom) = (lc shift);
365  
366 0 my ($resp, $url);
367 0 my ($name, $tld) = Net::Whois::Raw::Common::split_domain( $dom );
368  
369 0 my $http_query_urls = Net::Whois::Raw::Common::get_http_query_url($dom);
370  
371 0 foreach my $qurl ( @{$http_query_urls} ) {
372  
373 # load-on-demand
374 0 ▶ unless ($INC{'LWP/UserAgent.pm'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($INC{"LWP/UserAgent.pm"}) 0 0 0
375 0 require LWP::UserAgent;
376 0 require HTTP::Request;
377 0 require HTTP::Headers;
378 0 require URI::URL;
379 0 import LWP::UserAgent;
380 0 import HTTP::Request;
381 0 import HTTP::Headers;
382 0 import URI::URL;
383 }
384  
385 0 ▶ my $referer = delete $qurl->{form}{referer} if $qurl->{form} && defined $qurl->{form}{referer};
Branch: 1 branch
BranchTrueFalseTotal
if $qurl->{"form"} and defined $qurl->{"form"}{"referer"} 0 0 0
Condition0%0/3
$qurl->{"form"} and defined $qurl->{"form"}{"referer"}
!ll&&!rl&&r
000
MC/DC0%0/2
$qurl->{"form"} and defined $qurl->{"form"}{"referer"}
$qurl->{"form"} defined $qurl->{"form"}{"referer"}
Truth table0%0/3
A and B
A= $qurl->{"form"}B= defined $qurl->{"form"}{"referer"}
ABresult
0X0
100
111
386 0 ▶ my $method = ( $qurl->{form} && scalar(keys %{$qurl->{form}}) ) ? 'POST' : 'GET';
Branch: 1 branch
BranchTrueFalseTotal
$qurl->{'form'} && scalar keys %{$$qurl{'form'};} ? : 0 0 0
Condition0%0/2
$qurl->{"form"} and scalar keys %{$$qurl{"form"};}
!ll
00
MC/DC0%0/1
$qurl->{"form"} and scalar keys %{$$qurl{"form"};}
$qurl->{"form"}
Truth table0%0/2
A
A= $qurl->{"form"}
Aresult
00
11
387  
388 0 my $ua;
389  
390 # hook for outside defined lwp
391 0 ▶ if ($class->can ('whois_query_ua')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::Whois::Raw::class->can("whois_query_ua")) 0 0 0
392 0 $ua = $class->whois_query_ua ($dom);
393 }
394  
395 0 ▶ unless($ua){
Branch: 1 branch
BranchTrueFalseTotal
unless ($ua) 0 0 0
396 0 $ua = new LWP::UserAgent( parse_head => 0 );
397 0 $ua->agent('Mozilla/5.0 (X11; U; Linux i686; ru; rv:1.9.0.5) Gecko/2008121622 Fedora/3.0.5-1.fc10 Firefox/3.0.5');
398 }
399 0 my $header = HTTP::Headers->new;
400 0 ▶ $header->header('Referer' => $referer) if $referer;
Branch: 1 branch
BranchTrueFalseTotal
if $referer 0 0 0
401 0 my $req = new HTTP::Request $method, $qurl->{url}, $header;
402  
403 0 ▶ if ($method eq 'POST') {
Branch: 1 branch
BranchTrueFalseTotal
if ($method eq "POST") 0 0 0
404 0 require URI::URL;
405 0 import URI::URL;
406  
407 0 my $curl = url("http:");
408 0 $req->content_type('application/x-www-form-urlencoded');
409 0 $curl->query_form( %{$qurl->{form}} );
410 0 $req->content( $curl->equery );
411 }
412  
413 0 $resp = eval {
414 0 ▶ local $SIG{ALRM} = sub { die "www_whois connection timeout" };
Subroutine __ANON__: not called CC=1 SCAR=6.9
415 0 alarm 10;
416 0 $ua->request($req)->content;
417 };
418 0 alarm 0;
419  
420 0 ▶ if ( !$resp || $@ || $resp =~ /www_whois connection timeout/ || $resp =~ /^500 Can\'t connect/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $resp or $@ or $resp =~ /www_whois connection timeout/ or $resp =~ /^500 Can\'t connect/) { } 0 0 0
Condition0%0/9
not $resp or $@ or $resp =~ /www_whois connection timeout/ or $resp =~ /^500 Can\'t connect/
l!l&&r!l&&!r
000
not $resp or $@ or $resp =~ /www_whois connection timeout/
l!l&&r!l&&!r
000
not $resp or $@
l!l&&r!l&&!r
000
MC/DC0%0/4
not $resp or $@ or $resp =~ /www_whois connection timeout/ or $resp =~ /^500 Can\'t connect/
not $resp $@ $resp =~ /www_whois connection timeout/ $resp =~ /^500 Can\'t connect/
Truth table0%0/5
not(A) or B or C or D
A= not $respB= $@C= $resp =~ /www_whois connection timeout/D= $resp =~ /^500 Can\'t connect/
ABCDresult
1XXX1
01XX1
001X1
00011
00000
421 0 undef $resp;
422 }
423 else {
424 0 $url = $qurl->{url};
425 0 last;
426 }
427 }
428  
429 0 ▶ return undef unless $resp;
Branch: 1 branch
BranchTrueFalseTotal
unless $resp 0 0 0
430  
431 0 chomp $resp;
432 0 $resp =~ s/\r//g;
433  
434 0 my $ishtml;
435  
436 0 $resp = Net::Whois::Raw::Common::parse_www_content($resp, $tld, $url, $CHECK_EXCEED);
437  
438 0 ▶ return wantarray ? ($resp, $ishtml) : $resp;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
439 }
440  
441  
442 2 ▶sub import {
Subroutine import: called CC=2 SCAR=6.9
443 2 my $mypkg = shift;
444 2 my $callpkg = caller;
445  
446 4 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
447  
448 # export subs
449 2 *{"$callpkg\::$_"} = \&{"$mypkg\::$_"} foreach ((@EXPORT, @_));
450 }
451  
452  
453 0 ▶sub set_ips_for_server {
Subroutine set_ips_for_server: not called CC=3 SCAR=24.8
Pod documented
454 0 my ($server, $ips) = @_;
455  
456 0 ▶ croak "Missing params" if (!$ips || !$server);
Branch: 1 branch
BranchTrueFalseTotal
unless $ips and $server 0 0 0
Condition0%0/3
$ips and $server
!ll&&!rl&&r
000
MC/DC0%0/2
$ips and $server
$ips $server
Truth table0%0/3
A and B
A= $ipsB= $server
ABresult
0X0
100
111
457  
458 0 $server = lc $server;
459 0 $_IPS->{$server} = $ips;
460 }
461  
462  
463 2 ▶sub get_ips_for_query {
Subroutine get_ips_for_query: called CC=2 SCAR=7.4
Pod undocumented
464 2 my ($server) = @_;
465  
466 2 $server = lc $server;
467 2 ▶ if ($_IPS->{$server}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_IPS->{$server}) 0 2 2
468 0 return $_IPS->{$server};
469 }
470 2 return undef;
471 }
472  
473  
474 4 1;
475  
476 __END__
« Raw/Common.pm ↑ Summary Raw/Data.pm »