Enable clang warnings

This commit enables clang warnings, and fixes all warnings that were
found.  Most of these fall into a couple categories:

Variable shadow issues were fixed by renaming variables

unused parameter warnings were resolved by either checking error codes
that had been ignored, or removing the name of the variable from the
scope.

Other various warnings were fixed in the best way I was able to come up
with.

Note, the redfish Node class is especially insidious, as it causes all
imlementers to have variables for parameters, regardless of whether or
not they are used.  Deprecating the Node class is on my list of things
to do, as it adds extra overhead, and in general isn't a useful
abstraction.  For now, I have simply fixed all the handlers.

Tested:
Added the current meta-clang meta layer into bblayers.conf, and added
TOOLCHAIN_pn-bmcweb = "clang" to my local.conf

Signed-off-by: Ed Tanous <ed@tanous.net>
Change-Id: Ia75b94010359170159c703e535d1c1af182fe700
diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp
index 9c42e06..64c3b7f 100644
--- a/redfish-core/include/event_service_manager.hpp
+++ b/redfish-core/include/event_service_manager.hpp
@@ -48,7 +48,7 @@
     "/var/lib/bmcweb/eventservice_config.json";
 
 #ifndef BMCWEB_ENABLE_REDFISH_DBUS_LOG_ENTRIES
-std::shared_ptr<boost::asio::posix::stream_descriptor> inotifyConn = nullptr;
+static std::optional<boost::asio::posix::stream_descriptor> inotifyConn;
 static constexpr const char* redfishEventLogDir = "/var/log";
 static constexpr const char* redfishEventLogFile = "/var/log/redfish";
 static constexpr const size_t iEventSize = sizeof(inotify_event);
@@ -113,8 +113,8 @@
 
 namespace event_log
 {
-bool getUniqueEntryID(const std::string& logEntry, std::string& entryID,
-                      const bool firstEntry = true)
+inline bool getUniqueEntryID(const std::string& logEntry, std::string& entryID,
+                             const bool firstEntry = true)
 {
     static time_t prevTs = 0;
     static int index = 0;
@@ -149,9 +149,9 @@
     return true;
 }
 
-int getEventLogParams(const std::string& logEntry, std::string& timestamp,
-                      std::string& messageID,
-                      std::vector<std::string>& messageArgs)
+inline int getEventLogParams(const std::string& logEntry,
+                             std::string& timestamp, std::string& messageID,
+                             std::vector<std::string>& messageArgs)
 {
     // The redfish log format is "<Timestamp> <MessageId>,<MessageArgs>"
     // First get the Timestamp
@@ -195,9 +195,9 @@
     return 0;
 }
 
-void getRegistryAndMessageKey(const std::string& messageID,
-                              std::string& registryName,
-                              std::string& messageKey)
+inline void getRegistryAndMessageKey(const std::string& messageID,
+                                     std::string& registryName,
+                                     std::string& messageKey)
 {
     // Redfish MessageIds are in the form
     // RegistryName.MajorVersion.MinorVersion.MessageKey, so parse it to find
@@ -212,11 +212,12 @@
     }
 }
 
-int formatEventLogEntry(const std::string& logEntryID,
-                        const std::string& messageID,
-                        const std::vector<std::string>& messageArgs,
-                        std::string timestamp, const std::string customText,
-                        nlohmann::json& logEntryJson)
+inline int formatEventLogEntry(const std::string& logEntryID,
+                               const std::string& messageID,
+                               const std::vector<std::string>& messageArgs,
+                               std::string timestamp,
+                               const std::string customText,
+                               nlohmann::json& logEntryJson)
 {
     // Get the Message from the MessageRegistry
     const message_registries::Message* message =
@@ -267,7 +268,7 @@
 } // namespace event_log
 #endif
 
-bool isFilterQuerySpecialChar(char c)
+inline bool isFilterQuerySpecialChar(char c)
 {
     switch (c)
     {
@@ -280,10 +281,11 @@
     }
 }
 
-bool readSSEQueryParams(std::string sseFilter, std::string& formatType,
-                        std::vector<std::string>& messageIds,
-                        std::vector<std::string>& registryPrefixes,
-                        std::vector<std::string>& metricReportDefinitions)
+inline bool
+    readSSEQueryParams(std::string sseFilter, std::string& formatType,
+                       std::vector<std::string>& messageIds,
+                       std::vector<std::string>& registryPrefixes,
+                       std::vector<std::string>& metricReportDefinitions)
 {
     sseFilter.erase(std::remove_if(sseFilter.begin(), sseFilter.end(),
                                    isFilterQuerySpecialChar),
@@ -508,12 +510,12 @@
     }
 #endif
 
-    void filterAndSendReports(const std::string& id,
+    void filterAndSendReports(const std::string& id2,
                               const std::string& readingsTs,
                               const ReadingsObjType& readings)
     {
         std::string metricReportDef =
-            "/redfish/v1/TelemetryService/MetricReportDefinitions/" + id;
+            "/redfish/v1/TelemetryService/MetricReportDefinitions/" + id2;
 
         // Empty list means no filter. Send everything.
         if (metricReportDefinitions.size())
@@ -541,8 +543,8 @@
         nlohmann::json msg = {
             {"@odata.id", "/redfish/v1/TelemetryService/MetricReports/" + id},
             {"@odata.type", "#MetricReport.v1_3_0.MetricReport"},
-            {"Id", id},
-            {"Name", id},
+            {"Id", id2},
+            {"Name", id2},
             {"Timestamp", readingsTs},
             {"MetricReportDefinition", {{"@odata.id", metricReportDef}}},
             {"MetricValues", metricValuesArray}};
@@ -924,7 +926,7 @@
     std::string addSubscription(const std::shared_ptr<Subscription> subValue,
                                 const bool updateFile = true)
     {
-        std::srand(static_cast<uint32_t>(std::time(0)));
+        std::srand(static_cast<uint32_t>(std::time(nullptr)));
         std::string id;
 
         int retry = 3;
@@ -937,7 +939,7 @@
                 break;
             }
             --retry;
-        };
+        }
 
         if (retry <= 0)
         {
@@ -1199,7 +1201,7 @@
 
     static void watchRedfishEventLogFile()
     {
-        if (inotifyConn == nullptr)
+        if (inotifyConn)
         {
             return;
         }
@@ -1295,8 +1297,7 @@
 
     static int startEventLogMonitor(boost::asio::io_context& ioc)
     {
-        inotifyConn =
-            std::make_shared<boost::asio::posix::stream_descriptor>(ioc);
+        inotifyConn.emplace(ioc);
         inotifyFd = inotify_init1(IN_NONBLOCK);
         if (inotifyFd == -1)
         {
@@ -1486,6 +1487,6 @@
         }
         return true;
     }
-}; // namespace redfish
+};
 
 } // namespace redfish
diff --git a/redfish-core/include/node.hpp b/redfish-core/include/node.hpp
index be098ca..b21fba5 100644
--- a/redfish-core/include/node.hpp
+++ b/redfish-core/include/node.hpp
@@ -108,7 +108,7 @@
         {
             if (getRule != nullptr)
             {
-                getRule->requires(it->second);
+                getRule->privileges(it->second);
             }
         }
         it = entityPrivileges.find(boost::beast::http::verb::post);
@@ -116,7 +116,7 @@
         {
             if (postRule != nullptr)
             {
-                postRule->requires(it->second);
+                postRule->privileges(it->second);
             }
         }
         it = entityPrivileges.find(boost::beast::http::verb::patch);
@@ -124,7 +124,7 @@
         {
             if (patchRule != nullptr)
             {
-                patchRule->requires(it->second);
+                patchRule->privileges(it->second);
             }
         }
         it = entityPrivileges.find(boost::beast::http::verb::put);
@@ -132,7 +132,7 @@
         {
             if (putRule != nullptr)
             {
-                putRule->requires(it->second);
+                putRule->privileges(it->second);
             }
         }
         it = entityPrivileges.find(boost::beast::http::verb::delete_);
@@ -140,7 +140,7 @@
         {
             if (deleteRule != nullptr)
             {
-                deleteRule->requires(it->second);
+                deleteRule->privileges(it->second);
             }
         }
     }
diff --git a/redfish-core/include/privileges.hpp b/redfish-core/include/privileges.hpp
index 0282f35..d9bf1fc 100644
--- a/redfish-core/include/privileges.hpp
+++ b/redfish-core/include/privileges.hpp
@@ -45,8 +45,9 @@
 constexpr const size_t maxPrivilegeCount = 32;
 
 /** @brief A vector of all privilege names and their indexes */
-static const std::vector<std::string> privilegeNames{basePrivileges.begin(),
-                                                     basePrivileges.end()};
+static const std::array<std::string, maxPrivilegeCount> privilegeNames{
+    "Login", "ConfigureManager", "ConfigureComponents", "ConfigureSelf",
+    "ConfigureUsers"};
 
 /**
  * @brief Redfish privileges
@@ -100,7 +101,7 @@
      * @return               None
      *
      */
-    bool setSinglePrivilege(const char* privilege)
+    bool setSinglePrivilege(const std::string_view privilege)
     {
         for (size_t searchIndex = 0; searchIndex < privilegeNames.size();
              searchIndex++)
@@ -116,19 +117,6 @@
     }
 
     /**
-     * @brief Sets given privilege in the bitset
-     *
-     * @param[in] privilege  Privilege to be set
-     *
-     * @return               None
-     *
-     */
-    bool setSinglePrivilege(const std::string& privilege)
-    {
-        return setSinglePrivilege(privilege.c_str());
-    }
-
-    /**
      * @brief Resets the given privilege in the bitset
      *
      * @param[in] privilege  Privilege to be reset
@@ -159,10 +147,10 @@
      * the setSinglePrivilege is called, or the Privilege structure is destroyed
      *
      */
-    std::vector<const std::string*>
+    std::vector<std::string>
         getActivePrivilegeNames(const PrivilegeType type) const
     {
-        std::vector<const std::string*> activePrivileges;
+        std::vector<std::string> activePrivileges;
 
         size_t searchIndex = 0;
         size_t endIndex = basePrivilegeCount;
@@ -176,7 +164,7 @@
         {
             if (privilegeBitset.test(searchIndex))
             {
-                activePrivileges.emplace_back(&privilegeNames[searchIndex]);
+                activePrivileges.emplace_back(privilegeNames[searchIndex]);
             }
         }
 
diff --git a/redfish-core/include/server_sent_events.hpp b/redfish-core/include/server_sent_events.hpp
index 1c4d2a5..9f0da8f 100644
--- a/redfish-core/include/server_sent_events.hpp
+++ b/redfish-core/include/server_sent_events.hpp
@@ -229,6 +229,8 @@
             case SseConnState::initInProgress:
             case SseConnState::sendInProgress:
             case SseConnState::suspended:
+            case SseConnState::startInit:
+            case SseConnState::closed:
                 // do nothing
                 break;
             case SseConnState::initFailed:
@@ -245,8 +247,6 @@
                 sendEvent(std::to_string(reqData.first), reqData.second);
                 break;
             }
-            default:
-                break;
         }
 
         return;
diff --git a/redfish-core/include/task_messages.hpp b/redfish-core/include/task_messages.hpp
index 050cc63..33c2db5 100644
--- a/redfish-core/include/task_messages.hpp
+++ b/redfish-core/include/task_messages.hpp
@@ -20,7 +20,7 @@
 namespace messages
 {
 
-nlohmann::json taskAborted(const std::string& arg1)
+inline nlohmann::json taskAborted(const std::string& arg1)
 {
     return nlohmann::json{
         {"@odata.type", "#Message.v1_0_0.Message"},
@@ -31,7 +31,7 @@
         {"Resolution", "None."}};
 }
 
-nlohmann::json taskCancelled(const std::string& arg1)
+inline nlohmann::json taskCancelled(const std::string& arg1)
 {
     return nlohmann::json{
         {"@odata.type", "#Message.v1_0_0.Message"},
@@ -42,7 +42,7 @@
         {"Resolution", "None."}};
 }
 
-nlohmann::json taskCompletedOK(const std::string& arg1)
+inline nlohmann::json taskCompletedOK(const std::string& arg1)
 {
     return nlohmann::json{
         {"@odata.type", "#Message.v1_0_0.Message"},
@@ -53,7 +53,7 @@
         {"Resolution", "None."}};
 }
 
-nlohmann::json taskCompletedWarning(const std::string& arg1)
+inline nlohmann::json taskCompletedWarning(const std::string& arg1)
 {
     return nlohmann::json{{"@odata.type", "#Message.v1_0_0.Message"},
                           {"MessageId", "TaskEvent.1.0.1.TaskCompletedWarning"},
@@ -64,7 +64,7 @@
                           {"Resolution", "None."}};
 }
 
-nlohmann::json taskPaused(const std::string& arg1)
+inline nlohmann::json taskPaused(const std::string& arg1)
 {
     return nlohmann::json{
         {"@odata.type", "#Message.v1_0_0.Message"},
@@ -75,7 +75,8 @@
         {"Resolution", "None."}};
 }
 
-nlohmann::json taskProgressChanged(const std::string& arg1, const size_t arg2)
+inline nlohmann::json taskProgressChanged(const std::string& arg1,
+                                          const size_t arg2)
 {
     return nlohmann::json{
         {"@odata.type", "#Message.v1_0_0.Message"},
@@ -87,7 +88,7 @@
         {"Resolution", "None."}};
 }
 
-nlohmann::json taskRemoved(const std::string& arg1)
+inline nlohmann::json taskRemoved(const std::string& arg1)
 {
     return nlohmann::json{
         {"@odata.type", "#Message.v1_0_0.Message"},
@@ -98,7 +99,7 @@
         {"Resolution", "None."}};
 }
 
-nlohmann::json taskResumed(const std::string& arg1)
+inline nlohmann::json taskResumed(const std::string& arg1)
 {
     return nlohmann::json{
         {"@odata.type", "#Message.v1_0_0.Message"},
@@ -109,7 +110,7 @@
         {"Resolution", "None."}};
 }
 
-nlohmann::json taskStarted(const std::string& arg1)
+inline nlohmann::json taskStarted(const std::string& arg1)
 {
     return nlohmann::json{
         {"@odata.type", "#Message.v1_0_0.Message"},
diff --git a/redfish-core/include/utils/fw_utils.hpp b/redfish-core/include/utils/fw_utils.hpp
index 95d684f..65f19ca 100644
--- a/redfish-core/include/utils/fw_utils.hpp
+++ b/redfish-core/include/utils/fw_utils.hpp
@@ -28,10 +28,10 @@
  *
  * @return void
  */
-void getActiveFwVersion(std::shared_ptr<AsyncResp> aResp,
-                        const std::string& fwVersionPurpose,
-                        const std::string& activeVersionPropName,
-                        const bool populateLinkToActiveImage)
+inline void getActiveFwVersion(std::shared_ptr<AsyncResp> aResp,
+                               const std::string& fwVersionPurpose,
+                               const std::string& activeVersionPropName,
+                               const bool populateLinkToActiveImage)
 {
     // Get active FW images
     crow::connections::systemBus->async_method_call(
@@ -80,13 +80,13 @@
                 crow::connections::systemBus->async_method_call(
                     [aResp, fw, swId, fwVersionPurpose, activeVersionPropName,
                      populateLinkToActiveImage](
-                        const boost::system::error_code ec,
+                        const boost::system::error_code ec2,
                         const std::vector<std::pair<
                             std::string, std::vector<std::string>>>& objInfo) {
-                        if (ec)
+                        if (ec2)
                         {
-                            BMCWEB_LOG_DEBUG << "error_code = " << ec;
-                            BMCWEB_LOG_DEBUG << "error msg = " << ec.message();
+                            BMCWEB_LOG_DEBUG << "error_code = " << ec2;
+                            BMCWEB_LOG_DEBUG << "error msg = " << ec2.message();
                             messages::internalError(aResp->res);
                             return;
                         }
@@ -116,16 +116,16 @@
                         crow::connections::systemBus->async_method_call(
                             [aResp, swId, fwVersionPurpose,
                              activeVersionPropName, populateLinkToActiveImage](
-                                const boost::system::error_code ec,
+                                const boost::system::error_code ec3,
                                 const boost::container::flat_map<
                                     std::string,
                                     std::variant<bool, std::string, uint64_t,
                                                  uint32_t>>& propertiesList) {
-                                if (ec)
+                                if (ec3)
                                 {
-                                    BMCWEB_LOG_ERROR << "error_code = " << ec;
+                                    BMCWEB_LOG_ERROR << "error_code = " << ec3;
                                     BMCWEB_LOG_ERROR << "error msg = "
-                                                     << ec.message();
+                                                     << ec3.message();
                                     messages::internalError(aResp->res);
                                     return;
                                 }
@@ -230,7 +230,7 @@
  *
  * @return The corresponding Redfish state
  */
-std::string getRedfishFWState(const std::string& fwState)
+inline std::string getRedfishFWState(const std::string& fwState)
 {
     if (fwState == "xyz.openbmc_project.Software.Activation.Activations.Active")
     {
@@ -262,7 +262,7 @@
  *
  * @return The corresponding Redfish health state
  */
-std::string getRedfishFWHealth(const std::string& fwState)
+inline std::string getRedfishFWHealth(const std::string& fwState)
 {
     if ((fwState ==
          "xyz.openbmc_project.Software.Activation.Activations.Active") ||
@@ -292,9 +292,9 @@
  *
  * @return void
  */
-void getFwStatus(std::shared_ptr<AsyncResp> asyncResp,
-                 const std::shared_ptr<std::string> swId,
-                 const std::string& dbusSvc)
+inline void getFwStatus(std::shared_ptr<AsyncResp> asyncResp,
+                        const std::shared_ptr<std::string> swId,
+                        const std::string& dbusSvc)
 {
     BMCWEB_LOG_DEBUG << "getFwStatus: swId " << *swId << " svc " << dbusSvc;
 
@@ -350,8 +350,8 @@
  * @param[i,o] asyncResp  Async response object
  * @param[i]   fwId       The firmware ID
  */
-void getFwUpdateableStatus(std::shared_ptr<AsyncResp> asyncResp,
-                           const std::shared_ptr<std::string> fwId)
+inline void getFwUpdateableStatus(std::shared_ptr<AsyncResp> asyncResp,
+                                  const std::shared_ptr<std::string> fwId)
 {
     crow::connections::systemBus->async_method_call(
         [asyncResp, fwId](const boost::system::error_code ec,
diff --git a/redfish-core/include/utils/systemd_utils.hpp b/redfish-core/include/utils/systemd_utils.hpp
index da1b4e2..0db1d94 100644
--- a/redfish-core/include/utils/systemd_utils.hpp
+++ b/redfish-core/include/utils/systemd_utils.hpp
@@ -29,7 +29,7 @@
  * @return Service root UUID
  */
 
-const std::string getUuid()
+inline const std::string getUuid()
 {
     std::string ret;
     // This ID needs to match the one in ipmid