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
*lpInternetProtocolVtbl
;
28 const IInternetPriorityVtbl
*lpInternetPriorityVtbl
;
29 const IWinInetHttpInfoVtbl
*lpWinInetHttpInfoVtbl
;
34 #define PROTOCOL(x) ((IInternetProtocol*) &(x)->lpInternetProtocolVtbl)
35 #define PRIORITY(x) ((IInternetPriority*) &(x)->lpInternetPriorityVtbl)
36 #define INETHTTPINFO(x) ((IWinInetHttpInfo*) &(x)->lpWinInetHttpInfoVtbl)
38 #define ASYNCPROTOCOL_THIS(iface) DEFINE_THIS2(FtpProtocol, base, iface)
40 static HRESULT
FtpProtocol_open_request(Protocol
*prot
, LPCWSTR url
, DWORD request_flags
,
41 IInternetBindInfo
*bind_info
)
43 FtpProtocol
*This
= ASYNCPROTOCOL_THIS(prot
);
45 This
->base
.request
= InternetOpenUrlW(This
->base
.internet
, url
, NULL
, 0,
46 request_flags
|INTERNET_FLAG_EXISTING_CONNECT
|INTERNET_FLAG_PASSIVE
,
47 (DWORD_PTR
)&This
->base
);
48 if (!This
->base
.request
&& GetLastError() != ERROR_IO_PENDING
) {
49 WARN("InternetOpenUrl failed: %d\n", GetLastError());
50 return INET_E_RESOURCE_NOT_FOUND
;
56 static HRESULT
FtpProtocol_start_downloading(Protocol
*prot
)
58 FtpProtocol
*This
= ASYNCPROTOCOL_THIS(prot
);
62 res
= FtpGetFileSize(This
->base
.request
, &size
);
64 This
->base
.content_length
= size
;
66 WARN("FtpGetFileSize failed: %d\n", GetLastError());
71 static void FtpProtocol_close_connection(Protocol
*prot
)
75 #undef ASYNCPROTOCOL_THIS
77 static const ProtocolVtbl AsyncProtocolVtbl
= {
78 FtpProtocol_open_request
,
79 FtpProtocol_start_downloading
,
80 FtpProtocol_close_connection
83 #define PROTOCOL_THIS(iface) DEFINE_THIS(FtpProtocol, InternetProtocol, iface)
85 static HRESULT WINAPI
FtpProtocol_QueryInterface(IInternetProtocol
*iface
, REFIID riid
, void **ppv
)
87 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
90 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
91 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
92 *ppv
= PROTOCOL(This
);
93 }else if(IsEqualGUID(&IID_IInternetProtocolRoot
, riid
)) {
94 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This
, ppv
);
95 *ppv
= PROTOCOL(This
);
96 }else if(IsEqualGUID(&IID_IInternetProtocol
, riid
)) {
97 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This
, ppv
);
98 *ppv
= PROTOCOL(This
);
99 }else if(IsEqualGUID(&IID_IInternetPriority
, riid
)) {
100 TRACE("(%p)->(IID_IInternetPriority %p)\n", This
, ppv
);
101 *ppv
= PRIORITY(This
);
102 }else if(IsEqualGUID(&IID_IWinInetInfo
, riid
)) {
103 TRACE("(%p)->(IID_IWinInetInfo %p)\n", This
, ppv
);
104 *ppv
= INETHTTPINFO(This
);
105 }else if(IsEqualGUID(&IID_IWinInetHttpInfo
, riid
)) {
106 TRACE("(%p)->(IID_IWinInetHttpInfo %p)\n", This
, ppv
);
107 *ppv
= INETHTTPINFO(This
);
111 IInternetProtocol_AddRef(iface
);
115 WARN("not supported interface %s\n", debugstr_guid(riid
));
116 return E_NOINTERFACE
;
119 static ULONG WINAPI
FtpProtocol_AddRef(IInternetProtocol
*iface
)
121 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
122 LONG ref
= InterlockedIncrement(&This
->ref
);
123 TRACE("(%p) ref=%d\n", This
, ref
);
127 static ULONG WINAPI
FtpProtocol_Release(IInternetProtocol
*iface
)
129 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
130 LONG ref
= InterlockedDecrement(&This
->ref
);
132 TRACE("(%p) ref=%d\n", This
, ref
);
135 protocol_close_connection(&This
->base
);
138 URLMON_UnlockModule();
144 static HRESULT WINAPI
FtpProtocol_Start(IInternetProtocol
*iface
, LPCWSTR szUrl
,
145 IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
,
146 DWORD grfPI
, HANDLE_PTR dwReserved
)
148 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
150 static const WCHAR ftpW
[] = {'f','t','p',':'};
152 TRACE("(%p)->(%s %p %p %08x %lx)\n", This
, debugstr_w(szUrl
), pOIProtSink
,
153 pOIBindInfo
, grfPI
, dwReserved
);
155 if(strncmpW(szUrl
, ftpW
, sizeof(ftpW
)/sizeof(WCHAR
)))
158 return protocol_start(&This
->base
, PROTOCOL(This
), szUrl
, pOIProtSink
, pOIBindInfo
);
161 static HRESULT WINAPI
FtpProtocol_Continue(IInternetProtocol
*iface
, PROTOCOLDATA
*pProtocolData
)
163 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
165 TRACE("(%p)->(%p)\n", This
, pProtocolData
);
167 return protocol_continue(&This
->base
, pProtocolData
);
170 static HRESULT WINAPI
FtpProtocol_Abort(IInternetProtocol
*iface
, HRESULT hrReason
,
173 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
174 FIXME("(%p)->(%08x %08x)\n", This
, hrReason
, dwOptions
);
178 static HRESULT WINAPI
FtpProtocol_Terminate(IInternetProtocol
*iface
, DWORD dwOptions
)
180 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
182 TRACE("(%p)->(%08x)\n", This
, dwOptions
);
184 protocol_close_connection(&This
->base
);
188 static HRESULT WINAPI
FtpProtocol_Suspend(IInternetProtocol
*iface
)
190 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
191 FIXME("(%p)\n", This
);
195 static HRESULT WINAPI
FtpProtocol_Resume(IInternetProtocol
*iface
)
197 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
198 FIXME("(%p)\n", This
);
202 static HRESULT WINAPI
FtpProtocol_Read(IInternetProtocol
*iface
, void *pv
,
203 ULONG cb
, ULONG
*pcbRead
)
205 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
207 TRACE("(%p)->(%p %u %p)\n", This
, pv
, cb
, pcbRead
);
209 return protocol_read(&This
->base
, pv
, cb
, pcbRead
);
212 static HRESULT WINAPI
FtpProtocol_Seek(IInternetProtocol
*iface
, LARGE_INTEGER dlibMove
,
213 DWORD dwOrigin
, ULARGE_INTEGER
*plibNewPosition
)
215 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
216 FIXME("(%p)->(%d %d %p)\n", This
, dlibMove
.u
.LowPart
, dwOrigin
, plibNewPosition
);
220 static HRESULT WINAPI
FtpProtocol_LockRequest(IInternetProtocol
*iface
, DWORD dwOptions
)
222 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
224 TRACE("(%p)->(%08x)\n", This
, dwOptions
);
226 return protocol_lock_request(&This
->base
);
229 static HRESULT WINAPI
FtpProtocol_UnlockRequest(IInternetProtocol
*iface
)
231 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
233 TRACE("(%p)\n", This
);
235 return protocol_unlock_request(&This
->base
);
240 static const IInternetProtocolVtbl FtpProtocolVtbl
= {
241 FtpProtocol_QueryInterface
,
245 FtpProtocol_Continue
,
247 FtpProtocol_Terminate
,
252 FtpProtocol_LockRequest
,
253 FtpProtocol_UnlockRequest
256 #define PRIORITY_THIS(iface) DEFINE_THIS(FtpProtocol, InternetPriority, iface)
258 static HRESULT WINAPI
FtpPriority_QueryInterface(IInternetPriority
*iface
, REFIID riid
, void **ppv
)
260 FtpProtocol
*This
= PRIORITY_THIS(iface
);
261 return IInternetProtocol_QueryInterface(PROTOCOL(This
), riid
, ppv
);
264 static ULONG WINAPI
FtpPriority_AddRef(IInternetPriority
*iface
)
266 FtpProtocol
*This
= PRIORITY_THIS(iface
);
267 return IInternetProtocol_AddRef(PROTOCOL(This
));
270 static ULONG WINAPI
FtpPriority_Release(IInternetPriority
*iface
)
272 FtpProtocol
*This
= PRIORITY_THIS(iface
);
273 return IInternetProtocol_Release(PROTOCOL(This
));
276 static HRESULT WINAPI
FtpPriority_SetPriority(IInternetPriority
*iface
, LONG nPriority
)
278 FtpProtocol
*This
= PRIORITY_THIS(iface
);
280 TRACE("(%p)->(%d)\n", This
, nPriority
);
282 This
->base
.priority
= nPriority
;
286 static HRESULT WINAPI
FtpPriority_GetPriority(IInternetPriority
*iface
, LONG
*pnPriority
)
288 FtpProtocol
*This
= PRIORITY_THIS(iface
);
290 TRACE("(%p)->(%p)\n", This
, pnPriority
);
292 *pnPriority
= This
->base
.priority
;
298 static const IInternetPriorityVtbl FtpPriorityVtbl
= {
299 FtpPriority_QueryInterface
,
302 FtpPriority_SetPriority
,
303 FtpPriority_GetPriority
306 #define INETINFO_THIS(iface) DEFINE_THIS(FtpProtocol, WinInetHttpInfo, iface)
308 static HRESULT WINAPI
HttpInfo_QueryInterface(IWinInetHttpInfo
*iface
, REFIID riid
, void **ppv
)
310 FtpProtocol
*This
= INETINFO_THIS(iface
);
311 return IBinding_QueryInterface(PROTOCOL(This
), riid
, ppv
);
314 static ULONG WINAPI
HttpInfo_AddRef(IWinInetHttpInfo
*iface
)
316 FtpProtocol
*This
= INETINFO_THIS(iface
);
317 return IBinding_AddRef(PROTOCOL(This
));
320 static ULONG WINAPI
HttpInfo_Release(IWinInetHttpInfo
*iface
)
322 FtpProtocol
*This
= INETINFO_THIS(iface
);
323 return IBinding_Release(PROTOCOL(This
));
326 static HRESULT WINAPI
HttpInfo_QueryOption(IWinInetHttpInfo
*iface
, DWORD dwOption
,
327 void *pBuffer
, DWORD
*pcbBuffer
)
329 FtpProtocol
*This
= INETINFO_THIS(iface
);
330 FIXME("(%p)->(%x %p %p)\n", This
, dwOption
, pBuffer
, pcbBuffer
);
334 static HRESULT WINAPI
HttpInfo_QueryInfo(IWinInetHttpInfo
*iface
, DWORD dwOption
,
335 void *pBuffer
, DWORD
*pcbBuffer
, DWORD
*pdwFlags
, DWORD
*pdwReserved
)
337 FtpProtocol
*This
= INETINFO_THIS(iface
);
338 FIXME("(%p)->(%x %p %p %p %p)\n", This
, dwOption
, pBuffer
, pcbBuffer
, pdwFlags
, pdwReserved
);
344 static const IWinInetHttpInfoVtbl WinInetHttpInfoVtbl
= {
345 HttpInfo_QueryInterface
,
348 HttpInfo_QueryOption
,
352 HRESULT
FtpProtocol_Construct(IUnknown
*pUnkOuter
, LPVOID
*ppobj
)
356 TRACE("(%p %p)\n", pUnkOuter
, ppobj
);
360 ret
= heap_alloc_zero(sizeof(FtpProtocol
));
362 ret
->base
.vtbl
= &AsyncProtocolVtbl
;
363 ret
->lpInternetProtocolVtbl
= &FtpProtocolVtbl
;
364 ret
->lpInternetPriorityVtbl
= &FtpPriorityVtbl
;
365 ret
->lpWinInetHttpInfoVtbl
= &WinInetHttpInfoVtbl
;
368 *ppobj
= PROTOCOL(ret
);