2 * Copyright 2005 Jacek Caban
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "urlmon_main.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(urlmon
);
35 const IInternetProtocolVtbl
*lpInternetProtocolVtbl
;
36 const IInternetPriorityVtbl
*lpInternetPriorityVtbl
;
44 #define PROTOCOL(x) ((IInternetProtocol*) &(x)->lpInternetProtocolVtbl)
45 #define PRIORITY(x) ((IInternetPriority*) &(x)->lpInternetPriorityVtbl)
47 #define PROTOCOL_THIS(iface) DEFINE_THIS(FileProtocol, InternetProtocol, iface)
49 static HRESULT WINAPI
FileProtocol_QueryInterface(IInternetProtocol
*iface
, REFIID riid
, void **ppv
)
51 FileProtocol
*This
= PROTOCOL_THIS(iface
);
54 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
55 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
56 *ppv
= PROTOCOL(This
);
57 }else if(IsEqualGUID(&IID_IInternetProtocolRoot
, riid
)) {
58 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This
, ppv
);
59 *ppv
= PROTOCOL(This
);
60 }else if(IsEqualGUID(&IID_IInternetProtocol
, riid
)) {
61 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This
, ppv
);
62 *ppv
= PROTOCOL(This
);
63 }else if(IsEqualGUID(&IID_IInternetPriority
, riid
)) {
64 TRACE("(%p)->(IID_IInternetPriority %p)\n", This
, ppv
);
65 *ppv
= PRIORITY(This
);
69 IInternetProtocol_AddRef(iface
);
73 WARN("not supported interface %s\n", debugstr_guid(riid
));
77 static ULONG WINAPI
FileProtocol_AddRef(IInternetProtocol
*iface
)
79 FileProtocol
*This
= PROTOCOL_THIS(iface
);
80 LONG ref
= InterlockedIncrement(&This
->ref
);
81 TRACE("(%p) ref=%ld\n", This
, ref
);
85 static ULONG WINAPI
FileProtocol_Release(IInternetProtocol
*iface
)
87 FileProtocol
*This
= PROTOCOL_THIS(iface
);
88 LONG ref
= InterlockedDecrement(&This
->ref
);
90 TRACE("(%p) ref=%ld\n", This
, ref
);
94 CloseHandle(This
->file
);
95 HeapFree(GetProcessHeap(), 0, This
);
97 URLMON_UnlockModule();
103 static HRESULT WINAPI
FileProtocol_Start(IInternetProtocol
*iface
, LPCWSTR szUrl
,
104 IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
,
105 DWORD grfPI
, DWORD dwReserved
)
107 FileProtocol
*This
= PROTOCOL_THIS(iface
);
112 LPWSTR url
, mime
= NULL
;
115 BOOL first_call
= FALSE
;
118 static const WCHAR wszFile
[] = {'f','i','l','e',':'};
120 TRACE("(%p)->(%s %p %p %08lx %ld)\n", This
, debugstr_w(szUrl
), pOIProtSink
,
121 pOIBindInfo
, grfPI
, dwReserved
);
123 memset(&bindinfo
, 0, sizeof(bindinfo
));
124 bindinfo
.cbSize
= sizeof(BINDINFO
);
125 IInternetBindInfo_GetBindInfo(pOIBindInfo
, &grfBINDF
, &bindinfo
);
127 if(lstrlenW(szUrl
) < sizeof(wszFile
)/sizeof(WCHAR
)
128 || memcmp(szUrl
, wszFile
, sizeof(wszFile
)))
131 len
= lstrlenW(szUrl
)+16;
132 url
= HeapAlloc(GetProcessHeap(), 0, len
*sizeof(WCHAR
));
133 hres
= CoInternetParseUrl(szUrl
, PARSE_ENCODE
, 0, url
, len
, &len
, 0);
135 HeapFree(GetProcessHeap(), 0, url
);
139 if(!(grfBINDF
& BINDF_FROMURLMON
))
140 IInternetProtocolSink_ReportProgress(pOIProtSink
, BINDSTATUS_DIRECTBIND
, NULL
);
145 IInternetProtocolSink_ReportProgress(pOIProtSink
, BINDSTATUS_SENDINGREQUEST
, &null_char
);
147 file_name
= url
+sizeof(wszFile
)/sizeof(WCHAR
);
148 if(file_name
[0] == '/' && file_name
[1] == '/' && file_name
[2] == '/')
151 This
->file
= CreateFileW(file_name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
152 OPEN_EXISTING
, FILE_ATTRIBUTE_NORMAL
, NULL
);
154 if(This
->file
== INVALID_HANDLE_VALUE
) {
156 IInternetProtocolSink_ReportResult(pOIProtSink
, INET_E_RESOURCE_NOT_FOUND
,
157 GetLastError(), NULL
);
158 HeapFree(GetProcessHeap(), 0, url
);
159 return INET_E_RESOURCE_NOT_FOUND
;
162 IInternetProtocolSink_ReportProgress(pOIProtSink
,
163 BINDSTATUS_CACHEFILENAMEAVAILABLE
, file_name
);
165 hres
= FindMimeFromData(NULL
, url
, NULL
, 0, NULL
, 0, &mime
, 0);
166 if(SUCCEEDED(hres
)) {
167 IInternetProtocolSink_ReportProgress(pOIProtSink
,
168 (grfBINDF
& BINDF_FROMURLMON
) ?
169 BINDSTATUS_VERIFIEDMIMETYPEAVAILABLE
: BINDSTATUS_MIMETYPEAVAILABLE
,
175 HeapFree(GetProcessHeap(), 0, url
);
177 if(GetFileSizeEx(This
->file
, &size
))
178 IInternetProtocolSink_ReportData(pOIProtSink
,
179 BSCF_FIRSTDATANOTIFICATION
|BSCF_LASTDATANOTIFICATION
,
180 size
.u
.LowPart
, size
.u
.LowPart
);
183 IInternetProtocolSink_ReportResult(pOIProtSink
, S_OK
, 0, NULL
);
188 static HRESULT WINAPI
FileProtocol_Continue(IInternetProtocol
*iface
, PROTOCOLDATA
*pProtocolData
)
190 FileProtocol
*This
= PROTOCOL_THIS(iface
);
191 FIXME("(%p)->(%p)\n", This
, pProtocolData
);
195 static HRESULT WINAPI
FileProtocol_Abort(IInternetProtocol
*iface
, HRESULT hrReason
,
198 FileProtocol
*This
= PROTOCOL_THIS(iface
);
199 FIXME("(%p)->(%08lx %08lx)\n", This
, hrReason
, dwOptions
);
203 static HRESULT WINAPI
FileProtocol_Terminate(IInternetProtocol
*iface
, DWORD dwOptions
)
205 FileProtocol
*This
= PROTOCOL_THIS(iface
);
207 TRACE("(%p)->(%08lx)\n", This
, dwOptions
);
212 static HRESULT WINAPI
FileProtocol_Suspend(IInternetProtocol
*iface
)
214 FileProtocol
*This
= PROTOCOL_THIS(iface
);
215 FIXME("(%p)\n", This
);
219 static HRESULT WINAPI
FileProtocol_Resume(IInternetProtocol
*iface
)
221 FileProtocol
*This
= PROTOCOL_THIS(iface
);
222 FIXME("(%p)\n", This
);
226 static HRESULT WINAPI
FileProtocol_Read(IInternetProtocol
*iface
, void *pv
,
227 ULONG cb
, ULONG
*pcbRead
)
229 FileProtocol
*This
= PROTOCOL_THIS(iface
);
232 TRACE("(%p)->(%p %lu %p)\n", This
, pv
, cb
, pcbRead
);
235 return INET_E_DATA_NOT_AVAILABLE
;
237 ReadFile(This
->file
, pv
, cb
, &read
, NULL
);
242 return cb
== read
? S_OK
: S_FALSE
;
245 static HRESULT WINAPI
FileProtocol_Seek(IInternetProtocol
*iface
, LARGE_INTEGER dlibMove
,
246 DWORD dwOrgin
, ULARGE_INTEGER
*plibNewPosition
)
248 FileProtocol
*This
= PROTOCOL_THIS(iface
);
249 FIXME("(%p)->(%ld %ld %p)\n", This
, dlibMove
.u
.LowPart
, dwOrgin
, plibNewPosition
);
253 static HRESULT WINAPI
FileProtocol_LockRequest(IInternetProtocol
*iface
, DWORD dwOptions
)
255 FileProtocol
*This
= PROTOCOL_THIS(iface
);
257 TRACE("(%p)->(%08lx)\n", This
, dwOptions
);
262 static HRESULT WINAPI
FileProtocol_UnlockRequest(IInternetProtocol
*iface
)
264 FileProtocol
*This
= PROTOCOL_THIS(iface
);
266 TRACE("(%p)\n", This
);
273 static const IInternetProtocolVtbl FileProtocolVtbl
= {
274 FileProtocol_QueryInterface
,
276 FileProtocol_Release
,
278 FileProtocol_Continue
,
280 FileProtocol_Terminate
,
281 FileProtocol_Suspend
,
285 FileProtocol_LockRequest
,
286 FileProtocol_UnlockRequest
289 #define PRIORITY_THIS(iface) DEFINE_THIS(FileProtocol, InternetPriority, iface)
291 static HRESULT WINAPI
FilePriority_QueryInterface(IInternetPriority
*iface
,
292 REFIID riid
, void **ppv
)
294 FileProtocol
*This
= PRIORITY_THIS(iface
);
295 return IInternetProtocol_QueryInterface(PROTOCOL(This
), riid
, ppv
);
298 static ULONG WINAPI
FilePriority_AddRef(IInternetPriority
*iface
)
300 FileProtocol
*This
= PRIORITY_THIS(iface
);
301 return IInternetProtocol_AddRef(PROTOCOL(This
));
304 static ULONG WINAPI
FilePriority_Release(IInternetPriority
*iface
)
306 FileProtocol
*This
= PRIORITY_THIS(iface
);
307 return IInternetProtocol_Release(PROTOCOL(This
));
310 static HRESULT WINAPI
FilePriority_SetPriority(IInternetPriority
*iface
, LONG nPriority
)
312 FileProtocol
*This
= PRIORITY_THIS(iface
);
314 TRACE("(%p)->(%ld)\n", This
, nPriority
);
316 This
->priority
= nPriority
;
320 static HRESULT WINAPI
FilePriority_GetPriority(IInternetPriority
*iface
, LONG
*pnPriority
)
322 FileProtocol
*This
= PRIORITY_THIS(iface
);
324 TRACE("(%p)->(%p)\n", This
, pnPriority
);
326 *pnPriority
= This
->priority
;
332 static const IInternetPriorityVtbl FilePriorityVtbl
= {
333 FilePriority_QueryInterface
,
335 FilePriority_Release
,
336 FilePriority_SetPriority
,
337 FilePriority_GetPriority
340 HRESULT
FileProtocol_Construct(IUnknown
*pUnkOuter
, LPVOID
*ppobj
)
344 TRACE("(%p %p)\n", pUnkOuter
, ppobj
);
348 ret
= HeapAlloc(GetProcessHeap(), 0, sizeof(FileProtocol
));
350 ret
->lpInternetProtocolVtbl
= &FileProtocolVtbl
;
351 ret
->lpInternetPriorityVtbl
= &FilePriorityVtbl
;
356 *ppobj
= PROTOCOL(ret
);