Contiki 2.5
httpd-fs.c
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. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  * This file is part of the lwIP TCP/IP stack.
30  *
31  * Author: Adam Dunkels <adam@sics.se>
32  *
33  * $Id: httpd-fs.c,v 1.4 2009/07/24 15:41:52 dak664 Exp $
34  */
35 
36 #include "contiki-net.h"
37 #include "httpd.h"
38 #include "httpd-fs.h"
39 #include "httpd-fsdata.h"
40 #include "httpd-fsdata.c"
41 
42 #if HTTPD_FS_STATISTICS==2
43 u16_t httpd_filecount[HTTPD_FS_NUMFILES];
44 #endif /* HTTPD_FS_STATISTICS */
45 
46 /*-----------------------------------------------------------------------------------*/
47 void *
48 httpd_fs_get_root()
49 {
50  return (void *)HTTPD_FS_ROOT;
51 }
52 /*-----------------------------------------------------------------------------------*/
53 u16_t
54 httpd_fs_get_size()
55 {
56  return HTTPD_FS_SIZE;
57 }
58 /*-----------------------------------------------------------------------------------*/
59 
60 u16_t
61 httpd_fs_open(const char *name, struct httpd_fs_file *file)
62 {
63 #if HTTPD_FS_STATISTICS
64  u16_t i = 0;
65 #endif /* HTTPD_FS_STATISTICS */
66  struct httpd_fsdata_file_noconst *f,fram;
67 
68  for(f = (struct httpd_fsdata_file_noconst *)HTTPD_FS_ROOT;
69  f != NULL;
70  f = (struct httpd_fsdata_file_noconst *)fram.next) {
71 
72  /*Get the linked list entry into ram from wherever it is */
73  httpd_memcpy(&fram,f,sizeof(fram));
74 
75  /*Compare name passed in RAM with name in whatever flash the file is in */
76  if(httpd_fs_strcmp((char *)name, fram.name) == 0) {
77  if (file) {
78  file->data = fram.data;
79  file->len = fram.len;
80 #if HTTPD_FS_STATISTICS==1 //increment count in linked list field if it is in RAM
81  f->count++;
82  }
83  return f->count;
84  }
85  ++i
86 #elif HTTPD_FS_STATISTICS==2 //increment count in RAM array when linked list is in flash
87  ++httpd_filecount[i];
88  }
89  return httpd_filecount[i];
90  }
91  ++i;
92 #else //no file statistics
93  }
94  return 1;
95  }
96 #endif /*HTTPD_FS_STATISTICS*/
97  }
98  return 0;
99 
100 }
101 /*-----------------------------------------------------------------------------------*/
102 void
103 httpd_fs_init(void)
104 {
105 #if HTTPD_FS_STATISTICS && 0 //count will already be zero at boot
106  u16_t i;
107  for(i = 0; i < HTTPD_FS_NUMFILES; i++) {
108  count[i] = 0;
109  }
110 #endif /* HTTPD_FS_STATISTICS */
111 }
112 /*-----------------------------------------------------------------------------------*/
113 #if HTTPD_FS_STATISTICS && 0 //Not needed, httpd_fs_open returns count
114 u16_t
115 httpd_fs_count(char *name)
116 {
117  struct httpd_fsdata_file_noconst *f,fram;
118  u16_t i;
119 
120  i = 0;
121  for(f = (struct httpd_fsdata_file_noconst *)HTTPD_FS_ROOT;
122  f != NULL;
123  f = (struct httpd_fsdata_file_noconst *)fram.next) {
124  httpd_memcpy(&fram,f,sizeof(fram));
125  if(httpd_strcmp(name, fram.name) == 0) {
126 #if HTTPD_FS_STATISTICS==1
127  return f->count;
128 #elif HTTPD_FS_STATISTICS==2
129  return count[i];
130 #endif
131  }
132  ++i;
133  }
134  return 0;
135 }
136 #endif /* HTTPD_FS_STATISTICS */
137 /*-----------------------------------------------------------------------------------*/