Move to common variant
This saves approximately 34kB in the compressed binary size of bmcweb
due to reduced template instantiations. This amounts to a 2.5%
reduction in the overall size.
Note, there were a few places where we broke const-correctness in the
form of pulling a non-const reference out of a const variant. This
new variant now requires const correctness, so some consts are
added where required.
Tested: Code compiles.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I6a60c8881c1268627eedb4ffddf16689dc5f6ed2
diff --git a/include/nbd_proxy.hpp b/include/nbd_proxy.hpp
index 7b90e90..ed5265d 100644
--- a/include/nbd_proxy.hpp
+++ b/include/nbd_proxy.hpp
@@ -25,8 +25,6 @@
#include <privileges.hpp>
#include <websocket.hpp>
-#include <variant>
-
namespace crow
{
@@ -256,56 +254,54 @@
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
BMCWEB_LOG_DEBUG << "nbd-proxy.onopen(" << &conn << ")";
- auto getUserInfoHandler =
- [&conn, asyncResp](
- const boost::system::error_code ec,
- boost::container::flat_map<
- std::string, std::variant<bool, std::string,
- std::vector<std::string>>>
- userInfo) {
- if (ec)
- {
- BMCWEB_LOG_ERROR << "GetUserInfo failed...";
- conn.close("Failed to get user information");
- return;
- }
+ auto getUserInfoHandler = [&conn, asyncResp](
+ const boost::system::error_code ec,
+ boost::container::flat_map<
+ std::string,
+ dbus::utility::DbusVariantType>
+ userInfo) {
+ if (ec)
+ {
+ BMCWEB_LOG_ERROR << "GetUserInfo failed...";
+ conn.close("Failed to get user information");
+ return;
+ }
- const std::string* userRolePtr = nullptr;
- auto userInfoIter = userInfo.find("UserPrivilege");
- if (userInfoIter != userInfo.end())
- {
- userRolePtr =
- std::get_if<std::string>(&userInfoIter->second);
- }
+ const std::string* userRolePtr = nullptr;
+ auto userInfoIter = userInfo.find("UserPrivilege");
+ if (userInfoIter != userInfo.end())
+ {
+ userRolePtr =
+ std::get_if<std::string>(&userInfoIter->second);
+ }
- std::string userRole{};
- if (userRolePtr != nullptr)
- {
- userRole = *userRolePtr;
- BMCWEB_LOG_DEBUG << "userName = " << conn.getUserName()
- << " userRole = " << *userRolePtr;
- }
+ std::string userRole{};
+ if (userRolePtr != nullptr)
+ {
+ userRole = *userRolePtr;
+ BMCWEB_LOG_DEBUG << "userName = " << conn.getUserName()
+ << " userRole = " << *userRolePtr;
+ }
- // Get the user privileges from the role
- ::redfish::Privileges userPrivileges =
- ::redfish::getUserPrivileges(userRole);
+ // Get the user privileges from the role
+ ::redfish::Privileges userPrivileges =
+ ::redfish::getUserPrivileges(userRole);
- const ::redfish::Privileges requiredPrivileges{
- requiredPrivilegeString};
+ const ::redfish::Privileges requiredPrivileges{
+ requiredPrivilegeString};
- if (!userPrivileges.isSupersetOf(requiredPrivileges))
- {
- BMCWEB_LOG_DEBUG
- << "User " << conn.getUserName()
- << " not authorized for nbd connection";
- conn.close("Unathourized access");
- return;
- }
+ if (!userPrivileges.isSupersetOf(requiredPrivileges))
+ {
+ BMCWEB_LOG_DEBUG << "User " << conn.getUserName()
+ << " not authorized for nbd connection";
+ conn.close("Unathourized access");
+ return;
+ }
- auto openHandler = [&conn, asyncResp](
- const boost::system::error_code ec,
- const dbus::utility::
- ManagedObjectType& objects) {
+ auto openHandler =
+ [&conn, asyncResp](
+ const boost::system::error_code ec,
+ const dbus::utility::ManagedObjectType& objects) {
const std::string* socketValue = nullptr;
const std::string* endpointValue = nullptr;
const std::string* endpointObjectPath = nullptr;
@@ -404,13 +400,11 @@
sessions[&conn]->run();
};
- crow::connections::systemBus->async_method_call(
- std::move(openHandler),
- "xyz.openbmc_project.VirtualMedia",
- "/xyz/openbmc_project/VirtualMedia",
- "org.freedesktop.DBus.ObjectManager",
- "GetManagedObjects");
- };
+ crow::connections::systemBus->async_method_call(
+ std::move(openHandler), "xyz.openbmc_project.VirtualMedia",
+ "/xyz/openbmc_project/VirtualMedia",
+ "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
+ };
crow::connections::systemBus->async_method_call(
std::move(getUserInfoHandler),