Add url type safety to message registry

There are a number of places where we use message registry messages
incorrectly.  This patchset attempts to fix them, and invoke some type
safety when they're used such that they're more obvious to use.

Namely, it changes a number of the message registry methods to accept a
boost::urls::url_view for its argument instead of a const std::string&.
This forces the calling code to correctly encode a URL to use the
method, which should make it obvious that it's not for an ID, a property
name, or anything else.  In the course of doing this, several places
were found to be using the first argument incorrectly.

Tested:
curl --insecure --user root:0penBmc https://192.168.7.2/redfish/v1/Chassis/foobar

Returns:
{
  "error": {
    "@Message.ExtendedInfo": [
      {
        "@odata.type": "#Message.v1_1_1.Message",
        "Message": "The requested resource of type #Chassis.v1_16_0.Chassis named foobar was not found.",
        "MessageArgs": [
          "#Chassis.v1_16_0.Chassis",
          "foobar"
        ],
        "MessageId": "Base.1.8.1.ResourceNotFound",
        "MessageSeverity": "Critical",
        "Resolution": "Provide a valid resource identifier and resubmit the request."
      }
    ],
    "code": "Base.1.8.1.ResourceNotFound",
    "message": "The requested resource of type #Chassis.v1_16_0.Chassis named foobar was not found."
}

Identically to previously.

Also tested with IDs that contained % encoded characters, like
foobar%10, which gave the same result.

Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: Icbb3bce5d190a260610087c9ef35e7becc5a50c7
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index 94de5a9..154de95 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -328,7 +328,8 @@
             indexStr.data(), indexStr.data() + indexStr.size(), index);
         if (ec != std::errc())
         {
-            messages::resourceMissingAtURI(asyncResp->res, entryID);
+            messages::resourceMissingAtURI(
+                asyncResp->res, crow::utility::urlFromPieces(entryID));
             return false;
         }
     }
@@ -337,7 +338,8 @@
         std::from_chars(tsStr.data(), tsStr.data() + tsStr.size(), timestamp);
     if (ec != std::errc())
     {
-        messages::resourceMissingAtURI(asyncResp->res, entryID);
+        messages::resourceMissingAtURI(asyncResp->res,
+                                       crow::utility::urlFromPieces(entryID));
         return false;
     }
     return true;
@@ -812,8 +814,7 @@
             (*diagnosticDataType != "OEM"))
         {
             BMCWEB_LOG_ERROR << "Wrong parameter values passed";
-            messages::invalidObject(asyncResp->res,
-                                    "System Dump creation parameters");
+            messages::internalError(asyncResp->res);
             return;
         }
     }
@@ -831,8 +832,7 @@
         {
             BMCWEB_LOG_ERROR
                 << "Wrong parameter value passed for 'DiagnosticDataType'";
-            messages::invalidObject(asyncResp->res,
-                                    "BMC Dump creation parameters");
+            messages::internalError(asyncResp->res);
             return;
         }
     }
@@ -1332,7 +1332,8 @@
                     }
                 }
                 // Requested ID was not found
-                messages::resourceMissingAtURI(asyncResp->res, targetID);
+                messages::resourceMissingAtURI(
+                    asyncResp->res, crow::utility::urlFromPieces(targetID));
             });
 }
 
@@ -1976,7 +1977,7 @@
         app, "/redfish/v1/Systems/system/LogServices/HostLogger/Entries/<str>/")
         .privileges(redfish::privileges::getLogEntry)
         .methods(boost::beast::http::verb::get)(
-            [](const crow::Request&,
+            [](const crow::Request& req,
                const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
                const std::string& param) {
                 const std::string& targetID = param;
@@ -1989,12 +1990,12 @@
                 auto [ptr, ec] = std::from_chars(targetID.data(), end, idInt);
                 if (ec == std::errc::invalid_argument)
                 {
-                    messages::resourceMissingAtURI(asyncResp->res, targetID);
+                    messages::resourceMissingAtURI(asyncResp->res, req.urlView);
                     return;
                 }
                 if (ec == std::errc::result_out_of_range)
                 {
-                    messages::resourceMissingAtURI(asyncResp->res, targetID);
+                    messages::resourceMissingAtURI(asyncResp->res, req.urlView);
                     return;
                 }
 
@@ -2026,7 +2027,7 @@
                 }
 
                 // Requested ID was not found
-                messages::resourceMissingAtURI(asyncResp->res, targetID);
+                messages::resourceMissingAtURI(asyncResp->res, req.urlView);
             });
 }
 
@@ -2253,7 +2254,7 @@
                  "/redfish/v1/Managers/bmc/LogServices/Journal/Entries/<str>/")
         .privileges(redfish::privileges::getLogEntry)
         .methods(boost::beast::http::verb::get)(
-            [](const crow::Request&,
+            [](const crow::Request& req,
                const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
                const std::string& entryID) {
                 // Convert the unique ID back to a timestamp to find the entry
@@ -2304,7 +2305,7 @@
                 // Confirm that the entry ID matches what was requested
                 if (idStr != entryID)
                 {
-                    messages::resourceMissingAtURI(asyncResp->res, entryID);
+                    messages::resourceMissingAtURI(asyncResp->res, req.urlView);
                     return;
                 }
 
@@ -2642,7 +2643,8 @@
 
             if (filename.empty() || timestamp.empty())
             {
-                messages::resourceMissingAtURI(asyncResp->res, logID);
+                messages::resourceMissingAtURI(
+                    asyncResp->res, crow::utility::urlFromPieces(logID));
                 return;
             }
 
@@ -2774,11 +2776,12 @@
         "/redfish/v1/Systems/system/LogServices/Crashdump/Entries/<str>/<str>/")
         .privileges(redfish::privileges::getLogEntry)
         .methods(boost::beast::http::verb::get)(
-            [](const crow::Request&,
+            [](const crow::Request& req,
                const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
                const std::string& logID, const std::string& fileName) {
                 auto getStoredLogCallback =
-                    [asyncResp, logID, fileName](
+                    [asyncResp, logID, fileName,
+                     url(boost::urls::url(req.urlView))](
                         const boost::system::error_code ec,
                         const std::vector<std::pair<
                             std::string, dbus::utility::DbusVariantType>>&
@@ -2801,23 +2804,20 @@
                         if (dbusFilename.empty() || dbusTimestamp.empty() ||
                             dbusFilepath.empty())
                         {
-                            messages::resourceMissingAtURI(asyncResp->res,
-                                                           fileName);
+                            messages::resourceMissingAtURI(asyncResp->res, url);
                             return;
                         }
 
                         // Verify the file name parameter is correct
                         if (fileName != dbusFilename)
                         {
-                            messages::resourceMissingAtURI(asyncResp->res,
-                                                           fileName);
+                            messages::resourceMissingAtURI(asyncResp->res, url);
                             return;
                         }
 
                         if (!std::filesystem::exists(dbusFilepath))
                         {
-                            messages::resourceMissingAtURI(asyncResp->res,
-                                                           fileName);
+                            messages::resourceMissingAtURI(asyncResp->res, url);
                             return;
                         }
                         std::ifstream ifs(dbusFilepath,
@@ -3456,7 +3456,7 @@
         app, "/redfish/v1/Systems/system/LogServices/PostCodes/Entries/<str>/")
         .privileges(redfish::privileges::getLogEntry)
         .methods(boost::beast::http::verb::get)(
-            [](const crow::Request&,
+            [](const crow::Request& req,
                const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
                const std::string& targetID) {
                 uint16_t bootIndex = 0;
@@ -3464,7 +3464,7 @@
                 if (!parsePostCode(targetID, codeIndex, bootIndex))
                 {
                     // Requested ID was not found
-                    messages::resourceMissingAtURI(asyncResp->res, targetID);
+                    messages::resourceMissingAtURI(asyncResp->res, req.urlView);
                     return;
                 }
                 if (bootIndex == 0 || codeIndex == 0)