cryptui: Add Norwegian Bokmål translation.
[wine/hacks.git] / dlls / urlmon / bindctx.c
blob0b3efa6c87433c0d6e2fa2c12585fc3d6c26b0bf
1 /*
2 * Copyright 2007 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include <stdio.h>
21 #include "urlmon_main.h"
22 #include "wine/debug.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
26 static WCHAR BSCBHolder[] = { '_','B','S','C','B','_','H','o','l','d','e','r','_',0 };
28 extern IID IID_IBindStatusCallbackHolder;
30 typedef struct {
31 const IBindStatusCallbackExVtbl *lpBindStatusCallbackExVtbl;
32 const IServiceProviderVtbl *lpServiceProviderVtbl;
33 const IHttpNegotiate2Vtbl *lpHttpNegotiate2Vtbl;
34 const IAuthenticateVtbl *lpAuthenticateVtbl;
36 LONG ref;
38 IBindStatusCallback *callback;
39 IServiceProvider *serv_prov;
40 } BindStatusCallback;
42 #define STATUSCLB(x) ((IBindStatusCallback*) &(x)->lpBindStatusCallbackExVtbl)
43 #define STATUSCLBEX(x) ((IBindStatusCallbackEx*)&(x)->lpBindStatusCallbackExVtbl)
44 #define SERVPROV(x) ((IServiceProvider*) &(x)->lpServiceProviderVtbl)
45 #define HTTPNEG2(x) ((IHttpNegotiate2*) &(x)->lpHttpNegotiate2Vtbl)
46 #define AUTHENTICATE(x) ((IAuthenticate*) &(x)->lpAuthenticateVtbl)
48 static void *get_callback_iface(BindStatusCallback *This, REFIID riid)
50 void *ret;
51 HRESULT hres;
53 hres = IBindStatusCallback_QueryInterface(This->callback, riid, (void**)&ret);
54 if(FAILED(hres) && This->serv_prov)
55 hres = IServiceProvider_QueryService(This->serv_prov, riid, riid, &ret);
57 return SUCCEEDED(hres) ? ret : NULL;
60 #define STATUSCLB_THIS(iface) DEFINE_THIS(BindStatusCallback, BindStatusCallbackEx, iface)
62 static HRESULT WINAPI BindStatusCallback_QueryInterface(IBindStatusCallbackEx *iface,
63 REFIID riid, void **ppv)
65 BindStatusCallback *This = STATUSCLB_THIS(iface);
67 *ppv = NULL;
69 if(IsEqualGUID(&IID_IUnknown, riid)) {
70 TRACE("(%p)->(IID_IUnknown, %p)\n", This, ppv);
71 *ppv = STATUSCLB(This);
72 }else if(IsEqualGUID(&IID_IBindStatusCallback, riid)) {
73 TRACE("(%p)->(IID_IBindStatusCallback, %p)\n", This, ppv);
74 *ppv = STATUSCLB(This);
75 }else if(IsEqualGUID(&IID_IBindStatusCallbackEx, riid)) {
76 TRACE("(%p)->(IID_IBindStatusCallback, %p)\n", This, ppv);
77 *ppv = STATUSCLBEX(This);
78 }else if(IsEqualGUID(&IID_IBindStatusCallbackHolder, riid)) {
79 TRACE("(%p)->(IID_IBindStatusCallbackHolder, %p)\n", This, ppv);
80 *ppv = This;
81 }else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
82 TRACE("(%p)->(IID_IServiceProvider, %p)\n", This, ppv);
83 *ppv = SERVPROV(This);
84 }else if(IsEqualGUID(&IID_IHttpNegotiate, riid)) {
85 TRACE("(%p)->(IID_IHttpNegotiate, %p)\n", This, ppv);
86 *ppv = HTTPNEG2(This);
87 }else if(IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
88 TRACE("(%p)->(IID_IHttpNegotiate2, %p)\n", This, ppv);
89 *ppv = HTTPNEG2(This);
90 }else if(IsEqualGUID(&IID_IAuthenticate, riid)) {
91 TRACE("(%p)->(IID_IAuthenticate, %p)\n", This, ppv);
92 *ppv = AUTHENTICATE(This);
95 if(*ppv) {
96 IBindStatusCallback_AddRef((IUnknown*)*ppv);
97 return S_OK;
100 TRACE("Unsupported riid = %s\n", debugstr_guid(riid));
101 return E_NOINTERFACE;
104 static ULONG WINAPI BindStatusCallback_AddRef(IBindStatusCallbackEx *iface)
106 BindStatusCallback *This = STATUSCLB_THIS(iface);
107 LONG ref = InterlockedIncrement(&This->ref);
109 TRACE("(%p) ref = %d\n", This, ref);
111 return ref;
114 static ULONG WINAPI BindStatusCallback_Release(IBindStatusCallbackEx *iface)
116 BindStatusCallback *This = STATUSCLB_THIS(iface);
117 LONG ref = InterlockedDecrement(&This->ref);
119 TRACE("(%p) ref = %d\n", This, ref);
121 if(!ref) {
122 if(This->serv_prov)
123 IServiceProvider_Release(This->serv_prov);
124 IBindStatusCallback_Release(This->callback);
125 heap_free(This);
128 return ref;
131 static HRESULT WINAPI BindStatusCallback_OnStartBinding(IBindStatusCallbackEx *iface,
132 DWORD dwReserved, IBinding *pbind)
134 BindStatusCallback *This = STATUSCLB_THIS(iface);
136 TRACE("(%p)->(%d %p)\n", This, dwReserved, pbind);
138 return IBindStatusCallback_OnStartBinding(This->callback, 0xff, pbind);
141 static HRESULT WINAPI BindStatusCallback_GetPriority(IBindStatusCallbackEx *iface, LONG *pnPriority)
143 BindStatusCallback *This = STATUSCLB_THIS(iface);
145 TRACE("(%p)->(%p)\n", This, pnPriority);
147 return IBindStatusCallback_GetPriority(This->callback, pnPriority);
150 static HRESULT WINAPI BindStatusCallback_OnLowResource(IBindStatusCallbackEx *iface, DWORD reserved)
152 BindStatusCallback *This = STATUSCLB_THIS(iface);
154 TRACE("(%p)->(%d)\n", This, reserved);
156 return IBindStatusCallback_OnLowResource(This->callback, reserved);
159 static HRESULT WINAPI BindStatusCallback_OnProgress(IBindStatusCallbackEx *iface, ULONG ulProgress,
160 ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
162 BindStatusCallback *This = STATUSCLB_THIS(iface);
164 TRACE("%p)->(%u %u %u %s)\n", This, ulProgress, ulProgressMax, ulStatusCode,
165 debugstr_w(szStatusText));
167 return IBindStatusCallback_OnProgress(This->callback, ulProgress,
168 ulProgressMax, ulStatusCode, szStatusText);
171 static HRESULT WINAPI BindStatusCallback_OnStopBinding(IBindStatusCallbackEx *iface,
172 HRESULT hresult, LPCWSTR szError)
174 BindStatusCallback *This = STATUSCLB_THIS(iface);
176 TRACE("(%p)->(%08x %s)\n", This, hresult, debugstr_w(szError));
178 return IBindStatusCallback_OnStopBinding(This->callback, hresult, szError);
181 static HRESULT WINAPI BindStatusCallback_GetBindInfo(IBindStatusCallbackEx *iface,
182 DWORD *grfBINDF, BINDINFO *pbindinfo)
184 BindStatusCallback *This = STATUSCLB_THIS(iface);
185 IBindStatusCallbackEx *bscex;
186 HRESULT hres;
188 TRACE("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
190 hres = IBindStatusCallback_QueryInterface(This->callback, &IID_IBindStatusCallbackEx, (void**)&bscex);
191 if(SUCCEEDED(hres)) {
192 DWORD bindf2 = 0, reserv = 0;
194 hres = IBindStatusCallbackEx_GetBindInfoEx(bscex, grfBINDF, pbindinfo, &bindf2, &reserv);
195 IBindStatusCallbackEx_Release(bscex);
196 }else {
197 hres = IBindStatusCallback_GetBindInfo(This->callback, grfBINDF, pbindinfo);
200 return hres;
203 static HRESULT WINAPI BindStatusCallback_OnDataAvailable(IBindStatusCallbackEx *iface,
204 DWORD grfBSCF, DWORD dwSize, FORMATETC *pformatetc, STGMEDIUM *pstgmed)
206 BindStatusCallback *This = STATUSCLB_THIS(iface);
208 TRACE("(%p)->(%08x %d %p %p)\n", This, grfBSCF, dwSize, pformatetc, pstgmed);
210 return IBindStatusCallback_OnDataAvailable(This->callback, grfBSCF, dwSize, pformatetc, pstgmed);
213 static HRESULT WINAPI BindStatusCallback_OnObjectAvailable(IBindStatusCallbackEx *iface,
214 REFIID riid, IUnknown *punk)
216 BindStatusCallback *This = STATUSCLB_THIS(iface);
218 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), punk);
220 return IBindStatusCallback_OnObjectAvailable(This->callback, riid, punk);
223 static HRESULT WINAPI BindStatusCallback_GetBindInfoEx(IBindStatusCallbackEx *iface, DWORD *grfBINDF,
224 BINDINFO *pbindinfo, DWORD *grfBINDF2, DWORD *pdwReserved)
226 BindStatusCallback *This = STATUSCLB_THIS(iface);
227 IBindStatusCallbackEx *bscex;
228 HRESULT hres;
230 TRACE("(%p)->(%p %p %p %p)\n", This, grfBINDF, pbindinfo, grfBINDF2, pdwReserved);
232 hres = IBindStatusCallback_QueryInterface(This->callback, &IID_IBindStatusCallbackEx, (void**)&bscex);
233 if(SUCCEEDED(hres)) {
234 hres = IBindStatusCallbackEx_GetBindInfoEx(bscex, grfBINDF, pbindinfo, grfBINDF2, pdwReserved);
235 IBindStatusCallbackEx_Release(bscex);
236 }else {
237 hres = IBindStatusCallback_GetBindInfo(This->callback, grfBINDF, pbindinfo);
240 return hres;
243 #undef STATUSCLB_THIS
245 static const IBindStatusCallbackExVtbl BindStatusCallbackExVtbl = {
246 BindStatusCallback_QueryInterface,
247 BindStatusCallback_AddRef,
248 BindStatusCallback_Release,
249 BindStatusCallback_OnStartBinding,
250 BindStatusCallback_GetPriority,
251 BindStatusCallback_OnLowResource,
252 BindStatusCallback_OnProgress,
253 BindStatusCallback_OnStopBinding,
254 BindStatusCallback_GetBindInfo,
255 BindStatusCallback_OnDataAvailable,
256 BindStatusCallback_OnObjectAvailable,
257 BindStatusCallback_GetBindInfoEx
260 #define SERVPROV_THIS(iface) DEFINE_THIS(BindStatusCallback, ServiceProvider, iface)
262 static HRESULT WINAPI BSCServiceProvider_QueryInterface(IServiceProvider *iface,
263 REFIID riid, void **ppv)
265 BindStatusCallback *This = SERVPROV_THIS(iface);
266 return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv);
269 static ULONG WINAPI BSCServiceProvider_AddRef(IServiceProvider *iface)
271 BindStatusCallback *This = SERVPROV_THIS(iface);
272 return IBindStatusCallback_AddRef(STATUSCLB(This));
275 static ULONG WINAPI BSCServiceProvider_Release(IServiceProvider *iface)
277 BindStatusCallback *This = SERVPROV_THIS(iface);
278 return IBindStatusCallback_Release(STATUSCLB(This));
281 static HRESULT WINAPI BSCServiceProvider_QueryService(IServiceProvider *iface,
282 REFGUID guidService, REFIID riid, void **ppv)
284 BindStatusCallback *This = SERVPROV_THIS(iface);
285 HRESULT hres;
287 if(IsEqualGUID(&IID_IHttpNegotiate, guidService)) {
288 TRACE("(%p)->(IID_IHttpNegotiate %s %p)\n", This, debugstr_guid(riid), ppv);
289 return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv);
292 if(IsEqualGUID(&IID_IHttpNegotiate2, guidService)) {
293 TRACE("(%p)->(IID_IHttpNegotiate2 %s %p)\n", This, debugstr_guid(riid), ppv);
294 return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv);
297 if(IsEqualGUID(&IID_IAuthenticate, guidService)) {
298 TRACE("(%p)->(IID_IAuthenticate %s %p)\n", This, debugstr_guid(riid), ppv);
299 return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv);
302 TRACE("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
304 hres = IBindStatusCallback_QueryInterface(This->callback, riid, ppv);
305 if(SUCCEEDED(hres))
306 return S_OK;
308 if(This->serv_prov) {
309 hres = IServiceProvider_QueryService(This->serv_prov, guidService, riid, ppv);
310 if(SUCCEEDED(hres))
311 return S_OK;
314 return E_NOINTERFACE;
317 #undef SERVPROV_THIS
319 static const IServiceProviderVtbl BSCServiceProviderVtbl = {
320 BSCServiceProvider_QueryInterface,
321 BSCServiceProvider_AddRef,
322 BSCServiceProvider_Release,
323 BSCServiceProvider_QueryService
326 #define HTTPNEG2_THIS(iface) DEFINE_THIS(BindStatusCallback, HttpNegotiate2, iface)
328 static HRESULT WINAPI BSCHttpNegotiate_QueryInterface(IHttpNegotiate2 *iface,
329 REFIID riid, void **ppv)
331 BindStatusCallback *This = HTTPNEG2_THIS(iface);
332 return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv);
335 static ULONG WINAPI BSCHttpNegotiate_AddRef(IHttpNegotiate2 *iface)
337 BindStatusCallback *This = HTTPNEG2_THIS(iface);
338 return IBindStatusCallback_AddRef(STATUSCLB(This));
341 static ULONG WINAPI BSCHttpNegotiate_Release(IHttpNegotiate2 *iface)
343 BindStatusCallback *This = HTTPNEG2_THIS(iface);
344 return IBindStatusCallback_Release(STATUSCLB(This));
347 static HRESULT WINAPI BSCHttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface,
348 LPCWSTR szURL, LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
350 BindStatusCallback *This = HTTPNEG2_THIS(iface);
351 IHttpNegotiate *http_negotiate;
352 HRESULT hres = S_OK;
354 TRACE("(%p)->(%s %s %d %p)\n", This, debugstr_w(szURL), debugstr_w(szHeaders), dwReserved,
355 pszAdditionalHeaders);
357 *pszAdditionalHeaders = NULL;
359 http_negotiate = get_callback_iface(This, &IID_IHttpNegotiate);
360 if(http_negotiate) {
361 hres = IHttpNegotiate_BeginningTransaction(http_negotiate, szURL, szHeaders,
362 dwReserved, pszAdditionalHeaders);
363 IHttpNegotiate_Release(http_negotiate);
366 return hres;
369 static HRESULT WINAPI BSCHttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
370 LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders,
371 LPWSTR *pszAdditionalRequestHeaders)
373 BindStatusCallback *This = HTTPNEG2_THIS(iface);
374 LPWSTR additional_headers = NULL;
375 IHttpNegotiate *http_negotiate;
376 HRESULT hres = S_OK;
378 TRACE("(%p)->(%d %s %s %p)\n", This, dwResponseCode, debugstr_w(szResponseHeaders),
379 debugstr_w(szRequestHeaders), pszAdditionalRequestHeaders);
381 http_negotiate = get_callback_iface(This, &IID_IHttpNegotiate);
382 if(http_negotiate) {
383 hres = IHttpNegotiate_OnResponse(http_negotiate, dwResponseCode, szResponseHeaders,
384 szRequestHeaders, &additional_headers);
385 IHttpNegotiate_Release(http_negotiate);
388 if(pszAdditionalRequestHeaders)
389 *pszAdditionalRequestHeaders = additional_headers;
390 else if(additional_headers)
391 CoTaskMemFree(additional_headers);
393 return hres;
396 static HRESULT WINAPI BSCHttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
397 BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
399 BindStatusCallback *This = HTTPNEG2_THIS(iface);
400 IHttpNegotiate2 *http_negotiate2;
401 HRESULT hres = E_FAIL;
403 TRACE("(%p)->(%p %p %ld)\n", This, pbSecurityId, pcbSecurityId, dwReserved);
405 http_negotiate2 = get_callback_iface(This, &IID_IHttpNegotiate2);
406 if(http_negotiate2) {
407 hres = IHttpNegotiate2_GetRootSecurityId(http_negotiate2, pbSecurityId,
408 pcbSecurityId, dwReserved);
409 IHttpNegotiate2_Release(http_negotiate2);
412 return hres;
415 #undef HTTPNEG2_THIS
417 static const IHttpNegotiate2Vtbl BSCHttpNegotiateVtbl = {
418 BSCHttpNegotiate_QueryInterface,
419 BSCHttpNegotiate_AddRef,
420 BSCHttpNegotiate_Release,
421 BSCHttpNegotiate_BeginningTransaction,
422 BSCHttpNegotiate_OnResponse,
423 BSCHttpNegotiate_GetRootSecurityId
426 #define AUTHENTICATE_THIS(iface) DEFINE_THIS(BindStatusCallback, Authenticate, iface)
428 static HRESULT WINAPI BSCAuthenticate_QueryInterface(IAuthenticate *iface, REFIID riid, void **ppv)
430 BindStatusCallback *This = AUTHENTICATE_THIS(iface);
431 return IBindStatusCallback_QueryInterface(AUTHENTICATE(This), riid, ppv);
434 static ULONG WINAPI BSCAuthenticate_AddRef(IAuthenticate *iface)
436 BindStatusCallback *This = AUTHENTICATE_THIS(iface);
437 return IBindStatusCallback_AddRef(STATUSCLB(This));
440 static ULONG WINAPI BSCAuthenticate_Release(IAuthenticate *iface)
442 BindStatusCallback *This = AUTHENTICATE_THIS(iface);
443 return IBindStatusCallback_Release(STATUSCLB(This));
446 static HRESULT WINAPI BSCAuthenticate_Authenticate(IAuthenticate *iface,
447 HWND *phwnd, LPWSTR *pszUsername, LPWSTR *pszPassword)
449 BindStatusCallback *This = AUTHENTICATE_THIS(iface);
450 FIXME("(%p)->(%p %p %p)\n", This, phwnd, pszUsername, pszPassword);
451 return E_NOTIMPL;
454 #undef AUTHENTICATE_THIS
456 static const IAuthenticateVtbl BSCAuthenticateVtbl = {
457 BSCAuthenticate_QueryInterface,
458 BSCAuthenticate_AddRef,
459 BSCAuthenticate_Release,
460 BSCAuthenticate_Authenticate
463 static IBindStatusCallback *create_bsc(IBindStatusCallback *bsc)
465 BindStatusCallback *ret = heap_alloc_zero(sizeof(BindStatusCallback));
467 ret->lpBindStatusCallbackExVtbl = &BindStatusCallbackExVtbl;
468 ret->lpServiceProviderVtbl = &BSCServiceProviderVtbl;
469 ret->lpHttpNegotiate2Vtbl = &BSCHttpNegotiateVtbl;
470 ret->lpAuthenticateVtbl = &BSCAuthenticateVtbl;
472 ret->ref = 1;
474 IBindStatusCallback_AddRef(bsc);
475 ret->callback = bsc;
477 IBindStatusCallback_QueryInterface(bsc, &IID_IServiceProvider, (void**)&ret->serv_prov);
479 return STATUSCLB(ret);
482 /***********************************************************************
483 * RegisterBindStatusCallback (urlmon.@)
485 * Register a bind status callback.
487 * PARAMS
488 * pbc [I] Binding context
489 * pbsc [I] Callback to register
490 * ppbscPrevious [O] Destination for previous callback
491 * dwReserved [I] Reserved, must be 0.
493 * RETURNS
494 * Success: S_OK.
495 * Failure: E_INVALIDARG, if any argument is invalid, or
496 * E_OUTOFMEMORY if memory allocation fails.
498 HRESULT WINAPI RegisterBindStatusCallback(IBindCtx *pbc, IBindStatusCallback *pbsc,
499 IBindStatusCallback **ppbscPrevious, DWORD dwReserved)
501 BindStatusCallback *holder;
502 IBindStatusCallback *bsc, *prev = NULL;
503 IUnknown *unk;
504 HRESULT hres;
506 TRACE("(%p %p %p %x)\n", pbc, pbsc, ppbscPrevious, dwReserved);
508 if (!pbc || !pbsc)
509 return E_INVALIDARG;
511 hres = IBindCtx_GetObjectParam(pbc, BSCBHolder, &unk);
512 if(SUCCEEDED(hres)) {
513 hres = IUnknown_QueryInterface(unk, &IID_IBindStatusCallback, (void**)&bsc);
514 if(SUCCEEDED(hres)) {
515 hres = IBindStatusCallback_QueryInterface(bsc, &IID_IBindStatusCallbackHolder, (void**)&holder);
516 if(SUCCEEDED(hres)) {
517 prev = holder->callback;
518 IBindStatusCallback_AddRef(prev);
519 IBindStatusCallback_Release(bsc);
520 IBindStatusCallback_Release(STATUSCLB(holder));
521 }else {
522 prev = bsc;
526 IUnknown_Release(unk);
527 IBindCtx_RevokeObjectParam(pbc, BSCBHolder);
530 bsc = create_bsc(pbsc);
531 hres = IBindCtx_RegisterObjectParam(pbc, BSCBHolder, (IUnknown*)bsc);
532 IBindStatusCallback_Release(bsc);
533 if(FAILED(hres)) {
534 if(prev)
535 IBindStatusCallback_Release(prev);
536 return hres;
539 if(ppbscPrevious)
540 *ppbscPrevious = prev;
541 return S_OK;
544 /***********************************************************************
545 * RevokeBindStatusCallback (URLMON.@)
547 * Unregister a bind status callback.
549 * pbc [I] Binding context
550 * pbsc [I] Callback to unregister
552 * RETURNS
553 * Success: S_OK.
554 * Failure: E_INVALIDARG, if any argument is invalid
556 HRESULT WINAPI RevokeBindStatusCallback(IBindCtx *pbc, IBindStatusCallback *pbsc)
558 BindStatusCallback *holder;
559 IBindStatusCallback *callback;
560 IUnknown *unk;
561 BOOL dorevoke = FALSE;
562 HRESULT hres;
564 TRACE("(%p %p)\n", pbc, pbsc);
566 if (!pbc || !pbsc)
567 return E_INVALIDARG;
569 hres = IBindCtx_GetObjectParam(pbc, BSCBHolder, &unk);
570 if(FAILED(hres))
571 return S_OK;
573 hres = IUnknown_QueryInterface(unk, &IID_IBindStatusCallback, (void**)&callback);
574 IUnknown_Release(unk);
575 if(FAILED(hres))
576 return S_OK;
578 hres = IBindStatusCallback_QueryInterface(callback, &IID_IBindStatusCallbackHolder, (void**)&holder);
579 if(SUCCEEDED(hres)) {
580 if(pbsc == holder->callback)
581 dorevoke = TRUE;
582 IBindStatusCallback_Release(STATUSCLB(holder));
583 }else if(pbsc == callback) {
584 dorevoke = TRUE;
586 IBindStatusCallback_Release(callback);
588 if(dorevoke)
589 IBindCtx_RevokeObjectParam(pbc, BSCBHolder);
591 return S_OK;
594 typedef struct {
595 const IBindCtxVtbl *lpBindCtxVtbl;
597 LONG ref;
599 IBindCtx *bindctx;
600 } AsyncBindCtx;
602 #define BINDCTX(x) ((IBindCtx*) &(x)->lpBindCtxVtbl)
604 #define BINDCTX_THIS(iface) DEFINE_THIS(AsyncBindCtx, BindCtx, iface)
606 static HRESULT WINAPI AsyncBindCtx_QueryInterface(IBindCtx *iface, REFIID riid, void **ppv)
608 AsyncBindCtx *This = BINDCTX_THIS(iface);
610 *ppv = NULL;
612 if(IsEqualGUID(riid, &IID_IUnknown)) {
613 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
614 *ppv = BINDCTX(This);
615 }else if(IsEqualGUID(riid, &IID_IBindCtx)) {
616 TRACE("(%p)->(IID_IBindCtx %p)\n", This, ppv);
617 *ppv = BINDCTX(This);
618 }else if(IsEqualGUID(riid, &IID_IAsyncBindCtx)) {
619 TRACE("(%p)->(IID_IAsyncBindCtx %p)\n", This, ppv);
620 *ppv = BINDCTX(This);
623 if(*ppv) {
624 IUnknown_AddRef((IUnknown*)*ppv);
625 return S_OK;
628 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
629 return E_NOINTERFACE;
632 static ULONG WINAPI AsyncBindCtx_AddRef(IBindCtx *iface)
634 AsyncBindCtx *This = BINDCTX_THIS(iface);
635 LONG ref = InterlockedIncrement(&This->ref);
637 TRACE("(%p) ref=%d\n", This, ref);
639 return ref;
642 static ULONG WINAPI AsyncBindCtx_Release(IBindCtx *iface)
644 AsyncBindCtx *This = BINDCTX_THIS(iface);
645 LONG ref = InterlockedDecrement(&This->ref);
647 TRACE("(%p) ref=%d\n", This, ref);
649 if(!ref) {
650 IBindCtx_Release(This->bindctx);
651 heap_free(This);
654 return ref;
657 static HRESULT WINAPI AsyncBindCtx_RegisterObjectBound(IBindCtx *iface, IUnknown *punk)
659 AsyncBindCtx *This = BINDCTX_THIS(iface);
661 TRACE("(%p)->(%p)\n", This, punk);
663 return IBindCtx_RegisterObjectBound(This->bindctx, punk);
666 static HRESULT WINAPI AsyncBindCtx_RevokeObjectBound(IBindCtx *iface, IUnknown *punk)
668 AsyncBindCtx *This = BINDCTX_THIS(iface);
670 TRACE("(%p %p)\n", This, punk);
672 return IBindCtx_RevokeObjectBound(This->bindctx, punk);
675 static HRESULT WINAPI AsyncBindCtx_ReleaseBoundObjects(IBindCtx *iface)
677 AsyncBindCtx *This = BINDCTX_THIS(iface);
679 TRACE("(%p)\n", This);
681 return IBindCtx_ReleaseBoundObjects(This->bindctx);
684 static HRESULT WINAPI AsyncBindCtx_SetBindOptions(IBindCtx *iface, BIND_OPTS *pbindopts)
686 AsyncBindCtx *This = BINDCTX_THIS(iface);
688 TRACE("(%p)->(%p)\n", This, pbindopts);
690 return IBindCtx_SetBindOptions(This->bindctx, pbindopts);
693 static HRESULT WINAPI AsyncBindCtx_GetBindOptions(IBindCtx *iface, BIND_OPTS *pbindopts)
695 AsyncBindCtx *This = BINDCTX_THIS(iface);
697 TRACE("(%p)->(%p)\n", This, pbindopts);
699 return IBindCtx_GetBindOptions(This->bindctx, pbindopts);
702 static HRESULT WINAPI AsyncBindCtx_GetRunningObjectTable(IBindCtx *iface, IRunningObjectTable **pprot)
704 AsyncBindCtx *This = BINDCTX_THIS(iface);
706 TRACE("(%p)->(%p)\n", This, pprot);
708 return IBindCtx_GetRunningObjectTable(This->bindctx, pprot);
711 static HRESULT WINAPI AsyncBindCtx_RegisterObjectParam(IBindCtx *iface, LPOLESTR pszkey, IUnknown *punk)
713 AsyncBindCtx *This = BINDCTX_THIS(iface);
715 TRACE("(%p)->(%s %p)\n", This, debugstr_w(pszkey), punk);
717 return IBindCtx_RegisterObjectParam(This->bindctx, pszkey, punk);
720 static HRESULT WINAPI AsyncBindCtx_GetObjectParam(IBindCtx* iface, LPOLESTR pszkey, IUnknown **punk)
722 AsyncBindCtx *This = BINDCTX_THIS(iface);
724 TRACE("(%p)->(%s %p)\n", This, debugstr_w(pszkey), punk);
726 return IBindCtx_GetObjectParam(This->bindctx, pszkey, punk);
729 static HRESULT WINAPI AsyncBindCtx_RevokeObjectParam(IBindCtx *iface, LPOLESTR pszkey)
731 AsyncBindCtx *This = BINDCTX_THIS(iface);
733 TRACE("(%p)->(%s)\n", This, debugstr_w(pszkey));
735 return IBindCtx_RevokeObjectParam(This->bindctx, pszkey);
738 static HRESULT WINAPI AsyncBindCtx_EnumObjectParam(IBindCtx *iface, IEnumString **pszkey)
740 AsyncBindCtx *This = BINDCTX_THIS(iface);
742 TRACE("(%p)->(%p)\n", This, pszkey);
744 return IBindCtx_EnumObjectParam(This->bindctx, pszkey);
747 #undef BINDCTX_THIS
749 static const IBindCtxVtbl AsyncBindCtxVtbl =
751 AsyncBindCtx_QueryInterface,
752 AsyncBindCtx_AddRef,
753 AsyncBindCtx_Release,
754 AsyncBindCtx_RegisterObjectBound,
755 AsyncBindCtx_RevokeObjectBound,
756 AsyncBindCtx_ReleaseBoundObjects,
757 AsyncBindCtx_SetBindOptions,
758 AsyncBindCtx_GetBindOptions,
759 AsyncBindCtx_GetRunningObjectTable,
760 AsyncBindCtx_RegisterObjectParam,
761 AsyncBindCtx_GetObjectParam,
762 AsyncBindCtx_EnumObjectParam,
763 AsyncBindCtx_RevokeObjectParam
766 static HRESULT init_bindctx(IBindCtx *bindctx, DWORD options,
767 IBindStatusCallback *callback, IEnumFORMATETC *format)
769 BIND_OPTS bindopts;
770 HRESULT hres;
772 if(options)
773 FIXME("not supported options %08x\n", options);
774 if(format)
775 FIXME("format is not supported\n");
777 bindopts.cbStruct = sizeof(BIND_OPTS);
778 bindopts.grfFlags = BIND_MAYBOTHERUSER;
779 bindopts.grfMode = STGM_READWRITE | STGM_SHARE_EXCLUSIVE;
780 bindopts.dwTickCountDeadline = 0;
782 hres = IBindCtx_SetBindOptions(bindctx, &bindopts);
783 if(FAILED(hres))
784 return hres;
786 if(callback) {
787 hres = RegisterBindStatusCallback(bindctx, callback, NULL, 0);
788 if(FAILED(hres))
789 return hres;
792 return S_OK;
795 /***********************************************************************
796 * CreateAsyncBindCtx (urlmon.@)
798 HRESULT WINAPI CreateAsyncBindCtx(DWORD reserved, IBindStatusCallback *callback,
799 IEnumFORMATETC *format, IBindCtx **pbind)
801 IBindCtx *bindctx;
802 HRESULT hres;
804 TRACE("(%08x %p %p %p)\n", reserved, callback, format, pbind);
806 if(!pbind || !callback)
807 return E_INVALIDARG;
809 hres = CreateBindCtx(0, &bindctx);
810 if(FAILED(hres))
811 return hres;
813 hres = init_bindctx(bindctx, 0, callback, format);
814 if(FAILED(hres)) {
815 IBindCtx_Release(bindctx);
816 return hres;
819 *pbind = bindctx;
820 return S_OK;
823 /***********************************************************************
824 * CreateAsyncBindCtxEx (urlmon.@)
826 * Create an asynchronous bind context.
828 HRESULT WINAPI CreateAsyncBindCtxEx(IBindCtx *ibind, DWORD options,
829 IBindStatusCallback *callback, IEnumFORMATETC *format, IBindCtx** pbind,
830 DWORD reserved)
832 AsyncBindCtx *ret;
833 IBindCtx *bindctx;
834 HRESULT hres;
836 TRACE("(%p %08x %p %p %p %d)\n", ibind, options, callback, format, pbind, reserved);
838 if(!pbind)
839 return E_INVALIDARG;
841 if(reserved)
842 WARN("reserved=%d\n", reserved);
844 if(ibind) {
845 IBindCtx_AddRef(ibind);
846 bindctx = ibind;
847 }else {
848 hres = CreateBindCtx(0, &bindctx);
849 if(FAILED(hres))
850 return hres;
853 ret = heap_alloc(sizeof(AsyncBindCtx));
855 ret->lpBindCtxVtbl = &AsyncBindCtxVtbl;
856 ret->ref = 1;
857 ret->bindctx = bindctx;
859 hres = init_bindctx(BINDCTX(ret), options, callback, format);
860 if(FAILED(hres)) {
861 IBindCtx_Release(BINDCTX(ret));
862 return hres;
865 *pbind = BINDCTX(ret);
866 return S_OK;