1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
41
42
43
44
53
54
55
56
57
58
59
60
61
64
65
66
71
72
73
74
75
76
77
78
79
80
81
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
103
104
105
106
107
108
109
110
111
113
114
116
117
118
119
122
123
125
126
127
128
129
130
131
132
133
134
135
136
137
140
141
142
143
144
145
146
147
148
149
169
170
171
/* ... */
#include "lwip/apps/httpd_opts.h"
#include "lwip/def.h"
#include "lwip/apps/fs.h"
#include <string.h>
#include HTTPD_FSDATA_FILE
5 includes
#if LWIP_HTTPD_CUSTOM_FILES
int fs_open_custom(struct fs_file *file, const char *name);
void fs_close_custom(struct fs_file *file);
#if LWIP_HTTPD_FS_ASYNC_READ
u8_t fs_canread_custom(struct fs_file *file);
u8_t fs_wait_read_custom(struct fs_file *file, fs_wait_cb callback_fn, void *callback_arg);
int fs_read_async_custom(struct fs_file *file, char *buffer, int count, fs_wait_cb callback_fn, void *callback_arg);/* ... */
#else
int fs_read_custom(struct fs_file *file, char *buffer, int count);
#endif /* ... */
#endif
err_t
fs_open(struct fs_file *file, const char *name)
{
const struct fsdata_file *f;
if ((file == NULL) || (name == NULL)) {
return ERR_ARG;
}if ((file == NULL) || (name == NULL)) { ... }
#if LWIP_HTTPD_CUSTOM_FILES
if (fs_open_custom(file, name)) {
file->is_custom_file = 1;
return ERR_OK;
}if (fs_open_custom(file, name)) { ... }
file->is_custom_file = 0;/* ... */
#endif
for (f = FS_ROOT; f != NULL; f = f->next) {
if (!strcmp(name, (const char *)f->name)) {
file->data = (const char *)f->data;
file->len = f->len;
file->index = f->len;
file->pextension = NULL;
file->flags = f->flags;
#if HTTPD_PRECALCULATED_CHECKSUM
file->chksum_count = f->chksum_count;
file->chksum = f->chksum;/* ... */
#endif
#if LWIP_HTTPD_FILE_STATE
file->state = fs_state_init(file, name);
#endif
return ERR_OK;
}if (!strcmp(name, (const char *)f->name)) { ... }
}for (f = FS_ROOT; f != NULL; f = f->next) { ... }
return ERR_VAL;
}{ ... }
void
fs_close(struct fs_file *file)
{
#if LWIP_HTTPD_CUSTOM_FILES
if (file->is_custom_file) {
fs_close_custom(file);
}if (file->is_custom_file) { ... }
/* ... */#endif
#if LWIP_HTTPD_FILE_STATE
fs_state_free(file, file->state);
#endif
LWIP_UNUSED_ARG(file);
}{ ... }
#if LWIP_HTTPD_DYNAMIC_FILE_READ
#if LWIP_HTTPD_FS_ASYNC_READ
int
fs_read_async(struct fs_file *file, char *buffer, int count, fs_wait_cb callback_fn, void *callback_arg)/* ... */
#else
int
fs_read(struct fs_file *file, char *buffer, int count)/* ... */
#endif
{
int read;
if (file->index == file->len) {
return FS_READ_EOF;
}if (file->index == file->len) { ... }
#if LWIP_HTTPD_FS_ASYNC_READ
LWIP_UNUSED_ARG(callback_fn);
LWIP_UNUSED_ARG(callback_arg);/* ... */
#endif
#if LWIP_HTTPD_CUSTOM_FILES
if (file->is_custom_file) {
#if LWIP_HTTPD_FS_ASYNC_READ
return fs_read_async_custom(file, buffer, count, callback_fn, callback_arg);
#else
return fs_read_custom(file, buffer, count);
#endif
}if (file->is_custom_file) { ... }
/* ... */#endif
read = file->len - file->index;
if (read > count) {
read = count;
}if (read > count) { ... }
MEMCPY(buffer, (file->data + file->index), read);
file->index += read;
return (read);
...}/* ... */
#endif
#if LWIP_HTTPD_FS_ASYNC_READ
int
fs_is_file_ready(struct fs_file *file, fs_wait_cb callback_fn, void *callback_arg)
{
if (file != NULL) {
#if LWIP_HTTPD_FS_ASYNC_READ
#if LWIP_HTTPD_CUSTOM_FILES
if (!fs_canread_custom(file)) {
if (fs_wait_read_custom(file, callback_fn, callback_arg)) {
return 0;
}if (fs_wait_read_custom(file, callback_fn, callback_arg)) { ... }
}if (!fs_canread_custom(file)) { ... }
/* ... */#else
LWIP_UNUSED_ARG(callback_fn);
LWIP_UNUSED_ARG(callback_arg);/* ... */
#endif /* ... */
#endif
}if (file != NULL) { ... }
return 1;
}fs_is_file_ready (struct fs_file *file, fs_wait_cb callback_fn, void *callback_arg) { ... }
/* ... */#endif
int
fs_bytes_left(struct fs_file *file)
{
return file->len - file->index;
}{ ... }