diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-02-10 20:58:39 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-04-21 20:14:50 +0300 |
commit | c3559b24eba76052deb9d4ce79e4704815d902a5 (patch) | |
tree | 900dd0a5b8039e5e7bdd9ad609d9b3ae45d9dbde /staging/adblock/options.cpp | |
parent | Add libfuzzer test to libconfiguration (diff) | |
download | smolbote-c3559b24eba76052deb9d4ce79e4704815d902a5.tar.xz |
staging: rewrite AdblockPlus parser yet again
Diffstat (limited to 'staging/adblock/options.cpp')
-rw-r--r-- | staging/adblock/options.cpp | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/staging/adblock/options.cpp b/staging/adblock/options.cpp new file mode 100644 index 0000000..0f70570 --- /dev/null +++ b/staging/adblock/options.cpp @@ -0,0 +1,111 @@ +/* + * 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://library.iserlohn-fortress.net/aqua/smolbote.git + * + * SPDX-License-Identifier: GPL-3.0 + */ + +#include "options.h" + +using namespace AdblockPlus; + +bool Options::set(const QString &opt) +{ + const bool exception = opt.startsWith("~"); + const QString option = [exception, opt]() { + if(exception) + return opt.mid(1); + else + return opt; + }(); + + if(option == "match-case") { + matchcase = exception; + return true; + } + + // TODO: map all ResourceType's to their respective strings + // TODO: websocket, webrtc, elemhide, generichide, genericblock, popup + + else if(option == "document") { + resource_options[QWebEngineUrlRequestInfo::ResourceTypeMainFrame] = exception; + return true; + } + + else if(option == "subdocument") { + resource_options[QWebEngineUrlRequestInfo::ResourceTypeSubFrame] = exception; + return true; + } + + else if(option == "stylesheet") { + resource_options[QWebEngineUrlRequestInfo::ResourceTypeStylesheet] = exception; + return true; + } + + else if(option == "script") { + resource_options[QWebEngineUrlRequestInfo::ResourceTypeScript] = exception; + return true; + } + + else if(option == "image") { + resource_options[QWebEngineUrlRequestInfo::ResourceTypeImage] = exception; + return true; + } + + else if(option == "font") { + resource_options[QWebEngineUrlRequestInfo::ResourceTypeFontResource] = exception; + return true; + } + + else if(option == "other") { + // An "other" subresource. + resource_options[QWebEngineUrlRequestInfo::ResourceTypeSubResource] = exception; + return true; + } + + else if(option == "object") { + resource_options[QWebEngineUrlRequestInfo::ResourceTypeObject] = exception; + return true; + } + + else if(option == "media") { + resource_options[QWebEngineUrlRequestInfo::ResourceTypeMedia] = exception; + return true; + } + /* +QWebEngineUrlRequestInfo::ResourceTypeWorker 9 The main resource of a dedicated worker. +QWebEngineUrlRequestInfo::ResourceTypeSharedWorker 10 The main resource of a shared worker. +QWebEngineUrlRequestInfo::ResourceTypePrefetch 11 An explicitly requested prefetch. +QWebEngineUrlRequestInfo::ResourceTypeFavicon 12 A favicon. +*/ + else if(option == "xmlhttprequest") { + resource_options[QWebEngineUrlRequestInfo::ResourceTypeXhr] = exception; + return true; + } + + else if(option == "ping") { + resource_options[QWebEngineUrlRequestInfo::ResourceTypePing] = exception; + return true; + } + + /* +QWebEngineUrlRequestInfo::ResourceTypeServiceWorker 15 The main resource of a service worker. +QWebEngineUrlRequestInfo::ResourceTypeCspReport 16 A report of Content Security Policy (CSP) violations. CSP reports are in JSON format and they are delivered by HTTP POST requests to specified servers. (Added in Qt 5.7) +QWebEngineUrlRequestInfo::ResourceTypePluginResource 17 A resource requested by a plugin. (Added in Qt 5.7) +QWebEngineUrlRequestInfo::ResourceTypeNavigationPreloadMainFrame 19 A main-frame service worker navigation preload request. (Added in Qt 5.14) +QWebEngineUrlRequestInfo::ResourceTypeNavigationPreloadSubFrame 20 A sub-frame service worker navigation preload request. (Added in Qt 5.14) +QWebEngineUrlRequestInfo::ResourceTypeUnknown 255 Unknown request type. + */ + + // Restriction to third-party/first-party requests + else if(option == "third-party") { + if(exception) + thirdparty = false; + else + firstparty = false; + return true; + } + + return false; +} |