DRI/Protocol/EPP/Extensions/KeyRelay.pm

filter: Statementstmt 15.7% 19 / 121 Branchbran 0.0% 0 / 68 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 42.8% 6 / 14 Podpod 0.0% 0 / 7 totaltotal 11.3% 25 / 220 CC 42 SCAR 48.8
CC
42
Cov
10%
command
306.0
format_duration
90.0
notification_parse
90.0
CRAP 131.6
« DRI/Protocol/Whois/Domain/AT.pm ↑ Summary DRI/Data/Contact/US.pm »
1 ## Domain Registry Interface, Key Relay Mapping for EPP
2 ##
3 ## Copyright (c) 2013,2015-2017,2018 Patrick Mevzek <netdri@dotandco.com>. All rights reserved.
4 ##
5 ## This file is part of Net::DRI
6 ##
7 ## Net::DRI is free software; you can redistribute it and/or modify
8 ## it under the terms of the GNU General Public License as published by
9 ## the Free Software Foundation; either version 2 of the License, or
10 ## (at your option) any later version.
11 ##
12 ## See the LICENSE file that comes with this distribution for more details.
13 ####################################################################################################
14  
15 package Net::DRI::Protocol::EPP::Extensions::KeyRelay;
16  
17 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use feature 'state';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 ▶use Net::DRI::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Net::DRI::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use Net::DRI::Protocol::EPP::Extensions::SecDNS;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 ####################################################################################################
26  
27 sub register_commands
28 {
29 0 ▶ my ($class,$version)=@_;
Subroutine register_commands: not called CC=1 SCAR=6.9
Pod undocumented
30 0 my %d=(
31 keyrelay => [ \&command, undef ],
32 notification => [ undef, \&notification_parse ],
33 );
34  
35 0 return { 'domain' => \%d };
36 }
37  
38 sub setup
39 {
40 0 ▶ my ($class,$po,$version)=@_;
Subroutine setup: not called CC=1 SCAR=6.9
Pod undocumented
41 0 $po->ns({
42 'keyrelay' => 'urn:ietf:params:xml:ns:keyrelay-1.0',
43 'secDNS' => 'urn:ietf:params:xml:ns:secDNS-1.1', ## force 1.1 here
44 });
45 0 return;
46 }
47  
48 0 ▶sub implements { return 'https://tools.ietf.org/html/rfc8063'; }
Subroutine implements: not called CC=1 SCAR=6.9
Pod undocumented
49  
50 ####################################################################################################
51  
52 sub format_duration
53 {
54 0 ▶ my ($d)=@_;
Subroutine format_duration: not called CC=9 SCAR=45.0
Pod undocumented
55  
56 0 ▶ return 'P0D' if $d->is_zero();
Branch: 1 branch
BranchTrueFalseTotal
if $d->is_zero 0 0 0
57  
58 0 my $duration='P';
59 0 my $tmp='';
60  
61 0 state $ru=[qw/years months weeks days hours minutes seconds/];
62 0 my @d=$d->in_units(@$ru[0..3]);
63 0 foreach my $wi (0..$#d)
64 {
65 0 ▶ next unless $d[$wi] > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $d[$wi] > 0 0 0 0
66 0 $tmp.=$d[$wi].uc(substr($ru->[$wi],0,1));
67 }
68 0 ▶ $duration.=$tmp if length $tmp;
Branch: 1 branch
BranchTrueFalseTotal
if length $tmp 0 0 0
69 0 $tmp='';
70  
71 0 @d=$d->in_units(@$ru[4..6]);
72 0 foreach my $wi (0..$#d)
73 {
74 0 ▶ next unless $d[$wi] > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $d[$wi] > 0 0 0 0
75 0 $tmp.=$d[$wi].uc(substr($ru->[4+$wi],0,1));
76 }
77 0 ▶ $duration.='T'.$tmp if length $tmp;
Branch: 1 branch
BranchTrueFalseTotal
if length $tmp 0 0 0
78 0 ▶ $duration='-'.$duration if $d->is_negative();
Branch: 1 branch
BranchTrueFalseTotal
if $d->is_negative 0 0 0
79 0 return $duration;
80 }
81  
82 sub command
83 {
84 0 ▶ my ($epp,$domain,$rd)=@_;
Subroutine command: not called CC=17 SCAR=57.2
Pod undocumented
85 0 my $mes=$epp->message();
86  
87 0 ▶ Net::DRI::Exception::usererr_insufficient_parameters('One domain name must be specified for keyrelay operation') unless defined $domain && length $domain;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $domain and length $domain 0 0 0
Condition0%0/3
defined $domain and length $domain
!ll&&!rl&&r
000
MC/DC0%0/2
defined $domain and length $domain
defined $domain length $domain
Truth table0%0/3
A and B
A= defined $domainB= length $domain
ABresult
0X0
100
111
88 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('Invalid syntax for domain name: '.$domain) unless Net::DRI::Util::xml_is_token($domain,1,255);
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::xml_is_token($domain, 1, 255) 0 0 0
89  
90 0 my @d;
91 0 push @d,['keyrelay:name',$domain];
92  
93 0 ▶ Net::DRI::Exception::usererr_insufficient_parameters('authInfo is mandatory') unless Net::DRI::Util::has_auth($rd);
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::has_auth($rd) 0 0 0
94 0 ▶ push @d,['keyrelay:authInfo',['domain:pw',$rd->{auth}->{pw},exists $rd->{auth}->{roid} ? { 'roid' => $rd->{auth}->{roid} } : undef]];
Branch: 1 branch
BranchTrueFalseTotal
exists $rd->{'auth'}{'roid'} ? : 0 0 0
95  
96 0 ▶ Net::DRI::Exception::usererr_insufficient_parameters('key is mandatory') unless Net::DRI::Util::has_key($rd,'key');
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::has_key($rd, "key") 0 0 0
97 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('key must be a single ref hash or a ref array of ref hashes') unless ref $rd->{key} eq 'ARRAY' || ref $rd->{key} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $rd->{"key"} eq "ARRAY" or ref $rd->{"key"} eq "HASH" 0 0 0
Condition0%0/3
ref $rd->{"key"} eq "ARRAY" or ref $rd->{"key"} eq "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $rd->{"key"} eq "ARRAY" or ref $rd->{"key"} eq "HASH"
ref $rd->{"key"} eq "ARRAY" ref $rd->{"key"} eq "HASH"
Truth table0%0/3
A or B
A= ref $rd->{"key"} eq "ARRAY"B= ref $rd->{"key"} eq "HASH"
ABresult
1X1
011
000
98 0 ▶ my @keys = ref $rd->{key} eq 'ARRAY' ? @{$rd->{key}} : ($rd->{key});
Branch: 1 branch
BranchTrueFalseTotal
ref $rd->{'key'} eq 'ARRAY' ? : 0 0 0
99 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('key must be a single ref hash or a ref array of ref hashes') if grep { ref $_ ne 'HASH' } @keys;
Branch: 1 branch
BranchTrueFalseTotal
if grep {ref $_ ne "HASH";} @keys 0 0 0
100 0 foreach my $kd (@keys)
101 {
102 0 my @dd;
103 0 ▶ Net::DRI::Exception::usererr_insufficient_parameters('secdns is mandatory') unless Net::DRI::Util::has_key($kd,'secdns');
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::has_key($kd, "secdns") 0 0 0
104 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('secdns value must be a single ref hash') unless ref $kd->{secdns} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $kd->{"secdns"} eq "HASH" 0 0 0
105 0 push @dd,['keyrelay:keyData',Net::DRI::Protocol::EPP::Extensions::SecDNS::format_keydata($kd->{secdns})];
106  
107 ## Now optional parameters
108 0 ▶ if (Net::DRI::Util::has_key($kd,'expiry'))
Branch: 1 branch
BranchTrueFalseTotal
if (Net::DRI::Util::has_key($kd, "expiry")) 0 0 0
109 {
110 0 my $exp=$kd->{expiry};
111 0 ▶ if (Net::DRI::Util::is_class($exp,'DateTime'))
Branch: 2 branches
BranchTrueFalseTotal
if (Net::DRI::Util::is_class($exp, 'DateTime')) { } 0 0 0
elsif (Net::DRI::Util::is_class($exp, 'DateTime::Duration')) { } 0 0 0
112 {
113 0 push @dd,['keyrelay:expiry',['keyrelay:absolute',$exp->strftime('%FT%T.%6N%z')]];
114 } elsif (Net::DRI::Util::is_class($exp,'DateTime::Duration'))
115 {
116 0 push @dd,['keyrelay:expiry',['keyrelay:relative',format_duration($exp)]];
117 } else {
118 0 Net::DRI::Exception::usererr_invalid_parameters('expiry value must be a DateTime or a DateTime::Duration object');
119 }
120 }
121 0 push @d,['keyrelay:keyRelayData',@dd];
122 }
123  
124 0 $mes->command(['create','keyrelay:create', $mes->nsattrs('keyrelay')]);
125 0 $mes->command_body(\@d);
126  
127 0 return;
128 }
129  
130 sub parse_duration
131 {
132 0 ▶ my ($po,$dur)=@_;
Subroutine parse_duration: not called CC=5 SCAR=34.0
Pod undocumented
133 0 state $rm1={ qw/Y years M months W weeks D days/ };
134 0 state $rm2={ qw/H hours M minutes S seconds/ };
135 0 my $rm=$rm1;
136 0 my $tmp=$dur;
137 0 my @d;
138 0 ▶ Net::DRI::Exception::err_assert('Unknown duration format: '.$tmp) unless $tmp=~s/^P//;
Branch: 1 branch
BranchTrueFalseTotal
unless $tmp =~ s/^P// 0 0 0
139 0 ▶ while($tmp=~m/(\d+\S|T)/g)
Branch: 1 branch
BranchTrueFalseTotal
if ($tmp =~ /(\d+\S|T)/g) 0 0 0
140 {
141 0 my $token=$1;
142 0 ▶ if ($token eq 'T')
Branch: 1 branch
BranchTrueFalseTotal
if ($token eq "T") 0 0 0
143 {
144 0 $rm=$rm2;
145 0 next;
146 }
147 0 my ($v,$t)=($token=~m/^(\d+)(\S)$/);
148 0 ▶ Net::DRI::Exception::err_assert('Unknown duration token: '.$token.' in '.$dur) unless exists $rm->{$t};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $rm->{$t} 0 0 0
149 0 push @d,$rm->{$t},$v;
150 }
151 0 return $po->create_local_object('duration',@d);
152 }
153  
154 sub notification_parse
155 {
156 0 ▶ my ($po,$otype,$oaction,$oname,$rinfo)=@_;
Subroutine notification_parse: not called CC=9 SCAR=45.0
Pod undocumented
157 0 my $mes=$po->message();
158 0 ▶ return unless $mes->is_success();
Branch: 1 branch
BranchTrueFalseTotal
unless $mes->is_success 0 0 0
159  
160 0 my $data=$mes->get_response('keyrelay', 'infData');
161 0 ▶ return unless defined $data;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data 0 0 0
162  
163 0 my %r = ( type => 'keyrelay' );
164 0 foreach my $el (Net::DRI::Util::xml_list_children($data))
165 {
166 0 my ($name,$node)=@$el;
167 0 ▶ if ($name eq 'name')
Branch: 5 branches
BranchTrueFalseTotal
if ($name eq 'name') { } 0 0 0
elsif ($name eq 'authInfo') { } 0 0 0
elsif ($name eq 'keyRelayData') { } 0 0 0
elsif ($name eq 'crDate') { } 0 0 0
elsif ($name =~ /^(?:reID|acID)$/) { } 0 0 0
168 {
169 0 $r{name} = $oname = $node->textContent();
170 } elsif ($name eq 'authInfo')
171 {
172 0 $r{auth}={pw => Net::DRI::Util::xml_child_content($node,$mes->ns('domain'),'pw')};
173 } elsif ($name eq 'keyRelayData')
174 {
175 0 push @{$r{key}}, _parse_keyrelay($po,$node);
176 } elsif ($name eq 'crDate')
177 {
178 0 $r{date}=$po->parse_iso8601($node->textContent());
179 } elsif ($name=~m/^(?:reID|acID)$/)
180 {
181 0 $r{$name}=$node->textContent();
182 }
183 }
184  
185 0 $rinfo->{domain}->{$oname}->{relay}=\%r;
186  
187 0 return;
188 }
189  
190 sub _parse_keyrelay
191 {
192 0 ▶ my ($po, $data)=@_;
Subroutine _parse_keyrelay: not called CC=6 SCAR=37.4
193  
194 0 my $mes=$po->message();
195 0 my $ns=$mes->ns('keyrelay');
196  
197 0 my %r;
198 0 foreach my $el (Net::DRI::Util::xml_list_children($data))
199 {
200 0 my ($name,$node)=@$el;
201 0 ▶ if ($name eq 'keyData')
Branch: 2 branches
BranchTrueFalseTotal
if ($name eq 'keyData') { } 0 0 0
elsif ($name eq 'expiry') { } 0 0 0
202 {
203 0 my %n;
204 0 Net::DRI::Protocol::EPP::Extensions::SecDNS::parse_keydata($node,\%n);
205 0 $r{secdns}=\%n;
206 } elsif ($name eq 'expiry')
207 {
208 0 my $exp;
209 0 ▶ if (defined($exp=Net::DRI::Util::xml_child_content($node,$ns,'absolute')))
Branch: 2 branches
BranchTrueFalseTotal
if (defined($exp = Net::DRI::Util::xml_child_content($node, $ns, 'absolute'))) { } 0 0 0
elsif (defined($exp = Net::DRI::Util::xml_child_content($node, $ns, 'relative'))) { } 0 0 0
210 {
211 0 $r{expiry}=$po->parse_iso8601($exp);
212 } elsif (defined($exp=Net::DRI::Util::xml_child_content($node,$ns,'relative')))
213 {
214 0 $r{expiry}=parse_duration($po,$exp);
215 }
216 }
217 }
218  
219 0 return \%r;
220 }
221  
222 ####################################################################################################
223 1 1;
224  
225 __END__
226  
227 =pod
228  
229 =head1 NAME
230  
231 Net::DRI::Protocol::EPP::Extensions::KeyRelay - EPP Key Relay mapping (draft-ietf-eppext-keyrelay-12) for Net::DRI
232  
233 =head1 DESCRIPTION
234  
235 Please see the README file for details.
236  
237 =head1 SUPPORT
238  
239 For now, support questions should be sent to:
240  
241 E<lt>netdri@dotandco.comE<gt>
242  
243 Please also see the SUPPORT file in the distribution.
244  
245 =head1 SEE ALSO
246  
247 E<lt>http://www.dotandco.com/services/software/Net-DRI/E<gt>
248  
249 =head1 AUTHOR
250  
251 Patrick Mevzek, E<lt>netdri@dotandco.comE<gt>
252  
253 =head1 COPYRIGHT
254  
255 Copyright (c) 2013,2015-2017,2018 Patrick Mevzek <netdri@dotandco.com>.
256 All rights reserved.
257  
258 This program is free software; you can redistribute it and/or modify
259 it under the terms of the GNU General Public License as published by
260 the Free Software Foundation; either version 2 of the License, or
261 (at your option) any later version.
262  
263 See the LICENSE file that comes with this distribution for more details.
264  
265 =cut
« DRI/Protocol/Whois/Domain/AT.pm ↑ Summary DRI/Data/Contact/US.pm »