diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-07-18 10:07:51 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-07-18 10:07:51 +0200 |
commit | f507a7a5557c7cca9570c684920e055c5251b08e (patch) | |
tree | 0fad83fc99053006b375608e2a2d04388776ad89 /lib/web/urlfilter/filterdomain.cpp | |
parent | AdBlockTest: loading subscription (diff) | |
download | smolbote-f507a7a5557c7cca9570c684920e055c5251b08e.tar.xz |
AdBlockRule: move matching logic to FilterRule
Diffstat (limited to 'lib/web/urlfilter/filterdomain.cpp')
-rw-r--r-- | lib/web/urlfilter/filterdomain.cpp | 68 |
1 files changed, 0 insertions, 68 deletions
diff --git a/lib/web/urlfilter/filterdomain.cpp b/lib/web/urlfilter/filterdomain.cpp deleted file mode 100644 index 99cc71c..0000000 --- a/lib/web/urlfilter/filterdomain.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include "filterdomain.h" -#include <QVector> - -bool isMatchingDomain(const QString &domain, const QString &filter) -{ - // domain and filter are the same - if(domain == filter) { - return true; - } - - // domain can't be matched by filter if it doesn't end with filter - // ex. example2.com isn't matched by example.com - if(!domain.endsWith(filter)) { - return false; - } - - // match with subdomains - // ex. subdomain.example.com is matched by example.com - int index = domain.indexOf(filter); - - // match if (domain ends with filter) && (filter has been found) and (character before filter is '.') - return index > 0 && domain[index - 1] == QLatin1Char('.'); -} - -FilterDomain::FilterDomain(QObject *parent) - : QObject(parent) -{ -} - -void FilterDomain::addDomain(const QString &domain, bool isException) -{ - if(domain.isEmpty()) - return; - - if(!isException) - m_allowedOnDomains.append(domain); - else - m_blockedOnDomains.append(domain); -} - -void FilterDomain::addRule(FilterRule_ptr &rule) -{ - Q_ASSERT(rule); - m_rules.emplace_back(std::move(rule)); -} - -bool FilterDomain::hasMatch(const QString &host) const -{ - for(const auto &domain : qAsConst(m_blockedOnDomains)) { - if(isMatchingDomain(host, domain)) - return false; - } - - for(const auto &domain : qAsConst(m_allowedOnDomains)) { - if(isMatchingDomain(host, domain)) - return true; - } - - return false; -} - -void FilterDomain::process(QWebEngineUrlRequestInfo &info) const -{ - for(const FilterRule_ptr &rule : m_rules) { - if(rule->matchRequestUrl(info.requestUrl().toString(), info.resourceType())) - rule->process(info); - } -} |