blib/lib/Net/DAV/Server.pm

filter: Statementstmt 79.7% 410 / 514 Branchbran 76.8% 163 / 212 Conditioncond 70.2% 52 / 74 MC/DCmcdc 60.0% 27 / 45 Subroutinesub 90.9% 40 / 44 Podpod 0.0% 0 / 15 totaltotal 76.5% 692 / 904 CC 146 SCAR 34.0
CC
146
Cov
78%
copy
182.0
_copy_file
56.0
propfind
45.1
CRAP 30.0
↑ Summary blib/lib/Net/DAV/Lock.pm »
1 package Net::DAV::Server;
2 14 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 14 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use File::Slurp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 14 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 14 ▶use File::Find::Rule::Filesys::Virtual;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 14 ▶use HTTP::Date qw(time2str time2isoz);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 14 ▶use HTTP::Headers;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 14 ▶use HTTP::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 14 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 14 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 14 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 14 ▶use URI::Escape;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 14 ▶use XML::LibXML;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 14 ▶use XML::LibXML::XPathContext;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 14 ▶use Net::DAV::LockManager ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 14 ▶use Net::DAV::LockManager::DB ();
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 14 our $VERSION = '1.304';
20 14 $VERSION = eval $VERSION; # convert development version into a simpler version number.
21  
22 14 our %implemented = (
23 options => 1,
24 put => 1,
25 get => 1,
26 head => 1,
27 post => 1,
28 delete => 1,
29 mkcol => 1,
30 propfind => 1,
31 copy => 1,
32 lock => 1,
33 unlock => 1,
34 move => 1
35 );
36  
37 sub new {
38 94 ▶ my $class = shift;
Subroutine new: called CC=6 SCAR=17.9
Pod undocumented
39 94 ▶ my %args = @_ % 2 ? () : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ % 2 ? : 0 94 94
40 94 my $self = {};
41 94 ▶ if ( $args{'-dbobj'} ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($args{'-dbobj'}) { } 85 9 94
elsif ($args{'-dbfile'}) { } 1 8 9
elsif ($args{'-dsn'}) { } 1 7 8
42 85 $self->{'lock_manager'} = Net::DAV::LockManager->new( $args{'-dbobj'} );
43 }
44 elsif ( $args{'-dbfile'} ) {
45 1 $self->{'_dsn'} = "dbi:SQLite:dbname=$args{'-dbfile'}";
46 }
47 elsif ( $args{'-dsn'} ) {
48 1 $self->{'_dsn'} = $args{'-dsn'};
49 }
50 94 bless $self, $class;
51 94 ▶ if ( $args{'-filesys'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"-filesys"}) 65 29 94
52 65 $self->filesys( $args{'-filesys'} );
53 }
54 94 return $self;
55 }
56  
57 sub filesys {
58 231 ▶ my ($self, $nfs) = @_;
Subroutine filesys: called CC=2 SCAR=6.9
Pod undocumented
59 231 ▶ $self->{'-filesys'} = $nfs if defined $nfs;
Branch: 1 branch
BranchTrueFalseTotal
if defined $nfs 87 144 231
60 231 return $self->{'-filesys'};
61 }
62  
63 sub run {
64 20 ▶ my ( $self, $request, $response ) = @_;
Subroutine run: called CC=6 SCAR=17.9
Pod undocumented
65  
66 20 ▶ my $fs = $self->filesys || die 'Filesys missing';
Condition100%2/2
$self->filesys || die('Filesys missing')
l!l
191
MC/DC100%1/1
$self->filesys || die('Filesys missing')
$self->filesys
Truth table100%2/2
A
A= $self->filesys
Aresult
11
00
67  
68 19 my $method = $request->method;
69 19 my $path = uri_unescape $request->uri->path;
70  
71 19 ▶ if ( !defined $response ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $response) 2 17 19
72 2 $response = HTTP::Response->new;
73 }
74  
75 19 $method = lc $method;
76 19 ▶ if ( $implemented{$method} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Net::DAV::Server::implemented{$method}) { } 18 1 19
77 18 $response->code(200);
78 18 $response->message('OK');
79 eval {
80 18 $response = $self->$method( $request, $response );
81 17 ▶ $response->header( 'Content-Length' => length( $response->content ) ) if defined $response->content;
Branch: 1 branch
BranchTrueFalseTotal
if defined $response->content 17 0 17
82 17 1;
83 18 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $response = $self->$method($request, $response); $response->header("Content-Length", length $response->content) if defined $response->content; 1 } } or do { return "HTTP::Response"->new(400, "Bad Request") } 1 17 18
84 1 return HTTP::Response->new( 400, 'Bad Request' );
85 };
86 }
87 else {
88  
89 # Saying it isn't implemented is better than crashing!
90 1 $response->code(501);
91 1 $response->message('Not Implemented');
92 }
93 18 return $response;
94 }
95  
96 sub options {
97 3 ▶ my ( $self, $request, $response ) = @_;
Subroutine options: called CC=1 SCAR=0.0
Pod undocumented
98 3 $response->header( 'DAV' => '1,2,<http://apache.org/dav/propset/fs/1>' ); # Nautilus freaks out
99 3 $response->header( 'MS-Author-Via' => 'DAV' ); # Nautilus freaks out
100 3 $response->header( 'Allow' => join( ',', map { uc } keys %implemented ) );
101 3 $response->header( 'Content-Type' => 'httpd/unix-directory' );
102 3 $response->header( 'Keep-Alive' => 'timeout=15, max=96' );
103 3 return $response;
104 }
105  
106 sub head {
107 4 ▶ my ( $self, $request, $response ) = @_;
Subroutine head: called CC=4 SCAR=13.9
Pod undocumented
108 4 my $path = uri_unescape $request->uri->path;
109 4 my $fs = $self->filesys;
110  
111 4 ▶ if ( $fs->test( 'f', $path ) && $fs->test( 'r', $path ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($fs->test('f', $path) and $fs->test('r', $path)) { } 1 3 4
elsif ($fs->test('d', $path)) { } 1 2 3
Condition100%3/3
$fs->test("f", $path) and $fs->test("r", $path)
!ll&&!rl&&r
211
MC/DC100%2/2
$fs->test("f", $path) and $fs->test("r", $path)
$fs->test("f", $path) $fs->test("r", $path)
Truth table100%3/3
A and B
A= $fs->test("f", $path)B= $fs->test("r", $path)
ABresult
0X0
100
111
112 1 $response->last_modified( $fs->modtime($path) );
113 }
114 elsif ( $fs->test( 'd', $path ) ) {
115 1 $response->header( 'Content-Type' => 'text/html; charset="utf-8"' );
116 }
117 else {
118 2 $response = HTTP::Response->new( 404, 'NOT FOUND', $response->headers );
119 }
120 4 return $response;
121 }
122  
123 sub get {
124 5 ▶ my ( $self, $request, $response ) = @_;
Subroutine get: called CC=7 SCAR=19.5
Pod undocumented
125 5 my $path = uri_unescape $request->uri->path;
126 5 my $fs = $self->filesys;
127  
128 5 ▶ if ( $fs->test( 'f', $path ) && $fs->test( 'r', $path ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($fs->test('f', $path) and $fs->test('r', $path)) { } 1 4 5
elsif ($fs->test('d', $path)) { } 2 2 4
Condition100%3/3
$fs->test("f", $path) and $fs->test("r", $path)
!ll&&!rl&&r
311
MC/DC100%2/2
$fs->test("f", $path) and $fs->test("r", $path)
$fs->test("f", $path) $fs->test("r", $path)
Truth table100%3/3
A and B
A= $fs->test("f", $path)B= $fs->test("r", $path)
ABresult
0X0
100
111
129 1 my $fh = $fs->open_read($path);
130 1 my $file = join '', <$fh>;
131 1 $fs->close_read($fh);
132 1 $response->content($file);
133 1 $response->last_modified( $fs->modtime($path) );
134 }
135 elsif ( $fs->test( 'd', $path ) ) {
136  
137 # a web browser, then
138 2 my @files = $fs->list($path);
139 2 my $body;
140 2 ▶ my $fpath = $path =~ m{/$} ? $path : $path . '/';
Branch: 1 branch
BranchTrueFalseTotal
$path =~ m[/$] ? : 1 1 2
141 2 foreach my $file (@files) {
142 10 ▶ if ( $fs->test( 'd', $fpath . $file ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fs->test('d', $fpath . $file)) { } 3 7 10
143 3 $body .= qq|<a href="$file/">$file/</a><br>\n|;
144 }
145 else {
146 7 $file =~ s{/$}{};
147 7 $body .= qq|<a href="$file">$file</a><br>\n|;
148 }
149 }
150 2 $response->header( 'Content-Type' => 'text/html; charset="utf-8"' );
151 2 $response->content($body);
152 }
153 else {
154 2 return HTTP::Response->new( 404, 'Not Found' );
155 }
156 3 return $response;
157 }
158  
159 sub _lock_manager {
160 101 ▶ my ($self) = @_;
Subroutine _lock_manager: called CC=3 SCAR=16.7
161 101 ▶ unless ( $self->{'lock_manager'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"lock_manager"}) 0 101 101
162 0 ▶ if ( $self->{'_dsn'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_dsn'}) { } 0 0 0
163 0 my $db = Net::DAV::LockManager::DB->new( $self->{'_dsn'} );
164 0 $self->{'lock_manager'} = Net::DAV::LockManager->new($db);
165 }
166 else {
167 0 $self->{'lock_manager'} = Net::DAV::LockManager->new();
168 }
169 }
170 101 return $self->{'lock_manager'};
171 }
172  
173 sub lock {
174 38 ▶ my ( $self, $request, $response ) = @_;
Subroutine lock: called CC=14 SCAR=26.5
Pod undocumented
175  
176 38 my $lockreq = _parse_lock_request($request);
177  
178 # Invalid XML requires a 400 response code.
179 38 ▶ return HTTP::Response->new( 400, 'Bad Request' ) unless defined $lockreq;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $lockreq 0 38 38
180  
181 38 ▶ if ( !$lockreq->{'has_content'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($lockreq->{"has_content"}) 5 33 38
182  
183 # Not already locked.
184 5 ▶ return HTTP::Response->new( 403, 'Forbidden' ) if !$lockreq->{'token'};
Branch: 1 branch
BranchTrueFalseTotal
unless $lockreq->{"token"} 1 4 5
185  
186 # Reset timeout
187 4 ▶ if ( my $lock = $self->_lock_manager()->refresh_lock($lockreq) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $lock = $self->_lock_manager->refresh_lock($lockreq)) { } 1 3 4
188 1 $response->header( 'Content-Type' => 'text/xml; charset="utf-8"' );
189 1 $response->content(
190 _lock_response_content(
191 {
192 'path' => $lock->path,
193 'token' => $lock->token,
194 'timeout' => $lock->timeout,
195 'scope' => $lock->scope,
196 'depth' => $lock->depth,
197 }
198 )
199 );
200 }
201 else {
202 3 my $curr = $self->_lock_manager()->find_lock( { 'path' => $lockreq->{'path'} } );
203 3 ▶ return HTTP::Response->new( 412, 'Precondition Failed' ) unless $curr;
Branch: 1 branch
BranchTrueFalseTotal
unless $curr 1 2 3
204  
205 # Not the correct lock token
206 2 ▶ return HTTP::Response->new( 412, 'Precondition Failed' ) if $lockreq->{'token'} ne $curr->token;
Branch: 1 branch
BranchTrueFalseTotal
if $lockreq->{"token"} ne $curr->token 1 1 2
207  
208 # Not the correct user.
209 1 return HTTP::Response->new( 403, 'Forbidden' );
210 }
211 1 return $response;
212 }
213  
214 # Validate depth request
215 33 ▶ return HTTP::Response->new( 400, 'Bad Request' ) unless $lockreq->{'depth'} =~ /^(?:0|infinity)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $lockreq->{"depth"} =~ /^(?:0|infinity)$/ 1 32 33
216  
217 32 my $lock = $self->_lock_manager()->lock($lockreq);
218  
219 31 ▶ if ( !$lock ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($lock) 3 28 31
220 3 my $curr = $self->_lock_manager()->find_lock( { 'path' => $lockreq->{'path'} } );
221 3 ▶ return HTTP::Response->new( 412, 'Precondition Failed' ) unless $curr;
Branch: 1 branch
BranchTrueFalseTotal
unless $curr 0 3 3
222  
223 # Not the correct lock token
224 3 ▶ return HTTP::Response->new( 412, 'Precondition Failed' ) if $lockreq->{'token'}||'' ne $curr->token;
Branch: 1 branch
BranchTrueFalseTotal
if $lockreq->{"token"} or "" ne $curr->token 3 0 3
Condition66%2/3
$lockreq->{"token"} or "" ne $curr->token
l!l&&r!l&&!r
210
MC/DC0%0/2
$lockreq->{"token"} or "" ne $curr->token
$lockreq->{"token"} "" ne $curr->token
Truth table66%2/3
A or B
A= $lockreq->{"token"}B= "" ne $curr->token
ABresult
1X1
011
000
225  
226 # Resource is already locked
227 0 return HTTP::Response->new( 403, 'Forbidden' );
228 }
229  
230 28 my $token = $lock->token;
231 28 $response->code( 200 );
232 28 $response->message( 'OK' );
233 28 $response->header( 'Lock-Token', "<$token>" );
234 28 $response->header( 'Content-Type', 'text/xml; charset="utf-8"' );
235 $response->content(
236 _lock_response_content(
237 {
238 'path' => $lock->path,
239 'token' => $token,
240 'timeout' => $lock->timeout,
241 'scope' => 'exclusive',
242 'depth' => $lock->depth,
243 28 'owner_node' => $lockreq->{'owner_node'},
244 }
245 )
246 );
247  
248 # Create empty file if none exists, as per RFC 4918, Section 9.10.4
249 28 my $fs = $self->filesys;
250 28 ▶ if ( !$fs->test( 'e', $lock->path ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fs->test("e", $lock->path)) 9 19 28
251 9 my $fh = $fs->open_write( $lock->path, 1 );
252 9 ▶ $fs->close_write($fh) if $fh;
Branch: 1 branch
BranchTrueFalseTotal
if $fh 9 0 9
253 }
254  
255 28 return $response;
256 }
257  
258 sub _get_timeout {
259 78 ▶ my ($to_header) = @_;
Subroutine _get_timeout: called CC=5 SCAR=16.2
260 78 ▶ return undef unless defined $to_header and length $to_header;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $to_header and length $to_header 60 18 78
Condition66%2/3
defined $to_header and length $to_header
!ll&&!rl&&r
60018
MC/DC50%1/2
defined $to_header and length $to_header
defined $to_header length $to_header
Truth table66%2/3
A and B
A= defined $to_headerB= length $to_header
ABresult
0X0
100
111
261  
262 my @timeouts = sort
263 18 ▶ map { /Second-(\d+)/ ? $1 : $_ }
Branch: 1 branch
BranchTrueFalseTotal
/Second-(\d+)/ ? : 13 5 18
264 18 grep { $_ ne 'Infinite' }
265 split /\s*,\s*/, $to_header;
266  
267 18 ▶ return undef unless @timeouts;
Branch: 1 branch
BranchTrueFalseTotal
unless @timeouts 0 18 18
268 18 return $timeouts[0];
269 }
270  
271 sub _parse_lock_header {
272 78 ▶ my ($req) = @_;
Subroutine _parse_lock_header: called CC=4 SCAR=13.9
273 78 my $depth = $req->header('Depth');
274 78 ▶ my %lockreq = (
Branch: 1 branch
BranchTrueFalseTotal
defined $depth ? : 1 77 78
Condition75%3/4
($req->authorization_basic)[0] || ''
l!l
780
_extract_lock_token($req) || undef
l!l
1959
MC/DC0%0/1
($req->authorization_basic)[0] || ''
($req->authorization_basic)[0]
MC/DC100%1/1
_extract_lock_token($req) || undef
_extract_lock_token($req)
Truth table50%1/2
A
A= ($req->authorization_basic)[0]
Aresult
11
00
Truth table100%2/2
A
A= _extract_lock_token($req)
Aresult
11
00
275 'path' => uri_unescape( $req->uri->path ),
276  
277 # Assuming basic auth for now.
278 'user' => ( $req->authorization_basic() )[0] || '',
279 'token' => ( _extract_lock_token($req) || undef ),
280 'timeout' => _get_timeout( $req->header('Timeout') ),
281 'depth' => ( defined $depth ? $depth : 'infinity' ),
282 );
283 78 return \%lockreq;
284 }
285  
286 sub _parse_lock_request {
287 38 ▶ my ($req) = @_;
Subroutine _parse_lock_request: called CC=4 SCAR=13.9
288 38 my $lockreq = _parse_lock_header($req);
289 38 ▶ return $lockreq unless $req->content;
Branch: 1 branch
BranchTrueFalseTotal
unless $req->content 5 33 38
290  
291 33 my $parser = XML::LibXML->new;
292 33 my $doc;
293 33 ▶ eval { $doc = $parser->parse_string( $req->content ); } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $doc = $parser->parse_string($req->content) } } or do { return } 0 33 33
294  
295 # Request body must be a valid XML request
296 0 return;
297 };
298 33 my $xpc = XML::LibXML::XPathContext->new($doc);
299 33 $xpc->registerNs( 'D', 'DAV:' );
300  
301 # Want the following in list context.
302 33 $lockreq->{'owner_node'} = ( $xpc->findnodes('/D:lockinfo/D:owner') )[0];
303 33 ▶ if ( $lockreq->{'owner_node'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lockreq->{"owner_node"}) 33 0 33
304 33 my $owner = $lockreq->{'owner_node'}->toString;
305 33 $owner =~ s/^<(?:[^:]+:)?owner>//sm;
306 33 $owner =~ s!</(?:[^:]+:)?owner>$!!sm;
307 33 $lockreq->{'owner'} = $owner;
308 }
309 33 $lockreq->{'scope'} = eval { ( $xpc->findnodes('/D:lockinfo/D:lockscope/D:*') )[0]->localname; };
310 33 $lockreq->{'has_content'} = 1;
311  
312 33 return $lockreq;
313 }
314  
315 sub _extract_lock_token {
316 93 ▶ my ($req) = @_;
Subroutine _extract_lock_token: called CC=6 SCAR=17.9
317 93 my $token = $req->header('If');
318 93 ▶ unless ($token) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($token) 67 26 93
319 67 $token = $req->header('Lock-Token');
320 67 ▶ return $1 if defined $token && $token =~ /<([^>]+)>/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $token and $token =~ /<([^>]+)>/ 11 56 67
Condition100%3/3
defined $token and $token =~ /<([^>]+)>/
!ll&&!rl&&r
55111
MC/DC100%2/2
defined $token and $token =~ /<([^>]+)>/
defined $token $token =~ /<([^>]+)>/
Truth table100%3/3
A and B
A= defined $tokenB= $token =~ /<([^>]+)>/
ABresult
0X0
100
111
321 56 return undef;
322 }
323  
324 # Based on the last paragraph of section 10.4.1 of RFC 4918, it appears
325 # that any lock token that appears in the If header is available as a
326 # known lock token. Rather than trying to deal with the whole entity,
327 # lock, implicit and/or, and Not (with and without resources) thing,
328 # This code just returns a list of lock tokens found in the header.
329 26 my @tokens = map { $_ =~ /<([^>]+)>/g } ( $token =~ /\(([^\)]+)\)/g );
330  
331 26 ▶ return undef unless @tokens;
Branch: 1 branch
BranchTrueFalseTotal
unless @tokens 4 22 26
332 22 ▶ return @tokens == 1 ? $tokens[0] : \@tokens;
Branch: 1 branch
BranchTrueFalseTotal
@tokens == 1 ? : 10 12 22
333 }
334  
335 sub _lock_response_content {
336 29 ▶ my ($args) = @_;
Subroutine _lock_response_content: called CC=4 SCAR=13.9
337 29 my $resp = XML::LibXML::Document->new( '1.0', 'utf-8' );
338 29 my $prop = _dav_root( $resp, 'prop' );
339 29 my $lock = _dav_child( _dav_child( $prop, 'lockdiscovery' ), 'activelock' );
340 29 _dav_child( _dav_child( $lock, 'locktype' ), 'write' );
341 29 ▶ _dav_child( _dav_child( $lock, 'lockscope' ), $args->{'scope'} || 'exclusive' );
Condition50%1/2
$args->{'scope'} || 'exclusive'
l!l
290
MC/DC0%0/1
$args->{'scope'} || 'exclusive'
$args->{'scope'}
Truth table50%1/2
A
A= $args->{'scope'}
Aresult
11
00
342 29 ▶ _dav_child( $lock, 'depth', $args->{'depth'} || 'infinity' );
Condition50%1/2
$args->{'depth'} || 'infinity'
l!l
290
MC/DC0%0/1
$args->{'depth'} || 'infinity'
$args->{'depth'}
Truth table50%1/2
A
A= $args->{'depth'}
Aresult
11
00
343 29 ▶ if ( $args->{'owner_node'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"owner_node"}) 28 1 29
344 28 my $owner = $args->{'owner_node'}->cloneNode(1);
345 28 $resp->adoptNode($owner);
346 28 $lock->addChild($owner);
347 }
348 29 _dav_child( $lock, 'timeout', "Second-$args->{'timeout'}" );
349 29 _dav_child( _dav_child( $lock, 'locktoken' ), 'href', $args->{'token'} );
350 29 _dav_child( _dav_child( $lock, 'lockroot' ), 'href', $args->{'path'} );
351  
352 29 return $resp->toString;
353 }
354  
355 sub _active_lock_prop {
356 6 ▶ my ( $doc, $lock ) = @_;
Subroutine _active_lock_prop: called CC=1 SCAR=0.0
357 6 my $active = $doc->createElement('D:activelock');
358  
359 # All locks are write
360 6 _dav_child( _dav_child( $active, 'locktype' ), 'write' );
361 6 _dav_child( _dav_child( $active, 'lockscope' ), $lock->scope );
362 6 _dav_child( $active, 'depth', $lock->depth );
363 6 $active->appendWellBalancedChunk( '<D:owner xmlns:D="DAV:">' . $lock->owner . '</D:owner>' );
364 6 _dav_child( $active, 'timeout', 'Second-' . $lock->timeout );
365 6 _dav_child( _dav_child( $active, 'locktoken' ), 'href', $lock->token );
366 6 _dav_child( _dav_child( $active, 'lockroot' ), 'href', $lock->path );
367  
368 6 return $active;
369 }
370  
371 sub unlock {
372 12 ▶ my ( $self, $request, $response ) = @_;
Subroutine unlock: called CC=4 SCAR=13.9
Pod undocumented
373 12 my $path = uri_unescape( $request->uri->path );
374 12 my $lockreq = _parse_lock_header($request);
375  
376 # No lock token supplied, we cannot unlock
377 12 ▶ return HTTP::Response->new( 400, 'Bad Request' ) unless $lockreq->{'token'};
Branch: 1 branch
BranchTrueFalseTotal
unless $lockreq->{"token"} 1 11 12
378  
379 11 ▶ if ( !$self->_lock_manager()->unlock($lockreq) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_lock_manager->unlock($lockreq)) 2 9 11
380 2 my $curr = $self->_lock_manager()->find_lock( { 'path' => $lockreq->{'path'} } );
381  
382 # No lock exists, conflicting requirements.
383 2 ▶ return HTTP::Response->new( 409, 'Conflict' ) unless $curr;
Branch: 1 branch
BranchTrueFalseTotal
unless $curr 1 1 2
384  
385 # Not the owner of the lock or bad token.
386 1 return HTTP::Response->new( 403, 'Forbidden' );
387 }
388  
389 9 return HTTP::Response->new( 204, 'No content' );
390 }
391  
392 sub _dav_child {
393 752 ▶ my ( $parent, $tag, $text ) = @_;
Subroutine _dav_child: called CC=2 SCAR=6.9
394 752 my $child = $parent->ownerDocument->createElement("D:$tag");
395 752 $parent->addChild($child);
396 752 ▶ $child->appendText($text) if defined $text;
Branch: 1 branch
BranchTrueFalseTotal
if defined $text 266 486 752
397 752 return $child;
398 }
399  
400 sub _dav_root {
401 29 ▶ my ( $doc, $tag ) = @_;
Subroutine _dav_root: called CC=1 SCAR=0.0
402 29 my $root = $doc->createElementNS( 'DAV:', $tag );
403 29 $root->setNamespace( 'DAV:', 'D', 1 );
404 29 $doc->setDocumentElement($root);
405 29 return $root;
406 }
407  
408 sub _can_modify {
409 28 ▶ my ( $self, $request ) = @_;
Subroutine _can_modify: called CC=1 SCAR=0.0
410 28 my $lockreq = _parse_lock_header($request);
411 28 return $self->_lock_manager()->can_modify($lockreq);
412 }
413  
414 sub post {
415 2 ▶ my ( $self, $request, $response ) = @_;
Subroutine post: called CC=2 SCAR=6.9
Pod undocumented
416  
417 2 ▶ if ( !$self->_can_modify( $request ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_can_modify($request)) 1 1 2
418 1 return HTTP::Response->new( 403, 'Forbidden' );
419 }
420  
421 1 return HTTP::Response->new( 501, 'Not Implemented' );
422 }
423  
424 sub put {
425 9 ▶ my ( $self, $request, $response ) = @_;
Subroutine put: called CC=6 SCAR=17.9
Pod undocumented
426  
427 9 ▶ if ( !$self->_can_modify($request) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_can_modify($request)) 4 5 9
428 4 return HTTP::Response->new( 403, 'Forbidden' );
429 }
430  
431 5 my $path = uri_unescape $request->uri->path;
432 5 my $fs = $self->filesys;
433  
434 5 ▶ return HTTP::Response->new( 405, 'Method Not Allowed' ) if $fs->test( 'd', $path );
Branch: 1 branch
BranchTrueFalseTotal
if $fs->test("d", $path) 1 4 5
435 4 my $parent = $path;
436 4 $parent =~ s{/[^/]+$}{};
437 4 ▶ $parent = '/' if $parent eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $parent eq "" 3 1 4
438 # Parent directory does not exist.
439 4 ▶ return HTTP::Response->new( 409, 'Conflict' ) unless $fs->test( 'd', $parent );
Branch: 1 branch
BranchTrueFalseTotal
unless $fs->test("d", $parent) 1 3 4
440  
441 3 my $fh = $fs->open_write( $path );
442 3 ▶ if ( $fh ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fh) { } 2 1 3
443 2 $response = HTTP::Response->new( 201, 'Created', $response->headers );
444 2 print $fh $request->content;
445 2 $fs->close_write($fh);
446 }
447 else {
448 # Unable to write for some other reason.
449 1 return HTTP::Response->new( 403, 'Forbidden' );
450 }
451  
452 2 return $response;
453 }
454  
455 sub _delete_xml {
456 0 ▶ my ( $dom, $path ) = @_;
Subroutine _delete_xml: not called CC=1 SCAR=6.9
457  
458 0 my $response = $dom->createElement('d:response');
459 0 $response->appendTextChild( 'd:href' => $path );
460 0 $response->appendTextChild( 'd:status' => 'HTTP/1.1 401 Permission Denied' ); # *** FIXME ***
461 }
462  
463 sub delete {
464 9 ▶ my ( $self, $request, $response ) = @_;
Subroutine delete: called CC=12 SCAR=25.8
Pod undocumented
465  
466 9 ▶ if ( !$self->_can_modify($request) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_can_modify($request)) 4 5 9
467 4 return HTTP::Response->new( 403, 'Forbidden' );
468 }
469  
470 5 ▶ if ( $request->uri->fragment ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($request->uri->fragment) 1 4 5
471 1 return HTTP::Response->new( 404, 'Not Found', $response->headers );
472 }
473  
474 4 my $path = uri_unescape $request->uri->path;
475 4 my $fs = $self->filesys;
476 4 ▶ unless ( $fs->test( 'e', $path ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fs->test("e", $path)) 1 3 4
477 1 return HTTP::Response->new( 404, 'Not Found', $response->headers );
478 }
479  
480 3 my $dom = XML::LibXML::Document->new( '1.0', 'utf-8' );
481 3 my @error;
482 3 foreach my $part (
483 6 grep { $_ !~ m{/\.\.?$} }
484 6 map { s{/+}{/}g; $_ }
485 File::Find::Rule::Filesys::Virtual->virtual($fs)->in($path), $path
486 ) {
487  
488 6 ▶ next unless $fs->test( 'e', $part );
Branch: 1 branch
BranchTrueFalseTotal
unless $fs->test("e", $part) 1 5 6
489  
490 5 ▶ if ( $fs->test( 'f', $part ) ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($fs->test('f', $part)) { } 3 2 5
elsif ($fs->test('d', $part)) { } 2 0 2
491 3 ▶ push @error, _delete_xml( $dom, $part )
Branch: 1 branch
BranchTrueFalseTotal
unless $fs->delete($part) 0 3 3
492 unless $fs->delete($part);
493 }
494 elsif ( $fs->test( 'd', $part ) ) {
495 2 ▶ push @error, _delete_xml( $dom, $part )
Branch: 1 branch
BranchTrueFalseTotal
unless $fs->rmdir($part) 0 2 2
496 unless $fs->rmdir($part);
497 }
498 }
499  
500 3 ▶ if (@error) {
Branch: 1 branch
BranchTrueFalseTotal
if (@error) { } 0 3 3
501 0 my $multistatus = $dom->createElement('D:multistatus');
502 0 $multistatus->setAttribute( 'xmlns:D', 'DAV:' );
503  
504 0 $multistatus->addChild($_) foreach @error;
505  
506 0 $response = HTTP::Response->new( 207 => 'Multi-Status' );
507 0 $response->header( 'Content-Type' => 'text/xml; charset="utf-8"' );
508 }
509 else {
510 3 $response = HTTP::Response->new( 204 => 'No Content' );
511 }
512 3 return $response;
513 }
514  
515 sub copy {
516 0 ▶ my ( $self, $request, $response ) = @_;
Subroutine copy: not called CC=13 SCAR=52.0
Pod undocumented
517 0 my $path = uri_unescape $request->uri->path;
518  
519 # need to modify request to pay attention to destination address.
520 0 my $lockreq = _parse_lock_header( $request );
521 0 $lockreq->{'path'} = uri_unescape( $request->header( 'Destination' ) );
522 0 ▶ if ( !$self->_lock_manager()->can_modify( $lockreq ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_lock_manager->can_modify($lockreq)) 0 0 0
523 0 return HTTP::Response->new( 403, 'Forbidden' );
524 }
525 0 my $fs = $self->filesys;
526  
527 0 my $destination = $request->header('Destination');
528 0 $destination = URI->new($destination)->path;
529 0 ▶ my $depth = $request->header('Depth') || 0;
Condition0%0/2
$request->header('Depth') || 0
l!l
00
MC/DC0%0/1
$request->header('Depth') || 0
$request->header('Depth')
Truth table0%0/2
A
A= $request->header('Depth')
Aresult
11
00
530 0 ▶ my $overwrite = $request->header('Overwrite') || 'F';
Condition0%0/2
$request->header('Overwrite') || 'F'
l!l
00
MC/DC0%0/1
$request->header('Overwrite') || 'F'
$request->header('Overwrite')
Truth table0%0/2
A
A= $request->header('Overwrite')
Aresult
11
00
531  
532 0 ▶ if ( $fs->test( "f", $path ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fs->test("f", $path)) 0 0 0
533 0 return $self->_copy_file( $request, $response );
534 }
535  
536 # it's a good approximation
537 0 ▶ $depth = 100 if defined $depth && $depth eq 'infinity';
Branch: 1 branch
BranchTrueFalseTotal
if defined $depth and $depth eq "infinity" 0 0 0
Condition0%0/3
defined $depth and $depth eq "infinity"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $depth and $depth eq "infinity"
defined $depth $depth eq "infinity"
Truth table0%0/3
A and B
A= defined $depthB= $depth eq "infinity"
ABresult
0X0
100
111
538  
539 my @files =
540 0 map { s{/+}{/}g; $_ }
541 File::Find::Rule::Filesys::Virtual->virtual($fs)->file->maxdepth($depth)
542 ->in($path);
543  
544 my @dirs = reverse sort
545 0 grep { $_ !~ m{/\.\.?$} }
546 0 map { s{/+}{/}g; $_ }
547 File::Find::Rule::Filesys::Virtual->virtual($fs)->directory->maxdepth($depth)
548 ->in($path);
549  
550 0 push @dirs, $path;
551 0 foreach my $dir ( sort @dirs ) {
552 0 my $destdir = $dir;
553 0 $destdir =~ s/^$path/$destination/;
554 0 ▶ if ( $overwrite eq 'F' && $fs->test( "e", $destdir ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($overwrite eq "F" and $fs->test("e", $destdir)) 0 0 0
Condition0%0/3
$overwrite eq "F" and $fs->test("e", $destdir)
!ll&&!rl&&r
000
MC/DC0%0/2
$overwrite eq "F" and $fs->test("e", $destdir)
$overwrite eq "F" $fs->test("e", $destdir)
Truth table0%0/3
A and B
A= $overwrite eq "F"B= $fs->test("e", $destdir)
ABresult
0X0
100
111
555 0 return HTTP::Response->new( 401, "ERROR", $response->headers );
556 }
557 0 $fs->mkdir($destdir);
558 }
559  
560 0 foreach my $file ( reverse sort @files ) {
561 0 my $destfile = $file;
562 0 $destfile =~ s/^$path/$destination/;
563 0 my $fh = $fs->open_read($file);
564 0 my $file = join '', <$fh>;
565 0 $fs->close_read($fh);
566 0 ▶ if ( $fs->test( 'e', $destfile ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fs->test('e', $destfile)) { } 0 0 0
567 0 ▶ if ( $overwrite eq 'T' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($overwrite eq 'T') { } 0 0 0
568 0 $fh = $fs->open_write($destfile);
569 0 print $fh $file;
570 0 $fs->close_write($fh);
571 }
572 else {
573 0 return HTTP::Response( 412, 'Precondition Failed' );
574 }
575 }
576 else {
577 0 $fh = $fs->open_write($destfile);
578 0 print $fh $file;
579 0 $fs->close_write($fh);
580 }
581 }
582  
583 0 $response = HTTP::Response->new( 200, 'OK', $response->headers );
584 0 return $response;
585 }
586  
587 sub _copy_file {
588 0 ▶ my ( $self, $request, $response ) = @_;
Subroutine _copy_file: not called CC=7 SCAR=40.3
589 0 my $path = uri_unescape $request->uri->path;
590 0 my $fs = $self->filesys;
591  
592 0 my $destination = $request->header('Destination');
593 0 $destination = URI->new($destination)->path;
594 0 my $depth = $request->header('Depth');
595 0 my $overwrite = $request->header('Overwrite');
596  
597 0 ▶ if ( $fs->test( 'd', $destination ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fs->test("d", $destination)) 0 0 0
598 0 return HTTP::Response->new( 204, 'No Content', $response->headers );
599 }
600 0 ▶ if ( $fs->test( 'f', $path ) && $fs->test( 'r', $path ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fs->test('f', $path) and $fs->test('r', $path)) { } 0 0 0
Condition0%0/3
$fs->test("f", $path) and $fs->test("r", $path)
!ll&&!rl&&r
000
MC/DC0%0/2
$fs->test("f", $path) and $fs->test("r", $path)
$fs->test("f", $path) $fs->test("r", $path)
Truth table0%0/3
A and B
A= $fs->test("f", $path)B= $fs->test("r", $path)
ABresult
0X0
100
111
601 0 my $fh = $fs->open_read($path);
602 0 my $file = join '', <$fh>;
603 0 $fs->close_read($fh);
604 0 ▶ if ( $fs->test( 'f', $destination ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fs->test('f', $destination)) { } 0 0 0
605 0 ▶ if ( $overwrite eq 'T' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($overwrite eq 'T') { } 0 0 0
606 0 $fh = $fs->open_write($destination);
607 0 print $fh $file;
608 0 $fs->close_write($fh);
609 }
610 else {
611 0 return HTTP::Response( 412, 'Precondition Failed' );
612 }
613 }
614 else {
615 0 ▶ unless ( $fh = $fs->open_write($destination) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fh = $fs->open_write($destination)) 0 0 0
616 0 return HTTP::Response->new( 409, 'Conflict' );
617 }
618 0 print $fh $file;
619 0 $fs->close_write($fh);
620 0 $response->code(201);
621 0 $response->message('Created');
622 }
623 }
624 else {
625 0 return HTTP::Response->new( 404, 'Not Found' );
626 }
627  
628 0 return $response;
629 }
630  
631 sub move {
632 0 ▶ my ( $self, $request, $response ) = @_;
Subroutine move: not called CC=5 SCAR=34.0
Pod undocumented
633  
634 # need to check both paths for locks.
635 0 my $lockreq = _parse_lock_header( $request );
636 0 ▶ if ( !$self->_lock_manager()->can_modify( $lockreq ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_lock_manager->can_modify($lockreq)) 0 0 0
637 0 return HTTP::Response->new( 403, 'Forbidden' );
638 }
639 0 $lockreq->{'path'} = uri_unescape( $request->header( 'Destination' ) );
640 0 ▶ if ( !$self->_lock_manager()->can_modify( $lockreq ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_lock_manager->can_modify($lockreq)) 0 0 0
641 0 return HTTP::Response->new( 403, 'Forbidden' );
642 }
643  
644 0 my $destination = $request->header('Destination');
645 0 $destination = URI->new($destination)->path;
646 0 my $destexists = $self->filesys->test( "e", $destination );
647  
648 0 $response = $self->copy( $request, $response );
649 0 ▶ $response = $self->delete( $request, $response )
Branch: 1 branch
BranchTrueFalseTotal
if $response->is_success 0 0 0
650 if $response->is_success;
651  
652 0 ▶ $response->code(201) unless $destexists;
Branch: 1 branch
BranchTrueFalseTotal
unless $destexists 0 0 0
653  
654 0 return $response;
655 }
656  
657 sub mkcol {
658 8 ▶ my ( $self, $request, $response ) = @_;
Subroutine mkcol: called CC=5 SCAR=16.2
Pod undocumented
659 8 my $path = uri_unescape $request->uri->path;
660  
661 8 ▶ if ( !$self->_can_modify($request) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_can_modify($request)) 2 6 8
662 2 return HTTP::Response->new( 403, 'Forbidden' );
663 }
664  
665 6 my $fs = $self->filesys;
666  
667 6 ▶ return HTTP::Response->new( 415, 'Unsupported Media Type' ) if $request->content;
Branch: 1 branch
BranchTrueFalseTotal
if $request->content 1 5 6
668 5 ▶ return HTTP::Response->new( 405, 'Method Not Allowed' ) if $fs->test( 'e', $path );
Branch: 1 branch
BranchTrueFalseTotal
if $fs->test("e", $path) 2 3 5
669 3 $fs->mkdir($path);
670 3 ▶ if ( $fs->test( 'd', $path ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($fs->test('d', $path)) { } 3 0 3
671 3 $response->code(201);
672 3 $response->message('Created');
673 }
674 else {
675 0 $response->code(409);
676 0 $response->message('Conflict');
677 }
678  
679 3 return $response;
680 }
681  
682 sub propfind {
683 34 ▶ my ( $self, $request, $response ) = @_;
Subroutine propfind: called CC=45 SCAR=38.1
Pod undocumented
684 34 my $path = uri_unescape $request->uri->path;
685 34 my $fs = $self->filesys;
686 34 my $depth = $request->header('Depth');
687  
688 34 my $reqinfo = 'allprop';
689 34 my @reqprops;
690 34 ▶ if ( $request->header('Content-Length') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($request->header("Content-Length")) 28 6 34
691 28 my $content = $request->content;
692 28 my $parser = XML::LibXML->new;
693 28 my $doc;
694 28 eval { $doc = $parser->parse_string($content); };
695 28 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 28 28
696 0 return HTTP::Response->new( 400, 'Bad Request' );
697 }
698  
699 #$reqinfo = doc->find('/DAV:propfind/*')->localname;
700 28 $reqinfo = $doc->find('/*/*')->shift->localname;
701 28 ▶ if ( $reqinfo eq 'prop' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reqinfo eq "prop") 19 9 28
702  
703 #for my $node ($doc->find('/DAV:propfind/DAV:prop/*')) {
704 19 for my $node ( $doc->find('/*/*/*')->get_nodelist ) {
705 19 push @reqprops, [ $node->namespaceURI, $node->localname ];
706 }
707 }
708 }
709  
710 34 ▶ if ( !$fs->test( 'e', $path ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fs->test("e", $path)) 3 31 34
711 3 return HTTP::Response->new( 404, 'Not Found' );
712 }
713  
714 31 $response->code(207);
715 31 $response->message('Multi-Status');
716 31 $response->header( 'Content-Type' => 'text/xml; charset="utf-8"' );
717  
718 31 my $doc = XML::LibXML::Document->new( '1.0', 'utf-8' );
719 31 my $multistat = $doc->createElement('D:multistatus');
720 31 $multistat->setAttribute( 'xmlns:D', 'DAV:' );
721 31 $doc->setDocumentElement($multistat);
722  
723 31 my @paths;
724 31 ▶ if ( defined $depth && $depth eq 1 and $fs->test( 'd', $path ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $depth and $depth eq 1 and $fs->test('d', $path)) { } 1 30 31
Condition66%4/6
defined $depth and $depth eq 1 and $fs->test("d", $path)
!ll&&!rl&&r
3001
defined $depth and $depth eq 1
!ll&&!rl&&r
3001
MC/DC33%1/3
defined $depth and $depth eq 1 and $fs->test("d", $path)
defined $depth $depth eq 1 $fs->test("d", $path)
Truth table50%2/4
A and B and C
A= defined $depthB= $depth eq 1C= $fs->test("d", $path)
ABCresult
0XX0
10X0
1100
1111
725 1 my $p = $path;
726 1 ▶ $p .= '/' unless $p =~ m{/$};
Branch: 1 branch
BranchTrueFalseTotal
unless $p =~ m[/$] 0 1 1
727 1 @paths = map { $p . $_ } File::Spec->no_upwards( $fs->list($path) );
728 1 push @paths, $path;
729 }
730 else {
731 30 @paths = ($path);
732 }
733  
734 31 for my $path (@paths) {
735 my (
736 35 $dev, $ino, $mode, $nlink, $uid, $gid, $rdev,
737 $size, $atime, $mtime, $ctime, $blksize, $blocks
738 ) = $fs->stat($path);
739  
740 # modified time is stringified human readable HTTP::Date style
741 35 $mtime = time2str($mtime);
742  
743 # created time is ISO format
744 # tidy up date format - isoz isn't exactly what we want, but
745 # it's easy to change.
746 35 $ctime = time2isoz($ctime);
747 35 $ctime =~ s/ /T/;
748 35 $ctime =~ s/Z//;
749  
750 35 ▶ $size ||= '';
Condition100%2/2
$size ||= ""
l!l
1718
MC/DC100%1/1
$size ||= ""
$size
Truth table100%2/2
A
A= $size
Aresult
11
00
751  
752 35 my $is_dir = $fs->test( 'd', $path );
753 35 my $resp = _dav_child( $multistat, 'response' );
754 my $href = File::Spec->catdir(
755 35 ▶ map { uri_escape $_} File::Spec->splitdir($path)
Branch: 1 branch
BranchTrueFalseTotal
$is_dir && !($path =~ m[/$]) ? : 5 30 35
Condition100%3/3
$is_dir and not $path =~ m[/$]
!ll&&!rl&&r
17135
MC/DC100%2/2
$is_dir and not $path =~ m[/$]
$is_dir not $path =~ m[/$]
Truth table100%3/3
A and not(B)
A= $is_dirB= not $path =~ m[/$]
ABresult
0X0
100
111
756 ) . ( $is_dir && $path !~ m{/$} ? '/' : '');
757 35 $href =~ tr{\\}{/}; # Protection from wrong slashes under Windows.
758 35 _dav_child( $resp, 'href', $href );
759 35 my $okprops = $doc->createElement('D:prop');
760 35 my $nfprops = $doc->createElement('D:prop');
761 35 my $prop;
762  
763 35 ▶ if ( $reqinfo eq 'prop' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($reqinfo eq 'prop') { } 19 16 35
elsif ($reqinfo eq 'propname') { } 2 14 16
764 19 my %prefixes = ( 'DAV:' => 'D' );
765 19 my $i = 0;
766  
767 19 for my $reqprop (@reqprops) {
768 19 my ( $ns, $name ) = @$reqprop;
769 19 ▶ if ( $ns eq 'DAV:' && $name eq 'creationdate' ) {
Branch: 7 branches
BranchTrueFalseTotal
if ($ns eq 'DAV:' and $name eq 'creationdate') { } 2 17 19
elsif ($ns eq 'DAV:' and $name eq 'getcontentlength') { } 2 15 17
elsif ($ns eq 'DAV:' and $name eq 'getcontenttype') { } 2 13 15
elsif ($ns eq 'DAV:' and $name eq 'getlastmodified') { } 2 11 13
elsif ($ns eq 'DAV:' and $name eq 'resourcetype') { } 2 9 11
elsif ($ns eq 'DAV:' and $name eq 'lockdiscovery') { } 4 5 9
elsif ($ns eq 'DAV:' and $name eq 'supportedlock') { } 2 3 5
Condition100%3/3
$ns eq "DAV:" and $name eq "creationdate"
!ll&&!rl&&r
1162
MC/DC100%2/2
$ns eq "DAV:" and $name eq "creationdate"
$ns eq "DAV:" $name eq "creationdate"
Truth table100%3/3
A and B
A= $ns eq "DAV:"B= $name eq "creationdate"
ABresult
0X0
100
111
770 2 _dav_child( $okprops, 'creationdate', $ctime );
771 }
772 ▶ elsif ( $ns eq 'DAV:' && $name eq 'getcontentlength' ) {
Condition100%3/3
$ns eq "DAV:" and $name eq "getcontentlength"
!ll&&!rl&&r
1142
MC/DC100%2/2
$ns eq "DAV:" and $name eq "getcontentlength"
$ns eq "DAV:" $name eq "getcontentlength"
Truth table100%3/3
A and B
A= $ns eq "DAV:"B= $name eq "getcontentlength"
ABresult
0X0
100
111
773 2 ▶ _dav_child( $okprops, 'getcontentlength', $is_dir ? () : ($size) );
Branch: 1 branch
BranchTrueFalseTotal
$is_dir ? : 1 1 2
774 }
775 ▶ elsif ( $ns eq 'DAV:' && $name eq 'getcontenttype' ) {
Condition100%3/3
$ns eq "DAV:" and $name eq "getcontenttype"
!ll&&!rl&&r
1122
MC/DC100%2/2
$ns eq "DAV:" and $name eq "getcontenttype"
$ns eq "DAV:" $name eq "getcontenttype"
Truth table100%3/3
A and B
A= $ns eq "DAV:"B= $name eq "getcontenttype"
ABresult
0X0
100
111
776 2 ▶ _dav_child( $okprops, 'getcontenttype', $is_dir ? 'httpd/unix-directory' : 'httpd/unix-file' );
Branch: 1 branch
BranchTrueFalseTotal
$is_dir ? : 1 1 2
777 }
778 ▶ elsif ( $ns eq 'DAV:' && $name eq 'getlastmodified' ) {
Condition100%3/3
$ns eq "DAV:" and $name eq "getlastmodified"
!ll&&!rl&&r
1102
MC/DC100%2/2
$ns eq "DAV:" and $name eq "getlastmodified"
$ns eq "DAV:" $name eq "getlastmodified"
Truth table100%3/3
A and B
A= $ns eq "DAV:"B= $name eq "getlastmodified"
ABresult
0X0
100
111
779 2 _dav_child( $okprops, 'getlastmodified', $mtime );
780 }
781 ▶ elsif ( $ns eq 'DAV:' && $name eq 'resourcetype' ) {
Condition100%3/3
$ns eq "DAV:" and $name eq "resourcetype"
!ll&&!rl&&r
182
MC/DC100%2/2
$ns eq "DAV:" and $name eq "resourcetype"
$ns eq "DAV:" $name eq "resourcetype"
Truth table100%3/3
A and B
A= $ns eq "DAV:"B= $name eq "resourcetype"
ABresult
0X0
100
111
782 2 $prop = _dav_child( $okprops, 'resourcetype' );
783 2 ▶ if ( $is_dir ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_dir) 1 1 2
784 1 _dav_child( $prop, 'collection' );
785 }
786 }
787 ▶ elsif ( $ns eq 'DAV:' && $name eq 'lockdiscovery' ) {
Condition100%3/3
$ns eq "DAV:" and $name eq "lockdiscovery"
!ll&&!rl&&r
144
MC/DC100%2/2
$ns eq "DAV:" and $name eq "lockdiscovery"
$ns eq "DAV:" $name eq "lockdiscovery"
Truth table100%3/3
A and B
A= $ns eq "DAV:"B= $name eq "lockdiscovery"
ABresult
0X0
100
111
788 4 $prop = _dav_child( $okprops, 'lockdiscovery' );
789 4 ▶ my $user = ($request->authorization_basic())[0]||'';
Condition50%1/2
($request->authorization_basic)[0] || ''
l!l
40
MC/DC0%0/1
($request->authorization_basic)[0] || ''
($request->authorization_basic)[0]
Truth table50%1/2
A
A= ($request->authorization_basic)[0]
Aresult
11
00
790 4 foreach my $lock ( $self->_lock_manager()->list_all_locks({ 'path' => $path, 'user' => $user }) ) {
791 2 my $active = _active_lock_prop( $doc, $lock );
792 2 $prop->addChild( $active );
793 }
794 }
795 ▶ elsif ( $ns eq 'DAV:' && $name eq 'supportedlock' ) {
Condition100%3/3
$ns eq "DAV:" and $name eq "supportedlock"
!ll&&!rl&&r
122
MC/DC100%2/2
$ns eq "DAV:" and $name eq "supportedlock"
$ns eq "DAV:" $name eq "supportedlock"
Truth table100%3/3
A and B
A= $ns eq "DAV:"B= $name eq "supportedlock"
ABresult
0X0
100
111
796 2 $prop = _supportedlock_child( $okprops );
797 }
798 else {
799 3 my $prefix = $prefixes{$ns};
800 3 ▶ if ( !defined $prefix ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $prefix) 1 2 3
801 1 $prefix = 'i' . $i++;
802  
803 # mod_dav sets <response> 'xmlns' attribute - whatever
804 #$nfprops->setAttribute("xmlns:$prefix", $ns);
805 1 $resp->setAttribute( "xmlns:$prefix", $ns );
806  
807 1 $prefixes{$ns} = $prefix;
808 }
809  
810 3 $prop = $doc->createElement("$prefix:$name");
811 3 $nfprops->addChild($prop);
812 }
813 }
814 }
815 elsif ( $reqinfo eq 'propname' ) {
816 2 _dav_child( $okprops, 'creationdate' );
817 2 _dav_child( $okprops, 'getcontentlength' );
818 2 _dav_child( $okprops, 'getcontenttype' );
819 2 _dav_child( $okprops, 'getlastmodified' );
820 2 _dav_child( $okprops, 'supportedlock' );
821 2 _dav_child( $okprops, 'resourcetype' );
822 }
823 else {
824 14 _dav_child( $okprops, 'creationdate', $ctime );
825 14 ▶ _dav_child( $okprops, 'getcontentlength', $is_dir ? () : ($size) );
Branch: 1 branch
BranchTrueFalseTotal
$is_dir ? : 7 7 14
826 14 ▶ _dav_child( $okprops, 'getcontenttype', $is_dir ? 'httpd/unix-directory' : 'httpd/unix-file' );
Branch: 1 branch
BranchTrueFalseTotal
$is_dir ? : 7 7 14
827 14 _dav_child( $okprops, 'getlastmodified', $mtime );
828 14 $prop = _supportedlock_child( $okprops );
829 14 ▶ my $user = ($request->authorization_basic())[0]||'';
Condition50%1/2
($request->authorization_basic)[0] || ''
l!l
140
MC/DC0%0/1
($request->authorization_basic)[0] || ''
($request->authorization_basic)[0]
Truth table50%1/2
A
A= ($request->authorization_basic)[0]
Aresult
11
00
830 14 my @locks = $self->_lock_manager()->list_all_locks({ 'path' => $path, 'user' => $user });
831 14 ▶ if ( @locks ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@locks) 4 10 14
832 4 $prop = _dav_child( $okprops, 'lockdiscovery' );
833 4 foreach my $lock ( @locks ) {
834 4 my $active = _active_lock_prop( $doc, $lock );
835 4 $prop->addChild( $active );
836 }
837 }
838 14 $prop = _dav_child( $okprops, 'resourcetype' );
839 14 ▶ if ( $is_dir ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_dir) 7 7 14
840 7 _dav_child( $prop, 'collection' );
841 }
842 }
843  
844 35 ▶ if ( $okprops->hasChildNodes ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($okprops->hasChildNodes) 32 3 35
845 32 my $propstat = _dav_child( $resp, 'propstat' );
846 32 $propstat->addChild($okprops);
847 32 _dav_child( $propstat, 'status', 'HTTP/1.1 200 OK' );
848 }
849  
850 35 ▶ if ( $nfprops->hasChildNodes ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nfprops->hasChildNodes) 3 32 35
851 3 my $propstat = _dav_child( $resp, 'propstat' );
852 3 $propstat->addChild($nfprops);
853 3 _dav_child( $propstat, 'status', 'HTTP/1.1 404 Not Found' );
854 }
855 }
856  
857 #this must be 0 as certin ms webdav clients choke on 1
858 31 $response->content( $doc->toString(0) );
859  
860 31 return $response;
861 }
862  
863 sub _supportedlock_child {
864 16 ▶ my ($okprops) = @_;
Subroutine _supportedlock_child: called CC=2 SCAR=6.9
865 16 my $prop = _dav_child( $okprops, 'supportedlock' );
866 #for my $n (qw(exclusive shared)) { # shared is currently not supported.
867 16 for my $n (qw(exclusive)) {
868 16 my $lock = _dav_child( $prop, 'lockentry' );
869  
870 16 _dav_child( _dav_child( $lock, 'lockscope' ), $n );
871 16 _dav_child( _dav_child( $lock, 'locktype' ), 'write' );
872 }
873  
874 16 return $prop;
875 }
876  
877 14 1;
878  
879 __END__
↑ Summary blib/lib/Net/DAV/Lock.pm »