diff --git a/dlls/wininet/tests/urlcache.c b/dlls/wininet/tests/urlcache.c index 162d38557fb..92bd2f02f2d 100644 --- a/dlls/wininet/tests/urlcache.c +++ b/dlls/wininet/tests/urlcache.c @@ -512,20 +512,16 @@ static void test_urlcacheA(void) ret = CommitUrlCacheEntry(TEST_URL, NULL, filetime_zero, filetime_zero, STICKY_CACHE_ENTRY, (LPBYTE)ok_header, strlen(ok_header), "html", NULL); - todo_wine { ok(!ret, "expected failure\n"); ok(GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); - } SetLastError(0xdeadbeef); ret = CommitUrlCacheEntry(TEST_URL, NULL, filetime_zero, filetime_zero, NORMAL_CACHE_ENTRY|STICKY_CACHE_ENTRY, (LPBYTE)ok_header, strlen(ok_header), "html", NULL); - todo_wine { ok(!ret, "expected failure\n"); ok(GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError()); - } ret = CreateUrlCacheEntry(TEST_URL, 0, "html", filenameA, 0); ok(ret, "CreateUrlCacheEntry failed with error %d\n", GetLastError()); create_and_write_file(filenameA, &zero_byte, sizeof(zero_byte)); @@ -545,7 +541,6 @@ static void test_urlcacheA(void) ok(lpCacheEntryInfo->CacheEntryType & (NORMAL_CACHE_ENTRY|STICKY_CACHE_ENTRY), "expected cache entry type NORMAL_CACHE_ENTRY | STICKY_CACHE_ENTRY, got %d (0x%08x)\n", lpCacheEntryInfo->CacheEntryType, lpCacheEntryInfo->CacheEntryType); - todo_wine ok(lpCacheEntryInfo->dwExemptDelta == 86400, "expected dwExemptDelta 864000, got %d\n", lpCacheEntryInfo->dwExemptDelta); @@ -578,7 +573,6 @@ static void test_urlcacheA(void) ok(lpCacheEntryInfo->CacheEntryType & (NORMAL_CACHE_ENTRY|STICKY_CACHE_ENTRY), "expected cache entry type NORMAL_CACHE_ENTRY | STICKY_CACHE_ENTRY, got %d (0x%08x)\n", lpCacheEntryInfo->CacheEntryType, lpCacheEntryInfo->CacheEntryType); - todo_wine ok(lpCacheEntryInfo->dwExemptDelta == 86400, "expected dwExemptDelta 864000, got %d\n", lpCacheEntryInfo->dwExemptDelta); diff --git a/dlls/wininet/urlcache.c b/dlls/wininet/urlcache.c index 137ec3c0fad..05e16a88104 100644 --- a/dlls/wininet/urlcache.c +++ b/dlls/wininet/urlcache.c @@ -2473,6 +2473,11 @@ static BOOL CommitUrlCacheEntryInternal( debugstr_w(lpszFileExtension), debugstr_w(lpszOriginalUrl)); + if (CacheEntryType & STICKY_CACHE_ENTRY && !lpszLocalFileName) + { + SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } if (lpszOriginalUrl) WARN(": lpszOriginalUrl ignored\n"); @@ -2612,7 +2617,13 @@ static BOOL CommitUrlCacheEntryInternal( pUrlEntry->CacheDir = cDirectory; pUrlEntry->CacheEntryType = CacheEntryType; pUrlEntry->dwHeaderInfoSize = dwHeaderSize; - pUrlEntry->dwExemptDelta = 0; + if (CacheEntryType & STICKY_CACHE_ENTRY) + { + /* Sticky entries have a default exempt time of one day */ + pUrlEntry->dwExemptDelta = 86400; + } + else + pUrlEntry->dwExemptDelta = 0; pUrlEntry->dwHitRate = 0; pUrlEntry->dwOffsetFileExtension = dwOffsetFileExtension; pUrlEntry->dwOffsetHeaderInfo = dwOffsetHeader; @@ -2653,8 +2664,12 @@ static BOOL CommitUrlCacheEntryInternal( { if (pUrlEntry->CacheDir < pHeader->DirectoryCount) pHeader->directory_data[pUrlEntry->CacheDir].dwNumFiles++; - pHeader->CacheUsage.QuadPart += file_size.QuadPart; - if (pHeader->CacheUsage.QuadPart > pHeader->CacheLimit.QuadPart) + if (CacheEntryType & STICKY_CACHE_ENTRY) + pHeader->ExemptUsage.QuadPart += file_size.QuadPart; + else + pHeader->CacheUsage.QuadPart += file_size.QuadPart; + if (pHeader->CacheUsage.QuadPart + pHeader->ExemptUsage.QuadPart > + pHeader->CacheLimit.QuadPart) FIXME("file of size %s bytes fills cache\n", wine_dbgstr_longlong(file_size.QuadPart)); } @@ -3032,10 +3047,20 @@ BOOL WINAPI DeleteUrlCacheEntryA(LPCSTR lpszUrlName) if (pHeader->directory_data[pUrlEntry->CacheDir].dwNumFiles) pHeader->directory_data[pUrlEntry->CacheDir].dwNumFiles--; } - if (pUrlEntry->size.QuadPart < pHeader->CacheUsage.QuadPart) - pHeader->CacheUsage.QuadPart -= pUrlEntry->size.QuadPart; + if (pUrlEntry->CacheEntryType & STICKY_CACHE_ENTRY) + { + if (pUrlEntry->size.QuadPart < pHeader->ExemptUsage.QuadPart) + pHeader->ExemptUsage.QuadPart -= pUrlEntry->size.QuadPart; + else + pHeader->ExemptUsage.QuadPart = 0; + } else - pHeader->CacheUsage.QuadPart = 0; + { + if (pUrlEntry->size.QuadPart < pHeader->CacheUsage.QuadPart) + pHeader->CacheUsage.QuadPart -= pUrlEntry->size.QuadPart; + else + pHeader->CacheUsage.QuadPart = 0; + } URLCache_DeleteEntry(pHeader, pEntry); @@ -3115,10 +3140,20 @@ BOOL WINAPI DeleteUrlCacheEntryW(LPCWSTR lpszUrlName) if (pHeader->directory_data[pUrlEntry->CacheDir].dwNumFiles) pHeader->directory_data[pUrlEntry->CacheDir].dwNumFiles--; } - if (pUrlEntry->size.QuadPart < pHeader->CacheUsage.QuadPart) - pHeader->CacheUsage.QuadPart -= pUrlEntry->size.QuadPart; + if (pUrlEntry->CacheEntryType & STICKY_CACHE_ENTRY) + { + if (pUrlEntry->size.QuadPart < pHeader->ExemptUsage.QuadPart) + pHeader->ExemptUsage.QuadPart -= pUrlEntry->size.QuadPart; + else + pHeader->ExemptUsage.QuadPart = 0; + } else - pHeader->CacheUsage.QuadPart = 0; + { + if (pUrlEntry->size.QuadPart < pHeader->CacheUsage.QuadPart) + pHeader->CacheUsage.QuadPart -= pUrlEntry->size.QuadPart; + else + pHeader->CacheUsage.QuadPart = 0; + } URLCache_DeleteEntry(pHeader, pEntry);