diff options
-rw-r--r-- | http/http_connection.hpp | 41 | ||||
-rw-r--r-- | http/http_request.hpp | 2 | ||||
-rw-r--r-- | meson.build | 8 | ||||
-rw-r--r-- | redfish-core/lib/log_services.hpp | 6 | ||||
-rw-r--r-- | redfish-core/lib/virtual_media.hpp | 58 | ||||
-rw-r--r-- | src/boost_url.cpp | 2 | ||||
-rw-r--r-- | subprojects/boost-url.wrap | 2 |
7 files changed, 67 insertions, 52 deletions
diff --git a/http/http_connection.hpp b/http/http_connection.hpp index ae0477ab32..3720d9d355 100644 --- a/http/http_connection.hpp +++ b/http/http_connection.hpp @@ -16,6 +16,7 @@ #include <boost/beast/core/flat_static_buffer.hpp> #include <boost/beast/ssl/ssl_stream.hpp> #include <boost/beast/websocket.hpp> +#include <boost/url/url_view.hpp> #include <json_html_serializer.hpp> #include <security_headers.hpp> #include <ssl_key_handler.hpp> @@ -336,15 +337,18 @@ class Connection : << "." << thisReq.version() % 10 << ' ' << thisReq.methodString() << " " << thisReq.target() << " " << thisReq.ipAddress; - try - { - thisReq.urlView = boost::urls::url_view(thisReq.target()); - thisReq.url = thisReq.urlView.encoded_path(); - } - catch (std::exception& p) + + boost::urls::error_code ec; + req->urlView = boost::urls::parse_relative_ref( + boost::urls::string_view(req->target().data(), + req->target().size()), + ec); + if (ec) { - BMCWEB_LOG_ERROR << p.what(); + return; } + req->url = std::string_view(req->urlView.encoded_path().data(), + req->urlView.encoded_path().size()); res.setCompleteRequestHandler(nullptr); res.isAliveHelper = [this]() -> bool { return isAlive(); }; @@ -547,16 +551,21 @@ class Connection : boost::beast::http::verb method = parser->get().method(); readClientIp(); - try - { - req->urlView = - boost::urls::url_view(parser->get().target()); - req->url = req->urlView.encoded_path(); - } - catch (std::exception& p) + boost::urls::error_code uriEc; + boost::urls::string_view uriStringView( + parser->get().target().data(), + parser->get().target().size()); + BMCWEB_LOG_DEBUG << "Parsing URI: " << uriStringView; + req->urlView = + boost::urls::parse_relative_ref(uriStringView, uriEc); + if (uriEc) { - BMCWEB_LOG_ERROR << p.what(); + BMCWEB_LOG_ERROR << "Failed to parse URI " + << uriEc.message(); + return; } + req->url = std::string_view(req->urlView.encoded_path().data(), + req->urlView.encoded_path().size()); boost::asio::ip::address ip; if (getClientIp(ip)) @@ -573,7 +582,7 @@ class Connection : startDeadline(loggedInAttempts); BMCWEB_LOG_DEBUG << "Starting slow deadline"; - req->urlParams = req->urlView.params(); + req->urlParams = req->urlView.query_params(); #ifdef BMCWEB_ENABLE_DEBUG std::string paramList = ""; diff --git a/http/http_request.hpp b/http/http_request.hpp index fecb9de3fb..da3d4e0047 100644 --- a/http/http_request.hpp +++ b/http/http_request.hpp @@ -22,7 +22,7 @@ struct Request boost::beast::http::fields& fields; std::string_view url{}; boost::urls::url_view urlView{}; - boost::urls::url_view::params_type urlParams{}; + boost::urls::query_params_view urlParams{}; bool isSecure{false}; const std::string& body; diff --git a/meson.build b/meson.build index 2bbc0d9dab..650a5ec688 100644 --- a/meson.build +++ b/meson.build @@ -151,6 +151,7 @@ add_project_arguments( '-Wswitch-enum', '-Wnull-dereference', '-Wdouble-promotion', + '-Wno-newline-eof', '-Wformat=2', ]), language:'cpp') @@ -363,7 +364,8 @@ endif srcfiles_bmcweb = [ 'src/webserver_main.cpp', 'redfish-core/src/error_messages.cpp', - 'redfish-core/src/utils/json_utils.cpp' + 'redfish-core/src/utils/json_utils.cpp', + 'src/boost_url.cpp' ] srcfiles_unittest = [ @@ -433,7 +435,9 @@ executable('bmcweb',srcfiles_bmcweb, if(get_option('tests').enabled()) foreach src_test : srcfiles_unittest testname = src_test.split('/')[-1].split('.')[0] - test(testname,executable(testname,src_test, + test(testname,executable(testname, + [src_test, + 'src/boost_url.cpp'], include_directories : incdir, install_dir: bindir, dependencies: [ 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 {}; diff --git a/src/boost_url.cpp b/src/boost_url.cpp new file mode 100644 index 0000000000..ce55e9b9c3 --- /dev/null +++ b/src/boost_url.cpp @@ -0,0 +1,2 @@ + +#include <boost/url/src.hpp>
\ No newline at end of file diff --git a/subprojects/boost-url.wrap b/subprojects/boost-url.wrap index c41d2d119e..3d00dcf8cc 100644 --- a/subprojects/boost-url.wrap +++ b/subprojects/boost-url.wrap @@ -1,3 +1,3 @@ [wrap-git] -revision = a56ae0df6d3078319755fbaa67822b4fa7fd352b +revision = 4f712ed69a04a344957d22efa5dc111b415b3aff url = https://github.com/CPPAlliance/url.git
\ No newline at end of file |