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

Alexandre Julliard julliard at wine.codeweavers.com
Mon Feb 19 07:02:04 CST 2007


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

Author: Paul Vriens <paul.vriens.wine at gmail.com>
Date:   Fri Feb 16 17:48:39 2007 +0100

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

---

 dlls/wininet/ftp.c       |   46 ++++++++++++++++++++++++++++------------------
 dlls/wininet/tests/ftp.c |   33 ++++++++++++++++++++++++++-------
 2 files changed, 54 insertions(+), 25 deletions(-)

diff --git a/dlls/wininet/ftp.c b/dlls/wininet/ftp.c
index e8a31b4..6bc21ff 100644
--- a/dlls/wininet/ftp.c
+++ b/dlls/wininet/ftp.c
@@ -64,6 +64,11 @@ WINE_DEFAULT_DEBUG_CHANNEL(wininet);
 #define szCRLF 			"\r\n"
 #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 {
   /* FTP commands with arguments. */
   FTP_CMD_ACCT,
@@ -201,13 +206,31 @@ BOOL WINAPI FtpPutFileW(HINTERNET hConnect, LPCWSTR lpszLocalFile,
     LPWININETAPPINFOW hIC = NULL;
     BOOL r = FALSE;
 
+    if (!lpszLocalFile || !lpszNewRemoteFile)
+    {
+        INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+    }
+
     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);
         goto lend;
     }
 
+    if ((dwFlags & FTP_CONDITION_MASK) > FTP_TRANSFER_TYPE_BINARY)
+    {
+        INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
+        goto lend;
+    }
+
     hIC = lpwfs->lpAppInfo;
     if (hIC->hdr.dwFlags & INTERNET_FLAG_ASYNC)
     {
@@ -230,8 +253,7 @@ BOOL WINAPI FtpPutFileW(HINTERNET hConnect, LPCWSTR lpszLocalFile,
     }
 
 lend:
-    if( lpwfs )
-        WININET_Release( &lpwfs->hdr );
+    WININET_Release( &lpwfs->hdr );
 
     return r;
 }
@@ -256,24 +278,19 @@ BOOL WINAPI FTP_FtpPutFileW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszLocalFile,
 
     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 */
     INTERNET_SetLastError(0);
-    hIC = lpwfs->lpAppInfo;
 
     /* Open file to be uploaded */
     if (INVALID_HANDLE_VALUE ==
         (hFile = CreateFileW(lpszLocalFile, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0)))
     {
         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);
 
     if (FTP_SendStore(lpwfs, lpszNewRemoteFile, dwFlags))
@@ -296,7 +313,6 @@ BOOL WINAPI FTP_FtpPutFileW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszLocalFile,
         }
     }
 
-lend:
     if (lpwfs->lstnSocket != -1)
         closesocket(lpwfs->lstnSocket);
 
@@ -1193,8 +1209,6 @@ static void AsyncFtpGetFileProc(WORKREQUEST *workRequest)
     HeapFree(GetProcessHeap(), 0, req->lpszNewFile);
 }
 
-#define FTP_CONDITION_MASK      0x0007
-
 BOOL WINAPI FtpGetFileW(HINTERNET hInternet, LPCWSTR lpszRemoteFile, LPCWSTR lpszNewFile,
     BOOL fFailIfExists, DWORD dwLocalFlagsAttribute, DWORD dwInternetFlags,
     DWORD dwContext)
@@ -1222,10 +1236,6 @@ BOOL WINAPI FtpGetFileW(HINTERNET hInternet, LPCWSTR lpszRemoteFile, LPCWSTR lps
         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)
     {
         INTERNET_SetLastError(ERROR_INVALID_PARAMETER);
diff --git a/dlls/wininet/tests/ftp.c b/dlls/wininet/tests/ftp.c
index 43be942..840d91b 100644
--- a/dlls/wininet/tests/ftp.c
+++ b/dlls/wininet/tests/ftp.c
@@ -245,7 +245,7 @@ static void test_getfile(void)
      *   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);
     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");
@@ -519,11 +519,25 @@ static void test_putfile(void)
     HINTERNET hInternet, hFtp, hConnect;
     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);
-    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");
-    todo_wine
     ok ( GetLastError() == ERROR_INVALID_HANDLE,
         "Expected ERROR_INVALID_HANDLE, got %d\n", GetLastError());
 
@@ -556,7 +570,6 @@ static void test_putfile(void)
     SetLastError(0xdeadbeef);
     bRet = FtpPutFileA(hFtp, "non_existing_local", "non_existing_remote", 5, 0);
     ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
-    todo_wine
     ok ( GetLastError() == ERROR_INVALID_PARAMETER,
         "Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
 
@@ -564,7 +577,6 @@ static void test_putfile(void)
     SetLastError(0xdeadbeef);
     bRet = FtpPutFileA(hFtp, "non_existing_local", "non_existing_remote", FTP_TRANSFER_TYPE_UNKNOWN, 0);
     ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");
-    todo_wine
     ok ( GetLastError() == ERROR_FILE_NOT_FOUND,
         "Expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
 
@@ -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);
 
-    /* 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);
     bRet = FtpPutFileA(hConnect, "non_existing_local", "non_existing_remote", 5, 0);
     ok ( bRet == FALSE, "Expected FtpPutFileA to fail\n");




More information about the wine-cvs mailing list