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