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.1 2006/06/07 09:13:08 adam Exp $ 00034 */ 00035 00036 #include "httpd.h" 00037 #include "httpd-fs.h" 00038 #include "httpd-fsdata.h" 00039 00040 #ifndef NULL 00041 #define NULL 0 00042 #endif /* NULL */ 00043 00044 #include "httpd-fsdata.c" 00045 00046 #if HTTPD_FS_STATISTICS 00047 static u16_t count[HTTPD_FS_NUMFILES]; 00048 #endif /* HTTPD_FS_STATISTICS */ 00049 00050 /*-----------------------------------------------------------------------------------*/ 00051 static u8_t 00052 httpd_fs_strcmp(const char *str1, const char *str2) 00053 { 00054 u8_t i; 00055 i = 0; 00056 loop: 00057 00058 if(str2[i] == 0 || 00059 str1[i] == '\r' || 00060 str1[i] == '\n') { 00061 return 0; 00062 } 00063 00064 if(str1[i] != str2[i]) { 00065 return 1; 00066 } 00067 00068 00069 ++i; 00070 goto loop; 00071 } 00072 /*-----------------------------------------------------------------------------------*/ 00073 int 00074 httpd_fs_open(const char *name, struct httpd_fs_file *file) 00075 { 00076 #if HTTPD_FS_STATISTICS 00077 u16_t i = 0; 00078 #endif /* HTTPD_FS_STATISTICS */ 00079 struct httpd_fsdata_file_noconst *f; 00080 00081 for(f = (struct httpd_fsdata_file_noconst *)HTTPD_FS_ROOT; 00082 f != NULL; 00083 f = (struct httpd_fsdata_file_noconst *)f->next) { 00084 00085 if(httpd_fs_strcmp(name, f->name) == 0) { 00086 file->data = f->data; 00087 file->len = f->len; 00088 #if HTTPD_FS_STATISTICS 00089 ++count[i]; 00090 #endif /* HTTPD_FS_STATISTICS */ 00091 return 1; 00092 } 00093 #if HTTPD_FS_STATISTICS 00094 ++i; 00095 #endif /* HTTPD_FS_STATISTICS */ 00096 00097 } 00098 return 0; 00099 } 00100 /*-----------------------------------------------------------------------------------*/ 00101 void 00102 httpd_fs_init(void) 00103 { 00104 #if HTTPD_FS_STATISTICS 00105 u16_t i; 00106 for(i = 0; i < HTTPD_FS_NUMFILES; i++) { 00107 count[i] = 0; 00108 } 00109 #endif /* HTTPD_FS_STATISTICS */ 00110 } 00111 /*-----------------------------------------------------------------------------------*/ 00112 #if HTTPD_FS_STATISTICS 00113 u16_t httpd_fs_count 00114 (char *name) 00115 { 00116 struct httpd_fsdata_file_noconst *f; 00117 u16_t i; 00118 00119 i = 0; 00120 for(f = (struct httpd_fsdata_file_noconst *)HTTPD_FS_ROOT; 00121 f != NULL; 00122 f = (struct httpd_fsdata_file_noconst *)f->next) { 00123 00124 if(httpd_fs_strcmp(name, f->name) == 0) { 00125 return count[i]; 00126 } 00127 ++i; 00128 } 00129 return 0; 00130 } 00131 #endif /* HTTPD_FS_STATISTICS */ 00132 /*-----------------------------------------------------------------------------------*/