static void PostVideoFilterResult(const Url & url,DWORD dwFilterType) { static HWND hNotifyWnd = ::FindWindow(L"{AF78EE96-9716-455c-B89E-BC1CA0AEC7F1}_cleanmainmsg", NULL); if(hNotifyWnd != NULL) { int len = url.GetString().length(); char *szUrl = new char[len+1]; memset(szUrl,0,len+1); strcpy_s(szUrl,len+1,url.GetString().c_str()); if (!::PostMessage(hNotifyWnd, WM_USER + 302,WPARAM(dwFilterType), LPARAM(szUrl))) { delete szUrl; } } }
bool RedirectRule::shouldRedirect(const Url & u) { std::string url=u.GetString(); if (m_reParse.empty() || url.find(m_reParse.c_str()) != std::string::npos) { return false; } if(!this->m_isMatchProtocol) { //url=url.substr(url.length()-u.GetScheme().length()); if (!u.GetScheme().empty()) { url=url.substr(u.GetScheme().length()+3); } } if (!m_vwhiteContent.empty() && isMatchContent(m_vwhiteContent,url)) { return false; } if (!m_vblackContent.empty() && !isMatchContent(m_vblackContent,url)) { return false; } bool ret = adbMatch(url.c_str(),m_reRedirect.c_str()); if (ret) { m_rule; } return ret; }
int RuleMap::shouldFilterByShortcut(const Url & mainURL,const Url & url,FilterType t) { int iRet = 0; StringVector shortcuts; collectShortcuts(url.GetString(), shortcuts); this->m_ShortcutFilterRules.prepareStartFind(); for (StringVector::iterator it = shortcuts.begin(); it != shortcuts.end(); ++it) { iRet = m_ShortcutWhiteRules.doFilter(mainURL, *it, url, t); if (iRet != 0) return 0; } for (FilterRuleVector::iterator it = this->m_UnshortcutWhiteRules.begin(); it != this->m_UnshortcutWhiteRules.end(); ++it) { iRet = (*it)->shouldFilter(mainURL, url, t); if (iRet != 0) return 0; } for (StringVector::iterator it = shortcuts.begin(); it != shortcuts.end(); ++it) { iRet = this->m_ShortcutFilterRules.doFilter(mainURL, *it, url, t); if (iRet != 0) return iRet; } for (FilterRuleVector::iterator it = this->m_UnshortcutFilterRules.begin(); it != this->m_UnshortcutFilterRules.end(); ++it) { iRet = (*it)->shouldFilter(mainURL, url, t); if (iRet != 0) return iRet; } return iRet; }
int FilterRule::shouldFilter(const Url & mainURL,const Url & u,FilterType t) { if (!m_stateDomains.empty() && !isMatchState(m_stateDomains)) { return 0; } std::string url=u.GetString(); bool ret; if(!this->m_isMatchProtocol) { //url=url.substr(url.length()-u.GetScheme().length()); if (!u.GetScheme().empty()) { url=url.substr(u.GetScheme().length()+3); } } if(!this->isMatchThirdParty(mainURL,u)) { return 0; } if(!this->isMatchDomains(u) || !this->isMatchDomains(mainURL)) { return 0; } if(!isMatchType(u,t)) { return 0; } ret=adbMatch(url.c_str(),m_reFilter.c_str()); if (ret) { if (m_iresponse > 0 && m_iresponse<1000) { return m_iresponse; } return 1; } return 0; }
/* when t is 0, the caller wants that the FilterRule decide the url type itself */ bool FilterRule::isMatchType(const Url &u, FilterType t) { if(m_type==0) { return true; } if(t!=0) { return t&m_type?true:false; } std::string url=u.GetString(); t=m_type; t&=~FILTER_TYPE_SCRIPT; if(m_type&FILTER_TYPE_SCRIPT && boost::iends_with(url,".js")) { return true; } t&=~FILTER_TYPE_IMAGE; if(m_type&FILTER_TYPE_IMAGE) { if(boost::iends_with(url,".png") ||boost::iends_with(url,".jpg") ||boost::iends_with(url,".gif") ||boost::iends_with(url,".bmp") ||boost::iends_with(url,".jpeg") ||boost::iends_with(url,".ico")) return true; } t&=~FILTER_TYPE_STYLESHEET; if(m_type&FILTER_TYPE_STYLESHEET && boost::iends_with(url,".css")) { return true; } t&=~FILTER_TYPE_OBJECT; if(m_type & FILTER_TYPE_OBJECT && boost::iends_with(url,".swf")) { //filter flash return true; } return false; }
static void PostVideoFilterResult(const Url & url,DWORD dwFilterType) { static std::wstring szClassName = GetMsgWndClassNameByPid(); static HWND hNotifyWnd = ::FindWindow(szClassName.c_str(), NULL); if(hNotifyWnd != NULL) { int len = url.GetString().length(); char *szUrl = new char[len+1]; memset(szUrl,0,len+1); strcpy_s(szUrl,len+1,url.GetString().c_str()); if (!::PostMessage(hNotifyWnd, WM_USER + 302,WPARAM(dwFilterType), LPARAM(szUrl))) { delete szUrl; } } }
bool FilterRule::isMatchThirdParty(const Url &mainURL, const Url &other) { if(!this->m_filterThirdParty) return true; if(mainURL.GetString().empty()) return true; return boost::iends_with(other.GetHost(),mainURL.GetHost()) == this->m_matchFirstParty; }
bool ReplaceRule::shouldReplace(const Url & u) { if (!m_stateDomains.empty() && !isMatchState(m_stateDomains)) { return false; } std::string url=u.GetString(); bool ret; if(!this->m_isMatchProtocol) { //url=url.substr(url.length()-u.GetScheme().length()); if (!u.GetScheme().empty()) { url=url.substr(u.GetScheme().length()+3); } } ret=adbMatch(url.c_str(),m_reReplace.c_str()); return ret; }