2 * Copyright 2007 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);
25 const IInternetProtocolVtbl *lpInternetProtocolVtbl;
26 const IInternetBindInfoVtbl *lpInternetBindInfoVtbl;
27 const IInternetPriorityVtbl *lpInternetPriorityVtbl;
28 const IServiceProviderVtbl *lpServiceProviderVtbl;
29 const IInternetProtocolSinkVtbl *lpInternetProtocolSinkVtbl;
33 IInternetProtocol *protocol;
34 IInternetBindInfo *bind_info;
35 IInternetProtocolSink *protocol_sink;
36 IServiceProvider *service_provider;
41 #define PROTOCOL(x) ((IInternetProtocol*) &(x)->lpInternetProtocolVtbl)
42 #define BINDINFO(x) ((IInternetBindInfo*) &(x)->lpInternetBindInfoVtbl)
43 #define PRIORITY(x) ((IInternetPriority*) &(x)->lpInternetPriorityVtbl)
44 #define SERVPROV(x) ((IServiceProvider*) &(x)->lpServiceProviderVtbl)
45 #define PROTSINK(x) ((IInternetProtocolSink*) &(x)->lpInternetProtocolSinkVtbl)
47 #define PROTOCOL_THIS(iface) DEFINE_THIS(BindProtocol, InternetProtocol, iface)
49 static HRESULT WINAPI BindProtocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
51 BindProtocol *This = PROTOCOL_THIS(iface);
54 if(IsEqualGUID(&IID_IUnknown, riid)) {
55 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
56 *ppv = PROTOCOL(This);
57 }else if(IsEqualGUID(&IID_IInternetProtocolRoot, riid)) {
58 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This, ppv);
59 *ppv = PROTOCOL(This);
60 }else if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
61 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This, ppv);
62 *ppv = PROTOCOL(This);
63 }else if(IsEqualGUID(&IID_IInternetBindInfo, riid)) {
64 TRACE("(%p)->(IID_IInternetBindInfo %p)\n", This, ppv);
65 *ppv = BINDINFO(This);
66 }else if(IsEqualGUID(&IID_IInternetPriority, riid)) {
67 TRACE("(%p)->(IID_IInternetPriority %p)\n", This, ppv);
68 *ppv = PRIORITY(This);
69 }else if(IsEqualGUID(&IID_IAuthenticate, riid)) {
70 FIXME("(%p)->(IID_IAuthenticate %p)\n", This, ppv);
71 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
72 TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
73 *ppv = SERVPROV(This);
74 }else if(IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
75 TRACE("(%p)->(IID_IInternetProtocolSink %p)\n", This, ppv);
76 *ppv = PROTSINK(This);
80 IInternetProtocol_AddRef(iface);
84 WARN("not supported interface %s\n", debugstr_guid(riid));
88 static ULONG WINAPI BindProtocol_AddRef(IInternetProtocol *iface)
90 BindProtocol *This = PROTOCOL_THIS(iface);
91 LONG ref = InterlockedIncrement(&This->ref);
92 TRACE("(%p) ref=%d\n", This, ref);
96 static ULONG WINAPI BindProtocol_Release(IInternetProtocol *iface)
98 BindProtocol *This = PROTOCOL_THIS(iface);
99 LONG ref = InterlockedDecrement(&This->ref);
101 TRACE("(%p) ref=%d\n", This, ref);
105 IInternetProtocol_Release(This->protocol);
107 IInternetBindInfo_Release(This->bind_info);
108 if(This->protocol_sink)
109 IInternetProtocolSink_Release(This->protocol_sink);
113 URLMON_UnlockModule();
119 static HRESULT WINAPI BindProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
120 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
121 DWORD grfPI, DWORD dwReserved)
123 BindProtocol *This = PROTOCOL_THIS(iface);
124 IInternetProtocol *protocol = NULL;
125 IInternetPriority *priority;
126 IServiceProvider *service_provider;
127 CLSID clsid = IID_NULL;
131 TRACE("(%p)->(%s %p %p %08x %d)\n", This, debugstr_w(szUrl), pOIProtSink,
132 pOIBindInfo, grfPI, dwReserved);
134 if(!szUrl || !pOIProtSink || !pOIBindInfo)
137 hres = IInternetProtocolSink_QueryInterface(pOIProtSink, &IID_IServiceProvider,
138 (void**)&service_provider);
139 if(SUCCEEDED(hres)) {
140 /* FIXME: What's protocol CLSID here? */
141 IServiceProvider_QueryService(service_provider, &IID_IInternetProtocol,
142 &IID_IInternetProtocol, (void**)&protocol);
143 IServiceProvider_Release(service_provider);
150 hres = get_protocol_handler(szUrl, &clsid, &cf);
154 hres = IClassFactory_CreateInstance(cf, (IUnknown*)BINDINFO(This),
155 &IID_IUnknown, (void**)&unk);
156 IClassFactory_Release(cf);
160 hres = IUnknown_QueryInterface(unk, &IID_IInternetProtocol, (void**)&protocol);
161 IUnknown_Release(unk);
166 StringFromCLSID(&clsid, &clsid_str);
167 IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_PROTOCOLCLASSID, clsid_str);
168 CoTaskMemFree(clsid_str);
170 This->protocol = protocol;
172 IInternetBindInfo_AddRef(pOIBindInfo);
173 This->bind_info = pOIBindInfo;
175 IInternetProtocolSink_AddRef(pOIProtSink);
176 This->protocol_sink = pOIProtSink;
178 IInternetProtocolSink_QueryInterface(pOIProtSink, &IID_IServiceProvider, (void**)&This->service_provider);
180 hres = IInternetProtocol_QueryInterface(protocol, &IID_IInternetPriority, (void**)&priority);
181 if(SUCCEEDED(hres)) {
182 IInternetPriority_SetPriority(priority, This->priority);
183 IInternetPriority_Release(priority);
186 return IInternetProtocol_Start(protocol, szUrl, PROTSINK(This), BINDINFO(This), 0, 0);
189 static HRESULT WINAPI BindProtocol_Continue(IInternetProtocol *iface, PROTOCOLDATA *pProtocolData)
191 BindProtocol *This = PROTOCOL_THIS(iface);
193 TRACE("(%p)->(%p)\n", This, pProtocolData);
195 return IInternetProtocol_Continue(This->protocol, pProtocolData);
198 static HRESULT WINAPI BindProtocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
201 BindProtocol *This = PROTOCOL_THIS(iface);
202 FIXME("(%p)->(%08x %08x)\n", This, hrReason, dwOptions);
206 static HRESULT WINAPI BindProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
208 BindProtocol *This = PROTOCOL_THIS(iface);
210 TRACE("(%p)->(%08x)\n", This, dwOptions);
212 IInternetProtocol_Terminate(This->protocol, 0);
216 static HRESULT WINAPI BindProtocol_Suspend(IInternetProtocol *iface)
218 BindProtocol *This = PROTOCOL_THIS(iface);
219 FIXME("(%p)\n", This);
223 static HRESULT WINAPI BindProtocol_Resume(IInternetProtocol *iface)
225 BindProtocol *This = PROTOCOL_THIS(iface);
226 FIXME("(%p)\n", This);
230 static HRESULT WINAPI BindProtocol_Read(IInternetProtocol *iface, void *pv,
231 ULONG cb, ULONG *pcbRead)
233 BindProtocol *This = PROTOCOL_THIS(iface);
237 TRACE("(%p)->(%p %u %p)\n", This, pv, cb, pcbRead);
239 hres = IInternetProtocol_Read(This->protocol, pv, cb, &read);
245 static HRESULT WINAPI BindProtocol_Seek(IInternetProtocol *iface, LARGE_INTEGER dlibMove,
246 DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
248 BindProtocol *This = PROTOCOL_THIS(iface);
249 FIXME("(%p)->(%d %d %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
253 static HRESULT WINAPI BindProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
255 BindProtocol *This = PROTOCOL_THIS(iface);
257 TRACE("(%p)->(%08x)\n", This, dwOptions);
259 return IInternetProtocol_LockRequest(This->protocol, dwOptions);
262 static HRESULT WINAPI BindProtocol_UnlockRequest(IInternetProtocol *iface)
264 BindProtocol *This = PROTOCOL_THIS(iface);
266 TRACE("(%p)\n", This);
268 return IInternetProtocol_UnlockRequest(This->protocol);
273 static const IInternetProtocolVtbl BindProtocolVtbl = {
274 BindProtocol_QueryInterface,
276 BindProtocol_Release,
278 BindProtocol_Continue,
280 BindProtocol_Terminate,
281 BindProtocol_Suspend,
285 BindProtocol_LockRequest,
286 BindProtocol_UnlockRequest
289 #define BINDINFO_THIS(iface) DEFINE_THIS(BindProtocol, InternetBindInfo, iface)
291 static HRESULT WINAPI BindInfo_QueryInterface(IInternetBindInfo *iface,
292 REFIID riid, void **ppv)
294 BindProtocol *This = BINDINFO_THIS(iface);
295 return IInternetProtocol_QueryInterface(PROTOCOL(This), riid, ppv);
298 static ULONG WINAPI BindInfo_AddRef(IInternetBindInfo *iface)
300 BindProtocol *This = BINDINFO_THIS(iface);
301 return IBinding_AddRef(PROTOCOL(This));
304 static ULONG WINAPI BindInfo_Release(IInternetBindInfo *iface)
306 BindProtocol *This = BINDINFO_THIS(iface);
307 return IBinding_Release(PROTOCOL(This));
310 static HRESULT WINAPI BindInfo_GetBindInfo(IInternetBindInfo *iface,
311 DWORD *grfBINDF, BINDINFO *pbindinfo)
313 BindProtocol *This = BINDINFO_THIS(iface);
316 TRACE("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
318 hres = IInternetBindInfo_GetBindInfo(This->bind_info, grfBINDF, pbindinfo);
320 WARN("GetBindInfo failed: %08x\n", hres);
324 *grfBINDF |= BINDF_FROMURLMON;
328 static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface,
329 ULONG ulStringType, LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
331 BindProtocol *This = BINDINFO_THIS(iface);
333 TRACE("(%p)->(%d %p %d %p)\n", This, ulStringType, ppwzStr, cEl, pcElFetched);
335 return IInternetBindInfo_GetBindString(This->bind_info, ulStringType, ppwzStr, cEl, pcElFetched);
340 static const IInternetBindInfoVtbl InternetBindInfoVtbl = {
341 BindInfo_QueryInterface,
344 BindInfo_GetBindInfo,
345 BindInfo_GetBindString
348 #define PRIORITY_THIS(iface) DEFINE_THIS(BindProtocol, InternetPriority, iface)
350 static HRESULT WINAPI InternetPriority_QueryInterface(IInternetPriority *iface,
351 REFIID riid, void **ppv)
353 BindProtocol *This = PRIORITY_THIS(iface);
354 return IInternetProtocol_QueryInterface(PROTOCOL(This), riid, ppv);
357 static ULONG WINAPI InternetPriority_AddRef(IInternetPriority *iface)
359 BindProtocol *This = PRIORITY_THIS(iface);
360 return IInternetProtocol_AddRef(PROTOCOL(This));
363 static ULONG WINAPI InternetPriority_Release(IInternetPriority *iface)
365 BindProtocol *This = PRIORITY_THIS(iface);
366 return IInternetProtocol_Release(PROTOCOL(This));
369 static HRESULT WINAPI InternetPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
371 BindProtocol *This = PRIORITY_THIS(iface);
373 TRACE("(%p)->(%d)\n", This, nPriority);
375 This->priority = nPriority;
379 static HRESULT WINAPI InternetPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
381 BindProtocol *This = PRIORITY_THIS(iface);
383 TRACE("(%p)->(%p)\n", This, pnPriority);
385 *pnPriority = This->priority;
391 static const IInternetPriorityVtbl InternetPriorityVtbl = {
392 InternetPriority_QueryInterface,
393 InternetPriority_AddRef,
394 InternetPriority_Release,
395 InternetPriority_SetPriority,
396 InternetPriority_GetPriority
400 #define PROTSINK_THIS(iface) DEFINE_THIS(BindProtocol, InternetProtocolSink, iface)
402 static HRESULT WINAPI BPInternetProtocolSink_QueryInterface(IInternetProtocolSink *iface,
403 REFIID riid, void **ppv)
405 BindProtocol *This = PROTSINK_THIS(iface);
406 return IInternetProtocol_QueryInterface(PROTOCOL(This), riid, ppv);
409 static ULONG WINAPI BPInternetProtocolSink_AddRef(IInternetProtocolSink *iface)
411 BindProtocol *This = PROTSINK_THIS(iface);
412 return IInternetProtocol_AddRef(PROTOCOL(This));
415 static ULONG WINAPI BPInternetProtocolSink_Release(IInternetProtocolSink *iface)
417 BindProtocol *This = PROTSINK_THIS(iface);
418 return IInternetProtocol_Release(PROTOCOL(This));
421 static HRESULT WINAPI BPInternetProtocolSink_Switch(IInternetProtocolSink *iface,
422 PROTOCOLDATA *pProtocolData)
424 BindProtocol *This = PROTSINK_THIS(iface);
426 TRACE("(%p)->(%p)\n", This, pProtocolData);
428 return IInternetProtocolSink_Switch(This->protocol_sink, pProtocolData);
431 static HRESULT WINAPI BPInternetProtocolSink_ReportProgress(IInternetProtocolSink *iface,
432 ULONG ulStatusCode, LPCWSTR szStatusText)
434 BindProtocol *This = PROTSINK_THIS(iface);
436 TRACE("(%p)->(%u %s)\n", This, ulStatusCode, debugstr_w(szStatusText));
438 switch(ulStatusCode) {
439 case BINDSTATUS_FINDINGRESOURCE:
440 case BINDSTATUS_CONNECTING:
441 case BINDSTATUS_SENDINGREQUEST:
442 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
443 return IInternetProtocolSink_ReportProgress(This->protocol_sink,
444 ulStatusCode, szStatusText);
445 case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE:
446 case BINDSTATUS_MIMETYPEAVAILABLE:
447 return IInternetProtocolSink_ReportProgress(This->protocol_sink,
448 BINDSTATUS_MIMETYPEAVAILABLE, szStatusText);
450 FIXME("unsupported ulStatusCode %u\n", ulStatusCode);
456 static HRESULT WINAPI BPInternetProtocolSink_ReportData(IInternetProtocolSink *iface,
457 DWORD grfBSCF, ULONG ulProgress, ULONG ulProgressMax)
459 BindProtocol *This = PROTSINK_THIS(iface);
461 TRACE("(%p)->(%d %u %u)\n", This, grfBSCF, ulProgress, ulProgressMax);
463 return IInternetProtocolSink_ReportData(This->protocol_sink, grfBSCF, ulProgress, ulProgressMax);
466 static HRESULT WINAPI BPInternetProtocolSink_ReportResult(IInternetProtocolSink *iface,
467 HRESULT hrResult, DWORD dwError, LPCWSTR szResult)
469 BindProtocol *This = PROTSINK_THIS(iface);
471 TRACE("(%p)->(%08x %d %s)\n", This, hrResult, dwError, debugstr_w(szResult));
473 return IInternetProtocolSink_ReportResult(This->protocol_sink, hrResult, dwError, szResult);
478 static const IInternetProtocolSinkVtbl InternetProtocolSinkVtbl = {
479 BPInternetProtocolSink_QueryInterface,
480 BPInternetProtocolSink_AddRef,
481 BPInternetProtocolSink_Release,
482 BPInternetProtocolSink_Switch,
483 BPInternetProtocolSink_ReportProgress,
484 BPInternetProtocolSink_ReportData,
485 BPInternetProtocolSink_ReportResult
488 #define SERVPROV_THIS(iface) DEFINE_THIS(BindProtocol, ServiceProvider, iface)
490 static HRESULT WINAPI BPServiceProvider_QueryInterface(IServiceProvider *iface,
491 REFIID riid, void **ppv)
493 BindProtocol *This = SERVPROV_THIS(iface);
494 return IInternetProtocol_QueryInterface(PROTOCOL(This), riid, ppv);
497 static ULONG WINAPI BPServiceProvider_AddRef(IServiceProvider *iface)
499 BindProtocol *This = SERVPROV_THIS(iface);
500 return IInternetProtocol_AddRef(PROTOCOL(This));
503 static ULONG WINAPI BPServiceProvider_Release(IServiceProvider *iface)
505 BindProtocol *This = SERVPROV_THIS(iface);
506 return IInternetProtocol_Release(PROTOCOL(This));
509 static HRESULT WINAPI BPServiceProvider_QueryService(IServiceProvider *iface,
510 REFGUID guidService, REFIID riid, void **ppv)
512 BindProtocol *This = SERVPROV_THIS(iface);
514 TRACE("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
516 if(!This->service_provider)
517 return E_NOINTERFACE;
519 return IServiceProvider_QueryService(This->service_provider, guidService, riid, ppv);
524 static const IServiceProviderVtbl ServiceProviderVtbl = {
525 BPServiceProvider_QueryInterface,
526 BPServiceProvider_AddRef,
527 BPServiceProvider_Release,
528 BPServiceProvider_QueryService
531 HRESULT create_binding_protocol(LPCWSTR url, IInternetProtocol **protocol)
533 BindProtocol *ret = heap_alloc_zero(sizeof(BindProtocol));
535 ret->lpInternetProtocolVtbl = &BindProtocolVtbl;
536 ret->lpInternetBindInfoVtbl = &InternetBindInfoVtbl;
537 ret->lpInternetPriorityVtbl = &InternetPriorityVtbl;
538 ret->lpServiceProviderVtbl = &ServiceProviderVtbl;
539 ret->lpInternetProtocolSinkVtbl = &InternetProtocolSinkVtbl;
545 *protocol = PROTOCOL(ret);