diff options
author | Ed Tanous <ed@tanous.net> | 2020-09-29 01:41:28 +0300 |
---|---|---|
committer | Ed Tanous <ed@tanous.net> | 2020-10-07 21:39:41 +0300 |
commit | 5fb91ba400e0482813cf5e1a86fdca17468d0a6a (patch) | |
tree | 6026179632f0aac3273fcf3583c4aa0bd81fd462 /redfish-core/lib | |
parent | 988403c64f7d1937eece8c52a076d5abedfb3b60 (diff) | |
download | bmcweb-5fb91ba400e0482813cf5e1a86fdca17468d0a6a.tar.xz |
Remove adl_serializer uses for json
Several pieces of code seems to be using the adl_serializer from
nlohmann. This unfortunately has very undesirable behavior in some
cases, and makes a lot of things really difficult to track back to the
function that did the serialization, which has caused several bugs in
the past with incorrect types.
This patchset removes them, and opts for the inline version of the
nlohmann json serialization.
Tested:
Booted bmcweb, and logged in.
cat bmcweb_persistent_data.json showed persistent data written properly.
Logged into bmc through webui-vue
systemctl restart bmcweb
Then refreshed webui-vue, and didn't get logged out.
Change-Id: I92868629c54d08b37dd1d956f7c2e2a954f9b670
Diffstat (limited to 'redfish-core/lib')
-rw-r--r-- | redfish-core/lib/cpudimm.hpp | 193 | ||||
-rw-r--r-- | redfish-core/lib/task.hpp | 15 |
2 files changed, 156 insertions, 52 deletions
diff --git a/redfish-core/lib/cpudimm.hpp b/redfish-core/lib/cpudimm.hpp index 6e658dfd04..31db746588 100644 --- a/redfish-core/lib/cpudimm.hpp +++ b/redfish-core/lib/cpudimm.hpp @@ -110,10 +110,6 @@ inline void } aResp->res.jsonValue["TotalCores"] = *coresCount; } - else if (property.first == "MaxSpeedInMhz") - { - aResp->res.jsonValue["MaxSpeedMHz"] = property.second; - } else if (property.first == "Socket") { const std::string* value = @@ -125,7 +121,11 @@ inline void } else if (property.first == "ThreadCount") { - aResp->res.jsonValue["TotalThreads"] = property.second; + const int64_t* value = std::get_if<int64_t>(&property.second); + if (value != nullptr) + { + aResp->res.jsonValue["TotalThreads"] = *value; + } } else if (property.first == "Family") { @@ -642,24 +642,53 @@ inline void getPersistentMemoryProperties(std::shared_ptr<AsyncResp> aResp, } else if (property.first == "VolatileRegionNumberLimit") { - aResp->res.jsonValue["VolatileRegionNumberLimit"] = property.second; + const uint64_t* value = std::get_if<uint64_t>(&property.second); + if (value == nullptr) + { + messages::internalError(aResp->res); + continue; + } + aResp->res.jsonValue["VolatileRegionNumberLimit"] = *value; } else if (property.first == "PmRegionNumberLimit") { - aResp->res.jsonValue["PersistentRegionNumberLimit"] = - property.second; + const uint64_t* value = std::get_if<uint64_t>(&property.second); + if (value == nullptr) + { + messages::internalError(aResp->res); + continue; + } + aResp->res.jsonValue["PersistentRegionNumberLimit"] = *value; } else if (property.first == "SpareDeviceCount") { - aResp->res.jsonValue["SpareDeviceCount"] = property.second; + const uint64_t* value = std::get_if<uint64_t>(&property.second); + if (value == nullptr) + { + messages::internalError(aResp->res); + continue; + } + aResp->res.jsonValue["SpareDeviceCount"] = *value; } else if (property.first == "IsSpareDeviceInUse") { - aResp->res.jsonValue["IsSpareDeviceEnabled"] = property.second; + const bool* value = std::get_if<bool>(&property.second); + if (value == nullptr) + { + messages::internalError(aResp->res); + continue; + } + aResp->res.jsonValue["IsSpareDeviceEnabled"] = *value; } else if (property.first == "IsRankSpareEnabled") { - aResp->res.jsonValue["IsRankSpareEnabled"] = property.second; + const bool* value = std::get_if<bool>(&property.second); + if (value == nullptr) + { + messages::internalError(aResp->res); + continue; + } + aResp->res.jsonValue["IsRankSpareEnabled"] = *value; } else if (property.first == "MaxAveragePowerLimitmW") { @@ -674,13 +703,15 @@ inline void getPersistentMemoryProperties(std::shared_ptr<AsyncResp> aResp, } aResp->res.jsonValue["MaxTDPMilliWatts"] = *value; } - else if (property.first == "CurrentSecurityState") - { - aResp->res.jsonValue["SecurityState"] = property.second; - } else if (property.first == "ConfigurationLocked") { - aResp->res.jsonValue["ConfigurationLocked"] = property.second; + const bool* value = std::get_if<bool>(&property.second); + if (value == nullptr) + { + messages::internalError(aResp->res); + continue; + } + aResp->res.jsonValue["ConfigurationLocked"] = *value; } else if (property.first == "AllowedMemoryModes") { @@ -726,26 +757,31 @@ inline void getPersistentMemoryProperties(std::shared_ptr<AsyncResp> aResp, } } } - // PersistantMemory.PowerManagmentPolicy interface - else if (property.first == "AveragePowerBudgetmW" || - property.first == "MaxTDPmW" || - property.first == "PeakPowerBudgetmW" || - property.first == "PolicyEnabled") - { - std::string name = - boost::replace_all_copy(property.first, "mW", "MilliWatts"); - aResp->res.jsonValue["PowerManagementPolicy"][name] = - property.second; - } // PersistantMemory.SecurityCapabilites interface else if (property.first == "ConfigurationLockCapable" || property.first == "DataLockCapable" || - property.first == "MaxPassphraseCount" || - property.first == "PassphraseCapable" || + property.first == "PassphraseCapable") + { + const bool* value = std::get_if<bool>(&property.second); + if (value == nullptr) + { + messages::internalError(aResp->res); + continue; + } + aResp->res.jsonValue["SecurityCapabilities"][property.first] = + *value; + } + else if (property.first == "MaxPassphraseCount" || property.first == "PassphraseLockLimit") { + const uint64_t* value = std::get_if<uint64_t>(&property.second); + if (value == nullptr) + { + messages::internalError(aResp->res); + continue; + } aResp->res.jsonValue["SecurityCapabilities"][property.first] = - property.second; + *value; } } } @@ -802,19 +838,43 @@ inline void getDimmDataByService(std::shared_ptr<AsyncResp> aResp, { if (property.first == "MemoryDataWidth") { - aResp->res.jsonValue["DataWidthBits"] = property.second; + const uint16_t* value = + std::get_if<uint16_t>(&property.second); + if (value == nullptr) + { + continue; + } + aResp->res.jsonValue["DataWidthBits"] = *value; } else if (property.first == "PartNumber") { - aResp->res.jsonValue["PartNumber"] = property.second; + const std::string* value = + std::get_if<std::string>(&property.second); + if (value == nullptr) + { + continue; + } + aResp->res.jsonValue["PartNumber"] = *value; } else if (property.first == "SerialNumber") { - aResp->res.jsonValue["SerialNumber"] = property.second; + const std::string* value = + std::get_if<std::string>(&property.second); + if (value == nullptr) + { + continue; + } + aResp->res.jsonValue["SerialNumber"] = *value; } else if (property.first == "Manufacturer") { - aResp->res.jsonValue["Manufacturer"] = property.second; + const std::string* value = + std::get_if<std::string>(&property.second); + if (value == nullptr) + { + continue; + } + aResp->res.jsonValue["Manufacturer"] = *value; } else if (property.first == "RevisionCode") { @@ -833,7 +893,13 @@ inline void getDimmDataByService(std::shared_ptr<AsyncResp> aResp, } else if (property.first == "MemoryTotalWidth") { - aResp->res.jsonValue["BusWidthBits"] = property.second; + const uint16_t* value = + std::get_if<uint16_t>(&property.second); + if (value == nullptr) + { + continue; + } + aResp->res.jsonValue["BusWidthBits"] = *value; } else if (property.first == "ECC") { @@ -886,7 +952,19 @@ inline void getDimmDataByService(std::shared_ptr<AsyncResp> aResp, } else if (property.first == "AllowedSpeedsMT") { - aResp->res.jsonValue["AllowedSpeedsMHz"] = property.second; + const std::vector<uint16_t>* value = + std::get_if<std::vector<uint16_t>>(&property.second); + if (value == nullptr) + { + continue; + } + nlohmann::json& jValue = + aResp->res.jsonValue["AllowedSpeedsMHz"]; + jValue = nlohmann::json::array(); + for (uint16_t subVal : *value) + { + jValue.push_back(subVal); + } } else if (property.first == "MemoryAttributes") { @@ -905,7 +983,13 @@ inline void getDimmDataByService(std::shared_ptr<AsyncResp> aResp, } else if (property.first == "MemoryConfiguredSpeedInMhz") { - aResp->res.jsonValue["OperatingSpeedMhz"] = property.second; + const uint16_t* value = + std::get_if<uint16_t>(&property.second); + if (value == nullptr) + { + continue; + } + aResp->res.jsonValue["OperatingSpeedMhz"] = *value; } else if (property.first == "MemoryType") { @@ -938,8 +1022,15 @@ inline void getDimmDataByService(std::shared_ptr<AsyncResp> aResp, property.first == "MemoryController" || property.first == "Slot" || property.first == "Socket") { + const std::string* value = + std::get_if<std::string>(&property.second); + if (value == nullptr) + { + messages::internalError(aResp->res); + continue; + } aResp->res.jsonValue["MemoryLocation"][property.first] = - property.second; + *value; } else { @@ -975,7 +1066,13 @@ inline void getDimmPartitionData(std::shared_ptr<AsyncResp> aResp, { if (key == "MemoryClassification") { - partition[key] = val; + const std::string* value = std::get_if<std::string>(&val); + if (value == nullptr) + { + messages::internalError(aResp->res); + continue; + } + partition[key] = *value; } else if (key == "OffsetInKiB") { @@ -983,8 +1080,6 @@ inline void getDimmPartitionData(std::shared_ptr<AsyncResp> aResp, if (value == nullptr) { messages::internalError(aResp->res); - BMCWEB_LOG_DEBUG - << "Invalid property type for OffsetInKiB"; continue; } @@ -992,12 +1087,24 @@ inline void getDimmPartitionData(std::shared_ptr<AsyncResp> aResp, } else if (key == "PartitionId") { - partition["RegionId"] = val; + const std::string* value = std::get_if<std::string>(&val); + if (value == nullptr) + { + messages::internalError(aResp->res); + continue; + } + partition["RegionId"] = *value; } else if (key == "PassphraseState") { - partition["PassphraseEnabled"] = val; + const bool* value = std::get_if<bool>(&val); + if (value == nullptr) + { + messages::internalError(aResp->res); + continue; + } + partition["PassphraseEnabled"] = *value; } else if (key == "SizeInKiB") { diff --git a/redfish-core/lib/task.hpp b/redfish-core/lib/task.hpp index 8083566d45..19973d96ad 100644 --- a/redfish-core/lib/task.hpp +++ b/redfish-core/lib/task.hpp @@ -80,14 +80,6 @@ struct Payload nlohmann::json jsonBody; }; -inline void to_json(nlohmann::json& j, const Payload& p) -{ - j = {{"TargetUri", p.targetUri}, - {"HttpOperation", p.httpOperation}, - {"HttpHeaders", p.httpHeaders}, - {"JsonBody", p.jsonBody.dump()}}; -} - struct TaskData : std::enable_shared_from_this<TaskData> { private: @@ -448,7 +440,12 @@ class Task : public Node } if (ptr->payload) { - asyncResp->res.jsonValue["Payload"] = *(ptr->payload); + const task::Payload& p = *(ptr->payload); + asyncResp->res.jsonValue["Payload"] = { + {"TargetUri", p.targetUri}, + {"HttpOperation", p.httpOperation}, + {"HttpHeaders", p.httpHeaders}, + {"JsonBody", p.jsonBody.dump()}}; } } }; |