The HTTP resource manager, or HttpResMgr for short, is a Web File Manager. The HttpResMgr was initially used in the FuguHub consumer product, but has now been replaced by a Lua version. The HttpResMgr is delivered as a free product for the Barracuda Embedded Web Server. The product can be used as is or be customized for various purposes. See the Web File Manager Readme file for an introduction to the HttpResMgr's capabilities.
The purpose of this tutorial is:
Limitations in this example:
The Web File Manager shows a "Play All" button when visiting directories with MP3 files. The "Play All" button does not work in this example, however, the inline MP3 player works.
The Play All button requires the Lua enhanced HttpResMgr version, but this example does not include (activate) the LSP plugin.
The HttpResMgr is designed such that it can be enhanced by Lua code. The Lua file "WebResources\rtl\.lua\wfm.lua" implements the functionality needed by the "play all" button.
In Lua, a standard HttpResMgr is created by calling ba.create.resmgr(..) and the enhanced version is created by calling: ba.create.wfm(...)
The Lua object returned by ba.create.wfm(...) does the following when the Play All button is pressed: scans the directory, extracts the MP3 tags, and generates an XML file, which is sent to the client.
The third party media player, implemented in Flash, requires a license if used in a commercial application.
The Barracuda Virtual File System's (VFS) building blocks are the HttpDir and HttpPage classes. This example shows how to extend the default HttpDir implementation. The HttpResMgr extends the default HttpDir implementation.
The default implementation for HttpDir is to search for subdirectories in the VFS. The directory node delegates the request to the sub-node if the directory is found. This continues down into sub-nodes until a HttpPage is found or an extended HttpDir implementation traps the request. The HttpResMgr extends the HttpDir class and allows a client to manage files on, for example, a file system.
As an example, assume we have the following virtual directory structure:
Let us assume that the server root directory and dir1 are standard HttpDir instances and that dir2 is a HttpResMgr instance. Assume a client sends the following URL: http://localhost/dir1/dir2/dir3/dir4/
The HttpResMgr does not know that it is working with a hard drive. The HttpResMgr is using functions in the IoIntf API when working with files. The HttpResMgr can work with anything that implements the IoIntf API, which can be a hard drive, a ZIP file, or, for example, a database.For example, the path 'dir3/dir4/' can be:
A standard Barracuda application assembles the VFS at startup. The examples assemble the file system in InstallVD.c or InstallVirtualDir.cpp for C++ applications.
As an example, you can create multiple HttpResMgr instances that are using the same IoIntf implementation. The same physical file can then be accessed from two different URL's. This example assembles a VFS that is using a HttpResRdr for read only access to files and a HttpResMgr for read and write access to files. The base url 'public' and 'private' point to the same resource on the hard drive.
As we mentioned above, the HttpResMgr can be used by browser and non-browser HTTP clients. The HttpResMgr API is explained in the online FuguHub API. We recommend that you study the API documentation as it will give you a better understanding of how the HttpResMgr class works.
The core of the HttpResMgr is the request service function. This function is called from the parent directory node when the parent directory node delegates the request to the HttpResMgr.
The HttpResMgr service function prototype:
An HttpDir service function is similar to an HttpPage service function, though an HttpPage is always a leaf node -- i.e., one resource. An HttpDir is a collection of one or several resources.
The relPath (relative path) argument is a relative path extracted from the client URL. From the above example, the path received is 'dir3/dir4/'
The service function extracts the client path/parameters/command and executes the request. Uploading data from the client to the server is per the HTTP specification, normally HTTP PUT. Browsers cannot use PUT, but can upload data using multipart POST if an HTML page contains a form with the enctype set to 'multipart/form-data'.
Some servers can be configured to accept multipart POST and upload files to a fixed location in the server's local storage by, for example, using a CGI script. The HttpResMgr class does not have this limitation. You can upload files to any subdirectory from the HttpResMgr's configured root directory. The HttpResMgr dynamically generates a HTML page as follows when the upload button is pressed in the file manager:
The "WebResources\rtl" directory contains code that is required by the HttpResMgr. The HttpResMgr C code generates HTML that includes jquery.js, wfm.js, and style.css. You must modify the HttpResMgr and remove the code that emits HTML code for referencing these three files if you do not plan on using the enhancements. A style sheet can be generated inline in the produced HTML.
The "play all" MP3 player is opened if the "play all" button is pressed. The MP3 player that opens when the "play all" button is pressed, does not work in this example since the example is not LSP enabled. The MP3 player requests a XML playlist from the Lua script: rtl/.lua/wfm.lua.
You can still play MP3 songs without this functionality. The embedded Web file Manager MP3 player does not require the wfm.lua script.
The Lua version of the Web file Manager embedded in the HttpResMgr class. See ba.create.wfs for more information.
The third party Flash media player requires a license if used in a commercial application.
SWFObject is an easy-to-use and standards-friendly method to embed Flash content.
The HttpResMgr style sheet.
A Flash file that makes it possible for the Web File Manager to copy the current URL to the computer's clipboard.
The search list is included as an iframe in search.html.
The photo album implementation.