HTTP Pluggable protocol
I'm trying to create my custom HTTP protocol. I've created a new ATL
control which implements IInternetProtocolRoot and I've registered it
using RegisterNameSpace as the current HTTP protocol (after saving the
original HTTP interface).
When the user surfs via the software, I want to be able to use the
original protocol to download images and other media, and to use my
protocol (with the original one) to download html page, change them and
serve them back to the application. For example, when the user tries to
surf with the software, the custom protocol will filter all elements
containing the word "sex" in them. I want to filter it BEFORE it
reaches the browser at all, that's why I'm using a custom protocol.
When trying to serve a normal data without altering - there is no
problem. But when I'm trying to download an html page, and only then
serve it - it doesn't work.
I've implemented IInternetProtocolSink, and I'm calling the original
IInternetProtocolRoot::Start method, passing my own
IInternetProtocolSink as a pointer. Then I'm trying to read the data
when ReportData is being called,
STDMETHOD(ReportData)(DWORD grfBSCF,ULONG ulProgress,ULONG
ulProgressMax)
{
ATLTRACE(_T("%s(%u,%u,%u)\n"),__FUNCTION__,grfBSCF,ulProgress,ulProgressMax);
if (m_szMimeType.Find(L"text/html")>=0)
{
CHAR szBuffer[4096];
HRESULT hResult;
for (ULONG
nRead=0;(hResult=m_pProtocol->Read(szBuffer,sizeof(szBuffer),&nRead))==S_OK;nRead=0)
m_szHtml.append(szBuffer,nRead);
if (hResult==S_FALSE)
{ // End of stream
CreateStreamOnHGlobal(NULL,TRUE,&m_pStream);
m_pStream->Write(m_szHtml.data(),m_szHtml.length(),NULL);
LARGE_INTEGER Li={0};
m_pStream->Seek(Li,STREAM_SEEK_SET,NULL);
return
m_pSink->ReportData(BSCF_DATAFULLYAVAILABLE,m_szHtml.length(),m_szHtml.length());
}
return S_OK;
}
return m_pSink->ReportData(grfBSCF,ulProgress,ulProgressMax);
}
But it doesn't work for me. IE just hangs.
date: 9 Dec 2005 00:14:14 -0800
author: unknown