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
;
33 #define PROTOCOL(x) ((IInternetProtocol*) &(x)->lpInternetProtocolVtbl)
34 #define PRIORITY(x) ((IInternetPriority*) &(x)->lpInternetPriorityVtbl)
36 #define ASYNCPROTOCOL_THIS(iface) DEFINE_THIS2(FtpProtocol, base, iface)
38 static HRESULT
FtpProtocol_open_request(Protocol
*prot
, LPCWSTR url
, DWORD request_flags
,
39 IInternetBindInfo
*bind_info
)
41 FtpProtocol
*This
= ASYNCPROTOCOL_THIS(prot
);
43 This
->base
.request
= InternetOpenUrlW(This
->base
.internet
, url
, NULL
, 0,
44 request_flags
|INTERNET_FLAG_EXISTING_CONNECT
|INTERNET_FLAG_PASSIVE
,
45 (DWORD_PTR
)&This
->base
);
46 if (!This
->base
.request
&& GetLastError() != ERROR_IO_PENDING
) {
47 WARN("InternetOpenUrl failed: %d\n", GetLastError());
48 return INET_E_RESOURCE_NOT_FOUND
;
54 static HRESULT
FtpProtocol_start_downloading(Protocol
*prot
)
56 FtpProtocol
*This
= ASYNCPROTOCOL_THIS(prot
);
60 res
= FtpGetFileSize(This
->base
.request
, &size
);
62 This
->base
.content_length
= size
;
64 WARN("FtpGetFileSize failed: %d\n", GetLastError());
69 static void FtpProtocol_close_connection(Protocol
*prot
)
73 #undef ASYNCPROTOCOL_THIS
75 static const ProtocolVtbl AsyncProtocolVtbl
= {
76 FtpProtocol_open_request
,
77 FtpProtocol_start_downloading
,
78 FtpProtocol_close_connection
81 #define PROTOCOL_THIS(iface) DEFINE_THIS(FtpProtocol, InternetProtocol, iface)
83 static HRESULT WINAPI
FtpProtocol_QueryInterface(IInternetProtocol
*iface
, REFIID riid
, void **ppv
)
85 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
88 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
89 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
90 *ppv
= PROTOCOL(This
);
91 }else if(IsEqualGUID(&IID_IInternetProtocolRoot
, riid
)) {
92 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This
, ppv
);
93 *ppv
= PROTOCOL(This
);
94 }else if(IsEqualGUID(&IID_IInternetProtocol
, riid
)) {
95 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This
, ppv
);
96 *ppv
= PROTOCOL(This
);
97 }else if(IsEqualGUID(&IID_IInternetPriority
, riid
)) {
98 TRACE("(%p)->(IID_IInternetPriority %p)\n", This
, ppv
);
99 *ppv
= PRIORITY(This
);
103 IInternetProtocol_AddRef(iface
);
107 WARN("not supported interface %s\n", debugstr_guid(riid
));
108 return E_NOINTERFACE
;
111 static ULONG WINAPI
FtpProtocol_AddRef(IInternetProtocol
*iface
)
113 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
114 LONG ref
= InterlockedIncrement(&This
->ref
);
115 TRACE("(%p) ref=%d\n", This
, ref
);
119 static ULONG WINAPI
FtpProtocol_Release(IInternetProtocol
*iface
)
121 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
122 LONG ref
= InterlockedDecrement(&This
->ref
);
124 TRACE("(%p) ref=%d\n", This
, ref
);
127 protocol_close_connection(&This
->base
);
130 URLMON_UnlockModule();
136 static HRESULT WINAPI
FtpProtocol_Start(IInternetProtocol
*iface
, LPCWSTR szUrl
,
137 IInternetProtocolSink
*pOIProtSink
, IInternetBindInfo
*pOIBindInfo
,
138 DWORD grfPI
, DWORD dwReserved
)
140 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
142 static const WCHAR ftpW
[] = {'f','t','p',':'};
144 TRACE("(%p)->(%s %p %p %08x %d)\n", This
, debugstr_w(szUrl
), pOIProtSink
,
145 pOIBindInfo
, grfPI
, dwReserved
);
147 if(strncmpW(szUrl
, ftpW
, sizeof(ftpW
)/sizeof(WCHAR
)))
150 return protocol_start(&This
->base
, PROTOCOL(This
), szUrl
, pOIProtSink
, pOIBindInfo
);
153 static HRESULT WINAPI
FtpProtocol_Continue(IInternetProtocol
*iface
, PROTOCOLDATA
*pProtocolData
)
155 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
157 TRACE("(%p)->(%p)\n", This
, pProtocolData
);
159 return protocol_continue(&This
->base
, pProtocolData
);
162 static HRESULT WINAPI
FtpProtocol_Abort(IInternetProtocol
*iface
, HRESULT hrReason
,
165 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
166 FIXME("(%p)->(%08x %08x)\n", This
, hrReason
, dwOptions
);
170 static HRESULT WINAPI
FtpProtocol_Terminate(IInternetProtocol
*iface
, DWORD dwOptions
)
172 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
174 TRACE("(%p)->(%08x)\n", This
, dwOptions
);
176 protocol_close_connection(&This
->base
);
180 static HRESULT WINAPI
FtpProtocol_Suspend(IInternetProtocol
*iface
)
182 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
183 FIXME("(%p)\n", This
);
187 static HRESULT WINAPI
FtpProtocol_Resume(IInternetProtocol
*iface
)
189 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
190 FIXME("(%p)\n", This
);
194 static HRESULT WINAPI
FtpProtocol_Read(IInternetProtocol
*iface
, void *pv
,
195 ULONG cb
, ULONG
*pcbRead
)
197 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
199 TRACE("(%p)->(%p %u %p)\n", This
, pv
, cb
, pcbRead
);
201 return protocol_read(&This
->base
, pv
, cb
, pcbRead
);
204 static HRESULT WINAPI
FtpProtocol_Seek(IInternetProtocol
*iface
, LARGE_INTEGER dlibMove
,
205 DWORD dwOrigin
, ULARGE_INTEGER
*plibNewPosition
)
207 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
208 FIXME("(%p)->(%d %d %p)\n", This
, dlibMove
.u
.LowPart
, dwOrigin
, plibNewPosition
);
212 static HRESULT WINAPI
FtpProtocol_LockRequest(IInternetProtocol
*iface
, DWORD dwOptions
)
214 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
216 TRACE("(%p)->(%08x)\n", This
, dwOptions
);
218 return protocol_lock_request(&This
->base
);
221 static HRESULT WINAPI
FtpProtocol_UnlockRequest(IInternetProtocol
*iface
)
223 FtpProtocol
*This
= PROTOCOL_THIS(iface
);
225 TRACE("(%p)\n", This
);
227 return protocol_unlock_request(&This
->base
);
232 static const IInternetProtocolVtbl FtpProtocolVtbl
= {
233 FtpProtocol_QueryInterface
,
237 FtpProtocol_Continue
,
239 FtpProtocol_Terminate
,
244 FtpProtocol_LockRequest
,
245 FtpProtocol_UnlockRequest
248 #define PRIORITY_THIS(iface) DEFINE_THIS(FtpProtocol, InternetPriority, iface)
250 static HRESULT WINAPI
FtpPriority_QueryInterface(IInternetPriority
*iface
, REFIID riid
, void **ppv
)
252 FtpProtocol
*This
= PRIORITY_THIS(iface
);
253 return IInternetProtocol_QueryInterface(PROTOCOL(This
), riid
, ppv
);
256 static ULONG WINAPI
FtpPriority_AddRef(IInternetPriority
*iface
)
258 FtpProtocol
*This
= PRIORITY_THIS(iface
);
259 return IInternetProtocol_AddRef(PROTOCOL(This
));
262 static ULONG WINAPI
FtpPriority_Release(IInternetPriority
*iface
)
264 FtpProtocol
*This
= PRIORITY_THIS(iface
);
265 return IInternetProtocol_Release(PROTOCOL(This
));
268 static HRESULT WINAPI
FtpPriority_SetPriority(IInternetPriority
*iface
, LONG nPriority
)
270 FtpProtocol
*This
= PRIORITY_THIS(iface
);
272 TRACE("(%p)->(%d)\n", This
, nPriority
);
274 This
->base
.priority
= nPriority
;
278 static HRESULT WINAPI
FtpPriority_GetPriority(IInternetPriority
*iface
, LONG
*pnPriority
)
280 FtpProtocol
*This
= PRIORITY_THIS(iface
);
282 TRACE("(%p)->(%p)\n", This
, pnPriority
);
284 *pnPriority
= This
->base
.priority
;
290 static const IInternetPriorityVtbl FtpPriorityVtbl
= {
291 FtpPriority_QueryInterface
,
294 FtpPriority_SetPriority
,
295 FtpPriority_GetPriority
298 HRESULT
FtpProtocol_Construct(IUnknown
*pUnkOuter
, LPVOID
*ppobj
)
302 TRACE("(%p %p)\n", pUnkOuter
, ppobj
);
306 ret
= heap_alloc_zero(sizeof(FtpProtocol
));
308 ret
->base
.vtbl
= &AsyncProtocolVtbl
;
309 ret
->lpInternetProtocolVtbl
= &FtpProtocolVtbl
;
310 ret
->lpInternetPriorityVtbl
= &FtpPriorityVtbl
;
313 *ppobj
= PROTOCOL(ret
);