ReactOS 0.4.15-dev-8131-g4988de4
ftp.c File Reference
#include "ws2tcpip.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <assert.h>
#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
#include "winuser.h"
#include "wininet.h"
#include "winnls.h"
#include "winerror.h"
#include "winreg.h"
#include "winternl.h"
#include "shlwapi.h"
#include "wine/debug.h"
#include "internet.h"
Include dependency graph for ftp.c:

Go to the source code of this file.

Classes

struct  ftp_file_t
 
struct  _ftp_session_t
 
struct  FILEPROPERTIESW
 
struct  WININETFTPFINDNEXTW
 
struct  put_file_task_t
 
struct  directory_task_t
 
struct  find_first_file_task_t
 
struct  get_current_dir_task_t
 
struct  open_file_task_t
 
struct  get_file_task_t
 
struct  delete_file_task_t
 
struct  rename_file_task_t
 
struct  find_next_task_t
 

Macros

#define RESPONSE_TIMEOUT   30
 
#define DATA_PACKET_SIZE   0x2000
 
#define szCRLF   "\r\n"
 
#define MAX_BACKLOG   5
 
#define FTP_CONDITION_MASK   0x0007
 

Typedefs

typedef struct _ftp_session_t ftp_session_t
 
typedef struct FILEPROPERTIESWLPFILEPROPERTIESW
 
typedef struct WININETFTPFINDNEXTWLPWININETFTPFINDNEXTW
 

Enumerations

enum  FTP_COMMAND {
  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 , FTP_CMD_SIZE , FTP_CMD_ABOR , FTP_CMD_LIST ,
  FTP_CMD_NLST , FTP_CMD_PASV , FTP_CMD_PWD , FTP_CMD_QUIT
}
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (wininet)
 
static BOOL FTP_SendCommand (INT nSocket, FTP_COMMAND ftpCmd, LPCWSTR lpszParam, INTERNET_STATUS_CALLBACK lpfnStatusCB, object_header_t *hdr, DWORD_PTR dwContext)
 
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 *)
 
static BOOL FTP_ParsePermission (LPCSTR lpszPermission, LPFILEPROPERTIESW lpfp)
 
static BOOL FTP_ParseNextFile (INT nSocket, LPCWSTR lpszSearchFile, LPFILEPROPERTIESW fileprop)
 
static BOOL FTP_ParseDirectory (ftp_session_t *, INT nSocket, LPCWSTR lpszSearchFile, LPFILEPROPERTIESW *lpafp, LPDWORD dwfp)
 
static HINTERNET FTP_ReceiveFileList (ftp_session_t *, INT nSocket, LPCWSTR lpszSearchFile, LPWIN32_FIND_DATAW lpFindFileData, DWORD_PTR dwContext)
 
static DWORD FTP_SetResponseError (DWORD dwResponse)
 
static BOOL FTP_ConvertFileProp (LPFILEPROPERTIESW lpafp, LPWIN32_FIND_DATAW lpFindFileData)
 
static BOOL FTP_FtpPutFileW (ftp_session_t *, LPCWSTR lpszLocalFile, LPCWSTR lpszNewRemoteFile, DWORD dwFlags, DWORD_PTR dwContext)
 
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 *, LPCWSTR lpszSearchFile, LPWIN32_FIND_DATAW lpFindFileData, DWORD dwFlags, DWORD_PTR dwContext)
 
static BOOL FTP_FtpGetCurrentDirectoryW (ftp_session_t *, LPWSTR lpszCurrentDirectory, LPDWORD lpdwCurrentDirectory)
 
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, BOOL fFailIfExists, DWORD dwLocalFlagsAttribute, DWORD dwInternetFlags, DWORD_PTR dwContext)
 
static BOOL res_to_le (DWORD res)
 
BOOL WINAPI FtpPutFileA (HINTERNET hConnect, LPCSTR lpszLocalFile, LPCSTR lpszNewRemoteFile, DWORD dwFlags, DWORD_PTR dwContext)
 
static void AsyncFtpPutFileProc (task_header_t *hdr)
 
BOOL WINAPI FtpPutFileW (HINTERNET hConnect, LPCWSTR lpszLocalFile, LPCWSTR lpszNewRemoteFile, DWORD dwFlags, DWORD_PTR dwContext)
 
BOOL WINAPI FtpSetCurrentDirectoryA (HINTERNET hConnect, LPCSTR lpszDirectory)
 
static void AsyncFtpSetCurrentDirectoryProc (task_header_t *hdr)
 
BOOL WINAPI FtpSetCurrentDirectoryW (HINTERNET hConnect, LPCWSTR lpszDirectory)
 
BOOL WINAPI FtpCreateDirectoryA (HINTERNET hConnect, LPCSTR lpszDirectory)
 
static void AsyncFtpCreateDirectoryProc (task_header_t *hdr)
 
BOOL WINAPI FtpCreateDirectoryW (HINTERNET hConnect, LPCWSTR lpszDirectory)
 
HINTERNET WINAPI FtpFindFirstFileA (HINTERNET hConnect, LPCSTR lpszSearchFile, LPWIN32_FIND_DATAA lpFindFileData, DWORD dwFlags, DWORD_PTR dwContext)
 
static void AsyncFtpFindFirstFileProc (task_header_t *hdr)
 
HINTERNET WINAPI FtpFindFirstFileW (HINTERNET hConnect, LPCWSTR lpszSearchFile, LPWIN32_FIND_DATAW lpFindFileData, DWORD dwFlags, DWORD_PTR dwContext)
 
BOOL WINAPI FtpGetCurrentDirectoryA (HINTERNET hFtpSession, LPSTR lpszCurrentDirectory, LPDWORD lpdwCurrentDirectory)
 
static void AsyncFtpGetCurrentDirectoryProc (task_header_t *hdr)
 
BOOL WINAPI FtpGetCurrentDirectoryW (HINTERNET hFtpSession, LPWSTR lpszCurrentDirectory, LPDWORD lpdwCurrentDirectory)
 
static void FTPFILE_Destroy (object_header_t *hdr)
 
static DWORD FTPFILE_QueryOption (object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
 
static DWORD FTPFILE_ReadFile (object_header_t *hdr, void *buffer, DWORD size, DWORD *read, DWORD flags, DWORD_PTR context)
 
static DWORD FTPFILE_WriteFile (object_header_t *hdr, const void *buffer, DWORD size, DWORD *written)
 
static void FTP_ReceiveRequestData (ftp_file_t *file, BOOL first_notif)
 
static void FTPFILE_AsyncQueryDataAvailableProc (task_header_t *task)
 
static DWORD FTPFILE_QueryDataAvailable (object_header_t *hdr, DWORD *available, DWORD flags, DWORD_PTR ctx)
 
static DWORD FTPFILE_LockRequestFile (object_header_t *hdr, req_file_t **ret)
 
static HINTERNET FTP_FtpOpenFileW (ftp_session_t *lpwfs, LPCWSTR lpszFileName, DWORD fdwAccess, DWORD dwFlags, DWORD_PTR dwContext)
 
HINTERNET WINAPI FtpOpenFileA (HINTERNET hFtpSession, LPCSTR lpszFileName, DWORD fdwAccess, DWORD dwFlags, DWORD_PTR dwContext)
 
static void AsyncFtpOpenFileProc (task_header_t *hdr)
 
HINTERNET WINAPI FtpOpenFileW (HINTERNET hFtpSession, LPCWSTR lpszFileName, DWORD fdwAccess, DWORD dwFlags, DWORD_PTR dwContext)
 
BOOL WINAPI FtpGetFileA (HINTERNET hInternet, LPCSTR lpszRemoteFile, LPCSTR lpszNewFile, BOOL fFailIfExists, DWORD dwLocalFlagsAttribute, DWORD dwInternetFlags, DWORD_PTR dwContext)
 
static void AsyncFtpGetFileProc (task_header_t *hdr)
 
BOOL WINAPI FtpGetFileW (HINTERNET hInternet, LPCWSTR lpszRemoteFile, LPCWSTR lpszNewFile, BOOL fFailIfExists, DWORD dwLocalFlagsAttribute, DWORD dwInternetFlags, DWORD_PTR dwContext)
 
DWORD WINAPI FtpGetFileSize (HINTERNET hFile, LPDWORD lpdwFileSizeHigh)
 
BOOL WINAPI FtpDeleteFileA (HINTERNET hFtpSession, LPCSTR lpszFileName)
 
static void AsyncFtpDeleteFileProc (task_header_t *hdr)
 
BOOL WINAPI FtpDeleteFileW (HINTERNET hFtpSession, LPCWSTR lpszFileName)
 
BOOL WINAPI FtpRemoveDirectoryA (HINTERNET hFtpSession, LPCSTR lpszDirectory)
 
static void AsyncFtpRemoveDirectoryProc (task_header_t *hdr)
 
BOOL WINAPI FtpRemoveDirectoryW (HINTERNET hFtpSession, LPCWSTR lpszDirectory)
 
BOOL WINAPI FtpRenameFileA (HINTERNET hFtpSession, LPCSTR lpszSrc, LPCSTR lpszDest)
 
static void AsyncFtpRenameFileProc (task_header_t *hdr)
 
BOOL WINAPI FtpRenameFileW (HINTERNET hFtpSession, LPCWSTR lpszSrc, LPCWSTR lpszDest)
 
BOOL WINAPI FtpCommandA (HINTERNET hConnect, BOOL fExpectResponse, DWORD dwFlags, LPCSTR lpszCommand, DWORD_PTR dwContext, HINTERNET *phFtpCommand)
 
BOOL WINAPI FtpCommandW (HINTERNET hConnect, BOOL fExpectResponse, DWORD dwFlags, LPCWSTR lpszCommand, DWORD_PTR dwContext, HINTERNET *phFtpCommand)
 
static void FTPSESSION_Destroy (object_header_t *hdr)
 
static void FTPSESSION_CloseConnection (object_header_t *hdr)
 
static DWORD FTPSESSION_QueryOption (object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
 
HINTERNET FTP_Connect (appinfo_t *hIC, LPCWSTR lpszServerName, INTERNET_PORT nServerPort, LPCWSTR lpszUserName, LPCWSTR lpszPassword, DWORD dwFlags, DWORD_PTR dwContext, DWORD dwInternalFlags)
 
static LPSTR FTP_GetNextLine (INT nSocket, LPDWORD dwLen)
 
static BOOL FTP_SendCommandA (INT nSocket, FTP_COMMAND ftpCmd, LPCSTR lpszParam, INTERNET_STATUS_CALLBACK lpfnStatusCB, object_header_t *hdr, DWORD_PTR dwContext)
 
static void FTPFINDNEXT_Destroy (object_header_t *hdr)
 
static DWORD FTPFINDNEXT_FindNextFileProc (WININETFTPFINDNEXTW *find, LPVOID data)
 
static void FTPFINDNEXT_AsyncFindNextFileProc (task_header_t *hdr)
 
static DWORD FTPFINDNEXT_QueryOption (object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
 
static DWORD FTPFINDNEXT_FindNextFileW (object_header_t *hdr, void *data)
 

Variables

static const CHAR *const szFtpCommands []
 
static const CHAR szMonths [] = "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC"
 
static const object_vtbl_t FTPFILEVtbl
 
static const object_vtbl_t FTPSESSIONVtbl
 
static const object_vtbl_t FTPFINDNEXTVtbl
 

Macro Definition Documentation

◆ DATA_PACKET_SIZE

#define DATA_PACKET_SIZE   0x2000

Definition at line 107 of file ftp.c.

◆ FTP_CONDITION_MASK

#define FTP_CONDITION_MASK   0x0007

Definition at line 114 of file ftp.c.

◆ MAX_BACKLOG

#define MAX_BACKLOG   5

Definition at line 109 of file ftp.c.

◆ RESPONSE_TIMEOUT

#define RESPONSE_TIMEOUT   30

Definition at line 59 of file ftp.c.

◆ szCRLF

#define szCRLF   "\r\n"

Definition at line 108 of file ftp.c.

Typedef Documentation

◆ ftp_session_t

Definition at line 61 of file ftp.c.

◆ LPFILEPROPERTIESW

◆ LPWININETFTPFINDNEXTW

Enumeration Type Documentation

◆ FTP_COMMAND

Enumerator
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 
FTP_CMD_SIZE 
FTP_CMD_ABOR 
FTP_CMD_LIST 
FTP_CMD_NLST 
FTP_CMD_PASV 
FTP_CMD_PWD 
FTP_CMD_QUIT 

Definition at line 116 of file ftp.c.

116 {
117 /* FTP commands with arguments. */
132
133 /* FTP commands without arguments. */
FTP_COMMAND
Definition: ftp.c:116
@ FTP_CMD_RETR
Definition: ftp.c:124
@ FTP_CMD_PORT
Definition: ftp.c:123
@ FTP_CMD_RNTO
Definition: ftp.c:127
@ FTP_CMD_LIST
Definition: ftp.c:135
@ FTP_CMD_SIZE
Definition: ftp.c:131
@ FTP_CMD_RNFR
Definition: ftp.c:126
@ FTP_CMD_PWD
Definition: ftp.c:138
@ FTP_CMD_MKD
Definition: ftp.c:121
@ FTP_CMD_RMD
Definition: ftp.c:125
@ FTP_CMD_QUIT
Definition: ftp.c:139
@ FTP_CMD_ABOR
Definition: ftp.c:134
@ FTP_CMD_CWD
Definition: ftp.c:119
@ FTP_CMD_PASS
Definition: ftp.c:122
@ FTP_CMD_DELE
Definition: ftp.c:120
@ FTP_CMD_TYPE
Definition: ftp.c:129
@ FTP_CMD_PASV
Definition: ftp.c:137
@ FTP_CMD_ACCT
Definition: ftp.c:118
@ FTP_CMD_STOR
Definition: ftp.c:128
@ FTP_CMD_NLST
Definition: ftp.c:136
@ FTP_CMD_USER
Definition: ftp.c:130

Function Documentation

◆ AsyncFtpCreateDirectoryProc()

static void AsyncFtpCreateDirectoryProc ( task_header_t hdr)
static

Definition at line 578 of file ftp.c.

579{
582
583 TRACE(" %p\n", session);
584
586 heap_free(task->directory);
587}
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
static BOOL FTP_FtpCreateDirectoryW(ftp_session_t *, LPCWSTR lpszDirectory)
Definition: ftp.c:661
char hdr[14]
Definition: iptest.cpp:33
#define TRACE(s)
Definition: solgame.cpp:4
WCHAR * directory
Definition: ftp.c:432
task_header_t hdr
Definition: ftp.c:431
object_header_t * hdr
Definition: internet.h:390

Referenced by FtpCreateDirectoryW().

◆ AsyncFtpDeleteFileProc()

static void AsyncFtpDeleteFileProc ( task_header_t hdr)
static

Definition at line 1793 of file ftp.c.

1794{
1797
1798 TRACE("%p\n", session);
1799
1801 heap_free(task->file_name);
1802}
static BOOL FTP_FtpDeleteFileW(ftp_session_t *, LPCWSTR lpszFileName)
Definition: ftp.c:1876
WCHAR * file_name
Definition: ftp.c:1790
task_header_t hdr
Definition: ftp.c:1789

Referenced by FtpDeleteFileW().

◆ AsyncFtpFindFirstFileProc()

static void AsyncFtpFindFirstFileProc ( task_header_t hdr)
static

Definition at line 736 of file ftp.c.

737{
740
741 TRACE("%p\n", session);
742
744 heap_free(task->search_file);
745}
static HINTERNET FTP_FtpFindFirstFileW(ftp_session_t *, LPCWSTR lpszSearchFile, LPWIN32_FIND_DATAW lpFindFileData, DWORD dwFlags, DWORD_PTR dwContext)
Definition: ftp.c:814
task_header_t hdr
Definition: ftp.c:729
WIN32_FIND_DATAW * find_file_data
Definition: ftp.c:731
WCHAR * search_file
Definition: ftp.c:730
DWORD_PTR context
Definition: ftp.c:733

Referenced by FtpFindFirstFileW().

◆ AsyncFtpGetCurrentDirectoryProc()

static void AsyncFtpGetCurrentDirectoryProc ( task_header_t hdr)
static

Definition at line 951 of file ftp.c.

952{
955
956 TRACE("%p\n", session);
957
959}
static BOOL FTP_FtpGetCurrentDirectoryW(ftp_session_t *, LPWSTR lpszCurrentDirectory, LPDWORD lpdwCurrentDirectory)
Definition: ftp.c:1046
DWORD * directory_len
Definition: ftp.c:948
task_header_t hdr
Definition: ftp.c:946
WCHAR * directory
Definition: ftp.c:947

Referenced by FtpGetCurrentDirectoryW().

◆ AsyncFtpGetFileProc()

static void AsyncFtpGetFileProc ( task_header_t hdr)
static

Definition at line 1586 of file ftp.c.

1587{
1590
1591 TRACE("%p\n", session);
1592
1594 task->local_attr, task->flags, task->context);
1595 heap_free(task->remote_file);
1596 heap_free(task->new_file);
1597}
static BOOL FTP_FtpGetFileW(ftp_session_t *, LPCWSTR lpszRemoteFile, LPCWSTR lpszNewFile, BOOL fFailIfExists, DWORD dwLocalFlagsAttribute, DWORD dwInternetFlags, DWORD_PTR dwContext)
Definition: ftp.c:1687
DWORD local_attr
Definition: ftp.c:1581
WCHAR * new_file
Definition: ftp.c:1579
task_header_t hdr
Definition: ftp.c:1577
DWORD_PTR context
Definition: ftp.c:1583
DWORD flags
Definition: ftp.c:1582
BOOL fail_if_exists
Definition: ftp.c:1580
WCHAR * remote_file
Definition: ftp.c:1578

Referenced by FtpGetFileW().

◆ AsyncFtpOpenFileProc()

static void AsyncFtpOpenFileProc ( task_header_t hdr)
static

Definition at line 1464 of file ftp.c.

1465{
1468
1469 TRACE("%p\n", session);
1470
1471 FTP_FtpOpenFileW(session, task->file_name, task->access, task->flags, task->context);
1472 heap_free(task->file_name);
1473}
static HINTERNET FTP_FtpOpenFileW(ftp_session_t *lpwfs, LPCWSTR lpszFileName, DWORD fdwAccess, DWORD dwFlags, DWORD_PTR dwContext)
Definition: ftp.c:1317
task_header_t hdr
Definition: ftp.c:1457
WCHAR * file_name
Definition: ftp.c:1458
DWORD_PTR context
Definition: ftp.c:1461
DWORD flags
Definition: ftp.c:1460
DWORD access
Definition: ftp.c:1459

Referenced by FtpOpenFileW().

◆ AsyncFtpPutFileProc()

static void AsyncFtpPutFileProc ( task_header_t hdr)
static

Definition at line 248 of file ftp.c.

249{
252
253 TRACE("%p\n", session);
254
256 task->flags, task->context);
257
258 heap_free(task->local_file);
259 heap_free(task->remote_file);
260}
static BOOL FTP_FtpPutFileW(ftp_session_t *, LPCWSTR lpszLocalFile, LPCWSTR lpszNewRemoteFile, DWORD dwFlags, DWORD_PTR dwContext)
Definition: ftp.c:344
task_header_t hdr
Definition: ftp.c:241
DWORD_PTR context
Definition: ftp.c:245
WCHAR * remote_file
Definition: ftp.c:243
WCHAR * local_file
Definition: ftp.c:242
DWORD flags
Definition: ftp.c:244

Referenced by FtpPutFileW().

◆ AsyncFtpRemoveDirectoryProc()

static void AsyncFtpRemoveDirectoryProc ( task_header_t hdr)
static

Definition at line 1935 of file ftp.c.

1936{
1939
1940 TRACE("%p\n", session);
1941
1943 heap_free(task->directory);
1944}
static BOOL FTP_FtpRemoveDirectoryW(ftp_session_t *, LPCWSTR lpszDirectory)
Definition: ftp.c:2018

Referenced by FtpRemoveDirectoryW().

◆ AsyncFtpRenameFileProc()

static void AsyncFtpRenameFileProc ( task_header_t hdr)
static

Definition at line 2087 of file ftp.c.

2088{
2091
2092 TRACE("%p\n", session);
2093
2095 heap_free(task->src_file);
2096 heap_free(task->dst_file);
2097}
static BOOL FTP_FtpRenameFileW(ftp_session_t *, LPCWSTR lpszSrc, LPCWSTR lpszDest)
Definition: ftp.c:2172
WCHAR * dst_file
Definition: ftp.c:2084
task_header_t hdr
Definition: ftp.c:2082
WCHAR * src_file
Definition: ftp.c:2083

Referenced by FtpRenameFileW().

◆ AsyncFtpSetCurrentDirectoryProc()

static void AsyncFtpSetCurrentDirectoryProc ( task_header_t hdr)
static

Definition at line 435 of file ftp.c.

436{
439
440 TRACE("%p\n", session);
441
443 heap_free(task->directory);
444}
static BOOL FTP_FtpSetCurrentDirectoryW(ftp_session_t *, LPCWSTR lpszDirectory)
Definition: ftp.c:516

Referenced by FtpSetCurrentDirectoryW().

◆ FTP_Connect()

HINTERNET FTP_Connect ( appinfo_t hIC,
LPCWSTR  lpszServerName,
INTERNET_PORT  nServerPort,
LPCWSTR  lpszUserName,
LPCWSTR  lpszPassword,
DWORD  dwFlags,
DWORD_PTR  dwContext,
DWORD  dwInternalFlags 
)

Definition at line 2428 of file ftp.c.

2432{
2433 struct sockaddr_in socketAddr;
2434 INT nsocket = -1;
2435 socklen_t sock_namelen;
2437 ftp_session_t *lpwfs = NULL;
2438 char szaddr[INET6_ADDRSTRLEN];
2439
2440 TRACE("%p Server(%s) Port(%d) User(%s) Paswd(%s)\n",
2441 hIC, debugstr_w(lpszServerName),
2442 nServerPort, debugstr_w(lpszUserName), debugstr_w(lpszPassword));
2443
2444 assert( hIC->hdr.htype == WH_HINIT );
2445
2446 if ((!lpszUserName || !*lpszUserName) && lpszPassword && *lpszPassword)
2447 {
2449 return NULL;
2450 }
2451
2452 lpwfs = alloc_object(&hIC->hdr, &FTPSESSIONVtbl, sizeof(ftp_session_t));
2453 if (NULL == lpwfs)
2454 {
2456 return NULL;
2457 }
2458
2459 if (nServerPort == INTERNET_INVALID_PORT_NUMBER)
2461 else
2462 lpwfs->serverport = nServerPort;
2463
2464 lpwfs->hdr.htype = WH_HFTPSESSION;
2465 lpwfs->hdr.dwFlags = dwFlags;
2466 lpwfs->hdr.dwContext = dwContext;
2467 lpwfs->hdr.dwInternalFlags |= dwInternalFlags;
2468 lpwfs->download_in_progress = NULL;
2469 lpwfs->sndSocket = -1;
2470 lpwfs->lstnSocket = -1;
2471 lpwfs->pasvSocket = -1;
2472
2473 WININET_AddRef( &hIC->hdr );
2474 lpwfs->lpAppInfo = hIC;
2475 list_add_head( &hIC->hdr.children, &lpwfs->hdr.entry );
2476
2477 if(hIC->proxy && hIC->accessType == INTERNET_OPEN_TYPE_PROXY) {
2478 if(wcschr(hIC->proxy, ' '))
2479 FIXME("Several proxies not implemented.\n");
2480 if(hIC->proxyBypass)
2481 FIXME("Proxy bypass is ignored.\n");
2482 }
2483 if (!lpszUserName || !lpszUserName[0]) {
2484 HKEY key;
2485 WCHAR szPassword[MAX_PATH];
2486 DWORD len = sizeof(szPassword);
2487
2488 lpwfs->lpszUserName = heap_strdupW(L"anonymous");
2489
2490 RegOpenKeyW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", &key);
2491 if (RegQueryValueExW(key, L"EmailName", NULL, NULL, (LPBYTE)szPassword, &len)) {
2492 /* Nothing in the registry, get the username and use that as the password */
2493 if (!GetUserNameW(szPassword, &len)) {
2494 /* Should never get here, but use an empty password as failsafe */
2495 lstrcpyW(szPassword, L"");
2496 }
2497 }
2499
2500 TRACE("Password used for anonymous ftp : (%s)\n", debugstr_w(szPassword));
2501 lpwfs->lpszPassword = heap_strdupW(szPassword);
2502 }
2503 else {
2504 lpwfs->lpszUserName = heap_strdupW(lpszUserName);
2506 }
2507 lpwfs->servername = heap_strdupW(lpszServerName);
2508
2509 /* Don't send a handle created callback if this handle was created with InternetOpenUrl */
2510 if (!(lpwfs->hdr.dwInternalFlags & INET_OPENURL))
2511 {
2513
2514 iar.dwResult = (DWORD_PTR)lpwfs->hdr.hInternet;
2515 iar.dwError = ERROR_SUCCESS;
2516
2517 INTERNET_SendCallback(&hIC->hdr, dwContext,
2519 sizeof(INTERNET_ASYNC_RESULT));
2520 }
2521
2523 (LPWSTR) lpszServerName, (lstrlenW(lpszServerName)+1) * sizeof(WCHAR));
2524
2525 sock_namelen = sizeof(socketAddr);
2526 if (!GetAddress(lpszServerName, lpwfs->serverport, (struct sockaddr *)&socketAddr, &sock_namelen, szaddr))
2527 {
2529 goto lerror;
2530 }
2531
2532 if (socketAddr.sin_family != AF_INET)
2533 {
2534 WARN("unsupported address family %d\n", socketAddr.sin_family);
2536 goto lerror;
2537 }
2538
2540 szaddr, strlen(szaddr)+1);
2541
2542 init_winsock();
2543 nsocket = socket(AF_INET,SOCK_STREAM,0);
2544 if (nsocket == -1)
2545 {
2547 goto lerror;
2548 }
2549
2551 szaddr, strlen(szaddr)+1);
2552
2553 if (connect(nsocket, (struct sockaddr *)&socketAddr, sock_namelen) < 0)
2554 {
2555 ERR("Unable to connect (%d)\n", WSAGetLastError());
2557 closesocket(nsocket);
2558 }
2559 else
2560 {
2561 TRACE("Connected to server\n");
2562 lpwfs->sndSocket = nsocket;
2564 szaddr, strlen(szaddr)+1);
2565
2566 sock_namelen = sizeof(lpwfs->socketAddress);
2567 getsockname(nsocket, (struct sockaddr *) &lpwfs->socketAddress, &sock_namelen);
2568
2569 if (FTP_ConnectToHost(lpwfs))
2570 {
2571 TRACE("Successfully logged into server\n");
2572 bSuccess = TRUE;
2573 }
2574 }
2575
2576lerror:
2577 if (!bSuccess)
2578 {
2579 WININET_Release(&lpwfs->hdr);
2580 return NULL;
2581 }
2582
2583 return lpwfs->hdr.hInternet;
2584}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static void list_add_head(struct list_entry *head, struct list_entry *entry)
Definition: list.h:76
#define FIXME(fmt,...)
Definition: debug.h:114
#define WARN(fmt,...)
Definition: debug.h:115
#define ERR(fmt,...)
Definition: debug.h:113
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
LONG WINAPI RegOpenKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3268
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
BOOL WINAPI GetUserNameW(LPWSTR lpszName, LPDWORD lpSize)
Definition: misc.c:291
static WCHAR * heap_strdupW(const WCHAR *str)
Definition: propsheet.c:178
#define wcschr
Definition: compat.h:17
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define MAX_PATH
Definition: compat.h:34
#define lstrcpyW
Definition: compat.h:749
#define lstrlenW
Definition: compat.h:750
static const object_vtbl_t FTPSESSIONVtbl
Definition: ftp.c:2396
static BOOL FTP_ConnectToHost(ftp_session_t *)
Definition: ftp.c:2597
BOOL WININET_Release(object_header_t *info)
Definition: internet.c:211
object_header_t * WININET_AddRef(object_header_t *info)
Definition: internet.c:169
void INTERNET_SetLastError(DWORD dwError)
Definition: internet.c:3837
void * alloc_object(object_header_t *parent, const object_vtbl_t *vtbl, size_t size)
Definition: internet.c:103
#define assert(x)
Definition: debug.h:53
static BOOLEAN bSuccess
Definition: drive.cpp:433
#define SOCK_STREAM
Definition: tcpip.h:118
#define AF_INET
Definition: tcpip.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLenum GLsizei len
Definition: glext.h:6722
void init_winsock(void) DECLSPEC_HIDDEN
#define INET_OPENURL
Definition: internet.h:243
@ WH_HFTPSESSION
Definition: internet.h:235
@ WH_HINIT
Definition: internet.h:234
BOOL GetAddress(const WCHAR *, INTERNET_PORT, SOCKADDR *, int *, char *) DECLSPEC_HIDDEN
Definition: utility.c:133
VOID INTERNET_SendCallback(object_header_t *hdr, DWORD_PTR dwContext, DWORD dwInternetStatus, LPVOID lpvStatusInfo, DWORD dwStatusInfoLength) DECLSPEC_HIDDEN
#define debugstr_w
Definition: kernel32.h:32
int socklen_t
Definition: tcp.c:35
#define closesocket
Definition: ncftp.h:477
#define L(x)
Definition: ntvdm.h:50
INT WSAAPI getsockname(IN SOCKET s, OUT LPSOCKADDR name, IN OUT INT FAR *namelen)
Definition: sockctrl.c:213
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
Definition: socklife.c:143
DWORD_PTR dwResult
Definition: wininet.h:155
object_header_t hdr
Definition: ftp.c:75
ftp_file_t * download_in_progress
Definition: ftp.c:80
int lstnSocket
Definition: ftp.c:78
LPWSTR servername
Definition: ftp.c:83
INTERNET_PORT serverport
Definition: ftp.c:84
int pasvSocket
Definition: ftp.c:79
appinfo_t * lpAppInfo
Definition: ftp.c:76
int sndSocket
Definition: ftp.c:77
LPWSTR lpszPassword
Definition: ftp.c:85
struct sockaddr_in socketAddress
Definition: ftp.c:81
LPWSTR lpszUserName
Definition: ftp.c:86
WH_TYPE htype
Definition: internet.h:273
HINTERNET hInternet
Definition: internet.h:275
DWORD dwInternalFlags
Definition: internet.h:281
struct list children
Definition: internet.h:286
struct list entry
Definition: internet.h:285
DWORD_PTR dwContext
Definition: internet.h:278
LPWSTR proxy
Definition: internet.h:293
LPWSTR proxyBypass
Definition: internet.h:294
DWORD accessType
Definition: internet.h:297
object_header_t hdr
Definition: internet.h:291
Definition: copy.c:22
#define DWORD_PTR
Definition: treelist.c:76
unsigned char * LPBYTE
Definition: typedefs.h:53
int32_t INT
Definition: typedefs.h:58
_In_opt_ LPSTR _In_opt_ LPSTR lpszPassword
Definition: winbase.h:2712
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1176
#define INTERNET_DEFAULT_FTP_PORT
Definition: wininet.h:38
#define INTERNET_STATUS_RESOLVING_NAME
Definition: wininet.h:883
#define INTERNET_STATUS_CONNECTING_TO_SERVER
Definition: wininet.h:885
#define INTERNET_OPEN_TYPE_PROXY
Definition: wininet.h:523
#define INTERNET_INVALID_PORT_NUMBER
Definition: wininet.h:36
#define INTERNET_STATUS_HANDLE_CREATED
Definition: wininet.h:895
#define ERROR_INTERNET_CANNOT_CONNECT
Definition: wininet.h:2018
#define ERROR_INTERNET_NAME_NOT_RESOLVED
Definition: wininet.h:1996
#define INTERNET_STATUS_CONNECTED_TO_SERVER
Definition: wininet.h:886
#define INTERNET_STATUS_NAME_RESOLVED
Definition: wininet.h:884
#define HKEY_CURRENT_USER
Definition: winreg.h:11
int PASCAL FAR WSAGetLastError(void)
Definition: dllmain.c:112
#define INET6_ADDRSTRLEN
Definition: ws2ipdef.h:132
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by INTERNET_InternetOpenUrlW(), and InternetConnectW().

◆ FTP_ConnectToHost()

static BOOL FTP_ConnectToHost ( ftp_session_t lpwfs)
static

Definition at line 2597 of file ftp.c.

2598{
2599 INT nResCode;
2601
2602 TRACE("\n");
2603 FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
2604
2605 if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_USER, lpwfs->lpszUserName, 0, 0, 0))
2606 goto lend;
2607
2608 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
2609 if (nResCode)
2610 {
2611 /* Login successful... */
2612 if (nResCode == 230)
2613 bSuccess = TRUE;
2614 /* User name okay, need password... */
2615 else if (nResCode == 331)
2616 bSuccess = FTP_SendPassword(lpwfs);
2617 /* Need account for login... */
2618 else if (nResCode == 332)
2619 bSuccess = FTP_SendAccount(lpwfs);
2620 else
2621 FTP_SetResponseError(nResCode);
2622 }
2623
2624 TRACE("Returning %d\n", bSuccess);
2625lend:
2626 return bSuccess;
2627}
static BOOL FTP_SendPassword(ftp_session_t *)
Definition: ftp.c:2829
static DWORD FTP_SetResponseError(DWORD dwResponse)
Definition: ftp.c:3915
static BOOL FTP_SendAccount(ftp_session_t *)
Definition: ftp.c:2869
static BOOL FTP_SendCommand(INT nSocket, FTP_COMMAND ftpCmd, LPCWSTR lpszParam, INTERNET_STATUS_CALLBACK lpfnStatusCB, object_header_t *hdr, DWORD_PTR dwContext)
Definition: ftp.c:2746
static INT FTP_ReceiveResponse(ftp_session_t *, DWORD_PTR dwContext)
Definition: ftp.c:2766

Referenced by FTP_Connect().

◆ FTP_ConvertFileProp()

static BOOL FTP_ConvertFileProp ( LPFILEPROPERTIESW  lpafp,
LPWIN32_FIND_DATAW  lpFindFileData 
)
static

Definition at line 3589 of file ftp.c.

3590{
3592
3593 ZeroMemory(lpFindFileData, sizeof(WIN32_FIND_DATAW));
3594
3595 if (lpafp)
3596 {
3597 SystemTimeToFileTime( &lpafp->tmLastModified, &lpFindFileData->ftLastAccessTime );
3598 lpFindFileData->ftLastWriteTime = lpFindFileData->ftLastAccessTime;
3599 lpFindFileData->ftCreationTime = lpFindFileData->ftLastAccessTime;
3600
3601 /* Not all fields are filled in */
3602 lpFindFileData->nFileSizeHigh = 0; /* We do not handle files bigger than 0xFFFFFFFF bytes yet :-) */
3603 lpFindFileData->nFileSizeLow = lpafp->nSize;
3604
3605 if (lpafp->bIsDirectory)
3606 lpFindFileData->dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
3607
3608 if (lpafp->lpszName)
3609 lstrcpynW(lpFindFileData->cFileName, lpafp->lpszName, MAX_PATH);
3610
3611 bSuccess = TRUE;
3612 }
3613
3614 return bSuccess;
3615}
#define lstrcpynW
Definition: compat.h:738
BOOL WINAPI SystemTimeToFileTime(IN CONST SYSTEMTIME *lpSystemTime, OUT LPFILETIME lpFileTime)
Definition: time.c:158
#define FILE_ATTRIBUTE_DIRECTORY
Definition: nt_native.h:705
LPWSTR lpszName
Definition: ftp.c:92
SYSTEMTIME tmLastModified
Definition: ftp.c:94
DWORD nSize
Definition: ftp.c:93
BOOL bIsDirectory
Definition: ftp.c:91
FILETIME ftLastWriteTime
Definition: winbase.h:942
WCHAR cFileName[MAX_PATH]
Definition: winbase.h:947
DWORD nFileSizeLow
Definition: winbase.h:944
DWORD nFileSizeHigh
Definition: winbase.h:943
DWORD dwFileAttributes
Definition: winbase.h:939
FILETIME ftLastAccessTime
Definition: winbase.h:941
FILETIME ftCreationTime
Definition: winbase.h:940
#define ZeroMemory
Definition: winbase.h:1712

Referenced by FTP_ReceiveFileList(), and FTPFINDNEXT_FindNextFileProc().

◆ FTP_DoPassive()

static BOOL FTP_DoPassive ( ftp_session_t lpwfs)
static

Definition at line 3131 of file ftp.c.

3132{
3133 INT nResCode;
3135
3136 TRACE("\n");
3137 if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_PASV, NULL, 0, 0, 0))
3138 goto lend;
3139
3140 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
3141 if (nResCode)
3142 {
3143 if (nResCode == 227)
3144 {
3145 LPSTR lpszResponseBuffer = INTERNET_GetResponseBuffer();
3146 LPSTR p;
3147 int f[6];
3148 int i;
3149 char *pAddr, *pPort;
3150 INT nsocket = -1;
3151 struct sockaddr_in dataSocketAddress;
3152
3153 p = lpszResponseBuffer+4; /* skip status code */
3154 while (*p != '\0' && (*p < '0' || *p > '9')) p++;
3155
3156 if (*p == '\0')
3157 {
3158 ERR("no address found in response, aborting\n");
3159 goto lend;
3160 }
3161
3162 if (sscanf(p, "%d,%d,%d,%d,%d,%d", &f[0], &f[1], &f[2], &f[3],
3163 &f[4], &f[5]) != 6)
3164 {
3165 ERR("unknown response address format '%s', aborting\n", p);
3166 goto lend;
3167 }
3168 for (i=0; i < 6; i++)
3169 f[i] = f[i] & 0xff;
3170
3171 dataSocketAddress = lpwfs->socketAddress;
3172 pAddr = (char *)&(dataSocketAddress.sin_addr.S_un.S_addr);
3173 pPort = (char *)&(dataSocketAddress.sin_port);
3174 pAddr[0] = f[0];
3175 pAddr[1] = f[1];
3176 pAddr[2] = f[2];
3177 pAddr[3] = f[3];
3178 pPort[0] = f[4];
3179 pPort[1] = f[5];
3180
3181 nsocket = socket(AF_INET,SOCK_STREAM,0);
3182 if (nsocket == -1)
3183 goto lend;
3184
3185 if (connect(nsocket, (struct sockaddr *)&dataSocketAddress, sizeof(dataSocketAddress)))
3186 {
3187 ERR("can't connect passive FTP data port.\n");
3188 closesocket(nsocket);
3189 goto lend;
3190 }
3191 lpwfs->pasvSocket = nsocket;
3192 bSuccess = TRUE;
3193 }
3194 else
3195 FTP_SetResponseError(nResCode);
3196 }
3197
3198lend:
3199 return bSuccess;
3200}
LPSTR INTERNET_GetResponseBuffer(void)
Definition: internet.c:3937
PWDF_CHILD_ADDRESS_DESCRIPTION_HEADER pAddr
GLfloat f
Definition: glext.h:7540
GLfloat GLfloat p
Definition: glext.h:8902
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
char * LPSTR
Definition: xmlstorage.h:182

Referenced by FTP_SendPortOrPasv().

◆ FTP_FtpCreateDirectoryW()

static BOOL FTP_FtpCreateDirectoryW ( ftp_session_t lpwfs,
LPCWSTR  lpszDirectory 
)
static

Definition at line 661 of file ftp.c.

662{
663 INT nResCode;
665 appinfo_t *hIC = NULL;
666
667 TRACE("lpszDirectory(%s)\n", debugstr_w(lpszDirectory));
668
669 /* Clear any error information */
671
672 if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_MKD, lpszDirectory, 0, 0, 0))
673 goto lend;
674
675 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
676 if (nResCode)
677 {
678 if (nResCode == 257)
679 bSuccess = TRUE;
680 else
681 FTP_SetResponseError(nResCode);
682 }
683
684lend:
685 hIC = lpwfs->lpAppInfo;
687 {
689
690 iar.dwResult = (DWORD)bSuccess;
693 &iar, sizeof(INTERNET_ASYNC_RESULT));
694 }
695
696 return bSuccess;
697}
DWORD INTERNET_GetLastError(void)
Definition: internet.c:3858
#define DWORD
Definition: nt_native.h:44
#define INTERNET_FLAG_ASYNC
Definition: wininet.h:64
#define INTERNET_STATUS_REQUEST_COMPLETE
Definition: wininet.h:898

Referenced by AsyncFtpCreateDirectoryProc(), and FtpCreateDirectoryW().

◆ FTP_FtpDeleteFileW()

BOOL FTP_FtpDeleteFileW ( ftp_session_t lpwfs,
LPCWSTR  lpszFileName 
)
static

Definition at line 1876 of file ftp.c.

1877{
1878 INT nResCode;
1880 appinfo_t *hIC = NULL;
1881
1882 TRACE("%p\n", lpwfs);
1883
1884 /* Clear any error information */
1886
1887 if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_DELE, lpszFileName, 0, 0, 0))
1888 goto lend;
1889
1890 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
1891 if (nResCode)
1892 {
1893 if (nResCode == 250)
1894 bSuccess = TRUE;
1895 else
1896 FTP_SetResponseError(nResCode);
1897 }
1898lend:
1899 hIC = lpwfs->lpAppInfo;
1900 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
1901 {
1903
1904 iar.dwResult = (DWORD)bSuccess;
1907 &iar, sizeof(INTERNET_ASYNC_RESULT));
1908 }
1909
1910 return bSuccess;
1911}

Referenced by AsyncFtpDeleteFileProc(), and FtpDeleteFileW().

◆ FTP_FtpFindFirstFileW()

static HINTERNET FTP_FtpFindFirstFileW ( ftp_session_t lpwfs,
LPCWSTR  lpszSearchFile,
LPWIN32_FIND_DATAW  lpFindFileData,
DWORD  dwFlags,
DWORD_PTR  dwContext 
)
static

Definition at line 814 of file ftp.c.

816{
817 INT nResCode;
818 appinfo_t *hIC = NULL;
819 HINTERNET hFindNext = NULL;
820 LPWSTR lpszSearchPath = NULL;
821
822 TRACE("\n");
823
824 /* Clear any error information */
826
827 if (!FTP_InitListenSocket(lpwfs))
828 goto lend;
829
831 goto lend;
832
833 if (!FTP_SendPortOrPasv(lpwfs))
834 goto lend;
835
836 /* split search path into file and path */
837 if (lpszSearchFile)
838 {
839 LPCWSTR name = lpszSearchFile, p;
840 if ((p = wcsrchr( name, '\\' ))) name = p + 1;
841 if ((p = wcsrchr( name, '/' ))) name = p + 1;
842 if (name != lpszSearchFile)
843 {
844 lpszSearchPath = heap_strndupW(lpszSearchFile, name - lpszSearchFile);
845 lpszSearchFile = name;
846 }
847 }
848
849 if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_LIST, lpszSearchPath,
850 lpwfs->hdr.lpfnStatusCB, &lpwfs->hdr, lpwfs->hdr.dwContext))
851 goto lend;
852
853 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
854 if (nResCode)
855 {
856 if (nResCode == 125 || nResCode == 150)
857 {
858 INT nDataSocket;
859
860 /* Get data socket to server */
861 if (FTP_GetDataSocket(lpwfs, &nDataSocket))
862 {
863 hFindNext = FTP_ReceiveFileList(lpwfs, nDataSocket, lpszSearchFile, lpFindFileData, dwContext);
864 closesocket(nDataSocket);
865 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
866 if (nResCode != 226 && nResCode != 250)
868 }
869 }
870 else
871 FTP_SetResponseError(nResCode);
872 }
873
874lend:
875 heap_free(lpszSearchPath);
876
877 if (lpwfs->lstnSocket != -1)
878 {
879 closesocket(lpwfs->lstnSocket);
880 lpwfs->lstnSocket = -1;
881 }
882
883 hIC = lpwfs->lpAppInfo;
885 {
887
888 if (hFindNext)
889 {
890 iar.dwResult = (DWORD_PTR)hFindNext;
893 &iar, sizeof(INTERNET_ASYNC_RESULT));
894 }
895
896 iar.dwResult = (DWORD_PTR)hFindNext;
897 iar.dwError = hFindNext ? ERROR_SUCCESS : INTERNET_GetLastError();
899 &iar, sizeof(INTERNET_ASYNC_RESULT));
900 }
901
902 return hFindNext;
903}
#define wcsrchr
Definition: compat.h:16
static BOOL FTP_GetDataSocket(ftp_session_t *, LPINT nDataSocket)
Definition: ftp.c:3232
static BOOL FTP_SendType(ftp_session_t *, DWORD dwType)
Definition: ftp.c:3006
static BOOL FTP_InitListenSocket(ftp_session_t *)
Definition: ftp.c:2946
static HINTERNET FTP_ReceiveFileList(ftp_session_t *, INT nSocket, LPCWSTR lpszSearchFile, LPWIN32_FIND_DATAW lpFindFileData, DWORD_PTR dwContext)
Definition: ftp.c:3545
static BOOL FTP_SendPortOrPasv(ftp_session_t *)
Definition: ftp.c:3203
static LPWSTR heap_strndupW(LPCWSTR str, unsigned len)
INTERNET_STATUS_CALLBACK lpfnStatusCB
Definition: internet.h:284
Definition: name.c:39
#define ERROR_NO_MORE_FILES
Definition: winerror.h:121
#define INTERNET_FLAG_TRANSFER_ASCII
Definition: wininet.h:90
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185

Referenced by AsyncFtpFindFirstFileProc(), and FtpFindFirstFileW().

◆ FTP_FtpGetCurrentDirectoryW()

static BOOL FTP_FtpGetCurrentDirectoryW ( ftp_session_t lpwfs,
LPWSTR  lpszCurrentDirectory,
LPDWORD  lpdwCurrentDirectory 
)
static

Definition at line 1046 of file ftp.c.

1048{
1049 INT nResCode;
1050 appinfo_t *hIC = NULL;
1052
1053 /* Clear any error information */
1055
1056 hIC = lpwfs->lpAppInfo;
1058 lpwfs->hdr.lpfnStatusCB, &lpwfs->hdr, lpwfs->hdr.dwContext))
1059 goto lend;
1060
1061 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
1062 if (nResCode)
1063 {
1064 if (nResCode == 257) /* Extract directory name */
1065 {
1066 DWORD firstpos, lastpos, len;
1067 LPWSTR lpszResponseBuffer = heap_strdupAtoW(INTERNET_GetResponseBuffer());
1068
1069 for (firstpos = 0, lastpos = 0; lpszResponseBuffer[lastpos]; lastpos++)
1070 {
1071 if ('"' == lpszResponseBuffer[lastpos])
1072 {
1073 if (!firstpos)
1074 firstpos = lastpos;
1075 else
1076 break;
1077 }
1078 }
1079 len = lastpos - firstpos;
1080 if (*lpdwCurrentDirectory >= len)
1081 {
1082 memcpy(lpszCurrentDirectory, &lpszResponseBuffer[firstpos + 1], len * sizeof(WCHAR));
1083 lpszCurrentDirectory[len - 1] = 0;
1084 *lpdwCurrentDirectory = len;
1085 bSuccess = TRUE;
1086 }
1088
1089 heap_free(lpszResponseBuffer);
1090 }
1091 else
1092 FTP_SetResponseError(nResCode);
1093 }
1094
1095lend:
1096 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
1097 {
1099
1100 iar.dwResult = bSuccess;
1103 &iar, sizeof(INTERNET_ASYNC_RESULT));
1104 }
1105
1106 return bSuccess;
1107}
static WCHAR * heap_strdupAtoW(const char *str)
Definition: appwiz.h:81
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define ERROR_INTERNET_EXTENDED_ERROR
Definition: wininet.h:1992

Referenced by AsyncFtpGetCurrentDirectoryProc(), and FtpGetCurrentDirectoryW().

◆ FTP_FtpGetFileW()

static BOOL FTP_FtpGetFileW ( ftp_session_t lpwfs,
LPCWSTR  lpszRemoteFile,
LPCWSTR  lpszNewFile,
BOOL  fFailIfExists,
DWORD  dwLocalFlagsAttribute,
DWORD  dwInternetFlags,
DWORD_PTR  dwContext 
)
static

Definition at line 1687 of file ftp.c.

1690{
1692 HANDLE hFile;
1693 appinfo_t *hIC = NULL;
1694
1695 TRACE("lpszRemoteFile(%s) lpszNewFile(%s)\n", debugstr_w(lpszRemoteFile), debugstr_w(lpszNewFile));
1696
1697 /* Clear any error information */
1699
1700 /* Ensure we can write to lpszNewfile by opening it */
1701 hFile = CreateFileW(lpszNewFile, GENERIC_WRITE, 0, 0, fFailIfExists ?
1702 CREATE_NEW : CREATE_ALWAYS, dwLocalFlagsAttribute, 0);
1704 return FALSE;
1705
1706 /* Set up socket to retrieve data */
1707 if (FTP_SendRetrieve(lpwfs, lpszRemoteFile, dwInternetFlags))
1708 {
1709 INT nDataSocket;
1710
1711 /* Get data socket to server */
1712 if (FTP_GetDataSocket(lpwfs, &nDataSocket))
1713 {
1714 INT nResCode;
1715
1716 /* Receive data */
1717 FTP_RetrieveFileData(lpwfs, nDataSocket, hFile);
1718 closesocket(nDataSocket);
1719
1720 nResCode = FTP_ReceiveResponse(lpwfs, dwContext);
1721 if (nResCode)
1722 {
1723 if (nResCode == 226)
1724 bSuccess = TRUE;
1725 else
1726 FTP_SetResponseError(nResCode);
1727 }
1728 }
1729 }
1730
1731 if (lpwfs->lstnSocket != -1)
1732 {
1733 closesocket(lpwfs->lstnSocket);
1734 lpwfs->lstnSocket = -1;
1735 }
1736
1738
1739 hIC = lpwfs->lpAppInfo;
1740 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
1741 {
1743
1744 iar.dwResult = (DWORD)bSuccess;
1747 &iar, sizeof(INTERNET_ASYNC_RESULT));
1748 }
1749
1750 if (!bSuccess) DeleteFileW(lpszNewFile);
1751 return bSuccess;
1752}
#define CloseHandle
Definition: compat.h:739
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileW
Definition: compat.h:741
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
static BOOL FTP_SendRetrieve(ftp_session_t *, LPCWSTR lpszRemoteFile, DWORD dwType)
Definition: ftp.c:3343
static BOOL FTP_RetrieveFileData(ftp_session_t *, INT nDataSocket, HANDLE hFile)
Definition: ftp.c:3389
#define CREATE_ALWAYS
Definition: disk.h:72
#define CREATE_NEW
Definition: disk.h:69
_In_ HANDLE hFile
Definition: mswsock.h:90
#define GENERIC_WRITE
Definition: nt_native.h:90

Referenced by AsyncFtpGetFileProc(), and FtpGetFileW().

◆ FTP_FtpOpenFileW()

static HINTERNET FTP_FtpOpenFileW ( ftp_session_t lpwfs,
LPCWSTR  lpszFileName,
DWORD  fdwAccess,
DWORD  dwFlags,
DWORD_PTR  dwContext 
)
static

Definition at line 1317 of file ftp.c.

1320{
1321 INT nDataSocket;
1323 ftp_file_t *lpwh = NULL;
1324 appinfo_t *hIC = NULL;
1325
1326 TRACE("\n");
1327
1328 /* Clear any error information */
1330
1331 if (GENERIC_READ == fdwAccess)
1332 {
1333 /* Set up socket to retrieve data */
1334 bSuccess = FTP_SendRetrieve(lpwfs, lpszFileName, dwFlags);
1335 }
1336 else if (GENERIC_WRITE == fdwAccess)
1337 {
1338 /* Set up socket to send data */
1339 bSuccess = FTP_SendStore(lpwfs, lpszFileName, dwFlags);
1340 }
1341
1342 /* Get data socket to server */
1343 if (bSuccess && FTP_GetDataSocket(lpwfs, &nDataSocket))
1344 {
1345 lpwh = alloc_object(&lpwfs->hdr, &FTPFILEVtbl, sizeof(ftp_file_t));
1346 lpwh->hdr.htype = WH_HFILE;
1347 lpwh->hdr.dwFlags = dwFlags;
1348 lpwh->hdr.dwContext = dwContext;
1349 lpwh->nDataSocket = nDataSocket;
1350 lpwh->cache_file = NULL;
1352 lpwh->session_deleted = FALSE;
1353
1354 WININET_AddRef( &lpwfs->hdr );
1355 lpwh->lpFtpSession = lpwfs;
1356 list_add_head( &lpwfs->hdr.children, &lpwh->hdr.entry );
1357
1358 /* Indicate that a download is currently in progress */
1359 lpwfs->download_in_progress = lpwh;
1360 }
1361
1362 if (lpwfs->lstnSocket != -1)
1363 {
1364 closesocket(lpwfs->lstnSocket);
1365 lpwfs->lstnSocket = -1;
1366 }
1367
1368 if (bSuccess && fdwAccess == GENERIC_READ)
1369 {
1370 WCHAR filename[MAX_PATH + 1];
1371 URL_COMPONENTSW uc;
1372 DWORD len;
1373
1374 memset(&uc, 0, sizeof(uc));
1375 uc.dwStructSize = sizeof(uc);
1377 uc.lpszHostName = lpwfs->servername;
1378 uc.nPort = lpwfs->serverport;
1379 uc.lpszUserName = lpwfs->lpszUserName;
1380 uc.lpszUrlPath = heap_strdupW(lpszFileName);
1381
1383 {
1384 WCHAR *url = heap_alloc(len * sizeof(WCHAR));
1385
1386 if (url && InternetCreateUrlW(&uc, 0, url, &len) && CreateUrlCacheEntryW(url, 0, NULL, filename, 0))
1387 {
1392 {
1393 WARN("Could not create cache file: %u\n", GetLastError());
1394 heap_free(lpwh->cache_file);
1395 lpwh->cache_file = NULL;
1396 }
1397 }
1398 heap_free(url);
1399 }
1401 }
1402
1403 hIC = lpwfs->lpAppInfo;
1404 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
1405 {
1407
1408 if (lpwh)
1409 {
1410 iar.dwResult = (DWORD_PTR)lpwh->hdr.hInternet;
1411 iar.dwError = ERROR_SUCCESS;
1413 &iar, sizeof(INTERNET_ASYNC_RESULT));
1414 }
1415
1416 if(bSuccess) {
1418 }else {
1419 iar.dwResult = 0;
1422 &iar, sizeof(INTERNET_ASYNC_RESULT));
1423 }
1424 }
1425
1426 if(!bSuccess)
1427 return FALSE;
1428
1429 return lpwh->hdr.hInternet;
1430}
static void * heap_alloc(size_t len)
Definition: appwiz.h:66
#define OPEN_EXISTING
Definition: compat.h:775
#define GENERIC_READ
Definition: compat.h:135
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define FILE_SHARE_READ
Definition: compat.h:136
static void FTP_ReceiveRequestData(ftp_file_t *file, BOOL first_notif)
Definition: ftp.c:1226
static const object_vtbl_t FTPFILEVtbl
Definition: ftp.c:1295
static BOOL FTP_SendStore(ftp_session_t *, LPCWSTR lpszRemoteFile, DWORD dwType)
Definition: ftp.c:2899
BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags, LPWSTR lpszUrl, LPDWORD lpdwUrlLength)
Definition: internet.c:4425
BOOL WINAPI CreateUrlCacheEntryW(LPCWSTR lpszUrlName, DWORD dwExpectedFileSize, LPCWSTR lpszFileExtension, LPWSTR lpszFileName, DWORD dwReserved)
Definition: urlcache.c:2815
@ WH_HFILE
Definition: internet.h:238
const char * filename
Definition: ioapi.h:137
static const WCHAR url[]
Definition: encode.c:1432
#define memset(x, y, z)
Definition: compat.h:39
DWORD dwStructSize
Definition: wininet.h:211
LPWSTR lpszHostName
Definition: wininet.h:215
INTERNET_SCHEME nScheme
Definition: wininet.h:214
LPWSTR lpszUserName
Definition: wininet.h:218
LPWSTR lpszUrlPath
Definition: wininet.h:222
INTERNET_PORT nPort
Definition: wininet.h:217
Definition: ftp.c:64
WCHAR * cache_file
Definition: ftp.c:69
BOOL session_deleted
Definition: ftp.c:67
ftp_session_t * lpFtpSession
Definition: ftp.c:66
HANDLE cache_file_handle
Definition: ftp.c:70
int nDataSocket
Definition: ftp.c:68
object_header_t hdr
Definition: ftp.c:65
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define INTERNET_SCHEME_FTP
Definition: winhttp.h:44

Referenced by AsyncFtpOpenFileProc(), and FtpOpenFileW().

◆ FTP_FtpPutFileW()

static BOOL FTP_FtpPutFileW ( ftp_session_t lpwfs,
LPCWSTR  lpszLocalFile,
LPCWSTR  lpszNewRemoteFile,
DWORD  dwFlags,
DWORD_PTR  dwContext 
)
static

Definition at line 344 of file ftp.c.

346{
349 appinfo_t *hIC = NULL;
350 INT nResCode;
351
352 TRACE(" lpszLocalFile(%s) lpszNewRemoteFile(%s)\n", debugstr_w(lpszLocalFile), debugstr_w(lpszNewRemoteFile));
353
354 /* Clear any error information */
356
357 /* Open file to be uploaded */
359 (hFile = CreateFileW(lpszLocalFile, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0)))
360 /* Let CreateFile set the appropriate error */
361 return FALSE;
362
363 hIC = lpwfs->lpAppInfo;
364
366
367 if (FTP_SendStore(lpwfs, lpszNewRemoteFile, dwFlags))
368 {
369 INT nDataSocket;
370
371 /* Get data socket to server */
372 if (FTP_GetDataSocket(lpwfs, &nDataSocket))
373 {
374 FTP_SendData(lpwfs, nDataSocket, hFile);
375 closesocket(nDataSocket);
376 nResCode = FTP_ReceiveResponse(lpwfs, dwContext);
377 if (nResCode)
378 {
379 if (nResCode == 226)
380 bSuccess = TRUE;
381 else
382 FTP_SetResponseError(nResCode);
383 }
384 }
385 }
386
387 if (lpwfs->lstnSocket != -1)
388 {
389 closesocket(lpwfs->lstnSocket);
390 lpwfs->lstnSocket = -1;
391 }
392
394 {
396
397 iar.dwResult = (DWORD)bSuccess;
400 &iar, sizeof(INTERNET_ASYNC_RESULT));
401 }
402
404
405 return bSuccess;
406}
static BOOL FTP_SendData(ftp_session_t *, INT nDataSocket, HANDLE hFile)
Definition: ftp.c:3263
#define INTERNET_STATUS_SENDING_REQUEST
Definition: wininet.h:887

Referenced by AsyncFtpPutFileProc(), and FtpPutFileW().

◆ FTP_FtpRemoveDirectoryW()

BOOL FTP_FtpRemoveDirectoryW ( ftp_session_t lpwfs,
LPCWSTR  lpszDirectory 
)
static

Definition at line 2018 of file ftp.c.

2019{
2020 INT nResCode;
2022 appinfo_t *hIC = NULL;
2023
2024 TRACE("\n");
2025
2026 /* Clear any error information */
2028
2029 if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_RMD, lpszDirectory, 0, 0, 0))
2030 goto lend;
2031
2032 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
2033 if (nResCode)
2034 {
2035 if (nResCode == 250)
2036 bSuccess = TRUE;
2037 else
2038 FTP_SetResponseError(nResCode);
2039 }
2040
2041lend:
2042 hIC = lpwfs->lpAppInfo;
2043 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
2044 {
2046
2047 iar.dwResult = (DWORD)bSuccess;
2050 &iar, sizeof(INTERNET_ASYNC_RESULT));
2051 }
2052
2053 return bSuccess;
2054}

Referenced by AsyncFtpRemoveDirectoryProc(), and FtpRemoveDirectoryW().

◆ FTP_FtpRenameFileW()

BOOL FTP_FtpRenameFileW ( ftp_session_t lpwfs,
LPCWSTR  lpszSrc,
LPCWSTR  lpszDest 
)
static

Definition at line 2172 of file ftp.c.

2173{
2174 INT nResCode;
2176 appinfo_t *hIC = NULL;
2177
2178 TRACE("\n");
2179
2180 /* Clear any error information */
2182
2183 if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_RNFR, lpszSrc, 0, 0, 0))
2184 goto lend;
2185
2186 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
2187 if (nResCode == 350)
2188 {
2189 if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_RNTO, lpszDest, 0, 0, 0))
2190 goto lend;
2191
2192 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
2193 }
2194
2195 if (nResCode == 250)
2196 bSuccess = TRUE;
2197 else
2198 FTP_SetResponseError(nResCode);
2199
2200lend:
2201 hIC = lpwfs->lpAppInfo;
2202 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
2203 {
2205
2206 iar.dwResult = (DWORD)bSuccess;
2209 &iar, sizeof(INTERNET_ASYNC_RESULT));
2210 }
2211
2212 return bSuccess;
2213}
WCHAR lpszDest[260]

Referenced by AsyncFtpRenameFileProc(), and FtpRenameFileW().

◆ FTP_FtpSetCurrentDirectoryW()

static BOOL FTP_FtpSetCurrentDirectoryW ( ftp_session_t lpwfs,
LPCWSTR  lpszDirectory 
)
static

Definition at line 516 of file ftp.c.

517{
518 INT nResCode;
519 appinfo_t *hIC = NULL;
521
522 TRACE("lpszDirectory(%s)\n", debugstr_w(lpszDirectory));
523
524 /* Clear any error information */
526
527 hIC = lpwfs->lpAppInfo;
528 if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_CWD, lpszDirectory,
529 lpwfs->hdr.lpfnStatusCB, &lpwfs->hdr, lpwfs->hdr.dwContext))
530 goto lend;
531
532 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
533
534 if (nResCode)
535 {
536 if (nResCode == 250)
537 bSuccess = TRUE;
538 else
539 FTP_SetResponseError(nResCode);
540 }
541
542lend:
544 {
546
547 iar.dwResult = bSuccess;
550 &iar, sizeof(INTERNET_ASYNC_RESULT));
551 }
552 return bSuccess;
553}

Referenced by AsyncFtpSetCurrentDirectoryProc(), and FtpSetCurrentDirectoryW().

◆ FTP_GetDataSocket()

static BOOL FTP_GetDataSocket ( ftp_session_t lpwfs,
LPINT  nDataSocket 
)
static

Definition at line 3232 of file ftp.c.

3233{
3234 struct sockaddr_in saddr;
3235 socklen_t addrlen = sizeof(saddr);
3236
3237 TRACE("\n");
3238 if (lpwfs->hdr.dwFlags & INTERNET_FLAG_PASSIVE)
3239 {
3240 *nDataSocket = lpwfs->pasvSocket;
3241 lpwfs->pasvSocket = -1;
3242 }
3243 else
3244 {
3245 *nDataSocket = accept(lpwfs->lstnSocket, (struct sockaddr *) &saddr, &addrlen);
3246 closesocket(lpwfs->lstnSocket);
3247 lpwfs->lstnSocket = -1;
3248 }
3249 return *nDataSocket != -1;
3250}
SOCKET WSAAPI accept(IN SOCKET s, OUT LPSOCKADDR addr, OUT INT FAR *addrlen)
Definition: socklife.c:23
#define INTERNET_FLAG_PASSIVE
Definition: wininet.h:65

Referenced by FTP_FtpFindFirstFileW(), FTP_FtpGetFileW(), FTP_FtpOpenFileW(), and FTP_FtpPutFileW().

◆ FTP_GetNextLine()

static LPSTR FTP_GetNextLine ( INT  nSocket,
LPDWORD  dwLen 
)
static

Definition at line 2640 of file ftp.c.

2641{
2642 struct timeval tv = {RESPONSE_TIMEOUT,0};
2643 FD_SET set;
2644 INT nRecv = 0;
2645 LPSTR lpszBuffer = INTERNET_GetResponseBuffer();
2646
2647 TRACE("\n");
2648
2649 FD_ZERO(&set);
2650 FD_SET(nSocket, &set);
2651
2652 while (nRecv < MAX_REPLY_LEN)
2653 {
2654 if (select(nSocket+1, &set, NULL, NULL, &tv) > 0)
2655 {
2656 if (sock_recv(nSocket, &lpszBuffer[nRecv], 1, 0) <= 0)
2657 {
2659 return NULL;
2660 }
2661
2662 if (lpszBuffer[nRecv] == '\n')
2663 {
2664 lpszBuffer[nRecv] = '\0';
2665 *dwLen = nRecv - 1;
2666 TRACE(":%d %s\n", nRecv, lpszBuffer);
2667 return lpszBuffer;
2668 }
2669 if (lpszBuffer[nRecv] != '\r')
2670 nRecv++;
2671 }
2672 else
2673 {
2675 return NULL;
2676 }
2677 }
2678
2679 return NULL;
2680}
Definition: _set.h:50
static int sock_recv(int fd, void *msg, size_t len, int flags)
Definition: net.c:49
#define RESPONSE_TIMEOUT
Definition: ftp.c:59
INT WSAAPI select(IN INT s, IN OUT LPFD_SET readfds, IN OUT LPFD_SET writefds, IN OUT LPFD_SET exceptfds, IN CONST struct timeval *timeout)
Definition: select.c:41
#define MAX_REPLY_LEN
Definition: request.c:2568
Definition: winsock.h:66
#define ERROR_INTERNET_TIMEOUT
Definition: wininet.h:1991
#define ERROR_FTP_TRANSFER_IN_PROGRESS
Definition: wininet.h:2046
#define FD_ZERO(set)
Definition: winsock.h:96
#define FD_SET(fd, set)
Definition: winsock.h:89

Referenced by FTP_ParseNextFile(), and FTP_ReceiveResponse().

◆ FTP_InitListenSocket()

static BOOL FTP_InitListenSocket ( ftp_session_t lpwfs)
static

Definition at line 2946 of file ftp.c.

2947{
2949 socklen_t namelen = sizeof(lpwfs->lstnSocketAddress);
2950
2951 TRACE("\n");
2952
2953 init_winsock();
2954 lpwfs->lstnSocket = socket(AF_INET, SOCK_STREAM, 0);
2955 if (lpwfs->lstnSocket == -1)
2956 {
2957 TRACE("Unable to create listening socket\n");
2958 goto lend;
2959 }
2960
2961 /* We obtain our ip addr from the name of the command channel socket */
2962 lpwfs->lstnSocketAddress = lpwfs->socketAddress;
2963
2964 /* and get the system to assign us a port */
2965 lpwfs->lstnSocketAddress.sin_port = htons(0);
2966
2967 if (bind(lpwfs->lstnSocket,(struct sockaddr *) &lpwfs->lstnSocketAddress, sizeof(lpwfs->lstnSocketAddress)) == -1)
2968 {
2969 TRACE("Unable to bind socket\n");
2970 goto lend;
2971 }
2972
2973 if (listen(lpwfs->lstnSocket, MAX_BACKLOG) == -1)
2974 {
2975 TRACE("listen failed\n");
2976 goto lend;
2977 }
2978
2979 if (getsockname(lpwfs->lstnSocket, (struct sockaddr *) &lpwfs->lstnSocketAddress, &namelen) != -1)
2980 bSuccess = TRUE;
2981
2982lend:
2983 if (!bSuccess && lpwfs->lstnSocket != -1)
2984 {
2985 closesocket(lpwfs->lstnSocket);
2986 lpwfs->lstnSocket = -1;
2987 }
2988
2989 return bSuccess;
2990}
#define MAX_BACKLOG
Definition: ftp.c:109
GLint namelen
Definition: glext.h:7232
#define htons(x)
Definition: module.h:215
INT WSAAPI listen(IN SOCKET s, IN INT backlog)
Definition: sockctrl.c:123
INT WSAAPI bind(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: socklife.c:36
struct sockaddr_in lstnSocketAddress
Definition: ftp.c:82

Referenced by FTP_FtpFindFirstFileW(), FTP_SendRetrieve(), and FTP_SendStore().

◆ FTP_ParseDirectory()

static BOOL FTP_ParseDirectory ( ftp_session_t lpwfs,
INT  nSocket,
LPCWSTR  lpszSearchFile,
LPFILEPROPERTIESW lpafp,
LPDWORD  dwfp 
)
static

Definition at line 3787 of file ftp.c.

3789{
3790 BOOL bSuccess = TRUE;
3791 INT sizeFilePropArray = 500;/*20; */
3792 INT indexFilePropArray = -1;
3793
3794 TRACE("\n");
3795
3796 /* Allocate initial file properties array */
3797 *lpafp = heap_alloc_zero(sizeof(FILEPROPERTIESW)*(sizeFilePropArray));
3798 if (!*lpafp)
3799 return FALSE;
3800
3801 do {
3802 if (indexFilePropArray+1 >= sizeFilePropArray)
3803 {
3804 LPFILEPROPERTIESW tmpafp;
3805
3806 sizeFilePropArray *= 2;
3807 tmpafp = heap_realloc_zero(*lpafp, sizeof(FILEPROPERTIESW)*sizeFilePropArray);
3808 if (NULL == tmpafp)
3809 {
3810 bSuccess = FALSE;
3811 break;
3812 }
3813
3814 *lpafp = tmpafp;
3815 }
3816 indexFilePropArray++;
3817 } while (FTP_ParseNextFile(nSocket, lpszSearchFile, &(*lpafp)[indexFilePropArray]));
3818
3819 if (bSuccess && indexFilePropArray)
3820 {
3821 if (indexFilePropArray < sizeFilePropArray - 1)
3822 {
3823 LPFILEPROPERTIESW tmpafp;
3824
3825 tmpafp = heap_realloc(*lpafp, sizeof(FILEPROPERTIESW)*indexFilePropArray);
3826 if (NULL != tmpafp)
3827 *lpafp = tmpafp;
3828 }
3829 *dwfp = indexFilePropArray;
3830 }
3831 else
3832 {
3833 heap_free(*lpafp);
3835 bSuccess = FALSE;
3836 }
3837
3838 return bSuccess;
3839}
static void * heap_realloc(void *mem, size_t len)
Definition: appwiz.h:71
static BOOL FTP_ParseNextFile(INT nSocket, LPCWSTR lpszSearchFile, LPFILEPROPERTIESW fileprop)
Definition: ftp.c:3626

Referenced by FTP_ReceiveFileList().

◆ FTP_ParseNextFile()

static BOOL FTP_ParseNextFile ( INT  nSocket,
LPCWSTR  lpszSearchFile,
LPFILEPROPERTIESW  fileprop 
)
static

Definition at line 3626 of file ftp.c.

3627{
3628 static const char szSpace[] = " \t";
3629 DWORD nBufLen;
3630 char *pszLine;
3631 char *pszToken;
3632 char *pszTmp;
3633 BOOL found = FALSE;
3634 int i;
3635
3636 lpfp->lpszName = NULL;
3637 do {
3638 if(!(pszLine = FTP_GetNextLine(nSocket, &nBufLen)))
3639 return FALSE;
3640
3641 pszToken = strtok(pszLine, szSpace);
3642 /* ls format
3643 * <Permissions> <NoLinks> <owner> <group> <size> <date> <time or year> <filename>
3644 *
3645 * For instance:
3646 * drwx--s--- 2 pcarrier ens 512 Sep 28 1995 pcarrier
3647 */
3648 if(!isdigit(pszToken[0]) && 10 == strlen(pszToken)) {
3649 if(!FTP_ParsePermission(pszToken, lpfp))
3650 lpfp->bIsDirectory = FALSE;
3651 for(i=0; i<=3; i++) {
3652 if(!(pszToken = strtok(NULL, szSpace)))
3653 break;
3654 }
3655 if(!pszToken) continue;
3656 if(lpfp->bIsDirectory) {
3657 TRACE("Is directory\n");
3658 lpfp->nSize = 0;
3659 }
3660 else {
3661 TRACE("Size: %s\n", pszToken);
3662 lpfp->nSize = atol(pszToken);
3663 }
3664
3665 lpfp->tmLastModified.wSecond = 0;
3666 lpfp->tmLastModified.wMinute = 0;
3667 lpfp->tmLastModified.wHour = 0;
3668 lpfp->tmLastModified.wDay = 0;
3669 lpfp->tmLastModified.wMonth = 0;
3670 lpfp->tmLastModified.wYear = 0;
3671
3672 /* Determine month */
3673 pszToken = strtok(NULL, szSpace);
3674 if(!pszToken) continue;
3675 if(strlen(pszToken) >= 3) {
3676 pszToken[3] = 0;
3677 if((pszTmp = StrStrIA(szMonths, pszToken)))
3678 lpfp->tmLastModified.wMonth = ((pszTmp - szMonths) / 3)+1;
3679 }
3680 /* Determine day */
3681 pszToken = strtok(NULL, szSpace);
3682 if(!pszToken) continue;
3683 lpfp->tmLastModified.wDay = atoi(pszToken);
3684 /* Determine time or year */
3685 pszToken = strtok(NULL, szSpace);
3686 if(!pszToken) continue;
3687 if((pszTmp = strchr(pszToken, ':'))) {
3688 SYSTEMTIME curr_time;
3689 *pszTmp = 0;
3690 pszTmp++;
3691 lpfp->tmLastModified.wMinute = atoi(pszTmp);
3692 lpfp->tmLastModified.wHour = atoi(pszToken);
3693 GetLocalTime( &curr_time );
3694 lpfp->tmLastModified.wYear = curr_time.wYear;
3695 }
3696 else {
3697 lpfp->tmLastModified.wYear = atoi(pszToken);
3698 lpfp->tmLastModified.wHour = 12;
3699 }
3700 TRACE("Mod time: %02d:%02d:%02d %04d/%02d/%02d\n",
3701 lpfp->tmLastModified.wHour, lpfp->tmLastModified.wMinute, lpfp->tmLastModified.wSecond,
3702 lpfp->tmLastModified.wYear, lpfp->tmLastModified.wMonth, lpfp->tmLastModified.wDay);
3703
3704 pszToken = strtok(NULL, szSpace);
3705 if(!pszToken) continue;
3706 lpfp->lpszName = heap_strdupAtoW(pszToken);
3707 TRACE("File: %s\n", debugstr_w(lpfp->lpszName));
3708 }
3709 /* NT way of parsing ... :
3710
3711 07-13-03 08:55PM <DIR> sakpatch
3712 05-09-03 06:02PM 12656686 2003-04-21bgm_cmd_e.rgz
3713 */
3714 else if(isdigit(pszToken[0]) && 8 == strlen(pszToken)) {
3715 int mon, mday, year, hour, min;
3716 lpfp->permissions = 0xFFFF; /* No idea, put full permission :-) */
3717
3718 sscanf(pszToken, "%d-%d-%d", &mon, &mday, &year);
3719 lpfp->tmLastModified.wDay = mday;
3720 lpfp->tmLastModified.wMonth = mon;
3721 lpfp->tmLastModified.wYear = year;
3722
3723 /* Hacky and bad Y2K protection :-) */
3724 if (lpfp->tmLastModified.wYear < 70) lpfp->tmLastModified.wYear += 2000;
3725
3726 pszToken = strtok(NULL, szSpace);
3727 if(!pszToken) continue;
3728 sscanf(pszToken, "%d:%d", &hour, &min);
3729 lpfp->tmLastModified.wHour = hour;
3730 lpfp->tmLastModified.wMinute = min;
3731 if((pszToken[5] == 'P') && (pszToken[6] == 'M')) {
3732 lpfp->tmLastModified.wHour += 12;
3733 }
3734 lpfp->tmLastModified.wSecond = 0;
3735
3736 TRACE("Mod time: %02d:%02d:%02d %04d/%02d/%02d\n",
3737 lpfp->tmLastModified.wHour, lpfp->tmLastModified.wMinute, lpfp->tmLastModified.wSecond,
3738 lpfp->tmLastModified.wYear, lpfp->tmLastModified.wMonth, lpfp->tmLastModified.wDay);
3739
3740 pszToken = strtok(NULL, szSpace);
3741 if(!pszToken) continue;
3742 if(!stricmp(pszToken, "<DIR>")) {
3743 lpfp->bIsDirectory = TRUE;
3744 lpfp->nSize = 0;
3745 TRACE("Is directory\n");
3746 }
3747 else {
3748 lpfp->bIsDirectory = FALSE;
3749 lpfp->nSize = atol(pszToken);
3750 TRACE("Size: %d\n", lpfp->nSize);
3751 }
3752
3753 pszToken = strtok(NULL, szSpace);
3754 if(!pszToken) continue;
3755 lpfp->lpszName = heap_strdupAtoW(pszToken);
3756 TRACE("Name: %s\n", debugstr_w(lpfp->lpszName));
3757 }
3758 /* EPLF format - http://cr.yp.to/ftp/list/eplf.html */
3759 else if(pszToken[0] == '+') {
3760 FIXME("EPLF Format not implemented\n");
3761 }
3762
3763 if(lpfp->lpszName) {
3764 if((lpszSearchFile == NULL) ||
3765 (PathMatchSpecW(lpfp->lpszName, lpszSearchFile))) {
3766 found = TRUE;
3767 TRACE("Matched: %s\n", debugstr_w(lpfp->lpszName));
3768 }
3769 else {
3770 heap_free(lpfp->lpszName);
3771 lpfp->lpszName = NULL;
3772 }
3773 }
3774 } while(!found);
3775 return TRUE;
3776}
#define isdigit(c)
Definition: acclib.h:68
char * strtok(char *String, const char *Delimiters)
Definition: utclib.c:338
char * strchr(const char *String, int ch)
Definition: utclib.c:501
LPSTR WINAPI StrStrIA(LPCSTR lpszStr, LPCSTR lpszSearch)
Definition: string.c:355
#define stricmp(_String1, _String2)
Definition: compat.h:24
VOID WINAPI GetLocalTime(OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:286
BOOL WINAPI PathMatchSpecW(LPCWSTR lpszPath, LPCWSTR lpszMask)
Definition: path.c:1964
static const CHAR szMonths[]
Definition: ftp.c:165
static BOOL FTP_ParsePermission(LPCSTR lpszPermission, LPFILEPROPERTIESW lpfp)
Definition: ftp.c:3852
static LPSTR FTP_GetNextLine(INT nSocket, LPDWORD dwLen)
Definition: ftp.c:2640
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
_Check_return_ long __cdecl atol(_In_z_ const char *_Str)
#define min(a, b)
Definition: monoChain.cc:55
WORD wYear
Definition: winbase.h:905
WORD wMinute
Definition: winbase.h:910

Referenced by FTP_ParseDirectory().

◆ FTP_ParsePermission()

static BOOL FTP_ParsePermission ( LPCSTR  lpszPermission,
LPFILEPROPERTIESW  lpfp 
)
static

Definition at line 3852 of file ftp.c.

3853{
3854 BOOL bSuccess = TRUE;
3855 unsigned short nPermission = 0;
3856 INT nPos = 1;
3857 INT nLast = 9;
3858
3859 TRACE("\n");
3860 if ((*lpszPermission != 'd') && (*lpszPermission != '-') && (*lpszPermission != 'l'))
3861 {
3862 bSuccess = FALSE;
3863 return bSuccess;
3864 }
3865
3866 lpfp->bIsDirectory = (*lpszPermission == 'd');
3867 do
3868 {
3869 switch (nPos)
3870 {
3871 case 1:
3872 nPermission |= (*(lpszPermission+1) == 'r' ? 1 : 0) << 8;
3873 break;
3874 case 2:
3875 nPermission |= (*(lpszPermission+2) == 'w' ? 1 : 0) << 7;
3876 break;
3877 case 3:
3878 nPermission |= (*(lpszPermission+3) == 'x' ? 1 : 0) << 6;
3879 break;
3880 case 4:
3881 nPermission |= (*(lpszPermission+4) == 'r' ? 1 : 0) << 5;
3882 break;
3883 case 5:
3884 nPermission |= (*(lpszPermission+5) == 'w' ? 1 : 0) << 4;
3885 break;
3886 case 6:
3887 nPermission |= (*(lpszPermission+6) == 'x' ? 1 : 0) << 3;
3888 break;
3889 case 7:
3890 nPermission |= (*(lpszPermission+7) == 'r' ? 1 : 0) << 2;
3891 break;
3892 case 8:
3893 nPermission |= (*(lpszPermission+8) == 'w' ? 1 : 0) << 1;
3894 break;
3895 case 9:
3896 nPermission |= (*(lpszPermission+9) == 'x' ? 1 : 0);
3897 break;
3898 }
3899 nPos++;
3900 }while (nPos <= nLast);
3901
3902 lpfp->permissions = nPermission;
3903 return bSuccess;
3904}
unsigned short permissions
Definition: ftp.c:95

Referenced by FTP_ParseNextFile().

◆ FTP_ReceiveFileList()

static HINTERNET FTP_ReceiveFileList ( ftp_session_t lpwfs,
INT  nSocket,
LPCWSTR  lpszSearchFile,
LPWIN32_FIND_DATAW  lpFindFileData,
DWORD_PTR  dwContext 
)
static

Definition at line 3545 of file ftp.c.

3547{
3548 DWORD dwSize = 0;
3549 LPFILEPROPERTIESW lpafp = NULL;
3551
3552 TRACE("(%p,%d,%s,%p,%08lx)\n", lpwfs, nSocket, debugstr_w(lpszSearchFile), lpFindFileData, dwContext);
3553
3554 if (FTP_ParseDirectory(lpwfs, nSocket, lpszSearchFile, &lpafp, &dwSize))
3555 {
3556 if(lpFindFileData)
3557 FTP_ConvertFileProp(lpafp, lpFindFileData);
3558
3559 lpwfn = alloc_object(&lpwfs->hdr, &FTPFINDNEXTVtbl, sizeof(WININETFTPFINDNEXTW));
3560 if (lpwfn)
3561 {
3562 lpwfn->hdr.htype = WH_HFTPFINDNEXT;
3563 lpwfn->hdr.dwContext = dwContext;
3564 lpwfn->index = 1; /* Next index is 1 since we return index 0 */
3565 lpwfn->size = dwSize;
3566 lpwfn->lpafp = lpafp;
3567
3568 WININET_AddRef( &lpwfs->hdr );
3569 lpwfn->lpFtpSession = lpwfs;
3570 list_add_head( &lpwfs->hdr.children, &lpwfn->hdr.entry );
3571 }
3572 }
3573
3574 TRACE("Matched %d files\n", dwSize);
3575 return lpwfn ? lpwfn->hdr.hInternet : NULL;
3576}
static const object_vtbl_t FTPFINDNEXTVtbl
Definition: ftp.c:3524
static BOOL FTP_ParseDirectory(ftp_session_t *, INT nSocket, LPCWSTR lpszSearchFile, LPFILEPROPERTIESW *lpafp, LPDWORD dwfp)
Definition: ftp.c:3787
static BOOL FTP_ConvertFileProp(LPFILEPROPERTIESW lpafp, LPWIN32_FIND_DATAW lpFindFileData)
Definition: ftp.c:3589
@ WH_HFTPFINDNEXT
Definition: internet.h:239
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
ftp_session_t * lpFtpSession
Definition: ftp.c:101
object_header_t hdr
Definition: ftp.c:100
LPFILEPROPERTIESW lpafp
Definition: ftp.c:104

Referenced by FTP_FtpFindFirstFileW().

◆ FTP_ReceiveRequestData()

static void FTP_ReceiveRequestData ( ftp_file_t file,
BOOL  first_notif 
)
static

Definition at line 1226 of file ftp.c.

1227{
1229 BYTE buffer[4096];
1230 int available;
1231
1232 TRACE("%p\n", file);
1233
1234 available = sock_recv(file->nDataSocket, buffer, sizeof(buffer), MSG_PEEK);
1235
1236 if(available != -1) {
1237 iar.dwResult = (DWORD_PTR)file->hdr.hInternet;
1238 iar.dwError = first_notif ? 0 : available;
1239 }else {
1240 iar.dwResult = 0;
1242 }
1243
1245 sizeof(INTERNET_ASYNC_RESULT));
1246}
static WCHAR available[MAX_STRING_RESOURCE_LEN]
Definition: object.c:2336
GLuint buffer
Definition: glext.h:5915
Definition: fci.c:127
#define MSG_PEEK
Definition: winsock.h:222
unsigned char BYTE
Definition: xxhash.c:193

Referenced by FTP_FtpOpenFileW(), and FTPFILE_AsyncQueryDataAvailableProc().

◆ FTP_ReceiveResponse()

INT FTP_ReceiveResponse ( ftp_session_t lpwfs,
DWORD_PTR  dwContext 
)
static

Definition at line 2766 of file ftp.c.

2767{
2768 LPSTR lpszResponse = INTERNET_GetResponseBuffer();
2769 DWORD nRecv;
2770 INT rc = 0;
2771 char firstprefix[5];
2772 BOOL multiline = FALSE;
2773
2774 TRACE("socket(%d)\n", lpwfs->sndSocket);
2775
2777
2778 while(1)
2779 {
2780 if (!FTP_GetNextLine(lpwfs->sndSocket, &nRecv))
2781 goto lerror;
2782
2783 if (nRecv >= 3)
2784 {
2785 if(!multiline)
2786 {
2787 if(lpszResponse[3] != '-')
2788 break;
2789 else
2790 { /* Start of multiline response. Loop until we get "nnn " */
2791 multiline = TRUE;
2792 memcpy(firstprefix, lpszResponse, 3);
2793 firstprefix[3] = ' ';
2794 firstprefix[4] = '\0';
2795 }
2796 }
2797 else
2798 {
2799 if(!memcmp(firstprefix, lpszResponse, 4))
2800 break;
2801 }
2802 }
2803 }
2804
2805 if (nRecv >= 3)
2806 {
2807 rc = atoi(lpszResponse);
2808
2810 &nRecv, sizeof(DWORD));
2811 }
2812
2813lerror:
2814 TRACE("return %d\n", rc);
2815 return rc;
2816}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define INTERNET_STATUS_RECEIVING_RESPONSE
Definition: wininet.h:889
#define INTERNET_STATUS_RESPONSE_RECEIVED
Definition: wininet.h:890

Referenced by FTP_ConnectToHost(), FTP_DoPassive(), FTP_FtpCreateDirectoryW(), FTP_FtpDeleteFileW(), FTP_FtpFindFirstFileW(), FTP_FtpGetCurrentDirectoryW(), FTP_FtpGetFileW(), FTP_FtpPutFileW(), FTP_FtpRemoveDirectoryW(), FTP_FtpRenameFileW(), FTP_FtpSetCurrentDirectoryW(), FTP_SendAccount(), FTP_SendPassword(), FTP_SendPort(), FTP_SendRetrieve(), FTP_SendStore(), FTP_SendType(), FtpCommandW(), and FTPFILE_Destroy().

◆ FTP_RetrieveFileData()

static BOOL FTP_RetrieveFileData ( ftp_session_t lpwfs,
INT  nDataSocket,
HANDLE  hFile 
)
static

Definition at line 3389 of file ftp.c.

3390{
3391 DWORD nBytesWritten;
3392 INT nRC = 0;
3393 CHAR *lpszBuffer;
3394
3395 TRACE("\n");
3396
3397 lpszBuffer = heap_alloc_zero(sizeof(CHAR)*DATA_PACKET_SIZE);
3398 if (NULL == lpszBuffer)
3399 {
3401 return FALSE;
3402 }
3403
3404 while (nRC != -1)
3405 {
3406 nRC = sock_recv(nDataSocket, lpszBuffer, DATA_PACKET_SIZE, 0);
3407 if (nRC != -1)
3408 {
3409 /* other side closed socket. */
3410 if (nRC == 0)
3411 goto recv_end;
3412 WriteFile(hFile, lpszBuffer, nRC, &nBytesWritten, NULL);
3413 }
3414 }
3415
3416 TRACE("Data transfer complete\n");
3417
3418recv_end:
3419 heap_free(lpszBuffer);
3420 return (nRC != -1);
3421}
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
#define DATA_PACKET_SIZE
Definition: ftp.c:107
char CHAR
Definition: xmlstorage.h:175

Referenced by FTP_FtpGetFileW().

◆ FTP_SendAccount()

static BOOL FTP_SendAccount ( ftp_session_t lpwfs)
static

Definition at line 2869 of file ftp.c.

2870{
2871 INT nResCode;
2873
2874 TRACE("\n");
2875 if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_ACCT, L"noaccount", 0, 0, 0))
2876 goto lend;
2877
2878 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
2879 if (nResCode)
2880 bSuccess = TRUE;
2881 else
2882 FTP_SetResponseError(nResCode);
2883
2884lend:
2885 return bSuccess;
2886}

Referenced by FTP_ConnectToHost(), and FTP_SendPassword().

◆ FTP_SendCommand()

static BOOL FTP_SendCommand ( INT  nSocket,
FTP_COMMAND  ftpCmd,
LPCWSTR  lpszParam,
INTERNET_STATUS_CALLBACK  lpfnStatusCB,
object_header_t hdr,
DWORD_PTR  dwContext 
)
static

Definition at line 2746 of file ftp.c.

2748{
2749 BOOL ret;
2750 LPSTR lpszParamA = heap_strdupWtoA(lpszParam);
2751 ret = FTP_SendCommandA(nSocket, ftpCmd, lpszParamA, lpfnStatusCB, hdr, dwContext);
2752 heap_free(lpszParamA);
2753 return ret;
2754}
static char * heap_strdupWtoA(const WCHAR *str)
static BOOL FTP_SendCommandA(INT nSocket, FTP_COMMAND ftpCmd, LPCSTR lpszParam, INTERNET_STATUS_CALLBACK lpfnStatusCB, object_header_t *hdr, DWORD_PTR dwContext)
Definition: ftp.c:2692
int ret

Referenced by FTP_ConnectToHost(), FTP_DoPassive(), FTP_FtpCreateDirectoryW(), FTP_FtpDeleteFileW(), FTP_FtpFindFirstFileW(), FTP_FtpGetCurrentDirectoryW(), FTP_FtpRemoveDirectoryW(), FTP_FtpRenameFileW(), FTP_FtpSetCurrentDirectoryW(), FTP_SendAccount(), FTP_SendPassword(), FTP_SendPort(), FTP_SendRetrieve(), FTP_SendStore(), and FTP_SendType().

◆ FTP_SendCommandA()

static BOOL FTP_SendCommandA ( INT  nSocket,
FTP_COMMAND  ftpCmd,
LPCSTR  lpszParam,
INTERNET_STATUS_CALLBACK  lpfnStatusCB,
object_header_t hdr,
DWORD_PTR  dwContext 
)
static

Definition at line 2692 of file ftp.c.

2694{
2695 DWORD len;
2696 CHAR *buf;
2697 DWORD nBytesSent = 0;
2698 int nRC = 0;
2699 DWORD dwParamLen;
2700
2701 TRACE("%d: (%s) %d\n", ftpCmd, debugstr_a(lpszParam), nSocket);
2702
2703 if (lpfnStatusCB)
2704 {
2705 lpfnStatusCB(hdr->hInternet, dwContext, INTERNET_STATUS_SENDING_REQUEST, NULL, 0);
2706 }
2707
2708 dwParamLen = lpszParam?strlen(lpszParam)+1:0;
2709 len = dwParamLen + strlen(szFtpCommands[ftpCmd]) + strlen(szCRLF);
2710 if (NULL == (buf = heap_alloc(len+1)))
2711 {
2713 return FALSE;
2714 }
2715 sprintf(buf, "%s%s%s%s", szFtpCommands[ftpCmd], dwParamLen ? " " : "",
2716 dwParamLen ? lpszParam : "", szCRLF);
2717
2718 TRACE("Sending (%s) len(%d)\n", debugstr_a(buf), len);
2719 while((nBytesSent < len) && (nRC != -1))
2720 {
2721 nRC = sock_send(nSocket, buf+nBytesSent, len - nBytesSent, 0);
2722 nBytesSent += nRC;
2723 }
2724 heap_free(buf);
2725
2726 if (lpfnStatusCB)
2727 {
2728 lpfnStatusCB(hdr->hInternet, dwContext, INTERNET_STATUS_REQUEST_SENT,
2729 &nBytesSent, sizeof(DWORD));
2730 }
2731
2732 TRACE("Sent %d bytes\n", nBytesSent);
2733 return (nRC != -1);
2734}
static int sock_send(int fd, const void *msg, size_t len, int flags)
Definition: net.c:38
static const CHAR *const szFtpCommands[]
Definition: ftp.c:142
#define szCRLF
Definition: ftp.c:108
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define debugstr_a
Definition: kernel32.h:31
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define INTERNET_STATUS_REQUEST_SENT
Definition: wininet.h:888

Referenced by FTP_SendCommand().

◆ FTP_SendData()

static BOOL FTP_SendData ( ftp_session_t lpwfs,
INT  nDataSocket,
HANDLE  hFile 
)
static

Definition at line 3263 of file ftp.c.

3264{
3266 DWORD nBytesRead = 0;
3267 DWORD nBytesSent = 0;
3268 DWORD nTotalSent = 0;
3269 DWORD nBytesToSend, nLen;
3270 int nRC = 1;
3271 time_t s_long_time, e_long_time;
3272 LONG nSeconds;
3273 CHAR *lpszBuffer;
3274
3275 TRACE("\n");
3276 lpszBuffer = heap_alloc_zero(sizeof(CHAR)*DATA_PACKET_SIZE);
3277
3278 /* Get the size of the file. */
3280 time(&s_long_time);
3281
3282 do
3283 {
3284 nBytesToSend = nBytesRead - nBytesSent;
3285
3286 if (nBytesToSend <= 0)
3287 {
3288 /* Read data from file. */
3289 nBytesSent = 0;
3290 if (!ReadFile(hFile, lpszBuffer, DATA_PACKET_SIZE, &nBytesRead, 0))
3291 ERR("Failed reading from file\n");
3292
3293 if (nBytesRead > 0)
3294 nBytesToSend = nBytesRead;
3295 else
3296 break;
3297 }
3298
3299 nLen = DATA_PACKET_SIZE < nBytesToSend ?
3300 DATA_PACKET_SIZE : nBytesToSend;
3301 nRC = sock_send(nDataSocket, lpszBuffer, nLen, 0);
3302
3303 if (nRC != -1)
3304 {
3305 nBytesSent += nRC;
3306 nTotalSent += nRC;
3307 }
3308
3309 /* Do some computation to display the status. */
3310 time(&e_long_time);
3311 nSeconds = e_long_time - s_long_time;
3312 if( nSeconds / 60 > 0 )
3313 {
3314 TRACE( "%d bytes of %d bytes (%d%%) in %d min %d sec estimated remaining time %d sec\n",
3315 nTotalSent, fi.nFileSizeLow, nTotalSent*100/fi.nFileSizeLow, nSeconds / 60,
3316 nSeconds % 60, (fi.nFileSizeLow - nTotalSent) * nSeconds / nTotalSent );
3317 }
3318 else
3319 {
3320 TRACE( "%d bytes of %d bytes (%d%%) in %d sec estimated remaining time %d sec\n",
3321 nTotalSent, fi.nFileSizeLow, nTotalSent*100/fi.nFileSizeLow, nSeconds,
3322 (fi.nFileSizeLow - nTotalSent) * nSeconds / nTotalSent);
3323 }
3324 } while (nRC != -1);
3325
3326 TRACE("file transfer complete!\n");
3327
3328 heap_free(lpszBuffer);
3329 return nTotalSent;
3330}
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
BOOL WINAPI GetFileInformationByHandle(HANDLE hFile, LPBY_HANDLE_FILE_INFORMATION lpFileInformation)
Definition: fileinfo.c:458
__kernel_time_t time_t
Definition: linux.h:252
__u16 time
Definition: mkdosfs.c:8
long LONG
Definition: pedump.c:60

Referenced by FTP_FtpPutFileW().

◆ FTP_SendPassword()

static BOOL FTP_SendPassword ( ftp_session_t lpwfs)
static

Definition at line 2829 of file ftp.c.

2830{
2831 INT nResCode;
2833
2834 TRACE("\n");
2835 if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_PASS, lpwfs->lpszPassword, 0, 0, 0))
2836 goto lend;
2837
2838 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
2839 if (nResCode)
2840 {
2841 TRACE("Received reply code %d\n", nResCode);
2842 /* Login successful... */
2843 if (nResCode == 230)
2844 bSuccess = TRUE;
2845 /* Command not implemented, superfluous at the server site... */
2846 /* Need account for login... */
2847 else if (nResCode == 332)
2848 bSuccess = FTP_SendAccount(lpwfs);
2849 else
2850 FTP_SetResponseError(nResCode);
2851 }
2852
2853lend:
2854 TRACE("Returning %d\n", bSuccess);
2855 return bSuccess;
2856}

Referenced by FTP_ConnectToHost().

◆ FTP_SendPort()

static BOOL FTP_SendPort ( ftp_session_t lpwfs)
static

Definition at line 3088 of file ftp.c.

3089{
3090 INT nResCode;
3091 WCHAR szIPAddress[64];
3093 TRACE("\n");
3094
3095 swprintf(szIPAddress, ARRAY_SIZE(szIPAddress), L"%d,%d,%d,%d,%d,%d",
3096 lpwfs->lstnSocketAddress.sin_addr.S_un.S_addr&0x000000FF,
3097 (lpwfs->lstnSocketAddress.sin_addr.S_un.S_addr&0x0000FF00)>>8,
3098 (lpwfs->lstnSocketAddress.sin_addr.S_un.S_addr&0x00FF0000)>>16,
3099 (lpwfs->lstnSocketAddress.sin_addr.S_un.S_addr&0xFF000000)>>24,
3100 lpwfs->lstnSocketAddress.sin_port & 0xFF,
3101 (lpwfs->lstnSocketAddress.sin_port & 0xFF00)>>8);
3102
3103 if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_PORT, szIPAddress, 0, 0, 0))
3104 goto lend;
3105
3106 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
3107 if (nResCode)
3108 {
3109 if (nResCode == 200)
3110 bSuccess = TRUE;
3111 else
3112 FTP_SetResponseError(nResCode);
3113 }
3114
3115lend:
3116 return bSuccess;
3117}
#define ARRAY_SIZE(A)
Definition: main.h:33
#define swprintf
Definition: precomp.h:40

Referenced by FTP_SendPortOrPasv().

◆ FTP_SendPortOrPasv()

static BOOL FTP_SendPortOrPasv ( ftp_session_t lpwfs)
static

Definition at line 3203 of file ftp.c.

3204{
3205 if (lpwfs->hdr.dwFlags & INTERNET_FLAG_PASSIVE)
3206 {
3207 if (!FTP_DoPassive(lpwfs))
3208 return FALSE;
3209 }
3210 else
3211 {
3212 if (!FTP_SendPort(lpwfs))
3213 return FALSE;
3214 }
3215 return TRUE;
3216}
static BOOL FTP_DoPassive(ftp_session_t *)
Definition: ftp.c:3131
static BOOL FTP_SendPort(ftp_session_t *)
Definition: ftp.c:3088

Referenced by FTP_FtpFindFirstFileW(), FTP_SendRetrieve(), and FTP_SendStore().

◆ FTP_SendRetrieve()

static BOOL FTP_SendRetrieve ( ftp_session_t lpwfs,
LPCWSTR  lpszRemoteFile,
DWORD  dwType 
)
static

Definition at line 3343 of file ftp.c.

3344{
3345 INT nResCode;
3346 BOOL ret;
3347
3348 TRACE("\n");
3349 if (!(ret = FTP_InitListenSocket(lpwfs)))
3350 goto lend;
3351
3352 if (!(ret = FTP_SendType(lpwfs, dwType)))
3353 goto lend;
3354
3355 if (!(ret = FTP_SendPortOrPasv(lpwfs)))
3356 goto lend;
3357
3358 if (!(ret = FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_RETR, lpszRemoteFile, 0, 0, 0)))
3359 goto lend;
3360
3361 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
3362 if ((nResCode != 125) && (nResCode != 150)) {
3363 /* That means that we got an error getting the file. */
3364 FTP_SetResponseError(nResCode);
3365 ret = FALSE;
3366 }
3367
3368lend:
3369 if (!ret && lpwfs->lstnSocket != -1)
3370 {
3371 closesocket(lpwfs->lstnSocket);
3372 lpwfs->lstnSocket = -1;
3373 }
3374
3375 return ret;
3376}

Referenced by FTP_FtpGetFileW(), and FTP_FtpOpenFileW().

◆ FTP_SendStore()

static BOOL FTP_SendStore ( ftp_session_t lpwfs,
LPCWSTR  lpszRemoteFile,
DWORD  dwType 
)
static

Definition at line 2899 of file ftp.c.

2900{
2901 INT nResCode;
2903
2904 TRACE("\n");
2905 if (!FTP_InitListenSocket(lpwfs))
2906 goto lend;
2907
2908 if (!FTP_SendType(lpwfs, dwType))
2909 goto lend;
2910
2911 if (!FTP_SendPortOrPasv(lpwfs))
2912 goto lend;
2913
2914 if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_STOR, lpszRemoteFile, 0, 0, 0))
2915 goto lend;
2916 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
2917 if (nResCode)
2918 {
2919 if (nResCode == 150 || nResCode == 125)
2920 bSuccess = TRUE;
2921 else
2922 FTP_SetResponseError(nResCode);
2923 }
2924
2925lend:
2926 if (!bSuccess && lpwfs->lstnSocket != -1)
2927 {
2928 closesocket(lpwfs->lstnSocket);
2929 lpwfs->lstnSocket = -1;
2930 }
2931
2932 return bSuccess;
2933}

Referenced by FTP_FtpOpenFileW(), and FTP_FtpPutFileW().

◆ FTP_SendType()

static BOOL FTP_SendType ( ftp_session_t lpwfs,
DWORD  dwType 
)
static

Definition at line 3006 of file ftp.c.

3007{
3008 INT nResCode;
3009 WCHAR type[] = L"I";
3011
3012 TRACE("\n");
3013 if (dwType & INTERNET_FLAG_TRANSFER_ASCII)
3014 type[0] = 'A';
3015
3016 if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_TYPE, type, 0, 0, 0))
3017 goto lend;
3018
3019 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext)/100;
3020 if (nResCode)
3021 {
3022 if (nResCode == 2)
3023 bSuccess = TRUE;
3024 else
3025 FTP_SetResponseError(nResCode);
3026 }
3027
3028lend:
3029 return bSuccess;
3030}
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545

Referenced by FTP_FtpFindFirstFileW(), FTP_SendRetrieve(), and FTP_SendStore().

◆ FTP_SetResponseError()

static DWORD FTP_SetResponseError ( DWORD  dwResponse)
static

Definition at line 3915 of file ftp.c.

3916{
3917 DWORD dwCode = 0;
3918
3919 switch(dwResponse)
3920 {
3921 case 425: /* Cannot open data connection. */
3923 break;
3924
3925 case 426: /* Connection closed, transfer aborted. */
3927 break;
3928
3929 case 530: /* Not logged in. Login incorrect. */
3931 break;
3932
3933 case 421: /* Service not available - Server may be shutting down. */
3934 case 450: /* File action not taken. File may be busy. */
3935 case 451: /* Action aborted. Server error. */
3936 case 452: /* Action not taken. Insufficient storage space on server. */
3937 case 500: /* Syntax error. Command unrecognized. */
3938 case 501: /* Syntax error. Error in parameters or arguments. */
3939 case 502: /* Command not implemented. */
3940 case 503: /* Bad sequence of commands. */
3941 case 504: /* Command not implemented for that parameter. */
3942 case 532: /* Need account for storing files */
3943 case 550: /* File action not taken. File not found or no access. */
3944 case 551: /* Requested action aborted. Page type unknown */
3945 case 552: /* Action aborted. Exceeded storage allocation */
3946 case 553: /* Action not taken. File name not allowed. */
3947
3948 default:
3950 break;
3951 }
3952
3953 INTERNET_SetLastError(dwCode);
3954 return dwCode;
3955}
#define ERROR_INTERNET_CONNECTION_ABORTED
Definition: wininet.h:2019
#define ERROR_INTERNET_LOGIN_FAILURE
Definition: wininet.h:2004

Referenced by FTP_ConnectToHost(), FTP_DoPassive(), FTP_FtpCreateDirectoryW(), FTP_FtpDeleteFileW(), FTP_FtpFindFirstFileW(), FTP_FtpGetCurrentDirectoryW(), FTP_FtpGetFileW(), FTP_FtpPutFileW(), FTP_FtpRemoveDirectoryW(), FTP_FtpRenameFileW(), FTP_FtpSetCurrentDirectoryW(), FTP_SendAccount(), FTP_SendPassword(), FTP_SendPort(), FTP_SendRetrieve(), FTP_SendStore(), FTP_SendType(), and FtpCommandW().

◆ FtpCommandA()

BOOL WINAPI FtpCommandA ( HINTERNET  hConnect,
BOOL  fExpectResponse,
DWORD  dwFlags,
LPCSTR  lpszCommand,
DWORD_PTR  dwContext,
HINTERNET phFtpCommand 
)

Definition at line 2218 of file ftp.c.

2220{
2221 BOOL r;
2222 WCHAR *cmdW;
2223
2224 TRACE("%p %d 0x%08x %s 0x%08lx %p\n", hConnect, fExpectResponse, dwFlags,
2225 debugstr_a(lpszCommand), dwContext, phFtpCommand);
2226
2227 if (fExpectResponse)
2228 {
2229 FIXME("data connection not supported\n");
2230 return FALSE;
2231 }
2232
2233 if (!lpszCommand || !lpszCommand[0])
2234 {
2236 return FALSE;
2237 }
2238
2239 if (!(cmdW = heap_strdupAtoW(lpszCommand)))
2240 {
2242 return FALSE;
2243 }
2244
2245 r = FtpCommandW(hConnect, fExpectResponse, dwFlags, cmdW, dwContext, phFtpCommand);
2246
2247 heap_free(cmdW);
2248 return r;
2249}
BOOL WINAPI FtpCommandW(HINTERNET hConnect, BOOL fExpectResponse, DWORD dwFlags, LPCWSTR lpszCommand, DWORD_PTR dwContext, HINTERNET *phFtpCommand)
Definition: ftp.c:2254
GLdouble GLdouble GLdouble r
Definition: gl.h:2055

◆ FtpCommandW()

BOOL WINAPI FtpCommandW ( HINTERNET  hConnect,
BOOL  fExpectResponse,
DWORD  dwFlags,
LPCWSTR  lpszCommand,
DWORD_PTR  dwContext,
HINTERNET phFtpCommand 
)

Definition at line 2254 of file ftp.c.

2256{
2257 BOOL r = FALSE;
2258 ftp_session_t *lpwfs;
2259 LPSTR cmd = NULL;
2260 DWORD len, nBytesSent= 0;
2261 INT nResCode, nRC = 0;
2262
2263 TRACE("%p %d 0x%08x %s 0x%08lx %p\n", hConnect, fExpectResponse, dwFlags,
2264 debugstr_w(lpszCommand), dwContext, phFtpCommand);
2265
2266 if (!lpszCommand || !lpszCommand[0])
2267 {
2269 return FALSE;
2270 }
2271
2272 if (fExpectResponse)
2273 {
2274 FIXME("data connection not supported\n");
2275 return FALSE;
2276 }
2277
2278 lpwfs = (ftp_session_t*) get_handle_object( hConnect );
2279 if (!lpwfs)
2280 {
2282 return FALSE;
2283 }
2284
2285 if (WH_HFTPSESSION != lpwfs->hdr.htype)
2286 {
2288 goto lend;
2289 }
2290
2291 if (lpwfs->download_in_progress != NULL)
2292 {
2294 goto lend;
2295 }
2296
2297 len = WideCharToMultiByte(CP_ACP, 0, lpszCommand, -1, NULL, 0, NULL, NULL) + strlen(szCRLF);
2298 if ((cmd = heap_alloc(len)))
2299 WideCharToMultiByte(CP_ACP, 0, lpszCommand, -1, cmd, len, NULL, NULL);
2300 else
2301 {
2303 goto lend;
2304 }
2305
2306 strcat(cmd, szCRLF);
2307 len--;
2308
2309 TRACE("Sending (%s) len(%d)\n", debugstr_a(cmd), len);
2310 while ((nBytesSent < len) && (nRC != -1))
2311 {
2312 nRC = sock_send(lpwfs->sndSocket, cmd + nBytesSent, len - nBytesSent, 0);
2313 if (nRC != -1)
2314 {
2315 nBytesSent += nRC;
2316 TRACE("Sent %d bytes\n", nRC);
2317 }
2318 }
2319
2320 if (nBytesSent)
2321 {
2322 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
2323 if (nResCode > 0 && nResCode < 400)
2324 r = TRUE;
2325 else
2326 FTP_SetResponseError(nResCode);
2327 }
2328
2329lend:
2330 WININET_Release( &lpwfs->hdr );
2331 heap_free( cmd );
2332 return r;
2333}
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
#define CP_ACP
Definition: compat.h:109
#define ERROR_INVALID_HANDLE
Definition: compat.h:98
#define WideCharToMultiByte
Definition: compat.h:111
object_header_t * get_handle_object(HINTERNET hinternet)
Definition: internet.c:176
Definition: ftp_var.h:139
#define ERROR_INTERNET_INCORRECT_HANDLE_TYPE
Definition: wininet.h:2007

Referenced by FtpCommandA().

◆ FtpCreateDirectoryA()

BOOL WINAPI FtpCreateDirectoryA ( HINTERNET  hConnect,
LPCSTR  lpszDirectory 
)

Definition at line 566 of file ftp.c.

567{
568 LPWSTR lpwzDirectory;
569 BOOL ret;
570
571 lpwzDirectory = heap_strdupAtoW(lpszDirectory);
572 ret = FtpCreateDirectoryW(hConnect, lpwzDirectory);
573 heap_free(lpwzDirectory);
574 return ret;
575}
BOOL WINAPI FtpCreateDirectoryW(HINTERNET hConnect, LPCWSTR lpszDirectory)
Definition: ftp.c:599

Referenced by test_createdir(), and test_openfile().

◆ FtpCreateDirectoryW()

BOOL WINAPI FtpCreateDirectoryW ( HINTERNET  hConnect,
LPCWSTR  lpszDirectory 
)

Definition at line 599 of file ftp.c.

600{
601 ftp_session_t *lpwfs;
602 appinfo_t *hIC = NULL;
603 BOOL r = FALSE;
604
605 lpwfs = (ftp_session_t*) get_handle_object( hConnect );
606 if (!lpwfs)
607 {
609 return FALSE;
610 }
611
612 if (WH_HFTPSESSION != lpwfs->hdr.htype)
613 {
615 goto lend;
616 }
617
618 if (lpwfs->download_in_progress != NULL)
619 {
621 goto lend;
622 }
623
624 if (!lpszDirectory)
625 {
627 goto lend;
628 }
629
630 hIC = lpwfs->lpAppInfo;
632 {
633 directory_task_t *task;
634
635 task = alloc_async_task(&lpwfs->hdr, AsyncFtpCreateDirectoryProc, sizeof(*task));
636 task->directory = heap_strdupW(lpszDirectory);
637
639 }
640 else
641 {
642 r = FTP_FtpCreateDirectoryW(lpwfs, lpszDirectory);
643 }
644lend:
645 WININET_Release( &lpwfs->hdr );
646
647 return r;
648}
static void AsyncFtpCreateDirectoryProc(task_header_t *hdr)
Definition: ftp.c:578
static BOOL res_to_le(DWORD res)
Definition: ftp.c:207
DWORD INTERNET_AsyncCall(task_header_t *task)
Definition: internet.c:3915
void * alloc_async_task(object_header_t *hdr, async_task_proc_t proc, size_t size)
Definition: internet.c:3894

Referenced by FtpCreateDirectoryA().

◆ FtpDeleteFileA()

BOOL WINAPI FtpDeleteFileA ( HINTERNET  hFtpSession,
LPCSTR  lpszFileName 
)

Definition at line 1777 of file ftp.c.

1778{
1779 LPWSTR lpwzFileName;
1780 BOOL ret;
1781
1782 lpwzFileName = heap_strdupAtoW(lpszFileName);
1783 ret = FtpDeleteFileW(hFtpSession, lpwzFileName);
1784 heap_free(lpwzFileName);
1785 return ret;
1786}
BOOL WINAPI FtpDeleteFileW(HINTERNET hFtpSession, LPCWSTR lpszFileName)
Definition: ftp.c:1814

Referenced by test_deletefile(), and test_openfile().

◆ FtpDeleteFileW()

BOOL WINAPI FtpDeleteFileW ( HINTERNET  hFtpSession,
LPCWSTR  lpszFileName 
)

Definition at line 1814 of file ftp.c.

1815{
1816 ftp_session_t *lpwfs;
1817 appinfo_t *hIC = NULL;
1818 BOOL r = FALSE;
1819
1820 lpwfs = (ftp_session_t*) get_handle_object( hFtpSession );
1821 if (!lpwfs)
1822 {
1824 return FALSE;
1825 }
1826
1827 if (WH_HFTPSESSION != lpwfs->hdr.htype)
1828 {
1830 goto lend;
1831 }
1832
1833 if (lpwfs->download_in_progress != NULL)
1834 {
1836 goto lend;
1837 }
1838
1839 if (!lpszFileName)
1840 {
1842 goto lend;
1843 }
1844
1845 hIC = lpwfs->lpAppInfo;
1846 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
1847 {
1848 delete_file_task_t *task;
1849
1850 task = alloc_async_task(&lpwfs->hdr, AsyncFtpDeleteFileProc, sizeof(*task));
1851 task->file_name = heap_strdupW(lpszFileName);
1852
1853 r = res_to_le(INTERNET_AsyncCall(&task->hdr));
1854 }
1855 else
1856 {
1857 r = FTP_FtpDeleteFileW(lpwfs, lpszFileName);
1858 }
1859
1860lend:
1861 WININET_Release( &lpwfs->hdr );
1862
1863 return r;
1864}
static void AsyncFtpDeleteFileProc(task_header_t *hdr)
Definition: ftp.c:1793

Referenced by FtpDeleteFileA().

◆ FTPFILE_AsyncQueryDataAvailableProc()

static void FTPFILE_AsyncQueryDataAvailableProc ( task_header_t task)
static

Definition at line 1248 of file ftp.c.

1249{
1250 ftp_file_t *file = (ftp_file_t*)task->hdr;
1251
1253}

Referenced by FTPFILE_QueryDataAvailable().

◆ FTPFILE_Destroy()

static void FTPFILE_Destroy ( object_header_t hdr)
static

Definition at line 1117 of file ftp.c.

1118{
1119 ftp_file_t *lpwh = (ftp_file_t*) hdr;
1120 ftp_session_t *lpwfs = lpwh->lpFtpSession;
1121 INT nResCode;
1122
1123 TRACE("\n");
1124
1127
1128 heap_free(lpwh->cache_file);
1129
1130 if (!lpwh->session_deleted)
1131 lpwfs->download_in_progress = NULL;
1132
1133 if (lpwh->nDataSocket != -1)
1134 closesocket(lpwh->nDataSocket);
1135
1136 nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
1137 if (nResCode > 0 && nResCode != 226) WARN("server reports failed transfer\n");
1138
1140}

◆ FTPFILE_LockRequestFile()

static DWORD FTPFILE_LockRequestFile ( object_header_t hdr,
req_file_t **  ret 
)
static

Definition at line 1288 of file ftp.c.

1289{
1291 FIXME("%p\n", file);
1292 return ERROR_NOT_SUPPORTED;
1293}
#define ERROR_NOT_SUPPORTED
Definition: compat.h:100

◆ FTPFILE_QueryDataAvailable()

static DWORD FTPFILE_QueryDataAvailable ( object_header_t hdr,
DWORD available,
DWORD  flags,
DWORD_PTR  ctx 
)
static

Definition at line 1255 of file ftp.c.

1256{
1258 ULONG unread = 0;
1259 int retval;
1260
1261 TRACE("(%p %p %x %lx)\n", file, available, flags, ctx);
1262
1263 retval = ioctlsocket(file->nDataSocket, FIONREAD, &unread);
1264 if (!retval)
1265 TRACE("%d bytes of queued, but unread data\n", unread);
1266
1267 *available = unread;
1268
1269 if(!unread) {
1270 BYTE byte;
1271
1272 *available = 0;
1273
1274 retval = sock_recv(file->nDataSocket, &byte, 1, MSG_PEEK);
1275 if(retval > 0) {
1276 task_header_t *task;
1277
1278 task = alloc_async_task(&file->hdr, FTPFILE_AsyncQueryDataAvailableProc, sizeof(*task));
1279 INTERNET_AsyncCall(task);
1280
1281 return ERROR_IO_PENDING;
1282 }
1283 }
1284
1285 return ERROR_SUCCESS;
1286}
#define ERROR_IO_PENDING
Definition: dderror.h:15
#define byte(x, n)
Definition: tomcrypt.h:118
static void FTPFILE_AsyncQueryDataAvailableProc(task_header_t *task)
Definition: ftp.c:1248
GLbitfield flags
Definition: glext.h:7161
#define ioctlsocket
Definition: ncftp.h:481
uint32_t ULONG
Definition: typedefs.h:59
#define FIONREAD
Definition: winsock.h:247

◆ FTPFILE_QueryOption()

static DWORD FTPFILE_QueryOption ( object_header_t hdr,
DWORD  option,
void buffer,
DWORD size,
BOOL  unicode 
)
static

Definition at line 1142 of file ftp.c.

1143{
1144 switch(option) {
1146 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
1147
1148 if (*size < sizeof(ULONG))
1150
1151 *size = sizeof(DWORD);
1153 return ERROR_SUCCESS;
1155 {
1156 DWORD required;
1158
1159 TRACE("INTERNET_OPTION_DATAFILE_NAME\n");
1160
1161 if (!file->cache_file)
1162 {
1163 *size = 0;
1165 }
1166 if (unicode)
1167 {
1168 required = (lstrlenW(file->cache_file) + 1) * sizeof(WCHAR);
1169 if (*size < required)
1171
1172 *size = required;
1173 memcpy(buffer, file->cache_file, *size);
1174 return ERROR_SUCCESS;
1175 }
1176 else
1177 {
1178 required = WideCharToMultiByte(CP_ACP, 0, file->cache_file, -1, NULL, 0, NULL, NULL);
1179 if (required > *size)
1181
1182 *size = WideCharToMultiByte(CP_ACP, 0, file->cache_file, -1, buffer, *size, NULL, NULL);
1183 return ERROR_SUCCESS;
1184 }
1185 }
1186 }
1187 return INET_QueryOption(hdr, option, buffer, size, unicode);
1188}
DWORD INET_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
Definition: internet.c:2654
GLsizeiptr size
Definition: glext.h:5919
Definition: getopt.h:109
#define ERROR_INTERNET_ITEM_NOT_FOUND
Definition: wininet.h:2017
#define INTERNET_OPTION_DATAFILE_NAME
Definition: wininet.h:727
#define INTERNET_OPTION_HANDLE_TYPE
Definition: wininet.h:710
#define INTERNET_HANDLE_TYPE_FTP_FILE
Definition: wininet.h:808

◆ FTPFILE_ReadFile()

static DWORD FTPFILE_ReadFile ( object_header_t hdr,
void buffer,
DWORD  size,
DWORD read,
DWORD  flags,
DWORD_PTR  context 
)
static

Definition at line 1190 of file ftp.c.

1192{
1194 int res;
1195 DWORD error;
1196
1197 if (file->nDataSocket == -1)
1199
1200 /* FIXME: FTP should use NETCON_ stuff */
1201 res = sock_recv(file->nDataSocket, buffer, size, MSG_WAITALL);
1202 *read = res>0 ? res : 0;
1203
1204 error = res >= 0 ? ERROR_SUCCESS : INTERNET_ERROR_BASE; /* FIXME */
1205 if (error == ERROR_SUCCESS && file->cache_file)
1206 {
1207 DWORD bytes_written;
1208
1209 if (!WriteFile(file->cache_file_handle, buffer, *read, &bytes_written, NULL))
1210 WARN("WriteFile failed: %u\n", GetLastError());
1211 }
1212 return error;
1213}
#define read
Definition: acwin.h:96
GLuint res
Definition: glext.h:9613
#define error(str)
Definition: mkdosfs.c:1605
#define INTERNET_ERROR_BASE
Definition: wininet.h:1988
#define ERROR_INTERNET_DISCONNECTED
Definition: wininet.h:2072

◆ FTPFILE_WriteFile()

static DWORD FTPFILE_WriteFile ( object_header_t hdr,
const void buffer,
DWORD  size,
DWORD written 
)
static

Definition at line 1215 of file ftp.c.

1216{
1217 ftp_file_t *lpwh = (ftp_file_t*) hdr;
1218 int res;
1219
1220 res = sock_send(lpwh->nDataSocket, buffer, size, 0);
1221
1222 *written = res>0 ? res : 0;
1223 return res >= 0 ? ERROR_SUCCESS : WSAGetLastError();
1224}

◆ FtpFindFirstFileA()

HINTERNET WINAPI FtpFindFirstFileA ( HINTERNET  hConnect,
LPCSTR  lpszSearchFile,
LPWIN32_FIND_DATAA  lpFindFileData,
DWORD  dwFlags,
DWORD_PTR  dwContext 
)

Definition at line 709 of file ftp.c.

711{
712 LPWSTR lpwzSearchFile;
714 LPWIN32_FIND_DATAW lpFindFileDataW;
716
717 lpwzSearchFile = heap_strdupAtoW(lpszSearchFile);
718 lpFindFileDataW = lpFindFileData?&wfd:NULL;
719 ret = FtpFindFirstFileW(hConnect, lpwzSearchFile, lpFindFileDataW, dwFlags, dwContext);
720 heap_free(lpwzSearchFile);
721
722 if (ret && lpFindFileData)
723 WININET_find_data_WtoA(lpFindFileDataW, lpFindFileData);
724
725 return ret;
726}
HINTERNET WINAPI FtpFindFirstFileW(HINTERNET hConnect, LPCWSTR lpszSearchFile, LPWIN32_FIND_DATAW lpFindFileData, DWORD dwFlags, DWORD_PTR dwContext)
Definition: ftp.c:757
static void WININET_find_data_WtoA(LPWIN32_FIND_DATAW dataW, LPWIN32_FIND_DATAA dataA)
Definition: internet.h:214

Referenced by test_find_first_file().

◆ FtpFindFirstFileW()

HINTERNET WINAPI FtpFindFirstFileW ( HINTERNET  hConnect,
LPCWSTR  lpszSearchFile,
LPWIN32_FIND_DATAW  lpFindFileData,
DWORD  dwFlags,
DWORD_PTR  dwContext 
)

Definition at line 757 of file ftp.c.

759{
760 ftp_session_t *lpwfs;
761 appinfo_t *hIC = NULL;
762 HINTERNET r = NULL;
763
764 lpwfs = (ftp_session_t*) get_handle_object( hConnect );
765 if (NULL == lpwfs || WH_HFTPSESSION != lpwfs->hdr.htype)
766 {
768 goto lend;
769 }
770
771 if (lpwfs->download_in_progress != NULL)
772 {
774 goto lend;
775 }
776
777 hIC = lpwfs->lpAppInfo;
779 {
781
782 task = alloc_async_task(&lpwfs->hdr, AsyncFtpFindFirstFileProc, sizeof(*task));
783 task->search_file = heap_strdupW(lpszSearchFile);
784 task->find_file_data = lpFindFileData;
785 task->flags = dwFlags;
786 task->context = dwContext;
787
788 INTERNET_AsyncCall(&task->hdr);
789 r = NULL;
790 }
791 else
792 {
793 r = FTP_FtpFindFirstFileW(lpwfs, lpszSearchFile, lpFindFileData,
794 dwFlags, dwContext);
795 }
796lend:
797 if( lpwfs )
798 WININET_Release( &lpwfs->hdr );
799
800 return r;
801}
static void AsyncFtpFindFirstFileProc(task_header_t *hdr)
Definition: ftp.c:736

Referenced by FtpFindFirstFileA().

◆ FTPFINDNEXT_AsyncFindNextFileProc()

static void FTPFINDNEXT_AsyncFindNextFileProc ( task_header_t hdr)
static

Definition at line 3482 of file ftp.c.

3483{
3485
3487}
static DWORD FTPFINDNEXT_FindNextFileProc(WININETFTPFINDNEXTW *find, LPVOID data)
Definition: ftp.c:3444
WIN32_FIND_DATAW * find_data
Definition: ftp.c:3479
task_header_t hdr
Definition: ftp.c:3478

Referenced by FTPFINDNEXT_FindNextFileW().

◆ FTPFINDNEXT_Destroy()

static void FTPFINDNEXT_Destroy ( object_header_t hdr)
static

Definition at line 3428 of file ftp.c.

3429{
3431 DWORD i;
3432
3433 TRACE("\n");
3434
3436
3437 for (i = 0; i < lpwfn->size; i++)
3438 {
3439 heap_free(lpwfn->lpafp[i].lpszName);
3440 }
3441 heap_free(lpwfn->lpafp);
3442}
struct WININETFTPFINDNEXTW * LPWININETFTPFINDNEXTW

◆ FTPFINDNEXT_FindNextFileProc()

static DWORD FTPFINDNEXT_FindNextFileProc ( WININETFTPFINDNEXTW find,
LPVOID  data 
)
static

Definition at line 3444 of file ftp.c.

3445{
3448
3449 TRACE("index(%d) size(%d)\n", find->index, find->size);
3450
3452
3453 if (find->index < find->size) {
3454 FTP_ConvertFileProp(&find->lpafp[find->index], find_data);
3455 find->index++;
3456
3457 TRACE("Name: %s\nSize: %d\n", debugstr_w(find_data->cFileName), find_data->nFileSizeLow);
3458 }else {
3460 }
3461
3462 if (find->hdr.dwFlags & INTERNET_FLAG_ASYNC)
3463 {
3465
3466 iar.dwResult = (res == ERROR_SUCCESS);
3467 iar.dwError = res;
3468
3469 INTERNET_SendCallback(&find->hdr, find->hdr.dwContext,
3471 sizeof(INTERNET_ASYNC_RESULT));
3472 }
3473
3474 return res;
3475}
static TAGID TAGID find
Definition: db.cpp:155
static int find_data(const struct Vector *v, const BYTE *pData, int size)
Definition: filtermapper.c:162
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950

Referenced by FTPFINDNEXT_AsyncFindNextFileProc(), and FTPFINDNEXT_FindNextFileW().

◆ FTPFINDNEXT_FindNextFileW()

static DWORD FTPFINDNEXT_FindNextFileW ( object_header_t hdr,
void data 
)
static

Definition at line 3506 of file ftp.c.

3507{
3509
3510 if (find->lpFtpSession->lpAppInfo->hdr.dwFlags & INTERNET_FLAG_ASYNC)
3511 {
3512 find_next_task_t *task;
3513
3514 task = alloc_async_task(&find->hdr, FTPFINDNEXT_AsyncFindNextFileProc, sizeof(*task));
3515 task->find_data = data;
3516
3517 INTERNET_AsyncCall(&task->hdr);
3518 return ERROR_SUCCESS;
3519 }
3520
3522}
static void FTPFINDNEXT_AsyncFindNextFileProc(task_header_t *hdr)
Definition: ftp.c:3482

◆ FTPFINDNEXT_QueryOption()

static DWORD FTPFINDNEXT_QueryOption ( object_header_t hdr,
DWORD  option,
void buffer,
DWORD size,
BOOL  unicode 
)
static

Definition at line 3489 of file ftp.c.

3490{
3491 switch(option) {
3493 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
3494
3495 if (*size < sizeof(ULONG))
3497
3498 *size = sizeof(DWORD);
3500 return ERROR_SUCCESS;
3501 }
3502
3503 return INET_QueryOption(hdr, option, buffer, size, unicode);
3504}
#define INTERNET_HANDLE_TYPE_FTP_FIND
Definition: wininet.h:806

◆ FtpGetCurrentDirectoryA()

BOOL WINAPI FtpGetCurrentDirectoryA ( HINTERNET  hFtpSession,
LPSTR  lpszCurrentDirectory,
LPDWORD  lpdwCurrentDirectory 
)

Definition at line 916 of file ftp.c.

918{
919 WCHAR *dir = NULL;
920 DWORD len;
921 BOOL ret;
922
923 if(lpdwCurrentDirectory) {
924 len = *lpdwCurrentDirectory;
925 if(lpszCurrentDirectory)
926 {
927 dir = heap_alloc(len * sizeof(WCHAR));
928 if (NULL == dir)
929 {
931 return FALSE;
932 }
933 }
934 }
935 ret = FtpGetCurrentDirectoryW(hFtpSession, lpszCurrentDirectory?dir:NULL, lpdwCurrentDirectory?&len:NULL);
936
937 if (ret && lpszCurrentDirectory)
938 WideCharToMultiByte(CP_ACP, 0, dir, -1, lpszCurrentDirectory, len, NULL, NULL);
939
940 if (lpdwCurrentDirectory) *lpdwCurrentDirectory = len;
941 heap_free(dir);
942 return ret;
943}
unsigned int dir
Definition: maze.c:112
BOOL WINAPI FtpGetCurrentDirectoryW(HINTERNET hFtpSession, LPWSTR lpszCurrentDirectory, LPDWORD lpdwCurrentDirectory)
Definition: ftp.c:971

Referenced by test_get_current_dir().

◆ FtpGetCurrentDirectoryW()

BOOL WINAPI FtpGetCurrentDirectoryW ( HINTERNET  hFtpSession,
LPWSTR  lpszCurrentDirectory,
LPDWORD  lpdwCurrentDirectory 
)

Definition at line 971 of file ftp.c.

973{
974 ftp_session_t *lpwfs;
975 appinfo_t *hIC = NULL;
976 BOOL r = FALSE;
977
978 TRACE("%p %p %p\n", hFtpSession, lpszCurrentDirectory, lpdwCurrentDirectory);
979
980 lpwfs = (ftp_session_t*) get_handle_object( hFtpSession );
981 if (NULL == lpwfs)
982 {
984 goto lend;
985 }
986
987 if (WH_HFTPSESSION != lpwfs->hdr.htype)
988 {
990 goto lend;
991 }
992
993 if (!lpdwCurrentDirectory)
994 {
996 goto lend;
997 }
998
999 if (lpszCurrentDirectory == NULL)
1000 {
1002 goto lend;
1003 }
1004
1005 if (lpwfs->download_in_progress != NULL)
1006 {
1008 goto lend;
1009 }
1010
1011 hIC = lpwfs->lpAppInfo;
1012 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
1013 {
1015
1016 task = alloc_async_task(&lpwfs->hdr, AsyncFtpGetCurrentDirectoryProc, sizeof(*task));
1017 task->directory = lpszCurrentDirectory;
1018 task->directory_len = lpdwCurrentDirectory;
1019
1020 r = res_to_le(INTERNET_AsyncCall(&task->hdr));
1021 }
1022 else
1023 {
1024 r = FTP_FtpGetCurrentDirectoryW(lpwfs, lpszCurrentDirectory,
1025 lpdwCurrentDirectory);
1026 }
1027
1028lend:
1029 if( lpwfs )
1030 WININET_Release( &lpwfs->hdr );
1031
1032 return r;
1033}
static void AsyncFtpGetCurrentDirectoryProc(task_header_t *hdr)
Definition: ftp.c:951

Referenced by FtpGetCurrentDirectoryA().

◆ FtpGetFileA()

BOOL WINAPI FtpGetFileA ( HINTERNET  hInternet,
LPCSTR  lpszRemoteFile,
LPCSTR  lpszNewFile,
BOOL  fFailIfExists,
DWORD  dwLocalFlagsAttribute,
DWORD  dwInternetFlags,
DWORD_PTR  dwContext 
)

Definition at line 1559 of file ftp.c.

1562{
1563 LPWSTR lpwzRemoteFile;
1564 LPWSTR lpwzNewFile;
1565 BOOL ret;
1566
1567 lpwzRemoteFile = heap_strdupAtoW(lpszRemoteFile);
1568 lpwzNewFile = heap_strdupAtoW(lpszNewFile);
1569 ret = FtpGetFileW(hInternet, lpwzRemoteFile, lpwzNewFile, fFailIfExists,
1570 dwLocalFlagsAttribute, dwInternetFlags, dwContext);
1571 heap_free(lpwzRemoteFile);
1572 heap_free(lpwzNewFile);
1573 return ret;
1574}
BOOL WINAPI FtpGetFileW(HINTERNET hInternet, LPCWSTR lpszRemoteFile, LPCWSTR lpszNewFile, BOOL fFailIfExists, DWORD dwLocalFlagsAttribute, DWORD dwInternetFlags, DWORD_PTR dwContext)
Definition: ftp.c:1610

Referenced by test_getfile(), test_getfile_no_open(), and test_openfile().

◆ FtpGetFileSize()

DWORD WINAPI FtpGetFileSize ( HINTERNET  hFile,
LPDWORD  lpdwFileSizeHigh 
)

Definition at line 1757 of file ftp.c.

1758{
1759 FIXME("(%p, %p)\n", hFile, lpdwFileSizeHigh);
1760
1761 if (lpdwFileSizeHigh)
1762 *lpdwFileSizeHigh = 0;
1763
1764 return 0;
1765}

Referenced by FtpProtocol_start_downloading(), and CDownloadManager::ThreadFunc().

◆ FtpGetFileW()

BOOL WINAPI FtpGetFileW ( HINTERNET  hInternet,
LPCWSTR  lpszRemoteFile,
LPCWSTR  lpszNewFile,
BOOL  fFailIfExists,
DWORD  dwLocalFlagsAttribute,
DWORD  dwInternetFlags,
DWORD_PTR  dwContext 
)

Definition at line 1610 of file ftp.c.

1613{
1614 ftp_session_t *lpwfs;
1615 appinfo_t *hIC = NULL;
1616 BOOL r = FALSE;
1617
1618 if (!lpszRemoteFile || !lpszNewFile)
1619 {
1621 return FALSE;
1622 }
1623
1624 lpwfs = (ftp_session_t*) get_handle_object( hInternet );
1625 if (!lpwfs)
1626 {
1628 return FALSE;
1629 }
1630
1631 if (WH_HFTPSESSION != lpwfs->hdr.htype)
1632 {
1634 goto lend;
1635 }
1636
1637 if ((dwInternetFlags & FTP_CONDITION_MASK) > FTP_TRANSFER_TYPE_BINARY)
1638 {
1640 goto lend;
1641 }
1642
1643 if (lpwfs->download_in_progress != NULL)
1644 {
1646 goto lend;
1647 }
1648
1649 hIC = lpwfs->lpAppInfo;
1650 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
1651 {
1652 get_file_task_t *task;
1653
1654 task = alloc_async_task(&lpwfs->hdr, AsyncFtpGetFileProc, sizeof(*task));
1655 task->remote_file = heap_strdupW(lpszRemoteFile);
1656 task->new_file = heap_strdupW(lpszNewFile);
1657 task->local_attr = dwLocalFlagsAttribute;
1658 task->fail_if_exists = fFailIfExists;
1659 task->flags = dwInternetFlags;
1660 task->context = dwContext;
1661
1662 r = res_to_le(INTERNET_AsyncCall(&task->hdr));
1663 }
1664 else
1665 {
1666 r = FTP_FtpGetFileW(lpwfs, lpszRemoteFile, lpszNewFile,
1667 fFailIfExists, dwLocalFlagsAttribute, dwInternetFlags, dwContext);
1668 }
1669
1670lend:
1671 WININET_Release( &lpwfs->hdr );
1672
1673 return r;
1674}
static void AsyncFtpGetFileProc(task_header_t *hdr)
Definition: ftp.c:1586
#define FTP_CONDITION_MASK
Definition: ftp.c:114
#define FTP_TRANSFER_TYPE_BINARY
Definition: wininet.h:919

Referenced by FtpGetFileA().

◆ FtpOpenFileA()

HINTERNET WINAPI FtpOpenFileA ( HINTERNET  hFtpSession,
LPCSTR  lpszFileName,
DWORD  fdwAccess,
DWORD  dwFlags,
DWORD_PTR  dwContext 
)

Definition at line 1443 of file ftp.c.

1446{
1447 LPWSTR lpwzFileName;
1448 HINTERNET ret;
1449
1450 lpwzFileName = heap_strdupAtoW(lpszFileName);
1451 ret = FtpOpenFileW(hFtpSession, lpwzFileName, fdwAccess, dwFlags, dwContext);
1452 heap_free(lpwzFileName);
1453 return ret;
1454}
HINTERNET WINAPI FtpOpenFileW(HINTERNET hFtpSession, LPCWSTR lpszFileName, DWORD fdwAccess, DWORD dwFlags, DWORD_PTR dwContext)
Definition: ftp.c:1485

Referenced by test_find_first_file(), and test_openfile().

◆ FtpOpenFileW()

HINTERNET WINAPI FtpOpenFileW ( HINTERNET  hFtpSession,
LPCWSTR  lpszFileName,
DWORD  fdwAccess,
DWORD  dwFlags,
DWORD_PTR  dwContext 
)

Definition at line 1485 of file ftp.c.

1488{
1489 ftp_session_t *lpwfs;
1490 appinfo_t *hIC = NULL;
1491 HINTERNET r = NULL;
1492
1493 TRACE("(%p,%s,0x%08x,0x%08x,0x%08lx)\n", hFtpSession,
1494 debugstr_w(lpszFileName), fdwAccess, dwFlags, dwContext);
1495
1496 lpwfs = (ftp_session_t*) get_handle_object( hFtpSession );
1497 if (!lpwfs)
1498 {
1500 return FALSE;
1501 }
1502
1503 if (WH_HFTPSESSION != lpwfs->hdr.htype)
1504 {
1506 goto lend;
1507 }
1508
1509 if ((!lpszFileName) ||
1510 ((fdwAccess != GENERIC_READ) && (fdwAccess != GENERIC_WRITE)) ||
1512 {
1514 goto lend;
1515 }
1516
1517 if (lpwfs->download_in_progress != NULL)
1518 {
1520 goto lend;
1521 }
1522
1523 hIC = lpwfs->lpAppInfo;
1524 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
1525 {
1526 open_file_task_t *task;
1527
1528 task = alloc_async_task(&lpwfs->hdr, AsyncFtpOpenFileProc, sizeof(*task));
1529 task->file_name = heap_strdupW(lpszFileName);
1530 task->access = fdwAccess;
1531 task->flags = dwFlags;
1532 task->context = dwContext;
1533
1534 INTERNET_AsyncCall(&task->hdr);
1535 r = NULL;
1536 }
1537 else
1538 {
1539 r = FTP_FtpOpenFileW(lpwfs, lpszFileName, fdwAccess, dwFlags, dwContext);
1540 }
1541
1542lend:
1543 WININET_Release( &lpwfs->hdr );
1544
1545 return r;
1546}
static void AsyncFtpOpenFileProc(task_header_t *hdr)
Definition: ftp.c:1464

Referenced by FtpOpenFileA(), and INTERNET_InternetOpenUrlW().

◆ FtpPutFileA()

BOOL WINAPI FtpPutFileA ( HINTERNET  hConnect,
LPCSTR  lpszLocalFile,
LPCSTR  lpszNewRemoteFile,
DWORD  dwFlags,
DWORD_PTR  dwContext 
)

Definition at line 224 of file ftp.c.

226{
227 LPWSTR lpwzLocalFile;
228 LPWSTR lpwzNewRemoteFile;
229 BOOL ret;
230
231 lpwzLocalFile = heap_strdupAtoW(lpszLocalFile);
232 lpwzNewRemoteFile = heap_strdupAtoW(lpszNewRemoteFile);
233 ret = FtpPutFileW(hConnect, lpwzLocalFile, lpwzNewRemoteFile,
234 dwFlags, dwContext);
235 heap_free(lpwzLocalFile);
236 heap_free(lpwzNewRemoteFile);
237 return ret;
238}
BOOL WINAPI FtpPutFileW(HINTERNET hConnect, LPCWSTR lpszLocalFile, LPCWSTR lpszNewRemoteFile, DWORD dwFlags, DWORD_PTR dwContext)
Definition: ftp.c:272

Referenced by test_openfile(), and test_putfile().

◆ FtpPutFileW()

BOOL WINAPI FtpPutFileW ( HINTERNET  hConnect,
LPCWSTR  lpszLocalFile,
LPCWSTR  lpszNewRemoteFile,
DWORD  dwFlags,
DWORD_PTR  dwContext 
)

Definition at line 272 of file ftp.c.

274{
275 ftp_session_t *lpwfs;
276 appinfo_t *hIC = NULL;
277 BOOL r = FALSE;
278
279 if (!lpszLocalFile || !lpszNewRemoteFile)
280 {
282 return FALSE;
283 }
284
285 lpwfs = (ftp_session_t*) get_handle_object( hConnect );
286 if (!lpwfs)
287 {
289 return FALSE;
290 }
291
292 if (WH_HFTPSESSION != lpwfs->hdr.htype)
293 {
295 goto lend;
296 }
297
298 if (lpwfs->download_in_progress != NULL)
299 {
301 goto lend;
302 }
303
305 {
307 goto lend;
308 }
309
310 hIC = lpwfs->lpAppInfo;
312 {
313 put_file_task_t *task = alloc_async_task(&lpwfs->hdr, AsyncFtpPutFileProc, sizeof(*task));
314
315 task->local_file = heap_strdupW(lpszLocalFile);
316 task->remote_file = heap_strdupW(lpszNewRemoteFile);
317 task->flags = dwFlags;
318 task->context = dwContext;
319
321 }
322 else
323 {
324 r = FTP_FtpPutFileW(lpwfs, lpszLocalFile,
325 lpszNewRemoteFile, dwFlags, dwContext);
326 }
327
328lend:
329 WININET_Release( &lpwfs->hdr );
330
331 return r;
332}
static void AsyncFtpPutFileProc(task_header_t *hdr)
Definition: ftp.c:248

Referenced by FtpPutFileA().

◆ FtpRemoveDirectoryA()

BOOL WINAPI FtpRemoveDirectoryA ( HINTERNET  hFtpSession,
LPCSTR  lpszDirectory 
)

Definition at line 1924 of file ftp.c.

1925{
1926 LPWSTR lpwzDirectory;
1927 BOOL ret;
1928
1929 lpwzDirectory = heap_strdupAtoW(lpszDirectory);
1930 ret = FtpRemoveDirectoryW(hFtpSession, lpwzDirectory);
1931 heap_free(lpwzDirectory);
1932 return ret;
1933}
BOOL WINAPI FtpRemoveDirectoryW(HINTERNET hFtpSession, LPCWSTR lpszDirectory)
Definition: ftp.c:1956

Referenced by test_openfile(), and test_removedir().

◆ FtpRemoveDirectoryW()

BOOL WINAPI FtpRemoveDirectoryW ( HINTERNET  hFtpSession,
LPCWSTR  lpszDirectory 
)

Definition at line 1956 of file ftp.c.

1957{
1958 ftp_session_t *lpwfs;
1959 appinfo_t *hIC = NULL;
1960 BOOL r = FALSE;
1961
1962 lpwfs = (ftp_session_t*) get_handle_object( hFtpSession );
1963 if (!lpwfs)
1964 {
1966 return FALSE;
1967 }
1968
1969 if (WH_HFTPSESSION != lpwfs->hdr.htype)
1970 {
1972 goto lend;
1973 }
1974
1975 if (lpwfs->download_in_progress != NULL)
1976 {
1978 goto lend;
1979 }
1980
1981 if (!lpszDirectory)
1982 {
1984 goto lend;
1985 }
1986
1987 hIC = lpwfs->lpAppInfo;
1988 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
1989 {
1990 directory_task_t *task;
1991
1992 task = alloc_async_task(&lpwfs->hdr, AsyncFtpRemoveDirectoryProc, sizeof(*task));
1993 task->directory = heap_strdupW(lpszDirectory);
1994
1995 r = res_to_le(INTERNET_AsyncCall(&task->hdr));
1996 }
1997 else
1998 {
1999 r = FTP_FtpRemoveDirectoryW(lpwfs, lpszDirectory);
2000 }
2001
2002lend:
2003 WININET_Release( &lpwfs->hdr );
2004
2005 return r;
2006}
static void AsyncFtpRemoveDirectoryProc(task_header_t *hdr)
Definition: ftp.c:1935

Referenced by FtpRemoveDirectoryA().

◆ FtpRenameFileA()

BOOL WINAPI FtpRenameFileA ( HINTERNET  hFtpSession,
LPCSTR  lpszSrc,
LPCSTR  lpszDest 
)

Definition at line 2067 of file ftp.c.

2068{
2069 LPWSTR lpwzSrc;
2070 LPWSTR lpwzDest;
2071 BOOL ret;
2072
2073 lpwzSrc = heap_strdupAtoW(lpszSrc);
2074 lpwzDest = heap_strdupAtoW(lpszDest);
2075 ret = FtpRenameFileW(hFtpSession, lpwzSrc, lpwzDest);
2076 heap_free(lpwzSrc);
2077 heap_free(lpwzDest);
2078 return ret;
2079}
BOOL WINAPI FtpRenameFileW(HINTERNET hFtpSession, LPCWSTR lpszSrc, LPCWSTR lpszDest)
Definition: ftp.c:2109

Referenced by test_openfile(), and test_renamefile().

◆ FtpRenameFileW()

BOOL WINAPI FtpRenameFileW ( HINTERNET  hFtpSession,
LPCWSTR  lpszSrc,
LPCWSTR  lpszDest 
)

Definition at line 2109 of file ftp.c.

2110{
2111 ftp_session_t *lpwfs;
2112 appinfo_t *hIC = NULL;
2113 BOOL r = FALSE;
2114
2115 lpwfs = (ftp_session_t*) get_handle_object( hFtpSession );
2116 if (!lpwfs)
2117 {
2119 return FALSE;
2120 }
2121
2122 if (WH_HFTPSESSION != lpwfs->hdr.htype)
2123 {
2125 goto lend;
2126 }
2127
2128 if (lpwfs->download_in_progress != NULL)
2129 {
2131 goto lend;
2132 }
2133
2134 if (!lpszSrc || !lpszDest)
2135 {
2137 goto lend;
2138 }
2139
2140 hIC = lpwfs->lpAppInfo;
2141 if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
2142 {
2143 rename_file_task_t *task;
2144
2145 task = alloc_async_task(&lpwfs->hdr, AsyncFtpRenameFileProc, sizeof(*task));
2146 task->src_file = heap_strdupW(lpszSrc);
2148
2149 r = res_to_le(INTERNET_AsyncCall(&task->hdr));
2150 }
2151 else
2152 {
2153 r = FTP_FtpRenameFileW(lpwfs, lpszSrc, lpszDest);
2154 }
2155
2156lend:
2157 WININET_Release( &lpwfs->hdr );
2158
2159 return r;
2160}
static void AsyncFtpRenameFileProc(task_header_t *hdr)
Definition: ftp.c:2087

Referenced by FtpRenameFileA().

◆ FTPSESSION_CloseConnection()

static void FTPSESSION_CloseConnection ( object_header_t hdr)
static

Definition at line 2354 of file ftp.c.

2355{
2356 ftp_session_t *lpwfs = (ftp_session_t*) hdr;
2357
2358 TRACE("\n");
2359
2360 INTERNET_SendCallback(&lpwfs->hdr, lpwfs->hdr.dwContext,
2362
2363 if (lpwfs->download_in_progress != NULL)
2365
2366 if (lpwfs->sndSocket != -1)
2367 closesocket(lpwfs->sndSocket);
2368
2369 if (lpwfs->lstnSocket != -1)
2370 closesocket(lpwfs->lstnSocket);
2371
2372 if (lpwfs->pasvSocket != -1)
2373 closesocket(lpwfs->pasvSocket);
2374
2375 INTERNET_SendCallback(&lpwfs->hdr, lpwfs->hdr.dwContext,
2377}
#define INTERNET_STATUS_CONNECTION_CLOSED
Definition: wininet.h:894
#define INTERNET_STATUS_CLOSING_CONNECTION
Definition: wininet.h:893

◆ FTPSESSION_Destroy()

static void FTPSESSION_Destroy ( object_header_t hdr)
static

Definition at line 2341 of file ftp.c.

2342{
2343 ftp_session_t *lpwfs = (ftp_session_t*) hdr;
2344
2345 TRACE("\n");
2346
2347 WININET_Release(&lpwfs->lpAppInfo->hdr);
2348
2349 heap_free(lpwfs->lpszPassword);
2350 heap_free(lpwfs->lpszUserName);
2351 heap_free(lpwfs->servername);
2352}

◆ FTPSESSION_QueryOption()

static DWORD FTPSESSION_QueryOption ( object_header_t hdr,
DWORD  option,
void buffer,
DWORD size,
BOOL  unicode 
)
static

Definition at line 2379 of file ftp.c.

2380{
2381 switch(option) {
2383 TRACE("INTERNET_OPTION_HANDLE_TYPE\n");
2384
2385 if (*size < sizeof(ULONG))
2387
2388 *size = sizeof(DWORD);
2390 return ERROR_SUCCESS;
2391 }
2392
2393 return INET_QueryOption(hdr, option, buffer, size, unicode);
2394}
#define INTERNET_HANDLE_TYPE_CONNECT_FTP
Definition: wininet.h:803

◆ FtpSetCurrentDirectoryA()

BOOL WINAPI FtpSetCurrentDirectoryA ( HINTERNET  hConnect,
LPCSTR  lpszDirectory 
)

Definition at line 419 of file ftp.c.

420{
421 LPWSTR lpwzDirectory;
422 BOOL ret;
423
424 lpwzDirectory = heap_strdupAtoW(lpszDirectory);
425 ret = FtpSetCurrentDirectoryW(hConnect, lpwzDirectory);
426 heap_free(lpwzDirectory);
427 return ret;
428}
BOOL WINAPI FtpSetCurrentDirectoryW(HINTERNET hConnect, LPCWSTR lpszDirectory)
Definition: ftp.c:456

Referenced by test_find_first_file().

◆ FtpSetCurrentDirectoryW()

BOOL WINAPI FtpSetCurrentDirectoryW ( HINTERNET  hConnect,
LPCWSTR  lpszDirectory 
)

Definition at line 456 of file ftp.c.

457{
458 ftp_session_t *lpwfs = NULL;
459 appinfo_t *hIC = NULL;
460 BOOL r = FALSE;
461
462 if (!lpszDirectory)
463 {
465 goto lend;
466 }
467
468 lpwfs = (ftp_session_t*) get_handle_object( hConnect );
469 if (NULL == lpwfs || WH_HFTPSESSION != lpwfs->hdr.htype)
470 {
472 goto lend;
473 }
474
475 if (lpwfs->download_in_progress != NULL)
476 {
478 goto lend;
479 }
480
481 TRACE("lpszDirectory(%s)\n", debugstr_w(lpszDirectory));
482
483 hIC = lpwfs->lpAppInfo;
485 {
486 directory_task_t *task;
487
488 task = alloc_async_task(&lpwfs->hdr, AsyncFtpSetCurrentDirectoryProc, sizeof(*task));
489 task->directory = heap_strdupW(lpszDirectory);
490
492 }
493 else
494 {
495 r = FTP_FtpSetCurrentDirectoryW(lpwfs, lpszDirectory);
496 }
497
498lend:
499 if( lpwfs )
500 WININET_Release( &lpwfs->hdr );
501
502 return r;
503}
static void AsyncFtpSetCurrentDirectoryProc(task_header_t *hdr)
Definition: ftp.c:435

Referenced by FtpSetCurrentDirectoryA().

◆ res_to_le()

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( wininet  )

Variable Documentation

◆ FTPFILEVtbl

const object_vtbl_t FTPFILEVtbl
static
Initial value:
= {
}
static DWORD FTPFILE_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
Definition: ftp.c:1142
static DWORD FTPFILE_QueryDataAvailable(object_header_t *hdr, DWORD *available, DWORD flags, DWORD_PTR ctx)
Definition: ftp.c:1255
static DWORD FTPFILE_ReadFile(object_header_t *hdr, void *buffer, DWORD size, DWORD *read, DWORD flags, DWORD_PTR context)
Definition: ftp.c:1190
static DWORD FTPFILE_LockRequestFile(object_header_t *hdr, req_file_t **ret)
Definition: ftp.c:1288
static DWORD FTPFILE_WriteFile(object_header_t *hdr, const void *buffer, DWORD size, DWORD *written)
Definition: ftp.c:1215
static void FTPFILE_Destroy(object_header_t *hdr)
Definition: ftp.c:1117
DWORD INET_SetOption(object_header_t *hdr, DWORD option, void *buf, DWORD size)
Definition: internet.c:2753

Definition at line 1295 of file ftp.c.

Referenced by FTP_FtpOpenFileW().

◆ FTPFINDNEXTVtbl

const object_vtbl_t FTPFINDNEXTVtbl
static
Initial value:
= {
}
static DWORD FTPFINDNEXT_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
Definition: ftp.c:3489
static DWORD FTPFINDNEXT_FindNextFileW(object_header_t *hdr, void *data)
Definition: ftp.c:3506
static void FTPFINDNEXT_Destroy(object_header_t *hdr)
Definition: ftp.c:3428

Definition at line 3524 of file ftp.c.

Referenced by FTP_ReceiveFileList().

◆ FTPSESSIONVtbl

const object_vtbl_t FTPSESSIONVtbl
static
Initial value:
= {
}
static void FTPSESSION_Destroy(object_header_t *hdr)
Definition: ftp.c:2341
static DWORD FTPSESSION_QueryOption(object_header_t *hdr, DWORD option, void *buffer, DWORD *size, BOOL unicode)
Definition: ftp.c:2379
static void FTPSESSION_CloseConnection(object_header_t *hdr)
Definition: ftp.c:2354

Definition at line 2396 of file ftp.c.

Referenced by FTP_Connect().

◆ szFtpCommands

const CHAR* const szFtpCommands[]
static
Initial value:
= {
"ACCT",
"CWD",
"DELE",
"MKD",
"PASS",
"PORT",
"RETR",
"RMD",
"RNFR",
"RNTO",
"STOR",
"TYPE",
"USER",
"SIZE",
"ABOR",
"LIST",
"NLST",
"PASV",
"PWD",
"QUIT",
}

Definition at line 142 of file ftp.c.

Referenced by FTP_SendCommandA().

◆ szMonths

const CHAR szMonths[] = "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC"
static

Definition at line 165 of file ftp.c.

Referenced by FTP_ParseNextFile().