-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathWebServer.cpp
55 lines (46 loc) · 1.15 KB
/
WebServer.cpp
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <string.h>
#include "lwip/apps/fs.h"
#include "lwip/apps/httpd.h"
#include "WebServer.h"
WebServer webserver;
void WebServer::begin() {
httpd_init();
webpages = NULL;
}
void WebServer::setWebpages(const struct webpage *new_webpages) {
webpages = new_webpages;
}
const char *WebServer::getPage(const char *name) {
if(webpages == NULL) {
return NULL;
}
for(uint32_t i = 0; webpages[i].filename != NULL; i++) {
if(strcmp(name, webpages[i].filename) == 0) {
if(webpages[i].pageGen) {
return webpages[i].pageGen(name);
}
return webpages[i].content;
}
}
return NULL;
}
extern "C" {
int fs_open_custom(struct fs_file *file, const char *name) {
if (file && name) {
const char *data = webserver.getPage(name);
if(data) {
file->data = data;
file->len = strlen(file->data);
file->index = file->len;
return 1;
}
return 0;
}
return 0;
}
void fs_close_custom(struct fs_file *file) {
}
int fs_read_custom(struct fs_file *file, char *buffer, int count) {
return FS_READ_EOF;
}
}