#include <lwip/httpd/httpd.h>
Public Member Functions | |
tcHttpd (int max_connects) | |
int | run (tsHttpdParams *params) |
void | html_write (tsHttpConn *httpconn, const void *str, int length) |
int | find_cgi_param (tsHttpConn *httpconn, const char *name, char *value, int maxlen) |
This class is the MityDSP web server. Your application will create one tcHttpd object to handle all of the HTTP requests received from web browsers.
tcHttpd::tcHttpd | ( | int | max_connects | ) |
This constructor creates the web server.
max_connects | The maximum number of simultaneous HTTP connections which the server will allow. |
int tcHttpd::run | ( | tsHttpdParams * | params | ) |
This function starts the web server. At this point the tsHttpdParams::user1 parameter, the tsHttpdParams::port parameter and the applications CGI function table (tsHttpdParams::cgi_table) are specified to the HTTPD object.
params | The web server configuration parameters. |
void tcHttpd::html_write | ( | tsHttpConn * | httpconn, |
const void * | str, | ||
int | length | ||
) |
This function incrementally builds up a web page in response to a GET from the web browser. When an application supplied CGI function is executed, it will enqueue its rendered HTML data into the web page being served by calling this function with the appropriate tsHttpConn pointer, a pointer to the string containing the HTML text and the length of that string.
httpconn | The web server connection which requested the page being rendered. |
str | The HTML text string to insert into the page. |
length | The length of the HTML text string. |
int tcHttpd::find_cgi_param | ( | tsHttpConn * | httpconn, |
const char * | name, | ||
char * | value, | ||
int | maxlen | ||
) |
This function will retrieve posted HTML form data from the last HTML query made to the specified connection. When an HTML form is created each form object has a name and a value. The name identifies the form object and the value identifies the user data entered into the object by the browser user.
To retrieve data submitted from a form you will call this function for each HTML form object. You set the name parameter to the name of the HTML form object that you want to retrieve the data from. If a match is found in the HTML query, the value string that you supply will be filled in. If there is no match, the function will return a non-zero value.
httpconn | The web server connection which requested the page being rendered. |
name | The name of the form object being retrieved. |
value | Pointer to the string buffer where you want the value stored. |
maxlen | The maximum string length that the value buffer will hold. |
Assume we have a user login form with an HTML text object named "user" which a visitor is prompted to enter their user name into. There is also a submit button to invoke the login. The form action points to a web page which references the following CGI function "cgi_login".
The first visit to this page the user will be prompted with "Please Login...", then when they enter a user name and hit submit, the page will refresh with either a welcome message or an invalid user message.
HTML Code for login.html:
CGI function for <login%>: