summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-11-18 12:09:27 (GMT)
committerMontel Laurent <montel@kde.org>2016-11-18 12:09:27 (GMT)
commit02a8e79b474caacf55af24317249d9101a63a5b4 (patch)
treef303a5be9843c2b0776117656d8cfc9eff94d3eb
parentc9c9cdeb6c3f861da2c8334fa844e2806dce18aa (diff)
Improve localdatabase creation
-rw-r--r--webengineviewer/src/checkphishingurl/autotests/localdatabasemanagertest.cpp23
-rw-r--r--webengineviewer/src/checkphishingurl/localdatabasemanager.cpp57
-rw-r--r--webengineviewer/src/checkphishingurl/localdatabasemanager.h4
3 files changed, 70 insertions, 14 deletions
diff --git a/webengineviewer/src/checkphishingurl/autotests/localdatabasemanagertest.cpp b/webengineviewer/src/checkphishingurl/autotests/localdatabasemanagertest.cpp
index 5b210f8..e02b7c1 100644
--- a/webengineviewer/src/checkphishingurl/autotests/localdatabasemanagertest.cpp
+++ b/webengineviewer/src/checkphishingurl/autotests/localdatabasemanagertest.cpp
@@ -22,6 +22,29 @@
#include <QTest>
+class TestLocalDataBaseManager : public WebEngineViewer::LocalDataBaseManager
+{
+public:
+ TestLocalDataBaseManager(QObject *parent)
+ : WebEngineViewer::LocalDataBaseManager(parent)
+ {
+
+ }
+
+ // LocalDataBaseManager interface
+protected:
+ void downloadFullDataBase() Q_DECL_OVERRIDE;
+ void downloadPartialDataBase() Q_DECL_OVERRIDE;
+};
+
+void TestLocalDataBaseManager::downloadFullDataBase()
+{
+}
+
+void TestLocalDataBaseManager::downloadPartialDataBase()
+{
+}
+
LocalDataBaseManagerTest::LocalDataBaseManagerTest(QObject *parent)
: QObject(parent)
{
diff --git a/webengineviewer/src/checkphishingurl/localdatabasemanager.cpp b/webengineviewer/src/checkphishingurl/localdatabasemanager.cpp
index 3f31060..b518d19 100644
--- a/webengineviewer/src/checkphishingurl/localdatabasemanager.cpp
+++ b/webengineviewer/src/checkphishingurl/localdatabasemanager.cpp
@@ -175,21 +175,17 @@ void LocalDataBaseManager::slotDownloadDataBaseFinished(const WebEngineViewer::U
qDebug() << "No update necessary ";
} else {
//qDebug() << "infoDataBase" << infoDataBase.additionList.count();
- if (infoDataBase.responseType == WebEngineViewer::UpdateDataBaseInfo::FullUpdate) {
- //TODO Clear database ?
- } else if (infoDataBase.responseType == WebEngineViewer::UpdateDataBaseInfo::Unknown) {
- // ?????
+ switch(infoDataBase.responseType) {
+ case WebEngineViewer::UpdateDataBaseInfo::FullUpdate:
+ fullUpdateDataBase(infoDataBase);
+ break;
+ case WebEngineViewer::UpdateDataBaseInfo::PartialUpdate:
+ partialUpdateDataBase(infoDataBase);
+ break;
+ case WebEngineViewer::UpdateDataBaseInfo::Unknown:
+ //Signal it ?
return;
- }
- Q_FOREACH(const Addition &add, infoDataBase.additionList) {
- //qDebug() << " add.size" << add.prefixSize;
- //qDebug() << " add.hash" << QByteArray::fromBase64(add.hashString).size();
- const QByteArray uncompressed = QByteArray::fromBase64(add.hashString);
- for (int i = 0; i < uncompressed.size();) {
- QByteArray m = uncompressed.mid(i, add.prefixSize);
- i += add.prefixSize;
- //qDebug() << "m " << m << " m.size" << m.size();
- }
+ break;
}
}
}
@@ -200,6 +196,39 @@ void LocalDataBaseManager::slotDownloadDataBaseFinished(const WebEngineViewer::U
}
}
+void LocalDataBaseManager::removeElementFromDataBase(const QVector<Removal> &removalList)
+{
+ Q_FOREACH(const Removal &removeItem, removalList) {
+ //TODO
+ }
+}
+
+void LocalDataBaseManager::addElementToDataBase(const QVector<Addition> &additionList)
+{
+ Q_FOREACH(const Addition &add, additionList) {
+ //qDebug() << " add.size" << add.prefixSize;
+ //qDebug() << " add.hash" << QByteArray::fromBase64(add.hashString).size();
+ const QByteArray uncompressed = QByteArray::fromBase64(add.hashString);
+ for (int i = 0; i < uncompressed.size();) {
+ const QByteArray m = uncompressed.mid(i, add.prefixSize);
+ i += add.prefixSize;
+ //qDebug() << "m " << m << " m.size" << m.size();
+ }
+ }
+}
+
+void LocalDataBaseManager::fullUpdateDataBase(const WebEngineViewer::UpdateDataBaseInfo &infoDataBase)
+{
+ //Clear DataBase
+ addElementToDataBase(infoDataBase.additionList);
+}
+
+void LocalDataBaseManager::partialUpdateDataBase(const WebEngineViewer::UpdateDataBaseInfo &infoDataBase)
+{
+ removeElementFromDataBase(infoDataBase.removalList);
+ addElementToDataBase(infoDataBase.additionList);
+}
+
LocalDataBaseManager *LocalDataBaseManager::self()
{
return s_localDataBaseManager;
diff --git a/webengineviewer/src/checkphishingurl/localdatabasemanager.h b/webengineviewer/src/checkphishingurl/localdatabasemanager.h
index 07cf6ba..b36eb96 100644
--- a/webengineviewer/src/checkphishingurl/localdatabasemanager.h
+++ b/webengineviewer/src/checkphishingurl/localdatabasemanager.h
@@ -62,7 +62,11 @@ private:
void readConfig();
void saveConfig();
+ void fullUpdateDataBase(const WebEngineViewer::UpdateDataBaseInfo &infoDataBase);
void slotDownloadDataBaseFinished(const WebEngineViewer::UpdateDataBaseInfo &infoDataBase, WebEngineViewer::CreatePhishingUrlDataBaseJob::DataBaseDownloadResult status);
+ void partialUpdateDataBase(const WebEngineViewer::UpdateDataBaseInfo &infoDataBase);
+ void addElementToDataBase(const QVector<Addition> &additionList);
+ void removeElementFromDataBase(const QVector<Removal> &removalList);
void slotCheckDataBase();
bool initializeDataBase();