From 77b3cd57f930ec70e6f618da70985e23e5cf76fc Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Fri, 19 Oct 2018 01:44:06 +0200 Subject: 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 --- lib/urlfilter/domain.cpp | 4 ++++ lib/urlfilter/filterleaf.h | 2 +- lib/urlfilter/filtertree.cpp | 4 ++-- lib/urlfilter/filtertree.h | 2 +- lib/urlfilter/formats/hostlistrule.cpp | 5 +++-- lib/urlfilter/formats/hostlistrule.h | 2 +- 6 files changed, 12 insertions(+), 7 deletions(-) (limited to 'lib/urlfilter') 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 FilterTree::match(const QString &domain, const QString &requestUrl) const +QVector FilterTree::match(const QUrl &domain, const QUrl &requestUrl) const { QVector 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 match(const QString &domain, const QString &requestUrl) const; + QVector 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; }; -- cgit v1.2.1