wininet: Handle finding ftp files in subdirectories and using wildcards.
Mike Ruprecht
cmaiku at gmail.com
Sat Sep 26 22:15:46 CDT 2009
---
dlls/wininet/ftp.c | 35 +++++++++++++++++++++++++++++++++--
dlls/wininet/tests/ftp.c | 4 ++--
2 files changed, 35 insertions(+), 4 deletions(-)
diff --git a/dlls/wininet/ftp.c b/dlls/wininet/ftp.c
index 8894add..f4312d6 100644
--- a/dlls/wininet/ftp.c
+++ b/dlls/wininet/ftp.c
@@ -811,6 +811,8 @@ static HINTERNET FTP_FtpFindFirstFileW(ftp_session_t *lpwfs,
INT nResCode;
appinfo_t *hIC = NULL;
HINTERNET hFindNext = NULL;
+ LPWSTR lpszSearchPath = NULL;
+ LPCWSTR lpszSearchFileName = NULL;
TRACE("\n");
@@ -826,7 +828,33 @@ static HINTERNET FTP_FtpFindFirstFileW(ftp_session_t *lpwfs,
if (!FTP_SendPortOrPasv(lpwfs))
goto lend;
- if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_LIST, NULL,
+ if (lpszSearchFile) {
+ static const WCHAR wildcards[] = {'*', '?', '\0'};
+
+ /* Strip the path from the search file */
+ LPCWSTR lpszSlash = strrchrW(lpszSearchFile, '/');
+ LPCWSTR lpszTmp = strrchrW(lpszSearchFile, '\\');
+
+ if (lpszSlash < lpszTmp)
+ lpszSlash = lpszTmp;
+
+ if (lpszSlash == NULL)
+ lpszSlash = lpszSearchFile;
+ else
+ ++lpszSlash;
+
+ /* Copy the path to request */
+ lpszSearchPath = heap_strdupW(lpszSearchFile);
+
+ if (strcspnW(lpszSlash, wildcards) < strlenW(lpszSlash))
+ {
+ /* Filename contains wildcards. Validate results */
+ lpszSearchPath[strlenW(lpszSlash) - strlenW(lpszSearchFile)] = 0;
+ lpszSearchFileName = lpszSearchFile;
+ }
+ }
+
+ if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_LIST, lpszSearchPath,
lpwfs->hdr.lpfnStatusCB, &lpwfs->hdr, lpwfs->hdr.dwContext))
goto lend;
@@ -840,7 +868,7 @@ static HINTERNET FTP_FtpFindFirstFileW(ftp_session_t *lpwfs,
/* Get data socket to server */
if (FTP_GetDataSocket(lpwfs, &nDataSocket))
{
- hFindNext = FTP_ReceiveFileList(lpwfs, nDataSocket, lpszSearchFile, lpFindFileData, dwContext);
+ hFindNext = FTP_ReceiveFileList(lpwfs, nDataSocket, lpszSearchFileName, lpFindFileData, dwContext);
closesocket(nDataSocket);
nResCode = FTP_ReceiveResponse(lpwfs, lpwfs->hdr.dwContext);
if (nResCode != 226 && nResCode != 250)
@@ -852,6 +880,9 @@ static HINTERNET FTP_FtpFindFirstFileW(ftp_session_t *lpwfs,
}
lend:
+ if (lpszSearchPath)
+ HeapFree(GetProcessHeap(), 0, lpszSearchPath);
+
if (lpwfs->lstnSocket != -1)
{
closesocket(lpwfs->lstnSocket);
diff --git a/dlls/wininet/tests/ftp.c b/dlls/wininet/tests/ftp.c
index b4de4e1..05a280a 100644
--- a/dlls/wininet/tests/ftp.c
+++ b/dlls/wininet/tests/ftp.c
@@ -747,13 +747,13 @@ static void test_find_first_file(HINTERNET hFtp, HINTERNET hConnect)
/* Try a valid filename in a subdirectory search */
SetLastError(0xdeadbeef);
hSearch = FtpFindFirstFileA(hFtp, "pub/wine", &findData, 0, 0);
- todo_wine ok ( hSearch != NULL, "Expected FtpFindFirstFileA to pass\n" );
+ ok ( hSearch != NULL, "Expected FtpFindFirstFileA to pass\n" );
InternetCloseHandle(hSearch);
/* Try a valid filename in a subdirectory wildcard search */
SetLastError(0xdeadbeef);
hSearch = FtpFindFirstFileA(hFtp, "pub/w*", &findData, 0, 0);
- todo_wine ok ( hSearch != NULL, "Expected FtpFindFirstFileA to pass\n" );
+ ok ( hSearch != NULL, "Expected FtpFindFirstFileA to pass\n" );
InternetCloseHandle(hSearch);
/* Try an invalid wildcard search */
--
1.6.0.4
More information about the wine-patches
mailing list