2005-11-14 16:12:43 +01:00
|
|
|
/*
|
2007-02-08 02:32:48 +01:00
|
|
|
* Copyright 2005-2007 Jacek Caban for CodeWeavers
|
2005-11-14 16:12:43 +01:00
|
|
|
*
|
|
|
|
* 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-11-14 16:12:43 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "urlmon_main.h"
|
2007-12-30 17:45:00 +01:00
|
|
|
#include "winreg.h"
|
2010-11-15 12:38:06 +01:00
|
|
|
#include "shlwapi.h"
|
2007-12-30 17:45:00 +01:00
|
|
|
|
2005-11-14 16:12:43 +01:00
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
|
|
|
|
|
2007-12-30 17:44:02 +01:00
|
|
|
static WCHAR cbinding_contextW[] = {'C','B','i','n','d','i','n','g',' ','C','o','n','t','e','x','t',0};
|
2007-12-30 17:45:00 +01:00
|
|
|
static WCHAR bscb_holderW[] = { '_','B','S','C','B','_','H','o','l','d','e','r','_',0 };
|
2007-12-30 17:44:02 +01:00
|
|
|
|
2005-11-14 16:12:43 +01:00
|
|
|
typedef struct {
|
2011-01-11 00:36:45 +01:00
|
|
|
IUnknown IUnknown_iface;
|
2006-05-31 19:45:16 +02:00
|
|
|
|
|
|
|
LONG ref;
|
|
|
|
|
2010-11-15 12:37:03 +01:00
|
|
|
IInternetProtocolEx *protocol;
|
2006-05-31 19:45:16 +02:00
|
|
|
|
2010-05-04 20:13:54 +02:00
|
|
|
HANDLE file;
|
2007-02-10 16:32:44 +01:00
|
|
|
HRESULT hres;
|
2008-01-31 18:17:18 +01:00
|
|
|
|
|
|
|
LPWSTR cache_file;
|
2008-01-31 18:15:11 +01:00
|
|
|
} stgmed_buf_t;
|
|
|
|
|
2008-01-31 18:15:53 +01:00
|
|
|
typedef struct _stgmed_obj_t stgmed_obj_t;
|
2008-01-31 18:15:11 +01:00
|
|
|
|
|
|
|
typedef struct {
|
2008-01-31 18:15:53 +01:00
|
|
|
void (*release)(stgmed_obj_t*);
|
|
|
|
HRESULT (*fill_stgmed)(stgmed_obj_t*,STGMEDIUM*);
|
2010-04-29 17:14:47 +02:00
|
|
|
HRESULT (*get_result)(stgmed_obj_t*,DWORD,void**);
|
2008-01-31 18:15:53 +01:00
|
|
|
} stgmed_obj_vtbl;
|
2008-01-31 18:15:11 +01:00
|
|
|
|
2008-01-31 18:15:53 +01:00
|
|
|
struct _stgmed_obj_t {
|
|
|
|
const stgmed_obj_vtbl *vtbl;
|
|
|
|
};
|
2008-01-31 18:15:11 +01:00
|
|
|
|
2007-08-03 13:35:35 +02:00
|
|
|
typedef enum {
|
|
|
|
BEFORE_DOWNLOAD,
|
|
|
|
DOWNLOADING,
|
|
|
|
END_DOWNLOAD
|
|
|
|
} download_state_t;
|
|
|
|
|
2007-12-30 17:45:00 +01:00
|
|
|
#define BINDING_LOCKED 0x0001
|
|
|
|
#define BINDING_STOPPED 0x0002
|
|
|
|
#define BINDING_OBJAVAIL 0x0004
|
2010-10-06 14:10:25 +02:00
|
|
|
#define BINDING_ABORTED 0x0008
|
2007-12-17 01:38:50 +01:00
|
|
|
|
2011-01-10 18:25:44 +01:00
|
|
|
typedef struct {
|
2011-01-14 23:27:11 +01:00
|
|
|
IBinding IBinding_iface;
|
2011-01-14 23:29:12 +01:00
|
|
|
IInternetProtocolSink IInternetProtocolSink_iface;
|
|
|
|
IInternetBindInfo IInternetBindInfo_iface;
|
|
|
|
IWinInetHttpInfo IWinInetHttpInfo_iface;
|
|
|
|
IServiceProvider IServiceProvider_iface;
|
2005-11-14 16:12:43 +01:00
|
|
|
|
|
|
|
LONG ref;
|
|
|
|
|
|
|
|
IBindStatusCallback *callback;
|
2006-01-05 13:42:32 +01:00
|
|
|
IServiceProvider *service_provider;
|
2008-01-31 18:15:11 +01:00
|
|
|
|
2011-01-10 18:25:44 +01:00
|
|
|
BindProtocol *protocol;
|
|
|
|
|
2008-01-31 18:15:11 +01:00
|
|
|
stgmed_buf_t *stgmed_buf;
|
2008-01-31 18:15:53 +01:00
|
|
|
stgmed_obj_t *stgmed_obj;
|
2005-11-14 16:12:43 +01:00
|
|
|
|
|
|
|
BINDINFO bindinfo;
|
|
|
|
DWORD bindf;
|
2007-12-30 17:45:00 +01:00
|
|
|
BOOL to_object;
|
2005-11-14 16:12:43 +01:00
|
|
|
LPWSTR mime;
|
2007-12-13 20:25:59 +01:00
|
|
|
UINT clipboard_format;
|
2005-11-14 16:12:43 +01:00
|
|
|
LPWSTR url;
|
2009-12-15 21:16:35 +01:00
|
|
|
LPWSTR redirect_url;
|
2007-12-30 17:45:00 +01:00
|
|
|
IID iid;
|
2007-02-08 02:33:32 +01:00
|
|
|
BOOL report_mime;
|
2010-05-04 20:13:54 +02:00
|
|
|
BOOL use_cache_file;
|
2007-12-17 01:38:50 +01:00
|
|
|
DWORD state;
|
2007-12-30 17:43:11 +01:00
|
|
|
HRESULT hres;
|
2012-03-15 12:07:30 +01:00
|
|
|
CLSID clsid;
|
2007-08-03 13:35:35 +02:00
|
|
|
download_state_t download_state;
|
2007-12-30 17:45:00 +01:00
|
|
|
IUnknown *obj;
|
|
|
|
IMoniker *mon;
|
|
|
|
IBindCtx *bctx;
|
2006-05-25 18:35:35 +02:00
|
|
|
HWND notif_hwnd;
|
2006-05-27 22:56:20 +02:00
|
|
|
|
2006-05-31 19:45:16 +02:00
|
|
|
CRITICAL_SECTION section;
|
2011-01-10 18:25:44 +01:00
|
|
|
} Binding;
|
2006-01-09 17:18:06 +01:00
|
|
|
|
2010-05-04 20:13:54 +02:00
|
|
|
static void read_protocol_data(stgmed_buf_t *stgmed_buf)
|
|
|
|
{
|
|
|
|
BYTE buf[8192];
|
|
|
|
DWORD read;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2012-07-27 11:15:05 +02:00
|
|
|
do hres = IInternetProtocolEx_Read(stgmed_buf->protocol, buf, sizeof(buf), &read);
|
2010-05-04 20:13:54 +02:00
|
|
|
while(hres == S_OK);
|
|
|
|
}
|
|
|
|
|
2006-05-27 22:56:40 +02:00
|
|
|
static void dump_BINDINFO(BINDINFO *bi)
|
|
|
|
{
|
2006-11-29 11:03:44 +01:00
|
|
|
static const char * const BINDINFOF_str[] = {
|
2006-05-27 22:56:40 +02:00
|
|
|
"#0",
|
|
|
|
"BINDINFOF_URLENCODESTGMEDDATA",
|
|
|
|
"BINDINFOF_URLENCODEDEXTRAINFO"
|
|
|
|
};
|
|
|
|
|
2006-11-29 11:03:44 +01:00
|
|
|
static const char * const BINDVERB_str[] = {
|
2006-05-27 22:56:40 +02:00
|
|
|
"BINDVERB_GET",
|
|
|
|
"BINDVERB_POST",
|
|
|
|
"BINDVERB_PUT",
|
|
|
|
"BINDVERB_CUSTOM"
|
|
|
|
};
|
|
|
|
|
|
|
|
TRACE("\n"
|
|
|
|
"BINDINFO = {\n"
|
2006-10-05 23:49:11 +02:00
|
|
|
" %d, %s,\n"
|
|
|
|
" {%d, %p, %p},\n"
|
2006-05-27 22:56:40 +02:00
|
|
|
" %s,\n"
|
|
|
|
" %s,\n"
|
|
|
|
" %s,\n"
|
2006-10-05 23:49:11 +02:00
|
|
|
" %d, %08x, %d, %d\n"
|
|
|
|
" {%d %p %x},\n"
|
2006-05-27 22:56:40 +02:00
|
|
|
" %s\n"
|
2006-10-05 23:49:11 +02:00
|
|
|
" %p, %d\n"
|
2006-05-27 22:56:40 +02:00
|
|
|
"}\n",
|
|
|
|
|
|
|
|
bi->cbSize, debugstr_w(bi->szExtraInfo),
|
|
|
|
bi->stgmedData.tymed, bi->stgmedData.u.hGlobal, bi->stgmedData.pUnkForRelease,
|
|
|
|
bi->grfBindInfoF > BINDINFOF_URLENCODEDEXTRAINFO
|
|
|
|
? "unknown" : BINDINFOF_str[bi->grfBindInfoF],
|
|
|
|
bi->dwBindVerb > BINDVERB_CUSTOM
|
|
|
|
? "unknown" : BINDVERB_str[bi->dwBindVerb],
|
|
|
|
debugstr_w(bi->szCustomVerb),
|
2006-09-29 12:42:10 +02:00
|
|
|
bi->cbstgmedData, bi->dwOptions, bi->dwOptionsFlags, bi->dwCodePage,
|
2006-05-27 22:56:40 +02:00
|
|
|
bi->securityAttributes.nLength,
|
|
|
|
bi->securityAttributes.lpSecurityDescriptor,
|
|
|
|
bi->securityAttributes.bInheritHandle,
|
|
|
|
debugstr_guid(&bi->iid),
|
|
|
|
bi->pUnk, bi->dwReserved
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2009-05-14 00:49:33 +02:00
|
|
|
static void mime_available(Binding *This, LPCWSTR mime)
|
2007-12-13 20:25:59 +01:00
|
|
|
{
|
2009-05-14 00:49:33 +02:00
|
|
|
heap_free(This->mime);
|
|
|
|
This->mime = heap_strdupW(mime);
|
2007-12-13 20:25:59 +01:00
|
|
|
|
2009-05-14 00:49:33 +02:00
|
|
|
if(!This->mime || !This->report_mime)
|
2007-12-13 20:25:59 +01:00
|
|
|
return;
|
|
|
|
|
2009-05-14 00:49:33 +02:00
|
|
|
IBindStatusCallback_OnProgress(This->callback, 0, 0, BINDSTATUS_MIMETYPEAVAILABLE, This->mime);
|
2007-12-13 20:25:59 +01:00
|
|
|
|
2009-05-14 00:49:33 +02:00
|
|
|
This->clipboard_format = RegisterClipboardFormatW(This->mime);
|
2007-12-13 20:25:59 +01:00
|
|
|
}
|
|
|
|
|
2007-12-30 17:43:11 +01:00
|
|
|
static void stop_binding(Binding *binding, HRESULT hres, LPCWSTR str)
|
|
|
|
{
|
|
|
|
if(binding->state & BINDING_LOCKED) {
|
2011-01-12 00:43:44 +01:00
|
|
|
IInternetProtocolEx_UnlockRequest(&binding->protocol->IInternetProtocolEx_iface);
|
2007-12-30 17:43:11 +01:00
|
|
|
binding->state &= ~BINDING_LOCKED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!(binding->state & BINDING_STOPPED)) {
|
|
|
|
binding->state |= BINDING_STOPPED;
|
|
|
|
|
|
|
|
binding->hres = hres;
|
2012-03-15 12:07:30 +01:00
|
|
|
IBindStatusCallback_OnStopBinding(binding->callback, hres, str);
|
2007-12-30 17:43:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-30 17:45:00 +01:00
|
|
|
static LPWSTR get_mime_clsid(LPCWSTR mime, CLSID *clsid)
|
|
|
|
{
|
|
|
|
LPWSTR key_name, ret;
|
|
|
|
DWORD res, type, size;
|
|
|
|
HKEY hkey;
|
|
|
|
int len;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
static const WCHAR mime_keyW[] =
|
|
|
|
{'M','I','M','E','\\','D','a','t','a','b','a','s','e','\\',
|
|
|
|
'C','o','n','t','e','n','t',' ','T','y','p','e','\\'};
|
|
|
|
static const WCHAR clsidW[] = {'C','L','S','I','D',0};
|
|
|
|
|
|
|
|
len = strlenW(mime)+1;
|
|
|
|
key_name = heap_alloc(sizeof(mime_keyW) + len*sizeof(WCHAR));
|
|
|
|
memcpy(key_name, mime_keyW, sizeof(mime_keyW));
|
|
|
|
strcpyW(key_name + sizeof(mime_keyW)/sizeof(WCHAR), mime);
|
|
|
|
|
|
|
|
res = RegOpenKeyW(HKEY_CLASSES_ROOT, key_name, &hkey);
|
|
|
|
heap_free(key_name);
|
|
|
|
if(res != ERROR_SUCCESS) {
|
|
|
|
WARN("Could not open MIME key: %x\n", res);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = 50*sizeof(WCHAR);
|
|
|
|
ret = heap_alloc(size);
|
|
|
|
res = RegQueryValueExW(hkey, clsidW, NULL, &type, (LPBYTE)ret, &size);
|
|
|
|
RegCloseKey(hkey);
|
|
|
|
if(res != ERROR_SUCCESS) {
|
|
|
|
WARN("Could not get CLSID: %08x\n", res);
|
|
|
|
heap_free(ret);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = CLSIDFromString(ret, clsid);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
WARN("Could not parse CLSID: %08x\n", hres);
|
|
|
|
heap_free(ret);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void load_doc_mon(Binding *binding, IPersistMoniker *persist)
|
|
|
|
{
|
|
|
|
IBindCtx *bctx;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = CreateAsyncBindCtxEx(binding->bctx, 0, NULL, NULL, &bctx, 0);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
WARN("CreateAsyncBindCtxEx failed: %08x\n", hres);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
IBindCtx_RevokeObjectParam(bctx, bscb_holderW);
|
2011-01-14 23:27:11 +01:00
|
|
|
IBindCtx_RegisterObjectParam(bctx, cbinding_contextW, (IUnknown*)&binding->IBinding_iface);
|
2007-12-30 17:45:00 +01:00
|
|
|
|
|
|
|
hres = IPersistMoniker_Load(persist, binding->download_state == END_DOWNLOAD, binding->mon, bctx, 0x12);
|
|
|
|
IBindCtx_RevokeObjectParam(bctx, cbinding_contextW);
|
|
|
|
IBindCtx_Release(bctx);
|
|
|
|
if(FAILED(hres))
|
|
|
|
FIXME("Load failed: %08x\n", hres);
|
|
|
|
}
|
|
|
|
|
2008-02-22 02:09:12 +01:00
|
|
|
static HRESULT create_mime_object(Binding *binding, const CLSID *clsid, LPCWSTR clsid_str)
|
2007-12-30 17:45:00 +01:00
|
|
|
{
|
|
|
|
IPersistMoniker *persist;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2008-02-22 02:09:12 +01:00
|
|
|
hres = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER|CLSCTX_INPROC_HANDLER,
|
2007-12-30 17:45:00 +01:00
|
|
|
&binding->iid, (void**)&binding->obj);
|
2008-02-22 02:09:12 +01:00
|
|
|
if(FAILED(hres)) {
|
|
|
|
WARN("CoCreateInstance failed: %08x\n", hres);
|
|
|
|
return INET_E_CANNOT_INSTANTIATE_OBJECT;
|
|
|
|
}
|
2007-12-30 17:45:00 +01:00
|
|
|
|
|
|
|
binding->state |= BINDING_OBJAVAIL;
|
|
|
|
|
|
|
|
hres = IUnknown_QueryInterface(binding->obj, &IID_IPersistMoniker, (void**)&persist);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
IMonikerProp *prop;
|
|
|
|
|
|
|
|
hres = IPersistMoniker_QueryInterface(persist, &IID_IMonikerProp, (void**)&prop);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
IMonikerProp_PutProperty(prop, MIMETYPEPROP, binding->mime);
|
|
|
|
IMonikerProp_PutProperty(prop, CLASSIDPROP, clsid_str);
|
|
|
|
IMonikerProp_Release(prop);
|
|
|
|
}
|
|
|
|
|
|
|
|
load_doc_mon(binding, persist);
|
|
|
|
|
|
|
|
IPersistMoniker_Release(persist);
|
|
|
|
}else {
|
|
|
|
FIXME("Could not get IPersistMoniker: %08x\n", hres);
|
|
|
|
/* FIXME: Try query IPersistFile */
|
|
|
|
}
|
|
|
|
|
|
|
|
IBindStatusCallback_OnObjectAvailable(binding->callback, &binding->iid, binding->obj);
|
|
|
|
|
2008-02-22 02:09:12 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void create_object(Binding *binding)
|
|
|
|
{
|
|
|
|
LPWSTR clsid_str;
|
|
|
|
CLSID clsid;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
if(!binding->mime) {
|
|
|
|
FIXME("MIME not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!(clsid_str = get_mime_clsid(binding->mime, &clsid))) {
|
|
|
|
FIXME("Could not find object for MIME %s\n", debugstr_w(binding->mime));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
IBindStatusCallback_OnProgress(binding->callback, 0, 0, BINDSTATUS_CLASSIDAVAILABLE, clsid_str);
|
|
|
|
IBindStatusCallback_OnProgress(binding->callback, 0, 0, BINDSTATUS_BEGINSYNCOPERATION, NULL);
|
|
|
|
|
|
|
|
hres = create_mime_object(binding, &clsid, clsid_str);
|
|
|
|
heap_free(clsid_str);
|
|
|
|
|
2007-12-30 17:45:00 +01:00
|
|
|
IBindStatusCallback_OnProgress(binding->callback, 0, 0, BINDSTATUS_ENDSYNCOPERATION, NULL);
|
2012-03-15 12:07:30 +01:00
|
|
|
binding->clsid = CLSID_NULL;
|
2007-12-30 17:45:00 +01:00
|
|
|
|
2008-02-22 02:09:12 +01:00
|
|
|
stop_binding(binding, hres, NULL);
|
|
|
|
if(FAILED(hres))
|
2011-01-12 00:43:44 +01:00
|
|
|
IInternetProtocolEx_Terminate(&binding->protocol->IInternetProtocolEx_iface, 0);
|
2007-12-30 17:45:00 +01:00
|
|
|
}
|
|
|
|
|
2010-05-04 20:13:54 +02:00
|
|
|
static void cache_file_available(Binding *This, const WCHAR *file_name)
|
|
|
|
{
|
|
|
|
heap_free(This->stgmed_buf->cache_file);
|
|
|
|
This->stgmed_buf->cache_file = heap_strdupW(file_name);
|
|
|
|
|
|
|
|
if(This->use_cache_file) {
|
|
|
|
This->stgmed_buf->file = CreateFileW(file_name, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
|
|
|
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
if(This->stgmed_buf->file == INVALID_HANDLE_VALUE)
|
|
|
|
WARN("CreateFile failed: %u\n", GetLastError());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-11 00:36:45 +01:00
|
|
|
static inline stgmed_buf_t *impl_from_IUnknown(IUnknown *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, stgmed_buf_t, IUnknown_iface);
|
|
|
|
}
|
2008-01-31 18:15:11 +01:00
|
|
|
|
|
|
|
static HRESULT WINAPI StgMedUnk_QueryInterface(IUnknown *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
2011-01-11 00:36:45 +01:00
|
|
|
stgmed_buf_t *This = impl_from_IUnknown(iface);
|
2008-01-31 18:15:11 +01:00
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if(IsEqualGUID(riid, &IID_IUnknown)) {
|
|
|
|
TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
|
|
|
|
|
2011-01-11 00:36:45 +01:00
|
|
|
*ppv = &This->IUnknown_iface;
|
|
|
|
IUnknown_AddRef(&This->IUnknown_iface);
|
2008-01-31 18:15:11 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI StgMedUnk_AddRef(IUnknown *iface)
|
|
|
|
{
|
2011-01-11 00:36:45 +01:00
|
|
|
stgmed_buf_t *This = impl_from_IUnknown(iface);
|
2008-01-31 18:15:11 +01:00
|
|
|
LONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI StgMedUnk_Release(IUnknown *iface)
|
|
|
|
{
|
2011-01-11 00:36:45 +01:00
|
|
|
stgmed_buf_t *This = impl_from_IUnknown(iface);
|
2008-01-31 18:15:11 +01:00
|
|
|
LONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
|
|
|
|
|
|
|
if(!ref) {
|
2010-05-04 20:13:54 +02:00
|
|
|
if(This->file != INVALID_HANDLE_VALUE)
|
|
|
|
CloseHandle(This->file);
|
2012-07-27 11:15:05 +02:00
|
|
|
IInternetProtocolEx_Release(This->protocol);
|
2008-01-31 18:17:18 +01:00
|
|
|
heap_free(This->cache_file);
|
2008-01-31 18:15:11 +01:00
|
|
|
heap_free(This);
|
|
|
|
|
|
|
|
URLMON_UnlockModule();
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IUnknownVtbl StgMedUnkVtbl = {
|
|
|
|
StgMedUnk_QueryInterface,
|
|
|
|
StgMedUnk_AddRef,
|
|
|
|
StgMedUnk_Release
|
|
|
|
};
|
|
|
|
|
2010-11-15 12:37:03 +01:00
|
|
|
static stgmed_buf_t *create_stgmed_buf(IInternetProtocolEx *protocol)
|
2008-01-31 18:15:53 +01:00
|
|
|
{
|
|
|
|
stgmed_buf_t *ret = heap_alloc(sizeof(*ret));
|
|
|
|
|
2011-01-11 00:36:45 +01:00
|
|
|
ret->IUnknown_iface.lpVtbl = &StgMedUnkVtbl;
|
2008-01-31 18:15:53 +01:00
|
|
|
ret->ref = 1;
|
2010-05-04 20:13:54 +02:00
|
|
|
ret->file = INVALID_HANDLE_VALUE;
|
2008-01-31 18:15:53 +01:00
|
|
|
ret->hres = S_OK;
|
2008-01-31 18:17:18 +01:00
|
|
|
ret->cache_file = NULL;
|
2008-01-31 18:15:53 +01:00
|
|
|
|
2012-07-27 11:15:05 +02:00
|
|
|
IInternetProtocolEx_AddRef(protocol);
|
2008-01-31 18:15:53 +01:00
|
|
|
ret->protocol = protocol;
|
|
|
|
|
|
|
|
URLMON_LockModule();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
stgmed_obj_t stgmed_obj;
|
2011-01-14 23:31:13 +01:00
|
|
|
IStream IStream_iface;
|
2008-01-31 18:15:53 +01:00
|
|
|
|
|
|
|
LONG ref;
|
|
|
|
|
|
|
|
stgmed_buf_t *buf;
|
|
|
|
} ProtocolStream;
|
|
|
|
|
2011-01-14 23:31:13 +01:00
|
|
|
static inline ProtocolStream *impl_from_IStream(IStream *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, ProtocolStream, IStream_iface);
|
|
|
|
}
|
2006-01-09 17:18:06 +01:00
|
|
|
|
|
|
|
static HRESULT WINAPI ProtocolStream_QueryInterface(IStream *iface,
|
|
|
|
REFIID riid, void **ppv)
|
|
|
|
{
|
2011-01-14 23:31:13 +01:00
|
|
|
ProtocolStream *This = impl_from_IStream(iface);
|
2006-01-09 17:18:06 +01:00
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if(IsEqualGUID(&IID_IUnknown, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
|
2011-01-14 23:31:13 +01:00
|
|
|
*ppv = &This->IStream_iface;
|
2006-01-09 17:18:06 +01:00
|
|
|
}else if(IsEqualGUID(&IID_ISequentialStream, riid)) {
|
|
|
|
TRACE("(%p)->(IID_ISequentialStream %p)\n", This, ppv);
|
2011-01-14 23:31:13 +01:00
|
|
|
*ppv = &This->IStream_iface;
|
2006-01-09 17:18:06 +01:00
|
|
|
}else if(IsEqualGUID(&IID_IStream, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IStream %p)\n", This, ppv);
|
2011-01-14 23:31:13 +01:00
|
|
|
*ppv = &This->IStream_iface;
|
2006-01-09 17:18:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if(*ppv) {
|
2011-01-14 23:31:13 +01:00
|
|
|
IStream_AddRef(&This->IStream_iface);
|
2006-01-09 17:18:06 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ProtocolStream_AddRef(IStream *iface)
|
|
|
|
{
|
2011-01-14 23:31:13 +01:00
|
|
|
ProtocolStream *This = impl_from_IStream(iface);
|
2006-01-09 17:18:06 +01:00
|
|
|
LONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
2006-10-05 23:49:11 +02:00
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
2006-01-09 17:18:06 +01:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ProtocolStream_Release(IStream *iface)
|
|
|
|
{
|
2011-01-14 23:31:13 +01:00
|
|
|
ProtocolStream *This = impl_from_IStream(iface);
|
2006-01-09 17:18:06 +01:00
|
|
|
LONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
2006-10-05 23:49:11 +02:00
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
2006-01-09 17:18:06 +01:00
|
|
|
|
|
|
|
if(!ref) {
|
2011-01-11 00:36:45 +01:00
|
|
|
IUnknown_Release(&This->buf->IUnknown_iface);
|
2007-11-29 22:12:34 +01:00
|
|
|
heap_free(This);
|
2006-01-09 17:20:04 +01:00
|
|
|
|
|
|
|
URLMON_UnlockModule();
|
2006-01-09 17:18:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProtocolStream_Read(IStream *iface, void *pv,
|
2008-01-31 18:15:11 +01:00
|
|
|
ULONG cb, ULONG *pcbRead)
|
2006-01-09 17:18:06 +01:00
|
|
|
{
|
2011-01-14 23:31:13 +01:00
|
|
|
ProtocolStream *This = impl_from_IStream(iface);
|
2011-02-15 17:02:29 +01:00
|
|
|
DWORD read = 0;
|
2008-01-31 18:15:11 +01:00
|
|
|
HRESULT hres;
|
2006-01-09 17:18:06 +01:00
|
|
|
|
2006-10-05 23:49:11 +02:00
|
|
|
TRACE("(%p)->(%p %d %p)\n", This, pv, cb, pcbRead);
|
2006-01-09 17:18:06 +01:00
|
|
|
|
2011-02-15 17:02:29 +01:00
|
|
|
if(This->buf->file == INVALID_HANDLE_VALUE) {
|
2012-07-27 11:15:05 +02:00
|
|
|
hres = This->buf->hres = IInternetProtocolEx_Read(This->buf->protocol, (PBYTE)pv, cb, &read);
|
2011-02-15 17:02:29 +01:00
|
|
|
}else {
|
|
|
|
hres = ReadFile(This->buf->file, pv, cb, &read, NULL) ? S_OK : INET_E_DOWNLOAD_FAILURE;
|
2006-01-09 17:18:06 +01:00
|
|
|
}
|
|
|
|
|
2007-08-03 23:10:55 +02:00
|
|
|
if (pcbRead)
|
2011-02-15 17:02:29 +01:00
|
|
|
*pcbRead = read;
|
2006-01-09 17:18:06 +01:00
|
|
|
|
2008-01-31 18:15:11 +01:00
|
|
|
if(hres == E_PENDING)
|
2006-05-25 18:40:47 +02:00
|
|
|
return E_PENDING;
|
2008-01-31 18:15:11 +01:00
|
|
|
else if(FAILED(hres))
|
|
|
|
FIXME("Read failed: %08x\n", hres);
|
2006-05-25 18:40:47 +02:00
|
|
|
|
2011-02-15 17:02:29 +01:00
|
|
|
return read ? S_OK : S_FALSE;
|
2006-01-09 17:18:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProtocolStream_Write(IStream *iface, const void *pv,
|
|
|
|
ULONG cb, ULONG *pcbWritten)
|
|
|
|
{
|
2011-01-14 23:31:13 +01:00
|
|
|
ProtocolStream *This = impl_from_IStream(iface);
|
2006-01-09 17:18:06 +01:00
|
|
|
|
2006-10-05 23:49:11 +02:00
|
|
|
TRACE("(%p)->(%p %d %p)\n", This, pv, cb, pcbWritten);
|
2006-01-09 17:18:06 +01:00
|
|
|
|
|
|
|
return STG_E_ACCESSDENIED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProtocolStream_Seek(IStream *iface, LARGE_INTEGER dlibMove,
|
|
|
|
DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
|
|
|
|
{
|
2011-01-14 23:31:13 +01:00
|
|
|
ProtocolStream *This = impl_from_IStream(iface);
|
2006-10-05 23:49:11 +02:00
|
|
|
FIXME("(%p)->(%d %08x %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
|
2006-01-09 17:18:06 +01:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProtocolStream_SetSize(IStream *iface, ULARGE_INTEGER libNewSize)
|
|
|
|
{
|
2011-01-14 23:31:13 +01:00
|
|
|
ProtocolStream *This = impl_from_IStream(iface);
|
2006-10-05 23:49:11 +02:00
|
|
|
FIXME("(%p)->(%d)\n", This, libNewSize.u.LowPart);
|
2006-01-09 17:18:06 +01:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProtocolStream_CopyTo(IStream *iface, IStream *pstm,
|
|
|
|
ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten)
|
|
|
|
{
|
2011-01-14 23:31:13 +01:00
|
|
|
ProtocolStream *This = impl_from_IStream(iface);
|
2006-10-05 23:49:11 +02:00
|
|
|
FIXME("(%p)->(%p %d %p %p)\n", This, pstm, cb.u.LowPart, pcbRead, pcbWritten);
|
2006-01-09 17:18:06 +01:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProtocolStream_Commit(IStream *iface, DWORD grfCommitFlags)
|
|
|
|
{
|
2011-01-14 23:31:13 +01:00
|
|
|
ProtocolStream *This = impl_from_IStream(iface);
|
2006-01-09 17:18:06 +01:00
|
|
|
|
2006-10-05 23:49:11 +02:00
|
|
|
TRACE("(%p)->(%08x)\n", This, grfCommitFlags);
|
2006-01-09 17:18:06 +01:00
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProtocolStream_Revert(IStream *iface)
|
|
|
|
{
|
2011-01-14 23:31:13 +01:00
|
|
|
ProtocolStream *This = impl_from_IStream(iface);
|
2006-01-09 17:18:06 +01:00
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProtocolStream_LockRegion(IStream *iface, ULARGE_INTEGER libOffset,
|
|
|
|
ULARGE_INTEGER cb, DWORD dwLockType)
|
|
|
|
{
|
2011-01-14 23:31:13 +01:00
|
|
|
ProtocolStream *This = impl_from_IStream(iface);
|
2006-10-05 23:49:11 +02:00
|
|
|
FIXME("(%p)->(%d %d %d)\n", This, libOffset.u.LowPart, cb.u.LowPart, dwLockType);
|
2006-01-09 17:18:06 +01:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProtocolStream_UnlockRegion(IStream *iface,
|
|
|
|
ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
|
|
|
|
{
|
2011-01-14 23:31:13 +01:00
|
|
|
ProtocolStream *This = impl_from_IStream(iface);
|
2006-10-05 23:49:11 +02:00
|
|
|
FIXME("(%p)->(%d %d %d)\n", This, libOffset.u.LowPart, cb.u.LowPart, dwLockType);
|
2006-01-09 17:18:06 +01:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProtocolStream_Stat(IStream *iface, STATSTG *pstatstg,
|
|
|
|
DWORD dwStatFlag)
|
|
|
|
{
|
2011-01-14 23:31:13 +01:00
|
|
|
ProtocolStream *This = impl_from_IStream(iface);
|
2010-10-10 22:22:13 +02:00
|
|
|
TRACE("(%p)->(%p %08x)\n", This, pstatstg, dwStatFlag);
|
|
|
|
|
|
|
|
if(!pstatstg)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
memset(pstatstg, 0, sizeof(STATSTG));
|
|
|
|
|
|
|
|
if(!(dwStatFlag&STATFLAG_NONAME) && This->buf->cache_file) {
|
|
|
|
pstatstg->pwcsName = CoTaskMemAlloc((lstrlenW(This->buf->cache_file)+1)*sizeof(WCHAR));
|
|
|
|
if(!pstatstg->pwcsName)
|
|
|
|
return STG_E_INSUFFICIENTMEMORY;
|
|
|
|
|
|
|
|
lstrcpyW(pstatstg->pwcsName, This->buf->cache_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
pstatstg->type = STGTY_STREAM;
|
|
|
|
if(This->buf->file != INVALID_HANDLE_VALUE) {
|
|
|
|
GetFileSizeEx(This->buf->file, (PLARGE_INTEGER)&pstatstg->cbSize);
|
|
|
|
GetFileTime(This->buf->file, &pstatstg->ctime, &pstatstg->atime, &pstatstg->mtime);
|
|
|
|
if(pstatstg->cbSize.QuadPart)
|
|
|
|
pstatstg->grfMode = GENERIC_READ;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
2006-01-09 17:18:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProtocolStream_Clone(IStream *iface, IStream **ppstm)
|
|
|
|
{
|
2011-01-14 23:31:13 +01:00
|
|
|
ProtocolStream *This = impl_from_IStream(iface);
|
2006-01-09 17:18:06 +01:00
|
|
|
FIXME("(%p)->(%p)\n", This, ppstm);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IStreamVtbl ProtocolStreamVtbl = {
|
|
|
|
ProtocolStream_QueryInterface,
|
|
|
|
ProtocolStream_AddRef,
|
|
|
|
ProtocolStream_Release,
|
|
|
|
ProtocolStream_Read,
|
|
|
|
ProtocolStream_Write,
|
|
|
|
ProtocolStream_Seek,
|
|
|
|
ProtocolStream_SetSize,
|
|
|
|
ProtocolStream_CopyTo,
|
|
|
|
ProtocolStream_Commit,
|
|
|
|
ProtocolStream_Revert,
|
|
|
|
ProtocolStream_LockRegion,
|
|
|
|
ProtocolStream_UnlockRegion,
|
|
|
|
ProtocolStream_Stat,
|
|
|
|
ProtocolStream_Clone
|
|
|
|
};
|
|
|
|
|
2008-01-31 18:15:53 +01:00
|
|
|
static void stgmed_stream_release(stgmed_obj_t *obj)
|
|
|
|
{
|
|
|
|
ProtocolStream *stream = (ProtocolStream*)obj;
|
2011-01-14 23:31:13 +01:00
|
|
|
IStream_Release(&stream->IStream_iface);
|
2008-01-31 18:15:53 +01:00
|
|
|
}
|
2005-11-14 16:12:43 +01:00
|
|
|
|
2008-01-31 18:15:53 +01:00
|
|
|
static HRESULT stgmed_stream_fill_stgmed(stgmed_obj_t *obj, STGMEDIUM *stgmed)
|
2006-01-09 17:18:06 +01:00
|
|
|
{
|
2008-01-31 18:15:53 +01:00
|
|
|
ProtocolStream *stream = (ProtocolStream*)obj;
|
2006-01-09 17:18:06 +01:00
|
|
|
|
2008-01-31 18:15:53 +01:00
|
|
|
stgmed->tymed = TYMED_ISTREAM;
|
2011-01-14 23:31:13 +01:00
|
|
|
stgmed->u.pstm = &stream->IStream_iface;
|
2011-01-11 00:36:45 +01:00
|
|
|
stgmed->pUnkForRelease = &stream->buf->IUnknown_iface;
|
2006-01-09 17:18:06 +01:00
|
|
|
|
2008-01-31 18:15:53 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
2006-01-09 17:18:06 +01:00
|
|
|
|
2010-04-29 17:14:47 +02:00
|
|
|
static HRESULT stgmed_stream_get_result(stgmed_obj_t *obj, DWORD bindf, void **result)
|
2008-01-31 18:15:53 +01:00
|
|
|
{
|
|
|
|
ProtocolStream *stream = (ProtocolStream*)obj;
|
2006-01-09 17:20:04 +01:00
|
|
|
|
2010-10-06 14:10:25 +02:00
|
|
|
if(!(bindf & BINDF_ASYNCHRONOUS) && stream->buf->file == INVALID_HANDLE_VALUE
|
2011-02-15 17:02:29 +01:00
|
|
|
&& stream->buf->hres != S_FALSE)
|
2010-10-06 14:10:25 +02:00
|
|
|
return INET_E_DATA_NOT_AVAILABLE;
|
|
|
|
|
2011-01-14 23:31:13 +01:00
|
|
|
IStream_AddRef(&stream->IStream_iface);
|
|
|
|
*result = &stream->IStream_iface;
|
2010-04-29 17:14:47 +02:00
|
|
|
return S_OK;
|
2006-01-09 17:18:06 +01:00
|
|
|
}
|
|
|
|
|
2008-01-31 18:15:53 +01:00
|
|
|
static const stgmed_obj_vtbl stgmed_stream_vtbl = {
|
|
|
|
stgmed_stream_release,
|
|
|
|
stgmed_stream_fill_stgmed,
|
|
|
|
stgmed_stream_get_result
|
|
|
|
};
|
|
|
|
|
2008-01-31 18:17:48 +01:00
|
|
|
typedef struct {
|
|
|
|
stgmed_obj_t stgmed_obj;
|
|
|
|
stgmed_buf_t *buf;
|
|
|
|
} stgmed_file_obj_t;
|
|
|
|
|
2008-01-31 18:15:53 +01:00
|
|
|
static stgmed_obj_t *create_stgmed_stream(stgmed_buf_t *buf)
|
2008-01-31 18:15:11 +01:00
|
|
|
{
|
|
|
|
ProtocolStream *ret = heap_alloc(sizeof(ProtocolStream));
|
|
|
|
|
2008-01-31 18:15:53 +01:00
|
|
|
ret->stgmed_obj.vtbl = &stgmed_stream_vtbl;
|
2011-01-14 23:31:13 +01:00
|
|
|
ret->IStream_iface.lpVtbl = &ProtocolStreamVtbl;
|
2008-01-31 18:15:11 +01:00
|
|
|
ret->ref = 1;
|
|
|
|
|
2011-01-11 00:36:45 +01:00
|
|
|
IUnknown_AddRef(&buf->IUnknown_iface);
|
2008-01-31 18:15:11 +01:00
|
|
|
ret->buf = buf;
|
|
|
|
|
|
|
|
URLMON_LockModule();
|
|
|
|
|
2008-01-31 18:15:53 +01:00
|
|
|
return &ret->stgmed_obj;
|
2008-01-31 18:15:11 +01:00
|
|
|
}
|
|
|
|
|
2008-01-31 18:17:48 +01:00
|
|
|
static void stgmed_file_release(stgmed_obj_t *obj)
|
|
|
|
{
|
2008-02-06 17:42:55 +01:00
|
|
|
stgmed_file_obj_t *file_obj = (stgmed_file_obj_t*)obj;
|
|
|
|
|
2011-01-11 00:36:45 +01:00
|
|
|
IUnknown_Release(&file_obj->buf->IUnknown_iface);
|
2008-02-06 17:42:55 +01:00
|
|
|
heap_free(file_obj);
|
2008-01-31 18:17:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT stgmed_file_fill_stgmed(stgmed_obj_t *obj, STGMEDIUM *stgmed)
|
|
|
|
{
|
|
|
|
stgmed_file_obj_t *file_obj = (stgmed_file_obj_t*)obj;
|
|
|
|
|
|
|
|
if(!file_obj->buf->cache_file) {
|
|
|
|
WARN("cache_file not set\n");
|
|
|
|
return INET_E_DATA_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2010-05-04 20:13:54 +02:00
|
|
|
read_protocol_data(file_obj->buf);
|
2008-01-31 18:17:48 +01:00
|
|
|
|
|
|
|
stgmed->tymed = TYMED_FILE;
|
|
|
|
stgmed->u.lpszFileName = file_obj->buf->cache_file;
|
2011-01-11 00:36:45 +01:00
|
|
|
stgmed->pUnkForRelease = &file_obj->buf->IUnknown_iface;
|
2008-01-31 18:17:48 +01:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-04-29 17:14:47 +02:00
|
|
|
static HRESULT stgmed_file_get_result(stgmed_obj_t *obj, DWORD bindf, void **result)
|
2008-01-31 18:17:48 +01:00
|
|
|
{
|
2010-04-29 17:14:47 +02:00
|
|
|
return bindf & BINDF_ASYNCHRONOUS ? MK_S_ASYNCHRONOUS : S_OK;
|
2008-01-31 18:17:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const stgmed_obj_vtbl stgmed_file_vtbl = {
|
|
|
|
stgmed_file_release,
|
|
|
|
stgmed_file_fill_stgmed,
|
|
|
|
stgmed_file_get_result
|
|
|
|
};
|
|
|
|
|
|
|
|
static stgmed_obj_t *create_stgmed_file(stgmed_buf_t *buf)
|
|
|
|
{
|
|
|
|
stgmed_file_obj_t *ret = heap_alloc(sizeof(*ret));
|
|
|
|
|
|
|
|
ret->stgmed_obj.vtbl = &stgmed_file_vtbl;
|
|
|
|
|
2011-01-11 00:36:45 +01:00
|
|
|
IUnknown_AddRef(&buf->IUnknown_iface);
|
2008-01-31 18:17:48 +01:00
|
|
|
ret->buf = buf;
|
|
|
|
|
|
|
|
return &ret->stgmed_obj;
|
|
|
|
}
|
|
|
|
|
2011-01-14 23:27:11 +01:00
|
|
|
static inline Binding *impl_from_IBinding(IBinding *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, Binding, IBinding_iface);
|
|
|
|
}
|
2008-01-31 18:15:53 +01:00
|
|
|
|
2005-11-14 16:12:43 +01:00
|
|
|
static HRESULT WINAPI Binding_QueryInterface(IBinding *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
2011-01-14 23:27:11 +01:00
|
|
|
Binding *This = impl_from_IBinding(iface);
|
2005-11-14 16:12:43 +01:00
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if(IsEqualGUID(&IID_IUnknown, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
|
2011-01-14 23:27:11 +01:00
|
|
|
*ppv = &This->IBinding_iface;
|
2005-11-14 16:12:43 +01:00
|
|
|
}else if(IsEqualGUID(&IID_IBinding, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IBinding %p)\n", This, ppv);
|
2011-01-14 23:27:11 +01:00
|
|
|
*ppv = &This->IBinding_iface;
|
2005-11-14 16:12:43 +01:00
|
|
|
}else if(IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IInternetProtocolSink %p)\n", This, ppv);
|
2011-01-14 23:29:12 +01:00
|
|
|
*ppv = &This->IInternetProtocolSink_iface;
|
2005-11-14 16:12:43 +01:00
|
|
|
}else if(IsEqualGUID(&IID_IInternetBindInfo, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IInternetBindInfo %p)\n", This, ppv);
|
2011-01-14 23:29:12 +01:00
|
|
|
*ppv = &This->IInternetBindInfo_iface;
|
2005-11-14 16:12:43 +01:00
|
|
|
}else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
|
2011-01-14 23:29:12 +01:00
|
|
|
*ppv = &This->IServiceProvider_iface;
|
2009-03-29 21:31:15 +02:00
|
|
|
}else if(IsEqualGUID(&IID_IWinInetInfo, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IWinInetInfo %p)\n", This, ppv);
|
|
|
|
|
|
|
|
/* NOTE: This violidates COM rules, but tests prove that we should do it */
|
2011-01-10 18:25:44 +01:00
|
|
|
if(!This->protocol->wininet_info)
|
2009-03-29 21:31:15 +02:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
2011-01-14 23:29:12 +01:00
|
|
|
*ppv = &This->IWinInetHttpInfo_iface;
|
2009-03-29 21:31:15 +02:00
|
|
|
}else if(IsEqualGUID(&IID_IWinInetHttpInfo, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IWinInetHttpInfo %p)\n", This, ppv);
|
|
|
|
|
2011-03-28 23:38:07 +02:00
|
|
|
if(!This->protocol->wininet_http_info)
|
2009-03-29 21:31:15 +02:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
|
2011-01-14 23:29:12 +01:00
|
|
|
*ppv = &This->IWinInetHttpInfo_iface;
|
2005-11-14 16:12:43 +01:00
|
|
|
}
|
|
|
|
|
2006-01-09 17:20:04 +01:00
|
|
|
if(*ppv) {
|
2011-01-14 23:27:11 +01:00
|
|
|
IBinding_AddRef(&This->IBinding_iface);
|
2005-11-14 16:12:43 +01:00
|
|
|
return S_OK;
|
2006-01-09 17:20:04 +01:00
|
|
|
}
|
2005-11-14 16:12:43 +01:00
|
|
|
|
|
|
|
WARN("Unsupported interface %s\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI Binding_AddRef(IBinding *iface)
|
|
|
|
{
|
2011-01-14 23:27:11 +01:00
|
|
|
Binding *This = impl_from_IBinding(iface);
|
2005-11-14 16:12:43 +01:00
|
|
|
LONG ref = InterlockedIncrement(&This->ref);
|
|
|
|
|
2006-10-05 23:49:11 +02:00
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
2005-11-14 16:12:43 +01:00
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI Binding_Release(IBinding *iface)
|
|
|
|
{
|
2011-01-14 23:27:11 +01:00
|
|
|
Binding *This = impl_from_IBinding(iface);
|
2005-11-14 16:12:43 +01:00
|
|
|
LONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
2006-10-05 23:49:11 +02:00
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
2005-11-14 16:12:43 +01:00
|
|
|
|
|
|
|
if(!ref) {
|
2009-05-11 13:14:45 +02:00
|
|
|
if(This->notif_hwnd)
|
|
|
|
release_notif_hwnd(This->notif_hwnd);
|
2007-12-30 17:45:00 +01:00
|
|
|
if(This->mon)
|
|
|
|
IMoniker_Release(This->mon);
|
2005-11-14 16:12:43 +01:00
|
|
|
if(This->callback)
|
|
|
|
IBindStatusCallback_Release(This->callback);
|
|
|
|
if(This->protocol)
|
2011-01-12 00:43:44 +01:00
|
|
|
IInternetProtocolEx_Release(&This->protocol->IInternetProtocolEx_iface);
|
2006-01-05 13:42:32 +01:00
|
|
|
if(This->service_provider)
|
|
|
|
IServiceProvider_Release(This->service_provider);
|
2008-01-31 18:15:11 +01:00
|
|
|
if(This->stgmed_buf)
|
2011-01-11 00:36:45 +01:00
|
|
|
IUnknown_Release(&This->stgmed_buf->IUnknown_iface);
|
2008-01-31 18:15:53 +01:00
|
|
|
if(This->stgmed_obj)
|
|
|
|
This->stgmed_obj->vtbl->release(This->stgmed_obj);
|
2007-12-30 17:45:00 +01:00
|
|
|
if(This->obj)
|
|
|
|
IUnknown_Release(This->obj);
|
|
|
|
if(This->bctx)
|
|
|
|
IBindCtx_Release(This->bctx);
|
2005-11-14 16:12:43 +01:00
|
|
|
|
|
|
|
ReleaseBindInfo(&This->bindinfo);
|
2007-03-10 22:10:52 +01:00
|
|
|
This->section.DebugInfo->Spare[0] = 0;
|
2006-05-31 19:45:16 +02:00
|
|
|
DeleteCriticalSection(&This->section);
|
2010-11-15 12:38:06 +01:00
|
|
|
SysFreeString(This->url);
|
2007-11-29 22:12:34 +01:00
|
|
|
heap_free(This->mime);
|
2009-12-15 21:16:35 +01:00
|
|
|
heap_free(This->redirect_url);
|
2007-11-29 22:12:34 +01:00
|
|
|
heap_free(This);
|
2006-01-09 17:20:04 +01:00
|
|
|
|
|
|
|
URLMON_UnlockModule();
|
2005-11-14 16:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Binding_Abort(IBinding *iface)
|
|
|
|
{
|
2011-01-14 23:27:11 +01:00
|
|
|
Binding *This = impl_from_IBinding(iface);
|
2010-10-06 21:35:53 +02:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
if(This->state & BINDING_ABORTED)
|
|
|
|
return E_FAIL;
|
|
|
|
|
2011-01-12 00:43:44 +01:00
|
|
|
hres = IInternetProtocolEx_Abort(&This->protocol->IInternetProtocolEx_iface, E_ABORT,
|
|
|
|
ERROR_SUCCESS);
|
2010-10-06 21:35:53 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
This->state |= BINDING_ABORTED;
|
|
|
|
return S_OK;
|
2005-11-14 16:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Binding_Suspend(IBinding *iface)
|
|
|
|
{
|
2011-01-14 23:27:11 +01:00
|
|
|
Binding *This = impl_from_IBinding(iface);
|
2005-11-14 16:12:43 +01:00
|
|
|
FIXME("(%p)\n", This);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Binding_Resume(IBinding *iface)
|
|
|
|
{
|
2011-01-14 23:27:11 +01:00
|
|
|
Binding *This = impl_from_IBinding(iface);
|
2005-11-14 16:12:43 +01:00
|
|
|
FIXME("(%p)\n", This);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Binding_SetPriority(IBinding *iface, LONG nPriority)
|
|
|
|
{
|
2011-01-14 23:27:11 +01:00
|
|
|
Binding *This = impl_from_IBinding(iface);
|
2006-10-05 23:49:11 +02:00
|
|
|
FIXME("(%p)->(%d)\n", This, nPriority);
|
2005-11-14 16:12:43 +01:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Binding_GetPriority(IBinding *iface, LONG *pnPriority)
|
|
|
|
{
|
2011-01-14 23:27:11 +01:00
|
|
|
Binding *This = impl_from_IBinding(iface);
|
2005-11-14 16:12:43 +01:00
|
|
|
FIXME("(%p)->(%p)\n", This, pnPriority);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Binding_GetBindResult(IBinding *iface, CLSID *pclsidProtocol,
|
|
|
|
DWORD *pdwResult, LPOLESTR *pszResult, DWORD *pdwReserved)
|
|
|
|
{
|
2011-01-14 23:27:11 +01:00
|
|
|
Binding *This = impl_from_IBinding(iface);
|
2012-03-15 12:07:30 +01:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p %p %p %p)\n", This, pclsidProtocol, pdwResult, pszResult, pdwReserved);
|
|
|
|
|
|
|
|
if(!pdwResult || !pszResult || pdwReserved)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
if(!(This->state & BINDING_STOPPED)) {
|
|
|
|
*pclsidProtocol = CLSID_NULL;
|
|
|
|
*pdwResult = 0;
|
|
|
|
*pszResult = NULL;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pclsidProtocol = This->hres==S_OK ? CLSID_NULL : This->clsid;
|
|
|
|
*pdwResult = This->hres;
|
|
|
|
*pszResult = NULL;
|
|
|
|
return S_OK;
|
2005-11-14 16:12:43 +01:00
|
|
|
}
|
|
|
|
|
2011-01-14 23:27:11 +01:00
|
|
|
static const IBindingVtbl BindingVtbl = {
|
|
|
|
Binding_QueryInterface,
|
|
|
|
Binding_AddRef,
|
|
|
|
Binding_Release,
|
|
|
|
Binding_Abort,
|
|
|
|
Binding_Suspend,
|
|
|
|
Binding_Resume,
|
|
|
|
Binding_SetPriority,
|
|
|
|
Binding_GetPriority,
|
|
|
|
Binding_GetBindResult
|
|
|
|
};
|
|
|
|
|
2007-12-30 17:44:02 +01:00
|
|
|
static Binding *get_bctx_binding(IBindCtx *bctx)
|
|
|
|
{
|
|
|
|
IBinding *binding;
|
|
|
|
IUnknown *unk;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = IBindCtx_GetObjectParam(bctx, cbinding_contextW, &unk);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return NULL;
|
|
|
|
|
2011-04-01 08:57:12 +02:00
|
|
|
hres = IUnknown_QueryInterface(unk, &IID_IBinding, (void**)&binding);
|
2007-12-30 17:44:02 +01:00
|
|
|
IUnknown_Release(unk);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return NULL;
|
|
|
|
|
2011-01-14 23:27:11 +01:00
|
|
|
if (binding->lpVtbl != &BindingVtbl)
|
|
|
|
return NULL;
|
|
|
|
return impl_from_IBinding(binding);
|
2007-12-30 17:44:02 +01:00
|
|
|
}
|
|
|
|
|
2011-01-14 23:29:12 +01:00
|
|
|
static inline Binding *impl_from_IInternetProtocolSink(IInternetProtocolSink *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, Binding, IInternetProtocolSink_iface);
|
|
|
|
}
|
2005-11-14 16:12:43 +01:00
|
|
|
|
|
|
|
static HRESULT WINAPI InternetProtocolSink_QueryInterface(IInternetProtocolSink *iface,
|
|
|
|
REFIID riid, void **ppv)
|
|
|
|
{
|
2011-01-14 23:29:12 +01:00
|
|
|
Binding *This = impl_from_IInternetProtocolSink(iface);
|
2011-01-14 23:27:11 +01:00
|
|
|
return IBinding_QueryInterface(&This->IBinding_iface, riid, ppv);
|
2005-11-14 16:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI InternetProtocolSink_AddRef(IInternetProtocolSink *iface)
|
|
|
|
{
|
2011-01-14 23:29:12 +01:00
|
|
|
Binding *This = impl_from_IInternetProtocolSink(iface);
|
2011-01-14 23:27:11 +01:00
|
|
|
return IBinding_AddRef(&This->IBinding_iface);
|
2005-11-14 16:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI InternetProtocolSink_Release(IInternetProtocolSink *iface)
|
|
|
|
{
|
2011-01-14 23:29:12 +01:00
|
|
|
Binding *This = impl_from_IInternetProtocolSink(iface);
|
2011-01-14 23:27:11 +01:00
|
|
|
return IBinding_Release(&This->IBinding_iface);
|
2005-11-14 16:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI InternetProtocolSink_Switch(IInternetProtocolSink *iface,
|
|
|
|
PROTOCOLDATA *pProtocolData)
|
|
|
|
{
|
2011-01-14 23:29:12 +01:00
|
|
|
Binding *This = impl_from_IInternetProtocolSink(iface);
|
2006-05-25 18:39:26 +02:00
|
|
|
|
2009-05-11 22:01:05 +02:00
|
|
|
WARN("(%p)->(%p)\n", This, pProtocolData);
|
2006-05-25 18:39:26 +02:00
|
|
|
|
2009-05-11 22:01:05 +02:00
|
|
|
return E_FAIL;
|
2005-11-14 16:12:43 +01:00
|
|
|
}
|
|
|
|
|
2007-02-07 17:31:04 +01:00
|
|
|
static void on_progress(Binding *This, ULONG progress, ULONG progress_max,
|
|
|
|
ULONG status_code, LPCWSTR status_text)
|
|
|
|
{
|
2009-05-11 22:01:54 +02:00
|
|
|
IBindStatusCallback_OnProgress(This->callback, progress, progress_max,
|
|
|
|
status_code, status_text);
|
2007-02-07 17:31:04 +01:00
|
|
|
}
|
|
|
|
|
2005-11-14 16:12:43 +01:00
|
|
|
static HRESULT WINAPI InternetProtocolSink_ReportProgress(IInternetProtocolSink *iface,
|
|
|
|
ULONG ulStatusCode, LPCWSTR szStatusText)
|
|
|
|
{
|
2011-01-14 23:29:12 +01:00
|
|
|
Binding *This = impl_from_IInternetProtocolSink(iface);
|
2005-11-14 16:12:43 +01:00
|
|
|
|
2006-10-05 23:49:11 +02:00
|
|
|
TRACE("(%p)->(%u %s)\n", This, ulStatusCode, debugstr_w(szStatusText));
|
2005-11-14 16:12:43 +01:00
|
|
|
|
|
|
|
switch(ulStatusCode) {
|
2006-05-25 18:37:55 +02:00
|
|
|
case BINDSTATUS_FINDINGRESOURCE:
|
|
|
|
on_progress(This, 0, 0, BINDSTATUS_FINDINGRESOURCE, szStatusText);
|
|
|
|
break;
|
|
|
|
case BINDSTATUS_CONNECTING:
|
|
|
|
on_progress(This, 0, 0, BINDSTATUS_CONNECTING, szStatusText);
|
|
|
|
break;
|
2009-12-15 21:15:28 +01:00
|
|
|
case BINDSTATUS_REDIRECTING:
|
2009-12-15 21:16:35 +01:00
|
|
|
heap_free(This->redirect_url);
|
|
|
|
This->redirect_url = heap_strdupW(szStatusText);
|
2009-12-15 21:15:28 +01:00
|
|
|
on_progress(This, 0, 0, BINDSTATUS_REDIRECTING, szStatusText);
|
|
|
|
break;
|
2007-02-07 17:30:28 +01:00
|
|
|
case BINDSTATUS_BEGINDOWNLOADDATA:
|
|
|
|
break;
|
2005-12-26 13:27:10 +01:00
|
|
|
case BINDSTATUS_SENDINGREQUEST:
|
2006-05-25 18:35:35 +02:00
|
|
|
on_progress(This, 0, 0, BINDSTATUS_SENDINGREQUEST, szStatusText);
|
2005-12-26 13:27:10 +01:00
|
|
|
break;
|
2007-12-30 17:40:26 +01:00
|
|
|
case BINDSTATUS_PROTOCOLCLASSID:
|
2012-03-15 12:07:30 +01:00
|
|
|
CLSIDFromString(szStatusText, &This->clsid);
|
2007-12-30 17:40:26 +01:00
|
|
|
break;
|
2009-05-14 00:49:33 +02:00
|
|
|
case BINDSTATUS_MIMETYPEAVAILABLE:
|
2005-12-26 13:27:10 +01:00
|
|
|
case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE:
|
2009-05-14 00:49:33 +02:00
|
|
|
mime_available(This, szStatusText);
|
2005-12-26 13:27:10 +01:00
|
|
|
break;
|
|
|
|
case BINDSTATUS_CACHEFILENAMEAVAILABLE:
|
2010-05-04 20:13:54 +02:00
|
|
|
cache_file_available(This, szStatusText);
|
2005-12-26 13:27:10 +01:00
|
|
|
break;
|
2009-05-18 03:06:08 +02:00
|
|
|
case BINDSTATUS_DECODING:
|
|
|
|
IBindStatusCallback_OnProgress(This->callback, 0, 0, BINDSTATUS_DECODING, szStatusText);
|
|
|
|
break;
|
|
|
|
case BINDSTATUS_LOADINGMIMEHANDLER:
|
|
|
|
on_progress(This, 0, 0, BINDSTATUS_LOADINGMIMEHANDLER, szStatusText);
|
|
|
|
break;
|
2009-05-14 00:49:33 +02:00
|
|
|
case BINDSTATUS_DIRECTBIND: /* FIXME: Handle BINDSTATUS_DIRECTBIND in BindProtocol */
|
2007-02-08 02:33:32 +01:00
|
|
|
This->report_mime = FALSE;
|
|
|
|
break;
|
2009-01-12 18:20:14 +01:00
|
|
|
case BINDSTATUS_ACCEPTRANGES:
|
|
|
|
break;
|
2005-11-14 16:12:43 +01:00
|
|
|
default:
|
2006-10-05 23:49:11 +02:00
|
|
|
FIXME("Unhandled status code %d\n", ulStatusCode);
|
2005-11-14 16:12:43 +01:00
|
|
|
return E_NOTIMPL;
|
|
|
|
};
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2007-02-07 17:29:52 +01:00
|
|
|
static void report_data(Binding *This, DWORD bscf, ULONG progress, ULONG progress_max)
|
2007-02-07 17:31:04 +01:00
|
|
|
{
|
|
|
|
FORMATETC formatetc = {0, NULL, 1, -1, TYMED_ISTREAM};
|
2007-08-03 03:46:58 +02:00
|
|
|
BOOL sent_begindownloaddata = FALSE;
|
2007-02-07 17:31:04 +01:00
|
|
|
|
2007-02-07 17:29:52 +01:00
|
|
|
TRACE("(%p)->(%d %u %u)\n", This, bscf, progress, progress_max);
|
|
|
|
|
2011-02-15 17:01:44 +01:00
|
|
|
if(This->download_state == END_DOWNLOAD || (This->state & BINDING_ABORTED)) {
|
|
|
|
read_protocol_data(This->stgmed_buf);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(This->state & BINDING_STOPPED)
|
2007-08-03 13:35:35 +02:00
|
|
|
return;
|
|
|
|
|
2010-05-04 20:13:54 +02:00
|
|
|
if(This->stgmed_buf->file != INVALID_HANDLE_VALUE)
|
|
|
|
read_protocol_data(This->stgmed_buf);
|
2007-02-10 16:32:03 +01:00
|
|
|
|
2010-05-04 20:13:54 +02:00
|
|
|
if(This->download_state == BEFORE_DOWNLOAD) {
|
2007-08-03 13:35:35 +02:00
|
|
|
This->download_state = DOWNLOADING;
|
2007-08-03 03:46:58 +02:00
|
|
|
sent_begindownloaddata = TRUE;
|
2007-02-08 02:34:13 +01:00
|
|
|
IBindStatusCallback_OnProgress(This->callback, progress, progress_max,
|
|
|
|
BINDSTATUS_BEGINDOWNLOADDATA, This->url);
|
2008-01-31 18:17:18 +01:00
|
|
|
|
|
|
|
if(This->stgmed_buf->cache_file)
|
|
|
|
IBindStatusCallback_OnProgress(This->callback, progress, progress_max,
|
|
|
|
BINDSTATUS_CACHEFILENAMEAVAILABLE, This->stgmed_buf->cache_file);
|
2007-02-07 17:29:52 +01:00
|
|
|
}
|
|
|
|
|
2008-01-31 18:15:11 +01:00
|
|
|
if(This->stgmed_buf->hres == S_FALSE || (bscf & BSCF_LASTDATANOTIFICATION)) {
|
2007-08-03 03:45:17 +02:00
|
|
|
This->download_state = END_DOWNLOAD;
|
2007-02-08 02:34:13 +01:00
|
|
|
IBindStatusCallback_OnProgress(This->callback, progress, progress_max,
|
|
|
|
BINDSTATUS_ENDDOWNLOADDATA, This->url);
|
2007-08-03 03:46:58 +02:00
|
|
|
}else if(!sent_begindownloaddata) {
|
|
|
|
IBindStatusCallback_OnProgress(This->callback, progress, progress_max,
|
|
|
|
BINDSTATUS_DOWNLOADINGDATA, This->url);
|
2007-02-10 16:32:03 +01:00
|
|
|
}
|
2007-02-07 17:29:52 +01:00
|
|
|
|
2010-10-06 21:35:53 +02:00
|
|
|
if(This->state & (BINDING_STOPPED|BINDING_ABORTED))
|
|
|
|
return;
|
|
|
|
|
2007-12-30 17:45:00 +01:00
|
|
|
if(This->to_object) {
|
2010-10-01 13:56:56 +02:00
|
|
|
if(!(This->state & BINDING_OBJAVAIL)) {
|
2011-01-14 23:27:11 +01:00
|
|
|
IBinding_AddRef(&This->IBinding_iface);
|
2007-12-30 17:45:00 +01:00
|
|
|
create_object(This);
|
2011-01-14 23:27:11 +01:00
|
|
|
IBinding_Release(&This->IBinding_iface);
|
2010-10-01 13:56:56 +02:00
|
|
|
}
|
2007-12-30 17:45:00 +01:00
|
|
|
}else {
|
2008-01-31 18:15:53 +01:00
|
|
|
STGMEDIUM stgmed;
|
2008-01-31 18:17:48 +01:00
|
|
|
HRESULT hres;
|
2008-01-31 18:15:53 +01:00
|
|
|
|
2007-12-30 17:45:00 +01:00
|
|
|
if(!(This->state & BINDING_LOCKED)) {
|
2011-01-12 00:43:44 +01:00
|
|
|
HRESULT hres = IInternetProtocolEx_LockRequest(
|
|
|
|
&This->protocol->IInternetProtocolEx_iface, 0);
|
2007-12-30 17:45:00 +01:00
|
|
|
if(SUCCEEDED(hres))
|
|
|
|
This->state |= BINDING_LOCKED;
|
|
|
|
}
|
2007-02-07 17:29:52 +01:00
|
|
|
|
2008-01-31 18:17:48 +01:00
|
|
|
hres = This->stgmed_obj->vtbl->fill_stgmed(This->stgmed_obj, &stgmed);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
stop_binding(This, hres, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
formatetc.tymed = stgmed.tymed;
|
2007-12-30 17:45:00 +01:00
|
|
|
formatetc.cfFormat = This->clipboard_format;
|
2008-01-31 18:15:53 +01:00
|
|
|
|
2012-03-15 12:08:05 +01:00
|
|
|
hres = IBindStatusCallback_OnDataAvailable(This->callback, bscf, progress,
|
2008-01-31 18:15:53 +01:00
|
|
|
&formatetc, &stgmed);
|
2012-03-15 12:08:05 +01:00
|
|
|
if(hres != S_OK) {
|
|
|
|
if(This->download_state != END_DOWNLOAD) {
|
|
|
|
This->download_state = END_DOWNLOAD;
|
|
|
|
IBindStatusCallback_OnProgress(This->callback, progress, progress_max,
|
|
|
|
BINDSTATUS_ENDDOWNLOADDATA, This->url);
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("OnDataAvailable returned %x\n", hres);
|
|
|
|
stop_binding(This, hres, NULL);
|
|
|
|
return;
|
|
|
|
}
|
2007-02-07 17:29:52 +01:00
|
|
|
|
2007-12-30 17:45:00 +01:00
|
|
|
if(This->download_state == END_DOWNLOAD)
|
|
|
|
stop_binding(This, S_OK, NULL);
|
|
|
|
}
|
2007-02-07 17:31:04 +01:00
|
|
|
}
|
|
|
|
|
2005-11-14 16:12:43 +01:00
|
|
|
static HRESULT WINAPI InternetProtocolSink_ReportData(IInternetProtocolSink *iface,
|
|
|
|
DWORD grfBSCF, ULONG ulProgress, ULONG ulProgressMax)
|
|
|
|
{
|
2011-01-14 23:29:12 +01:00
|
|
|
Binding *This = impl_from_IInternetProtocolSink(iface);
|
2005-11-14 16:12:43 +01:00
|
|
|
|
2006-10-05 23:49:11 +02:00
|
|
|
TRACE("(%p)->(%d %u %u)\n", This, grfBSCF, ulProgress, ulProgressMax);
|
2005-11-14 16:12:43 +01:00
|
|
|
|
2009-05-11 22:01:39 +02:00
|
|
|
report_data(This, grfBSCF, ulProgress, ulProgressMax);
|
2005-11-14 16:12:43 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI InternetProtocolSink_ReportResult(IInternetProtocolSink *iface,
|
|
|
|
HRESULT hrResult, DWORD dwError, LPCWSTR szResult)
|
|
|
|
{
|
2011-01-14 23:29:12 +01:00
|
|
|
Binding *This = impl_from_IInternetProtocolSink(iface);
|
2006-05-25 18:33:21 +02:00
|
|
|
|
2006-10-05 23:49:11 +02:00
|
|
|
TRACE("(%p)->(%08x %d %s)\n", This, hrResult, dwError, debugstr_w(szResult));
|
2006-05-25 18:33:21 +02:00
|
|
|
|
2009-05-11 22:01:39 +02:00
|
|
|
stop_binding(This, hrResult, szResult);
|
2011-01-12 00:43:44 +01:00
|
|
|
IInternetProtocolEx_Terminate(&This->protocol->IInternetProtocolEx_iface, 0);
|
2006-05-25 18:33:21 +02:00
|
|
|
return S_OK;
|
2005-11-14 16:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IInternetProtocolSinkVtbl InternetProtocolSinkVtbl = {
|
|
|
|
InternetProtocolSink_QueryInterface,
|
|
|
|
InternetProtocolSink_AddRef,
|
|
|
|
InternetProtocolSink_Release,
|
|
|
|
InternetProtocolSink_Switch,
|
|
|
|
InternetProtocolSink_ReportProgress,
|
|
|
|
InternetProtocolSink_ReportData,
|
|
|
|
InternetProtocolSink_ReportResult
|
|
|
|
};
|
|
|
|
|
2011-01-14 23:29:12 +01:00
|
|
|
static inline Binding *impl_from_IInternetBindInfo(IInternetBindInfo *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, Binding, IInternetBindInfo_iface);
|
|
|
|
}
|
2005-11-14 16:12:43 +01:00
|
|
|
|
|
|
|
static HRESULT WINAPI InternetBindInfo_QueryInterface(IInternetBindInfo *iface,
|
|
|
|
REFIID riid, void **ppv)
|
|
|
|
{
|
2011-01-14 23:29:12 +01:00
|
|
|
Binding *This = impl_from_IInternetBindInfo(iface);
|
2011-01-14 23:27:11 +01:00
|
|
|
return IBinding_QueryInterface(&This->IBinding_iface, riid, ppv);
|
2005-11-14 16:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI InternetBindInfo_AddRef(IInternetBindInfo *iface)
|
|
|
|
{
|
2011-01-14 23:29:12 +01:00
|
|
|
Binding *This = impl_from_IInternetBindInfo(iface);
|
2011-01-14 23:27:11 +01:00
|
|
|
return IBinding_AddRef(&This->IBinding_iface);
|
2005-11-14 16:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI InternetBindInfo_Release(IInternetBindInfo *iface)
|
|
|
|
{
|
2011-01-14 23:29:12 +01:00
|
|
|
Binding *This = impl_from_IInternetBindInfo(iface);
|
2011-01-14 23:27:11 +01:00
|
|
|
return IBinding_Release(&This->IBinding_iface);
|
2005-11-14 16:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI InternetBindInfo_GetBindInfo(IInternetBindInfo *iface,
|
|
|
|
DWORD *grfBINDF, BINDINFO *pbindinfo)
|
|
|
|
{
|
2011-01-14 23:29:12 +01:00
|
|
|
Binding *This = impl_from_IInternetBindInfo(iface);
|
2005-11-14 16:12:43 +01:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
|
|
|
|
|
|
|
|
*grfBINDF = This->bindf;
|
2012-03-08 13:45:51 +01:00
|
|
|
return CopyBindInfo(&This->bindinfo, pbindinfo);
|
2005-11-14 16:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI InternetBindInfo_GetBindString(IInternetBindInfo *iface,
|
|
|
|
ULONG ulStringType, LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
|
|
|
|
{
|
2011-01-14 23:29:12 +01:00
|
|
|
Binding *This = impl_from_IInternetBindInfo(iface);
|
2006-01-05 12:17:59 +01:00
|
|
|
|
2006-10-05 23:49:11 +02:00
|
|
|
TRACE("(%p)->(%d %p %d %p)\n", This, ulStringType, ppwzStr, cEl, pcElFetched);
|
2006-01-05 12:17:59 +01:00
|
|
|
|
|
|
|
switch(ulStringType) {
|
|
|
|
case BINDSTRING_ACCEPT_MIMES: {
|
|
|
|
static const WCHAR wszMimes[] = {'*','/','*',0};
|
|
|
|
|
|
|
|
if(!ppwzStr || !pcElFetched)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
ppwzStr[0] = CoTaskMemAlloc(sizeof(wszMimes));
|
|
|
|
memcpy(ppwzStr[0], wszMimes, sizeof(wszMimes));
|
|
|
|
*pcElFetched = 1;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
case BINDSTRING_USER_AGENT: {
|
|
|
|
IInternetBindInfo *bindinfo = NULL;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = IBindStatusCallback_QueryInterface(This->callback, &IID_IInternetBindInfo,
|
|
|
|
(void**)&bindinfo);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = IInternetBindInfo_GetBindString(bindinfo, ulStringType, ppwzStr,
|
|
|
|
cEl, pcElFetched);
|
|
|
|
IInternetBindInfo_Release(bindinfo);
|
|
|
|
|
|
|
|
return hres;
|
|
|
|
}
|
2009-05-18 03:05:39 +02:00
|
|
|
case BINDSTRING_URL: {
|
2010-11-15 12:38:06 +01:00
|
|
|
DWORD size = (SysStringLen(This->url)+1) * sizeof(WCHAR);
|
2009-05-18 03:05:39 +02:00
|
|
|
|
|
|
|
if(!ppwzStr || !pcElFetched)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
*ppwzStr = CoTaskMemAlloc(size);
|
|
|
|
memcpy(*ppwzStr, This->url, size);
|
|
|
|
*pcElFetched = 1;
|
|
|
|
return S_OK;
|
|
|
|
}
|
2006-01-05 12:17:59 +01:00
|
|
|
}
|
|
|
|
|
2006-10-05 23:49:11 +02:00
|
|
|
FIXME("not supported string type %d\n", ulStringType);
|
2005-11-14 16:12:43 +01:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const IInternetBindInfoVtbl InternetBindInfoVtbl = {
|
|
|
|
InternetBindInfo_QueryInterface,
|
|
|
|
InternetBindInfo_AddRef,
|
|
|
|
InternetBindInfo_Release,
|
|
|
|
InternetBindInfo_GetBindInfo,
|
|
|
|
InternetBindInfo_GetBindString
|
|
|
|
};
|
|
|
|
|
2011-01-14 23:29:12 +01:00
|
|
|
static inline Binding *impl_from_IWinInetHttpInfo(IWinInetHttpInfo *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, Binding, IWinInetHttpInfo_iface);
|
|
|
|
}
|
2009-03-29 21:31:15 +02:00
|
|
|
|
|
|
|
static HRESULT WINAPI WinInetHttpInfo_QueryInterface(IWinInetHttpInfo *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
2011-01-14 23:29:12 +01:00
|
|
|
Binding *This = impl_from_IWinInetHttpInfo(iface);
|
2011-01-14 23:27:11 +01:00
|
|
|
return IBinding_QueryInterface(&This->IBinding_iface, riid, ppv);
|
2009-03-29 21:31:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI WinInetHttpInfo_AddRef(IWinInetHttpInfo *iface)
|
|
|
|
{
|
2011-01-14 23:29:12 +01:00
|
|
|
Binding *This = impl_from_IWinInetHttpInfo(iface);
|
2011-01-14 23:27:11 +01:00
|
|
|
return IBinding_AddRef(&This->IBinding_iface);
|
2009-03-29 21:31:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI WinInetHttpInfo_Release(IWinInetHttpInfo *iface)
|
|
|
|
{
|
2011-01-14 23:29:12 +01:00
|
|
|
Binding *This = impl_from_IWinInetHttpInfo(iface);
|
2011-01-14 23:27:11 +01:00
|
|
|
return IBinding_Release(&This->IBinding_iface);
|
2009-03-29 21:31:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI WinInetHttpInfo_QueryOption(IWinInetHttpInfo *iface, DWORD dwOption,
|
|
|
|
void *pBuffer, DWORD *pcbBuffer)
|
|
|
|
{
|
2011-01-14 23:29:12 +01:00
|
|
|
Binding *This = impl_from_IWinInetHttpInfo(iface);
|
2011-03-28 23:38:07 +02:00
|
|
|
TRACE("(%p)->(%x %p %p)\n", This, dwOption, pBuffer, pcbBuffer);
|
|
|
|
|
|
|
|
if(!This->protocol->wininet_info)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
return IWinInetInfo_QueryOption(This->protocol->wininet_info,
|
|
|
|
dwOption, pBuffer, pcbBuffer);
|
2009-03-29 21:31:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI WinInetHttpInfo_QueryInfo(IWinInetHttpInfo *iface, DWORD dwOption,
|
|
|
|
void *pBuffer, DWORD *pcbBuffer, DWORD *pdwFlags, DWORD *pdwReserved)
|
|
|
|
{
|
2011-01-14 23:29:12 +01:00
|
|
|
Binding *This = impl_from_IWinInetHttpInfo(iface);
|
2011-03-28 23:38:07 +02:00
|
|
|
TRACE("(%p)->(%x %p %p %p %p)\n", This, dwOption, pBuffer, pcbBuffer, pdwFlags, pdwReserved);
|
|
|
|
|
|
|
|
if(!This->protocol->wininet_http_info)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
return IWinInetHttpInfo_QueryInfo(This->protocol->wininet_http_info,
|
|
|
|
dwOption, pBuffer, pcbBuffer, pdwFlags, pdwReserved);
|
2009-03-29 21:31:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IWinInetHttpInfoVtbl WinInetHttpInfoVtbl = {
|
|
|
|
WinInetHttpInfo_QueryInterface,
|
|
|
|
WinInetHttpInfo_AddRef,
|
|
|
|
WinInetHttpInfo_Release,
|
|
|
|
WinInetHttpInfo_QueryOption,
|
|
|
|
WinInetHttpInfo_QueryInfo
|
|
|
|
};
|
|
|
|
|
2011-01-14 23:29:12 +01:00
|
|
|
static inline Binding *impl_from_IServiceProvider(IServiceProvider *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, Binding, IServiceProvider_iface);
|
|
|
|
}
|
2005-11-14 16:12:43 +01:00
|
|
|
|
|
|
|
static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface,
|
|
|
|
REFIID riid, void **ppv)
|
|
|
|
{
|
2011-01-14 23:29:12 +01:00
|
|
|
Binding *This = impl_from_IServiceProvider(iface);
|
2011-01-14 23:27:11 +01:00
|
|
|
return IBinding_QueryInterface(&This->IBinding_iface, riid, ppv);
|
2005-11-14 16:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
|
|
|
|
{
|
2011-01-14 23:29:12 +01:00
|
|
|
Binding *This = impl_from_IServiceProvider(iface);
|
2011-01-14 23:27:11 +01:00
|
|
|
return IBinding_AddRef(&This->IBinding_iface);
|
2005-11-14 16:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
|
|
|
|
{
|
2011-01-14 23:29:12 +01:00
|
|
|
Binding *This = impl_from_IServiceProvider(iface);
|
2011-01-14 23:27:11 +01:00
|
|
|
return IBinding_Release(&This->IBinding_iface);
|
2005-11-14 16:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface,
|
|
|
|
REFGUID guidService, REFIID riid, void **ppv)
|
|
|
|
{
|
2011-01-14 23:29:12 +01:00
|
|
|
Binding *This = impl_from_IServiceProvider(iface);
|
2006-01-05 13:42:43 +01:00
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %s %p)\n", This, debugstr_guid(guidService), debugstr_guid(riid), ppv);
|
|
|
|
|
|
|
|
if(This->service_provider) {
|
|
|
|
hres = IServiceProvider_QueryService(This->service_provider, guidService,
|
|
|
|
riid, ppv);
|
|
|
|
if(SUCCEEDED(hres))
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("unknown service %s\n", debugstr_guid(guidService));
|
2010-12-22 00:50:25 +01:00
|
|
|
return E_NOINTERFACE;
|
2005-11-14 16:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IServiceProviderVtbl ServiceProviderVtbl = {
|
|
|
|
ServiceProvider_QueryInterface,
|
|
|
|
ServiceProvider_AddRef,
|
|
|
|
ServiceProvider_Release,
|
|
|
|
ServiceProvider_QueryService
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT get_callback(IBindCtx *pbc, IBindStatusCallback **callback)
|
|
|
|
{
|
2007-10-26 00:21:21 +02:00
|
|
|
IUnknown *unk;
|
2005-11-14 16:12:43 +01:00
|
|
|
HRESULT hres;
|
|
|
|
|
2007-12-30 17:45:00 +01:00
|
|
|
hres = IBindCtx_GetObjectParam(pbc, bscb_holderW, &unk);
|
2010-10-06 21:36:18 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return create_default_callback(callback);
|
2005-11-14 16:12:43 +01:00
|
|
|
|
2010-10-06 21:36:18 +02:00
|
|
|
hres = IUnknown_QueryInterface(unk, &IID_IBindStatusCallback, (void**)callback);
|
|
|
|
IUnknown_Release(unk);
|
|
|
|
return hres;
|
2005-11-14 16:12:43 +01:00
|
|
|
}
|
|
|
|
|
2010-11-15 12:38:06 +01:00
|
|
|
static BOOL is_urlmon_protocol(IUri *uri)
|
|
|
|
{
|
|
|
|
DWORD scheme;
|
|
|
|
HRESULT hres;
|
2007-02-07 17:27:35 +01:00
|
|
|
|
2010-11-15 12:38:06 +01:00
|
|
|
hres = IUri_GetScheme(uri, &scheme);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
switch(scheme) {
|
|
|
|
case URL_SCHEME_FILE:
|
|
|
|
case URL_SCHEME_FTP:
|
|
|
|
case URL_SCHEME_GOPHER:
|
|
|
|
case URL_SCHEME_HTTP:
|
|
|
|
case URL_SCHEME_HTTPS:
|
|
|
|
case URL_SCHEME_MK:
|
|
|
|
return TRUE;
|
2007-02-07 17:27:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-11-15 12:38:06 +01:00
|
|
|
static HRESULT Binding_Create(IMoniker *mon, Binding *binding_ctx, IUri *uri, IBindCtx *pbc,
|
2007-12-30 17:45:00 +01:00
|
|
|
BOOL to_obj, REFIID riid, Binding **binding)
|
2005-11-14 16:12:43 +01:00
|
|
|
{
|
|
|
|
Binding *ret;
|
|
|
|
HRESULT hres;
|
|
|
|
|
2006-01-09 17:20:04 +01:00
|
|
|
URLMON_LockModule();
|
|
|
|
|
2007-12-30 17:43:39 +01:00
|
|
|
ret = heap_alloc_zero(sizeof(Binding));
|
2005-11-14 16:12:43 +01:00
|
|
|
|
2011-01-14 23:27:11 +01:00
|
|
|
ret->IBinding_iface.lpVtbl = &BindingVtbl;
|
2011-01-14 23:29:12 +01:00
|
|
|
ret->IInternetProtocolSink_iface.lpVtbl = &InternetProtocolSinkVtbl;
|
|
|
|
ret->IInternetBindInfo_iface.lpVtbl = &InternetBindInfoVtbl;
|
|
|
|
ret->IWinInetHttpInfo_iface.lpVtbl = &WinInetHttpInfoVtbl;
|
|
|
|
ret->IServiceProvider_iface.lpVtbl = &ServiceProviderVtbl;
|
2005-11-14 16:12:43 +01:00
|
|
|
|
|
|
|
ret->ref = 1;
|
|
|
|
|
2007-12-30 17:45:00 +01:00
|
|
|
ret->to_object = to_obj;
|
|
|
|
ret->iid = *riid;
|
2006-05-25 18:35:35 +02:00
|
|
|
ret->notif_hwnd = get_notif_hwnd();
|
2007-12-30 17:44:02 +01:00
|
|
|
ret->report_mime = !binding_ctx;
|
2007-08-03 13:35:35 +02:00
|
|
|
ret->download_state = BEFORE_DOWNLOAD;
|
2005-11-14 16:12:43 +01:00
|
|
|
|
2007-12-30 17:45:00 +01:00
|
|
|
if(to_obj) {
|
|
|
|
IBindCtx_AddRef(pbc);
|
|
|
|
ret->bctx = pbc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(mon) {
|
|
|
|
IMoniker_AddRef(mon);
|
|
|
|
ret->mon = mon;
|
|
|
|
}
|
|
|
|
|
2005-11-14 16:12:43 +01:00
|
|
|
ret->bindinfo.cbSize = sizeof(BINDINFO);
|
|
|
|
|
2006-05-31 19:45:16 +02:00
|
|
|
InitializeCriticalSection(&ret->section);
|
2007-03-10 22:10:52 +01:00
|
|
|
ret->section.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": Binding.section");
|
2006-05-31 19:45:16 +02:00
|
|
|
|
2005-11-14 16:12:43 +01:00
|
|
|
hres = get_callback(pbc, &ret->callback);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
WARN("Could not get IBindStatusCallback\n");
|
2011-01-14 23:27:11 +01:00
|
|
|
IBinding_Release(&ret->IBinding_iface);
|
2005-11-14 16:12:43 +01:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2006-01-05 13:42:32 +01:00
|
|
|
IBindStatusCallback_QueryInterface(ret->callback, &IID_IServiceProvider,
|
|
|
|
(void**)&ret->service_provider);
|
|
|
|
|
2007-12-30 17:44:02 +01:00
|
|
|
if(binding_ctx) {
|
|
|
|
ret->protocol = binding_ctx->protocol;
|
2011-01-12 00:43:44 +01:00
|
|
|
IInternetProtocolEx_AddRef(&ret->protocol->IInternetProtocolEx_iface);
|
2007-12-30 17:44:02 +01:00
|
|
|
}else {
|
2010-11-15 12:37:03 +01:00
|
|
|
hres = create_binding_protocol(TRUE, &ret->protocol);
|
2007-12-30 17:44:02 +01:00
|
|
|
if(FAILED(hres)) {
|
|
|
|
WARN("Could not get protocol handler\n");
|
2011-01-14 23:27:11 +01:00
|
|
|
IBinding_Release(&ret->IBinding_iface);
|
2007-12-30 17:44:02 +01:00
|
|
|
return hres;
|
|
|
|
}
|
2005-11-14 16:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
hres = IBindStatusCallback_GetBindInfo(ret->callback, &ret->bindf, &ret->bindinfo);
|
|
|
|
if(FAILED(hres)) {
|
2006-10-05 23:49:11 +02:00
|
|
|
WARN("GetBindInfo failed: %08x\n", hres);
|
2011-01-14 23:27:11 +01:00
|
|
|
IBinding_Release(&ret->IBinding_iface);
|
2005-11-14 16:12:43 +01:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2007-12-30 17:45:00 +01:00
|
|
|
TRACE("bindf %08x\n", ret->bindf);
|
2006-05-27 22:56:40 +02:00
|
|
|
dump_BINDINFO(&ret->bindinfo);
|
|
|
|
|
2005-12-26 13:27:10 +01:00
|
|
|
ret->bindf |= BINDF_FROMURLMON;
|
2007-12-30 17:45:00 +01:00
|
|
|
if(to_obj)
|
|
|
|
ret->bindinfo.dwOptions |= 0x100000;
|
2005-11-14 16:12:43 +01:00
|
|
|
|
2010-12-19 21:26:06 +01:00
|
|
|
if(!(ret->bindf & BINDF_ASYNCHRONOUS) || !(ret->bindf & BINDF_PULLDATA)) {
|
2005-12-26 13:27:10 +01:00
|
|
|
ret->bindf |= BINDF_NEEDFILE;
|
2010-05-04 20:13:54 +02:00
|
|
|
ret->use_cache_file = TRUE;
|
2010-11-15 12:38:06 +01:00
|
|
|
}else if(!is_urlmon_protocol(uri)) {
|
2010-05-04 20:13:54 +02:00
|
|
|
ret->bindf |= BINDF_NEEDFILE;
|
|
|
|
}
|
2005-12-26 13:27:10 +01:00
|
|
|
|
2010-11-15 12:38:06 +01:00
|
|
|
hres = IUri_GetDisplayUri(uri, &ret->url);
|
|
|
|
if(FAILED(hres)) {
|
2011-01-14 23:27:11 +01:00
|
|
|
IBinding_Release(&ret->IBinding_iface);
|
2010-11-15 12:38:06 +01:00
|
|
|
return hres;
|
|
|
|
}
|
2005-11-14 16:12:43 +01:00
|
|
|
|
2007-12-30 17:44:02 +01:00
|
|
|
if(binding_ctx) {
|
2008-01-31 18:15:11 +01:00
|
|
|
ret->stgmed_buf = binding_ctx->stgmed_buf;
|
2011-01-11 00:36:45 +01:00
|
|
|
IUnknown_AddRef(&ret->stgmed_buf->IUnknown_iface);
|
2007-12-30 17:44:02 +01:00
|
|
|
ret->clipboard_format = binding_ctx->clipboard_format;
|
|
|
|
}else {
|
2011-01-12 00:43:44 +01:00
|
|
|
ret->stgmed_buf = create_stgmed_buf(&ret->protocol->IInternetProtocolEx_iface);
|
2007-12-30 17:44:02 +01:00
|
|
|
}
|
2008-01-31 18:15:53 +01:00
|
|
|
|
2008-01-31 18:16:31 +01:00
|
|
|
if(to_obj) {
|
|
|
|
ret->stgmed_obj = NULL;
|
|
|
|
}else if(IsEqualGUID(&IID_IStream, riid)) {
|
|
|
|
ret->stgmed_obj = create_stgmed_stream(ret->stgmed_buf);
|
2008-01-31 18:17:48 +01:00
|
|
|
}else if(IsEqualGUID(&IID_IUnknown, riid)) {
|
|
|
|
ret->bindf |= BINDF_NEEDFILE;
|
|
|
|
ret->stgmed_obj = create_stgmed_file(ret->stgmed_buf);
|
2008-01-31 18:16:31 +01:00
|
|
|
}else {
|
|
|
|
FIXME("Unsupported riid %s\n", debugstr_guid(riid));
|
2011-01-14 23:27:11 +01:00
|
|
|
IBinding_Release(&ret->IBinding_iface);
|
2008-01-31 18:16:31 +01:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2005-11-14 16:12:43 +01:00
|
|
|
|
|
|
|
*binding = ret;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-11-15 12:38:06 +01:00
|
|
|
static HRESULT start_binding(IMoniker *mon, Binding *binding_ctx, IUri *uri, IBindCtx *pbc,
|
2007-12-30 17:45:00 +01:00
|
|
|
BOOL to_obj, REFIID riid, Binding **ret)
|
2005-11-14 16:12:43 +01:00
|
|
|
{
|
|
|
|
Binding *binding = NULL;
|
|
|
|
HRESULT hres;
|
2007-08-07 06:08:31 +02:00
|
|
|
MSG msg;
|
2005-11-14 16:12:43 +01:00
|
|
|
|
2010-11-15 12:38:06 +01:00
|
|
|
hres = Binding_Create(mon, binding_ctx, uri, pbc, to_obj, riid, &binding);
|
2005-11-14 16:12:43 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2011-01-14 23:27:11 +01:00
|
|
|
hres = IBindStatusCallback_OnStartBinding(binding->callback, 0, &binding->IBinding_iface);
|
2005-11-14 16:12:43 +01:00
|
|
|
if(FAILED(hres)) {
|
2006-10-05 23:49:11 +02:00
|
|
|
WARN("OnStartBinding failed: %08x\n", hres);
|
2011-05-02 05:29:53 +02:00
|
|
|
if(hres != E_ABORT && hres != E_NOTIMPL)
|
|
|
|
hres = INET_E_DOWNLOAD_FAILURE;
|
|
|
|
|
|
|
|
stop_binding(binding, hres, NULL);
|
2011-01-14 23:27:11 +01:00
|
|
|
IBinding_Release(&binding->IBinding_iface);
|
2005-11-14 16:12:43 +01:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2007-12-30 17:44:02 +01:00
|
|
|
if(binding_ctx) {
|
2011-01-14 23:29:12 +01:00
|
|
|
set_binding_sink(binding->protocol, &binding->IInternetProtocolSink_iface,
|
|
|
|
&binding->IInternetBindInfo_iface);
|
2009-12-15 21:16:35 +01:00
|
|
|
if(binding_ctx->redirect_url)
|
|
|
|
IBindStatusCallback_OnProgress(binding->callback, 0, 0, BINDSTATUS_REDIRECTING, binding_ctx->redirect_url);
|
2010-10-14 00:51:18 +02:00
|
|
|
report_data(binding, BSCF_FIRSTDATANOTIFICATION | (binding_ctx->download_state == END_DOWNLOAD ? BSCF_LASTDATANOTIFICATION : 0),
|
|
|
|
0, 0);
|
2007-12-30 17:44:02 +01:00
|
|
|
}else {
|
2011-01-12 00:43:44 +01:00
|
|
|
hres = IInternetProtocolEx_StartEx(&binding->protocol->IInternetProtocolEx_iface, uri,
|
2011-01-14 23:29:12 +01:00
|
|
|
&binding->IInternetProtocolSink_iface, &binding->IInternetBindInfo_iface,
|
|
|
|
PI_APARTMENTTHREADED|PI_MIMEVERIFICATION, 0);
|
2007-12-30 17:42:17 +01:00
|
|
|
|
2007-12-30 17:44:02 +01:00
|
|
|
TRACE("start ret %08x\n", hres);
|
2006-05-25 18:34:15 +02:00
|
|
|
|
2008-02-18 01:04:53 +01:00
|
|
|
if(FAILED(hres) && hres != E_PENDING) {
|
2007-12-30 17:44:02 +01:00
|
|
|
stop_binding(binding, hres, NULL);
|
2011-01-14 23:27:11 +01:00
|
|
|
IBinding_Release(&binding->IBinding_iface);
|
2006-05-25 18:34:15 +02:00
|
|
|
|
2007-12-30 17:44:02 +01:00
|
|
|
return hres;
|
|
|
|
}
|
2005-11-14 16:12:43 +01:00
|
|
|
}
|
|
|
|
|
2007-08-07 06:08:31 +02:00
|
|
|
while(!(binding->bindf & BINDF_ASYNCHRONOUS) &&
|
2007-12-30 17:43:26 +01:00
|
|
|
!(binding->state & BINDING_STOPPED)) {
|
2007-08-07 06:08:31 +02:00
|
|
|
MsgWaitForMultipleObjects(0, NULL, FALSE, 5000, QS_POSTMESSAGE);
|
|
|
|
while (PeekMessageW(&msg, binding->notif_hwnd, WM_USER, WM_USER+117, PM_REMOVE|PM_NOYIELD)) {
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessageW(&msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-30 17:42:17 +01:00
|
|
|
*ret = binding;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2010-11-15 12:38:06 +01:00
|
|
|
HRESULT bind_to_storage(IUri *uri, IBindCtx *pbc, REFIID riid, void **ppv)
|
2007-12-30 17:42:17 +01:00
|
|
|
{
|
2007-12-30 17:44:02 +01:00
|
|
|
Binding *binding = NULL, *binding_ctx;
|
2007-12-30 17:42:17 +01:00
|
|
|
HRESULT hres;
|
|
|
|
|
2007-12-30 17:44:02 +01:00
|
|
|
binding_ctx = get_bctx_binding(pbc);
|
|
|
|
|
2010-11-15 12:38:06 +01:00
|
|
|
hres = start_binding(NULL, binding_ctx, uri, pbc, FALSE, riid, &binding);
|
2007-12-30 17:44:02 +01:00
|
|
|
if(binding_ctx)
|
2011-01-14 23:27:11 +01:00
|
|
|
IBinding_Release(&binding_ctx->IBinding_iface);
|
2007-12-30 17:42:17 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
2011-02-15 17:01:14 +01:00
|
|
|
if(binding->hres == S_OK && binding->download_state != BEFORE_DOWNLOAD /* FIXME */) {
|
2007-12-30 17:43:26 +01:00
|
|
|
if((binding->state & BINDING_STOPPED) && (binding->state & BINDING_LOCKED))
|
2011-01-12 00:43:44 +01:00
|
|
|
IInternetProtocolEx_UnlockRequest(&binding->protocol->IInternetProtocolEx_iface);
|
2006-05-25 18:34:15 +02:00
|
|
|
|
2010-04-29 17:14:47 +02:00
|
|
|
hres = binding->stgmed_obj->vtbl->get_result(binding->stgmed_obj, binding->bindf, ppv);
|
2010-10-06 14:10:25 +02:00
|
|
|
}else if(binding->bindf & BINDF_ASYNCHRONOUS) {
|
2010-04-29 17:14:47 +02:00
|
|
|
hres = MK_S_ASYNCHRONOUS;
|
2010-10-06 14:10:25 +02:00
|
|
|
}else {
|
|
|
|
hres = FAILED(binding->hres) ? binding->hres : S_OK;
|
2006-05-25 18:34:15 +02:00
|
|
|
}
|
2005-11-14 16:12:43 +01:00
|
|
|
|
2011-01-14 23:27:11 +01:00
|
|
|
IBinding_Release(&binding->IBinding_iface);
|
2005-11-14 16:12:43 +01:00
|
|
|
|
2010-04-29 17:14:47 +02:00
|
|
|
return hres;
|
2005-11-14 16:12:43 +01:00
|
|
|
}
|
2007-12-30 17:45:00 +01:00
|
|
|
|
2010-11-15 12:38:06 +01:00
|
|
|
HRESULT bind_to_object(IMoniker *mon, IUri *uri, IBindCtx *pbc, REFIID riid, void **ppv)
|
2007-12-30 17:45:00 +01:00
|
|
|
{
|
|
|
|
Binding *binding;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
2010-11-15 12:38:06 +01:00
|
|
|
hres = start_binding(mon, NULL, uri, pbc, TRUE, riid, &binding);
|
2007-12-30 17:45:00 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
if(binding->hres != S_OK) {
|
|
|
|
hres = SUCCEEDED(binding->hres) ? S_OK : binding->hres;
|
|
|
|
}else if(binding->bindf & BINDF_ASYNCHRONOUS) {
|
|
|
|
hres = MK_S_ASYNCHRONOUS;
|
|
|
|
}else {
|
|
|
|
*ppv = binding->obj;
|
|
|
|
IUnknown_AddRef(binding->obj);
|
|
|
|
hres = S_OK;
|
|
|
|
}
|
|
|
|
|
2011-01-14 23:27:11 +01:00
|
|
|
IBinding_Release(&binding->IBinding_iface);
|
2007-12-30 17:45:00 +01:00
|
|
|
|
|
|
|
return hres;
|
|
|
|
}
|