Enable unused variable warnings and resolve

This commit enables the "unused variables" warning in clang.  Throughout
this, it did point out several issues that would've been functional
bugs, so I think it was worthwhile.  It also cleaned up several unused
variable from old constructs that no longer exist.

Tested:
Built with clang.  Code no longer emits warnings.

Downloaded bmcweb to system and pulled up the webui, observed webui
loads and logs in properly.

Change-Id: I51505f4222cc147d6f2b87b14d7e2ac4a74cafa8
Signed-off-by: Ed Tanous <ed@tanous.net>
diff --git a/include/dbus_monitor.hpp b/include/dbus_monitor.hpp
index 4a5c7c6..3f0b826 100644
--- a/include/dbus_monitor.hpp
+++ b/include/dbus_monitor.hpp
@@ -120,14 +120,15 @@
         .privileges({"Login"})
         .websocket()
         .onopen([&](crow::websocket::Connection& conn,
-                    std::shared_ptr<bmcweb::AsyncResp> asyncResp) {
+                    std::shared_ptr<bmcweb::AsyncResp>) {
             BMCWEB_LOG_DEBUG << "Connection " << &conn << " opened";
             sessions[&conn] = DbusWebsocketSession();
         })
-        .onclose([&](crow::websocket::Connection& conn,
-                     const std::string& reason) { sessions.erase(&conn); })
+        .onclose([&](crow::websocket::Connection& conn, const std::string&) {
+            sessions.erase(&conn);
+        })
         .onmessage([&](crow::websocket::Connection& conn,
-                       const std::string& data, bool is_binary) {
+                       const std::string& data, bool) {
             DbusWebsocketSession& thisSession = sessions[&conn];
             BMCWEB_LOG_DEBUG << "Connection " << &conn << " received " << data;
             nlohmann::json j = nlohmann::json::parse(data, nullptr, false);
diff --git a/include/ibm/management_console_rest.hpp b/include/ibm/management_console_rest.hpp
index db1e9f3..6b77018 100644
--- a/include/ibm/management_console_rest.hpp
+++ b/include/ibm/management_console_rest.hpp
@@ -532,7 +532,7 @@
     }
 }
 
-void handleGetLockListAPI(const crow::Request& req, crow::Response& res,
+void handleGetLockListAPI(crow::Response& res,
                           const ListOfSessionIds& listSessionIds)
 {
     BMCWEB_LOG_DEBUG << listSessionIds.size();
@@ -581,7 +581,7 @@
     BMCWEB_ROUTE(app, "/ibm/v1/")
         .privileges({"ConfigureComponents", "ConfigureManager"})
         .methods(boost::beast::http::verb::get)(
-            [](const crow::Request& req, crow::Response& res) {
+            [](const crow::Request&, crow::Response& res) {
                 res.jsonValue["@odata.type"] =
                     "#ibmServiceRoot.v1_0_0.ibmServiceRoot";
                 res.jsonValue["@odata.id"] = "/ibm/v1/";
@@ -599,7 +599,7 @@
     BMCWEB_ROUTE(app, "/ibm/v1/Host/ConfigFiles")
         .privileges({"ConfigureComponents", "ConfigureManager"})
         .methods(boost::beast::http::verb::get)(
-            [](const crow::Request& req, crow::Response& res) {
+            [](const crow::Request&, crow::Response& res) {
                 handleConfigFileList(res);
             });
 
@@ -607,7 +607,7 @@
                  "/ibm/v1/Host/ConfigFiles/Actions/IBMConfigFiles.DeleteAll")
         .privileges({"ConfigureComponents", "ConfigureManager"})
         .methods(boost::beast::http::verb::post)(
-            [](const crow::Request& req, crow::Response& res) {
+            [](const crow::Request&, crow::Response& res) {
                 deleteConfigFiles(res);
             });
 
@@ -621,7 +621,7 @@
     BMCWEB_ROUTE(app, "/ibm/v1/HMC/LockService")
         .privileges({"ConfigureComponents", "ConfigureManager"})
         .methods(boost::beast::http::verb::get)(
-            [](const crow::Request& req, crow::Response& res) {
+            [](const crow::Request&, crow::Response& res) {
                 getLockServiceData(res);
             });
 
@@ -682,7 +682,7 @@
                     res.end();
                     return;
                 }
-                handleGetLockListAPI(req, res, listSessionIds);
+                handleGetLockListAPI(res, listSessionIds);
             });
 
     BMCWEB_ROUTE(app, "/ibm/v1/HMC/BroadcastService")
diff --git a/include/image_upload.hpp b/include/image_upload.hpp
index a135af9..9d0a0ca 100644
--- a/include/image_upload.hpp
+++ b/include/image_upload.hpp
@@ -18,8 +18,7 @@
 
 static std::unique_ptr<sdbusplus::bus::match::match> fwUpdateMatcher;
 
-inline void uploadImageHandler(const crow::Request& req, crow::Response& res,
-                               const std::string& filename)
+inline void uploadImageHandler(const crow::Request& req, crow::Response& res)
 {
     // Only allow one FW update at a time
     if (fwUpdateMatcher != nullptr)
@@ -115,15 +114,13 @@
         .privileges({"ConfigureComponents", "ConfigureManager"})
         .methods(boost::beast::http::verb::post, boost::beast::http::verb::put)(
             [](const crow::Request& req, crow::Response& res,
-               const std::string& filename) {
-                uploadImageHandler(req, res, filename);
-            });
+               const std::string&) { uploadImageHandler(req, res); });
 
     BMCWEB_ROUTE(app, "/upload/image")
         .privileges({"ConfigureComponents", "ConfigureManager"})
         .methods(boost::beast::http::verb::post, boost::beast::http::verb::put)(
             [](const crow::Request& req, crow::Response& res) {
-                uploadImageHandler(req, res, "");
+                uploadImageHandler(req, res);
             });
 }
 } // namespace image_upload
diff --git a/include/kvm_websocket.hpp b/include/kvm_websocket.hpp
index f83c95b..df50778 100644
--- a/include/kvm_websocket.hpp
+++ b/include/kvm_websocket.hpp
@@ -162,7 +162,7 @@
         .privileges({"ConfigureComponents", "ConfigureManager"})
         .websocket()
         .onopen([](crow::websocket::Connection& conn,
-                   std::shared_ptr<bmcweb::AsyncResp> asyncResp) {
+                   std::shared_ptr<bmcweb::AsyncResp>) {
             BMCWEB_LOG_DEBUG << "Connection " << &conn << " opened";
 
             if (sessions.size() == maxSessions)
@@ -173,10 +173,11 @@
 
             sessions[&conn] = std::make_unique<KvmSession>(conn);
         })
-        .onclose([](crow::websocket::Connection& conn,
-                    const std::string& reason) { sessions.erase(&conn); })
+        .onclose([](crow::websocket::Connection& conn, const std::string&) {
+            sessions.erase(&conn);
+        })
         .onmessage([](crow::websocket::Connection& conn,
-                      const std::string& data, bool is_binary) {
+                      const std::string& data, bool) {
             if (sessions[&conn])
             {
                 sessions[&conn]->onMessage(data);
diff --git a/include/obmc_console.hpp b/include/obmc_console.hpp
index 036fe5a..f2de85b 100644
--- a/include/obmc_console.hpp
+++ b/include/obmc_console.hpp
@@ -107,7 +107,7 @@
         .privileges({"ConfigureComponents", "ConfigureManager"})
         .websocket()
         .onopen([](crow::websocket::Connection& conn,
-                   std::shared_ptr<bmcweb::AsyncResp> asyncResp) {
+                   std::shared_ptr<bmcweb::AsyncResp>) {
             BMCWEB_LOG_DEBUG << "Connection " << &conn << " opened";
 
             sessions.insert(&conn);
@@ -122,18 +122,19 @@
                 host_socket->async_connect(ep, connectHandler);
             }
         })
-        .onclose(
-            [](crow::websocket::Connection& conn, const std::string& reason) {
-                sessions.erase(&conn);
-                if (sessions.empty())
-                {
-                    host_socket = nullptr;
-                    inputBuffer.clear();
-                    inputBuffer.shrink_to_fit();
-                }
-            })
-        .onmessage([](crow::websocket::Connection& conn,
-                      const std::string& data, bool is_binary) {
+        .onclose([](crow::websocket::Connection& conn,
+                    [[maybe_unused]] const std::string& reason) {
+            sessions.erase(&conn);
+            if (sessions.empty())
+            {
+                host_socket = nullptr;
+                inputBuffer.clear();
+                inputBuffer.shrink_to_fit();
+            }
+        })
+        .onmessage([]([[maybe_unused]] crow::websocket::Connection& conn,
+                      const std::string& data,
+                      [[maybe_unused]] bool is_binary) {
             inputBuffer += data;
             doWrite();
         });
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index 57bfc88..f049c00 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -791,13 +791,13 @@
             }
 
             nlohmann::json::const_iterator it = j->begin();
-            for (const std::string& argCode : dbusArgSplit(arg_type))
+            for (const std::string& argCode2 : dbusArgSplit(arg_type))
             {
                 if (it == j->end())
                 {
                     return -1;
                 }
-                r = convertJsonToDbus(m, argCode, *it);
+                r = convertJsonToDbus(m, argCode2, *it);
                 if (r < 0)
                 {
                     return r;
@@ -1556,8 +1556,7 @@
         std::array<std::string, 0>());
 }
 
-inline void handleDelete(const crow::Request& req, crow::Response& res,
-                         const std::string& objectPath)
+inline void handleDelete(crow::Response& res, const std::string& objectPath)
 {
     BMCWEB_LOG_DEBUG << "handleDelete on path: " << objectPath;
 
@@ -2065,7 +2064,7 @@
     }
     else if (req.method() == boost::beast::http::verb::delete_)
     {
-        handleDelete(req, res, objectPath);
+        handleDelete(res, objectPath);
         return;
     }
 
@@ -2079,7 +2078,7 @@
     BMCWEB_ROUTE(app, "/bus/")
         .privileges({"Login"})
         .methods(boost::beast::http::verb::get)(
-            [](const crow::Request& req, crow::Response& res) {
+            [](const crow::Request&, crow::Response& res) {
                 res.jsonValue = {{"buses", {{{"name", "system"}}}},
                                  {"status", "ok"}};
                 res.end();
@@ -2088,7 +2087,7 @@
     BMCWEB_ROUTE(app, "/bus/system/")
         .privileges({"Login"})
         .methods(boost::beast::http::verb::get)(
-            [](const crow::Request& req, crow::Response& res) {
+            [](const crow::Request&, crow::Response& res) {
                 auto myCallback = [&res](const boost::system::error_code ec,
                                          std::vector<std::string>& names) {
                     if (ec)
@@ -2117,7 +2116,7 @@
     BMCWEB_ROUTE(app, "/list/")
         .privileges({"Login"})
         .methods(boost::beast::http::verb::get)(
-            [](const crow::Request& req, crow::Response& res) {
+            [](const crow::Request&, crow::Response& res) {
                 handleList(res, "/");
             });
 
@@ -2161,7 +2160,7 @@
 
     BMCWEB_ROUTE(app, "/download/dump/<str>/")
         .privileges({"ConfigureManager"})
-        .methods(boost::beast::http::verb::get)([](const crow::Request& req,
+        .methods(boost::beast::http::verb::get)([](const crow::Request&,
                                                    crow::Response& res,
                                                    const std::string& dumpId) {
             std::regex validFilename("^[\\w\\- ]+(\\.?[\\w\\- ]*)$");
@@ -2231,7 +2230,7 @@
         .privileges({"Login"})
 
         .methods(boost::beast::http::verb::get)(
-            [](const crow::Request& req, crow::Response& res,
+            [](const crow::Request&, crow::Response& res,
                const std::string& Connection) {
                 introspectObjects(Connection, "/",
                                   std::make_shared<bmcweb::AsyncResp>(res));
diff --git a/include/redfish_v1.hpp b/include/redfish_v1.hpp
index cb7af8f..1e4bd65 100644
--- a/include/redfish_v1.hpp
+++ b/include/redfish_v1.hpp
@@ -10,7 +10,7 @@
 {
     BMCWEB_ROUTE(app, "/redfish/")
         .methods(boost::beast::http::verb::get)(
-            [](const crow::Request& req, crow::Response& res) {
+            [](const crow::Request&, crow::Response& res) {
                 res.jsonValue = {{"v1", "/redfish/v1/"}};
                 res.end();
             });
diff --git a/include/vm_websocket.hpp b/include/vm_websocket.hpp
index d07469e..da9a06f 100644
--- a/include/vm_websocket.hpp
+++ b/include/vm_websocket.hpp
@@ -160,7 +160,7 @@
         .privileges({"ConfigureComponents", "ConfigureManager"})
         .websocket()
         .onopen([](crow::websocket::Connection& conn,
-                   std::shared_ptr<bmcweb::AsyncResp> asyncResp) {
+                   std::shared_ptr<bmcweb::AsyncResp>) {
             BMCWEB_LOG_DEBUG << "Connection " << &conn << " opened";
 
             if (session != nullptr)
@@ -183,16 +183,21 @@
             handler = std::make_shared<Handler>(media, conn.get_io_context());
             handler->connect();
         })
-        .onclose(
-            [](crow::websocket::Connection& conn, const std::string& reason) {
-                session = nullptr;
-                handler->doClose();
-                handler->inputBuffer->clear();
-                handler->outputBuffer->clear();
-                handler.reset();
-            })
+        .onclose([](crow::websocket::Connection& conn,
+                    const std::string& /*reason*/) {
+            if (&conn != session)
+            {
+                return;
+            }
+
+            session = nullptr;
+            handler->doClose();
+            handler->inputBuffer->clear();
+            handler->outputBuffer->clear();
+            handler.reset();
+        })
         .onmessage([](crow::websocket::Connection& conn,
-                      const std::string& data, bool is_binary) {
+                      const std::string& data, bool) {
             if (data.length() > handler->inputBuffer->capacity())
             {
                 BMCWEB_LOG_ERROR << "Buffer overrun when writing "
diff --git a/include/webassets.hpp b/include/webassets.hpp
index 7e382d8..7cf6c93 100644
--- a/include/webassets.hpp
+++ b/include/webassets.hpp
@@ -128,8 +128,8 @@
             }
 
             app.routeDynamic(webpath)(
-                [absolutePath, contentType, contentEncoding](
-                    const crow::Request& req, crow::Response& res) {
+                [absolutePath, contentType,
+                 contentEncoding](const crow::Request&, crow::Response& res) {
                     if (contentType != nullptr)
                     {
                         res.addHeader("Content-Type", contentType);