2005-09-06 11:27:04 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2005 Jacek Caban
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2005-09-06 11:27:04 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "urlmon_main.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const IInternetProtocolVtbl *lpInternetProtocolVtbl;
|
2005-11-09 11:58:02 +01:00
|
|
|
const IInternetPriorityVtbl *lpInternetPriorityVtbl;
|
2005-09-06 11:27:04 +02:00
|
|
|
|
|
|
|
HANDLE file;
|
2005-11-09 11:58:02 +01:00
|
|
|
LONG priority;
|
2005-09-06 11:27:04 +02:00
|
|
|
|
|
|
|
LONG ref;
|
|
|
|
} FileProtocol;
|
|
|
|
|
|
|
|
#define PROTOCOL(x) ((IInternetProtocol*) &(x)->lpInternetProtocolVtbl)
|
2005-11-09 11:58:02 +01:00
|
|
|
#define PRIORITY(x) ((IInternetPriority*) &(x)->lpInternetPriorityVtbl)
|
|
|
|
|
|
|
|
#define PROTOCOL_THIS(iface) DEFINE_THIS(FileProtocol, InternetProtocol, iface)
|
2005-09-06 11:27:04 +02:00
|
|
|
|
|
|
|
static HRESULT WINAPI FileProtocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
FileProtocol *This = PROTOCOL_THIS(iface);
|
|
|
|
|
|
|
|
*ppv = NULL;
|
|
|
|
if(IsEqualGUID(&IID_IUnknown, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
|
|
|
|
*ppv = PROTOCOL(This);
|
|
|
|
}else if(IsEqualGUID(&IID_IInternetProtocolRoot, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This, ppv);
|
|
|
|
*ppv = PROTOCOL(This);
|
|
|
|
}else if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IInternetProtocol %p)\n", This, ppv);
|
|
|
|
*ppv = PROTOCOL(This);
|
2005-11-09 11:58:02 +01:00
|
|
|
}else if(IsEqualGUID(&IID_IInternetPriority, riid)) {
|
|
|
|
TRACE("(%p)->(IID_IInternetPriority %p)\n", This, ppv);
|
|
|
|
*ppv = PRIORITY(This);
|
2005-09-06 11:27:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(*ppv) {
|
|
|
|
IInternetProtocol_AddRef(iface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("not supported interface %s\n", debugstr_guid(riid));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI FileProtocol_AddRef(IInternetProtocol *iface)
|
|
|
|
{
|
|
|
|
FileProtocol *This = PROTOCOL_THIS(iface);
|
|
|
|
LONG ref = InterlockedIncrement(&This->ref);
|
2006-10-05 23:49:11 +02:00
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
2005-09-06 11:27:04 +02:00
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI FileProtocol_Release(IInternetProtocol *iface)
|
|
|
|
{
|
|
|
|
FileProtocol *This = PROTOCOL_THIS(iface);
|
|
|
|
LONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
2006-10-05 23:49:11 +02:00
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
2005-09-06 11:27:04 +02:00
|
|
|
|
|
|
|
if(!ref) {
|
|
|
|
if(This->file)
|
|
|
|
CloseHandle(This->file);
|
2007-11-29 22:12:34 +01:00
|
|
|
heap_free(This);
|
2005-09-06 11:27:04 +02:00
|
|
|
|
|
|
|
URLMON_UnlockModule();
|
|
|
|
}
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI FileProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
|
|
|
|
IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
|
|
|
|
DWORD grfPI, DWORD dwReserved)
|
|
|
|
{
|
|
|
|
FileProtocol *This = PROTOCOL_THIS(iface);
|
|
|
|
BINDINFO bindinfo;
|
|
|
|
DWORD grfBINDF = 0;
|
|
|
|
LARGE_INTEGER size;
|
2005-09-12 13:11:11 +02:00
|
|
|
DWORD len;
|
2005-09-14 12:29:56 +02:00
|
|
|
LPWSTR url, mime = NULL;
|
2005-12-19 09:52:30 +01:00
|
|
|
LPCWSTR file_name;
|
2005-10-29 12:28:47 +02:00
|
|
|
WCHAR null_char = 0;
|
2005-12-19 09:52:30 +01:00
|
|
|
BOOL first_call = FALSE;
|
2005-09-12 13:11:11 +02:00
|
|
|
HRESULT hres;
|
2005-09-06 11:27:04 +02:00
|
|
|
|
|
|
|
static const WCHAR wszFile[] = {'f','i','l','e',':'};
|
|
|
|
|
2006-10-05 23:49:11 +02:00
|
|
|
TRACE("(%p)->(%s %p %p %08x %d)\n", This, debugstr_w(szUrl), pOIProtSink,
|
2005-09-06 11:27:04 +02:00
|
|
|
pOIBindInfo, grfPI, dwReserved);
|
|
|
|
|
|
|
|
memset(&bindinfo, 0, sizeof(bindinfo));
|
|
|
|
bindinfo.cbSize = sizeof(BINDINFO);
|
2007-07-24 03:30:57 +02:00
|
|
|
hres = IInternetBindInfo_GetBindInfo(pOIBindInfo, &grfBINDF, &bindinfo);
|
|
|
|
if(FAILED(hres)) {
|
|
|
|
WARN("GetBindInfo failed: %08x\n", hres);
|
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReleaseBindInfo(&bindinfo);
|
2005-09-06 11:27:04 +02:00
|
|
|
|
|
|
|
if(lstrlenW(szUrl) < sizeof(wszFile)/sizeof(WCHAR)
|
|
|
|
|| memcmp(szUrl, wszFile, sizeof(wszFile)))
|
|
|
|
return MK_E_SYNTAX;
|
|
|
|
|
2005-09-12 13:11:11 +02:00
|
|
|
len = lstrlenW(szUrl)+16;
|
2007-11-29 22:12:34 +01:00
|
|
|
url = heap_alloc(len*sizeof(WCHAR));
|
2005-09-12 13:11:11 +02:00
|
|
|
hres = CoInternetParseUrl(szUrl, PARSE_ENCODE, 0, url, len, &len, 0);
|
|
|
|
if(FAILED(hres)) {
|
2007-11-29 22:12:34 +01:00
|
|
|
heap_free(url);
|
2005-09-12 13:11:11 +02:00
|
|
|
return hres;
|
|
|
|
}
|
|
|
|
|
2005-12-19 09:57:25 +01:00
|
|
|
if(!(grfBINDF & BINDF_FROMURLMON))
|
|
|
|
IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_DIRECTBIND, NULL);
|
2005-09-06 11:27:04 +02:00
|
|
|
|
|
|
|
if(!This->file) {
|
2005-12-19 09:52:30 +01:00
|
|
|
first_call = TRUE;
|
|
|
|
|
2005-10-29 12:28:47 +02:00
|
|
|
IInternetProtocolSink_ReportProgress(pOIProtSink, BINDSTATUS_SENDINGREQUEST, &null_char);
|
|
|
|
|
2005-12-19 09:52:30 +01:00
|
|
|
file_name = url+sizeof(wszFile)/sizeof(WCHAR);
|
2005-12-26 12:59:31 +01:00
|
|
|
if(file_name[0] == '/' && file_name[1] == '/')
|
|
|
|
file_name += 2;
|
|
|
|
if(*file_name == '/')
|
|
|
|
file_name++;
|
2005-12-19 09:52:30 +01:00
|
|
|
|
|
|
|
This->file = CreateFileW(file_name, GENERIC_READ, FILE_SHARE_READ, NULL,
|
|
|
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
2005-09-06 11:27:04 +02:00
|
|
|
|
|
|
|
if(This->file == INVALID_HANDLE_VALUE) {
|
|
|
|
This->file = NULL;
|
|
|
|
IInternetProtocolSink_ReportResult(pOIProtSink, INET_E_RESOURCE_NOT_FOUND,
|
|
|
|
GetLastError(), NULL);
|
2007-11-29 22:12:34 +01:00
|
|
|
heap_free(url);
|
2005-09-06 11:27:04 +02:00
|
|
|
return INET_E_RESOURCE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
2005-12-19 09:52:30 +01:00
|
|
|
IInternetProtocolSink_ReportProgress(pOIProtSink,
|
|
|
|
BINDSTATUS_CACHEFILENAMEAVAILABLE, file_name);
|
|
|
|
|
|
|
|
hres = FindMimeFromData(NULL, url, NULL, 0, NULL, 0, &mime, 0);
|
|
|
|
if(SUCCEEDED(hres)) {
|
|
|
|
IInternetProtocolSink_ReportProgress(pOIProtSink,
|
2005-12-19 09:57:25 +01:00
|
|
|
(grfBINDF & BINDF_FROMURLMON) ?
|
|
|
|
BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE : BINDSTATUS_MIMETYPEAVAILABLE,
|
|
|
|
mime);
|
2005-12-19 09:52:30 +01:00
|
|
|
CoTaskMemFree(mime);
|
|
|
|
}
|
2005-09-06 11:27:04 +02:00
|
|
|
}
|
|
|
|
|
2007-11-29 22:12:34 +01:00
|
|
|
heap_free(url);
|
2005-09-14 12:29:56 +02:00
|
|
|
|
2005-09-06 11:27:04 +02:00
|
|
|
if(GetFileSizeEx(This->file, &size))
|
|
|
|
IInternetProtocolSink_ReportData(pOIProtSink,
|
|
|
|
BSCF_FIRSTDATANOTIFICATION|BSCF_LASTDATANOTIFICATION,
|
|
|
|
size.u.LowPart, size.u.LowPart);
|
|
|
|
|
2005-12-19 09:52:30 +01:00
|
|
|
if(first_call)
|
|
|
|
IInternetProtocolSink_ReportResult(pOIProtSink, S_OK, 0, NULL);
|
|
|
|
|
2005-09-06 11:27:04 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI FileProtocol_Continue(IInternetProtocol *iface, PROTOCOLDATA *pProtocolData)
|
|
|
|
{
|
|
|
|
FileProtocol *This = PROTOCOL_THIS(iface);
|
|
|
|
FIXME("(%p)->(%p)\n", This, pProtocolData);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI FileProtocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
|
|
|
|
DWORD dwOptions)
|
|
|
|
{
|
|
|
|
FileProtocol *This = PROTOCOL_THIS(iface);
|
2006-10-05 23:49:11 +02:00
|
|
|
FIXME("(%p)->(%08x %08x)\n", This, hrReason, dwOptions);
|
2005-09-06 11:27:04 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI FileProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
|
|
|
|
{
|
|
|
|
FileProtocol *This = PROTOCOL_THIS(iface);
|
|
|
|
|
2006-10-05 23:49:11 +02:00
|
|
|
TRACE("(%p)->(%08x)\n", This, dwOptions);
|
2005-09-06 11:27:04 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI FileProtocol_Suspend(IInternetProtocol *iface)
|
|
|
|
{
|
|
|
|
FileProtocol *This = PROTOCOL_THIS(iface);
|
|
|
|
FIXME("(%p)\n", This);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI FileProtocol_Resume(IInternetProtocol *iface)
|
|
|
|
{
|
|
|
|
FileProtocol *This = PROTOCOL_THIS(iface);
|
|
|
|
FIXME("(%p)\n", This);
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI FileProtocol_Read(IInternetProtocol *iface, void *pv,
|
|
|
|
ULONG cb, ULONG *pcbRead)
|
|
|
|
{
|
|
|
|
FileProtocol *This = PROTOCOL_THIS(iface);
|
|
|
|
DWORD read = 0;
|
|
|
|
|
2006-10-05 23:49:11 +02:00
|
|
|
TRACE("(%p)->(%p %u %p)\n", This, pv, cb, pcbRead);
|
2005-09-06 11:27:04 +02:00
|
|
|
|
2008-02-15 11:09:25 +01:00
|
|
|
if (pcbRead)
|
|
|
|
*pcbRead = 0;
|
|
|
|
|
2005-09-06 11:27:04 +02:00
|
|
|
if(!This->file)
|
|
|
|
return INET_E_DATA_NOT_AVAILABLE;
|
|
|
|
|
2008-02-15 11:09:25 +01:00
|
|
|
if (!ReadFile(This->file, pv, cb, &read, NULL))
|
|
|
|
return INET_E_DOWNLOAD_FAILURE;
|
2005-09-06 11:27:04 +02:00
|
|
|
|
|
|
|
if(pcbRead)
|
|
|
|
*pcbRead = read;
|
|
|
|
|
|
|
|
return cb == read ? S_OK : S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI FileProtocol_Seek(IInternetProtocol *iface, LARGE_INTEGER dlibMove,
|
2006-10-03 14:11:42 +02:00
|
|
|
DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
|
2005-09-06 11:27:04 +02:00
|
|
|
{
|
|
|
|
FileProtocol *This = PROTOCOL_THIS(iface);
|
2006-10-05 23:49:11 +02:00
|
|
|
FIXME("(%p)->(%d %d %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
|
2005-09-06 11:27:04 +02:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI FileProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
|
|
|
|
{
|
|
|
|
FileProtocol *This = PROTOCOL_THIS(iface);
|
|
|
|
|
2006-10-05 23:49:11 +02:00
|
|
|
TRACE("(%p)->(%08x)\n", This, dwOptions);
|
2005-09-06 11:27:04 +02:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI FileProtocol_UnlockRequest(IInternetProtocol *iface)
|
|
|
|
{
|
|
|
|
FileProtocol *This = PROTOCOL_THIS(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef PROTOCOL_THIS
|
|
|
|
|
|
|
|
static const IInternetProtocolVtbl FileProtocolVtbl = {
|
|
|
|
FileProtocol_QueryInterface,
|
|
|
|
FileProtocol_AddRef,
|
|
|
|
FileProtocol_Release,
|
|
|
|
FileProtocol_Start,
|
|
|
|
FileProtocol_Continue,
|
|
|
|
FileProtocol_Abort,
|
|
|
|
FileProtocol_Terminate,
|
|
|
|
FileProtocol_Suspend,
|
|
|
|
FileProtocol_Resume,
|
|
|
|
FileProtocol_Read,
|
|
|
|
FileProtocol_Seek,
|
|
|
|
FileProtocol_LockRequest,
|
|
|
|
FileProtocol_UnlockRequest
|
|
|
|
};
|
|
|
|
|
2005-11-09 11:58:02 +01:00
|
|
|
#define PRIORITY_THIS(iface) DEFINE_THIS(FileProtocol, InternetPriority, iface)
|
|
|
|
|
|
|
|
static HRESULT WINAPI FilePriority_QueryInterface(IInternetPriority *iface,
|
|
|
|
REFIID riid, void **ppv)
|
|
|
|
{
|
|
|
|
FileProtocol *This = PRIORITY_THIS(iface);
|
|
|
|
return IInternetProtocol_QueryInterface(PROTOCOL(This), riid, ppv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI FilePriority_AddRef(IInternetPriority *iface)
|
|
|
|
{
|
|
|
|
FileProtocol *This = PRIORITY_THIS(iface);
|
|
|
|
return IInternetProtocol_AddRef(PROTOCOL(This));
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI FilePriority_Release(IInternetPriority *iface)
|
|
|
|
{
|
|
|
|
FileProtocol *This = PRIORITY_THIS(iface);
|
|
|
|
return IInternetProtocol_Release(PROTOCOL(This));
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI FilePriority_SetPriority(IInternetPriority *iface, LONG nPriority)
|
|
|
|
{
|
|
|
|
FileProtocol *This = PRIORITY_THIS(iface);
|
|
|
|
|
2006-10-05 23:49:11 +02:00
|
|
|
TRACE("(%p)->(%d)\n", This, nPriority);
|
2005-11-09 11:58:02 +01:00
|
|
|
|
|
|
|
This->priority = nPriority;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT WINAPI FilePriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
|
|
|
|
{
|
|
|
|
FileProtocol *This = PRIORITY_THIS(iface);
|
|
|
|
|
|
|
|
TRACE("(%p)->(%p)\n", This, pnPriority);
|
|
|
|
|
|
|
|
*pnPriority = This->priority;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef PRIORITY_THIS
|
|
|
|
|
|
|
|
static const IInternetPriorityVtbl FilePriorityVtbl = {
|
|
|
|
FilePriority_QueryInterface,
|
|
|
|
FilePriority_AddRef,
|
|
|
|
FilePriority_Release,
|
|
|
|
FilePriority_SetPriority,
|
|
|
|
FilePriority_GetPriority
|
|
|
|
};
|
|
|
|
|
2005-09-06 11:27:04 +02:00
|
|
|
HRESULT FileProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
|
|
|
|
{
|
|
|
|
FileProtocol *ret;
|
|
|
|
|
|
|
|
TRACE("(%p %p)\n", pUnkOuter, ppobj);
|
|
|
|
|
|
|
|
URLMON_LockModule();
|
|
|
|
|
2007-11-29 22:12:34 +01:00
|
|
|
ret = heap_alloc(sizeof(FileProtocol));
|
2005-09-06 11:27:04 +02:00
|
|
|
|
|
|
|
ret->lpInternetProtocolVtbl = &FileProtocolVtbl;
|
2005-11-09 11:58:02 +01:00
|
|
|
ret->lpInternetPriorityVtbl = &FilePriorityVtbl;
|
2005-09-06 11:27:04 +02:00
|
|
|
ret->file = NULL;
|
2005-11-09 11:58:02 +01:00
|
|
|
ret->priority = 0;
|
2005-09-06 11:27:04 +02:00
|
|
|
ret->ref = 1;
|
|
|
|
|
|
|
|
*ppobj = PROTOCOL(ret);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|