diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-10-18 23:39:28 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-10-19 00:30:13 +0200 |
commit | 5f623dcfc8f02504d745f47f8b9274b2bca5fd67 (patch) | |
tree | f7d6719f6c48c6c038e41631727ccc2ea3368461 /lib/urlfilter/filtertree.h | |
parent | urlfilter: add Domain class (diff) | |
download | smolbote-5f623dcfc8f02504d745f47f8b9274b2bca5fd67.tar.xz |
urlfilter: destroy FilterLeaves only when destroying the FilterTree
Add QMutex lock when adding rules
clang-format pass
Diffstat (limited to 'lib/urlfilter/filtertree.h')
-rw-r--r-- | lib/urlfilter/filtertree.h | 28 |
1 files changed, 18 insertions, 10 deletions
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 <QIODevice> #include <QObject> #include <QVector> #include <vector> -#include <QIODevice> -#include "filterleaf.h" -#include "domain.h" +#include <QMutex> /** 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<const FilterLeaf *> 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<FilterLeaf *> leaves; }; + Branch& branch(const QString &domain); + + QMutex branchLock; std::vector<Branch> m_branches; }; |