#!/usr/bin/perl -wT

#---libsetup---

# having . in @INC can cause tainting issues for use

no lib '.';

use FindBin;
BEGIN {
  ($dir)=($FindBin::Bin=~/^([\w\d\-\/\.]+)$/)
    or die "invalid current directory $FindBin::Bin";
}
use lib $dir;

#---endlibsetup---

use strict;

use PhotoPub::Global qw(&init &finit $error);
use PhotoPub::CGIBase qw($query &printheader);
use PhotoPub::Config;

use PhotoPub::Display qw(&display);

use Fcntl ':flock';

&init();

my $outputfile=&display(scalar $query->Vars);

open PIC,"<$outputfile" 
  or &$error(type => 'config', 
	     message => "couldn't open $outputfile for reading");
flock PIC,LOCK_SH;

# make expiry configurable on a per-path basis or something
&printheader(-type => 'image/jpeg'); 
if($ENV{'GATEWAY_INTERFACE'} =~ /^CGI-Perl\//) {
  Apache->request->send_fd(\*PIC);
} else {
  local $/;
  print <PIC>;
}
flock PIC,LOCK_UN;
close PIC;

&finit();

