diff --git a/src/blackcore/setupreader.cpp b/src/blackcore/setupreader.cpp index 4a2e46528..ea5b1b75e 100644 --- a/src/blackcore/setupreader.cpp +++ b/src/blackcore/setupreader.cpp @@ -387,6 +387,7 @@ namespace BlackCore // try next one if any if (this->m_bootstrapUrls.addFailedUrl(url)) { + m_distributionUrls.addFailedHost(url); // the same host will likely fail for distributions QTimer::singleShot(500, this, &CSetupReader::ps_readSetup); } else diff --git a/src/blackmisc/network/urllist.cpp b/src/blackmisc/network/urllist.cpp index b94685da5..6cf14f584 100644 --- a/src/blackmisc/network/urllist.cpp +++ b/src/blackmisc/network/urllist.cpp @@ -8,8 +8,9 @@ */ #include "blackmisc/network/urllist.h" -#include "blackmisc/math/mathutils.h" #include "blackmisc/network/networkutils.h" +#include "blackmisc/math/mathutils.h" +#include "blackmisc/stringutils.h" #include #include @@ -68,7 +69,7 @@ namespace BlackMisc return copy.getRandomUrl(); } - CUrlList CUrlList::appendPath(const QString &path) const + CUrlList CUrlList::withAppendedPath(const QString &path) const { if (path.isEmpty() || this->isEmpty()) { return (*this); } CUrlList urls; @@ -79,6 +80,20 @@ namespace BlackMisc return urls; } + CUrlList CUrlList::findByHost(const QString &host, Qt::CaseSensitivity cs) const + { + CUrlList result; + if (host.isEmpty() || this->isEmpty()) { return result; } + for (const CUrl &url : *this) + { + if (stringCompare(url.getHost(), host, cs)) + { + result.push_back(url); + } + } + return result; + } + QString CUrlList::convertToQString(const QString &separator, bool i18n) const { const QStringList sl(toStringList(i18n)); @@ -136,6 +151,26 @@ namespace BlackMisc return hasMoreUrlsToTry(); } + bool CFailoverUrlList::addFailedUrls(const CUrlList &failedUrls) + { + this->m_failedUrls.push_back(failedUrls); + return hasMoreUrlsToTry(); + } + + bool CFailoverUrlList::addFailedHost(const CUrl &failedUrl) + { + Q_ASSERT_X(!failedUrl.isEmpty(), Q_FUNC_INFO, "empty URL as failed"); + const QString host = failedUrl.getHost(); + return CFailoverUrlList::addFailedHost(host); + } + + bool CFailoverUrlList::addFailedHost(const QString &host, Qt::CaseSensitivity cs) + { + if (host.isEmpty()) { return this->hasMoreUrlsToTry(); } + const CUrlList failedUrls = this->findByHost(host, cs); + return addFailedUrls(failedUrls); + } + bool CFailoverUrlList::hasMoreUrlsToTry() const { if (this->isEmpty()) { return false; } diff --git a/src/blackmisc/network/urllist.h b/src/blackmisc/network/urllist.h index 2a4bf4e6c..4ce6e4175 100644 --- a/src/blackmisc/network/urllist.h +++ b/src/blackmisc/network/urllist.h @@ -53,7 +53,10 @@ namespace BlackMisc CUrl getRandomWithout(const CUrlList &exclude) const; //! Append path to all URLs - CUrlList appendPath(const QString &path) const; + CUrlList withAppendedPath(const QString &path) const; + + //! Find by host + CUrlList findByHost(const QString &host, Qt::CaseSensitivity cs = Qt::CaseInsensitive) const; //! To formatted String QString convertToQString(const QString &separator, bool i18n = false) const; @@ -90,6 +93,15 @@ namespace BlackMisc //! Failed URL bool addFailedUrl(const CUrl &failedUrl); + //! Failed URLs + bool addFailedUrls(const CUrlList &failedUrls); + + //! Failed host + bool addFailedHost(const CUrl &failedUrl); + + //! Failed host + bool addFailedHost(const QString &host, Qt::CaseSensitivity cs = Qt::CaseInsensitive); + //! More URLs to try bool hasMoreUrlsToTry() const; diff --git a/src/blackmisc/stringutils.cpp b/src/blackmisc/stringutils.cpp index 281f83b21..3c7c29383 100644 --- a/src/blackmisc/stringutils.cpp +++ b/src/blackmisc/stringutils.cpp @@ -290,6 +290,12 @@ namespace BlackMisc { return input.replace('.', QLocale::system().decimalPoint()); } + + bool stringCompare(const QString &c1, const QString &c2, Qt::CaseSensitivity cs) + { + if (cs == Qt::CaseSensitive) { return c1 == c2; } + return caseInsensitiveStringCompare(c1, c2); + } } //! \endcond diff --git a/src/blackmisc/stringutils.h b/src/blackmisc/stringutils.h index f645179cb..d2c96ed91 100644 --- a/src/blackmisc/stringutils.h +++ b/src/blackmisc/stringutils.h @@ -160,6 +160,9 @@ namespace BlackMisc //! Case insensitive string compare BLACKMISC_EXPORT bool caseInsensitiveStringCompare(const QString &c1, const QString &c2); + //! String compare + BLACKMISC_EXPORT bool stringCompare(const QString &c1, const QString &c2, Qt::CaseSensitivity cs); + //! Get a simplified upper case name for searching by removing all characters except A-Z BLACKMISC_EXPORT QString simplifyNameForSearch(const QString &name);