2000-04-11 22:07:00 +02:00
|
|
|
/*
|
|
|
|
* WININET - Ftp implementation
|
|
|
|
*
|
|
|
|
* Copyright 1999 Corel Corporation
|
2004-02-09 23:07:42 +01:00
|
|
|
* Copyright 2004 Mike McCormack for CodeWeavers
|
2004-05-25 06:02:05 +02:00
|
|
|
* Copyright 2004 Kevin Koltzau
|
2007-10-31 22:54:03 +01:00
|
|
|
* Copyright 2007 Hans Leidekker
|
2000-04-11 22:07:00 +02:00
|
|
|
*
|
|
|
|
* Ulrich Czekalla
|
|
|
|
* Noureddine Jemmali
|
2000-12-29 06:19:57 +01:00
|
|
|
*
|
|
|
|
* Copyright 2000 Andreas Mohr
|
2002-10-28 19:48:24 +01:00
|
|
|
* Copyright 2002 Jaco Greeff
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-04-11 22:07:00 +02:00
|
|
|
*/
|
|
|
|
|
2000-04-15 22:44:21 +02:00
|
|
|
#include "config.h"
|
2002-04-26 21:05:15 +02:00
|
|
|
#include "wine/port.h"
|
2000-04-15 22:44:21 +02:00
|
|
|
|
2008-12-09 11:33:25 +01:00
|
|
|
#if defined(__MINGW32__) || defined (_MSC_VER)
|
|
|
|
#include <ws2tcpip.h>
|
|
|
|
#endif
|
|
|
|
|
2000-04-11 22:07:00 +02:00
|
|
|
#include <errno.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2000-04-11 22:07:00 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2000-04-29 19:14:24 +02:00
|
|
|
#include <sys/types.h>
|
2000-04-15 22:44:21 +02:00
|
|
|
#ifdef HAVE_SYS_SOCKET_H
|
|
|
|
# include <sys/socket.h>
|
|
|
|
#endif
|
2009-12-04 13:25:14 +01:00
|
|
|
#ifdef HAVE_ARPA_INET_H
|
|
|
|
# include <arpa/inet.h>
|
|
|
|
#endif
|
2002-08-17 02:43:16 +02:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
2009-02-10 16:29:40 +01:00
|
|
|
#ifdef HAVE_SYS_IOCTL_H
|
|
|
|
# include <sys/ioctl.h>
|
|
|
|
#endif
|
2001-02-15 22:24:07 +01:00
|
|
|
#include <time.h>
|
2004-07-19 23:49:39 +02:00
|
|
|
#include <assert.h>
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2000-06-11 22:04:44 +02:00
|
|
|
#include "winbase.h"
|
|
|
|
#include "wingdi.h"
|
|
|
|
#include "winuser.h"
|
2000-04-11 22:07:00 +02:00
|
|
|
#include "wininet.h"
|
2002-10-28 19:48:24 +01:00
|
|
|
#include "winnls.h"
|
2000-04-11 22:07:00 +02:00
|
|
|
#include "winerror.h"
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "winreg.h"
|
2003-07-22 00:04:14 +02:00
|
|
|
#include "winternl.h"
|
2004-05-25 06:02:05 +02:00
|
|
|
#include "shlwapi.h"
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
2000-04-11 22:07:00 +02:00
|
|
|
#include "internet.h"
|
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(wininet);
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2009-07-13 01:45:53 +02:00
|
|
|
typedef struct _ftp_session_t ftp_session_t;
|
2008-03-02 19:54:36 +01:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2009-07-07 21:46:09 +02:00
|
|
|
object_header_t hdr;
|
2009-07-13 01:45:53 +02:00
|
|
|
ftp_session_t *lpFtpSession;
|
2008-03-02 19:54:36 +01:00
|
|
|
BOOL session_deleted;
|
|
|
|
int nDataSocket;
|
2009-12-01 17:00:39 +01:00
|
|
|
WCHAR *cache_file;
|
|
|
|
HANDLE cache_file_handle;
|
2009-07-13 01:46:44 +02:00
|
|
|
} ftp_file_t;
|
2008-03-02 19:54:36 +01:00
|
|
|
|
2009-07-13 01:45:53 +02:00
|
|
|
struct _ftp_session_t
|
2008-03-02 19:54:36 +01:00
|
|
|
{
|
2009-07-07 21:46:09 +02:00
|
|
|
object_header_t hdr;
|
2009-07-13 01:45:06 +02:00
|
|
|
appinfo_t *lpAppInfo;
|
2008-03-02 19:54:36 +01:00
|
|
|
int sndSocket;
|
|
|
|
int lstnSocket;
|
|
|
|
int pasvSocket; /* data socket connected by us in case of passive FTP */
|
2009-07-13 01:46:44 +02:00
|
|
|
ftp_file_t *download_in_progress;
|
2008-03-02 19:54:36 +01:00
|
|
|
struct sockaddr_in socketAddress;
|
|
|
|
struct sockaddr_in lstnSocketAddress;
|
2009-12-01 17:00:39 +01:00
|
|
|
LPWSTR servername;
|
|
|
|
INTERNET_PORT serverport;
|
2008-03-02 19:54:36 +01:00
|
|
|
LPWSTR lpszPassword;
|
|
|
|
LPWSTR lpszUserName;
|
2009-07-13 01:45:53 +02:00
|
|
|
};
|
2008-03-02 19:54:36 +01:00
|
|
|
|
2008-02-27 18:55:28 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
BOOL bIsDirectory;
|
|
|
|
LPWSTR lpszName;
|
|
|
|
DWORD nSize;
|
2008-12-22 11:44:45 +01:00
|
|
|
SYSTEMTIME tmLastModified;
|
2008-02-27 18:55:28 +01:00
|
|
|
unsigned short permissions;
|
|
|
|
} FILEPROPERTIESW, *LPFILEPROPERTIESW;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2009-07-07 21:46:09 +02:00
|
|
|
object_header_t hdr;
|
2009-07-13 01:45:53 +02:00
|
|
|
ftp_session_t *lpFtpSession;
|
2008-02-27 18:55:28 +01:00
|
|
|
DWORD index;
|
|
|
|
DWORD size;
|
|
|
|
LPFILEPROPERTIESW lpafp;
|
|
|
|
} WININETFTPFINDNEXTW, *LPWININETFTPFINDNEXTW;
|
|
|
|
|
2000-04-11 22:07:00 +02:00
|
|
|
#define DATA_PACKET_SIZE 0x2000
|
|
|
|
#define szCRLF "\r\n"
|
|
|
|
#define MAX_BACKLOG 5
|
|
|
|
|
2007-02-16 17:48:39 +01:00
|
|
|
/* Testing shows that Windows only accepts dwFlags where the last
|
|
|
|
* 3 (yes 3) bits define FTP_TRANSFER_TYPE_UNKNOWN, FTP_TRANSFER_TYPE_ASCII or FTP_TRANSFER_TYPE_BINARY.
|
|
|
|
*/
|
|
|
|
#define FTP_CONDITION_MASK 0x0007
|
|
|
|
|
2000-04-11 22:07:00 +02:00
|
|
|
typedef enum {
|
|
|
|
/* FTP commands with arguments. */
|
2002-06-01 01:06:46 +02:00
|
|
|
FTP_CMD_ACCT,
|
|
|
|
FTP_CMD_CWD,
|
|
|
|
FTP_CMD_DELE,
|
|
|
|
FTP_CMD_MKD,
|
|
|
|
FTP_CMD_PASS,
|
|
|
|
FTP_CMD_PORT,
|
|
|
|
FTP_CMD_RETR,
|
|
|
|
FTP_CMD_RMD,
|
|
|
|
FTP_CMD_RNFR,
|
|
|
|
FTP_CMD_RNTO,
|
|
|
|
FTP_CMD_STOR,
|
|
|
|
FTP_CMD_TYPE,
|
|
|
|
FTP_CMD_USER,
|
2003-07-21 21:59:03 +02:00
|
|
|
FTP_CMD_SIZE,
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
/* FTP commands without arguments. */
|
|
|
|
FTP_CMD_ABOR,
|
|
|
|
FTP_CMD_LIST,
|
|
|
|
FTP_CMD_NLST,
|
2000-12-29 06:19:57 +01:00
|
|
|
FTP_CMD_PASV,
|
2002-06-01 01:06:46 +02:00
|
|
|
FTP_CMD_PWD,
|
2000-04-11 22:07:00 +02:00
|
|
|
FTP_CMD_QUIT,
|
2002-06-01 01:06:46 +02:00
|
|
|
} FTP_COMMAND;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2007-02-24 22:55:12 +01:00
|
|
|
static const CHAR *const szFtpCommands[] = {
|
2000-04-11 22:07:00 +02:00
|
|
|
"ACCT",
|
|
|
|
"CWD",
|
|
|
|
"DELE",
|
|
|
|
"MKD",
|
|
|
|
"PASS",
|
|
|
|
"PORT",
|
|
|
|
"RETR",
|
|
|
|
"RMD",
|
|
|
|
"RNFR",
|
|
|
|
"RNTO",
|
|
|
|
"STOR",
|
|
|
|
"TYPE",
|
|
|
|
"USER",
|
2003-07-21 21:59:03 +02:00
|
|
|
"SIZE",
|
2000-04-11 22:07:00 +02:00
|
|
|
"ABOR",
|
|
|
|
"LIST",
|
|
|
|
"NLST",
|
2000-12-29 06:19:57 +01:00
|
|
|
"PASV",
|
2000-04-11 22:07:00 +02:00
|
|
|
"PWD",
|
|
|
|
"QUIT",
|
|
|
|
};
|
|
|
|
|
|
|
|
static const CHAR szMonths[] = "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC";
|
2004-05-25 06:02:05 +02:00
|
|
|
static const WCHAR szNoAccount[] = {'n','o','a','c','c','o','u','n','t','\0'};
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2005-12-03 18:03:08 +01:00
|
|
|
static BOOL FTP_SendCommand(INT nSocket, FTP_COMMAND ftpCmd, LPCWSTR lpszParam,
|
2009-07-07 21:46:09 +02:00
|
|
|
INTERNET_STATUS_CALLBACK lpfnStatusCB, object_header_t *hdr, DWORD_PTR dwContext);
|
2009-07-13 01:45:53 +02:00
|
|
|
static BOOL FTP_SendStore(ftp_session_t*, LPCWSTR lpszRemoteFile, DWORD dwType);
|
|
|
|
static BOOL FTP_GetDataSocket(ftp_session_t*, LPINT nDataSocket);
|
|
|
|
static BOOL FTP_SendData(ftp_session_t*, INT nDataSocket, HANDLE hFile);
|
|
|
|
static INT FTP_ReceiveResponse(ftp_session_t*, DWORD_PTR dwContext);
|
|
|
|
static BOOL FTP_SendRetrieve(ftp_session_t*, LPCWSTR lpszRemoteFile, DWORD dwType);
|
|
|
|
static BOOL FTP_RetrieveFileData(ftp_session_t*, INT nDataSocket, HANDLE hFile);
|
|
|
|
static BOOL FTP_InitListenSocket(ftp_session_t*);
|
|
|
|
static BOOL FTP_ConnectToHost(ftp_session_t*);
|
|
|
|
static BOOL FTP_SendPassword(ftp_session_t*);
|
|
|
|
static BOOL FTP_SendAccount(ftp_session_t*);
|
|
|
|
static BOOL FTP_SendType(ftp_session_t*, DWORD dwType);
|
|
|
|
static BOOL FTP_SendPort(ftp_session_t*);
|
|
|
|
static BOOL FTP_DoPassive(ftp_session_t*);
|
|
|
|
static BOOL FTP_SendPortOrPasv(ftp_session_t*);
|
2005-12-03 18:03:08 +01:00
|
|
|
static BOOL FTP_ParsePermission(LPCSTR lpszPermission, LPFILEPROPERTIESW lpfp);
|
|
|
|
static BOOL FTP_ParseNextFile(INT nSocket, LPCWSTR lpszSearchFile, LPFILEPROPERTIESW fileprop);
|
2009-07-13 01:45:53 +02:00
|
|
|
static BOOL FTP_ParseDirectory(ftp_session_t*, INT nSocket, LPCWSTR lpszSearchFile,
|
2008-03-02 19:54:36 +01:00
|
|
|
LPFILEPROPERTIESW *lpafp, LPDWORD dwfp);
|
2009-07-13 01:45:53 +02:00
|
|
|
static HINTERNET FTP_ReceiveFileList(ftp_session_t*, INT nSocket, LPCWSTR lpszSearchFile,
|
2008-03-02 19:54:36 +01:00
|
|
|
LPWIN32_FIND_DATAW lpFindFileData, DWORD_PTR dwContext);
|
2005-12-03 18:03:08 +01:00
|
|
|
static DWORD FTP_SetResponseError(DWORD dwResponse);
|
2008-02-27 18:55:28 +01:00
|
|
|
static BOOL FTP_ConvertFileProp(LPFILEPROPERTIESW lpafp, LPWIN32_FIND_DATAW lpFindFileData);
|
2009-07-13 01:45:53 +02:00
|
|
|
static BOOL FTP_FtpPutFileW(ftp_session_t*, LPCWSTR lpszLocalFile,
|
2008-03-02 19:54:36 +01:00
|
|
|
LPCWSTR lpszNewRemoteFile, DWORD dwFlags, DWORD_PTR dwContext);
|
2009-07-13 01:45:53 +02:00
|
|
|
static BOOL FTP_FtpSetCurrentDirectoryW(ftp_session_t*, LPCWSTR lpszDirectory);
|
|
|
|
static BOOL FTP_FtpCreateDirectoryW(ftp_session_t*, LPCWSTR lpszDirectory);
|
|
|
|
static HINTERNET FTP_FtpFindFirstFileW(ftp_session_t*,
|
2008-03-02 19:54:36 +01:00
|
|
|
LPCWSTR lpszSearchFile, LPWIN32_FIND_DATAW lpFindFileData, DWORD dwFlags, DWORD_PTR dwContext);
|
2009-07-13 01:45:53 +02:00
|
|
|
static BOOL FTP_FtpGetCurrentDirectoryW(ftp_session_t*, LPWSTR lpszCurrentDirectory,
|
2008-03-02 19:54:36 +01:00
|
|
|
LPDWORD lpdwCurrentDirectory);
|
2009-07-13 01:45:53 +02:00
|
|
|
static BOOL FTP_FtpRenameFileW(ftp_session_t*, LPCWSTR lpszSrc, LPCWSTR lpszDest);
|
|
|
|
static BOOL FTP_FtpRemoveDirectoryW(ftp_session_t*, LPCWSTR lpszDirectory);
|
|
|
|
static BOOL FTP_FtpDeleteFileW(ftp_session_t*, LPCWSTR lpszFileName);
|
|
|
|
static BOOL FTP_FtpGetFileW(ftp_session_t*, LPCWSTR lpszRemoteFile, LPCWSTR lpszNewFile,
|
2008-03-02 19:54:36 +01:00
|
|
|
BOOL fFailIfExists, DWORD dwLocalFlagsAttribute, DWORD dwInternetFlags,
|
|
|
|
DWORD_PTR dwContext);
|
|
|
|
|
2009-12-21 13:57:49 +01:00
|
|
|
/* A temporary helper until we get rid of INTERNET_GetLastError calls */
|
|
|
|
static BOOL res_to_le(DWORD res)
|
|
|
|
{
|
|
|
|
if(res != ERROR_SUCCESS)
|
|
|
|
INTERNET_SetLastError(res);
|
|
|
|
return res == ERROR_SUCCESS;
|
|
|
|
}
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* FtpPutFileA (WININET.@)
|
|
|
|
*
|
|
|
|
* Uploads a file to the FTP server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
BOOL WINAPI FtpPutFileA(HINTERNET hConnect, LPCSTR lpszLocalFile,
|
2007-08-30 16:21:33 +02:00
|
|
|
LPCSTR lpszNewRemoteFile, DWORD dwFlags, DWORD_PTR dwContext)
|
2004-03-30 06:36:09 +02:00
|
|
|
{
|
2004-05-25 06:02:05 +02:00
|
|
|
LPWSTR lpwzLocalFile;
|
|
|
|
LPWSTR lpwzNewRemoteFile;
|
|
|
|
BOOL ret;
|
|
|
|
|
2009-07-17 01:11:24 +02:00
|
|
|
lpwzLocalFile = heap_strdupAtoW(lpszLocalFile);
|
|
|
|
lpwzNewRemoteFile = heap_strdupAtoW(lpszNewRemoteFile);
|
2004-05-25 06:02:05 +02:00
|
|
|
ret = FtpPutFileW(hConnect, lpwzLocalFile, lpwzNewRemoteFile,
|
|
|
|
dwFlags, dwContext);
|
2004-12-21 15:42:35 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpwzLocalFile);
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwzNewRemoteFile);
|
2004-03-30 06:36:09 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-12-25 21:34:39 +01:00
|
|
|
static void AsyncFtpPutFileProc(WORKREQUEST *workRequest)
|
|
|
|
{
|
|
|
|
struct WORKREQ_FTPPUTFILEW const *req = &workRequest->u.FtpPutFileW;
|
2009-07-13 01:45:53 +02:00
|
|
|
ftp_session_t *lpwfs = (ftp_session_t*) workRequest->hdr;
|
2006-12-25 21:34:39 +01:00
|
|
|
|
|
|
|
TRACE("%p\n", lpwfs);
|
|
|
|
|
|
|
|
FTP_FtpPutFileW(lpwfs, req->lpszLocalFile,
|
|
|
|
req->lpszNewRemoteFile, req->dwFlags, req->dwContext);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, req->lpszLocalFile);
|
|
|
|
HeapFree(GetProcessHeap(), 0, req->lpszNewRemoteFile);
|
|
|
|
}
|
|
|
|
|
2007-02-20 15:52:01 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* FtpPutFileW (WININET.@)
|
|
|
|
*
|
|
|
|
* Uploads a file to the FTP server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2004-05-25 06:02:05 +02:00
|
|
|
BOOL WINAPI FtpPutFileW(HINTERNET hConnect, LPCWSTR lpszLocalFile,
|
2007-08-30 16:21:33 +02:00
|
|
|
LPCWSTR lpszNewRemoteFile, DWORD dwFlags, DWORD_PTR dwContext)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
2009-07-13 01:45:53 +02:00
|
|
|
ftp_session_t *lpwfs;
|
2009-07-13 01:45:06 +02:00
|
|
|
appinfo_t *hIC = NULL;
|
2004-07-19 23:49:39 +02:00
|
|
|
BOOL r = FALSE;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2007-02-16 17:48:39 +01:00
|
|
|
if (!lpszLocalFile || !lpszNewRemoteFile)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-02-02 22:50:31 +01:00
|
|
|
lpwfs = (ftp_session_t*) get_handle_object( hConnect );
|
2007-02-16 17:48:39 +01:00
|
|
|
if (!lpwfs)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WH_HFTPSESSION != lpwfs->hdr.htype)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
|
2004-07-19 23:49:39 +02:00
|
|
|
goto lend;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
2007-10-26 23:19:05 +02:00
|
|
|
if (lpwfs->download_in_progress != NULL)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
2007-02-16 17:48:39 +01:00
|
|
|
if ((dwFlags & FTP_CONDITION_MASK) > FTP_TRANSFER_TYPE_BINARY)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
2006-10-29 18:52:47 +01:00
|
|
|
hIC = lpwfs->lpAppInfo;
|
2000-04-11 22:07:00 +02:00
|
|
|
if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
|
|
|
|
{
|
|
|
|
WORKREQUEST workRequest;
|
2004-05-25 06:02:05 +02:00
|
|
|
struct WORKREQ_FTPPUTFILEW *req = &workRequest.u.FtpPutFileW;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2006-12-25 21:34:39 +01:00
|
|
|
workRequest.asyncproc = AsyncFtpPutFileProc;
|
|
|
|
workRequest.hdr = WININET_AddRef( &lpwfs->hdr );
|
2009-07-17 01:10:41 +02:00
|
|
|
req->lpszLocalFile = heap_strdupW(lpszLocalFile);
|
|
|
|
req->lpszNewRemoteFile = heap_strdupW(lpszNewRemoteFile);
|
2003-09-25 22:25:22 +02:00
|
|
|
req->dwFlags = dwFlags;
|
|
|
|
req->dwContext = dwContext;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2009-12-21 13:57:49 +01:00
|
|
|
r = res_to_le(INTERNET_AsyncCall(&workRequest));
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-07-19 23:49:39 +02:00
|
|
|
r = FTP_FtpPutFileW(lpwfs, lpszLocalFile,
|
2004-05-25 06:02:05 +02:00
|
|
|
lpszNewRemoteFile, dwFlags, dwContext);
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
2004-07-19 23:49:39 +02:00
|
|
|
|
|
|
|
lend:
|
2007-02-16 17:48:39 +01:00
|
|
|
WININET_Release( &lpwfs->hdr );
|
2004-07-19 23:49:39 +02:00
|
|
|
|
|
|
|
return r;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2004-05-25 06:02:05 +02:00
|
|
|
* FTP_FtpPutFileW (Internal)
|
2000-04-11 22:07:00 +02:00
|
|
|
*
|
|
|
|
* Uploads a file to the FTP server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2009-07-13 01:45:53 +02:00
|
|
|
static BOOL FTP_FtpPutFileW(ftp_session_t *lpwfs, LPCWSTR lpszLocalFile,
|
2007-08-30 16:21:33 +02:00
|
|
|
LPCWSTR lpszNewRemoteFile, DWORD dwFlags, DWORD_PTR dwContext)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
2007-03-08 15:29:01 +01:00
|
|
|
HANDLE hFile;
|
2000-04-11 22:07:00 +02:00
|
|
|
BOOL bSuccess = FALSE;
|
2009-07-13 01:45:06 +02:00
|
|
|
appinfo_t *hIC = NULL;
|
2000-11-07 21:28:34 +01:00
|
|
|
INT nResCode;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
TRACE(" lpszLocalFile(%s) lpszNewRemoteFile(%s)\n", debugstr_w(lpszLocalFile), debugstr_w(lpszNewRemoteFile));
|
|
|
|
|
2000-04-11 22:07:00 +02:00
|
|
|
/* Clear any error information */
|
|
|
|
INTERNET_SetLastError(0);
|
|
|
|
|
|
|
|
/* Open file to be uploaded */
|
2002-06-01 01:06:46 +02:00
|
|
|
if (INVALID_HANDLE_VALUE ==
|
2004-05-25 06:02:05 +02:00
|
|
|
(hFile = CreateFileW(lpszLocalFile, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0)))
|
2007-03-01 12:01:04 +01:00
|
|
|
/* Let CreateFile set the appropriate error */
|
2007-02-16 17:48:39 +01:00
|
|
|
return FALSE;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2007-02-16 17:48:39 +01:00
|
|
|
hIC = lpwfs->lpAppInfo;
|
|
|
|
|
2004-09-20 21:10:31 +02:00
|
|
|
SendAsyncCallback(&lpwfs->hdr, lpwfs->hdr.dwContext, INTERNET_STATUS_SENDING_REQUEST, NULL, 0);
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
if (FTP_SendStore(lpwfs, lpszNewRemoteFile, dwFlags))
|
|
|
|
{
|
|
|
|
INT nDataSocket;
|
|
|
|
|
2000-12-29 06:19:57 +01:00
|
|
|
/* Get data socket to server */
|
2002-06-01 01:06:46 +02:00
|
|
|
if (FTP_GetDataSocket(lpwfs, &nDataSocket))
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
FTP_SendData(lpwfs, nDataSocket, hFile);
|
2004-09-03 20:57:19 +02:00
|
|
|
closesocket(nDataSocket);
|
2004-05-25 06:02:05 +02:00
|
|
|
nResCode = FTP_ReceiveResponse(lpwfs, dwContext);
|
2000-11-07 21:28:34 +01:00
|
|
|
if (nResCode)
|
|
|
|
{
|
|
|
|
if (nResCode == 226)
|
|
|
|
bSuccess = TRUE;
|
|
|
|
else
|
|
|
|
FTP_SetResponseError(nResCode);
|
|
|
|
}
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-24 21:13:36 +02:00
|
|
|
if (lpwfs->lstnSocket != -1)
|
2009-09-16 17:22:31 +02:00
|
|
|
{
|
2004-09-03 20:57:19 +02:00
|
|
|
closesocket(lpwfs->lstnSocket);
|
2009-09-16 17:22:31 +02:00
|
|
|
lpwfs->lstnSocket = -1;
|
|
|
|
}
|
2000-12-29 06:19:57 +01:00
|
|
|
|
2004-09-20 21:10:31 +02:00
|
|
|
if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INTERNET_ASYNC_RESULT iar;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-04-11 22:07:00 +02:00
|
|
|
iar.dwResult = (DWORD)bSuccess;
|
|
|
|
iar.dwError = bSuccess ? ERROR_SUCCESS : INTERNET_GetLastError();
|
2004-09-20 21:10:31 +02:00
|
|
|
SendAsyncCallback(&lpwfs->hdr, lpwfs->hdr.dwContext, INTERNET_STATUS_REQUEST_COMPLETE,
|
2000-04-11 22:07:00 +02:00
|
|
|
&iar, sizeof(INTERNET_ASYNC_RESULT));
|
|
|
|
}
|
|
|
|
|
2007-03-08 15:29:01 +01:00
|
|
|
CloseHandle(hFile);
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* FtpSetCurrentDirectoryA (WININET.@)
|
2000-04-11 22:07:00 +02:00
|
|
|
*
|
|
|
|
* Change the working directory on the FTP server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2000-04-15 22:44:21 +02:00
|
|
|
BOOL WINAPI FtpSetCurrentDirectoryA(HINTERNET hConnect, LPCSTR lpszDirectory)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
2004-05-25 06:02:05 +02:00
|
|
|
LPWSTR lpwzDirectory;
|
|
|
|
BOOL ret;
|
|
|
|
|
2009-07-17 01:11:24 +02:00
|
|
|
lpwzDirectory = heap_strdupAtoW(lpszDirectory);
|
2004-05-25 06:02:05 +02:00
|
|
|
ret = FtpSetCurrentDirectoryW(hConnect, lpwzDirectory);
|
2004-12-21 15:42:35 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpwzDirectory);
|
2004-05-25 06:02:05 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-25 21:34:53 +01:00
|
|
|
static void AsyncFtpSetCurrentDirectoryProc(WORKREQUEST *workRequest)
|
|
|
|
{
|
|
|
|
struct WORKREQ_FTPSETCURRENTDIRECTORYW const *req = &workRequest->u.FtpSetCurrentDirectoryW;
|
2009-07-13 01:45:53 +02:00
|
|
|
ftp_session_t *lpwfs = (ftp_session_t*) workRequest->hdr;
|
2006-12-25 21:34:53 +01:00
|
|
|
|
|
|
|
TRACE("%p\n", lpwfs);
|
|
|
|
|
|
|
|
FTP_FtpSetCurrentDirectoryW(lpwfs, req->lpszDirectory);
|
|
|
|
HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
|
|
|
|
}
|
|
|
|
|
2007-02-20 15:52:01 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* FtpSetCurrentDirectoryW (WININET.@)
|
|
|
|
*
|
|
|
|
* Change the working directory on the FTP server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2004-05-25 06:02:05 +02:00
|
|
|
BOOL WINAPI FtpSetCurrentDirectoryW(HINTERNET hConnect, LPCWSTR lpszDirectory)
|
|
|
|
{
|
2009-07-13 01:45:53 +02:00
|
|
|
ftp_session_t *lpwfs = NULL;
|
2009-07-13 01:45:06 +02:00
|
|
|
appinfo_t *hIC = NULL;
|
2004-07-19 23:49:39 +02:00
|
|
|
BOOL r = FALSE;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2006-05-11 17:47:52 +02:00
|
|
|
if (!lpszDirectory)
|
|
|
|
{
|
2007-01-09 12:30:45 +01:00
|
|
|
INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
|
2006-05-11 17:47:52 +02:00
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
2011-02-02 22:50:31 +01:00
|
|
|
lpwfs = (ftp_session_t*) get_handle_object( hConnect );
|
2000-04-11 22:07:00 +02:00
|
|
|
if (NULL == lpwfs || WH_HFTPSESSION != lpwfs->hdr.htype)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
|
2004-07-19 23:49:39 +02:00
|
|
|
goto lend;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
2007-10-26 23:19:05 +02:00
|
|
|
if (lpwfs->download_in_progress != NULL)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
TRACE("lpszDirectory(%s)\n", debugstr_w(lpszDirectory));
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2006-10-29 18:52:47 +01:00
|
|
|
hIC = lpwfs->lpAppInfo;
|
2000-04-11 22:07:00 +02:00
|
|
|
if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
|
|
|
|
{
|
|
|
|
WORKREQUEST workRequest;
|
2004-05-25 06:02:05 +02:00
|
|
|
struct WORKREQ_FTPSETCURRENTDIRECTORYW *req;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2006-12-25 21:34:53 +01:00
|
|
|
workRequest.asyncproc = AsyncFtpSetCurrentDirectoryProc;
|
|
|
|
workRequest.hdr = WININET_AddRef( &lpwfs->hdr );
|
2004-05-25 06:02:05 +02:00
|
|
|
req = &workRequest.u.FtpSetCurrentDirectoryW;
|
2009-07-17 01:10:41 +02:00
|
|
|
req->lpszDirectory = heap_strdupW(lpszDirectory);
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2009-12-21 13:57:49 +01:00
|
|
|
r = res_to_le(INTERNET_AsyncCall(&workRequest));
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-07-19 23:49:39 +02:00
|
|
|
r = FTP_FtpSetCurrentDirectoryW(lpwfs, lpszDirectory);
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
2004-07-19 23:49:39 +02:00
|
|
|
|
|
|
|
lend:
|
|
|
|
if( lpwfs )
|
|
|
|
WININET_Release( &lpwfs->hdr );
|
|
|
|
|
|
|
|
return r;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-28 19:48:24 +01:00
|
|
|
/***********************************************************************
|
2004-05-25 06:02:05 +02:00
|
|
|
* FTP_FtpSetCurrentDirectoryW (Internal)
|
2002-10-28 19:48:24 +01:00
|
|
|
*
|
|
|
|
* Change the working directory on the FTP server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2009-07-13 01:45:53 +02:00
|
|
|
static BOOL FTP_FtpSetCurrentDirectoryW(ftp_session_t *lpwfs, LPCWSTR lpszDirectory)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INT nResCode;
|
2009-07-13 01:45:06 +02:00
|
|
|
appinfo_t *hIC = NULL;
|
2000-04-11 22:07:00 +02:00
|
|
|
DWORD bSuccess = FALSE;
|
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
TRACE("lpszDirectory(%s)\n", debugstr_w(lpszDirectory));
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
/* Clear any error information */
|
|
|
|
INTERNET_SetLastError(0);
|
|
|
|
|
2006-10-29 18:52:47 +01:00
|
|
|
hIC = lpwfs->lpAppInfo;
|
2000-04-11 22:07:00 +02:00
|
|
|
if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_CWD, lpszDirectory,
|
2004-09-20 21:10:31 +02:00
|
|
|
lpwfs->hdr.lpfnStatusCB, &lpwfs->hdr, lpwfs->hdr.dwContext))
|
2000-04-11 22:07:00 +02:00
|
|
|
goto lend;
|
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
if (nResCode)
|
|
|
|
{
|
|
|
|
if (nResCode == 250)
|
|
|
|
bSuccess = TRUE;
|
|
|
|
else
|
|
|
|
FTP_SetResponseError(nResCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
lend:
|
2004-09-20 21:10:31 +02:00
|
|
|
if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INTERNET_ASYNC_RESULT iar;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2008-02-04 23:07:57 +01:00
|
|
|
iar.dwResult = bSuccess;
|
2000-04-11 22:07:00 +02:00
|
|
|
iar.dwError = bSuccess ? ERROR_SUCCESS : ERROR_INTERNET_EXTENDED_ERROR;
|
2004-09-20 21:10:31 +02:00
|
|
|
SendAsyncCallback(&lpwfs->hdr, lpwfs->hdr.dwContext, INTERNET_STATUS_REQUEST_COMPLETE,
|
2000-04-11 22:07:00 +02:00
|
|
|
&iar, sizeof(INTERNET_ASYNC_RESULT));
|
|
|
|
}
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* FtpCreateDirectoryA (WININET.@)
|
2000-04-11 22:07:00 +02:00
|
|
|
*
|
|
|
|
* Create new directory on the FTP server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2000-04-15 22:44:21 +02:00
|
|
|
BOOL WINAPI FtpCreateDirectoryA(HINTERNET hConnect, LPCSTR lpszDirectory)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
2004-05-25 06:02:05 +02:00
|
|
|
LPWSTR lpwzDirectory;
|
|
|
|
BOOL ret;
|
|
|
|
|
2009-07-17 01:11:24 +02:00
|
|
|
lpwzDirectory = heap_strdupAtoW(lpszDirectory);
|
2004-05-25 06:02:05 +02:00
|
|
|
ret = FtpCreateDirectoryW(hConnect, lpwzDirectory);
|
2004-12-21 15:42:35 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpwzDirectory);
|
2004-05-25 06:02:05 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-25 21:35:03 +01:00
|
|
|
static void AsyncFtpCreateDirectoryProc(WORKREQUEST *workRequest)
|
|
|
|
{
|
|
|
|
struct WORKREQ_FTPCREATEDIRECTORYW const *req = &workRequest->u.FtpCreateDirectoryW;
|
2009-07-13 01:45:53 +02:00
|
|
|
ftp_session_t *lpwfs = (ftp_session_t*) workRequest->hdr;
|
2006-12-25 21:35:03 +01:00
|
|
|
|
|
|
|
TRACE(" %p\n", lpwfs);
|
|
|
|
|
|
|
|
FTP_FtpCreateDirectoryW(lpwfs, req->lpszDirectory);
|
|
|
|
HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
|
|
|
|
}
|
|
|
|
|
2007-02-20 15:52:01 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* FtpCreateDirectoryW (WININET.@)
|
|
|
|
*
|
|
|
|
* Create new directory on the FTP server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2004-05-25 06:02:05 +02:00
|
|
|
BOOL WINAPI FtpCreateDirectoryW(HINTERNET hConnect, LPCWSTR lpszDirectory)
|
|
|
|
{
|
2009-07-13 01:45:53 +02:00
|
|
|
ftp_session_t *lpwfs;
|
2009-07-13 01:45:06 +02:00
|
|
|
appinfo_t *hIC = NULL;
|
2004-07-19 23:49:39 +02:00
|
|
|
BOOL r = FALSE;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2011-02-02 22:50:31 +01:00
|
|
|
lpwfs = (ftp_session_t*) get_handle_object( hConnect );
|
2007-02-08 17:27:57 +01:00
|
|
|
if (!lpwfs)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WH_HFTPSESSION != lpwfs->hdr.htype)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
|
2004-07-19 23:49:39 +02:00
|
|
|
goto lend;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
2007-10-26 23:19:05 +02:00
|
|
|
if (lpwfs->download_in_progress != NULL)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
2007-02-08 17:27:57 +01:00
|
|
|
if (!lpszDirectory)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
2006-10-29 18:52:47 +01:00
|
|
|
hIC = lpwfs->lpAppInfo;
|
2000-04-11 22:07:00 +02:00
|
|
|
if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
|
|
|
|
{
|
|
|
|
WORKREQUEST workRequest;
|
2004-05-25 06:02:05 +02:00
|
|
|
struct WORKREQ_FTPCREATEDIRECTORYW *req;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2006-12-25 21:35:03 +01:00
|
|
|
workRequest.asyncproc = AsyncFtpCreateDirectoryProc;
|
|
|
|
workRequest.hdr = WININET_AddRef( &lpwfs->hdr );
|
2004-05-25 06:02:05 +02:00
|
|
|
req = &workRequest.u.FtpCreateDirectoryW;
|
2009-07-17 01:10:41 +02:00
|
|
|
req->lpszDirectory = heap_strdupW(lpszDirectory);
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2009-12-21 13:57:49 +01:00
|
|
|
r = res_to_le(INTERNET_AsyncCall(&workRequest));
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-07-19 23:49:39 +02:00
|
|
|
r = FTP_FtpCreateDirectoryW(lpwfs, lpszDirectory);
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
2004-07-19 23:49:39 +02:00
|
|
|
lend:
|
2007-02-08 17:27:57 +01:00
|
|
|
WININET_Release( &lpwfs->hdr );
|
2004-07-19 23:49:39 +02:00
|
|
|
|
|
|
|
return r;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-28 19:48:24 +01:00
|
|
|
/***********************************************************************
|
2004-05-25 06:02:05 +02:00
|
|
|
* FTP_FtpCreateDirectoryW (Internal)
|
2000-04-11 22:07:00 +02:00
|
|
|
*
|
|
|
|
* Create new directory on the FTP server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2009-07-13 01:45:53 +02:00
|
|
|
static BOOL FTP_FtpCreateDirectoryW(ftp_session_t *lpwfs, LPCWSTR lpszDirectory)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INT nResCode;
|
|
|
|
BOOL bSuccess = FALSE;
|
2009-07-13 01:45:06 +02:00
|
|
|
appinfo_t *hIC = NULL;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
TRACE("lpszDirectory(%s)\n", debugstr_w(lpszDirectory));
|
2004-02-07 02:03:41 +01:00
|
|
|
|
2000-04-11 22:07:00 +02:00
|
|
|
/* Clear any error information */
|
|
|
|
INTERNET_SetLastError(0);
|
|
|
|
|
|
|
|
if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_MKD, lpszDirectory, 0, 0, 0))
|
|
|
|
goto lend;
|
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
|
2000-04-11 22:07:00 +02:00
|
|
|
if (nResCode)
|
|
|
|
{
|
|
|
|
if (nResCode == 257)
|
|
|
|
bSuccess = TRUE;
|
|
|
|
else
|
|
|
|
FTP_SetResponseError(nResCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
lend:
|
2006-10-29 18:52:47 +01:00
|
|
|
hIC = lpwfs->lpAppInfo;
|
2004-09-20 21:10:31 +02:00
|
|
|
if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INTERNET_ASYNC_RESULT iar;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-04-11 22:07:00 +02:00
|
|
|
iar.dwResult = (DWORD)bSuccess;
|
|
|
|
iar.dwError = bSuccess ? ERROR_SUCCESS : INTERNET_GetLastError();
|
2004-09-20 21:10:31 +02:00
|
|
|
SendAsyncCallback(&lpwfs->hdr, lpwfs->hdr.dwContext, INTERNET_STATUS_REQUEST_COMPLETE,
|
2000-04-11 22:07:00 +02:00
|
|
|
&iar, sizeof(INTERNET_ASYNC_RESULT));
|
|
|
|
}
|
|
|
|
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* FtpFindFirstFileA (WININET.@)
|
2000-04-11 22:07:00 +02:00
|
|
|
*
|
|
|
|
* Search the specified directory
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* HINTERNET on success
|
|
|
|
* NULL on failure
|
|
|
|
*
|
|
|
|
*/
|
2001-09-11 02:32:32 +02:00
|
|
|
HINTERNET WINAPI FtpFindFirstFileA(HINTERNET hConnect,
|
2007-08-30 16:21:33 +02:00
|
|
|
LPCSTR lpszSearchFile, LPWIN32_FIND_DATAA lpFindFileData, DWORD dwFlags, DWORD_PTR dwContext)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
2004-05-25 06:02:05 +02:00
|
|
|
LPWSTR lpwzSearchFile;
|
|
|
|
WIN32_FIND_DATAW wfd;
|
|
|
|
LPWIN32_FIND_DATAW lpFindFileDataW;
|
|
|
|
HINTERNET ret;
|
|
|
|
|
2009-07-17 01:11:24 +02:00
|
|
|
lpwzSearchFile = heap_strdupAtoW(lpszSearchFile);
|
2004-05-25 06:02:05 +02:00
|
|
|
lpFindFileDataW = lpFindFileData?&wfd:NULL;
|
|
|
|
ret = FtpFindFirstFileW(hConnect, lpwzSearchFile, lpFindFileDataW, dwFlags, dwContext);
|
2004-12-21 15:42:35 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpwzSearchFile);
|
2004-05-25 06:02:05 +02:00
|
|
|
|
2009-10-23 10:49:22 +02:00
|
|
|
if (ret && lpFindFileData)
|
2004-05-25 06:02:05 +02:00
|
|
|
WININET_find_data_WtoA(lpFindFileDataW, lpFindFileData);
|
2009-10-23 10:49:22 +02:00
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-25 21:35:11 +01:00
|
|
|
static void AsyncFtpFindFirstFileProc(WORKREQUEST *workRequest)
|
|
|
|
{
|
|
|
|
struct WORKREQ_FTPFINDFIRSTFILEW const *req = &workRequest->u.FtpFindFirstFileW;
|
2009-07-13 01:45:53 +02:00
|
|
|
ftp_session_t *lpwfs = (ftp_session_t*) workRequest->hdr;
|
2006-12-25 21:35:11 +01:00
|
|
|
|
|
|
|
TRACE("%p\n", lpwfs);
|
|
|
|
|
|
|
|
FTP_FtpFindFirstFileW(lpwfs, req->lpszSearchFile,
|
|
|
|
req->lpFindFileData, req->dwFlags, req->dwContext);
|
|
|
|
HeapFree(GetProcessHeap(), 0, req->lpszSearchFile);
|
|
|
|
}
|
|
|
|
|
2007-02-20 15:52:01 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* FtpFindFirstFileW (WININET.@)
|
|
|
|
*
|
|
|
|
* Search the specified directory
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* HINTERNET on success
|
|
|
|
* NULL on failure
|
|
|
|
*
|
|
|
|
*/
|
2004-05-25 06:02:05 +02:00
|
|
|
HINTERNET WINAPI FtpFindFirstFileW(HINTERNET hConnect,
|
2007-08-30 16:21:33 +02:00
|
|
|
LPCWSTR lpszSearchFile, LPWIN32_FIND_DATAW lpFindFileData, DWORD dwFlags, DWORD_PTR dwContext)
|
2004-05-25 06:02:05 +02:00
|
|
|
{
|
2009-07-13 01:45:53 +02:00
|
|
|
ftp_session_t *lpwfs;
|
2009-07-13 01:45:06 +02:00
|
|
|
appinfo_t *hIC = NULL;
|
2004-07-19 23:49:39 +02:00
|
|
|
HINTERNET r = NULL;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2011-02-02 22:50:31 +01:00
|
|
|
lpwfs = (ftp_session_t*) get_handle_object( hConnect );
|
2000-04-11 22:07:00 +02:00
|
|
|
if (NULL == lpwfs || WH_HFTPSESSION != lpwfs->hdr.htype)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
|
2004-07-19 23:49:39 +02:00
|
|
|
goto lend;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
2007-10-26 23:19:05 +02:00
|
|
|
if (lpwfs->download_in_progress != NULL)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
2006-10-29 18:52:47 +01:00
|
|
|
hIC = lpwfs->lpAppInfo;
|
2000-04-11 22:07:00 +02:00
|
|
|
if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
|
|
|
|
{
|
|
|
|
WORKREQUEST workRequest;
|
2004-05-25 06:02:05 +02:00
|
|
|
struct WORKREQ_FTPFINDFIRSTFILEW *req;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2006-12-25 21:35:11 +01:00
|
|
|
workRequest.asyncproc = AsyncFtpFindFirstFileProc;
|
|
|
|
workRequest.hdr = WININET_AddRef( &lpwfs->hdr );
|
2004-05-25 06:02:05 +02:00
|
|
|
req = &workRequest.u.FtpFindFirstFileW;
|
2009-07-17 01:10:41 +02:00
|
|
|
req->lpszSearchFile = (lpszSearchFile == NULL) ? NULL : heap_strdupW(lpszSearchFile);
|
2003-09-25 22:25:22 +02:00
|
|
|
req->lpFindFileData = lpFindFileData;
|
|
|
|
req->dwFlags = dwFlags;
|
|
|
|
req->dwContext= dwContext;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
INTERNET_AsyncCall(&workRequest);
|
2004-07-19 23:49:39 +02:00
|
|
|
r = NULL;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-07-19 23:49:39 +02:00
|
|
|
r = FTP_FtpFindFirstFileW(lpwfs, lpszSearchFile, lpFindFileData,
|
2004-05-25 06:02:05 +02:00
|
|
|
dwFlags, dwContext);
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
2004-07-19 23:49:39 +02:00
|
|
|
lend:
|
|
|
|
if( lpwfs )
|
|
|
|
WININET_Release( &lpwfs->hdr );
|
|
|
|
|
|
|
|
return r;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-28 19:48:24 +01:00
|
|
|
/***********************************************************************
|
2004-05-25 06:02:05 +02:00
|
|
|
* FTP_FtpFindFirstFileW (Internal)
|
2002-10-28 19:48:24 +01:00
|
|
|
*
|
|
|
|
* Search the specified directory
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* HINTERNET on success
|
|
|
|
* NULL on failure
|
|
|
|
*
|
|
|
|
*/
|
2009-07-13 01:45:53 +02:00
|
|
|
static HINTERNET FTP_FtpFindFirstFileW(ftp_session_t *lpwfs,
|
2007-08-30 16:21:33 +02:00
|
|
|
LPCWSTR lpszSearchFile, LPWIN32_FIND_DATAW lpFindFileData, DWORD dwFlags, DWORD_PTR dwContext)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INT nResCode;
|
2009-07-13 01:45:06 +02:00
|
|
|
appinfo_t *hIC = NULL;
|
2004-02-07 02:03:41 +01:00
|
|
|
HINTERNET hFindNext = NULL;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
/* Clear any error information */
|
|
|
|
INTERNET_SetLastError(0);
|
|
|
|
|
|
|
|
if (!FTP_InitListenSocket(lpwfs))
|
|
|
|
goto lend;
|
|
|
|
|
|
|
|
if (!FTP_SendType(lpwfs, INTERNET_FLAG_TRANSFER_ASCII))
|
|
|
|
goto lend;
|
|
|
|
|
2000-12-29 06:19:57 +01:00
|
|
|
if (!FTP_SendPortOrPasv(lpwfs))
|
2000-04-11 22:07:00 +02:00
|
|
|
goto lend;
|
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_LIST, NULL,
|
2004-09-20 21:10:31 +02:00
|
|
|
lpwfs->hdr.lpfnStatusCB, &lpwfs->hdr, lpwfs->hdr.dwContext))
|
2000-04-11 22:07:00 +02:00
|
|
|
goto lend;
|
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
|
2000-04-11 22:07:00 +02:00
|
|
|
if (nResCode)
|
|
|
|
{
|
|
|
|
if (nResCode == 125 || nResCode == 150)
|
|
|
|
{
|
|
|
|
INT nDataSocket;
|
|
|
|
|
2000-12-29 06:19:57 +01:00
|
|
|
/* Get data socket to server */
|
|
|
|
if (FTP_GetDataSocket(lpwfs, &nDataSocket))
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
2004-05-25 06:02:05 +02:00
|
|
|
hFindNext = FTP_ReceiveFileList(lpwfs, nDataSocket, lpszSearchFile, lpFindFileData, dwContext);
|
2004-09-03 20:57:19 +02:00
|
|
|
closesocket(nDataSocket);
|
2004-05-25 06:02:05 +02:00
|
|
|
nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
|
2000-04-11 22:07:00 +02:00
|
|
|
if (nResCode != 226 && nResCode != 250)
|
|
|
|
INTERNET_SetLastError(ERROR_NO_MORE_FILES);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
FTP_SetResponseError(nResCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
lend:
|
2001-08-24 21:13:36 +02:00
|
|
|
if (lpwfs->lstnSocket != -1)
|
2009-09-16 17:22:31 +02:00
|
|
|
{
|
2004-09-03 20:57:19 +02:00
|
|
|
closesocket(lpwfs->lstnSocket);
|
2009-09-16 17:22:31 +02:00
|
|
|
lpwfs->lstnSocket = -1;
|
|
|
|
}
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2007-03-20 18:40:25 +01:00
|
|
|
hIC = lpwfs->lpAppInfo;
|
2004-09-20 21:10:31 +02:00
|
|
|
if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INTERNET_ASYNC_RESULT iar;
|
|
|
|
|
|
|
|
if (hFindNext)
|
|
|
|
{
|
2009-01-08 17:28:21 +01:00
|
|
|
iar.dwResult = (DWORD_PTR)hFindNext;
|
2000-04-11 22:07:00 +02:00
|
|
|
iar.dwError = ERROR_SUCCESS;
|
2004-09-20 21:10:31 +02:00
|
|
|
SendAsyncCallback(&lpwfs->hdr, lpwfs->hdr.dwContext, INTERNET_STATUS_HANDLE_CREATED,
|
2000-04-11 22:07:00 +02:00
|
|
|
&iar, sizeof(INTERNET_ASYNC_RESULT));
|
|
|
|
}
|
|
|
|
|
2009-01-08 17:28:21 +01:00
|
|
|
iar.dwResult = (DWORD_PTR)hFindNext;
|
2000-04-11 22:07:00 +02:00
|
|
|
iar.dwError = hFindNext ? ERROR_SUCCESS : INTERNET_GetLastError();
|
2004-09-20 21:10:31 +02:00
|
|
|
SendAsyncCallback(&lpwfs->hdr, lpwfs->hdr.dwContext, INTERNET_STATUS_REQUEST_COMPLETE,
|
2000-04-11 22:07:00 +02:00
|
|
|
&iar, sizeof(INTERNET_ASYNC_RESULT));
|
|
|
|
}
|
|
|
|
|
2004-02-07 02:03:41 +01:00
|
|
|
return hFindNext;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* FtpGetCurrentDirectoryA (WININET.@)
|
2000-04-11 22:07:00 +02:00
|
|
|
*
|
|
|
|
* Retrieves the current directory
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2002-06-01 01:06:46 +02:00
|
|
|
BOOL WINAPI FtpGetCurrentDirectoryA(HINTERNET hFtpSession, LPSTR lpszCurrentDirectory,
|
2002-10-28 19:48:24 +01:00
|
|
|
LPDWORD lpdwCurrentDirectory)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
2006-06-07 21:35:16 +02:00
|
|
|
WCHAR *dir = NULL;
|
2004-05-25 06:02:05 +02:00
|
|
|
DWORD len;
|
|
|
|
BOOL ret;
|
|
|
|
|
2006-06-07 21:35:16 +02:00
|
|
|
if(lpdwCurrentDirectory) {
|
|
|
|
len = *lpdwCurrentDirectory;
|
|
|
|
if(lpszCurrentDirectory)
|
|
|
|
{
|
2011-04-21 13:39:03 +02:00
|
|
|
dir = heap_alloc(len * sizeof(WCHAR));
|
2006-06-07 21:35:16 +02:00
|
|
|
if (NULL == dir)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-05-25 06:02:05 +02:00
|
|
|
ret = FtpGetCurrentDirectoryW(hFtpSession, lpszCurrentDirectory?dir:NULL, lpdwCurrentDirectory?&len:NULL);
|
2007-12-08 22:54:43 +01:00
|
|
|
|
|
|
|
if (ret && lpszCurrentDirectory)
|
|
|
|
WideCharToMultiByte(CP_ACP, 0, dir, -1, lpszCurrentDirectory, len, NULL, NULL);
|
|
|
|
|
|
|
|
if (lpdwCurrentDirectory) *lpdwCurrentDirectory = len;
|
|
|
|
HeapFree(GetProcessHeap(), 0, dir);
|
2004-05-25 06:02:05 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-25 21:35:20 +01:00
|
|
|
static void AsyncFtpGetCurrentDirectoryProc(WORKREQUEST *workRequest)
|
|
|
|
{
|
|
|
|
struct WORKREQ_FTPGETCURRENTDIRECTORYW const *req = &workRequest->u.FtpGetCurrentDirectoryW;
|
2009-07-13 01:45:53 +02:00
|
|
|
ftp_session_t *lpwfs = (ftp_session_t*) workRequest->hdr;
|
2006-12-25 21:35:20 +01:00
|
|
|
|
|
|
|
TRACE("%p\n", lpwfs);
|
|
|
|
|
|
|
|
FTP_FtpGetCurrentDirectoryW(lpwfs, req->lpszDirectory, req->lpdwDirectory);
|
|
|
|
}
|
|
|
|
|
2007-02-20 15:52:01 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* FtpGetCurrentDirectoryW (WININET.@)
|
|
|
|
*
|
|
|
|
* Retrieves the current directory
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2004-05-25 06:02:05 +02:00
|
|
|
BOOL WINAPI FtpGetCurrentDirectoryW(HINTERNET hFtpSession, LPWSTR lpszCurrentDirectory,
|
|
|
|
LPDWORD lpdwCurrentDirectory)
|
|
|
|
{
|
2009-07-13 01:45:53 +02:00
|
|
|
ftp_session_t *lpwfs;
|
2009-07-13 01:45:06 +02:00
|
|
|
appinfo_t *hIC = NULL;
|
2004-07-19 23:49:39 +02:00
|
|
|
BOOL r = FALSE;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2008-03-24 21:32:36 +01:00
|
|
|
TRACE("%p %p %p\n", hFtpSession, lpszCurrentDirectory, lpdwCurrentDirectory);
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2011-02-02 22:50:31 +01:00
|
|
|
lpwfs = (ftp_session_t*) get_handle_object( hFtpSession );
|
2007-12-01 23:21:07 +01:00
|
|
|
if (NULL == lpwfs)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WH_HFTPSESSION != lpwfs->hdr.htype)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
|
2004-07-19 23:49:39 +02:00
|
|
|
goto lend;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
2007-12-01 23:21:07 +01:00
|
|
|
if (!lpdwCurrentDirectory)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lpszCurrentDirectory == NULL)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
2007-10-26 23:19:05 +02:00
|
|
|
if (lpwfs->download_in_progress != NULL)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
2006-10-29 18:52:47 +01:00
|
|
|
hIC = lpwfs->lpAppInfo;
|
2000-04-11 22:07:00 +02:00
|
|
|
if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
|
|
|
|
{
|
|
|
|
WORKREQUEST workRequest;
|
2004-05-25 06:02:05 +02:00
|
|
|
struct WORKREQ_FTPGETCURRENTDIRECTORYW *req;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2006-12-25 21:35:20 +01:00
|
|
|
workRequest.asyncproc = AsyncFtpGetCurrentDirectoryProc;
|
|
|
|
workRequest.hdr = WININET_AddRef( &lpwfs->hdr );
|
2004-05-25 06:02:05 +02:00
|
|
|
req = &workRequest.u.FtpGetCurrentDirectoryW;
|
2003-09-25 22:25:22 +02:00
|
|
|
req->lpszDirectory = lpszCurrentDirectory;
|
|
|
|
req->lpdwDirectory = lpdwCurrentDirectory;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2009-12-21 13:57:49 +01:00
|
|
|
r = res_to_le(INTERNET_AsyncCall(&workRequest));
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-07-19 23:49:39 +02:00
|
|
|
r = FTP_FtpGetCurrentDirectoryW(lpwfs, lpszCurrentDirectory,
|
2004-05-25 06:02:05 +02:00
|
|
|
lpdwCurrentDirectory);
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
2004-07-19 23:49:39 +02:00
|
|
|
|
|
|
|
lend:
|
|
|
|
if( lpwfs )
|
|
|
|
WININET_Release( &lpwfs->hdr );
|
|
|
|
|
|
|
|
return r;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2007-02-07 13:30:10 +01:00
|
|
|
* FTP_FtpGetCurrentDirectoryW (Internal)
|
2000-04-11 22:07:00 +02:00
|
|
|
*
|
|
|
|
* Retrieves the current directory
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2009-07-13 01:45:53 +02:00
|
|
|
static BOOL FTP_FtpGetCurrentDirectoryW(ftp_session_t *lpwfs, LPWSTR lpszCurrentDirectory,
|
2000-04-11 22:07:00 +02:00
|
|
|
LPDWORD lpdwCurrentDirectory)
|
|
|
|
{
|
|
|
|
INT nResCode;
|
2009-07-13 01:45:06 +02:00
|
|
|
appinfo_t *hIC = NULL;
|
2000-04-11 22:07:00 +02:00
|
|
|
DWORD bSuccess = FALSE;
|
|
|
|
|
|
|
|
/* Clear any error information */
|
|
|
|
INTERNET_SetLastError(0);
|
|
|
|
|
2006-10-29 18:52:47 +01:00
|
|
|
hIC = lpwfs->lpAppInfo;
|
2000-04-11 22:07:00 +02:00
|
|
|
if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_PWD, NULL,
|
2004-09-20 21:10:31 +02:00
|
|
|
lpwfs->hdr.lpfnStatusCB, &lpwfs->hdr, lpwfs->hdr.dwContext))
|
2000-04-11 22:07:00 +02:00
|
|
|
goto lend;
|
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
|
2000-04-11 22:07:00 +02:00
|
|
|
if (nResCode)
|
|
|
|
{
|
|
|
|
if (nResCode == 257) /* Extract directory name */
|
|
|
|
{
|
2004-08-09 20:54:23 +02:00
|
|
|
DWORD firstpos, lastpos, len;
|
2009-07-17 01:11:24 +02:00
|
|
|
LPWSTR lpszResponseBuffer = heap_strdupAtoW(INTERNET_GetResponseBuffer());
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
for (firstpos = 0, lastpos = 0; lpszResponseBuffer[lastpos]; lastpos++)
|
|
|
|
{
|
|
|
|
if ('"' == lpszResponseBuffer[lastpos])
|
|
|
|
{
|
|
|
|
if (!firstpos)
|
|
|
|
firstpos = lastpos;
|
|
|
|
else
|
|
|
|
break;
|
2007-12-08 22:54:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
len = lastpos - firstpos;
|
|
|
|
if (*lpdwCurrentDirectory >= len)
|
|
|
|
{
|
|
|
|
memcpy(lpszCurrentDirectory, &lpszResponseBuffer[firstpos + 1], len * sizeof(WCHAR));
|
|
|
|
lpszCurrentDirectory[len - 1] = 0;
|
|
|
|
*lpdwCurrentDirectory = len;
|
|
|
|
bSuccess = TRUE;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
2007-12-08 22:54:43 +01:00
|
|
|
else INTERNET_SetLastError(ERROR_INSUFFICIENT_BUFFER);
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpszResponseBuffer);
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
FTP_SetResponseError(nResCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
lend:
|
2004-09-20 21:10:31 +02:00
|
|
|
if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INTERNET_ASYNC_RESULT iar;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2008-02-04 23:07:57 +01:00
|
|
|
iar.dwResult = bSuccess;
|
2000-04-11 22:07:00 +02:00
|
|
|
iar.dwError = bSuccess ? ERROR_SUCCESS : ERROR_INTERNET_EXTENDED_ERROR;
|
2004-09-20 21:10:31 +02:00
|
|
|
SendAsyncCallback(&lpwfs->hdr, lpwfs->hdr.dwContext, INTERNET_STATUS_REQUEST_COMPLETE,
|
2000-04-11 22:07:00 +02:00
|
|
|
&iar, sizeof(INTERNET_ASYNC_RESULT));
|
|
|
|
}
|
|
|
|
|
2008-02-04 23:07:57 +01:00
|
|
|
return bSuccess;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-26 20:20:41 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* FTPFILE_Destroy(internal)
|
|
|
|
*
|
|
|
|
* Closes the file transfer handle. This also 'cleans' the data queue of
|
|
|
|
* the 'transfer complete' message (this is a bit of a hack though :-/ )
|
|
|
|
*
|
|
|
|
*/
|
2009-07-07 21:46:09 +02:00
|
|
|
static void FTPFILE_Destroy(object_header_t *hdr)
|
2008-02-26 20:20:41 +01:00
|
|
|
{
|
2009-07-13 01:46:44 +02:00
|
|
|
ftp_file_t *lpwh = (ftp_file_t*) hdr;
|
2009-07-13 01:45:53 +02:00
|
|
|
ftp_session_t *lpwfs = lpwh->lpFtpSession;
|
2008-02-26 20:20:41 +01:00
|
|
|
INT nResCode;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2009-12-01 17:00:39 +01:00
|
|
|
if (lpwh->cache_file_handle != INVALID_HANDLE_VALUE)
|
|
|
|
CloseHandle(lpwh->cache_file_handle);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwh->cache_file);
|
|
|
|
|
2008-02-26 20:20:41 +01:00
|
|
|
if (!lpwh->session_deleted)
|
|
|
|
lpwfs->download_in_progress = NULL;
|
|
|
|
|
|
|
|
if (lpwh->nDataSocket != -1)
|
|
|
|
closesocket(lpwh->nDataSocket);
|
|
|
|
|
|
|
|
nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
|
|
|
|
if (nResCode > 0 && nResCode != 226) WARN("server reports failed transfer\n");
|
|
|
|
|
2009-03-09 01:49:20 +01:00
|
|
|
WININET_Release(&lpwh->lpFtpSession->hdr);
|
2008-02-26 20:20:41 +01:00
|
|
|
}
|
|
|
|
|
2009-07-07 21:46:09 +02:00
|
|
|
static DWORD FTPFILE_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
|
2008-03-12 02:23:20 +01:00
|
|
|
{
|
|
|
|
switch(option) {
|
|
|
|
case INTERNET_OPTION_HANDLE_TYPE:
|
|
|
|
TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
|
|
|
|
|
|
|
|
if (*size < sizeof(ULONG))
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
|
|
|
|
*size = sizeof(DWORD);
|
|
|
|
*(DWORD*)buffer = INTERNET_HANDLE_TYPE_FTP_FILE;
|
|
|
|
return ERROR_SUCCESS;
|
2009-12-01 17:01:35 +01:00
|
|
|
case INTERNET_OPTION_DATAFILE_NAME:
|
|
|
|
{
|
|
|
|
DWORD required;
|
|
|
|
ftp_file_t *file = (ftp_file_t *)hdr;
|
|
|
|
|
|
|
|
TRACE("INTERNET_OPTION_DATAFILE_NAME\n");
|
|
|
|
|
|
|
|
if (!file->cache_file)
|
|
|
|
{
|
|
|
|
*size = 0;
|
|
|
|
return ERROR_INTERNET_ITEM_NOT_FOUND;
|
|
|
|
}
|
|
|
|
if (unicode)
|
|
|
|
{
|
|
|
|
required = (lstrlenW(file->cache_file) + 1) * sizeof(WCHAR);
|
|
|
|
if (*size < required)
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
2008-03-12 02:23:20 +01:00
|
|
|
|
2009-12-01 17:01:35 +01:00
|
|
|
*size = required;
|
|
|
|
memcpy(buffer, file->cache_file, *size);
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
required = WideCharToMultiByte(CP_ACP, 0, file->cache_file, -1, NULL, 0, NULL, NULL);
|
|
|
|
if (required > *size)
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
|
|
|
|
*size = WideCharToMultiByte(CP_ACP, 0, file->cache_file, -1, buffer, *size, NULL, NULL);
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-05-25 12:19:32 +02:00
|
|
|
return INET_QueryOption(hdr, option, buffer, size, unicode);
|
2008-03-12 02:23:20 +01:00
|
|
|
}
|
|
|
|
|
2009-07-07 21:46:09 +02:00
|
|
|
static DWORD FTPFILE_ReadFile(object_header_t *hdr, void *buffer, DWORD size, DWORD *read)
|
2008-03-02 19:35:11 +01:00
|
|
|
{
|
2009-07-13 01:46:44 +02:00
|
|
|
ftp_file_t *file = (ftp_file_t*)hdr;
|
2008-03-02 19:35:11 +01:00
|
|
|
int res;
|
2009-12-01 17:00:39 +01:00
|
|
|
DWORD error;
|
2008-03-02 19:35:11 +01:00
|
|
|
|
|
|
|
if (file->nDataSocket == -1)
|
|
|
|
return ERROR_INTERNET_DISCONNECTED;
|
|
|
|
|
|
|
|
/* FIXME: FTP should use NETCON_ stuff */
|
|
|
|
res = recv(file->nDataSocket, buffer, size, MSG_WAITALL);
|
|
|
|
*read = res>0 ? res : 0;
|
|
|
|
|
2009-12-01 17:00:39 +01:00
|
|
|
error = res >= 0 ? ERROR_SUCCESS : INTERNET_ERROR_BASE; /* FIXME */
|
|
|
|
if (error == ERROR_SUCCESS && file->cache_file)
|
|
|
|
{
|
|
|
|
DWORD bytes_written;
|
|
|
|
|
|
|
|
if (!WriteFile(file->cache_file_handle, buffer, *read, &bytes_written, NULL))
|
|
|
|
WARN("WriteFile failed: %u\n", GetLastError());
|
|
|
|
}
|
|
|
|
return error;
|
2008-03-02 19:35:11 +01:00
|
|
|
}
|
|
|
|
|
2009-07-07 21:46:09 +02:00
|
|
|
static DWORD FTPFILE_ReadFileExA(object_header_t *hdr, INTERNET_BUFFERSA *buffers,
|
2009-04-30 09:14:36 +02:00
|
|
|
DWORD flags, DWORD_PTR context)
|
|
|
|
{
|
|
|
|
return FTPFILE_ReadFile(hdr, buffers->lpvBuffer, buffers->dwBufferLength, &buffers->dwBufferLength);
|
|
|
|
}
|
|
|
|
|
2009-07-07 21:46:09 +02:00
|
|
|
static DWORD FTPFILE_ReadFileExW(object_header_t *hdr, INTERNET_BUFFERSW *buffers,
|
2009-04-30 09:14:36 +02:00
|
|
|
DWORD flags, DWORD_PTR context)
|
|
|
|
{
|
|
|
|
return FTPFILE_ReadFile(hdr, buffers->lpvBuffer, buffers->dwBufferLength, &buffers->dwBufferLength);
|
|
|
|
}
|
|
|
|
|
2009-11-30 00:13:39 +01:00
|
|
|
static DWORD FTPFILE_WriteFile(object_header_t *hdr, const void *buffer, DWORD size, DWORD *written)
|
2008-02-26 20:21:34 +01:00
|
|
|
{
|
2009-07-13 01:46:44 +02:00
|
|
|
ftp_file_t *lpwh = (ftp_file_t*) hdr;
|
2008-02-26 20:21:34 +01:00
|
|
|
int res;
|
|
|
|
|
|
|
|
res = send(lpwh->nDataSocket, buffer, size, 0);
|
|
|
|
|
|
|
|
*written = res>0 ? res : 0;
|
2009-11-30 00:13:39 +01:00
|
|
|
return res >= 0 ? ERROR_SUCCESS : sock_get_error(errno);
|
2008-02-26 20:21:34 +01:00
|
|
|
}
|
|
|
|
|
2009-07-13 01:46:44 +02:00
|
|
|
static void FTP_ReceiveRequestData(ftp_file_t *file, BOOL first_notif)
|
2009-02-10 16:29:40 +01:00
|
|
|
{
|
|
|
|
INTERNET_ASYNC_RESULT iar;
|
|
|
|
BYTE buffer[4096];
|
|
|
|
int available;
|
|
|
|
|
|
|
|
TRACE("%p\n", file);
|
|
|
|
|
|
|
|
available = recv(file->nDataSocket, buffer, sizeof(buffer), MSG_PEEK);
|
|
|
|
|
|
|
|
if(available != -1) {
|
|
|
|
iar.dwResult = (DWORD_PTR)file->hdr.hInternet;
|
|
|
|
iar.dwError = first_notif ? 0 : available;
|
|
|
|
}else {
|
|
|
|
iar.dwResult = 0;
|
|
|
|
iar.dwError = INTERNET_GetLastError();
|
|
|
|
}
|
|
|
|
|
|
|
|
INTERNET_SendCallback(&file->hdr, file->hdr.dwContext, INTERNET_STATUS_REQUEST_COMPLETE, &iar,
|
|
|
|
sizeof(INTERNET_ASYNC_RESULT));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void FTPFILE_AsyncQueryDataAvailableProc(WORKREQUEST *workRequest)
|
|
|
|
{
|
2009-07-13 01:46:44 +02:00
|
|
|
ftp_file_t *file = (ftp_file_t*)workRequest->hdr;
|
2009-02-10 16:29:40 +01:00
|
|
|
|
|
|
|
FTP_ReceiveRequestData(file, FALSE);
|
|
|
|
}
|
|
|
|
|
2009-07-07 21:46:09 +02:00
|
|
|
static DWORD FTPFILE_QueryDataAvailable(object_header_t *hdr, DWORD *available, DWORD flags, DWORD_PTR ctx)
|
2009-02-10 16:29:40 +01:00
|
|
|
{
|
2009-07-13 01:46:44 +02:00
|
|
|
ftp_file_t *file = (ftp_file_t*) hdr;
|
2009-02-10 16:29:40 +01:00
|
|
|
int retval, unread = 0;
|
|
|
|
|
|
|
|
TRACE("(%p %p %x %lx)\n", file, available, flags, ctx);
|
|
|
|
|
|
|
|
#ifdef FIONREAD
|
|
|
|
retval = ioctlsocket(file->nDataSocket, FIONREAD, &unread);
|
|
|
|
if (!retval)
|
|
|
|
TRACE("%d bytes of queued, but unread data\n", unread);
|
|
|
|
#else
|
|
|
|
FIXME("FIONREAD not available\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
*available = unread;
|
|
|
|
|
|
|
|
if(!unread) {
|
|
|
|
BYTE byte;
|
|
|
|
|
|
|
|
*available = 0;
|
|
|
|
|
|
|
|
retval = recv(file->nDataSocket, &byte, 1, MSG_PEEK);
|
|
|
|
if(retval > 0) {
|
|
|
|
WORKREQUEST workRequest;
|
|
|
|
|
|
|
|
*available = 0;
|
|
|
|
workRequest.asyncproc = FTPFILE_AsyncQueryDataAvailableProc;
|
|
|
|
workRequest.hdr = WININET_AddRef( &file->hdr );
|
|
|
|
|
|
|
|
INTERNET_AsyncCall(&workRequest);
|
|
|
|
|
|
|
|
return ERROR_IO_PENDING;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-07 21:46:09 +02:00
|
|
|
static const object_vtbl_t FTPFILEVtbl = {
|
2008-02-26 20:21:00 +01:00
|
|
|
FTPFILE_Destroy,
|
2008-02-26 20:21:34 +01:00
|
|
|
NULL,
|
2008-03-12 02:23:20 +01:00
|
|
|
FTPFILE_QueryOption,
|
2008-02-26 20:22:02 +01:00
|
|
|
NULL,
|
2008-03-02 19:35:11 +01:00
|
|
|
FTPFILE_ReadFile,
|
2009-04-30 09:14:36 +02:00
|
|
|
FTPFILE_ReadFileExA,
|
|
|
|
FTPFILE_ReadFileExW,
|
2008-02-27 18:55:09 +01:00
|
|
|
FTPFILE_WriteFile,
|
2009-02-10 16:29:40 +01:00
|
|
|
FTPFILE_QueryDataAvailable,
|
2008-02-27 18:55:09 +01:00
|
|
|
NULL
|
2008-02-26 20:20:41 +01:00
|
|
|
};
|
|
|
|
|
2002-10-28 19:48:24 +01:00
|
|
|
/***********************************************************************
|
2004-05-25 06:02:05 +02:00
|
|
|
* FTP_FtpOpenFileW (Internal)
|
2000-04-11 22:07:00 +02:00
|
|
|
*
|
|
|
|
* Open a remote file for writing or reading
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* HINTERNET handle on success
|
|
|
|
* NULL on failure
|
|
|
|
*
|
|
|
|
*/
|
2009-12-04 11:43:25 +01:00
|
|
|
static HINTERNET FTP_FtpOpenFileW(ftp_session_t *lpwfs,
|
2004-05-25 06:02:05 +02:00
|
|
|
LPCWSTR lpszFileName, DWORD fdwAccess, DWORD dwFlags,
|
2007-08-30 16:21:33 +02:00
|
|
|
DWORD_PTR dwContext)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INT nDataSocket;
|
|
|
|
BOOL bSuccess = FALSE;
|
2009-07-13 01:46:44 +02:00
|
|
|
ftp_file_t *lpwh = NULL;
|
2009-07-13 01:45:06 +02:00
|
|
|
appinfo_t *hIC = NULL;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
/* Clear any error information */
|
|
|
|
INTERNET_SetLastError(0);
|
|
|
|
|
|
|
|
if (GENERIC_READ == fdwAccess)
|
|
|
|
{
|
|
|
|
/* Set up socket to retrieve data */
|
|
|
|
bSuccess = FTP_SendRetrieve(lpwfs, lpszFileName, dwFlags);
|
|
|
|
}
|
|
|
|
else if (GENERIC_WRITE == fdwAccess)
|
|
|
|
{
|
|
|
|
/* Set up socket to send data */
|
|
|
|
bSuccess = FTP_SendStore(lpwfs, lpszFileName, dwFlags);
|
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/* Get data socket to server */
|
|
|
|
if (bSuccess && FTP_GetDataSocket(lpwfs, &nDataSocket))
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
2011-02-02 22:51:13 +01:00
|
|
|
lpwh = alloc_object(&lpwfs->hdr, &FTPFILEVtbl, sizeof(ftp_file_t));
|
2004-02-07 02:03:41 +01:00
|
|
|
lpwh->hdr.htype = WH_HFILE;
|
|
|
|
lpwh->hdr.dwFlags = dwFlags;
|
|
|
|
lpwh->hdr.dwContext = dwContext;
|
|
|
|
lpwh->nDataSocket = nDataSocket;
|
2009-12-01 17:00:39 +01:00
|
|
|
lpwh->cache_file = NULL;
|
|
|
|
lpwh->cache_file_handle = INVALID_HANDLE_VALUE;
|
|
|
|
lpwh->session_deleted = FALSE;
|
2006-10-29 18:55:15 +01:00
|
|
|
|
|
|
|
WININET_AddRef( &lpwfs->hdr );
|
|
|
|
lpwh->lpFtpSession = lpwfs;
|
2007-09-21 03:59:40 +02:00
|
|
|
list_add_head( &lpwfs->hdr.children, &lpwh->hdr.entry );
|
2003-07-22 00:04:14 +02:00
|
|
|
|
|
|
|
/* Indicate that a download is currently in progress */
|
2004-02-07 02:03:41 +01:00
|
|
|
lpwfs->download_in_progress = lpwh;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
2001-08-24 21:13:36 +02:00
|
|
|
if (lpwfs->lstnSocket != -1)
|
2009-09-16 17:22:31 +02:00
|
|
|
{
|
2004-09-03 20:57:19 +02:00
|
|
|
closesocket(lpwfs->lstnSocket);
|
2009-09-16 17:22:31 +02:00
|
|
|
lpwfs->lstnSocket = -1;
|
|
|
|
}
|
2000-12-29 06:19:57 +01:00
|
|
|
|
2009-12-01 17:00:39 +01:00
|
|
|
if (bSuccess && fdwAccess == GENERIC_READ)
|
|
|
|
{
|
|
|
|
WCHAR filename[MAX_PATH + 1];
|
|
|
|
URL_COMPONENTSW uc;
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
memset(&uc, 0, sizeof(uc));
|
|
|
|
uc.dwStructSize = sizeof(uc);
|
|
|
|
uc.nScheme = INTERNET_SCHEME_FTP;
|
|
|
|
uc.lpszHostName = lpwfs->servername;
|
|
|
|
uc.nPort = lpwfs->serverport;
|
|
|
|
uc.lpszUserName = lpwfs->lpszUserName;
|
|
|
|
uc.lpszUrlPath = heap_strdupW(lpszFileName);
|
|
|
|
|
|
|
|
if (!InternetCreateUrlW(&uc, 0, NULL, &len) && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
|
|
|
{
|
2011-04-21 13:39:03 +02:00
|
|
|
WCHAR *url = heap_alloc(len * sizeof(WCHAR));
|
2009-12-01 17:00:39 +01:00
|
|
|
|
|
|
|
if (url && InternetCreateUrlW(&uc, 0, url, &len) && CreateUrlCacheEntryW(url, 0, NULL, filename, 0))
|
|
|
|
{
|
|
|
|
lpwh->cache_file = heap_strdupW(filename);
|
|
|
|
lpwh->cache_file_handle = CreateFileW(filename, GENERIC_WRITE, FILE_SHARE_READ,
|
|
|
|
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
|
|
if (lpwh->cache_file_handle == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
WARN("Could not create cache file: %u\n", GetLastError());
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwh->cache_file);
|
|
|
|
lpwh->cache_file = NULL;
|
|
|
|
}
|
|
|
|
}
|
2009-12-03 00:41:55 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, url);
|
2009-12-01 17:00:39 +01:00
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, uc.lpszUrlPath);
|
|
|
|
}
|
|
|
|
|
2006-10-29 18:52:47 +01:00
|
|
|
hIC = lpwfs->lpAppInfo;
|
2004-09-20 21:10:31 +02:00
|
|
|
if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INTERNET_ASYNC_RESULT iar;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2004-02-07 02:03:41 +01:00
|
|
|
if (lpwh)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
2011-02-02 22:51:13 +01:00
|
|
|
iar.dwResult = (DWORD_PTR)lpwh->hdr.hInternet;
|
2000-04-11 22:07:00 +02:00
|
|
|
iar.dwError = ERROR_SUCCESS;
|
2004-09-20 21:10:31 +02:00
|
|
|
SendAsyncCallback(&lpwfs->hdr, lpwfs->hdr.dwContext, INTERNET_STATUS_HANDLE_CREATED,
|
2000-04-11 22:07:00 +02:00
|
|
|
&iar, sizeof(INTERNET_ASYNC_RESULT));
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2009-02-10 16:30:45 +01:00
|
|
|
if(bSuccess) {
|
|
|
|
FTP_ReceiveRequestData(lpwh, TRUE);
|
|
|
|
}else {
|
|
|
|
iar.dwResult = 0;
|
|
|
|
iar.dwError = INTERNET_GetLastError();
|
|
|
|
SendAsyncCallback(&lpwfs->hdr, lpwfs->hdr.dwContext, INTERNET_STATUS_REQUEST_COMPLETE,
|
|
|
|
&iar, sizeof(INTERNET_ASYNC_RESULT));
|
|
|
|
}
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
2011-02-02 22:51:13 +01:00
|
|
|
if(!bSuccess) {
|
|
|
|
if(lpwh)
|
|
|
|
WININET_Release( &lpwh->hdr );
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-07-19 23:49:39 +02:00
|
|
|
|
2011-02-02 22:51:13 +01:00
|
|
|
return lpwh->hdr.hInternet;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-10 16:28:56 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* FtpOpenFileA (WININET.@)
|
|
|
|
*
|
|
|
|
* Open a remote file for writing or reading
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* HINTERNET handle on success
|
|
|
|
* NULL on failure
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
HINTERNET WINAPI FtpOpenFileA(HINTERNET hFtpSession,
|
|
|
|
LPCSTR lpszFileName, DWORD fdwAccess, DWORD dwFlags,
|
|
|
|
DWORD_PTR dwContext)
|
|
|
|
{
|
|
|
|
LPWSTR lpwzFileName;
|
|
|
|
HINTERNET ret;
|
|
|
|
|
2009-07-17 01:11:24 +02:00
|
|
|
lpwzFileName = heap_strdupAtoW(lpszFileName);
|
2009-02-10 16:28:56 +01:00
|
|
|
ret = FtpOpenFileW(hFtpSession, lpwzFileName, fdwAccess, dwFlags, dwContext);
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwzFileName);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void AsyncFtpOpenFileProc(WORKREQUEST *workRequest)
|
|
|
|
{
|
|
|
|
struct WORKREQ_FTPOPENFILEW const *req = &workRequest->u.FtpOpenFileW;
|
2009-07-13 01:45:53 +02:00
|
|
|
ftp_session_t *lpwfs = (ftp_session_t*) workRequest->hdr;
|
2009-02-10 16:28:56 +01:00
|
|
|
|
|
|
|
TRACE("%p\n", lpwfs);
|
|
|
|
|
|
|
|
FTP_FtpOpenFileW(lpwfs, req->lpszFilename,
|
|
|
|
req->dwAccess, req->dwFlags, req->dwContext);
|
|
|
|
HeapFree(GetProcessHeap(), 0, req->lpszFilename);
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FtpOpenFileW (WININET.@)
|
|
|
|
*
|
|
|
|
* Open a remote file for writing or reading
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* HINTERNET handle on success
|
|
|
|
* NULL on failure
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
HINTERNET WINAPI FtpOpenFileW(HINTERNET hFtpSession,
|
|
|
|
LPCWSTR lpszFileName, DWORD fdwAccess, DWORD dwFlags,
|
|
|
|
DWORD_PTR dwContext)
|
|
|
|
{
|
2009-07-13 01:45:53 +02:00
|
|
|
ftp_session_t *lpwfs;
|
2009-07-13 01:45:06 +02:00
|
|
|
appinfo_t *hIC = NULL;
|
2009-02-10 16:28:56 +01:00
|
|
|
HINTERNET r = NULL;
|
|
|
|
|
|
|
|
TRACE("(%p,%s,0x%08x,0x%08x,0x%08lx)\n", hFtpSession,
|
|
|
|
debugstr_w(lpszFileName), fdwAccess, dwFlags, dwContext);
|
|
|
|
|
2011-02-02 22:50:31 +01:00
|
|
|
lpwfs = (ftp_session_t*) get_handle_object( hFtpSession );
|
2009-02-10 16:28:56 +01:00
|
|
|
if (!lpwfs)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WH_HFTPSESSION != lpwfs->hdr.htype)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((!lpszFileName) ||
|
|
|
|
((fdwAccess != GENERIC_READ) && (fdwAccess != GENERIC_WRITE)) ||
|
|
|
|
((dwFlags & FTP_CONDITION_MASK) > FTP_TRANSFER_TYPE_BINARY))
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lpwfs->download_in_progress != NULL)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
|
|
|
hIC = lpwfs->lpAppInfo;
|
|
|
|
if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
|
|
|
|
{
|
|
|
|
WORKREQUEST workRequest;
|
|
|
|
struct WORKREQ_FTPOPENFILEW *req;
|
|
|
|
|
|
|
|
workRequest.asyncproc = AsyncFtpOpenFileProc;
|
|
|
|
workRequest.hdr = WININET_AddRef( &lpwfs->hdr );
|
|
|
|
req = &workRequest.u.FtpOpenFileW;
|
2009-07-17 01:10:41 +02:00
|
|
|
req->lpszFilename = heap_strdupW(lpszFileName);
|
2009-02-10 16:28:56 +01:00
|
|
|
req->dwAccess = fdwAccess;
|
|
|
|
req->dwFlags = dwFlags;
|
|
|
|
req->dwContext = dwContext;
|
|
|
|
|
|
|
|
INTERNET_AsyncCall(&workRequest);
|
|
|
|
r = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
r = FTP_FtpOpenFileW(lpwfs, lpszFileName, fdwAccess, dwFlags, dwContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
lend:
|
|
|
|
WININET_Release( &lpwfs->hdr );
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-11 22:07:00 +02:00
|
|
|
/***********************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* FtpGetFileA (WININET.@)
|
2000-04-11 22:07:00 +02:00
|
|
|
*
|
|
|
|
* Retrieve file from the FTP server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2000-04-15 22:44:21 +02:00
|
|
|
BOOL WINAPI FtpGetFileA(HINTERNET hInternet, LPCSTR lpszRemoteFile, LPCSTR lpszNewFile,
|
2002-10-28 19:48:24 +01:00
|
|
|
BOOL fFailIfExists, DWORD dwLocalFlagsAttribute, DWORD dwInternetFlags,
|
2007-08-30 16:21:33 +02:00
|
|
|
DWORD_PTR dwContext)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
2004-05-25 06:02:05 +02:00
|
|
|
LPWSTR lpwzRemoteFile;
|
|
|
|
LPWSTR lpwzNewFile;
|
|
|
|
BOOL ret;
|
|
|
|
|
2009-07-17 01:11:24 +02:00
|
|
|
lpwzRemoteFile = heap_strdupAtoW(lpszRemoteFile);
|
|
|
|
lpwzNewFile = heap_strdupAtoW(lpszNewFile);
|
2004-05-25 06:02:05 +02:00
|
|
|
ret = FtpGetFileW(hInternet, lpwzRemoteFile, lpwzNewFile, fFailIfExists,
|
|
|
|
dwLocalFlagsAttribute, dwInternetFlags, dwContext);
|
2004-12-21 15:42:35 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpwzRemoteFile);
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwzNewFile);
|
2004-05-25 06:02:05 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-25 21:35:46 +01:00
|
|
|
static void AsyncFtpGetFileProc(WORKREQUEST *workRequest)
|
|
|
|
{
|
|
|
|
struct WORKREQ_FTPGETFILEW const *req = &workRequest->u.FtpGetFileW;
|
2009-07-13 01:45:53 +02:00
|
|
|
ftp_session_t *lpwfs = (ftp_session_t*) workRequest->hdr;
|
2006-12-25 21:35:46 +01:00
|
|
|
|
|
|
|
TRACE("%p\n", lpwfs);
|
|
|
|
|
|
|
|
FTP_FtpGetFileW(lpwfs, req->lpszRemoteFile,
|
|
|
|
req->lpszNewFile, req->fFailIfExists,
|
|
|
|
req->dwLocalFlagsAttribute, req->dwFlags, req->dwContext);
|
|
|
|
HeapFree(GetProcessHeap(), 0, req->lpszRemoteFile);
|
|
|
|
HeapFree(GetProcessHeap(), 0, req->lpszNewFile);
|
|
|
|
}
|
|
|
|
|
2007-02-20 15:52:01 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FtpGetFileW (WININET.@)
|
|
|
|
*
|
|
|
|
* Retrieve file from the FTP server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2004-05-25 06:02:05 +02:00
|
|
|
BOOL WINAPI FtpGetFileW(HINTERNET hInternet, LPCWSTR lpszRemoteFile, LPCWSTR lpszNewFile,
|
|
|
|
BOOL fFailIfExists, DWORD dwLocalFlagsAttribute, DWORD dwInternetFlags,
|
2007-08-30 16:21:33 +02:00
|
|
|
DWORD_PTR dwContext)
|
2004-05-25 06:02:05 +02:00
|
|
|
{
|
2009-07-13 01:45:53 +02:00
|
|
|
ftp_session_t *lpwfs;
|
2009-07-13 01:45:06 +02:00
|
|
|
appinfo_t *hIC = NULL;
|
2004-07-19 23:49:39 +02:00
|
|
|
BOOL r = FALSE;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2007-02-12 11:33:26 +01:00
|
|
|
if (!lpszRemoteFile || !lpszNewFile)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-02-02 22:50:31 +01:00
|
|
|
lpwfs = (ftp_session_t*) get_handle_object( hInternet );
|
2007-02-12 11:33:26 +01:00
|
|
|
if (!lpwfs)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WH_HFTPSESSION != lpwfs->hdr.htype)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
|
2004-07-19 23:49:39 +02:00
|
|
|
goto lend;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
2007-02-12 11:33:26 +01:00
|
|
|
if ((dwInternetFlags & FTP_CONDITION_MASK) > FTP_TRANSFER_TYPE_BINARY)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
2007-10-26 23:19:05 +02:00
|
|
|
if (lpwfs->download_in_progress != NULL)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
|
2004-07-19 23:49:39 +02:00
|
|
|
goto lend;
|
2003-07-22 00:04:14 +02:00
|
|
|
}
|
|
|
|
|
2006-10-29 18:52:47 +01:00
|
|
|
hIC = lpwfs->lpAppInfo;
|
2000-04-11 22:07:00 +02:00
|
|
|
if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
|
|
|
|
{
|
|
|
|
WORKREQUEST workRequest;
|
2004-05-25 06:02:05 +02:00
|
|
|
struct WORKREQ_FTPGETFILEW *req;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2006-12-25 21:35:46 +01:00
|
|
|
workRequest.asyncproc = AsyncFtpGetFileProc;
|
|
|
|
workRequest.hdr = WININET_AddRef( &lpwfs->hdr );
|
2004-05-25 06:02:05 +02:00
|
|
|
req = &workRequest.u.FtpGetFileW;
|
2009-07-17 01:10:41 +02:00
|
|
|
req->lpszRemoteFile = heap_strdupW(lpszRemoteFile);
|
|
|
|
req->lpszNewFile = heap_strdupW(lpszNewFile);
|
2003-09-25 22:25:22 +02:00
|
|
|
req->dwLocalFlagsAttribute = dwLocalFlagsAttribute;
|
|
|
|
req->fFailIfExists = fFailIfExists;
|
|
|
|
req->dwFlags = dwInternetFlags;
|
|
|
|
req->dwContext = dwContext;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2009-12-21 13:57:49 +01:00
|
|
|
r = res_to_le(INTERNET_AsyncCall(&workRequest));
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-07-19 23:49:39 +02:00
|
|
|
r = FTP_FtpGetFileW(lpwfs, lpszRemoteFile, lpszNewFile,
|
2000-04-11 22:07:00 +02:00
|
|
|
fFailIfExists, dwLocalFlagsAttribute, dwInternetFlags, dwContext);
|
|
|
|
}
|
2004-07-19 23:49:39 +02:00
|
|
|
|
|
|
|
lend:
|
2007-02-12 11:33:26 +01:00
|
|
|
WININET_Release( &lpwfs->hdr );
|
2004-07-19 23:49:39 +02:00
|
|
|
|
|
|
|
return r;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-10-28 19:48:24 +01:00
|
|
|
/***********************************************************************
|
2004-05-25 06:02:05 +02:00
|
|
|
* FTP_FtpGetFileW (Internal)
|
2002-10-28 19:48:24 +01:00
|
|
|
*
|
|
|
|
* Retrieve file from the FTP server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2009-07-13 01:45:53 +02:00
|
|
|
static BOOL FTP_FtpGetFileW(ftp_session_t *lpwfs, LPCWSTR lpszRemoteFile, LPCWSTR lpszNewFile,
|
2000-04-11 22:07:00 +02:00
|
|
|
BOOL fFailIfExists, DWORD dwLocalFlagsAttribute, DWORD dwInternetFlags,
|
2007-08-30 16:21:33 +02:00
|
|
|
DWORD_PTR dwContext)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
BOOL bSuccess = FALSE;
|
|
|
|
HANDLE hFile;
|
2009-07-13 01:45:06 +02:00
|
|
|
appinfo_t *hIC = NULL;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
TRACE("lpszRemoteFile(%s) lpszNewFile(%s)\n", debugstr_w(lpszRemoteFile), debugstr_w(lpszNewFile));
|
2004-02-07 02:03:41 +01:00
|
|
|
|
2000-04-11 22:07:00 +02:00
|
|
|
/* Clear any error information */
|
|
|
|
INTERNET_SetLastError(0);
|
|
|
|
|
|
|
|
/* Ensure we can write to lpszNewfile by opening it */
|
2004-05-25 06:02:05 +02:00
|
|
|
hFile = CreateFileW(lpszNewFile, GENERIC_WRITE, 0, 0, fFailIfExists ?
|
2000-04-11 22:07:00 +02:00
|
|
|
CREATE_NEW : CREATE_ALWAYS, dwLocalFlagsAttribute, 0);
|
|
|
|
if (INVALID_HANDLE_VALUE == hFile)
|
2007-03-20 18:30:35 +01:00
|
|
|
return FALSE;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
/* Set up socket to retrieve data */
|
2007-09-17 12:56:48 +02:00
|
|
|
if (FTP_SendRetrieve(lpwfs, lpszRemoteFile, dwInternetFlags))
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INT nDataSocket;
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
/* Get data socket to server */
|
|
|
|
if (FTP_GetDataSocket(lpwfs, &nDataSocket))
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INT nResCode;
|
|
|
|
|
|
|
|
/* Receive data */
|
2007-09-17 12:56:48 +02:00
|
|
|
FTP_RetrieveFileData(lpwfs, nDataSocket, hFile);
|
2007-10-26 23:19:38 +02:00
|
|
|
closesocket(nDataSocket);
|
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
nResCode = FTP_ReceiveResponse(lpwfs, dwContext);
|
2000-04-11 22:07:00 +02:00
|
|
|
if (nResCode)
|
|
|
|
{
|
|
|
|
if (nResCode == 226)
|
|
|
|
bSuccess = TRUE;
|
2007-10-26 23:19:38 +02:00
|
|
|
else
|
2000-04-11 22:07:00 +02:00
|
|
|
FTP_SetResponseError(nResCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-24 21:13:36 +02:00
|
|
|
if (lpwfs->lstnSocket != -1)
|
2009-09-16 17:22:31 +02:00
|
|
|
{
|
2004-09-03 20:57:19 +02:00
|
|
|
closesocket(lpwfs->lstnSocket);
|
2009-09-16 17:22:31 +02:00
|
|
|
lpwfs->lstnSocket = -1;
|
|
|
|
}
|
2000-12-29 06:19:57 +01:00
|
|
|
|
2007-03-20 18:30:35 +01:00
|
|
|
CloseHandle(hFile);
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2006-10-29 18:52:47 +01:00
|
|
|
hIC = lpwfs->lpAppInfo;
|
2004-09-20 21:10:31 +02:00
|
|
|
if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INTERNET_ASYNC_RESULT iar;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-04-11 22:07:00 +02:00
|
|
|
iar.dwResult = (DWORD)bSuccess;
|
|
|
|
iar.dwError = bSuccess ? ERROR_SUCCESS : INTERNET_GetLastError();
|
2004-09-20 21:10:31 +02:00
|
|
|
SendAsyncCallback(&lpwfs->hdr, lpwfs->hdr.dwContext, INTERNET_STATUS_REQUEST_COMPLETE,
|
2000-04-11 22:07:00 +02:00
|
|
|
&iar, sizeof(INTERNET_ASYNC_RESULT));
|
|
|
|
}
|
|
|
|
|
2008-07-19 19:53:19 +02:00
|
|
|
if (!bSuccess) DeleteFileW(lpszNewFile);
|
2000-04-11 22:07:00 +02:00
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
2005-04-20 17:18:42 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* FtpGetFileSize (WININET.@)
|
|
|
|
*/
|
- Stub implementations for FtpGetFileSize, FtpCommand{A,W},
HttpSendRequestExW, InternetGetLastResponseInfoW,
InternetConfirmZoneCrossing{A,W}, InternetDial{A,W},
InternetGoOnline{A,W}, InternetHangUp, CreateMD5SSOHash,
InternetClearAllPerSiteCookieDecisions,
InternetEnumPerSiteCookieDecision{A,W}, InternetGetCookieEx{A,W},
InternetGetPerSiteCookieDecision{A,W},
InternetSetPerSiteCookieDecision{A,W}, InternetSetCookieEx{A,W},
ResumeSuspendedDownload, RetrieveUrlCacheEntryFileW,
UnlockUrlCacheEntryFileW, {Create,Delete}UrlCacheEntryW,
CommitUrlCacheEntryW, RetrieveUrlCacheEntryStreamW,
FindCloseUrlCache, FindFirstUrlCacheEntryEx{A,W},
FindFirstUrlCacheGroup, FindNextUrlCacheEntry{,Ex}{A,W},
FindNextUrlCacheGroup, SetUrlCacheEntryGroup{A,W},
{Get,Set}UrlCacheGroupAttribute{A,W}, SetUrlCacheConfigInfo{A,W}.
- Spec file stubs for new undocumented functions
ForceNexusLookup{,ExW}, Ftp{Get,Put}FileEx, HttpCheckDavCompliance,
InternetAlgIdToString{A,W}, InternetFortezzaCommand,
InternetGetCertByURLA, InternetQueryFortezzaStatus,
InternetSecurityProtocolToString{A,W}, InternetSetDialState{A,W},
InternetShowSecurityInfoByURL{A,W}, IsUrlCacheEntryExpired{A,W},
Privacy{Get,Set}ZonePreferenceW, RegisterUrlCacheNotification,
UrlZonesDetach.
- Use memcpy instead of strncpy in InternetGetLastResponseInfoA.
- Add and improve some traces.
- Fix my own coding style in InternetTimeToSystemTimeW.
- Fix a couple of signedness warnings.
2005-02-01 19:50:53 +01:00
|
|
|
DWORD WINAPI FtpGetFileSize( HINTERNET hFile, LPDWORD lpdwFileSizeHigh )
|
|
|
|
{
|
|
|
|
FIXME("(%p, %p)\n", hFile, lpdwFileSizeHigh);
|
|
|
|
|
|
|
|
if (lpdwFileSizeHigh)
|
|
|
|
*lpdwFileSizeHigh = 0;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* FtpDeleteFileA (WININET.@)
|
2000-04-11 22:07:00 +02:00
|
|
|
*
|
|
|
|
* Delete a file on the ftp server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2000-04-15 22:44:21 +02:00
|
|
|
BOOL WINAPI FtpDeleteFileA(HINTERNET hFtpSession, LPCSTR lpszFileName)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
2004-05-25 06:02:05 +02:00
|
|
|
LPWSTR lpwzFileName;
|
|
|
|
BOOL ret;
|
|
|
|
|
2009-07-17 01:11:24 +02:00
|
|
|
lpwzFileName = heap_strdupAtoW(lpszFileName);
|
2004-05-25 06:02:05 +02:00
|
|
|
ret = FtpDeleteFileW(hFtpSession, lpwzFileName);
|
2004-12-21 15:42:35 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpwzFileName);
|
2004-05-25 06:02:05 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-12-25 21:36:01 +01:00
|
|
|
static void AsyncFtpDeleteFileProc(WORKREQUEST *workRequest)
|
|
|
|
{
|
|
|
|
struct WORKREQ_FTPDELETEFILEW const *req = &workRequest->u.FtpDeleteFileW;
|
2009-07-13 01:45:53 +02:00
|
|
|
ftp_session_t *lpwfs = (ftp_session_t*) workRequest->hdr;
|
2006-12-25 21:36:01 +01:00
|
|
|
|
|
|
|
TRACE("%p\n", lpwfs);
|
|
|
|
|
|
|
|
FTP_FtpDeleteFileW(lpwfs, req->lpszFilename);
|
|
|
|
HeapFree(GetProcessHeap(), 0, req->lpszFilename);
|
|
|
|
}
|
|
|
|
|
2007-02-20 15:52:01 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* FtpDeleteFileW (WININET.@)
|
|
|
|
*
|
|
|
|
* Delete a file on the ftp server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2004-05-25 06:02:05 +02:00
|
|
|
BOOL WINAPI FtpDeleteFileW(HINTERNET hFtpSession, LPCWSTR lpszFileName)
|
|
|
|
{
|
2009-07-13 01:45:53 +02:00
|
|
|
ftp_session_t *lpwfs;
|
2009-07-13 01:45:06 +02:00
|
|
|
appinfo_t *hIC = NULL;
|
2004-07-19 23:49:39 +02:00
|
|
|
BOOL r = FALSE;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2011-02-02 22:50:31 +01:00
|
|
|
lpwfs = (ftp_session_t*) get_handle_object( hFtpSession );
|
2007-02-09 21:17:27 +01:00
|
|
|
if (!lpwfs)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WH_HFTPSESSION != lpwfs->hdr.htype)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
|
2004-07-19 23:49:39 +02:00
|
|
|
goto lend;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
2007-10-26 23:19:05 +02:00
|
|
|
if (lpwfs->download_in_progress != NULL)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
2007-02-09 21:17:27 +01:00
|
|
|
if (!lpszFileName)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
2006-10-29 18:52:47 +01:00
|
|
|
hIC = lpwfs->lpAppInfo;
|
2000-04-11 22:07:00 +02:00
|
|
|
if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
|
|
|
|
{
|
|
|
|
WORKREQUEST workRequest;
|
2004-05-25 06:02:05 +02:00
|
|
|
struct WORKREQ_FTPDELETEFILEW *req;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2006-12-25 21:36:01 +01:00
|
|
|
workRequest.asyncproc = AsyncFtpDeleteFileProc;
|
|
|
|
workRequest.hdr = WININET_AddRef( &lpwfs->hdr );
|
2004-05-25 06:02:05 +02:00
|
|
|
req = &workRequest.u.FtpDeleteFileW;
|
2009-07-17 01:10:41 +02:00
|
|
|
req->lpszFilename = heap_strdupW(lpszFileName);
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2009-12-21 13:57:49 +01:00
|
|
|
r = res_to_le(INTERNET_AsyncCall(&workRequest));
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-07-19 22:33:17 +02:00
|
|
|
r = FTP_FtpDeleteFileW(lpwfs, lpszFileName);
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
2004-07-19 23:49:39 +02:00
|
|
|
|
|
|
|
lend:
|
2007-02-09 21:17:27 +01:00
|
|
|
WININET_Release( &lpwfs->hdr );
|
2004-07-19 23:49:39 +02:00
|
|
|
|
|
|
|
return r;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2004-05-25 06:02:05 +02:00
|
|
|
* FTP_FtpDeleteFileW (Internal)
|
2000-04-11 22:07:00 +02:00
|
|
|
*
|
|
|
|
* Delete a file on the ftp server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2009-07-13 01:45:53 +02:00
|
|
|
BOOL FTP_FtpDeleteFileW(ftp_session_t *lpwfs, LPCWSTR lpszFileName)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INT nResCode;
|
|
|
|
BOOL bSuccess = FALSE;
|
2009-07-13 01:45:06 +02:00
|
|
|
appinfo_t *hIC = NULL;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2004-07-19 23:49:39 +02:00
|
|
|
TRACE("%p\n", lpwfs);
|
2004-02-07 02:03:41 +01:00
|
|
|
|
2000-04-11 22:07:00 +02:00
|
|
|
/* Clear any error information */
|
|
|
|
INTERNET_SetLastError(0);
|
|
|
|
|
|
|
|
if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_DELE, lpszFileName, 0, 0, 0))
|
|
|
|
goto lend;
|
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
|
2000-04-11 22:07:00 +02:00
|
|
|
if (nResCode)
|
|
|
|
{
|
|
|
|
if (nResCode == 250)
|
|
|
|
bSuccess = TRUE;
|
|
|
|
else
|
|
|
|
FTP_SetResponseError(nResCode);
|
|
|
|
}
|
|
|
|
lend:
|
2006-10-29 18:52:47 +01:00
|
|
|
hIC = lpwfs->lpAppInfo;
|
2004-09-20 21:10:31 +02:00
|
|
|
if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INTERNET_ASYNC_RESULT iar;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-04-11 22:07:00 +02:00
|
|
|
iar.dwResult = (DWORD)bSuccess;
|
|
|
|
iar.dwError = bSuccess ? ERROR_SUCCESS : INTERNET_GetLastError();
|
2004-09-20 21:10:31 +02:00
|
|
|
SendAsyncCallback(&lpwfs->hdr, lpwfs->hdr.dwContext, INTERNET_STATUS_REQUEST_COMPLETE,
|
2000-04-11 22:07:00 +02:00
|
|
|
&iar, sizeof(INTERNET_ASYNC_RESULT));
|
|
|
|
}
|
|
|
|
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* FtpRemoveDirectoryA (WININET.@)
|
2000-04-11 22:07:00 +02:00
|
|
|
*
|
|
|
|
* Remove a directory on the ftp server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2000-04-15 22:44:21 +02:00
|
|
|
BOOL WINAPI FtpRemoveDirectoryA(HINTERNET hFtpSession, LPCSTR lpszDirectory)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
2004-05-25 06:02:05 +02:00
|
|
|
LPWSTR lpwzDirectory;
|
|
|
|
BOOL ret;
|
|
|
|
|
2009-07-17 01:11:24 +02:00
|
|
|
lpwzDirectory = heap_strdupAtoW(lpszDirectory);
|
2004-05-25 06:02:05 +02:00
|
|
|
ret = FtpRemoveDirectoryW(hFtpSession, lpwzDirectory);
|
2004-12-21 15:42:35 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpwzDirectory);
|
2004-05-25 06:02:05 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-12-25 21:36:15 +01:00
|
|
|
static void AsyncFtpRemoveDirectoryProc(WORKREQUEST *workRequest)
|
|
|
|
{
|
|
|
|
struct WORKREQ_FTPREMOVEDIRECTORYW const *req = &workRequest->u.FtpRemoveDirectoryW;
|
2009-07-13 01:45:53 +02:00
|
|
|
ftp_session_t *lpwfs = (ftp_session_t*) workRequest->hdr;
|
2006-12-25 21:36:15 +01:00
|
|
|
|
|
|
|
TRACE("%p\n", lpwfs);
|
|
|
|
|
|
|
|
FTP_FtpRemoveDirectoryW(lpwfs, req->lpszDirectory);
|
|
|
|
HeapFree(GetProcessHeap(), 0, req->lpszDirectory);
|
|
|
|
}
|
|
|
|
|
2007-02-20 15:52:01 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* FtpRemoveDirectoryW (WININET.@)
|
|
|
|
*
|
|
|
|
* Remove a directory on the ftp server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2004-05-25 06:02:05 +02:00
|
|
|
BOOL WINAPI FtpRemoveDirectoryW(HINTERNET hFtpSession, LPCWSTR lpszDirectory)
|
|
|
|
{
|
2009-07-13 01:45:53 +02:00
|
|
|
ftp_session_t *lpwfs;
|
2009-07-13 01:45:06 +02:00
|
|
|
appinfo_t *hIC = NULL;
|
2004-07-19 23:49:39 +02:00
|
|
|
BOOL r = FALSE;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2011-02-02 22:50:31 +01:00
|
|
|
lpwfs = (ftp_session_t*) get_handle_object( hFtpSession );
|
2007-02-10 17:23:15 +01:00
|
|
|
if (!lpwfs)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WH_HFTPSESSION != lpwfs->hdr.htype)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
|
2004-07-19 23:49:39 +02:00
|
|
|
goto lend;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
2007-10-26 23:19:05 +02:00
|
|
|
if (lpwfs->download_in_progress != NULL)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
2007-02-10 17:23:15 +01:00
|
|
|
if (!lpszDirectory)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
2006-10-29 18:52:47 +01:00
|
|
|
hIC = lpwfs->lpAppInfo;
|
2000-04-11 22:07:00 +02:00
|
|
|
if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
|
|
|
|
{
|
|
|
|
WORKREQUEST workRequest;
|
2004-05-25 06:02:05 +02:00
|
|
|
struct WORKREQ_FTPREMOVEDIRECTORYW *req;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2006-12-25 21:36:15 +01:00
|
|
|
workRequest.asyncproc = AsyncFtpRemoveDirectoryProc;
|
|
|
|
workRequest.hdr = WININET_AddRef( &lpwfs->hdr );
|
2004-05-25 06:02:05 +02:00
|
|
|
req = &workRequest.u.FtpRemoveDirectoryW;
|
2009-07-17 01:10:41 +02:00
|
|
|
req->lpszDirectory = heap_strdupW(lpszDirectory);
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2009-12-21 13:57:49 +01:00
|
|
|
r = res_to_le(INTERNET_AsyncCall(&workRequest));
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-07-19 23:49:39 +02:00
|
|
|
r = FTP_FtpRemoveDirectoryW(lpwfs, lpszDirectory);
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
2004-07-19 23:49:39 +02:00
|
|
|
|
|
|
|
lend:
|
2007-02-10 17:23:15 +01:00
|
|
|
WININET_Release( &lpwfs->hdr );
|
2004-07-19 23:49:39 +02:00
|
|
|
|
|
|
|
return r;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2004-05-25 06:02:05 +02:00
|
|
|
* FTP_FtpRemoveDirectoryW (Internal)
|
2000-04-11 22:07:00 +02:00
|
|
|
*
|
|
|
|
* Remove a directory on the ftp server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2009-07-13 01:45:53 +02:00
|
|
|
BOOL FTP_FtpRemoveDirectoryW(ftp_session_t *lpwfs, LPCWSTR lpszDirectory)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INT nResCode;
|
|
|
|
BOOL bSuccess = FALSE;
|
2009-07-13 01:45:06 +02:00
|
|
|
appinfo_t *hIC = NULL;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
2004-02-07 02:03:41 +01:00
|
|
|
|
2000-04-11 22:07:00 +02:00
|
|
|
/* Clear any error information */
|
|
|
|
INTERNET_SetLastError(0);
|
|
|
|
|
|
|
|
if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_RMD, lpszDirectory, 0, 0, 0))
|
|
|
|
goto lend;
|
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
|
2000-04-11 22:07:00 +02:00
|
|
|
if (nResCode)
|
|
|
|
{
|
|
|
|
if (nResCode == 250)
|
|
|
|
bSuccess = TRUE;
|
|
|
|
else
|
|
|
|
FTP_SetResponseError(nResCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
lend:
|
2006-10-29 18:52:47 +01:00
|
|
|
hIC = lpwfs->lpAppInfo;
|
2004-09-20 21:10:31 +02:00
|
|
|
if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INTERNET_ASYNC_RESULT iar;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-04-11 22:07:00 +02:00
|
|
|
iar.dwResult = (DWORD)bSuccess;
|
|
|
|
iar.dwError = bSuccess ? ERROR_SUCCESS : INTERNET_GetLastError();
|
2004-09-20 21:10:31 +02:00
|
|
|
SendAsyncCallback(&lpwfs->hdr, lpwfs->hdr.dwContext, INTERNET_STATUS_REQUEST_COMPLETE,
|
2000-04-11 22:07:00 +02:00
|
|
|
&iar, sizeof(INTERNET_ASYNC_RESULT));
|
|
|
|
}
|
|
|
|
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2001-06-19 20:20:47 +02:00
|
|
|
* FtpRenameFileA (WININET.@)
|
2000-04-11 22:07:00 +02:00
|
|
|
*
|
|
|
|
* Rename a file on the ftp server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2000-04-15 22:44:21 +02:00
|
|
|
BOOL WINAPI FtpRenameFileA(HINTERNET hFtpSession, LPCSTR lpszSrc, LPCSTR lpszDest)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
2004-05-25 06:02:05 +02:00
|
|
|
LPWSTR lpwzSrc;
|
|
|
|
LPWSTR lpwzDest;
|
|
|
|
BOOL ret;
|
|
|
|
|
2009-07-17 01:11:24 +02:00
|
|
|
lpwzSrc = heap_strdupAtoW(lpszSrc);
|
|
|
|
lpwzDest = heap_strdupAtoW(lpszDest);
|
2004-05-25 06:02:05 +02:00
|
|
|
ret = FtpRenameFileW(hFtpSession, lpwzSrc, lpwzDest);
|
2004-12-21 15:42:35 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpwzSrc);
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwzDest);
|
2004-05-25 06:02:05 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-12-25 21:36:30 +01:00
|
|
|
static void AsyncFtpRenameFileProc(WORKREQUEST *workRequest)
|
|
|
|
{
|
|
|
|
struct WORKREQ_FTPRENAMEFILEW const *req = &workRequest->u.FtpRenameFileW;
|
2009-07-13 01:45:53 +02:00
|
|
|
ftp_session_t *lpwfs = (ftp_session_t*) workRequest->hdr;
|
2006-12-25 21:36:30 +01:00
|
|
|
|
|
|
|
TRACE("%p\n", lpwfs);
|
|
|
|
|
|
|
|
FTP_FtpRenameFileW(lpwfs, req->lpszSrcFile, req->lpszDestFile);
|
|
|
|
HeapFree(GetProcessHeap(), 0, req->lpszSrcFile);
|
|
|
|
HeapFree(GetProcessHeap(), 0, req->lpszDestFile);
|
|
|
|
}
|
|
|
|
|
2007-02-20 15:52:01 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* FtpRenameFileW (WININET.@)
|
|
|
|
*
|
|
|
|
* Rename a file on the ftp server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2004-05-25 06:02:05 +02:00
|
|
|
BOOL WINAPI FtpRenameFileW(HINTERNET hFtpSession, LPCWSTR lpszSrc, LPCWSTR lpszDest)
|
|
|
|
{
|
2009-07-13 01:45:53 +02:00
|
|
|
ftp_session_t *lpwfs;
|
2009-07-13 01:45:06 +02:00
|
|
|
appinfo_t *hIC = NULL;
|
2004-07-19 23:49:39 +02:00
|
|
|
BOOL r = FALSE;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2011-02-02 22:50:31 +01:00
|
|
|
lpwfs = (ftp_session_t*) get_handle_object( hFtpSession );
|
2007-02-10 17:33:17 +01:00
|
|
|
if (!lpwfs)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WH_HFTPSESSION != lpwfs->hdr.htype)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
|
2004-07-19 23:49:39 +02:00
|
|
|
goto lend;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
2007-10-26 23:19:05 +02:00
|
|
|
if (lpwfs->download_in_progress != NULL)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
2007-02-10 17:33:17 +01:00
|
|
|
if (!lpszSrc || !lpszDest)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
2006-10-29 18:52:47 +01:00
|
|
|
hIC = lpwfs->lpAppInfo;
|
2000-04-11 22:07:00 +02:00
|
|
|
if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
|
|
|
|
{
|
|
|
|
WORKREQUEST workRequest;
|
2004-05-25 06:02:05 +02:00
|
|
|
struct WORKREQ_FTPRENAMEFILEW *req;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2006-12-25 21:36:30 +01:00
|
|
|
workRequest.asyncproc = AsyncFtpRenameFileProc;
|
|
|
|
workRequest.hdr = WININET_AddRef( &lpwfs->hdr );
|
2004-05-25 06:02:05 +02:00
|
|
|
req = &workRequest.u.FtpRenameFileW;
|
2009-07-17 01:10:41 +02:00
|
|
|
req->lpszSrcFile = heap_strdupW(lpszSrc);
|
|
|
|
req->lpszDestFile = heap_strdupW(lpszDest);
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2009-12-21 13:57:49 +01:00
|
|
|
r = res_to_le(INTERNET_AsyncCall(&workRequest));
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-07-19 12:06:07 +02:00
|
|
|
r = FTP_FtpRenameFileW(lpwfs, lpszSrc, lpszDest);
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
2004-07-19 23:49:39 +02:00
|
|
|
|
|
|
|
lend:
|
2007-02-10 17:33:17 +01:00
|
|
|
WININET_Release( &lpwfs->hdr );
|
2004-07-19 23:49:39 +02:00
|
|
|
|
|
|
|
return r;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2006-07-04 20:06:58 +02:00
|
|
|
* FTP_FtpRenameFileW (Internal)
|
2000-04-11 22:07:00 +02:00
|
|
|
*
|
|
|
|
* Rename a file on the ftp server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2009-07-13 01:45:53 +02:00
|
|
|
BOOL FTP_FtpRenameFileW(ftp_session_t *lpwfs, LPCWSTR lpszSrc, LPCWSTR lpszDest)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INT nResCode;
|
|
|
|
BOOL bSuccess = FALSE;
|
2009-07-13 01:45:06 +02:00
|
|
|
appinfo_t *hIC = NULL;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
2004-02-07 02:03:41 +01:00
|
|
|
|
2000-04-11 22:07:00 +02:00
|
|
|
/* Clear any error information */
|
|
|
|
INTERNET_SetLastError(0);
|
|
|
|
|
|
|
|
if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_RNFR, lpszSrc, 0, 0, 0))
|
|
|
|
goto lend;
|
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
|
2000-04-11 22:07:00 +02:00
|
|
|
if (nResCode == 350)
|
|
|
|
{
|
|
|
|
if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_RNTO, lpszDest, 0, 0, 0))
|
|
|
|
goto lend;
|
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (nResCode == 250)
|
|
|
|
bSuccess = TRUE;
|
|
|
|
else
|
|
|
|
FTP_SetResponseError(nResCode);
|
|
|
|
|
|
|
|
lend:
|
2006-10-29 18:52:47 +01:00
|
|
|
hIC = lpwfs->lpAppInfo;
|
2004-09-20 21:10:31 +02:00
|
|
|
if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INTERNET_ASYNC_RESULT iar;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-04-11 22:07:00 +02:00
|
|
|
iar.dwResult = (DWORD)bSuccess;
|
|
|
|
iar.dwError = bSuccess ? ERROR_SUCCESS : INTERNET_GetLastError();
|
2004-09-20 21:10:31 +02:00
|
|
|
SendAsyncCallback(&lpwfs->hdr, lpwfs->hdr.dwContext, INTERNET_STATUS_REQUEST_COMPLETE,
|
2000-04-11 22:07:00 +02:00
|
|
|
&iar, sizeof(INTERNET_ASYNC_RESULT));
|
|
|
|
}
|
|
|
|
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
2005-04-20 17:18:42 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* FtpCommandA (WININET.@)
|
|
|
|
*/
|
- Stub implementations for FtpGetFileSize, FtpCommand{A,W},
HttpSendRequestExW, InternetGetLastResponseInfoW,
InternetConfirmZoneCrossing{A,W}, InternetDial{A,W},
InternetGoOnline{A,W}, InternetHangUp, CreateMD5SSOHash,
InternetClearAllPerSiteCookieDecisions,
InternetEnumPerSiteCookieDecision{A,W}, InternetGetCookieEx{A,W},
InternetGetPerSiteCookieDecision{A,W},
InternetSetPerSiteCookieDecision{A,W}, InternetSetCookieEx{A,W},
ResumeSuspendedDownload, RetrieveUrlCacheEntryFileW,
UnlockUrlCacheEntryFileW, {Create,Delete}UrlCacheEntryW,
CommitUrlCacheEntryW, RetrieveUrlCacheEntryStreamW,
FindCloseUrlCache, FindFirstUrlCacheEntryEx{A,W},
FindFirstUrlCacheGroup, FindNextUrlCacheEntry{,Ex}{A,W},
FindNextUrlCacheGroup, SetUrlCacheEntryGroup{A,W},
{Get,Set}UrlCacheGroupAttribute{A,W}, SetUrlCacheConfigInfo{A,W}.
- Spec file stubs for new undocumented functions
ForceNexusLookup{,ExW}, Ftp{Get,Put}FileEx, HttpCheckDavCompliance,
InternetAlgIdToString{A,W}, InternetFortezzaCommand,
InternetGetCertByURLA, InternetQueryFortezzaStatus,
InternetSecurityProtocolToString{A,W}, InternetSetDialState{A,W},
InternetShowSecurityInfoByURL{A,W}, IsUrlCacheEntryExpired{A,W},
Privacy{Get,Set}ZonePreferenceW, RegisterUrlCacheNotification,
UrlZonesDetach.
- Use memcpy instead of strncpy in InternetGetLastResponseInfoA.
- Add and improve some traces.
- Fix my own coding style in InternetTimeToSystemTimeW.
- Fix a couple of signedness warnings.
2005-02-01 19:50:53 +01:00
|
|
|
BOOL WINAPI FtpCommandA( HINTERNET hConnect, BOOL fExpectResponse, DWORD dwFlags,
|
|
|
|
LPCSTR lpszCommand, DWORD_PTR dwContext, HINTERNET* phFtpCommand )
|
|
|
|
{
|
2007-10-31 22:54:03 +01:00
|
|
|
BOOL r;
|
|
|
|
WCHAR *cmdW;
|
|
|
|
|
|
|
|
TRACE("%p %d 0x%08x %s 0x%08lx %p\n", hConnect, fExpectResponse, dwFlags,
|
- Stub implementations for FtpGetFileSize, FtpCommand{A,W},
HttpSendRequestExW, InternetGetLastResponseInfoW,
InternetConfirmZoneCrossing{A,W}, InternetDial{A,W},
InternetGoOnline{A,W}, InternetHangUp, CreateMD5SSOHash,
InternetClearAllPerSiteCookieDecisions,
InternetEnumPerSiteCookieDecision{A,W}, InternetGetCookieEx{A,W},
InternetGetPerSiteCookieDecision{A,W},
InternetSetPerSiteCookieDecision{A,W}, InternetSetCookieEx{A,W},
ResumeSuspendedDownload, RetrieveUrlCacheEntryFileW,
UnlockUrlCacheEntryFileW, {Create,Delete}UrlCacheEntryW,
CommitUrlCacheEntryW, RetrieveUrlCacheEntryStreamW,
FindCloseUrlCache, FindFirstUrlCacheEntryEx{A,W},
FindFirstUrlCacheGroup, FindNextUrlCacheEntry{,Ex}{A,W},
FindNextUrlCacheGroup, SetUrlCacheEntryGroup{A,W},
{Get,Set}UrlCacheGroupAttribute{A,W}, SetUrlCacheConfigInfo{A,W}.
- Spec file stubs for new undocumented functions
ForceNexusLookup{,ExW}, Ftp{Get,Put}FileEx, HttpCheckDavCompliance,
InternetAlgIdToString{A,W}, InternetFortezzaCommand,
InternetGetCertByURLA, InternetQueryFortezzaStatus,
InternetSecurityProtocolToString{A,W}, InternetSetDialState{A,W},
InternetShowSecurityInfoByURL{A,W}, IsUrlCacheEntryExpired{A,W},
Privacy{Get,Set}ZonePreferenceW, RegisterUrlCacheNotification,
UrlZonesDetach.
- Use memcpy instead of strncpy in InternetGetLastResponseInfoA.
- Add and improve some traces.
- Fix my own coding style in InternetTimeToSystemTimeW.
- Fix a couple of signedness warnings.
2005-02-01 19:50:53 +01:00
|
|
|
debugstr_a(lpszCommand), dwContext, phFtpCommand);
|
|
|
|
|
2007-10-31 22:54:03 +01:00
|
|
|
if (fExpectResponse)
|
|
|
|
{
|
|
|
|
FIXME("data connection not supported\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!lpszCommand || !lpszCommand[0])
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-07-17 01:11:24 +02:00
|
|
|
if (!(cmdW = heap_strdupAtoW(lpszCommand)))
|
2007-10-31 22:54:03 +01:00
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = FtpCommandW(hConnect, fExpectResponse, dwFlags, cmdW, dwContext, phFtpCommand);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, cmdW);
|
|
|
|
return r;
|
- Stub implementations for FtpGetFileSize, FtpCommand{A,W},
HttpSendRequestExW, InternetGetLastResponseInfoW,
InternetConfirmZoneCrossing{A,W}, InternetDial{A,W},
InternetGoOnline{A,W}, InternetHangUp, CreateMD5SSOHash,
InternetClearAllPerSiteCookieDecisions,
InternetEnumPerSiteCookieDecision{A,W}, InternetGetCookieEx{A,W},
InternetGetPerSiteCookieDecision{A,W},
InternetSetPerSiteCookieDecision{A,W}, InternetSetCookieEx{A,W},
ResumeSuspendedDownload, RetrieveUrlCacheEntryFileW,
UnlockUrlCacheEntryFileW, {Create,Delete}UrlCacheEntryW,
CommitUrlCacheEntryW, RetrieveUrlCacheEntryStreamW,
FindCloseUrlCache, FindFirstUrlCacheEntryEx{A,W},
FindFirstUrlCacheGroup, FindNextUrlCacheEntry{,Ex}{A,W},
FindNextUrlCacheGroup, SetUrlCacheEntryGroup{A,W},
{Get,Set}UrlCacheGroupAttribute{A,W}, SetUrlCacheConfigInfo{A,W}.
- Spec file stubs for new undocumented functions
ForceNexusLookup{,ExW}, Ftp{Get,Put}FileEx, HttpCheckDavCompliance,
InternetAlgIdToString{A,W}, InternetFortezzaCommand,
InternetGetCertByURLA, InternetQueryFortezzaStatus,
InternetSecurityProtocolToString{A,W}, InternetSetDialState{A,W},
InternetShowSecurityInfoByURL{A,W}, IsUrlCacheEntryExpired{A,W},
Privacy{Get,Set}ZonePreferenceW, RegisterUrlCacheNotification,
UrlZonesDetach.
- Use memcpy instead of strncpy in InternetGetLastResponseInfoA.
- Add and improve some traces.
- Fix my own coding style in InternetTimeToSystemTimeW.
- Fix a couple of signedness warnings.
2005-02-01 19:50:53 +01:00
|
|
|
}
|
|
|
|
|
2005-04-20 17:18:42 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* FtpCommandW (WININET.@)
|
|
|
|
*/
|
- Stub implementations for FtpGetFileSize, FtpCommand{A,W},
HttpSendRequestExW, InternetGetLastResponseInfoW,
InternetConfirmZoneCrossing{A,W}, InternetDial{A,W},
InternetGoOnline{A,W}, InternetHangUp, CreateMD5SSOHash,
InternetClearAllPerSiteCookieDecisions,
InternetEnumPerSiteCookieDecision{A,W}, InternetGetCookieEx{A,W},
InternetGetPerSiteCookieDecision{A,W},
InternetSetPerSiteCookieDecision{A,W}, InternetSetCookieEx{A,W},
ResumeSuspendedDownload, RetrieveUrlCacheEntryFileW,
UnlockUrlCacheEntryFileW, {Create,Delete}UrlCacheEntryW,
CommitUrlCacheEntryW, RetrieveUrlCacheEntryStreamW,
FindCloseUrlCache, FindFirstUrlCacheEntryEx{A,W},
FindFirstUrlCacheGroup, FindNextUrlCacheEntry{,Ex}{A,W},
FindNextUrlCacheGroup, SetUrlCacheEntryGroup{A,W},
{Get,Set}UrlCacheGroupAttribute{A,W}, SetUrlCacheConfigInfo{A,W}.
- Spec file stubs for new undocumented functions
ForceNexusLookup{,ExW}, Ftp{Get,Put}FileEx, HttpCheckDavCompliance,
InternetAlgIdToString{A,W}, InternetFortezzaCommand,
InternetGetCertByURLA, InternetQueryFortezzaStatus,
InternetSecurityProtocolToString{A,W}, InternetSetDialState{A,W},
InternetShowSecurityInfoByURL{A,W}, IsUrlCacheEntryExpired{A,W},
Privacy{Get,Set}ZonePreferenceW, RegisterUrlCacheNotification,
UrlZonesDetach.
- Use memcpy instead of strncpy in InternetGetLastResponseInfoA.
- Add and improve some traces.
- Fix my own coding style in InternetTimeToSystemTimeW.
- Fix a couple of signedness warnings.
2005-02-01 19:50:53 +01:00
|
|
|
BOOL WINAPI FtpCommandW( HINTERNET hConnect, BOOL fExpectResponse, DWORD dwFlags,
|
|
|
|
LPCWSTR lpszCommand, DWORD_PTR dwContext, HINTERNET* phFtpCommand )
|
|
|
|
{
|
2007-10-31 22:54:03 +01:00
|
|
|
BOOL r = FALSE;
|
2009-07-13 01:45:53 +02:00
|
|
|
ftp_session_t *lpwfs;
|
2007-10-31 22:54:03 +01:00
|
|
|
LPSTR cmd = NULL;
|
|
|
|
DWORD len, nBytesSent= 0;
|
|
|
|
INT nResCode, nRC = 0;
|
|
|
|
|
|
|
|
TRACE("%p %d 0x%08x %s 0x%08lx %p\n", hConnect, fExpectResponse, dwFlags,
|
|
|
|
debugstr_w(lpszCommand), dwContext, phFtpCommand);
|
- Stub implementations for FtpGetFileSize, FtpCommand{A,W},
HttpSendRequestExW, InternetGetLastResponseInfoW,
InternetConfirmZoneCrossing{A,W}, InternetDial{A,W},
InternetGoOnline{A,W}, InternetHangUp, CreateMD5SSOHash,
InternetClearAllPerSiteCookieDecisions,
InternetEnumPerSiteCookieDecision{A,W}, InternetGetCookieEx{A,W},
InternetGetPerSiteCookieDecision{A,W},
InternetSetPerSiteCookieDecision{A,W}, InternetSetCookieEx{A,W},
ResumeSuspendedDownload, RetrieveUrlCacheEntryFileW,
UnlockUrlCacheEntryFileW, {Create,Delete}UrlCacheEntryW,
CommitUrlCacheEntryW, RetrieveUrlCacheEntryStreamW,
FindCloseUrlCache, FindFirstUrlCacheEntryEx{A,W},
FindFirstUrlCacheGroup, FindNextUrlCacheEntry{,Ex}{A,W},
FindNextUrlCacheGroup, SetUrlCacheEntryGroup{A,W},
{Get,Set}UrlCacheGroupAttribute{A,W}, SetUrlCacheConfigInfo{A,W}.
- Spec file stubs for new undocumented functions
ForceNexusLookup{,ExW}, Ftp{Get,Put}FileEx, HttpCheckDavCompliance,
InternetAlgIdToString{A,W}, InternetFortezzaCommand,
InternetGetCertByURLA, InternetQueryFortezzaStatus,
InternetSecurityProtocolToString{A,W}, InternetSetDialState{A,W},
InternetShowSecurityInfoByURL{A,W}, IsUrlCacheEntryExpired{A,W},
Privacy{Get,Set}ZonePreferenceW, RegisterUrlCacheNotification,
UrlZonesDetach.
- Use memcpy instead of strncpy in InternetGetLastResponseInfoA.
- Add and improve some traces.
- Fix my own coding style in InternetTimeToSystemTimeW.
- Fix a couple of signedness warnings.
2005-02-01 19:50:53 +01:00
|
|
|
|
2007-10-31 22:54:03 +01:00
|
|
|
if (!lpszCommand || !lpszCommand[0])
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fExpectResponse)
|
|
|
|
{
|
|
|
|
FIXME("data connection not supported\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-02-02 22:50:31 +01:00
|
|
|
lpwfs = (ftp_session_t*) get_handle_object( hConnect );
|
2007-10-31 22:54:03 +01:00
|
|
|
if (!lpwfs)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WH_HFTPSESSION != lpwfs->hdr.htype)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lpwfs->download_in_progress != NULL)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
|
|
|
len = WideCharToMultiByte(CP_ACP, 0, lpszCommand, -1, NULL, 0, NULL, NULL) + strlen(szCRLF);
|
2011-04-21 13:39:03 +02:00
|
|
|
if ((cmd = heap_alloc(len)))
|
2007-10-31 22:54:03 +01:00
|
|
|
WideCharToMultiByte(CP_ACP, 0, lpszCommand, -1, cmd, len, NULL, NULL);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
|
|
|
strcat(cmd, szCRLF);
|
|
|
|
len--;
|
|
|
|
|
|
|
|
TRACE("Sending (%s) len(%d)\n", cmd, len);
|
|
|
|
while ((nBytesSent < len) && (nRC != -1))
|
|
|
|
{
|
|
|
|
nRC = send(lpwfs->sndSocket, cmd + nBytesSent, len - nBytesSent, 0);
|
|
|
|
if (nRC != -1)
|
|
|
|
{
|
|
|
|
nBytesSent += nRC;
|
|
|
|
TRACE("Sent %d bytes\n", nRC);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nBytesSent)
|
|
|
|
{
|
|
|
|
nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
|
|
|
|
if (nResCode > 0 && nResCode < 400)
|
|
|
|
r = TRUE;
|
|
|
|
else
|
|
|
|
FTP_SetResponseError(nResCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
lend:
|
|
|
|
WININET_Release( &lpwfs->hdr );
|
|
|
|
HeapFree(GetProcessHeap(), 0, cmd);
|
|
|
|
return r;
|
- Stub implementations for FtpGetFileSize, FtpCommand{A,W},
HttpSendRequestExW, InternetGetLastResponseInfoW,
InternetConfirmZoneCrossing{A,W}, InternetDial{A,W},
InternetGoOnline{A,W}, InternetHangUp, CreateMD5SSOHash,
InternetClearAllPerSiteCookieDecisions,
InternetEnumPerSiteCookieDecision{A,W}, InternetGetCookieEx{A,W},
InternetGetPerSiteCookieDecision{A,W},
InternetSetPerSiteCookieDecision{A,W}, InternetSetCookieEx{A,W},
ResumeSuspendedDownload, RetrieveUrlCacheEntryFileW,
UnlockUrlCacheEntryFileW, {Create,Delete}UrlCacheEntryW,
CommitUrlCacheEntryW, RetrieveUrlCacheEntryStreamW,
FindCloseUrlCache, FindFirstUrlCacheEntryEx{A,W},
FindFirstUrlCacheGroup, FindNextUrlCacheEntry{,Ex}{A,W},
FindNextUrlCacheGroup, SetUrlCacheEntryGroup{A,W},
{Get,Set}UrlCacheGroupAttribute{A,W}, SetUrlCacheConfigInfo{A,W}.
- Spec file stubs for new undocumented functions
ForceNexusLookup{,ExW}, Ftp{Get,Put}FileEx, HttpCheckDavCompliance,
InternetAlgIdToString{A,W}, InternetFortezzaCommand,
InternetGetCertByURLA, InternetQueryFortezzaStatus,
InternetSecurityProtocolToString{A,W}, InternetSetDialState{A,W},
InternetShowSecurityInfoByURL{A,W}, IsUrlCacheEntryExpired{A,W},
Privacy{Get,Set}ZonePreferenceW, RegisterUrlCacheNotification,
UrlZonesDetach.
- Use memcpy instead of strncpy in InternetGetLastResponseInfoA.
- Add and improve some traces.
- Fix my own coding style in InternetTimeToSystemTimeW.
- Fix a couple of signedness warnings.
2005-02-01 19:50:53 +01:00
|
|
|
}
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2008-02-26 20:20:41 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FTPSESSION_Destroy (internal)
|
|
|
|
*
|
|
|
|
* Deallocate session handle
|
|
|
|
*/
|
2009-07-07 21:46:09 +02:00
|
|
|
static void FTPSESSION_Destroy(object_header_t *hdr)
|
2008-02-26 20:20:41 +01:00
|
|
|
{
|
2009-07-13 01:45:53 +02:00
|
|
|
ftp_session_t *lpwfs = (ftp_session_t*) hdr;
|
2008-02-26 20:20:41 +01:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
WININET_Release(&lpwfs->lpAppInfo->hdr);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwfs->lpszPassword);
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpwfs->lpszUserName);
|
2009-12-01 17:00:39 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpwfs->servername);
|
2008-02-26 20:20:41 +01:00
|
|
|
}
|
|
|
|
|
2009-07-07 21:46:09 +02:00
|
|
|
static void FTPSESSION_CloseConnection(object_header_t *hdr)
|
2008-02-26 20:21:00 +01:00
|
|
|
{
|
2009-07-13 01:45:53 +02:00
|
|
|
ftp_session_t *lpwfs = (ftp_session_t*) hdr;
|
2008-02-26 20:21:00 +01:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
SendAsyncCallback(&lpwfs->hdr, lpwfs->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_CLOSING_CONNECTION, 0, 0);
|
|
|
|
|
|
|
|
if (lpwfs->download_in_progress != NULL)
|
|
|
|
lpwfs->download_in_progress->session_deleted = TRUE;
|
|
|
|
|
|
|
|
if (lpwfs->sndSocket != -1)
|
|
|
|
closesocket(lpwfs->sndSocket);
|
|
|
|
|
|
|
|
if (lpwfs->lstnSocket != -1)
|
|
|
|
closesocket(lpwfs->lstnSocket);
|
|
|
|
|
|
|
|
if (lpwfs->pasvSocket != -1)
|
|
|
|
closesocket(lpwfs->pasvSocket);
|
|
|
|
|
|
|
|
SendAsyncCallback(&lpwfs->hdr, lpwfs->hdr.dwContext,
|
|
|
|
INTERNET_STATUS_CONNECTION_CLOSED, 0, 0);
|
|
|
|
}
|
2008-02-26 20:20:41 +01:00
|
|
|
|
2009-07-07 21:46:09 +02:00
|
|
|
static DWORD FTPSESSION_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
|
2008-03-12 02:23:20 +01:00
|
|
|
{
|
|
|
|
switch(option) {
|
|
|
|
case INTERNET_OPTION_HANDLE_TYPE:
|
|
|
|
TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
|
|
|
|
|
|
|
|
if (*size < sizeof(ULONG))
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
|
|
|
|
*size = sizeof(DWORD);
|
|
|
|
*(DWORD*)buffer = INTERNET_HANDLE_TYPE_CONNECT_FTP;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2010-05-25 12:19:32 +02:00
|
|
|
return INET_QueryOption(hdr, option, buffer, size, unicode);
|
2008-03-12 02:23:20 +01:00
|
|
|
}
|
|
|
|
|
2009-07-07 21:46:09 +02:00
|
|
|
static const object_vtbl_t FTPSESSIONVtbl = {
|
2008-02-26 20:21:00 +01:00
|
|
|
FTPSESSION_Destroy,
|
2008-02-26 20:21:34 +01:00
|
|
|
FTPSESSION_CloseConnection,
|
2008-03-12 02:23:20 +01:00
|
|
|
FTPSESSION_QueryOption,
|
2008-02-26 20:22:02 +01:00
|
|
|
NULL,
|
2008-02-27 18:55:09 +01:00
|
|
|
NULL,
|
2008-02-29 12:57:57 +01:00
|
|
|
NULL,
|
2008-03-02 19:35:11 +01:00
|
|
|
NULL,
|
2008-03-03 18:07:20 +01:00
|
|
|
NULL,
|
2008-02-26 20:21:34 +01:00
|
|
|
NULL
|
2008-02-26 20:20:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-04-11 22:07:00 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* FTP_Connect (internal)
|
|
|
|
*
|
|
|
|
* Connect to a ftp server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* HINTERNET a session handle on success
|
|
|
|
* NULL on failure
|
|
|
|
*
|
2006-07-07 13:30:33 +02:00
|
|
|
* NOTES:
|
|
|
|
*
|
|
|
|
* Windows uses 'anonymous' as the username, when given a NULL username
|
|
|
|
* and a NULL password. The password is first looked up in:
|
|
|
|
*
|
|
|
|
* HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\EmailName
|
|
|
|
*
|
|
|
|
* If this entry is not present it uses the current username as the password.
|
|
|
|
*
|
2000-04-11 22:07:00 +02:00
|
|
|
*/
|
|
|
|
|
2009-07-13 01:45:06 +02:00
|
|
|
HINTERNET FTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName,
|
2004-03-30 06:36:09 +02:00
|
|
|
INTERNET_PORT nServerPort, LPCWSTR lpszUserName,
|
2007-08-30 16:21:33 +02:00
|
|
|
LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext,
|
2004-05-13 07:17:25 +02:00
|
|
|
DWORD dwInternalFlags)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
2006-07-07 13:30:33 +02:00
|
|
|
static const WCHAR szKey[] = {'S','o','f','t','w','a','r','e','\\',
|
|
|
|
'M','i','c','r','o','s','o','f','t','\\',
|
|
|
|
'W','i','n','d','o','w','s','\\',
|
|
|
|
'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
|
|
|
|
'I','n','t','e','r','n','e','t',' ','S','e','t','t','i','n','g','s',0};
|
|
|
|
static const WCHAR szValue[] = {'E','m','a','i','l','N','a','m','e',0};
|
2004-05-25 06:02:05 +02:00
|
|
|
static const WCHAR szDefaultUsername[] = {'a','n','o','n','y','m','o','u','s','\0'};
|
2006-07-03 23:09:03 +02:00
|
|
|
static const WCHAR szEmpty[] = {'\0'};
|
2000-04-11 22:07:00 +02:00
|
|
|
struct sockaddr_in socketAddr;
|
- Stub implementations for FtpGetFileSize, FtpCommand{A,W},
HttpSendRequestExW, InternetGetLastResponseInfoW,
InternetConfirmZoneCrossing{A,W}, InternetDial{A,W},
InternetGoOnline{A,W}, InternetHangUp, CreateMD5SSOHash,
InternetClearAllPerSiteCookieDecisions,
InternetEnumPerSiteCookieDecision{A,W}, InternetGetCookieEx{A,W},
InternetGetPerSiteCookieDecision{A,W},
InternetSetPerSiteCookieDecision{A,W}, InternetSetCookieEx{A,W},
ResumeSuspendedDownload, RetrieveUrlCacheEntryFileW,
UnlockUrlCacheEntryFileW, {Create,Delete}UrlCacheEntryW,
CommitUrlCacheEntryW, RetrieveUrlCacheEntryStreamW,
FindCloseUrlCache, FindFirstUrlCacheEntryEx{A,W},
FindFirstUrlCacheGroup, FindNextUrlCacheEntry{,Ex}{A,W},
FindNextUrlCacheGroup, SetUrlCacheEntryGroup{A,W},
{Get,Set}UrlCacheGroupAttribute{A,W}, SetUrlCacheConfigInfo{A,W}.
- Spec file stubs for new undocumented functions
ForceNexusLookup{,ExW}, Ftp{Get,Put}FileEx, HttpCheckDavCompliance,
InternetAlgIdToString{A,W}, InternetFortezzaCommand,
InternetGetCertByURLA, InternetQueryFortezzaStatus,
InternetSecurityProtocolToString{A,W}, InternetSetDialState{A,W},
InternetShowSecurityInfoByURL{A,W}, IsUrlCacheEntryExpired{A,W},
Privacy{Get,Set}ZonePreferenceW, RegisterUrlCacheNotification,
UrlZonesDetach.
- Use memcpy instead of strncpy in InternetGetLastResponseInfoA.
- Add and improve some traces.
- Fix my own coding style in InternetTimeToSystemTimeW.
- Fix a couple of signedness warnings.
2005-02-01 19:50:53 +01:00
|
|
|
INT nsocket = -1;
|
|
|
|
UINT sock_namelen;
|
2000-04-11 22:07:00 +02:00
|
|
|
BOOL bSuccess = FALSE;
|
2009-07-13 01:45:53 +02:00
|
|
|
ftp_session_t *lpwfs = NULL;
|
2009-12-04 13:25:14 +01:00
|
|
|
char szaddr[INET_ADDRSTRLEN];
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2004-07-19 23:49:39 +02:00
|
|
|
TRACE("%p Server(%s) Port(%d) User(%s) Paswd(%s)\n",
|
|
|
|
hIC, debugstr_w(lpszServerName),
|
2004-03-30 06:36:09 +02:00
|
|
|
nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword));
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2004-09-06 22:24:38 +02:00
|
|
|
assert( hIC->hdr.htype == WH_HINIT );
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2009-02-10 16:29:11 +01:00
|
|
|
if ((!lpszUserName || !*lpszUserName) && lpszPassword && *lpszPassword)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
2004-05-25 06:02:05 +02:00
|
|
|
INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
|
2011-02-02 22:51:13 +01:00
|
|
|
return NULL;
|
2004-05-25 06:02:05 +02:00
|
|
|
}
|
|
|
|
|
2011-02-02 22:51:13 +01:00
|
|
|
lpwfs = alloc_object(&hIC->hdr, &FTPSESSIONVtbl, sizeof(ftp_session_t));
|
2004-05-25 06:02:05 +02:00
|
|
|
if (NULL == lpwfs)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_OUTOFMEMORY);
|
2011-02-02 22:51:13 +01:00
|
|
|
return NULL;
|
2004-05-25 06:02:05 +02:00
|
|
|
}
|
|
|
|
|
2000-04-11 22:07:00 +02:00
|
|
|
if (nServerPort == INTERNET_INVALID_PORT_NUMBER)
|
2009-12-01 17:00:39 +01:00
|
|
|
lpwfs->serverport = INTERNET_DEFAULT_FTP_PORT;
|
|
|
|
else
|
|
|
|
lpwfs->serverport = nServerPort;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
lpwfs->hdr.htype = WH_HFTPSESSION;
|
|
|
|
lpwfs->hdr.dwFlags = dwFlags;
|
|
|
|
lpwfs->hdr.dwContext = dwContext;
|
2011-02-02 22:51:13 +01:00
|
|
|
lpwfs->hdr.dwInternalFlags |= dwInternalFlags;
|
2004-05-25 06:02:05 +02:00
|
|
|
lpwfs->download_in_progress = NULL;
|
2007-11-08 07:33:21 +01:00
|
|
|
lpwfs->sndSocket = -1;
|
|
|
|
lpwfs->lstnSocket = -1;
|
|
|
|
lpwfs->pasvSocket = -1;
|
2004-07-19 23:49:39 +02:00
|
|
|
|
2006-10-29 18:52:02 +01:00
|
|
|
WININET_AddRef( &hIC->hdr );
|
|
|
|
lpwfs->lpAppInfo = hIC;
|
2007-09-21 03:59:40 +02:00
|
|
|
list_add_head( &hIC->hdr.children, &lpwfs->hdr.entry );
|
2006-10-29 18:52:02 +01:00
|
|
|
|
2011-03-01 20:00:49 +01:00
|
|
|
if(hIC->proxy && hIC->accessType == INTERNET_OPEN_TYPE_PROXY) {
|
|
|
|
if(strchrW(hIC->proxy, ' '))
|
2004-05-25 06:02:05 +02:00
|
|
|
FIXME("Several proxies not implemented.\n");
|
2011-03-01 20:00:49 +01:00
|
|
|
if(hIC->proxyBypass)
|
2004-05-25 06:02:05 +02:00
|
|
|
FIXME("Proxy bypass is ignored.\n");
|
|
|
|
}
|
2008-11-18 09:27:59 +01:00
|
|
|
if (!lpszUserName || !strlenW(lpszUserName)) {
|
2006-07-07 13:30:33 +02:00
|
|
|
HKEY key;
|
|
|
|
WCHAR szPassword[MAX_PATH];
|
|
|
|
DWORD len = sizeof(szPassword);
|
|
|
|
|
2009-07-17 01:10:41 +02:00
|
|
|
lpwfs->lpszUserName = heap_strdupW(szDefaultUsername);
|
2006-07-07 13:30:33 +02:00
|
|
|
|
|
|
|
RegOpenKeyW(HKEY_CURRENT_USER, szKey, &key);
|
|
|
|
if (RegQueryValueExW(key, szValue, NULL, NULL, (LPBYTE)szPassword, &len)) {
|
|
|
|
/* Nothing in the registry, get the username and use that as the password */
|
|
|
|
if (!GetUserNameW(szPassword, &len)) {
|
|
|
|
/* Should never get here, but use an empty password as failsafe */
|
|
|
|
strcpyW(szPassword, szEmpty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RegCloseKey(key);
|
|
|
|
|
|
|
|
TRACE("Password used for anonymous ftp : (%s)\n", debugstr_w(szPassword));
|
2009-07-17 01:10:41 +02:00
|
|
|
lpwfs->lpszPassword = heap_strdupW(szPassword);
|
2004-05-25 06:02:05 +02:00
|
|
|
}
|
|
|
|
else {
|
2009-07-17 01:10:41 +02:00
|
|
|
lpwfs->lpszUserName = heap_strdupW(lpszUserName);
|
|
|
|
lpwfs->lpszPassword = heap_strdupW(lpszPassword ? lpszPassword : szEmpty);
|
2004-05-25 06:02:05 +02:00
|
|
|
}
|
2009-12-01 17:00:39 +01:00
|
|
|
lpwfs->servername = heap_strdupW(lpszServerName);
|
2004-05-25 06:02:05 +02:00
|
|
|
|
|
|
|
/* Don't send a handle created callback if this handle was created with InternetOpenUrl */
|
2004-09-20 21:10:31 +02:00
|
|
|
if (!(lpwfs->hdr.dwInternalFlags & INET_OPENURL))
|
2004-05-25 06:02:05 +02:00
|
|
|
{
|
|
|
|
INTERNET_ASYNC_RESULT iar;
|
|
|
|
|
2011-02-02 22:51:13 +01:00
|
|
|
iar.dwResult = (DWORD_PTR)lpwfs->hdr.hInternet;
|
2004-05-25 06:02:05 +02:00
|
|
|
iar.dwError = ERROR_SUCCESS;
|
|
|
|
|
2004-09-20 21:10:31 +02:00
|
|
|
SendAsyncCallback(&hIC->hdr, dwContext,
|
2004-05-25 06:02:05 +02:00
|
|
|
INTERNET_STATUS_HANDLE_CREATED, &iar,
|
|
|
|
sizeof(INTERNET_ASYNC_RESULT));
|
|
|
|
}
|
|
|
|
|
2004-09-20 21:10:31 +02:00
|
|
|
SendAsyncCallback(&hIC->hdr, dwContext, INTERNET_STATUS_RESOLVING_NAME,
|
2009-12-04 03:19:00 +01:00
|
|
|
(LPWSTR) lpszServerName, (strlenW(lpszServerName)+1) * sizeof(WCHAR));
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2009-07-09 19:53:08 +02:00
|
|
|
sock_namelen = sizeof(socketAddr);
|
2009-12-01 17:00:39 +01:00
|
|
|
if (!GetAddress(lpszServerName, lpwfs->serverport, (struct sockaddr *)&socketAddr, &sock_namelen))
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_NAME_NOT_RESOLVED);
|
|
|
|
goto lerror;
|
|
|
|
}
|
|
|
|
|
2009-07-09 20:45:48 +02:00
|
|
|
if (socketAddr.sin_family != AF_INET)
|
|
|
|
{
|
|
|
|
WARN("unsupported address family %d\n", socketAddr.sin_family);
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_CANNOT_CONNECT);
|
|
|
|
goto lerror;
|
|
|
|
}
|
2009-12-04 13:25:14 +01:00
|
|
|
|
|
|
|
inet_ntop(socketAddr.sin_family, &socketAddr.sin_addr, szaddr, sizeof(szaddr));
|
|
|
|
SendAsyncCallback(&hIC->hdr, dwContext, INTERNET_STATUS_NAME_RESOLVED,
|
|
|
|
szaddr, strlen(szaddr)+1);
|
|
|
|
|
2001-08-24 21:13:36 +02:00
|
|
|
nsocket = socket(AF_INET,SOCK_STREAM,0);
|
|
|
|
if (nsocket == -1)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_CANNOT_CONNECT);
|
|
|
|
goto lerror;
|
|
|
|
}
|
|
|
|
|
2004-09-20 21:10:31 +02:00
|
|
|
SendAsyncCallback(&hIC->hdr, dwContext, INTERNET_STATUS_CONNECTING_TO_SERVER,
|
2009-12-04 13:25:14 +01:00
|
|
|
szaddr, strlen(szaddr)+1);
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2009-07-09 20:01:44 +02:00
|
|
|
if (connect(nsocket, (struct sockaddr *)&socketAddr, sock_namelen) < 0)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
2000-08-26 22:31:48 +02:00
|
|
|
ERR("Unable to connect (%s)\n", strerror(errno));
|
2000-04-11 22:07:00 +02:00
|
|
|
INTERNET_SetLastError(ERROR_INTERNET_CANNOT_CONNECT);
|
2009-06-26 14:09:39 +02:00
|
|
|
closesocket(nsocket);
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-06-01 01:06:46 +02:00
|
|
|
TRACE("Connected to server\n");
|
2004-05-25 06:02:05 +02:00
|
|
|
lpwfs->sndSocket = nsocket;
|
2004-09-20 21:10:31 +02:00
|
|
|
SendAsyncCallback(&hIC->hdr, dwContext, INTERNET_STATUS_CONNECTED_TO_SERVER,
|
2009-12-04 13:25:14 +01:00
|
|
|
szaddr, strlen(szaddr)+1);
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2000-11-07 21:28:34 +01:00
|
|
|
sock_namelen = sizeof(lpwfs->socketAddress);
|
2000-11-25 04:09:30 +01:00
|
|
|
getsockname(nsocket, (struct sockaddr *) &lpwfs->socketAddress, &sock_namelen);
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
if (FTP_ConnectToHost(lpwfs))
|
|
|
|
{
|
|
|
|
TRACE("Successfully logged into server\n");
|
|
|
|
bSuccess = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lerror:
|
2011-02-02 22:51:13 +01:00
|
|
|
if (!bSuccess)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
2011-02-02 22:51:13 +01:00
|
|
|
if(lpwfs)
|
|
|
|
WININET_Release( &lpwfs->hdr );
|
|
|
|
return NULL;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
2011-02-02 22:51:13 +01:00
|
|
|
return lpwfs->hdr.hInternet;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2000-12-29 06:19:57 +01:00
|
|
|
* FTP_ConnectToHost (internal)
|
2000-04-11 22:07:00 +02:00
|
|
|
*
|
|
|
|
* Connect to a ftp server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* NULL on failure
|
|
|
|
*
|
|
|
|
*/
|
2009-07-13 01:45:53 +02:00
|
|
|
static BOOL FTP_ConnectToHost(ftp_session_t *lpwfs)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INT nResCode;
|
|
|
|
BOOL bSuccess = FALSE;
|
|
|
|
|
|
|
|
TRACE("\n");
|
2004-05-25 06:02:05 +02:00
|
|
|
FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_USER, lpwfs->lpszUserName, 0, 0, 0))
|
|
|
|
goto lend;
|
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
|
2000-04-11 22:07:00 +02:00
|
|
|
if (nResCode)
|
|
|
|
{
|
|
|
|
/* Login successful... */
|
|
|
|
if (nResCode == 230)
|
|
|
|
bSuccess = TRUE;
|
|
|
|
/* User name okay, need password... */
|
|
|
|
else if (nResCode == 331)
|
|
|
|
bSuccess = FTP_SendPassword(lpwfs);
|
|
|
|
/* Need account for login... */
|
|
|
|
else if (nResCode == 332)
|
|
|
|
bSuccess = FTP_SendAccount(lpwfs);
|
|
|
|
else
|
|
|
|
FTP_SetResponseError(nResCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Returning %d\n", bSuccess);
|
|
|
|
lend:
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2004-05-25 06:02:05 +02:00
|
|
|
* FTP_SendCommandA (internal)
|
2000-04-11 22:07:00 +02:00
|
|
|
*
|
|
|
|
* Send command to server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* NULL on failure
|
|
|
|
*
|
|
|
|
*/
|
2005-06-13 21:05:42 +02:00
|
|
|
static BOOL FTP_SendCommandA(INT nSocket, FTP_COMMAND ftpCmd, LPCSTR lpszParam,
|
2009-07-07 21:46:09 +02:00
|
|
|
INTERNET_STATUS_CALLBACK lpfnStatusCB, object_header_t *hdr, DWORD_PTR dwContext)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
DWORD len;
|
|
|
|
CHAR *buf;
|
|
|
|
DWORD nBytesSent = 0;
|
2004-08-09 20:54:23 +02:00
|
|
|
int nRC = 0;
|
2004-05-25 06:02:05 +02:00
|
|
|
DWORD dwParamLen;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
TRACE("%d: (%s) %d\n", ftpCmd, lpszParam, nSocket);
|
|
|
|
|
|
|
|
if (lpfnStatusCB)
|
2004-07-19 23:49:39 +02:00
|
|
|
{
|
2006-10-30 22:13:52 +01:00
|
|
|
lpfnStatusCB(hdr->hInternet, dwContext, INTERNET_STATUS_SENDING_REQUEST, NULL, 0);
|
2004-07-19 23:49:39 +02:00
|
|
|
}
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
dwParamLen = lpszParam?strlen(lpszParam)+1:0;
|
|
|
|
len = dwParamLen + strlen(szFtpCommands[ftpCmd]) + strlen(szCRLF);
|
2011-04-21 13:39:03 +02:00
|
|
|
if (NULL == (buf = heap_alloc(len+1)))
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2004-05-25 06:02:05 +02:00
|
|
|
sprintf(buf, "%s%s%s%s", szFtpCommands[ftpCmd], dwParamLen ? " " : "",
|
|
|
|
dwParamLen ? lpszParam : "", szCRLF);
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2006-10-05 13:18:56 +02:00
|
|
|
TRACE("Sending (%s) len(%d)\n", buf, len);
|
2001-08-24 21:13:36 +02:00
|
|
|
while((nBytesSent < len) && (nRC != -1))
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
nRC = send(nSocket, buf+nBytesSent, len - nBytesSent, 0);
|
|
|
|
nBytesSent += nRC;
|
|
|
|
}
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, (LPVOID)buf);
|
|
|
|
|
|
|
|
if (lpfnStatusCB)
|
2004-07-19 23:49:39 +02:00
|
|
|
{
|
2006-10-30 22:13:52 +01:00
|
|
|
lpfnStatusCB(hdr->hInternet, dwContext, INTERNET_STATUS_REQUEST_SENT,
|
|
|
|
&nBytesSent, sizeof(DWORD));
|
2004-07-19 23:49:39 +02:00
|
|
|
}
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2006-10-05 13:18:56 +02:00
|
|
|
TRACE("Sent %d bytes\n", nBytesSent);
|
2001-08-24 21:13:36 +02:00
|
|
|
return (nRC != -1);
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* FTP_SendCommand (internal)
|
|
|
|
*
|
|
|
|
* Send command to server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* NULL on failure
|
|
|
|
*
|
|
|
|
*/
|
2005-12-03 18:03:08 +01:00
|
|
|
static BOOL FTP_SendCommand(INT nSocket, FTP_COMMAND ftpCmd, LPCWSTR lpszParam,
|
2009-07-07 21:46:09 +02:00
|
|
|
INTERNET_STATUS_CALLBACK lpfnStatusCB, object_header_t *hdr, DWORD_PTR dwContext)
|
2004-05-25 06:02:05 +02:00
|
|
|
{
|
|
|
|
BOOL ret;
|
2009-07-17 01:12:04 +02:00
|
|
|
LPSTR lpszParamA = heap_strdupWtoA(lpszParam);
|
2004-07-19 23:49:39 +02:00
|
|
|
ret = FTP_SendCommandA(nSocket, ftpCmd, lpszParamA, lpfnStatusCB, hdr, dwContext);
|
2004-05-25 06:02:05 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpszParamA);
|
|
|
|
return ret;
|
|
|
|
}
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FTP_ReceiveResponse (internal)
|
|
|
|
*
|
|
|
|
* Receive response from server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Reply code on success
|
|
|
|
* 0 on failure
|
|
|
|
*
|
|
|
|
*/
|
2009-07-13 01:45:53 +02:00
|
|
|
INT FTP_ReceiveResponse(ftp_session_t *lpwfs, DWORD_PTR dwContext)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
2004-05-25 06:02:05 +02:00
|
|
|
LPSTR lpszResponse = INTERNET_GetResponseBuffer();
|
2000-04-11 22:07:00 +02:00
|
|
|
DWORD nRecv;
|
|
|
|
INT rc = 0;
|
2000-11-07 21:28:34 +01:00
|
|
|
char firstprefix[5];
|
|
|
|
BOOL multiline = FALSE;
|
|
|
|
|
2005-11-10 13:14:56 +01:00
|
|
|
TRACE("socket(%d)\n", lpwfs->sndSocket);
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2004-09-20 21:10:31 +02:00
|
|
|
SendAsyncCallback(&lpwfs->hdr, dwContext, INTERNET_STATUS_RECEIVING_RESPONSE, NULL, 0);
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
2004-05-25 06:02:05 +02:00
|
|
|
if (!INTERNET_GetNextLine(lpwfs->sndSocket, &nRecv))
|
2000-04-11 22:07:00 +02:00
|
|
|
goto lerror;
|
|
|
|
|
2000-11-07 21:28:34 +01:00
|
|
|
if (nRecv >= 3)
|
|
|
|
{
|
|
|
|
if(!multiline)
|
|
|
|
{
|
|
|
|
if(lpszResponse[3] != '-')
|
|
|
|
break;
|
|
|
|
else
|
2008-01-04 20:37:14 +01:00
|
|
|
{ /* Start of multiline response. Loop until we get "nnn " */
|
2000-11-07 21:28:34 +01:00
|
|
|
multiline = TRUE;
|
|
|
|
memcpy(firstprefix, lpszResponse, 3);
|
|
|
|
firstprefix[3] = ' ';
|
|
|
|
firstprefix[4] = '\0';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(!memcmp(firstprefix, lpszResponse, 4))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-04-11 22:07:00 +02:00
|
|
|
if (nRecv >= 3)
|
|
|
|
{
|
|
|
|
rc = atoi(lpszResponse);
|
|
|
|
|
2004-09-20 21:10:31 +02:00
|
|
|
SendAsyncCallback(&lpwfs->hdr, dwContext, INTERNET_STATUS_RESPONSE_RECEIVED,
|
2000-04-11 22:07:00 +02:00
|
|
|
&nRecv, sizeof(DWORD));
|
|
|
|
}
|
|
|
|
|
|
|
|
lerror:
|
|
|
|
TRACE("return %d\n", rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FTP_SendPassword (internal)
|
|
|
|
*
|
|
|
|
* Send password to ftp server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* NULL on failure
|
|
|
|
*
|
|
|
|
*/
|
2009-07-13 01:45:53 +02:00
|
|
|
static BOOL FTP_SendPassword(ftp_session_t *lpwfs)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INT nResCode;
|
|
|
|
BOOL bSuccess = FALSE;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_PASS, lpwfs->lpszPassword, 0, 0, 0))
|
|
|
|
goto lend;
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
|
2000-04-11 22:07:00 +02:00
|
|
|
if (nResCode)
|
|
|
|
{
|
|
|
|
TRACE("Received reply code %d\n", nResCode);
|
|
|
|
/* Login successful... */
|
|
|
|
if (nResCode == 230)
|
|
|
|
bSuccess = TRUE;
|
|
|
|
/* Command not implemented, superfluous at the server site... */
|
|
|
|
/* Need account for login... */
|
|
|
|
else if (nResCode == 332)
|
|
|
|
bSuccess = FTP_SendAccount(lpwfs);
|
|
|
|
else
|
|
|
|
FTP_SetResponseError(nResCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
lend:
|
|
|
|
TRACE("Returning %d\n", bSuccess);
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FTP_SendAccount (internal)
|
|
|
|
*
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2000-04-11 22:07:00 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2009-07-13 01:45:53 +02:00
|
|
|
static BOOL FTP_SendAccount(ftp_session_t *lpwfs)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INT nResCode;
|
|
|
|
BOOL bSuccess = FALSE;
|
|
|
|
|
|
|
|
TRACE("\n");
|
2004-05-25 06:02:05 +02:00
|
|
|
if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_ACCT, szNoAccount, 0, 0, 0))
|
2000-04-11 22:07:00 +02:00
|
|
|
goto lend;
|
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
|
2000-04-11 22:07:00 +02:00
|
|
|
if (nResCode)
|
|
|
|
bSuccess = TRUE;
|
|
|
|
else
|
|
|
|
FTP_SetResponseError(nResCode);
|
|
|
|
|
|
|
|
lend:
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FTP_SendStore (internal)
|
|
|
|
*
|
|
|
|
* Send request to upload file to ftp server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2009-07-13 01:45:53 +02:00
|
|
|
static BOOL FTP_SendStore(ftp_session_t *lpwfs, LPCWSTR lpszRemoteFile, DWORD dwType)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INT nResCode;
|
|
|
|
BOOL bSuccess = FALSE;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
if (!FTP_InitListenSocket(lpwfs))
|
|
|
|
goto lend;
|
|
|
|
|
|
|
|
if (!FTP_SendType(lpwfs, dwType))
|
|
|
|
goto lend;
|
|
|
|
|
2000-12-29 06:19:57 +01:00
|
|
|
if (!FTP_SendPortOrPasv(lpwfs))
|
2000-04-11 22:07:00 +02:00
|
|
|
goto lend;
|
|
|
|
|
|
|
|
if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_STOR, lpszRemoteFile, 0, 0, 0))
|
|
|
|
goto lend;
|
2004-05-25 06:02:05 +02:00
|
|
|
nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
|
2000-04-11 22:07:00 +02:00
|
|
|
if (nResCode)
|
|
|
|
{
|
2006-06-07 21:43:50 +02:00
|
|
|
if (nResCode == 150 || nResCode == 125)
|
2000-04-11 22:07:00 +02:00
|
|
|
bSuccess = TRUE;
|
|
|
|
else
|
|
|
|
FTP_SetResponseError(nResCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
lend:
|
2001-08-24 21:13:36 +02:00
|
|
|
if (!bSuccess && lpwfs->lstnSocket != -1)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
2004-09-03 20:57:19 +02:00
|
|
|
closesocket(lpwfs->lstnSocket);
|
2001-08-24 21:13:36 +02:00
|
|
|
lpwfs->lstnSocket = -1;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FTP_InitListenSocket (internal)
|
|
|
|
*
|
|
|
|
* Create a socket to listen for server response
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2009-07-13 01:45:53 +02:00
|
|
|
static BOOL FTP_InitListenSocket(ftp_session_t *lpwfs)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
BOOL bSuccess = FALSE;
|
2009-07-09 20:04:33 +02:00
|
|
|
socklen_t namelen = sizeof(lpwfs->lstnSocketAddress);
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
lpwfs->lstnSocket = socket(PF_INET, SOCK_STREAM, 0);
|
2001-08-24 21:13:36 +02:00
|
|
|
if (lpwfs->lstnSocket == -1)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
TRACE("Unable to create listening socket\n");
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
2000-11-07 21:28:34 +01:00
|
|
|
/* We obtain our ip addr from the name of the command channel socket */
|
|
|
|
lpwfs->lstnSocketAddress = lpwfs->socketAddress;
|
|
|
|
|
|
|
|
/* and get the system to assign us a port */
|
2008-12-01 02:09:30 +01:00
|
|
|
lpwfs->lstnSocketAddress.sin_port = htons(0);
|
2000-11-07 21:28:34 +01:00
|
|
|
|
2009-07-09 20:04:33 +02:00
|
|
|
if (bind(lpwfs->lstnSocket,(struct sockaddr *) &lpwfs->lstnSocketAddress, sizeof(lpwfs->lstnSocketAddress)) == -1)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
TRACE("Unable to bind socket\n");
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
2001-08-24 21:13:36 +02:00
|
|
|
if (listen(lpwfs->lstnSocket, MAX_BACKLOG) == -1)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
TRACE("listen failed\n");
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
2001-08-24 21:13:36 +02:00
|
|
|
if (getsockname(lpwfs->lstnSocket, (struct sockaddr *) &lpwfs->lstnSocketAddress, &namelen) != -1)
|
2000-04-11 22:07:00 +02:00
|
|
|
bSuccess = TRUE;
|
|
|
|
|
|
|
|
lend:
|
2007-03-08 15:30:41 +01:00
|
|
|
if (!bSuccess && lpwfs->lstnSocket != -1)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
2004-09-03 20:57:19 +02:00
|
|
|
closesocket(lpwfs->lstnSocket);
|
2001-08-24 21:13:36 +02:00
|
|
|
lpwfs->lstnSocket = -1;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FTP_SendType (internal)
|
|
|
|
*
|
2001-10-22 21:04:32 +02:00
|
|
|
* Tell server type of data being transferred
|
2000-04-11 22:07:00 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
2000-12-29 06:19:57 +01:00
|
|
|
* W98SE doesn't cache the type that's currently set
|
|
|
|
* (i.e. it sends it always),
|
|
|
|
* so we probably don't want to do that either.
|
2000-04-11 22:07:00 +02:00
|
|
|
*/
|
2009-07-13 01:45:53 +02:00
|
|
|
static BOOL FTP_SendType(ftp_session_t *lpwfs, DWORD dwType)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INT nResCode;
|
2004-05-25 06:02:05 +02:00
|
|
|
WCHAR type[] = { 'I','\0' };
|
2000-04-11 22:07:00 +02:00
|
|
|
BOOL bSuccess = FALSE;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
if (dwType & INTERNET_FLAG_TRANSFER_ASCII)
|
2004-05-25 06:02:05 +02:00
|
|
|
type[0] = 'A';
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_TYPE, type, 0, 0, 0))
|
|
|
|
goto lend;
|
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext)/100;
|
2000-04-11 22:07:00 +02:00
|
|
|
if (nResCode)
|
|
|
|
{
|
|
|
|
if (nResCode == 2)
|
|
|
|
bSuccess = TRUE;
|
|
|
|
else
|
|
|
|
FTP_SetResponseError(nResCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
lend:
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
2007-09-17 12:56:48 +02:00
|
|
|
|
|
|
|
#if 0 /* FIXME: should probably be used for FtpGetFileSize */
|
2003-07-21 21:59:03 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* FTP_GetFileSize (internal)
|
|
|
|
*
|
|
|
|
* Retrieves from the server the size of the given file
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2009-07-13 01:45:53 +02:00
|
|
|
static BOOL FTP_GetFileSize(ftp_session_t *lpwfs, LPCWSTR lpszRemoteFile, DWORD *dwSize)
|
2003-07-21 21:59:03 +02:00
|
|
|
{
|
|
|
|
INT nResCode;
|
|
|
|
BOOL bSuccess = FALSE;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
|
|
|
if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_SIZE, lpszRemoteFile, 0, 0, 0))
|
|
|
|
goto lend;
|
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
|
2003-07-21 21:59:03 +02:00
|
|
|
if (nResCode)
|
|
|
|
{
|
|
|
|
if (nResCode == 213) {
|
|
|
|
/* Now parses the output to get the actual file size */
|
|
|
|
int i;
|
|
|
|
LPSTR lpszResponseBuffer = INTERNET_GetResponseBuffer();
|
|
|
|
|
|
|
|
for (i = 0; (lpszResponseBuffer[i] != ' ') && (lpszResponseBuffer[i] != '\0'); i++) ;
|
|
|
|
if (lpszResponseBuffer[i] == '\0') return FALSE;
|
|
|
|
*dwSize = atol(&(lpszResponseBuffer[i + 1]));
|
|
|
|
|
|
|
|
bSuccess = TRUE;
|
|
|
|
} else {
|
|
|
|
FTP_SetResponseError(nResCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lend:
|
|
|
|
return bSuccess;
|
|
|
|
}
|
2007-09-17 12:56:48 +02:00
|
|
|
#endif
|
2003-07-21 21:59:03 +02:00
|
|
|
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FTP_SendPort (internal)
|
|
|
|
*
|
|
|
|
* Tell server which port to use
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2009-07-13 01:45:53 +02:00
|
|
|
static BOOL FTP_SendPort(ftp_session_t *lpwfs)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
2004-05-25 06:02:05 +02:00
|
|
|
static const WCHAR szIPFormat[] = {'%','d',',','%','d',',','%','d',',','%','d',',','%','d',',','%','d','\0'};
|
2000-04-11 22:07:00 +02:00
|
|
|
INT nResCode;
|
2004-05-25 06:02:05 +02:00
|
|
|
WCHAR szIPAddress[64];
|
2000-04-11 22:07:00 +02:00
|
|
|
BOOL bSuccess = FALSE;
|
|
|
|
TRACE("\n");
|
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
sprintfW(szIPAddress, szIPFormat,
|
2000-11-07 21:28:34 +01:00
|
|
|
lpwfs->lstnSocketAddress.sin_addr.s_addr&0x000000FF,
|
|
|
|
(lpwfs->lstnSocketAddress.sin_addr.s_addr&0x0000FF00)>>8,
|
|
|
|
(lpwfs->lstnSocketAddress.sin_addr.s_addr&0x00FF0000)>>16,
|
|
|
|
(lpwfs->lstnSocketAddress.sin_addr.s_addr&0xFF000000)>>24,
|
2000-04-11 22:07:00 +02:00
|
|
|
lpwfs->lstnSocketAddress.sin_port & 0xFF,
|
|
|
|
(lpwfs->lstnSocketAddress.sin_port & 0xFF00)>>8);
|
|
|
|
|
|
|
|
if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_PORT, szIPAddress, 0, 0, 0))
|
|
|
|
goto lend;
|
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
|
2000-04-11 22:07:00 +02:00
|
|
|
if (nResCode)
|
|
|
|
{
|
|
|
|
if (nResCode == 200)
|
|
|
|
bSuccess = TRUE;
|
|
|
|
else
|
|
|
|
FTP_SetResponseError(nResCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
lend:
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2000-12-29 06:19:57 +01:00
|
|
|
* FTP_DoPassive (internal)
|
|
|
|
*
|
|
|
|
* Tell server that we want to do passive transfers
|
|
|
|
* and connect data socket
|
2000-04-11 22:07:00 +02:00
|
|
|
*
|
2000-12-29 06:19:57 +01:00
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2009-07-13 01:45:53 +02:00
|
|
|
static BOOL FTP_DoPassive(ftp_session_t *lpwfs)
|
2000-12-29 06:19:57 +01:00
|
|
|
{
|
|
|
|
INT nResCode;
|
|
|
|
BOOL bSuccess = FALSE;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_PASV, NULL, 0, 0, 0))
|
|
|
|
goto lend;
|
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
|
2000-12-29 06:19:57 +01:00
|
|
|
if (nResCode)
|
|
|
|
{
|
|
|
|
if (nResCode == 227)
|
|
|
|
{
|
|
|
|
LPSTR lpszResponseBuffer = INTERNET_GetResponseBuffer();
|
|
|
|
LPSTR p;
|
|
|
|
int f[6];
|
|
|
|
int i;
|
|
|
|
char *pAddr, *pPort;
|
2001-08-24 21:13:36 +02:00
|
|
|
INT nsocket = -1;
|
2000-12-29 06:19:57 +01:00
|
|
|
struct sockaddr_in dataSocketAddress;
|
|
|
|
|
|
|
|
p = lpszResponseBuffer+4; /* skip status code */
|
2007-06-07 16:32:24 +02:00
|
|
|
while (*p != '\0' && (*p < '0' || *p > '9')) p++;
|
2000-12-29 06:19:57 +01:00
|
|
|
|
2007-06-07 16:32:24 +02:00
|
|
|
if (*p == '\0')
|
2000-12-29 06:19:57 +01:00
|
|
|
{
|
2007-06-07 16:32:24 +02:00
|
|
|
ERR("no address found in response, aborting\n");
|
2000-12-29 06:19:57 +01:00
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sscanf(p, "%d,%d,%d,%d,%d,%d", &f[0], &f[1], &f[2], &f[3],
|
|
|
|
&f[4], &f[5]) != 6)
|
|
|
|
{
|
|
|
|
ERR("unknown response address format '%s', aborting\n", p);
|
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
for (i=0; i < 6; i++)
|
|
|
|
f[i] = f[i] & 0xff;
|
|
|
|
|
|
|
|
dataSocketAddress = lpwfs->socketAddress;
|
|
|
|
pAddr = (char *)&(dataSocketAddress.sin_addr.s_addr);
|
|
|
|
pPort = (char *)&(dataSocketAddress.sin_port);
|
|
|
|
pAddr[0] = f[0];
|
|
|
|
pAddr[1] = f[1];
|
|
|
|
pAddr[2] = f[2];
|
|
|
|
pAddr[3] = f[3];
|
|
|
|
pPort[0] = f[4];
|
|
|
|
pPort[1] = f[5];
|
|
|
|
|
2001-08-24 21:13:36 +02:00
|
|
|
nsocket = socket(AF_INET,SOCK_STREAM,0);
|
|
|
|
if (nsocket == -1)
|
2000-12-29 06:19:57 +01:00
|
|
|
goto lend;
|
|
|
|
|
|
|
|
if (connect(nsocket, (struct sockaddr *)&dataSocketAddress, sizeof(dataSocketAddress)))
|
|
|
|
{
|
|
|
|
ERR("can't connect passive FTP data port.\n");
|
2006-09-06 10:46:10 +02:00
|
|
|
closesocket(nsocket);
|
2000-12-29 06:19:57 +01:00
|
|
|
goto lend;
|
|
|
|
}
|
|
|
|
lpwfs->pasvSocket = nsocket;
|
|
|
|
bSuccess = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
FTP_SetResponseError(nResCode);
|
|
|
|
}
|
|
|
|
|
|
|
|
lend:
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-13 01:45:53 +02:00
|
|
|
static BOOL FTP_SendPortOrPasv(ftp_session_t *lpwfs)
|
2000-12-29 06:19:57 +01:00
|
|
|
{
|
|
|
|
if (lpwfs->hdr.dwFlags & INTERNET_FLAG_PASSIVE)
|
|
|
|
{
|
|
|
|
if (!FTP_DoPassive(lpwfs))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!FTP_SendPort(lpwfs))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FTP_GetDataSocket (internal)
|
|
|
|
*
|
|
|
|
* Either accepts an incoming data socket connection from the server
|
|
|
|
* or just returns the already opened socket after a PASV command
|
|
|
|
* in case of passive FTP.
|
2002-06-01 01:06:46 +02:00
|
|
|
*
|
2000-04-11 22:07:00 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2009-07-13 01:45:53 +02:00
|
|
|
static BOOL FTP_GetDataSocket(ftp_session_t *lpwfs, LPINT nDataSocket)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
struct sockaddr_in saddr;
|
2007-01-04 19:21:24 +01:00
|
|
|
socklen_t addrlen = sizeof(struct sockaddr);
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
2000-12-29 06:19:57 +01:00
|
|
|
if (lpwfs->hdr.dwFlags & INTERNET_FLAG_PASSIVE)
|
|
|
|
{
|
|
|
|
*nDataSocket = lpwfs->pasvSocket;
|
2009-09-17 14:42:37 +02:00
|
|
|
lpwfs->pasvSocket = -1;
|
2000-12-29 06:19:57 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*nDataSocket = accept(lpwfs->lstnSocket, (struct sockaddr *) &saddr, &addrlen);
|
2004-09-03 20:57:19 +02:00
|
|
|
closesocket(lpwfs->lstnSocket);
|
2001-08-24 21:13:36 +02:00
|
|
|
lpwfs->lstnSocket = -1;
|
2000-12-29 06:19:57 +01:00
|
|
|
}
|
2001-08-24 21:13:36 +02:00
|
|
|
return *nDataSocket != -1;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FTP_SendData (internal)
|
|
|
|
*
|
|
|
|
* Send data to the server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2009-07-13 01:45:53 +02:00
|
|
|
static BOOL FTP_SendData(ftp_session_t *lpwfs, INT nDataSocket, HANDLE hFile)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
BY_HANDLE_FILE_INFORMATION fi;
|
|
|
|
DWORD nBytesRead = 0;
|
|
|
|
DWORD nBytesSent = 0;
|
|
|
|
DWORD nTotalSent = 0;
|
2004-08-09 20:54:23 +02:00
|
|
|
DWORD nBytesToSend, nLen;
|
|
|
|
int nRC = 1;
|
2000-04-11 22:07:00 +02:00
|
|
|
time_t s_long_time, e_long_time;
|
|
|
|
LONG nSeconds;
|
|
|
|
CHAR *lpszBuffer;
|
|
|
|
|
|
|
|
TRACE("\n");
|
2011-04-21 13:39:03 +02:00
|
|
|
lpszBuffer = heap_alloc_zero(sizeof(CHAR)*DATA_PACKET_SIZE);
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
/* Get the size of the file. */
|
|
|
|
GetFileInformationByHandle(hFile, &fi);
|
|
|
|
time(&s_long_time);
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
nBytesToSend = nBytesRead - nBytesSent;
|
|
|
|
|
|
|
|
if (nBytesToSend <= 0)
|
|
|
|
{
|
|
|
|
/* Read data from file. */
|
|
|
|
nBytesSent = 0;
|
|
|
|
if (!ReadFile(hFile, lpszBuffer, DATA_PACKET_SIZE, &nBytesRead, 0))
|
|
|
|
ERR("Failed reading from file\n");
|
|
|
|
|
|
|
|
if (nBytesRead > 0)
|
|
|
|
nBytesToSend = nBytesRead;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
nLen = DATA_PACKET_SIZE < nBytesToSend ?
|
2000-04-11 22:07:00 +02:00
|
|
|
DATA_PACKET_SIZE : nBytesToSend;
|
|
|
|
nRC = send(nDataSocket, lpszBuffer, nLen, 0);
|
|
|
|
|
2001-08-24 21:13:36 +02:00
|
|
|
if (nRC != -1)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
nBytesSent += nRC;
|
|
|
|
nTotalSent += nRC;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Do some computation to display the status. */
|
|
|
|
time(&e_long_time);
|
|
|
|
nSeconds = e_long_time - s_long_time;
|
|
|
|
if( nSeconds / 60 > 0 )
|
|
|
|
{
|
2006-10-05 13:18:56 +02:00
|
|
|
TRACE( "%d bytes of %d bytes (%d%%) in %d min %d sec estimated remaining time %d sec\n",
|
2002-06-01 01:06:46 +02:00
|
|
|
nTotalSent, fi.nFileSizeLow, nTotalSent*100/fi.nFileSizeLow, nSeconds / 60,
|
2000-04-11 22:07:00 +02:00
|
|
|
nSeconds % 60, (fi.nFileSizeLow - nTotalSent) * nSeconds / nTotalSent );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-10-05 13:18:56 +02:00
|
|
|
TRACE( "%d bytes of %d bytes (%d%%) in %d sec estimated remaining time %d sec\n",
|
2000-04-11 22:07:00 +02:00
|
|
|
nTotalSent, fi.nFileSizeLow, nTotalSent*100/fi.nFileSizeLow, nSeconds,
|
|
|
|
(fi.nFileSizeLow - nTotalSent) * nSeconds / nTotalSent);
|
|
|
|
}
|
2001-08-24 21:13:36 +02:00
|
|
|
} while (nRC != -1);
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
TRACE("file transfer complete!\n");
|
|
|
|
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpszBuffer);
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
return nTotalSent;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FTP_SendRetrieve (internal)
|
|
|
|
*
|
|
|
|
* Send request to retrieve a file
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Number of bytes to be received on success
|
|
|
|
* 0 on failure
|
|
|
|
*
|
|
|
|
*/
|
2009-07-13 01:45:53 +02:00
|
|
|
static BOOL FTP_SendRetrieve(ftp_session_t *lpwfs, LPCWSTR lpszRemoteFile, DWORD dwType)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
INT nResCode;
|
2007-09-17 12:56:48 +02:00
|
|
|
BOOL ret;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
2007-09-17 12:56:48 +02:00
|
|
|
if (!(ret = FTP_InitListenSocket(lpwfs)))
|
2000-04-11 22:07:00 +02:00
|
|
|
goto lend;
|
|
|
|
|
2007-09-17 12:56:48 +02:00
|
|
|
if (!(ret = FTP_SendType(lpwfs, dwType)))
|
2000-04-11 22:07:00 +02:00
|
|
|
goto lend;
|
|
|
|
|
2007-09-17 12:56:48 +02:00
|
|
|
if (!(ret = FTP_SendPortOrPasv(lpwfs)))
|
2000-04-11 22:07:00 +02:00
|
|
|
goto lend;
|
|
|
|
|
2007-09-17 12:56:48 +02:00
|
|
|
if (!(ret = FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_RETR, lpszRemoteFile, 0, 0, 0)))
|
2000-04-11 22:07:00 +02:00
|
|
|
goto lend;
|
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
|
2003-07-21 21:59:03 +02:00
|
|
|
if ((nResCode != 125) && (nResCode != 150)) {
|
|
|
|
/* That means that we got an error getting the file. */
|
2007-09-17 12:56:48 +02:00
|
|
|
FTP_SetResponseError(nResCode);
|
|
|
|
ret = FALSE;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
lend:
|
2007-09-17 12:56:48 +02:00
|
|
|
if (!ret && lpwfs->lstnSocket != -1)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
2004-09-03 20:57:19 +02:00
|
|
|
closesocket(lpwfs->lstnSocket);
|
2001-08-24 21:13:36 +02:00
|
|
|
lpwfs->lstnSocket = -1;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
2007-09-17 12:56:48 +02:00
|
|
|
return ret;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FTP_RetrieveData (internal)
|
|
|
|
*
|
|
|
|
* Retrieve data from server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2009-07-13 01:45:53 +02:00
|
|
|
static BOOL FTP_RetrieveFileData(ftp_session_t *lpwfs, INT nDataSocket, HANDLE hFile)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
DWORD nBytesWritten;
|
|
|
|
INT nRC = 0;
|
|
|
|
CHAR *lpszBuffer;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2011-04-21 13:39:03 +02:00
|
|
|
lpszBuffer = heap_alloc_zero(sizeof(CHAR)*DATA_PACKET_SIZE);
|
2000-04-11 22:07:00 +02:00
|
|
|
if (NULL == lpszBuffer)
|
|
|
|
{
|
|
|
|
INTERNET_SetLastError(ERROR_OUTOFMEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-09-17 12:56:48 +02:00
|
|
|
while (nRC != -1)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
nRC = recv(nDataSocket, lpszBuffer, DATA_PACKET_SIZE, 0);
|
2001-08-24 21:13:36 +02:00
|
|
|
if (nRC != -1)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
/* other side closed socket. */
|
|
|
|
if (nRC == 0)
|
|
|
|
goto recv_end;
|
2002-06-01 01:06:46 +02:00
|
|
|
WriteFile(hFile, lpszBuffer, nRC, &nBytesWritten, NULL);
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Data transfer complete\n");
|
|
|
|
|
|
|
|
recv_end:
|
2007-03-21 17:56:09 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpszBuffer);
|
|
|
|
|
2001-08-24 21:13:36 +02:00
|
|
|
return (nRC != -1);
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
2006-10-29 18:53:41 +01:00
|
|
|
/***********************************************************************
|
2008-02-27 18:55:09 +01:00
|
|
|
* FTPFINDNEXT_Destroy (internal)
|
2006-10-29 18:53:41 +01:00
|
|
|
*
|
2008-02-27 18:55:09 +01:00
|
|
|
* Deallocate session handle
|
2006-10-29 18:53:41 +01:00
|
|
|
*/
|
2009-07-07 21:46:09 +02:00
|
|
|
static void FTPFINDNEXT_Destroy(object_header_t *hdr)
|
2006-10-29 18:53:41 +01:00
|
|
|
{
|
2008-02-27 18:55:09 +01:00
|
|
|
LPWININETFTPFINDNEXTW lpwfn = (LPWININETFTPFINDNEXTW) hdr;
|
|
|
|
DWORD i;
|
2006-10-29 18:53:41 +01:00
|
|
|
|
2008-02-27 18:55:09 +01:00
|
|
|
TRACE("\n");
|
2006-10-29 18:53:41 +01:00
|
|
|
|
2008-02-27 18:55:09 +01:00
|
|
|
WININET_Release(&lpwfn->lpFtpSession->hdr);
|
2006-10-29 18:53:41 +01:00
|
|
|
|
2008-02-27 18:55:09 +01:00
|
|
|
for (i = 0; i < lpwfn->size; i++)
|
2006-10-29 18:53:41 +01:00
|
|
|
{
|
2008-02-27 18:55:09 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpwfn->lpafp[i].lpszName);
|
2006-10-29 18:53:41 +01:00
|
|
|
}
|
|
|
|
|
2008-02-27 18:55:09 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, lpwfn->lpafp);
|
|
|
|
}
|
2006-10-29 18:53:41 +01:00
|
|
|
|
2008-11-24 17:24:22 +01:00
|
|
|
static DWORD FTPFINDNEXT_FindNextFileProc(WININETFTPFINDNEXTW *find, LPVOID data)
|
2008-02-27 18:55:09 +01:00
|
|
|
{
|
|
|
|
WIN32_FIND_DATAW *find_data = data;
|
|
|
|
DWORD res = ERROR_SUCCESS;
|
2006-10-29 18:53:41 +01:00
|
|
|
|
2008-02-27 18:55:09 +01:00
|
|
|
TRACE("index(%d) size(%d)\n", find->index, find->size);
|
|
|
|
|
|
|
|
ZeroMemory(find_data, sizeof(WIN32_FIND_DATAW));
|
|
|
|
|
|
|
|
if (find->index < find->size) {
|
|
|
|
FTP_ConvertFileProp(&find->lpafp[find->index], find_data);
|
|
|
|
find->index++;
|
2006-10-29 18:53:41 +01:00
|
|
|
|
2008-02-27 18:55:09 +01:00
|
|
|
TRACE("Name: %s\nSize: %d\n", debugstr_w(find_data->cFileName), find_data->nFileSizeLow);
|
|
|
|
}else {
|
|
|
|
res = ERROR_NO_MORE_FILES;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (find->hdr.dwFlags & INTERNET_FLAG_ASYNC)
|
2006-10-29 18:53:41 +01:00
|
|
|
{
|
|
|
|
INTERNET_ASYNC_RESULT iar;
|
|
|
|
|
2008-02-27 18:55:09 +01:00
|
|
|
iar.dwResult = (res == ERROR_SUCCESS);
|
|
|
|
iar.dwError = res;
|
2006-10-29 18:53:41 +01:00
|
|
|
|
2008-02-27 18:55:09 +01:00
|
|
|
INTERNET_SendCallback(&find->hdr, find->hdr.dwContext,
|
2006-10-29 18:53:41 +01:00
|
|
|
INTERNET_STATUS_REQUEST_COMPLETE, &iar,
|
|
|
|
sizeof(INTERNET_ASYNC_RESULT));
|
|
|
|
}
|
|
|
|
|
2008-02-27 18:55:09 +01:00
|
|
|
return res;
|
2006-10-29 18:53:41 +01:00
|
|
|
}
|
|
|
|
|
2008-02-27 18:55:09 +01:00
|
|
|
static void FTPFINDNEXT_AsyncFindNextFileProc(WORKREQUEST *workRequest)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
2008-02-27 18:55:09 +01:00
|
|
|
struct WORKREQ_FTPFINDNEXTW *req = &workRequest->u.FtpFindNextW;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2008-02-27 18:55:09 +01:00
|
|
|
FTPFINDNEXT_FindNextFileProc((WININETFTPFINDNEXTW*)workRequest->hdr, req->lpFindFileData);
|
|
|
|
}
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2009-07-07 21:46:09 +02:00
|
|
|
static DWORD FTPFINDNEXT_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
|
2008-03-12 02:23:20 +01:00
|
|
|
{
|
|
|
|
switch(option) {
|
|
|
|
case INTERNET_OPTION_HANDLE_TYPE:
|
|
|
|
TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
|
|
|
|
|
|
|
|
if (*size < sizeof(ULONG))
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
|
|
|
|
*size = sizeof(DWORD);
|
|
|
|
*(DWORD*)buffer = INTERNET_HANDLE_TYPE_FTP_FIND;
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2010-05-25 12:19:32 +02:00
|
|
|
return INET_QueryOption(hdr, option, buffer, size, unicode);
|
2008-03-12 02:23:20 +01:00
|
|
|
}
|
|
|
|
|
2009-07-07 21:46:09 +02:00
|
|
|
static DWORD FTPFINDNEXT_FindNextFileW(object_header_t *hdr, void *data)
|
2008-02-27 18:55:09 +01:00
|
|
|
{
|
|
|
|
WININETFTPFINDNEXTW *find = (WININETFTPFINDNEXTW*)hdr;
|
2006-10-29 18:54:29 +01:00
|
|
|
|
2008-02-27 18:55:09 +01:00
|
|
|
if (find->lpFtpSession->lpAppInfo->hdr.dwFlags & INTERNET_FLAG_ASYNC)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
2008-02-27 18:55:09 +01:00
|
|
|
WORKREQUEST workRequest;
|
|
|
|
struct WORKREQ_FTPFINDNEXTW *req;
|
|
|
|
|
|
|
|
workRequest.asyncproc = FTPFINDNEXT_AsyncFindNextFileProc;
|
|
|
|
workRequest.hdr = WININET_AddRef( &find->hdr );
|
|
|
|
req = &workRequest.u.FtpFindNextW;
|
|
|
|
req->lpFindFileData = data;
|
|
|
|
|
|
|
|
INTERNET_AsyncCall(&workRequest);
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
2008-02-27 18:55:09 +01:00
|
|
|
return FTPFINDNEXT_FindNextFileProc(find, data);
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
2009-07-07 21:46:09 +02:00
|
|
|
static const object_vtbl_t FTPFINDNEXTVtbl = {
|
2008-02-26 20:21:00 +01:00
|
|
|
FTPFINDNEXT_Destroy,
|
2008-02-26 20:21:34 +01:00
|
|
|
NULL,
|
2008-03-12 02:23:20 +01:00
|
|
|
FTPFINDNEXT_QueryOption,
|
2008-02-26 20:22:02 +01:00
|
|
|
NULL,
|
2008-02-27 18:55:09 +01:00
|
|
|
NULL,
|
2008-02-29 12:57:57 +01:00
|
|
|
NULL,
|
2008-03-02 19:35:11 +01:00
|
|
|
NULL,
|
2008-03-03 18:07:20 +01:00
|
|
|
NULL,
|
2009-01-15 16:41:42 +01:00
|
|
|
NULL,
|
2008-02-27 18:55:09 +01:00
|
|
|
FTPFINDNEXT_FindNextFileW
|
2008-02-26 20:20:41 +01:00
|
|
|
};
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FTP_ReceiveFileList (internal)
|
|
|
|
*
|
|
|
|
* Read file list from server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* Handle to file list on success
|
|
|
|
* NULL on failure
|
|
|
|
*
|
|
|
|
*/
|
2009-07-13 01:45:53 +02:00
|
|
|
static HINTERNET FTP_ReceiveFileList(ftp_session_t *lpwfs, INT nSocket, LPCWSTR lpszSearchFile,
|
2007-08-30 16:21:33 +02:00
|
|
|
LPWIN32_FIND_DATAW lpFindFileData, DWORD_PTR dwContext)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
DWORD dwSize = 0;
|
2004-05-25 06:02:05 +02:00
|
|
|
LPFILEPROPERTIESW lpafp = NULL;
|
2006-10-29 18:53:41 +01:00
|
|
|
LPWININETFTPFINDNEXTW lpwfn = NULL;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2007-08-30 16:21:33 +02:00
|
|
|
TRACE("(%p,%d,%s,%p,%08lx)\n", lpwfs, nSocket, debugstr_w(lpszSearchFile), lpFindFileData, dwContext);
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
if (FTP_ParseDirectory(lpwfs, nSocket, lpszSearchFile, &lpafp, &dwSize))
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
2004-05-25 06:02:05 +02:00
|
|
|
if(lpFindFileData)
|
|
|
|
FTP_ConvertFileProp(lpafp, lpFindFileData);
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2011-02-02 22:51:13 +01:00
|
|
|
lpwfn = alloc_object(&lpwfs->hdr, &FTPFINDNEXTVtbl, sizeof(WININETFTPFINDNEXTW));
|
2004-02-07 02:03:41 +01:00
|
|
|
if (lpwfn)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
2006-10-29 18:53:41 +01:00
|
|
|
lpwfn->hdr.htype = WH_HFTPFINDNEXT;
|
2004-07-19 23:49:39 +02:00
|
|
|
lpwfn->hdr.dwContext = dwContext;
|
|
|
|
lpwfn->index = 1; /* Next index is 1 since we return index 0 */
|
|
|
|
lpwfn->size = dwSize;
|
|
|
|
lpwfn->lpafp = lpafp;
|
|
|
|
|
2006-10-29 18:54:29 +01:00
|
|
|
WININET_AddRef( &lpwfs->hdr );
|
|
|
|
lpwfn->lpFtpSession = lpwfs;
|
2007-09-21 03:59:40 +02:00
|
|
|
list_add_head( &lpwfs->hdr.children, &lpwfn->hdr.entry );
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
}
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2006-10-05 13:18:56 +02:00
|
|
|
TRACE("Matched %d files\n", dwSize);
|
2011-02-02 22:51:13 +01:00
|
|
|
return lpwfn ? lpwfn->hdr.hInternet : NULL;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FTP_ConvertFileProp (internal)
|
|
|
|
*
|
2004-05-25 06:02:05 +02:00
|
|
|
* Converts FILEPROPERTIESW struct to WIN32_FIND_DATAA
|
2000-04-11 22:07:00 +02:00
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2008-02-27 18:55:28 +01:00
|
|
|
static BOOL FTP_ConvertFileProp(LPFILEPROPERTIESW lpafp, LPWIN32_FIND_DATAW lpFindFileData)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
BOOL bSuccess = FALSE;
|
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
ZeroMemory(lpFindFileData, sizeof(WIN32_FIND_DATAW));
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
if (lpafp)
|
|
|
|
{
|
2008-12-22 11:44:45 +01:00
|
|
|
SystemTimeToFileTime( &lpafp->tmLastModified, &lpFindFileData->ftLastAccessTime );
|
2004-09-06 22:24:38 +02:00
|
|
|
lpFindFileData->ftLastWriteTime = lpFindFileData->ftLastAccessTime;
|
|
|
|
lpFindFileData->ftCreationTime = lpFindFileData->ftLastAccessTime;
|
2003-07-22 00:04:14 +02:00
|
|
|
|
2000-04-11 22:07:00 +02:00
|
|
|
/* Not all fields are filled in */
|
2003-07-22 00:04:14 +02:00
|
|
|
lpFindFileData->nFileSizeHigh = 0; /* We do not handle files bigger than 0xFFFFFFFF bytes yet :-) */
|
|
|
|
lpFindFileData->nFileSizeLow = lpafp->nSize;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
if (lpafp->bIsDirectory)
|
|
|
|
lpFindFileData->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
|
|
|
|
|
|
|
|
if (lpafp->lpszName)
|
2005-03-28 16:17:51 +02:00
|
|
|
lstrcpynW(lpFindFileData->cFileName, lpafp->lpszName, MAX_PATH);
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
bSuccess = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* FTP_ParseNextFile (internal)
|
|
|
|
*
|
|
|
|
* Parse the next line in file listing
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*/
|
2005-12-03 18:03:08 +01:00
|
|
|
static BOOL FTP_ParseNextFile(INT nSocket, LPCWSTR lpszSearchFile, LPFILEPROPERTIESW lpfp)
|
2004-05-25 06:02:05 +02:00
|
|
|
{
|
|
|
|
static const char szSpace[] = " \t";
|
|
|
|
DWORD nBufLen;
|
|
|
|
char *pszLine;
|
|
|
|
char *pszToken;
|
|
|
|
char *pszTmp;
|
|
|
|
BOOL found = FALSE;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
lpfp->lpszName = NULL;
|
|
|
|
do {
|
|
|
|
if(!(pszLine = INTERNET_GetNextLine(nSocket, &nBufLen)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
pszToken = strtok(pszLine, szSpace);
|
|
|
|
/* ls format
|
|
|
|
* <Permissions> <NoLinks> <owner> <group> <size> <date> <time or year> <filename>
|
|
|
|
*
|
|
|
|
* For instance:
|
|
|
|
* drwx--s--- 2 pcarrier ens 512 Sep 28 1995 pcarrier
|
|
|
|
*/
|
|
|
|
if(!isdigit(pszToken[0]) && 10 == strlen(pszToken)) {
|
|
|
|
if(!FTP_ParsePermission(pszToken, lpfp))
|
|
|
|
lpfp->bIsDirectory = FALSE;
|
|
|
|
for(i=0; i<=3; i++) {
|
|
|
|
if(!(pszToken = strtok(NULL, szSpace)))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(!pszToken) continue;
|
|
|
|
if(lpfp->bIsDirectory) {
|
|
|
|
TRACE("Is directory\n");
|
|
|
|
lpfp->nSize = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
TRACE("Size: %s\n", pszToken);
|
|
|
|
lpfp->nSize = atol(pszToken);
|
|
|
|
}
|
|
|
|
|
2008-12-22 11:44:45 +01:00
|
|
|
lpfp->tmLastModified.wSecond = 0;
|
|
|
|
lpfp->tmLastModified.wMinute = 0;
|
|
|
|
lpfp->tmLastModified.wHour = 0;
|
|
|
|
lpfp->tmLastModified.wDay = 0;
|
|
|
|
lpfp->tmLastModified.wMonth = 0;
|
|
|
|
lpfp->tmLastModified.wYear = 0;
|
2004-05-25 06:02:05 +02:00
|
|
|
|
|
|
|
/* Determine month */
|
|
|
|
pszToken = strtok(NULL, szSpace);
|
|
|
|
if(!pszToken) continue;
|
|
|
|
if(strlen(pszToken) >= 3) {
|
|
|
|
pszToken[3] = 0;
|
|
|
|
if((pszTmp = StrStrIA(szMonths, pszToken)))
|
2008-12-22 11:44:45 +01:00
|
|
|
lpfp->tmLastModified.wMonth = ((pszTmp - szMonths) / 3)+1;
|
2004-05-25 06:02:05 +02:00
|
|
|
}
|
|
|
|
/* Determine day */
|
|
|
|
pszToken = strtok(NULL, szSpace);
|
|
|
|
if(!pszToken) continue;
|
2008-12-22 11:44:45 +01:00
|
|
|
lpfp->tmLastModified.wDay = atoi(pszToken);
|
2004-05-25 06:02:05 +02:00
|
|
|
/* Determine time or year */
|
|
|
|
pszToken = strtok(NULL, szSpace);
|
|
|
|
if(!pszToken) continue;
|
|
|
|
if((pszTmp = strchr(pszToken, ':'))) {
|
2008-12-22 11:44:45 +01:00
|
|
|
SYSTEMTIME curr_time;
|
2004-05-25 06:02:05 +02:00
|
|
|
*pszTmp = 0;
|
|
|
|
pszTmp++;
|
2008-12-22 11:44:45 +01:00
|
|
|
lpfp->tmLastModified.wMinute = atoi(pszTmp);
|
|
|
|
lpfp->tmLastModified.wHour = atoi(pszToken);
|
|
|
|
GetLocalTime( &curr_time );
|
|
|
|
lpfp->tmLastModified.wYear = curr_time.wYear;
|
2004-05-25 06:02:05 +02:00
|
|
|
}
|
|
|
|
else {
|
2008-12-22 11:44:45 +01:00
|
|
|
lpfp->tmLastModified.wYear = atoi(pszToken);
|
|
|
|
lpfp->tmLastModified.wHour = 12;
|
2004-05-25 06:02:05 +02:00
|
|
|
}
|
2008-12-22 11:44:45 +01:00
|
|
|
TRACE("Mod time: %02d:%02d:%02d %04d/%02d/%02d\n",
|
|
|
|
lpfp->tmLastModified.wHour, lpfp->tmLastModified.wMinute, lpfp->tmLastModified.wSecond,
|
|
|
|
lpfp->tmLastModified.wYear, lpfp->tmLastModified.wMonth, lpfp->tmLastModified.wDay);
|
2004-05-25 06:02:05 +02:00
|
|
|
|
|
|
|
pszToken = strtok(NULL, szSpace);
|
|
|
|
if(!pszToken) continue;
|
2009-07-17 01:11:24 +02:00
|
|
|
lpfp->lpszName = heap_strdupAtoW(pszToken);
|
2004-05-25 06:02:05 +02:00
|
|
|
TRACE("File: %s\n", debugstr_w(lpfp->lpszName));
|
|
|
|
}
|
|
|
|
/* NT way of parsing ... :
|
|
|
|
|
|
|
|
07-13-03 08:55PM <DIR> sakpatch
|
|
|
|
05-09-03 06:02PM 12656686 2003-04-21bgm_cmd_e.rgz
|
|
|
|
*/
|
|
|
|
else if(isdigit(pszToken[0]) && 8 == strlen(pszToken)) {
|
2008-12-22 11:44:45 +01:00
|
|
|
int mon, mday, year, hour, min;
|
2004-05-25 06:02:05 +02:00
|
|
|
lpfp->permissions = 0xFFFF; /* No idea, put full permission :-) */
|
|
|
|
|
2008-12-22 11:44:45 +01:00
|
|
|
sscanf(pszToken, "%d-%d-%d", &mon, &mday, &year);
|
|
|
|
lpfp->tmLastModified.wDay = mday;
|
|
|
|
lpfp->tmLastModified.wMonth = mon;
|
|
|
|
lpfp->tmLastModified.wYear = year;
|
2004-05-25 06:02:05 +02:00
|
|
|
|
|
|
|
/* Hacky and bad Y2K protection :-) */
|
2008-12-22 11:44:45 +01:00
|
|
|
if (lpfp->tmLastModified.wYear < 70) lpfp->tmLastModified.wYear += 2000;
|
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
pszToken = strtok(NULL, szSpace);
|
|
|
|
if(!pszToken) continue;
|
2008-12-22 11:44:45 +01:00
|
|
|
sscanf(pszToken, "%d:%d", &hour, &min);
|
|
|
|
lpfp->tmLastModified.wHour = hour;
|
|
|
|
lpfp->tmLastModified.wMinute = min;
|
2004-05-25 06:02:05 +02:00
|
|
|
if((pszToken[5] == 'P') && (pszToken[6] == 'M')) {
|
2008-12-22 11:44:45 +01:00
|
|
|
lpfp->tmLastModified.wHour += 12;
|
2004-05-25 06:02:05 +02:00
|
|
|
}
|
2008-12-22 11:44:45 +01:00
|
|
|
lpfp->tmLastModified.wSecond = 0;
|
|
|
|
|
|
|
|
TRACE("Mod time: %02d:%02d:%02d %04d/%02d/%02d\n",
|
|
|
|
lpfp->tmLastModified.wHour, lpfp->tmLastModified.wMinute, lpfp->tmLastModified.wSecond,
|
|
|
|
lpfp->tmLastModified.wYear, lpfp->tmLastModified.wMonth, lpfp->tmLastModified.wDay);
|
2004-05-25 06:02:05 +02:00
|
|
|
|
|
|
|
pszToken = strtok(NULL, szSpace);
|
|
|
|
if(!pszToken) continue;
|
|
|
|
if(!strcasecmp(pszToken, "<DIR>")) {
|
|
|
|
lpfp->bIsDirectory = TRUE;
|
|
|
|
lpfp->nSize = 0;
|
|
|
|
TRACE("Is directory\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lpfp->bIsDirectory = FALSE;
|
|
|
|
lpfp->nSize = atol(pszToken);
|
2006-10-05 13:18:56 +02:00
|
|
|
TRACE("Size: %d\n", lpfp->nSize);
|
2004-05-25 06:02:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pszToken = strtok(NULL, szSpace);
|
|
|
|
if(!pszToken) continue;
|
2009-07-17 01:11:24 +02:00
|
|
|
lpfp->lpszName = heap_strdupAtoW(pszToken);
|
2004-05-25 06:02:05 +02:00
|
|
|
TRACE("Name: %s\n", debugstr_w(lpfp->lpszName));
|
|
|
|
}
|
|
|
|
/* EPLF format - http://cr.yp.to/ftp/list/eplf.html */
|
|
|
|
else if(pszToken[0] == '+') {
|
|
|
|
FIXME("EPLF Format not implemented\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(lpfp->lpszName) {
|
2004-06-01 21:42:43 +02:00
|
|
|
if((lpszSearchFile == NULL) ||
|
|
|
|
(PathMatchSpecW(lpfp->lpszName, lpszSearchFile))) {
|
2004-05-25 06:02:05 +02:00
|
|
|
found = TRUE;
|
|
|
|
TRACE("Matched: %s\n", debugstr_w(lpfp->lpszName));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
HeapFree(GetProcessHeap(), 0, lpfp->lpszName);
|
|
|
|
lpfp->lpszName = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while(!found);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FTP_ParseDirectory (internal)
|
|
|
|
*
|
|
|
|
* Parse string of directory information
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*/
|
2009-07-13 01:45:53 +02:00
|
|
|
static BOOL FTP_ParseDirectory(ftp_session_t *lpwfs, INT nSocket, LPCWSTR lpszSearchFile,
|
2004-05-25 06:02:05 +02:00
|
|
|
LPFILEPROPERTIESW *lpafp, LPDWORD dwfp)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
BOOL bSuccess = TRUE;
|
2004-05-25 06:02:05 +02:00
|
|
|
INT sizeFilePropArray = 500;/*20; */
|
|
|
|
INT indexFilePropArray = -1;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
|
2008-01-04 20:37:14 +01:00
|
|
|
/* Allocate initial file properties array */
|
2011-04-21 13:39:03 +02:00
|
|
|
*lpafp = heap_alloc_zero(sizeof(FILEPROPERTIESW)*(sizeFilePropArray));
|
2004-05-25 06:02:05 +02:00
|
|
|
if (!*lpafp)
|
|
|
|
return FALSE;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2004-05-25 06:02:05 +02:00
|
|
|
do {
|
|
|
|
if (indexFilePropArray+1 >= sizeFilePropArray)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
2004-05-25 06:02:05 +02:00
|
|
|
LPFILEPROPERTIESW tmpafp;
|
|
|
|
|
2000-04-11 22:07:00 +02:00
|
|
|
sizeFilePropArray *= 2;
|
2011-04-22 12:35:05 +02:00
|
|
|
tmpafp = heap_realloc_zero(*lpafp, sizeof(FILEPROPERTIESW)*sizeFilePropArray);
|
2000-04-11 22:07:00 +02:00
|
|
|
if (NULL == tmpafp)
|
|
|
|
{
|
|
|
|
bSuccess = FALSE;
|
2004-05-25 06:02:05 +02:00
|
|
|
break;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
*lpafp = tmpafp;
|
|
|
|
}
|
2004-05-25 06:02:05 +02:00
|
|
|
indexFilePropArray++;
|
|
|
|
} while (FTP_ParseNextFile(nSocket, lpszSearchFile, &(*lpafp)[indexFilePropArray]));
|
2000-04-11 22:07:00 +02:00
|
|
|
|
|
|
|
if (bSuccess && indexFilePropArray)
|
|
|
|
{
|
|
|
|
if (indexFilePropArray < sizeFilePropArray - 1)
|
|
|
|
{
|
2004-05-25 06:02:05 +02:00
|
|
|
LPFILEPROPERTIESW tmpafp;
|
2000-04-11 22:07:00 +02:00
|
|
|
|
2011-04-22 12:35:05 +02:00
|
|
|
tmpafp = heap_realloc(*lpafp, sizeof(FILEPROPERTIESW)*indexFilePropArray);
|
2007-12-29 01:04:58 +01:00
|
|
|
if (NULL != tmpafp)
|
2000-04-11 22:07:00 +02:00
|
|
|
*lpafp = tmpafp;
|
|
|
|
}
|
|
|
|
*dwfp = indexFilePropArray;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, *lpafp);
|
|
|
|
INTERNET_SetLastError(ERROR_NO_MORE_FILES);
|
|
|
|
bSuccess = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FTP_ParsePermission (internal)
|
|
|
|
*
|
|
|
|
* Parse permission string of directory information
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
* TRUE on success
|
|
|
|
* FALSE on failure
|
|
|
|
*
|
|
|
|
*/
|
2005-12-03 18:03:08 +01:00
|
|
|
static BOOL FTP_ParsePermission(LPCSTR lpszPermission, LPFILEPROPERTIESW lpfp)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
BOOL bSuccess = TRUE;
|
|
|
|
unsigned short nPermission = 0;
|
|
|
|
INT nPos = 1;
|
|
|
|
INT nLast = 9;
|
|
|
|
|
|
|
|
TRACE("\n");
|
|
|
|
if ((*lpszPermission != 'd') && (*lpszPermission != '-') && (*lpszPermission != 'l'))
|
|
|
|
{
|
|
|
|
bSuccess = FALSE;
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
lpfp->bIsDirectory = (*lpszPermission == 'd');
|
|
|
|
do
|
|
|
|
{
|
|
|
|
switch (nPos)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
nPermission |= (*(lpszPermission+1) == 'r' ? 1 : 0) << 8;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
nPermission |= (*(lpszPermission+2) == 'w' ? 1 : 0) << 7;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
nPermission |= (*(lpszPermission+3) == 'x' ? 1 : 0) << 6;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
nPermission |= (*(lpszPermission+4) == 'r' ? 1 : 0) << 5;
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
nPermission |= (*(lpszPermission+5) == 'w' ? 1 : 0) << 4;
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
nPermission |= (*(lpszPermission+6) == 'x' ? 1 : 0) << 3;
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
nPermission |= (*(lpszPermission+7) == 'r' ? 1 : 0) << 2;
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
nPermission |= (*(lpszPermission+8) == 'w' ? 1 : 0) << 1;
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
nPermission |= (*(lpszPermission+9) == 'x' ? 1 : 0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
nPos++;
|
|
|
|
}while (nPos <= nLast);
|
|
|
|
|
|
|
|
lpfp->permissions = nPermission;
|
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* FTP_SetResponseError (internal)
|
|
|
|
*
|
|
|
|
* Set the appropriate error code for a given response from the server
|
|
|
|
*
|
|
|
|
* RETURNS
|
|
|
|
*
|
|
|
|
*/
|
2005-12-03 18:03:08 +01:00
|
|
|
static DWORD FTP_SetResponseError(DWORD dwResponse)
|
2000-04-11 22:07:00 +02:00
|
|
|
{
|
|
|
|
DWORD dwCode = 0;
|
|
|
|
|
|
|
|
switch(dwResponse)
|
|
|
|
{
|
2007-10-31 22:53:51 +01:00
|
|
|
case 425: /* Cannot open data connection. */
|
|
|
|
dwCode = ERROR_INTERNET_CANNOT_CONNECT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 426: /* Connection closed, transer aborted. */
|
|
|
|
dwCode = ERROR_INTERNET_CONNECTION_ABORTED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 530: /* Not logged in. Login incorrect. */
|
|
|
|
dwCode = ERROR_INTERNET_LOGIN_FAILURE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 421: /* Service not available - Server may be shutting down. */
|
|
|
|
case 450: /* File action not taken. File may be busy. */
|
|
|
|
case 451: /* Action aborted. Server error. */
|
|
|
|
case 452: /* Action not taken. Insufficient storage space on server. */
|
|
|
|
case 500: /* Syntax error. Command unrecognized. */
|
|
|
|
case 501: /* Syntax error. Error in parameters or arguments. */
|
|
|
|
case 502: /* Command not implemented. */
|
|
|
|
case 503: /* Bad sequence of commands. */
|
|
|
|
case 504: /* Command not implemented for that parameter. */
|
|
|
|
case 532: /* Need account for storing files */
|
|
|
|
case 550: /* File action not taken. File not found or no access. */
|
|
|
|
case 551: /* Requested action aborted. Page type unknown */
|
|
|
|
case 552: /* Action aborted. Exceeded storage allocation */
|
|
|
|
case 553: /* Action not taken. File name not allowed. */
|
|
|
|
|
|
|
|
default:
|
|
|
|
dwCode = ERROR_INTERNET_EXTENDED_ERROR;
|
|
|
|
break;
|
2000-04-11 22:07:00 +02:00
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
2000-04-11 22:07:00 +02:00
|
|
|
INTERNET_SetLastError(dwCode);
|
|
|
|
return dwCode;
|
|
|
|
}
|