diff --git a/Sming/Libraries/ArduCAM/ArduCAMStream.cpp b/Sming/Libraries/ArduCAM/ArduCAMStream.cpp index 5dad79555b..91564aa79c 100644 --- a/Sming/Libraries/ArduCAM/ArduCAMStream.cpp +++ b/Sming/Libraries/ArduCAM/ArduCAMStream.cpp @@ -99,7 +99,7 @@ uint16_t ArduCAMStream::readMemoryBlock(char* data, int bufSize) { } - int bytesread = min(len, bufSize); + int bytesread = min(len, (unsigned int)bufSize); ACAM_DEBUG("ArduCAMStream::readMemoryBlock [%d] (%d bytes) remaining (%d bytes)\n", bcount++, bytesread, len); diff --git a/Sming/Libraries/I2Cdev/I2Cdev.cpp b/Sming/Libraries/I2Cdev/I2Cdev.cpp index 3e65697ad3..25d9db0ca6 100644 --- a/Sming/Libraries/I2Cdev/I2Cdev.cpp +++ b/Sming/Libraries/I2Cdev/I2Cdev.cpp @@ -273,7 +273,7 @@ int8_t I2Cdev::readBytes(uint8_t devAddr, uint8_t regAddr, uint8_t length, uint8 // I2C/TWI subsystem uses internal buffer that breaks with large data requests // so if user requests more than BUFFER_LENGTH bytes, we have to do it in // smaller chunks instead of all at once - for (uint8_t k = 0; k < length; k += min(length, BUFFER_LENGTH)) { + for (uint8_t k = 0; k < length; k += min((unsigned int)length, (unsigned int)BUFFER_LENGTH)) { Wire.beginTransmission(devAddr); Wire.write(regAddr); Wire.endTransmission(); diff --git a/Sming/Makefile-project.mk b/Sming/Makefile-project.mk index 31bd35b751..cbb7170e4f 100644 --- a/Sming/Makefile-project.mk +++ b/Sming/Makefile-project.mk @@ -212,7 +212,8 @@ else ifeq ($(ENABLE_CUSTOM_LWIP), 2) endif EXTRA_INCDIR += $(SMING_HOME)/include $(SMING_HOME)/ $(LWIP_INCDIR) $(SMING_HOME)/system/include \ - $(SMING_HOME)/Wiring $(SMING_HOME)/Libraries $(SMING_HOME)/Libraries/Adafruit_GFX \ + $(SMING_HOME)/Wiring $(SMING_HOME)/Libraries \ + $(SMING_HOME)/Libraries/Adafruit_GFX $(SMING_HOME)/Libraries/Adafruit_Sensor \ $(SMING_HOME)/SmingCore $(SMING_HOME)/Services/SpifFS $(SDK_BASE)/../include \ $(THIRD_PARTY_DIR)/rboot $(THIRD_PARTY_DIR)/rboot/appcode $(THIRD_PARTY_DIR)/spiffs/src diff --git a/Sming/Makefile-rboot.mk b/Sming/Makefile-rboot.mk index 8ec37f3c3d..783504bd26 100644 --- a/Sming/Makefile-rboot.mk +++ b/Sming/Makefile-rboot.mk @@ -227,7 +227,8 @@ else ifeq ($(ENABLE_CUSTOM_LWIP), 2) endif EXTRA_INCDIR += $(SMING_HOME)/include $(SMING_HOME)/ $(LWIP_INCDIR) $(SMING_HOME)/system/include \ - $(SMING_HOME)/Wiring $(SMING_HOME)/Libraries $(SMING_HOME)/Libraries/Adafruit_GFX \ + $(SMING_HOME)/Wiring $(SMING_HOME)/Libraries \ + $(SMING_HOME)/Libraries/Adafruit_GFX $(SMING_HOME)/Libraries/Adafruit_Sensor \ $(SMING_HOME)/SmingCore $(SMING_HOME)/Services/SpifFS $(SDK_BASE)/../include \ $(THIRD_PARTY_DIR)/rboot $(THIRD_PARTY_DIR)/rboot/appcode $(THIRD_PARTY_DIR)/spiffs/src diff --git a/Sming/SmingCore/ArduinoCompat.h b/Sming/SmingCore/ArduinoCompat.h index 02ce660e25..fae1491513 100644 --- a/Sming/SmingCore/ArduinoCompat.h +++ b/Sming/SmingCore/ArduinoCompat.h @@ -19,6 +19,15 @@ extern "C" { #endif +#define abs(x) ((x)>0?(x):-(x)) +#ifndef min +#define min(a,b) ((a)<(b)?(a):(b)) +#endif +#ifndef max +#define max(a,b) ((a)>(b)?(a):(b)) +#endif +#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) + void yield(); #ifdef __cplusplus diff --git a/Sming/SmingCore/DataSourceStream.cpp b/Sming/SmingCore/DataSourceStream.cpp index 23f68bbb0a..9b44e43e6c 100644 --- a/Sming/SmingCore/DataSourceStream.cpp +++ b/Sming/SmingCore/DataSourceStream.cpp @@ -6,6 +6,7 @@ ****/ #include "../SmingCore/DataSourceStream.h" +#include int IDataSourceStream::read() { @@ -91,7 +92,7 @@ size_t MemoryDataStream::write(const uint8_t* data, size_t len) uint16_t MemoryDataStream::readMemoryBlock(char* data, int bufSize) { - int available = min(size - (pos - buf), bufSize); + int available = std::min(size - (pos - buf), bufSize); memcpy(data, pos, available); return available; } @@ -154,7 +155,7 @@ FileStream::~FileStream() uint16_t FileStream::readMemoryBlock(char* data, int bufSize) { - int len = min(bufSize, size - pos); + int len = std::min(bufSize, size - pos); int available = fileRead(handle, data, len); fileSeek(handle, pos, eSO_FileStart); // Don't move cursor now (waiting seek) if(available < 0) { @@ -250,7 +251,7 @@ uint16_t TemplateFileStream::readMemoryBlock(char* data, int bufSize) debug_d("var %s not found", varName.c_str()); state = eTES_Wait; int len = FileStream::readMemoryBlock(data, bufSize); - return min(len, skipBlockSize); + return std::min(len, skipBlockSize); } } else if (state == eTES_SendingVar) diff --git a/Sming/SmingCore/Interrupts.h b/Sming/SmingCore/Interrupts.h index 4c6db9b465..aae2f4608f 100644 --- a/Sming/SmingCore/Interrupts.h +++ b/Sming/SmingCore/Interrupts.h @@ -100,7 +100,7 @@ void noInterrupts(); */ void interrupts(); -#define digitalPinToInterrupt(pin) ( (p) < ESP_MAX_INTERRUPTS ? (p) : -1 ) +#define digitalPinToInterrupt(pin) ( (pin) < ESP_MAX_INTERRUPTS ? (pin) : -1 ) #define cli() noInterrupts() #define sei() interrupts() diff --git a/Sming/SmingCore/Network/Http/HttpConnection.cpp b/Sming/SmingCore/Network/Http/HttpConnection.cpp index a1b378ac54..883fcbf3b0 100644 --- a/Sming/SmingCore/Network/Http/HttpConnection.cpp +++ b/Sming/SmingCore/Network/Http/HttpConnection.cpp @@ -225,6 +225,7 @@ int HttpConnection::staticOnMessageComplete(http_parser* parser) if(connection->incomingRequest->responseStream != NULL) { connection->incomingRequest->responseStream->close(); delete connection->incomingRequest->responseStream; + connection->incomingRequest->responseStream = NULL; } delete connection->incomingRequest; diff --git a/Sming/SmingCore/Network/Http/HttpRequest.cpp b/Sming/SmingCore/Network/Http/HttpRequest.cpp index 84c616d1f1..70d517432f 100644 --- a/Sming/SmingCore/Network/Http/HttpRequest.cpp +++ b/Sming/SmingCore/Network/Http/HttpRequest.cpp @@ -12,6 +12,8 @@ #include "HttpRequest.h" +#include + HttpRequest::HttpRequest(const URL& uri) { this->uri = uri; } @@ -52,8 +54,10 @@ HttpRequest& HttpRequest::operator = (const HttpRequest& rhs) { HttpRequest::~HttpRequest() { delete queryParams; delete stream; + delete responseStream; queryParams = NULL; stream = NULL; + responseStream = NULL; } HttpRequest* HttpRequest::setURL(const URL& uri) { @@ -155,9 +159,9 @@ String HttpRequest::getBody() if(stream->available() != -1 && stream->getStreamType() == eSST_Memory) { MemoryDataStream *memory = (MemoryDataStream *)stream; char buf[1024]; - for(int i=0; i< stream->available(); i += 1024) { + while(stream->available() > 0) { int available = memory->readMemoryBlock(buf, 1024); - memory->seek(max(available, 0)); + memory->seek(std::max(available, 0)); ret += String(buf, available); if(available < 1024) { break; diff --git a/Sming/SmingCore/Network/Http/HttpServerConnection.cpp b/Sming/SmingCore/Network/Http/HttpServerConnection.cpp index c7c0e7fd0c..9d5919634d 100644 --- a/Sming/SmingCore/Network/Http/HttpServerConnection.cpp +++ b/Sming/SmingCore/Network/Http/HttpServerConnection.cpp @@ -90,7 +90,8 @@ int HttpServerConnection::staticOnMessageBegin(http_parser* parser) return 0; } -int HttpServerConnection::staticOnPath(http_parser *parser, const char *at, size_t length) { +int HttpServerConnection::staticOnPath(http_parser *parser, const char *at, size_t length) +{ HttpServerConnection *connection = (HttpServerConnection*)parser->data; if(connection == NULL) { // something went wrong @@ -150,6 +151,7 @@ int HttpServerConnection::staticOnMessageComplete(http_parser* parser) if(connection->request.responseStream != NULL) { connection->request.responseStream->close(); delete connection->request.responseStream; + connection->request.responseStream = NULL; } return hasError; @@ -175,7 +177,7 @@ int HttpServerConnection::staticOnHeadersComplete(http_parser* parser) * chunked' headers that indicate the presence of a body. * * Returning `2` from on_headers_complete will tell parser that it should not - * expect neither a body nor any futher responses on this connection. This is + * expect neither a body nor any further responses on this connection. This is * useful for handling responses to a CONNECT request which may not contain * `Upgrade` or `Connection: upgrade` headers. */ @@ -509,7 +511,8 @@ bool HttpServerConnection::sendResponseBody(HttpResponse *response) } -void HttpServerConnection::onError(err_t err) { +void HttpServerConnection::onError(err_t err) +{ TcpClient::onError(err); } diff --git a/Sming/SmingCore/Network/Http/Stream/HttpChunkedStream.cpp b/Sming/SmingCore/Network/Http/Stream/HttpChunkedStream.cpp index cd29889270..28761b03f5 100644 --- a/Sming/SmingCore/Network/Http/Stream/HttpChunkedStream.cpp +++ b/Sming/SmingCore/Network/Http/Stream/HttpChunkedStream.cpp @@ -1,5 +1,7 @@ #include "HttpChunkedStream.h" +#include + HttpChunkedStream::HttpChunkedStream(ReadWriteStream *stream) { this->stream = stream; @@ -43,7 +45,7 @@ uint16_t HttpChunkedStream::readMemoryBlock(char* data, int bufSize) int len = readSize; char buffer[len]; len = stream->readMemoryBlock(buffer, len); - stream->seek(max(len, 0)); + stream->seek(std::max(len, 0)); if(len < 1) { return 0; } diff --git a/Sming/SmingCore/Network/MqttClient.cpp b/Sming/SmingCore/Network/MqttClient.cpp index 4a05259f6d..60b9bdcc3a 100644 --- a/Sming/SmingCore/Network/MqttClient.cpp +++ b/Sming/SmingCore/Network/MqttClient.cpp @@ -47,7 +47,7 @@ void MqttClient::setPingRepeatTime(int seconds) { if (PingRepeatTime > keepAlive) PingRepeatTime = keepAlive; - else + else PingRepeatTime = seconds; } @@ -239,7 +239,7 @@ err_t MqttClient::onReceive(pbuf *buf) continue; } - int available = min(waitingSize, buf->tot_len - received); + int available = std::min(waitingSize, buf->tot_len - received); waitingSize -= available; if (current != NULL) { diff --git a/Sming/SmingCore/Network/TcpConnection.cpp b/Sming/SmingCore/Network/TcpConnection.cpp index e2d27829b8..faf70a116a 100644 --- a/Sming/SmingCore/Network/TcpConnection.cpp +++ b/Sming/SmingCore/Network/TcpConnection.cpp @@ -13,6 +13,8 @@ #include "../Wiring/WString.h" #include "../Wiring/IPAddress.h" +#include + TcpConnection::TcpConnection(bool autoDestruct) : autoSelfDestruct(autoDestruct), sleep(0), canSend(true), timeOut(70) { @@ -265,7 +267,7 @@ int TcpConnection::write(IDataSourceStream* stream) do { pushCount++; - int read = min(NETWORK_SEND_BUFFER_SIZE, getAvailableWriteSize()); + int read = std::min((uint16_t)NETWORK_SEND_BUFFER_SIZE, getAvailableWriteSize()); if (read > 0) available = stream->readMemoryBlock(buffer, read); else @@ -275,7 +277,7 @@ int TcpConnection::write(IDataSourceStream* stream) { int written = write(buffer, available, TCP_WRITE_FLAG_COPY | TCP_WRITE_FLAG_MORE); total += written; - stream->seek(max(written, 0)); + stream->seek(std::max(written, 0)); debug_d("Written: %d, Available: %d, isFinished: %d, PushCount: %d [TcpBuf: %d]", written, available, (stream->isFinished()?1:0), pushCount, tcp_sndbuf(tcp)); repeat = written == available && !stream->isFinished() && pushCount < 25; } diff --git a/Sming/SmingCore/SPI.cpp b/Sming/SmingCore/SPI.cpp index b3f1787485..3d97c7c606 100644 --- a/Sming/SmingCore/SPI.cpp +++ b/Sming/SmingCore/SPI.cpp @@ -197,7 +197,7 @@ void SPIClass::transfer(uint8 *buffer, size_t numberBytes) { while (blocks--) { // get full BLOCKSIZE or number of remaining bytes - bufLenght = min(numberBytes-bufIndx, BLOCKSIZE); + bufLenght = std::min(numberBytes-bufIndx, (unsigned int)BLOCKSIZE); #ifdef SPI_DEBUG debugf("Write/Read Block %d total %d bytes", total-blocks, bufLenght); @@ -453,7 +453,7 @@ void SPIClass::setFrequency(int freq) { return; } - freq = min(freq, _CPU_freq/2); + freq = std::min(freq, _CPU_freq/2); _SPISettings._speed = freq; diff --git a/Sming/SmingCore/SmingCore.h b/Sming/SmingCore/SmingCore.h index e44f7a510b..5c27fadeab 100644 --- a/Sming/SmingCore/SmingCore.h +++ b/Sming/SmingCore/SmingCore.h @@ -10,6 +10,8 @@ #define SMING_VERSION "3.5.1" // Major Minor Sub +#include + #include "../Wiring/WiringFrameworkIncludes.h" #include "Delegate.h" diff --git a/Sming/Wiring/WConstants.h b/Sming/Wiring/WConstants.h index 1b431d8398..4e461f9caf 100644 --- a/Sming/Wiring/WConstants.h +++ b/Sming/Wiring/WConstants.h @@ -114,8 +114,12 @@ #define sq(x) ((x)*(x)) //#define abs(x) ((x)>0?(x):-(x)) -#define min(a,b) ((a)<(b)?(a):(b)) -#define max(a,b) ((a)>(b)?(a):(b)) +//#ifndef min +//#define min(a,b) ((a)<(b)?(a):(b)) +//#endif +//#ifndef max +//#define max(a,b) ((a)>(b)?(a):(b)) +//#endif //#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) #define radians(deg) ((deg)*DEG_TO_RAD) #define degrees(rad) ((rad)*RAD_TO_DEG) diff --git a/Sming/appinit/user_main.cpp b/Sming/appinit/user_main.cpp index 8e57fe8eec..ae1b7918cd 100644 --- a/Sming/appinit/user_main.cpp +++ b/Sming/appinit/user_main.cpp @@ -68,3 +68,10 @@ extern "C" uint32 ICACHE_FLASH_ATTR __attribute__((weak)) user_rf_cal_sector_se return rf_cal_sec; } + +namespace std { + void __attribute__((weak)) __throw_bad_function_call() + { + while(1); + }; +} diff --git a/Sming/third-party/.patches/http-parser.patch b/Sming/third-party/.patches/http-parser.patch index 2e340f410e..9650d4f0e7 100644 --- a/Sming/third-party/.patches/http-parser.patch +++ b/Sming/third-party/.patches/http-parser.patch @@ -1,9 +1,9 @@ diff --git a/bench.c b/bench.c deleted file mode 100644 -index 5b452fa..0000000 +index 678f555..0000000 --- a/bench.c +++ /dev/null -@@ -1,111 +0,0 @@ +@@ -1,128 +0,0 @@ -/* Copyright Fedor Indutny. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -26,10 +26,14 @@ index 5b452fa..0000000 - */ -#include "http_parser.h" -#include +-#include -#include -#include -#include - +-/* 8 gb */ +-static const int64_t kBytes = 8LL << 30; +- -static const char data[] = - "POST /joyent/http-parser HTTP/1.1\r\n" - "Host: github.com\r\n" @@ -44,7 +48,7 @@ index 5b452fa..0000000 - "Referer: https://github.com/joyent/http-parser\r\n" - "Connection: keep-alive\r\n" - "Transfer-Encoding: chunked\r\n" -- "Cache-Control: max-age=0\r\n\r\nb\r\nhello world\r\n0\r\n\r\n"; +- "Cache-Control: max-age=0\r\n\r\nb\r\nhello world\r\n0\r\n"; -static const size_t data_len = sizeof(data) - 1; - -static int on_info(http_parser* p) { @@ -73,13 +77,13 @@ index 5b452fa..0000000 - int err; - struct timeval start; - struct timeval end; -- float rps; - - if (!silent) { - err = gettimeofday(&start, NULL); - assert(err == 0); - } - +- fprintf(stderr, "req_len=%d\n", (int) data_len); - for (i = 0; i < iter_count; i++) { - size_t parsed; - http_parser_init(&parser, HTTP_REQUEST); @@ -89,17 +93,27 @@ index 5b452fa..0000000 - } - - if (!silent) { +- double elapsed; +- double bw; +- double total; +- - err = gettimeofday(&end, NULL); - assert(err == 0); - - fprintf(stdout, "Benchmark result:\n"); - -- rps = (float) (end.tv_sec - start.tv_sec) + -- (end.tv_usec - start.tv_usec) * 1e-6f; -- fprintf(stdout, "Took %f seconds to run\n", rps); +- elapsed = (double) (end.tv_sec - start.tv_sec) + +- (end.tv_usec - start.tv_usec) * 1e-6f; +- +- total = (double) iter_count * data_len; +- bw = (double) total / elapsed; +- +- fprintf(stdout, "%.2f mb | %.2f mb/s | %.2f req/sec | %.2f s\n", +- (double) total / (1024 * 1024), +- bw / (1024 * 1024), +- (double) iter_count / elapsed, +- elapsed); - -- rps = (float) iter_count / rps; -- fprintf(stdout, "%f req/sec\n", rps); - fflush(stdout); - } - @@ -107,45 +121,47 @@ index 5b452fa..0000000 -} - -int main(int argc, char** argv) { +- int64_t iterations; +- +- iterations = kBytes / (int64_t) data_len; - if (argc == 2 && strcmp(argv[1], "infinite") == 0) { - for (;;) -- bench(5000000, 1); +- bench(iterations, 1); - return 0; - } else { -- return bench(5000000, 0); +- return bench(iterations, 0); - } -} diff --git a/http_parser.c b/http_parser.c -index 895bf0c..050d0b7 100644 +index 5b5657b..e7a2b3d 100644 --- a/http_parser.c +++ b/http_parser.c -@@ -22,13 +22,23 @@ +@@ -19,12 +19,22 @@ * IN THE SOFTWARE. */ #include "http_parser.h" -#include -#include +#ifdef __ets__ -+ #include ++ #include +#endif #include - #include #include #include +#ifdef __ets__ -+ #include -+ #include "m_printf.h" -+ #undef assert -+ #define assert(condition) if (!(condition)) m_printf("ASSERT: %s %d", __FUNCTION__, __LINE__) ++ #include ++ #include "m_printf.h" ++ #undef assert ++ #define assert(condition) if (!(condition)) m_printf("ASSERT: %s %d", __FUNCTION__, __LINE__) +#else -+ #include ++ #include +#endif + #ifndef ULLONG_MAX # define ULLONG_MAX ((uint64_t) -1) /* 2^64-1 */ #endif -@@ -186,7 +196,7 @@ static const char *method_strings[] = +@@ -182,7 +192,7 @@ static const char *method_strings[] = * | "/" | "[" | "]" | "?" | "=" * | "{" | "}" | SP | HT */ @@ -154,7 +170,7 @@ index 895bf0c..050d0b7 100644 /* 0 nul 1 soh 2 stx 3 etx 4 eot 5 enq 6 ack 7 bel */ 0, 0, 0, 0, 0, 0, 0, 0, /* 8 bs 9 ht 10 nl 11 vt 12 np 13 cr 14 so 15 si */ -@@ -221,7 +231,7 @@ static const char tokens[256] = { +@@ -217,7 +227,7 @@ static const char tokens[256] = { 'x', 'y', 'z', 0, '|', 0, '~', 0 }; @@ -163,7 +179,7 @@ index 895bf0c..050d0b7 100644 {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 -@@ -240,7 +250,7 @@ static const int8_t unhex[256] = +@@ -236,7 +246,7 @@ static const int8_t unhex[256] = #endif @@ -174,10 +190,10 @@ index 895bf0c..050d0b7 100644 /* 8 bs 9 ht 10 nl 11 vt 12 np 13 cr 14 so 15 si */ diff --git a/test.c b/test.c deleted file mode 100644 -index f5744aa..0000000 +index bc4e664..0000000 --- a/test.c +++ /dev/null -@@ -1,4226 +0,0 @@ +@@ -1,4456 +0,0 @@ -/* Copyright Joyent, Inc. and other Node contributors. All rights reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -258,6 +274,7 @@ index f5744aa..0000000 - int message_begin_cb_called; - int headers_complete_cb_called; - int message_complete_cb_called; +- int status_cb_called; - int message_complete_on_eof; - int body_is_final; -}; @@ -1311,7 +1328,7 @@ index f5744aa..0000000 - } - -#define UNLINK_REQUEST 41 --, {.name = "link request" +-, {.name = "unlink request" - ,.type= HTTP_REQUEST - ,.raw= "UNLINK /images/my_dog.jpg HTTP/1.1\r\n" - "Host: example.com\r\n" @@ -1333,6 +1350,26 @@ index f5744aa..0000000 - ,.body= "" - } - +-#define SOURCE_REQUEST 42 +-, {.name = "source request" +- ,.type= HTTP_REQUEST +- ,.raw= "SOURCE /music/sweet/music HTTP/1.1\r\n" +- "Host: example.com\r\n" +- "\r\n" +- ,.should_keep_alive= TRUE +- ,.message_complete_on_eof= FALSE +- ,.http_major= 1 +- ,.http_minor= 1 +- ,.method= HTTP_SOURCE +- ,.request_path= "/music/sweet/music" +- ,.request_url= "/music/sweet/music" +- ,.query_string= "" +- ,.fragment= "" +- ,.num_headers= 1 +- ,.headers= { { "Host", "example.com" } } +- ,.body= "" +- } +- -, {.name= NULL } /* sentinel */ -}; - @@ -1951,6 +1988,167 @@ index f5744aa..0000000 - ,.chunk_lengths= { 2 } - } - +-#define HTTP_101_RESPONSE_WITH_UPGRADE_HEADER 22 +-, {.name= "HTTP 101 response with Upgrade header" +- ,.type= HTTP_RESPONSE +- ,.raw= "HTTP/1.1 101 Switching Protocols\r\n" +- "Connection: upgrade\r\n" +- "Upgrade: h2c\r\n" +- "\r\n" +- "proto" +- ,.should_keep_alive= TRUE +- ,.message_complete_on_eof= FALSE +- ,.http_major= 1 +- ,.http_minor= 1 +- ,.status_code= 101 +- ,.response_status= "Switching Protocols" +- ,.upgrade= "proto" +- ,.num_headers= 2 +- ,.headers= +- { { "Connection", "upgrade" } +- , { "Upgrade", "h2c" } +- } +- } +- +-#define HTTP_101_RESPONSE_WITH_UPGRADE_HEADER_AND_CONTENT_LENGTH 23 +-, {.name= "HTTP 101 response with Upgrade and Content-Length header" +- ,.type= HTTP_RESPONSE +- ,.raw= "HTTP/1.1 101 Switching Protocols\r\n" +- "Connection: upgrade\r\n" +- "Upgrade: h2c\r\n" +- "Content-Length: 4\r\n" +- "\r\n" +- "body" +- "proto" +- ,.should_keep_alive= TRUE +- ,.message_complete_on_eof= FALSE +- ,.http_major= 1 +- ,.http_minor= 1 +- ,.status_code= 101 +- ,.response_status= "Switching Protocols" +- ,.body= "body" +- ,.upgrade= "proto" +- ,.num_headers= 3 +- ,.headers= +- { { "Connection", "upgrade" } +- , { "Upgrade", "h2c" } +- , { "Content-Length", "4" } +- } +- } +- +-#define HTTP_101_RESPONSE_WITH_UPGRADE_HEADER_AND_TRANSFER_ENCODING 24 +-, {.name= "HTTP 101 response with Upgrade and Transfer-Encoding header" +- ,.type= HTTP_RESPONSE +- ,.raw= "HTTP/1.1 101 Switching Protocols\r\n" +- "Connection: upgrade\r\n" +- "Upgrade: h2c\r\n" +- "Transfer-Encoding: chunked\r\n" +- "\r\n" +- "2\r\n" +- "bo\r\n" +- "2\r\n" +- "dy\r\n" +- "0\r\n" +- "\r\n" +- "proto" +- ,.should_keep_alive= TRUE +- ,.message_complete_on_eof= FALSE +- ,.http_major= 1 +- ,.http_minor= 1 +- ,.status_code= 101 +- ,.response_status= "Switching Protocols" +- ,.body= "body" +- ,.upgrade= "proto" +- ,.num_headers= 3 +- ,.headers= +- { { "Connection", "upgrade" } +- , { "Upgrade", "h2c" } +- , { "Transfer-Encoding", "chunked" } +- } +- ,.num_chunks_complete= 3 +- ,.chunk_lengths= { 2, 2 } +- } +- +-#define HTTP_200_RESPONSE_WITH_UPGRADE_HEADER 25 +-, {.name= "HTTP 200 response with Upgrade header" +- ,.type= HTTP_RESPONSE +- ,.raw= "HTTP/1.1 200 OK\r\n" +- "Connection: upgrade\r\n" +- "Upgrade: h2c\r\n" +- "\r\n" +- "body" +- ,.should_keep_alive= FALSE +- ,.message_complete_on_eof= TRUE +- ,.http_major= 1 +- ,.http_minor= 1 +- ,.status_code= 200 +- ,.response_status= "OK" +- ,.body= "body" +- ,.upgrade= NULL +- ,.num_headers= 2 +- ,.headers= +- { { "Connection", "upgrade" } +- , { "Upgrade", "h2c" } +- } +- } +- +-#define HTTP_200_RESPONSE_WITH_UPGRADE_HEADER_AND_CONTENT_LENGTH 26 +-, {.name= "HTTP 200 response with Upgrade and Content-Length header" +- ,.type= HTTP_RESPONSE +- ,.raw= "HTTP/1.1 200 OK\r\n" +- "Connection: upgrade\r\n" +- "Upgrade: h2c\r\n" +- "Content-Length: 4\r\n" +- "\r\n" +- "body" +- ,.should_keep_alive= TRUE +- ,.message_complete_on_eof= FALSE +- ,.http_major= 1 +- ,.http_minor= 1 +- ,.status_code= 200 +- ,.response_status= "OK" +- ,.num_headers= 3 +- ,.body= "body" +- ,.upgrade= NULL +- ,.headers= +- { { "Connection", "upgrade" } +- , { "Upgrade", "h2c" } +- , { "Content-Length", "4" } +- } +- } +- +-#define HTTP_200_RESPONSE_WITH_UPGRADE_HEADER_AND_TRANSFER_ENCODING 27 +-, {.name= "HTTP 200 response with Upgrade and Transfer-Encoding header" +- ,.type= HTTP_RESPONSE +- ,.raw= "HTTP/1.1 200 OK\r\n" +- "Connection: upgrade\r\n" +- "Upgrade: h2c\r\n" +- "Transfer-Encoding: chunked\r\n" +- "\r\n" +- "2\r\n" +- "bo\r\n" +- "2\r\n" +- "dy\r\n" +- "0\r\n" +- "\r\n" +- ,.should_keep_alive= TRUE +- ,.message_complete_on_eof= FALSE +- ,.http_major= 1 +- ,.http_minor= 1 +- ,.status_code= 200 +- ,.response_status= "OK" +- ,.num_headers= 3 +- ,.body= "body" +- ,.upgrade= NULL +- ,.headers= +- { { "Connection", "upgrade" } +- , { "Upgrade", "h2c" } +- , { "Transfer-Encoding", "chunked" } +- } +- ,.num_chunks_complete= 3 +- ,.chunk_lengths= { 2, 2 } +- } +- -, {.name= NULL } /* sentinel */ -}; - @@ -2161,6 +2359,9 @@ index f5744aa..0000000 -response_status_cb (http_parser *p, const char *buf, size_t len) -{ - assert(p == parser); +- +- messages[num_messages].status_cb_called = TRUE; +- - strlncat(messages[num_messages].response_status, - sizeof(messages[num_messages].response_status), - buf, @@ -2585,6 +2786,7 @@ index f5744aa..0000000 - } else { - MESSAGE_CHECK_NUM_EQ(expected, m, status_code); - MESSAGE_CHECK_STR_EQ(expected, m, response_status); +- assert(m->status_cb_called); - } - - if (!connect) { @@ -2656,7 +2858,9 @@ index f5744aa..0000000 - if (!r) return 0; - } - -- MESSAGE_CHECK_STR_EQ(expected, m, upgrade); +- if (!connect) { +- MESSAGE_CHECK_STR_EQ(expected, m, upgrade); +- } - - return 1; -} @@ -3493,9 +3697,11 @@ index f5744aa..0000000 -} - -void --test_simple (const char *buf, enum http_errno err_expected) +-test_simple_type (const char *buf, +- enum http_errno err_expected, +- enum http_parser_type type) -{ -- parser_init(HTTP_REQUEST); +- parser_init(type); - - enum http_errno err; - @@ -3520,6 +3726,12 @@ index f5744aa..0000000 -} - -void +-test_simple (const char *buf, enum http_errno err_expected) +-{ +- test_simple_type(buf, err_expected, HTTP_REQUEST); +-} +- +-void -test_invalid_header_content (int req, const char* str) -{ - http_parser parser; @@ -3669,6 +3881,30 @@ index f5744aa..0000000 -} - -void +-test_no_overflow_parse_url (void) +-{ +- int rv; +- struct http_parser_url u; +- +- http_parser_url_init(&u); +- rv = http_parser_parse_url("http://example.com:8001", 22, 0, &u); +- +- if (rv != 0) { +- fprintf(stderr, +- "\n*** test_no_overflow_parse_url invalid return value=%d\n", +- rv); +- abort(); +- } +- +- if (u.port != 800) { +- fprintf(stderr, +- "\n*** test_no_overflow_parse_url invalid port number=%d\n", +- u.port); +- abort(); +- } +-} +- +-void -test_header_overflow_error (int req) -{ - http_parser parser; @@ -4103,6 +4339,7 @@ index f5744aa..0000000 - test_header_nread_value(); - - //// OVERFLOW CONDITIONS +- test_no_overflow_parse_url(); - - test_header_overflow_error(HTTP_REQUEST); - test_no_overflow_long_body(HTTP_REQUEST, 1000); @@ -4129,6 +4366,12 @@ index f5744aa..0000000 - - //// RESPONSES - +- test_simple_type("HTP/1.1 200 OK\r\n\r\n", HPE_INVALID_VERSION, HTTP_RESPONSE); +- test_simple_type("HTTP/01.1 200 OK\r\n\r\n", HPE_INVALID_VERSION, HTTP_RESPONSE); +- test_simple_type("HTTP/11.1 200 OK\r\n\r\n", HPE_INVALID_VERSION, HTTP_RESPONSE); +- test_simple_type("HTTP/1.01 200 OK\r\n\r\n", HPE_INVALID_VERSION, HTTP_RESPONSE); +- test_simple_type("HTTP/1.1\t200 OK\r\n\r\n", HPE_INVALID_VERSION, HTTP_RESPONSE); +- - for (i = 0; i < response_count; i++) { - test_message(&responses[i]); - } @@ -4206,6 +4449,9 @@ index f5744aa..0000000 - /// REQUESTS - - test_simple("GET / HTP/1.1\r\n\r\n", HPE_INVALID_VERSION); +- test_simple("GET / HTTP/01.1\r\n\r\n", HPE_INVALID_VERSION); +- test_simple("GET / HTTP/11.1\r\n\r\n", HPE_INVALID_VERSION); +- test_simple("GET / HTTP/1.01\r\n\r\n", HPE_INVALID_VERSION); - - // Extended characters - see nodejs/test/parallel/test-http-headers-obstext.js - test_simple("GET / HTTP/1.1\r\n" diff --git a/Sming/third-party/.patches/pwm.patch b/Sming/third-party/.patches/pwm.patch index bd2b382c65..26fb1037ad 100644 --- a/Sming/third-party/.patches/pwm.patch +++ b/Sming/third-party/.patches/pwm.patch @@ -1,5 +1,5 @@ diff --git a/pwm.c b/pwm.c -index 5e7f218..0386a06 100644 +index 6df21ac..d039908 100644 --- a/pwm.c +++ b/pwm.c @@ -16,6 +16,8 @@ @@ -11,12 +11,14 @@ index 5e7f218..0386a06 100644 /* Set the following three defines to your needs */ #ifndef SDK_PWM_PERIOD_COMPAT_MODE -@@ -109,7 +111,7 @@ struct timer_regs { +@@ -109,8 +111,8 @@ struct timer_regs { }; - static struct timer_regs* timer = (void*)(0x60000600); + static struct timer_regs* timer = (struct timer_regs*)(0x60000600); --static void pwm_intr_handler(void) -+static void pwm_intr_handler(void* param) +-static void ICACHE_RAM_ATTR +-pwm_intr_handler(void) ++static void IRAM_ATTR ++pwm_intr_handler(void* param) { if ((pwm_state.current_set[pwm_state.current_phase].off_mask == 0) && (pwm_state.current_set[pwm_state.current_phase].on_mask == 0)) { diff --git a/Sming/third-party/http-parser/LICENSE-MIT b/Sming/third-party/http-parser/LICENSE-MIT index 58010b3889..1ec0ab4e17 100644 --- a/Sming/third-party/http-parser/LICENSE-MIT +++ b/Sming/third-party/http-parser/LICENSE-MIT @@ -1,8 +1,4 @@ -http_parser.c is based on src/http/ngx_http_parse.c from NGINX copyright -Igor Sysoev. - -Additional changes are licensed under the same terms as NGINX and -copyright Joyent, Inc. and other Node contributors. All rights reserved. +Copyright Joyent, Inc. and other Node contributors. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to diff --git a/Sming/third-party/http-parser/Makefile b/Sming/third-party/http-parser/Makefile index b2476dbd4a..6cf63bd35e 100644 --- a/Sming/third-party/http-parser/Makefile +++ b/Sming/third-party/http-parser/Makefile @@ -21,16 +21,22 @@ PLATFORM ?= $(shell sh -c 'uname -s | tr "[A-Z]" "[a-z]"') HELPER ?= BINEXT ?= +SOLIBNAME = libhttp_parser +SOMAJOR = 2 +SOMINOR = 8 +SOREV = 0 ifeq (darwin,$(PLATFORM)) -SONAME ?= libhttp_parser.2.7.1.dylib SOEXT ?= dylib +SONAME ?= $(SOLIBNAME).$(SOMAJOR).$(SOMINOR).$(SOEXT) +LIBNAME ?= $(SOLIBNAME).$(SOMAJOR).$(SOMINOR).$(SOREV).$(SOEXT) else ifeq (wine,$(PLATFORM)) CC = winegcc BINEXT = .exe.so HELPER = wine else -SONAME ?= libhttp_parser.so.2.7.1 SOEXT ?= so +SONAME ?= $(SOLIBNAME).$(SOEXT).$(SOMAJOR).$(SOMINOR) +LIBNAME ?= $(SOLIBNAME).$(SOEXT).$(SOMAJOR).$(SOMINOR).$(SOREV) endif CC?=gcc @@ -55,11 +61,13 @@ CFLAGS_LIB = $(CFLAGS_FAST) -fPIC LDFLAGS_LIB = $(LDFLAGS) -shared INSTALL ?= install -PREFIX ?= $(DESTDIR)/usr/local +PREFIX ?= /usr/local LIBDIR = $(PREFIX)/lib INCLUDEDIR = $(PREFIX)/include -ifneq (darwin,$(PLATFORM)) +ifeq (darwin,$(PLATFORM)) +LDFLAGS_LIB += -Wl,-install_name,$(LIBDIR)/$(SONAME) +else # TODO(bnoordhuis) The native SunOS linker expects -h rather than -soname... LDFLAGS_LIB += -Wl,-soname=$(SONAME) endif @@ -102,7 +110,7 @@ libhttp_parser.o: http_parser.c http_parser.h Makefile $(CC) $(CPPFLAGS_FAST) $(CFLAGS_LIB) -c http_parser.c -o libhttp_parser.o library: libhttp_parser.o - $(CC) $(LDFLAGS_LIB) -o $(SONAME) $< + $(CC) $(LDFLAGS_LIB) -o $(LIBNAME) $< package: http_parser.o $(AR) rcs libhttp_parser.a http_parser.o @@ -123,19 +131,22 @@ tags: http_parser.c http_parser.h test.c ctags $^ install: library - $(INSTALL) -D http_parser.h $(INCLUDEDIR)/http_parser.h - $(INSTALL) -D $(SONAME) $(LIBDIR)/$(SONAME) - ln -s $(LIBDIR)/$(SONAME) $(LIBDIR)/libhttp_parser.$(SOEXT) + $(INSTALL) -D http_parser.h $(DESTDIR)$(INCLUDEDIR)/http_parser.h + $(INSTALL) -D $(LIBNAME) $(DESTDIR)$(LIBDIR)/$(LIBNAME) + ln -s $(LIBNAME) $(DESTDIR)$(LIBDIR)/$(SONAME) + ln -s $(LIBNAME) $(DESTDIR)$(LIBDIR)/$(SOLIBNAME).$(SOEXT) install-strip: library - $(INSTALL) -D http_parser.h $(INCLUDEDIR)/http_parser.h - $(INSTALL) -D -s $(SONAME) $(LIBDIR)/$(SONAME) - ln -s $(LIBDIR)/$(SONAME) $(LIBDIR)/libhttp_parser.$(SOEXT) + $(INSTALL) -D http_parser.h $(DESTDIR)$(INCLUDEDIR)/http_parser.h + $(INSTALL) -D -s $(LIBNAME) $(DESTDIR)$(LIBDIR)/$(LIBNAME) + ln -s $(LIBNAME) $(DESTDIR)$(LIBDIR)/$(SONAME) + ln -s $(LIBNAME) $(DESTDIR)$(LIBDIR)/$(SOLIBNAME).$(SOEXT) uninstall: - rm $(INCLUDEDIR)/http_parser.h - rm $(LIBDIR)/$(SONAME) - rm $(LIBDIR)/libhttp_parser.so + rm $(DESTDIR)$(INCLUDEDIR)/http_parser.h + rm $(DESTDIR)$(LIBDIR)/$(SOLIBNAME).$(SOEXT) + rm $(DESTDIR)$(LIBDIR)/$(SONAME) + rm $(DESTDIR)$(LIBDIR)/$(LIBNAME) clean: rm -f *.o *.a tags test test_fast test_g \ diff --git a/Sming/third-party/http-parser/README.md b/Sming/third-party/http-parser/README.md index 439b30998d..b265d71715 100644 --- a/Sming/third-party/http-parser/README.md +++ b/Sming/third-party/http-parser/README.md @@ -72,9 +72,9 @@ if (parser->upgrade) { } ``` -HTTP needs to know where the end of the stream is. For example, sometimes +`http_parser` needs to know where the end of the stream is. For example, sometimes servers send responses without Content-Length and expect the client to -consume input (for the body) until EOF. To tell http_parser about EOF, give +consume input (for the body) until EOF. To tell `http_parser` about EOF, give `0` as the fourth parameter to `http_parser_execute()`. Callbacks and errors can still be encountered during an EOF, so one must still be prepared to receive them. @@ -93,7 +93,7 @@ the on_body callback. The Special Problem of Upgrade ------------------------------ -HTTP supports upgrading the connection to a different protocol. An +`http_parser` supports upgrading the connection to a different protocol. An increasingly common example of this is the WebSocket protocol which sends a request like @@ -144,7 +144,7 @@ parse a request, and then give a response over that socket. By instantiation of a thread-local struct containing relevant data (e.g. accepted socket, allocated memory for callbacks to write into, etc), a parser's callbacks are able to communicate data between the scope of the thread and the scope of the -callback in a threadsafe manner. This allows http-parser to be used in +callback in a threadsafe manner. This allows `http_parser` to be used in multi-threaded contexts. Example: @@ -202,7 +202,7 @@ void http_parser_thread(socket_t sock) { In case you parse HTTP message in chunks (i.e. `read()` request line from socket, parse, read half headers, parse, etc) your data callbacks -may be called more than once. Http-parser guarantees that data pointer is only +may be called more than once. `http_parser` guarantees that data pointer is only valid for the lifetime of callback. You can also `read()` into a heap allocated buffer to avoid copying memory around if this fits your application. diff --git a/Sming/third-party/http-parser/contrib/parsertrace.c b/Sming/third-party/http-parser/contrib/parsertrace.c index e7153680f4..3daa7f46a1 100644 --- a/Sming/third-party/http-parser/contrib/parsertrace.c +++ b/Sming/third-party/http-parser/contrib/parsertrace.c @@ -1,7 +1,4 @@ -/* Based on src/http/ngx_http_parse.c from NGINX copyright Igor Sysoev - * - * Additional changes are licensed under the same terms as NGINX and - * copyright Joyent, Inc. and other Node contributors. All rights reserved. +/* Copyright Joyent, Inc. and other Node contributors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to diff --git a/Sming/third-party/http-parser/http_parser.c b/Sming/third-party/http-parser/http_parser.c index 050d0b761e..e7a2b3de24 100644 --- a/Sming/third-party/http-parser/http_parser.c +++ b/Sming/third-party/http-parser/http_parser.c @@ -1,7 +1,4 @@ -/* Based on src/http/ngx_http_parse.c from NGINX copyright Igor Sysoev - * - * Additional changes are licensed under the same terms as NGINX and - * copyright Joyent, Inc. and other Node contributors. All rights reserved. +/* Copyright Joyent, Inc. and other Node contributors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to @@ -23,20 +20,19 @@ */ #include "http_parser.h" #ifdef __ets__ - #include + #include #endif #include -#include #include #include #ifdef __ets__ - #include - #include "m_printf.h" - #undef assert - #define assert(condition) if (!(condition)) m_printf("ASSERT: %s %d", __FUNCTION__, __LINE__) + #include + #include "m_printf.h" + #undef assert + #define assert(condition) if (!(condition)) m_printf("ASSERT: %s %d", __FUNCTION__, __LINE__) #else - #include + #include #endif #ifndef ULLONG_MAX @@ -296,10 +292,10 @@ enum state , s_res_HT , s_res_HTT , s_res_HTTP - , s_res_first_http_major , s_res_http_major - , s_res_first_http_minor + , s_res_http_dot , s_res_http_minor + , s_res_http_end , s_res_first_status_code , s_res_status_code , s_res_status_start @@ -326,10 +322,10 @@ enum state , s_req_http_HT , s_req_http_HTT , s_req_http_HTTP - , s_req_first_http_major , s_req_http_major - , s_req_first_http_minor + , s_req_http_dot , s_req_http_minor + , s_req_http_end , s_req_line_almost_done , s_header_field_start @@ -805,75 +801,48 @@ size_t http_parser_execute (http_parser *parser, case s_res_HTTP: STRICT_CHECK(ch != '/'); - UPDATE_STATE(s_res_first_http_major); + UPDATE_STATE(s_res_http_major); break; - case s_res_first_http_major: - if (UNLIKELY(ch < '0' || ch > '9')) { + case s_res_http_major: + if (UNLIKELY(!IS_NUM(ch))) { SET_ERRNO(HPE_INVALID_VERSION); goto error; } parser->http_major = ch - '0'; - UPDATE_STATE(s_res_http_major); + UPDATE_STATE(s_res_http_dot); break; - /* major HTTP version or dot */ - case s_res_http_major: + case s_res_http_dot: { - if (ch == '.') { - UPDATE_STATE(s_res_first_http_minor); - break; - } - - if (!IS_NUM(ch)) { - SET_ERRNO(HPE_INVALID_VERSION); - goto error; - } - - parser->http_major *= 10; - parser->http_major += ch - '0'; - - if (UNLIKELY(parser->http_major > 999)) { + if (UNLIKELY(ch != '.')) { SET_ERRNO(HPE_INVALID_VERSION); goto error; } + UPDATE_STATE(s_res_http_minor); break; } - /* first digit of minor HTTP version */ - case s_res_first_http_minor: + case s_res_http_minor: if (UNLIKELY(!IS_NUM(ch))) { SET_ERRNO(HPE_INVALID_VERSION); goto error; } parser->http_minor = ch - '0'; - UPDATE_STATE(s_res_http_minor); + UPDATE_STATE(s_res_http_end); break; - /* minor HTTP version or end of request line */ - case s_res_http_minor: + case s_res_http_end: { - if (ch == ' ') { - UPDATE_STATE(s_res_first_status_code); - break; - } - - if (UNLIKELY(!IS_NUM(ch))) { - SET_ERRNO(HPE_INVALID_VERSION); - goto error; - } - - parser->http_minor *= 10; - parser->http_minor += ch - '0'; - - if (UNLIKELY(parser->http_minor > 999)) { + if (UNLIKELY(ch != ' ')) { SET_ERRNO(HPE_INVALID_VERSION); goto error; } + UPDATE_STATE(s_res_first_status_code); break; } @@ -900,10 +869,9 @@ size_t http_parser_execute (http_parser *parser, UPDATE_STATE(s_res_status_start); break; case CR: - UPDATE_STATE(s_res_line_almost_done); - break; case LF: - UPDATE_STATE(s_header_field_start); + UPDATE_STATE(s_res_status_start); + REEXECUTE(); break; default: SET_ERRNO(HPE_INVALID_STATUS); @@ -925,19 +893,13 @@ size_t http_parser_execute (http_parser *parser, case s_res_status_start: { - if (ch == CR) { - UPDATE_STATE(s_res_line_almost_done); - break; - } - - if (ch == LF) { - UPDATE_STATE(s_header_field_start); - break; - } - MARK(status); UPDATE_STATE(s_res_status); parser->index = 0; + + if (ch == CR || ch == LF) + REEXECUTE(); + break; } @@ -990,7 +952,7 @@ size_t http_parser_execute (http_parser *parser, /* or PROPFIND|PROPPATCH|PUT|PATCH|PURGE */ break; case 'R': parser->method = HTTP_REPORT; /* or REBIND */ break; - case 'S': parser->method = HTTP_SUBSCRIBE; /* or SEARCH */ break; + case 'S': parser->method = HTTP_SUBSCRIBE; /* or SEARCH, SOURCE */ break; case 'T': parser->method = HTTP_TRACE; break; case 'U': parser->method = HTTP_UNLOCK; /* or UNSUBSCRIBE, UNBIND, UNLINK */ break; default: @@ -1017,7 +979,7 @@ size_t http_parser_execute (http_parser *parser, UPDATE_STATE(s_req_spaces_before_url); } else if (ch == matcher[parser->index]) { ; /* nada */ - } else if (IS_ALPHA(ch)) { + } else if ((ch >= 'A' && ch <= 'Z') || ch == '-') { switch (parser->method << 16 | parser->index << 8 | ch) { #define XX(meth, pos, ch, new_meth) \ @@ -1026,31 +988,28 @@ size_t http_parser_execute (http_parser *parser, XX(POST, 1, 'U', PUT) XX(POST, 1, 'A', PATCH) + XX(POST, 1, 'R', PROPFIND) + XX(PUT, 2, 'R', PURGE) XX(CONNECT, 1, 'H', CHECKOUT) XX(CONNECT, 2, 'P', COPY) XX(MKCOL, 1, 'O', MOVE) XX(MKCOL, 1, 'E', MERGE) + XX(MKCOL, 1, '-', MSEARCH) XX(MKCOL, 2, 'A', MKACTIVITY) XX(MKCOL, 3, 'A', MKCALENDAR) XX(SUBSCRIBE, 1, 'E', SEARCH) + XX(SUBSCRIBE, 1, 'O', SOURCE) XX(REPORT, 2, 'B', REBIND) - XX(POST, 1, 'R', PROPFIND) XX(PROPFIND, 4, 'P', PROPPATCH) - XX(PUT, 2, 'R', PURGE) XX(LOCK, 1, 'I', LINK) XX(UNLOCK, 2, 'S', UNSUBSCRIBE) XX(UNLOCK, 2, 'B', UNBIND) XX(UNLOCK, 3, 'I', UNLINK) #undef XX - default: SET_ERRNO(HPE_INVALID_METHOD); goto error; } - } else if (ch == '-' && - parser->index == 1 && - parser->method == HTTP_MKCOL) { - parser->method = HTTP_MSEARCH; } else { SET_ERRNO(HPE_INVALID_METHOD); goto error; @@ -1163,57 +1122,41 @@ size_t http_parser_execute (http_parser *parser, case s_req_http_HTTP: STRICT_CHECK(ch != '/'); - UPDATE_STATE(s_req_first_http_major); - break; - - /* first digit of major HTTP version */ - case s_req_first_http_major: - if (UNLIKELY(ch < '1' || ch > '9')) { - SET_ERRNO(HPE_INVALID_VERSION); - goto error; - } - - parser->http_major = ch - '0'; UPDATE_STATE(s_req_http_major); break; - /* major HTTP version or dot */ case s_req_http_major: - { - if (ch == '.') { - UPDATE_STATE(s_req_first_http_minor); - break; - } - if (UNLIKELY(!IS_NUM(ch))) { SET_ERRNO(HPE_INVALID_VERSION); goto error; } - parser->http_major *= 10; - parser->http_major += ch - '0'; + parser->http_major = ch - '0'; + UPDATE_STATE(s_req_http_dot); + break; - if (UNLIKELY(parser->http_major > 999)) { + case s_req_http_dot: + { + if (UNLIKELY(ch != '.')) { SET_ERRNO(HPE_INVALID_VERSION); goto error; } + UPDATE_STATE(s_req_http_minor); break; } - /* first digit of minor HTTP version */ - case s_req_first_http_minor: + case s_req_http_minor: if (UNLIKELY(!IS_NUM(ch))) { SET_ERRNO(HPE_INVALID_VERSION); goto error; } parser->http_minor = ch - '0'; - UPDATE_STATE(s_req_http_minor); + UPDATE_STATE(s_req_http_end); break; - /* minor HTTP version or end of request line */ - case s_req_http_minor: + case s_req_http_end: { if (ch == CR) { UPDATE_STATE(s_req_line_almost_done); @@ -1225,21 +1168,8 @@ size_t http_parser_execute (http_parser *parser, break; } - /* XXX allow spaces after digit? */ - - if (UNLIKELY(!IS_NUM(ch))) { - SET_ERRNO(HPE_INVALID_VERSION); - goto error; - } - - parser->http_minor *= 10; - parser->http_minor += ch - '0'; - - if (UNLIKELY(parser->http_minor > 999)) { - SET_ERRNO(HPE_INVALID_VERSION); - goto error; - } - + SET_ERRNO(HPE_INVALID_VERSION); + goto error; break; } @@ -1804,10 +1734,17 @@ size_t http_parser_execute (http_parser *parser, UPDATE_STATE(s_headers_done); /* Set this here so that on_headers_complete() callbacks can see it */ - parser->upgrade = - ((parser->flags & (F_UPGRADE | F_CONNECTION_UPGRADE)) == - (F_UPGRADE | F_CONNECTION_UPGRADE) || - parser->method == HTTP_CONNECT); + if ((parser->flags & F_UPGRADE) && + (parser->flags & F_CONNECTION_UPGRADE)) { + /* For responses, "Upgrade: foo" and "Connection: upgrade" are + * mandatory only when it is a 101 Switching Protocols response, + * otherwise it is purely informational, to announce support. + */ + parser->upgrade = + (parser->type == HTTP_REQUEST || parser->status_code == 101); + } else { + parser->upgrade = (parser->method == HTTP_CONNECT); + } /* Here we call the headers_complete callback. This is somewhat * different than other callbacks because if the user returns 1, we @@ -1826,6 +1763,7 @@ size_t http_parser_execute (http_parser *parser, case 2: parser->upgrade = 1; + /* FALLTHROUGH */ case 1: parser->flags |= F_SKIPBODY; break; @@ -2385,7 +2323,7 @@ http_parser_parse_url(const char *buf, size_t buflen, int is_connect, case s_req_server_with_at: found_at = 1; - /* FALLTROUGH */ + /* FALLTHROUGH */ case s_req_server: uf = UF_HOST; break; @@ -2439,12 +2377,27 @@ http_parser_parse_url(const char *buf, size_t buflen, int is_connect, } if (u->field_set & (1 << UF_PORT)) { - /* Don't bother with endp; we've already validated the string */ - unsigned long v = strtoul(buf + u->field_data[UF_PORT].off, NULL, 10); - - /* Ports have a max value of 2^16 */ - if (v > 0xffff) { - return 1; + uint16_t off; + uint16_t len; + const char* p; + const char* end; + unsigned long v; + + off = u->field_data[UF_PORT].off; + len = u->field_data[UF_PORT].len; + end = buf + off + len; + + /* NOTE: The characters are already validated and are in the [0-9] range */ + assert(off + len <= buflen && "Port number overflow"); + v = 0; + for (p = buf + off; p < end; p++) { + v *= 10; + v += *p - '0'; + + /* Ports have a max value of 2^16 */ + if (v > 0xffff) { + return 1; + } } u->port = (uint16_t) v; diff --git a/Sming/third-party/http-parser/http_parser.h b/Sming/third-party/http-parser/http_parser.h index 45c72a078c..1fbf30e2b4 100644 --- a/Sming/third-party/http-parser/http_parser.h +++ b/Sming/third-party/http-parser/http_parser.h @@ -26,14 +26,13 @@ extern "C" { /* Also update SONAME in the Makefile whenever you change these. */ #define HTTP_PARSER_VERSION_MAJOR 2 -#define HTTP_PARSER_VERSION_MINOR 7 -#define HTTP_PARSER_VERSION_PATCH 1 +#define HTTP_PARSER_VERSION_MINOR 8 +#define HTTP_PARSER_VERSION_PATCH 0 -#include +#include #if defined(_WIN32) && !defined(__MINGW32__) && \ (!defined(_MSC_VER) || _MSC_VER<1600) && !defined(__WINE__) #include -#include typedef __int8 int8_t; typedef unsigned __int8 uint8_t; typedef __int16 int16_t; @@ -202,6 +201,8 @@ enum http_status /* RFC-2068, section 19.6.1.2 */ \ XX(31, LINK, LINK) \ XX(32, UNLINK, UNLINK) \ + /* icecast */ \ + XX(33, SOURCE, SOURCE) \ enum http_method { diff --git a/Sming/third-party/pwm/README.md b/Sming/third-party/pwm/README.md index 513dee80eb..dba28e836a 100644 --- a/Sming/third-party/pwm/README.md +++ b/Sming/third-party/pwm/README.md @@ -1,6 +1,8 @@ # ESP8266_new_pwm This is a drop-in replacement for the ESP8266 SDK PWM +If you like this project and want to support this and my other works, consider donating on [Liberapay][liberapay] + The software PWM provided in the ESP8266 SDK from Espressif has several drawbacks: 1. Duty cycle limited to 90% (at 1kHz PWM period) @@ -60,3 +62,4 @@ Example usage: softtimer, there is a conflict. You can use NM1 for the PWM instead.** +[liberapay]: https://liberapay.com/StefanB/ diff --git a/Sming/third-party/pwm/pwm.c b/Sming/third-party/pwm/pwm.c index 0386a06ff1..d0399086ea 100644 --- a/Sming/third-party/pwm/pwm.c +++ b/Sming/third-party/pwm/pwm.c @@ -95,7 +95,7 @@ struct gpio_regs { uint32_t status_w1ts; /* 0x60000320 */ uint32_t status_w1tc; /* 0x60000324 */ }; -static struct gpio_regs* gpio = (void*)(0x60000300); +static struct gpio_regs* gpio = (struct gpio_regs*)(0x60000300); struct timer_regs { uint32_t frc1_load; /* 0x60000600 */ @@ -109,9 +109,10 @@ struct timer_regs { uint32_t frc2_int; /* 0x6000062C */ uint32_t frc2_alarm; /* 0x60000630 */ }; -static struct timer_regs* timer = (void*)(0x60000600); +static struct timer_regs* timer = (struct timer_regs*)(0x60000600); -static void pwm_intr_handler(void* param) +static void IRAM_ATTR +pwm_intr_handler(void* param) { if ((pwm_state.current_set[pwm_state.current_phase].off_mask == 0) && (pwm_state.current_set[pwm_state.current_phase].on_mask == 0)) { diff --git a/samples/Basic_APA102/.cproject b/samples/Basic_APA102/.cproject new file mode 100644 index 0000000000..e1450b6031 --- /dev/null +++ b/samples/Basic_APA102/.cproject @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + make + -f ${ProjDirPath}/Makefile + all + true + true + true + + + make + -f ${ProjDirPath}/Makefile + clean + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flash + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashonefile + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashinit + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashboot + true + true + true + + + make + -f ${ProjDirPath}/Makefile + rebuild + true + true + true + + + + + + + + + + + + + + + + + + + + diff --git a/samples/Basic_APA102/.project b/samples/Basic_APA102/.project new file mode 100644 index 0000000000..97036b7c8e --- /dev/null +++ b/samples/Basic_APA102/.project @@ -0,0 +1,28 @@ + + + Basic_APA102 + + + SmingFramework + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/samples/Basic_Ssl/.cproject b/samples/Basic_Ssl/.cproject new file mode 100644 index 0000000000..e1450b6031 --- /dev/null +++ b/samples/Basic_Ssl/.cproject @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + make + -f ${ProjDirPath}/Makefile + all + true + true + true + + + make + -f ${ProjDirPath}/Makefile + clean + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flash + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashonefile + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashinit + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashboot + true + true + true + + + make + -f ${ProjDirPath}/Makefile + rebuild + true + true + true + + + + + + + + + + + + + + + + + + + + diff --git a/samples/Gesture_APDS-9960/.cproject b/samples/Gesture_APDS-9960/.cproject new file mode 100644 index 0000000000..e1450b6031 --- /dev/null +++ b/samples/Gesture_APDS-9960/.cproject @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + make + -f ${ProjDirPath}/Makefile + all + true + true + true + + + make + -f ${ProjDirPath}/Makefile + clean + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flash + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashonefile + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashinit + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashboot + true + true + true + + + make + -f ${ProjDirPath}/Makefile + rebuild + true + true + true + + + + + + + + + + + + + + + + + + + + diff --git a/samples/Gesture_APDS-9960/.project b/samples/Gesture_APDS-9960/.project new file mode 100644 index 0000000000..0784e87605 --- /dev/null +++ b/samples/Gesture_APDS-9960/.project @@ -0,0 +1,28 @@ + + + Gesture_APDS-9960 + + + SmingFramework + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/samples/IR_lib/.cproject b/samples/IR_lib/.cproject new file mode 100644 index 0000000000..e1450b6031 --- /dev/null +++ b/samples/IR_lib/.cproject @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + make + -f ${ProjDirPath}/Makefile + all + true + true + true + + + make + -f ${ProjDirPath}/Makefile + clean + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flash + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashonefile + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashinit + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashboot + true + true + true + + + make + -f ${ProjDirPath}/Makefile + rebuild + true + true + true + + + + + + + + + + + + + + + + + + + + diff --git a/samples/IR_lib/.project b/samples/IR_lib/.project new file mode 100644 index 0000000000..27f9d0781b --- /dev/null +++ b/samples/IR_lib/.project @@ -0,0 +1,28 @@ + + + IR_lib + + + SmingFramework + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + + diff --git a/samples/ScreenTFT_ST7735/.cproject b/samples/ScreenTFT_ST7735/.cproject new file mode 100644 index 0000000000..e1450b6031 --- /dev/null +++ b/samples/ScreenTFT_ST7735/.cproject @@ -0,0 +1,151 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + make + -f ${ProjDirPath}/Makefile + all + true + true + true + + + make + -f ${ProjDirPath}/Makefile + clean + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flash + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashonefile + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashinit + true + true + true + + + make + -f ${ProjDirPath}/Makefile + flashboot + true + true + true + + + make + -f ${ProjDirPath}/Makefile + rebuild + true + true + true + + + + + + + + + + + + + + + + + + + + diff --git a/samples/ScreenTFT_ST7735/.project b/samples/ScreenTFT_ST7735/.project new file mode 100644 index 0000000000..4a2668bcb8 --- /dev/null +++ b/samples/ScreenTFT_ST7735/.project @@ -0,0 +1,28 @@ + + + ScreenTFT_ST7735 + + + SmingFramework + + + + org.eclipse.cdt.managedbuilder.core.genmakebuilder + clean,full,incremental, + + + + + org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder + full,incremental, + + + + + + org.eclipse.cdt.core.cnature + org.eclipse.cdt.core.ccnature + org.eclipse.cdt.managedbuilder.core.managedBuildNature + org.eclipse.cdt.managedbuilder.core.ScannerConfigNature + +