From eae260f92345fa81716857a0cbc13566ed6f8632 Mon Sep 17 00:00:00 2001 From: Jeff Kent Date: Tue, 27 Jun 2017 22:30:36 -0500 Subject: [PATCH 1/2] make esp-open-rtos compatable --- core/auth.c | 4 +- core/base64.c | 2 +- core/httpd-freertos.c | 37 ++++++++++--------- core/httpd-nonos.c | 7 ++-- core/httpd.c | 4 +- core/httpdespfs.c | 8 ++-- core/sha1.c | 7 +--- espfs/espfs.c | 15 +++++--- espfs/heatshrink_decoder.c | 4 +- espfs/mkespfsimage/main.c | 4 +- include/{ => libesphttpd}/auth.h | 0 include/{ => libesphttpd}/captdns.h | 0 include/{ => libesphttpd}/cgiflash.h | 0 include/{ => libesphttpd}/cgiwebsocket.h | 0 include/{ => libesphttpd}/cgiwifi.h | 0 include/{ => libesphttpd}/esp8266.h | 12 ++++-- include/{ => libesphttpd}/espfs.h | 0 .../{ => libesphttpd}/espmissingincludes.h | 0 include/{ => libesphttpd}/httpd.h | 8 ++-- include/{ => libesphttpd}/httpdespfs.h | 4 +- include/{ => libesphttpd}/platform.h | 12 +++++- include/{ => libesphttpd}/sha1.h | 0 include/{ => libesphttpd}/user_config.h | 0 include/{ => libesphttpd}/webpages-espfs.h | 0 util/captdns.c | 4 +- util/cgiflash.c | 16 +++----- util/cgiwebsocket.c | 10 ++--- util/cgiwifi.c | 4 +- 28 files changed, 88 insertions(+), 74 deletions(-) rename include/{ => libesphttpd}/auth.h (100%) rename include/{ => libesphttpd}/captdns.h (100%) rename include/{ => libesphttpd}/cgiflash.h (100%) rename include/{ => libesphttpd}/cgiwebsocket.h (100%) rename include/{ => libesphttpd}/cgiwifi.h (100%) rename include/{ => libesphttpd}/esp8266.h (81%) rename include/{ => libesphttpd}/espfs.h (100%) rename include/{ => libesphttpd}/espmissingincludes.h (100%) rename include/{ => libesphttpd}/httpd.h (97%) rename include/{ => libesphttpd}/httpdespfs.h (80%) rename include/{ => libesphttpd}/platform.h (85%) rename include/{ => libesphttpd}/sha1.h (100%) rename include/{ => libesphttpd}/user_config.h (100%) rename include/{ => libesphttpd}/webpages-espfs.h (100%) diff --git a/core/auth.c b/core/auth.c index e244a443..3ba7502e 100644 --- a/core/auth.c +++ b/core/auth.c @@ -12,8 +12,8 @@ HTTP auth implementation. Only does basic authentication for now. */ -#include -#include "auth.h" +#include +#include #include "base64.h" int ICACHE_FLASH_ATTR authBasic(HttpdConnData *connData) { diff --git a/core/base64.c b/core/base64.c index 81f19fee..9c46e1ff 100644 --- a/core/base64.c +++ b/core/base64.c @@ -1,6 +1,6 @@ /* base64.c : base-64 / MIME encode/decode */ /* PUBLIC DOMAIN - Jon Mayo - November 13, 2003 */ -#include +#include #include "base64.h" static const int base64dec_tab[256] ICACHE_RODATA_ATTR={ diff --git a/core/httpd-freertos.c b/core/httpd-freertos.c index ff461b4f..1defe688 100644 --- a/core/httpd-freertos.c +++ b/core/httpd-freertos.c @@ -4,25 +4,26 @@ ESP8266 web server - platform-dependent routines, FreeRTOS version Thanks to my collague at Espressif for writing the foundations of this code. */ -#ifdef FREERTOS +#include +#ifdef FREERTOS -#include -#include "httpd.h" -#include "platform.h" +#include #include "httpd-platform.h" -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "freertos/queue.h" -#include "freertos/semphr.h" +#include -#include "lwip/lwip/sockets.h" +#include +#include +#include +#include + +#include "lwip/sockets.h" static int httpPort; static int httpMaxConnCt; -static xQueueHandle httpdMux; +static QueueHandle_t httpdMux; struct RtosConnType{ @@ -61,10 +62,10 @@ void ICACHE_FLASH_ATTR httpdPlatUnlock() { #define RECV_BUF_SIZE 2048 static void platHttpServerTask(void *pvParameters) { - int32 listenfd; - int32 remotefd; - int32 len; - int32 ret; + int32_t listenfd; + int32_t remotefd; + int32_t len; + int32_t ret; int x; int maxfdp = 0; char *precvbuf; @@ -92,7 +93,7 @@ static void platHttpServerTask(void *pvParameters) { listenfd = socket(AF_INET, SOCK_STREAM, 0); if (listenfd == -1) { httpd_printf("platHttpServerTask: failed to create sock!\n"); - vTaskDelay(1000/portTICK_RATE_MS); + vTaskDelay(1000/portTICK_PERIOD_MS); } } while(listenfd == -1); @@ -101,7 +102,7 @@ static void platHttpServerTask(void *pvParameters) { ret = bind(listenfd, (struct sockaddr *)&server_addr, sizeof(server_addr)); if (ret != 0) { httpd_printf("platHttpServerTask: failed to bind!\n"); - vTaskDelay(1000/portTICK_RATE_MS); + vTaskDelay(1000/portTICK_PERIOD_MS); } } while(ret != 0); @@ -110,7 +111,7 @@ static void platHttpServerTask(void *pvParameters) { ret = listen(listenfd, HTTPD_MAX_CONNECTIONS); if (ret != 0) { httpd_printf("platHttpServerTask: failed to listen!\n"); - vTaskDelay(1000/portTICK_RATE_MS); + vTaskDelay(1000/portTICK_PERIOD_MS); } } while(ret != 0); @@ -263,4 +264,4 @@ void ICACHE_FLASH_ATTR httpdPlatInit(int port, int maxConnCt) { } -#endif \ No newline at end of file +#endif diff --git a/core/httpd-nonos.c b/core/httpd-nonos.c index 410aa309..16f4cc94 100644 --- a/core/httpd-nonos.c +++ b/core/httpd-nonos.c @@ -2,9 +2,8 @@ ESP8266 web server - platform-dependent routines, nonos version */ -#include -#include "httpd.h" -#include "platform.h" +#include +#include #include "httpd-platform.h" #ifndef FREERTOS @@ -85,4 +84,4 @@ void ICACHE_FLASH_ATTR httpdPlatInit(int port, int maxConnCt) { } -#endif \ No newline at end of file +#endif diff --git a/core/httpd.c b/core/httpd.c index bb5b5f5b..5685db9d 100644 --- a/core/httpd.c +++ b/core/httpd.c @@ -12,8 +12,8 @@ Esp8266 http server - core routines */ -#include -#include "httpd.h" +#include +#include #include "httpd-platform.h" //This gets set at init time. diff --git a/core/httpdespfs.c b/core/httpdespfs.c index 0cbfeb80..1f917543 100644 --- a/core/httpdespfs.c +++ b/core/httpdespfs.c @@ -11,10 +11,10 @@ Connector to let httpd use the espfs filesystem to serve the files in it. * ---------------------------------------------------------------------------- */ -#include -#include "httpdespfs.h" -#include "espfs.h" -#include "espfsformat.h" +#include +#include +#include +#include // 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.) diff --git a/core/sha1.c b/core/sha1.c index 062db2c8..af4beb67 100644 --- a/core/sha1.c +++ b/core/sha1.c @@ -3,11 +3,8 @@ */ // gcc -Wall -DSHA1TEST -o sha1test sha1.c && ./sha1test -#include -#include -#include - -#include "sha1.h" +#include +#include //according to http://ip.cadence.com/uploads/pdf/xtensalx_overview_handbook.pdf // the cpu is normally defined as little ending, but can be big endian too. diff --git a/espfs/espfs.c b/espfs/espfs.c index d5270d2a..a8cf171c 100644 --- a/espfs/espfs.c +++ b/espfs/espfs.c @@ -20,7 +20,9 @@ It's written for use with httpd, but doesn't need to be used as such. #ifdef __ets__ //esp build -#include +#include +#include +#define spi_flash_read spiflash_read #else //Test build #include @@ -30,8 +32,9 @@ It's written for use with httpd, but doesn't need to be used as such. #define ICACHE_FLASH_ATTR #endif + +#include #include "espfsformat.h" -#include "espfs.h" #ifdef ESPFS_HEATSHRINK #include "heatshrink_config_custom.h" @@ -86,7 +89,7 @@ EspFsInitResult ICACHE_FLASH_ATTR espFsInit(void *flashAddress) { // check if there is valid header at address EspFsHeader testHeader; - spi_flash_read((uint32)flashAddress, (uint32*)&testHeader, sizeof(EspFsHeader)); + spi_flash_read((uint32_t)flashAddress, (uint8_t*)&testHeader, sizeof(EspFsHeader)); if (testHeader.magic != ESPFS_MAGIC) { return ESPFS_INIT_RESULT_NO_IMAGE; } @@ -105,7 +108,7 @@ void ICACHE_FLASH_ATTR readFlashUnaligned(char *dst, char *src, int len) { uint32_t src_address = ((uint32_t)src) - src_offset; uint32_t tmp_buf[len/4 + 2]; - spi_flash_read((uint32)src_address, (uint32*)tmp_buf, len+src_offset); + spi_flash_read((uint32_t)src_address, (uint8_t*)tmp_buf, len+src_offset); memcpy(dst, ((uint8_t*)tmp_buf)+src_offset, len); } #else @@ -141,7 +144,7 @@ EspFsFile ICACHE_FLASH_ATTR *espFsOpen(char *fileName) { while(1) { hpos=p; //Grab the next file header. - spi_flash_read((uint32)p, (uint32*)&h, sizeof(EspFsHeader)); + spi_flash_read((uint32_t)p, (uint8_t*)&h, sizeof(EspFsHeader)); if (h.magic!=ESPFS_MAGIC) { httpd_printf("Magic mismatch. EspFS image broken.\n"); @@ -153,7 +156,7 @@ EspFsFile ICACHE_FLASH_ATTR *espFsOpen(char *fileName) { } //Grab the name of the file. p+=sizeof(EspFsHeader); - spi_flash_read((uint32)p, (uint32*)&namebuf, sizeof(namebuf)); + spi_flash_read((uint32_t)p, (uint8_t*)&namebuf, sizeof(namebuf)); // httpd_printf("Found file '%s'. Namelen=%x fileLenComp=%x, compr=%d flags=%d\n", // namebuf, (unsigned int)h.nameLen, (unsigned int)h.fileLenComp, h.compression, h.flags); if (strcmp(namebuf, fileName)==0) { diff --git a/espfs/heatshrink_decoder.c b/espfs/heatshrink_decoder.c index bda1f63d..8b1d745e 100644 --- a/espfs/heatshrink_decoder.c +++ b/espfs/heatshrink_decoder.c @@ -1,4 +1,4 @@ -#include "espfs.h" +#include #ifdef ESPFS_HEATSHRINK //Stupid wrapper so we don't have to move c-files around //Also loads httpd-specific config. @@ -6,7 +6,7 @@ #ifdef __ets__ //esp build -#include +#include #endif diff --git a/espfs/mkespfsimage/main.c b/espfs/mkespfsimage/main.c index 39e31f57..83941114 100644 --- a/espfs/mkespfsimage/main.c +++ b/espfs/mkespfsimage/main.c @@ -9,8 +9,8 @@ #ifdef __MINGW32__ #include #endif -#include "espfs.h" -#include "espfsformat.h" +#include +#include //Heatshrink #ifdef ESPFS_HEATSHRINK diff --git a/include/auth.h b/include/libesphttpd/auth.h similarity index 100% rename from include/auth.h rename to include/libesphttpd/auth.h diff --git a/include/captdns.h b/include/libesphttpd/captdns.h similarity index 100% rename from include/captdns.h rename to include/libesphttpd/captdns.h diff --git a/include/cgiflash.h b/include/libesphttpd/cgiflash.h similarity index 100% rename from include/cgiflash.h rename to include/libesphttpd/cgiflash.h diff --git a/include/cgiwebsocket.h b/include/libesphttpd/cgiwebsocket.h similarity index 100% rename from include/cgiwebsocket.h rename to include/libesphttpd/cgiwebsocket.h diff --git a/include/cgiwifi.h b/include/libesphttpd/cgiwifi.h similarity index 100% rename from include/cgiwifi.h rename to include/libesphttpd/cgiwifi.h diff --git a/include/esp8266.h b/include/libesphttpd/esp8266.h similarity index 81% rename from include/esp8266.h rename to include/libesphttpd/esp8266.h index 7b685e45..a4a4e005 100644 --- a/include/esp8266.h +++ b/include/libesphttpd/esp8266.h @@ -2,12 +2,16 @@ // Actually misnamed, as it also works for ESP32. // ToDo: Figure out better name - #include #include #include #include +#ifdef ESPOPENRTOS +#define FREERTOS +#include +#endif + #ifdef FREERTOS #include @@ -29,6 +33,8 @@ #include #endif -#include "platform.h" -#include "espmissingincludes.h" +#include +#ifndef ESPOPENRTOS +#include "espmissingincludes.h" +#endif diff --git a/include/espfs.h b/include/libesphttpd/espfs.h similarity index 100% rename from include/espfs.h rename to include/libesphttpd/espfs.h diff --git a/include/espmissingincludes.h b/include/libesphttpd/espmissingincludes.h similarity index 100% rename from include/espmissingincludes.h rename to include/libesphttpd/espmissingincludes.h diff --git a/include/httpd.h b/include/libesphttpd/httpd.h similarity index 97% rename from include/httpd.h rename to include/libesphttpd/httpd.h index 73745ac7..563b52b6 100644 --- a/include/httpd.h +++ b/include/libesphttpd/httpd.h @@ -3,6 +3,8 @@ #define HTTPDVER "0.4" +#include + //Max length of request head. This is statically allocated for each connection. #define HTTPD_MAX_HEAD_LEN 1024 //Max post buffer len. This is dynamically malloc'ed if needed. @@ -48,8 +50,8 @@ struct HttpdConnData { cgiRecvHandler recvHdl; // Handler for data received after headers, if any HttpdPostData *post; // POST data structure int remote_port; // Remote TCP port - uint8 remote_ip[4]; // IP address of client - uint8 slot; // Slot ID + uint8_t remote_ip[4]; // IP address of client + uint8_t slot; // Slot ID }; //A struct describing the POST data sent inside the http connection. This is used by the CGI functions @@ -96,4 +98,4 @@ void httpdDisconCb(ConnTypePtr conn, char *remIp, int remPort); int httpdConnectCb(ConnTypePtr conn, char *remIp, int remPort); -#endif \ No newline at end of file +#endif diff --git a/include/httpdespfs.h b/include/libesphttpd/httpdespfs.h similarity index 80% rename from include/httpdespfs.h rename to include/libesphttpd/httpdespfs.h index 5eda3356..68e0cdae 100644 --- a/include/httpdespfs.h +++ b/include/libesphttpd/httpdespfs.h @@ -1,9 +1,9 @@ #ifndef HTTPDESPFS_H #define HTTPDESPFS_H -#include "httpd.h" +#include int cgiEspFsHook(HttpdConnData *connData); int ICACHE_FLASH_ATTR cgiEspFsTemplate(HttpdConnData *connData); -#endif \ No newline at end of file +#endif diff --git a/include/platform.h b/include/libesphttpd/platform.h similarity index 85% rename from include/platform.h rename to include/libesphttpd/platform.h index 27d392de..32db23bc 100644 --- a/include/platform.h +++ b/include/libesphttpd/platform.h @@ -1,10 +1,19 @@ #ifndef PLATFORM_H #define PLATFORM_H +#ifdef ESPOPENRTOS +#define FREERTOS +#endif + #ifdef FREERTOS //#include "esp_timer.h" typedef struct RtosConnType RtosConnType; typedef RtosConnType* ConnTypePtr; +#if defined(ESPOPENRTOS) +#define ICACHE_FLASH_ATTR +#define ICACHE_RODATA_ATTR +#define httpd_printf(fmt, ...) printf(fmt, ##__VA_ARGS__) +#else #if 0 //Unfortunately, this does not always work... the latest esp32 sdk, for example, breaks this. #define httpd_printf(fmt, ...) do { \ @@ -14,6 +23,7 @@ typedef RtosConnType* ConnTypePtr; #else #define httpd_printf(fmt, ...) os_printf(fmt, ##__VA_ARGS__) #endif +#endif #else #define printf(...) os_printf(__VA_ARGS__) #define sprintf(str, ...) os_sprintf(str, __VA_ARGS__) @@ -35,4 +45,4 @@ typedef struct espconn* ConnTypePtr; -#endif \ No newline at end of file +#endif diff --git a/include/sha1.h b/include/libesphttpd/sha1.h similarity index 100% rename from include/sha1.h rename to include/libesphttpd/sha1.h diff --git a/include/user_config.h b/include/libesphttpd/user_config.h similarity index 100% rename from include/user_config.h rename to include/libesphttpd/user_config.h diff --git a/include/webpages-espfs.h b/include/libesphttpd/webpages-espfs.h similarity index 100% rename from include/webpages-espfs.h rename to include/libesphttpd/webpages-espfs.h diff --git a/util/captdns.c b/util/captdns.c index 22589a63..14551fae 100644 --- a/util/captdns.c +++ b/util/captdns.c @@ -15,7 +15,7 @@ be used to send mobile phones, tablets etc which connect to the ESP in AP mode d the internal webserver. */ -#include +#include #ifdef FREERTOS #include "FreeRTOS.h" @@ -331,4 +331,4 @@ void ICACHE_FLASH_ATTR captdnsInit(void) { espconn_create(&conn); } -#endif \ No newline at end of file +#endif diff --git a/util/cgiflash.c b/util/cgiflash.c index 1a74c2ed..c6b42cd9 100644 --- a/util/cgiflash.c +++ b/util/cgiflash.c @@ -14,15 +14,11 @@ Some flash handling cgi routines. Used for updating the ESPFS/OTA image. //This doesn't work yet on the ESP32. ToDo: figure out how to make it work. #ifndef ESP32 -#include -#include "cgiflash.h" -#include "espfs.h" -#include "cgiflash.h" -#include "espfs.h" - -//#include -#include "cgiflash.h" -#include "espfs.h" +#include +#include +#include +#include +#include #ifndef UPGRADE_FLAG_FINISH #define UPGRADE_FLAG_FINISH 0x02 @@ -299,4 +295,4 @@ int ICACHE_FLASH_ATTR cgiRebootFirmware(HttpdConnData *connData) { return HTTPD_CGI_DONE; } -#endif \ No newline at end of file +#endif diff --git a/util/cgiwebsocket.c b/util/cgiwebsocket.c index bf1953e4..2a041746 100644 --- a/util/cgiwebsocket.c +++ b/util/cgiwebsocket.c @@ -12,11 +12,11 @@ Websocket support for esphttpd. Inspired by https://github.com/dangrie158/ESP-82 */ -#include -#include "httpd.h" -#include "sha1.h" -#include "base64.h" -#include "cgiwebsocket.h" +#include +#include +#include +#include +#include #define WS_KEY_IDENTIFIER "Sec-WebSocket-Key: " #define WS_GUID "258EAFA5-E914-47DA-95CA-C5AB0DC85B11" diff --git a/util/cgiwifi.c b/util/cgiwifi.c index 7a3b46a2..eb2d5420 100644 --- a/util/cgiwifi.c +++ b/util/cgiwifi.c @@ -12,8 +12,8 @@ Cgi/template routines for the /wifi url. */ -#include -#include "cgiwifi.h" +#include +#include //Enable this to disallow any changes in AP settings //#define DEMO_MODE From 9ade31bb0896208fdea53d677b20a8edb5f571db Mon Sep 17 00:00:00 2001 From: Jeff Kent Date: Wed, 28 Jun 2017 01:06:09 -0500 Subject: [PATCH 2/2] header fix --- include/libesphttpd/httpd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/libesphttpd/httpd.h b/include/libesphttpd/httpd.h index 563b52b6..3a33df54 100644 --- a/include/libesphttpd/httpd.h +++ b/include/libesphttpd/httpd.h @@ -3,7 +3,7 @@ #define HTTPDVER "0.4" -#include +#include //Max length of request head. This is statically allocated for each connection. #define HTTPD_MAX_HEAD_LEN 1024