| OLD | NEW |
| 1 // Copyright 2007 Igor Tandetnik | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 | |
| 15 #ifndef PASSTHROUGHAPP_PROTOCOLIMPL_INL | 1 #ifndef PASSTHROUGHAPP_PROTOCOLIMPL_INL |
| 16 #define PASSTHROUGHAPP_PROTOCOLIMPL_INL | 2 #define PASSTHROUGHAPP_PROTOCOLIMPL_INL |
| 17 | 3 |
| 18 #if _MSC_VER > 1000 | 4 #if _MSC_VER > 1000 |
| 19 #pragma once | 5 » #pragma once |
| 20 #endif // _MSC_VER > 1000 | 6 #endif // _MSC_VER > 1000 |
| 21 | 7 |
| 22 #ifndef PASSTHROUGHAPP_PROTOCOLIMPL_H | 8 #ifndef PASSTHROUGHAPP_PROTOCOLIMPL_H |
| 23 #error ProtocolImpl.inl requires ProtocolImpl.h to be included first | 9 » #error ProtocolImpl.inl requires ProtocolImpl.h to be included first |
| 24 #endif | 10 #endif |
| 25 | 11 |
| 26 namespace PassthroughAPP | 12 namespace PassthroughAPP |
| 27 { | 13 { |
| 28 | 14 |
| 29 namespace Detail | 15 namespace Detail |
| 30 { | 16 { |
| 31 template <class T> | 17 |
| 32 inline HRESULT WINAPI QIPassthrough<T>:: | 18 template <class T> |
| 33 QueryInterfacePassthroughT(void* pv, REFIID riid, LPVOID* ppv, DWORD_PTR d
w) | 19 inline HRESULT WINAPI QIPassthrough<T>:: |
| 34 { | 20 QueryInterfacePassthroughT(void* pv, REFIID riid, LPVOID* ppv, DWORD_PTR
dw) |
| 35 ATLASSERT(pv != 0); | 21 { |
| 36 T* pT = static_cast<T*>(pv); | 22 ATLASSERT(pv != 0); |
| 37 | 23 T* pT = static_cast<T*>(pv); |
| 38 IUnknown* punkTarget = pT->GetTargetUnknown(); | 24 |
| 39 ATLASSERT(punkTarget != 0); | 25 IUnknown* punkTarget = pT->GetTargetUnknown(); |
| 40 if (!punkTarget) | 26 ATLASSERT(punkTarget != 0); |
| 41 { | 27 if (!punkTarget) |
| 42 ATLTRACE(_T("Interface queried before target unknown is set")); | 28 { |
| 43 return E_UNEXPECTED; | 29 ATLTRACE(_T("Interface queried before target unknown is set")); |
| 44 } | 30 return E_UNEXPECTED; |
| 45 | 31 } |
| 46 IUnknown* punkWrapper = pT->GetUnknown(); | 32 |
| 47 | 33 IUnknown* punkWrapper = pT->GetUnknown(); |
| 48 typename T::ObjectLock lock(pT); | 34 |
| 49 return QueryInterfacePassthrough( | 35 typename T::ObjectLock lock(pT); |
| 50 pv, riid, ppv, dw, punkTarget, punkWrapper); | 36 return QueryInterfacePassthrough( |
| 51 } | 37 pv, riid, ppv, dw, punkTarget, punkWrapper); |
| 52 | 38 } |
| 53 template <class T> | 39 |
| 54 inline HRESULT WINAPI QIPassthrough<T>:: | 40 template <class T> |
| 55 QueryInterfaceDebugT(void* pv, REFIID riid, LPVOID* ppv, DWORD_PTR dw) | 41 inline HRESULT WINAPI QIPassthrough<T>:: |
| 56 { | 42 QueryInterfaceDebugT(void* pv, REFIID riid, LPVOID* ppv, DWORD_PTR dw) |
| 57 ATLASSERT(pv != 0); | 43 { |
| 58 T* pT = static_cast<T*>(pv); | 44 ATLASSERT(pv != 0); |
| 59 | 45 T* pT = static_cast<T*>(pv); |
| 60 IUnknown* punkTarget = pT->GetTargetUnknown(); | 46 |
| 61 // ATLASSERT(punkTarget != 0); | 47 IUnknown* punkTarget = pT->GetTargetUnknown(); |
| 62 if (!punkTarget) | 48 ATLASSERT(punkTarget != 0); |
| 63 { | 49 if (!punkTarget) |
| 64 // ATLTRACE(_T("Interface queried before target unknown is
set")); | 50 { |
| 65 return E_UNEXPECTED; | 51 ATLTRACE(_T("Interface queried before target unknown is set")); |
| 66 } | 52 return E_UNEXPECTED; |
| 67 | 53 } |
| 68 typename T::ObjectLock lock(pT); | 54 |
| 69 | 55 typename T::ObjectLock lock(pT); |
| 70 return QueryInterfaceDebug(pv, riid, ppv, dw, punkTarget); | 56 return QueryInterfaceDebug(pv, riid, ppv, dw, punkTarget); |
| 71 } | 57 } |
| 72 | 58 |
| 73 inline HRESULT WINAPI QueryInterfacePassthrough(void* pv, REFIID riid, | 59 inline HRESULT WINAPI QueryInterfacePassthrough(void* pv, REFIID riid, |
| 74 LPVOID* ppv, DWORD_PTR dw, IUnknown* punkTarget, IUnknown* punkWrapper) | 60 LPVOID* ppv, DWORD_PTR dw, IUnknown* punkTarget, IUnknown* punkWrapper) |
| 75 { | 61 { |
| 76 ATLASSERT(pv != 0); | 62 ATLASSERT(pv != 0); |
| 77 ATLASSERT(ppv != 0); | 63 ATLASSERT(ppv != 0); |
| 78 ATLASSERT(dw != 0); | 64 ATLASSERT(dw != 0); |
| 79 ATLASSERT(punkTarget != 0); | 65 ATLASSERT(punkTarget != 0); |
| 80 | 66 |
| 81 | 67 const PassthroughItfData& data = |
| 82 const PassthroughItfData& data = | 68 *reinterpret_cast<const PassthroughItfData*>(dw); |
| 83 *reinterpret_cast<const PassthroughItfData*>(dw); | 69 |
| 84 | 70 IUnknown** ppUnk = reinterpret_cast<IUnknown**>( |
| 85 IUnknown** ppUnk = reinterpret_cast<IUnknown**>( | 71 static_cast<char*>(pv) + data.offsetUnk); |
| 86 static_cast<char*>(pv) + data.offsetUnk); | 72 |
| 87 | 73 HRESULT hr = S_OK; |
| 88 HRESULT hr = S_OK; | 74 if (!*ppUnk) |
| 89 if (!*ppUnk) | 75 { |
| 90 { | 76 CComPtr<IUnknown> spUnk; |
| 91 CComPtr<IUnknown> spUnk; | 77 hr = punkTarget->QueryInterface(riid, |
| 92 hr = punkTarget->QueryInterface(riid, | 78 reinterpret_cast<void**>(&spUnk)); |
| 93 reinterpret_cast<void**>(&spUnk)); | 79 ATLASSERT(FAILED(hr) || spUnk != 0); |
| 94 ATLASSERT(FAILED(hr) || spUnk != 0); | 80 if (SUCCEEDED(hr)) |
| 95 if (SUCCEEDED(hr)) | 81 { |
| 96 { | 82 *ppUnk = spUnk.Detach(); |
| 97 *ppUnk = spUnk.Detach(); | 83 |
| 98 | 84 // Need to QI for base interface to fill in base target
pointer |
| 99 // Need to QI for base interface to fill in base target pointer | 85 if (data.piidBase) |
| 100 if (data.piidBase) | 86 { |
| 101 { | 87 ATLASSERT(punkWrapper != 0); |
| 102 ATLASSERT(punkWrapper != 0); | 88 hr = punkWrapper->QueryInterface(*data.piidBase, |
| 103 hr = punkWrapper->QueryInterface(*data.piidBase, | 89 reinterpret_cast<void**>(&spUnk)); |
| 104 reinterpret_cast<void**>(&spUnk)); | 90 // since QI for derived interface succeeded, |
| 105 // since QI for derived interface succeeded, | 91 // QI for base interface must succeed, too |
| 106 // QI for base interface must succeed, too | 92 ATLASSERT(SUCCEEDED(hr)); |
| 107 ATLASSERT(SUCCEEDED(hr)); | 93 } |
| 108 } | 94 } |
| 109 } | 95 } |
| 110 } | 96 if (SUCCEEDED(hr)) |
| 111 if (SUCCEEDED(hr)) | 97 { |
| 112 { | 98 CComPtr<IUnknown> spItf = reinterpret_cast<IUnknown*>( |
| 113 CComPtr<IUnknown> spItf = reinterpret_cast<IUnknown*>( | 99 static_cast<char*>(pv) + data.offsetItf); |
| 114 static_cast<char*>(pv) + data.offsetItf); | 100 *ppv = spItf.Detach(); |
| 115 *ppv = spItf.Detach(); | 101 } |
| 116 } | 102 else |
| 117 else | 103 { |
| 118 { | 104 ATLASSERT(_T("Interface not supported by target unknown")); |
| 119 ATLASSERT(_T("Interface not supported by target unknown")); | 105 } |
| 120 } | 106 return hr; |
| 121 return hr; | 107 } |
| 122 } | 108 |
| 123 | 109 inline HRESULT WINAPI QueryInterfaceDebug(void* pv, REFIID riid, |
| 124 inline HRESULT WINAPI QueryInterfaceDebug(void* pv, REFIID riid, | 110 LPVOID* ppv, DWORD_PTR dw, IUnknown* punkTarget) |
| 125 LPVOID* ppv, DWORD_PTR dw, IUnknown* punkTarget) | 111 { |
| 126 { | 112 ATLASSERT(pv != 0); |
| 127 ATLASSERT(pv != 0); | 113 ATLASSERT(ppv != 0); |
| 128 ATLASSERT(ppv != 0); | 114 ATLASSERT(punkTarget != 0); |
| 129 ATLASSERT(punkTarget != 0); | 115 |
| 130 | 116 CComPtr<IUnknown> spUnk; |
| 131 CComPtr<IUnknown> spUnk; | 117 HRESULT hr = punkTarget->QueryInterface(riid, |
| 132 HRESULT hr = punkTarget->QueryInterface(riid, | 118 reinterpret_cast<void**>(&spUnk)); |
| 133 reinterpret_cast<void**>(&spUnk)); | 119 ATLASSERT(FAILED(hr) || spUnk != 0); |
| 134 ATLASSERT(FAILED(hr) || spUnk != 0); | 120 if (SUCCEEDED(hr)) |
| 135 if (SUCCEEDED(hr)) | 121 { |
| 136 { | 122 ATLTRACE(_T("Unrecognized interface supported by target unknown"
)); |
| 137 //Added by MH to display interface CLSID in debug | 123 ATLASSERT(false); |
| 138 OLECHAR wszBuff[39]; | 124 } |
| 139 int i = StringFromGUID2(riid, wszBuff, 39); | 125 |
| 140 USES_CONVERSION; | 126 // We don't support this interface, so return an error. |
| 141 ATLTRACE(_T("=====>Unrecognized interface supported by target unknown=%s
\n"), OLE2T(wszBuff)); | 127 // The operations above are for debugging purposes only, |
| 142 } | 128 // this function is not supposed to ever return success |
| 143 | 129 return E_NOINTERFACE; |
| 144 // We don't support this interface, so return an error. | 130 } |
| 145 // The operations above are for debugging purposes only, | 131 |
| 146 // this function is not supposed to ever return success | 132 inline HRESULT QueryServicePassthrough(REFGUID guidService, |
| 147 return E_NOINTERFACE; | 133 IUnknown* punkThis, REFIID riid, void** ppv, |
| 148 } | 134 IServiceProvider* pClientProvider) |
| 149 | 135 { |
| 150 inline HRESULT QueryServicePassthrough(REFGUID guidService, | 136 ATLASSERT(punkThis != 0); |
| 151 IUnknown* punkThis, REFIID riid, void** ppv, | 137 CComPtr<IUnknown> spDummy; |
| 152 IServiceProvider* pClientProvider) | 138 HRESULT hr = pClientProvider ? |
| 153 { | 139 pClientProvider->QueryService(guidService, riid, |
| 154 ATLASSERT(punkThis != 0); | 140 reinterpret_cast<void**>(&spDummy)) : |
| 155 CComPtr<IUnknown> spDummy; | 141 E_NOINTERFACE; |
| 156 HRESULT hr = pClientProvider ? | 142 if (SUCCEEDED(hr)) |
| 157 pClientProvider->QueryService(guidService, riid, | 143 { |
| 158 reinterpret_cast<void**>(&spDummy)) : | 144 hr = punkThis->QueryInterface(riid, ppv); |
| 159 E_NOINTERFACE; | 145 } |
| 160 if (SUCCEEDED(hr)) | 146 return hr; |
| 161 { | 147 } |
| 162 hr = punkThis->QueryInterface(riid, ppv); | 148 |
| 163 } | 149 } // end namespace PassthroughAPP::Detail |
| 164 return hr; | 150 |
| 165 } | 151 // ===== IInternetProtocolImpl ===== |
| 166 | 152 |
| 167 } // end namespace PassthroughAPP::Detail | 153 inline STDMETHODIMP IInternetProtocolImpl::SetTargetUnknown( |
| 168 | 154 IUnknown* punkTarget) |
| 169 // ===== IInternetProtocolImpl ===== | 155 { |
| 170 | 156 ATLASSERT(punkTarget != 0); |
| 171 inline STDMETHODIMP IInternetProtocolImpl::SetTargetUnknown( | 157 if (!punkTarget) |
| 172 IUnknown* punkTarget) | 158 { |
| 173 { | 159 return E_POINTER; |
| 174 ATLASSERT(punkTarget != 0); | 160 } |
| 175 if (!punkTarget) | 161 |
| 176 { | 162 // This method should only be called once, and be the only source |
| 177 return E_POINTER; | 163 // of target interface pointers. |
| 178 } | 164 ATLASSERT(m_spInternetProtocolUnk == 0); |
| 179 | 165 ATLASSERT(m_spInternetProtocol == 0); |
| 180 // This method should only be called once, and be the only source | 166 if (m_spInternetProtocolUnk || m_spInternetProtocol) |
| 181 // of target interface pointers. | 167 { |
| 182 ATLASSERT(m_spInternetProtocolUnk == 0); | 168 return E_UNEXPECTED; |
| 183 ATLASSERT(m_spInternetProtocol == 0); | 169 } |
| 184 if (m_spInternetProtocolUnk || m_spInternetProtocol) | 170 |
| 185 { | 171 // We expect the target unknown to implement at least IInternetProtocol |
| 186 return E_UNEXPECTED; | 172 // Otherwise we reject it |
| 187 } | 173 HRESULT hr = punkTarget->QueryInterface(&m_spInternetProtocol); |
| 188 | 174 ATLASSERT(FAILED(hr) || m_spInternetProtocol != 0); |
| 189 // We expect the target unknown to implement at least IInternetProtocol | 175 if (FAILED(hr)) |
| 190 // Otherwise we reject it | 176 { |
| 191 HRESULT hr = punkTarget->QueryInterface(&m_spInternetProtocol); | 177 return hr; |
| 192 ATLASSERT(FAILED(hr) || m_spInternetProtocol != 0); | 178 } |
| 193 if (FAILED(hr)) | 179 |
| 194 { | 180 hr = m_spInternetProtocol->QueryInterface(&m_spInternetProtocolEx); |
| 195 return hr; | 181 ATLASSERT(FAILED(hr) || m_spInternetProtocolEx != 0); |
| 196 } | 182 if (FAILED(hr)) |
| 197 | 183 { |
| 198 ATLASSERT(m_spInternetProtocolInfo == 0); | 184 return hr; |
| 199 ATLASSERT(m_spInternetPriority == 0); | 185 } |
| 200 ATLASSERT(m_spInternetThreadSwitch == 0); | 186 |
| 201 ATLASSERT(m_spWinInetInfo == 0); | 187 ATLASSERT(m_spInternetProtocolInfo == 0); |
| 202 ATLASSERT(m_spWinInetHttpInfo == 0); | 188 ATLASSERT(m_spInternetPriority == 0); |
| 203 | 189 ATLASSERT(m_spInternetThreadSwitch == 0); |
| 204 m_spInternetProtocolUnk = punkTarget; | 190 ATLASSERT(m_spWinInetInfo == 0); |
| 205 return S_OK; | 191 ATLASSERT(m_spWinInetHttpInfo == 0); |
| 206 } | 192 |
| 207 | 193 m_spInternetProtocolUnk = punkTarget; |
| 208 inline void IInternetProtocolImpl::ReleaseAll() | 194 return S_OK; |
| 209 { | 195 } |
| 210 m_spInternetProtocolUnk.Release(); | 196 |
| 211 m_spInternetProtocol.Release(); | 197 inline void IInternetProtocolImpl::ReleaseAll() |
| 212 m_spInternetProtocolInfo.Release(); | 198 { |
| 213 m_spInternetPriority.Release(); | 199 m_spInternetProtocolUnk.Release(); |
| 214 m_spInternetThreadSwitch.Release(); | 200 m_spInternetProtocol.Release(); |
| 215 m_spWinInetInfo.Release(); | 201 m_spInternetProtocolEx.Release(); |
| 216 m_spWinInetHttpInfo.Release(); | 202 m_spInternetProtocolInfo.Release(); |
| 217 } | 203 m_spInternetPriority.Release(); |
| 218 | 204 m_spInternetThreadSwitch.Release(); |
| 219 // IInternetProtocolRoot | 205 m_spWinInetInfo.Release(); |
| 220 inline STDMETHODIMP IInternetProtocolImpl::Start( | 206 m_spWinInetHttpInfo.Release(); |
| 221 /* [in] */ LPCWSTR szUrl, | 207 m_spWinInetCacheHints.Release(); |
| 222 /* [in] */ IInternetProtocolSink *pOIProtSink, | 208 m_spWinInetCacheHints2.Release(); |
| 223 /* [in] */ IInternetBindInfo *pOIBindInfo, | 209 } |
| 224 /* [in] */ DWORD grfPI, | 210 |
| 225 /* [in] */ HANDLE_PTR dwReserved) | 211 // IInternetProtocolRoot |
| 226 { | 212 inline STDMETHODIMP IInternetProtocolImpl::Start( |
| 227 ATLASSERT(m_spInternetProtocol != 0); | 213 /* [in] */ LPCWSTR szUrl, |
| 228 return m_spInternetProtocol ? | 214 /* [in] */ IInternetProtocolSink *pOIProtSink, |
| 229 m_spInternetProtocol->Start(szUrl, pOIProtSink, pOIBindInfo, grfPI, | 215 /* [in] */ IInternetBindInfo *pOIBindInfo, |
| 230 dwReserved) : | 216 /* [in] */ DWORD grfPI, |
| 231 E_UNEXPECTED; | 217 /* [in] */ HANDLE_PTR dwReserved) |
| 232 } | 218 { |
| 233 | 219 ATLASSERT(m_spInternetProtocol != 0); |
| 234 inline STDMETHODIMP IInternetProtocolImpl::Continue( | 220 return m_spInternetProtocol ? |
| 235 /* [in] */ PROTOCOLDATA *pProtocolData) | 221 m_spInternetProtocol->Start(szUrl, pOIProtSink, pOIBindInfo, grf
PI, |
| 236 { | 222 dwReserved) : |
| 237 ATLASSERT(m_spInternetProtocol != 0); | 223 E_UNEXPECTED; |
| 238 return m_spInternetProtocol ? | 224 } |
| 239 m_spInternetProtocol->Continue(pProtocolData) : | 225 |
| 240 E_UNEXPECTED; | 226 inline STDMETHODIMP IInternetProtocolImpl::Continue( |
| 241 } | 227 /* [in] */ PROTOCOLDATA *pProtocolData) |
| 242 | 228 { |
| 243 inline STDMETHODIMP IInternetProtocolImpl::Abort( | 229 ATLASSERT(m_spInternetProtocol != 0); |
| 244 /* [in] */ HRESULT hrReason, | 230 return m_spInternetProtocol ? |
| 245 /* [in] */ DWORD dwOptions) | 231 m_spInternetProtocol->Continue(pProtocolData) : |
| 246 { | 232 E_UNEXPECTED; |
| 247 ATLASSERT(m_spInternetProtocol != 0); | 233 } |
| 248 return m_spInternetProtocol ? | 234 |
| 249 m_spInternetProtocol->Abort(hrReason, dwOptions) : | 235 inline STDMETHODIMP IInternetProtocolImpl::Abort( |
| 250 E_UNEXPECTED; | 236 /* [in] */ HRESULT hrReason, |
| 251 } | 237 /* [in] */ DWORD dwOptions) |
| 252 | 238 { |
| 253 inline STDMETHODIMP IInternetProtocolImpl::Terminate( | 239 ATLASSERT(m_spInternetProtocol != 0); |
| 254 /* [in] */ DWORD dwOptions) | 240 return m_spInternetProtocol ? |
| 255 { | 241 m_spInternetProtocol->Abort(hrReason, dwOptions) : |
| 256 ATLASSERT(m_spInternetProtocol != 0); | 242 E_UNEXPECTED; |
| 257 return m_spInternetProtocol ? | 243 } |
| 258 m_spInternetProtocol->Terminate(dwOptions) : | 244 |
| 259 E_UNEXPECTED; | 245 inline STDMETHODIMP IInternetProtocolImpl::Terminate( |
| 260 } | 246 /* [in] */ DWORD dwOptions) |
| 261 | 247 { |
| 262 inline STDMETHODIMP IInternetProtocolImpl::Suspend() | 248 ATLASSERT(m_spInternetProtocol != 0); |
| 263 { | 249 return m_spInternetProtocol ? |
| 264 ATLASSERT(m_spInternetProtocol != 0); | 250 m_spInternetProtocol->Terminate(dwOptions) : |
| 265 return m_spInternetProtocol ? | 251 E_UNEXPECTED; |
| 266 m_spInternetProtocol->Suspend() : | 252 } |
| 267 E_UNEXPECTED; | 253 |
| 268 } | 254 inline STDMETHODIMP IInternetProtocolImpl::Suspend() |
| 269 | 255 { |
| 270 inline STDMETHODIMP IInternetProtocolImpl::Resume() | 256 ATLASSERT(m_spInternetProtocol != 0); |
| 271 { | 257 return m_spInternetProtocol ? |
| 272 ATLASSERT(m_spInternetProtocol != 0); | 258 m_spInternetProtocol->Suspend() : |
| 273 return m_spInternetProtocol ? | 259 E_UNEXPECTED; |
| 274 m_spInternetProtocol->Resume() : | 260 } |
| 275 E_UNEXPECTED; | 261 |
| 276 } | 262 inline STDMETHODIMP IInternetProtocolImpl::Resume() |
| 277 | 263 { |
| 278 // IInternetProtocol | 264 ATLASSERT(m_spInternetProtocol != 0); |
| 279 inline STDMETHODIMP IInternetProtocolImpl::Read( | 265 return m_spInternetProtocol ? |
| 280 /* [in, out] */ void *pv, | 266 m_spInternetProtocol->Resume() : |
| 281 /* [in] */ ULONG cb, | 267 E_UNEXPECTED; |
| 282 /* [out] */ ULONG *pcbRead) | 268 } |
| 283 { | 269 |
| 284 ATLASSERT(m_spInternetProtocol != 0); | 270 // IInternetProtocol |
| 285 return m_spInternetProtocol ? | 271 inline STDMETHODIMP IInternetProtocolImpl::Read( |
| 286 m_spInternetProtocol->Read(pv, cb, pcbRead) : | 272 /* [in, out] */ void *pv, |
| 287 E_UNEXPECTED; | 273 /* [in] */ ULONG cb, |
| 288 } | 274 /* [out] */ ULONG *pcbRead) |
| 289 | 275 { |
| 290 inline STDMETHODIMP IInternetProtocolImpl::Seek( | 276 ATLASSERT(m_spInternetProtocol != 0); |
| 291 /* [in] */ LARGE_INTEGER dlibMove, | 277 return m_spInternetProtocol ? |
| 292 /* [in] */ DWORD dwOrigin, | 278 m_spInternetProtocol->Read(pv, cb, pcbRead) : |
| 293 /* [out] */ ULARGE_INTEGER *plibNewPosition) | 279 E_UNEXPECTED; |
| 294 { | 280 } |
| 295 ATLASSERT(m_spInternetProtocol != 0); | 281 |
| 296 return m_spInternetProtocol ? | 282 inline STDMETHODIMP IInternetProtocolImpl::Seek( |
| 297 m_spInternetProtocol->Seek(dlibMove, dwOrigin, plibNewPosition) : | 283 /* [in] */ LARGE_INTEGER dlibMove, |
| 298 E_UNEXPECTED; | 284 /* [in] */ DWORD dwOrigin, |
| 299 } | 285 /* [out] */ ULARGE_INTEGER *plibNewPosition) |
| 300 | 286 { |
| 301 inline STDMETHODIMP IInternetProtocolImpl::LockRequest( | 287 ATLASSERT(m_spInternetProtocol != 0); |
| 302 /* [in] */ DWORD dwOptions) | 288 return m_spInternetProtocol ? |
| 303 { | 289 m_spInternetProtocol->Seek(dlibMove, dwOrigin, plibNewPosition)
: |
| 304 ATLASSERT(m_spInternetProtocol != 0); | 290 E_UNEXPECTED; |
| 305 return m_spInternetProtocol ? | 291 } |
| 306 m_spInternetProtocol->LockRequest(dwOptions) : | 292 |
| 307 E_UNEXPECTED; | 293 inline STDMETHODIMP IInternetProtocolImpl::LockRequest( |
| 308 } | 294 /* [in] */ DWORD dwOptions) |
| 309 | 295 { |
| 310 inline STDMETHODIMP IInternetProtocolImpl::UnlockRequest() | 296 ATLASSERT(m_spInternetProtocol != 0); |
| 311 { | 297 return m_spInternetProtocol ? |
| 312 ATLASSERT(m_spInternetProtocol != 0); | 298 m_spInternetProtocol->LockRequest(dwOptions) : |
| 313 return m_spInternetProtocol ? | 299 E_UNEXPECTED; |
| 314 m_spInternetProtocol->UnlockRequest() : | 300 } |
| 315 E_UNEXPECTED; | 301 |
| 316 } | 302 inline STDMETHODIMP IInternetProtocolImpl::UnlockRequest() |
| 317 | 303 { |
| 318 // IInternetProtocolInfo | 304 ATLASSERT(m_spInternetProtocol != 0); |
| 319 inline STDMETHODIMP IInternetProtocolImpl::ParseUrl( | 305 return m_spInternetProtocol ? |
| 320 /* [in] */ LPCWSTR pwzUrl, | 306 m_spInternetProtocol->UnlockRequest() : |
| 321 /* [in] */ PARSEACTION ParseAction, | 307 E_UNEXPECTED; |
| 322 /* [in] */ DWORD dwParseFlags, | 308 } |
| 323 /* [out] */ LPWSTR pwzResult, | 309 |
| 324 /* [in] */ DWORD cchResult, | 310 // IInternetProtocolEx |
| 325 /* [out] */ DWORD *pcchResult, | 311 |
| 326 /* [in] */ DWORD dwReserved) | 312 inline STDMETHODIMP IInternetProtocolImpl::StartEx( |
| 327 { | 313 IUri *pUri, |
| 328 ATLASSERT(m_spInternetProtocolInfo != 0); | 314 IInternetProtocolSink *pOIProtSink, |
| 329 return m_spInternetProtocolInfo ? | 315 IInternetBindInfo *pOIBindInfo, |
| 330 m_spInternetProtocolInfo->ParseUrl(pwzUrl, ParseAction, dwParseFlags, | 316 DWORD grfPI, |
| 331 pwzResult, cchResult, pcchResult, dwReserved) : | 317 HANDLE_PTR dwReserved) |
| 332 E_UNEXPECTED; | 318 { |
| 333 } | 319 ATLASSERT(m_spInternetProtocolEx != 0); |
| 334 | 320 return m_spInternetProtocolEx ? |
| 335 inline STDMETHODIMP IInternetProtocolImpl::CombineUrl( | 321 m_spInternetProtocolEx->StartEx(pUri, pOIProtSink, pOIBindInfo,
grfPI, dwReserved) : |
| 336 /* [in] */ LPCWSTR pwzBaseUrl, | 322 E_UNEXPECTED; |
| 337 /* [in] */ LPCWSTR pwzRelativeUrl, | 323 } |
| 338 /* [in] */ DWORD dwCombineFlags, | 324 |
| 339 /* [out] */ LPWSTR pwzResult, | 325 // IInternetProtocolInfo |
| 340 /* [in] */ DWORD cchResult, | 326 inline STDMETHODIMP IInternetProtocolImpl::ParseUrl( |
| 341 /* [out] */ DWORD *pcchResult, | 327 /* [in] */ LPCWSTR pwzUrl, |
| 342 /* [in] */ DWORD dwReserved) | 328 /* [in] */ PARSEACTION ParseAction, |
| 343 { | 329 /* [in] */ DWORD dwParseFlags, |
| 344 ATLASSERT(m_spInternetProtocolInfo != 0); | 330 /* [out] */ LPWSTR pwzResult, |
| 345 return m_spInternetProtocolInfo ? | 331 /* [in] */ DWORD cchResult, |
| 346 m_spInternetProtocolInfo->CombineUrl(pwzBaseUrl, pwzRelativeUrl, | 332 /* [out] */ DWORD *pcchResult, |
| 347 dwCombineFlags, pwzResult, cchResult, pcchResult, dwReserved) : | 333 /* [in] */ DWORD dwReserved) |
| 348 E_UNEXPECTED; | 334 { |
| 349 } | 335 ATLASSERT(m_spInternetProtocolInfo != 0); |
| 350 | 336 return m_spInternetProtocolInfo ? |
| 351 inline STDMETHODIMP IInternetProtocolImpl::CompareUrl( | 337 m_spInternetProtocolInfo->ParseUrl(pwzUrl, ParseAction, dwParseF
lags, |
| 352 /* [in] */ LPCWSTR pwzUrl1, | 338 pwzResult, cchResult, pcchResult, dwReserved) : |
| 353 /* [in] */ LPCWSTR pwzUrl2, | 339 E_UNEXPECTED; |
| 354 /* [in] */ DWORD dwCompareFlags) | 340 } |
| 355 { | 341 |
| 356 ATLASSERT(m_spInternetProtocolInfo != 0); | 342 inline STDMETHODIMP IInternetProtocolImpl::CombineUrl( |
| 357 return m_spInternetProtocolInfo ? | 343 /* [in] */ LPCWSTR pwzBaseUrl, |
| 358 m_spInternetProtocolInfo->CompareUrl(pwzUrl1,pwzUrl2, dwCompareFlags) : | 344 /* [in] */ LPCWSTR pwzRelativeUrl, |
| 359 E_UNEXPECTED; | 345 /* [in] */ DWORD dwCombineFlags, |
| 360 } | 346 /* [out] */ LPWSTR pwzResult, |
| 361 | 347 /* [in] */ DWORD cchResult, |
| 362 inline STDMETHODIMP IInternetProtocolImpl::QueryInfo( | 348 /* [out] */ DWORD *pcchResult, |
| 363 /* [in] */ LPCWSTR pwzUrl, | 349 /* [in] */ DWORD dwReserved) |
| 364 /* [in] */ QUERYOPTION QueryOption, | 350 { |
| 365 /* [in] */ DWORD dwQueryFlags, | 351 ATLASSERT(m_spInternetProtocolInfo != 0); |
| 366 /* [in, out] */ LPVOID pBuffer, | 352 return m_spInternetProtocolInfo ? |
| 367 /* [in] */ DWORD cbBuffer, | 353 m_spInternetProtocolInfo->CombineUrl(pwzBaseUrl, pwzRelativeUrl, |
| 368 /* [in, out] */ DWORD *pcbBuf, | 354 dwCombineFlags, pwzResult, cchResult, pcchResult, dwRese
rved) : |
| 369 /* [in] */ DWORD dwReserved) | 355 E_UNEXPECTED; |
| 370 { | 356 } |
| 371 ATLASSERT(m_spInternetProtocolInfo != 0); | 357 |
| 372 return m_spInternetProtocolInfo ? | 358 inline STDMETHODIMP IInternetProtocolImpl::CompareUrl( |
| 373 m_spInternetProtocolInfo->QueryInfo(pwzUrl, QueryOption, dwQueryFlags, | 359 /* [in] */ LPCWSTR pwzUrl1, |
| 374 pBuffer, cbBuffer, pcbBuf, dwReserved) : | 360 /* [in] */ LPCWSTR pwzUrl2, |
| 375 E_UNEXPECTED; | 361 /* [in] */ DWORD dwCompareFlags) |
| 376 } | 362 { |
| 377 | 363 ATLASSERT(m_spInternetProtocolInfo != 0); |
| 378 // IInternetPriority | 364 return m_spInternetProtocolInfo ? |
| 379 inline STDMETHODIMP IInternetProtocolImpl::SetPriority( | 365 m_spInternetProtocolInfo->CompareUrl(pwzUrl1,pwzUrl2, dwCompareF
lags) : |
| 380 /* [in] */ LONG nPriority) | 366 E_UNEXPECTED; |
| 381 { | 367 } |
| 382 ATLASSERT(m_spInternetPriority != 0); | 368 |
| 383 return m_spInternetPriority ? | 369 inline STDMETHODIMP IInternetProtocolImpl::QueryInfo( |
| 384 m_spInternetPriority->SetPriority(nPriority) : | 370 /* [in] */ LPCWSTR pwzUrl, |
| 385 E_UNEXPECTED; | 371 /* [in] */ QUERYOPTION QueryOption, |
| 386 } | 372 /* [in] */ DWORD dwQueryFlags, |
| 387 | 373 /* [in, out] */ LPVOID pBuffer, |
| 388 inline STDMETHODIMP IInternetProtocolImpl::GetPriority( | 374 /* [in] */ DWORD cbBuffer, |
| 389 /* [out] */ LONG *pnPriority) | 375 /* [in, out] */ DWORD *pcbBuf, |
| 390 { | 376 /* [in] */ DWORD dwReserved) |
| 391 ATLASSERT(m_spInternetPriority != 0); | 377 { |
| 392 return m_spInternetPriority ? | 378 ATLASSERT(m_spInternetProtocolInfo != 0); |
| 393 m_spInternetPriority->GetPriority(pnPriority) : | 379 return m_spInternetProtocolInfo ? |
| 394 E_UNEXPECTED; | 380 m_spInternetProtocolInfo->QueryInfo(pwzUrl, QueryOption, dwQuery
Flags, |
| 395 } | 381 pBuffer, cbBuffer, pcbBuf, dwReserved) : |
| 396 | 382 E_UNEXPECTED; |
| 397 // IInternetThreadSwitch | 383 } |
| 398 inline STDMETHODIMP IInternetProtocolImpl::Prepare() | 384 |
| 399 { | 385 // IInternetPriority |
| 400 ATLASSERT(m_spInternetThreadSwitch != 0); | 386 inline STDMETHODIMP IInternetProtocolImpl::SetPriority( |
| 401 return m_spInternetThreadSwitch ? | 387 /* [in] */ LONG nPriority) |
| 402 m_spInternetThreadSwitch->Prepare() : | 388 { |
| 403 E_UNEXPECTED; | 389 ATLASSERT(m_spInternetPriority != 0); |
| 404 } | 390 return m_spInternetPriority ? |
| 405 | 391 m_spInternetPriority->SetPriority(nPriority) : |
| 406 inline STDMETHODIMP IInternetProtocolImpl::Continue() | 392 E_UNEXPECTED; |
| 407 { | 393 } |
| 408 ATLASSERT(m_spInternetThreadSwitch != 0); | 394 |
| 409 return m_spInternetThreadSwitch ? | 395 inline STDMETHODIMP IInternetProtocolImpl::GetPriority( |
| 410 m_spInternetThreadSwitch->Continue() : | 396 /* [out] */ LONG *pnPriority) |
| 411 E_UNEXPECTED; | 397 { |
| 412 } | 398 ATLASSERT(m_spInternetPriority != 0); |
| 413 | 399 return m_spInternetPriority ? |
| 414 // IWinInetInfo | 400 m_spInternetPriority->GetPriority(pnPriority) : |
| 415 inline STDMETHODIMP IInternetProtocolImpl::QueryOption( | 401 E_UNEXPECTED; |
| 416 /* [in] */ DWORD dwOption, | 402 } |
| 417 /* [in, out] */ LPVOID pBuffer, | 403 |
| 418 /* [in, out] */ DWORD *pcbBuf) | 404 // IInternetThreadSwitch |
| 419 { | 405 inline STDMETHODIMP IInternetProtocolImpl::Prepare() |
| 420 ATLASSERT(m_spWinInetInfo != 0); | 406 { |
| 421 return m_spWinInetInfo ? | 407 ATLASSERT(m_spInternetThreadSwitch != 0); |
| 422 m_spWinInetInfo->QueryOption(dwOption, pBuffer, pcbBuf) : | 408 return m_spInternetThreadSwitch ? |
| 423 E_UNEXPECTED; | 409 m_spInternetThreadSwitch->Prepare() : |
| 424 } | 410 E_UNEXPECTED; |
| 425 | 411 } |
| 426 // IWinInetHttpInfo | 412 |
| 427 inline STDMETHODIMP IInternetProtocolImpl::QueryInfo( | 413 inline STDMETHODIMP IInternetProtocolImpl::Continue() |
| 428 /* [in] */ DWORD dwOption, | 414 { |
| 429 /* [in, out] */ LPVOID pBuffer, | 415 ATLASSERT(m_spInternetThreadSwitch != 0); |
| 430 /* [in, out] */ DWORD *pcbBuf, | 416 return m_spInternetThreadSwitch ? |
| 431 /* [in, out] */ DWORD *pdwFlags, | 417 m_spInternetThreadSwitch->Continue() : |
| 432 /* [in, out] */ DWORD *pdwReserved) | 418 E_UNEXPECTED; |
| 433 { | 419 } |
| 434 ATLASSERT(m_spWinInetHttpInfo != 0); | 420 |
| 435 return m_spWinInetHttpInfo ? | 421 // IWinInetInfo |
| 436 m_spWinInetHttpInfo->QueryInfo(dwOption, pBuffer, pcbBuf, pdwFlags, | 422 inline STDMETHODIMP IInternetProtocolImpl::QueryOption( |
| 437 pdwReserved) : | 423 /* [in] */ DWORD dwOption, |
| 438 E_UNEXPECTED; | 424 /* [in, out] */ LPVOID pBuffer, |
| 439 } | 425 /* [in, out] */ DWORD *pcbBuf) |
| 440 | 426 { |
| 441 // ===== IInternetProtocolSinkImpl ===== | 427 ATLASSERT(m_spWinInetInfo != 0); |
| 442 | 428 return m_spWinInetInfo ? |
| 443 inline HRESULT IInternetProtocolSinkImpl::OnStart(LPCWSTR szUrl, | 429 m_spWinInetInfo->QueryOption(dwOption, pBuffer, pcbBuf) : |
| 444 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo, | 430 E_UNEXPECTED; |
| 445 DWORD grfPI, HANDLE_PTR dwReserved, IInternetProtocol* pTargetProtocol) | 431 } |
| 446 { | 432 |
| 447 ATLASSERT(pOIProtSink != 0); | 433 // IWinInetHttpInfo |
| 448 ATLASSERT(pOIBindInfo != 0); | 434 inline STDMETHODIMP IInternetProtocolImpl::QueryInfo( |
| 449 ATLASSERT(pTargetProtocol != 0); | 435 /* [in] */ DWORD dwOption, |
| 450 if (!pOIProtSink || !pOIBindInfo || !pTargetProtocol) | 436 /* [in, out] */ LPVOID pBuffer, |
| 451 { | 437 /* [in, out] */ DWORD *pcbBuf, |
| 452 return E_POINTER; | 438 /* [in, out] */ DWORD *pdwFlags, |
| 453 } | 439 /* [in, out] */ DWORD *pdwReserved) |
| 454 | 440 { |
| 455 // This method should only be called once, and be the only source | 441 ATLASSERT(m_spWinInetHttpInfo != 0); |
| 456 // of target interface pointers. | 442 return m_spWinInetHttpInfo ? |
| 457 ATLASSERT(m_spInternetProtocolSink == 0); | 443 m_spWinInetHttpInfo->QueryInfo(dwOption, pBuffer, pcbBuf, pdwFla
gs, |
| 458 ATLASSERT(m_spTargetProtocol == 0); | 444 pdwReserved) : |
| 459 if (m_spInternetProtocolSink || m_spTargetProtocol) | 445 E_UNEXPECTED; |
| 460 { | 446 } |
| 461 return E_UNEXPECTED; | 447 |
| 462 } | 448 // IWinInetCacheHints |
| 463 | 449 |
| 464 ATLASSERT(m_spServiceProvider == 0); | 450 inline STDMETHODIMP IInternetProtocolImpl::SetCacheExtension( |
| 465 | 451 /* [in] */ LPCWSTR pwzExt, |
| 466 m_spInternetProtocolSink = pOIProtSink; | 452 /* [in, out] */ LPVOID pszCacheFile, |
| 467 m_spTargetProtocol = pTargetProtocol; | 453 /* [in, out] */ DWORD *pcbCacheFile, |
| 468 return S_OK; | 454 /* [in, out] */ DWORD *pdwWinInetError, |
| 469 } | 455 /* [in, out] */ DWORD *pdwReserved) |
| 470 | 456 { |
| 471 inline void IInternetProtocolSinkImpl::ReleaseAll() | 457 ATLASSERT(m_spWinInetCacheHints2 != NULL); |
| 472 { | 458 return m_spWinInetCacheHints2 ? |
| 473 m_spInternetProtocolSink.Release(); | 459 m_spWinInetCacheHints2->SetCacheExtension(pwzExt, pszCacheFile,
pcbCacheFile, |
| 474 m_spServiceProvider.Release(); | 460 pdwWinInetError, pdwReserved) : E_UNEXPECTED; |
| 475 m_spTargetProtocol.Release(); | 461 } |
| 476 } | 462 |
| 477 | 463 inline STDMETHODIMP IInternetProtocolImpl::SetCacheExtension2( |
| 478 inline IServiceProvider* IInternetProtocolSinkImpl::GetClientServiceProvider() | 464 /* [in] */ LPCWSTR pwzExt, |
| 479 { | 465 /* [out] */ WCHAR *pwzCacheFile, |
| 480 return m_spServiceProvider; | 466 /* [in, out] */ DWORD *pcchCacheFile, |
| 481 } | 467 /* [out] */ DWORD *pdwWinInetError, |
| 482 | 468 /* [out] */ DWORD *pdwReserved) |
| 483 inline HRESULT IInternetProtocolSinkImpl::QueryServiceFromClient( | 469 { |
| 484 REFGUID guidService, REFIID riid, void** ppvObject) | 470 ATLASSERT(m_spWinInetCacheHints2 != NULL); |
| 485 { | 471 return m_spWinInetCacheHints2 ? |
| 486 HRESULT hr = S_OK; | 472 m_spWinInetCacheHints2->SetCacheExtension2(pwzExt, pwzCacheFile
, pcchCacheFile, |
| 487 CComPtr<IServiceProvider> spClientProvider = m_spServiceProvider; | 473 pdwWinInetError, pdwReserved) : E_UNEXPECTED; |
| 488 if (!spClientProvider) | 474 } |
| 489 { | 475 |
| 490 hr = m_spInternetProtocolSink->QueryInterface(&spClientProvider); | 476 // ===== IInternetProtocolSinkImpl ===== |
| 491 ATLASSERT(SUCCEEDED(hr) && spClientProvider != 0); | 477 |
| 492 } | 478 inline HRESULT IInternetProtocolSinkImpl::InitMembers(IInternetProtocolSink *pOI
ProtSink, IInternetBindInfo *pOIBindInfo, |
| 493 if (SUCCEEDED(hr)) | 479 IInternetProtocol* pTargetProtocol) |
| 494 { | 480 { |
| 495 hr = spClientProvider->QueryService(guidService, riid, ppvObject); | 481 ATLASSERT(pOIProtSink != 0); |
| 496 } | 482 ATLASSERT(pOIBindInfo != 0); |
| 497 return hr; | 483 ATLASSERT(pTargetProtocol != 0); |
| 498 } | 484 if (!pOIProtSink || !pOIBindInfo || !pTargetProtocol) |
| 499 | 485 { |
| 500 // IInternetProtocolSink | 486 return E_POINTER; |
| 501 inline STDMETHODIMP IInternetProtocolSinkImpl::Switch( | 487 } |
| 502 /* [in] */ PROTOCOLDATA *pProtocolData) | 488 |
| 503 { | 489 // This method should only be called once, and be the only source |
| 504 ATLASSERT(m_spInternetProtocolSink != 0); | 490 // of target interface pointers. |
| 505 return m_spInternetProtocolSink ? | 491 ATLASSERT(m_spInternetProtocolSink == 0); |
| 506 m_spInternetProtocolSink->Switch(pProtocolData) : | 492 ATLASSERT(m_spInternetBindInfo == 0); |
| 507 E_UNEXPECTED; | 493 ATLASSERT(m_spTargetProtocol == 0); |
| 508 } | 494 if (m_spInternetProtocolSink || m_spInternetBindInfo || m_spTargetProtoc
ol) |
| 509 | 495 { |
| 510 inline STDMETHODIMP IInternetProtocolSinkImpl::ReportProgress( | 496 return E_UNEXPECTED; |
| 511 /* [in] */ ULONG ulStatusCode, | 497 } |
| 512 /* [in] */ LPCWSTR szStatusText) | 498 |
| 513 { | 499 ATLASSERT(m_spServiceProvider == 0); |
| 514 ATLASSERT(m_spInternetProtocolSink != 0); | 500 |
| 515 return m_spInternetProtocolSink ? | 501 m_spInternetProtocolSink = pOIProtSink; |
| 516 m_spInternetProtocolSink->ReportProgress(ulStatusCode, szStatusText) : | 502 m_spInternetBindInfo = pOIBindInfo; |
| 517 E_UNEXPECTED; | 503 if (FAILED(m_spInternetBindInfo->QueryInterface(&m_spInternetBindInfoEx)
)) |
| 518 } | 504 m_spInternetBindInfoEx = NULL; |
| 519 | 505 m_spTargetProtocol = pTargetProtocol; |
| 520 inline STDMETHODIMP IInternetProtocolSinkImpl::ReportData( | 506 return S_OK; |
| 521 /* [in] */ DWORD grfBSCF, | 507 } |
| 522 /* [in] */ ULONG ulProgress, | 508 |
| 523 /* [in] */ ULONG ulProgressMax) | 509 inline HRESULT IInternetProtocolSinkImpl::OnStart(LPCWSTR szUrl, |
| 524 { | 510 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo, |
| 525 ATLASSERT(m_spInternetProtocolSink != 0); | 511 DWORD grfPI, HANDLE_PTR dwReserved, IInternetProtocol* pTargetProtocol) |
| 526 return m_spInternetProtocolSink ? | 512 { |
| 527 m_spInternetProtocolSink->ReportData(grfBSCF, ulProgress, | 513 return InitMembers(pOIProtSink, pOIBindInfo, pTargetProtocol); |
| 528 ulProgressMax) : | 514 } |
| 529 E_UNEXPECTED; | 515 |
| 530 } | 516 inline HRESULT IInternetProtocolSinkImpl::OnStartEx(IUri* pUri, |
| 531 | 517 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo, |
| 532 inline STDMETHODIMP IInternetProtocolSinkImpl::ReportResult( | 518 DWORD grfPI, HANDLE_PTR dwReserved, IInternetProtocol* pTargetProtocol) |
| 533 /* [in] */ HRESULT hrResult, | 519 { |
| 534 /* [in] */ DWORD dwError, | 520 return InitMembers(pOIProtSink, pOIBindInfo, pTargetProtocol); |
| 535 /* [in] */ LPCWSTR szResult) | 521 } |
| 536 { | 522 |
| 537 ATLASSERT(m_spInternetProtocolSink != 0); | 523 |
| 538 | 524 inline void IInternetProtocolSinkImpl::ReleaseAll() |
| 539 // On some websites there are broken requests, that keep on redirecting with
out a stop. | 525 { |
| 540 // For example: http://telegrafua.com/ has a request to: http://www.ool.ua/w
ebroot/delivery/images/ool-button.gif | 526 m_spInternetProtocolSink.Release(); |
| 541 // which causes IE tab to crash in urlmon.dll. That request doesn't ever res
olve, since it's constantly responding | 527 m_spServiceProvider.Release(); |
| 542 // with HTTP 302. | 528 m_spInternetBindInfo.Release(); |
| 543 | 529 m_spInternetBindInfoEx.Release(); |
| 544 // It seems like WinInet (urlmon.dll) doesn't expect anything like that to h
appen, and relies on APP to make sure it doesn't. | 530 m_spUriContainer.Release(); |
| 545 // So here we detect if there has been too many redirects (ie INET_E_REDIREC
T_FAILED) and we just notify WinInet | 531 m_spTargetProtocol.Release(); |
| 546 // that there has been a generic problem, not redirect specific error. | 532 } |
| 547 | 533 |
| 548 // This seem to only postpone the issue to some different place. Undo for
now | 534 inline IServiceProvider* IInternetProtocolSinkImpl::GetClientServiceProvider() |
| 549 // if (hrResult == INET_E_REDIRECT_FAILED) | 535 { |
| 550 // hrResult = S_FALSE; | 536 return m_spServiceProvider; |
| 551 | 537 } |
| 552 return m_spInternetProtocolSink ? | 538 |
| 553 m_spInternetProtocolSink->ReportResult(hrResult, dwError, szResult) : | 539 inline HRESULT IInternetProtocolSinkImpl::QueryServiceFromClient( |
| 554 E_UNEXPECTED; | 540 REFGUID guidService, REFIID riid, void** ppvObject) |
| 555 } | 541 { |
| 556 | 542 HRESULT hr = S_OK; |
| 557 // IServiceProvider | 543 CComPtr<IServiceProvider> spClientProvider = m_spServiceProvider; |
| 558 inline STDMETHODIMP IInternetProtocolSinkImpl::QueryService( | 544 if (!spClientProvider) |
| 559 /* [in] */ REFGUID guidService, | 545 { |
| 560 /* [in] */ REFIID riid, | 546 hr = m_spInternetProtocolSink->QueryInterface(&spClientProvider)
; |
| 561 /* [out] */ void** ppvObject) | 547 ATLASSERT(SUCCEEDED(hr) && spClientProvider != 0); |
| 562 { | 548 } |
| 563 ATLASSERT(m_spServiceProvider != 0); | 549 if (SUCCEEDED(hr)) |
| 564 return m_spServiceProvider ? | 550 { |
| 565 m_spServiceProvider->QueryService(guidService, riid, ppvObject) : | 551 hr = spClientProvider->QueryService(guidService, riid, ppvObject
); |
| 566 E_UNEXPECTED; | 552 } |
| 567 } | 553 return hr; |
| 568 | 554 } |
| 569 // ===== CInternetProtocolSinkWithSP ===== | 555 |
| 570 | 556 // IInternetProtocolSink |
| 571 template <class T, class ThreadModel> | 557 inline STDMETHODIMP IInternetProtocolSinkImpl::Switch( |
| 572 inline HRESULT CInternetProtocolSinkWithSP<T, ThreadModel>::OnStart( | 558 /* [in] */ PROTOCOLDATA *pProtocolData) |
| 573 LPCWSTR szUrl, IInternetProtocolSink *pOIProtSink, | 559 { |
| 574 IInternetBindInfo *pOIBindInfo, DWORD grfPI, HANDLE_PTR dwReserved, | 560 ATLASSERT(m_spInternetProtocolSink != 0); |
| 575 IInternetProtocol* pTargetProtocol) | 561 return m_spInternetProtocolSink ? |
| 576 { | 562 m_spInternetProtocolSink->Switch(pProtocolData) : |
| 577 ATLASSERT(m_spServiceProvider == 0); | 563 E_UNEXPECTED; |
| 578 if (m_spServiceProvider) | 564 } |
| 579 { | 565 |
| 580 return E_UNEXPECTED; | 566 inline STDMETHODIMP IInternetProtocolSinkImpl::ReportProgress( |
| 581 } | 567 /* [in] */ ULONG ulStatusCode, |
| 582 HRESULT hr = BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, | 568 /* [in] */ LPCWSTR szStatusText) |
| 583 dwReserved, pTargetProtocol); | 569 { |
| 584 if (SUCCEEDED(hr)) | 570 ATLASSERT(m_spInternetProtocolSink != 0); |
| 585 { | 571 return m_spInternetProtocolSink ? |
| 586 pOIProtSink->QueryInterface(&m_spServiceProvider); | 572 m_spInternetProtocolSink->ReportProgress(ulStatusCode, szStatusT
ext) : |
| 587 } | 573 E_UNEXPECTED; |
| 588 return hr; | 574 } |
| 589 } | 575 |
| 590 | 576 inline STDMETHODIMP IInternetProtocolSinkImpl::ReportData( |
| 591 template <class T, class ThreadModel> | 577 /* [in] */ DWORD grfBSCF, |
| 592 inline HRESULT CInternetProtocolSinkWithSP<T, ThreadModel>:: | 578 /* [in] */ ULONG ulProgress, |
| 593 _InternalQueryService(REFGUID guidService, REFIID riid, void** ppvObject) | 579 /* [in] */ ULONG ulProgressMax) |
| 594 { | 580 { |
| 595 return E_NOINTERFACE; | 581 ATLASSERT(m_spInternetProtocolSink != 0); |
| 596 } | 582 return m_spInternetProtocolSink ? |
| 597 | 583 m_spInternetProtocolSink->ReportData(grfBSCF, ulProgress, |
| 598 template <class T, class ThreadModel> | 584 ulProgressMax) : |
| 599 inline STDMETHODIMP CInternetProtocolSinkWithSP<T, ThreadModel>::QueryService( | 585 E_UNEXPECTED; |
| 600 REFGUID guidService, REFIID riid, void** ppv) | 586 } |
| 601 { | 587 |
| 602 T* pT = static_cast<T*>(this); | 588 inline STDMETHODIMP IInternetProtocolSinkImpl::ReportResult( |
| 603 HRESULT hr = pT->_InternalQueryService(guidService, riid, ppv); | 589 /* [in] */ HRESULT hrResult, |
| 604 if (FAILED(hr) && m_spServiceProvider) | 590 /* [in] */ DWORD dwError, |
| 605 { | 591 /* [in] */ LPCWSTR szResult) |
| 606 hr = m_spServiceProvider->QueryService(guidService, riid, ppv); | 592 { |
| 607 } | 593 ATLASSERT(m_spInternetProtocolSink != 0); |
| 608 return hr; | 594 return m_spInternetProtocolSink ? |
| 609 } | 595 m_spInternetProtocolSink->ReportResult(hrResult, dwError, szResu
lt) : |
| 596 E_UNEXPECTED; |
| 597 } |
| 598 |
| 599 // IServiceProvider |
| 600 inline STDMETHODIMP IInternetProtocolSinkImpl::QueryService( |
| 601 /* [in] */ REFGUID guidService, |
| 602 /* [in] */ REFIID riid, |
| 603 /* [out] */ void** ppvObject) |
| 604 { |
| 605 ATLASSERT(m_spServiceProvider != 0); |
| 606 return m_spServiceProvider ? |
| 607 m_spServiceProvider->QueryService(guidService, riid, ppvObject)
: |
| 608 E_UNEXPECTED; |
| 609 } |
| 610 |
| 611 // IInternetBindInfo |
| 612 inline STDMETHODIMP IInternetProtocolSinkImpl::GetBindInfo( |
| 613 /* [out] */ DWORD *grfBINDF, |
| 614 /* [in, out] */ BINDINFO *pbindinfo) |
| 615 { |
| 616 ATLASSERT(m_spInternetBindInfo != 0); |
| 617 return m_spInternetBindInfo ? |
| 618 m_spInternetBindInfo->GetBindInfo(grfBINDF, pbindinfo) : |
| 619 E_UNEXPECTED; |
| 620 } |
| 621 |
| 622 inline STDMETHODIMP IInternetProtocolSinkImpl::GetBindString( |
| 623 /* [in] */ ULONG ulStringType, |
| 624 /* [in, out] */ LPOLESTR *ppwzStr, |
| 625 /* [in] */ ULONG cEl, |
| 626 /* [in, out] */ ULONG *pcElFetched) |
| 627 { |
| 628 ATLASSERT(m_spInternetBindInfo != 0); |
| 629 return m_spInternetBindInfo ? |
| 630 m_spInternetBindInfo->GetBindString(ulStringType, ppwzStr, cEl, |
| 631 pcElFetched) : |
| 632 E_UNEXPECTED; |
| 633 } |
| 634 |
| 635 // IInternetBindInfoEx |
| 636 inline STDMETHODIMP IInternetProtocolSinkImpl::GetBindInfoEx( |
| 637 DWORD *grfBINDF, |
| 638 BINDINFO *pbindinfo, |
| 639 DWORD *grfBINDF2, |
| 640 DWORD *pdwReserved) |
| 641 { |
| 642 ATLASSERT(m_spInternetBindInfoEx != 0); |
| 643 return m_spInternetBindInfoEx ? |
| 644 m_spInternetBindInfoEx->GetBindInfoEx(grfBINDF, pbindinfo, |
| 645 grfBINDF2, pdwReserved) : E_UNEXPECTED; |
| 646 } |
| 647 |
| 648 inline STDMETHODIMP IInternetProtocolSinkImpl::GetIUri( |
| 649 IUri **ppIUri |
| 650 ) |
| 651 { |
| 652 ATLASSERT(m_spUriContainer != 0); |
| 653 return m_spUriContainer ? |
| 654 m_spUriContainer->GetIUri(ppIUri) : E_UNEXPECTED; |
| 655 } |
| 656 |
| 657 // ===== CInternetProtocolSinkWithSP ===== |
| 658 |
| 659 template <class T, class ThreadModel> |
| 660 inline HRESULT CInternetProtocolSinkWithSP<T, ThreadModel>::OnStart( |
| 661 LPCWSTR szUrl, IInternetProtocolSink *pOIProtSink, |
| 662 IInternetBindInfo *pOIBindInfo, DWORD grfPI, HANDLE_PTR dwReserved, |
| 663 IInternetProtocol* pTargetProtocol) |
| 664 { |
| 665 ATLASSERT(m_spServiceProvider == 0); |
| 666 if (m_spServiceProvider) |
| 667 { |
| 668 return E_UNEXPECTED; |
| 669 } |
| 670 HRESULT hr = BaseClass::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, |
| 671 dwReserved, pTargetProtocol); |
| 672 if (SUCCEEDED(hr)) |
| 673 { |
| 674 pOIProtSink->QueryInterface(&m_spServiceProvider); |
| 675 } |
| 676 return hr; |
| 677 } |
| 678 |
| 679 template <class T, class ThreadModel> |
| 680 inline HRESULT CInternetProtocolSinkWithSP<T, ThreadModel>::OnStartEx( |
| 681 IUri* pUri, IInternetProtocolSink *pOIProtSink, |
| 682 IInternetBindInfo *pOIBindInfo, DWORD grfPI, HANDLE_PTR dwReserved, |
| 683 IInternetProtocol* pTargetProtocol) |
| 684 { |
| 685 ATLASSERT(m_spServiceProvider == 0); |
| 686 if (m_spServiceProvider) |
| 687 { |
| 688 return E_UNEXPECTED; |
| 689 } |
| 690 HRESULT hr = BaseClass::OnStartEx(pUri, pOIProtSink, pOIBindInfo, grfPI, |
| 691 dwReserved, pTargetProtocol); |
| 692 if (SUCCEEDED(hr)) |
| 693 { |
| 694 pOIProtSink->QueryInterface(&m_spServiceProvider); |
| 695 } |
| 696 return hr; |
| 697 } |
| 698 |
| 699 template <class T, class ThreadModel> |
| 700 inline HRESULT CInternetProtocolSinkWithSP<T, ThreadModel>:: |
| 701 _InternalQueryService(REFGUID guidService, REFIID riid, void** ppvObject
) |
| 702 { |
| 703 return E_NOINTERFACE; |
| 704 } |
| 705 |
| 706 template <class T, class ThreadModel> |
| 707 inline STDMETHODIMP CInternetProtocolSinkWithSP<T, ThreadModel>::QueryService( |
| 708 REFGUID guidService, REFIID riid, void** ppv) |
| 709 { |
| 710 T* pT = static_cast<T*>(this); |
| 711 HRESULT hr = pT->_InternalQueryService(guidService, riid, ppv); |
| 712 if (FAILED(hr) && m_spServiceProvider) |
| 713 { |
| 714 hr = m_spServiceProvider->QueryService(guidService, riid, ppv); |
| 715 } |
| 716 return hr; |
| 717 } |
| 718 |
| 719 // ===== CInternetProtocol ===== |
| 720 |
| 721 // IInternetProtocolRoot |
| 722 template <class StartPolicy, class ThreadModel> |
| 723 inline STDMETHODIMP CInternetProtocol<StartPolicy, ThreadModel>::Start( |
| 724 LPCWSTR szUrl, IInternetProtocolSink *pOIProtSink, |
| 725 IInternetBindInfo *pOIBindInfo, DWORD grfPI, HANDLE_PTR dwReserved) |
| 726 { |
| 727 ATLASSERT(m_spInternetProtocol != 0); |
| 728 if (!m_spInternetProtocol) |
| 729 { |
| 730 return E_UNEXPECTED; |
| 731 } |
| 732 |
| 733 return StartPolicy::OnStart(szUrl, pOIProtSink, pOIBindInfo, grfPI, |
| 734 dwReserved, m_spInternetProtocol); |
| 735 } |
| 736 |
| 737 // IInternetProtocolEx |
| 738 template <class StartPolicy, class ThreadModel> |
| 739 inline STDMETHODIMP CInternetProtocol<StartPolicy, ThreadModel>::StartEx( |
| 740 IUri* pUri, IInternetProtocolSink *pOIProtSink, |
| 741 IInternetBindInfo *pOIBindInfo, DWORD grfPI, HANDLE_PTR dwReserved) |
| 742 { |
| 743 ATLASSERT(m_spInternetProtocolEx != 0); |
| 744 if (!m_spInternetProtocolEx) |
| 745 { |
| 746 return E_UNEXPECTED; |
| 747 } |
| 748 |
| 749 return StartPolicy::OnStartEx(pUri, pOIProtSink, pOIBindInfo, grfPI, |
| 750 dwReserved, m_spInternetProtocolEx); |
| 751 } |
| 752 |
| 610 } // end namespace PassthroughAPP | 753 } // end namespace PassthroughAPP |
| 611 | 754 |
| 612 #endif // PASSTHROUGHAPP_PROTOCOLIMPL_INL | 755 #endif // PASSTHROUGHAPP_PROTOCOLIMPL_INL |
| OLD | NEW |