# -*- Mode: perl; indent-tabs-mode: nil -*- # # The contents of this file are subject to the Mozilla Public # License Version 1.1 (the "License"); you may not use this file # except in compliance with the License. You may obtain a copy of # the License at http://www.mozilla.org/MPL/ # # Software distributed under the License is distributed on an "AS # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or # implied. See the License for the specific language governing # rights and limitations under the License. # # The Original Code is the Bugzilla Bug Tracking System. # # The Initial Developer of the Original Code is Netscape Communications # Corporation. Portions created by Netscape are # Copyright (C) 1998 Netscape Communications Corporation. All # Rights Reserved. # # Contributor(s): Terry Weissman # Contains some global routines used throughout the CGI scripts of Bugzilla. use diagnostics; use strict; # Shut up misguided -w warnings about "used only once". For some reason, # "use vars" chokes on me when I try it here. sub CGI_pl_sillyness { my $zz; $zz = %::FILENAME; } use CGI::Carp qw(fatalsToBrowser); require 'globals.pl'; sub GeneratePersonInput { my ($field, $required, $def_value, $extraJavaScript) = (@_); $extraJavaScript ||= ""; if ($extraJavaScript ne "") { $extraJavaScript = "onChange=\"$extraJavaScript\""; } return ""; } sub GeneratePeopleInput { my ($field, $def_value) = (@_); return ""; } # Implementations of several of the below were blatently stolen from CGI.pm, # by Lincoln D. Stein. # Get rid of all the %xx encoding and the like from the given URL. sub url_decode { my ($todecode) = (@_); $todecode =~ tr/+/ /; # pluses become spaces $todecode =~ s/%([0-9a-fA-F]{2})/pack("c",hex($1))/ge; return $todecode; } # Quotify a string, suitable for putting into a URL. sub url_quote { my($toencode) = (@_); $toencode=~s/([^a-zA-Z0-9_\-.])/uc sprintf("%%%02x",ord($1))/eg; return $toencode; } sub ProcessFormFields { my ($buffer) = (@_); undef %::FORM; undef %::MFORM; my %isnull; my $remaining = $buffer; while ($remaining ne "") { my $item; if ($remaining =~ /^([^&]*)&(.*)$/) { $item = $1; $remaining = $2; } else { $item = $remaining; $remaining = ""; } my $name; my $value; if ($item =~ /^([^=]*)=(.*)$/) { $name = $1; $value = url_decode($2); } else { $name = $item; $value = ""; } if ($value ne "") { if (defined $::FORM{$name}) { $::FORM{$name} .= $value; my $ref = $::MFORM{$name}; push @$ref, $value; } else { $::FORM{$name} = $value; $::MFORM{$name} = [$value]; } } else { $isnull{$name} = 1; } } if (defined %isnull) { foreach my $name (keys(%isnull)) { if (!defined $::FORM{$name}) { $::FORM{$name} = ""; $::MFORM{$name} = []; } } } } sub ProcessMultipartFormFields { my ($boundary) = (@_); $boundary =~ s/^-*//; my $remaining = $ENV{"CONTENT_LENGTH"}; my $inheader = 1; my $itemname = ""; # open(DEBUG, ">debug") || die "Can't open debugging thing"; # print DEBUG "Boundary is '$boundary'\n"; while ($remaining > 0 && ($_ = )) { $remaining -= length($_); # print DEBUG "< $_"; if ($_ =~ m/^-*$boundary/) { # print DEBUG "Entered header\n"; $inheader = 1; $itemname = ""; next; } if ($inheader) { if (m/^\s*$/) { $inheader = 0; # print DEBUG "left header\n"; $::FORM{$itemname} = ""; } if (m/^Content-Disposition:\s*form-data\s*;\s*name\s*=\s*"([^\"]+)"/i) { $itemname = $1; # print DEBUG "Found itemname $itemname\n"; if (m/;\s*filename\s*=\s*"([^\"]+)"/i) { $::FILENAME{$itemname} = $1; } } next; } $::FORM{$itemname} .= $_; } delete $::FORM{""}; # Get rid of trailing newlines. foreach my $i (keys %::FORM) { chomp($::FORM{$i}); $::FORM{$i} =~ s/\r$//; } } sub FormData { my ($field) = (@_); return $::FORM{$field}; } sub html_quote { my ($var) = (@_); $var =~ s/\&/\&/g; $var =~ s//\>/g; return $var; } sub value_quote { my ($var) = (@_); $var =~ s/\&/\&/g; $var =~ s//\>/g; $var =~ s/"/\"/g; $var =~ s/\n/\ /g; $var =~ s/\r/\ /g; return $var; } sub navigation_header { if (defined $::COOKIE{"BUGLIST"} && $::COOKIE{"BUGLIST"} ne "" && defined $::FORM{'id'}) { my @bugs = split(/:/, $::COOKIE{"BUGLIST"}); my $cur = lsearch(\@bugs, $::FORM{"id"}); print "Bug List: (@{[$cur + 1]} of @{[$#bugs + 1]})\n"; print "First\n"; print "Last\n"; if ($cur > 0) { print "Prev\n"; } else { print "Prev\n"; } if ($cur < $#bugs) { $::next_bug = $bugs[$cur + 1]; print "Next\n"; } else { print "Next\n"; } } print "     Query page\n"; print "     Enter new bug\n" } sub make_options { my ($src,$default,$isregexp) = (@_); my $last = ""; my $popup = ""; my $found = 0; $default = "" if !defined $default; if ($src) { foreach my $item (@$src) { if ($item eq "-blank-" || $item ne $last) { if ($item eq "-blank-") { $item = ""; } $last = $item; if ($isregexp ? $item =~ $default : $default eq $item) { $popup .= "