From 204cb7ec3f533796990c67c56de0815e45bb7b8c Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Mon, 25 Jan 2021 08:05:16 +0100 Subject: [PATCH 1/2] Fixed build with curl --- src/tl/tl/tlHttpStream.cc | 26 +++++++++++++++++++++++++- src/tl/tl/tlHttpStream.h | 6 +++--- src/tl/tl/tlHttpStreamQt.cc | 37 +++---------------------------------- 3 files changed, 31 insertions(+), 38 deletions(-) diff --git a/src/tl/tl/tlHttpStream.cc b/src/tl/tl/tlHttpStream.cc index e6900a432..04e18f74d 100644 --- a/src/tl/tl/tlHttpStream.cc +++ b/src/tl/tl/tlHttpStream.cc @@ -26,6 +26,30 @@ namespace tl { - // .. nothing yet .. +// --------------------------------------------------------------- +// HttpErrorException implementation + +std::string +HttpErrorException::format_error (const std::string &em, int ec, const std::string &url, const std::string &body) +{ + std::string msg = tl::sprintf (tl::to_string (tr ("Error %d: %s, fetching %s")), ec, em, url); + + if (! body.empty ()) { + + msg += "\n\n"; + msg += tl::to_string (tr ("Reply body:")); + msg += "\n"; + + if (body.size () > 1000) { + msg += std::string (body.c_str (), 1000); + msg += "..."; + } else { + msg += body; + } + + } + + return msg; +} } diff --git a/src/tl/tl/tlHttpStream.h b/src/tl/tl/tlHttpStream.h index cd2884657..30a8f8339 100644 --- a/src/tl/tl/tlHttpStream.h +++ b/src/tl/tl/tlHttpStream.h @@ -56,11 +56,11 @@ class TL_PUBLIC HttpErrorException : public tl::Exception { public: - HttpErrorException (const std::string &f, int ec, QNetworkReply *reply) - : tl::Exception (format_error (f, ec, reply)) + HttpErrorException (const std::string &f, int ec, const std::string &url, const std::string &body = std::string ()) + : tl::Exception (format_error (f, ec, url, body)) { } - static std::string format_error (const std::string &em, int ec, QNetworkReply *reply); + static std::string format_error (const std::string &em, int ec, const std::string &url, const std::string &body); }; class InputHttpStreamPrivateData; diff --git a/src/tl/tl/tlHttpStreamQt.cc b/src/tl/tl/tlHttpStreamQt.cc index e53b94f57..f31426767 100644 --- a/src/tl/tl/tlHttpStreamQt.cc +++ b/src/tl/tl/tlHttpStreamQt.cc @@ -123,39 +123,6 @@ AuthenticationHandler::proxyAuthenticationRequired (const QNetworkProxy &proxy, // --------------------------------------------------------------- // InputHttpStream implementation -std::string -HttpErrorException::format_error (const std::string &em, int ec, QNetworkReply *reply) -{ - std::string msg = tl::sprintf (tl::to_string (tr ("Error %d: %s, fetching %s")), ec, em, tl::to_string (reply->url ().toString ())); - - std::string data = tl::to_string (QString::fromUtf8 (reply->readAll ())); - if (data.size () > 1000) { - data = data.substr (0, size_t (1000)) + "..."; - } - - if (! data.empty ()) { - - msg += "\n\n"; - msg += tl::to_string (tr ("Reply body:")); - msg += "\n"; - msg += data; - - } - - std::string redirected = tl::to_string (reply->attribute (QNetworkRequest::RedirectionTargetAttribute).toString ()); - if (! redirected.empty ()) { - - msg += "\n\n"; - msg += tl::to_string (tr ("Redirected to: ")) + redirected; - - } - - return msg; -} - -// --------------------------------------------------------------- -// InputHttpStream implementation - InputHttpStream::InputHttpStream (const std::string &url) { mp_data = new InputHttpStreamPrivateData (url); @@ -482,7 +449,9 @@ InputHttpStreamPrivateData::read (char *b, size_t n) ec = int (mp_reply->error ()); } - throw HttpErrorException (em, ec, mp_reply); + QByteArray data = mp_reply->readAll (); + + throw HttpErrorException (em, ec, tl::to_string (mp_reply->url ().toString ()), tl::to_string (data.constData (), (int)data.size ())); } From 885c52eeebfc5b6bcf7a46fe9a278976db695bcd Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Mon, 25 Jan 2021 08:10:28 +0100 Subject: [PATCH 2/2] Stupid bug fixed --- src/db/db/dbColdProxy.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/db/db/dbColdProxy.cc b/src/db/db/dbColdProxy.cc index b1a70549d..363694380 100644 --- a/src/db/db/dbColdProxy.cc +++ b/src/db/db/dbColdProxy.cc @@ -55,7 +55,7 @@ ColdProxy::ColdProxy (db::cell_index_type ci, db::Layout &layout, const ProxyCon if (! info.lib_name.empty ()) { tl::MutexLocker locker (&s_map_mutex); std::map *>::iterator i = s_proxies_per_library_name.find (info.lib_name); - if (i != s_proxies_per_library_name.end ()) { + if (i == s_proxies_per_library_name.end ()) { i = s_proxies_per_library_name.insert (std::make_pair (info.lib_name, new tl::weak_collection ())).first; } i->second->push_back (this);