names at the left frame

pull/183/head
Karai Csaba 9 years ago committed by cskarai
parent 4f159c1e47
commit aad4bc0631
  1. 4
      esp-link/cgi.c
  2. 6
      espfs/espfs.c
  3. 47
      web-server/web-server.c
  4. 2
      web-server/web-server.h

@ -16,6 +16,7 @@ Some random cgi routines.
#include <esp8266.h> #include <esp8266.h>
#include "cgi.h" #include "cgi.h"
#include "config.h" #include "config.h"
#include "web-server.h"
#ifdef CGI_DBG #ifdef CGI_DBG
#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0) #define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0)
@ -215,11 +216,12 @@ int ICACHE_FLASH_ATTR cgiMenu(HttpdConnData *connData) {
#endif #endif
"\"Debug log\", \"/log.html\", " "\"Debug log\", \"/log.html\", "
"\"Web Server\", \"/web-server.html\"" "\"Web Server\", \"/web-server.html\""
"%s"
" ], " " ], "
"\"version\": \"%s\", " "\"version\": \"%s\", "
"\"name\": \"%s\"" "\"name\": \"%s\""
" }", " }",
esp_link_version, name); webServerUserPages(), esp_link_version, name);
httpdSend(connData, buff, -1); httpdSend(connData, buff, -1);
return HTTPD_CGI_DONE; return HTTPD_CGI_DONE;

@ -221,8 +221,7 @@ EspFsFile ICACHE_FLASH_ATTR *espFsOpen(EspFsContext *ctx, char *fileName) {
//os_printf("Alloc %p[%d]\n", r, sizeof(EspFsFile)); //os_printf("Alloc %p[%d]\n", r, sizeof(EspFsFile));
if (r==NULL) return NULL; if (r==NULL) return NULL;
r->ctx = ctx; r->ctx = ctx;
r->header=(EspFsHeader *)os_malloc(sizeof(EspFsHeader)); r->header=(EspFsHeader *)it.node;
os_memcpy(r->header, &it.header, sizeof(EspFsHeader));
r->decompressor=it.header.compression; r->decompressor=it.header.compression;
r->posComp=it.node + it.header.nameLen + sizeof(EspFsHeader); r->posComp=it.node + it.header.nameLen + sizeof(EspFsHeader);
r->posStart=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) { void ICACHE_FLASH_ATTR espFsClose(EspFsFile *fh) {
if (fh==NULL) return; if (fh==NULL) return;
//os_printf("Freed %p\n", fh); //os_printf("Freed %p\n", fh);
if( fh->header != NULL )
os_free( fh->header );
fh->header = NULL;
os_free(fh); os_free(fh);
} }

@ -3,22 +3,63 @@
#include "espfs.h" #include "espfs.h"
#include "config.h" #include "config.h"
char * webServerPages = NULL;
char * ICACHE_FLASH_ATTR webServerUserPages()
{
return webServerPages;
}
void ICACHE_FLASH_ATTR webServerBrowseFiles() void ICACHE_FLASH_ATTR webServerBrowseFiles()
{ {
char buffer[1024];
buffer[0] = 0;
EspFsIterator it; EspFsIterator it;
espFsIteratorInit(userPageCtx, &it); espFsIteratorInit(userPageCtx, &it);
{ {
while( espFsIteratorNext(&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() void ICACHE_FLASH_ATTR webServerInit()

@ -5,5 +5,7 @@
void webServerInit(); void webServerInit();
char * webServerUserPages();
#endif /* WEB_SERVER_H */ #endif /* WEB_SERVER_H */

Loading…
Cancel
Save