mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
remove & reference to JsonVariant (prevent dangling references)
This commit is contained in:
@@ -70,7 +70,7 @@ class MsgpackAsyncJsonResponse : public AsyncAbstractResponse {
|
|||||||
|
|
||||||
~MsgpackAsyncJsonResponse() {
|
~MsgpackAsyncJsonResponse() {
|
||||||
}
|
}
|
||||||
JsonVariant & getRoot() {
|
JsonVariant getRoot() {
|
||||||
return _root;
|
return _root;
|
||||||
}
|
}
|
||||||
bool _sourceValid() const {
|
bool _sourceValid() const {
|
||||||
@@ -114,7 +114,7 @@ class AsyncJsonResponse : public AsyncAbstractResponse {
|
|||||||
|
|
||||||
~AsyncJsonResponse() {
|
~AsyncJsonResponse() {
|
||||||
}
|
}
|
||||||
JsonVariant & getRoot() {
|
JsonVariant getRoot() {
|
||||||
return _root;
|
return _root;
|
||||||
}
|
}
|
||||||
bool _sourceValid() const {
|
bool _sourceValid() const {
|
||||||
@@ -158,7 +158,7 @@ class PrettyAsyncJsonResponse : public AsyncJsonResponse {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::function<void(AsyncWebServerRequest * request, JsonVariant & json)> ArJsonRequestHandlerFunction;
|
typedef std::function<void(AsyncWebServerRequest * request, JsonVariant json)> ArJsonRequestHandlerFunction;
|
||||||
|
|
||||||
class AsyncCallbackJsonWebHandler : public AsyncWebHandler {
|
class AsyncCallbackJsonWebHandler : public AsyncWebHandler {
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ void AuthenticationService::verifyAuthorization(AsyncWebServerRequest * request)
|
|||||||
* Signs in a user if the username and password match. Provides a JWT to be used in the Authorization header in
|
* Signs in a user if the username and password match. Provides a JWT to be used in the Authorization header in
|
||||||
* subsequent requests.
|
* subsequent requests.
|
||||||
*/
|
*/
|
||||||
void AuthenticationService::signIn(AsyncWebServerRequest * request, JsonVariant & json) {
|
void AuthenticationService::signIn(AsyncWebServerRequest * request, JsonVariant json) {
|
||||||
if (json.is<JsonObject>()) {
|
if (json.is<JsonObject>()) {
|
||||||
String username = json["username"];
|
String username = json["username"];
|
||||||
String password = json["password"];
|
String password = json["password"];
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ class AuthenticationService {
|
|||||||
AsyncCallbackJsonWebHandler _signInHandler;
|
AsyncCallbackJsonWebHandler _signInHandler;
|
||||||
|
|
||||||
// endpoint functions
|
// endpoint functions
|
||||||
void signIn(AsyncWebServerRequest * request, JsonVariant & json);
|
void signIn(AsyncWebServerRequest * request, JsonVariant json);
|
||||||
void verifyAuthorization(AsyncWebServerRequest * request);
|
void verifyAuthorization(AsyncWebServerRequest * request);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ class HttpPostEndpoint {
|
|||||||
StatefulService<T> * _statefulService;
|
StatefulService<T> * _statefulService;
|
||||||
AsyncCallbackJsonWebHandler _updateHandler;
|
AsyncCallbackJsonWebHandler _updateHandler;
|
||||||
|
|
||||||
void updateSettings(AsyncWebServerRequest * request, JsonVariant & json) {
|
void updateSettings(AsyncWebServerRequest * request, JsonVariant json) {
|
||||||
if (!json.is<JsonObject>()) {
|
if (!json.is<JsonObject>()) {
|
||||||
request->send(400);
|
request->send(400);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ void NTPSettingsService::configureNTP() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NTPSettingsService::configureTime(AsyncWebServerRequest * request, JsonVariant & json) {
|
void NTPSettingsService::configureTime(AsyncWebServerRequest * request, JsonVariant json) {
|
||||||
if (json.is<JsonObject>()) {
|
if (json.is<JsonObject>()) {
|
||||||
struct tm tm = {0};
|
struct tm tm = {0};
|
||||||
String timeLocal = json["local_time"];
|
String timeLocal = json["local_time"];
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ class NTPSettingsService : public StatefulService<NTPSettings> {
|
|||||||
bool connected_ = false;
|
bool connected_ = false;
|
||||||
void WiFiEvent(WiFiEvent_t event);
|
void WiFiEvent(WiFiEvent_t event);
|
||||||
void configureNTP();
|
void configureNTP();
|
||||||
void configureTime(AsyncWebServerRequest * request, JsonVariant & json);
|
void configureTime(AsyncWebServerRequest * request, JsonVariant json);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ ArRequestHandlerFunction SecuritySettingsService::wrapRequest(ArRequestHandlerFu
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArJsonRequestHandlerFunction SecuritySettingsService::wrapCallback(ArJsonRequestHandlerFunction onRequest, AuthenticationPredicate predicate) {
|
ArJsonRequestHandlerFunction SecuritySettingsService::wrapCallback(ArJsonRequestHandlerFunction onRequest, AuthenticationPredicate predicate) {
|
||||||
return [this, onRequest, predicate](AsyncWebServerRequest * request, JsonVariant & json) {
|
return [this, onRequest, predicate](AsyncWebServerRequest * request, JsonVariant json) {
|
||||||
Authentication authentication = authenticateRequest(request);
|
Authentication authentication = authenticateRequest(request);
|
||||||
if (!predicate(authentication)) {
|
if (!predicate(authentication)) {
|
||||||
request->send(401);
|
request->send(401);
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ class PrettyAsyncJsonResponse {
|
|||||||
~PrettyAsyncJsonResponse() {
|
~PrettyAsyncJsonResponse() {
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonVariant & getRoot() {
|
JsonVariant getRoot() {
|
||||||
return _root;
|
return _root;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +104,7 @@ class MsgpackAsyncJsonResponse {
|
|||||||
~MsgpackAsyncJsonResponse() {
|
~MsgpackAsyncJsonResponse() {
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonVariant & getRoot() {
|
JsonVariant getRoot() {
|
||||||
return _root;
|
return _root;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,7 +150,7 @@ class AsyncJsonResponse {
|
|||||||
~AsyncJsonResponse() {
|
~AsyncJsonResponse() {
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonVariant & getRoot() {
|
JsonVariant getRoot() {
|
||||||
return _root;
|
return _root;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,7 +177,7 @@ class AsyncJsonResponse {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::function<void(AsyncWebServerRequest * request, JsonVariant & json)> ArJsonRequestHandlerFunction;
|
typedef std::function<void(AsyncWebServerRequest * request, JsonVariant json)> ArJsonRequestHandlerFunction;
|
||||||
|
|
||||||
class AsyncCallbackJsonWebHandler : public AsyncWebHandler {
|
class AsyncCallbackJsonWebHandler : public AsyncWebHandler {
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ class HttpPostEndpoint {
|
|||||||
JsonStateUpdater<T> _stateUpdater;
|
JsonStateUpdater<T> _stateUpdater;
|
||||||
StatefulService<T> * _statefulService;
|
StatefulService<T> * _statefulService;
|
||||||
|
|
||||||
void updateSettings(AsyncWebServerRequest * request, JsonVariant & json) {
|
void updateSettings(AsyncWebServerRequest * request, JsonVariant json) {
|
||||||
if (!json.is<JsonObject>()) {
|
if (!json.is<JsonObject>()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ ArRequestHandlerFunction SecuritySettingsService::wrapRequest(ArRequestHandlerFu
|
|||||||
}
|
}
|
||||||
|
|
||||||
ArJsonRequestHandlerFunction SecuritySettingsService::wrapCallback(ArJsonRequestHandlerFunction onRequest, AuthenticationPredicate predicate) {
|
ArJsonRequestHandlerFunction SecuritySettingsService::wrapCallback(ArJsonRequestHandlerFunction onRequest, AuthenticationPredicate predicate) {
|
||||||
return [this, onRequest, predicate](AsyncWebServerRequest * request, JsonVariant & json) {
|
return [this, onRequest, predicate](AsyncWebServerRequest * request, JsonVariant json) {
|
||||||
Authentication authentication = authenticateRequest(request);
|
Authentication authentication = authenticateRequest(request);
|
||||||
if (!predicate(authentication)) {
|
if (!predicate(authentication)) {
|
||||||
request->send(401);
|
request->send(401);
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ void WebAPIService::webAPIService_get(AsyncWebServerRequest * request) {
|
|||||||
// For HTTP POSTS with an optional JSON body
|
// For HTTP POSTS with an optional JSON body
|
||||||
// HTTP_POST | HTTP_PUT | HTTP_PATCH
|
// HTTP_POST | HTTP_PUT | HTTP_PATCH
|
||||||
// POST /{device}[/{hc|id}][/{name}]
|
// POST /{device}[/{hc|id}][/{name}]
|
||||||
void WebAPIService::webAPIService_post(AsyncWebServerRequest * request, JsonVariant & json) {
|
void WebAPIService::webAPIService_post(AsyncWebServerRequest * request, JsonVariant json) {
|
||||||
// if no body then treat it as a secure GET
|
// if no body then treat it as a secure GET
|
||||||
if (!json.is<JsonObject>()) {
|
if (!json.is<JsonObject>()) {
|
||||||
webAPIService_get(request);
|
webAPIService_get(request);
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ class WebAPIService {
|
|||||||
public:
|
public:
|
||||||
WebAPIService(AsyncWebServer * server, SecurityManager * securityManager);
|
WebAPIService(AsyncWebServer * server, SecurityManager * securityManager);
|
||||||
|
|
||||||
void webAPIService_post(AsyncWebServerRequest * request, JsonVariant & json); // for POSTs
|
void webAPIService_post(AsyncWebServerRequest * request, JsonVariant json); // for POSTs
|
||||||
void webAPIService_get(AsyncWebServerRequest * request); // for GETs
|
void webAPIService_get(AsyncWebServerRequest * request); // for GETs
|
||||||
|
|
||||||
static uint32_t api_count() {
|
static uint32_t api_count() {
|
||||||
return api_count_;
|
return api_count_;
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ void WebCustomizationService::device_entities(AsyncWebServerRequest * request) {
|
|||||||
// takes a list of updated entities with new masks from the web UI
|
// takes a list of updated entities with new masks from the web UI
|
||||||
// saves it in the customization service
|
// saves it in the customization service
|
||||||
// and updates the entity list real-time
|
// and updates the entity list real-time
|
||||||
void WebCustomizationService::customization_entities(AsyncWebServerRequest * request, JsonVariant & json) {
|
void WebCustomizationService::customization_entities(AsyncWebServerRequest * request, JsonVariant json) {
|
||||||
bool need_reboot = false;
|
bool need_reboot = false;
|
||||||
if (json.is<JsonObject>()) {
|
if (json.is<JsonObject>()) {
|
||||||
// find the device using the unique_id
|
// find the device using the unique_id
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ class WebCustomizationService : public StatefulService<WebCustomization> {
|
|||||||
void device_entities(AsyncWebServerRequest * request);
|
void device_entities(AsyncWebServerRequest * request);
|
||||||
|
|
||||||
// POST
|
// POST
|
||||||
void customization_entities(AsyncWebServerRequest * request, JsonVariant & json);
|
void customization_entities(AsyncWebServerRequest * request, JsonVariant json);
|
||||||
void reset_customization(AsyncWebServerRequest * request); // command
|
void reset_customization(AsyncWebServerRequest * request); // command
|
||||||
|
|
||||||
AsyncCallbackJsonWebHandler _masked_entities_handler;
|
AsyncCallbackJsonWebHandler _masked_entities_handler;
|
||||||
|
|||||||
@@ -227,7 +227,7 @@ void WebDataService::device_data(AsyncWebServerRequest * request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// assumes the service has been checked for admin authentication
|
// assumes the service has been checked for admin authentication
|
||||||
void WebDataService::write_device_value(AsyncWebServerRequest * request, JsonVariant & json) {
|
void WebDataService::write_device_value(AsyncWebServerRequest * request, JsonVariant json) {
|
||||||
if (json.is<JsonObject>()) {
|
if (json.is<JsonObject>()) {
|
||||||
uint8_t unique_id = json["id"]; // unique ID
|
uint8_t unique_id = json["id"]; // unique ID
|
||||||
const char * cmd = json["c"]; // the command
|
const char * cmd = json["c"]; // the command
|
||||||
@@ -323,7 +323,7 @@ void WebDataService::write_device_value(AsyncWebServerRequest * request, JsonVar
|
|||||||
|
|
||||||
// takes a temperaturesensor name and optional offset from the WebUI and update the customization settings
|
// takes a temperaturesensor name and optional offset from the WebUI and update the customization settings
|
||||||
// via the temperaturesensor service
|
// via the temperaturesensor service
|
||||||
void WebDataService::write_temperature_sensor(AsyncWebServerRequest * request, JsonVariant & json) {
|
void WebDataService::write_temperature_sensor(AsyncWebServerRequest * request, JsonVariant json) {
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
if (json.is<JsonObject>()) {
|
if (json.is<JsonObject>()) {
|
||||||
JsonObject sensor = json;
|
JsonObject sensor = json;
|
||||||
@@ -346,7 +346,7 @@ void WebDataService::write_temperature_sensor(AsyncWebServerRequest * request, J
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update the analog record, or create a new one
|
// update the analog record, or create a new one
|
||||||
void WebDataService::write_analog_sensor(AsyncWebServerRequest * request, JsonVariant & json) {
|
void WebDataService::write_analog_sensor(AsyncWebServerRequest * request, JsonVariant json) {
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
if (json.is<JsonObject>()) {
|
if (json.is<JsonObject>()) {
|
||||||
JsonObject analog = json;
|
JsonObject analog = json;
|
||||||
|
|||||||
@@ -47,9 +47,9 @@ class WebDataService {
|
|||||||
void device_data(AsyncWebServerRequest * request);
|
void device_data(AsyncWebServerRequest * request);
|
||||||
|
|
||||||
// POST
|
// POST
|
||||||
void write_device_value(AsyncWebServerRequest * request, JsonVariant & json);
|
void write_device_value(AsyncWebServerRequest * request, JsonVariant json);
|
||||||
void write_temperature_sensor(AsyncWebServerRequest * request, JsonVariant & json);
|
void write_temperature_sensor(AsyncWebServerRequest * request, JsonVariant json);
|
||||||
void write_analog_sensor(AsyncWebServerRequest * request, JsonVariant & json);
|
void write_analog_sensor(AsyncWebServerRequest * request, JsonVariant json);
|
||||||
void scan_devices(AsyncWebServerRequest * request); // command
|
void scan_devices(AsyncWebServerRequest * request); // command
|
||||||
|
|
||||||
AsyncCallbackJsonWebHandler _write_value_handler, _write_temperature_handler, _write_analog_handler;
|
AsyncCallbackJsonWebHandler _write_value_handler, _write_temperature_handler, _write_analog_handler;
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ void WebLogService::fetchLog(AsyncWebServerRequest * request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// sets the values like level after a POST
|
// sets the values like level after a POST
|
||||||
void WebLogService::setValues(AsyncWebServerRequest * request, JsonVariant & json) {
|
void WebLogService::setValues(AsyncWebServerRequest * request, JsonVariant json) {
|
||||||
if (!json.is<JsonObject>()) {
|
if (!json.is<JsonObject>()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ class WebLogService : public uuid::log::Handler {
|
|||||||
|
|
||||||
char * messagetime(char * out, const uint64_t t, const size_t bufsize);
|
char * messagetime(char * out, const uint64_t t, const size_t bufsize);
|
||||||
|
|
||||||
void setValues(AsyncWebServerRequest * request, JsonVariant & json);
|
void setValues(AsyncWebServerRequest * request, JsonVariant json);
|
||||||
|
|
||||||
AsyncCallbackJsonWebHandler setValues_; // for POSTs
|
AsyncCallbackJsonWebHandler setValues_; // for POSTs
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user