HTTP CGI Programming

EusLisp can be used for CGI programming. The following is a typical cgi entry to a EusLisp program. This code piece should be placed under .../cgi-bin/ or under any directories where ExecCGI is allowed. The code piece must have execute permission by the `nobody' user. Note that CGI programs are executed by httpd whose owner is nobody. You also have to set up some environment variables in the code piece, for nobody does not know anything particular for EusLisp.

#! /bin/csh
setenv EUSDIR /usr/local/eus/
setenv LD_LIBRARY_PATH /usr/local/eus/Linux/lib
/usr/local/bin/eus /usr/local/eus/lib/demo/mycgi.l

mycgi.l is a lisp source program, which should load "$EUSDIR/lib/llib/httpcgi.l" at the beginning. The CGI program is responsible for obtaining CGI arguments, generating an html header, and producing html contents. The arguments are obtained by the get-cgi-query function, and split to a list by the parse-cgi-query function. The parsed list contains pairs of argument-name and argument-value. For example, if the CGI is invoked by href to "/cgi-bin/eus.cgi?user=matsui&age=43", the parsed list gives ((user matsui) (age 43)).

All normal CGI output should go to *cgi-out*. Before any html document, a header should be generated by the html-header function. If there is any error message written to *error-output*, it appears in the httpd's error-log. When the work is done and html document finishes by '</html> tag, the process may close the connection (*cgi-out*) and may exit. Normal exit of the CGI process usually signals the httpd to send the data to http clients.

*cgi-out* is the output stream to which the generated html document should be sent.



gen string [function]

Outputs the string to *cgi-out* stream, which is then forwarded to to the client (browser).


html args ... [function]

generates args as one string.


html-table lst &key heading (table-option "") [function]

generates an html table.


get-cgi-query [function]

gets the argument to this CGI program. First, the REQUEST_METHOD environment variable is looked up, and the POST/GET method is determined. The query string is obtained from the QUERY_STRING environment variable or from the standard input. Anyways, the result is returned in one string.


parse-http-query query-string [function]



html-header [function]
generates the html header, usually a simple string of two lines, "Content-type: text/html~%~%".


qval arg query [function]

arg (symbol) is searched in the query list, and the value is returned if found. The result is converted to euc encoding from sjis encoding.


k-okada 2013-05-21