1## Domain Registry Interface, .LU Contact EPP extension commands
2##
3## Copyright (c) 2007,2008 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#
16####################################################################################################
17
18package Net::DRI::Protocol::EPP::Extensions::LU::Contact;
19
20use strict;
21
22use Net::DRI::Util;
23
24our $VERSION=do { my @r=(q$Revision: 1.3 $=~/\d+/g); sprintf("%d".".%02d" x $#r, @r); };
25
26=pod
27
28=head1 NAME
29
30Net::DRI::Protocol::EPP::Extensions::LU::Contact - .LU EPP Contact extension commands for Net::DRI
31
32=head1 DESCRIPTION
33
34Please see the README file for details.
35
36=head1 SUPPORT
37
38For now, support questions should be sent to:
39
40E<lt>netdri@dotandco.comE<gt>
41
42Please also see the SUPPORT file in the distribution.
43
44=head1 SEE ALSO
45
46E<lt>http://www.dotandco.com/services/software/Net-DRI/E<gt>
47
48=head1 AUTHOR
49
50Patrick Mevzek, E<lt>netdri@dotandco.comE<gt>
51
52=head1 COPYRIGHT
53
54Copyright (c) 2007,2008 Patrick Mevzek <netdri@dotandco.com>.
55All rights reserved.
56
57This program is free software; you can redistribute it and/or modify
58it under the terms of the GNU General Public License as published by
59the Free Software Foundation; either version 2 of the License, or
60(at your option) any later version.
61
62See the LICENSE file that comes with this distribution for more details.
63
64=cut
65
66####################################################################################################
67
68sub register_commands
69{
70 my ($class,$version)=@_;
71 my %tmp=(
72          info   => [ undef, \&info_parse ],
73          create => [ \&create, undef     ],
74          update => [ \&update, undef     ],
75         );
76
77 return { 'contact' => \%tmp };
78}
79
80sub build_command_extension
81{
82 my ($mes,$epp,$tag)=@_;
83 return $mes->command_extension_register($tag,sprintf('xmlns:dnslu="%s" xsi:schemaLocation="%s %s"',$mes->nsattrs('dnslu')));
84}
85
86####################################################################################################
87
88sub info_parse
89{
90 my ($po,$otype,$oaction,$oname,$rinfo)=@_;
91 my $mes=$po->message();
92 return unless $mes->is_success();
93
94 my $infdata=$mes->get_extension('dnslu','ext');
95 return unless $infdata;
96 my $ns=$mes->ns('dnslu');
97 $infdata=$infdata->getChildrenByTagNameNS($ns,'resData');
98 return unless $infdata->size();
99 $infdata=$infdata->shift()->getChildrenByTagNameNS($ns,'infData');
100 return unless $infdata->size();
101 $infdata=$infdata->shift()->getChildrenByTagNameNS($ns,'contact');
102 return unless $infdata->size();
103 $infdata=$infdata->shift();
104
105 my $co=$rinfo->{contact}->{$oname}->{self};
106
107 my $t=$infdata->getChildrenByTagNameNS($ns,'type');
108 $co->type($t->shift->getFirstChild()->getData()) if $t->size();
109
110 my $c=$infdata->getChildrenByTagNameNS($ns,'disclose');
111 if ($c->size())
112 {
113  $c=$c->shift()->getFirstChild();
114  $co->disclose({}) unless defined($co->disclose());
115  while($c)
116  {
117   next unless ($c->nodeType() == 1); ## only for element nodes
118   my $name=$c->localname() || $c->nodeName();
119   next unless $name;
120   $co->disclose()->{$name.'_loc'}=$c->getAttribute('flag');
121  } continue { $c=$c->getNextSibling(); }
122 }
123}
124
125sub build_disclose
126{
127 my ($rd,$type)=@_;
128 return () unless (defined($rd) && (ref($rd) eq 'HASH') && %$rd);
129 my @d=();
130 push @d,['dnslu:name',{flag=>$rd->{name_loc}}] if (exists($rd->{name_loc}) && Net::DRI::Util::xml_is_boolean($rd->{name_loc}));
131 push @d,['dnslu:addr',{flag=>$rd->{addr_loc}}] if (exists($rd->{addr_loc}) && Net::DRI::Util::xml_is_boolean($rd->{addr_loc}));
132 if ($type eq 'contact')
133 {
134  push @d,['dnslu:org',{flag=>$rd->{org_loc}}] if (exists($rd->{org_loc}) && Net::DRI::Util::xml_is_boolean($rd->{org_loc}));
135  push @d,['dnslu:voice',{flag=>$rd->{voice}}] if (exists($rd->{voice}) && Net::DRI::Util::xml_is_boolean($rd->{voice}));
136  push @d,['dnslu:fax',{flag=>$rd->{fax}}] if (exists($rd->{fax}) && Net::DRI::Util::xml_is_boolean($rd->{fax}));
137  push @d,['dnslu:email',{flag=>$rd->{email}}] if (exists($rd->{email}) && Net::DRI::Util::xml_is_boolean($rd->{email}));
138 }
139 return \@d;
140}
141
142sub create
143{
144 my ($epp,$contact)=@_;
145 my $mes=$epp->message();
146
147 ## validate() has been called, we are sure that type exists
148 my @n;
149 push @n,['dnslu:type',$contact->type()];
150 my $rd=build_disclose($contact->disclose(),$contact->type());
151 push @n,['dnslu:disclose',@$rd] if $rd;
152
153 my $eid=build_command_extension($mes,$epp,'dnslu:ext');
154 $mes->command_extension($eid,['dnslu:create',['dnslu:contact',@n]]);
155}
156
157sub update
158{
159 my ($epp,$domain,$todo)=@_;
160 my $mes=$epp->message();
161
162 my @n;
163 push @n,['dnslu:add',['dnslu:disclose',@{build_disclose($todo->add('disclose'),'contact')}]] if $todo->add('disclose');
164 push @n,['dnslu:rem',['dnslu:disclose',@{build_disclose($todo->del('disclose'),'contact')}]] if $todo->del('disclose');
165 return unless @n;
166
167 my $eid=build_command_extension($mes,$epp,'dnslu:ext');
168 $mes->command_extension($eid,['dnslu:update',['dnslu:contact',@n]]);
169}
170
171####################################################################################################
1721;
173