You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
1.6 KiB
80 lines
1.6 KiB
2 years ago
|
#include <stdio.h>
|
||
|
#include "httpd.h"
|
||
|
#include "httpd-utils.h"
|
||
|
#include "httpdespfs.h"
|
||
|
|
||
|
#include <httpd.h>
|
||
|
#include <cgiwebsocket.h>
|
||
|
#include <httpdespfs.h>
|
||
|
#include <auth.h>
|
||
2 years ago
|
#include <signal.h>
|
||
2 years ago
|
|
||
|
#include "logging.h"
|
||
|
|
||
2 years ago
|
extern unsigned char espfs_image[];
|
||
|
extern unsigned int espfs_image_len;
|
||
|
|
||
2 years ago
|
/** "About" page */
|
||
|
httpd_cgi_state tplIndex(HttpdConnData *connData, char *token, void **arg)
|
||
|
{
|
||
|
if (token == NULL) { return HTTPD_CGI_DONE; }
|
||
|
|
||
|
else if (streq(token, "date")) {
|
||
|
tplSend(connData, __DATE__, -1);
|
||
|
} else if (streq(token, "time")) {
|
||
|
tplSend(connData, __TIME__, -1);
|
||
|
} else if (streq(token, "vers_httpd")) {
|
||
|
tplSend(connData, httpdGetVersion(), -1);
|
||
|
}
|
||
|
|
||
|
return HTTPD_CGI_DONE;
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* Application routes
|
||
|
*/
|
||
|
const HttpdBuiltInUrl routes[] = {
|
||
|
// TODO password lock ...
|
||
|
|
||
|
// --- Web pages ---
|
||
2 years ago
|
// ROUTE_TPL_FILE("/", tplIndex, "/index.tpl"),
|
||
|
ROUTE_FILE("/", "index.html"),
|
||
2 years ago
|
|
||
|
ROUTE_FILESYSTEM(),
|
||
|
ROUTE_END(),
|
||
|
};
|
||
|
|
||
2 years ago
|
void sigpipe_handler(int unused)
|
||
|
{
|
||
|
}
|
||
|
|
||
2 years ago
|
int main()
|
||
|
{
|
||
|
printf("Hello, World!\n");
|
||
|
|
||
2 years ago
|
// prevent abort on sigpipe
|
||
|
sigaction(SIGPIPE, &(struct sigaction) {sigpipe_handler}, NULL);
|
||
|
|
||
2 years ago
|
struct httpd_options opts = {
|
||
2 years ago
|
.port = 8080,
|
||
2 years ago
|
};
|
||
|
|
||
|
httpd_thread_handle_t *handle = httpdInit(routes, &opts);
|
||
|
httpdSetName("ServerName");
|
||
|
|
||
|
httpdJoin(handle);
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
2 years ago
|
|
||
|
int httpdPlatEspfsRead(void *dest, uint32_t offset, size_t len)
|
||
|
{
|
||
|
if (offset + len > espfs_image_len) {
|
||
|
return -1;
|
||
|
}
|
||
|
|
||
|
memcpy(dest, &espfs_image[offset], len);
|
||
|
return 0;
|
||
|
}
|