DRI/Protocol/IRIS/XCP.pm

filter: Statementstmt 26.1% 28 / 107 Branchbran 0.0% 0 / 46 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 50.0% 9 / 18 Podpod 0.0% 0 / 9 totaltotal 18.6% 37 / 198 CC 28 SCAR 44.1
CC
28
Cov
17%
read_data
210.0
write_chunk
72.0
parse_block_header
20.0
CRAP 81.9
« DRI/Transport/HTTP/SOAPWSDL.pm ↑ Summary DRI/Protocol/EPP/Extensions/E164Validation.pm »
1 ## Domain Registry Interface, IRIS XCP Connection handling
2 ##
3 ## Copyright (c) 2008-2010 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::IRIS::XCP;
16  
17 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
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::Util;
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::Data::Raw;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use Net::DRI::Protocol::ResultStatus;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use Net::DRI::Protocol::IRIS::Core;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 =pod
30  
31 =head1 NAME
32  
33 Net::DRI::Protocol::IRIS::XCP - IRIS XCP Connection Handling (RFC4992) for Net::DRI
34  
35 =head1 DESCRIPTION
36  
37 Please see the README file for details.
38  
39 This is only a preliminary basic implementation, with only SASL PLAIN support.
40  
41 There is currently no known public server speaking this protocol.
42  
43 =head1 CURRENT LIMITATIONS
44  
45 =over
46  
47 =item *
48  
49 Nothing is parsed from server greeting message
50  
51 =item *
52  
53 Only SASL PLAIN is handled
54  
55 =item *
56  
57 Blocks split over multiple chunks are not handled, except for application data
58  
59 =item *
60  
61 Nothing is parsed in authentication success result from server
62  
63 =item *
64  
65 Only chunk types "application data", "authentication success" and "authentication failure"
66 are recognized and parsed.
67  
68 =back
69  
70 =head1 SUPPORT
71  
72 For now, support questions should be sent to:
73  
74 E<lt>netdri@dotandco.comE<gt>
75  
76 Please also see the SUPPORT file in the distribution.
77  
78 =head1 SEE ALSO
79  
80 E<lt>http://www.dotandco.com/services/software/Net-DRI/E<gt>
81  
82 =head1 AUTHOR
83  
84 Patrick Mevzek, E<lt>netdri@dotandco.comE<gt>
85  
86 =head1 COPYRIGHT
87  
88 Copyright (c) 2008-2010 Patrick Mevzek <netdri@dotandco.com>.
89 All rights reserved.
90  
91 This program is free software; you can redistribute it and/or modify
92 it under the terms of the GNU General Public License as published by
93 the Free Software Foundation; either version 2 of the License, or
94 (at your option) any later version.
95  
96 See the LICENSE file that comes with this distribution for more details.
97  
98 =cut
99  
100 ####################################################################################################
101  
102 sub parse_greeting ## §4.2
103 0 ▶{
Subroutine parse_greeting: not called CC=1 SCAR=6.9
Pod undocumented
104 0 my $dr=shift;
105 ## TODO: really parse something ?
106 0 return Net::DRI::Protocol::ResultStatus->new_success('COMMAND_SUCCESSFUL','Greeting OK','en');
107 }
108  
109 sub read_data # §4
110 0 ▶{
Subroutine read_data: not called CC=14 SCAR=53.5
Pod undocumented
111 0 my ($class,$to,$sock)=@_;
112  
113 0 my $data;
114 0 ▶ $sock->sysread($data,1) or die(Net::DRI::Protocol::ResultStatus->new_error('COMMAND_FAILED_CLOSING','Unable to read registry reply (block header): '.$!,'en'));
Branch: 1 branch
BranchTrueFalseTotal
$sock->sysread($data, 1) or die "Net::DRI::Protocol::ResultStatus"->new_error("COMMAND_FAILED_CLOSING", 'Unable to read registry reply (block header): ' . $!, "en") 0 0 0
115 0 my $hdr=substr($data,0,1);
116  
117 0 my $keepopen=parse_block_header($hdr);
118 0 ▶ $to->send_logout() unless ($keepopen); ## will not truly send anything, as there is no logout, but will properly close the socket and prepare everything as needed for next connection
Branch: 1 branch
BranchTrueFalseTotal
unless $keepopen 0 0 0
119  
120 ## We do not handle blocks split over multiple chunks, except for application data
121 0 my $m='';
122 0 my ($lastchunk,$datacomplete,$chunktype);
123 0 ▶ while(($lastchunk,$datacomplete,$chunktype,$data)=parse_chunk($sock))
Branch: 1 branch
BranchTrueFalseTotal
if (() = parse_chunk($sock)) 0 0 0
124 {
125 0 ▶ if ($chunktype==4+2+1) ## ad=application data
Branch: 4 branches
BranchTrueFalseTotal
if ($chunktype == 7) { } 0 0 0
elsif ($chunktype == 4) { } 0 0 0
elsif ($chunktype == 5) { } 0 0 0
elsif ($chunktype == 6) { } 0 0 0
126 {
127 0 $m.=$data;
128 } elsif ($chunktype==4+0+0)
129 {
130 0 die(Net::DRI::Protocol::ResultStatus->new_error('COMMAND_SYNTAX_ERROR','Extra SASL data returned by server, currently not handled','en'));
131 } elsif ($chunktype==4+0+1) ## as=authentication success
132 {
133 ## We do not parse anything. If so needed, see §6 of RFC4991, and Core::parse_authentication
134 0 next;
135 } elsif ($chunktype==4+2+0) ## af=authentication failure
136 {
137 0 my $doc=XML::LibXML->new()->parse_string(Net::DRI::Util::decode_utf8($data));
138 0 my $root=$doc->getDocumentElement();
139 0 my ($msg,$lang,$ri)=Net::DRI::Protocol::IRIS::Core::parse_authentication($root);
140  
141 0 ▶ if (!defined $msg || !defined $lang) { die(Net::DRI::Protocol::ResultStatus->new_error('COMMAND_SYNTAX_ERROR','Authentication failure without any data','en')); }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $msg and defined $lang) 0 0 0
Condition0%0/3
defined $msg and defined $lang
!ll&&!rl&&r
000
MC/DC0%0/2
defined $msg and defined $lang
defined $msg defined $lang
Truth table0%0/3
A and B
A= defined $msgB= defined $lang
ABresult
0X0
100
111
142 0 die(Net::DRI::Protocol::ResultStatus->new_error('AUTHENTICATION_ERROR',$msg,$lang,$ri));
143 } else
144 {
145 0 die(Net::DRI::Protocol::ResultStatus->new_error('COMMAND_SYNTAX_ERROR','Chunk type not handled: '.$chunktype,'en'));
146 }
147  
148 0 ▶ last if $lastchunk==1;
Branch: 1 branch
BranchTrueFalseTotal
if $lastchunk == 1 0 0 0
149 }
150 0 ▶ die(Net::DRI::Protocol::ResultStatus->new_error('COMMAND_FAILED','Last chunk does not have DC=1','en')) unless $datacomplete==1; ## TODO: does that happen IRL ?
Branch: 1 branch
BranchTrueFalseTotal
unless $datacomplete == 1 0 0 0
151 0 $m=Net::DRI::Util::decode_utf8($m); ## do it only once at end, when all chunks of application data were joined together again
152  
153 0 ▶ die(Net::DRI::Protocol::ResultStatus->new_error('COMMAND_SYNTAX_ERROR',$m? 'Got unexpected reply message: '.$m : '<empty message from server>','en')) unless ($m=~m!</(?:\S+:)?response>\s*$!s); ## we do not handle other things than plain responses (see Message)
Branch: 2 branches
BranchTrueFalseTotal
unless $m =~ m[</(?:\S+:)?response>\s*$]s 0 0 0
$m ? : 0 0 0
154 0 return Net::DRI::Data::Raw->new_from_xmlstring($m);
155 }
156  
157 sub write_message ## §5
158 0 ▶{
Subroutine write_message: not called CC=1 SCAR=6.9
Pod undocumented
159 0 my ($self,$to,$msg)=@_;
160  
161 0 my $hdr='00100000'; ## V=0, KO=1 (Keep Open please)
162 0 my $auth=Net::DRI::Util::encode_utf8($msg->authority());
163 0 return pack('B8',$hdr).pack('C',length($auth)).$auth.write_chunk('sasl',$to).write_chunk('data',$msg->as_string());
164 }
165  
166 sub keepalive
167 0 ▶{
Subroutine keepalive: not called CC=1 SCAR=6.9
Pod undocumented
168 0 my ($class,$cm)=@_;
169 0 my $mes=$cm->();
170 ## TODO: update IRIS/Message to handle this kind of messages
171 0 return $mes; ## TODO: update write_message to handle various types (should be infered from content of message probably)
172 }
173  
174 ####################################################################################################
175  
176 sub parse_block_header ## §5
177 0 ▶{
Subroutine parse_block_header: not called CC=4 SCAR=30.0
Pod undocumented
178 0 my $d=shift; ## one-octet
179 0 ▶ die(Net::DRI::Protocol::ResultStatus->new_error('COMMAND_FAILED_CLOSING','Unable to read 1 byte block header','en')) unless $d;
Branch: 1 branch
BranchTrueFalseTotal
unless $d 0 0 0
180 0 my $hdr=unpack('C',$d);
181 0 my $ver=($hdr & (128+64)) >> 6;
182 0 ▶ die(Net::DRI::Protocol::ResultStatus->new_error('COMMAND_SYNTAX_ERROR','Version unknown in block header: '.$ver,'en')) unless $ver==0;
Branch: 1 branch
BranchTrueFalseTotal
unless $ver == 0 0 0 0
183 0 my $keepopen=($hdr & 32) >> 5;
184 0 my $res=($hdr & (16+8+4+2+1));
185 0 ▶ die(Net::DRI::Protocol::ResultStatus->new_error('COMMAND_SYNTAX_ERROR','Reserved part unknown in block header: '.$res,'en')) unless $res==0;
Branch: 1 branch
BranchTrueFalseTotal
unless $res == 0 0 0 0
186 0 return $keepopen;
187 }
188  
189 sub parse_chunk_header ## §6
190 0 ▶{
Subroutine parse_chunk_header: not called CC=3 SCAR=24.8
Pod undocumented
191 0 my $d=shift; ## one-octet
192 0 ▶ die(Net::DRI::Protocol::ResultStatus->new_error('COMMAND_FAILED_CLOSING','Unable to read 1 byte chunk header','en')) unless $d;
Branch: 1 branch
BranchTrueFalseTotal
unless $d 0 0 0
193 0 my $hdr=unpack('C',$d);
194  
195 0 my $lc=($hdr & 128) >> 7; ## is last chunk in reply ?
196 0 my $dc=($hdr & 64) >> 6; ## is data complete with this chunk ?
197 0 my $res=($hdr & (32+16+8)) >> 3;
198 0 ▶ die(Net::DRI::Protocol::ResultStatus->new_error('COMMAND_SYNTAX_ERROR','Reserved part unknown in chunk header: '.$res,'en')) unless $res==0;
Branch: 1 branch
BranchTrueFalseTotal
unless $res == 0 0 0 0
199 0 my $ct=($hdr & (4+2+1)); ## chunk type
200  
201 0 return ($lc,$dc,$ct);
202 }
203  
204 sub parse_chunk ## §6
205 0 ▶{
Subroutine parse_chunk: not called CC=3 SCAR=24.8
Pod undocumented
206 0 my $sock=shift;
207 0 my $data;
208  
209 0 ▶ $sock->sysread($data,3) or die(Net::DRI::Protocol::ResultStatus->new_error('COMMAND_FAILED_CLOSING','Unable to read registry reply (chunk header of 3 bytes): '.$!,'en'));
Branch: 1 branch
BranchTrueFalseTotal
$sock->sysread($data, 3) or die "Net::DRI::Protocol::ResultStatus"->new_error("COMMAND_FAILED_CLOSING", 'Unable to read registry reply (chunk header of 3 bytes): ' . $!, "en") 0 0 0
210 0 my $hdr=substr($data,0,1);
211 0 my @hdr=parse_chunk_header($hdr);
212 0 my $length=unpack('n',substr($data,1,2));
213 0 $data=undef;
214 0 ▶ $sock->sysread($data,$length) or die(Net::DRI::Protocol::ResultStatus->new_error('COMMAND_FAILED_CLOSING','Unable to read registry reply (chunk data of '.$length.' bytes): '.$!,'en'));
Branch: 1 branch
BranchTrueFalseTotal
$sock->sysread($data, $length) or die "Net::DRI::Protocol::ResultStatus"->new_error("COMMAND_FAILED_CLOSING", 'Unable to read registry reply (chunk data of ' . $length . ' bytes): ' . $!, "en") 0 0 0
215 0 return (@hdr,$data);
216 }
217  
218 ## We handle only 'application data' type and sasl plain
219 sub write_chunk
220 0 ▶{
Subroutine write_chunk: not called CC=8 SCAR=42.8
Pod undocumented
221 0 my ($type,$data)=@_;
222 0 my $hdr;
223 0 ▶ if ($type eq 'data')
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'data') { } 0 0 0
elsif ($type eq 'nodata') { } 0 0 0
elsif ($type eq 'sasl') { } 0 0 0
224 {
225 0 $hdr='11000111'; ## LC=yes, DC=yes, CT=ad
226 0 $data=Net::DRI::Util::encode_utf8($data);
227 } elsif ($type eq 'nodata')
228 {
229 0 $hdr='11000000';
230 0 $data='';
231 } elsif ($type eq 'sasl')
232 {
233 0 my $t=$data->transport_data(); ## $data=$to here
234 0 ▶ unless (exists $t->{client_login} && $t->{client_login} && exists $t->{client_password} && $t->{client_password}) { return ''; }
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $t->{"client_login"} and $t->{"client_login"} and exists $t->{"client_password"} and $t->{"client_password"}) 0 0 0
Condition0%0/9
exists $t->{"client_login"} and $t->{"client_login"} and exists $t->{"client_password"} and $t->{"client_password"}
!ll&&!rl&&r
000
exists $t->{"client_login"} and $t->{"client_login"} and exists $t->{"client_password"}
!ll&&!rl&&r
000
exists $t->{"client_login"} and $t->{"client_login"}
!ll&&!rl&&r
000
MC/DC0%0/4
exists $t->{"client_login"} and $t->{"client_login"} and exists $t->{"client_password"} and $t->{"client_password"}
exists $t->{"client_login"} $t->{"client_login"} exists $t->{"client_password"} $t->{"client_password"}
Truth table0%0/5
A and B and C and D
A= exists $t->{"client_login"}B= $t->{"client_login"}C= exists $t->{"client_password"}D= $t->{"client_password"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
235 0 $hdr='01000100'; ## LC=no, DC=yes, CT=sd
236 ## Only SASL PLAIN is supported for now
237 0 my $sasltype='PLAIN';
238 0 $data=pack('C',length($sasltype)).$sasltype;
239 0 my $sasldata=Net::DRI::Util::encode_utf8(sprintf('%s %s %s',$t->{client_login},chr(0),$t->{client_password})); ## authcid=LOGIN, authzid=NULL, password=PASSWORD
240 0 $data.=pack('n',length($sasldata)).$sasldata;
241 }
242 0 return pack('B8',$hdr).pack('n',length($data)).$data;
243 }
244  
245 sub transport_default
246 0 ▶{
Subroutine transport_default: not called CC=1 SCAR=6.9
Pod undocumented
247 0 my ($self,$tname)=@_;
248 0 return (has_state => 1, type => 'tcp');
249 }
250  
251 ####################################################################################################
252 1 1;
« DRI/Transport/HTTP/SOAPWSDL.pm ↑ Summary DRI/Protocol/EPP/Extensions/E164Validation.pm »