clang-format: re-format for clang-18
clang-format-18 isn't compatible with the clang-format-17 output, so we
need to reformat the code with the latest version. The way clang-18
handles lambda formatting also changed, so we have made changes to the
organization default style format to better handle lambda formatting.
See I5e08687e696dd240402a2780158664b7113def0e for updated style.
See Iea0776aaa7edd483fa395e23de25ebf5a6288f71 for clang-18 enablement.
Change-Id: Iceec1dc95b6c908ec6c21fb40093de9dd18bf11a
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
diff --git a/include/async_resolve.hpp b/include/async_resolve.hpp
index dbc0cfc..ae73dd3 100644
--- a/include/async_resolve.hpp
+++ b/include/async_resolve.hpp
@@ -86,35 +86,35 @@
const std::vector<
std::tuple<int32_t, int32_t, std::vector<uint8_t>>>& resp,
const std::string& hostName, const uint64_t flagNum) {
- results_type endpointList;
- if (ec)
- {
- BMCWEB_LOG_ERROR("Resolve failed: {}", ec.message());
- handler(ec, endpointList);
- return;
- }
- BMCWEB_LOG_DEBUG("ResolveHostname returned: {}:{}", hostName,
- flagNum);
- // Extract the IP address from the response
- for (const std::tuple<int32_t, int32_t, std::vector<uint8_t>>&
- resolveList : resp)
- {
- boost::asio::ip::tcp::endpoint endpoint;
- endpoint.port(portNum);
- if (!endpointFromResolveTuple(std::get<2>(resolveList),
- endpoint))
+ results_type endpointList;
+ if (ec)
{
- boost::system::error_code ecErr = make_error_code(
- boost::system::errc::address_not_available);
- handler(ecErr, endpointList);
+ BMCWEB_LOG_ERROR("Resolve failed: {}", ec.message());
+ handler(ec, endpointList);
+ return;
}
- BMCWEB_LOG_DEBUG("resolved endpoint is : {}",
- endpoint.address().to_string());
- endpointList.push_back(endpoint);
- }
- // All the resolved data is filled in the endpointList
- handler(ec, endpointList);
- },
+ BMCWEB_LOG_DEBUG("ResolveHostname returned: {}:{}", hostName,
+ flagNum);
+ // Extract the IP address from the response
+ for (const std::tuple<int32_t, int32_t, std::vector<uint8_t>>&
+ resolveList : resp)
+ {
+ boost::asio::ip::tcp::endpoint endpoint;
+ endpoint.port(portNum);
+ if (!endpointFromResolveTuple(std::get<2>(resolveList),
+ endpoint))
+ {
+ boost::system::error_code ecErr = make_error_code(
+ boost::system::errc::address_not_available);
+ handler(ecErr, endpointList);
+ }
+ BMCWEB_LOG_DEBUG("resolved endpoint is : {}",
+ endpoint.address().to_string());
+ endpointList.push_back(endpoint);
+ }
+ // 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/authentication.hpp b/include/authentication.hpp
index 6199808..1690550 100644
--- a/include/authentication.hpp
+++ b/include/authentication.hpp
@@ -19,9 +19,8 @@
namespace authentication
{
-inline std::shared_ptr<persistent_data::UserSession>
- performBasicAuth(const boost::asio::ip::address& clientIp,
- std::string_view authHeader)
+inline std::shared_ptr<persistent_data::UserSession> performBasicAuth(
+ const boost::asio::ip::address& clientIp, std::string_view authHeader)
{
BMCWEB_LOG_DEBUG("[AuthMiddleware] Basic authentication");
@@ -142,8 +141,8 @@
{
endIndex = cookieValue.size();
}
- std::string_view authKey = cookieValue.substr(startIndex,
- endIndex - startIndex);
+ std::string_view authKey =
+ cookieValue.substr(startIndex, endIndex - startIndex);
std::shared_ptr<persistent_data::UserSession> sessionOut =
persistent_data::SessionStore::getInstance().loginSessionByToken(
@@ -183,9 +182,8 @@
return nullptr;
}
-inline std::shared_ptr<persistent_data::UserSession>
- performTLSAuth(Response& res,
- const std::shared_ptr<persistent_data::UserSession>& session)
+inline std::shared_ptr<persistent_data::UserSession> performTLSAuth(
+ Response& res, const std::shared_ptr<persistent_data::UserSession>& session)
{
if (session != nullptr)
{
diff --git a/include/dbus_monitor.hpp b/include/dbus_monitor.hpp
index 6ec43d0..39a9897 100644
--- a/include/dbus_monitor.hpp
+++ b/include/dbus_monitor.hpp
@@ -126,135 +126,136 @@
.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())
- {
- thisSession.interfaces.reserve(interfaces->size());
- for (auto& interface : *interfaces)
+ const auto sessionPair = sessions.find(&conn);
+ if (sessionPair == sessions.end())
{
- const std::string* str =
- interface.get_ptr<const std::string*>();
- if (str != nullptr)
+ 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.insert(*str);
+ const std::string* str =
+ interface.get_ptr<const std::string*>();
+ if (str != nullptr)
+ {
+ 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;
- }
-
- size_t interfaceCount = thisSession.interfaces.size();
- if (interfaceCount == 0)
- {
- interfaceCount = 1;
- }
-
- // 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<const std::string*>();
- if (thisPathString == nullptr)
+ nlohmann::json::iterator paths = j.find("paths");
+ if (paths == j.end())
{
- BMCWEB_LOG_ERROR("subscribe path isn't a string?");
- conn.close();
+ BMCWEB_LOG_ERROR("Unable to find paths in json data");
+ conn.close("Unable to find paths in json data");
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);
- thisSession.matches.emplace_back(
- std::make_unique<sdbusplus::bus::match_t>(
- *crow::connections::systemBus, propertiesMatchString,
- onPropertyUpdate, &conn));
- }
- else
+ size_t interfaceCount = thisSession.interfaces.size();
+ if (interfaceCount == 0)
{
- // If interfaces were specified, add a match for each
- // interface
- for (const std::string& interface : thisSession.interfaces)
+ interfaceCount = 1;
+ }
+
+ // 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<const std::string*>();
+ if (thisPathString == nullptr)
{
- 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);
+ 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);
+
thisSession.matches.emplace_back(
std::make_unique<sdbusplus::bus::match_t>(
- *crow::connections::systemBus, ifaceMatchString,
- onPropertyUpdate, &conn));
+ *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 (!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<sdbusplus::bus::match_t>(
+ *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<sdbusplus::bus::match_t>(
+ *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<sdbusplus::bus::match_t>(
- *crow::connections::systemBus, objectManagerMatchString,
- onPropertyUpdate, &conn));
- }
- });
+ });
}
} // namespace dbus_monitor
} // namespace crow
diff --git a/include/dbus_privileges.hpp b/include/dbus_privileges.hpp
index 02d134d..355f877 100644
--- a/include/dbus_privileges.hpp
+++ b/include/dbus_privileges.hpp
@@ -63,10 +63,9 @@
return true;
}
-inline bool
- isUserPrivileged(Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- BaseRule& rule)
+inline bool isUserPrivileged(
+ Request& req, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ BaseRule& rule)
{
if (req.session == nullptr)
{
@@ -134,15 +133,15 @@
[asyncResp, callback = std::forward<CallbackFn>(callback)](
const boost::system::error_code& ec,
const dbus::utility::DBusPropertiesMap& userInfoMap) mutable {
- if (ec)
- {
- BMCWEB_LOG_ERROR("GetUserInfo failed...");
- asyncResp->res.result(
- boost::beast::http::status::internal_server_error);
- return;
- }
- callback(userInfoMap);
- },
+ if (ec)
+ {
+ BMCWEB_LOG_ERROR("GetUserInfo failed...");
+ asyncResp->res.result(
+ boost::beast::http::status::internal_server_error);
+ return;
+ }
+ callback(userInfoMap);
+ },
"xyz.openbmc_project.User.Manager", "/xyz/openbmc_project/user",
"xyz.openbmc_project.User.Manager", "GetUserInfo", username);
}
@@ -161,11 +160,11 @@
req->session->username, asyncResp,
[req, asyncResp, &rule, callback = std::forward<CallbackFn>(callback)](
const dbus::utility::DBusPropertiesMap& userInfoMap) mutable {
- if (afterGetUserInfoValidate(*req, asyncResp, rule, userInfoMap))
- {
- callback();
- }
- });
+ if (afterGetUserInfoValidate(*req, asyncResp, rule, userInfoMap))
+ {
+ callback();
+ }
+ });
}
template <typename CallbackFn>
@@ -178,15 +177,15 @@
username, asyncResp,
[asyncResp, session, callback = std::forward<CallbackFn>(callback)](
const dbus::utility::DBusPropertiesMap& userInfoMap) {
- if (!populateUserInfo(*session, userInfoMap))
- {
- BMCWEB_LOG_ERROR("Failed to populate user information");
- asyncResp->res.result(
- boost::beast::http::status::internal_server_error);
- return;
- }
- callback();
- });
+ if (!populateUserInfo(*session, userInfoMap))
+ {
+ BMCWEB_LOG_ERROR("Failed to populate user information");
+ asyncResp->res.result(
+ boost::beast::http::status::internal_server_error);
+ return;
+ }
+ callback();
+ });
}
} // namespace crow
diff --git a/include/dbus_utility.hpp b/include/dbus_utility.hpp
index 0cd3b7e..c9604f0 100644
--- a/include/dbus_utility.hpp
+++ b/include/dbus_utility.hpp
@@ -151,8 +151,8 @@
[callback = std::forward<Callback>(callback)](
const boost::system::error_code& ec,
const dbus::utility::MapperGetObject& objectNames) {
- callback(!ec && !objectNames.empty());
- },
+ callback(!ec && !objectNames.empty());
+ },
"xyz.openbmc_project.ObjectMapper",
"/xyz/openbmc_project/object_mapper",
"xyz.openbmc_project.ObjectMapper", "GetObject", path,
@@ -185,8 +185,8 @@
[callback{std::move(callback)}](
const boost::system::error_code& ec,
const MapperGetSubTreePathsResponse& subtreePaths) {
- callback(ec, subtreePaths);
- },
+ callback(ec, subtreePaths);
+ },
"xyz.openbmc_project.ObjectMapper",
"/xyz/openbmc_project/object_mapper",
"xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", path, depth,
@@ -221,25 +221,24 @@
[callback{std::move(callback)}](
const boost::system::error_code& ec,
const MapperGetSubTreePathsResponse& subtreePaths) {
- callback(ec, subtreePaths);
- },
+ callback(ec, subtreePaths);
+ },
"xyz.openbmc_project.ObjectMapper",
"/xyz/openbmc_project/object_mapper",
"xyz.openbmc_project.ObjectMapper", "GetAssociatedSubTreePaths",
associatedPath, path, depth, interfaces);
}
-inline void
- getDbusObject(const std::string& path,
- std::span<const std::string_view> interfaces,
- std::function<void(const boost::system::error_code&,
- const MapperGetObject&)>&& callback)
+inline void getDbusObject(
+ const std::string& path, std::span<const std::string_view> interfaces,
+ std::function<void(const boost::system::error_code&,
+ const MapperGetObject&)>&& callback)
{
crow::connections::systemBus->async_method_call(
[callback{std::move(callback)}](const boost::system::error_code& ec,
const MapperGetObject& object) {
- callback(ec, object);
- },
+ callback(ec, object);
+ },
"xyz.openbmc_project.ObjectMapper",
"/xyz/openbmc_project/object_mapper",
"xyz.openbmc_project.ObjectMapper", "GetObject", path, interfaces);
@@ -255,17 +254,16 @@
"xyz.openbmc_project.Association", "endpoints", std::move(callback));
}
-inline void
- getManagedObjects(const std::string& service,
- const sdbusplus::message::object_path& path,
- std::function<void(const boost::system::error_code&,
- const ManagedObjectType&)>&& callback)
+inline void getManagedObjects(
+ const std::string& service, const sdbusplus::message::object_path& path,
+ std::function<void(const boost::system::error_code&,
+ const ManagedObjectType&)>&& callback)
{
crow::connections::systemBus->async_method_call(
[callback{std::move(callback)}](const boost::system::error_code& ec,
const ManagedObjectType& objects) {
- callback(ec, objects);
- },
+ callback(ec, objects);
+ },
service, path, "org.freedesktop.DBus.ObjectManager",
"GetManagedObjects");
}
diff --git a/include/event_service_store.hpp b/include/event_service_store.hpp
index e59a7d8..8501fff 100644
--- a/include/event_service_store.hpp
+++ b/include/event_service_store.hpp
@@ -26,9 +26,8 @@
boost::beast::http::fields httpHeaders;
std::vector<std::string> metricReportDefinitions;
- static std::shared_ptr<UserSubscription>
- fromJson(const nlohmann::json::object_t& j,
- const bool loadFromOldConfig = false)
+ static std::shared_ptr<UserSubscription> fromJson(
+ const nlohmann::json::object_t& j, const bool loadFromOldConfig = false)
{
std::shared_ptr<UserSubscription> subvalue =
std::make_shared<UserSubscription>();
diff --git a/include/forward_unauthorized.hpp b/include/forward_unauthorized.hpp
index 07836ce..bc3d609 100644
--- a/include/forward_unauthorized.hpp
+++ b/include/forward_unauthorized.hpp
@@ -24,8 +24,8 @@
// If we have a webui installed, redirect to that login page
if (hasWebuiRoute)
{
- boost::urls::url forward = boost::urls::format("/?next={}#/login",
- url);
+ boost::urls::url forward =
+ boost::urls::format("/?next={}#/login", url);
res.result(boost::beast::http::status::temporary_redirect);
res.addHeader(boost::beast::http::field::location,
forward.buffer());
diff --git a/include/google/google_service_root.hpp b/include/google/google_service_root.hpp
index 00c5e36..9b7a909 100644
--- a/include/google/google_service_root.hpp
+++ b/include/google/google_service_root.hpp
@@ -107,9 +107,9 @@
[command, asyncResp, rotId, entityHandler{std::move(entityHandler)}](
const boost::system::error_code& ec,
const dbus::utility::MapperGetSubTreeResponse& subtree) {
- hothGetSubtreeCallback(command, asyncResp, rotId, entityHandler, ec,
- subtree);
- });
+ hothGetSubtreeCallback(command, asyncResp, rotId, entityHandler, ec,
+ subtree);
+ });
}
inline void populateRootOfTrustEntity(
@@ -179,8 +179,8 @@
crow::connections::systemBus->async_method_call(
[asyncResp{asyncResp}](const boost::system::error_code& ec,
const std::vector<uint8_t>& responseBytes) {
- invocationCallback(asyncResp, ec, 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 a3a176d..4eb31f1 100644
--- a/include/hostname_monitor.hpp
+++ b/include/hostname_monitor.hpp
@@ -19,21 +19,21 @@
{
crow::connections::systemBus->async_method_call(
[certPath](const boost::system::error_code& ec) {
- if (ec)
- {
- BMCWEB_LOG_ERROR("Replace Certificate Fail..");
- return;
- }
+ if (ec)
+ {
+ BMCWEB_LOG_ERROR("Replace Certificate Fail..");
+ return;
+ }
- BMCWEB_LOG_INFO("Replace HTTPs Certificate Success, "
- "remove temporary certificate file..");
- std::error_code ec2;
- std::filesystem::remove(certPath.c_str(), ec2);
- if (ec2)
- {
- BMCWEB_LOG_ERROR("Failed to remove certificate");
- }
- },
+ BMCWEB_LOG_INFO("Replace HTTPs Certificate Success, "
+ "remove temporary certificate file..");
+ std::error_code ec2;
+ std::filesystem::remove(certPath.c_str(), ec2);
+ if (ec2)
+ {
+ BMCWEB_LOG_ERROR("Failed to remove certificate");
+ }
+ },
"xyz.openbmc_project.Certs.Manager.Server.Https",
"/xyz/openbmc_project/certs/server/https/1",
"xyz.openbmc_project.Certs.Replace", "Replace", certPath.string());
@@ -79,9 +79,9 @@
const int maxKeySize = 256;
std::array<char, maxKeySize> cnBuffer{};
- int cnLength = X509_NAME_get_text_by_NID(X509_get_subject_name(cert),
- NID_commonName, cnBuffer.data(),
- cnBuffer.size());
+ int cnLength =
+ X509_NAME_get_text_by_NID(X509_get_subject_name(cert), NID_commonName,
+ cnBuffer.data(), cnBuffer.size());
if (cnLength == -1)
{
BMCWEB_LOG_ERROR("Failed to read NID_commonName");
diff --git a/include/http_utility.hpp b/include/http_utility.hpp
index 74ab15a..c6c0e3e 100644
--- a/include/http_utility.hpp
+++ b/include/http_utility.hpp
@@ -40,9 +40,8 @@
{"text/event-stream", ContentType::EventStream},
}};
-inline ContentType
- getPreferredContentType(std::string_view header,
- std::span<const ContentType> preferedOrder)
+inline ContentType getPreferredContentType(
+ std::string_view header, std::span<const ContentType> preferedOrder)
{
size_t lastIndex = 0;
while (lastIndex < header.size() + 1)
@@ -74,8 +73,8 @@
}
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 c32412a..ce8e573 100644
--- a/include/ibm/management_console_rest.hpp
+++ b/include/ibm/management_console_rest.hpp
@@ -231,8 +231,8 @@
const std::filesystem::path& pathObj = file.path();
if (std::filesystem::is_regular_file(pathObj))
{
- pathObjList.emplace_back("/ibm/v1/Host/ConfigFiles/" +
- pathObj.filename().string());
+ pathObjList.emplace_back(
+ "/ibm/v1/Host/ConfigFiles/" + pathObj.filename().string());
}
}
}
@@ -291,8 +291,8 @@
return;
}
- std::string contentDispositionParam = "attachment; filename=\"" + fileID +
- "\"";
+ std::string contentDispositionParam =
+ "attachment; filename=\"" + fileID + "\"";
asyncResp->res.addHeader(boost::beast::http::field::content_disposition,
contentDispositionParam);
std::string fileData;
@@ -305,8 +305,8 @@
handleFileDelete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& fileID)
{
- std::string filePath("/var/lib/bmcweb/ibm-management-console/configfiles/" +
- fileID);
+ std::string filePath(
+ "/var/lib/bmcweb/ibm-management-console/configfiles/" + fileID);
BMCWEB_LOG_DEBUG("Removing the file : {}", filePath);
std::ifstream fileOpen(filePath.c_str());
if (static_cast<bool>(fileOpen))
@@ -416,24 +416,24 @@
.methods(boost::beast::http::verb::get)(
[](const crow::Request&,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
- asyncResp->res.jsonValue["@odata.type"] =
- "#ibmServiceRoot.v1_0_0.ibmServiceRoot";
- asyncResp->res.jsonValue["@odata.id"] = "/ibm/v1/";
- asyncResp->res.jsonValue["Id"] = "IBM Rest RootService";
- asyncResp->res.jsonValue["Name"] = "IBM Service Root";
- asyncResp->res.jsonValue["ConfigFiles"]["@odata.id"] =
- "/ibm/v1/Host/ConfigFiles";
- asyncResp->res.jsonValue["BroadcastService"]["@odata.id"] =
- "/ibm/v1/HMC/BroadcastService";
- });
+ asyncResp->res.jsonValue["@odata.type"] =
+ "#ibmServiceRoot.v1_0_0.ibmServiceRoot";
+ asyncResp->res.jsonValue["@odata.id"] = "/ibm/v1/";
+ asyncResp->res.jsonValue["Id"] = "IBM Rest RootService";
+ asyncResp->res.jsonValue["Name"] = "IBM Service Root";
+ asyncResp->res.jsonValue["ConfigFiles"]["@odata.id"] =
+ "/ibm/v1/Host/ConfigFiles";
+ asyncResp->res.jsonValue["BroadcastService"]["@odata.id"] =
+ "/ibm/v1/HMC/BroadcastService";
+ });
BMCWEB_ROUTE(app, "/ibm/v1/Host/ConfigFiles")
.privileges({{"ConfigureComponents", "ConfigureManager"}})
.methods(boost::beast::http::verb::get)(
[](const crow::Request&,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
- handleConfigFileList(asyncResp);
- });
+ handleConfigFileList(asyncResp);
+ });
BMCWEB_ROUTE(app,
"/ibm/v1/Host/ConfigFiles/Actions/IBMConfigFiles.DeleteAll")
@@ -441,8 +441,8 @@
.methods(boost::beast::http::verb::post)(
[](const crow::Request&,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
- deleteConfigFiles(asyncResp);
- });
+ deleteConfigFiles(asyncResp);
+ });
BMCWEB_ROUTE(app, "/ibm/v1/Host/ConfigFiles/<str>")
.privileges({{"ConfigureComponents", "ConfigureManager"}})
@@ -451,23 +451,24 @@
[](const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& fileName) {
- BMCWEB_LOG_DEBUG("ConfigFile : {}", fileName);
- // Validate the incoming fileName
- if (!isValidConfigFileName(fileName, asyncResp->res))
- {
- asyncResp->res.result(boost::beast::http::status::bad_request);
- return;
- }
- handleFileUrl(req, asyncResp, fileName);
- });
+ BMCWEB_LOG_DEBUG("ConfigFile : {}", fileName);
+ // Validate the incoming fileName
+ if (!isValidConfigFileName(fileName, asyncResp->res))
+ {
+ asyncResp->res.result(
+ boost::beast::http::status::bad_request);
+ return;
+ }
+ handleFileUrl(req, asyncResp, fileName);
+ });
BMCWEB_ROUTE(app, "/ibm/v1/HMC/BroadcastService")
.privileges({{"ConfigureComponents", "ConfigureManager"}})
.methods(boost::beast::http::verb::post)(
[](const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
- handleBroadcastService(req, asyncResp);
- });
+ handleBroadcastService(req, asyncResp);
+ });
}
} // namespace ibm_mc
diff --git a/include/image_upload.hpp b/include/image_upload.hpp
index 8b3dc10..202adc6 100644
--- a/include/image_upload.hpp
+++ b/include/image_upload.hpp
@@ -67,30 +67,30 @@
std::function<void(sdbusplus::message_t&)> callback =
[asyncResp](sdbusplus::message_t& m) {
- BMCWEB_LOG_DEBUG("Match fired");
+ BMCWEB_LOG_DEBUG("Match fired");
- sdbusplus::message::object_path path;
- dbus::utility::DBusInterfacesMap interfaces;
- m.read(path, interfaces);
+ sdbusplus::message::object_path path;
+ dbus::utility::DBusInterfacesMap interfaces;
+ m.read(path, interfaces);
- if (std::ranges::find_if(interfaces, [](const auto& i) {
- return i.first == "xyz.openbmc_project.Software.Version";
- }) != interfaces.end())
- {
- timeout.cancel();
- std::string leaf = path.filename();
- if (leaf.empty())
+ if (std::ranges::find_if(interfaces, [](const auto& i) {
+ return i.first == "xyz.openbmc_project.Software.Version";
+ }) != interfaces.end())
{
- leaf = path.str;
- }
+ timeout.cancel();
+ std::string leaf = path.filename();
+ if (leaf.empty())
+ {
+ leaf = path.str;
+ }
- asyncResp->res.jsonValue["data"] = leaf;
- asyncResp->res.jsonValue["message"] = "200 OK";
- asyncResp->res.jsonValue["status"] = "ok";
- BMCWEB_LOG_DEBUG("ending response");
- fwUpdateMatcher = nullptr;
- }
- };
+ asyncResp->res.jsonValue["data"] = leaf;
+ asyncResp->res.jsonValue["message"] = "200 OK";
+ asyncResp->res.jsonValue["status"] = "ok";
+ BMCWEB_LOG_DEBUG("ending response");
+ fwUpdateMatcher = nullptr;
+ }
+ };
fwUpdateMatcher = std::make_unique<sdbusplus::bus::match_t>(
*crow::connections::systemBus,
"interface='org.freedesktop.DBus.ObjectManager',type='signal',"
@@ -120,8 +120,8 @@
.methods(boost::beast::http::verb::post, boost::beast::http::verb::put)(
[](const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
- uploadImageHandler(req, asyncResp);
- });
+ uploadImageHandler(req, asyncResp);
+ });
}
} // namespace image_upload
} // namespace crow
diff --git a/include/kvm_websocket.hpp b/include/kvm_websocket.hpp
index df13a67..fd56da1 100644
--- a/include/kvm_websocket.hpp
+++ b/include/kvm_websocket.hpp
@@ -24,20 +24,20 @@
boost::asio::ip::make_address("127.0.0.1"), 5900);
hostSocket.async_connect(
endpoint, [this, &connIn](const boost::system::error_code& ec) {
- if (ec)
- {
- BMCWEB_LOG_ERROR(
- "conn:{}, Couldn't connect to KVM socket port: {}",
- logPtr(&conn), ec);
- if (ec != boost::asio::error::operation_aborted)
+ if (ec)
{
- connIn.close("Error in connecting to KVM port");
+ 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;
}
- return;
- }
- doRead();
- });
+ doRead();
+ });
}
void onMessage(const std::string& data)
@@ -73,36 +73,36 @@
outputBuffer.prepare(outputBuffer.capacity() - outputBuffer.size()),
[this, weak(weak_from_this())](const boost::system::error_code& ec,
std::size_t bytesRead) {
- auto self = weak.lock();
- if (self == nullptr)
- {
- return;
- }
- BMCWEB_LOG_DEBUG("conn:{}, read done. Read {} bytes",
- logPtr(&conn), bytesRead);
- if (ec)
- {
- BMCWEB_LOG_ERROR(
- "conn:{}, Couldn't read from KVM socket port: {}",
- logPtr(&conn), ec);
- if (ec != boost::asio::error::operation_aborted)
+ auto self = weak.lock();
+ if (self == nullptr)
{
- conn.close("Error in connecting to KVM port");
+ return;
}
- return;
- }
+ BMCWEB_LOG_DEBUG("conn:{}, read done. Read {} bytes",
+ logPtr(&conn), bytesRead);
+ if (ec)
+ {
+ BMCWEB_LOG_ERROR(
+ "conn:{}, Couldn't read from KVM socket port: {}",
+ logPtr(&conn), ec);
+ if (ec != boost::asio::error::operation_aborted)
+ {
+ conn.close("Error in connecting to KVM port");
+ }
+ return;
+ }
- outputBuffer.commit(bytesRead);
- std::string_view payload(
- static_cast<const char*>(outputBuffer.data().data()),
- bytesRead);
- BMCWEB_LOG_DEBUG("conn:{}, Sending payload size {}", logPtr(&conn),
- payload.size());
- conn.sendBinary(payload);
- outputBuffer.consume(bytesRead);
+ outputBuffer.commit(bytesRead);
+ std::string_view payload(
+ static_cast<const char*>(outputBuffer.data().data()),
+ bytesRead);
+ BMCWEB_LOG_DEBUG("conn:{}, Sending payload size {}",
+ logPtr(&conn), payload.size());
+ conn.sendBinary(payload);
+ outputBuffer.consume(bytesRead);
- doRead();
- });
+ doRead();
+ });
}
void doWrite()
@@ -125,34 +125,34 @@
inputBuffer.data(),
[this, weak(weak_from_this())](const boost::system::error_code& ec,
std::size_t bytesWritten) {
- auto self = weak.lock();
- if (self == nullptr)
- {
- return;
- }
- BMCWEB_LOG_DEBUG("conn:{}, Wrote {}bytes", logPtr(&conn),
- bytesWritten);
- doingWrite = false;
- inputBuffer.consume(bytesWritten);
-
- if (ec == boost::asio::error::eof)
- {
- conn.close("KVM socket port closed");
- return;
- }
- if (ec)
- {
- BMCWEB_LOG_ERROR("conn:{}, Error in KVM socket write {}",
- logPtr(&conn), ec);
- if (ec != boost::asio::error::operation_aborted)
+ auto self = weak.lock();
+ if (self == nullptr)
{
- conn.close("Error in reading to host port");
+ return;
}
- return;
- }
+ BMCWEB_LOG_DEBUG("conn:{}, Wrote {}bytes", logPtr(&conn),
+ bytesWritten);
+ doingWrite = false;
+ inputBuffer.consume(bytesWritten);
- doWrite();
- });
+ if (ec == boost::asio::error::eof)
+ {
+ conn.close("KVM socket port closed");
+ return;
+ }
+ if (ec)
+ {
+ BMCWEB_LOG_ERROR("conn:{}, Error in KVM socket write {}",
+ logPtr(&conn), ec);
+ if (ec != boost::asio::error::operation_aborted)
+ {
+ conn.close("Error in reading to host port");
+ }
+ return;
+ }
+
+ doWrite();
+ });
}
crow::websocket::Connection& conn;
@@ -175,26 +175,26 @@
.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<KvmSession>(conn);
- })
+ sessions[&conn] = std::make_shared<KvmSession>(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/login_routes.hpp b/include/login_routes.hpp
index 988bf45..7664592 100644
--- a/include/login_routes.hpp
+++ b/include/login_routes.hpp
@@ -186,8 +186,8 @@
const auto& session = req.session;
if (session != nullptr)
{
- asyncResp->res.jsonValue["data"] = "User '" + session->username +
- "' logged out";
+ asyncResp->res.jsonValue["data"] =
+ "User '" + session->username + "' logged out";
asyncResp->res.jsonValue["message"] = "200 OK";
asyncResp->res.jsonValue["status"] = "ok";
diff --git a/include/multipart_parser.hpp b/include/multipart_parser.hpp
index 9d55f3a..3c60995 100644
--- a/include/multipart_parser.hpp
+++ b/include/multipart_parser.hpp
@@ -270,8 +270,8 @@
{
const char* start = &buffer[partDataMark];
size_t size = i - partDataMark;
- mime_fields.rbegin()->content += std::string_view(start,
- size);
+ mime_fields.rbegin()->content +=
+ std::string_view(start, size);
}
index++;
}
diff --git a/include/obmc_console.hpp b/include/obmc_console.hpp
index 842cbe6..81303e5 100644
--- a/include/obmc_console.hpp
+++ b/include/obmc_console.hpp
@@ -27,8 +27,7 @@
public:
ConsoleHandler(boost::asio::io_context& ioc,
crow::websocket::Connection& connIn) :
- hostSocket(ioc),
- conn(connIn)
+ hostSocket(ioc), conn(connIn)
{}
~ConsoleHandler() = default;
@@ -57,27 +56,28 @@
boost::asio::buffer(inputBuffer.data(), inputBuffer.size()),
[weak(weak_from_this())](const boost::beast::error_code& ec,
std::size_t bytesWritten) {
- std::shared_ptr<ConsoleHandler> self = weak.lock();
- if (self == nullptr)
- {
- return;
- }
+ std::shared_ptr<ConsoleHandler> self = weak.lock();
+ if (self == nullptr)
+ {
+ return;
+ }
- self->doingWrite = false;
- self->inputBuffer.erase(0, bytesWritten);
+ self->doingWrite = false;
+ self->inputBuffer.erase(0, bytesWritten);
- if (ec == boost::asio::error::eof)
- {
- self->conn.close("Error in reading to host port");
- return;
- }
- if (ec)
- {
- BMCWEB_LOG_ERROR("Error in host serial write {}", ec.message());
- return;
- }
- self->doWrite();
- });
+ if (ec == boost::asio::error::eof)
+ {
+ self->conn.close("Error in reading to host port");
+ return;
+ }
+ if (ec)
+ {
+ BMCWEB_LOG_ERROR("Error in host serial write {}",
+ ec.message());
+ return;
+ }
+ self->doWrite();
+ });
}
static void afterSendEx(const std::weak_ptr<ConsoleHandler>& weak)
@@ -97,23 +97,24 @@
boost::asio::buffer(outputBuffer),
[this, weakSelf(weak_from_this())](
const boost::system::error_code& ec, std::size_t bytesRead) {
- BMCWEB_LOG_DEBUG("read done. Read {} bytes", bytesRead);
- std::shared_ptr<ConsoleHandler> self = weakSelf.lock();
- if (self == nullptr)
- {
- return;
- }
- if (ec)
- {
- BMCWEB_LOG_ERROR("Couldn't read from host serial port: {}",
- ec.message());
- conn.close("Error connecting to host port");
- return;
- }
- std::string_view payload(outputBuffer.data(), bytesRead);
- self->conn.sendEx(crow::websocket::MessageType::Binary, payload,
- std::bind_front(afterSendEx, weak_from_this()));
- });
+ BMCWEB_LOG_DEBUG("read done. Read {} bytes", bytesRead);
+ std::shared_ptr<ConsoleHandler> self = weakSelf.lock();
+ if (self == nullptr)
+ {
+ return;
+ }
+ if (ec)
+ {
+ BMCWEB_LOG_ERROR("Couldn't read from host serial port: {}",
+ ec.message());
+ conn.close("Error connecting to host port");
+ return;
+ }
+ 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)
@@ -214,11 +215,10 @@
}
}
-inline void
- processConsoleObject(crow::websocket::Connection& conn,
- const std::string& consoleObjPath,
- const boost::system::error_code& ec,
- const ::dbus::utility::MapperGetObject& objInfo)
+inline void processConsoleObject(
+ crow::websocket::Connection& conn, const std::string& consoleObjPath,
+ const boost::system::error_code& ec,
+ const ::dbus::utility::MapperGetObject& objInfo)
{
// Look up the handler
auto iter = getConsoleHandlerMap().find(&conn);
@@ -252,8 +252,8 @@
crow::connections::systemBus->async_method_call(
[&conn](const boost::system::error_code& ec1,
const sdbusplus::message::unix_fd& unixfd) {
- connectConsoleSocket(conn, ec1, unixfd);
- },
+ connectConsoleSocket(conn, ec1, unixfd);
+ },
consoleService, consoleObjPath, "xyz.openbmc_project.Console.Access",
"Connect");
}
@@ -304,8 +304,8 @@
consolePath, interfaces,
[&conn, consolePath](const boost::system::error_code& ec,
const ::dbus::utility::MapperGetObject& objInfo) {
- processConsoleObject(conn, consolePath, ec, 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 eb54899..9a3a632 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -116,10 +116,9 @@
res.jsonValue["status"] = "error";
}
-inline void
- introspectObjects(const std::string& processName,
- const std::string& objectPath,
- const std::shared_ptr<bmcweb::AsyncResp>& transaction)
+inline void introspectObjects(
+ const std::string& processName, const std::string& objectPath,
+ const std::shared_ptr<bmcweb::AsyncResp>& transaction)
{
if (transaction->res.jsonValue.is_null())
{
@@ -133,49 +132,50 @@
objectPath{std::string(objectPath)}](
const boost::system::error_code& ec,
const std::string& introspectXml) {
- if (ec)
- {
- BMCWEB_LOG_ERROR(
- "Introspect call failed with error: {} on process: {} path: {}",
- ec.message(), processName, objectPath);
- return;
- }
- nlohmann::json::object_t object;
- object["path"] = objectPath;
-
- transaction->res.jsonValue["objects"].emplace_back(std::move(object));
-
- tinyxml2::XMLDocument doc;
-
- doc.Parse(introspectXml.c_str());
- tinyxml2::XMLNode* pRoot = doc.FirstChildElement("node");
- if (pRoot == nullptr)
- {
- BMCWEB_LOG_ERROR("XML document failed to parse {} {}", processName,
- objectPath);
- }
- else
- {
- tinyxml2::XMLElement* node = pRoot->FirstChildElement("node");
- while (node != nullptr)
+ if (ec)
{
- const char* childPath = node->Attribute("name");
- if (childPath != nullptr)
- {
- std::string newpath;
- if (objectPath != "/")
- {
- newpath += objectPath;
- }
- newpath += std::string("/") + childPath;
- // introspect the subobjects as well
- introspectObjects(processName, newpath, transaction);
- }
-
- node = node->NextSiblingElement("node");
+ BMCWEB_LOG_ERROR(
+ "Introspect call failed with error: {} on process: {} path: {}",
+ ec.message(), processName, objectPath);
+ return;
}
- }
- },
+ nlohmann::json::object_t object;
+ object["path"] = objectPath;
+
+ transaction->res.jsonValue["objects"].emplace_back(
+ std::move(object));
+
+ tinyxml2::XMLDocument doc;
+
+ doc.Parse(introspectXml.c_str());
+ tinyxml2::XMLNode* pRoot = doc.FirstChildElement("node");
+ if (pRoot == nullptr)
+ {
+ BMCWEB_LOG_ERROR("XML document failed to parse {} {}",
+ processName, objectPath);
+ }
+ else
+ {
+ tinyxml2::XMLElement* node = pRoot->FirstChildElement("node");
+ while (node != nullptr)
+ {
+ const char* childPath = node->Attribute("name");
+ if (childPath != nullptr)
+ {
+ std::string newpath;
+ if (objectPath != "/")
+ {
+ newpath += objectPath;
+ }
+ newpath += std::string("/") + childPath;
+ // introspect the subobjects as well
+ introspectObjects(processName, newpath, transaction);
+ }
+
+ node = node->NextSiblingElement("node");
+ }
+ }
+ },
processName, objectPath, "org.freedesktop.DBus.Introspectable",
"Introspect");
}
@@ -193,39 +193,40 @@
[asyncResp, objectPath, service,
interface](const boost::system::error_code& ec,
const dbus::utility::DBusPropertiesMap& propertiesList) {
- if (ec)
- {
- BMCWEB_LOG_ERROR(
- "GetAll on path {} iface {} service {} failed with code {}",
- objectPath, interface, service, ec);
- return;
- }
+ if (ec)
+ {
+ BMCWEB_LOG_ERROR(
+ "GetAll on path {} iface {} service {} failed with code {}",
+ objectPath, interface, service, ec);
+ return;
+ }
- nlohmann::json& dataJson = asyncResp->res.jsonValue["data"];
- nlohmann::json& objectJson = dataJson[objectPath];
- if (objectJson.is_null())
- {
- objectJson = nlohmann::json::object();
- }
+ nlohmann::json& dataJson = asyncResp->res.jsonValue["data"];
+ nlohmann::json& objectJson = dataJson[objectPath];
+ if (objectJson.is_null())
+ {
+ objectJson = nlohmann::json::object();
+ }
- for (const auto& [name, value] : propertiesList)
- {
- nlohmann::json& propertyJson = objectJson[name];
- std::visit(
- [&propertyJson](auto&& val) {
- if constexpr (std::is_same_v<std::decay_t<decltype(val)>,
- sdbusplus::message::unix_fd>)
- {
- propertyJson = val.fd;
- }
- else
- {
- propertyJson = val;
- }
- },
- value);
- }
- });
+ for (const auto& [name, value] : propertiesList)
+ {
+ nlohmann::json& propertyJson = objectJson[name];
+ std::visit(
+ [&propertyJson](auto&& val) {
+ if constexpr (std::is_same_v<
+ std::decay_t<decltype(val)>,
+ sdbusplus::message::unix_fd>)
+ {
+ propertyJson = val.fd;
+ }
+ else
+ {
+ propertyJson = val;
+ }
+ },
+ value);
+ }
+ });
}
// Find any results that weren't picked up by ObjectManagers, to be
@@ -267,8 +268,7 @@
InProgressEnumerateData(
const std::string& objectPathIn,
const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn) :
- objectPath(objectPathIn),
- asyncResp(asyncRespIn)
+ objectPath(objectPathIn), asyncResp(asyncRespIn)
{}
~InProgressEnumerateData()
@@ -307,61 +307,62 @@
[transaction, objectName,
connectionName](const boost::system::error_code& ec,
const dbus::utility::ManagedObjectType& objects) {
- if (ec)
- {
- BMCWEB_LOG_ERROR(
- "GetManagedObjects on path {} on connection {} failed with code {}",
- objectName, connectionName, ec);
- return;
- }
-
- nlohmann::json& dataJson =
- transaction->asyncResp->res.jsonValue["data"];
-
- for (const auto& objectPath : objects)
- {
- if (objectPath.first.str.starts_with(objectName))
+ if (ec)
{
- BMCWEB_LOG_DEBUG("Reading object {}", objectPath.first.str);
- nlohmann::json& objectJson = dataJson[objectPath.first.str];
- if (objectJson.is_null())
+ BMCWEB_LOG_ERROR(
+ "GetManagedObjects on path {} on connection {} failed with code {}",
+ objectName, connectionName, ec);
+ return;
+ }
+
+ nlohmann::json& dataJson =
+ transaction->asyncResp->res.jsonValue["data"];
+
+ for (const auto& objectPath : objects)
+ {
+ if (objectPath.first.str.starts_with(objectName))
{
- objectJson = nlohmann::json::object();
+ BMCWEB_LOG_DEBUG("Reading object {}", objectPath.first.str);
+ nlohmann::json& objectJson = dataJson[objectPath.first.str];
+ if (objectJson.is_null())
+ {
+ objectJson = nlohmann::json::object();
+ }
+ for (const auto& interface : objectPath.second)
+ {
+ for (const auto& property : interface.second)
+ {
+ nlohmann::json& propertyJson =
+ objectJson[property.first];
+ std::visit(
+ [&propertyJson](auto&& val) {
+ if constexpr (
+ std::is_same_v<
+ std::decay_t<decltype(val)>,
+ sdbusplus::message::unix_fd>)
+ {
+ propertyJson = val.fd;
+ }
+ else
+ {
+ propertyJson = val;
+ }
+ },
+ property.second);
+ }
+ }
}
for (const auto& interface : objectPath.second)
{
- for (const auto& property : interface.second)
+ if (interface.first == "org.freedesktop.DBus.ObjectManager")
{
- nlohmann::json& propertyJson =
- objectJson[property.first];
- std::visit(
- [&propertyJson](auto&& val) {
- if constexpr (std::is_same_v<
- std::decay_t<decltype(val)>,
- sdbusplus::message::unix_fd>)
- {
- propertyJson = val.fd;
- }
- else
- {
- propertyJson = val;
- }
- },
- property.second);
+ getManagedObjectsForEnumerate(
+ objectPath.first.str, objectPath.first.str,
+ connectionName, transaction);
}
}
}
- for (const auto& interface : objectPath.second)
- {
- if (interface.first == "org.freedesktop.DBus.ObjectManager")
- {
- getManagedObjectsForEnumerate(objectPath.first.str,
- objectPath.first.str,
- connectionName, transaction);
- }
- }
- }
- });
+ });
}
inline void findObjectManagerPathForEnumerate(
@@ -374,27 +375,28 @@
[transaction, objectName, connectionName](
const boost::system::error_code& ec,
const dbus::utility::MapperGetAncestorsResponse& objects) {
- if (ec)
- {
- BMCWEB_LOG_ERROR("GetAncestors on path {} failed with code {}",
- objectName, ec);
- return;
- }
-
- for (const auto& pathGroup : objects)
- {
- for (const auto& connectionGroup : pathGroup.second)
+ if (ec)
{
- if (connectionGroup.first == connectionName)
+ BMCWEB_LOG_ERROR("GetAncestors on path {} failed with code {}",
+ objectName, ec);
+ return;
+ }
+
+ for (const auto& pathGroup : objects)
+ {
+ for (const auto& connectionGroup : pathGroup.second)
{
- // Found the object manager path for this resource.
- getManagedObjectsForEnumerate(objectName, pathGroup.first,
- connectionName, transaction);
- return;
+ if (connectionGroup.first == connectionName)
+ {
+ // Found the object manager path for this resource.
+ getManagedObjectsForEnumerate(
+ objectName, pathGroup.first, connectionName,
+ transaction);
+ return;
+ }
}
}
- }
- },
+ },
"xyz.openbmc_project.ObjectMapper",
"/xyz/openbmc_project/object_mapper",
"xyz.openbmc_project.ObjectMapper", "GetAncestors", objectName,
@@ -411,75 +413,74 @@
transaction->objectPath, {},
[transaction](const boost::system::error_code& ec,
const dbus::utility::MapperGetObject& objects) {
- if (ec)
- {
- BMCWEB_LOG_ERROR("GetObject for path {} failed with code {}",
- transaction->objectPath, ec);
- return;
- }
-
- BMCWEB_LOG_DEBUG("GetObject for {} has {} entries",
- transaction->objectPath, objects.size());
- if (!objects.empty())
- {
- transaction->subtree->emplace_back(transaction->objectPath,
- objects);
- }
-
- // Map indicating connection name, and the path where the object
- // manager exists
- boost::container::flat_map<
- std::string, std::string, std::less<>,
- std::vector<std::pair<std::string, std::string>>>
- connections;
-
- for (const auto& object : *(transaction->subtree))
- {
- for (const auto& connection : object.second)
+ if (ec)
{
- for (const auto& interface : connection.second)
+ BMCWEB_LOG_ERROR("GetObject for path {} failed with code {}",
+ transaction->objectPath, ec);
+ return;
+ }
+
+ BMCWEB_LOG_DEBUG("GetObject for {} has {} entries",
+ transaction->objectPath, objects.size());
+ if (!objects.empty())
+ {
+ transaction->subtree->emplace_back(transaction->objectPath,
+ objects);
+ }
+
+ // Map indicating connection name, and the path where the object
+ // manager exists
+ boost::container::flat_map<
+ std::string, std::string, std::less<>,
+ std::vector<std::pair<std::string, std::string>>>
+ connections;
+
+ for (const auto& object : *(transaction->subtree))
+ {
+ for (const auto& connection : object.second)
{
- BMCWEB_LOG_DEBUG("{} has interface {}", connection.first,
- interface);
- if (interface == "org.freedesktop.DBus.ObjectManager")
+ for (const auto& interface : connection.second)
{
- BMCWEB_LOG_DEBUG("found object manager path {}",
- object.first);
- connections[connection.first] = object.first;
+ BMCWEB_LOG_DEBUG("{} has interface {}",
+ connection.first, interface);
+ if (interface == "org.freedesktop.DBus.ObjectManager")
+ {
+ BMCWEB_LOG_DEBUG("found object manager path {}",
+ object.first);
+ connections[connection.first] = object.first;
+ }
}
}
}
- }
- BMCWEB_LOG_DEBUG("Got {} connections", connections.size());
+ BMCWEB_LOG_DEBUG("Got {} connections", connections.size());
- for (const auto& connection : connections)
- {
- // If we already know where the object manager is, we don't
- // need to search for it, we can call directly in to
- // getManagedObjects
- if (!connection.second.empty())
+ for (const auto& connection : connections)
{
- getManagedObjectsForEnumerate(transaction->objectPath,
- connection.second,
- connection.first, transaction);
+ // If we already know where the object manager is, we don't
+ // need to search for it, we can call directly in to
+ // getManagedObjects
+ if (!connection.second.empty())
+ {
+ getManagedObjectsForEnumerate(
+ transaction->objectPath, connection.second,
+ connection.first, transaction);
+ }
+ else
+ {
+ // otherwise we need to find the object manager path
+ // before we can continue
+ findObjectManagerPathForEnumerate(
+ transaction->objectPath, connection.first, transaction);
+ }
}
- else
- {
- // otherwise we need to find the object manager path
- // before we can continue
- findObjectManagerPathForEnumerate(
- transaction->objectPath, connection.first, transaction);
- }
- }
- });
+ });
}
// Structure for storing data on an in progress action
struct InProgressActionData
{
explicit InProgressActionData(
- const std::shared_ptr<bmcweb::AsyncResp>& res) :
- asyncResp(res)
+ const std::shared_ptr<bmcweb::AsyncResp>& res) : asyncResp(res)
{}
~InProgressActionData()
{
@@ -1401,149 +1402,159 @@
[transaction, connectionName{std::string(connectionName)}](
const boost::system::error_code& ec,
const std::string& introspectXml) {
- BMCWEB_LOG_DEBUG("got xml:\n {}", introspectXml);
- if (ec)
- {
- BMCWEB_LOG_ERROR(
- "Introspect call failed with error: {} on process: {}",
- ec.message(), connectionName);
- return;
- }
- tinyxml2::XMLDocument doc;
-
- doc.Parse(introspectXml.data(), introspectXml.size());
- tinyxml2::XMLNode* pRoot = doc.FirstChildElement("node");
- if (pRoot == nullptr)
- {
- BMCWEB_LOG_ERROR("XML document failed to parse {}", connectionName);
- return;
- }
- tinyxml2::XMLElement* interfaceNode =
- pRoot->FirstChildElement("interface");
- while (interfaceNode != nullptr)
- {
- const char* thisInterfaceName = interfaceNode->Attribute("name");
- if (thisInterfaceName != nullptr)
+ BMCWEB_LOG_DEBUG("got xml:\n {}", introspectXml);
+ if (ec)
{
- if (!transaction->interfaceName.empty() &&
- (transaction->interfaceName != thisInterfaceName))
- {
- interfaceNode =
- interfaceNode->NextSiblingElement("interface");
- continue;
- }
-
- tinyxml2::XMLElement* methodNode =
- interfaceNode->FirstChildElement("method");
- while (methodNode != nullptr)
- {
- const char* thisMethodName = methodNode->Attribute("name");
- BMCWEB_LOG_DEBUG("Found method: {}", thisMethodName);
- if (thisMethodName != nullptr &&
- thisMethodName == transaction->methodName)
- {
- BMCWEB_LOG_DEBUG(
- "Found method named {} on interface {}",
- thisMethodName, thisInterfaceName);
- sdbusplus::message_t m =
- crow::connections::systemBus->new_method_call(
- connectionName.c_str(),
- transaction->path.c_str(), thisInterfaceName,
- transaction->methodName.c_str());
-
- tinyxml2::XMLElement* argumentNode =
- methodNode->FirstChildElement("arg");
-
- std::string returnType;
-
- // Find the output type
- while (argumentNode != nullptr)
- {
- const char* argDirection =
- argumentNode->Attribute("direction");
- const char* argType =
- argumentNode->Attribute("type");
- if (argDirection != nullptr && argType != nullptr &&
- std::string(argDirection) == "out")
- {
- returnType = argType;
- break;
- }
- argumentNode =
- argumentNode->NextSiblingElement("arg");
- }
-
- auto argIt = transaction->arguments.begin();
-
- argumentNode = methodNode->FirstChildElement("arg");
-
- while (argumentNode != nullptr)
- {
- const char* argDirection =
- argumentNode->Attribute("direction");
- const char* argType =
- argumentNode->Attribute("type");
- if (argDirection != nullptr && argType != nullptr &&
- std::string(argDirection) == "in")
- {
- if (argIt == transaction->arguments.end())
- {
- transaction->setErrorStatus(
- "Invalid method args");
- return;
- }
- if (convertJsonToDbus(m.get(),
- std::string(argType),
- *argIt) < 0)
- {
- transaction->setErrorStatus(
- "Invalid method arg type");
- return;
- }
-
- argIt++;
- }
- argumentNode =
- argumentNode->NextSiblingElement("arg");
- }
-
- crow::connections::systemBus->async_send(
- m, [transaction, returnType](
- const boost::system::error_code& ec2,
- sdbusplus::message_t& m2) {
- if (ec2)
- {
- transaction->methodFailed = true;
- const sd_bus_error* e = m2.get_error();
-
- if (e != nullptr)
- {
- setErrorResponse(
- transaction->asyncResp->res,
- boost::beast::http::status::bad_request,
- e->name, e->message);
- }
- else
- {
- setErrorResponse(
- transaction->asyncResp->res,
- boost::beast::http::status::bad_request,
- "Method call failed", methodFailedMsg);
- }
- return;
- }
- transaction->methodPassed = true;
-
- handleMethodResponse(transaction, m2, returnType);
- });
- break;
- }
- methodNode = methodNode->NextSiblingElement("method");
- }
+ BMCWEB_LOG_ERROR(
+ "Introspect call failed with error: {} on process: {}",
+ ec.message(), connectionName);
+ return;
}
- interfaceNode = interfaceNode->NextSiblingElement("interface");
- }
- },
+ tinyxml2::XMLDocument doc;
+
+ doc.Parse(introspectXml.data(), introspectXml.size());
+ tinyxml2::XMLNode* pRoot = doc.FirstChildElement("node");
+ if (pRoot == nullptr)
+ {
+ BMCWEB_LOG_ERROR("XML document failed to parse {}",
+ connectionName);
+ return;
+ }
+ tinyxml2::XMLElement* interfaceNode =
+ pRoot->FirstChildElement("interface");
+ while (interfaceNode != nullptr)
+ {
+ const char* thisInterfaceName =
+ interfaceNode->Attribute("name");
+ if (thisInterfaceName != nullptr)
+ {
+ if (!transaction->interfaceName.empty() &&
+ (transaction->interfaceName != thisInterfaceName))
+ {
+ interfaceNode =
+ interfaceNode->NextSiblingElement("interface");
+ continue;
+ }
+
+ tinyxml2::XMLElement* methodNode =
+ interfaceNode->FirstChildElement("method");
+ while (methodNode != nullptr)
+ {
+ const char* thisMethodName =
+ methodNode->Attribute("name");
+ BMCWEB_LOG_DEBUG("Found method: {}", thisMethodName);
+ if (thisMethodName != nullptr &&
+ thisMethodName == transaction->methodName)
+ {
+ BMCWEB_LOG_DEBUG(
+ "Found method named {} on interface {}",
+ thisMethodName, thisInterfaceName);
+ sdbusplus::message_t m =
+ crow::connections::systemBus->new_method_call(
+ connectionName.c_str(),
+ transaction->path.c_str(),
+ thisInterfaceName,
+ transaction->methodName.c_str());
+
+ tinyxml2::XMLElement* argumentNode =
+ methodNode->FirstChildElement("arg");
+
+ std::string returnType;
+
+ // Find the output type
+ while (argumentNode != nullptr)
+ {
+ const char* argDirection =
+ argumentNode->Attribute("direction");
+ const char* argType =
+ argumentNode->Attribute("type");
+ if (argDirection != nullptr &&
+ argType != nullptr &&
+ std::string(argDirection) == "out")
+ {
+ returnType = argType;
+ break;
+ }
+ argumentNode =
+ argumentNode->NextSiblingElement("arg");
+ }
+
+ auto argIt = transaction->arguments.begin();
+
+ argumentNode = methodNode->FirstChildElement("arg");
+
+ while (argumentNode != nullptr)
+ {
+ const char* argDirection =
+ argumentNode->Attribute("direction");
+ const char* argType =
+ argumentNode->Attribute("type");
+ if (argDirection != nullptr &&
+ argType != nullptr &&
+ std::string(argDirection) == "in")
+ {
+ if (argIt == transaction->arguments.end())
+ {
+ transaction->setErrorStatus(
+ "Invalid method args");
+ return;
+ }
+ if (convertJsonToDbus(m.get(),
+ std::string(argType),
+ *argIt) < 0)
+ {
+ transaction->setErrorStatus(
+ "Invalid method arg type");
+ return;
+ }
+
+ argIt++;
+ }
+ argumentNode =
+ argumentNode->NextSiblingElement("arg");
+ }
+
+ crow::connections::systemBus->async_send(
+ m, [transaction, returnType](
+ const boost::system::error_code& ec2,
+ sdbusplus::message_t& m2) {
+ if (ec2)
+ {
+ transaction->methodFailed = true;
+ const sd_bus_error* e = m2.get_error();
+
+ if (e != nullptr)
+ {
+ setErrorResponse(
+ transaction->asyncResp->res,
+ boost::beast::http::status::
+ bad_request,
+ e->name, e->message);
+ }
+ else
+ {
+ setErrorResponse(
+ transaction->asyncResp->res,
+ boost::beast::http::status::
+ bad_request,
+ "Method call failed",
+ methodFailedMsg);
+ }
+ return;
+ }
+ transaction->methodPassed = true;
+
+ handleMethodResponse(transaction, m2,
+ returnType);
+ });
+ break;
+ }
+ methodNode = methodNode->NextSiblingElement("method");
+ }
+ }
+ interfaceNode = interfaceNode->NextSiblingElement("interface");
+ }
+ },
connectionName, transaction->path,
"org.freedesktop.DBus.Introspectable", "Introspect");
}
@@ -1599,24 +1610,24 @@
const boost::system::error_code& ec,
const std::vector<std::pair<std::string, std::vector<std::string>>>&
interfaceNames) {
- if (ec || interfaceNames.empty())
- {
- BMCWEB_LOG_ERROR("Can't find object");
- setErrorResponse(transaction->asyncResp->res,
- boost::beast::http::status::not_found,
- notFoundDesc, notFoundMsg);
- return;
- }
+ if (ec || interfaceNames.empty())
+ {
+ BMCWEB_LOG_ERROR("Can't find object");
+ setErrorResponse(transaction->asyncResp->res,
+ boost::beast::http::status::not_found,
+ notFoundDesc, notFoundMsg);
+ return;
+ }
- BMCWEB_LOG_DEBUG("GetObject returned {} object(s)",
- interfaceNames.size());
+ BMCWEB_LOG_DEBUG("GetObject returned {} object(s)",
+ interfaceNames.size());
- for (const std::pair<std::string, std::vector<std::string>>& object :
- interfaceNames)
- {
- findActionOnInterface(transaction, object.first);
- }
- });
+ for (const std::pair<std::string, std::vector<std::string>>&
+ object : interfaceNames)
+ {
+ findActionOnInterface(transaction, object.first);
+ }
+ });
}
inline void handleDelete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
@@ -1630,26 +1641,27 @@
const boost::system::error_code& ec,
const std::vector<std::pair<std::string, std::vector<std::string>>>&
interfaceNames) {
- if (ec || interfaceNames.empty())
- {
- BMCWEB_LOG_ERROR("Can't find object");
- setErrorResponse(asyncResp->res,
- boost::beast::http::status::method_not_allowed,
- methodNotAllowedDesc, methodNotAllowedMsg);
- return;
- }
+ if (ec || interfaceNames.empty())
+ {
+ BMCWEB_LOG_ERROR("Can't find object");
+ setErrorResponse(asyncResp->res,
+ boost::beast::http::status::method_not_allowed,
+ methodNotAllowedDesc, methodNotAllowedMsg);
+ return;
+ }
- auto transaction = std::make_shared<InProgressActionData>(asyncResp);
- transaction->path = objectPath;
- transaction->methodName = "Delete";
- transaction->interfaceName = "xyz.openbmc_project.Object.Delete";
+ auto transaction =
+ std::make_shared<InProgressActionData>(asyncResp);
+ transaction->path = objectPath;
+ transaction->methodName = "Delete";
+ transaction->interfaceName = "xyz.openbmc_project.Object.Delete";
- for (const std::pair<std::string, std::vector<std::string>>& object :
- interfaceNames)
- {
- findActionOnInterface(transaction, object.first);
- }
- });
+ for (const std::pair<std::string, std::vector<std::string>>&
+ object : interfaceNames)
+ {
+ findActionOnInterface(transaction, object.first);
+ }
+ });
}
inline void handleList(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
@@ -1660,19 +1672,19 @@
[asyncResp](
const boost::system::error_code& ec,
const dbus::utility::MapperGetSubTreePathsResponse& objectPaths) {
- if (ec)
- {
- setErrorResponse(asyncResp->res,
- boost::beast::http::status::not_found,
- notFoundDesc, notFoundMsg);
- }
- else
- {
- asyncResp->res.jsonValue["status"] = "ok";
- asyncResp->res.jsonValue["message"] = "200 OK";
- asyncResp->res.jsonValue["data"] = objectPaths;
- }
- });
+ if (ec)
+ {
+ setErrorResponse(asyncResp->res,
+ boost::beast::http::status::not_found,
+ notFoundDesc, notFoundMsg);
+ }
+ else
+ {
+ asyncResp->res.jsonValue["status"] = "ok";
+ asyncResp->res.jsonValue["message"] = "200 OK";
+ asyncResp->res.jsonValue["data"] = objectPaths;
+ }
+ });
}
inline void handleEnumerate(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
@@ -1689,27 +1701,27 @@
[objectPath, asyncResp](
const boost::system::error_code& ec,
const dbus::utility::MapperGetSubTreeResponse& objectNames) {
- auto transaction = std::make_shared<InProgressEnumerateData>(objectPath,
- asyncResp);
+ auto transaction = std::make_shared<InProgressEnumerateData>(
+ objectPath, asyncResp);
- transaction->subtree =
- std::make_shared<dbus::utility::MapperGetSubTreeResponse>(
- objectNames);
+ transaction->subtree =
+ std::make_shared<dbus::utility::MapperGetSubTreeResponse>(
+ objectNames);
- if (ec)
- {
- BMCWEB_LOG_ERROR("GetSubTree failed on {}",
- transaction->objectPath);
- setErrorResponse(transaction->asyncResp->res,
- boost::beast::http::status::not_found,
- notFoundDesc, notFoundMsg);
- return;
- }
+ if (ec)
+ {
+ BMCWEB_LOG_ERROR("GetSubTree failed on {}",
+ transaction->objectPath);
+ setErrorResponse(transaction->asyncResp->res,
+ boost::beast::http::status::not_found,
+ notFoundDesc, notFoundMsg);
+ return;
+ }
- // Add the data for the path passed in to the results
- // as if GetSubTree returned it, and continue on enumerating
- getObjectAndEnumerate(transaction);
- });
+ // 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<bmcweb::AsyncResp>& asyncResp,
@@ -1727,99 +1739,106 @@
[asyncResp, path,
propertyName](const boost::system::error_code& ec,
const dbus::utility::MapperGetObject& objectNames) {
- if (ec || objectNames.empty())
- {
- setErrorResponse(asyncResp->res,
- boost::beast::http::status::not_found,
- notFoundDesc, notFoundMsg);
- return;
- }
- std::shared_ptr<nlohmann::json> response =
- std::make_shared<nlohmann::json>(nlohmann::json::object());
- // The mapper should never give us an empty interface names
- // list, but check anyway
- for (const std::pair<std::string, std::vector<std::string>>&
- connection : objectNames)
- {
- const std::vector<std::string>& interfaceNames = connection.second;
-
- if (interfaceNames.empty())
+ if (ec || objectNames.empty())
{
setErrorResponse(asyncResp->res,
boost::beast::http::status::not_found,
notFoundDesc, notFoundMsg);
return;
}
-
- for (const std::string& interface : interfaceNames)
+ std::shared_ptr<nlohmann::json> response =
+ std::make_shared<nlohmann::json>(nlohmann::json::object());
+ // The mapper should never give us an empty interface names
+ // list, but check anyway
+ for (const std::pair<std::string, std::vector<std::string>>&
+ connection : objectNames)
{
- sdbusplus::message_t m =
- crow::connections::systemBus->new_method_call(
- connection.first.c_str(), path->c_str(),
- "org.freedesktop.DBus.Properties", "GetAll");
- m.append(interface);
- crow::connections::systemBus->async_send(
- m, [asyncResp, response,
- propertyName](const boost::system::error_code& ec2,
- sdbusplus::message_t& msg) {
- 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("convertDBusToJSON failed");
- }
- else
- {
- nlohmann::json::object_t* obj =
- properties.get_ptr<nlohmann::json::object_t*>();
- if (obj == nullptr)
- {
- return;
- }
- for (auto& prop : *obj)
- {
- // if property name is empty, or
- // matches our search query, add it
- // to the response json
+ const std::vector<std::string>& interfaceNames =
+ connection.second;
- if (propertyName->empty())
+ if (interfaceNames.empty())
+ {
+ setErrorResponse(asyncResp->res,
+ boost::beast::http::status::not_found,
+ notFoundDesc, notFoundMsg);
+ return;
+ }
+
+ for (const std::string& interface : interfaceNames)
+ {
+ sdbusplus::message_t m =
+ crow::connections::systemBus->new_method_call(
+ connection.first.c_str(), path->c_str(),
+ "org.freedesktop.DBus.Properties", "GetAll");
+ m.append(interface);
+ crow::connections::systemBus->async_send(
+ m, [asyncResp, response,
+ propertyName](const boost::system::error_code& ec2,
+ sdbusplus::message_t& msg) {
+ if (ec2)
+ {
+ BMCWEB_LOG_ERROR("Bad dbus request error: {}",
+ ec2);
+ }
+ else
+ {
+ nlohmann::json properties;
+ int r =
+ convertDBusToJSON("a{sv}", msg, properties);
+ if (r < 0)
{
- (*response)[prop.first] =
- std::move(prop.second);
+ BMCWEB_LOG_ERROR(
+ "convertDBusToJSON failed");
}
- else if (prop.first == *propertyName)
+ else
{
- *response = std::move(prop.second);
+ nlohmann::json::object_t* obj =
+ properties.get_ptr<
+ nlohmann::json::object_t*>();
+ if (obj == nullptr)
+ {
+ return;
+ }
+ for (auto& prop : *obj)
+ {
+ // if property name is empty, or
+ // matches our search query, add it
+ // to the response json
+
+ if (propertyName->empty())
+ {
+ (*response)[prop.first] =
+ std::move(prop.second);
+ }
+ else if (prop.first == *propertyName)
+ {
+ *response = std::move(prop.second);
+ }
+ }
}
}
- }
- }
- if (response.use_count() == 1)
- {
- 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;
- }
- }
- });
+ if (response.use_count() == 1)
+ {
+ 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;
+ }
+ }
+ });
+ }
}
- }
- });
+ });
}
struct AsyncPutRequest
@@ -1903,147 +1922,174 @@
transaction->objectPath, {},
[transaction](const boost::system::error_code& ec2,
const dbus::utility::MapperGetObject& objectNames) {
- if (!ec2 && objectNames.empty())
- {
- setErrorResponse(transaction->asyncResp->res,
- boost::beast::http::status::not_found,
- propNotFoundDesc, notFoundMsg);
- return;
- }
+ if (!ec2 && objectNames.empty())
+ {
+ setErrorResponse(transaction->asyncResp->res,
+ boost::beast::http::status::not_found,
+ propNotFoundDesc, notFoundMsg);
+ return;
+ }
- for (const std::pair<std::string, std::vector<std::string>>&
- connection : objectNames)
- {
- const std::string& connectionName = connection.first;
+ for (const std::pair<std::string, std::vector<std::string>>&
+ connection : objectNames)
+ {
+ const std::string& connectionName = connection.first;
- crow::connections::systemBus->async_method_call(
- [connectionName{std::string(connectionName)},
- transaction](const boost::system::error_code& ec3,
- const std::string& introspectXml) {
- if (ec3)
- {
- BMCWEB_LOG_ERROR(
- "Introspect call failed with error: {} on process: {}",
- ec3.message(), connectionName);
- transaction->setErrorStatus("Unexpected Error");
- return;
- }
- tinyxml2::XMLDocument doc;
-
- doc.Parse(introspectXml.c_str());
- tinyxml2::XMLNode* pRoot = doc.FirstChildElement("node");
- if (pRoot == nullptr)
- {
- BMCWEB_LOG_ERROR("XML document failed to parse: {}",
- introspectXml);
- transaction->setErrorStatus("Unexpected Error");
- return;
- }
- tinyxml2::XMLElement* ifaceNode =
- pRoot->FirstChildElement("interface");
- while (ifaceNode != nullptr)
- {
- const char* interfaceName = ifaceNode->Attribute("name");
- BMCWEB_LOG_DEBUG("found interface {}", interfaceName);
- tinyxml2::XMLElement* propNode =
- ifaceNode->FirstChildElement("property");
- while (propNode != nullptr)
- {
- const char* propertyName = propNode->Attribute("name");
- if (propertyName == nullptr)
+ crow::connections::systemBus->async_method_call(
+ [connectionName{std::string(connectionName)},
+ transaction](const boost::system::error_code& ec3,
+ const std::string& introspectXml) {
+ if (ec3)
{
- BMCWEB_LOG_DEBUG("Couldn't find name property");
- continue;
+ BMCWEB_LOG_ERROR(
+ "Introspect call failed with error: {} on process: {}",
+ ec3.message(), connectionName);
+ transaction->setErrorStatus("Unexpected Error");
+ return;
}
- BMCWEB_LOG_DEBUG("Found property {}", propertyName);
- if (propertyName == transaction->propertyName)
+ tinyxml2::XMLDocument doc;
+
+ doc.Parse(introspectXml.c_str());
+ tinyxml2::XMLNode* pRoot =
+ doc.FirstChildElement("node");
+ if (pRoot == nullptr)
{
- const char* argType = propNode->Attribute("type");
- if (argType != nullptr)
+ BMCWEB_LOG_ERROR("XML document failed to parse: {}",
+ introspectXml);
+ transaction->setErrorStatus("Unexpected Error");
+ return;
+ }
+ tinyxml2::XMLElement* ifaceNode =
+ pRoot->FirstChildElement("interface");
+ while (ifaceNode != nullptr)
+ {
+ const char* interfaceName =
+ ifaceNode->Attribute("name");
+ BMCWEB_LOG_DEBUG("found interface {}",
+ interfaceName);
+ tinyxml2::XMLElement* propNode =
+ ifaceNode->FirstChildElement("property");
+ while (propNode != nullptr)
{
- sdbusplus::message_t m =
- crow::connections::systemBus
- ->new_method_call(
- connectionName.c_str(),
- transaction->objectPath.c_str(),
- "org.freedesktop.DBus."
- "Properties",
- "Set");
- m.append(interfaceName,
- transaction->propertyName);
- int r = sd_bus_message_open_container(
- m.get(), SD_BUS_TYPE_VARIANT, argType);
- if (r < 0)
+ const char* propertyName =
+ propNode->Attribute("name");
+ if (propertyName == nullptr)
{
- transaction->setErrorStatus(
- "Unexpected Error");
- return;
+ BMCWEB_LOG_DEBUG(
+ "Couldn't find name property");
+ continue;
}
- r = convertJsonToDbus(
- m.get(), argType,
- transaction->propertyValue);
- if (r < 0)
+ BMCWEB_LOG_DEBUG("Found property {}",
+ propertyName);
+ if (propertyName == transaction->propertyName)
{
- if (r == -ERANGE)
+ const char* argType =
+ propNode->Attribute("type");
+ if (argType != nullptr)
{
- transaction->setErrorStatus(
- "Provided property value "
- "is out of range for the "
- "property type");
+ sdbusplus::message_t m =
+ crow::connections::systemBus
+ ->new_method_call(
+ connectionName.c_str(),
+ transaction->objectPath
+ .c_str(),
+ "org.freedesktop.DBus."
+ "Properties",
+ "Set");
+ m.append(interfaceName,
+ transaction->propertyName);
+ int r = sd_bus_message_open_container(
+ m.get(), SD_BUS_TYPE_VARIANT,
+ argType);
+ if (r < 0)
+ {
+ transaction->setErrorStatus(
+ "Unexpected Error");
+ return;
+ }
+ r = convertJsonToDbus(
+ m.get(), argType,
+ transaction->propertyValue);
+ if (r < 0)
+ {
+ if (r == -ERANGE)
+ {
+ transaction->setErrorStatus(
+ "Provided property value "
+ "is out of range for the "
+ "property type");
+ }
+ else
+ {
+ transaction->setErrorStatus(
+ "Invalid arg type");
+ }
+ return;
+ }
+ r = sd_bus_message_close_container(
+ m.get());
+ if (r < 0)
+ {
+ transaction->setErrorStatus(
+ "Unexpected Error");
+ return;
+ }
+ crow::connections::systemBus
+ ->async_send(
+ m,
+ [transaction](
+ const boost::system::
+ error_code& ec,
+ sdbusplus::message_t& m2) {
+ BMCWEB_LOG_DEBUG("sent");
+ if (ec)
+ {
+ const sd_bus_error* e =
+ m2.get_error();
+ setErrorResponse(
+ transaction
+ ->asyncResp
+ ->res,
+ boost::beast::http::
+ status::
+ forbidden,
+ (e) != nullptr
+ ? e->name
+ : ec.category()
+ .name(),
+ (e) != nullptr
+ ? e->message
+ : ec.message());
+ }
+ else
+ {
+ transaction->asyncResp
+ ->res.jsonValue
+ ["status"] =
+ "ok";
+ transaction->asyncResp
+ ->res.jsonValue
+ ["message"] =
+ "200 OK";
+ transaction->asyncResp
+ ->res
+ .jsonValue["data"] =
+ nullptr;
+ }
+ });
}
- else
- {
- transaction->setErrorStatus(
- "Invalid arg type");
- }
- return;
}
- r = sd_bus_message_close_container(m.get());
- if (r < 0)
- {
- transaction->setErrorStatus(
- "Unexpected Error");
- return;
- }
- crow::connections::systemBus->async_send(
- m, [transaction](
- const boost::system::error_code& ec,
- sdbusplus::message_t& m2) {
- BMCWEB_LOG_DEBUG("sent");
- if (ec)
- {
- const sd_bus_error* e = m2.get_error();
- setErrorResponse(
- transaction->asyncResp->res,
- boost::beast::http::status::
- forbidden,
- (e) != nullptr
- ? e->name
- : ec.category().name(),
- (e) != nullptr ? e->message
- : ec.message());
- }
- else
- {
- transaction->asyncResp->res
- .jsonValue["status"] = "ok";
- transaction->asyncResp->res
- .jsonValue["message"] = "200 OK";
- transaction->asyncResp->res
- .jsonValue["data"] = nullptr;
- }
- });
+ propNode =
+ propNode->NextSiblingElement("property");
}
+ ifaceNode =
+ ifaceNode->NextSiblingElement("interface");
}
- propNode = propNode->NextSiblingElement("property");
- }
- ifaceNode = ifaceNode->NextSiblingElement("interface");
- }
- },
- connectionName, transaction->objectPath,
- "org.freedesktop.DBus.Introspectable", "Introspect");
- }
- });
+ },
+ connectionName, transaction->objectPath,
+ "org.freedesktop.DBus.Introspectable", "Introspect");
+ }
+ });
}
inline void handleDBusUrl(const crow::Request& req,
@@ -2121,11 +2167,10 @@
methodNotAllowedDesc, methodNotAllowedMsg);
}
-inline void
- handleBusSystemPost(const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& processName,
- const std::string& requestedPath)
+inline void handleBusSystemPost(
+ const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
+ const std::string& processName, const std::string& requestedPath)
{
std::vector<std::string> strs;
@@ -2181,51 +2226,51 @@
[asyncResp, processName,
objectPath](const boost::system::error_code& ec,
const std::string& introspectXml) {
- if (ec)
- {
- BMCWEB_LOG_ERROR(
- "Introspect call failed with error: {} on process: {} path: {}",
- ec.message(), processName, objectPath);
- return;
- }
- tinyxml2::XMLDocument doc;
-
- doc.Parse(introspectXml.c_str());
- tinyxml2::XMLNode* pRoot = doc.FirstChildElement("node");
- if (pRoot == nullptr)
- {
- BMCWEB_LOG_ERROR("XML document failed to parse {} {}",
- processName, objectPath);
- asyncResp->res.jsonValue["status"] = "XML parse error";
- asyncResp->res.result(
- boost::beast::http::status::internal_server_error);
- return;
- }
-
- BMCWEB_LOG_DEBUG("{}", introspectXml);
- asyncResp->res.jsonValue["status"] = "ok";
- asyncResp->res.jsonValue["bus_name"] = processName;
- asyncResp->res.jsonValue["object_path"] = objectPath;
-
- nlohmann::json& interfacesArray =
- asyncResp->res.jsonValue["interfaces"];
- interfacesArray = nlohmann::json::array();
- tinyxml2::XMLElement* interface =
- pRoot->FirstChildElement("interface");
-
- while (interface != nullptr)
- {
- const char* ifaceName = interface->Attribute("name");
- if (ifaceName != nullptr)
+ if (ec)
{
- nlohmann::json::object_t interfaceObj;
- interfaceObj["name"] = ifaceName;
- interfacesArray.emplace_back(std::move(interfaceObj));
+ BMCWEB_LOG_ERROR(
+ "Introspect call failed with error: {} on process: {} path: {}",
+ ec.message(), processName, objectPath);
+ return;
+ }
+ tinyxml2::XMLDocument doc;
+
+ doc.Parse(introspectXml.c_str());
+ tinyxml2::XMLNode* pRoot = doc.FirstChildElement("node");
+ if (pRoot == nullptr)
+ {
+ BMCWEB_LOG_ERROR("XML document failed to parse {} {}",
+ processName, objectPath);
+ asyncResp->res.jsonValue["status"] = "XML parse error";
+ asyncResp->res.result(
+ boost::beast::http::status::internal_server_error);
+ return;
}
- interface = interface->NextSiblingElement("interface");
- }
- },
+ BMCWEB_LOG_DEBUG("{}", introspectXml);
+ asyncResp->res.jsonValue["status"] = "ok";
+ asyncResp->res.jsonValue["bus_name"] = processName;
+ asyncResp->res.jsonValue["object_path"] = objectPath;
+
+ nlohmann::json& interfacesArray =
+ asyncResp->res.jsonValue["interfaces"];
+ interfacesArray = nlohmann::json::array();
+ tinyxml2::XMLElement* interface =
+ pRoot->FirstChildElement("interface");
+
+ while (interface != nullptr)
+ {
+ const char* ifaceName = interface->Attribute("name");
+ if (ifaceName != nullptr)
+ {
+ nlohmann::json::object_t interfaceObj;
+ interfaceObj["name"] = ifaceName;
+ interfacesArray.emplace_back(std::move(interfaceObj));
+ }
+
+ interface = interface->NextSiblingElement("interface");
+ }
+ },
processName, objectPath, "org.freedesktop.DBus.Introspectable",
"Introspect");
}
@@ -2235,177 +2280,185 @@
[asyncResp, processName, objectPath,
interfaceName](const boost::system::error_code& ec,
const std::string& introspectXml) {
- if (ec)
- {
- BMCWEB_LOG_ERROR(
- "Introspect call failed with error: {} on process: {} path: {}",
- ec.message(), processName, objectPath);
- return;
- }
- tinyxml2::XMLDocument doc;
-
- doc.Parse(introspectXml.data(), introspectXml.size());
- tinyxml2::XMLNode* pRoot = doc.FirstChildElement("node");
- if (pRoot == nullptr)
- {
- BMCWEB_LOG_ERROR("XML document failed to parse {} {}",
- processName, objectPath);
- asyncResp->res.result(
- boost::beast::http::status::internal_server_error);
- return;
- }
-
- asyncResp->res.jsonValue["status"] = "ok";
- asyncResp->res.jsonValue["bus_name"] = processName;
- asyncResp->res.jsonValue["interface"] = interfaceName;
- asyncResp->res.jsonValue["object_path"] = objectPath;
-
- nlohmann::json& methodsArray = asyncResp->res.jsonValue["methods"];
- methodsArray = nlohmann::json::array();
-
- nlohmann::json& signalsArray = asyncResp->res.jsonValue["signals"];
- signalsArray = nlohmann::json::array();
-
- nlohmann::json& propertiesObj =
- asyncResp->res.jsonValue["properties"];
- propertiesObj = nlohmann::json::object();
-
- // if we know we're the only call, build the
- // json directly
- tinyxml2::XMLElement* interface =
- pRoot->FirstChildElement("interface");
- while (interface != nullptr)
- {
- const char* ifaceName = interface->Attribute("name");
-
- if (ifaceName != nullptr && ifaceName == interfaceName)
+ if (ec)
{
- break;
+ BMCWEB_LOG_ERROR(
+ "Introspect call failed with error: {} on process: {} path: {}",
+ ec.message(), processName, objectPath);
+ return;
+ }
+ tinyxml2::XMLDocument doc;
+
+ doc.Parse(introspectXml.data(), introspectXml.size());
+ tinyxml2::XMLNode* pRoot = doc.FirstChildElement("node");
+ if (pRoot == nullptr)
+ {
+ BMCWEB_LOG_ERROR("XML document failed to parse {} {}",
+ processName, objectPath);
+ asyncResp->res.result(
+ boost::beast::http::status::internal_server_error);
+ return;
}
- interface = interface->NextSiblingElement("interface");
- }
- if (interface == nullptr)
- {
- // if we got to the end of the list and
- // never found a match, throw 404
- asyncResp->res.result(boost::beast::http::status::not_found);
- return;
- }
+ asyncResp->res.jsonValue["status"] = "ok";
+ asyncResp->res.jsonValue["bus_name"] = processName;
+ asyncResp->res.jsonValue["interface"] = interfaceName;
+ asyncResp->res.jsonValue["object_path"] = objectPath;
- tinyxml2::XMLElement* methods =
- interface->FirstChildElement("method");
- while (methods != nullptr)
- {
- nlohmann::json argsArray = nlohmann::json::array();
- tinyxml2::XMLElement* arg = methods->FirstChildElement("arg");
- while (arg != nullptr)
+ nlohmann::json& methodsArray =
+ asyncResp->res.jsonValue["methods"];
+ methodsArray = nlohmann::json::array();
+
+ nlohmann::json& signalsArray =
+ asyncResp->res.jsonValue["signals"];
+ signalsArray = nlohmann::json::array();
+
+ nlohmann::json& propertiesObj =
+ asyncResp->res.jsonValue["properties"];
+ propertiesObj = nlohmann::json::object();
+
+ // if we know we're the only call, build the
+ // json directly
+ tinyxml2::XMLElement* interface =
+ pRoot->FirstChildElement("interface");
+ while (interface != nullptr)
{
- nlohmann::json thisArg;
- for (const char* fieldName : std::array<const char*, 3>{
- "name", "direction", "type"})
+ const char* ifaceName = interface->Attribute("name");
+
+ if (ifaceName != nullptr && ifaceName == interfaceName)
{
- const char* fieldValue = arg->Attribute(fieldName);
- if (fieldValue != nullptr)
- {
- thisArg[fieldName] = fieldValue;
- }
+ break;
}
- argsArray.emplace_back(std::move(thisArg));
- arg = arg->NextSiblingElement("arg");
+
+ interface = interface->NextSiblingElement("interface");
+ }
+ if (interface == nullptr)
+ {
+ // if we got to the end of the list and
+ // never found a match, throw 404
+ asyncResp->res.result(
+ boost::beast::http::status::not_found);
+ return;
}
- const char* name = methods->Attribute("name");
- if (name != nullptr)
+ tinyxml2::XMLElement* methods =
+ interface->FirstChildElement("method");
+ while (methods != nullptr)
{
- std::string uri;
- uri.reserve(14 + processName.size() + objectPath.size() +
- interfaceName.size() + strlen(name));
- uri += "/bus/system/";
- uri += processName;
- uri += objectPath;
- uri += "/";
- uri += interfaceName;
- uri += "/";
- uri += name;
-
- nlohmann::json::object_t object;
- object["name"] = name;
- object["uri"] = std::move(uri);
- object["args"] = argsArray;
-
- methodsArray.emplace_back(std::move(object));
- }
- methods = methods->NextSiblingElement("method");
- }
- tinyxml2::XMLElement* signals =
- interface->FirstChildElement("signal");
- while (signals != nullptr)
- {
- nlohmann::json argsArray = nlohmann::json::array();
-
- tinyxml2::XMLElement* arg = signals->FirstChildElement("arg");
- while (arg != nullptr)
- {
- const char* name = arg->Attribute("name");
- const char* type = arg->Attribute("type");
- if (name != nullptr && type != nullptr)
+ nlohmann::json argsArray = nlohmann::json::array();
+ tinyxml2::XMLElement* arg =
+ methods->FirstChildElement("arg");
+ while (arg != nullptr)
{
- nlohmann::json::object_t params;
- params["name"] = name;
- params["type"] = type;
- argsArray.push_back(std::move(params));
+ nlohmann::json thisArg;
+ for (const char* fieldName : std::array<const char*, 3>{
+ "name", "direction", "type"})
+ {
+ const char* fieldValue = arg->Attribute(fieldName);
+ if (fieldValue != nullptr)
+ {
+ thisArg[fieldName] = fieldValue;
+ }
+ }
+ argsArray.emplace_back(std::move(thisArg));
+ arg = arg->NextSiblingElement("arg");
}
- arg = arg->NextSiblingElement("arg");
+
+ const char* name = methods->Attribute("name");
+ if (name != nullptr)
+ {
+ std::string uri;
+ uri.reserve(14 + processName.size() +
+ objectPath.size() + interfaceName.size() +
+ strlen(name));
+ uri += "/bus/system/";
+ uri += processName;
+ uri += objectPath;
+ uri += "/";
+ uri += interfaceName;
+ uri += "/";
+ uri += name;
+
+ nlohmann::json::object_t object;
+ object["name"] = name;
+ object["uri"] = std::move(uri);
+ object["args"] = argsArray;
+
+ methodsArray.emplace_back(std::move(object));
+ }
+ methods = methods->NextSiblingElement("method");
}
- const char* name = signals->Attribute("name");
- if (name != nullptr)
+ tinyxml2::XMLElement* signals =
+ interface->FirstChildElement("signal");
+ while (signals != nullptr)
{
- nlohmann::json::object_t object;
- object["name"] = name;
- object["args"] = argsArray;
- signalsArray.emplace_back(std::move(object));
+ nlohmann::json argsArray = nlohmann::json::array();
+
+ tinyxml2::XMLElement* arg =
+ signals->FirstChildElement("arg");
+ while (arg != nullptr)
+ {
+ const char* name = arg->Attribute("name");
+ const char* type = arg->Attribute("type");
+ if (name != nullptr && type != nullptr)
+ {
+ nlohmann::json::object_t params;
+ params["name"] = name;
+ params["type"] = type;
+ argsArray.push_back(std::move(params));
+ }
+ arg = arg->NextSiblingElement("arg");
+ }
+ const char* name = signals->Attribute("name");
+ if (name != nullptr)
+ {
+ nlohmann::json::object_t object;
+ object["name"] = name;
+ object["args"] = argsArray;
+ signalsArray.emplace_back(std::move(object));
+ }
+
+ signals = signals->NextSiblingElement("signal");
}
- signals = signals->NextSiblingElement("signal");
- }
-
- tinyxml2::XMLElement* property =
- interface->FirstChildElement("property");
- while (property != nullptr)
- {
- const char* name = property->Attribute("name");
- const char* type = property->Attribute("type");
- if (type != nullptr && name != nullptr)
+ tinyxml2::XMLElement* property =
+ interface->FirstChildElement("property");
+ while (property != nullptr)
{
- sdbusplus::message_t m =
- crow::connections::systemBus->new_method_call(
- processName.c_str(), objectPath.c_str(),
- "org.freedesktop."
- "DBus."
- "Properties",
- "Get");
- m.append(interfaceName, name);
- nlohmann::json& propertyItem = propertiesObj[name];
- crow::connections::systemBus->async_send(
- m, [&propertyItem,
- asyncResp](const boost::system::error_code& ec2,
- sdbusplus::message_t& msg) {
- if (ec2)
- {
- return;
- }
+ const char* name = property->Attribute("name");
+ const char* type = property->Attribute("type");
+ if (type != nullptr && name != nullptr)
+ {
+ sdbusplus::message_t m =
+ crow::connections::systemBus->new_method_call(
+ processName.c_str(), objectPath.c_str(),
+ "org.freedesktop."
+ "DBus."
+ "Properties",
+ "Get");
+ m.append(interfaceName, name);
+ nlohmann::json& propertyItem = propertiesObj[name];
+ crow::connections::systemBus->async_send(
+ m, [&propertyItem,
+ asyncResp](const boost::system::error_code& ec2,
+ sdbusplus::message_t& msg) {
+ if (ec2)
+ {
+ return;
+ }
- int r = convertDBusToJSON("v", msg, propertyItem);
- if (r < 0)
- {
- BMCWEB_LOG_ERROR("Couldn't convert vector to json");
- }
- });
+ int r =
+ convertDBusToJSON("v", msg, propertyItem);
+ if (r < 0)
+ {
+ BMCWEB_LOG_ERROR(
+ "Couldn't convert vector to json");
+ }
+ });
+ }
+ property = property->NextSiblingElement("property");
}
- property = property->NextSiblingElement("property");
- }
- },
+ },
processName, objectPath, "org.freedesktop.DBus.Introspectable",
"Introspect");
}
@@ -2456,51 +2509,52 @@
.methods(boost::beast::http::verb::get)(
[](const crow::Request&,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
- nlohmann::json::array_t buses;
- nlohmann::json& bus = buses.emplace_back();
- bus["name"] = "system";
- asyncResp->res.jsonValue["busses"] = std::move(buses);
- asyncResp->res.jsonValue["status"] = "ok";
- });
+ nlohmann::json::array_t buses;
+ nlohmann::json& bus = buses.emplace_back();
+ bus["name"] = "system";
+ asyncResp->res.jsonValue["busses"] = std::move(buses);
+ asyncResp->res.jsonValue["status"] = "ok";
+ });
BMCWEB_ROUTE(app, "/bus/system/")
.privileges({{"Login"}})
.methods(boost::beast::http::verb::get)(
[](const crow::Request&,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
- auto myCallback = [asyncResp](const boost::system::error_code& ec,
+ auto myCallback = [asyncResp](
+ const boost::system::error_code& ec,
std::vector<std::string>& names) {
- if (ec)
- {
- BMCWEB_LOG_ERROR("Dbus call failed with code {}", ec);
- asyncResp->res.result(
- boost::beast::http::status::internal_server_error);
- }
- else
- {
- std::ranges::sort(names);
- asyncResp->res.jsonValue["status"] = "ok";
- auto& objectsSub = asyncResp->res.jsonValue["objects"];
- for (const auto& name : names)
- {
- nlohmann::json::object_t object;
- object["name"] = name;
- objectsSub.emplace_back(std::move(object));
- }
- }
- };
- crow::connections::systemBus->async_method_call(
- std::move(myCallback), "org.freedesktop.DBus", "/",
- "org.freedesktop.DBus", "ListNames");
- });
+ if (ec)
+ {
+ BMCWEB_LOG_ERROR("Dbus call failed with code {}", ec);
+ asyncResp->res.result(
+ boost::beast::http::status::internal_server_error);
+ }
+ else
+ {
+ std::ranges::sort(names);
+ asyncResp->res.jsonValue["status"] = "ok";
+ auto& objectsSub = asyncResp->res.jsonValue["objects"];
+ for (const auto& name : names)
+ {
+ nlohmann::json::object_t object;
+ object["name"] = name;
+ objectsSub.emplace_back(std::move(object));
+ }
+ }
+ };
+ crow::connections::systemBus->async_method_call(
+ std::move(myCallback), "org.freedesktop.DBus", "/",
+ "org.freedesktop.DBus", "ListNames");
+ });
BMCWEB_ROUTE(app, "/list/")
.privileges({{"Login"}})
.methods(boost::beast::http::verb::get)(
[](const crow::Request&,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
- handleList(asyncResp, "/");
- });
+ handleList(asyncResp, "/");
+ });
BMCWEB_ROUTE(app, "/xyz/<path>")
.privileges({{"Login"}})
@@ -2508,9 +2562,9 @@
[](const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& path) {
- std::string objectPath = "/xyz/" + path;
- handleDBusUrl(req, asyncResp, objectPath);
- });
+ std::string objectPath = "/xyz/" + path;
+ handleDBusUrl(req, asyncResp, objectPath);
+ });
BMCWEB_ROUTE(app, "/xyz/<path>")
.privileges({{"ConfigureComponents", "ConfigureManager"}})
@@ -2519,9 +2573,9 @@
[](const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& path) {
- std::string objectPath = "/xyz/" + path;
- handleDBusUrl(req, asyncResp, objectPath);
- });
+ std::string objectPath = "/xyz/" + path;
+ handleDBusUrl(req, asyncResp, objectPath);
+ });
BMCWEB_ROUTE(app, "/org/<path>")
.privileges({{"Login"}})
@@ -2529,9 +2583,9 @@
[](const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& path) {
- std::string objectPath = "/org/" + path;
- handleDBusUrl(req, asyncResp, objectPath);
- });
+ std::string objectPath = "/org/" + path;
+ handleDBusUrl(req, asyncResp, objectPath);
+ });
BMCWEB_ROUTE(app, "/org/<path>")
.privileges({{"ConfigureComponents", "ConfigureManager"}})
@@ -2540,9 +2594,9 @@
[](const crow::Request& req,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& path) {
- std::string objectPath = "/org/" + path;
- handleDBusUrl(req, asyncResp, objectPath);
- });
+ std::string objectPath = "/org/" + path;
+ handleDBusUrl(req, asyncResp, objectPath);
+ });
BMCWEB_ROUTE(app, "/download/dump/<str>/")
.privileges({{"ConfigureManager"}})
@@ -2550,60 +2604,66 @@
[](const crow::Request&,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& dumpId) {
- if (!validateFilename(dumpId))
- {
- asyncResp->res.result(boost::beast::http::status::bad_request);
- return;
- }
- std::filesystem::path loc("/var/lib/phosphor-debug-collector/dumps");
+ if (!validateFilename(dumpId))
+ {
+ asyncResp->res.result(
+ boost::beast::http::status::bad_request);
+ return;
+ }
+ std::filesystem::path loc(
+ "/var/lib/phosphor-debug-collector/dumps");
- loc /= dumpId;
+ loc /= dumpId;
- if (!std::filesystem::exists(loc) ||
- !std::filesystem::is_directory(loc))
- {
- BMCWEB_LOG_ERROR("{}Not found", loc.string());
- asyncResp->res.result(boost::beast::http::status::not_found);
- return;
- }
- std::filesystem::directory_iterator files(loc);
+ if (!std::filesystem::exists(loc) ||
+ !std::filesystem::is_directory(loc))
+ {
+ BMCWEB_LOG_ERROR("{}Not found", loc.string());
+ asyncResp->res.result(
+ boost::beast::http::status::not_found);
+ return;
+ }
+ std::filesystem::directory_iterator files(loc);
- for (const auto& file : files)
- {
- if (!asyncResp->res.openFile(file))
- {
- continue;
- }
+ for (const auto& file : files)
+ {
+ if (!asyncResp->res.openFile(file))
+ {
+ continue;
+ }
- asyncResp->res.addHeader(boost::beast::http::field::content_type,
- "application/octet-stream");
+ asyncResp->res.addHeader(
+ boost::beast::http::field::content_type,
+ "application/octet-stream");
- // Assuming only one dump file will be present in the dump
- // id directory
- std::string dumpFileName = file.path().filename().string();
+ // Assuming only one dump file will be present in the dump
+ // id directory
+ std::string dumpFileName = file.path().filename().string();
- // Filename should be in alphanumeric, dot and underscore
- // Its based on phosphor-debug-collector application
- // dumpfile format
- static std::regex dumpFileRegex("[a-zA-Z0-9\\._]+");
- if (!std::regex_match(dumpFileName, dumpFileRegex))
- {
- BMCWEB_LOG_ERROR("Invalid dump filename {}", dumpFileName);
+ // Filename should be in alphanumeric, dot and underscore
+ // Its based on phosphor-debug-collector application
+ // dumpfile format
+ static std::regex dumpFileRegex("[a-zA-Z0-9\\._]+");
+ if (!std::regex_match(dumpFileName, dumpFileRegex))
+ {
+ BMCWEB_LOG_ERROR("Invalid dump filename {}",
+ dumpFileName);
+ asyncResp->res.result(
+ boost::beast::http::status::not_found);
+ return;
+ }
+ std::string contentDispositionParam =
+ "attachment; filename=\"" + dumpFileName + "\"";
+
+ asyncResp->res.addHeader(
+ boost::beast::http::field::content_disposition,
+ contentDispositionParam);
+
+ return;
+ }
asyncResp->res.result(boost::beast::http::status::not_found);
return;
- }
- std::string contentDispositionParam = "attachment; filename=\"" +
- dumpFileName + "\"";
-
- asyncResp->res.addHeader(
- boost::beast::http::field::content_disposition,
- contentDispositionParam);
-
- return;
- }
- asyncResp->res.result(boost::beast::http::status::not_found);
- return;
- });
+ });
BMCWEB_ROUTE(app, "/bus/system/<str>/")
.privileges({{"Login"}})
@@ -2612,8 +2672,8 @@
[](const crow::Request&,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& connection) {
- introspectObjects(connection, "/", asyncResp);
- });
+ introspectObjects(connection, "/", asyncResp);
+ });
BMCWEB_ROUTE(app, "/bus/system/<str>/<path>")
.privileges({{"ConfigureComponents", "ConfigureManager"}})
diff --git a/include/security_headers.hpp b/include/security_headers.hpp
index 3206acc16..f48a22a 100644
--- a/include/security_headers.hpp
+++ b/include/security_headers.hpp
@@ -27,49 +27,52 @@
{
res.addHeader(bf::x_frame_options, "DENY");
res.addHeader("Referrer-Policy", "no-referrer");
- res.addHeader("Permissions-Policy", "accelerometer=(),"
- "ambient-light-sensor=(),"
- "autoplay=(),"
- "battery=(),"
- "camera=(),"
- "display-capture=(),"
- "document-domain=(),"
- "encrypted-media=(),"
- "fullscreen=(),"
- "gamepad=(),"
- "geolocation=(),"
- "gyroscope=(),"
- "layout-animations=(self),"
- "legacy-image-formats=(self),"
- "magnetometer=(),"
- "microphone=(),"
- "midi=(),"
- "oversized-images=(self),"
- "payment=(),"
- "picture-in-picture=(),"
- "publickey-credentials-get=(),"
- "speaker-selection=(),"
- "sync-xhr=(self),"
- "unoptimized-images=(self),"
- "unsized-media=(self),"
- "usb=(),"
- "screen-wak-lock=(),"
- "web-share=(),"
- "xr-spatial-tracking=()");
+ res.addHeader(
+ "Permissions-Policy",
+ "accelerometer=(),"
+ "ambient-light-sensor=(),"
+ "autoplay=(),"
+ "battery=(),"
+ "camera=(),"
+ "display-capture=(),"
+ "document-domain=(),"
+ "encrypted-media=(),"
+ "fullscreen=(),"
+ "gamepad=(),"
+ "geolocation=(),"
+ "gyroscope=(),"
+ "layout-animations=(self),"
+ "legacy-image-formats=(self),"
+ "magnetometer=(),"
+ "microphone=(),"
+ "midi=(),"
+ "oversized-images=(self),"
+ "payment=(),"
+ "picture-in-picture=(),"
+ "publickey-credentials-get=(),"
+ "speaker-selection=(),"
+ "sync-xhr=(self),"
+ "unoptimized-images=(self),"
+ "unsized-media=(self),"
+ "usb=(),"
+ "screen-wak-lock=(),"
+ "web-share=(),"
+ "xr-spatial-tracking=()");
res.addHeader("X-Permitted-Cross-Domain-Policies", "none");
res.addHeader("Cross-Origin-Embedder-Policy", "require-corp");
res.addHeader("Cross-Origin-Opener-Policy", "same-origin");
res.addHeader("Cross-Origin-Resource-Policy", "same-origin");
- res.addHeader("Content-Security-Policy", "default-src 'none'; "
- "img-src 'self' data:; "
- "font-src 'self'; "
- "style-src 'self'; "
- "script-src 'self'; "
- "connect-src 'self' wss:; "
- "form-action 'none'; "
- "frame-ancestors 'none'; "
- "object-src 'none'; "
- "base-uri 'none' ");
+ res.addHeader("Content-Security-Policy",
+ "default-src 'none'; "
+ "img-src 'self' data:; "
+ "font-src 'self'; "
+ "style-src 'self'; "
+ "script-src 'self'; "
+ "connect-src 'self' wss:; "
+ "form-action 'none'; "
+ "frame-ancestors 'none'; "
+ "object-src 'none'; "
+ "base-uri 'none' ");
// The KVM currently needs to load images from base64 encoded
// strings. img-src 'self' data: is used to allow that.
// https://stackoverflow.com/questions/18447970/content-security-polic
diff --git a/include/sessions.hpp b/include/sessions.hpp
index d97c54d..e42542b 100644
--- a/include/sessions.hpp
+++ b/include/sessions.hpp
@@ -278,19 +278,19 @@
return nullptr;
}
- auto session = std::make_shared<UserSession>(
- UserSession{uniqueId,
- sessionToken,
- std::string(username),
- csrfToken,
- clientId,
- redfish::ip_util::toString(clientIp),
- std::chrono::steady_clock::now(),
- sessionType,
- false,
- isConfigureSelfOnly,
- "",
- {}});
+ auto session = std::make_shared<UserSession>(UserSession{
+ uniqueId,
+ sessionToken,
+ std::string(username),
+ csrfToken,
+ clientId,
+ redfish::ip_util::toString(clientIp),
+ std::chrono::steady_clock::now(),
+ sessionType,
+ false,
+ isConfigureSelfOnly,
+ "",
+ {}});
auto it = authTokens.emplace(sessionToken, session);
// Only need to write to disk if session isn't about to be destroyed.
needWrite = sessionType != SessionType::Basic &&
diff --git a/include/vm_websocket.hpp b/include/vm_websocket.hpp
index 2180329..1e56cd9 100644
--- a/include/vm_websocket.hpp
+++ b/include/vm_websocket.hpp
@@ -101,27 +101,27 @@
inputBuffer->data(),
[this, self(shared_from_this())](const boost::beast::error_code& ec,
std::size_t bytesWritten) {
- BMCWEB_LOG_DEBUG("Wrote {}bytes", bytesWritten);
- doingWrite = false;
- inputBuffer->consume(bytesWritten);
+ BMCWEB_LOG_DEBUG("Wrote {}bytes", bytesWritten);
+ doingWrite = false;
+ inputBuffer->consume(bytesWritten);
- if (session == nullptr)
- {
- return;
- }
- if (ec == boost::asio::error::eof)
- {
- session->close("VM socket port closed");
- return;
- }
- if (ec)
- {
- session->close("Error in writing to proxy port");
- BMCWEB_LOG_ERROR("Error in VM socket write {}", ec);
- return;
- }
- doWrite();
- });
+ if (session == nullptr)
+ {
+ return;
+ }
+ if (ec == boost::asio::error::eof)
+ {
+ session->close("VM socket port closed");
+ return;
+ }
+ if (ec)
+ {
+ session->close("Error in writing to proxy port");
+ BMCWEB_LOG_ERROR("Error in VM socket write {}", ec);
+ return;
+ }
+ doWrite();
+ });
}
void doRead()
@@ -132,30 +132,30 @@
outputBuffer->prepare(bytes),
[this, self(shared_from_this())](
const boost::system::error_code& ec, std::size_t bytesRead) {
- BMCWEB_LOG_DEBUG("Read done. Read {} bytes", bytesRead);
- if (ec)
- {
- BMCWEB_LOG_ERROR("Couldn't read from VM port: {}", ec);
- if (session != nullptr)
+ BMCWEB_LOG_DEBUG("Read done. Read {} bytes", bytesRead);
+ if (ec)
{
- session->close("Error in connecting to VM port");
+ BMCWEB_LOG_ERROR("Couldn't read from VM port: {}", ec);
+ if (session != nullptr)
+ {
+ session->close("Error in connecting to VM port");
+ }
+ return;
}
- return;
- }
- if (session == nullptr)
- {
- return;
- }
+ if (session == nullptr)
+ {
+ return;
+ }
- outputBuffer->commit(bytesRead);
- std::string_view payload(
- static_cast<const char*>(outputBuffer->data().data()),
- bytesRead);
- session->sendBinary(payload);
- outputBuffer->consume(bytesRead);
+ outputBuffer->commit(bytesRead);
+ std::string_view payload(
+ static_cast<const char*>(outputBuffer->data().data()),
+ bytesRead);
+ session->sendBinary(payload);
+ outputBuffer->consume(bytesRead);
- doRead();
- });
+ doRead();
+ });
}
boost::asio::readable_pipe pipeOut;
@@ -188,8 +188,7 @@
NbdProxyServer(crow::websocket::Connection& connIn,
const std::string& socketIdIn,
const std::string& endpointIdIn, const std::string& pathIn) :
- socketId(socketIdIn),
- endpointId(endpointIdIn), path(pathIn),
+ socketId(socketIdIn), endpointId(endpointIdIn), path(pathIn),
peerSocket(connIn.getIoContext()),
acceptor(connIn.getIoContext(), stream_protocol::endpoint(socketId)),
@@ -278,8 +277,8 @@
crow::connections::systemBus->async_method_call(
[weak{weak_from_this()}](const boost::system::error_code& ec,
bool isBinary) {
- afterMount(weak, ec, isBinary);
- },
+ afterMount(weak, ec, isBinary);
+ },
"xyz.openbmc_project.VirtualMedia", path,
"xyz.openbmc_project.VirtualMedia.Proxy", "Mount");
}
@@ -380,10 +379,10 @@
}
uxWriteInProgress = true;
- peerSocket.async_write_some(ws2uxBuf.data(),
- std::bind_front(&NbdProxyServer::afterWrite,
- weak_from_this(),
- std::move(onDone)));
+ peerSocket.async_write_some(
+ ws2uxBuf.data(),
+ std::bind_front(&NbdProxyServer::afterWrite, weak_from_this(),
+ std::move(onDone)));
}
// Keeps UNIX socket endpoint file path
@@ -455,8 +454,8 @@
std::filesystem::remove(socket.c_str(), ec2);
// Ignore failures. File might not exist.
- sessions[&conn] = std::make_shared<NbdProxyServer>(conn, socket, endpointId,
- path);
+ sessions[&conn] =
+ std::make_shared<NbdProxyServer>(conn, socket, endpointId, path);
sessions[&conn]->run();
}
@@ -480,8 +479,8 @@
"xyz.openbmc_project.VirtualMedia.MountPoint",
[&conn, path](const boost::system::error_code& ec,
const dbus::utility::DBusPropertiesMap& propertiesList) {
- afterGetSocket(conn, path, ec, propertiesList);
- });
+ afterGetSocket(conn, path, ec, propertiesList);
+ });
// 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
@@ -552,58 +551,58 @@
.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<Handler>(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<Handler>(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;
+ }
- size_t copied = boost::asio::buffer_copy(
- handler->inputBuffer->prepare(data.size()),
- boost::asio::buffer(data));
- handler->inputBuffer->commit(copied);
- handler->doWrite();
- });
+ size_t copied = boost::asio::buffer_copy(
+ handler->inputBuffer->prepare(data.size()),
+ boost::asio::buffer(data));
+ handler->inputBuffer->commit(copied);
+ handler->doWrite();
+ });
}
}
diff --git a/include/webassets.hpp b/include/webassets.hpp
index d465ca0..689c7d3 100644
--- a/include/webassets.hpp
+++ b/include/webassets.hpp
@@ -62,10 +62,9 @@
bool renamed = false;
};
-inline void
- handleStaticAsset(const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const StaticFile& file)
+inline void handleStaticAsset(
+ const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const StaticFile& file)
{
if (!file.contentType.empty())
{
@@ -135,9 +134,10 @@
{".woff2", "application/x-font-woff2"},
{".xml", "application/xml"}}};
- const auto* contentType = std::ranges::find_if(
- contentTypes,
- [&extension](const auto& val) { return val.first == extension; });
+ const auto* contentType =
+ std::ranges::find_if(contentTypes, [&extension](const auto& val) {
+ return val.first == extension;
+ });
if (contentType == contentTypes.end())
{
@@ -206,11 +206,11 @@
}
app.routeDynamic(webpath)(
- [file = std::move(file)](
- const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
- handleStaticAsset(req, asyncResp, file);
- });
+ [file = std::move(
+ file)](const crow::Request& req,
+ const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
+ handleStaticAsset(req, asyncResp, file);
+ });
}
inline void requestRoutes(App& app)