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

Alexandre Julliard julliard at wine.codeweavers.com
Tue Feb 20 05:25:01 CST 2007


Module: wine
Branch: master
Commit: 8316b93386d3d4074d28c7665cde6008c3648071
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=8316b93386d3d4074d28c7665cde6008c3648071

Author: Paul Vriens <paul.vriens.wine at gmail.com>
Date:   Mon Feb 19 19:34:58 2007 +0100

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

---

 dlls/wininet/ftp.c       |   19 ++++++++++++++++---
 dlls/wininet/tests/ftp.c |   18 ++++++++----------
 2 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/dlls/wininet/ftp.c b/dlls/wininet/ftp.c
index 6bc21ff..ed49af8 100644
--- a/dlls/wininet/ftp.c
+++ b/dlls/wininet/ftp.c
@@ -1027,12 +1027,26 @@ HINTERNET WINAPI FtpOpenFileW(HINTERNET hFtpSession,
         debugstr_w(lpszFileName), fdwAccess, dwFlags, dwContext);
 
     lpwfs = (LPWININETFTPSESSIONW) WININET_GetObject( hFtpSession );
-    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);
         goto lend;
     }
 
+    if ((!lpszFileName) ||
+        ((fdwAccess != GENERIC_READ) && (fdwAccess != GENERIC_WRITE)) ||
+        ((dwFlags & FTP_CONDITION_MASK) > FTP_TRANSFER_TYPE_BINARY))
+    {
+        INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
+        goto lend;
+    }
+
     if (lpwfs->download_in_progress != NULL) {
 	INTERNET_SetLastError(ERROR_FTP_TRANSFER_IN_PROGRESS);
 	goto lend;
@@ -1060,8 +1074,7 @@ HINTERNET WINAPI FtpOpenFileW(HINTERNET hFtpSession,
     }
 
 lend:
-    if( lpwfs )
-        WININET_Release( &lpwfs->hdr );
+    WININET_Release( &lpwfs->hdr );
 
     return r;
 }
diff --git a/dlls/wininet/tests/ftp.c b/dlls/wininet/tests/ftp.c
index 840d91b..770fdeb 100644
--- a/dlls/wininet/tests/ftp.c
+++ b/dlls/wininet/tests/ftp.c
@@ -409,7 +409,6 @@ static void test_openfile(void)
     SetLastError(0xdeadbeef);
     hOpenFile = FtpOpenFileA(NULL, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
     ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
-    todo_wine
     ok ( GetLastError() == ERROR_INVALID_HANDLE,
         "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
     InternetCloseHandle(hOpenFile); /* Just in case */
@@ -429,7 +428,6 @@ static void test_openfile(void)
     SetLastError(0xdeadbeef);
     hOpenFile = FtpOpenFileA(hFtp, NULL, GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
     ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
-    todo_wine
     ok ( GetLastError() == ERROR_INVALID_PARAMETER,
         "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
     InternetCloseHandle(hOpenFile); /* Just in case */
@@ -438,7 +436,6 @@ static void test_openfile(void)
     SetLastError(0xdeadbeef);
     hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", 0, FTP_TRANSFER_TYPE_ASCII, 0);
     ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
-    todo_wine
     ok ( GetLastError() == ERROR_INVALID_PARAMETER,
         "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
     InternetCloseHandle(hOpenFile); /* Just in case */
@@ -447,7 +444,6 @@ static void test_openfile(void)
     SetLastError(0xdeadbeef);
     hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ|GENERIC_WRITE, FTP_TRANSFER_TYPE_ASCII, 0);
     ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
-    todo_wine
     ok ( GetLastError() == ERROR_INVALID_PARAMETER,
         "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
     InternetCloseHandle(hOpenFile); /* Just in case */
@@ -455,28 +451,23 @@ static void test_openfile(void)
     /* Illegal condition flags */
     SetLastError(0xdeadbeef);
     hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ, 5, 0);
-    todo_wine
-    {
     ok ( !hOpenFile, "Expected FtpOpenFileA to fail\n");
     ok ( GetLastError() == ERROR_INVALID_PARAMETER,
         "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
-    }
     InternetCloseHandle(hOpenFile); /* Just in case */
 
     /* All OK */
     SetLastError(0xdeadbeef);
     hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
-    todo_wine
-    {
     ok ( hOpenFile != NULL, "Expected FtpOpenFileA to succeed\n");
     /* For some strange/unknown reason, win98 returns ERROR_FILE_NOT_FOUND */
     ok ( GetLastError() == ERROR_SUCCESS || GetLastError() == ERROR_FILE_NOT_FOUND,
         "Expected ERROR_SUCCESS or ERROR_FILE_NOT_FOUND (win98), got %d\n", GetLastError());
-    }
 
     if (hOpenFile)
     {
         BOOL bRet;
+        HINTERNET hOpenFile2;
 
         /* We have a handle so all ftp calls should fail (TODO: Put more ftp-calls in here) */
         SetLastError(0xdeadbeef);
@@ -485,6 +476,13 @@ static void test_openfile(void)
         ok ( GetLastError() == ERROR_FTP_TRANSFER_IN_PROGRESS,
             "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", GetLastError());
         DeleteFileA("should_be_non_existing_deadbeef"); /* Just in case */
+
+        SetLastError(0xdeadbeef);
+        hOpenFile2 = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
+        ok ( bRet == FALSE, "Expected FtpOpenFileA to fail\n");
+        ok ( GetLastError() == ERROR_FTP_TRANSFER_IN_PROGRESS,
+            "Expected ERROR_FTP_TRANSFER_IN_PROGRESS, got %d\n", GetLastError());
+        InternetCloseHandle(hOpenFile); /* Just in case */
     }
 
     InternetCloseHandle(hOpenFile);




More information about the wine-cvs mailing list