X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=src%2FUpdateChecker.cpp;h=467ab178a432697c2c76930ef1db03f2b1fbe238;hb=094d203774862cca1ecd401c2baef078f92a48bf;hp=ca3cfa9cbc53d21e2ccc2c8df33c774145e988cc;hpb=62471a93e888a8413fe495a8f5c1d9b0c55f9562;p=mutilities%2FMUtilities.git diff --git a/src/UpdateChecker.cpp b/src/UpdateChecker.cpp index ca3cfa9..467ab17 100644 --- a/src/UpdateChecker.cpp +++ b/src/UpdateChecker.cpp @@ -32,6 +32,7 @@ #include #include #include +#include using namespace MUtils; @@ -53,7 +54,7 @@ static const char *update_mirrors[] = "http://muldersoft.com/", "http://mulder.bplaced.net/", "http://mulder.6te.net/", - "http://mulder.webuda.com/", + "http://mulder.000webhostapp.com/", //"http://mulder.webuda.com/", "http://mulder.pe.hu/", "http://muldersoft.square7.ch/", "http://muldersoft.co.nf/", @@ -94,7 +95,6 @@ static const char *known_hosts[] = //Taken form: http://www.alexa.com/topsites "www.bing.com", "www.bingeandgrab.com", "www.bucketheadpikes.com", - "www.buckethead-coop.com", "www.buzzfeed.com", "www.cam.ac.uk", "www.ccc.de", @@ -108,6 +108,7 @@ static const char *known_hosts[] = //Taken form: http://www.alexa.com/topsites "www.der-postillon.com", "www.ebay.com", "www.equation.com", + "www.ethz.ch", "www.farbrausch.de", "fc2.com", "fedoraproject.org", @@ -165,6 +166,7 @@ static const char *known_hosts[] = //Taken form: http://www.alexa.com/topsites "www.nytimes.com", "www.opera.com", "www.oxford.gov.uk", + "www.ox-fanzine.de", "www.partha.com", "pastebin.com", "pastie.org", @@ -175,6 +177,7 @@ static const char *known_hosts[] = //Taken form: http://www.alexa.com/topsites "www.qt.io", "www.quakelive.com", "rationalqm.us", + "www.reddit.com", "www.rwth-aachen.de", "www.seamonkey-project.org", "selfhtml.org", @@ -192,7 +195,15 @@ static const char *known_hosts[] = //Taken form: http://www.alexa.com/topsites "www.tdrsmusic.com", "tu-dresden.de", "www.ubuntu.com", + "portal.uned.es", + "www.unibuc.ro", + "www.uniroma1.it", + "www.univ-paris1.fr", + "www.univer.kharkov.ua", + "www.univie.ac.at", "www.uol.com.br", + "www.uva.nl", + "www.uw.edu.pl", "www.videohelp.com", "www.videolan.org", "virtualdub.org", @@ -224,9 +235,9 @@ static char *USER_AGENT_STR = "Mozilla/5.0 (X11; Linux i686; rv:10.0) Gecko/2010 #define CHECK_CANCELLED() do \ { \ - if(m_cancelled) \ + if(MUTILS_BOOLIFY(m_cancelled)) \ { \ - m_success = false; \ + m_success.fetchAndStoreOrdered(0); \ log("", "Update check has been cancelled by user!"); \ setProgress(m_maxProgress); \ setStatus(UpdateStatus_CancelledByUser); \ @@ -298,11 +309,11 @@ bool UpdateCheckerInfo::isComplete(void) // Constructor & Destructor //////////////////////////////////////////////////////////// -UpdateChecker::UpdateChecker(const QString &binWGet, const QString &binNC, const QString &binGnuPG, const QString &binKeys, const QString &applicationId, const quint32 &installedBuildNo, const bool betaUpdates, const bool testMode) +UpdateChecker::UpdateChecker(const QString &binWGet, const QString &binMCat, const QString &binGnuPG, const QString &binKeys, const QString &applicationId, const quint32 &installedBuildNo, const bool betaUpdates, const bool testMode) : m_updateInfo(new UpdateCheckerInfo()), m_binaryWGet(binWGet), - m_binaryNC(binNC), + m_binaryMCat(binMCat), m_binaryGnuPG(binGnuPG), m_binaryKeys(binKeys), m_applicationId(applicationId), @@ -311,7 +322,6 @@ UpdateChecker::UpdateChecker(const QString &binWGet, const QString &binNC, const m_testMode(testMode), m_maxProgress(getMaxProgress()) { - m_success = m_cancelled = false; m_status = UpdateStatus_NotStartedYet; m_progress = 0; @@ -331,7 +341,8 @@ UpdateChecker::~UpdateChecker(void) void UpdateChecker::start(Priority priority) { - m_cancelled = m_success = false; + m_success.fetchAndStoreOrdered(0); + m_cancelled.fetchAndStoreOrdered(0); QThread::start(priority); } @@ -425,7 +436,7 @@ endLoop: const bool isQuick = (mirrorCount++ < QUICK_MIRRORS); if(tryUpdateMirror(m_updateInfo.data(), currentMirror, isQuick)) { - m_success = true; /*success*/ + m_success.ref(); /*success*/ break; } if (isQuick) @@ -445,7 +456,7 @@ endLoop: // ----- Generate final result ----- // - if(m_success) + if(MUTILS_BOOLIFY(m_success)) { if(m_updateInfo->m_buildNo > m_installedBuildNo) { @@ -477,13 +488,25 @@ void UpdateChecker::testKnownHosts(void) qDebug("\n[Known Hosts]"); log("Testing all known hosts...", "", "---"); - int hostCount = hostList.count(); + QSet ipAddrSet; + quint32 ipAddr; while(!hostList.isEmpty()) { - QString currentHost = hostList.takeFirst(); + const QString currentHost = hostList.takeFirst(); qDebug("Testing: %s", currentHost.toLatin1().constData()); log("", "Testing:", currentHost, ""); - if (!tryContactHost(currentHost, DOWNLOAD_TIMEOUT)) + if (tryContactHost(currentHost, DOWNLOAD_TIMEOUT, &ipAddr)) + { + if (ipAddrSet.contains(ipAddr)) + { + qWarning("Duplicate IP-address 0x%08X was encountered!", ipAddr); + } + else + { + ipAddrSet << ipAddr; /*not encountered yet*/ + } + } + else { qWarning("\nConnectivity test FAILED on the following host:\n%s\n", currentHost.toLatin1().constData()); } @@ -541,7 +564,7 @@ bool UpdateChecker::tryUpdateMirror(UpdateCheckerInfo *updateInfo, const QString log("", "Download okay, checking signature:"); if (checkSignature(outFileVers, outFileSign)) { - log("", "Signature okay, parsing info:"); + log("", "Signature okay, parsing info:", ""); success = parseVersionInfo(outFileVers, updateInfo); } else @@ -562,19 +585,19 @@ bool UpdateChecker::tryUpdateMirror(UpdateCheckerInfo *updateInfo, const QString bool UpdateChecker::getUpdateInfo(const QString &url, const QString &outFileVers, const QString &outFileSign) { - log("Downloading update info:"); - if(!getFile(QString("%1%2" ).arg(url, mirror_url_postfix[m_betaUpdates ? 1 : 0]), outFileVers)) + log("Downloading update info:", ""); + if(getFile(QString("%1%2").arg(url, mirror_url_postfix[m_betaUpdates ? 1 : 0]), outFileVers)) { - return false; - } - - log("", "Downloading signature:"); - if(!getFile(QString("%1%2.sig2").arg(url, mirror_url_postfix[m_betaUpdates ? 1 : 0]), outFileSign)) - { - return false; + if (!m_cancelled) + { + log("", "Downloading signature:", ""); + if (getFile(QString("%1%2.sig2").arg(url, mirror_url_postfix[m_betaUpdates ? 1 : 0]), outFileSign)) + { + return true; + } + } } - - return true; + return false; } bool UpdateChecker::parseVersionInfo(const QString &file, UpdateCheckerInfo *updateInfo) @@ -692,6 +715,10 @@ bool UpdateChecker::getFile(const QString &url, const QString &outFile, const un { return true; } + if (MUTILS_BOOLIFY(m_cancelled)) + { + break; /*cancelled*/ + } } return false; } @@ -753,7 +780,7 @@ bool UpdateChecker::getFile(const QString &url, const bool forceIp4, const QStri const QString line = QString::fromLatin1(process.readLine()).simplified(); log(line); } - if (bTimeOut || m_cancelled) + if (bTimeOut || MUTILS_BOOLIFY(m_cancelled)) { qWarning("WGet process timed out <-- killing!"); process.kill(); @@ -770,15 +797,15 @@ bool UpdateChecker::getFile(const QString &url, const bool forceIp4, const QStri return (process.exitCode() == 0) && output.exists() && output.isFile(); } -bool UpdateChecker::tryContactHost(const QString &hostname, const int &timeoutMsec) +bool UpdateChecker::tryContactHost(const QString &hostname, const int &timeoutMsec, quint32 *const ipAddrOut) { - log(QString("Connecting to host: %1").arg(hostname)); + log(QString("Connecting to host: %1").arg(hostname), ""); QProcess process; init_process(process, temp_folder()); QStringList args; - args << "-z" << hostname << QString::number(80); + args << "--retry" << QString::number(3) << hostname << QString::number(80); QEventLoop loop; connect(&process, SIGNAL(error(QProcess::ProcessError)), &loop, SLOT(quit())); @@ -789,7 +816,14 @@ bool UpdateChecker::tryContactHost(const QString &hostname, const int &timeoutMs timer.setSingleShot(true); connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit())); - process.start(m_binaryNC, args); + QScopedPointer ipAddr; + if (ipAddrOut) + { + *ipAddrOut = 0; + ipAddr.reset(new QRegExp("Connecting\\s+to\\s+(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+):(\\d+)", Qt::CaseInsensitive)); + } + + process.start(m_binaryMCat, args); if (!process.waitForStarted()) { @@ -804,12 +838,26 @@ bool UpdateChecker::tryContactHost(const QString &hostname, const int &timeoutMs const bool bTimeOut = (!timer.isActive()); while (process.canReadLine()) { - QString line = QString::fromLatin1(process.readLine()).simplified(); + const QString line = QString::fromLatin1(process.readLine()).simplified(); + if (!ipAddr.isNull()) + { + if (ipAddr->indexIn(line) >= 0) + { + quint32 values[4]; + if (MUtils::regexp_parse_uint32((*ipAddr), values, 4)) + { + *ipAddrOut |= ((values[0] & 0xFF) << 0x18); + *ipAddrOut |= ((values[1] & 0xFF) << 0x10); + *ipAddrOut |= ((values[2] & 0xFF) << 0x08); + *ipAddrOut |= ((values[3] & 0xFF) << 0x00); + } + } + } log(line); } - if (bTimeOut || m_cancelled) + if (bTimeOut || MUTILS_BOOLIFY(m_cancelled)) { - qWarning("NC process timed out <-- killing!"); + qWarning("MCat process timed out <-- killing!"); process.kill(); process.waitForFinished(); log(bTimeOut ? "!!! TIMEOUT !!!" : "!!! CANCELLED !!!");