Web server shows user pages

pull/183/head
Karai Csaba 9 years ago committed by cskarai
parent eedf1959ca
commit 730c0bdb5c
  1. 3
      esp-link/main.c
  2. 8
      espfs/espfs.c
  3. 3
      espfs/espfs.h
  4. 18
      httpd/httpdespfs.c
  5. 2
      httpd/httpdespfs.h

@ -150,10 +150,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);

@ -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;
}

@ -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);

@ -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

@ -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);

Loading…
Cancel
Save