diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-07-05 19:37:05 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-07-05 19:37:05 +0200 |
commit | aaed4ebc642d95dfb3cddab4fad196e870077bcf (patch) | |
tree | 1534dccf6ffd1b6ae3f4d85b13201c0d474c3f78 /lib/web/urlfilter/filterrule.h | |
parent | Add filter.header (diff) | |
download | smolbote-aaed4ebc642d95dfb3cddab4fad196e870077bcf.tar.xz |
Add web/urlfilter
Diffstat (limited to 'lib/web/urlfilter/filterrule.h')
-rw-r--r-- | lib/web/urlfilter/filterrule.h | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/lib/web/urlfilter/filterrule.h b/lib/web/urlfilter/filterrule.h new file mode 100644 index 0000000..46690b1 --- /dev/null +++ b/lib/web/urlfilter/filterrule.h @@ -0,0 +1,68 @@ +#ifndef SMOLBOTE_FILTERRULE_H +#define SMOLBOTE_FILTERRULE_H + +#include <QObject> +#include <QRegularExpression> +#include <QStringList> +#include <QStringMatcher> +#include <QJsonObject> +#include <QUrl> +#include <QWebEngineUrlRequestInfo> + +class QUrl; +class FilterRule +{ +public: + FilterRule(const QJsonObject &filter); + ~FilterRule() = default; + + bool isValid() const; + bool process(QWebEngineUrlRequestInfo &info) const; + bool matchRequestUrl(const QString &requestUrl, const QWebEngineUrlRequestInfo::ResourceType type) const; + +private: + Q_DISABLE_COPY(FilterRule) + + enum ActionType { + Whitelist, + Blacklist, + Redirect, + SetHeader + }; + + enum RuleType { + CssRule = 0, // + DomainMatchRule = 1, // + RegExpMatchRule = 2, // match request url with regexp + StringEndsMatchRule = 3, // request url ends with string + StringContainsMatchRule = 4, // request url contains string + MatchAllUrlsRule = 5, // + Invalid = 6 + }; + + ActionType m_action; + RuleType m_type = RuleType::Invalid; + + QHash<QWebEngineUrlRequestInfo::ResourceType, bool> m_options; + + // Parsed rule for string matching (CSS Selector for CSS rules) + QString m_matchString; + // Case sensitivity for string matching + Qt::CaseSensitivity m_caseSensitivity = Qt::CaseInsensitive; + + bool m_isException = false; + + // domains this rule is allowed or blocked on + QStringList m_allowedForDomains; + QStringList m_blockedForDomains; + + QUrl m_redirectUrl; + + QRegularExpression regexp; + QStringMatcher matcher; + QString pattern; +}; + +//bool isMatchingDomain(const QString &domain, const QString &filter); + +#endif // SMOLBOTE_FILTERRULE_H |