You copied the Doc URL to your clipboard.

2.1.3. Common Gateway Interface

In most embedded systems, the main purpose of CGI routines is to use data from HTML forms to configure the system. The CGI on the server is optimized for this purpose.

In general terms, CGI is an HTTP feature that allows the end user to execute a predefined program on the server. Usually, the end user initiates this by getting an HTML page that contains a form from the server. The form specifies a file the browser should reference when it sends back filled-in form data. When the end user has filled in the form, the browser sends a GET or POST request for the file referenced in the form, with the form data appended to the file name as a string of encoded text.

On a conventional UNIX webserver, the server then executes a process (indicated by the file name in the form), and passes it the form data. The process executes a C program or Perl script that processes the form data and returns HTML text to be sent back to the browser.

The ARM Webserver assumes that there is no command shell capability. The file indicated by the GET or POST reply to a form is looked up in the VFS. If the programmer and HTML form author are cooperating, this file will be a CGI file, having a pointer to a CGI routine to execute instead of file data. You, as part of the porting effort, supply the CGI routine. All the form reply data items are parsed from the HTTP header and stored in a C structure, struct formdata in httpd.h, which is passed to the CGI routine.

The CGI routine is also passed a pointer to the httpd structure, from which it can get the transaction’s socket. This routine can do whatever you want with the passed data, and return any HTML text you want. It can also send HTML data into the socket, and it can close the socket. On a system with multitasking, the CGI routine can block, and the logic in the ARM Webserver will not be affected. It can loop indefinitely, sending occasional updates to the browser. On a port to a UNIX-like system, this CGI routine could execute a shell script, allowing any standard CGI script or program to be used with the server.

The exact semantics of the CGI routine are designed to take advantage of generic form reply HTML text that you can modify and embed with the HTML Compiler. See CGI routines for details.

Was this page helpful? Yes No