From a261ade0186ff55c10de6c17aca47b89f900bc26 Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Fri, 7 Feb 2020 12:49:35 +0500 Subject: [PATCH] UI: TaskZoneDownloader: Add "binChecksum" field. --- src/ui/conf/confmanager.cpp | 9 ++++++--- src/ui/conf/confmanager.h | 3 ++- src/ui/conf/migrations/1.sql | 3 ++- src/ui/model/zonelistmodel.cpp | 16 ++++++++++------ src/ui/model/zonelistmodel.h | 6 ++++-- src/ui/task/taskinfozonedownloader.cpp | 8 +++++--- src/ui/task/taskzonedownloader.cpp | 17 +++++++++++------ src/ui/task/taskzonedownloader.h | 16 +++++++++++----- 8 files changed, 51 insertions(+), 27 deletions(-) diff --git a/src/ui/conf/confmanager.cpp b/src/ui/conf/confmanager.cpp index c92a9c52..7d1825bf 100644 --- a/src/ui/conf/confmanager.cpp +++ b/src/ui/conf/confmanager.cpp @@ -208,7 +208,8 @@ const char * const sqlUpdateZoneEnabled = const char * const sqlUpdateZoneResult = "UPDATE zone" - " SET checksum = ?2, last_run = ?3, last_success = ?4" + " SET text_checksum = ?2, bin_checksum = ?3," + " last_run = ?4, last_success = ?5" " WHERE zone_id = ?1;" ; @@ -743,7 +744,8 @@ bool ConfManager::updateZoneEnabled(qint64 zoneId, bool enabled) return ok; } -bool ConfManager::updateZoneResult(qint64 zoneId, const QString &checksum, +bool ConfManager::updateZoneResult(qint64 zoneId, const QString &textChecksum, + const QString &binChecksum, const QDateTime &lastRun, const QDateTime &lastSuccess) { @@ -751,7 +753,8 @@ bool ConfManager::updateZoneResult(qint64 zoneId, const QString &checksum, const auto vars = QVariantList() << zoneId - << checksum + << textChecksum + << binChecksum << lastRun << lastSuccess ; diff --git a/src/ui/conf/confmanager.h b/src/ui/conf/confmanager.h index 38c386a2..97d507ee 100644 --- a/src/ui/conf/confmanager.h +++ b/src/ui/conf/confmanager.h @@ -75,7 +75,8 @@ public: bool storeText, bool customUrl); bool updateZoneName(qint64 zoneId, const QString &zoneName); bool updateZoneEnabled(qint64 zoneId, bool enabled); - bool updateZoneResult(qint64 zoneId, const QString &checksum, + bool updateZoneResult(qint64 zoneId, const QString &textChecksum, + const QString &binChecksum, const QDateTime &lastRun, const QDateTime &lastSuccess); diff --git a/src/ui/conf/migrations/1.sql b/src/ui/conf/migrations/1.sql index b8d250ec..ab52a7a0 100644 --- a/src/ui/conf/migrations/1.sql +++ b/src/ui/conf/migrations/1.sql @@ -7,7 +7,8 @@ CREATE TABLE zone( source_code TEXT NOT NULL, url TEXT, form_data TEXT, - checksum TEXT, + text_checksum TEXT, + bin_checksum TEXT, last_run INTEGER, last_success INTEGER ); diff --git a/src/ui/model/zonelistmodel.cpp b/src/ui/model/zonelistmodel.cpp index 634ad005..3d7576d2 100644 --- a/src/ui/model/zonelistmodel.cpp +++ b/src/ui/model/zonelistmodel.cpp @@ -170,11 +170,13 @@ bool ZoneListModel::updateZoneEnabled(qint64 zoneId, bool enabled) return false; } -bool ZoneListModel::updateZoneResult(qint64 zoneId, const QString &checksum, +bool ZoneListModel::updateZoneResult(qint64 zoneId, const QString &textChecksum, + const QString &binChecksum, const QDateTime &lastRun, const QDateTime &lastSuccess) { - if (confManager()->updateZoneResult(zoneId, checksum, lastRun, lastSuccess)) { + if (confManager()->updateZoneResult(zoneId, textChecksum, binChecksum, + lastRun, lastSuccess)) { refresh(); return true; } @@ -219,9 +221,10 @@ bool ZoneListModel::updateTableRow(int row) const m_zoneRow.sourceCode = stmt.columnText(5); m_zoneRow.url = stmt.columnText(6); m_zoneRow.formData = stmt.columnText(7); - m_zoneRow.checksum = stmt.columnText(8); - m_zoneRow.lastRun = stmt.columnDateTime(9); - m_zoneRow.lastSuccess = stmt.columnDateTime(10); + m_zoneRow.textChecksum = stmt.columnText(8); + m_zoneRow.binChecksum = stmt.columnText(9); + m_zoneRow.lastRun = stmt.columnDateTime(10); + m_zoneRow.lastSuccess = stmt.columnDateTime(11); return true; } @@ -238,7 +241,8 @@ QString ZoneListModel::sqlBase() const " source_code," " url," " form_data," - " checksum," + " text_checksum," + " bin_checksum," " last_run," " last_success" " FROM zone" diff --git a/src/ui/model/zonelistmodel.h b/src/ui/model/zonelistmodel.h index ea6cb13a..1b779399 100644 --- a/src/ui/model/zonelistmodel.h +++ b/src/ui/model/zonelistmodel.h @@ -22,7 +22,8 @@ struct ZoneRow : TableRow { QString url; QString formData; - QString checksum; + QString textChecksum; + QString binChecksum; QDateTime lastRun; QDateTime lastSuccess; @@ -61,7 +62,8 @@ public: bool customUrl, bool updateDriver = true); bool updateZoneName(qint64 zoneId, const QString &zoneName); bool updateZoneEnabled(qint64 zoneId, bool enabled); - bool updateZoneResult(qint64 zoneId, const QString &checksum, + bool updateZoneResult(qint64 zoneId, const QString &textChecksum, + const QString &binChecksum, const QDateTime &lastRun, const QDateTime &lastSuccess); void deleteZone(qint64 zoneId, int row); diff --git a/src/ui/task/taskinfozonedownloader.cpp b/src/ui/task/taskinfozonedownloader.cpp index bd28317b..8b833b88 100644 --- a/src/ui/task/taskinfozonedownloader.cpp +++ b/src/ui/task/taskinfozonedownloader.cpp @@ -65,7 +65,7 @@ void TaskInfoZoneDownloader::setupTaskWorker() worker->setFormData(zoneRow.customUrl ? zoneRow.formData : zoneSource.formData()); worker->setPattern(zoneType.pattern()); - worker->setChecksum(zoneRow.checksum); + worker->setTextChecksum(zoneRow.textChecksum); worker->setCachePath(cachePath()); worker->setLastSuccess(zoneRow.lastSuccess); @@ -94,12 +94,14 @@ void TaskInfoZoneDownloader::processSubResult(bool success) auto worker = zoneDownloader(); const auto zoneId = worker->zoneId(); - const auto checksum = worker->checksum(); + const auto textChecksum = worker->textChecksum(); + const auto binChecksum = worker->binChecksum(); const auto now = QDateTime::currentDateTime(); const auto lastSuccess = success ? now : worker->lastSuccess(); - zoneListModel()->updateZoneResult(zoneId, checksum, now, lastSuccess); + zoneListModel()->updateZoneResult(zoneId, textChecksum, binChecksum, + now, lastSuccess); } void TaskInfoZoneDownloader::removeOrphanCacheFiles() diff --git a/src/ui/task/taskzonedownloader.cpp b/src/ui/task/taskzonedownloader.cpp index aa38ecaa..b352d20f 100644 --- a/src/ui/task/taskzonedownloader.cpp +++ b/src/ui/task/taskzonedownloader.cpp @@ -24,15 +24,18 @@ void TaskZoneDownloader::downloadFinished(bool success) if (success) { success = false; - QString checksum; + QString textChecksum; const auto text = QString::fromLatin1(downloader()->buffer()); - const auto list = parseAddresses(text, checksum); + const auto list = parseAddresses(text, textChecksum); if (!list.isEmpty() - && (this->checksum() != checksum + && (this->textChecksum() != textChecksum || !FileUtil::fileExists(cacheFileBinPath()))) { - setChecksum(checksum); - success = storeAddresses(list); + setTextChecksum(textChecksum); + + QString binChecksum; + success = storeAddresses(list, binChecksum); + setBinChecksum(binChecksum); } } @@ -58,6 +61,7 @@ QVector TaskZoneDownloader::parseAddresses(const QString &text, list.append(ip); cryptoHash.addData(ip.toLatin1()); + cryptoHash.addData("\n"); } checksum = QString::fromLatin1(cryptoHash.result().toHex()); @@ -65,7 +69,8 @@ QVector TaskZoneDownloader::parseAddresses(const QString &text, return list; } -bool TaskZoneDownloader::storeAddresses(const QVector &list) const +bool TaskZoneDownloader::storeAddresses(const QVector &list, + QString &binChecksum) const { Ip4Range ip4Range; if (!ip4Range.fromList(list, emptyNetMask(), sort())) diff --git a/src/ui/task/taskzonedownloader.h b/src/ui/task/taskzonedownloader.h index e53dfaf7..91baeb96 100644 --- a/src/ui/task/taskzonedownloader.h +++ b/src/ui/task/taskzonedownloader.h @@ -33,8 +33,11 @@ public: QString pattern() const { return m_pattern; } void setPattern(const QString &v) { m_pattern = v; } - QString checksum() const { return m_checksum; } - void setChecksum(const QString &v) { m_checksum = v; } + QString textChecksum() const { return m_textChecksum; } + void setTextChecksum(const QString &v) { m_textChecksum = v; } + + QString binChecksum() const { return m_binChecksum; } + void setBinChecksum(const QString &v) { m_binChecksum = v; } QString cachePath() const { return m_cachePath; } void setCachePath(const QString &v) { m_cachePath = v; } @@ -43,8 +46,9 @@ public: void setLastSuccess(const QDateTime &v) { m_lastSuccess = v; } QVector parseAddresses(const QString &text, - QString &checksum) const; - bool storeAddresses(const QVector &list) const; + QString &textChecksum) const; + bool storeAddresses(const QVector &list, + QString &binChecksum) const; QString cacheFileBasePath() const; QString cacheFileBinPath() const; @@ -69,7 +73,9 @@ private: QString m_pattern; - QString m_checksum; + QString m_textChecksum; + QString m_binChecksum; + QString m_cachePath; QDateTime m_lastSuccess;