summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-11-15 12:46:56 (GMT)
committerMontel Laurent <montel@kde.org>2016-11-15 12:46:56 (GMT)
commit8e2f230ebb062643a5cb1e734d73ad345793a9eb (patch)
tree17688b0f4bd365e83e7166b9e4629366124fbd8b
parent530c8afa7057724c8bea88d4737a51df4406ec8d (diff)
Improve
-rw-r--r--webengineviewer/src/checkphishingurl/createphishingurldatabasejob.cpp32
-rw-r--r--webengineviewer/src/checkphishingurl/createphishingurldatabasejob.h8
2 files changed, 38 insertions, 2 deletions
diff --git a/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.cpp b/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.cpp
index 6ded519..7143fd1 100644
--- a/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.cpp
+++ b/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.cpp
@@ -20,9 +20,10 @@
#include "createphishingurldatabasejob.h"
#include "webengineviewer_debug.h"
+#include <PimCommon/NetworkManager>
+#include <QNetworkConfigurationManager>
#include <QJsonDocument>
-#include <QNetworkReply>
//#define DEBUG_JSON_REQUEST 1
using namespace WebEngineViewer;
@@ -40,6 +41,12 @@ CreatePhishingUrlDataBaseJob::~CreatePhishingUrlDataBaseJob()
}
+QString CreatePhishingUrlDataBaseJob::apiKey() const
+{
+ return QStringLiteral("AIzaSyBS62pXATjabbH2RM_jO2EzDg1mTMHlnyo");
+}
+
+
void CreatePhishingUrlDataBaseJob::slotSslErrors(QNetworkReply *reply, const QList<QSslError> &error)
{
qCDebug(WEBENGINEVIEWER_LOG) << " void CreatePhishingUrlDataBaseJob::slotSslErrors(QNetworkReply *reply, const QList<QSslError> &error)" << error.count();
@@ -48,7 +55,30 @@ void CreatePhishingUrlDataBaseJob::slotSslErrors(QNetworkReply *reply, const QLi
void CreatePhishingUrlDataBaseJob::start()
{
+ if (!PimCommon::NetworkManager::self()->networkConfigureManager()->isOnline()) {
+ Q_EMIT finished();
+ deleteLater();
+ } else {
+ QUrl safeUrl = QUrl(QStringLiteral("https://safebrowsing.googleapis.com/v4/threatListUpdates:fetch"));
+ safeUrl.addQueryItem(QStringLiteral("key"), apiKey());
+ //qDebug() << " safeUrl" << safeUrl;
+ QNetworkRequest request(safeUrl);
+ request.setHeader(QNetworkRequest::ContentTypeHeader, QStringLiteral("application/json"));
+
+ const QByteArray baPostData = jsonRequest();
+ qCDebug(WEBENGINEVIEWER_LOG) << " postData.toJson()" << baPostData;
+ //curl -H "Content-Type: application/json" -X POST -d '{"client":{"clientId":"KDE","clientVersion":"5.4.0"},"threatInfo":{"platformTypes":["WINDOWS"],"threatEntries":[{"url":"http://www.kde.org"}],"threatEntryTypes":["URL"],"threatTypes":["MALWARE"]}}' https://safebrowsing.googleapis.com/v4/threatMatches:find?key=AIzaSyBS62pXATjabbH2RM_jO2EzDg1mTMHlnyo
+ QNetworkReply *reply = mNetworkAccessManager->post(request, baPostData);
+ connect(reply, static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error), this, &CreatePhishingUrlDataBaseJob::slotError);
+ }
+}
+void CreatePhishingUrlDataBaseJob::slotError(QNetworkReply::NetworkError error)
+{
+ QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
+ qWarning() << " error " << error << " error string : " << reply->errorString();
+ reply->deleteLater();
+ deleteLater();
}
QByteArray CreatePhishingUrlDataBaseJob::jsonRequest() const
diff --git a/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.h b/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.h
index 45163ca..3cc7d42 100644
--- a/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.h
+++ b/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.h
@@ -23,10 +23,10 @@
#include <QObject>
#include <QSslError>
+#include <QNetworkReply>
#include "webengineviewer_export.h"
class QNetworkAccessManager;
-class QNetworkReply;
namespace WebEngineViewer
{
class WEBENGINEVIEWER_EXPORT CreatePhishingUrlDataBaseJob : public QObject
@@ -46,9 +46,15 @@ public:
void setDataBaseDownloadNeeded(WebEngineViewer::CreatePhishingUrlDataBaseJob::DataBaseDownload type);
QByteArray jsonRequest() const;
+
+Q_SIGNALS:
+ void finished();
+
private:
+ QString apiKey() const;
void slotCheckUrlFinished(QNetworkReply *reply);
void slotSslErrors(QNetworkReply *reply, const QList<QSslError> &error);
+ void slotError(QNetworkReply::NetworkError error);
DataBaseDownload mDataBaseDownloadNeeded;
QNetworkAccessManager *mNetworkAccessManager;