summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-11-20 08:31:23 (GMT)
committerMontel Laurent <montel@kde.org>2016-11-20 08:31:23 (GMT)
commit48069042eaccc944e98a7ae63d5a22c71a074cf0 (patch)
treea32fb4e3ca5f8070fc421c9612ec5025eac7a240
parentc6e9cce694840ff0a7592d74d062e73c1703b36b (diff)
Improve searchfullhash job
-rw-r--r--webengineviewer/src/checkphishingurl/searchfullhashjob.cpp26
-rw-r--r--webengineviewer/src/checkphishingurl/searchfullhashjob.h7
2 files changed, 18 insertions, 15 deletions
diff --git a/webengineviewer/src/checkphishingurl/searchfullhashjob.cpp b/webengineviewer/src/checkphishingurl/searchfullhashjob.cpp
index 31703c2..ae43374 100644
--- a/webengineviewer/src/checkphishingurl/searchfullhashjob.cpp
+++ b/webengineviewer/src/checkphishingurl/searchfullhashjob.cpp
@@ -87,13 +87,14 @@ void SearchFullHashJob::parse(const QByteArray &replyStr)
"negativeCacheDuration": "300.000s"
}
*/
+ /*
QJsonDocument document = QJsonDocument::fromJson(replyStr);
if (document.isNull()) {
- Q_EMIT result(WebEngineViewer::SearchFullHashJob::Unknown, mUrl);
+ Q_EMIT result(WebEngineViewer::SearchFullHashJob::Unknown, mHash);
} else {
const QVariantMap answer = document.toVariant().toMap();
if (answer.isEmpty()) {
- Q_EMIT result(WebEngineViewer::SearchFullHashJob::Ok, mUrl);
+ Q_EMIT result(WebEngineViewer::SearchFullHashJob::Ok, mHash);
return;
} else {
const QVariantList info = answer.value(QStringLiteral("matches")).toList();
@@ -103,8 +104,8 @@ void SearchFullHashJob::parse(const QByteArray &replyStr)
if (threatTypeStr == QStringLiteral("MALWARE")) {
const QVariantMap urlMap = map[QStringLiteral("threat")].toMap();
if (urlMap.count() == 1) {
- if (urlMap[QStringLiteral("url")].toString() == mUrl.toString()) {
- Q_EMIT result(WebEngineViewer::SearchFullHashJob::MalWare, mUrl);
+ if (urlMap[QStringLiteral("url")].toString() == mHash.toString()) {
+ Q_EMIT result(WebEngineViewer::SearchFullHashJob::MalWare, mHash);
return;
}
}
@@ -112,9 +113,10 @@ void SearchFullHashJob::parse(const QByteArray &replyStr)
qWarning() << " SearchFullHashJob::parse threatTypeStr : " << threatTypeStr;
}
}
- Q_EMIT result(WebEngineViewer::SearchFullHashJob::Unknown, mUrl);
+ Q_EMIT result(WebEngineViewer::SearchFullHashJob::Unknown, mHash);
}
}
+ */
}
void SearchFullHashJob::slotCheckUrlFinished(QNetworkReply *reply)
@@ -124,9 +126,9 @@ void SearchFullHashJob::slotCheckUrlFinished(QNetworkReply *reply)
deleteLater();
}
-void SearchFullHashJob::setUrl(const QUrl &url)
+void SearchFullHashJob::setSearchHash(const QByteArray &hash)
{
- mUrl = url;
+ mHash = hash;
}
QByteArray SearchFullHashJob::jsonRequest() const
@@ -161,6 +163,8 @@ QByteArray SearchFullHashJob::jsonRequest() const
map.insert(QStringLiteral("client"), clientMap);
//clientStates
+ const QVariantList clientStatesList = { QString() }; //Add client states
+ map.insert(QStringLiteral("clientStates"), clientStatesList);
QVariantMap threatMap;
@@ -173,7 +177,7 @@ QByteArray SearchFullHashJob::jsonRequest() const
threatMap.insert(QStringLiteral("threatEntryTypes"), threatEntryTypesList);
QVariantList threatEntriesList;
QVariantMap hashUrlMap;
- hashUrlMap.insert(QStringLiteral("hash"), mUrl.toString());
+ hashUrlMap.insert(QStringLiteral("hash"), mHash);
threatEntriesList.append(hashUrlMap);
threatMap.insert(QStringLiteral("threatEntries"), threatEntriesList);
@@ -187,7 +191,7 @@ QByteArray SearchFullHashJob::jsonRequest() const
void SearchFullHashJob::start()
{
if (!PimCommon::NetworkManager::self()->networkConfigureManager()->isOnline()) {
- Q_EMIT result(WebEngineViewer::SearchFullHashJob::BrokenNetwork, mUrl);
+ Q_EMIT result(WebEngineViewer::SearchFullHashJob::BrokenNetwork, mHash);
deleteLater();
} else if (canStart()) {
QUrl safeUrl = QUrl(QStringLiteral("https://safebrowsing.googleapis.com/v4/fullHashes:find"));
@@ -203,7 +207,7 @@ void SearchFullHashJob::start()
QNetworkReply *reply = mNetworkAccessManager->post(request, baPostData);
connect(reply, static_cast<void (QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error), this, &SearchFullHashJob::slotError);
} else {
- Q_EMIT result(WebEngineViewer::SearchFullHashJob::InvalidUrl, mUrl);
+ Q_EMIT result(WebEngineViewer::SearchFullHashJob::InvalidUrl, mHash);
deleteLater();
}
}
@@ -218,5 +222,5 @@ void SearchFullHashJob::slotError(QNetworkReply::NetworkError error)
bool SearchFullHashJob::canStart() const
{
- return mUrl.isValid();
+ return !mHash.isEmpty();
}
diff --git a/webengineviewer/src/checkphishingurl/searchfullhashjob.h b/webengineviewer/src/checkphishingurl/searchfullhashjob.h
index 1f8e48b..6eb6bce 100644
--- a/webengineviewer/src/checkphishingurl/searchfullhashjob.h
+++ b/webengineviewer/src/checkphishingurl/searchfullhashjob.h
@@ -43,8 +43,6 @@ public:
Unknown
};
- void setUrl(const QUrl &url);
-
void start();
bool canStart() const;
@@ -52,8 +50,9 @@ public:
void parse(const QByteArray &replyStr);
void setUseCompactJson(bool useCompactJson);
+ void setSearchHash(const QByteArray &hash);
Q_SIGNALS:
- void result(WebEngineViewer::SearchFullHashJob::UrlStatus status, const QUrl &url);
+ void result(WebEngineViewer::SearchFullHashJob::UrlStatus status, const QByteArray &url);
void debugJson(const QByteArray &ba);
private Q_SLOTS:
@@ -61,7 +60,7 @@ private Q_SLOTS:
void slotError(QNetworkReply::NetworkError error);
void slotCheckUrlFinished(QNetworkReply *reply);
private:
- QUrl mUrl;
+ QByteArray mHash;
bool mUseCompactJson;
QNetworkAccessManager *mNetworkAccessManager;
};