diff options
-rw-r--r-- | .gitignore | 5 | ||||
-rw-r--r-- | include/smolbote/filterinterface.hpp | 7 | ||||
-rw-r--r-- | meson.build | 2 | ||||
-rw-r--r-- | staging/hostlist/meson.build | 20 | ||||
-rw-r--r-- | staging/smolblok/smolblok.cpp | 8 | ||||
-rw-r--r-- | subprojects/plugin_hostlist/filterlist.cpp (renamed from staging/hostlist/filterlist.cpp) | 0 | ||||
-rw-r--r-- | subprojects/plugin_hostlist/filterlist.hpp (renamed from staging/hostlist/filterlist.hpp) | 2 | ||||
-rw-r--r-- | subprojects/plugin_hostlist/meson.build | 43 | ||||
-rw-r--r-- | subprojects/plugin_hostlist/meson_options.txt | 1 | ||||
-rw-r--r-- | subprojects/plugin_hostlist/plugin/plugin.cpp | 32 | ||||
-rw-r--r-- | subprojects/plugin_hostlist/plugin/plugin.h | 28 | ||||
-rw-r--r-- | subprojects/plugin_hostlist/plugin/smolblokHostlistPlugin.json | 4 | ||||
-rw-r--r-- | subprojects/plugin_hostlist/test/filterlist.cpp (renamed from staging/hostlist/test/filterlist.cpp) | 0 | ||||
-rw-r--r-- | subprojects/plugin_hostlist/test/hostlist.txt (renamed from staging/hostlist/test/hostlist.txt) | 0 | ||||
-rw-r--r-- | subprojects/plugin_hostlist/test/rule.cpp (renamed from staging/hostlist/test/rule.cpp) | 0 |
15 files changed, 124 insertions, 28 deletions
@@ -5,7 +5,10 @@ build* # qtcreator *.user -subprojects/ +subprojects/* +!subprojects/*.wrap +!subprojects/plugin_* + lang/*.qm tools/src/crashhandler/defaults.go .config diff --git a/include/smolbote/filterinterface.hpp b/include/smolbote/filterinterface.hpp index 1ae65cc..3bbddf2 100644 --- a/include/smolbote/filterinterface.hpp +++ b/include/smolbote/filterinterface.hpp @@ -11,8 +11,7 @@ #include <QWebEngineUrlRequestInfo> #include <QtPlugin> - -class QIODevice; +#include <QIODevice> class FilterList { @@ -29,8 +28,8 @@ class FilterPlugin public: virtual ~FilterPlugin() = default; - virtual FilterList *load(QIODevice* from) const = 0; - virtual bool update(QIODevice *f, const QUrl &upstream) const = 0; + virtual FilterList *load(QIODevice&) const = 0; + virtual bool parse(FilterList *list, QIODevice &) const = 0; }; #define FilterPluginIid "net.iserlohn-fortress.smolbote.FilterPlugin" diff --git a/meson.build b/meson.build index ce3dbf5..605fb64 100644 --- a/meson.build +++ b/meson.build @@ -93,6 +93,8 @@ subdir('test/matcherbenchmark') subdir('staging/smolblok') +subproject('plugin_hostlist', default_options: 'interface=../../include') + ssconfig = poi_sourceset.apply(cdata) poi_exe = executable(get_option('poi'), diff --git a/staging/hostlist/meson.build b/staging/hostlist/meson.build deleted file mode 100644 index c5f3499..0000000 --- a/staging/hostlist/meson.build +++ /dev/null @@ -1,20 +0,0 @@ -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 -) - -test('hostlist: rule parsing', executable('rule', - sources: 'test/rule.cpp', - dependencies: [dep_qt5, dep_catch, dep_hostlistfilter])) - -test('hostlist: filterlist', executable('filterlist', - sources: 'test/filterlist.cpp', - dependencies: [dep_qt5, dep_catch, dep_hostlistfilter]), - env: 'HOSTLIST_TXT='+meson.current_source_dir()/'test/hostlist.txt' -) diff --git a/staging/smolblok/smolblok.cpp b/staging/smolblok/smolblok.cpp index 6095082..26d46cb 100644 --- a/staging/smolblok/smolblok.cpp +++ b/staging/smolblok/smolblok.cpp @@ -45,11 +45,15 @@ bool smolblok::addSubscriptions(const QString &filename) const auto *loader = m_formats.value(listconf.value("Format").toString()).instance; if(loader != nullptr) { QFile f(listconf.value("File").toString()); - if(!f.exists() && !loader->update(&f, listconf.value("Href").toUrl())) { + if(!f.exists()) { continue; } - m_subscriptions.addFilterList(loader->load(&f)); + auto *list = loader->load(f); + f.seek(0); + if(loader->parse(list, f)) { + m_subscriptions.addFilterList(list); + } } listconf.endGroup(); } diff --git a/staging/hostlist/filterlist.cpp b/subprojects/plugin_hostlist/filterlist.cpp index 42be349..42be349 100644 --- a/staging/hostlist/filterlist.cpp +++ b/subprojects/plugin_hostlist/filterlist.cpp diff --git a/staging/hostlist/filterlist.hpp b/subprojects/plugin_hostlist/filterlist.hpp index 6edc19d..7301f20 100644 --- a/staging/hostlist/filterlist.hpp +++ b/subprojects/plugin_hostlist/filterlist.hpp @@ -14,7 +14,7 @@ namespace Hostlist { -class Filterlist final : public Filter +class Filterlist final : public FilterList { public: typedef uint DomainHash; diff --git a/subprojects/plugin_hostlist/meson.build b/subprojects/plugin_hostlist/meson.build new file mode 100644 index 0000000..d8286d1 --- /dev/null +++ b/subprojects/plugin_hostlist/meson.build @@ -0,0 +1,43 @@ +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(get_option('interface')) +message(get_option('interface')) + +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' +) diff --git a/subprojects/plugin_hostlist/meson_options.txt b/subprojects/plugin_hostlist/meson_options.txt new file mode 100644 index 0000000..e4aed19 --- /dev/null +++ b/subprojects/plugin_hostlist/meson_options.txt @@ -0,0 +1 @@ +option('interface', description: 'Interfaces path', type: 'string', value: '/usr/local/include') diff --git a/subprojects/plugin_hostlist/plugin/plugin.cpp b/subprojects/plugin_hostlist/plugin/plugin.cpp new file mode 100644 index 0000000..2399510 --- /dev/null +++ b/subprojects/plugin_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.hpp" + +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<Hostlist::Filterlist*>(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 new file mode 100644 index 0000000..53b5d36 --- /dev/null +++ b/subprojects/plugin_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 <smolbote/filterinterface.hpp> + +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 new file mode 100644 index 0000000..aa53cdd --- /dev/null +++ b/subprojects/plugin_hostlist/plugin/smolblokHostlistPlugin.json @@ -0,0 +1,4 @@ +{ + "name": "smolblok Hostlist filter plugin", + "author": "Aqua <aqua@iserlohn-fortress.net>" +} diff --git a/staging/hostlist/test/filterlist.cpp b/subprojects/plugin_hostlist/test/filterlist.cpp index fb71068..fb71068 100644 --- a/staging/hostlist/test/filterlist.cpp +++ b/subprojects/plugin_hostlist/test/filterlist.cpp diff --git a/staging/hostlist/test/hostlist.txt b/subprojects/plugin_hostlist/test/hostlist.txt index a0b4e5c..a0b4e5c 100644 --- a/staging/hostlist/test/hostlist.txt +++ b/subprojects/plugin_hostlist/test/hostlist.txt diff --git a/staging/hostlist/test/rule.cpp b/subprojects/plugin_hostlist/test/rule.cpp index 6b1ea70..6b1ea70 100644 --- a/staging/hostlist/test/rule.cpp +++ b/subprojects/plugin_hostlist/test/rule.cpp |