msi/tests: Avoid size_t in traces.
[wine/hacks.git] / dlls / urlmon / ftp.c
blobdbdd7a7fd37be89638d6c150363a1af25ceb0901
1 /*
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);
24 typedef struct {
25 Protocol base;
27 const IInternetProtocolVtbl *lpInternetProtocolVtbl;
28 const IInternetPriorityVtbl *lpInternetPriorityVtbl;
30 LONG ref;
31 } FtpProtocol;
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;
51 return S_OK;
54 static HRESULT FtpProtocol_start_downloading(Protocol *prot)
56 FtpProtocol *This = ASYNCPROTOCOL_THIS(prot);
57 DWORD size;
58 BOOL res;
60 res = FtpGetFileSize(This->base.request, &size);
61 if(res)
62 This->base.content_length = size;
63 else
64 WARN("FtpGetFileSize failed: %d\n", GetLastError());
66 return S_OK;
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);
87 *ppv = NULL;
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);
102 if(*ppv) {
103 IInternetProtocol_AddRef(iface);
104 return S_OK;
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);
116 return 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);
126 if(!ref) {
127 protocol_close_connection(&This->base);
128 heap_free(This);
130 URLMON_UnlockModule();
133 return ref;
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)))
148 return MK_E_SYNTAX;
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,
163 DWORD dwOptions)
165 FtpProtocol *This = PROTOCOL_THIS(iface);
166 FIXME("(%p)->(%08x %08x)\n", This, hrReason, dwOptions);
167 return E_NOTIMPL;
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);
177 return S_OK;
180 static HRESULT WINAPI FtpProtocol_Suspend(IInternetProtocol *iface)
182 FtpProtocol *This = PROTOCOL_THIS(iface);
183 FIXME("(%p)\n", This);
184 return E_NOTIMPL;
187 static HRESULT WINAPI FtpProtocol_Resume(IInternetProtocol *iface)
189 FtpProtocol *This = PROTOCOL_THIS(iface);
190 FIXME("(%p)\n", This);
191 return E_NOTIMPL;
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);
209 return E_NOTIMPL;
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);
230 #undef PROTOCOL_THIS
232 static const IInternetProtocolVtbl FtpProtocolVtbl = {
233 FtpProtocol_QueryInterface,
234 FtpProtocol_AddRef,
235 FtpProtocol_Release,
236 FtpProtocol_Start,
237 FtpProtocol_Continue,
238 FtpProtocol_Abort,
239 FtpProtocol_Terminate,
240 FtpProtocol_Suspend,
241 FtpProtocol_Resume,
242 FtpProtocol_Read,
243 FtpProtocol_Seek,
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;
275 return S_OK;
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;
285 return S_OK;
288 #undef PRIORITY_THIS
290 static const IInternetPriorityVtbl FtpPriorityVtbl = {
291 FtpPriority_QueryInterface,
292 FtpPriority_AddRef,
293 FtpPriority_Release,
294 FtpPriority_SetPriority,
295 FtpPriority_GetPriority
298 HRESULT FtpProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
300 FtpProtocol *ret;
302 TRACE("(%p %p)\n", pUnkOuter, ppobj);
304 URLMON_LockModule();
306 ret = heap_alloc_zero(sizeof(FtpProtocol));
308 ret->base.vtbl = &AsyncProtocolVtbl;
309 ret->lpInternetProtocolVtbl = &FtpProtocolVtbl;
310 ret->lpInternetPriorityVtbl = &FtpPriorityVtbl;
311 ret->ref = 1;
313 *ppobj = PROTOCOL(ret);
315 return S_OK;