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
diff --git a/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp
index a773048..f8ba322 100644
--- a/redfish-core/lib/account_service.hpp
+++ b/redfish-core/lib/account_service.hpp
@@ -1328,7 +1328,7 @@
         "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 2fc606d..a4ecbf0 100644
--- a/redfish-core/lib/certificate_service.hpp
+++ b/redfish-core/lib/certificate_service.hpp
@@ -460,7 +460,7 @@
             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 c3372f8..a84052d 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -183,15 +183,15 @@
     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 @@
         [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 be2d887..c118deb 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -84,8 +84,8 @@
     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 @@
     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 @@
     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 bda5a1a..039fced 100644
--- a/redfish-core/lib/managers.hpp
+++ b/redfish-core/lib/managers.hpp
@@ -935,19 +935,19 @@
         }
         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 @@
             }
             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 @@
         }
 
         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 dd24a40..f99cfd3 100644
--- a/redfish-core/lib/network_protocol.hpp
+++ b/redfish-core/lib/network_protocol.hpp
@@ -139,7 +139,7 @@
 
     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 8b97b7c..6e72fea 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -1332,7 +1332,7 @@
         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 @@
         // 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 @@
     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 @@
         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 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 3315a26..8140337 100644
--- a/redfish-core/lib/systems.hpp
+++ b/redfish-core/lib/systems.hpp
@@ -52,7 +52,7 @@
     // 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 @@
 {
     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 @@
                                         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 @@
  * @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 @@
         // 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 dcad059..8892614 100644
--- a/redfish-core/lib/task.hpp
+++ b/redfish-core/lib/task.hpp
@@ -120,7 +120,7 @@
 
         if (tasks.size() >= maxTaskCount)
         {
-            auto& last = tasks.front();
+            const auto& last = tasks.front();
 
             // destroy all references
             last->timer.cancel();
@@ -389,7 +389,7 @@
             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 69040a6..17971dc 100644
--- a/redfish-core/lib/virtual_media.hpp
+++ b/redfish-core/lib/virtual_media.hpp
@@ -172,9 +172,9 @@
 {
     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 @@
         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";