2 * Copyright 2009 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "urlmon_main.h"
20 #include "wine/debug.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
24 static inline ProtocolProxy *impl_from_IInternetProtocol(IInternetProtocol *iface)
26 return CONTAINING_RECORD(iface, ProtocolProxy, IInternetProtocol_iface);
29 static HRESULT WINAPI ProtocolProxy_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
31 ProtocolProxy *This = impl_from_IInternetProtocol(iface);
34 if(IsEqualGUID(&IID_IUnknown, riid)) {
35 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
36 *ppv = &This->IInternetProtocol_iface;
37 }else if(IsEqualGUID(&IID_IInternetProtocolRoot, riid)) {
38 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This, ppv);
39 *ppv = &This->IInternetProtocol_iface;
40 }else if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
41 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This, ppv);
42 *ppv = &This->IInternetProtocol_iface;
43 }else if(IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
44 TRACE("(%p)->(IID_IInternetProtocolSink %p)\n", This, ppv);
45 *ppv = &This->IInternetProtocolSink_iface;
49 IInternetProtocol_AddRef(iface);
53 WARN("not supported interface %s\n", debugstr_guid(riid));
57 static ULONG WINAPI ProtocolProxy_AddRef(IInternetProtocol *iface)
59 ProtocolProxy *This = impl_from_IInternetProtocol(iface);
60 LONG ref = InterlockedIncrement(&This->ref);
61 TRACE("(%p) ref=%d\n", This, ref);
65 static ULONG WINAPI ProtocolProxy_Release(IInternetProtocol *iface)
67 ProtocolProxy *This = impl_from_IInternetProtocol(iface);
68 LONG ref = InterlockedDecrement(&This->ref);
70 TRACE("(%p) ref=%d\n", This, ref);
73 if(This->protocol_sink)
74 IInternetProtocolSink_Release(This->protocol_sink);
76 IInternetProtocol_Release(This->protocol);
80 URLMON_UnlockModule();
86 static HRESULT WINAPI ProtocolProxy_Start(IInternetProtocol *iface, LPCWSTR szUrl,
87 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
88 DWORD grfPI, HANDLE_PTR dwReserved)
90 ProtocolProxy *This = impl_from_IInternetProtocol(iface);
92 TRACE("(%p)->(%s %p %p %08x %lx)\n", This, debugstr_w(szUrl), pOIProtSink,
93 pOIBindInfo, grfPI, dwReserved);
95 return IInternetProtocol_Start(This->protocol, szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved);
98 static HRESULT WINAPI ProtocolProxy_Continue(IInternetProtocol *iface, PROTOCOLDATA *pProtocolData)
100 ProtocolProxy *This = impl_from_IInternetProtocol(iface);
102 TRACE("(%p)->(%p)\n", This, pProtocolData);
104 return IInternetProtocol_Continue(This->protocol, pProtocolData);
107 static HRESULT WINAPI ProtocolProxy_Abort(IInternetProtocol *iface, HRESULT hrReason,
110 ProtocolProxy *This = impl_from_IInternetProtocol(iface);
111 FIXME("(%p)->(%08x %08x)\n", This, hrReason, dwOptions);
115 static HRESULT WINAPI ProtocolProxy_Terminate(IInternetProtocol *iface, DWORD dwOptions)
117 ProtocolProxy *This = impl_from_IInternetProtocol(iface);
119 TRACE("(%p)->(%08x)\n", This, dwOptions);
121 return IInternetProtocol_Terminate(This->protocol, dwOptions);
124 static HRESULT WINAPI ProtocolProxy_Suspend(IInternetProtocol *iface)
126 ProtocolProxy *This = impl_from_IInternetProtocol(iface);
127 FIXME("(%p)\n", This);
131 static HRESULT WINAPI ProtocolProxy_Resume(IInternetProtocol *iface)
133 ProtocolProxy *This = impl_from_IInternetProtocol(iface);
134 FIXME("(%p)\n", This);
138 static HRESULT WINAPI ProtocolProxy_Read(IInternetProtocol *iface, void *pv,
139 ULONG cb, ULONG *pcbRead)
141 ProtocolProxy *This = impl_from_IInternetProtocol(iface);
143 TRACE("(%p)->(%p %u %p)\n", This, pv, cb, pcbRead);
145 return IInternetProtocol_Read(This->protocol, pv, cb, pcbRead);
148 static HRESULT WINAPI ProtocolProxy_Seek(IInternetProtocol *iface, LARGE_INTEGER dlibMove,
149 DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
151 ProtocolProxy *This = impl_from_IInternetProtocol(iface);
152 FIXME("(%p)->(%d %d %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
156 static HRESULT WINAPI ProtocolProxy_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
158 ProtocolProxy *This = impl_from_IInternetProtocol(iface);
160 TRACE("(%p)->(%08x)\n", This, dwOptions);
162 return IInternetProtocol_LockRequest(This->protocol, dwOptions);
165 static HRESULT WINAPI ProtocolProxy_UnlockRequest(IInternetProtocol *iface)
167 ProtocolProxy *This = impl_from_IInternetProtocol(iface);
169 TRACE("(%p)\n", This);
171 return IInternetProtocol_UnlockRequest(This->protocol);
174 static const IInternetProtocolVtbl ProtocolProxyVtbl = {
175 ProtocolProxy_QueryInterface,
176 ProtocolProxy_AddRef,
177 ProtocolProxy_Release,
179 ProtocolProxy_Continue,
181 ProtocolProxy_Terminate,
182 ProtocolProxy_Suspend,
183 ProtocolProxy_Resume,
186 ProtocolProxy_LockRequest,
187 ProtocolProxy_UnlockRequest
190 static inline ProtocolProxy *impl_from_IInternetProtocolSink(IInternetProtocolSink *iface)
192 return CONTAINING_RECORD(iface, ProtocolProxy, IInternetProtocolSink_iface);
195 static HRESULT WINAPI ProtocolProxySink_QueryInterface(IInternetProtocolSink *iface,
196 REFIID riid, void **ppv)
198 ProtocolProxy *This = impl_from_IInternetProtocolSink(iface);
199 return IInternetProtocol_QueryInterface(&This->IInternetProtocol_iface, riid, ppv);
202 static ULONG WINAPI ProtocolProxySink_AddRef(IInternetProtocolSink *iface)
204 ProtocolProxy *This = impl_from_IInternetProtocolSink(iface);
205 return IInternetProtocol_AddRef(&This->IInternetProtocol_iface);
208 static ULONG WINAPI ProtocolProxySink_Release(IInternetProtocolSink *iface)
210 ProtocolProxy *This = impl_from_IInternetProtocolSink(iface);
211 return IInternetProtocol_Release(&This->IInternetProtocol_iface);
214 static HRESULT WINAPI ProtocolProxySink_Switch(IInternetProtocolSink *iface,
215 PROTOCOLDATA *pProtocolData)
217 ProtocolProxy *This = impl_from_IInternetProtocolSink(iface);
219 TRACE("(%p)->(%p)\n", This, pProtocolData);
221 return IInternetProtocolSink_Switch(This->protocol_sink, pProtocolData);
224 static HRESULT WINAPI ProtocolProxySink_ReportProgress(IInternetProtocolSink *iface,
225 ULONG ulStatusCode, LPCWSTR szStatusText)
227 ProtocolProxy *This = impl_from_IInternetProtocolSink(iface);
229 TRACE("(%p)->(%u %s)\n", This, ulStatusCode, debugstr_w(szStatusText));
231 switch(ulStatusCode) {
232 case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE:
233 IInternetProtocolSink_ReportProgress(This->protocol_sink, BINDSTATUS_MIMETYPEAVAILABLE, szStatusText);
236 IInternetProtocolSink_ReportProgress(This->protocol_sink, ulStatusCode, szStatusText);
242 static HRESULT WINAPI ProtocolProxySink_ReportData(IInternetProtocolSink *iface,
243 DWORD grfBSCF, ULONG ulProgress, ULONG ulProgressMax)
245 ProtocolProxy *This = impl_from_IInternetProtocolSink(iface);
247 TRACE("(%p)->(%d %u %u)\n", This, grfBSCF, ulProgress, ulProgressMax);
249 return IInternetProtocolSink_ReportData(This->protocol_sink, grfBSCF, ulProgress, ulProgressMax);
252 static HRESULT WINAPI ProtocolProxySink_ReportResult(IInternetProtocolSink *iface,
253 HRESULT hrResult, DWORD dwError, LPCWSTR szResult)
255 ProtocolProxy *This = impl_from_IInternetProtocolSink(iface);
257 TRACE("(%p)->(%08x %d %s)\n", This, hrResult, dwError, debugstr_w(szResult));
259 return IInternetProtocolSink_ReportResult(This->protocol_sink, hrResult, dwError, szResult);
262 static const IInternetProtocolSinkVtbl InternetProtocolSinkVtbl = {
263 ProtocolProxySink_QueryInterface,
264 ProtocolProxySink_AddRef,
265 ProtocolProxySink_Release,
266 ProtocolProxySink_Switch,
267 ProtocolProxySink_ReportProgress,
268 ProtocolProxySink_ReportData,
269 ProtocolProxySink_ReportResult
272 HRESULT create_protocol_proxy(IInternetProtocol *protocol, IInternetProtocolSink *protocol_sink, ProtocolProxy **ret)
276 sink = heap_alloc(sizeof(ProtocolProxy));
278 return E_OUTOFMEMORY;
280 sink->IInternetProtocol_iface.lpVtbl = &ProtocolProxyVtbl;
281 sink->IInternetProtocolSink_iface.lpVtbl = &InternetProtocolSinkVtbl;
284 IInternetProtocol_AddRef(protocol);
285 sink->protocol = protocol;
287 IInternetProtocolSink_AddRef(protocol_sink);
288 sink->protocol_sink = protocol_sink;