aboutsummaryrefslogtreecommitdiff
path: root/src/webengine/urlinterceptor.cpp
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-07-07 19:45:45 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-07-07 19:45:45 +0200
commit0e4ee2ed1c64130262e42ddfc87f2d8944c5a10c (patch)
tree45b852937529d19101dee06c82c924c57c3a47aa /src/webengine/urlinterceptor.cpp
parentAdd web/urlfilter (diff)
downloadsmolbote-0e4ee2ed1c64130262e42ddfc87f2d8944c5a10c.tar.xz
Integrate urlfilter with urlrequestinterceptor
Diffstat (limited to 'src/webengine/urlinterceptor.cpp')
-rw-r--r--src/webengine/urlinterceptor.cpp40
1 files changed, 34 insertions, 6 deletions
diff --git a/src/webengine/urlinterceptor.cpp b/src/webengine/urlinterceptor.cpp
index 4e1b2f1..1b44c47 100644
--- a/src/webengine/urlinterceptor.cpp
+++ b/src/webengine/urlinterceptor.cpp
@@ -11,6 +11,8 @@
#include <QTextStream>
#include <configuration/configuration.h>
#include <boost/algorithm/string.hpp>
+#include <QJsonDocument>
+#include <QJsonArray>
UrlRequestInterceptor::UrlRequestInterceptor(const std::unique_ptr<Configuration> &config, QObject *parent)
: QWebEngineUrlRequestInterceptor(parent)
@@ -36,8 +38,29 @@ UrlRequestInterceptor::UrlRequestInterceptor(const std::unique_ptr<Configuration
m_headers.emplace_back(pair);
}
}
+
+ QFile rules(config->value<QString>("filter.json-path").value());
+ if(rules.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ auto doc = QJsonDocument::fromJson(rules.readAll()).object();
+
+ Q_ASSERT(doc.value("domains").isArray());
+ for(QJsonValue d : doc.value("domains").toArray()) {
+ domain.addDomain(d.toString());
+ }
+
+ Q_ASSERT(doc.value("rules").isArray());
+ for(QJsonValue rule : doc.value("rules").toArray()) {
+ auto p = std::make_unique<FilterRule>(rule.toObject());
+ parseJson(p, rule.toObject());
+ domain.addRule(p);
+ }
+
+ rules.close();
+ }
+
}
+// test DNT on https://browserleaks.com/donottrack
void UrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
{
for(const Header &header : m_headers) {
@@ -46,15 +69,20 @@ void UrlRequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo &info)
if(rules.contains(info.requestUrl().host())) {
info.block(rules.value(info.requestUrl().host()).isBlocking);
+ return;
+ }
+
+ if(domain.hasMatch(info.requestUrl().host())) {
+ domain.process(info);
}
#ifdef QT_DEBUG
- qDebug("request>>>");
- qDebug("firstParty url=%s", qUtf8Printable(info.firstPartyUrl().toString()));
- qDebug("firstParty host=%s", qUtf8Printable(info.firstPartyUrl().host()));
- qDebug("request url=%s", qUtf8Printable(info.requestUrl().toString()));
- qDebug("request host=%s", qUtf8Printable(info.requestUrl().host()));
- qDebug("<<<");
+// qDebug("request>>>");
+// qDebug("firstParty url=%s", qUtf8Printable(info.firstPartyUrl().toString()));
+// qDebug("firstParty host=%s", qUtf8Printable(info.firstPartyUrl().host()));
+// qDebug("request url=%s", qUtf8Printable(info.requestUrl().toString()));
+// qDebug("request host=%s", qUtf8Printable(info.requestUrl().host()));
+// qDebug("<<<");
#endif
}