Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenftp.c
Go to the documentation of this file.
00001 /* 00002 * Copyright 2005-2009 Jacek Caban for CodeWeavers 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2.1 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with this library; if not, write to the Free Software 00016 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 00017 */ 00018 00019 #include "urlmon_main.h" 00020 00021 #define NO_SHLWAPI_REG 00022 #include "shlwapi.h" 00023 00024 #include "wine/debug.h" 00025 00026 WINE_DEFAULT_DEBUG_CHANNEL(urlmon); 00027 00028 typedef struct { 00029 Protocol base; 00030 00031 IInternetProtocolEx IInternetProtocolEx_iface; 00032 IInternetPriority IInternetPriority_iface; 00033 IWinInetHttpInfo IWinInetHttpInfo_iface; 00034 00035 LONG ref; 00036 } FtpProtocol; 00037 00038 static inline FtpProtocol *impl_from_IInternetProtocolEx(IInternetProtocolEx *iface) 00039 { 00040 return CONTAINING_RECORD(iface, FtpProtocol, IInternetProtocolEx_iface); 00041 } 00042 00043 static inline FtpProtocol *impl_from_IInternetPriority(IInternetPriority *iface) 00044 { 00045 return CONTAINING_RECORD(iface, FtpProtocol, IInternetPriority_iface); 00046 } 00047 static inline FtpProtocol *impl_from_IWinInetHttpInfo(IWinInetHttpInfo *iface) 00048 00049 { 00050 return CONTAINING_RECORD(iface, FtpProtocol, IWinInetHttpInfo_iface); 00051 } 00052 00053 static inline FtpProtocol *impl_from_Protocol(Protocol *prot) 00054 { 00055 return CONTAINING_RECORD(prot, FtpProtocol, base); 00056 } 00057 00058 static HRESULT FtpProtocol_open_request(Protocol *prot, IUri *uri, DWORD request_flags, 00059 HINTERNET internet_session, IInternetBindInfo *bind_info) 00060 { 00061 FtpProtocol *This = impl_from_Protocol(prot); 00062 BSTR url; 00063 HRESULT hres; 00064 00065 hres = IUri_GetAbsoluteUri(uri, &url); 00066 if(FAILED(hres)) 00067 return hres; 00068 00069 This->base.request = InternetOpenUrlW(internet_session, url, NULL, 0, 00070 request_flags|INTERNET_FLAG_EXISTING_CONNECT|INTERNET_FLAG_PASSIVE, 00071 (DWORD_PTR)&This->base); 00072 SysFreeString(url); 00073 if (!This->base.request && GetLastError() != ERROR_IO_PENDING) { 00074 WARN("InternetOpenUrl failed: %d\n", GetLastError()); 00075 return INET_E_RESOURCE_NOT_FOUND; 00076 } 00077 00078 return S_OK; 00079 } 00080 00081 static HRESULT FtpProtocol_end_request(Protocol *prot) 00082 { 00083 return E_NOTIMPL; 00084 } 00085 00086 static HRESULT FtpProtocol_start_downloading(Protocol *prot) 00087 { 00088 FtpProtocol *This = impl_from_Protocol(prot); 00089 DWORD size; 00090 BOOL res; 00091 00092 res = FtpGetFileSize(This->base.request, &size); 00093 if(res) 00094 This->base.content_length = size; 00095 else 00096 WARN("FtpGetFileSize failed: %d\n", GetLastError()); 00097 00098 return S_OK; 00099 } 00100 00101 static void FtpProtocol_close_connection(Protocol *prot) 00102 { 00103 } 00104 00105 static void FtpProtocol_on_error(Protocol *prot, DWORD error) 00106 { 00107 FIXME("(%p) %d - stub\n", prot, error); 00108 } 00109 00110 static const ProtocolVtbl AsyncProtocolVtbl = { 00111 FtpProtocol_open_request, 00112 FtpProtocol_end_request, 00113 FtpProtocol_start_downloading, 00114 FtpProtocol_close_connection, 00115 FtpProtocol_on_error 00116 }; 00117 00118 static HRESULT WINAPI FtpProtocol_QueryInterface(IInternetProtocolEx *iface, REFIID riid, void **ppv) 00119 { 00120 FtpProtocol *This = impl_from_IInternetProtocolEx(iface); 00121 00122 *ppv = NULL; 00123 if(IsEqualGUID(&IID_IUnknown, riid)) { 00124 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv); 00125 *ppv = &This->IInternetProtocolEx_iface; 00126 }else if(IsEqualGUID(&IID_IInternetProtocolRoot, riid)) { 00127 TRACE("(%p)->(IID_IInternetProtocolRoot %p)\n", This, ppv); 00128 *ppv = &This->IInternetProtocolEx_iface; 00129 }else if(IsEqualGUID(&IID_IInternetProtocol, riid)) { 00130 TRACE("(%p)->(IID_IInternetProtocol %p)\n", This, ppv); 00131 *ppv = &This->IInternetProtocolEx_iface; 00132 }else if(IsEqualGUID(&IID_IInternetProtocolEx, riid)) { 00133 TRACE("(%p)->(IID_IInternetProtocolEx %p)\n", This, ppv); 00134 *ppv = &This->IInternetProtocolEx_iface; 00135 }else if(IsEqualGUID(&IID_IInternetPriority, riid)) { 00136 TRACE("(%p)->(IID_IInternetPriority %p)\n", This, ppv); 00137 *ppv = &This->IInternetPriority_iface; 00138 }else if(IsEqualGUID(&IID_IWinInetInfo, riid)) { 00139 TRACE("(%p)->(IID_IWinInetInfo %p)\n", This, ppv); 00140 *ppv = &This->IWinInetHttpInfo_iface; 00141 }else if(IsEqualGUID(&IID_IWinInetHttpInfo, riid)) { 00142 TRACE("(%p)->(IID_IWinInetHttpInfo %p)\n", This, ppv); 00143 *ppv = &This->IWinInetHttpInfo_iface; 00144 } 00145 00146 if(*ppv) { 00147 IInternetProtocol_AddRef(iface); 00148 return S_OK; 00149 } 00150 00151 WARN("not supported interface %s\n", debugstr_guid(riid)); 00152 return E_NOINTERFACE; 00153 } 00154 00155 static ULONG WINAPI FtpProtocol_AddRef(IInternetProtocolEx *iface) 00156 { 00157 FtpProtocol *This = impl_from_IInternetProtocolEx(iface); 00158 LONG ref = InterlockedIncrement(&This->ref); 00159 TRACE("(%p) ref=%d\n", This, ref); 00160 return ref; 00161 } 00162 00163 static ULONG WINAPI FtpProtocol_Release(IInternetProtocolEx *iface) 00164 { 00165 FtpProtocol *This = impl_from_IInternetProtocolEx(iface); 00166 LONG ref = InterlockedDecrement(&This->ref); 00167 00168 TRACE("(%p) ref=%d\n", This, ref); 00169 00170 if(!ref) { 00171 protocol_close_connection(&This->base); 00172 heap_free(This); 00173 00174 URLMON_UnlockModule(); 00175 } 00176 00177 return ref; 00178 } 00179 00180 static HRESULT WINAPI FtpProtocol_Start(IInternetProtocolEx *iface, LPCWSTR szUrl, 00181 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo, 00182 DWORD grfPI, HANDLE_PTR dwReserved) 00183 { 00184 FtpProtocol *This = impl_from_IInternetProtocolEx(iface); 00185 IUri *uri; 00186 HRESULT hres; 00187 00188 TRACE("(%p)->(%s %p %p %08x %lx)\n", This, debugstr_w(szUrl), pOIProtSink, 00189 pOIBindInfo, grfPI, dwReserved); 00190 00191 hres = CreateUri(szUrl, 0, 0, &uri); 00192 if(FAILED(hres)) 00193 return hres; 00194 00195 hres = IInternetProtocolEx_StartEx(&This->IInternetProtocolEx_iface, uri, pOIProtSink, 00196 pOIBindInfo, grfPI, (HANDLE*)dwReserved); 00197 00198 IUri_Release(uri); 00199 return hres; 00200 } 00201 00202 static HRESULT WINAPI FtpProtocol_Continue(IInternetProtocolEx *iface, PROTOCOLDATA *pProtocolData) 00203 { 00204 FtpProtocol *This = impl_from_IInternetProtocolEx(iface); 00205 00206 TRACE("(%p)->(%p)\n", This, pProtocolData); 00207 00208 return protocol_continue(&This->base, pProtocolData); 00209 } 00210 00211 static HRESULT WINAPI FtpProtocol_Abort(IInternetProtocolEx *iface, HRESULT hrReason, 00212 DWORD dwOptions) 00213 { 00214 FtpProtocol *This = impl_from_IInternetProtocolEx(iface); 00215 00216 TRACE("(%p)->(%08x %08x)\n", This, hrReason, dwOptions); 00217 00218 return protocol_abort(&This->base, hrReason); 00219 } 00220 00221 static HRESULT WINAPI FtpProtocol_Terminate(IInternetProtocolEx *iface, DWORD dwOptions) 00222 { 00223 FtpProtocol *This = impl_from_IInternetProtocolEx(iface); 00224 00225 TRACE("(%p)->(%08x)\n", This, dwOptions); 00226 00227 protocol_close_connection(&This->base); 00228 return S_OK; 00229 } 00230 00231 static HRESULT WINAPI FtpProtocol_Suspend(IInternetProtocolEx *iface) 00232 { 00233 FtpProtocol *This = impl_from_IInternetProtocolEx(iface); 00234 FIXME("(%p)\n", This); 00235 return E_NOTIMPL; 00236 } 00237 00238 static HRESULT WINAPI FtpProtocol_Resume(IInternetProtocolEx *iface) 00239 { 00240 FtpProtocol *This = impl_from_IInternetProtocolEx(iface); 00241 FIXME("(%p)\n", This); 00242 return E_NOTIMPL; 00243 } 00244 00245 static HRESULT WINAPI FtpProtocol_Read(IInternetProtocolEx *iface, void *pv, 00246 ULONG cb, ULONG *pcbRead) 00247 { 00248 FtpProtocol *This = impl_from_IInternetProtocolEx(iface); 00249 00250 TRACE("(%p)->(%p %u %p)\n", This, pv, cb, pcbRead); 00251 00252 return protocol_read(&This->base, pv, cb, pcbRead); 00253 } 00254 00255 static HRESULT WINAPI FtpProtocol_Seek(IInternetProtocolEx *iface, LARGE_INTEGER dlibMove, 00256 DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition) 00257 { 00258 FtpProtocol *This = impl_from_IInternetProtocolEx(iface); 00259 FIXME("(%p)->(%d %d %p)\n", This, dlibMove.u.LowPart, dwOrigin, plibNewPosition); 00260 return E_NOTIMPL; 00261 } 00262 00263 static HRESULT WINAPI FtpProtocol_LockRequest(IInternetProtocolEx *iface, DWORD dwOptions) 00264 { 00265 FtpProtocol *This = impl_from_IInternetProtocolEx(iface); 00266 00267 TRACE("(%p)->(%08x)\n", This, dwOptions); 00268 00269 return protocol_lock_request(&This->base); 00270 } 00271 00272 static HRESULT WINAPI FtpProtocol_UnlockRequest(IInternetProtocolEx *iface) 00273 { 00274 FtpProtocol *This = impl_from_IInternetProtocolEx(iface); 00275 00276 TRACE("(%p)\n", This); 00277 00278 return protocol_unlock_request(&This->base); 00279 } 00280 00281 static HRESULT WINAPI FtpProtocol_StartEx(IInternetProtocolEx *iface, IUri *pUri, 00282 IInternetProtocolSink *pOIProtSink, IInternetBindInfo *pOIBindInfo, 00283 DWORD grfPI, HANDLE *dwReserved) 00284 { 00285 FtpProtocol *This = impl_from_IInternetProtocolEx(iface); 00286 DWORD scheme = 0; 00287 HRESULT hres; 00288 00289 TRACE("(%p)->(%p %p %p %08x %p)\n", This, pUri, pOIProtSink, 00290 pOIBindInfo, grfPI, dwReserved); 00291 00292 hres = IUri_GetScheme(pUri, &scheme); 00293 if(FAILED(hres)) 00294 return hres; 00295 if(scheme != URL_SCHEME_FTP) 00296 return MK_E_SYNTAX; 00297 00298 return protocol_start(&This->base, (IInternetProtocol*)&This->IInternetProtocolEx_iface, pUri, 00299 pOIProtSink, pOIBindInfo); 00300 } 00301 00302 static const IInternetProtocolExVtbl FtpProtocolVtbl = { 00303 FtpProtocol_QueryInterface, 00304 FtpProtocol_AddRef, 00305 FtpProtocol_Release, 00306 FtpProtocol_Start, 00307 FtpProtocol_Continue, 00308 FtpProtocol_Abort, 00309 FtpProtocol_Terminate, 00310 FtpProtocol_Suspend, 00311 FtpProtocol_Resume, 00312 FtpProtocol_Read, 00313 FtpProtocol_Seek, 00314 FtpProtocol_LockRequest, 00315 FtpProtocol_UnlockRequest, 00316 FtpProtocol_StartEx 00317 }; 00318 00319 static HRESULT WINAPI FtpPriority_QueryInterface(IInternetPriority *iface, REFIID riid, void **ppv) 00320 { 00321 FtpProtocol *This = impl_from_IInternetPriority(iface); 00322 return IInternetProtocolEx_QueryInterface(&This->IInternetProtocolEx_iface, riid, ppv); 00323 } 00324 00325 static ULONG WINAPI FtpPriority_AddRef(IInternetPriority *iface) 00326 { 00327 FtpProtocol *This = impl_from_IInternetPriority(iface); 00328 return IInternetProtocolEx_AddRef(&This->IInternetProtocolEx_iface); 00329 } 00330 00331 static ULONG WINAPI FtpPriority_Release(IInternetPriority *iface) 00332 { 00333 FtpProtocol *This = impl_from_IInternetPriority(iface); 00334 return IInternetProtocolEx_Release(&This->IInternetProtocolEx_iface); 00335 } 00336 00337 static HRESULT WINAPI FtpPriority_SetPriority(IInternetPriority *iface, LONG nPriority) 00338 { 00339 FtpProtocol *This = impl_from_IInternetPriority(iface); 00340 00341 TRACE("(%p)->(%d)\n", This, nPriority); 00342 00343 This->base.priority = nPriority; 00344 return S_OK; 00345 } 00346 00347 static HRESULT WINAPI FtpPriority_GetPriority(IInternetPriority *iface, LONG *pnPriority) 00348 { 00349 FtpProtocol *This = impl_from_IInternetPriority(iface); 00350 00351 TRACE("(%p)->(%p)\n", This, pnPriority); 00352 00353 *pnPriority = This->base.priority; 00354 return S_OK; 00355 } 00356 00357 static const IInternetPriorityVtbl FtpPriorityVtbl = { 00358 FtpPriority_QueryInterface, 00359 FtpPriority_AddRef, 00360 FtpPriority_Release, 00361 FtpPriority_SetPriority, 00362 FtpPriority_GetPriority 00363 }; 00364 00365 static HRESULT WINAPI HttpInfo_QueryInterface(IWinInetHttpInfo *iface, REFIID riid, void **ppv) 00366 { 00367 FtpProtocol *This = impl_from_IWinInetHttpInfo(iface); 00368 return IInternetProtocolEx_QueryInterface(&This->IInternetProtocolEx_iface, riid, ppv); 00369 } 00370 00371 static ULONG WINAPI HttpInfo_AddRef(IWinInetHttpInfo *iface) 00372 { 00373 FtpProtocol *This = impl_from_IWinInetHttpInfo(iface); 00374 return IInternetProtocolEx_AddRef(&This->IInternetProtocolEx_iface); 00375 } 00376 00377 static ULONG WINAPI HttpInfo_Release(IWinInetHttpInfo *iface) 00378 { 00379 FtpProtocol *This = impl_from_IWinInetHttpInfo(iface); 00380 return IInternetProtocolEx_Release(&This->IInternetProtocolEx_iface); 00381 } 00382 00383 static HRESULT WINAPI HttpInfo_QueryOption(IWinInetHttpInfo *iface, DWORD dwOption, 00384 void *pBuffer, DWORD *pcbBuffer) 00385 { 00386 FtpProtocol *This = impl_from_IWinInetHttpInfo(iface); 00387 TRACE("(%p)->(%x %p %p)\n", This, dwOption, pBuffer, pcbBuffer); 00388 00389 if(!This->base.request) 00390 return E_FAIL; 00391 00392 if(!InternetQueryOptionW(This->base.request, dwOption, pBuffer, pcbBuffer)) 00393 return S_FALSE; 00394 return S_OK; 00395 } 00396 00397 static HRESULT WINAPI HttpInfo_QueryInfo(IWinInetHttpInfo *iface, DWORD dwOption, 00398 void *pBuffer, DWORD *pcbBuffer, DWORD *pdwFlags, DWORD *pdwReserved) 00399 { 00400 FtpProtocol *This = impl_from_IWinInetHttpInfo(iface); 00401 TRACE("(%p)->(%x %p %p %p %p)\n", This, dwOption, pBuffer, pcbBuffer, pdwFlags, pdwReserved); 00402 00403 if(!This->base.request) 00404 return E_FAIL; 00405 00406 if(!HttpQueryInfoW(This->base.request, dwOption, pBuffer, pcbBuffer, pdwFlags)) 00407 return S_FALSE; 00408 return S_OK; 00409 } 00410 00411 static const IWinInetHttpInfoVtbl WinInetHttpInfoVtbl = { 00412 HttpInfo_QueryInterface, 00413 HttpInfo_AddRef, 00414 HttpInfo_Release, 00415 HttpInfo_QueryOption, 00416 HttpInfo_QueryInfo 00417 }; 00418 00419 HRESULT FtpProtocol_Construct(IUnknown *pUnkOuter, LPVOID *ppobj) 00420 { 00421 FtpProtocol *ret; 00422 00423 TRACE("(%p %p)\n", pUnkOuter, ppobj); 00424 00425 URLMON_LockModule(); 00426 00427 ret = heap_alloc_zero(sizeof(FtpProtocol)); 00428 00429 ret->base.vtbl = &AsyncProtocolVtbl; 00430 ret->IInternetProtocolEx_iface.lpVtbl = &FtpProtocolVtbl; 00431 ret->IInternetPriority_iface.lpVtbl = &FtpPriorityVtbl; 00432 ret->IWinInetHttpInfo_iface.lpVtbl = &WinInetHttpInfoVtbl; 00433 ret->ref = 1; 00434 00435 *ppobj = &ret->IInternetProtocolEx_iface; 00436 00437 return S_OK; 00438 } Generated on Sun May 27 2012 04:17:13 for ReactOS by
1.7.6.1
|