DRI/Protocol/EPP/Extensions/NO/Host.pm

filter: Statementstmt 7.3% 10 / 137 Branchbran 0.0% 0 / 70 Conditioncond 0.0% 0 / 36 MC/DCmcdc 0.0% 0 / 21 Subroutinesub 30.0% 3 / 10 Podpod 0.0% 0 / 7 totaltotal 4.6% 13 / 281 CC 59 SCAR 59.4
CC
59
Cov
4%
update
756.0
create
272.0
parse_info
72.0
CRAP 380.7
« DRI/Protocol/RRI/RegistryMessage.pm ↑ Summary DRI/Protocol/Whois/Domain/common.pm »
1 ## Domain Registry Interface, .NO Host extensions
2 ##
3 ## Copyright (c) 2008,2010,2013-2014 UNINETT Norid AS, E<lt>http://www.norid.noE<gt>,
4 ## Trond Haugen E<lt>info@norid.noE<gt>
5 ## Copyright (c) 2016,2019 Patrick Mevzek <netdri@dotandco.com>.
6 ## All rights reserved.
7 ##
8 ## This file is part of Net::DRI
9 ##
10 ## Net::DRI is free software; you can redistribute it and/or modify
11 ## it under the terms of the GNU General Public License as published by
12 ## the Free Software Foundation; either version 2 of the License, or
13 ## (at your option) any later version.
14 ##
15 ## See the LICENSE file that comes with this distribution for more details.
16 ####################################################################################################
17  
18 package Net::DRI::Protocol::EPP::Extensions::NO::Host;
19  
20 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 ▶use Net::DRI::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 =pod
26  
27 =head1 NAME
28  
29 Net::DRI::Protocol::EPP::Extensions::NO::Host - .NO Host Extensions for Net::DRI
30  
31 =head1 DESCRIPTION
32  
33 Please see the README file for details.
34  
35 =head1 SUPPORT
36  
37 For now, support questions should be sent to:
38  
39 E<lt>netdri@dotandco.comE<gt>
40  
41 Please also see the SUPPORT file in the distribution.
42  
43 =head1 SEE ALSO
44  
45 E<lt>http://www.dotandco.com/services/software/Net-DRI/E<gt>
46  
47 =head1 AUTHOR
48  
49 Trond Haugen, E<lt>info@norid.noE<gt>
50  
51 =head1 COPYRIGHT
52  
53 Copyright (c) 2008,2010,2013-2014 UNINETT Norid AS, E<lt>http://www.norid.noE<gt>,
54 Trond Haugen E<lt>info@norid.noE<gt>
55 Copyright (c) 2016,2019 Patrick Mevzek <netdri@dotandco.com>.
56 All rights reserved.
57  
58 This program is free software; you can redistribute it and/or modify
59 it under the terms of the GNU General Public License as published by
60 the Free Software Foundation; either version 2 of the License, or
61 (at your option) any later version.
62  
63 See the LICENSE file that comes with this distribution for more details.
64  
65 =cut
66  
67 ####################################################################################################
68  
69 0 ▶sub register_commands {
Subroutine register_commands: not called CC=1 SCAR=6.9
Pod undocumented
70 0 my ( $class, $version ) = @_;
71 0 my %tmp = (
72 create => [ \&create, undef ],
73 update => [ \&update, undef ],
74 delete => [ \&facet, undef ],
75 check => [ \&facet, undef ],
76 info => [ \&info, \&parse_info ],
77 );
78  
79 0 return { 'host' => \%tmp };
80 }
81  
82 ####################################################################################################
83  
84 ##
85 # This facet method is generic and can be called from all object operations
86 #
87 0 ▶sub build_facets {
Subroutine build_facets: not called CC=5 SCAR=34.0
Pod undocumented
88 0 my ( $epp, $rd ) = @_;
89  
90 0 my @e;
91  
92 0 ▶ if (exists($rd->{facets}) && defined($rd->{facets})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $rd->{"facets"} and defined $rd->{"facets"}) 0 0 0
Condition0%0/3
exists $rd->{"facets"} and defined $rd->{"facets"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $rd->{"facets"} and defined $rd->{"facets"}
exists $rd->{"facets"} defined $rd->{"facets"}
Truth table0%0/3
A and B
A= exists $rd->{"facets"}B= defined $rd->{"facets"}
ABresult
0X0
100
111
93 0 foreach my $fkey (sort { $a cmp $b } keys(%{$rd->{facets}})) {
94 0 push @e, [ 'no-ext-epp:facet', { name => $fkey }, $rd->{facets}->{$fkey} ];
95 }
96 }
97 0 ▶ $epp->message()->command_extension( 'no-ext-epp', ['extended', @e] ) if @e;
Branch: 1 branch
BranchTrueFalseTotal
if @e 0 0 0
98 0 return;
99 }
100  
101  
102 0 ▶sub facet {
Subroutine facet: not called CC=1 SCAR=6.9
Pod undocumented
103 0 my ( $epp, $o, $rd ) = @_;
104  
105 0 return build_facets( $epp, $rd );
106 }
107  
108  
109 0 ▶sub parse_info {
Subroutine parse_info: not called CC=8 SCAR=42.8
Pod undocumented
110 0 my ( $po, $otype, $oaction, $oname, $rinfo ) = @_;
111 0 my $mes = $po->message();
112 0 ▶ return unless $mes->is_success();
Branch: 1 branch
BranchTrueFalseTotal
unless $mes->is_success 0 0 0
113  
114 0 my $NS = $mes->ns('no-ext-host');
115  
116 0 my $condata = $mes->get_extension('no-ext-host','infData');
117 0 ▶ return unless $condata;
Branch: 1 branch
BranchTrueFalseTotal
unless $condata 0 0 0
118  
119 0 my @e = $condata->getElementsByTagNameNS( $NS, 'contact' );
120 0 ▶ return unless @e;
Branch: 1 branch
BranchTrueFalseTotal
unless @e 0 0 0
121  
122 # Contact is optional, may be single or multiple,
123 # return the contactIDs in an ARRAY
124 0 my @hc;
125 0 foreach my $el ( @e)
126 {
127 0 my $c = $el->getFirstChild();
128 0 my $v;
129 0 ▶ $v = $c->getData() if ($c);
Branch: 1 branch
BranchTrueFalseTotal
if $c 0 0 0
130 0 ▶ push @hc, $v if ($v);
Branch: 1 branch
BranchTrueFalseTotal
if $v 0 0 0
131 }
132 0 ▶ if ( @hc > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@hc > 0) 0 0 0
133 # multiple, return array
134 0 push @{$rinfo->{host}->{$oname}->{contact}}, @hc;
135 }
136 0 return;
137 }
138  
139 0 ▶sub info {
Subroutine info: not called CC=7 SCAR=40.3
Pod undocumented
140 0 my ( $epp, $ho, $rd ) = @_;
141  
142 0 my $si;
143 0 ▶ $si = $rd->{sponsoringclientid} if (exists($rd->{sponsoringclientid}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $rd->{"sponsoringclientid"} 0 0 0
144 0 my $fs;
145 0 ▶ $fs = $rd->{facets} if (exists($rd->{facets}));
Branch: 1 branch
BranchTrueFalseTotal
if exists $rd->{"facets"} 0 0 0
146  
147 0 ▶ return unless ( $si || $fs );
Branch: 1 branch
BranchTrueFalseTotal
unless $si or $fs 0 0 0
Condition0%0/3
$si or $fs
l!l&&r!l&&!r
000
MC/DC0%0/2
$si or $fs
$si $fs
Truth table0%0/3
A or B
A= $siB= $fs
ABresult
1X1
011
000
148  
149 0 my $r;
150  
151 0 ▶ if ($si) {
Branch: 1 branch
BranchTrueFalseTotal
if ($si) 0 0 0
152 0 $r = $epp->message()->command_extension( 'no-ext-host', ['info', ['sponsoringClientID', $si]] );
153 }
154 0 ▶ if ($fs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fs) 0 0 0
155 0 $r = facet( $epp, $ho, $rd );
156 }
157  
158 0 return $r;
159 }
160  
161 0 ▶sub create {
Subroutine create: not called CC=16 SCAR=56.1
Pod undocumented
162 0 my ( $epp, $ho, $rd ) = @_;
163  
164 0 ▶ return unless ((exists($rd->{contact}) && defined($rd->{contact})) || (exists($rd->{facets}) && defined($rd->{facets})));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $rd->{"contact"} and defined $rd->{"contact"} or exists $rd->{"facets"} and defined $rd->{"facets"} 0 0 0
Condition0%0/9
exists $rd->{"contact"} and defined $rd->{"contact"} or exists $rd->{"facets"} and defined $rd->{"facets"}
l!l&&r!l&&!r
000
exists $rd->{"contact"} and defined $rd->{"contact"}
!ll&&!rl&&r
000
exists $rd->{"facets"} and defined $rd->{"facets"}
!ll&&!rl&&r
000
MC/DC0%0/4
exists $rd->{"contact"} and defined $rd->{"contact"} or exists $rd->{"facets"} and defined $rd->{"facets"}
exists $rd->{"contact"} defined $rd->{"contact"} exists $rd->{"facets"} defined $rd->{"facets"}
Truth table0%0/7
A and B or C and D
A= exists $rd->{"contact"}B= defined $rd->{"contact"}C= exists $rd->{"facets"}D= defined $rd->{"facets"}
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
165  
166 0 my $r;
167  
168 0 ▶ if (exists($rd->{contact}) && defined($rd->{contact})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $rd->{"contact"} and defined $rd->{"contact"}) 0 0 0
Condition0%0/3
exists $rd->{"contact"} and defined $rd->{"contact"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $rd->{"contact"} and defined $rd->{"contact"}
exists $rd->{"contact"} defined $rd->{"contact"}
Truth table0%0/3
A and B
A= exists $rd->{"contact"}B= defined $rd->{"contact"}
ABresult
0X0
100
111
169 0 my @e;
170 0 my $c = $rd->{contact};
171 0 my $srid;
172  
173 0 ▶ if ( ref($c) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $c eq 'ARRAY') { } 0 0 0
174 0 foreach my $cn (@$c) {
175 0 ▶ if (Net::DRI::Util::isa_contact($cn))
Branch: 1 branch
BranchTrueFalseTotal
if (Net::DRI::Util::isa_contact($cn)) { } 0 0 0
176 {
177 0 $srid = $cn->srid();
178 } else {
179 0 $srid = $cn;
180 }
181 0 push @e, [ 'no-ext-host:contact', $srid ];
182 }
183 } else {
184 # $c may be a contact set, contact object or a direct scalar
185 0 my @contacts;
186 0 ▶ if (Net::DRI::Util::isa_contactset($c)) {
Branch: 2 branches
BranchTrueFalseTotal
if (Net::DRI::Util::isa_contactset($c)) { } 0 0 0
elsif (Net::DRI::Util::isa_contact($c)) { } 0 0 0
187 0 foreach my $cn (sort { $a cmp $b } keys %{ $$c{'c'} } ) {
188 0 push @contacts, ${$$c{'c'}}{$cn}->[0]->srid();
189 }
190 } elsif (Net::DRI::Util::isa_contact($c)) {
191 0 @contacts = $c->srid();
192 } else {
193 0 @contacts = $c;
194 }
195 0 foreach my $srid (@contacts) {
196 0 push @e, [ 'no-ext-host:contact', $srid ];
197 }
198 }
199 0 $r = $epp->message()->command_extension( 'no-ext-host', ['create', @e] );
200 }
201  
202 # Add facet if any is set
203 0 ▶ if (exists($rd->{facets}) && defined($rd->{facets})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $rd->{"facets"} and defined $rd->{"facets"}) 0 0 0
Condition0%0/3
exists $rd->{"facets"} and defined $rd->{"facets"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $rd->{"facets"} and defined $rd->{"facets"}
exists $rd->{"facets"} defined $rd->{"facets"}
Truth table0%0/3
A and B
A= exists $rd->{"facets"}B= defined $rd->{"facets"}
ABresult
0X0
100
111
204 0 $r = facet( $epp, $ho, $rd );
205 }
206  
207 0 return $r;
208 }
209  
210 0 ▶sub update {
Subroutine update: not called CC=27 SCAR=66.3
Pod undocumented
211 0 my ( $epp, $ho, $todo ) = @_;
212  
213 0 my $ca = $todo->add('contact');
214 0 my $cd = $todo->del('contact');
215 0 my $fs = $todo->set('facets');
216  
217 0 ▶ return unless ( $ca || $cd || $fs); # No updates asked
Branch: 1 branch
BranchTrueFalseTotal
unless $ca or $cd or $fs 0 0 0
Condition0%0/6
$ca or $cd or $fs
l!l&&r!l&&!r
000
$ca or $cd
l!l&&r!l&&!r
000
MC/DC0%0/3
$ca or $cd or $fs
$ca $cd $fs
Truth table0%0/4
A or B or C
A= $caB= $cdC= $fs
ABCresult
1XX1
01X1
0011
0000
218  
219 0 my $r;
220  
221 0 ▶ if ( $ca || $cd ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ca or $cd) 0 0 0
Condition0%0/3
$ca or $cd
l!l&&r!l&&!r
000
MC/DC0%0/2
$ca or $cd
$ca $cd
Truth table0%0/3
A or B
A= $caB= $cd
ABresult
1X1
011
000
222  
223 0 my ( @n, @e, $c, $srid );
224  
225 0 ▶ if ( defined($ca) && $ca ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ca and $ca) 0 0 0
Condition0%0/3
defined $ca and $ca
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ca and $ca
defined $ca $ca
Truth table0%0/3
A and B
A= defined $caB= $ca
ABresult
0X0
100
111
226 0 $c = $ca;
227 0 ▶ if ( ref($c) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $c eq 'ARRAY') { } 0 0 0
228 0 foreach my $cn (@$c) {
229 0 ▶ if (Net::DRI::Util::isa_contact($cn))
Branch: 1 branch
BranchTrueFalseTotal
if (Net::DRI::Util::isa_contact($cn)) { } 0 0 0
230 {
231 0 $srid = $cn->srid();
232 } else {
233 0 $srid = $cn;
234 }
235 0 push @e, [ 'no-ext-host:contact', $srid ];
236 }
237 } else {
238 # $c may be a contact set, contact object or a direct scalar
239 0 my @contacts;
240 0 ▶ if (Net::DRI::Util::isa_contactset($c)) {
Branch: 2 branches
BranchTrueFalseTotal
if (Net::DRI::Util::isa_contactset($c)) { } 0 0 0
elsif (Net::DRI::Util::isa_contact($c)) { } 0 0 0
241 0 foreach my $cn (sort { $a cmp $b } keys %{ $$c{'c'} } ) {
242 0 push @contacts, ${$$c{'c'}}{$cn}->[0]->srid();
243 }
244 } elsif (Net::DRI::Util::isa_contact($c)) {
245 0 @contacts = $c->srid();
246 } else {
247 0 @contacts = $c;
248 }
249 0 foreach my $srid (@contacts) {
250 0 push @e, [ 'no-ext-host:contact', $srid ];
251 }
252 }
253  
254 0 ▶ push @n, [ 'no-ext-host:add', @e ] if ( @e > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if @e > 0 0 0 0
255 }
256 0 @e = undef;
257 0 ▶ if ( defined($cd) && $cd ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $cd and $cd) 0 0 0
Condition0%0/3
defined $cd and $cd
!ll&&!rl&&r
000
MC/DC0%0/2
defined $cd and $cd
defined $cd $cd
Truth table0%0/3
A and B
A= defined $cdB= $cd
ABresult
0X0
100
111
258  
259 0 $c = $cd;
260 0 ▶ if ( ref($c) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $c eq 'ARRAY') { } 0 0 0
261 0 foreach my $cn (@$c) {
262 0 ▶ if (Net::DRI::Util::isa_contact($cn))
Branch: 1 branch
BranchTrueFalseTotal
if (Net::DRI::Util::isa_contact($cn)) { } 0 0 0
263 {
264 0 $srid = $cn->srid();
265 } else {
266 0 $srid = $cn;
267 }
268 0 push @e, [ 'no-ext-host:contact', $srid ];
269 }
270 } else {
271 # $c may be a contact set, contact object or a direct scalar
272 0 my @contacts;
273 0 ▶ if (Net::DRI::Util::isa_contactset($c)) {
Branch: 2 branches
BranchTrueFalseTotal
if (Net::DRI::Util::isa_contactset($c)) { } 0 0 0
elsif (Net::DRI::Util::isa_contact($c)) { } 0 0 0
274 0 foreach my $cn (sort { $a cmp $b } keys %{ $$c{'c'} } ) {
275 0 push @contacts, ${$$c{'c'}}{$cn}->[0]->srid();
276 }
277 } elsif (Net::DRI::Util::isa_contact($c)) {
278 0 @contacts = $c->srid();
279 } else {
280 0 @contacts = $c;
281 }
282 0 foreach my $srid (@contacts) {
283 0 push @e, [ 'no-ext-host:contact', $srid ];
284 }
285 }
286 0 ▶ push @n, [ 'no-ext-host:rem', @e ] if ( @e > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if @e > 0 0 0 0
287 }
288 0 $r = $epp->message()->command_extension( 'no-ext-host', ['update', @n] );
289 }
290  
291 # Add facet if any is set
292 0 ▶ if ($fs) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fs) 0 0 0
293 0 my $rd;
294 0 $rd->{facets} = $fs;
295 0 $r = facet( $epp, $ho, $rd );
296 }
297 0 return $r;
298 }
299  
300 ####################################################################################################
301 1 1;
« DRI/Protocol/RRI/RegistryMessage.pm ↑ Summary DRI/Protocol/Whois/Domain/common.pm »