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..8a2e4993 100644 --- a/Makefile +++ b/Makefile @@ -180,6 +180,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 +193,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.c b/core/httpd.c index bb5b5f5b..d878eaf1 100644 --- a/core/httpd.c +++ b/core/httpd.c @@ -536,6 +536,7 @@ static void ICACHE_FLASH_ATTR httpdProcessRequest(HttpdConnData *conn) { if (match) { httpd_printf("Is url index %d\n", i); conn->cgiData=NULL; + conn->userData=NULL; conn->cgi=builtInUrls[i].cgiCb; conn->cgiArg=builtInUrls[i].cgiArg; break; @@ -683,15 +684,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; } @@ -714,7 +716,7 @@ void ICACHE_FLASH_ATTR httpdRecvCb(ConnTypePtr rconn, char *remIp, int remPort, } } //ToDo: return http error code 431 (request header too long) if this happens - if (conn->priv->headPos!=HTTPD_MAX_HEAD_LEN) conn->priv->head[conn->priv->headPos++]=data[x]; + if (conn->priv->headPospriv->head[conn->priv->headPos++]=data[x]; conn->priv->head[conn->priv->headPos]=0; //Scan for /r/n/r/n. Receiving this indicate the headers end. if (data[x]=='\n' && (char *)strstr(conn->priv->head, "\r\n\r\n")!=NULL) { diff --git a/espfs/espfs.c b/espfs/espfs.c index d5270d2a..919373ef 100644 --- a/espfs/espfs.c +++ b/espfs/espfs.c @@ -135,8 +135,9 @@ EspFsFile ICACHE_FLASH_ATTR *espFsOpen(char *fileName) { char namebuf[256]; EspFsHeader h; EspFsFile *r; - //Strip initial slashes - while(fileName[0]=='/') fileName++; + //Strip first initial slash + //We should not strip any next slashes otherwise there is potential security risk when mapped authentication handler will not invoke (ex. ///security.html) + if(fileName[0]=='/') fileName++; //Go find that file! while(1) { hpos=p; @@ -183,6 +184,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/esp8266.h b/include/esp8266.h index 7b685e45..b30a1d47 100644 --- a/include/esp8266.h +++ b/include/esp8266.h @@ -7,6 +7,7 @@ #include #include #include +#include #ifdef FREERTOS #include @@ -25,7 +26,6 @@ #include #include #include -#include #include #endif diff --git a/include/espmissingincludes.h b/include/espmissingincludes.h index 3126c95c..6ade6346 100644 --- a/include/espmissingincludes.h +++ b/include/espmissingincludes.h @@ -9,13 +9,14 @@ int strcasecmp(const char *a, const char *b); #ifndef FREERTOS #include #include + //Missing function prototypes in include folders. Gcc will warn on these if we don't define 'em anywhere. //MOST OF THESE ARE GUESSED! but they seem to swork and shut up the compiler. typedef struct espconn espconn; int atoi(const char *nptr); -void ets_install_putc1(void *routine); -void ets_isr_attach(int intr, void *handler, void *arg); +void ets_install_putc1(void (*routine)(char c)); +void ets_isr_attach(int intr, void (*handler)(void *), void *arg); void ets_isr_mask(unsigned intr); void ets_isr_unmask(unsigned intr); int ets_memcmp(const void *s1, const void *s2, size_t n); @@ -25,11 +26,11 @@ int ets_sprintf(char *str, const char *format, ...) __attribute__ ((format (pri int ets_str2macaddr(void *, void *); int ets_strcmp(const char *s1, const char *s2); char *ets_strcpy(char *dest, const char *src); -size_t ets_strlen(const char *s); -int ets_strncmp(const char *s1, const char *s2, int len); +int ets_strlen(const char *s); +int ets_strncmp(const char *s1, const char *s2, unsigned int len); char *ets_strncpy(char *dest, const char *src, size_t n); char *ets_strstr(const char *haystack, const char *needle); -void ets_timer_arm_new(os_timer_t *a, int b, int c, int isMstimer); +void ets_timer_arm_new(os_timer_t *a, uint32_t b, bool repeat, bool isMstimer); void ets_timer_disarm(os_timer_t *a); void ets_timer_setfn(os_timer_t *t, ETSTimerFunc *fn, void *parg); void ets_update_cpu_frequency(int freqmhz); @@ -37,12 +38,12 @@ void *os_memmove(void *dest, const void *src, size_t n); int os_printf(const char *format, ...) __attribute__ ((format (printf, 1, 2))); int os_snprintf(char *str, size_t size, const char *format, ...) __attribute__ ((format (printf, 3, 4))); int os_printf_plus(const char *format, ...) __attribute__ ((format (printf, 1, 2))); -void uart_div_modify(int no, unsigned int freq); +void uart_div_modify(uint8 no, uint32 freq); uint8 wifi_get_opmode(void); uint32 system_get_time(); int rand(void); void ets_bzero(void *s, size_t n); -void ets_delay_us(int ms); +void ets_delay_us(uint16_t ms); //Hack: this is defined in SDK 1.4.0 and undefined in 1.3.0. It's only used for this, the symbol itself //has no meaning here. @@ -54,11 +55,11 @@ void vPortFree(void *ptr); void *vPortMalloc(size_t xWantedSize); void pvPortFree(void *ptr); #else -void *pvPortMalloc(size_t xWantedSize, const char *file, int line); -void *pvPortZalloc(size_t, const char *file, int line); -void vPortFree(void *ptr, const char *file, int line); -void *vPortMalloc(size_t xWantedSize, const char *file, int line); -void pvPortFree(void *ptr, const char *file, int line); +void *pvPortMalloc(size_t xWantedSize, const char *file, unsigned line); +void *pvPortZalloc(size_t, const char *file, unsigned line); +void vPortFree(void *ptr, const char *file, unsigned line); +void *vPortMalloc(size_t xWantedSize, const char *file, unsigned line); +void pvPortFree(void *ptr, const char *file, unsigned line); #endif //Standard PIN_FUNC_SELECT gives a warning. Replace by a non-warning one. diff --git a/include/httpd.h b/include/httpd.h index 73745ac7..aea02103 100644 --- a/include/httpd.h +++ b/include/httpd.h @@ -50,6 +50,7 @@ struct HttpdConnData { int remote_port; // Remote TCP port uint8 remote_ip[4]; // IP address of client uint8 slot; // Slot ID + void *userData; // Variable for storing any user data }; //A struct describing the POST data sent inside the http connection. This is used by the CGI functions