From 3d2ae07c455c0e423c64f19e445518427a5684fa Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Wed, 9 Jan 2019 19:38:58 +0100 Subject: Rewrite lib/urlfilter - Make HostList and AdBlockList implementations independent from each other - Move urlfilter tests to lib/urlfilter --- src/webengine/filter.cpp | 70 ------------------------------------------------ 1 file changed, 70 deletions(-) delete mode 100644 src/webengine/filter.cpp (limited to 'src/webengine/filter.cpp') diff --git a/src/webengine/filter.cpp b/src/webengine/filter.cpp deleted file mode 100644 index f1a38af..0000000 --- a/src/webengine/filter.cpp +++ /dev/null @@ -1,70 +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://neueland.iserlohn-fortress.net/gitea/aqua/smolbote - * - * SPDX-License-Identifier: GPL-3.0 - */ - -#include "filter.h" -#include "configuration.h" -#include "urlinterceptor.h" -#include "util.h" -#include -#include -#include -#include - -Filter::Filter::Filter(const std::unique_ptr &config, QObject *parent) - : QObject(parent) -{ - // parse headers - if(config->exists("filter.header")) { - const auto headers = config->value("filter.header").value(); - for(const QString header : headers) { - const auto list = header.split(QLatin1Literal(":")); - if(list.length() == 2) - m_headers.insert(list.at(0).toLatin1(), list.at(1).toLatin1()); - } -#ifdef QT_DEBUG - qDebug("Added %i custom http headers", m_headers.size()); -#endif - } - - const QStringList hostfiles = Util::files(config->value("filter.hosts").value()); - //qDebug("filter.path=[%s]", qUtf8Printable(config->value("filter.hosts").value())); - for(const QString &hostfile : hostfiles) { - QFile f(hostfile); - if(f.open(QIODevice::ReadOnly | QIODevice::Text)) { -#ifdef QT_DEBUG - qDebug("Loading hostlist filters [%s]", qUtf8Printable(hostfile)); -#endif - loadHostlist(f, &filters); - f.close(); - } - } -} - -void Filter::filterRequest(QWebEngineUrlRequestInfo &info) const -{ - auto matches = filters.match(info.firstPartyUrl().toString(), info.requestUrl().toString()); - for(const auto &rule : matches) { - switch(rule->action().first) { - case FilterLeaf::NotMatched: -#ifdef QT_DEBUG - qDebug("Paradoxical match: request matched, but not matched."); - qDebug(" - %s", qUtf8Printable(info.requestUrl().toString())); -#endif - break; - case FilterLeaf::Block: - //qDebug("block %s", qUtf8Printable(info.requestUrl().toString())); - info.block(true); - break; - case FilterLeaf::Allow: - info.block(false); - break; - //case FilterLeaf::Redirect: - // break; - } - } -} -- cgit v1.2.1