Commit cb0a5c91 authored by Juan Lang's avatar Juan Lang Committed by Alexandre Julliard

wininet: Implement DeleteUrlCacheEntryA/W with a helper function.

parent 190acb9e
...@@ -2039,6 +2039,47 @@ BOOL WINAPI RetrieveUrlCacheEntryFileW( ...@@ -2039,6 +2039,47 @@ BOOL WINAPI RetrieveUrlCacheEntryFileW(
return TRUE; return TRUE;
} }
static BOOL DeleteUrlCacheEntryInternal(LPURLCACHE_HEADER pHeader,
struct _HASH_ENTRY *pHashEntry)
{
CACHEFILE_ENTRY * pEntry;
URL_CACHEFILE_ENTRY * pUrlEntry;
pEntry = (CACHEFILE_ENTRY *)((LPBYTE)pHeader + pHashEntry->dwOffsetEntry);
if (pEntry->dwSignature != URL_SIGNATURE)
{
FIXME("Trying to delete entry of unknown format %s\n",
debugstr_an((LPCSTR)&pEntry->dwSignature, sizeof(DWORD)));
SetLastError(ERROR_FILE_NOT_FOUND);
return FALSE;
}
pUrlEntry = (URL_CACHEFILE_ENTRY *)pEntry;
if (pUrlEntry->CacheDir < pHeader->DirectoryCount)
{
if (pHeader->directory_data[pUrlEntry->CacheDir].dwNumFiles)
pHeader->directory_data[pUrlEntry->CacheDir].dwNumFiles--;
}
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
{
if (pUrlEntry->size.QuadPart < pHeader->CacheUsage.QuadPart)
pHeader->CacheUsage.QuadPart -= pUrlEntry->size.QuadPart;
else
pHeader->CacheUsage.QuadPart = 0;
}
URLCache_DeleteEntry(pHeader, pEntry);
URLCache_DeleteEntryFromHash(pHashEntry);
return TRUE;
}
/*********************************************************************** /***********************************************************************
* UnlockUrlCacheEntryFileA (WININET.@) * UnlockUrlCacheEntryFileA (WININET.@)
* *
...@@ -3001,9 +3042,8 @@ BOOL WINAPI DeleteUrlCacheEntryA(LPCSTR lpszUrlName) ...@@ -3001,9 +3042,8 @@ BOOL WINAPI DeleteUrlCacheEntryA(LPCSTR lpszUrlName)
URLCACHECONTAINER * pContainer; URLCACHECONTAINER * pContainer;
LPURLCACHE_HEADER pHeader; LPURLCACHE_HEADER pHeader;
struct _HASH_ENTRY * pHashEntry; struct _HASH_ENTRY * pHashEntry;
CACHEFILE_ENTRY * pEntry;
const URL_CACHEFILE_ENTRY * pUrlEntry;
DWORD error; DWORD error;
BOOL ret;
TRACE("(%s)\n", debugstr_a(lpszUrlName)); TRACE("(%s)\n", debugstr_a(lpszUrlName));
...@@ -3032,43 +3072,11 @@ BOOL WINAPI DeleteUrlCacheEntryA(LPCSTR lpszUrlName) ...@@ -3032,43 +3072,11 @@ BOOL WINAPI DeleteUrlCacheEntryA(LPCSTR lpszUrlName)
return FALSE; return FALSE;
} }
pEntry = (CACHEFILE_ENTRY *)((LPBYTE)pHeader + pHashEntry->dwOffsetEntry); ret = DeleteUrlCacheEntryInternal(pHeader, pHashEntry);
if (pEntry->dwSignature != URL_SIGNATURE)
{
URLCacheContainer_UnlockIndex(pContainer, pHeader);
FIXME("Trying to delete entry of unknown format %s\n",
debugstr_an((LPCSTR)&pEntry->dwSignature, sizeof(DWORD)));
SetLastError(ERROR_FILE_NOT_FOUND);
return FALSE;
}
pUrlEntry = (const URL_CACHEFILE_ENTRY *)pEntry;
if (pUrlEntry->CacheDir < pHeader->DirectoryCount)
{
if (pHeader->directory_data[pUrlEntry->CacheDir].dwNumFiles)
pHeader->directory_data[pUrlEntry->CacheDir].dwNumFiles--;
}
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
{
if (pUrlEntry->size.QuadPart < pHeader->CacheUsage.QuadPart)
pHeader->CacheUsage.QuadPart -= pUrlEntry->size.QuadPart;
else
pHeader->CacheUsage.QuadPart = 0;
}
URLCache_DeleteEntry(pHeader, pEntry);
URLCache_DeleteEntryFromHash(pHashEntry);
URLCacheContainer_UnlockIndex(pContainer, pHeader); URLCacheContainer_UnlockIndex(pContainer, pHeader);
return TRUE; return ret;
} }
/*********************************************************************** /***********************************************************************
...@@ -3080,10 +3088,9 @@ BOOL WINAPI DeleteUrlCacheEntryW(LPCWSTR lpszUrlName) ...@@ -3080,10 +3088,9 @@ BOOL WINAPI DeleteUrlCacheEntryW(LPCWSTR lpszUrlName)
URLCACHECONTAINER * pContainer; URLCACHECONTAINER * pContainer;
LPURLCACHE_HEADER pHeader; LPURLCACHE_HEADER pHeader;
struct _HASH_ENTRY * pHashEntry; struct _HASH_ENTRY * pHashEntry;
CACHEFILE_ENTRY * pEntry;
const URL_CACHEFILE_ENTRY * pUrlEntry;
LPSTR urlA; LPSTR urlA;
DWORD error; DWORD error;
BOOL ret;
TRACE("(%s)\n", debugstr_w(lpszUrlName)); TRACE("(%s)\n", debugstr_w(lpszUrlName));
...@@ -3125,44 +3132,12 @@ BOOL WINAPI DeleteUrlCacheEntryW(LPCWSTR lpszUrlName) ...@@ -3125,44 +3132,12 @@ BOOL WINAPI DeleteUrlCacheEntryW(LPCWSTR lpszUrlName)
return FALSE; return FALSE;
} }
pEntry = (CACHEFILE_ENTRY *)((LPBYTE)pHeader + pHashEntry->dwOffsetEntry); ret = DeleteUrlCacheEntryInternal(pHeader, pHashEntry);
if (pEntry->dwSignature != URL_SIGNATURE)
{
URLCacheContainer_UnlockIndex(pContainer, pHeader);
FIXME("Trying to delete entry of unknown format %s\n",
debugstr_an((LPCSTR)&pEntry->dwSignature, sizeof(DWORD)));
SetLastError(ERROR_FILE_NOT_FOUND);
return FALSE;
}
pUrlEntry = (const URL_CACHEFILE_ENTRY *)pEntry;
if (pUrlEntry->CacheDir < pHeader->DirectoryCount)
{
if (pHeader->directory_data[pUrlEntry->CacheDir].dwNumFiles)
pHeader->directory_data[pUrlEntry->CacheDir].dwNumFiles--;
}
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
{
if (pUrlEntry->size.QuadPart < pHeader->CacheUsage.QuadPart)
pHeader->CacheUsage.QuadPart -= pUrlEntry->size.QuadPart;
else
pHeader->CacheUsage.QuadPart = 0;
}
URLCache_DeleteEntry(pHeader, pEntry);
URLCache_DeleteEntryFromHash(pHashEntry);
URLCacheContainer_UnlockIndex(pContainer, pHeader); URLCacheContainer_UnlockIndex(pContainer, pHeader);
HeapFree(GetProcessHeap(), 0, urlA); HeapFree(GetProcessHeap(), 0, urlA);
return TRUE; return ret;
} }
BOOL WINAPI DeleteUrlCacheContainerA(DWORD d1, DWORD d2) BOOL WINAPI DeleteUrlCacheContainerA(DWORD d1, DWORD d2)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment