line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTTP::DAV::Nginx; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
29530
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
3234
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
99753
|
|
|
1
|
|
|
|
|
42
|
|
7
|
1
|
|
|
1
|
|
11
|
use HTTP::Request; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
8
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
199
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.1.6'; |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
7
|
use constant C_BUF_SIZE => 8192; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1544
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
#----------- |
15
|
|
|
|
|
|
|
sub new |
16
|
|
|
|
|
|
|
#----------- |
17
|
|
|
|
|
|
|
{ |
18
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
19
|
0
|
|
|
|
|
|
my $url = shift; |
20
|
0
|
|
|
|
|
|
my %param = @_; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
my $self = {}; |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
$self -> {'ua'} = new LWP::UserAgent; |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
|
|
|
$url = _add_trailing_slash($url); |
27
|
0
|
|
|
|
|
|
$self -> {'url'} = $url; |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
0
|
|
|
|
$self -> {'die_on_errors'} = $param{'die_on_errors'} || 0; |
30
|
0
|
|
0
|
|
|
|
$self -> {'warn_on_errors'} = $param{'warn_on_errors'} || 0; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
bless $self, $class; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
return $self; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
#------------ |
39
|
|
|
|
|
|
|
sub _error |
40
|
|
|
|
|
|
|
#------------ |
41
|
|
|
|
|
|
|
{ |
42
|
0
|
|
|
0
|
|
|
my $self = shift; |
43
|
0
|
|
|
|
|
|
my $error = shift; |
44
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
if ($self -> {'die_on_errors'}) |
46
|
|
|
|
|
|
|
{ |
47
|
0
|
|
|
|
|
|
croak $error; |
48
|
|
|
|
|
|
|
} |
49
|
0
|
0
|
|
|
|
|
if ($self -> {'warn_on_errors'}) |
50
|
|
|
|
|
|
|
{ |
51
|
0
|
|
|
|
|
|
carp $error; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
$self -> {'err'} = $error; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
#------------------------ |
58
|
|
|
|
|
|
|
sub _add_trailing_slash |
59
|
|
|
|
|
|
|
#------------------------ |
60
|
|
|
|
|
|
|
{ |
61
|
0
|
|
|
0
|
|
|
my $url = shift; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
$url =~ s|/$||; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
$url .= '/'; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
return $url; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
#-------------------------- |
71
|
|
|
|
|
|
|
sub _clear_begining_slash |
72
|
|
|
|
|
|
|
#-------------------------- |
73
|
|
|
|
|
|
|
{ |
74
|
0
|
|
|
0
|
|
|
my $uri = shift; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
$uri =~ s/^\///; |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
return $uri; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
#------------------ |
82
|
|
|
|
|
|
|
sub _read_file_cb |
83
|
|
|
|
|
|
|
#------------------ |
84
|
|
|
|
|
|
|
{ |
85
|
0
|
|
|
0
|
|
|
my $fh = shift; |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
my $buffer; |
88
|
0
|
|
|
|
|
|
read($fh, $buffer, C_BUF_SIZE); |
89
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
return $buffer; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
#---------- |
96
|
|
|
|
|
|
|
sub err |
97
|
|
|
|
|
|
|
#---------- |
98
|
|
|
|
|
|
|
{ |
99
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
return $self -> {'err'}; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
#----------- |
105
|
|
|
|
|
|
|
sub mkcol |
106
|
|
|
|
|
|
|
#----------- |
107
|
|
|
|
|
|
|
{ |
108
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
109
|
0
|
|
|
|
|
|
my $uri = shift; |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
my $request = HTTP::Request->new(); |
112
|
0
|
|
|
|
|
|
$request -> method('MKCOL'); |
113
|
0
|
|
|
|
|
|
$request -> uri($self -> {'url'} . _clear_begining_slash($uri)); |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
my $response = $self -> {'ua'} -> request($request); |
116
|
|
|
|
|
|
|
|
117
|
0
|
0
|
|
|
|
|
unless ($response -> is_success) |
118
|
|
|
|
|
|
|
{ |
119
|
0
|
|
|
|
|
|
$self -> _error("METHOD:MKCOL URI:$uri Status:" . $response -> status_line); |
120
|
0
|
|
|
|
|
|
return undef; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
return 1; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
#------------- |
127
|
|
|
|
|
|
|
sub delete |
128
|
|
|
|
|
|
|
#------------- |
129
|
|
|
|
|
|
|
{ |
130
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
131
|
0
|
|
|
|
|
|
my $uri = shift; |
132
|
0
|
|
|
|
|
|
my %params = @_; |
133
|
|
|
|
|
|
|
|
134
|
0
|
|
|
|
|
|
my $request = HTTP::Request->new(); |
135
|
0
|
|
|
|
|
|
$request -> method('DELETE'); |
136
|
0
|
|
|
|
|
|
$request -> uri($self -> {'url'} . _clear_begining_slash($uri)); |
137
|
|
|
|
|
|
|
|
138
|
0
|
0
|
|
|
|
|
$request -> header('Depth' => $params{'depth'}) if defined $params{'depth'}; |
139
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
my $response = $self -> {'ua'} -> request($request); |
141
|
|
|
|
|
|
|
|
142
|
0
|
0
|
|
|
|
|
unless ($response -> is_success) |
143
|
|
|
|
|
|
|
{ |
144
|
0
|
|
|
|
|
|
$self -> _error("METHOD:DELETE URI:$uri Status:" . $response -> status_line); |
145
|
0
|
|
|
|
|
|
return undef; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
return 1; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
#--------- |
152
|
|
|
|
|
|
|
sub put |
153
|
|
|
|
|
|
|
#--------- |
154
|
|
|
|
|
|
|
{ |
155
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
156
|
0
|
|
|
|
|
|
my $uri = shift; |
157
|
0
|
|
|
|
|
|
my $data_type = shift; |
158
|
0
|
|
|
|
|
|
my $data = shift; |
159
|
|
|
|
|
|
|
|
160
|
0
|
0
|
0
|
|
|
|
unless ($data && $data_type) |
161
|
|
|
|
|
|
|
{ |
162
|
0
|
|
|
|
|
|
$self -> _error('METHOD:PUT ERROR:data not specified'); |
163
|
0
|
|
|
|
|
|
return; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
|
my $request = HTTP::Request -> new(); |
167
|
0
|
|
|
|
|
|
$request -> method('PUT'); |
168
|
0
|
|
|
|
|
|
$request -> uri($self -> {'url'} . _clear_begining_slash($uri)); |
169
|
|
|
|
|
|
|
|
170
|
0
|
|
|
|
|
|
my $content; |
171
|
|
|
|
|
|
|
my $fh; |
172
|
|
|
|
|
|
|
|
173
|
0
|
0
|
|
|
|
|
if (lc($data_type) eq 'data') |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
174
|
|
|
|
|
|
|
{ |
175
|
0
|
|
|
|
|
|
$content = $data; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
elsif (lc($data_type) eq 'file') |
178
|
|
|
|
|
|
|
{ |
179
|
|
|
|
|
|
|
|
180
|
0
|
|
|
|
|
|
my $filename = $data; |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
open($fh, '<:raw', $filename) or do |
183
|
0
|
0
|
|
|
|
|
{ |
184
|
0
|
|
|
|
|
|
$self -> _error("Can't open file $data for reading"); |
185
|
0
|
|
|
|
|
|
return; |
186
|
|
|
|
|
|
|
}; |
187
|
0
|
|
|
|
|
|
binmode($fh); |
188
|
|
|
|
|
|
|
|
189
|
0
|
|
|
|
|
|
$request -> header('Content-length' => -s $filename); |
190
|
|
|
|
|
|
|
|
191
|
0
|
|
|
0
|
|
|
$content = sub { return _read_file_cb($fh) }; |
|
0
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
elsif (lc($data_type) eq 'fh') |
194
|
|
|
|
|
|
|
{ |
195
|
0
|
|
|
|
|
|
my $fh = $data; |
196
|
0
|
|
|
|
|
|
my $filesize = (stat($fh))[7]; |
197
|
|
|
|
|
|
|
|
198
|
0
|
|
|
|
|
|
binmode($fh); |
199
|
|
|
|
|
|
|
|
200
|
0
|
|
|
|
|
|
$request -> header('Content-length' => $filesize); |
201
|
|
|
|
|
|
|
|
202
|
0
|
|
|
0
|
|
|
$content = sub { return _read_file_cb($fh) }; |
|
0
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
} |
204
|
|
|
|
|
|
|
|
205
|
0
|
|
|
|
|
|
$request -> content($content); |
206
|
|
|
|
|
|
|
|
207
|
0
|
|
|
|
|
|
my $response = $self -> {'ua'} -> request($request); |
208
|
|
|
|
|
|
|
|
209
|
0
|
0
|
|
|
|
|
unless ($response -> is_success) |
210
|
|
|
|
|
|
|
{ |
211
|
0
|
|
|
|
|
|
$self -> _error("METHOD:PUT URI:$uri Status:" . $response -> status_line); |
212
|
0
|
|
|
|
|
|
return undef; |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
0
|
|
|
|
|
|
return 1; |
216
|
|
|
|
|
|
|
} |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
#---------- |
219
|
|
|
|
|
|
|
sub copy |
220
|
|
|
|
|
|
|
#---------- |
221
|
|
|
|
|
|
|
{ |
222
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
223
|
0
|
|
|
|
|
|
my $uri = shift; |
224
|
0
|
|
|
|
|
|
my $dest_uri = shift; |
225
|
0
|
|
|
|
|
|
my %params = @_; |
226
|
|
|
|
|
|
|
|
227
|
0
|
|
|
|
|
|
my $request = HTTP::Request->new(); |
228
|
0
|
|
|
|
|
|
$request -> method('COPY'); |
229
|
0
|
|
|
|
|
|
$request -> uri($self -> {'url'} . _clear_begining_slash($uri)); |
230
|
0
|
|
|
|
|
|
$request -> header('Destination' => $dest_uri); |
231
|
|
|
|
|
|
|
|
232
|
0
|
0
|
|
|
|
|
$request -> header('Depth' => $params{'depth'}) if defined $params{'depth'}; |
233
|
0
|
0
|
|
|
|
|
if (defined $params{'overwrite'}) |
234
|
|
|
|
|
|
|
{ |
235
|
0
|
|
|
|
|
|
$params{'overwrite'} =~ tr/01/FT/; |
236
|
0
|
|
|
|
|
|
$request -> header('Overwrite' => $params{'overwrite'}); |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
|
239
|
0
|
|
|
|
|
|
my $response = $self -> {'ua'} -> request($request); |
240
|
0
|
0
|
|
|
|
|
unless ($response -> is_success) |
241
|
|
|
|
|
|
|
{ |
242
|
0
|
|
|
|
|
|
$self -> _error("METHOD:COPY URI:$uri Status:" . $response -> status_line); |
243
|
0
|
|
|
|
|
|
return undef; |
244
|
|
|
|
|
|
|
} |
245
|
|
|
|
|
|
|
|
246
|
0
|
|
|
|
|
|
return 1; |
247
|
|
|
|
|
|
|
} |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
#--------- |
250
|
|
|
|
|
|
|
sub move |
251
|
|
|
|
|
|
|
#--------- |
252
|
|
|
|
|
|
|
{ |
253
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
254
|
0
|
|
|
|
|
|
my $uri = shift; |
255
|
0
|
|
|
|
|
|
my $dest_uri = shift; |
256
|
0
|
|
|
|
|
|
my %params = @_; |
257
|
|
|
|
|
|
|
|
258
|
0
|
|
|
|
|
|
my $request = HTTP::Request->new(); |
259
|
0
|
|
|
|
|
|
$request -> method('MOVE'); |
260
|
0
|
|
|
|
|
|
$request -> uri($self -> {'url'} . _clear_begining_slash($uri)); |
261
|
0
|
|
|
|
|
|
$request -> header('Destination' => $dest_uri); |
262
|
|
|
|
|
|
|
|
263
|
0
|
0
|
|
|
|
|
$request -> header('Depth' => $params{'depth'}) if defined $params{'depth'}; |
264
|
0
|
0
|
|
|
|
|
if (defined $params{'overwrite'}) |
265
|
|
|
|
|
|
|
{ |
266
|
0
|
|
|
|
|
|
$params{'overwrite'} =~ tr/01/FT/; |
267
|
0
|
|
|
|
|
|
$request -> header('Overwrite' => $params{'overwrite'}); |
268
|
|
|
|
|
|
|
} |
269
|
0
|
|
|
|
|
|
my $response = $self -> {'ua'} -> request($request); |
270
|
0
|
0
|
|
|
|
|
unless ($response -> is_success) |
271
|
|
|
|
|
|
|
{ |
272
|
0
|
|
|
|
|
|
$self -> _error("METHOD:MOVE URI:$uri Status:" . $response -> status_line); |
273
|
0
|
|
|
|
|
|
return undef; |
274
|
|
|
|
|
|
|
} |
275
|
|
|
|
|
|
|
|
276
|
0
|
|
|
|
|
|
return 1; |
277
|
|
|
|
|
|
|
} |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
#-------------- |
280
|
|
|
|
|
|
|
sub useragent |
281
|
|
|
|
|
|
|
#-------------- |
282
|
|
|
|
|
|
|
{ |
283
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
284
|
|
|
|
|
|
|
|
285
|
0
|
|
|
|
|
|
return $self -> {'ua'}; |
286
|
|
|
|
|
|
|
} |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
1; |
289
|
|
|
|
|
|
|
__END__ |