summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-11-16 12:10:33 (GMT)
committerMontel Laurent <montel@kde.org>2016-11-16 12:10:33 (GMT)
commit6e5a492d6efcfbe5f23f1ffc0e8bc1dc1d99578c (patch)
treeb90b759b4390861486a2f7f2e5d477fa52557471
parent9038d4382e75c0f46d3de38e5501bbee61033eec (diff)
Improve parsing
-rw-r--r--webengineviewer/src/checkphishingurl/autotests/checkphishingurlfromlocaldatabasejobtest.cpp11
-rw-r--r--webengineviewer/src/checkphishingurl/autotests/checkphishingurlfromlocaldatabasejobtest.h3
-rw-r--r--webengineviewer/src/checkphishingurl/createphishingurldatabasejob.cpp74
-rw-r--r--webengineviewer/src/checkphishingurl/createphishingurldatabasejob.h26
-rw-r--r--webengineviewer/src/checkphishingurl/localdatabasemanager.cpp6
-rw-r--r--webengineviewer/src/checkphishingurl/localdatabasemanager.h2
6 files changed, 117 insertions, 5 deletions
diff --git a/webengineviewer/src/checkphishingurl/autotests/checkphishingurlfromlocaldatabasejobtest.cpp b/webengineviewer/src/checkphishingurl/autotests/checkphishingurlfromlocaldatabasejobtest.cpp
index b6ae472..4be38f6 100644
--- a/webengineviewer/src/checkphishingurl/autotests/checkphishingurlfromlocaldatabasejobtest.cpp
+++ b/webengineviewer/src/checkphishingurl/autotests/checkphishingurlfromlocaldatabasejobtest.cpp
@@ -18,6 +18,7 @@
*/
#include "checkphishingurlfromlocaldatabasejobtest.h"
+#include "../checkphishingurlfromlocaldatabasejob.h"
#include <QTest>
CheckPhishingUrlFromLocalDataBaseJobTest::CheckPhishingUrlFromLocalDataBaseJobTest(QObject *parent)
@@ -31,4 +32,14 @@ CheckPhishingUrlFromLocalDataBaseJobTest::~CheckPhishingUrlFromLocalDataBaseJobT
}
+void CheckPhishingUrlFromLocalDataBaseJobTest::shouldCreateRequest_data()
+{
+
+}
+
+void CheckPhishingUrlFromLocalDataBaseJobTest::shouldCreateRequest()
+{
+
+}
+
QTEST_MAIN(CheckPhishingUrlFromLocalDataBaseJobTest)
diff --git a/webengineviewer/src/checkphishingurl/autotests/checkphishingurlfromlocaldatabasejobtest.h b/webengineviewer/src/checkphishingurl/autotests/checkphishingurlfromlocaldatabasejobtest.h
index cf89ec5..158b9b8 100644
--- a/webengineviewer/src/checkphishingurl/autotests/checkphishingurlfromlocaldatabasejobtest.h
+++ b/webengineviewer/src/checkphishingurl/autotests/checkphishingurlfromlocaldatabasejobtest.h
@@ -28,6 +28,9 @@ class CheckPhishingUrlFromLocalDataBaseJobTest : public QObject
public:
explicit CheckPhishingUrlFromLocalDataBaseJobTest(QObject *parent = Q_NULLPTR);
~CheckPhishingUrlFromLocalDataBaseJobTest();
+private Q_SLOTS:
+ void shouldCreateRequest_data();
+ void shouldCreateRequest();
};
#endif // CHECKPHISHINGURLFROMLOCALDATABASEJOB_H
diff --git a/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.cpp b/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.cpp
index 10a272b..ad0dd86 100644
--- a/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.cpp
+++ b/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.cpp
@@ -163,6 +163,68 @@ void CreatePhishingUrlDataBaseJob::slotDownloadDataBaseFinished(QNetworkReply *r
reply->deleteLater();
}
+QVector<Addition> CreatePhishingUrlDataBaseJob::parseAdditions(const QVariantList &lst)
+{
+ QVector<Addition> additionList;
+ Q_FOREACH(const QVariant &v, lst) {
+ if (v.canConvert<QVariantMap>()) {
+ QMapIterator<QString, QVariant> mapIt(v.toMap());
+ while (mapIt.hasNext()) {
+ mapIt.next();
+ const QString keyStr = mapIt.key();
+ if (keyStr == QLatin1String("compressionType")) {
+ //TODO ?
+ } else if (keyStr == QLatin1String("rawHashes")) {
+ Addition tmp;
+ QMapIterator<QString, QVariant> rawHashesIt(mapIt.value().toMap());
+ while (rawHashesIt.hasNext()) {
+ rawHashesIt.next();
+ //qDebug() << " rawHashesIt.key() " << rawHashesIt.key() << " rawHashesIt.value()" << rawHashesIt.value();
+ const QString key = rawHashesIt.key();
+ if (key == QLatin1String("rawHashes")) {
+ tmp.hashString = rawHashesIt.value().toByteArray();
+ } else if (key == QLatin1String("prefixSize")) {
+ tmp.prefixSize = rawHashesIt.value().toInt();
+ } else {
+ qDebug() << " CreatePhishingUrlDataBaseJob::parseAdditions unknown rawHashes key " << key;
+ }
+ }
+ //qDebug()<<" rawHashs " << mapIt.value().typeName();
+ } else {
+ qDebug() << " CreatePhishingUrlDataBaseJob::parseAdditions unknown mapIt.key() " << keyStr;
+ }
+ }
+ } else {
+ qDebug() << " CreatePhishingUrlDataBaseJob::parseAdditions not parsing type "<<v.typeName();
+ }
+ }
+ return additionList;
+}
+
+QVector<Removal> CreatePhishingUrlDataBaseJob::parseRemovals(const QVariantList &lst)
+{
+ QVector<Removal> removalList;
+ Q_FOREACH(const QVariant &v, lst) {
+ if (v.canConvert<QVariantMap>()) {
+ QMapIterator<QString, QVariant> mapIt(v.toMap());
+ while (mapIt.hasNext()) {
+ mapIt.next();
+ const QString keyStr = mapIt.key();
+ if (keyStr == QLatin1String("compressionType")) {
+
+ } else if (keyStr == QLatin1String("rawIndices")) {
+
+ } else {
+ qDebug() << " CreatePhishingUrlDataBaseJob::parseRemovals unknown mapIt.key() " << keyStr;
+ }
+ }
+ } else {
+ qDebug() << " CreatePhishingUrlDataBaseJob::parseRemovals not parsing type "<<v.typeName();
+ }
+ }
+ return removalList;
+}
+
void CreatePhishingUrlDataBaseJob::parseResult(const QByteArray &value)
{
QJsonDocument document = QJsonDocument::fromJson(value);
@@ -179,17 +241,21 @@ void CreatePhishingUrlDataBaseJob::parseResult(const QByteArray &value)
if (i.key() == QLatin1String("listUpdateResponses")) {
const QVariantList info = i.value().toList();
if (info.count() == 1) {
- if (info.at(0).canConvert<QVariantMap>()) {
- QMapIterator<QString, QVariant> mapIt(info.at(0).toMap());
+ const QVariant infoVar = info.at(0);
+ if (infoVar.canConvert<QVariantMap>()) {
+ QMapIterator<QString, QVariant> mapIt(infoVar.toMap());
while (mapIt.hasNext()) {
mapIt.next();
const QString mapKey = mapIt.key();
if (mapKey == QLatin1String("additions")) {
- qDebug() << " addition" << mapIt.value().typeName();
+ qDebug() << " additions" << mapIt.value().typeName();
const QVariantList lst = mapIt.value().toList();
+ parseAdditions(lst);
+
} else if (mapKey == QLatin1String("removals")) {
- qDebug() << " removals items ";
+ qDebug() << " removals items " << mapIt.value().typeName();
const QVariantList lst = mapIt.value().toList();
+ parseRemovals(lst);
} else if (mapKey == QLatin1String("checksum")) {
QMapIterator<QString, QVariant> mapCheckSum(mapIt.value().toMap());
while (mapCheckSum.hasNext()) {
diff --git a/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.h b/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.h
index 038d4ee..b757d8c 100644
--- a/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.h
+++ b/webengineviewer/src/checkphishingurl/createphishingurldatabasejob.h
@@ -29,8 +29,27 @@
class QNetworkAccessManager;
namespace WebEngineViewer
{
+struct Addition {
+ Addition()
+ : prefixSize(0)
+ {
+
+ }
+ QByteArray hashString;
+ int prefixSize;
+};
+
+struct Removal {
+ Removal()
+ {
+
+ }
+ QList<int> indexes;
+};
+
struct UpdateDataBaseInfo {
- QList<int> indexToRemove;
+ QList<Addition> additionList;
+ QList<Removal> indexToRemove;
QString minimumWaitDuration;
QString threatType;
QString threatEntryType;
@@ -79,10 +98,15 @@ private:
void slotSslErrors(QNetworkReply *reply, const QList<QSslError> &error);
void slotError(QNetworkReply::NetworkError error);
void parseResult(const QByteArray &value);
+ QVector<Removal> parseRemovals(const QVariantList &lst);
+ QVector<Addition> parseAdditions(const QVariantList &lst);
QString mDataBaseState;
DataBaseDownload mDataBaseDownloadNeeded;
QNetworkAccessManager *mNetworkAccessManager;
};
}
+
+Q_DECLARE_TYPEINFO(WebEngineViewer::Addition, Q_MOVABLE_TYPE);
+Q_DECLARE_TYPEINFO(WebEngineViewer::Removal, Q_MOVABLE_TYPE);
#endif // CREATEPHISHINGURLDATABASEJOB_H
diff --git a/webengineviewer/src/checkphishingurl/localdatabasemanager.cpp b/webengineviewer/src/checkphishingurl/localdatabasemanager.cpp
index 053c70c..26f18fa 100644
--- a/webengineviewer/src/checkphishingurl/localdatabasemanager.cpp
+++ b/webengineviewer/src/checkphishingurl/localdatabasemanager.cpp
@@ -42,3 +42,9 @@ void LocalDataBaseManager::initializeDataBase()
{
//TODO
}
+
+void LocalDataBaseManager::checkUrl(const QUrl &url)
+{
+ //TODO
+}
+
diff --git a/webengineviewer/src/checkphishingurl/localdatabasemanager.h b/webengineviewer/src/checkphishingurl/localdatabasemanager.h
index f3f3841..a35ea64 100644
--- a/webengineviewer/src/checkphishingurl/localdatabasemanager.h
+++ b/webengineviewer/src/checkphishingurl/localdatabasemanager.h
@@ -21,6 +21,7 @@
#define LOCALDATABASEMANAGER_H
#include <QObject>
+#include <QUrl>
namespace WebEngineViewer
{
class LocalDataBaseManager : public QObject
@@ -32,6 +33,7 @@ public:
static LocalDataBaseManager *self();
+ void checkUrl(const QUrl &url);
private:
void initializeDataBase();
};