UI: TaskZoneDownloader: Add "binChecksum" field.

This commit is contained in:
Nodir Temirkhodjaev 2020-02-07 12:49:35 +05:00
parent 46067f81cf
commit a261ade018
8 changed files with 51 additions and 27 deletions

View File

@ -208,7 +208,8 @@ const char * const sqlUpdateZoneEnabled =
const char * const sqlUpdateZoneResult = const char * const sqlUpdateZoneResult =
"UPDATE zone" "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;" " WHERE zone_id = ?1;"
; ;
@ -743,7 +744,8 @@ bool ConfManager::updateZoneEnabled(qint64 zoneId, bool enabled)
return ok; 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 &lastRun,
const QDateTime &lastSuccess) const QDateTime &lastSuccess)
{ {
@ -751,7 +753,8 @@ bool ConfManager::updateZoneResult(qint64 zoneId, const QString &checksum,
const auto vars = QVariantList() const auto vars = QVariantList()
<< zoneId << zoneId
<< checksum << textChecksum
<< binChecksum
<< lastRun << lastRun
<< lastSuccess << lastSuccess
; ;

View File

@ -75,7 +75,8 @@ public:
bool storeText, bool customUrl); bool storeText, bool customUrl);
bool updateZoneName(qint64 zoneId, const QString &zoneName); bool updateZoneName(qint64 zoneId, const QString &zoneName);
bool updateZoneEnabled(qint64 zoneId, bool enabled); 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 &lastRun,
const QDateTime &lastSuccess); const QDateTime &lastSuccess);

View File

@ -7,7 +7,8 @@ CREATE TABLE zone(
source_code TEXT NOT NULL, source_code TEXT NOT NULL,
url TEXT, url TEXT,
form_data TEXT, form_data TEXT,
checksum TEXT, text_checksum TEXT,
bin_checksum TEXT,
last_run INTEGER, last_run INTEGER,
last_success INTEGER last_success INTEGER
); );

View File

@ -170,11 +170,13 @@ bool ZoneListModel::updateZoneEnabled(qint64 zoneId, bool enabled)
return false; 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 &lastRun,
const QDateTime &lastSuccess) const QDateTime &lastSuccess)
{ {
if (confManager()->updateZoneResult(zoneId, checksum, lastRun, lastSuccess)) { if (confManager()->updateZoneResult(zoneId, textChecksum, binChecksum,
lastRun, lastSuccess)) {
refresh(); refresh();
return true; return true;
} }
@ -219,9 +221,10 @@ bool ZoneListModel::updateTableRow(int row) const
m_zoneRow.sourceCode = stmt.columnText(5); m_zoneRow.sourceCode = stmt.columnText(5);
m_zoneRow.url = stmt.columnText(6); m_zoneRow.url = stmt.columnText(6);
m_zoneRow.formData = stmt.columnText(7); m_zoneRow.formData = stmt.columnText(7);
m_zoneRow.checksum = stmt.columnText(8); m_zoneRow.textChecksum = stmt.columnText(8);
m_zoneRow.lastRun = stmt.columnDateTime(9); m_zoneRow.binChecksum = stmt.columnText(9);
m_zoneRow.lastSuccess = stmt.columnDateTime(10); m_zoneRow.lastRun = stmt.columnDateTime(10);
m_zoneRow.lastSuccess = stmt.columnDateTime(11);
return true; return true;
} }
@ -238,7 +241,8 @@ QString ZoneListModel::sqlBase() const
" source_code," " source_code,"
" url," " url,"
" form_data," " form_data,"
" checksum," " text_checksum,"
" bin_checksum,"
" last_run," " last_run,"
" last_success" " last_success"
" FROM zone" " FROM zone"

View File

@ -22,7 +22,8 @@ struct ZoneRow : TableRow {
QString url; QString url;
QString formData; QString formData;
QString checksum; QString textChecksum;
QString binChecksum;
QDateTime lastRun; QDateTime lastRun;
QDateTime lastSuccess; QDateTime lastSuccess;
@ -61,7 +62,8 @@ public:
bool customUrl, bool updateDriver = true); bool customUrl, bool updateDriver = true);
bool updateZoneName(qint64 zoneId, const QString &zoneName); bool updateZoneName(qint64 zoneId, const QString &zoneName);
bool updateZoneEnabled(qint64 zoneId, bool enabled); 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 &lastRun,
const QDateTime &lastSuccess); const QDateTime &lastSuccess);
void deleteZone(qint64 zoneId, int row); void deleteZone(qint64 zoneId, int row);

View File

@ -65,7 +65,7 @@ void TaskInfoZoneDownloader::setupTaskWorker()
worker->setFormData(zoneRow.customUrl ? zoneRow.formData worker->setFormData(zoneRow.customUrl ? zoneRow.formData
: zoneSource.formData()); : zoneSource.formData());
worker->setPattern(zoneType.pattern()); worker->setPattern(zoneType.pattern());
worker->setChecksum(zoneRow.checksum); worker->setTextChecksum(zoneRow.textChecksum);
worker->setCachePath(cachePath()); worker->setCachePath(cachePath());
worker->setLastSuccess(zoneRow.lastSuccess); worker->setLastSuccess(zoneRow.lastSuccess);
@ -94,12 +94,14 @@ void TaskInfoZoneDownloader::processSubResult(bool success)
auto worker = zoneDownloader(); auto worker = zoneDownloader();
const auto zoneId = worker->zoneId(); 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 now = QDateTime::currentDateTime();
const auto lastSuccess = success ? now : worker->lastSuccess(); const auto lastSuccess = success ? now : worker->lastSuccess();
zoneListModel()->updateZoneResult(zoneId, checksum, now, lastSuccess); zoneListModel()->updateZoneResult(zoneId, textChecksum, binChecksum,
now, lastSuccess);
} }
void TaskInfoZoneDownloader::removeOrphanCacheFiles() void TaskInfoZoneDownloader::removeOrphanCacheFiles()

View File

@ -24,15 +24,18 @@ void TaskZoneDownloader::downloadFinished(bool success)
if (success) { if (success) {
success = false; success = false;
QString checksum; QString textChecksum;
const auto text = QString::fromLatin1(downloader()->buffer()); const auto text = QString::fromLatin1(downloader()->buffer());
const auto list = parseAddresses(text, checksum); const auto list = parseAddresses(text, textChecksum);
if (!list.isEmpty() if (!list.isEmpty()
&& (this->checksum() != checksum && (this->textChecksum() != textChecksum
|| !FileUtil::fileExists(cacheFileBinPath()))) { || !FileUtil::fileExists(cacheFileBinPath()))) {
setChecksum(checksum); setTextChecksum(textChecksum);
success = storeAddresses(list);
QString binChecksum;
success = storeAddresses(list, binChecksum);
setBinChecksum(binChecksum);
} }
} }
@ -58,6 +61,7 @@ QVector<QStringRef> TaskZoneDownloader::parseAddresses(const QString &text,
list.append(ip); list.append(ip);
cryptoHash.addData(ip.toLatin1()); cryptoHash.addData(ip.toLatin1());
cryptoHash.addData("\n");
} }
checksum = QString::fromLatin1(cryptoHash.result().toHex()); checksum = QString::fromLatin1(cryptoHash.result().toHex());
@ -65,7 +69,8 @@ QVector<QStringRef> TaskZoneDownloader::parseAddresses(const QString &text,
return list; return list;
} }
bool TaskZoneDownloader::storeAddresses(const QVector<QStringRef> &list) const bool TaskZoneDownloader::storeAddresses(const QVector<QStringRef> &list,
QString &binChecksum) const
{ {
Ip4Range ip4Range; Ip4Range ip4Range;
if (!ip4Range.fromList(list, emptyNetMask(), sort())) if (!ip4Range.fromList(list, emptyNetMask(), sort()))

View File

@ -33,8 +33,11 @@ public:
QString pattern() const { return m_pattern; } QString pattern() const { return m_pattern; }
void setPattern(const QString &v) { m_pattern = v; } void setPattern(const QString &v) { m_pattern = v; }
QString checksum() const { return m_checksum; } QString textChecksum() const { return m_textChecksum; }
void setChecksum(const QString &v) { m_checksum = v; } 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; } QString cachePath() const { return m_cachePath; }
void setCachePath(const QString &v) { m_cachePath = v; } void setCachePath(const QString &v) { m_cachePath = v; }
@ -43,8 +46,9 @@ public:
void setLastSuccess(const QDateTime &v) { m_lastSuccess = v; } void setLastSuccess(const QDateTime &v) { m_lastSuccess = v; }
QVector<QStringRef> parseAddresses(const QString &text, QVector<QStringRef> parseAddresses(const QString &text,
QString &checksum) const; QString &textChecksum) const;
bool storeAddresses(const QVector<QStringRef> &list) const; bool storeAddresses(const QVector<QStringRef> &list,
QString &binChecksum) const;
QString cacheFileBasePath() const; QString cacheFileBasePath() const;
QString cacheFileBinPath() const; QString cacheFileBinPath() const;
@ -69,7 +73,9 @@ private:
QString m_pattern; QString m_pattern;
QString m_checksum; QString m_textChecksum;
QString m_binChecksum;
QString m_cachePath; QString m_cachePath;
QDateTime m_lastSuccess; QDateTime m_lastSuccess;