aboutsummaryrefslogtreecommitdiff
path: root/lib/web/urlfilter/filterrule.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/web/urlfilter/filterrule.h')
-rw-r--r--lib/web/urlfilter/filterrule.h78
1 files changed, 35 insertions, 43 deletions
diff --git a/lib/web/urlfilter/filterrule.h b/lib/web/urlfilter/filterrule.h
index f20ab15..8a622fe 100644
--- a/lib/web/urlfilter/filterrule.h
+++ b/lib/web/urlfilter/filterrule.h
@@ -1,70 +1,62 @@
#ifndef SMOLBOTE_FILTERRULE_H
#define SMOLBOTE_FILTERRULE_H
-#include <QObject>
#include <QRegularExpression>
#include <QStringList>
#include <QStringMatcher>
-#include <QJsonObject>
#include <QUrl>
#include <QWebEngineUrlRequestInfo>
#include <memory>
-class QUrl;
class FilterRule
{
public:
- enum ActionType {
- Whitelist,
- Blacklist,
- Redirect,
- SetHeader,
- InvalidAction
+ enum UrlMatchType {
+ InvalidMatch,
+ RegularExpressionMatch,
+ StringContains,
+ StringStartsWith,
+ StringEndsWith,
+ StringEquals,
+ DomainMatch
};
- enum MatchType {
-// 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, //
- InvalidMatch = 6,
- };
-
- FilterRule(const QJsonObject &filter);
- ~FilterRule() = default;
+ FilterRule() = default;
- void setActionType(ActionType type);
- void setMatchType(MatchType type, const QString &pattern = QString());
- void setRedirectUrl(const QUrl &url);
- void addHeaderRule(const QByteArray &header, const QByteArray &value);
+ bool isEnabled() const;
- bool isValid() const;
- bool process(QWebEngineUrlRequestInfo &info) const;
- bool matchRequestUrl(const QString &requestUrl, const QWebEngineUrlRequestInfo::ResourceType type) const;
+ /**
+ * @brief matchesDomain
+ * @param domain
+ * @return
+ */
+ bool matchesDomain(const QString &domain) const;
-private:
- Q_DISABLE_COPY(FilterRule)
+ /**
+ * @brief matchesType
+ * @param type
+ * @return true if type matches, false otherwise
+ */
+ bool matchesType(QWebEngineUrlRequestInfo::ResourceType type) const;
+ /**
+ * @brief matchesUrl
+ * @param url
+ * @return
+ */
+ bool matchesUrl(const QUrl &url) const;
- ActionType m_actionType = ActionType::InvalidAction;
- MatchType m_matchType = MatchType::InvalidMatch;
+protected:
+ bool m_isEnabled = false;
+ bool m_isException = false;
+ UrlMatchType urlMatchType = InvalidMatch;
QHash<QWebEngineUrlRequestInfo::ResourceType, bool> m_resourceTypeOptions;
- QHash<QByteArray, QByteArray> m_headers;
+ QStringList allowedDomains, blockedDomains;
- // Parsed rule for string matching (CSS Selector for CSS rules)
- QString m_matchString;
- // Case sensitivity for string matching
- Qt::CaseSensitivity m_caseSensitivity = Qt::CaseInsensitive;
+ QString match;
+ QRegularExpression regexp;
- QUrl m_redirectUrl;
- QRegularExpression m_regexp;
- QStringMatcher m_matcher;
- QString m_pattern;
};
-void parseJson(std::unique_ptr<FilterRule> &rule, const QJsonObject &filter);
-
#endif // SMOLBOTE_FILTERRULE_H