From aa7e8fe1a90fbba289aec9b59a872170a0c593c2 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Thu, 23 Apr 2020 17:47:39 +0300 Subject: move subprojects/plugin_hostlist to plugins/smolblok_hostlist --- .gitignore | 5 +- meson.build | 3 +- plugins/smolblok_hostlist/corpus/apple.txt | 1 + plugins/smolblok_hostlist/corpus/banana.txt | 1 + plugins/smolblok_hostlist/corpus/kiwi.txt | 1 + plugins/smolblok_hostlist/corpus/orange.txt | 1 + plugins/smolblok_hostlist/filterlist.cpp | 58 ++++++++++++++++++++++ plugins/smolblok_hostlist/filterlist.h | 58 ++++++++++++++++++++++ plugins/smolblok_hostlist/meson.build | 42 ++++++++++++++++ plugins/smolblok_hostlist/plugin/plugin.cpp | 32 ++++++++++++ plugins/smolblok_hostlist/plugin/plugin.h | 28 +++++++++++ .../plugin/smolblokHostlistPlugin.json | 4 ++ plugins/smolblok_hostlist/test/filterlist.cpp | 29 +++++++++++ plugins/smolblok_hostlist/test/hostlist.txt | 6 +++ plugins/smolblok_hostlist/test/rule.cpp | 57 +++++++++++++++++++++ subprojects/plugin_hostlist/corpus/apple.txt | 1 - subprojects/plugin_hostlist/corpus/banana.txt | 1 - subprojects/plugin_hostlist/corpus/kiwi.txt | 1 - subprojects/plugin_hostlist/corpus/orange.txt | 1 - subprojects/plugin_hostlist/filterlist.cpp | 58 ---------------------- subprojects/plugin_hostlist/filterlist.h | 58 ---------------------- subprojects/plugin_hostlist/include | 1 - subprojects/plugin_hostlist/meson.build | 53 -------------------- subprojects/plugin_hostlist/plugin/plugin.cpp | 32 ------------ subprojects/plugin_hostlist/plugin/plugin.h | 28 ----------- .../plugin/smolblokHostlistPlugin.json | 4 -- subprojects/plugin_hostlist/test/filterlist.cpp | 29 ----------- subprojects/plugin_hostlist/test/hostlist.txt | 6 --- subprojects/plugin_hostlist/test/rule.cpp | 57 --------------------- 29 files changed, 322 insertions(+), 334 deletions(-) create mode 100644 plugins/smolblok_hostlist/corpus/apple.txt create mode 100644 plugins/smolblok_hostlist/corpus/banana.txt create mode 100644 plugins/smolblok_hostlist/corpus/kiwi.txt create mode 100644 plugins/smolblok_hostlist/corpus/orange.txt create mode 100644 plugins/smolblok_hostlist/filterlist.cpp create mode 100644 plugins/smolblok_hostlist/filterlist.h create mode 100644 plugins/smolblok_hostlist/meson.build create mode 100644 plugins/smolblok_hostlist/plugin/plugin.cpp create mode 100644 plugins/smolblok_hostlist/plugin/plugin.h create mode 100644 plugins/smolblok_hostlist/plugin/smolblokHostlistPlugin.json create mode 100644 plugins/smolblok_hostlist/test/filterlist.cpp create mode 100644 plugins/smolblok_hostlist/test/hostlist.txt create mode 100644 plugins/smolblok_hostlist/test/rule.cpp delete mode 100644 subprojects/plugin_hostlist/corpus/apple.txt delete mode 100644 subprojects/plugin_hostlist/corpus/banana.txt delete mode 100644 subprojects/plugin_hostlist/corpus/kiwi.txt delete mode 100644 subprojects/plugin_hostlist/corpus/orange.txt delete mode 100644 subprojects/plugin_hostlist/filterlist.cpp delete mode 100644 subprojects/plugin_hostlist/filterlist.h delete mode 120000 subprojects/plugin_hostlist/include delete mode 100644 subprojects/plugin_hostlist/meson.build delete mode 100644 subprojects/plugin_hostlist/plugin/plugin.cpp delete mode 100644 subprojects/plugin_hostlist/plugin/plugin.h delete mode 100644 subprojects/plugin_hostlist/plugin/smolblokHostlistPlugin.json delete mode 100644 subprojects/plugin_hostlist/test/filterlist.cpp delete mode 100644 subprojects/plugin_hostlist/test/hostlist.txt delete mode 100644 subprojects/plugin_hostlist/test/rule.cpp diff --git a/.gitignore b/.gitignore index 1715188..acfb13d 100644 --- a/.gitignore +++ b/.gitignore @@ -7,8 +7,6 @@ build* subprojects/* !subprojects/*.wrap -!subprojects/plugin_* -subprojects/plugin_*/corpus lang/*.qm tools/src/crashhandler/defaults.go @@ -16,5 +14,8 @@ tools/src/crashhandler/defaults.go .config.old compile_commands.json +# fuzzer files lib/configuration/test/corpus +plugins/*/corpus +!plugins/*/corpus/*.txt diff --git a/meson.build b/meson.build index c8f86a0..eee01a5 100644 --- a/meson.build +++ b/meson.build @@ -96,8 +96,7 @@ subdir('test/firefox-bookmarks-json-parser') subdir('test/matcherbenchmark') subdir('staging/smolblok') - -subproject('plugin_hostlist') +subdir('plugins/smolblok_hostlist') ssconfig = poi_sourceset.apply(cdata) diff --git a/plugins/smolblok_hostlist/corpus/apple.txt b/plugins/smolblok_hostlist/corpus/apple.txt new file mode 100644 index 0000000..3a8973b --- /dev/null +++ b/plugins/smolblok_hostlist/corpus/apple.txt @@ -0,0 +1 @@ +127.0.0.1 localhost.localdomain diff --git a/plugins/smolblok_hostlist/corpus/banana.txt b/plugins/smolblok_hostlist/corpus/banana.txt new file mode 100644 index 0000000..c30aa84 --- /dev/null +++ b/plugins/smolblok_hostlist/corpus/banana.txt @@ -0,0 +1 @@ +0.0.0.0 blockeddomain.com diff --git a/plugins/smolblok_hostlist/corpus/kiwi.txt b/plugins/smolblok_hostlist/corpus/kiwi.txt new file mode 100644 index 0000000..77c325c --- /dev/null +++ b/plugins/smolblok_hostlist/corpus/kiwi.txt @@ -0,0 +1 @@ +# This is a comment, and after it comes a blank line diff --git a/plugins/smolblok_hostlist/corpus/orange.txt b/plugins/smolblok_hostlist/corpus/orange.txt new file mode 100644 index 0000000..583273d --- /dev/null +++ b/plugins/smolblok_hostlist/corpus/orange.txt @@ -0,0 +1 @@ +0.0.0.0 blockeddomain.first blockeddomain.second diff --git a/plugins/smolblok_hostlist/filterlist.cpp b/plugins/smolblok_hostlist/filterlist.cpp new file mode 100644 index 0000000..a0fd414 --- /dev/null +++ b/plugins/smolblok_hostlist/filterlist.cpp @@ -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 + */ + +#include "filterlist.h" +#include +#include + +using namespace Hostlist; + +#ifdef FUZZER +extern "C" int LLVMFuzzerTestOneInput(const char *Data, long long Size) +{ + Filterlist::parseRule(QString::fromLatin1(Data, Size)); + return 0; +} +#endif + +std::map Filterlist::parseRule(const QString &line) +{ + if(line.isEmpty() || line.at(0) == '#') { + return {}; + } + + auto parts = line.trimmed().split(' '); + if(parts.size() < 2) { + return {}; + } + + const auto redirect = (parts[0] == "0.0.0.0") ? QString() : parts[0]; + + std::map r; + for(int i = 1; i < parts.size(); ++i) { + r.emplace(qHash(parts[i], 0), Filterlist::Rule{ parts[i], redirect }); + } + return r; +} + +bool Filterlist::load(QIODevice &from) +{ + if(!from.isReadable() || !from.isTextModeEnabled()) { + return false; + } + + while(from.bytesAvailable() > 0) { + const auto line = from.readLine(512).trimmed(); + auto r = parseRule(line); + if(!r.empty()) { + qDebug("merging in %lu rules", r.size()); + rules.merge(r); + } + } + return true; +} diff --git a/plugins/smolblok_hostlist/filterlist.h b/plugins/smolblok_hostlist/filterlist.h new file mode 100644 index 0000000..7301f20 --- /dev/null +++ b/plugins/smolblok_hostlist/filterlist.h @@ -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 +#include + +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 parseRule(const QString &line); + +private: + std::map rules; +}; +} // namespace Hostlist diff --git a/plugins/smolblok_hostlist/meson.build b/plugins/smolblok_hostlist/meson.build new file mode 100644 index 0000000..a3e64a7 --- /dev/null +++ b/plugins/smolblok_hostlist/meson.build @@ -0,0 +1,42 @@ +lib_hostlistfilter = static_library('hostlistfilter', + [ 'filterlist.cpp' ], + include_directories: smolbote_interfaces, + dependencies: [dep_qt5] +) + +dep_hostlistfilter = declare_dependency( + include_directories: [ '.', smolbote_interfaces ], + link_with: lib_hostlistfilter +) + +# plugin +plugin = shared_library('smolblokHostlistPlugin', + [ 'plugin/plugin.cpp', + mod_qt5.preprocess(include_directories: smolbote_interfaces, moc_headers: 'plugin/plugin.h', dependencies: dep_qt5) ], + include_directories: smolbote_interfaces, + dependencies: [ dep_hostlistfilter, dep_qt5 ], + install: true, + install_dir: get_option('libdir')/'smolbote/plugins' +) + +# tests +test('rule parsing', executable('rule', + sources: 'test/rule.cpp', + dependencies: [dep_qt5, dep_catch, dep_hostlistfilter])) + +test('filterlist', executable('filterlist', + sources: 'test/filterlist.cpp', + dependencies: [dep_qt5, dep_catch, dep_hostlistfilter]), + env: 'HOSTLIST_TXT='+meson.current_source_dir()/'test/hostlist.txt' +) + +# fuzzer +if meson.get_compiler('cpp').has_multi_arguments('-g', '-fsanitize=fuzzer') +executable('hostlist-fuzzer', + sources: 'filterlist.cpp', + include_directories: smolbote_interfaces, + dependencies: dep_qt5, + cpp_args: [ '-g', '-fsanitize=fuzzer', '-DFUZZER' ], + link_args: [ '-fsanitize=fuzzer' ] +) +endif diff --git a/plugins/smolblok_hostlist/plugin/plugin.cpp b/plugins/smolblok_hostlist/plugin/plugin.cpp new file mode 100644 index 0000000..28a7706 --- /dev/null +++ b/plugins/smolblok_hostlist/plugin/plugin.cpp @@ -0,0 +1,32 @@ +/* + * 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 + */ + +#include "plugin.h" +#include "filterlist.h" + +FilterList* HostlistFilterPlugin::load(QIODevice &from) const +{ + if(!from.isOpen()) + return nullptr; + + auto *list = new Hostlist::Filterlist; + return list; +} + +bool HostlistFilterPlugin::parse(FilterList *list, QIODevice &from) const +{ + if(list == nullptr || !from.isOpen()) { + return false; + } + auto *l = dynamic_cast(list); + if(l == nullptr) { + return false; + } + return l->load(from); +} + diff --git a/plugins/smolblok_hostlist/plugin/plugin.h b/plugins/smolblok_hostlist/plugin/plugin.h new file mode 100644 index 0000000..53b5d36 --- /dev/null +++ b/plugins/smolblok_hostlist/plugin/plugin.h @@ -0,0 +1,28 @@ +/* + * 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 + */ + +#ifndef SMOLBLOK_FILTER_PLUGIN_H +#define SMOLBLOK_FILTER_PLUGIN_H + +#include + +class HostlistFilterPlugin : public QObject, public FilterPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID FilterPluginIid FILE "smolblokHostlistPlugin.json") + Q_INTERFACES(FilterPlugin) + +public: + ~HostlistFilterPlugin() = default; + + FilterList *load(QIODevice &from) const override; + bool parse(FilterList *list, QIODevice &from) const override; +}; + +#endif // SMOLBLOK_FILTER_PLUGIN_H + diff --git a/plugins/smolblok_hostlist/plugin/smolblokHostlistPlugin.json b/plugins/smolblok_hostlist/plugin/smolblokHostlistPlugin.json new file mode 100644 index 0000000..aa53cdd --- /dev/null +++ b/plugins/smolblok_hostlist/plugin/smolblokHostlistPlugin.json @@ -0,0 +1,4 @@ +{ + "name": "smolblok Hostlist filter plugin", + "author": "Aqua " +} diff --git a/plugins/smolblok_hostlist/test/filterlist.cpp b/plugins/smolblok_hostlist/test/filterlist.cpp new file mode 100644 index 0000000..4aa532b --- /dev/null +++ b/plugins/smolblok_hostlist/test/filterlist.cpp @@ -0,0 +1,29 @@ +#define CATCH_CONFIG_MAIN +#include "filterlist.h" +#include +#include + +using namespace Hostlist; + +TEST_CASE("Hostlist") +{ + Filterlist list; + + const QString filename(qgetenv("HOSTLIST_TXT")); + REQUIRE(!filename.isEmpty()); + + QFile f(filename); + REQUIRE(f.open(QIODevice::ReadOnly | QIODevice::Text)); + + REQUIRE(list.load(f)); + f.close(); + + REQUIRE(list.count() == 4); + + REQUIRE(list.findMatch("blockeddomain.first")); + REQUIRE(list.findMatch("blockeddomain.second")); + + REQUIRE(list.findMatch("localhost.localdomain")); + + REQUIRE(!list.findMatch("other.domain")); +} diff --git a/plugins/smolblok_hostlist/test/hostlist.txt b/plugins/smolblok_hostlist/test/hostlist.txt new file mode 100644 index 0000000..a0b4e5c --- /dev/null +++ b/plugins/smolblok_hostlist/test/hostlist.txt @@ -0,0 +1,6 @@ +# This is a comment, and after it comes a blank line + +127.0.0.1 localhost.localdomain + +0.0.0.0 blockeddomain.com +0.0.0.0 blockeddomain.first blockeddomain.second diff --git a/plugins/smolblok_hostlist/test/rule.cpp b/plugins/smolblok_hostlist/test/rule.cpp new file mode 100644 index 0000000..b5ba6e0 --- /dev/null +++ b/plugins/smolblok_hostlist/test/rule.cpp @@ -0,0 +1,57 @@ +#define CATCH_CONFIG_MAIN +#include "filterlist.h" +#include + +using namespace Hostlist; + +SCENARIO("Hostlist::Rule") +{ + GIVEN("an invalid rule") + { + const auto rule = Filterlist::parseRule("0.0.0.0 "); + REQUIRE(rule.empty()); + } + GIVEN("127.0.0.1 localhost.localdomain") + { + auto rule = Filterlist::parseRule("127.0.0.1 localhost.localdomain"); + + REQUIRE(!rule.empty()); + REQUIRE(rule.size() == 1); + + // note: you need to force it to hash a string, rather than the address itself + const auto index = qHash(QString("localhost.localdomain"), 0); + REQUIRE(rule[index].domain == "localhost.localdomain"); + REQUIRE(rule[index].redirect == "127.0.0.1"); + } + + GIVEN("0.0.0.0 blockeddomain.com") + { + auto rule = Filterlist::parseRule("0.0.0.0 blockeddomain.com"); + + REQUIRE(!rule.empty()); + REQUIRE(rule.size() == 1); + + const auto index = qHash(QString("blockeddomain.com"), 0); + REQUIRE(rule[index].domain == "blockeddomain.com"); + REQUIRE(rule[index].redirect.isEmpty()); + ; + } + + GIVEN("0.0.0.0 blockeddomain.first blockeddomain.second") + { + auto rule = Filterlist::parseRule("0.0.0.0 blockeddomain.first blockeddomain.second"); + + REQUIRE(!rule.empty()); + REQUIRE(rule.size() == 2); + { + const auto index = qHash(QString("blockeddomain.first"), 0); + REQUIRE(rule[index].domain == "blockeddomain.first"); + REQUIRE(rule[index].redirect.isEmpty()); + } + { + const auto index = qHash(QString("blockeddomain.second"), 0); + REQUIRE(rule[index].domain == "blockeddomain.second"); + REQUIRE(rule[index].redirect.isEmpty()); + } + } +} diff --git a/subprojects/plugin_hostlist/corpus/apple.txt b/subprojects/plugin_hostlist/corpus/apple.txt deleted file mode 100644 index 3a8973b..0000000 --- a/subprojects/plugin_hostlist/corpus/apple.txt +++ /dev/null @@ -1 +0,0 @@ -127.0.0.1 localhost.localdomain diff --git a/subprojects/plugin_hostlist/corpus/banana.txt b/subprojects/plugin_hostlist/corpus/banana.txt deleted file mode 100644 index c30aa84..0000000 --- a/subprojects/plugin_hostlist/corpus/banana.txt +++ /dev/null @@ -1 +0,0 @@ -0.0.0.0 blockeddomain.com diff --git a/subprojects/plugin_hostlist/corpus/kiwi.txt b/subprojects/plugin_hostlist/corpus/kiwi.txt deleted file mode 100644 index 77c325c..0000000 --- a/subprojects/plugin_hostlist/corpus/kiwi.txt +++ /dev/null @@ -1 +0,0 @@ -# This is a comment, and after it comes a blank line diff --git a/subprojects/plugin_hostlist/corpus/orange.txt b/subprojects/plugin_hostlist/corpus/orange.txt deleted file mode 100644 index 583273d..0000000 --- a/subprojects/plugin_hostlist/corpus/orange.txt +++ /dev/null @@ -1 +0,0 @@ -0.0.0.0 blockeddomain.first blockeddomain.second diff --git a/subprojects/plugin_hostlist/filterlist.cpp b/subprojects/plugin_hostlist/filterlist.cpp deleted file mode 100644 index a0fd414..0000000 --- a/subprojects/plugin_hostlist/filterlist.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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 - */ - -#include "filterlist.h" -#include -#include - -using namespace Hostlist; - -#ifdef FUZZER -extern "C" int LLVMFuzzerTestOneInput(const char *Data, long long Size) -{ - Filterlist::parseRule(QString::fromLatin1(Data, Size)); - return 0; -} -#endif - -std::map Filterlist::parseRule(const QString &line) -{ - if(line.isEmpty() || line.at(0) == '#') { - return {}; - } - - auto parts = line.trimmed().split(' '); - if(parts.size() < 2) { - return {}; - } - - const auto redirect = (parts[0] == "0.0.0.0") ? QString() : parts[0]; - - std::map r; - for(int i = 1; i < parts.size(); ++i) { - r.emplace(qHash(parts[i], 0), Filterlist::Rule{ parts[i], redirect }); - } - return r; -} - -bool Filterlist::load(QIODevice &from) -{ - if(!from.isReadable() || !from.isTextModeEnabled()) { - return false; - } - - while(from.bytesAvailable() > 0) { - const auto line = from.readLine(512).trimmed(); - auto r = parseRule(line); - if(!r.empty()) { - qDebug("merging in %lu rules", r.size()); - rules.merge(r); - } - } - return true; -} diff --git a/subprojects/plugin_hostlist/filterlist.h b/subprojects/plugin_hostlist/filterlist.h deleted file mode 100644 index 7301f20..0000000 --- a/subprojects/plugin_hostlist/filterlist.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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 -#include - -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 parseRule(const QString &line); - -private: - std::map rules; -}; -} // namespace Hostlist diff --git a/subprojects/plugin_hostlist/include b/subprojects/plugin_hostlist/include deleted file mode 120000 index 3611dd2..0000000 --- a/subprojects/plugin_hostlist/include +++ /dev/null @@ -1 +0,0 @@ -../../include/ \ No newline at end of file diff --git a/subprojects/plugin_hostlist/meson.build b/subprojects/plugin_hostlist/meson.build deleted file mode 100644 index f4178c9..0000000 --- a/subprojects/plugin_hostlist/meson.build +++ /dev/null @@ -1,53 +0,0 @@ -project('hostlistfilter', 'cpp') - -mod_qt5 = import('qt5') -dep_qt5 = dependency('qt5', - modules: [ 'Core', 'Network', 'WebEngineWidgets' ], - include_type: 'system' -) -dep_catch = dependency('catch2', required: true, fallback: ['catch2', 'catch2_dep'] ) - -smolbote_interface = include_directories('include') - -lib_hostlistfilter = static_library('hostlistfilter', - [ 'filterlist.cpp' ], - include_directories: smolbote_interface, - dependencies: [dep_qt5] -) - -dep_hostlistfilter = declare_dependency( - include_directories: [ '.', smolbote_interface ], - link_with: lib_hostlistfilter -) - -# plugin -plugin = shared_library('smolblokHostlistPlugin', - [ 'plugin/plugin.cpp', - mod_qt5.preprocess(include_directories: smolbote_interface, moc_headers: 'plugin/plugin.h', dependencies: dep_qt5) ], - include_directories: smolbote_interface, - dependencies: [ dep_hostlistfilter, dep_qt5 ], - install: true, - install_dir: get_option('libdir')/'smolbote/plugins' -) - -# tests -test('rule parsing', executable('rule', - sources: 'test/rule.cpp', - dependencies: [dep_qt5, dep_catch, dep_hostlistfilter])) - -test('filterlist', executable('filterlist', - sources: 'test/filterlist.cpp', - dependencies: [dep_qt5, dep_catch, dep_hostlistfilter]), - env: 'HOSTLIST_TXT='+meson.current_source_dir()/'test/hostlist.txt' -) - -# fuzzer -if meson.get_compiler('cpp').has_multi_arguments('-g', '-fsanitize=fuzzer') -executable('hostlist-fuzzer', - sources: 'filterlist.cpp', - include_directories: smolbote_interface, - dependencies: dep_qt5, - cpp_args: [ '-g', '-fsanitize=fuzzer', '-DFUZZER' ], - link_args: [ '-fsanitize=fuzzer' ] -) -endif diff --git a/subprojects/plugin_hostlist/plugin/plugin.cpp b/subprojects/plugin_hostlist/plugin/plugin.cpp deleted file mode 100644 index 28a7706..0000000 --- a/subprojects/plugin_hostlist/plugin/plugin.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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 - */ - -#include "plugin.h" -#include "filterlist.h" - -FilterList* HostlistFilterPlugin::load(QIODevice &from) const -{ - if(!from.isOpen()) - return nullptr; - - auto *list = new Hostlist::Filterlist; - return list; -} - -bool HostlistFilterPlugin::parse(FilterList *list, QIODevice &from) const -{ - if(list == nullptr || !from.isOpen()) { - return false; - } - auto *l = dynamic_cast(list); - if(l == nullptr) { - return false; - } - return l->load(from); -} - diff --git a/subprojects/plugin_hostlist/plugin/plugin.h b/subprojects/plugin_hostlist/plugin/plugin.h deleted file mode 100644 index 53b5d36..0000000 --- a/subprojects/plugin_hostlist/plugin/plugin.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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 - */ - -#ifndef SMOLBLOK_FILTER_PLUGIN_H -#define SMOLBLOK_FILTER_PLUGIN_H - -#include - -class HostlistFilterPlugin : public QObject, public FilterPlugin -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID FilterPluginIid FILE "smolblokHostlistPlugin.json") - Q_INTERFACES(FilterPlugin) - -public: - ~HostlistFilterPlugin() = default; - - FilterList *load(QIODevice &from) const override; - bool parse(FilterList *list, QIODevice &from) const override; -}; - -#endif // SMOLBLOK_FILTER_PLUGIN_H - diff --git a/subprojects/plugin_hostlist/plugin/smolblokHostlistPlugin.json b/subprojects/plugin_hostlist/plugin/smolblokHostlistPlugin.json deleted file mode 100644 index aa53cdd..0000000 --- a/subprojects/plugin_hostlist/plugin/smolblokHostlistPlugin.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "smolblok Hostlist filter plugin", - "author": "Aqua " -} diff --git a/subprojects/plugin_hostlist/test/filterlist.cpp b/subprojects/plugin_hostlist/test/filterlist.cpp deleted file mode 100644 index 4aa532b..0000000 --- a/subprojects/plugin_hostlist/test/filterlist.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#define CATCH_CONFIG_MAIN -#include "filterlist.h" -#include -#include - -using namespace Hostlist; - -TEST_CASE("Hostlist") -{ - Filterlist list; - - const QString filename(qgetenv("HOSTLIST_TXT")); - REQUIRE(!filename.isEmpty()); - - QFile f(filename); - REQUIRE(f.open(QIODevice::ReadOnly | QIODevice::Text)); - - REQUIRE(list.load(f)); - f.close(); - - REQUIRE(list.count() == 4); - - REQUIRE(list.findMatch("blockeddomain.first")); - REQUIRE(list.findMatch("blockeddomain.second")); - - REQUIRE(list.findMatch("localhost.localdomain")); - - REQUIRE(!list.findMatch("other.domain")); -} diff --git a/subprojects/plugin_hostlist/test/hostlist.txt b/subprojects/plugin_hostlist/test/hostlist.txt deleted file mode 100644 index a0b4e5c..0000000 --- a/subprojects/plugin_hostlist/test/hostlist.txt +++ /dev/null @@ -1,6 +0,0 @@ -# This is a comment, and after it comes a blank line - -127.0.0.1 localhost.localdomain - -0.0.0.0 blockeddomain.com -0.0.0.0 blockeddomain.first blockeddomain.second diff --git a/subprojects/plugin_hostlist/test/rule.cpp b/subprojects/plugin_hostlist/test/rule.cpp deleted file mode 100644 index b5ba6e0..0000000 --- a/subprojects/plugin_hostlist/test/rule.cpp +++ /dev/null @@ -1,57 +0,0 @@ -#define CATCH_CONFIG_MAIN -#include "filterlist.h" -#include - -using namespace Hostlist; - -SCENARIO("Hostlist::Rule") -{ - GIVEN("an invalid rule") - { - const auto rule = Filterlist::parseRule("0.0.0.0 "); - REQUIRE(rule.empty()); - } - GIVEN("127.0.0.1 localhost.localdomain") - { - auto rule = Filterlist::parseRule("127.0.0.1 localhost.localdomain"); - - REQUIRE(!rule.empty()); - REQUIRE(rule.size() == 1); - - // note: you need to force it to hash a string, rather than the address itself - const auto index = qHash(QString("localhost.localdomain"), 0); - REQUIRE(rule[index].domain == "localhost.localdomain"); - REQUIRE(rule[index].redirect == "127.0.0.1"); - } - - GIVEN("0.0.0.0 blockeddomain.com") - { - auto rule = Filterlist::parseRule("0.0.0.0 blockeddomain.com"); - - REQUIRE(!rule.empty()); - REQUIRE(rule.size() == 1); - - const auto index = qHash(QString("blockeddomain.com"), 0); - REQUIRE(rule[index].domain == "blockeddomain.com"); - REQUIRE(rule[index].redirect.isEmpty()); - ; - } - - GIVEN("0.0.0.0 blockeddomain.first blockeddomain.second") - { - auto rule = Filterlist::parseRule("0.0.0.0 blockeddomain.first blockeddomain.second"); - - REQUIRE(!rule.empty()); - REQUIRE(rule.size() == 2); - { - const auto index = qHash(QString("blockeddomain.first"), 0); - REQUIRE(rule[index].domain == "blockeddomain.first"); - REQUIRE(rule[index].redirect.isEmpty()); - } - { - const auto index = qHash(QString("blockeddomain.second"), 0); - REQUIRE(rule[index].domain == "blockeddomain.second"); - REQUIRE(rule[index].redirect.isEmpty()); - } - } -} -- cgit v1.2.1