Skip to content

Commit

Permalink
https://telecominfraproject.atlassian.net/browse/WIFI-13273
Browse files Browse the repository at this point in the history
Signed-off-by: stephb9959 <[email protected]>
  • Loading branch information
stephb9959 committed Jan 5, 2024
1 parent c6c6eaa commit aa862d3
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 22 deletions.
11 changes: 9 additions & 2 deletions src/AP_WS_Process_connect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ namespace OpenWifi {
State_.Address = Utils::FormatIPv6(WS_->peerAddress().toString());
CId_ = SerialNumber_ + "@" + CId_;

auto &Platform = Caps.Platform();

if(ParamsObj->has("reason")) {
State_.connectReason = ParamsObj->get("reason").toString();
}
Expand Down Expand Up @@ -204,8 +206,13 @@ namespace OpenWifi {
++Updated;
}

if (Compatible_ != DeviceInfo.DeviceType) {
DeviceInfo.DeviceType = Compatible_;
if (Compatible_ != DeviceInfo.Compatible) {
DeviceInfo.Compatible = Compatible_;
++Updated;
}

if (Platform != DeviceInfo.DeviceType) {
DeviceInfo.DeviceType = Platform;
++Updated;
}

Expand Down
9 changes: 7 additions & 2 deletions src/RESTAPI/RESTAPI_devices_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,15 @@ namespace OpenWifi {
}
}

auto platform = Poco::toLower(GetParameter("platform", ""));
auto serialOnly = GetBoolParameter(RESTAPI::Protocol::SERIALONLY, false);
auto deviceWithStatus = GetBoolParameter(RESTAPI::Protocol::DEVICEWITHSTATUS, false);
auto completeInfo = GetBoolParameter("completeInfo", false);

if(!platform.empty() && (platform!="ap" && platform!="switch")) {
return BadRequest(RESTAPI::Errors::MissingOrInvalidParameters);
}

Poco::JSON::Object RetObj;
if (!QB_.Select.empty()) {
Poco::JSON::Array Objects;
Expand Down Expand Up @@ -116,9 +121,9 @@ namespace OpenWifi {
else
RetObj.set(RESTAPI::Protocol::DEVICES, Objects);

} else if (QB_.CountOnly == true) {
} else if (QB_.CountOnly) {
uint64_t Count = 0;
if (StorageService()->GetDeviceCount(Count)) {
if (StorageService()->GetDeviceCount(Count, platform)) {
return ReturnCountOnly(Count);
}
} else if (serialOnly) {
Expand Down
8 changes: 5 additions & 3 deletions src/StorageService.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ namespace OpenWifi {
bool GetDevice(Poco::Data::Session &Session, const std::string &SerialNumber, GWObjects::Device &DeviceDetails);
bool GetDevice(const std::string &SerialNumber, GWObjects::Device &);
bool GetDevices(uint64_t From, uint64_t HowMany, std::vector<GWObjects::Device> &Devices,
const std::string &orderBy = "");
const std::string &orderBy = "",
const std::string &platform = "");
// bool GetDevices(uint64_t From, uint64_t HowMany, const std::string & Select,
// std::vector<GWObjects::Device> &Devices, const std::string & orderBy="");
bool DeleteDevice(std::string &SerialNumber);
Expand All @@ -159,10 +160,11 @@ namespace OpenWifi {
bool UpdateDevice(Poco::Data::Session &Sess, GWObjects::Device &NewDeviceDetails);
bool DeviceExists(std::string &SerialNumber);
bool SetConnectInfo(std::string &SerialNumber, std::string &Firmware);
bool GetDeviceCount(uint64_t &Count);
bool GetDeviceCount(uint64_t &Count, const std::string &platform = "");
bool GetDeviceSerialNumbers(uint64_t From, uint64_t HowMany,
std::vector<std::string> &SerialNumbers,
const std::string &orderBy = "");
const std::string &orderBy = "",
const std::string &platform = "");
bool GetDeviceFWUpdatePolicy(std::string &SerialNumber, std::string &Policy);
bool SetDevicePassword(LockedDbSession &Session, std::string &SerialNumber, std::string &Password);
bool UpdateSerialNumberCache();
Expand Down
47 changes: 32 additions & 15 deletions src/storage/storage_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,18 @@ namespace OpenWifi {
R.set<30>(D.connectReason);
}

bool Storage::GetDeviceCount(uint64_t &Count) {
bool Storage::GetDeviceCount(uint64_t &Count, const std::string &platform) {
try {
Poco::Data::Session Sess = Pool_->get();
Poco::Data::Statement Select(Sess);

std::string st{"SELECT COUNT(*) FROM Devices"};

Select << st, Poco::Data::Keywords::into(Count);
if(!platform.empty()) {
std::string st{"SELECT COUNT(*) FROM Devices WHERE DeviceType='" + platform + "'"};
Select << st, Poco::Data::Keywords::into(Count);
} else {
std::string st{"SELECT COUNT(*) FROM Devices"};
Select << st, Poco::Data::Keywords::into(Count);
}
Select.execute();
return true;
} catch (const Poco::Exception &E) {
Expand All @@ -190,16 +194,22 @@ namespace OpenWifi {

bool Storage::GetDeviceSerialNumbers(uint64_t From, uint64_t HowMany,
std::vector<std::string> &SerialNumbers,
const std::string &orderBy) {
const std::string &orderBy,
const std::string &platform) {
try {
Poco::Data::Session Sess = Pool_->get();
Poco::Data::Statement Select(Sess);

std::string st;
if(!platform.empty()) {
st = "SELECT SerialNumber From Devices WHERE DeviceType='" + platform + "' ";
} else {
st = "SELECT SerialNumber From Devices ";
}
if (orderBy.empty())
st = "SELECT SerialNumber From Devices ORDER BY SerialNumber ASC ";
st += " ORDER BY SerialNumber ASC ";
else
st = "SELECT SerialNumber From Devices " + orderBy;
st += orderBy;

Select << st + ComputeRange(From, HowMany), Poco::Data::Keywords::into(SerialNumbers);
Select.execute();
Expand Down Expand Up @@ -536,7 +546,7 @@ namespace OpenWifi {
} catch (const Poco::Exception &E) {
Logger().log(E);
}
return true;
return false;
}

bool Storage::CreateDefaultDevice(Poco::Data::Session &Session, std::string &SerialNumber, const Config::Capabilities &Caps,
Expand Down Expand Up @@ -582,7 +592,7 @@ namespace OpenWifi {
D.locale = InsertRadiosCountyRegulation(D.Configuration, IPAddress);
D.SerialNumber = Poco::toLower(SerialNumber);
D.Compatible = Caps.Compatible();
D.DeviceType = Daemon()->IdentifyDevice(D.Compatible);
D.DeviceType = Caps.Platform();
D.MACAddress = Utils::SerialToMAC(SerialNumber);
D.Manufacturer = Caps.Model();
D.Firmware = Firmware;
Expand Down Expand Up @@ -825,17 +835,24 @@ namespace OpenWifi {
}

bool Storage::GetDevices(uint64_t From, uint64_t HowMany,
std::vector<GWObjects::Device> &Devices, const std::string &orderBy) {
std::vector<GWObjects::Device> &Devices, const std::string &orderBy, const std::string &platform) {
DeviceRecordList Records;
try {
Poco::Data::Session Sess = Pool_->get();
Poco::Data::Statement Select(Sess);

// std::string st{"SELECT " + DB_DeviceSelectFields + " FROM Devices " + orderBy.empty()
// ? " ORDER BY SerialNumber ASC " + ComputeRange(From, HowMany)};
std::string st = fmt::format("SELECT {} FROM Devices {} {}", DB_DeviceSelectFields,
orderBy.empty() ? " ORDER BY SerialNumber ASC " : orderBy,
ComputeRange(From, HowMany));
std::string st;
if(platform.empty()) {
st =
fmt::format("SELECT {} FROM Devices {} {}", DB_DeviceSelectFields,
orderBy.empty() ? " ORDER BY SerialNumber ASC " : orderBy,
ComputeRange(From, HowMany));
} else {
st =
fmt::format("SELECT {} FROM Devices WHERE DeviceType='{}' {} {}", DB_DeviceSelectFields, platform,
orderBy.empty() ? " ORDER BY SerialNumber ASC " : orderBy,
ComputeRange(From, HowMany));
}

Select << ConvertParams(st), Poco::Data::Keywords::into(Records);
Select.execute();
Expand Down

0 comments on commit aa862d3

Please sign in to comment.