2005-05-04 12:36:54 +02:00
|
|
|
/*
|
|
|
|
* Based on ../shell32/memorystream.c
|
|
|
|
*
|
|
|
|
* Copyright 1999 Juergen Schmied
|
|
|
|
* Copyright 2003 Mike McCormack for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-05-04 12:36:54 +02:00
|
|
|
*/
|
|
|
|
|
2007-12-13 20:26:51 +01:00
|
|
|
#include "urlmon_main.h"
|
2005-05-04 12:36:54 +02:00
|
|
|
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "winternl.h"
|
|
|
|
#include "wininet.h"
|
|
|
|
#include "shlwapi.h"
|
2007-12-13 20:26:51 +01:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
2005-05-04 12:36:54 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
|
|
|
|
|
2007-08-03 23:11:31 +02:00
|
|
|
typedef struct ProxyBindStatusCallback
|
|
|
|
{
|
2011-01-06 22:21:22 +01:00
|
|
|
IBindStatusCallback IBindStatusCallback_iface;
|
2007-08-03 23:11:31 +02:00
|
|
|
|
|
|
|
IBindStatusCallback *pBSC;
|
|
|
|
} ProxyBindStatusCallback;
|
|
|
|
|
2011-01-06 22:21:22 +01:00
|
|
|
static inline ProxyBindStatusCallback *impl_from_IBindStatusCallback(IBindStatusCallback *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, ProxyBindStatusCallback, IBindStatusCallback_iface);
|
|
|
|
}
|
|
|
|
|
2007-08-03 23:11:31 +02:00
|
|
|
static HRESULT WINAPI ProxyBindStatusCallback_QueryInterface(IBindStatusCallback *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
if (IsEqualGUID(&IID_IBindStatusCallback, riid) ||
|
|
|
|
IsEqualGUID(&IID_IUnknown, riid))
|
|
|
|
{
|
|
|
|
*ppv = iface;
|
2012-07-27 11:15:05 +02:00
|
|
|
IBindStatusCallback_AddRef(iface);
|
2007-08-03 23:11:31 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ProxyBindStatusCallback_AddRef(IBindStatusCallback *iface)
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ProxyBindStatusCallback_Release(IBindStatusCallback *iface)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProxyBindStatusCallback_OnStartBinding(IBindStatusCallback *iface, DWORD dwReserved,
|
|
|
|
IBinding *pib)
|
|
|
|
{
|
2011-01-06 22:21:22 +01:00
|
|
|
ProxyBindStatusCallback *This = impl_from_IBindStatusCallback(iface);
|
2007-11-28 12:20:14 +01:00
|
|
|
|
|
|
|
if(This->pBSC)
|
|
|
|
return IBindStatusCallback_OnStartBinding(This->pBSC, dwReserved, pib);
|
|
|
|
|
|
|
|
return S_OK;
|
2007-08-03 23:11:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProxyBindStatusCallback_GetPriority(IBindStatusCallback *iface, LONG *pnPriority)
|
|
|
|
{
|
2011-01-06 22:21:22 +01:00
|
|
|
ProxyBindStatusCallback *This = impl_from_IBindStatusCallback(iface);
|
2007-11-28 12:20:14 +01:00
|
|
|
|
|
|
|
if(This->pBSC)
|
|
|
|
return IBindStatusCallback_GetPriority(This->pBSC, pnPriority);
|
|
|
|
|
|
|
|
return S_OK;
|
2007-08-03 23:11:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProxyBindStatusCallback_OnLowResource(IBindStatusCallback *iface, DWORD reserved)
|
|
|
|
{
|
2011-01-06 22:21:22 +01:00
|
|
|
ProxyBindStatusCallback *This = impl_from_IBindStatusCallback(iface);
|
2007-11-28 12:20:14 +01:00
|
|
|
|
|
|
|
if(This->pBSC)
|
|
|
|
return IBindStatusCallback_OnLowResource(This->pBSC, reserved);
|
|
|
|
|
|
|
|
return S_OK;
|
2007-08-03 23:11:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProxyBindStatusCallback_OnProgress(IBindStatusCallback *iface, ULONG ulProgress,
|
|
|
|
ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText)
|
|
|
|
{
|
2011-01-06 22:21:22 +01:00
|
|
|
ProxyBindStatusCallback *This = impl_from_IBindStatusCallback(iface);
|
2007-11-28 12:20:14 +01:00
|
|
|
|
|
|
|
if(This->pBSC)
|
|
|
|
return IBindStatusCallback_OnProgress(This->pBSC, ulProgress,
|
2007-08-03 23:11:31 +02:00
|
|
|
ulProgressMax, ulStatusCode,
|
|
|
|
szStatusText);
|
2007-11-28 12:20:14 +01:00
|
|
|
|
|
|
|
return S_OK;
|
2007-08-03 23:11:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProxyBindStatusCallback_OnStopBinding(IBindStatusCallback *iface, HRESULT hresult, LPCWSTR szError)
|
|
|
|
{
|
2011-01-06 22:21:22 +01:00
|
|
|
ProxyBindStatusCallback *This = impl_from_IBindStatusCallback(iface);
|
2007-11-28 12:20:14 +01:00
|
|
|
|
|
|
|
if(This->pBSC)
|
|
|
|
return IBindStatusCallback_OnStopBinding(This->pBSC, hresult, szError);
|
|
|
|
|
|
|
|
return S_OK;
|
2007-08-03 23:11:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProxyBindStatusCallback_GetBindInfo(IBindStatusCallback *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
|
|
|
|
{
|
2016-06-21 21:13:05 +02:00
|
|
|
DWORD size = pbindinfo->cbSize;
|
2011-01-06 22:21:22 +01:00
|
|
|
ProxyBindStatusCallback *This = impl_from_IBindStatusCallback(iface);
|
2007-11-28 12:20:14 +01:00
|
|
|
|
|
|
|
if(This->pBSC)
|
|
|
|
return IBindStatusCallback_GetBindInfo(This->pBSC, grfBINDF, pbindinfo);
|
|
|
|
|
2016-06-21 21:13:05 +02:00
|
|
|
memset(pbindinfo, 0, size);
|
|
|
|
pbindinfo->cbSize = size;
|
|
|
|
|
|
|
|
*grfBINDF = 0;
|
|
|
|
|
|
|
|
return S_OK;
|
2007-08-03 23:11:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProxyBindStatusCallback_OnDataAvailable(IBindStatusCallback *iface, DWORD grfBSCF,
|
|
|
|
DWORD dwSize, FORMATETC* pformatetc, STGMEDIUM* pstgmed)
|
|
|
|
{
|
2011-01-06 22:21:22 +01:00
|
|
|
ProxyBindStatusCallback *This = impl_from_IBindStatusCallback(iface);
|
2007-11-28 12:20:14 +01:00
|
|
|
|
|
|
|
if(This->pBSC)
|
|
|
|
return IBindStatusCallback_OnDataAvailable(This->pBSC, grfBSCF, dwSize,
|
2007-08-03 23:11:31 +02:00
|
|
|
pformatetc, pstgmed);
|
2007-11-28 12:20:14 +01:00
|
|
|
|
|
|
|
return S_OK;
|
2007-08-03 23:11:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProxyBindStatusCallback_OnObjectAvailable(IBindStatusCallback *iface, REFIID riid, IUnknown *punk)
|
|
|
|
{
|
2011-01-06 22:21:22 +01:00
|
|
|
ProxyBindStatusCallback *This = impl_from_IBindStatusCallback(iface);
|
2007-11-28 12:20:14 +01:00
|
|
|
|
|
|
|
if(This->pBSC)
|
|
|
|
return IBindStatusCallback_OnObjectAvailable(This->pBSC, riid, punk);
|
|
|
|
|
|
|
|
return S_OK;
|
2007-08-03 23:11:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI BlockingBindStatusCallback_OnDataAvailable(IBindStatusCallback *iface, DWORD grfBSCF,
|
|
|
|
DWORD dwSize, FORMATETC* pformatetc, STGMEDIUM* pstgmed)
|
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IBindStatusCallbackVtbl BlockingBindStatusCallbackVtbl =
|
|
|
|
{
|
|
|
|
ProxyBindStatusCallback_QueryInterface,
|
|
|
|
ProxyBindStatusCallback_AddRef,
|
|
|
|
ProxyBindStatusCallback_Release,
|
|
|
|
ProxyBindStatusCallback_OnStartBinding,
|
|
|
|
ProxyBindStatusCallback_GetPriority,
|
|
|
|
ProxyBindStatusCallback_OnLowResource,
|
|
|
|
ProxyBindStatusCallback_OnProgress,
|
|
|
|
ProxyBindStatusCallback_OnStopBinding,
|
|
|
|
ProxyBindStatusCallback_GetBindInfo,
|
|
|
|
BlockingBindStatusCallback_OnDataAvailable,
|
|
|
|
ProxyBindStatusCallback_OnObjectAvailable
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT WINAPI AsyncBindStatusCallback_GetBindInfo(IBindStatusCallback *iface, DWORD *grfBINDF, BINDINFO *pbindinfo)
|
|
|
|
{
|
2011-01-06 22:21:22 +01:00
|
|
|
ProxyBindStatusCallback *This = impl_from_IBindStatusCallback(iface);
|
2016-06-21 21:13:09 +02:00
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
if(This->pBSC)
|
|
|
|
hr = IBindStatusCallback_GetBindInfo(This->pBSC, grfBINDF, pbindinfo);
|
|
|
|
else{
|
|
|
|
DWORD size = pbindinfo->cbSize;
|
|
|
|
memset(pbindinfo, 0, size);
|
|
|
|
pbindinfo->cbSize = size;
|
|
|
|
|
|
|
|
*grfBINDF = 0;
|
|
|
|
}
|
|
|
|
|
2007-08-03 23:11:31 +02:00
|
|
|
*grfBINDF |= BINDF_PULLDATA | BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE;
|
2016-06-21 21:13:09 +02:00
|
|
|
|
2007-08-03 23:11:31 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IBindStatusCallbackVtbl AsyncBindStatusCallbackVtbl =
|
|
|
|
{
|
|
|
|
ProxyBindStatusCallback_QueryInterface,
|
|
|
|
ProxyBindStatusCallback_AddRef,
|
|
|
|
ProxyBindStatusCallback_Release,
|
|
|
|
ProxyBindStatusCallback_OnStartBinding,
|
|
|
|
ProxyBindStatusCallback_GetPriority,
|
|
|
|
ProxyBindStatusCallback_OnLowResource,
|
|
|
|
ProxyBindStatusCallback_OnProgress,
|
|
|
|
ProxyBindStatusCallback_OnStopBinding,
|
|
|
|
AsyncBindStatusCallback_GetBindInfo,
|
|
|
|
ProxyBindStatusCallback_OnDataAvailable,
|
|
|
|
ProxyBindStatusCallback_OnObjectAvailable
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT URLStartDownload(LPCWSTR szURL, LPSTREAM *ppStream, IBindStatusCallback *pBSC)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IMoniker *pMoniker;
|
|
|
|
IBindCtx *pbc;
|
|
|
|
|
|
|
|
*ppStream = NULL;
|
|
|
|
|
|
|
|
hr = CreateURLMoniker(NULL, szURL, &pMoniker);
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
hr = CreateBindCtx(0, &pbc);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
IMoniker_Release(pMoniker);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = RegisterBindStatusCallback(pbc, pBSC, NULL, 0);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
IBindCtx_Release(pbc);
|
|
|
|
IMoniker_Release(pMoniker);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IMoniker_BindToStorage(pMoniker, pbc, NULL, &IID_IStream, (void **)ppStream);
|
|
|
|
|
|
|
|
/* BindToStorage returning E_PENDING because it's asynchronous is not an error */
|
|
|
|
if (hr == E_PENDING) hr = S_OK;
|
|
|
|
|
|
|
|
IBindCtx_Release(pbc);
|
|
|
|
IMoniker_Release(pMoniker);
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2007-08-03 23:09:48 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* URLOpenBlockingStreamA (URLMON.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI URLOpenBlockingStreamA(LPUNKNOWN pCaller, LPCSTR szURL,
|
|
|
|
LPSTREAM *ppStream, DWORD dwReserved,
|
|
|
|
LPBINDSTATUSCALLBACK lpfnCB)
|
|
|
|
{
|
2007-08-03 23:11:31 +02:00
|
|
|
LPWSTR szURLW;
|
|
|
|
int len;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p, %s, %p, 0x%x, %p)\n", pCaller, szURL, ppStream, dwReserved, lpfnCB);
|
|
|
|
|
2007-08-03 23:14:15 +02:00
|
|
|
if (!szURL || !ppStream)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2007-08-03 23:11:31 +02:00
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, szURL, -1, NULL, 0);
|
2007-11-29 22:12:34 +01:00
|
|
|
szURLW = heap_alloc(len * sizeof(WCHAR));
|
2007-08-03 23:11:31 +02:00
|
|
|
if (!szURLW)
|
2007-08-03 23:14:15 +02:00
|
|
|
{
|
|
|
|
*ppStream = NULL;
|
2007-08-03 23:11:31 +02:00
|
|
|
return E_OUTOFMEMORY;
|
2007-08-03 23:14:15 +02:00
|
|
|
}
|
2007-08-03 23:11:31 +02:00
|
|
|
MultiByteToWideChar(CP_ACP, 0, szURL, -1, szURLW, len);
|
|
|
|
|
|
|
|
hr = URLOpenBlockingStreamW(pCaller, szURLW, ppStream, dwReserved, lpfnCB);
|
|
|
|
|
2007-11-29 22:12:34 +01:00
|
|
|
heap_free(szURLW);
|
2007-08-03 23:11:31 +02:00
|
|
|
|
|
|
|
return hr;
|
2007-08-03 23:09:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* URLOpenBlockingStreamW (URLMON.@)
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI URLOpenBlockingStreamW(LPUNKNOWN pCaller, LPCWSTR szURL,
|
|
|
|
LPSTREAM *ppStream, DWORD dwReserved,
|
|
|
|
LPBINDSTATUSCALLBACK lpfnCB)
|
|
|
|
{
|
2007-08-03 23:11:31 +02:00
|
|
|
ProxyBindStatusCallback blocking_bsc;
|
|
|
|
|
|
|
|
TRACE("(%p, %s, %p, 0x%x, %p)\n", pCaller, debugstr_w(szURL), ppStream,
|
2007-08-03 23:09:48 +02:00
|
|
|
dwReserved, lpfnCB);
|
2007-08-03 23:11:31 +02:00
|
|
|
|
2007-08-03 23:14:15 +02:00
|
|
|
if (!szURL || !ppStream)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2011-01-06 22:21:22 +01:00
|
|
|
blocking_bsc.IBindStatusCallback_iface.lpVtbl = &BlockingBindStatusCallbackVtbl;
|
2007-08-03 23:11:31 +02:00
|
|
|
blocking_bsc.pBSC = lpfnCB;
|
|
|
|
|
2011-01-06 22:21:22 +01:00
|
|
|
return URLStartDownload(szURL, ppStream, &blocking_bsc.IBindStatusCallback_iface);
|
2007-08-03 23:09:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2007-08-03 23:11:31 +02:00
|
|
|
* URLOpenStreamA (URLMON.@)
|
|
|
|
*/
|
2007-08-03 23:09:48 +02:00
|
|
|
HRESULT WINAPI URLOpenStreamA(LPUNKNOWN pCaller, LPCSTR szURL, DWORD dwReserved,
|
|
|
|
LPBINDSTATUSCALLBACK lpfnCB)
|
|
|
|
{
|
2007-08-03 23:11:31 +02:00
|
|
|
LPWSTR szURLW;
|
|
|
|
int len;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p, %s, 0x%x, %p)\n", pCaller, szURL, dwReserved, lpfnCB);
|
|
|
|
|
2007-08-03 23:14:15 +02:00
|
|
|
if (!szURL)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2007-08-03 23:11:31 +02:00
|
|
|
len = MultiByteToWideChar(CP_ACP, 0, szURL, -1, NULL, 0);
|
2007-11-29 22:12:34 +01:00
|
|
|
szURLW = heap_alloc(len * sizeof(WCHAR));
|
2007-08-03 23:11:31 +02:00
|
|
|
if (!szURLW)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, szURL, -1, szURLW, len);
|
|
|
|
|
|
|
|
hr = URLOpenStreamW(pCaller, szURLW, dwReserved, lpfnCB);
|
|
|
|
|
2007-11-29 22:12:34 +01:00
|
|
|
heap_free(szURLW);
|
2007-08-03 23:11:31 +02:00
|
|
|
|
|
|
|
return hr;
|
2007-08-03 23:09:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2007-08-03 23:11:31 +02:00
|
|
|
* URLOpenStreamW (URLMON.@)
|
|
|
|
*/
|
2007-08-03 23:09:48 +02:00
|
|
|
HRESULT WINAPI URLOpenStreamW(LPUNKNOWN pCaller, LPCWSTR szURL, DWORD dwReserved,
|
|
|
|
LPBINDSTATUSCALLBACK lpfnCB)
|
|
|
|
{
|
2007-08-03 23:11:31 +02:00
|
|
|
HRESULT hr;
|
|
|
|
ProxyBindStatusCallback async_bsc;
|
|
|
|
IStream *pStream;
|
|
|
|
|
|
|
|
TRACE("(%p, %s, 0x%x, %p)\n", pCaller, debugstr_w(szURL), dwReserved,
|
2007-08-03 23:09:48 +02:00
|
|
|
lpfnCB);
|
2007-08-03 23:11:31 +02:00
|
|
|
|
2007-08-03 23:14:15 +02:00
|
|
|
if (!szURL)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2011-01-06 22:21:22 +01:00
|
|
|
async_bsc.IBindStatusCallback_iface.lpVtbl = &AsyncBindStatusCallbackVtbl;
|
2007-08-03 23:11:31 +02:00
|
|
|
async_bsc.pBSC = lpfnCB;
|
|
|
|
|
2011-01-06 22:21:22 +01:00
|
|
|
hr = URLStartDownload(szURL, &pStream, &async_bsc.IBindStatusCallback_iface);
|
2007-08-03 23:11:31 +02:00
|
|
|
if (SUCCEEDED(hr) && pStream)
|
|
|
|
IStream_Release(pStream);
|
|
|
|
|
|
|
|
return hr;
|
2007-08-03 23:09:48 +02:00
|
|
|
}
|