usp10: Handle Ligature Substitution Subtable from GSUB.
[wine/testsucceed.git] / dlls / urlmon / ftp.c
blobf5e35064c9010a4cc5bc5c95590c0067066b077f
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 *lpIInternetProtocolVtbl;
28 const IInternetPriorityVtbl *lpInternetPriorityVtbl;
29 const IWinInetHttpInfoVtbl *lpWinInetHttpInfoVtbl;
31 LONG ref;
32 } FtpProtocol;
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, LPCWSTR url, DWORD request_flags,
40 HINTERNET internet_session, IInternetBindInfo *bind_info)
42 FtpProtocol *This = ASYNCPROTOCOL_THIS(prot);
44 This->base.request = InternetOpenUrlW(internet_session, url, NULL, 0,
45 request_flags|INTERNET_FLAG_EXISTING_CONNECT|INTERNET_FLAG_PASSIVE,
46 (DWORD_PTR)&This->base);
47 if (!This->base.request && GetLastError() != ERROR_IO_PENDING) {
48 WARN("InternetOpenUrl failed: %d\n", GetLastError());
49 return INET_E_RESOURCE_NOT_FOUND;
52 return S_OK;
55 static HRESULT FtpProtocol_start_downloading(Protocol *prot)
57 FtpProtocol *This = ASYNCPROTOCOL_THIS(prot);
58 DWORD size;
59 BOOL res;
61 res = FtpGetFileSize(This->base.request, &size);
62 if(res)
63 This->base.content_length = size;
64 else
65 WARN("FtpGetFileSize failed: %d\n", GetLastError());
67 return S_OK;
70 static void FtpProtocol_close_connection(Protocol *prot)
74 #undef ASYNCPROTOCOL_THIS
76 static const ProtocolVtbl AsyncProtocolVtbl = {
77 FtpProtocol_open_request,
78 FtpProtocol_start_downloading,
79 FtpProtocol_close_connection
82 #define PROTOCOL_THIS(iface) DEFINE_THIS(FtpProtocol, IInternetProtocol, iface)
84 static HRESULT WINAPI FtpProtocol_QueryInterface(IInternetProtocol *iface, REFIID riid, void **ppv)
86 FtpProtocol *This = PROTOCOL_THIS(iface);
88 *ppv = NULL;
89 if(IsEqualGUID(&IID_IUnknown, riid)) {
90 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
91 *ppv = PROTOCOL(This);
92 }else if(IsEqualGUID(&IID_IInternetProtocolRoot, riid)) {
93 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This, ppv);
94 *ppv = PROTOCOL(This);
95 }else if(IsEqualGUID(&IID_IInternetProtocol, riid)) {
96 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This, ppv);
97 *ppv = PROTOCOL(This);
98 }else if(IsEqualGUID(&IID_IInternetPriority, riid)) {
99 TRACE("(%p)->(IID_IInternetPriority %p)\n", This, ppv);
100 *ppv = PRIORITY(This);
101 }else if(IsEqualGUID(&IID_IWinInetInfo, riid)) {
102 TRACE("(%p)->(IID_IWinInetInfo %p)\n", This, ppv);
103 *ppv = INETHTTPINFO(This);
104 }else if(IsEqualGUID(&IID_IWinInetHttpInfo, riid)) {
105 TRACE("(%p)->(IID_IWinInetHttpInfo %p)\n", This, ppv);
106 *ppv = INETHTTPINFO(This);
109 if(*ppv) {
110 IInternetProtocol_AddRef(iface);
111 return S_OK;
114 WARN("not supported interface %s\n", debugstr_guid(riid));
115 return E_NOINTERFACE;
118 static ULONG WINAPI FtpProtocol_AddRef(IInternetProtocol *iface)
120 FtpProtocol *This = PROTOCOL_THIS(iface);
121 LONG ref = InterlockedIncrement(&This->ref);
122 TRACE("(%p) ref=%d\n", This, ref);
123 return ref;
126 static ULONG WINAPI FtpProtocol_Release(IInternetProtocol *iface)
128 FtpProtocol *This = PROTOCOL_THIS(iface);
129 LONG ref = InterlockedDecrement(&This->ref);
131 TRACE("(%p) ref=%d\n", This, ref);
133 if(!ref) {
134 protocol_close_connection(&This->base);
135 heap_free(This);
137 URLMON_UnlockModule();
140 return ref;
143 static HRESULT WINAPI FtpProtocol_Start(IInternetProtocol *iface, LPCWSTR szUrl,
144 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo,
145 DWORD grfPI, HANDLE_PTR dwReserved)
147 FtpProtocol *This = PROTOCOL_THIS(iface);
149 static const WCHAR ftpW[] = {'f','t','p',':'};
151 TRACE("(%p)->(%s %p %p %08x %lx)\n", This, debugstr_w(szUrl), pOIProtSink,
152 pOIBindInfo, grfPI, dwReserved);
154 if(strncmpW(szUrl, ftpW, sizeof(ftpW)/sizeof(WCHAR)))
155 return MK_E_SYNTAX;
157 return protocol_start(&This->base, PROTOCOL(This), szUrl, pOIProtSink, pOIBindInfo);
160 static HRESULT WINAPI FtpProtocol_Continue(IInternetProtocol *iface, PROTOCOLDATA *pProtocolData)
162 FtpProtocol *This = PROTOCOL_THIS(iface);
164 TRACE("(%p)->(%p)\n", This, pProtocolData);
166 return protocol_continue(&This->base, pProtocolData);
169 static HRESULT WINAPI FtpProtocol_Abort(IInternetProtocol *iface, HRESULT hrReason,
170 DWORD dwOptions)
172 FtpProtocol *This = PROTOCOL_THIS(iface);
173 FIXME("(%p)->(%08x %08x)\n", This, hrReason, dwOptions);
174 return E_NOTIMPL;
177 static HRESULT WINAPI FtpProtocol_Terminate(IInternetProtocol *iface, DWORD dwOptions)
179 FtpProtocol *This = PROTOCOL_THIS(iface);
181 TRACE("(%p)->(%08x)\n", This, dwOptions);
183 protocol_close_connection(&This->base);
184 return S_OK;
187 static HRESULT WINAPI FtpProtocol_Suspend(IInternetProtocol *iface)
189 FtpProtocol *This = PROTOCOL_THIS(iface);
190 FIXME("(%p)\n", This);
191 return E_NOTIMPL;
194 static HRESULT WINAPI FtpProtocol_Resume(IInternetProtocol *iface)
196 FtpProtocol *This = PROTOCOL_THIS(iface);
197 FIXME("(%p)\n", This);
198 return E_NOTIMPL;
201 static HRESULT WINAPI FtpProtocol_Read(IInternetProtocol *iface, void *pv,
202 ULONG cb, ULONG *pcbRead)
204 FtpProtocol *This = PROTOCOL_THIS(iface);
206 TRACE("(%p)->(%p %u %p)\n", This, pv, cb, pcbRead);
208 return protocol_read(&This->base, pv, cb, pcbRead);
211 static HRESULT WINAPI FtpProtocol_Seek(IInternetProtocol *iface, LARGE_INTEGER dlibMove,
212 DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
214 FtpProtocol *This = PROTOCOL_THIS(iface);
215 FIXME("(%p)->(%d %d %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition);
216 return E_NOTIMPL;
219 static HRESULT WINAPI FtpProtocol_LockRequest(IInternetProtocol *iface, DWORD dwOptions)
221 FtpProtocol *This = PROTOCOL_THIS(iface);
223 TRACE("(%p)->(%08x)\n", This, dwOptions);
225 return protocol_lock_request(&This->base);
228 static HRESULT WINAPI FtpProtocol_UnlockRequest(IInternetProtocol *iface)
230 FtpProtocol *This = PROTOCOL_THIS(iface);
232 TRACE("(%p)\n", This);
234 return protocol_unlock_request(&This->base);
237 #undef PROTOCOL_THIS
239 static const IInternetProtocolVtbl FtpProtocolVtbl = {
240 FtpProtocol_QueryInterface,
241 FtpProtocol_AddRef,
242 FtpProtocol_Release,
243 FtpProtocol_Start,
244 FtpProtocol_Continue,
245 FtpProtocol_Abort,
246 FtpProtocol_Terminate,
247 FtpProtocol_Suspend,
248 FtpProtocol_Resume,
249 FtpProtocol_Read,
250 FtpProtocol_Seek,
251 FtpProtocol_LockRequest,
252 FtpProtocol_UnlockRequest
255 #define PRIORITY_THIS(iface) DEFINE_THIS(FtpProtocol, InternetPriority, iface)
257 static HRESULT WINAPI FtpPriority_QueryInterface(IInternetPriority *iface, REFIID riid, void **ppv)
259 FtpProtocol *This = PRIORITY_THIS(iface);
260 return IInternetProtocol_QueryInterface(PROTOCOL(This), riid, ppv);
263 static ULONG WINAPI FtpPriority_AddRef(IInternetPriority *iface)
265 FtpProtocol *This = PRIORITY_THIS(iface);
266 return IInternetProtocol_AddRef(PROTOCOL(This));
269 static ULONG WINAPI FtpPriority_Release(IInternetPriority *iface)
271 FtpProtocol *This = PRIORITY_THIS(iface);
272 return IInternetProtocol_Release(PROTOCOL(This));
275 static HRESULT WINAPI FtpPriority_SetPriority(IInternetPriority *iface, LONG nPriority)
277 FtpProtocol *This = PRIORITY_THIS(iface);
279 TRACE("(%p)->(%d)\n", This, nPriority);
281 This->base.priority = nPriority;
282 return S_OK;
285 static HRESULT WINAPI FtpPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority)
287 FtpProtocol *This = PRIORITY_THIS(iface);
289 TRACE("(%p)->(%p)\n", This, pnPriority);
291 *pnPriority = This->base.priority;
292 return S_OK;
295 #undef PRIORITY_THIS
297 static const IInternetPriorityVtbl FtpPriorityVtbl = {
298 FtpPriority_QueryInterface,
299 FtpPriority_AddRef,
300 FtpPriority_Release,
301 FtpPriority_SetPriority,
302 FtpPriority_GetPriority
305 #define INETINFO_THIS(iface) DEFINE_THIS(FtpProtocol, WinInetHttpInfo, iface)
307 static HRESULT WINAPI HttpInfo_QueryInterface(IWinInetHttpInfo *iface, REFIID riid, void **ppv)
309 FtpProtocol *This = INETINFO_THIS(iface);
310 return IBinding_QueryInterface(PROTOCOL(This), riid, ppv);
313 static ULONG WINAPI HttpInfo_AddRef(IWinInetHttpInfo *iface)
315 FtpProtocol *This = INETINFO_THIS(iface);
316 return IBinding_AddRef(PROTOCOL(This));
319 static ULONG WINAPI HttpInfo_Release(IWinInetHttpInfo *iface)
321 FtpProtocol *This = INETINFO_THIS(iface);
322 return IBinding_Release(PROTOCOL(This));
325 static HRESULT WINAPI HttpInfo_QueryOption(IWinInetHttpInfo *iface, DWORD dwOption,
326 void *pBuffer, DWORD *pcbBuffer)
328 FtpProtocol *This = INETINFO_THIS(iface);
329 FIXME("(%p)->(%x %p %p)\n", This, dwOption, pBuffer, pcbBuffer);
330 return E_NOTIMPL;
333 static HRESULT WINAPI HttpInfo_QueryInfo(IWinInetHttpInfo *iface, DWORD dwOption,
334 void *pBuffer, DWORD *pcbBuffer, DWORD *pdwFlags, DWORD *pdwReserved)
336 FtpProtocol *This = INETINFO_THIS(iface);
337 FIXME("(%p)->(%x %p %p %p %p)\n", This, dwOption, pBuffer, pcbBuffer, pdwFlags, pdwReserved);
338 return E_NOTIMPL;
341 #undef INETINFO_THIS
343 static const IWinInetHttpInfoVtbl WinInetHttpInfoVtbl = {
344 HttpInfo_QueryInterface,
345 HttpInfo_AddRef,
346 HttpInfo_Release,
347 HttpInfo_QueryOption,
348 HttpInfo_QueryInfo
351 HRESULT FtpProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj)
353 FtpProtocol *ret;
355 TRACE("(%p %p)\n", pUnkOuter, ppobj);
357 URLMON_LockModule();
359 ret = heap_alloc_zero(sizeof(FtpProtocol));
361 ret->base.vtbl = &AsyncProtocolVtbl;
362 ret->lpIInternetProtocolVtbl = &FtpProtocolVtbl;
363 ret->lpInternetPriorityVtbl = &FtpPriorityVtbl;
364 ret->lpWinInetHttpInfoVtbl = &WinInetHttpInfoVtbl;
365 ret->ref = 1;
367 *ppobj = PROTOCOL(ret);
369 return S_OK;