WebSTAR 4 Manual & Technical Reference

Manual Contents | Chapter Contents | Previous Page | Next Page

Developing CGIs

A CGI is any application that uses the Mac OS Common Gateway Interface standard to interact with an information server such as WebSTAR. The CGI standard defines arguments that allow the server to pass data to applications and receive data back from them.

You can develop a CGI to integrate with databases, process forms, and perform all sorts of other useful functions. CGIs can be developed and programmed in high-level scripting languages such as AppleScript, Frontier or MacPerl, or in low-level languages like C, Pascal or Java. Developing an application in a low-level language requires more effort but results in much better performance than an application developed in a scripting language.

The WebSTAR server itself does not process the data it sends to the CGI application nor the pages it returns to the client software. The server's job is to handle connections, use the proper method to return pages and files, and handle communications between the client and the CGI.

CGIs must perform all HTML formatting themselves. The WebSTAR web server expects your script or application to generate and return a proper HTTP header, and does no conversion of the return values from CGIs.

See the WebSTAR Development site at <http://dev.starnine.com/> for specs and more information related to Mac OS CGI development.

ACGIs and Asynchronous Processing

The WebSTAR server can interact with a CGI synchronously or asynchronously . If the name application ends with " .cgi ", the server passes an Apple Event to the application and waits for the CGI to return a result (synchronous operation). If the application name ends in " .acgi ", the server passes an Apple Event to the application and then continues processing other tasks until it receives a reply. Writing a CGI to be processed asynchronously is usually preferable.

AppleScript CGI Issues

While the Mac OS CGI ' handle CGI request ' parameter provides a cleaner format for writing AppleScript-based CGIs, it does not support the " Full Request " and " DIRE " parameters supported by the WebSTAR CGIs ' «event WWWωsdoc» ' format.
http://dev.starnine.com/

WebSTAR Apple Events

The WebSTAR server includes Apple Events and application properties to set all configuration parameters. For the most part, the syntax of the data sent by the AppleScript Set commands, or returned by the AppleScript Get commands is the same as the syntax for setting parameters.

Many of the application properties can be found in the Apple Event dictionary for the WebSTAR server, viewable in the Script Editor.

The WebSTAR server supports the four required Apple Events, plus a custom Apple Event suite for sending information to the WebSTAR server while it is running. The custom event suite provides the flexibility and power of WebSTAR CGIs.

The event suite for the WebSTAR server Apple Events is the same as the four-character creator code for the WebSTAR server application. The four-character Event Suite is WWWω--three uppercase Ws (WWW), followed by the omega character "ω" (option-Z on the keyboard).

WebSTAR Apple Event Suite 

Event

Command

Parameters

Example

Verbose Messages

Toggle Verbose Messages on or off

Verbose Messages <boolean value>

True or False

verbose messages false

Hide Window

Toggle hiding status window in the background

Hide Window <boolean value>

True or False

hide window true

Refuse Connections

Toggle incoming web connections on or off

Refuse Connections <boolean value>

True or False

refuse connections false

Suspend Logging

Turn logging on or off

Suspend Logging <boolean value>

True or False

suspend logging true

flush cache

Flushes the file info cache, the data cache and any Plug-In caches.

flush cache

none

flush cache

reset stats

resets all server counters to zero

reset stats

none

reset stats

add user

Add a user and password for a specific security realm

add user <username> password <password> realm <security realm>

 

user name, password and realm name as character strings

add user "President" password "speCial100" realm "HUMRES"

delete user

Delete specified user from a particular security realm

delete user <username> realm <security realm>

user name and realm name strings.

delete user "President" realm "HUMRES"

import users

import records into the user/password database

import users <importFile>

importFile: file specification, fileRefNum in AppleScript.

import users myUserFile

validate user

Validate that a given password is correct for a user in a specific realm

validate user <username> password <password> realm <security realm>

user name, password and realm name as character strings

validate user "President" password "speCial100" realm "HUMRES"

Get_AllowDenyInfo

get allow/deny info for a specific realm

Result: character string containing allow/deny info for specified realm

Get_AllowDenyInfo for <realmName>

realmName: name of the realm as a character string.

Get_AllowDenyInfor "HUMRES"

Set_AllowDenyInfo

set allow/deny info for a specific realm

Set_AllowDenyInfo <status><address> for <realmName>

status: allow or denay;address: host name, domain name or IP address as string; realmName: name of the realm as a string.

Set_AllowDenyIndeny "dumb.com" for "HUMRES"

Status Report

Return status information about the server

Result: returns info about WebSTAR in a character string.

Status Report

 

none

status report true

r equest reporting

Request real-time status reports be sent to caller.

Result: status of request & name and port of remote WebSTAR server in a character string.

request reporting messages <boolean> status <boolean> id <requestor ID> client_version <admin client version number>

user name, password and realm name as character strings

request reporting messages true status false client_version 3.0

 

send partial

Sends partial ACGI execution results to the WebSTAR web server for transmission to clients.

send partial <partialData> connection integer <connectionID> more <boolean>

partialData : data to return to the WWW client, as a character string.
connectionID : connection ID to return data to, as an integer
more : is there more data to send? True/False

send partial "this is a test" connection 24 more true

WSAPI_ReadHTTPData

Read incoming data from a HTTP client (e.g., POST args, etc.)

WSAPI_ReadHTTPData

The WebSTAR API parameter that you would like to read for that connection, along with the connection ID

WSAPI_ReadHTTPData

WSAPI_GetIndexedParamete r

Result: 'char'

Retrieve a scalar WebSTAR API parameter (indexed or normal)

WSAPI_GetIndexed
Parameter <WebSTAR API parameter> [index <indexName> connection <connectionID>]

WebSTAR API parameter
[index ' char '] -- index to retrieve
connection integer -- connection ID to retrieve parameter from

WSAPI_GetIndexedParameter

Notes on WebSTAR API Apple Events

WSAPI_ReadHTTPData circumvents the old 32K limit on POST args by allowing you to call it multiple times. The dataLen parameter is limited to 32K at a time. If more than 32K is expected from the client, you'll have to send this event multiple times to read all the data. Note that calling this function when data isn't pending will likely result in a timeout.

The WSAPI_GetIndexedParameter event gets information about WebSTAR using WebSTAR API parameters (see WebSTAR API Parameter Definitions ). Unlike the function of the same name in the WebSTAR API, the Plug-In parameter specifier is a character string instead of a 4 byte OSType character. Also, integer values are coerced to strings before being returned and non-integer, non-string parameters are not returned (e.g., FSSpecs, etc.).

For information about the equivalent API functions, use the WebSTAR Server Suite Installer to custom install "WebSTAR Development Resources", and see the WebSTAR API SDK.

Apple Event Properties

The WebSTAR server application Get and Set events can use these properties:

WebSTAR Apple Event Properties  

Property

Data Type

Meaning

dump_buf_size

small integer

(256-10240)

Output buffer size for TCP/IP writes to clients.

maxusers

small integer

(4-500)

Maximum number of simultaneous users. The upper limit is 500 under Open Transport.

no_dns

boolean

(true = DNS off, false = DNS on)

Toggle for domain name resolution by the server.

time_out

small integer

(5-600)

Timeout value for idle client connections and Apple Events in seconds

logging

boolean

Enable/Disable logging

verbose_messages

boolean

Toggle Verbose Messages on/off

refuse_connections

boolean

Refuse/Allow incoming web connections

default_mime_type

`char'

Default MIME type for untyped files

port

small integer

TCP/IP port for server to listen on

index_file

`char'

Name of the default "index" file

error_file

`char'

Name of the error message file

log_file

`char'

Name of server log file

log_format

`char'

String of keywords for log format

no_access_file

`char'

Name of "no access" file

pre_processor

`char'

Pre-processor application name

post_processor

`char'

Post-processor application name

suffix_mappings

`char'

Suffix and MIME Type mappings in text block format

access_controls

`char'

Allow/Deny access controls via IP address and domain name. Text block format

realms

`char'

Security realm entries in text block format.

actions

`char'

User-defined actions in text block format

version

`char' [r/o]

WebSTAR version number

CGI_Persistent_Connections

integer

Should CGIs be allowed to have persistent connections?

WNE_Threshhold

integer

How often Wai Next Event should be called

report_delay

small integer

(1-60)

Number of seconds delay between status report events

file_info_

cache_size

integer

(0 to max RAM)

Amount of memory to allocate for file info caching. The upper limit is the amount of RAM available to WebSTAR

keep_alive_
connections

small integer

(0 - 10)

Number of persistent connections per client to keep active

keep_alive_time

small integer

(0 - 60)

Timeout delay for persistent connections

plugin_admin_info

`char' [r/o]

Information for configuring installed Plug-Ins (tab separated tokens)

server_name

`char'

Name of server to return in HTTP responses instead of DNS name

cgi_bin_only

boolean

Flag that indicates if only CGIs inside the cgi-bin directory will be executed

Calling CGIs

If the WebSTAR server receives a query (such as "GET") from a browser requesting a file whose suffix mapping Action is "CGI" or "ACGI", the WebSTAR server attempts to launch the CGI application and communicate with it via Apple Events.

The WebSTAR server implements the Mac OS Common Gateway Interface standard in the sdoc Apple Event. The four-character Event Suite is "WWWω"--three uppercase Ws (WWW), followed by the omega character (option-Z on the keyboard). The four-character event code is sdoc . For example:

 
on «event WWWωsdoc»

The Apple Event keyword codes for the parameters passed by the WebSTAR server to CGI and ACGI applications are listed below. You can name the variables associated with these parameters whatever you like.

CGI Parameters  

Parameter

Keyword

Data size

Description

Path Args

----

 
1024

Contains arguments following the dollar-sign ($) in a URL. For example, for this URL:

<form action="ProcessForm.cgi$JimmyJones?14" method=post>

the value "JimmyJones" is contained in this parameter. This keyword is also the direct parameter of the Apple Event (keyDirectObject).

Search Args

kfor

 
1024

Contains arguments following a question mark ("?") in a URL. For example, for this URL:

<form action="ProcessForm.cgi$JimmyJones?14" method=post>

the value "14" is contained in this parameter.

Username

user

 
32

Passes the username if authentication was required.

Password

pass

 
32

Passes the password if authentication was required.

From User

frmu

128

(obsolete) email address of user.

Client Address

addr

 
256

Passes the domain name of the client (or the IP address if DNS look-ups are disabled).

Server Address

svnm

 
256

Passes the domain name of the server (or the server's IP address if DNS look-ups are disabled).

Server IP port

svpt

 
16

Passes the TCP/IP port the server is listening on.

Script name

scnm

1024

Passes the path of the CGI being executed. If the CGI is called as an ACTION, this parameter contains the file portion of the URL.

Content Type

ctyp

64

Passes the MIME type of post arguments if present.

Referrer

refr

1024

Passes the URL of the page from which this CGI was referenced. This information is useful for telling what sites are referencing your pages. It can also be useful in a script to add a "return" link to pages on-the-fly that would return users to whatever page they came from.

User Agent

Agnt

256

Passes the WWW client software (browser) name and version.

Action

Kact

1024

Passes the action being performed by the CGI. It will contain either the name of the user-defined action or one of these strings: CGI , ACGI , PREPROCESSOR , POSTPROCESSOR , ERROR , INDEX , or NOACCESS .

Action Path

Kapt

1024

Passes the path to this CGI if it is executing as an action (in which case, the script name parameter contains the URL file path sent from the client).

Post Arguments

post

32,768

Passes arguments sent from the WWW client as part of a POST request (such as form arguments). The actual form data (returned from running the CGI) is also placed in this parameter.

Method

meth

32

Passes the HTTP method being requested (such as GET , GET_CONDITIONAL , POST , etc.). For more information, see The Method Parameter .

Client IP Address

Kcip

32

Passes the IP address of the client as a string, even if NO_DNS is false.

Full Request

Kfrq

4096

Passes the complete, unmodified HTTP request as received from the WWW client.

Connection ID

Kcid

4

Passes a unique long integer identifying the TCP/IP connection over which the server is communicating to the client. This number is used for sending the "Send Partial" Apple Event to the WebSTAR web server.

DIRE

DIRE

70

An FSSpec pointing to the root folder of the virtual host, or, if the URL is not for a virtual host, the WebSTAR root folder.

The Method Parameter

This parameter passes the HTTP method being requested (such as GET, GET_CONDITIONAL, POST, etc.).

If the HTTP method is POST, the form data sent in the object body of the HTTP request is returned to the server in the post_args parameter. Otherwise, this parameter is empty.

If the HTTP method is GET, the form data overwrites the http_search_args parameter. If you are using a map-processing CGI, you might use the method=get argument to pass the name of a map information file that the CGI should use to process the map. The URL might look like this:

 
/cgi/MapServe.acgi$jonsmap.map

When a user clicks on the map, the client software changes this URL so that the map coordinates are added in the search. arguments. The full URL transmitted to the WebSTAR web server would look something like this:

 
/cgi/MapServe.acgi$jonsmap.map?223,1

CGIs and Virtual Hosts

When WebSTAR sends an Apple Event to CGIs, it includes a "DIRE" parameter. This enables CGIs to determine the correct root folder for the virtual host the request was made to.

More Information on CGIs

For more information about how to develop CGI applications that work with the WebSTAR server, see:

http://dev.starnine.com/


Manual Contents | Chapter Contents | Previous Page | Next Page