aboutsummaryrefslogtreecommitdiff
path: root/lib/urlfilter/formats/adblockrule.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/urlfilter/formats/adblockrule.cpp')
-rw-r--r--lib/urlfilter/formats/adblockrule.cpp63
1 files changed, 0 insertions, 63 deletions
diff --git a/lib/urlfilter/formats/adblockrule.cpp b/lib/urlfilter/formats/adblockrule.cpp
deleted file mode 100644
index 60e817f..0000000
--- a/lib/urlfilter/formats/adblockrule.cpp
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * This file is part of smolbote. It's copyrighted by the contributors recorded
- * in the version control history of the file, available from its original
- * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote
- *
- * SPDX-License-Identifier: GPL-3.0
- */
-
-#include "adblockrule.h"
-#include <QRegExp>
-#include <QStringMatcher>
-
-AdBlockRule::AdBlockRule(FilterLeaf::UrlMatchType matchType, const QString &filter, FilterLeaf::Action action)
-{
- this->matchType = matchType;
- this->m_request = filter;
- this->m_isBlocking = (action == FilterLeaf::Block);
- //matcher.setPattern(filter);
- if(matchType == FilterLeaf::RegularExpressionMatch)
- regExp = new QRegExp(filter);
- else
- stringMatcher = new QStringMatcher(filter);
-}
-
-void AdBlockRule::mergeOptions(const QHash<QWebEngineUrlRequestInfo::ResourceType, bool> &options)
-{
- this->resourceTypeOptions.unite(options);
-}
-
-bool AdBlockRule::match(const QUrl &requestUrl) const
-{
- switch(matchType) {
- case FilterLeaf::RegularExpressionMatch:
- return (regExp->indexIn(requestUrl.toString()) != -1);
- default:
- return false;
- }
-}
-
-bool AdBlockRule::match(const QUrl &requestUrl, QWebEngineUrlRequestInfo::ResourceType type) const
-{
- // if request is of the required type, or there are no types set (== apply to all requests)
- if(this->resourceTypeOptions.contains(type) || this->resourceTypeOptions.isEmpty()) {
- switch(matchType) {
- case FilterLeaf::RegularExpressionMatch:
- return (regExp->indexIn(requestUrl.toString()) != -1);
- default:
- qWarning("Match type not implemented, returning false!");
- return false;
- }
- }
-
- // request type is not matched
- return false;
-}
-
-std::pair<FilterLeaf::Action, QVariant> AdBlockRule::action() const
-{
- if(m_isBlocking)
- return std::make_pair(FilterLeaf::Block, QVariant());
- else
- return std::make_pair(FilterLeaf::Allow, QVariant());
-}