wininet: Always close the data connection before receiving a server response.
This commit is contained in:
parent
e55531d694
commit
e8eaee4f6a
|
@ -1365,6 +1365,8 @@ BOOL WINAPI FTP_FtpGetFileW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszRemoteFile,
|
||||||
|
|
||||||
/* Receive data */
|
/* Receive data */
|
||||||
FTP_RetrieveFileData(lpwfs, nDataSocket, hFile);
|
FTP_RetrieveFileData(lpwfs, nDataSocket, hFile);
|
||||||
|
closesocket(nDataSocket);
|
||||||
|
|
||||||
nResCode = FTP_ReceiveResponse(lpwfs, dwContext);
|
nResCode = FTP_ReceiveResponse(lpwfs, dwContext);
|
||||||
if (nResCode)
|
if (nResCode)
|
||||||
{
|
{
|
||||||
|
@ -1373,7 +1375,6 @@ BOOL WINAPI FTP_FtpGetFileW(LPWININETFTPSESSIONW lpwfs, LPCWSTR lpszRemoteFile,
|
||||||
else
|
else
|
||||||
FTP_SetResponseError(nResCode);
|
FTP_SetResponseError(nResCode);
|
||||||
}
|
}
|
||||||
closesocket(nDataSocket);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3008,7 +3009,7 @@ static void FTP_CloseFindNextHandle(LPWININETHANDLEHEADER hdr)
|
||||||
* FTP_CloseFileTransferHandle (internal)
|
* FTP_CloseFileTransferHandle (internal)
|
||||||
*
|
*
|
||||||
* Closes the file transfer handle. This also 'cleans' the data queue of
|
* Closes the file transfer handle. This also 'cleans' the data queue of
|
||||||
* the 'transfer conplete' message (this is a bit of a hack though :-/ )
|
* the 'transfer complete' message (this is a bit of a hack though :-/ )
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
static void FTP_CloseFileTransferHandle(LPWININETHANDLEHEADER hdr)
|
static void FTP_CloseFileTransferHandle(LPWININETHANDLEHEADER hdr)
|
||||||
|
@ -3024,16 +3025,12 @@ static void FTP_CloseFileTransferHandle(LPWININETHANDLEHEADER hdr)
|
||||||
if (!lpwh->session_deleted)
|
if (!lpwh->session_deleted)
|
||||||
lpwfs->download_in_progress = NULL;
|
lpwfs->download_in_progress = NULL;
|
||||||
|
|
||||||
/* This just serves to flush the control socket of any spurrious lines written
|
|
||||||
to it (like '226 Transfer complete.').
|
|
||||||
|
|
||||||
Wonder what to do if the server sends us an error code though...
|
|
||||||
*/
|
|
||||||
nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
|
|
||||||
|
|
||||||
if (lpwh->nDataSocket != -1)
|
if (lpwh->nDataSocket != -1)
|
||||||
closesocket(lpwh->nDataSocket);
|
closesocket(lpwh->nDataSocket);
|
||||||
|
|
||||||
|
nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
|
||||||
|
if (nResCode > 0 && nResCode != 226) WARN("server reports failed transfer\n");
|
||||||
|
|
||||||
HeapFree(GetProcessHeap(), 0, lpwh);
|
HeapFree(GetProcessHeap(), 0, lpwh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -301,16 +301,12 @@ static void test_getfile(void)
|
||||||
|
|
||||||
/* Zero attributes */
|
/* Zero attributes */
|
||||||
SetLastError(0xdeadbeef);
|
SetLastError(0xdeadbeef);
|
||||||
bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, 0, FTP_TRANSFER_TYPE_UNKNOWN, 0);
|
bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_existing_non_deadbeef", FALSE, 0, FTP_TRANSFER_TYPE_UNKNOWN, 0);
|
||||||
ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
|
ok ( bRet == TRUE, "Expected FtpGetFileA to succeed\n");
|
||||||
todo_wine
|
ok (GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
|
||||||
{
|
ok (GetFileAttributesA("should_be_existing_non_deadbeef") != INVALID_FILE_ATTRIBUTES,
|
||||||
ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
|
"Local file should have been created\n");
|
||||||
"Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
|
DeleteFileA("should_be_existing_non_deadbeef");
|
||||||
ok (GetFileAttributesA("should_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES,
|
|
||||||
"Local file should not have been created\n");
|
|
||||||
}
|
|
||||||
DeleteFileA("should_be_non_existing_deadbeef");
|
|
||||||
|
|
||||||
/* Illegal condition flags */
|
/* Illegal condition flags */
|
||||||
SetLastError(0xdeadbeef);
|
SetLastError(0xdeadbeef);
|
||||||
|
@ -326,12 +322,14 @@ static void test_getfile(void)
|
||||||
SetLastError(0xdeadbeef);
|
SetLastError(0xdeadbeef);
|
||||||
bRet = FtpGetFileA(hFtp, "should_be_non_existing_deadbeef", "should_also_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
|
bRet = FtpGetFileA(hFtp, "should_be_non_existing_deadbeef", "should_also_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");
|
||||||
|
todo_wine
|
||||||
|
{
|
||||||
ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
|
ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
|
||||||
"Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
|
"Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
|
||||||
/* Currently Wine always creates the local file (even on failure) which is not correct, hence the test */
|
/* Currently Wine always creates the local file (even on failure) which is not correct, hence the test */
|
||||||
todo_wine
|
|
||||||
ok (GetFileAttributesA("should_also_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES,
|
ok (GetFileAttributesA("should_also_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES,
|
||||||
"Local file should not have been created\n");
|
"Local file should not have been created\n");
|
||||||
|
}
|
||||||
DeleteFileA("should_also_be_non_existing_deadbeef");
|
DeleteFileA("should_also_be_non_existing_deadbeef");
|
||||||
|
|
||||||
/* Same call as the previous but now the local file does exists. Windows just removes the file if the call fails
|
/* Same call as the previous but now the local file does exists. Windows just removes the file if the call fails
|
||||||
|
@ -346,32 +344,30 @@ static void test_getfile(void)
|
||||||
SetLastError(0xdeadbeef);
|
SetLastError(0xdeadbeef);
|
||||||
bRet = FtpGetFileA(hFtp, "should_be_non_existing_deadbeef", "should_also_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
|
bRet = FtpGetFileA(hFtp, "should_be_non_existing_deadbeef", "should_also_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");
|
||||||
|
todo_wine
|
||||||
|
{
|
||||||
ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
|
ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
|
||||||
"Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
|
"Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
|
||||||
/* Currently Wine always creates the local file (even on failure) which is not correct, hence the test */
|
/* Currently Wine always creates the local file (even on failure) which is not correct, hence the test */
|
||||||
todo_wine
|
|
||||||
ok (GetFileAttributesA("should_also_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES,
|
ok (GetFileAttributesA("should_also_be_non_existing_deadbeef") == INVALID_FILE_ATTRIBUTES,
|
||||||
"Local file should not have been created\n");
|
"Local file should not have been created\n");
|
||||||
|
}
|
||||||
DeleteFileA("should_also_be_non_existing_deadbeef");
|
DeleteFileA("should_also_be_non_existing_deadbeef");
|
||||||
|
|
||||||
/* This one should fail */
|
/* This one should succeed */
|
||||||
SetLastError(0xdeadbeef);
|
SetLastError(0xdeadbeef);
|
||||||
bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
|
bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_existing_non_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
|
||||||
ok ( bRet == FALSE, "Expected FtpGetFileA to fail\n");
|
ok ( bRet == TRUE, "Expected FtpGetFileA to fail\n");
|
||||||
ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR,
|
ok ( GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %d\n", GetLastError());
|
||||||
"Expected ERROR_INTERNET_EXTENDED_ERROR, got %d\n", GetLastError());
|
|
||||||
|
|
||||||
if (GetFileAttributesA("should_be_non_existing_deadbeef") != INVALID_FILE_ATTRIBUTES)
|
if (GetFileAttributesA("should_be_existing_non_deadbeef") != INVALID_FILE_ATTRIBUTES)
|
||||||
{
|
{
|
||||||
/* Should succeed as fFailIfExists is set to FALSE (meaning don't fail if local file exists) */
|
/* Should succeed as fFailIfExists is set to FALSE (meaning don't fail if local file exists) */
|
||||||
SetLastError(0xdeadbeef);
|
SetLastError(0xdeadbeef);
|
||||||
bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
|
bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
|
||||||
todo_wine
|
|
||||||
{
|
|
||||||
ok ( bRet == TRUE, "Expected FtpGetFileA to succeed\n");
|
ok ( bRet == TRUE, "Expected FtpGetFileA to succeed\n");
|
||||||
ok ( GetLastError() == ERROR_SUCCESS,
|
ok ( GetLastError() == ERROR_SUCCESS,
|
||||||
"Expected ERROR_SUCCESS, got %d\n", GetLastError());
|
"Expected ERROR_SUCCESS, got %d\n", GetLastError());
|
||||||
}
|
|
||||||
|
|
||||||
/* Should fail as fFailIfExists is set to TRUE */
|
/* Should fail as fFailIfExists is set to TRUE */
|
||||||
SetLastError(0xdeadbeef);
|
SetLastError(0xdeadbeef);
|
||||||
|
@ -387,7 +383,7 @@ static void test_getfile(void)
|
||||||
ok ( GetLastError() == ERROR_FILE_EXISTS,
|
ok ( GetLastError() == ERROR_FILE_EXISTS,
|
||||||
"Expected ERROR_FILE_EXISTS, got %d\n", GetLastError());
|
"Expected ERROR_FILE_EXISTS, got %d\n", GetLastError());
|
||||||
|
|
||||||
DeleteFileA("should_be_non_existing_deadbeef");
|
DeleteFileA("should_be_existing_non_deadbeef");
|
||||||
}
|
}
|
||||||
|
|
||||||
InternetCloseHandle(hFtp);
|
InternetCloseHandle(hFtp);
|
||||||
|
@ -478,13 +474,8 @@ static void test_openfile(void)
|
||||||
|
|
||||||
SetLastError(0xdeadbeef);
|
SetLastError(0xdeadbeef);
|
||||||
hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
|
hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
|
||||||
todo_wine
|
ok ( hOpenFile != NULL, "Expected FtpOpenFileA to succeed\n");
|
||||||
{
|
ok ( GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", GetLastError());
|
||||||
ok ( hOpenFile == NULL, "Expected FtpOpenFileA to fail\n");
|
|
||||||
/* For some strange/unknown reason, win98 returns ERROR_FILE_NOT_FOUND */
|
|
||||||
ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR || GetLastError() == ERROR_FILE_NOT_FOUND,
|
|
||||||
"Expected ERROR_INTERNET_EXTENDED_ERROR or ERROR_FILE_NOT_FOUND (win98), got %d\n", GetLastError());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hOpenFile)
|
if (hOpenFile)
|
||||||
{
|
{
|
||||||
|
@ -840,14 +831,14 @@ static void test_multiple(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* A correct call */
|
/* A correct call */
|
||||||
bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_non_existing_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
|
bRet = FtpGetFileA(hFtp, "welcome.msg", "should_be_existing_non_deadbeef", FALSE, FILE_ATTRIBUTE_NORMAL, FTP_TRANSFER_TYPE_UNKNOWN, 0);
|
||||||
DeleteFileA("should_be_non_existing_deadbeef");
|
ok(bRet, "Expected FtpGetFileA to succeed\n");
|
||||||
|
DeleteFileA("should_be_existing_non_deadbeef");
|
||||||
|
|
||||||
SetLastError(0xdeadbeef);
|
SetLastError(0xdeadbeef);
|
||||||
hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
|
hOpenFile = FtpOpenFileA(hFtp, "welcome.msg", GENERIC_READ, FTP_TRANSFER_TYPE_ASCII, 0);
|
||||||
ok ( hOpenFile == NULL, "Expected FtpOpenFileA to fail\n");
|
ok(hOpenFile != NULL, "Expected FtpOpenFileA to succeed\n");
|
||||||
ok ( GetLastError() == ERROR_INTERNET_EXTENDED_ERROR || GetLastError() == ERROR_FILE_NOT_FOUND,
|
ok(GetLastError() == ERROR_SUCCESS, "Expected ERROR_SUCCESS, got %u\n", GetLastError());
|
||||||
"Expected ERROR_INTERNET_EXTENDED_ERROR or ERROR_FILE_NOT_FOUND (win98), got %d\n", GetLastError());
|
|
||||||
|
|
||||||
InternetCloseHandle(hOpenFile);
|
InternetCloseHandle(hOpenFile);
|
||||||
InternetCloseHandle(hFtp);
|
InternetCloseHandle(hFtp);
|
||||||
|
|
Loading…
Reference in New Issue