diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-04-20 13:29:06 +0300 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-04-21 20:14:58 +0300 |
commit | 8d484d153dd054be89be51b7b4e9815450c0065a (patch) | |
tree | 44a4c1045969909197312003957611f90d9be582 /subprojects/plugin_hostlist/filterlist.hpp | |
parent | Add plugin loading code to smolblok (diff) | |
download | smolbote-8d484d153dd054be89be51b7b4e9815450c0065a.tar.xz |
Move staging/hostlist to subprojects/plugin_hostlist
Diffstat (limited to 'subprojects/plugin_hostlist/filterlist.hpp')
-rw-r--r-- | subprojects/plugin_hostlist/filterlist.hpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/subprojects/plugin_hostlist/filterlist.hpp b/subprojects/plugin_hostlist/filterlist.hpp new file mode 100644 index 0000000..7301f20 --- /dev/null +++ b/subprojects/plugin_hostlist/filterlist.hpp @@ -0,0 +1,58 @@ +/* + * 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://library.iserlohn-fortress.net/aqua/smolbote.git + * + * SPDX-License-Identifier: GPL-3.0 + */ + +#pragma once + +#include <map> +#include <smolbote/filterinterface.hpp> + +namespace Hostlist +{ + +class Filterlist final : public FilterList +{ +public: + typedef uint DomainHash; + struct Rule { + QString domain; + QString redirect; + }; + + Filterlist() = default; + ~Filterlist() = default; + + [[nodiscard]] bool findMatch(const QString &domain) const + { + const auto hash = qHash(domain, 0); + const auto found = rules.find(hash); + if(found != rules.end()) { + return true; + } + return false; + } + int count() const + { + return rules.size(); + } + + [[nodiscard]] bool filter(QWebEngineUrlRequestInfo &info) const + { + return false; + } + [[nodiscard]] bool isUpToDate() const + { + return true; + } + + bool load(QIODevice &device); + [[nodiscard]] static std::map<DomainHash, Rule> parseRule(const QString &line); + +private: + std::map<DomainHash, Rule> rules; +}; +} // namespace Hostlist |