Quantum Leaps - innovating embedded systems Quantum Leaps, LLC
info@state-machine.com
www.state-machine.com

About CGI Support

QP-lwIP

The HTTP server that comes with lwIP has been extended to support rudimentary Common Gateway Interface (CGI) facility. To enable the CGI support in the lwIP-HTTP server, you need to define the macro INCLUDE_HTTPD_CGI in the lwipopts.h header file. You must also provide the mapping between CGI requests (strings) and CGI callback functions and register this mapping by calling the http_set_cgi_handlers() function.

Application Note (1.4MB PDF)

The CGI implemented in the lwIP-HTTP works currently only with the GET method, which encodes all parameters within the URI rather than in a block following the request. Attempts to use the POST method will result in the request being ignored.

After receiving a CGI request, the lwIP-HTTP server will scan all registered requests (strings) and call the corresponding CGI callback function, if the match is found. The lwIP-HTTP server will also parse the CGI request parameters and will pass them to the CGI callback function. Currently the maximum number of CGI parameters cannot exceed 16, but you can re-define this limit by changing the macro MAX_CGI_PARAMS in the http.h header file.

Please refer to the Quantum Leaps Application Note: "QP and lwIP TCP/IP Stack" for more information. The Application Note in PDF is provided in the QP-lwIP example code.

CGI Example

The following form demonstrates sending commands to your embedded target via the lwIP-HTTP server. The form contains a text control, which allows you to type some text to be displayed on the screen in the target board. You send the command by pressing the Submit button. In response, the lwIP-HTTP server will execute the command in the target and will serve the thank_you.htm page.

CGI Example
  Screen text: