line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Net::ICAP::Request -- Request object for ICAP |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# (c) 2012, Arthur Corliss |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# $Revision: 0.04 $ |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# This software is licensed under the same terms as Perl, itself. |
8
|
|
|
|
|
|
|
# Please see http://dev.perl.org/licenses/ for more information. |
9
|
|
|
|
|
|
|
# |
10
|
|
|
|
|
|
|
##################################################################### |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
##################################################################### |
13
|
|
|
|
|
|
|
# |
14
|
|
|
|
|
|
|
# Environment definitions |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
##################################################################### |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
package Net::ICAP::Request; |
19
|
|
|
|
|
|
|
|
20
|
2
|
|
|
2
|
|
13793
|
use 5.008003; |
|
2
|
|
|
|
|
7
|
|
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
34
|
|
23
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
61
|
|
24
|
2
|
|
|
2
|
|
9
|
use vars qw($VERSION @ISA @_properties @_methods); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
114
|
|
25
|
2
|
|
|
2
|
|
517
|
use Class::EHierarchy qw(:all); |
|
2
|
|
|
|
|
5940
|
|
|
2
|
|
|
|
|
276
|
|
26
|
2
|
|
|
2
|
|
318
|
use Net::ICAP::Common qw(:std :debug :req); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
263
|
|
27
|
2
|
|
|
2
|
|
360
|
use Net::ICAP::Message; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
74
|
|
28
|
2
|
|
|
2
|
|
13
|
use Paranoid::Debug; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
83
|
|
29
|
2
|
|
|
2
|
|
849
|
use URI; |
|
2
|
|
|
|
|
8386
|
|
|
2
|
|
|
|
|
1895
|
|
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
($VERSION) = ( q$Revision: 0.04 $ =~ /(\d+(?:\.(\d+))+)/s ); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
@ISA = qw(Net::ICAP::Message Class::EHierarchy); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
@_properties = ( |
36
|
|
|
|
|
|
|
[ CEH_RESTR | CEH_ARRAY, '_valid_methods', [qw(REQMOD RESPMOD OPTIONS)] ], |
37
|
|
|
|
|
|
|
[ CEH_RESTR | CEH_SCALAR, '_method' ], |
38
|
|
|
|
|
|
|
[ CEH_RESTR | CEH_SCALAR, '_url' ], |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
##################################################################### |
42
|
|
|
|
|
|
|
# |
43
|
|
|
|
|
|
|
# Module code follows |
44
|
|
|
|
|
|
|
# |
45
|
|
|
|
|
|
|
##################################################################### |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _initialize ($;@) { |
48
|
|
|
|
|
|
|
|
49
|
13
|
|
|
13
|
|
15483
|
my $obj = shift; |
50
|
13
|
|
|
|
|
34
|
my %args = @_; |
51
|
13
|
|
|
|
|
23
|
my $rv = 1; |
52
|
|
|
|
|
|
|
|
53
|
13
|
|
|
|
|
49
|
pdebug( 'entering w/%s and %s', ICAPDEBUG1, $obj, keys %args ); |
54
|
13
|
|
|
|
|
606
|
pIn(); |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# Set internal state if args were passed |
57
|
13
|
100
|
|
|
|
126
|
$rv = $obj->method( $args{method} ) if exists $args{method}; |
58
|
13
|
100
|
66
|
|
|
48
|
$rv = $obj->url( $args{url} ) if exists $args{url} and $rv; |
59
|
|
|
|
|
|
|
|
60
|
13
|
|
|
|
|
39
|
pOut(); |
61
|
13
|
|
|
|
|
103
|
pdebug( 'leaving w/rv: %s', ICAPDEBUG1, $rv ); |
62
|
|
|
|
|
|
|
|
63
|
13
|
|
|
|
|
430
|
return $rv; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _validHeaders ($) { |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# Purpose: Returns a list of valid ICAP headers |
69
|
|
|
|
|
|
|
# Returns: Array |
70
|
|
|
|
|
|
|
# Usage: @val = $obj->_validHeaders; |
71
|
|
|
|
|
|
|
|
72
|
60
|
|
|
60
|
|
97
|
my $obj = shift; |
73
|
|
|
|
|
|
|
|
74
|
60
|
|
|
|
|
166
|
return ( qw(Host Authorization Allow From Referer User-Agent Preview), |
75
|
|
|
|
|
|
|
$obj->SUPER::_validHeaders ); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub method ($;$) { |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Purpose: Gets/sets method |
81
|
|
|
|
|
|
|
# Returns: Boolean/String |
82
|
|
|
|
|
|
|
# Usage: $rv = $obj->method($method); |
83
|
|
|
|
|
|
|
# Usage: $method = $obj->method; |
84
|
|
|
|
|
|
|
|
85
|
20
|
|
|
20
|
1
|
41
|
my $obj = shift; |
86
|
20
|
|
|
|
|
36
|
my $method = shift; |
87
|
20
|
|
|
|
|
32
|
my $rv; |
88
|
|
|
|
|
|
|
|
89
|
20
|
|
|
|
|
69
|
pdebug( 'entering w/%s', ICAPDEBUG1, $method ); |
90
|
20
|
|
|
|
|
784
|
pIn(); |
91
|
|
|
|
|
|
|
|
92
|
20
|
100
|
|
|
|
192
|
if ( defined $method ) { |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# Write mode |
95
|
7
|
50
|
|
|
|
18
|
if ( grep { $_ eq $method } $obj->get('_valid_methods') ) { |
|
21
|
|
|
|
|
374
|
|
96
|
7
|
|
|
|
|
22
|
$rv = $obj->set( '_method', $method ); |
97
|
|
|
|
|
|
|
} else { |
98
|
0
|
|
|
|
|
0
|
$obj->error("invalid method passed: $method"); |
99
|
0
|
|
|
|
|
0
|
$rv = 0; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
} else { |
103
|
13
|
|
|
|
|
45
|
$rv = $obj->get('_method'); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
20
|
|
|
|
|
1185
|
pOut(); |
107
|
20
|
|
|
|
|
160
|
pdebug( 'leaving w/rv: %s', ICAPDEBUG1, $rv ); |
108
|
|
|
|
|
|
|
|
109
|
20
|
|
|
|
|
681
|
return $rv; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub url ($;$) { |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# Purpose: Gets/sets URL |
115
|
|
|
|
|
|
|
# Returns: Boolean/String |
116
|
|
|
|
|
|
|
# Usage: $rv = $obj->url($url); |
117
|
|
|
|
|
|
|
# Usage: $method = $obj->url; |
118
|
|
|
|
|
|
|
|
119
|
27
|
|
|
27
|
1
|
69
|
my $obj = shift; |
120
|
27
|
|
|
|
|
47
|
my $url = shift; |
121
|
27
|
|
|
|
|
49
|
my $rv; |
122
|
|
|
|
|
|
|
|
123
|
27
|
|
|
|
|
95
|
pdebug( 'entering w/%s', ICAPDEBUG1, $url ); |
124
|
27
|
|
|
|
|
1170
|
pIn(); |
125
|
|
|
|
|
|
|
|
126
|
27
|
100
|
|
|
|
273
|
if ( defined $url ) { |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# Write mode |
129
|
7
|
|
|
|
|
20
|
$rv = $obj->set( '_url', $url ); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
} else { |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
# Read mode |
134
|
20
|
|
|
|
|
72
|
$rv = $obj->get('_url'); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
27
|
|
|
|
|
1612
|
pOut(); |
138
|
27
|
|
|
|
|
212
|
pdebug( 'leaving w/rv: %s', ICAPDEBUG1, $rv ); |
139
|
|
|
|
|
|
|
|
140
|
27
|
|
|
|
|
926
|
return $rv; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub authority ($) { |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# Purpose: Returns the authority section of the URL |
146
|
|
|
|
|
|
|
# Returns: String |
147
|
|
|
|
|
|
|
# Usage: $auth = $obj->authority; |
148
|
|
|
|
|
|
|
|
149
|
0
|
|
|
0
|
1
|
0
|
my $obj = shift; |
150
|
0
|
|
|
|
|
0
|
my $url = $obj->set('_url'); |
151
|
0
|
|
|
|
|
0
|
my ( $uri, $rv ); |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
0
|
pdebug( 'entering', ICAPDEBUG1 ); |
154
|
0
|
|
|
|
|
0
|
pIn(); |
155
|
|
|
|
|
|
|
|
156
|
0
|
0
|
0
|
|
|
0
|
if ( defined $url and length $url ) { |
157
|
0
|
|
|
|
|
0
|
$uri = URI->new($url); |
158
|
0
|
|
|
|
|
0
|
$rv = $uri->authority; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
0
|
pOut(); |
162
|
0
|
|
|
|
|
0
|
pdebug( 'leaving w/rv: %s', ICAPDEBUG1, $rv ); |
163
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
0
|
return $rv; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub service ($) { |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
# Purpose: Returns the service section of the URL |
170
|
|
|
|
|
|
|
# Returns: String |
171
|
|
|
|
|
|
|
# Usage: $auth = $obj->service; |
172
|
|
|
|
|
|
|
|
173
|
0
|
|
|
0
|
1
|
0
|
my $obj = shift; |
174
|
0
|
|
|
|
|
0
|
my $url = $obj->get('_url'); |
175
|
0
|
|
|
|
|
0
|
my ( $uri, $rv ); |
176
|
|
|
|
|
|
|
|
177
|
0
|
|
|
|
|
0
|
pdebug( 'entering', ICAPDEBUG1 ); |
178
|
0
|
|
|
|
|
0
|
pIn(); |
179
|
|
|
|
|
|
|
|
180
|
0
|
0
|
0
|
|
|
0
|
if ( defined $url and length $url ) { |
181
|
0
|
|
|
|
|
0
|
$uri = URI->new($url); |
182
|
0
|
|
|
|
|
0
|
$rv = $uri->path; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
0
|
|
|
|
|
0
|
pOut(); |
186
|
0
|
|
|
|
|
0
|
pdebug( 'leaving w/rv: %s', ICAPDEBUG1, $rv ); |
187
|
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
0
|
return $rv; |
189
|
|
|
|
|
|
|
} |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
sub query ($;$) { |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
# Purpose: Returns the query section of the URL |
194
|
|
|
|
|
|
|
# Returns: String |
195
|
|
|
|
|
|
|
# Usage: $auth = $obj->query; |
196
|
|
|
|
|
|
|
# Usage: $auth = $obj->query($query_arg); |
197
|
|
|
|
|
|
|
|
198
|
0
|
|
|
0
|
1
|
0
|
my $obj = shift; |
199
|
0
|
|
|
|
|
0
|
my $qname = shift; |
200
|
0
|
|
|
|
|
0
|
my $url = $obj->get('_url'); |
201
|
0
|
|
|
|
|
0
|
my ( $uri, %q, $rv ); |
202
|
|
|
|
|
|
|
|
203
|
0
|
|
|
|
|
0
|
pdebug( 'entering', ICAPDEBUG1 ); |
204
|
0
|
|
|
|
|
0
|
pIn(); |
205
|
|
|
|
|
|
|
|
206
|
0
|
0
|
0
|
|
|
0
|
if ( defined $url and length $url ) { |
207
|
0
|
|
|
|
|
0
|
$uri = URI->new($url); |
208
|
0
|
|
|
|
|
0
|
$rv = $uri->query; |
209
|
|
|
|
|
|
|
|
210
|
0
|
0
|
0
|
|
|
0
|
if ( defined $qname and length $qname ) { |
211
|
0
|
|
|
|
|
0
|
%q = $uri->query_form; |
212
|
0
|
|
|
|
|
0
|
$rv = $q{$qname}; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
0
|
|
|
|
|
0
|
pOut(); |
217
|
0
|
|
|
|
|
0
|
pdebug( 'leaving w/rv: %s', ICAPDEBUG1, $rv ); |
218
|
|
|
|
|
|
|
|
219
|
0
|
|
|
|
|
0
|
return $rv; |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
sub sanityCheck ($) { |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
# Purpose: Checks for required information |
225
|
|
|
|
|
|
|
# Returns: Boolean |
226
|
|
|
|
|
|
|
# Usage: $rv = $obj->sanityCheck; |
227
|
|
|
|
|
|
|
|
228
|
13
|
|
|
13
|
1
|
23
|
my $obj = shift; |
229
|
13
|
|
|
|
|
20
|
my $rv = 1; |
230
|
13
|
|
|
|
|
21
|
my $t; |
231
|
|
|
|
|
|
|
|
232
|
13
|
|
|
|
|
30
|
$t = $obj->get('_method'); |
233
|
13
|
50
|
33
|
|
|
634
|
unless ( defined $t and length $t ) { |
234
|
0
|
|
|
|
|
0
|
$obj->error('missing a valid request method'); |
235
|
0
|
|
|
|
|
0
|
$rv = 0; |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
|
238
|
13
|
|
|
|
|
29
|
$t = $obj->get('_url'); |
239
|
13
|
50
|
33
|
|
|
602
|
unless ( defined $t and length $t ) { |
240
|
0
|
|
|
|
|
0
|
$obj->error('missing a valid request URL'); |
241
|
0
|
|
|
|
|
0
|
$rv = 0; |
242
|
|
|
|
|
|
|
} |
243
|
|
|
|
|
|
|
|
244
|
13
|
|
|
|
|
33
|
$t = $obj->get('_version'); |
245
|
13
|
50
|
33
|
|
|
615
|
unless ( defined $t and length $t ) { |
246
|
0
|
|
|
|
|
0
|
$obj->error('missing a valid ICAP protocol version'); |
247
|
0
|
|
|
|
|
0
|
$rv = 0; |
248
|
|
|
|
|
|
|
} |
249
|
|
|
|
|
|
|
|
250
|
13
|
|
|
|
|
37
|
$t = $obj->header('Host'); |
251
|
13
|
50
|
33
|
|
|
61
|
unless ( defined $t and length $t ) { |
252
|
0
|
|
|
|
|
0
|
$obj->error('missing mandatory Host header'); |
253
|
0
|
|
|
|
|
0
|
$rv = 0; |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
|
256
|
13
|
50
|
|
|
|
31
|
$obj->error('failed sanity check') unless $rv; |
257
|
13
|
50
|
|
|
|
28
|
$obj->error('failed sanity check') unless $rv; |
258
|
|
|
|
|
|
|
|
259
|
13
|
|
|
|
|
36
|
return $rv; |
260
|
|
|
|
|
|
|
} |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
sub parse ($$) { |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
# Purpose: Parses message from passed input |
265
|
|
|
|
|
|
|
# Returns: Boolean |
266
|
|
|
|
|
|
|
# Usage: $rv = $obj->parse($input); |
267
|
|
|
|
|
|
|
|
268
|
12
|
|
|
12
|
1
|
2224
|
my $obj = shift; |
269
|
12
|
|
|
|
|
19
|
my $input = shift; |
270
|
12
|
|
|
|
|
18
|
my $rv = 0; |
271
|
12
|
|
|
|
|
24
|
my ( $line, $m, $u, $v ); |
272
|
|
|
|
|
|
|
|
273
|
12
|
|
|
|
|
37
|
pdebug( 'entering w/%s, %s', ICAPDEBUG1, $obj, $input ); |
274
|
12
|
|
|
|
|
471
|
pIn(); |
275
|
|
|
|
|
|
|
|
276
|
12
|
50
|
|
|
|
107
|
if ( defined $input ) { |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
# Purge internal state |
279
|
12
|
|
|
|
|
46
|
$obj->set( '_method', undef ); |
280
|
12
|
|
|
|
|
835
|
$obj->set( '_url', undef ); |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
# Parse |
283
|
12
|
|
|
|
|
746
|
$rv = $obj->SUPER::parse($input); |
284
|
|
|
|
|
|
|
|
285
|
12
|
100
|
|
|
|
37
|
if ($rv) { |
286
|
|
|
|
|
|
|
|
287
|
|
|
|
|
|
|
# Extract request specific fields |
288
|
6
|
|
|
|
|
21
|
$line = $obj->get('_start'); |
289
|
6
|
|
|
|
|
323
|
( $m, $u, $v ) = ( $line =~ /^(\S+)\s+(\S+)\s+(\S+)$/s ); |
290
|
|
|
|
|
|
|
|
291
|
|
|
|
|
|
|
# Save the extracted information |
292
|
6
|
|
33
|
|
|
19
|
$rv = $obj->method($m) && $obj->url($u) && $obj->version($v); |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
# Perform basic sanity checks |
295
|
6
|
50
|
|
|
|
25
|
$rv = $obj->sanityCheck if $rv; |
296
|
|
|
|
|
|
|
} |
297
|
|
|
|
|
|
|
} |
298
|
|
|
|
|
|
|
|
299
|
12
|
50
|
|
|
|
32
|
$rv = 0 unless defined $rv; |
300
|
|
|
|
|
|
|
|
301
|
12
|
|
|
|
|
34
|
pOut(); |
302
|
12
|
|
|
|
|
93
|
pdebug( 'leaving w/rv: %s', ICAPDEBUG1, $rv ); |
303
|
|
|
|
|
|
|
|
304
|
12
|
|
|
|
|
421
|
return $rv; |
305
|
|
|
|
|
|
|
} |
306
|
|
|
|
|
|
|
|
307
|
|
|
|
|
|
|
sub generate ($$) { |
308
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
# Purpose: Generates an ICAP request |
310
|
|
|
|
|
|
|
# Returns: String |
311
|
|
|
|
|
|
|
# Usage: $request = $obj->generate($ref); |
312
|
|
|
|
|
|
|
|
313
|
7
|
|
|
7
|
1
|
563
|
my $obj = shift; |
314
|
7
|
|
|
|
|
17
|
my $out = shift; |
315
|
7
|
|
|
|
|
19
|
my ( $url, $host, $rv ); |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
# Generate Host header from URL |
318
|
7
|
|
|
|
|
25
|
$url = $obj->url; |
319
|
7
|
50
|
|
|
|
23
|
if ( defined $url ) { |
320
|
7
|
|
|
|
|
26
|
($host) = ( $url =~ m#^icap://([^:/]+)#si ); |
321
|
7
|
|
|
|
|
24
|
$obj->header( 'Host', $host ); |
322
|
|
|
|
|
|
|
} |
323
|
|
|
|
|
|
|
|
324
|
7
|
50
|
|
|
|
18
|
if ( $obj->sanityCheck ) { |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
# Build start line |
327
|
7
|
|
|
|
|
48
|
$obj->set( '_start', join ' ', $obj->method, $obj->url, |
328
|
|
|
|
|
|
|
ICAP_VERSION ); |
329
|
7
|
|
|
|
|
481
|
$rv = $obj->SUPER::generate($out); |
330
|
|
|
|
|
|
|
} |
331
|
|
|
|
|
|
|
|
332
|
7
|
|
|
|
|
39
|
return $rv; |
333
|
|
|
|
|
|
|
} |
334
|
|
|
|
|
|
|
|
335
|
|
|
|
|
|
|
1; |
336
|
|
|
|
|
|
|
|
337
|
|
|
|
|
|
|
__END__ |