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>
diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp
index 7399d2e..cac6b8b 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 4ce25fd..f255b9f 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 @@
// 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 @@
// 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 @@
// 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 @@
// 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 55c92bc..03b5f53 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 099aab8..390efbc 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 6e0d334..20ea0f6 100644
--- a/redfish-core/lib/health.hpp
+++ b/redfish-core/lib/health.hpp
@@ -73,7 +73,7 @@
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 e634191..371ae44 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 @@
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 @@
" 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 @@
}
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 @@
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 @@
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 @@
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 @@
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 @@
// 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 38add8b..c61132f 100644
--- a/redfish-core/lib/managers.hpp
+++ b/redfish-core/lib/managers.hpp
@@ -743,7 +743,7 @@
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 @@
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 @@
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 151f993..c57343c 100644
--- a/redfish-core/lib/network_protocol.hpp
+++ b/redfish-core/lib/network_protocol.hpp
@@ -404,7 +404,7 @@
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 19e32ce..1935adc 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 @@
}
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 @@
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 @@
sensorsAsyncResp->asyncResp->res);
return;
}
- std::replace(name.begin(), name.end(), '_', ' ');
+ std::ranges::replace(name, '_', ' ');
std::string health;
@@ -2186,11 +2185,22 @@
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 @@
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 9a07d3c..74e1101 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 @@
// 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,