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 <stdarg.h>
|
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
#define NONAMELESSUNION
|
|
|
|
#define NONAMELESSSTRUCT
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "ole2.h"
|
|
|
|
#include "urlmon.h"
|
|
|
|
#include "urlmon_main.h"
|
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "wine/unicode.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
|
|
|
|
|
2006-05-31 19:45:16 +02:00
|
|
|
typedef struct Binding Binding;
|
|
|
|
|
2007-02-07 17:29:12 +01:00
|
|
|
struct _task_header_t;
|
2007-02-07 17:31:04 +01:00
|
|
|
|
2007-02-07 17:29:12 +01:00
|
|
|
typedef void (*task_proc_t)(Binding*, struct _task_header_t*);
|
2006-05-31 19:45:16 +02:00
|
|
|
|
2007-02-07 17:29:12 +01:00
|
|
|
typedef struct _task_header_t {
|
2007-02-07 17:31:04 +01:00
|
|
|
task_proc_t proc;
|
2007-02-07 17:29:12 +01:00
|
|
|
struct _task_header_t *next;
|
|
|
|
} task_header_t;
|
2006-01-09 17:18:06 +01:00
|
|
|
|
2005-11-14 16:12:43 +01:00
|
|
|
typedef struct {
|
2006-05-31 19:45:16 +02:00
|
|
|
const IStreamVtbl *lpStreamVtbl;
|
|
|
|
|
|
|
|
LONG ref;
|
|
|
|
|
|
|
|
IInternetProtocol *protocol;
|
|
|
|
|
|
|
|
BYTE buf[1024*8];
|
|
|
|
DWORD buf_size;
|
|
|
|
BOOL init_buf;
|
2007-02-10 16:32:44 +01:00
|
|
|
HRESULT hres;
|
2006-05-31 19:45:16 +02:00
|
|
|
} ProtocolStream;
|
|
|
|
|
2007-02-10 16:32:03 +01:00
|
|
|
typedef enum {
|
|
|
|
BEFORE_DOWNLOAD,
|
|
|
|
DOWNLOADING,
|
|
|
|
END_DOWNLOAD
|
|
|
|
} download_state_t;
|
|
|
|
|
2006-05-31 19:45:16 +02:00
|
|
|
struct Binding {
|
2005-11-14 16:12:43 +01:00
|
|
|
const IBindingVtbl *lpBindingVtbl;
|
|
|
|
const IInternetProtocolSinkVtbl *lpInternetProtocolSinkVtbl;
|
|
|
|
const IInternetBindInfoVtbl *lpInternetBindInfoVtbl;
|
|
|
|
const IServiceProviderVtbl *lpServiceProviderVtbl;
|
|
|
|
|
|
|
|
LONG ref;
|
|
|
|
|
|
|
|
IBindStatusCallback *callback;
|
|
|
|
IInternetProtocol *protocol;
|
2006-01-05 13:42:32 +01:00
|
|
|
IServiceProvider *service_provider;
|
2006-01-09 17:18:06 +01:00
|
|
|
ProtocolStream *stream;
|
2005-11-14 16:12:43 +01:00
|
|
|
|
|
|
|
BINDINFO bindinfo;
|
|
|
|
DWORD bindf;
|
|
|
|
LPWSTR mime;
|
|
|
|
LPWSTR url;
|
2007-02-08 02:33:32 +01:00
|
|
|
BOOL report_mime;
|
2006-05-31 19:45:16 +02:00
|
|
|
DWORD continue_call;
|
2007-02-07 17:28:17 +01:00
|
|
|
BOOL request_locked;
|
2007-02-10 16:32:03 +01:00
|
|
|
download_state_t download_state;
|
2006-05-25 18:35:35 +02:00
|
|
|
|
|
|
|
DWORD apartment_thread;
|
|
|
|
HWND notif_hwnd;
|
2006-05-27 22:56:20 +02:00
|
|
|
|
|
|
|
STGMEDIUM stgmed;
|
2006-01-09 17:18:06 +01:00
|
|
|
|
2007-02-07 17:29:12 +01:00
|
|
|
task_header_t *task_queue_head, *task_queue_tail;
|
2006-05-31 19:45:16 +02:00
|
|
|
CRITICAL_SECTION section;
|
2006-01-09 17:18:06 +01:00
|
|
|
};
|
|
|
|
|
2005-11-14 16:12:43 +01:00
|
|
|
#define BINDING(x) ((IBinding*) &(x)->lpBindingVtbl)
|
|
|
|
#define PROTSINK(x) ((IInternetProtocolSink*) &(x)->lpInternetProtocolSinkVtbl)
|
|
|
|
#define BINDINF(x) ((IInternetBindInfo*) &(x)->lpInternetBindInfoVtbl)
|
|
|
|
#define SERVPROV(x) ((IServiceProvider*) &(x)->lpServiceProviderVtbl)
|
|
|
|
|
2006-01-09 17:18:06 +01:00
|
|
|
#define STREAM(x) ((IStream*) &(x)->lpStreamVtbl)
|
|
|
|
|
2006-05-25 18:39:26 +02:00
|
|
|
#define WM_MK_CONTINUE (WM_USER+101)
|
2006-05-25 18:35:35 +02:00
|
|
|
|
2007-02-07 17:29:12 +01:00
|
|
|
static void push_task(Binding *binding, task_header_t *task, task_proc_t proc)
|
2006-05-31 19:45:16 +02:00
|
|
|
{
|
2007-02-07 17:29:12 +01:00
|
|
|
task->proc = proc;
|
2006-05-31 19:45:16 +02:00
|
|
|
task->next = NULL;
|
2006-05-25 18:35:35 +02:00
|
|
|
|
2007-02-07 17:29:12 +01:00
|
|
|
EnterCriticalSection(&binding->section);
|
2006-05-31 19:45:16 +02:00
|
|
|
|
2006-05-31 19:48:23 +02:00
|
|
|
if(binding->task_queue_tail)
|
|
|
|
binding->task_queue_tail->next = task;
|
2006-05-31 19:45:16 +02:00
|
|
|
else
|
2006-05-31 19:48:23 +02:00
|
|
|
binding->task_queue_tail = binding->task_queue_head = task;
|
2006-05-31 19:45:16 +02:00
|
|
|
|
2006-05-31 19:48:23 +02:00
|
|
|
LeaveCriticalSection(&binding->section);
|
2006-05-31 19:45:16 +02:00
|
|
|
}
|
|
|
|
|
2007-02-07 17:29:12 +01:00
|
|
|
static task_header_t *pop_task(Binding *binding)
|
2006-05-31 19:45:16 +02:00
|
|
|
{
|
2007-02-07 17:29:12 +01:00
|
|
|
task_header_t *ret;
|
2006-05-31 19:45:16 +02:00
|
|
|
|
2007-02-07 17:29:12 +01:00
|
|
|
EnterCriticalSection(&binding->section);
|
2006-05-31 19:45:16 +02:00
|
|
|
|
2007-02-07 17:29:12 +01:00
|
|
|
ret = binding->task_queue_head;
|
|
|
|
if(ret) {
|
|
|
|
binding->task_queue_head = ret->next;
|
|
|
|
if(!binding->task_queue_head)
|
|
|
|
binding->task_queue_tail = NULL;
|
|
|
|
}
|
2006-05-31 19:45:16 +02:00
|
|
|
|
2007-02-07 17:29:12 +01:00
|
|
|
LeaveCriticalSection(&binding->section);
|
2006-05-31 19:45:16 +02:00
|
|
|
|
2007-02-07 17:29:12 +01:00
|
|
|
return ret;
|
2006-05-31 19:45:16 +02:00
|
|
|
}
|
|
|
|
|
2006-06-03 00:26:48 +02:00
|
|
|
static void fill_stream_buffer(ProtocolStream *This)
|
|
|
|
{
|
|
|
|
DWORD read = 0;
|
|
|
|
|
|
|
|
if(sizeof(This->buf) == This->buf_size)
|
|
|
|
return;
|
|
|
|
|
2007-02-10 16:32:44 +01:00
|
|
|
This->hres = IInternetProtocol_Read(This->protocol, This->buf+This->buf_size,
|
|
|
|
sizeof(This->buf)-This->buf_size, &read);
|
|
|
|
if(SUCCEEDED(This->hres)) {
|
2006-06-03 00:26:48 +02:00
|
|
|
This->buf_size += read;
|
|
|
|
This->init_buf = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-25 18:35:35 +02:00
|
|
|
static LRESULT WINAPI notif_wnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2006-05-31 19:47:42 +02:00
|
|
|
if(msg == WM_MK_CONTINUE) {
|
2006-05-31 19:46:04 +02:00
|
|
|
Binding *binding = (Binding*)lParam;
|
2007-02-07 17:29:12 +01:00
|
|
|
task_header_t *task;
|
2006-05-31 19:45:16 +02:00
|
|
|
|
2007-02-08 02:34:52 +01:00
|
|
|
while((task = pop_task(binding))) {
|
|
|
|
binding->continue_call++;
|
2007-02-07 17:31:04 +01:00
|
|
|
task->proc(binding, task);
|
2007-02-08 02:34:52 +01:00
|
|
|
binding->continue_call--;
|
|
|
|
}
|
2006-05-25 18:39:26 +02:00
|
|
|
|
2006-05-31 19:46:04 +02:00
|
|
|
IBinding_Release(BINDING(binding));
|
2006-05-25 18:39:26 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2006-05-25 18:35:35 +02:00
|
|
|
|
|
|
|
return DefWindowProcW(hwnd, msg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
static HWND get_notif_hwnd(void)
|
|
|
|
{
|
|
|
|
static ATOM wnd_class = 0;
|
|
|
|
HWND hwnd;
|
|
|
|
|
|
|
|
static const WCHAR wszURLMonikerNotificationWindow[] =
|
|
|
|
{'U','R','L',' ','M','o','n','i','k','e','r',' ',
|
|
|
|
'N','o','t','i','f','i','c','a','t','i','o','n',' ','W','i','n','d','o','w',0};
|
|
|
|
|
|
|
|
if(!wnd_class) {
|
|
|
|
static WNDCLASSEXW wndclass = {
|
|
|
|
sizeof(wndclass), 0,
|
|
|
|
notif_wnd_proc, 0, 0,
|
|
|
|
NULL, NULL, NULL, NULL, NULL,
|
|
|
|
wszURLMonikerNotificationWindow,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
wndclass.hInstance = URLMON_hInstance;
|
|
|
|
|
|
|
|
wnd_class = RegisterClassExW(&wndclass);
|
2006-10-16 11:32:17 +02:00
|
|
|
if (!wnd_class && GetLastError() == ERROR_CLASS_ALREADY_EXISTS)
|
|
|
|
wnd_class = 1;
|
2006-05-25 18:35:35 +02:00
|
|
|
}
|
|
|
|
|
2006-10-16 11:32:17 +02:00
|
|
|
hwnd = CreateWindowExW(0, wszURLMonikerNotificationWindow,
|
2006-05-25 18:35:35 +02:00
|
|
|
wszURLMonikerNotificationWindow, 0, 0, 0, 0, 0, HWND_MESSAGE,
|
|
|
|
NULL, URLMON_hInstance, NULL);
|
|
|
|
|
|
|
|
TRACE("hwnd = %p\n", hwnd);
|
|
|
|
|
|
|
|
return hwnd;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2006-01-05 13:42:43 +01:00
|
|
|
static HRESULT WINAPI HttpNegotiate_QueryInterface(IHttpNegotiate2 *iface,
|
|
|
|
REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if(IsEqualGUID(&IID_IUnknown, riid)) {
|
|
|
|
TRACE("(IID_IUnknown %p)\n", ppv);
|
|
|
|
*ppv = iface;
|
|
|
|
}else if(IsEqualGUID(&IID_IHttpNegotiate, riid)) {
|
|
|
|
TRACE("(IID_IHttpNegotiate %p)\n", ppv);
|
|
|
|
*ppv = iface;
|
|
|
|
}else if(IsEqualGUID(&IID_IHttpNegotiate2, riid)) {
|
|
|
|
TRACE("(IID_IHttpNegotiate2 %p)\n", ppv);
|
|
|
|
*ppv = iface;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*ppv) {
|
|
|
|
IHttpNegotiate2_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("Unsupported interface %s\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI HttpNegotiate_AddRef(IHttpNegotiate2 *iface)
|
|
|
|
{
|
|
|
|
URLMON_LockModule();
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI HttpNegotiate_Release(IHttpNegotiate2 *iface)
|
|
|
|
{
|
|
|
|
URLMON_UnlockModule();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HttpNegotiate_BeginningTransaction(IHttpNegotiate2 *iface,
|
|
|
|
LPCWSTR szURL, LPCWSTR szHeaders, DWORD dwReserved, LPWSTR *pszAdditionalHeaders)
|
|
|
|
{
|
2006-10-05 23:49:11 +02:00
|
|
|
TRACE("(%s %s %d %p)\n", debugstr_w(szURL), debugstr_w(szHeaders), dwReserved,
|
2006-01-05 13:42:43 +01:00
|
|
|
pszAdditionalHeaders);
|
2006-05-25 18:32:54 +02:00
|
|
|
|
|
|
|
*pszAdditionalHeaders = NULL;
|
|
|
|
return S_OK;
|
2006-01-05 13:42:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HttpNegotiate_OnResponse(IHttpNegotiate2 *iface, DWORD dwResponseCode,
|
|
|
|
LPCWSTR szResponseHeaders, LPCWSTR szRequestHeaders,
|
|
|
|
LPWSTR *pszAdditionalRequestHeaders)
|
|
|
|
{
|
2006-10-05 23:49:11 +02:00
|
|
|
TRACE("(%d %s %s %p)\n", dwResponseCode, debugstr_w(szResponseHeaders),
|
2006-01-05 13:42:43 +01:00
|
|
|
debugstr_w(szRequestHeaders), pszAdditionalRequestHeaders);
|
2006-06-03 00:24:56 +02:00
|
|
|
|
|
|
|
if(pszAdditionalRequestHeaders)
|
|
|
|
*pszAdditionalRequestHeaders = NULL;
|
|
|
|
return S_OK;
|
2006-01-05 13:42:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI HttpNegotiate_GetRootSecurityId(IHttpNegotiate2 *iface,
|
|
|
|
BYTE *pbSecurityId, DWORD *pcbSecurityId, DWORD_PTR dwReserved)
|
|
|
|
{
|
2006-05-25 18:32:54 +02:00
|
|
|
TRACE("(%p %p %ld)\n", pbSecurityId, pcbSecurityId, dwReserved);
|
|
|
|
|
|
|
|
/* That's all we have to do here */
|
|
|
|
return E_FAIL;
|
2006-01-05 13:42:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const IHttpNegotiate2Vtbl HttpNegotiate2Vtbl = {
|
|
|
|
HttpNegotiate_QueryInterface,
|
|
|
|
HttpNegotiate_AddRef,
|
|
|
|
HttpNegotiate_Release,
|
|
|
|
HttpNegotiate_BeginningTransaction,
|
|
|
|
HttpNegotiate_OnResponse,
|
|
|
|
HttpNegotiate_GetRootSecurityId
|
|
|
|
};
|
|
|
|
|
|
|
|
static IHttpNegotiate2 HttpNegotiate = { &HttpNegotiate2Vtbl };
|
2005-11-14 16:12:43 +01:00
|
|
|
|
2006-01-09 17:18:06 +01:00
|
|
|
#define STREAM_THIS(iface) DEFINE_THIS(ProtocolStream, Stream, iface)
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProtocolStream_QueryInterface(IStream *iface,
|
|
|
|
REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
ProtocolStream *This = STREAM_THIS(iface);
|
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if(IsEqualGUID(&IID_IUnknown, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
|
|
|
|
*ppv = STREAM(This);
|
|
|
|
}else if(IsEqualGUID(&IID_ISequentialStream, riid)) {
|
|
|
|
TRACE("(%p)->(IID_ISequentialStream %p)\n", This, ppv);
|
|
|
|
*ppv = STREAM(This);
|
|
|
|
}else if(IsEqualGUID(&IID_IStream, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IStream %p)\n", This, ppv);
|
|
|
|
*ppv = STREAM(This);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(*ppv) {
|
|
|
|
IStream_AddRef(STREAM(This));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ProtocolStream_AddRef(IStream *iface)
|
|
|
|
{
|
|
|
|
ProtocolStream *This = STREAM_THIS(iface);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
ProtocolStream *This = STREAM_THIS(iface);
|
|
|
|
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) {
|
|
|
|
IInternetProtocol_Release(This->protocol);
|
|
|
|
HeapFree(GetProcessHeap(), 0, 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,
|
|
|
|
ULONG cb, ULONG *pcbRead)
|
|
|
|
{
|
|
|
|
ProtocolStream *This = STREAM_THIS(iface);
|
|
|
|
DWORD read = 0, pread = 0;
|
|
|
|
|
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
|
|
|
|
|
|
|
if(This->buf_size) {
|
|
|
|
read = cb;
|
|
|
|
|
|
|
|
if(read > This->buf_size)
|
|
|
|
read = This->buf_size;
|
|
|
|
|
|
|
|
memcpy(pv, This->buf, read);
|
|
|
|
|
|
|
|
if(read < This->buf_size)
|
|
|
|
memmove(This->buf, This->buf+read, This->buf_size-read);
|
|
|
|
This->buf_size -= read;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(read == cb) {
|
|
|
|
*pcbRead = read;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2007-02-10 16:32:44 +01:00
|
|
|
This->hres = IInternetProtocol_Read(This->protocol, (PBYTE)pv+read, cb-read, &pread);
|
2006-01-09 17:18:06 +01:00
|
|
|
*pcbRead = read + pread;
|
|
|
|
|
2007-02-10 16:32:44 +01:00
|
|
|
if(This->hres == E_PENDING)
|
2006-05-25 18:40:47 +02:00
|
|
|
return E_PENDING;
|
2007-02-10 16:32:44 +01:00
|
|
|
else if(FAILED(This->hres))
|
|
|
|
FIXME("Read failed: %08x\n", This->hres);
|
2006-05-25 18:40:47 +02:00
|
|
|
|
2006-01-09 17:18:06 +01:00
|
|
|
return read || pread ? S_OK : S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProtocolStream_Write(IStream *iface, const void *pv,
|
|
|
|
ULONG cb, ULONG *pcbWritten)
|
|
|
|
{
|
|
|
|
ProtocolStream *This = STREAM_THIS(iface);
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
ProtocolStream *This = STREAM_THIS(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)
|
|
|
|
{
|
|
|
|
ProtocolStream *This = STREAM_THIS(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)
|
|
|
|
{
|
|
|
|
ProtocolStream *This = STREAM_THIS(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)
|
|
|
|
{
|
|
|
|
ProtocolStream *This = STREAM_THIS(iface);
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
ProtocolStream *This = STREAM_THIS(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProtocolStream_LockRegion(IStream *iface, ULARGE_INTEGER libOffset,
|
|
|
|
ULARGE_INTEGER cb, DWORD dwLockType)
|
|
|
|
{
|
|
|
|
ProtocolStream *This = STREAM_THIS(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)
|
|
|
|
{
|
|
|
|
ProtocolStream *This = STREAM_THIS(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)
|
|
|
|
{
|
|
|
|
ProtocolStream *This = STREAM_THIS(iface);
|
2006-10-05 23:49:11 +02:00
|
|
|
FIXME("(%p)->(%p %08x)\n", This, pstatstg, dwStatFlag);
|
2006-01-09 17:18:06 +01:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ProtocolStream_Clone(IStream *iface, IStream **ppstm)
|
|
|
|
{
|
|
|
|
ProtocolStream *This = STREAM_THIS(iface);
|
|
|
|
FIXME("(%p)->(%p)\n", This, ppstm);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef STREAM_THIS
|
|
|
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2005-11-14 16:12:43 +01:00
|
|
|
#define BINDING_THIS(iface) DEFINE_THIS(Binding, Binding, iface)
|
|
|
|
|
2006-01-09 17:18:06 +01:00
|
|
|
static ProtocolStream *create_stream(IInternetProtocol *protocol)
|
|
|
|
{
|
|
|
|
ProtocolStream *ret = HeapAlloc(GetProcessHeap(), 0, sizeof(ProtocolStream));
|
|
|
|
|
|
|
|
ret->lpStreamVtbl = &ProtocolStreamVtbl;
|
|
|
|
ret->ref = 1;
|
|
|
|
ret->buf_size = 0;
|
2006-05-25 18:34:15 +02:00
|
|
|
ret->init_buf = FALSE;
|
2007-02-10 16:32:44 +01:00
|
|
|
ret->hres = S_OK;
|
2006-01-09 17:18:06 +01:00
|
|
|
|
|
|
|
IInternetProtocol_AddRef(protocol);
|
|
|
|
ret->protocol = protocol;
|
|
|
|
|
2006-01-09 17:20:04 +01:00
|
|
|
URLMON_LockModule();
|
|
|
|
|
2006-01-09 17:18:06 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-11-14 16:12:43 +01:00
|
|
|
static HRESULT WINAPI Binding_QueryInterface(IBinding *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
Binding *This = BINDING_THIS(iface);
|
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
if(IsEqualGUID(&IID_IUnknown, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
|
|
|
|
*ppv = BINDING(This);
|
|
|
|
}else if(IsEqualGUID(&IID_IBinding, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IBinding %p)\n", This, ppv);
|
|
|
|
*ppv = BINDING(This);
|
|
|
|
}else if(IsEqualGUID(&IID_IInternetProtocolSink, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IInternetProtocolSink %p)\n", This, ppv);
|
|
|
|
*ppv = PROTSINK(This);
|
|
|
|
}else if(IsEqualGUID(&IID_IInternetBindInfo, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IInternetBindInfo %p)\n", This, ppv);
|
|
|
|
*ppv = BINDINF(This);
|
|
|
|
}else if(IsEqualGUID(&IID_IServiceProvider, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IServiceProvider %p)\n", This, ppv);
|
|
|
|
*ppv = SERVPROV(This);
|
|
|
|
}
|
|
|
|
|
2006-01-09 17:20:04 +01:00
|
|
|
if(*ppv) {
|
|
|
|
IBinding_AddRef(BINDING(This));
|
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)
|
|
|
|
{
|
|
|
|
Binding *This = BINDING_THIS(iface);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
Binding *This = BINDING_THIS(iface);
|
|
|
|
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) {
|
2006-10-16 11:32:17 +02:00
|
|
|
if (This->notif_hwnd)
|
|
|
|
DestroyWindow( This->notif_hwnd );
|
2005-11-14 16:12:43 +01:00
|
|
|
if(This->callback)
|
|
|
|
IBindStatusCallback_Release(This->callback);
|
|
|
|
if(This->protocol)
|
|
|
|
IInternetProtocol_Release(This->protocol);
|
2006-01-05 13:42:32 +01:00
|
|
|
if(This->service_provider)
|
|
|
|
IServiceProvider_Release(This->service_provider);
|
2005-11-14 16:12:43 +01:00
|
|
|
if(This->stream)
|
2006-01-09 17:18:06 +01:00
|
|
|
IStream_Release(STREAM(This->stream));
|
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);
|
2005-11-14 16:12:43 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->mime);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->url);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, 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)
|
|
|
|
{
|
|
|
|
Binding *This = BINDING_THIS(iface);
|
|
|
|
FIXME("(%p)\n", This);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Binding_Suspend(IBinding *iface)
|
|
|
|
{
|
|
|
|
Binding *This = BINDING_THIS(iface);
|
|
|
|
FIXME("(%p)\n", This);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Binding_Resume(IBinding *iface)
|
|
|
|
{
|
|
|
|
Binding *This = BINDING_THIS(iface);
|
|
|
|
FIXME("(%p)\n", This);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Binding_SetPriority(IBinding *iface, LONG nPriority)
|
|
|
|
{
|
|
|
|
Binding *This = BINDING_THIS(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)
|
|
|
|
{
|
|
|
|
Binding *This = BINDING_THIS(iface);
|
|
|
|
FIXME("(%p)->(%p)\n", This, pnPriority);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI Binding_GetBindResult(IBinding *iface, CLSID *pclsidProtocol,
|
|
|
|
DWORD *pdwResult, LPOLESTR *pszResult, DWORD *pdwReserved)
|
|
|
|
{
|
|
|
|
Binding *This = BINDING_THIS(iface);
|
|
|
|
FIXME("(%p)->(%p %p %p %p)\n", This, pclsidProtocol, pdwResult, pszResult, pdwReserved);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef BINDING_THIS
|
|
|
|
|
|
|
|
static const IBindingVtbl BindingVtbl = {
|
|
|
|
Binding_QueryInterface,
|
|
|
|
Binding_AddRef,
|
|
|
|
Binding_Release,
|
|
|
|
Binding_Abort,
|
|
|
|
Binding_Suspend,
|
|
|
|
Binding_Resume,
|
|
|
|
Binding_SetPriority,
|
|
|
|
Binding_GetPriority,
|
|
|
|
Binding_GetBindResult
|
|
|
|
};
|
|
|
|
|
|
|
|
#define PROTSINK_THIS(iface) DEFINE_THIS(Binding, InternetProtocolSink, iface)
|
|
|
|
|
|
|
|
static HRESULT WINAPI InternetProtocolSink_QueryInterface(IInternetProtocolSink *iface,
|
|
|
|
REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
Binding *This = PROTSINK_THIS(iface);
|
|
|
|
return IBinding_QueryInterface(BINDING(This), riid, ppv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI InternetProtocolSink_AddRef(IInternetProtocolSink *iface)
|
|
|
|
{
|
|
|
|
Binding *This = PROTSINK_THIS(iface);
|
|
|
|
return IBinding_AddRef(BINDING(This));
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI InternetProtocolSink_Release(IInternetProtocolSink *iface)
|
|
|
|
{
|
|
|
|
Binding *This = PROTSINK_THIS(iface);
|
|
|
|
return IBinding_Release(BINDING(This));
|
|
|
|
}
|
|
|
|
|
2007-02-07 17:29:12 +01:00
|
|
|
typedef struct {
|
|
|
|
task_header_t header;
|
|
|
|
PROTOCOLDATA *data;
|
|
|
|
} switch_task_t;
|
|
|
|
|
|
|
|
static void switch_proc(Binding *binding, task_header_t *t)
|
2007-02-07 17:31:04 +01:00
|
|
|
{
|
2007-02-07 17:29:12 +01:00
|
|
|
switch_task_t *task = (switch_task_t*)t;
|
|
|
|
|
|
|
|
IInternetProtocol_Continue(binding->protocol, task->data);
|
2007-02-07 17:31:04 +01:00
|
|
|
|
2007-02-07 17:29:12 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, task);
|
2007-02-07 17:31:04 +01:00
|
|
|
}
|
|
|
|
|
2005-11-14 16:12:43 +01:00
|
|
|
static HRESULT WINAPI InternetProtocolSink_Switch(IInternetProtocolSink *iface,
|
|
|
|
PROTOCOLDATA *pProtocolData)
|
|
|
|
{
|
|
|
|
Binding *This = PROTSINK_THIS(iface);
|
2007-02-07 17:29:12 +01:00
|
|
|
switch_task_t *task;
|
2006-05-25 18:39:26 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, pProtocolData);
|
|
|
|
|
2007-02-07 17:29:12 +01:00
|
|
|
task = HeapAlloc(GetProcessHeap(), 0, sizeof(switch_task_t));
|
|
|
|
task->data = pProtocolData;
|
2006-05-25 18:39:26 +02:00
|
|
|
|
2007-02-07 17:29:12 +01:00
|
|
|
push_task(This, &task->header, switch_proc);
|
2006-05-31 19:46:04 +02:00
|
|
|
|
|
|
|
IBinding_AddRef(BINDING(This));
|
|
|
|
PostMessageW(This->notif_hwnd, WM_MK_CONTINUE, 0, (LPARAM)This);
|
2006-05-25 18:39:26 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2005-11-14 16:12:43 +01:00
|
|
|
}
|
|
|
|
|
2007-02-07 17:29:12 +01:00
|
|
|
typedef struct {
|
|
|
|
task_header_t header;
|
|
|
|
|
|
|
|
Binding *binding;
|
|
|
|
ULONG progress;
|
|
|
|
ULONG progress_max;
|
|
|
|
ULONG status_code;
|
|
|
|
LPWSTR status_text;
|
|
|
|
} on_progress_task_t;
|
|
|
|
|
|
|
|
static void on_progress_proc(Binding *binding, task_header_t *t)
|
2007-02-07 17:31:04 +01:00
|
|
|
{
|
2007-02-07 17:29:12 +01:00
|
|
|
on_progress_task_t *task = (on_progress_task_t*)t;
|
|
|
|
|
|
|
|
IBindStatusCallback_OnProgress(binding->callback, task->progress,
|
|
|
|
task->progress_max, task->status_code, task->status_text);
|
2007-02-07 17:31:04 +01:00
|
|
|
|
2007-02-07 17:29:12 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, task->status_text);
|
|
|
|
HeapFree(GetProcessHeap(), 0, task);
|
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)
|
|
|
|
{
|
2007-02-07 17:29:12 +01:00
|
|
|
on_progress_task_t *task;
|
2007-02-07 17:31:04 +01:00
|
|
|
|
|
|
|
if(GetCurrentThreadId() == This->apartment_thread && !This->continue_call) {
|
|
|
|
IBindStatusCallback_OnProgress(This->callback, progress, progress_max,
|
|
|
|
status_code, status_text);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-02-07 17:29:12 +01:00
|
|
|
task = HeapAlloc(GetProcessHeap(), 0, sizeof(on_progress_task_t));
|
2007-02-07 17:31:04 +01:00
|
|
|
|
2007-02-07 17:29:12 +01:00
|
|
|
task->progress = progress;
|
|
|
|
task->progress_max = progress_max;
|
|
|
|
task->status_code = status_code;
|
2007-02-07 17:31:04 +01:00
|
|
|
|
|
|
|
if(status_text) {
|
|
|
|
DWORD size = (strlenW(status_text)+1)*sizeof(WCHAR);
|
|
|
|
|
2007-02-07 17:29:12 +01:00
|
|
|
task->status_text = HeapAlloc(GetProcessHeap(), 0, size);
|
|
|
|
memcpy(task->status_text, status_text, size);
|
2007-02-07 17:31:04 +01:00
|
|
|
}else {
|
2007-02-07 17:29:12 +01:00
|
|
|
task->status_text = NULL;
|
2007-02-07 17:31:04 +01:00
|
|
|
}
|
|
|
|
|
2007-02-07 17:29:12 +01:00
|
|
|
push_task(This, &task->header, on_progress_proc);
|
2007-02-07 17:31:04 +01:00
|
|
|
|
|
|
|
if(GetCurrentThreadId() != This->apartment_thread) {
|
|
|
|
IBinding_AddRef(BINDING(This));
|
|
|
|
PostMessageW(This->notif_hwnd, WM_MK_CONTINUE, 0, (LPARAM)This);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-14 16:12:43 +01:00
|
|
|
static HRESULT WINAPI InternetProtocolSink_ReportProgress(IInternetProtocolSink *iface,
|
|
|
|
ULONG ulStatusCode, LPCWSTR szStatusText)
|
|
|
|
{
|
|
|
|
Binding *This = PROTSINK_THIS(iface);
|
|
|
|
|
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;
|
2007-02-07 17:30:28 +01:00
|
|
|
case BINDSTATUS_BEGINDOWNLOADDATA:
|
|
|
|
fill_stream_buffer(This->stream);
|
|
|
|
break;
|
2005-11-14 16:12:43 +01:00
|
|
|
case BINDSTATUS_MIMETYPEAVAILABLE: {
|
|
|
|
int len = strlenW(szStatusText)+1;
|
|
|
|
This->mime = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
|
|
|
|
memcpy(This->mime, szStatusText, len*sizeof(WCHAR));
|
|
|
|
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;
|
|
|
|
case BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE:
|
2007-02-08 02:33:32 +01:00
|
|
|
This->report_mime = FALSE;
|
2006-05-25 18:35:35 +02:00
|
|
|
on_progress(This, 0, 0, BINDSTATUS_MIMETYPEAVAILABLE, szStatusText);
|
2005-12-26 13:27:10 +01:00
|
|
|
break;
|
|
|
|
case BINDSTATUS_CACHEFILENAMEAVAILABLE:
|
|
|
|
break;
|
2007-02-08 02:33:32 +01:00
|
|
|
case BINDSTATUS_DIRECTBIND:
|
|
|
|
This->report_mime = FALSE;
|
|
|
|
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-02-07 17:29:52 +01:00
|
|
|
TRACE("(%p)->(%d %u %u)\n", This, bscf, progress, progress_max);
|
|
|
|
|
2007-02-10 16:32:03 +01:00
|
|
|
if(This->download_state == END_DOWNLOAD)
|
|
|
|
return;
|
|
|
|
|
2007-02-07 17:29:52 +01:00
|
|
|
if(GetCurrentThreadId() != This->apartment_thread)
|
|
|
|
FIXME("called from worked hread\n");
|
|
|
|
|
2007-02-08 02:33:32 +01:00
|
|
|
if(This->report_mime) {
|
2007-02-07 17:29:52 +01:00
|
|
|
LPWSTR mime;
|
|
|
|
|
2007-02-08 02:33:32 +01:00
|
|
|
This->report_mime = FALSE;
|
2007-02-07 17:29:52 +01:00
|
|
|
|
|
|
|
fill_stream_buffer(This->stream);
|
|
|
|
|
|
|
|
FindMimeFromData(NULL, This->url, This->stream->buf,
|
|
|
|
min(This->stream->buf_size, 255), This->mime, 0, &mime, 0);
|
|
|
|
|
2007-02-08 02:34:13 +01:00
|
|
|
IBindStatusCallback_OnProgress(This->callback, progress, progress_max,
|
|
|
|
BINDSTATUS_MIMETYPEAVAILABLE, mime);
|
2007-02-07 17:29:52 +01:00
|
|
|
}
|
|
|
|
|
2007-02-10 16:32:03 +01:00
|
|
|
if(This->download_state == BEFORE_DOWNLOAD) {
|
|
|
|
fill_stream_buffer(This->stream);
|
|
|
|
|
|
|
|
This->download_state = DOWNLOADING;
|
2007-02-08 02:34:13 +01:00
|
|
|
IBindStatusCallback_OnProgress(This->callback, progress, progress_max,
|
|
|
|
BINDSTATUS_BEGINDOWNLOADDATA, This->url);
|
2007-02-07 17:29:52 +01:00
|
|
|
}
|
|
|
|
|
2007-02-10 16:32:44 +01:00
|
|
|
if(This->stream->hres == S_FALSE || (bscf & BSCF_LASTDATANOTIFICATION)) {
|
2007-02-08 02:34:13 +01:00
|
|
|
IBindStatusCallback_OnProgress(This->callback, progress, progress_max,
|
|
|
|
BINDSTATUS_ENDDOWNLOADDATA, This->url);
|
2007-02-10 16:32:03 +01:00
|
|
|
}
|
2007-02-07 17:29:52 +01:00
|
|
|
|
|
|
|
if(!This->request_locked) {
|
|
|
|
HRESULT hres = IInternetProtocol_LockRequest(This->protocol, 0);
|
|
|
|
This->request_locked = SUCCEEDED(hres);
|
|
|
|
}
|
|
|
|
|
2007-02-07 17:31:04 +01:00
|
|
|
fill_stream_buffer(This->stream);
|
|
|
|
|
|
|
|
IBindStatusCallback_OnDataAvailable(This->callback, bscf, This->stream->buf_size,
|
|
|
|
&formatetc, &This->stgmed);
|
2007-02-07 17:29:52 +01:00
|
|
|
|
2007-02-10 16:32:44 +01:00
|
|
|
if(This->stream->hres == S_FALSE) {
|
2007-02-10 16:32:03 +01:00
|
|
|
This->download_state = END_DOWNLOAD;
|
2007-02-07 17:29:52 +01:00
|
|
|
IBindStatusCallback_OnStopBinding(This->callback, S_OK, NULL);
|
2007-02-10 16:32:03 +01:00
|
|
|
}
|
2007-02-07 17:31:04 +01:00
|
|
|
}
|
|
|
|
|
2007-02-07 17:29:12 +01:00
|
|
|
typedef struct {
|
|
|
|
task_header_t header;
|
|
|
|
DWORD bscf;
|
2007-02-07 17:29:52 +01:00
|
|
|
ULONG progress;
|
|
|
|
ULONG progress_max;
|
2007-02-07 17:29:12 +01:00
|
|
|
} report_data_task_t;
|
|
|
|
|
|
|
|
static void report_data_proc(Binding *binding, task_header_t *t)
|
2007-02-07 17:31:04 +01:00
|
|
|
{
|
2007-02-07 17:29:12 +01:00
|
|
|
report_data_task_t *task = (report_data_task_t*)t;
|
|
|
|
|
2007-02-07 17:29:52 +01:00
|
|
|
report_data(binding, task->bscf, task->progress, task->progress_max);
|
2007-02-07 17:31:04 +01:00
|
|
|
|
2007-02-07 17:29:12 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, task);
|
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)
|
|
|
|
{
|
|
|
|
Binding *This = PROTSINK_THIS(iface);
|
|
|
|
|
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
|
|
|
|
2007-02-07 17:31:04 +01:00
|
|
|
if(GetCurrentThreadId() != This->apartment_thread)
|
|
|
|
FIXME("called from worked hread\n");
|
|
|
|
|
|
|
|
if(This->continue_call) {
|
2007-02-07 17:29:12 +01:00
|
|
|
report_data_task_t *task = HeapAlloc(GetProcessHeap(), 0, sizeof(report_data_task_t));
|
|
|
|
task->bscf = grfBSCF;
|
2007-02-07 17:29:52 +01:00
|
|
|
task->progress = ulProgress;
|
|
|
|
task->progress_max = ulProgressMax;
|
2007-02-07 17:31:04 +01:00
|
|
|
|
2007-02-07 17:29:12 +01:00
|
|
|
push_task(This, &task->header, report_data_proc);
|
2007-02-07 17:31:04 +01:00
|
|
|
}else {
|
2007-02-07 17:29:52 +01:00
|
|
|
report_data(This, grfBSCF, ulProgress, ulProgressMax);
|
2007-02-07 17:31:04 +01:00
|
|
|
}
|
2005-11-14 16:12:43 +01:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2007-02-08 02:32:48 +01:00
|
|
|
static void report_result_proc(Binding *binding, task_header_t *t)
|
|
|
|
{
|
|
|
|
IInternetProtocol_Terminate(binding->protocol, 0);
|
|
|
|
|
|
|
|
if(binding->request_locked) {
|
|
|
|
IInternetProtocol_UnlockRequest(binding->protocol);
|
|
|
|
binding->request_locked = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, t);
|
|
|
|
}
|
|
|
|
|
2005-11-14 16:12:43 +01:00
|
|
|
static HRESULT WINAPI InternetProtocolSink_ReportResult(IInternetProtocolSink *iface,
|
|
|
|
HRESULT hrResult, DWORD dwError, LPCWSTR szResult)
|
|
|
|
{
|
|
|
|
Binding *This = PROTSINK_THIS(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
|
|
|
|
2007-02-08 02:32:48 +01:00
|
|
|
if(GetCurrentThreadId() == This->apartment_thread && !This->continue_call) {
|
|
|
|
IInternetProtocol_Terminate(This->protocol, 0);
|
|
|
|
}else {
|
|
|
|
task_header_t *task = HeapAlloc(GetProcessHeap(), 0, sizeof(task_header_t));
|
|
|
|
push_task(This, task, report_result_proc);
|
|
|
|
}
|
|
|
|
|
2006-05-25 18:33:21 +02:00
|
|
|
return S_OK;
|
2005-11-14 16:12:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#undef PROTSINK_THIS
|
|
|
|
|
|
|
|
static const IInternetProtocolSinkVtbl InternetProtocolSinkVtbl = {
|
|
|
|
InternetProtocolSink_QueryInterface,
|
|
|
|
InternetProtocolSink_AddRef,
|
|
|
|
InternetProtocolSink_Release,
|
|
|
|
InternetProtocolSink_Switch,
|
|
|
|
InternetProtocolSink_ReportProgress,
|
|
|
|
InternetProtocolSink_ReportData,
|
|
|
|
InternetProtocolSink_ReportResult
|
|
|
|
};
|
|
|
|
|
|
|
|
#define BINDINF_THIS(iface) DEFINE_THIS(Binding, InternetBindInfo, iface)
|
|
|
|
|
|
|
|
static HRESULT WINAPI InternetBindInfo_QueryInterface(IInternetBindInfo *iface,
|
|
|
|
REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
Binding *This = BINDINF_THIS(iface);
|
|
|
|
return IBinding_QueryInterface(BINDING(This), riid, ppv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI InternetBindInfo_AddRef(IInternetBindInfo *iface)
|
|
|
|
{
|
|
|
|
Binding *This = BINDINF_THIS(iface);
|
|
|
|
return IBinding_AddRef(BINDING(This));
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI InternetBindInfo_Release(IInternetBindInfo *iface)
|
|
|
|
{
|
|
|
|
Binding *This = BINDINF_THIS(iface);
|
|
|
|
return IBinding_Release(BINDING(This));
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI InternetBindInfo_GetBindInfo(IInternetBindInfo *iface,
|
|
|
|
DWORD *grfBINDF, BINDINFO *pbindinfo)
|
|
|
|
{
|
|
|
|
Binding *This = BINDINF_THIS(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p %p)\n", This, grfBINDF, pbindinfo);
|
|
|
|
|
|
|
|
*grfBINDF = This->bindf;
|
|
|
|
|
|
|
|
memcpy(pbindinfo, &This->bindinfo, sizeof(BINDINFO));
|
|
|
|
|
|
|
|
if(pbindinfo->szExtraInfo || pbindinfo->szCustomVerb)
|
|
|
|
FIXME("copy strings\n");
|
|
|
|
|
|
|
|
if(pbindinfo->pUnk)
|
|
|
|
IUnknown_AddRef(pbindinfo->pUnk);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI InternetBindInfo_GetBindString(IInternetBindInfo *iface,
|
|
|
|
ULONG ulStringType, LPOLESTR *ppwzStr, ULONG cEl, ULONG *pcElFetched)
|
|
|
|
{
|
|
|
|
Binding *This = BINDINF_THIS(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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef BINDF_THIS
|
|
|
|
|
|
|
|
static const IInternetBindInfoVtbl InternetBindInfoVtbl = {
|
|
|
|
InternetBindInfo_QueryInterface,
|
|
|
|
InternetBindInfo_AddRef,
|
|
|
|
InternetBindInfo_Release,
|
|
|
|
InternetBindInfo_GetBindInfo,
|
|
|
|
InternetBindInfo_GetBindString
|
|
|
|
};
|
|
|
|
|
|
|
|
#define SERVPROV_THIS(iface) DEFINE_THIS(Binding, ServiceProvider, iface)
|
|
|
|
|
|
|
|
static HRESULT WINAPI ServiceProvider_QueryInterface(IServiceProvider *iface,
|
|
|
|
REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
Binding *This = SERVPROV_THIS(iface);
|
|
|
|
return IBinding_QueryInterface(BINDING(This), riid, ppv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ServiceProvider_AddRef(IServiceProvider *iface)
|
|
|
|
{
|
|
|
|
Binding *This = SERVPROV_THIS(iface);
|
|
|
|
return IBinding_AddRef(BINDING(This));
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI ServiceProvider_Release(IServiceProvider *iface)
|
|
|
|
{
|
|
|
|
Binding *This = SERVPROV_THIS(iface);
|
|
|
|
return IBinding_Release(BINDING(This));
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI ServiceProvider_QueryService(IServiceProvider *iface,
|
|
|
|
REFGUID guidService, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
Binding *This = SERVPROV_THIS(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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(IsEqualGUID(&IID_IHttpNegotiate, guidService)
|
|
|
|
|| IsEqualGUID(&IID_IHttpNegotiate2, guidService))
|
|
|
|
return IHttpNegotiate2_QueryInterface(&HttpNegotiate, riid, ppv);
|
|
|
|
|
|
|
|
WARN("unknown service %s\n", debugstr_guid(guidService));
|
2005-11-14 16:12:43 +01:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef SERVPROV_THIS
|
|
|
|
|
|
|
|
static const IServiceProviderVtbl ServiceProviderVtbl = {
|
|
|
|
ServiceProvider_QueryInterface,
|
|
|
|
ServiceProvider_AddRef,
|
|
|
|
ServiceProvider_Release,
|
|
|
|
ServiceProvider_QueryService
|
|
|
|
};
|
|
|
|
|
|
|
|
static HRESULT get_callback(IBindCtx *pbc, IBindStatusCallback **callback)
|
|
|
|
{
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
static WCHAR wszBSCBHolder[] = { '_','B','S','C','B','_','H','o','l','d','e','r','_',0 };
|
|
|
|
|
|
|
|
hres = IBindCtx_GetObjectParam(pbc, wszBSCBHolder, (IUnknown**)callback);
|
|
|
|
if(FAILED(hres))
|
2005-12-16 12:40:39 +01:00
|
|
|
return MK_E_SYNTAX;
|
2005-11-14 16:12:43 +01:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT get_protocol(Binding *This, LPCWSTR url)
|
|
|
|
{
|
|
|
|
IClassFactory *cf = NULL;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = IBindStatusCallback_QueryInterface(This->callback, &IID_IInternetProtocol,
|
|
|
|
(void**)&This->protocol);
|
|
|
|
if(SUCCEEDED(hres))
|
|
|
|
return S_OK;
|
|
|
|
|
2006-01-05 13:42:32 +01:00
|
|
|
if(This->service_provider) {
|
|
|
|
hres = IServiceProvider_QueryService(This->service_provider, &IID_IInternetProtocol,
|
|
|
|
&IID_IInternetProtocol, (void**)&This->protocol);
|
|
|
|
if(SUCCEEDED(hres))
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2007-01-23 19:35:35 +01:00
|
|
|
hres = get_protocol_handler(url, NULL, &cf);
|
2005-11-14 16:12:43 +01:00
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = IClassFactory_CreateInstance(cf, NULL, &IID_IInternetProtocol, (void**)&This->protocol);
|
|
|
|
IClassFactory_Release(cf);
|
|
|
|
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2007-02-07 17:27:35 +01:00
|
|
|
static BOOL is_urlmon_protocol(LPCWSTR url)
|
|
|
|
{
|
|
|
|
static const WCHAR wszCdl[] = {'c','d','l'};
|
|
|
|
static const WCHAR wszFile[] = {'f','i','l','e'};
|
|
|
|
static const WCHAR wszFtp[] = {'f','t','p'};
|
|
|
|
static const WCHAR wszGopher[] = {'g','o','p','h','e','r'};
|
|
|
|
static const WCHAR wszHttp[] = {'h','t','t','p'};
|
|
|
|
static const WCHAR wszHttps[] = {'h','t','t','p','s'};
|
|
|
|
static const WCHAR wszMk[] = {'m','k'};
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
LPCWSTR scheme;
|
|
|
|
int len;
|
|
|
|
} protocol_list[] = {
|
|
|
|
{wszCdl, sizeof(wszCdl) /sizeof(WCHAR)},
|
|
|
|
{wszFile, sizeof(wszFile) /sizeof(WCHAR)},
|
|
|
|
{wszFtp, sizeof(wszFtp) /sizeof(WCHAR)},
|
|
|
|
{wszGopher, sizeof(wszGopher)/sizeof(WCHAR)},
|
|
|
|
{wszHttp, sizeof(wszHttp) /sizeof(WCHAR)},
|
|
|
|
{wszHttps, sizeof(wszHttps) /sizeof(WCHAR)},
|
|
|
|
{wszMk, sizeof(wszMk) /sizeof(WCHAR)}
|
|
|
|
};
|
|
|
|
|
|
|
|
int i, len = strlenW(url);
|
|
|
|
|
|
|
|
for(i=0; i < sizeof(protocol_list)/sizeof(protocol_list[0]); i++) {
|
|
|
|
if(len >= protocol_list[i].len
|
|
|
|
&& !memcmp(url, protocol_list[i].scheme, protocol_list[i].len*sizeof(WCHAR)))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-11-14 16:12:43 +01:00
|
|
|
static HRESULT Binding_Create(LPCWSTR url, IBindCtx *pbc, REFIID riid, Binding **binding)
|
|
|
|
{
|
|
|
|
Binding *ret;
|
|
|
|
int len;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
if(!IsEqualGUID(&IID_IStream, riid)) {
|
|
|
|
FIXME("Unsupported riid %s\n", debugstr_guid(riid));
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2006-01-09 17:20:04 +01:00
|
|
|
URLMON_LockModule();
|
|
|
|
|
2005-11-14 16:12:43 +01:00
|
|
|
ret = HeapAlloc(GetProcessHeap(), 0, sizeof(Binding));
|
|
|
|
|
|
|
|
ret->lpBindingVtbl = &BindingVtbl;
|
|
|
|
ret->lpInternetProtocolSinkVtbl = &InternetProtocolSinkVtbl;
|
|
|
|
ret->lpInternetBindInfoVtbl = &InternetBindInfoVtbl;
|
|
|
|
ret->lpServiceProviderVtbl = &ServiceProviderVtbl;
|
|
|
|
|
|
|
|
ret->ref = 1;
|
|
|
|
|
|
|
|
ret->callback = NULL;
|
|
|
|
ret->protocol = NULL;
|
2006-01-05 13:42:32 +01:00
|
|
|
ret->service_provider = NULL;
|
2005-11-14 16:12:43 +01:00
|
|
|
ret->stream = NULL;
|
|
|
|
ret->mime = NULL;
|
|
|
|
ret->url = NULL;
|
2006-05-25 18:35:35 +02:00
|
|
|
ret->apartment_thread = GetCurrentThreadId();
|
|
|
|
ret->notif_hwnd = get_notif_hwnd();
|
2007-02-08 02:33:32 +01:00
|
|
|
ret->report_mime = TRUE;
|
2006-05-31 19:45:16 +02:00
|
|
|
ret->continue_call = 0;
|
2007-02-07 17:28:17 +01:00
|
|
|
ret->request_locked = FALSE;
|
2007-02-10 16:32:03 +01:00
|
|
|
ret->download_state = BEFORE_DOWNLOAD;
|
2006-05-31 19:45:16 +02:00
|
|
|
ret->task_queue_head = ret->task_queue_tail = NULL;
|
2005-11-14 16:12:43 +01:00
|
|
|
|
|
|
|
memset(&ret->bindinfo, 0, sizeof(BINDINFO));
|
|
|
|
ret->bindinfo.cbSize = sizeof(BINDINFO);
|
|
|
|
ret->bindf = 0;
|
|
|
|
|
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");
|
|
|
|
IBinding_Release(BINDING(ret));
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2006-01-05 13:42:32 +01:00
|
|
|
IBindStatusCallback_QueryInterface(ret->callback, &IID_IServiceProvider,
|
|
|
|
(void**)&ret->service_provider);
|
|
|
|
|
2005-11-14 16:12:43 +01:00
|
|
|
hres = get_protocol(ret, url);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
WARN("Could not get protocol handler\n");
|
|
|
|
IBinding_Release(BINDING(ret));
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2005-11-14 16:12:43 +01:00
|
|
|
IBinding_Release(BINDING(ret));
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2006-05-27 22:56:40 +02:00
|
|
|
dump_BINDINFO(&ret->bindinfo);
|
|
|
|
|
2005-12-26 13:27:10 +01:00
|
|
|
ret->bindf |= BINDF_FROMURLMON;
|
2005-11-14 16:12:43 +01:00
|
|
|
|
2007-02-07 17:27:35 +01:00
|
|
|
if(!is_urlmon_protocol(url))
|
2005-12-26 13:27:10 +01:00
|
|
|
ret->bindf |= BINDF_NEEDFILE;
|
|
|
|
|
2007-02-07 17:27:35 +01:00
|
|
|
len = strlenW(url)+1;
|
2005-11-14 16:12:43 +01:00
|
|
|
ret->url = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
|
|
|
|
memcpy(ret->url, url, len*sizeof(WCHAR));
|
|
|
|
|
2006-01-09 17:18:06 +01:00
|
|
|
ret->stream = create_stream(ret->protocol);
|
2006-05-27 22:56:20 +02:00
|
|
|
ret->stgmed.tymed = TYMED_ISTREAM;
|
|
|
|
ret->stgmed.u.pstm = STREAM(ret->stream);
|
|
|
|
ret->stgmed.pUnkForRelease = (IUnknown*)BINDING(ret); /* NOTE: Windows uses other IUnknown */
|
2005-11-14 16:12:43 +01:00
|
|
|
|
|
|
|
*binding = ret;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT start_binding(LPCWSTR url, IBindCtx *pbc, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
Binding *binding = NULL;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
|
|
|
|
hres = Binding_Create(url, pbc, riid, &binding);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return hres;
|
|
|
|
|
|
|
|
hres = IBindStatusCallback_OnStartBinding(binding->callback, 0, BINDING(binding));
|
|
|
|
if(FAILED(hres)) {
|
2006-10-05 23:49:11 +02:00
|
|
|
WARN("OnStartBinding failed: %08x\n", hres);
|
2005-11-14 16:12:43 +01:00
|
|
|
IBindStatusCallback_OnStopBinding(binding->callback, 0x800c0008, NULL);
|
|
|
|
IBinding_Release(BINDING(binding));
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
hres = IInternetProtocol_Start(binding->protocol, url, PROTSINK(binding),
|
|
|
|
BINDINF(binding), 0, 0);
|
|
|
|
|
2006-05-25 18:34:15 +02:00
|
|
|
if(FAILED(hres)) {
|
2006-10-05 23:49:11 +02:00
|
|
|
WARN("Start failed: %08x\n", hres);
|
2006-05-25 18:34:15 +02:00
|
|
|
|
|
|
|
IInternetProtocol_Terminate(binding->protocol, 0);
|
2005-11-14 16:12:43 +01:00
|
|
|
IBindStatusCallback_OnStopBinding(binding->callback, S_OK, NULL);
|
2006-05-25 18:34:15 +02:00
|
|
|
IBinding_Release(BINDING(binding));
|
|
|
|
|
|
|
|
return hres;
|
2005-11-14 16:12:43 +01:00
|
|
|
}
|
|
|
|
|
2006-05-25 18:34:15 +02:00
|
|
|
if(binding->stream->init_buf) {
|
2007-02-07 17:28:17 +01:00
|
|
|
if(binding->request_locked)
|
|
|
|
IInternetProtocol_UnlockRequest(binding->protocol);
|
2006-05-25 18:34:15 +02:00
|
|
|
|
|
|
|
IStream_AddRef(STREAM(binding->stream));
|
|
|
|
*ppv = binding->stream;
|
|
|
|
|
|
|
|
hres = S_OK;
|
|
|
|
}else {
|
|
|
|
hres = MK_S_ASYNCHRONOUS;
|
|
|
|
}
|
2005-11-14 16:12:43 +01:00
|
|
|
|
|
|
|
IBinding_Release(BINDING(binding));
|
|
|
|
|
|
|
|
return hres;
|
|
|
|
}
|