diff options
author | Ed Tanous <edtanous@google.com> | 2021-09-14 23:16:51 +0300 |
---|---|---|
committer | Ed Tanous <edtanous@google.com> | 2021-10-05 20:51:01 +0300 |
commit | d32c4fa936f9a88fc1dd124201ed11a6a90a18c5 (patch) | |
tree | fad1030fb5244223fa81ae84b0e4cea8b0bdbd44 /redfish-core/lib | |
parent | b7ff344535c42af074c60bfb272ef66a2ba157b4 (diff) | |
download | bmcweb-d32c4fa936f9a88fc1dd124201ed11a6a90a18c5.tar.xz |
Boost uri update
Update to the latest version of boost::uri
The newest version of boost uri makes some breaking changes that we need
to account for. At the same time, we take the opportunity to move to
the error code based parse methods that don't rely on exceptions.
The biggest changes are:
The standalone build is no longer present. A discussion with the
boost::url maintainers shows that our best option is to do a simple
copy of the headers, and compile boost/url/src.hpp in a separate file.
This is intended to allow people to pull the library in "standalone" and
not have to rely on the build machinery in boost-url, which we don't
really need. Interestingly, this file doesn't have a newline at the
end, which clang correctly flags. OpenBMC doesn't really need that
warning, as we rely on clang-format to do that, so we add
-Wno-newline-eof clang to get the code to compile there.
All url parsers are moved to the parse_uri, or parse_relative_uri
equivalents. This slightly tightens the requirements around what URLs
are accepted, but in no ways that should break anything. (Ie,
"/redfish/v1" is no longer accepted for a virtual media endpoint.
boost::urls::url_view::params_type has been renamed to
query_params_type, and the relevant methods have been updated.
Because of the missing standalone mode, we now need to use
boost::string_view which doesn't implicitly construct from
std::string_view. Some discussion on the boost list shows that this is
coming soon, so that cruft can eventually be cleaned up, but for now we
need the construction.
Tested:
Loaded in qemu, and ran some URLs (/redfish/v1 and /redfish/v1/Chassis)
to ensure that the url handler functions as intended.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I5843776d4ec01b4d92af2ee3a9cf1ebb1d920ae7
Diffstat (limited to 'redfish-core/lib')
-rw-r--r-- | redfish-core/lib/log_services.hpp | 6 | ||||
-rw-r--r-- | redfish-core/lib/virtual_media.hpp | 58 |
2 files changed, 32 insertions, 32 deletions
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp index 12ec64a880..2c9ae3a9ce 100644 --- a/redfish-core/lib/log_services.hpp +++ b/redfish-core/lib/log_services.hpp @@ -188,8 +188,7 @@ inline static bool getEntryTimestamp(sd_journal* journal, static bool getSkipParam(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const crow::Request& req, uint64_t& skip) { - boost::urls::url_view::params_type::iterator it = - req.urlParams.find("$skip"); + boost::urls::query_params_view::iterator it = req.urlParams.find("$skip"); if (it != req.urlParams.end()) { std::string skipParam = it->value(); @@ -210,8 +209,7 @@ static constexpr const uint64_t maxEntriesPerPage = 1000; static bool getTopParam(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const crow::Request& req, uint64_t& top) { - boost::urls::url_view::params_type::iterator it = - req.urlParams.find("$top"); + boost::urls::query_params_view::iterator it = req.urlParams.find("$top"); if (it != req.urlParams.end()) { std::string topParam = it->value(); diff --git a/redfish-core/lib/virtual_media.hpp b/redfish-core/lib/virtual_media.hpp index 6e69f20eac..7383477b3f 100644 --- a/redfish-core/lib/virtual_media.hpp +++ b/redfish-core/lib/virtual_media.hpp @@ -33,22 +33,23 @@ namespace redfish */ inline std::string getTransferProtocolTypeFromUri(const std::string& imageUri) { - try + boost::urls::error_code ec; + boost::urls::url_view url = + boost::urls::parse_uri(boost::string_view(imageUri), ec); + if (ec) { - std::string_view scheme = boost::urls::url_view(imageUri).scheme(); - if (scheme == "smb") - { - return "CIFS"; - } - if (scheme == "https") - { - return "HTTPS"; - } + return "None"; + } + boost::string_view scheme = url.scheme(); + if (scheme == "smb") + { + return "CIFS"; } - catch (std::exception& p) + if (scheme == "https") { - BMCWEB_LOG_ERROR << p.what(); + return "HTTPS"; } + return "None"; } @@ -325,25 +326,26 @@ enum class TransferProtocol inline std::optional<TransferProtocol> getTransferProtocolFromUri(const std::string& imageUri) { - try + boost::urls::error_code ec; + boost::urls::url_view url = + boost::urls::parse_uri(boost::string_view(imageUri), ec); + if (ec) { - std::string_view scheme = boost::urls::url_view(imageUri).scheme(); - if (scheme == "smb") - { - return TransferProtocol::smb; - } - if (scheme == "https") - { - return TransferProtocol::https; - } - if (!scheme.empty()) - { - return TransferProtocol::invalid; - } + return {}; + } + + boost::string_view scheme = url.scheme(); + if (scheme == "smb") + { + return TransferProtocol::smb; + } + if (scheme == "https") + { + return TransferProtocol::https; } - catch (std::exception& p) + if (!scheme.empty()) { - BMCWEB_LOG_ERROR << p.what(); + return TransferProtocol::invalid; } return {}; |