diff options
-rw-r--r-- | redfish-core/lib/network_protocol.hpp | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/redfish-core/lib/network_protocol.hpp b/redfish-core/lib/network_protocol.hpp index 89f0334076..1d63bc99a6 100644 --- a/redfish-core/lib/network_protocol.hpp +++ b/redfish-core/lib/network_protocol.hpp @@ -36,8 +36,13 @@ namespace redfish void getNTPProtocolEnabled(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp); std::string getHostName(); -const static std::array<std::pair<std::string, std::string>, 3> protocolToDBus{ - {{"SSH", "dropbear"}, {"HTTPS", "bmcweb"}, {"IPMI", "phosphor-ipmi-net"}}}; +static constexpr const char* sshServiceName = "dropbear"; +static constexpr const char* httpsServiceName = "bmcweb"; +static constexpr const char* ipmiServiceName = "phosphor-ipmi-net"; +static constexpr std::array<std::pair<const char*, const char*>, 3> + protocolToService = {{{"SSH", sshServiceName}, + {"HTTPS", httpsServiceName}, + {"IPMI", ipmiServiceName}}}; inline void extractNTPServersAndDomainNamesData( const dbus::utility::ManagedObjectType& dbusData, @@ -168,7 +173,7 @@ inline void getNetworkData(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, "/redfish/v1/Managers/bmc/NetworkProtocol/HTTPS/Certificates"; } - for (const auto& protocol : protocolToDBus) + for (const auto& protocol : protocolToService) { const std::string& protocolName = protocol.first; const std::string& serviceName = protocol.second; @@ -297,7 +302,7 @@ inline void inline void handleProtocolEnabled(const bool protocolEnabled, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, - const std::string_view netBasePath) + const std::string& netBasePath) { crow::connections::systemBus->async_method_call( [protocolEnabled, asyncResp, @@ -388,6 +393,14 @@ inline void }); } +inline std::string encodeServiceObjectPath(const std::string& serviceName) +{ + sdbusplus::message::object_path objPath( + "/xyz/openbmc_project/control/service"); + objPath /= serviceName; + return objPath.str; +} + inline void requestRoutesNetworkProtocol(App& app) { BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/NetworkProtocol/") @@ -439,14 +452,13 @@ inline void requestRoutesNetworkProtocol(App& app) { handleProtocolEnabled( *ipmiEnabled, asyncResp, - "/xyz/openbmc_project/control/service/phosphor_2dipmi_2dnet_40"); + encodeServiceObjectPath(std::string(ipmiServiceName) + '@')); } if (sshEnabled) { - handleProtocolEnabled( - *sshEnabled, asyncResp, - "/xyz/openbmc_project/control/service/dropbear"); + handleProtocolEnabled(*sshEnabled, asyncResp, + encodeServiceObjectPath(sshServiceName)); } }); |