aboutsummaryrefslogtreecommitdiff
path: root/src/webengine/urlinterceptor.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-06-02 11:02:42 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-06-02 11:02:42 +0200
commit3533e0d4cce3e7af2df8e6c42f462315da8c9df8 (patch)
treeff19b54818708f122f4dc501fcaf80594b8b99a2 /src/webengine/urlinterceptor.cpp
parentFix hg bookmark not showing up in arch build version (diff)
downloadsmolbote-3533e0d4cce3e7af2df8e6c42f462315da8c9df8.tar.xz
Clazy fixes
Diffstat (limited to 'src/webengine/urlinterceptor.cpp')
-rw-r--r--src/webengine/urlinterceptor.cpp31
1 files changed, 19 insertions, 12 deletions
diff --git a/src/webengine/urlinterceptor.cpp b/src/webengine/urlinterceptor.cpp
index e88e5b7..5e17e78 100644
--- a/src/webengine/urlinterceptor.cpp
+++ b/src/webengine/urlinterceptor.cpp
@@ -25,13 +25,7 @@ UrlRequestInterceptor::UrlRequestInterceptor(const QString &path, QObject *paren
#endif
rulesLock.lock();
- for(const auto &k : r.keys()) {
- if(rules.contains(k)) {
- //
- } else {
- rules.insert(k, r.value(k));
- }
- }
+ rules.unite(r);
rulesLock.unlock();
});
}
@@ -57,28 +51,41 @@ QHash<QString, UrlRequestInterceptor::HostRule> parse(const QString &filename)
// with a QTextStream we can read lines without getting linebreaks at the end
QTextStream hostfile_stream(&hostfile);
+
while(!hostfile_stream.atEnd()) {
+
// read line and remove any whitespace at the end
const QString &line = hostfile_stream.readLine().trimmed();
// skip comments and empty lines
+ if(line.isEmpty() || line.startsWith('#'))
+ continue;
+
// everything else should be a rule
// format is <redirect> <host>
// 0.0.0.0 hostname
const QStringList &parts = line.split(' ');
const QString &redirect = parts.at(0);
- for(const QString &host : parts.mid(1)) {
- if(!rules.contains(host)) {
+ for(auto i = parts.constBegin() + 1; i != parts.constEnd(); ++i) {
+ if(!rules.contains(*i)) {
UrlRequestInterceptor::HostRule rule{};
- rule.isBlocking = redirect == "0.0.0.0";
- rules.insert(host, rule);
+ rule.isBlocking = (redirect == "0.0.0.0");
+ rules.insert(*i, rule);
}
}
+
+// for(const QString &host : parts.mid(1)) {
+// if(!rules.contains(host)) {
+// UrlRequestInterceptor::HostRule rule{};
+// rule.isBlocking = redirect == "0.0.0.0";
+// rules.insert(host, rule);
+// }
+// }
}
hostfile.close();
}
return rules;
-}; \ No newline at end of file
+};