Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Commit

Permalink
v1.5.0 to fix AsyncWebSocket bug
Browse files Browse the repository at this point in the history
#### Releases v1.5.0

1. Fix AsyncWebSocket bug
  • Loading branch information
khoih-prog authored Oct 1, 2022
1 parent 6ca7b3e commit 5829a7e
Show file tree
Hide file tree
Showing 35 changed files with 2,597 additions and 248 deletions.
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ If you don't find anything, please [open a new issue](https://github.com/khoih-p
Please ensure to specify the following:

* Arduino IDE version (e.g. 1.8.16) or Platform.io version
* Board Core Version (e.g. ESP32 core v2.0.1)
* Board Core Version (e.g. ESP32 core v2.0.5)
* 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:
Expand All @@ -26,14 +26,14 @@ Please ensure to specify the following:
### Example

```
Arduino IDE version: 1.8.16
Arduino IDE version: 1.8.19
WT32_ETH01 board
ESP32 core v2.0.1
ESP32 core v2.0.5
OS: Ubuntu 20.04 LTS
Linux xy-Inspiron-3593 5.4.0-90-generic #101-Ubuntu SMP Fri Oct 15 20:00:55 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Linux xy-Inspiron-3593 5.15.0-48-generic #54~20.04.1-Ubuntu SMP Thu Sep 1 16:17:26 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Context:
I encountered a crash while trying to use the Timer Interrupt.
I encountered a crash while trying to use this library
Steps to reproduce:
1. ...
Expand Down
250 changes: 53 additions & 197 deletions README.md

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
## Table of contents

* [Changelog](#changelog)
* [Releases v1.5.0](#releases-v150)
* [Releases v1.4.1](#releases-v141)
* [Releases v1.4.0](#releases-v140)
* [Releases v1.3.0](#releases-v130)
Expand All @@ -24,6 +25,10 @@

## Changelog

#### Releases v1.5.0

1. Fix AsyncWebSocket bug

#### Releases v1.4.1

1. Fix bug in examples to reduce connection time
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name":"AsyncWebServer_WT32_ETH01",
"version": "1.4.1",
"version": "1.5.0",
"description":"Asynchronous HTTP and WebSocket Server Library for WT32_ETH01 (ESP32 + LAN8720)",
"keywords":"http, async, async-webserver, websocket, webserver, esp32, wt32-eth01, lan8720, lan8720a",
"authors":
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=AsyncWebServer_WT32_ETH01
version=1.4.1
version=1.5.0
author=Hristo Gochkov,Khoi Hoang
maintainer=Khoi Hoang <[email protected]>
license=GPLv3
Expand Down
3 changes: 2 additions & 1 deletion src/AsyncEventSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
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.4.1
Version: 1.5.0
Version Modified By Date Comments
------- ----------- ---------- -----------
Expand All @@ -32,6 +32,7 @@
1.3.0 K Hoang 23/10/2021 Making compatible with breaking core v2.0.0+
1.4.0 K Hoang 27/11/2021 Auto detect ESP32 core version
1.4.1 K Hoang 29/11/2021 Fix bug in examples to reduce connection time
1.5.0 K Hoang 01/10/2022 Fix AsyncWebSocket bug
*****************************************************************************************************************************/

#include "Arduino.h"
Expand Down
3 changes: 2 additions & 1 deletion src/AsyncEventSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
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.4.1
Version: 1.5.0
Version Modified By Date Comments
------- ----------- ---------- -----------
Expand All @@ -32,6 +32,7 @@
1.3.0 K Hoang 23/10/2021 Making compatible with breaking core v2.0.0+
1.4.0 K Hoang 27/11/2021 Auto detect ESP32 core version
1.4.1 K Hoang 29/11/2021 Fix bug in examples to reduce connection time
1.5.0 K Hoang 01/10/2022 Fix AsyncWebSocket bug
*****************************************************************************************************************************/

#ifndef ASYNCEVENTSOURCE_H_
Expand Down
3 changes: 2 additions & 1 deletion src/AsyncJson.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
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.4.1
Version: 1.5.0
Version Modified By Date Comments
------- ----------- ---------- -----------
Expand All @@ -32,6 +32,7 @@
1.3.0 K Hoang 23/10/2021 Making compatible with breaking core v2.0.0+
1.4.0 K Hoang 27/11/2021 Auto detect ESP32 core version
1.4.1 K Hoang 29/11/2021 Fix bug in examples to reduce connection time
1.5.0 K Hoang 01/10/2022 Fix AsyncWebSocket bug
*****************************************************************************************************************************/
/*
Async Response to use with ArduinoJson and AsyncWebServer
Expand Down
3 changes: 2 additions & 1 deletion src/AsyncWebServer_WT32_ETH01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
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.4.1
Version: 1.5.0
Version Modified By Date Comments
------- ----------- ---------- -----------
Expand All @@ -32,6 +32,7 @@
1.3.0 K Hoang 23/10/2021 Making compatible with breaking core v2.0.0+
1.4.0 K Hoang 27/11/2021 Auto detect ESP32 core version
1.4.1 K Hoang 29/11/2021 Fix bug in examples to reduce connection time
1.5.0 K Hoang 01/10/2022 Fix AsyncWebSocket bug
*****************************************************************************************************************************/

#include "AsyncWebServer_WT32_ETH01.h"
Expand Down
7 changes: 4 additions & 3 deletions src/AsyncWebServer_WT32_ETH01.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
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.4.1
Version: 1.5.0
Version Modified By Date Comments
------- ----------- ---------- -----------
Expand All @@ -32,6 +32,7 @@
1.3.0 K Hoang 23/10/2021 Making compatible with breaking core v2.0.0+
1.4.0 K Hoang 27/11/2021 Auto detect ESP32 core version
1.4.1 K Hoang 29/11/2021 Fix bug in examples to reduce connection time
1.5.0 K Hoang 01/10/2022 Fix AsyncWebSocket bug
*****************************************************************************************************************************/

#ifndef _AsyncWebServer_WT32_ETH01_H_
Expand All @@ -55,14 +56,14 @@
#warning Using code for ESP32 core v2.0.0+ in AsyncWebServer_WT32_ETH01.h
#endif

#define ASYNC_WEBSERVER_WT32_ETH01_VERSION "AsyncWebServer_WT32_ETH01 v1.4.1 for core v2.0.0+"
#define ASYNC_WEBSERVER_WT32_ETH01_VERSION "AsyncWebServer_WT32_ETH01 v1.5.0 for core v2.0.0+"
#else

#if (_ASYNC_WEBSERVER_LOGLEVEL_ > 2 )
#warning Using code for ESP32 core v1.0.6- in AsyncWebServer_WT32_ETH01.h
#endif

#define ASYNC_WEBSERVER_WT32_ETH01_VERSION "AsyncWebServer_WT32_ETH01 v1.4.1 for core v1.0.6-"
#define ASYNC_WEBSERVER_WT32_ETH01_VERSION "AsyncWebServer_WT32_ETH01 v1.5.0 for core v1.0.6-"
#endif


Expand Down
3 changes: 2 additions & 1 deletion src/AsyncWebServer_WT32_ETH01_Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
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.4.1
Version: 1.5.0
Version Modified By Date Comments
------- ----------- ---------- -----------
Expand All @@ -32,6 +32,7 @@
1.3.0 K Hoang 23/10/2021 Making compatible with breaking core v2.0.0+
1.4.0 K Hoang 27/11/2021 Auto detect ESP32 core version
1.4.1 K Hoang 29/11/2021 Fix bug in examples to reduce connection time
1.5.0 K Hoang 01/10/2022 Fix AsyncWebSocket bug
*****************************************************************************************************************************/

#pragma once
Expand Down
41 changes: 18 additions & 23 deletions src/AsyncWebSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
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.4.1
Version: 1.5.0
Version Modified By Date Comments
------- ----------- ---------- -----------
Expand All @@ -32,27 +32,16 @@
1.3.0 K Hoang 23/10/2021 Making compatible with breaking core v2.0.0+
1.4.0 K Hoang 27/11/2021 Auto detect ESP32 core version
1.4.1 K Hoang 29/11/2021 Fix bug in examples to reduce connection time
1.5.0 K Hoang 01/10/2022 Fix AsyncWebSocket bug
*****************************************************************************************************************************/

#include "Arduino.h"
#include "AsyncWebSocket.h"

#include <libb64/cencode.h>

extern "C"
{
typedef struct
{
uint32_t state[5];
uint32_t count[2];
unsigned char buffer[64];
} SHA1_CTX;

void SHA1Transform(uint32_t state[5], const unsigned char buffer[64]);
void SHA1Init(SHA1_CTX* context);
void SHA1Update(SHA1_CTX* context, const unsigned char* data, uint32_t len);
void SHA1Final(unsigned char digest[20], SHA1_CTX* context);
}
#include "Crypto/sha1.h"
#include "Crypto/Hash.h"

#define MAX_PRINTF_LEN 64

Expand Down Expand Up @@ -1653,13 +1642,13 @@ AsyncWebSocket::AsyncWebSocketClientLinkedList AsyncWebSocket::getClients() cons
Authentication code from https://github.com/Links2004/arduinoWebSockets/blob/master/src/WebSockets.cpp#L480
*/

AsyncWebSocketResponse::AsyncWebSocketResponse(const String& key, AsyncWebSocket *server)
AsyncWebSocketResponse::AsyncWebSocketResponse(const String & key, AsyncWebSocket * server)
{
_server = server;
_code = 101;
_sendContentLength = false;

uint8_t * hash = (uint8_t*)malloc(20);
uint8_t * hash = (uint8_t*) malloc(HASH_BUFFER_SIZE);

if (hash == NULL)
{
Expand All @@ -1676,23 +1665,29 @@ AsyncWebSocketResponse::AsyncWebSocketResponse(const String& key, AsyncWebSocket
return;
}

(String&)key += WS_STR_UUID;
SHA1_CTX ctx;
SHA1Init(&ctx);
SHA1Update(&ctx, (const unsigned char*)key.c_str(), key.length());
SHA1Final(hash, &ctx);
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, 20, buffer, &_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)
Expand Down
3 changes: 2 additions & 1 deletion src/AsyncWebSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
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.4.1
Version: 1.5.0
Version Modified By Date Comments
------- ----------- ---------- -----------
Expand All @@ -32,6 +32,7 @@
1.3.0 K Hoang 23/10/2021 Making compatible with breaking core v2.0.0+
1.4.0 K Hoang 27/11/2021 Auto detect ESP32 core version
1.4.1 K Hoang 29/11/2021 Fix bug in examples to reduce connection time
1.5.0 K Hoang 01/10/2022 Fix AsyncWebSocket bug
*****************************************************************************************************************************/

#ifndef ASYNCWEBSOCKET_H_
Expand Down
3 changes: 2 additions & 1 deletion src/AsyncWebSynchronization.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
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.4.1
Version: 1.5.0
Version Modified By Date Comments
------- ----------- ---------- -----------
Expand All @@ -32,6 +32,7 @@
1.3.0 K Hoang 23/10/2021 Making compatible with breaking core v2.0.0+
1.4.0 K Hoang 27/11/2021 Auto detect ESP32 core version
1.4.1 K Hoang 29/11/2021 Fix bug in examples to reduce connection time
1.5.0 K Hoang 01/10/2022 Fix AsyncWebSocket bug
*****************************************************************************************************************************/

#ifndef ASYNCWEBSYNCHRONIZATION_H_
Expand Down
Loading

0 comments on commit 5829a7e

Please sign in to comment.