httpd-fs.c
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #include "contiki-net.h"
00037 #include "httpd.h"
00038 #include "httpd-fs.h"
00039 #include "httpd-fsdata.h"
00040 #include "httpd-fsdata.c"
00041
00042 #if HTTPD_FS_STATISTICS==2
00043 u16_t httpd_filecount[HTTPD_FS_NUMFILES];
00044 #endif
00045
00046
00047 void *
00048 httpd_fs_get_root()
00049 {
00050 return (void *)HTTPD_FS_ROOT;
00051 }
00052
00053 u16_t
00054 httpd_fs_get_size()
00055 {
00056 return HTTPD_FS_SIZE;
00057 }
00058
00059
00060 u16_t
00061 httpd_fs_open(const char *name, struct httpd_fs_file *file)
00062 {
00063 #if HTTPD_FS_STATISTICS
00064 u16_t i = 0;
00065 #endif
00066 struct httpd_fsdata_file_noconst *f,fram;
00067
00068 for(f = (struct httpd_fsdata_file_noconst *)HTTPD_FS_ROOT;
00069 f != NULL;
00070 f = (struct httpd_fsdata_file_noconst *)fram.next) {
00071
00072
00073 httpd_memcpy(&fram,f,sizeof(fram));
00074
00075
00076 if(httpd_fs_strcmp((char *)name, fram.name) == 0) {
00077 if (file) {
00078 file->data = fram.data;
00079 file->len = fram.len;
00080 #if HTTPD_FS_STATISTICS==1 //increment count in linked list field if it is in RAM
00081 f->count++;
00082 }
00083 return f->count;
00084 }
00085 ++i
00086 #elif HTTPD_FS_STATISTICS==2 //increment count in RAM array when linked list is in flash
00087 ++httpd_filecount[i];
00088 }
00089 return httpd_filecount[i];
00090 }
00091 ++i;
00092 #else //no file statistics
00093 }
00094 return 1;
00095 }
00096 #endif
00097 }
00098 return 0;
00099
00100 }
00101
00102 void
00103 httpd_fs_init(void)
00104 {
00105 #if HTTPD_FS_STATISTICS && 0 //count will already be zero at boot
00106 u16_t i;
00107 for(i = 0; i < HTTPD_FS_NUMFILES; i++) {
00108 count[i] = 0;
00109 }
00110 #endif
00111 }
00112
00113 #if HTTPD_FS_STATISTICS && 0 //Not needed, httpd_fs_open returns count
00114 u16_t
00115 httpd_fs_count(char *name)
00116 {
00117 struct httpd_fsdata_file_noconst *f,fram;
00118 u16_t i;
00119
00120 i = 0;
00121 for(f = (struct httpd_fsdata_file_noconst *)HTTPD_FS_ROOT;
00122 f != NULL;
00123 f = (struct httpd_fsdata_file_noconst *)fram.next) {
00124 httpd_memcpy(&fram,f,sizeof(fram));
00125 if(httpd_strcmp(name, fram.name) == 0) {
00126 #if HTTPD_FS_STATISTICS==1
00127 return f->count;
00128 #elif HTTPD_FS_STATISTICS==2
00129 return count[i];
00130 #endif
00131 }
00132 ++i;
00133 }
00134 return 0;
00135 }
00136 #endif
00137