summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-11-20 16:45:21 (GMT)
committerMontel Laurent <montel@kde.org>2016-11-20 16:45:21 (GMT)
commitd9ac1d0877d844a793e4a0fccdf08dda311bef62 (patch)
tree97f583ba6e1026912b2745cb2771e9db3202fea0
parentc9d5c0a1637074d58a46807ee414c87d023d3d57 (diff)
Improve localfile support
-rw-r--r--webengineviewer/src/checkphishingurl/localdatabasefile.cpp28
-rw-r--r--webengineviewer/src/checkphishingurl/localdatabasefile.h29
2 files changed, 51 insertions, 6 deletions
diff --git a/webengineviewer/src/checkphishingurl/localdatabasefile.cpp b/webengineviewer/src/checkphishingurl/localdatabasefile.cpp
index 3d5a9aa..99fa7b6 100644
--- a/webengineviewer/src/checkphishingurl/localdatabasefile.cpp
+++ b/webengineviewer/src/checkphishingurl/localdatabasefile.cpp
@@ -22,9 +22,10 @@
using namespace WebEngineViewer;
LocalDataBaseFile::LocalDataBaseFile(const QString &filename)
- : mFileName(filename)
+ : mFile(filename),
+ mValid(false)
{
-
+ load();
}
LocalDataBaseFile::~LocalDataBaseFile()
@@ -32,7 +33,26 @@ LocalDataBaseFile::~LocalDataBaseFile()
}
-void LocalDataBaseFile::initialize()
+bool LocalDataBaseFile::load()
+{
+ if (!mFile.open(QIODevice::ReadOnly))
+ return false;
+ mData = mFile.map(0, mFile.size());
+ if (mData) {
+ const int major = getUint16(0);
+ const int minor = getUint16(2);
+ mValid = (major == 1 && minor >= 1 && minor <= 2);
+ }
+ mMtime = QFileInfo(mFile).lastModified();
+ return mValid;
+}
+
+bool LocalDataBaseFile::reload()
{
- //TODO
+ mValid = false;
+ if (mFile.isOpen()) {
+ mFile.close();
+ }
+ mData = 0;
+ return load();
}
diff --git a/webengineviewer/src/checkphishingurl/localdatabasefile.h b/webengineviewer/src/checkphishingurl/localdatabasefile.h
index e4c0614..fe9213d 100644
--- a/webengineviewer/src/checkphishingurl/localdatabasefile.h
+++ b/webengineviewer/src/checkphishingurl/localdatabasefile.h
@@ -21,6 +21,10 @@
#define LOCALDATABASEFILE_H
#include <QString>
+#include <QDateTime>
+#include <QFile>
+#include <QFileInfo>
+#include <QtEndian>
namespace WebEngineViewer
{
@@ -29,9 +33,30 @@ class LocalDataBaseFile
public:
LocalDataBaseFile(const QString &filename);
~LocalDataBaseFile();
+
+ bool isValid() const { return mValid; }
+ inline quint16 getUint16(int offset) const
+ {
+ return qFromBigEndian(*reinterpret_cast<quint16 *>(mData + offset));
+ }
+ inline quint32 getUint32(int offset) const
+ {
+ return qFromBigEndian(*reinterpret_cast<quint32 *>(mData + offset));
+ }
+ inline const char *getCharStar(int offset) const
+ {
+ return reinterpret_cast<const char *>(mData + offset);
+ }
+
+
private:
- void initialize();
- QString mFileName;
+ bool load();
+ bool reload();
+
+ QFile mFile;
+ uchar *mData;
+ QDateTime mMtime;
+ bool mValid;
};
}