diff --git a/.gitignore b/.gitignore index 5e14a6fa..0d1e171c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ espfs/espfstest/*.o espfs/espfstest/espfstest *.DS_Store html_compressed/ -libwebpages-espfs.a \ No newline at end of file +libwebpages-espfs.a +*.swp diff --git a/Makefile b/Makefile index 59a6db62..e38ada23 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,7 @@ YUI-COMPRESSOR ?= /usr/bin/yui-compressor USE_HEATSHRINK ?= yes HTTPD_WEBSOCKETS ?= yes USE_OPENSDK ?= no +USE_SSL ?= no HTTPD_MAX_CONNECTIONS ?= 4 #For FreeRTOS HTTPD_STACKSIZE ?= 2048 @@ -152,6 +153,10 @@ ifeq ("$(HTTPD_WEBSOCKETS)","yes") CFLAGS += -DHTTPD_WEBSOCKETS endif +ifeq ("$(USE_SSL)","yes") +CFLAGS += -DUSE_SSL +endif + vpath %.c $(SRC_DIR) define compile-objects @@ -180,6 +185,8 @@ checkdirs: $(BUILD_DIR) $(BUILD_DIR): $(Q) mkdir -p $@ +#ignore vim swap files +FIND_OPTIONS = -not -iname '*.swp' webpages.espfs: $(HTMLDIR) espfs/mkespfsimage/mkespfsimage ifeq ("$(COMPRESS_W_YUI)","yes") @@ -191,9 +198,9 @@ ifeq ("$(COMPRESS_W_YUI)","yes") $(Q) awk "BEGIN {printf \"YUI compression ratio was: %.2f%%\\n\", (`du -b -s html_compressed/ | sed 's/\([0-9]*\).*/\1/'`/`du -b -s ../html/ | sed 's/\([0-9]*\).*/\1/'`)*100}" # mkespfsimage will compress html, css, svg and js files with gzip by default if enabled # override with -g cmdline parameter - $(Q) cd html_compressed; find . | $(THISDIR)/espfs/mkespfsimage/mkespfsimage > $(THISDIR)/webpages.espfs; cd ..; + $(Q) cd html_compressed; find . $(FIND_OPTIONS) | $(THISDIR)/espfs/mkespfsimage/mkespfsimage > $(THISDIR)/webpages.espfs; cd ..; else - $(Q) cd ../html; find . | $(THISDIR)/espfs/mkespfsimage/mkespfsimage > $(THISDIR)/webpages.espfs; cd .. + $(Q) cd ../html; find . $(FIND_OPTIONS) | $(THISDIR)/espfs/mkespfsimage/mkespfsimage > $(THISDIR)/webpages.espfs; cd .. endif libwebpages-espfs.a: webpages.espfs diff --git a/core/httpd-nonos.c b/core/httpd-nonos.c index 410aa309..faefaa6d 100644 --- a/core/httpd-nonos.c +++ b/core/httpd-nonos.c @@ -60,12 +60,12 @@ static void ICACHE_FLASH_ATTR platConnCb(void *arg) { int ICACHE_FLASH_ATTR httpdPlatSendData(ConnTypePtr conn, char *buff, int len) { int r; - r=espconn_sent(conn, (uint8_t*)buff, len); - return (r>=0); + r=espconn_sent(conn, (uint8_t*)buff, len); + return (r>=0); } void ICACHE_FLASH_ATTR httpdPlatDisconnect(ConnTypePtr conn) { - espconn_disconnect(conn); + espconn_disconnect(conn); } void ICACHE_FLASH_ATTR httpdPlatDisableTimeout(ConnTypePtr conn) { @@ -80,8 +80,9 @@ void ICACHE_FLASH_ATTR httpdPlatInit(int port, int maxConnCt) { httpdTcp.local_port=port; httpdConn.proto.tcp=&httpdTcp; espconn_regist_connectcb(&httpdConn, platConnCb); - espconn_accept(&httpdConn); - espconn_tcp_set_max_con_allow(&httpdConn, maxConnCt); + espconn_accept(&httpdConn); + espconn_tcp_set_max_con_allow(&httpdConn, maxConnCt); + } diff --git a/core/httpd.c b/core/httpd.c index bb5b5f5b..0458bd2a 100644 --- a/core/httpd.c +++ b/core/httpd.c @@ -588,6 +588,15 @@ static void ICACHE_FLASH_ATTR httpdParseHeader(char *h, HttpdConnData *conn) { } else if (strncmp(h, "POST ", 5)==0) { conn->requestType = HTTPD_METHOD_POST; firstLine=1; + } else if (strncmp(h, "PUT ", 4)==0) { + conn->requestType = HTTPD_METHOD_PUT; + firstLine=1; + } else if (strncmp(h, "PATCH ", 6)==0) { + conn->requestType = HTTPD_METHOD_PATCH; + firstLine=1; + } else if (strncmp(h, "DELETE ", 7)==0) { + conn->requestType = HTTPD_METHOD_DELETE; + firstLine=1; } if (firstLine) { @@ -683,15 +692,16 @@ void ICACHE_FLASH_ATTR httpdRecvCb(ConnTypePtr rconn, char *remIp, int remPort, int x, r; char *p, *e; httpdPlatLock(); - char *sendBuff=malloc(HTTPD_MAX_SENDBUFF_LEN); - if (sendBuff==NULL) { - printf("Malloc sendBuff failed!\n"); + + HttpdConnData *conn=httpdFindConnData(rconn, remIp, remPort); + if (conn==NULL) { httpdPlatUnlock(); return; } - HttpdConnData *conn=httpdFindConnData(rconn, remIp, remPort); - if (conn==NULL) { + char *sendBuff=malloc(HTTPD_MAX_SENDBUFF_LEN); + if (sendBuff==NULL) { + printf("Malloc sendBuff failed!\n"); httpdPlatUnlock(); return; } diff --git a/espfs/espfs.c b/espfs/espfs.c index d5270d2a..e179cb95 100644 --- a/espfs/espfs.c +++ b/espfs/espfs.c @@ -183,6 +183,7 @@ EspFsFile ICACHE_FLASH_ATTR *espFsOpen(char *fileName) { #endif } else { httpd_printf("Invalid compression: %d\n", h.compression); + free(r); return NULL; } return r; diff --git a/include/httpd.h b/include/httpd.h index 73745ac7..a669624d 100644 --- a/include/httpd.h +++ b/include/httpd.h @@ -21,6 +21,9 @@ #define HTTPD_METHOD_GET 1 #define HTTPD_METHOD_POST 2 +#define HTTPD_METHOD_PUT 3 +#define HTTPD_METHOD_PATCH 4 +#define HTTPD_METHOD_DELETE 5 #define HTTPD_TRANSFER_CLOSE 0 #define HTTPD_TRANSFER_CHUNKED 1 diff --git a/util/cgiflash.c b/util/cgiflash.c index 1a74c2ed..b38c55ee 100644 --- a/util/cgiflash.c +++ b/util/cgiflash.c @@ -25,7 +25,7 @@ Some flash handling cgi routines. Used for updating the ESPFS/OTA image. #include "espfs.h" #ifndef UPGRADE_FLAG_FINISH -#define UPGRADE_FLAG_FINISH 0x02 +#define UPGRADE_FLAG_FINISH 0x02 #endif // Check that the header of the firmware blob looks like actual firmware... @@ -175,7 +175,10 @@ int ICACHE_FLASH_ATTR cgiUploadFirmware(HttpdConnData *connData) { if (connData->post->len > def->fwSize) { state->err="Firmware image too large"; state->state=FLST_ERROR; - } else { + } else if (system_upgrade_userbin_check() == 0) { + state->err="Can't overwrite running image"; + state->state=FLST_ERROR; + } else { state->len=connData->post->len; state->address=def->fw1Pos; state->state=FLST_WRITE;