From 02aab701468a4137c6f1cce5dab550d4655d5b38 Mon Sep 17 00:00:00 2001 From: Patrick Schwarz Date: Sun, 10 Nov 2024 15:28:27 +0100 Subject: [PATCH] Remove libs for move them to submodule --- lib/ArtNet/Artnet/ArtDmx.h | 87 - lib/ArtNet/Artnet/ArtNzs.h | 87 - lib/ArtNet/Artnet/ArtPollReply.h | 148 -- lib/ArtNet/Artnet/ArtSync.h | 45 - lib/ArtNet/Artnet/ArtTrigger.h | 67 - lib/ArtNet/Artnet/Common.h | 144 -- lib/ArtNet/Artnet/Manager.h | 32 - lib/ArtNet/Artnet/Receiver.h | 490 ----- lib/ArtNet/Artnet/Sender.h | 208 -- .../util/TeensyDirtySTLErrorSolution/LICENSE | 21 - .../TeensyDirtySTLErrorSolution/README.md | 57 - .../TeensyDirtySTLErrorSolution.h | 65 - lib/ArtNet/ArtnetETH.h | 19 - lib/ArtNet/ArtnetWiFi.h | 40 - lib/ArtNet/LICENSE | 21 - lib/ArtNet/README.md | 423 ---- lib/ArtNet/library.json | 22 - lib/ArtNet/library.properties | 10 - lib/AsyncWebServer_ESP32_W5500/.codespellrc | 7 - lib/AsyncWebServer_ESP32_W5500/.gitignore | 32 - .../CONTRIBUTING.md | 79 - lib/AsyncWebServer_ESP32_W5500/LICENSE | 674 ------ lib/AsyncWebServer_ESP32_W5500/README.md | 1952 ----------------- lib/AsyncWebServer_ESP32_W5500/changelog.md | 43 - lib/AsyncWebServer_ESP32_W5500/keywords.txt | 530 ----- lib/AsyncWebServer_ESP32_W5500/library.json | 38 - .../library.properties | 12 - .../src/AsyncEventSource.cpp | 566 ----- .../src/AsyncEventSource.h | 208 -- .../src/AsyncJson.h | 447 ---- .../src/AsyncWebServer_ESP32_W5500.cpp | 161 -- .../src/AsyncWebServer_ESP32_W5500.h | 938 -------- .../src/AsyncWebServer_ESP32_W5500_Debug.h | 115 - .../src/AsyncWebSocket.cpp | 1929 ---------------- .../src/AsyncWebSocket.h | 611 ------ .../src/AsyncWebSynchronization.h | 124 -- .../src/Crypto/Hash.cpp | 109 - .../src/Crypto/Hash.h | 46 - .../src/Crypto/bearssl_hash.h | 1357 ------------ .../src/Crypto/md5.h | 95 - .../src/Crypto/sha1.c | 330 --- .../src/Crypto/sha1.h | 101 - .../src/ESP32_W5500_SPIFFSEditor.cpp | 689 ------ .../src/ESP32_W5500_SPIFFSEditor.h | 65 - .../src/StringArray.h | 353 --- .../src/WebAuthentication.cpp | 360 --- .../src/WebAuthentication.h | 55 - .../src/WebHandlerImpl.h | 245 --- .../src/WebHandlers.cpp | 294 --- .../src/WebRequest.cpp | 1753 --------------- .../src/WebResponseImpl.h | 278 --- .../src/WebResponses.cpp | 1300 ----------- .../src/WebServer.cpp | 315 --- lib/AsyncWebServer_ESP32_W5500/src/edit.htm | 627 ------ .../src/libb64/cdecode.c | 150 -- .../src/libb64/cdecode.h | 62 - .../src/libb64/cencode.c | 154 -- .../src/libb64/cencode.h | 65 - .../src/w5500/esp32_w5500.cpp | 412 ---- .../src/w5500/esp32_w5500.h | 94 - .../src/w5500/esp_eth/esp_eth_mac_w5500.c | 950 -------- .../src/w5500/esp_eth/esp_eth_phy_w5500.c | 372 ---- .../src/w5500/esp_eth/esp_eth_spi_w5500.c | 102 - .../src/w5500/esp_eth/esp_eth_w5500.h | 138 -- .../src/w5500/esp_eth/w5500.h | 118 - .../utils/astyle_library.conf | 70 - .../utils/restyle.sh | 6 - 67 files changed, 21517 deletions(-) delete mode 100644 lib/ArtNet/Artnet/ArtDmx.h delete mode 100644 lib/ArtNet/Artnet/ArtNzs.h delete mode 100644 lib/ArtNet/Artnet/ArtPollReply.h delete mode 100644 lib/ArtNet/Artnet/ArtSync.h delete mode 100644 lib/ArtNet/Artnet/ArtTrigger.h delete mode 100644 lib/ArtNet/Artnet/Common.h delete mode 100644 lib/ArtNet/Artnet/Manager.h delete mode 100644 lib/ArtNet/Artnet/Receiver.h delete mode 100644 lib/ArtNet/Artnet/Sender.h delete mode 100644 lib/ArtNet/Artnet/util/TeensyDirtySTLErrorSolution/LICENSE delete mode 100644 lib/ArtNet/Artnet/util/TeensyDirtySTLErrorSolution/README.md delete mode 100644 lib/ArtNet/Artnet/util/TeensyDirtySTLErrorSolution/TeensyDirtySTLErrorSolution.h delete mode 100644 lib/ArtNet/ArtnetETH.h delete mode 100644 lib/ArtNet/ArtnetWiFi.h delete mode 100644 lib/ArtNet/LICENSE delete mode 100644 lib/ArtNet/README.md delete mode 100644 lib/ArtNet/library.json delete mode 100644 lib/ArtNet/library.properties delete mode 100644 lib/AsyncWebServer_ESP32_W5500/.codespellrc delete mode 100644 lib/AsyncWebServer_ESP32_W5500/.gitignore delete mode 100644 lib/AsyncWebServer_ESP32_W5500/CONTRIBUTING.md delete mode 100644 lib/AsyncWebServer_ESP32_W5500/LICENSE delete mode 100644 lib/AsyncWebServer_ESP32_W5500/README.md delete mode 100644 lib/AsyncWebServer_ESP32_W5500/changelog.md delete mode 100644 lib/AsyncWebServer_ESP32_W5500/keywords.txt delete mode 100644 lib/AsyncWebServer_ESP32_W5500/library.json delete mode 100644 lib/AsyncWebServer_ESP32_W5500/library.properties delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/AsyncEventSource.cpp delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/AsyncEventSource.h delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/AsyncJson.h delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/AsyncWebServer_ESP32_W5500.cpp delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/AsyncWebServer_ESP32_W5500.h delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/AsyncWebServer_ESP32_W5500_Debug.h delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/AsyncWebSocket.cpp delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/AsyncWebSocket.h delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/AsyncWebSynchronization.h delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/Crypto/Hash.cpp delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/Crypto/Hash.h delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/Crypto/bearssl_hash.h delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/Crypto/md5.h delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/Crypto/sha1.c delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/Crypto/sha1.h delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/ESP32_W5500_SPIFFSEditor.cpp delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/ESP32_W5500_SPIFFSEditor.h delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/StringArray.h delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/WebAuthentication.cpp delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/WebAuthentication.h delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/WebHandlerImpl.h delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/WebHandlers.cpp delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/WebRequest.cpp delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/WebResponseImpl.h delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/WebResponses.cpp delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/WebServer.cpp delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/edit.htm delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/libb64/cdecode.c delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/libb64/cdecode.h delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/libb64/cencode.c delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/libb64/cencode.h delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/w5500/esp32_w5500.cpp delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/w5500/esp32_w5500.h delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/w5500/esp_eth/esp_eth_mac_w5500.c delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/w5500/esp_eth/esp_eth_phy_w5500.c delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/w5500/esp_eth/esp_eth_spi_w5500.c delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/w5500/esp_eth/esp_eth_w5500.h delete mode 100644 lib/AsyncWebServer_ESP32_W5500/src/w5500/esp_eth/w5500.h delete mode 100644 lib/AsyncWebServer_ESP32_W5500/utils/astyle_library.conf delete mode 100644 lib/AsyncWebServer_ESP32_W5500/utils/restyle.sh diff --git a/lib/ArtNet/Artnet/ArtDmx.h b/lib/ArtNet/Artnet/ArtDmx.h deleted file mode 100644 index 57b1403..0000000 --- a/lib/ArtNet/Artnet/ArtDmx.h +++ /dev/null @@ -1,87 +0,0 @@ -#pragma once -#ifndef ARTNET_ARTDMX_H -#define ARTNET_ARTDMX_H - -#include "Common.h" -#include -#include - -namespace art_net { -namespace art_dmx { - -enum Index : uint16_t -{ - ID = 0, - OP_CODE_L = 8, - OP_CODE_H = 9, - PROTOCOL_VER_H = 10, - PROTOCOL_VER_L = 11, - SEQUENCE = 12, - PHYSICAL = 13, - SUBUNI = 14, - NET = 15, - LENGTH_H = 16, - LENGTH_L = 17, - DATA = 18 -}; - -struct Metadata -{ - uint8_t sequence; - uint8_t physical; - uint8_t net; - uint8_t subnet; - uint8_t universe; -}; - -using CallbackType = std::function; -#if ARX_HAVE_LIBSTDCPLUSPLUS >= 201103L // Have libstdc++11 -using CallbackMap = std::map; -#else -using CallbackMap = arx::stdx::map; -#endif - -inline Metadata generateMetadataFrom(const uint8_t *packet) -{ - Metadata metadata; - metadata.sequence = packet[SEQUENCE]; - metadata.physical = packet[PHYSICAL]; - metadata.net = packet[NET]; - metadata.subnet = (packet[SUBUNI] >> 4) & 0x0F; - metadata.universe = (packet[SUBUNI] >> 0) & 0x0F; - return metadata; -} - -inline void setMetadataTo(uint8_t *packet, uint8_t sequence, uint8_t physical, uint8_t net, uint8_t subnet, uint8_t universe) -{ - for (size_t i = 0; i < ID_LENGTH; i++) { - packet[i] = static_cast(ARTNET_ID[i]); - } - packet[OP_CODE_L] = (static_cast(OpCode::Dmx) >> 0) & 0x00FF; - packet[OP_CODE_H] = (static_cast(OpCode::Dmx) >> 8) & 0x00FF; - packet[PROTOCOL_VER_H] = (PROTOCOL_VER >> 8) & 0x00FF; - packet[PROTOCOL_VER_L] = (PROTOCOL_VER >> 0) & 0x00FF; - packet[SEQUENCE] = sequence; - packet[PHYSICAL] = physical & 0x03; - packet[NET] = net & 0x7F; - packet[SUBUNI] = ((subnet & 0x0F) << 4) | (universe & 0x0F); - packet[LENGTH_H] = (512 >> 8) & 0xFF; - packet[LENGTH_L] = (512 >> 0) & 0xFF; -} - -inline void setDataTo(uint8_t *packet, const uint8_t* const data, uint16_t size) -{ - memcpy(packet + art_dmx::DATA, data, size); -} -inline void setDataTo(uint8_t *packet, const uint16_t ch, const uint8_t data) -{ - packet[art_dmx::DATA + ch] = data; -} - -} // namespace art_dmx -} // namespace art_net - -using ArtDmxMetadata = art_net::art_dmx::Metadata; -using ArtDmxCallback = art_net::art_dmx::CallbackType; - -#endif // ARTNET_ARTDMX_H diff --git a/lib/ArtNet/Artnet/ArtNzs.h b/lib/ArtNet/Artnet/ArtNzs.h deleted file mode 100644 index 6c52367..0000000 --- a/lib/ArtNet/Artnet/ArtNzs.h +++ /dev/null @@ -1,87 +0,0 @@ -#pragma once -#ifndef ARTNET_ARTNZS_H -#define ARTNET_ARTNZS_H - -#include "Common.h" -#include -#include - -namespace art_net { -namespace art_nzs { - -enum Index : uint16_t -{ - ID = 0, - OP_CODE_L = 8, - OP_CODE_H = 9, - PROTOCOL_VER_H = 10, - PROTOCOL_VER_L = 11, - SEQUENCE = 12, - START_CODE = 13, - SUBUNI = 14, - NET = 15, - LENGTH_H = 16, - LENGTH_L = 17, - DATA = 18 -}; - -struct Metadata -{ - uint8_t sequence; - uint8_t start_code; - uint8_t net; - uint8_t subnet; - uint8_t universe; -}; - -using CallbackType = std::function; -#if ARX_HAVE_LIBSTDCPLUSPLUS >= 201103L // Have libstdc++11 -using CallbackMap = std::map; -#else -using CallbackMap = arx::stdx::map; -#endif - -inline Metadata generateMetadataFrom(const uint8_t *packet) -{ - Metadata metadata; - metadata.sequence = packet[SEQUENCE]; - metadata.start_code = packet[START_CODE]; - metadata.net = packet[NET]; - metadata.subnet = (packet[SUBUNI] >> 4) & 0x0F; - metadata.universe = (packet[SUBUNI] >> 0) & 0x0F; - return metadata; -} - -inline void setMetadataTo(uint8_t *packet, uint8_t sequence, uint8_t start_code, uint8_t net, uint8_t subnet, uint8_t universe) -{ - for (size_t i = 0; i < ID_LENGTH; i++) { - packet[i] = static_cast(ARTNET_ID[i]); - } - packet[OP_CODE_L] = (static_cast(OpCode::Nzs) >> 0) & 0x00FF; - packet[OP_CODE_H] = (static_cast(OpCode::Nzs) >> 8) & 0x00FF; - packet[PROTOCOL_VER_H] = (PROTOCOL_VER >> 8) & 0x00FF; - packet[PROTOCOL_VER_L] = (PROTOCOL_VER >> 0) & 0x00FF; - packet[SEQUENCE] = sequence; - packet[START_CODE] = start_code & 0x03; - packet[NET] = net & 0x7F; - packet[SUBUNI] = ((subnet & 0x0F) << 4) | (universe & 0x0F); - packet[LENGTH_H] = (512 >> 8) & 0xFF; - packet[LENGTH_L] = (512 >> 0) & 0xFF; -} - -inline void setDataTo(uint8_t *packet, const uint8_t* const data, uint16_t size) -{ - memcpy(packet + art_nzs::DATA, data, size); -} -inline void setDataTo(uint8_t *packet, const uint16_t ch, const uint8_t data) -{ - packet[art_nzs::DATA + ch] = data; -} - -} // namespace art_nzs -} // namespace art_net - -using ArtNzsMetadata = art_net::art_nzs::Metadata; -using ArtNzsCallback = art_net::art_nzs::CallbackType; - -#endif // ARTNET_ARTNZS_H diff --git a/lib/ArtNet/Artnet/ArtPollReply.h b/lib/ArtNet/Artnet/ArtPollReply.h deleted file mode 100644 index fd354cc..0000000 --- a/lib/ArtNet/Artnet/ArtPollReply.h +++ /dev/null @@ -1,148 +0,0 @@ -#pragma once -#ifndef ARTNET_ARTPOLLREPLY_H -#define ARTNET_ARTPOLLREPLY_H - -#include "Common.h" -#include -#include -#include - -namespace art_net { -namespace art_poll_reply { - -static constexpr size_t NUM_POLLREPLY_PUBLIC_PORT_LIMIT {4}; - -union Packet -{ - struct - { - uint8_t id[8]; - uint8_t op_code_l; - uint8_t op_code_h; - uint8_t ip[4]; - uint8_t port_l; - uint8_t port_h; - uint8_t ver_h; - uint8_t ver_l; - uint8_t net_sw; - uint8_t sub_sw; - uint8_t oem_h; - uint8_t oem_l; - uint8_t ubea_ver; - uint8_t status_1; - uint8_t esta_man_l; - uint8_t esta_man_h; - uint8_t short_name[18]; - uint8_t long_name[64]; - uint8_t node_report[64]; - uint8_t num_ports_h; - uint8_t num_ports_l; - uint8_t port_types[NUM_POLLREPLY_PUBLIC_PORT_LIMIT]; - uint8_t good_input[NUM_POLLREPLY_PUBLIC_PORT_LIMIT]; - uint8_t good_output[NUM_POLLREPLY_PUBLIC_PORT_LIMIT]; - uint8_t sw_in[NUM_POLLREPLY_PUBLIC_PORT_LIMIT]; - uint8_t sw_out[NUM_POLLREPLY_PUBLIC_PORT_LIMIT]; - uint8_t sw_video; - uint8_t sw_macro; - uint8_t sw_remote; - uint8_t spare[3]; - uint8_t style; - uint8_t mac[6]; - uint8_t bind_ip[4]; - uint8_t bind_index; - uint8_t status_2; - uint8_t filler[26]; - }; - uint8_t b[239]; -}; - -struct Config -{ - uint16_t oem {0x00FF}; // OemUnknown https://github.com/tobiasebsen/ArtNode/blob/master/src/Art-NetOemCodes.h - uint16_t esta_man {0x0000}; // ESTA manufacturer code - uint8_t status1 {0x00}; // Unknown / Normal - uint8_t status2 {0x08}; // sACN capable - String short_name {"ChaosDMX"}; - String long_name {"ChaosDMX Interface"}; - String node_report {""}; - // Four universes from Device to Controller - // NOTE: Only low 4 bits of the universes - // NOTE: Upper 11 bits of the universes will be - // shared with the subscribed universe (net, subnet) - // e.g.) If you have subscribed universe 0x1234, - // you can set the device to controller universes - // from 0x1230 to 0x123F (sw_in will be from 0x0 to 0xF). - // So, I recommned subscribing only in the range of - // 0x1230 to 0x123F if you want to set the sw_in. - // REF: Please refer the Art-Net spec for the detail. - // https://art-net.org.uk/downloads/art-net.pdf - uint8_t sw_in[4] {0}; -}; - -inline Packet generatePacketFrom(const IPAddress &my_ip, const uint8_t my_mac[6], uint16_t universe, const Config &metadata) -{ - Packet r; - for (size_t i = 0; i < ID_LENGTH; i++) { - r.id[i] = static_cast(ARTNET_ID[i]); - } - r.op_code_l = ((uint16_t)OpCode::PollReply >> 0) & 0x00FF; - r.op_code_h = ((uint16_t)OpCode::PollReply >> 8) & 0x00FF; - memcpy(r.mac, my_mac, 6); - for (size_t i = 0; i < 4; ++i) { - r.ip[i] = my_ip[i]; - } - r.port_l = (DEFAULT_PORT >> 0) & 0xFF; - r.port_h = (DEFAULT_PORT >> 8) & 0xFF; - r.ver_h = (PROTOCOL_VER >> 8) & 0x00FF; - r.ver_l = (PROTOCOL_VER >> 0) & 0x00FF; - r.oem_h = (metadata.oem >> 8) & 0xFF; // - r.oem_l = (metadata.oem >> 0) & 0xFF; - r.ubea_ver = 0; // UBEA not programmed - r.status_1 = metadata.status1; - r.esta_man_l = (metadata.esta_man >> 8) & 0xFF; - r.esta_man_h = (metadata.esta_man >> 8) & 0xFF; - memset(r.short_name, 0, 18); - memset(r.long_name, 0, 64); - memset(r.node_report, 0, 64); - memcpy(r.short_name, metadata.short_name.c_str(), metadata.short_name.length()); - memcpy(r.long_name, metadata.long_name.c_str(), metadata.long_name.length()); - memcpy(r.node_report, metadata.node_report.c_str(), metadata.node_report.length()); - r.num_ports_h = 0; // Reserved - r.num_ports_l = 1; - memset(r.sw_in, 0, 4); - memset(r.sw_out, 0, 4); - memset(r.port_types, 0, 4); - memset(r.good_input, 0, 4); - memset(r.good_output, 0, 4); - r.net_sw = (universe >> 8) & 0x7F; - r.sub_sw = (universe >> 4) & 0x0F; - // https://github.com/hideakitai/ArtNet/issues/81 - // https://github.com/hideakitai/ArtNet/issues/121 - r.sw_out[0] = (universe >> 0) & 0x0F; - for (size_t i = 0; i < 4; ++i) { - r.sw_in[i] = metadata.sw_in[i] & 0x0F; - } - r.port_types[0] = 0xC0; // I/O available by DMX512 - r.good_input[0] = 0x80; // Data received without error - r.good_output[0] = 0x80; // Data transmitted without error - r.sw_video = 0; // Video display shows local data - r.sw_macro = 0; // No support for macro key inputs - r.sw_remote = 0; // No support for remote trigger inputs - memset(r.spare, 0x00, 3); - r.style = 0x00; // A DMX to / from Art-Net device - for (size_t i = 0; i < 4; ++i) { - r.bind_ip[i] = my_ip[i]; - } - r.bind_index = 0; - r.status_2 = metadata.status2; - memset(r.filler, 0x00, 26); - - return r; -} - -} // namespace art_poll_reply -} // namespace art_net - -using ArtPollReplyConfig = art_net::art_poll_reply::Config; - -#endif // ARTNET_ARTPOLLREPLY_H diff --git a/lib/ArtNet/Artnet/ArtSync.h b/lib/ArtNet/Artnet/ArtSync.h deleted file mode 100644 index 3423ff4..0000000 --- a/lib/ArtNet/Artnet/ArtSync.h +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once -#ifndef ARTNET_ART_SYNC_H -#define ARTNET_ART_SYNC_H - -#include "Common.h" -#include -#include - -namespace art_net { -namespace art_sync { - -enum Index : uint16_t -{ - ID = 0, - OP_CODE_L = 8, - OP_CODE_H = 9, - PROTOCOL_VER_H = 10, - PROTOCOL_VER_L = 11, - AUX1 = 12, - AUX2 = 13, - - PACKET_SIZE = 14, -}; - -using CallbackType = std::function; - -inline void setMetadataTo(uint8_t *packet) -{ - for (size_t i = 0; i < ID_LENGTH; i++) { - packet[i] = static_cast(ARTNET_ID[i]); - } - packet[OP_CODE_L] = (static_cast(OpCode::Sync) >> 0) & 0x00FF; - packet[OP_CODE_H] = (static_cast(OpCode::Sync) >> 8) & 0x00FF; - packet[PROTOCOL_VER_H] = (PROTOCOL_VER >> 8) & 0x00FF; - packet[PROTOCOL_VER_L] = (PROTOCOL_VER >> 0) & 0x00FF; - packet[AUX1] = 0; - packet[AUX2] = 0; -} - -} // namespace art_sync -} // namespace art_net - -using ArtSyncCallback = art_net::art_sync::CallbackType; - -#endif // ARTNET_ART_SYNC_H diff --git a/lib/ArtNet/Artnet/ArtTrigger.h b/lib/ArtNet/Artnet/ArtTrigger.h deleted file mode 100644 index 88e3a31..0000000 --- a/lib/ArtNet/Artnet/ArtTrigger.h +++ /dev/null @@ -1,67 +0,0 @@ -#pragma once -#ifndef ARTNET_ART_TRIGGER_H -#define ARTNET_ART_TRIGGER_H - -#include "Common.h" -#include -#include - -namespace art_net { -namespace art_trigger { - -enum Index : uint16_t -{ - ID = 0, - OP_CODE_L = 8, - OP_CODE_H = 9, - PROTOCOL_VER_H = 10, - PROTOCOL_VER_L = 11, - FILTER_1 = 12, - FILTER_2 = 13, - OEM_H = 14, - OEM_L = 15, - KEY = 16, - SUB_KEY = 17, - PAYLOAD = 18 -}; - -struct Metadata -{ - uint16_t oem; - uint8_t key; - uint8_t sub_key; - const uint8_t *payload; - uint16_t size; -}; - -using CallbackType = std::function; - -inline void setDataTo(uint8_t *packet, uint16_t oem, uint8_t key, uint8_t subkey, const uint8_t* const payload, uint16_t size) -{ - for (size_t i = 0; i < ID_LENGTH; i++) { - packet[i] = static_cast(ARTNET_ID[i]); - } - packet[OP_CODE_L] = (static_cast(OpCode::Trigger) >> 0) & 0x00FF; - packet[OP_CODE_H] = (static_cast(OpCode::Trigger) >> 8) & 0x00FF; - packet[PROTOCOL_VER_H] = (PROTOCOL_VER >> 8) & 0x00FF; - packet[PROTOCOL_VER_L] = (PROTOCOL_VER >> 0) & 0x00FF; - packet[FILTER_1] = 0; - packet[FILTER_2] = 0; - packet[OEM_H] = (oem >> 8) & 0x00FF; - packet[OEM_L] = (oem >> 0) & 0x00FF; - packet[KEY] = key; - packet[SUB_KEY] = subkey; - if (payload) { - memcpy(packet + PAYLOAD, payload, size); - } else { - memset(packet + PAYLOAD, 0, 512); - } -} - -} // namespace art_trigger -} // namespace art_net - -using ArtTriggerCallback = art_net::art_trigger::CallbackType; -using ArtTriggerMetadata = art_net::art_trigger::Metadata; - -#endif // ARTNET_ART_TRIGGER_H diff --git a/lib/ArtNet/Artnet/Common.h b/lib/ArtNet/Artnet/Common.h deleted file mode 100644 index 7075b83..0000000 --- a/lib/ArtNet/Artnet/Common.h +++ /dev/null @@ -1,144 +0,0 @@ -#pragma once -#ifndef ARTNET_COMMON_H -#define ARTNET_COMMON_H - -#include -#include -#include -#include - -namespace art_net { -// Packet Summary : https://art-net.org.uk/structure/packet-summary-2/ -// Packet Definition : https://art-net.org.uk/structure/streaming-packets/artdmx-packet-definition/ - -enum class OpCode : uint16_t { - // Device Discovery - Poll = 0x2000, - PollReply = 0x2100, - // Device Configuration - Address = 0x6000, - Input = 0x7000, - IpProg = 0xF800, - IpProgReply = 0xF900, - Command = 0x2400, - // Streaming Control - Dmx = 0x5000, - Nzs = 0x5100, - Sync = 0x5200, - // RDM - TodRequest = 0x8000, - TodData = 0x8100, - TodControl = 0x8200, - Rdm = 0x8300, - RdmSub = 0x8400, - // Time-Keeping - TimeCode = 0x9700, - TimeSync = 0x9800, - // Triggering - Trigger = 0x9900, - // Diagnostics - DiagData = 0x2300, - // File Transfer - FirmwareMaster = 0xF200, - FirmwareReply = 0xF300, - Directory = 0x9A00, - DirectoryReply = 0x9B00, - FileTnMaster = 0xF400, - FileFnMaster = 0xF500, - FileFnReply = 0xF600, - // Others - NoPacket = 0x0000, - Unsupported = 0xFFFE, - ParseFailed = 0xFFFF, -}; - -constexpr uint16_t DEFAULT_PORT {6454}; // 0x1936 -constexpr uint16_t PROTOCOL_VER {14}; // 0x000E -constexpr uint8_t ID_LENGTH {8}; -constexpr char ARTNET_ID[ID_LENGTH] {"Art-Net"}; -constexpr float DEFAULT_FPS {40.}; -constexpr uint32_t DEFAULT_INTERVAL_MS {(uint32_t)(1000. / DEFAULT_FPS)}; - -// ArtDmx, ArtTrigger has same structure -constexpr uint16_t HEADER_SIZE {18}; -constexpr uint16_t PACKET_SIZE {530}; - -#if ARX_HAVE_LIBSTDCPLUSPLUS >= 201103L // Have libstdc++11 -template -using Array = std::array; -#else -template -using Array = arx::stdx::vector; -#endif - -struct RemoteInfo -{ - IPAddress ip; - uint16_t port; -}; - -struct Destination -{ - String ip; - uint8_t net; - uint8_t subnet; - uint8_t universe; -}; - - -inline bool operator<(const Destination &rhs, const Destination &lhs) -{ - if (rhs.ip < lhs.ip) { - return true; - } - if (rhs.ip > lhs.ip) { - return false; - } - if (rhs.net < lhs.net) { - return true; - } - if (rhs.net > lhs.net) { - return false; - } - if (rhs.subnet < lhs.subnet) { - return true; - } - if (rhs.subnet > lhs.subnet) { - return false; - } - if (rhs.universe < lhs.universe) { - return true; - } - if (rhs.universe > lhs.universe) { - return false; - } - return false; -} - -inline bool operator==(const Destination &rhs, const Destination &lhs) -{ - return rhs.ip == lhs.ip && rhs.net == lhs.net && rhs.subnet == lhs.subnet && rhs.universe == lhs.universe; -} - -#if ARX_HAVE_LIBSTDCPLUSPLUS >= 201103L // Have libstdc++11 -// sender -using LastSendTimeMsMap = std::map; -using SequenceMap = std::map; -#else -// sender -using LastSendTimeMsMap = arx::stdx::map; -using SequenceMap = arx::stdx::map; -#endif - -#ifdef ARTNET_ENABLE_WIFI -inline bool isNetworkReady() -{ - return true; -} -#endif - -} // namespace art_net - -using ArtNetRemoteInfo = art_net::RemoteInfo; - -#endif // ARTNET_COMMON_H diff --git a/lib/ArtNet/Artnet/Manager.h b/lib/ArtNet/Artnet/Manager.h deleted file mode 100644 index 9559870..0000000 --- a/lib/ArtNet/Artnet/Manager.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once -#ifndef ARTNET_MANAGER_H - -#include "Common.h" -#include "Receiver.h" -#include "Sender.h" - -namespace art_net { - -template -class Manager : public Sender_, public Receiver_ -{ - S stream; - -public: - void begin(uint16_t recv_port = DEFAULT_PORT) - { - this->stream.begin(recv_port); - this->Sender_::attach(this->stream); - this->Receiver_::attach(this->stream); - } - - void parse() - { - this->Receiver_::parse(); - } -}; - - -} // namespace art_net - -#endif // ARTNET_MANAGER_H diff --git a/lib/ArtNet/Artnet/Receiver.h b/lib/ArtNet/Artnet/Receiver.h deleted file mode 100644 index aa19cbd..0000000 --- a/lib/ArtNet/Artnet/Receiver.h +++ /dev/null @@ -1,490 +0,0 @@ -#pragma once -#ifndef ARTNET_RECEIVER_H -#define ARTNET_RECEIVER_H - -#include "Common.h" -#include "ArtDmx.h" -#include "ArtNzs.h" -#include "ArtPollReply.h" -#include "ArtTrigger.h" -#include "ArtSync.h" - -namespace art_net { - -namespace { - -struct NoPrint : public Print -{ - size_t write(uint8_t) override { return 0; } -}; -static NoPrint no_log; - -} // namespace - -template -class Receiver_ -{ - S *stream; - Array packet; - - art_dmx::CallbackMap callback_art_dmx_universes; - art_dmx::CallbackType callback_art_dmx; - art_nzs::CallbackMap callback_art_nzs_universes; - art_sync::CallbackType callback_art_sync; - art_trigger::CallbackType callback_art_trigger; - ArtPollReplyConfig art_poll_reply_config; - - Print *logger {&no_log}; - -public: -#if ARX_HAVE_LIBSTDCPLUSPLUS >= 201103L // Have libstdc++11 -#else - Receiver_() - { - this->packet.resize(PACKET_SIZE); - } -#endif - - OpCode parse() - { -#ifdef ARTNET_ENABLE_WIFI - if (!isNetworkReady()) { - return OpCode::NoPacket; - } -#endif - size_t size = this->stream->parsePacket(); - if (size == 0) { - return OpCode::NoPacket; - } - - this->logger->print(F("Packet received: size = ")); - this->logger->println(size); - - if (size > PACKET_SIZE) { - this->logger->print(F("Packet size is unexpectedly too large: ")); - this->logger->println(size); - size = PACKET_SIZE; - } - this->stream->read(this->packet.data(), size); - - if (!checkID()) { - this->logger->println(F("Packet ID is not Art-Net")); - return OpCode::ParseFailed; - } - - RemoteInfo remote_info; - remote_info.ip = this->stream->S::remoteIP(); - remote_info.port = (uint16_t)this->stream->S::remotePort(); - - OpCode op_code = OpCode::Unsupported; - OpCode received_op_code = static_cast(this->getOpCode()); - switch (received_op_code) { - case OpCode::Dmx: { - art_dmx::Metadata metadata = art_dmx::generateMetadataFrom(this->packet.data()); - if (this->callback_art_dmx) { - this->callback_art_dmx(this->getArtDmxData(), size - HEADER_SIZE, metadata, remote_info); - } - for (auto& cb : this->callback_art_dmx_universes) { - if (this->getArtDmxUniverse15bit() == cb.first) { - cb.second(this->getArtDmxData(), size - HEADER_SIZE, metadata, remote_info); - } - } - op_code = OpCode::Dmx; - break; - } - case OpCode::Nzs: { - art_nzs::Metadata metadata = art_nzs::generateMetadataFrom(this->packet.data()); - for (auto& cb : this->callback_art_nzs_universes) { - if (this->getArtDmxUniverse15bit() == cb.first) { - cb.second(this->getArtDmxData(), size - HEADER_SIZE, metadata, remote_info); - } - } - op_code = OpCode::Nzs; - break; - } - case OpCode::Poll: { - this->sendArtPollReply(remote_info); - op_code = OpCode::Poll; - break; - } - case OpCode::Trigger: { - if (this->callback_art_trigger) { - ArtTriggerMetadata metadata = { - .oem = this->getArtTriggerOEM(), - .key = this->getArtTriggerKey(), - .sub_key = this->getArtTriggerSubKey(), - .payload = this->getArtTriggerPayload(), - .size = static_cast(size - art_trigger::PAYLOAD), - }; - this->callback_art_trigger(metadata, remote_info); - } - op_code = OpCode::Trigger; - break; - } - case OpCode::Sync: { - if (this->callback_art_sync) { - this->callback_art_sync(remote_info); - } - op_code = OpCode::Sync; - break; - } - default: { - this->logger->print(F("Unsupported OpCode: ")); - this->logger->println(this->getOpCode(), HEX); - op_code = OpCode::Unsupported; - break; - } - } - - this->stream->flush(); - return op_code; - } - - // subscribe artdmx packet for specified net, subnet, and universe - template - auto subscribeArtDmxUniverse(uint8_t net, uint8_t subnet, uint8_t universe, const Fn &func) - -> std::enable_if_t::value> - { - if (net > 0x7F) { - this->logger->println(F("net should be less than 0x7F")); - return; - } - if (subnet > 0xF) { - this->logger->println(F("subnet should be less than 0xF")); - return; - } - if (universe > 0xF) { - this->logger->println(F("universe should be less than 0xF")); - return; - } - uint16_t u = ((uint16_t)net << 8) | ((uint16_t)subnet << 4) | (uint16_t)universe; - this->subscribeArtDmxUniverse(u, func); - } - - // subscribe artdmx packet for specified universe (15 bit) - template - auto subscribeArtDmxUniverse(uint16_t universe, const Fn &func) - -> std::enable_if_t::value> - { - this->callback_art_dmx_universes.insert(std::make_pair(universe, arx::function_traits::cast(func))); - } - - // subscribe artnzs packet for specified universe (15 bit) - template - auto subscribeArtNzsUniverse(uint16_t universe, const Fn &func) - -> std::enable_if_t::value> - { - this->callback_art_nzs_universes.insert(std::make_pair(universe, arx::function_traits::cast(func))); - } - - // subscribe artdmx packet for all universes - template - auto subscribeArtDmx(const Fn &func) - -> std::enable_if_t::value> - { - this->callback_art_dmx = arx::function_traits::cast(func); - } - - // subscribe other packets - template - auto subscribeArtSync(const Fn &func) - -> std::enable_if_t::value> - { - this->callback_art_sync = arx::function_traits::cast(func); - } - - template - auto subscribeArtTrigger(const Fn &func) - -> std::enable_if_t::value> - { - this->callback_art_trigger = arx::function_traits::cast(func); - } - - void unsubscribeArtDmxUniverse(uint8_t net, uint8_t subnet, uint8_t universe) - { - uint16_t u = ((uint16_t)net << 8) | ((uint16_t)subnet << 4) | (uint16_t)universe; - this->unsubscribe(u); - } - void unsubscribeArtDmxUniverse(uint16_t universe) - { - auto it = this->callback_art_dmx_universes.find(universe); - if (it != this->callback_art_dmx_universes.end()) { - this->callback_art_dmx_universes.erase(it); - } - } - void unsubscribeArtDmxUniverses() - { - this->callback_art_dmx_universes.clear(); - } - void unsubscribeArtDmx() - { - this->callback_art_dmx = nullptr; - } - - void unsubscribeArtNzsUniverse(uint16_t universe) - { - auto it = this->callback_art_nzs_universes.find(universe); - if (it != this->callback_art_nzs_universes.end()) { - this->callback_art_nzs_universes.erase(it); - } - } - - void unsubscribeArtSync() - { - this->callback_art_sync = nullptr; - } - - void unsubscribeArtTrigger() - { - this->callback_art_trigger = nullptr; - } - -#ifdef FASTLED_VERSION - void forwardArtDmxDataToFastLED(uint8_t net, uint8_t subnet, uint8_t universe, CRGB* leds, uint16_t num) - { - uint16_t u = ((uint16_t)net << 8) | ((uint16_t)subnet << 4) | (uint16_t)universe; - this->forwardArtDmxDataToFastLED(u, leds, num); - } - void forwardArtDmxDataToFastLED(uint16_t universe, CRGB* leds, uint16_t num) - { - this->subscribeArtDmxUniverse(universe, [this, leds, num](const uint8_t* data, const uint16_t size, const ArtDmxMetadata &, const RemoteInfo &) { - size_t n; - if (num <= size / 3) { - // OK: requested number of LEDs is less than received data size - n = num; - } else { - n = size / 3; - this->logger->println(F("WARN: ArtNet packet size is less than requested LED numbers to forward")); - this->logger->print(F(" requested: ")); - this->logger->print(num * 3); - this->logger->print(F(" received : ")); - this->logger->println(size); - } - for (size_t pixel = 0; pixel < n; ++pixel) { - size_t idx = pixel * 3; - leds[pixel].r = data[idx + 0]; - leds[pixel].g = data[idx + 1]; - leds[pixel].b = data[idx + 2]; - } - }); - } -#endif - - // https://art-net.org.uk/how-it-works/discovery-packets/artpollreply/ - void setArtPollReplyConfigOem(uint16_t oem) - { - this->art_poll_reply_config.oem = oem; - } - void setArtPollReplyConfigEstaMan(uint16_t esta_man) - { - this->art_poll_reply_config.esta_man = esta_man; - } - void setArtPollReplyConfigStatus1(uint8_t status1) - { - this->art_poll_reply_config.status1 = status1; - } - void setArtPollReplyConfigStatus2(uint8_t status2) - { - this->art_poll_reply_config.status2 = status2; - } - void setArtPollReplyConfigShortName(const String &short_name) - { - this->art_poll_reply_config.short_name = short_name; - } - void setArtPollReplyConfigLongName(const String &long_name) - { - this->art_poll_reply_config.long_name = long_name; - } - void setArtPollReplyConfigNodeReport(const String &node_report) - { - this->art_poll_reply_config.node_report = node_report; - } - void setArtPollReplyConfigSwIn(size_t index, uint8_t sw_in) - { - if (index < 4) { - this->art_poll_reply_config.sw_in[index] = sw_in; - } - } - void setArtPollReplyConfigSwIn(uint8_t sw_in[4]) - { - for (size_t i = 0; i < 4; ++i) { - this->art_poll_reply_config.sw_in[i] = sw_in[i]; - } - } - void setArtPollReplyConfigSwIn(uint8_t sw_in_0, uint8_t sw_in_1, uint8_t sw_in_2, uint8_t sw_in_3) - { - this->setArtPollReplyConfigSwIn(0, sw_in_0); - this->setArtPollReplyConfigSwIn(1, sw_in_1); - this->setArtPollReplyConfigSwIn(2, sw_in_2); - this->setArtPollReplyConfigSwIn(3, sw_in_3); - } - void setArtPollReplyConfig( - uint16_t oem, - uint16_t esta_man, - uint8_t status1, - uint8_t status2, - const String &short_name, - const String &long_name, - const String &node_report, - uint8_t sw_in[4] - ) { - this->setArtPollReplyConfigOem(oem); - this->setArtPollReplyConfigEstaMan(esta_man); - this->setArtPollReplyConfigStatus1(status1); - this->setArtPollReplyConfigStatus2(status2); - this->setArtPollReplyConfigShortName(short_name); - this->setArtPollReplyConfigLongName(long_name); - this->setArtPollReplyConfigNodeReport(node_report); - this->setArtPollReplyConfigSwIn(sw_in); - } - void setArtPollReplyConfig(const ArtPollReplyConfig &cfg) - { - this->art_poll_reply_config = cfg; - } - - void setLogger(Print* logger) - { - this->logger = logger; - } - -protected: - void attach(S& s) - { - this->stream = &s; - } - -private: - - bool checkID() const - { - const char* idptr = reinterpret_cast(this->packet.data()); - return !strcmp(ARTNET_ID, idptr); - } - - uint16_t getOpCode() const - { - return (this->packet[art_dmx::OP_CODE_H] << 8) | this->packet[art_dmx::OP_CODE_L]; - } - - uint16_t getArtDmxUniverse15bit() const - { - return (this->packet[art_dmx::NET] << 8) | this->packet[art_dmx::SUBUNI]; - } - - const uint8_t *getArtDmxData() const - { - return &(this->packet[art_dmx::DATA]); - } - - void sendArtPollReply(const RemoteInfo &remote) - { - const IPAddress my_ip = this->localIP(); - uint8_t my_mac[6]; - this->macAddress(my_mac); - - arx::stdx::map universes; - for (const auto &cb_pair : this->callback_art_dmx_universes) { - universes[cb_pair.first] = true; - } - for (const auto &cb_pair : this->callback_art_nzs_universes) { - universes[cb_pair.first] = true; - } - // if no universe is subscribed, send reply for universe 0 - if (universes.empty()) { - universes[0] = true; - } - - for (const auto &u_pair : universes) { - art_poll_reply::Packet reply = art_poll_reply::generatePacketFrom(my_ip, my_mac, u_pair.first, this->art_poll_reply_config); - this->stream->beginPacket(remote.ip, DEFAULT_PORT); - this->stream->write(reply.b, sizeof(art_poll_reply::Packet)); - this->stream->endPacket(); - } - } - - uint16_t getArtTriggerOEM() const - { - return (this->packet[art_trigger::OEM_H] << 8) | this->packet[art_trigger::OEM_L]; - } - - uint8_t getArtTriggerKey() const - { - return this->packet[art_trigger::KEY]; - } - - uint8_t getArtTriggerSubKey() const - { - return this->packet[art_trigger::SUB_KEY]; - } - - const uint8_t *getArtTriggerPayload() const - { - return this->packet.data() + art_trigger::PAYLOAD; - } - - IPAddress localIP() - { - switch (WiFi.getMode()) - { - case WIFI_AP: - return WiFi.softAPIP(); - break; - case WIFI_STA: - return WiFi.localIP(); - break; - default: - return ETH.localIP(); - break; - } - } - - IPAddress subnetMask() - { - switch (WiFi.getMode()) - { - case WIFI_AP: - return WiFi.softAPSubnetMask(); - break; - case WIFI_STA: - return WiFi.subnetMask(); - break; - default: - return ETH.subnetMask(); - break; - } - } - - void macAddress(uint8_t* mac) - { - switch (WiFi.getMode()) - { - case WIFI_AP: - WiFi.softAPmacAddress(mac); - break; - case WIFI_STA: - WiFi.macAddress(mac); - break; - default: - ETH.macAddress(mac); - //Ethernet.MACAddress(mac); - break; - } - } -}; - -template -class Receiver : public Receiver_ -{ - S stream; - -public: - void begin(uint16_t recv_port = DEFAULT_PORT) - { - this->stream.begin(recv_port); - this->Receiver_::attach(this->stream); - } -}; - -} // namespace art_net - -#endif // ARTNET_RECEIVER_H diff --git a/lib/ArtNet/Artnet/Sender.h b/lib/ArtNet/Artnet/Sender.h deleted file mode 100644 index ea956c8..0000000 --- a/lib/ArtNet/Artnet/Sender.h +++ /dev/null @@ -1,208 +0,0 @@ -#pragma once -#ifndef ARTNET_SENDER_H -#define ARTNET_SENDER_H - -#include "Common.h" -#include "ArtDmx.h" -#include "ArtNzs.h" -#include "ArtTrigger.h" -#include "ArtSync.h" - -namespace art_net { - -template -class Sender_ -{ - S* stream; - Array packet; - LastSendTimeMsMap last_send_times; - SequenceMap dmx_sequences; - SequenceMap nzs_sequences; - -public: -#if ARX_HAVE_LIBSTDCPLUSPLUS >= 201103L // Have libstdc++11 -#else - Sender_() - { - this->packet.resize(PACKET_SIZE); - } -#endif - - // streaming artdmx packet - void setArtDmxData(const uint8_t* const data, uint16_t size) - { - art_dmx::setDataTo(this->packet.data(), data, size); - } - void setArtDmxData(uint16_t ch, uint8_t data) - { - art_dmx::setDataTo(this->packet.data(), ch, data); - } - - void streamArtDmxTo(const String& ip, uint16_t universe15bit) - { - uint8_t net = (universe15bit >> 8) & 0x7F; - uint8_t subnet = (universe15bit >> 4) & 0x0F; - uint8_t universe = (universe15bit >> 0) & 0x0F; - this->streamArtDmxTo(ip, net, subnet, universe, 0); - } - void streamArtDmxTo(const String& ip, uint8_t net, uint8_t subnet, uint8_t universe) - { - this->streamArtDmxTo(ip, net, subnet, universe, 0); - } - void streamArtDmxTo(const String& ip, uint8_t net, uint8_t subnet, uint8_t universe, uint8_t physical) - { - Destination dest {ip, net, subnet, universe}; - uint32_t now = millis(); - if (this->last_send_times.find(dest) == this->last_send_times.end()) { - this->last_send_times.insert(std::make_pair(dest, uint32_t(0))); - } - if (now >= this->last_send_times[dest] + DEFAULT_INTERVAL_MS) { - this->sendArxDmxInternal(dest, physical); - this->last_send_times[dest] = now; - } - } - - // streaming artnzs packet - void setArtNzsData(const uint8_t* const data, uint16_t size) - { - art_nzs::setDataTo(this->packet.data(), data, size); - } - void setArtNzsData(uint16_t ch, uint8_t data) - { - art_nzs::setDataTo(this->packet.data(), ch, data); - } - - void streamArtNzsTo(const String& ip, uint16_t universe15bit) - { - uint8_t net = (universe15bit >> 8) & 0x7F; - uint8_t subnet = (universe15bit >> 4) & 0x0F; - uint8_t universe = (universe15bit >> 0) & 0x0F; - this->streamArtNzsTo(ip, net, subnet, universe, 0); - } - void streamArtNzsTo(const String& ip, uint8_t net, uint8_t subnet, uint8_t universe) - { - this->streamArtNzsTo(ip, net, subnet, universe, 0, 0); - } - void streamArtNzsTo(const String& ip, uint8_t net, uint8_t subnet, uint8_t universe, uint8_t start_code) - { - Destination dest {ip, net, subnet, universe}; - uint32_t now = millis(); - if (this->last_send_times.find(dest) == this->last_send_times.end()) { - this->last_send_times.insert(std::make_pair(dest, uint32_t(0))); - } - if (now >= this->last_send_times[dest] + DEFAULT_INTERVAL_MS) { - this->sendArxNzsInternal(dest, start_code); - this->last_send_times[dest] = now; - } - } - - // one-line artdmx sender - void sendArtDmx(const String& ip, uint16_t universe15bit, const uint8_t* const data, uint16_t size) - { - uint8_t net = (universe15bit >> 8) & 0x7F; - uint8_t subnet = (universe15bit >> 4) & 0x0F; - uint8_t universe = (universe15bit >> 0) & 0x0F; - this->sendArtDmx(ip, net, subnet, universe, 0, data, size); - } - void sendArtDmx(const String& ip, uint8_t net, uint8_t subnet, uint8_t universe, const uint8_t* const data, uint16_t size) - { - this->sendArtDmx(ip, net, subnet, universe, 0, data, size); - } - void sendArtDmx(const String& ip, uint8_t net, uint8_t subnet, uint8_t universe, uint8_t physical, const uint8_t *data, uint16_t size) - { - Destination dest {ip, net, subnet, universe}; - this->setArtDmxData(data, size); - this->sendArxDmxInternal(dest, physical); - } - - // one-line artnzs sender - void sendArtNzs(const String& ip, uint16_t universe15bit, const uint8_t* const data, uint16_t size) - { - uint8_t net = (universe15bit >> 8) & 0x7F; - uint8_t subnet = (universe15bit >> 4) & 0x0F; - uint8_t universe = (universe15bit >> 0) & 0x0F; - this->sendArtNzs(ip, net, subnet, universe, data, size); - } - void sendArtNzs(const String& ip, uint8_t net, uint8_t subnet, uint8_t universe, const uint8_t* const data, uint16_t size) - { - this->sendArtNzs(ip, net, subnet, universe, 0, data, size); - } - void sendArtNzs(const String& ip, uint8_t net, uint8_t subnet, uint8_t universe, uint8_t start_code, const uint8_t *data, uint16_t size) - { - Destination dest {ip, net, subnet, universe}; - this->setArtNzsData(data, size); - this->sendArxNzsInternal(dest, start_code); - } - - void sendArtTrigger(const String& ip, uint16_t oem = 0, uint8_t key = 0, uint8_t subkey = 0, const uint8_t *payload = nullptr, uint16_t size = 512) - { - art_trigger::setDataTo(packet.data(), oem, key, subkey, payload, size); - this->sendRawData(ip, DEFAULT_PORT, packet.data(), packet.size()); - } - - void sendArtSync(const String& ip) - { - art_sync::setMetadataTo(packet.data()); - this->sendRawData(ip, DEFAULT_PORT, packet.data(), art_sync::PACKET_SIZE); - } - -protected: - void attach(S& s) - { - this->stream = &s; - } - - void sendArxDmxInternal(const Destination &dest, uint8_t physical) - { -#ifdef ARTNET_ENABLE_WIFI - if (!isNetworkReady()) { - return; - } -#endif - if (this->dmx_sequences.find(dest) == this->dmx_sequences.end()) { - this->dmx_sequences.insert(std::make_pair(dest, uint8_t(0))); - } - art_dmx::setMetadataTo(this->packet.data(), this->dmx_sequences[dest], physical, dest.net, dest.subnet, dest.universe); - this->sendRawData(dest.ip, DEFAULT_PORT, this->packet.data(), this->packet.size()); - this->dmx_sequences[dest] = (this->dmx_sequences[dest] + 1) % 256; - } - - void sendArxNzsInternal(const Destination &dest, uint8_t start_code) - { -#ifdef ARTNET_ENABLE_WIFI - if (!isNetworkReady()) { - return; - } -#endif - if (this->nzs_sequences.find(dest) == this->nzs_sequences.end()) { - this->nzs_sequences.insert(std::make_pair(dest, uint8_t(0))); - } - art_nzs::setMetadataTo(this->packet.data(), this->nzs_sequences[dest], start_code, dest.net, dest.subnet, dest.universe); - this->sendRawData(dest.ip, DEFAULT_PORT, this->packet.data(), this->packet.size()); - this->nzs_sequences[dest] = (this->nzs_sequences[dest] + 1) % 256; - } - - void sendRawData(const String& ip, uint16_t port, const uint8_t* const data, size_t size) - { - this->stream->beginPacket(ip.c_str(), port); - this->stream->write(data, size); - this->stream->endPacket(); - } -}; - -template -class Sender : public Sender_ -{ - S stream; - -public: - void begin() - { - this->stream.begin(DEFAULT_PORT); - this->Sender_::attach(this->stream); - } -}; - -} // namespace art_net - -#endif // ARTNET_SENDER_H diff --git a/lib/ArtNet/Artnet/util/TeensyDirtySTLErrorSolution/LICENSE b/lib/ArtNet/Artnet/util/TeensyDirtySTLErrorSolution/LICENSE deleted file mode 100644 index 6f5269b..0000000 --- a/lib/ArtNet/Artnet/util/TeensyDirtySTLErrorSolution/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020 Hideaki Tai - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/lib/ArtNet/Artnet/util/TeensyDirtySTLErrorSolution/README.md b/lib/ArtNet/Artnet/util/TeensyDirtySTLErrorSolution/README.md deleted file mode 100644 index 166a80f..0000000 --- a/lib/ArtNet/Artnet/util/TeensyDirtySTLErrorSolution/README.md +++ /dev/null @@ -1,57 +0,0 @@ -# TeensyDirtySTLErrorSolution - -dirty solution to use STL in teensy - -## Introduction - -Sometimes we want to use STL on Teensy, but Teensy 3.x in Arduino IDE does not support STL by default. Though STL is enabled on Teensy 4.x, but you have to enable it manually on Teensy 3.x. If you use PlatformIO, you can also use STL on Teensy 3.x. - -| | Teensy 4.x | Teensy 3.x | -| ----------- | ----------------- | ----------------- | -| PlatformIO | Almost Compilable | Almost Compilable | -| Arduino IDE | Almost Compilable | NOT Compilable | - - -## Enable STL in Arduino IDE - -To enable STL on Teensy 3.x using Arduino IDE, add `-lstdc++` to `build flags`, which is defined in `boards.txt`. Many STL can be used by adding this flag. You have to do this procedure every time you upgrade the version of Teensyduino. - -| OS | default location | -| ------- | --------------------------------------------------------------- | -| macOS | `Arduino.app/Contents/Java/hardware/teensy/avr/boards.txt` | -| Windows | `C:\Program Files (x86)\Arduino\hardware\teensy\avr\boards.txt` | - - -#### Before - -``` boards.txt - teensy36.build.flags.libs=-larm_cortexM4lf_math -lm - teensy35.build.flags.libs=-larm_cortexM4lf_math -lm - teensy31.build.flags.libs=-larm_cortexM4l_math -lm -``` - -#### After - -``` boards.txt - teensy36.build.flags.libs=-larm_cortexM4lf_math -lm -lstdc++ - teensy35.build.flags.libs=-larm_cortexM4lf_math -lm -lstdc++ - teensy31.build.flags.libs=-larm_cortexM4l_math -lm -lstdc++ -``` - -## Do you still have compile error? - -Yes, maybe you still have compilation error in both 4.x and 3.x for some STLs... Then you should add this library (header file) to your project. Some dirty solution I found is included in this header file. - -``` C++ -#include -``` - -## Warning - -This method is not recommended because STL is not enabled by default... (if you know the reason, please let me know). I am not responsible for any trouble that may occur as a result of the use of this library. Please use at your own risk. - - -## License - -MIT - diff --git a/lib/ArtNet/Artnet/util/TeensyDirtySTLErrorSolution/TeensyDirtySTLErrorSolution.h b/lib/ArtNet/Artnet/util/TeensyDirtySTLErrorSolution/TeensyDirtySTLErrorSolution.h deleted file mode 100644 index b50c6a3..0000000 --- a/lib/ArtNet/Artnet/util/TeensyDirtySTLErrorSolution/TeensyDirtySTLErrorSolution.h +++ /dev/null @@ -1,65 +0,0 @@ -#pragma once - -#include - -#ifdef TEENSYDUINO -#ifndef TEENSYDUINO_DIRTY_STL_ERROR_SOLUTION -#define TEENSYDUINO_DIRTY_STL_ERROR_SOLUTION - - -#if defined(__MK20DX256__) || defined(__MK64FX512__) || defined(__MK66FX1M0__) // TEENSY 3.1/3.2, 3.5, 3.6 - -extern "C" -{ - int _write() { return -1; } -} - -#elif defined(__IMXRT1062__) // TEENSY4.0 - -extern "C" -{ - void *__exidx_start __attribute__((__visibility__ ("hidden"))); - void *__exidx_end __attribute__((__visibility__ ("hidden"))); -} - -#else - - #error NOT SUPPORTED TEENSY VERSION - -#endif - - -// ----- template ----- -// -// #if defined(__MK20DX256__) // TEENSY3.1/3.2 -// #elif defined(__MK64FX512__) // TEENSY3.5 -// #elif defined(__MK66FX1M0__) // TEENSY3.6 -// #elif defined(__IMXRT1062__) // TEENSY4.0 -// -// extern "C" -// { -// int _getpid() { return -1; } -// int _kill(int pid, int sig) { return -1; } -// int _write() { return -1; } -// void *__exidx_start __attribute__((__visibility__ ("hidden"))); -// void *__exidx_end __attribute__((__visibility__ ("hidden"))); -// int _getpid();// { return -1; } -// int _kill(int pid, int sig);// { return -1; } -// int _write() { return -1; } -// void *__exidx_start __attribute__((__visibility__ ("hidden"))); -// void *__exidx_end __attribute__((__visibility__ ("hidden"))); -// } -// -// // copied from https://github.com/gcc-mirror/ -// namespace std -// { -// void __throw_bad_alloc() { _GLIBCXX_THROW_OR_ABORT(bad_alloc()); } -// void __throw_length_error(const char* __s __attribute__((unused))) { _GLIBCXX_THROW_OR_ABORT(length_error(_(__s))); } -// void __throw_bad_function_call() { _GLIBCXX_THROW_OR_ABORT(bad_function_call()); } -// void _Rb_tree_decrement(std::_Rb_tree_node_base* a) {} -// void _Rb_tree_insert_and_rebalance(bool, std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::_Rb_tree_node_base&) {} -// } - -#endif // TEENSYDUINO_DIRTY_STL_ERROR_SOLUTION -#endif // TEENSYDUINO - diff --git a/lib/ArtNet/ArtnetETH.h b/lib/ArtNet/ArtnetETH.h deleted file mode 100644 index af55213..0000000 --- a/lib/ArtNet/ArtnetETH.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once -#ifndef ARTNET_ETH_H -#define ARTNET_ETH_H - -#define ARTNET_ENABLE_ETH - -#include -#include -#include -#include -#include -#include "Artnet/Manager.h" - -// ETH.h is a library for Ethernet PHY, but we should use WiFi library's apis for sever/client -using Artnet = art_net::Manager; -using ArtnetSender = art_net::Sender; -using ArtnetReceiver = art_net::Receiver; - -#endif // ARTNET_ETH_H diff --git a/lib/ArtNet/ArtnetWiFi.h b/lib/ArtNet/ArtnetWiFi.h deleted file mode 100644 index ef1183a..0000000 --- a/lib/ArtNet/ArtnetWiFi.h +++ /dev/null @@ -1,40 +0,0 @@ -#pragma once -#ifndef ARTNET_WIFI_H -#define ARTNET_WIFI_H - -#if defined(ESP_PLATFORM) || defined(ESP8266) || defined(ARDUINO_AVR_UNO_WIFI_REV2) \ - || defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_MKRVIDOR4000) || defined(ARDUINO_SAMD_MKR1000) \ - || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_RASPBERRY_PI_PICO_W) || defined(ARDUINO_UNOR4_WIFI) -#define ARTNET_ENABLE_WIFI -#endif - -#ifdef ARTNET_ENABLE_WIFI -#include -#include -#include -#if defined(ESP_PLATFORM) || defined(ARDUINO_ARCH_RP2040) -#include -#include -#elif defined(ESP8266) -#include -#include -#elif defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_MKRVIDOR4000) \ - || defined(ARDUINO_SAMD_NANO_33_IOT) -#include -#include -#include -#elif defined(ARDUINO_SAMD_MKR1000) -#include -#include -#include -#elif defined(ARDUINO_UNOR4_WIFI) -#include -#endif -#include "Artnet/Manager.h" - -using ArtnetWiFi = art_net::Manager; -using ArtnetWiFiSender = art_net::Sender; -using ArtnetWiFiReceiver = art_net::Receiver; -#endif // ARTNET_ENABLE_WIFI - -#endif // ARTNET_WIFI_H diff --git a/lib/ArtNet/LICENSE b/lib/ArtNet/LICENSE deleted file mode 100644 index 8c86460..0000000 --- a/lib/ArtNet/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2019 Hideaki Tai - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/lib/ArtNet/README.md b/lib/ArtNet/README.md deleted file mode 100644 index 97f2b31..0000000 --- a/lib/ArtNet/README.md +++ /dev/null @@ -1,423 +0,0 @@ -# ArtNet - -[Art-Net](https://en.wikipedia.org/wiki/Art-Net) Sender/Receiver for Arduino (Ethernet, WiFi) - -> [!WARNING] -> Breaking API changes from v0.4.0 and above - -> [!WARNING] -> Dependent libraries removed from v0.3.0 - -If you have already installed this library before v0.3.0, please follow: - -- Cloned from GitHub (manually): Please install dependent libraries manually -- Installed from library manager: re-install this library from library manager - - Dependent libraries will be installed automatically - -## Feature - -- Supports following protocols: - - ArtDmx - - ArtNzs - - ArtPoll/ArtPollReply - - ArtTrigger - - ArtSync -- Supports multiple WiFi/Ethernet libraries - - WiFi - - WiFiNINA - - WiFiS3 (Arduino Uno R4 WiFi) - - Ethernet - - EthernetENC - - ETH (ESP32) -- Supports a lot of boards which can use Ethernet or WiFi -- Multiple receiver callbacks depending on universe -- Mutilple destination streaming with sender -- One-line send to desired destination -- Flexible net/subnet/universe setting -- Easy data forwarding to [FastLED](https://github.com/FastLED/FastLED) - -## Supported Platforms - -#### WiFi - -- ESP32 -- ESP8266 -- Raspberry Pi Pico W -- Arduino Uno WiFi Rev2 -- Arduino Uno R4 WiFi -- Arduino MKR VIDOR 4000 -- Arduino MKR WiFi 1010 -- Arduino MKR WiFi 1000 -- Arduino Nano 33 IoT - -#### Ethernet - -- ESP32 (Ethernet and ETH) -- ESP8266 -- Almost all platforms without WiFi -- Any platform supported by ENC28J60 (please read following section) - -
- Notes for ENC28J60 ethernet controller (click to expand) - -When using the ENC28J60 controller - -- make sure to **clone** the [EthernetENC](https://github.com/JAndrassy/EthernetENC) library (version =< 2.0.4 doesn't support MAC address) -- simply replace `#include ` with `#include ` -
- -## Usage - -This library has following Art-Net controller options. -Please use them depending on the situation. - -- ArtnetReveiver -- ArtnetSender -- Artnet (Integrated Sender/Receiver) - -### Include Artnet - -Please include `#include "Artnet.h` first. - -If you use the board which has both `WiFi` and `Ethernet`, you can't use `#include `. Please replace it with `#include ` or `#include ` depending on the interface you want to use. - -```C++ -// For the boards which can use ether WiFi or Ethernet -#include -// OR use WiFi on the board which can use both WiFi and Ethernet -#include -// OR use Ethenet on the board which can use both WiFi and Ethernet -#include -``` - -### ArtnetReceiver - -```C++ -#include -ArtnetReceiver artnet; - -void callback(const uint8_t *data, uint16_t size, const ArtDmxMetadata &metadata, const ArtNetRemoteInfo &remote) { - // you can also use pre-defined callbacks -} - -void setup() { - // setup Ethernet/WiFi... - - artnet.begin(); // waiting for Art-Net in default port - - artnet.subscribeArtDmxUniverse(universe15bit, [&](const uint8_t *data, uint16_t size, const ArtDmxMetadata &metadata, const ArtNetRemoteInfo &remote) { - // if Artnet packet comes to this universe(0-15), this function is called - }); - - // you can also use pre-defined callbacks - artnet.subscribeArtDmxUniverse(net, subnet, universe, callback); -} - -void loop() { - artnet.parse(); // check if artnet packet has come and execute callback -} -``` - -### ArtnetSender - -```C++ -#include -ArtnetSender artnet; - -void setup() { - // setup Ethernet/WiFi... - - artnet.begin(); -} - -void loop() { - // change send data as you want - - // one-line send - artnet.sendArtDmx("127.0.0.1", universe15bit, data_ptr, size); - // or you can set net and subnet - // artnet.sendArtDmx("127.0.0.1", net, subnet, universe, data_ptr, size); - - // To use streamArtDmxTo(), you need to setArtDmxData() before streamArtDmxTo() - artnet.setArtDmxData(data_ptr, size); - // automatically send set data in 40fps - artnet.streamArtDmxTo("127.0.0.1", universe15bit); - // or you can set net and subnet here - // artnet.streamArtDmxTo("127.0.0.1", net, subnet, universe); -} -``` - -### Artnet (Integrated Sender/Receiver) - -`ArtNet` class has `ArtNetReceiver` and `ArtNetSender` features. - -```C++ -#include -Artnet artnet; - -void setup() -{ - // setup Ethernet/WiFi... - - artnet.begin(); // send to localhost and listen to default port - - artnet.subscribeArtDmxUniverse(universe, [&](const uint8_t *data, uint16_t size, const ArtDmxMetadata &metadata, const ArtNetRemoteInfo &remote) { - // if Artnet packet comes to this universe, this function is called - }); - artnet.subscribeArtDmx([&](const uint8_t *data, uint16_t size, const ArtDmxMetadata& metadata, const ArtNetRemoteInfo& remote) { - // if Artnet packet comes, this function is called for every universe - }); -} - -void loop() { - artnet.parse(); // check if artnet packet has come and execute callback - - // change send data as you want - - artnet.send("127.0.0.1", universe, data_ptr, size); // one-line send - - artnet.streaming_data(data_ptr, size); - artnet.streaming("127.0.0.1", universe); // stream in 40 fps -} -``` - -### Artnet Receiver + FastLED - -```C++ -#include -ArtnetReceiver artnet; - -// FastLED -#define NUM_LEDS 1 -CRGB leds[NUM_LEDS]; -const uint8_t PIN_LED_DATA = 3; - -void setup() { - // setup Ethernet/WiFi... - - // setup FastLED - FastLED.addLeds(&leds, NUM_LEDS); - - artnet.begin(); - // if Artnet packet comes to this universe, forward them to fastled directly - artnet.forwardArtDmxDataToFastLED(universe, leds, NUM_LEDS); - - // this can be achieved manually as follows - // artnet.subscribeArtDmxUniverse(universe, [](const uint8_t *data, uint16_t size, const ArtDmxMetadata& metadata, const ArtNetRemoteInfo& remote) - // { - // // artnet data size per packet is 512 max - // // so there is max 170 pixel per packet (per universe) - // for (size_t pixel = 0; pixel < NUM_LEDS; ++pixel) - // { - // size_t idx = pixel * 3; - // leds[pixel].r = data[idx + 0]; - // leds[pixel].g = data[idx + 1]; - // leds[pixel].b = data[idx + 2]; - // } - // }); -} - -void loop() { - artnet.parse(); // check if artnet packet has come and execute callback - FastLED.show(); -} -``` - -## Other Configurations - -### Subscribing Callbacks with Net, Sub-Net and Universe as you like - -- The relationship of Net (0-127), Sub-Net (0-15), 4-bit Universe (0-15) and 15-bit Universe (0-32767) is `universe15bit = (net << 8) | (subnet << 4) | universe4bit` -- You can subscribe ArtDmx data for Net (0-127), Sub-Net (0-15), and 4-bit Universe (0-15) like `artnet.subscribeArtDmxUniverse(net, subnet, universe, callback)` -- Or you can use 15-bit Universe (0-32767) can be set lnke `artnet.subscribeArtDmxUniverse(universe, callback)` -- Subscribed universes (targets of the callbacks) are automatically reflected to `net_sw` `sub_sw` `sw_out` in `ArtPollreply` - -### ArtPollReply Configuration - -- This library supports `ArtPoll` and `ArtPollReply` -- `ArtPoll` is automatically parsed and sends `ArtPollReply` -- You can configure the following information of by `setArtPollReplyConfig()` -- Other settings are set automatically based on registerd callbacks -- Please refer [here](https://art-net.org.uk/downloads/art-net.pdf) for more information - -```C++ -struct ArtPollReplyMetadata -{ - uint16_t oem {0x00FF}; // OemUnknown https://github.com/tobiasebsen/ArtNode/blob/master/src/Art-NetOemCodes.h - uint16_t esta_man {0x0000}; // ESTA manufacturer code - uint8_t status1 {0x00}; // Unknown / Normal - uint8_t status2 {0x08}; // sACN capable - String short_name {"Arduino ArtNet"}; - String long_name {"Ardino ArtNet Protocol by hideakitai/ArtNet"}; - String node_report {""}; - // Four universes from Device to Controller - // NOTE: Only low 4 bits of the universes - // NOTE: Upper 11 bits of the universes will be - // shared with the subscribed universe (net, subnet) - // e.g.) If you have subscribed universe 0x1234, - // you can set the device to controller universes - // from 0x1230 to 0x123F (sw_in will be from 0x0 to 0xF). - // So, I recommned subscribing only in the range of - // 0x1230 to 0x123F if you want to set the sw_in. - // REF: Please refer the Art-Net spec for the detail. - // https://art-net.org.uk/downloads/art-net.pdf - uint8_t sw_in[4] {0}; -}; -``` - -```c++ -// set information for artpollreply individually -// https://art-net.org.uk/downloads/art-net.pdf -void setArtPollReplyConfig(const ArtPollReplyConfig &cfg); -void setArtPollReplyConfig(uint16_t oem, uint16_t esta_man, uint8_t status1, uint8_t status2, const String &short_name, const String &long_name, const String &node_report, uint8_t sw_in[4]); -void setArtPollReplyConfigOem(uint16_t oem); -void setArtPollReplyConfigEstaMan(uint16_t esta_man); -void setArtPollReplyConfigStatus1(uint8_t status1); -void setArtPollReplyConfigStatus2(uint8_t status2); -void setArtPollReplyConfigShortName(const String &short_name); -void setArtPollReplyConfigLongName(const String &long_name); -void setArtPollReplyConfigNodeReport(const String &node_report); -void setArtPollReplyConfigSwIn(size_t index, uint8_t sw_in); -void setArtPollReplyConfigSwIn(uint8_t sw_in[4]); -void setArtPollReplyConfigSwIn(uint8_t sw_in_0, uint8_t sw_in_1, uint8_t sw_in_2, uint8_t sw_in_3); -``` - -## ArtTrigger - -You can send/subscribe `ArtTrigger` using the follwing APIs. Please refer [here](https://art-net.org.uk/how-it-works/time-keeping-triggering/arttrigger/) for more information. - -```C++ -void sendArtTrigger(const String& ip, uint16_t oem = 0, uint8_t key = 0, uint8_t subkey = 0, const uint8_t *payload = nullptr, uint16_t size = 512); -void subscribeArtTrigger(const ArtTriggerCallback &func); -using ArtTriggerCallback = std::function; -``` - -## ArtSync - -You can send/subscribe `ArtSync` using the follwing APIs. Please refer [here](https://art-net.org.uk/how-it-works/time-keeping-triggering/arttimesync/) for more information. - -```C++ -void sendArtSync(const String& ip); -void subscribeArtSync(const ArtSyncCallback &func); -using ArtSyncCallback = std::function; -``` - -## APIs - -### ArtnetSender - -```C++ -// streaming artdmx packet -void setArtDmxData(const uint8_t* const data, uint16_t size); -void setArtDmxData(uint16_t ch, uint8_t data); -void streamArtDmxTo(const String& ip, uint16_t universe15bit); -void streamArtDmxTo(const String& ip, uint8_t net, uint8_t subnet, uint8_t universe); -void streamArtDmxTo(const String& ip, uint8_t net, uint8_t subnet, uint8_t universe, uint8_t physical); -// streaming artnzs packet -void setArtNzsData(const uint8_t* const data, uint16_t size); -void setArtNzsData(uint16_t ch, uint8_t data); -void streamArtNzsTo(const String& ip, uint16_t universe15bit); -void streamArtNzsTo(const String& ip, uint8_t net, uint8_t subnet, uint8_t universe); -void streamArtNzsTo(const String& ip, uint8_t net, uint8_t subnet, uint8_t universe, uint8_t start_code); -// one-line artdmx sender -void sendArtDmx(const String& ip, uint16_t universe15bit, const uint8_t* const data, uint16_t size); -void sendArtDmx(const String& ip, uint8_t net, uint8_t subnet, uint8_t universe, const uint8_t* const data, uint16_t size); -void sendArtDmx(const String& ip, uint8_t net, uint8_t subnet, uint8_t universe, uint8_t physical, const uint8_t *data, uint16_t size); -// one-line artnzs sender -void sendArtNzs(const String& ip, uint16_t universe15bit, const uint8_t* const data, uint16_t size); -void sendArtNzs(const String& ip, uint8_t net, uint8_t subnet, uint8_t universe, const uint8_t* const data, uint16_t size); -void sendArtNzs(const String& ip, uint8_t net, uint8_t subnet, uint8_t universe, uint8_t start_code, const uint8_t *data, uint16_t size); -// send other packets -void sendArtTrigger(const String& ip, uint16_t oem = 0, uint8_t key = 0, uint8_t subkey = 0, const uint8_t *payload = nullptr, uint16_t size = 512); -void sendArtSync(const String& ip); -``` - -### ArtnetReceiver - -```C++ -using ArtDmxCallback = std::function; -using ArtSyncCallback = std::function; -using ArtTriggerCallback = std::function; -``` - -```C++ -struct ArtNetRemoteInfo -{ - IPAddress ip; - uint16_t port; -}; - -struct ArtDmxMetadata -{ - uint8_t sequence; - uint8_t physical; - uint8_t net; - uint8_t subnet; - uint8_t universe; -}; -``` - -```C++ -OpCode parse() -// subscribe artdmx packet for specified net, subnet, and universe -void subscribeArtDmxUniverse(uint8_t net, uint8_t subnet, uint8_t universe, const ArtDmxCallback &func); -// subscribe artdmx packet for specified universe (15 bit) -void subscribeArtDmxUniverse(uint16_t universe, const ArtDmxCallback &func); -// subscribe artnzs packet for specified universe (15 bit) -auto subscribeArtNzsUniverse(uint16_t universe, const ArtNzsCallback &func); -// subscribe artdmx packet for all universes -void subscribeArtDmx(const ArtDmxCallback &func); -// subscribe other packets -void subscribeArtSync(const ArtSyncCallback &func); -void subscribeArtTrigger(const ArtTriggerCallback &func); -// unsubscribe callbacks -void unsubscribeArtDmxUniverse(uint8_t net, uint8_t subnet, uint8_t universe); -void unsubscribeArtDmxUniverse(uint16_t universe); -void unsubscribeArtDmxUniverses(); -void unsubscribeArtDmx(); -void unsubscribeArtNzsUniverse(uint16_t universe); -void unsubscribeArtSync(); -void unsubscribeArtTrigger(); -// set artdmx data to CRGB (FastLED) directly -void forwardArtDmxDataToFastLED(uint8_t net, uint8_t subnet, uint8_t universe, CRGB* leds, uint16_t num); -void forwardArtDmxDataToFastLED(uint16_t universe, CRGB* leds, uint16_t num); -// set information for artpollreply individually -// https://art-net.org.uk/downloads/art-net.pdf -void setArtPollReplyConfig(const ArtPollReplyConfig &cfg); -void setArtPollReplyConfig(uint16_t oem, uint16_t esta_man, uint8_t status1, uint8_t status2, const String &short_name, const String &long_name, const String &node_report, uint8_t sw_in[4]); -void setArtPollReplyConfigOem(uint16_t oem); -void setArtPollReplyConfigEstaMan(uint16_t esta_man); -void setArtPollReplyConfigStatus1(uint8_t status1); -void setArtPollReplyConfigStatus2(uint8_t status2); -void setArtPollReplyConfigShortName(const String &short_name); -void setArtPollReplyConfigLongName(const String &long_name); -void setArtPollReplyConfigNodeReport(const String &node_report); -void setArtPollReplyConfigSwIn(size_t index, uint8_t sw_in); -void setArtPollReplyConfigSwIn(uint8_t sw_in[4]); -void setArtPollReplyConfigSwIn(uint8_t sw_in_0, uint8_t sw_in_1, uint8_t sw_in_2, uint8_t sw_in_3); -// Set where debug output should go (e.g. setLogger(&Serial); default is nowhere) -void setLogger(Print*); -``` - -### Note - -Some boards without enough memory (e.g. Uno, Nano, etc.) may not be able to use integrated sender/receiver because of the lack of enough memory. Please consider to use more powerful board or to use only sender OR receiver. - -## Reference - -- [Spec (Art-Net 4)](http://artisticlicence.com/WebSiteMaster/User%20Guides/art-net.pdf) -- [Packet Summary](https://art-net.org.uk/structure/packet-summary-2/) -- [Packet Definition](https://art-net.org.uk/structure/streaming-packets/artdmx-packet-definition/) - -## Dependent Libraries - -- [ArxContainer](https://github.com/hideakitai/ArxContainer) -- [ArxTypeTraits](https://github.com/hideakitai/ArxTypeTraits) - -## Embedded Libraries - -- [TeensyDirtySTLErrorSolution v0.1.0](https://github.com/hideakitai/TeensyDirtySTLErrorSolution) - -## License - -MIT diff --git a/lib/ArtNet/library.json b/lib/ArtNet/library.json deleted file mode 100644 index 53caa23..0000000 --- a/lib/ArtNet/library.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "ArtNet", - "keywords": "Art-Net,Artnet,Ethernet,WiFi", - "description": "Art-Net Sender/Receiver for Arduino (Ethernet, WiFi)binary data packer / unpacker", - "repository": { - "type": "git", - "url": "https://github.com/hideakitai/ArtNet.git" - }, - "authors": { - "name": "Hideaki Tai", - "url": "https://github.com/hideakitai", - "maintainer": true - }, - "version": "0.8.0", - "license": "MIT", - "frameworks": "*", - "platforms": "*", - "dependencies": { - "hideakitai/ArxContainer": ">=0.6.0", - "hideakitai/ArxTypeTraits": "*" - } -} diff --git a/lib/ArtNet/library.properties b/lib/ArtNet/library.properties deleted file mode 100644 index 16f461a..0000000 --- a/lib/ArtNet/library.properties +++ /dev/null @@ -1,10 +0,0 @@ -name=ArtNet -version=0.8.0 -author=hideakitai -maintainer=hideakitai -sentence=Art-Net Sender/Receiver for Arduino (Ethernet, WiFi) -paragraph=Art-Net Sender/Receiver for Arduino (Ethernet, WiFi) -category=Communication -url=https://github.com/hideakitai/ArtNet -architectures=* -depends=ArxContainer (>=0.6.0), ArxTypeTraits diff --git a/lib/AsyncWebServer_ESP32_W5500/.codespellrc b/lib/AsyncWebServer_ESP32_W5500/.codespellrc deleted file mode 100644 index 00fe362..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/.codespellrc +++ /dev/null @@ -1,7 +0,0 @@ -# See: https://github.com/codespell-project/codespell#using-a-config-file -[codespell] -# In the event of a false positive, add the problematic word, in all lowercase, to a comma-separated list here: -ignore-words-list = , -check-filenames = -check-hidden = -skip = ./.git,./src,./examples,./Packages_Patches,./LibraryPatches diff --git a/lib/AsyncWebServer_ESP32_W5500/.gitignore b/lib/AsyncWebServer_ESP32_W5500/.gitignore deleted file mode 100644 index 259148f..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/.gitignore +++ /dev/null @@ -1,32 +0,0 @@ -# Prerequisites -*.d - -# Compiled Object files -*.slo -*.lo -*.o -*.obj - -# Precompiled Headers -*.gch -*.pch - -# Compiled Dynamic libraries -*.so -*.dylib -*.dll - -# Fortran module files -*.mod -*.smod - -# Compiled Static libraries -*.lai -*.la -*.a -*.lib - -# Executables -*.exe -*.out -*.app diff --git a/lib/AsyncWebServer_ESP32_W5500/CONTRIBUTING.md b/lib/AsyncWebServer_ESP32_W5500/CONTRIBUTING.md deleted file mode 100644 index a442af2..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/CONTRIBUTING.md +++ /dev/null @@ -1,79 +0,0 @@ -## Contributing to AsyncWebServer_ESP32_W5500 - -### Reporting Bugs - -Please report bugs in AsyncWebServer_ESP32_W5500 if you find them. - -However, before reporting a bug please check through the following: - -* [Existing Open Issues](https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500/issues) - someone might have already encountered this. - -If you don't find anything, please [open a new issue](https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500/issues/new). - -### How to submit a bug report - -Please ensure to specify the following: - -* Arduino IDE version (e.g. 1.8.19) or Platform.io version -* Board Core Version (e.g. ESP32 core v2.0.6) -* Contextual information (e.g. what you were trying to achieve) -* Simplest possible steps to reproduce -* Anything that might be relevant in your opinion, such as: - * Operating system (Windows, Ubuntu, etc.) and the output of `uname -a` - * Network configuration - - -Please be educated, civilized and constructive. Disrespective posts against [GitHub Code of Conduct](https://docs.github.com/en/site-policy/github-terms/github-event-code-of-conduct) will be ignored and deleted. - - -### Example - -``` -Arduino IDE version: 1.8.19 -ESP32_DEV board -ESP32 core v2.0.6 -OS: Ubuntu 20.04 LTS -Linux xy-Inspiron-3593 5.15.0-56-generic #62~20.04.1-Ubuntu SMP Tue Nov 22 21:24:20 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux - -Context: -I encountered a crash while using this library -Steps to reproduce: -1. ... -2. ... -3. ... -4. ... -``` - -### Additional context - -Add any other context about the problem here. - ---- - -### Sending Feature Requests - -Feel free to post feature requests. It's helpful if you can explain exactly why the feature would be useful. - -There are usually some outstanding feature requests in the [existing issues list](https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500/issues?q=is%3Aopen+is%3Aissue+label%3Aenhancement), feel free to add comments to them. - ---- - -### Sending Pull Requests - -Pull Requests with changes and fixes are also welcome! - -Please use the `astyle` to reformat the updated library code as follows (demo for Ubuntu Linux) - -1. Change directory to the library GitHub - -``` -xy@xy-Inspiron-3593:~$ cd Arduino/xy/AsyncWebServer_ESP32_W5500_GitHub/ -xy@xy-Inspiron-3593:~/Arduino/xy/AsyncWebServer_ESP32_W5500_GitHub$ -``` - -2. Issue astyle command - -``` -xy@xy-Inspiron-3593:~/Arduino/xy/AsyncWebServer_ESP32_W5500_GitHub$ bash utils/restyle.sh -``` - diff --git a/lib/AsyncWebServer_ESP32_W5500/LICENSE b/lib/AsyncWebServer_ESP32_W5500/LICENSE deleted file mode 100644 index 94a9ed0..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/LICENSE +++ /dev/null @@ -1,674 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 - - Copyright (C) 2007 Free Software Foundation, Inc. - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. - - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. - - The precise terms and conditions for copying, distribution and -modification follow. - - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of -this License. - - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. diff --git a/lib/AsyncWebServer_ESP32_W5500/README.md b/lib/AsyncWebServer_ESP32_W5500/README.md deleted file mode 100644 index 5aa78a6..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/README.md +++ /dev/null @@ -1,1952 +0,0 @@ -# AsyncWebServer_ESP32_W5500 Library - -[![arduino-library-badge](https://www.ardu-badge.com/badge/AsyncWebServer_ESP32_W5500.svg?)](https://www.ardu-badge.com/AsyncWebServer_ESP32_W5500) -[![GitHub release](https://img.shields.io/github/release/khoih-prog/AsyncWebServer_ESP32_W5500.svg)](https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500/releases) -[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing) -[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/AsyncWebServer_ESP32_W5500.svg)](http://github.com/khoih-prog/AsyncWebServer_ESP32_W5500/issues) - - -Donate to my libraries using BuyMeACoffee - - - ---- ---- - -## Table of contents - -* [Table of contents](#table-of-contents) -* [Important Note from v1.6.2](#Important-Note-from-v162) -* [Why do we need this AsyncWebServer_ESP32_W5500 library](#why-do-we-need-this-AsyncWebServer_ESP32_W5500-library) - * [Features](#features) - * [Why Async is better](#why-async-is-better) - * [Currently supported Boards](#currently-supported-boards) -* [Changelog](changelog.md) -* [Prerequisites](#prerequisites) -* [Installation](#installation) - * [Use Arduino Library Manager](#use-arduino-library-manager) - * [Manual Install](#manual-install) - * [VS Code & PlatformIO](#vs-code--platformio) -* [Important things to remember](#important-things-to-remember) -* [Principles of operation](#principles-of-operation) - * [The Async Web server](#the-async-web-server) - * [Request Life Cycle](#request-life-cycle) - * [Rewrites and how do they work](#rewrites-and-how-do-they-work) - * [Handlers and how do they work](#handlers-and-how-do-they-work) - * [Responses and how do they work](#responses-and-how-do-they-work) - * [Template processing](#template-processing) -* [Request Variables](#request-variables) - * [Common Variables](#common-variables) - * [Headers](#headers) - * [GET, POST and FILE parameters](#get-post-and-file-parameters) - * [JSON body handling with ArduinoJson](#json-body-handling-with-arduinojson) -* [Responses](#responses) - * [Redirect to another URL](#redirect-to-another-url) - * [Basic response with HTTP Code](#basic-response-with-http-code) - * [Basic response with HTTP Code and extra headers](#basic-response-with-http-code-and-extra-headers) - * [Basic response with string content](#basic-response-with-string-content) - * [Basic response with string content and extra headers](#basic-response-with-string-content-and-extra-headers) - * [Respond with content coming from a Stream](#respond-with-content-coming-from-a-stream) - * [Respond with content coming from a Stream and extra headers](#respond-with-content-coming-from-a-stream-and-extra-headers) - * [Respond with content coming from a Stream containing templates](#respond-with-content-coming-from-a-stream-containing-templates) - * [Respond with content coming from a Stream containing templates and extra headers](#respond-with-content-coming-from-a-stream-containing-templates-and-extra-headers) - * [Respond with content using a callback](#respond-with-content-using-a-callback) - * [Respond with content using a callback and extra headers](#respond-with-content-using-a-callback-and-extra-headers) - * [Respond with content using a callback containing templates](#respond-with-content-using-a-callback-containing-templates) - * [Respond with content using a callback containing templates and extra headers](#respond-with-content-using-a-callback-containing-templates-and-extra-headers) - * [Chunked Response](#chunked-response) - * [Chunked Response containing templates](#chunked-response-containing-templates) - * [Print to response](#print-to-response) - * [ArduinoJson Basic Response](#arduinojson-basic-response) - * [ArduinoJson Advanced Response](#arduinojson-advanced-response) -* [Param Rewrite With Matching](#param-rewrite-with-matching) -* [Using filters](#using-filters) -* [Bad Responses](#bad-responses) - * [Respond with content using a callback without content length to HTTP/1.0 clients](#respond-with-content-using-a-callback-without-content-length-to-http10-clients) -* [Async WebSocket Plugin](#async-websocket-plugin) - * [Async WebSocket Event](#async-websocket-event) - * [Methods for sending data to a socket client](#methods-for-sending-data-to-a-socket-client) - * [Direct access to web socket message buffer](#direct-access-to-web-socket-message-buffer) - * [Limiting the number of web socket clients](#limiting-the-number-of-web-socket-clients) -* [Async Event Source Plugin](#async-event-source-plugin) - * [Setup Event Source on the server](#setup-event-source-on-the-server) - * [Setup Event Source in the browser](#setup-event-source-in-the-browser) -* [Remove handlers and rewrites](#remove-handlers-and-rewrites) -* [Setting up the server](#setting-up-the-server) - * [Setup global and class functions as request handlers](#setup-global-and-class-functions-as-request-handlers) - * [Methods for controlling websocket connections](#methods-for-controlling-websocket-connections) - * [Adding Default Headers](#adding-default-headers) - * [Path variable](#path-variable) -* [How to connect W5500 to ESP32](#How-to-connect-W5500-to-ESP32) -* [Examples](#examples) - * [ 1. Async_AdvancedWebServer](examples/Async_AdvancedWebServer) - * [ 2. Async_AdvancedWebServer_MemoryIssues_SendArduinoString](examples/Async_AdvancedWebServer_MemoryIssues_SendArduinoString) - * [ 3. Async_AdvancedWebServer_MemoryIssues_Send_CString](examples/Async_AdvancedWebServer_MemoryIssues_Send_CString) - * [ 4. Async_AdvancedWebServer_SendChunked](examples/Async_AdvancedWebServer_SendChunked) - * [ 5. Async_HelloServer](examples/Async_HelloServer) - * [ 6. Async_HelloServer2](examples/Async_HelloServer2) - * [ 7. Async_HttpBasicAuth](examples/Async_HttpBasicAuth) - * [ 8. AsyncMultiWebServer_ESP32_W5500](examples/AsyncMultiWebServer_ESP32_W5500) - * [ 9. Async_PostServer](examples/Async_PostServer) - * [10. Async_RegexPatterns_ESP32_W5500](examples/Async_RegexPatterns_ESP32_W5500) - * [11. AsyncSimpleServer_ESP32_W5500](examples/AsyncSimpleServer_ESP32_W5500) - * [12. AsyncWebServer_SendChunked](examples/AsyncWebServer_SendChunked) - * [13. Async_WebSocketsServer](examples/Async_WebSocketsServer) - * [14. MQTTClient_Auth](examples/MQTTClient_Auth) - * [15. MQTTClient_Basic](examples/MQTTClient_Basic) - * [16. MQTT_ThingStream](examples/MQTT_ThingStream) -* [Example Async_AdvancedWebServer](#Example-Async_AdvancedWebServer) -* [Debug Terminal Output Samples](#debug-terminal-output-samples) - * [1. AsyncMultiWebServer_ESP32_W5500 on ESP32_DEV with ESP32_W5500](#1-AsyncMultiWebServer_ESP32_W5500-on-ESP32_DEV-with-ESP32_W5500) - * [2. Async_AdvancedWebServer_MemoryIssues_Send_CString on ESP32_DEV with ESP32_W5500](#2-Async_AdvancedWebServer_MemoryIssues_Send_CString-on-ESP32_DEV-with-ESP32_W5500) - * [3. Async_AdvancedWebServer_SendChunked on ESP32_DEV with ESP32_W5500](#3-Async_AdvancedWebServer_SendChunked-on-ESP32_DEV-with-ESP32_W5500) - * [4. AsyncWebServer_SendChunked on ESP32_DEV with ESP32_W5500](#4-AsyncWebServer_SendChunked-on-ESP32_DEV-with-ESP32_W5500) - * [5. Async_WebSocketsServer on ESP32_DEV with ESP32_W5500](#5-Async_WebSocketsServer-on-ESP32_DEV-with-ESP32_W5500) - * [6. Async_HTTPBasicAuth on ESP32_DEV with ESP32_W5500](#6-Async_HTTPBasicAuth-on-ESP32_DEV-with-ESP32_W5500) -* [Debug](#debug) -* [Troubleshooting](#troubleshooting) -* [Issues](#issues) -* [TO DO](#to-do) -* [DONE](#done) -* [Contributions and Thanks](#contributions-and-thanks) -* [Contributing](#contributing) -* [License](#license) -* [Copyright](#copyright) - ---- ---- - -### Important Note from v1.6.2 - -The new `v1.6.2+` has added a new and powerful feature to permit using `CString` to save heap to send `very large data`. - -Check the `marvelleous` PRs of **@salasidis** in [Portenta_H7_AsyncWebServer library](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer) -- [request->send(200, textPlainStr, jsonChartDataCharStr); - Without using String Class - to save heap #8](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer/pull/8) -- [All memmove() removed - string no longer destroyed #11](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer/pull/11) - -and these new examples - -1. [Async_AdvancedWebServer_MemoryIssues_Send_CString](https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500/tree/main/examples/Async_AdvancedWebServer_MemoryIssues_Send_CString) -2. [Async_AdvancedWebServer_MemoryIssues_SendArduinoString](https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500/tree/main/examples/Async_AdvancedWebServer_MemoryIssues_SendArduinoString) - -If using Arduino String, to send a buffer around 30 KBytes, the used `Max Heap` is around **144,124 bytes** - -If using CString in regular memory, with the same 30 KBytes, the used `Max Heap` is around **111,828 bytes, saving around a buffer size (30 KBytes)** - -This is very critical in use-cases where sending `very large data` is necessary, without `heap-allocation-error`. - - -1. The traditional function used to send `Arduino String` is - - -```cpp -void send(int code, const String& contentType = String(), const String& content = String()); -``` - -such as - -```cpp -request->send(200, textPlainStr, ArduinoStr); -``` -The required additional HEAP is about **3 times of the String size** - - -2. To use `CString` with copying while sending. Use function - - -```cpp -void send(int code, const String& contentType, const char *content, bool nonDetructiveSend = true); // RSMOD -``` - -such as - -```cpp -request->send(200, textPlainStr, cStr); -``` - -The required additional HEAP is also about **2 times of the CString size** because of `unnecessary copies` of the CString in HEAP. Avoid this `unefficient` way. - - -3. To use `CString` without copying while sending. Use function - - -```cpp -void send(int code, const String& contentType, const char *content, bool nonDetructiveSend = true); // RSMOD -``` - -such as - -```cpp -request->send(200, textPlainStr, cStr, false); -``` - -The required additional HEAP is about **1 times of the CString size**. This way is the best and **most efficient way** to use by avoiding of `unnecessary copies` of the CString in HEAP - - ---- ---- - -### Why do we need this [AsyncWebServer_ESP32_W5500 library](https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500) - - -#### Features - -This library is based on, modified from: - -1. [Hristo Gochkov's ESPAsyncWebServer](https://github.com/me-no-dev/ESPAsyncWebServer) - -to apply the better and faster **asynchronous** feature of the **powerful** [ESPAsyncWebServer Library](https://github.com/me-no-dev/ESPAsyncWebServer) into **(ESP32 + W5500)**. - - -#### Why Async is better - -- Using asynchronous network means that you can handle **more than one connection at the same time** -- **You are called once the request is ready and parsed** -- When you send the response, you are **immediately ready** to handle other connections while the server is taking care of sending the response in the background -- **Speed is OMG** -- **Easy to use API, HTTP Basic and Digest MD5 Authentication (default), ChunkedResponse** -- Easily extensible to handle **any type of content** -- Supports Continue 100 -- **Async WebSocket plugin offering different locations without extra servers or ports** -- Async EventSource (Server-Sent Events) plugin to send events to the browser -- URL Rewrite plugin for conditional and permanent url rewrites -- ServeStatic plugin that supports cache, Last-Modified, default index and more -- Simple template processing engine to handle templates - - ---- - -#### Currently supported Boards - -1. **(ESP32 + W5500 Ethernet) boards** - ---- ---- - - -## Prerequisites - - 1. [`Arduino IDE 1.8.19+` for Arduino](https://github.com/arduino/Arduino). [![GitHub release](https://img.shields.io/github/release/arduino/Arduino.svg)](https://github.com/arduino/Arduino/releases/latest) - 2. [`ESP32 Core 2.0.6+`](https://github.com/espressif/arduino-esp32) for ESP32-based boards. ESP32 Latest Core [![Latest release](https://img.shields.io/github/release/espressif/arduino-esp32.svg)](https://github.com/espressif/arduino-esp32/releases/latest/) - 3. [`AsyncTCP library v1.1.1+`](https://github.com/me-no-dev/AsyncTCP). - ---- - -## Installation - -### Use Arduino Library Manager - -The best and easiest way is to use `Arduino Library Manager`. Search for `AsyncWebServer_ESP32_W5500`, then select / install the latest version. You can also use this link [![arduino-library-badge](https://www.ardu-badge.com/badge/AsyncWebServer_ESP32_W5500.svg?)](https://www.ardu-badge.com/AsyncWebServer_ESP32_W5500) for more detailed instructions. - -### Manual Install - -1. Navigate to [AsyncWebServer_ESP32_W5500](https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500) page. -2. Download the latest release `AsyncWebServer_ESP32_W5500-main.zip`. -3. Extract the zip file to `AsyncWebServer_ESP32_W5500-main` directory -4. Copy the whole `AsyncWebServer_ESP32_W5500-main` folder to Arduino libraries' directory such as `~/Arduino/libraries/`. - -### VS Code & PlatformIO: - -1. Install [VS Code](https://code.visualstudio.com/) -2. Install [PlatformIO](https://platformio.org/platformio-ide) -3. Install [**AsyncWebServer_ESP32_W5500** library](https://registry.platformio.org/libraries/khoih-prog/AsyncWebServer_ESP32_W5500) by using [Library Manager](https://registry.platformio.org/libraries/khoih-prog/AsyncWebServer_ESP32_W5500/installation). Search for **AsyncWebServer_ESP32_W5500** in [Platform.io Author's Libraries](https://platformio.org/lib/search?query=author:%22Khoi%20Hoang%22) -4. Use included [platformio.ini](platformio/platformio.ini) file from examples to ensure that all dependent libraries will installed automatically. Please visit documentation for the other options and examples at [Project Configuration File](https://docs.platformio.org/page/projectconf.html) - - ---- ---- - -## Important things to remember - -- This is **fully asynchronous server** and as such does not run on the `loop()` thread. -- You can not use `yield()` or `delay()` or any function that uses them inside the callbacks -- The server is smart enough to know when to close the connection and free resources -- You can not send more than one response to a single request - ---- - -## Principles of operation - -### The Async Web server - -- Listens for connections -- Wraps the new clients into `Request` -- Keeps track of clients and cleans memory -- Manages `Rewrites` and apply them on the request url -- Manages `Handlers` and attaches them to Requests - -### Request Life Cycle - -- TCP connection is received by the server -- The connection is wrapped inside `Request` object -- When the request head is received (type, url, get params, http version and host), - the server goes through all `Rewrites` (in the order they were added) to rewrite the url and inject query parameters, - next, it goes through all attached `Handlers` (in the order they were added) trying to find one - that `canHandle` the given request. If none are found, the default(catch-all) handler is attached. -- The rest of the request is received, calling the `handleUpload` or `handleBody` methods of the `Handler` if they are needed (POST+File/Body) -- When the whole request is parsed, the result is given to the `handleRequest` method of the `Handler` and is ready to be responded to -- In the `handleRequest` method, to the `Request` is attached a `Response` object (see below) that will serve the response data back to the client -- When the `Response` is sent, the client is closed and freed from the memory - -### Rewrites and how do they work - -- The `Rewrites` are used to rewrite the request url and/or inject get parameters for a specific request url path. -- All `Rewrites` are evaluated on the request in the order they have been added to the server. -- The `Rewrite` will change the request url only if the request url (excluding get parameters) is fully match - the rewrite url, and when the optional `Filter` callback return true. -- Setting a `Filter` to the `Rewrite` enables to control when to apply the rewrite, decision can be based on - request url, http version, request host/port/target host, get parameters or the request client's localIP or remoteIP. -- The `Rewrite` can specify a target url with optional get parameters, e.g. `/to-url?with=params` - -### Handlers and how do they work - -- The `Handlers` are used for executing specific actions to particular requests -- One `Handler` instance can be attached to any request and lives together with the server -- Setting a `Filter` to the `Handler` enables to control when to apply the handler, decision can be based on - request url, http version, request host/port/target host, get parameters or the request client's localIP or remoteIP. -- The `canHandle` method is used for handler specific control on whether the requests can be handled - and for declaring any interesting headers that the `Request` should parse. Decision can be based on request - method, request url, http version, request host/port/target host and get parameters -- Once a `Handler` is attached to given `Request` (`canHandle` returned true) - that `Handler` takes care to receive any file/data upload and attach a `Response` - once the `Request` has been fully parsed -- `Handlers` are evaluated in the order they are attached to the server. The `canHandle` is called only - if the `Filter` that was set to the `Handler` return true. -- The first `Handler` that can handle the request is selected, not further `Filter` and `canHandle` are called. - -### Responses and how do they work - -- The `Response` objects are used to send the response data back to the client -- The `Response` object lives with the `Request` and is freed on end or disconnect -- Different techniques are used depending on the response type to send the data in packets - returning back almost immediately and sending the next packet when this one is received. - Any time in between is spent to run the user loop and handle other network packets -- Responding asynchronously is probably the most difficult thing for most to understand -- Many different options exist for the user to make responding a background task - -### Template processing - -- `AsyncWebServer_ESP32_W5500` contains simple template processing engine. -- Template processing can be added to most response types. -- Currently it supports only replacing template placeholders with actual values. No conditional processing, cycles, etc. -- Placeholders are delimited with `%` symbols. Like this: `%TEMPLATE_PLACEHOLDER%`. -- It works by extracting placeholder name from response text and passing it to user provided function which should return actual value to be used instead of placeholder. -- Since it's user provided function, it is possible for library users to implement conditional processing and cycles themselves. -- Since it's impossible to know the actual response size after template processing step in advance (and, therefore, to include it in response headers), the response becomes [chunked](#chunked-response). - ---- - -## Request Variables - -### Common Variables - -```cpp -request->version(); // uint8_t: 0 = HTTP/1.0, 1 = HTTP/1.1 -request->method(); // enum: HTTP_GET, HTTP_POST, HTTP_DELETE, HTTP_PUT, HTTP_PATCH, HTTP_HEAD, HTTP_OPTIONS -request->url(); // String: URL of the request (not including host, port or GET parameters) -request->host(); // String: The requested host (can be used for virtual hosting) -request->contentType(); // String: ContentType of the request (not available in Handler::canHandle) -request->contentLength(); // size_t: ContentLength of the request (not available in Handler::canHandle) -request->multipart(); // bool: True if the request has content type "multipart" -``` - -### Headers - -```cpp -//List all collected headers -int headers = request->headers(); -int i; - -for (i=0;igetHeader(i); - Serial.printf("HEADER[%s]: %s\n", h->name().c_str(), h->value().c_str()); -} - -//get specific header by name -if (request->hasHeader("MyHeader")) -{ - AsyncWebHeader* h = request->getHeader("MyHeader"); - Serial.printf("MyHeader: %s\n", h->value().c_str()); -} - -//List all collected headers (Compatibility) -int headers = request->headers(); -int i; - -for (i=0;iheaderName(i).c_str(), request->header(i).c_str()); -} - -//get specific header by name (Compatibility) -if (request->hasHeader("MyHeader")) -{ - Serial.printf("MyHeader: %s\n", request->header("MyHeader").c_str()); -} -``` - -### GET, POST and FILE parameters - -```cpp -//List all parameters -int params = request->params(); - -for (int i=0;igetParam(i); - - if (p->isFile()) - { - //p->isPost() is also true - Serial.printf("FILE[%s]: %s, size: %u\n", p->name().c_str(), p->value().c_str(), p->size()); - } - else if (p->isPost()) - { - Serial.printf("POST[%s]: %s\n", p->name().c_str(), p->value().c_str()); - } - else - { - Serial.printf("GET[%s]: %s\n", p->name().c_str(), p->value().c_str()); - } -} - -//Check if GET parameter exists -if (request->hasParam("download")) - AsyncWebParameter* p = request->getParam("download"); - -//Check if POST (but not File) parameter exists -if (request->hasParam("download", true)) - AsyncWebParameter* p = request->getParam("download", true); - -//Check if FILE was uploaded -if (request->hasParam("download", true, true)) - AsyncWebParameter* p = request->getParam("download", true, true); - -//List all parameters (Compatibility) -int args = request->args(); - -for (int i=0;iargName(i).c_str(), request->arg(i).c_str()); -} - -//Check if parameter exists (Compatibility) -if (request->hasArg("download")) - String arg = request->arg("download"); -``` - -### JSON body handling with ArduinoJson - -Endpoints which consume JSON can use a special handler to get ready to use JSON data in the request callback: - -```cpp -#include "AsyncJson.h" -#include "ArduinoJson.h" - -AsyncCallbackJsonWebHandler* handler = new AsyncCallbackJsonWebHandler("/rest/endpoint", [](AsyncWebServerRequest *request, JsonVariant &json) -{ - JsonObject& jsonObj = json.as(); - // ... -}); - -server.addHandler(handler); -``` ---- - -## Responses - -### Redirect to another URL - -```cpp -//to local url -request->redirect("/login"); - -//to external url -request->redirect("http://esp8266.com"); -``` - -### Basic response with HTTP Code - -```cpp -request->send(404); //Sends 404 File Not Found -``` - -### Basic response with HTTP Code and extra headers - -```cpp -AsyncWebServerResponse *response = request->beginResponse(404); //Sends 404 File Not Found -response->addHeader("Server","AsyncWebServer_ESP32_W5500"); -request->send(response); -``` - -### Basic response with string content - -```cpp -request->send(200, "text/plain", "Hello World!"); -``` - -### Basic response with string content and extra headers - -```cpp -AsyncWebServerResponse *response = request->beginResponse(200, "text/plain", "Hello World!"); -response->addHeader("Server","AsyncWebServer"); -request->send(response); -``` - -### Respond with content coming from a Stream - -```cpp -//read 12 bytes from Serial and send them as Content Type text/plain -request->send(Serial, "text/plain", 12); -``` - -### Respond with content coming from a Stream and extra headers - -```cpp -//read 12 bytes from Serial and send them as Content Type text/plain -AsyncWebServerResponse *response = request->beginResponse(Serial, "text/plain", 12); -response->addHeader("Server","AsyncWebServer_ESP32_W5500"); -request->send(response); -``` - -### Respond with content coming from a Stream containing templates - -```cpp -String processor(const String& var) -{ - if (var == "HELLO_FROM_TEMPLATE") - return F("Hello world!"); - - return String(); -} - -// ... - -//read 12 bytes from Serial and send them as Content Type text/plain -request->send(Serial, "text/plain", 12, processor); -``` - -### Respond with content coming from a Stream containing templates and extra headers - -```cpp -String processor(const String& var) -{ - if (var == "HELLO_FROM_TEMPLATE") - return F("Hello world!"); - return String(); -} - -// ... - -//read 12 bytes from Serial and send them as Content Type text/plain -AsyncWebServerResponse *response = request->beginResponse(Serial, "text/plain", 12, processor); -response->addHeader("Server","AsyncWebServer_ESP32_W5500"); -request->send(response); -``` - -### Respond with content using a callback - -```cpp -//send 128 bytes as plain text -request->send("text/plain", 128, [](uint8_t *buffer, size_t maxLen, size_t index) -> size_t -{ - //Write up to "maxLen" bytes into "buffer" and return the amount written. - //index equals the amount of bytes that have been already sent - //You will not be asked for more bytes once the content length has been reached. - //Keep in mind that you can not delay or yield waiting for more data! - //Send what you currently have and you will be asked for more again - return mySource.read(buffer, maxLen); -}); -``` - -### Respond with content using a callback and extra headers - -```cpp -//send 128 bytes as plain text -AsyncWebServerResponse *response = request->beginResponse("text/plain", 128, [](uint8_t *buffer, size_t maxLen, size_t index) -> size_t -{ - //Write up to "maxLen" bytes into "buffer" and return the amount written. - //index equals the amount of bytes that have been already sent - //You will not be asked for more bytes once the content length has been reached. - //Keep in mind that you can not delay or yield waiting for more data! - //Send what you currently have and you will be asked for more again - return mySource.read(buffer, maxLen); -}); - -response->addHeader("Server","AsyncWebServer_ESP32_W5500"); -request->send(response); -``` - -### Respond with content using a callback containing templates - -```cpp -String processor(const String& var) -{ - if (var == "HELLO_FROM_TEMPLATE") - return F("Hello world!"); - - return String(); -} - -// ... - -//send 128 bytes as plain text -request->send("text/plain", 128, [](uint8_t *buffer, size_t maxLen, size_t index) -> size_t -{ - //Write up to "maxLen" bytes into "buffer" and return the amount written. - //index equals the amount of bytes that have been already sent - //You will not be asked for more bytes once the content length has been reached. - //Keep in mind that you can not delay or yield waiting for more data! - //Send what you currently have and you will be asked for more again - return mySource.read(buffer, maxLen); -}, processor); -``` - -### Respond with content using a callback containing templates and extra headers - -```cpp -String processor(const String& var) -{ - if (var == "HELLO_FROM_TEMPLATE") - return F("Hello world!"); - return String(); -} - -// ... - -//send 128 bytes as plain text -AsyncWebServerResponse *response = request->beginResponse("text/plain", 128, [](uint8_t *buffer, size_t maxLen, size_t index) -> size_t -{ - //Write up to "maxLen" bytes into "buffer" and return the amount written. - //index equals the amount of bytes that have been already sent - //You will not be asked for more bytes once the content length has been reached. - //Keep in mind that you can not delay or yield waiting for more data! - //Send what you currently have and you will be asked for more again - return mySource.read(buffer, maxLen); -}, processor); - -response->addHeader("Server","AsyncWebServer_ESP32_W5500"); -request->send(response); -``` - -### Chunked Response - -Used when content length is unknown. Works best if the client supports HTTP/1.1 - -```cpp -AsyncWebServerResponse *response = request->beginChunkedResponse("text/plain", [](uint8_t *buffer, size_t maxLen, size_t index) -> size_t -{ - //Write up to "maxLen" bytes into "buffer" and return the amount written. - //index equals the amount of bytes that have been already sent - //You will be asked for more data until 0 is returned - //Keep in mind that you can not delay or yield waiting for more data! - return mySource.read(buffer, maxLen); -}); - -response->addHeader("Server","AsyncWebServer_ESP32_W5500"); -request->send(response); -``` - -### Chunked Response containing templates - -Used when content length is unknown. Works best if the client supports HTTP/1.1 - -```cpp -String processor(const String& var) -{ - if (var == "HELLO_FROM_TEMPLATE") - return F("Hello world!"); - - return String(); -} - -// ... - -AsyncWebServerResponse *response = request->beginChunkedResponse("text/plain", [](uint8_t *buffer, size_t maxLen, size_t index) -> size_t -{ - //Write up to "maxLen" bytes into "buffer" and return the amount written. - //index equals the amount of bytes that have been already sent - //You will be asked for more data until 0 is returned - //Keep in mind that you can not delay or yield waiting for more data! - return mySource.read(buffer, maxLen); -}, processor); - -response->addHeader("Server","AsyncWebServer_ESP32_W5500"); -request->send(response); -``` - -### Print to response - -```cpp -AsyncResponseStream *response = request->beginResponseStream("text/html"); -response->addHeader("Server","AsyncWebServer_ESP32_W5500"); -response->printf("Webpage at %s", request->url().c_str()); - -response->print("

Hello "); -response->print(request->client()->remoteIP()); -response->print("

"); - -response->print("

General

"); -response->print("
    "); -response->printf("
  • Version: HTTP/1.%u
  • ", request->version()); -response->printf("
  • Method: %s
  • ", request->methodToString()); -response->printf("
  • URL: %s
  • ", request->url().c_str()); -response->printf("
  • Host: %s
  • ", request->host().c_str()); -response->printf("
  • ContentType: %s
  • ", request->contentType().c_str()); -response->printf("
  • ContentLength: %u
  • ", request->contentLength()); -response->printf("
  • Multipart: %s
  • ", request->multipart()?"true":"false"); -response->print("
"); - -response->print("

Headers

"); -response->print("
    "); -int headers = request->headers(); - -for (int i=0;igetHeader(i); - response->printf("
  • %s: %s
  • ", h->name().c_str(), h->value().c_str()); -} - -response->print("
"); - -response->print("

Parameters

"); -response->print("
    "); - -int params = request->params(); - -for (int i=0;igetParam(i); - - if (p->isFile()) - { - response->printf("
  • FILE[%s]: %s, size: %u
  • ", p->name().c_str(), p->value().c_str(), p->size()); - } - else if (p->isPost()) - { - response->printf("
  • POST[%s]: %s
  • ", p->name().c_str(), p->value().c_str()); - } - else - { - response->printf("
  • GET[%s]: %s
  • ", p->name().c_str(), p->value().c_str()); - } -} - -response->print("
"); - -response->print(""); -//send the response last -request->send(response); -``` - -### ArduinoJson Basic Response - -This way of sending Json is great for when the result is **below 4KB** - -```cpp -#include "AsyncJson.h" -#include "ArduinoJson.h" - - -AsyncResponseStream *response = request->beginResponseStream("application/json"); -DynamicJsonBuffer jsonBuffer; -JsonObject &root = jsonBuffer.createObject(); -root["heap"] = ESP.getFreeHeap(); -root["ssid"] = WiFi.SSID(); -root.printTo(*response); - -request->send(response); -``` - -### ArduinoJson Advanced Response - -This response can handle really **large Json objects (tested to 40KB)** - -There isn't any noticeable speed decrease for small results with the method above - -Since ArduinoJson does not allow reading parts of the string, the whole Json has to be passed every time a -chunks needs to be sent, which shows speed decrease proportional to the resulting json packets - -```cpp -#include "AsyncJson.h" -#include "ArduinoJson.h" - -AsyncJsonResponse * response = new AsyncJsonResponse(); -response->addHeader("Server","AsyncWebServer"); -JsonObject& root = response->getRoot(); -root["IP"] = Ethernet.localIP(); -response->setLength(); - -request->send(response); -``` ---- - -## Param Rewrite With Matching - -It is possible to rewrite the request url with parameter matchg. Here is an example with one parameter: -Rewrite for example "/radio/{frequence}" -> "/radio?f={frequence}" - -```cpp -class OneParamRewrite : public AsyncWebRewrite -{ - protected: - String _urlPrefix; - int _paramIndex; - String _paramsBackup; - - public: - OneParamRewrite(const char* from, const char* to) - : AsyncWebRewrite(from, to) - { - - _paramIndex = _from.indexOf('{'); - - if ( _paramIndex >=0 && _from.endsWith("}")) - { - _urlPrefix = _from.substring(0, _paramIndex); - int index = _params.indexOf('{'); - - if (index >= 0) - { - _params = _params.substring(0, index); - } - } - else - { - _urlPrefix = _from; - } - - _paramsBackup = _params; - } - - bool match(AsyncWebServerRequest *request) override - { - if (request->url().startsWith(_urlPrefix)) - { - if (_paramIndex >= 0) - { - _params = _paramsBackup + request->url().substring(_paramIndex); - } - else - { - _params = _paramsBackup; - } - - return true; - - } - else - { - return false; - } - } -}; -``` - -Usage: - -```cpp - server.addRewrite( new OneParamRewrite("/radio/{frequence}", "/radio?f={frequence}") ); -``` ---- - -## Using filters - -Filters can be set to `Rewrite` or `Handler` in order to control when to apply the rewrite and consider the handler. -A filter is a callback function that evaluates the request and return a boolean `true` to include the item -or `false` to exclude it. - ---- - -## Bad Responses - -Some responses are implemented, but you should not use them, because they do not conform to HTTP. -The following example will lead to unclean close of the connection and more time wasted -than providing the length of the content - -### Respond with content using a callback without content length to HTTP/1.0 clients - -```cpp -//This is used as fallback for chunked responses to HTTP/1.0 Clients -request->send("text/plain", 0, [](uint8_t *buffer, size_t maxLen, size_t index) -> size_t -{ - //Write up to "maxLen" bytes into "buffer" and return the amount written. - //You will be asked for more data until 0 is returned - //Keep in mind that you can not delay or yield waiting for more data! - return mySource.read(buffer, maxLen); -}); -``` - ---- - -## Async WebSocket Plugin - -The server includes a web socket plugin which lets you define different WebSocket locations to connect to -without starting another listening service or using different port - -### Async WebSocket Event - -```cpp -void onEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len) -{ - if (type == WS_EVT_CONNECT) - { - //client connected - Serial.printf("ws[%s][%u] connect\n", server->url(), client->id()); - client->printf("Hello Client %u :)", client->id()); - client->ping(); - } - else if (type == WS_EVT_DISCONNECT) - { - //client disconnected - Serial.printf("ws[%s][%u] disconnect: %u\n", server->url(), client->id()); - } - else if (type == WS_EVT_ERROR) - { - //error was received from the other end - Serial.printf("ws[%s][%u] error(%u): %s\n", server->url(), client->id(), *((uint16_t*)arg), (char*)data); - } - else if (type == WS_EVT_PONG) - { - //pong message was received (in response to a ping request maybe) - Serial.printf("ws[%s][%u] pong[%u]: %s\n", server->url(), client->id(), len, (len)?(char*)data:""); - } - else if (type == WS_EVT_DATA) - { - //data packet - AwsFrameInfo * info = (AwsFrameInfo*)arg; - - if (info->final && info->index == 0 && info->len == len) - { - //the whole message is in a single frame and we got all of it's data - Serial.printf("ws[%s][%u] %s-message[%llu]: ", server->url(), client->id(), (info->opcode == WS_TEXT)?"text":"binary", info->len); - - if (info->opcode == WS_TEXT) - { - data[len] = 0; - Serial.printf("%s\n", (char*)data); - } - else - { - for (size_t i=0; i < info->len; i++) - { - Serial.printf("%02x ", data[i]); - } - - Serial.printf("\n"); - } - - if (info->opcode == WS_TEXT) - client->text("I got your text message"); - else - client->binary("I got your binary message"); - } - else - { - //message is comprised of multiple frames or the frame is split into multiple packets - if (info->index == 0) - { - if (info->num == 0) - Serial.printf("ws[%s][%u] %s-message start\n", server->url(), client->id(), (info->message_opcode == WS_TEXT)?"text":"binary"); - - Serial.printf("ws[%s][%u] frame[%u] start[%llu]\n", server->url(), client->id(), info->num, info->len); - } - - Serial.printf("ws[%s][%u] frame[%u] %s[%llu - %llu]: ", server->url(), client->id(), info->num, (info->message_opcode == WS_TEXT)?"text":"binary", info->index, info->index + len); - - if (info->message_opcode == WS_TEXT) - { - data[len] = 0; - Serial.printf("%s\n", (char*)data); - } - else - { - for (size_t i=0; i < len; i++){ - Serial.printf("%02x ", data[i]); - } - Serial.printf("\n"); - } - - if ((info->index + len) == info->len) - { - Serial.printf("ws[%s][%u] frame[%u] end[%llu]\n", server->url(), client->id(), info->num, info->len); - - if (info->final) - { - Serial.printf("ws[%s][%u] %s-message end\n", server->url(), client->id(), (info->message_opcode == WS_TEXT)?"text":"binary"); - - if (info->message_opcode == WS_TEXT) - client->text("I got your text message"); - else - client->binary("I got your binary message"); - } - } - } - } -} -``` - -### Methods for sending data to a socket client - -```cpp -//Server methods -AsyncWebSocket ws("/ws"); -//printf to a client -ws.printf((uint32_t)client_id, arguments...); -//printf to all clients -ws.printfAll(arguments...); -//send text to a client -ws.text((uint32_t)client_id, (char*)text); -ws.text((uint32_t)client_id, (uint8_t*)text, (size_t)len); -//send text to all clients -ws.textAll((char*)text); -ws.textAll((uint8_t*)text, (size_t)len); -//send binary to a client -ws.binary((uint32_t)client_id, (char*)binary); -ws.binary((uint32_t)client_id, (uint8_t*)binary, (size_t)len); -ws.binary((uint32_t)client_id, flash_binary, 4); -//send binary to all clients -ws.binaryAll((char*)binary); -ws.binaryAll((uint8_t*)binary, (size_t)len); -//HTTP Authenticate before switch to Websocket protocol -ws.setAuthentication("user", "pass"); - -//client methods -AsyncWebSocketClient * client; -//printf -client->printf(arguments...); -//send text -client->text((char*)text); -client->text((uint8_t*)text, (size_t)len); -//send binary -client->binary((char*)binary); -client->binary((uint8_t*)binary, (size_t)len); -``` - -### Direct access to web socket message buffer - -When sending a web socket message using the above methods a buffer is created. Under certain circumstances you might want to manipulate or populate this buffer directly from your application, for example to prevent unnecessary duplications of the data. This example below shows how to create a buffer and print data to it from an ArduinoJson object then send it. - -```cpp -void sendDataWs(AsyncWebSocketClient * client) -{ - DynamicJsonBuffer jsonBuffer; - JsonObject& root = jsonBuffer.createObject(); - root["a"] = "abc"; - root["b"] = "abcd"; - root["c"] = "abcde"; - root["d"] = "abcdef"; - root["e"] = "abcdefg"; - size_t len = root.measureLength(); - AsyncWebSocketMessageBuffer * buffer = ws.makeBuffer(len); // creates a buffer (len + 1) for you. - - if (buffer) - { - root.printTo((char *)buffer->get(), len + 1); - - if (client) - { - client->text(buffer); - } - else - { - ws.textAll(buffer); - } - } -} -``` - -### Limiting the number of web socket clients - -Browsers sometimes do not correctly close the websocket connection, even when the `close()` function is called in javascript. This will eventually exhaust the web server's resources and will cause the server to crash. Periodically calling the `cleanClients()` function from the main `loop()` function limits the number of clients by closing the oldest client when the maximum number of clients has been exceeded. This can called be every cycle, however, if you wish to use less power, then calling as infrequently as once per second is sufficient. - -```cpp -void loop() -{ - ws.cleanupClients(); -} -``` - ---- - -## Async Event Source Plugin - -The server includes `EventSource` (Server-Sent Events) plugin which can be used to send short text events to the browser. -Difference between `EventSource` and `WebSockets` is that `EventSource` is single direction, text-only protocol. - -### Setup Event Source on the server - -```cpp -AsyncWebServer server(80); -AsyncEventSource events("/events"); - -void setup() -{ - // setup ...... - events.onConnect([](AsyncEventSourceClient *client) - { - if (client->lastId()) - { - Serial.printf("Client reconnected! Last message ID that it got is: %u\n", client->lastId()); - } - - //send event with message "hello!", id current millis - // and set reconnect delay to 1 second - client->send("hello!",NULL,millis(),1000); - }); - - //HTTP Basic authentication - events.setAuthentication("user", "pass"); - server.addHandler(&events); - // setup ...... -} - -void loop() -{ - if (eventTriggered) - { - // your logic here - //send event "myevent" - events.send("my event content","myevent",millis()); - } -} -``` - -### Setup Event Source in the browser - -```javascript -if (!!window.EventSource) -{ - var source = new EventSource('/events'); - - source.addEventListener('open', function(e) - { - console.log("Events Connected"); - }, false); - - source.addEventListener('error', function(e) - { - if (e.target.readyState != EventSource.OPEN) - { - console.log("Events Disconnected"); - } - }, false); - - source.addEventListener('message', function(e) - { - console.log("message", e.data); - }, false); - - source.addEventListener('myevent', function(e) - { - console.log("myevent", e.data); - }, false); -} -``` ---- - -## Remove handlers and rewrites - -Server goes through handlers in same order as they were added. You can't simple add handler with same path to override them. -To remove handler: - -```cpp -// save callback for particular URL path -auto handler = server.on("/some/path", [](AsyncWebServerRequest *request) -{ - //do something useful -}); - -// when you don't need handler anymore remove it -server.removeHandler(&handler); - -// same with rewrites -server.removeRewrite(&someRewrite); - -server.onNotFound([](AsyncWebServerRequest *request) -{ - request->send(404); -}); - -// remove server.onNotFound handler -server.onNotFound(NULL); - -// remove all rewrites, handlers and onNotFound/onFileUpload/onRequestBody callbacks -server.reset(); -``` ---- - -## Setting up the server - -```cpp -#if !( defined(ESP32) ) - #error This code is designed for (ESP32 + W5500) to run on ESP32 platform! Please check your Tools->Board setting. -#endif - -#include - -#define _ASYNC_WEBSERVER_LOGLEVEL_ 2 - -// Enter a MAC address and IP address for your controller below. -#define NUMBER_OF_MAC 20 - -byte mac[][NUMBER_OF_MAC] = -{ - { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x01 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x02 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x03 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x04 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x05 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x06 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x07 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x08 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x09 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0A }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0B }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0C }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0D }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x0E }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x0F }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x10 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x11 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x12 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0x13 }, - { 0xDE, 0xAD, 0xBE, 0xEF, 0xBE, 0x14 }, -}; - -// Select the IP address according to your local network -IPAddress myIP(192, 168, 2, 232); -IPAddress myGW(192, 168, 2, 1); -IPAddress mySN(255, 255, 255, 0); - -// Google DNS Server IP -IPAddress myDNS(8, 8, 8, 8); - -////////////////////////////////////////////////////////// - -// Optional values to override default settings -// Don't change unless you know what you're doing -//#define ETH_SPI_HOST SPI3_HOST -//#define SPI_CLOCK_MHZ 25 - -// Must connect INT to GPIOxx or not working -//#define INT_GPIO 4 - -//#define MISO_GPIO 19 -//#define MOSI_GPIO 23 -//#define SCK_GPIO 18 -//#define CS_GPIO 5 - -////////////////////////////////////////////////////////// - -#include - -#include - -AsyncWebServer server(80); - -void handleRoot(AsyncWebServerRequest *request) -{ - request->send(200, "text/plain", String("Hello from Async_HelloServer on ") + ARDUINO_BOARD ); -} - -void handleNotFound(AsyncWebServerRequest *request) -{ - String message = "File Not Found\n\n"; - - message += "URI: "; - //message += server.uri(); - message += request->url(); - message += "\nMethod: "; - message += (request->method() == HTTP_GET) ? "GET" : "POST"; - message += "\nArguments: "; - message += request->args(); - message += "\n"; - - for (uint8_t i = 0; i < request->args(); i++) - { - message += " " + request->argName(i) + ": " + request->arg(i) + "\n"; - } - - request->send(404, "text/plain", message); -} - -void setup() -{ - Serial.begin(115200); - - while (!Serial && millis() < 5000); - - delay(200); - - Serial.print(F("\nStart Async_HelloServer on ")); - Serial.print(ARDUINO_BOARD); - Serial.print(F(" with ")); - Serial.println(SHIELD_TYPE); - Serial.println(ASYNC_WEBSERVER_ESP32_W5500_VERSION); - - AWS_LOGWARN(F("Default SPI pinout:")); - AWS_LOGWARN1(F("SPI_HOST:"), ETH_SPI_HOST); - AWS_LOGWARN1(F("MOSI:"), MOSI_GPIO); - AWS_LOGWARN1(F("MISO:"), MISO_GPIO); - AWS_LOGWARN1(F("SCK:"), SCK_GPIO); - AWS_LOGWARN1(F("CS:"), CS_GPIO); - AWS_LOGWARN1(F("INT:"), INT_GPIO); - AWS_LOGWARN1(F("SPI Clock (MHz):"), SPI_CLOCK_MHZ); - AWS_LOGWARN(F("=========================")); - - /////////////////////////////////// - - // To be called before ETH.begin() - ESP32_W5500_onEvent(); - - // start the ethernet connection and the server: - // Use DHCP dynamic IP and random mac - uint16_t index = millis() % NUMBER_OF_MAC; - - //bool begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPI_CLOCK_MHZ, - // int SPI_HOST, uint8_t *W5500_Mac = W5500_Default_Mac); - //ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST ); - ETH.begin( MISO_GPIO, MOSI_GPIO, SCK_GPIO, CS_GPIO, INT_GPIO, SPI_CLOCK_MHZ, ETH_SPI_HOST, mac[index] ); - - // Static IP, leave without this line to get IP via DHCP - //bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = 0, IPAddress dns2 = 0); - //ETH.config(myIP, myGW, mySN, myDNS); - - ESP32_W5500_waitForConnect(); - - /////////////////////////////////// - - - server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) - { - handleRoot(request); - }); - - server.on("/inline", [](AsyncWebServerRequest * request) - { - request->send(200, "text/plain", "This works as well"); - }); - - server.onNotFound(handleNotFound); - - server.begin(); - - Serial.print(F("HTTP EthernetWebServer is @ IP : ")); - Serial.println(ETH.localIP()); -} - -void loop() -{ -} -``` ---- - -### Setup global and class functions as request handlers - -```cpp -#include - -#include - -... - -void handleRequest(AsyncWebServerRequest *request){} - -class WebClass -{ -public : - AsyncWebServer classWebServer = AsyncWebServer(81); - - WebClass(){}; - - void classRequest (AsyncWebServerRequest *request){} - - void begin() - { - // attach global request handler - classWebServer.on("/example", HTTP_ANY, handleRequest); - - // attach class request handler - classWebServer.on("/example", HTTP_ANY, std::bind(&WebClass::classRequest, this, std::placeholders::_1)); - } -}; - -AsyncWebServer globalWebServer(80); -WebClass webClassInstance; - -void setup() -{ - // attach global request handler - globalWebServer.on("/example", HTTP_ANY, handleRequest); - - // attach class request handler - globalWebServer.on("/example", HTTP_ANY, std::bind(&WebClass::classRequest, webClassInstance, std::placeholders::_1)); -} - -void loop() -{ -} -``` - -### Methods for controlling websocket connections - -```cpp -// Disable client connections if it was activated -if ( ws.enabled() ) - ws.enable(false); - -// enable client connections if it was disabled -if ( !ws.enabled() ) - ws.enable(true); -``` - - -### Adding Default Headers - -In some cases, such as when working with CORS, or with some sort of custom authentication system, -you might need to define a header that should get added to all responses (including static, websocket and EventSource). -The DefaultHeaders singleton allows you to do this. - -Example: - -```cpp -DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", "*"); -webServer.begin(); -``` - -*NOTE*: You will still need to respond to the OPTIONS method for CORS pre-flight in most cases. (unless you are only using GET) - -This is one option: - -```cpp -webServer.onNotFound([](AsyncWebServerRequest *request) -{ - if (request->method() == HTTP_OPTIONS) - { - request->send(200); - } - else - { - request->send(404); - } -}); -``` - ---- - -### Path variable - -With path variable you can create a custom regex rule for a specific parameter in a route. -For example we want a `sensorId` parameter in a route rule to match only a integer. - -```cpp -server.on("^\\/sensor\\/([0-9]+)$", HTTP_GET, [] (AsyncWebServerRequest *request) -{ - String sensorId = request->pathArg(0); -}); -``` - -*NOTE*: All regex patterns starts with `^` and ends with `$` - -To enable the `Path variable` support, you have to define the buildflag `-DASYNCWEBSERVER_REGEX`. - - -For Arduino IDE create/update `platform.local.txt`: - -`Windows`: C:\Users\(username)\AppData\Local\Arduino15\packages\\`{espxxxx}`\hardware\\`espxxxx`\\`{version}`\platform.local.txt - -`Linux`: ~/.arduino15/packages/`{espxxxx}`/hardware/`{espxxxx}`/`{version}`/platform.local.txt - -Add/Update the following line: - -``` -compiler.cpp.extra_flags=-DDASYNCWEBSERVER_REGEX -``` - -For platformio modify `platformio.ini`: - -```ini -[env:myboard] -build_flags = - -DASYNCWEBSERVER_REGEX -``` - -*NOTE*: By enabling `ASYNCWEBSERVER_REGEX`, `` will be included. This will add an 100k to your binary. - ---- ---- - - -### How to connect W5500 to ESP32 - -You can change the `INT` pin to another one. Default is `GPIO4` - -```cpp -// Must connect INT to GPIOxx or not working -#define INT_GPIO 4 -``` - ---- - -#### W5500 - -

- -

- -

- -

- ---- - - -|W5500|<--->|ESP32| -|:-:|:-:|:-:| -|MOSI|<--->|GPIO23| -|MISO|<--->|GPIO19| -|SCK|<--->|GPIO18| -|SS|<--->|GPIO5| -|INT|<--->|GPIO4| -|RST|<--->|RST| -|GND|<--->|GND| -|3.3V|<--->|3.3V| - - ---- ---- - -### Examples - - 1. [Async_AdvancedWebServer](examples/Async_AdvancedWebServer) - 2. [Async_AdvancedWebServer_MemoryIssues_SendArduinoString](examples/Async_AdvancedWebServer_MemoryIssues_SendArduinoString) - 3. [Async_AdvancedWebServer_MemoryIssues_Send_CString](examples/Async_AdvancedWebServer_MemoryIssues_Send_CString) - 4. [Async_AdvancedWebServer_SendChunked](examples/Async_AdvancedWebServer_SendChunked) - 5. [Async_HelloServer](examples/Async_HelloServer) - 6. [Async_HelloServer2](examples/Async_HelloServer2) - 7. [Async_HttpBasicAuth](examples/Async_HttpBasicAuth) - 8. [AsyncMultiWebServer_ESP32_W5500](examples/AsyncMultiWebServer_ESP32_W5500) - 9. [Async_PostServer](examples/Async_PostServer) -10. [Async_RegexPatterns_ESP32_W5500](examples/Async_RegexPatterns_ESP32_W5500) -11. [AsyncSimpleServer_ESP32_W5500](examples/AsyncSimpleServer_ESP32_W5500) -12. [AsyncWebServer_SendChunked](examples/AsyncWebServer_SendChunked) -13. [Async_WebSocketsServer](examples/Async_WebSocketsServer) -14. [MQTTClient_Auth](examples/MQTTClient_Auth) -15. [MQTTClient_Basic](examples/MQTTClient_Basic) -16. [MQTT_ThingStream](examples/MQTT_ThingStream) - - ---- ---- - -### Example [Async_AdvancedWebServer](examples/Async_AdvancedWebServer) - -https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500/blob/80ac7eebf5d0125626cea309333315c4f0565efd/examples/Async_AdvancedWebServer/Async_AdvancedWebServer.ino#L41-L256 - - -You can access the Async Advanced WebServer @ the server IP - -

- -

- ---- ---- - -### Debug Terminal Output Samples - -#### 1. AsyncMultiWebServer_ESP32_W5500 on ESP32_DEV with ESP32_W5500 - -Following are debug terminal output and screen shots when running example [AsyncMultiWebServer_ESP32_W5500](examples/AsyncMultiWebServer_ESP32_W5500) on `ESP32_DEV with LwIP W5500`, using ESP32 core `v2.0.0+`, to demonstrate the operation of 3 independent AsyncWebServers on 3 different ports and how to handle the complicated AsyncMultiWebServers. - - -```cpp -Start AsyncMultiWebServer_ESP32_W5500 on ESP32_DEV with ESP32_W5500 -AsyncWebServer_ESP32_W5500 v1.6.4 for core v2.0.0+ -[AWS] Default SPI pinout: -[AWS] SPI_HOST: 2 -[AWS] MOSI: 23 -[AWS] MISO: 19 -[AWS] SCK: 18 -[AWS] CS: 5 -[AWS] INT: 4 -[AWS] SPI Clock (MHz): 25 -[AWS] ========================= - -ETH Started -ETH Connected -ETH MAC: DE:AD:BE:EF:BE:08, IPv4: 192.168.2.88 -FULL_DUPLEX, 100Mbps - -Connected to network. IP = 192.168.2.88 -Initialize multiServer OK, serverIndex = 0, port = 8080 -HTTP server started at ports 8080 -Initialize multiServer OK, serverIndex = 1, port = 8081 -HTTP server started at ports 8081 -Initialize multiServer OK, serverIndex = 2, port = 8082 -HTTP server started at ports 8082 -``` - -You can access the Async Advanced WebServers @ the server IP and corresponding ports (8080, 8081 and 8082) - -

- -

- -

- -

- -

- -

- ---- - -#### 2. Async_AdvancedWebServer_MemoryIssues_Send_CString on ESP32_DEV with ESP32_W5500 - -Following is the debug terminal and screen shot when running example [Async_AdvancedWebServer_MemoryIssues_Send_CString](examples/Async_AdvancedWebServer_MemoryIssues_Send_CString), on `ESP32_DEV with LwIP W5500`, to demonstrate the new and powerful `HEAP-saving` feature - - -##### Using CString ===> smaller heap (111,828 bytes) - -```cpp -Start Async_AdvancedWebServer_MemoryIssues_Send_CString on ESP32_DEV with ESP32_W5500 -AsyncWebServer_ESP32_W5500 v1.6.4 for core v2.0.0+ -[AWS] Default SPI pinout: -[AWS] SPI_HOST: 2 -[AWS] MOSI: 23 -[AWS] MISO: 19 -[AWS] SCK: 18 -[AWS] CS: 5 -[AWS] INT: 4 -[AWS] SPI Clock (MHz): 25 -[AWS] ========================= - -ETH Started -ETH Connected -ETH MAC: DE:AD:BE:EF:BE:08, IPv4: 192.168.2.88 -FULL_DUPLEX, 100Mbps -HTTP EthernetWebServer is @ IP : 192.168.2.88 - -HEAP DATA - Pre Create Arduino String Max heap: 323016 Free heap: 222076 Used heap: 100940 -. -HEAP DATA - Pre Send Max heap: 323016 Free heap: 217656 Used heap: 105360 - -HEAP DATA - Post Send Max heap: 323016 Free heap: 209648 Used heap: 111828 -. -``` - -While using `Arduino String`, the HEAP usage is very large - - -#### Async_AdvancedWebServer_MemoryIssues_SendArduinoString ===> very large heap (144,124 bytes) - -```cpp -Start Async_AdvancedWebServer_MemoryIssues_SendArduinoString on ESP32_DEV with ESP32_W5500 -AsyncWebServer_ESP32_W5500 v1.6.4 for core v2.0.0+ -[AWS] Default SPI pinout: -[AWS] SPI_HOST: 2 -[AWS] MOSI: 23 -[AWS] MISO: 19 -[AWS] SCK: 18 -[AWS] CS: 5 -[AWS] INT: 4 -[AWS] SPI Clock (MHz): 25 -[AWS] ========================= - -ETH Started -ETH Connected -ETH MAC: DE:AD:BE:EF:BE:08, IPv4: 192.168.2.88 -FULL_DUPLEX, 100Mbps -HTTP EthernetWebServer is @ IP : 192.168.2.88 - -HEAP DATA - Pre Create Arduino String Max heap: 323288 Free heap: 262348 Used heap: 60940 -. -HEAP DATA - Pre Send Max heap: 323288 Free heap: 218444 Used heap: 104844 - -HEAP DATA - Post Send Max heap: 323288 Free heap: 180644 Used heap: 144124 -. -``` - - -You can access the Async Advanced WebServers at the displayed server IP, e.g. `192.168.2.88` - -

- -

- ---- - -#### 3. Async_AdvancedWebServer_SendChunked on ESP32_DEV with ESP32_W5500 - -Following is debug terminal output when running example [Async_AdvancedWebServer_SendChunked](examples/Async_AdvancedWebServer_SendChunked) on `ESP32_DEV with LwIP W5500`, using ESP32 core `v2.0.0+`, to demo how to use `beginChunkedResponse()` to send large `html` in chunks - -```cpp -Start Async_AdvancedWebServer_SendChunked on ESP32_DEV with ESP32_W5500 -AsyncWebServer_ESP32_W5500 v1.6.4 for core v2.0.0+ -[AWS] Default SPI pinout: -[AWS] SPI_HOST: 2 -[AWS] MOSI: 23 -[AWS] MISO: 19 -[AWS] SCK: 18 -[AWS] CS: 5 -[AWS] INT: 4 -[AWS] SPI Clock (MHz): 25 -[AWS] ========================= - -ETH Started -ETH Connected -ETH MAC: DE:AD:BE:EF:BE:08, IPv4: 192.168.2.88 -FULL_DUPLEX, 100Mbps -AsyncWebServer is @ IP : 192.168.2.88 -.[AWS] Total length to send in chunks = 31259 -[AWS] Bytes sent in chunk = 5620 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 4300 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 4203 -[AWS] Bytes sent in chunk = 0 -.[AWS] Total length to send in chunks = 31279 -[AWS] Bytes sent in chunk = 5620 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 2864 -[AWS] Bytes sent in chunk = 2864 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 2864 -[AWS] Bytes sent in chunk = 2787 -[AWS] Bytes sent in chunk = 0 -``` - -You can access the Async Advanced WebServers @ the server IP - -

- -

- - ---- - -#### 4. AsyncWebServer_SendChunked on ESP32_DEV with ESP32_W5500 - -Following is debug terminal output when running example [AsyncWebServer_SendChunked](examples/AsyncWebServer_SendChunked) on `ESP32_DEV with LwIP W5500`, using ESP32 core `v2.0.0+`, to demo how to use `beginChunkedResponse()` to send large `html` in chunks - - -```cpp -Start AsyncWebServer_SendChunked on ESP32_DEV with ESP32_W5500 -AsyncWebServer_ESP32_W5500 v1.6.4 for core v2.0.0+ -[AWS] Default SPI pinout: -[AWS] SPI_HOST: 2 -[AWS] MOSI: 23 -[AWS] MISO: 19 -[AWS] SCK: 18 -[AWS] CS: 5 -[AWS] INT: 4 -[AWS] SPI Clock (MHz): 25 -[AWS] ========================= - -ETH Started -ETH Connected -ETH MAC: DE:AD:BE:EF:BE:08, IPv4: 192.168.2.88 -FULL_DUPLEX, 100Mbps -AsyncWebServer is @ IP : 192.168.2.88 -.[AWS] Total length to send in chunks = 47802 -[AWS] Bytes sent in chunk = 5624 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 4300 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 1428 -[AWS] Bytes sent in chunk = 4300 -[AWS] Bytes sent in chunk = 2864 -[AWS] Bytes sent in chunk = 2864 -[AWS] Bytes sent in chunk = 2864 -[AWS] Bytes sent in chunk = 2864 -[AWS] Bytes sent in chunk = 2864 -[AWS] Bytes sent in chunk = 2122 -[AWS] Bytes sent in chunk = 0 -``` - - ---- - -#### 5. Async_WebSocketsServer on ESP32_DEV with ESP32_W5500 - -Following is debug terminal output when running example [Async_WebSocketsServer](examples/Async_WebSocketsServer) on `ESP32_DEV with LwIP W5500`, using ESP32 core `v2.0.0+`, to demo how to use `Async_WebSocketsServer` feature - - -```cpp -Starting Async_WebSocketsServer on ESP32_DEV with ESP32_W5500 -AsyncWebServer_ESP32_W5500 v1.6.4 for core v2.0.0+ -[AWS] Default SPI pinout: -[AWS] SPI_HOST: 2 -[AWS] MOSI: 23 -[AWS] MISO: 19 -[AWS] SCK: 18 -[AWS] CS: 5 -[AWS] INT: 4 -[AWS] SPI Clock (MHz): 25 -[AWS] ========================= - -ETH Started -ETH Connected -ETH MAC: DE:AD:BE:EF:BE:08, IPv4: 192.168.2.88 -FULL_DUPLEX, 100Mbps -ws[Server: /ws][ClientID: 1] WSClient connected -ws[Server: /ws][ClientID: 1] WSClient disconnected -ws[Server: /ws][ClientID: 2] WSClient connected -ws[Server: /ws][ClientID: 3] WSClient connected -``` - ---- - -#### 6. Async_HTTPBasicAuth on ESP32_DEV with ESP32_W5500 - -Following is debug terminal output when running example [Async_HTTPBasicAuth](examples/Async_HTTPBasicAuth) on `ESP32_DEV with LwIP W5500`, using ESP32 core `v2.0.0+`, to demo how to use `Async_Auth` feature - - -```cpp -Start Async_HTTPBasicAuth on ESP32_DEV with ESP32_W5500 -AsyncWebServer_ESP32_W5500 v1.6.4 for core v2.0.0+ -[AWS] Default SPI pinout: -[AWS] SPI_HOST: 2 -[AWS] MOSI: 23 -[AWS] MISO: 19 -[AWS] SCK: 18 -[AWS] CS: 5 -[AWS] INT: 4 -[AWS] SPI Clock (MHz): 25 -[AWS] ========================= - -ETH Started -ETH Connected -ETH MAC: DE:AD:BE:EF:BE:08, IPv4: 192.168.2.88 -FULL_DUPLEX, 100Mbps -Async_HttpBasicAuth started @ IP : 192.168.2.88 -Open http://192.168.2.88/ in your browser to see it working -Login using username = admin and password = esp32_w5500 -``` - - ---- ---- - -### Debug - -Debug is enabled by default on Serial. Debug Level from 0 to 4. To disable, change the _ETHERNET_WEBSERVER_LOGLEVEL_ to 0 - -```cpp -// Use this to output debug msgs to Serial -#define DEBUG_ASYNC_WEBSERVER_PORT Serial -// Use this to disable all output debug msgs -// Debug Level from 0 to 4 -#define _ASYNC_WEBSERVER_LOGLEVEL_ 0 -``` - ---- - -### Troubleshooting - -If you get compilation errors, more often than not, you may need to install a newer version of Arduino IDE, the Arduino `ESP32` core or depending libraries. - -Sometimes, the library will only work if you update the `ESP32` core to the latest version because I'm always using the latest cores /libraries. - ---- - -### Issues ### - -Submit issues to: [AsyncWebServer_ESP32_W5500 issues](https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500/issues) - ---- ---- - -## TO DO - - 1. Fix bug. Add enhancement - 2. Add support to more Ethernet shields, such as **DP83848, TLK110, IP101, RTL8201, DM9051, KSZ8041, KSZ8081, W6100, etc.** - 3. Add `LittleFS` support to use with new cores - ---- - -## DONE - - 1. Initial port to `ESP32` boards using `LwIP W5500` Ethernet. - 2. Add more examples. - 3. Add debugging features. - 4. Add Table-of-Contents and Version String - 5. Display compiler `#warning` only when `DEBUG_LEVEL` is 3+ - 6. Fix `AsyncWebSocket` bug - 7. Support using `CString` to save heap to send `very large data`. Check [request->send(200, textPlainStr, jsonChartDataCharStr); - Without using String Class - to save heap #8](https://github.com/khoih-prog/Portenta_H7_AsyncWebServer/pull/8) - 8. Add examples [Async_AdvancedWebServer_SendChunked](https://github.com/khoih-prog/AsyncWebServer_RP2040W/tree/main/examples/Async_AdvancedWebServer_SendChunked) and [AsyncWebServer_SendChunked](https://github.com/khoih-prog/AsyncWebServer_RP2040W/tree/main/examples/AsyncWebServer_SendChunked) to demo how to use `beginChunkedResponse()` to send large `html` in chunks - 9. Use `allman astyle` and add `utils` -10. Add `Async_WebSocketsServer`, `Async_HttpBasicAuth` and `MQTT` examples - ---- ---- - - -### Contributions and Thanks - -1. Based on and modified from [Hristo Gochkov's ESPAsyncWebServer](https://github.com/me-no-dev/ESPAsyncWebServer). Many thanks to [Hristo Gochkov](https://github.com/me-no-dev) for great [ESPAsyncWebServer Library](https://github.com/me-no-dev/ESPAsyncWebServer) - - - - - - -
me-no-dev
⭐️⭐️ Hristo Gochkov

- ---- - -### Contributing - -If you want to contribute to this project: -- Report bugs and errors -- Ask for enhancements -- Create issues and pull requests -- Tell other people about this library - ---- - -### License - -- The library is licensed under [GPLv3](https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500/blob/main/LICENSE) - ---- - -## Copyright - -- Copyright (c) 2016- Hristo Gochkov - -- Copyright (c) 2022- Khoi Hoang - - - diff --git a/lib/AsyncWebServer_ESP32_W5500/changelog.md b/lib/AsyncWebServer_ESP32_W5500/changelog.md deleted file mode 100644 index 4244afc..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/changelog.md +++ /dev/null @@ -1,43 +0,0 @@ -# AsyncWebServer_ESP32_W5500 Library - -[![arduino-library-badge](https://www.ardu-badge.com/badge/AsyncWebServer_ESP32_W5500.svg?)](https://www.ardu-badge.com/AsyncWebServer_ESP32_W5500) -[![GitHub release](https://img.shields.io/github/release/khoih-prog/AsyncWebServer_ESP32_W5500.svg)](https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500/releases) -[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](#Contributing) -[![GitHub issues](https://img.shields.io/github/issues/khoih-prog/AsyncWebServer_ESP32_W5500.svg)](http://github.com/khoih-prog/AsyncWebServer_ESP32_W5500/issues) - -Donate to my libraries using BuyMeACoffee - - - ---- ---- - -## Table of contents - -* [Changelog](#changelog) - * [Releases v1.6.4](#releases-v164) - * [Releases v1.6.3](#releases-v163) - * [Releases v1.6.2](#releases-v162) - - - ---- ---- - -## Changelog - -#### Releases v1.6.4 - -1. Remove unused variable to avoid compiler warning and error - -#### Releases v1.6.3 - -1. Add `Async_WebSocketsServer`, `Async_HttpBasicAuth` and `MQTT` examples - -#### Releases v1.6.2 - -1. Initial coding to port [ESPAsyncWebServer](https://github.com/me-no-dev/ESPAsyncWebServer) to ESP32 boards using `LwIP W5500 Ethernet`. -2. Bump up to `v1.6.2` to sync with [AsyncWebServer_WT32_ETH01 v1.6.2](https://github.com/khoih-prog/AsyncWebServer_WT32_ETH01). -3. Use `allman astyle` - - diff --git a/lib/AsyncWebServer_ESP32_W5500/keywords.txt b/lib/AsyncWebServer_ESP32_W5500/keywords.txt deleted file mode 100644 index 7bb5dd4..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/keywords.txt +++ /dev/null @@ -1,530 +0,0 @@ -############################################### -# Syntax Coloring Map For AsyncWebServer_STM32 -############################################### - -####################################### -# Datatypes (KEYWORD1) -####################################### - -ESP32_ENC KEYWORD1 - -AsyncWebServer KEYWORD1 -AsyncWebServerRequest KEYWORD1 -AsyncWebServerResponse KEYWORD1 -AsyncWebHeader KEYWORD1 -AsyncWebParameter KEYWORD1 -AsyncWebRewrite KEYWORD1 -AsyncWebHandler KEYWORD1 -AsyncStaticWebHandler KEYWORD1 -AsyncCallbackWebHandler KEYWORD1 -AsyncResponseStream KEYWORD1 - -AsyncWebSocketMessageBuffer -AsyncWebSocketMessage -AsyncWebSocketBasicMessage -AsyncWebSocketMultiMessage -AsyncWebSocket KEYWORD1 -AsyncWebSocketResponse KEYWORD1 -AsyncWebSocketClient KEYWORD1 -AsyncWebSocketControl KEYWORD1 - -AsyncEventSourceMessage KEYWORD1 -AsyncEventSourceClient KEYWORD1 -AsyncEventSource KEYWORD1 -AsyncEventSourceResponse KEYWORD1 -ChunkPrint KEYWORD1 - -AsyncJsonResponse KEYWORD1 -PrettyAsyncJsonResponse KEYWORD1 -AsyncCallbackJsonWebHandler KEYWORD1 - -AsyncBasicResponse KEYWORD1 -AsyncAbstractResponse KEYWORD1 -AsyncStreamResponse KEYWORD1 -AsyncCallbackResponse KEYWORD1 -AsyncChunkedResponse KEYWORD1 -AsyncResponseStream KEYWORD1 - -AsyncWebLock KEYWORD1 -AsyncWebLockGuard KEYWORD1 - -LinkedListNode KEYWORD1 -LinkedList KEYWORD1 -StringArray KEYWORD1 - -WebRequestMethod KEYWORD1 -WebRequestMethodComposite KEYWORD1 -ArDisconnectHandler KEYWORD1 - -RequestedConnectionType KEYWORD1 -AwsResponseFiller KEYWORD1 -AwsTemplateProcessor KEYWORD1 -ArRequestFilterFunction KEYWORD1 - -WebResponseState KEYWORD1 -ArRequestHandlerFunction KEYWORD1 -ArUploadHandlerFunction KEYWORD1 -ArBodyHandlerFunction KEYWORD1 - -ArJsonRequestHandlerFunction KEYWORD1 - -AwsFrameInfo KEYWORD1 -AwsClientStatus KEYWORD1 -AwsFrameType KEYWORD1 -AwsMessageStatus KEYWORD1 -AwsEventType KEYWORD1 -AwsEventHandler KEYWORD1 - -####################################### -# Methods and Functions (KEYWORD2) -####################################### - -################### -# AsyncWebParameter -################### - -name KEYWORD2 -value KEYWORD2 -size KEYWORD2 -isPost KEYWORD2 -isFile KEYWORD2 - -################### -# AsyncWebHeader -################### - -name KEYWORD2 -value KEYWORD2 -toString KEYWORD2 - -######################## -# AsyncWebServerRequest -######################## - -client KEYWORD2 -version KEYWORD2 -method KEYWORD2 -url KEYWORD2 -host KEYWORD2 -contentType KEYWORD2 -contentLength KEYWORD2 -multipart KEYWORD2 -methodToString KEYWORD2 -requestedConnType KEYWORD2 -isExpectedRequestedConnType KEYWORD2 -onDisconnect KEYWORD2 -authenticate KEYWORD2 -requestAuthentication KEYWORD2 -setHandler KEYWORD2 -addInterestingHeader KEYWORD2 -redirect KEYWORD2 -send KEYWORD2 -sendChunked KEYWORD2 -beginResponse KEYWORD2 -beginChunkedResponse KEYWORD2 -beginResponseStream KEYWORD2 -headers KEYWORD2 -hasHeader KEYWORD2 -getHeader KEYWORD2 -params KEYWORD2 -hasParam KEYWORD2 -getParam KEYWORD2 -arg KEYWORD2 -argName KEYWORD2 -hasArg KEYWORD2 -header KEYWORD2 -headerName KEYWORD2 -urlDecode KEYWORD2 - -################### -# AsyncWebRewrite -################### - -filter KEYWORD2 -from KEYWORD2 -toUrl KEYWORD2 -params KEYWORD2 -match KEYWORD2 - -######################## -# AsyncWebHandler -######################## - -setFilter KEYWORD2 -setAuthentication KEYWORD2 -filter KEYWORD2 -canHandle KEYWORD2 -handleRequest KEYWORD2 -handleUpload KEYWORD2 -handleBody KEYWORD2 -isRequestHandlerTrivial KEYWORD2 - -######################### -# AsyncWebServerResponse -######################### - -setCode KEYWORD2 -setContentLength KEYWORD2 -setContentType KEYWORD2 -addHeader KEYWORD2 -_assembleHead KEYWORD2 -_started KEYWORD2 -_finished KEYWORD2 -_failed KEYWORD2 -_sourceValid KEYWORD2 -_respond KEYWORD2 -_ack KEYWORD2 - -######################### -# AsyncWebServer -######################### - -begin KEYWORD2 -end KEYWORD2 -addRewrite KEYWORD2 -removeRewrite KEYWORD2 -addHandler KEYWORD2 -removeHandler KEYWORD2 -on KEYWORD2 -onNotFound KEYWORD2 -onRequestBody KEYWORD2 -reset KEYWORD2 -_handleDisconnect KEYWORD2 -_attachHandler KEYWORD2 -_rewriteRequest KEYWORD2 - -######################### -# DefaultHeaders -######################### - -addHeader KEYWORD2 -end KEYWORD2 -begin KEYWORD2 -Instance KEYWORD2 - -######################### -# AsyncEventSourceMessage -######################### - -ack KEYWORD2 -send KEYWORD2 -finished KEYWORD2 -sent KEYWORD2 - -######################### -# AsyncEventSourceClient -######################### - -client KEYWORD2 -close KEYWORD2 -write KEYWORD2 -send KEYWORD2 -connected KEYWORD2 -lastId KEYWORD2 -packetsWaiting KEYWORD2 -_onAck KEYWORD2 -_onPoll KEYWORD2 -_onTimeout KEYWORD2 -_onDisconnect KEYWORD2 - -########################### -# AsyncEventSource -########################### - -url KEYWORD2 -close KEYWORD2 -onConnect KEYWORD2 -send KEYWORD2 -count KEYWORD2 -avgPacketsWaiting KEYWORD2 -_addClient KEYWORD2 -_handleDisconnect KEYWORD2 -canHandle KEYWORD2 -handleRequest KEYWORD2 - -########################### -# AsyncEventSourceResponse -########################### - -_respond KEYWORD2 -_ack KEYWORD2 -_sourceValid KEYWORD2 - -########################### -# ChunkPrint -########################### - -write KEYWORD2 - -########################### -# AsyncJsonResponse -########################### - -getRoot KEYWORD2 -_sourceValid KEYWORD2 -setLength KEYWORD2 -getSize KEYWORD2 -_fillBuffer KEYWORD2 - -########################### -# PrettyAsyncJsonResponse -########################### - -setLength KEYWORD2 -_fillBuffer KEYWORD2 - -############################## -# AsyncCallbackJsonWebHandler -############################## - -setMethod KEYWORD2 -setMaxContentLength KEYWORD2 - -onRequest KEYWORD2 -canHandle KEYWORD2 -handleRequest KEYWORD2 -handleUpload KEYWORD2 -handleBody KEYWORD2 -isRequestHandlerTrivial KEYWORD2 - -########################### -# AsyncStaticWebHandler -########################### - -canHandle KEYWORD2 -handleRequest KEYWORD2 -setIsDir KEYWORD2 -setCacheControl KEYWORD2 -setLastModified KEYWORD2 -setTemplateProcessor KEYWORD2 - -############################## -# AsyncCallbackWebHandler -############################## - -setUri KEYWORD2 -setMethod KEYWORD2 -onRequest KEYWORD2 -onUpload KEYWORD2 -onBody KEYWORD2 -canHandle KEYWORD2 -handleRequest KEYWORD2 -handleBody KEYWORD2 -isRequestHandlerTrivial KEYWORD2 - -############################## -# AsyncBasicResponse -############################## - -_respond KEYWORD2 -_ack KEYWORD2 -_sourceValid KEYWORD2 - -############################## -# AsyncAbstractResponse -############################## - -_respond KEYWORD2 -_ack KEYWORD2 -_sourceValid KEYWORD2 -_fillBuffer KEYWORD2 - -############################## -# AsyncStreamResponse -############################## - -_sourceValid KEYWORD2 -_fillBuffer KEYWORD2 - -############################## -# AsyncCallbackResponse -############################## - -_sourceValid KEYWORD2 -_fillBuffer KEYWORD2 - -############################## -# AsyncChunkedResponse -############################## - -_sourceValid KEYWORD2 -_fillBuffer KEYWORD2 - -############################## -# AsyncResponseStream -############################## - -_sourceValid KEYWORD2 -_fillBuffer KEYWORD2 -write KEYWORD2 - -############################## -# AsyncWebSocketMessage -############################## - -ack KEYWORD2 -send KEYWORD2 -finished KEYWORD2 -betweenFrames KEYWORD2 - -############################## -# AsyncWebSocketBasicMessage -############################## - -ack KEYWORD2 -send KEYWORD2 -betweenFrames KEYWORD2 - -############################## -# AsyncWebSocketMultiMessage -############################## - -ack KEYWORD2 -send KEYWORD2 -betweenFrames KEYWORD2 - -############################## -# AsyncWebSocketClient -############################## - -id KEYWORD2 -status KEYWORD2 -client KEYWORD2 -server KEYWORD2 -pinfo KEYWORD2 -remoteIP KEYWORD2 -remotePort KEYWORD2 -close KEYWORD2 -ping KEYWORD2 -keepAlivePeriod KEYWORD2 -message KEYWORD2 -queueIsFull KEYWORD2 -printf KEYWORD2 -text KEYWORD2 -binary KEYWORD2 -canSend KEYWORD2 -_onAck KEYWORD2 -_onError KEYWORD2 -_onPoll KEYWORD2 -_onTimeout KEYWORD2 -_onDisconnect KEYWORD2 -_onData KEYWORD2 - -############################## -# AsyncWebSocket -############################## - -url KEYWORD2 -enable KEYWORD2 -enabled KEYWORD2 -availableForWriteAll KEYWORD2 -availableForWrite KEYWORD2 -count KEYWORD2 -client KEYWORD2 -hasClient KEYWORD2 -close KEYWORD2 -closeAll KEYWORD2 -cleanupClients KEYWORD2 - -ping KEYWORD2 -pingAll KEYWORD2 -text KEYWORD2 -textAll KEYWORD2 -binary KEYWORD2 -binaryAll KEYWORD2 -message KEYWORD2 -messageAll KEYWORD2 -printf KEYWORD2 -printfAll KEYWORD2 -onEvent KEYWORD2 -_getNextId KEYWORD2 -_addClient KEYWORD2 -_handleDisconnect KEYWORD2 -_handleEvent KEYWORD2 -canHandle KEYWORD2 -handleRequest KEYWORD2 -makeBuffer KEYWORD2 -_cleanBuffers KEYWORD2 -getClients KEYWORD2 - -############################## -# AsyncWebSocketResponse -############################## - -_respond KEYWORD2 -_ack KEYWORD2 -_sourceValid KEYWORD2 - -############################## -# AsyncWebLock -############################## - -lock KEYWORD2 -unlock KEYWORD2 - -############################## -# LinkedListNode -############################## - -value KEYWORD2 - -############################## -# LinkedList -############################## - -begin KEYWORD2 -end KEYWORD2 -add KEYWORD2 -front KEYWORD2 -isEmpty KEYWORD2 -length KEYWORD2 -count_if KEYWORD2 -nth KEYWORD2 -remove KEYWORD2 -remove_first KEYWORD2 -free KEYWORD2 - -############################## -# StringArray -############################## - -containsIgnoreCase KEYWORD2 - -############################## -# General -############################## - -memchr KEYWORD2 -webSocketSendFrameWindow KEYWORD2 -webSocketSendFrame KEYWORD2 -generateEventMessage KEYWORD2 - -############################## -# ESP32_ENC -############################## - -begin KEYWORD2 -config KEYWORD2 -getHostname KEYWORD2 -setHostname KEYWORD2 -fullDuplex KEYWORD2 -linkUp KEYWORD2 -linkSpeed KEYWORD2 -enableIpV6 KEYWORD2 -localIPv6 KEYWORD2 -localIP KEYWORD2 -subnetMask KEYWORD2 -gatewayIP KEYWORD2 -dnsIP KEYWORD2 -broadcastIP KEYWORD2 -networkID KEYWORD2 -subnetCIDR KEYWORD2 -macAddress KEYWORD2 -macAddress KEYWORD2 - -####################################### -# Constants (LITERAL1) -####################################### - -# LITERAL1 -ENC28J60_Default_Mac LITERAL1 diff --git a/lib/AsyncWebServer_ESP32_W5500/library.json b/lib/AsyncWebServer_ESP32_W5500/library.json deleted file mode 100644 index 515097a..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/library.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "name":"AsyncWebServer_ESP32_W5500", - "version": "1.6.4", - "description":"Asynchronous HTTP and WebSocket Server Library for (ESP32 + LwIP W5500). Now supporting using CString to save heap to send very large data and with examples to demo how to use beginChunkedResponse() to send large html in chunks", - "keywords":"http, async, async-webserver, websocket, webserver, esp32, w5500, lwip", - "authors": - [ - { - "name": "Hristo Gochkov", - "url": "https://github.com/me-no-dev" - }, - { - "name": "Khoi Hoang", - "url": "https://github.com/khoih-prog", - "email": "khoih.prog@gmail.com", - "maintainer": true - } - ], - "repository": - { - "type": "git", - "url": "https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500" - }, - "dependencies": - [ - { - "owner": "me-no-dev", - "name": "AsyncTCP", - "version": "^1.1.1", - "platforms": "espressif32" - } - ], - "license": "LGPL-3.0", - "frameworks": "arduino", - "platforms": ["espressif32"], - "examples": "examples/*/*/*.ino", - "headers": ["AsyncWebServer_ESP32_W5500.h"] -} diff --git a/lib/AsyncWebServer_ESP32_W5500/library.properties b/lib/AsyncWebServer_ESP32_W5500/library.properties deleted file mode 100644 index 0c4d720..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/library.properties +++ /dev/null @@ -1,12 +0,0 @@ -name=AsyncWebServer_ESP32_W5500 -version=1.6.4 -author=Hristo Gochkov,Khoi Hoang -maintainer=Khoi Hoang -license=GPLv3 -sentence=AsyncWebServer for (ESP32 + LwIP W5500) -paragraph=This is Asynchronous HTTP and WebSocket Server Library for (ESP32 + LwIP W5500). Now supporting using CString to save heap to send very large data and with examples to demo how to use beginChunkedResponse() to send large html in chunks -category=Communication -url=https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 -architectures=esp32 -depends=AsyncTCP -includes=AsyncWebServer_ESP32_W5500.h diff --git a/lib/AsyncWebServer_ESP32_W5500/src/AsyncEventSource.cpp b/lib/AsyncWebServer_ESP32_W5500/src/AsyncEventSource.cpp deleted file mode 100644 index 8424510..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/AsyncEventSource.cpp +++ /dev/null @@ -1,566 +0,0 @@ -/**************************************************************************************************************************** - AsyncEventSource.cpp - Dead simple Ethernet AsyncWebServer. - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - - Original author: Hristo Gochkov - - Copyright (c) 2016 Hristo Gochkov. All rights reserved. - - This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License along with this library; - if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Version: 1.6.4 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2 - 1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples - 1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error - *****************************************************************************************************************************/ - -#include "Arduino.h" -#include "AsyncEventSource.h" - -///////////////////////////////////////////////// - -static String generateEventMessage(const char *message, const char *event, uint32_t id, uint32_t reconnect) -{ - String ev = ""; - - if (reconnect) - { - ev += "retry: "; - ev += String(reconnect); - ev += "\r\n"; - } - - if (id) - { - ev += "id: "; - ev += String(id); - ev += "\r\n"; - } - - if (event != NULL) - { - ev += "event: "; - ev += String(event); - ev += "\r\n"; - } - - if (message != NULL) - { - size_t messageLen = strlen(message); - char * lineStart = (char *)message; - char * lineEnd; - - do - { - char * nextN = strchr(lineStart, '\n'); - char * nextR = strchr(lineStart, '\r'); - - if (nextN == NULL && nextR == NULL) - { - size_t llen = ((char *)message + messageLen) - lineStart; - char * ldata = (char *)malloc(llen + 1); - - if (ldata != NULL) - { - memcpy(ldata, lineStart, llen); - ldata[llen] = 0; - ev += "data: "; - ev += ldata; - ev += "\r\n\r\n"; - free(ldata); - } - - lineStart = (char *)message + messageLen; - } - else - { - char * nextLine = NULL; - - if (nextN != NULL && nextR != NULL) - { - if (nextR < nextN) - { - lineEnd = nextR; - - if (nextN == (nextR + 1)) - nextLine = nextN + 1; - else - nextLine = nextR + 1; - } - else - { - lineEnd = nextN; - - if (nextR == (nextN + 1)) - nextLine = nextR + 1; - else - nextLine = nextN + 1; - } - } - else if (nextN != NULL) - { - lineEnd = nextN; - nextLine = nextN + 1; - } - else - { - lineEnd = nextR; - nextLine = nextR + 1; - } - - size_t llen = lineEnd - lineStart; - char * ldata = (char *)malloc(llen + 1); - - if (ldata != NULL) - { - memcpy(ldata, lineStart, llen); - ldata[llen] = 0; - ev += "data: "; - ev += ldata; - ev += "\r\n"; - free(ldata); - } - - lineStart = nextLine; - - if (lineStart == ((char *)message + messageLen)) - ev += "\r\n"; - } - } while (lineStart < ((char *)message + messageLen)); - } - - return ev; -} - -///////////////////////////////////////////////// -///////////////////////////////////////////////// - -// Message - -AsyncEventSourceMessage::AsyncEventSourceMessage(const char * data, size_t len) - : _data(nullptr), _len(len), _sent(0), _acked(0) -{ - _data = (uint8_t*)malloc(_len + 1); - - if (_data == nullptr) - { - _len = 0; - } - else - { - memcpy(_data, data, len); - _data[_len] = 0; - } -} - -///////////////////////////////////////////////// - -AsyncEventSourceMessage::~AsyncEventSourceMessage() -{ - if (_data != NULL) - free(_data); -} - -///////////////////////////////////////////////// - -size_t AsyncEventSourceMessage::ack(size_t len, uint32_t time) -{ - ESP32_W5500_AWS_UNUSED(time); - - // If the whole message is now acked... - if (_acked + len > _len) - { - // Return the number of extra bytes acked (they will be carried on to the next message) - const size_t extra = _acked + len - _len; - _acked = _len; - return extra; - } - - // Return that no extra bytes left. - _acked += len; - - return 0; -} - -///////////////////////////////////////////////// - -size_t AsyncEventSourceMessage::send(AsyncClient *client) -{ - const size_t len = _len - _sent; - - if (client->space() < len) - { - return 0; - } - - size_t sent = client->add((const char *)_data, len); - - if (client->canSend()) - client->send(); - - _sent += sent; - - return sent; -} - -///////////////////////////////////////////////// -///////////////////////////////////////////////// - -// Client - -AsyncEventSourceClient::AsyncEventSourceClient(AsyncWebServerRequest *request, AsyncEventSource *server) - : _messageQueue(LinkedList([](AsyncEventSourceMessage * m) -{ - delete m; -})) -{ - _client = request->client(); - _server = server; - _lastId = 0; - - if (request->hasHeader("Last-Event-ID")) - _lastId = atoi(request->getHeader("Last-Event-ID")->value().c_str()); - - _client->setRxTimeout(0); - _client->onError(NULL, NULL); - - _client->onAck([](void *r, AsyncClient * c, size_t len, uint32_t time) - { - ESP32_W5500_AWS_UNUSED(c); - ((AsyncEventSourceClient*)(r))->_onAck(len, time); - }, this); - - _client->onPoll([](void *r, AsyncClient * c) - { - ESP32_W5500_AWS_UNUSED(c); - ((AsyncEventSourceClient*)(r))->_onPoll(); - }, this); - - _client->onData(NULL, NULL); - - _client->onTimeout([this](void *r, AsyncClient * c __attribute__((unused)), uint32_t time) - { - ((AsyncEventSourceClient*)(r))->_onTimeout(time); - }, this); - - _client->onDisconnect([this](void *r, AsyncClient * c) - { - ((AsyncEventSourceClient*)(r))->_onDisconnect(); - delete c; - }, this); - - _server->_addClient(this); - - delete request; -} - -///////////////////////////////////////////////// - -AsyncEventSourceClient::~AsyncEventSourceClient() -{ - _messageQueue.free(); - close(); -} - -///////////////////////////////////////////////// - -void AsyncEventSourceClient::_queueMessage(AsyncEventSourceMessage *dataMessage) -{ - if (dataMessage == NULL) - return; - - if (!connected()) - { - delete dataMessage; - - return; - } - - if (_messageQueue.length() >= SSE_MAX_QUEUED_MESSAGES) - { - AWS_LOGERROR(F("[AsyncEventSourceClient::_queueMessage] ERROR: Too many messages queued")); - - delete dataMessage; - } - else - { - _messageQueue.add(dataMessage); - } - - if (_client->canSend()) - _runQueue(); -} - -///////////////////////////////////////////////// - -void AsyncEventSourceClient::_onAck(size_t len, uint32_t time) -{ - while (len && !_messageQueue.isEmpty()) - { - len = _messageQueue.front()->ack(len, time); - - if (_messageQueue.front()->finished()) - _messageQueue.remove(_messageQueue.front()); - } - - _runQueue(); -} - -///////////////////////////////////////////////// - -void AsyncEventSourceClient::_onPoll() -{ - if (!_messageQueue.isEmpty()) - { - _runQueue(); - } -} - -///////////////////////////////////////////////// - -void AsyncEventSourceClient::_onTimeout(uint32_t time __attribute__((unused))) -{ - _client->close(true); -} - -///////////////////////////////////////////////// - -void AsyncEventSourceClient::_onDisconnect() -{ - _client = NULL; - _server->_handleDisconnect(this); -} - -///////////////////////////////////////////////// - -void AsyncEventSourceClient::close() -{ - if (_client != NULL) - _client->close(); -} - -///////////////////////////////////////////////// - -void AsyncEventSourceClient::write(const char * message, size_t len) -{ - _queueMessage(new AsyncEventSourceMessage(message, len)); -} - -///////////////////////////////////////////////// - -void AsyncEventSourceClient::send(const char *message, const char *event, uint32_t id, uint32_t reconnect) -{ - String ev = generateEventMessage(message, event, id, reconnect); - _queueMessage(new AsyncEventSourceMessage(ev.c_str(), ev.length())); -} - -///////////////////////////////////////////////// - -void AsyncEventSourceClient::_runQueue() -{ - while (!_messageQueue.isEmpty() && _messageQueue.front()->finished()) - { - _messageQueue.remove(_messageQueue.front()); - } - - for (auto i = _messageQueue.begin(); i != _messageQueue.end(); ++i) - { - if (!(*i)->sent()) - (*i)->send(_client); - } -} - -///////////////////////////////////////////////// -///////////////////////////////////////////////// - -// Handler - -AsyncEventSource::AsyncEventSource(const String& url) - : _url(url) - , _clients(LinkedList([](AsyncEventSourceClient * c) -{ - delete c; -})) -, _connectcb(NULL) -{} - -///////////////////////////////////////////////// - -AsyncEventSource::~AsyncEventSource() -{ - close(); -} - -///////////////////////////////////////////////// - -void AsyncEventSource::onConnect(ArEventHandlerFunction cb) -{ - _connectcb = cb; -} - -///////////////////////////////////////////////// - -void AsyncEventSource::_addClient(AsyncEventSourceClient * client) -{ - /*char * temp = (char *)malloc(2054); - if(temp != NULL){ - memset(temp+1,' ',2048); - temp[0] = ':'; - temp[2049] = '\r'; - temp[2050] = '\n'; - temp[2051] = '\r'; - temp[2052] = '\n'; - temp[2053] = 0; - client->write((const char *)temp, 2053); - free(temp); - }*/ - - _clients.add(client); - - if (_connectcb) - _connectcb(client); -} - -///////////////////////////////////////////////// - -void AsyncEventSource::_handleDisconnect(AsyncEventSourceClient * client) -{ - _clients.remove(client); -} - -///////////////////////////////////////////////// - -void AsyncEventSource::close() -{ - for (const auto &c : _clients) - { - if (c->connected()) - c->close(); - } -} - -///////////////////////////////////////////////// - -// pmb fix -size_t AsyncEventSource::avgPacketsWaiting() const -{ - if (_clients.isEmpty()) - return 0; - - size_t aql = 0; - uint32_t nConnectedClients = 0; - - for (const auto &c : _clients) - { - if (c->connected()) - { - aql += c->packetsWaiting(); - ++nConnectedClients; - } - } - - // return aql / nConnectedClients; - return ((aql) + (nConnectedClients / 2)) / (nConnectedClients); // round up -} - -///////////////////////////////////////////////// - -void AsyncEventSource::send(const char *message, const char *event, uint32_t id, uint32_t reconnect) -{ - String ev = generateEventMessage(message, event, id, reconnect); - - for (const auto &c : _clients) - { - if (c->connected()) - { - c->write(ev.c_str(), ev.length()); - } - } -} - -///////////////////////////////////////////////// - -size_t AsyncEventSource::count() const -{ - return _clients.count_if([](AsyncEventSourceClient * c) - { - return c->connected(); - }); -} - -///////////////////////////////////////////////// - -bool AsyncEventSource::canHandle(AsyncWebServerRequest *request) -{ - if (request->method() != HTTP_GET || !request->url().equals(_url)) - { - return false; - } - - request->addInterestingHeader("Last-Event-ID"); - - return true; -} - -///////////////////////////////////////////////// - -void AsyncEventSource::handleRequest(AsyncWebServerRequest *request) -{ - if ((_username != "" && _password != "") && !request->authenticate(_username.c_str(), _password.c_str())) - return request->requestAuthentication(); - - request->send(new AsyncEventSourceResponse(this)); -} - -///////////////////////////////////////////////// -///////////////////////////////////////////////// - -// Response - -AsyncEventSourceResponse::AsyncEventSourceResponse(AsyncEventSource *server) -{ - _server = server; - _code = 200; - _contentType = "text/event-stream"; - _sendContentLength = false; - addHeader("Cache-Control", "no-cache"); - addHeader("Connection", "keep-alive"); -} - -///////////////////////////////////////////////// - -void AsyncEventSourceResponse::_respond(AsyncWebServerRequest *request) -{ - String out = _assembleHead(request->version()); - request->client()->write(out.c_str(), _headLength); - _state = RESPONSE_WAIT_ACK; -} - -///////////////////////////////////////////////// - -size_t AsyncEventSourceResponse::_ack(AsyncWebServerRequest *request, size_t len, uint32_t time __attribute__((unused))) -{ - if (len) - { - new AsyncEventSourceClient(request, _server); - } - - return 0; -} diff --git a/lib/AsyncWebServer_ESP32_W5500/src/AsyncEventSource.h b/lib/AsyncWebServer_ESP32_W5500/src/AsyncEventSource.h deleted file mode 100644 index e7f3b89..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/AsyncEventSource.h +++ /dev/null @@ -1,208 +0,0 @@ -/**************************************************************************************************************************** - AsyncEventSource.h - Dead simple Ethernet AsyncWebServer. - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - - Original author: Hristo Gochkov - - Copyright (c) 2016 Hristo Gochkov. All rights reserved. - - This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License along with this library; - if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Version: 1.6.4 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2 - 1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples - 1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error - *****************************************************************************************************************************/ - -#ifndef ASYNCEVENTSOURCE_H_ -#define ASYNCEVENTSOURCE_H_ - -#include - -#include -#define SSE_MAX_QUEUED_MESSAGES 32 - -#include "AsyncWebServer_ESP32_W5500.h" - -#include "AsyncWebSynchronization.h" - -///////////////////////////////////////////////// - -#define DEFAULT_MAX_SSE_CLIENTS 8 - -class AsyncEventSource; -class AsyncEventSourceResponse; -class AsyncEventSourceClient; - -///////////////////////////////////////////////// - -typedef std::function ArEventHandlerFunction; - -///////////////////////////////////////////////// - -class AsyncEventSourceMessage -{ - private: - uint8_t * _data; - size_t _len; - size_t _sent; - size_t _acked; - - public: - AsyncEventSourceMessage(const char * data, size_t len); - ~AsyncEventSourceMessage(); - size_t ack(size_t len, uint32_t time __attribute__((unused))); - size_t send(AsyncClient *client); - - ///////////////////////////////////////////////// - - inline bool finished() - { - return _acked == _len; - } - - ///////////////////////////////////////////////// - - inline bool sent() - { - return _sent == _len; - } -}; - -///////////////////////////////////////////////// - -class AsyncEventSourceClient -{ - private: - AsyncClient *_client; - AsyncEventSource *_server; - uint32_t _lastId; - LinkedList _messageQueue; - void _queueMessage(AsyncEventSourceMessage *dataMessage); - void _runQueue(); - - public: - - AsyncEventSourceClient(AsyncWebServerRequest *request, AsyncEventSource *server); - ~AsyncEventSourceClient(); - - ///////////////////////////////////////////////// - - inline AsyncClient* client() - { - return _client; - } - - ///////////////////////////////////////////////// - - void close(); - void write(const char * message, size_t len); - void send(const char *message, const char *event = NULL, uint32_t id = 0, uint32_t reconnect = 0); - - ///////////////////////////////////////////////// - - inline bool connected() const - { - return (_client != NULL) && _client->connected(); - } - - ///////////////////////////////////////////////// - - inline uint32_t lastId() const - { - return _lastId; - } - - ///////////////////////////////////////////////// - - inline size_t packetsWaiting() const - { - return _messageQueue.length(); - } - - ///////////////////////////////////////////////// - - //system callbacks (do not call) - void _onAck(size_t len, uint32_t time); - void _onPoll(); - void _onTimeout(uint32_t time); - void _onDisconnect(); -}; - -///////////////////////////////////////////////// - -class AsyncEventSource: public AsyncWebHandler -{ - private: - String _url; - LinkedList _clients; - ArEventHandlerFunction _connectcb; - - public: - AsyncEventSource(const String& url); - ~AsyncEventSource(); - - ///////////////////////////////////////////////// - - inline const char * url() const - { - return _url.c_str(); - } - - ///////////////////////////////////////////////// - - void close(); - void onConnect(ArEventHandlerFunction cb); - void send(const char *message, const char *event = NULL, uint32_t id = 0, uint32_t reconnect = 0); - size_t count() const; //number clinets connected - size_t avgPacketsWaiting() const; - - //system callbacks (do not call) - void _addClient(AsyncEventSourceClient * client); - void _handleDisconnect(AsyncEventSourceClient * client); - virtual bool canHandle(AsyncWebServerRequest *request) override final; - virtual void handleRequest(AsyncWebServerRequest *request) override final; -}; - -///////////////////////////////////////////////// - -class AsyncEventSourceResponse: public AsyncWebServerResponse -{ - private: - String _content; - AsyncEventSource *_server; - - public: - AsyncEventSourceResponse(AsyncEventSource *server); - void _respond(AsyncWebServerRequest *request); - size_t _ack(AsyncWebServerRequest *request, size_t len, uint32_t time); - - ///////////////////////////////////////////////// - - inline bool _sourceValid() const - { - return true; - } -}; - -///////////////////////////////////////////////// - -#endif /* ASYNCEVENTSOURCE_H_ */ - diff --git a/lib/AsyncWebServer_ESP32_W5500/src/AsyncJson.h b/lib/AsyncWebServer_ESP32_W5500/src/AsyncJson.h deleted file mode 100644 index 634b7f3..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/AsyncJson.h +++ /dev/null @@ -1,447 +0,0 @@ -/**************************************************************************************************************************** - AsyncJson.h - Dead simple Ethernet AsyncWebServer. - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - - Original author: Hristo Gochkov - - Copyright (c) 2016 Hristo Gochkov. All rights reserved. - - This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License along with this library; - if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Version: 1.6.4 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2 - 1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples - 1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error - *****************************************************************************************************************************/ -/* - Async Response to use with ArduinoJson and AsyncWebServer - Written by Andrew Melvin (SticilFace) with help from me-no-dev and BBlanchon. - - Example of callback in use - - server.on("/json", HTTP_ANY, [](AsyncWebServerRequest * request) { - - AsyncJsonResponse * response = new AsyncJsonResponse(); - JsonObject& root = response->getRoot(); - root["key1"] = "key number one"; - JsonObject& nested = root.createNestedObject("nested"); - nested["key1"] = "key number one"; - - response->setLength(); - request->send(response); - }); - - -------------------- - - Async Request to use with ArduinoJson and AsyncWebServer - Written by Arsène von Wyss (avonwyss) - - Example - - AsyncCallbackJsonWebHandler* handler = new AsyncCallbackJsonWebHandler("/rest/endpoint"); - handler->onRequest([](AsyncWebServerRequest *request, JsonVariant &json) { - JsonObject& jsonObj = json.as(); - // ... - }); - server.addHandler(handler); - -*/ - -#ifndef ASYNC_JSON_H_ -#define ASYNC_JSON_H_ - -#include - -#include "AsyncWebServer_ESP32_W5500.h" - -#include - -///////////////////////////////////////////////// - -#if ARDUINOJSON_VERSION_MAJOR == 5 - #define ARDUINOJSON_5_COMPATIBILITY -#else - #ifndef DYNAMIC_JSON_DOCUMENT_SIZE - #define DYNAMIC_JSON_DOCUMENT_SIZE 1024 - #endif -#endif - -///////////////////////////////////////////////// - -constexpr const char* JSON_MIMETYPE = "application/json"; - -///////////////////////////////////////////////// - -/* - Json Response - * */ - -class ChunkPrint : public Print -{ - private: - uint8_t* _destination; - size_t _to_skip; - size_t _to_write; - size_t _pos; - - public: - ChunkPrint(uint8_t* destination, size_t from, size_t len) - : _destination(destination), _to_skip(from), _to_write(len), _pos{0} {} - - virtual ~ChunkPrint() {} - - ///////////////////////////////////////////////// - - size_t write(uint8_t c) - { - if (_to_skip > 0) - { - _to_skip--; - - return 1; - } - else if (_to_write > 0) - { - _to_write--; - _destination[_pos++] = c; - - return 1; - } - - return 0; - } - - ///////////////////////////////////////////////// - - inline size_t write(const uint8_t *buffer, size_t size) - { - return this->Print::write(buffer, size); - } -}; - -///////////////////////////////////////////////// - -///////////////////////////////////////////////// - -class AsyncJsonResponse: public AsyncAbstractResponse -{ - protected: - -#ifdef ARDUINOJSON_5_COMPATIBILITY - DynamicJsonBuffer _jsonBuffer; -#else - DynamicJsonDocument _jsonBuffer; -#endif - - JsonVariant _root; - bool _isValid; - - public: - - ///////////////////////////////////////////////// - -#ifdef ARDUINOJSON_5_COMPATIBILITY - AsyncJsonResponse(bool isArray = false): _isValid {false} - { - _code = 200; - _contentType = JSON_MIMETYPE; - - if (isArray) - _root = _jsonBuffer.createArray(); - else - _root = _jsonBuffer.createObject(); - } -#else - AsyncJsonResponse(bool isArray = false, - size_t maxJsonBufferSize = DYNAMIC_JSON_DOCUMENT_SIZE) : _jsonBuffer(maxJsonBufferSize), _isValid {false} - { - _code = 200; - _contentType = JSON_MIMETYPE; - - if (isArray) - _root = _jsonBuffer.createNestedArray(); - else - _root = _jsonBuffer.createNestedObject(); - } -#endif - - ///////////////////////////////////////////////// - - ~AsyncJsonResponse() {} - - ///////////////////////////////////////////////// - - inline JsonVariant & getRoot() - { - return _root; - } - - ///////////////////////////////////////////////// - - inline bool _sourceValid() const - { - return _isValid; - } - - ///////////////////////////////////////////////// - - size_t setLength() - { - -#ifdef ARDUINOJSON_5_COMPATIBILITY - _contentLength = _root.measureLength(); -#else - _contentLength = measureJson(_root); -#endif - - if (_contentLength) - { - _isValid = true; - } - - return _contentLength; - } - - ///////////////////////////////////////////////// - - inline size_t getSize() - { - return _jsonBuffer.size(); - } - - ///////////////////////////////////////////////// - - size_t _fillBuffer(uint8_t *data, size_t len) - { - ChunkPrint dest(data, _sentLength, len); - -#ifdef ARDUINOJSON_5_COMPATIBILITY - _root.printTo( dest ) ; -#else - serializeJson(_root, dest); -#endif - return len; - } - - ///////////////////////////////////////////////// - -}; - -///////////////////////////////////////////////// -///////////////////////////////////////////////// - -class PrettyAsyncJsonResponse: public AsyncJsonResponse -{ - public: -#ifdef ARDUINOJSON_5_COMPATIBILITY - PrettyAsyncJsonResponse (bool isArray = false) : AsyncJsonResponse {isArray} {} -#else - PrettyAsyncJsonResponse (bool isArray = false, - size_t maxJsonBufferSize = DYNAMIC_JSON_DOCUMENT_SIZE) : AsyncJsonResponse {isArray, maxJsonBufferSize} {} -#endif - - ///////////////////////////////////////////////// - - size_t setLength () - { -#ifdef ARDUINOJSON_5_COMPATIBILITY - _contentLength = _root.measurePrettyLength (); -#else - _contentLength = measureJsonPretty(_root); -#endif - - if (_contentLength) - { - _isValid = true; - } - - return _contentLength; - } - - ///////////////////////////////////////////////// - - size_t _fillBuffer (uint8_t *data, size_t len) - { - ChunkPrint dest (data, _sentLength, len); - -#ifdef ARDUINOJSON_5_COMPATIBILITY - _root.prettyPrintTo (dest); -#else - serializeJsonPretty(_root, dest); -#endif - - return len; - } -}; - -///////////////////////////////////////////////// - -typedef std::function ArJsonRequestHandlerFunction; - -///////////////////////////////////////////////// -///////////////////////////////////////////////// - -class AsyncCallbackJsonWebHandler: public AsyncWebHandler -{ - private: - protected: - const String _uri; - WebRequestMethodComposite _method; - ArJsonRequestHandlerFunction _onRequest; - size_t _contentLength; - -#ifndef ARDUINOJSON_5_COMPATIBILITY - const size_t maxJsonBufferSize; -#endif - - size_t _maxContentLength; - - public: - - ///////////////////////////////////////////////// - -#ifdef ARDUINOJSON_5_COMPATIBILITY - AsyncCallbackJsonWebHandler(const String& uri, ArJsonRequestHandlerFunction onRequest) - : _uri(uri), _method(HTTP_POST | HTTP_PUT | HTTP_PATCH), _onRequest(onRequest), _maxContentLength(16384) {} -#else - AsyncCallbackJsonWebHandler(const String& uri, ArJsonRequestHandlerFunction onRequest, - size_t maxJsonBufferSize = DYNAMIC_JSON_DOCUMENT_SIZE) - : _uri(uri), _method(HTTP_POST | HTTP_PUT | HTTP_PATCH), _onRequest(onRequest), maxJsonBufferSize(maxJsonBufferSize), - _maxContentLength(16384) {} -#endif - - ///////////////////////////////////////////////// - - inline void setMethod(WebRequestMethodComposite method) - { - _method = method; - } - - ///////////////////////////////////////////////// - - inline void setMaxContentLength(int maxContentLength) - { - _maxContentLength = maxContentLength; - } - - ///////////////////////////////////////////////// - - inline void onRequest(ArJsonRequestHandlerFunction fn) - { - _onRequest = fn; - } - - ///////////////////////////////////////////////// - - virtual bool canHandle(AsyncWebServerRequest *request) override final - { - if (!_onRequest) - return false; - - if (!(_method & request->method())) - return false; - - if (_uri.length() && (_uri != request->url() && !request->url().startsWith(_uri + "/"))) - return false; - - if ( !request->contentType().equalsIgnoreCase(JSON_MIMETYPE) ) - return false; - - request->addInterestingHeader("ANY"); - - return true; - } - - ///////////////////////////////////////////////// - - virtual void handleRequest(AsyncWebServerRequest *request) override final - { - if (_onRequest) - { - if (request->_tempObject != NULL) - { - -#ifdef ARDUINOJSON_5_COMPATIBILITY - DynamicJsonBuffer jsonBuffer; - JsonVariant json = jsonBuffer.parse((uint8_t*)(request->_tempObject)); - - if (json.success()) - { -#else - DynamicJsonDocument jsonBuffer(this->maxJsonBufferSize); - DeserializationError error = deserializeJson(jsonBuffer, (uint8_t*)(request->_tempObject)); - - if (!error) - { - JsonVariant json = jsonBuffer.as(); -#endif - - _onRequest(request, json); - - return; - } - } - - request->send(_contentLength > _maxContentLength ? 413 : 400); - } - else - { - request->send(500); - } - } - - ///////////////////////////////////////////////// - - virtual void handleUpload(AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data, - size_t len, bool final) override final - { - } - - ///////////////////////////////////////////////// - - virtual void handleBody(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, - size_t total) override final - { - if (_onRequest) - { - _contentLength = total; - - if (total > 0 && request->_tempObject == NULL && total < _maxContentLength) - { - request->_tempObject = malloc(total); - } - - if (request->_tempObject != NULL) - { - memcpy((uint8_t*)(request->_tempObject) + index, data, len); - } - } - } - - ///////////////////////////////////////////////// - - virtual bool isRequestHandlerTrivial() override final - { - return _onRequest ? false : true; - } -}; - -#endif - diff --git a/lib/AsyncWebServer_ESP32_W5500/src/AsyncWebServer_ESP32_W5500.cpp b/lib/AsyncWebServer_ESP32_W5500/src/AsyncWebServer_ESP32_W5500.cpp deleted file mode 100644 index 67c7bf7..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/AsyncWebServer_ESP32_W5500.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/**************************************************************************************************************************** - AsyncWebServer_ESP32_W5500.cpp - Dead simple Ethernet AsyncWebServer. - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - - Original author: Hristo Gochkov - - Copyright (c) 2016 Hristo Gochkov. All rights reserved. - - This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License along with this library; - if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Version: 1.6.4 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2 - 1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples - 1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error - *****************************************************************************************************************************/ - -#include "AsyncWebServer_ESP32_W5500.h" - -////////////////////////////////////////////////////////////// - -bool ESP32_W5500_eth_connected = false; - -void ESP32_W5500_onEvent() -{ - WiFi.onEvent(ESP32_W5500_event); -} - -void ESP32_W5500_waitForConnect() -{ - while (!ESP32_W5500_eth_connected) - delay(100); -} - -bool ESP32_W5500_isConnected() -{ - return ESP32_W5500_eth_connected; -} - -void ESP32_W5500_event(WiFiEvent_t event) -{ - switch (event) - { - //#if USING_CORE_ESP32_CORE_V200_PLUS -#if ( ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 2) ) && ( ARDUINO_ESP32_GIT_VER != 0x46d5afb1 ) ) - // For breaking core v2.0.0 - // Why so strange to define a breaking enum arduino_event_id_t in WiFiGeneric.h - // compared to the old system_event_id_t, now in tools/sdk/esp32/include/esp_event/include/esp_event_legacy.h - // You can preserve the old enum order and just adding new items to do no harm - case ARDUINO_EVENT_ETH_START: - AWS_LOG(F("\nETH Started")); - //set eth hostname here - ETH.setHostname("ESP32_W5500"); - break; - - case ARDUINO_EVENT_ETH_CONNECTED: - AWS_LOG(F("ETH Connected")); - break; - - case ARDUINO_EVENT_ETH_GOT_IP: - if (!ESP32_W5500_eth_connected) - { - AWS_LOG3(F("ETH MAC: "), ETH.macAddress(), F(", IPv4: "), ETH.localIP()); - - if (ETH.fullDuplex()) - { - AWS_LOG0(F("FULL_DUPLEX, ")); - } - else - { - AWS_LOG0(F("HALF_DUPLEX, ")); - } - - AWS_LOG1(ETH.linkSpeed(), F("Mbps")); - - ESP32_W5500_eth_connected = true; - } - - break; - - case ARDUINO_EVENT_ETH_DISCONNECTED: - AWS_LOG("ETH Disconnected"); - ESP32_W5500_eth_connected = false; - break; - - case ARDUINO_EVENT_ETH_STOP: - AWS_LOG("\nETH Stopped"); - ESP32_W5500_eth_connected = false; - break; - -#else - - // For old core v1.0.6- - // Core v2.0.0 defines a stupid enum arduino_event_id_t, breaking any code for ESP32_W5500 written for previous core - // Why so strange to define a breaking enum arduino_event_id_t in WiFiGeneric.h - // compared to the old system_event_id_t, now in tools/sdk/esp32/include/esp_event/include/esp_event_legacy.h - // You can preserve the old enum order and just adding new items to do no harm - case SYSTEM_EVENT_ETH_START: - AWS_LOG(F("\nETH Started")); - //set eth hostname here - ETH.setHostname("ESP32_W5500"); - break; - - case SYSTEM_EVENT_ETH_CONNECTED: - AWS_LOG(F("ETH Connected")); - break; - - case SYSTEM_EVENT_ETH_GOT_IP: - if (!ESP32_W5500_eth_connected) - { - AWS_LOG3(F("ETH MAC: "), ETH.macAddress(), F(", IPv4: "), ETH.localIP()); - - if (ETH.fullDuplex()) - { - AWS_LOG0(F("FULL_DUPLEX, ")); - } - else - { - AWS_LOG0(F("HALF_DUPLEX, ")); - } - - AWS_LOG1(ETH.linkSpeed(), F("Mbps")); - - ESP32_W5500_eth_connected = true; - } - - break; - - case SYSTEM_EVENT_ETH_DISCONNECTED: - AWS_LOG("ETH Disconnected"); - ESP32_W5500_eth_connected = false; - break; - - case SYSTEM_EVENT_ETH_STOP: - AWS_LOG("\nETH Stopped"); - ESP32_W5500_eth_connected = false; - break; -#endif - - default: - break; - } -} - - diff --git a/lib/AsyncWebServer_ESP32_W5500/src/AsyncWebServer_ESP32_W5500.h b/lib/AsyncWebServer_ESP32_W5500/src/AsyncWebServer_ESP32_W5500.h deleted file mode 100644 index 9703341..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/AsyncWebServer_ESP32_W5500.h +++ /dev/null @@ -1,938 +0,0 @@ -/**************************************************************************************************************************** - AsyncWebServer_ESP32_W5500.h - Dead simple Ethernet AsyncWebServer. - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - - Original author: Hristo Gochkov - - Copyright (c) 2016 Hristo Gochkov. All rights reserved. - - This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License along with this library; - if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Version: 1.6.4 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2 - 1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples - 1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error - *****************************************************************************************************************************/ - -#ifndef _AsyncWebServer_ESP32_W5500_H_ -#define _AsyncWebServer_ESP32_W5500_H_ - -///////////////////////////////////////////////// - -#if ESP32 - - #if (_ASYNC_WEBSERVER_LOGLEVEL_ > 3 ) - #warning Using ESP32 architecture for WebServer_ESP32_W5500 - #endif - -#else - #error This code is designed for ESP32_W5500 to run on ESP32 platform! Please check your Tools->Board setting. -#endif - -///////////////////////////////////////////////// - -#if ( ( defined(ESP_ARDUINO_VERSION_MAJOR) && (ESP_ARDUINO_VERSION_MAJOR >= 2) ) && ( ARDUINO_ESP32_GIT_VER != 0x46d5afb1 ) ) - #define USING_CORE_ESP32_CORE_V200_PLUS true - - #if (_ASYNC_WEBSERVER_LOGLEVEL_ > 3 ) - #warning Using code for ESP32 core v2.0.0+ in AsyncWebServer_ESP32_W5500.h - #endif - - #define ASYNC_WEBSERVER_ESP32_W5500_VERSION "AsyncWebServer_ESP32_W5500 v1.6.4 for core v2.0.0+" -#else - - #if (_ASYNC_WEBSERVER_LOGLEVEL_ > 3 ) - #warning Using code for ESP32 core v1.0.6- in AsyncWebServer_ESP32_W5500.h - #endif - - #define ASYNC_WEBSERVER_ESP32_W5500_VERSION "AsyncWebServer_ESP32_W5500 v1.6.4 for core v1.0.6-" -#endif - -#define ASYNC_WEBSERVER_ESP32_W5500_VERSION_MAJOR 1 -#define ASYNC_WEBSERVER_ESP32_W5500_VERSION_MINOR 6 -#define ASYNC_WEBSERVER_ESP32_W5500_VERSION_PATCH 4 - -#define ASYNC_WEBSERVER_ESP32_W5500_VERSION_INT 1006004 - -///////////////////////////////////////////////// - -#ifndef ESP32_W5500_AWS_UNUSED - #define ESP32_W5500_AWS_UNUSED(x) (void)(x) -#endif - -///////////////////////////////////////////////// - -#include "Arduino.h" - -#include -#include "FS.h" - -#include "StringArray.h" - -////////////////////////////////////////////////////////////// -// ESP32_W5500 related code - -#include "AsyncWebServer_ESP32_W5500_Debug.h" - -#if 1 - - #include - #include // Introduce corresponding libraries - - #include "w5500/esp32_w5500.h" - - #include - - #if !defined(ETH_SPI_HOST) - #define ETH_SPI_HOST SPI3_HOST - #endif - - #if !defined(SPI_CLOCK_MHZ) - // Using 25MHz for W5500, 14MHz for W5100 - #define SPI_CLOCK_MHZ 25 - #endif - - #if !defined(INT_GPIO) - #define INT_GPIO 4 - #endif - - #if !defined(MISO_GPIO) - #define MISO_GPIO 19 - #endif - - #if !defined(MOSI_GPIO) - #define MOSI_GPIO 23 - #endif - - #if !defined(SCK_GPIO) - #define SCK_GPIO 18 - #endif - - #if !defined(CS_GPIO) - #define CS_GPIO 5 - #endif - - #ifndef SHIELD_TYPE - #define SHIELD_TYPE "ESP32_W5500" - #endif - - - -#else - - //#include - - -#endif - -extern bool ESP32_W5500_eth_connected; - -extern void ESP32_W5500_onEvent(); - -extern void ESP32_W5500_waitForConnect(); - -extern bool ESP32_W5500_isConnected(); - -extern void ESP32_W5500_event(WiFiEvent_t event); - -////////////////////////////////////////////////////////////// - -#include - -#ifdef ASYNCWEBSERVER_REGEX - #define ASYNCWEBSERVER_REGEX_ATTRIBUTE -#else - #define ASYNCWEBSERVER_REGEX_ATTRIBUTE __attribute__((warning("ASYNCWEBSERVER_REGEX not defined"))) -#endif - -#define DEBUGF(...) //Serial.printf(__VA_ARGS__) - -class AsyncWebServer; -class AsyncWebServerRequest; -class AsyncWebServerResponse; -class AsyncWebHeader; -class AsyncWebParameter; -class AsyncWebRewrite; -class AsyncWebHandler; -class AsyncStaticWebHandler; -class AsyncCallbackWebHandler; -class AsyncResponseStream; - -///////////////////////////////////////////////// - -#ifndef WEBSERVER_H - -typedef enum -{ - HTTP_GET = 0b00000001, - HTTP_POST = 0b00000010, - HTTP_DELETE = 0b00000100, - HTTP_PUT = 0b00001000, - HTTP_PATCH = 0b00010000, - HTTP_HEAD = 0b00100000, - HTTP_OPTIONS = 0b01000000, - HTTP_ANY = 0b01111111, -} WebRequestMethod; - -#endif - -//if this value is returned when asked for data, packet will not be sent and you will be asked for data again -#define RESPONSE_TRY_AGAIN 0xFFFFFFFF - -typedef uint8_t WebRequestMethodComposite; -typedef std::function ArDisconnectHandler; - -///////////////////////////////////////////////// - -/* - PARAMETER :: Chainable object to hold GET/POST and FILE parameters - * */ - -class AsyncWebParameter -{ - private: - String _name; - String _value; - size_t _size; - bool _isForm; - bool _isFile; - - public: - - AsyncWebParameter(const String& name, const String& value, bool form = false, bool file = false, - size_t size = 0): _name(name), _value(value), _size(size), _isForm(form), _isFile(file) {} - - ///////////////////////////////////////////////// - - inline const String& name() const - { - return _name; - } - - ///////////////////////////////////////////////// - - inline const String& value() const - { - return _value; - } - - ///////////////////////////////////////////////// - - inline size_t size() const - { - return _size; - } - - ///////////////////////////////////////////////// - - inline bool isPost() const - { - return _isForm; - } - - ///////////////////////////////////////////////// - - inline bool isFile() const - { - return _isFile; - } - - ///////////////////////////////////////////////// - -}; - -///////////////////////////////////////////////// - -/* - HEADER :: Chainable object to hold the headers - * */ - -class AsyncWebHeader -{ - private: - String _name; - String _value; - - public: - AsyncWebHeader(const String& name, const String& value): _name(name), _value(value) {} - - ///////////////////////////////////////////////// - - AsyncWebHeader(const String& data): _name(), _value() - { - if (!data) - return; - - int index = data.indexOf(':'); - - if (index < 0) - return; - - _name = data.substring(0, index); - _value = data.substring(index + 2); - } - - ///////////////////////////////////////////////// - - ~AsyncWebHeader() {} - - ///////////////////////////////////////////////// - - inline const String& name() const - { - return _name; - } - - ///////////////////////////////////////////////// - - inline const String& value() const - { - return _value; - } - - ///////////////////////////////////////////////// - - inline String toString() const - { - return String(_name + ": " + _value + "\r\n"); - } - - ///////////////////////////////////////////////// - -}; - -///////////////////////////////////////////////// - -/* - REQUEST :: Each incoming Client is wrapped inside a Request and both live together until disconnect - * */ - -typedef enum -{ - RCT_NOT_USED = -1, - RCT_DEFAULT = 0, - RCT_HTTP, - RCT_WS, - RCT_EVENT, - RCT_MAX -} RequestedConnectionType; - -typedef std::function AwsResponseFiller; -typedef std::function AwsTemplateProcessor; - -///////////////////////////////////////////////// - -class AsyncWebServerRequest -{ - using File = fs::File; - using FS = fs::FS; - friend class AsyncWebServer; - friend class AsyncCallbackWebHandler; - - private: - AsyncClient* _client; - AsyncWebServer* _server; - AsyncWebHandler* _handler; - AsyncWebServerResponse* _response; - StringArray _interestingHeaders; - ArDisconnectHandler _onDisconnectfn; - - String _temp; - uint8_t _parseState; - - uint8_t _version; - WebRequestMethodComposite _method; - String _url; - String _host; - String _contentType; - String _boundary; - String _authorization; - RequestedConnectionType _reqconntype; - void _removeNotInterestingHeaders(); - bool _isDigest; - bool _isMultipart; - bool _isPlainPost; - bool _expectingContinue; - size_t _contentLength; - size_t _parsedLength; - - LinkedList _headers; - LinkedList _params; - LinkedList _pathParams; - - uint8_t _multiParseState; - uint8_t _boundaryPosition; - size_t _itemStartIndex; - size_t _itemSize; - String _itemName; - String _itemFilename; - String _itemType; - String _itemValue; - uint8_t *_itemBuffer; - size_t _itemBufferIndex; - bool _itemIsFile; - - void _onPoll(); - void _onAck(size_t len, uint32_t time); - void _onError(int8_t error); - void _onTimeout(uint32_t time); - void _onDisconnect(); - void _onData(void *buf, size_t len); - - void _addParam(AsyncWebParameter*); - void _addPathParam(const char *param); - - bool _parseReqHead(); - bool _parseReqHeader(); - void _parseLine(); - void _parsePlainPostChar(uint8_t data); - void _parseMultipartPostByte(uint8_t data, bool last); - void _addGetParams(const String& params); - - void _handleUploadStart(); - void _handleUploadByte(uint8_t data, bool last); - void _handleUploadEnd(); - - public: - File _tempFile; - void *_tempObject; - - AsyncWebServerRequest(AsyncWebServer*, AsyncClient*); - ~AsyncWebServerRequest(); - - ///////////////////////////////////////////////// - - inline AsyncClient* client() - { - return _client; - } - - ///////////////////////////////////////////////// - - inline uint8_t version() const - { - return _version; - } - - ///////////////////////////////////////////////// - - inline WebRequestMethodComposite method() const - { - return _method; - } - - ///////////////////////////////////////////////// - - inline const String& url() const - { - return _url; - } - - ///////////////////////////////////////////////// - - inline const String& host() const - { - return _host; - } - - ///////////////////////////////////////////////// - - inline const String& contentType() const - { - return _contentType; - } - - ///////////////////////////////////////////////// - - inline size_t contentLength() const - { - return _contentLength; - } - - ///////////////////////////////////////////////// - - inline bool multipart() const - { - return _isMultipart; - } - - ///////////////////////////////////////////////// - - const char * methodToString() const; - const char * requestedConnTypeToString() const; - - ///////////////////////////////////////////////// - - inline RequestedConnectionType requestedConnType() const - { - return _reqconntype; - } - - ///////////////////////////////////////////////// - - bool isExpectedRequestedConnType(RequestedConnectionType erct1, RequestedConnectionType erct2 = RCT_NOT_USED, - RequestedConnectionType erct3 = RCT_NOT_USED); - void onDisconnect (ArDisconnectHandler fn); - - //hash is the string representation of: - // base64(user:pass) for basic or - // user:realm:md5(user:realm:pass) for digest - bool authenticate(const char * hash); - bool authenticate(const char * username, const char * password, const char * realm = NULL, bool passwordIsHash = false); - void requestAuthentication(const char * realm = NULL, bool isDigest = true); - - ///////////////////////////////////////////////// - - inline void setHandler(AsyncWebHandler *handler) - { - _handler = handler; - } - - ///////////////////////////////////////////////// - - void addInterestingHeader(const String& name); - - void redirect(const String& url); - - void send(AsyncWebServerResponse *response); - void send(int code, const String& contentType = String(), const String& content = String()); - - void send(int code, const String& contentType, const char *content, bool nonDetructiveSend = true); // RSMOD - - void send(FS &fs, const String& path, const String& contentType = String(), bool download = false, - AwsTemplateProcessor callback = nullptr); - void send(File content, const String& path, const String& contentType = String(), bool download = false, - AwsTemplateProcessor callback = nullptr); - void send(Stream &stream, const String& contentType, size_t len, AwsTemplateProcessor callback = nullptr); - void send(const String& contentType, size_t len, AwsResponseFiller callback, - AwsTemplateProcessor templateCallback = nullptr); - - void sendChunked(const String& contentType, AwsResponseFiller callback, - AwsTemplateProcessor templateCallback = nullptr); - - void send_P(int code, const String& contentType, const uint8_t * content, size_t len, - AwsTemplateProcessor callback = nullptr); - void send_P(int code, const String& contentType, PGM_P content, AwsTemplateProcessor callback = nullptr); - - AsyncWebServerResponse *beginResponse(int code, const String& contentType = String(), const String& content = String()); - - AsyncWebServerResponse *beginResponse(int code, const String& contentType, const char * content = nullptr); // RSMOD - - // KH add - AsyncWebServerResponse *beginResponse(int code, const String& contentType, const uint8_t * content, size_t len, - AwsTemplateProcessor callback = nullptr); - ////// - - - AsyncWebServerResponse *beginResponse(FS &fs, const String& path, const String& contentType = String(), - bool download = false, - AwsTemplateProcessor callback = nullptr); - AsyncWebServerResponse *beginResponse(File content, const String& path, const String& contentType = String(), - bool download = false, - AwsTemplateProcessor callback = nullptr); - AsyncWebServerResponse *beginResponse(Stream &stream, const String& contentType, size_t len, - AwsTemplateProcessor callback = nullptr); - AsyncWebServerResponse *beginResponse(const String& contentType, size_t len, AwsResponseFiller callback, - AwsTemplateProcessor templateCallback = nullptr); - - AsyncWebServerResponse *beginChunkedResponse(const String& contentType, AwsResponseFiller callback, - AwsTemplateProcessor templateCallback = nullptr); - AsyncResponseStream *beginResponseStream(const String& contentType, size_t bufferSize = 1460); - - AsyncWebServerResponse *beginResponse_P(int code, const String& contentType, const uint8_t * content, size_t len, - AwsTemplateProcessor callback = nullptr); - AsyncWebServerResponse *beginResponse_P(int code, const String& contentType, PGM_P content, - AwsTemplateProcessor callback = nullptr); - - size_t headers() const; // get header count - bool hasHeader(const String& name) const; // check if header exists - bool hasHeader(const __FlashStringHelper * data) const; // check if header exists - - AsyncWebHeader* getHeader(const String& name) const; - AsyncWebHeader* getHeader(const __FlashStringHelper * data) const; - AsyncWebHeader* getHeader(size_t num) const; - - size_t params() const; // get arguments count - bool hasParam(const String& name, bool post = false, bool file = false) const; - bool hasParam(const __FlashStringHelper * data, bool post = false, bool file = false) const; - - AsyncWebParameter* getParam(const String& name, bool post = false, bool file = false) const; - AsyncWebParameter* getParam(const __FlashStringHelper * data, bool post, bool file) const; - AsyncWebParameter* getParam(size_t num) const; - - ///////////////////////////////////////////////// - - inline size_t args() const - { - return params(); // get arguments count - } - - ///////////////////////////////////////////////// - - const String& arg(const String& name) const; // get request argument value by name - const String& arg(const __FlashStringHelper * data) const; // get request argument value by F(name) - const String& arg(size_t i) const; // get request argument value by number - const String& argName(size_t i) const; // get request argument name by number - bool hasArg(const char* name) const; // check if argument exists - bool hasArg(const __FlashStringHelper * data) const; // check if F(argument) exists - - const String& ASYNCWEBSERVER_REGEX_ATTRIBUTE pathArg(size_t i) const; - - const String& header(const char* name) const;// get request header value by name - const String& header(const __FlashStringHelper * data) const;// get request header value by F(name) - const String& header(size_t i) const; // get request header value by number - const String& headerName(size_t i) const; // get request header name by number - String urlDecode(const String& text) const; -}; - -///////////////////////////////////////////////// - -/* - FILTER :: Callback to filter AsyncWebRewrite and AsyncWebHandler (done by the Server) - * */ - -typedef std::function ArRequestFilterFunction; - -bool ON_STA_FILTER(AsyncWebServerRequest *request); - -bool ON_AP_FILTER(AsyncWebServerRequest *request); - -///////////////////////////////////////////////// - -/* - REWRITE :: One instance can be handle any Request (done by the Server) - * */ - -class AsyncWebRewrite -{ - protected: - String _from; - String _toUrl; - String _params; - ArRequestFilterFunction _filter; - - public: - - ///////////////////////////////////////////////// - - AsyncWebRewrite(const char* from, const char* to): _from(from), _toUrl(to), _params(String()), _filter(NULL) - { - int index = _toUrl.indexOf('?'); - - if (index > 0) - { - _params = _toUrl.substring(index + 1); - _toUrl = _toUrl.substring(0, index); - } - } - - ///////////////////////////////////////////////// - - virtual ~AsyncWebRewrite() {} - - ///////////////////////////////////////////////// - - inline AsyncWebRewrite& setFilter(ArRequestFilterFunction fn) - { - _filter = fn; - return *this; - } - - ///////////////////////////////////////////////// - - inline bool filter(AsyncWebServerRequest *request) const - { - return _filter == NULL || _filter(request); - } - - ///////////////////////////////////////////////// - - inline const String& from() const - { - return _from; - } - - ///////////////////////////////////////////////// - - inline const String& toUrl() const - { - return _toUrl; - } - - ///////////////////////////////////////////////// - - inline const String& params() const - { - return _params; - } - - ///////////////////////////////////////////////// - - virtual bool match(AsyncWebServerRequest *request) - { - return from() == request->url() && filter(request); - } -}; - -///////////////////////////////////////////////// - -/* - HANDLER :: One instance can be attached to any Request (done by the Server) - * */ - -class AsyncWebHandler -{ - protected: - ArRequestFilterFunction _filter; - String _username; - String _password; - - public: - AsyncWebHandler(): _username(""), _password("") {} - - ///////////////////////////////////////////////// - - inline AsyncWebHandler& setFilter(ArRequestFilterFunction fn) - { - _filter = fn; - return *this; - } - - ///////////////////////////////////////////////// - - inline AsyncWebHandler& setAuthentication(const char *username, const char *password) - { - _username = String(username); - _password = String(password); - return *this; - }; - - ///////////////////////////////////////////////// - - inline bool filter(AsyncWebServerRequest *request) - { - return _filter == NULL || _filter(request); - } - - ///////////////////////////////////////////////// - - virtual ~AsyncWebHandler() {} - - ///////////////////////////////////////////////// - - virtual bool canHandle(AsyncWebServerRequest *request __attribute__((unused))) - { - return false; - } - - ///////////////////////////////////////////////// - - virtual void handleRequest(AsyncWebServerRequest *request __attribute__((unused))) {} - virtual void handleUpload(AsyncWebServerRequest *request __attribute__((unused)), - const String& filename __attribute__((unused)), - size_t index __attribute__((unused)), uint8_t *data __attribute__((unused)), size_t len __attribute__((unused)), - bool final __attribute__((unused))) {} - virtual void handleBody(AsyncWebServerRequest *request __attribute__((unused)), uint8_t *data __attribute__((unused)), - size_t len __attribute__((unused)), size_t index __attribute__((unused)), size_t total __attribute__((unused))) {} - - ///////////////////////////////////////////////// - - virtual bool isRequestHandlerTrivial() - { - return true; - } -}; - -///////////////////////////////////////////////// - -/* - RESPONSE :: One instance is created for each Request (attached by the Handler) - * */ - -typedef enum -{ - RESPONSE_SETUP, - RESPONSE_HEADERS, - RESPONSE_CONTENT, - RESPONSE_WAIT_ACK, - RESPONSE_END, - RESPONSE_FAILED -} WebResponseState; - -///////////////////////////////////////////////// - -class AsyncWebServerResponse -{ - protected: - int _code; - LinkedList _headers; - String _contentType; - size_t _contentLength; - bool _sendContentLength; - bool _chunked; - size_t _headLength; - size_t _sentLength; - size_t _ackedLength; - size_t _writtenLength; - WebResponseState _state; - const char* _responseCodeToString(int code); - - public: - AsyncWebServerResponse(); - virtual ~AsyncWebServerResponse(); - virtual void setCode(int code); - virtual void setContentLength(size_t len); - virtual void setContentType(const String& type); - virtual void addHeader(const String& name, const String& value); - virtual String _assembleHead(uint8_t version); - virtual bool _started() const; - virtual bool _finished() const; - virtual bool _failed() const; - virtual bool _sourceValid() const; - virtual void _respond(AsyncWebServerRequest *request); - virtual size_t _ack(AsyncWebServerRequest *request, size_t len, uint32_t time); -}; - -///////////////////////////////////////////////// - -/* - SERVER :: One instance - * */ - -typedef std::function ArRequestHandlerFunction; -typedef std::function -ArUploadHandlerFunction; -typedef std::function -ArBodyHandlerFunction; - -///////////////////////////////////////////////// - -class AsyncWebServer -{ - protected: - AsyncServer _server; - LinkedList _rewrites; - LinkedList _handlers; - AsyncCallbackWebHandler* _catchAllHandler; - - public: - AsyncWebServer(uint16_t port); - ~AsyncWebServer(); - - void begin(); - void end(); - -#if ASYNC_TCP_SSL_ENABLED - void onSslFileRequest(AcSSlFileHandler cb, void* arg); - void beginSecure(const char *cert, const char *private_key_file, const char *password); -#endif - - AsyncWebRewrite& addRewrite(AsyncWebRewrite* rewrite); - bool removeRewrite(AsyncWebRewrite* rewrite); - AsyncWebRewrite& rewrite(const char* from, const char* to); - - AsyncWebHandler& addHandler(AsyncWebHandler* handler); - bool removeHandler(AsyncWebHandler* handler); - - AsyncCallbackWebHandler& on(const char* uri, ArRequestHandlerFunction onRequest); - AsyncCallbackWebHandler& on(const char* uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest); - AsyncCallbackWebHandler& on(const char* uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest, - ArUploadHandlerFunction onUpload); - AsyncCallbackWebHandler& on(const char* uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest, - ArUploadHandlerFunction onUpload, ArBodyHandlerFunction onBody); - - AsyncStaticWebHandler& serveStatic(const char* uri, fs::FS& fs, const char* path, const char* cache_control = NULL); - - void onNotFound(ArRequestHandlerFunction fn); //called when handler is not assigned - void onFileUpload(ArUploadHandlerFunction fn); //handle file uploads - void onRequestBody(ArBodyHandlerFunction - fn); //handle posts with plain body content (JSON often transmitted this way as a request) - - void reset(); //remove all writers and handlers, with onNotFound/onFileUpload/onRequestBody - - void _handleDisconnect(AsyncWebServerRequest *request); - void _attachHandler(AsyncWebServerRequest *request); - void _rewriteRequest(AsyncWebServerRequest *request); -}; - -///////////////////////////////////////////////// - -class DefaultHeaders -{ - using headers_t = LinkedList; - headers_t _headers; - - ///////////////////////////////////////////////// - - DefaultHeaders() - : _headers(headers_t([](AsyncWebHeader * h) - { - delete h; - })) - {} - - ///////////////////////////////////////////////// - - public: - using ConstIterator = headers_t::ConstIterator; - - ///////////////////////////////////////////////// - - void addHeader(const String& name, const String& value) - { - _headers.add(new AsyncWebHeader(name, value)); - } - - ///////////////////////////////////////////////// - - inline ConstIterator begin() const - { - return _headers.begin(); - } - - ///////////////////////////////////////////////// - - inline ConstIterator end() const - { - return _headers.end(); - } - - ///////////////////////////////////////////////// - - DefaultHeaders(DefaultHeaders const &) = delete; - DefaultHeaders &operator=(DefaultHeaders const &) = delete; - - ///////////////////////////////////////////////// - - static DefaultHeaders &Instance() - { - static DefaultHeaders instance; - return instance; - } -}; - -///////////////////////////////////////////////// - -#include "WebResponseImpl.h" -#include "WebHandlerImpl.h" -#include "AsyncWebSocket.h" -#include "AsyncEventSource.h" - -#endif /* _AsyncWebServer_ESP32_W5500_H_ */ diff --git a/lib/AsyncWebServer_ESP32_W5500/src/AsyncWebServer_ESP32_W5500_Debug.h b/lib/AsyncWebServer_ESP32_W5500/src/AsyncWebServer_ESP32_W5500_Debug.h deleted file mode 100644 index fb12bfb..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/AsyncWebServer_ESP32_W5500_Debug.h +++ /dev/null @@ -1,115 +0,0 @@ -/**************************************************************************************************************************** - AsyncWebServer_ESP32_W5500_Debug.h - Dead simple Ethernet AsyncWebServer. - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - - Original author: Hristo Gochkov - - Copyright (c) 2016 Hristo Gochkov. All rights reserved. - - This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License along with this library; - if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Version: 1.6.4 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2 - 1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples - 1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error - *****************************************************************************************************************************/ - -#pragma once - -#ifndef ASYNC_WEBSERVER_ESP32_W5500_DEBUG_H -#define ASYNC_WEBSERVER_ESP32_W5500_DEBUG_H - -#include - -#ifdef DEBUG_ASYNC_WEBSERVER_PORT - #define AWS_DEBUG_OUTPUT DEBUG_ASYNC_WEBSERVER_PORT -#else - #define AWS_DEBUG_OUTPUT Serial -#endif - -// Change _ASYNC_WEBSERVER_LOGLEVEL_ to set tracing and logging verbosity -// 0: DISABLED: no logging -// 1: ERROR: errors -// 2: WARN: errors and warnings -// 3: INFO: errors, warnings and informational (default) -// 4: DEBUG: errors, warnings, informational and debug - -#ifndef _ASYNC_WEBSERVER_LOGLEVEL_ - #define _ASYNC_WEBSERVER_LOGLEVEL_ 1 -#endif - -const char AWS_MARK[] = "[AWS] "; -const char AWS_SPACE[] = " "; -const char AWS_LINE[] = "========================================\n"; - -#define AWS_PRINT_MARK AWS_PRINT(AWS_MARK) -#define AWS_PRINT_SP AWS_PRINT(AWS_SPACE) -#define AWS_PRINT_LINE AWS_PRINT(AWS_LINE) - -#define AWS_PRINT AWS_DEBUG_OUTPUT.print -#define AWS_PRINTLN AWS_DEBUG_OUTPUT.println - -/////////////////////////////////////// - -#define AWS_LOG(x) { AWS_PRINTLN(x); } -#define AWS_LOG0(x) { AWS_PRINT(x); } -#define AWS_LOG1(x,y) { AWS_PRINT(x); AWS_PRINTLN(y); } -#define AWS_LOG2(x,y,z) { AWS_PRINT(x); AWS_PRINT(y); AWS_PRINTLN(z); } -#define AWS_LOG3(x,y,z,w) { AWS_PRINT(x); AWS_PRINT(y); AWS_PRINT(z); AWS_PRINTLN(w); } - -/////////////////////////////////////// - -#define AWS_LOGERROR(x) if(_ASYNC_WEBSERVER_LOGLEVEL_>0) { AWS_PRINT_MARK; AWS_PRINTLN(x); } -#define AWS_LOGERROR_LINE(x) if(_ASYNC_WEBSERVER_LOGLEVEL_>0) { AWS_PRINT_MARK; AWS_PRINTLN(x); AWS_PRINT_LINE; } -#define AWS_LOGERROR0(x) if(_ASYNC_WEBSERVER_LOGLEVEL_>0) { AWS_PRINT(x); } -#define AWS_LOGERROR1(x,y) if(_ASYNC_WEBSERVER_LOGLEVEL_>0) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINTLN(y); } -#define AWS_LOGERROR2(x,y,z) if(_ASYNC_WEBSERVER_LOGLEVEL_>0) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINT(y); AWS_PRINT_SP; AWS_PRINTLN(z); } -#define AWS_LOGERROR3(x,y,z,w) if(_ASYNC_WEBSERVER_LOGLEVEL_>0) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINT(y); AWS_PRINT_SP; AWS_PRINT(z); AWS_PRINT_SP; AWS_PRINTLN(w); } - -/////////////////////////////////////// - -#define AWS_LOGWARN(x) if(_ASYNC_WEBSERVER_LOGLEVEL_>1) { AWS_PRINT_MARK; AWS_PRINTLN(x); } -#define AWS_LOGWARN_LINE(x) if(_ASYNC_WEBSERVER_LOGLEVEL_>1) { AWS_PRINT_MARK; AWS_PRINTLN(x); AWS_PRINT_LINE; } -#define AWS_LOGWARN0(x) if(_ASYNC_WEBSERVER_LOGLEVEL_>1) { AWS_PRINT(x); } -#define AWS_LOGWARN1(x,y) if(_ASYNC_WEBSERVER_LOGLEVEL_>1) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINTLN(y); } -#define AWS_LOGWARN2(x,y,z) if(_ASYNC_WEBSERVER_LOGLEVEL_>1) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINT(y); AWS_PRINT_SP; AWS_PRINTLN(z); } -#define AWS_LOGWARN3(x,y,z,w) if(_ASYNC_WEBSERVER_LOGLEVEL_>1) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINT(y); AWS_PRINT_SP; AWS_PRINT(z); AWS_PRINT_SP; AWS_PRINTLN(w); } - -/////////////////////////////////////// - -#define AWS_LOGINFO(x) if(_ASYNC_WEBSERVER_LOGLEVEL_>2) { AWS_PRINT_MARK; AWS_PRINTLN(x); } -#define AWS_LOGINFO_LINE(x) if(_ASYNC_WEBSERVER_LOGLEVEL_>2) { AWS_PRINT_MARK; AWS_PRINTLN(x); AWS_PRINT_LINE; } -#define AWS_LOGINFO0(x) if(_ASYNC_WEBSERVER_LOGLEVEL_>2) { AWS_PRINT(x); } -#define AWS_LOGINFO1(x,y) if(_ASYNC_WEBSERVER_LOGLEVEL_>2) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINTLN(y); } -#define AWS_LOGINFO2(x,y,z) if(_ASYNC_WEBSERVER_LOGLEVEL_>2) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINT(y); AWS_PRINT_SP; AWS_PRINTLN(z); } -#define AWS_LOGINFO3(x,y,z,w) if(_ASYNC_WEBSERVER_LOGLEVEL_>2) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINT(y); AWS_PRINT_SP; AWS_PRINT(z); AWS_PRINT_SP; AWS_PRINTLN(w); } - -/////////////////////////////////////// - -#define AWS_LOGDEBUG(x) if(_ASYNC_WEBSERVER_LOGLEVEL_>3) { AWS_PRINT_MARK; AWS_PRINTLN(x); } -#define AWS_LOGDEBUG_LINE(x) if(_ASYNC_WEBSERVER_LOGLEVEL_>3) { AWS_PRINT_MARK; AWS_PRINTLN(x); AWS_PRINT_LINE; } -#define AWS_LOGDEBUG0(x) if(_ASYNC_WEBSERVER_LOGLEVEL_>3) { AWS_PRINT(x); } -#define AWS_LOGDEBUG1(x,y) if(_ASYNC_WEBSERVER_LOGLEVEL_>3) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINTLN(y); } -#define AWS_LOGDEBUG2(x,y,z) if(_ASYNC_WEBSERVER_LOGLEVEL_>3) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINT(y); AWS_PRINT_SP; AWS_PRINTLN(z); } -#define AWS_LOGDEBUG3(x,y,z,w) if(_ASYNC_WEBSERVER_LOGLEVEL_>3) { AWS_PRINT_MARK; AWS_PRINT(x); AWS_PRINT_SP; AWS_PRINT(y); AWS_PRINT_SP; AWS_PRINT(z); AWS_PRINT_SP; AWS_PRINTLN(w); } - -#endif // ASYNC_WEBSERVER_ESP32_W5500_DEBUG_H - - diff --git a/lib/AsyncWebServer_ESP32_W5500/src/AsyncWebSocket.cpp b/lib/AsyncWebServer_ESP32_W5500/src/AsyncWebSocket.cpp deleted file mode 100644 index 60204dc..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/AsyncWebSocket.cpp +++ /dev/null @@ -1,1929 +0,0 @@ -/**************************************************************************************************************************** - AsyncWebSocket.cpp - Dead simple Ethernet AsyncWebServer. - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - - Original author: Hristo Gochkov - - Copyright (c) 2016 Hristo Gochkov. All rights reserved. - - This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License along with this library; - if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Version: 1.6.4 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2 - 1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples - 1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error - *****************************************************************************************************************************/ - -#include "Arduino.h" -#include "AsyncWebSocket.h" - -#include - -#include "Crypto/sha1.h" -#include "Crypto/Hash.h" - -///////////////////////////////////////////////// - -#define MAX_PRINTF_LEN 64 - -///////////////////////////////////////////////// - -size_t webSocketSendFrameWindow(AsyncClient *client) -{ - if (!client->canSend()) - return 0; - - size_t space = client->space(); - - if (space < 9) - return 0; - - return space - 8; -} - -///////////////////////////////////////////////// - -size_t webSocketSendFrame(AsyncClient *client, bool final, uint8_t opcode, bool mask, uint8_t *data, size_t len) -{ - if (!client->canSend()) - return 0; - - size_t space = client->space(); - - if (space < 2) - return 0; - - uint8_t mbuf[4] = {0, 0, 0, 0}; - uint8_t headLen = 2; - - if (len && mask) - { - headLen += 4; - mbuf[0] = rand() % 0xFF; - mbuf[1] = rand() % 0xFF; - mbuf[2] = rand() % 0xFF; - mbuf[3] = rand() % 0xFF; - } - - if (len > 125) - headLen += 2; - - if (space < headLen) - return 0; - - space -= headLen; - - if (len > space) - len = space; - - uint8_t *buf = (uint8_t*)malloc(headLen); - - if (buf == NULL) - { - AWS_LOGDEBUG1(F("Error malloc for frame header (bytes):"), headLen); - return 0; - } - - buf[0] = opcode & 0x0F; - - if (final) - buf[0] |= 0x80; - - if (len < 126) - buf[1] = len & 0x7F; - else - { - buf[1] = 126; - buf[2] = (uint8_t)((len >> 8) & 0xFF); - buf[3] = (uint8_t)(len & 0xFF); - } - - if (len && mask) - { - buf[1] |= 0x80; - memcpy(buf + (headLen - 4), mbuf, 4); - } - - if (client->add((const char *)buf, headLen) != headLen) - { - AWS_LOGDEBUG1(F("Error adding header (bytes):"), headLen); - free(buf); - - return 0; - } - - free(buf); - - if (len) - { - if (len && mask) - { - size_t i; - - for (i = 0; i < len; i++) - data[i] = data[i] ^ mbuf[i % 4]; - } - - if (client->add((const char *)data, len) != len) - { - AWS_LOGDEBUG1(F("Error adding data (bytes):"), len); - return 0; - } - } - - if (!client->send()) - { - AWS_LOGDEBUG1(F("Error sending frame (bytes):"), headLen + len); - return 0; - } - - return len; -} - -///////////////////////////////////////////////// - -/* - AsyncWebSocketMessageBuffer -*/ - -AsyncWebSocketMessageBuffer::AsyncWebSocketMessageBuffer() - : _data(nullptr) - , _len(0) - , _lock(false) - , _count(0) -{ -} - -///////////////////////////////////////////////// - -AsyncWebSocketMessageBuffer::AsyncWebSocketMessageBuffer(uint8_t * data, size_t size) - : _data(nullptr) - , _len(size) - , _lock(false) - , _count(0) -{ - - if (!data) - { - return; - } - - _data = new uint8_t[_len + 1]; - - if (_data) - { - memcpy(_data, data, _len); - _data[_len] = 0; - } -} - -///////////////////////////////////////////////// - -AsyncWebSocketMessageBuffer::AsyncWebSocketMessageBuffer(size_t size) - : _data(nullptr) - , _len(size) - , _lock(false) - , _count(0) -{ - _data = new uint8_t[_len + 1]; - - if (_data) - { - _data[_len] = 0; - } -} - -///////////////////////////////////////////////// - -AsyncWebSocketMessageBuffer::AsyncWebSocketMessageBuffer(const AsyncWebSocketMessageBuffer & copy) - : _data(nullptr) - , _len(0) - , _lock(false) - , _count(0) -{ - _len = copy._len; - _lock = copy._lock; - _count = 0; - - if (_len) - { - _data = new uint8_t[_len + 1]; - _data[_len] = 0; - } - - if (_data) - { - memcpy(_data, copy._data, _len); - _data[_len] = 0; - } -} - -///////////////////////////////////////////////// - -AsyncWebSocketMessageBuffer::AsyncWebSocketMessageBuffer(AsyncWebSocketMessageBuffer && copy) - : _data(nullptr) - , _len(0) - , _lock(false) - , _count(0) -{ - _len = copy._len; - _lock = copy._lock; - _count = 0; - - if (copy._data) - { - _data = copy._data; - copy._data = nullptr; - } -} - -///////////////////////////////////////////////// - -AsyncWebSocketMessageBuffer::~AsyncWebSocketMessageBuffer() -{ - if (_data) - { - delete[] _data; - } -} - -///////////////////////////////////////////////// - -bool AsyncWebSocketMessageBuffer::reserve(size_t size) -{ - _len = size; - - if (_data) - { - delete[] _data; - _data = nullptr; - } - - _data = new uint8_t[_len + 1]; - - if (_data) - { - _data[_len] = 0; - return true; - } - else - { - return false; - } -} - -///////////////////////////////////////////////// -///////////////////////////////////////////////// - -/* - Control Frame -*/ - -class AsyncWebSocketControl -{ - private: - uint8_t _opcode; - uint8_t *_data; - size_t _len; - bool _mask; - bool _finished; - - public: - AsyncWebSocketControl(uint8_t opcode, uint8_t *data = NULL, size_t len = 0, bool mask = false) - : _opcode(opcode) - , _len(len) - , _mask(len && mask) - , _finished(false) - { - if (data == NULL) - _len = 0; - - if (_len) - { - if (_len > 125) - _len = 125; - - _data = (uint8_t*)malloc(_len); - - if (_data == NULL) - _len = 0; - else - memcpy(_data, data, len); - } - else - _data = NULL; - } - - virtual ~AsyncWebSocketControl() - { - if (_data != NULL) - free(_data); - } - - virtual bool finished() const - { - return _finished; - } - - uint8_t opcode() - { - return _opcode; - } - - uint8_t len() - { - return _len + 2; - } - - size_t send(AsyncClient *client) - { - _finished = true; - - return webSocketSendFrame(client, true, _opcode & 0x0F, _mask, _data, _len); - } -}; - -///////////////////////////////////////////////// -///////////////////////////////////////////////// - -/* - Basic Buffered Message -*/ - - -AsyncWebSocketBasicMessage::AsyncWebSocketBasicMessage(const char * data, size_t len, uint8_t opcode, bool mask) - : _len(len) - , _sent(0) - , _ack(0) - , _acked(0) -{ - _opcode = opcode & 0x07; - _mask = mask; - _data = (uint8_t*)malloc(_len + 1); - - if (_data == NULL) - { - _len = 0; - _status = WS_MSG_ERROR; - } - else - { - _status = WS_MSG_SENDING; - memcpy(_data, data, _len); - _data[_len] = 0; - } -} - -///////////////////////////////////////////////// - -AsyncWebSocketBasicMessage::AsyncWebSocketBasicMessage(uint8_t opcode, bool mask) - : _len(0) - , _sent(0) - , _ack(0) - , _acked(0) - , _data(NULL) -{ - _opcode = opcode & 0x07; - _mask = mask; - -} - -///////////////////////////////////////////////// - -AsyncWebSocketBasicMessage::~AsyncWebSocketBasicMessage() -{ - if (_data != NULL) - free(_data); -} - -///////////////////////////////////////////////// - -void AsyncWebSocketBasicMessage::ack(size_t len, uint32_t time) -{ - ESP32_W5500_AWS_UNUSED(time); - - _acked += len; - - if (_sent == _len && _acked == _ack) - { - _status = WS_MSG_SENT; - } -} - -///////////////////////////////////////////////// - -size_t AsyncWebSocketBasicMessage::send(AsyncClient *client) -{ - if (_status != WS_MSG_SENDING) - return 0; - - if (_acked < _ack) - { - return 0; - } - - if (_sent == _len) - { - if (_acked == _ack) - _status = WS_MSG_SENT; - - return 0; - } - - if (_sent > _len) - { - _status = WS_MSG_ERROR; - - return 0; - } - - size_t toSend = _len - _sent; - size_t window = webSocketSendFrameWindow(client); - - if (window < toSend) - { - toSend = window; - } - - _sent += toSend; - _ack += toSend + ((toSend < 126) ? 2 : 4) + (_mask * 4); - - bool final = (_sent == _len); - uint8_t* dPtr = (uint8_t*)(_data + (_sent - toSend)); - uint8_t opCode = (toSend && _sent == toSend) ? _opcode : (uint8_t)WS_CONTINUATION; - - size_t sent = webSocketSendFrame(client, final, opCode, _mask, dPtr, toSend); - _status = WS_MSG_SENDING; - - if (toSend && sent != toSend) - { - _sent -= (toSend - sent); - _ack -= (toSend - sent); - } - - return sent; -} - -///////////////////////////////////////////////// - -// bool AsyncWebSocketBasicMessage::reserve(size_t size) -//{ -// if (size) { -// _data = (uint8_t*)malloc(size +1); -// if (_data) { -// memset(_data, 0, size); -// _len = size; -// _status = WS_MSG_SENDING; -// return true; -// } -// } -// return false; -// } - -///////////////////////////////////////////////// -///////////////////////////////////////////////// - -/* - AsyncWebSocketMultiMessage Message -*/ - -AsyncWebSocketMultiMessage::AsyncWebSocketMultiMessage(AsyncWebSocketMessageBuffer * buffer, uint8_t opcode, bool mask) - : _len(0) - , _sent(0) - , _ack(0) - , _acked(0) - , _WSbuffer(nullptr) -{ - - _opcode = opcode & 0x07; - _mask = mask; - - if (buffer) - { - _WSbuffer = buffer; - - (*_WSbuffer)++; - _data = buffer->get(); - _len = buffer->length(); - _status = WS_MSG_SENDING; - - AWS_LOGDEBUG1("AWSMultiMessage: _len =", _len); - } - else - { - _status = WS_MSG_ERROR; - } -} - -///////////////////////////////////////////////// - -AsyncWebSocketMultiMessage::~AsyncWebSocketMultiMessage() -{ - if (_WSbuffer) - { - (*_WSbuffer)--; // decreases the counter. - } -} - -///////////////////////////////////////////////// - -void AsyncWebSocketMultiMessage::ack(size_t len, uint32_t time) -{ - ESP32_W5500_AWS_UNUSED(time); - - _acked += len; - - if (_sent >= _len && _acked >= _ack) - { - _status = WS_MSG_SENT; - } - - AWS_LOGDEBUG1("AWSMultiMessage::ack: len =", len); -} - -///////////////////////////////////////////////// - -size_t AsyncWebSocketMultiMessage::send(AsyncClient *client) -{ - if (_status != WS_MSG_SENDING) - return 0; - - if (_acked < _ack) - { - return 0; - } - - if (_sent == _len) - { - _status = WS_MSG_SENT; - - return 0; - } - - if (_sent > _len) - { - _status = WS_MSG_ERROR; - - AWS_LOGDEBUG3("AWSMultiMessage::send: Error _sent =", _sent, " > _len =", _len); - - return 0; - } - - size_t toSend = _len - _sent; - size_t window = webSocketSendFrameWindow(client); - - if (window < toSend) - { - toSend = window; - } - - _sent += toSend; - _ack += toSend + ((toSend < 126) ? 2 : 4) + (_mask * 4); - - AWS_LOGDEBUG3("AWSMultiMessage::send: Warning (_sent - toSend) =", _sent - toSend, " : toSend =", toSend); - - bool final = (_sent == _len); - uint8_t* dPtr = (uint8_t*)(_data + (_sent - toSend)); - uint8_t opCode = (toSend && _sent == toSend) ? _opcode : (uint8_t)WS_CONTINUATION; - - size_t sent = webSocketSendFrame(client, final, opCode, _mask, dPtr, toSend); - _status = WS_MSG_SENDING; - - if (toSend && sent != toSend) - { - AWS_LOGDEBUG3("AWSMultiMessage::send: Error toSend =", toSend, " != sent =", sent); - - _sent -= (toSend - sent); - _ack -= (toSend - sent); - } - - AWS_LOGDEBUG3("AWSMultiMessage::send: _sent =", _sent, " : sent =", sent); - - return sent; -} - -///////////////////////////////////////////////// -///////////////////////////////////////////////// - -/* - Async WebSocket Client -*/ -const char * AWSC_PING_PAYLOAD = "AsyncWebServer_WT32-PING"; -const size_t AWSC_PING_PAYLOAD_LEN = 22; - -///////////////////////////////////////////////// - -AsyncWebSocketClient::AsyncWebSocketClient(AsyncWebServerRequest *request, AsyncWebSocket *server) - : _controlQueue(LinkedList([](AsyncWebSocketControl * c) -{ - delete c; -})) -, _messageQueue(LinkedList([](AsyncWebSocketMessage *m) -{ - delete m; -})) -, _tempObject(NULL) -{ - _client = request->client(); - _server = server; - _clientId = _server->_getNextId(); - _status = WS_CONNECTED; - _pstate = 0; - _lastMessageTime = millis(); - _keepAlivePeriod = 0; - _client->setRxTimeout(0); - - _client->onError([](void *r, AsyncClient * c, int8_t error) - { - ESP32_W5500_AWS_UNUSED(c); - ((AsyncWebSocketClient*)(r))->_onError(error); - }, this); - - _client->onAck([](void *r, AsyncClient * c, size_t len, uint32_t time) - { - ESP32_W5500_AWS_UNUSED(c); - ((AsyncWebSocketClient*)(r))->_onAck(len, time); - }, this); - - _client->onDisconnect([](void *r, AsyncClient * c) - { - ((AsyncWebSocketClient*)(r))->_onDisconnect(); - delete c; - }, this); - - _client->onTimeout([](void *r, AsyncClient * c, uint32_t time) - { - ESP32_W5500_AWS_UNUSED(c); - ((AsyncWebSocketClient*)(r))->_onTimeout(time); - }, this); - - _client->onData([](void *r, AsyncClient * c, void *buf, size_t len) - { - ESP32_W5500_AWS_UNUSED(c); - ((AsyncWebSocketClient*)(r))->_onData(buf, len); - }, this); - - _client->onPoll([](void *r, AsyncClient * c) - { - ESP32_W5500_AWS_UNUSED(c); - ((AsyncWebSocketClient*)(r))->_onPoll(); - }, this); - - _server->_addClient(this); - _server->_handleEvent(this, WS_EVT_CONNECT, request, NULL, 0); - delete request; -} - -///////////////////////////////////////////////// - -AsyncWebSocketClient::~AsyncWebSocketClient() -{ - _messageQueue.free(); - _controlQueue.free(); - _server->_handleEvent(this, WS_EVT_DISCONNECT, NULL, NULL, 0); -} - -///////////////////////////////////////////////// - -void AsyncWebSocketClient::_onAck(size_t len, uint32_t time) -{ - _lastMessageTime = millis(); - - if (!_controlQueue.isEmpty()) - { - auto head = _controlQueue.front(); - - if (head->finished()) - { - len -= head->len(); - - if (_status == WS_DISCONNECTING && head->opcode() == WS_DISCONNECT) - { - _controlQueue.remove(head); - _status = WS_DISCONNECTED; - _client->close(true); - return; - } - - _controlQueue.remove(head); - } - } - - if (len && !_messageQueue.isEmpty()) - { - _messageQueue.front()->ack(len, time); - } - - _server->_cleanBuffers(); - _runQueue(); -} - -///////////////////////////////////////////////// - -void AsyncWebSocketClient::_onPoll() -{ - if (_client->canSend() && (!_controlQueue.isEmpty() || !_messageQueue.isEmpty())) - { - _runQueue(); - } - else if (_keepAlivePeriod > 0 && _controlQueue.isEmpty() && _messageQueue.isEmpty() - && (millis() - _lastMessageTime) >= _keepAlivePeriod) - { - ping((uint8_t *)AWSC_PING_PAYLOAD, AWSC_PING_PAYLOAD_LEN); - } -} - -///////////////////////////////////////////////// - -void AsyncWebSocketClient::_runQueue() -{ - while (!_messageQueue.isEmpty() && _messageQueue.front()->finished()) - { - _messageQueue.remove(_messageQueue.front()); - } - - if (!_controlQueue.isEmpty() && (_messageQueue.isEmpty() || _messageQueue.front()->betweenFrames()) && - webSocketSendFrameWindow(_client) > (size_t)(_controlQueue.front()->len() - 1)) - { - _controlQueue.front()->send(_client); - } - else if (!_messageQueue.isEmpty() && _messageQueue.front()->betweenFrames() && webSocketSendFrameWindow(_client)) - { - _messageQueue.front()->send(_client); - } -} - -///////////////////////////////////////////////// - -bool AsyncWebSocketClient::queueIsFull() -{ - if ((_messageQueue.length() >= WS_MAX_QUEUED_MESSAGES) || (_status != WS_CONNECTED) ) - return true; - - return false; -} - -///////////////////////////////////////////////// - -void AsyncWebSocketClient::_queueMessage(AsyncWebSocketMessage *dataMessage) -{ - if (dataMessage == NULL) - return; - - if (_status != WS_CONNECTED) - { - delete dataMessage; - return; - } - - if (_messageQueue.length() >= WS_MAX_QUEUED_MESSAGES) - { - AWS_LOGDEBUG("ERROR: Too many messages queued"); - - delete dataMessage; - } - else - { - _messageQueue.add(dataMessage); - } - - if (_client->canSend()) - _runQueue(); -} - -///////////////////////////////////////////////// - -void AsyncWebSocketClient::_queueControl(AsyncWebSocketControl *controlMessage) -{ - if (controlMessage == NULL) - return; - - _controlQueue.add(controlMessage); - - if (_client->canSend()) - _runQueue(); -} - -///////////////////////////////////////////////// - -void AsyncWebSocketClient::close(uint16_t code, const char * message) -{ - if (_status != WS_CONNECTED) - return; - - if (code) - { - uint8_t packetLen = 2; - - if (message != NULL) - { - size_t mlen = strlen(message); - - if (mlen > 123) - mlen = 123; - - packetLen += mlen; - } - - char * buf = (char*)malloc(packetLen); - - if (buf != NULL) - { - buf[0] = (uint8_t)(code >> 8); - buf[1] = (uint8_t)(code & 0xFF); - - if (message != NULL) - { - memcpy(buf + 2, message, packetLen - 2); - } - - _queueControl(new AsyncWebSocketControl(WS_DISCONNECT, (uint8_t*)buf, packetLen)); - free(buf); - - return; - } - } - - _queueControl(new AsyncWebSocketControl(WS_DISCONNECT)); -} - -///////////////////////////////////////////////// - -void AsyncWebSocketClient::ping(uint8_t *data, size_t len) -{ - if (_status == WS_CONNECTED) - _queueControl(new AsyncWebSocketControl(WS_PING, data, len)); -} - -///////////////////////////////////////////////// - -void AsyncWebSocketClient::_onError(int8_t) {} - -///////////////////////////////////////////////// - -void AsyncWebSocketClient::_onTimeout(uint32_t time) -{ - ESP32_W5500_AWS_UNUSED(time); - - _client->close(true); -} - -///////////////////////////////////////////////// - -void AsyncWebSocketClient::_onDisconnect() -{ - _client = NULL; - _server->_handleDisconnect(this); -} - -///////////////////////////////////////////////// - -void AsyncWebSocketClient::_onData(void *pbuf, size_t plen) -{ - _lastMessageTime = millis(); - uint8_t *data = (uint8_t*)pbuf; - - while (plen > 0) - { - if (!_pstate) - { - const uint8_t *fdata = data; - _pinfo.index = 0; - _pinfo.final = (fdata[0] & 0x80) != 0; - _pinfo.opcode = fdata[0] & 0x0F; - _pinfo.masked = (fdata[1] & 0x80) != 0; - _pinfo.len = fdata[1] & 0x7F; - data += 2; - plen -= 2; - - if (_pinfo.len == 126) - { - _pinfo.len = fdata[3] | (uint16_t)(fdata[2]) << 8; - data += 2; - plen -= 2; - } - else if (_pinfo.len == 127) - { - _pinfo.len = fdata[9] | (uint16_t)(fdata[8]) << 8 | (uint32_t)(fdata[7]) << 16 | (uint32_t)(fdata[6]) << 24 | - (uint64_t)(fdata[5]) << 32 | (uint64_t)(fdata[4]) << 40 | (uint64_t)(fdata[3]) << 48 | - (uint64_t)(fdata[2]) << 56; - data += 8; - plen -= 8; - } - - if (_pinfo.masked) - { - memcpy(_pinfo.mask, data, 4); - data += 4; - plen -= 4; - } - } - - const size_t datalen = std::min((size_t)(_pinfo.len - _pinfo.index), plen); - const auto datalast = data[datalen]; - - if (_pinfo.masked) - { - for (size_t i = 0; i < datalen; i++) - data[i] ^= _pinfo.mask[(_pinfo.index + i) % 4]; - } - - if ((datalen + _pinfo.index) < _pinfo.len) - { - _pstate = 1; - - if (_pinfo.index == 0) - { - if (_pinfo.opcode) - { - _pinfo.message_opcode = _pinfo.opcode; - _pinfo.num = 0; - } - else - _pinfo.num += 1; - } - - _server->_handleEvent(this, WS_EVT_DATA, (void *)&_pinfo, (uint8_t*)data, datalen); - - _pinfo.index += datalen; - } - else if ((datalen + _pinfo.index) == _pinfo.len) - { - _pstate = 0; - - if (_pinfo.opcode == WS_DISCONNECT) - { - if (datalen) - { - uint16_t reasonCode = (uint16_t)(data[0] << 8) + data[1]; - char * reasonString = (char*)(data + 2); - - if (reasonCode > 1001) - { - _server->_handleEvent(this, WS_EVT_ERROR, (void *)&reasonCode, (uint8_t*)reasonString, strlen(reasonString)); - } - } - - if (_status == WS_DISCONNECTING) - { - _status = WS_DISCONNECTED; - _client->close(true); - } - else - { - _status = WS_DISCONNECTING; - _client->ackLater(); - _queueControl(new AsyncWebSocketControl(WS_DISCONNECT, data, datalen)); - } - } - else if (_pinfo.opcode == WS_PING) - { - _queueControl(new AsyncWebSocketControl(WS_PONG, data, datalen)); - } - else if (_pinfo.opcode == WS_PONG) - { - if (datalen != AWSC_PING_PAYLOAD_LEN || memcmp(AWSC_PING_PAYLOAD, data, AWSC_PING_PAYLOAD_LEN) != 0) - _server->_handleEvent(this, WS_EVT_PONG, NULL, data, datalen); - } - else if (_pinfo.opcode < 8) - { - //continuation or text/binary frame - _server->_handleEvent(this, WS_EVT_DATA, (void *)&_pinfo, data, datalen); - } - } - else - { - AWS_LOGDEBUG1("AsyncWebSocketClient::_onData: frame error: len: ", datalen); - AWS_LOGDEBUG3("index:", _pinfo.index, ", total:", _pinfo.len); - - //what should we do? - break; - } - - // restore byte as _handleEvent may have added a null terminator i.e., data[len] = 0; - if (datalen > 0) - data[datalen] = datalast; - - data += datalen; - plen -= datalen; - } -} - -///////////////////////////////////////////////// - -size_t AsyncWebSocketClient::printf(const char *format, ...) -{ - va_list arg; - va_start(arg, format); - char* temp = new char[MAX_PRINTF_LEN]; - - if (!temp) - { - va_end(arg); - - return 0; - } - - char* buffer = temp; - size_t len = vsnprintf(temp, MAX_PRINTF_LEN, format, arg); - va_end(arg); - - if (len > (MAX_PRINTF_LEN - 1)) - { - buffer = new char[len + 1]; - - if (!buffer) - { - delete[] temp; - - return 0; - } - - va_start(arg, format); - vsnprintf(buffer, len + 1, format, arg); - va_end(arg); - } - - text(buffer, len); - - if (buffer != temp) - { - delete[] buffer; - } - - delete[] temp; - - return len; -} - -///////////////////////////////////////////////// - -void AsyncWebSocketClient::text(const char * message, size_t len) -{ - _queueMessage(new AsyncWebSocketBasicMessage(message, len)); -} - -///////////////////////////////////////////////// - -void AsyncWebSocketClient::text(const char * message) -{ - text(message, strlen(message)); -} - -///////////////////////////////////////////////// - -void AsyncWebSocketClient::text(uint8_t * message, size_t len) -{ - text((const char *)message, len); -} - -///////////////////////////////////////////////// - -void AsyncWebSocketClient::text(char * message) -{ - text(message, strlen(message)); -} - -///////////////////////////////////////////////// - -void AsyncWebSocketClient::text(const String &message) -{ - text(message.c_str(), message.length()); -} - -///////////////////////////////////////////////// - -void AsyncWebSocketClient::text(const __FlashStringHelper *data) -{ - PGM_P p = reinterpret_cast(data); - size_t n = 0; - - while (1) - { - if (pgm_read_byte(p + n) == 0) - break; - - n += 1; - } - - char * message = (char*) malloc(n + 1); - - if (message) - { - for (size_t b = 0; b < n; b++) - message[b] = pgm_read_byte(p++); - - message[n] = 0; - text(message, n); - free(message); - } -} - -///////////////////////////////////////////////// - -void AsyncWebSocketClient::text(AsyncWebSocketMessageBuffer * buffer) -{ - _queueMessage(new AsyncWebSocketMultiMessage(buffer)); -} - -///////////////////////////////////////////////// - -void AsyncWebSocketClient::binary(const char * message, size_t len) -{ - _queueMessage(new AsyncWebSocketBasicMessage(message, len, WS_BINARY)); -} - -///////////////////////////////////////////////// - -void AsyncWebSocketClient::binary(const char * message) -{ - binary(message, strlen(message)); -} - -///////////////////////////////////////////////// - -void AsyncWebSocketClient::binary(uint8_t * message, size_t len) -{ - binary((const char *)message, len); -} - -///////////////////////////////////////////////// - -void AsyncWebSocketClient::binary(char * message) -{ - binary(message, strlen(message)); -} - -///////////////////////////////////////////////// - -void AsyncWebSocketClient::binary(const String &message) -{ - binary(message.c_str(), message.length()); -} - -///////////////////////////////////////////////// - -void AsyncWebSocketClient::binary(const __FlashStringHelper *data, size_t len) -{ - PGM_P p = reinterpret_cast(data); - char * message = (char*) malloc(len); - - if (message) - { - for (size_t b = 0; b < len; b++) - message[b] = pgm_read_byte(p++); - - binary(message, len); - free(message); - } -} - -///////////////////////////////////////////////// - -void AsyncWebSocketClient::binary(AsyncWebSocketMessageBuffer * buffer) -{ - _queueMessage(new AsyncWebSocketMultiMessage(buffer, WS_BINARY)); -} - -///////////////////////////////////////////////// - -IPAddress AsyncWebSocketClient::remoteIP() -{ - if (!_client) - { - return IPAddress((uint32_t) 0); - } - - return _client->remoteIP(); -} - -///////////////////////////////////////////////// - -uint16_t AsyncWebSocketClient::remotePort() -{ - if (!_client) - { - return 0; - } - - return _client->remotePort(); -} - -///////////////////////////////////////////////// -///////////////////////////////////////////////// - -/* - Async Web Socket - Each separate socket location -*/ - -AsyncWebSocket::AsyncWebSocket(const String& url) - : _url(url) - , _clients(LinkedList([](AsyncWebSocketClient * c) -{ - delete c; -})) -, _cNextId(1) -, _enabled(true) -, _buffers(LinkedList([](AsyncWebSocketMessageBuffer *b) -{ - delete b; -})) -{ - _eventHandler = NULL; -} - -///////////////////////////////////////////////// - -AsyncWebSocket::~AsyncWebSocket() {} - -void AsyncWebSocket::_handleEvent(AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, - size_t len) -{ - if (_eventHandler != NULL) - { - _eventHandler(this, client, type, arg, data, len); - } -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::_addClient(AsyncWebSocketClient * client) -{ - _clients.add(client); -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::_handleDisconnect(AsyncWebSocketClient * client) -{ - - _clients.remove_first([ = ](AsyncWebSocketClient * c) - { - return c->id() == client->id(); - }); -} - -///////////////////////////////////////////////// - -bool AsyncWebSocket::availableForWriteAll() -{ - for (const auto& c : _clients) - { - if (c->queueIsFull()) - return false; - } - - return true; -} - -///////////////////////////////////////////////// - -bool AsyncWebSocket::availableForWrite(uint32_t id) -{ - for (const auto& c : _clients) - { - if (c->queueIsFull() && (c->id() == id )) - return false; - } - - return true; -} - -///////////////////////////////////////////////// - -size_t AsyncWebSocket::count() const -{ - return _clients.count_if([](AsyncWebSocketClient * c) - { - return c->status() == WS_CONNECTED; - }); -} - -///////////////////////////////////////////////// - -AsyncWebSocketClient * AsyncWebSocket::client(uint32_t id) -{ - for (const auto &c : _clients) - { - if (c->id() == id && c->status() == WS_CONNECTED) - { - return c; - } - } - - return nullptr; -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::close(uint32_t id, uint16_t code, const char * message) -{ - AsyncWebSocketClient * c = client(id); - - if (c) - c->close(code, message); -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::closeAll(uint16_t code, const char * message) -{ - for (const auto& c : _clients) - { - if (c->status() == WS_CONNECTED) - c->close(code, message); - } -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::cleanupClients(uint16_t maxClients) -{ - if (count() > maxClients) - { - _clients.front()->close(); - } -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::ping(uint32_t id, uint8_t *data, size_t len) -{ - AsyncWebSocketClient * c = client(id); - - if (c) - c->ping(data, len); -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::pingAll(uint8_t *data, size_t len) -{ - for (const auto& c : _clients) - { - if (c->status() == WS_CONNECTED) - c->ping(data, len); - } -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::text(uint32_t id, const char * message, size_t len) -{ - AsyncWebSocketClient * c = client(id); - - if (c) - c->text(message, len); -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::textAll(AsyncWebSocketMessageBuffer * buffer) -{ - if (!buffer) - return; - - buffer->lock(); - - for (const auto& c : _clients) - { - if (c->status() == WS_CONNECTED) - { - c->text(buffer); - } - } - - buffer->unlock(); - _cleanBuffers(); -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::textAll(const char * message, size_t len) -{ - AsyncWebSocketMessageBuffer * WSBuffer = makeBuffer((uint8_t *)message, len); - textAll(WSBuffer); -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::binary(uint32_t id, const char * message, size_t len) -{ - AsyncWebSocketClient * c = client(id); - - if (c) - c->binary(message, len); -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::binaryAll(const char * message, size_t len) -{ - AsyncWebSocketMessageBuffer * buffer = makeBuffer((uint8_t *)message, len); - binaryAll(buffer); -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::binaryAll(AsyncWebSocketMessageBuffer * buffer) -{ - if (!buffer) - return; - - buffer->lock(); - - for (const auto& c : _clients) - { - if (c->status() == WS_CONNECTED) - c->binary(buffer); - } - - buffer->unlock(); - _cleanBuffers(); -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::message(uint32_t id, AsyncWebSocketMessage *message) -{ - AsyncWebSocketClient * c = client(id); - - if (c) - c->message(message); -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::messageAll(AsyncWebSocketMultiMessage *message) -{ - for (const auto& c : _clients) - { - if (c->status() == WS_CONNECTED) - c->message(message); - } - - _cleanBuffers(); -} - -///////////////////////////////////////////////// - -size_t AsyncWebSocket::printf(uint32_t id, const char *format, ...) -{ - AsyncWebSocketClient * c = client(id); - - if (c) - { - va_list arg; - va_start(arg, format); - size_t len = c->printf(format, arg); - va_end(arg); - - return len; - } - - return 0; -} - -///////////////////////////////////////////////// - -size_t AsyncWebSocket::printfAll(const char *format, ...) -{ - va_list arg; - char* temp = new char[MAX_PRINTF_LEN]; - - if (!temp) - { - return 0; - } - - va_start(arg, format); - size_t len = vsnprintf(temp, MAX_PRINTF_LEN, format, arg); - va_end(arg); - delete[] temp; - - AsyncWebSocketMessageBuffer * buffer = makeBuffer(len); - - if (!buffer) - { - return 0; - } - - va_start(arg, format); - vsnprintf( (char *)buffer->get(), len + 1, format, arg); - va_end(arg); - - textAll(buffer); - - return len; -} - -///////////////////////////////////////////////// - -size_t AsyncWebSocket::printfAll_P(PGM_P formatP, ...) -{ - va_list arg; - char* temp = new char[MAX_PRINTF_LEN]; - - if (!temp) - { - return 0; - } - - va_start(arg, formatP); - size_t len = vsnprintf_P(temp, MAX_PRINTF_LEN, formatP, arg); - va_end(arg); - delete[] temp; - - AsyncWebSocketMessageBuffer * buffer = makeBuffer(len + 1); - - if (!buffer) - { - return 0; - } - - va_start(arg, formatP); - vsnprintf_P((char *)buffer->get(), len + 1, formatP, arg); - va_end(arg); - - textAll(buffer); - - return len; -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::text(uint32_t id, const char * message) -{ - text(id, message, strlen(message)); -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::text(uint32_t id, uint8_t * message, size_t len) -{ - text(id, (const char *)message, len); -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::text(uint32_t id, char * message) -{ - text(id, message, strlen(message)); -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::text(uint32_t id, const String &message) -{ - text(id, message.c_str(), message.length()); -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::text(uint32_t id, const __FlashStringHelper *message) -{ - AsyncWebSocketClient * c = client(id); - - if (c != NULL) - c->text(message); -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::textAll(const char * message) -{ - textAll(message, strlen(message)); -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::textAll(uint8_t * message, size_t len) -{ - textAll((const char *)message, len); -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::textAll(char * message) -{ - textAll(message, strlen(message)); -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::textAll(const String &message) -{ - textAll(message.c_str(), message.length()); -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::textAll(const __FlashStringHelper *message) -{ - for (const auto& c : _clients) - { - if (c->status() == WS_CONNECTED) - c->text(message); - } -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::binary(uint32_t id, const char * message) -{ - binary(id, message, strlen(message)); -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::binary(uint32_t id, uint8_t * message, size_t len) -{ - binary(id, (const char *)message, len); -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::binary(uint32_t id, char * message) -{ - binary(id, message, strlen(message)); -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::binary(uint32_t id, const String &message) -{ - binary(id, message.c_str(), message.length()); -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::binary(uint32_t id, const __FlashStringHelper *message, size_t len) -{ - AsyncWebSocketClient * c = client(id); - - if (c != NULL) - c-> binary(message, len); -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::binaryAll(const char * message) -{ - binaryAll(message, strlen(message)); -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::binaryAll(uint8_t * message, size_t len) -{ - binaryAll((const char *)message, len); -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::binaryAll(char * message) -{ - binaryAll(message, strlen(message)); -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::binaryAll(const String &message) -{ - binaryAll(message.c_str(), message.length()); -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::binaryAll(const __FlashStringHelper *message, size_t len) -{ - for (const auto& c : _clients) - { - if (c->status() == WS_CONNECTED) - c-> binary(message, len); - } -} - -///////////////////////////////////////////////// - -const char * WS_STR_CONNECTION = "Connection"; -const char * WS_STR_UPGRADE = "Upgrade"; -const char * WS_STR_ORIGIN = "Origin"; -const char * WS_STR_VERSION = "Sec-WebSocket-Version"; -const char * WS_STR_KEY = "Sec-WebSocket-Key"; -const char * WS_STR_PROTOCOL = "Sec-WebSocket-Protocol"; -const char * WS_STR_ACCEPT = "Sec-WebSocket-Accept"; -const char * WS_STR_UUID = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"; - -///////////////////////////////////////////////// - -bool AsyncWebSocket::canHandle(AsyncWebServerRequest *request) -{ - if (!_enabled) - return false; - - if (request->method() != HTTP_GET || !request->url().equals(_url) || !request->isExpectedRequestedConnType(RCT_WS)) - return false; - - request->addInterestingHeader(WS_STR_CONNECTION); - request->addInterestingHeader(WS_STR_UPGRADE); - request->addInterestingHeader(WS_STR_ORIGIN); - request->addInterestingHeader(WS_STR_VERSION); - request->addInterestingHeader(WS_STR_KEY); - request->addInterestingHeader(WS_STR_PROTOCOL); - - return true; -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::handleRequest(AsyncWebServerRequest *request) -{ - if (!request->hasHeader(WS_STR_VERSION) || !request->hasHeader(WS_STR_KEY)) - { - request->send(400); - - return; - } - - if ((_username != "" && _password != "") && !request->authenticate(_username.c_str(), _password.c_str())) - { - return request->requestAuthentication(); - } - - AsyncWebHeader* version = request->getHeader(WS_STR_VERSION); - - if (version->value().toInt() != 13) - { - AsyncWebServerResponse *response = request->beginResponse(400); - response->addHeader(WS_STR_VERSION, "13"); - request->send(response); - - return; - } - - AsyncWebHeader* key = request->getHeader(WS_STR_KEY); - AsyncWebServerResponse *response = new AsyncWebSocketResponse(key->value(), this); - - if (request->hasHeader(WS_STR_PROTOCOL)) - { - AsyncWebHeader* protocol = request->getHeader(WS_STR_PROTOCOL); - //ToDo: check protocol - response->addHeader(WS_STR_PROTOCOL, protocol->value()); - } - - request->send(response); -} - -///////////////////////////////////////////////// - -AsyncWebSocketMessageBuffer * AsyncWebSocket::makeBuffer(size_t size) -{ - AsyncWebSocketMessageBuffer * buffer = new AsyncWebSocketMessageBuffer(size); - - if (buffer) - { - AsyncWebLockGuard l(_lock); - _buffers.add(buffer); - } - - return buffer; -} - -///////////////////////////////////////////////// - -AsyncWebSocketMessageBuffer * AsyncWebSocket::makeBuffer(uint8_t * data, size_t size) -{ - AsyncWebSocketMessageBuffer * buffer = new AsyncWebSocketMessageBuffer(data, size); - - if (buffer) - { - AsyncWebLockGuard l(_lock); - _buffers.add(buffer); - } - - return buffer; -} - -///////////////////////////////////////////////// - -void AsyncWebSocket::_cleanBuffers() -{ - AsyncWebLockGuard l(_lock); - - for (AsyncWebSocketMessageBuffer * c : _buffers) - { - if (c && c->canDelete()) - { - _buffers.remove(c); - } - } -} - -///////////////////////////////////////////////// - -AsyncWebSocket::AsyncWebSocketClientLinkedList AsyncWebSocket::getClients() const -{ - return _clients; -} - -///////////////////////////////////////////////// -///////////////////////////////////////////////// - -/* - Response to Web Socket request - sends the authorization and detaches the TCP Client from the web server - Authentication code from https://github.com/Links2004/arduinoWebSockets/blob/master/src/WebSockets.cpp#L480 -*/ - -AsyncWebSocketResponse::AsyncWebSocketResponse(const String & key, AsyncWebSocket * server) -{ - _server = server; - _code = 101; - _sendContentLength = false; - - uint8_t * hash = (uint8_t*) malloc(HASH_BUFFER_SIZE); - - if (hash == NULL) - { - _state = RESPONSE_FAILED; - return; - } - - char * buffer = (char *) malloc(33); - - if (buffer == NULL) - { - free(hash); - _state = RESPONSE_FAILED; - return; - } - - sha1_context _ctx; - - (String&) key += WS_STR_UUID; - - sha1_starts(&_ctx); - sha1_update(&_ctx, (const unsigned char*) key.c_str(), key.length()); - sha1_finish(&_ctx, hash); - ////// - - base64_encodestate _state; - base64_init_encodestate(&_state); - int len = base64_encode_block((const char *) hash, HASH_BUFFER_SIZE, buffer, &_state); - len = base64_encode_blockend((buffer + len), &_state); - - addHeader(WS_STR_CONNECTION, WS_STR_UPGRADE); - addHeader(WS_STR_UPGRADE, "websocket"); - addHeader(WS_STR_ACCEPT, buffer); - - free(buffer); - free(hash); -} - -///////////////////////////////////////////////// - -void AsyncWebSocketResponse::_respond(AsyncWebServerRequest *request) -{ - if (_state == RESPONSE_FAILED) - { - request->client()->close(true); - return; - } - - String out = _assembleHead(request->version()); - request->client()->write(out.c_str(), _headLength); - _state = RESPONSE_WAIT_ACK; -} - -///////////////////////////////////////////////// - -size_t AsyncWebSocketResponse::_ack(AsyncWebServerRequest *request, size_t len, uint32_t time) -{ - ESP32_W5500_AWS_UNUSED(time); - - if (len) - { - new AsyncWebSocketClient(request, _server); - } - - return 0; -} - - diff --git a/lib/AsyncWebServer_ESP32_W5500/src/AsyncWebSocket.h b/lib/AsyncWebServer_ESP32_W5500/src/AsyncWebSocket.h deleted file mode 100644 index 91cdfa2..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/AsyncWebSocket.h +++ /dev/null @@ -1,611 +0,0 @@ -/**************************************************************************************************************************** - AsyncWebSocket.h - Dead simple Ethernet AsyncWebServer. - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - - Original author: Hristo Gochkov - - Copyright (c) 2016 Hristo Gochkov. All rights reserved. - - This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License along with this library; - if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Version: 1.6.4 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2 - 1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples - 1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error - *****************************************************************************************************************************/ - -#ifndef ASYNCWEBSOCKET_H_ -#define ASYNCWEBSOCKET_H_ - -#include "mbedtls/version.h" - -#if (MBEDTLS_VERSION_NUMBER >= 0x02070000) - //#error Must use ESP32 core v1.0.6-, with MBEDTLS_VERSION_NUMBER < v2.7.0 -#endif - -#include - -#include -#define WS_MAX_QUEUED_MESSAGES 32 - -#include "AsyncWebServer_ESP32_W5500.h" - -#include "AsyncWebSynchronization.h" - -///////////////////////////////////////////////// - -#define DEFAULT_MAX_WS_CLIENTS 8 - -///////////////////////////////////////////////// - -class AsyncWebSocket; -class AsyncWebSocketResponse; -class AsyncWebSocketClient; -class AsyncWebSocketControl; - -///////////////////////////////////////////////// - -typedef struct -{ - /** Message type as defined by enum AwsFrameType. - Note: Applications will only see WS_TEXT and WS_BINARY. - All other types are handled by the library. */ - uint8_t message_opcode; - /** Frame number of a fragmented message. */ - uint32_t num; - /** Is this the last frame in a fragmented message ?*/ - uint8_t final; - /** Is this frame masked? */ - uint8_t masked; - /** Message type as defined by enum AwsFrameType. - This value is the same as message_opcode for non-fragmented - messages, but may also be WS_CONTINUATION in a fragmented message. */ - uint8_t opcode; - /** Length of the current frame. - This equals the total length of the message if num == 0 && final == true */ - uint64_t len; - /** Mask key */ - uint8_t mask[4]; - /** Offset of the data inside the current frame. */ - uint64_t index; -} AwsFrameInfo; - -///////////////////////////////////////////////// - -typedef enum -{ - WS_DISCONNECTED, - WS_CONNECTED, - WS_DISCONNECTING -} AwsClientStatus; - -typedef enum -{ - WS_CONTINUATION, - WS_TEXT, - WS_BINARY, - WS_DISCONNECT = 0x08, - WS_PING, - WS_PONG -} AwsFrameType; - -typedef enum -{ - WS_MSG_SENDING, - WS_MSG_SENT, - WS_MSG_ERROR -} AwsMessageStatus; - -typedef enum -{ - WS_EVT_CONNECT, - WS_EVT_DISCONNECT, - WS_EVT_PONG, - WS_EVT_ERROR, - WS_EVT_DATA -} AwsEventType; - -///////////////////////////////////////////////// - -class AsyncWebSocketMessageBuffer -{ - private: - uint8_t * _data; - size_t _len; - bool _lock; - uint32_t _count; - - public: - AsyncWebSocketMessageBuffer(); - AsyncWebSocketMessageBuffer(size_t size); - AsyncWebSocketMessageBuffer(uint8_t * data, size_t size); - AsyncWebSocketMessageBuffer(const AsyncWebSocketMessageBuffer &); - AsyncWebSocketMessageBuffer(AsyncWebSocketMessageBuffer &&); - ~AsyncWebSocketMessageBuffer(); - - ///////////////////////////////////////////////// - - void operator ++(int i) - { - ESP32_W5500_AWS_UNUSED(i); - _count++; - } - - ///////////////////////////////////////////////// - - void operator --(int i) - { - ESP32_W5500_AWS_UNUSED(i); - - if (_count > 0) - { - _count--; - } ; - } - - ///////////////////////////////////////////////// - - bool reserve(size_t size); - - ///////////////////////////////////////////////// - - inline void lock() - { - _lock = true; - } - - ///////////////////////////////////////////////// - - inline void unlock() - { - _lock = false; - } - - ///////////////////////////////////////////////// - - inline uint8_t * get() - { - return _data; - } - - ///////////////////////////////////////////////// - - inline size_t length() - { - return _len; - } - - ///////////////////////////////////////////////// - - inline uint32_t count() - { - return _count; - } - - ///////////////////////////////////////////////// - - inline bool canDelete() - { - return (!_count && !_lock); - } - - ///////////////////////////////////////////////// - - friend AsyncWebSocket; - -}; - -///////////////////////////////////////////////// - -class AsyncWebSocketMessage -{ - protected: - uint8_t _opcode; - bool _mask; - AwsMessageStatus _status; - - public: - AsyncWebSocketMessage(): _opcode(WS_TEXT), _mask(false), _status(WS_MSG_ERROR) {} - virtual ~AsyncWebSocketMessage() {} - virtual void ack(size_t len __attribute__((unused)), uint32_t time __attribute__((unused))) {} - - ///////////////////////////////////////////////// - - virtual size_t send(AsyncClient *client __attribute__((unused))) - { - return 0; - } - - ///////////////////////////////////////////////// - - virtual bool finished() - { - return _status != WS_MSG_SENDING; - } - - ///////////////////////////////////////////////// - - virtual bool betweenFrames() const - { - return false; - } -}; - -///////////////////////////////////////////////// - -class AsyncWebSocketBasicMessage: public AsyncWebSocketMessage -{ - private: - size_t _len; - size_t _sent; - size_t _ack; - size_t _acked; - uint8_t * _data; - - public: - AsyncWebSocketBasicMessage(const char * data, size_t len, uint8_t opcode = WS_TEXT, bool mask = false); - AsyncWebSocketBasicMessage(uint8_t opcode = WS_TEXT, bool mask = false); - virtual ~AsyncWebSocketBasicMessage() override; - - ///////////////////////////////////////////////// - - virtual bool betweenFrames() const override - { - return _acked == _ack; - } - - ///////////////////////////////////////////////// - - virtual void ack(size_t len, uint32_t time) override ; - virtual size_t send(AsyncClient *client) override ; -}; - -///////////////////////////////////////////////// - -class AsyncWebSocketMultiMessage: public AsyncWebSocketMessage -{ - private: - uint8_t * _data; - size_t _len; - size_t _sent; - size_t _ack; - size_t _acked; - AsyncWebSocketMessageBuffer * _WSbuffer; - - public: - AsyncWebSocketMultiMessage(AsyncWebSocketMessageBuffer * buffer, uint8_t opcode = WS_TEXT, bool mask = false); - virtual ~AsyncWebSocketMultiMessage() override; - - ///////////////////////////////////////////////// - - virtual bool betweenFrames() const override - { - return _acked == _ack; - } - - ///////////////////////////////////////////////// - - virtual void ack(size_t len, uint32_t time) override ; - virtual size_t send(AsyncClient *client) override ; -}; - -///////////////////////////////////////////////// - -class AsyncWebSocketClient -{ - private: - AsyncClient *_client; - AsyncWebSocket *_server; - uint32_t _clientId; - AwsClientStatus _status; - - LinkedList _controlQueue; - LinkedList _messageQueue; - - uint8_t _pstate; - AwsFrameInfo _pinfo; - - uint32_t _lastMessageTime; - uint32_t _keepAlivePeriod; - - void _queueMessage(AsyncWebSocketMessage *dataMessage); - void _queueControl(AsyncWebSocketControl *controlMessage); - void _runQueue(); - - public: - void *_tempObject; - - AsyncWebSocketClient(AsyncWebServerRequest *request, AsyncWebSocket *server); - ~AsyncWebSocketClient(); - - ///////////////////////////////////////////////// - - //client id increments for the given server - inline uint32_t id() - { - return _clientId; - } - - ///////////////////////////////////////////////// - - inline AwsClientStatus status() - { - return _status; - } - - ///////////////////////////////////////////////// - - inline AsyncClient* client() - { - return _client; - } - - ///////////////////////////////////////////////// - - inline AsyncWebSocket *server() - { - return _server; - } - - ///////////////////////////////////////////////// - - inline AwsFrameInfo const &pinfo() const - { - return _pinfo; - } - - ///////////////////////////////////////////////// - - IPAddress remoteIP(); - uint16_t remotePort(); - - //control frames - void close(uint16_t code = 0, const char * message = NULL); - void ping(uint8_t *data = NULL, size_t len = 0); - - ///////////////////////////////////////////////// - - //set auto-ping period in seconds. disabled if zero (default) - inline void keepAlivePeriod(uint16_t seconds) - { - _keepAlivePeriod = seconds * 1000; - } - - ///////////////////////////////////////////////// - - inline uint16_t keepAlivePeriod() - { - return (uint16_t)(_keepAlivePeriod / 1000); - } - - ///////////////////////////////////////////////// - - //data packets - inline void message(AsyncWebSocketMessage *message) - { - _queueMessage(message); - } - - ///////////////////////////////////////////////// - - bool queueIsFull(); - - size_t printf(const char *format, ...) __attribute__ ((format (printf, 2, 3))); - - void text(const char * message, size_t len); - void text(const char * message); - void text(uint8_t * message, size_t len); - void text(char * message); - void text(const String &message); - void text(const __FlashStringHelper *data); - void text(AsyncWebSocketMessageBuffer *buffer); - - void binary(const char * message, size_t len); - void binary(const char * message); - void binary(uint8_t * message, size_t len); - void binary(char * message); - void binary(const String &message); - void binary(const __FlashStringHelper *data, size_t len); - void binary(AsyncWebSocketMessageBuffer *buffer); - - ///////////////////////////////////////////////// - - inline bool canSend() - { - return _messageQueue.length() < WS_MAX_QUEUED_MESSAGES; - } - - ///////////////////////////////////////////////// - - //system callbacks (do not call) - void _onAck(size_t len, uint32_t time); - void _onError(int8_t); - void _onPoll(); - void _onTimeout(uint32_t time); - void _onDisconnect(); - void _onData(void *pbuf, size_t plen); -}; - -///////////////////////////////////////////////// - -typedef std::function -AwsEventHandler; - -///////////////////////////////////////////////// - -//WebServer Handler implementation that plays the role of a socket server -class AsyncWebSocket: public AsyncWebHandler -{ - public: - typedef LinkedList AsyncWebSocketClientLinkedList; - - private: - String _url; - AsyncWebSocketClientLinkedList _clients; - uint32_t _cNextId; - AwsEventHandler _eventHandler; - bool _enabled; - AsyncWebLock _lock; - - public: - AsyncWebSocket(const String& url); - ~AsyncWebSocket(); - - ///////////////////////////////////////////////// - - inline const char * url() const - { - return _url.c_str(); - } - - ///////////////////////////////////////////////// - - inline void enable(bool e) - { - _enabled = e; - } - - ///////////////////////////////////////////////// - - inline bool enabled() const - { - return _enabled; - } - - ///////////////////////////////////////////////// - - bool availableForWriteAll(); - bool availableForWrite(uint32_t id); - - size_t count() const; - AsyncWebSocketClient * client(uint32_t id); - - ///////////////////////////////////////////////// - - inline bool hasClient(uint32_t id) - { - return client(id) != NULL; - } - - ///////////////////////////////////////////////// - - void close(uint32_t id, uint16_t code = 0, const char * message = NULL); - void closeAll(uint16_t code = 0, const char * message = NULL); - void cleanupClients(uint16_t maxClients = DEFAULT_MAX_WS_CLIENTS); - - void ping(uint32_t id, uint8_t *data = NULL, size_t len = 0); - void pingAll(uint8_t *data = NULL, size_t len = 0); // done - - void text(uint32_t id, const char * message, size_t len); - void text(uint32_t id, const char * message); - void text(uint32_t id, uint8_t * message, size_t len); - void text(uint32_t id, char * message); - void text(uint32_t id, const String &message); - void text(uint32_t id, const __FlashStringHelper *message); - - void textAll(const char * message, size_t len); - void textAll(const char * message); - void textAll(uint8_t * message, size_t len); - void textAll(char * message); - void textAll(const String &message); - void textAll(const __FlashStringHelper *message); // need to convert - void textAll(AsyncWebSocketMessageBuffer * buffer); - - void binary(uint32_t id, const char * message, size_t len); - void binary(uint32_t id, const char * message); - void binary(uint32_t id, uint8_t * message, size_t len); - void binary(uint32_t id, char * message); - void binary(uint32_t id, const String &message); - void binary(uint32_t id, const __FlashStringHelper *message, size_t len); - - void binaryAll(const char * message, size_t len); - void binaryAll(const char * message); - void binaryAll(uint8_t * message, size_t len); - void binaryAll(char * message); - void binaryAll(const String &message); - void binaryAll(const __FlashStringHelper *message, size_t len); - void binaryAll(AsyncWebSocketMessageBuffer * buffer); - - void message(uint32_t id, AsyncWebSocketMessage *message); - void messageAll(AsyncWebSocketMultiMessage *message); - - size_t printf(uint32_t id, const char *format, ...) __attribute__ ((format (printf, 3, 4))); - size_t printfAll(const char *format, ...) __attribute__ ((format (printf, 2, 3))); - - size_t printfAll_P(PGM_P formatP, ...) __attribute__ ((format (printf, 2, 3))); - - ///////////////////////////////////////////////// - - //event listener - inline void onEvent(AwsEventHandler handler) - { - _eventHandler = handler; - } - - ///////////////////////////////////////////////// - - //system callbacks (do not call) - inline uint32_t _getNextId() - { - return _cNextId++; - } - - ///////////////////////////////////////////////// - - void _addClient(AsyncWebSocketClient * client); - void _handleDisconnect(AsyncWebSocketClient * client); - void _handleEvent(AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len); - virtual bool canHandle(AsyncWebServerRequest *request) override final; - virtual void handleRequest(AsyncWebServerRequest *request) override final; - - // messagebuffer functions/objects. - AsyncWebSocketMessageBuffer * makeBuffer(size_t size = 0); - AsyncWebSocketMessageBuffer * makeBuffer(uint8_t * data, size_t size); - LinkedList _buffers; - void _cleanBuffers(); - - AsyncWebSocketClientLinkedList getClients() const; -}; - -///////////////////////////////////////////////// - -//WebServer response to authenticate the socket and detach the tcp client from the web server request -class AsyncWebSocketResponse: public AsyncWebServerResponse -{ - private: - String _content; - AsyncWebSocket *_server; - - public: - AsyncWebSocketResponse(const String& key, AsyncWebSocket *server); - void _respond(AsyncWebServerRequest *request); - size_t _ack(AsyncWebServerRequest *request, size_t len, uint32_t time); - - ///////////////////////////////////////////////// - - inline bool _sourceValid() const - { - return true; - } -}; - -///////////////////////////////////////////////// - -#endif /* ASYNCWEBSOCKET_H_ */ diff --git a/lib/AsyncWebServer_ESP32_W5500/src/AsyncWebSynchronization.h b/lib/AsyncWebServer_ESP32_W5500/src/AsyncWebSynchronization.h deleted file mode 100644 index d0eaa7f..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/AsyncWebSynchronization.h +++ /dev/null @@ -1,124 +0,0 @@ -/**************************************************************************************************************************** - AsyncWebSynchronization.h - Dead simple Ethernet AsyncWebServer. - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - - Original author: Hristo Gochkov - - Copyright (c) 2016 Hristo Gochkov. All rights reserved. - - This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License along with this library; - if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Version: 1.6.4 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2 - 1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples - 1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error - *****************************************************************************************************************************/ - -#ifndef ASYNCWEBSYNCHRONIZATION_H_ -#define ASYNCWEBSYNCHRONIZATION_H_ - -// Synchronisation is only available on ESP32, as the ESP8266 isn't using FreeRTOS by default - -#include "AsyncWebServer_ESP32_W5500.h" - -///////////////////////////////////////////////// - -// This is the ESP32 version of the Sync Lock, using the FreeRTOS Semaphore -class AsyncWebLock -{ - private: - SemaphoreHandle_t _lock; - mutable void *_lockedBy; - - public: - AsyncWebLock() - { - _lock = xSemaphoreCreateBinary(); - _lockedBy = NULL; - xSemaphoreGive(_lock); - } - - ///////////////////////////////////////////////// - - ~AsyncWebLock() - { - vSemaphoreDelete(_lock); - } - - ///////////////////////////////////////////////// - - bool lock() const - { - extern void *pxCurrentTCB; - - if (_lockedBy != pxCurrentTCB) - { - xSemaphoreTake(_lock, portMAX_DELAY); - _lockedBy = pxCurrentTCB; - - return true; - } - - return false; - } - - ///////////////////////////////////////////////// - - void unlock() const - { - _lockedBy = NULL; - xSemaphoreGive(_lock); - } -}; - -///////////////////////////////////////////////// - -class AsyncWebLockGuard -{ - private: - const AsyncWebLock *_lock; - - public: - AsyncWebLockGuard(const AsyncWebLock &l) - { - if (l.lock()) - { - _lock = &l; - } - else - { - _lock = NULL; - } - } - - ///////////////////////////////////////////////// - - ~AsyncWebLockGuard() - { - if (_lock) - { - _lock->unlock(); - } - } -}; - -///////////////////////////////////////////////// - -#endif // ASYNCWEBSYNCHRONIZATION_H_ diff --git a/lib/AsyncWebServer_ESP32_W5500/src/Crypto/Hash.cpp b/lib/AsyncWebServer_ESP32_W5500/src/Crypto/Hash.cpp deleted file mode 100644 index 65257da..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/Crypto/Hash.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/** - @file Hash.cpp - @date 20.05.2015 - @author Markus Sattler - - Copyright (c) 2015 Markus Sattler. All rights reserved. - This file is part of the esp8266 core for Arduino environment. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -#include -#include "bearssl_hash.h" - -#include "Hash.h" - -/** - create a sha1 hash from data - @param data uint8_t - @param size uint32_t - @param hash uint8_t[HASH_BUFFER_SIZE] -*/ -void sha1(const uint8_t* data, uint32_t size, uint8_t hash[HASH_BUFFER_SIZE]) -{ - br_sha1_context ctx; - - AWS_LOGDEBUG0("DATA:"); - - for (uint16_t i = 0; i < size; i++) - { - AWS_LOGDEBUG0(data[i]); - } - - AWS_LOGDEBUG0("\nDATA:"); - - for (uint16_t i = 0; i < size; i++) - { - AWS_LOGDEBUG0((char) data[i]); - - } - - AWS_LOGDEBUG0("\n"); - - br_sha1_init(&ctx); - br_sha1_update(&ctx, data, size); - br_sha1_out(&ctx, hash); - - AWS_LOGDEBUG0("SHA1:"); - - for (uint16_t i = 0; i < HASH_BUFFER_SIZE; i++) - { - AWS_LOGDEBUG0(hash[i]); - } - - AWS_LOGDEBUG0("\n"); -} - -void sha1(const char* data, uint32_t size, uint8_t hash[HASH_BUFFER_SIZE]) -{ - sha1((const uint8_t *) data, size, hash); -} - -void sha1(const String& data, uint8_t hash[HASH_BUFFER_SIZE]) -{ - sha1(data.c_str(), data.length(), hash); -} - -String sha1(const uint8_t* data, uint32_t size) -{ - uint8_t hash[HASH_BUFFER_SIZE]; - - String hashStr((const char*)nullptr); - hashStr.reserve(HASH_BUFFER_SIZE * 2 + 1); - - sha1(&data[0], size, &hash[0]); - - for (uint16_t i = 0; i < HASH_BUFFER_SIZE; i++) - { - char hex[3]; - snprintf(hex, sizeof(hex), "%02x", hash[i]); - hashStr += hex; - } - - return hashStr; -} - -String sha1(const char* data, uint32_t size) -{ - return sha1((const uint8_t*) data, size); -} - -String sha1(const String& data) -{ - return sha1(data.c_str(), data.length()); -} - diff --git a/lib/AsyncWebServer_ESP32_W5500/src/Crypto/Hash.h b/lib/AsyncWebServer_ESP32_W5500/src/Crypto/Hash.h deleted file mode 100644 index 4713c8a..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/Crypto/Hash.h +++ /dev/null @@ -1,46 +0,0 @@ -/** - @file Hash.h - @date 20.05.2015 - @author Markus Sattler - - Copyright (c) 2015 Markus Sattler. All rights reserved. - This file is part of the esp8266 core for Arduino environment. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - -*/ - -#pragma once - -#ifndef HASH_H_ -#define HASH_H_ - -#include "AsyncWebServer_ESP32_W5500_Debug.h" - -#ifdef HASH_BUFFER_SIZE - #undef HASH_BUFFER_SIZE -#endif - -#define HASH_BUFFER_SIZE 20 - -void sha1(const uint8_t* data, uint32_t size, uint8_t hash[HASH_BUFFER_SIZE]); -void sha1(const char* data, uint32_t size, uint8_t hash[HASH_BUFFER_SIZE]); -void sha1(const String& data, uint8_t hash[HASH_BUFFER_SIZE]); - -String sha1(const uint8_t* data, uint32_t size); -String sha1(const char* data, uint32_t size); -String sha1(const String& data); - -#endif /* HASH_H_ */ diff --git a/lib/AsyncWebServer_ESP32_W5500/src/Crypto/bearssl_hash.h b/lib/AsyncWebServer_ESP32_W5500/src/Crypto/bearssl_hash.h deleted file mode 100644 index 2d5098d..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/Crypto/bearssl_hash.h +++ /dev/null @@ -1,1357 +0,0 @@ -/* - Copyright (c) 2016 Thomas Pornin - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -*/ - -#pragma once - -#ifndef BR_BEARSSL_HASH_H__ -#define BR_BEARSSL_HASH_H__ - -#include "AsyncWebServer_ESP32_W5500_Debug.h" - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/** \file bearssl_hash.h - - # Hash Functions - - This file documents the API for hash functions. - - - ## Procedural API - - For each implemented hash function, of name "`xxx`", the following - elements are defined: - - - `br_xxx_vtable` - - An externally defined instance of `br_hash_class`. - - - `br_xxx_SIZE` - - A macro that evaluates to the output size (in bytes) of the - hash function. - - - `br_xxx_ID` - - A macro that evaluates to a symbolic identifier for the hash - function. Such identifiers are used with HMAC and signature - algorithm implementations. - - NOTE: for the "standard" hash functions defined in [the TLS - standard](https://tools.ietf.org/html/rfc5246#section-7.4.1.4.1), - the symbolic identifiers match the constants used in TLS, i.e. - 1 to 6 for MD5, SHA-1, SHA-224, SHA-256, SHA-384 and SHA-512, - respectively. - - - `br_xxx_context` - - Context for an ongoing computation. It is allocated by the - caller, and a pointer to it is passed to all functions. A - context contains no interior pointer, so it can be moved around - and cloned (with a simple `memcpy()` or equivalent) in order to - capture the function state at some point. Computations that use - distinct context structures are independent of each other. The - first field of `br_xxx_context` is always a pointer to the - `br_xxx_vtable` structure; `br_xxx_init()` sets that pointer. - - - `br_xxx_init(br_xxx_context *ctx)` - - Initialise the provided context. Previous contents of the structure - are ignored. This calls resets the context to the start of a new - hash computation; it also sets the first field of the context - structure (called `vtable`) to a pointer to the statically - allocated constant `br_xxx_vtable` structure. - - - `br_xxx_update(br_xxx_context *ctx, const void *data, size_t len)` - - Add some more bytes to the hash computation represented by the - provided context. - - - `br_xxx_out(const br_xxx_context *ctx, void *out)` - - Complete the hash computation and write the result in the provided - buffer. The output buffer MUST be large enough to accommodate the - result. The context is NOT modified by this operation, so this - function can be used to get a "partial hash" while still keeping - the possibility of adding more bytes to the input. - - - `br_xxx_state(const br_xxx_context *ctx, void *out)` - - Get a copy of the "current state" for the computation so far. For - MD functions (MD5, SHA-1, SHA-2 family), this is the running state - resulting from the processing of the last complete input block. - Returned value is the current input length (in bytes). - - - `br_xxx_set_state(br_xxx_context *ctx, const void *stb, uint64_t count)` - - Set the internal state to the provided values. The 'stb' and - 'count' values shall match that which was obtained from - `br_xxx_state()`. This restores the hash state only if the state - values were at an appropriate block boundary. This does NOT set - the `vtable` pointer in the context. - - Context structures can be discarded without any explicit deallocation. - Hash function implementations are purely software and don't reserve - any resources outside of the context structure itself. - - - ## Object-Oriented API - - For each hash function that follows the procedural API described - above, an object-oriented API is also provided. In that API, function - pointers from the vtable (`br_xxx_vtable`) are used. The vtable - incarnates object-oriented programming. An introduction on the OOP - concept used here can be read on the BearSSL Web site:
-    [https://www.bearssl.org/oop.html](https://www.bearssl.org/oop.html) - - The vtable offers functions called `init()`, `update()`, `out()`, - `set()` and `set_state()`, which are in fact the functions from - the procedural API. That vtable also contains two informative fields: - - - `context_size` - - The size of the context structure (`br_xxx_context`), in bytes. - This can be used by generic implementations to perform dynamic - context allocation. - - - `desc` - - A "descriptor" field that encodes some information on the hash - function: symbolic identifier, output size, state size, - internal block size, details on the padding. - - Users of this object-oriented API (in particular generic HMAC - implementations) may make the following assumptions: - - - Hash output size is no more than 64 bytes. - - Hash internal state size is no more than 64 bytes. - - Internal block size is a power of two, no less than 16 and no more - than 256. - - - ## Implemented Hash Functions - - Implemented hash functions are: - - | Function | Name | Output length | State length | - | :-------- | :------ | :-----------: | :----------: | - | MD5 | md5 | 16 | 16 | - | SHA-1 | sha1 | 20 | 20 | - | SHA-224 | sha224 | 28 | 32 | - | SHA-256 | sha256 | 32 | 32 | - | SHA-384 | sha384 | 48 | 64 | - | SHA-512 | sha512 | 64 | 64 | - | MD5+SHA-1 | md5sha1 | 36 | 36 | - - (MD5+SHA-1 is the concatenation of MD5 and SHA-1 computed over the - same input; in the implementation, the internal data buffer is - shared, thus making it more memory-efficient than separate MD5 and - SHA-1. It can be useful in implementing SSL 3.0, TLS 1.0 and TLS - 1.1.) - - - ## Multi-Hasher - - An aggregate hasher is provided, that can compute several standard - hash functions in parallel. It uses `br_multihash_context` and a - procedural API. It is configured with the implementations (the vtables) - that it should use; it will then compute all these hash functions in - parallel, on the same input. It is meant to be used in cases when the - hash of an object will be used, but the exact hash function is not - known yet (typically, streamed processing on X.509 certificates). - - Only the standard hash functions (MD5, SHA-1, SHA-224, SHA-256, SHA-384 - and SHA-512) are supported by the multi-hasher. - - - ## GHASH - - GHASH is not a generic hash function; it is a _universal_ hash function, - which, as the name does not say, means that it CANNOT be used in most - places where a hash function is needed. GHASH is used within the GCM - encryption mode, to provide the checked integrity functionality. - - A GHASH implementation is basically a function that uses the type defined - in this file under the name `br_ghash`: - - typedef void (*br_ghash)(void *y, const void *h, const void *data, size_t len); - - The `y` pointer refers to a 16-byte value which is used as input, and - receives the output of the GHASH invocation. `h` is a 16-byte secret - value (that serves as key). `data` and `len` define the input data. - - Three GHASH implementations are provided, all constant-time, based on - the use of integer multiplications with appropriate masking to cancel - carry propagation. -*/ - -/** - \brief Class type for hash function implementations. - - A `br_hash_class` instance references the methods implementing a hash - function. Constant instances of this structure are defined for each - implemented hash function. Such instances are also called "vtables". - - Vtables are used to support object-oriented programming, as - described on [the BearSSL Web site](https://www.bearssl.org/oop.html). -*/ -typedef struct br_hash_class_ br_hash_class; - -struct br_hash_class_ -{ - /** - \brief Size (in bytes) of the context structure appropriate for - computing this hash function. - */ - size_t context_size; - - /** - \brief Descriptor word that contains information about the hash - function. - - For each word `xxx` described below, use `BR_HASHDESC_xxx_OFF` - and `BR_HASHDESC_xxx_MASK` to access the specific value, as - follows: - - (hf->desc >> BR_HASHDESC_xxx_OFF) & BR_HASHDESC_xxx_MASK - - The defined elements are: - - - `ID`: the symbolic identifier for the function, as defined - in [TLS](https://tools.ietf.org/html/rfc5246#section-7.4.1.4.1) - (MD5 = 1, SHA-1 = 2,...). - - - `OUT`: hash output size, in bytes. - - - `STATE`: internal running state size, in bytes. - - - `LBLEN`: base-2 logarithm for the internal block size, as - defined for HMAC processing (this is 6 for MD5, SHA-1, SHA-224 - and SHA-256, since these functions use 64-byte blocks; for - SHA-384 and SHA-512, this is 7, corresponding to their - 128-byte blocks). - - The descriptor may contain a few other flags. - */ - uint32_t desc; - - /** - \brief Initialisation method. - - This method takes as parameter a pointer to a context area, - that it initialises. The first field of the context is set - to this vtable; other elements are initialised for a new hash - computation. - - \param ctx pointer to (the first field of) the context. - */ - void (*init)(const br_hash_class **ctx); - - /** - \brief Data injection method. - - The `len` bytes starting at address `data` are injected into - the running hash computation incarnated by the specified - context. The context is updated accordingly. It is allowed - to have `len == 0`, in which case `data` is ignored (and could - be `NULL`), and nothing happens. - on the input data. - - \param ctx pointer to (the first field of) the context. - \param data pointer to the first data byte to inject. - \param len number of bytes to inject. - */ - void (*update)(const br_hash_class **ctx, const void *data, size_t len); - - /** - \brief Produce hash output. - - The hash output corresponding to all data bytes injected in the - context since the last `init()` call is computed, and written - in the buffer pointed to by `dst`. The hash output size depends - on the implemented hash function (e.g. 16 bytes for MD5). - The context is _not_ modified by this call, so further bytes - may be afterwards injected to continue the current computation. - - \param ctx pointer to (the first field of) the context. - \param dst destination buffer for the hash output. - */ - void (*out)(const br_hash_class *const *ctx, void *dst); - - /** - \brief Get running state. - - This method saves the current running state into the `dst` - buffer. What constitutes the "running state" depends on the - hash function; for Merkle-Damgård hash functions (like - MD5 or SHA-1), this is the output obtained after processing - each block. The number of bytes injected so far is returned. - The context is not modified by this call. - - \param ctx pointer to (the first field of) the context. - \param dst destination buffer for the state. - \return the injected total byte length. - */ - uint64_t (*state)(const br_hash_class *const *ctx, void *dst); - - /** - \brief Set running state. - - This methods replaces the running state for the function. - - \param ctx pointer to (the first field of) the context. - \param stb source buffer for the state. - \param count injected total byte length. - */ - void (*set_state)(const br_hash_class **ctx, - const void *stb, uint64_t count); -}; - -#ifndef BR_DOXYGEN_IGNORE -#define BR_HASHDESC_ID(id) ((uint32_t)(id) << BR_HASHDESC_ID_OFF) -#define BR_HASHDESC_ID_OFF 0 -#define BR_HASHDESC_ID_MASK 0xFF - -#define BR_HASHDESC_OUT(size) ((uint32_t)(size) << BR_HASHDESC_OUT_OFF) -#define BR_HASHDESC_OUT_OFF 8 -#define BR_HASHDESC_OUT_MASK 0x7F - -#define BR_HASHDESC_STATE(size) ((uint32_t)(size) << BR_HASHDESC_STATE_OFF) -#define BR_HASHDESC_STATE_OFF 15 -#define BR_HASHDESC_STATE_MASK 0xFF - -#define BR_HASHDESC_LBLEN(ls) ((uint32_t)(ls) << BR_HASHDESC_LBLEN_OFF) -#define BR_HASHDESC_LBLEN_OFF 23 -#define BR_HASHDESC_LBLEN_MASK 0x0F - -#define BR_HASHDESC_MD_PADDING ((uint32_t)1 << 28) -#define BR_HASHDESC_MD_PADDING_128 ((uint32_t)1 << 29) -#define BR_HASHDESC_MD_PADDING_BE ((uint32_t)1 << 30) -#endif - -/* - Specific hash functions. - - Rules for contexts: - -- No interior pointer. - -- No pointer to external dynamically allocated resources. - -- First field is called 'vtable' and is a pointer to a - const-qualified br_hash_class instance (pointer is set by init()). - -- SHA-224 and SHA-256 contexts are identical. - -- SHA-384 and SHA-512 contexts are identical. - - Thus, contexts can be moved and cloned to capture the hash function - current state; and there is no need for any explicit "release" function. -*/ - -/** - \brief Symbolic identifier for MD5. -*/ -#define br_md5_ID 1 - -/** - \brief MD5 output size (in bytes). -*/ -#define br_md5_SIZE 16 - -/** - \brief Constant vtable for MD5. -*/ -extern const br_hash_class br_md5_vtable; - -/** - \brief MD5 context. - - First field is a pointer to the vtable; it is set by the initialisation - function. Other fields are not supposed to be accessed by user code. -*/ -typedef struct -{ - /** - \brief Pointer to vtable for this context. - */ - const br_hash_class *vtable; -#ifndef BR_DOXYGEN_IGNORE - unsigned char buf[64]; - uint64_t count; - uint32_t val[4]; -#endif -} br_md5_context; - -/** - \brief MD5 context initialisation. - - This function initialises or resets a context for a new MD5 - computation. It also sets the vtable pointer. - - \param ctx pointer to the context structure. -*/ -void br_md5_init(br_md5_context *ctx); - -/** - \brief Inject some data bytes in a running MD5 computation. - - The provided context is updated with some data bytes. If the number - of bytes (`len`) is zero, then the data pointer (`data`) is ignored - and may be `NULL`, and this function does nothing. - - \param ctx pointer to the context structure. - \param data pointer to the injected data. - \param len injected data length (in bytes). -*/ -void br_md5_update(br_md5_context *ctx, const void *data, size_t len); - -/** - \brief Compute MD5 output. - - The MD5 output for the concatenation of all bytes injected in the - provided context since the last initialisation or reset call, is - computed and written in the buffer pointed to by `out`. The context - itself is not modified, so extra bytes may be injected afterwards - to continue that computation. - - \param ctx pointer to the context structure. - \param out destination buffer for the hash output. -*/ -void br_md5_out(const br_md5_context *ctx, void *out); - -/** - \brief Save MD5 running state. - - The running state for MD5 (output of the last internal block - processing) is written in the buffer pointed to by `out`. The - number of bytes injected since the last initialisation or reset - call is returned. The context is not modified. - - \param ctx pointer to the context structure. - \param out destination buffer for the running state. - \return the injected total byte length. -*/ -uint64_t br_md5_state(const br_md5_context *ctx, void *out); - -/** - \brief Restore MD5 running state. - - The running state for MD5 is set to the provided values. - - \param ctx pointer to the context structure. - \param stb source buffer for the running state. - \param count the injected total byte length. -*/ -void br_md5_set_state(br_md5_context *ctx, const void *stb, uint64_t count); - -/** - \brief Symbolic identifier for SHA-1. -*/ -#define br_sha1_ID 2 - -/** - \brief SHA-1 output size (in bytes). -*/ -#define br_sha1_SIZE 20 - -/** - \brief Constant vtable for SHA-1. -*/ -extern const br_hash_class br_sha1_vtable; - -/** - \brief SHA-1 context. - - First field is a pointer to the vtable; it is set by the initialisation - function. Other fields are not supposed to be accessed by user code. -*/ -typedef struct -{ - /** - \brief Pointer to vtable for this context. - */ - const br_hash_class *vtable; -#ifndef BR_DOXYGEN_IGNORE - unsigned char buf[64]; - uint64_t count; - uint32_t val[5]; -#endif -} br_sha1_context; - -/** - \brief SHA-1 context initialisation. - - This function initialises or resets a context for a new SHA-1 - computation. It also sets the vtable pointer. - - \param ctx pointer to the context structure. -*/ -void br_sha1_init(br_sha1_context *ctx); - -/** - \brief Inject some data bytes in a running SHA-1 computation. - - The provided context is updated with some data bytes. If the number - of bytes (`len`) is zero, then the data pointer (`data`) is ignored - and may be `NULL`, and this function does nothing. - - \param ctx pointer to the context structure. - \param data pointer to the injected data. - \param len injected data length (in bytes). -*/ -void br_sha1_update(br_sha1_context *ctx, const void *data, size_t len); - -/** - \brief Compute SHA-1 output. - - The SHA-1 output for the concatenation of all bytes injected in the - provided context since the last initialisation or reset call, is - computed and written in the buffer pointed to by `out`. The context - itself is not modified, so extra bytes may be injected afterwards - to continue that computation. - - \param ctx pointer to the context structure. - \param out destination buffer for the hash output. -*/ -void br_sha1_out(const br_sha1_context *ctx, void *out); - -/** - \brief Save SHA-1 running state. - - The running state for SHA-1 (output of the last internal block - processing) is written in the buffer pointed to by `out`. The - number of bytes injected since the last initialisation or reset - call is returned. The context is not modified. - - \param ctx pointer to the context structure. - \param out destination buffer for the running state. - \return the injected total byte length. -*/ -uint64_t br_sha1_state(const br_sha1_context *ctx, void *out); - -/** - \brief Restore SHA-1 running state. - - The running state for SHA-1 is set to the provided values. - - \param ctx pointer to the context structure. - \param stb source buffer for the running state. - \param count the injected total byte length. -*/ -void br_sha1_set_state(br_sha1_context *ctx, const void *stb, uint64_t count); - -/** - \brief Symbolic identifier for SHA-224. -*/ -#define br_sha224_ID 3 - -/** - \brief SHA-224 output size (in bytes). -*/ -#define br_sha224_SIZE 28 - -/** - \brief Constant vtable for SHA-224. -*/ -extern const br_hash_class br_sha224_vtable; - -/** - \brief SHA-224 context. - - First field is a pointer to the vtable; it is set by the initialisation - function. Other fields are not supposed to be accessed by user code. -*/ -typedef struct -{ - /** - \brief Pointer to vtable for this context. - */ - const br_hash_class *vtable; -#ifndef BR_DOXYGEN_IGNORE - unsigned char buf[64]; - uint64_t count; - uint32_t val[8]; -#endif -} br_sha224_context; - -/** - \brief SHA-224 context initialisation. - - This function initialises or resets a context for a new SHA-224 - computation. It also sets the vtable pointer. - - \param ctx pointer to the context structure. -*/ -void br_sha224_init(br_sha224_context *ctx); - -/** - \brief Inject some data bytes in a running SHA-224 computation. - - The provided context is updated with some data bytes. If the number - of bytes (`len`) is zero, then the data pointer (`data`) is ignored - and may be `NULL`, and this function does nothing. - - \param ctx pointer to the context structure. - \param data pointer to the injected data. - \param len injected data length (in bytes). -*/ -void br_sha224_update(br_sha224_context *ctx, const void *data, size_t len); - -/** - \brief Compute SHA-224 output. - - The SHA-224 output for the concatenation of all bytes injected in the - provided context since the last initialisation or reset call, is - computed and written in the buffer pointed to by `out`. The context - itself is not modified, so extra bytes may be injected afterwards - to continue that computation. - - \param ctx pointer to the context structure. - \param out destination buffer for the hash output. -*/ -void br_sha224_out(const br_sha224_context *ctx, void *out); - -/** - \brief Save SHA-224 running state. - - The running state for SHA-224 (output of the last internal block - processing) is written in the buffer pointed to by `out`. The - number of bytes injected since the last initialisation or reset - call is returned. The context is not modified. - - \param ctx pointer to the context structure. - \param out destination buffer for the running state. - \return the injected total byte length. -*/ -uint64_t br_sha224_state(const br_sha224_context *ctx, void *out); - -/** - \brief Restore SHA-224 running state. - - The running state for SHA-224 is set to the provided values. - - \param ctx pointer to the context structure. - \param stb source buffer for the running state. - \param count the injected total byte length. -*/ -void br_sha224_set_state(br_sha224_context *ctx, const void *stb, uint64_t count); - -/** - \brief Symbolic identifier for SHA-256. -*/ -#define br_sha256_ID 4 - -/** - \brief SHA-256 output size (in bytes). -*/ -#define br_sha256_SIZE 32 - -/** - \brief Constant vtable for SHA-256. -*/ -extern const br_hash_class br_sha256_vtable; - -#ifdef BR_DOXYGEN_IGNORE -/** - \brief SHA-256 context. - - First field is a pointer to the vtable; it is set by the initialisation - function. Other fields are not supposed to be accessed by user code. -*/ -typedef struct -{ - /** - \brief Pointer to vtable for this context. - */ - const br_hash_class *vtable; -} br_sha256_context; - -#else -typedef br_sha224_context br_sha256_context; -#endif - -/** - \brief SHA-256 context initialisation. - - This function initialises or resets a context for a new SHA-256 - computation. It also sets the vtable pointer. - - \param ctx pointer to the context structure. -*/ -void br_sha256_init(br_sha256_context *ctx); - -#ifdef BR_DOXYGEN_IGNORE -/** - \brief Inject some data bytes in a running SHA-256 computation. - - The provided context is updated with some data bytes. If the number - of bytes (`len`) is zero, then the data pointer (`data`) is ignored - and may be `NULL`, and this function does nothing. - - \param ctx pointer to the context structure. - \param data pointer to the injected data. - \param len injected data length (in bytes). -*/ -void br_sha256_update(br_sha256_context *ctx, const void *data, size_t len); -#else -#define br_sha256_update br_sha224_update -#endif - -/** - \brief Compute SHA-256 output. - - The SHA-256 output for the concatenation of all bytes injected in the - provided context since the last initialisation or reset call, is - computed and written in the buffer pointed to by `out`. The context - itself is not modified, so extra bytes may be injected afterwards - to continue that computation. - - \param ctx pointer to the context structure. - \param out destination buffer for the hash output. -*/ -void br_sha256_out(const br_sha256_context *ctx, void *out); - -#ifdef BR_DOXYGEN_IGNORE -/** - \brief Save SHA-256 running state. - - The running state for SHA-256 (output of the last internal block - processing) is written in the buffer pointed to by `out`. The - number of bytes injected since the last initialisation or reset - call is returned. The context is not modified. - - \param ctx pointer to the context structure. - \param out destination buffer for the running state. - \return the injected total byte length. -*/ -uint64_t br_sha256_state(const br_sha256_context *ctx, void *out); -#else -#define br_sha256_state br_sha224_state -#endif - -#ifdef BR_DOXYGEN_IGNORE -/** - \brief Restore SHA-256 running state. - - The running state for SHA-256 is set to the provided values. - - \param ctx pointer to the context structure. - \param stb source buffer for the running state. - \param count the injected total byte length. -*/ -void br_sha256_set_state(br_sha256_context *ctx, const void *stb, uint64_t count); -#else -#define br_sha256_set_state br_sha224_set_state -#endif - -/** - \brief Symbolic identifier for SHA-384. -*/ -#define br_sha384_ID 5 - -/** - \brief SHA-384 output size (in bytes). -*/ -#define br_sha384_SIZE 48 - -/** - \brief Constant vtable for SHA-384. -*/ -extern const br_hash_class br_sha384_vtable; - -/** - \brief SHA-384 context. - - First field is a pointer to the vtable; it is set by the initialisation - function. Other fields are not supposed to be accessed by user code. -*/ -typedef struct -{ - /** - \brief Pointer to vtable for this context. - */ - const br_hash_class *vtable; -#ifndef BR_DOXYGEN_IGNORE - unsigned char buf[128]; - uint64_t count; - uint64_t val[8]; -#endif -} br_sha384_context; - -/** - \brief SHA-384 context initialisation. - - This function initialises or resets a context for a new SHA-384 - computation. It also sets the vtable pointer. - - \param ctx pointer to the context structure. -*/ -void br_sha384_init(br_sha384_context *ctx); - -/** - \brief Inject some data bytes in a running SHA-384 computation. - - The provided context is updated with some data bytes. If the number - of bytes (`len`) is zero, then the data pointer (`data`) is ignored - and may be `NULL`, and this function does nothing. - - \param ctx pointer to the context structure. - \param data pointer to the injected data. - \param len injected data length (in bytes). -*/ -void br_sha384_update(br_sha384_context *ctx, const void *data, size_t len); - -/** - \brief Compute SHA-384 output. - - The SHA-384 output for the concatenation of all bytes injected in the - provided context since the last initialisation or reset call, is - computed and written in the buffer pointed to by `out`. The context - itself is not modified, so extra bytes may be injected afterwards - to continue that computation. - - \param ctx pointer to the context structure. - \param out destination buffer for the hash output. -*/ -void br_sha384_out(const br_sha384_context *ctx, void *out); - -/** - \brief Save SHA-384 running state. - - The running state for SHA-384 (output of the last internal block - processing) is written in the buffer pointed to by `out`. The - number of bytes injected since the last initialisation or reset - call is returned. The context is not modified. - - \param ctx pointer to the context structure. - \param out destination buffer for the running state. - \return the injected total byte length. -*/ -uint64_t br_sha384_state(const br_sha384_context *ctx, void *out); - -/** - \brief Restore SHA-384 running state. - - The running state for SHA-384 is set to the provided values. - - \param ctx pointer to the context structure. - \param stb source buffer for the running state. - \param count the injected total byte length. -*/ -void br_sha384_set_state(br_sha384_context *ctx, - const void *stb, uint64_t count); - -/** - \brief Symbolic identifier for SHA-512. -*/ -#define br_sha512_ID 6 - -/** - \brief SHA-512 output size (in bytes). -*/ -#define br_sha512_SIZE 64 - -/** - \brief Constant vtable for SHA-512. -*/ -extern const br_hash_class br_sha512_vtable; - -#ifdef BR_DOXYGEN_IGNORE -/** - \brief SHA-512 context. - - First field is a pointer to the vtable; it is set by the initialisation - function. Other fields are not supposed to be accessed by user code. -*/ -typedef struct -{ - /** - \brief Pointer to vtable for this context. - */ - const br_hash_class *vtable; -} br_sha512_context; -#else -typedef br_sha384_context br_sha512_context; -#endif - -/** - \brief SHA-512 context initialisation. - - This function initialises or resets a context for a new SHA-512 - computation. It also sets the vtable pointer. - - \param ctx pointer to the context structure. -*/ -void br_sha512_init(br_sha512_context *ctx); - -#ifdef BR_DOXYGEN_IGNORE -/** - \brief Inject some data bytes in a running SHA-512 computation. - - The provided context is updated with some data bytes. If the number - of bytes (`len`) is zero, then the data pointer (`data`) is ignored - and may be `NULL`, and this function does nothing. - - \param ctx pointer to the context structure. - \param data pointer to the injected data. - \param len injected data length (in bytes). -*/ -void br_sha512_update(br_sha512_context *ctx, const void *data, size_t len); -#else -#define br_sha512_update br_sha384_update -#endif - -/** - \brief Compute SHA-512 output. - - The SHA-512 output for the concatenation of all bytes injected in the - provided context since the last initialisation or reset call, is - computed and written in the buffer pointed to by `out`. The context - itself is not modified, so extra bytes may be injected afterwards - to continue that computation. - - \param ctx pointer to the context structure. - \param out destination buffer for the hash output. -*/ -void br_sha512_out(const br_sha512_context *ctx, void *out); - -#ifdef BR_DOXYGEN_IGNORE -/** - \brief Save SHA-512 running state. - - The running state for SHA-512 (output of the last internal block - processing) is written in the buffer pointed to by `out`. The - number of bytes injected since the last initialisation or reset - call is returned. The context is not modified. - - \param ctx pointer to the context structure. - \param out destination buffer for the running state. - \return the injected total byte length. -*/ -uint64_t br_sha512_state(const br_sha512_context *ctx, void *out); -#else -#define br_sha512_state br_sha384_state -#endif - -#ifdef BR_DOXYGEN_IGNORE -/** - \brief Restore SHA-512 running state. - - The running state for SHA-512 is set to the provided values. - - \param ctx pointer to the context structure. - \param stb source buffer for the running state. - \param count the injected total byte length. -*/ -void br_sha512_set_state(br_sha512_context *ctx, const void *stb, uint64_t count); -#else -#define br_sha512_set_state br_sha384_set_state -#endif - -/* - "md5sha1" is a special hash function that computes both MD5 and SHA-1 - on the same input, and produces a 36-byte output (MD5 and SHA-1 - concatenation, in that order). State size is also 36 bytes. -*/ - -/** - \brief Symbolic identifier for MD5+SHA-1. - - MD5+SHA-1 is the concatenation of MD5 and SHA-1, computed over the - same input. It is not one of the functions identified in TLS, so - we give it a symbolic identifier of value 0. -*/ -#define br_md5sha1_ID 0 - -/** - \brief MD5+SHA-1 output size (in bytes). -*/ -#define br_md5sha1_SIZE 36 - -/** - \brief Constant vtable for MD5+SHA-1. -*/ -extern const br_hash_class br_md5sha1_vtable; - -/** - \brief MD5+SHA-1 context. - - First field is a pointer to the vtable; it is set by the initialisation - function. Other fields are not supposed to be accessed by user code. -*/ -typedef struct -{ - /** - \brief Pointer to vtable for this context. - */ - const br_hash_class *vtable; -#ifndef BR_DOXYGEN_IGNORE - unsigned char buf[64]; - uint64_t count; - uint32_t val_md5[4]; - uint32_t val_sha1[5]; -#endif -} br_md5sha1_context; - -/** - \brief MD5+SHA-1 context initialisation. - - This function initialises or resets a context for a new SHA-512 - computation. It also sets the vtable pointer. - - \param ctx pointer to the context structure. -*/ -void br_md5sha1_init(br_md5sha1_context *ctx); - -/** - \brief Inject some data bytes in a running MD5+SHA-1 computation. - - The provided context is updated with some data bytes. If the number - of bytes (`len`) is zero, then the data pointer (`data`) is ignored - and may be `NULL`, and this function does nothing. - - \param ctx pointer to the context structure. - \param data pointer to the injected data. - \param len injected data length (in bytes). -*/ -void br_md5sha1_update(br_md5sha1_context *ctx, const void *data, size_t len); - -/** - \brief Compute MD5+SHA-1 output. - - The MD5+SHA-1 output for the concatenation of all bytes injected in the - provided context since the last initialisation or reset call, is - computed and written in the buffer pointed to by `out`. The context - itself is not modified, so extra bytes may be injected afterwards - to continue that computation. - - \param ctx pointer to the context structure. - \param out destination buffer for the hash output. -*/ -void br_md5sha1_out(const br_md5sha1_context *ctx, void *out); - -/** - \brief Save MD5+SHA-1 running state. - - The running state for MD5+SHA-1 (output of the last internal block - processing) is written in the buffer pointed to by `out`. The - number of bytes injected since the last initialisation or reset - call is returned. The context is not modified. - - \param ctx pointer to the context structure. - \param out destination buffer for the running state. - \return the injected total byte length. -*/ -uint64_t br_md5sha1_state(const br_md5sha1_context *ctx, void *out); - -/** - \brief Restore MD5+SHA-1 running state. - - The running state for MD5+SHA-1 is set to the provided values. - - \param ctx pointer to the context structure. - \param stb source buffer for the running state. - \param count the injected total byte length. -*/ -void br_md5sha1_set_state(br_md5sha1_context *ctx, - const void *stb, uint64_t count); - -/** - \brief Aggregate context for configurable hash function support. - - The `br_hash_compat_context` type is a type which is large enough to - serve as context for all standard hash functions defined above. -*/ -typedef union -{ - const br_hash_class *vtable; - br_md5_context md5; - br_sha1_context sha1; - br_sha224_context sha224; - br_sha256_context sha256; - br_sha384_context sha384; - br_sha512_context sha512; - br_md5sha1_context md5sha1; -} br_hash_compat_context; - -/* - The multi-hasher is a construct that handles hashing of the same input - data with several hash functions, with a single shared input buffer. - It can handle MD5, SHA-1, SHA-224, SHA-256, SHA-384 and SHA-512 - simultaneously, though which functions are activated depends on - the set implementation pointers. -*/ - -/** - \brief Multi-hasher context structure. - - The multi-hasher runs up to six hash functions in the standard TLS list - (MD5, SHA-1, SHA-224, SHA-256, SHA-384 and SHA-512) in parallel, over - the same input. - - The multi-hasher does _not_ follow the OOP structure with a vtable. - Instead, it is configured with the vtables of the hash functions it - should run. Structure fields are not supposed to be accessed directly. -*/ -typedef struct -{ -#ifndef BR_DOXYGEN_IGNORE - unsigned char buf[128]; - uint64_t count; - uint32_t val_32[25]; - uint64_t val_64[16]; - const br_hash_class *impl[6]; -#endif -} br_multihash_context; - -/** - \brief Clear a multi-hasher context. - - This should always be called once on a given context, _before_ setting - the implementation pointers. - - \param ctx the multi-hasher context. -*/ -void br_multihash_zero(br_multihash_context *ctx); - -/** - \brief Set a hash function implementation. - - Implementations shall be set _after_ clearing the context (with - `br_multihash_zero()`) but _before_ initialising the computation - (with `br_multihash_init()`). The hash function implementation - MUST be one of the standard hash functions (MD5, SHA-1, SHA-224, - SHA-256, SHA-384 or SHA-512); it may also be `NULL` to remove - an implementation from the multi-hasher. - - \param ctx the multi-hasher context. - \param id the hash function symbolic identifier. - \param impl the hash function vtable, or `NULL`. -*/ -static inline void -br_multihash_setimpl(br_multihash_context *ctx, int id, const br_hash_class *impl) -{ - /* - This code relies on hash functions ID being values 1 to 6, - in the MD5 to SHA-512 order. - */ - ctx->impl[id - 1] = impl; -} - -/** - \brief Get a hash function implementation. - - This function returns the currently configured vtable for a given - hash function (by symbolic ID). If no such function was configured in - the provided multi-hasher context, then this function returns `NULL`. - - \param ctx the multi-hasher context. - \param id the hash function symbolic identifier. - \return the hash function vtable, or `NULL`. -*/ -static inline const br_hash_class * -br_multihash_getimpl(const br_multihash_context *ctx, int id) -{ - return ctx->impl[id - 1]; -} - -/** - \brief Reset a multi-hasher context. - - This function prepares the context for a new hashing computation, - for all implementations configured at that point. - - \param ctx the multi-hasher context. -*/ -void br_multihash_init(br_multihash_context *ctx); - -/** - \brief Inject some data bytes in a running multi-hashing computation. - - The provided context is updated with some data bytes. If the number - of bytes (`len`) is zero, then the data pointer (`data`) is ignored - and may be `NULL`, and this function does nothing. - - \param ctx pointer to the context structure. - \param data pointer to the injected data. - \param len injected data length (in bytes). -*/ -void br_multihash_update(br_multihash_context *ctx, const void *data, size_t len); - -/** - \brief Compute a hash output from a multi-hasher. - - The hash output for the concatenation of all bytes injected in the - provided context since the last initialisation or reset call, is - computed and written in the buffer pointed to by `dst`. The hash - function to use is identified by `id` and must be one of the standard - hash functions. If that hash function was indeed configured in the - multi-hasher context, the corresponding hash value is written in - `dst` and its length (in bytes) is returned. If the hash function - was _not_ configured, then nothing is written in `dst` and 0 is - returned. - - The context itself is not modified, so extra bytes may be injected - afterwards to continue the hash computations. - - \param ctx pointer to the context structure. - \param id the hash function symbolic identifier. - \param dst destination buffer for the hash output. - \return the hash output length (in bytes), or 0. -*/ -size_t br_multihash_out(const br_multihash_context *ctx, int id, void *dst); - -/** - \brief Type for a GHASH implementation. - - GHASH is a sort of keyed hash meant to be used to implement GCM in - combination with a block cipher (with 16-byte blocks). - - The `y` array has length 16 bytes and is used for input and output; in - a complete GHASH run, it starts with an all-zero value. `h` is a 16-byte - value that serves as key (it is derived from the encryption key in GCM, - using the block cipher). The data length (`len`) is expressed in bytes. - The `y` array is updated. - - If the data length is not a multiple of 16, then the data is implicitly - padded with zeros up to the next multiple of 16. Thus, when using GHASH - in GCM, this method may be called twice, for the associated data and - for the ciphertext, respectively; the zero-padding implements exactly - the GCM rules. - - \param y the array to update. - \param h the GHASH key. - \param data the input data (may be `NULL` if `len` is zero). - \param len the input data length (in bytes). -*/ -typedef void (*br_ghash)(void *y, const void *h, const void *data, size_t len); - -/** - \brief GHASH implementation using multiplications (mixed 32-bit). - - This implementation uses multiplications of 32-bit values, with a - 64-bit result. It is constant-time (if multiplications are - constant-time). - - \param y the array to update. - \param h the GHASH key. - \param data the input data (may be `NULL` if `len` is zero). - \param len the input data length (in bytes). -*/ -void br_ghash_ctmul(void *y, const void *h, const void *data, size_t len); - -/** - \brief GHASH implementation using multiplications (strict 32-bit). - - This implementation uses multiplications of 32-bit values, with a - 32-bit result. It is usually somewhat slower than `br_ghash_ctmul()`, - but it is expected to be faster on architectures for which the - 32-bit multiplication opcode does not yield the upper 32 bits of the - product. It is constant-time (if multiplications are constant-time). - - \param y the array to update. - \param h the GHASH key. - \param data the input data (may be `NULL` if `len` is zero). - \param len the input data length (in bytes). -*/ -void br_ghash_ctmul32(void *y, const void *h, const void *data, size_t len); - -/** - \brief GHASH implementation using multiplications (64-bit). - - This implementation uses multiplications of 64-bit values, with a - 64-bit result. It is constant-time (if multiplications are - constant-time). It is substantially faster than `br_ghash_ctmul()` - and `br_ghash_ctmul32()` on most 64-bit architectures. - - \param y the array to update. - \param h the GHASH key. - \param data the input data (may be `NULL` if `len` is zero). - \param len the input data length (in bytes). -*/ -void br_ghash_ctmul64(void *y, const void *h, const void *data, size_t len); - -/** - \brief GHASH implementation using the `pclmulqdq` opcode (part of the - AES-NI instructions). - - This implementation is available only on x86 platforms where the - compiler supports the relevant intrinsic functions. Even if the - compiler supports these functions, the local CPU might not support - the `pclmulqdq` opcode, meaning that a call will fail with an - illegal instruction exception. To safely obtain a pointer to this - function when supported (or 0 otherwise), use `br_ghash_pclmul_get()`. - - \param y the array to update. - \param h the GHASH key. - \param data the input data (may be `NULL` if `len` is zero). - \param len the input data length (in bytes). -*/ -void br_ghash_pclmul(void *y, const void *h, const void *data, size_t len); - -/** - \brief Obtain the `pclmul` GHASH implementation, if available. - - If the `pclmul` implementation was compiled in the library (depending - on the compiler abilities) _and_ the local CPU appears to support the - opcode, then this function will return a pointer to the - `br_ghash_pclmul()` function. Otherwise, it will return `0`. - - \return the `pclmul` GHASH implementation, or `0`. -*/ -br_ghash br_ghash_pclmul_get(); - -/** - \brief GHASH implementation using the POWER8 opcodes. - - This implementation is available only on POWER8 platforms (and later). - To safely obtain a pointer to this function when supported (or 0 - otherwise), use `br_ghash_pwr8_get()`. - - \param y the array to update. - \param h the GHASH key. - \param data the input data (may be `NULL` if `len` is zero). - \param len the input data length (in bytes). -*/ -void br_ghash_pwr8(void *y, const void *h, const void *data, size_t len); - -/** - \brief Obtain the `pwr8` GHASH implementation, if available. - - If the `pwr8` implementation was compiled in the library (depending - on the compiler abilities) _and_ the local CPU appears to support the - opcode, then this function will return a pointer to the - `br_ghash_pwr8()` function. Otherwise, it will return `0`. - - \return the `pwr8` GHASH implementation, or `0`. -*/ -br_ghash br_ghash_pwr8_get(); - -#ifdef __cplusplus -} -#endif - -#endif // BR_BEARSSL_HASH_H__ diff --git a/lib/AsyncWebServer_ESP32_W5500/src/Crypto/md5.h b/lib/AsyncWebServer_ESP32_W5500/src/Crypto/md5.h deleted file mode 100644 index 5d58340..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/Crypto/md5.h +++ /dev/null @@ -1,95 +0,0 @@ -/** - \file md5.h - - Based on XySSL: Copyright (C) 2006-2008 Christophe Devine - - Copyright (C) 2009 Paul Bakker - - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - * * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * * Neither the names of PolarSSL or XySSL nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#pragma once - -#ifndef LWIP_INCLUDED_POLARSSL_MD5_H -#define LWIP_INCLUDED_POLARSSL_MD5_H - -#include "AsyncWebServer_ESP32_W5500_Debug.h" - -/** - \brief MD5 context structure -*/ -typedef struct -{ - unsigned long total[2]; /*!< number of bytes processed */ - unsigned long state[4]; /*!< intermediate digest state */ - unsigned char buffer[64]; /*!< data block being processed */ -} -md5_context; - -#ifdef __cplusplus -extern "C" { -#endif - -/** - \brief MD5 context setup - - \param ctx context to be initialized -*/ -void md5_starts( md5_context *ctx ); - -/** - \brief MD5 process buffer - - \param ctx MD5 context - \param input buffer holding the data - \param ilen length of the input data -*/ -void md5_update( md5_context *ctx, const unsigned char *input, int ilen ); - -/** - \brief MD5 final digest - - \param ctx MD5 context - \param output MD5 checksum result -*/ -void md5_finish( md5_context *ctx, unsigned char output[16] ); - -/** - \brief Output = MD5( input buffer ) - - \param input buffer holding the data - \param ilen length of the input data - \param output MD5 checksum result -*/ -void md5( unsigned char *input, int ilen, unsigned char output[16] ); - -#ifdef __cplusplus -} -#endif - -#endif /* LWIP_INCLUDED_POLARSSL_MD5_H */ diff --git a/lib/AsyncWebServer_ESP32_W5500/src/Crypto/sha1.c b/lib/AsyncWebServer_ESP32_W5500/src/Crypto/sha1.c deleted file mode 100644 index 0bd892d..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/Crypto/sha1.c +++ /dev/null @@ -1,330 +0,0 @@ -/* - FIPS-180-1 compliant SHA-1 implementation - - Based on XySSL: Copyright (C) 2006-2008 Christophe Devine - - Copyright (C) 2009 Paul Bakker - - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - * * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * * Neither the names of PolarSSL or XySSL nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ -/* - The SHA-1 standard was published by NIST in 1993. - - http://www.itl.nist.gov/fipspubs/fip180-1.htm -*/ - -#include "sha1.h" - -#include - -/* - 32-bit integer manipulation macros (big endian) -*/ -#ifndef GET_ULONG_BE -#define GET_ULONG_BE(n,b,i) \ -{ \ - (n) = ( (unsigned long) (b)[(i) ] << 24 ) \ - | ( (unsigned long) (b)[(i) + 1] << 16 ) \ - | ( (unsigned long) (b)[(i) + 2] << 8 ) \ - | ( (unsigned long) (b)[(i) + 3] ); \ -} -#endif - -#ifndef PUT_ULONG_BE -#define PUT_ULONG_BE(n,b,i) \ -{ \ - (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \ - (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \ - (b)[(i) + 2] = (unsigned char) ( (n) >> 8 ); \ - (b)[(i) + 3] = (unsigned char) ( (n) ); \ -} -#endif - -/* - SHA-1 context setup -*/ -void sha1_starts( sha1_context *ctx ) -{ - ctx->total[0] = 0; - ctx->total[1] = 0; - - ctx->state[0] = 0x67452301; - ctx->state[1] = 0xEFCDAB89; - ctx->state[2] = 0x98BADCFE; - ctx->state[3] = 0x10325476; - ctx->state[4] = 0xC3D2E1F0; -} - -static void sha1_process( sha1_context *ctx, const unsigned char data[64] ) -{ - unsigned long temp, W[16], A, B, C, D, E; - - GET_ULONG_BE( W[ 0], data, 0 ); - GET_ULONG_BE( W[ 1], data, 4 ); - GET_ULONG_BE( W[ 2], data, 8 ); - GET_ULONG_BE( W[ 3], data, 12 ); - GET_ULONG_BE( W[ 4], data, 16 ); - GET_ULONG_BE( W[ 5], data, 20 ); - GET_ULONG_BE( W[ 6], data, 24 ); - GET_ULONG_BE( W[ 7], data, 28 ); - GET_ULONG_BE( W[ 8], data, 32 ); - GET_ULONG_BE( W[ 9], data, 36 ); - GET_ULONG_BE( W[10], data, 40 ); - GET_ULONG_BE( W[11], data, 44 ); - GET_ULONG_BE( W[12], data, 48 ); - GET_ULONG_BE( W[13], data, 52 ); - GET_ULONG_BE( W[14], data, 56 ); - GET_ULONG_BE( W[15], data, 60 ); - -#define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n))) - -#define R(t) \ -( \ - temp = W[(t - 3) & 0x0F] ^ W[(t - 8) & 0x0F] ^ \ - W[(t - 14) & 0x0F] ^ W[ t & 0x0F], \ - ( W[t & 0x0F] = S(temp,1) ) \ -) - -#define P(a,b,c,d,e,x) \ -{ \ - e += S(a,5) + F(b,c,d) + K + x; b = S(b,30); \ -} - - A = ctx->state[0]; - B = ctx->state[1]; - C = ctx->state[2]; - D = ctx->state[3]; - E = ctx->state[4]; - -#define F(x,y,z) (z ^ (x & (y ^ z))) -#define K 0x5A827999 - - P( A, B, C, D, E, W[0] ); - P( E, A, B, C, D, W[1] ); - P( D, E, A, B, C, W[2] ); - P( C, D, E, A, B, W[3] ); - P( B, C, D, E, A, W[4] ); - P( A, B, C, D, E, W[5] ); - P( E, A, B, C, D, W[6] ); - P( D, E, A, B, C, W[7] ); - P( C, D, E, A, B, W[8] ); - P( B, C, D, E, A, W[9] ); - P( A, B, C, D, E, W[10] ); - P( E, A, B, C, D, W[11] ); - P( D, E, A, B, C, W[12] ); - P( C, D, E, A, B, W[13] ); - P( B, C, D, E, A, W[14] ); - P( A, B, C, D, E, W[15] ); - P( E, A, B, C, D, R(16) ); - P( D, E, A, B, C, R(17) ); - P( C, D, E, A, B, R(18) ); - P( B, C, D, E, A, R(19) ); - -#undef K -#undef F - -#define F(x,y,z) (x ^ y ^ z) -#define K 0x6ED9EBA1 - - P( A, B, C, D, E, R(20) ); - P( E, A, B, C, D, R(21) ); - P( D, E, A, B, C, R(22) ); - P( C, D, E, A, B, R(23) ); - P( B, C, D, E, A, R(24) ); - P( A, B, C, D, E, R(25) ); - P( E, A, B, C, D, R(26) ); - P( D, E, A, B, C, R(27) ); - P( C, D, E, A, B, R(28) ); - P( B, C, D, E, A, R(29) ); - P( A, B, C, D, E, R(30) ); - P( E, A, B, C, D, R(31) ); - P( D, E, A, B, C, R(32) ); - P( C, D, E, A, B, R(33) ); - P( B, C, D, E, A, R(34) ); - P( A, B, C, D, E, R(35) ); - P( E, A, B, C, D, R(36) ); - P( D, E, A, B, C, R(37) ); - P( C, D, E, A, B, R(38) ); - P( B, C, D, E, A, R(39) ); - -#undef K -#undef F - -#define F(x,y,z) ((x & y) | (z & (x | y))) -#define K 0x8F1BBCDC - - P( A, B, C, D, E, R(40) ); - P( E, A, B, C, D, R(41) ); - P( D, E, A, B, C, R(42) ); - P( C, D, E, A, B, R(43) ); - P( B, C, D, E, A, R(44) ); - P( A, B, C, D, E, R(45) ); - P( E, A, B, C, D, R(46) ); - P( D, E, A, B, C, R(47) ); - P( C, D, E, A, B, R(48) ); - P( B, C, D, E, A, R(49) ); - P( A, B, C, D, E, R(50) ); - P( E, A, B, C, D, R(51) ); - P( D, E, A, B, C, R(52) ); - P( C, D, E, A, B, R(53) ); - P( B, C, D, E, A, R(54) ); - P( A, B, C, D, E, R(55) ); - P( E, A, B, C, D, R(56) ); - P( D, E, A, B, C, R(57) ); - P( C, D, E, A, B, R(58) ); - P( B, C, D, E, A, R(59) ); - -#undef K -#undef F - -#define F(x,y,z) (x ^ y ^ z) -#define K 0xCA62C1D6 - - P( A, B, C, D, E, R(60) ); - P( E, A, B, C, D, R(61) ); - P( D, E, A, B, C, R(62) ); - P( C, D, E, A, B, R(63) ); - P( B, C, D, E, A, R(64) ); - P( A, B, C, D, E, R(65) ); - P( E, A, B, C, D, R(66) ); - P( D, E, A, B, C, R(67) ); - P( C, D, E, A, B, R(68) ); - P( B, C, D, E, A, R(69) ); - P( A, B, C, D, E, R(70) ); - P( E, A, B, C, D, R(71) ); - P( D, E, A, B, C, R(72) ); - P( C, D, E, A, B, R(73) ); - P( B, C, D, E, A, R(74) ); - P( A, B, C, D, E, R(75) ); - P( E, A, B, C, D, R(76) ); - P( D, E, A, B, C, R(77) ); - P( C, D, E, A, B, R(78) ); - P( B, C, D, E, A, R(79) ); - -#undef K -#undef F - - ctx->state[0] += A; - ctx->state[1] += B; - ctx->state[2] += C; - ctx->state[3] += D; - ctx->state[4] += E; -} - -/* - SHA-1 process buffer -*/ -void sha1_update( sha1_context *ctx, const unsigned char *input, int ilen ) -{ - int fill; - unsigned long left; - - if ( ilen <= 0 ) - return; - - left = ctx->total[0] & 0x3F; - fill = 64 - left; - - ctx->total[0] += ilen; - ctx->total[0] &= 0xFFFFFFFF; - - if ( ctx->total[0] < (unsigned long) ilen ) - ctx->total[1]++; - - if ( left && ilen >= fill ) - { - memcpy( (void *) (ctx->buffer + left), - input, fill ); - sha1_process( ctx, ctx->buffer ); - input += fill; - ilen -= fill; - left = 0; - } - - while ( ilen >= 64 ) - { - sha1_process( ctx, input ); - input += 64; - ilen -= 64; - } - - if ( ilen > 0 ) - { - memcpy( (void *) (ctx->buffer + left), - input, ilen ); - } -} - -static const unsigned char sha1_padding[64] = -{ - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - -/* - SHA-1 final digest -*/ -void sha1_finish( sha1_context *ctx, unsigned char output[SHA1_BUFFER_SIZE] ) -{ - unsigned long last, padn; - unsigned long high, low; - unsigned char msglen[8]; - - high = ( ctx->total[0] >> 29 ) - | ( ctx->total[1] << 3 ); - low = ( ctx->total[0] << 3 ); - - PUT_ULONG_BE( high, msglen, 0 ); - PUT_ULONG_BE( low, msglen, 4 ); - - last = ctx->total[0] & 0x3F; - padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last ); - - sha1_update( ctx, sha1_padding, padn ); - sha1_update( ctx, msglen, 8 ); - - PUT_ULONG_BE( ctx->state[0], output, 0 ); - PUT_ULONG_BE( ctx->state[1], output, 4 ); - PUT_ULONG_BE( ctx->state[2], output, 8 ); - PUT_ULONG_BE( ctx->state[3], output, 12 ); - PUT_ULONG_BE( ctx->state[4], output, 16 ); -} - -/* - output = SHA-1( input buffer ) -*/ -void sha1( unsigned char *input, int ilen, unsigned char output[SHA1_BUFFER_SIZE] ) -{ - sha1_context ctx; - - sha1_starts( &ctx ); - sha1_update( &ctx, input, ilen ); - sha1_finish( &ctx, output ); -} diff --git a/lib/AsyncWebServer_ESP32_W5500/src/Crypto/sha1.h b/lib/AsyncWebServer_ESP32_W5500/src/Crypto/sha1.h deleted file mode 100644 index 3f69c21..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/Crypto/sha1.h +++ /dev/null @@ -1,101 +0,0 @@ -/** - \file sha1.h - - Based on XySSL: Copyright (C) 2006-2008 Christophe Devine - - Copyright (C) 2009 Paul Bakker - - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - * * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * * Neither the names of PolarSSL or XySSL nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#pragma once - -#ifndef LWIP_INCLUDED_POLARSSL_SHA1_H -#define LWIP_INCLUDED_POLARSSL_SHA1_H - -#include "AsyncWebServer_ESP32_W5500_Debug.h" - -#ifdef SHA1_BUFFER_SIZE - #undef SHA1_BUFFER_SIZE -#endif - -#define SHA1_BUFFER_SIZE 20 - -/** - \brief SHA-1 context structure -*/ -typedef struct -{ - unsigned long total[2]; /*!< number of bytes processed */ - unsigned long state[5]; /*!< intermediate digest state */ - unsigned char buffer[64]; /*!< data block being processed */ -} -sha1_context; - -#ifdef __cplusplus -extern "C" { -#endif - -/** - \brief SHA-1 context setup - - \param ctx context to be initialized -*/ -void sha1_starts( sha1_context *ctx ); - -/** - \brief SHA-1 process buffer - - \param ctx SHA-1 context - \param input buffer holding the data - \param ilen length of the input data -*/ -void sha1_update( sha1_context *ctx, const unsigned char *input, int ilen ); - -/** - \brief SHA-1 final digest - - \param ctx SHA-1 context - \param output SHA-1 checksum result -*/ -void sha1_finish( sha1_context *ctx, unsigned char output[SHA1_BUFFER_SIZE] ); - -/** - \brief Output = SHA-1( input buffer ) - - \param input buffer holding the data - \param ilen length of the input data - \param output SHA-1 checksum result -*/ -void sha1( unsigned char *input, int ilen, unsigned char output[SHA1_BUFFER_SIZE] ); - -#ifdef __cplusplus -} -#endif - -#endif /* LWIP_INCLUDED_POLARSSL_SHA1_H */ diff --git a/lib/AsyncWebServer_ESP32_W5500/src/ESP32_W5500_SPIFFSEditor.cpp b/lib/AsyncWebServer_ESP32_W5500/src/ESP32_W5500_SPIFFSEditor.cpp deleted file mode 100644 index 45efd18..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/ESP32_W5500_SPIFFSEditor.cpp +++ /dev/null @@ -1,689 +0,0 @@ -/**************************************************************************************************************************** - ESP32_W5500_SPIFFSEditor.cpp - Dead simple Ethernet AsyncWebServer. - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - - Original author: Hristo Gochkov - - Copyright (c) 2016 Hristo Gochkov. All rights reserved. - - This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License along with this library; - if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Version: 1.6.4 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2 - 1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples - 1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error - *****************************************************************************************************************************/ - -#include "ESP32_W5500_SPIFFSEditor.h" -#include - -///////////////////////////////////////////////// - -//File: edit.htm.gz, Size: 4151 -#define edit_htm_gz_len 4151 - -const uint8_t edit_htm_gz[] PROGMEM = -{ - 0x1F, 0x8B, 0x08, 0x08, 0xB8, 0x94, 0xB1, 0x59, 0x00, 0x03, 0x65, 0x64, 0x69, 0x74, 0x2E, 0x68, - 0x74, 0x6D, 0x00, 0xB5, 0x3A, 0x0B, 0x7B, 0xDA, 0xB8, 0xB2, 0x7F, 0xC5, 0x71, 0xCF, 0x66, 0xED, - 0x83, 0x31, 0x90, 0xA4, 0xD9, 0xD6, 0xC4, 0xC9, 0x42, 0x92, 0x36, 0x6D, 0xF3, 0x6A, 0x80, 0xB6, - 0x69, 0x4F, 0xEE, 0x7E, 0xC2, 0x16, 0xA0, 0xC6, 0x96, 0x5D, 0x5B, 0x0E, 0x49, 0x59, 0xFE, 0xFB, - 0x9D, 0x91, 0x6C, 0xB0, 0x09, 0x69, 0x77, 0xCF, 0xBD, 0xBB, 0xDD, 0x2D, 0x92, 0x46, 0x33, 0x9A, - 0x19, 0xCD, 0x53, 0xDE, 0xBD, 0x8D, 0xA3, 0x8B, 0xC3, 0xFE, 0xF5, 0xE5, 0xB1, 0x36, 0x11, 0x61, - 0xB0, 0xBF, 0x87, 0x7F, 0x6B, 0x01, 0xE1, 0x63, 0x97, 0xF2, 0xFD, 0x3D, 0xC1, 0x44, 0x40, 0xF7, - 0x8F, 0x7B, 0x97, 0xDA, 0xB1, 0xCF, 0x44, 0x94, 0xEC, 0x35, 0xD4, 0xCA, 0x5E, 0x2A, 0x1E, 0x02, - 0xAA, 0x85, 0xD4, 0x67, 0xC4, 0x4D, 0xBD, 0x84, 0xC2, 0x66, 0xDB, 0x0B, 0x67, 0xDF, 0xEB, 0x8C, - 0xFB, 0xF4, 0xDE, 0xD9, 0x6E, 0x36, 0xDB, 0x71, 0x94, 0x32, 0xC1, 0x22, 0xEE, 0x90, 0x61, 0x1A, - 0x05, 0x99, 0xA0, 0xED, 0x80, 0x8E, 0x84, 0xF3, 0x3C, 0xBE, 0x6F, 0x0F, 0xA3, 0xC4, 0xA7, 0x89, - 0xD3, 0x8A, 0xEF, 0x35, 0x00, 0x31, 0x5F, 0x7B, 0xB6, 0xB3, 0xB3, 0xD3, 0x1E, 0x12, 0xEF, 0x76, - 0x9C, 0x44, 0x19, 0xF7, 0xEB, 0x5E, 0x14, 0x44, 0x89, 0xF3, 0x6C, 0xF4, 0x1C, 0xFF, 0xB4, 0x7D, - 0x96, 0xC6, 0x01, 0x79, 0x70, 0x78, 0xC4, 0x29, 0xE0, 0xDE, 0xD7, 0xD3, 0x09, 0xF1, 0xA3, 0xA9, - 0xD3, 0xD4, 0x9A, 0x5A, 0xAB, 0x09, 0x44, 0x92, 0xF1, 0x90, 0x18, 0x4D, 0x0B, 0xFF, 0xD8, 0x3B, - 0x66, 0x7B, 0x14, 0x71, 0x51, 0x4F, 0xD9, 0x77, 0xEA, 0xB4, 0xB6, 0xE0, 0x34, 0x39, 0x1D, 0x91, - 0x90, 0x05, 0x0F, 0x4E, 0x4A, 0x78, 0x5A, 0x4F, 0x69, 0xC2, 0x46, 0x6A, 0x79, 0x4A, 0xD9, 0x78, - 0x22, 0x9C, 0xDF, 0x9A, 0xCD, 0x39, 0xF0, 0xAF, 0x65, 0xC1, 0x2C, 0x60, 0x29, 0x20, 0xA3, 0x78, - 0xEA, 0x3C, 0x11, 0xC5, 0x4E, 0x53, 0xB1, 0xDE, 0x6C, 0x87, 0x24, 0x19, 0x33, 0x0E, 0x83, 0x98, - 0xF8, 0x3E, 0xE3, 0x63, 0x47, 0xA1, 0x05, 0x6C, 0xB6, 0x90, 0x36, 0xA1, 0x01, 0x11, 0xEC, 0x8E, - 0xB6, 0x43, 0xC6, 0xEB, 0x53, 0xE6, 0x8B, 0x89, 0xB3, 0x0B, 0x3C, 0xB6, 0xBD, 0x2C, 0x49, 0x41, - 0xA6, 0x38, 0x62, 0x5C, 0xD0, 0x44, 0xA2, 0xA5, 0x31, 0xE1, 0xB3, 0x5C, 0x54, 0x54, 0x40, 0x21, - 0x27, 0xE3, 0x01, 0xE3, 0xB4, 0x3E, 0x0C, 0x22, 0xEF, 0x76, 0x71, 0xD2, 0x6E, 0x7C, 0x9F, 0x9F, - 0xE5, 0x4C, 0xA2, 0x3B, 0x9A, 0xCC, 0x96, 0xEA, 0x92, 0xD8, 0x15, 0x60, 0x85, 0x34, 0xA5, 0x74, - 0x6E, 0x8B, 0xBB, 0x0C, 0xA0, 0x96, 0xFC, 0x05, 0x29, 0x17, 0xFC, 0x2F, 0x45, 0x5A, 0x11, 0x5C, - 0xA1, 0x30, 0x1E, 0x67, 0x62, 0xF6, 0xF8, 0x2A, 0xA3, 0x98, 0x78, 0x4C, 0x3C, 0xA0, 0xFC, 0xB0, - 0x6D, 0x86, 0xBA, 0x04, 0xAC, 0x24, 0x24, 0x81, 0x86, 0x3A, 0xD7, 0x3E, 0xD0, 0xC4, 0x27, 0x9C, - 0x58, 0x9D, 0x84, 0x91, 0xC0, 0xEA, 0x2D, 0xB5, 0x5E, 0x0F, 0xA3, 0xEF, 0xF5, 0x0C, 0xC6, 0x30, - 0x0F, 0xA8, 0x27, 0x94, 0x92, 0xE1, 0x1E, 0x86, 0xB7, 0x4C, 0x3C, 0x06, 0x3C, 0x5A, 0x28, 0xA9, - 0x4B, 0x2A, 0x69, 0xA2, 0x2E, 0xB0, 0x25, 0xD5, 0x83, 0x1C, 0x4B, 0xC9, 0x95, 0x50, 0xF5, 0x61, - 0x24, 0x44, 0x14, 0x4A, 0x93, 0x5B, 0x08, 0xAC, 0x49, 0xAB, 0x79, 0xF1, 0xE8, 0x46, 0xD6, 0x6B, - 0xBF, 0x44, 0xBE, 0x0D, 0x7A, 0x15, 0xCC, 0x23, 0x41, 0x9D, 0x04, 0x6C, 0xCC, 0x9D, 0x90, 0xF9, - 0x7E, 0x40, 0x4B, 0x56, 0xEB, 0x64, 0x49, 0x60, 0xF8, 0x44, 0x10, 0x87, 0x85, 0x64, 0x4C, 0x1B, - 0x31, 0x1F, 0x03, 0x34, 0xA5, 0xBB, 0x3B, 0x16, 0xFB, 0xD0, 0xBD, 0xB8, 0x9A, 0x36, 0xDF, 0xBD, - 0x1E, 0x47, 0x1D, 0xF8, 0xE7, 0xBC, 0x37, 0x98, 0x1C, 0x0F, 0xC6, 0x30, 0xEA, 0xE2, 0xB4, 0xF3, - 0xFE, 0xB0, 0xF3, 0x1E, 0x7E, 0x0E, 0x5B, 0xB5, 0xAF, 0xA3, 0x6F, 0xB8, 0xD0, 0x7D, 0xED, 0x77, - 0xFB, 0x83, 0xE3, 0x4E, 0xE7, 0x5D, 0xE3, 0xCD, 0xF9, 0xF4, 0xE3, 0xBB, 0x5D, 0x04, 0x77, 0x83, - 0xE6, 0xD5, 0x87, 0x49, 0x73, 0xB0, 0xF5, 0x32, 0xF4, 0x4F, 0xFC, 0x89, 0x17, 0x0E, 0x3A, 0xEF, - 0x3F, 0x5E, 0xDD, 0x5D, 0x87, 0x83, 0x71, 0xEF, 0x63, 0x6B, 0xF2, 0x79, 0xEB, 0x43, 0xEF, 0xF3, - 0xC7, 0x57, 0xB7, 0xF4, 0xD3, 0xC9, 0xDB, 0xCF, 0xFD, 0x29, 0x20, 0x1C, 0x45, 0xBD, 0xC1, 0x55, - 0xF7, 0x43, 0x77, 0xFC, 0xB9, 0xEB, 0x1D, 0xDF, 0x0F, 0x83, 0xF3, 0xEE, 0xEB, 0xCE, 0xB0, 0xB3, - 0xE5, 0x51, 0x3A, 0xEE, 0x5F, 0x75, 0xB3, 0x37, 0xEF, 0x2E, 0xC6, 0x8C, 0x4D, 0x7A, 0x9F, 0xCF, - 0xFB, 0xDE, 0xE1, 0xF3, 0xD3, 0xC1, 0x49, 0x87, 0x4D, 0xCE, 0xDF, 0x5E, 0x35, 0x6F, 0x5F, 0xBF, - 0x3B, 0x3C, 0xF2, 0xAE, 0xDF, 0x5E, 0xEF, 0x1E, 0x6D, 0x37, 0x7E, 0xFB, 0xED, 0xCC, 0xBF, 0x60, - 0xBC, 0x7F, 0xF7, 0xBD, 0x33, 0x3E, 0x9C, 0xBE, 0x78, 0x48, 0xFB, 0x93, 0x37, 0x77, 0xBC, 0xF1, - 0x21, 0xFA, 0xFA, 0xE6, 0xE1, 0x0C, 0xFE, 0xBB, 0xBC, 0xAC, 0x0D, 0x7B, 0xAD, 0x74, 0xF0, 0xFE, - 0xCD, 0x87, 0xAD, 0xF4, 0xE5, 0xF3, 0xB8, 0x7B, 0x74, 0x74, 0x17, 0x0E, 0x2F, 0x1B, 0xA1, 0x7F, - 0x3B, 0x12, 0x2F, 0xB6, 0x45, 0x7C, 0x3D, 0xCE, 0x3E, 0x7F, 0x7B, 0xFE, 0x76, 0xD2, 0xB8, 0xA0, - 0xE4, 0x7A, 0x52, 0x7B, 0xF8, 0xFE, 0xF0, 0x62, 0xD2, 0x3F, 0xB9, 0x3B, 0x0F, 0xC8, 0xFD, 0xF9, - 0xB9, 0xF7, 0x3D, 0xAC, 0x05, 0xE4, 0xE5, 0x45, 0x3F, 0x20, 0x49, 0x6B, 0xE0, 0x77, 0x1A, 0xB5, - 0xC3, 0xAD, 0xCE, 0x8E, 0x48, 0xAE, 0x0E, 0xF9, 0xD1, 0xF6, 0xD7, 0xDE, 0x8B, 0x6E, 0xB7, 0x15, - 0x0D, 0xBF, 0x6D, 0xBD, 0xBE, 0xDD, 0x7D, 0x3D, 0xD8, 0x7D, 0x3F, 0x7C, 0xDF, 0xE9, 0xED, 0x74, - 0x07, 0xE4, 0xBA, 0xF7, 0xBE, 0x33, 0xDA, 0x19, 0x4E, 0x26, 0xEF, 0xDE, 0xF5, 0x5F, 0xF9, 0x9D, - 0xEF, 0x49, 0xE7, 0x62, 0xDA, 0xB9, 0x3F, 0x1E, 0x74, 0x4E, 0x6A, 0xEF, 0x8E, 0xCF, 0x9A, 0xAD, - 0xDE, 0xF5, 0xF6, 0xF8, 0x6C, 0x77, 0xDA, 0x4D, 0x8F, 0x3B, 0xEF, 0xBB, 0xCD, 0xF1, 0xDB, 0x5A, - 0x48, 0x3E, 0x47, 0x87, 0xDB, 0xE3, 0x37, 0xBB, 0xEC, 0xF2, 0x9A, 0x74, 0xDE, 0x74, 0xDF, 0xA6, - 0xEC, 0x2A, 0x3C, 0x19, 0x34, 0x3B, 0x9D, 0xD3, 0x0B, 0xFA, 0xEA, 0x70, 0x9B, 0xBC, 0xDB, 0xF2, - 0x3E, 0x82, 0xFE, 0x07, 0x9F, 0xE8, 0x6F, 0xB5, 0xCE, 0xF4, 0xA2, 0x19, 0x78, 0x2F, 0x69, 0xFF, - 0xE4, 0xBA, 0x2F, 0x6F, 0xE7, 0x38, 0x78, 0xD5, 0xBF, 0xED, 0x65, 0xEF, 0xC3, 0xC3, 0x43, 0x53, - 0xE3, 0x51, 0x3D, 0xA1, 0x31, 0x25, 0xA2, 0x1C, 0xAE, 0x16, 0xFE, 0x01, 0xB6, 0xB5, 0xB4, 0xC2, - 0xDC, 0x4F, 0x05, 0xBD, 0x17, 0x75, 0x9F, 0x7A, 0x51, 0x42, 0xE4, 0x1E, 0x40, 0xA0, 0x09, 0x9A, - 0xD8, 0xFC, 0x77, 0x19, 0x3F, 0x35, 0x15, 0x3F, 0x35, 0xC2, 0x7D, 0xCD, 0x28, 0x1C, 0x01, 0x83, - 0x87, 0x4F, 0xEF, 0x98, 0x47, 0xEB, 0x31, 0xBB, 0xA7, 0x41, 0x5D, 0x22, 0x3B, 0x4D, 0x73, 0x26, - 0xFD, 0xAD, 0xD8, 0x46, 0x38, 0x98, 0x9A, 0xA4, 0x5A, 0x2C, 0xF8, 0x5F, 0x89, 0x47, 0x21, 0xB0, - 0x81, 0xCB, 0x84, 0xF8, 0xAB, 0x7C, 0x27, 0x4A, 0xEA, 0xC3, 0x6C, 0x3C, 0x62, 0xF7, 0xE0, 0xD0, - 0x23, 0xC6, 0x99, 0xA0, 0x5A, 0x2B, 0x9D, 0xFF, 0x5E, 0x90, 0xB9, 0xA5, 0x0F, 0xA3, 0x84, 0x84, - 0x34, 0xD5, 0xFE, 0x22, 0x99, 0xD9, 0x28, 0x89, 0xC2, 0x65, 0x10, 0x99, 0x8B, 0xA8, 0x34, 0x99, - 0xCF, 0x9F, 0x65, 0x71, 0x10, 0x11, 0x10, 0x73, 0x4D, 0xE4, 0x50, 0xF1, 0x34, 0x91, 0x6E, 0xB5, - 0x88, 0xAB, 0xB9, 0x9B, 0x6D, 0xA1, 0x5B, 0x96, 0xDD, 0x7A, 0x6B, 0x67, 0xE9, 0xBA, 0x75, 0xB9, - 0x17, 0xE3, 0xFD, 0x9A, 0x4C, 0x81, 0xF1, 0xA0, 0x14, 0xEE, 0x9E, 0x09, 0x50, 0xE9, 0x13, 0x87, - 0xCB, 0x43, 0xF2, 0xC8, 0xB0, 0x60, 0x40, 0x05, 0xEA, 0x96, 0x8C, 0xD4, 0x85, 0x24, 0xB0, 0x6F, - 0xFE, 0x8C, 0xCA, 0xBC, 0x67, 0x3D, 0x8B, 0x13, 0xB8, 0x0D, 0x3A, 0xFD, 0x11, 0xCD, 0x42, 0xA6, - 0x2A, 0x6D, 0x45, 0x53, 0x65, 0xBC, 0x5C, 0x84, 0x65, 0xDA, 0x93, 0xBC, 0x16, 0xA4, 0x1F, 0x4B, - 0x05, 0xE0, 0x05, 0x37, 0xCF, 0x91, 0x9B, 0x1F, 0x6A, 0x75, 0x7B, 0xF7, 0x97, 0x9C, 0x87, 0x9D, - 0xE6, 0x2F, 0x73, 0x3B, 0xDF, 0x5B, 0xA4, 0xE4, 0x56, 0x13, 0xFE, 0x29, 0x32, 0xEF, 0x8B, 0x25, - 0x0B, 0xC3, 0xE7, 0xF8, 0xA7, 0x60, 0x10, 0xE9, 0x94, 0x80, 0xDB, 0x3B, 0x2F, 0x5F, 0xF8, 0xC3, - 0x02, 0x98, 0x0B, 0xF6, 0x24, 0x3C, 0x21, 0x3E, 0xCB, 0x52, 0xE7, 0x79, 0xF3, 0x97, 0x5C, 0x9F, - 0x5B, 0x3B, 0x28, 0xFB, 0xE2, 0x2E, 0x71, 0xB2, 0xB4, 0xD8, 0x34, 0x66, 0x5C, 0xDB, 0x4A, 0x35, - 0xBC, 0x6F, 0x92, 0x2C, 0x0C, 0xB3, 0x92, 0xED, 0xE7, 0xBF, 0x2F, 0x4D, 0x13, 0xF7, 0xCF, 0x9A, - 0xBF, 0xCC, 0x44, 0x02, 0xD9, 0x64, 0x04, 0xB9, 0xC6, 0x49, 0x22, 0x41, 0x04, 0x35, 0x9A, 0xE6, - 0x1C, 0x84, 0x5B, 0x03, 0xD8, 0xDE, 0x6D, 0xFA, 0x74, 0x6C, 0xCE, 0xE7, 0x7B, 0x0D, 0x99, 0xD7, - 0xA0, 0x6C, 0xF1, 0x12, 0x16, 0x8B, 0xFD, 0x51, 0xC6, 0x3D, 0xE4, 0x41, 0x1B, 0x53, 0x83, 0x9A, - 0xB3, 0x84, 0x8A, 0x2C, 0xE1, 0x9A, 0x1F, 0x79, 0x19, 0x1A, 0xBB, 0x3D, 0xA6, 0xE2, 0x58, 0xD9, - 0x7D, 0xF7, 0xE1, 0x8D, 0x0F, 0x3B, 0xE6, 0x0B, 0x04, 0x6F, 0x2D, 0x02, 0x38, 0x30, 0x9C, 0x97, - 0xE3, 0x54, 0xF6, 0x43, 0x82, 0x01, 0x22, 0xEF, 0xE8, 0x83, 0x41, 0x2D, 0xB1, 0x40, 0xA4, 0x36, - 0xAE, 0x1B, 0xC5, 0x2E, 0x80, 0x71, 0x73, 0x76, 0x07, 0x4A, 0x20, 0x2E, 0xFD, 0x22, 0x6E, 0x2C, - 0xE6, 0x72, 0xF8, 0x69, 0xE7, 0xBB, 0xC9, 0x1E, 0x3B, 0xA8, 0xB7, 0x1C, 0xB2, 0xCF, 0x0E, 0x5A, - 0xE0, 0x5E, 0x65, 0x6E, 0xE4, 0xB9, 0xAF, 0x58, 0x40, 0x07, 0xB9, 0xC3, 0xE1, 0x31, 0x48, 0x6C, - 0xB1, 0x85, 0x28, 0xE2, 0x5B, 0xCD, 0xE6, 0x86, 0x4B, 0x0F, 0x48, 0x00, 0x39, 0xCC, 0xD0, 0x8F, - 0xAF, 0xAE, 0x2E, 0xAE, 0xBE, 0xE8, 0x35, 0x5A, 0xD3, 0x6F, 0x1C, 0x4D, 0xAF, 0x71, 0xD3, 0x11, - 0x76, 0x42, 0x47, 0x09, 0x4D, 0x27, 0x97, 0x44, 0x4C, 0x8C, 0xD4, 0xBE, 0x23, 0x41, 0x56, 0x16, - 0x84, 0xA1, 0xDC, 0xC8, 0xA2, 0x70, 0x39, 0x9D, 0x6A, 0xAF, 0x40, 0xCD, 0x47, 0x90, 0xEA, 0xDA, - 0xC2, 0x26, 0x71, 0x4C, 0xB9, 0x6F, 0xE8, 0x31, 0x20, 0xEA, 0x16, 0x35, 0xAD, 0x84, 0x7E, 0xCB, - 0x68, 0x2A, 0x52, 0x1B, 0x2C, 0xD7, 0xD0, 0x2F, 0x07, 0x7D, 0xDD, 0xD2, 0x1B, 0xE8, 0x47, 0x3A, - 0xF0, 0x46, 0xCC, 0x39, 0x52, 0x89, 0x5C, 0xD0, 0xA4, 0x3E, 0xCC, 0xC0, 0xA0, 0xB8, 0x6E, 0xB6, - 0x23, 0x9B, 0x71, 0x4E, 0x93, 0x93, 0xFE, 0xD9, 0xA9, 0xAB, 0x5F, 0x29, 0x46, 0xB4, 0x53, 0x28, - 0x48, 0x74, 0x4B, 0x5E, 0x51, 0x7E, 0xC8, 0xE1, 0x84, 0x05, 0xBE, 0x11, 0x99, 0x6D, 0x24, 0xE1, - 0x49, 0x12, 0xB2, 0x40, 0x01, 0x0A, 0x9E, 0x2D, 0x1E, 0x62, 0xEA, 0xEA, 0x23, 0x50, 0x86, 0x6E, - 0x79, 0x76, 0x98, 0x05, 0x82, 0xC5, 0x01, 0x75, 0x37, 0x5A, 0x30, 0xE3, 0x60, 0x41, 0xAE, 0x8E, - 0xB9, 0x19, 0x61, 0xCC, 0x77, 0x75, 0x15, 0xA1, 0xF2, 0xB8, 0xB6, 0xEE, 0x14, 0x4F, 0x9D, 0x92, - 0x56, 0x4E, 0x49, 0xCB, 0xB8, 0x4A, 0xE0, 0x34, 0x3F, 0x18, 0xC3, 0x3C, 0xCE, 0xD4, 0x51, 0x05, - 0xCC, 0xA7, 0x23, 0x02, 0x9C, 0x7C, 0x40, 0x6D, 0xBA, 0x7A, 0x63, 0xDD, 0x41, 0xA9, 0x3A, 0xC8, - 0xAF, 0x6A, 0xC4, 0x2F, 0x6B, 0x44, 0xDD, 0xEE, 0x3A, 0x64, 0x5F, 0x21, 0x07, 0x55, 0xE4, 0xA0, - 0x8C, 0x7C, 0x28, 0x8D, 0x64, 0x1D, 0x72, 0xA0, 0x90, 0x93, 0x8A, 0x88, 0x89, 0x14, 0x51, 0x85, - 0xBD, 0x3A, 0x6A, 0x13, 0x05, 0xD2, 0xAD, 0xA4, 0x22, 0x66, 0x62, 0x83, 0x97, 0x92, 0x61, 0x40, - 0x7D, 0x77, 0xA3, 0x09, 0x33, 0x2C, 0xB6, 0xDD, 0xAD, 0xE6, 0x9A, 0x33, 0x12, 0x75, 0x46, 0x56, - 0x65, 0x30, 0x2B, 0x33, 0xA8, 0xF5, 0xC8, 0x1D, 0xD5, 0xD6, 0x31, 0x98, 0x99, 0x56, 0x60, 0x47, - 0xDC, 0x0B, 0x98, 0x77, 0xEB, 0x2E, 0xBD, 0xC5, 0x9C, 0xB1, 0x85, 0x85, 0x5A, 0x5C, 0x06, 0xBA, - 0x01, 0x94, 0x5E, 0x8B, 0xA5, 0x7C, 0x80, 0xFA, 0x9E, 0x5B, 0xD9, 0x5A, 0x02, 0xDC, 0xA6, 0xF7, - 0xD4, 0x3B, 0x8C, 0xC2, 0x90, 0xA0, 0xED, 0xA6, 0xC0, 0x41, 0x3E, 0xD1, 0xCD, 0xB9, 0x15, 0xAD, - 0xC5, 0x79, 0xC2, 0x45, 0x2C, 0x7F, 0x3D, 0x8B, 0x23, 0x03, 0x5C, 0xCE, 0xF5, 0x6C, 0xD4, 0x61, - 0x6A, 0x83, 0x1E, 0xC7, 0x62, 0xF2, 0x13, 0x17, 0x2A, 0x0C, 0x54, 0xA2, 0x7C, 0x69, 0xDE, 0x58, - 0x0B, 0x91, 0x56, 0x7C, 0xEA, 0xA2, 0xB7, 0xE2, 0x54, 0xA8, 0xBC, 0x8A, 0x5D, 0x9A, 0x4B, 0x1D, - 0x94, 0x61, 0xB9, 0xBD, 0x2F, 0xA0, 0xFA, 0x7C, 0x0E, 0xE7, 0x01, 0xFF, 0x13, 0x68, 0xF9, 0xE8, - 0x5F, 0x17, 0x60, 0xC9, 0xA3, 0x34, 0x78, 0x8B, 0xBB, 0x0D, 0xE3, 0xC0, 0xF9, 0x8F, 0x6D, 0x7C, - 0xF9, 0x1F, 0xFB, 0xA6, 0x66, 0x9A, 0x07, 0xFF, 0x6A, 0x48, 0x0D, 0x1B, 0xC2, 0xFC, 0xD2, 0xBA, - 0xB1, 0x08, 0x80, 0xED, 0x7F, 0x9B, 0xFF, 0xB1, 0x25, 0xB8, 0x02, 0x6B, 0xDF, 0x45, 0x90, 0x49, - 0xF0, 0x24, 0x34, 0xB0, 0x68, 0xA4, 0x91, 0xCD, 0x4D, 0x43, 0xB8, 0xA4, 0x72, 0x8D, 0x35, 0x51, - 0xD3, 0x6D, 0x88, 0x53, 0x50, 0x5B, 0xAC, 0x04, 0xBF, 0x3E, 0x24, 0x7A, 0x15, 0x5B, 0x17, 0x00, - 0xC9, 0x3D, 0xCA, 0x0C, 0x3D, 0x22, 0x97, 0x52, 0xCB, 0x0C, 0x02, 0x42, 0xA7, 0x89, 0xE7, 0x2A, - 0xAD, 0x1D, 0x14, 0x30, 0x17, 0xA2, 0xE0, 0xBC, 0x1C, 0x2D, 0x15, 0xEA, 0xAA, 0xFD, 0x17, 0x0A, - 0xA3, 0xD6, 0x12, 0x8A, 0x04, 0x31, 0xAD, 0xD8, 0x79, 0xC6, 0x72, 0x75, 0x4C, 0x59, 0xBA, 0x35, - 0x59, 0x5D, 0x96, 0xAD, 0x04, 0xAE, 0x2F, 0x8D, 0xFE, 0xD7, 0x3D, 0x16, 0x8E, 0xB5, 0x12, 0x3F, - 0xF8, 0x97, 0xFB, 0x2B, 0x46, 0xE4, 0xCD, 0x3F, 0xBC, 0x21, 0x70, 0x05, 0xA6, 0x41, 0x6D, 0x1E, - 0x4D, 0x0D, 0xB3, 0xF6, 0xAB, 0xAE, 0x49, 0x8A, 0xAE, 0x1E, 0x92, 0xFB, 0xBC, 0xA7, 0xC4, 0x8C, - 0xD7, 0xD6, 0x70, 0x5E, 0xB4, 0x28, 0xF9, 0x82, 0xEC, 0xE6, 0x48, 0x26, 0xA2, 0xB6, 0x56, 0x64, - 0x52, 0xD5, 0xCA, 0xE8, 0x5A, 0x63, 0xFF, 0xD7, 0x4A, 0x40, 0xB7, 0x98, 0xBA, 0x4E, 0x15, 0x8C, - 0xB3, 0x00, 0x1C, 0x93, 0x3E, 0x1D, 0x69, 0x03, 0x26, 0x03, 0x75, 0x35, 0x46, 0x5A, 0x81, 0xC1, - 0xCC, 0x03, 0xC3, 0x2B, 0xFB, 0xF3, 0x1E, 0x16, 0xBF, 0xFB, 0x97, 0xAA, 0xAA, 0x81, 0xD4, 0x8B, - 0x33, 0x5D, 0x59, 0x59, 0xD5, 0x4B, 0xE0, 0xD2, 0x08, 0xA0, 0x5B, 0x8B, 0x3C, 0x3A, 0x8C, 0xFC, - 0x87, 0x52, 0xF6, 0x4D, 0xBB, 0x0F, 0x87, 0x01, 0x49, 0xD3, 0x73, 0xB8, 0x01, 0x43, 0xF7, 0x42, - 0x50, 0xB8, 0xB2, 0xC2, 0xFD, 0xE6, 0xE6, 0x66, 0x15, 0x29, 0xA1, 0x21, 0x14, 0xDB, 0x8A, 0x2B, - 0xF0, 0x49, 0xD3, 0xF1, 0x81, 0x30, 0x18, 0xD2, 0x1A, 0xC6, 0xF0, 0x25, 0xE3, 0x47, 0x5C, 0x71, - 0xF4, 0xF4, 0x22, 0xA6, 0xFC, 0x33, 0xDC, 0x95, 0x32, 0xCB, 0x1A, 0xAD, 0xA6, 0x68, 0xFA, 0x8F, - 0xD8, 0x3E, 0xCA, 0x0D, 0x76, 0xC1, 0x7A, 0xBA, 0x56, 0xA1, 0xFC, 0x9F, 0x61, 0xB9, 0x94, 0x28, - 0xD6, 0x70, 0x9C, 0x40, 0x80, 0x5A, 0xC3, 0x31, 0xC4, 0x1A, 0x41, 0x17, 0xFC, 0x26, 0x6B, 0xF9, - 0xCD, 0xFE, 0x19, 0x7E, 0x97, 0x76, 0x1E, 0x15, 0x25, 0x91, 0xAA, 0xAF, 0x50, 0x02, 0x9F, 0xDD, - 0xE9, 0xA6, 0x15, 0xB9, 0x55, 0x0A, 0x50, 0x1B, 0x46, 0x41, 0xD0, 0x8F, 0xE2, 0x83, 0x27, 0xD6, - 0x9D, 0xC5, 0x7A, 0x31, 0xC8, 0xD9, 0x5C, 0x6E, 0xB1, 0xBC, 0xB5, 0x44, 0x4F, 0xA1, 0xEC, 0x5F, - 0x4B, 0x15, 0x01, 0x3F, 0x23, 0x8B, 0x7B, 0xAC, 0xD4, 0xA5, 0x36, 0x28, 0x0F, 0x56, 0x3F, 0xD5, - 0x3C, 0xCB, 0x5F, 0xCC, 0xAE, 0x6B, 0x51, 0x9B, 0xC0, 0x38, 0x57, 0x92, 0x8B, 0x4A, 0xB2, 0xC8, - 0x13, 0x01, 0xA8, 0x58, 0xC7, 0x2E, 0xC4, 0x4D, 0x6B, 0x7A, 0x7C, 0xBF, 0x5C, 0x83, 0xC2, 0xDF, - 0xF5, 0xD5, 0x12, 0x33, 0x08, 0xC4, 0xD3, 0x95, 0x4B, 0x29, 0x5F, 0x37, 0x29, 0x8A, 0x0E, 0x62, - 0x47, 0xA3, 0x51, 0x4A, 0xC5, 0x47, 0x0C, 0x49, 0x56, 0xB2, 0x98, 0x9F, 0xC8, 0x90, 0x04, 0x8C, - 0x45, 0x3C, 0x8C, 0xB2, 0x94, 0x46, 0x99, 0xA8, 0xA4, 0x16, 0x63, 0x21, 0xCC, 0x5E, 0xFA, 0xE7, - 0x9F, 0x8B, 0xC9, 0x7E, 0x5A, 0x0B, 0x96, 0xD3, 0xEB, 0x3D, 0xBF, 0x34, 0xD9, 0xF7, 0x6B, 0x89, - 0xB9, 0x7A, 0xE9, 0xFF, 0x67, 0x4B, 0x21, 0x65, 0x4B, 0xF1, 0xB0, 0x54, 0x2E, 0x62, 0x62, 0x29, - 0xE6, 0xC9, 0x82, 0x91, 0x97, 0x7C, 0x16, 0x0D, 0x1A, 0x2B, 0x25, 0x55, 0x9E, 0x97, 0x7D, 0x95, - 0x43, 0x40, 0x59, 0x71, 0xE5, 0x35, 0x11, 0x06, 0x34, 0xE0, 0x63, 0x64, 0xF2, 0x41, 0xEB, 0xA7, - 0xD1, 0x94, 0x26, 0x87, 0x24, 0xA5, 0x06, 0x24, 0xCD, 0x65, 0xDC, 0x41, 0xA8, 0xE9, 0x04, 0xEB, - 0x76, 0x6D, 0x6E, 0x12, 0x05, 0xCE, 0x33, 0x77, 0xC4, 0xB1, 0x26, 0x03, 0xF9, 0xB2, 0xCA, 0x09, - 0xD4, 0xC6, 0xBE, 0x12, 0xA4, 0x3E, 0x52, 0x25, 0xA8, 0x61, 0x5A, 0xD0, 0x76, 0xC0, 0x35, 0x5F, - 0x26, 0x51, 0x4C, 0xC6, 0xB2, 0x07, 0x83, 0x35, 0x74, 0x0F, 0xA4, 0x66, 0x6D, 0x34, 0x91, 0x60, - 0xA9, 0x73, 0x29, 0xFC, 0x66, 0xD9, 0xC2, 0x70, 0x4B, 0x57, 0xC9, 0xB0, 0xBD, 0xF4, 0xA5, 0x35, - 0x59, 0x83, 0xE0, 0x0B, 0x6C, 0x62, 0xE0, 0x1E, 0x68, 0x64, 0xF2, 0x7B, 0x00, 0x77, 0x6B, 0xB6, - 0xA3, 0x3D, 0xD6, 0x8E, 0x6A, 0x35, 0x53, 0x55, 0xE9, 0xAE, 0x0B, 0x6D, 0x4E, 0x74, 0x23, 0x0B, - 0x4B, 0x10, 0xAA, 0x9A, 0x59, 0x0C, 0x38, 0x1B, 0x81, 0xAA, 0xBA, 0xC0, 0x11, 0xD6, 0x98, 0x66, - 0xA9, 0x23, 0xF1, 0x97, 0x1D, 0xC9, 0x13, 0xB5, 0x07, 0x95, 0xF5, 0x05, 0xD4, 0x31, 0xAB, 0x25, - 0x86, 0x30, 0xD3, 0x29, 0x13, 0xDE, 0x04, 0x03, 0x90, 0x07, 0x5A, 0xD5, 0x05, 0x14, 0xB5, 0x8E, - 0x1C, 0x4D, 0x44, 0xB8, 0x1C, 0x05, 0xF9, 0xF0, 0x6B, 0x9A, 0x0F, 0xBC, 0xB4, 0x18, 0xDD, 0x97, - 0x80, 0x50, 0xD2, 0xE6, 0xE0, 0x88, 0x8F, 0xF2, 0x21, 0xF4, 0xB2, 0x05, 0x9D, 0x02, 0x58, 0xFC, - 0xC6, 0x71, 0x3E, 0x8A, 0x27, 0xC5, 0x68, 0x42, 0xEF, 0x17, 0x78, 0x51, 0x01, 0xF5, 0xA9, 0xEE, - 0x28, 0x1B, 0xDB, 0x68, 0xCE, 0xF3, 0x41, 0x6B, 0x29, 0x7F, 0xF0, 0xFF, 0x28, 0x7F, 0xCC, 0xC7, - 0x85, 0x34, 0x71, 0x31, 0x1A, 0xB3, 0x42, 0x96, 0x61, 0x18, 0xFF, 0x90, 0x93, 0xA4, 0xD4, 0x13, - 0x97, 0x7A, 0x5A, 0xF1, 0xB3, 0xB6, 0x53, 0x98, 0x8E, 0x31, 0xAA, 0xF8, 0xE3, 0xC8, 0xF6, 0xF0, - 0xF7, 0x3C, 0xF2, 0x65, 0x6D, 0x69, 0x5A, 0xA1, 0x31, 0x82, 0x3A, 0x57, 0x37, 0xCB, 0x7E, 0x9A, - 0xFD, 0xB7, 0xAD, 0xE8, 0xD1, 0xF1, 0xE9, 0x71, 0xFF, 0xB8, 0x5C, 0x38, 0x23, 0xE7, 0x25, 0x93, - 0x8A, 0x2B, 0x5D, 0xFA, 0xB2, 0x22, 0x80, 0x02, 0x1B, 0x45, 0x01, 0x7B, 0xDD, 0xDC, 0x54, 0x7E, - 0xF1, 0xB6, 0x77, 0x71, 0x6E, 0xC7, 0x24, 0x01, 0x8F, 0x24, 0x15, 0xE6, 0xC2, 0x82, 0x44, 0xF9, - 0xE0, 0xD7, 0xC7, 0xA5, 0x72, 0x5D, 0x7E, 0x61, 0x70, 0xC4, 0xDC, 0x52, 0xA7, 0xA9, 0x7E, 0x78, - 0xE2, 0x62, 0x5D, 0x99, 0xBF, 0x04, 0x41, 0x72, 0x1A, 0x2D, 0x13, 0x55, 0x11, 0x67, 0x46, 0xE5, - 0x30, 0x2F, 0xEE, 0xB2, 0x75, 0x0D, 0xD3, 0xC8, 0xB4, 0xC4, 0x84, 0xA5, 0xE5, 0x46, 0xA5, 0x12, - 0x14, 0xFE, 0xA2, 0xB6, 0xE7, 0x8B, 0x91, 0x24, 0xB7, 0x5A, 0x73, 0xAB, 0x6F, 0x41, 0x2A, 0x3E, - 0x58, 0x04, 0x23, 0x66, 0x39, 0xDB, 0x16, 0x77, 0xA3, 0x43, 0xEE, 0x61, 0x5C, 0x7F, 0xBA, 0x35, - 0x78, 0xD2, 0x3C, 0x79, 0x61, 0x9E, 0xFC, 0xB1, 0x7B, 0x2E, 0x1C, 0x45, 0xF9, 0xDA, 0xE2, 0x98, - 0xF6, 0x10, 0x58, 0xBB, 0x6D, 0x2F, 0x7D, 0x18, 0x20, 0xD2, 0x83, 0xCB, 0x00, 0xF4, 0x63, 0x58, - 0xFF, 0x4A, 0xEE, 0x88, 0x7A, 0x09, 0xAA, 0xA2, 0xAD, 0x73, 0x54, 0xD8, 0xEE, 0xFD, 0x81, 0xA3, - 0xF2, 0xCE, 0x65, 0x18, 0x48, 0x97, 0xC3, 0x92, 0x37, 0x8B, 0x75, 0xC1, 0x61, 0x19, 0x31, 0x64, - 0x6C, 0x00, 0xE3, 0xCD, 0x5D, 0x49, 0x13, 0xD5, 0x1C, 0xB4, 0xF0, 0x1B, 0x08, 0x8A, 0x4F, 0x39, - 0xCE, 0x9A, 0x38, 0xAD, 0x62, 0x72, 0xC5, 0x23, 0xC8, 0x4A, 0x67, 0x89, 0xC0, 0x6E, 0x10, 0x0D, - 0x0D, 0x7C, 0x64, 0x9A, 0xA1, 0xB6, 0x1D, 0x3E, 0x37, 0xD7, 0xBC, 0xD9, 0x54, 0xFA, 0x4B, 0x62, - 0x79, 0xD5, 0xB0, 0x8B, 0x1C, 0x56, 0xCC, 0x75, 0x7D, 0x1F, 0xF4, 0xA3, 0x4E, 0x29, 0xAF, 0x48, - 0xA4, 0x53, 0xD1, 0x83, 0xC4, 0x86, 0xA2, 0x41, 0xBE, 0x91, 0x40, 0x44, 0x72, 0x4A, 0x33, 0x5D, - 0xC7, 0xCA, 0xD2, 0x0B, 0x28, 0x49, 0x7A, 0xB2, 0x73, 0x95, 0x49, 0x6B, 0x25, 0x06, 0xFE, 0xC8, - 0xD7, 0xF0, 0xC7, 0xA1, 0xD0, 0xA3, 0x83, 0x9B, 0x49, 0x2B, 0x83, 0xA4, 0x23, 0x64, 0x83, 0xA9, - 0x37, 0xE4, 0xBB, 0xA8, 0x2D, 0x2F, 0xCB, 0xB4, 0x16, 0x50, 0x70, 0x71, 0x83, 0xBB, 0x11, 0x30, - 0x52, 0x5A, 0xC4, 0x9E, 0x94, 0xA8, 0xC7, 0x8F, 0x10, 0x1F, 0x53, 0x4A, 0x20, 0x06, 0x20, 0xA6, - 0x40, 0xD0, 0xA7, 0x42, 0x8A, 0x54, 0xE6, 0x92, 0x53, 0x2A, 0x20, 0xCA, 0x48, 0xCD, 0xE2, 0xC1, - 0x85, 0x78, 0xD4, 0x46, 0xD6, 0x80, 0xFD, 0xDC, 0xBD, 0x73, 0x33, 0xDE, 0x90, 0x68, 0x09, 0x56, - 0x36, 0x3D, 0x9A, 0xA6, 0x52, 0x5C, 0x54, 0xC7, 0x19, 0xF8, 0xA8, 0xA1, 0x03, 0x5A, 0x23, 0x84, - 0x11, 0x1E, 0x84, 0x8A, 0x01, 0x40, 0x7F, 0x42, 0xC3, 0x1C, 0x22, 0x70, 0x08, 0x20, 0x82, 0xA0, - 0x7F, 0x49, 0x0D, 0xF7, 0x64, 0x05, 0xC9, 0xF8, 0xD8, 0x6D, 0x35, 0xF0, 0x9D, 0x66, 0x95, 0xEC, - 0x20, 0xA5, 0xBD, 0x68, 0x24, 0xFA, 0x64, 0x98, 0x1A, 0x50, 0x00, 0xAC, 0xD9, 0x01, 0xA0, 0x1E, - 0x24, 0x5E, 0x63, 0x2B, 0x3F, 0xEF, 0x04, 0x2A, 0xBB, 0x00, 0xAB, 0xBB, 0x8E, 0x87, 0x5F, 0x39, - 0x4F, 0x19, 0xA7, 0x39, 0x26, 0x00, 0x7B, 0x93, 0x68, 0x7A, 0x99, 0x30, 0x2E, 0xCE, 0x64, 0x1B, - 0x6A, 0x6C, 0xB4, 0xE4, 0xF5, 0xA9, 0x87, 0x15, 0x79, 0x3F, 0xC5, 0x8B, 0xCB, 0x0C, 0xF3, 0xBA, - 0x53, 0x79, 0x77, 0xB1, 0x86, 0x70, 0x21, 0x50, 0x66, 0x38, 0xB3, 0x29, 0x74, 0xB0, 0xFA, 0xA1, - 0x48, 0x82, 0x7A, 0x4F, 0xB7, 0x42, 0xE2, 0xC1, 0x44, 0xED, 0x81, 0xF9, 0xDC, 0xC2, 0xD8, 0xE1, - 0x94, 0x83, 0x5A, 0x0A, 0xB5, 0x02, 0x45, 0xC6, 0x95, 0xCD, 0x98, 0x35, 0x1D, 0x6A, 0x58, 0x88, - 0x61, 0xE0, 0xAF, 0xFE, 0x05, 0x0F, 0x1E, 0x1C, 0xC8, 0x55, 0x3F, 0xE1, 0x23, 0xE3, 0x7E, 0xF4, - 0x23, 0x3E, 0x3E, 0xAF, 0xF0, 0xF1, 0x79, 0x1D, 0x1F, 0xB4, 0xAA, 0x3C, 0x98, 0x0C, 0x80, 0xEC, - 0x19, 0xE1, 0x64, 0x4C, 0x13, 0x58, 0xC0, 0x43, 0x50, 0x25, 0x7F, 0x8B, 0xB3, 0x84, 0xFE, 0x98, - 0xB3, 0xDE, 0x84, 0x8D, 0xC4, 0x23, 0xFE, 0x8A, 0xD5, 0xFF, 0x82, 0x4B, 0x3C, 0x70, 0x3D, 0x97, - 0x79, 0x6D, 0x5A, 0x49, 0x28, 0x3F, 0x7E, 0x2B, 0x91, 0x7E, 0xE4, 0x42, 0x78, 0xA9, 0x38, 0xC8, - 0xDF, 0xB7, 0xF4, 0x00, 0xBC, 0x11, 0xF8, 0x29, 0x35, 0x75, 0xBC, 0x0B, 0xA5, 0xFC, 0x29, 0x30, - 0x64, 0xA8, 0xC0, 0x47, 0xDD, 0xD9, 0xDC, 0x12, 0xAE, 0x01, 0x8A, 0xF1, 0xA3, 0x29, 0xB0, 0xEA, - 0xC9, 0x02, 0xD7, 0x9E, 0x40, 0x26, 0x04, 0x91, 0xE0, 0x48, 0xC8, 0xA7, 0x8D, 0x2F, 0x07, 0x9B, - 0x37, 0x35, 0xC8, 0x43, 0x2E, 0xFC, 0x98, 0x2E, 0x0C, 0x36, 0x6F, 0xFE, 0x6D, 0x36, 0xC6, 0xCC, - 0x5A, 0x76, 0xA4, 0x96, 0x4C, 0xF6, 0xF4, 0x0B, 0xBF, 0x71, 0x09, 0x48, 0x5D, 0x49, 0x78, 0x45, - 0x34, 0x03, 0x6B, 0x43, 0x61, 0xE1, 0x07, 0xFF, 0x47, 0x09, 0xF8, 0x91, 0x9E, 0x07, 0xCE, 0xBD, - 0xE6, 0x3D, 0x5E, 0x2F, 0x3E, 0x85, 0xE9, 0x56, 0xE9, 0xC1, 0x4A, 0xC7, 0xEF, 0x53, 0x3A, 0x76, - 0x59, 0xA2, 0x14, 0x4A, 0x14, 0x59, 0x88, 0x1A, 0x6A, 0x50, 0x0E, 0x51, 0x98, 0x89, 0x17, 0xCD, - 0x81, 0x02, 0x9B, 0x73, 0x34, 0x5B, 0x3A, 0x02, 0x0F, 0xF4, 0xF5, 0x45, 0xEE, 0xFC, 0x74, 0x76, - 0x7A, 0x22, 0x44, 0x7C, 0xA5, 0x62, 0x22, 0xD0, 0xAA, 0x2E, 0x2C, 0x2F, 0xCF, 0x9C, 0x89, 0xE4, - 0xA1, 0x28, 0x75, 0x30, 0x31, 0x28, 0x87, 0xFE, 0x74, 0x31, 0xFC, 0x0A, 0x71, 0xD6, 0xD0, 0xCF, - 0x52, 0x48, 0x58, 0x5B, 0x36, 0xA2, 0xF7, 0xFB, 0x97, 0xF6, 0xAE, 0xDD, 0x84, 0xBA, 0x00, 0xB4, - 0x0A, 0x69, 0x19, 0xEE, 0x7D, 0xFE, 0xB7, 0x90, 0xB7, 0xFF, 0x1E, 0x32, 0x83, 0xA8, 0x95, 0x42, - 0x58, 0x2A, 0xF0, 0xAB, 0xB8, 0x93, 0x24, 0x9A, 0x4A, 0xB4, 0xE3, 0x24, 0xC1, 0x4B, 0xE9, 0x43, - 0x85, 0xA2, 0x0D, 0x61, 0x31, 0xA5, 0x89, 0xE6, 0x47, 0x34, 0xD5, 0x78, 0x24, 0xB4, 0x34, 0x8B, - 0x63, 0x68, 0x5C, 0x56, 0xF4, 0x61, 0xEB, 0xC5, 0xEB, 0xCB, 0xFB, 0x8C, 0x66, 0xD4, 0xCF, 0x97, - 0x69, 0x52, 0xD1, 0x0B, 0x56, 0x50, 0xDF, 0x10, 0xEE, 0x7E, 0xB9, 0xC9, 0xEB, 0xA9, 0x8C, 0x73, - 0x8C, 0xA2, 0x1B, 0x2D, 0x35, 0x07, 0xE9, 0x26, 0x40, 0xD5, 0xE5, 0x59, 0x10, 0xCC, 0xDB, 0x2B, - 0xB4, 0xA0, 0xF1, 0x8A, 0x44, 0x24, 0x9F, 0xCB, 0x67, 0x7F, 0xE4, 0xC9, 0xA9, 0xE2, 0x82, 0x50, - 0xF2, 0x54, 0xA9, 0x36, 0xAD, 0x0D, 0x63, 0x83, 0x6A, 0x8C, 0xA7, 0x82, 0x70, 0x0F, 0xAF, 0x51, - 0xE9, 0xC2, 0x2C, 0x6A, 0x29, 0xDC, 0xDE, 0x46, 0x5F, 0xCB, 0x6D, 0xE9, 0x89, 0x7C, 0x2A, 0x25, - 0xE3, 0xAE, 0xAE, 0x63, 0x55, 0x45, 0xB1, 0x3E, 0x25, 0x61, 0x5A, 0x26, 0x5B, 0x54, 0x06, 0x26, - 0x77, 0x0B, 0x70, 0x9B, 0x06, 0x29, 0x1C, 0xBD, 0x7E, 0x7F, 0xCE, 0x46, 0xD1, 0xCE, 0x11, 0x80, - 0x69, 0xC5, 0x3E, 0x93, 0xD7, 0xE0, 0x24, 0xCC, 0x73, 0x07, 0x32, 0xE9, 0x4A, 0x03, 0x0E, 0xA9, - 0x98, 0x44, 0xFE, 0x81, 0x7E, 0xA0, 0x3B, 0x3A, 0xFC, 0xBB, 0x09, 0x35, 0x47, 0xCD, 0xA5, 0xD0, - 0xA4, 0xFA, 0x74, 0x70, 0xF5, 0x06, 0xC2, 0x53, 0x0C, 0xA5, 0x01, 0x17, 0x50, 0x34, 0xD7, 0x74, - 0x7C, 0x7A, 0x7D, 0x0C, 0x29, 0xC8, 0x7F, 0x21, 0x37, 0x66, 0xBB, 0xAA, 0x6C, 0xB8, 0xF3, 0xEA, - 0x75, 0x56, 0x2E, 0x03, 0x7A, 0x61, 0x8C, 0x58, 0x0F, 0x29, 0x7E, 0xFB, 0x7B, 0xF4, 0x9E, 0x8D, - 0x15, 0xD2, 0x6A, 0x5D, 0x6F, 0xCE, 0x76, 0x90, 0x67, 0x89, 0xD5, 0x43, 0x2C, 0x70, 0x97, 0x1F, - 0x29, 0x59, 0x95, 0x35, 0xDC, 0xF6, 0x48, 0x10, 0xE0, 0xC7, 0x5A, 0x03, 0x1B, 0x6A, 0x22, 0xB2, - 0xD4, 0x42, 0x22, 0x29, 0x08, 0x90, 0xD2, 0x3E, 0x84, 0x39, 0xD3, 0x92, 0x65, 0x86, 0xB2, 0xA1, - 0xBC, 0xFF, 0xC5, 0x9A, 0xA3, 0x64, 0x46, 0xE8, 0xCE, 0xF9, 0x6C, 0x73, 0x53, 0xD8, 0x85, 0x99, - 0x18, 0x05, 0x52, 0x8A, 0x01, 0x1C, 0x9A, 0x7D, 0x68, 0x2D, 0x8C, 0xB2, 0x90, 0x58, 0xAB, 0x3D, - 0xD2, 0xB6, 0x51, 0x55, 0x03, 0x54, 0x7C, 0x46, 0x01, 0x03, 0xCE, 0xB2, 0x24, 0x80, 0xA8, 0x8B, - 0x39, 0xBA, 0xB2, 0x2D, 0xC5, 0xBA, 0xD0, 0x84, 0x0E, 0xEC, 0x67, 0xC8, 0x12, 0x95, 0x97, 0xAD, - 0xA2, 0x27, 0x12, 0xC5, 0x77, 0x95, 0x9E, 0xC8, 0x6F, 0xE5, 0x84, 0xAA, 0xC8, 0x77, 0x88, 0x2F, - 0x13, 0x5C, 0xD4, 0xD1, 0x13, 0xA0, 0x24, 0x83, 0x52, 0x34, 0x60, 0x2A, 0x2C, 0x37, 0xEE, 0xEB, - 0xD3, 0xE9, 0xB4, 0x8E, 0xDF, 0x6A, 0xEB, 0x70, 0x82, 0xB2, 0x02, 0x5F, 0x5F, 0xC7, 0x21, 0x47, - 0x15, 0x58, 0xF8, 0x6E, 0xE1, 0xAC, 0xBA, 0xE8, 0x42, 0x7F, 0x2B, 0xDE, 0xD4, 0xAA, 0xD2, 0x59, - 0xE1, 0x73, 0x79, 0xDB, 0x7B, 0x3B, 0x2B, 0x20, 0x32, 0xC4, 0xAF, 0xB2, 0x90, 0x69, 0x20, 0x0D, - 0x3B, 0xE5, 0x46, 0x56, 0x25, 0x85, 0x65, 0x5C, 0xB0, 0xE3, 0x2C, 0x9D, 0x18, 0x33, 0x60, 0xDD, - 0x11, 0x96, 0xD2, 0x95, 0x43, 0x2D, 0x65, 0xB7, 0x0E, 0xB7, 0x0A, 0xFB, 0x70, 0x30, 0x83, 0x94, - 0x79, 0xFB, 0xF3, 0x4F, 0x39, 0x5B, 0xDE, 0xF6, 0x92, 0x62, 0x71, 0xE1, 0xF3, 0xFC, 0xA9, 0x35, - 0xAF, 0x69, 0xA5, 0xD1, 0xAF, 0xC4, 0x97, 0xBD, 0x46, 0xFE, 0x19, 0x3B, 0xFF, 0x9C, 0xAD, 0x81, - 0xB1, 0x43, 0x23, 0x2A, 0xDC, 0x4C, 0x8C, 0xEA, 0x2F, 0x34, 0xE6, 0x63, 0x79, 0x29, 0xBF, 0x2D, - 0xA0, 0x54, 0xA9, 0xD3, 0x68, 0x78, 0x3E, 0xFF, 0x9A, 0x42, 0x19, 0x1D, 0x65, 0xFE, 0x28, 0x20, - 0x09, 0xC5, 0x82, 0xA3, 0x41, 0xBE, 0x92, 0xFB, 0x46, 0xC0, 0x86, 0x69, 0x03, 0x93, 0x6D, 0xCB, - 0xDE, 0xB2, 0x77, 0x71, 0x64, 0x7F, 0x4D, 0xF7, 0x57, 0x4F, 0xD8, 0x5F, 0x34, 0x69, 0x58, 0x0B, - 0xE7, 0xB5, 0xAB, 0x8A, 0x4D, 0x6A, 0x83, 0xFB, 0xC4, 0xA7, 0x70, 0x3D, 0x6F, 0xB3, 0xCC, 0xB6, - 0x1A, 0xE4, 0x5F, 0x60, 0xD4, 0x31, 0xBA, 0x95, 0x2F, 0x92, 0xF4, 0x81, 0x7B, 0x18, 0x5B, 0x17, - 0x54, 0x26, 0x70, 0x49, 0xD5, 0x87, 0x34, 0xB9, 0xD3, 0x9C, 0x2F, 0x39, 0xC3, 0xB7, 0x3C, 0xA8, - 0x03, 0xE4, 0x37, 0x9C, 0x72, 0x39, 0xB0, 0xBF, 0x07, 0x5D, 0x33, 0x2A, 0x41, 0x79, 0xB1, 0x26, - 0x9B, 0xE6, 0x7C, 0x02, 0x82, 0x01, 0x70, 0xB1, 0xA3, 0x48, 0xCD, 0x2B, 0xCB, 0x98, 0x9B, 0x57, - 0x96, 0x54, 0xE2, 0x5F, 0x59, 0xCC, 0xDB, 0x9F, 0xFC, 0xDB, 0x4C, 0xF9, 0x7F, 0x5B, 0x28, 0x36, - 0x32, 0xF9, 0xE1, 0x09, 0xF7, 0x56, 0x3F, 0x45, 0xAD, 0x47, 0x51, 0xBB, 0xF7, 0xFF, 0x17, 0x53, - 0xE8, 0x9D, 0x36, 0x92, 0x29, 0x00, 0x00 -}; - -///////////////////////////////////////////////// - -#define SPIFFS_MAXLENGTH_FILEPATH 32 - -const char *excludeListFile = "/.exclude.files"; - -typedef struct ExcludeListS -{ - char *item; - ExcludeListS *next; -} ExcludeList; - -static ExcludeList *excludes = NULL; - -///////////////////////////////////////////////// - -static bool matchWild(const char *pattern, const char *testee) -{ - const char *nxPat = NULL, *nxTst = NULL; - - while (*testee) - { - if (( *pattern == '?' ) || (*pattern == *testee)) - { - pattern++; - testee++; - continue; - } - - if (*pattern == '*') - { - nxPat = pattern++; - nxTst = testee; - continue; - } - - if (nxPat) - { - pattern = nxPat + 1; - testee = ++nxTst; - continue; - } - - return false; - } - - while (*pattern == '*') - { - pattern++; - } - - return (*pattern == 0); -} - -///////////////////////////////////////////////// - -static bool addExclude(const char *item) -{ - size_t len = strlen(item); - - if (!len) - { - return false; - } - - ExcludeList *e = (ExcludeList *)malloc(sizeof(ExcludeList)); - - if (!e) - { - return false; - } - - e->item = (char *)malloc(len + 1); - - if (!e->item) - { - free(e); - return false; - } - - memcpy(e->item, item, len + 1); - e->next = excludes; - excludes = e; - - return true; -} - -///////////////////////////////////////////////// - -static void loadExcludeList(fs::FS &_fs, const char *filename) -{ - static char linebuf[SPIFFS_MAXLENGTH_FILEPATH]; - fs::File excludeFile = _fs.open(filename, "r"); - - if (!excludeFile) - { - //addExclude("/*.js.gz"); - return; - } - - if (excludeFile.isDirectory()) - { - excludeFile.close(); - return; - } - - if (excludeFile.size() > 0) - { - uint8_t idx; - bool isOverflowed = false; - - while (excludeFile.available()) - { - linebuf[0] = '\0'; - idx = 0; - int lastChar; - - do - { - lastChar = excludeFile.read(); - - if (lastChar != '\r') - { - linebuf[idx++] = (char) lastChar; - } - } while ((lastChar >= 0) && (lastChar != '\n') && (idx < SPIFFS_MAXLENGTH_FILEPATH)); - - if (isOverflowed) - { - isOverflowed = (lastChar != '\n'); - continue; - } - - isOverflowed = (idx >= SPIFFS_MAXLENGTH_FILEPATH); - linebuf[idx - 1] = '\0'; - - if (!addExclude(linebuf)) - { - excludeFile.close(); - return; - } - } - } - - excludeFile.close(); -} - -///////////////////////////////////////////////// - -static bool isExcluded(fs::FS &_fs, const char *filename) -{ - if (excludes == NULL) - { - loadExcludeList(_fs, excludeListFile); - } - - ExcludeList *e = excludes; - - while (e) - { - if (matchWild(e->item, filename)) - { - return true; - } - - e = e->next; - } - - return false; -} - -///////////////////////////////////////////////// -///////////////////////////////////////////////// - -// WEB HANDLER IMPLEMENTATION - -SPIFFSEditor::SPIFFSEditor(const fs::FS& fs, const String& username, const String& password) - : _fs(fs) - , _username(username) - , _password(password) - , _authenticated(false) - , _startTime(0) -{} - -///////////////////////////////////////////////// - -bool SPIFFSEditor::canHandle(AsyncWebServerRequest *request) -{ - if (request->url().equalsIgnoreCase("/edit")) - { - if (request->method() == HTTP_GET) - { - if (request->hasParam("list")) - return true; - - if (request->hasParam("edit")) - { - request->_tempFile = _fs.open(request->arg("edit"), "r"); - - if (!request->_tempFile) - { - return false; - } - - if (request->_tempFile.isDirectory()) - { - request->_tempFile.close(); - return false; - } - } - - if (request->hasParam("download")) - { - request->_tempFile = _fs.open(request->arg("download"), "r"); - - if (!request->_tempFile) - { - return false; - } - - if (request->_tempFile.isDirectory()) - { - request->_tempFile.close(); - return false; - } - } - - request->addInterestingHeader("If-Modified-Since"); - return true; - } - - else if (request->method() == HTTP_POST) - return true; - else if (request->method() == HTTP_DELETE) - return true; - else if (request->method() == HTTP_PUT) - return true; - } - - return false; -} - -///////////////////////////////////////////////// - -void SPIFFSEditor::handleRequest(AsyncWebServerRequest *request) -{ - if (_username.length() && _password.length() && !request->authenticate(_username.c_str(), _password.c_str())) - return request->requestAuthentication(); - - if (request->method() == HTTP_GET) - { - if (request->hasParam("list")) - { - String path = request->getParam("list")->value(); - File dir = _fs.open(path); - path = String(); - String output = "["; - - File entry = dir.openNextFile(); - - while (entry) - { - if (isExcluded(_fs, entry.name())) - { - entry = dir.openNextFile(); - continue; - } - - if (output != "[") - output += ','; - - output += "{\"type\":\""; - output += "file"; - output += "\",\"name\":\""; - output += String(entry.name()); - output += "\",\"size\":"; - output += String(entry.size()); - output += "}"; - - entry = dir.openNextFile(); - } - - dir.close(); - output += "]"; - request->send(200, "application/json", output); - output = String(); - } - else if (request->hasParam("edit") || request->hasParam("download")) - { - request->send(request->_tempFile, request->_tempFile.name(), String(), request->hasParam("download")); - } - else - { - const char * buildTime = __DATE__ " " __TIME__ " GMT"; - - if (request->header("If-Modified-Since").equals(buildTime)) - { - request->send(304); - } - else - { - AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", edit_htm_gz, edit_htm_gz_len); - response->addHeader("Content-Encoding", "gzip"); - response->addHeader("Last-Modified", buildTime); - request->send(response); - } - } - } - else if (request->method() == HTTP_DELETE) - { - if (request->hasParam("path", true)) - { - _fs.remove(request->getParam("path", true)->value()); - request->send(200, "", "DELETE: " + request->getParam("path", true)->value()); - } - else - request->send(404); - } - else if (request->method() == HTTP_POST) - { - if (request->hasParam("data", true, true) && _fs.exists(request->getParam("data", true, true)->value())) - request->send(200, "", "UPLOADED: " + request->getParam("data", true, true)->value()); - else - request->send(500); - } - else if (request->method() == HTTP_PUT) - { - if (request->hasParam("path", true)) - { - String filename = request->getParam("path", true)->value(); - - if (_fs.exists(filename)) - { - request->send(200); - } - else - { - fs::File f = _fs.open(filename, "w"); - - if (f) - { - f.write((uint8_t)0x00); - f.close(); - request->send(200, "", "CREATE: " + filename); - } - else - { - request->send(500); - } - } - } - else - request->send(400); - } -} - -///////////////////////////////////////////////// - -void SPIFFSEditor::handleUpload(AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data, - size_t len, bool final) -{ - if (!index) - { - if (!_username.length() || request->authenticate(_username.c_str(), _password.c_str())) - { - _authenticated = true; - request->_tempFile = _fs.open(filename, "w"); - _startTime = millis(); - } - } - - if (_authenticated && request->_tempFile) - { - if (len) - { - request->_tempFile.write(data, len); - } - - if (final) - { - request->_tempFile.close(); - } - } -} diff --git a/lib/AsyncWebServer_ESP32_W5500/src/ESP32_W5500_SPIFFSEditor.h b/lib/AsyncWebServer_ESP32_W5500/src/ESP32_W5500_SPIFFSEditor.h deleted file mode 100644 index 098dfa9..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/ESP32_W5500_SPIFFSEditor.h +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************************************************************** - ESP32_W5500_SPIFFSEditor.h - Dead simple Ethernet AsyncWebServer. - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - - Original author: Hristo Gochkov - - Copyright (c) 2016 Hristo Gochkov. All rights reserved. - - This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License along with this library; - if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Version: 1.6.4 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2 - 1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples - 1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error - *****************************************************************************************************************************/ - -#ifndef ESP32_W5500_SPIFFSEditor_H_ -#define ESP32_W5500_SPIFFSEditor_H_ - -#include "AsyncWebServer_ESP32_W5500.h" - -///////////////////////////////////////////////// - -class SPIFFSEditor: public AsyncWebHandler -{ - private: - fs::FS _fs; - String _username; - String _password; - bool _authenticated; - uint32_t _startTime; - - public: - SPIFFSEditor(const fs::FS& fs, const String& username = String(), const String& password = String()); - virtual bool canHandle(AsyncWebServerRequest *request) override final; - virtual void handleRequest(AsyncWebServerRequest *request) override final; - virtual void handleUpload(AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data, - size_t len, bool final) override final; - - virtual bool isRequestHandlerTrivial() override final - { - return false; - } -}; - -///////////////////////////////////////////////// - -#endif // SPIFFSEditor_H_ diff --git a/lib/AsyncWebServer_ESP32_W5500/src/StringArray.h b/lib/AsyncWebServer_ESP32_W5500/src/StringArray.h deleted file mode 100644 index 7ee92ca..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/StringArray.h +++ /dev/null @@ -1,353 +0,0 @@ -/**************************************************************************************************************************** - StringArray.h - Dead simple Ethernet AsyncWebServer. - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - - Original author: Hristo Gochkov - - Copyright (c) 2016 Hristo Gochkov. All rights reserved. - - This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License along with this library; - if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Version: 1.6.4 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2 - 1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples - 1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error - *****************************************************************************************************************************/ - -#ifndef STRINGARRAY_H_ -#define STRINGARRAY_H_ - -#include "stddef.h" -#include "WString.h" - -///////////////////////////////////////////////// - -template -class LinkedListNode -{ - T _value; - - public: - LinkedListNode* next; - LinkedListNode(const T val): _value(val), next(nullptr) {} - ~LinkedListNode() {} - - ///////////////////////////////////////////////// - - inline const T& value() const - { - return _value; - }; - - ///////////////////////////////////////////////// - - inline T& value() - { - return _value; - } -}; - -///////////////////////////////////////////////// -///////////////////////////////////////////////// - -template class Item = LinkedListNode> -class LinkedList -{ - public: - typedef Item ItemType; - typedef std::function OnRemove; - typedef std::function Predicate; - - private: - ItemType* _root; - OnRemove _onRemove; - - class Iterator - { - ItemType* _node; - - public: - Iterator(ItemType* current = nullptr) : _node(current) {} - Iterator(const Iterator& i) : _node(i._node) {} - - ///////////////////////////////////////////////// - - inline Iterator& operator ++() - { - _node = _node->next; - return *this; - } - - ///////////////////////////////////////////////// - - inline bool operator != (const Iterator& i) const - { - return _node != i._node; - } - - ///////////////////////////////////////////////// - - inline const T& operator * () const - { - return _node->value(); - } - - ///////////////////////////////////////////////// - - inline const T* operator -> () const - { - return &_node->value(); - } - }; - - public: - typedef const Iterator ConstIterator; - - ///////////////////////////////////////////////// - - inline ConstIterator begin() const - { - return ConstIterator(_root); - } - - ///////////////////////////////////////////////// - - inline ConstIterator end() const - { - return ConstIterator(nullptr); - } - - ///////////////////////////////////////////////// - - LinkedList(OnRemove onRemove) : _root(nullptr), _onRemove(onRemove) {} - ~LinkedList() {} - - ///////////////////////////////////////////////// - - void add(const T& t) - { - auto it = new ItemType(t); - - if (!_root) - { - _root = it; - } - else - { - auto i = _root; - - while (i->next) - i = i->next; - - i->next = it; - } - } - - ///////////////////////////////////////////////// - - inline T& front() const - { - return _root->value(); - } - - ///////////////////////////////////////////////// - - inline bool isEmpty() const - { - return _root == nullptr; - } - - ///////////////////////////////////////////////// - - size_t length() const - { - size_t i = 0; - auto it = _root; - - while (it) - { - i++; - it = it->next; - } - - return i; - } - - ///////////////////////////////////////////////// - - size_t count_if(Predicate predicate) const - { - size_t i = 0; - auto it = _root; - - while (it) - { - if (!predicate) - { - i++; - } - else if (predicate(it->value())) - { - i++; - } - - it = it->next; - } - - return i; - } - - ///////////////////////////////////////////////// - - const T* nth(size_t N) const - { - size_t i = 0; - auto it = _root; - - while (it) - { - if (i++ == N) - return &(it->value()); - - it = it->next; - } - - return nullptr; - } - - ///////////////////////////////////////////////// - - bool remove(const T& t) - { - auto it = _root; - auto pit = _root; - - while (it) - { - if (it->value() == t) - { - if (it == _root) - { - _root = _root->next; - } - else - { - pit->next = it->next; - } - - if (_onRemove) - { - _onRemove(it->value()); - } - - delete it; - return true; - } - - pit = it; - it = it->next; - } - - return false; - } - - ///////////////////////////////////////////////// - - bool remove_first(Predicate predicate) - { - auto it = _root; - auto pit = _root; - - while (it) - { - if (predicate(it->value())) - { - if (it == _root) - { - _root = _root->next; - } - else - { - pit->next = it->next; - } - - if (_onRemove) - { - _onRemove(it->value()); - } - - delete it; - return true; - } - - pit = it; - it = it->next; - } - - return false; - } - - ///////////////////////////////////////////////// - - void free() - { - while (_root != nullptr) - { - auto it = _root; - _root = _root->next; - - if (_onRemove) - { - _onRemove(it->value()); - } - - delete it; - } - - _root = nullptr; - } -}; - -///////////////////////////////////////////////// -///////////////////////////////////////////////// - -class StringArray : public LinkedList -{ - public: - - StringArray() : LinkedList(nullptr) {} - - ///////////////////////////////////////////////// - - bool containsIgnoreCase(const String& str) - { - for (const auto& s : *this) - { - if (str.equalsIgnoreCase(s)) - { - return true; - } - } - - return false; - } -}; - -#endif /* STRINGARRAY_H_ */ diff --git a/lib/AsyncWebServer_ESP32_W5500/src/WebAuthentication.cpp b/lib/AsyncWebServer_ESP32_W5500/src/WebAuthentication.cpp deleted file mode 100644 index 6e72451..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/WebAuthentication.cpp +++ /dev/null @@ -1,360 +0,0 @@ -/**************************************************************************************************************************** - WebAuthentication.cpp - Dead simple Ethernet AsyncWebServer. - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - - Original author: Hristo Gochkov - - Copyright (c) 2016 Hristo Gochkov. All rights reserved. - - This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License along with this library; - if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Version: 1.6.4 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2 - 1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples - 1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error - *****************************************************************************************************************************/ - -#include "WebAuthentication.h" -#include - -#include "mbedtls/md5.h" -#include "mbedtls/version.h" - -///////////////////////////////////////////////// - -// Basic Auth hash = base64("username:password") - -bool checkBasicAuthentication(const char * hash, const char * username, const char * password) -{ - if (username == NULL || password == NULL || hash == NULL) - return false; - - size_t toencodeLen = strlen(username) + strlen(password) + 1; - size_t encodedLen = base64_encode_expected_len(toencodeLen); - - if (strlen(hash) != encodedLen) - return false; - - char *toencode = new char[toencodeLen + 1]; - - if (toencode == NULL) - { - return false; - } - - char *encoded = new char[base64_encode_expected_len(toencodeLen) + 1]; - - if (encoded == NULL) - { - delete[] toencode; - - return false; - } - - sprintf(toencode, "%s:%s", username, password); - - if (base64_encode_chars(toencode, toencodeLen, encoded) > 0 && memcmp(hash, encoded, encodedLen) == 0) - { - delete[] toencode; - delete[] encoded; - - return true; - } - - delete[] toencode; - delete[] encoded; - - return false; -} - -///////////////////////////////////////////////// - -static bool getMD5(uint8_t * data, uint16_t len, char * output) -{ - //33 bytes or more - mbedtls_md5_context _ctx; - uint8_t i; - uint8_t * _buf = (uint8_t*)malloc(16); - - if (_buf == NULL) - return false; - - memset(_buf, 0x00, 16); - - mbedtls_md5_init(&_ctx); - -#if (MBEDTLS_VERSION_NUMBER < 0x02070000) - // Superseded from v2.7.0 - mbedtls_md5_starts(&_ctx); - mbedtls_md5_update(&_ctx, data, len); - mbedtls_md5_finish(&_ctx, _buf); -#else - mbedtls_md5_starts_ret(&_ctx); - mbedtls_md5_update_ret(&_ctx, data, len); - mbedtls_md5_finish_ret(&_ctx, _buf); -#endif - - for (i = 0; i < 16; i++) - { - sprintf(output + (i * 2), "%02x", _buf[i]); - } - - free(_buf); - - return true; -} - -///////////////////////////////////////////////// - -static String genRandomMD5() -{ - uint32_t r = rand(); - char * out = (char*)malloc(33); - - if (out == NULL || !getMD5((uint8_t*)(&r), 4, out)) - return ""; - - String res = String(out); - free(out); - - return res; -} - -///////////////////////////////////////////////// - -static String stringMD5(const String& in) -{ - char * out = (char*)malloc(33); - - if (out == NULL || !getMD5((uint8_t*)(in.c_str()), in.length(), out)) - return ""; - - String res = String(out); - free(out); - - return res; -} - -///////////////////////////////////////////////// - -String generateDigestHash(const char * username, const char * password, const char * realm) -{ - if (username == NULL || password == NULL || realm == NULL) - { - return ""; - } - - char * out = (char*)malloc(33); - String res = String(username); - res.concat(":"); - res.concat(realm); - res.concat(":"); - String in = res; - in.concat(password); - - if (out == NULL || !getMD5((uint8_t*)(in.c_str()), in.length(), out)) - return ""; - - res.concat(out); - free(out); - - return res; -} - -///////////////////////////////////////////////// - -String requestDigestAuthentication(const char * realm) -{ - String header = "realm=\""; - - if (realm == NULL) - header.concat("asyncesp"); - else - header.concat(realm); - - header.concat( "\", qop=\"auth\", nonce=\""); - header.concat(genRandomMD5()); - header.concat("\", opaque=\""); - header.concat(genRandomMD5()); - header.concat("\""); - - return header; -} - -///////////////////////////////////////////////// - -bool checkDigestAuthentication(const char * header, const char * method, const char * username, const char * password, - const char * realm, - bool passwordIsHash, const char * nonce, const char * opaque, const char * uri) -{ - if (username == NULL || password == NULL || header == NULL || method == NULL) - { - AWS_LOGERROR(F("checkDigestAuthentication: AUTH FAIL, missing required fields")); - - return false; - } - - String myHeader = String(header); - int nextBreak = myHeader.indexOf(","); - - if (nextBreak < 0) - { - AWS_LOGERROR(F("checkDigestAuthentication: AUTH FAIL, no variables")); - - return false; - } - - String myUsername = String(); - String myRealm = String(); - String myNonce = String(); - String myUri = String(); - String myResponse = String(); - String myQop = String(); - String myNc = String(); - String myCnonce = String(); - - myHeader += ", "; - - do - { - String avLine = myHeader.substring(0, nextBreak); - avLine.trim(); - myHeader = myHeader.substring(nextBreak + 1); - nextBreak = myHeader.indexOf(","); - - int eqSign = avLine.indexOf("="); - - if (eqSign < 0) - { - AWS_LOGERROR(F("checkDigestAuthentication: AUTH FAIL, no = sign")); - - return false; - } - - String varName = avLine.substring(0, eqSign); - avLine = avLine.substring(eqSign + 1); - - if (avLine.startsWith("\"")) - { - avLine = avLine.substring(1, avLine.length() - 1); - } - - if (varName.equals("username")) - { - if (!avLine.equals(username)) - { - AWS_LOGERROR(F("checkDigestAuthentication: AUTH FAIL, username")); - - return false; - } - - AWS_LOGINFO1(F("checkDigestAuthentication: myUsername ="), myUsername); - - myUsername = avLine; - } - else if (varName.equals("realm")) - { - if (realm != NULL && !avLine.equals(realm)) - { - AWS_LOGERROR(F("checkDigestAuthentication: AUTH FAIL, realm")); - - return false; - } - - AWS_LOGINFO1(F("checkDigestAuthentication: myRealm ="), myRealm); - - myRealm = avLine; - } - else if (varName.equals("nonce")) - { - if (nonce != NULL && !avLine.equals(nonce)) - { - AWS_LOGERROR(F("checkDigestAuthentication: AUTH FAIL, nonce")); - - return false; - } - - AWS_LOGINFO1(F("checkDigestAuthentication: myNonce ="), myNonce); - - myNonce = avLine; - } - else if (varName.equals("opaque")) - { - if (opaque != NULL && !avLine.equals(opaque)) - { - AWS_LOGERROR(F("checkDigestAuthentication: AUTH FAIL, opaque")); - - return false; - } - } - else if (varName.equals("uri")) - { - if (uri != NULL && !avLine.equals(uri)) - { - AWS_LOGERROR(F("checkDigestAuthentication: AUTH FAIL, uri")); - - return false; - } - - AWS_LOGINFO1(F("checkDigestAuthentication: myUri ="), myUri); - - myUri = avLine; - } - else if (varName.equals("response")) - { - AWS_LOGINFO1(F("checkDigestAuthentication: myResponse ="), myResponse); - - myResponse = avLine; - } - else if (varName.equals("qop")) - { - AWS_LOGINFO1(F("checkDigestAuthentication: myQop ="), myQop); - - myQop = avLine; - } - else if (varName.equals("nc")) - { - AWS_LOGINFO1(F("checkDigestAuthentication: myNc ="), myNc); - - myNc = avLine; - } - else if (varName.equals("cnonce")) - { - AWS_LOGINFO1(F("checkDigestAuthentication: myCnonce ="), myCnonce); - - myCnonce = avLine; - } - } while (nextBreak > 0); - - String ha1 = (passwordIsHash) ? String(password) : stringMD5(myUsername + ":" + myRealm + ":" + String(password)); - String ha2 = String(method) + ":" + myUri; - String response = ha1 + ":" + myNonce + ":" + myNc + ":" + myCnonce + ":" + myQop + ":" + stringMD5(ha2); - - if (myResponse.equals(stringMD5(response))) - { - AWS_LOGINFO(F("AUTH SUCCESS")); - - return true; - } - - AWS_LOGINFO(F("AUTH FAIL: password")); - - return false; -} diff --git a/lib/AsyncWebServer_ESP32_W5500/src/WebAuthentication.h b/lib/AsyncWebServer_ESP32_W5500/src/WebAuthentication.h deleted file mode 100644 index a5234ad..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/WebAuthentication.h +++ /dev/null @@ -1,55 +0,0 @@ -/**************************************************************************************************************************** - WebAuthentication.h - Dead simple Ethernet AsyncWebServer. - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - - Original author: Hristo Gochkov - - Copyright (c) 2016 Hristo Gochkov. All rights reserved. - - This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License along with this library; - if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Version: 1.6.4 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2 - 1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples - 1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error - *****************************************************************************************************************************/ - -#ifndef WEB_AUTHENTICATION_H_ -#define WEB_AUTHENTICATION_H_ - -#include "Arduino.h" - -#include "AsyncWebServer_ESP32_W5500_Debug.h" - -///////////////////////////////////////////////// - -bool checkBasicAuthentication(const char * header, const char * username, const char * password); -String requestDigestAuthentication(const char * realm); - -bool checkDigestAuthentication(const char * header, const char * method, const char * username, const char * password, - const char * realm, - bool passwordIsHash, const char * nonce, const char * opaque, const char * uri); - -//for storing hashed versions on the device that can be authenticated against -String generateDigestHash(const char * username, const char * password, const char * realm); - -///////////////////////////////////////////////// - -#endif // WEB_AUTHENTICATION_H_ diff --git a/lib/AsyncWebServer_ESP32_W5500/src/WebHandlerImpl.h b/lib/AsyncWebServer_ESP32_W5500/src/WebHandlerImpl.h deleted file mode 100644 index c7caa60..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/WebHandlerImpl.h +++ /dev/null @@ -1,245 +0,0 @@ -/**************************************************************************************************************************** - WebHandlerImpl.h - Dead simple Ethernet AsyncWebServer. - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - - Original author: Hristo Gochkov - - Copyright (c) 2016 Hristo Gochkov. All rights reserved. - - This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License along with this library; - if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Version: 1.6.4 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2 - 1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples - 1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error - *****************************************************************************************************************************/ - -#ifndef ASYNCWEBSERVERHANDLERIMPL_H_ -#define ASYNCWEBSERVERHANDLERIMPL_H_ - -#include - -#ifdef ASYNCWEBSERVER_REGEX - #include -#endif - -#include "stddef.h" -#include - -#include "AsyncWebServer_ESP32_W5500_Debug.h" - -///////////////////////////////////////////////// - -class AsyncStaticWebHandler: public AsyncWebHandler -{ - using File = fs::File; - using FS = fs::FS; - - private: - bool _getFile(AsyncWebServerRequest *request); - bool _fileExists(AsyncWebServerRequest *request, const String& path); - uint8_t _countBits(const uint8_t value) const; - - protected: - FS _fs; - String _uri; - String _path; - String _default_file; - String _cache_control; - String _last_modified; - AwsTemplateProcessor _callback; - bool _isDir; - bool _gzipFirst; - uint8_t _gzipStats; - - public: - AsyncStaticWebHandler(const char* uri, FS& fs, const char* path, const char* cache_control); - virtual bool canHandle(AsyncWebServerRequest *request) override final; - virtual void handleRequest(AsyncWebServerRequest *request) override final; - AsyncStaticWebHandler& setIsDir(bool isDir); - AsyncStaticWebHandler& setDefaultFile(const char* filename); - AsyncStaticWebHandler& setCacheControl(const char* cache_control); - AsyncStaticWebHandler& setLastModified(const char* last_modified); - AsyncStaticWebHandler& setLastModified(struct tm* last_modified); - - AsyncStaticWebHandler& setTemplateProcessor(AwsTemplateProcessor newCallback) - { - _callback = newCallback; - return *this; - } -}; - -///////////////////////////////////////////////// - -class AsyncCallbackWebHandler: public AsyncWebHandler -{ - private: - - protected: - String _uri; - WebRequestMethodComposite _method; - ArRequestHandlerFunction _onRequest; - ArUploadHandlerFunction _onUpload; - ArBodyHandlerFunction _onBody; - bool _isRegex; - - public: - AsyncCallbackWebHandler() : _uri(), _method(HTTP_ANY), _onRequest(NULL), _onUpload(NULL), _onBody(NULL), - _isRegex(false) {} - - ///////////////////////////////////////////////// - - inline void setUri(const String& uri) - { - _uri = uri; - _isRegex = uri.startsWith("^") && uri.endsWith("$"); - } - - ///////////////////////////////////////////////// - - inline void setMethod(WebRequestMethodComposite method) - { - _method = method; - } - - ///////////////////////////////////////////////// - - inline void onRequest(ArRequestHandlerFunction fn) - { - _onRequest = fn; - } - - ///////////////////////////////////////////////// - - inline void onUpload(ArUploadHandlerFunction fn) - { - _onUpload = fn; - } - - ///////////////////////////////////////////////// - - inline void onBody(ArBodyHandlerFunction fn) - { - _onBody = fn; - } - - ///////////////////////////////////////////////// - - virtual bool canHandle(AsyncWebServerRequest *request) override final - { - if (!_onRequest) - return false; - - if (!(_method & request->method())) - return false; - -#ifdef ASYNCWEBSERVER_REGEX - - if (_isRegex) - { - std::regex pattern(_uri.c_str()); - std::smatch matches; - std::string s(request->url().c_str()); - - if (std::regex_search(s, matches, pattern)) - { - for (size_t i = 1; i < matches.size(); ++i) - { - // start from 1 - request->_addPathParam(matches[i].str().c_str()); - } - } - else - { - return false; - } - } - else -#endif - if (_uri.length() && _uri.startsWith("/*.")) - { - String uriTemplate = String (_uri); - uriTemplate = uriTemplate.substring(uriTemplate.lastIndexOf(".")); - - if (!request->url().endsWith(uriTemplate)) - return false; - } - else if (_uri.length() && _uri.endsWith("*")) - { - String uriTemplate = String(_uri); - uriTemplate = uriTemplate.substring(0, uriTemplate.length() - 1); - - if (!request->url().startsWith(uriTemplate)) - return false; - } - else if (_uri.length() && (_uri != request->url() && !request->url().startsWith(_uri + "/"))) - return false; - - request->addInterestingHeader("ANY"); - - return true; - } - - ///////////////////////////////////////////////// - - virtual void handleRequest(AsyncWebServerRequest *request) override final - { - if ((_username != "" && _password != "") && !request->authenticate(_username.c_str(), _password.c_str())) - return request->requestAuthentication(); - - if (_onRequest) - _onRequest(request); - else - request->send(500); - } - - ///////////////////////////////////////////////// - - virtual void handleUpload(AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data, - size_t len, bool final) override final - { - if ((_username != "" && _password != "") && !request->authenticate(_username.c_str(), _password.c_str())) - return request->requestAuthentication(); - - if (_onUpload) - _onUpload(request, filename, index, data, len, final); - } - - ///////////////////////////////////////////////// - - virtual void handleBody(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, - size_t total) override final - { - if ((_username != "" && _password != "") && !request->authenticate(_username.c_str(), _password.c_str())) - return request->requestAuthentication(); - - if (_onBody) - _onBody(request, data, len, index, total); - } - - ///////////////////////////////////////////////// - - virtual bool isRequestHandlerTrivial() override final - { - return _onRequest ? false : true; - } -}; - -#endif /* ASYNCWEBSERVERHANDLERIMPL_H_ */ diff --git a/lib/AsyncWebServer_ESP32_W5500/src/WebHandlers.cpp b/lib/AsyncWebServer_ESP32_W5500/src/WebHandlers.cpp deleted file mode 100644 index 573ee46..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/WebHandlers.cpp +++ /dev/null @@ -1,294 +0,0 @@ -/**************************************************************************************************************************** - WebHandlers.cpp - Dead simple Ethernet AsyncWebServer. - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - - Original author: Hristo Gochkov - - Copyright (c) 2016 Hristo Gochkov. All rights reserved. - - This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License along with this library; - if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Version: 1.6.4 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2 - 1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples - 1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error - *****************************************************************************************************************************/ - -#include "AsyncWebServer_ESP32_W5500.h" - -#include "WebHandlerImpl.h" - -///////////////////////////////////////////////// - -AsyncStaticWebHandler::AsyncStaticWebHandler(const char* uri, FS& fs, const char* path, const char* cache_control) - : _fs(fs), _uri(uri), _path(path), _default_file("index.htm"), _cache_control(cache_control), _last_modified(""), - _callback(nullptr) -{ - // Ensure leading '/' - if (_uri.length() == 0 || _uri[0] != '/') - _uri = "/" + _uri; - - if (_path.length() == 0 || _path[0] != '/') - _path = "/" + _path; - - // If path ends with '/' we assume a hint that this is a directory to improve performance. - // However - if it does not end with '/' we, can't assume a file, path can still be a directory. - _isDir = _path[_path.length() - 1] == '/'; - - // Remove the trailing '/' so we can handle default file - // Notice that root will be "" not "/" - if (_uri[_uri.length() - 1] == '/') - _uri = _uri.substring(0, _uri.length() - 1); - - if (_path[_path.length() - 1] == '/') - _path = _path.substring(0, _path.length() - 1); - - // Reset stats - _gzipFirst = false; - _gzipStats = 0xF8; -} - -///////////////////////////////////////////////// - -AsyncStaticWebHandler& AsyncStaticWebHandler::setIsDir(bool isDir) -{ - _isDir = isDir; - - return *this; -} - -///////////////////////////////////////////////// - -AsyncStaticWebHandler& AsyncStaticWebHandler::setDefaultFile(const char* filename) -{ - _default_file = String(filename); - - return *this; -} - -///////////////////////////////////////////////// - -AsyncStaticWebHandler& AsyncStaticWebHandler::setCacheControl(const char* cache_control) -{ - _cache_control = String(cache_control); - - return *this; -} - -///////////////////////////////////////////////// - -AsyncStaticWebHandler& AsyncStaticWebHandler::setLastModified(const char* last_modified) -{ - _last_modified = String(last_modified); - - return *this; -} - -///////////////////////////////////////////////// - -AsyncStaticWebHandler& AsyncStaticWebHandler::setLastModified(struct tm* last_modified) -{ - char result[30]; - strftime (result, 30, "%a, %d %b %Y %H:%M:%S %Z", last_modified); - - return setLastModified((const char *)result); -} - -///////////////////////////////////////////////// - -bool AsyncStaticWebHandler::canHandle(AsyncWebServerRequest *request) -{ - if (request->method() != HTTP_GET || !request->url().startsWith(_uri) - || !request->isExpectedRequestedConnType(RCT_DEFAULT, RCT_HTTP) ) - { - return false; - } - - if (_getFile(request)) - { - // We interested in "If-Modified-Since" header to check if file was modified - if (_last_modified.length()) - request->addInterestingHeader("If-Modified-Since"); - - if (_cache_control.length()) - request->addInterestingHeader("If-None-Match"); - - AWS_LOGDEBUG("[AsyncStaticWebHandler::canHandle] TRUE"); - - return true; - } - - return false; -} - -///////////////////////////////////////////////// - -bool AsyncStaticWebHandler::_getFile(AsyncWebServerRequest *request) -{ - // Remove the found uri - String path = request->url().substring(_uri.length()); - - // We can skip the file check and look for default if request is to the root of a directory or that request path ends with '/' - bool canSkipFileCheck = (_isDir && path.length() == 0) || (path.length() && path[path.length() - 1] == '/'); - - path = _path + path; - - // Do we have a file or .gz file - if (!canSkipFileCheck && _fileExists(request, path)) - return true; - - // Can't handle if not default file - if (_default_file.length() == 0) - return false; - - // Try to add default file, ensure there is a trailing '/' ot the path. - if (path.length() == 0 || path[path.length() - 1] != '/') - path += "/"; - - path += _default_file; - - return _fileExists(request, path); -} - -///////////////////////////////////////////////// - -#define FILE_IS_REAL(f) (f == true && !f.isDirectory()) - -///////////////////////////////////////////////// - -bool AsyncStaticWebHandler::_fileExists(AsyncWebServerRequest *request, const String& path) -{ - bool fileFound = false; - bool gzipFound = false; - - String gzip = path + ".gz"; - - if (_gzipFirst) - { - request->_tempFile = _fs.open(gzip, "r"); - gzipFound = FILE_IS_REAL(request->_tempFile); - - if (!gzipFound) - { - request->_tempFile = _fs.open(path, "r"); - fileFound = FILE_IS_REAL(request->_tempFile); - } - } - else - { - request->_tempFile = _fs.open(path, "r"); - fileFound = FILE_IS_REAL(request->_tempFile); - - if (!fileFound) - { - request->_tempFile = _fs.open(gzip, "r"); - gzipFound = FILE_IS_REAL(request->_tempFile); - } - } - - bool found = fileFound || gzipFound; - - if (found) - { - // Extract the file name from the path and keep it in _tempObject - size_t pathLen = path.length(); - char * _tempPath = (char*)malloc(pathLen + 1); - snprintf(_tempPath, pathLen + 1, "%s", path.c_str()); - request->_tempObject = (void*)_tempPath; - - // Calculate gzip statistic - _gzipStats = (_gzipStats << 1) + (gzipFound ? 1 : 0); - - if (_gzipStats == 0x00) - _gzipFirst = false; // All files are not gzip - else if (_gzipStats == 0xFF) - _gzipFirst = true; // All files are gzip - else - _gzipFirst = _countBits(_gzipStats) > 4; // IF we have more gzip files - try gzip first - } - - return found; -} - -///////////////////////////////////////////////// - -uint8_t AsyncStaticWebHandler::_countBits(const uint8_t value) const -{ - uint8_t w = value; - uint8_t n; - - for (n = 0; w != 0; n++) - w &= w - 1; - - return n; -} - -///////////////////////////////////////////////// - -void AsyncStaticWebHandler::handleRequest(AsyncWebServerRequest *request) -{ - // Get the filename from request->_tempObject and free it - String filename = String((char*)request->_tempObject); - free(request->_tempObject); - request->_tempObject = NULL; - - if ((_username != "" && _password != "") && !request->authenticate(_username.c_str(), _password.c_str())) - return request->requestAuthentication(); - - if (request->_tempFile == true) - { - String etag = String(request->_tempFile.size()); - - if (_last_modified.length() && _last_modified == request->header("If-Modified-Since")) - { - request->_tempFile.close(); - request->send(304); // Not modified - } - else if (_cache_control.length() && request->hasHeader("If-None-Match") - && request->header("If-None-Match").equals(etag)) - { - request->_tempFile.close(); - AsyncWebServerResponse * response = new AsyncBasicResponse(304); // Not modified - - response->addHeader("Cache-Control", _cache_control); - response->addHeader("ETag", etag); - request->send(response); - } - else - { - AsyncWebServerResponse * response = new AsyncFileResponse(request->_tempFile, filename, String(), false, _callback); - - if (_last_modified.length()) - response->addHeader("Last-Modified", _last_modified); - - if (_cache_control.length()) - { - response->addHeader("Cache-Control", _cache_control); - response->addHeader("ETag", etag); - } - - request->send(response); - } - } - else - { - request->send(404); - } -} diff --git a/lib/AsyncWebServer_ESP32_W5500/src/WebRequest.cpp b/lib/AsyncWebServer_ESP32_W5500/src/WebRequest.cpp deleted file mode 100644 index 866b5b3..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/WebRequest.cpp +++ /dev/null @@ -1,1753 +0,0 @@ -/**************************************************************************************************************************** - WebRequest.cpp - Dead simple Ethernet AsyncWebServer. - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - - Original author: Hristo Gochkov - - Copyright (c) 2016 Hristo Gochkov. All rights reserved. - - This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License along with this library; - if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Version: 1.6.4 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2 - 1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples - 1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error - *****************************************************************************************************************************/ - -//#include "ESPAsyncWebServer.h" -#include "AsyncWebServer_ESP32_W5500.h" - -#include "WebResponseImpl.h" -#include "WebAuthentication.h" - -#ifndef ESP8266 - #define os_strlen strlen -#endif - -///////////////////////////////////////////////// - -static const String SharedEmptyString = String(); - -#define __is_param_char(c) ((c) && ((c) != '{') && ((c) != '[') && ((c) != '&') && ((c) != '=')) - -enum { PARSE_REQ_START, PARSE_REQ_HEADERS, PARSE_REQ_BODY, PARSE_REQ_END, PARSE_REQ_FAIL }; - -///////////////////////////////////////////////// - -AsyncWebServerRequest::AsyncWebServerRequest(AsyncWebServer* s, AsyncClient* c) - : _client(c) - , _server(s) - , _handler(NULL) - , _response(NULL) - , _temp() - , _parseState(0) - , _version(0) - , _method(HTTP_ANY) - , _url() - , _host() - , _contentType() - , _boundary() - , _authorization() - , _reqconntype(RCT_HTTP) - , _isDigest(false) - , _isMultipart(false) - , _isPlainPost(false) - , _expectingContinue(false) - , _contentLength(0) - , _parsedLength(0) - , _headers(LinkedList([](AsyncWebHeader * h) -{ - delete h; -})) -, _params(LinkedList([](AsyncWebParameter *p) -{ - delete p; -})) -, _pathParams(LinkedList([](String *p) -{ - delete p; -})) -, _multiParseState(0) -, _boundaryPosition(0) -, _itemStartIndex(0) -, _itemSize(0) -, _itemName() -, _itemFilename() -, _itemType() -, _itemValue() -, _itemBuffer(0) -, _itemBufferIndex(0) -, _itemIsFile(false) -, _tempObject(NULL) -{ - c->onError([](void *r, AsyncClient * c, int8_t error) - { - ESP32_W5500_AWS_UNUSED(c); - AsyncWebServerRequest *req = (AsyncWebServerRequest*)r; - req->_onError(error); - }, this); - - c->onAck([](void *r, AsyncClient * c, size_t len, uint32_t time) - { - ESP32_W5500_AWS_UNUSED(c); - AsyncWebServerRequest *req = (AsyncWebServerRequest*)r; - req->_onAck(len, time); - }, this); - - c->onDisconnect([](void *r, AsyncClient * c) - { - AsyncWebServerRequest *req = (AsyncWebServerRequest*)r; - req->_onDisconnect(); - delete c; - }, this); - - c->onTimeout([](void *r, AsyncClient * c, uint32_t time) - { - ESP32_W5500_AWS_UNUSED(c); - AsyncWebServerRequest *req = (AsyncWebServerRequest*)r; - req->_onTimeout(time); - }, this); - - c->onData([](void *r, AsyncClient * c, void *buf, size_t len) - { - ESP32_W5500_AWS_UNUSED(c); - AsyncWebServerRequest *req = (AsyncWebServerRequest*)r; - req->_onData(buf, len); - }, this); - - c->onPoll([](void *r, AsyncClient * c) - { - ESP32_W5500_AWS_UNUSED(c); - AsyncWebServerRequest *req = ( AsyncWebServerRequest*)r; - req->_onPoll(); - }, this); -} - -///////////////////////////////////////////////// - -AsyncWebServerRequest::~AsyncWebServerRequest() -{ - _headers.free(); - - _params.free(); - _pathParams.free(); - - _interestingHeaders.free(); - - if (_response != NULL) - { - delete _response; - } - - if (_tempObject != NULL) - { - free(_tempObject); - } -} - -///////////////////////////////////////////////// - -void AsyncWebServerRequest::_onData(void *buf, size_t len) -{ - size_t i = 0; - - while (true) - { - if (_parseState < PARSE_REQ_BODY) - { - // Find new line in buf - char *str = (char*)buf; - - for (i = 0; i < len; i++) - { - if (str[i] == '\n') - { - break; - } - } - - if (i == len) - { - // No new line, just add the buffer in _temp - char ch = str[len - 1]; - str[len - 1] = 0; - _temp.reserve(_temp.length() + len); - _temp.concat(str); - _temp.concat(ch); - } - else - { - // Found new line - extract it and parse - str[i] = 0; // Terminate the string at the end of the line. - _temp.concat(str); - _temp.trim(); - _parseLine(); - - if (++i < len) - { - // Still have more buffer to process - buf = str + i; - len -= i; - continue; - } - } - } - else if (_parseState == PARSE_REQ_BODY) - { - // A handler should be already attached at this point in _parseLine function. - // If handler does nothing (_onRequest is NULL), we don't need to really parse the body. - const bool needParse = _handler && !_handler->isRequestHandlerTrivial(); - - if (_isMultipart) - { - if (needParse) - { - size_t i; - - for (i = 0; i < len; i++) - { - _parseMultipartPostByte(((uint8_t*)buf)[i], i == len - 1); - _parsedLength++; - } - } - else - _parsedLength += len; - } - else - { - if (_parsedLength == 0) - { - if (_contentType.startsWith("application/x-www-form-urlencoded")) - { - _isPlainPost = true; - } - else if (_contentType == "text/plain" && __is_param_char(((char*)buf)[0])) - { - size_t i = 0; - - while (i < len && __is_param_char(((char*)buf)[i++])); - - if (i < len && ((char*)buf)[i - 1] == '=') - { - _isPlainPost = true; - } - } - } - - if (!_isPlainPost) - { - //check if authenticated before calling the body - if (_handler) - _handler->handleBody(this, (uint8_t*)buf, len, _parsedLength, _contentLength); - - _parsedLength += len; - } - else if (needParse) - { - size_t i; - - for (i = 0; i < len; i++) - { - _parsedLength++; - _parsePlainPostChar(((uint8_t*)buf)[i]); - } - } - else - { - _parsedLength += len; - } - } - - if (_parsedLength == _contentLength) - { - _parseState = PARSE_REQ_END; - - //check if authenticated before calling handleRequest and request auth instead - if (_handler) - _handler->handleRequest(this); - - else - send(501); - } - } - - break; - } -} - -///////////////////////////////////////////////// - -void AsyncWebServerRequest::_removeNotInterestingHeaders() -{ - if (_interestingHeaders.containsIgnoreCase("ANY")) - return; // nothing to do - - for (const auto& header : _headers) - { - if (!_interestingHeaders.containsIgnoreCase(header->name().c_str())) - { - _headers.remove(header); - } - } -} - -///////////////////////////////////////////////// - -void AsyncWebServerRequest::_onPoll() -{ - if (_response != NULL && _client != NULL && _client->canSend() && !_response->_finished()) - { - _response->_ack(this, 0, 0); - } -} - -///////////////////////////////////////////////// - -void AsyncWebServerRequest::_onAck(size_t len, uint32_t time) -{ - AWS_LOGDEBUG3("onAck: len =", len, ", time =", time); - - if (_response != NULL) - { - if (!_response->_finished()) - { - _response->_ack(this, len, time); - } - else - { - AsyncWebServerResponse* r = _response; - _response = NULL; - delete r; - } - } -} - -///////////////////////////////////////////////// - -void AsyncWebServerRequest::_onError(int8_t error) -{ - ESP32_W5500_AWS_UNUSED(error); -} - -///////////////////////////////////////////////// - -void AsyncWebServerRequest::_onTimeout(uint32_t time) -{ - ESP32_W5500_AWS_UNUSED(time); - - AWS_LOGDEBUG3("TIMEOUT: time =", time, ", state =", _client->stateToString()); - - _client->close(); -} - -///////////////////////////////////////////////// - -void AsyncWebServerRequest::onDisconnect (ArDisconnectHandler fn) -{ - _onDisconnectfn = fn; -} - -///////////////////////////////////////////////// - -void AsyncWebServerRequest::_onDisconnect() -{ - if (_onDisconnectfn) - { - _onDisconnectfn(); - } - - _server->_handleDisconnect(this); -} - -///////////////////////////////////////////////// - -void AsyncWebServerRequest::_addParam(AsyncWebParameter *p) -{ - _params.add(p); -} - -///////////////////////////////////////////////// - -void AsyncWebServerRequest::_addPathParam(const char *p) -{ - _pathParams.add(new String(p)); -} - -///////////////////////////////////////////////// - -void AsyncWebServerRequest::_addGetParams(const String& params) -{ - size_t start = 0; - - while (start < params.length()) - { - int end = params.indexOf('&', start); - - if (end < 0) - end = params.length(); - - int equal = params.indexOf('=', start); - - if (equal < 0 || equal > end) - equal = end; - - String name = params.substring(start, equal); - String value = equal + 1 < end ? params.substring(equal + 1, end) : String(); - _addParam(new AsyncWebParameter(urlDecode(name), urlDecode(value))); - start = end + 1; - } -} - -///////////////////////////////////////////////// - -bool AsyncWebServerRequest::_parseReqHead() -{ - // Split the head into method, url and version - int index = _temp.indexOf(' '); - String m = _temp.substring(0, index); - index = _temp.indexOf(' ', index + 1); - String u = _temp.substring(m.length() + 1, index); - _temp = _temp.substring(index + 1); - - if (m == "GET") - { - _method = HTTP_GET; - } - else if (m == "POST") - { - _method = HTTP_POST; - } - else if (m == "DELETE") - { - _method = HTTP_DELETE; - } - else if (m == "PUT") - { - _method = HTTP_PUT; - } - else if (m == "PATCH") - { - _method = HTTP_PATCH; - } - else if (m == "HEAD") - { - _method = HTTP_HEAD; - } - else if (m == "OPTIONS") - { - _method = HTTP_OPTIONS; - } - - String g = String(); - index = u.indexOf('?'); - - if (index > 0) - { - g = u.substring(index + 1); - u = u.substring(0, index); - } - - _url = urlDecode(u); - _addGetParams(g); - - if (!_temp.startsWith("HTTP/1.0")) - _version = 1; - - _temp = String(); - - return true; -} - -///////////////////////////////////////////////// - -bool strContains(String src, String find, bool mindcase = true) -{ - int pos = 0, i = 0; - const int slen = src.length(); - const int flen = find.length(); - - if (slen < flen) - return false; - - while (pos <= (slen - flen)) - { - for (i = 0; i < flen; i++) - { - if (mindcase) - { - if (src[pos + i] != find[i]) - i = flen + 1; // no match - } - else if (tolower(src[pos + i]) != tolower(find[i])) - i = flen + 1; // no match - } - - if (i == flen) - return true; - - pos++; - } - - return false; -} - -///////////////////////////////////////////////// - -bool AsyncWebServerRequest::_parseReqHeader() -{ - int index = _temp.indexOf(':'); - - if (index) - { - String name = _temp.substring(0, index); - String value = _temp.substring(index + 2); - - if (name.equalsIgnoreCase("Host")) - { - _host = value; - } - else if (name.equalsIgnoreCase("Content-Type")) - { - _contentType = value.substring(0, value.indexOf(';')); - - if (value.startsWith("multipart/")) - { - _boundary = value.substring(value.indexOf('=') + 1); - _boundary.replace("\"", ""); - _isMultipart = true; - } - } - else if (name.equalsIgnoreCase("Content-Length")) - { - _contentLength = atoi(value.c_str()); - } - else if (name.equalsIgnoreCase("Expect") && value == "100-continue") - { - _expectingContinue = true; - } - else if (name.equalsIgnoreCase("Authorization")) - { - if (value.length() > 5 && value.substring(0, 5).equalsIgnoreCase("Basic")) - { - _authorization = value.substring(6); - } - else if (value.length() > 6 && value.substring(0, 6).equalsIgnoreCase("Digest")) - { - _isDigest = true; - _authorization = value.substring(7); - } - } - else - { - if (name.equalsIgnoreCase("Upgrade") && value.equalsIgnoreCase("websocket")) - { - // WebSocket request can be uniquely identified by header: [Upgrade: websocket] - _reqconntype = RCT_WS; - } - else - { - if (name.equalsIgnoreCase("Accept") && strContains(value, "text/event-stream", false)) - { - // WebEvent request can be uniquely identified by header: [Accept: text/event-stream] - _reqconntype = RCT_EVENT; - } - } - } - - _headers.add(new AsyncWebHeader(name, value)); - } - - _temp = String(); - - return true; -} - -///////////////////////////////////////////////// - -void AsyncWebServerRequest::_parsePlainPostChar(uint8_t data) -{ - if (data && (char)data != '&') - _temp += (char)data; - - if (!data || (char)data == '&' || _parsedLength == _contentLength) - { - String name = "body"; - String value = _temp; - - if (!_temp.startsWith("{") && !_temp.startsWith("[") && _temp.indexOf('=') > 0) - { - name = _temp.substring(0, _temp.indexOf('=')); - value = _temp.substring(_temp.indexOf('=') + 1); - } - - _addParam(new AsyncWebParameter(urlDecode(name), urlDecode(value), true)); - _temp = String(); - } -} - -///////////////////////////////////////////////// - -void AsyncWebServerRequest::_handleUploadByte(uint8_t data, bool last) -{ - _itemBuffer[_itemBufferIndex++] = data; - - if (last || _itemBufferIndex == 1460) - { - //check if authenticated before calling the upload - if (_handler) - _handler->handleUpload(this, _itemFilename, _itemSize - _itemBufferIndex, _itemBuffer, _itemBufferIndex, false); - - _itemBufferIndex = 0; - } -} - -///////////////////////////////////////////////// - -enum -{ - EXPECT_BOUNDARY, - PARSE_HEADERS, - WAIT_FOR_RETURN1, - EXPECT_FEED1, - EXPECT_DASH1, - EXPECT_DASH2, - BOUNDARY_OR_DATA, - DASH3_OR_RETURN2, - EXPECT_FEED2, - PARSING_FINISHED, - PARSE_ERROR -}; - -///////////////////////////////////////////////// - -void AsyncWebServerRequest::_parseMultipartPostByte(uint8_t data, bool last) -{ -#define itemWriteByte(b) do { _itemSize++; if(_itemIsFile) _handleUploadByte(b, last); else _itemValue+=(char)(b); } while(0) - - if (!_parsedLength) - { - _multiParseState = EXPECT_BOUNDARY; - _temp = String(); - _itemName = String(); - _itemFilename = String(); - _itemType = String(); - } - - if (_multiParseState == WAIT_FOR_RETURN1) - { - if (data != '\r') - { - itemWriteByte(data); - } - else - { - _multiParseState = EXPECT_FEED1; - } - } - else if (_multiParseState == EXPECT_BOUNDARY) - { - if (_parsedLength < 2 && data != '-') - { - _multiParseState = PARSE_ERROR; - - return; - } - else if (_parsedLength - 2 < _boundary.length() && _boundary.c_str()[_parsedLength - 2] != data) - { - _multiParseState = PARSE_ERROR; - - return; - } - else if (_parsedLength - 2 == _boundary.length() && data != '\r') - { - _multiParseState = PARSE_ERROR; - - return; - } - else if (_parsedLength - 3 == _boundary.length()) - { - if (data != '\n') - { - _multiParseState = PARSE_ERROR; - - return; - } - - _multiParseState = PARSE_HEADERS; - _itemIsFile = false; - } - } - else if (_multiParseState == PARSE_HEADERS) - { - if ((char)data != '\r' && (char)data != '\n') - _temp += (char)data; - - if ((char)data == '\n') - { - if (_temp.length()) - { - if (_temp.length() > 12 && _temp.substring(0, 12).equalsIgnoreCase("Content-Type")) - { - _itemType = _temp.substring(14); - _itemIsFile = true; - } - else if (_temp.length() > 19 && _temp.substring(0, 19).equalsIgnoreCase("Content-Disposition")) - { - _temp = _temp.substring(_temp.indexOf(';') + 2); - - while (_temp.indexOf(';') > 0) - { - String name = _temp.substring(0, _temp.indexOf('=')); - String nameVal = _temp.substring(_temp.indexOf('=') + 2, _temp.indexOf(';') - 1); - - if (name == "name") - { - _itemName = nameVal; - } - else if (name == "filename") - { - _itemFilename = nameVal; - _itemIsFile = true; - } - - _temp = _temp.substring(_temp.indexOf(';') + 2); - } - - String name = _temp.substring(0, _temp.indexOf('=')); - String nameVal = _temp.substring(_temp.indexOf('=') + 2, _temp.length() - 1); - - if (name == "name") - { - _itemName = nameVal; - } - else if (name == "filename") - { - _itemFilename = nameVal; - _itemIsFile = true; - } - } - - _temp = String(); - } - else - { - _multiParseState = WAIT_FOR_RETURN1; - - //value starts from here - _itemSize = 0; - _itemStartIndex = _parsedLength; - _itemValue = String(); - - if (_itemIsFile) - { - if (_itemBuffer) - free(_itemBuffer); - - _itemBuffer = (uint8_t*) malloc(1460); - - if (_itemBuffer == NULL) - { - _multiParseState = PARSE_ERROR; - - return; - } - - _itemBufferIndex = 0; - } - } - } - } - else if (_multiParseState == EXPECT_FEED1) - { - if (data != '\n') - { - _multiParseState = WAIT_FOR_RETURN1; - itemWriteByte('\r'); - - _parseMultipartPostByte(data, last); - } - else - { - _multiParseState = EXPECT_DASH1; - } - } - else if (_multiParseState == EXPECT_DASH1) - { - if (data != '-') - { - _multiParseState = WAIT_FOR_RETURN1; - itemWriteByte('\r'); - itemWriteByte('\n'); - - _parseMultipartPostByte(data, last); - } - else - { - _multiParseState = EXPECT_DASH2; - } - } - else if (_multiParseState == EXPECT_DASH2) - { - if (data != '-') - { - _multiParseState = WAIT_FOR_RETURN1; - itemWriteByte('\r'); - itemWriteByte('\n'); - itemWriteByte('-'); - - _parseMultipartPostByte(data, last); - } - else - { - _multiParseState = BOUNDARY_OR_DATA; - _boundaryPosition = 0; - } - } - else if (_multiParseState == BOUNDARY_OR_DATA) - { - if (_boundaryPosition < _boundary.length() && _boundary.c_str()[_boundaryPosition] != data) - { - _multiParseState = WAIT_FOR_RETURN1; - itemWriteByte('\r'); - itemWriteByte('\n'); - itemWriteByte('-'); - itemWriteByte('-'); - - uint8_t i; - - for (i = 0; i < _boundaryPosition; i++) - itemWriteByte(_boundary.c_str()[i]); - - _parseMultipartPostByte(data, last); - } - else if (_boundaryPosition == _boundary.length() - 1) - { - _multiParseState = DASH3_OR_RETURN2; - - if (!_itemIsFile) - { - _addParam(new AsyncWebParameter(_itemName, _itemValue, true)); - } - else - { - if (_itemSize) - { - //check if authenticated before calling the upload - if (_handler) - _handler->handleUpload(this, _itemFilename, _itemSize - _itemBufferIndex, _itemBuffer, _itemBufferIndex, true); - - _itemBufferIndex = 0; - _addParam(new AsyncWebParameter(_itemName, _itemFilename, true, true, _itemSize)); - } - - free(_itemBuffer); - _itemBuffer = NULL; - } - - } - else - { - _boundaryPosition++; - } - } - else if (_multiParseState == DASH3_OR_RETURN2) - { - if (data == '-' && (_contentLength - _parsedLength - 4) != 0) - { - AWS_LOGDEBUG1("ERROR: The parser got to the end of the POST but is expecting more bytes =", - (_contentLength - _parsedLength - 4)); - AWS_LOGDEBUG("Drop an issue so we can have more info on the matter!"); - - _contentLength = _parsedLength + 4;//lets close the request gracefully - } - - if (data == '\r') - { - _multiParseState = EXPECT_FEED2; - } - else if (data == '-' && _contentLength == (_parsedLength + 4)) - { - _multiParseState = PARSING_FINISHED; - } - else - { - _multiParseState = WAIT_FOR_RETURN1; - itemWriteByte('\r'); - itemWriteByte('\n'); - itemWriteByte('-'); - itemWriteByte('-'); - - uint8_t i; - - for (i = 0; i < _boundary.length(); i++) - itemWriteByte(_boundary.c_str()[i]); - - _parseMultipartPostByte(data, last); - } - } - else if (_multiParseState == EXPECT_FEED2) - { - if (data == '\n') - { - _multiParseState = PARSE_HEADERS; - _itemIsFile = false; - } - else - { - _multiParseState = WAIT_FOR_RETURN1; - itemWriteByte('\r'); - itemWriteByte('\n'); - itemWriteByte('-'); - itemWriteByte('-'); - - uint8_t i; - - for (i = 0; i < _boundary.length(); i++) - itemWriteByte(_boundary.c_str()[i]); - - itemWriteByte('\r'); - - _parseMultipartPostByte(data, last); - } - } -} - -///////////////////////////////////////////////// - -void AsyncWebServerRequest::_parseLine() -{ - if (_parseState == PARSE_REQ_START) - { - if (!_temp.length()) - { - _parseState = PARSE_REQ_FAIL; - _client->close(); - } - else - { - _parseReqHead(); - _parseState = PARSE_REQ_HEADERS; - } - - return; - } - - if (_parseState == PARSE_REQ_HEADERS) - { - if (!_temp.length()) - { - //end of headers - _server->_rewriteRequest(this); - _server->_attachHandler(this); - _removeNotInterestingHeaders(); - - if (_expectingContinue) - { - const char * response = "HTTP/1.1 100 Continue\r\n\r\n"; - //_client->write(response, os_strlen(response)); - _client->write(response, strlen(response)); - } - - //check handler for authentication - if (_contentLength) - { - _parseState = PARSE_REQ_BODY; - } - else - { - _parseState = PARSE_REQ_END; - - if (_handler) - _handler->handleRequest(this); - else - send(501); - } - } - else - _parseReqHeader(); - } -} - -///////////////////////////////////////////////// - -size_t AsyncWebServerRequest::headers() const -{ - return _headers.length(); -} - -///////////////////////////////////////////////// - -bool AsyncWebServerRequest::hasHeader(const String& name) const -{ - for (const auto& h : _headers) - { - if (h->name().equalsIgnoreCase(name)) - { - return true; - } - } - - return false; -} - -///////////////////////////////////////////////// - -bool AsyncWebServerRequest::hasHeader(const __FlashStringHelper * data) const -{ - PGM_P p = reinterpret_cast(data); - size_t n = 0; - - while (1) - { - if (pgm_read_byte(p + n) == 0) - break; - - n += 1; - } - - char * name = (char*) malloc(n + 1); - name[n] = 0; - - if (name) - { - for (size_t b = 0; b < n; b++) - name[b] = pgm_read_byte(p++); - - bool result = hasHeader( String(name) ); - free(name); - return result; - } - else - { - return false; - } -} - -///////////////////////////////////////////////// - -AsyncWebHeader* AsyncWebServerRequest::getHeader(const String& name) const -{ - for (const auto& h : _headers) - { - if (h->name().equalsIgnoreCase(name)) - { - return h; - } - } - - return nullptr; -} - -///////////////////////////////////////////////// - -AsyncWebHeader* AsyncWebServerRequest::getHeader(const __FlashStringHelper * data) const -{ - PGM_P p = reinterpret_cast(data); - size_t n = strlen_P(p); - char * name = (char*) malloc(n + 1); - - if (name) - { - strcpy_P(name, p); - AsyncWebHeader* result = getHeader( String(name)); - free(name); - return result; - } - else - { - return nullptr; - } -} - -///////////////////////////////////////////////// - -AsyncWebHeader* AsyncWebServerRequest::getHeader(size_t num) const -{ - auto header = _headers.nth(num); - - return (header ? *header : nullptr); -} - -///////////////////////////////////////////////// - -size_t AsyncWebServerRequest::params() const -{ - return _params.length(); -} - -///////////////////////////////////////////////// - -bool AsyncWebServerRequest::hasParam(const String& name, bool post, bool file) const -{ - for (const auto& p : _params) - { - if (p->name() == name && p->isPost() == post && p->isFile() == file) - { - return true; - } - } - - return false; -} - -///////////////////////////////////////////////// - -bool AsyncWebServerRequest::hasParam(const __FlashStringHelper * data, bool post, bool file) const -{ - PGM_P p = reinterpret_cast(data); - size_t n = strlen_P(p); - - char * name = (char*) malloc(n + 1); - name[n] = 0; - - if (name) - { - strcpy_P(name, p); - bool result = hasParam( name, post, file); - free(name); - - return result; - } - else - { - return false; - } -} - -///////////////////////////////////////////////// - -AsyncWebParameter* AsyncWebServerRequest::getParam(const String& name, bool post, bool file) const -{ - for (const auto& p : _params) - { - if (p->name() == name && p->isPost() == post && p->isFile() == file) - { - return p; - } - } - - return nullptr; -} - -///////////////////////////////////////////////// - -AsyncWebParameter* AsyncWebServerRequest::getParam(const __FlashStringHelper * data, bool post, bool file) const -{ - PGM_P p = reinterpret_cast(data); - size_t n = strlen_P(p); - char * name = (char*) malloc(n + 1); - - if (name) - { - strcpy_P(name, p); - AsyncWebParameter* result = getParam(name, post, file); - free(name); - - return result; - } - else - { - return nullptr; - } -} - -///////////////////////////////////////////////// - -AsyncWebParameter* AsyncWebServerRequest::getParam(size_t num) const -{ - auto param = _params.nth(num); - - return (param ? *param : nullptr); -} - -///////////////////////////////////////////////// - -void AsyncWebServerRequest::addInterestingHeader(const String& name) -{ - if (!_interestingHeaders.containsIgnoreCase(name)) - _interestingHeaders.add(name); -} - -///////////////////////////////////////////////// - -void AsyncWebServerRequest::send(AsyncWebServerResponse *response) -{ - _response = response; - - if (_response == NULL) - { - _client->close(true); - - _onDisconnect(); - - return; - } - - if (!_response->_sourceValid()) - { - delete response; - _response = NULL; - send(500); - } - else - { - _client->setRxTimeout(0); - _response->_respond(this); - } -} - -//RSMOD/////////////////////////////////////////////// - -AsyncWebServerResponse * AsyncWebServerRequest::beginResponse(int code, const String& contentType, const char * content) -{ - return new AsyncBasicResponse(code, contentType, content); -} -///////////////////////////////////////////////// - -AsyncWebServerResponse * AsyncWebServerRequest::beginResponse(int code, const String& contentType, - const String& content) -{ - return new AsyncBasicResponse(code, contentType, content); -} - -///////////////////////////////////////////////// -// KH add for favicon -AsyncWebServerResponse * AsyncWebServerRequest::beginResponse(int code, const String& contentType, - const uint8_t * content, size_t len, - AwsTemplateProcessor callback) -{ - return new AsyncProgmemResponse(code, contentType, content, len, callback); -} - -///////////////////////////////////////////////// - -AsyncWebServerResponse * AsyncWebServerRequest::beginResponse(FS &fs, const String& path, const String& contentType, - bool download, - AwsTemplateProcessor callback) -{ - if (fs.exists(path) || (!download && fs.exists(path + ".gz"))) - return new AsyncFileResponse(fs, path, contentType, download, callback); - - return NULL; -} - -///////////////////////////////////////////////// - -AsyncWebServerResponse * AsyncWebServerRequest::beginResponse(File content, const String& path, - const String& contentType, bool download, - AwsTemplateProcessor callback) -{ - if (content == true) - return new AsyncFileResponse(content, path, contentType, download, callback); - - return NULL; -} - -///////////////////////////////////////////////// - -AsyncWebServerResponse * AsyncWebServerRequest::beginResponse(Stream &stream, const String& contentType, size_t len, - AwsTemplateProcessor callback) -{ - return new AsyncStreamResponse(stream, contentType, len, callback); -} - -///////////////////////////////////////////////// - -AsyncWebServerResponse * AsyncWebServerRequest::beginResponse(const String& contentType, size_t len, - AwsResponseFiller callback, - AwsTemplateProcessor templateCallback) -{ - return new AsyncCallbackResponse(contentType, len, callback, templateCallback); -} - -///////////////////////////////////////////////// - -AsyncWebServerResponse * AsyncWebServerRequest::beginChunkedResponse(const String& contentType, - AwsResponseFiller callback, - AwsTemplateProcessor templateCallback) -{ - if (_version) - return new AsyncChunkedResponse(contentType, callback, templateCallback); - - return new AsyncCallbackResponse(contentType, 0, callback, templateCallback); -} - -///////////////////////////////////////////////// - -AsyncResponseStream * AsyncWebServerRequest::beginResponseStream(const String& contentType, size_t bufferSize) -{ - return new AsyncResponseStream(contentType, bufferSize); -} - -AsyncWebServerResponse * AsyncWebServerRequest::beginResponse_P(int code, const String& contentType, - const uint8_t * content, size_t len, - AwsTemplateProcessor callback) -{ - return new AsyncProgmemResponse(code, contentType, content, len, callback); -} - -///////////////////////////////////////////////// - -AsyncWebServerResponse * AsyncWebServerRequest::beginResponse_P(int code, const String& contentType, PGM_P content, - AwsTemplateProcessor callback) -{ - return beginResponse_P(code, contentType, (const uint8_t *)content, strlen_P(content), callback); -} - -//RSMOD/////////////////////////////////////////////// - -void AsyncWebServerRequest::send(int code, const String& contentType, const char *content, bool nonDetructiveSend) -{ - if (nonDetructiveSend) - { - send(beginResponse(code, contentType, String(content))); // for backwards compatibility - } - else - { - send(beginResponse(code, contentType, content)); - } -} - -///////////////////////////////////////////////// - -void AsyncWebServerRequest::send(int code, const String& contentType, const String& content) -{ - send(beginResponse(code, contentType, content)); -} - -///////////////////////////////////////////////// - -void AsyncWebServerRequest::send(FS &fs, const String& path, const String& contentType, bool download, - AwsTemplateProcessor callback) -{ - if (fs.exists(path) || (!download && fs.exists(path + ".gz"))) - { - send(beginResponse(fs, path, contentType, download, callback)); - } - else - send(404); -} - -///////////////////////////////////////////////// - -void AsyncWebServerRequest::send(File content, const String& path, const String& contentType, bool download, - AwsTemplateProcessor callback) -{ - if (content == true) - { - send(beginResponse(content, path, contentType, download, callback)); - } - else - send(404); -} - -///////////////////////////////////////////////// - -void AsyncWebServerRequest::send(Stream &stream, const String& contentType, size_t len, AwsTemplateProcessor callback) -{ - send(beginResponse(stream, contentType, len, callback)); -} - -///////////////////////////////////////////////// - -void AsyncWebServerRequest::send(const String& contentType, size_t len, AwsResponseFiller callback, - AwsTemplateProcessor templateCallback) -{ - send(beginResponse(contentType, len, callback, templateCallback)); -} - -///////////////////////////////////////////////// - -void AsyncWebServerRequest::sendChunked(const String& contentType, AwsResponseFiller callback, - AwsTemplateProcessor templateCallback) -{ - send(beginChunkedResponse(contentType, callback, templateCallback)); -} - -///////////////////////////////////////////////// - -void AsyncWebServerRequest::send_P(int code, const String& contentType, const uint8_t * content, size_t len, - AwsTemplateProcessor callback) -{ - send(beginResponse_P(code, contentType, content, len, callback)); -} - -///////////////////////////////////////////////// - -void AsyncWebServerRequest::send_P(int code, const String& contentType, PGM_P content, AwsTemplateProcessor callback) -{ - send(beginResponse_P(code, contentType, content, callback)); -} - -///////////////////////////////////////////////// - -void AsyncWebServerRequest::redirect(const String& url) -{ - AsyncWebServerResponse * response = beginResponse(302); - - response->addHeader("Location", url); - send(response); -} - -///////////////////////////////////////////////// - -bool AsyncWebServerRequest::authenticate(const char * username, const char * password, const char * realm, - bool passwordIsHash) -{ - AWS_LOGDEBUG1("AsyncWebServerRequest::authenticate: auth-len =", _authorization.length()); - - if (_authorization.length()) - { - if (_isDigest) - { - AWS_LOGDEBUG("AsyncWebServerRequest::authenticate: _isDigest"); - - return checkDigestAuthentication(_authorization.c_str(), methodToString(), username, password, realm, passwordIsHash, - NULL, NULL, NULL); - } - else if (!passwordIsHash) - { - AWS_LOGDEBUG("AsyncWebServerRequest::authenticate: !passwordIsHash"); - - return checkBasicAuthentication(_authorization.c_str(), username, password); - } - else - { - AWS_LOGDEBUG("AsyncWebServerRequest::authenticate: Using password _authorization.equals"); - - return _authorization.equals(password); - } - } - - AWS_LOGDEBUG("AsyncWebServerRequest::authenticate: failed, len = 0"); - - return false; -} - -///////////////////////////////////////////////// - -bool AsyncWebServerRequest::authenticate(const char * hash) -{ - if (!_authorization.length() || hash == NULL) - return false; - - if (_isDigest) - { - String hStr = String(hash); - int separator = hStr.indexOf(":"); - - if (separator <= 0) - return false; - - String username = hStr.substring(0, separator); - hStr = hStr.substring(separator + 1); - separator = hStr.indexOf(":"); - - if (separator <= 0) - return false; - - String realm = hStr.substring(0, separator); - hStr = hStr.substring(separator + 1); - - return checkDigestAuthentication(_authorization.c_str(), methodToString(), username.c_str(), hStr.c_str(), - realm.c_str(), true, NULL, NULL, NULL); - } - - return (_authorization.equals(hash)); -} - -///////////////////////////////////////////////// - -void AsyncWebServerRequest::requestAuthentication(const char * realm, bool isDigest) -{ - AsyncWebServerResponse * r = beginResponse(401); - - if (!isDigest && realm == NULL) - { - r->addHeader("WWW-Authenticate", "Basic realm=\"Login Required\""); - } - else if (!isDigest) - { - String header = "Basic realm=\""; - header.concat(realm); - header.concat("\""); - r->addHeader("WWW-Authenticate", header); - } - else - { - String header = "Digest "; - header.concat(requestDigestAuthentication(realm)); - r->addHeader("WWW-Authenticate", header); - } - - send(r); -} - -///////////////////////////////////////////////// - -bool AsyncWebServerRequest::hasArg(const char* name) const -{ - for (const auto& arg : _params) - { - if (arg->name() == name) - { - return true; - } - } - - return false; -} - -///////////////////////////////////////////////// - -bool AsyncWebServerRequest::hasArg(const __FlashStringHelper * data) const -{ - PGM_P p = reinterpret_cast(data); - size_t n = strlen_P(p); - char * name = (char*) malloc(n + 1); - - if (name) - { - strcpy_P(name, p); - bool result = hasArg( name ); - free(name); - - return result; - } - else - { - return false; - } -} - -///////////////////////////////////////////////// - -const String& AsyncWebServerRequest::arg(const String& name) const -{ - for (const auto& arg : _params) - { - if (arg->name() == name) - { - return arg->value(); - } - } - - return SharedEmptyString; -} - -///////////////////////////////////////////////// - -const String& AsyncWebServerRequest::arg(const __FlashStringHelper * data) const -{ - PGM_P p = reinterpret_cast(data); - size_t n = strlen_P(p); - char * name = (char*) malloc(n + 1); - - if (name) - { - strcpy_P(name, p); - const String & result = arg( String(name) ); - free(name); - - return result; - } - else - { - return SharedEmptyString; - } -} - -///////////////////////////////////////////////// - -const String& AsyncWebServerRequest::arg(size_t i) const -{ - return getParam(i)->value(); -} - -///////////////////////////////////////////////// - -const String& AsyncWebServerRequest::argName(size_t i) const -{ - return getParam(i)->name(); -} - -///////////////////////////////////////////////// - -const String& AsyncWebServerRequest::pathArg(size_t i) const -{ - auto param = _pathParams.nth(i); - - return (param ? **param : SharedEmptyString); -} - -///////////////////////////////////////////////// - -const String& AsyncWebServerRequest::header(const char* name) const -{ - AsyncWebHeader* h = getHeader(String(name)); - - return (h ? h->value() : SharedEmptyString); -} - -///////////////////////////////////////////////// - -const String& AsyncWebServerRequest::header(const __FlashStringHelper * data) const -{ - PGM_P p = reinterpret_cast(data); - size_t n = strlen_P(p); - char * name = (char*) malloc(n + 1); - - if (name) - { - strcpy_P(name, p); - const String & result = header( (const char *)name ); - free(name); - - return result; - } - else - { - return SharedEmptyString; - } -}; -///////////////////////////////////////////////// - -const String& AsyncWebServerRequest::header(size_t i) const -{ - AsyncWebHeader* h = getHeader(i); - - return (h ? h->value() : SharedEmptyString); -} - -///////////////////////////////////////////////// - -const String& AsyncWebServerRequest::headerName(size_t i) const -{ - AsyncWebHeader* h = getHeader(i); - - return (h ? h->name() : SharedEmptyString); -} - -///////////////////////////////////////////////// - -String AsyncWebServerRequest::urlDecode(const String& text) const -{ - char temp[] = "0x00"; - unsigned int len = text.length(); - unsigned int i = 0; - String decoded = String(); - decoded.reserve(len); // Allocate the string internal buffer - never longer from source text - - while (i < len) - { - char decodedChar; - char encodedChar = text.charAt(i++); - - if ((encodedChar == '%') && (i + 1 < len)) - { - temp[2] = text.charAt(i++); - temp[3] = text.charAt(i++); - decodedChar = strtol(temp, NULL, 16); - } - else if (encodedChar == '+') - { - decodedChar = ' '; - } - else - { - decodedChar = encodedChar; // normal ascii char - } - - decoded.concat(decodedChar); - } - - return decoded; -} - -///////////////////////////////////////////////// - -const char * AsyncWebServerRequest::methodToString() const -{ - if (_method == HTTP_ANY) - return "ANY"; - else if (_method & HTTP_GET) - return "GET"; - else if (_method & HTTP_POST) - return "POST"; - else if (_method & HTTP_DELETE) - return "DELETE"; - else if (_method & HTTP_PUT) - return "PUT"; - else if (_method & HTTP_PATCH) - return "PATCH"; - else if (_method & HTTP_HEAD) - return "HEAD"; - else if (_method & HTTP_OPTIONS) - return "OPTIONS"; - - return "UNKNOWN"; -} - -///////////////////////////////////////////////// - -const char *AsyncWebServerRequest::requestedConnTypeToString() const -{ - switch (_reqconntype) - { - case RCT_NOT_USED: - return "RCT_NOT_USED"; - - case RCT_DEFAULT: - return "RCT_DEFAULT"; - - case RCT_HTTP: - return "RCT_HTTP"; - - case RCT_WS: - return "RCT_WS"; - - case RCT_EVENT: - return "RCT_EVENT"; - - default: - return "ERROR"; - } -} - -///////////////////////////////////////////////// - -bool AsyncWebServerRequest::isExpectedRequestedConnType(RequestedConnectionType erct1, RequestedConnectionType erct2, - RequestedConnectionType erct3) -{ - bool res = false; - - if ((erct1 != RCT_NOT_USED) && (erct1 == _reqconntype)) - res = true; - - if ((erct2 != RCT_NOT_USED) && (erct2 == _reqconntype)) - res = true; - - if ((erct3 != RCT_NOT_USED) && (erct3 == _reqconntype)) - res = true; - - return res; -} - -///////////////////////////////////////////////// diff --git a/lib/AsyncWebServer_ESP32_W5500/src/WebResponseImpl.h b/lib/AsyncWebServer_ESP32_W5500/src/WebResponseImpl.h deleted file mode 100644 index 2e6c7e7..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/WebResponseImpl.h +++ /dev/null @@ -1,278 +0,0 @@ -/**************************************************************************************************************************** - WebResponseImpl.h - Dead simple Ethernet AsyncWebServer. - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - - Original author: Hristo Gochkov - - Copyright (c) 2016 Hristo Gochkov. All rights reserved. - - This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License along with this library; - if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Version: 1.6.4 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2 - 1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples - 1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error - *****************************************************************************************************************************/ - -#ifndef ASYNCWEBSERVERRESPONSEIMPL_H_ -#define ASYNCWEBSERVERRESPONSEIMPL_H_ - -#ifdef Arduino_h - // arduino is not compatible with std::vector - #undef min - #undef max -#endif - -#include - -// It is possible to restore these defines, but one can use _min and _max instead. Or std::min, std::max. - -///////////////////////////////////////////////// - -class AsyncBasicResponse: public AsyncWebServerResponse -{ - private: - String _content; - - char *_contentCstr; // RSMOD - String _partialHeader; - - public: - AsyncBasicResponse(int code, const String& contentType = String(), const String& content = String()); - - AsyncBasicResponse(int code, const String& contentType, const char *content = nullptr); // RSMOD - - void _respond(AsyncWebServerRequest *request); - size_t _ack(AsyncWebServerRequest *request, size_t len, uint32_t time); - - ///////////////////////////////////////////////// - - inline bool _sourceValid() const - { - return true; - } - - ///////////////////////////////////////////////// -}; - -///////////////////////////////////////////////// - -class AsyncAbstractResponse: public AsyncWebServerResponse -{ - private: - String _head; - // Data is inserted into cache at begin(). - // This is inefficient with vector, but if we use some other container, - // we won't be able to access it as contiguous array of bytes when reading from it, - // so by gaining performance in one place, we'll lose it in another. - std::vector _cache; - size_t _readDataFromCacheOrContent(uint8_t* data, const size_t len); - size_t _fillBufferAndProcessTemplates(uint8_t* buf, size_t maxLen); - - protected: - AwsTemplateProcessor _callback; - - public: - AsyncAbstractResponse(AwsTemplateProcessor callback = nullptr); - void _respond(AsyncWebServerRequest *request); - size_t _ack(AsyncWebServerRequest *request, size_t len, uint32_t time); - - ///////////////////////////////////////////////// - - inline bool _sourceValid() const - { - return false; - } - - ///////////////////////////////////////////////// - - virtual size_t _fillBuffer(uint8_t *buf __attribute__((unused)), size_t maxLen __attribute__((unused))) - { - return 0; - } - - ///////////////////////////////////////////////// -}; - -///////////////////////////////////////////////// - -#ifndef TEMPLATE_PLACEHOLDER - #define TEMPLATE_PLACEHOLDER '%' -#endif - -#define TEMPLATE_PARAM_NAME_LENGTH 32 - -///////////////////////////////////////////////// - -class AsyncFileResponse: public AsyncAbstractResponse -{ - using File = fs::File; - using FS = fs::FS; - - private: - File _content; - String _path; - void _setContentType(const String& path); - - public: - AsyncFileResponse(FS &fs, const String& path, const String& contentType = String(), bool download = false, - AwsTemplateProcessor callback = nullptr); - AsyncFileResponse(File content, const String& path, const String& contentType = String(), bool download = false, - AwsTemplateProcessor callback = nullptr); - - ~AsyncFileResponse(); - - ///////////////////////////////////////////////// - - inline bool _sourceValid() const - { - return !!(_content); - } - - ///////////////////////////////////////////////// - - virtual size_t _fillBuffer(uint8_t *buf, size_t maxLen) override; -}; - -///////////////////////////////////////////////// - -class AsyncStreamResponse: public AsyncAbstractResponse -{ - private: - Stream *_content; - - public: - AsyncStreamResponse(Stream &stream, const String& contentType, size_t len, AwsTemplateProcessor callback = nullptr); - - ///////////////////////////////////////////////// - - inline bool _sourceValid() const - { - return !!(_content); - } - - ///////////////////////////////////////////////// - - virtual size_t _fillBuffer(uint8_t *buf, size_t maxLen) override; -}; - -///////////////////////////////////////////////// - -class AsyncCallbackResponse: public AsyncAbstractResponse -{ - private: - AwsResponseFiller _content; - size_t _filledLength; - - public: - AsyncCallbackResponse(const String& contentType, size_t len, AwsResponseFiller callback, - AwsTemplateProcessor templateCallback = nullptr); - - ///////////////////////////////////////////////// - - inline bool _sourceValid() const - { - return !!(_content); - } - - ///////////////////////////////////////////////// - - virtual size_t _fillBuffer(uint8_t *buf, size_t maxLen) override; -}; - -///////////////////////////////////////////////// - -class AsyncChunkedResponse: public AsyncAbstractResponse -{ - private: - AwsResponseFiller _content; - size_t _filledLength; - - public: - AsyncChunkedResponse(const String& contentType, AwsResponseFiller callback, - AwsTemplateProcessor templateCallback = nullptr); - - ///////////////////////////////////////////////// - - inline bool _sourceValid() const - { - return !!(_content); - } - - ///////////////////////////////////////////////// - - virtual size_t _fillBuffer(uint8_t *buf, size_t maxLen) override; -}; - -///////////////////////////////////////////////// - -class AsyncProgmemResponse: public AsyncAbstractResponse -{ - private: - const uint8_t * _content; - size_t _readLength; - - public: - AsyncProgmemResponse(int code, const String& contentType, const uint8_t * content, size_t len, - AwsTemplateProcessor callback = nullptr); - - ///////////////////////////////////////////////// - - inline bool _sourceValid() const - { - return true; - } - - ///////////////////////////////////////////////// - - virtual size_t _fillBuffer(uint8_t *buf, size_t maxLen) override; -}; - -///////////////////////////////////////////////// - -class cbuf; - -///////////////////////////////////////////////// - -class AsyncResponseStream: public AsyncAbstractResponse, public Print -{ - private: - cbuf *_content; - - public: - AsyncResponseStream(const String& contentType, size_t bufferSize); - ~AsyncResponseStream(); - - ///////////////////////////////////////////////// - - inline bool _sourceValid() const - { - return (_state < RESPONSE_END); - } - - ///////////////////////////////////////////////// - - virtual size_t _fillBuffer(uint8_t *buf, size_t maxLen) override; - size_t write(const uint8_t *data, size_t len); - size_t write(uint8_t data); - using Print::write; -}; - -#endif /* ASYNCWEBSERVERRESPONSEIMPL_H_ */ diff --git a/lib/AsyncWebServer_ESP32_W5500/src/WebResponses.cpp b/lib/AsyncWebServer_ESP32_W5500/src/WebResponses.cpp deleted file mode 100644 index 11c78c4..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/WebResponses.cpp +++ /dev/null @@ -1,1300 +0,0 @@ -/**************************************************************************************************************************** - WebResponses.cpp - Dead simple Ethernet AsyncWebServer. - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - - Original author: Hristo Gochkov - - Copyright (c) 2016 Hristo Gochkov. All rights reserved. - - This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License along with this library; - if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Version: 1.6.4 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2 - 1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples - 1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error - *****************************************************************************************************************************/ - -#include "AsyncWebServer_ESP32_W5500.h" - -#include "WebResponseImpl.h" -#include "cbuf.h" - -///////////////////////////////////////////////// - -void* memchr(void* ptr, int ch, size_t count) -{ - unsigned char* p = static_cast(ptr); - - while (count--) - if (*p++ == static_cast(ch)) - return --p; - - return nullptr; -} - -///////////////////////////////////////////////// - -/* - Abstract Response - * */ -const char* AsyncWebServerResponse::_responseCodeToString(int code) -{ - switch (code) - { - case 100: - return "Continue"; - - case 101: - return "Switching Protocols"; - - case 200: - return "OK"; - - case 201: - return "Created"; - - case 202: - return "Accepted"; - - case 203: - return "Non-Authoritative Information"; - - case 204: - return "No Content"; - - case 205: - return "Reset Content"; - - case 206: - return "Partial Content"; - - case 300: - return "Multiple Choices"; - - case 301: - return "Moved Permanently"; - - case 302: - return "Found"; - - case 303: - return "See Other"; - - case 304: - return "Not Modified"; - - case 305: - return "Use Proxy"; - - case 307: - return "Temporary Redirect"; - - case 400: - return "Bad Request"; - - case 401: - return "Unauthorized"; - - case 402: - return "Payment Required"; - - case 403: - return "Forbidden"; - - case 404: - return "Not Found"; - - case 405: - return "Method Not Allowed"; - - case 406: - return "Not Acceptable"; - - case 407: - return "Proxy Authentication Required"; - - case 408: - return "Request Time-out"; - - case 409: - return "Conflict"; - - case 410: - return "Gone"; - - case 411: - return "Length Required"; - - case 412: - return "Precondition Failed"; - - case 413: - return "Request Entity Too Large"; - - case 414: - return "Request-URI Too Large"; - - case 415: - return "Unsupported Media Type"; - - case 416: - return "Requested range not satisfiable"; - - case 417: - return "Expectation Failed"; - - case 500: - return "Internal Server Error"; - - case 501: - return "Not Implemented"; - - case 502: - return "Bad Gateway"; - - case 503: - return "Service Unavailable"; - - case 504: - return "Gateway Time-out"; - - case 505: - return "HTTP Version not supported"; - - default: - return ""; - } -} - -///////////////////////////////////////////////// - -AsyncWebServerResponse::AsyncWebServerResponse() - : _code(0) - , _headers(LinkedList([](AsyncWebHeader * h) -{ - delete h; -})) -, _contentType() -, _contentLength(0) -, _sendContentLength(true) -, _chunked(false) -, _headLength(0) -, _sentLength(0) -, _ackedLength(0) -, _writtenLength(0) -, _state(RESPONSE_SETUP) -{ - for (auto header : DefaultHeaders::Instance()) - { - _headers.add(new AsyncWebHeader(header->name(), header->value())); - } -} - -///////////////////////////////////////////////// - -AsyncWebServerResponse::~AsyncWebServerResponse() -{ - _headers.free(); -} - -///////////////////////////////////////////////// - -void AsyncWebServerResponse::setCode(int code) -{ - if (_state == RESPONSE_SETUP) - _code = code; -} - -void AsyncWebServerResponse::setContentLength(size_t len) -{ - if (_state == RESPONSE_SETUP) - _contentLength = len; -} - -///////////////////////////////////////////////// - -void AsyncWebServerResponse::setContentType(const String& type) -{ - if (_state == RESPONSE_SETUP) - _contentType = type; -} - -///////////////////////////////////////////////// - -void AsyncWebServerResponse::addHeader(const String& name, const String& value) -{ - _headers.add(new AsyncWebHeader(name, value)); -} - -///////////////////////////////////////////////// - -String AsyncWebServerResponse::_assembleHead(uint8_t version) -{ - if (version) - { - addHeader("Accept-Ranges", "none"); - - if (_chunked) - addHeader("Transfer-Encoding", "chunked"); - } - - String out = String(); - int bufSize = 300; - char buf[bufSize]; - - snprintf(buf, bufSize, "HTTP/1.%d %d %s\r\n", version, _code, _responseCodeToString(_code)); - out.concat(buf); - - if (_sendContentLength) - { - snprintf(buf, bufSize, "Content-Length: %d\r\n", _contentLength); - out.concat(buf); - } - - if (_contentType.length()) - { - snprintf(buf, bufSize, "Content-Type: %s\r\n", _contentType.c_str()); - out.concat(buf); - } - - for (const auto& header : _headers) - { - snprintf(buf, bufSize, "%s: %s\r\n", header->name().c_str(), header->value().c_str()); - out.concat(buf); - } - - _headers.free(); - - out.concat("\r\n"); - _headLength = out.length(); - - return out; -} - -///////////////////////////////////////////////// - -bool AsyncWebServerResponse::_started() const -{ - return _state > RESPONSE_SETUP; -} - -///////////////////////////////////////////////// - -bool AsyncWebServerResponse::_finished() const -{ - return _state > RESPONSE_WAIT_ACK; -} - -///////////////////////////////////////////////// - -bool AsyncWebServerResponse::_failed() const -{ - return _state == RESPONSE_FAILED; -} - -///////////////////////////////////////////////// - -bool AsyncWebServerResponse::_sourceValid() const -{ - return false; -} - -///////////////////////////////////////////////// - -void AsyncWebServerResponse::_respond(AsyncWebServerRequest *request) -{ - _state = RESPONSE_END; - request->client()->close(); -} - -///////////////////////////////////////////////// - -size_t AsyncWebServerResponse::_ack(AsyncWebServerRequest *request, size_t len, uint32_t time) -{ - ESP32_W5500_AWS_UNUSED(request); - ESP32_W5500_AWS_UNUSED(len); - ESP32_W5500_AWS_UNUSED(time); - - return 0; -} - -//RSMOD/////////////////////////////////////////////// - -/* - String/Code Response - * */ -AsyncBasicResponse::AsyncBasicResponse(int code, const String& contentType, const char *content) -{ - _code = code; - _content = String(""); - _contentCstr = (char *)content; // RSMOD - _contentType = contentType; - _partialHeader = String(); - - int iLen; - - if ((iLen = strlen(_contentCstr))) - { - _contentLength = iLen; - - if (!_contentType.length()) - _contentType = "text/plain"; - } - - addHeader("Connection", "close"); -} - -///////////////////////////////////////////////// - -/* - String/Code Response - * */ -AsyncBasicResponse::AsyncBasicResponse(int code, const String& contentType, const String& content) -{ - _code = code; - _content = content; - - _contentCstr = nullptr; // RSMOD - - _contentType = contentType; - _partialHeader = String(); - - if (_content.length()) - { - _contentLength = _content.length(); - - if (!_contentType.length()) - _contentType = "text/plain"; - } - - addHeader("Connection", "close"); -} - -///////////////////////////////////////////////// - -void AsyncBasicResponse::_respond(AsyncWebServerRequest *request) -{ - _state = RESPONSE_HEADERS; - String out = _assembleHead(request->version()); - size_t outLen = out.length(); - size_t space = request->client()->space(); - - AWS_LOGDEBUG3("AsyncBasicResponse::_respond : Pre_respond, _contentLength =", _contentLength, ", out =", out ); - AWS_LOGDEBUG3("outLen =", outLen, ", _contentCstr =", _contentCstr); - - if (!_contentLength && space >= outLen) - { - AWS_LOGDEBUG("Step 1"); - - _writtenLength += request->client()->write(out.c_str(), outLen); - _state = RESPONSE_WAIT_ACK; - } - else if (_contentLength && space >= outLen + _contentLength) - { - AWS_LOGDEBUG("Step 2"); - - if (_contentCstr) - { - _content = String( - _contentCstr); // short _contentCstr - so just send as Arduino String - not much of a penalty - fall into below - } - - out += _content; - outLen += _contentLength; - _writtenLength += request->client()->write(out.c_str(), outLen); - - _state = RESPONSE_WAIT_ACK; - } - else if (space && space < outLen) - { - String partial = out.substring(0, space); - - AWS_LOGDEBUG("Step 3"); - - if (_contentCstr) - { - _partialHeader = out.substring(space); - } - else - { - _content = out.substring(space) + _content; - _contentLength += outLen - space; - } - - AWS_LOGDEBUG1("partial =", partial); - - _writtenLength += request->client()->write(partial.c_str(), partial.length()); - - _state = RESPONSE_CONTENT; - } - else if (space > outLen && space < (outLen + _contentLength)) - { - size_t shift = space - outLen; - - AWS_LOGDEBUG("Step 4"); - - outLen += shift; - _sentLength += shift; - - if (_contentCstr) - { - char *s = (char *)malloc(shift + 1); - - if (s != nullptr) - { - strncpy(s, _contentCstr, shift); - s[shift] = '\0'; - out += String(s); - _contentCstr += shift; - - free(s); - } - else - { - AWS_LOGERROR("AsyncBasicResponse::_respond: Out of heap"); - - return; - } - } - else - { - out += _content.substring(0, shift); - _content = _content.substring(shift); - } - - AWS_LOGDEBUG1("out =", out); - - _writtenLength += request->client()->write(out.c_str(), outLen); - _state = RESPONSE_CONTENT; - } - else - { - AWS_LOGDEBUG("Step 5"); - - if (_contentCstr) - { - _partialHeader = out; - } - else - { - _content = out + _content; - _contentLength += outLen; - } - - _state = RESPONSE_CONTENT; - } - - AWS_LOGDEBUG3("AsyncBasicResponse::_respond : Post_respond, _contentLength =", _contentLength, ", out =", out ); - AWS_LOGDEBUG3("outLen =", outLen, ", _contentCstr =", _contentCstr); -} - -///////////////////////////////////////////////// - -size_t AsyncBasicResponse::_ack(AsyncWebServerRequest *request, size_t len, uint32_t time) -{ - ESP32_W5500_AWS_UNUSED(time); - - AWS_LOGDEBUG1("AsyncBasicResponse::_ack : Pre_ack, _contentLength =", _contentLength); - - _ackedLength += len; - - if (_state == RESPONSE_CONTENT) - { - String out; - size_t available = _contentLength - _sentLength; - size_t space = request->client()->space(); - - if (_partialHeader.length() > 0) - { - if (_partialHeader.length() > space) - { - // Header longer than space - send a piece of it, and make the _partialHeader = to what remains - String _subHeader; - String tmpString; - - _subHeader = _partialHeader.substring(0, space); - tmpString = _partialHeader.substring(space); - _partialHeader = tmpString; - - _writtenLength += request->client()->write(_subHeader.c_str(), space); - - return (_partialHeader.length()); - } - else - { - // _partialHeader is <= space length - therefore send the whole thing, and make the remaining length = to the _contrentLength - _writtenLength += request->client()->write(_partialHeader.c_str(), _partialHeader.length()); - - _partialHeader = String(); - - return (_contentLength); - } - } - - // if we are here - there is no _partialHJeader to send - - AWS_LOGDEBUG3("AsyncBasicResponse::_ack : available =", available, ", space =", space ); - - //we can fit in this packet - if (space > available) - { - AWS_LOGDEBUG1("AsyncBasicResponse::_ack : Pre_ack, _contentLength =", _contentLength); - - if (_contentCstr) - { - AWS_LOGDEBUG1("In space>available : output =", _contentCstr); - - _writtenLength += request->client()->write(_contentCstr, available); - //_contentCstr[0] = '\0'; - } - else - { - _writtenLength += request->client()->write(_content.c_str(), available); - _content = String(); - } - - _state = RESPONSE_WAIT_ACK; - - return available; - } - - //send some data, the rest on ack - if (_contentCstr) - { - char *s = (char *)malloc(space + 1); - - if (s != nullptr) - { - strncpy(s, _contentCstr, space); - s[space] = '\0'; - out = String(s); - _contentCstr += space; - - free(s); - } - else - { - AWS_LOGERROR("AsyncBasicResponse::_ack: Out of heap"); - - return 0; - } - } - else - { - out = _content.substring(0, space); - _content = _content.substring(space); - } - - _sentLength += space; - - AWS_LOGDEBUG1("In space>available : output =", out); - - _writtenLength += request->client()->write(out.c_str(), space); - - return space; - } - else if (_state == RESPONSE_WAIT_ACK) - { - if (_ackedLength >= _writtenLength) - { - _state = RESPONSE_END; - } - } - - AWS_LOGDEBUG3("AsyncBasicResponse::_ack : Post_ack, _contentLength =", _contentLength, ", _contentCstr =", - _contentCstr); - - return 0; -} - -///////////////////////////////////////////////// -///////////////////////////////////////////////// - -/* - Abstract Response - * */ - -AsyncAbstractResponse::AsyncAbstractResponse(AwsTemplateProcessor callback): _callback(callback) -{ - // In case of template processing, we're unable to determine real response size - if (callback) - { - _contentLength = 0; - _sendContentLength = false; - _chunked = true; - } -} - -///////////////////////////////////////////////// - -void AsyncAbstractResponse::_respond(AsyncWebServerRequest *request) -{ - addHeader("Connection", "close"); - _head = _assembleHead(request->version()); - _state = RESPONSE_HEADERS; - _ack(request, 0, 0); -} - -///////////////////////////////////////////////// - -size_t AsyncAbstractResponse::_ack(AsyncWebServerRequest *request, size_t len, uint32_t time) -{ - ESP32_W5500_AWS_UNUSED(time); - - if (!_sourceValid()) - { - _state = RESPONSE_FAILED; - request->client()->close(); - return 0; - } - - _ackedLength += len; - size_t space = request->client()->space(); - - size_t headLen = _head.length(); - - if (_state == RESPONSE_HEADERS) - { - if (space >= headLen) - { - _state = RESPONSE_CONTENT; - space -= headLen; - } - else - { - String out = _head.substring(0, space); - _head = _head.substring(space); - _writtenLength += request->client()->write(out.c_str(), out.length()); - - return out.length(); - } - } - - if (_state == RESPONSE_CONTENT) - { - size_t outLen; - - if (_chunked) - { - if (space <= 8) - { - return 0; - } - - outLen = space; - } - else if (!_sendContentLength) - { - outLen = space; - } - else - { - outLen = ((_contentLength - _sentLength) > space) ? space : (_contentLength - _sentLength); - } - - uint8_t *buf = (uint8_t *)malloc(outLen + headLen); - - if (!buf) - { - AWS_LOGERROR1(F("[AsyncAbstractResponse::_ack] _ack malloc failed, size ="), outLen + headLen); - - return 0; - } - - if (headLen) - { - memcpy(buf, _head.c_str(), _head.length()); - } - - size_t readLen = 0; - - if (_chunked) - { - // HTTP 1.1 allows leading zeros in chunk length. Or spaces may be added. - // See RFC2616 sections 2, 3.6.1. - readLen = _fillBufferAndProcessTemplates(buf + headLen + 6, outLen - 8); - - if (readLen == RESPONSE_TRY_AGAIN) - { - free(buf); - return 0; - } - - outLen = sprintf((char*)buf + headLen, "%x", readLen) + headLen; - - while (outLen < headLen + 4) - buf[outLen++] = ' '; - - buf[outLen++] = '\r'; - buf[outLen++] = '\n'; - outLen += readLen; - buf[outLen++] = '\r'; - buf[outLen++] = '\n'; - } - else - { - readLen = _fillBufferAndProcessTemplates(buf + headLen, outLen); - - if (readLen == RESPONSE_TRY_AGAIN) - { - free(buf); - return 0; - } - - outLen = readLen + headLen; - } - - if (headLen) - { - _head = String(); - } - - if (outLen) - { - _writtenLength += request->client()->write((const char*)buf, outLen); - } - - if (_chunked) - { - _sentLength += readLen; - } - else - { - _sentLength += outLen - headLen; - } - - free(buf); - - if ((_chunked && readLen == 0) || (!_sendContentLength && outLen == 0) || (!_chunked && _sentLength == _contentLength)) - { - _state = RESPONSE_WAIT_ACK; - } - - return outLen; - - } - else if (_state == RESPONSE_WAIT_ACK) - { - if (!_sendContentLength || _ackedLength >= _writtenLength) - { - _state = RESPONSE_END; - - if (!_chunked && !_sendContentLength) - request->client()->close(true); - } - } - - return 0; -} - -///////////////////////////////////////////////// - -size_t AsyncAbstractResponse::_readDataFromCacheOrContent(uint8_t* data, const size_t len) -{ - // If we have something in cache, copy it to buffer - const size_t readFromCache = std::min(len, _cache.size()); - - if (readFromCache) - { - memcpy(data, _cache.data(), readFromCache); - _cache.erase(_cache.begin(), _cache.begin() + readFromCache); - } - - // If we need to read more... - const size_t needFromFile = len - readFromCache; - const size_t readFromContent = _fillBuffer(data + readFromCache, needFromFile); - - return readFromCache + readFromContent; -} - -///////////////////////////////////////////////// - -size_t AsyncAbstractResponse::_fillBufferAndProcessTemplates(uint8_t* data, size_t len) -{ - if (!_callback) - return _fillBuffer(data, len); - - const size_t originalLen = len; - len = _readDataFromCacheOrContent(data, len); - - // Now we've read 'len' bytes, either from cache or from file - // Search for template placeholders - uint8_t* pTemplateStart = data; - - while ((pTemplateStart < &data[len]) - && (pTemplateStart = (uint8_t*)memchr(pTemplateStart, TEMPLATE_PLACEHOLDER, &data[len - 1] - pTemplateStart + 1))) - { - // data[0] ... data[len - 1] - uint8_t* pTemplateEnd = (pTemplateStart < &data[len - 1]) ? (uint8_t*)memchr(pTemplateStart + 1, TEMPLATE_PLACEHOLDER, - &data[len - 1] - pTemplateStart) : nullptr; - // temporary buffer to hold parameter name - uint8_t buf[TEMPLATE_PARAM_NAME_LENGTH + 1]; - String paramName; - - // If closing placeholder is found: - if (pTemplateEnd) - { - // prepare argument to callback - const size_t paramNameLength = std::min(sizeof(buf) - 1, (unsigned int)(pTemplateEnd - pTemplateStart - 1)); - - if (paramNameLength) - { - memcpy(buf, pTemplateStart + 1, paramNameLength); - buf[paramNameLength] = 0; - paramName = String(reinterpret_cast(buf)); - } - else - { - // double percent sign encountered, this is single percent sign escaped. - // remove the 2nd percent sign - memmove(pTemplateEnd, pTemplateEnd + 1, &data[len] - pTemplateEnd - 1); - len += _readDataFromCacheOrContent(&data[len - 1], 1) - 1; - ++pTemplateStart; - } - } - else if (&data[len - 1] - pTemplateStart + 1 < TEMPLATE_PARAM_NAME_LENGTH + 2) - { - // closing placeholder not found, check if it's in the remaining file data - memcpy(buf, pTemplateStart + 1, &data[len - 1] - pTemplateStart); - - const size_t readFromCacheOrContent = _readDataFromCacheOrContent(buf + (&data[len - 1] - pTemplateStart), - TEMPLATE_PARAM_NAME_LENGTH + 2 - (&data[len - 1] - pTemplateStart + 1)); - - if (readFromCacheOrContent) - { - pTemplateEnd = (uint8_t*)memchr(buf + (&data[len - 1] - pTemplateStart), TEMPLATE_PLACEHOLDER, readFromCacheOrContent); - - if (pTemplateEnd) - { - // prepare argument to callback - *pTemplateEnd = 0; - paramName = String(reinterpret_cast(buf)); - - // Copy remaining read-ahead data into cache - _cache.insert(_cache.begin(), pTemplateEnd + 1, buf + (&data[len - 1] - pTemplateStart) + readFromCacheOrContent); - pTemplateEnd = &data[len - 1]; - } - else // closing placeholder not found in file data, store found percent symbol as is and advance to the next position - { - // but first, store read file data in cache - _cache.insert(_cache.begin(), buf + (&data[len - 1] - pTemplateStart), - buf + (&data[len - 1] - pTemplateStart) + readFromCacheOrContent); - ++pTemplateStart; - } - } - else // closing placeholder not found in content data, store found percent symbol as is and advance to the next position - ++pTemplateStart; - } - else // closing placeholder not found in content data, store found percent symbol as is and advance to the next position - ++pTemplateStart; - - if (paramName.length()) - { - // call callback and replace with result. - // Everything in range [pTemplateStart, pTemplateEnd] can be safely replaced with parameter value. - // Data after pTemplateEnd may need to be moved. - // The first byte of data after placeholder is located at pTemplateEnd + 1. - // It should be located at pTemplateStart + numBytesCopied (to begin right after inserted parameter value). - const String paramValue(_callback(paramName)); - const char* pvstr = paramValue.c_str(); - const unsigned int pvlen = paramValue.length(); - const size_t numBytesCopied = std::min(pvlen, static_cast(&data[originalLen - 1] - pTemplateStart + 1)); - - // make room for param value - // 1. move extra data to cache if parameter value is longer than placeholder AND if there is no room to store - if ((pTemplateEnd + 1 < pTemplateStart + numBytesCopied) - && (originalLen - (pTemplateStart + numBytesCopied - pTemplateEnd - 1) < len)) - { - _cache.insert(_cache.begin(), &data[originalLen - (pTemplateStart + numBytesCopied - pTemplateEnd - 1)], &data[len]); - //2. parameter value is longer than placeholder text, push the data after placeholder which not saved into cache further to the end - memmove(pTemplateStart + numBytesCopied, pTemplateEnd + 1, &data[originalLen] - pTemplateStart - numBytesCopied); - len = originalLen; // fix issue with truncated data, not sure if it has any side effects - } - else if (pTemplateEnd + 1 != pTemplateStart + numBytesCopied) - //2. Either parameter value is shorter than placeholder text OR there is enough free space in buffer to fit. - // Move the entire data after the placeholder - memmove(pTemplateStart + numBytesCopied, pTemplateEnd + 1, &data[len] - pTemplateEnd - 1); - - // 3. replace placeholder with actual value - memcpy(pTemplateStart, pvstr, numBytesCopied); - - // If result is longer than buffer, copy the remainder into cache (this could happen only if placeholder text itself did not fit entirely in buffer) - if (numBytesCopied < pvlen) - { - _cache.insert(_cache.begin(), pvstr + numBytesCopied, pvstr + pvlen); - } - else if (pTemplateStart + numBytesCopied < pTemplateEnd + 1) - { - // result is copied fully; if result is shorter than placeholder text... - // there is some free room, fill it from cache - const size_t roomFreed = pTemplateEnd + 1 - pTemplateStart - numBytesCopied; - const size_t totalFreeRoom = originalLen - len + roomFreed; - len += _readDataFromCacheOrContent(&data[len - roomFreed], totalFreeRoom) - roomFreed; - } - else - { - // result is copied fully; it is longer than placeholder text - const size_t roomTaken = pTemplateStart + numBytesCopied - pTemplateEnd - 1; - len = std::min(len + roomTaken, originalLen); - } - } - } // while(pTemplateStart) - - return len; -} - -///////////////////////////////////////////////// -///////////////////////////////////////////////// - -/* - File Response - * */ - -AsyncFileResponse::~AsyncFileResponse() -{ - if (_content) - _content.close(); -} - -///////////////////////////////////////////////// - -void AsyncFileResponse::_setContentType(const String& path) -{ - if (path.endsWith(".html")) - _contentType = "text/html"; - else if (path.endsWith(".htm")) - _contentType = "text/html"; - else if (path.endsWith(".css")) - _contentType = "text/css"; - else if (path.endsWith(".json")) - _contentType = "application/json"; - else if (path.endsWith(".js")) - _contentType = "application/javascript"; - else if (path.endsWith(".png")) - _contentType = "image/png"; - else if (path.endsWith(".gif")) - _contentType = "image/gif"; - else if (path.endsWith(".jpg")) - _contentType = "image/jpeg"; - else if (path.endsWith(".ico")) - _contentType = "image/x-icon"; - else if (path.endsWith(".svg")) - _contentType = "image/svg+xml"; - else if (path.endsWith(".eot")) - _contentType = "font/eot"; - else if (path.endsWith(".woff")) - _contentType = "font/woff"; - else if (path.endsWith(".woff2")) - _contentType = "font/woff2"; - else if (path.endsWith(".ttf")) - _contentType = "font/ttf"; - else if (path.endsWith(".xml")) - _contentType = "text/xml"; - else if (path.endsWith(".pdf")) - _contentType = "application/pdf"; - else if (path.endsWith(".zip")) - _contentType = "application/zip"; - else if (path.endsWith(".gz")) - _contentType = "application/x-gzip"; - else - _contentType = "text/plain"; -} - -///////////////////////////////////////////////// - -AsyncFileResponse::AsyncFileResponse(FS &fs, const String& path, const String& contentType, bool download, - AwsTemplateProcessor callback): AsyncAbstractResponse(callback) -{ - _code = 200; - _path = path; - - if (!download && !fs.exists(_path) && fs.exists(_path + ".gz")) - { - _path = _path + ".gz"; - addHeader("Content-Encoding", "gzip"); - _callback = nullptr; // Unable to process zipped templates - _sendContentLength = true; - _chunked = false; - } - - _content = fs.open(_path, "r"); - _contentLength = _content.size(); - - if (contentType == "") - _setContentType(path); - else - _contentType = contentType; - - int filenameStart = path.lastIndexOf('/') + 1; - char buf[26 + path.length() - filenameStart]; - char* filename = (char*)path.c_str() + filenameStart; - - if (download) - { - // set filename and force download - snprintf(buf, sizeof (buf), "attachment; filename=\"%s\"", filename); - } - else - { - // set filename and force rendering - snprintf(buf, sizeof (buf), "inline; filename=\"%s\"", filename); - } - - addHeader("Content-Disposition", buf); -} - -///////////////////////////////////////////////// - -AsyncFileResponse::AsyncFileResponse(File content, const String& path, const String& contentType, bool download, - AwsTemplateProcessor callback): AsyncAbstractResponse(callback) -{ - _code = 200; - _path = path; - - if (!download && String(content.name()).endsWith(".gz") && !path.endsWith(".gz")) - { - addHeader("Content-Encoding", "gzip"); - _callback = nullptr; // Unable to process gzipped templates - _sendContentLength = true; - _chunked = false; - } - - _content = content; - _contentLength = _content.size(); - - if (contentType == "") - _setContentType(path); - else - _contentType = contentType; - - int filenameStart = path.lastIndexOf('/') + 1; - char buf[26 + path.length() - filenameStart]; - char* filename = (char*)path.c_str() + filenameStart; - - if (download) - { - snprintf(buf, sizeof (buf), "attachment; filename=\"%s\"", filename); - } - else - { - snprintf(buf, sizeof (buf), "inline; filename=\"%s\"", filename); - } - - addHeader("Content-Disposition", buf); -} - -///////////////////////////////////////////////// - -size_t AsyncFileResponse::_fillBuffer(uint8_t *data, size_t len) -{ - return _content.read(data, len); -} - -///////////////////////////////////////////////// -///////////////////////////////////////////////// - -/* - Stream Response - * */ - -AsyncStreamResponse::AsyncStreamResponse(Stream &stream, const String& contentType, size_t len, - AwsTemplateProcessor callback): AsyncAbstractResponse(callback) -{ - _code = 200; - _content = &stream; - _contentLength = len; - _contentType = contentType; -} - -///////////////////////////////////////////////// - -size_t AsyncStreamResponse::_fillBuffer(uint8_t *data, size_t len) -{ - size_t available = _content->available(); - size_t outLen = (available > len) ? len : available; - size_t i; - - for (i = 0; i < outLen; i++) - data[i] = _content->read(); - - return outLen; -} - -///////////////////////////////////////////////// -///////////////////////////////////////////////// - -/* - Callback Response - * */ - -AsyncCallbackResponse::AsyncCallbackResponse(const String& contentType, size_t len, AwsResponseFiller callback, - AwsTemplateProcessor templateCallback): AsyncAbstractResponse(templateCallback) -{ - _code = 200; - _content = callback; - _contentLength = len; - - if (!len) - _sendContentLength = false; - - _contentType = contentType; - _filledLength = 0; -} - -///////////////////////////////////////////////// - -size_t AsyncCallbackResponse::_fillBuffer(uint8_t *data, size_t len) -{ - size_t ret = _content(data, len, _filledLength); - - if (ret != RESPONSE_TRY_AGAIN) - { - _filledLength += ret; - } - - return ret; -} - -///////////////////////////////////////////////// -///////////////////////////////////////////////// - -/* - Chunked Response - * */ - -AsyncChunkedResponse::AsyncChunkedResponse(const String& contentType, AwsResponseFiller callback, - AwsTemplateProcessor processorCallback): AsyncAbstractResponse(processorCallback) -{ - _code = 200; - _content = callback; - _contentLength = 0; - _contentType = contentType; - _sendContentLength = false; - _chunked = true; - _filledLength = 0; -} - -///////////////////////////////////////////////// - -size_t AsyncChunkedResponse::_fillBuffer(uint8_t *data, size_t len) -{ - size_t ret = _content(data, len, _filledLength); - - if (ret != RESPONSE_TRY_AGAIN) - { - _filledLength += ret; - } - - return ret; -} - -///////////////////////////////////////////////// -///////////////////////////////////////////////// - -/* - Progmem Response - * */ - -AsyncProgmemResponse::AsyncProgmemResponse(int code, const String& contentType, const uint8_t * content, size_t len, - AwsTemplateProcessor callback): AsyncAbstractResponse(callback) -{ - _code = code; - _content = content; - _contentType = contentType; - _contentLength = len; - _readLength = 0; -} - -///////////////////////////////////////////////// - -size_t AsyncProgmemResponse::_fillBuffer(uint8_t *data, size_t len) -{ - size_t left = _contentLength - _readLength; - - if (left > len) - { - memcpy_P(data, _content + _readLength, len); - _readLength += len; - return len; - } - - memcpy_P(data, _content + _readLength, left); - _readLength += left; - - return left; -} - -///////////////////////////////////////////////// -///////////////////////////////////////////////// - -/* - Response Stream (You can print/write/printf to it, up to the contentLen bytes) - * */ - -AsyncResponseStream::AsyncResponseStream(const String& contentType, size_t bufferSize) -{ - _code = 200; - _contentLength = 0; - _contentType = contentType; - _content = new cbuf(bufferSize); -} - -///////////////////////////////////////////////// - -AsyncResponseStream::~AsyncResponseStream() -{ - delete _content; -} - -///////////////////////////////////////////////// - -size_t AsyncResponseStream::_fillBuffer(uint8_t *buf, size_t maxLen) -{ - return _content->read((char*)buf, maxLen); -} - -///////////////////////////////////////////////// - -size_t AsyncResponseStream::write(const uint8_t *data, size_t len) -{ - if (_started()) - return 0; - - if (len > _content->room()) - { - size_t needed = len - _content->room(); - _content->resizeAdd(needed); - } - - size_t written = _content->write((const char*)data, len); - _contentLength += written; - - return written; -} - -///////////////////////////////////////////////// - -size_t AsyncResponseStream::write(uint8_t data) -{ - return write(&data, 1); -} - -///////////////////////////////////////////////// - diff --git a/lib/AsyncWebServer_ESP32_W5500/src/WebServer.cpp b/lib/AsyncWebServer_ESP32_W5500/src/WebServer.cpp deleted file mode 100644 index b104ff2..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/WebServer.cpp +++ /dev/null @@ -1,315 +0,0 @@ -/**************************************************************************************************************************** - WebServer.cpp - Dead simple Ethernet AsyncWebServer. - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - - Original author: Hristo Gochkov - - Copyright (c) 2016 Hristo Gochkov. All rights reserved. - - This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License along with this library; - if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - Version: 1.6.4 - - Version Modified By Date Comments - ------- ----------- ---------- ----------- - 1.6.2 K Hoang 30/11/2022 Initial porting for ENC28J60 + ESP32. Sync with AsyncWebServer_WT32_ETH01 v1.6.2 - 1.6.3 K Hoang 05/12/2022 Add Async_WebSocketsServer, MQTT examples - 1.6.4 K Hoang 23/12/2022 Remove unused variable to avoid compiler warning and error - *****************************************************************************************************************************/ - -#include "AsyncWebServer_ESP32_W5500.h" -#include "WebHandlerImpl.h" - -///////////////////////////////////////////////// - -bool ON_STA_FILTER(AsyncWebServerRequest *request) -{ - return ETH.localIP() == request->client()->localIP(); -} - -///////////////////////////////////////////////// - -bool ON_AP_FILTER(AsyncWebServerRequest *request) -{ - return ETH.localIP() != request->client()->localIP(); -} - -///////////////////////////////////////////////// - -AsyncWebServer::AsyncWebServer(uint16_t port) - : _server(port), - _rewrites(LinkedList([](AsyncWebRewrite * r) -{ - delete r; -})), -_handlers(LinkedList([](AsyncWebHandler* h) -{ - delete h; -})) -{ - _catchAllHandler = new AsyncCallbackWebHandler(); - - if (_catchAllHandler == NULL) - return; - - _server.onClient([](void *s, AsyncClient * c) - { - if (c == NULL) - return; - - c->setRxTimeout(3); - AsyncWebServerRequest *r = new AsyncWebServerRequest((AsyncWebServer*)s, c); - - if (r == NULL) - { - c->close(true); - c->free(); - delete c; - } - }, this); -} - -///////////////////////////////////////////////// - -AsyncWebServer::~AsyncWebServer() -{ - reset(); - end(); - - if (_catchAllHandler) - delete _catchAllHandler; -} - -///////////////////////////////////////////////// - -AsyncWebRewrite& AsyncWebServer::addRewrite(AsyncWebRewrite* rewrite) -{ - _rewrites.add(rewrite); - - return *rewrite; -} - -///////////////////////////////////////////////// - -bool AsyncWebServer::removeRewrite(AsyncWebRewrite *rewrite) -{ - return _rewrites.remove(rewrite); -} - -///////////////////////////////////////////////// - -AsyncWebRewrite& AsyncWebServer::rewrite(const char* from, const char* to) -{ - return addRewrite(new AsyncWebRewrite(from, to)); -} - -///////////////////////////////////////////////// - -AsyncWebHandler& AsyncWebServer::addHandler(AsyncWebHandler* handler) -{ - _handlers.add(handler); - - return *handler; -} - -///////////////////////////////////////////////// - -bool AsyncWebServer::removeHandler(AsyncWebHandler *handler) -{ - return _handlers.remove(handler); -} - -///////////////////////////////////////////////// - -void AsyncWebServer::begin() -{ - _server.setNoDelay(true); - _server.begin(); -} - -///////////////////////////////////////////////// - -void AsyncWebServer::end() -{ - _server.end(); -} - -///////////////////////////////////////////////// - -#if ASYNC_TCP_SSL_ENABLED - -void AsyncWebServer::onSslFileRequest(AcSSlFileHandler cb, void* arg) -{ - _server.onSslFileRequest(cb, arg); -} - -///////////////////////////////////////////////// - -void AsyncWebServer::beginSecure(const char *cert, const char *key, const char *password) -{ - _server.beginSecure(cert, key, password); -} - -#endif - -///////////////////////////////////////////////// - -void AsyncWebServer::_handleDisconnect(AsyncWebServerRequest *request) -{ - delete request; -} - -///////////////////////////////////////////////// - -void AsyncWebServer::_rewriteRequest(AsyncWebServerRequest *request) -{ - for (const auto& r : _rewrites) - { - if (r->match(request)) - { - request->_url = r->toUrl(); - request->_addGetParams(r->params()); - } - } -} - -///////////////////////////////////////////////// - -void AsyncWebServer::_attachHandler(AsyncWebServerRequest *request) -{ - for (const auto& h : _handlers) - { - if (h->filter(request) && h->canHandle(request)) - { - request->setHandler(h); - return; - } - } - - request->addInterestingHeader("ANY"); - request->setHandler(_catchAllHandler); -} - -///////////////////////////////////////////////// - -AsyncCallbackWebHandler& AsyncWebServer::on(const char* uri, WebRequestMethodComposite method, - ArRequestHandlerFunction onRequest, - ArUploadHandlerFunction onUpload, ArBodyHandlerFunction onBody) -{ - AsyncCallbackWebHandler* handler = new AsyncCallbackWebHandler(); - handler->setUri(uri); - handler->setMethod(method); - handler->onRequest(onRequest); - handler->onUpload(onUpload); - handler->onBody(onBody); - addHandler(handler); - - return *handler; -} - -///////////////////////////////////////////////// - -AsyncCallbackWebHandler& AsyncWebServer::on(const char* uri, WebRequestMethodComposite method, - ArRequestHandlerFunction onRequest, - ArUploadHandlerFunction onUpload) -{ - AsyncCallbackWebHandler* handler = new AsyncCallbackWebHandler(); - handler->setUri(uri); - handler->setMethod(method); - handler->onRequest(onRequest); - handler->onUpload(onUpload); - addHandler(handler); - - return *handler; -} - -///////////////////////////////////////////////// - -AsyncCallbackWebHandler& AsyncWebServer::on(const char* uri, WebRequestMethodComposite method, - ArRequestHandlerFunction onRequest) -{ - AsyncCallbackWebHandler* handler = new AsyncCallbackWebHandler(); - handler->setUri(uri); - handler->setMethod(method); - handler->onRequest(onRequest); - addHandler(handler); - - return *handler; -} - -///////////////////////////////////////////////// - -AsyncCallbackWebHandler& AsyncWebServer::on(const char* uri, ArRequestHandlerFunction onRequest) -{ - AsyncCallbackWebHandler* handler = new AsyncCallbackWebHandler(); - handler->setUri(uri); - handler->onRequest(onRequest); - addHandler(handler); - - return *handler; -} - -///////////////////////////////////////////////// - -AsyncStaticWebHandler& AsyncWebServer::serveStatic(const char* uri, fs::FS& fs, const char* path, - const char* cache_control) -{ - AsyncStaticWebHandler* handler = new AsyncStaticWebHandler(uri, fs, path, cache_control); - addHandler(handler); - - return *handler; -} - -///////////////////////////////////////////////// - -void AsyncWebServer::onNotFound(ArRequestHandlerFunction fn) -{ - _catchAllHandler->onRequest(fn); -} - -///////////////////////////////////////////////// - -void AsyncWebServer::onFileUpload(ArUploadHandlerFunction fn) -{ - _catchAllHandler->onUpload(fn); -} - -///////////////////////////////////////////////// - -void AsyncWebServer::onRequestBody(ArBodyHandlerFunction fn) -{ - _catchAllHandler->onBody(fn); -} - -///////////////////////////////////////////////// - -void AsyncWebServer::reset() -{ - _rewrites.free(); - _handlers.free(); - - if (_catchAllHandler != NULL) - { - _catchAllHandler->onRequest(NULL); - _catchAllHandler->onUpload(NULL); - _catchAllHandler->onBody(NULL); - } -} - -///////////////////////////////////////////////// - - diff --git a/lib/AsyncWebServer_ESP32_W5500/src/edit.htm b/lib/AsyncWebServer_ESP32_W5500/src/edit.htm deleted file mode 100644 index 43d4984..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/edit.htm +++ /dev/null @@ -1,627 +0,0 @@ - - - - -ESP Editor - - - - - - -
-
-
-
- - - - diff --git a/lib/AsyncWebServer_ESP32_W5500/src/libb64/cdecode.c b/lib/AsyncWebServer_ESP32_W5500/src/libb64/cdecode.c deleted file mode 100644 index daa895b..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/libb64/cdecode.c +++ /dev/null @@ -1,150 +0,0 @@ -/**************************************************************************************************************************** - cdecode.c - c source to a base64 decoding algorithm implementation - - This is part of the libb64 project, and has been placed in the public domain. - For details, see http://sourceforge.net/projects/libb64 - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - *****************************************************************************************************************************/ - -#include "cdecode.h" - -///////////////////////////////////////////////// - -int base64_decode_value(int value_in) -{ - static const char decoding[] = - { - 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -2, -1, -1, -1, 0, 1, 2, - 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, - -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, - 47, 48, 49, 50, 51 - }; - - static const char decoding_size = sizeof(decoding); - value_in -= 43; - - if (value_in < 0 || value_in > decoding_size) - return -1; - - return decoding[(int)value_in]; -} - -///////////////////////////////////////////////// - -void base64_init_decodestate(base64_decodestate* state_in) -{ - state_in->step = step_a; - state_in->plainchar = 0; -} - -///////////////////////////////////////////////// - -int base64_decode_block(const char* code_in, const int length_in, char* plaintext_out, base64_decodestate* state_in) -{ - const char* codechar = code_in; - char* plainchar = plaintext_out; - int fragment; - - *plainchar = state_in->plainchar; - - switch (state_in->step) - { - while (1) - { - case step_a: - do - { - if (codechar == code_in + length_in) - { - state_in->step = step_a; - state_in->plainchar = *plainchar; - return plainchar - plaintext_out; - } - - fragment = base64_decode_value(*codechar++); - } while (fragment < 0); - - *plainchar = (fragment & 0x03f) << 2; - - // fall through - - case step_b: - do - { - if (codechar == code_in + length_in) - { - state_in->step = step_b; - state_in->plainchar = *plainchar; - return plainchar - plaintext_out; - } - - fragment = base64_decode_value(*codechar++); - } while (fragment < 0); - - *plainchar++ |= (fragment & 0x030) >> 4; - *plainchar = (fragment & 0x00f) << 4; - - // fall through - - case step_c: - do - { - if (codechar == code_in + length_in) - { - state_in->step = step_c; - state_in->plainchar = *plainchar; - return plainchar - plaintext_out; - } - - fragment = base64_decode_value(*codechar++); - } while (fragment < 0); - - *plainchar++ |= (fragment & 0x03c) >> 2; - *plainchar = (fragment & 0x003) << 6; - - // fall through - - case step_d: - do - { - if (codechar == code_in + length_in) - { - state_in->step = step_d; - state_in->plainchar = *plainchar; - return plainchar - plaintext_out; - } - - fragment = base64_decode_value(*codechar++); - } while (fragment < 0); - - *plainchar++ |= (fragment & 0x03f); - - // fall through - } - } - - /* control should not reach here */ - return plainchar - plaintext_out; -} - -///////////////////////////////////////////////// - -int base64_decode_chars(const char* code_in, const int length_in, char* plaintext_out) -{ - - base64_decodestate _state; - base64_init_decodestate(&_state); - int len = base64_decode_block(code_in, length_in, plaintext_out, &_state); - - if (len > 0) - plaintext_out[len] = 0; - - return len; -} diff --git a/lib/AsyncWebServer_ESP32_W5500/src/libb64/cdecode.h b/lib/AsyncWebServer_ESP32_W5500/src/libb64/cdecode.h deleted file mode 100644 index 524d1ed..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/libb64/cdecode.h +++ /dev/null @@ -1,62 +0,0 @@ -/**************************************************************************************************************************** - cdecode.h - c header for a base64 decoding algorithm - - This is part of the libb64 project, and has been placed in the public domain. - For details, see http://sourceforge.net/projects/libb64 - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - *****************************************************************************************************************************/ - -#pragma once - -// Reintroduce to prevent duplication compile error if other lib/core already has LIB64 -// pragma once can't prevent that -#ifndef BASE64_CDECODE_H -#define BASE64_CDECODE_H - -#define base64_decode_expected_len(n) ((n * 3) / 4) - -///////////////////////////////////////////////// - -#ifdef __cplusplus -extern "C" { -#endif - -///////////////////////////////////////////////// - -typedef enum -{ - step_a, step_b, step_c, step_d -} base64_decodestep; - -typedef struct -{ - base64_decodestep step; - char plainchar; -} base64_decodestate; - -///////////////////////////////////////////////// - -void base64_init_decodestate(base64_decodestate* state_in); - -int base64_decode_value(int value_in); - -int base64_decode_block(const char* code_in, const int length_in, char* plaintext_out, base64_decodestate* state_in); - -int base64_decode_chars(const char* code_in, const int length_in, char* plaintext_out); - -///////////////////////////////////////////////// - -#ifdef __cplusplus -} // extern "C" -#endif - -///////////////////////////////////////////////// - -#endif /* BASE64_CDECODE_H */ diff --git a/lib/AsyncWebServer_ESP32_W5500/src/libb64/cencode.c b/lib/AsyncWebServer_ESP32_W5500/src/libb64/cencode.c deleted file mode 100644 index 46635da..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/libb64/cencode.c +++ /dev/null @@ -1,154 +0,0 @@ -/**************************************************************************************************************************** - cencode.c - c source to a base64 encoding algorithm implementation - - This is part of the libb64 project, and has been placed in the public domain. - For details, see http://sourceforge.net/projects/libb64 - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - *****************************************************************************************************************************/ - -#include "cencode.h" - -const int CHARS_PER_LINE = 72; - -///////////////////////////////////////////////// - -void base64_init_encodestate(base64_encodestate* state_in) -{ - state_in->step = step_A; - state_in->result = 0; - state_in->stepcount = 0; -} - -///////////////////////////////////////////////// - -char base64_encode_value(char value_in) -{ - static const char* encoding = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - - if (value_in > 63) - return '='; - - return encoding[(unsigned int)value_in]; -} - -///////////////////////////////////////////////// - -int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in) -{ - const char* plainchar = plaintext_in; - const char* const plaintextend = plaintext_in + length_in; - char* codechar = code_out; - char result; - char fragment; - - result = state_in->result; - - switch (state_in->step) - { - while (1) - { - case step_A: - if (plainchar == plaintextend) - { - state_in->result = result; - state_in->step = step_A; - return codechar - code_out; - } - - fragment = *plainchar++; - result = (fragment & 0x0fc) >> 2; - *codechar++ = base64_encode_value(result); - result = (fragment & 0x003) << 4; - - // fall through - - case step_B: - if (plainchar == plaintextend) - { - state_in->result = result; - state_in->step = step_B; - return codechar - code_out; - } - - fragment = *plainchar++; - result |= (fragment & 0x0f0) >> 4; - *codechar++ = base64_encode_value(result); - result = (fragment & 0x00f) << 2; - - // fall through - - case step_C: - if (plainchar == plaintextend) - { - state_in->result = result; - state_in->step = step_C; - return codechar - code_out; - } - - fragment = *plainchar++; - result |= (fragment & 0x0c0) >> 6; - *codechar++ = base64_encode_value(result); - result = (fragment & 0x03f) >> 0; - *codechar++ = base64_encode_value(result); - - ++(state_in->stepcount); - - if (state_in->stepcount == CHARS_PER_LINE / 4) - { - *codechar++ = '\n'; - state_in->stepcount = 0; - } - - // fall through - } - } - - /* control should not reach here */ - return codechar - code_out; -} - -///////////////////////////////////////////////// - -int base64_encode_blockend(char* code_out, base64_encodestate* state_in) -{ - char* codechar = code_out; - - switch (state_in->step) - { - case step_B: - *codechar++ = base64_encode_value(state_in->result); - *codechar++ = '='; - *codechar++ = '='; - break; - - case step_C: - *codechar++ = base64_encode_value(state_in->result); - *codechar++ = '='; - break; - - case step_A: - break; - } - - *codechar = 0x00; - - return codechar - code_out; -} - -///////////////////////////////////////////////// - -int base64_encode_chars(const char* plaintext_in, int length_in, char* code_out) -{ - base64_encodestate _state; - base64_init_encodestate(&_state); - int len = base64_encode_block(plaintext_in, length_in, code_out, &_state); - - return len + base64_encode_blockend((code_out + len), &_state); -} diff --git a/lib/AsyncWebServer_ESP32_W5500/src/libb64/cencode.h b/lib/AsyncWebServer_ESP32_W5500/src/libb64/cencode.h deleted file mode 100644 index 1e392d3..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/libb64/cencode.h +++ /dev/null @@ -1,65 +0,0 @@ -/**************************************************************************************************************************** - cencode.h - c header for a base64 encoding algorithm - - This is part of the libb64 project, and has been placed in the public domain. - For details, see http://sourceforge.net/projects/libb64 - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - *****************************************************************************************************************************/ - -#pragma once - -// Reintroduce to prevent duplication compile error if other lib/core already has LIB64 -// pragma once can't prevent that -#ifndef BASE64_CENCODE_H -#define BASE64_CENCODE_H - -#define base64_encode_expected_len(n) ((((4 * n) / 3) + 3) & ~3) - -///////////////////////////////////////////////// - -#ifdef __cplusplus -extern "C" { -#endif - -///////////////////////////////////////////////// - -typedef enum -{ - step_A, step_B, step_C -} base64_encodestep; - -typedef struct -{ - base64_encodestep step; - char result; - int stepcount; -} base64_encodestate; - -///////////////////////////////////////////////// - -void base64_init_encodestate(base64_encodestate* state_in); - -char base64_encode_value(char value_in); - -int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in); - -int base64_encode_blockend(char* code_out, base64_encodestate* state_in); - -int base64_encode_chars(const char* plaintext_in, int length_in, char* code_out); - -///////////////////////////////////////////////// - -#ifdef __cplusplus -} // extern "C" -#endif - -///////////////////////////////////////////////// - -#endif /* BASE64_CENCODE_H */ diff --git a/lib/AsyncWebServer_ESP32_W5500/src/w5500/esp32_w5500.cpp b/lib/AsyncWebServer_ESP32_W5500/src/w5500/esp32_w5500.cpp deleted file mode 100644 index a870e77..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/w5500/esp32_w5500.cpp +++ /dev/null @@ -1,412 +0,0 @@ -/**************************************************************************************************************************** - esp32_w5500.cpp - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - *****************************************************************************************************************************/ - -#include "AsyncWebServer_ESP32_W5500_Debug.h" -#include "esp32_w5500.h" - -extern "C" -{ - esp_eth_mac_t* w5500_begin(int MISO, int MOSI, int SCLK, int CS, int INT, int SPICLOCK_MHZ, - int SPIHOST); -#include "esp_eth/esp_eth_w5500.h" -} - -#include "esp_event.h" -#include "esp_eth_phy.h" -#include "esp_eth_mac.h" -#include "esp_eth_com.h" - -#if CONFIG_IDF_TARGET_ESP32 - #include "soc/emac_ext_struct.h" - #include "soc/rtc.h" -#endif - -#include "lwip/err.h" -#include "lwip/dns.h" - -extern void tcpipInit(); - -//////////////////////////////////////// - -ESP32_W5500::ESP32_W5500() - : initialized(false) - , staticIP(false) - , eth_handle(NULL) - , started(false) - , eth_link(ETH_LINK_DOWN) -{ -} - -//////////////////////////////////////// - -ESP32_W5500::~ESP32_W5500() -{} - -//////////////////////////////////////// - -bool ESP32_W5500::begin(int MISO, int MOSI, int SCLK, int CS, int INT, int SPICLOCK_MHZ, int SPIHOST, - uint8_t *W5500_Mac) -{ - tcpipInit(); - - esp_base_mac_addr_set( W5500_Mac ); - - tcpip_adapter_set_default_eth_handlers(); - - esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH(); - esp_netif_t *eth_netif = esp_netif_new(&cfg); - - esp_eth_mac_t *eth_mac = w5500_begin(MISO, MOSI, SCLK, CS, INT, SPICLOCK_MHZ, SPIHOST); - - if (eth_mac == NULL) - { - AWS_LOGERROR("esp_eth_mac_new_esp32 failed"); - - return false; - } - - eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); - phy_config.autonego_timeout_ms = 0; // W5500 doesn't support auto-negotiation - phy_config.reset_gpio_num = -1; // W5500 doesn't have a pin to reset internal PHY - esp_eth_phy_t *eth_phy = esp_eth_phy_new_w5500(&phy_config); - - if (eth_phy == NULL) - { - AWS_LOGERROR("esp_eth_phy_new failed"); - - return false; - } - - eth_handle = NULL; - esp_eth_config_t eth_config = ETH_DEFAULT_CONFIG(eth_mac, eth_phy); - - if (esp_eth_driver_install(ð_config, ð_handle) != ESP_OK || eth_handle == NULL) - { - AWS_LOG("esp_eth_driver_install failed"); - - return false; - } - - eth_mac->set_addr(eth_mac, W5500_Mac); - -#if 1 - - if ( (SPICLOCK_MHZ < 14) || (SPICLOCK_MHZ > 25) ) - { - AWS_LOGERROR("SPI Clock must be >= 8 and <= 25 MHz for W5500"); - ESP_ERROR_CHECK(ESP_FAIL); - } - -#endif - - /* attach Ethernet driver to TCP/IP stack */ - if (esp_netif_attach(eth_netif, esp_eth_new_netif_glue(eth_handle)) != ESP_OK) - { - AWS_LOGERROR("esp_netif_attach failed"); - - return false; - } - - if (esp_eth_start(eth_handle) != ESP_OK) - { - AWS_LOG("esp_eth_start failed"); - - return false; - } - - // holds a few microseconds to let DHCP start and enter into a good state - // FIX ME -- addresses issue https://github.com/espressif/arduino-esp32/issues/5733 - delay(50); - - return true; -} - -//////////////////////////////////////// - -bool ESP32_W5500::config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1, IPAddress dns2) -{ - esp_err_t err = ESP_OK; - tcpip_adapter_ip_info_t info; - - if (static_cast(local_ip) != 0) - { - info.ip.addr = static_cast(local_ip); - info.gw.addr = static_cast(gateway); - info.netmask.addr = static_cast(subnet); - } - else - { - info.ip.addr = 0; - info.gw.addr = 0; - info.netmask.addr = 0; - } - - err = tcpip_adapter_dhcpc_stop(TCPIP_ADAPTER_IF_ETH); - - if (err != ESP_OK && err != ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STOPPED) - { - AWS_LOGERROR1("DHCP could not be stopped! Error =", err); - return false; - } - - err = tcpip_adapter_set_ip_info(TCPIP_ADAPTER_IF_ETH, &info); - - if (err != ERR_OK) - { - AWS_LOGERROR1("STA IP could not be configured! Error = ", err); - return false; - } - - if (info.ip.addr) - { - staticIP = true; - } - else - { - err = tcpip_adapter_dhcpc_start(TCPIP_ADAPTER_IF_ETH); - - if (err != ESP_OK && err != ESP_ERR_TCPIP_ADAPTER_DHCP_ALREADY_STARTED) - { - AWS_LOGWARN1("DHCP could not be started! Error =", err); - return false; - } - - staticIP = false; - } - - ip_addr_t d; - d.type = IPADDR_TYPE_V4; - - if (static_cast(dns1) != 0) - { - // Set DNS1-Server - d.u_addr.ip4.addr = static_cast(dns1); - dns_setserver(0, &d); - } - - if (static_cast(dns2) != 0) - { - // Set DNS2-Server - d.u_addr.ip4.addr = static_cast(dns2); - dns_setserver(1, &d); - } - - return true; -} - -//////////////////////////////////////// - -IPAddress ESP32_W5500::localIP() -{ - tcpip_adapter_ip_info_t ip; - - if (tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &ip)) - { - AWS_LOGDEBUG("localIP NULL"); - - return IPAddress(); - } - - AWS_LOGDEBUG1("localIP =", IPAddress(ip.ip.addr)); - - return IPAddress(ip.ip.addr); -} - -//////////////////////////////////////// - -IPAddress ESP32_W5500::subnetMask() -{ - tcpip_adapter_ip_info_t ip; - - if (tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &ip)) - { - return IPAddress(); - } - - return IPAddress(ip.netmask.addr); -} - -//////////////////////////////////////// - -IPAddress ESP32_W5500::gatewayIP() -{ - tcpip_adapter_ip_info_t ip; - - if (tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &ip)) - { - return IPAddress(); - } - - return IPAddress(ip.gw.addr); -} - -//////////////////////////////////////// - -IPAddress ESP32_W5500::dnsIP(uint8_t dns_no) -{ - const ip_addr_t * dns_ip = dns_getserver(dns_no); - - return IPAddress(dns_ip->u_addr.ip4.addr); -} - -//////////////////////////////////////// - -IPAddress ESP32_W5500::broadcastIP() -{ - tcpip_adapter_ip_info_t ip; - - if (tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &ip)) - { - return IPAddress(); - } - - return WiFiGenericClass::calculateBroadcast(IPAddress(ip.gw.addr), IPAddress(ip.netmask.addr)); -} - -//////////////////////////////////////// - -IPAddress ESP32_W5500::networkID() -{ - tcpip_adapter_ip_info_t ip; - - if (tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &ip)) - { - return IPAddress(); - } - - return WiFiGenericClass::calculateNetworkID(IPAddress(ip.gw.addr), IPAddress(ip.netmask.addr)); -} - -//////////////////////////////////////// - -uint8_t ESP32_W5500::subnetCIDR() -{ - tcpip_adapter_ip_info_t ip; - - if (tcpip_adapter_get_ip_info(TCPIP_ADAPTER_IF_ETH, &ip)) - { - return (uint8_t)0; - } - - return WiFiGenericClass::calculateSubnetCIDR(IPAddress(ip.netmask.addr)); -} - -//////////////////////////////////////// - -const char * ESP32_W5500::getHostname() -{ - const char * hostname; - - if (tcpip_adapter_get_hostname(TCPIP_ADAPTER_IF_ETH, &hostname)) - { - return NULL; - } - - return hostname; -} - -//////////////////////////////////////// - -bool ESP32_W5500::setHostname(const char * hostname) -{ - return tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_ETH, hostname) == 0; -} - -//////////////////////////////////////// - -bool ESP32_W5500::fullDuplex() -{ -#ifdef ESP_IDF_VERSION_MAJOR - return true;//todo: do not see an API for this -#else - return eth_config.phy_get_duplex_mode(); -#endif -} - -//////////////////////////////////////// - -bool ESP32_W5500::linkUp() -{ -#ifdef ESP_IDF_VERSION_MAJOR - return eth_link == ETH_LINK_UP; -#else - return eth_config.phy_check_link(); -#endif -} - -//////////////////////////////////////// - -uint8_t ESP32_W5500::linkSpeed() -{ -#ifdef ESP_IDF_VERSION_MAJOR - eth_speed_t link_speed; - esp_eth_ioctl(eth_handle, ETH_CMD_G_SPEED, &link_speed); - return (link_speed == ETH_SPEED_10M) ? 10 : 100; -#else - return eth_config.phy_get_speed_mode() ? 100 : 10; -#endif -} - -//////////////////////////////////////// - -bool ESP32_W5500::enableIpV6() -{ - return tcpip_adapter_create_ip6_linklocal(TCPIP_ADAPTER_IF_ETH) == 0; -} - -//////////////////////////////////////// - -IPv6Address ESP32_W5500::localIPv6() -{ - static ip6_addr_t addr; - - if (tcpip_adapter_get_ip6_linklocal(TCPIP_ADAPTER_IF_ETH, &addr)) - { - return IPv6Address(); - } - - return IPv6Address(addr.addr); -} - -//////////////////////////////////////// - -uint8_t * ESP32_W5500::macAddress(uint8_t* mac) -{ - if (!mac) - { - return NULL; - } - -#ifdef ESP_IDF_VERSION_MAJOR - esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, mac); -#else - esp_eth_get_mac(mac); -#endif - - return mac; -} - -//////////////////////////////////////// - -String ESP32_W5500::macAddress() -{ - uint8_t mac[6] = {0, 0, 0, 0, 0, 0}; - char macStr[18] = { 0 }; - macAddress(mac); - sprintf(macStr, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - - return String(macStr); -} - -//////////////////////////////////////// - -ESP32_W5500 ETH; diff --git a/lib/AsyncWebServer_ESP32_W5500/src/w5500/esp32_w5500.h b/lib/AsyncWebServer_ESP32_W5500/src/w5500/esp32_w5500.h deleted file mode 100644 index 21ec0c4..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/w5500/esp32_w5500.h +++ /dev/null @@ -1,94 +0,0 @@ -/**************************************************************************************************************************** - esp32_w5500.h - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - *****************************************************************************************************************************/ - -#ifndef _ESP32_W5500_H_ -#define _ESP32_W5500_H_ - -#include "WiFi.h" -#include "esp_system.h" -#include "esp_eth.h" - -#include - -//////////////////////////////////////// - -#if ESP_IDF_VERSION_MAJOR < 4 || ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(4,4,0) - #error "This version of Arduino is too old" -#endif - -//////////////////////////////////////// - -static uint8_t W5500_Default_Mac[] = { 0xFE, 0xED, 0xDE, 0xAD, 0xBE, 0xEF }; - -//////////////////////////////////////// - -class ESP32_W5500 -{ - private: - bool initialized; - bool staticIP; - -#if ESP_IDF_VERSION_MAJOR > 3 - esp_eth_handle_t eth_handle; - - protected: - bool started; - eth_link_t eth_link; - static void eth_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data); -#else - bool started; - eth_config_t eth_config; -#endif - - public: - ESP32_W5500(); - ~ESP32_W5500(); - - bool begin(int MISO, int MOSI, int SCLK, int CS, int INT, int SPICLOCK_MHZ = 25, int SPIHOST = SPI3_HOST, - uint8_t *W5500_Mac = W5500_Default_Mac); - - bool config(IPAddress local_ip, IPAddress gateway, IPAddress subnet, IPAddress dns1 = (uint32_t)0x00000000, - IPAddress dns2 = (uint32_t)0x00000000); - - const char * getHostname(); - bool setHostname(const char * hostname); - - bool fullDuplex(); - bool linkUp(); - uint8_t linkSpeed(); - - bool enableIpV6(); - IPv6Address localIPv6(); - - IPAddress localIP(); - IPAddress subnetMask(); - IPAddress gatewayIP(); - IPAddress dnsIP(uint8_t dns_no = 0); - - IPAddress broadcastIP(); - IPAddress networkID(); - uint8_t subnetCIDR(); - - uint8_t * macAddress(uint8_t* mac); - String macAddress(); - - friend class WiFiClient; - friend class WiFiServer; -}; - -//////////////////////////////////////// - -extern ESP32_W5500 ETH; - -//////////////////////////////////////// - -#endif /* _ESP32_W5500_H_ */ diff --git a/lib/AsyncWebServer_ESP32_W5500/src/w5500/esp_eth/esp_eth_mac_w5500.c b/lib/AsyncWebServer_ESP32_W5500/src/w5500/esp_eth/esp_eth_mac_w5500.c deleted file mode 100644 index 4a11138..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/w5500/esp_eth/esp_eth_mac_w5500.c +++ /dev/null @@ -1,950 +0,0 @@ -/**************************************************************************************************************************** - esp_eth_mac_w5500.c - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - *****************************************************************************************************************************/ - -// Copyright 2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include -#include -#include "driver/gpio.h" -#include "driver/spi_master.h" -#include "esp_attr.h" -#include "esp_log.h" -#include "esp_check.h" -#include "esp_eth.h" -#include "esp_system.h" -#include "esp_intr_alloc.h" -#include "esp_heap_caps.h" -#include "esp_rom_gpio.h" -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "freertos/semphr.h" -#include "hal/cpu_hal.h" -#include "w5500.h" -#include "sdkconfig.h" - -//////////////////////////////////////// - -static const char *TAG = "w5500.mac"; - -#define W5500_SPI_LOCK_TIMEOUT_MS (50) -#define W5500_TX_MEM_SIZE (0x4000) -#define W5500_RX_MEM_SIZE (0x4000) - -//////////////////////////////////////// - -typedef struct -{ - esp_eth_mac_t parent; - esp_eth_mediator_t *eth; - spi_device_handle_t spi_hdl; - SemaphoreHandle_t spi_lock; - TaskHandle_t rx_task_hdl; - uint32_t sw_reset_timeout_ms; - int int_gpio_num; - uint8_t addr[6]; - bool packets_remain; -} emac_w5500_t; - -//////////////////////////////////////// - -static inline bool w5500_lock(emac_w5500_t *emac) -{ - return xSemaphoreTake(emac->spi_lock, pdMS_TO_TICKS(W5500_SPI_LOCK_TIMEOUT_MS)) == pdTRUE; -} - -//////////////////////////////////////// - -static inline bool w5500_unlock(emac_w5500_t *emac) -{ - return xSemaphoreGive(emac->spi_lock) == pdTRUE; -} - -//////////////////////////////////////// - -static esp_err_t w5500_write(emac_w5500_t *emac, uint32_t address, const void *value, uint32_t len) -{ - esp_err_t ret = ESP_OK; - - spi_transaction_t trans = - { - .cmd = (address >> W5500_ADDR_OFFSET), - .addr = ((address & 0xFFFF) | (W5500_ACCESS_MODE_WRITE << W5500_RWB_OFFSET) | W5500_SPI_OP_MODE_VDM), - .length = 8 * len, - .tx_buffer = value - }; - - if (w5500_lock(emac)) - { - if (spi_device_polling_transmit(emac->spi_hdl, &trans) != ESP_OK) - { - ESP_LOGE(TAG, "%s(%d): SPI transmit failed", __FUNCTION__, __LINE__); - ret = ESP_FAIL; - } - - w5500_unlock(emac); - } - else - { - ret = ESP_ERR_TIMEOUT; - } - - return ret; -} - -//////////////////////////////////////// - -static esp_err_t w5500_read(emac_w5500_t *emac, uint32_t address, void *value, uint32_t len) -{ - esp_err_t ret = ESP_OK; - - spi_transaction_t trans = - { - // use direct reads for registers to prevent overwrites by 4-byte boundary writes - .flags = len <= 4 ? SPI_TRANS_USE_RXDATA : 0, - .cmd = (address >> W5500_ADDR_OFFSET), - .addr = ((address & 0xFFFF) | (W5500_ACCESS_MODE_READ << W5500_RWB_OFFSET) | W5500_SPI_OP_MODE_VDM), - .length = 8 * len, - .rx_buffer = value - }; - - if (w5500_lock(emac)) - { - if (spi_device_polling_transmit(emac->spi_hdl, &trans) != ESP_OK) - { - ESP_LOGE(TAG, "%s(%d): SPI transmit failed", __FUNCTION__, __LINE__); - ret = ESP_FAIL; - } - - w5500_unlock(emac); - } - else - { - ret = ESP_ERR_TIMEOUT; - } - - if ((trans.flags & SPI_TRANS_USE_RXDATA) && len <= 4) - { - memcpy(value, trans.rx_data, len); // copy register values to output - } - - return ret; -} - -//////////////////////////////////////// - -static esp_err_t w5500_send_command(emac_w5500_t *emac, uint8_t command, uint32_t timeout_ms) -{ - esp_err_t ret = ESP_OK; - - ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SOCK_CR(0), &command, sizeof(command)), err, TAG, "Write SCR failed"); - - // after W5500 accepts the command, the command register will be cleared automatically - uint32_t to = 0; - - for (to = 0; to < timeout_ms / 10; to++) - { - ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_REG_SOCK_CR(0), &command, sizeof(command)), err, TAG, "Read SCR failed"); - - if (!command) - { - break; - } - - vTaskDelay(pdMS_TO_TICKS(10)); - } - - ESP_GOTO_ON_FALSE(to < timeout_ms / 10, ESP_ERR_TIMEOUT, err, TAG, "Send command timeout"); - -err: - return ret; -} - -//////////////////////////////////////// - -static esp_err_t w5500_get_tx_free_size(emac_w5500_t *emac, uint16_t *size) -{ - esp_err_t ret = ESP_OK; - uint16_t free0, free1 = 0; - - // read TX_FSR register more than once, until we get the same value - // this is a trick because we might be interrupted between reading the high/low part of the TX_FSR register (16 bits in length) - do - { - ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_REG_SOCK_TX_FSR(0), &free0, sizeof(free0)), err, TAG, "Read TX FSR failed"); - ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_REG_SOCK_TX_FSR(0), &free1, sizeof(free1)), err, TAG, "Read TX FSR failed"); - } while (free0 != free1); - - *size = __builtin_bswap16(free0); - -err: - return ret; -} - -//////////////////////////////////////// - -static esp_err_t w5500_get_rx_received_size(emac_w5500_t *emac, uint16_t *size) -{ - esp_err_t ret = ESP_OK; - uint16_t received0, received1 = 0; - - do - { - ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_REG_SOCK_RX_RSR(0), &received0, sizeof(received0)), err, TAG, - "Read RX RSR failed"); - ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_REG_SOCK_RX_RSR(0), &received1, sizeof(received1)), err, TAG, - "Read RX RSR failed"); - } while (received0 != received1); - - *size = __builtin_bswap16(received0); - -err: - return ret; -} - -//////////////////////////////////////// - -static esp_err_t w5500_write_buffer(emac_w5500_t *emac, const void *buffer, uint32_t len, uint16_t offset) -{ - esp_err_t ret = ESP_OK; - uint32_t remain = len; - const uint8_t *buf = buffer; - offset %= W5500_TX_MEM_SIZE; - - if (offset + len > W5500_TX_MEM_SIZE) - { - remain = (offset + len) % W5500_TX_MEM_SIZE; - len = W5500_TX_MEM_SIZE - offset; - ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_MEM_SOCK_TX(0, offset), buf, len), err, TAG, "Write TX buffer failed"); - offset += len; - buf += len; - } - - ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_MEM_SOCK_TX(0, offset), buf, remain), err, TAG, "Write TX buffer failed"); - -err: - return ret; -} - -//////////////////////////////////////// - -static esp_err_t w5500_read_buffer(emac_w5500_t *emac, void *buffer, uint32_t len, uint16_t offset) -{ - esp_err_t ret = ESP_OK; - uint32_t remain = len; - uint8_t *buf = buffer; - offset %= W5500_RX_MEM_SIZE; - - if (offset + len > W5500_RX_MEM_SIZE) - { - remain = (offset + len) % W5500_RX_MEM_SIZE; - len = W5500_RX_MEM_SIZE - offset; - ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_MEM_SOCK_RX(0, offset), buf, len), err, TAG, "Read RX buffer failed"); - offset += len; - buf += len; - } - - ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_MEM_SOCK_RX(0, offset), buf, remain), err, TAG, "Read RX buffer failed"); - -err: - return ret; -} - -//////////////////////////////////////// - -static esp_err_t w5500_set_mac_addr(emac_w5500_t *emac) -{ - esp_err_t ret = ESP_OK; - - ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_MAC, emac->addr, 6), err, TAG, "Write MAC address register failed"); - -err: - return ret; -} - -//////////////////////////////////////// - -static esp_err_t w5500_reset(emac_w5500_t *emac) -{ - esp_err_t ret = ESP_OK; - - /* software reset */ - uint8_t mr = W5500_MR_RST; // Set RST bit (auto clear) - - ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_MR, &mr, sizeof(mr)), err, TAG, "Write MR failed"); - - uint32_t to = 0; - - for (to = 0; to < emac->sw_reset_timeout_ms / 10; to++) - { - ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_REG_MR, &mr, sizeof(mr)), err, TAG, "Read MR failed"); - - if (!(mr & W5500_MR_RST)) - { - break; - } - - vTaskDelay(pdMS_TO_TICKS(10)); - } - - ESP_GOTO_ON_FALSE(to < emac->sw_reset_timeout_ms / 10, ESP_ERR_TIMEOUT, err, TAG, "Reset timeout"); - -err: - return ret; -} - -//////////////////////////////////////// - -static esp_err_t w5500_verify_id(emac_w5500_t *emac) -{ - esp_err_t ret = ESP_OK; - uint8_t version = 0; - ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_REG_VERSIONR, &version, sizeof(version)), err, TAG, "Read VERSIONR failed"); - - // W5500 doesn't have chip ID, we just print the version number instead - ESP_LOGI(TAG, "version=%x", version); - -err: - return ret; -} - -//////////////////////////////////////// - -static esp_err_t w5500_setup_default(emac_w5500_t *emac) -{ - esp_err_t ret = ESP_OK; - uint8_t reg_value = 16; - - // Only SOCK0 can be used as MAC RAW mode, so we give the whole buffer (16KB TX and 16KB RX) to SOCK0 - ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SOCK_RXBUF_SIZE(0), ®_value, sizeof(reg_value)), err, TAG, - "Set rx buffer size failed"); - ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SOCK_TXBUF_SIZE(0), ®_value, sizeof(reg_value)), err, TAG, - "Set tx buffer size failed"); - - reg_value = 0; - - for (int i = 1; i < 8; i++) - { - ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SOCK_RXBUF_SIZE(i), ®_value, sizeof(reg_value)), err, TAG, - "Set SOCK_RXBUF_SIZE failed"); - ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SOCK_TXBUF_SIZE(i), ®_value, sizeof(reg_value)), err, TAG, - "Set SOCK_TXBUF_SIZE failed"); - } - - /* Enable ping block, disable PPPoE, WOL */ - reg_value = W5500_MR_PB; - ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_MR, ®_value, sizeof(reg_value)), err, TAG, "Write MR failed"); - - /* Disable interrupt for all sockets by default */ - reg_value = 0; - ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SIMR, ®_value, sizeof(reg_value)), err, TAG, "Write SIMR failed"); - - /* Enable MAC RAW mode for SOCK0, enable MAC filter, no blocking broadcast and multicast */ - reg_value = W5500_SMR_MAC_RAW | W5500_SMR_MAC_FILTER; - ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SOCK_MR(0), ®_value, sizeof(reg_value)), err, TAG, - "Write SOCK0 MR failed"); - - /* Enable receive event for SOCK0 */ - reg_value = W5500_SIR_RECV; - ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SOCK_IMR(0), ®_value, sizeof(reg_value)), err, TAG, - "Write SOCK0 IMR failed"); - - /* Set the interrupt re-assert level to maximum (~1.5ms) to lower the chances of missing it */ - uint16_t int_level = __builtin_bswap16(0xFFFF); - ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_INTLEVEL, &int_level, sizeof(int_level)), err, TAG, - "Write INTLEVEL failed"); - -err: - return ret; -} - -//////////////////////////////////////// - -static esp_err_t emac_w5500_start(esp_eth_mac_t *mac) -{ - esp_err_t ret = ESP_OK; - emac_w5500_t *emac = __containerof(mac, emac_w5500_t, parent); - - uint8_t reg_value = 0; - /* open SOCK0 */ - ESP_GOTO_ON_ERROR(w5500_send_command(emac, W5500_SCR_OPEN, 100), err, TAG, "Issue OPEN command failed"); - - /* enable interrupt for SOCK0 */ - reg_value = W5500_SIMR_SOCK0; - ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SIMR, ®_value, sizeof(reg_value)), err, TAG, "Write SIMR failed"); - -err: - return ret; -} - -static esp_err_t emac_w5500_stop(esp_eth_mac_t *mac) -{ - esp_err_t ret = ESP_OK; - - emac_w5500_t *emac = __containerof(mac, emac_w5500_t, parent); - uint8_t reg_value = 0; - /* disable interrupt */ - ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SIMR, ®_value, sizeof(reg_value)), err, TAG, "Write SIMR failed"); - /* close SOCK0 */ - ESP_GOTO_ON_ERROR(w5500_send_command(emac, W5500_SCR_CLOSE, 100), err, TAG, "Issue SCR_CLOSE command failed"); - -err: - return ret; -} - -//////////////////////////////////////// - -IRAM_ATTR static void w5500_isr_handler(void *arg) -{ - emac_w5500_t *emac = (emac_w5500_t *)arg; - BaseType_t high_task_wakeup = pdFALSE; - - /* notify w5500 task */ - vTaskNotifyGiveFromISR(emac->rx_task_hdl, &high_task_wakeup); - - if (high_task_wakeup != pdFALSE) - { - portYIELD_FROM_ISR(); - } -} - -//////////////////////////////////////// - -static void emac_w5500_task(void *arg) -{ - emac_w5500_t *emac = (emac_w5500_t *)arg; - uint8_t status = 0; - uint8_t *buffer = NULL; - uint32_t length = 0; - - while (1) - { - // check if the task receives any notification - if (ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(1000)) == 0 && // if no notification ... - gpio_get_level(emac->int_gpio_num) != 0) - { - // ...and no interrupt asserted - continue; // -> just continue to check again - } - - /* read interrupt status */ - w5500_read(emac, W5500_REG_SOCK_IR(0), &status, sizeof(status)); - - /* packet received */ - if (status & W5500_SIR_RECV) - { - status = W5500_SIR_RECV; - // clear interrupt status - w5500_write(emac, W5500_REG_SOCK_IR(0), &status, sizeof(status)); - - do - { - length = ETH_MAX_PACKET_SIZE; - buffer = heap_caps_malloc(length, MALLOC_CAP_DMA); - - if (!buffer) - { - ESP_LOGE(TAG, "No mem for receive buffer"); - break; - } - else if (emac->parent.receive(&emac->parent, buffer, &length) == ESP_OK) - { - /* pass the buffer to stack (e.g. TCP/IP layer) */ - if (length) - { - emac->eth->stack_input(emac->eth, buffer, length); - } - else - { - free(buffer); - } - } - else - { - free(buffer); - } - } while (emac->packets_remain); - } - } - - vTaskDelete(NULL); -} - -//////////////////////////////////////// - -static esp_err_t emac_w5500_set_mediator(esp_eth_mac_t *mac, esp_eth_mediator_t *eth) -{ - esp_err_t ret = ESP_OK; - ESP_GOTO_ON_FALSE(eth, ESP_ERR_INVALID_ARG, err, TAG, "Can't set mac's mediator to null"); - emac_w5500_t *emac = __containerof(mac, emac_w5500_t, parent); - emac->eth = eth; - return ESP_OK; -err: - return ret; -} - -//////////////////////////////////////// - -static esp_err_t emac_w5500_write_phy_reg(esp_eth_mac_t *mac, uint32_t phy_addr, uint32_t phy_reg, uint32_t reg_value) -{ - esp_err_t ret = ESP_OK; - emac_w5500_t *emac = __containerof(mac, emac_w5500_t, parent); - - // PHY register and MAC registers are mixed together in W5500 - // The only PHY register is PHYCFGR - ESP_GOTO_ON_FALSE(phy_reg == W5500_REG_PHYCFGR, ESP_FAIL, err, TAG, "Wrong PHY register"); - ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_PHYCFGR, ®_value, sizeof(uint8_t)), err, TAG, - "write PHY register failed"); - -err: - return ret; -} - -//////////////////////////////////////// - -static esp_err_t emac_w5500_read_phy_reg(esp_eth_mac_t *mac, uint32_t phy_addr, uint32_t phy_reg, uint32_t *reg_value) -{ - esp_err_t ret = ESP_OK; - ESP_GOTO_ON_FALSE(reg_value, ESP_ERR_INVALID_ARG, err, TAG, "Can't set reg_value to null"); - emac_w5500_t *emac = __containerof(mac, emac_w5500_t, parent); - - // PHY register and MAC registers are mixed together in W5500 - // The only PHY register is PHYCFGR - ESP_GOTO_ON_FALSE(phy_reg == W5500_REG_PHYCFGR, ESP_FAIL, err, TAG, "Wrong PHY register"); - ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_REG_PHYCFGR, reg_value, sizeof(uint8_t)), err, TAG, - "read PHY register failed"); - -err: - return ret; -} - -//////////////////////////////////////// - -static esp_err_t emac_w5500_set_addr(esp_eth_mac_t *mac, uint8_t *addr) -{ - esp_err_t ret = ESP_OK; - - ESP_GOTO_ON_FALSE(addr, ESP_ERR_INVALID_ARG, err, TAG, "Invalid argument"); - emac_w5500_t *emac = __containerof(mac, emac_w5500_t, parent); - memcpy(emac->addr, addr, 6); - ESP_GOTO_ON_ERROR(w5500_set_mac_addr(emac), err, TAG, "Set mac address failed"); - -err: - return ret; -} - -//////////////////////////////////////// - -static esp_err_t emac_w5500_get_addr(esp_eth_mac_t *mac, uint8_t *addr) -{ - esp_err_t ret = ESP_OK; - - ESP_GOTO_ON_FALSE(addr, ESP_ERR_INVALID_ARG, err, TAG, "Invalid argument"); - emac_w5500_t *emac = __containerof(mac, emac_w5500_t, parent); - memcpy(addr, emac->addr, 6); - -err: - return ret; -} - -//////////////////////////////////////// - -static esp_err_t emac_w5500_set_link(esp_eth_mac_t *mac, eth_link_t link) -{ - esp_err_t ret = ESP_OK; - - switch (link) - { - case ETH_LINK_UP: - ESP_LOGD(TAG, "Link is up"); - ESP_GOTO_ON_ERROR(mac->start(mac), err, TAG, "W5500 start failed"); - break; - - case ETH_LINK_DOWN: - ESP_LOGD(TAG, "link is down"); - ESP_GOTO_ON_ERROR(mac->stop(mac), err, TAG, "W5500 stop failed"); - break; - - default: - ESP_GOTO_ON_FALSE(false, ESP_ERR_INVALID_ARG, err, TAG, "Unknown link status"); - break; - } - -err: - return ret; -} - -//////////////////////////////////////// - -static esp_err_t emac_w5500_set_speed(esp_eth_mac_t *mac, eth_speed_t speed) -{ - esp_err_t ret = ESP_OK; - - switch (speed) - { - case ETH_SPEED_10M: - ESP_LOGD(TAG, "Setting to 10Mbps"); - break; - - case ETH_SPEED_100M: - ESP_LOGD(TAG, "Setting to 100Mbps"); - break; - - default: - ESP_GOTO_ON_FALSE(false, ESP_ERR_INVALID_ARG, err, TAG, "Unknown speed"); - break; - } - -err: - return ret; -} - -//////////////////////////////////////// - -static esp_err_t emac_w5500_set_duplex(esp_eth_mac_t *mac, eth_duplex_t duplex) -{ - esp_err_t ret = ESP_OK; - - switch (duplex) - { - case ETH_DUPLEX_HALF: - ESP_LOGD(TAG, "Setting to HALF_DUPLEX"); - break; - - case ETH_DUPLEX_FULL: - ESP_LOGD(TAG, "Setting to FULL_DUPLEX"); - break; - - default: - ESP_GOTO_ON_FALSE(false, ESP_ERR_INVALID_ARG, err, TAG, "Unknown duplex"); - break; - } - -err: - return ret; -} - -//////////////////////////////////////// - -static esp_err_t emac_w5500_set_promiscuous(esp_eth_mac_t *mac, bool enable) -{ - esp_err_t ret = ESP_OK; - emac_w5500_t *emac = __containerof(mac, emac_w5500_t, parent); - - uint8_t smr = 0; - ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_REG_SOCK_MR(0), &smr, sizeof(smr)), err, TAG, "Read SOCK0 MR failed"); - - if (enable) - { - smr &= ~W5500_SMR_MAC_FILTER; - } - else - { - smr |= W5500_SMR_MAC_FILTER; - } - - ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SOCK_MR(0), &smr, sizeof(smr)), err, TAG, "Write SOCK0 MR failed"); - -err: - return ret; -} - -//////////////////////////////////////// - -static esp_err_t emac_w5500_enable_flow_ctrl(esp_eth_mac_t *mac, bool enable) -{ - /* w5500 doesn't support flow control function, so accept any value */ - return ESP_ERR_NOT_SUPPORTED; -} - -//////////////////////////////////////// - -static esp_err_t emac_w5500_set_peer_pause_ability(esp_eth_mac_t *mac, uint32_t ability) -{ - /* w5500 doesn't support PAUSE function, so accept any value */ - return ESP_ERR_NOT_SUPPORTED; -} - -//////////////////////////////////////// - -static inline bool is_w5500_sane_for_rxtx(emac_w5500_t *emac) -{ - uint8_t phycfg; - - /* phy is ok for rx and tx operations if bits RST and LNK are set (no link down, no reset) */ - if (w5500_read(emac, W5500_REG_PHYCFGR, &phycfg, 1) == ESP_OK && (phycfg & 0x8001)) - { - return true; - } - - return false; -} - -//////////////////////////////////////// - -static esp_err_t emac_w5500_transmit(esp_eth_mac_t *mac, uint8_t *buf, uint32_t length) -{ - esp_err_t ret = ESP_OK; - - emac_w5500_t *emac = __containerof(mac, emac_w5500_t, parent); - uint16_t offset = 0; - - // check if there're free memory to store this packet - uint16_t free_size = 0; - ESP_GOTO_ON_ERROR(w5500_get_tx_free_size(emac, &free_size), err, TAG, "Get free size failed"); - ESP_GOTO_ON_FALSE(length <= free_size, ESP_ERR_NO_MEM, err, TAG, "Free size (%d) < send length (%d)", length, - free_size); - - // get current write pointer - ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_REG_SOCK_TX_WR(0), &offset, sizeof(offset)), err, TAG, "Read TX WR failed"); - offset = __builtin_bswap16(offset); - - // copy data to tx memory - ESP_GOTO_ON_ERROR(w5500_write_buffer(emac, buf, length, offset), err, TAG, "Write frame failed"); - - // update write pointer - offset += length; - offset = __builtin_bswap16(offset); - ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SOCK_TX_WR(0), &offset, sizeof(offset)), err, TAG, "Write TX WR failed"); - - // issue SEND command - ESP_GOTO_ON_ERROR(w5500_send_command(emac, W5500_SCR_SEND, 100), err, TAG, "Issue SEND command failed"); - - // pooling the TX done event - int retry = 0; - uint8_t status = 0; - - while (!(status & W5500_SIR_SEND)) - { - ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_REG_SOCK_IR(0), &status, sizeof(status)), err, TAG, "Read SOCK0 IR failed"); - - if ((retry++ > 3 && !is_w5500_sane_for_rxtx(emac)) || retry > 10) - { - return ESP_FAIL; - } - } - - // clear the event bit - status = W5500_SIR_SEND; - ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SOCK_IR(0), &status, sizeof(status)), err, TAG, "Write SOCK0 IR failed"); - -err: - return ret; -} - -//////////////////////////////////////// - -static esp_err_t emac_w5500_receive(esp_eth_mac_t *mac, uint8_t *buf, uint32_t *length) -{ - esp_err_t ret = ESP_OK; - - emac_w5500_t *emac = __containerof(mac, emac_w5500_t, parent); - - uint16_t offset = 0; - uint16_t rx_len = 0; - uint16_t remain_bytes = 0; - emac->packets_remain = false; - - w5500_get_rx_received_size(emac, &remain_bytes); - - if (remain_bytes) - { - // get current read pointer - ESP_GOTO_ON_ERROR(w5500_read(emac, W5500_REG_SOCK_RX_RD(0), &offset, sizeof(offset)), err, TAG, "Read RX RD failed"); - - offset = __builtin_bswap16(offset); - - // read head first - ESP_GOTO_ON_ERROR(w5500_read_buffer(emac, &rx_len, sizeof(rx_len), offset), err, TAG, "Read frame header failed"); - - rx_len = __builtin_bswap16(rx_len) - 2; // data size includes 2 bytes of header - offset += 2; - - // read the payload - ESP_GOTO_ON_ERROR(w5500_read_buffer(emac, buf, rx_len, offset), err, TAG, "Read payload failed, len=%d, offset=%d", - rx_len, offset); - - offset += rx_len; - - // update read pointer - offset = __builtin_bswap16(offset); - ESP_GOTO_ON_ERROR(w5500_write(emac, W5500_REG_SOCK_RX_RD(0), &offset, sizeof(offset)), err, TAG, "Write RX RD failed"); - - /* issue RECV command */ - ESP_GOTO_ON_ERROR(w5500_send_command(emac, W5500_SCR_RECV, 100), err, TAG, "Issue RECV command failed"); - - // check if there're more data need to process - remain_bytes -= rx_len + 2; - emac->packets_remain = remain_bytes > 0; - } - - *length = rx_len; - -err: - return ret; -} - -//////////////////////////////////////// - -static esp_err_t emac_w5500_init(esp_eth_mac_t *mac) -{ - esp_err_t ret = ESP_OK; - - emac_w5500_t *emac = __containerof(mac, emac_w5500_t, parent); - - esp_eth_mediator_t *eth = emac->eth; - esp_rom_gpio_pad_select_gpio(emac->int_gpio_num); - gpio_set_direction(emac->int_gpio_num, GPIO_MODE_INPUT); - gpio_set_pull_mode(emac->int_gpio_num, GPIO_PULLUP_ONLY); - gpio_set_intr_type(emac->int_gpio_num, GPIO_INTR_NEGEDGE); // active low - gpio_intr_enable(emac->int_gpio_num); - gpio_isr_handler_add(emac->int_gpio_num, w5500_isr_handler, emac); - - ESP_GOTO_ON_ERROR(eth->on_state_changed(eth, ETH_STATE_LLINIT, NULL), err, TAG, "Lowlevel init failed"); - - /* reset w5500 */ - ESP_GOTO_ON_ERROR(w5500_reset(emac), err, TAG, "Reset w5500 failed"); - - /* verify chip id */ - ESP_GOTO_ON_ERROR(w5500_verify_id(emac), err, TAG, "Verify chip ID failed"); - - /* default setup of internal registers */ - ESP_GOTO_ON_ERROR(w5500_setup_default(emac), err, TAG, "W5500 default setup failed"); - - return ESP_OK; - -err: - gpio_isr_handler_remove(emac->int_gpio_num); - gpio_reset_pin(emac->int_gpio_num); - eth->on_state_changed(eth, ETH_STATE_DEINIT, NULL); - - return ret; -} - -//////////////////////////////////////// - -static esp_err_t emac_w5500_deinit(esp_eth_mac_t *mac) -{ - emac_w5500_t *emac = __containerof(mac, emac_w5500_t, parent); - - esp_eth_mediator_t *eth = emac->eth; - mac->stop(mac); - gpio_isr_handler_remove(emac->int_gpio_num); - gpio_reset_pin(emac->int_gpio_num); - eth->on_state_changed(eth, ETH_STATE_DEINIT, NULL); - - return ESP_OK; -} - -//////////////////////////////////////// - -static esp_err_t emac_w5500_del(esp_eth_mac_t *mac) -{ - emac_w5500_t *emac = __containerof(mac, emac_w5500_t, parent); - - vTaskDelete(emac->rx_task_hdl); - vSemaphoreDelete(emac->spi_lock); - free(emac); - - return ESP_OK; -} - -//////////////////////////////////////// - -esp_eth_mac_t *esp_eth_mac_new_w5500(const eth_w5500_config_t *w5500_config, const eth_mac_config_t *mac_config) -{ - esp_eth_mac_t *ret = NULL; - emac_w5500_t *emac = NULL; - - ESP_GOTO_ON_FALSE(w5500_config && mac_config, NULL, err, TAG, "Invalid argument"); - - emac = calloc(1, sizeof(emac_w5500_t)); - ESP_GOTO_ON_FALSE(emac, NULL, err, TAG, "No mem for MAC instance"); - - /* w5500 driver is interrupt driven */ - ESP_GOTO_ON_FALSE(w5500_config->int_gpio_num >= 0, NULL, err, TAG, "Invalid interrupt gpio number"); - - /* bind methods and attributes */ - emac->sw_reset_timeout_ms = mac_config->sw_reset_timeout_ms; - emac->int_gpio_num = w5500_config->int_gpio_num; - emac->spi_hdl = w5500_config->spi_hdl; - emac->parent.set_mediator = emac_w5500_set_mediator; - emac->parent.init = emac_w5500_init; - emac->parent.deinit = emac_w5500_deinit; - emac->parent.start = emac_w5500_start; - emac->parent.stop = emac_w5500_stop; - emac->parent.del = emac_w5500_del; - emac->parent.write_phy_reg = emac_w5500_write_phy_reg; - emac->parent.read_phy_reg = emac_w5500_read_phy_reg; - emac->parent.set_addr = emac_w5500_set_addr; - emac->parent.get_addr = emac_w5500_get_addr; - emac->parent.set_speed = emac_w5500_set_speed; - emac->parent.set_duplex = emac_w5500_set_duplex; - emac->parent.set_link = emac_w5500_set_link; - emac->parent.set_promiscuous = emac_w5500_set_promiscuous; - emac->parent.set_peer_pause_ability = emac_w5500_set_peer_pause_ability; - emac->parent.enable_flow_ctrl = emac_w5500_enable_flow_ctrl; - emac->parent.transmit = emac_w5500_transmit; - emac->parent.receive = emac_w5500_receive; - - /* create mutex */ - emac->spi_lock = xSemaphoreCreateMutex(); - ESP_GOTO_ON_FALSE(emac->spi_lock, NULL, err, TAG, "Create lock failed"); - - /* create w5500 task */ - BaseType_t core_num = tskNO_AFFINITY; - - if (mac_config->flags & ETH_MAC_FLAG_PIN_TO_CORE) - { - core_num = cpu_hal_get_core_id(); - } - - BaseType_t xReturned = xTaskCreatePinnedToCore(emac_w5500_task, "w5500_tsk", mac_config->rx_task_stack_size, emac, - mac_config->rx_task_prio, &emac->rx_task_hdl, core_num); - ESP_GOTO_ON_FALSE(xReturned == pdPASS, NULL, err, TAG, "Create w5500 task failed"); - - return &(emac->parent); - -err: - - if (emac) - { - if (emac->rx_task_hdl) - { - vTaskDelete(emac->rx_task_hdl); - } - - if (emac->spi_lock) - { - vSemaphoreDelete(emac->spi_lock); - } - - free(emac); - } - - return ret; -} - -//////////////////////////////////////// - diff --git a/lib/AsyncWebServer_ESP32_W5500/src/w5500/esp_eth/esp_eth_phy_w5500.c b/lib/AsyncWebServer_ESP32_W5500/src/w5500/esp_eth/esp_eth_phy_w5500.c deleted file mode 100644 index ac34252..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/w5500/esp_eth/esp_eth_phy_w5500.c +++ /dev/null @@ -1,372 +0,0 @@ -/**************************************************************************************************************************** - esp_eth_phy_w5500.c - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - *****************************************************************************************************************************/ -// Copyright 2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//////////////////////////////////////// - - -#include -#include -#include -#include "esp_log.h" -#include "esp_check.h" -#include "esp_eth.h" -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "driver/gpio.h" -#include "esp_rom_gpio.h" -#include "esp_rom_sys.h" -#include "w5500.h" - -//////////////////////////////////////// - -static const char *TAG = "w5500.phy"; - -//////////////////////////////////////// - -/***************Vendor Specific Register***************/ -/** - @brief PHYCFGR(PHY Configuration Register) - -*/ -typedef union -{ - struct - { - uint8_t link: 1; /*!< Link status */ - uint8_t speed: 1; /*!< Speed status */ - uint8_t duplex: 1; /*!< Duplex status */ - uint8_t opmode: 3; /*!< Operation mode */ - uint8_t opsel: 1; /*!< Operation select */ - uint8_t reset: 1; /*!< Reset, when this bit is '0', PHY will get reset */ - }; - - uint8_t val; -} phycfg_reg_t; - -//////////////////////////////////////// - -typedef struct -{ - esp_eth_phy_t parent; - esp_eth_mediator_t *eth; - int addr; - uint32_t reset_timeout_ms; - uint32_t autonego_timeout_ms; - eth_link_t link_status; - int reset_gpio_num; -} phy_w5500_t; - -//////////////////////////////////////// - -static esp_err_t w5500_update_link_duplex_speed(phy_w5500_t *w5500) -{ - esp_err_t ret = ESP_OK; - - esp_eth_mediator_t *eth = w5500->eth; - eth_speed_t speed = ETH_SPEED_10M; - eth_duplex_t duplex = ETH_DUPLEX_HALF; - phycfg_reg_t phycfg; - - ESP_GOTO_ON_ERROR(eth->phy_reg_read(eth, w5500->addr, W5500_REG_PHYCFGR, (uint32_t *) & (phycfg.val)), err, TAG, - "Read PHYCFG failed"); - eth_link_t link = phycfg.link ? ETH_LINK_UP : ETH_LINK_DOWN; - - /* check if link status changed */ - if (w5500->link_status != link) - { - /* when link up, read negotiation result */ - if (link == ETH_LINK_UP) - { - if (phycfg.speed) - { - speed = ETH_SPEED_100M; - } - else - { - speed = ETH_SPEED_10M; - } - - if (phycfg.duplex) - { - duplex = ETH_DUPLEX_FULL; - } - else - { - duplex = ETH_DUPLEX_HALF; - } - - ESP_GOTO_ON_ERROR(eth->on_state_changed(eth, ETH_STATE_SPEED, (void *)speed), err, TAG, "Change speed failed"); - ESP_GOTO_ON_ERROR(eth->on_state_changed(eth, ETH_STATE_DUPLEX, (void *)duplex), err, TAG, "Change duplex failed"); - } - - ESP_GOTO_ON_ERROR(eth->on_state_changed(eth, ETH_STATE_LINK, (void *)link), err, TAG, "Change link failed"); - w5500->link_status = link; - } - - return ESP_OK; - -err: - return ret; -} - -//////////////////////////////////////// - -static esp_err_t w5500_set_mediator(esp_eth_phy_t *phy, esp_eth_mediator_t *eth) -{ - esp_err_t ret = ESP_OK; - - ESP_GOTO_ON_FALSE(eth, ESP_ERR_INVALID_ARG, err, TAG, "Can't set mediator to null"); - phy_w5500_t *w5500 = __containerof(phy, phy_w5500_t, parent); - w5500->eth = eth; - - return ESP_OK; - -err: - return ret; -} - -//////////////////////////////////////// - -static esp_err_t w5500_get_link(esp_eth_phy_t *phy) -{ - esp_err_t ret = ESP_OK; - - phy_w5500_t *w5500 = __containerof(phy, phy_w5500_t, parent); - - /* Updata information about link, speed, duplex */ - ESP_GOTO_ON_ERROR(w5500_update_link_duplex_speed(w5500), err, TAG, "Update link duplex speed failed"); - - return ESP_OK; - -err: - return ret; -} - -//////////////////////////////////////// - -static esp_err_t w5500_reset(esp_eth_phy_t *phy) -{ - esp_err_t ret = ESP_OK; - - phy_w5500_t *w5500 = __containerof(phy, phy_w5500_t, parent); - - w5500->link_status = ETH_LINK_DOWN; - esp_eth_mediator_t *eth = w5500->eth; - - phycfg_reg_t phycfg; - ESP_GOTO_ON_ERROR(eth->phy_reg_read(eth, w5500->addr, W5500_REG_PHYCFGR, (uint32_t *) & (phycfg.val)), err, TAG, - "Read PHYCFG failed"); - - phycfg.reset = 0; // set to '0' will reset internal PHY - ESP_GOTO_ON_ERROR(eth->phy_reg_write(eth, w5500->addr, W5500_REG_PHYCFGR, phycfg.val), err, TAG, "Write PHYCFG failed"); - - vTaskDelay(pdMS_TO_TICKS(10)); - - phycfg.reset = 1; // set to '1' after reset - ESP_GOTO_ON_ERROR(eth->phy_reg_write(eth, w5500->addr, W5500_REG_PHYCFGR, phycfg.val), err, TAG, "Write PHYCFG failed"); - - return ESP_OK; - -err: - return ret; -} - -//////////////////////////////////////// - -static esp_err_t w5500_reset_hw(esp_eth_phy_t *phy) -{ - phy_w5500_t *w5500 = __containerof(phy, phy_w5500_t, parent); - - // set reset_gpio_num to a negative value can skip hardware reset phy chip - if (w5500->reset_gpio_num >= 0) - { - esp_rom_gpio_pad_select_gpio(w5500->reset_gpio_num); - gpio_set_direction(w5500->reset_gpio_num, GPIO_MODE_OUTPUT); - gpio_set_level(w5500->reset_gpio_num, 0); - esp_rom_delay_us(100); // insert min input assert time - gpio_set_level(w5500->reset_gpio_num, 1); - } - - return ESP_OK; -} - -//////////////////////////////////////// - -static esp_err_t w5500_negotiate(esp_eth_phy_t *phy) -{ - esp_err_t ret = ESP_OK; - - phy_w5500_t *w5500 = __containerof(phy, phy_w5500_t, parent); - - esp_eth_mediator_t *eth = w5500->eth; - - /* in case any link status has changed, let's assume we're in link down status */ - w5500->link_status = ETH_LINK_DOWN; - phycfg_reg_t phycfg; - ESP_GOTO_ON_ERROR(eth->phy_reg_read(eth, w5500->addr, W5500_REG_PHYCFGR, (uint32_t *) & (phycfg.val)), err, TAG, - "Read PHYCFG failed"); - - phycfg.opsel = 1; // PHY working mode configured by register - phycfg.opmode = 7; // all capable, auto-negotiation enabled - ESP_GOTO_ON_ERROR(eth->phy_reg_write(eth, w5500->addr, W5500_REG_PHYCFGR, phycfg.val), err, TAG, "Write PHYCFG failed"); - - return ESP_OK; - -err: - return ret; -} - -//////////////////////////////////////// - -static esp_err_t w5500_pwrctl(esp_eth_phy_t *phy, bool enable) -{ - // power control is not supported for W5500 internal PHY - return ESP_OK; -} - -//////////////////////////////////////// - -static esp_err_t w5500_set_addr(esp_eth_phy_t *phy, uint32_t addr) -{ - phy_w5500_t *w5500 = __containerof(phy, phy_w5500_t, parent); - w5500->addr = addr; - - return ESP_OK; -} - -//////////////////////////////////////// - -static esp_err_t w5500_get_addr(esp_eth_phy_t *phy, uint32_t *addr) -{ - esp_err_t ret = ESP_OK; - - ESP_GOTO_ON_FALSE(addr, ESP_ERR_INVALID_ARG, err, TAG, "Addr can't be null"); - phy_w5500_t *w5500 = __containerof(phy, phy_w5500_t, parent); - *addr = w5500->addr; - - return ESP_OK; - -err: - return ret; -} - -//////////////////////////////////////// - -static esp_err_t w5500_del(esp_eth_phy_t *phy) -{ - phy_w5500_t *w5500 = __containerof(phy, phy_w5500_t, parent); - free(w5500); - - return ESP_OK; -} - -//////////////////////////////////////// - -static esp_err_t w5500_advertise_pause_ability(esp_eth_phy_t *phy, uint32_t ability) -{ - // pause ability advertisement is not supported for W5500 internal PHY - return ESP_OK; -} - -//////////////////////////////////////// - -static esp_err_t w5500_loopback(esp_eth_phy_t *phy, bool enable) -{ - // Loopback is not supported for W5500 internal PHY - return ESP_ERR_NOT_SUPPORTED; -} - -//////////////////////////////////////// - -static esp_err_t w5500_init(esp_eth_phy_t *phy) -{ - esp_err_t ret = ESP_OK; - - /* Power on Ethernet PHY */ - ESP_GOTO_ON_ERROR(w5500_pwrctl(phy, true), err, TAG, "Power control failed"); - - /* Reset Ethernet PHY */ - ESP_GOTO_ON_ERROR(w5500_reset(phy), err, TAG, "Reset failed"); - - return ESP_OK; - -err: - return ret; -} - -//////////////////////////////////////// - -static esp_err_t w5500_deinit(esp_eth_phy_t *phy) -{ - esp_err_t ret = ESP_OK; - - /* Power off Ethernet PHY */ - ESP_GOTO_ON_ERROR(w5500_pwrctl(phy, false), err, TAG, "Power control failed"); - - return ESP_OK; - -err: - return ret; -} - -//////////////////////////////////////// - -esp_eth_phy_t *esp_eth_phy_new_w5500(const eth_phy_config_t *config) -{ - esp_eth_phy_t *ret = NULL; - - ESP_GOTO_ON_FALSE(config, NULL, err, TAG, "Invalid arguments"); - - phy_w5500_t *w5500 = calloc(1, sizeof(phy_w5500_t)); - ESP_GOTO_ON_FALSE(w5500, NULL, err, TAG, "No mem for PHY instance"); - - /* bind methods and attributes */ - w5500->addr = config->phy_addr; - w5500->reset_timeout_ms = config->reset_timeout_ms; - w5500->reset_gpio_num = config->reset_gpio_num; - w5500->link_status = ETH_LINK_DOWN; - w5500->autonego_timeout_ms = config->autonego_timeout_ms; - w5500->parent.reset = w5500_reset; - w5500->parent.reset_hw = w5500_reset_hw; - w5500->parent.init = w5500_init; - w5500->parent.deinit = w5500_deinit; - w5500->parent.set_mediator = w5500_set_mediator; - w5500->parent.negotiate = w5500_negotiate; - w5500->parent.get_link = w5500_get_link; - w5500->parent.pwrctl = w5500_pwrctl; - w5500->parent.get_addr = w5500_get_addr; - w5500->parent.set_addr = w5500_set_addr; - w5500->parent.advertise_pause_ability = w5500_advertise_pause_ability; - w5500->parent.loopback = w5500_loopback; - w5500->parent.del = w5500_del; - - return &(w5500->parent); - -err: - return ret; -} - -//////////////////////////////////////// - diff --git a/lib/AsyncWebServer_ESP32_W5500/src/w5500/esp_eth/esp_eth_spi_w5500.c b/lib/AsyncWebServer_ESP32_W5500/src/w5500/esp_eth/esp_eth_spi_w5500.c deleted file mode 100644 index c0dd1e1..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/w5500/esp_eth/esp_eth_spi_w5500.c +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************************************************************** - esp_eth_spi_w5500.c - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - *****************************************************************************************************************************/ - -#include -#include -#include "sdkconfig.h" -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "esp_netif.h" -#include "esp_eth.h" -#include "esp_event.h" -#include "driver/gpio.h" -#include "esp_eth_w5500.h" -#include "driver/spi_master.h" - -#include "esp_log.h" -#include "esp_check.h" - -static const char *TAG = "w5500.spi"; - -//////////////////////////////////////// - -esp_eth_mac_t* w5500_new_mac( spi_device_handle_t *spi_handle, int INT_GPIO ) -{ - eth_w5500_config_t w5500_config = ETH_W5500_DEFAULT_CONFIG( *spi_handle ); - w5500_config.int_gpio_num = INT_GPIO; - - eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG(); - - //eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG(); - //phy_config.reset_gpio_num = -1; - - mac_config.smi_mdc_gpio_num = -1; // w5500 doesn't have SMI interface - mac_config.smi_mdio_gpio_num = -1; - mac_config.rx_task_prio = 1; - - return esp_eth_mac_new_w5500( &w5500_config, &mac_config ); -} - -//////////////////////////////////////// - -esp_eth_mac_t* w5500_begin(int MISO_GPIO, int MOSI_GPIO, int SCLK_GPIO, int CS_GPIO, int INT_GPIO, int SPICLOCK_MHZ, - int SPIHOST) -{ - if (ESP_OK != gpio_install_isr_service(0)) - { - ESP_LOGE(TAG, "%s(%d): Error gpio_install_isr_service", __FUNCTION__, __LINE__); - - return NULL; - } - - /* w5500 ethernet driver is based on spi driver */ - spi_bus_config_t buscfg = - { - .miso_io_num = MISO_GPIO, - .mosi_io_num = MOSI_GPIO, - .sclk_io_num = SCLK_GPIO, - .quadwp_io_num = -1, - .quadhd_io_num = -1, - }; - - if ( ESP_OK != spi_bus_initialize( SPIHOST, &buscfg, 1 )) - { - ESP_LOGE(TAG, "%s(%d): Error spi_bus_initialize", __FUNCTION__, __LINE__); - - return NULL; - } - - spi_device_interface_config_t devcfg = - { - .command_bits = 16, - .address_bits = 8, - .mode = 0, - .clock_speed_hz = SPICLOCK_MHZ * 1000 * 1000, - .spics_io_num = CS_GPIO, - .queue_size = 20, - .cs_ena_posttrans = w5500_cal_spi_cs_hold_time(SPICLOCK_MHZ), - }; - - spi_device_handle_t spi_handle = NULL; - - if (ESP_OK != spi_bus_add_device( SPIHOST, &devcfg, &spi_handle )) - { - ESP_LOGE(TAG, "%s(%d): Error spi_bus_add_device", __FUNCTION__, __LINE__); - - return NULL; - } - - return w5500_new_mac( &spi_handle, INT_GPIO ); -} - -//////////////////////////////////////// - diff --git a/lib/AsyncWebServer_ESP32_W5500/src/w5500/esp_eth/esp_eth_w5500.h b/lib/AsyncWebServer_ESP32_W5500/src/w5500/esp_eth/esp_eth_w5500.h deleted file mode 100644 index 30b22a5..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/w5500/esp_eth/esp_eth_w5500.h +++ /dev/null @@ -1,138 +0,0 @@ -/**************************************************************************************************************************** - esp_eth_w5500.h - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - *****************************************************************************************************************************/ - -// Copyright 2021 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -//////////////////////////////////////// - -#include "esp_eth_phy.h" -#include "esp_eth_mac.h" -#include "driver/spi_master.h" - -//////////////////////////////////////// - -#define CS_HOLD_TIME_MIN_NS 210 - -//////////////////////////////////////// - -/* - // From tools/sdk/esp32/include/esp_eth/include/esp_eth_mac.h - - typedef struct - { - void *spi_hdl; //!< Handle of SPI device driver - int int_gpio_num; //!< Interrupt GPIO number - } eth_w5500_config_t; - - - #define ETH_W5500_DEFAULT_CONFIG(spi_device) \ - { \ - .spi_hdl = spi_device, \ - .int_gpio_num = 4, \ - } - -*/ - - -//////////////////////////////////////// - -/** - @brief Compute amount of SPI bit-cycles the CS should stay active after the transmission - to meet w5500 CS Hold Time specification. - - @param clock_speed_mhz SPI Clock frequency in MHz (valid range is <1, 20>) - @return uint8_t -*/ -static inline uint8_t w5500_cal_spi_cs_hold_time(int clock_speed_mhz) -{ - if (clock_speed_mhz <= 0 || clock_speed_mhz > 20) - { - return 0; - } - - int temp = clock_speed_mhz * CS_HOLD_TIME_MIN_NS; - uint8_t cs_posttrans = temp / 1000; - - if (temp % 1000) - { - cs_posttrans += 1; - } - - return cs_posttrans; -} - -//////////////////////////////////////// - -/** - @brief Create w5500 Ethernet MAC instance - - @param[in] w5500_config: w5500 specific configuration - @param[in] mac_config: Ethernet MAC configuration - - @return - - instance: create MAC instance successfully - - NULL: create MAC instance failed because some error occurred -*/ -esp_eth_mac_t *esp_eth_mac_new_w5500(const eth_w5500_config_t *w5500_config, - const eth_mac_config_t *mac_config); - -//////////////////////////////////////// - -/** - @brief Create a PHY instance of w5500 - - @param[in] config: configuration of PHY - - @return - - instance: create PHY instance successfully - - NULL: create PHY instance failed because some error occurred -*/ -esp_eth_phy_t *esp_eth_phy_new_w5500(const eth_phy_config_t *config); - -//////////////////////////////////////// - -// todo: the below functions should be accessed through ioctl in the future -/** - @brief Set w5500 Duplex mode. It sets Duplex mode first to the PHY and then - MAC is set based on what PHY indicates. - - @param phy w5500 PHY Handle - @param duplex Duplex mode - - @return esp_err_t - - ESP_OK when PHY registers were correctly written. -*/ -esp_err_t w5500_set_phy_duplex(esp_eth_phy_t *phy, eth_duplex_t duplex); - -//////////////////////////////////////// - -#ifdef __cplusplus -} -#endif diff --git a/lib/AsyncWebServer_ESP32_W5500/src/w5500/esp_eth/w5500.h b/lib/AsyncWebServer_ESP32_W5500/src/w5500/esp_eth/w5500.h deleted file mode 100644 index 04e9d3b..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/src/w5500/esp_eth/w5500.h +++ /dev/null @@ -1,118 +0,0 @@ -/**************************************************************************************************************************** - w5500.h - - For W5500 LwIP Ethernet in ESP32 (ESP32 + W5500) - - AsyncWebServer_ESP32_W5500 is a library for the LwIP Ethernet W5500 in ESP32 to run AsyncWebServer - - Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer) - Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_ESP32_W5500 - Licensed under GPLv3 license - *****************************************************************************************************************************/ - -// Copyright 2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//////////////////////////////////////// - -#define W5500_ADDR_OFFSET (16) // Address length -#define W5500_BSB_OFFSET (3) // Block Select Bits offset -#define W5500_RWB_OFFSET (2) // Read Write Bits offset - -//////////////////////////////////////// - -#define W5500_BSB_COM_REG (0x00) // Common Register -#define W5500_BSB_SOCK_REG(s) ((s)*4+1) // Socket Register -#define W5500_BSB_SOCK_TX_BUF(s) ((s)*4+2) // Socket TX Buffer -#define W5500_BSB_SOCK_RX_BUF(s) ((s)*4+3) // Socket RX Buffer - -//////////////////////////////////////// - -#define W5500_ACCESS_MODE_READ (0) // Read Mode -#define W5500_ACCESS_MODE_WRITE (1) // Write Mode - -//////////////////////////////////////// - -#define W5500_SPI_OP_MODE_VDM (0x00) // Variable Data Length Mode (SPI frame is controlled by CS line) -#define W5500_SPI_OP_MODE_FDM_1 (0x01) // Fixed Data Length Mode, 1 Byte Length -#define W5500_SPI_OP_MODE_FDM_2 (0x02) // Fixed Data Length Mode, 2 Bytes Length -#define W5500_SPI_OP_MODE_FDM_4 (0x03) // Fixed Data Length Mode, 4 Bytes Length - -//////////////////////////////////////// - -#define W5500_MAKE_MAP(offset, bsb) ((offset) << W5500_ADDR_OFFSET | (bsb) << W5500_BSB_OFFSET) - -//////////////////////////////////////// - -#define W5500_REG_MR W5500_MAKE_MAP(0x0000, W5500_BSB_COM_REG) // Mode -#define W5500_REG_MAC W5500_MAKE_MAP(0x0009, W5500_BSB_COM_REG) // MAC Address -#define W5500_REG_INTLEVEL W5500_MAKE_MAP(0x0013, W5500_BSB_COM_REG) // Interrupt Level Timeout -#define W5500_REG_IR W5500_MAKE_MAP(0x0015, W5500_BSB_COM_REG) // Interrupt -#define W5500_REG_IMR W5500_MAKE_MAP(0x0016, W5500_BSB_COM_REG) // Interrupt Mask -#define W5500_REG_SIR W5500_MAKE_MAP(0x0017, W5500_BSB_COM_REG) // Socket Interrupt -#define W5500_REG_SIMR W5500_MAKE_MAP(0x0018, W5500_BSB_COM_REG) // Socket Interrupt Mask -#define W5500_REG_RTR W5500_MAKE_MAP(0x0019, W5500_BSB_COM_REG) // Retry Time -#define W5500_REG_RCR W5500_MAKE_MAP(0x001B, W5500_BSB_COM_REG) // Retry Count -#define W5500_REG_PHYCFGR W5500_MAKE_MAP(0x002E, W5500_BSB_COM_REG) // PHY Configuration -#define W5500_REG_VERSIONR W5500_MAKE_MAP(0x0039, W5500_BSB_COM_REG) // Chip version - -//////////////////////////////////////// - -#define W5500_REG_SOCK_MR(s) W5500_MAKE_MAP(0x0000, W5500_BSB_SOCK_REG(s)) // Socket Mode -#define W5500_REG_SOCK_CR(s) W5500_MAKE_MAP(0x0001, W5500_BSB_SOCK_REG(s)) // Socket Command -#define W5500_REG_SOCK_IR(s) W5500_MAKE_MAP(0x0002, W5500_BSB_SOCK_REG(s)) // Socket Interrupt -#define W5500_REG_SOCK_SR(s) W5500_MAKE_MAP(0x0004, W5500_BSB_SOCK_REG(s)) // Socket Status -#define W5500_REG_SOCK_RXBUF_SIZE(s) W5500_MAKE_MAP(0x001E, W5500_BSB_SOCK_REG(s)) // Socket Receive Buffer Size -#define W5500_REG_SOCK_TXBUF_SIZE(s) W5500_MAKE_MAP(0x001F, W5500_BSB_SOCK_REG(s)) // Socket Transmit Buffer Size -#define W5500_REG_SOCK_TX_FSR(s) W5500_MAKE_MAP(0x0020, W5500_BSB_SOCK_REG(s)) // Socket TX Free Size -#define W5500_REG_SOCK_TX_RD(s) W5500_MAKE_MAP(0x0022, W5500_BSB_SOCK_REG(s)) // Socket TX Read Pointer -#define W5500_REG_SOCK_TX_WR(s) W5500_MAKE_MAP(0x0024, W5500_BSB_SOCK_REG(s)) // Socket TX Write Pointer -#define W5500_REG_SOCK_RX_RSR(s) W5500_MAKE_MAP(0x0026, W5500_BSB_SOCK_REG(s)) // Socket RX Received Size -#define W5500_REG_SOCK_RX_RD(s) W5500_MAKE_MAP(0x0028, W5500_BSB_SOCK_REG(s)) // Socket RX Read Pointer -#define W5500_REG_SOCK_RX_WR(s) W5500_MAKE_MAP(0x002A, W5500_BSB_SOCK_REG(s)) // Socket RX Write Pointer -#define W5500_REG_SOCK_IMR(s) W5500_MAKE_MAP(0x002C, W5500_BSB_SOCK_REG(s)) // Socket Interrupt Mask - -//////////////////////////////////////// - -#define W5500_MEM_SOCK_TX(s,addr) W5500_MAKE_MAP(addr, W5500_BSB_SOCK_TX_BUF(s)) // Socket TX buffer address -#define W5500_MEM_SOCK_RX(s,addr) W5500_MAKE_MAP(addr, W5500_BSB_SOCK_RX_BUF(s)) // Socket RX buffer address - -//////////////////////////////////////// - -#define W5500_MR_RST (1<<7) // Software reset -#define W5500_MR_PB (1<<4) // Ping block (block the response to a ping request) - -//////////////////////////////////////// - -#define W5500_SIMR_SOCK0 (1<<0) // Socket 0 interrupt - -//////////////////////////////////////// - -#define W5500_SMR_MAC_RAW (1<<2) // MAC RAW mode -#define W5500_SMR_MAC_FILTER (1<<7) // MAC filter - -//////////////////////////////////////// - -#define W5500_SCR_OPEN (0x01) // Open command -#define W5500_SCR_CLOSE (0x10) // Close command -#define W5500_SCR_SEND (0x20) // Send command -#define W5500_SCR_RECV (0x40) // Recv command - -//////////////////////////////////////// - -#define W5500_SIR_RECV (1<<2) // Receive done -#define W5500_SIR_SEND (1<<4) // Send done - -//////////////////////////////////////// - diff --git a/lib/AsyncWebServer_ESP32_W5500/utils/astyle_library.conf b/lib/AsyncWebServer_ESP32_W5500/utils/astyle_library.conf deleted file mode 100644 index 8a73bc2..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/utils/astyle_library.conf +++ /dev/null @@ -1,70 +0,0 @@ -# Code formatting rules for Arduino libraries, modified from for KH libraries: -# -# https://github.com/arduino/Arduino/blob/master/build/shared/examples_formatter.conf -# - -# astyle --style=allman -s2 -t2 -C -S -xW -Y -M120 -f -p -xg -H -xb -c --xC120 -xL *.h *.cpp *.ino - ---mode=c ---lineend=linux ---style=allman - -# -r or -R -#--recursive - -# -c => Converts tabs into spaces -convert-tabs - -# -s2 => 2 spaces indentation ---indent=spaces=2 - -# -t2 => tab =2 spaces -#--indent=tab=2 - -# -C ---indent-classes - -# -S ---indent-switches - -# -xW ---indent-preproc-block - -# -Y => indent classes, switches (and cases), comments starting at column 1 ---indent-col1-comments - -# -M120 => maximum of 120 spaces to indent a continuation line ---max-continuation-indent=120 - -# -xC120 => max‑code‑length will break a line if the code exceeds # characters ---max-code-length=120 - -# -f => ---break-blocks - -# -p => put a space around operators ---pad-oper - -# -xg => Insert space padding after commas ---pad-comma - -# -H => put a space after if/for/while -pad-header - -# -xb => Break one line headers (e.g. if/for/while) ---break-one-line-headers - -# -c => Converts tabs into spaces -#--convert-tabs - -# if you like one-liners, keep them -#keep-one-line-statements - -# -xV ---attach-closing-while - -#unpad-paren - -# -xp -remove-comment-prefix - diff --git a/lib/AsyncWebServer_ESP32_W5500/utils/restyle.sh b/lib/AsyncWebServer_ESP32_W5500/utils/restyle.sh deleted file mode 100644 index bcd846f..0000000 --- a/lib/AsyncWebServer_ESP32_W5500/utils/restyle.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -for dir in . ; do - find $dir -type f \( -name "*.c" -o -name "*.h" -o -name "*.cpp" -o -name "*.ino" \) -exec astyle --suffix=none --options=./utils/astyle_library.conf \{\} \; -done -