diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-02-10 20:58:39 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-05-30 11:01:35 +0300 |
commit | d1287f43964633035938f4f4d4133bb6d9da7b3e (patch) | |
tree | d09efa4074815c20be9bd6348203fe4336dfe716 /lib/urlfilter/adblock/parser.cpp | |
parent | Fix segfault in release build (diff) | |
download | smolbote-d1287f43964633035938f4f4d4133bb6d9da7b3e.tar.xz |
staging: smolblok
smolblok is a replacement for the current lib/urlfilter AdBlockPlus
and hostlist format filter parser. It is a library that uses plugins to
provide support for different filter formats.
staging/adblock: AdBlockPlus parser plugin
plugins/smolblok_hostlist: hostlist format parser plugin
Headers will be installed to include/smolbote/
Remove lib/urlfilter
Diffstat (limited to 'lib/urlfilter/adblock/parser.cpp')
-rw-r--r-- | lib/urlfilter/adblock/parser.cpp | 75 |
1 files changed, 0 insertions, 75 deletions
diff --git a/lib/urlfilter/adblock/parser.cpp b/lib/urlfilter/adblock/parser.cpp deleted file mode 100644 index 68f895d..0000000 --- a/lib/urlfilter/adblock/parser.cpp +++ /dev/null @@ -1,75 +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 "parser.h" - -std::optional<std::pair<QString, QString>> parseComment(QString &line) -{ - const QLatin1String separator(": "); - if(line.contains(separator)) { - const QStringList comment = line.mid(1).split(QLatin1String(": ")); - return std::make_pair(comment.at(0).trimmed(), comment.at(1).trimmed()); - } else - return std::nullopt; -} - -std::optional<std::pair<QWebEngineUrlRequestInfo::ResourceType, bool>> parseResourceOption(const QString &option) -{ - const bool exception = !option.startsWith(QLatin1String("~")); - - if(option.endsWith(QLatin1String("script"))) { - // external scripts loaded via HTML script tag - return std::make_pair(QWebEngineUrlRequestInfo::ResourceTypeScript, exception); - - } else if(option.endsWith(QLatin1String("image"))) { - // regular images, typically loaded via HTML img tag - return std::make_pair(QWebEngineUrlRequestInfo::ResourceTypeImage, exception); - - } else if(option.endsWith(QLatin1String("stylesheet"))) { - // external CSS stylesheet files - return std::make_pair(QWebEngineUrlRequestInfo::ResourceTypeStylesheet, exception); - - } else if(option.endsWith(QLatin1String("object"))) { - // content handled by browser plugins, e.g. Flash or Java - return std::make_pair(QWebEngineUrlRequestInfo::ResourceTypeObject, exception); - - } else if(option.endsWith(QLatin1String("xmlhttprequest"))) { - // requests started using the XMLHttpRequest object or fetch() API - return std::make_pair(QWebEngineUrlRequestInfo::ResourceTypeXhr, exception); - - } else if(option.endsWith(QLatin1String("object-subrequest"))) { - // requests started by plugins like Flash - return std::make_pair(QWebEngineUrlRequestInfo::ResourceTypePluginResource, exception); - - } else if(option.endsWith(QLatin1String("subdocument"))) { - // embedded pages, usually included via HTML frames - return std::make_pair(QWebEngineUrlRequestInfo::ResourceTypeSubFrame, exception); - - } else if(option.endsWith(QLatin1String("ping"))) { - // requests started by <a ping> or navigator.sendBeacon() - return std::make_pair(QWebEngineUrlRequestInfo::ResourceTypePing, exception); - - } else if(option.endsWith(QLatin1String("websocket"))) { - // requests initiated via WebSocket object - qDebug("Resource type 'websocket' not available"); - - } else if(option.endsWith(QLatin1String("webrtc"))) { - // connections opened via RTCPeerConnection instances to ICE servers - qDebug("Resource type 'webrtc' not available"); - - } else if(option.endsWith(QLatin1String("document"))) { - // the page itself - return std::make_pair(QWebEngineUrlRequestInfo::ResourceTypeMainFrame, exception); - - } else if(option.endsWith(QLatin1String("other"))) { - return std::make_pair(QWebEngineUrlRequestInfo::ResourceTypeUnknown, exception); - } - - qDebug("TODO: %s", qUtf8Printable(option)); - return std::nullopt; -} |