Origin: 7debf8b5eda2ad917af8ccb06f987a1ce8cb14cd Mon Sep 17 00:00:00 2001
From: Don Armstrong <don@donarmstrong.com>
Last-Update: 2017-11-02
Bug-Debian: https://bugs.debian.org/770687
Subject: add updates for -4

git-svn-id: file:///srv/don_svn/deb_pkgs/libapache-gallery-perl/trunk@727 8f7917da-ec0b-0410-a553-b9b0e350d17e
---
 debian/changelog      |  7 +++++
 lib/Apache/Gallery.pm | 72 ++++++++++++++++++++++---------------------
 t/004_cache_dir.t     |  8 ++---
 3 files changed, 48 insertions(+), 39 deletions(-)

diff --git a/lib/Apache/Gallery.pm b/lib/Apache/Gallery.pm
index 10b4381..b4575be 100644
--- a/lib/Apache/Gallery.pm
+++ b/lib/Apache/Gallery.pm
@@ -121,10 +121,11 @@ sub handler {
 	# Let Apache serve icons without us modifying the request
 	if ($r->uri =~ m/^\/icons/i) {
 	    if ($r->uri =~ m/^\/icons\/gallery\/([^\/]+$)/i) {
-		$filename = "/usr/share/libapache-gallery-perl/icons/$filename";
-		$r->filename($filename);
-	    }
-	    return $::MP2 ? Apache2::Const::DECLINED() : Apache::Constants::DECLINED();
+            $filename = "/usr/share/libapache-gallery-perl/icons/$1";
+            return send_file($r,$filename);
+	    } else {
+            return $::MP2 ? Apache2::Const::DECLINED() : Apache::Constants::DECLINED();
+        }
 	}
 	# Lookup the file in the cache and scale the image if the cached
 	# image does not exist
@@ -148,32 +149,8 @@ sub handler {
 		my $file = cache_dir($r, 0);
 		$file =~ s/\.cache//;
 
-		my $subr = $r->lookup_file($file);
-		$r->content_type($subr->content_type());
+        return send_file($r,$file);
 
-		if ($::MP2) {
-			my $fileinfo = stat($file);
-
-			my $nonce = md5_base64($fileinfo->ino.$fileinfo->mtime);
-			if ($r->headers_in->{"If-None-Match"} eq $nonce) {
-				return Apache2::Const::HTTP_NOT_MODIFIED();
-			}
-
-			if ($r->headers_in->{"If-Modified-Since"} && str2time($r->headers_in->{"If-Modified-Since"}) < $fileinfo->mtime) {
-				return Apache2::Const::HTTP_NOT_MODIFIED();
-			}
-
-			$r->headers_out->{"Content-Length"} = $fileinfo->size; 
-			$r->headers_out->{"Last-Modified-Date"} = time2str($fileinfo->mtime); 
-			$r->headers_out->{"ETag"} = $nonce;
-			$r->sendfile($file);
-			return Apache2::Const::OK();
-		}
-		else {
-			$r->path_info('');
-			$r->filename($file);
-			return Apache::Constants::DECLINED();
-		}
 		
 	}
 
@@ -189,8 +166,7 @@ sub handler {
 	unless ($doc_pattern) {
 		$doc_pattern = '\.(mpe?g|avi|mov|asf|wmv|doc|mp3|mp4|ogg|pdf|rtf|wav|dlt|txt|html?|csv|eps)$'
 	}
-	my $img_pattern = $r->dir_config('GalleryImgFile');
-	unless ($img_pattern) {
+	my $img_pattern = $r->dir_config('GalleryImgFile')	unless ($img_pattern) {
 		$img_pattern = '\.(jpe?g|png|tiff?|ppm)$'
 	}
 
@@ -852,6 +828,35 @@ sub handler {
 
 }
 
+sub send_file {
+    my ($r,$file) = @_;
+    my $subr = $r->lookup_file($file);
+    $r->content_type($subr->content_type());
+    if ($::MP2) {
+        my $fileinfo = stat($file);
+
+        my $nonce = md5_base64($fileinfo->ino.$fileinfo->mtime);
+        if ($r->headers_in->{"If-None-Match"} eq $nonce) {
+            return Apache2::Const::HTTP_NOT_MODIFIED();
+        }
+
+        if ($r->headers_in->{"If-Modified-Since"} && str2time($r->headers_in->{"If-Modified-Since"}) < $fileinfo->mtime) {
+            return Apache2::Const::HTTP_NOT_MODIFIED();
+        }
+
+        $r->headers_out->{"Content-Length"} = $fileinfo->size; 
+        $r->headers_out->{"Last-Modified-Date"} = time2str($fileinfo->mtime); 
+        $r->headers_out->{"ETag"} = $nonce;
+        $r->sendfile($file);
+        return Apache2::Const::OK();
+    }
+    else {
+        $r->path_info('');
+        $r->filename($file);
+        return Apache::Constants::DECLINED();
+    }
+}
+
 sub cache_dir {
 
 	my ($r, $strip_filename) = @_;
@@ -1833,10 +1838,7 @@ Pattern matching the files you want Apache::Gallery to view in the index
 as normal files. All other filetypes will still be served by Apache::Gallery
 but are not visible in the index.
 
-The default is
-
-     '\.(mpe?g|avi|mov|asf|wmv|doc|mp3|mp4
-      |ogg|pdf|rtf|wav|dlt|txt|html?|csv|eps)$'
+The default is '\.(mpe?g|avi|mov|asf|wmv|doc|mp3|mp4|ogg|pdf|rtf|wav|dlt|txt|html?|csv|eps)$'
 
 =item B<GalleryTTFDir>
 
diff --git a/t/004_cache_dir.t b/t/004_cache_dir.t
index 4998b3c..d3dfa3b 100644
--- a/t/004_cache_dir.t
+++ b/t/004_cache_dir.t
@@ -42,12 +42,12 @@ sub request {
 }
 
 my $r=request(undef, 1);
-is(Apache::Gallery::cache_dir($r, 1), '/var/tmp/Apache-Gallery/hostname/uripath1/uripath2');
-is(Apache::Gallery::cache_dir($r, 0), '/var/tmp/Apache-Gallery/hostname/uripath1/uripath2/urifile');
+is(Apache::Gallery::cache_dir($r, 1), '/var/cache/www/hostname/uripath1/uripath2');
+is(Apache::Gallery::cache_dir($r, 0), '/var/cache/www/hostname/uripath1/uripath2/urifile');
 
 $r=request(undef, 0);
-is(Apache::Gallery::cache_dir($r, 1), '/var/tmp/Apache-Gallery/location/uripath1/uripath2');
-is(Apache::Gallery::cache_dir($r, 0), '/var/tmp/Apache-Gallery/location/uripath1/uripath2/urifile');
+is(Apache::Gallery::cache_dir($r, 1), '/var/cache/www/location/uripath1/uripath2');
+is(Apache::Gallery::cache_dir($r, 0), '/var/cache/www/location/uripath1/uripath2/urifile');
 
 $r=request('t/cachetest', 1);
 is(Apache::Gallery::cache_dir($r, 1), 't/cachetest/uripath1/uripath2');
