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

Fix base64 encoding of websocket client key and progmem support for webserver #7

Merged
merged 1 commit into from
Dec 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions src/AsyncWebRequest_STM32.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/****************************************************************************************************************************
AsyncWebRequest_STM32.cpp - Dead simple AsyncWebServer for STM32 LAN8720 or built-in LAN8742A Ethernet

For STM32 with LAN8720 (STM32F4/F7) or built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)

AsyncWebServer_STM32 is a library for the STM32 with LAN8720 or built-in LAN8742A Ethernet WebServer

Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_STM32
Licensed under MIT license

Version: 1.3.0

Version Modified By Date Comments
------- ----------- ---------- -----------
1.2.3 K Hoang 02/09/2020 Initial coding for STM32 for built-in Ethernet (Nucleo-144, DISCOVERY, etc).
Expand Down Expand Up @@ -1007,6 +1007,14 @@ void AsyncWebServerRequest::send(AsyncWebServerResponse *response)
}
}

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);
}

AsyncWebServerResponse * AsyncWebServerRequest::beginResponse(int code, const String& contentType, const String& content)
{
return new AsyncBasicResponse(code, contentType, content);
Expand Down Expand Up @@ -1063,31 +1071,31 @@ void AsyncWebServerRequest::redirect(const String& url)
}

bool AsyncWebServerRequest::authenticate(const char * username, const char * password, const char * realm, bool passwordIsHash)
{
{
LOGDEBUG1("AsyncWebServerRequest::authenticate: auth-len =", _authorization.length());

if (_authorization.length())
{
{
if (_isDigest)
{
LOGDEBUG("AsyncWebServerRequest::authenticate: _isDigest");

return checkDigestAuthentication(_authorization.c_str(), methodToString(), username, password, realm, passwordIsHash, NULL, NULL, NULL);
}
else if (!passwordIsHash)
{
LOGDEBUG("AsyncWebServerRequest::authenticate: !passwordIsHash");

return checkBasicAuthentication(_authorization.c_str(), username, password);
}
else
{
LOGDEBUG("AsyncWebServerRequest::authenticate: Using password _authorization.equals");

return _authorization.equals(password);
}
}

LOGDEBUG("AsyncWebServerRequest::authenticate: failed, len = 0");

return false;
Expand Down Expand Up @@ -1293,12 +1301,12 @@ bool AsyncWebServerRequest::isExpectedRequestedConnType(RequestedConnectionType

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;
}
84 changes: 47 additions & 37 deletions src/AsyncWebResponseImpl_STM32.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/****************************************************************************************************************************
AsyncWebResponseImpl_STM32.h - Dead simple AsyncWebServer for STM32 LAN8720 or built-in LAN8742A Ethernet

For STM32 with LAN8720 (STM32F4/F7) or built-in LAN8742A Ethernet (Nucleo-144, DISCOVERY, etc)

AsyncWebServer_STM32 is a library for the STM32 with LAN8720 or built-in LAN8742A Ethernet WebServer

Based on and modified from ESPAsyncWebServer (https://github.com/me-no-dev/ESPAsyncWebServer)
Built by Khoi Hoang https://github.com/khoih-prog/AsyncWebServer_STM32
Licensed under MIT license

Version: 1.3.0

Version Modified By Date Comments
------- ----------- ---------- -----------
1.2.3 K Hoang 02/09/2020 Initial coding for STM32 for built-in Ethernet (Nucleo-144, DISCOVERY, etc).
Expand All @@ -35,24 +35,25 @@
#include <vector>
// It is possible to restore these defines, but one can use _min and _max instead. Or std::min, std::max.

class AsyncBasicResponse: public AsyncWebServerResponse

class AsyncBasicResponse: public AsyncWebServerResponse
{
private:
String _content;

public:
AsyncBasicResponse(int code, const String& contentType = String(), const String& content = String());
void _respond(AsyncWebServerRequest *request);

size_t _ack(AsyncWebServerRequest *request, size_t len, uint32_t time);
bool _sourceValid() const

bool _sourceValid() const
{
return true;
}
};

class AsyncAbstractResponse: public AsyncWebServerResponse
class AsyncAbstractResponse: public AsyncWebServerResponse
{
private:
String _head;
Expand All @@ -63,21 +64,21 @@ class AsyncAbstractResponse: public AsyncWebServerResponse
std::vector<uint8_t> _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);
bool _sourceValid() const

bool _sourceValid() const
{
return false;
}
virtual size_t _fillBuffer(uint8_t *buf __attribute__((unused)), size_t maxLen __attribute__((unused)))

virtual size_t _fillBuffer(uint8_t *buf __attribute__((unused)), size_t maxLen __attribute__((unused)))
{
return 0;
}
Expand All @@ -89,72 +90,81 @@ class AsyncAbstractResponse: public AsyncWebServerResponse

#define TEMPLATE_PARAM_NAME_LENGTH 32

class AsyncStreamResponse: public AsyncAbstractResponse
class AsyncStreamResponse: public AsyncAbstractResponse
{
private:
Stream *_content;

public:
AsyncStreamResponse(Stream &stream, const String& contentType, size_t len, AwsTemplateProcessor callback = nullptr);
bool _sourceValid() const

bool _sourceValid() const
{
return !!(_content);
}

virtual size_t _fillBuffer(uint8_t *buf, size_t maxLen) override;
};

class AsyncCallbackResponse: public AsyncAbstractResponse
class AsyncCallbackResponse: public AsyncAbstractResponse
{
private:
AwsResponseFiller _content;
size_t _filledLength;

public:
AsyncCallbackResponse(const String& contentType, size_t len, AwsResponseFiller callback, AwsTemplateProcessor templateCallback = nullptr);
bool _sourceValid() const

bool _sourceValid() const
{
return !!(_content);
}

virtual size_t _fillBuffer(uint8_t *buf, size_t maxLen) override;
};

class AsyncChunkedResponse: public AsyncAbstractResponse
class AsyncChunkedResponse: public AsyncAbstractResponse
{
private:
AwsResponseFiller _content;
size_t _filledLength;

public:
AsyncChunkedResponse(const String& contentType, AwsResponseFiller callback, AwsTemplateProcessor templateCallback = nullptr);
bool _sourceValid() const

bool _sourceValid() const
{
return !!(_content);
}

virtual size_t _fillBuffer(uint8_t *buf, size_t maxLen) override;
};

class cbuf;
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);
bool _sourceValid() const { return true; }
virtual size_t _fillBuffer(uint8_t *buf, size_t maxLen) override;
};

class AsyncResponseStream: public AsyncAbstractResponse, public Print
class AsyncResponseStream: public AsyncAbstractResponse, public Print
{
private:
cbuf *_content;

public:
AsyncResponseStream(const String& contentType, size_t bufferSize);
~AsyncResponseStream();
bool _sourceValid() const

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);
Expand Down
Loading