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"
21 #define NO_SHLWAPI_REG
24 #include "wine/debug.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(urlmon
);
31 const IInternetProtocolExVtbl
*lpIInternetProtocolExVtbl
;
32 const IInternetPriorityVtbl
*lpInternetPriorityVtbl
;
33 const IWinInetHttpInfoVtbl
*lpWinInetHttpInfoVtbl
;
38 #define PROTOCOLEX(x) ((IInternetProtocolEx*)&(x)->lpIInternetProtocolExVtbl)
39 #define PRIORITY(x) ((IInternetPriority*) &(x)->lpInternetPriorityVtbl)
40 #define INETHTTPINFO(x) ((IWinInetHttpInfo*) &(x)->lpWinInetHttpInfoVtbl)
42 #define ASYNCPROTOCOL_THIS(iface) DEFINE_THIS2(FtpProtocol, base, iface)
44 static HRESULT
FtpProtocol_open_request(Protocol
*prot
, IUri
*uri
, DWORD request_flags
,
45 HINTERNET internet_session
, IInternetBindInfo
*bind_info
)
47 FtpProtocol
*This
= ASYNCPROTOCOL_THIS(prot
);
51 hres
= IUri_GetAbsoluteUri(uri
, &url
);
55 This
->base
.request
= InternetOpenUrlW(internet_session
, url
, NULL
, 0,
56 request_flags
|INTERNET_FLAG_EXISTING_CONNECT
|INTERNET_FLAG_PASSIVE
,
57 (DWORD_PTR
)&This
->base
);
59 if (!This
->base
.request
&& GetLastError() != ERROR_IO_PENDING
) {
60 WARN("InternetOpenUrl failed: %d\n", GetLastError());
61 return INET_E_RESOURCE_NOT_FOUND
;
67 static HRESULT
FtpProtocol_end_request(Protocol
*prot
)
72 static HRESULT
FtpProtocol_start_downloading(Protocol
*prot
)
74 FtpProtocol
*This
= ASYNCPROTOCOL_THIS(prot
);
78 res
= FtpGetFileSize(This
->base
.request
, &size
);
80 This
->base
.content_length
= size
;
82 WARN("FtpGetFileSize failed: %d\n", GetLastError());
87 static void FtpProtocol_close_connection(Protocol
*prot
)
91 #undef ASYNCPROTOCOL_THIS
93 static const ProtocolVtbl AsyncProtocolVtbl
= {
94 FtpProtocol_open_request
,
95 FtpProtocol_end_request
,
96 FtpProtocol_start_downloading
,
97 FtpProtocol_close_connection
100 #define PROTOCOL_THIS(iface) DEFINE_THIS(FtpProtocol, IInternetProtocolEx, iface)
102 static HRESULT WINAPI
FtpProtocol_QueryInterface(IInternetProtocolEx
*iface
, REFIID riid
, void **ppv
)
104 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
107 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
108 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
109 *ppv
= PROTOCOLEX(This
);
110 }else if(IsEqualGUID(&IID_IInternetProtocolRoot
, riid
)) {
111 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This
, ppv
);
112 *ppv
= PROTOCOLEX(This
);
113 }else if(IsEqualGUID(&IID_IInternetProtocol
, riid
)) {
114 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This
, ppv
);
115 *ppv
= PROTOCOLEX(This
);
116 }else if(IsEqualGUID(&IID_IInternetProtocolEx
, riid
)) {
117 TRACE("(%p)->(IID_IInternetProtocolEx %p)\n", This
, ppv
);
118 *ppv
= PROTOCOLEX(This
);
119 }else if(IsEqualGUID(&IID_IInternetPriority
, riid
)) {
120 TRACE("(%p)->(IID_IInternetPriority %p)\n", This
, ppv
);
121 *ppv
= PRIORITY(This
);
122 }else if(IsEqualGUID(&IID_IWinInetInfo
, riid
)) {
123 TRACE("(%p)->(IID_IWinInetInfo %p)\n", This
, ppv
);
124 *ppv
= INETHTTPINFO(This
);
125 }else if(IsEqualGUID(&IID_IWinInetHttpInfo
, riid
)) {
126 TRACE("(%p)->(IID_IWinInetHttpInfo %p)\n", This
, ppv
);
127 *ppv
= INETHTTPINFO(This
);
131 IInternetProtocol_AddRef(iface
);
135 WARN("not supported interface %s\n", debugstr_guid(riid
));
136 return E_NOINTERFACE
;
139 static ULONG WINAPI
FtpProtocol_AddRef(IInternetProtocolEx
*iface
)
141 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
142 LONG ref
= InterlockedIncrement(&This
->ref
);
143 TRACE("(%p) ref=%d\n", This
, ref
);
147 static ULONG WINAPI
FtpProtocol_Release(IInternetProtocolEx
*iface
)
149 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
150 LONG ref
= InterlockedDecrement(&This
->ref
);
152 TRACE("(%p) ref=%d\n", This
, ref
);
155 protocol_close_connection(&This
->base
);
158 URLMON_UnlockModule();
164 static HRESULT WINAPI
FtpProtocol_Start(IInternetProtocolEx
*iface
, LPCWSTR szUrl
,
165 IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
,
166 DWORD grfPI
, HANDLE_PTR dwReserved
)
168 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
172 TRACE("(%p)->(%s %p %p %08x %lx)\n", This
, debugstr_w(szUrl
), pOIProtSink
,
173 pOIBindInfo
, grfPI
, dwReserved
);
175 hres
= CreateUri(szUrl
, 0, 0, &uri
);
179 hres
= IInternetProtocolEx_StartEx(PROTOCOLEX(This
), uri
, pOIProtSink
, pOIBindInfo
,
180 grfPI
, (HANDLE
*)dwReserved
);
186 static HRESULT WINAPI
FtpProtocol_Continue(IInternetProtocolEx
*iface
, PROTOCOLDATA
*pProtocolData
)
188 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
190 TRACE("(%p)->(%p)\n", This
, pProtocolData
);
192 return protocol_continue(&This
->base
, pProtocolData
);
195 static HRESULT WINAPI
FtpProtocol_Abort(IInternetProtocolEx
*iface
, HRESULT hrReason
,
198 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
200 TRACE("(%p)->(%08x %08x)\n", This
, hrReason
, dwOptions
);
202 return protocol_abort(&This
->base
, hrReason
);
205 static HRESULT WINAPI
FtpProtocol_Terminate(IInternetProtocolEx
*iface
, DWORD dwOptions
)
207 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
209 TRACE("(%p)->(%08x)\n", This
, dwOptions
);
211 protocol_close_connection(&This
->base
);
215 static HRESULT WINAPI
FtpProtocol_Suspend(IInternetProtocolEx
*iface
)
217 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
218 FIXME("(%p)\n", This
);
222 static HRESULT WINAPI
FtpProtocol_Resume(IInternetProtocolEx
*iface
)
224 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
225 FIXME("(%p)\n", This
);
229 static HRESULT WINAPI
FtpProtocol_Read(IInternetProtocolEx
*iface
, void *pv
,
230 ULONG cb
, ULONG
*pcbRead
)
232 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
234 TRACE("(%p)->(%p %u %p)\n", This
, pv
, cb
, pcbRead
);
236 return protocol_read(&This
->base
, pv
, cb
, pcbRead
);
239 static HRESULT WINAPI
FtpProtocol_Seek(IInternetProtocolEx
*iface
, LARGE_INTEGER dlibMove
,
240 DWORD dwOrigin
, ULARGE_INTEGER
*plibNewPosition
)
242 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
243 FIXME("(%p)->(%d %d %p)\n", This
, dlibMove
.u
.LowPart
, dwOrigin
, plibNewPosition
);
247 static HRESULT WINAPI
FtpProtocol_LockRequest(IInternetProtocolEx
*iface
, DWORD dwOptions
)
249 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
251 TRACE("(%p)->(%08x)\n", This
, dwOptions
);
253 return protocol_lock_request(&This
->base
);
256 static HRESULT WINAPI
FtpProtocol_UnlockRequest(IInternetProtocolEx
*iface
)
258 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
260 TRACE("(%p)\n", This
);
262 return protocol_unlock_request(&This
->base
);
265 static HRESULT WINAPI
FtpProtocol_StartEx(IInternetProtocolEx
*iface
, IUri
*pUri
,
266 IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
,
267 DWORD grfPI
, HANDLE
*dwReserved
)
269 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
273 TRACE("(%p)->(%p %p %p %08x %p)\n", This
, pUri
, pOIProtSink
,
274 pOIBindInfo
, grfPI
, dwReserved
);
276 hres
= IUri_GetScheme(pUri
, &scheme
);
279 if(scheme
!= URL_SCHEME_FTP
)
282 return protocol_start(&This
->base
, (IInternetProtocol
*)PROTOCOLEX(This
), pUri
, pOIProtSink
, pOIBindInfo
);
286 static const IInternetProtocolExVtbl FtpProtocolVtbl
= {
287 FtpProtocol_QueryInterface
,
291 FtpProtocol_Continue
,
293 FtpProtocol_Terminate
,
298 FtpProtocol_LockRequest
,
299 FtpProtocol_UnlockRequest
,
303 #define PRIORITY_THIS(iface) DEFINE_THIS(FtpProtocol, InternetPriority, iface)
305 static HRESULT WINAPI
FtpPriority_QueryInterface(IInternetPriority
*iface
, REFIID riid
, void **ppv
)
307 FtpProtocol
*This
= PRIORITY_THIS(iface
);
308 return IInternetProtocolEx_QueryInterface(PROTOCOLEX(This
), riid
, ppv
);
311 static ULONG WINAPI
FtpPriority_AddRef(IInternetPriority
*iface
)
313 FtpProtocol
*This
= PRIORITY_THIS(iface
);
314 return IInternetProtocolEx_AddRef(PROTOCOLEX(This
));
317 static ULONG WINAPI
FtpPriority_Release(IInternetPriority
*iface
)
319 FtpProtocol
*This
= PRIORITY_THIS(iface
);
320 return IInternetProtocolEx_Release(PROTOCOLEX(This
));
323 static HRESULT WINAPI
FtpPriority_SetPriority(IInternetPriority
*iface
, LONG nPriority
)
325 FtpProtocol
*This
= PRIORITY_THIS(iface
);
327 TRACE("(%p)->(%d)\n", This
, nPriority
);
329 This
->base
.priority
= nPriority
;
333 static HRESULT WINAPI
FtpPriority_GetPriority(IInternetPriority
*iface
, LONG
*pnPriority
)
335 FtpProtocol
*This
= PRIORITY_THIS(iface
);
337 TRACE("(%p)->(%p)\n", This
, pnPriority
);
339 *pnPriority
= This
->base
.priority
;
345 static const IInternetPriorityVtbl FtpPriorityVtbl
= {
346 FtpPriority_QueryInterface
,
349 FtpPriority_SetPriority
,
350 FtpPriority_GetPriority
353 #define INETINFO_THIS(iface) DEFINE_THIS(FtpProtocol, WinInetHttpInfo, iface)
355 static HRESULT WINAPI
HttpInfo_QueryInterface(IWinInetHttpInfo
*iface
, REFIID riid
, void **ppv
)
357 FtpProtocol
*This
= INETINFO_THIS(iface
);
358 return IInternetProtocolEx_QueryInterface(PROTOCOLEX(This
), riid
, ppv
);
361 static ULONG WINAPI
HttpInfo_AddRef(IWinInetHttpInfo
*iface
)
363 FtpProtocol
*This
= INETINFO_THIS(iface
);
364 return IInternetProtocolEx_AddRef(PROTOCOLEX(This
));
367 static ULONG WINAPI
HttpInfo_Release(IWinInetHttpInfo
*iface
)
369 FtpProtocol
*This
= INETINFO_THIS(iface
);
370 return IInternetProtocolEx_Release(PROTOCOLEX(This
));
373 static HRESULT WINAPI
HttpInfo_QueryOption(IWinInetHttpInfo
*iface
, DWORD dwOption
,
374 void *pBuffer
, DWORD
*pcbBuffer
)
376 FtpProtocol
*This
= INETINFO_THIS(iface
);
377 FIXME("(%p)->(%x %p %p)\n", This
, dwOption
, pBuffer
, pcbBuffer
);
381 static HRESULT WINAPI
HttpInfo_QueryInfo(IWinInetHttpInfo
*iface
, DWORD dwOption
,
382 void *pBuffer
, DWORD
*pcbBuffer
, DWORD
*pdwFlags
, DWORD
*pdwReserved
)
384 FtpProtocol
*This
= INETINFO_THIS(iface
);
385 FIXME("(%p)->(%x %p %p %p %p)\n", This
, dwOption
, pBuffer
, pcbBuffer
, pdwFlags
, pdwReserved
);
391 static const IWinInetHttpInfoVtbl WinInetHttpInfoVtbl
= {
392 HttpInfo_QueryInterface
,
395 HttpInfo_QueryOption
,
399 HRESULT
FtpProtocol_Construct(IUnknown
*pUnkOuter
, LPVOID
*ppobj
)
403 TRACE("(%p %p)\n", pUnkOuter
, ppobj
);
407 ret
= heap_alloc_zero(sizeof(FtpProtocol
));
409 ret
->base
.vtbl
= &AsyncProtocolVtbl
;
410 ret
->lpIInternetProtocolExVtbl
= &FtpProtocolVtbl
;
411 ret
->lpInternetPriorityVtbl
= &FtpPriorityVtbl
;
412 ret
->lpWinInetHttpInfoVtbl
= &WinInetHttpInfoVtbl
;
415 *ppobj
= PROTOCOLEX(ret
);