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