Contiki 3.x
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  */
34 
35 #include "contiki-net.h"
36 #include "httpd.h"
37 #include "httpd-fs.h"
38 #include "httpd-fsdata.h"
39 #include "httpd-fsdata.c"
40 
41 #if HTTPD_FS_STATISTICS==2
42 uint16_t httpd_filecount[HTTPD_FS_NUMFILES];
43 #endif /* HTTPD_FS_STATISTICS */
44 
45 /*-----------------------------------------------------------------------------------*/
46 void *
47 httpd_fs_get_root()
48 {
49  return (void *)HTTPD_FS_ROOT;
50 }
51 /*-----------------------------------------------------------------------------------*/
52 uint16_t
53 httpd_fs_get_size()
54 {
55  return HTTPD_FS_SIZE;
56 }
57 /*-----------------------------------------------------------------------------------*/
58 
59 uint16_t
60 httpd_fs_open(const char *name, struct httpd_fs_file *file)
61 {
62 #if HTTPD_FS_STATISTICS
63  uint16_t i = 0;
64 #endif /* HTTPD_FS_STATISTICS */
65  struct httpd_fsdata_file_noconst *f,fram;
66 
67  for(f = (struct httpd_fsdata_file_noconst *)HTTPD_FS_ROOT;
68  f != NULL;
69  f = (struct httpd_fsdata_file_noconst *)fram.next) {
70 
71  /*Get the linked list entry into ram from wherever it is */
72  httpd_memcpy(&fram,f,sizeof(fram));
73 
74  /*Compare name passed in RAM with name in whatever flash the file is in */
75  if(httpd_fs_strcmp((char *)name, fram.name) == 0) {
76  if (file) {
77  file->data = fram.data;
78  file->len = fram.len;
79 #if HTTPD_FS_STATISTICS==1 //increment count in linked list field if it is in RAM
80  f->count++;
81  }
82  return f->count;
83  }
84  ++i
85 #elif HTTPD_FS_STATISTICS==2 //increment count in RAM array when linked list is in flash
86  ++httpd_filecount[i];
87  }
88  return httpd_filecount[i];
89  }
90  ++i;
91 #else //no file statistics
92  }
93  return 1;
94  }
95 #endif /*HTTPD_FS_STATISTICS*/
96  }
97  return 0;
98 
99 }
100 /*-----------------------------------------------------------------------------------*/
101 void
102 httpd_fs_init(void)
103 {
104 #if HTTPD_FS_STATISTICS && 0 //count will already be zero at boot
105  uint16_t i;
106  for(i = 0; i < HTTPD_FS_NUMFILES; i++) {
107  count[i] = 0;
108  }
109 #endif /* HTTPD_FS_STATISTICS */
110 }
111 /*-----------------------------------------------------------------------------------*/
112 #if HTTPD_FS_STATISTICS && 0 //Not needed, httpd_fs_open returns count
113 uint16_t
114 httpd_fs_count(char *name)
115 {
116  struct httpd_fsdata_file_noconst *f,fram;
117  uint16_t i;
118 
119  i = 0;
120  for(f = (struct httpd_fsdata_file_noconst *)HTTPD_FS_ROOT;
121  f != NULL;
122  f = (struct httpd_fsdata_file_noconst *)fram.next) {
123  httpd_memcpy(&fram,f,sizeof(fram));
124  if(httpd_strcmp(name, fram.name) == 0) {
125 #if HTTPD_FS_STATISTICS==1
126  return f->count;
127 #elif HTTPD_FS_STATISTICS==2
128  return count[i];
129 #endif
130  }
131  ++i;
132  }
133  return 0;
134 }
135 #endif /* HTTPD_FS_STATISTICS */
136 /*-----------------------------------------------------------------------------------*/
#define NULL
The null pointer.