summaryrefslogtreecommitdiff
path: root/redfish-core
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2023-07-18 20:07:23 +0300
committerEd Tanous <ed@tanous.net>2024-01-19 22:43:50 +0300
commit18f8f608b966c802b3e2a389e3c1ec5a1fd9407b (patch)
tree89684cb74b7492ffc1e34fb8e3a004de18726071 /redfish-core
parentf86bcc875a496b3c321a4ed102579a4031617800 (diff)
downloadbmcweb-18f8f608b966c802b3e2a389e3c1ec5a1fd9407b.tar.xz
Remove some boost includes
The less we rely on boost, and more on std algorithms, the less people have to look up, and the more likely that our code will deduplicate. Replace all uses of boost::algorithms with std alternatives. Tested: Redfish Service Validator passes. Change-Id: I8a26f39b5709adc444b4178e92f5f3c7b988b05b Signed-off-by: Ed Tanous <edtanous@google.com>
Diffstat (limited to 'redfish-core')
-rw-r--r--redfish-core/include/event_service_manager.hpp1
-rw-r--r--redfish-core/include/redfish_aggregator.hpp23
-rw-r--r--redfish-core/include/utils/query_param.hpp1
-rw-r--r--redfish-core/lib/ethernet.hpp2
-rw-r--r--redfish-core/lib/health.hpp2
-rw-r--r--redfish-core/lib/log_services.hpp50
-rw-r--r--redfish-core/lib/managers.hpp7
-rw-r--r--redfish-core/lib/network_protocol.hpp2
-rw-r--r--redfish-core/lib/sensors.hpp34
-rw-r--r--redfish-core/lib/update_service.hpp3
10 files changed, 59 insertions, 66 deletions
diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp
index 7399d2e15e..cac6b8b2b2 100644
--- a/redfish-core/include/event_service_manager.hpp
+++ b/redfish-core/include/event_service_manager.hpp
@@ -29,7 +29,6 @@
#include <sys/inotify.h>
-#include <boost/algorithm/string/classification.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/container/flat_map.hpp>
#include <boost/url/format.hpp>
diff --git a/redfish-core/include/redfish_aggregator.hpp b/redfish-core/include/redfish_aggregator.hpp
index 4ce25fdcf3..f255b9f0a6 100644
--- a/redfish-core/include/redfish_aggregator.hpp
+++ b/redfish-core/include/redfish_aggregator.hpp
@@ -5,8 +5,7 @@
#include "error_messages.hpp"
#include "http_client.hpp"
#include "http_connection.hpp"
-
-#include <boost/algorithm/string/predicate.hpp>
+#include "parsing.hpp"
#include <array>
#include <ranges>
@@ -154,8 +153,12 @@ inline bool searchCollectionsArray(std::string_view uri,
// defined in the above array.
inline bool isPropertyUri(std::string_view propertyName)
{
- return boost::iends_with(propertyName, "uri") ||
- std::binary_search(nonUriProperties.begin(), nonUriProperties.end(),
+ if (propertyName.ends_with("uri") || propertyName.ends_with("Uri") ||
+ propertyName.ends_with("URI"))
+ {
+ return true;
+ }
+ return std::binary_search(nonUriProperties.begin(), nonUriProperties.end(),
propertyName);
}
@@ -870,9 +873,7 @@ class RedfishAggregator
// We want to attempt prefix fixing regardless of response code
// The resp will not have a json component
// We need to create a json from resp's stringResponse
- std::string_view contentType = resp.getHeaderValue("Content-Type");
- if (boost::iequals(contentType, "application/json") ||
- boost::iequals(contentType, "application/json; charset=utf-8"))
+ if (isJsonContentType(resp.getHeaderValue("Content-Type")))
{
nlohmann::json jsonVal = nlohmann::json::parse(*resp.body(),
nullptr, false);
@@ -934,9 +935,7 @@ class RedfishAggregator
// The resp will not have a json component
// We need to create a json from resp's stringResponse
- std::string_view contentType = resp.getHeaderValue("Content-Type");
- if (boost::iequals(contentType, "application/json") ||
- boost::iequals(contentType, "application/json; charset=utf-8"))
+ if (isJsonContentType(resp.getHeaderValue("Content-Type")))
{
nlohmann::json jsonVal = nlohmann::json::parse(*resp.body(),
nullptr, false);
@@ -1068,9 +1067,7 @@ class RedfishAggregator
// The resp will not have a json component
// We need to create a json from resp's stringResponse
- std::string_view contentType = resp.getHeaderValue("Content-Type");
- if (boost::iequals(contentType, "application/json") ||
- boost::iequals(contentType, "application/json; charset=utf-8"))
+ if (isJsonContentType(resp.getHeaderValue("Content-Type")))
{
bool addedLinks = false;
nlohmann::json jsonVal = nlohmann::json::parse(*resp.body(),
diff --git a/redfish-core/include/utils/query_param.hpp b/redfish-core/include/utils/query_param.hpp
index 55c92bca42..03b5f53b6b 100644
--- a/redfish-core/include/utils/query_param.hpp
+++ b/redfish-core/include/utils/query_param.hpp
@@ -11,7 +11,6 @@
#include <sys/types.h>
-#include <boost/algorithm/string/classification.hpp>
#include <boost/beast/http/message.hpp> // IWYU pragma: keep
#include <boost/beast/http/status.hpp>
#include <boost/beast/http/verb.hpp>
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index 099aab83f9..390efbcc36 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -28,8 +28,6 @@
#include "utils/ip_utils.hpp"
#include "utils/json_utils.hpp"
-#include <boost/algorithm/string/classification.hpp>
-#include <boost/algorithm/string/split.hpp>
#include <boost/url/format.hpp>
#include <array>
diff --git a/redfish-core/lib/health.hpp b/redfish-core/lib/health.hpp
index 6e0d3349bd..20ea0f6236 100644
--- a/redfish-core/lib/health.hpp
+++ b/redfish-core/lib/health.hpp
@@ -73,7 +73,7 @@ struct HealthPopulate : std::enable_shared_from_this<HealthPopulate>
bool isSelf = false;
if (selfPath)
{
- if (boost::equals(path.str, *selfPath) ||
+ if (path.str == *selfPath ||
path.str.starts_with(*selfPath + "/"))
{
isSelf = true;
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index e634191151..371ae44867 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -36,10 +36,6 @@
#include <tinyxml2.h>
#include <unistd.h>
-#include <boost/algorithm/string/case_conv.hpp>
-#include <boost/algorithm/string/classification.hpp>
-#include <boost/algorithm/string/replace.hpp>
-#include <boost/algorithm/string/split.hpp>
#include <boost/beast/http/verb.hpp>
#include <boost/container/flat_map.hpp>
#include <boost/system/linux_error.hpp>
@@ -50,9 +46,11 @@
#include <array>
#include <charconv>
#include <filesystem>
+#include <iterator>
#include <optional>
#include <ranges>
#include <span>
+#include <string>
#include <string_view>
#include <variant>
@@ -115,6 +113,15 @@ inline std::optional<bool> getProviderNotifyAction(const std::string& notify)
return notifyAction;
}
+inline std::string getDumpPath(std::string_view dumpType)
+{
+ std::string dbusDumpPath = "/xyz/openbmc_project/dump/";
+ std::ranges::transform(dumpType, std::back_inserter(dbusDumpPath),
+ bmcweb::asciiToLower);
+
+ return dbusDumpPath;
+}
+
inline static int getJournalMetadata(sd_journal* journal,
std::string_view field,
std::string_view& contents)
@@ -537,9 +544,7 @@ inline void
" Dump Entries";
nlohmann::json::array_t entriesArray;
- std::string dumpEntryPath =
- "/xyz/openbmc_project/dump/" +
- std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/";
+ std::string dumpEntryPath = getDumpPath(dumpType) + "/entry/";
dbus::utility::ManagedObjectType resp(objects);
std::ranges::sort(resp, [](const auto& l, const auto& r) {
@@ -640,9 +645,7 @@ inline void
}
bool foundDumpEntry = false;
- std::string dumpEntryPath =
- "/xyz/openbmc_project/dump/" +
- std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/";
+ std::string dumpEntryPath = getDumpPath(dumpType) + "/entry/";
for (const auto& objectPath : resp)
{
@@ -736,11 +739,10 @@ inline void deleteDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
return;
}
};
+
crow::connections::systemBus->async_method_call(
respHandler, "xyz.openbmc_project.Dump.Manager",
- "/xyz/openbmc_project/dump/" +
- std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/" +
- entryID,
+ std::format("{}/entry/{}", getDumpPath(dumpType), entryID),
"xyz.openbmc_project.Object.Delete", "Delete");
}
@@ -847,10 +849,8 @@ inline void
return;
}
- std::string dumpEntryPath =
- sdbusplus::message::object_path("/xyz/openbmc_project/dump/") /
- std::string(boost::algorithm::to_lower_copy(dumpType)) / "entry" /
- entryID;
+ std::string dumpEntryPath = std::format("{}/entry/{}",
+ getDumpPath(dumpType), entryID);
auto downloadDumpEntryHandler =
[asyncResp, entryID,
@@ -1212,18 +1212,13 @@ inline void createDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
BMCWEB_LOG_DEBUG("Dump Created. Path: {}", objPath.str);
createDumpTaskCallback(std::move(payload), asyncResp, objPath);
},
- "xyz.openbmc_project.Dump.Manager",
- "/xyz/openbmc_project/dump/" +
- std::string(boost::algorithm::to_lower_copy(dumpType)),
+ "xyz.openbmc_project.Dump.Manager", getDumpPath(dumpType),
"xyz.openbmc_project.Dump.Create", "CreateDump", createDumpParamVec);
}
inline void clearDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& dumpType)
{
- std::string dumpTypeLowerCopy =
- std::string(boost::algorithm::to_lower_copy(dumpType));
-
crow::connections::systemBus->async_method_call(
[asyncResp](const boost::system::error_code& ec) {
if (ec)
@@ -1233,8 +1228,7 @@ inline void clearDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
return;
}
},
- "xyz.openbmc_project.Dump.Manager",
- "/xyz/openbmc_project/dump/" + dumpTypeLowerCopy,
+ "xyz.openbmc_project.Dump.Manager", getDumpPath(dumpType),
"xyz.openbmc_project.Collection.DeleteAll", "DeleteAll");
}
@@ -2836,11 +2830,7 @@ inline void
// LogServices. Return without adding any error response.
return;
}
-
- const std::string dbusDumpPath =
- "/xyz/openbmc_project/dump/" +
- boost::algorithm::to_lower_copy(dumpType);
-
+ std::string dbusDumpPath = getDumpPath(dumpType);
for (const std::string& path : subTreePaths)
{
if (path == dbusDumpPath)
diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp
index 38add8be5b..c61132f215 100644
--- a/redfish-core/lib/managers.hpp
+++ b/redfish-core/lib/managers.hpp
@@ -743,7 +743,7 @@ inline const dbus::utility::ManagedObjectType::value_type*
std::replace(escaped.begin(), escaped.end(), ' ', '_');
escaped = "/" + escaped;
auto it = std::ranges::find_if(managedObj, [&escaped](const auto& obj) {
- if (boost::algorithm::ends_with(obj.first.str, escaped))
+ if (obj.first.str.ends_with(escaped))
{
BMCWEB_LOG_DEBUG("Matched {}", obj.first.str);
return true;
@@ -1492,8 +1492,7 @@ struct SetPIDValues : std::enable_shared_from_this<SetPIDValues>
auto pathItr = std::ranges::find_if(
managedObj, [&dbusObjName](const auto& obj) {
- return boost::algorithm::ends_with(obj.first.str,
- "/" + dbusObjName);
+ return obj.first.parent_path() == dbusObjName;
});
dbus::utility::DBusPropertiesMap output;
@@ -1621,7 +1620,7 @@ struct SetPIDValues : std::enable_shared_from_this<SetPIDValues>
bool foundChassis = false;
for (const auto& obj : managedObj)
{
- if (boost::algorithm::ends_with(obj.first.str, chassis))
+ if (obj.first.parent_path() == chassis)
{
chassis = obj.first.str;
foundChassis = true;
diff --git a/redfish-core/lib/network_protocol.hpp b/redfish-core/lib/network_protocol.hpp
index 151f993d61..c57343c3bd 100644
--- a/redfish-core/lib/network_protocol.hpp
+++ b/redfish-core/lib/network_protocol.hpp
@@ -404,7 +404,7 @@ inline void
for (const auto& entry : subtree)
{
- if (boost::algorithm::starts_with(entry.first, netBasePath))
+ if (entry.first.starts_with(netBasePath))
{
sdbusplus::asio::setProperty(
*crow::connections::systemBus, entry.second.begin()->first,
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index 19e32cec7f..1935adc136 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -26,11 +26,6 @@
#include "utils/json_utils.hpp"
#include "utils/query_param.hpp"
-#include <boost/algorithm/string/classification.hpp>
-#include <boost/algorithm/string/find.hpp>
-#include <boost/algorithm/string/predicate.hpp>
-#include <boost/algorithm/string/replace.hpp>
-#include <boost/range/algorithm/replace_copy_if.hpp>
#include <boost/system/error_code.hpp>
#include <boost/url/format.hpp>
#include <sdbusplus/asio/property.hpp>
@@ -43,6 +38,7 @@
#include <map>
#include <ranges>
#include <set>
+#include <string>
#include <string_view>
#include <utility>
#include <variant>
@@ -823,7 +819,10 @@ inline void objectPropertiesToJson(
}
else if (sensorType == "power")
{
- if (boost::iequals(sensorName, "total_power"))
+ std::string lower;
+ std::ranges::transform(sensorName, std::back_inserter(lower),
+ bmcweb::asciiToLower);
+ if (lower == "total_power")
{
sensorJson["@odata.type"] = "#Power.v1_0_0.PowerControl";
// Put multiple "sensors" into a single PowerControl, so have
@@ -832,7 +831,7 @@ inline void objectPropertiesToJson(
sensorJson["Name"] = "Chassis Power Control";
unit = "/PowerConsumedWatts"_json_pointer;
}
- else if (!(boost::ifind_first(sensorName, "input").empty()))
+ else if (lower.find("input") != std::string::npos)
{
unit = "/PowerInputWatts"_json_pointer;
}
@@ -1073,7 +1072,7 @@ inline void populateFanRedundancy(
sensorsAsyncResp->asyncResp->res);
return;
}
- std::replace(name.begin(), name.end(), '_', ' ');
+ std::ranges::replace(name, '_', ' ');
std::string health;
@@ -2186,11 +2185,22 @@ inline nlohmann::json& getPowerSupply(nlohmann::json& powerSupplyArray,
const InventoryItem& inventoryItem,
const std::string& chassisId)
{
+ std::string nameS;
+ std::ranges::replace_copy(inventoryItem.name, nameS.begin(), '_', ' ');
// Check if matching PowerSupply object already exists in JSON array
for (nlohmann::json& powerSupply : powerSupplyArray)
{
- if (powerSupply["Name"] ==
- boost::replace_all_copy(inventoryItem.name, "_", " "))
+ nlohmann::json::iterator nameIt = powerSupply.find("Name");
+ if (nameIt == powerSupply.end())
+ {
+ continue;
+ }
+ const std::string* name = nameIt->get_ptr<std::string*>();
+ if (name == nullptr)
+ {
+ continue;
+ }
+ if (nameS == *name)
{
return powerSupply;
}
@@ -2203,7 +2213,9 @@ inline nlohmann::json& getPowerSupply(nlohmann::json& powerSupplyArray,
chassisId);
url.set_fragment(("/PowerSupplies"_json_pointer).to_string());
powerSupply["@odata.id"] = std::move(url);
- powerSupply["Name"] = boost::replace_all_copy(inventoryItem.name, "_", " ");
+ std::string escaped;
+ std::ranges::replace_copy(inventoryItem.name, escaped.begin(), '_', ' ');
+ powerSupply["Name"] = std::move(escaped);
powerSupply["Manufacturer"] = inventoryItem.manufacturer;
powerSupply["Model"] = inventoryItem.model;
powerSupply["PartNumber"] = inventoryItem.partNumber;
diff --git a/redfish-core/lib/update_service.hpp b/redfish-core/lib/update_service.hpp
index 9a07d3c334..74e110170a 100644
--- a/redfish-core/lib/update_service.hpp
+++ b/redfish-core/lib/update_service.hpp
@@ -28,7 +28,6 @@
#include "utils/dbus_utils.hpp"
#include "utils/sw_utils.hpp"
-#include <boost/algorithm/string/case_conv.hpp>
#include <boost/system/error_code.hpp>
#include <boost/url/format.hpp>
#include <sdbusplus/asio/property.hpp>
@@ -731,7 +730,7 @@ inline void
// Make sure that content type is application/octet-stream or
// multipart/form-data
- if (boost::iequals(contentType, "application/octet-stream"))
+ if (bmcweb::asciiIEquals(contentType, "application/octet-stream"))
{
// Setup callback for when new software detected
monitorForSoftwareAvailable(asyncResp, req,