2008-07-27 19:54:38 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Piotr Caban
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
#define NONAMELESSUNION
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
2011-02-24 13:11:53 +01:00
|
|
|
#ifdef HAVE_LIBXML2
|
|
|
|
# include <libxml/parser.h>
|
|
|
|
# include <libxml/xmlerror.h>
|
|
|
|
#endif
|
|
|
|
|
2008-07-27 19:54:38 +02:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "ole2.h"
|
2010-08-29 23:31:49 +02:00
|
|
|
#include "msxml6.h"
|
2008-07-27 19:54:38 +02:00
|
|
|
#include "wininet.h"
|
|
|
|
#include "urlmon.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "shlwapi.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
#include "msxml_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(msxml);
|
|
|
|
|
|
|
|
struct bsc_t {
|
2011-01-24 00:08:15 +01:00
|
|
|
IBindStatusCallback IBindStatusCallback_iface;
|
2008-07-27 19:54:38 +02:00
|
|
|
|
|
|
|
LONG ref;
|
|
|
|
|
|
|
|
void *obj;
|
|
|
|
HRESULT (*onDataAvailable)(void*,char*,DWORD);
|
|
|
|
|
|
|
|
IBinding *binding;
|
|
|
|
IStream *memstream;
|
2011-10-24 12:55:00 +02:00
|
|
|
HRESULT hres;
|
2008-07-27 19:54:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline bsc_t *impl_from_IBindStatusCallback( IBindStatusCallback *iface )
|
|
|
|
{
|
2011-01-24 00:08:15 +01:00
|
|
|
return CONTAINING_RECORD(iface, bsc_t, IBindStatusCallback_iface);
|
2008-07-27 19:54:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI bsc_QueryInterface(
|
|
|
|
IBindStatusCallback *iface,
|
|
|
|
REFIID riid,
|
|
|
|
LPVOID *ppobj )
|
|
|
|
{
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualGUID(riid, &IID_IBindStatusCallback))
|
|
|
|
{
|
|
|
|
IBindStatusCallback_AddRef( iface );
|
|
|
|
*ppobj = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-16 20:55:52 +02:00
|
|
|
TRACE("interface %s not implemented\n", debugstr_guid(riid));
|
2011-02-28 20:28:53 +01:00
|
|
|
*ppobj = NULL;
|
2008-07-27 19:54:38 +02:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI bsc_AddRef(
|
|
|
|
IBindStatusCallback *iface )
|
|
|
|
{
|
|
|
|
bsc_t *This = impl_from_IBindStatusCallback(iface);
|
|
|
|
LONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI bsc_Release(
|
|
|
|
IBindStatusCallback *iface )
|
|
|
|
{
|
|
|
|
bsc_t *This = impl_from_IBindStatusCallback(iface);
|
|
|
|
LONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
|
|
|
|
|
|
|
if(!ref) {
|
2010-02-03 20:47:53 +01:00
|
|
|
if (This->binding) IBinding_Release(This->binding);
|
|
|
|
if (This->memstream) IStream_Release(This->memstream);
|
|
|
|
heap_free(This);
|
2008-07-27 19:54:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI bsc_OnStartBinding(
|
|
|
|
IBindStatusCallback* iface,
|
|
|
|
DWORD dwReserved,
|
|
|
|
IBinding* pib)
|
|
|
|
{
|
|
|
|
bsc_t *This = impl_from_IBindStatusCallback(iface);
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%x %p)\n", This, dwReserved, pib);
|
|
|
|
|
|
|
|
This->binding = pib;
|
2008-10-11 23:58:19 +02:00
|
|
|
IBinding_AddRef(pib);
|
2008-07-27 19:54:38 +02:00
|
|
|
|
|
|
|
hr = CreateStreamOnHGlobal(NULL, TRUE, &This->memstream);
|
|
|
|
if(FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI bsc_GetPriority(
|
|
|
|
IBindStatusCallback* iface,
|
|
|
|
LONG* pnPriority)
|
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI bsc_OnLowResource(
|
|
|
|
IBindStatusCallback* iface,
|
|
|
|
DWORD reserved)
|
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI bsc_OnProgress(
|
|
|
|
IBindStatusCallback* iface,
|
|
|
|
ULONG ulProgress,
|
|
|
|
ULONG ulProgressMax,
|
|
|
|
ULONG ulStatusCode,
|
|
|
|
LPCWSTR szStatusText)
|
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI bsc_OnStopBinding(
|
|
|
|
IBindStatusCallback* iface,
|
|
|
|
HRESULT hresult,
|
|
|
|
LPCWSTR szError)
|
|
|
|
{
|
|
|
|
bsc_t *This = impl_from_IBindStatusCallback(iface);
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%08x %s)\n", This, hresult, debugstr_w(szError));
|
|
|
|
|
|
|
|
if(This->binding) {
|
|
|
|
IBinding_Release(This->binding);
|
|
|
|
This->binding = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(This->obj && SUCCEEDED(hresult)) {
|
|
|
|
HGLOBAL hglobal;
|
|
|
|
hr = GetHGlobalFromStream(This->memstream, &hglobal);
|
|
|
|
if(SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
DWORD len = GlobalSize(hglobal);
|
|
|
|
char *ptr = GlobalLock(hglobal);
|
|
|
|
|
2013-10-12 20:11:41 +02:00
|
|
|
This->hres = This->onDataAvailable(This->obj, ptr, len);
|
2008-07-27 19:54:38 +02:00
|
|
|
|
|
|
|
GlobalUnlock(hglobal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI bsc_GetBindInfo(
|
|
|
|
IBindStatusCallback* iface,
|
|
|
|
DWORD* grfBINDF,
|
|
|
|
BINDINFO* pbindinfo)
|
|
|
|
{
|
|
|
|
*grfBINDF = BINDF_GETNEWESTVERSION|BINDF_PULLDATA|BINDF_RESYNCHRONIZE|BINDF_PRAGMA_NO_CACHE;
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI bsc_OnDataAvailable(
|
|
|
|
IBindStatusCallback* iface,
|
|
|
|
DWORD grfBSCF,
|
|
|
|
DWORD dwSize,
|
|
|
|
FORMATETC* pformatetc,
|
|
|
|
STGMEDIUM* pstgmed)
|
|
|
|
{
|
|
|
|
bsc_t *This = impl_from_IBindStatusCallback(iface);
|
|
|
|
BYTE buf[4096];
|
|
|
|
DWORD read, written;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%x %d %p %p)\n", This, grfBSCF, dwSize, pformatetc, pstgmed);
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
hr = IStream_Read(pstgmed->u.pstm, buf, sizeof(buf), &read);
|
|
|
|
if(FAILED(hr))
|
|
|
|
break;
|
|
|
|
|
|
|
|
hr = IStream_Write(This->memstream, buf, read, &written);
|
|
|
|
} while(SUCCEEDED(hr) && written != 0 && read != 0);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI bsc_OnObjectAvailable(
|
|
|
|
IBindStatusCallback* iface,
|
|
|
|
REFIID riid,
|
|
|
|
IUnknown* punk)
|
|
|
|
{
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct IBindStatusCallbackVtbl bsc_vtbl =
|
|
|
|
{
|
|
|
|
bsc_QueryInterface,
|
|
|
|
bsc_AddRef,
|
|
|
|
bsc_Release,
|
|
|
|
bsc_OnStartBinding,
|
|
|
|
bsc_GetPriority,
|
|
|
|
bsc_OnLowResource,
|
|
|
|
bsc_OnProgress,
|
|
|
|
bsc_OnStopBinding,
|
|
|
|
bsc_GetBindInfo,
|
|
|
|
bsc_OnDataAvailable,
|
|
|
|
bsc_OnObjectAvailable
|
|
|
|
};
|
|
|
|
|
2020-07-09 09:18:11 +02:00
|
|
|
HRESULT create_uri(IUri *base, const WCHAR *url, IUri **uri)
|
2008-07-27 19:54:38 +02:00
|
|
|
{
|
|
|
|
WCHAR fileUrl[INTERNET_MAX_URL_LENGTH];
|
2020-07-09 09:18:11 +02:00
|
|
|
HRESULT hr;
|
2008-07-27 19:54:38 +02:00
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_w(url));
|
|
|
|
|
2018-01-23 09:27:54 +01:00
|
|
|
if (!PathIsURLW(url))
|
2008-07-27 19:54:38 +02:00
|
|
|
{
|
|
|
|
WCHAR fullpath[MAX_PATH];
|
2018-02-26 23:16:41 +01:00
|
|
|
DWORD needed = ARRAY_SIZE(fileUrl);
|
2008-07-27 19:54:38 +02:00
|
|
|
|
2019-12-08 18:48:50 +01:00
|
|
|
lstrcpynW(fileUrl, url, ARRAY_SIZE(fileUrl));
|
|
|
|
UrlUnescapeW(fileUrl, NULL, NULL, URL_UNESCAPE_INPLACE);
|
|
|
|
|
|
|
|
if (!PathSearchAndQualifyW(fileUrl, fullpath, ARRAY_SIZE(fullpath)))
|
2008-07-27 19:54:38 +02:00
|
|
|
{
|
|
|
|
WARN("can't find path\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2019-12-08 18:48:50 +01:00
|
|
|
if (FAILED(UrlApplySchemeW(fullpath, fileUrl, &needed, URL_APPLY_GUESSSCHEME | URL_APPLY_GUESSFILE |
|
|
|
|
URL_APPLY_DEFAULT)))
|
2008-07-27 19:54:38 +02:00
|
|
|
{
|
2019-12-08 18:48:50 +01:00
|
|
|
ERR("Failed to apply url scheme.\n");
|
2008-07-27 19:54:38 +02:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
url = fileUrl;
|
|
|
|
}
|
|
|
|
|
2020-07-09 09:18:11 +02:00
|
|
|
hr = CreateUri(url, Uri_CREATE_ALLOW_RELATIVE | Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME, 0, uri);
|
|
|
|
if (hr == S_OK && base)
|
|
|
|
{
|
|
|
|
IUri *rebased_uri;
|
|
|
|
|
|
|
|
hr = CoInternetCombineIUri(base, *uri, 0, &rebased_uri, 0);
|
|
|
|
IUri_Release(*uri);
|
|
|
|
*uri = rebased_uri;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2018-01-23 09:27:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT create_moniker_from_url(LPCWSTR url, IMoniker **mon)
|
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
IUri *uri;
|
|
|
|
|
|
|
|
TRACE("%s\n", debugstr_w(url));
|
|
|
|
|
2020-07-09 09:18:11 +02:00
|
|
|
if (FAILED(hr = create_uri(NULL, url, &uri)))
|
2018-01-23 09:27:54 +01:00
|
|
|
return hr;
|
|
|
|
|
|
|
|
hr = CreateURLMonikerEx2(NULL, uri, mon, 0);
|
|
|
|
IUri_Release(uri);
|
|
|
|
return hr;
|
2012-03-12 10:56:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT bind_url(IMoniker *mon, HRESULT (*onDataAvailable)(void*,char*,DWORD),
|
|
|
|
void *obj, bsc_t **ret)
|
|
|
|
{
|
|
|
|
bsc_t *bsc;
|
|
|
|
IBindCtx *pbc;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("%p\n", mon);
|
|
|
|
|
2008-07-27 19:54:38 +02:00
|
|
|
hr = CreateBindCtx(0, &pbc);
|
|
|
|
if(FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
2010-02-03 20:47:53 +01:00
|
|
|
bsc = heap_alloc(sizeof(bsc_t));
|
2008-07-27 19:54:38 +02:00
|
|
|
|
2011-01-24 00:08:15 +01:00
|
|
|
bsc->IBindStatusCallback_iface.lpVtbl = &bsc_vtbl;
|
2008-07-27 19:54:38 +02:00
|
|
|
bsc->ref = 1;
|
|
|
|
bsc->obj = obj;
|
|
|
|
bsc->onDataAvailable = onDataAvailable;
|
|
|
|
bsc->binding = NULL;
|
|
|
|
bsc->memstream = NULL;
|
2011-10-24 12:55:00 +02:00
|
|
|
bsc->hres = S_OK;
|
2008-07-27 19:54:38 +02:00
|
|
|
|
2011-01-24 00:08:15 +01:00
|
|
|
hr = RegisterBindStatusCallback(pbc, &bsc->IBindStatusCallback_iface, NULL, 0);
|
2008-07-27 19:54:38 +02:00
|
|
|
if(SUCCEEDED(hr))
|
|
|
|
{
|
2012-03-12 10:56:59 +01:00
|
|
|
IStream *stream;
|
|
|
|
hr = IMoniker_BindToStorage(mon, pbc, NULL, &IID_IStream, (LPVOID*)&stream);
|
|
|
|
if(stream)
|
|
|
|
IStream_Release(stream);
|
2008-07-27 19:54:38 +02:00
|
|
|
IBindCtx_Release(pbc);
|
|
|
|
}
|
|
|
|
|
2008-10-11 23:58:43 +02:00
|
|
|
if(FAILED(hr))
|
|
|
|
{
|
2011-01-24 00:08:15 +01:00
|
|
|
IBindStatusCallback_Release(&bsc->IBindStatusCallback_iface);
|
2008-10-11 23:58:43 +02:00
|
|
|
bsc = NULL;
|
|
|
|
}
|
|
|
|
|
2008-07-27 19:54:38 +02:00
|
|
|
*ret = bsc;
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2011-10-24 12:55:00 +02:00
|
|
|
HRESULT detach_bsc(bsc_t *bsc)
|
2008-07-27 19:54:38 +02:00
|
|
|
{
|
2011-10-24 12:55:00 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
2008-07-27 19:54:38 +02:00
|
|
|
if(bsc->binding)
|
|
|
|
IBinding_Abort(bsc->binding);
|
|
|
|
|
|
|
|
bsc->obj = NULL;
|
2011-10-24 12:55:00 +02:00
|
|
|
hres = bsc->hres;
|
2011-01-24 00:08:15 +01:00
|
|
|
IBindStatusCallback_Release(&bsc->IBindStatusCallback_iface);
|
2011-10-24 12:55:00 +02:00
|
|
|
|
|
|
|
return hres;
|
2008-07-27 19:54:38 +02:00
|
|
|
}
|