Start using sdbusplus::message::filename()

Lots of code gets checked in that does this path checking incorrectly.
So much so, that we have it documented in COMMON_ERRORS.md, yet, we
persist.  This patchset starts using the new object_path::filename()
method that was added recently to sdbusplus.  Overall, it deletes code,
and makes for a much better developer experience.

Tested:
Pulled down several endpoints and verified that filename() method works
properly, and the collections are returned as expected.

curl -vvvv --insecure --user root:0penBmc https://192.168.7.2/redfish/v1/AccountService/Accounts

Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Ief1e0584394fb139678d3453265f7011bc931f3c
diff --git a/redfish-core/include/utils/collection.hpp b/redfish-core/include/utils/collection.hpp
index bcf5c16..f1b7f21 100644
--- a/redfish-core/include/utils/collection.hpp
+++ b/redfish-core/include/utils/collection.hpp
@@ -44,13 +44,16 @@
 
             for (const auto& object : objects)
             {
-                auto pos = object.rfind('/');
-                if ((pos != std::string::npos) && (pos < (object.size() - 1)))
+                sdbusplus::message::object_path path(object);
+                std::string leaf = path.filename();
+                if (leaf.empty())
                 {
-                    members.push_back(
-                        {{"@odata.id",
-                          collectionPath + "/" + object.substr(pos + 1)}});
+                    continue;
                 }
+                std::string newPath = collectionPath;
+                newPath += '/';
+                newPath += leaf;
+                members.push_back({{"@odata.id", std::move(newPath)}});
             }
             aResp->res.jsonValue["Members@odata.count"] = members.size();
         },
diff --git a/redfish-core/include/utils/fw_utils.hpp b/redfish-core/include/utils/fw_utils.hpp
index 0e46f17..1e29139 100644
--- a/redfish-core/include/utils/fw_utils.hpp
+++ b/redfish-core/include/utils/fw_utils.hpp
@@ -68,20 +68,14 @@
             //        "/xyz/openbmc_project/software/230fb078"
             for (auto& fw : *functionalFw)
             {
+                sdbusplus::message::object_path path(fw);
+                std::string leaf = path.filename();
+                if (leaf.empty())
+                {
+                    continue;
+                }
 
-                std::string::size_type idPos = fw.rfind('/');
-                if (idPos == std::string::npos)
-                {
-                    BMCWEB_LOG_DEBUG << "Can't parse firmware ID!";
-                    continue;
-                }
-                idPos++;
-                if (idPos >= fw.size())
-                {
-                    BMCWEB_LOG_DEBUG << "Invalid firmware ID";
-                    continue;
-                }
-                functionalFwIds.push_back(fw.substr(idPos));
+                functionalFwIds.push_back(leaf);
             }
 
             crow::connections::systemBus->async_method_call(
@@ -109,22 +103,16 @@
                                  std::string, std::vector<std::string>>>>& obj :
                          subtree)
                     {
-                        // if can't parse fw id then return
-                        std::string::size_type idPos = obj.first.rfind('/');
-                        if (idPos == std::string::npos)
-                        {
-                            messages::internalError(aResp->res);
-                            BMCWEB_LOG_ERROR << "Can't parse firmware ID!!";
-                            return;
-                        }
-                        idPos++;
-                        if (idPos >= obj.first.size())
+
+                        sdbusplus::message::object_path path(obj.first);
+                        std::string swId = path.filename();
+                        if (swId.empty())
                         {
                             messages::internalError(aResp->res);
                             BMCWEB_LOG_ERROR << "Invalid firmware ID";
+
                             return;
                         }
-                        std::string swId = obj.first.substr(idPos);
 
                         bool runningImage = false;
                         // Look at Ids from