summaryrefslogtreecommitdiff
path: root/redfish-core/lib
diff options
context:
space:
mode:
authorOliver Brewka <oliver.brewka@9elements.com>2025-08-26 09:21:30 +0300
committerEd Tanous <ed@tanous.net>2025-09-11 22:09:19 +0300
commitff35df942a0f173013cca54e5dfda3d3c5f5332d (patch)
tree62de353823c39732539d8488ed520f96dc39b8f0 /redfish-core/lib
parent50ab50dbb0107812af1f7b44797bdd132474c166 (diff)
downloadbmcweb-master.tar.xz
Extract downloadEntryCallback functionHEADmaster
As part of a EventLog refactor, extract this function into a log_services utility. Tested: Only code extraction. Code compiles. Change-Id: Iaa7aa583a38587c338280af2a9fff65d3732f301 Signed-off-by: Oliver Brewka <oliver.brewka@9elements.com>
Diffstat (limited to 'redfish-core/lib')
-rw-r--r--redfish-core/lib/log_services.hpp96
1 files changed, 5 insertions, 91 deletions
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index a31d738985..e1f3fb6001 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -27,6 +27,7 @@
#include "utils/dbus_event_log_entry.hpp"
#include "utils/dbus_utils.hpp"
#include "utils/json_utils.hpp"
+#include "utils/log_services_utils.hpp"
#include "utils/query_param.hpp"
#include "utils/time_utils.hpp"
@@ -595,95 +596,6 @@ inline void deleteDumpEntry(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
std::format("{}/entry/{}", getDumpPath(dumpType), entryID),
"xyz.openbmc_project.Object.Delete", "Delete");
}
-inline bool checkSizeLimit(int fd, crow::Response& res)
-{
- long long int size = lseek(fd, 0, SEEK_END);
- if (size <= 0)
- {
- BMCWEB_LOG_ERROR("Failed to get size of file, lseek() returned {}",
- size);
- messages::internalError(res);
- return false;
- }
-
- // Arbitrary max size of 20MB to accommodate BMC dumps
- constexpr long long int maxFileSize = 20LL * 1024LL * 1024LL;
- if (size > maxFileSize)
- {
- BMCWEB_LOG_ERROR("File size {} exceeds maximum allowed size of {}",
- size, maxFileSize);
- messages::internalError(res);
- return false;
- }
- off_t rc = lseek(fd, 0, SEEK_SET);
- if (rc < 0)
- {
- BMCWEB_LOG_ERROR("Failed to reset file offset to 0");
- messages::internalError(res);
- return false;
- }
- return true;
-}
-inline void downloadEntryCallback(
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& entryID, const std::string& downloadEntryType,
- const boost::system::error_code& ec,
- const sdbusplus::message::unix_fd& unixfd)
-{
- if (ec.value() == EBADR)
- {
- messages::resourceNotFound(asyncResp->res, "EntryAttachment", entryID);
- return;
- }
- if (ec)
- {
- BMCWEB_LOG_ERROR("DBUS response error: {}", ec);
- messages::internalError(asyncResp->res);
- return;
- }
-
- // Make sure we know how to process the retrieved entry attachment
- if ((downloadEntryType != "BMC") && (downloadEntryType != "System"))
- {
- BMCWEB_LOG_ERROR("downloadEntryCallback() invalid entry type: {}",
- downloadEntryType);
- messages::internalError(asyncResp->res);
- }
-
- int fd = -1;
- fd = dup(unixfd);
- if (fd < 0)
- {
- BMCWEB_LOG_ERROR("Failed to open file");
- messages::internalError(asyncResp->res);
- return;
- }
- if (!checkSizeLimit(fd, asyncResp->res))
- {
- close(fd);
- return;
- }
- if (downloadEntryType == "System")
- {
- if (!asyncResp->res.openFd(fd, bmcweb::EncodingType::Base64))
- {
- messages::internalError(asyncResp->res);
- close(fd);
- return;
- }
- asyncResp->res.addHeader(
- boost::beast::http::field::content_transfer_encoding, "Base64");
- return;
- }
- if (!asyncResp->res.openFd(fd))
- {
- messages::internalError(asyncResp->res);
- close(fd);
- return;
- }
- asyncResp->res.addHeader(boost::beast::http::field::content_type,
- "application/octet-stream");
-}
inline void downloadDumpEntry(
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
@@ -703,7 +615,8 @@ inline void downloadDumpEntry(
[asyncResp, entryID,
dumpType](const boost::system::error_code& ec,
const sdbusplus::message::unix_fd& unixfd) {
- downloadEntryCallback(asyncResp, entryID, dumpType, ec, unixfd);
+ log_services_utils::downloadEntryCallback(asyncResp, entryID,
+ dumpType, ec, unixfd);
};
dbus::utility::async_method_call(
@@ -739,7 +652,8 @@ inline void downloadEventLogEntry(
[asyncResp, entryID,
dumpType](const boost::system::error_code& ec,
const sdbusplus::message::unix_fd& unixfd) {
- downloadEntryCallback(asyncResp, entryID, dumpType, ec, unixfd);
+ log_services_utils::downloadEntryCallback(asyncResp, entryID,
+ dumpType, ec, unixfd);
};
dbus::utility::async_method_call(