Ref T32, utility functions for URL/URL list

* keep error messages of failed URLs
* append query
This commit is contained in:
Klaus Basan
2017-04-21 03:11:00 +02:00
parent cbe3122c40
commit 88ef2ee019
4 changed files with 26 additions and 12 deletions

View File

@@ -96,17 +96,16 @@ namespace BlackMisc
{
const QString q(stripQueryString(queryToAppend));
if (q.isEmpty()) { return m_query; }
if (!hasQuery())
{
this->setQuery(q);
}
else
{
m_query = m_query + "&" + q;
}
m_query += hasQuery() ? "&" + q : q;
return m_query;
}
QString CUrl::appendQuery(const QString &key, const QString &value)
{
if (key.isEmpty()) { return m_query; }
return this->appendQuery(key + "=" + value);
}
QString CUrl::getFullUrl(bool withQuery) const
{
if (m_host.isEmpty()) { return ""; }

View File

@@ -106,6 +106,9 @@ namespace BlackMisc
//! Append query
QString appendQuery(const QString &queryToAppend);
//! Append query
QString appendQuery(const QString &key, const QString &value);
//! Empty
bool isEmpty() const;

View File

@@ -147,8 +147,16 @@ namespace BlackMisc
if (!failedUrl.isEmpty()) { this->addFailedUrl(failedUrl); }
if (!hasMoreUrlsToTry()) { return CUrl(); }
const CUrl url(this->obtainNextUrlWithout(random, this->m_failedUrls));
if (CNetworkUtils::canConnect(url)) { return url; }
if (addFailedUrl(url)) { return obtainNextWorkingUrl(); }
QString msg;
if (CNetworkUtils::canConnect(url, msg)) { return url; }
if (addFailedUrl(url))
{
if (!msg.isEmpty())
{
this->m_errorMsgs.append(QString("URL: %1 error: ").arg(url.toQString(), msg));
}
return obtainNextWorkingUrl();
}
return CUrl();
}

View File

@@ -102,13 +102,17 @@ namespace BlackMisc
//! Next working URL, test if it can be connected
CUrl obtainNextWorkingUrl( bool random = false, const CUrl &failedUrl = CUrl());
//! Get the error messages
const QStringList &getErrorMessages() const { return m_errorMsgs; }
//! Reset failed URL, allows to set an optional new number of max.trials
void reset(int maxTrials = -1);
private:
int m_currentIndexDistributedLoad = -1; //!< index for random access
int m_maxTrials = 2; //!< number of max trials
CUrlList m_failedUrls;
int m_maxTrials = 2; //!< number of max trials
CUrlList m_failedUrls; //!< failed tested URLs
QStringList m_errorMsgs; //!< error messages while testing;
};
} //namespace