DRI/Protocol/RRP/Message.pm

filter: Statementstmt 89.2% 91 / 102 Branchbran 81.2% 39 / 48 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 84.6% 11 / 13 Podpod 14.2% 1 / 7 totaltotal 79.4% 143 / 180 CC 30 SCAR 19.5
CC
30
Cov
84%
entities
12.0
_eppcode
12.0
as_string
7.0
CRAP 7.1
« DRI/DRD/DotCooperation.pm ↑ Summary DRI/Protocol/OVH/WS/Connection.pm »
1 ## Domain Registry Interface, RRP Message
2 ##
3 ## Copyright (c) 2005-2008,2010,2013-2014 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::RRP::Message;
16  
17 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 3 ▶use Net::DRI::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 3 ▶use Net::DRI::Protocol::ResultStatus;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 3 ▶use base qw(Class::Accessor::Chained::Fast Net::DRI::Protocol::Message);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 3 __PACKAGE__->mk_accessors(qw(version errcode errmsg command));
25  
26 =pod
27  
28 =head1 NAME
29  
30 Net::DRI::Protocol::RRP::Message - RRP Message for Net::DRI
31  
32 =head1 DESCRIPTION
33  
34 Please see the README file for details.
35  
36 =head1 SUPPORT
37  
38 For now, support questions should be sent to:
39  
40 E<lt>netdri@dotandco.comE<gt>
41  
42 Please also see the SUPPORT file in the distribution.
43  
44 =head1 SEE ALSO
45  
46 E<lt>http://www.dotandco.com/services/software/Net-DRI/E<gt>
47  
48 =head1 AUTHOR
49  
50 Patrick Mevzek, E<lt>netdri@dotandco.comE<gt>
51  
52 =head1 COPYRIGHT
53  
54 Copyright (c) 2005-2008,2010,2013-2014 Patrick Mevzek <netdri@dotandco.com>.
55 All rights reserved.
56  
57 This program is free software; you can redistribute it and/or modify
58 it under the terms of the GNU General Public License as published by
59 the Free Software Foundation; either version 2 of the License, or
60 (at your option) any later version.
61  
62 See the LICENSE file that comes with this distribution for more details.
63  
64 =cut
65  
66 ####################################################################################################
67  
68 3 our $EOL="\r\n"; ## as mandated by RFC 2832
69  
70 3 our %CODES; ## defined at bottom
71  
72 3 our %ORDER=('add_domain' => ['EntityName','DomainName','-Period','NameServer'],
73 'add_nameserver' => ['EntityName','NameServer','IPAddress'],
74 'check_domain' => ['EntityName','DomainName'],
75 'check_nameserver' => ['EntityName','NameServer'],
76 'del_domain' => ['EntityName','DomainName'],
77 'del_nameserver' => ['EntityName','NameServer'],
78 'describe' => ['-Target'],
79 'mod_domain' => ['EntityName','DomainName','NameServer','Status'],
80 'mod_nameserver' => ['EntityName','NameServer','NewNameServer','IPAddress'],
81 'quit' => [],
82 'renew_domain' => ['EntityName','DomainName','-Period','-CurrentExpirationYear'],
83 'session' => ['-Id','-Password','-NewPassword'],
84 'status_domain' => ['EntityName','DomainName'],
85 'status_nameserver' => ['EntityName','NameServer'],
86 'transfer_domain' => ['-Approve','EntityName','DomainName'],
87 );
88  
89  
90 sub new
91 {
92 19 ▶ my $proto=shift;
Subroutine new: called CC=2 SCAR=7.1
Pod documented
93 19 ▶ my $class=ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
0190
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
94  
95 19 my $self={errcode => 0};
96 19 bless($self,$class);
97  
98 19 my $trid=shift;
99  
100 19 return $self;
101 }
102  
103 1 ▶sub is_success { return (shift->errcode()=~m/^2/)? 1 : 0; }
Subroutine is_success: called CC=2 SCAR=7.6
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
(shift())->errcode =~ /^2/ ? : 1 0 1
104  
105 sub result_status
106 {
107 0 ▶ my $self=shift;
Subroutine result_status: not called CC=1 SCAR=6.9
Pod undocumented
108 0 my $code=$self->errcode();
109 0 my $eppcode=_eppcode($code);
110 0 return Net::DRI::Protocol::ResultStatus->new('rrp',$code,$eppcode,$self->is_success(),$self->errmsg(),'en');
111 }
112  
113 sub _eppcode
114 {
115 0 ▶ my $code=shift;
Subroutine _eppcode: not called CC=3 SCAR=24.8
116 0 ▶ return (defined $code && exists $CODES{$code})? $CODES{$code} : 'COMMAND_FAILED';
Branch: 1 branch
BranchTrueFalseTotal
defined $code && exists $Net::DRI::Protocol::RRP::Message::CODES{$code} ? : 0 0 0
Condition0%0/3
defined $code and exists $Net::DRI::Protocol::RRP::Message::CODES{$code}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $code and exists $Net::DRI::Protocol::RRP::Message::CODES{$code}
defined $code exists $Net::DRI::Protocol::RRP::Message::CODES{$code}
Truth table0%0/3
A and B
A= defined $codeB= exists $Net::DRI::Protocol::RRP::Message::CODES{$code}
ABresult
0X0
100
111
117 }
118  
119 sub as_string
120 {
121 18 ▶ my $self=shift;
Subroutine as_string: called CC=7 SCAR=19.5
Pod undocumented
122 18 my $cmd=$self->command();
123 18 my $ent=$self->entities('EntityName');
124 18 my $allopt=$self->options();
125 18 my $order=lc($cmd);
126 18 ▶ $order.='_'.lc($ent) if ($ent);
Branch: 1 branch
BranchTrueFalseTotal
if $ent 15 3 18
127  
128 18 ▶ Net::DRI::Exception->die(1,'protocol/RRP',5,'Unknown command '.$cmd.', no order found') unless (exists($ORDER{$order}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Net::DRI::Protocol::RRP::Message::ORDER{$order} 0 18 18
129  
130 18 my @r=($cmd);
131 18 foreach my $o (@{$ORDER{$order}})
132 {
133 48 ▶ if ($o=~m/^-(.+)$/) ## Option
Branch: 1 branch
BranchTrueFalseTotal
if ($o =~ /^-(.+)$/) { } 11 37 48
134 {
135 11 ▶ push @r,$o.':'.$allopt->{$1} if exists($allopt->{$1});
Branch: 1 branch
BranchTrueFalseTotal
if exists $allopt->{$1} 9 2 11
136 } else ## Entity
137 {
138 37 my @e=$self->entities($o);
139 37 ▶ push @r,map { $o.':'.$_ } @e if @e;
Branch: 1 branch
BranchTrueFalseTotal
if @e 35 2 37
140 }
141 }
142  
143 18 push @r,'.'.$EOL; ## end
144 18 return join($EOL,@r);
145 }
146  
147 sub parse
148 {
149 2 ▶ my ($self,$dc)=@_; ## DataRaw
Subroutine parse: called CC=5 SCAR=16.4
Pod undocumented
150 2 ▶ my @todo=map { my $s=$_; $s=~s/\r*\n*\r*$//; $s; } grep { defined() && ! /^\s+$/ } $dc->as_array();
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and not /^\s+$/ 6 0 6
151 2 ▶ Net::DRI::Exception->die(0,'protocol/RRP',1,'Unsuccessfull parse (last line not a lonely dot ') unless (pop(@todo) eq '.');
Branch: 1 branch
BranchTrueFalseTotal
unless pop @todo eq "." 0 2 2
152  
153 2 my $t=shift(@todo);
154 2 $t=~m/^(\d+)\s+(\S.*\S)\s*$/;
155 2 $self->errcode($1);
156 2 $self->errmsg($2);
157  
158 2 foreach my $l (@todo)
159 {
160 2 my ($lh,$rh)=split(/:/,$l,2);
161 2 ▶ if ($lh=~m/^-(.+)$/) ## option
Branch: 1 branch
BranchTrueFalseTotal
if ($lh =~ /^-(.+)$/) { } 0 2 2
162 {
163 0 $self->options($1,$rh);
164 } else ## entity
165 {
166 2 $self->entities($lh,$rh);
167 }
168 }
169 2 return;
170 }
171  
172 sub entities
173 {
174 95 ▶ my ($self,$k,$v)=@_;
Subroutine entities: called CC=12 SCAR=24.9
Pod undocumented
175 95 ▶ if (defined($k))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $k) { } 93 2 95
176 {
177 93 ▶ if (defined($v)) ## key + value => add
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v) { } 35 58 93
178 {
179 35 ▶ $self->{entities}={} unless exists($self->{entities});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"entities"} 15 20 35
180 35 ▶ my @v=(ref($v) eq 'ARRAY')? @$v : ($v);
Branch: 1 branch
BranchTrueFalseTotal
ref $v eq 'ARRAY' ? : 3 32 35
181 35 ▶ if (exists($self->{entities}->{$k}))
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'entities'}{$k}) { } 0 35 35
182 {
183 0 push @{$self->{entities}->{$k}},@v;
184 } else
185 {
186 35 $self->{entities}->{$k}=\@v;
187 }
188 35 return $self;
189 } else ## only key given => get value of key
190 {
191 58 ▶ return unless (exists($self->{entities}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"entities"} 3 55 58
192 55 $k=lc($k);
193 55 ▶ foreach my $i ( sort { $a cmp $b } keys %{$self->{entities}} ) { next if lc $i ne $k; $k=$i; last; };
Branch: 1 branch
BranchTrueFalseTotal
if lc $i ne $k 43 53 96
194 55 ▶ return unless (exists($self->{entities}->{$k}));
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"entities"}{$k} 2 53 55
195 53 ▶ return wantarray()? @{$self->{entities}->{$k}} : join(' ',@{$self->{entities}->{$k}});
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 35 18 53
196 }
197 } else ## nothing given => get list of keys
198 {
199 2 ▶ return exists $self->{entities} ? ( sort { $a cmp $b } keys %{$self->{entities}} ) : ();
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'entities'} ? : 1 1 2
200 }
201 }
202  
203 sub options
204 {
205 27 ▶ my ($self,$rh1,$v)=@_;
Subroutine options: called CC=5 SCAR=16.4
Pod undocumented
206 27 ▶ if (defined($rh1)) ## something to add
Branch: 1 branch
BranchTrueFalseTotal
if (defined $rh1) 8 19 27
207 {
208 8 ▶ $self->{options}={} unless exists($self->{options});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"options"} 6 2 8
209 8 ▶ if (ref($rh1) eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $rh1 eq 'HASH') { } 0 8 8
210 {
211 0 $self->{options}={ %{$self->{options}}, %$rh1 };
212 } else
213 {
214 8 $self->{options}->{$rh1}=$v;
215 }
216 8 return $self;
217 }
218 19 ▶ return exists($self->{options})? $self->{options} : {};
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'options'} ? : 7 12 19
219 }
220  
221 ####################################################################################################
222  
223 3 %CODES=(
224 200 => 1000, # Command completed successfully
225 210 => 2303, # Domain name available => Object does not exist
226 211 => 2302, # Domain name not available => Object exists
227 212 => 2303, # Name server available => Object does not exist
228 213 => 2302, # Name server not available => Object exists
229 220 => 1500, # Command completed successfully. Server closing connection
230 420 => 2500, # Command failed due to server error. Server closing connection
231 421 => 2400, # Command failed due to server error. Client should try again
232 500 => 2000, # Invalid command name => Unknown command
233 501 => 2102, # Invalid command option => Unimplemented option
234 502 => 2005, # Invalid entity value => Parameter value syntax error
235 503 => 2005, # Invalid attribute name => Parameter value syntax error
236 504 => 2003, # Missing required attribute => Required parameter missing
237 505 => 2005, # Invalid attribute value syntax => Parameter value syntax error
238 506 => 2004, # Invalid option value => Parameter value range error
239 507 => 2001, # Invalid command format => Command syntax error
240 508 => 2003, # Missing required entity => Required parameter missing
241 509 => 2003, # Missing command option => Required parameter missing
242 510 => 2306, # Invalid encoding => Parameter value policy error (RRP v2.0)
243 520 => 2500, # Server closing connection. Client should try opening new connection => Command failed; server closing connection
244 521 => 2502, # Too many sessions open. Server closing connection => Session limit exceeded; server closing connection
245 530 => 2200, # Authentication failed => Authentication error
246 531 => 2201, # Authorization failed => Authorization error
247 532 => 2305, # Domain names linked with name server => Object association prohibits operation
248 533 => 2305, # Domain name has active name servers => Object association prohibits operation
249 534 => 2301, # Domain name has not been flagged for transfer => Object not pending transfer
250 535 => 2306, # Restricted IP address => Parameter value policy error
251 536 => 2300, # Domain already flagged for transfer => Object pending transfer
252 540 => 2308, # Attribute value is not unique => Data management policy violation
253 541 => 2005, # Invalid attribute value => Parameter value syntax error
254 542 => 2306, # Invalid old value for an attribute => Parameter value policy error
255 543 => 2308, # Final or implicit attribute cannot be updated => Data management policy violation
256 544 => 2304, # Entity on hold => Object status prohibits operation
257 545 => 2308, # Entity reference not found => Data management policy violation
258 546 => 2104, # Credit limit exceeded => Billing failure
259 547 => 2002, # Invalid command sequence => Command use error
260 548 => 2105, # Domain is not up for renewal => Object is not eligible for renewal
261 549 => 2400, # Command failed
262 550 => 2308, # Parent domain not registered => Data management policy violation
263 551 => 2308, # Parent domain status does not allow for operation => Data management policy violation
264 552 => 2304, # Domain status does not allow for operation => Object status prohibits operation
265 553 => 2300, # Operation not allowed. Domain pending transfer => Object pending transfer
266 554 => 2302, # Domain already registered => Object exists
267 555 => 2105, # Domain already renewed => Object is not eligible for renewal
268 556 => 2308, # Maximum registration period exceeded => Data management policy violation
269 557 => 2304, # Name server locked => Object status prohibits operation (RRP v2.0)
270 );
271  
272 ########################################################################
273 3 1;
« DRI/DRD/DotCooperation.pm ↑ Summary DRI/Protocol/OVH/WS/Connection.pm »