Commit 5b04d3d6 authored by Paul Vriens's avatar Paul Vriens Committed by Alexandre Julliard

wininet/ftp.c: Fix some returned error codes.

parent bb7bc013
...@@ -64,6 +64,11 @@ WINE_DEFAULT_DEBUG_CHANNEL(wininet); ...@@ -64,6 +64,11 @@ WINE_DEFAULT_DEBUG_CHANNEL(wininet);
#define szCRLF "\r\n" #define szCRLF "\r\n"
#define MAX_BACKLOG 5 #define MAX_BACKLOG 5
/* Testing shows that Windows only accepts dwFlags where the last
* 3 (yes 3) bits define FTP_TRANSFER_TYPE_UNKNOWN, FTP_TRANSFER_TYPE_ASCII or FTP_TRANSFER_TYPE_BINARY.
*/
#define FTP_CONDITION_MASK 0x0007
typedef enum { typedef enum {
/* FTP commands with arguments. */ /* FTP commands with arguments. */
FTP_CMD_ACCT, FTP_CMD_ACCT,
...@@ -201,13 +206,31 @@ BOOL WINAPI FtpPutFileW(HINTERNET hConnect, LPCWSTR lpszLocalFile, ...@@ -201,13 +206,31 @@ BOOL WINAPI FtpPutFileW(HINTERNET hConnect, LPCWSTR lpszLocalFile,
LPWININETAPPINFOW hIC = NULL; LPWININETAPPINFOW hIC = NULL;
BOOL r = FALSE; BOOL r = FALSE;
if (!lpszLocalFile || !lpszNewRemoteFile)
{
INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
lpwfs = (LPWININETFTPSESSIONW) WININET_GetObject( hConnect ); lpwfs = (LPWININETFTPSESSIONW) WININET_GetObject( hConnect );
if (NULL == lpwfs || WH_HFTPSESSION != lpwfs->hdr.htype) if (!lpwfs)
{
INTERNET_SetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}
if (WH_HFTPSESSION != lpwfs->hdr.htype)
{ {
INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE); INTERNET_SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE);
goto lend; goto lend;
} }
if ((dwFlags & FTP_CONDITION_MASK) > FTP_TRANSFER_TYPE_BINARY)
{
INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
goto lend;
}
hIC = lpwfs->lpAppInfo; hIC = lpwfs->lpAppInfo;
if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC) if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
{ {
...@@ -230,7 +253,6 @@ BOOL WINAPI FtpPutFileW(HINTERNET hConnect, LPCWSTR lpszLocalFile, ...@@ -230,7 +253,6 @@ BOOL WINAPI FtpPutFileW(HINTERNET hConnect, LPCWSTR lpszLocalFile,
} }
lend: lend:
if( lpwfs )
WININET_Release( &lpwfs->hdr ); WININET_Release( &lpwfs->hdr );
return r; return r;
...@@ -256,24 +278,19 @@ BOOL WINAPI FTP_FtpPutFileW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszLocalFile, ...@@ -256,24 +278,19 @@ BOOL WINAPI FTP_FtpPutFileW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszLocalFile,
TRACE(" lpszLocalFile(%s) lpszNewRemoteFile(%s)\n", debugstr_w(lpszLocalFile), debugstr_w(lpszNewRemoteFile)); TRACE(" lpszLocalFile(%s) lpszNewRemoteFile(%s)\n", debugstr_w(lpszLocalFile), debugstr_w(lpszNewRemoteFile));
if (!lpszLocalFile || !lpszNewRemoteFile)
{
INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
/* Clear any error information */ /* Clear any error information */
INTERNET_SetLastError(0); INTERNET_SetLastError(0);
hIC = lpwfs->lpAppInfo;
/* Open file to be uploaded */ /* Open file to be uploaded */
if (INVALID_HANDLE_VALUE == if (INVALID_HANDLE_VALUE ==
(hFile = CreateFileW(lpszLocalFile, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0))) (hFile = CreateFileW(lpszLocalFile, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0)))
{ {
INTERNET_SetLastError(ERROR_FILE_NOT_FOUND); INTERNET_SetLastError(ERROR_FILE_NOT_FOUND);
goto lend; return FALSE;
} }
hIC = lpwfs->lpAppInfo;
SendAsyncCallback(&lpwfs->hdr, lpwfs->hdr.dwContext, INTERNET_STATUS_SENDING_REQUEST, NULL, 0); SendAsyncCallback(&lpwfs->hdr, lpwfs->hdr.dwContext, INTERNET_STATUS_SENDING_REQUEST, NULL, 0);
if (FTP_SendStore(lpwfs, lpszNewRemoteFile, dwFlags)) if (FTP_SendStore(lpwfs, lpszNewRemoteFile, dwFlags))
...@@ -296,7 +313,6 @@ BOOL WINAPI FTP_FtpPutFileW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszLocalFile, ...@@ -296,7 +313,6 @@ BOOL WINAPI FTP_FtpPutFileW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszLocalFile,
} }
} }
lend:
if (lpwfs->lstnSocket != -1) if (lpwfs->lstnSocket != -1)
closesocket(lpwfs->lstnSocket); closesocket(lpwfs->lstnSocket);
...@@ -1193,8 +1209,6 @@ static void AsyncFtpGetFileProc(WORKREQUEST *workRequest) ...@@ -1193,8 +1209,6 @@ static void AsyncFtpGetFileProc(WORKREQUEST *workRequest)
HeapFree(GetProcessHeap(), 0, req->lpszNewFile); HeapFree(GetProcessHeap(), 0, req->lpszNewFile);
} }
#define FTP_CONDITION_MASK 0x0007
BOOL WINAPI FtpGetFileW(HINTERNET hInternet, LPCWSTR lpszRemoteFile, LPCWSTR lpszNewFile, BOOL WINAPI FtpGetFileW(HINTERNET hInternet, LPCWSTR lpszRemoteFile, LPCWSTR lpszNewFile,
BOOL fFailIfExists, DWORD dwLocalFlagsAttribute, DWORD dwInternetFlags, BOOL fFailIfExists, DWORD dwLocalFlagsAttribute, DWORD dwInternetFlags,
DWORD dwContext) DWORD dwContext)
...@@ -1222,10 +1236,6 @@ BOOL WINAPI FtpGetFileW(HINTERNET hInternet, LPCWSTR lpszRemoteFile, LPCWSTR lps ...@@ -1222,10 +1236,6 @@ BOOL WINAPI FtpGetFileW(HINTERNET hInternet, LPCWSTR lpszRemoteFile, LPCWSTR lps
goto lend; goto lend;
} }
/* Testing shows that Windows only accepts dwInternetFlags where the last
* 3 (yes 3) bits define FTP_TRANSFER_TYPE_UNKNOWN, FTP_TRANSFER_TYPE_ASCII or FTP_TRANSFER_TYPE_BINARY.
*/
if ((dwInternetFlags & FTP_CONDITION_MASK) > FTP_TRANSFER_TYPE_BINARY) if ((dwInternetFlags & FTP_CONDITION_MASK) > FTP_TRANSFER_TYPE_BINARY)
{ {
INTERNET_SetLastError(ERROR_INVALID_PARAMETER); INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
......
...@@ -245,7 +245,7 @@ static void test_getfile(void) ...@@ -245,7 +245,7 @@ static void test_getfile(void)
* Condition flags * Condition flags
*/ */
/* Test to show existence of local file is tested first (together with 'remote file') */ /* Test to show validity of 'local file' parameter is tested first (together with 'remote file') */
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
bRet = FtpGetFileA(NULL, NULL, "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0); bRet = FtpGetFileA(NULL, NULL, "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n"); ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
...@@ -519,11 +519,25 @@ static void test_putfile(void) ...@@ -519,11 +519,25 @@ static void test_putfile(void)
HINTERNET hInternet, hFtp, hConnect; HINTERNET hInternet, hFtp, hConnect;
HANDLE hFile; HANDLE hFile;
/* Invalid internet handle, the rest are valid parameters */ /* The order of checking is:
*
* All parameters except 'session handle' and 'condition flags'
* Session handle
* Session handle type
* Condition flags
*/
/* Test to show validity of 'local file' parameter is tested first (together with 'remote file') */
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
bRet = FtpPutFileA(NULL, "non_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0); bRet = FtpPutFileA(NULL, NULL, "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
ok ( GetLastError() == ERROR_INVALID_PARAMETER,
"Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
/* Test to show session handle is checked before 'condition flags' */
SetLastError(0xdeadbeef);
bRet = FtpPutFileA(NULL, "non_existing_local", "non_existing_remote", 5, 0);
ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n"); ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
todo_wine
ok ( GetLastError() == ERROR_INVALID_HANDLE, ok ( GetLastError() == ERROR_INVALID_HANDLE,
"Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError()); "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
...@@ -556,7 +570,6 @@ static void test_putfile(void) ...@@ -556,7 +570,6 @@ static void test_putfile(void)
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
bRet = FtpPutFileA(hFtp, "non_existing_local", "non_existing_remote", 5, 0); bRet = FtpPutFileA(hFtp, "non_existing_local", "non_existing_remote", 5, 0);
ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n"); ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
todo_wine
ok ( GetLastError() == ERROR_INVALID_PARAMETER, ok ( GetLastError() == ERROR_INVALID_PARAMETER,
"Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
...@@ -564,7 +577,6 @@ static void test_putfile(void) ...@@ -564,7 +577,6 @@ static void test_putfile(void)
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
bRet = FtpPutFileA(hFtp, "non_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0); bRet = FtpPutFileA(hFtp, "non_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n"); ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
todo_wine
ok ( GetLastError() == ERROR_FILE_NOT_FOUND, ok ( GetLastError() == ERROR_FILE_NOT_FOUND,
"Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError()); "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
...@@ -590,7 +602,14 @@ static void test_putfile(void) ...@@ -590,7 +602,14 @@ static void test_putfile(void)
hConnect = InternetConnect(hInternet, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); hConnect = InternetConnect(hInternet, "www.winehq.org", INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);
/* One small test to show that handle type is checked before parameters */ /* Test to show validity of 'local file' parameter is tested a before 'session handle type' */
SetLastError(0xdeadbeef);
bRet = FtpPutFileA(hConnect, NULL, "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
ok ( GetLastError() == ERROR_INVALID_PARAMETER,
"Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
/* Test to show that 'session handle type' is checked before 'condition flags' */
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
bRet = FtpPutFileA(hConnect, "non_existing_local", "non_existing_remote", 5, 0); bRet = FtpPutFileA(hConnect, "non_existing_local", "non_existing_remote", 5, 0);
ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n"); ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment