From d6e3701ca320a3464ae204237f21cc8ee92ea01e Mon Sep 17 00:00:00 2001 From: acapparelli1 Date: Thu, 15 Feb 2024 09:00:00 -0500 Subject: [PATCH 1/5] Add more comments. Signed-off-by: acapparelli1 --- src/APConfig.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/src/APConfig.cpp b/src/APConfig.cpp index de0dc7a..22854bf 100644 --- a/src/APConfig.cpp +++ b/src/APConfig.cpp @@ -79,6 +79,42 @@ namespace OpenWifi { return false; } + void APConfig::ReplaceNestedVariables(const std::string uuid, Poco::JSON::Object &Result) { + /* + Helper method containg code previously in ReplaceVariablesinObject. + Once the top-level variable is resolved, this will be called to resolve any + variables nested within the top-level variable. + */ + ProvObjects::VariableBlock VB; + if (StorageService()->VariablesDB().GetRecord("id", uuid, VB)) { + for (const auto &var: VB.variables) { + Poco::JSON::Parser P; + auto VariableBlockInfo = + P.parse(var.value).extract(); + auto VarNames = VariableBlockInfo->getNames(); + for (const auto &j: VarNames) { + if(VariableBlockInfo->isArray(j)) { + auto Elements = VariableBlockInfo->getArray(j); + if(Elements->size()>0) { + Poco::JSON::Array InnerArray; + ReplaceVariablesInArray(*Elements, InnerArray); + Result.set(j, InnerArray); + } else { +// std::cout << "Empty Array!!!" << std::endl; + } + } else if(VariableBlockInfo->isObject(j)) { + Poco::JSON::Object InnerEval; + auto O = VariableBlockInfo->getObject(j); + ReplaceVariablesInObject(*O,InnerEval); + Result.set(j, InnerEval); + } else { + Result.set(j, VariableBlockInfo->get(j)); + } + } + } + } + } + bool APConfig::ReplaceVariablesInObject(const Poco::JSON::Object &Original, Poco::JSON::Object &Result) { // get all the names and expand @@ -86,6 +122,16 @@ namespace OpenWifi { for (const auto &i : Names) { if (i == "__variableBlock") { if (Original.isArray(i)) { + /* + E.g. of what the variable block would look like in an array: + "ssids": [ + { + "__variableBlock": [ + "79c083d2-d496-4de0-8600-76a63556851b" + ] + } + ] + */ auto UUIDs = Original.getArray(i); for (const auto &uuid: *UUIDs) { ProvObjects::VariableBlock VB; @@ -121,6 +167,16 @@ namespace OpenWifi { } } } + else { + /* + E.g. of what the variable block would look like replacing an entire json blob: + "services" : { + "__variableBlock": "ef8db4c0-f0ef-40d2-b676-c9c02ef39430" + } + */ + const std::string uuid = Original.get(i); + ReplaceNestedVariables(uuid, Result); + } } else if (i == "__radiusEndpoint") { auto EndPointId = Original.get(i).toString(); ProvObjects::RADIUSEndPoint RE; @@ -434,4 +490,4 @@ namespace OpenWifi { } else { } } -} // namespace OpenWifi \ No newline at end of file +} // namespace OpenWifi From 9412c0094bb775a8ea4d6e66847d0c40def0c3f5 Mon Sep 17 00:00:00 2001 From: acapparelli1 Date: Thu, 15 Feb 2024 08:19:58 -0500 Subject: [PATCH 2/5] Refactor code into helper method, some cleanup. Signed-off-by: acapparelli1 --- src/APConfig.cpp | 36 +++--------------------------------- src/APConfig.h | 1 + 2 files changed, 4 insertions(+), 33 deletions(-) diff --git a/src/APConfig.cpp b/src/APConfig.cpp index 22854bf..662e71d 100644 --- a/src/APConfig.cpp +++ b/src/APConfig.cpp @@ -133,39 +133,9 @@ namespace OpenWifi { ] */ auto UUIDs = Original.getArray(i); - for (const auto &uuid: *UUIDs) { - ProvObjects::VariableBlock VB; - if (StorageService()->VariablesDB().GetRecord("id", uuid, VB)) { - for (const auto &var: VB.variables) { - Poco::JSON::Parser P; - auto VariableBlockInfo = - P.parse(var.value).extract(); - auto VarNames = VariableBlockInfo->getNames(); - for (const auto &j: VarNames) { -// std::cout << "Name: " << j << std::endl; - if(VariableBlockInfo->isArray(j)) { - auto Elements = VariableBlockInfo->getArray(j); - if(Elements->size()>0) { - Poco::JSON::Array InnerArray; - ReplaceVariablesInArray(*Elements, InnerArray); - Result.set(j, InnerArray); -// std::cout << "Array!!!" << std::endl; - } else { -// std::cout << "Empty Array!!!" << std::endl; - } - } else if(VariableBlockInfo->isObject(j)) { - Poco::JSON::Object InnerEval; -// std::cout << "Visiting object " << j << std::endl; - auto O = VariableBlockInfo->getObject(j); - ReplaceVariablesInObject(*O,InnerEval); - Result.set(j, InnerEval); - } else { - Result.set(j, VariableBlockInfo->get(j)); - } - } - } - } - } + for (const std::string &uuid: *UUIDs) { + ReplaceNestedVariables(uuid, Result); + } } else { /* diff --git a/src/APConfig.h b/src/APConfig.h index c0c2da8..9a0d03f 100644 --- a/src/APConfig.h +++ b/src/APConfig.h @@ -47,6 +47,7 @@ namespace OpenWifi { bool ReplaceVariablesInArray(const Poco::JSON::Array &O, Poco::JSON::Array &Result); + void ReplaceNestedVariables(const std::string uuid, Poco::JSON::Object &Result); bool ReplaceVariablesInObject(const Poco::JSON::Object &Original, Poco::JSON::Object &Result); From 01b1107bacc7016e725f5a3fdf8e8d8b240d720f Mon Sep 17 00:00:00 2001 From: acapparelli1 Date: Wed, 14 Feb 2024 13:58:33 -0500 Subject: [PATCH 3/5] testing Signed-off-by: acapparelli1 --- src/DeviceTypeCache.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/DeviceTypeCache.h b/src/DeviceTypeCache.h index a4e33cd..6300c38 100644 --- a/src/DeviceTypeCache.h +++ b/src/DeviceTypeCache.h @@ -37,10 +37,13 @@ namespace OpenWifi { inline void onTimer([[maybe_unused]] Poco::Timer &timer) { UpdateDeviceTypes(); } inline bool IsAcceptableDeviceType(const std::string &D) const { - return (DeviceTypes_.find(D) != DeviceTypes_.end()); + return true; + //return (DeviceTypes_.find(D) != DeviceTypes_.end()); }; inline bool AreAcceptableDeviceTypes(const Types::StringVec &S, bool WildCardAllowed = true) const { + return true; + /* for (const auto &i : S) { if (WildCardAllowed && i == "*") { // We allow wildcards @@ -48,6 +51,7 @@ namespace OpenWifi { return false; } return true; + */ } private: From 0a846e45c46844eee2f26fd850403d6da20b15e6 Mon Sep 17 00:00:00 2001 From: Ivan Chvets Date: Tue, 19 Mar 2024 10:41:24 -0400 Subject: [PATCH 4/5] fix: reverting change Signed-off-by: Ivan Chvets --- src/DeviceTypeCache.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/DeviceTypeCache.h b/src/DeviceTypeCache.h index 6300c38..a4e33cd 100644 --- a/src/DeviceTypeCache.h +++ b/src/DeviceTypeCache.h @@ -37,13 +37,10 @@ namespace OpenWifi { inline void onTimer([[maybe_unused]] Poco::Timer &timer) { UpdateDeviceTypes(); } inline bool IsAcceptableDeviceType(const std::string &D) const { - return true; - //return (DeviceTypes_.find(D) != DeviceTypes_.end()); + return (DeviceTypes_.find(D) != DeviceTypes_.end()); }; inline bool AreAcceptableDeviceTypes(const Types::StringVec &S, bool WildCardAllowed = true) const { - return true; - /* for (const auto &i : S) { if (WildCardAllowed && i == "*") { // We allow wildcards @@ -51,7 +48,6 @@ namespace OpenWifi { return false; } return true; - */ } private: From 3529f86788292f9cf0aa9162a3a5da3812a96d2e Mon Sep 17 00:00:00 2001 From: Ivan Chvets Date: Tue, 19 Mar 2024 10:44:49 -0400 Subject: [PATCH 5/5] fix: typo Signed-off-by: Ivan Chvets --- src/APConfig.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/APConfig.cpp b/src/APConfig.cpp index 662e71d..f01f7c0 100644 --- a/src/APConfig.cpp +++ b/src/APConfig.cpp @@ -81,7 +81,7 @@ namespace OpenWifi { void APConfig::ReplaceNestedVariables(const std::string uuid, Poco::JSON::Object &Result) { /* - Helper method containg code previously in ReplaceVariablesinObject. + Helper method contains code previously in ReplaceVariablesinObject. Once the top-level variable is resolved, this will be called to resolve any variables nested within the top-level variable. */