DRI/Protocol/RRI/Message.pm

filter: Statementstmt 19.0% 23 / 121 Branchbran 0.0% 0 / 54 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 46.6% 7 / 15 Podpod 12.5% 1 / 8 totaltotal 13.6% 31 / 227 CC 35 SCAR 43.7
CC
35
Cov
12%
parse
156.0
as_string
132.0
get_content
56.0
CRAP 78.9
« DRI/Protocol/EPP/Extensions/DNSBE/Domain.pm ↑ Summary DRI/Protocol/EPP/Extensions/VeriSign/ZoneManagement.pm »
1 ## Domain Registry Interface, RRI Message
2 ##
3 ## Copyright (c) 2007-2009,2013 Tonnerre Lombard <tonnerre.lombard@sygroup.ch>. All rights reserved.
4 ## (c) 2018 Patrick Mevzek <netdri@dotandco.com>. All rights reserved.
5 ##
6 ## This file is part of Net::DRI
7 ##
8 ## Net::DRI is free software; you can redistribute it and/or modify
9 ## it under the terms of the GNU General Public License as published by
10 ## the Free Software Foundation; either version 2 of the License, or
11 ## (at your option) any later version.
12 ##
13 ## See the LICENSE file that comes with this distribution for more details.
14 ####################################################################################################
15  
16 package Net::DRI::Protocol::RRI::Message;
17  
18 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 ▶use XML::LibXML ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 ▶use Net::DRI::Protocol::ResultStatus;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use Net::DRI::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use Net::DRI::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 1 ▶use base qw(Class::Accessor::Chained::Fast Net::DRI::Protocol::Message);
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 __PACKAGE__->mk_accessors(qw(version command command_body cltrid svtrid result
29 errcode errmsg node_resdata result_extra_info));
30  
31 =pod
32  
33 =head1 NAME
34  
35 Net::DRI::Protocol::RRI::Message - RRI Message for Net::DRI
36  
37 =head1 DESCRIPTION
38  
39 Please see the README file for details.
40  
41 =head1 SUPPORT
42  
43 For now, support questions should be sent to:
44  
45 E<lt>tonnerre.lombard@sygroup.chE<gt>
46  
47 Please also see the SUPPORT file in the distribution.
48  
49 =head1 SEE ALSO
50  
51 E<lt>http://oss.bsdprojects.net/projects/netdri/E<gt>
52  
53 =head1 AUTHOR
54  
55 Tonnerre Lombard, E<lt>tonnerre.lombard@sygroup.chE<gt>
56  
57 =head1 COPYRIGHT
58  
59 Copyright (c) 2007-2009,2013 Tonnerre Lombard <tonnerre.lombard@sygroup.ch>.
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 new
74 {
75 0 ▶ my $class = shift;
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
76 0 my $trid = shift;
77  
78 0 my $self = {
79 result => 'uninitialized',
80 };
81  
82 0 bless($self,$class);
83  
84 0 ▶ $self->cltrid($trid) if (defined($trid) && $trid);
Branch: 1 branch
BranchTrueFalseTotal
if defined $trid and $trid 0 0 0
Condition0%0/3
defined $trid and $trid
!ll&&!rl&&r
000
MC/DC0%0/2
defined $trid and $trid
defined $trid $trid
Truth table0%0/3
A and B
A= defined $tridB= $trid
ABresult
0X0
100
111
85 0 return $self;
86 }
87  
88 sub ns
89 {
90 0 ▶ my ($self,$what)=@_;
Subroutine ns: not called CC=4 SCAR=30.0
Pod undocumented
91 0 ▶ return $self->{ns} unless defined($what);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $what 0 0 0
92  
93 0 ▶ if (ref($what) eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $what eq "HASH") 0 0 0
94 {
95 0 $self->{ns}=$what;
96 0 return $what;
97 }
98 0 ▶ return unless exists($self->{ns}->{$what});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"ns"}{$what} 0 0 0
99 0 return $self->{ns}->{$what};
100 }
101  
102 0 ▶sub is_success { return (shift->result() =~ m/^success/)? 1 : 0; }
Subroutine is_success: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
(shift())->result =~ /^success/ ? : 0 0 0
103  
104 sub result_status
105 {
106 0 ▶ my $self=shift;
Subroutine result_status: not called CC=2 SCAR=17.9
Pod undocumented
107 0 ▶ my $rs = Net::DRI::Protocol::ResultStatus->new('rri',
Branch: 1 branch
BranchTrueFalseTotal
$self->is_success ? : 0 0 0
108 ($self->is_success() ? 1000 : $self->errcode()), undef,
109 $self->is_success(), $self->errmsg(), 'en',
110 $self->result_extra_info());
111 0 $rs->_set_trid([ $self->cltrid(), $self->svtrid() ]);
112 0 return $rs;
113 }
114  
115 sub as_string
116 {
117 0 ▶ my ($self)=@_;
Subroutine as_string: not called CC=11 SCAR=48.8
Pod undocumented
118 0 my $rns=$self->ns();
119 0 my $ens=sprintf('xmlns="%s"', $rns->{rri});
120 0 my $cmdi = $self->command();
121 0 my @d;
122 0 push @d,'<?xml version="1.0" encoding="UTF-8" standalone="yes"?>';
123 0 my ($type, $cmd, $ns, $attr);
124 0 ▶ ($type, $cmd, $ns, $attr) = @{$cmdi} if (ref($cmdi) eq 'ARRAY');
Branch: 1 branch
BranchTrueFalseTotal
if ref $cmdi eq "ARRAY" 0 0 0
125  
126 0 ▶ $attr = '' unless (defined($attr));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $attr 0 0 0
127 0 $attr = ' ' . join(' ', map { $_ . '="' . $attr->{$_} . '"' }
128 0 ▶ sort { $a cmp $b } keys (%{$attr})) if (ref($attr) eq 'HASH');
Branch: 1 branch
BranchTrueFalseTotal
if ref $attr eq "HASH" 0 0 0
129  
130 0 ▶ if (defined($ns))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ns) { } 0 0 0
131 {
132 0 ▶ if (ref($ns) eq 'HASH')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $ns eq 'HASH') { } 0 0 0
133 {
134 0 $ens .= ' ' . join(' ', map { 'xmlns:' . $_ . '="' . $ns->{$_} . '"' }
135 0 sort { $a cmp $b } keys(%{$ns}));
136 0 $cmd = $type . ':' . $cmd;
137 }
138 else
139 {
140 0 $ens .= ' xmlns:' . $type . '="' . $ns . '"';
141 0 $cmd = $type . ':' . $cmd;
142 }
143 }
144 else
145 {
146 0 $cmd = $type;
147 0 $type = undef;
148 }
149  
150 0 push @d,'<registry-request '.$ens.'>';
151  
152 0 my $body=$self->command_body();
153 0 ▶ if (defined($body) && $body)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $body and $body) { } 0 0 0
Condition0%0/3
defined $body and $body
!ll&&!rl&&r
000
MC/DC0%0/2
defined $body and $body
defined $body $body
Truth table0%0/3
A and B
A= defined $bodyB= $body
ABresult
0X0
100
111
154 {
155 0 push @d,'<'.$cmd.$attr.'>';
156 0 push @d,Net::DRI::Util::xml_write($body);
157 0 push @d,'</'.$cmd.'>';
158 } else
159 {
160 0 push @d,'<'.$cmd.$attr.'/>';
161 }
162
163 ## OPTIONAL clTRID
164 0 my $cltrid=$self->cltrid();
165 0 ▶ push @d,'<ctid>'.$cltrid.'</ctid>'
Branch: 1 branch
BranchTrueFalseTotal
if defined $cltrid and $cltrid and Net::DRI::Util::xml_is_token($cltrid, 3, 64) 0 0 0
Condition0%0/6
defined $cltrid and $cltrid and Net::DRI::Util::xml_is_token($cltrid, 3, 64)
!ll&&!rl&&r
000
defined $cltrid and $cltrid
!ll&&!rl&&r
000
MC/DC0%0/3
defined $cltrid and $cltrid and Net::DRI::Util::xml_is_token($cltrid, 3, 64)
defined $cltrid $cltrid Net::DRI::Util::xml_is_token($cltrid, 3, 64)
Truth table0%0/4
A and B and C
A= defined $cltridB= $cltridC= Net::DRI::Util::xml_is_token($cltrid, 3, 64)
ABCresult
0XX0
10X0
1100
1111
166 if (defined($cltrid) && $cltrid &&
167 Net::DRI::Util::xml_is_token($cltrid,3,64));
168 0 push @d,'</registry-request>';
169  
170 0 return join('',@d);
171 }
172  
173 0 ▶sub topns { return shift->ns->{rri}; }
Subroutine topns: not called CC=1 SCAR=6.9
Pod undocumented
174  
175 sub get_content
176 {
177 0 ▶ my ($self,$nodename,$ns,$ext)=@_;
Subroutine get_content: not called CC=7 SCAR=40.3
Pod undocumented
178 0 ▶ return unless (defined($nodename) && $nodename);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $nodename and $nodename 0 0 0
Condition0%0/3
defined $nodename and $nodename
!ll&&!rl&&r
000
MC/DC0%0/2
defined $nodename and $nodename
defined $nodename $nodename
Truth table0%0/3
A and B
A= defined $nodenameB= $nodename
ABresult
0X0
100
111
179  
180 0 my @tmp;
181 0 my $n1=$self->node_resdata();
182  
183 0 ▶ @tmp=$n1->getElementsByTagNameNS($ns // $self->topns(),$nodename) if (defined($n1));
Branch: 1 branch
BranchTrueFalseTotal
if defined $n1 0 0 0
Condition0%0/3
$ns // $self->topns
l!l&&r!l&&!r
000
MC/DC0%0/2
$ns // $self->topns
$ns $self->topns
Truth table0%0/3
A // B
A= $nsB= $self->topns
ABresult
1X1
011
000
184  
185 0 ▶ return unless @tmp;
Branch: 1 branch
BranchTrueFalseTotal
unless @tmp 0 0 0
186 0 ▶ return wantarray()? @tmp : $tmp[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
187 }
188  
189 sub parse
190 {
191 0 ▶ my ($self,$dc,$rinfo)=@_;
Subroutine parse: not called CC=12 SCAR=50.5
Pod undocumented
192 0 my $trNS = $self->ns('tr');
193 0 my $parser=XML::LibXML->new();
194 0 my $xstr = $dc->as_string();
195 0 $xstr =~ s/^\s*//;
196 0 my $doc=$parser->parse_string($xstr);
197 0 my $root=$doc->getDocumentElement();
198 0 ▶ Net::DRI::Exception->die(0, 'protocol/RRI', 1,
Branch: 1 branch
BranchTrueFalseTotal
unless $root->getName eq "registry-response" 0 0 0
199 'Unsuccessfull parse, root element is not registry-response')
200 unless ($root->getName() eq 'registry-response');
201  
202 0 my @trtags = $root->getElementsByTagNameNS($trNS, 'transaction');
203 0 ▶ Net::DRI::Exception->die(0, 'protocol/RRI', 1,
Branch: 1 branch
BranchTrueFalseTotal
unless @trtags 0 0 0
204 'Unsuccessfull parse, no transaction block') unless (@trtags);
205 0 my $res = $trtags[0];
206  
207 ## result block(s)
208 0 my @results = $res->getElementsByTagNameNS($trNS,'result'); ## success indicator
209 0 foreach (@results)
210 {
211 0 $self->result($_->firstChild()->getData());
212 }
213  
214 0 ▶ if ($res->getElementsByTagNameNS($trNS,'message')) ## OPTIONAL
Branch: 1 branch
BranchTrueFalseTotal
if ($res->getElementsByTagNameNS($trNS, "message")) 0 0 0
215 {
216 0 my @msgs = $res->getElementsByTagNameNS($trNS,'message');
217 0 my $msg = $msgs[0];
218 0 my @extra = ();
219  
220 0 ▶ if (defined($msg))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $msg) 0 0 0
221 {
222 0 my @texts = $msg->getElementsByTagNameNS($trNS, 'text');
223 0 my $msgtype = $msg->getAttribute('level');
224 0 my $text = $texts[0];
225  
226 0 ▶ if ($msgtype eq 'error')
Branch: 1 branch
BranchTrueFalseTotal
if ($msgtype eq 'error') { } 0 0 0
227 {
228 0 $self->errcode($msg->getAttribute('code'));
229 0 ▶ $self->errmsg($text->getFirstChild()->getData()) if (defined($text));
Branch: 1 branch
BranchTrueFalseTotal
if defined $text 0 0 0
230 }
231 else
232 {
233 0 ▶ push @extra, { from => 'rri', type => 'text', code => $msg->getAttribute('code'), message => (defined $text ? $text->textContent() : '') };
Branch: 1 branch
BranchTrueFalseTotal
defined $text ? : 0 0 0
234 }
235 }
236 0 $self->result_extra_info(\@extra);
237 }
238  
239 0 ▶ if ($res->getElementsByTagNameNS($trNS,'data')) ## OPTIONAL
Branch: 1 branch
BranchTrueFalseTotal
if ($res->getElementsByTagNameNS($trNS, "data")) 0 0 0
240 {
241 0 $self->node_resdata(($res->getElementsByTagNameNS($trNS,'data'))[0]);
242 }
243  
244 ## trID
245 0 ▶ if ($res->getElementsByTagNameNS($trNS, 'stid'))
Branch: 1 branch
BranchTrueFalseTotal
if ($res->getElementsByTagNameNS($trNS, "stid")) 0 0 0
246 {
247 0 my @svtrid = $res->getElementsByTagNameNS($trNS, 'stid');
248 0 $self->svtrid($svtrid[0]->firstChild()->getData());
249 }
250 0 ▶ if ($res->getElementsByTagNameNS($trNS, 'ctid'))
Branch: 1 branch
BranchTrueFalseTotal
if ($res->getElementsByTagNameNS($trNS, "ctid")) 0 0 0
251 {
252 0 my @cltrid = $res->getElementsByTagNameNS($trNS, 'ctid');
253 0 $self->cltrid($cltrid[0]->firstChild()->getData());
254 }
255  
256 0 return;
257 }
258  
259 ####################################################################################################
260 1 1;
261  
« DRI/Protocol/EPP/Extensions/DNSBE/Domain.pm ↑ Summary DRI/Protocol/EPP/Extensions/VeriSign/ZoneManagement.pm »