From 000cd8b6dcdf2247c6a5df79facacc8a986d71be Mon Sep 17 00:00:00 2001 From: Thomas Basler Date: Mon, 18 Apr 2022 01:33:46 +0200 Subject: [PATCH] Implemented additional timezone description --- include/Configuration.h | 2 ++ include/defaults.h | 3 ++- src/Configuration.cpp | 2 ++ src/WebApi.cpp | 9 +++++++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/include/Configuration.h b/include/Configuration.h index 3050330..e24214f 100644 --- a/include/Configuration.h +++ b/include/Configuration.h @@ -11,6 +11,7 @@ #define NTP_MAX_SERVER_STRLEN 31 #define NTP_MAX_TIMEZONE_STRLEN 50 +#define NTP_MAX_TIMEZONEDESCR_STRLEN 50 struct CONFIG_T { uint32_t Cfg_Version; @@ -28,6 +29,7 @@ struct CONFIG_T { char Ntp_Server[NTP_MAX_SERVER_STRLEN + 1]; char Ntp_Timezone[NTP_MAX_TIMEZONE_STRLEN + 1]; + char Ntp_TimezoneDescr[NTP_MAX_TIMEZONEDESCR_STRLEN + 1]; }; class ConfigurationClass { diff --git a/include/defaults.h b/include/defaults.h index e88191e..a04ffa6 100644 --- a/include/defaults.h +++ b/include/defaults.h @@ -18,4 +18,5 @@ #define WIFI_DHCP true #define NTP_SERVER "pool.ntp.org" -#define NTP_TIMEZONE "CET-1CEST,M3.5.0,M10.5.0/3" \ No newline at end of file +#define NTP_TIMEZONE "CET-1CEST,M3.5.0,M10.5.0/3" +#define NTP_TIMEZONEDESCR "Europe/Berlin" \ No newline at end of file diff --git a/src/Configuration.cpp b/src/Configuration.cpp index 0d534a8..506e93b 100644 --- a/src/Configuration.cpp +++ b/src/Configuration.cpp @@ -19,6 +19,7 @@ void ConfigurationClass::init() // NTP Settings strlcpy(config.Ntp_Server, NTP_SERVER, sizeof(config.Ntp_Server)); strlcpy(config.Ntp_Timezone, NTP_TIMEZONE, sizeof(config.Ntp_Timezone)); + strlcpy(config.Ntp_TimezoneDescr, NTP_TIMEZONEDESCR, sizeof(config.Ntp_TimezoneDescr)); } bool ConfigurationClass::write() @@ -55,6 +56,7 @@ void ConfigurationClass::migrate() if (config.Cfg_Version < 0x00010400) { strlcpy(config.Ntp_Server, NTP_SERVER, sizeof(config.Ntp_Server)); strlcpy(config.Ntp_Timezone, NTP_TIMEZONE, sizeof(config.Ntp_Timezone)); + strlcpy(config.Ntp_TimezoneDescr, NTP_TIMEZONEDESCR, sizeof(config.Ntp_TimezoneDescr)); } config.Cfg_Version = CONFIG_VERSION; write(); diff --git a/src/WebApi.cpp b/src/WebApi.cpp index fc47b8c..2bcaedf 100644 --- a/src/WebApi.cpp +++ b/src/WebApi.cpp @@ -307,6 +307,7 @@ void WebApiClass::onNtpAdminGet(AsyncWebServerRequest* request) root[F("ntp_server")] = config.Ntp_Server; root[F("ntp_timezone")] = config.Ntp_Timezone; + root[F("ntp_timezone_descr")] = config.Ntp_TimezoneDescr; response->setLength(); request->send(response); @@ -365,9 +366,17 @@ void WebApiClass::onNtpAdminPost(AsyncWebServerRequest* request) return; } + if (root[F("ntp_timezone_descr")].as().length() == 0 || root[F("ntp_timezone_descr")].as().length() > NTP_MAX_TIMEZONEDESCR_STRLEN) { + retMsg[F("message")] = F("Timezone description must between 1 and " STR(NTP_MAX_TIMEZONEDESCR_STRLEN) " characters long!"); + response->setLength(); + request->send(response); + return; + } + CONFIG_T& config = Configuration.get(); strcpy(config.Ntp_Server, root[F("ntp_server")].as().c_str()); strcpy(config.Ntp_Timezone, root[F("ntp_timezone")].as().c_str()); + strcpy(config.Ntp_TimezoneDescr, root[F("ntp_timezone_descr")].as().c_str()); Configuration.write(); retMsg[F("type")] = F("success");