| 1 | |||
| 2 | |||
| 3 | package HTTP::DAVServer::COPY; | ||
| 4 | |||
| 5 | our $VERSION=0.1; | ||
| 6 | |||
| 7 | use strict; | ||
| 8 | use warnings; | ||
| 9 | |||
| 10 | use File::Copy qw(copy); | ||
| 11 | |||
| 12 | =head1 NAME | ||
| 13 | |||
| 14 | HTTP::DAVServer::COPY - Implements the COPY method | ||
| 15 | |||
| 16 | =cut | ||
| 17 | |||
| 18 | |||
| 19 | sub handle { | ||
| 20 | |||
| 21 | my ($self, $r, $url, $responder, $request) = @_; | ||
| 22 | |||
| 23 | my $fullPath = $HTTP::DAVServer::ROOT . $url; | ||
| 24 | $url =~ m#^(.*)/([^/]+)$#; | ||
| 25 | my $path = $HTTP::DAVServer::ROOT . $1; | ||
| 26 | my $file = $2; | ||
| 27 | my $dest = $HTTP::DAVServer::ROOT . $ENV{'HTTP_DESTINATION'}; | ||
| 28 | |||
| 29 | if ( -d $fullPath ) { | ||
| 30 | $responder->multiStatus( $r, join "", copyDir( $fullPath, $url, $dest) ); | ||
| 31 | } | ||
| 32 | |||
| 33 | if ( -f $fullPath ) { | ||
| 34 | $responder->multiStatus( $r, copyFile( $fullPath, $url, $dest ) ); | ||
| 35 | } | ||
| 36 | |||
| 37 | $responder->notFound( $r ); | ||
| 38 | |||
| 39 | } | ||
| 40 | |||
| 41 | sub copyFile { | ||
| 42 | |||
| 43 | my ( $fullpath, $url, $dest ) = @_; | ||
| 44 | |||
| 45 | my $response = qq(<response>\n<href>$HTTP::DAVServer::HOST$url</href>\n); | ||
| 46 | warn "COPY $fullpath $dest\n" if $HTTP::DAVServer::TRACE; | ||
| 47 | unless (copy $fullpath, $dest) { | ||
| 48 | $response .= qq(<status>403 Forbidden</status>\n); | ||
| 49 | } | ||
| 50 | $response .= "</response>"; | ||
| 51 | |||
| 52 | return $response; | ||
| 53 | |||
| 54 | } | ||
| 55 | |||
| 56 | sub copyDir { | ||
| 57 | |||
| 58 | my ( $directory, $url, $dest ) = @_; | ||
| 59 | |||
| 60 | my @responses=(); | ||
| 61 | opendir MYDIR, $directory; | ||
| 62 | |||
| 63 | while (my $entry = readdir MYDIR) { | ||
| 64 | |||
| 65 | next if $entry =~ /^\.\.?$/; | ||
| 66 | |||
| 67 | if ( -f "$directory/$entry" ) { | ||
| 68 | push @responses, copyFile( "$directory/$entry", "$url/$entry", "$dest/$entry" ); | ||
| 69 | } else { | ||
| 70 | push @responses, copyDir( "$directory/$entry", "$url/$entry", "$dest/$entry" ); | ||
| 71 | } | ||
| 72 | |||
| 73 | } | ||
| 74 | |||
| 75 | my $response = qq(<response>\n<href>$HTTP::DAVServer::HOST$url</href>\n); | ||
| 76 | my $resp=mkdir $directory; | ||
| 77 | warn "COPY $directory\n" if $HTTP::DAVServer::TRACE; | ||
| 78 | $response .= "</response>"; | ||
| 79 | |||
| 80 | push @responses, $response; | ||
| 81 | |||
| 82 | return @responses; | ||
| 83 | |||
| 84 | } | ||
| 85 | |||
| 86 | =head1 SUPPORT | ||
| 87 | |||
| 88 | For technical support please email to jlawrenc@cpan.org ... | ||
| 89 | for faster service please include "HTTP::DAVServer" and "help" in your subject line. | ||
| 90 | |||
| 91 | =head1 AUTHOR | ||
| 92 | |||
| 93 | Jay J. Lawrence - jlawrenc@cpan.org | ||
| 94 | Infonium Inc., Canada | ||
| 95 | http://www.infonium.ca/ | ||
| 96 | |||
| 97 | =head1 COPYRIGHT | ||
| 98 | |||
| 99 | Copyright (c) 2003 Jay J. Lawrence, Infonium Inc. All rights reserved. | ||
| 100 | This program is free software; you can redistribute | ||
| 101 | it and/or modify it under the same terms as Perl itself. | ||
| 102 | |||
| 103 | The full text of the license can be found in the | ||
| 104 | LICENSE file included with this module. | ||
| 105 | |||
| 106 | =head1 ACKNOWLEDGEMENTS | ||
| 107 | |||
| 108 | Thank you to the authors of my prequisite modules. With out your help this code | ||
| 109 | would be much more difficult to write! | ||
| 110 | |||
| 111 | XML::Simple - Grant McLean | ||
| 112 | XML::SAX - Matt Sergeant | ||
| 113 | DateTime - Dave Rolsky | ||
| 114 | |||
| 115 | Also the authors of litmus, a very helpful tool indeed! | ||
| 116 | |||
| 117 | =head1 SEE ALSO | ||
| 118 | |||
| 119 | HTTP::DAV, HTTP::Webdav, http://www.webdav.org/, RFC 2518 | ||
| 120 | |||
| 121 | =cut | ||
| 122 | |||
| 123 | 1; | ||
| 124 | |||
| 125 |