line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Domain::Registry::Joker::Response; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
13
|
use 5.006; |
|
1
|
|
|
|
|
2
|
|
4
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
14
|
|
5
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
17
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
3
|
use WWW::Domain::Registry::Joker::Loggish; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
906
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our @ISA = qw(WWW::Domain::Registry::Joker::Loggish); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
WWW::Domain::Registry::Joker::Response - parse a DMAPI response |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use WWW::Domain::Registry::Joker::Response; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
$r = new WWW::Domain::Registry::Joker::Response(); |
22
|
|
|
|
|
|
|
$r->parse($resp); |
23
|
|
|
|
|
|
|
print "$r->{Proc-Id}: $r->{'Status-Code'} $r->{Status-Text}\n"; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 DESCRIPTION |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
The C class is a helper parser |
28
|
|
|
|
|
|
|
for the HTTP responses returned by the Joker.com DMAPI. It examines |
29
|
|
|
|
|
|
|
a response object, extracts the status and error flags, codes, and |
30
|
|
|
|
|
|
|
descriptive messages, and makes them available as Perl object members. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 METHODS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
The C class defines the |
35
|
|
|
|
|
|
|
following methods: |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=over 4 |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=item new () |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Initialize a C object. |
42
|
|
|
|
|
|
|
No user-serviceable parameters inside. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub new($ %) |
47
|
|
|
|
|
|
|
{ |
48
|
0
|
|
|
0
|
1
|
|
my ($proto, %param) = @_; |
49
|
0
|
|
|
|
|
|
my $self; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
$self = WWW::Domain::Registry::Joker::Loggish::new($proto, |
52
|
|
|
|
|
|
|
'code' => 1337, |
53
|
|
|
|
|
|
|
'msg' => '(no status text)', |
54
|
|
|
|
|
|
|
'status' => '(no status line)', |
55
|
|
|
|
|
|
|
'success' => 0, |
56
|
|
|
|
|
|
|
%param, |
57
|
|
|
|
|
|
|
); |
58
|
0
|
|
|
|
|
|
return $self; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=item parse ( RESPONSE ) |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Parse a C from the DMAPI and store the result code, |
64
|
|
|
|
|
|
|
message, error, etc. into the respective fields of the object. |
65
|
|
|
|
|
|
|
In addition to the C, C, C, and C members |
66
|
|
|
|
|
|
|
described above, the C method may also set the C, |
67
|
|
|
|
|
|
|
C, C, C, C, and any other |
68
|
|
|
|
|
|
|
result description members as listed in the DMAPI specification. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub parse($ $) |
73
|
|
|
|
|
|
|
{ |
74
|
0
|
|
|
0
|
1
|
|
my ($self, $resp) = @_; |
75
|
0
|
|
|
|
|
|
my ($in_data, $var, $val); |
76
|
0
|
|
|
|
|
|
my (@r, @data); |
77
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
|
die("No response object passed to ".ref($self)."->parse()\n") |
79
|
|
|
|
|
|
|
unless defined($resp); |
80
|
0
|
|
|
|
|
|
$self->debug("parsing a response - '".ref($resp)."'"); |
81
|
0
|
0
|
0
|
|
|
|
if (index(ref($resp), '::') == -1 || !$resp->isa('HTTP::Response')) { |
82
|
0
|
|
|
|
|
|
die("Not a HTTP response object in ".ref($self)."->parse()\n"); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
$self->{'success'} = $resp->is_success(); |
86
|
0
|
|
|
|
|
|
$self->{'status'} = $resp->status_line(); |
87
|
0
|
|
|
|
|
|
undef $self->{'Status-Code'}; |
88
|
0
|
|
|
|
|
|
undef $self->{'Status-Text'}; |
89
|
0
|
|
|
|
|
|
@r = split("\n", $resp->content()); |
90
|
0
|
|
|
|
|
|
$self->debug(scalar(@r)." content lines"); |
91
|
0
|
|
|
|
|
|
foreach (@r) { |
92
|
0
|
|
|
|
|
|
s/[\r\n]+$//; |
93
|
0
|
0
|
|
|
|
|
if ($in_data) { |
94
|
0
|
|
|
|
|
|
$self->debug("- data line $_"); |
95
|
0
|
|
|
|
|
|
push @data, $_; |
96
|
0
|
|
|
|
|
|
next; |
97
|
|
|
|
|
|
|
} |
98
|
0
|
|
|
|
|
|
$self->debug("- line $_"); |
99
|
0
|
0
|
|
|
|
|
if ($_ eq '') { |
|
|
0
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
$self->debug("- - end of header"); |
101
|
0
|
|
|
|
|
|
$in_data = 1; |
102
|
0
|
|
|
|
|
|
next; |
103
|
|
|
|
|
|
|
} elsif (!/^([\w-]+):\s+(.*)$/) { |
104
|
0
|
|
|
|
|
|
$self->debug("- - bad format!"); |
105
|
0
|
|
|
|
|
|
next; |
106
|
|
|
|
|
|
|
} |
107
|
0
|
|
|
|
|
|
($var, $val) = ($1, $2); |
108
|
0
|
0
|
|
|
|
|
if (defined($self->{$var})) { |
109
|
0
|
|
|
|
|
|
$self->{$var} .= " / $val"; |
110
|
|
|
|
|
|
|
} else { |
111
|
0
|
|
|
|
|
|
$self->{$var} = $val; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
} |
114
|
0
|
|
|
|
|
|
$self->{'data'} = [ @data ]; |
115
|
0
|
0
|
|
|
|
|
if (defined($self->{'Status-Code'})) { |
116
|
0
|
|
|
|
|
|
$self->{'code'} = $self->{'Status-Code'}; |
117
|
|
|
|
|
|
|
} else { |
118
|
0
|
|
|
|
|
|
$self->{'code'} = 1337; |
119
|
|
|
|
|
|
|
} |
120
|
0
|
0
|
|
|
|
|
if (defined($self->{'Status-Text'})) { |
121
|
0
|
|
|
|
|
|
$self->{'msg'} = $self->{'Status-Text'}; |
122
|
|
|
|
|
|
|
} else { |
123
|
0
|
|
|
|
|
|
$self->{'msg'} = '(no status text)'; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
$self->debug("=== DMAPI response: is_success $self->{success} ". |
126
|
|
|
|
|
|
|
"status line '$self->{status}', status code: $self->{code}, ". |
127
|
|
|
|
|
|
|
"status text: '$self->{msg}', ". |
128
|
0
|
|
|
|
|
|
"data lines ".scalar(@{$self->{'data'}})."\n"); |
|
0
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
return 1; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=back |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 EXAMPLES |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Create an object and parse an HTTP response: |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
$r = new WWW::Domain::Registry::Joker::Response(); |
139
|
|
|
|
|
|
|
eval { |
140
|
|
|
|
|
|
|
$r->parse($resp); |
141
|
|
|
|
|
|
|
}; |
142
|
|
|
|
|
|
|
if ($@) { |
143
|
|
|
|
|
|
|
print STDERR "Could not parse the DMAPI response: $@\n"; |
144
|
|
|
|
|
|
|
} elsif (!$r->{'success'}) { |
145
|
|
|
|
|
|
|
print STDERR "DMAPI error: code $r->{code}, text $r->{msg}\n"; |
146
|
|
|
|
|
|
|
print STDERR "DMAPI error message: $r->{Error}\n" |
147
|
|
|
|
|
|
|
if $r->{'Error'}; |
148
|
|
|
|
|
|
|
} else { |
149
|
|
|
|
|
|
|
print "Successful DMAPI request: $r->{code} $r->{msg}\n"; |
150
|
|
|
|
|
|
|
print "Tracking process ID: $r->{Proc-ID}\n" if $r->{'Proc-ID'}; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head1 ERRORS |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
The C method will die on invalid input: |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=over 4 |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=item * |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
no response parameter passed in; |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=item * |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
the response parameter was not an C or compatible object. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=back |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
If the response object is a valid DMAPI response, its C, C, |
170
|
|
|
|
|
|
|
C, C, and other attributes are exposed as members of |
171
|
|
|
|
|
|
|
the C object as shown above. |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 SEE ALSO |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
L, L |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
I - the Joker.com DMAPI |
178
|
|
|
|
|
|
|
documentation |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head1 BUGS |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
None known so far ;) |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 HISTORY |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
The C class was written by |
187
|
|
|
|
|
|
|
Peter Pentchev in 2007. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=head1 AUTHOR |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Peter Pentchev, Eroam@ringlet.netE |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
Copyright (C) 2007 by Peter Pentchev |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
198
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.8 or, |
199
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=cut |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
1; |