Fix for Download dump file with original file name

Issue:
The downloaded dump file name is having dump id instead of actual dump
file name.

Solution:
Added "Content-Disposition" header into http response packet with
filename as actual dump file name. So, The downloaded dump file
will be saved in actual dump file name when downloading the dump file
by using dump id.

Tested By:
- curl -O -J -c cjar -b cjar -k -H "X-Auth-Token: $bmc_token"
https: //$bmc_ip/download/dump/DUMP_ID

Change-Id: Id4726da20081e7d57d62038f672169f440edecfd
Signed-off-by: Ramesh Iyyar <rameshi1@in.ibm.com>
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index 0aa23e2..5b9b738 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -23,6 +23,7 @@
 #include <dbus_utility.hpp>
 #include <filesystem>
 #include <fstream>
+#include <regex>
 #include <sdbusplus/message/types.hpp>
 
 namespace crow
@@ -2110,7 +2111,30 @@
                 {
                     continue;
                 }
+
                 res.addHeader("Content-Type", "application/octet-stream");
+
+                // Assuming only one dump file will be present in the dump id
+                // directory
+                std::string dumpFileName = file.path().filename().string();
+
+                // Filename should be in alphanumeric, dot and underscore
+                // Its based on phosphor-debug-collector application dumpfile
+                // format
+                std::regex dumpFileRegex("[a-zA-Z0-9\\._]+");
+                if (!std::regex_match(dumpFileName, dumpFileRegex))
+                {
+                    BMCWEB_LOG_ERROR << "Invalid dump filename "
+                                     << dumpFileName;
+                    res.result(boost::beast::http::status::not_found);
+                    res.end();
+                    return;
+                }
+                std::string contentDispositionParam =
+                    "attachment; filename=\"" + dumpFileName + "\"";
+
+                res.addHeader("Content-Disposition", contentDispositionParam);
+
                 res.body() = {std::istreambuf_iterator<char>(readFile),
                               std::istreambuf_iterator<char>()};
                 res.end();