]> git.deb.at Git - deb/packages.git/blob - lib/Packages/DoIndex.pm
Some fixes for Polish translation.
[deb/packages.git] / lib / Packages / DoIndex.pm
1 package Packages::DoIndex;
2
3 use strict;
4 use warnings;
5
6 use CGI qw( :cgi );
7 use POSIX qw( strftime );
8 use Exporter;
9
10 use Deb::Versions;
11 use Packages::Config qw( $TOPDIR );
12 use Packages::CGI;
13
14 our @ISA = qw( Exporter );
15 our @EXPORT = qw( do_homepage do_index do_allpackages );
16
17 sub do_homepage {
18     $_[1]->{suite} = [];
19     return send_file( 'index', @_ );
20 }
21
22 sub do_index {
23     return send_file( 'index', @_ );
24 }
25 sub do_allpackages {
26     return send_file( 'allpackages', @_ );
27 }
28
29 my %encoding = (
30                 'txt.gz' => 'x-gzip',
31                 );
32 sub send_file {
33     my ($file, $params, $opts) = @_;
34     my $cat = $opts->{cat};
35
36     if ($params->{errors}{suite}) {
37         fatal_error( $cat->g( "suite not valid or not specified" ) );
38     }
39     if (@{$opts->{suite}} > 1) {
40         fatal_error( $cat->g( "more than one suite specified for show_static (%s)",
41                               "@{$opts->{suite}}" ) );
42     }
43     if (@{$opts->{subsection}} > 1) {
44         fatal_error( $cat->g( "more than one subsection specified for show_static (%s)",
45                               "@{$opts->{suite}}" ) );
46     }
47
48     if ($opts->{format} eq 'txt.gz') {
49         $opts->{po_lang} = 'en';
50     }
51     my $wwwdir = "$TOPDIR/www";
52     my $path = "";
53     $path .= "source/" if $opts->{source};
54     $path .= "$opts->{suite}[0]/" if @{$opts->{suite}};
55     $path .= "$opts->{archive}[0]/" if @{$opts->{archive}} == 1;
56     $path .= "$opts->{subsection}[0]/" if @{$opts->{subsection}};
57     $path .= "$opts->{priority}[0]/" if @{$opts->{priority}};
58     $path .= "$file.$opts->{po_lang}.$opts->{format}";
59
60     unless (@Packages::CGI::fatal_errors) {
61         my $buffer;
62         if (open( INDEX, '<', "$wwwdir/$path" )) {
63             my %headers;
64             $headers{'-charset'} = 'UTF-8';
65             $headers{'-type'} = get_mime( $opts->{format}, 'text/plain' );
66             $headers{'-content-encoding'} = $encoding{$opts->{format}} if exists $encoding{$opts->{format}};
67             my ($size,$mtime) = (stat("$wwwdir/$path"))[7,9];
68             $headers{'-content-length'} = $size;
69             $headers{'-vary'} = 'negotiate,accept-language';
70             $headers{'-last-modified'} = strftime("%a, %d %b %Y %T %z", localtime($mtime));
71             $headers{'-expires'} = strftime("%a, %d %b %Y %T %z", localtime($mtime+(12*3600)));
72             print header( %headers );
73
74             binmode INDEX;
75             while (read INDEX, $buffer, 4096) {
76                 print $buffer;
77             }
78             close INDEX;
79             exit;
80         } else {
81             fatal_error( $cat->g( "couldn't read index file %s: %s",
82                                   $path, $! ) );
83         }
84     }
85 }
86
87 1;
88