David Fletcher / Mbed 2 deprecated CC3000WebServer

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers FlashDB.h Source File

FlashDB.h

00001 /*****************************************************************************
00002 *
00003 *  FlashDB.h
00004 *  Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
00005 *
00006 *  Redistribution and use in source and binary forms, with or without
00007 *  modification, are permitted provided that the following conditions
00008 *  are met:
00009 *
00010 *    Redistributions of source code must retain the above copyright
00011 *    notice, this list of conditions and the following disclaimer.
00012 *
00013 *    Redistributions in binary form must reproduce the above copyright
00014 *    notice, this list of conditions and the following disclaimer in the
00015 *    documentation and/or other materials provided with the   
00016 *    distribution.
00017 *
00018 *    Neither the name of Texas Instruments Incorporated nor the names of
00019 *    its contributors may be used to endorse or promote products derived
00020 *    from this software without specific prior written permission.
00021 *
00022 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00023 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
00024 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00025 *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
00026 *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
00027 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
00028 *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00029 *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00030 *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
00031 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
00032 *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00033 *
00034 *****************************************************************************/
00035 #ifndef _FLASH_DB_H_
00036 #define _FLASH_DB_H_
00037 
00038 #include "HttpString.h"
00039 
00040 
00041 
00042 /** 
00043  * @defgroup FlashDB Flash-storage database management
00044  * This module implements a database for static content, which is either stored on Flash or read-only memory of some kind.
00045  * The database is pre-compiled using external tools and is stored as a "flat file" in memory.
00046  * The contents of the database are:
00047  * - A list of content-type strings
00048  * - A sorted-list of static content entities. Each entity has:
00049  *   - URL Resource of the content (sort and lookup key)
00050  *   - Content type number (index into the list of content-types)
00051  *   - Content binary data
00052  *   - Additional metadata flags (Compressed, Requires-authentication)
00053  *
00054  * @{
00055  */
00056 
00057 /// Denotes gzip-compressed content
00058 #define FLASHDB_FLAG_COMPRESSED     (1 << 0)
00059 /// Denotes authentication required
00060 #define FLASHDB_FLAG_REQUIRE_AUTH   (1 << 1)
00061 
00062 /**
00063  * A structure to hold all data about content which was found in a database lookup
00064  */
00065 //#ifdef __CCS__
00066 //struct __attribute__ ((__packed__)) FlashDBContent
00067 //#elif __IAR_SYSTEMS_ICC__
00068 //#pragma pack(1)
00069 struct FlashDBContent
00070 //#endif
00071 {
00072     /// Flags. See FLASHDB_FLAG_*
00073     uint16 uFlags;
00074     /// Index of content type entry for this resource, in the content type list
00075     uint16 uContentType;
00076     /// The content blob's pointer and length
00077     struct HttpBlob contentBlob;
00078 };
00079 
00080 /**
00081  * Initialize the flash database module
00082  * @param pDatabase Pointer to the beginning of the database in flash memory
00083  */
00084 void FlashDB_Init();
00085 
00086 /**
00087  * Find a content-type in the database
00088  * @param index The index of the content type in the database
00089  * @param[out] pResult Returns the string and its length
00090  * @return nonzero if successful. zero if index out of range.
00091  */
00092 int FlashDB_FindContentType(uint16 index, struct HttpBlob* pResult);
00093 
00094 /**
00095  * Lookup content in the database, given a resource identifier
00096  * @param pResource The resource as given in the HTTP request
00097  * @param[out] pResult Returns the content and its metadata
00098  * @return nonzero if successful. zero if such a resource was not found.
00099  */
00100 int FlashDB_FindContent(struct HttpBlob pResource, struct FlashDBContent* pResult);
00101 
00102 /// @}
00103 
00104 #endif // _FLASH_DB_H_
00105