summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMontel Laurent <montel@kde.org>2016-11-10 20:26:54 (GMT)
committerMontel Laurent <montel@kde.org>2016-11-10 20:26:54 (GMT)
commita20268fb6f40580d59ad367175f7548e4d4a9002 (patch)
tree108fef362c8167f2fcc37a03c609f9b5727e3ba4
parentf111a3ef8b531e859012d5b58a50ec467f9b9a7e (diff)
Add a cache for check phishing url
-rw-r--r--webengineviewer/src/CMakeLists.txt2
-rw-r--r--webengineviewer/src/checkphishingurl/checkphishingurlcache.cpp87
-rw-r--r--webengineviewer/src/checkphishingurl/checkphishingurlcache.h64
3 files changed, 153 insertions, 0 deletions
diff --git a/webengineviewer/src/CMakeLists.txt b/webengineviewer/src/CMakeLists.txt
index 663c2af..b596f1e 100644
--- a/webengineviewer/src/CMakeLists.txt
+++ b/webengineviewer/src/CMakeLists.txt
@@ -32,6 +32,7 @@ set(libwebengineviewer_webengine_SRCS
set(libwebengineviewer_checkphishingurl_SRCS
checkphishingurl/checkphishingurljob.cpp
+ checkphishingurl/checkphishingurlcache.cpp
)
set(libwebengineviewer_interceptor_SRCS
@@ -143,6 +144,7 @@ ecm_generate_headers(WebEngineViewer_Camelcasewebengine_manager_HEADERS
ecm_generate_headers(WebEngineViewer_Camelcasewebengine_checkurl_HEADERS
HEADER_NAMES
CheckPhishingUrlJob
+ CheckPhishingUrlCache
REQUIRED_HEADERS WebEngineViewer_webengine_checkurl_HEADERS
PREFIX WebEngineViewer
RELATIVE checkphishingurl
diff --git a/webengineviewer/src/checkphishingurl/checkphishingurlcache.cpp b/webengineviewer/src/checkphishingurl/checkphishingurlcache.cpp
new file mode 100644
index 0000000..21dd6c6
--- /dev/null
+++ b/webengineviewer/src/checkphishingurl/checkphishingurlcache.cpp
@@ -0,0 +1,87 @@
+/*
+ Copyright (C) 2016 Laurent Montel <montel@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "checkphishingurlcache.h"
+#include <QMap>
+
+using namespace WebEngineViewer;
+
+Q_GLOBAL_STATIC(CheckPhishingUrlCache, s_checkPhishingUrlCache)
+
+class WebEngineViewer::CheckPhishingUrlCachePrivate
+{
+public:
+ CheckPhishingUrlCachePrivate()
+ {
+
+ }
+ CheckPhishingUrlCache::UrlStatus urlStatus(const QUrl &url);
+ void setCheckingUrlResult(const QUrl &url, bool correctUrl);
+ void clearCache();
+private:
+ QMap<QUrl, CheckPhishingUrlCache::UrlStatus> mCacheCheckedUrl;
+};
+
+void CheckPhishingUrlCachePrivate::clearCache()
+{
+ mCacheCheckedUrl.clear();
+}
+
+CheckPhishingUrlCache::UrlStatus CheckPhishingUrlCachePrivate::urlStatus(const QUrl &url)
+{
+ return mCacheCheckedUrl.value(url, CheckPhishingUrlCache::Unknown);
+}
+
+void CheckPhishingUrlCachePrivate::setCheckingUrlResult(const QUrl &url, bool correctUrl)
+{
+ mCacheCheckedUrl.insert(url, correctUrl ? CheckPhishingUrlCache::UrlOk : CheckPhishingUrlCache::MalWare);
+}
+
+CheckPhishingUrlCache::CheckPhishingUrlCache(QObject *parent)
+ : QObject(parent),
+ d(new CheckPhishingUrlCachePrivate)
+{
+
+}
+
+CheckPhishingUrlCache::~CheckPhishingUrlCache()
+{
+ delete d;
+}
+
+void CheckPhishingUrlCache::setCheckingUrlResult(const QUrl &url, bool correctUrl)
+{
+ d->setCheckingUrlResult(url, correctUrl);
+}
+
+CheckPhishingUrlCache::UrlStatus CheckPhishingUrlCache::urlStatus(const QUrl &url)
+{
+ return d->urlStatus(url);
+}
+
+void CheckPhishingUrlCache::clearCache()
+{
+ d->clearCache();
+}
+
+CheckPhishingUrlCache *CheckPhishingUrlCache::self()
+{
+ return s_checkPhishingUrlCache;
+}
+
diff --git a/webengineviewer/src/checkphishingurl/checkphishingurlcache.h b/webengineviewer/src/checkphishingurl/checkphishingurlcache.h
new file mode 100644
index 0000000..90f4ac6
--- /dev/null
+++ b/webengineviewer/src/checkphishingurl/checkphishingurlcache.h
@@ -0,0 +1,64 @@
+/*
+ Copyright (C) 2016 Laurent Montel <montel@kde.org>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef CHECKPHISHINGURLCACHE_H
+#define CHECKPHISHINGURLCACHE_H
+
+#include "webengineviewer_export.h"
+#include <QObject>
+#include <QUrl>
+
+namespace WebEngineViewer
+{
+class CheckPhishingUrlCachePrivate;
+class WEBENGINEVIEWER_EXPORT CheckPhishingUrlCache: public QObject
+{
+ Q_OBJECT
+public:
+ static CheckPhishingUrlCache *self();
+
+ enum UrlStatus {
+ UrlOk = 0,
+ MalWare = 1,
+ Unknown = 2
+ };
+
+ explicit CheckPhishingUrlCache(QObject *parent = Q_NULLPTR);
+ ~CheckPhishingUrlCache();
+
+ /**
+ * @brief setCheckingUrlResult cache url. If @p correctUrl is true we store as UrlOk otherwise MalWare
+ * @param url
+ * @param correctUrl
+ */
+ void setCheckingUrlResult(const QUrl &url, bool correctUrl);
+ /**
+ * @brief urlStatus Return the status of cached Url. When we didn't stored it it returns Unknown
+ * @param url
+ * @return the status of url
+ */
+ CheckPhishingUrlCache::UrlStatus urlStatus(const QUrl &url);
+
+ void clearCache();
+private:
+ CheckPhishingUrlCachePrivate *const d;
+};
+}
+
+#endif // CHECKPHISHINGURLCACHE_H