#!/usr/local/bin/perl ##++ ## Copyright (c) 1995, 1996 ## Shishir Gundavaram and O'Reilly & Associates ## All Rights Reserved ## ## E-Mail: shishir@ora.com ## ## Permission to use, copy, modify and distribute is hereby granted, ## providing that no charges are involved and the above copyright ## notice and this permission appear in all copies and in supporting ## documentation. Requests for other distribution rights, including ## incorporation in commercial products, such as books, magazine ## articles, or CD-ROMS should be made to the authors. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ## ## This "mini" library contains the parse_form_data and ## return_error subroutines. ## ## There are two ways to use these subroutines: ## ## 1. You can cut and paste these subroutines directly into ## the program. ## ## 2. You can leave this file as is, and then insert the ## following line at the top of your program: ## ## require "common.pl"; ## ## Shishir Gundavaram ## June 20, 1996 ##-- sub parse_form_data { local (*FORM_DATA) = @_; local ($request_method, $query_string, @key_value_pairs, $key_value, $key, $value); $request_method = $ENV{'REQUEST_METHOD'}; if ($request_method eq "GET") { $query_string = $ENV{'QUERY_STRING'}; } elsif ($request_method eq "POST") { read (STDIN, $query_string, $ENV{'CONTENT_LENGTH'}); } else { &return_error (500, "Server Error", "Server uses unsupported method"); } @key_value_pairs = split (/&/, $query_string); foreach $key_value (@key_value_pairs) { ($key, $value) = split (/=/, $key_value); $value =~ tr/+/ /; $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg; if (defined($FORM_DATA{$key})) { $FORM_DATA{$key} = join ("\0", $FORM_DATA{$key}, $value); } else { $FORM_DATA{$key} = $value; } } } sub return_error { local ($status, $keyword, $message) = @_; print "Content-type: text/html", "\n"; print "Status: ", $status, " ", $keyword, "\n\n"; print <CGI Program - Unexpected Error

$keyword


$message Please contact $webmaster for more information. End_of_Error exit(1); } 1;