From 377564ff345ee9599114849bd278aa4fbcdce658 Mon Sep 17 00:00:00 2001 From: CommanderRedYT Date: Sat, 29 Jan 2022 03:41:19 +0100 Subject: [PATCH] Revert "Moved FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET into config-system" This reverts commit ccc8eb0e3601e0769988426f3f59713ff6071a61. --- main/webserver.cpp | 35 +++++++-------- main/webserver_displaycontrol.cpp | 75 +++++++++++++++---------------- main/webserver_dumpnvs.cpp | 16 +++---- main/webserver_lock.cpp | 2 + main/webserver_lock.h | 2 + main/webserver_newsettings.cpp | 47 +++++++++---------- main/webserver_ota.cpp | 45 +++++++++---------- main/webserver_settings.cpp | 31 +++++++------ 8 files changed, 121 insertions(+), 132 deletions(-) diff --git a/main/webserver.cpp b/main/webserver.cpp index 5b27d17..3b00fc4 100644 --- a/main/webserver.cpp +++ b/main/webserver.cpp @@ -46,11 +46,10 @@ httpd_handle_t httpdHandle; void initWebserver() { - if (!configs.feature.webserver_disable_lock.value) - { - webserver_lock.construct(); - webserver_lock->take(portMAX_DELAY); - } +#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET + webserver_lock.construct(); + webserver_lock->take(portMAX_DELAY); +#endif { httpd_config_t httpConfig HTTPD_DEFAULT_CONFIG(); @@ -92,12 +91,11 @@ void initWebserver() void handleWebserver() { - if (!configs.feature.webserver_disable_lock.value) - { - webserver_lock->give(); - vTaskDelay(1); - webserver_lock->take(portMAX_DELAY); - } +#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET + webserver_lock->give(); + vTaskDelay(1); + webserver_lock->take(portMAX_DELAY); +#endif } namespace { @@ -158,16 +156,15 @@ bool menuDisplayChanged() esp_err_t webserver_status_handler(httpd_req_t *req) { - if (!configs.feature.webserver_disable_lock.value) +#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET + espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; + if (!helper.locked()) { - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) - { - constexpr const std::string_view msg = "could not lock webserver_lock"; - ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); - CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); - } + constexpr const std::string_view msg = "could not lock webserver_lock"; + ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); + CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); } +#endif CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Access-Control-Allow-Origin", "http://web.bobbycar.cloud"); diff --git a/main/webserver_displaycontrol.cpp b/main/webserver_displaycontrol.cpp index 02be330..34d4bff 100644 --- a/main/webserver_displaycontrol.cpp +++ b/main/webserver_displaycontrol.cpp @@ -33,16 +33,15 @@ constexpr const char * const TAG = "BOBBYWEB"; esp_err_t webserver_root_handler(httpd_req_t *req) { - if (!configs.feature.webserver_disable_lock.value) +#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET + espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; + if (!helper.locked()) { - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) - { - constexpr const std::string_view msg = "could not lock webserver_lock"; - ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); - CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); - } + constexpr const std::string_view msg = "could not lock webserver_lock"; + ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); + CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); } +#endif std::string body; @@ -283,16 +282,15 @@ esp_err_t webserver_root_handler(httpd_req_t *req) esp_err_t webserver_triggerRawButton_handler(httpd_req_t *req) { - if (!configs.feature.webserver_disable_lock.value) +#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET + espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; + if (!helper.locked()) { - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) - { - constexpr const std::string_view msg = "could not lock webserver_lock"; - ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); - CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); - } + constexpr const std::string_view msg = "could not lock webserver_lock"; + ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); + CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); } +#endif std::string query; if (auto result = esphttpdutils::webserver_get_query(req)) @@ -358,16 +356,15 @@ esp_err_t webserver_triggerRawButton_handler(httpd_req_t *req) esp_err_t webserver_triggerButton_handler(httpd_req_t *req) { - if (!configs.feature.webserver_disable_lock.value) +#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET + espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; + if (!helper.locked()) { - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) - { - constexpr const std::string_view msg = "could not lock webserver_lock"; - ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); - CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); - } + constexpr const std::string_view msg = "could not lock webserver_lock"; + ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); + CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); } +#endif std::string query; if (auto result = esphttpdutils::webserver_get_query(req)) @@ -433,16 +430,15 @@ esp_err_t webserver_triggerButton_handler(httpd_req_t *req) esp_err_t webserver_triggerItem_handler(httpd_req_t *req) { - if (!configs.feature.webserver_disable_lock.value) +#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET + espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; + if (!helper.locked()) { - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) - { - constexpr const std::string_view msg = "could not lock webserver_lock"; - ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); - CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); - } + constexpr const std::string_view msg = "could not lock webserver_lock"; + ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); + CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); } +#endif CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Access-Control-Allow-Origin", "http://web.bobbycar.cloud"); @@ -524,16 +520,15 @@ esp_err_t webserver_triggerItem_handler(httpd_req_t *req) esp_err_t webserver_setValue_handler(httpd_req_t *req) { - if (!configs.feature.webserver_disable_lock.value) +#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET + espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; + if (!helper.locked()) { - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) - { - constexpr const std::string_view msg = "could not lock webserver_lock"; - ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); - CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); - } + constexpr const std::string_view msg = "could not lock webserver_lock"; + ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); + CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); } +#endif CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Access-Control-Allow-Origin", "http://web.bobbycar.cloud"); diff --git a/main/webserver_dumpnvs.cpp b/main/webserver_dumpnvs.cpp index 80def2f..6a8ef47 100644 --- a/main/webserver_dumpnvs.cpp +++ b/main/webserver_dumpnvs.cpp @@ -128,16 +128,16 @@ showInputForSetting(std::string_view key, T value, JsonObject &body) esp_err_t webserver_dump_nvs_handler(httpd_req_t *req) { - if (!configs.feature.webserver_disable_lock.value) +#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET + espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; + if (!helper.locked()) { - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) - { - constexpr const std::string_view msg = "could not lock webserver_lock"; - ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); - CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); - } + constexpr const std::string_view msg = "could not lock webserver_lock"; + ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); + CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); } +#endif + DynamicJsonDocument doc(6144); JsonObject settings = doc.createNestedObject("settings"); diff --git a/main/webserver_lock.cpp b/main/webserver_lock.cpp index ae0dbe1..c2215f9 100644 --- a/main/webserver_lock.cpp +++ b/main/webserver_lock.cpp @@ -1,3 +1,5 @@ #include "webserver_lock.h" +#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET cpputils::DelayedConstruction webserver_lock; +#endif diff --git a/main/webserver_lock.h b/main/webserver_lock.h index ddb94b5..e6f2429 100644 --- a/main/webserver_lock.h +++ b/main/webserver_lock.h @@ -4,4 +4,6 @@ #include #include +#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET extern cpputils::DelayedConstruction webserver_lock; +#endif diff --git a/main/webserver_newsettings.cpp b/main/webserver_newsettings.cpp index 7f0d3d6..35036d7 100644 --- a/main/webserver_newsettings.cpp +++ b/main/webserver_newsettings.cpp @@ -259,17 +259,16 @@ showInputForSetting(std::string_view key, T value, std::string &body) esp_err_t webserver_newSettings_handler(httpd_req_t *req) { - if (!configs.feature.webserver_disable_lock.value) +#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET + ESP_LOGI(TAG, "trying to lock..."); + espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; + if (!helper.locked()) { - ESP_LOGI(TAG, "trying to lock..."); - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) - { - constexpr const std::string_view msg = "could not lock webserver_lock"; - ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); - CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); - } + constexpr const std::string_view msg = "could not lock webserver_lock"; + ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); + CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); } +#endif std::string body; @@ -503,16 +502,15 @@ saveSetting(ConfigWrapper &config, std::string_view newValue) esp_err_t webserver_saveNewSettings_handler(httpd_req_t *req) { - if (!configs.feature.webserver_disable_lock.value) +#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET + espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; + if (!helper.locked()) { - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) - { - constexpr const std::string_view msg = "could not lock webserver_lock"; - ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); - CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); - } + constexpr const std::string_view msg = "could not lock webserver_lock"; + ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); + CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); } +#endif std::string query; if (auto result = esphttpdutils::webserver_get_query(req)) @@ -573,16 +571,15 @@ esp_err_t webserver_saveNewSettings_handler(httpd_req_t *req) esp_err_t webserver_resetNewSettings_handler(httpd_req_t *req) { - if (!configs.feature.webserver_disable_lock.value) +#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET + espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; + if (!helper.locked()) { - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) - { - constexpr const std::string_view msg = "could not lock webserver_lock"; - ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); - CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); - } + constexpr const std::string_view msg = "could not lock webserver_lock"; + ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); + CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); } +#endif std::string query; if (auto result = esphttpdutils::webserver_get_query(req)) diff --git a/main/webserver_ota.cpp b/main/webserver_ota.cpp index eadd2e3..407036c 100644 --- a/main/webserver_ota.cpp +++ b/main/webserver_ota.cpp @@ -29,16 +29,15 @@ constexpr const char * const TAG = "BOBBYWEB"; esp_err_t webserver_ota_percentage_handler(httpd_req_t *req) { - if (!configs.feature.webserver_disable_lock.value) +#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET + espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; + if (!helper.locked()) { - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) - { - constexpr const std::string_view msg = "could not lock webserver_lock"; - ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); - CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); - } + constexpr const std::string_view msg = "could not lock webserver_lock"; + ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); + CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); } +#endif CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Access-Control-Allow-Origin", "http://web.bobbycar.cloud"); @@ -91,16 +90,15 @@ esp_err_t webserver_ota_percentage_handler(httpd_req_t *req) esp_err_t webserver_ota_handler(httpd_req_t *req) { - if (!configs.feature.webserver_disable_lock.value) +#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET + espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; + if (!helper.locked()) { - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) - { - constexpr const std::string_view msg = "could not lock webserver_lock"; - ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); - CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); - } + constexpr const std::string_view msg = "could not lock webserver_lock"; + ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); + CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); } +#endif CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Access-Control-Allow-Origin", "http://web.bobbycar.cloud"); @@ -362,16 +360,15 @@ esp_err_t webserver_ota_handler(httpd_req_t *req) esp_err_t webserver_trigger_ota_handler(httpd_req_t *req) { - if (!configs.feature.webserver_disable_lock.value) +#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET + espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; + if (!helper.locked()) { - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) - { - constexpr const std::string_view msg = "could not lock webserver_lock"; - ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); - CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); - } + constexpr const std::string_view msg = "could not lock webserver_lock"; + ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); + CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); } +#endif CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Access-Control-Allow-Origin", "http://web.bobbycar.cloud"); diff --git a/main/webserver_settings.cpp b/main/webserver_settings.cpp index eea9daf..a93817f 100644 --- a/main/webserver_settings.cpp +++ b/main/webserver_settings.cpp @@ -86,16 +86,16 @@ showInputForSetting(std::string_view key, T value, std::string &body) esp_err_t webserver_settings_handler(httpd_req_t *req) { - if (!configs.feature.webserver_disable_lock.value) +#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET + espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; + if (!helper.locked()) { - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) - { - constexpr const std::string_view msg = "could not lock webserver_lock"; - ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); - CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); - } + constexpr const std::string_view msg = "could not lock webserver_lock"; + ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); + CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); } +#endif + std::string body; { @@ -252,16 +252,15 @@ saveSetting(T &value, std::string_view newValue, std::string &body) esp_err_t webserver_saveSettings_handler(httpd_req_t *req) { - if (!configs.feature.webserver_disable_lock.value) +#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET + espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; + if (!helper.locked()) { - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) - { - constexpr const std::string_view msg = "could not lock webserver_lock"; - ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); - CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); - } + constexpr const std::string_view msg = "could not lock webserver_lock"; + ESP_LOGE(TAG, "%.*s", msg.size(), msg.data()); + CALL_AND_EXIT(esphttpdutils::webserver_resp_send, req, esphttpdutils::ResponseStatus::BadRequest, "text/plain", msg); } +#endif std::string query; if (auto result = esphttpdutils::webserver_get_query(req))