From c4cded360e1fe8fedfb4d51435f209d762bf0ba7 Mon Sep 17 00:00:00 2001 From: Karai Csaba Date: Sun, 1 May 2016 06:34:57 +0200 Subject: [PATCH] names at the left frame --- esp-link/cgi.c | 4 +++- espfs/espfs.c | 6 +----- web-server/web-server.c | 47 ++++++++++++++++++++++++++++++++++++++--- web-server/web-server.h | 4 +++- 4 files changed, 51 insertions(+), 10 deletions(-) diff --git a/esp-link/cgi.c b/esp-link/cgi.c index 825fe52..891b688 100644 --- a/esp-link/cgi.c +++ b/esp-link/cgi.c @@ -16,6 +16,7 @@ Some random cgi routines. #include #include "cgi.h" #include "config.h" +#include "web-server.h" #ifdef CGI_DBG #define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) @@ -216,11 +217,12 @@ int ICACHE_FLASH_ATTR cgiMenu(HttpdConnData *connData) { "\"Debug log\", \"/log.html\"," "\"Upgrade Firmware\", \"/flash.html\"" "\"Web Server\", \"/web-server.html\"" + "%s" " ], " "\"version\": \"%s\", " "\"name\": \"%s\"" " }", - esp_link_version, name); + webServerUserPages(), esp_link_version, name); httpdSend(connData, buff, -1); return HTTPD_CGI_DONE; diff --git a/espfs/espfs.c b/espfs/espfs.c index 340e394..39f2e12 100644 --- a/espfs/espfs.c +++ b/espfs/espfs.c @@ -221,8 +221,7 @@ EspFsFile ICACHE_FLASH_ATTR *espFsOpen(EspFsContext *ctx, char *fileName) { //os_printf("Alloc %p[%d]\n", r, sizeof(EspFsFile)); if (r==NULL) return NULL; r->ctx = ctx; - r->header=(EspFsHeader *)os_malloc(sizeof(EspFsHeader)); - os_memcpy(r->header, &it.header, sizeof(EspFsHeader)); + r->header=(EspFsHeader *)it.node; r->decompressor=it.header.compression; r->posComp=it.node + it.header.nameLen + sizeof(EspFsHeader); r->posStart=it.node + it.header.nameLen + sizeof(EspFsHeader); @@ -267,9 +266,6 @@ int ICACHE_FLASH_ATTR espFsRead(EspFsFile *fh, char *buff, int len) { void ICACHE_FLASH_ATTR espFsClose(EspFsFile *fh) { if (fh==NULL) return; //os_printf("Freed %p\n", fh); - if( fh->header != NULL ) - os_free( fh->header ); - fh->header = NULL; os_free(fh); } diff --git a/web-server/web-server.c b/web-server/web-server.c index ddfd0ec..b7df35e 100644 --- a/web-server/web-server.c +++ b/web-server/web-server.c @@ -3,22 +3,63 @@ #include "espfs.h" #include "config.h" +char * webServerPages = NULL; + +char * ICACHE_FLASH_ATTR webServerUserPages() +{ + return webServerPages; +} + void ICACHE_FLASH_ATTR webServerBrowseFiles() { + char buffer[1024]; + buffer[0] = 0; + EspFsIterator it; espFsIteratorInit(userPageCtx, &it); { while( espFsIteratorNext(&it) ) { - if( strlen(it.name) >= 6 ) + int nlen = strlen(it.name); + if( nlen >= 6 ) { - if( os_strcmp( it.name + strlen(it.name)-5, ".html" ) == 0 ) + if( os_strcmp( it.name + nlen-5, ".html" ) == 0 ) { - os_printf("%s\n", it.name); // TODO + char sh_name[17]; + + int spos = nlen-5; + + while( spos > 0 ) + { + if( it.name[spos+1] == '/' ) + break; + spos--; + } + + int ps = nlen-5-spos; + if( ps > 16 ) + ps = 16; + os_memcpy(sh_name, it.name + spos, ps); + sh_name[ps] = 0; + + os_strcat(buffer, ", \""); + os_strcat(buffer, sh_name); + os_strcat(buffer, "\", \"/"); + os_strcat(buffer, it.name); + os_strcat(buffer, "\""); } } + if( strlen(buffer) > 600 ) + break; } } + + if( webServerPages != NULL ) + os_free( webServerPages ); + + int len = strlen(buffer) + 1; + webServerPages = (char *)os_malloc( len ); + os_memcpy( webServerPages, buffer, len ); } void ICACHE_FLASH_ATTR webServerInit() diff --git a/web-server/web-server.h b/web-server/web-server.h index 5917605..7716b33 100644 --- a/web-server/web-server.h +++ b/web-server/web-server.h @@ -3,7 +3,9 @@ #include -void webServerInit(); +void webServerInit(); + +char * webServerUserPages(); #endif /* WEB_SERVER_H */