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 =
"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
;

View File

@ -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);

View File

@ -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
);

View File

@ -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"

View File

@ -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);

View File

@ -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()

View File

@ -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<QStringRef> 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<QStringRef> TaskZoneDownloader::parseAddresses(const QString &text,
return list;
}
bool TaskZoneDownloader::storeAddresses(const QVector<QStringRef> &list) const
bool TaskZoneDownloader::storeAddresses(const QVector<QStringRef> &list,
QString &binChecksum) const
{
Ip4Range ip4Range;
if (!ip4Range.fromList(list, emptyNetMask(), sort()))

View File

@ -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<QStringRef> parseAddresses(const QString &text,
QString &checksum) const;
bool storeAddresses(const QVector<QStringRef> &list) const;
QString &textChecksum) const;
bool storeAddresses(const QVector<QStringRef> &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;