summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Tanous <edtanous@google.com>2022-07-01 02:50:15 +0300
committerEd Tanous <ed@tanous.net>2022-07-12 21:38:38 +0300
commit02cad96e3a83b0c9a01dbc87219c1b8b6681fa67 (patch)
treea2dab0f07fe50ed5708f3c6fea43b7d2af5419e7
parentbb60f4ded18153718709e23dc1d648eb2ae13743 (diff)
downloadbmcweb-02cad96e3a83b0c9a01dbc87219c1b8b6681fa67.tar.xz
Fix const correctness issues
cppcheck correctly notes that a lot of variables in the new code can be const. Make most of them const. Tested: WIP Signed-off-by: Ed Tanous <edtanous@google.com> Change-Id: I8f37b6353fd707923f533e1d61c5b5419282bf23
-rw-r--r--http/http_client.hpp4
-rw-r--r--include/authentication.hpp4
-rw-r--r--include/ibm/management_console_rest.hpp4
-rw-r--r--include/openbmc_dbus_rest.hpp4
-rw-r--r--redfish-core/include/event_service_manager.hpp14
-rw-r--r--redfish-core/include/utils/query_param.hpp3
-rw-r--r--redfish-core/lib/account_service.hpp2
-rw-r--r--redfish-core/lib/certificate_service.hpp2
-rw-r--r--redfish-core/lib/ethernet.hpp14
-rw-r--r--redfish-core/lib/log_services.hpp13
-rw-r--r--redfish-core/lib/managers.hpp16
-rw-r--r--redfish-core/lib/network_protocol.hpp2
-rw-r--r--redfish-core/lib/sensors.hpp20
-rw-r--r--redfish-core/lib/systems.hpp12
-rw-r--r--redfish-core/lib/task.hpp4
-rw-r--r--redfish-core/lib/virtual_media.hpp12
-rw-r--r--redfish-core/ut/lock_test.cpp2
17 files changed, 66 insertions, 66 deletions
diff --git a/http/http_client.hpp b/http/http_client.hpp
index 63c2611a2d..f59438be8c 100644
--- a/http/http_client.hpp
+++ b/http/http_client.hpp
@@ -632,7 +632,7 @@ class HttpClient
// Used as a dummy callback by sendData() in order to call
// sendDataWithCallback()
- static void genericResHandler(Response& res)
+ static void genericResHandler(const Response& res)
{
BMCWEB_LOG_DEBUG << "Response handled with return code: "
<< std::to_string(res.resultInt());
@@ -660,7 +660,7 @@ class HttpClient
const boost::beast::http::verb verb,
const std::string& retryPolicyName)
{
- std::function<void(Response&)> cb = genericResHandler;
+ const std::function<void(const Response&)> cb = genericResHandler;
sendDataWithCallback(data, id, destIP, destPort, destUri, httpHeader,
verb, retryPolicyName, cb);
}
diff --git a/include/authentication.hpp b/include/authentication.hpp
index 3c1ca484d9..8d59be406e 100644
--- a/include/authentication.hpp
+++ b/include/authentication.hpp
@@ -21,7 +21,7 @@ namespace crow
namespace authentication
{
-static void cleanupTempSession(Request& req)
+static void cleanupTempSession(const Request& req)
{
// TODO(ed) THis should really be handled by the persistent data
// middleware, but because it is upstream, it doesn't have access to the
@@ -260,7 +260,7 @@ static std::shared_ptr<persistent_data::UserSession>
[[maybe_unused]] static std::shared_ptr<persistent_data::UserSession>
authenticate(
- boost::asio::ip::address& ipAddress [[maybe_unused]],
+ const boost::asio::ip::address& ipAddress [[maybe_unused]],
Response& res [[maybe_unused]], boost::beast::http::verb method,
const boost::beast::http::header<true>& reqHeader,
[[maybe_unused]] const std::shared_ptr<persistent_data::UserSession>&
diff --git a/include/ibm/management_console_rest.hpp b/include/ibm/management_console_rest.hpp
index 2bede28220..8d50c9f147 100644
--- a/include/ibm/management_console_rest.hpp
+++ b/include/ibm/management_console_rest.hpp
@@ -520,7 +520,7 @@ inline void
returnJson["LockType"] = std::get<2>(var.second);
returnJson["ResourceID"] = std::get<3>(var.second);
- for (auto& i : std::get<4>(var.second))
+ for (const auto& i : std::get<4>(var.second))
{
segments["LockFlag"] = i.first;
segments["SegmentLength"] = i.second;
@@ -588,7 +588,7 @@ inline void
returnJson["LockType"] = std::get<2>(var.second);
returnJson["ResourceID"] = std::get<3>(var.second);
- for (auto& i : std::get<4>(var.second))
+ for (const auto& i : std::get<4>(var.second))
{
segments["LockFlag"] = i.first;
segments["SegmentLength"] = i.second;
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index 0e2af700f6..d0bc29c3d1 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -2340,7 +2340,7 @@ inline void
nlohmann::json& propertyItem = propertiesObj[name];
crow::connections::systemBus->async_send(
m, [&propertyItem,
- asyncResp](boost::system::error_code& e,
+ asyncResp](const boost::system::error_code& e,
sdbusplus::message::message& msg) {
if (e)
{
@@ -2420,7 +2420,7 @@ inline void requestRoutes(App& app)
std::sort(names.begin(), names.end());
asyncResp->res.jsonValue["status"] = "ok";
auto& objectsSub = asyncResp->res.jsonValue["objects"];
- for (auto& name : names)
+ for (const auto& name : names)
{
nlohmann::json::object_t object;
object["name"] = name;
diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp
index 7e249ba3a8..aa7f0eb261 100644
--- a/redfish-core/include/event_service_manager.hpp
+++ b/redfish-core/include/event_service_manager.hpp
@@ -119,8 +119,8 @@ static const Message* formatMessage(const std::string_view& messageID)
{
return nullptr;
}
- std::string& registryName = fields[0];
- std::string& messageKey = fields[3];
+ const std::string& registryName = fields[0];
+ const std::string& messageKey = fields[3];
// Find the right registry and check it for the MessageKey
return getMsgFromRegistry(messageKey, getRegistryFromPrefix(registryName));
@@ -194,7 +194,7 @@ inline int getEventLogParams(const std::string& logEntry,
// Get the MessageArgs from the log if there are any
if (logEntryFields.size() > 1)
{
- std::string& messageArgsStart = logEntryFields[1];
+ const std::string& messageArgsStart = logEntryFields[1];
// If the first string is empty, assume there are no MessageArgs
if (!messageArgsStart.empty())
{
@@ -307,13 +307,13 @@ inline bool
for (std::size_t i = 0; i < result.size(); i += divisor)
{
- std::string& key = result[i];
- std::string& op = result[i + 1];
- std::string& value = result[i + 2];
+ const std::string& key = result[i];
+ const std::string& op = result[i + 1];
+ const std::string& value = result[i + 2];
if ((i + minTokenSize) < result.size())
{
- std::string& separator = result[i + minTokenSize];
+ const std::string& separator = result[i + minTokenSize];
// SSE supports only "or" and "and" in query params.
if ((separator != "or") && (separator != "and"))
{
diff --git a/redfish-core/include/utils/query_param.hpp b/redfish-core/include/utils/query_param.hpp
index e221a865ac..fb3b5bdaff 100644
--- a/redfish-core/include/utils/query_param.hpp
+++ b/redfish-core/include/utils/query_param.hpp
@@ -3,6 +3,7 @@
#include "async_resp.hpp"
#include "error_messages.hpp"
#include "http_request.hpp"
+#include "http_response.hpp"
#include "routing.hpp"
#include <charconv>
@@ -477,7 +478,7 @@ class MultiAsyncResp : public std::enable_shared_from_this<MultiAsyncResp>
{}
void addAwaitingResponse(
- std::shared_ptr<bmcweb::AsyncResp>& res,
+ const std::shared_ptr<bmcweb::AsyncResp>& res,
const nlohmann::json::json_pointer& finalExpandLocation)
{
res->res.setCompleteRequestHandler(std::bind_front(
diff --git a/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp
index a773048455..f8ba322566 100644
--- a/redfish-core/lib/account_service.hpp
+++ b/redfish-core/lib/account_service.hpp
@@ -1328,7 +1328,7 @@ inline void
"org.freedesktop.DBus.Properties", "GetAll",
"xyz.openbmc_project.User.AccountPolicy");
- auto callback = [asyncResp](bool success, LDAPConfigData& confData,
+ auto callback = [asyncResp](bool success, const LDAPConfigData& confData,
const std::string& ldapType) {
if (!success)
{
diff --git a/redfish-core/lib/certificate_service.hpp b/redfish-core/lib/certificate_service.hpp
index 2fc606d645..a4ecbf048c 100644
--- a/redfish-core/lib/certificate_service.hpp
+++ b/redfish-core/lib/certificate_service.hpp
@@ -460,7 +460,7 @@ inline void requestRoutesCertificateActionGenerateCSR(App& app)
sdbusplus::message::object_path csrObjectPath;
m.read(csrObjectPath, interfacesProperties);
BMCWEB_LOG_DEBUG << "CSR object added" << csrObjectPath.str;
- for (auto& interface : interfacesProperties)
+ for (const auto& interface : interfacesProperties)
{
if (interface.first == "xyz.openbmc_project.Certs.CSR")
{
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index c3372f8a3e..a84052d02a 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -183,15 +183,15 @@ inline std::string
return "";
}
-inline bool
- extractEthernetInterfaceData(const std::string& ethifaceId,
- dbus::utility::ManagedObjectType& dbusData,
- EthernetInterfaceData& ethData)
+inline bool extractEthernetInterfaceData(
+ const std::string& ethifaceId,
+ const dbus::utility::ManagedObjectType& dbusData,
+ EthernetInterfaceData& ethData)
{
bool idFound = false;
- for (auto& objpath : dbusData)
+ for (const auto& objpath : dbusData)
{
- for (auto& ifacePair : objpath.second)
+ for (const auto& ifacePair : objpath.second)
{
if (objpath.first == "/xyz/openbmc_project/network/" + ethifaceId)
{
@@ -904,7 +904,7 @@ void getEthernetIfaceData(const std::string& ethifaceId,
[ethifaceId{std::string{ethifaceId}},
callback{std::forward<CallbackFunc>(callback)}](
const boost::system::error_code errorCode,
- dbus::utility::ManagedObjectType& resp) {
+ const dbus::utility::ManagedObjectType& resp) {
EthernetInterfaceData ethData{};
boost::container::flat_set<IPv4AddressData> ipv4Data;
boost::container::flat_set<IPv6AddressData> ipv6Data;
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index be2d887472..c118deb4b1 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -84,8 +84,8 @@ static const Message* getMessage(const std::string_view& messageID)
std::vector<std::string> fields;
fields.reserve(4);
boost::split(fields, messageID, boost::is_any_of("."));
- std::string& registryName = fields[0];
- std::string& messageKey = fields[3];
+ const std::string& registryName = fields[0];
+ const std::string& messageKey = fields[3];
// Find the right registry and check it for the MessageKey
if (std::string(base::header.registryPrefix) == registryName)
@@ -527,7 +527,7 @@ inline void
crow::connections::systemBus->async_method_call(
[asyncResp, entryID, dumpType,
entriesPath](const boost::system::error_code ec,
- dbus::utility::ManagedObjectType& resp) {
+ const dbus::utility::ManagedObjectType& resp) {
if (ec)
{
BMCWEB_LOG_ERROR << "DumpEntry resp_handler got error " << ec;
@@ -1788,10 +1788,9 @@ inline bool
return true;
}
-inline bool
- getHostLoggerEntries(std::vector<std::filesystem::path>& hostLoggerFiles,
- uint64_t skip, uint64_t top,
- std::vector<std::string>& logEntries, size_t& logCount)
+inline bool getHostLoggerEntries(
+ const std::vector<std::filesystem::path>& hostLoggerFiles, uint64_t skip,
+ uint64_t top, std::vector<std::string>& logEntries, size_t& logCount)
{
GzFileReader logFile;
diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp
index bda5a1a2dc..039fced5c7 100644
--- a/redfish-core/lib/managers.hpp
+++ b/redfish-core/lib/managers.hpp
@@ -935,19 +935,19 @@ inline CreatePIDRet createPidInterface(
}
if (inputs || outputs)
{
- std::array<std::optional<std::vector<std::string>>*, 2> containers =
- {&inputs, &outputs};
+ std::array<
+ std::reference_wrapper<std::optional<std::vector<std::string>>>,
+ 2>
+ containers = {inputs, outputs};
size_t index = 0;
- for (const auto& containerPtr : containers)
+ for (std::optional<std::vector<std::string>>& container :
+ containers)
{
- std::optional<std::vector<std::string>>& container =
- *containerPtr;
if (!container)
{
index++;
continue;
}
-
for (std::string& value : *container)
{
boost::replace_all(value, "_", " ");
@@ -1534,7 +1534,7 @@ struct SetPIDValues : std::enable_shared_from_this<SetPIDValues>
}
BMCWEB_LOG_DEBUG << *container;
- std::string& type = containerPair.first;
+ const std::string& type = containerPair.first;
for (nlohmann::json::iterator it = container->begin();
it != container->end(); ++it)
@@ -1833,7 +1833,7 @@ inline void
}
bool foundImage = false;
- for (auto& object : subtree)
+ for (const auto& object : subtree)
{
const std::string& path =
static_cast<const std::string&>(object.first);
diff --git a/redfish-core/lib/network_protocol.hpp b/redfish-core/lib/network_protocol.hpp
index dd24a404a1..f99cfd3627 100644
--- a/redfish-core/lib/network_protocol.hpp
+++ b/redfish-core/lib/network_protocol.hpp
@@ -139,7 +139,7 @@ inline void getNetworkData(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
getEthernetIfaceData(
[hostName, asyncResp](const bool& success,
- std::vector<std::string>& ntpServers,
+ const std::vector<std::string>& ntpServers,
const std::vector<std::string>& domainNames) {
if (!success)
{
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index 8b97b7c79e..6e72fea43d 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -1332,7 +1332,7 @@ inline void
if (entry != response.end())
{
std::sort(entry->begin(), entry->end(),
- [](nlohmann::json& c1, nlohmann::json& c2) {
+ [](const nlohmann::json& c1, const nlohmann::json& c2) {
return c1["Name"] < c2["Name"];
});
@@ -1613,9 +1613,9 @@ static void getInventoryItemsData(
// Response handler for GetManagedObjects
auto respHandler =
[sensorsAsyncResp, inventoryItems, invConnections, objectMgrPaths,
- callback{std::forward<Callback>(callback)},
- invConnectionsIndex](const boost::system::error_code ec,
- dbus::utility::ManagedObjectType& resp) {
+ callback{std::forward<Callback>(callback)}, invConnectionsIndex](
+ const boost::system::error_code ec,
+ const dbus::utility::ManagedObjectType& resp) {
BMCWEB_LOG_DEBUG << "getInventoryItemsData respHandler enter";
if (ec)
{
@@ -1781,10 +1781,10 @@ static void getInventoryItemAssociations(
BMCWEB_LOG_DEBUG << "getInventoryItemAssociations enter";
// Response handler for GetManagedObjects
- auto respHandler = [callback{std::forward<Callback>(callback)},
- sensorsAsyncResp,
- sensorNames](const boost::system::error_code ec,
- dbus::utility::ManagedObjectType& resp) {
+ auto respHandler =
+ [callback{std::forward<Callback>(callback)}, sensorsAsyncResp,
+ sensorNames](const boost::system::error_code ec,
+ const dbus::utility::ManagedObjectType& resp) {
BMCWEB_LOG_DEBUG << "getInventoryItemAssociations respHandler enter";
if (ec)
{
@@ -2468,7 +2468,7 @@ inline void getSensorData(
auto getManagedObjectsCb =
[sensorsAsyncResp, sensorNames,
inventoryItems](const boost::system::error_code ec,
- dbus::utility::ManagedObjectType& resp) {
+ const dbus::utility::ManagedObjectType& resp) {
BMCWEB_LOG_DEBUG << "getManagedObjectsCb enter";
if (ec)
{
@@ -2742,7 +2742,7 @@ inline void
*/
inline bool
findSensorNameUsingSensorPath(std::string_view sensorName,
- std::set<std::string>& sensorsList,
+ const std::set<std::string>& sensorsList,
std::set<std::string>& sensorsModified)
{
for (const auto& chassisSensor : sensorsList)
diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp
index 3315a26c8d..8140337093 100644
--- a/redfish-core/lib/systems.hpp
+++ b/redfish-core/lib/systems.hpp
@@ -52,7 +52,7 @@ inline void
// Set it as Enabled if at least one DIMM is functional
// Update STATE only if previous State was DISABLED and current Dimm is
// ENABLED.
- nlohmann::json& prevMemSummary =
+ const nlohmann::json& prevMemSummary =
aResp->res.jsonValue["MemorySummary"]["Status"]["State"];
if (prevMemSummary == "Disabled")
{
@@ -107,7 +107,7 @@ inline void
{
BMCWEB_LOG_DEBUG << "Cpu Functional: " << isCpuFunctional;
- nlohmann::json& prevProcState =
+ const nlohmann::json& prevProcState =
aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"];
// Set it as Enabled if at least one CPU is functional
@@ -326,8 +326,8 @@ inline void
aResp->res
.jsonValue["MemorySummary"]
["TotalSystemMemoryGiB"];
- uint64_t* preValue =
- totalMemory.get_ptr<uint64_t*>();
+ const uint64_t* preValue =
+ totalMemory.get_ptr<const uint64_t*>();
if (preValue == nullptr)
{
continue;
@@ -2299,7 +2299,7 @@ using ipsPropertiesType =
* @return true if successful
*/
inline bool parseIpsProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
- ipsPropertiesType& properties)
+ const ipsPropertiesType& properties)
{
for (const auto& property : properties)
{
@@ -2428,7 +2428,7 @@ inline void getIdlePowerSaver(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
// Valid IdlePowerSaver object found, now read the current values
crow::connections::systemBus->async_method_call(
[aResp](const boost::system::error_code ec2,
- ipsPropertiesType& properties) {
+ const ipsPropertiesType& properties) {
if (ec2)
{
BMCWEB_LOG_ERROR
diff --git a/redfish-core/lib/task.hpp b/redfish-core/lib/task.hpp
index dcad059655..88926146f0 100644
--- a/redfish-core/lib/task.hpp
+++ b/redfish-core/lib/task.hpp
@@ -120,7 +120,7 @@ struct TaskData : std::enable_shared_from_this<TaskData>
if (tasks.size() >= maxTaskCount)
{
- auto& last = tasks.front();
+ const auto& last = tasks.front();
// destroy all references
last->timer.cancel();
@@ -389,7 +389,7 @@ inline void requestRoutesTask(App& app)
return;
}
- std::shared_ptr<task::TaskData>& ptr = *find;
+ const std::shared_ptr<task::TaskData>& ptr = *find;
asyncResp->res.jsonValue["@odata.type"] = "#Task.v1_4_3.Task";
asyncResp->res.jsonValue["Id"] = strParam;
diff --git a/redfish-core/lib/virtual_media.hpp b/redfish-core/lib/virtual_media.hpp
index 69040a6170..17971dc092 100644
--- a/redfish-core/lib/virtual_media.hpp
+++ b/redfish-core/lib/virtual_media.hpp
@@ -172,9 +172,9 @@ inline void getVmResourceList(std::shared_ptr<bmcweb::AsyncResp> aResp,
{
BMCWEB_LOG_DEBUG << "Get available Virtual Media resources.";
crow::connections::systemBus->async_method_call(
- [name,
- aResp{std::move(aResp)}](const boost::system::error_code ec,
- dbus::utility::ManagedObjectType& subtree) {
+ [name, aResp{std::move(aResp)}](
+ const boost::system::error_code ec,
+ const dbus::utility::ManagedObjectType& subtree) {
if (ec)
{
BMCWEB_LOG_DEBUG << "DBUS response error";
@@ -917,9 +917,9 @@ inline void handleManagersVirtualMediaActionEject(
BMCWEB_LOG_DEBUG << "GetObjectType: " << service;
crow::connections::systemBus->async_method_call(
- [resName, service,
- asyncResp{asyncResp}](const boost::system::error_code ec,
- dbus::utility::ManagedObjectType& subtree) {
+ [resName, service, asyncResp{asyncResp}](
+ const boost::system::error_code ec,
+ const dbus::utility::ManagedObjectType& subtree) {
if (ec)
{
BMCWEB_LOG_DEBUG << "DBUS response error";
diff --git a/redfish-core/ut/lock_test.cpp b/redfish-core/ut/lock_test.cpp
index e89377df16..7ee2b71626 100644
--- a/redfish-core/ut/lock_test.cpp
+++ b/redfish-core/ut/lock_test.cpp
@@ -100,7 +100,7 @@ class MockLock : public crow::ibm_mc_lock::Lock
auto status = Lock::isItMyLock(tids, ids);
return status;
}
- RcGetLockList getList(std::vector<std::string>& listSessionid)
+ RcGetLockList getList(const std::vector<std::string>& listSessionid)
{
auto status = Lock::getLockList(listSessionid);
return status;