Skip to content

Commit 57a77e1

Browse files
authored
Merge pull request #2 from agners/fix-build-with-arduino-esp32-2.0.0-rc1
2 parents 32ab7bd + 468ac18 commit 57a77e1

File tree

5 files changed

+38
-23
lines changed

5 files changed

+38
-23
lines changed

src/AsyncJson.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
#if ARDUINOJSON_VERSION_MAJOR == 5
4242
#define ARDUINOJSON_5_COMPATIBILITY
4343
#else
44-
#define DYNAMIC_JSON_DOCUMENT_SIZE 1024
44+
#ifndef DYNAMIC_JSON_DOCUMENT_SIZE
45+
#define DYNAMIC_JSON_DOCUMENT_SIZE 1024
46+
#endif
4547
#endif
4648

4749
constexpr const char* JSON_MIMETYPE = "application/json";

src/AsyncWebSocket.cpp

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,7 @@
2424
#include <libb64/cencode.h>
2525

2626
#ifndef ESP8266
27-
extern "C" {
28-
typedef struct {
29-
uint32_t state[5];
30-
uint32_t count[2];
31-
unsigned char buffer[64];
32-
} SHA1_CTX;
33-
34-
void SHA1Transform(uint32_t state[5], const unsigned char buffer[64]);
35-
void SHA1Init(SHA1_CTX* context);
36-
void SHA1Update(SHA1_CTX* context, const unsigned char* data, uint32_t len);
37-
void SHA1Final(unsigned char digest[20], SHA1_CTX* context);
38-
}
27+
#include "mbedtls/sha1.h"
3928
#else
4029
#include <Hash.h>
4130
#endif
@@ -837,7 +826,7 @@ void AsyncWebSocketClient::binary(AsyncWebSocketMessageBuffer * buffer)
837826

838827
IPAddress AsyncWebSocketClient::remoteIP() {
839828
if(!_client) {
840-
return IPAddress(0U);
829+
return IPAddress((uint32_t)0);
841830
}
842831
return _client->remoteIP();
843832
}
@@ -1265,10 +1254,12 @@ AsyncWebSocketResponse::AsyncWebSocketResponse(const String& key, AsyncWebSocket
12651254
sha1(key + WS_STR_UUID, hash);
12661255
#else
12671256
(String&)key += WS_STR_UUID;
1268-
SHA1_CTX ctx;
1269-
SHA1Init(&ctx);
1270-
SHA1Update(&ctx, (const unsigned char*)key.c_str(), key.length());
1271-
SHA1Final(hash, &ctx);
1257+
mbedtls_sha1_context ctx;
1258+
mbedtls_sha1_init(&ctx);
1259+
mbedtls_sha1_starts_ret(&ctx);
1260+
mbedtls_sha1_update_ret(&ctx, (const unsigned char*)key.c_str(), key.length());
1261+
mbedtls_sha1_finish_ret(&ctx, hash);
1262+
mbedtls_sha1_free(&ctx);
12721263
#endif
12731264
base64_encodestate _state;
12741265
base64_init_encodestate(&_state);

src/StringArray.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,19 @@ class LinkedList {
4747

4848
class Iterator {
4949
ItemType* _node;
50+
ItemType* _nextNode = nullptr;
5051
public:
51-
Iterator(ItemType* current = nullptr) : _node(current) {}
52+
Iterator(ItemType* current = nullptr) : _node(current) {
53+
if (_node != nullptr) {
54+
_nextNode = current->next;
55+
}
56+
}
5257
Iterator(const Iterator& i) : _node(i._node) {}
53-
Iterator& operator ++() { _node = _node->next; return *this; }
58+
Iterator& operator ++() {
59+
_node = _nextNode;
60+
_nextNode = _node != nullptr ? _node->next : nullptr;
61+
return *this;
62+
}
5463
bool operator != (const Iterator& i) const { return _node != i._node; }
5564
const T& operator * () const { return _node->value(); }
5665
const T* operator -> () const { return &_node->value(); }

src/WebAuthentication.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ static bool getMD5(uint8_t * data, uint16_t len, char * output){//33 bytes or mo
7171
memset(_buf, 0x00, 16);
7272
#ifdef ESP32
7373
mbedtls_md5_init(&_ctx);
74-
mbedtls_md5_starts(&_ctx);
75-
mbedtls_md5_update(&_ctx, data, len);
76-
mbedtls_md5_finish(&_ctx, _buf);
74+
mbedtls_md5_starts_ret(&_ctx);
75+
mbedtls_md5_update_ret(&_ctx, data, len);
76+
mbedtls_md5_finish_ret(&_ctx, _buf);
7777
#else
7878
MD5Init(&_ctx);
7979
MD5Update(&_ctx, data, len);

src/WebHandlerImpl.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ class AsyncCallbackWebHandler: public AsyncWebHandler {
105105
}
106106
} else
107107
#endif
108+
if (_uri.length() && _uri.startsWith("/*.")) {
109+
String uriTemplate = String (_uri);
110+
uriTemplate = uriTemplate.substring(uriTemplate.lastIndexOf("."));
111+
if (!request->url().endsWith(uriTemplate))
112+
return false;
113+
}
114+
else
108115
if (_uri.length() && _uri.endsWith("*")) {
109116
String uriTemplate = String(_uri);
110117
uriTemplate = uriTemplate.substring(0, uriTemplate.length() - 1);
@@ -119,16 +126,22 @@ class AsyncCallbackWebHandler: public AsyncWebHandler {
119126
}
120127

121128
virtual void handleRequest(AsyncWebServerRequest *request) override final {
129+
if((_username != "" && _password != "") && !request->authenticate(_username.c_str(), _password.c_str()))
130+
return request->requestAuthentication();
122131
if(_onRequest)
123132
_onRequest(request);
124133
else
125134
request->send(500);
126135
}
127136
virtual void handleUpload(AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data, size_t len, bool final) override final {
137+
if((_username != "" && _password != "") && !request->authenticate(_username.c_str(), _password.c_str()))
138+
return request->requestAuthentication();
128139
if(_onUpload)
129140
_onUpload(request, filename, index, data, len, final);
130141
}
131142
virtual void handleBody(AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total) override final {
143+
if((_username != "" && _password != "") && !request->authenticate(_username.c_str(), _password.c_str()))
144+
return request->requestAuthentication();
132145
if(_onBody)
133146
_onBody(request, data, len, index, total);
134147
}

0 commit comments

Comments
 (0)