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 #define PROTOCOL_THIS(iface) DEFINE_THIS(ProtocolProxy, IInternetProtocol, iface)
26 static HRESULT WINAPI ProtocolProxy_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
28 ProtocolProxy *This = PROTOCOL_THIS(iface);
31 if(IsEqualGUID(&IID_IUnknown, riid)) {
32 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
33 *ppv = PROTOCOL(This);
34 }else if(IsEqualGUID(&IID_IInternetProtocolRoot, riid)) {
35 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This, ppv);
36 *ppv = PROTOCOL(This);
37 }else if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
38 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This, ppv);
39 *ppv = PROTOCOL(This);
40 }else if(IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
41 TRACE("(%p)->(IID_IInternetProtocolSink %p)\n", This, ppv);
42 *ppv = PROTSINK(This);
46 IInternetProtocol_AddRef(iface);
50 WARN("not supported interface %s\n", debugstr_guid(riid));
54 static ULONG WINAPI ProtocolProxy_AddRef(IInternetProtocol *iface)
56 ProtocolProxy *This = PROTOCOL_THIS(iface);
57 LONG ref = InterlockedIncrement(&This->ref);
58 TRACE("(%p) ref=%d\n", This, ref);
62 static ULONG WINAPI ProtocolProxy_Release(IInternetProtocol *iface)
64 ProtocolProxy *This = PROTOCOL_THIS(iface);
65 LONG ref = InterlockedDecrement(&This->ref);
67 TRACE("(%p) ref=%d\n", This, ref);
70 if(This->protocol_sink)
71 IInternetProtocolSink_Release(This->protocol_sink);
73 IInternetProtocol_Release(This->protocol);
77 URLMON_UnlockModule();
83 static HRESULT WINAPI ProtocolProxy_Start(IInternetProtocol *iface, LPCWSTR szUrl,
84 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
85 DWORD grfPI, HANDLE_PTR dwReserved)
87 ProtocolProxy *This = PROTOCOL_THIS(iface);
89 TRACE("(%p)->(%s %p %p %08x %lx)\n", This, debugstr_w(szUrl), pOIProtSink,
90 pOIBindInfo, grfPI, dwReserved);
92 return IInternetProtocol_Start(This->protocol, szUrl, pOIProtSink, pOIBindInfo, grfPI, dwReserved);
95 static HRESULT WINAPI ProtocolProxy_Continue(IInternetProtocol *iface, PROTOCOLDATA *pProtocolData)
97 ProtocolProxy *This = PROTOCOL_THIS(iface);
99 TRACE("(%p)->(%p)\n", This, pProtocolData);
101 return IInternetProtocol_Continue(This->protocol, pProtocolData);
104 static HRESULT WINAPI ProtocolProxy_Abort(IInternetProtocol *iface, HRESULT hrReason,
107 ProtocolProxy *This = PROTOCOL_THIS(iface);
108 FIXME("(%p)->(%08x %08x)\n", This, hrReason, dwOptions);
112 static HRESULT WINAPI ProtocolProxy_Terminate(IInternetProtocol *iface, DWORD dwOptions)
114 ProtocolProxy *This = PROTOCOL_THIS(iface);
116 TRACE("(%p)->(%08x)\n", This, dwOptions);
118 return IInternetProtocol_Terminate(This->protocol, dwOptions);
121 static HRESULT WINAPI ProtocolProxy_Suspend(IInternetProtocol *iface)
123 ProtocolProxy *This = PROTOCOL_THIS(iface);
124 FIXME("(%p)\n", This);
128 static HRESULT WINAPI ProtocolProxy_Resume(IInternetProtocol *iface)
130 ProtocolProxy *This = PROTOCOL_THIS(iface);
131 FIXME("(%p)\n", This);
135 static HRESULT WINAPI ProtocolProxy_Read(IInternetProtocol *iface, void *pv,
136 ULONG cb, ULONG *pcbRead)
138 ProtocolProxy *This = PROTOCOL_THIS(iface);
140 TRACE("(%p)->(%p %u %p)\n", This, pv, cb, pcbRead);
142 return IInternetProtocol_Read(This->protocol, pv, cb, pcbRead);
145 static HRESULT WINAPI ProtocolProxy_Seek(IInternetProtocol *iface, LARGE_INTEGER dlibMove,
146 DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
148 ProtocolProxy *This = PROTOCOL_THIS(iface);
149 FIXME("(%p)->(%d %d %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
153 static HRESULT WINAPI ProtocolProxy_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
155 ProtocolProxy *This = PROTOCOL_THIS(iface);
157 TRACE("(%p)->(%08x)\n", This, dwOptions);
159 return IInternetProtocol_LockRequest(This->protocol, dwOptions);
162 static HRESULT WINAPI ProtocolProxy_UnlockRequest(IInternetProtocol *iface)
164 ProtocolProxy *This = PROTOCOL_THIS(iface);
166 TRACE("(%p)\n", This);
168 return IInternetProtocol_UnlockRequest(This->protocol);
173 static const IInternetProtocolVtbl ProtocolProxyVtbl = {
174 ProtocolProxy_QueryInterface,
175 ProtocolProxy_AddRef,
176 ProtocolProxy_Release,
178 ProtocolProxy_Continue,
180 ProtocolProxy_Terminate,
181 ProtocolProxy_Suspend,
182 ProtocolProxy_Resume,
185 ProtocolProxy_LockRequest,
186 ProtocolProxy_UnlockRequest
189 #define PROTSINK_THIS(iface) DEFINE_THIS(ProtocolProxy, IInternetProtocolSink, iface)
191 static HRESULT WINAPI ProtocolProxySink_QueryInterface(IInternetProtocolSink *iface,
192 REFIID riid, void **ppv)
194 ProtocolProxy *This = PROTSINK_THIS(iface);
195 return IInternetProtocol_QueryInterface(PROTOCOL(This), riid, ppv);
198 static ULONG WINAPI ProtocolProxySink_AddRef(IInternetProtocolSink *iface)
200 ProtocolProxy *This = PROTSINK_THIS(iface);
201 return IInternetProtocol_AddRef(PROTOCOL(This));
204 static ULONG WINAPI ProtocolProxySink_Release(IInternetProtocolSink *iface)
206 ProtocolProxy *This = PROTSINK_THIS(iface);
207 return IInternetProtocol_Release(PROTOCOL(This));
210 static HRESULT WINAPI ProtocolProxySink_Switch(IInternetProtocolSink *iface,
211 PROTOCOLDATA *pProtocolData)
213 ProtocolProxy *This = PROTSINK_THIS(iface);
215 TRACE("(%p)->(%p)\n", This, pProtocolData);
217 return IInternetProtocolSink_Switch(This->protocol_sink, pProtocolData);
220 static HRESULT WINAPI ProtocolProxySink_ReportProgress(IInternetProtocolSink *iface,
221 ULONG ulStatusCode, LPCWSTR szStatusText)
223 ProtocolProxy *This = PROTSINK_THIS(iface);
225 TRACE("(%p)->(%u %s)\n", This, ulStatusCode, debugstr_w(szStatusText));
227 switch(ulStatusCode) {
228 case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE:
229 IInternetProtocolSink_ReportProgress(This->protocol_sink, BINDSTATUS_MIMETYPEAVAILABLE, szStatusText);
232 IInternetProtocolSink_ReportProgress(This->protocol_sink, ulStatusCode, szStatusText);
238 static HRESULT WINAPI ProtocolProxySink_ReportData(IInternetProtocolSink *iface,
239 DWORD grfBSCF, ULONG ulProgress, ULONG ulProgressMax)
241 ProtocolProxy *This = PROTSINK_THIS(iface);
243 TRACE("(%p)->(%d %u %u)\n", This, grfBSCF, ulProgress, ulProgressMax);
245 return IInternetProtocolSink_ReportData(This->protocol_sink, grfBSCF, ulProgress, ulProgressMax);
248 static HRESULT WINAPI ProtocolProxySink_ReportResult(IInternetProtocolSink *iface,
249 HRESULT hrResult, DWORD dwError, LPCWSTR szResult)
251 ProtocolProxy *This = PROTSINK_THIS(iface);
253 TRACE("(%p)->(%08x %d %s)\n", This, hrResult, dwError, debugstr_w(szResult));
255 return IInternetProtocolSink_ReportResult(This->protocol_sink, hrResult, dwError, szResult);
260 static const IInternetProtocolSinkVtbl InternetProtocolSinkVtbl = {
261 ProtocolProxySink_QueryInterface,
262 ProtocolProxySink_AddRef,
263 ProtocolProxySink_Release,
264 ProtocolProxySink_Switch,
265 ProtocolProxySink_ReportProgress,
266 ProtocolProxySink_ReportData,
267 ProtocolProxySink_ReportResult
270 HRESULT create_protocol_proxy(IInternetProtocol *protocol, IInternetProtocolSink *protocol_sink, ProtocolProxy **ret)
274 sink = heap_alloc(sizeof(ProtocolProxy));
276 return E_OUTOFMEMORY;
278 sink->lpIInternetProtocolVtbl = &ProtocolProxyVtbl;
279 sink->lpIInternetProtocolSinkVtbl = &InternetProtocolSinkVtbl;
282 IInternetProtocol_AddRef(protocol);
283 sink->protocol = protocol;
285 IInternetProtocolSink_AddRef(protocol_sink);
286 sink->protocol_sink = protocol_sink;