This commit is contained in:
proddy
2025-01-04 13:41:39 +01:00
parent 4138598db2
commit eb87651c47
166 changed files with 2099 additions and 10446 deletions

8236
lib_standalone/ArduinoJson.h Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,3 @@
#ifndef ASYNC_JSON_H_
#define ASYNC_JSON_H_
@@ -6,7 +5,8 @@
#include "ESPAsyncWebServer.h"
#define DYNAMIC_JSON_DOCUMENT_SIZE 1024
// treat MessagePack as normal JSON responses
#define AsyncMessagePackResponse AsyncJsonResponse
constexpr const char * JSON_MIMETYPE = "application/json";
@@ -42,65 +42,17 @@ class ChunkPrint : public Print {
}
};
// class PrettyAsyncJsonResponse {
// protected:
// JsonDocument _jsonBuffer;
// JsonVariant _root;
// bool _isValid;
// public:
// PrettyAsyncJsonResponse(bool isArray = false)
// : _isValid{false} {
// if (isArray)
// _root = _jsonBuffer.to<JsonArray>();
// else
// _root = _jsonBuffer.add<JsonObject>();
// }
// ~PrettyAsyncJsonResponse() {
// }
// JsonVariant getRoot() {
// return _root;
// }
// bool _sourceValid() const {
// return _isValid;
// }
// size_t setLength() {
// return 0;
// }
// void setContentType(const char * s) {
// }
// size_t getSize() {
// return _jsonBuffer.size();
// }
// size_t _fillBuffer(uint8_t * data, size_t len) {
// return len;
// }
// void setCode(uint16_t) {
// }
// };
class AsyncJsonResponse {
protected:
JsonDocument _jsonBuffer;
JsonVariant _root;
bool _isValid;
bool _isMsgPack;
int _code;
size_t _contentLength;
public:
AsyncJsonResponse(bool isArray = false, bool isMsgPack = false)
: _isValid{false}
, _isMsgPack{isMsgPack} {
AsyncJsonResponse(bool isArray = false)
: _isValid{false} {
_code = 200;
if (isArray)
_root = _jsonBuffer.to<JsonArray>();
@@ -120,7 +72,7 @@ class AsyncJsonResponse {
}
size_t setLength() {
_contentLength = _isMsgPack ? measureMsgPack(_root) : measureJson(_root);
_contentLength = measureJson(_root);
if (_contentLength) {
_isValid = true;
@@ -133,7 +85,7 @@ class AsyncJsonResponse {
}
size_t _fillBuffer(uint8_t * data, size_t len) {
// _isMsgPack ? serializeMsgPack(_root, data) : serializeJson(_root, data);
// serializeJson(_root, data);
return len;
}
@@ -155,10 +107,9 @@ class AsyncCallbackJsonWebHandler : public AsyncWebHandler {
ArJsonRequestHandlerFunction _onRequest;
size_t _contentLength;
size_t _maxContentLength;
size_t _maxJsonBufferSize;
public:
AsyncCallbackJsonWebHandler(const String & uri, ArJsonRequestHandlerFunction onRequest, size_t maxJsonBufferSize = DYNAMIC_JSON_DOCUMENT_SIZE)
AsyncCallbackJsonWebHandler(const String & uri, ArJsonRequestHandlerFunction onRequest = nullptr)
: _uri(uri)
, _method(HTTP_POST | HTTP_PUT | HTTP_PATCH)
, _onRequest(onRequest)
@@ -171,9 +122,6 @@ class AsyncCallbackJsonWebHandler : public AsyncWebHandler {
void setMaxContentLength(int maxContentLength) {
_maxContentLength = maxContentLength;
}
void setMaxJsonBufferSize(int maxJsonBufferSize) {
_maxJsonBufferSize = maxJsonBufferSize;
}
void onRequest(ArJsonRequestHandlerFunction fn) {
_onRequest = fn;
}

View File

@@ -1,5 +1,5 @@
#ifndef ESP8266React_h
#define ESP8266React_h
#ifndef ESP32React_h
#define ESP32React_h
#include <list>
@@ -97,9 +97,9 @@ class DummySettingsService : public StatefulService<DummySettings> {
#define NTPSettings DummySettings
#define APSettings DummySettings
class ESP8266React {
class ESP32React {
public:
ESP8266React(AsyncWebServer * server, FS * fs)
ESP32React(AsyncWebServer * server, FS * fs)
: _settings(server, fs, nullptr)
, _securitySettingsService(server, fs){};

View File

@@ -11,8 +11,6 @@ class AsyncWebServer;
class AsyncWebServerRequest;
class AsyncWebServerResponse;
class AsyncJsonResponse;
// class PrettyAsyncJsonResponse;
// class MsgpackAsyncJsonResponse;
class AsyncEventSource;
class AsyncWebParameter {
@@ -102,8 +100,6 @@ class AsyncWebServerRequest {
void send(AsyncJsonResponse * response) {};
// void send(PrettyAsyncJsonResponse * response) {};
// void send(MsgpackAsyncJsonResponse * response) {};
void send(int code, const String & contentType = String(), const String & content = String()) {};
void send(int code, const String & contentType, const __FlashStringHelper *) {};
@@ -226,7 +222,6 @@ class AsyncWebServerResponse {
typedef std::function<void(AsyncWebServerRequest * request)> ArRequestHandlerFunction;
typedef std::function<void(AsyncWebServerRequest * request, const String & filename, size_t index, uint8_t * data, size_t len, bool final)> ArUploadHandlerFunction;
typedef std::function<void(AsyncWebServerRequest * request, uint8_t * data, size_t len, size_t index, size_t total)> ArBodyHandlerFunction;
typedef std::function<void(AsyncWebServerRequest * request, JsonVariant json)> ArJsonRequestHandlerFunction; // added by proddy for EMS-ESP
class AsyncWebServer {
protected:
@@ -246,7 +241,6 @@ class AsyncWebServer {
}
void on(const char * uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest) {};
void on(const char * uri, ArJsonRequestHandlerFunction onRequest) {}; // added by proddy for EMS-ESP
};

View File

@@ -1,29 +0,0 @@
#ifndef Features_h
#define Features_h
// project feature off by default
#ifndef FT_PROJECT
#define FT_PROJECT 0
#endif
// security feature on by default
#ifndef FT_SECURITY
#define FT_SECURITY 0
#endif
// mqtt feature on by default
#ifndef FT_MQTT
#define FT_MQTT 0
#endif
// ntp feature on by default
#ifndef FT_NTP
#define FT_NTP 0
#endif
// upload firmware/file feature off by default
#ifndef FT_UPLOAD_FIRMWARE
#define FT_UPLOAD_FIRMWARE 0
#endif
#endif

View File

@@ -5,9 +5,6 @@
class HTTPClient {
public:
// HTTPClient();
// ~HTTPClient();
bool begin(String url) {
return true;
};

View File

@@ -2,7 +2,6 @@
#define SecurityManager_h
#include "Arduino.h"
#include "Features.h"
#include "ESPAsyncWebServer.h"
#include "AsyncJson.h"
@@ -70,6 +69,21 @@ class SecurityManager {
virtual ArRequestFilterFunction filterRequest(AuthenticationPredicate predicate) = 0;
virtual ArRequestHandlerFunction wrapRequest(ArRequestHandlerFunction onRequest, AuthenticationPredicate predicate) = 0;
virtual ArJsonRequestHandlerFunction wrapCallback(ArJsonRequestHandlerFunction onRequest, AuthenticationPredicate predicate) = 0;
void addEndpoint(AsyncWebServer * server,
const String & path,
AuthenticationPredicate predicate,
ArJsonRequestHandlerFunction function,
WebRequestMethodComposite method = HTTP_POST) {
}
// non-Json endpoints - default GET
void addEndpoint(AsyncWebServer * server,
const String & path,
AuthenticationPredicate predicate,
ArRequestHandlerFunction function,
WebRequestMethodComposite method = HTTP_GET) {
}
};
#endif

View File

@@ -1,7 +1,6 @@
#ifndef SecuritySettingsService_h
#define SecuritySettingsService_h
#include "Features.h"
#include "SecurityManager.h"
#include "HttpEndpoint.h"
#include "FSPersistence.h"