aboutsummaryrefslogtreecommitdiff
path: root/src/webengine/urlinterceptor.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2017-12-26 16:29:21 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2017-12-26 16:29:21 +0100
commit4cbf8607e94732cf4318451d397e0d416c0080b7 (patch)
tree6c37e9380186f1d60f592ae9131a3605d42941e0 /src/webengine/urlinterceptor.cpp
parentSettingsDialog patches (diff)
downloadsmolbote-4cbf8607e94732cf4318451d397e0d416c0080b7.tar.xz
UrlRequestInterceptor fixes
- Using QHash to store HostRule's, so lookup should be faster - HostRule is now a struct
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));
+ }
}
}