| 1 | ## Domain Registry Interface, EPP AusRegistry Key Value Extension | ||||||||||
| 2 | ## | ||||||||||
| 3 | ## Copyright (c) 2013,2018-2019 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::EPP::Extensions::AusRegistry::KeyValue; | ||||||||||
| 16 | |||||||||||
| 17 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | 1 | ▶ | use Net::DRI::Util; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 1 | ▶ | use Net::DRI::Exception; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | |||||||||||
| 23 | #################################################################################################### | ||||||||||
| 24 | |||||||||||
| 25 | sub register_commands | ||||||||||
| 26 | 0 | ▶ | { | ||||||||
|
Subroutine
register_commands: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 27 | 0 | my ($class,$version)=@_; | |||||||||
| 28 | 0 | my %tmp=( | |||||||||
| 29 | info => [ undef , \&info_parse ], | ||||||||||
| 30 | create => [ \&create_build, undef ], | ||||||||||
| 31 | update => [ \&update_build, undef ], | ||||||||||
| 32 | ); | ||||||||||
| 33 | |||||||||||
| 34 | 0 | return { 'domain' => \%tmp }; | |||||||||
| 35 | } | ||||||||||
| 36 | |||||||||||
| 37 | sub setup | ||||||||||
| 38 | 0 | ▶ | { | ||||||||
|
Subroutine
setup: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 39 | 0 | my ($class,$po,$version)=@_; | |||||||||
| 40 | 0 | $po->ns({ 'kv' => 'urn:X-ar:params:xml:ns:kv-1.0' }); | |||||||||
| 41 | 0 | return; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 0 | ▶ | sub capabilities_add { return ('domain_update','keyvalue',['set']); } | ||||||||
|
Subroutine
capabilities_add: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 45 | |||||||||||
| 46 | #################################################################################################### | ||||||||||
| 47 | |||||||||||
| 48 | ## <extension> | ||||||||||
| 49 | ## <infData xmlns="urn:X-ar:params:xml:ns:kv-1.0"> | ||||||||||
| 50 | ## <kvlist name="ext"> | ||||||||||
| 51 | ## <item key="key1">value1</item> | ||||||||||
| 52 | ## <item key="key2">value2</item> | ||||||||||
| 53 | ## </kvlist> | ||||||||||
| 54 | ## </infData> | ||||||||||
| 55 | ## </extension> | ||||||||||
| 56 | |||||||||||
| 57 | sub info_parse | ||||||||||
| 58 | 0 | ▶ | { | ||||||||
|
Subroutine
info_parse: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||
| 59 | 0 | my ($po,$otype,$oaction,$oname,$rinfo)=@_; | |||||||||
| 60 | 0 | my $mes=$po->message(); | |||||||||
| 61 | 0 | ▶ | return unless $mes->is_success(); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 62 | |||||||||||
| 63 | 0 | my $data=$mes->get_extension('kv','infData'); | |||||||||
| 64 | 0 | ▶ | return unless defined $data; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | |||||||||||
| 66 | 0 | my %kvs; | |||||||||
| 67 | 0 | foreach my $el (Net::DRI::Util::xml_list_children($data)) | |||||||||
| 68 | { | ||||||||||
| 69 | 0 | my ($name,$node)=@$el; | |||||||||
| 70 | 0 | ▶ | if ($name eq 'kvlist') | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | { | ||||||||||
| 72 | 0 | my $kvname=$node->getAttribute('name'); | |||||||||
| 73 | 0 | my %kv; | |||||||||
| 74 | 0 | foreach my $kvel (Net::DRI::Util::xml_list_children($node)) | |||||||||
| 75 | { | ||||||||||
| 76 | 0 | my ($kvelname,$kvelnode)=@$kvel; | |||||||||
| 77 | 0 | ▶ | if ($kvelname eq 'item') | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | { | ||||||||||
| 79 | 0 | $kv{$kvelnode->getAttribute('key')}=$kvelnode->textContent(); | |||||||||
| 80 | } | ||||||||||
| 81 | } | ||||||||||
| 82 | 0 | $kvs{$kvname}=\%kv; | |||||||||
| 83 | } | ||||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | 0 | $rinfo->{domain}->{$oname}->{keyvalue}=\%kvs; | |||||||||
| 87 | 0 | return; | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | sub build_kvlists | ||||||||||
| 91 | 0 | ▶ | { | ||||||||
|
Subroutine
build_kvlists: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||
| 92 | 0 | my ($rd)=@_; | |||||||||
| 93 | 0 | ▶ | Net::DRI::Exception::usererr_invalid_parameters(qq{keyvalue parameter must be ref hash, not: }.$rd) unless ref $rd eq 'HASH'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 94 | 0 | my @kvs; | |||||||||
| 95 | 0 | foreach my $kvlistname (sort { $a cmp $b } keys %$rd) | |||||||||
| 96 | { | ||||||||||
| 97 | 0 | ▶ | Net::DRI::Exception::usererr_invalid_parameters(qq{kvlist name "$kvlistname" must be an XML token}) unless Net::DRI::Util::xml_is_token($kvlistname); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 98 | 0 | ▶ | Net::DRI::Exception::usererr_invalid_parameters(qq{value for kvlistname "$kvlistname" must be ref hash, not: }.$rd->{$kvlistname}) unless ref $rd->{$kvlistname} eq 'HASH'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 99 | 0 | my @kv; | |||||||||
| 100 | 0 | foreach my $key (sort { $a cmp $b } keys %{$rd->{$kvlistname}}) | |||||||||
| 101 | { | ||||||||||
| 102 | 0 | ▶ | Net::DRI::Exception::usererr_invalid_parameters(qq{item name "$key" (in kvlist name "$kvlistname") must be an XML token}) unless Net::DRI::Util::xml_is_token($key); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 103 | 0 | my $v=$rd->{$kvlistname}->{$key}; | |||||||||
| 104 | 0 | ▶ | Net::DRI::Exception::usererr_invalid_parameters(qq{value "$v" for item name "$key" (in kvlist name "$kvlistname") must be an XML string}) unless Net::DRI::Util::xml_is_string($v); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 105 | 0 | push @kv,['item',{key => $key},$v]; | |||||||||
| 106 | } | ||||||||||
| 107 | 0 | push @kvs,['kvlist',{name => $kvlistname},@kv]; | |||||||||
| 108 | } | ||||||||||
| 109 | 0 | return @kvs; | |||||||||
| 110 | } | ||||||||||
| 111 | |||||||||||
| 112 | ## <extension> | ||||||||||
| 113 | ## <create xmlns="urn:X-ar:params:xml:ns:kv-1.0"> | ||||||||||
| 114 | ## <kvlist name="ext"> | ||||||||||
| 115 | ## <item key="key1">value1</item> | ||||||||||
| 116 | ## <item key="key2">value2</item> | ||||||||||
| 117 | ## </kvlist> | ||||||||||
| 118 | ## </create> | ||||||||||
| 119 | ## </extension> | ||||||||||
| 120 | |||||||||||
| 121 | sub create_build | ||||||||||
| 122 | 0 | ▶ | { | ||||||||
|
Subroutine
create_build: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 123 | 0 | my ($epp,$domain,$rd)=@_; | |||||||||
| 124 | |||||||||||
| 125 | 0 | ▶ | $epp->message()->command_extension('kv', ['create', build_kvlists($rd->{keyvalue})]) if Net::DRI::Util::has_key($rd,'keyvalue'); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 126 | |||||||||||
| 127 | 0 | return; | |||||||||
| 128 | } | ||||||||||
| 129 | |||||||||||
| 130 | ## <extension> | ||||||||||
| 131 | ## <update xmlns="urn:X-ar:params:xml:ns:kv-1.0"> | ||||||||||
| 132 | ## <kvlist name="ext"> | ||||||||||
| 133 | ## <item key="key1">value1</item> | ||||||||||
| 134 | ## <item key="key2">value2</item> | ||||||||||
| 135 | ## </kvlist> | ||||||||||
| 136 | ## </update> | ||||||||||
| 137 | ## </extension> | ||||||||||
| 138 | |||||||||||
| 139 | sub update_build | ||||||||||
| 140 | 0 | ▶ | { | ||||||||
|
Subroutine
update_build: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 141 | 0 | my ($epp,$domain,$todo)=@_; | |||||||||
| 142 | |||||||||||
| 143 | 0 | my $toset=$todo->set('keyvalue'); | |||||||||
| 144 | |||||||||||
| 145 | 0 | ▶ | $epp->message()->command_extension('kv', ['update', build_kvlists($toset)]) if defined $toset; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 146 | |||||||||||
| 147 | 0 | return; | |||||||||
| 148 | } | ||||||||||
| 149 | |||||||||||
| 150 | #################################################################################################### | ||||||||||
| 151 | 1 | 1; | |||||||||
| 152 | |||||||||||
| 153 | __END__ | ||||||||||