bool SBinetCookie::matchRequest(const char *domain, const char *path, const SWIutilLogger* logger) const { bool match = true; if (!matchDomain(_Domain.c_str(), domain, logger)) { match = false; } else if (!matchPath(_Path.c_str(), path, logger)) { match = false; } // TBD, if port was specified by the remote web server for the // cookie, the port must be included in the list of ports of the // cookie's port attribute. We aren't returning that information yet // so we don't even have a port stored in our cookies. if (logger && logger->DiagIsEnabled(MODULE_SBINET_COOKIE_TAGID)) { char expStr[64]; logger->Diag(MODULE_SBINET_COOKIE_TAGID, L"SBinetCookie::matchRequest", L"match: %s, (domain = '%S', path = '%S') compared to " L"(name = '%S', value = '%S', domain = '%S', " L"path = '%S', expires = %S (%d), secure = %s)", (match ? L"true" : L"false"), domain, path, _Name.c_str(), _Value.c_str(), _Domain.c_str(), _Path.c_str(), SBinetUtils::getTimeStampStr(_nExpires, expStr), _nExpires, (_fSecure ? L"true" : L"false")); } return match; }
bool AdBlockRule::networkMatch(const QNetworkRequest &request, const QString &domain, const QString &encodedUrl) const { if (m_type == CssRule || !m_isEnabled || m_isInternalDisabled) { return false; } bool matched = false; if (m_type == StringContainsMatchRule) { matched = encodedUrl.contains(m_matchString, m_caseSensitivity); } else if (m_type == DomainMatchRule) { matched = isMatchingDomain(domain, m_matchString); } else if (m_type == StringEndsMatchRule) { matched = encodedUrl.endsWith(m_matchString, m_caseSensitivity); } else if (m_type == RegExpMatchRule) { if (!isMatchingRegExpStrings(encodedUrl)) { return false; } matched = (m_regExp->regExp.indexIn(encodedUrl) != -1); } if (matched) { // Check domain restrictions if (hasOption(DomainRestrictedOption) && !matchDomain(domain)) { return false; } // Check third-party restriction if (hasOption(ThirdPartyOption) && !matchThirdParty(request)) { return false; } // Check object restrictions if (hasOption(ObjectOption) && !matchObject(request)) { return false; } // Check subdocument restriction if (hasOption(SubdocumentOption) && !matchSubdocument(request)) { return false; } // Check xmlhttprequest restriction if (hasOption(XMLHttpRequestOption) && !matchXmlHttpRequest(request)) { return false; } // Check image restriction if (hasOption(ImageOption) && !matchImage(encodedUrl)) { return false; } } return matched; }
bool AdBlockRule::networkMatch(const QWebEngineUrlRequestInfo &request, const QString &domain, const QString &encodedUrl) const { if (m_type == CssRule || !m_isEnabled || m_isInternalDisabled) { return false; } bool matched = stringMatch(domain, encodedUrl); if (matched) { // Check domain restrictions if (hasOption(DomainRestrictedOption) && !matchDomain(request.firstPartyUrl().host())) { return false; } // Check third-party restriction if (hasOption(ThirdPartyOption) && !matchThirdParty(request)) { return false; } // Check object restrictions if (hasOption(ObjectOption) && !matchObject(request)) { return false; } // Check subdocument restriction if (hasOption(SubdocumentOption) && !matchSubdocument(request)) { return false; } // Check xmlhttprequest restriction if (hasOption(XMLHttpRequestOption) && !matchXmlHttpRequest(request)) { return false; } // Check image restriction if (hasOption(ImageOption) && !matchImage(request)) { return false; } // Check script restriction if (hasOption(ScriptOption) && !matchScript(request)) { return false; } // Check stylesheet restriction if (hasOption(StyleSheetOption) && !matchStyleSheet(request)) { return false; } // Check object-subrequest restriction if (hasOption(ObjectSubrequestOption) && !matchObjectSubrequest(request)) { return false; } } return matched; }
bool CookieJar::listMatchesDomain(const QStringList &list, const QString &cookieDomain) { foreach(const QString & d, list) { if (matchDomain(d, cookieDomain)) { return true; } } return false; }
bool CookieJar::rejectCookie(const QString &domain, const QNetworkCookie &cookie) const { Q_UNUSED(domain) const QString &cookieDomain = cookie.domain(); if (!m_allowCookies) { bool result = listMatchesDomain(m_whitelist, cookieDomain); if (!result) { #ifdef COOKIE_DEBUG qDebug() << "not in whitelist" << cookie; #endif return true; } } if (m_allowCookies) { bool result = listMatchesDomain(m_blacklist, cookieDomain); if (result) { #ifdef COOKIE_DEBUG qDebug() << "found in blacklist" << cookie; #endif return true; } } // This feature is now natively in QtWebKit 2.3 #if QTWEBKIT_TO_2_3 if (m_blockThirdParty) { bool result = matchDomain(cookieDomain, domain); if (!result) { #ifdef COOKIE_DEBUG qDebug() << "purged for domain mismatch" << cookie << cookieDomain << domain; #endif return true; } } #endif if (m_filterTrackingCookie && cookie.name().startsWith("__utm")) { #ifdef COOKIE_DEBUG qDebug() << "purged as tracking " << cookie; #endif return true; } return false; }
bool SnippetRule:: match(Uri const& uri) const { return matchDomain(uri.host(), m_domains.get()); }