adamdunkels | 3023dee | 2003-07-04 10:54:51 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2001, Swedish Institute of Computer Science. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * 3. All advertising materials mentioning features or use of this software |
| 14 | * must display the following acknowledgement: |
| 15 | * This product includes software developed by the Swedish Institute |
| 16 | * of Computer Science and its contributors. |
| 17 | * 4. Neither the name of the Institute nor the names of its contributors |
| 18 | * may be used to endorse or promote products derived from this software |
| 19 | * without specific prior written permission. |
| 20 | * |
| 21 | * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND |
| 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE |
| 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 31 | * SUCH DAMAGE. |
| 32 | * |
| 33 | * This file is part of the lwIP TCP/IP stack. |
| 34 | * |
| 35 | * Author: Adam Dunkels <adam@sics.se> |
| 36 | * |
adamdunkels | c50bf8d | 2004-08-09 22:19:35 +0000 | [diff] [blame] | 37 | * $Id: httpd-fs.c,v 1.2 2004/08/09 22:19:35 adamdunkels Exp $ |
adamdunkels | 3023dee | 2003-07-04 10:54:51 +0000 | [diff] [blame] | 38 | */ |
| 39 | |
| 40 | #define HTTPD_FS_STATISTICS 1 |
| 41 | |
| 42 | #include "uip.h" |
| 43 | #include "httpd.h" |
| 44 | #include "httpd-fs.h" |
| 45 | #include "httpd-fsdata.h" |
| 46 | |
| 47 | #include <avr/pgmspace.h> |
| 48 | |
| 49 | #include "httpd-fsdata.c" |
| 50 | |
| 51 | #if HTTPD_FS_STATISTICS |
adamdunkels | c50bf8d | 2004-08-09 22:19:35 +0000 | [diff] [blame] | 52 | static unsigned long count[HTTPD_FS_NUMFILES]; |
adamdunkels | 3023dee | 2003-07-04 10:54:51 +0000 | [diff] [blame] | 53 | #endif /* HTTPD_FS_STATISTICS */ |
| 54 | |
| 55 | /*-----------------------------------------------------------------------------------*/ |
| 56 | static u8_t |
| 57 | httpd_fs_strcmp(const char *str1, prog_char *str2p) |
| 58 | { |
| 59 | char str2[40]; |
| 60 | u8_t i; |
| 61 | i = 0; |
| 62 | |
| 63 | memcpy_P(str2, str2p, sizeof(str2) - 1); |
| 64 | str2[39] = 0; |
| 65 | loop: |
| 66 | |
| 67 | if(str2[i] == 0 || |
| 68 | str1[i] == '\r' || |
| 69 | str1[i] == '\n') { |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | if(str1[i] != str2[i]) { |
| 74 | return 1; |
| 75 | } |
| 76 | |
| 77 | |
| 78 | ++i; |
| 79 | goto loop; |
| 80 | } |
| 81 | /*-----------------------------------------------------------------------------------*/ |
| 82 | int |
| 83 | httpd_fs_open(const char *name, struct httpd_fs_file *file) |
| 84 | { |
| 85 | #if HTTPD_FS_STATISTICS |
| 86 | u16_t i = 0; |
| 87 | #endif /* HTTPD_FS_STATISTICS */ |
| 88 | struct httpd_fsdata_file_noconst *f; |
| 89 | |
| 90 | for(f = (struct httpd_fsdata_file_noconst *)HTTPD_FS_ROOT; |
| 91 | f != NULL; |
| 92 | f = (struct httpd_fsdata_file_noconst *)f->next) { |
| 93 | |
| 94 | if(httpd_fs_strcmp(name, f->name) == 0) { |
| 95 | file->data = f->data; |
| 96 | file->len = f->len; |
| 97 | #if HTTPD_FS_STATISTICS |
| 98 | ++(count[i]); |
| 99 | #endif /* HTTPD_FS_STATISTICS */ |
| 100 | return 1; |
| 101 | } |
| 102 | #if HTTPD_FS_STATISTICS |
| 103 | ++i; |
| 104 | #endif /* HTTPD_FS_STATISTICS */ |
| 105 | |
| 106 | } |
| 107 | return 0; |
| 108 | } |
| 109 | /*-----------------------------------------------------------------------------------*/ |
| 110 | void |
| 111 | httpd_fs_init(void) |
| 112 | { |
| 113 | #if HTTPD_FS_STATISTICS |
| 114 | u16_t i; |
| 115 | for(i = 0; i < HTTPD_FS_NUMFILES; i++) { |
| 116 | count[i] = 0; |
| 117 | } |
| 118 | #endif /* HTTPD_FS_STATISTICS */ |
| 119 | } |
| 120 | /*-----------------------------------------------------------------------------------*/ |
| 121 | #if HTTPD_FS_STATISTICS |
adamdunkels | c50bf8d | 2004-08-09 22:19:35 +0000 | [diff] [blame] | 122 | unsigned long httpd_fs_count |
adamdunkels | 3023dee | 2003-07-04 10:54:51 +0000 | [diff] [blame] | 123 | (char *name) |
| 124 | { |
| 125 | struct httpd_fsdata_file_noconst *f; |
| 126 | u16_t i; |
| 127 | |
| 128 | i = 0; |
| 129 | for(f = (struct httpd_fsdata_file_noconst *)HTTPD_FS_ROOT; |
| 130 | f != NULL; |
| 131 | f = (struct httpd_fsdata_file_noconst *)f->next) { |
| 132 | |
| 133 | if(httpd_fs_strcmp(name, f->name) == 0) { |
| 134 | return count[i]; |
| 135 | } |
| 136 | ++i; |
| 137 | } |
| 138 | return 0; |
| 139 | } |
adamdunkels | c50bf8d | 2004-08-09 22:19:35 +0000 | [diff] [blame] | 140 | static unsigned long total; |
| 141 | unsigned long |
adamdunkels | 3023dee | 2003-07-04 10:54:51 +0000 | [diff] [blame] | 142 | httpd_fs_total(void) |
| 143 | { |
| 144 | return total; |
| 145 | } |
| 146 | void |
| 147 | httpd_fs_inc(void) |
| 148 | { |
| 149 | ++total; |
| 150 | } |
| 151 | #endif /* HTTPD_FS_STATISTICS */ |
| 152 | /*-----------------------------------------------------------------------------------*/ |