The mosmlcgi library

The mosmlcgi library was developed to make it easy to develop CGI applications in Moscow ML. I am assuming that the reader is already familiar with the general idea of the CGI interface.

Moscow ML is very suitable for writing such applications because of the excellent string manipulation facilities that come with the new standard library that Moscow ML implements.

What the mosmlcgi library provides to a CGI application is:

  1. a number of constants that give information about the caller's and the CGI application's environment;
  2. procedures for extracting information from a <FORM> element that invoked the CGI application.

The following is the signature of the mosmlcgi library:

val cgi_server_software : string option;
val cgi_server_name : string option;
val cgi_gateway_interface : string option;
val cgi_server_protocol : string option;
val cgi_server_port : string option;
val cgi_request_method : string option;
val cgi_http_accept : string option;
val cgi_http_user_agent : string option;
val cgi_http_referer : string option;
val cgi_path_info : string option;
val cgi_path_translated : string option;
val cgi_script_name : string option;
val cgi_query_string : string option;
val cgi_remote_host : string option;
val cgi_remote_addr : string option;
val cgi_remote_user : string option;
val cgi_remote_ident : string option;
val cgi_auth_type : string option;
val cgi_content_type : string option;
val cgi_content_length : string option;
val cgi_annotation_server : string option;

val cgi_field_strings : string -> string list;
val cgi_field_string : string -> string option;
val cgi_field_integer : string * int -> int;
The non-procedures are constants that are NONE if the corresponding information was not provided by the HTTP server and SOME(str) otherwise, where str is a string.

The procedures cgi_field_strings, cgi_field_string and cgi_field_integer retrieve the values sent for <INPUT>, <TEXTAREA> and <SELECT> units on the form.

The procedure cgi_field_strings : string -> string list retrieves a list of all values that were provided for some name. I.e., if fld is a string, then cgi_field_strings(fld) is a (possibly nonempty) list of strings where each string is the value sent with some name/value pair for fld. The order of values in the list is the same as the order in which the name/value pairs were transmitted by the browser.

The procedure cgi_field_string : string -> string option retrieves a value that was provided for some name, if there was one (if there was more than one pair with the given name, one is chosen arbitrarily). I.e., if fld is a string, then cgi_field_string(fld) returns NONE if no name/value pair with that name was sent and SOME(value) otherwise, where value is a string that is the value from one such name/value pair.

The procedure cgi_field_integer : string * int -> int retrieves an integer that was provided for some name, if there was one (if there was more than one pair with the given name, one is chosen arbitrarily) and if that value was an integer numeral. In any other case, a default value is returned. I.e., if fld is a string that contains an integer numeral and def is an int, then cgi_field_integer(fld,def) returns def if no name/value pair with that name was sent or the chosen one was not an integer numeral and value otherwise, where value is an int that is the integer corresponding to the value from one such name/value pair.

You may copy the files mosmlcgi.sig and mosmlcgi.sml to another computer and compile them there to obtain mosmlcgi.sig and mosmlcgi.sml. Under UNIX or on a PC, give the commands

mosmlc -c mosmlcgi.sig
mosmlc -c mosmlcgi.sml
and on a Macintosh, use the Compile... choice under the Command menu on each file.

In order to use mosmlcgi you must supply the option

-I ~jonas/public_html/mosmlcgi
to mosmlc or mosml. (If you are not running on the computers at our department, replace ~jonas/public_html/mosmlcgi with the directory where you have put mosmlcgi.ui and mosmlcgi.uo.) Also you need to link in the library unit object files
Splaytree.uo Splaymap.uo StringCvt.uo Integer.uo Substring.uo Process.uo
in addition to mosmlcgi.uo.

mosmlcgi was developed by Jonas Barklund, Computing Science Department, Uppsala University.


Denna WWW-sida har URL http://www.csd.uu.se/~jonas/mosmlcgi/index.shtml och underhålls av Jonas Barklund.
Den har hämtats 1462 gånger sedan 960704. Senaste uppdatering 961208 06:27.