4 use Fcntl qw/O_RDONLY/;
11 $config_path = '/etc/debbugs';
12 $lib_path = '/usr/lib/debbugs';
13 require "$lib_path/errorlib";
15 use Debbugs::Versions;
16 use Debbugs::MIME qw(decode_rfc1522);
18 $MLDBM::RemoveTaint = 1;
20 my $common_archive = 0;
21 my $common_repeatmerged = 1;
22 my %common_include = ();
23 my %common_exclude = ();
24 my $common_raw_sort = 0;
25 my $common_bug_reverse = 0;
27 my %common_reverse = (
32 'show_list_header' => 1,
33 'show_list_footer' => 1,
36 sub exact_field_match {
37 my ($field, $values, $status) = @_;
38 my @values = @$values;
39 my @ret = grep {$_ eq $status->{$field} } @values;
42 sub contains_field_match {
43 my ($field, $values, $status) = @_;
44 foreach my $data (@$values) {
45 return 1 if (index($status->{$field}, $data) > -1);
50 sub detect_user_agent {
51 my $userAgent = $ENV{HTTP_USER_AGENT};
52 return { 'name' => 'unknown' } unless defined $userAgent;
53 return { 'name' => 'links' } if ( $userAgent =~ m,^ELinks,);
54 return { 'name' => 'lynx' } if ( $userAgent =~ m,^Lynx,);
55 return { 'name' => 'wget' } if ( $userAgent =~ m,^Wget,);
56 return { 'name' => 'gecko' } if ( $userAgent =~ m,^Mozilla.* Gecko/,);
57 return { 'name' => 'ie' } if ( $userAgent =~ m,^.*MSIE.*,);
58 return { 'name' => 'unknown' };
62 'subject' => \&contains_field_match,
64 my ($field, $values, $status) = @_;
65 my %values = map {$_=>1} @$values;
66 foreach my $t (split /\s+/, $status->{$field}) {
67 return 1 if (defined $values{$t});
71 'severity' => \&exact_field_match,
72 'pending' => \&exact_field_match,
73 'originator' => \%contains_field_match,
74 'forwarded' => \%contains_field_match,
75 'owner' => \%contains_field_match,
77 my @common_grouping = ( 'severity', 'pending' );
78 my %common_grouping_order = (
79 'pending' => [ qw( pending forwarded pending-fixed fixed done absent ) ],
80 'severity' => \@debbugs::gSeverityList,
82 my %common_grouping_display = (
83 'pending' => 'Status',
84 'severity' => 'Severity',
86 my %common_headers = (
88 "pending" => "outstanding",
89 "pending-fixed" => "pending upload",
90 "fixed" => "fixed in NMU",
92 "forwarded" => "forwarded to upstream software authors",
93 "absent" => "not applicable to this version",
95 'severity' => \%debbugs::gSeverityDisplay,
104 sub array_option($) {
107 @vals = ( $val ) if (ref($val) eq "" && $val );
108 @vals = ( $$val ) if (ref($val) eq "SCALAR" && $$val );
109 @vals = @{$val} if (ref($val) eq "ARRAY" );
113 sub filter_include_exclude($\%) {
114 my ($val, $filter_map) = @_;
115 my @vals = array_option($val);
117 if (/^([^:]*):(.*)$/) { if ($1 eq 'subj') { ['subject', $2]; } else { [$1, $2] } } else { ['tags', $_] }
118 } split /[\s,]+/, join ',', @vals;
119 foreach my $data (@data) {
120 &quitcgi("Invalid filter key: '$data->[0]'") if (!exists($field_match{$data->[0]}));
121 push @{$filter_map->{$data->[0]}}, $data->[1];
125 sub filter_option($$\%) {
126 my ($key, $val, $filter_map) = @_;
127 my @vals = array_option($val);
128 foreach $val (@vals) {
129 push @{$filter_map->{$key}}, $val;
134 my ($opt, $val) = @_;
135 if ($opt =~ m/^show_list_(foot|head)er$/) { $common{$opt} = $val; }
136 if ($opt eq "archive") { $common_archive = $val; }
137 if ($opt eq "repeatmerged") { $common_repeatmerged = $val; }
138 if ($opt eq "exclude") {
139 filter_include_exclude($val, %common_exclude);
141 if ($opt eq "include") {
142 filter_include_exclude($val, %common_include);
144 if ($opt eq "raw") { $common_raw_sort = $val; }
145 if ($opt eq "bug-rev") { $common_bug_reverse = $val; }
146 if ($opt eq "pend-rev") { $common_reverse{pending} = $val; }
147 if ($opt eq "sev-rev") { $common_reverse{severity} = $val; }
148 if ($opt eq "pend-exc") {
149 filter_option('pending', $val, %common_exclude);
151 if ($opt eq "pend-inc") {
152 filter_option('pending', $val, %common_include);
154 if ($opt eq "sev-exc") {
155 filter_option('severity', $val, %common_exclude);
157 if ($opt eq "sev-inc") {
158 filter_option('severity', $val, %common_include);
160 if ($opt eq "version") { $common_version = $val; }
161 if ($opt eq "dist") { $common_dist = $val; }
162 if ($opt eq "arch") { $common_arch = $val; }
166 my ($in, $key, $val, %ret);
167 if (defined $ENV{"QUERY_STRING"} && $ENV{"QUERY_STRING"} ne "") {
168 $in=$ENV{QUERY_STRING};
169 } elsif(defined $ENV{"REQUEST_METHOD"}
170 && $ENV{"REQUEST_METHOD"} eq "POST")
172 read(STDIN,$in,$ENV{CONTENT_LENGTH});
176 foreach (split(/[&;]/,$in)) {
178 ($key, $val) = split(/=/,$_,2);
179 $key=~s/%(..)/pack("c",hex($1))/ge;
180 $val=~s/%(..)/pack("c",hex($1))/ge;
181 if ( exists $ret{$key} ) {
182 if ( !exists $ret{"&$key"} ) {
183 $ret{"&$key"} = [ $ret{$key} ];
185 push @{$ret{"&$key"}},$val;
189 $debug = 1 if (defined $ret{"debug"} && $ret{"debug"} eq "aj");
195 print "Content-Type: text/html\n\n";
196 print "<HTML><HEAD><TITLE>Error</TITLE></HEAD><BODY>\n";
197 print "An error occurred. Dammit.\n";
198 print "Error was: $msg.\n";
199 print "</BODY></HTML>\n";
205 # my $Archive = $common_archive ? "archive" : "";
206 # print header . start_html("Sorry");
207 # print "Sorry bug #$msg doesn't seem to be in the $Archive database.\n";
212 # Split a package string from the status file into a list of package names.
215 return unless defined $pkgs;
216 return map lc, split /[ \t?,()]+/, $pkgs;
222 return () unless defined $addr;
223 return @{$_parsedaddrs{$addr}} if exists $_parsedaddrs{$addr};
224 @{$_parsedaddrs{$addr}} = Mail::Address->parse($addr);
225 return @{$_parsedaddrs{$addr}};
228 # Generate a comma-separated list of HTML links to each package given in
229 # $pkgs. $pkgs may be empty, in which case an empty string is returned, or
230 # it may be a comma-separated list of package names.
231 sub htmlpackagelinks {
233 return unless defined $pkgs and $pkgs ne '';
235 my @pkglist = splitpackages($pkgs);
237 my $openstrong = $strong ? '<strong>' : '';
238 my $closestrong = $strong ? '</strong>' : '';
240 return 'Package' . (@pkglist > 1 ? 's' : '') . ': ' .
243 '<a href="' . pkgurl($_) . '">' .
244 $openstrong . htmlsanit($_) . $closestrong . '</a>'
249 # Generate a comma-separated list of HTML links to each address given in
250 # $addresses, which should be a comma-separated list of RFC822 addresses.
251 # $urlfunc should be a reference to a function like mainturl or submitterurl
252 # which returns the URL for each individual address.
253 sub htmladdresslinks {
254 my ($prefixfunc, $urlfunc, $addresses) = @_;
255 if (defined $addresses and $addresses ne '') {
256 my @addrs = getparsedaddrs($addresses);
257 my $prefix = (ref $prefixfunc) ? $prefixfunc->(scalar @addrs)
260 join ', ', map { sprintf '<a href="%s">%s</a>',
261 $urlfunc->($_->address),
262 htmlsanit($_->format) || '(unknown)'
265 my $prefix = (ref $prefixfunc) ? $prefixfunc->(1) : $prefixfunc;
266 return sprintf '%s<a href="%s">(unknown)</a>', $prefix, $urlfunc->('');
270 # Generate a comma-separated list of HTML links to each maintainer given in
271 # $maints, which should be a comma-separated list of RFC822 addresses.
273 my ($prefixfunc, $maints) = @_;
274 return htmladdresslinks($prefixfunc, \&mainturl, $maints);
279 my %status = %{getbugstatus($ref)};
280 return htmlindexentrystatus(%status) if (%status);
284 sub htmlindexentrystatus {
290 if ($status{severity} eq 'normal') {
292 } elsif (isstrongseverity($status{severity})) {
293 $showseverity = "<strong>Severity: $status{severity}</strong>;\n";
295 $showseverity = "Severity: <em>$status{severity}</em>;\n";
298 $result .= htmlpackagelinks($status{"package"}, 1);
300 my $showversions = '';
301 if (@{$status{found_versions}}) {
302 my @found = @{$status{found_versions}};
304 s{/}{ } foreach @found;
305 $showversions .= join ', ', map htmlsanit($_), @found;
307 if (@{$status{fixed_versions}}) {
308 $showversions .= '; ' if length $showversions;
309 $showversions .= '<strong>fixed</strong>: ';
310 my @fixed = @{$status{fixed_versions}};
312 s{/}{ } foreach @fixed;
313 $showversions .= join ', ', map htmlsanit($_), @fixed;
315 $result .= " ($showversions)" if length $showversions;
318 $result .= $showseverity;
319 $result .= htmladdresslinks("Reported by: ", \&submitterurl,
320 $status{originator});
321 $result .= ";\nOwned by: " . htmlsanit($status{owner})
322 if length $status{owner};
323 $result .= ";\nTags: <strong>"
324 . htmlsanit(join(", ", sort(split(/\s+/, $status{tags}))))
326 if (length($status{tags}));
328 my @merged= split(/ /,$status{mergedwith});
329 my $mseparator= ";\nmerged with ";
330 for my $m (@merged) {
331 $result .= $mseparator."<A href=\"" . bugurl($m) . "\">#$m</A>";
335 if (length($status{done})) {
336 $result .= ";\n<strong>Done:</strong> " . htmlsanit($status{done});
337 $days = ceil($debbugs::gRemoveAge - -M buglog($status{id}));
339 $result .= ";\n<strong>Will be archived:</strong>" . ( $days == 0 ? " today" : $days == 1 ? " in $days day" : " in $days days" );
341 $result .= ";\n<strong>Archived</strong>";
345 unless (length($status{done})) {
346 if (length($status{forwarded})) {
347 $result .= ";\n<strong>Forwarded</strong> to "
348 . maybelink($status{forwarded});
350 my $daysold = int((time - $status{date}) / 86400); # seconds to days
354 $font = "em" if ($daysold > 30);
355 $font = "strong" if ($daysold > 60);
356 $efont = "</$font>" if ($font);
357 $font = "<$font>" if ($font);
359 my $yearsold = int($daysold / 365);
360 $daysold -= $yearsold * 365;
362 $result .= ";\n $font";
364 push @age, "1 year" if ($yearsold == 1);
365 push @age, "$yearsold years" if ($yearsold > 1);
366 push @age, "1 day" if ($daysold == 1);
367 push @age, "$daysold days" if ($daysold > 1);
368 $result .= join(" and ", @age);
369 $result .= " old$efont";
380 $args .= "&archive=yes" if $common_archive;
381 $args .= "&repeatmerged=no" unless $common_repeatmerged;
382 $args .= "&version=$common_version" if defined $common_version;
383 $args .= "&dist=$common_dist" if defined $common_dist;
384 $args .= "&arch=$common_arch" if defined $common_arch;
389 my $ref = shift || "";
390 my $params = "submitter=" . emailfromrfc822($ref);
391 $params .= urlargs();
392 return urlsanit("pkgreport.cgi" . "?" . $params);
396 my $ref = shift || "";
397 my $params = "maint=" . emailfromrfc822($ref);
398 $params .= urlargs();
399 return urlsanit("pkgreport.cgi" . "?" . $params);
404 my $params = "pkg=$ref";
405 $params .= urlargs();
406 return urlsanit("pkgreport.cgi" . "?" . "$params");
411 my $params = "src=$ref";
412 $params .= urlargs();
413 return urlsanit("pkgreport.cgi" . "?" . "$params");
418 my $params = "tag=$ref";
419 $params .= urlargs();
420 return urlsanit("pkgreport.cgi" . "?" . "$params");
428 my %saniarray = ('<','lt', '>','gt', '&','amp', '"','quot');
429 $url =~ s/([<>&"])/\&$saniarray{$1};/g;
434 my %saniarray = ('<','lt', '>','gt', '&','amp', '"','quot');
435 my $in = shift || "";
436 $in =~ s/([<>&"])/\&$saniarray{$1};/g;
442 if ($in =~ /^[a-zA-Z0-9+.-]+:/) { # RFC 1738 scheme
443 return qq{<a href="$in">} . htmlsanit($in) . '</a>';
445 return htmlsanit($in);
451 my $params = "bug=$ref";
452 foreach my $val (@_) {
453 $params .= "\&msg=$1" if ($val =~ /^msg=([0-9]+)/);
454 $params .= "\&archive=yes" if (!$common_archive && $val =~ /^archive.*$/);
456 $params .= "&archive=yes" if ($common_archive);
457 $params .= "&repeatmerged=no" unless ($common_repeatmerged);
459 return urlsanit("bugreport.cgi" . "?" . "$params");
464 my $params = "bug=$ref";
466 foreach my $val (@_) {
467 $params .= "\&$1=$2" if ($val =~ /^(msg|att)=([0-9]+)/);
468 $filename = $1 if ($val =~ /^filename=(.*)$/);
470 $params .= "&archive=yes" if ($common_archive);
472 $pathinfo = '/'.uri_escape($filename) if $filename ne '';
474 return urlsanit("bugreport.cgi$pathinfo?$params");
479 return urlsanit("bugreport.cgi" . "?" . "bug=$ref&mbox=yes");
483 return @{getbugs(sub { 1 })};
486 sub bugmatches(\%\%) {
487 my ($hash, $status) = @_;
488 foreach my $key( keys( %$hash ) ) {
489 my $value = $hash->{$key};
490 my $sub = $field_match{$key};
491 return 1 if ($sub->($key, $value, $status));
496 my ($bug, %status) = @_;
498 if (%common_include) {
499 return 1 if (!bugmatches(%common_include, %status));
501 if (%common_exclude) {
502 return 1 if (bugmatches(%common_exclude, %status));
504 my @merged = sort {$a<=>$b} $bug, split(/ /, $status{mergedwith});
505 return 1 unless ($common_repeatmerged || !$seenmerged{$merged[0]});
506 $seenmerged{$merged[0]} = 1;
521 return "<HR><H2>No reports found!</H2></HR>\n";
524 if ( $common_bug_reverse ) {
525 @bugs = sort {$b<=>$a} @bugs;
527 @bugs = sort {$a<=>$b} @bugs;
530 foreach my $bug (@bugs) {
531 my %status = %{getbugstatus($bug)};
533 next if bugfilter($bug, %status);
535 my $html = sprintf "<li><a href=\"%s\">#%d: %s</a>\n<br>",
536 bugurl($bug), $bug, htmlsanit($status{subject});
537 $html .= htmlindexentrystatus(\%status) . "\n";
538 my $key = join( '_', map( {$status{$_}} @common_grouping ) );
539 $section{$key} .= $html;
541 foreach my $grouping ( @common_grouping ) {
542 $count{"${grouping}_$status{$grouping}"}++;
544 $anydone = 1 if $status{pending} eq 'done';
545 push @status, [ $bug, \%status, $html ];
549 if ($common_raw_sort) {
550 $result .= "<UL>\n" . join("", map( { $_->[ 2 ] } @status ) ) . "</UL>\n";
552 my (@order, @headers);
553 for( my $i = 0; $i < @common_grouping; $i++ ) {
554 my $grouping_name = $common_grouping[ $i ];
555 my @items = @{ $common_grouping_order{ $grouping_name } };
556 @items = reverse( @items ) if ( $common_reverse{ $grouping_name } );
560 foreach my $grouping ( @items ) {
561 push @neworder, map( { "${_}_$grouping" } @order );
562 push @newheaders, map( { "$_ - $common_headers{$grouping_name}{$grouping}" } @headers );
565 @headers = @newheaders;
568 push @headers, map( { $common_headers{$common_grouping[$i]}{$_} } @items );
572 for ( my $i = 0; $i < @order; $i++ ) {
573 my $order = $order[ $i ];
574 next unless defined $section{$order};
575 my $count = $count{"_$order"};
576 my $bugs = $count == 1 ? "bug" : "bugs";
577 $header .= "<li><a href=\"#$order\">$headers[$i]</a> ($count $bugs)</li>\n";
579 $header .= "</ul>\n";
580 for ( my $i = 0; $i < @order; $i++ ) {
581 my $order = $order[ $i ];
582 next unless defined $section{$order};
583 if ($common{show_list_header}) {
584 my $count = $count{"_$order"};
585 my $bugs = $count == 1 ? "bug" : "bugs";
586 $result .= "<HR><H2><a name=\"$order\"></a>$headers[$i] ($count $bugs)</H2>\n";
588 $result .= "<HR><H2>$headers[$i]</H2>\n";
591 $result .= $section{$order};
592 $result .= "</UL>\n";
595 foreach my $grouping ( @common_grouping ) {
596 my $local_result = '';
597 foreach my $key ( @{$common_grouping_order{ $grouping }} ) {
598 my $count = $count{"${grouping}_$key"};
600 $local_result .= "<li>$count $common_headers{$grouping}{$key}</li>\n";
602 if ( $local_result ) {
603 $footer .= "<li>$common_grouping_display{$grouping}<ul>\n$local_result</ul></li>\n";
606 $footer .= "</ul>\n";
609 $result = $header . $result if ( $common{show_list_header} );
610 $result .= $debbugs::gHTMLExpireNote if $gRemoveAge and $anydone;
611 $result .= "<hr>" . $footer if ( $common{show_list_footer} );
617 if ($common_archive) {
618 open I, "<$debbugs::gSpoolDir/index.archive"
619 or &quitcgi("$debbugs::gSpoolDir/index.archive: $!");
621 open I, "<$debbugs::gSpoolDir/index.db"
622 or &quitcgi("$debbugs::gSpoolDir/index.db: $!");
628 if (m/^(\S+)\s+(\d+)\s+(\d+)\s+(\S+)\s+\[\s*([^]]*)\s*\]\s+(\w+)\s+(.*)$/) {
629 my @x = $bugfunc->(pkg => $1, bug => $2, status => $4,
630 submitter => $5, severity => $6, tags => $7);
632 $count{$_}++ foreach @x;
645 if (!$common_archive && defined $opt &&
646 -e "$debbugs::gSpoolDir/by-$opt.idx")
649 print STDERR "optimized\n" if ($debug);
650 tie %lookup, DB_File => "$debbugs::gSpoolDir/by-$opt.idx", O_RDONLY
651 or die "$0: can't open $debbugs::gSpoolDir/by-$opt.idx ($!)\n";
652 while ($key = shift) {
653 my $bugs = $lookup{$key};
655 push @result, (unpack 'N*', $bugs);
659 print STDERR "done optimized\n" if ($debug);
661 if ( $common_archive ) {
662 open I, "<$debbugs::gSpoolDir/index.archive"
663 or &quitcgi("$debbugs::gSpoolDir/index.archive: $!");
665 open I, "<$debbugs::gSpoolDir/index.db"
666 or &quitcgi("$debbugs::gSpoolDir/index.db: $!");
669 if (m/^(\S+)\s+(\d+)\s+(\d+)\s+(\S+)\s+\[\s*([^]]*)\s*\]\s+(\w+)\s+(.*)$/) {
670 if ($bugfunc->(pkg => $1, bug => $2, status => $4,
671 submitter => $5, severity => $6, tags => $7))
679 @result = sort {$a <=> $b} @result;
683 sub emailfromrfc822 {
685 $email =~ s/\s*\(.*\)\s*//;
686 $email = $1 if ($email =~ m/<(.*)>/);
694 while ($input =~ m/\W/) {
695 $encoded.=$`.sprintf("-%02x_",unpack("C",$&));
700 $encoded =~ s/-2e_/\./g;
701 $encoded =~ s/^([^,]+)-20_-3c_(.*)-40_(.*)-3e_/$1,$2,$3,/;
702 $encoded =~ s/^(.*)-40_(.*)-20_-28_([^,]+)-29_$/,$1,$2,$3/;
703 $encoded =~ s/-20_/_/g;
704 $encoded =~ s/-([^_]+)_-/-$1/g;
710 return $_maintainer if $_maintainer;
713 open(MM,"$gMaintainerFile") or &quitcgi("open $gMaintainerFile: $!");
715 next unless m/^(\S+)\s+(\S.*\S)\s*$/;
721 if (defined $gMaintainerFileOverride) {
722 open(MM,"$gMaintainerFileOverride") or &quitcgi("open $gMaintainerFileOverride: $!");
724 next unless m/^(\S+)\s+(\S.*\S)\s*$/;
731 $_maintainer = \%maintainer;
738 return $_pkgsrc if $_pkgsrc;
739 return {} unless defined $gPackageSource;
743 open(MM,"$gPackageSource") or &quitcgi("open $gPackageSource: $!");
745 next unless m/^(\S+)\s+(\S+)\s+(\S.*\S)\s*$/;
746 ($a,$b,$c)=($1,$2,$3);
749 $pkgcomponent{$a}= $b;
753 $_pkgcomponent = \%pkgcomponent;
757 sub getpkgcomponent {
758 return $_pkgcomponent if $_pkgcomponent;
760 return $_pkgcomponent;
765 return $_pseudodesc if $_pseudodesc;
768 open(PSEUDO, "< $gPseudoDescFile") or &quitcgi("open $gPseudoDescFile: $!");
770 next unless m/^(\S+)\s+(\S.*\S)\s*$/;
771 $pseudodesc{lc $1} = $2;
774 $_pseudodesc = \%pseudodesc;
783 my $location = getbuglocation( $bugnum, 'summary' );
784 return {} if ( !$location );
785 %status = %{ readbug( $bugnum, $location ) };
786 $status{ id } = $bugnum;
788 $status{found_versions} = [];
789 $status{fixed_versions} = [];
790 if (defined $gVersionBugsDir and
791 (defined $common_version or defined $common_dist)) {
792 my $bughash = get_hashname($bugnum);
793 if (open BUGVER, "< $gVersionBugsDir/$bughash/$bugnum.versions") {
796 if (/^Found-in: (.*)/i) {
797 $status{found_versions} = [split ' ', $1];
798 } elsif (/^Fixed-in: (.*)/i) {
799 $status{fixed_versions} = [split ' ', $1];
806 $status{tags} = $status{keywords};
807 my %tags = map { $_ => 1 } split ' ', $status{tags};
809 $status{"package"} =~ s/\s*$//;
810 $status{"package"} = 'unknown' if ($status{"package"} eq '');
811 $status{"severity"} = 'normal' if ($status{"severity"} eq '');
813 $status{"pending"} = 'pending';
814 $status{"pending"} = 'forwarded' if (length($status{"forwarded"}));
815 $status{"pending"} = 'pending-fixed' if ($tags{pending});
816 $status{"pending"} = 'fixed' if ($tags{fixed});
819 if (defined $common_version) {
820 @versions = ($common_version);
821 } elsif (defined $common_dist) {
822 @versions = getversions($status{package}, $common_dist, $common_arch);
825 # TODO: This should probably be handled further out for efficiency and
826 # for more ease of distinguishing between pkg= and src= queries.
827 my @sourceversions = makesourceversions($status{package}, $common_arch,
830 if (@sourceversions) {
831 # Resolve bugginess states (we might be looking at multiple
832 # architectures, say). Found wins, then fixed, then absent.
833 my $maxbuggy = 'absent';
834 for my $version (@sourceversions) {
835 my $buggy = buggyversion($bugnum, $version, \%status);
836 if ($buggy eq 'found') {
839 } elsif ($buggy eq 'fixed' and $maxbuggy ne 'found') {
843 if ($maxbuggy eq 'absent') {
844 $status{"pending"} = 'absent';
845 } elsif ($maxbuggy eq 'fixed') {
846 $status{"pending"} = 'done';
850 if (length($status{done}) and
851 (not @sourceversions or not @{$status{fixed_versions}})) {
852 $status{"pending"} = 'done';
861 my %pkgsrc = %{getpkgsrc()};
863 foreach ( keys %pkgsrc ) {
864 push @pkgs, $_ if $pkgsrc{$_} eq $src;
871 my $location = getbuglocation($bugnum, 'log');
872 return getbugcomponent($bugnum, 'log', $location) if ($location);
873 $location = getbuglocation($bugnum, 'log.gz');
874 return getbugcomponent($bugnum, 'log.gz', $location);
877 # Canonicalize versions into source versions, which have an explicitly
878 # named source package. This is used to cope with source packages whose
879 # names have changed during their history, and with cases where source
880 # version numbers differ from binary version numbers.
881 sub makesourceversions {
886 for my $version (@_) {
887 if ($version =~ m[/]) {
888 # Already a source version.
889 $sourceversions{$version} = 1;
891 my @srcinfo = binarytosource($pkg, $version, $arch);
892 next unless @srcinfo;
893 $sourceversions{"$_->[0]/$_->[1]"} = 1 foreach @srcinfo;
897 return sort keys %sourceversions;
902 my ($bug, $ver, $status) = @_;
903 return '' unless defined $gVersionPackagesDir;
904 my $src = getpkgsrc()->{$status->{package}};
905 $src = $status->{package} unless defined $src;
908 if (exists $_versionobj{$src}) {
909 $tree = $_versionobj{$src};
911 $tree = Debbugs::Versions->new(\&DpkgVer::vercmp);
912 my $srchash = substr $src, 0, 1;
913 if (open VERFILE, "< $gVersionPackagesDir/$srchash/$src") {
914 $tree->load(\*VERFILE);
917 $_versionobj{$src} = $tree;
920 my @found = makesourceversions($status->{package}, undef,
921 @{$status->{found_versions}});
922 my @fixed = makesourceversions($status->{package}, undef,
923 @{$status->{fixed_versions}});
925 return $tree->buggy($ver, \@found, \@fixed);
930 my ($pkg, $dist, $arch) = @_;
931 return () unless defined $gVersionIndex;
932 $dist = 'unstable' unless defined $dist;
934 unless (tied %_versions) {
935 tie %_versions, 'MLDBM', $gVersionIndex, O_RDONLY
936 or die "can't open versions index: $!";
940 my $ver = $_versions{$pkg}{$dist}{$arch};
941 return $ver if defined $ver;
945 for my $ar (keys %{$_versions{$pkg}{$dist}}) {
946 $uniq{$_versions{$pkg}{$dist}{$ar}} = 1 unless $ar eq 'source';
955 if (defined $common_version) {
956 return "version $common_version";
957 } elsif (defined $common_dist) {
958 my @distvers = getversions($pkg, $common_dist, $common_arch);
959 @distvers = sort @distvers;
962 return "versions @distvers";
963 } elsif (@distvers == 1) {
964 return "version @distvers";
971 # Returns an array of zero or more references to (srcname, srcver) pairs.
972 # If $binarch is undef, returns results for all architectures.
975 my ($binname, $binver, $binarch) = @_;
977 # TODO: This gets hit a lot, especially from buggyversion() - probably
978 # need an extra cache for speed here.
980 if (tied %_binarytosource or
981 tie %_binarytosource, 'MLDBM', $gBinarySourceMap, O_RDONLY) {
982 # avoid autovivification
983 if (exists $_binarytosource{$binname} and
984 exists $_binarytosource{$binname}{$binver}) {
985 if (defined $binarch) {
986 my $src = $_binarytosource{$binname}{$binver}{$binarch};
987 return () unless defined $src; # not on this arch
988 # Copy the data to avoid tiedness problems.
991 # Get (srcname, srcver) pairs for all architectures and
992 # remove any duplicates. This involves some slightly tricky
993 # multidimensional hashing; sorry. Fortunately there'll
994 # usually only be one pair returned.
996 for my $ar (keys %{$_binarytosource{$binname}{$binver}}) {
997 my $src = $_binarytosource{$binname}{$binver}{$ar};
998 next unless defined $src;
999 $uniq{$src->[0]}{$src->[1]} = 1;
1002 for my $sn (sort keys %uniq) {
1003 push @uniq, [$sn, $_] for sort keys %{$uniq{$sn}};
1010 # No $gBinarySourceMap, or it didn't have an entry for this name and
1011 # version. Try $gPackageSource (unversioned) instead.
1012 my $pkgsrc = getpkgsrc();
1013 if (exists $pkgsrc->{$binname}) {
1014 return [$pkgsrc->{$binname}, $binver];
1020 # Returns an array of zero or more references to
1021 # (binname, binver[, binarch]) triplets.
1022 my %_sourcetobinary;
1023 sub sourcetobinary {
1024 my ($srcname, $srcver) = @_;
1026 if (tied %_sourcetobinary or
1027 tie %_sourcetobinary, 'MLDBM', $gSourceBinaryMap, O_RDONLY) {
1028 # avoid autovivification
1029 if (exists $_sourcetobinary{$srcname} and
1030 exists $_sourcetobinary{$srcname}{$srcver}) {
1031 my $bin = $_sourcetobinary{$srcname}{$srcver};
1032 return () unless defined $bin;
1033 # Copy the data to avoid tiedness problems.
1038 # No $gSourceBinaryMap, or it didn't have an entry for this name and
1039 # version. Try $gPackageSource (unversioned) instead.
1040 my @srcpkgs = getsrcpkgs($srcname);
1041 return map [$_, $srcver], @srcpkgs;