2 * Copyright 2005-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"
22 #include "wine/debug.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(urlmon
);
26 static WCHAR cbinding_contextW
[] = {'C','B','i','n','d','i','n','g',' ','C','o','n','t','e','x','t',0};
27 static WCHAR bscb_holderW
[] = { '_','B','S','C','B','_','H','o','l','d','e','r','_',0 };
29 typedef struct Binding Binding
;
31 struct _task_header_t
;
33 typedef void (*task_proc_t
)(Binding
*, struct _task_header_t
*);
35 typedef struct _task_header_t
{
37 struct _task_header_t
*next
;
41 const IUnknownVtbl
*lpUnknownVtbl
;
45 IInternetProtocol
*protocol
;
55 typedef struct _stgmed_obj_t stgmed_obj_t
;
58 void (*release
)(stgmed_obj_t
*);
59 HRESULT (*fill_stgmed
)(stgmed_obj_t
*,STGMEDIUM
*);
60 HRESULT (*get_result
)(stgmed_obj_t
*,DWORD
,void**);
63 struct _stgmed_obj_t
{
64 const stgmed_obj_vtbl
*vtbl
;
67 #define STGMEDUNK(x) ((IUnknown*) &(x)->lpUnknownVtbl)
75 #define BINDING_LOCKED 0x0001
76 #define BINDING_STOPPED 0x0002
77 #define BINDING_OBJAVAIL 0x0004
80 const IBindingVtbl
*lpBindingVtbl
;
81 const IInternetProtocolSinkVtbl
*lpIInternetProtocolSinkVtbl
;
82 const IInternetBindInfoVtbl
*lpInternetBindInfoVtbl
;
83 const IWinInetHttpInfoVtbl
*lpWinInetHttpInfoVtbl
;
84 const IServiceProviderVtbl
*lpServiceProviderVtbl
;
88 IBindStatusCallback
*callback
;
89 IInternetProtocol
*protocol
;
90 IServiceProvider
*service_provider
;
92 stgmed_buf_t
*stgmed_buf
;
93 stgmed_obj_t
*stgmed_obj
;
99 UINT clipboard_format
;
106 download_state_t download_state
;
112 CRITICAL_SECTION section
;
115 #define BINDING(x) ((IBinding*) &(x)->lpBindingVtbl)
116 #define BINDINF(x) ((IInternetBindInfo*) &(x)->lpInternetBindInfoVtbl)
117 #define INETINFO(x) ((IWinInetHttpInfo*) &(x)->lpWinInetHttpInfoVtbl)
118 #define SERVPROV(x) ((IServiceProvider*) &(x)->lpServiceProviderVtbl)
120 #define STREAM(x) ((IStream*) &(x)->lpStreamVtbl)
121 #define HTTPNEG2(x) ((IHttpNegotiate2*) &(x)->lpHttpNegotiate2Vtbl)
123 static void fill_stgmed_buffer(stgmed_buf_t
*buf
)
127 if(sizeof(buf
->buf
) == buf
->size
)
130 buf
->hres
= IInternetProtocol_Read(buf
->protocol
, buf
->buf
+buf
->size
,
131 sizeof(buf
->buf
)-buf
->size
, &read
);
137 static void dump_BINDINFO(BINDINFO
*bi
)
139 static const char * const BINDINFOF_str
[] = {
141 "BINDINFOF_URLENCODESTGMEDDATA",
142 "BINDINFOF_URLENCODEDEXTRAINFO"
145 static const char * const BINDVERB_str
[] = {
159 " %d, %08x, %d, %d\n"
165 bi
->cbSize
, debugstr_w(bi
->szExtraInfo
),
166 bi
->stgmedData
.tymed
, bi
->stgmedData
.u
.hGlobal
, bi
->stgmedData
.pUnkForRelease
,
167 bi
->grfBindInfoF
> BINDINFOF_URLENCODEDEXTRAINFO
168 ? "unknown" : BINDINFOF_str
[bi
->grfBindInfoF
],
169 bi
->dwBindVerb
> BINDVERB_CUSTOM
170 ? "unknown" : BINDVERB_str
[bi
->dwBindVerb
],
171 debugstr_w(bi
->szCustomVerb
),
172 bi
->cbstgmedData
, bi
->dwOptions
, bi
->dwOptionsFlags
, bi
->dwCodePage
,
173 bi
->securityAttributes
.nLength
,
174 bi
->securityAttributes
.lpSecurityDescriptor
,
175 bi
->securityAttributes
.bInheritHandle
,
176 debugstr_guid(&bi
->iid
),
177 bi
->pUnk
, bi
->dwReserved
181 static void mime_available(Binding
*This
, LPCWSTR mime
)
183 heap_free(This
->mime
);
184 This
->mime
= heap_strdupW(mime
);
186 if(!This
->mime
|| !This
->report_mime
)
189 IBindStatusCallback_OnProgress(This
->callback
, 0, 0, BINDSTATUS_MIMETYPEAVAILABLE
, This
->mime
);
191 This
->clipboard_format
= RegisterClipboardFormatW(This
->mime
);
194 static void stop_binding(Binding
*binding
, HRESULT hres
, LPCWSTR str
)
196 if(binding
->state
& BINDING_LOCKED
) {
197 IInternetProtocol_UnlockRequest(binding
->protocol
);
198 binding
->state
&= ~BINDING_LOCKED
;
201 if(!(binding
->state
& BINDING_STOPPED
)) {
202 binding
->state
|= BINDING_STOPPED
;
204 IBindStatusCallback_OnStopBinding(binding
->callback
, hres
, str
);
205 binding
->hres
= hres
;
209 static LPWSTR
get_mime_clsid(LPCWSTR mime
, CLSID
*clsid
)
211 LPWSTR key_name
, ret
;
212 DWORD res
, type
, size
;
217 static const WCHAR mime_keyW
[] =
218 {'M','I','M','E','\\','D','a','t','a','b','a','s','e','\\',
219 'C','o','n','t','e','n','t',' ','T','y','p','e','\\'};
220 static const WCHAR clsidW
[] = {'C','L','S','I','D',0};
222 len
= strlenW(mime
)+1;
223 key_name
= heap_alloc(sizeof(mime_keyW
) + len
*sizeof(WCHAR
));
224 memcpy(key_name
, mime_keyW
, sizeof(mime_keyW
));
225 strcpyW(key_name
+ sizeof(mime_keyW
)/sizeof(WCHAR
), mime
);
227 res
= RegOpenKeyW(HKEY_CLASSES_ROOT
, key_name
, &hkey
);
229 if(res
!= ERROR_SUCCESS
) {
230 WARN("Could not open MIME key: %x\n", res
);
234 size
= 50*sizeof(WCHAR
);
235 ret
= heap_alloc(size
);
236 res
= RegQueryValueExW(hkey
, clsidW
, NULL
, &type
, (LPBYTE
)ret
, &size
);
238 if(res
!= ERROR_SUCCESS
) {
239 WARN("Could not get CLSID: %08x\n", res
);
244 hres
= CLSIDFromString(ret
, clsid
);
246 WARN("Could not parse CLSID: %08x\n", hres
);
254 static void load_doc_mon(Binding
*binding
, IPersistMoniker
*persist
)
259 hres
= CreateAsyncBindCtxEx(binding
->bctx
, 0, NULL
, NULL
, &bctx
, 0);
261 WARN("CreateAsyncBindCtxEx failed: %08x\n", hres
);
265 IBindCtx_RevokeObjectParam(bctx
, bscb_holderW
);
266 IBindCtx_RegisterObjectParam(bctx
, cbinding_contextW
, (IUnknown
*)BINDING(binding
));
268 hres
= IPersistMoniker_Load(persist
, binding
->download_state
== END_DOWNLOAD
, binding
->mon
, bctx
, 0x12);
269 IBindCtx_RevokeObjectParam(bctx
, cbinding_contextW
);
270 IBindCtx_Release(bctx
);
272 FIXME("Load failed: %08x\n", hres
);
275 static HRESULT
create_mime_object(Binding
*binding
, const CLSID
*clsid
, LPCWSTR clsid_str
)
277 IPersistMoniker
*persist
;
280 hres
= CoCreateInstance(clsid
, NULL
, CLSCTX_INPROC_SERVER
|CLSCTX_INPROC_HANDLER
,
281 &binding
->iid
, (void**)&binding
->obj
);
283 WARN("CoCreateInstance failed: %08x\n", hres
);
284 return INET_E_CANNOT_INSTANTIATE_OBJECT
;
287 binding
->state
|= BINDING_OBJAVAIL
;
289 hres
= IUnknown_QueryInterface(binding
->obj
, &IID_IPersistMoniker
, (void**)&persist
);
290 if(SUCCEEDED(hres
)) {
293 hres
= IPersistMoniker_QueryInterface(persist
, &IID_IMonikerProp
, (void**)&prop
);
294 if(SUCCEEDED(hres
)) {
295 IMonikerProp_PutProperty(prop
, MIMETYPEPROP
, binding
->mime
);
296 IMonikerProp_PutProperty(prop
, CLASSIDPROP
, clsid_str
);
297 IMonikerProp_Release(prop
);
300 load_doc_mon(binding
, persist
);
302 IPersistMoniker_Release(persist
);
304 FIXME("Could not get IPersistMoniker: %08x\n", hres
);
305 /* FIXME: Try query IPersistFile */
308 IBindStatusCallback_OnObjectAvailable(binding
->callback
, &binding
->iid
, binding
->obj
);
313 static void create_object(Binding
*binding
)
320 FIXME("MIME not available\n");
324 if(!(clsid_str
= get_mime_clsid(binding
->mime
, &clsid
))) {
325 FIXME("Could not find object for MIME %s\n", debugstr_w(binding
->mime
));
329 IBindStatusCallback_OnProgress(binding
->callback
, 0, 0, BINDSTATUS_CLASSIDAVAILABLE
, clsid_str
);
330 IBindStatusCallback_OnProgress(binding
->callback
, 0, 0, BINDSTATUS_BEGINSYNCOPERATION
, NULL
);
332 hres
= create_mime_object(binding
, &clsid
, clsid_str
);
333 heap_free(clsid_str
);
335 IBindStatusCallback_OnProgress(binding
->callback
, 0, 0, BINDSTATUS_ENDSYNCOPERATION
, NULL
);
337 stop_binding(binding
, hres
, NULL
);
339 IInternetProtocol_Terminate(binding
->protocol
, 0);
342 #define STGMEDUNK_THIS(iface) DEFINE_THIS(stgmed_buf_t, Unknown, iface)
344 static HRESULT WINAPI
StgMedUnk_QueryInterface(IUnknown
*iface
, REFIID riid
, void **ppv
)
346 stgmed_buf_t
*This
= STGMEDUNK_THIS(iface
);
350 if(IsEqualGUID(riid
, &IID_IUnknown
)) {
351 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
353 *ppv
= STGMEDUNK(This
);
354 IUnknown_AddRef(STGMEDUNK(This
));
358 TRACE("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
359 return E_NOINTERFACE
;
362 static ULONG WINAPI
StgMedUnk_AddRef(IUnknown
*iface
)
364 stgmed_buf_t
*This
= STGMEDUNK_THIS(iface
);
365 LONG ref
= InterlockedIncrement(&This
->ref
);
367 TRACE("(%p) ref=%d\n", This
, ref
);
372 static ULONG WINAPI
StgMedUnk_Release(IUnknown
*iface
)
374 stgmed_buf_t
*This
= STGMEDUNK_THIS(iface
);
375 LONG ref
= InterlockedDecrement(&This
->ref
);
377 TRACE("(%p) ref=%d\n", This
, ref
);
380 IInternetProtocol_Release(This
->protocol
);
381 heap_free(This
->cache_file
);
384 URLMON_UnlockModule();
390 #undef STGMEDUNK_THIS
392 static const IUnknownVtbl StgMedUnkVtbl
= {
393 StgMedUnk_QueryInterface
,
398 static stgmed_buf_t
*create_stgmed_buf(IInternetProtocol
*protocol
)
400 stgmed_buf_t
*ret
= heap_alloc(sizeof(*ret
));
402 ret
->lpUnknownVtbl
= &StgMedUnkVtbl
;
407 ret
->cache_file
= NULL
;
409 IInternetProtocol_AddRef(protocol
);
410 ret
->protocol
= protocol
;
418 stgmed_obj_t stgmed_obj
;
419 const IStreamVtbl
*lpStreamVtbl
;
426 #define STREAM_THIS(iface) DEFINE_THIS(ProtocolStream, Stream, iface)
428 static HRESULT WINAPI
ProtocolStream_QueryInterface(IStream
*iface
,
429 REFIID riid
, void **ppv
)
431 ProtocolStream
*This
= STREAM_THIS(iface
);
435 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
436 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
438 }else if(IsEqualGUID(&IID_ISequentialStream
, riid
)) {
439 TRACE("(%p)->(IID_ISequentialStream %p)\n", This
, ppv
);
441 }else if(IsEqualGUID(&IID_IStream
, riid
)) {
442 TRACE("(%p)->(IID_IStream %p)\n", This
, ppv
);
447 IStream_AddRef(STREAM(This
));
451 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
452 return E_NOINTERFACE
;
455 static ULONG WINAPI
ProtocolStream_AddRef(IStream
*iface
)
457 ProtocolStream
*This
= STREAM_THIS(iface
);
458 LONG ref
= InterlockedIncrement(&This
->ref
);
460 TRACE("(%p) ref=%d\n", This
, ref
);
465 static ULONG WINAPI
ProtocolStream_Release(IStream
*iface
)
467 ProtocolStream
*This
= STREAM_THIS(iface
);
468 LONG ref
= InterlockedDecrement(&This
->ref
);
470 TRACE("(%p) ref=%d\n", This
, ref
);
473 IUnknown_Release(STGMEDUNK(This
->buf
));
476 URLMON_UnlockModule();
482 static HRESULT WINAPI
ProtocolStream_Read(IStream
*iface
, void *pv
,
483 ULONG cb
, ULONG
*pcbRead
)
485 ProtocolStream
*This
= STREAM_THIS(iface
);
486 DWORD read
= 0, pread
= 0;
489 TRACE("(%p)->(%p %d %p)\n", This
, pv
, cb
, pcbRead
);
491 if(This
->buf
->size
) {
494 if(read
> This
->buf
->size
)
495 read
= This
->buf
->size
;
497 memcpy(pv
, This
->buf
->buf
, read
);
499 if(read
< This
->buf
->size
)
500 memmove(This
->buf
->buf
, This
->buf
->buf
+read
, This
->buf
->size
-read
);
501 This
->buf
->size
-= read
;
510 hres
= This
->buf
->hres
= IInternetProtocol_Read(This
->buf
->protocol
, (PBYTE
)pv
+read
, cb
-read
, &pread
);
512 *pcbRead
= read
+ pread
;
514 if(hres
== E_PENDING
)
516 else if(FAILED(hres
))
517 FIXME("Read failed: %08x\n", hres
);
519 return read
|| pread
? S_OK
: S_FALSE
;
522 static HRESULT WINAPI
ProtocolStream_Write(IStream
*iface
, const void *pv
,
523 ULONG cb
, ULONG
*pcbWritten
)
525 ProtocolStream
*This
= STREAM_THIS(iface
);
527 TRACE("(%p)->(%p %d %p)\n", This
, pv
, cb
, pcbWritten
);
529 return STG_E_ACCESSDENIED
;
532 static HRESULT WINAPI
ProtocolStream_Seek(IStream
*iface
, LARGE_INTEGER dlibMove
,
533 DWORD dwOrigin
, ULARGE_INTEGER
*plibNewPosition
)
535 ProtocolStream
*This
= STREAM_THIS(iface
);
536 FIXME("(%p)->(%d %08x %p)\n", This
, dlibMove
.u
.LowPart
, dwOrigin
, plibNewPosition
);
540 static HRESULT WINAPI
ProtocolStream_SetSize(IStream
*iface
, ULARGE_INTEGER libNewSize
)
542 ProtocolStream
*This
= STREAM_THIS(iface
);
543 FIXME("(%p)->(%d)\n", This
, libNewSize
.u
.LowPart
);
547 static HRESULT WINAPI
ProtocolStream_CopyTo(IStream
*iface
, IStream
*pstm
,
548 ULARGE_INTEGER cb
, ULARGE_INTEGER
*pcbRead
, ULARGE_INTEGER
*pcbWritten
)
550 ProtocolStream
*This
= STREAM_THIS(iface
);
551 FIXME("(%p)->(%p %d %p %p)\n", This
, pstm
, cb
.u
.LowPart
, pcbRead
, pcbWritten
);
555 static HRESULT WINAPI
ProtocolStream_Commit(IStream
*iface
, DWORD grfCommitFlags
)
557 ProtocolStream
*This
= STREAM_THIS(iface
);
559 TRACE("(%p)->(%08x)\n", This
, grfCommitFlags
);
564 static HRESULT WINAPI
ProtocolStream_Revert(IStream
*iface
)
566 ProtocolStream
*This
= STREAM_THIS(iface
);
568 TRACE("(%p)\n", This
);
573 static HRESULT WINAPI
ProtocolStream_LockRegion(IStream
*iface
, ULARGE_INTEGER libOffset
,
574 ULARGE_INTEGER cb
, DWORD dwLockType
)
576 ProtocolStream
*This
= STREAM_THIS(iface
);
577 FIXME("(%p)->(%d %d %d)\n", This
, libOffset
.u
.LowPart
, cb
.u
.LowPart
, dwLockType
);
581 static HRESULT WINAPI
ProtocolStream_UnlockRegion(IStream
*iface
,
582 ULARGE_INTEGER libOffset
, ULARGE_INTEGER cb
, DWORD dwLockType
)
584 ProtocolStream
*This
= STREAM_THIS(iface
);
585 FIXME("(%p)->(%d %d %d)\n", This
, libOffset
.u
.LowPart
, cb
.u
.LowPart
, dwLockType
);
589 static HRESULT WINAPI
ProtocolStream_Stat(IStream
*iface
, STATSTG
*pstatstg
,
592 ProtocolStream
*This
= STREAM_THIS(iface
);
593 FIXME("(%p)->(%p %08x)\n", This
, pstatstg
, dwStatFlag
);
597 static HRESULT WINAPI
ProtocolStream_Clone(IStream
*iface
, IStream
**ppstm
)
599 ProtocolStream
*This
= STREAM_THIS(iface
);
600 FIXME("(%p)->(%p)\n", This
, ppstm
);
606 static const IStreamVtbl ProtocolStreamVtbl
= {
607 ProtocolStream_QueryInterface
,
608 ProtocolStream_AddRef
,
609 ProtocolStream_Release
,
611 ProtocolStream_Write
,
613 ProtocolStream_SetSize
,
614 ProtocolStream_CopyTo
,
615 ProtocolStream_Commit
,
616 ProtocolStream_Revert
,
617 ProtocolStream_LockRegion
,
618 ProtocolStream_UnlockRegion
,
623 static void stgmed_stream_release(stgmed_obj_t
*obj
)
625 ProtocolStream
*stream
= (ProtocolStream
*)obj
;
626 IStream_Release(STREAM(stream
));
629 static HRESULT
stgmed_stream_fill_stgmed(stgmed_obj_t
*obj
, STGMEDIUM
*stgmed
)
631 ProtocolStream
*stream
= (ProtocolStream
*)obj
;
633 stgmed
->tymed
= TYMED_ISTREAM
;
634 stgmed
->u
.pstm
= STREAM(stream
);
635 stgmed
->pUnkForRelease
= STGMEDUNK(stream
->buf
);
640 static HRESULT
stgmed_stream_get_result(stgmed_obj_t
*obj
, DWORD bindf
, void **result
)
642 ProtocolStream
*stream
= (ProtocolStream
*)obj
;
644 IStream_AddRef(STREAM(stream
));
645 *result
= STREAM(stream
);
649 static const stgmed_obj_vtbl stgmed_stream_vtbl
= {
650 stgmed_stream_release
,
651 stgmed_stream_fill_stgmed
,
652 stgmed_stream_get_result
656 stgmed_obj_t stgmed_obj
;
660 static stgmed_obj_t
*create_stgmed_stream(stgmed_buf_t
*buf
)
662 ProtocolStream
*ret
= heap_alloc(sizeof(ProtocolStream
));
664 ret
->stgmed_obj
.vtbl
= &stgmed_stream_vtbl
;
665 ret
->lpStreamVtbl
= &ProtocolStreamVtbl
;
668 IUnknown_AddRef(STGMEDUNK(buf
));
673 return &ret
->stgmed_obj
;
676 static void stgmed_file_release(stgmed_obj_t
*obj
)
678 stgmed_file_obj_t
*file_obj
= (stgmed_file_obj_t
*)obj
;
680 IUnknown_Release(STGMEDUNK(file_obj
->buf
));
684 static HRESULT
stgmed_file_fill_stgmed(stgmed_obj_t
*obj
, STGMEDIUM
*stgmed
)
686 stgmed_file_obj_t
*file_obj
= (stgmed_file_obj_t
*)obj
;
688 if(!file_obj
->buf
->cache_file
) {
689 WARN("cache_file not set\n");
690 return INET_E_DATA_NOT_AVAILABLE
;
693 fill_stgmed_buffer(file_obj
->buf
);
694 if(file_obj
->buf
->size
== sizeof(file_obj
->buf
->buf
)) {
700 hres
= IInternetProtocol_Read(file_obj
->buf
->protocol
, buf
, sizeof(buf
), &read
);
701 }while(hres
== S_OK
);
704 stgmed
->tymed
= TYMED_FILE
;
705 stgmed
->u
.lpszFileName
= file_obj
->buf
->cache_file
;
706 stgmed
->pUnkForRelease
= STGMEDUNK(file_obj
->buf
);
711 static HRESULT
stgmed_file_get_result(stgmed_obj_t
*obj
, DWORD bindf
, void **result
)
713 return bindf
& BINDF_ASYNCHRONOUS
? MK_S_ASYNCHRONOUS
: S_OK
;
716 static const stgmed_obj_vtbl stgmed_file_vtbl
= {
718 stgmed_file_fill_stgmed
,
719 stgmed_file_get_result
722 static stgmed_obj_t
*create_stgmed_file(stgmed_buf_t
*buf
)
724 stgmed_file_obj_t
*ret
= heap_alloc(sizeof(*ret
));
726 ret
->stgmed_obj
.vtbl
= &stgmed_file_vtbl
;
728 IUnknown_AddRef(STGMEDUNK(buf
));
731 return &ret
->stgmed_obj
;
734 #define BINDING_THIS(iface) DEFINE_THIS(Binding, Binding, iface)
736 static HRESULT WINAPI
Binding_QueryInterface(IBinding
*iface
, REFIID riid
, void **ppv
)
738 Binding
*This
= BINDING_THIS(iface
);
742 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
743 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
744 *ppv
= BINDING(This
);
745 }else if(IsEqualGUID(&IID_IBinding
, riid
)) {
746 TRACE("(%p)->(IID_IBinding %p)\n", This
, ppv
);
747 *ppv
= BINDING(This
);
748 }else if(IsEqualGUID(&IID_IInternetProtocolSink
, riid
)) {
749 TRACE("(%p)->(IID_IInternetProtocolSink %p)\n", This
, ppv
);
750 *ppv
= PROTSINK(This
);
751 }else if(IsEqualGUID(&IID_IInternetBindInfo
, riid
)) {
752 TRACE("(%p)->(IID_IInternetBindInfo %p)\n", This
, ppv
);
753 *ppv
= BINDINF(This
);
754 }else if(IsEqualGUID(&IID_IServiceProvider
, riid
)) {
755 TRACE("(%p)->(IID_IServiceProvider %p)\n", This
, ppv
);
756 *ppv
= SERVPROV(This
);
757 }else if(IsEqualGUID(&IID_IWinInetInfo
, riid
)) {
758 TRACE("(%p)->(IID_IWinInetInfo %p)\n", This
, ppv
);
760 /* NOTE: This violidates COM rules, but tests prove that we should do it */
761 if(!get_wininet_info(This
->protocol
))
762 return E_NOINTERFACE
;
764 *ppv
= INETINFO(This
);
765 }else if(IsEqualGUID(&IID_IWinInetHttpInfo
, riid
)) {
766 IWinInetHttpInfo
*http_info
;
770 TRACE("(%p)->(IID_IWinInetHttpInfo %p)\n", This
, ppv
);
772 info
= get_wininet_info(This
->protocol
);
774 return E_NOINTERFACE
;
776 hres
= IWinInetInfo_QueryInterface(info
, &IID_IWinInetHttpInfo
, (void**)&http_info
);
778 return E_NOINTERFACE
;
780 IWinInetHttpInfo_Release(http_info
);
781 *ppv
= INETINFO(This
);
785 IBinding_AddRef(BINDING(This
));
789 WARN("Unsupported interface %s\n", debugstr_guid(riid
));
790 return E_NOINTERFACE
;
793 static ULONG WINAPI
Binding_AddRef(IBinding
*iface
)
795 Binding
*This
= BINDING_THIS(iface
);
796 LONG ref
= InterlockedIncrement(&This
->ref
);
798 TRACE("(%p) ref=%d\n", This
, ref
);
803 static ULONG WINAPI
Binding_Release(IBinding
*iface
)
805 Binding
*This
= BINDING_THIS(iface
);
806 LONG ref
= InterlockedDecrement(&This
->ref
);
808 TRACE("(%p) ref=%d\n", This
, ref
);
812 release_notif_hwnd(This
->notif_hwnd
);
814 IMoniker_Release(This
->mon
);
816 IBindStatusCallback_Release(This
->callback
);
818 IInternetProtocol_Release(This
->protocol
);
819 if(This
->service_provider
)
820 IServiceProvider_Release(This
->service_provider
);
822 IUnknown_Release(STGMEDUNK(This
->stgmed_buf
));
824 This
->stgmed_obj
->vtbl
->release(This
->stgmed_obj
);
826 IUnknown_Release(This
->obj
);
828 IBindCtx_Release(This
->bctx
);
830 ReleaseBindInfo(&This
->bindinfo
);
831 This
->section
.DebugInfo
->Spare
[0] = 0;
832 DeleteCriticalSection(&This
->section
);
833 heap_free(This
->mime
);
834 heap_free(This
->redirect_url
);
835 heap_free(This
->url
);
839 URLMON_UnlockModule();
845 static HRESULT WINAPI
Binding_Abort(IBinding
*iface
)
847 Binding
*This
= BINDING_THIS(iface
);
848 FIXME("(%p)\n", This
);
852 static HRESULT WINAPI
Binding_Suspend(IBinding
*iface
)
854 Binding
*This
= BINDING_THIS(iface
);
855 FIXME("(%p)\n", This
);
859 static HRESULT WINAPI
Binding_Resume(IBinding
*iface
)
861 Binding
*This
= BINDING_THIS(iface
);
862 FIXME("(%p)\n", This
);
866 static HRESULT WINAPI
Binding_SetPriority(IBinding
*iface
, LONG nPriority
)
868 Binding
*This
= BINDING_THIS(iface
);
869 FIXME("(%p)->(%d)\n", This
, nPriority
);
873 static HRESULT WINAPI
Binding_GetPriority(IBinding
*iface
, LONG
*pnPriority
)
875 Binding
*This
= BINDING_THIS(iface
);
876 FIXME("(%p)->(%p)\n", This
, pnPriority
);
880 static HRESULT WINAPI
Binding_GetBindResult(IBinding
*iface
, CLSID
*pclsidProtocol
,
881 DWORD
*pdwResult
, LPOLESTR
*pszResult
, DWORD
*pdwReserved
)
883 Binding
*This
= BINDING_THIS(iface
);
884 FIXME("(%p)->(%p %p %p %p)\n", This
, pclsidProtocol
, pdwResult
, pszResult
, pdwReserved
);
888 static Binding
*get_bctx_binding(IBindCtx
*bctx
)
894 hres
= IBindCtx_GetObjectParam(bctx
, cbinding_contextW
, &unk
);
898 hres
= IUnknown_QueryInterface(unk
, &IID_IBinding
, (void*)&binding
);
899 IUnknown_Release(unk
);
904 return BINDING_THIS(binding
);
909 static const IBindingVtbl BindingVtbl
= {
910 Binding_QueryInterface
,
918 Binding_GetBindResult
921 #define PROTSINK_THIS(iface) DEFINE_THIS(Binding, IInternetProtocolSink, iface)
923 static HRESULT WINAPI
InternetProtocolSink_QueryInterface(IInternetProtocolSink
*iface
,
924 REFIID riid
, void **ppv
)
926 Binding
*This
= PROTSINK_THIS(iface
);
927 return IBinding_QueryInterface(BINDING(This
), riid
, ppv
);
930 static ULONG WINAPI
InternetProtocolSink_AddRef(IInternetProtocolSink
*iface
)
932 Binding
*This
= PROTSINK_THIS(iface
);
933 return IBinding_AddRef(BINDING(This
));
936 static ULONG WINAPI
InternetProtocolSink_Release(IInternetProtocolSink
*iface
)
938 Binding
*This
= PROTSINK_THIS(iface
);
939 return IBinding_Release(BINDING(This
));
942 static HRESULT WINAPI
InternetProtocolSink_Switch(IInternetProtocolSink
*iface
,
943 PROTOCOLDATA
*pProtocolData
)
945 Binding
*This
= PROTSINK_THIS(iface
);
947 WARN("(%p)->(%p)\n", This
, pProtocolData
);
952 static void on_progress(Binding
*This
, ULONG progress
, ULONG progress_max
,
953 ULONG status_code
, LPCWSTR status_text
)
955 IBindStatusCallback_OnProgress(This
->callback
, progress
, progress_max
,
956 status_code
, status_text
);
959 static HRESULT WINAPI
InternetProtocolSink_ReportProgress(IInternetProtocolSink
*iface
,
960 ULONG ulStatusCode
, LPCWSTR szStatusText
)
962 Binding
*This
= PROTSINK_THIS(iface
);
964 TRACE("(%p)->(%u %s)\n", This
, ulStatusCode
, debugstr_w(szStatusText
));
966 switch(ulStatusCode
) {
967 case BINDSTATUS_FINDINGRESOURCE
:
968 on_progress(This
, 0, 0, BINDSTATUS_FINDINGRESOURCE
, szStatusText
);
970 case BINDSTATUS_CONNECTING
:
971 on_progress(This
, 0, 0, BINDSTATUS_CONNECTING
, szStatusText
);
973 case BINDSTATUS_REDIRECTING
:
974 heap_free(This
->redirect_url
);
975 This
->redirect_url
= heap_strdupW(szStatusText
);
976 on_progress(This
, 0, 0, BINDSTATUS_REDIRECTING
, szStatusText
);
978 case BINDSTATUS_BEGINDOWNLOADDATA
:
979 fill_stgmed_buffer(This
->stgmed_buf
);
981 case BINDSTATUS_SENDINGREQUEST
:
982 on_progress(This
, 0, 0, BINDSTATUS_SENDINGREQUEST
, szStatusText
);
984 case BINDSTATUS_PROTOCOLCLASSID
:
986 case BINDSTATUS_MIMETYPEAVAILABLE
:
987 case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE
:
988 mime_available(This
, szStatusText
);
990 case BINDSTATUS_CACHEFILENAMEAVAILABLE
:
991 heap_free(This
->stgmed_buf
->cache_file
);
992 This
->stgmed_buf
->cache_file
= heap_strdupW(szStatusText
);
994 case BINDSTATUS_DECODING
:
995 IBindStatusCallback_OnProgress(This
->callback
, 0, 0, BINDSTATUS_DECODING
, szStatusText
);
997 case BINDSTATUS_LOADINGMIMEHANDLER
:
998 on_progress(This
, 0, 0, BINDSTATUS_LOADINGMIMEHANDLER
, szStatusText
);
1000 case BINDSTATUS_DIRECTBIND
: /* FIXME: Handle BINDSTATUS_DIRECTBIND in BindProtocol */
1001 This
->report_mime
= FALSE
;
1003 case BINDSTATUS_ACCEPTRANGES
:
1006 FIXME("Unhandled status code %d\n", ulStatusCode
);
1013 static void report_data(Binding
*This
, DWORD bscf
, ULONG progress
, ULONG progress_max
)
1015 FORMATETC formatetc
= {0, NULL
, 1, -1, TYMED_ISTREAM
};
1016 BOOL sent_begindownloaddata
= FALSE
;
1018 TRACE("(%p)->(%d %u %u)\n", This
, bscf
, progress
, progress_max
);
1020 if(This
->download_state
== END_DOWNLOAD
|| (This
->state
& BINDING_STOPPED
))
1023 if(This
->download_state
== BEFORE_DOWNLOAD
) {
1024 fill_stgmed_buffer(This
->stgmed_buf
);
1026 This
->download_state
= DOWNLOADING
;
1027 sent_begindownloaddata
= TRUE
;
1028 IBindStatusCallback_OnProgress(This
->callback
, progress
, progress_max
,
1029 BINDSTATUS_BEGINDOWNLOADDATA
, This
->url
);
1031 if(This
->stgmed_buf
->cache_file
)
1032 IBindStatusCallback_OnProgress(This
->callback
, progress
, progress_max
,
1033 BINDSTATUS_CACHEFILENAMEAVAILABLE
, This
->stgmed_buf
->cache_file
);
1036 if(This
->stgmed_buf
->hres
== S_FALSE
|| (bscf
& BSCF_LASTDATANOTIFICATION
)) {
1037 This
->download_state
= END_DOWNLOAD
;
1038 IBindStatusCallback_OnProgress(This
->callback
, progress
, progress_max
,
1039 BINDSTATUS_ENDDOWNLOADDATA
, This
->url
);
1040 }else if(!sent_begindownloaddata
) {
1041 IBindStatusCallback_OnProgress(This
->callback
, progress
, progress_max
,
1042 BINDSTATUS_DOWNLOADINGDATA
, This
->url
);
1045 if(This
->to_object
) {
1046 if(!(This
->state
& BINDING_OBJAVAIL
))
1047 create_object(This
);
1052 if(!(This
->state
& BINDING_LOCKED
)) {
1053 HRESULT hres
= IInternetProtocol_LockRequest(This
->protocol
, 0);
1055 This
->state
|= BINDING_LOCKED
;
1058 hres
= This
->stgmed_obj
->vtbl
->fill_stgmed(This
->stgmed_obj
, &stgmed
);
1060 stop_binding(This
, hres
, NULL
);
1064 formatetc
.tymed
= stgmed
.tymed
;
1065 formatetc
.cfFormat
= This
->clipboard_format
;
1067 IBindStatusCallback_OnDataAvailable(This
->callback
, bscf
, progress
,
1068 &formatetc
, &stgmed
);
1070 if(This
->download_state
== END_DOWNLOAD
)
1071 stop_binding(This
, S_OK
, NULL
);
1075 static HRESULT WINAPI
InternetProtocolSink_ReportData(IInternetProtocolSink
*iface
,
1076 DWORD grfBSCF
, ULONG ulProgress
, ULONG ulProgressMax
)
1078 Binding
*This
= PROTSINK_THIS(iface
);
1080 TRACE("(%p)->(%d %u %u)\n", This
, grfBSCF
, ulProgress
, ulProgressMax
);
1082 report_data(This
, grfBSCF
, ulProgress
, ulProgressMax
);
1086 static HRESULT WINAPI
InternetProtocolSink_ReportResult(IInternetProtocolSink
*iface
,
1087 HRESULT hrResult
, DWORD dwError
, LPCWSTR szResult
)
1089 Binding
*This
= PROTSINK_THIS(iface
);
1091 TRACE("(%p)->(%08x %d %s)\n", This
, hrResult
, dwError
, debugstr_w(szResult
));
1093 stop_binding(This
, hrResult
, szResult
);
1094 IInternetProtocol_Terminate(This
->protocol
, 0);
1098 #undef PROTSINK_THIS
1100 static const IInternetProtocolSinkVtbl InternetProtocolSinkVtbl
= {
1101 InternetProtocolSink_QueryInterface
,
1102 InternetProtocolSink_AddRef
,
1103 InternetProtocolSink_Release
,
1104 InternetProtocolSink_Switch
,
1105 InternetProtocolSink_ReportProgress
,
1106 InternetProtocolSink_ReportData
,
1107 InternetProtocolSink_ReportResult
1110 #define BINDINF_THIS(iface) DEFINE_THIS(Binding, InternetBindInfo, iface)
1112 static HRESULT WINAPI
InternetBindInfo_QueryInterface(IInternetBindInfo
*iface
,
1113 REFIID riid
, void **ppv
)
1115 Binding
*This
= BINDINF_THIS(iface
);
1116 return IBinding_QueryInterface(BINDING(This
), riid
, ppv
);
1119 static ULONG WINAPI
InternetBindInfo_AddRef(IInternetBindInfo
*iface
)
1121 Binding
*This
= BINDINF_THIS(iface
);
1122 return IBinding_AddRef(BINDING(This
));
1125 static ULONG WINAPI
InternetBindInfo_Release(IInternetBindInfo
*iface
)
1127 Binding
*This
= BINDINF_THIS(iface
);
1128 return IBinding_Release(BINDING(This
));
1131 static HRESULT WINAPI
InternetBindInfo_GetBindInfo(IInternetBindInfo
*iface
,
1132 DWORD
*grfBINDF
, BINDINFO
*pbindinfo
)
1134 Binding
*This
= BINDINF_THIS(iface
);
1136 TRACE("(%p)->(%p %p)\n", This
, grfBINDF
, pbindinfo
);
1138 *grfBINDF
= This
->bindf
;
1140 *pbindinfo
= This
->bindinfo
;
1142 if(pbindinfo
->szExtraInfo
|| pbindinfo
->szCustomVerb
)
1143 FIXME("copy strings\n");
1145 if(pbindinfo
->stgmedData
.pUnkForRelease
)
1146 IUnknown_AddRef(pbindinfo
->stgmedData
.pUnkForRelease
);
1149 IUnknown_AddRef(pbindinfo
->pUnk
);
1154 static HRESULT WINAPI
InternetBindInfo_GetBindString(IInternetBindInfo
*iface
,
1155 ULONG ulStringType
, LPOLESTR
*ppwzStr
, ULONG cEl
, ULONG
*pcElFetched
)
1157 Binding
*This
= BINDINF_THIS(iface
);
1159 TRACE("(%p)->(%d %p %d %p)\n", This
, ulStringType
, ppwzStr
, cEl
, pcElFetched
);
1161 switch(ulStringType
) {
1162 case BINDSTRING_ACCEPT_MIMES
: {
1163 static const WCHAR wszMimes
[] = {'*','/','*',0};
1165 if(!ppwzStr
|| !pcElFetched
)
1166 return E_INVALIDARG
;
1168 ppwzStr
[0] = CoTaskMemAlloc(sizeof(wszMimes
));
1169 memcpy(ppwzStr
[0], wszMimes
, sizeof(wszMimes
));
1173 case BINDSTRING_USER_AGENT
: {
1174 IInternetBindInfo
*bindinfo
= NULL
;
1177 hres
= IBindStatusCallback_QueryInterface(This
->callback
, &IID_IInternetBindInfo
,
1182 hres
= IInternetBindInfo_GetBindString(bindinfo
, ulStringType
, ppwzStr
,
1184 IInternetBindInfo_Release(bindinfo
);
1188 case BINDSTRING_URL
: {
1189 DWORD size
= (strlenW(This
->url
)+1) * sizeof(WCHAR
);
1191 if(!ppwzStr
|| !pcElFetched
)
1192 return E_INVALIDARG
;
1194 *ppwzStr
= CoTaskMemAlloc(size
);
1195 memcpy(*ppwzStr
, This
->url
, size
);
1201 FIXME("not supported string type %d\n", ulStringType
);
1207 static const IInternetBindInfoVtbl InternetBindInfoVtbl
= {
1208 InternetBindInfo_QueryInterface
,
1209 InternetBindInfo_AddRef
,
1210 InternetBindInfo_Release
,
1211 InternetBindInfo_GetBindInfo
,
1212 InternetBindInfo_GetBindString
1215 #define INETINFO_THIS(iface) DEFINE_THIS(Binding, WinInetHttpInfo, iface)
1217 static HRESULT WINAPI
WinInetHttpInfo_QueryInterface(IWinInetHttpInfo
*iface
, REFIID riid
, void **ppv
)
1219 Binding
*This
= INETINFO_THIS(iface
);
1220 return IBinding_QueryInterface(BINDING(This
), riid
, ppv
);
1223 static ULONG WINAPI
WinInetHttpInfo_AddRef(IWinInetHttpInfo
*iface
)
1225 Binding
*This
= INETINFO_THIS(iface
);
1226 return IBinding_AddRef(BINDING(This
));
1229 static ULONG WINAPI
WinInetHttpInfo_Release(IWinInetHttpInfo
*iface
)
1231 Binding
*This
= INETINFO_THIS(iface
);
1232 return IBinding_Release(BINDING(This
));
1235 static HRESULT WINAPI
WinInetHttpInfo_QueryOption(IWinInetHttpInfo
*iface
, DWORD dwOption
,
1236 void *pBuffer
, DWORD
*pcbBuffer
)
1238 Binding
*This
= INETINFO_THIS(iface
);
1239 FIXME("(%p)->(%x %p %p)\n", This
, dwOption
, pBuffer
, pcbBuffer
);
1243 static HRESULT WINAPI
WinInetHttpInfo_QueryInfo(IWinInetHttpInfo
*iface
, DWORD dwOption
,
1244 void *pBuffer
, DWORD
*pcbBuffer
, DWORD
*pdwFlags
, DWORD
*pdwReserved
)
1246 Binding
*This
= INETINFO_THIS(iface
);
1247 FIXME("(%p)->(%x %p %p %p %p)\n", This
, dwOption
, pBuffer
, pcbBuffer
, pdwFlags
, pdwReserved
);
1251 #undef INETINFO_THIS
1253 static const IWinInetHttpInfoVtbl WinInetHttpInfoVtbl
= {
1254 WinInetHttpInfo_QueryInterface
,
1255 WinInetHttpInfo_AddRef
,
1256 WinInetHttpInfo_Release
,
1257 WinInetHttpInfo_QueryOption
,
1258 WinInetHttpInfo_QueryInfo
1261 #define SERVPROV_THIS(iface) DEFINE_THIS(Binding, ServiceProvider, iface)
1263 static HRESULT WINAPI
ServiceProvider_QueryInterface(IServiceProvider
*iface
,
1264 REFIID riid
, void **ppv
)
1266 Binding
*This
= SERVPROV_THIS(iface
);
1267 return IBinding_QueryInterface(BINDING(This
), riid
, ppv
);
1270 static ULONG WINAPI
ServiceProvider_AddRef(IServiceProvider
*iface
)
1272 Binding
*This
= SERVPROV_THIS(iface
);
1273 return IBinding_AddRef(BINDING(This
));
1276 static ULONG WINAPI
ServiceProvider_Release(IServiceProvider
*iface
)
1278 Binding
*This
= SERVPROV_THIS(iface
);
1279 return IBinding_Release(BINDING(This
));
1282 static HRESULT WINAPI
ServiceProvider_QueryService(IServiceProvider
*iface
,
1283 REFGUID guidService
, REFIID riid
, void **ppv
)
1285 Binding
*This
= SERVPROV_THIS(iface
);
1288 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_guid(guidService
), debugstr_guid(riid
), ppv
);
1290 if(This
->service_provider
) {
1291 hres
= IServiceProvider_QueryService(This
->service_provider
, guidService
,
1297 WARN("unknown service %s\n", debugstr_guid(guidService
));
1301 #undef SERVPROV_THIS
1303 static const IServiceProviderVtbl ServiceProviderVtbl
= {
1304 ServiceProvider_QueryInterface
,
1305 ServiceProvider_AddRef
,
1306 ServiceProvider_Release
,
1307 ServiceProvider_QueryService
1310 static HRESULT
get_callback(IBindCtx
*pbc
, IBindStatusCallback
**callback
)
1315 hres
= IBindCtx_GetObjectParam(pbc
, bscb_holderW
, &unk
);
1316 if(SUCCEEDED(hres
)) {
1317 hres
= IUnknown_QueryInterface(unk
, &IID_IBindStatusCallback
, (void**)callback
);
1318 IUnknown_Release(unk
);
1321 return SUCCEEDED(hres
) ? S_OK
: INET_E_DATA_NOT_AVAILABLE
;
1324 static BOOL
is_urlmon_protocol(LPCWSTR url
)
1326 static const WCHAR wszCdl
[] = {'c','d','l'};
1327 static const WCHAR wszFile
[] = {'f','i','l','e'};
1328 static const WCHAR wszFtp
[] = {'f','t','p'};
1329 static const WCHAR wszGopher
[] = {'g','o','p','h','e','r'};
1330 static const WCHAR wszHttp
[] = {'h','t','t','p'};
1331 static const WCHAR wszHttps
[] = {'h','t','t','p','s'};
1332 static const WCHAR wszMk
[] = {'m','k'};
1334 static const struct {
1337 } protocol_list
[] = {
1338 {wszCdl
, sizeof(wszCdl
) /sizeof(WCHAR
)},
1339 {wszFile
, sizeof(wszFile
) /sizeof(WCHAR
)},
1340 {wszFtp
, sizeof(wszFtp
) /sizeof(WCHAR
)},
1341 {wszGopher
, sizeof(wszGopher
)/sizeof(WCHAR
)},
1342 {wszHttp
, sizeof(wszHttp
) /sizeof(WCHAR
)},
1343 {wszHttps
, sizeof(wszHttps
) /sizeof(WCHAR
)},
1344 {wszMk
, sizeof(wszMk
) /sizeof(WCHAR
)}
1348 int len
= lstrlenW(url
);
1350 for(i
=0; i
< sizeof(protocol_list
)/sizeof(protocol_list
[0]); i
++) {
1351 if(len
>= protocol_list
[i
].len
1352 && !memcmp(url
, protocol_list
[i
].scheme
, protocol_list
[i
].len
*sizeof(WCHAR
)))
1359 static HRESULT
Binding_Create(IMoniker
*mon
, Binding
*binding_ctx
, LPCWSTR url
, IBindCtx
*pbc
,
1360 BOOL to_obj
, REFIID riid
, Binding
**binding
)
1365 URLMON_LockModule();
1367 ret
= heap_alloc_zero(sizeof(Binding
));
1369 ret
->lpBindingVtbl
= &BindingVtbl
;
1370 ret
->lpIInternetProtocolSinkVtbl
= &InternetProtocolSinkVtbl
;
1371 ret
->lpInternetBindInfoVtbl
= &InternetBindInfoVtbl
;
1372 ret
->lpWinInetHttpInfoVtbl
= &WinInetHttpInfoVtbl
;
1373 ret
->lpServiceProviderVtbl
= &ServiceProviderVtbl
;
1377 ret
->to_object
= to_obj
;
1379 ret
->notif_hwnd
= get_notif_hwnd();
1380 ret
->report_mime
= !binding_ctx
;
1381 ret
->download_state
= BEFORE_DOWNLOAD
;
1384 IBindCtx_AddRef(pbc
);
1389 IMoniker_AddRef(mon
);
1393 ret
->bindinfo
.cbSize
= sizeof(BINDINFO
);
1395 InitializeCriticalSection(&ret
->section
);
1396 ret
->section
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": Binding.section");
1398 hres
= get_callback(pbc
, &ret
->callback
);
1400 WARN("Could not get IBindStatusCallback\n");
1401 IBinding_Release(BINDING(ret
));
1405 IBindStatusCallback_QueryInterface(ret
->callback
, &IID_IServiceProvider
,
1406 (void**)&ret
->service_provider
);
1409 ret
->protocol
= binding_ctx
->protocol
;
1410 IInternetProtocol_AddRef(ret
->protocol
);
1412 hres
= create_binding_protocol(url
, TRUE
, &ret
->protocol
);
1414 WARN("Could not get protocol handler\n");
1415 IBinding_Release(BINDING(ret
));
1420 hres
= IBindStatusCallback_GetBindInfo(ret
->callback
, &ret
->bindf
, &ret
->bindinfo
);
1422 WARN("GetBindInfo failed: %08x\n", hres
);
1423 IBinding_Release(BINDING(ret
));
1427 TRACE("bindf %08x\n", ret
->bindf
);
1428 dump_BINDINFO(&ret
->bindinfo
);
1430 ret
->bindf
|= BINDF_FROMURLMON
;
1432 ret
->bindinfo
.dwOptions
|= 0x100000;
1434 if(!is_urlmon_protocol(url
))
1435 ret
->bindf
|= BINDF_NEEDFILE
;
1437 ret
->url
= heap_strdupW(url
);
1440 ret
->stgmed_buf
= binding_ctx
->stgmed_buf
;
1441 IUnknown_AddRef(STGMEDUNK(ret
->stgmed_buf
));
1442 ret
->clipboard_format
= binding_ctx
->clipboard_format
;
1444 ret
->stgmed_buf
= create_stgmed_buf(ret
->protocol
);
1448 ret
->stgmed_obj
= NULL
;
1449 }else if(IsEqualGUID(&IID_IStream
, riid
)) {
1450 ret
->stgmed_obj
= create_stgmed_stream(ret
->stgmed_buf
);
1451 }else if(IsEqualGUID(&IID_IUnknown
, riid
)) {
1452 ret
->bindf
|= BINDF_NEEDFILE
;
1453 ret
->stgmed_obj
= create_stgmed_file(ret
->stgmed_buf
);
1455 FIXME("Unsupported riid %s\n", debugstr_guid(riid
));
1456 IBinding_Release(BINDING(ret
));
1464 static HRESULT
start_binding(IMoniker
*mon
, Binding
*binding_ctx
, LPCWSTR url
, IBindCtx
*pbc
,
1465 BOOL to_obj
, REFIID riid
, Binding
**ret
)
1467 Binding
*binding
= NULL
;
1471 hres
= Binding_Create(mon
, binding_ctx
, url
, pbc
, to_obj
, riid
, &binding
);
1475 hres
= IBindStatusCallback_OnStartBinding(binding
->callback
, 0, BINDING(binding
));
1477 WARN("OnStartBinding failed: %08x\n", hres
);
1478 stop_binding(binding
, INET_E_DOWNLOAD_FAILURE
, NULL
);
1479 IBinding_Release(BINDING(binding
));
1484 set_binding_sink(binding
->protocol
, PROTSINK(binding
));
1485 if(binding_ctx
->redirect_url
)
1486 IBindStatusCallback_OnProgress(binding
->callback
, 0, 0, BINDSTATUS_REDIRECTING
, binding_ctx
->redirect_url
);
1487 report_data(binding
, 0, 0, 0);
1489 hres
= IInternetProtocol_Start(binding
->protocol
, url
, PROTSINK(binding
),
1490 BINDINF(binding
), PI_APARTMENTTHREADED
|PI_MIMEVERIFICATION
, 0);
1492 TRACE("start ret %08x\n", hres
);
1494 if(FAILED(hres
) && hres
!= E_PENDING
) {
1495 stop_binding(binding
, hres
, NULL
);
1496 IBinding_Release(BINDING(binding
));
1502 while(!(binding
->bindf
& BINDF_ASYNCHRONOUS
) &&
1503 !(binding
->state
& BINDING_STOPPED
)) {
1504 MsgWaitForMultipleObjects(0, NULL
, FALSE
, 5000, QS_POSTMESSAGE
);
1505 while (PeekMessageW(&msg
, binding
->notif_hwnd
, WM_USER
, WM_USER
+117, PM_REMOVE
|PM_NOYIELD
)) {
1506 TranslateMessage(&msg
);
1507 DispatchMessageW(&msg
);
1515 HRESULT
bind_to_storage(LPCWSTR url
, IBindCtx
*pbc
, REFIID riid
, void **ppv
)
1517 Binding
*binding
= NULL
, *binding_ctx
;
1522 binding_ctx
= get_bctx_binding(pbc
);
1524 hres
= start_binding(NULL
, binding_ctx
, url
, pbc
, FALSE
, riid
, &binding
);
1526 IBinding_Release(BINDING(binding_ctx
));
1530 if(binding
->hres
== S_OK
&& binding
->stgmed_buf
->init
) {
1531 if((binding
->state
& BINDING_STOPPED
) && (binding
->state
& BINDING_LOCKED
))
1532 IInternetProtocol_UnlockRequest(binding
->protocol
);
1534 hres
= binding
->stgmed_obj
->vtbl
->get_result(binding
->stgmed_obj
, binding
->bindf
, ppv
);
1536 hres
= MK_S_ASYNCHRONOUS
;
1539 IBinding_Release(BINDING(binding
));
1544 HRESULT
bind_to_object(IMoniker
*mon
, LPCWSTR url
, IBindCtx
*pbc
, REFIID riid
, void **ppv
)
1551 hres
= start_binding(mon
, NULL
, url
, pbc
, TRUE
, riid
, &binding
);
1555 if(binding
->hres
!= S_OK
) {
1556 hres
= SUCCEEDED(binding
->hres
) ? S_OK
: binding
->hres
;
1557 }else if(binding
->bindf
& BINDF_ASYNCHRONOUS
) {
1558 hres
= MK_S_ASYNCHRONOUS
;
1560 *ppv
= binding
->obj
;
1561 IUnknown_AddRef(binding
->obj
);
1565 IBinding_Release(BINDING(binding
));