From c74367d82c1c7bec393548d2e5014c794333822f Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Tue, 16 Oct 2018 17:25:40 +0200 Subject: urlfilter: Add FilterTree class FilterTree is a class that holds filter rules, sorted by the domain they are to be applied on. The rules are to follow FilterLeaf as interface. - Add a hostlist rule format to FilterTree. - Add a test for hostlist format. --- lib/urlfilter/formats/hostlistrule.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 lib/urlfilter/formats/hostlistrule.cpp (limited to 'lib/urlfilter/formats/hostlistrule.cpp') diff --git a/lib/urlfilter/formats/hostlistrule.cpp b/lib/urlfilter/formats/hostlistrule.cpp new file mode 100644 index 0000000..1df6b3e --- /dev/null +++ b/lib/urlfilter/formats/hostlistrule.cpp @@ -0,0 +1,21 @@ +#include "hostlistrule.h" + +HostlistRule::HostlistRule(const QString &domain, const QString& redirect) +{ + this->m_isBlocking = (redirect == QLatin1Literal("0.0.0.0")); + this->m_request = domain.toStdString(); + this->m_redirect = redirect.toStdString(); +} + +bool HostlistRule::match(const QString& requestUrl) const +{ + return (m_request == requestUrl.toStdString()); +} + +FilterLeaf::Action HostlistRule::action() const +{ + if(m_isBlocking) + return FilterLeaf::Block; + return FilterLeaf::Redirect; +} + -- cgit v1.2.1