aboutsummaryrefslogtreecommitdiff
path: root/src/webengine/urlinterceptor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/webengine/urlinterceptor.cpp')
-rw-r--r--src/webengine/urlinterceptor.cpp41
1 files changed, 24 insertions, 17 deletions
diff --git a/src/webengine/urlinterceptor.cpp b/src/webengine/urlinterceptor.cpp
index 2f3f04f..175643e 100644
--- a/src/webengine/urlinterceptor.cpp
+++ b/src/webengine/urlinterceptor.cpp
@@ -22,29 +22,20 @@ UrlRequestInterceptor::UrlRequestInterceptor(const QString &path, QObject *paren
for(const QString &file : hostsD.entryList(QDir::Files)) {
qDebug("Parsing hosts.d/%s: %i", qUtf8Printable(file), parseHostfile(hostsD.absoluteFilePath(file)));
}
+
+ qDebug("Total number of rules: %i", m_rules.count());
}
UrlRequestInterceptor::~UrlRequestInterceptor()
{
- for(HostRule *r : m_rules) {
- delete r;
- }
+ qDeleteAll(m_rules);
}
void UrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
{
-//#ifdef QT_DEBUG
-// qDebug("%s -> %s", qUtf8Printable(info.firstPartyUrl().toString()), qUtf8Printable(info.requestUrl().toString()));
-//#endif
-
- for(HostRule *test : m_rules) {
- if(test->shouldBlock(info)) {
+ if(m_rules.contains(info.requestUrl().host())) {
+ if(m_rules.value(info.requestUrl().host())->isBlocking) {
info.block(true);
-
-//#ifdef QT_DEBUG
-// qDebug("blocked on pattern %s", qUtf8Printable(test->pattern()));
-//#endif
- return;
}
}
}
@@ -64,9 +55,25 @@ int UrlRequestInterceptor::parseHostfile(const QString &filename)
// skip comments and empty lines
if(!line.startsWith('#') && !line.isEmpty()) {
- HostRule *r = new HostRule(line);
- m_rules.push_back(r);
- ++numRules;
+ // format is <redirect> <host>
+ //0.0.0.0 host
+ QStringList parts = line.split(' ');
+ QString redirect = parts.at(0);
+ QString host = parts.at(1);
+
+ if(m_rules.contains(host)) {
+ qWarning("Duplicate rule %s", qUtf8Printable(line));
+ }
+
+ if(redirect == "0.0.0.0") {
+ HostRule *rule = new HostRule;
+ rule->isBlocking = true;
+ m_rules.insert(host, rule);
+
+ ++numRules;
+ } else {
+ qDebug("Ignoring rule %s", qUtf8Printable(line));
+ }
}
}