From 18f8f608b966c802b3e2a389e3c1ec5a1fd9407b Mon Sep 17 00:00:00 2001 From: Ed Tanous Date: Tue, 18 Jul 2023 10:07:23 -0700 Subject: 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 --- include/http_utility.hpp | 6 +----- include/ibm/locks.hpp | 25 +++++++++++-------------- include/ibm/management_console_rest.hpp | 4 ++-- include/openbmc_dbus_rest.hpp | 16 ++++++++++++---- include/str_utility.hpp | 20 ++++++++++++++++++++ include/webassets.hpp | 1 - 6 files changed, 46 insertions(+), 26 deletions(-) (limited to 'include') diff --git a/include/http_utility.hpp b/include/http_utility.hpp index ae436caf1c..74ab15a86e 100644 --- a/include/http_utility.hpp +++ b/include/http_utility.hpp @@ -1,10 +1,6 @@ #pragma once -#include -#include -#include -#include - +#include #include #include #include diff --git a/include/ibm/locks.hpp b/include/ibm/locks.hpp index 7a161fc754..3bb82b9479 100644 --- a/include/ibm/locks.hpp +++ b/include/ibm/locks.hpp @@ -3,7 +3,6 @@ #include "ibm/utils.hpp" #include "logging.hpp" -#include #include #include #include @@ -363,8 +362,8 @@ inline bool Lock::isValidLockRequest(const LockRequest& refLockRecord) { // validate the locktype - if (!((boost::equals(std::get<2>(refLockRecord), "Read") || - (boost::equals(std::get<2>(refLockRecord), "Write"))))) + if (!((std::get<2>(refLockRecord) == "Read" || + (std::get<2>(refLockRecord) == "Write")))) { BMCWEB_LOG_DEBUG("Validation of LockType Failed"); BMCWEB_LOG_DEBUG("Locktype : {}", std::get<2>(refLockRecord)); @@ -392,9 +391,8 @@ inline bool Lock::isValidLockRequest(const LockRequest& refLockRecord) // validate the lock flags // Allowed lockflags are locksame,lockall & dontlock - if (!((boost::equals(p.first, "LockSame") || - (boost::equals(p.first, "LockAll")) || - (boost::equals(p.first, "DontLock"))))) + if (!((p.first == "LockSame" || (p.first == "LockAll") || + (p.first == "DontLock")))) { BMCWEB_LOG_DEBUG("Validation of lock flags failed"); BMCWEB_LOG_DEBUG("{}", p.first); @@ -411,8 +409,7 @@ inline bool Lock::isValidLockRequest(const LockRequest& refLockRecord) return false; } - if ((boost::equals(p.first, "LockSame") || - (boost::equals(p.first, "LockAll")))) + if ((p.first == "LockSame" || (p.first == "LockAll"))) { ++lockFlag; if (lockFlag >= 2) @@ -534,8 +531,8 @@ inline bool Lock::isConflictRecord(const LockRequest& refLockRecord1, { // No conflict if both are read locks - if (boost::equals(std::get<2>(refLockRecord1), "Read") && - boost::equals(std::get<2>(refLockRecord2), "Read")) + if (std::get<2>(refLockRecord1) == "Read" && + std::get<2>(refLockRecord2) == "Read") { BMCWEB_LOG_DEBUG("Both are read locks, no conflict"); return false; @@ -546,8 +543,8 @@ inline bool Lock::isConflictRecord(const LockRequest& refLockRecord1, { // return conflict when any of them is try to lock all resources // under the current resource level. - if (boost::equals(p.first, "LockAll") || - boost::equals(std::get<4>(refLockRecord2)[i].first, "LockAll")) + if (p.first == "LockAll" || + std::get<4>(refLockRecord2)[i].first == "LockAll") { BMCWEB_LOG_DEBUG( "Either of the Comparing locks are trying to lock all " @@ -558,8 +555,8 @@ inline bool Lock::isConflictRecord(const LockRequest& refLockRecord1, // determine if there is a lock-all-with-same-segment-size. // If the current segment sizes are the same,then we should fail. - if ((boost::equals(p.first, "LockSame") || - boost::equals(std::get<4>(refLockRecord2)[i].first, "LockSame")) && + if ((p.first == "LockSame" || + std::get<4>(refLockRecord2)[i].first == "LockSame") && (p.second == std::get<4>(refLockRecord2)[i].second)) { return true; diff --git a/include/ibm/management_console_rest.hpp b/include/ibm/management_console_rest.hpp index fd1e2a5cc8..103017bf09 100644 --- a/include/ibm/management_console_rest.hpp +++ b/include/ibm/management_console_rest.hpp @@ -6,9 +6,9 @@ #include "event_service_manager.hpp" #include "ibm/locks.hpp" #include "resource_messages.hpp" +#include "str_utility.hpp" #include "utils/json_utils.hpp" -#include #include #include #include @@ -49,7 +49,7 @@ inline void handleFilePut(const crow::Request& req, std::error_code ec; // Check the content-type of the request boost::beast::string_view contentType = req.getHeaderValue("content-type"); - if (!boost::iequals(contentType, "application/octet-stream")) + if (!bmcweb::asciiIEquals(contentType, "application/octet-stream")) { asyncResp->res.result(boost::beast::http::status::not_acceptable); asyncResp->res.jsonValue["Description"] = contentNotAcceptableMsg; diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp index 6bd3920587..e801a3291c 100644 --- a/include/openbmc_dbus_rest.hpp +++ b/include/openbmc_dbus_rest.hpp @@ -28,8 +28,6 @@ #include #include -#include -#include #include #include #include @@ -429,7 +427,10 @@ inline void getObjectAndEnumerate( // Map indicating connection name, and the path where the object // manager exists - boost::container::flat_map connections; + boost::container::flat_map< + std::string, std::string, std::less<>, + std::vector>> + connections; for (const auto& object : *(transaction->subtree)) { @@ -711,7 +712,14 @@ inline int convertJsonToDbus(sd_bus_message* m, const std::string& argType, } else if (stringValue != nullptr) { - boolInt = boost::istarts_with(*stringValue, "t") ? 1 : 0; + if (!stringValue->empty()) + { + if (stringValue->front() == 't' || + stringValue->front() == 'T') + { + boolInt = 1; + } + } } else { diff --git a/include/str_utility.hpp b/include/str_utility.hpp index 7142583ee2..8ac54b9182 100644 --- a/include/str_utility.hpp +++ b/include/str_utility.hpp @@ -1,5 +1,7 @@ #pragma once +#include +#include #include #include #include @@ -21,4 +23,22 @@ inline void split(std::vector& strings, std::string_view str, start = end + 1; } } + +inline char asciiToLower(char c) +{ + // Converts a character to lower case without relying on std::locale + if ('A' <= c && c <= 'Z') + { + c -= ('A' - 'a'); + } + return c; +} + +inline bool asciiIEquals(std::string_view left, std::string_view right) +{ + return std::ranges::equal(left, right, [](char lChar, char rChar) { + return asciiToLower(lChar) == asciiToLower(rChar); + }); +} + } // namespace bmcweb diff --git a/include/webassets.hpp b/include/webassets.hpp index 5ab03231e4..c5c7228ede 100644 --- a/include/webassets.hpp +++ b/include/webassets.hpp @@ -6,7 +6,6 @@ #include "routing.hpp" #include "webroutes.hpp" -#include #include #include -- cgit v1.2.3