2 * Copyright 2005 Jacek Caban
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #define NONAMELESSUNION
23 #define NONAMELESSSTRUCT
30 #include "urlmon_main.h"
32 #include "wine/debug.h"
33 #include "wine/unicode.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
37 typedef struct ProtocolStream ProtocolStream;
40 const IBindingVtbl *lpBindingVtbl;
41 const IInternetProtocolSinkVtbl *lpInternetProtocolSinkVtbl;
42 const IInternetBindInfoVtbl *lpInternetBindInfoVtbl;
43 const IServiceProviderVtbl *lpServiceProviderVtbl;
47 IBindStatusCallback *callback;
48 IInternetProtocol *protocol;
49 IServiceProvider *service_provider;
50 ProtocolStream *stream;
58 struct ProtocolStream {
59 const IStreamVtbl *lpStreamVtbl;
63 IInternetProtocol *protocol;
69 #define BINDING(x) ((IBinding*) &(x)->lpBindingVtbl)
70 #define PROTSINK(x) ((IInternetProtocolSink*) &(x)->lpInternetProtocolSinkVtbl)
71 #define BINDINF(x) ((IInternetBindInfo*) &(x)->lpInternetBindInfoVtbl)
72 #define SERVPROV(x) ((IServiceProvider*) &(x)->lpServiceProviderVtbl)
74 #define STREAM(x) ((IStream*) &(x)->lpStreamVtbl)
76 static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface,
77 REFIID riid, void **ppv)
81 if(IsEqualGUID(&IID_IUnknown, riid)) {
82 TRACE("(IID_IUnknown %p)\n", ppv);
84 }else if(IsEqualGUID(&IID_IHttpNegotiate, riid)) {
85 TRACE("(IID_IHttpNegotiate %p)\n", ppv);
87 }else if(IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
88 TRACE("(IID_IHttpNegotiate2 %p)\n", ppv);
93 IHttpNegotiate2_AddRef(iface);
97 WARN("Unsupported interface %s\n", debugstr_guid(riid));
101 static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
107 static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
109 URLMON_UnlockModule();
113 static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface,
114 LPCWSTR szURL, LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
116 FIXME("(%s %s %ld %p)\n", debugstr_w(szURL), debugstr_w(szHeaders), dwReserved,
117 pszAdditionalHeaders);
121 static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
122 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders,
123 LPWSTR *pszAdditionalRequestHeaders)
125 FIXME("(%ld %s %s %p)\n", dwResponseCode, debugstr_w(szResponseHeaders),
126 debugstr_w(szRequestHeaders), pszAdditionalRequestHeaders);
130 static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
131 BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
133 FIXME("(%p %p %ld)\n", pbSecurityId, pcbSecurityId, dwReserved);
137 static const IHttpNegotiate2Vtbl HttpNegotiate2Vtbl = {
138 HttpNegotiate_QueryInterface,
139 HttpNegotiate_AddRef,
140 HttpNegotiate_Release,
141 HttpNegotiate_BeginningTransaction,
142 HttpNegotiate_OnResponse,
143 HttpNegotiate_GetRootSecurityId
146 static IHttpNegotiate2 HttpNegotiate = { &HttpNegotiate2Vtbl };
148 #define STREAM_THIS(iface) DEFINE_THIS(ProtocolStream, Stream, iface)
150 static HRESULT WINAPI ProtocolStream_QueryInterface(IStream *iface,
151 REFIID riid, void **ppv)
153 ProtocolStream *This = STREAM_THIS(iface);
157 if(IsEqualGUID(&IID_IUnknown, riid)) {
158 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
160 }else if(IsEqualGUID(&IID_ISequentialStream, riid)) {
161 TRACE("(%p)->(IID_ISequentialStream %p)\n", This, ppv);
163 }else if(IsEqualGUID(&IID_IStream, riid)) {
164 TRACE("(%p)->(IID_IStream %p)\n", This, ppv);
169 IStream_AddRef(STREAM(This));
173 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
174 return E_NOINTERFACE;
177 static ULONG WINAPI ProtocolStream_AddRef(IStream *iface)
179 ProtocolStream *This = STREAM_THIS(iface);
180 LONG ref = InterlockedIncrement(&This->ref);
182 TRACE("(%p) ref=%ld\n", This, ref);
187 static ULONG WINAPI ProtocolStream_Release(IStream *iface)
189 ProtocolStream *This = STREAM_THIS(iface);
190 LONG ref = InterlockedDecrement(&This->ref);
192 TRACE("(%p) ref=%ld\n", This, ref);
195 IInternetProtocol_Release(This->protocol);
196 HeapFree(GetProcessHeap(), 0, This);
202 static HRESULT WINAPI ProtocolStream_Read(IStream *iface, void *pv,
203 ULONG cb, ULONG *pcbRead)
205 ProtocolStream *This = STREAM_THIS(iface);
206 DWORD read = 0, pread = 0;
208 TRACE("(%p)->(%p %ld %p)\n", This, pv, cb, pcbRead);
213 if(read > This->buf_size)
214 read = This->buf_size;
216 memcpy(pv, This->buf, read);
218 if(read < This->buf_size)
219 memmove(This->buf, This->buf+read, This->buf_size-read);
220 This->buf_size -= read;
228 IInternetProtocol_Read(This->protocol, (PBYTE)pv+read, cb-read, &pread);
229 *pcbRead = read + pread;
231 return read || pread ? S_OK : S_FALSE;
234 static HRESULT WINAPI ProtocolStream_Write(IStream *iface, const void *pv,
235 ULONG cb, ULONG *pcbWritten)
237 ProtocolStream *This = STREAM_THIS(iface);
239 TRACE("(%p)->(%p %ld %p)\n", This, pv, cb, pcbWritten);
241 return STG_E_ACCESSDENIED;
244 static HRESULT WINAPI ProtocolStream_Seek(IStream *iface, LARGE_INTEGER dlibMove,
245 DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
247 ProtocolStream *This = STREAM_THIS(iface);
248 FIXME("(%p)->(%ld %08lx %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
252 static HRESULT WINAPI ProtocolStream_SetSize(IStream *iface, ULARGE_INTEGER libNewSize)
254 ProtocolStream *This = STREAM_THIS(iface);
255 FIXME("(%p)->(%ld)\n", This, libNewSize.u.LowPart);
259 static HRESULT WINAPI ProtocolStream_CopyTo(IStream *iface, IStream *pstm,
260 ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten)
262 ProtocolStream *This = STREAM_THIS(iface);
263 FIXME("(%p)->(%p %ld %p %p)\n", This, pstm, cb.u.LowPart, pcbRead, pcbWritten);
267 static HRESULT WINAPI ProtocolStream_Commit(IStream *iface, DWORD grfCommitFlags)
269 ProtocolStream *This = STREAM_THIS(iface);
271 TRACE("(%p)->(%08lx)\n", This, grfCommitFlags);
276 static HRESULT WINAPI ProtocolStream_Revert(IStream *iface)
278 ProtocolStream *This = STREAM_THIS(iface);
280 TRACE("(%p)\n", This);
285 static HRESULT WINAPI ProtocolStream_LockRegion(IStream *iface, ULARGE_INTEGER libOffset,
286 ULARGE_INTEGER cb, DWORD dwLockType)
288 ProtocolStream *This = STREAM_THIS(iface);
289 FIXME("(%p)->(%ld %ld %ld)\n", This, libOffset.u.LowPart, cb.u.LowPart, dwLockType);
293 static HRESULT WINAPI ProtocolStream_UnlockRegion(IStream *iface,
294 ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
296 ProtocolStream *This = STREAM_THIS(iface);
297 FIXME("(%p)->(%ld %ld %ld)\n", This, libOffset.u.LowPart, cb.u.LowPart, dwLockType);
301 static HRESULT WINAPI ProtocolStream_Stat(IStream *iface, STATSTG *pstatstg,
304 ProtocolStream *This = STREAM_THIS(iface);
305 FIXME("(%p)->(%p %08lx)\n", This, pstatstg, dwStatFlag);
309 static HRESULT WINAPI ProtocolStream_Clone(IStream *iface, IStream **ppstm)
311 ProtocolStream *This = STREAM_THIS(iface);
312 FIXME("(%p)->(%p)\n", This, ppstm);
318 static const IStreamVtbl ProtocolStreamVtbl = {
319 ProtocolStream_QueryInterface,
320 ProtocolStream_AddRef,
321 ProtocolStream_Release,
323 ProtocolStream_Write,
325 ProtocolStream_SetSize,
326 ProtocolStream_CopyTo,
327 ProtocolStream_Commit,
328 ProtocolStream_Revert,
329 ProtocolStream_LockRegion,
330 ProtocolStream_UnlockRegion,
335 #define BINDING_THIS(iface) DEFINE_THIS(Binding, Binding, iface)
337 static ProtocolStream *create_stream(IInternetProtocol *protocol)
339 ProtocolStream *ret = HeapAlloc(GetProcessHeap(), 0, sizeof(ProtocolStream));
341 ret->lpStreamVtbl = &ProtocolStreamVtbl;
345 IInternetProtocol_AddRef(protocol);
346 ret->protocol = protocol;
351 static void fill_stream_buffer(ProtocolStream *This)
355 IInternetProtocol_Read(This->protocol, This->buf+This->buf_size,
356 sizeof(This->buf)-This->buf_size, &read);
357 This->buf_size += read;
360 static HRESULT WINAPI Binding_QueryInterface(IBinding *iface, REFIID riid, void **ppv)
362 Binding *This = BINDING_THIS(iface);
366 if(IsEqualGUID(&IID_IUnknown, riid)) {
367 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
368 *ppv = BINDING(This);
369 }else if(IsEqualGUID(&IID_IBinding, riid)) {
370 TRACE("(%p)->(IID_IBinding %p)\n", This, ppv);
371 *ppv = BINDING(This);
372 }else if(IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
373 TRACE("(%p)->(IID_IInternetProtocolSink %p)\n", This, ppv);
374 *ppv = PROTSINK(This);
375 }else if(IsEqualGUID(&IID_IInternetBindInfo, riid)) {
376 TRACE("(%p)->(IID_IInternetBindInfo %p)\n", This, ppv);
377 *ppv = BINDINF(This);
378 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
379 TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
380 *ppv = SERVPROV(This);
386 WARN("Unsupported interface %s\n", debugstr_guid(riid));
387 return E_NOINTERFACE;
390 static ULONG WINAPI Binding_AddRef(IBinding *iface)
392 Binding *This = BINDING_THIS(iface);
393 LONG ref = InterlockedIncrement(&This->ref);
395 TRACE("(%p) ref=%ld\n", This, ref);
400 static ULONG WINAPI Binding_Release(IBinding *iface)
402 Binding *This = BINDING_THIS(iface);
403 LONG ref = InterlockedDecrement(&This->ref);
405 TRACE("(%p) ref=%ld\n", This, ref);
409 IBindStatusCallback_Release(This->callback);
411 IInternetProtocol_Release(This->protocol);
412 if(This->service_provider)
413 IServiceProvider_Release(This->service_provider);
415 IStream_Release(STREAM(This->stream));
417 ReleaseBindInfo(&This->bindinfo);
418 HeapFree(GetProcessHeap(), 0, This->mime);
419 HeapFree(GetProcessHeap(), 0, This->url);
421 HeapFree(GetProcessHeap(), 0, This);
427 static HRESULT WINAPI Binding_Abort(IBinding *iface)
429 Binding *This = BINDING_THIS(iface);
430 FIXME("(%p)\n", This);
434 static HRESULT WINAPI Binding_Suspend(IBinding *iface)
436 Binding *This = BINDING_THIS(iface);
437 FIXME("(%p)\n", This);
441 static HRESULT WINAPI Binding_Resume(IBinding *iface)
443 Binding *This = BINDING_THIS(iface);
444 FIXME("(%p)\n", This);
448 static HRESULT WINAPI Binding_SetPriority(IBinding *iface, LONG nPriority)
450 Binding *This = BINDING_THIS(iface);
451 FIXME("(%p)->(%ld)\n", This, nPriority);
455 static HRESULT WINAPI Binding_GetPriority(IBinding *iface, LONG *pnPriority)
457 Binding *This = BINDING_THIS(iface);
458 FIXME("(%p)->(%p)\n", This, pnPriority);
462 static HRESULT WINAPI Binding_GetBindResult(IBinding *iface, CLSID *pclsidProtocol,
463 DWORD *pdwResult, LPOLESTR *pszResult, DWORD *pdwReserved)
465 Binding *This = BINDING_THIS(iface);
466 FIXME("(%p)->(%p %p %p %p)\n", This, pclsidProtocol, pdwResult, pszResult, pdwReserved);
472 static const IBindingVtbl BindingVtbl = {
473 Binding_QueryInterface,
481 Binding_GetBindResult
484 #define PROTSINK_THIS(iface) DEFINE_THIS(Binding, InternetProtocolSink, iface)
486 static HRESULT WINAPI InternetProtocolSink_QueryInterface(IInternetProtocolSink *iface,
487 REFIID riid, void **ppv)
489 Binding *This = PROTSINK_THIS(iface);
490 return IBinding_QueryInterface(BINDING(This), riid, ppv);
493 static ULONG WINAPI InternetProtocolSink_AddRef(IInternetProtocolSink *iface)
495 Binding *This = PROTSINK_THIS(iface);
496 return IBinding_AddRef(BINDING(This));
499 static ULONG WINAPI InternetProtocolSink_Release(IInternetProtocolSink *iface)
501 Binding *This = PROTSINK_THIS(iface);
502 return IBinding_Release(BINDING(This));
505 static HRESULT WINAPI InternetProtocolSink_Switch(IInternetProtocolSink *iface,
506 PROTOCOLDATA *pProtocolData)
508 Binding *This = PROTSINK_THIS(iface);
509 FIXME("(%p)->(%p)\n", This, pProtocolData);
513 static HRESULT WINAPI InternetProtocolSink_ReportProgress(IInternetProtocolSink *iface,
514 ULONG ulStatusCode, LPCWSTR szStatusText)
516 Binding *This = PROTSINK_THIS(iface);
518 TRACE("(%p)->(%lu %s)\n", This, ulStatusCode, debugstr_w(szStatusText));
520 switch(ulStatusCode) {
521 case BINDSTATUS_MIMETYPEAVAILABLE: {
522 int len = strlenW(szStatusText)+1;
523 This->mime = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
524 memcpy(This->mime, szStatusText, len*sizeof(WCHAR));
527 case BINDSTATUS_SENDINGREQUEST:
528 IBindStatusCallback_OnProgress(This->callback, 0, 0, BINDSTATUS_SENDINGREQUEST,
531 case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE:
532 IBindStatusCallback_OnProgress(This->callback, 0, 0,
533 BINDSTATUS_MIMETYPEAVAILABLE, szStatusText);
535 case BINDSTATUS_CACHEFILENAMEAVAILABLE:
538 FIXME("Unhandled status code %ld\n", ulStatusCode);
545 static HRESULT WINAPI InternetProtocolSink_ReportData(IInternetProtocolSink *iface,
546 DWORD grfBSCF, ULONG ulProgress, ULONG ulProgressMax)
548 Binding *This = PROTSINK_THIS(iface);
552 TRACE("(%p)->(%ld %lu %lu)\n", This, grfBSCF, ulProgress, ulProgressMax);
554 if(grfBSCF & BSCF_FIRSTDATANOTIFICATION) {
556 IBindStatusCallback_OnProgress(This->callback, ulProgress, ulProgressMax,
557 BINDSTATUS_MIMETYPEAVAILABLE, This->mime);
558 IBindStatusCallback_OnProgress(This->callback, ulProgress, ulProgressMax,
559 BINDSTATUS_BEGINDOWNLOADDATA, This->url);
562 if(grfBSCF & BSCF_LASTDATANOTIFICATION)
563 IBindStatusCallback_OnProgress(This->callback, ulProgress, ulProgressMax,
564 BINDSTATUS_ENDDOWNLOADDATA, This->url);
566 if(grfBSCF & BSCF_FIRSTDATANOTIFICATION)
567 IInternetProtocol_LockRequest(This->protocol, 0);
569 fill_stream_buffer(This->stream);
571 stgmed.tymed = TYMED_ISTREAM;
572 stgmed.u.pstm = STREAM(This->stream);
574 formatetc.cfFormat = 0; /* FIXME */
575 formatetc.ptd = NULL;
576 formatetc.dwAspect = 1;
577 formatetc.lindex = -1;
578 formatetc.tymed = TYMED_ISTREAM;
580 IBindStatusCallback_OnDataAvailable(This->callback, grfBSCF, This->stream->buf_size,
581 &formatetc, &stgmed);
583 if(grfBSCF & BSCF_LASTDATANOTIFICATION)
584 IBindStatusCallback_OnStopBinding(This->callback, S_OK, NULL);
589 static HRESULT WINAPI InternetProtocolSink_ReportResult(IInternetProtocolSink *iface,
590 HRESULT hrResult, DWORD dwError, LPCWSTR szResult)
592 Binding *This = PROTSINK_THIS(iface);
593 FIXME("(%p)->(%08lx %ld %s)\n", This, hrResult, dwError, debugstr_w(szResult));
599 static const IInternetProtocolSinkVtbl InternetProtocolSinkVtbl = {
600 InternetProtocolSink_QueryInterface,
601 InternetProtocolSink_AddRef,
602 InternetProtocolSink_Release,
603 InternetProtocolSink_Switch,
604 InternetProtocolSink_ReportProgress,
605 InternetProtocolSink_ReportData,
606 InternetProtocolSink_ReportResult
609 #define BINDINF_THIS(iface) DEFINE_THIS(Binding, InternetBindInfo, iface)
611 static HRESULT WINAPI InternetBindInfo_QueryInterface(IInternetBindInfo *iface,
612 REFIID riid, void **ppv)
614 Binding *This = BINDINF_THIS(iface);
615 return IBinding_QueryInterface(BINDING(This), riid, ppv);
618 static ULONG WINAPI InternetBindInfo_AddRef(IInternetBindInfo *iface)
620 Binding *This = BINDINF_THIS(iface);
621 return IBinding_AddRef(BINDING(This));
624 static ULONG WINAPI InternetBindInfo_Release(IInternetBindInfo *iface)
626 Binding *This = BINDINF_THIS(iface);
627 return IBinding_Release(BINDING(This));
630 static HRESULT WINAPI InternetBindInfo_GetBindInfo(IInternetBindInfo *iface,
631 DWORD *grfBINDF, BINDINFO *pbindinfo)
633 Binding *This = BINDINF_THIS(iface);
635 TRACE("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
637 *grfBINDF = This->bindf;
639 memcpy(pbindinfo, &This->bindinfo, sizeof(BINDINFO));
641 if(pbindinfo->szExtraInfo || pbindinfo->szCustomVerb)
642 FIXME("copy strings\n");
645 IUnknown_AddRef(pbindinfo->pUnk);
650 static HRESULT WINAPI InternetBindInfo_GetBindString(IInternetBindInfo *iface,
651 ULONG ulStringType, LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
653 Binding *This = BINDINF_THIS(iface);
655 TRACE("(%p)->(%ld %p %ld %p)\n", This, ulStringType, ppwzStr, cEl, pcElFetched);
657 switch(ulStringType) {
658 case BINDSTRING_ACCEPT_MIMES: {
659 static const WCHAR wszMimes[] = {'*','/','*',0};
661 if(!ppwzStr || !pcElFetched)
664 ppwzStr[0] = CoTaskMemAlloc(sizeof(wszMimes));
665 memcpy(ppwzStr[0], wszMimes, sizeof(wszMimes));
669 case BINDSTRING_USER_AGENT: {
670 IInternetBindInfo *bindinfo = NULL;
673 hres = IBindStatusCallback_QueryInterface(This->callback, &IID_IInternetBindInfo,
678 hres = IInternetBindInfo_GetBindString(bindinfo, ulStringType, ppwzStr,
680 IInternetBindInfo_Release(bindinfo);
686 FIXME("not supported string type %ld\n", ulStringType);
692 static const IInternetBindInfoVtbl InternetBindInfoVtbl = {
693 InternetBindInfo_QueryInterface,
694 InternetBindInfo_AddRef,
695 InternetBindInfo_Release,
696 InternetBindInfo_GetBindInfo,
697 InternetBindInfo_GetBindString
700 #define SERVPROV_THIS(iface) DEFINE_THIS(Binding, ServiceProvider, iface)
702 static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface,
703 REFIID riid, void **ppv)
705 Binding *This = SERVPROV_THIS(iface);
706 return IBinding_QueryInterface(BINDING(This), riid, ppv);
709 static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
711 Binding *This = SERVPROV_THIS(iface);
712 return IBinding_AddRef(BINDING(This));
715 static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
717 Binding *This = SERVPROV_THIS(iface);
718 return IBinding_Release(BINDING(This));
721 static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface,
722 REFGUID guidService, REFIID riid, void **ppv)
724 Binding *This = SERVPROV_THIS(iface);
727 TRACE("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
729 if(This->service_provider) {
730 hres = IServiceProvider_QueryService(This->service_provider, guidService,
736 if(IsEqualGUID(&IID_IHttpNegotiate, guidService)
737 || IsEqualGUID(&IID_IHttpNegotiate2, guidService))
738 return IHttpNegotiate2_QueryInterface(&HttpNegotiate, riid, ppv);
740 WARN("unknown service %s\n", debugstr_guid(guidService));
746 static const IServiceProviderVtbl ServiceProviderVtbl = {
747 ServiceProvider_QueryInterface,
748 ServiceProvider_AddRef,
749 ServiceProvider_Release,
750 ServiceProvider_QueryService
753 static HRESULT get_callback(IBindCtx *pbc, IBindStatusCallback **callback)
757 static WCHAR wszBSCBHolder[] = { '_','B','S','C','B','_','H','o','l','d','e','r','_',0 };
759 hres = IBindCtx_GetObjectParam(pbc, wszBSCBHolder, (IUnknown**)callback);
766 static HRESULT get_protocol(Binding *This, LPCWSTR url)
768 IUnknown *unk = NULL;
769 IClassFactory *cf = NULL;
772 hres = IBindStatusCallback_QueryInterface(This->callback, &IID_IInternetProtocol,
773 (void**)&This->protocol);
777 if(This->service_provider) {
778 hres = IServiceProvider_QueryService(This->service_provider, &IID_IInternetProtocol,
779 &IID_IInternetProtocol, (void**)&This->protocol);
784 hres = get_protocol_iface(url, &unk);
788 hres = IUnknown_QueryInterface(unk, &IID_IClassFactory, (void**)&cf);
789 IUnknown_Release(unk);
793 hres = IClassFactory_CreateInstance(cf, NULL, &IID_IInternetProtocol, (void**)&This->protocol);
794 IClassFactory_Release(cf);
799 static HRESULT Binding_Create(LPCWSTR url, IBindCtx *pbc, REFIID riid, Binding **binding)
805 static const WCHAR wszFile[] = {'f','i','l','e',':'};
807 if(!IsEqualGUID(&IID_IStream, riid)) {
808 FIXME("Unsupported riid %s\n", debugstr_guid(riid));
812 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(Binding));
814 ret->lpBindingVtbl = &BindingVtbl;
815 ret->lpInternetProtocolSinkVtbl = &InternetProtocolSinkVtbl;
816 ret->lpInternetBindInfoVtbl = &InternetBindInfoVtbl;
817 ret->lpServiceProviderVtbl = &ServiceProviderVtbl;
821 ret->callback = NULL;
822 ret->protocol = NULL;
823 ret->service_provider = NULL;
828 memset(&ret->bindinfo, 0, sizeof(BINDINFO));
829 ret->bindinfo.cbSize = sizeof(BINDINFO);
832 hres = get_callback(pbc, &ret->callback);
834 WARN("Could not get IBindStatusCallback\n");
835 IBinding_Release(BINDING(ret));
839 IBindStatusCallback_QueryInterface(ret->callback, &IID_IServiceProvider,
840 (void**)&ret->service_provider);
842 hres = get_protocol(ret, url);
844 WARN("Could not get protocol handler\n");
845 IBinding_Release(BINDING(ret));
849 hres = IBindStatusCallback_GetBindInfo(ret->callback, &ret->bindf, &ret->bindinfo);
851 WARN("GetBindInfo failed: %08lx\n", hres);
852 IBinding_Release(BINDING(ret));
856 ret->bindf |= BINDF_FROMURLMON;
858 len = strlenW(url)+1;
860 if(len < sizeof(wszFile)/sizeof(WCHAR) || memcmp(wszFile, url, sizeof(wszFile)))
861 ret->bindf |= BINDF_NEEDFILE;
863 ret->url = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
864 memcpy(ret->url, url, len*sizeof(WCHAR));
866 ret->stream = create_stream(ret->protocol);
872 HRESULT start_binding(LPCWSTR url, IBindCtx *pbc, REFIID riid, void **ppv)
874 Binding *binding = NULL;
879 hres = Binding_Create(url, pbc, riid, &binding);
883 hres = IBindStatusCallback_OnStartBinding(binding->callback, 0, BINDING(binding));
885 WARN("OnStartBinding failed: %08lx\n", hres);
886 IBindStatusCallback_OnStopBinding(binding->callback, 0x800c0008, NULL);
887 IBinding_Release(BINDING(binding));
891 hres = IInternetProtocol_Start(binding->protocol, url, PROTSINK(binding),
892 BINDINF(binding), 0, 0);
893 IInternetProtocol_Terminate(binding->protocol, 0);
895 if(SUCCEEDED(hres)) {
896 IInternetProtocol_UnlockRequest(binding->protocol);
898 WARN("Start failed: %08lx\n", hres);
899 IBindStatusCallback_OnStopBinding(binding->callback, S_OK, NULL);
902 IStream_AddRef(STREAM(binding->stream));
903 *ppv = binding->stream;
905 IBinding_Release(BINDING(binding));