aboutsummaryrefslogtreecommitdiff
path: root/lib/urlfilter
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-10-19 01:44:06 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-10-19 01:44:06 +0200
commit77b3cd57f930ec70e6f618da70985e23e5cf76fc (patch)
tree712dbb43ec463a8524286d9e6e0fb2d2f8b9d6ab /lib/urlfilter
parenturlfilter: destroy FilterLeaves only when destroying the FilterTree (diff)
downloadsmolbote-77b3cd57f930ec70e6f618da70985e23e5cf76fc.tar.xz
Integrate FilterTree into browser (#6)
- change filter.path to filter.hosts to represent that the setting is only used for hostlist-format lists - change FilterTree::match to use QUrl and not QString
Diffstat (limited to 'lib/urlfilter')
-rw-r--r--lib/urlfilter/domain.cpp4
-rw-r--r--lib/urlfilter/filterleaf.h2
-rw-r--r--lib/urlfilter/filtertree.cpp4
-rw-r--r--lib/urlfilter/filtertree.h2
-rw-r--r--lib/urlfilter/formats/hostlistrule.cpp5
-rw-r--r--lib/urlfilter/formats/hostlistrule.h2
6 files changed, 12 insertions, 7 deletions
diff --git a/lib/urlfilter/domain.cpp b/lib/urlfilter/domain.cpp
index 20c4f3a..2bfd524 100644
--- a/lib/urlfilter/domain.cpp
+++ b/lib/urlfilter/domain.cpp
@@ -29,6 +29,10 @@ Domain &Domain::operator=(Domain &&other)
bool Domain::matches(const QUrl &url) const
{
+ // empty domain matches all
+ if(m_domain.isEmpty() || url.isEmpty())
+ return true;
+
const QString domain = url.host();
// domain and filter are the same
diff --git a/lib/urlfilter/filterleaf.h b/lib/urlfilter/filterleaf.h
index 36c00e9..dcd3ec0 100644
--- a/lib/urlfilter/filterleaf.h
+++ b/lib/urlfilter/filterleaf.h
@@ -28,7 +28,7 @@ public:
FilterLeaf &operator=(FilterLeaf &&other);
~FilterLeaf() = default;
- virtual bool match(const QString &requestUrl) const = 0;
+ virtual bool match(const QUrl &requestUrl) const = 0;
virtual Action action() const = 0;
const QString request() const;
diff --git a/lib/urlfilter/filtertree.cpp b/lib/urlfilter/filtertree.cpp
index dcde196..2cdd6d0 100644
--- a/lib/urlfilter/filtertree.cpp
+++ b/lib/urlfilter/filtertree.cpp
@@ -57,11 +57,11 @@ const QStringList FilterTree::branches() const
return branches;
}
-QVector<const FilterLeaf *> FilterTree::match(const QString &domain, const QString &requestUrl) const
+QVector<const FilterLeaf *> FilterTree::match(const QUrl &domain, const QUrl &requestUrl) const
{
QVector<const FilterLeaf *> leaves;
for(const auto &branch : m_branches) {
- if(branch.domain.matches(QUrl(domain))) {
+ if(branch.domain.matches(domain)) {
for(const auto leaf : branch.leaves) {
if(leaf->match(requestUrl)) {
diff --git a/lib/urlfilter/filtertree.h b/lib/urlfilter/filtertree.h
index 3da82e0..f453a3d 100644
--- a/lib/urlfilter/filtertree.h
+++ b/lib/urlfilter/filtertree.h
@@ -30,7 +30,7 @@ public:
~FilterTree();
const QStringList branches() const;
- QVector<const FilterLeaf *> match(const QString &domain, const QString &requestUrl) const;
+ QVector<const FilterLeaf *> match(const QUrl &domain, const QUrl &requestUrl) const;
bool addRule(FilterLeaf *rule, const QString &domain);
diff --git a/lib/urlfilter/formats/hostlistrule.cpp b/lib/urlfilter/formats/hostlistrule.cpp
index f0cb4af..e4561f0 100644
--- a/lib/urlfilter/formats/hostlistrule.cpp
+++ b/lib/urlfilter/formats/hostlistrule.cpp
@@ -15,9 +15,10 @@ HostlistRule::HostlistRule(const QString &domain, const QString &redirect)
this->m_redirect = redirect;
}
-bool HostlistRule::match(const QString &requestUrl) const
+bool HostlistRule::match(const QUrl &requestUrl) const
{
- return (m_request == requestUrl);
+ //qDebug("checking [%s] against [%s]", qUtf8Printable(requestUrl.host()), qUtf8Printable(m_request));
+ return (m_request == requestUrl.host());
}
FilterLeaf::Action HostlistRule::action() const
diff --git a/lib/urlfilter/formats/hostlistrule.h b/lib/urlfilter/formats/hostlistrule.h
index 19fd63f..c65a98f 100644
--- a/lib/urlfilter/formats/hostlistrule.h
+++ b/lib/urlfilter/formats/hostlistrule.h
@@ -17,7 +17,7 @@ class HostlistRule : public FilterLeaf
public:
explicit HostlistRule(const QString &domain, const QString &redirect);
- bool match(const QString &requestUrl) const override;
+ bool match(const QUrl &requestUrl) const override;
FilterLeaf::Action action() const override;
};