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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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
;
57 DWORD apartment_thread
;
63 struct ProtocolStream
{
64 const IStreamVtbl
*lpStreamVtbl
;
68 IInternetProtocol
*protocol
;
75 #define BINDING(x) ((IBinding*) &(x)->lpBindingVtbl)
76 #define PROTSINK(x) ((IInternetProtocolSink*) &(x)->lpInternetProtocolSinkVtbl)
77 #define BINDINF(x) ((IInternetBindInfo*) &(x)->lpInternetBindInfoVtbl)
78 #define SERVPROV(x) ((IServiceProvider*) &(x)->lpServiceProviderVtbl)
80 #define STREAM(x) ((IStream*) &(x)->lpStreamVtbl)
82 #define WM_MK_ONPROGRESS (WM_USER+100)
83 #define WM_MK_CONTINUE (WM_USER+101)
98 static LRESULT WINAPI
notif_wnd_proc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
101 case WM_MK_ONPROGRESS
: {
102 on_progress_data
*data
= (on_progress_data
*)lParam
;
104 TRACE("WM_MK_PROGRESS %p\n", data
);
106 IBindStatusCallback_OnProgress(data
->binding
->callback
, data
->progress
,
107 data
->progress_max
, data
->status_code
, data
->status_text
);
109 IBinding_Release(BINDING(data
->binding
));
110 HeapFree(GetProcessHeap(), 0, data
->status_text
);
111 HeapFree(GetProcessHeap(), 0, data
);
115 case WM_MK_CONTINUE
: {
116 switch_data
*data
= (switch_data
*)lParam
;
118 IInternetProtocol_Continue(data
->binding
->protocol
, data
->data
);
120 IBinding_Release(BINDING(data
->binding
));
121 HeapFree(GetProcessHeap(), 0, data
);
126 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
129 static HWND
get_notif_hwnd(void)
131 static ATOM wnd_class
= 0;
134 static const WCHAR wszURLMonikerNotificationWindow
[] =
135 {'U','R','L',' ','M','o','n','i','k','e','r',' ',
136 'N','o','t','i','f','i','c','a','t','i','o','n',' ','W','i','n','d','o','w',0};
139 static WNDCLASSEXW wndclass
= {
141 notif_wnd_proc
, 0, 0,
142 NULL
, NULL
, NULL
, NULL
, NULL
,
143 wszURLMonikerNotificationWindow
,
147 wndclass
.hInstance
= URLMON_hInstance
;
149 wnd_class
= RegisterClassExW(&wndclass
);
153 urlmon_tls
= TlsAlloc();
155 hwnd
= TlsGetValue(urlmon_tls
);
159 hwnd
= CreateWindowExW(0, MAKEINTATOMW(wnd_class
),
160 wszURLMonikerNotificationWindow
, 0, 0, 0, 0, 0, HWND_MESSAGE
,
161 NULL
, URLMON_hInstance
, NULL
);
162 TlsSetValue(urlmon_tls
, hwnd
);
164 TRACE("hwnd = %p\n", hwnd
);
169 static void on_progress(Binding
*This
, ULONG progress
, ULONG progress_max
,
170 ULONG status_code
, LPCWSTR status_text
)
172 on_progress_data
*data
;
174 if(GetCurrentThreadId() == This
->apartment_thread
) {
175 IBindStatusCallback_OnProgress(This
->callback
, progress
, progress_max
,
176 status_code
, status_text
);
180 data
= HeapAlloc(GetProcessHeap(), 0, sizeof(*data
));
182 IBinding_AddRef(BINDING(This
));
184 data
->binding
= This
;
185 data
->progress
= progress
;
186 data
->progress_max
= progress_max
;
187 data
->status_code
= status_code
;
190 DWORD size
= (strlenW(status_text
)+1)*sizeof(WCHAR
);
192 data
->status_text
= HeapAlloc(GetProcessHeap(), 0, size
);
193 memcpy(data
->status_text
, status_text
, size
);
195 data
->status_text
= NULL
;
198 PostMessageW(This
->notif_hwnd
, WM_MK_ONPROGRESS
, 0, (LPARAM
)data
);
201 static HRESULT WINAPI
HttpNegotiate_QueryInterface(IHttpNegotiate2
*iface
,
202 REFIID riid
, void **ppv
)
206 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
207 TRACE("(IID_IUnknown %p)\n", ppv
);
209 }else if(IsEqualGUID(&IID_IHttpNegotiate
, riid
)) {
210 TRACE("(IID_IHttpNegotiate %p)\n", ppv
);
212 }else if(IsEqualGUID(&IID_IHttpNegotiate2
, riid
)) {
213 TRACE("(IID_IHttpNegotiate2 %p)\n", ppv
);
218 IHttpNegotiate2_AddRef(iface
);
222 WARN("Unsupported interface %s\n", debugstr_guid(riid
));
223 return E_NOINTERFACE
;
226 static ULONG WINAPI
HttpNegotiate_AddRef(IHttpNegotiate2
*iface
)
232 static ULONG WINAPI
HttpNegotiate_Release(IHttpNegotiate2
*iface
)
234 URLMON_UnlockModule();
238 static HRESULT WINAPI
HttpNegotiate_BeginningTransaction(IHttpNegotiate2
*iface
,
239 LPCWSTR szURL
, LPCWSTR szHeaders
, DWORD dwReserved
, LPWSTR
*pszAdditionalHeaders
)
241 TRACE("(%s %s %ld %p)\n", debugstr_w(szURL
), debugstr_w(szHeaders
), dwReserved
,
242 pszAdditionalHeaders
);
244 *pszAdditionalHeaders
= NULL
;
248 static HRESULT WINAPI
HttpNegotiate_OnResponse(IHttpNegotiate2
*iface
, DWORD dwResponseCode
,
249 LPCWSTR szResponseHeaders
, LPCWSTR szRequestHeaders
,
250 LPWSTR
*pszAdditionalRequestHeaders
)
252 FIXME("(%ld %s %s %p)\n", dwResponseCode
, debugstr_w(szResponseHeaders
),
253 debugstr_w(szRequestHeaders
), pszAdditionalRequestHeaders
);
257 static HRESULT WINAPI
HttpNegotiate_GetRootSecurityId(IHttpNegotiate2
*iface
,
258 BYTE
*pbSecurityId
, DWORD
*pcbSecurityId
, DWORD_PTR dwReserved
)
260 TRACE("(%p %p %ld)\n", pbSecurityId
, pcbSecurityId
, dwReserved
);
262 /* That's all we have to do here */
266 static const IHttpNegotiate2Vtbl HttpNegotiate2Vtbl
= {
267 HttpNegotiate_QueryInterface
,
268 HttpNegotiate_AddRef
,
269 HttpNegotiate_Release
,
270 HttpNegotiate_BeginningTransaction
,
271 HttpNegotiate_OnResponse
,
272 HttpNegotiate_GetRootSecurityId
275 static IHttpNegotiate2 HttpNegotiate
= { &HttpNegotiate2Vtbl
};
277 #define STREAM_THIS(iface) DEFINE_THIS(ProtocolStream, Stream, iface)
279 static HRESULT WINAPI
ProtocolStream_QueryInterface(IStream
*iface
,
280 REFIID riid
, void **ppv
)
282 ProtocolStream
*This
= STREAM_THIS(iface
);
286 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
287 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
289 }else if(IsEqualGUID(&IID_ISequentialStream
, riid
)) {
290 TRACE("(%p)->(IID_ISequentialStream %p)\n", This
, ppv
);
292 }else if(IsEqualGUID(&IID_IStream
, riid
)) {
293 TRACE("(%p)->(IID_IStream %p)\n", This
, ppv
);
298 IStream_AddRef(STREAM(This
));
302 WARN("(%p)->(%s %p)\n", This
, debugstr_guid(riid
), ppv
);
303 return E_NOINTERFACE
;
306 static ULONG WINAPI
ProtocolStream_AddRef(IStream
*iface
)
308 ProtocolStream
*This
= STREAM_THIS(iface
);
309 LONG ref
= InterlockedIncrement(&This
->ref
);
311 TRACE("(%p) ref=%ld\n", This
, ref
);
316 static ULONG WINAPI
ProtocolStream_Release(IStream
*iface
)
318 ProtocolStream
*This
= STREAM_THIS(iface
);
319 LONG ref
= InterlockedDecrement(&This
->ref
);
321 TRACE("(%p) ref=%ld\n", This
, ref
);
324 IInternetProtocol_Release(This
->protocol
);
325 HeapFree(GetProcessHeap(), 0, This
);
327 URLMON_UnlockModule();
333 static HRESULT WINAPI
ProtocolStream_Read(IStream
*iface
, void *pv
,
334 ULONG cb
, ULONG
*pcbRead
)
336 ProtocolStream
*This
= STREAM_THIS(iface
);
337 DWORD read
= 0, pread
= 0;
340 TRACE("(%p)->(%p %ld %p)\n", This
, pv
, cb
, pcbRead
);
345 if(read
> This
->buf_size
)
346 read
= This
->buf_size
;
348 memcpy(pv
, This
->buf
, read
);
350 if(read
< This
->buf_size
)
351 memmove(This
->buf
, This
->buf
+read
, This
->buf_size
-read
);
352 This
->buf_size
-= read
;
360 hres
= IInternetProtocol_Read(This
->protocol
, (PBYTE
)pv
+read
, cb
-read
, &pread
);
361 *pcbRead
= read
+ pread
;
363 if(hres
== E_PENDING
)
365 else if(FAILED(hres
))
366 FIXME("Read failed: %08lx\n", hres
);
368 return read
|| pread
? S_OK
: S_FALSE
;
371 static HRESULT WINAPI
ProtocolStream_Write(IStream
*iface
, const void *pv
,
372 ULONG cb
, ULONG
*pcbWritten
)
374 ProtocolStream
*This
= STREAM_THIS(iface
);
376 TRACE("(%p)->(%p %ld %p)\n", This
, pv
, cb
, pcbWritten
);
378 return STG_E_ACCESSDENIED
;
381 static HRESULT WINAPI
ProtocolStream_Seek(IStream
*iface
, LARGE_INTEGER dlibMove
,
382 DWORD dwOrigin
, ULARGE_INTEGER
*plibNewPosition
)
384 ProtocolStream
*This
= STREAM_THIS(iface
);
385 FIXME("(%p)->(%ld %08lx %p)\n", This
, dlibMove
.u
.LowPart
, dwOrigin
, plibNewPosition
);
389 static HRESULT WINAPI
ProtocolStream_SetSize(IStream
*iface
, ULARGE_INTEGER libNewSize
)
391 ProtocolStream
*This
= STREAM_THIS(iface
);
392 FIXME("(%p)->(%ld)\n", This
, libNewSize
.u
.LowPart
);
396 static HRESULT WINAPI
ProtocolStream_CopyTo(IStream
*iface
, IStream
*pstm
,
397 ULARGE_INTEGER cb
, ULARGE_INTEGER
*pcbRead
, ULARGE_INTEGER
*pcbWritten
)
399 ProtocolStream
*This
= STREAM_THIS(iface
);
400 FIXME("(%p)->(%p %ld %p %p)\n", This
, pstm
, cb
.u
.LowPart
, pcbRead
, pcbWritten
);
404 static HRESULT WINAPI
ProtocolStream_Commit(IStream
*iface
, DWORD grfCommitFlags
)
406 ProtocolStream
*This
= STREAM_THIS(iface
);
408 TRACE("(%p)->(%08lx)\n", This
, grfCommitFlags
);
413 static HRESULT WINAPI
ProtocolStream_Revert(IStream
*iface
)
415 ProtocolStream
*This
= STREAM_THIS(iface
);
417 TRACE("(%p)\n", This
);
422 static HRESULT WINAPI
ProtocolStream_LockRegion(IStream
*iface
, ULARGE_INTEGER libOffset
,
423 ULARGE_INTEGER cb
, DWORD dwLockType
)
425 ProtocolStream
*This
= STREAM_THIS(iface
);
426 FIXME("(%p)->(%ld %ld %ld)\n", This
, libOffset
.u
.LowPart
, cb
.u
.LowPart
, dwLockType
);
430 static HRESULT WINAPI
ProtocolStream_UnlockRegion(IStream
*iface
,
431 ULARGE_INTEGER libOffset
, ULARGE_INTEGER cb
, DWORD dwLockType
)
433 ProtocolStream
*This
= STREAM_THIS(iface
);
434 FIXME("(%p)->(%ld %ld %ld)\n", This
, libOffset
.u
.LowPart
, cb
.u
.LowPart
, dwLockType
);
438 static HRESULT WINAPI
ProtocolStream_Stat(IStream
*iface
, STATSTG
*pstatstg
,
441 ProtocolStream
*This
= STREAM_THIS(iface
);
442 FIXME("(%p)->(%p %08lx)\n", This
, pstatstg
, dwStatFlag
);
446 static HRESULT WINAPI
ProtocolStream_Clone(IStream
*iface
, IStream
**ppstm
)
448 ProtocolStream
*This
= STREAM_THIS(iface
);
449 FIXME("(%p)->(%p)\n", This
, ppstm
);
455 static const IStreamVtbl ProtocolStreamVtbl
= {
456 ProtocolStream_QueryInterface
,
457 ProtocolStream_AddRef
,
458 ProtocolStream_Release
,
460 ProtocolStream_Write
,
462 ProtocolStream_SetSize
,
463 ProtocolStream_CopyTo
,
464 ProtocolStream_Commit
,
465 ProtocolStream_Revert
,
466 ProtocolStream_LockRegion
,
467 ProtocolStream_UnlockRegion
,
472 #define BINDING_THIS(iface) DEFINE_THIS(Binding, Binding, iface)
474 static ProtocolStream
*create_stream(IInternetProtocol
*protocol
)
476 ProtocolStream
*ret
= HeapAlloc(GetProcessHeap(), 0, sizeof(ProtocolStream
));
478 ret
->lpStreamVtbl
= &ProtocolStreamVtbl
;
481 ret
->init_buf
= FALSE
;
483 IInternetProtocol_AddRef(protocol
);
484 ret
->protocol
= protocol
;
491 static void fill_stream_buffer(ProtocolStream
*This
)
496 hres
= IInternetProtocol_Read(This
->protocol
, This
->buf
+This
->buf_size
,
497 sizeof(This
->buf
)-This
->buf_size
, &read
);
498 if(SUCCEEDED(hres
)) {
499 This
->buf_size
+= read
;
500 This
->init_buf
= TRUE
;
504 static HRESULT WINAPI
Binding_QueryInterface(IBinding
*iface
, REFIID riid
, void **ppv
)
506 Binding
*This
= BINDING_THIS(iface
);
510 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
511 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
512 *ppv
= BINDING(This
);
513 }else if(IsEqualGUID(&IID_IBinding
, riid
)) {
514 TRACE("(%p)->(IID_IBinding %p)\n", This
, ppv
);
515 *ppv
= BINDING(This
);
516 }else if(IsEqualGUID(&IID_IInternetProtocolSink
, riid
)) {
517 TRACE("(%p)->(IID_IInternetProtocolSink %p)\n", This
, ppv
);
518 *ppv
= PROTSINK(This
);
519 }else if(IsEqualGUID(&IID_IInternetBindInfo
, riid
)) {
520 TRACE("(%p)->(IID_IInternetBindInfo %p)\n", This
, ppv
);
521 *ppv
= BINDINF(This
);
522 }else if(IsEqualGUID(&IID_IServiceProvider
, riid
)) {
523 TRACE("(%p)->(IID_IServiceProvider %p)\n", This
, ppv
);
524 *ppv
= SERVPROV(This
);
528 IBinding_AddRef(BINDING(This
));
532 WARN("Unsupported interface %s\n", debugstr_guid(riid
));
533 return E_NOINTERFACE
;
536 static ULONG WINAPI
Binding_AddRef(IBinding
*iface
)
538 Binding
*This
= BINDING_THIS(iface
);
539 LONG ref
= InterlockedIncrement(&This
->ref
);
541 TRACE("(%p) ref=%ld\n", This
, ref
);
546 static ULONG WINAPI
Binding_Release(IBinding
*iface
)
548 Binding
*This
= BINDING_THIS(iface
);
549 LONG ref
= InterlockedDecrement(&This
->ref
);
551 TRACE("(%p) ref=%ld\n", This
, ref
);
555 IBindStatusCallback_Release(This
->callback
);
557 IInternetProtocol_Release(This
->protocol
);
558 if(This
->service_provider
)
559 IServiceProvider_Release(This
->service_provider
);
561 IStream_Release(STREAM(This
->stream
));
563 ReleaseBindInfo(&This
->bindinfo
);
564 HeapFree(GetProcessHeap(), 0, This
->mime
);
565 HeapFree(GetProcessHeap(), 0, This
->url
);
567 HeapFree(GetProcessHeap(), 0, This
);
569 URLMON_UnlockModule();
575 static HRESULT WINAPI
Binding_Abort(IBinding
*iface
)
577 Binding
*This
= BINDING_THIS(iface
);
578 FIXME("(%p)\n", This
);
582 static HRESULT WINAPI
Binding_Suspend(IBinding
*iface
)
584 Binding
*This
= BINDING_THIS(iface
);
585 FIXME("(%p)\n", This
);
589 static HRESULT WINAPI
Binding_Resume(IBinding
*iface
)
591 Binding
*This
= BINDING_THIS(iface
);
592 FIXME("(%p)\n", This
);
596 static HRESULT WINAPI
Binding_SetPriority(IBinding
*iface
, LONG nPriority
)
598 Binding
*This
= BINDING_THIS(iface
);
599 FIXME("(%p)->(%ld)\n", This
, nPriority
);
603 static HRESULT WINAPI
Binding_GetPriority(IBinding
*iface
, LONG
*pnPriority
)
605 Binding
*This
= BINDING_THIS(iface
);
606 FIXME("(%p)->(%p)\n", This
, pnPriority
);
610 static HRESULT WINAPI
Binding_GetBindResult(IBinding
*iface
, CLSID
*pclsidProtocol
,
611 DWORD
*pdwResult
, LPOLESTR
*pszResult
, DWORD
*pdwReserved
)
613 Binding
*This
= BINDING_THIS(iface
);
614 FIXME("(%p)->(%p %p %p %p)\n", This
, pclsidProtocol
, pdwResult
, pszResult
, pdwReserved
);
620 static const IBindingVtbl BindingVtbl
= {
621 Binding_QueryInterface
,
629 Binding_GetBindResult
632 #define PROTSINK_THIS(iface) DEFINE_THIS(Binding, InternetProtocolSink, iface)
634 static HRESULT WINAPI
InternetProtocolSink_QueryInterface(IInternetProtocolSink
*iface
,
635 REFIID riid
, void **ppv
)
637 Binding
*This
= PROTSINK_THIS(iface
);
638 return IBinding_QueryInterface(BINDING(This
), riid
, ppv
);
641 static ULONG WINAPI
InternetProtocolSink_AddRef(IInternetProtocolSink
*iface
)
643 Binding
*This
= PROTSINK_THIS(iface
);
644 return IBinding_AddRef(BINDING(This
));
647 static ULONG WINAPI
InternetProtocolSink_Release(IInternetProtocolSink
*iface
)
649 Binding
*This
= PROTSINK_THIS(iface
);
650 return IBinding_Release(BINDING(This
));
653 static HRESULT WINAPI
InternetProtocolSink_Switch(IInternetProtocolSink
*iface
,
654 PROTOCOLDATA
*pProtocolData
)
656 Binding
*This
= PROTSINK_THIS(iface
);
659 TRACE("(%p)->(%p)\n", This
, pProtocolData
);
661 data
= HeapAlloc(GetProcessHeap(), 0, sizeof(switch_data
));
663 IBinding_AddRef(BINDING(This
));
664 data
->binding
= This
;
665 data
->data
= pProtocolData
;
667 PostMessageW(This
->notif_hwnd
, WM_MK_CONTINUE
, 0, (LPARAM
)data
);
672 static HRESULT WINAPI
InternetProtocolSink_ReportProgress(IInternetProtocolSink
*iface
,
673 ULONG ulStatusCode
, LPCWSTR szStatusText
)
675 Binding
*This
= PROTSINK_THIS(iface
);
677 TRACE("(%p)->(%lu %s)\n", This
, ulStatusCode
, debugstr_w(szStatusText
));
679 switch(ulStatusCode
) {
680 case BINDSTATUS_FINDINGRESOURCE
:
681 on_progress(This
, 0, 0, BINDSTATUS_FINDINGRESOURCE
, szStatusText
);
683 case BINDSTATUS_CONNECTING
:
684 on_progress(This
, 0, 0, BINDSTATUS_CONNECTING
, szStatusText
);
686 case BINDSTATUS_MIMETYPEAVAILABLE
: {
687 int len
= strlenW(szStatusText
)+1;
688 This
->mime
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
689 memcpy(This
->mime
, szStatusText
, len
*sizeof(WCHAR
));
692 case BINDSTATUS_SENDINGREQUEST
:
693 on_progress(This
, 0, 0, BINDSTATUS_SENDINGREQUEST
, szStatusText
);
695 case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE
:
696 on_progress(This
, 0, 0, BINDSTATUS_MIMETYPEAVAILABLE
, szStatusText
);
698 case BINDSTATUS_CACHEFILENAMEAVAILABLE
:
701 FIXME("Unhandled status code %ld\n", ulStatusCode
);
708 static HRESULT WINAPI
InternetProtocolSink_ReportData(IInternetProtocolSink
*iface
,
709 DWORD grfBSCF
, ULONG ulProgress
, ULONG ulProgressMax
)
711 Binding
*This
= PROTSINK_THIS(iface
);
714 TRACE("(%p)->(%ld %lu %lu)\n", This
, grfBSCF
, ulProgress
, ulProgressMax
);
716 if(grfBSCF
& BSCF_FIRSTDATANOTIFICATION
) {
718 IBindStatusCallback_OnProgress(This
->callback
, ulProgress
, ulProgressMax
,
719 BINDSTATUS_MIMETYPEAVAILABLE
, This
->mime
);
720 IBindStatusCallback_OnProgress(This
->callback
, ulProgress
, ulProgressMax
,
721 BINDSTATUS_BEGINDOWNLOADDATA
, This
->url
);
724 if(grfBSCF
& BSCF_LASTDATANOTIFICATION
)
725 IBindStatusCallback_OnProgress(This
->callback
, ulProgress
, ulProgressMax
,
726 BINDSTATUS_ENDDOWNLOADDATA
, This
->url
);
728 if(grfBSCF
& BSCF_FIRSTDATANOTIFICATION
)
729 IInternetProtocol_LockRequest(This
->protocol
, 0);
731 fill_stream_buffer(This
->stream
);
733 formatetc
.cfFormat
= 0; /* FIXME */
734 formatetc
.ptd
= NULL
;
735 formatetc
.dwAspect
= 1;
736 formatetc
.lindex
= -1;
737 formatetc
.tymed
= TYMED_ISTREAM
;
739 IBindStatusCallback_OnDataAvailable(This
->callback
, grfBSCF
, This
->stream
->buf_size
,
740 &formatetc
, &This
->stgmed
);
742 if(grfBSCF
& BSCF_LASTDATANOTIFICATION
)
743 IBindStatusCallback_OnStopBinding(This
->callback
, S_OK
, NULL
);
748 static HRESULT WINAPI
InternetProtocolSink_ReportResult(IInternetProtocolSink
*iface
,
749 HRESULT hrResult
, DWORD dwError
, LPCWSTR szResult
)
751 Binding
*This
= PROTSINK_THIS(iface
);
753 TRACE("(%p)->(%08lx %ld %s)\n", This
, hrResult
, dwError
, debugstr_w(szResult
));
755 IInternetProtocol_Terminate(This
->protocol
, 0);
761 static const IInternetProtocolSinkVtbl InternetProtocolSinkVtbl
= {
762 InternetProtocolSink_QueryInterface
,
763 InternetProtocolSink_AddRef
,
764 InternetProtocolSink_Release
,
765 InternetProtocolSink_Switch
,
766 InternetProtocolSink_ReportProgress
,
767 InternetProtocolSink_ReportData
,
768 InternetProtocolSink_ReportResult
771 #define BINDINF_THIS(iface) DEFINE_THIS(Binding, InternetBindInfo, iface)
773 static HRESULT WINAPI
InternetBindInfo_QueryInterface(IInternetBindInfo
*iface
,
774 REFIID riid
, void **ppv
)
776 Binding
*This
= BINDINF_THIS(iface
);
777 return IBinding_QueryInterface(BINDING(This
), riid
, ppv
);
780 static ULONG WINAPI
InternetBindInfo_AddRef(IInternetBindInfo
*iface
)
782 Binding
*This
= BINDINF_THIS(iface
);
783 return IBinding_AddRef(BINDING(This
));
786 static ULONG WINAPI
InternetBindInfo_Release(IInternetBindInfo
*iface
)
788 Binding
*This
= BINDINF_THIS(iface
);
789 return IBinding_Release(BINDING(This
));
792 static HRESULT WINAPI
InternetBindInfo_GetBindInfo(IInternetBindInfo
*iface
,
793 DWORD
*grfBINDF
, BINDINFO
*pbindinfo
)
795 Binding
*This
= BINDINF_THIS(iface
);
797 TRACE("(%p)->(%p %p)\n", This
, grfBINDF
, pbindinfo
);
799 *grfBINDF
= This
->bindf
;
801 memcpy(pbindinfo
, &This
->bindinfo
, sizeof(BINDINFO
));
803 if(pbindinfo
->szExtraInfo
|| pbindinfo
->szCustomVerb
)
804 FIXME("copy strings\n");
807 IUnknown_AddRef(pbindinfo
->pUnk
);
812 static HRESULT WINAPI
InternetBindInfo_GetBindString(IInternetBindInfo
*iface
,
813 ULONG ulStringType
, LPOLESTR
*ppwzStr
, ULONG cEl
, ULONG
*pcElFetched
)
815 Binding
*This
= BINDINF_THIS(iface
);
817 TRACE("(%p)->(%ld %p %ld %p)\n", This
, ulStringType
, ppwzStr
, cEl
, pcElFetched
);
819 switch(ulStringType
) {
820 case BINDSTRING_ACCEPT_MIMES
: {
821 static const WCHAR wszMimes
[] = {'*','/','*',0};
823 if(!ppwzStr
|| !pcElFetched
)
826 ppwzStr
[0] = CoTaskMemAlloc(sizeof(wszMimes
));
827 memcpy(ppwzStr
[0], wszMimes
, sizeof(wszMimes
));
831 case BINDSTRING_USER_AGENT
: {
832 IInternetBindInfo
*bindinfo
= NULL
;
835 hres
= IBindStatusCallback_QueryInterface(This
->callback
, &IID_IInternetBindInfo
,
840 hres
= IInternetBindInfo_GetBindString(bindinfo
, ulStringType
, ppwzStr
,
842 IInternetBindInfo_Release(bindinfo
);
848 FIXME("not supported string type %ld\n", ulStringType
);
854 static const IInternetBindInfoVtbl InternetBindInfoVtbl
= {
855 InternetBindInfo_QueryInterface
,
856 InternetBindInfo_AddRef
,
857 InternetBindInfo_Release
,
858 InternetBindInfo_GetBindInfo
,
859 InternetBindInfo_GetBindString
862 #define SERVPROV_THIS(iface) DEFINE_THIS(Binding, ServiceProvider, iface)
864 static HRESULT WINAPI
ServiceProvider_QueryInterface(IServiceProvider
*iface
,
865 REFIID riid
, void **ppv
)
867 Binding
*This
= SERVPROV_THIS(iface
);
868 return IBinding_QueryInterface(BINDING(This
), riid
, ppv
);
871 static ULONG WINAPI
ServiceProvider_AddRef(IServiceProvider
*iface
)
873 Binding
*This
= SERVPROV_THIS(iface
);
874 return IBinding_AddRef(BINDING(This
));
877 static ULONG WINAPI
ServiceProvider_Release(IServiceProvider
*iface
)
879 Binding
*This
= SERVPROV_THIS(iface
);
880 return IBinding_Release(BINDING(This
));
883 static HRESULT WINAPI
ServiceProvider_QueryService(IServiceProvider
*iface
,
884 REFGUID guidService
, REFIID riid
, void **ppv
)
886 Binding
*This
= SERVPROV_THIS(iface
);
889 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_guid(guidService
), debugstr_guid(riid
), ppv
);
891 if(This
->service_provider
) {
892 hres
= IServiceProvider_QueryService(This
->service_provider
, guidService
,
898 if(IsEqualGUID(&IID_IHttpNegotiate
, guidService
)
899 || IsEqualGUID(&IID_IHttpNegotiate2
, guidService
))
900 return IHttpNegotiate2_QueryInterface(&HttpNegotiate
, riid
, ppv
);
902 WARN("unknown service %s\n", debugstr_guid(guidService
));
908 static const IServiceProviderVtbl ServiceProviderVtbl
= {
909 ServiceProvider_QueryInterface
,
910 ServiceProvider_AddRef
,
911 ServiceProvider_Release
,
912 ServiceProvider_QueryService
915 static HRESULT
get_callback(IBindCtx
*pbc
, IBindStatusCallback
**callback
)
919 static WCHAR wszBSCBHolder
[] = { '_','B','S','C','B','_','H','o','l','d','e','r','_',0 };
921 hres
= IBindCtx_GetObjectParam(pbc
, wszBSCBHolder
, (IUnknown
**)callback
);
928 static HRESULT
get_protocol(Binding
*This
, LPCWSTR url
)
930 IClassFactory
*cf
= NULL
;
933 hres
= IBindStatusCallback_QueryInterface(This
->callback
, &IID_IInternetProtocol
,
934 (void**)&This
->protocol
);
938 if(This
->service_provider
) {
939 hres
= IServiceProvider_QueryService(This
->service_provider
, &IID_IInternetProtocol
,
940 &IID_IInternetProtocol
, (void**)&This
->protocol
);
945 hres
= get_protocol_handler(url
, &cf
);
949 hres
= IClassFactory_CreateInstance(cf
, NULL
, &IID_IInternetProtocol
, (void**)&This
->protocol
);
950 IClassFactory_Release(cf
);
955 static HRESULT
Binding_Create(LPCWSTR url
, IBindCtx
*pbc
, REFIID riid
, Binding
**binding
)
961 static const WCHAR wszFile
[] = {'f','i','l','e',':'};
963 if(!IsEqualGUID(&IID_IStream
, riid
)) {
964 FIXME("Unsupported riid %s\n", debugstr_guid(riid
));
970 ret
= HeapAlloc(GetProcessHeap(), 0, sizeof(Binding
));
972 ret
->lpBindingVtbl
= &BindingVtbl
;
973 ret
->lpInternetProtocolSinkVtbl
= &InternetProtocolSinkVtbl
;
974 ret
->lpInternetBindInfoVtbl
= &InternetBindInfoVtbl
;
975 ret
->lpServiceProviderVtbl
= &ServiceProviderVtbl
;
979 ret
->callback
= NULL
;
980 ret
->protocol
= NULL
;
981 ret
->service_provider
= NULL
;
985 ret
->apartment_thread
= GetCurrentThreadId();
986 ret
->notif_hwnd
= get_notif_hwnd();
988 memset(&ret
->bindinfo
, 0, sizeof(BINDINFO
));
989 ret
->bindinfo
.cbSize
= sizeof(BINDINFO
);
992 hres
= get_callback(pbc
, &ret
->callback
);
994 WARN("Could not get IBindStatusCallback\n");
995 IBinding_Release(BINDING(ret
));
999 IBindStatusCallback_QueryInterface(ret
->callback
, &IID_IServiceProvider
,
1000 (void**)&ret
->service_provider
);
1002 hres
= get_protocol(ret
, url
);
1004 WARN("Could not get protocol handler\n");
1005 IBinding_Release(BINDING(ret
));
1009 hres
= IBindStatusCallback_GetBindInfo(ret
->callback
, &ret
->bindf
, &ret
->bindinfo
);
1011 WARN("GetBindInfo failed: %08lx\n", hres
);
1012 IBinding_Release(BINDING(ret
));
1016 ret
->bindf
|= BINDF_FROMURLMON
;
1018 len
= strlenW(url
)+1;
1020 if(len
< sizeof(wszFile
)/sizeof(WCHAR
) || memcmp(wszFile
, url
, sizeof(wszFile
)))
1021 ret
->bindf
|= BINDF_NEEDFILE
;
1023 ret
->url
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
1024 memcpy(ret
->url
, url
, len
*sizeof(WCHAR
));
1026 ret
->stream
= create_stream(ret
->protocol
);
1027 ret
->stgmed
.tymed
= TYMED_ISTREAM
;
1028 ret
->stgmed
.u
.pstm
= STREAM(ret
->stream
);
1029 ret
->stgmed
.pUnkForRelease
= (IUnknown
*)BINDING(ret
); /* NOTE: Windows uses other IUnknown */
1035 HRESULT
start_binding(LPCWSTR url
, IBindCtx
*pbc
, REFIID riid
, void **ppv
)
1037 Binding
*binding
= NULL
;
1042 hres
= Binding_Create(url
, pbc
, riid
, &binding
);
1046 hres
= IBindStatusCallback_OnStartBinding(binding
->callback
, 0, BINDING(binding
));
1048 WARN("OnStartBinding failed: %08lx\n", hres
);
1049 IBindStatusCallback_OnStopBinding(binding
->callback
, 0x800c0008, NULL
);
1050 IBinding_Release(BINDING(binding
));
1054 hres
= IInternetProtocol_Start(binding
->protocol
, url
, PROTSINK(binding
),
1055 BINDINF(binding
), 0, 0);
1058 WARN("Start failed: %08lx\n", hres
);
1060 IInternetProtocol_Terminate(binding
->protocol
, 0);
1061 IBindStatusCallback_OnStopBinding(binding
->callback
, S_OK
, NULL
);
1062 IBinding_Release(BINDING(binding
));
1067 if(binding
->stream
->init_buf
) {
1068 IInternetProtocol_UnlockRequest(binding
->protocol
);
1070 IStream_AddRef(STREAM(binding
->stream
));
1071 *ppv
= binding
->stream
;
1075 hres
= MK_S_ASYNCHRONOUS
;
1078 IBinding_Release(BINDING(binding
));