DRI/Protocol/EPP/Extensions/CZ/Domain.pm

filter: Statementstmt 17.9% 25 / 139 Branchbran 0.0% 0 / 92 Conditioncond 0.0% 0 / 45 MC/DCmcdc 0.0% 0 / 24 Subroutinesub 50.0% 8 / 16 Podpod 0.0% 0 / 8 totaltotal 10.1% 33 / 324 CC 64 SCAR 56.9
CC
64
Cov
9%
update
506.0
info_parse
420.0
create
210.0
CRAP 295.2
« DRI/Protocol/EPP/Extensions/SecDNS.pm ↑ Summary DRI/Protocol/EPP/Extensions/AFNIC/Contact.pm »
1 ## Domain Registry Interface, CZ domain transactions extension
2 ##
3 ## Copyright (c) 2008-2010,2013 Tonnerre Lombard <tonnerre.lombard@sygroup.ch>.
4 ## 2018 Patrick Mevzek <netdri@dotandco.com>
5 ## All rights reserved.
6 ##
7 ## This file is part of Net::DRI
8 ##
9 ## Net::DRI is free software; you can redistribute it and/or modify
10 ## it under the terms of the GNU General Public License as published by
11 ## the Free Software Foundation; either version 2 of the License, or
12 ## (at your option) any later version.
13 ##
14 ## See the LICENSE file that comes with this distribution for more details.
15 ####################################################################################################
16  
17 package Net::DRI::Protocol::EPP::Extensions::CZ::Domain;
18  
19 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 ▶use Net::DRI::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use Net::DRI::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use Net::DRI::Data::ContactSet;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use Net::DRI::Data::Hosts;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use Net::DRI::Protocol::EPP::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 1 ▶use DateTime::Format::ISO8601;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 =pod
31  
32 =head1 NAME
33  
34 Net::DRI::Protocol::EPP::Extensions::CZ::Domain - .CZ Domain extension commands for Net::DRI
35  
36 =head1 DESCRIPTION
37  
38 Please see the README file for details.
39  
40 =head1 SUPPORT
41  
42 For now, support questions should be sent to:
43  
44 E<lt>development@sygroup.chE<gt>
45  
46 Please also see the SUPPORT file in the distribution.
47  
48 =head1 SEE ALSO
49  
50 E<lt>http://oss.bsdprojects.net/projects/netdri/E<gt>
51  
52 =head1 AUTHOR
53  
54 Tonnerre Lombard, E<lt>tonnerre.lombard@sygroup.chE<gt>
55  
56 =head1 COPYRIGHT
57  
58 Copyright (c) 2008-2010,2013 Tonnerre Lombard <tonnerre.lombard@sygroup.ch>.
59 2018 Patrick Mevzek <netdri@dotandco.com>
60 All rights reserved.
61  
62 This program is free software; you can redistribute it and/or modify
63 it under the terms of the GNU General Public License as published by
64 the Free Software Foundation; either version 2 of the License, or
65 (at your option) any later version.
66  
67 See the LICENSE file that comes with this distribution for more details.
68  
69 =cut
70  
71 ####################################################################################################
72  
73 sub register_commands
74 {
75 0 ▶ my ($class, $version) = @_;
Subroutine register_commands: not called CC=1 SCAR=6.9
Pod undocumented
76 0 my %tmp = (
77 info => [ \&info, \&info_parse ],
78 create => [ \&create, undef ],
79 update => [ \&update ],
80 );
81
82 0 return { 'domain' => \%tmp };
83 }
84  
85 ##################################################################################################
86  
87 sub build_command
88 {
89 0 ▶ my ($msg, $command, $domain, $domainattr) = @_;
Subroutine build_command: not called CC=9 SCAR=45.0
Pod undocumented
90 0 ▶ my @dom = (ref($domain)) ? @$domain : ($domain);
Branch: 1 branch
BranchTrueFalseTotal
ref $domain ? : 0 0 0
91 0 ▶ Net::DRI::Exception->die(1, 'protocol/EPP', 2, "Domain name needed")
Branch: 1 branch
BranchTrueFalseTotal
unless @dom 0 0 0
92 unless @dom;
93  
94 0 foreach my $d (@dom)
95 {
96 0 ▶ Net::DRI::Exception->die(1, 'protocol/EPP', 2,
Branch: 1 branch
BranchTrueFalseTotal
unless defined $d and $d and not ref $d 0 0 0
Condition0%0/6
defined $d and $d and not ref $d
!ll&&!rl&&r
000
defined $d and $d
!ll&&!rl&&r
000
MC/DC0%0/3
defined $d and $d and not ref $d
defined $d $d not ref $d
Truth table0%0/4
A and B and not(C)
A= defined $dB= $dC= not ref $d
ABCresult
0XX0
10X0
1100
1111
97 'Domain name needed') unless (defined($d) && $d && !ref($d));
98 0 ▶ Net::DRI::Exception->die(1, 'protocol/EPP', 10,
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::is_hostname($d) 0 0 0
99 'Invalid domain name: ' . $d)
100 unless (Net::DRI::Util::is_hostname($d));
101 }
102  
103 0 ▶ my $tcommand = (ref($command)) ? $command->[0] : $command;
Branch: 1 branch
BranchTrueFalseTotal
ref $command ? : 0 0 0
104 0 $msg->command([$command, 'domain:' . $tcommand, $msg->nsattrs('domain')]);
105 0 my @d = map { ['domain:name', $_, $domainattr] } @dom;
106 0 return @d;
107 }
108  
109 sub build_authinfo
110 {
111 0 ▶ my $rauth = shift;
Subroutine build_authinfo: not called CC=1 SCAR=6.9
Pod undocumented
112 0 return ['domain:authInfo', $rauth->{pw}];
113 }
114  
115 ####################################################################################################
116 ########### Query commands
117  
118 sub info
119 {
120 0 ▶ my ($epp, $domain, $rd) = @_;
Subroutine info: not called CC=2 SCAR=17.9
Pod undocumented
121 0 my $mes = $epp->message();
122 0 my @d = build_command($mes, 'info', $domain);
123 0 ▶ push(@d, build_authinfo($rd->{auth})) if Net::DRI::Util::has_auth($rd);
Branch: 1 branch
BranchTrueFalseTotal
if Net::DRI::Util::has_auth($rd) 0 0 0
124 0 $mes->command_body(\@d);
125 0 return;
126 }
127  
128 sub info_parse
129 {
130 0 ▶ my ($po, $otype, $oaction, $oname, $rinfo) = @_;
Subroutine info_parse: not called CC=20 SCAR=60.4
Pod undocumented
131 0 my $mes = $po->message();
132 0 ▶ return unless $mes->is_success();
Branch: 1 branch
BranchTrueFalseTotal
unless $mes->is_success 0 0 0
133 0 my $infdata = $mes->get_response('domain','infData');
134 0 ▶ return unless $infdata;
Branch: 1 branch
BranchTrueFalseTotal
unless $infdata 0 0 0
135 0 my (@s, @host, $ns);
136 0 my $cs = Net::DRI::Data::ContactSet->new();
137 0 my $c = $infdata->getFirstChild();
138  
139 0 ▶ while ($c)
Branch: 1 branch
BranchTrueFalseTotal
if ($c) 0 0 0
140 {
141 0 ▶ my $name = $c->localname() || $c->nodeName();
Condition0%0/3
$c->localname || $c->nodeName
l!l&&r!l&&!r
000
MC/DC0%0/2
$c->localname || $c->nodeName
$c->localname $c->nodeName
Truth table0%0/3
A || B
A= $c->localnameB= $c->nodeName
ABresult
1X1
011
000
142 0 ▶ next unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 0 0
143 0 ▶ if ($name eq 'name')
Branch: 10 branches
BranchTrueFalseTotal
if ($name eq 'name') { } 0 0 0
elsif ($name eq 'roid') { } 0 0 0
elsif ($name eq 'status') { } 0 0 0
elsif ($name =~ /^(registrant|admin)$/) { } 0 0 0
elsif ($name eq 'ns') { } 0 0 0
elsif ($name eq 'nsset') { } 0 0 0
elsif ($name eq 'host') { } 0 0 0
elsif ($name =~ /^(clID|crID|upID)$/) { } 0 0 0
elsif ($name =~ /^(crDate|upDate|trDate|exDate)$/) { } 0 0 0
elsif ($name eq 'authInfo') { } 0 0 0
144 {
145 0 $oname = lc($c->getFirstChild()->getData());
146 0 $rinfo->{domain}->{$oname}->{action} = 'info';
147 0 $rinfo->{domain}->{$oname}->{exist} = 1;
148 }
149 elsif ($name eq 'roid')
150 {
151 $rinfo->{domain}->{$oname}->{roid} =
152 0 $c->getFirstChild()->getData();
153 }
154 elsif ($name eq 'status')
155 {
156 0 push(@s, Net::DRI::Protocol::EPP::Util::parse_node_status($c));
157 }
158 elsif ($name =~ /^(registrant|admin)$/)
159 {
160 0 $cs->set($po->create_local_object('contact')->srid($c->getFirstChild()->getData()),
161 $1);
162 }
163 elsif ($name eq 'ns')
164 {
165 0 ▶ $ns = Net::DRI::Data::Hosts->new() if (!$ns);
Branch: 1 branch
BranchTrueFalseTotal
unless $ns 0 0 0
166 0 $ns->add($c->getFirstChild()->getData());
167 }
168 elsif ($name eq 'nsset')
169 {
170 $rinfo->{domain}->{$oname}->{nsset} =
171 0 $c->getFirstChild()->getData();
172 }
173 elsif ($name eq 'host')
174 {
175 0 push(@host, $c->getFirstChild()->getData());
176 }
177 elsif ($name =~ m/^(clID|crID|upID)$/)
178 {
179 0 $rinfo->{domain}->{$oname}->{$1} =
180 $c->getFirstChild()->getData();
181 }
182 elsif ($name =~ m/^(crDate|upDate|trDate|exDate)$/)
183 {
184 0 $rinfo->{domain}->{$oname}->{$1} =
185 DateTime::Format::ISO8601->new()->
186 parse_datetime($c->getFirstChild()->
187 getData());
188 }
189 elsif ($name eq 'authInfo')
190 {
191 0 my $pw = $c->getFirstChild()->getData();
192 $rinfo->{domain}->{$oname}->{auth} =
193 0 ▶ {pw => ($pw ? $pw : undef) };
Branch: 1 branch
BranchTrueFalseTotal
$pw ? : 0 0 0
194 }
195  
196 0 $c = $c->getNextSibling();
197 }
198  
199 0 $rinfo->{domain}->{$oname}->{contact} = $cs;
200 0 $rinfo->{domain}->{$oname}->{status} = $po->
201 create_local_object('status')->add(@s);
202 0 ▶ $rinfo->{domain}->{$oname}->{host} = Net::DRI::Data::Hosts->
Branch: 1 branch
BranchTrueFalseTotal
if @host 0 0 0
203 new_set(@host) if (@host);
204 0 ▶ $rinfo->{domain}->{$oname}->{ns} = $ns if ($ns);
Branch: 1 branch
BranchTrueFalseTotal
if $ns 0 0 0
205 0 return;
206 }
207  
208 ############ Transform commands
209  
210 sub create
211 {
212 0 ▶ my ($epp, $domain, $rd) = @_;
Subroutine create: not called CC=14 SCAR=53.5
Pod undocumented
213 0 my $mes = $epp->message();
214 0 my @d = build_command($mes, 'create', $domain);
215 0 my $def = $epp->default_parameters();
216
217 0 ▶ if ($def && (ref($def) eq 'HASH') && exists($def->{domain_create}) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($def and ref $def eq "HASH" and exists $def->{"domain_create"} and ref $def->{"domain_create"} eq "HASH") 0 0 0
Condition0%0/9
$def and ref $def eq "HASH" and exists $def->{"domain_create"} and ref $def->{"domain_create"} eq "HASH"
!ll&&!rl&&r
000
$def and ref $def eq "HASH" and exists $def->{"domain_create"}
!ll&&!rl&&r
000
$def and ref $def eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/4
$def and ref $def eq "HASH" and exists $def->{"domain_create"} and ref $def->{"domain_create"} eq "HASH"
$def ref $def eq "HASH" exists $def->{"domain_create"} ref $def->{"domain_create"} eq "HASH"
Truth table0%0/5
A and B and C and D
A= $defB= ref $def eq "HASH"C= exists $def->{"domain_create"}D= ref $def->{"domain_create"} eq "HASH"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
218 (ref($def->{domain_create}) eq 'HASH'))
219 {
220 0 ▶ $rd = {} unless ($rd && (ref($rd) eq 'HASH') && keys(%$rd));
Branch: 1 branch
BranchTrueFalseTotal
unless $rd and ref $rd eq "HASH" and keys %$rd 0 0 0
Condition0%0/6
$rd and ref $rd eq "HASH" and keys %$rd
!ll&&!rl&&r
000
$rd and ref $rd eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/3
$rd and ref $rd eq "HASH" and keys %$rd
$rd ref $rd eq "HASH" keys %$rd
Truth table0%0/4
A and B and C
A= $rdB= ref $rd eq "HASH"C= keys %$rd
ABCresult
0XX0
10X0
1100
1111
221  
222 0 ▶ while (my ($k, $v) = each(%{$def->{domain_create}}))
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$def{"domain_create"};}) 0 0 0
223 {
224 0 ▶ next if exists($rd->{$k});
Branch: 1 branch
BranchTrueFalseTotal
if exists $rd->{$k} 0 0 0
225 0 $rd->{$k} = $v;
226 }
227 }
228  
229 ## Period, OPTIONAL
230 0 ▶ push(@d, Net::DRI::Protocol::EPP::Util::build_period($rd->{duration})) if Net::DRI::Util::has_duration($rd);
Branch: 1 branch
BranchTrueFalseTotal
if Net::DRI::Util::has_duration($rd) 0 0 0
231  
232 ## Nameserver sets, OPTIONAL
233 0 ▶ push(@d, ['domain:nsset', $rd->{nsset}]) if (Net::DRI::Util::has_key($rd, 'nsset'));
Branch: 1 branch
BranchTrueFalseTotal
if Net::DRI::Util::has_key($rd, "nsset") 0 0 0
234  
235 ## Contacts, all OPTIONAL
236 0 ▶ push(@d, build_contacts($rd->{contact})) if (Net::DRI::Util::has_contact($rd));
Branch: 1 branch
BranchTrueFalseTotal
if Net::DRI::Util::has_contact($rd) 0 0 0
237  
238 ## AuthInfo
239 0 ▶ Net::DRI::Exception::usererr_insufficient_parameters('authInfo is ' .
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::has_auth($rd) 0 0 0
240 'mandatory')
241 unless (Net::DRI::Util::has_auth($rd));
242 0 push(@d, build_authinfo($rd->{auth}));
243 0 $mes->command_body(\@d);
244 0 return;
245 }
246  
247 sub build_contacts
248 {
249 0 ▶ my $cs = shift;
Subroutine build_contacts: not called CC=2 SCAR=17.9
Pod undocumented
250 0 my @d;
251  
252 0 foreach my $t (sort { $b cmp $a } $cs->types())
253 {
254 0 my @o = $cs->get($t);
255 0 push(@d, map { ['domain:' . $t, $_->srid()] } @o);
256 }
257  
258 0 return @d;
259 }
260  
261 sub update
262 {
263 0 ▶ my ($epp, $domain, $todo) = @_;
Subroutine update: not called CC=22 SCAR=62.3
Pod undocumented
264 0 my $mes = $epp->message();
265  
266 0 ▶ Net::DRI::Exception::usererr_invalid_parameters($todo .
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::isa_changes($todo) 0 0 0
267 ' must be a Net::DRI::Data::Changes object') unless
268 Net::DRI::Util::isa_changes($todo);
269  
270 0 ▶ if ((grep { ! /^(?:add|del)$/ } $todo->types('ns')) ||
Branch: 1 branch
BranchTrueFalseTotal
if (grep {not /^(?:add|del)$/;} $todo->types("ns") or grep {not /^(?:add|del)$/;} $todo->types("status") or grep {not /^(?:add|del)$/;} $todo->types("contact") or grep {not /^set$/;} $todo->types("auth")) 0 0 0
Condition0%0/9
grep {not /^(?:add|del)$/;} $todo->types("ns") or grep {not /^(?:add|del)$/;} $todo->types("status") or grep {not /^(?:add|del)$/;} $todo->types("contact") or grep {not /^set$/;} $todo->types("auth")
l!l&&r!l&&!r
000
grep {not /^(?:add|del)$/;} $todo->types("ns") or grep {not /^(?:add|del)$/;} $todo->types("status") or grep {not /^(?:add|del)$/;} $todo->types("contact")
l!l&&r!l&&!r
000
grep {not /^(?:add|del)$/;} $todo->types("ns") or grep {not /^(?:add|del)$/;} $todo->types("status")
l!l&&r!l&&!r
000
MC/DC0%0/4
grep {not /^(?:add|del)$/;} $todo->types("ns") or grep {not /^(?:add|del)$/;} $todo->types("status") or grep {not /^(?:add|del)$/;} $todo->types("contact") or grep {not /^set$/;} $todo->types("auth")
grep {not /^(?:add|del)$/;} $todo->types("ns") grep {not /^(?:add|del)$/;} $todo->types("status") grep {not /^(?:add|del)$/;} $todo->types("contact") grep {not /^set$/;} $todo->types("auth")
Truth table0%0/5
A or B or C or D
A= grep {not /^(?:add|del)$/;} $todo->types("ns")B= grep {not /^(?:add|del)$/;} $todo->types("status")C= grep {not /^(?:add|del)$/;} $todo->types("contact")D= grep {not /^set$/;} $todo->types("auth")
ABCDresult
1XXX1
01XX1
001X1
00011
00000
271 0 (grep { ! /^(?:add|del)$/ } $todo->types('status')) ||
272 0 (grep { ! /^(?:add|del)$/ } $todo->types('contact')) ||
273 0 (grep { ! /^set$/ } $todo->types('auth')))
274 {
275 0 Net::DRI::Exception->die(0, 'protocol/EPP', 11,
276 'Only ns/status/contact add/del or registrant/' .
277 'authinfo set available for domain');
278 }
279  
280 0 my @d = build_command($mes, 'update', $domain);
281  
282 0 my $nsadd = $todo->add('ns');
283 0 my $nsdel = $todo->del('ns');
284 0 my $sadd = $todo->add('status');
285 0 my $sdel = $todo->del('status');
286 0 my $cadd = $todo->add('contact');
287 0 my $cdel = $todo->del('contact');
288 0 my (@add, @del);
289  
290 0 ▶ push(@add, Net::DRI::Protocol::EPP::Util::build_ns($epp, $nsadd, $domain)) if ($nsadd &&
Branch: 1 branch
BranchTrueFalseTotal
if $nsadd and not $nsadd->is_empty 0 0 0
Condition0%0/3
$nsadd and not $nsadd->is_empty
!ll&&!rl&&r
000
MC/DC0%0/2
$nsadd and not $nsadd->is_empty
$nsadd not $nsadd->is_empty
Truth table0%0/3
A and not(B)
A= $nsaddB= not $nsadd->is_empty
ABresult
0X0
100
111
291 !$nsadd->is_empty());
292 0 ▶ push(@add, build_contacts($cadd)) if ($cadd);
Branch: 1 branch
BranchTrueFalseTotal
if $cadd 0 0 0
293 0 ▶ push(@add, $sadd->build_xml('domain:status', 'core')) if ($sadd);
Branch: 1 branch
BranchTrueFalseTotal
if $sadd 0 0 0
294 0 ▶ push(@del, Net::DRI::Protocol::EPP::Util::build_ns($epp, $nsdel, $domain)) if ($nsdel &&
Branch: 1 branch
BranchTrueFalseTotal
if $nsdel and not $nsdel->is_empty 0 0 0
Condition0%0/3
$nsdel and not $nsdel->is_empty
!ll&&!rl&&r
000
MC/DC0%0/2
$nsdel and not $nsdel->is_empty
$nsdel not $nsdel->is_empty
Truth table0%0/3
A and not(B)
A= $nsdelB= not $nsdel->is_empty
ABresult
0X0
100
111
295 !$nsdel->is_empty());
296 0 ▶ push(@del, build_contacts($cdel)) if ($cdel);
Branch: 1 branch
BranchTrueFalseTotal
if $cdel 0 0 0
297 0 ▶ push(@del, $sdel->build_xml('domain:status', 'core')) if ($sdel);
Branch: 1 branch
BranchTrueFalseTotal
if $sdel 0 0 0
298  
299 0 ▶ push(@d, ['domain:add', @add]) if (@add);
Branch: 1 branch
BranchTrueFalseTotal
if @add 0 0 0
300 0 ▶ push(@d, ['domain:rem', @del]) if (@del);
Branch: 1 branch
BranchTrueFalseTotal
if @del 0 0 0
301  
302 0 my @chg;
303 0 my $chg = $todo->set('nsset');
304 0 ▶ push(@chg, ['domain:nsset', $chg]) if (defined($chg) && length($chg));
Branch: 1 branch
BranchTrueFalseTotal
if defined $chg and length $chg 0 0 0
Condition0%0/3
defined $chg and length $chg
!ll&&!rl&&r
000
MC/DC0%0/2
defined $chg and length $chg
defined $chg length $chg
Truth table0%0/3
A and B
A= defined $chgB= length $chg
ABresult
0X0
100
111
305 0 $chg = $todo->set('registrant');
306 0 ▶ push(@chg, ['domain:registrant', $chg->srid()])
Branch: 1 branch
BranchTrueFalseTotal
if Net::DRI::Util::isa_contact($chg) 0 0 0
307 if Net::DRI::Util::isa_contact($chg);
308 0 $chg = $todo->set('auth');
309 0 ▶ push(@chg, build_authinfo($chg)) if ($chg && ref($chg));
Branch: 1 branch
BranchTrueFalseTotal
if $chg and ref $chg 0 0 0
Condition0%0/3
$chg and ref $chg
!ll&&!rl&&r
000
MC/DC0%0/2
$chg and ref $chg
$chg ref $chg
Truth table0%0/3
A and B
A= $chgB= ref $chg
ABresult
0X0
100
111
310 0 ▶ push(@d, ['domain:chg', @chg]) if (@chg);
Branch: 1 branch
BranchTrueFalseTotal
if @chg 0 0 0
311  
312 0 $mes->command_body(\@d);
313 0 return;
314 }
315  
316 ####################################################################################################
317 1 1;
« DRI/Protocol/EPP/Extensions/SecDNS.pm ↑ Summary DRI/Protocol/EPP/Extensions/AFNIC/Contact.pm »