MityDSP Documentation Index

tcHttpd Class Reference

#include <lwip/httpd/httpd.h>

List of all members.

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)

Detailed Description

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.


Constructor & Destructor Documentation

tcHttpd::tcHttpd ( int  max_connects  ) 

This constructor creates the web server.

Parameters:
max_connects The maximum number of simultaneous HTTP connections which the server will allow.
Attention:
You may need to play with the max_connects value a bit to get your web server running well. A new TCP connection is created for each file that a page references when it is viewed. Therefore even if you expect only one web browser to access your web server at a time, it may require several TCP connections to download a page (i.e. an additional TCP connection for each image). Test this field using Internet Explorer rather than FireFox browser, because IE appears to be much less conservative in its use of socket resources.
Note:
The server will not start running until you call the function tcHttpd::run.

Member Function Documentation

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.

Parameters:
params The web server configuration parameters.
Returns:
-1 if error.
Note:
This function will not return unless an initialization error occurs. Initialization errors will be recorded in human readable format to the debugger trace log.
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.

Parameters:
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.
Returns:
0 if successful, -1 if error.
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.

Parameters:
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.
Returns:
0 if successful, -1 if error.

Example

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:

 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html><head></head>
 <body>
     <%login%><br><br>
     <form action="login.html" method="get">
     <fieldset>
     <input type="text" name="user" size="50" maxlength="10" value=""/>
     <input type="submit" name="submit" value="Login"/>
     </fieldset>
     </form>
 </body>
 </html>

CGI function for <login%>:

 void cgi_login (tsHttpConn *httpconn)
 {
     char value[20], str[100];

     if (httpconn->httpd->find_cgi_param (httpconn, "user", value, 20) != 0)
     { 
         strcpy (str, "Please login...");
     }
     else if (is_user_valid (value))
     { 
         sprintf (str, "Welcome %s !!!", value);
     }
     else
     {
         strcpy (str, "Invalid user name.");
     }
     httpconn->httpd->html_write (httpconn, str, strlen (str));
 }

  
Generated on Fri Sep 23 16:34:01 2011 for MityDSP Net by  Doxygen Version 1.6.1
Copyright © 2009, Critical Link LLC, All rights reserved.