aboutsummaryrefslogtreecommitdiff
path: root/lib/urlfilter/filterrule.h
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-10-01 16:43:18 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-10-02 11:47:49 +0200
commit7d8cbdb9941532cd5bf560b21395f6ed371d1ab5 (patch)
tree9c5a2d72a3882050f2c3c95ec2d15ad21ff98a93 /lib/urlfilter/filterrule.h
parentupdater: windows fixes (diff)
downloadsmolbote-7d8cbdb9941532cd5bf560b21395f6ed371d1ab5.tar.xz
Split off UrlFilter into library
- add more adblock filter options
Diffstat (limited to 'lib/urlfilter/filterrule.h')
-rw-r--r--lib/urlfilter/filterrule.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/lib/urlfilter/filterrule.h b/lib/urlfilter/filterrule.h
new file mode 100644
index 0000000..95fff6a
--- /dev/null
+++ b/lib/urlfilter/filterrule.h
@@ -0,0 +1,55 @@
+/*
+ * 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/smolbote.hg
+ *
+ * SPDX-License-Identifier: GPL-3.0
+ */
+
+#ifndef SMOLBOTE_FILTERRULE_H
+#define SMOLBOTE_FILTERRULE_H
+
+#include <QObject>
+#include <QRegularExpression>
+#include <QStringList>
+#include <QStringMatcher>
+#include <QUrl>
+#include <QWebEngineUrlRequestInfo>
+#include <memory>
+#include <QVector>
+
+class FilterRule
+{
+public:
+ enum UrlMatchType {
+ InvalidMatch,
+ RegularExpressionMatch,
+ StringContains,
+ StringStartsWith,
+ StringEndsWith,
+ StringEquals,
+ DomainMatch
+ };
+
+ bool isEnabled() const;
+ bool isBlocking() const;
+
+ bool matchesDomain(uint domainHash) const;
+ bool matchesType(QWebEngineUrlRequestInfo::ResourceType type) const;
+ bool matchesUrl(const QUrl &url) const;
+
+protected:
+ bool m_isEnabled = false;
+ bool m_isBlocking = true;
+
+ UrlMatchType urlMatchType = InvalidMatch;
+ QHash<QWebEngineUrlRequestInfo::ResourceType, bool> m_resourceTypeOptions;
+
+ QVector<uint> allowedDomains_hashes, blockedDomains_hashes;
+
+ QString match;
+ QRegularExpression regexp;
+
+};
+
+#endif // SMOLBOTE_FILTERRULE_H