Change BMC and System dump code

This commit contains the dump code changes w.r.t the
latest changes in the backend. The dump paths are being
changed to /xyz/openbmc_project/dump/<bmc or system> as
per the below commit:

https://gerrit.openbmc-project.xyz/c/openbmc/phosphor-
debug-collector/+/36276

Signed-off-by: Asmitha Karunanithi <asmitk01@in.ibm.com>
Change-Id: I57abffc59354c363236be42d2d697916bd6480a9
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index 1198455..bbf8768 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -427,21 +427,14 @@
 
             nlohmann::json& entriesArray = asyncResp->res.jsonValue["Members"];
             entriesArray = nlohmann::json::array();
+            std::string dumpEntryPath =
+                "/xyz/openbmc_project/dump/" +
+                std::string(boost::algorithm::to_lower_copy(dumpType)) +
+                "/entry/";
 
             for (auto& object : resp)
             {
-                bool foundDumpEntry = false;
-                for (auto& interfaceMap : object.second)
-                {
-                    if (interfaceMap.first ==
-                        ("xyz.openbmc_project.Dump.Entry." + dumpType))
-                    {
-                        foundDumpEntry = true;
-                        break;
-                    }
-                }
-
-                if (foundDumpEntry == false)
+                if (object.first.str.find(dumpEntryPath) == std::string::npos)
                 {
                     continue;
                 }
@@ -566,32 +559,20 @@
                 return;
             }
 
+            bool foundDumpEntry = false;
+            std::string dumpEntryPath =
+                "/xyz/openbmc_project/dump/" +
+                std::string(boost::algorithm::to_lower_copy(dumpType)) +
+                "/entry/";
+
             for (auto& objectPath : resp)
             {
-                if (objectPath.first.str.find(
-                        "/xyz/openbmc_project/dump/entry/" + entryID) ==
-                    std::string::npos)
+                if (objectPath.first.str != dumpEntryPath + entryID)
                 {
                     continue;
                 }
 
-                bool foundDumpEntry = false;
-                for (auto& interfaceMap : objectPath.second)
-                {
-                    if (interfaceMap.first ==
-                        ("xyz.openbmc_project.Dump.Entry." + dumpType))
-                    {
-                        foundDumpEntry = true;
-                        break;
-                    }
-                }
-                if (foundDumpEntry == false)
-                {
-                    BMCWEB_LOG_ERROR << "Can't find Dump Entry";
-                    messages::internalError(asyncResp->res);
-                    return;
-                }
-
+                foundDumpEntry = true;
                 std::time_t timestamp;
                 uint64_t size = 0;
 
@@ -667,12 +648,19 @@
                         entryID;
                 }
             }
+            if (foundDumpEntry == false)
+            {
+                BMCWEB_LOG_ERROR << "Can't find Dump Entry";
+                messages::internalError(asyncResp->res);
+                return;
+            }
         },
         "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump",
         "org.freedesktop.DBus.ObjectManager", "GetManagedObjects");
 }
 
-inline void deleteDumpEntry(crow::Response& res, const std::string& entryID)
+inline void deleteDumpEntry(crow::Response& res, const std::string& entryID,
+                            const std::string& dumpType)
 {
     std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
 
@@ -688,7 +676,9 @@
     };
     crow::connections::systemBus->async_method_call(
         respHandler, "xyz.openbmc_project.Dump.Manager",
-        "/xyz/openbmc_project/dump/entry/" + entryID,
+        "/xyz/openbmc_project/dump/" +
+            std::string(boost::algorithm::to_lower_copy(dumpType)) + "/entry/" +
+            entryID,
         "xyz.openbmc_project.Object.Delete", "Delete");
 }
 
@@ -717,22 +707,21 @@
 
             m.read(objPath, interfacesList);
 
-            for (auto& interface : interfacesList)
+            if (objPath.str ==
+                "/xyz/openbmc_project/dump/" +
+                    std::string(boost::algorithm::to_lower_copy(dumpType)) +
+                    "/entry/" + std::to_string(dumpId))
             {
-                if (interface.first ==
-                    ("xyz.openbmc_project.Dump.Entry." + dumpType))
-                {
-                    nlohmann::json retMessage = messages::success();
-                    taskData->messages.emplace_back(retMessage);
+                nlohmann::json retMessage = messages::success();
+                taskData->messages.emplace_back(retMessage);
 
-                    std::string headerLoc =
-                        "Location: " + dumpPath + std::to_string(dumpId);
-                    taskData->payload->httpHeaders.emplace_back(
-                        std::move(headerLoc));
+                std::string headerLoc =
+                    "Location: " + dumpPath + std::to_string(dumpId);
+                taskData->payload->httpHeaders.emplace_back(
+                    std::move(headerLoc));
 
-                    taskData->state = "Completed";
-                    break;
-                }
+                taskData->state = "Completed";
+                return task::completed;
             }
             return task::completed;
         },
@@ -831,16 +820,20 @@
 
             createDumpTaskCallback(req, asyncResp, dumpId, dumpPath, dumpType);
         },
-        "xyz.openbmc_project.Dump.Manager", "/xyz/openbmc_project/dump",
+        "xyz.openbmc_project.Dump.Manager",
+        "/xyz/openbmc_project/dump/" +
+            std::string(boost::algorithm::to_lower_copy(dumpType)),
         "xyz.openbmc_project.Dump.Create", "CreateDump");
 }
 
-inline void clearDump(crow::Response& res, const std::string& dumpInterface)
+inline void clearDump(crow::Response& res, const std::string& dumpType)
 {
+    std::string dumpTypeLowerCopy =
+        std::string(boost::algorithm::to_lower_copy(dumpType));
     std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res);
     crow::connections::systemBus->async_method_call(
-        [asyncResp](const boost::system::error_code ec,
-                    const std::vector<std::string>& subTreePaths) {
+        [asyncResp, dumpType](const boost::system::error_code ec,
+                              const std::vector<std::string>& subTreePaths) {
             if (ec)
             {
                 BMCWEB_LOG_ERROR << "resp_handler got error " << ec;
@@ -854,15 +847,16 @@
                 if (pos != std::string::npos)
                 {
                     std::string logID = path.substr(pos + 1);
-                    deleteDumpEntry(asyncResp->res, logID);
+                    deleteDumpEntry(asyncResp->res, logID, dumpType);
                 }
             }
         },
         "xyz.openbmc_project.ObjectMapper",
         "/xyz/openbmc_project/object_mapper",
         "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths",
-        "/xyz/openbmc_project/dump", 0,
-        std::array<std::string, 1>{dumpInterface});
+        "/xyz/openbmc_project/dump/" + dumpTypeLowerCopy, 0,
+        std::array<std::string, 1>{"xyz.openbmc_project.Dump.Entry." +
+                                   dumpType});
 }
 
 static void parseCrashdumpParameters(
@@ -2103,7 +2097,7 @@
             messages::internalError(asyncResp->res);
             return;
         }
-        deleteDumpEntry(asyncResp->res, params[0]);
+        deleteDumpEntry(asyncResp->res, params[0], "bmc");
     }
 };
 
@@ -2153,7 +2147,7 @@
     void doPost(crow::Response& res, const crow::Request&,
                 const std::vector<std::string>&) override
     {
-        clearDump(res, "xyz.openbmc_project.Dump.Entry.BMC");
+        clearDump(res, "BMC");
     }
 };
 
@@ -2273,7 +2267,7 @@
             messages::internalError(asyncResp->res);
             return;
         }
-        deleteDumpEntry(asyncResp->res, params[0]);
+        deleteDumpEntry(asyncResp->res, params[0], "system");
     }
 };
 
@@ -2323,7 +2317,7 @@
     void doPost(crow::Response& res, const crow::Request&,
                 const std::vector<std::string>&) override
     {
-        clearDump(res, "xyz.openbmc_project.Dump.Entry.System");
+        clearDump(res, "System");
     }
 };