Encode service object path with sdbusplus

After service-config-manager switched to encode its object path with
sdbusplus, bmcweb needs to encode them with sdbusplus as well.

Tested:
Verified PATCH ServiceEnabled property of SSH and IPMI works.

Change-Id: I1d3317489617b609327847eaf1d40fbc5659e53c
Signed-off-by: Jiaqing Zhao <jiaqing.zhao@intel.com>
diff --git a/redfish-core/lib/network_protocol.hpp b/redfish-core/lib/network_protocol.hpp
index 89f0334..1d63bc9 100644
--- a/redfish-core/lib/network_protocol.hpp
+++ b/redfish-core/lib/network_protocol.hpp
@@ -36,8 +36,13 @@
 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 @@
             "/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
     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 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 @@
         {
             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));
         }
         });