Contiki 2.6
|
00001 /* 00002 * Copyright (c) 2001, Swedish Institute of Computer Science. 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 3. Neither the name of the Institute nor the names of its contributors 00014 * may be used to endorse or promote products derived from this software 00015 * without specific prior written permission. 00016 * 00017 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 00018 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00019 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00020 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 00021 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00023 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00024 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00025 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00026 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00027 * SUCH DAMAGE. 00028 * 00029 * This file is part of the lwIP TCP/IP stack. 00030 * 00031 * Author: Adam Dunkels <adam@sics.se> 00032 * 00033 * $Id: httpd-fs.c,v 1.4 2009/07/24 15:41:52 dak664 Exp $ 00034 */ 00035 00036 #include "contiki-net.h" 00037 #include "httpd.h" 00038 #include "httpd-fs.h" 00039 #include "httpd-fsdata.h" 00040 #include "httpd-fsdata.c" 00041 00042 #if HTTPD_FS_STATISTICS==2 00043 uint16_t httpd_filecount[HTTPD_FS_NUMFILES]; 00044 #endif /* HTTPD_FS_STATISTICS */ 00045 00046 /*-----------------------------------------------------------------------------------*/ 00047 void * 00048 httpd_fs_get_root() 00049 { 00050 return (void *)HTTPD_FS_ROOT; 00051 } 00052 /*-----------------------------------------------------------------------------------*/ 00053 uint16_t 00054 httpd_fs_get_size() 00055 { 00056 return HTTPD_FS_SIZE; 00057 } 00058 /*-----------------------------------------------------------------------------------*/ 00059 00060 uint16_t 00061 httpd_fs_open(const char *name, struct httpd_fs_file *file) 00062 { 00063 #if HTTPD_FS_STATISTICS 00064 uint16_t i = 0; 00065 #endif /* HTTPD_FS_STATISTICS */ 00066 struct httpd_fsdata_file_noconst *f,fram; 00067 00068 for(f = (struct httpd_fsdata_file_noconst *)HTTPD_FS_ROOT; 00069 f != NULL; 00070 f = (struct httpd_fsdata_file_noconst *)fram.next) { 00071 00072 /*Get the linked list entry into ram from wherever it is */ 00073 httpd_memcpy(&fram,f,sizeof(fram)); 00074 00075 /*Compare name passed in RAM with name in whatever flash the file is in */ 00076 if(httpd_fs_strcmp((char *)name, fram.name) == 0) { 00077 if (file) { 00078 file->data = fram.data; 00079 file->len = fram.len; 00080 #if HTTPD_FS_STATISTICS==1 //increment count in linked list field if it is in RAM 00081 f->count++; 00082 } 00083 return f->count; 00084 } 00085 ++i 00086 #elif HTTPD_FS_STATISTICS==2 //increment count in RAM array when linked list is in flash 00087 ++httpd_filecount[i]; 00088 } 00089 return httpd_filecount[i]; 00090 } 00091 ++i; 00092 #else //no file statistics 00093 } 00094 return 1; 00095 } 00096 #endif /*HTTPD_FS_STATISTICS*/ 00097 } 00098 return 0; 00099 00100 } 00101 /*-----------------------------------------------------------------------------------*/ 00102 void 00103 httpd_fs_init(void) 00104 { 00105 #if HTTPD_FS_STATISTICS && 0 //count will already be zero at boot 00106 uint16_t i; 00107 for(i = 0; i < HTTPD_FS_NUMFILES; i++) { 00108 count[i] = 0; 00109 } 00110 #endif /* HTTPD_FS_STATISTICS */ 00111 } 00112 /*-----------------------------------------------------------------------------------*/ 00113 #if HTTPD_FS_STATISTICS && 0 //Not needed, httpd_fs_open returns count 00114 uint16_t 00115 httpd_fs_count(char *name) 00116 { 00117 struct httpd_fsdata_file_noconst *f,fram; 00118 uint16_t i; 00119 00120 i = 0; 00121 for(f = (struct httpd_fsdata_file_noconst *)HTTPD_FS_ROOT; 00122 f != NULL; 00123 f = (struct httpd_fsdata_file_noconst *)fram.next) { 00124 httpd_memcpy(&fram,f,sizeof(fram)); 00125 if(httpd_strcmp(name, fram.name) == 0) { 00126 #if HTTPD_FS_STATISTICS==1 00127 return f->count; 00128 #elif HTTPD_FS_STATISTICS==2 00129 return count[i]; 00130 #endif 00131 } 00132 ++i; 00133 } 00134 return 0; 00135 } 00136 #endif /* HTTPD_FS_STATISTICS */ 00137 /*-----------------------------------------------------------------------------------*/