Skip to content

Commit

Permalink
Refactor code into helper method, some cleanup.
Browse files Browse the repository at this point in the history
Signed-off-by: acapparelli1 <[email protected]>
  • Loading branch information
acapparelli1 authored and Ivan Chvets committed Mar 19, 2024
1 parent d6e3701 commit 9412c00
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 33 deletions.
36 changes: 3 additions & 33 deletions src/APConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Poco::JSON::Object::Ptr>();
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 {
/*
Expand Down
1 change: 1 addition & 0 deletions src/APConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 9412c00

Please sign in to comment.