From 5a39f77a17fa28911c87caea1e2903c059e7ec41 Mon Sep 17 00:00:00 2001 From: Patrick Williams Date: Fri, 20 Oct 2023 11:20:21 -0500 Subject: clang-format: copy latest and re-format clang-format-17 has some backwards incompatible changes that require additional settings for best compatibility and re-running the formatter. Copy the latest .clang-format from the docs repository and reformat the repository. Change-Id: I2f9540cf0d545a2da4d6289fc87b754f684bc9a7 Signed-off-by: Patrick Williams --- include/async_resolve.hpp | 2 +- include/cors_preflight.hpp | 2 +- include/dbus_monitor.hpp | 229 ++++++++++++++++---------------- include/dbus_privileges.hpp | 2 +- include/dbus_utility.hpp | 10 +- include/google/google_service_root.hpp | 4 +- include/hostname_monitor.hpp | 2 +- include/http_utility.hpp | 4 +- include/ibm/management_console_rest.hpp | 18 +-- include/image_upload.hpp | 6 +- include/kvm_websocket.hpp | 56 ++++---- include/nbd_proxy.hpp | 6 +- include/obmc_console.hpp | 8 +- include/openbmc_dbus_rest.hpp | 158 +++++++++++----------- include/vm_websocket.hpp | 86 ++++++------ 15 files changed, 295 insertions(+), 298 deletions(-) (limited to 'include') diff --git a/include/async_resolve.hpp b/include/async_resolve.hpp index 71d2497e26..805fbad124 100644 --- a/include/async_resolve.hpp +++ b/include/async_resolve.hpp @@ -116,7 +116,7 @@ class Resolver } // All the resolved data is filled in the endpointList handler(ec, endpointList); - }, + }, "org.freedesktop.resolve1", "/org/freedesktop/resolve1", "org.freedesktop.resolve1.Manager", "ResolveHostname", 0, host, AF_UNSPEC, flag); diff --git a/include/cors_preflight.hpp b/include/cors_preflight.hpp index 43e90738de..b7272229b1 100644 --- a/include/cors_preflight.hpp +++ b/include/cors_preflight.hpp @@ -14,6 +14,6 @@ inline void requestRoutes(App& app) const std::shared_ptr&, const std::string&) { // An empty body handler that simply returns the headers bmcweb // uses This allows browsers to do their CORS preflight checks - }); + }); } } // namespace cors_preflight diff --git a/include/dbus_monitor.hpp b/include/dbus_monitor.hpp index 26827172a4..25f0c7f772 100644 --- a/include/dbus_monitor.hpp +++ b/include/dbus_monitor.hpp @@ -114,141 +114,140 @@ inline void requestRoutes(App& app) .privileges({{"Login"}}) .websocket() .onopen([&](crow::websocket::Connection& conn) { - BMCWEB_LOG_DEBUG("Connection {} opened", logPtr(&conn)); - sessions.try_emplace(&conn); - }) + BMCWEB_LOG_DEBUG("Connection {} opened", logPtr(&conn)); + sessions.try_emplace(&conn); + }) .onclose([&](crow::websocket::Connection& conn, const std::string&) { - sessions.erase(&conn); - }) + sessions.erase(&conn); + }) .onmessage([&](crow::websocket::Connection& conn, const std::string& data, bool) { - const auto sessionPair = sessions.find(&conn); - if (sessionPair == sessions.end()) - { - conn.close("Internal error"); - } - DbusWebsocketSession& thisSession = sessionPair->second; - BMCWEB_LOG_DEBUG("Connection {} received {}", logPtr(&conn), data); - nlohmann::json j = nlohmann::json::parse(data, nullptr, false); - if (j.is_discarded()) - { - BMCWEB_LOG_ERROR("Unable to parse json data for monitor"); - conn.close("Unable to parse json request"); - return; - } - nlohmann::json::iterator interfaces = j.find("interfaces"); - if (interfaces != j.end()) + const auto sessionPair = sessions.find(&conn); + if (sessionPair == sessions.end()) + { + conn.close("Internal error"); + } + DbusWebsocketSession& thisSession = sessionPair->second; + BMCWEB_LOG_DEBUG("Connection {} received {}", logPtr(&conn), data); + nlohmann::json j = nlohmann::json::parse(data, nullptr, false); + if (j.is_discarded()) + { + BMCWEB_LOG_ERROR("Unable to parse json data for monitor"); + conn.close("Unable to parse json request"); + return; + } + nlohmann::json::iterator interfaces = j.find("interfaces"); + if (interfaces != j.end()) + { + thisSession.interfaces.reserve(interfaces->size()); + for (auto& interface : *interfaces) { - thisSession.interfaces.reserve(interfaces->size()); - for (auto& interface : *interfaces) + const std::string* str = + interface.get_ptr(); + if (str != nullptr) { - const std::string* str = - interface.get_ptr(); - if (str != nullptr) - { - thisSession.interfaces.insert(*str); - } + thisSession.interfaces.insert(*str); } } + } + + nlohmann::json::iterator paths = j.find("paths"); + if (paths == j.end()) + { + BMCWEB_LOG_ERROR("Unable to find paths in json data"); + conn.close("Unable to find paths in json data"); + return; + } - nlohmann::json::iterator paths = j.find("paths"); - if (paths == j.end()) + size_t interfaceCount = thisSession.interfaces.size(); + if (interfaceCount == 0) + { + interfaceCount = 1; + } + // Reserve our matches upfront. For each path there is 1 for + // interfacesAdded, and InterfaceCount number for + // PropertiesChanged + thisSession.matches.reserve(thisSession.matches.size() + + paths->size() * (1U + interfaceCount)); + + // These regexes derived on the rules here: + // https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names + static std::regex validPath("^/([A-Za-z0-9_]+/?)*$"); + static std::regex validInterface( + "^[A-Za-z_][A-Za-z0-9_]*(\\.[A-Za-z_][A-Za-z0-9_]*)+$"); + + for (const auto& thisPath : *paths) + { + const std::string* thisPathString = + thisPath.get_ptr(); + if (thisPathString == nullptr) { - BMCWEB_LOG_ERROR("Unable to find paths in json data"); - conn.close("Unable to find paths in json data"); + BMCWEB_LOG_ERROR("subscribe path isn't a string?"); + conn.close(); return; } - - size_t interfaceCount = thisSession.interfaces.size(); - if (interfaceCount == 0) + if (!std::regex_match(*thisPathString, validPath)) { - interfaceCount = 1; + BMCWEB_LOG_ERROR("Invalid path name {}", *thisPathString); + conn.close(); + return; } - // Reserve our matches upfront. For each path there is 1 for - // interfacesAdded, and InterfaceCount number for - // PropertiesChanged - thisSession.matches.reserve(thisSession.matches.size() + - paths->size() * (1U + interfaceCount)); - - // These regexes derived on the rules here: - // https://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-names - static std::regex validPath("^/([A-Za-z0-9_]+/?)*$"); - static std::regex validInterface( - "^[A-Za-z_][A-Za-z0-9_]*(\\.[A-Za-z_][A-Za-z0-9_]*)+$"); - - for (const auto& thisPath : *paths) + std::string propertiesMatchString = + ("type='signal'," + "interface='org.freedesktop.DBus.Properties'," + "path_namespace='" + + *thisPathString + + "'," + "member='PropertiesChanged'"); + // If interfaces weren't specified, add a single match for all + // interfaces + if (thisSession.interfaces.empty()) { - const std::string* thisPathString = - thisPath.get_ptr(); - if (thisPathString == nullptr) - { - BMCWEB_LOG_ERROR("subscribe path isn't a string?"); - conn.close(); - return; - } - if (!std::regex_match(*thisPathString, validPath)) - { - BMCWEB_LOG_ERROR("Invalid path name {}", *thisPathString); - conn.close(); - return; - } - std::string propertiesMatchString = - ("type='signal'," - "interface='org.freedesktop.DBus.Properties'," - "path_namespace='" + - *thisPathString + - "'," - "member='PropertiesChanged'"); - // If interfaces weren't specified, add a single match for all - // interfaces - if (thisSession.interfaces.empty()) - { - BMCWEB_LOG_DEBUG("Creating match {}", - propertiesMatchString); + BMCWEB_LOG_DEBUG("Creating match {}", propertiesMatchString); - thisSession.matches.emplace_back( - std::make_unique( - *crow::connections::systemBus, - propertiesMatchString, onPropertyUpdate, &conn)); - } - else + thisSession.matches.emplace_back( + std::make_unique( + *crow::connections::systemBus, propertiesMatchString, + onPropertyUpdate, &conn)); + } + else + { + // If interfaces were specified, add a match for each + // interface + for (const std::string& interface : thisSession.interfaces) { - // If interfaces were specified, add a match for each - // interface - for (const std::string& interface : thisSession.interfaces) + if (!std::regex_match(interface, validInterface)) { - if (!std::regex_match(interface, validInterface)) - { - BMCWEB_LOG_ERROR("Invalid interface name {}", - interface); - conn.close(); - return; - } - std::string ifaceMatchString = propertiesMatchString; - ifaceMatchString += ",arg0='"; - ifaceMatchString += interface; - ifaceMatchString += "'"; - BMCWEB_LOG_DEBUG("Creating match {}", ifaceMatchString); - thisSession.matches.emplace_back( - std::make_unique( - *crow::connections::systemBus, ifaceMatchString, - onPropertyUpdate, &conn)); + BMCWEB_LOG_ERROR("Invalid interface name {}", + interface); + conn.close(); + return; } + std::string ifaceMatchString = propertiesMatchString; + ifaceMatchString += ",arg0='"; + ifaceMatchString += interface; + ifaceMatchString += "'"; + BMCWEB_LOG_DEBUG("Creating match {}", ifaceMatchString); + thisSession.matches.emplace_back( + std::make_unique( + *crow::connections::systemBus, ifaceMatchString, + onPropertyUpdate, &conn)); } - std::string objectManagerMatchString = - ("type='signal'," - "interface='org.freedesktop.DBus.ObjectManager'," - "path_namespace='" + - *thisPathString + - "'," - "member='InterfacesAdded'"); - BMCWEB_LOG_DEBUG("Creating match {}", objectManagerMatchString); - thisSession.matches.emplace_back( - std::make_unique( - *crow::connections::systemBus, objectManagerMatchString, - onPropertyUpdate, &conn)); } - }); + std::string objectManagerMatchString = + ("type='signal'," + "interface='org.freedesktop.DBus.ObjectManager'," + "path_namespace='" + + *thisPathString + + "'," + "member='InterfacesAdded'"); + BMCWEB_LOG_DEBUG("Creating match {}", objectManagerMatchString); + thisSession.matches.emplace_back( + std::make_unique( + *crow::connections::systemBus, objectManagerMatchString, + onPropertyUpdate, &conn)); + } + }); } } // namespace dbus_monitor } // namespace crow diff --git a/include/dbus_privileges.hpp b/include/dbus_privileges.hpp index 7fb545a9c1..16aae5e62a 100644 --- a/include/dbus_privileges.hpp +++ b/include/dbus_privileges.hpp @@ -181,7 +181,7 @@ void validatePrivilege(Request& req, const dbus::utility::DBusPropertiesMap& userInfoMap) mutable { afterGetUserInfo(req, asyncResp, rule, std::forward(callback), ec, userInfoMap); - }, + }, "xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user", "xyz.openbmc_project.User.Manager", "GetUserInfo", username); } diff --git a/include/dbus_utility.hpp b/include/dbus_utility.hpp index a8eefd5c1f..933d733f96 100644 --- a/include/dbus_utility.hpp +++ b/include/dbus_utility.hpp @@ -151,7 +151,7 @@ inline void checkDbusPathExists(const std::string& path, Callback&& callback) const boost::system::error_code& ec, const dbus::utility::MapperGetObject& objectNames) { callback(!ec && !objectNames.empty()); - }, + }, "xyz.openbmc_project.ObjectMapper", "/xyz/openbmc_project/object_mapper", "xyz.openbmc_project.ObjectMapper", "GetObject", path, @@ -185,7 +185,7 @@ inline void getSubTreePaths( const boost::system::error_code& ec, const MapperGetSubTreePathsResponse& subtreePaths) { callback(ec, subtreePaths); - }, + }, "xyz.openbmc_project.ObjectMapper", "/xyz/openbmc_project/object_mapper", "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", path, depth, @@ -221,7 +221,7 @@ inline void getAssociatedSubTreePaths( const boost::system::error_code& ec, const MapperGetSubTreePathsResponse& subtreePaths) { callback(ec, subtreePaths); - }, + }, "xyz.openbmc_project.ObjectMapper", "/xyz/openbmc_project/object_mapper", "xyz.openbmc_project.ObjectMapper", "GetAssociatedSubTreePaths", @@ -238,7 +238,7 @@ inline void [callback{std::move(callback)}](const boost::system::error_code& ec, const MapperGetObject& object) { callback(ec, object); - }, + }, "xyz.openbmc_project.ObjectMapper", "/xyz/openbmc_project/object_mapper", "xyz.openbmc_project.ObjectMapper", "GetObject", path, interfaces); @@ -264,7 +264,7 @@ inline void [callback{std::move(callback)}](const boost::system::error_code& ec, const ManagedObjectType& objects) { callback(ec, objects); - }, + }, service, path, "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); } diff --git a/include/google/google_service_root.hpp b/include/google/google_service_root.hpp index bb51490e9d..9dd2405738 100644 --- a/include/google/google_service_root.hpp +++ b/include/google/google_service_root.hpp @@ -110,7 +110,7 @@ inline void resolveRoT(const std::string& command, const dbus::utility::MapperGetSubTreeResponse& subtree) { hothGetSubtreeCallback(command, asyncResp, rotId, entityHandler, ec, subtree); - }); + }); } inline void populateRootOfTrustEntity( @@ -181,7 +181,7 @@ inline void [asyncResp{asyncResp}](const boost::system::error_code& ec, const std::vector& responseBytes) { invocationCallback(asyncResp, ec, responseBytes); - }, + }, resolvedEntity.service, resolvedEntity.object, resolvedEntity.interface, "SendHostCommand", bytes); } diff --git a/include/hostname_monitor.hpp b/include/hostname_monitor.hpp index f1a0d3d2c1..6339a6b414 100644 --- a/include/hostname_monitor.hpp +++ b/include/hostname_monitor.hpp @@ -29,7 +29,7 @@ inline void installCertificate(const std::filesystem::path& certPath) BMCWEB_LOG_INFO("Replace HTTPs Certificate Success, " "remove temporary certificate file.."); remove(certPath.c_str()); - }, + }, "xyz.openbmc_project.Certs.Manager.Server.Https", "/xyz/openbmc_project/certs/server/https/1", "xyz.openbmc_project.Certs.Replace", "Replace", certPath.string()); diff --git a/include/http_utility.hpp b/include/http_utility.hpp index 2fd5e14016..4f430aeb8e 100644 --- a/include/http_utility.hpp +++ b/include/http_utility.hpp @@ -78,8 +78,8 @@ inline ContentType } const auto* knownContentType = std::ranges::find_if( contentTypes, [encoding](const ContentTypePair& pair) { - return pair.contentTypeString == encoding; - }); + return pair.contentTypeString == encoding; + }); if (knownContentType == contentTypes.end()) { diff --git a/include/ibm/management_console_rest.hpp b/include/ibm/management_console_rest.hpp index b87cb1ee19..fd1e2a5cc8 100644 --- a/include/ibm/management_console_rest.hpp +++ b/include/ibm/management_console_rest.hpp @@ -695,7 +695,7 @@ inline void requestRoutes(App& app) "/ibm/v1/HMC/LockService"; asyncResp->res.jsonValue["BroadcastService"]["@odata.id"] = "/ibm/v1/HMC/BroadcastService"; - }); + }); BMCWEB_ROUTE(app, "/ibm/v1/Host/ConfigFiles") .privileges({{"ConfigureComponents", "ConfigureManager"}}) @@ -703,7 +703,7 @@ inline void requestRoutes(App& app) [](const crow::Request&, const std::shared_ptr& asyncResp) { handleConfigFileList(asyncResp); - }); + }); BMCWEB_ROUTE(app, "/ibm/v1/Host/ConfigFiles/Actions/IBMConfigFiles.DeleteAll") @@ -712,7 +712,7 @@ inline void requestRoutes(App& app) [](const crow::Request&, const std::shared_ptr& asyncResp) { deleteConfigFiles(asyncResp); - }); + }); BMCWEB_ROUTE(app, "/ibm/v1/Host/ConfigFiles/") .privileges({{"ConfigureComponents", "ConfigureManager"}}) @@ -729,7 +729,7 @@ inline void requestRoutes(App& app) return; } handleFileUrl(req, asyncResp, fileName); - }); + }); BMCWEB_ROUTE(app, "/ibm/v1/HMC/LockService") .privileges({{"ConfigureComponents", "ConfigureManager"}}) @@ -737,7 +737,7 @@ inline void requestRoutes(App& app) [](const crow::Request&, const std::shared_ptr& asyncResp) { getLockServiceData(asyncResp); - }); + }); BMCWEB_ROUTE(app, "/ibm/v1/HMC/LockService/Actions/LockService.AcquireLock") .privileges({{"ConfigureComponents", "ConfigureManager"}}) @@ -753,7 +753,7 @@ inline void requestRoutes(App& app) return; } handleAcquireLockAPI(req, asyncResp, body); - }); + }); BMCWEB_ROUTE(app, "/ibm/v1/HMC/LockService/Actions/LockService.ReleaseLock") .privileges({{"ConfigureComponents", "ConfigureManager"}}) .methods(boost::beast::http::verb::post)( @@ -783,7 +783,7 @@ inline void requestRoutes(App& app) redfish::messages::propertyValueNotInList(asyncResp->res, type, "Type"); } - }); + }); BMCWEB_ROUTE(app, "/ibm/v1/HMC/LockService/Actions/LockService.GetLockList") .privileges({{"ConfigureComponents", "ConfigureManager"}}) .methods(boost::beast::http::verb::post)( @@ -798,7 +798,7 @@ inline void requestRoutes(App& app) return; } handleGetLockListAPI(asyncResp, listSessionIds); - }); + }); BMCWEB_ROUTE(app, "/ibm/v1/HMC/BroadcastService") .privileges({{"ConfigureComponents", "ConfigureManager"}}) @@ -806,7 +806,7 @@ inline void requestRoutes(App& app) [](const crow::Request& req, const std::shared_ptr& asyncResp) { handleBroadcastService(req, asyncResp); - }); + }); } } // namespace ibm_mc diff --git a/include/image_upload.hpp b/include/image_upload.hpp index f5c81101c1..ef615cb3b8 100644 --- a/include/image_upload.hpp +++ b/include/image_upload.hpp @@ -68,8 +68,8 @@ inline void m.read(path, interfaces); if (std::ranges::find_if(interfaces, [](const auto& i) { - return i.first == "xyz.openbmc_project.Software.Version"; - }) != interfaces.end()) + return i.first == "xyz.openbmc_project.Software.Version"; + }) != interfaces.end()) { timeout.cancel(); std::string leaf = path.filename(); @@ -115,7 +115,7 @@ inline void requestRoutes(App& app) [](const crow::Request& req, const std::shared_ptr& asyncResp) { uploadImageHandler(req, asyncResp); - }); + }); } } // namespace image_upload } // namespace crow diff --git a/include/kvm_websocket.hpp b/include/kvm_websocket.hpp index d04c19fd93..0089ae375b 100644 --- a/include/kvm_websocket.hpp +++ b/include/kvm_websocket.hpp @@ -24,20 +24,20 @@ class KvmSession : public std::enable_shared_from_this boost::asio::ip::make_address("127.0.0.1"), 5900); hostSocket.async_connect( endpoint, [this, &connIn](const boost::system::error_code& ec) { - if (ec) + if (ec) + { + BMCWEB_LOG_ERROR( + "conn:{}, Couldn't connect to KVM socket port: {}", + logPtr(&conn), ec); + if (ec != boost::asio::error::operation_aborted) { - BMCWEB_LOG_ERROR( - "conn:{}, Couldn't connect to KVM socket port: {}", - logPtr(&conn), ec); - if (ec != boost::asio::error::operation_aborted) - { - connIn.close("Error in connecting to KVM port"); - } - return; + connIn.close("Error in connecting to KVM port"); } + return; + } - doRead(); - }); + doRead(); + }); } void onMessage(const std::string& data) @@ -102,7 +102,7 @@ class KvmSession : public std::enable_shared_from_this outputBuffer.consume(bytesRead); doRead(); - }); + }); } void doWrite() @@ -152,7 +152,7 @@ class KvmSession : public std::enable_shared_from_this } doWrite(); - }); + }); } crow::websocket::Connection& conn; @@ -175,26 +175,26 @@ inline void requestRoutes(App& app) .privileges({{"ConfigureComponents", "ConfigureManager"}}) .websocket() .onopen([](crow::websocket::Connection& conn) { - BMCWEB_LOG_DEBUG("Connection {} opened", logPtr(&conn)); + BMCWEB_LOG_DEBUG("Connection {} opened", logPtr(&conn)); - if (sessions.size() == maxSessions) - { - conn.close("Max sessions are already connected"); - return; - } + if (sessions.size() == maxSessions) + { + conn.close("Max sessions are already connected"); + return; + } - sessions[&conn] = std::make_shared(conn); - }) + sessions[&conn] = std::make_shared(conn); + }) .onclose([](crow::websocket::Connection& conn, const std::string&) { - sessions.erase(&conn); - }) + sessions.erase(&conn); + }) .onmessage([](crow::websocket::Connection& conn, const std::string& data, bool) { - if (sessions[&conn]) - { - sessions[&conn]->onMessage(data); - } - }); + if (sessions[&conn]) + { + sessions[&conn]->onMessage(data); + } + }); } } // namespace obmc_kvm diff --git a/include/nbd_proxy.hpp b/include/nbd_proxy.hpp index 5540886419..17d57b4c15 100644 --- a/include/nbd_proxy.hpp +++ b/include/nbd_proxy.hpp @@ -164,8 +164,8 @@ struct NbdProxyServer : std::enable_shared_from_this self2->ux2wsBuf.consume(self2->ux2wsBuf.size()); self2->doRead(); } - }); }); + }); } void doWrite(std::function&& onDone) @@ -211,7 +211,7 @@ struct NbdProxyServer : std::enable_shared_from_this return; } onDone(); - }); + }); } // Keeps UNIX socket endpoint file path @@ -332,7 +332,7 @@ inline void onOpen(crow::websocket::Connection& conn) [&conn](const boost::system::error_code& ec, const dbus::utility::ManagedObjectType& objects) { afterGetManagedObjects(conn, ec, objects); - }); + }); // We need to wait for dbus and the websockets to hook up before data is // sent/received. Tell the core to hold off messages until the sockets are diff --git a/include/obmc_console.hpp b/include/obmc_console.hpp index 2dd3edbf51..fb363be275 100644 --- a/include/obmc_console.hpp +++ b/include/obmc_console.hpp @@ -71,7 +71,7 @@ class ConsoleHandler : public std::enable_shared_from_this return; } self->doWrite(); - }); + }); } static void afterSendEx(const std::weak_ptr& weak) @@ -107,7 +107,7 @@ class ConsoleHandler : public std::enable_shared_from_this std::string_view payload(outputBuffer.data(), bytesRead); self->conn.sendEx(crow::websocket::MessageType::Binary, payload, std::bind_front(afterSendEx, weak_from_this())); - }); + }); } bool connect(int fd) @@ -247,7 +247,7 @@ inline void [&conn](const boost::system::error_code& ec1, const sdbusplus::message::unix_fd& unixfd) { connectConsoleSocket(conn, ec1, unixfd); - }, + }, consoleService, consoleObjPath, "xyz.openbmc_project.Console.Access", "Connect"); } @@ -299,7 +299,7 @@ inline void onOpen(crow::websocket::Connection& conn) [&conn, consolePath](const boost::system::error_code& ec, const ::dbus::utility::MapperGetObject& objInfo) { processConsoleObject(conn, consolePath, ec, objInfo); - }); + }); } inline void onMessage(crow::websocket::Connection& conn, diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp index 7c47bcc5fc..bade59e11b 100644 --- a/include/openbmc_dbus_rest.hpp +++ b/include/openbmc_dbus_rest.hpp @@ -176,7 +176,7 @@ inline void node = node->NextSiblingElement("node"); } } - }, + }, processName, objectPath, "org.freedesktop.DBus.Introspectable", "Introspect"); } @@ -223,10 +223,10 @@ inline void getPropertiesForEnumerate( { propertyJson = val; } - }, + }, value); } - }); + }); } // Find any results that weren't picked up by ObjectManagers, to be @@ -347,7 +347,7 @@ inline void getManagedObjectsForEnumerate( { propertyJson = val; } - }, + }, property.second); } } @@ -362,7 +362,7 @@ inline void getManagedObjectsForEnumerate( } } } - }); + }); } inline void findObjectManagerPathForEnumerate( @@ -395,7 +395,7 @@ inline void findObjectManagerPathForEnumerate( } } } - }, + }, "xyz.openbmc_project.ObjectMapper", "/xyz/openbmc_project/object_mapper", "xyz.openbmc_project.ObjectMapper", "GetAncestors", objectName, @@ -469,7 +469,7 @@ inline void getObjectAndEnumerate( transaction->objectPath, connection.first, transaction); } } - }); + }); } // Structure for storing data on an in progress action @@ -1487,10 +1487,9 @@ inline void findActionOnInterface( } crow::connections::systemBus->async_send( - m, - [transaction, - returnType](const boost::system::error_code& ec2, - sdbusplus::message_t& m2) { + m, [transaction, returnType]( + const boost::system::error_code& ec2, + sdbusplus::message_t& m2) { if (ec2) { transaction->methodFailed = true; @@ -1515,7 +1514,7 @@ inline void findActionOnInterface( transaction->methodPassed = true; handleMethodResponse(transaction, m2, returnType); - }); + }); break; } methodNode = methodNode->NextSiblingElement("method"); @@ -1523,7 +1522,7 @@ inline void findActionOnInterface( } interfaceNode = interfaceNode->NextSiblingElement("interface"); } - }, + }, connectionName, transaction->path, "org.freedesktop.DBus.Introspectable", "Introspect"); } @@ -1596,7 +1595,7 @@ inline void handleAction(const crow::Request& req, { findActionOnInterface(transaction, object.first); } - }); + }); } inline void handleDelete(const std::shared_ptr& asyncResp, @@ -1629,7 +1628,7 @@ inline void handleDelete(const std::shared_ptr& asyncResp, { findActionOnInterface(transaction, object.first); } - }); + }); } inline void handleList(const std::shared_ptr& asyncResp, @@ -1652,7 +1651,7 @@ inline void handleList(const std::shared_ptr& asyncResp, asyncResp->res.jsonValue["message"] = "200 OK"; asyncResp->res.jsonValue["data"] = objectPaths; } - }); + }); } inline void handleEnumerate(const std::shared_ptr& asyncResp, @@ -1689,7 +1688,7 @@ inline void handleEnumerate(const std::shared_ptr& asyncResp, // Add the data for the path passed in to the results // as if GetSubTree returned it, and continue on enumerating getObjectAndEnumerate(transaction); - }); + }); } inline void handleGet(const std::shared_ptr& asyncResp, @@ -1742,58 +1741,58 @@ inline void handleGet(const std::shared_ptr& asyncResp, m, [asyncResp, response, propertyName](const boost::system::error_code& ec2, sdbusplus::message_t& msg) { - if (ec2) + if (ec2) + { + BMCWEB_LOG_ERROR("Bad dbus request error: {}", ec2); + } + else + { + nlohmann::json properties; + int r = convertDBusToJSON("a{sv}", msg, properties); + if (r < 0) { - BMCWEB_LOG_ERROR("Bad dbus request error: {}", ec2); + BMCWEB_LOG_ERROR("convertDBusToJSON failed"); } else { - nlohmann::json properties; - int r = convertDBusToJSON("a{sv}", msg, properties); - if (r < 0) - { - BMCWEB_LOG_ERROR("convertDBusToJSON failed"); - } - else + for (const auto& prop : properties.items()) { - for (const auto& prop : properties.items()) - { - // if property name is empty, or - // matches our search query, add it - // to the response json + // if property name is empty, or + // matches our search query, add it + // to the response json - if (propertyName->empty()) - { - (*response)[prop.key()] = - std::move(prop.value()); - } - else if (prop.key() == *propertyName) - { - *response = std::move(prop.value()); - } + if (propertyName->empty()) + { + (*response)[prop.key()] = + std::move(prop.value()); + } + else if (prop.key() == *propertyName) + { + *response = std::move(prop.value()); } } } - if (response.use_count() == 1) + } + if (response.use_count() == 1) + { + if (!propertyName->empty() && response->empty()) { - if (!propertyName->empty() && response->empty()) - { - setErrorResponse( - asyncResp->res, - boost::beast::http::status::not_found, - propNotFoundDesc, notFoundMsg); - } - else - { - asyncResp->res.jsonValue["status"] = "ok"; - asyncResp->res.jsonValue["message"] = "200 OK"; - asyncResp->res.jsonValue["data"] = *response; - } + setErrorResponse( + asyncResp->res, + boost::beast::http::status::not_found, + propNotFoundDesc, notFoundMsg); } - }); + else + { + asyncResp->res.jsonValue["status"] = "ok"; + asyncResp->res.jsonValue["message"] = "200 OK"; + asyncResp->res.jsonValue["data"] = *response; + } + } + }); } } - }); + }); } struct AsyncPutRequest @@ -1975,10 +1974,9 @@ inline void handlePut(const crow::Request& req, return; } crow::connections::systemBus->async_send( - m, - [transaction]( - const boost::system::error_code& ec, - sdbusplus::message_t& m2) { + m, [transaction]( + const boost::system::error_code& ec, + sdbusplus::message_t& m2) { BMCWEB_LOG_DEBUG("sent"); if (ec) { @@ -2002,18 +2000,18 @@ inline void handlePut(const crow::Request& req, transaction->asyncResp->res .jsonValue["data"] = nullptr; } - }); + }); } } propNode = propNode->NextSiblingElement("property"); } ifaceNode = ifaceNode->NextSiblingElement("interface"); } - }, + }, connectionName, transaction->objectPath, "org.freedesktop.DBus.Introspectable", "Introspect"); } - }); + }); } inline void handleDBusUrl(const crow::Request& req, @@ -2195,7 +2193,7 @@ inline void interface = interface->NextSiblingElement("interface"); } - }, + }, processName, objectPath, "org.freedesktop.DBus.Introspectable", "Introspect"); } @@ -2361,17 +2359,17 @@ inline void m, [&propertyItem, asyncResp](const boost::system::error_code& ec2, sdbusplus::message_t& msg) { - if (ec2) - { - return; - } + if (ec2) + { + return; + } - convertDBusToJSON("v", msg, propertyItem); - }); + convertDBusToJSON("v", msg, propertyItem); + }); } property = property->NextSiblingElement("property"); } - }, + }, processName, objectPath, "org.freedesktop.DBus.Introspectable", "Introspect"); } @@ -2427,7 +2425,7 @@ inline void requestRoutes(App& app) bus["name"] = "system"; asyncResp->res.jsonValue["busses"] = std::move(buses); asyncResp->res.jsonValue["status"] = "ok"; - }); + }); BMCWEB_ROUTE(app, "/bus/system/") .privileges({{"Login"}}) @@ -2458,7 +2456,7 @@ inline void requestRoutes(App& app) crow::connections::systemBus->async_method_call( std::move(myCallback), "org.freedesktop.DBus", "/", "org.freedesktop.DBus", "ListNames"); - }); + }); BMCWEB_ROUTE(app, "/list/") .privileges({{"Login"}}) @@ -2466,7 +2464,7 @@ inline void requestRoutes(App& app) [](const crow::Request&, const std::shared_ptr& asyncResp) { handleList(asyncResp, "/"); - }); + }); BMCWEB_ROUTE(app, "/xyz/") .privileges({{"Login"}}) @@ -2476,7 +2474,7 @@ inline void requestRoutes(App& app) const std::string& path) { std::string objectPath = "/xyz/" + path; handleDBusUrl(req, asyncResp, objectPath); - }); + }); BMCWEB_ROUTE(app, "/xyz/") .privileges({{"ConfigureComponents", "ConfigureManager"}}) @@ -2487,7 +2485,7 @@ inline void requestRoutes(App& app) const std::string& path) { std::string objectPath = "/xyz/" + path; handleDBusUrl(req, asyncResp, objectPath); - }); + }); BMCWEB_ROUTE(app, "/org/") .privileges({{"Login"}}) @@ -2497,7 +2495,7 @@ inline void requestRoutes(App& app) const std::string& path) { std::string objectPath = "/org/" + path; handleDBusUrl(req, asyncResp, objectPath); - }); + }); BMCWEB_ROUTE(app, "/org/") .privileges({{"ConfigureComponents", "ConfigureManager"}}) @@ -2508,7 +2506,7 @@ inline void requestRoutes(App& app) const std::string& path) { std::string objectPath = "/org/" + path; handleDBusUrl(req, asyncResp, objectPath); - }); + }); BMCWEB_ROUTE(app, "/download/dump//") .privileges({{"ConfigureManager"}}) @@ -2572,7 +2570,7 @@ inline void requestRoutes(App& app) } asyncResp->res.result(boost::beast::http::status::not_found); return; - }); + }); BMCWEB_ROUTE(app, "/bus/system//") .privileges({{"Login"}}) @@ -2582,7 +2580,7 @@ inline void requestRoutes(App& app) const std::shared_ptr& asyncResp, const std::string& connection) { introspectObjects(connection, "/", asyncResp); - }); + }); BMCWEB_ROUTE(app, "/bus/system//") .privileges({{"ConfigureComponents", "ConfigureManager"}}) diff --git a/include/vm_websocket.hpp b/include/vm_websocket.hpp index a8d6a1494c..13bbdc6b23 100644 --- a/include/vm_websocket.hpp +++ b/include/vm_websocket.hpp @@ -111,7 +111,7 @@ class Handler : public std::enable_shared_from_this return; } doWrite(); - }); + }); } void doRead() @@ -145,7 +145,7 @@ class Handler : public std::enable_shared_from_this outputBuffer->consume(bytesRead); doRead(); - }); + }); } boost::process::async_pipe pipeOut; @@ -169,57 +169,57 @@ inline void requestRoutes(App& app) .privileges({{"ConfigureComponents", "ConfigureManager"}}) .websocket() .onopen([](crow::websocket::Connection& conn) { - BMCWEB_LOG_DEBUG("Connection {} opened", logPtr(&conn)); + BMCWEB_LOG_DEBUG("Connection {} opened", logPtr(&conn)); - if (session != nullptr) - { - conn.close("Session already connected"); - return; - } + if (session != nullptr) + { + conn.close("Session already connected"); + return; + } - if (handler != nullptr) - { - conn.close("Handler already running"); - return; - } + if (handler != nullptr) + { + conn.close("Handler already running"); + return; + } - session = &conn; + session = &conn; - // media is the last digit of the endpoint /vm/0/0. A future - // enhancement can include supporting different endpoint values. - const char* media = "0"; - handler = std::make_shared(media, conn.getIoContext()); - handler->connect(); - }) + // media is the last digit of the endpoint /vm/0/0. A future + // enhancement can include supporting different endpoint values. + const char* media = "0"; + handler = std::make_shared(media, conn.getIoContext()); + handler->connect(); + }) .onclose([](crow::websocket::Connection& conn, const std::string& /*reason*/) { - if (&conn != session) - { - return; - } + if (&conn != session) + { + return; + } - session = nullptr; - handler->doClose(); - handler->inputBuffer->clear(); - handler->outputBuffer->clear(); - handler.reset(); - }) + session = nullptr; + handler->doClose(); + handler->inputBuffer->clear(); + handler->outputBuffer->clear(); + handler.reset(); + }) .onmessage([](crow::websocket::Connection& conn, const std::string& data, bool) { - if (data.length() > - handler->inputBuffer->capacity() - handler->inputBuffer->size()) - { - BMCWEB_LOG_ERROR("Buffer overrun when writing {} bytes", - data.length()); - conn.close("Buffer overrun"); - return; - } + if (data.length() > + handler->inputBuffer->capacity() - handler->inputBuffer->size()) + { + BMCWEB_LOG_ERROR("Buffer overrun when writing {} bytes", + data.length()); + conn.close("Buffer overrun"); + return; + } - boost::asio::buffer_copy(handler->inputBuffer->prepare(data.size()), - boost::asio::buffer(data)); - handler->inputBuffer->commit(data.size()); - handler->doWrite(); - }); + boost::asio::buffer_copy(handler->inputBuffer->prepare(data.size()), + boost::asio::buffer(data)); + handler->inputBuffer->commit(data.size()); + handler->doWrite(); + }); } } // namespace obmc_vm -- cgit v1.2.3