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. 16
      httpd/httpdespfs.c
  5. 2
      httpd/httpdespfs.h

@ -150,10 +150,13 @@ void user_init(void) {
wifiInit(); wifiInit();
// init the flash filesystem with the html stuff // init the flash filesystem with the html stuff
espFsInit(espLinkCtx, &_binary_espfs_img_start, ESPFS_MEMORY); espFsInit(espLinkCtx, &_binary_espfs_img_start, ESPFS_MEMORY);
//EspFsInitResult res = espFsInit(&_binary_espfs_img_start); //EspFsInitResult res = espFsInit(&_binary_espfs_img_start);
//os_printf("espFsInit %s\n", res?"ERR":"ok"); //os_printf("espFsInit %s\n", res?"ERR":"ok");
// mount the http handlers // mount the http handlers
httpdInit(builtInUrls, 80); httpdInit(builtInUrls, 80);
httpdespfsInit();
// init the wifi-serial transparent bridge (port 23) // init the wifi-serial transparent bridge (port 23)
serbridgeInit(23, 2323); serbridgeInit(23, 2323);
uart_add_recv_cb(&serbridgeUartCb); 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" #include "espfs.h"
EspFsContext espLinkCtxDef; EspFsContext espLinkCtxDef;
EspFsContext userCtxDef; EspFsContext userPageCtxDef;
EspFsContext * espLinkCtx = &espLinkCtxDef; EspFsContext * espLinkCtx = &espLinkCtxDef;
EspFsContext * userCtx = &userCtxDef; EspFsContext * userPageCtx = &userPageCtxDef;
struct EspFsContext struct EspFsContext
{ {
@ -247,5 +247,7 @@ void ICACHE_FLASH_ATTR espFsClose(EspFsFile *fh) {
os_free(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; typedef struct EspFsContext EspFsContext;
extern EspFsContext * espLinkCtx; extern EspFsContext * espLinkCtx;
extern EspFsContext * userCtx; extern EspFsContext * userPageCtx;
EspFsInitResult espFsInit(EspFsContext *ctx, void *flashAddress, EspFsSource source); EspFsInitResult espFsInit(EspFsContext *ctx, void *flashAddress, EspFsSource source);
EspFsFile *espFsOpen(EspFsContext *ctx, char *fileName); EspFsFile *espFsOpen(EspFsContext *ctx, char *fileName);
int espFsIsValid(EspFsContext *ctx);
int espFsFlags(EspFsFile *fh); int espFsFlags(EspFsFile *fh);
int espFsRead(EspFsFile *fh, char *buff, int len); int espFsRead(EspFsFile *fh, char *buff, int len);
void espFsClose(EspFsFile *fh); 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 "httpdespfs.h"
#include "config.h"
// The static files marked with FLAG_GZIP are compressed and will be served with GZIP compression. // 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.) // 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"; 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 //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 //path in the filesystem and if it exists, passes the file through. This simulates what a normal
@ -42,6 +51,13 @@ cgiEspFsHook(HttpdConnData *connData) {
//First call to this cgi. Open the file so we can read it. //First call to this cgi. Open the file so we can read it.
file=espFsOpen(espLinkCtx, connData->url); file=espFsOpen(espLinkCtx, connData->url);
if (file==NULL) { if (file==NULL) {
if( espFsIsValid(userPageCtx) )
{
file = espFsOpen(userPageCtx, connData->url );
if( file == NULL )
return HTTPD_CGI_NOTFOUND;
}
else
return HTTPD_CGI_NOTFOUND; return HTTPD_CGI_NOTFOUND;
} }

@ -7,6 +7,8 @@
#include "cgi.h" #include "cgi.h"
#include "httpd.h" #include "httpd.h"
void httpdespfsInit();
int cgiEspFsHook(HttpdConnData *connData); int cgiEspFsHook(HttpdConnData *connData);
//int cgiEspFsTemplate(HttpdConnData *connData); //int cgiEspFsTemplate(HttpdConnData *connData);
//int ICACHE_FLASH_ATTR cgiEspFsHtml(HttpdConnData *connData); //int ICACHE_FLASH_ATTR cgiEspFsHtml(HttpdConnData *connData);

Loading…
Cancel
Save