]> git.deb.at Git - deb/packages.git/blob - lib/Packages/DoIndex.pm
Separate handling of po translations and DDTP translations
[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 Exporter;
8
9 use Deb::Versions;
10 use Packages::Config qw( $TOPDIR );
11 use Packages::CGI;
12
13 our @ISA = qw( Exporter );
14 our @EXPORT = qw( do_index do_allpackages );
15
16 sub do_index {
17     return send_file( 'index', @_ );
18 }
19 sub do_allpackages {
20     return send_file( 'allpackages', @_ );
21 }
22
23 my %encoding = (
24                 'txt.gz' => 'x-gzip',
25                 );
26 sub send_file {
27     my ($file, $params, $opts) = @_;
28     my $cat = $opts->{cat};
29
30     if ($params->{errors}{suite}) {
31         fatal_error( $cat->g( "suite not valid or not specified" ) );
32     }
33     if (@{$opts->{suite}} > 1) {
34         fatal_error( $cat->g( "more than one suite specified for show_static (%s)",
35                               "@{$opts->{suite}}" ) );
36     }
37     if (@{$opts->{subsection}} > 1) {
38         fatal_error( $cat->g( "more than one subsection specified for show_static (%s)",
39                               "@{$opts->{suite}}" ) );
40     }
41
42     my $wwwdir = "$TOPDIR/www";
43     my $path = "";
44     $path .= "source/" if $opts->{source};
45     $path .= "$opts->{suite}[0]/";
46     $path .= "$opts->{archive}[0]/" if @{$opts->{archive}} == 1;
47     $path .= "$opts->{subsection}[0]/" if @{$opts->{subsection}};
48     $path .= "$opts->{priority}[0]/" if @{$opts->{priority}};
49     $path .= "$file.$opts->{po_lang}.$opts->{format}";
50
51     unless (@Packages::CGI::fatal_errors) {
52         my $buffer;
53         if (open( INDEX, '<', "$wwwdir/$path" )) {
54             my %headers;
55             $headers{'-charset'} = 'UTF-8';
56             $headers{'-type'} = get_mime( $opts->{format}, 'text/plain' );
57             $headers{'-content-encoding'} = $encoding{$opts->{format}} if exists $encoding{$opts->{format}};
58             my ($size,$mtime) = (stat("$wwwdir/$path"))[7,9];
59             $headers{'-content-length'} = $size;
60             $headers{'-last-modified'} = gmtime($mtime);
61             print header( %headers );
62
63             binmode INDEX;
64             while (read INDEX, $buffer, 4096) {
65                 print $buffer;
66             }
67             close INDEX;
68             exit;
69         } else {
70             fatal_error( $cat->g( "couldn't read index file %s: %s",
71                                   $path, $! ) );
72         }
73     }
74 }
75
76 1;
77