THE PARSE CGI OSAX
This OSAX will accelerate and simplify all your HTML form scripts.
Version 1.0
By Alex Powers and Mark Kriegsman
Copyright © 1995 Document Directions, Inc.
(617) 227-2100

Contents


Claim

The parse CGI OSAX will accelerate and simplify all your HTML form scripts. If you find that your scripts are faster and simpler with our OSAX, please send the $10 shareware fee.


Description

The parse CGI OSAX is used to decode, parse, and access the HTML form information that is passed in to an AppleScript CGI program by MacHTTP. It is meant to replace the use of the "DePlus," "Decode URL," and "Tokenize" OSAXen to handle incoming form data. In addition, it provides a streamlined interface that is specifically designed for CGI scripting.

Example 1: Getting data from HTML forms into AppleScript variables

This is probably the most common operation found at the top of CGI scripts. The parse CGI OSAX has been explicitly designed to accelerate and simplify this process.
-- decode and parse all arguments
set formData to parse CGI arguments post_args

-- get specific fields
set first_name to CGI field "first_name" from formData
set last_name to CGI field "last_name" from formData
set processor to CGI field "processor" from formData default value "PowerPC"

Example 2: Updating Jon Wiederspan's "Level 5 Example"

The following code fragment is copied directly from Jon Wiederspan's "Level 5 Example Script". Jon's code returns a page showing all the incoming arguments. Below is the parsing code as it was published and as it can now be written using the parse CGI OSAX.
Jon Wiederspan's original code:
-- this creates a list of "name=value" pairs
set postarglist to tokenize post_args with delimiters {"&"}
		
-- The section below converts the list to readable output, putting each item onto a separate line.
-- Uses DecodeURL to convert %XX encodings and Tokenize/JoinList to
-- convert "+" to spaces.
		
-- store the original AppleScript text item delimiters
set oldDelim to AppleScript's text item delimiters
-- use "=" to delimit the pairs
set AppleScript's text item delimiters to {"="}
-- initialize postargtext in case the item is empty
set postargtext to ""
-- traverse the list item by item
repeat with currpostarg in postarglist
  set postargtext to postargtext & -|
  (Decode URL (dePlus (last text item of currpostarg))) & return & return
end repeat
-- restore the old AppleScript text item delimiters settings
set AppleScript's text item delimiters to oldDelim
Updated using the parse CGI OSAX
-- initialize postargtext		
set postargtext to ""

-- decode and parse all arguments
set formData to parse CGI arguments post_args

-- traverse the list of records
repeat with currField in formData
  set postargtext to postargtext & value of currField & return & return
end repeat

Exact behavior

There are actually two OSAX in this package. The first, parse CGI arguments, does all the decoding and parsing and returns a list of records. The second OSAX, CGI field, performs a high-speed lookup in the list of records.
parse CGI arguments post_args
This OSAX does the hard part. It decodes the post arguments, including allowances for the use of "+" where "%20" would be more correct. It then creates a list of records from the POST arguments, where each record has a "field" and a "value" that are taken from the HTML form post data. So, input of "first_name=Alex%20C.&last_name=Powers" would produce:
{{field:"first_name", value:"Alex C."}, 
 {field:"last_name", value:"Powers"}}

CGI field field_name from form_data
CGI field field_name from form_data default value default_value
This OSAX performs high-speed lookups in the list of records returned by parse CGI arguments. The input is the field name to search for. If the requested field is not found, or if the field's value is empty, then an optional default value can be returned. If no default is specified, and the search fails, the empty string is returned.

The search for the field name is case sensitive, because HTML forms can have distinct fields whose names differ only in capitalization.


Who we are and why we did this

Document Directions, Inc. is a consulting and integration company specializing in electronic document management for financial services companies. We were preparing a demonstration system based on MacHTTP, and needed to boost the performance of the system. We examined our (relatively simple) CGI scripts, and noticed how much time and code went into parsing the CGI arguments. The parse CGI OSAX is the direct result of our optimization efforts. The added benefit was that we now have a very direct programming interface for CGI scripts.

We have experience with Unix, Windows (NT and plain), and Macintosh platforms, building streamlined applications that provide powerful results. The parse CGI OSAX, we believe, is another good example of the leverage we provide to our clients, and now to the community at large.


Shareware details

We feel that the parse CGI OSAX will accelerate and simplify all your CGI scripts. If you find that your scripts are faster and simpler with our OSAX, please send the shareware fee listed below: Please send money orders or checks drawn on US Banks.
Make payable to
Document Directions, Inc.
Send to
Mark Kriegsman
Document Directions, Inc.
131 State Street
Boston, MA 02109
USA

Contacting us

You can contact us in our Boston office at (617) 227-2100, or send e-mail to ddi@document.com.
This package may be freely distributed in its unmodified state as long as this documentation is included.
Neither Document Directions, Inc., nor the authors make any claim as the suitability of this program or information for any particular task. You examine and use this program and information at your own risk.
Last updated 5/30/95