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);
256 FIXME("(%p)->(%08x)\n", This, dwOptions);
260 static HRESULT WINAPI BindProtocol_UnlockRequest(IInternetProtocol *iface)
262 BindProtocol *This = PROTOCOL_THIS(iface);
263 FIXME("(%p)\n", This);
269 static const IInternetProtocolVtbl BindProtocolVtbl = {
270 BindProtocol_QueryInterface,
272 BindProtocol_Release,
274 BindProtocol_Continue,
276 BindProtocol_Terminate,
277 BindProtocol_Suspend,
281 BindProtocol_LockRequest,
282 BindProtocol_UnlockRequest
285 #define BINDINFO_THIS(iface) DEFINE_THIS(BindProtocol, InternetBindInfo, iface)
287 static HRESULT WINAPI BindInfo_QueryInterface(IInternetBindInfo *iface,
288 REFIID riid, void **ppv)
290 BindProtocol *This = BINDINFO_THIS(iface);
291 return IInternetProtocol_QueryInterface(PROTOCOL(This), riid, ppv);
294 static ULONG WINAPI BindInfo_AddRef(IInternetBindInfo *iface)
296 BindProtocol *This = BINDINFO_THIS(iface);
297 return IBinding_AddRef(PROTOCOL(This));
300 static ULONG WINAPI BindInfo_Release(IInternetBindInfo *iface)
302 BindProtocol *This = BINDINFO_THIS(iface);
303 return IBinding_Release(PROTOCOL(This));
306 static HRESULT WINAPI BindInfo_GetBindInfo(IInternetBindInfo *iface,
307 DWORD *grfBINDF, BINDINFO *pbindinfo)
309 BindProtocol *This = BINDINFO_THIS(iface);
312 TRACE("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
314 hres = IInternetBindInfo_GetBindInfo(This->bind_info, grfBINDF, pbindinfo);
316 WARN("GetBindInfo failed: %08x\n", hres);
320 *grfBINDF |= BINDF_FROMURLMON;
324 static HRESULT WINAPI BindInfo_GetBindString(IInternetBindInfo *iface,
325 ULONG ulStringType, LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
327 BindProtocol *This = BINDINFO_THIS(iface);
329 TRACE("(%p)->(%d %p %d %p)\n", This, ulStringType, ppwzStr, cEl, pcElFetched);
331 return IInternetBindInfo_GetBindString(This->bind_info, ulStringType, ppwzStr, cEl, pcElFetched);
336 static const IInternetBindInfoVtbl InternetBindInfoVtbl = {
337 BindInfo_QueryInterface,
340 BindInfo_GetBindInfo,
341 BindInfo_GetBindString
344 #define PRIORITY_THIS(iface) DEFINE_THIS(BindProtocol, InternetPriority, iface)
346 static HRESULT WINAPI InternetPriority_QueryInterface(IInternetPriority *iface,
347 REFIID riid, void **ppv)
349 BindProtocol *This = PRIORITY_THIS(iface);
350 return IInternetProtocol_QueryInterface(PROTOCOL(This), riid, ppv);
353 static ULONG WINAPI InternetPriority_AddRef(IInternetPriority *iface)
355 BindProtocol *This = PRIORITY_THIS(iface);
356 return IInternetProtocol_AddRef(PROTOCOL(This));
359 static ULONG WINAPI InternetPriority_Release(IInternetPriority *iface)
361 BindProtocol *This = PRIORITY_THIS(iface);
362 return IInternetProtocol_Release(PROTOCOL(This));
365 static HRESULT WINAPI InternetPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
367 BindProtocol *This = PRIORITY_THIS(iface);
369 TRACE("(%p)->(%d)\n", This, nPriority);
371 This->priority = nPriority;
375 static HRESULT WINAPI InternetPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
377 BindProtocol *This = PRIORITY_THIS(iface);
379 TRACE("(%p)->(%p)\n", This, pnPriority);
381 *pnPriority = This->priority;
387 static const IInternetPriorityVtbl InternetPriorityVtbl = {
388 InternetPriority_QueryInterface,
389 InternetPriority_AddRef,
390 InternetPriority_Release,
391 InternetPriority_SetPriority,
392 InternetPriority_GetPriority
396 #define PROTSINK_THIS(iface) DEFINE_THIS(BindProtocol, InternetProtocolSink, iface)
398 static HRESULT WINAPI InternetProtocolSink_QueryInterface(IInternetProtocolSink *iface,
399 REFIID riid, void **ppv)
401 BindProtocol *This = PROTSINK_THIS(iface);
402 return IInternetProtocol_QueryInterface(PROTOCOL(This), riid, ppv);
405 static ULONG WINAPI InternetProtocolSink_AddRef(IInternetProtocolSink *iface)
407 BindProtocol *This = PROTSINK_THIS(iface);
408 return IInternetProtocol_AddRef(PROTOCOL(This));
411 static ULONG WINAPI InternetProtocolSink_Release(IInternetProtocolSink *iface)
413 BindProtocol *This = PROTSINK_THIS(iface);
414 return IInternetProtocol_Release(PROTOCOL(This));
417 static HRESULT WINAPI InternetProtocolSink_Switch(IInternetProtocolSink *iface,
418 PROTOCOLDATA *pProtocolData)
420 BindProtocol *This = PROTSINK_THIS(iface);
422 TRACE("(%p)->(%p)\n", This, pProtocolData);
424 return IInternetProtocolSink_Switch(This->protocol_sink, pProtocolData);
427 static HRESULT WINAPI InternetProtocolSink_ReportProgress(IInternetProtocolSink *iface,
428 ULONG ulStatusCode, LPCWSTR szStatusText)
430 BindProtocol *This = PROTSINK_THIS(iface);
432 TRACE("(%p)->(%u %s)\n", This, ulStatusCode, debugstr_w(szStatusText));
434 switch(ulStatusCode) {
435 case BINDSTATUS_SENDINGREQUEST:
436 return IInternetProtocolSink_ReportProgress(This->protocol_sink,
438 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
439 return IInternetProtocolSink_ReportProgress(This->protocol_sink,
440 ulStatusCode, szStatusText);
441 case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE:
442 return IInternetProtocolSink_ReportProgress(This->protocol_sink,
443 BINDSTATUS_MIMETYPEAVAILABLE, szStatusText);
445 FIXME("unsupported ulStatusCode %u\n", ulStatusCode);
451 static HRESULT WINAPI InternetProtocolSink_ReportData(IInternetProtocolSink *iface,
452 DWORD grfBSCF, ULONG ulProgress, ULONG ulProgressMax)
454 BindProtocol *This = PROTSINK_THIS(iface);
456 TRACE("(%p)->(%d %u %u)\n", This, grfBSCF, ulProgress, ulProgressMax);
458 return IInternetProtocolSink_ReportData(This->protocol_sink, grfBSCF, ulProgress, ulProgressMax);
461 static HRESULT WINAPI InternetProtocolSink_ReportResult(IInternetProtocolSink *iface,
462 HRESULT hrResult, DWORD dwError, LPCWSTR szResult)
464 BindProtocol *This = PROTSINK_THIS(iface);
466 TRACE("(%p)->(%08x %d %s)\n", This, hrResult, dwError, debugstr_w(szResult));
468 return IInternetProtocolSink_ReportResult(This->protocol_sink, hrResult, dwError, szResult);
473 static const IInternetProtocolSinkVtbl InternetProtocolSinkVtbl = {
474 InternetProtocolSink_QueryInterface,
475 InternetProtocolSink_AddRef,
476 InternetProtocolSink_Release,
477 InternetProtocolSink_Switch,
478 InternetProtocolSink_ReportProgress,
479 InternetProtocolSink_ReportData,
480 InternetProtocolSink_ReportResult
483 #define SERVPROV_THIS(iface) DEFINE_THIS(BindProtocol, ServiceProvider, iface)
485 static HRESULT WINAPI BPServiceProvider_QueryInterface(IServiceProvider *iface,
486 REFIID riid, void **ppv)
488 BindProtocol *This = SERVPROV_THIS(iface);
489 return IInternetProtocol_QueryInterface(PROTOCOL(This), riid, ppv);
492 static ULONG WINAPI BPServiceProvider_AddRef(IServiceProvider *iface)
494 BindProtocol *This = SERVPROV_THIS(iface);
495 return IInternetProtocol_AddRef(PROTOCOL(This));
498 static ULONG WINAPI BPServiceProvider_Release(IServiceProvider *iface)
500 BindProtocol *This = SERVPROV_THIS(iface);
501 return IInternetProtocol_Release(PROTOCOL(This));
504 static HRESULT WINAPI BPServiceProvider_QueryService(IServiceProvider *iface,
505 REFGUID guidService, REFIID riid, void **ppv)
507 BindProtocol *This = SERVPROV_THIS(iface);
509 TRACE("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
511 if(!This->service_provider)
512 return E_NOINTERFACE;
514 return IServiceProvider_QueryService(This->service_provider, guidService, riid, ppv);
519 static const IServiceProviderVtbl ServiceProviderVtbl = {
520 BPServiceProvider_QueryInterface,
521 BPServiceProvider_AddRef,
522 BPServiceProvider_Release,
523 BPServiceProvider_QueryService
526 HRESULT create_binding_protocol(LPCWSTR url, IInternetProtocol **protocol)
528 BindProtocol *ret = heap_alloc(sizeof(BindProtocol));
530 ret->lpInternetProtocolVtbl = &BindProtocolVtbl;
531 ret->lpInternetBindInfoVtbl = &InternetBindInfoVtbl;
532 ret->lpInternetPriorityVtbl = &InternetPriorityVtbl;
533 ret->lpServiceProviderVtbl = &ServiceProviderVtbl;
534 ret->lpInternetProtocolSinkVtbl = &InternetProtocolSinkVtbl;
537 ret->protocol = NULL;
538 ret->bind_info = NULL;
539 ret->protocol_sink = NULL;
540 ret->service_provider = NULL;
545 *protocol = PROTOCOL(ret);