diff options
Diffstat (limited to 'lib/urlfilter/hostlist/hostlist.cpp')
-rw-r--r-- | lib/urlfilter/hostlist/hostlist.cpp | 79 |
1 files changed, 0 insertions, 79 deletions
diff --git a/lib/urlfilter/hostlist/hostlist.cpp b/lib/urlfilter/hostlist/hostlist.cpp deleted file mode 100644 index bec79ea..0000000 --- a/lib/urlfilter/hostlist/hostlist.cpp +++ /dev/null @@ -1,79 +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 "hostlist.h" -#include <QIODevice> -#include <QTextStream> -#include <QDebug> - -HostList::HostList(QIODevice *device) -{ - Q_ASSERT(device->isOpen()); - - QTextStream list(device); - while (!list.atEnd()) { - parseLine(list.readLine()); - } - - qDebug() << m_metadata; -} - -QString HostList::metadata(const QString& key) const -{ - return m_metadata.value(key); -} - -int HostList::ruleCount() const -{ - return rules.size(); -} - -std::pair<UrlFilter::MatchResult, QString> HostList::match(const QUrl& firstParty, const QUrl& requestUrl, QWebEngineUrlRequestInfo::ResourceType type) const -{ - Q_UNUSED(firstParty); - Q_UNUSED(type); - - const QString domain = requestUrl.host(); - const uint domainHash = qHash(domain); - - for(const Rule &r : rules) { - if(r.domainHash == domainHash) - return std::make_pair(r.action, r.redirect); - } - - return std::make_pair(UrlFilter::NotMatched, QString()); -} - -void HostList::parseLine(const QString& line) -{ - // check comment - if(line.startsWith(QLatin1String("#"))) - return; - - QString parsedLine = line.trimmed(); - - // malformed rule - if(!parsedLine.contains(QLatin1String(" "))) - return; - - const QStringList parts = parsedLine.split(QLatin1String(" ")); - const QString &redirect = parts.at(0); - const auto action = (redirect == QLatin1String("0.0.0.0")) ? UrlFilter::Block : UrlFilter::Redirect; - - for(int i = 1; i < parts.size(); i++) { - const QString &domain = parts.at(i); - Rule r; - r.action = action; - r.domainHash = qHash(domain); - if(action == UrlFilter::Redirect) - r.redirect = redirect; - - rules.emplace_back(std::move(r)); - } -} - |