Commit 6e144aec authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Check if we must update database

parent efd80c51
......@@ -54,6 +54,7 @@ LocalDataBaseManager::LocalDataBaseManager(QObject *parent)
mDataBaseOk(false),
mDownloadProgress(false)
{
readConfig();
}
LocalDataBaseManager::~LocalDataBaseManager()
......@@ -76,27 +77,30 @@ void LocalDataBaseManager::closeDataBaseAndDeleteIt()
void LocalDataBaseManager::readConfig()
{
//TODO
KConfig phishingurlKConfig(QStringLiteral("phishingurlrc"));
KConfigGroup grp = phishingurlKConfig.group(QStringLiteral("General"));
mNewClientState = grp.readEntry(QStringLiteral("DataBaseState"));
}
void LocalDataBaseManager::saveConfig()
{
KConfig phishingurlKConfig(QStringLiteral("phishingurlrc"));
//TODO
}
void LocalDataBaseManager::downloadPartialDataBase()
{
mDownloadProgress = true;
setDownloadProgress(true);
WebEngineViewer::CreatePhishingUrlDataBaseJob *job = new WebEngineViewer::CreatePhishingUrlDataBaseJob(this);
job->setDataBaseDownloadNeeded(WebEngineViewer::CreatePhishingUrlDataBaseJob::UpdateDataBase);
job->setDataBaseState(QString()); //TODO
job->setDataBaseState(mNewClientState);
connect(job, &CreatePhishingUrlDataBaseJob::finished, this, &LocalDataBaseManager::slotDownloadDataBaseFinished);
job->start();
}
void LocalDataBaseManager::downloadFullDataBase()
{
mDownloadProgress = true;
setDownloadProgress(true);
WebEngineViewer::CreatePhishingUrlDataBaseJob *job = new WebEngineViewer::CreatePhishingUrlDataBaseJob(this);
job->setDataBaseDownloadNeeded(WebEngineViewer::CreatePhishingUrlDataBaseJob::FullDataBase);
connect(job, &CreatePhishingUrlDataBaseJob::finished, this, &LocalDataBaseManager::slotDownloadDataBaseFinished);
......@@ -166,15 +170,21 @@ void LocalDataBaseManager::slotDownloadDataBaseFinished(const WebEngineViewer::U
break;
}
if (mDataBaseOk) {
//qDebug() << "infoDataBase" << infoDataBase.additionList.count();
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();
if ((infoDataBase.responseType == QLatin1String("PARTIAL_UPDATE")) &&
(mNewClientState == infoDataBase.newClientState)) {
qDebug() << "No update necessary ";
} else {
//Clear database ?
//qDebug() << "infoDataBase" << infoDataBase.additionList.count();
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();
}
}
}
}
......@@ -209,6 +219,11 @@ bool LocalDataBaseManager::createTable()
"hash varchar(32))").arg(tableName()));
}
void LocalDataBaseManager::setDownloadProgress(bool downloadProgress)
{
mDownloadProgress = downloadProgress;
}
void LocalDataBaseManager::checkUrl(const QUrl &url)
{
if (mDataBaseOk) {
......
......@@ -49,10 +49,12 @@ public:
void closeDataBaseAndDeleteIt();
Q_SIGNALS:
void checkUrlFinished(const QUrl &url, WebEngineViewer::LocalDataBaseManager::UrlStatus status);
protected:
void setDownloadProgress(bool downloadProgress);
virtual void downloadFullDataBase();
virtual void downloadPartialDataBase();
......@@ -66,6 +68,7 @@ private:
bool initializeDataBase();
bool createTable();
QSqlDatabase mDataBase;
QString mNewClientState;
QTimer *mRegularCheckDataBaseTimer;
bool mDataBaseOk;
bool mDownloadProgress;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment