[2/2] wininet: Handle finding files in subdirectories and using wildcards.

Mike Ruprecht cmaiku at gmail.com
Mon Dec 15 20:31:24 CST 2008


---
 dlls/wininet/ftp.c |   31 +++++++++++++++++++++++++++++--
 1 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/dlls/wininet/ftp.c b/dlls/wininet/ftp.c
index 7dcbeb3..eba128c 100644
--- a/dlls/wininet/ftp.c
+++ b/dlls/wininet/ftp.c
@@ -807,6 +807,8 @@ static HINTERNET FTP_FtpFindFirstFileW(LPWININETFTPSESSIONW lpwfs,
     INT nResCode;
     LPWININETAPPINFOW hIC = NULL;
     HINTERNET hFindNext = NULL;
+    LPWSTR lpszSearchPath = NULL;
+    LPCWSTR lpszSearchFileName = NULL;
 
     TRACE("\n");
 
@@ -822,7 +824,29 @@ static HINTERNET FTP_FtpFindFirstFileW(LPWININETFTPSESSIONW 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, '/');
+        lpszSearchFileName = strrchrW(lpszSearchFile, '\\');
+
+        if (lpszSearchFileName < lpszSlash)
+            lpszSearchFileName = lpszSlash;
+
+        if (lpszSearchFileName == NULL)
+            lpszSearchFileName = lpszSearchFile;
+        else
+            ++lpszSearchFileName;
+
+        /* Copy the path to request */
+        if (strcspnW(lpszSearchFileName, wildcards) < strlenW(lpszSearchFileName))
+            lpszSearchPath = WININET_strndupW(lpszSearchFile, lpszSearchFileName - lpszSearchFile);
+        else
+            lpszSearchPath = WININET_strdupW(lpszSearchFile);
+    }
+
+    if (!FTP_SendCommand(lpwfs->sndSocket, FTP_CMD_LIST, lpszSearchPath,
         lpwfs->hdr.lpfnStatusCB, &lpwfs->hdr, lpwfs->hdr.dwContext))
         goto lend;
 
@@ -836,7 +860,7 @@ static HINTERNET FTP_FtpFindFirstFileW(LPWININETFTPSESSIONW 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)
@@ -848,6 +872,9 @@ static HINTERNET FTP_FtpFindFirstFileW(LPWININETFTPSESSIONW lpwfs,
     }
 
 lend:
+    if (lpszSearchPath)
+        HeapFree(GetProcessHeap(), 0, lpszSearchPath);
+
     if (lpwfs->lstnSocket != -1)
         closesocket(lpwfs->lstnSocket);
 




More information about the wine-patches mailing list