From 5f623dcfc8f02504d745f47f8b9274b2bca5fd67 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Thu, 18 Oct 2018 23:39:28 +0200 Subject: urlfilter: destroy FilterLeaves only when destroying the FilterTree Add QMutex lock when adding rules clang-format pass --- lib/urlfilter/filtertree.h | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'lib/urlfilter/filtertree.h') diff --git a/lib/urlfilter/filtertree.h b/lib/urlfilter/filtertree.h index 004cf5a..3da82e0 100644 --- a/lib/urlfilter/filtertree.h +++ b/lib/urlfilter/filtertree.h @@ -9,22 +9,26 @@ #ifndef SMOLBOTE_FILTERTREE_H #define SMOLBOTE_FILTERTREE_H +#include "domain.h" +#include "filterleaf.h" +#include #include #include #include -#include -#include "filterleaf.h" -#include "domain.h" +#include /** FilterTree: B+ tree of filter rules - * The root of the tree contains branches that represent domains, on which their rules are to be applied. - * Each branch contains leaves - rules + * The tree contains branches that represent domains + * Each domain-branch contains leaves (rules) that are to be applied to it. + * Rules may be applied to multiple branches. */ class FilterTree : public QObject { Q_OBJECT public: + ~FilterTree(); + const QStringList branches() const; QVector match(const QString &domain, const QString &requestUrl) const; @@ -32,19 +36,23 @@ public: private: struct Branch { - explicit Branch(const QString &host) : domain(host) {} + explicit Branch(const QString &host) + : domain(host) + { + } explicit Branch(Branch &&other) : domain(std::move(other.domain)) , leaves(std::move(other.leaves)) - {} - ~Branch() { qDeleteAll(leaves); } + { + } - // TODO: replace domain type with domain-matching class Domain domain; - //std::string domain; std::vector leaves; }; + Branch& branch(const QString &domain); + + QMutex branchLock; std::vector m_branches; }; -- cgit v1.2.1