From 2f7da964ace233c3b16417c967e34ddf7c70719c Mon Sep 17 00:00:00 2001 From: Michael Stefaniuc Date: Tue, 11 Jan 2011 00:39:48 +0100 Subject: [PATCH] urlmon: Use ifaces instead of vtbl pointers in BindStatusCallback. --- dlls/urlmon/bindctx.c | 146 +++++++++++++++++++++--------------------- 1 file changed, 72 insertions(+), 74 deletions(-) diff --git a/dlls/urlmon/bindctx.c b/dlls/urlmon/bindctx.c index b08eb80e7a..f04b3e4dde 100644 --- a/dlls/urlmon/bindctx.c +++ b/dlls/urlmon/bindctx.c @@ -28,10 +28,10 @@ static WCHAR BSCBHolder[] = { '_','B','S','C','B','_','H','o','l','d','e','r','_ extern IID IID_IBindStatusCallbackHolder; typedef struct { - const IBindStatusCallbackExVtbl *lpBindStatusCallbackExVtbl; - const IServiceProviderVtbl *lpServiceProviderVtbl; - const IHttpNegotiate2Vtbl *lpHttpNegotiate2Vtbl; - const IAuthenticateVtbl *lpAuthenticateVtbl; + IBindStatusCallbackEx IBindStatusCallbackEx_iface; + IServiceProvider IServiceProvider_iface; + IHttpNegotiate2 IHttpNegotiate2_iface; + IAuthenticate IAuthenticate_iface; LONG ref; @@ -39,12 +39,6 @@ typedef struct { IServiceProvider *serv_prov; } BindStatusCallback; -#define STATUSCLB(x) ((IBindStatusCallback*) &(x)->lpBindStatusCallbackExVtbl) -#define STATUSCLBEX(x) ((IBindStatusCallbackEx*)&(x)->lpBindStatusCallbackExVtbl) -#define SERVPROV(x) ((IServiceProvider*) &(x)->lpServiceProviderVtbl) -#define HTTPNEG2(x) ((IHttpNegotiate2*) &(x)->lpHttpNegotiate2Vtbl) -#define AUTHENTICATE(x) ((IAuthenticate*) &(x)->lpAuthenticateVtbl) - static void *get_callback_iface(BindStatusCallback *This, REFIID riid) { void *ret; @@ -57,39 +51,42 @@ static void *get_callback_iface(BindStatusCallback *This, REFIID riid) return SUCCEEDED(hres) ? ret : NULL; } -#define STATUSCLB_THIS(iface) DEFINE_THIS(BindStatusCallback, BindStatusCallbackEx, iface) +static inline BindStatusCallback *impl_from_IBindStatusCallbackEx(IBindStatusCallbackEx *iface) +{ + return CONTAINING_RECORD(iface, BindStatusCallback, IBindStatusCallbackEx_iface); +} static HRESULT WINAPI BindStatusCallback_QueryInterface(IBindStatusCallbackEx *iface, REFIID riid, void **ppv) { - BindStatusCallback *This = STATUSCLB_THIS(iface); + BindStatusCallback *This = impl_from_IBindStatusCallbackEx(iface); *ppv = NULL; if(IsEqualGUID(&IID_IUnknown, riid)) { TRACE("(%p)->(IID_IUnknown, %p)\n", This, ppv); - *ppv = STATUSCLB(This); + *ppv = &This->IBindStatusCallbackEx_iface; }else if(IsEqualGUID(&IID_IBindStatusCallback, riid)) { TRACE("(%p)->(IID_IBindStatusCallback, %p)\n", This, ppv); - *ppv = STATUSCLB(This); + *ppv = &This->IBindStatusCallbackEx_iface; }else if(IsEqualGUID(&IID_IBindStatusCallbackEx, riid)) { TRACE("(%p)->(IID_IBindStatusCallback, %p)\n", This, ppv); - *ppv = STATUSCLBEX(This); + *ppv = &This->IBindStatusCallbackEx_iface; }else if(IsEqualGUID(&IID_IBindStatusCallbackHolder, riid)) { TRACE("(%p)->(IID_IBindStatusCallbackHolder, %p)\n", This, ppv); *ppv = This; }else if(IsEqualGUID(&IID_IServiceProvider, riid)) { TRACE("(%p)->(IID_IServiceProvider, %p)\n", This, ppv); - *ppv = SERVPROV(This); + *ppv = &This->IServiceProvider_iface; }else if(IsEqualGUID(&IID_IHttpNegotiate, riid)) { TRACE("(%p)->(IID_IHttpNegotiate, %p)\n", This, ppv); - *ppv = HTTPNEG2(This); + *ppv = &This->IHttpNegotiate2_iface; }else if(IsEqualGUID(&IID_IHttpNegotiate2, riid)) { TRACE("(%p)->(IID_IHttpNegotiate2, %p)\n", This, ppv); - *ppv = HTTPNEG2(This); + *ppv = &This->IHttpNegotiate2_iface; }else if(IsEqualGUID(&IID_IAuthenticate, riid)) { TRACE("(%p)->(IID_IAuthenticate, %p)\n", This, ppv); - *ppv = AUTHENTICATE(This); + *ppv = &This->IAuthenticate_iface; } if(*ppv) { @@ -103,7 +100,7 @@ static HRESULT WINAPI BindStatusCallback_QueryInterface(IBindStatusCallbackEx *i static ULONG WINAPI BindStatusCallback_AddRef(IBindStatusCallbackEx *iface) { - BindStatusCallback *This = STATUSCLB_THIS(iface); + BindStatusCallback *This = impl_from_IBindStatusCallbackEx(iface); LONG ref = InterlockedIncrement(&This->ref); TRACE("(%p) ref = %d\n", This, ref); @@ -113,7 +110,7 @@ static ULONG WINAPI BindStatusCallback_AddRef(IBindStatusCallbackEx *iface) static ULONG WINAPI BindStatusCallback_Release(IBindStatusCallbackEx *iface) { - BindStatusCallback *This = STATUSCLB_THIS(iface); + BindStatusCallback *This = impl_from_IBindStatusCallbackEx(iface); LONG ref = InterlockedDecrement(&This->ref); TRACE("(%p) ref = %d\n", This, ref); @@ -131,7 +128,7 @@ static ULONG WINAPI BindStatusCallback_Release(IBindStatusCallbackEx *iface) static HRESULT WINAPI BindStatusCallback_OnStartBinding(IBindStatusCallbackEx *iface, DWORD dwReserved, IBinding *pbind) { - BindStatusCallback *This = STATUSCLB_THIS(iface); + BindStatusCallback *This = impl_from_IBindStatusCallbackEx(iface); TRACE("(%p)->(%d %p)\n", This, dwReserved, pbind); @@ -140,7 +137,7 @@ static HRESULT WINAPI BindStatusCallback_OnStartBinding(IBindStatusCallbackEx *i static HRESULT WINAPI BindStatusCallback_GetPriority(IBindStatusCallbackEx *iface, LONG *pnPriority) { - BindStatusCallback *This = STATUSCLB_THIS(iface); + BindStatusCallback *This = impl_from_IBindStatusCallbackEx(iface); TRACE("(%p)->(%p)\n", This, pnPriority); @@ -149,7 +146,7 @@ static HRESULT WINAPI BindStatusCallback_GetPriority(IBindStatusCallbackEx *ifac static HRESULT WINAPI BindStatusCallback_OnLowResource(IBindStatusCallbackEx *iface, DWORD reserved) { - BindStatusCallback *This = STATUSCLB_THIS(iface); + BindStatusCallback *This = impl_from_IBindStatusCallbackEx(iface); TRACE("(%p)->(%d)\n", This, reserved); @@ -159,7 +156,7 @@ static HRESULT WINAPI BindStatusCallback_OnLowResource(IBindStatusCallbackEx *if static HRESULT WINAPI BindStatusCallback_OnProgress(IBindStatusCallbackEx *iface, ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText) { - BindStatusCallback *This = STATUSCLB_THIS(iface); + BindStatusCallback *This = impl_from_IBindStatusCallbackEx(iface); TRACE("%p)->(%u %u %u %s)\n", This, ulProgress, ulProgressMax, ulStatusCode, debugstr_w(szStatusText)); @@ -171,7 +168,7 @@ static HRESULT WINAPI BindStatusCallback_OnProgress(IBindStatusCallbackEx *iface static HRESULT WINAPI BindStatusCallback_OnStopBinding(IBindStatusCallbackEx *iface, HRESULT hresult, LPCWSTR szError) { - BindStatusCallback *This = STATUSCLB_THIS(iface); + BindStatusCallback *This = impl_from_IBindStatusCallbackEx(iface); TRACE("(%p)->(%08x %s)\n", This, hresult, debugstr_w(szError)); @@ -181,7 +178,7 @@ static HRESULT WINAPI BindStatusCallback_OnStopBinding(IBindStatusCallbackEx *if static HRESULT WINAPI BindStatusCallback_GetBindInfo(IBindStatusCallbackEx *iface, DWORD *grfBINDF, BINDINFO *pbindinfo) { - BindStatusCallback *This = STATUSCLB_THIS(iface); + BindStatusCallback *This = impl_from_IBindStatusCallbackEx(iface); IBindStatusCallbackEx *bscex; HRESULT hres; @@ -203,7 +200,7 @@ static HRESULT WINAPI BindStatusCallback_GetBindInfo(IBindStatusCallbackEx *ifac static HRESULT WINAPI BindStatusCallback_OnDataAvailable(IBindStatusCallbackEx *iface, DWORD grfBSCF, DWORD dwSize, FORMATETC *pformatetc, STGMEDIUM *pstgmed) { - BindStatusCallback *This = STATUSCLB_THIS(iface); + BindStatusCallback *This = impl_from_IBindStatusCallbackEx(iface); TRACE("(%p)->(%08x %d %p %p)\n", This, grfBSCF, dwSize, pformatetc, pstgmed); @@ -213,7 +210,7 @@ static HRESULT WINAPI BindStatusCallback_OnDataAvailable(IBindStatusCallbackEx * static HRESULT WINAPI BindStatusCallback_OnObjectAvailable(IBindStatusCallbackEx *iface, REFIID riid, IUnknown *punk) { - BindStatusCallback *This = STATUSCLB_THIS(iface); + BindStatusCallback *This = impl_from_IBindStatusCallbackEx(iface); TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), punk); @@ -223,7 +220,7 @@ static HRESULT WINAPI BindStatusCallback_OnObjectAvailable(IBindStatusCallbackEx static HRESULT WINAPI BindStatusCallback_GetBindInfoEx(IBindStatusCallbackEx *iface, DWORD *grfBINDF, BINDINFO *pbindinfo, DWORD *grfBINDF2, DWORD *pdwReserved) { - BindStatusCallback *This = STATUSCLB_THIS(iface); + BindStatusCallback *This = impl_from_IBindStatusCallbackEx(iface); IBindStatusCallbackEx *bscex; HRESULT hres; @@ -240,8 +237,6 @@ static HRESULT WINAPI BindStatusCallback_GetBindInfoEx(IBindStatusCallbackEx *if return hres; } -#undef STATUSCLB_THIS - static const IBindStatusCallbackExVtbl BindStatusCallbackExVtbl = { BindStatusCallback_QueryInterface, BindStatusCallback_AddRef, @@ -257,46 +252,49 @@ static const IBindStatusCallbackExVtbl BindStatusCallbackExVtbl = { BindStatusCallback_GetBindInfoEx }; -#define SERVPROV_THIS(iface) DEFINE_THIS(BindStatusCallback, ServiceProvider, iface) +static inline BindStatusCallback *impl_from_IServiceProvider(IServiceProvider *iface) +{ + return CONTAINING_RECORD(iface, BindStatusCallback, IServiceProvider_iface); +} static HRESULT WINAPI BSCServiceProvider_QueryInterface(IServiceProvider *iface, REFIID riid, void **ppv) { - BindStatusCallback *This = SERVPROV_THIS(iface); - return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv); + BindStatusCallback *This = impl_from_IServiceProvider(iface); + return IBindStatusCallback_QueryInterface(&This->IBindStatusCallbackEx_iface, riid, ppv); } static ULONG WINAPI BSCServiceProvider_AddRef(IServiceProvider *iface) { - BindStatusCallback *This = SERVPROV_THIS(iface); - return IBindStatusCallback_AddRef(STATUSCLB(This)); + BindStatusCallback *This = impl_from_IServiceProvider(iface); + return IBindStatusCallback_AddRef(&This->IBindStatusCallbackEx_iface); } static ULONG WINAPI BSCServiceProvider_Release(IServiceProvider *iface) { - BindStatusCallback *This = SERVPROV_THIS(iface); - return IBindStatusCallback_Release(STATUSCLB(This)); + BindStatusCallback *This = impl_from_IServiceProvider(iface); + return IBindStatusCallback_Release(&This->IBindStatusCallbackEx_iface); } static HRESULT WINAPI BSCServiceProvider_QueryService(IServiceProvider *iface, REFGUID guidService, REFIID riid, void **ppv) { - BindStatusCallback *This = SERVPROV_THIS(iface); + BindStatusCallback *This = impl_from_IServiceProvider(iface); HRESULT hres; if(IsEqualGUID(&IID_IHttpNegotiate, guidService)) { TRACE("(%p)->(IID_IHttpNegotiate %s %p)\n", This, debugstr_guid(riid), ppv); - return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv); + return IBindStatusCallback_QueryInterface(&This->IBindStatusCallbackEx_iface, riid, ppv); } if(IsEqualGUID(&IID_IHttpNegotiate2, guidService)) { TRACE("(%p)->(IID_IHttpNegotiate2 %s %p)\n", This, debugstr_guid(riid), ppv); - return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv); + return IBindStatusCallback_QueryInterface(&This->IBindStatusCallbackEx_iface, riid, ppv); } if(IsEqualGUID(&IID_IAuthenticate, guidService)) { TRACE("(%p)->(IID_IAuthenticate %s %p)\n", This, debugstr_guid(riid), ppv); - return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv); + return IBindStatusCallback_QueryInterface(&This->IBindStatusCallbackEx_iface, riid, ppv); } TRACE("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv); @@ -314,8 +312,6 @@ static HRESULT WINAPI BSCServiceProvider_QueryService(IServiceProvider *iface, return E_NOINTERFACE; } -#undef SERVPROV_THIS - static const IServiceProviderVtbl BSCServiceProviderVtbl = { BSCServiceProvider_QueryInterface, BSCServiceProvider_AddRef, @@ -323,31 +319,34 @@ static const IServiceProviderVtbl BSCServiceProviderVtbl = { BSCServiceProvider_QueryService }; -#define HTTPNEG2_THIS(iface) DEFINE_THIS(BindStatusCallback, HttpNegotiate2, iface) +static inline BindStatusCallback *impl_from_IHttpNegotiate2(IHttpNegotiate2 *iface) +{ + return CONTAINING_RECORD(iface, BindStatusCallback, IHttpNegotiate2_iface); +} static HRESULT WINAPI BSCHttpNegotiate_QueryInterface(IHttpNegotiate2 *iface, REFIID riid, void **ppv) { - BindStatusCallback *This = HTTPNEG2_THIS(iface); - return IBindStatusCallback_QueryInterface(STATUSCLB(This), riid, ppv); + BindStatusCallback *This = impl_from_IHttpNegotiate2(iface); + return IBindStatusCallback_QueryInterface(&This->IBindStatusCallbackEx_iface, riid, ppv); } static ULONG WINAPI BSCHttpNegotiate_AddRef(IHttpNegotiate2 *iface) { - BindStatusCallback *This = HTTPNEG2_THIS(iface); - return IBindStatusCallback_AddRef(STATUSCLB(This)); + BindStatusCallback *This = impl_from_IHttpNegotiate2(iface); + return IBindStatusCallback_AddRef(&This->IBindStatusCallbackEx_iface); } static ULONG WINAPI BSCHttpNegotiate_Release(IHttpNegotiate2 *iface) { - BindStatusCallback *This = HTTPNEG2_THIS(iface); - return IBindStatusCallback_Release(STATUSCLB(This)); + BindStatusCallback *This = impl_from_IHttpNegotiate2(iface); + return IBindStatusCallback_Release(&This->IBindStatusCallbackEx_iface); } static HRESULT WINAPI BSCHttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface, LPCWSTR szURL, LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders) { - BindStatusCallback *This = HTTPNEG2_THIS(iface); + BindStatusCallback *This = impl_from_IHttpNegotiate2(iface); IHttpNegotiate *http_negotiate; HRESULT hres = S_OK; @@ -370,7 +369,7 @@ static HRESULT WINAPI BSCHttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders, LPWSTR *pszAdditionalRequestHeaders) { - BindStatusCallback *This = HTTPNEG2_THIS(iface); + BindStatusCallback *This = impl_from_IHttpNegotiate2(iface); LPWSTR additional_headers = NULL; IHttpNegotiate *http_negotiate; HRESULT hres = S_OK; @@ -396,7 +395,7 @@ static HRESULT WINAPI BSCHttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD static HRESULT WINAPI BSCHttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface, BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved) { - BindStatusCallback *This = HTTPNEG2_THIS(iface); + BindStatusCallback *This = impl_from_IHttpNegotiate2(iface); IHttpNegotiate2 *http_negotiate2; HRESULT hres = E_FAIL; @@ -412,8 +411,6 @@ static HRESULT WINAPI BSCHttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface, return hres; } -#undef HTTPNEG2_THIS - static const IHttpNegotiate2Vtbl BSCHttpNegotiateVtbl = { BSCHttpNegotiate_QueryInterface, BSCHttpNegotiate_AddRef, @@ -423,36 +420,37 @@ static const IHttpNegotiate2Vtbl BSCHttpNegotiateVtbl = { BSCHttpNegotiate_GetRootSecurityId }; -#define AUTHENTICATE_THIS(iface) DEFINE_THIS(BindStatusCallback, Authenticate, iface) +static inline BindStatusCallback *impl_from_IAuthenticate(IAuthenticate *iface) +{ + return CONTAINING_RECORD(iface, BindStatusCallback, IAuthenticate_iface); +} static HRESULT WINAPI BSCAuthenticate_QueryInterface(IAuthenticate *iface, REFIID riid, void **ppv) { - BindStatusCallback *This = AUTHENTICATE_THIS(iface); - return IBindStatusCallback_QueryInterface(AUTHENTICATE(This), riid, ppv); + BindStatusCallback *This = impl_from_IAuthenticate(iface); + return IBindStatusCallback_QueryInterface(&This->IAuthenticate_iface, riid, ppv); } static ULONG WINAPI BSCAuthenticate_AddRef(IAuthenticate *iface) { - BindStatusCallback *This = AUTHENTICATE_THIS(iface); - return IBindStatusCallback_AddRef(STATUSCLB(This)); + BindStatusCallback *This = impl_from_IAuthenticate(iface); + return IBindStatusCallback_AddRef(&This->IBindStatusCallbackEx_iface); } static ULONG WINAPI BSCAuthenticate_Release(IAuthenticate *iface) { - BindStatusCallback *This = AUTHENTICATE_THIS(iface); - return IBindStatusCallback_Release(STATUSCLB(This)); + BindStatusCallback *This = impl_from_IAuthenticate(iface); + return IBindStatusCallback_Release(&This->IBindStatusCallbackEx_iface); } static HRESULT WINAPI BSCAuthenticate_Authenticate(IAuthenticate *iface, HWND *phwnd, LPWSTR *pszUsername, LPWSTR *pszPassword) { - BindStatusCallback *This = AUTHENTICATE_THIS(iface); + BindStatusCallback *This = impl_from_IAuthenticate(iface); FIXME("(%p)->(%p %p %p)\n", This, phwnd, pszUsername, pszPassword); return E_NOTIMPL; } -#undef AUTHENTICATE_THIS - static const IAuthenticateVtbl BSCAuthenticateVtbl = { BSCAuthenticate_QueryInterface, BSCAuthenticate_AddRef, @@ -485,15 +483,15 @@ HRESULT wrap_callback(IBindStatusCallback *bsc, IBindStatusCallback **ret_iface) if(!ret) return E_OUTOFMEMORY; - ret->lpBindStatusCallbackExVtbl = &BindStatusCallbackExVtbl; - ret->lpServiceProviderVtbl = &BSCServiceProviderVtbl; - ret->lpHttpNegotiate2Vtbl = &BSCHttpNegotiateVtbl; - ret->lpAuthenticateVtbl = &BSCAuthenticateVtbl; + ret->IBindStatusCallbackEx_iface.lpVtbl = &BindStatusCallbackExVtbl; + ret->IServiceProvider_iface.lpVtbl = &BSCServiceProviderVtbl; + ret->IHttpNegotiate2_iface.lpVtbl = &BSCHttpNegotiateVtbl; + ret->IAuthenticate_iface.lpVtbl = &BSCAuthenticateVtbl; ret->ref = 1; set_callback(ret, bsc); - *ret_iface = STATUSCLB(ret); + *ret_iface = (IBindStatusCallback*)&ret->IBindStatusCallbackEx_iface; return S_OK; } @@ -541,7 +539,7 @@ HRESULT WINAPI RegisterBindStatusCallback(IBindCtx *pbc, IBindStatusCallback *pb set_callback(holder, pbsc); IBindStatusCallback_Release(bsc); - IBindStatusCallback_Release(STATUSCLB(holder)); + IBindStatusCallback_Release(&holder->IBindStatusCallbackEx_iface); return S_OK; }else { prev = bsc; @@ -605,7 +603,7 @@ HRESULT WINAPI RevokeBindStatusCallback(IBindCtx *pbc, IBindStatusCallback *pbsc if(SUCCEEDED(hres)) { if(pbsc == holder->callback) dorevoke = TRUE; - IBindStatusCallback_Release(STATUSCLB(holder)); + IBindStatusCallback_Release(&holder->IBindStatusCallbackEx_iface); }else if(pbsc == callback) { dorevoke = TRUE; }