bool EAWebKitDomainFilter::PathAllowed(const FixedString8_128& path, const FixedString8_128& excludedPaths) const { //We make a copy because we do custom processing on it. FixedString8_128 excludedPathsLocal(excludedPaths); //If the excludedPaths is empty, we assume that all the paths are okay. if(excludedPathsLocal.empty()) return true; //Expect the user to put a ";" at the end and remove it if found. if(excludedPathsLocal.find_last_of(";") == excludedPathsLocal.length()-1) excludedPathsLocal.pop_back(); FixedString8_128 pathShort; FixedString8_128 excludedPath; FixedString8_128::size_type lastDelimPos = 0; FixedString8_128::size_type delimPos = excludedPathsLocal.find_first_of(";"); while(delimPos != FixedString8_128::npos) { excludedPath = excludedPathsLocal.substr(lastDelimPos, delimPos); pathShort = path.substr(0,excludedPath.length()); if(pathShort.comparei(excludedPath)) return false; lastDelimPos = delimPos+1; //Doing this simplifies the code delimPos = excludedPathsLocal.find_first_of(";",lastDelimPos); } excludedPath = excludedPathsLocal.substr(lastDelimPos, excludedPathsLocal.length()); pathShort = path.substr(0,excludedPath.length()); if(pathShort.comparei(excludedPath) == 0) return false; return true; }
//replicate the code from the cookie manager. This code can use a little cleanup. But since it is tried and tested, keeping it as is. bool EAWebKitDomainFilter::DomainAllowed(const FixedString8_128& host, const FixedString8_128& allowedDomain) const { int32_t start = host.length() - allowedDomain.length(); if(start >= 0 ) { FixedString8_128 hostDomain = host.substr(start,FixedString8_128::npos); if( hostDomain.comparei(allowedDomain) == 0) { if( (start == 0) || (allowedDomain[0] == '.') || (host[start-1] == '.')) { return true; } } } else if (start == -1) { FixedString8_128 hostWithDot(FixedString8_128::CtorSprintf(),".%s",host.c_str()); if( hostWithDot.comparei(allowedDomain) == 0) return true; } return false; }