diff --git a/main/webserver.cpp b/main/webserver.cpp index 9812683..a20f60b 100644 --- a/main/webserver.cpp +++ b/main/webserver.cpp @@ -51,10 +51,11 @@ httpd_handle_t httpdHandle; void initWebserver() { -#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET - webserver_lock.construct(); - webserver_lock->take(portMAX_DELAY); -#endif + if (!configs.feature.webserver_disable_lock.value) + { + webserver_lock.construct(); + webserver_lock->take(portMAX_DELAY); + } { httpd_config_t httpConfig HTTPD_DEFAULT_CONFIG(); @@ -100,11 +101,12 @@ void initWebserver() void handleWebserver() { -#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET - webserver_lock->give(); - vTaskDelay(1); - webserver_lock->take(portMAX_DELAY); -#endif + if (!configs.feature.webserver_disable_lock.value) + { + webserver_lock->give(); + vTaskDelay(1); + webserver_lock->take(portMAX_DELAY); + } } namespace { @@ -165,16 +167,19 @@ bool menuDisplayChanged() esp_err_t webserver_status_handler(httpd_req_t *req) { -#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) + if (!configs.feature.webserver_disable_lock.value) { - 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); + 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); + } } -#endif + CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Access-Control-Allow-Origin", "http://web.bobbycar.cloud"); + std::string wants_json_query; if (auto result = esphttpdutils::webserver_get_query(req)) wants_json_query = *result; diff --git a/main/webserver_displaycontrol.cpp b/main/webserver_displaycontrol.cpp index 7e9ef9d..be21141 100644 --- a/main/webserver_displaycontrol.cpp +++ b/main/webserver_displaycontrol.cpp @@ -36,15 +36,16 @@ constexpr const char * const TAG = "BOBBYWEB"; esp_err_t webserver_root_handler(httpd_req_t *req) { -#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) + if (!configs.feature.webserver_disable_lock.value) { - 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); + 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); + } } -#endif std::string body; @@ -288,15 +289,16 @@ esp_err_t webserver_root_handler(httpd_req_t *req) esp_err_t webserver_triggerRawButton_handler(httpd_req_t *req) { -#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) + if (!configs.feature.webserver_disable_lock.value) { - 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); + 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); + } } -#endif std::string query; if (auto result = esphttpdutils::webserver_get_query(req)) @@ -362,15 +364,16 @@ esp_err_t webserver_triggerRawButton_handler(httpd_req_t *req) esp_err_t webserver_triggerButton_handler(httpd_req_t *req) { -#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) + if (!configs.feature.webserver_disable_lock.value) { - 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); + 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); + } } -#endif std::string query; if (auto result = esphttpdutils::webserver_get_query(req)) @@ -436,15 +439,17 @@ esp_err_t webserver_triggerButton_handler(httpd_req_t *req) esp_err_t webserver_triggerItem_handler(httpd_req_t *req) { -#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) + if (!configs.feature.webserver_disable_lock.value) { - 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); + 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); + } } -#endif + CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Access-Control-Allow-Origin", "http://web.bobbycar.cloud"); std::string query; @@ -525,15 +530,16 @@ esp_err_t webserver_triggerItem_handler(httpd_req_t *req) esp_err_t webserver_setValue_handler(httpd_req_t *req) { -#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) + if (!configs.feature.webserver_disable_lock.value) { - 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); + 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); + } } -#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 07c721b..46ccc7b 100644 --- a/main/webserver_dumpnvs.cpp +++ b/main/webserver_dumpnvs.cpp @@ -135,16 +135,16 @@ showInputForSetting(std::string_view key, T value, JsonObject &body) esp_err_t webserver_dump_nvs_handler(httpd_req_t *req) { -#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) + if (!configs.feature.webserver_disable_lock.value) { - 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); + 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); + } } -#endif - DynamicJsonDocument doc(6144); const auto profile = settingsPersister.currentlyOpenProfileIndex(); const auto switchBackProfile = profile ? int(*profile) : 0; diff --git a/main/webserver_lock.cpp b/main/webserver_lock.cpp index c2215f9..ae0dbe1 100644 --- a/main/webserver_lock.cpp +++ b/main/webserver_lock.cpp @@ -1,5 +1,3 @@ #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 e6f2429..ddb94b5 100644 --- a/main/webserver_lock.h +++ b/main/webserver_lock.h @@ -4,6 +4,4 @@ #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 8b65352..955938d 100644 --- a/main/webserver_newsettings.cpp +++ b/main/webserver_newsettings.cpp @@ -262,16 +262,17 @@ showInputForSetting(std::string_view key, T value, std::string &body) esp_err_t webserver_newSettings_handler(httpd_req_t *req) { -#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()) + if (!configs.feature.webserver_disable_lock.value) { - 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); + 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); + } } -#endif std::string body; @@ -507,15 +508,16 @@ saveSetting(ConfigWrapper &config, std::string_view newValue) esp_err_t webserver_saveNewSettings_handler(httpd_req_t *req) { -#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) + if (!configs.feature.webserver_disable_lock.value) { - 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); + 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); + } } -#endif std::string query; if (auto result = esphttpdutils::webserver_get_query(req)) @@ -576,15 +578,16 @@ esp_err_t webserver_saveNewSettings_handler(httpd_req_t *req) esp_err_t webserver_resetNewSettings_handler(httpd_req_t *req) { -#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) + if (!configs.feature.webserver_disable_lock.value) { - 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); + 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); + } } -#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 f2546ce..7ef9d67 100644 --- a/main/webserver_ota.cpp +++ b/main/webserver_ota.cpp @@ -34,16 +34,19 @@ constexpr const char * const TAG = "BOBBYWEB"; esp_err_t webserver_ota_percentage_handler(httpd_req_t *req) { -#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) + if (!configs.feature.webserver_disable_lock.value) { - 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); + 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); + } } -#endif + CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Access-Control-Allow-Origin", "http://web.bobbycar.cloud"); + std::string body; std::string wants_json_query; @@ -93,16 +96,19 @@ esp_err_t webserver_ota_percentage_handler(httpd_req_t *req) esp_err_t webserver_ota_handler(httpd_req_t *req) { -#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) + if (!configs.feature.webserver_disable_lock.value) { - 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); + 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); + } } -#endif + CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Access-Control-Allow-Origin", "http://web.bobbycar.cloud"); + std::string body; std::string wants_json_query; @@ -361,16 +367,19 @@ esp_err_t webserver_ota_handler(httpd_req_t *req) esp_err_t webserver_trigger_ota_handler(httpd_req_t *req) { -#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) + if (!configs.feature.webserver_disable_lock.value) { - 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); + 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); + } } -#endif + CALL_AND_EXIT_ON_ERROR(httpd_resp_set_hdr, req, "Access-Control-Allow-Origin", "http://web.bobbycar.cloud"); + std::string query; if (auto result = esphttpdutils::webserver_get_query(req)) query = *result; diff --git a/main/webserver_settings.cpp b/main/webserver_settings.cpp index 927b7a6..f6d5ddb 100644 --- a/main/webserver_settings.cpp +++ b/main/webserver_settings.cpp @@ -89,16 +89,16 @@ showInputForSetting(std::string_view key, T value, std::string &body) esp_err_t webserver_settings_handler(httpd_req_t *req) { -#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) + if (!configs.feature.webserver_disable_lock.value) { - 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); + 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); + } } -#endif - std::string body; { @@ -257,15 +257,16 @@ saveSetting(T &value, std::string_view newValue, std::string &body) esp_err_t webserver_saveSettings_handler(httpd_req_t *req) { -#ifndef FEATURE_IS_MIR_EGAL_OB_DER_WEBSERVER_KORREKT_ARBEITET - espcpputils::LockHelper helper{webserver_lock->handle, std::chrono::ceil(5s).count()}; - if (!helper.locked()) + if (!configs.feature.webserver_disable_lock.value) { - 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); + 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); + } } -#endif std::string query; if (auto result = esphttpdutils::webserver_get_query(req))