diff --git a/Sming/SmingCore/Network/Http/HttpConnection.cpp b/Sming/SmingCore/Network/Http/HttpConnection.cpp index 079ec22f7d..07360b0751 100644 --- a/Sming/SmingCore/Network/Http/HttpConnection.cpp +++ b/Sming/SmingCore/Network/Http/HttpConnection.cpp @@ -20,28 +20,37 @@ #include "lwip/tcp_impl.h" #endif +bool HttpConnection::parserSettingsInitialized = false; + HttpConnection::HttpConnection(RequestQueue* queue): TcpClient(false), mode(eHCM_String) { this->waitingQueue = queue; http_parser_init(&parser, HTTP_RESPONSE); parser.data = (void*)this; - memset(&parserSettings, 0, sizeof(parserSettings)); + if(!parserSettingsInitialized) { + memset(&parserSettings, 0, sizeof(parserSettings)); - // Notification callbacks: on_message_begin, on_headers_complete, on_message_complete. - parserSettings.on_message_begin = staticOnMessageBegin; - parserSettings.on_headers_complete = staticOnHeadersComplete; - parserSettings.on_message_complete = staticOnMessageComplete; + // Notification callbacks: on_message_begin, on_headers_complete, on_message_complete. + parserSettings.on_message_begin = staticOnMessageBegin; + parserSettings.on_headers_complete = staticOnHeadersComplete; + parserSettings.on_message_complete = staticOnMessageComplete; - parserSettings.on_chunk_header = staticOnChunkHeader; - parserSettings.on_chunk_complete = staticOnChunkComplete; +#ifndef COMPACT_MODE + parserSettings.on_chunk_header = staticOnChunkHeader; + parserSettings.on_chunk_complete = staticOnChunkComplete; +#endif + // Data callbacks: on_url, (common) on_header_field, on_header_value, on_body; +#ifndef COMPACT_MODE + parserSettings.on_status = staticOnStatus; +#endif + parserSettings.on_header_field = staticOnHeaderField; + parserSettings.on_header_value = staticOnHeaderValue; + parserSettings.on_body = staticOnBody; - // Data callbacks: on_url, (common) on_header_field, on_header_value, on_body; - parserSettings.on_status = staticOnStatus; - parserSettings.on_header_field = staticOnHeaderField; - parserSettings.on_header_value = staticOnHeaderValue; - parserSettings.on_body = staticOnBody; + parserSettingsInitialized = true; + } } bool HttpConnection::connect(const String& host, int port, bool useSsl /* = false */, uint32_t sslOptions /* = 0 */) { @@ -266,9 +275,11 @@ int HttpConnection::staticOnHeadersComplete(http_parser* parser) return error; } +#ifndef COMPACT_MODE int HttpConnection::staticOnStatus(http_parser *parser, const char *at, size_t length) { return 0; } +#endif int HttpConnection::staticOnHeaderField(http_parser *parser, const char *at, size_t length) { @@ -334,6 +345,7 @@ int HttpConnection::staticOnBody(http_parser *parser, const char *at, size_t len return 0; } +#ifndef COMPACT_MODE int HttpConnection::staticOnChunkHeader(http_parser* parser) { debugf("On chunk header"); return 0; @@ -343,6 +355,7 @@ int HttpConnection::staticOnChunkComplete(http_parser* parser) { debugf("On chunk complete"); return 0; } +#endif err_t HttpConnection::onConnected(err_t err) { if (err == ERR_OK) { diff --git a/Sming/SmingCore/Network/Http/HttpConnection.h b/Sming/SmingCore/Network/Http/HttpConnection.h index 15147c7815..2ea81f7072 100644 --- a/Sming/SmingCore/Network/Http/HttpConnection.h +++ b/Sming/SmingCore/Network/Http/HttpConnection.h @@ -89,13 +89,17 @@ class HttpConnection : protected TcpClient { private: static int IRAM_ATTR staticOnMessageBegin(http_parser* parser); +#ifndef COMPACT_MODE static int IRAM_ATTR staticOnStatus(http_parser *parser, const char *at, size_t length); +#endif static int IRAM_ATTR staticOnHeadersComplete(http_parser* parser); static int IRAM_ATTR staticOnHeaderField(http_parser *parser, const char *at, size_t length); static int IRAM_ATTR staticOnHeaderValue(http_parser *parser, const char *at, size_t length); static int IRAM_ATTR staticOnBody(http_parser *parser, const char *at, size_t length); +#ifndef COMPACT_MODE static int IRAM_ATTR staticOnChunkHeader(http_parser* parser); static int IRAM_ATTR staticOnChunkComplete(http_parser* parser); +#endif static int IRAM_ATTR staticOnMessageComplete(http_parser* parser); protected: @@ -105,7 +109,8 @@ class HttpConnection : protected TcpClient { RequestQueue* waitingQueue; RequestQueue executionQueue; http_parser parser; - http_parser_settings parserSettings; + static http_parser_settings parserSettings; + static bool parserSettingsInitialized; HttpHeaders responseHeaders; int code = 0; diff --git a/Sming/SmingCore/Network/Http/HttpServerConnection.cpp b/Sming/SmingCore/Network/Http/HttpServerConnection.cpp index 00d73c5f67..4030ea7797 100644 --- a/Sming/SmingCore/Network/Http/HttpServerConnection.cpp +++ b/Sming/SmingCore/Network/Http/HttpServerConnection.cpp @@ -17,6 +17,9 @@ #include "../../Services/cWebsocket/websocket.h" #include "WebConstants.h" +bool HttpServerConnection::parserSettingsInitialized = false; +http_parser_settings HttpServerConnection::parserSettings; + HttpServerConnection::HttpServerConnection(tcp_pcb *clientTcp) : TcpClient(clientTcp, 0, 0), state(eHCS_Ready) { @@ -24,17 +27,20 @@ HttpServerConnection::HttpServerConnection(tcp_pcb *clientTcp) http_parser_init(&parser, HTTP_REQUEST); parser.data = (void*)this; - memset(&parserSettings, 0, sizeof(parserSettings)); - // Notification callbacks: on_message_begin, on_headers_complete, on_message_complete. - parserSettings.on_message_begin = staticOnMessageBegin; - parserSettings.on_headers_complete = staticOnHeadersComplete; - parserSettings.on_message_complete = staticOnMessageComplete; - - // Data callbacks: on_url, (common) on_header_field, on_header_value, on_body; - parserSettings.on_url = staticOnPath; - parserSettings.on_header_field = staticOnHeaderField; - parserSettings.on_header_value = staticOnHeaderValue; - parserSettings.on_body = staticOnBody; + if(!parserSettingsInitialized) { + memset(&parserSettings, 0, sizeof(parserSettings)); + // Notification callbacks: on_message_begin, on_headers_complete, on_message_complete. + parserSettings.on_message_begin = staticOnMessageBegin; + parserSettings.on_headers_complete = staticOnHeadersComplete; + parserSettings.on_message_complete = staticOnMessageComplete; + + // Data callbacks: on_url, (common) on_header_field, on_header_value, on_body; + parserSettings.on_url = staticOnPath; + parserSettings.on_header_field = staticOnHeaderField; + parserSettings.on_header_value = staticOnHeaderValue; + parserSettings.on_body = staticOnBody; + parserSettingsInitialized = true; + } } HttpServerConnection::~HttpServerConnection() diff --git a/Sming/SmingCore/Network/Http/HttpServerConnection.h b/Sming/SmingCore/Network/Http/HttpServerConnection.h index e6d207ffce..6a68e415fa 100644 --- a/Sming/SmingCore/Network/Http/HttpServerConnection.h +++ b/Sming/SmingCore/Network/Http/HttpServerConnection.h @@ -78,7 +78,8 @@ class HttpServerConnection: public TcpClient HttpConnectionState state; http_parser parser; - http_parser_settings parserSettings; + static http_parser_settings parserSettings; + static bool parserSettingsInitialized; ResourceTree* resourceTree = NULL; HttpResource* resource = NULL;