]> git.sesse.net Git - pr0n/blobdiff - perl/Sesse/pr0n/WebDAV.pm
Implement support for HTTP digest authentication (RFC2617).
[pr0n] / perl / Sesse / pr0n / WebDAV.pm
index 8f30b7a0074d64052fc839c2b6190c10aaf88108..09f10e519cd1ebd312be7e6a51d84f0a58b6a008 100644 (file)
@@ -247,7 +247,7 @@ EOF
 EOF
        
                        return Apache2::Const::OK;
-               } elsif ($r->uri =~ m#^/webdav/upload/([a-zA-Z0-9-]+)/([a-zA-Z0-9._-]+)$#) {
+               } elsif ($r->uri =~ m#^/webdav/upload/([a-zA-Z0-9-]+)/([a-zA-Z0-9._()-]+)$#) {
                        # stat a single file
                        my ($event, $filename) = ($1, $2);
                        my ($fname, $size, $mtime);
@@ -423,11 +423,11 @@ EOF
                # gnome-vfs and mac os x love to make zero-byte files,
                # make them happy
                # 
-               if ($r->headers_in->{'content-length'} == 0) {
+               if ($r->headers_in->{'content-length'} == 0 || $filename =~ /^\.(_|DS_Store)/) {
                        $dbh->do('DELETE FROM fake_files WHERE expires_at <= now() OR (event=? AND vhost=? AND filename=?);',
                                undef, $event, $r->get_server_name, $filename)
                                or dberror($r, "Couldn't prune fake_files");
-                       $dbh->do('INSERT INTO fake_files (vhost,event,filename,expires_at) VALUES (?,?,?,now() + interval \'30 seconds\');',
+                       $dbh->do('INSERT INTO fake_files (vhost,event,filename,expires_at) VALUES (?,?,?,now() + interval \'1 day\');',
                                undef, $r->get_server_name, $event, $filename)
                                or dberror($r, "Couldn't add file");
                        $r->content_type('text/plain; charset="utf-8"');
@@ -468,8 +468,9 @@ EOF
                                        
                                $dbh->do('INSERT INTO images (id,vhost,event,uploadedby,takenby,filename) VALUES (?,?,?,?,?,?)',
                                        undef, $newid, $r->get_server_name, $event, $user, $takenby, $filename);
-                               $dbh->do('UPDATE events SET last_update=CURRENT_TIMESTAMP WHERE vhost=? AND event=?',
+                               $dbh->do('UPDATE last_picture_cache SET last_update=CURRENT_TIMESTAMP WHERE vhost=? AND event=?',
                                        undef, $r->get_server_name, $event);
+                               Sesse::pr0n::Common::purge_cache($r, "/$event/");
 
                                # Now save the file to disk
                                $fname = Sesse::pr0n::Common::get_disk_location($r, $newid);
@@ -490,8 +491,10 @@ EOF
 
                                # Make cache while we're at it.
                                # Don't do it for the resource forks Mac OS X loves to upload :-(
-                               if ($filename !~ /^\._/) {
-                                       Sesse::pr0n::Common::ensure_cached($r, $filename, $newid, -1, -1, 1, 80, 64, 320, 256, -1, -1);
+                               if ($filename !~ /^\.(_|DS_Store)/) {
+                                       # FIXME: Ideally we'd want to ensure cache of -1x-1 here as well (for NEFs), but that would
+                                       # preclude mipmapping in its current form.
+                                       Sesse::pr0n::Common::ensure_cached($r, $filename, $newid, undef, undef, "nobox", 80, 64, 320, 256);
                                }
                                
                                # OK, we got this far, commit
@@ -507,12 +510,12 @@ EOF
                        }
                }
 
-               # Insert a `shadow file' we can stat the next 30 secs
+               # Insert a `shadow file' we can stat the next day or so
                if (defined($autorename) && $autorename eq "autorename/") {
                        $dbh->do('DELETE FROM shadow_files WHERE expires_at <= now() OR (vhost=? AND event=? AND filename=?);',
                                undef, $r->get_server_name, $event, $filename)
                                or dberror($r, "Couldn't prune shadow_files");
-                       $dbh->do('INSERT INTO shadow_files (vhost,event,filename,id,expires_at) VALUES (?,?,?,?,now() + interval \'30 seconds\');',
+                       $dbh->do('INSERT INTO shadow_files (vhost,event,filename,id,expires_at) VALUES (?,?,?,?,now() + interval \'1 day\');',
                                undef, $r->get_server_name, $event, $orig_filename, $newid)
                                or dberror($r, "Couldn't add shadow file");
                        $r->log->info("Added shadow entry for $event/$filename");
@@ -602,9 +605,9 @@ EOF
 
                        # Try to insert this new file
                        eval {
-                               $dbh->do('INSERT INTO images (id,vhost,event,uploadedby,takenby,filename) VALUES (?,?,?,?,?);',
+                               $dbh->do('INSERT INTO images (id,vhost,event,uploadedby,takenby,filename) VALUES (?,?,?,?,?,?)',
                                        undef, $newid, $r->get_server_name, $event, $user, $takenby, $filename);
-                               $dbh->do('UPDATE events SET last_update=CURRENT_TIMESTAMP WHERE vhost=? AND event=?',
+                               $dbh->do('UPDATE last_picture_cache SET last_update=CURRENT_TIMESTAMP WHERE vhost=? AND event=?',
                                        undef, $r->get_server_name, $event);
 
                                # Now save the file to disk
@@ -622,7 +625,7 @@ EOF
                                        or die "/usr/bin/exifautotran: $!";
 
                                # Make cache while we're at it.
-                               Sesse::pr0n::Common::ensure_cached($r, $filename, $newid, -1, -1, 1, 80, 64, 320, 256, -1, -1);
+                               Sesse::pr0n::Common::ensure_cached($r, $filename, $newid, undef, undef, 1, 80, 64, 320, 256, -1, -1);
                                
                                # OK, we got this far, commit
                                $dbh->commit;
@@ -658,7 +661,8 @@ EOF
                }
 
                my ($event, $autorename, $filename) = ($1, $2, $3);
-               my $sha1 = Digest::SHA1::sha1_base64("/$event/$autorename/$filename");
+               $autorename = '' if (!defined($autorename));
+               my $sha1 = Digest::SHA1::sha1_base64("/$event/$autorename$filename");
 
                $r->status(200);
                $r->content_type('text/xml; charset=utf-8');
@@ -705,7 +709,7 @@ EOF
                $dbh->do('DELETE FROM images WHERE vhost=? AND event=? AND filename=?',
                        undef, $r->get_server_name, $event, $filename)
                        or dberror($r, "Couldn't remove file");
-               $dbh->do('UPDATE events SET last_update=CURRENT_TIMESTAMP WHERE vhost=? AND event=?',
+               $dbh->do('UPDATE last_picture_cache SET last_update=CURRENT_TIMESTAMP WHERE vhost=? AND event=?',
                        undef, $r->get_server_name, $event)
                        or dberror($r, "Couldn't invalidate cache");
                $r->status(200);