Jacek Caban : wininet: Added beginning support for HTTP cache files.

Alexandre Julliard julliard at winehq.org
Fri Feb 15 05:35:55 CST 2008


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Wed Feb 13 13:32:49 2008 +0100

wininet: Added beginning support for HTTP cache files.

---

 dlls/wininet/http.c     |   48 +++++++++++++++++++++++++++++++++++++++++++++++
 dlls/wininet/internet.c |    9 ++++++++
 dlls/wininet/internet.h |    2 +
 3 files changed, 59 insertions(+), 0 deletions(-)

diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c
index 964140e..d718eea 100644
--- a/dlls/wininet/http.c
+++ b/dlls/wininet/http.c
@@ -2283,6 +2283,20 @@ BOOL WINAPI HttpSendRequestA(HINTERNET hHttpRequest, LPCSTR lpszHeaders,
     return result;
 }
 
+static BOOL HTTP_GetRequestURL(WININETHTTPREQW *req, LPWSTR buf)
+{
+    LPHTTPHEADERW host_header;
+
+    static const WCHAR formatW[] = {'h','t','t','p',':','/','/','%','s','%','s',0};
+
+    host_header = HTTP_GetHeader(req, szHost);
+    if(!host_header)
+        return FALSE;
+
+    sprintfW(buf, formatW, host_header->lpszValue, req->lpszPath); /* FIXME */
+    return TRUE;
+}
+
 /***********************************************************************
  *           HTTP_HandleRedirect (internal)
  */
@@ -2743,6 +2757,32 @@ BOOL WINAPI HTTP_HttpSendRequestW(LPWININETHTTPREQW lpwhr, LPCWSTR lpszHeaders,
     }
     while (loop_next);
 
+    /* FIXME: Better check, when we have to create the cache file */
+    if(bSuccess && (lpwhr->hdr.dwFlags & INTERNET_FLAG_NEED_FILE)) {
+        WCHAR url[INTERNET_MAX_URL_LENGTH];
+        WCHAR cacheFileName[MAX_PATH+1];
+        BOOL b;
+
+        b = HTTP_GetRequestURL(lpwhr, url);
+        if(!b) {
+            WARN("Could not get URL\n");
+            goto lend;
+        }
+
+        b = CreateUrlCacheEntryW(url, lpwhr->dwContentLength > 0 ? lpwhr->dwContentLength : 0, NULL, cacheFileName, 0);
+        if(b) {
+            lpwhr->lpszCacheFile = WININET_strdupW(cacheFileName);
+            lpwhr->hCacheFile = CreateFileW(lpwhr->lpszCacheFile, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,
+                      NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+            if(lpwhr->hCacheFile == INVALID_HANDLE_VALUE) {
+                WARN("Could not create file: %u\n", GetLastError());
+                lpwhr->hCacheFile = NULL;
+            }
+        }else {
+            WARN("Could not create cache entry: %08x\n", GetLastError());
+        }
+    }
+
 lend:
 
     HeapFree(GetProcessHeap(), 0, requestString);
@@ -3393,6 +3433,14 @@ static void HTTP_CloseHTTPRequestHandle(LPWININETHANDLEHEADER hdr)
 
     TRACE("\n");
 
+    if(lpwhr->hCacheFile)
+        CloseHandle(lpwhr->hCacheFile);
+
+    if(lpwhr->lpszCacheFile) {
+        DeleteFileW(lpwhr->lpszCacheFile); /* FIXME */
+        HeapFree(GetProcessHeap(), 0, lpwhr->lpszCacheFile);
+    }
+
     WININET_Release(&lpwhr->lpHttpSession->hdr);
 
     HeapFree(GetProcessHeap(), 0, lpwhr->lpszPath);
diff --git a/dlls/wininet/internet.c b/dlls/wininet/internet.c
index 595a718..7f422da 100644
--- a/dlls/wininet/internet.c
+++ b/dlls/wininet/internet.c
@@ -1775,6 +1775,15 @@ BOOL INTERNET_ReadFile(LPWININETHANDLEHEADER lpwh, LPVOID lpBuffer,
             {
                 lpwhr->dwContentRead += bytes_read;
                 *pdwNumOfBytesRead = bytes_read;
+
+                if(lpwhr->lpszCacheFile) {
+                    BOOL res;
+
+                    res = WriteFile(lpwhr->hCacheFile, lpBuffer, bytes_read, NULL, NULL);
+                    if(!res)
+                        WARN("WriteFile failed: %u\n", GetLastError());
+                }
+
                 if (!bytes_read && (lpwhr->dwContentRead == lpwhr->dwContentLength))
                     retval = HTTP_FinishedReading(lpwhr);
                 else
diff --git a/dlls/wininet/internet.h b/dlls/wininet/internet.h
index 0f283e1..b80de88 100644
--- a/dlls/wininet/internet.h
+++ b/dlls/wininet/internet.h
@@ -209,6 +209,8 @@ typedef struct
     DWORD dwContentRead; /* bytes of the content read so far */
     HTTPHEADERW *pCustHeaders;
     DWORD nCustHeaders;
+    HANDLE hCacheFile;
+    LPWSTR lpszCacheFile;
     struct HttpAuthInfo *pAuthInfo;
     struct HttpAuthInfo *pProxyAuthInfo;
 } WININETHTTPREQW, *LPWININETHTTPREQW;




More information about the wine-cvs mailing list