std::string CAdblockPlusClient::GetWhitelistingFilter(const std::wstring& url, const std::vector<std::string>& frameHierarchy)
{
  DEBUG_GENERAL((L"IsWhitelistedUrl: " + url + L" start").c_str());
  Communication::OutputBuffer request;
  request << Communication::PROC_GET_WHITELISTING_FITER << ToUtf8String(url) << frameHierarchy;

  Communication::InputBuffer response;
  if (!CallEngine(request, response)) 
    return "";

  std::string filterText;
  response >> filterText;

  DEBUG_GENERAL((L"IsWhitelistedUrl: " + url + L" end").c_str());
  return filterText;
}
bool CAdblockPlusClient::IsWhitelistedUrl(const std::wstring& url)
{
  DEBUG_GENERAL((L"IsWhitelistedUrl: " + url + L" start").c_str());
  Communication::OutputBuffer request;
  request << Communication::PROC_IS_WHITELISTED_URL << ToUtf8String(url);

  Communication::InputBuffer response;
  if (!CallEngine(request, response)) 
    return false;

  bool isWhitelisted;
  response >> isWhitelisted;

  DEBUG_GENERAL((L"IsWhitelistedUrl: " + url + L" end").c_str());
  return isWhitelisted;
}
bool CPluginSettings::ReadWhitelist(bool isDebug)
{
  bool isRead = true;

  DEBUG_SETTINGS("SettingsWhitelist::Read")

    if (isDebug)
    {
      DEBUG_GENERAL("*** Loading whitelist settings");
    }

    CPluginSettingsWhitelistLock lock;
    if (lock.IsLocked())
    {
      ClearWhitelist();

      s_criticalSectionLocal.Lock();
      m_whitelistedDomains = CPluginClient::GetInstance()->GetExceptionDomains();
      s_criticalSectionLocal.Unlock();
    }
    else
    {
      isRead = false;
    }

    return isRead;
}
bool CAdblockPlusClient::IsFirstRun()
{
  DEBUG_GENERAL("IsFirstRun");
  Communication::InputBuffer response;
  if (!CallEngine(Communication::PROC_IS_FIRST_RUN_ACTION_NEEDED, response)) return false;
  bool res;
  response >> res;
  return res;
}
bool CAdblockPlusClient::CallEngine(Communication::OutputBuffer& message, Communication::InputBuffer& inputBuffer)
{
  DEBUG_GENERAL("CallEngine start");
  CriticalSection::Lock lock(enginePipeLock);
  try
  {
    if (!enginePipe)
      enginePipe.reset(OpenEnginePipe());
    enginePipe->WriteMessage(message);
    inputBuffer = enginePipe->ReadMessage();
  }
  catch (const std::exception& ex)
  {
    DEBUG_EXCEPTION(ex);
    return false;
  }
  DEBUG_GENERAL("CallEngine end");
  return true;
}
std::wstring CAdblockPlusClient::GetPref(const std::wstring& name, const std::wstring& defaultValue)
{
  DEBUG_GENERAL((L"GetPref: " + name + L" start").c_str());
  Communication::OutputBuffer request;
  request << Communication::PROC_GET_PREF << ToUtf8String(name);

  Communication::InputBuffer response;
  if (!CallEngine(request, response)) 
    return defaultValue;
  bool success;
  response >> success;
  if (success)
  {
    std::string value;
    response >> value;
    DEBUG_GENERAL((L"GetPref: " + name + L" end").c_str());
    return ToUtf16String(value);
  }
  else
  {
示例#7
0
static void print_charset_table(void)
{
    int c,r,i;
    char ch;
    if (!DEBUG_GENERAL(1))
	return;
    printf( "\n" );
    for (r=0; r<4; r+=1) {
	for (c=0; c<64; c+=1) {
	    i=r*64+c;
	    ch=charset_table[i];
	    if (ch != 0x08 && ch != 0x09 && ch != '\n' && ch != '\r')
		printf(" %02X.%2c.%02X", i, ch, ch);
	    else
		printf(" %02X.%02X.%02X", i, ch, ch);
	    if ((c & 15) == 15)
		printf( "\n" );
	}
    }
    printf( "\n" );
}
void passthrough_setup()
{
    /* check if the input is seekable, if it is, we don't need to buffer
     * things in memory => configure passmode accordingly
     */

    if (!passthrough)
	return;

    passmode = PASS_MEM;

    if (passmode == PASS_MEM)
	textblock_init();

    if (DEBUG_GENERAL(2)) {
	const char *m;
	switch (passmode) {
	case PASS_MEM:  m = "cache in memory"; break;
	case PASS_SEEK: m = "rewind and reread file"; break;
	default:        m = "unknown"; break;
	}
	fprintf(fpo, "passthrough mode: %s\n", m);
    }
}
STDMETHODIMP WBPassthruSink::BeginningTransaction(LPCWSTR szURL, LPCWSTR szHeaders, DWORD dwReserved, LPWSTR* pszAdditionalHeaders)
{
  if (!szURL)
  {
    return E_POINTER;
  }
  std::wstring src = szURL;
  UnescapeUrl(src);
  DEBUG_GENERAL(src);

  std::string acceptHeader = ExtractHttpAcceptHeader(m_spTargetProtocol);

  if (pszAdditionalHeaders)
  {
    *pszAdditionalHeaders = nullptr;
  }

  CComPtr<IHttpNegotiate> httpNegotiate;
  QueryServiceFromClient(&httpNegotiate);
  // This fills the pszAdditionalHeaders with more headers. One of which is the Referer header, which we need.
  // There doesn't seem to be any other way to get this header before the request has been made.
  HRESULT nativeHr = httpNegotiate ? httpNegotiate->BeginningTransaction(szURL, szHeaders, dwReserved, pszAdditionalHeaders) : S_OK;

  if (pszAdditionalHeaders && *pszAdditionalHeaders)
  {
    m_boundDomain = ExtractHttpHeader<std::wstring>(*pszAdditionalHeaders, L"Referer:", L"\n");
  }
  m_boundDomain = TrimString(m_boundDomain);
  m_contentType = GetContentType(ATL::CString(acceptHeader.c_str()), m_boundDomain, src);

  CPluginTab* tab = CPluginClass::GetTab(::GetCurrentThreadId());
  CPluginClient* client = CPluginClient::GetInstance();

  if (tab && client)
  {
    std::wstring documentUrl = tab->GetDocumentUrl();
    // Page is identical to document => don't block
    if (documentUrl == src)
    {
      return nativeHr;
    }
    else if (CPluginSettings::GetInstance()->IsPluginEnabled() && !client->IsWhitelistedUrl(documentUrl))
    {
      if (tab->IsFrameCached(src))
      {
        m_contentType = ContentType::CONTENT_TYPE_SUBDOCUMENT;
      }
    }
  }

  if (IsFlashRequest(pszAdditionalHeaders))
  {
    m_contentType = ContentType::CONTENT_TYPE_OBJECT_SUBREQUEST;
  }

  if (pszAdditionalHeaders && *pszAdditionalHeaders && IsXmlHttpRequest(*pszAdditionalHeaders))
  {
    m_contentType = ContentType::CONTENT_TYPE_XMLHTTPREQUEST;
  }

  if (client->ShouldBlock(szURL, m_contentType, m_boundDomain, /*debug flag but must be set*/true))
  {
    // NOTE: Feeding custom HTML to Flash, instead of original object subrequest
    // doesn't have much sense. It also can manifest in unwanted result
    // like video being blocked (See https://issues.adblockplus.org/ticket/1669)
    // So we report blocked object subrequests as failed, not just empty HTML.
    m_isCustomResponse = m_contentType != ContentType::CONTENT_TYPE_OBJECT_SUBREQUEST;
    return E_ABORT;
  }
  return nativeHr;
}