use Digest::MD5 qw(md5_hex);
use LWP::UserAgent;
use File::Temp qw(tempfile);
+use File::LibMagic;
+use Cwd qw(abs_path);
use Carp;
$DEBUG = 0 unless defined $DEBUG;
@EXPORT = ();
- %EXPORT_TAGS = (libravatar => [qw(cache_valid serve_cache retrieve_libravatar cache_location)]
+ %EXPORT_TAGS = (libravatar => [qw(cache_valid retrieve_libravatar cache_location)]
);
@EXPORT_OK = ();
Exporter::export_ok_tags(keys %EXPORT_TAGS);
);
my %param = @_;
my $cache_location = $param{location};
- $cache_location =~ s/\.[^\.]+$//;
+ $cache_location =~ s/\.[^\.\/]+$//;
# take out a lock on the cache location so that if another request
# is made while we are serving this one, we don't do double work
my ($fh,$lockfile,$errors) =
$temp_fn,
$cache_location.'.'.$dest_type) == 0 or
die "convert file failed";
- unlink($temp_fh);
+ unlink($temp_fn);
};
if ($@) {
unlink($cache_location.'.'.$dest_type) if -e $cache_location.'.'.$dest_type;
my $location = $r->location();
my ($email) = $uri =~ m/\Q$location\E\/?(.*)$/;
if (not length $email) {
- return Apache2::Const::NOT_FOUND;
+ return Apache2::Const::NOT_FOUND();
}
my $q = CGI::Simple->new();
my %param = cgi_parameters(query => $q,
serve_cache_mod_perl($cache_location,$r);
return Apache2::Const::DECLINED();
}
- $cache_location = retreive_libravatar(location => $cache_location,
+ $cache_location = retrieve_libravatar(location => $cache_location,
email => $email,
);
if (not defined $cache_location) {
}
+
+our $magic;
+
sub serve_cache_mod_perl {
my ($cache_location,$r) = @_;
if (not defined $cache_location or not length $cache_location) {
# serve the default image
$cache_location = $config{libravatar_default_image};
}
+ $magic = File::LibMagic->new() if not defined $magic;
+
+ return Apache2::Const::DECLINED() if not defined $magic;
+
+ $r->content_type($magic->checktype_filename(abs_path($cache_location)));
+
$r->filename($cache_location);
$r->path_info('');
- $r->finfo(APR::Finfo::stat($cache_location, APR::Const::FINFO_NORM, $r->pool));
+ $r->finfo(APR::Finfo::stat($cache_location, APR::Const::FINFO_NORM(), $r->pool));
}
=back