]> git.donarmstrong.com Git - debbugs.git/blobdiff - cgi/common.pl
[project @ 2001-01-27 22:09:01 by joy]
[debbugs.git] / cgi / common.pl
index 7ae481f9280ee33959f8bb3bf8739c07856ba1f6..2dea01b7fb271606070037fa322283138eb6e875 100644 (file)
@@ -2,11 +2,36 @@
 
 my $common_archive = 0;
 my $common_repeatmerged = 1;
+my %common_include = ();
+my %common_exclude = ();
 
 sub set_option {
     my ($opt, $val) = @_;
     if ($opt eq "archive") { $common_archive = $val; }
     if ($opt eq "repeatmerged") { $common_repeatmerged = $val; }
+    if ($opt eq "exclude") { %common_exclude = %{$val}; }
+    if ($opt eq "include") { %common_include = %{$val}; }
+}
+
+sub readparse {
+    my ($in, $key, $val, %ret);
+    if (defined $ENV{"QUERY_STRING"} && $ENV{"QUERY_STRING"} ne "") {
+        $in=$ENV{QUERY_STRING};
+    } elsif(defined $ENV{"REQUEST_METHOD"}
+        && $ENV{"REQUEST_METHOD"} eq "POST")
+    {
+        read(STDIN,$in,$ENV{CONTENT_LENGTH});
+    } else {
+        return;
+    }
+    foreach (split(/&/,$in)) {
+        s/\+/ /g;
+        ($key, $val) = split(/=/,$_,2);
+        $key=~s/%(..)/pack("c",hex($1))/ge;
+        $val=~s/%(..)/pack("c",hex($1))/ge;
+        $ret{$key}=$val;
+    }
+    return %ret;
 }
 
 sub quit {
@@ -54,8 +79,10 @@ sub htmlindexentrystatus {
                if (length($status{"package"}));
     $result .= $showseverity;
     $result .= "Reported by: " . htmlsanit($status{originator});
-    $result .= ";\nKeywords: " . htmlsanit($status{keywords})
-                       if (length($status{keywords}));
+    $result .= ";\nTags: <strong>" 
+                . htmlsanit(join(", ", sort(split(/\s+/, $status{tags}))))
+                . "</strong>"
+                       if (length($status{tags}));
 
     my @merged= split(/ /,$status{mergedwith});
     my $mseparator= ";\nmerged with ";
@@ -96,12 +123,20 @@ sub htmlindexentrystatus {
     return $result;
 }
 
+sub submitterurl {
+    my $ref = shift || "";
+    my $params = "submitter=" . emailfromrfc822($ref);
+    $params .= "&archive=yes" if ($common_archive);
+    $params .= "&repeatmerged=yes" if ($common_repeatmerged);
+    return urlsanit($debbugs::gCGIDomain . "pkgreport.cgi" . "?" . $params);
+}
+
 sub mainturl {
-    my $ref = shift;
-    my $params = "maintenc=" . maintencoded($ref);
+    my $ref = shift || "";
+    my $params = "maint=" . emailfromrfc822($ref);
     $params .= "&archive=yes" if ($common_archive);
     $params .= "&repeatmerged=yes" if ($common_repeatmerged);
-    return $debbugs::gCGIDomain . "pkgreport.cgi" . "?" . $params;
+    return urlsanit($debbugs::gCGIDomain . "pkgreport.cgi" . "?" . $params);
 }
 
 sub pkgurl {
@@ -110,12 +145,19 @@ sub pkgurl {
     $params .= "&archive=yes" if ($common_archive);
     $params .= "&repeatmerged=yes" if ($common_repeatmerged);
     
-    return $debbugs::gCGIDomain . "pkgreport.cgi" . "?" . "$params";
+    return urlsanit($debbugs::gCGIDomain . "pkgreport.cgi" . "?" . "$params");
+}
+
+sub urlsanit {
+    my $url = shift;
+    $url =~ s/%/%25/g;
+    $url =~ s/\+/%2b/g;
+    return $url;
 }
 
 sub htmlsanit {
     my %saniarray = ('<','lt', '>','gt', '&','amp', '"','quot');
-    my $in = shift;
+    my $in = shift || "";
     my $out;
     while ($in =~ m/[<>&"]/) {
         $out .= $`. '&'. $saniarray{$&}. ';';
@@ -172,13 +214,27 @@ sub htmlizebugs {
        my %status = getbugstatus($bug);
         next unless %status;
        my @merged = sort {$a<=>$b} ($bug, split(/ /, $status{mergedwith}));
-       if ($common_repeatmerged || $bug == $merged[0]) {
-           $section{$status{pending} . "_" . $status{severity}} .=
-               sprintf "<li><a href=\"%s\">#%d: %s</a>\n<br>",
-                   bugurl($bug), $bug, htmlsanit($status{subject});
-           $section{$status{pending} . "_" . $status{severity}} .=
-               htmlindexentrystatus(\%status) . "\n";
+       next unless ($common_repeatmerged || $bug == $merged[0]);
+       if (%common_include) {
+           my $okay = 0;
+           foreach my $t (split /\s+/, $status{tags}) {
+               $okay = 1, last if (defined $common_include{$t});
+           }
+           next unless ($okay);
+        }
+       if (%common_exclude) {
+           my $okay = 1;
+           foreach my $t (split /\s+/, $status{tags}) {
+               $okay = 0, last if (defined $comon_exclude{$t});
+           }
+           next unless ($okay);
        }
+           
+       $section{$status{pending} . "_" . $status{severity}} .=
+           sprintf "<li><a href=\"%s\">#%d: %s</a>\n<br>",
+               bugurl($bug), $bug, htmlsanit($status{subject});
+       $section{$status{pending} . "_" . $status{severity}} .=
+           htmlindexentrystatus(\%status) . "\n";
     }
 
     my $result = "";
@@ -188,7 +244,7 @@ sub htmlizebugs {
             $severity = $debbugs::gDefaultSeverity if ($severity eq '');
             next unless defined $section{${pending} . "_" . ${severity}};
             $result .= "<HR><H2>$debbugs::gSeverityDisplay{$severity} - $displayshowpending{$pending}</H2>\n";
-            $result .= "(A list of <a href=\"http://www.debian.org/Bugs/db/si/$pending$severity\">all such bugs</a> is available).\n";
+            $result .= "(A list of <a href=\"${debbugs::gWebDomain}/db/si/$pending$severity\">all such bugs</a> is available).\n";
             $result .= "<UL>\n";
            $result .= $section{$pending . "_" . $severity}; 
            $result .= "</UL>\n";
@@ -234,9 +290,9 @@ sub maintbugs {
 }
 
 sub maintencbugs {
-    my $maint = shift;
+    my $maintenc = shift;
     my %maintainers = getmaintainers();
-    return getbugs(sub {my %d=@_; return maintencoded($maintainers{$d{"pkg"}} || "") eq $maint});
+    return getbugs(sub {my %d=@_; return maintencoded($maintainers{$d{"pkg"}} || "") eq $maintenc});
 }
 
 sub pkgbugs {
@@ -244,6 +300,27 @@ sub pkgbugs {
     return getbugs( sub { my %d = @_; return $inpkg eq $d{"pkg"} });
 }
 
+sub countbugs {
+    my $bugfunc = shift;
+    if ($common_archive) {
+        open I, "<$debbugs::gSpoolDir/index.archive" or &quit("bugindex: $!");
+    } else {
+        open I, "<$debbugs::gSpoolDir/index.db" or &quit("bugindex: $!");
+    }
+
+    my %count = ();
+    while(<I>) 
+    {
+        if (m/^(\S+)\s+(\d+)\s+(\d+)\s+(\S+)\s+\[\s*([^]]*)\s*\]\s+(\w+)\s+(.*)$/) {
+            my $x = $bugfunc->(pkg => $1, bug => $2, status => $4, 
+                               submitter => $5, severity => $6, tags => $7);
+           $count{$x}++;
+       }
+    }
+    close I;
+    return %count;
+}
+
 sub getbugs {
     my $bugfunc = shift;
 
@@ -256,11 +333,12 @@ sub getbugs {
     my @result = ();
     while(<I>) 
     {
-        if (m/^(\S+)\s+(\d+)\s+(\d+)\s+(\S+)\s+\[\s*([^]]*)\s*\]\s+(\w+)\s+(.+)$/) {
+        if (m/^(\S+)\s+(\d+)\s+(\d+)\s+(\S+)\s+\[\s*([^]]*)\s*\]\s+(\w+)\s+(.*)$/) {
             if ($bugfunc->(pkg => $1, bug => $2, status => $4, submitter => $5,
-                          severity => $6, title => $7))
+                          severity => $6, tags => $7))
            {
                push (@result, $2);
+               #last if (@result > 400);
            }
        }
     }
@@ -278,9 +356,17 @@ sub pkgbugsindex {
     while(<I>) { 
         $descstr{ $1 } = 1 if (m/^(\S+)/);
     }
+    close(I);
     return %descstr;
 }
 
+sub emailfromrfc822 {
+    my $email = shift;
+    $email =~ s/\s*\(.*\)\s*//;
+    $email = $1 if ($email =~ m/<(.*)>/);
+    return $email;
+}
+
 sub maintencoded {
     my $input = shift;
     my $encoded = '';
@@ -323,7 +409,7 @@ sub getbugstatus {
         my $archdir = sprintf "%02d", $bugnum % 100;
        open(S,"$gSpoolDir/archive/$archdir/$bugnum.status" ) or return ();
     }
-    my @lines = qw(originator date subject msgid package keywords done
+    my @lines = qw(originator date subject msgid package tags done
                        forwarded mergedwith severity);
     while(<S>) {
         chomp;