File Coverage

blib/lib/Net/DRI/Protocol/EPP/Core/RegistryMessage.pm
Criterion Covered Total %
statement 12 75 16.0
branch 0 28 0.0
condition 0 21 0.0
subroutine 4 8 50.0
pod 0 4 0.0
total 16 136 11.7


line stmt bran cond sub pod time code
1             ## Domain Registry Interface, EPP Registry messages commands (RFC5730)
2             ##
3             ## Copyright (c) 2006-2013,2015 Patrick Mevzek . 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::Core::RegistryMessage;
16              
17 1     1   992 use strict;
  1         2  
  1         33  
18 1     1   4 use warnings;
  1         1  
  1         23  
19              
20 1     1   4 use Net::DRI::Exception;
  1         2  
  1         22  
21 1     1   4 use Net::DRI::Util;
  1         2  
  1         568  
22              
23             =pod
24              
25             =head1 NAME
26              
27             Net::DRI::Protocol::EPP::Core::RegistryMessage - EPP Registry messages commands (RFC5730) for Net::DRI
28              
29             =head1 DESCRIPTION
30              
31             Please see the README file for details.
32              
33             =head1 SUPPORT
34              
35             For now, support questions should be sent to:
36              
37             Enetdri@dotandco.comE
38              
39             Please also see the SUPPORT file in the distribution.
40              
41             =head1 SEE ALSO
42              
43             Ehttp://www.dotandco.com/services/software/Net-DRI/E
44              
45             =head1 AUTHOR
46              
47             Patrick Mevzek, Enetdri@dotandco.comE
48              
49             =head1 COPYRIGHT
50              
51             Copyright (c) 2006-2013,2015 Patrick Mevzek .
52             All rights reserved.
53              
54             This program is free software; you can redistribute it and/or modify
55             it under the terms of the GNU General Public License as published by
56             the Free Software Foundation; either version 2 of the License, or
57             (at your option) any later version.
58              
59             See the LICENSE file that comes with this distribution for more details.
60              
61             =cut
62              
63             ####################################################################################################
64              
65             sub register_commands
66             {
67 0     0 0   my ($class,$version)=@_;
68 0           my %tmp=(
69             retrieve => [ \&pollreq, \&parse_poll ],
70             delete => [ \&pollack ],
71             );
72              
73 0           return { 'message' => \%tmp };
74             }
75              
76             sub pollack
77             {
78 0     0 0   my ($epp,$msgid)=@_;
79 0           my $mes=$epp->message();
80 0 0         Net::DRI::Exception::usererr_invalid_parameters('In EPP, you must specify the message id (XML token) you want to delete') unless Net::DRI::Util::xml_is_token($msgid);
81 0           $mes->command([['poll',{op=>'ack',msgID=>$msgid}]]);
82 0           return;
83             }
84              
85             sub pollreq
86             {
87 0     0 0   my ($epp,$msgid)=@_;
88 0 0         Net::DRI::Exception::usererr_invalid_parameters('In EPP, you can not specify the message id you want to retrieve') if defined($msgid);
89 0           my $mes=$epp->message();
90 0           $mes->command([['poll',{op=>'req'}]]);
91 0           return;
92             }
93              
94             ## We take into account all parse functions, to be able to parse any result
95             sub parse_poll
96             {
97 0     0 0   my ($po,$otype,$oaction,$oname,$rinfo)=@_;
98 0 0         return if exists $rinfo->{_processing_parse_poll}; ## calling myself here would be a very bad idea !
99 0           my $mes=$po->message();
100 0 0         return unless $mes->is_success();
101              
102 0           my $msgid=$mes->msg_id();
103 0 0 0       return unless (defined($msgid) && $msgid);
104 0           $rinfo->{message}->{session}->{last_id}=$msgid; ## needed here and not lower below, in case of pure text registry message
105              
106             ## Was there really a registry message with some content ?
107 0 0 0       return unless ($mes->result_code() == 1301 && (defined($mes->node_resdata()) || defined($mes->node_extension()) || defined($mes->node_msg())));
      0        
108              
109 0           my $rd=$rinfo->{message}->{$msgid}; ## already partially filled by Message::parse()
110 0           my ($totype,$toaction,$toname); ## $toaction will remain undef, but could be $haction if only one
111 0           my %info;
112 0           my $h=$po->commands();
113              
114 0           while (my ($htype,$hv)=each(%$h))
115             {
116             ## Because of new Perl hash keys randomization, we must make sure review_complete action is done first
117             ## as it will setup $toname & such
118 0           my @k=keys(%$hv);
119 0           foreach my $haction ((grep { $_ eq 'review_complete' } @k),(sort { $a cmp $b } grep { $_ ne 'review_complete' } @k))
  0            
  0            
  0            
120             {
121 0 0 0       next if $htype eq 'message' && $haction eq 'result';
122 0           foreach my $t (@{$hv->{$haction}})
  0            
123             {
124 0           my $pf=$t->[1];
125 0 0 0       next unless (defined($pf) && (ref($pf) eq 'CODE'));
126 0           $info{_processing_parse_poll}=1;
127 0           $pf->($po,$totype,$toaction,$toname,\%info);
128 0           delete $info{_processing_parse_poll};
129 0           my @tmp=grep { $_ ne '_internal' } keys %info;
  0            
130 0 0         next unless @tmp;
131 0 0         next if defined($toname); ## this must be there and not optimised as a last call further below as there can be multiple information to parse for a given $toname
132 0 0         Net::DRI::Exception::err_assert('EPP::parse_poll can not handle multiple types !') unless @tmp==1;
133 0           $totype=$tmp[0];
134 0           @tmp=keys %{$info{$totype}};
  0            
135 0 0         Net::DRI::Exception::err_assert('EPP::parse_poll can not handle multiple names !') unless @tmp==1; ## this may happen for check_multi !
136 0           $toname=$tmp[0];
137 0           $info{$totype}->{$toname}->{name}=$toname;
138             }
139             }
140             }
141              
142             ## If message not completely in the node, we have to parse something !
143 0 0 0       Net::DRI::Exception::err_assert('EPP::parse_poll was not able to parse anything, please report !') if ((defined($mes->node_resdata()) || defined($mes->node_extension())) && ! defined $toname);
      0        
144              
145             ## Copy local %info into $rd (which is in fact global info as set above) someway (we're working with references)
146             ## Here, $rd=$rinfo->{message}->{$msgid}
147 0           $rd->{object_type}=$totype;
148 0           $rd->{object_id}=$toname; ## this has to be taken broadly, it is in fact a name for domains and hosts
149 0           while(my ($k,$v)=each(%{$info{$totype}->{$toname}}))
  0            
150             {
151 0           $rd->{$k}=$v;
152             }
153 0 0         if (exists $info{message}->{$msgid})
154             {
155 0           while(my ($k,$v)=each(%{$info{message}->{$msgid}}))
  0            
156             {
157 0           $rd->{$k}=$v;
158             }
159             }
160             ## Also update data about the queried object, for easier access
161 0           while(my ($k,$v)=each(%$rd))
162             {
163 0           $rinfo->{$totype}->{$toname}->{$k}=$v;
164             }
165 0           return;
166             }
167              
168             ####################################################################################################
169             1;