# SPL Module Reference: cgi

load "cgi";

    Module for writing CGIs

builtin cgi_userfile_save(paramname, filename);
builtin cgi_write(text);

namespace cgi
{
var param;
var cookie;
var config;
var content_type = "text/html";
var silent_debug = 0;
var sid;
var sid_vm;
var sid_task;
var sid_passed;
var url;
var agent;
var peerip;
var post_type;
var post_data;
}

builtin cgi_userfile_save(paramname, filename);

    This function can be used to save an uploaded file to the local filesystem.
    The 1st parameter is the name of the upload form field and the 2nd parameter
    the local filename.

    The file will be truncated if it exists already and created if it does not.

    The pseudo-variable 'cgi.param.<name>' contains the name of the file. The
    content of the uploaded file can't be accessed directly.

    This function returns the number of bytes written to the harddisk or undef
    for an error.

builtin cgi_write(text);

    This function sends the specified text to the web browser. It also creates
    the HTTP header when it is called the first time for an HTTP request.

namespace cgi

    This namespace holds all the CGI specific data, like query string parameters
    or browser type.

var cgi.param;

    A hash with  all query string parameters, parameter name as key and
    parameter value as value.

    This variable is read-only.

var cgi.cookie;

    A hash with all cookies passed by the browser. Writing to this hash is only
    possible as long as no cgi_write() has been isued.

var cgi.config;

    A hash with all config variables read from the webspl.conf files.
    Example given:

    	# In webspl.conf
    	[ myapp.webspl ]
    	myapp.dbtype = sqlite
    	myapp.database = /var/lib/myapp/database.bin

    	// In the script
    	var db = sql_connect(cgi.config.myapp.dbtype, cgi.config.myapp.database);

var cgi.content_type = "text/html";

    The HTTP content-type of the document to be send back to the browser. This
    variable is write-only and must be set before cgi_write() is called
    the first time. It is automatically reset to "text/html" for each new HTTP
    response.

var cgi.silent_debug = 0;

    When this variable has a non-zero value, the output created by debug
    statements is not sent to the browser. This variable is write-only. It
    is automatically reset to '0' for each new HTTP response.

var cgi.sid;

    The current session id (with the now running task)

    This variable is read-only.

var cgi.sid_vm;

    The current session id (without task)

    This variable is read-only.

var cgi.sid_task;

    The task part from the session id requested by the user.

    This variable is read-only.

var cgi.sid_passed;

    The session id as requested by the user (vm and task).

    This variable is read-only.

var cgi.url;

    The url requested by the browser (without the query string). This is useful
    for building self-references.

    This variable is read-only.

var cgi.agent;

    The identification string sent by the user agent.

    This variable is read-only.

var cgi.peerip;

    The IP address of the peer.

    This variable is read-only.

var cgi.post_type;

    The mime type of the data sent in a POST request.

    This variable is read-only.

var cgi.post_data;

    The data sent in a POST request when it is a text/<something> mime type.

    This variable is read-only.

Generated by SPLDOC. | http://www.clifford.at/spl/