2 * Copyright 2005-2009 Jacek Caban for CodeWeavers
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "urlmon_main.h"
20 #include "wine/debug.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(urlmon);
27 const IInternetProtocolVtbl *lpIInternetProtocolVtbl;
28 const IInternetPriorityVtbl *lpInternetPriorityVtbl;
29 const IWinInetHttpInfoVtbl *lpWinInetHttpInfoVtbl;
34 #define PRIORITY(x) ((IInternetPriority*) &(x)->lpInternetPriorityVtbl)
35 #define INETHTTPINFO(x) ((IWinInetHttpInfo*) &(x)->lpWinInetHttpInfoVtbl)
37 #define ASYNCPROTOCOL_THIS(iface) DEFINE_THIS2(FtpProtocol, base, iface)
39 static HRESULT FtpProtocol_open_request(Protocol *prot, IUri *uri, DWORD request_flags,
40 HINTERNET internet_session, IInternetBindInfo *bind_info)
42 FtpProtocol *This = ASYNCPROTOCOL_THIS(prot);
46 hres = IUri_GetAbsoluteUri(uri, &url);
50 This->base.request = InternetOpenUrlW(internet_session, url, NULL, 0,
51 request_flags|INTERNET_FLAG_EXISTING_CONNECT|INTERNET_FLAG_PASSIVE,
52 (DWORD_PTR)&This->base);
54 if (!This->base.request && GetLastError() != ERROR_IO_PENDING) {
55 WARN("InternetOpenUrl failed: %d\n", GetLastError());
56 return INET_E_RESOURCE_NOT_FOUND;
62 static HRESULT FtpProtocol_start_downloading(Protocol *prot)
64 FtpProtocol *This = ASYNCPROTOCOL_THIS(prot);
68 res = FtpGetFileSize(This->base.request, &size);
70 This->base.content_length = size;
72 WARN("FtpGetFileSize failed: %d\n", GetLastError());
77 static void FtpProtocol_close_connection(Protocol *prot)
81 #undef ASYNCPROTOCOL_THIS
83 static const ProtocolVtbl AsyncProtocolVtbl = {
84 FtpProtocol_open_request,
85 FtpProtocol_start_downloading,
86 FtpProtocol_close_connection
89 #define PROTOCOL_THIS(iface) DEFINE_THIS(FtpProtocol, IInternetProtocol, iface)
91 static HRESULT WINAPI FtpProtocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
93 FtpProtocol *This = PROTOCOL_THIS(iface);
96 if(IsEqualGUID(&IID_IUnknown, riid)) {
97 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
98 *ppv = PROTOCOL(This);
99 }else if(IsEqualGUID(&IID_IInternetProtocolRoot, riid)) {
100 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This, ppv);
101 *ppv = PROTOCOL(This);
102 }else if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
103 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This, ppv);
104 *ppv = PROTOCOL(This);
105 }else if(IsEqualGUID(&IID_IInternetPriority, riid)) {
106 TRACE("(%p)->(IID_IInternetPriority %p)\n", This, ppv);
107 *ppv = PRIORITY(This);
108 }else if(IsEqualGUID(&IID_IWinInetInfo, riid)) {
109 TRACE("(%p)->(IID_IWinInetInfo %p)\n", This, ppv);
110 *ppv = INETHTTPINFO(This);
111 }else if(IsEqualGUID(&IID_IWinInetHttpInfo, riid)) {
112 TRACE("(%p)->(IID_IWinInetHttpInfo %p)\n", This, ppv);
113 *ppv = INETHTTPINFO(This);
117 IInternetProtocol_AddRef(iface);
121 WARN("not supported interface %s\n", debugstr_guid(riid));
122 return E_NOINTERFACE;
125 static ULONG WINAPI FtpProtocol_AddRef(IInternetProtocol *iface)
127 FtpProtocol *This = PROTOCOL_THIS(iface);
128 LONG ref = InterlockedIncrement(&This->ref);
129 TRACE("(%p) ref=%d\n", This, ref);
133 static ULONG WINAPI FtpProtocol_Release(IInternetProtocol *iface)
135 FtpProtocol *This = PROTOCOL_THIS(iface);
136 LONG ref = InterlockedDecrement(&This->ref);
138 TRACE("(%p) ref=%d\n", This, ref);
141 protocol_close_connection(&This->base);
144 URLMON_UnlockModule();
150 static HRESULT WINAPI FtpProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
151 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
152 DWORD grfPI, HANDLE_PTR dwReserved)
154 FtpProtocol *This = PROTOCOL_THIS(iface);
158 static const WCHAR ftpW[] = {'f','t','p',':'};
160 TRACE("(%p)->(%s %p %p %08x %lx)\n", This, debugstr_w(szUrl), pOIProtSink,
161 pOIBindInfo, grfPI, dwReserved);
163 if(strncmpW(szUrl, ftpW, sizeof(ftpW)/sizeof(WCHAR)))
166 hres = CreateUri(szUrl, 0, 0, &uri);
170 hres = protocol_start(&This->base, PROTOCOL(This), uri, pOIProtSink, pOIBindInfo);
176 static HRESULT WINAPI FtpProtocol_Continue(IInternetProtocol *iface, PROTOCOLDATA *pProtocolData)
178 FtpProtocol *This = PROTOCOL_THIS(iface);
180 TRACE("(%p)->(%p)\n", This, pProtocolData);
182 return protocol_continue(&This->base, pProtocolData);
185 static HRESULT WINAPI FtpProtocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
188 FtpProtocol *This = PROTOCOL_THIS(iface);
189 FIXME("(%p)->(%08x %08x)\n", This, hrReason, dwOptions);
193 static HRESULT WINAPI FtpProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
195 FtpProtocol *This = PROTOCOL_THIS(iface);
197 TRACE("(%p)->(%08x)\n", This, dwOptions);
199 protocol_close_connection(&This->base);
203 static HRESULT WINAPI FtpProtocol_Suspend(IInternetProtocol *iface)
205 FtpProtocol *This = PROTOCOL_THIS(iface);
206 FIXME("(%p)\n", This);
210 static HRESULT WINAPI FtpProtocol_Resume(IInternetProtocol *iface)
212 FtpProtocol *This = PROTOCOL_THIS(iface);
213 FIXME("(%p)\n", This);
217 static HRESULT WINAPI FtpProtocol_Read(IInternetProtocol *iface, void *pv,
218 ULONG cb, ULONG *pcbRead)
220 FtpProtocol *This = PROTOCOL_THIS(iface);
222 TRACE("(%p)->(%p %u %p)\n", This, pv, cb, pcbRead);
224 return protocol_read(&This->base, pv, cb, pcbRead);
227 static HRESULT WINAPI FtpProtocol_Seek(IInternetProtocol *iface, LARGE_INTEGER dlibMove,
228 DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
230 FtpProtocol *This = PROTOCOL_THIS(iface);
231 FIXME("(%p)->(%d %d %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
235 static HRESULT WINAPI FtpProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
237 FtpProtocol *This = PROTOCOL_THIS(iface);
239 TRACE("(%p)->(%08x)\n", This, dwOptions);
241 return protocol_lock_request(&This->base);
244 static HRESULT WINAPI FtpProtocol_UnlockRequest(IInternetProtocol *iface)
246 FtpProtocol *This = PROTOCOL_THIS(iface);
248 TRACE("(%p)\n", This);
250 return protocol_unlock_request(&This->base);
255 static const IInternetProtocolVtbl FtpProtocolVtbl = {
256 FtpProtocol_QueryInterface,
260 FtpProtocol_Continue,
262 FtpProtocol_Terminate,
267 FtpProtocol_LockRequest,
268 FtpProtocol_UnlockRequest
271 #define PRIORITY_THIS(iface) DEFINE_THIS(FtpProtocol, InternetPriority, iface)
273 static HRESULT WINAPI FtpPriority_QueryInterface(IInternetPriority *iface, REFIID riid, void **ppv)
275 FtpProtocol *This = PRIORITY_THIS(iface);
276 return IInternetProtocol_QueryInterface(PROTOCOL(This), riid, ppv);
279 static ULONG WINAPI FtpPriority_AddRef(IInternetPriority *iface)
281 FtpProtocol *This = PRIORITY_THIS(iface);
282 return IInternetProtocol_AddRef(PROTOCOL(This));
285 static ULONG WINAPI FtpPriority_Release(IInternetPriority *iface)
287 FtpProtocol *This = PRIORITY_THIS(iface);
288 return IInternetProtocol_Release(PROTOCOL(This));
291 static HRESULT WINAPI FtpPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
293 FtpProtocol *This = PRIORITY_THIS(iface);
295 TRACE("(%p)->(%d)\n", This, nPriority);
297 This->base.priority = nPriority;
301 static HRESULT WINAPI FtpPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
303 FtpProtocol *This = PRIORITY_THIS(iface);
305 TRACE("(%p)->(%p)\n", This, pnPriority);
307 *pnPriority = This->base.priority;
313 static const IInternetPriorityVtbl FtpPriorityVtbl = {
314 FtpPriority_QueryInterface,
317 FtpPriority_SetPriority,
318 FtpPriority_GetPriority
321 #define INETINFO_THIS(iface) DEFINE_THIS(FtpProtocol, WinInetHttpInfo, iface)
323 static HRESULT WINAPI HttpInfo_QueryInterface(IWinInetHttpInfo *iface, REFIID riid, void **ppv)
325 FtpProtocol *This = INETINFO_THIS(iface);
326 return IBinding_QueryInterface(PROTOCOL(This), riid, ppv);
329 static ULONG WINAPI HttpInfo_AddRef(IWinInetHttpInfo *iface)
331 FtpProtocol *This = INETINFO_THIS(iface);
332 return IBinding_AddRef(PROTOCOL(This));
335 static ULONG WINAPI HttpInfo_Release(IWinInetHttpInfo *iface)
337 FtpProtocol *This = INETINFO_THIS(iface);
338 return IBinding_Release(PROTOCOL(This));
341 static HRESULT WINAPI HttpInfo_QueryOption(IWinInetHttpInfo *iface, DWORD dwOption,
342 void *pBuffer, DWORD *pcbBuffer)
344 FtpProtocol *This = INETINFO_THIS(iface);
345 FIXME("(%p)->(%x %p %p)\n", This, dwOption, pBuffer, pcbBuffer);
349 static HRESULT WINAPI HttpInfo_QueryInfo(IWinInetHttpInfo *iface, DWORD dwOption,
350 void *pBuffer, DWORD *pcbBuffer, DWORD *pdwFlags, DWORD *pdwReserved)
352 FtpProtocol *This = INETINFO_THIS(iface);
353 FIXME("(%p)->(%x %p %p %p %p)\n", This, dwOption, pBuffer, pcbBuffer, pdwFlags, pdwReserved);
359 static const IWinInetHttpInfoVtbl WinInetHttpInfoVtbl = {
360 HttpInfo_QueryInterface,
363 HttpInfo_QueryOption,
367 HRESULT FtpProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
371 TRACE("(%p %p)\n", pUnkOuter, ppobj);
375 ret = heap_alloc_zero(sizeof(FtpProtocol));
377 ret->base.vtbl = &AsyncProtocolVtbl;
378 ret->lpIInternetProtocolVtbl = &FtpProtocolVtbl;
379 ret->lpInternetPriorityVtbl = &FtpPriorityVtbl;
380 ret->lpWinInetHttpInfoVtbl = &WinInetHttpInfoVtbl;
383 *ppobj = PROTOCOL(ret);