@CHIP-RTOS - Web server CGI interface
IPC@CHIP® Documentation Index
CGI API
CGI API
The CGI ("Common Gateway Interface") API uses interrupt 0xAB with a service number
in the high order byte of the AX register (AH). This interface provides
access to the CGI implementation of the IPC@CHIP® Web server.
CGI at the IPC@CHIP® provides the possibility to install at the IPC@CHIP® Web server
own programmed CGI functions. These functions are bound with a fixed name and are executed by
the Web server task, if a http request with such a fixed name comes in. This mechanism allows
dynamic usage of the IPC@CHIP® Web server.
For better understanding of CGI and possibilities for
using, see description of available program examples at the example link below.
File Upload:
Also there is a possibility to upload files to the @CHIP's disk. This does not use the CGI
interface but the Web server. Therefore you only need a defined HTML form which sends
the required data to the @CHIP Web server. An example can be found in the CGI Example Zip file.
Notes:
- For test and demonstration purpose two pages are preinstalled at the IPC@CHIP®:
a)main.htm:
Static html introduction page.
b)chipcfg :
Dynamic page with system time/date and configuration data of the requested IPC@CHIP®.
-
For configuring the webserver and CGI, see the provided chip.ini entries.
-
For some useful comments see also under Programming notes
Topics
Interrupt 0xAB - CGI ServicesService is selected by
index in AH register.
Interrupt 0xAB - SSI ServicesService is selected by
index in AH register.
Interrupt 0xAB service 0x01:
CGI_INSTALL, Install a CGI function
Parameters
- AH
- 0x01 (= CGI_INSTALL)
- DX:SI
- Pointer to a CGI_Entry
type structure.
Return Value
- DX =0 success AX: 0
DX!=0 failure AX: contains error code
CGI_NO_FREE_ENTRY or CGI_INVALID_METHOD
Comments
- This API function makes no copy of the information in the
provided CGI_Entry structure, so the contents of structure
at [DX:SI] must be persistent, but not the structure itself.
This means that the PathPtr and CgiFuncPtr must be persistent.
The maximum number of available CGI pages is configurable at the chip.ini file, see
CGI entries.
Related Topics
-
- CGI API Error Codes
-
- cgistat
command line
-
- CGI_INSTALL_PAS API Function, for Pascal CGI Procedures
Supported since or modified in @CHIP-RTOS version-
SC12 | SC13 | SC11 | SC1x3 | SC2x |
-
V1.00 | V1.00 | V1.00 | V0.90 | V1.00 |
Top of list Index page
Interrupt 0xAB service 0x02:
CGI_REMOVE, Remove a CGI function
Parameters
- AH
- 0x02 (= CGI_REMOVE)
- DX:SI
- Pointer to the null terminated URL path name
Return Value
- DX =0 success AX: 0
DX!=0 failure AX: contains error code CGI_NOT_FOUND
Comments
- The CGI function to be deleted is identified by the provided
URL string.
It is also possible to remove the two predefined cgi functions
main.htm
and chipcfg
from the table.
Related Topics
-
- CGI API Error Codes
-
- cgistat
command line
Supported since or modified in @CHIP-RTOS version-
SC12 | SC13 | SC11 | SC1x3 | SC2x |
-
V1.00 | V1.00 | V1.00 | V0.90 | V1.00 |
Top of list Index page
Interrupt 0xAB service 0x03:
CGI_SETMAIN, Set a new main page
Parameters
- AH
- 0x03 (= CGI_SETMAIN)
- DX:SI
- Pointer to name of new main page
Return Value
- DX =0 success AX: 0
DX!=0 failure AX: error code CGI_INVALID_NAME
Comments
- The string at [DX:SI] is null terminated with a maximum
length of 64 characters (not counting the terminating zero).
Related Topics
-
- CGI_GETMAIN API Function
-
- CGI API Error Codes
Supported since or modified in @CHIP-RTOS version-
SC12 | SC13 | SC11 | SC1x3 | SC2x |
-
V1.00 | V1.00 | V1.00 | V0.90 | V1.00 |
Top of list Index page
Interrupt 0xAB service 0x04:
CGI_SETROOTDIR, Set Web server's root directory
Parameters
- AH
- 0x04 (= CGI_SETROOTDIR)
- DX:SI
- Pointer to the name of new root directory
Return Value
- DX =0 success AX: 0
DX!=0 failure AX: error code CGI_INVALID_DIR
Comments
- The string at [DX:SI] is null terminated with a maximum
length of 64 characters (not counting the terminating zero).
The root directory is also configurable at the chip.ini file, see
ROOTDIR and
DRIVE.
Related Topics
-
- CGI_GETROOTDIR API Function
-
- CGI API Error Codes
Supported since or modified in @CHIP-RTOS version-
SC12 | SC13 | SC11 | SC1x3 | SC2x |
-
V1.00 | V1.00 | V1.00 | V0.90 | V1.00 |
Top of list Index page
Interrupt 0xAB service 0x05:
CGI_GETROOTDIR, Get Web server's root directory
Parameters
- AH
- 0x05 (= CGI_GETROOTDIR)
Return Value
- DX=0 AX=0 , ES:DI contains pointer to root directory name
Comments
- The string referenced by [ES:DI] is null terminated and is in the
RTOS's data space.
Related Topics
-
- CGI_SETROOTDIR API Function
Supported since or modified in @CHIP-RTOS version-
SC12 | SC13 | SC11 | SC1x3 | SC2x |
-
V1.00 | V1.00 | V1.00 | V0.90 | V1.00 |
Top of list Index page
Interrupt 0xAB service 0x06:
CGI_GETMAIN, Get main page name
Parameters
- AH
- 0x06 (= CGI_GETMAIN)
Return Value
- DX=0 AX=0 , ES:DI contains pointer to current main page name
Comments
- The string referenced by [ES:DI] is null terminated and is in the
RTOS's data space.
Related Topics
-
- CGI_SETMAIN API Function
Supported since or modified in @CHIP-RTOS version-
SC12 | SC13 | SC11 | SC1x3 | SC2x |
-
V1.00 | V1.00 | V1.00 | V0.90 | V1.00 |
Top of list Index page
Interrupt 0xAB service 0x07:
CGI_GETFORMITEM, Split a form item into name and value
- Parse the argument buffer to obtain name and value.
Parameters
- AH
- 0x07 (= CGI_GETFORMITEM)
- BX:SI
- Pointer to argument buffer to be parsed.
- ES:DI
- Pointer to a FormItem
type structure
Return Value
- DX=0 AX=0, User buffers referenced by pointers in
FormItem structure at [ES:DI] are filled in
with name and value
Comments
- On initial call, the argument buffer pointer provided by the caller
in BX:SI is a copy of the fArgumentBufferPtr member of
the rbCgi
structure passed by the
Web server to the CGI callback function. On subsequent calls
to pick up additional form items, the pointer returned from the
CGI_FINDNEXTITEM API call can be used here.
The caller must set the two members of the FormItem
structure prior to
calling here. Both pointers reference buffers allocated by the
user, which will receive strings produced by this API call.
SC1x Comments- Method "GET":
For preventing internal buffer overruns, the user should provide 64 bytes
of buffer addressed by FormItem.NamePtr
and 256 bytes pointed by FormItem.ValuePtr.
The max. size for a full pathname (pagename+complete argumentbuffer)
e.g. "example?Name1=Value1&Name2=Value2" is 256 bytes.
Because of this behaviour, the storage addressed by FormItem.ValuePtr
must have the max. size of a full pathname (256 bytes).
See example submit.c.
Method "POST":
The size of the argument working buffer is configurable with the
chip.ini setting POST_SIZE.
Default value is 768 bytes.
For preventing internal buffer overruns, the user should provide 64 bytes
of buffer addressed by FormItem.NamePtr
and "POST_SIZE" bytes pointed by FormItem.ValuePtr.
The storage addressed by FormItem.ValuePtr
must have the max. possible size "POST_SIZE".
See example submitp.c.
SC1x3/SC2x Comments- Method "GET" and "POST":
The max. length of the whole http header is configurable with the
chip.ini setting HEADER_SIZE.
For preventing internal buffer overruns, the user should provide 64 bytes
of buffer addressed by FormItem.NamePtr
and "HEADER_SIZE" bytes pointed by FormItem.ValuePtr.
The storage addressed by FormItem.ValuePtr
must have the max. size "HEADER_SIZE".
See example submitp.c.
Related Topics
-
- CGI_FINDNEXTITEM API Function
Supported since or modified in @CHIP-RTOS version-
SC12 | SC13 | SC11 | SC1x3 | SC2x |
-
V1.20 | V1.20 | V1.20 | V1.05 | V1.00 |
Top of list Index page
Interrupt 0xAB service 0x08:
CGI_FINDNEXTITEM, Return the address of the next form item
- Most forms have more than one item, this function searches for
the next form item in a CGI request argument string. This function can
only be used after a CGIFORMITEM API call.
(See example submit2.c)
Parameters
- AH
- 0x08 (= CGI_FINDNEXTITEM)
- BX:SI
- CGI request argument pointer
Return Value
- DX=0 AX=0, ES:DI: pointer to the found item
DX=-1 AX=0, no next item was found
Comments
- The CGI request argument buffer pointer provided by the caller in BX:SI is
initially taken from the rbCgi structure passed by the Web
server to the CGI callback function.
This function scans the buffer at [BX:SI] for an ampersand character, '&',
and if found returns a pointer to the character in the string following
the ampersand.
The strings must be null terminated.
Related Topics
-
- CGI_GETFORMITEM API Function
Supported since or modified in @CHIP-RTOS version-
SC12 | SC13 | SC11 | SC1x3 | SC2x |
-
V1.00 | V1.00 | V1.00 | V0.90 | V1.00 |
Top of list Index page
Interrupt 0xAB service 0x09:
CGI_INSTALL_PAS, Install a Turbo Pascal CGI procedure
- Special install function for Turbo Pascal CGI procedures
Parameters
- AH
- 0x09 (= CGI_INSTALL_PAS)
- DX:SI
- Pointer to a temporary CGI_Entry
type structure.
Return Value
- DX =0 success AX: 0
DX!=0 failure AX: contains error code
CGI_NO_FREE_ENTRY or CGI_INVALID_METHOD
Comments
- This API function makes a copy of the information in the
provided CGI_Entry structure, so your structure
at [DX:SI] need not be persistent.
Related Topics
-
- CGI_INSTALL API Function, for C CGI Procedures
Supported since or modified in @CHIP-RTOS version-
SC12 | SC13 | SC11 | SC1x3 | SC2x |
-
V1.00 | V1.00 | V1.00 | n/a | n/a |
Top of list Index page
Interrupt 0xAB service 0x0A:
CGI_ERR_FUNC, Install a user CGI function on specified HTTP errors
- This functions allows the installation of user CGI functions, if a HTTP error
occurs, e.g. HTTP 404 Not found. It is possible to install different CGI handlers.
Parameters
- AH
- 0x0A (= CGI_ERR_FUNC )
- BX
- Http errorstate
07: 401 Unauthorized
08: 404 Not found
10: 500 Server error (File system error)
22: 503 Service not available (Out of memory)
- ES:DI
- CGI Function pointer
Return Value
- DX=0 AX=0, success
DX=-1 AX=-4, no space left at internal CGI error handler table
Comments
- The CGI function must be implemented in the same way than any "normal CGI function",
installed with CGI_INSTALL.
For deleting an entry, install a null pointer (es=di=0).
Please note: Do not install for HTTP state 401 (authentication reqired)
a CGI function, which does a redirect to another file. This blocks
the input of the username and password by a browser.
Supported since or modified in @CHIP-RTOS version-
SC12 | SC13 | SC11 | SC1x3 | SC2x |
-
V1.11 | V1.01 | V1.01 | V1.12 | V1.00 |
Top of list Index page
Interrupt 0xAB service 0x0B:
CGI_MIME_INSTALL, Install a custom user MIME table
- This functions allows the installation of user specific MIME types.
Parameters
- AH
- 0x0B (= CGI_MIME_INSTALL )
- BX
- Number of entries in MIME table
- ES:DI
- Pointer to
MIME table
Return Value
- DX=0 AX=0, success
DX!=0, error
Comments
- The MIME table must be persistent. The RTOS does not make a copy.
Supported since or modified in @CHIP-RTOS version-
SC12 | SC13 | SC11 | SC1x3 | SC2x |
-
V1.20 | V1.20 | V1.20 | V1.05 | V1.00 |
Top of list Index page
Interrupt 0xAB service 0x0C:
CGI_MIME_REMOVE, Remove the custom user MIME table
- This functions allows the deinstallation of user specific MIME types.
Parameters
- AH
- 0x0C (= CGI_MIME_REMOVE )
Return Value
- DX=0 AX=0, success
DX!=0, error
Supported since or modified in @CHIP-RTOS version-
SC12 | SC13 | SC11 | SC1x3 | SC2x |
-
V1.20 | V1.20 | V1.20 | V1.05 | V1.00 |
Top of list Index page
Interrupt 0xAB service 0x0D:
CGI_CONTENT_ENCODING_INSTALL, Install a user content encoding table
- This functions allows the installation of user specific
content-encoding types.
Parameters
- AH
- 0x0D (= CGI_CONTENT_ENCODING_INSTALL )
- BX
- Number of entries in content-encoding
table (must be equal to the user custom
mime table size).
- ES:DI
- Pointer to
ContentEncoding table
Return Value
- DX=0 AX=0, success
DX!=0, error
Comments
- The content encoding table references to the custom MIME table.
So the content encoding table assigns every mime type defined
in the MIME table a correspondent content encoding type.
To remove an installed content-encoding table use in register BX
the value 0.
The content encoding table must be persistent. The RTOS does not make a copy.
Related Topics
-
- CGI_MIME_INSTALL API Function, to install a custom user MIME table
Supported since or modified in @CHIP-RTOS version-
SC12 | SC13 | SC11 | SC1x3 | SC2x |
-
n/a | n/a | n/a | V1.16 | V1.00 |
Top of list Index page
Interrupt 0xAB service 0x0E:
CGI_SETMAIN_POST, Set a new main page (POST method)
Parameters
- AH
- 0x0E (= CGI_SETMAIN_POST)
- DX:SI
- Pointer to name of new main page
Return Value
- DX =0 success AX: 0
DX!=0 failure AX: error code CGI_INVALID_NAME
Comments
- The string at [DX:SI] is null terminated with a maximum
length of 64 characters (not counting the terminating zero).
Related Topics
-
- CGI_GETMAIN_POST API Function
-
- CGI API Error Codes
Supported since or modified in @CHIP-RTOS version-
SC12 | SC13 | SC11 | SC1x3 | SC2x |
-
V1.25 | V1.25 | V1.25 | V1.20 | V1.20 |
Top of list Index page
Interrupt 0xAB service 0x0F:
CGI_GETMAIN_POST, Get main page name (POST method)
Parameters
- AH
- 0x0F (= CGI_GETMAIN_POST)
Return Value
- DX=0 AX=0 , ES:DI contains pointer to current main page name
Comments
- The string referenced by [ES:DI] is null terminated and is in the
RTOS's data space.
Related Topics
-
- CGI_SETMAIN_POST API Function
Supported since or modified in @CHIP-RTOS version-
SC12 | SC13 | SC11 | SC1x3 | SC2x |
-
V1.25 | V1.25 | V1.25 | V1.20 | V1.20 |
Top of list Index page
Interrupt 0xAB service 0x10:
CGI_SETROOTDRIVE, Set Web server's root directory
Parameters
- AH
- 0x10 (= CGI_SETROOTDRIVE)
- DX
- New root drive (00h = A:, 01h = B:, etc)
Return Value
- DX =0 success AX: 0
DX!=0 failure AX: error code CGI_INVALID_DIR
Comments
- The root drive is also configurable at the chip.ini file, see
ROOTDIR and
DRIVE.
Related Topics
-
- CGI_GETROOTDRIVE API Function
-
- CGI API Error Codes
Supported since or modified in @CHIP-RTOS version-
SC12 | SC13 | SC11 | SC1x3 | SC2x |
-
V1.26 | V1.26 | V1.26 | V1.21 | V1.21 |
Top of list Index page
Interrupt 0xAB service 0x11:
CGI_GETROOTDRIVE, Get Web server's root directory
Parameters
- AH
- 0x11 (= CGI_GETROOTDRIVE)
Return Value
- AX=0 , DX contains the root drive (00h = A:, 01h = B:, etc)
Comments
- The value in DX contains the webservers root drive (00h = A:, 01h = B:, etc)
Related Topics
-
- CGI_SETROOTDRIVE API Function
Supported since or modified in @CHIP-RTOS version-
SC12 | SC13 | SC11 | SC1x3 | SC2x |
-
V1.26 | V1.26 | V1.26 | V1.21 | V1.21 |
Top of list Index page
Interrupt 0xAB service 0x12:
CGI_ENABLEUPLOAD, Enable/Disable Web server's file upload
Parameters
- AH
- 0x12 (= CGI_ENABLEUPLOAD)
- DX
- Enable or disable (0 = disable, 1 = enable)
Return Value
- DX =0 success AX: 0
Supported since or modified in @CHIP-RTOS version-
SC12 | SC13 | SC11 | SC1x3 | SC2x |
-
n/a | n/a | n/a | V1.30 | V1.30 |
Top of list Index page
Interrupt 0xAB service 0x13:
CGI_UPLOAD_FUNC, Install a user CGI function on HTTP upload requests
- This functions allows the installation of user CGI functions, that will be
called when a file upload was performed.
Parameters
- AH
- 0x13 (= CGI_UPLOAD_FUNC )
- ES:DI
- CGI Function pointer
Return Value
- DX=0 AX=0, success
DX=-1 AX=-4, no space left at internal CGI error handler table
Comments
- The CGI function must be implemented in the same way than any "normal CGI function",
installed with CGI_INSTALL. The name and
path of the uploaded file is stored in the CgiRequests fPathPtr element.
For deleting an entry, install a null pointer (es=di=0).
Supported since or modified in @CHIP-RTOS version-
SC12 | SC13 | SC11 | SC1x3 | SC2x |
-
n/a | n/a | n/a | V1.30 | V1.30 |
Top of list Index page
Interrupt 0xAB service 0x81:
SSI_SET_FILE_FILTER, Set SSI file filter
- Set Server Side Include (SSI) file filter
Parameters
- AH
- 0x81 (= SSI_SET_FILE_FILTER)
- ES:DI
- Pointer to null-terminated string
depending on the machted type
- BX
- Match type, possible values are:
SSI_MATCH_FILE_NAME(0x01) = File name, Example: "table.htm"
SSI_MATCH_FILE_EXT (0x02) = File extension, Example: "htm"
SSI_MATCH_FILE_PATH(0x03) = Full path to file, Example: "/web/ssi/table.htm"
SSI_MATCH_DIR_NAME (0x04) = Directory name, Example: "ssi"
SSI_MATCH_DIR_PATH (0x05) = Directory path, Example: "/web/ssi"
- CX
- 0 = register for HTTP server
1 = register for HTTPS (SSL) server
Return Value
- DX =0 success AX: 0
DX=-1 failure AX: contains error code CGI_INVALID_METHOD
Comments
- SSI commands are special HTML comment tags in web pages, and parsed
by the web server while the pages are being served. They allow
dynamically generated content to be inserted into a static page,
without having to dynamically generate the whole page.
There's no official standard for SSI command. Thus we provide an API
to register a SSI tag string and a handler function. When a registered
SSI tag is found in a page being served, the handler function will be
called to process it.
Related Topics
-
- SSI_REGISTER_TAG API Function, to register a SSI tag
Supported since or modified in @CHIP-RTOS version-
SC12 | SC13 | SC11 | SC1x3 | SC2x |
-
n/a | n/a | n/a | V0.91 | V1.00 |
Top of list Index page
Interrupt 0xAB service 0x82:
SSI_REGISTER_TAG, Register a SSI tag string
- Register Server Side Include (SSI) tag string
Parameters
- AH
- 0x82 (= SSI_REGISTER_TAG)
- ES:DI
- Tag string, Pointer to null-terminated string
- BX:SI
- user callback function for this tag.
Callback function prototype:
typedef
int huge (far *SSI_Handler) (unsigned long conhandle, const char far * tagPtr);
Possible callback function return values:
SSI_OUTPUT_ENABLE(0x00) = Enable web server to output static content
SSI_OUTPUT_DISABLE(0x01) = Disable web server to output static content
SSI_ABORT_PAGE(0x02) = Stop processing the current file
other = The web server will send an error message and stop serving the HTTP request - CX
- 0 = register for HTTP server
1 = register for HTTPS (SSL) server
Return Value
- DX =0 success AX: 0
DX=-1 failure AX: contains error code CGI_INVALID_METHOD or
CGI_NO_FREE_ENTRY
Related Topics
-
- SSI_SET_FILE_FILTER API Function, to set a SSI file filter
-
- SSI_SEND_BUFFER API Function, to send a buffer
Supported since or modified in @CHIP-RTOS version-
SC12 | SC13 | SC11 | SC1x3 | SC2x |
-
n/a | n/a | n/a | V0.91 | V1.00 |
Top of list Index page
Interrupt 0xAB service 0x83:
SSI_SET_TAG_LEN, Set the maximum SSI tag length
- Set maximum length of Server Side Include (SSI) tag string
Parameters
- AH
- 0x83 (= SSI_SET_TAG_LEN)
- BX
- length in bytes (default is 90)
Return Value
- DX =0 success AX: 0
DX=-1 failure AX: contains error code CGI_INVALID_METHOD
Comments
- Smaller values will optimize the performance of the SSI parser.
Related Topics
-
- SSI_REGISTER_TAG API Function, to register a SSI tag
-
- SSI_SET_FILE_FILTER API Function, to set a SSI file filter
Supported since or modified in @CHIP-RTOS version-
SC12 | SC13 | SC11 | SC1x3 | SC2x |
-
n/a | n/a | n/a | V0.91 | V1.00 |
Top of list Index page
Interrupt 0xAB service 0x84:
SSI_SEND_BUFFER, Transmit a user buffer
- Transmit a user buffer to the HTTP client through the HTTP connection
Parameters
- AH
- 0x84 (= SSI_SEND_BUFFER)
- ES:DI
- pointer to user buffer
- BX:SI
- connection handle (32 bit value)
- CX
- buffer length in bytes, max. 32767
- DX
- flag, set to 1
Return Value
- DX =0 success AX: 0
DX=-1 failure AX: contains error code
Comments
- Use this function in the SSI_Handler callback function to replace
SSI tags with dynamically generated data.
Related Topics
-
- SSI_REGISTER_TAG API Function, to register a SSI tag
-
- SSI_SET_FILE_FILTER API Function, to set a SSI file filter
Supported since or modified in @CHIP-RTOS version-
SC12 | SC13 | SC11 | SC1x3 | SC2x |
-
n/a | n/a | n/a | V0.91 | V1.00 |
Top of list Index page
Interrupt 0xAB service 0x85:
SSI_DEREGISTER_TAG, Deregister a SSI tag string and handler
- Deregister Server Side Include (SSI) tag string and handler
Parameters
- AH
- 0x85 (= SSI_DEREGISTER_TAG)
- BX:SI
- user callback function for this tag.
- CX
- 0 = deregister for HTTP server
1 = deregister for HTTPS (SSL) server
Return Value
- DX =0 success AX: 0
DX=-1 failure AX: contains error code CGI_INVALID_METHOD
Related Topics
-
- SSI_SET_FILE_FILTER API Function, to set a SSI file filter
-
- SSI_REGISTER_TAG API Function, to register a tag
Supported since or modified in @CHIP-RTOS version-
SC12 | SC13 | SC11 | SC1x3 | SC2x |
-
n/a | n/a | n/a | V1.21 | V1.21 |
Top of list Index page
Interrupt 0xAB service 0x86:
SSI_GET_CONN_PARAMS, Get SSI connection parameters
- Get SSI connection parameters. This function can be called inside
SSI handlers to retrieve some connection parameters.
Parameters
- AH
- 0x86 (= SSI_GET_CONN_PARAMS)
- BX:SI
- connection handle (32 bit value)
- ES:DI
- Pointer to
SSI_Params
structure, that will be filled with information.
Set the structVersion
member to zero before calling this function.
Return Value
- DX =0 success AX: 0
DX=-1 failure AX: contains error code CGI_INVALID_METHOD
Related Topics
-
- SSI_SET_FILE_FILTER API Function, to set a SSI file filter
-
- SSI_REGISTER_TAG API Function, to register a tag
Supported since or modified in @CHIP-RTOS version-
SC12 | SC13 | SC11 | SC1x3 | SC2x |
-
n/a | n/a | n/a | V1.24 | V1.24 |
Top of list Index page
End of document
|