HTTP Server

Modules

 Functions
 
 Definitions
 
 Data Structures
 

Detailed Description

The HTTP server displays web pages located in Flash Memory and/or RAM. To add HTTP-server support include httplib.h in your application and link http.lib to your project. The definition of web pages is similar to the FTP-server directory and file definition. To specify a page or GIF located in RAM, the content must be converted into a c-array and be included in main. Use program Makewebpage to recursively convert all html and image files within an entire subdirectory into a single file.

A simple

#include ".\webpage\webpage.c" // web page content

adds all web page contents to your project.
The generated file webpage.c contains two kinds of information for each web-element:

To make the generated web-elements accessible to the web-server, a list of all elements must be built and assigned to a user named "webserver". Example:

user_type user[] =
{
{"webserver", "*" , &uri1, &uri2, &uri3, &led1, &led2, &led3, EFS_TERMINATION},
EFS_TERMINATION
};

This user list must now be passed as argument to http_server_init() during initialization:

http_serv = http_server_init ( user, NULL, 0);

The interface between a HTTP request and the user reply is a user defined HTTP interpreter callback function. All HTTP requests cause a callback function call and the user is responsible to answer this request.

{
//**************************************************************************
// Execute specific method
//**************************************************************************
switch (http_server -> method)
{
case _HTTP_GET:
//******************************************************************
// the value of uri corresponds to the sequence of specified
// directories
// uri =
// 0 - INDEX_PAGE dir1
// 1 - SYNTAX_ERROR_MSG dir2
// 2 - NOT_FOUND_MSG dir3
// 3 - NOT_IMPLEMENTED_MSG dir4
// 4 - TEST_PAGE dir5
// -1 - page not found
//******************************************************************
//******************************************************************
// send the requested page
//******************************************************************
if ( http_send_user_page (http_server,
user,
http_server -> uri ) <= 0)
{
//**************************************************************
// uri not found: send user defined not-found-message
//**************************************************************
http_send_uri (http_server, &e404);
}
break;
case _HTTP_UNKNOWN : // unknown method
//******************************************************************
// method not implemented or syntax error
//******************************************************************
http_send_uri (http_server, &e501);
break;
}
//**************************************************************************
// back to http server
//**************************************************************************
}

To make a webpage dynamic, either change the content of a file e.g. by overwriting a place holder in a html page, or by changing the file itself:

static char ledon_gif[] = {..}
static char ledoff_gif[] = {..}
direntry_type led1 = {"led1" , "led1.gif" , sizeof(ledoff_gif) , FTP_RW | FTP_RAM, 'B', (uint32_t)ledoff_gif };
//**********************************************************************
// change file to ledoff.gif
//**********************************************************************
fsys_init_file (led1, (uint32_t)ledoff_gif, sizeof(ledoff_gif));
//**********************************************************************
// change file to ledon.gif
//**********************************************************************
fsys_init_file (led1, (uint32_t)ledon_gif, sizeof(ledon_gif));
See also
HTTPdynamic.c

Instead of calling fsys_init_file() the file parameters can be changed immediately:

static char ledon_gif[] = {..}
static char ledoff_gif[] = {..}
direntry_type led1 = {"led1" , "led1.gif" , sizeof(ledoff_gif) , FTP_RW | FTP_RAM, 'B', (uint32_t)ledoff_gif };
//**********************************************************************
// change file to ledon.gif
//**********************************************************************
led1.offset = (uint32_t)ledon_gif;
led1.size = sizeof(ledon_gif);
led1.max_offset = (uint32_t)ledon_gif + led1.size;
//**********************************************************************
// change file to ledoff.gif
//**********************************************************************
led1.offset = (uint32_t)ledoff_gif;
led1.size = sizeof(ledoff_gif);
led1.max_offset = (uint32_t)ledoff_gif + led1.size;
See also
HTTPjava.c

To reduce memory and to accelerate transmission gzip compressed files can be used. For this use a common file compression utility and gzip the desired file. The compressed file name must be identical to the original file name. Add the flag HTTP_GZIP to direntry_type::access to let the HTTP server generate the suitable compressed file header.

direntry_type e400 = {"e400.htm","e400.htm",sizeof(e400_htm), FTP_RW|FTP_RAM|HTTP_GZIP,'A',(uint32_t)e400_htm};

Example HTTPsimple.c uses compressed files. Website generation tool Makewebpage is called with parameter 'z' to set flag HTTP_GZIP for all files.

See also
HTTPsimple.c