HOMEWORK/cgi-Q4-EXAMPLE/cgi-bin/cgi-lib.pl # Perl Routines to Manipulate CGI input
# S.E.Brenner@bioc.cam.ac.uk
# $Id: cgi-lib.pl,v 2.4 1996/01/21 20:20:59 brenner Exp $
#
# Copyright (c) 1996 Steven E. Brenner
# Unpublished work.
# Permission granted to use and modify this library so long as the
# copyright above is maintained, modifications are documented, and
# credit is given for any use of the library.
#
# Thanks are due to many people for reporting bugs and suggestions
# especially Meng Weng Wong, Maki Watanabe, Bo Frese Rasmussen,
# Andrew Dalke, Mark-Jason Dominus, Dave Dittrich, Jason Mathews
# For more information, see:
# http://www.bio.cam.ac.uk/cgi-lib/
# Parameters affecting cgi-lib behavior
$cgi_lib’maxdata = 131072; # maximum bytes to accept via POST – 2^17
$cgi_lib’bufsize = 8192; # default buffer size when reading multipart
$cgi_lib’maxbound = 100; # maximum boundary length to be encounterd
$cgi_lib’writefiles = 0; # directory to which to write files
# ReadParse
# Reads in GET or POST data, converts it to unescaped text, and puts
# key/value pairs in %in, using ” to separate multiple selections
# Returns TRUE if there was input, FALSE if there was no input
# UNDEF may be used in the future to indicate some failure.
# Now that cgi scripts can be put in the normal file space, it is useful
# to combine both the form and the script in one place. If no parameters
# are given (i.e., ReadParse returns FALSE), then a form could be output.
# If a variable-glob parameter (e.g., *cgi_input) is passed to ReadParse,
# information is stored there, rather than in $in, @in, and %in.
sub ReadParse {
local (*in) = @_ if @_;
local ($len, $type, $meth);
# Get several useful env variables
$type = $ENV{‘CONTENT_TYPE’};
$len = $ENV{‘CONTENT_LENGTH’};
$meth = $ENV{‘REQUEST_METHOD’};
if ($len > $cgi_lib’maxdata) {
&CgiDie(“cgi-lib.pl: Request to receive too much data: $len…





