Revert "log_services: Add download of post code log entries"
This reverts commit af61db10fb40c7beb91a70f0b3ff28cb8e6c1704 which
breaks the ability to detect and post json content as HTTP. I suspect
something went wrong with the requestPrefersHtml() method that was
modified in this commit. Authors should feel free to resubmit this
patch once they have the failure understood and fixed.
Change-Id: Id6e8d102fe5d4b02ac0dce06bff50c28edfcf44c
Signed-off-by: Ed Tanous <edtanous@google.com>
diff --git a/include/http_utility.hpp b/include/http_utility.hpp
index d04fd93..119a1ee 100644
--- a/include/http_utility.hpp
+++ b/include/http_utility.hpp
@@ -5,24 +5,21 @@
namespace http_helpers
{
-inline std::string parseAccept(const crow::Request& req)
-{
- std::string_view acceptHeader = req.getHeaderValue("Accept");
- // The iterators in boost/http/rfc7230.hpp end the string if '/' is found,
- // so replace it with arbitrary character '|' which is not part of the
- // Accept header syntax.
- return boost::replace_all_copy(std::string(acceptHeader), "/", "|");
-}
-
inline bool requestPrefersHtml(const crow::Request& req)
{
- for (const auto& param : boost::beast::http::ext_list{parseAccept(req)})
+ std::string_view header = req.getHeaderValue("accept");
+ std::vector<std::string> encodings;
+ // chrome currently sends 6 accepts headers, firefox sends 4.
+ encodings.reserve(6);
+ boost::split(encodings, header, boost::is_any_of(", "),
+ boost::token_compress_on);
+ for (const std::string& encoding : encodings)
{
- if (param.first == "text|html")
+ if (encoding == "text/html")
{
return true;
}
- if (param.first == "application|json")
+ if (encoding == "application/json")
{
return false;
}
@@ -30,18 +27,6 @@
return false;
}
-inline bool isOctetAccepted(const crow::Request& req)
-{
- for (const auto& param : boost::beast::http::ext_list{parseAccept(req)})
- {
- if (param.first == "*|*" || param.first == "application|octet-stream")
- {
- return true;
- }
- }
- return false;
-}
-
inline std::string urlEncode(const std::string_view value)
{
std::ostringstream escaped;
diff --git a/redfish-core/include/redfish.hpp b/redfish-core/include/redfish.hpp
index 0a97150..1c7b695 100644
--- a/redfish-core/include/redfish.hpp
+++ b/redfish-core/include/redfish.hpp
@@ -93,7 +93,6 @@
requestRoutesSystemLogServiceCollection(app);
requestRoutesEventLogService(app);
- requestRoutesPostCodesEntryAdditionalData(app);
requestRoutesPostCodesLogService(app);
requestRoutesPostCodesClear(app);
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index 9aff5c6..b772bf1 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -15,7 +15,6 @@
*/
#pragma once
-#include "http_utility.hpp"
#include "registries.hpp"
#include "registries/base_message_registry.hpp"
#include "registries/openbmc_message_registry.hpp"
@@ -33,7 +32,6 @@
#include <boost/system/linux_error.hpp>
#include <error_messages.hpp>
-#include <charconv>
#include <filesystem>
#include <optional>
#include <string_view>
@@ -1701,7 +1699,24 @@
const std::string& param)
{
- if (!http_helpers::isOctetAccepted(req))
+ std::string_view acceptHeader = req.getHeaderValue("Accept");
+ // The iterators in boost/http/rfc7230.hpp end the string if '/'
+ // is found, so replace it with arbitrary character '|' which is
+ // not part of the Accept header syntax.
+ std::string acceptStr = boost::replace_all_copy(
+ std::string(acceptHeader), "/", "|");
+ boost::beast::http::ext_list acceptTypes{acceptStr};
+ bool supported = false;
+ for (const auto& type : acceptTypes)
+ {
+ if ((type.first == "*|*") ||
+ (type.first == "application|octet-stream"))
+ {
+ supported = true;
+ break;
+ }
+ }
+ if (!supported)
{
asyncResp->res.result(
boost::beast::http::status::bad_request);
@@ -3064,117 +3079,6 @@
"xyz.openbmc_project.State.Boot.PostCode", "CurrentBootCycleCount");
}
-inline static bool parsePostCode(std::string postCodeID, uint64_t& currentValue,
- uint16_t& index)
-{
- // postCodeID = B1-1
- std::vector<std::string> split;
- boost::algorithm::split(split, postCodeID, boost::is_any_of("-"));
- if (split.size() != 2 || split[0].length() < 2)
- {
- return false;
- }
-
- const char* start = split[0].data() + 1;
- const char* end = split[0].data() + split[0].size();
- auto [ptrIndex, ecIndex] = std::from_chars(start, end, index);
-
- if (ptrIndex != end || ecIndex != std::errc() || !index)
- {
- return false;
- }
-
- start = split[1].data();
- end = split[1].data() + split[1].size();
- auto [ptrValue, ecValue] = std::from_chars(start, end, currentValue);
- if (ptrValue != end || ecValue != std::errc() || !currentValue)
- {
- return false;
- }
-
- return true;
-}
-
-inline void requestRoutesPostCodesEntryAdditionalData(App& app)
-{
- BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/LogServices/PostCodes/"
- "Entries/<str>/attachment/")
- .privileges({{"Login"}})
- .methods(boost::beast::http::verb::get)(
- [](const crow::Request& req,
- const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
- const std::string& postCodeID) {
- if (!http_helpers::isOctetAccepted(req))
- {
- asyncResp->res.result(
- boost::beast::http::status::bad_request);
- return;
- }
-
- uint64_t currentValue = 0;
- uint16_t index = 0;
- if (!parsePostCode(postCodeID, currentValue, index))
- {
- messages::resourceNotFound(asyncResp->res, "LogEntry",
- postCodeID);
- return;
- }
-
- crow::connections::systemBus->async_method_call(
- [asyncResp, postCodeID, currentValue](
- const boost::system::error_code ec,
- const std::vector<std::tuple<
- uint64_t, std::vector<uint8_t>>>& postcodes) {
- if (ec.value() == EBADR)
- {
- messages::resourceNotFound(asyncResp->res,
- "LogEntry", postCodeID);
- return;
- }
- if (ec)
- {
- BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
- messages::internalError(asyncResp->res);
- return;
- }
-
- if (currentValue < 1 ||
- postcodes.size() <= currentValue)
- {
- BMCWEB_LOG_ERROR << "Wrong currentValue value";
- messages::resourceNotFound(asyncResp->res,
- "LogEntry", postCodeID);
- return;
- }
-
- size_t value = static_cast<size_t>(currentValue) - 1;
- auto& [tID, code] = postcodes[value];
-
- if (code.size() == 0)
- {
- BMCWEB_LOG_INFO << "No found post code data";
- messages::internalError(asyncResp->res);
- return;
- }
-
- std::string_view strData(
- reinterpret_cast<const char*>(code.data()),
- code.size());
-
- asyncResp->res.addHeader("Content-Type",
- "application/octet-stream");
- asyncResp->res.addHeader("Content-Transfer-Encoding",
- "Base64");
- asyncResp->res.body() =
- std::move(crow::utility::base64encode(strData));
- },
- "xyz.openbmc_project.State.Boot.PostCode0",
- "/xyz/openbmc_project/State/Boot/PostCode0",
- "xyz.openbmc_project.State.Boot.PostCode", "GetPostCodes",
- index);
- });
-}
-
inline void requestRoutesPostCodesEntryCollection(App& app)
{
BMCWEB_ROUTE(app,