summaryrefslogtreecommitdiffstats
path: root/src/libs/kdtools/kdupdaterfiledownloader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/kdtools/kdupdaterfiledownloader.cpp')
-rw-r--r--src/libs/kdtools/kdupdaterfiledownloader.cpp107
1 files changed, 91 insertions, 16 deletions
diff --git a/src/libs/kdtools/kdupdaterfiledownloader.cpp b/src/libs/kdtools/kdupdaterfiledownloader.cpp
index 9ad3861dd..a7fbfe85b 100644
--- a/src/libs/kdtools/kdupdaterfiledownloader.cpp
+++ b/src/libs/kdtools/kdupdaterfiledownloader.cpp
@@ -1,24 +1,43 @@
/****************************************************************************
-** Copyright (C) 2001-2010 Klaralvdalens Datakonsult AB. All rights reserved.
**
-** This file is part of the KD Tools library.
+** Copyright (C) 2013 Klaralvdalens Datakonsult AB (KDAB)
+** Contact: http://www.qt-project.org/legal
**
-** Licensees holding valid commercial KD Tools licenses may use this file in
-** accordance with the KD Tools Commercial License Agreement provided with
-** the Software.
+** This file is part of the Qt Installer Framework.
**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
**
-** This file may be distributed and/or modified under the terms of the
-** GNU Lesser General Public License version 2 and version 3 as published by the
-** Free Software Foundation and appearing in the file LICENSE.LGPL included.
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
-** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
-** Contact info@kdab.com if any conditions of this licensing are not
-** clear to you.
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
**
-**********************************************************************/
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
#include "kdupdaterfiledownloader_p.h"
#include "kdupdaterfiledownloaderfactory.h"
@@ -93,6 +112,7 @@ struct KDUpdater::FileDownloader::Private
, m_sampleIndex(0)
, m_downloadSpeed(0)
, m_factory(0)
+ , m_ignoreSslErrors(false)
{
memset(m_samples, 0, sizeof(m_samples));
}
@@ -125,6 +145,7 @@ struct KDUpdater::FileDownloader::Private
QAuthenticator m_authenticator;
FileDownloaderProxyFactory *m_factory;
+ bool m_ignoreSslErrors;
};
KDUpdater::FileDownloader::FileDownloader(const QString &scheme, QObject *parent)
@@ -363,6 +384,12 @@ void KDUpdater::FileDownloader::addCheckSumData(const char *data, int length)
d->m_hash.addData(data, length);
}
+void KDUpdater::FileDownloader::resetCheckSumData()
+{
+ d->m_hash.reset();
+}
+
+
/*!
Returns a copy of the proxy factory that this FileDownloader object is using to determine the proxies to
be used for requests.
@@ -407,6 +434,16 @@ void KDUpdater::FileDownloader::setAuthenticator(const QAuthenticator &authentic
}
}
+bool KDUpdater::FileDownloader::ignoreSslErrors()
+{
+ return d->m_ignoreSslErrors;
+}
+
+void KDUpdater::FileDownloader::setIgnoreSslErrors(bool ignore)
+{
+ d->m_ignoreSslErrors = ignore;
+}
+
// -- KDUpdater::LocalFileDownloader
/*
@@ -778,6 +815,7 @@ struct KDUpdater::HttpDownloader::Private
destination->close();
destination->deleteLater();
destination = 0;
+ q->resetCheckSumData();
}
};
@@ -941,6 +979,12 @@ void KDUpdater::HttpDownloader::httpReqFinished()
void KDUpdater::HttpDownloader::httpReadProgress(qint64 done, qint64 total)
{
+ if (d->http) {
+ const QUrl redirectUrl = d->http->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
+ if (followRedirects() && redirectUrl.isValid())
+ return; // if we are a redirection, do not emit the progress
+ }
+
setProgress(done, total);
emit downloadProgress(calcProgress(done, total));
}
@@ -1024,11 +1068,13 @@ void KDUpdater::HttpDownloader::onAuthenticationRequired(QNetworkReply *reply, Q
}
#ifndef QT_NO_OPENSSL
+
+#include "messageboxhandler.h"
+
// TODO: once we switch to Qt5, use QT_NO_SSL instead of QT_NO_OPENSSL
void KDUpdater::HttpDownloader::onSslErrors(QNetworkReply* reply, const QList<QSslError> &errors)
{
Q_UNUSED(reply)
-
QString errorString;
foreach (const QSslError &error, errors) {
if (!errorString.isEmpty())
@@ -1037,7 +1083,36 @@ void KDUpdater::HttpDownloader::onSslErrors(QNetworkReply* reply, const QList<QS
}
qDebug() << errorString;
- if (!d->aborted)
- httpDone(true);
+ const QStringList arguments = QCoreApplication::arguments();
+ if (arguments.contains(QLatin1String("--script")) || arguments.contains(QLatin1String("Script"))
+ || ignoreSslErrors()) {
+ reply->ignoreSslErrors();
+ return;
+ }
+ // TODO: Remove above code once we have a proper implementation for message box handler supporting
+ // methods used in the following code, right now we return here cause the message box is not scriptable.
+
+ QMessageBox msgBox(MessageBoxHandler::currentBestSuitParent());
+ msgBox.setDetailedText(errorString);
+ msgBox.setIcon(QMessageBox::Warning);
+ msgBox.setWindowModality(Qt::WindowModal);
+ msgBox.setWindowTitle(tr("Secure Connection Failed"));
+ msgBox.setText(tr("There was an error during connection to: %1.").arg(url().toString()));
+ msgBox.setInformativeText(QString::fromLatin1("<ul><li>%1</li><li>%2</li></ul>").arg(tr("This could be "
+ "a problem with the server's configuration, or it could be someone trying to impersonate the "
+ "server."), tr("If you have connected to this server successfully in the past or trust this server, "
+ "the error may be temporary and you can try again.")));
+
+ msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
+ msgBox.setButtonText(QMessageBox::Yes, tr("Try again"));
+ msgBox.setDefaultButton(QMessageBox::Cancel);
+
+ if (msgBox.exec() == QMessageBox::Cancel) {
+ if (!d->aborted)
+ httpDone(true);
+ } else {
+ reply->ignoreSslErrors();
+ KDUpdater::FileDownloaderFactory::instance().setIgnoreSslErrors(true);
+ }
}
#endif