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
;
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
);
198 URLMON_UnlockModule();
204 static HRESULT WINAPI
ProtocolStream_Read(IStream
*iface
, void *pv
,
205 ULONG cb
, ULONG
*pcbRead
)
207 ProtocolStream
*This
= STREAM_THIS(iface
);
208 DWORD read
= 0, pread
= 0;
210 TRACE("(%p)->(%p %ld %p)\n", This
, pv
, cb
, pcbRead
);
215 if(read
> This
->buf_size
)
216 read
= This
->buf_size
;
218 memcpy(pv
, This
->buf
, read
);
220 if(read
< This
->buf_size
)
221 memmove(This
->buf
, This
->buf
+read
, This
->buf_size
-read
);
222 This
->buf_size
-= read
;
230 IInternetProtocol_Read(This
->protocol
, (PBYTE
)pv
+read
, cb
-read
, &pread
);
231 *pcbRead
= read
+ pread
;
233 return read
|| pread
? S_OK
: S_FALSE
;
236 static HRESULT WINAPI
ProtocolStream_Write(IStream
*iface
, const void *pv
,
237 ULONG cb
, ULONG
*pcbWritten
)
239 ProtocolStream
*This
= STREAM_THIS(iface
);
241 TRACE("(%p)->(%p %ld %p)\n", This
, pv
, cb
, pcbWritten
);
243 return STG_E_ACCESSDENIED
;
246 static HRESULT WINAPI
ProtocolStream_Seek(IStream
*iface
, LARGE_INTEGER dlibMove
,
247 DWORD dwOrigin
, ULARGE_INTEGER
*plibNewPosition
)
249 ProtocolStream
*This
= STREAM_THIS(iface
);
250 FIXME("(%p)->(%ld %08lx %p)\n", This
, dlibMove
.u
.LowPart
, dwOrigin
, plibNewPosition
);
254 static HRESULT WINAPI
ProtocolStream_SetSize(IStream
*iface
, ULARGE_INTEGER libNewSize
)
256 ProtocolStream
*This
= STREAM_THIS(iface
);
257 FIXME("(%p)->(%ld)\n", This
, libNewSize
.u
.LowPart
);
261 static HRESULT WINAPI
ProtocolStream_CopyTo(IStream
*iface
, IStream
*pstm
,
262 ULARGE_INTEGER cb
, ULARGE_INTEGER
*pcbRead
, ULARGE_INTEGER
*pcbWritten
)
264 ProtocolStream
*This
= STREAM_THIS(iface
);
265 FIXME("(%p)->(%p %ld %p %p)\n", This
, pstm
, cb
.u
.LowPart
, pcbRead
, pcbWritten
);
269 static HRESULT WINAPI
ProtocolStream_Commit(IStream
*iface
, DWORD grfCommitFlags
)
271 ProtocolStream
*This
= STREAM_THIS(iface
);
273 TRACE("(%p)->(%08lx)\n", This
, grfCommitFlags
);
278 static HRESULT WINAPI
ProtocolStream_Revert(IStream
*iface
)
280 ProtocolStream
*This
= STREAM_THIS(iface
);
282 TRACE("(%p)\n", This
);
287 static HRESULT WINAPI
ProtocolStream_LockRegion(IStream
*iface
, ULARGE_INTEGER libOffset
,
288 ULARGE_INTEGER cb
, DWORD dwLockType
)
290 ProtocolStream
*This
= STREAM_THIS(iface
);
291 FIXME("(%p)->(%ld %ld %ld)\n", This
, libOffset
.u
.LowPart
, cb
.u
.LowPart
, dwLockType
);
295 static HRESULT WINAPI
ProtocolStream_UnlockRegion(IStream
*iface
,
296 ULARGE_INTEGER libOffset
, ULARGE_INTEGER cb
, DWORD dwLockType
)
298 ProtocolStream
*This
= STREAM_THIS(iface
);
299 FIXME("(%p)->(%ld %ld %ld)\n", This
, libOffset
.u
.LowPart
, cb
.u
.LowPart
, dwLockType
);
303 static HRESULT WINAPI
ProtocolStream_Stat(IStream
*iface
, STATSTG
*pstatstg
,
306 ProtocolStream
*This
= STREAM_THIS(iface
);
307 FIXME("(%p)->(%p %08lx)\n", This
, pstatstg
, dwStatFlag
);
311 static HRESULT WINAPI
ProtocolStream_Clone(IStream
*iface
, IStream
**ppstm
)
313 ProtocolStream
*This
= STREAM_THIS(iface
);
314 FIXME("(%p)->(%p)\n", This
, ppstm
);
320 static const IStreamVtbl ProtocolStreamVtbl
= {
321 ProtocolStream_QueryInterface
,
322 ProtocolStream_AddRef
,
323 ProtocolStream_Release
,
325 ProtocolStream_Write
,
327 ProtocolStream_SetSize
,
328 ProtocolStream_CopyTo
,
329 ProtocolStream_Commit
,
330 ProtocolStream_Revert
,
331 ProtocolStream_LockRegion
,
332 ProtocolStream_UnlockRegion
,
337 #define BINDING_THIS(iface) DEFINE_THIS(Binding, Binding, iface)
339 static ProtocolStream
*create_stream(IInternetProtocol
*protocol
)
341 ProtocolStream
*ret
= HeapAlloc(GetProcessHeap(), 0, sizeof(ProtocolStream
));
343 ret
->lpStreamVtbl
= &ProtocolStreamVtbl
;
347 IInternetProtocol_AddRef(protocol
);
348 ret
->protocol
= protocol
;
355 static void fill_stream_buffer(ProtocolStream
*This
)
359 IInternetProtocol_Read(This
->protocol
, This
->buf
+This
->buf_size
,
360 sizeof(This
->buf
)-This
->buf_size
, &read
);
361 This
->buf_size
+= read
;
364 static HRESULT WINAPI
Binding_QueryInterface(IBinding
*iface
, REFIID riid
, void **ppv
)
366 Binding
*This
= BINDING_THIS(iface
);
370 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
371 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
372 *ppv
= BINDING(This
);
373 }else if(IsEqualGUID(&IID_IBinding
, riid
)) {
374 TRACE("(%p)->(IID_IBinding %p)\n", This
, ppv
);
375 *ppv
= BINDING(This
);
376 }else if(IsEqualGUID(&IID_IInternetProtocolSink
, riid
)) {
377 TRACE("(%p)->(IID_IInternetProtocolSink %p)\n", This
, ppv
);
378 *ppv
= PROTSINK(This
);
379 }else if(IsEqualGUID(&IID_IInternetBindInfo
, riid
)) {
380 TRACE("(%p)->(IID_IInternetBindInfo %p)\n", This
, ppv
);
381 *ppv
= BINDINF(This
);
382 }else if(IsEqualGUID(&IID_IServiceProvider
, riid
)) {
383 TRACE("(%p)->(IID_IServiceProvider %p)\n", This
, ppv
);
384 *ppv
= SERVPROV(This
);
388 IBinding_AddRef(BINDING(This
));
392 WARN("Unsupported interface %s\n", debugstr_guid(riid
));
393 return E_NOINTERFACE
;
396 static ULONG WINAPI
Binding_AddRef(IBinding
*iface
)
398 Binding
*This
= BINDING_THIS(iface
);
399 LONG ref
= InterlockedIncrement(&This
->ref
);
401 TRACE("(%p) ref=%ld\n", This
, ref
);
406 static ULONG WINAPI
Binding_Release(IBinding
*iface
)
408 Binding
*This
= BINDING_THIS(iface
);
409 LONG ref
= InterlockedDecrement(&This
->ref
);
411 TRACE("(%p) ref=%ld\n", This
, ref
);
415 IBindStatusCallback_Release(This
->callback
);
417 IInternetProtocol_Release(This
->protocol
);
418 if(This
->service_provider
)
419 IServiceProvider_Release(This
->service_provider
);
421 IStream_Release(STREAM(This
->stream
));
423 ReleaseBindInfo(&This
->bindinfo
);
424 HeapFree(GetProcessHeap(), 0, This
->mime
);
425 HeapFree(GetProcessHeap(), 0, This
->url
);
427 HeapFree(GetProcessHeap(), 0, This
);
429 URLMON_UnlockModule();
435 static HRESULT WINAPI
Binding_Abort(IBinding
*iface
)
437 Binding
*This
= BINDING_THIS(iface
);
438 FIXME("(%p)\n", This
);
442 static HRESULT WINAPI
Binding_Suspend(IBinding
*iface
)
444 Binding
*This
= BINDING_THIS(iface
);
445 FIXME("(%p)\n", This
);
449 static HRESULT WINAPI
Binding_Resume(IBinding
*iface
)
451 Binding
*This
= BINDING_THIS(iface
);
452 FIXME("(%p)\n", This
);
456 static HRESULT WINAPI
Binding_SetPriority(IBinding
*iface
, LONG nPriority
)
458 Binding
*This
= BINDING_THIS(iface
);
459 FIXME("(%p)->(%ld)\n", This
, nPriority
);
463 static HRESULT WINAPI
Binding_GetPriority(IBinding
*iface
, LONG
*pnPriority
)
465 Binding
*This
= BINDING_THIS(iface
);
466 FIXME("(%p)->(%p)\n", This
, pnPriority
);
470 static HRESULT WINAPI
Binding_GetBindResult(IBinding
*iface
, CLSID
*pclsidProtocol
,
471 DWORD
*pdwResult
, LPOLESTR
*pszResult
, DWORD
*pdwReserved
)
473 Binding
*This
= BINDING_THIS(iface
);
474 FIXME("(%p)->(%p %p %p %p)\n", This
, pclsidProtocol
, pdwResult
, pszResult
, pdwReserved
);
480 static const IBindingVtbl BindingVtbl
= {
481 Binding_QueryInterface
,
489 Binding_GetBindResult
492 #define PROTSINK_THIS(iface) DEFINE_THIS(Binding, InternetProtocolSink, iface)
494 static HRESULT WINAPI
InternetProtocolSink_QueryInterface(IInternetProtocolSink
*iface
,
495 REFIID riid
, void **ppv
)
497 Binding
*This
= PROTSINK_THIS(iface
);
498 return IBinding_QueryInterface(BINDING(This
), riid
, ppv
);
501 static ULONG WINAPI
InternetProtocolSink_AddRef(IInternetProtocolSink
*iface
)
503 Binding
*This
= PROTSINK_THIS(iface
);
504 return IBinding_AddRef(BINDING(This
));
507 static ULONG WINAPI
InternetProtocolSink_Release(IInternetProtocolSink
*iface
)
509 Binding
*This
= PROTSINK_THIS(iface
);
510 return IBinding_Release(BINDING(This
));
513 static HRESULT WINAPI
InternetProtocolSink_Switch(IInternetProtocolSink
*iface
,
514 PROTOCOLDATA
*pProtocolData
)
516 Binding
*This
= PROTSINK_THIS(iface
);
517 FIXME("(%p)->(%p)\n", This
, pProtocolData
);
521 static HRESULT WINAPI
InternetProtocolSink_ReportProgress(IInternetProtocolSink
*iface
,
522 ULONG ulStatusCode
, LPCWSTR szStatusText
)
524 Binding
*This
= PROTSINK_THIS(iface
);
526 TRACE("(%p)->(%lu %s)\n", This
, ulStatusCode
, debugstr_w(szStatusText
));
528 switch(ulStatusCode
) {
529 case BINDSTATUS_MIMETYPEAVAILABLE
: {
530 int len
= strlenW(szStatusText
)+1;
531 This
->mime
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
532 memcpy(This
->mime
, szStatusText
, len
*sizeof(WCHAR
));
535 case BINDSTATUS_SENDINGREQUEST
:
536 IBindStatusCallback_OnProgress(This
->callback
, 0, 0, BINDSTATUS_SENDINGREQUEST
,
539 case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE
:
540 IBindStatusCallback_OnProgress(This
->callback
, 0, 0,
541 BINDSTATUS_MIMETYPEAVAILABLE
, szStatusText
);
543 case BINDSTATUS_CACHEFILENAMEAVAILABLE
:
546 FIXME("Unhandled status code %ld\n", ulStatusCode
);
553 static HRESULT WINAPI
InternetProtocolSink_ReportData(IInternetProtocolSink
*iface
,
554 DWORD grfBSCF
, ULONG ulProgress
, ULONG ulProgressMax
)
556 Binding
*This
= PROTSINK_THIS(iface
);
560 TRACE("(%p)->(%ld %lu %lu)\n", This
, grfBSCF
, ulProgress
, ulProgressMax
);
562 if(grfBSCF
& BSCF_FIRSTDATANOTIFICATION
) {
564 IBindStatusCallback_OnProgress(This
->callback
, ulProgress
, ulProgressMax
,
565 BINDSTATUS_MIMETYPEAVAILABLE
, This
->mime
);
566 IBindStatusCallback_OnProgress(This
->callback
, ulProgress
, ulProgressMax
,
567 BINDSTATUS_BEGINDOWNLOADDATA
, This
->url
);
570 if(grfBSCF
& BSCF_LASTDATANOTIFICATION
)
571 IBindStatusCallback_OnProgress(This
->callback
, ulProgress
, ulProgressMax
,
572 BINDSTATUS_ENDDOWNLOADDATA
, This
->url
);
574 if(grfBSCF
& BSCF_FIRSTDATANOTIFICATION
)
575 IInternetProtocol_LockRequest(This
->protocol
, 0);
577 fill_stream_buffer(This
->stream
);
579 stgmed
.tymed
= TYMED_ISTREAM
;
580 stgmed
.u
.pstm
= STREAM(This
->stream
);
582 formatetc
.cfFormat
= 0; /* FIXME */
583 formatetc
.ptd
= NULL
;
584 formatetc
.dwAspect
= 1;
585 formatetc
.lindex
= -1;
586 formatetc
.tymed
= TYMED_ISTREAM
;
588 IBindStatusCallback_OnDataAvailable(This
->callback
, grfBSCF
, This
->stream
->buf_size
,
589 &formatetc
, &stgmed
);
591 if(grfBSCF
& BSCF_LASTDATANOTIFICATION
)
592 IBindStatusCallback_OnStopBinding(This
->callback
, S_OK
, NULL
);
597 static HRESULT WINAPI
InternetProtocolSink_ReportResult(IInternetProtocolSink
*iface
,
598 HRESULT hrResult
, DWORD dwError
, LPCWSTR szResult
)
600 Binding
*This
= PROTSINK_THIS(iface
);
601 FIXME("(%p)->(%08lx %ld %s)\n", This
, hrResult
, dwError
, debugstr_w(szResult
));
607 static const IInternetProtocolSinkVtbl InternetProtocolSinkVtbl
= {
608 InternetProtocolSink_QueryInterface
,
609 InternetProtocolSink_AddRef
,
610 InternetProtocolSink_Release
,
611 InternetProtocolSink_Switch
,
612 InternetProtocolSink_ReportProgress
,
613 InternetProtocolSink_ReportData
,
614 InternetProtocolSink_ReportResult
617 #define BINDINF_THIS(iface) DEFINE_THIS(Binding, InternetBindInfo, iface)
619 static HRESULT WINAPI
InternetBindInfo_QueryInterface(IInternetBindInfo
*iface
,
620 REFIID riid
, void **ppv
)
622 Binding
*This
= BINDINF_THIS(iface
);
623 return IBinding_QueryInterface(BINDING(This
), riid
, ppv
);
626 static ULONG WINAPI
InternetBindInfo_AddRef(IInternetBindInfo
*iface
)
628 Binding
*This
= BINDINF_THIS(iface
);
629 return IBinding_AddRef(BINDING(This
));
632 static ULONG WINAPI
InternetBindInfo_Release(IInternetBindInfo
*iface
)
634 Binding
*This
= BINDINF_THIS(iface
);
635 return IBinding_Release(BINDING(This
));
638 static HRESULT WINAPI
InternetBindInfo_GetBindInfo(IInternetBindInfo
*iface
,
639 DWORD
*grfBINDF
, BINDINFO
*pbindinfo
)
641 Binding
*This
= BINDINF_THIS(iface
);
643 TRACE("(%p)->(%p %p)\n", This
, grfBINDF
, pbindinfo
);
645 *grfBINDF
= This
->bindf
;
647 memcpy(pbindinfo
, &This
->bindinfo
, sizeof(BINDINFO
));
649 if(pbindinfo
->szExtraInfo
|| pbindinfo
->szCustomVerb
)
650 FIXME("copy strings\n");
653 IUnknown_AddRef(pbindinfo
->pUnk
);
658 static HRESULT WINAPI
InternetBindInfo_GetBindString(IInternetBindInfo
*iface
,
659 ULONG ulStringType
, LPOLESTR
*ppwzStr
, ULONG cEl
, ULONG
*pcElFetched
)
661 Binding
*This
= BINDINF_THIS(iface
);
663 TRACE("(%p)->(%ld %p %ld %p)\n", This
, ulStringType
, ppwzStr
, cEl
, pcElFetched
);
665 switch(ulStringType
) {
666 case BINDSTRING_ACCEPT_MIMES
: {
667 static const WCHAR wszMimes
[] = {'*','/','*',0};
669 if(!ppwzStr
|| !pcElFetched
)
672 ppwzStr
[0] = CoTaskMemAlloc(sizeof(wszMimes
));
673 memcpy(ppwzStr
[0], wszMimes
, sizeof(wszMimes
));
677 case BINDSTRING_USER_AGENT
: {
678 IInternetBindInfo
*bindinfo
= NULL
;
681 hres
= IBindStatusCallback_QueryInterface(This
->callback
, &IID_IInternetBindInfo
,
686 hres
= IInternetBindInfo_GetBindString(bindinfo
, ulStringType
, ppwzStr
,
688 IInternetBindInfo_Release(bindinfo
);
694 FIXME("not supported string type %ld\n", ulStringType
);
700 static const IInternetBindInfoVtbl InternetBindInfoVtbl
= {
701 InternetBindInfo_QueryInterface
,
702 InternetBindInfo_AddRef
,
703 InternetBindInfo_Release
,
704 InternetBindInfo_GetBindInfo
,
705 InternetBindInfo_GetBindString
708 #define SERVPROV_THIS(iface) DEFINE_THIS(Binding, ServiceProvider, iface)
710 static HRESULT WINAPI
ServiceProvider_QueryInterface(IServiceProvider
*iface
,
711 REFIID riid
, void **ppv
)
713 Binding
*This
= SERVPROV_THIS(iface
);
714 return IBinding_QueryInterface(BINDING(This
), riid
, ppv
);
717 static ULONG WINAPI
ServiceProvider_AddRef(IServiceProvider
*iface
)
719 Binding
*This
= SERVPROV_THIS(iface
);
720 return IBinding_AddRef(BINDING(This
));
723 static ULONG WINAPI
ServiceProvider_Release(IServiceProvider
*iface
)
725 Binding
*This
= SERVPROV_THIS(iface
);
726 return IBinding_Release(BINDING(This
));
729 static HRESULT WINAPI
ServiceProvider_QueryService(IServiceProvider
*iface
,
730 REFGUID guidService
, REFIID riid
, void **ppv
)
732 Binding
*This
= SERVPROV_THIS(iface
);
735 TRACE("(%p)->(%s %s %p)\n", This
, debugstr_guid(guidService
), debugstr_guid(riid
), ppv
);
737 if(This
->service_provider
) {
738 hres
= IServiceProvider_QueryService(This
->service_provider
, guidService
,
744 if(IsEqualGUID(&IID_IHttpNegotiate
, guidService
)
745 || IsEqualGUID(&IID_IHttpNegotiate2
, guidService
))
746 return IHttpNegotiate2_QueryInterface(&HttpNegotiate
, riid
, ppv
);
748 WARN("unknown service %s\n", debugstr_guid(guidService
));
754 static const IServiceProviderVtbl ServiceProviderVtbl
= {
755 ServiceProvider_QueryInterface
,
756 ServiceProvider_AddRef
,
757 ServiceProvider_Release
,
758 ServiceProvider_QueryService
761 static HRESULT
get_callback(IBindCtx
*pbc
, IBindStatusCallback
**callback
)
765 static WCHAR wszBSCBHolder
[] = { '_','B','S','C','B','_','H','o','l','d','e','r','_',0 };
767 hres
= IBindCtx_GetObjectParam(pbc
, wszBSCBHolder
, (IUnknown
**)callback
);
774 static HRESULT
get_protocol(Binding
*This
, LPCWSTR url
)
776 IUnknown
*unk
= NULL
;
777 IClassFactory
*cf
= NULL
;
780 hres
= IBindStatusCallback_QueryInterface(This
->callback
, &IID_IInternetProtocol
,
781 (void**)&This
->protocol
);
785 if(This
->service_provider
) {
786 hres
= IServiceProvider_QueryService(This
->service_provider
, &IID_IInternetProtocol
,
787 &IID_IInternetProtocol
, (void**)&This
->protocol
);
792 hres
= get_protocol_handler(url
, &unk
);
796 hres
= IUnknown_QueryInterface(unk
, &IID_IClassFactory
, (void**)&cf
);
797 IUnknown_Release(unk
);
801 hres
= IClassFactory_CreateInstance(cf
, NULL
, &IID_IInternetProtocol
, (void**)&This
->protocol
);
802 IClassFactory_Release(cf
);
807 static HRESULT
Binding_Create(LPCWSTR url
, IBindCtx
*pbc
, REFIID riid
, Binding
**binding
)
813 static const WCHAR wszFile
[] = {'f','i','l','e',':'};
815 if(!IsEqualGUID(&IID_IStream
, riid
)) {
816 FIXME("Unsupported riid %s\n", debugstr_guid(riid
));
822 ret
= HeapAlloc(GetProcessHeap(), 0, sizeof(Binding
));
824 ret
->lpBindingVtbl
= &BindingVtbl
;
825 ret
->lpInternetProtocolSinkVtbl
= &InternetProtocolSinkVtbl
;
826 ret
->lpInternetBindInfoVtbl
= &InternetBindInfoVtbl
;
827 ret
->lpServiceProviderVtbl
= &ServiceProviderVtbl
;
831 ret
->callback
= NULL
;
832 ret
->protocol
= NULL
;
833 ret
->service_provider
= NULL
;
838 memset(&ret
->bindinfo
, 0, sizeof(BINDINFO
));
839 ret
->bindinfo
.cbSize
= sizeof(BINDINFO
);
842 hres
= get_callback(pbc
, &ret
->callback
);
844 WARN("Could not get IBindStatusCallback\n");
845 IBinding_Release(BINDING(ret
));
849 IBindStatusCallback_QueryInterface(ret
->callback
, &IID_IServiceProvider
,
850 (void**)&ret
->service_provider
);
852 hres
= get_protocol(ret
, url
);
854 WARN("Could not get protocol handler\n");
855 IBinding_Release(BINDING(ret
));
859 hres
= IBindStatusCallback_GetBindInfo(ret
->callback
, &ret
->bindf
, &ret
->bindinfo
);
861 WARN("GetBindInfo failed: %08lx\n", hres
);
862 IBinding_Release(BINDING(ret
));
866 ret
->bindf
|= BINDF_FROMURLMON
;
868 len
= strlenW(url
)+1;
870 if(len
< sizeof(wszFile
)/sizeof(WCHAR
) || memcmp(wszFile
, url
, sizeof(wszFile
)))
871 ret
->bindf
|= BINDF_NEEDFILE
;
873 ret
->url
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
874 memcpy(ret
->url
, url
, len
*sizeof(WCHAR
));
876 ret
->stream
= create_stream(ret
->protocol
);
882 HRESULT
start_binding(LPCWSTR url
, IBindCtx
*pbc
, REFIID riid
, void **ppv
)
884 Binding
*binding
= NULL
;
889 hres
= Binding_Create(url
, pbc
, riid
, &binding
);
893 hres
= IBindStatusCallback_OnStartBinding(binding
->callback
, 0, BINDING(binding
));
895 WARN("OnStartBinding failed: %08lx\n", hres
);
896 IBindStatusCallback_OnStopBinding(binding
->callback
, 0x800c0008, NULL
);
897 IBinding_Release(BINDING(binding
));
901 hres
= IInternetProtocol_Start(binding
->protocol
, url
, PROTSINK(binding
),
902 BINDINF(binding
), 0, 0);
903 IInternetProtocol_Terminate(binding
->protocol
, 0);
905 if(SUCCEEDED(hres
)) {
906 IInternetProtocol_UnlockRequest(binding
->protocol
);
908 WARN("Start failed: %08lx\n", hres
);
909 IBindStatusCallback_OnStopBinding(binding
->callback
, S_OK
, NULL
);
912 IStream_AddRef(STREAM(binding
->stream
));
913 *ppv
= binding
->stream
;
915 IBinding_Release(BINDING(binding
));