Code Confidencebuild 3.0.0.201402161939

Internal Resources

When the server does not use a file system the user must be responsible to provide a C language callback function for each URL that will be requested by the client. This means locating the data and sending it out using either cyg_httpd_write() or cyg_httpd_write_chunked().

In order to simplify this process the server allows registering any number of URLs as internal resources, by providing the URL name, the pointer to the resource data and its size. When a URL is requested the server will look it up among all internal resources, and if found, it will send out the resource.

Internal resource can also be used along with a file system. In this case the file system is searched first, and if a file is found, it it sent. If a file is not found, the internal resources are searched and if a match if found it is sent.

The drawback of this approach is, of course, that all these resources are going to add to the size of the operating system image, and thus it should be used only when memory is not a major constraint of the design.

As always, to provide this type of customization, ecos tables are used. The format for adding a new resource to the internal table is the following:

CYG_HTTPD_IRES_TABLE_ENTRY(entry, name, buffp, len)

entry            : an identifier unique to this entry.
name             : name of the URL including leading '/'
buffp            : a pointer to a buffer of characters where to store the value
                   of the form variable.
len              : size of the array                   

As an example, if the user wants to provide his own web page by hardcoding it in the application code, here is how he would do it:

#define MY_OWN_HOME_PAGE "eCos RTOS"
CYG_HTTPD_IRES_TABLE_ENTRY(cyg_httpd_ires_home,       \
                           "/index.html",             \
                           MY_OWN_HOME_PAGE,          \
                           9);

The extension of the file name determines the MIME type to be used for internal resources.

When using directory listing you are implicitly making use of internal resources. The small icons that appear to the left of file names and directories are internal resources. Unchecking CYGOPT_NET_HTTP_USE_DIRLIST will prevent the addition of these files.

In order to use internal resources, a generic file must first be turned into a c language array, which is then compiled in the application code. To create this array you can use the tcl script that comes with the ecos distribution at packages/fs/rom/current/support/file2.tcl.