OSDN Git Service

Small fix.
[mutilities/MUtilities.git] / src / UpdateChecker.cpp
index 467ab17..a044da2 100644 (file)
@@ -1,6 +1,6 @@
 ///////////////////////////////////////////////////////////////////////////////
 // MuldeR's Utilities for Qt
-// Copyright (C) 2004-2017 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2018 LoRd_MuldeR <MuldeR2@GMX.de>
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 #include <QStringList>
 #include <QFile>
 #include <QFileInfo>
+#include <QDir>
 #include <QProcess>
 #include <QUrl>
 #include <QEventLoop>
 #include <QTimer>
 #include <QElapsedTimer>
 #include <QSet>
+#include <QHash>
 
-using namespace MUtils;
+#include "Mirrors.h"
 
 ///////////////////////////////////////////////////////////////////////////////
 // CONSTANTS
@@ -49,189 +51,13 @@ static const char *mirror_url_postfix[] =
        NULL
 };
 
-static const char *update_mirrors[] =
-{
-       "http://muldersoft.com/",
-       "http://mulder.bplaced.net/",
-       "http://mulder.6te.net/",
-       "http://mulder.000webhostapp.com/",     //"http://mulder.webuda.com/",
-       "http://mulder.pe.hu/",
-       "http://muldersoft.square7.ch/",
-       "http://muldersoft.co.nf/",
-       "http://muldersoft.eu.pn/",
-       "http://muldersoft.lima-city.de/",
-       "http://www.muldersoft.keepfree.de/",
-       "http://lamexp.sourceforge.net/",
-       "http://lordmulder.github.io/LameXP/",
-       "http://muldersoft.bitbucket.io/",      //http://lord_mulder.bitbucket.org/
-       "http://www.tricksoft.de/",
-       "http://repo.or.cz/LameXP.git/blob_plain/gh-pages:/",
-       "http://gitlab.com/lamexp/lamexp/raw/gh-pages/",
-       NULL
-};
-
-static const char *known_hosts[] =             //Taken form: http://www.alexa.com/topsites !!!
-{
-       "www.163.com",
-       "www.7-zip.org",
-       "www.ac3filter.net",
-       "clbianco.altervista.org",
-       "status.aws.amazon.com",
-       "build.antergos.com",
-       "www.aol.com",
-       "www.apache.org",
-       "www.apple.com",
-       "www.adobe.com",
-       "archive.org",
-       "www.artlebedev.ru",
-       "web.audacityteam.org",
-       "status.automattic.com",
-       "www.avidemux.org",
-       "www.babylon.com",
-       "www.baidu.com",
-       "bandcamp.com",
-       "www.bbc.co.uk",
-       "www.berlios.de",
-       "www.bing.com",
-       "www.bingeandgrab.com",
-       "www.bucketheadpikes.com",
-       "www.buzzfeed.com",
-       "www.cam.ac.uk",
-       "www.ccc.de",
-       "home.cern",
-       "www.citizeninsomniac.com",
-       "www.cnet.com",
-       "cnzz.com",
-       "www.cuhk.edu.hk",
-       "www.codeplex.com",
-       "www.codeproject.com",
-       "www.der-postillon.com",
-       "www.ebay.com",
-       "www.equation.com",
-       "www.ethz.ch",
-       "www.farbrausch.de",
-       "fc2.com",
-       "fedoraproject.org",
-       "blog.fefe.de",
-       "www.ffmpeg.org",
-       "blog.flickr.net",
-       "www.fraunhofer.de",
-       "free-codecs.com",
-       "git-scm.com",
-       "doc.gitlab.com",
-       "www.gmx.net",
-       "news.gnome.org",
-       "www.gnu.org",
-       "go.com",
-       "code.google.com",
-       "haali.su",
-       "www.harvard.edu",
-       "www.heise.de",
-       "www.helmholtz.de",
-       "www.huffingtonpost.co.uk",
-       "www.hu-berlin.de",
-       "www.iana.org",
-       "www.imdb.com",
-       "www.imgburn.com",
-       "imgur.com",
-       "www.iuj.ac.jp",
-       "www.jd.com",
-       "www.jiscdigitalmedia.ac.uk",
-       "kannmanumdieuhrzeitschonnbierchentrinken.de",
-       "mirrors.kernel.org",
-       "komisar.gin.by",
-       "lame.sourceforge.net",
-       "www.libav.org",
-       "blog.linkedin.com",
-       "www.linuxmint.com",
-       "www.livedoor.com",
-       "www.livejournal.com",
-       "longplayer.org",
-       "go.mail.ru",
-       "marknelson.us",
-       "www.mediafire.com",
-       "web.mit.edu",
-       "www.mod-technologies.com",
-       "ftp.mozilla.org",
-       "www.mpg.de",
-       "mplayerhq.hu",
-       "www.msn.com",
-       "wiki.multimedia.cx",
-       "www.nch.com.au",
-       "neocities.org",
-       "mirror.netcologne.de",
-       "oss.netfarm.it",
-       "blog.netflix.com",
-       "netrenderer.de",
-       "www.nytimes.com",
-       "www.opera.com",
-       "www.oxford.gov.uk",
-       "www.ox-fanzine.de",
-       "www.partha.com",
-       "pastebin.com",
-       "pastie.org",
-       "portableapps.com",
-       "www.portablefreeware.com",
-       "support.proboards.com",
-       "www.qq.com",
-       "www.qt.io",
-       "www.quakelive.com",
-       "rationalqm.us",
-       "www.reddit.com",
-       "www.rwth-aachen.de",
-       "www.seamonkey-project.org",
-       "selfhtml.org",
-       "www.sina.com.cn",
-       "www.sohu.com",
-       "help.sogou.com",
-       "sourceforge.net",
-       "www.spiegel.de",
-       "www.sputnikmusic.com",
-       "stackoverflow.com",
-       "www.stanford.edu",
-       "www.t-online.de",
-       "www.tagesschau.de",
-       "tdm-gcc.tdragon.net",
-       "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",
-       "blog.virustotal.com",
-       "www.vkgoeswild.com",
-       "www.warr.org",
-       "www.weibo.com",
-       "status.wikimedia.org",
-       "www.winamp.com",
-       "www.winhoros.de",
-       "wpde.org",
-       "x265.org",
-       "xhmikosr.1f0.de",
-       "xiph.org",
-       "us.mail.yahoo.com",
-       "www.youtube.com",
-       "www.zedo.com",
-       "ffmpeg.zeranoe.com",
-       NULL
-};
-
 static const int MIN_CONNSCORE = 5;
 static const int QUICK_MIRRORS = 3;
-static const int MAX_CONN_TIMEOUT =  8000;
+static const int MAX_CONN_TIMEOUT = 16000;
 static const int DOWNLOAD_TIMEOUT = 30000;
 
 static const int VERSION_INFO_EXPIRES_MONTHS = 6;
-static char *USER_AGENT_STR = "Mozilla/5.0 (X11; Linux i686; rv:10.0) Gecko/20100101 Firefox/10.0"; /*use something innocuous*/
+static char *USER_AGENT_STR = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Firefox/52.0"; /*use something innocuous*/
 
 #define CHECK_CANCELLED() do \
 { \
@@ -266,22 +92,29 @@ static QStringList buildRandomList(const char *const values[])
        QStringList list;
        for (int index = 0; values[index]; index++)
        {
-               const int pos = next_rand_u32() % (index + 1);
+               const int pos = MUtils::next_rand_u32() % (index + 1);
                list.insert(pos, QString::fromLatin1(values[index]));
        }
        return list;
 }
 
+static const QHash<QString, QString> *initEnvVars(void)
+{
+       QHash<QString, QString> *const environment = new QHash<QString, QString>();
+       environment->insert(QLatin1String("CURL_HOME"), QDir::toNativeSeparators(MUtils::temp_folder()));
+       return environment;
+}
+
 ////////////////////////////////////////////////////////////
 // Update Info Class
 ////////////////////////////////////////////////////////////
 
-UpdateCheckerInfo::UpdateCheckerInfo(void)
+MUtils::UpdateCheckerInfo::UpdateCheckerInfo(void)
 {
        resetInfo();
 }
        
-void UpdateCheckerInfo::resetInfo(void)
+void MUtils::UpdateCheckerInfo::resetInfo(void)
 {
        m_buildNo = 0;
        m_buildDate.setDate(1900, 1, 1);
@@ -292,7 +125,7 @@ void UpdateCheckerInfo::resetInfo(void)
        m_downloadChecksum.clear();
 }
 
-bool UpdateCheckerInfo::isComplete(void)
+bool MUtils::UpdateCheckerInfo::isComplete(void)
 {
        if(this->m_buildNo < 1)                return false;
        if(this->m_buildDate.year() < 2010)    return false;
@@ -309,29 +142,29 @@ bool UpdateCheckerInfo::isComplete(void)
 // Constructor & Destructor
 ////////////////////////////////////////////////////////////
 
-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)
+MUtils::UpdateChecker::UpdateChecker(const QString &binCurl, 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_binaryMCat(binMCat),
+       m_binaryCurl(binCurl),
        m_binaryGnuPG(binGnuPG),
        m_binaryKeys(binKeys),
        m_applicationId(applicationId),
        m_installedBuildNo(installedBuildNo),
        m_betaUpdates(betaUpdates),
        m_testMode(testMode),
-       m_maxProgress(getMaxProgress())
+       m_maxProgress(getMaxProgress()),
+       m_environment(initEnvVars())
 {
        m_status = UpdateStatus_NotStartedYet;
        m_progress = 0;
 
-       if(m_binaryWGet.isEmpty() || m_binaryGnuPG.isEmpty() || m_binaryKeys.isEmpty())
+       if(m_binaryCurl.isEmpty() || m_binaryGnuPG.isEmpty() || m_binaryKeys.isEmpty())
        {
                MUTILS_THROW("Tools not initialized correctly!");
        }
 }
 
-UpdateChecker::~UpdateChecker(void)
+MUtils::UpdateChecker::~UpdateChecker(void)
 {
 }
 
@@ -339,7 +172,7 @@ UpdateChecker::~UpdateChecker(void)
 // Public slots
 ////////////////////////////////////////////////////////////
 
-void UpdateChecker::start(Priority priority)
+void MUtils::UpdateChecker::start(Priority priority)
 {
        m_success.fetchAndStoreOrdered(0);
        m_cancelled.fetchAndStoreOrdered(0);
@@ -350,14 +183,14 @@ void UpdateChecker::start(Priority priority)
 // Protected functions
 ////////////////////////////////////////////////////////////
 
-void UpdateChecker::run(void)
+void MUtils::UpdateChecker::run(void)
 {
        qDebug("Update checker thread started!");
-       MUTILS_EXCEPTION_HANDLER(m_testMode ? testKnownHosts() : checkForUpdates());
+       MUTILS_EXCEPTION_HANDLER(m_testMode ? testMirrorsList() : checkForUpdates());
        qDebug("Update checker thread completed.");
 }
 
-void UpdateChecker::checkForUpdates(void)
+void MUtils::UpdateChecker::checkForUpdates(void)
 {
        // ----- Initialization ----- //
 
@@ -366,18 +199,22 @@ void UpdateChecker::checkForUpdates(void)
 
        // ----- Test Internet Connection ----- //
 
-       log("Checking internet connection...", "");
+       log("Checking your Internet connection...", "");
        setStatus(UpdateStatus_CheckingConnection);
 
        const int networkStatus = OS::network_status();
        if(networkStatus == OS::NETWORK_TYPE_NON)
        {
-               log("Operating system reports that the computer is currently offline !!!");
-               setProgress(m_maxProgress);
-               setStatus(UpdateStatus_ErrorNoConnection);
-               return;
+               if (!MUtils::OS::arguments().contains("ignore-network-status"))
+               {
+                       log("Operating system reports that the computer is currently offline !!!");
+                       setProgress(m_maxProgress);
+                       setStatus(UpdateStatus_ErrorNoConnection);
+                       return;
+               }
        }
        
+       msleep(500);
        setProgress(1);
 
        // ----- Test Known Hosts Connectivity ----- //
@@ -385,7 +222,7 @@ void UpdateChecker::checkForUpdates(void)
        int connectionScore = 0;
        QStringList mirrorList = buildRandomList(known_hosts);
 
-       for(int connectionTimout = 250; connectionTimout <= MAX_CONN_TIMEOUT; connectionTimout *= 2)
+       for(int connectionTimout = 1000; connectionTimout <= MAX_CONN_TIMEOUT; connectionTimout *= 2)
        {
                QElapsedTimer elapsedTimer;
                elapsedTimer.start();
@@ -423,7 +260,7 @@ endLoop:
 
        // ----- Fetch Update Info From Server ----- //
 
-       log("----", "", "Checking for updates online...");
+       log("----", "", "Internet connection is operational, checking for updates online...");
        setStatus(UpdateStatus_FetchingUpdates);
 
        int mirrorCount = 0;
@@ -477,38 +314,61 @@ endLoop:
        }
 }
 
-void UpdateChecker::testKnownHosts(void)
+void MUtils::UpdateChecker::testMirrorsList(void)
 {
-       QStringList hostList;
-       for(int i = 0; known_hosts[i]; i++)
+       // ----- Test update mirrors ----- //
+
+       QStringList mirrorList;
+       for(int i = 0; update_mirrors[i]; i++)
        {
-               hostList << QString::fromLatin1(known_hosts[i]);
+               mirrorList << QString::fromLatin1(update_mirrors[i]);
        }
 
-       qDebug("\n[Known Hosts]");
-       log("Testing all known hosts...", "", "---");
+       qDebug("\n[Mirror Sites]");
+       log("Testing all known mirror sites...", "", "---");
 
-       QSet<quint32> ipAddrSet;
-       quint32 ipAddr;
-       while(!hostList.isEmpty())
+       UpdateCheckerInfo updateInfo;
+       while (!mirrorList.isEmpty())
        {
-               const QString currentHost = hostList.takeFirst();
-               qDebug("Testing: %s", currentHost.toLatin1().constData());
-               log("", "Testing:", currentHost, "");
-               if (tryContactHost(currentHost, DOWNLOAD_TIMEOUT, &ipAddr))
+               const QString currentMirror = mirrorList.takeFirst();
+               bool success = false;
+               qDebug("Testing: %s", MUTILS_L1STR(currentMirror));
+               log("", "Testing:", currentMirror, "");
+               for (quint8 attempt = 0; attempt < 3; ++attempt)
                {
-                       if (ipAddrSet.contains(ipAddr))
+                       updateInfo.resetInfo();
+                       if (tryUpdateMirror(&updateInfo, currentMirror, (!attempt)))
                        {
-                               qWarning("Duplicate IP-address 0x%08X was encountered!", ipAddr);
-                       }
-                       else
-                       {
-                               ipAddrSet << ipAddr; /*not encountered yet*/
+                               success = true;
+                               break;
                        }
                }
-               else
+               if (!success)
+               {
+                       qWarning("\nUpdate mirror seems to be unavailable:\n%s\n", MUTILS_L1STR(currentMirror));
+               }
+               log("", "---");
+       }
+
+       // ----- Test known hosts ----- //
+
+       QStringList knownHostList;
+       for (int i = 0; known_hosts[i]; i++)
+       {
+               knownHostList << QString::fromLatin1(known_hosts[i]);
+       }
+
+       qDebug("\n[Known Hosts]");
+       log("Testing all known hosts...", "", "---");
+
+       while(!knownHostList.isEmpty())
+       {
+               const QString currentHost = knownHostList.takeFirst();
+               qDebug("Testing: %s", MUTILS_L1STR(currentHost));
+               log(QLatin1String(""), "Testing:", currentHost, "");
+               if (!tryContactHost(currentHost, DOWNLOAD_TIMEOUT))
                {
-                       qWarning("\nConnectivity test FAILED on the following host:\n%s\n", currentHost.toLatin1().constData());
+                       qWarning("\nConnectivity test FAILED on the following host:\n%s\n", MUTILS_L1STR(currentHost));
                }
                log("", "---");
        }
@@ -518,7 +378,7 @@ void UpdateChecker::testKnownHosts(void)
 // PRIVATE FUNCTIONS
 ////////////////////////////////////////////////////////////
 
-void UpdateChecker::setStatus(const int status)
+void MUtils::UpdateChecker::setStatus(const int status)
 {
        if(m_status != status)
        {
@@ -527,7 +387,7 @@ void UpdateChecker::setStatus(const int status)
        }
 }
 
-void UpdateChecker::setProgress(const int progress)
+void MUtils::UpdateChecker::setProgress(const int progress)
 {
        if(m_progress != progress)
        {
@@ -536,7 +396,7 @@ void UpdateChecker::setProgress(const int progress)
        }
 }
 
-void UpdateChecker::log(const QString &str1, const QString &str2, const QString &str3, const QString &str4)
+void MUtils::UpdateChecker::log(const QString &str1, const QString &str2, const QString &str3, const QString &str4)
 {
        if(!str1.isNull()) emit messageLogged(str1);
        if(!str2.isNull()) emit messageLogged(str2);
@@ -544,15 +404,18 @@ void UpdateChecker::log(const QString &str1, const QString &str2, const QString
        if(!str4.isNull()) emit messageLogged(str4);
 }
 
-bool UpdateChecker::tryUpdateMirror(UpdateCheckerInfo *updateInfo, const QString &url, const bool &quick)
+bool MUtils::UpdateChecker::tryUpdateMirror(UpdateCheckerInfo *updateInfo, const QString &url, const bool &quick)
 {
        bool success = false;
        log("", "Trying mirror:", url, "");
 
-       if (!tryContactHost(QUrl(url).host(), quick ? (MAX_CONN_TIMEOUT / 10) : MAX_CONN_TIMEOUT))
+       if (quick)
        {
-               log("", quick ? "Mirror is too slow!" :"Mirror is unreachable!");
-               return false;
+               if (!tryContactHost(QUrl(url).host(), (MAX_CONN_TIMEOUT / 8)))
+               {
+                       log("", "Mirror is too slow, skipping!");
+                       return false;
+               }
        }
 
        const QString randPart = next_rand_str();
@@ -561,15 +424,15 @@ bool UpdateChecker::tryUpdateMirror(UpdateCheckerInfo *updateInfo, const QString
 
        if (getUpdateInfo(url, outFileVers, outFileSign))
        {
-               log("", "Download okay, checking signature:");
+               log("Download completed, verifying signature:", "");
                if (checkSignature(outFileVers, outFileSign))
                {
-                       log("", "Signature okay, parsing info:", "");
+                       log("", "Signature is valid, parsing info:", "");
                        success = parseVersionInfo(outFileVers, updateInfo);
                }
                else
                {
-                       log("", "Bad signature, take care!");
+                       log("", "Bad signature, take care !!!");
                }
        }
        else
@@ -583,15 +446,15 @@ bool UpdateChecker::tryUpdateMirror(UpdateCheckerInfo *updateInfo, const QString
        return success;
 }
 
-bool UpdateChecker::getUpdateInfo(const QString &url, const QString &outFileVers, const QString &outFileSign)
+bool MUtils::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))
+       if(getFile(QUrl(QString("%1%2").arg(url, mirror_url_postfix[m_betaUpdates ? 1 : 0])), outFileVers))
        {
                if (!m_cancelled)
                {
-                       log("", "Downloading signature:", "");
-                       if (getFile(QString("%1%2.sig2").arg(url, mirror_url_postfix[m_betaUpdates ? 1 : 0]), outFileSign))
+                       log( "Downloading signature file:", "");
+                       if (getFile(QUrl(QString("%1%2.sig2").arg(url, mirror_url_postfix[m_betaUpdates ? 1 : 0])), outFileSign))
                        {
                                return true;
                        }
@@ -600,7 +463,7 @@ bool UpdateChecker::getUpdateInfo(const QString &url, const QString &outFileVers
        return false;
 }
 
-bool UpdateChecker::parseVersionInfo(const QString &file, UpdateCheckerInfo *updateInfo)
+bool MUtils::UpdateChecker::parseVersionInfo(const QString &file, UpdateCheckerInfo *updateInfo)
 {
        QRegExp value("^(\\w+)=(.+)$");
        QRegExp section("^\\[(.+)\\]$");
@@ -707,23 +570,7 @@ bool UpdateChecker::parseVersionInfo(const QString &file, UpdateCheckerInfo *upd
 // EXTERNAL TOOLS
 //----------------------------------------------------------
 
-bool UpdateChecker::getFile(const QString &url, const QString &outFile, const unsigned int maxRedir)
-{
-       for (int i = 0; i < 2; i++)
-       {
-               if (getFile(url, (i > 0), outFile, maxRedir))
-               {
-                       return true;
-               }
-               if (MUTILS_BOOLIFY(m_cancelled))
-               {
-                       break; /*cancelled*/
-               }
-       }
-       return false;
-}
-
-bool UpdateChecker::getFile(const QString &url, const bool forceIp4, const QString &outFile, const unsigned int maxRedir)
+bool MUtils::UpdateChecker::getFile(const QUrl &url, const QString &outFile, const unsigned int maxRedir)
 {
        QFileInfo output(outFile);
        output.setCaching(false);
@@ -733,79 +580,98 @@ bool UpdateChecker::getFile(const QString &url, const bool forceIp4, const QStri
                QFile::remove(output.canonicalFilePath());
                if (output.exists())
                {
+                       qWarning("Existing output file could not be found!");
                        return false;
                }
        }
+       
+       QStringList args(QLatin1String("-vsSNqkfL"));
+       args << "-m" << QString::number(DOWNLOAD_TIMEOUT / 1000);
+       args << "--max-redirs" << QString::number(maxRedir);
+       args << "-A" << USER_AGENT_STR;
+       args << "-e" << QString("%1://%2/;auto").arg(url.scheme(), url.host());
+       args << "-o" << output.fileName() << url.toString();
+
+       return execCurl(args, output.absolutePath(), DOWNLOAD_TIMEOUT);
+}
 
-       QProcess process;
-       init_process(process, output.absolutePath());
+bool MUtils::UpdateChecker::tryContactHost(const QString &hostname, const int &timeoutMsec)
+{
+       log(QString("Connecting to host: %1").arg(hostname), "");
 
-       QStringList args;
-       if (forceIp4)
+       QStringList args(QLatin1String("-vsSNqkI"));
+       args << "-m" << QString::number(qMax(1, timeoutMsec / 1000));
+       args << "-A" << USER_AGENT_STR;
+       args << "-o" << OS::null_device() << QString("http://%1/").arg(hostname);
+       
+       return execCurl(args, temp_folder(), timeoutMsec);
+}
+
+bool MUtils::UpdateChecker::checkSignature(const QString &file, const QString &signature)
+{
+       if (QFileInfo(file).absolutePath().compare(QFileInfo(signature).absolutePath(), Qt::CaseInsensitive) != 0)
        {
-               args << "-4";
+               qWarning("CheckSignature: File and signature should be in same folder!");
+               return false;
        }
 
-       args << "--no-config" << "--no-cache" << "--no-dns-cache" << "--no-check-certificate" << "--no-hsts";
-       args << QString().sprintf("--max-redirect=%u", maxRedir) << QString().sprintf("--timeout=%u", DOWNLOAD_TIMEOUT / 1000);
-       args << QString("--referer=%1://%2/").arg(QUrl(url).scheme(), QUrl(url).host()) << "-U" << USER_AGENT_STR;
-       args << "-O" << output.fileName() << url;
-
-       QEventLoop loop;
-       connect(&process, SIGNAL(error(QProcess::ProcessError)), &loop, SLOT(quit()));
-       connect(&process, SIGNAL(finished(int, QProcess::ExitStatus)), &loop, SLOT(quit()));
-       connect(&process, SIGNAL(readyRead()), &loop, SLOT(quit()));
-
-       QTimer timer;
-       timer.setSingleShot(true);
-       connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
+       QString keyRingPath(m_binaryKeys);
+       bool removeKeyring = false;
+       if (QFileInfo(file).absolutePath().compare(QFileInfo(m_binaryKeys).absolutePath(), Qt::CaseInsensitive) != 0)
+       {
+               keyRingPath = make_temp_file(QFileInfo(file).absolutePath(), "gpg");
+               removeKeyring = true;
+               if (!QFile::copy(m_binaryKeys, keyRingPath))
+               {
+                       qWarning("CheckSignature: Failed to copy the key-ring file!");
+                       return false;
+               }
+       }
 
-       const QRegExp httpResponseOK("200 OK$");
+       QStringList args;
+       args << QStringList() << "--homedir" << ".";
+       args << "--keyring" << QFileInfo(keyRingPath).fileName();
+       args << QFileInfo(signature).fileName();
+       args << QFileInfo(file).fileName();
 
-       process.start(m_binaryWGet, args);
+       const int exitCode = execProcess(m_binaryGnuPG, args, QFileInfo(file).absolutePath(), DOWNLOAD_TIMEOUT);
+       if (exitCode != INT_MAX)
+       {
+               log(QString().sprintf("Exited with code %d", exitCode));
+       }
 
-       if (!process.waitForStarted())
+       if (removeKeyring)
        {
-               return false;
+               remove_file(keyRingPath);
        }
 
-       timer.start(DOWNLOAD_TIMEOUT);
+       return (exitCode == 0); /*completed*/
+}
 
-       while (process.state() != QProcess::NotRunning)
+bool MUtils::UpdateChecker::execCurl(const QStringList &args, const QString &workingDir, const int timeout)
+{
+       const int exitCode = execProcess(m_binaryCurl, args, workingDir, timeout + (timeout / 2));
+       if (exitCode != INT_MAX)
        {
-               loop.exec();
-               const bool bTimeOut = (!timer.isActive());
-               while (process.canReadLine())
-               {
-                       const QString line = QString::fromLatin1(process.readLine()).simplified();
-                       log(line);
-               }
-               if (bTimeOut || MUTILS_BOOLIFY(m_cancelled))
+               switch (exitCode)
                {
-                       qWarning("WGet process timed out <-- killing!");
-                       process.kill();
-                       process.waitForFinished();
-                       log(bTimeOut ? "!!! TIMEOUT !!!": "!!! CANCELLED !!!");
-                       return false;
+                       case -1:
+                       case  0: log(QLatin1String("DONE: Transfer completed successfully."), "");                     break;
+                       case  6: log(QLatin1String("ERROR: Remote host could not be resolved!"), "");                  break;
+                       case  7: log(QLatin1String("ERROR: Connection to remote host could not be established!"), ""); break;
+                       case 22: log(QLatin1String("ERROR: Requested URL was not found or returned an error!"), "");   break;
+                       case 28: log(QLatin1String("ERROR: Operation timed out !!!"), "");                             break;
+                       default: log(QString().sprintf("ERROR: Terminated with unknown code %d", exitCode), "");       break;
                }
        }
 
-       timer.stop();
-       timer.disconnect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
-
-       log(QString().sprintf("Exited with code %d", process.exitCode()));
-       return (process.exitCode() == 0) && output.exists() && output.isFile();
+       return (exitCode == 0); /*completed*/
 }
 
-bool UpdateChecker::tryContactHost(const QString &hostname, const int &timeoutMsec, quint32 *const ipAddrOut)
+int MUtils::UpdateChecker::execProcess(const QString &programFile, const QStringList &args, const QString &workingDir, const int timeout)
 {
-       log(QString("Connecting to host: %1").arg(hostname), "");
-
        QProcess process;
-       init_process(process, temp_folder());
-
-       QStringList args;
-       args << "--retry" << QString::number(3) << hostname << QString::number(80);
+       init_process(process, workingDir, true, NULL, m_environment.data());
 
        QEventLoop loop;
        connect(&process, SIGNAL(error(QProcess::ProcessError)), &loop, SLOT(quit()));
@@ -816,123 +682,56 @@ bool UpdateChecker::tryContactHost(const QString &hostname, const int &timeoutMs
        timer.setSingleShot(true);
        connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
 
-       QScopedPointer<QRegExp> 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);
-
+       process.start(programFile, args);
        if (!process.waitForStarted())
        {
-               return false;
+               log("PROCESS FAILED TO START !!!", "");
+               qWarning("WARNING: %s process could not be created!", MUTILS_UTF8(QFileInfo(programFile).fileName()));
+               return INT_MAX; /*failed to start*/
        }
 
-       timer.start(timeoutMsec);
+       bool bAborted = false;
+       timer.start(qMax(timeout, 1500));
 
        while (process.state() != QProcess::NotRunning)
        {
                loop.exec();
-               const bool bTimeOut = (!timer.isActive());
                while (process.canReadLine())
                {
                        const QString line = QString::fromLatin1(process.readLine()).simplified();
-                       if (!ipAddr.isNull())
+                       if ((!line.isEmpty()) && line.compare(QLatin1String("<")) && line.compare(QLatin1String(">")))
                        {
-                               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);
                        }
-                       log(line);
                }
-               if (bTimeOut || MUTILS_BOOLIFY(m_cancelled))
+               const bool bCancelled = MUTILS_BOOLIFY(m_cancelled);
+               if (bAborted = (bCancelled || ((!timer.isActive()) && (!process.waitForFinished(125)))))
                {
-                       qWarning("MCat process timed out <-- killing!");
-                       process.kill();
-                       process.waitForFinished();
-                       log(bTimeOut ? "!!! TIMEOUT !!!" : "!!! CANCELLED !!!");
-                       return false;
+                       log(bCancelled ? "CANCELLED BY USER !!!" : "PROCESS TIMEOUT !!!", "");
+                       qWarning("WARNING: %s process %s!", MUTILS_UTF8(QFileInfo(programFile).fileName()), bCancelled ? "cancelled" : "timed out");
+                       break; /*abort process*/
                }
        }
 
        timer.stop();
        timer.disconnect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
 
-       if (process.exitCode() != 0)
+       if (bAborted)
        {
-               log("Connection has failed!");
+               process.kill();
+               process.waitForFinished(-1);
        }
 
-       log(QString().sprintf("Exited with code %d", process.exitCode()), "");
-       return (process.exitCode() == 0);
-}
-
-bool UpdateChecker::checkSignature(const QString &file, const QString &signature)
-{
-       if (QFileInfo(file).absolutePath().compare(QFileInfo(signature).absolutePath(), Qt::CaseInsensitive) != 0)
+       while (process.canReadLine())
        {
-               qWarning("CheckSignature: File and signature should be in same folder!");
-               return false;
-       }
-
-       QString keyRingPath(m_binaryKeys);
-       bool removeKeyring = false;
-       if (QFileInfo(file).absolutePath().compare(QFileInfo(m_binaryKeys).absolutePath(), Qt::CaseInsensitive) != 0)
-       {
-               keyRingPath = make_temp_file(QFileInfo(file).absolutePath(), "gpg");
-               removeKeyring = true;
-               if (!QFile::copy(m_binaryKeys, keyRingPath))
-               {
-                       qWarning("CheckSignature: Failed to copy the key-ring file!");
-                       return false;
-               }
-       }
-
-       QProcess process;
-       init_process(process, QFileInfo(file).absolutePath());
-
-       QEventLoop loop;
-       connect(&process, SIGNAL(error(QProcess::ProcessError)), &loop, SLOT(quit()));
-       connect(&process, SIGNAL(finished(int, QProcess::ExitStatus)), &loop, SLOT(quit()));
-       connect(&process, SIGNAL(readyRead()), &loop, SLOT(quit()));
-
-       process.start(m_binaryGnuPG, QStringList() << "--homedir" << "." << "--keyring" << QFileInfo(keyRingPath).fileName() << QFileInfo(signature).fileName() << QFileInfo(file).fileName());
-
-       if (!process.waitForStarted())
-       {
-               if (removeKeyring)
-               {
-                       remove_file(keyRingPath);
-               }
-               return false;
-       }
-
-       while (process.state() == QProcess::Running)
-       {
-               loop.exec();
-               while (process.canReadLine())
+               const QString line = QString::fromLatin1(process.readLine()).simplified();
+               if ((!line.isEmpty()) && line.compare(QLatin1String("<")) && line.compare(QLatin1String(">")))
                {
-                       log(QString::fromLatin1(process.readLine()).simplified());
+                       log(line);
                }
        }
 
-       if (removeKeyring)
-       {
-               remove_file(keyRingPath);
-       }
-
-       log(QString().sprintf("Exited with code %d", process.exitCode()));
-       return (process.exitCode() == 0);
+       return bAborted ? INT_MAX : process.exitCode();
 }
 
 ////////////////////////////////////////////////////////////