Running under linux or some similar platform, CGIs process data from the standard io streams and can use the getenv() function to query additional data provided by the web server. On the Mac, this doesn't really happen. Instead, the CGI application and the web server communicate via the 'sdoc' AppleEvent.
There are two basic assumptions made:
- AppleEvents are a bit of a pain
- almost every Mac application has to be interactive
How It Works
Part of the code is a wrapper that provides the bare minimum interactive shell for a Mac application. This handles menus and a couple of dialogs.
The code install handling routines for the basic suite of AppleEvents which are required by all applications. Obviously, the 'sdoc' event is also supported. This is the interapplication data conduit for the CGI and the web server.
The 'sdoc' processing routines parse out the server requests and create an internal data structure which the application can access via the getenv() function. Note: this is currently fairly slow code and could be sped up by placing the fields in a hash table.
The application redirects the STDIN and STDOUT streams so that they can be used for communicating directly with the web server. This is really the only crafty bit of code here - the Assimilator hooks in at a really low level with in the MSL and makes this pretty seamless.
An incoming request from the web server will be processed and routed to a user processing routine which matches the default main(int, char**) function signature. Internally the function is called weasel(), but the precompiled headers will take care of remapping that at compile time.
The MacGetEnv() function emulates most of the abilities of the standard getenv() function. Again, the precompiled headers will remap this function at compile time.