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