diff --git a/esp-link/main.c b/esp-link/main.c index e572f03..06aa61e 100644 --- a/esp-link/main.c +++ b/esp-link/main.c @@ -152,10 +152,13 @@ void user_init(void) { wifiInit(); // init the flash filesystem with the html stuff espFsInit(espLinkCtx, &_binary_espfs_img_start, ESPFS_MEMORY); + //EspFsInitResult res = espFsInit(&_binary_espfs_img_start); //os_printf("espFsInit %s\n", res?"ERR":"ok"); // mount the http handlers httpdInit(builtInUrls, 80); + httpdespfsInit(); + // init the wifi-serial transparent bridge (port 23) serbridgeInit(23, 2323); uart_add_recv_cb(&serbridgeUartCb); diff --git a/espfs/espfs.c b/espfs/espfs.c index 6389b08..8657fd4 100644 --- a/espfs/espfs.c +++ b/espfs/espfs.c @@ -42,10 +42,10 @@ It's written for use with httpd, but doesn't need to be used as such. #include "espfs.h" EspFsContext espLinkCtxDef; -EspFsContext userCtxDef; +EspFsContext userPageCtxDef; EspFsContext * espLinkCtx = &espLinkCtxDef; -EspFsContext * userCtx = &userCtxDef; +EspFsContext * userPageCtx = &userPageCtxDef; struct EspFsContext { @@ -247,5 +247,7 @@ void ICACHE_FLASH_ATTR espFsClose(EspFsFile *fh) { os_free(fh); } - +int ICACHE_FLASH_ATTR espFsIsValid(EspFsContext *ctx) { + return ctx->valid; +} diff --git a/espfs/espfs.h b/espfs/espfs.h index 8e4b79f..cab1896 100644 --- a/espfs/espfs.h +++ b/espfs/espfs.h @@ -16,10 +16,11 @@ typedef struct EspFsFile EspFsFile; typedef struct EspFsContext EspFsContext; extern EspFsContext * espLinkCtx; -extern EspFsContext * userCtx; +extern EspFsContext * userPageCtx; EspFsInitResult espFsInit(EspFsContext *ctx, void *flashAddress, EspFsSource source); EspFsFile *espFsOpen(EspFsContext *ctx, char *fileName); +int espFsIsValid(EspFsContext *ctx); int espFsFlags(EspFsFile *fh); int espFsRead(EspFsFile *fh, char *buff, int len); void espFsClose(EspFsFile *fh); diff --git a/httpd/httpdespfs.c b/httpd/httpdespfs.c index 9ab2865..8beadca 100644 --- a/httpd/httpdespfs.c +++ b/httpd/httpdespfs.c @@ -13,11 +13,20 @@ Connector to let httpd use the espfs filesystem to serve the files in it. * ---------------------------------------------------------------------------- */ #include "httpdespfs.h" +#include "config.h" // The static files marked with FLAG_GZIP are compressed and will be served with GZIP compression. // If the client does not advertise that he accepts GZIP send following warning message (telnet users for e.g.) static const char *gzipNonSupportedMessage = "HTTP/1.0 501 Not implemented\r\nServer: esp8266-httpd/"HTTPDVER"\r\nConnection: close\r\nContent-Type: text/plain\r\nContent-Length: 52\r\n\r\nYour browser does not accept gzip-compressed data.\r\n"; +void ICACHE_FLASH_ATTR httpdespfsInit() +{ + espFsInit(userPageCtx, (void *)getUserPageSectionStart(), ESPFS_FLASH); + if( espFsIsValid( userPageCtx ) ) + os_printf("Valid user file system found!\n"); + else + os_printf("No user file system found!\n"); +} //This is a catch-all cgi function. It takes the url passed to it, looks up the corresponding //path in the filesystem and if it exists, passes the file through. This simulates what a normal @@ -42,7 +51,14 @@ cgiEspFsHook(HttpdConnData *connData) { //First call to this cgi. Open the file so we can read it. file=espFsOpen(espLinkCtx, connData->url); if (file==NULL) { - return HTTPD_CGI_NOTFOUND; + if( espFsIsValid(userPageCtx) ) + { + file = espFsOpen(userPageCtx, connData->url ); + if( file == NULL ) + return HTTPD_CGI_NOTFOUND; + } + else + return HTTPD_CGI_NOTFOUND; } // The gzip checking code is intentionally without #ifdefs because checking diff --git a/httpd/httpdespfs.h b/httpd/httpdespfs.h index 847a8b6..95c5f50 100644 --- a/httpd/httpdespfs.h +++ b/httpd/httpdespfs.h @@ -7,6 +7,8 @@ #include "cgi.h" #include "httpd.h" +void httpdespfsInit(); + int cgiEspFsHook(HttpdConnData *connData); //int cgiEspFsTemplate(HttpdConnData *connData); //int ICACHE_FLASH_ATTR cgiEspFsHtml(HttpdConnData *connData);