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/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