summaryrefslogtreecommitdiff
path: root/src/other_tools/utils
diff options
context:
space:
mode:
authorPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2023-11-06 15:40:56 +0100
committerPaul Cristian Sarbu <paul.cristian.sarbu@huawei.com>2023-11-14 13:35:01 +0100
commit8d656639aa07a9677a7c4c1ce8ce0a68287d99e5 (patch)
tree5406b7cab5a1bcb91a3a1cc12f4731fa6622f0cc /src/other_tools/utils
parent7b4bd58b07edc0b26cbe87121d55ef143a050490 (diff)
downloadjustbuild-8d656639aa07a9677a7c4c1ce8ce0a68287d99e5.tar.gz
curl_url_handle: Allow permissive parsing and URL extraction to be non-fatal
Diffstat (limited to 'src/other_tools/utils')
-rw-r--r--src/other_tools/utils/curl_url_handle.cpp12
-rw-r--r--src/other_tools/utils/curl_url_handle.hpp9
2 files changed, 13 insertions, 8 deletions
diff --git a/src/other_tools/utils/curl_url_handle.cpp b/src/other_tools/utils/curl_url_handle.cpp
index 95f04da1..90102e0b 100644
--- a/src/other_tools/utils/curl_url_handle.cpp
+++ b/src/other_tools/utils/curl_url_handle.cpp
@@ -189,7 +189,8 @@ auto CurlURLHandle::CreatePermissive(std::string const& url,
bool use_non_support_scheme,
bool use_no_authority,
bool use_path_as_is,
- bool use_allow_space) noexcept
+ bool use_allow_space,
+ bool ignore_fatal) noexcept
-> std::optional<CurlURLHandlePtr> {
try {
auto url_h = std::make_shared<CurlURLHandle>();
@@ -231,7 +232,7 @@ auto CurlURLHandle::CreatePermissive(std::string const& url,
url_h->handle_.reset(handle);
return std::make_optional<CurlURLHandlePtr>(url_h);
} catch (std::exception const& ex) {
- Logger::Log(LogLevel::Error,
+ Logger::Log(ignore_fatal ? LogLevel::Debug : LogLevel::Error,
"CurlURLHandle: creating permissive curl URL handle failed "
"unexpectedly with:\n{}",
ex.what());
@@ -255,7 +256,8 @@ auto CurlURLHandle::Duplicate() noexcept -> CurlURLHandlePtr {
auto CurlURLHandle::GetURL(bool use_default_port,
bool use_default_scheme,
- bool use_no_default_port) noexcept
+ bool use_no_default_port,
+ bool ignore_fatal) noexcept
-> std::optional<std::string> {
try {
// set up flags
@@ -274,7 +276,7 @@ auto CurlURLHandle::GetURL(bool use_default_port,
char* url = nullptr;
auto rc = curl_url_get(handle_.get(), CURLUPART_URL, &url, flags);
if (rc != CURLUE_OK) {
- Logger::Log(LogLevel::Error,
+ Logger::Log(ignore_fatal ? LogLevel::Debug : LogLevel::Error,
"CurlURLHandle: retrieving URL failed with:\n{}",
curl_url_strerror(rc));
return std::nullopt;
@@ -285,7 +287,7 @@ auto CurlURLHandle::GetURL(bool use_default_port,
return url_str;
} catch (std::exception const& ex) {
Logger::Log(
- LogLevel::Error,
+ ignore_fatal ? LogLevel::Debug : LogLevel::Error,
"CurlURLHandle: retrieving URL failed unexpectedly with:\n{}",
ex.what());
return std::nullopt;
diff --git a/src/other_tools/utils/curl_url_handle.hpp b/src/other_tools/utils/curl_url_handle.hpp
index dbb73baa..dfd278d7 100644
--- a/src/other_tools/utils/curl_url_handle.hpp
+++ b/src/other_tools/utils/curl_url_handle.hpp
@@ -100,6 +100,7 @@ class CurlURLHandle {
/// It allows the user to be very permissive with the types of URL strings
/// it can parse by providing configuration arguments that mirror those
/// provided by the libcurl API (see libcurl docs for effects of each flag).
+ /// \param [in] ignore_fatal Do not log failure if error or exception.
/// \returns Pointer to created object, nullptr on failure to parse with
/// given arguments, or nullopt on an unexpected exception.
[[nodiscard]] auto static CreatePermissive(
@@ -109,8 +110,8 @@ class CurlURLHandle {
bool use_non_support_scheme = false,
bool use_no_authority = false,
bool use_path_as_is = false,
- bool use_allow_space = false) noexcept
- -> std::optional<CurlURLHandlePtr>;
+ bool use_allow_space = false,
+ bool ignore_fatal = false) noexcept -> std::optional<CurlURLHandlePtr>;
/// \brief Creates a duplicate CurlURLHandle object.
/// \returns Pointer to duplicated object, or nullptr on errors.
@@ -118,10 +119,12 @@ class CurlURLHandle {
/// \brief Recomposes the URL from the fields in the stored handle.
/// Flags parallel the libcurl API for handling the scheme and port fields.
+ /// \param [in] ignore_fatal Do not log failure if error or exception.
/// \returns The recomposed URL as a string, or nullopt on errors.
[[nodiscard]] auto GetURL(bool use_default_port = false,
bool use_default_scheme = false,
- bool use_no_default_port = false) noexcept
+ bool use_no_default_port = false,
+ bool ignore_fatal = false) noexcept
-> std::optional<std::string>;
/// \brief Gets the parsed scheme field.