Commit 5e6e26e1 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

cryptnet: Fixed cache functions usage in CRYPT_CacheURL function.

parent af8dc809
...@@ -731,21 +731,24 @@ static void CRYPT_CacheURL(LPCWSTR pszURL, const CRYPT_BLOB_ARRAY *pObject, ...@@ -731,21 +731,24 @@ static void CRYPT_CacheURL(LPCWSTR pszURL, const CRYPT_BLOB_ARRAY *pObject,
DWORD dwRetrievalFlags, FILETIME expires) DWORD dwRetrievalFlags, FILETIME expires)
{ {
WCHAR cacheFileName[MAX_PATH]; WCHAR cacheFileName[MAX_PATH];
DWORD size = 0; HANDLE hCacheFile;
BOOL ret, create = FALSE; DWORD size = 0, entryType;
FILETIME ft;
GetUrlCacheEntryInfoW(pszURL, NULL, &size); GetUrlCacheEntryInfoW(pszURL, NULL, &size);
if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{ {
INTERNET_CACHE_ENTRY_INFOW *info = CryptMemAlloc(size); INTERNET_CACHE_ENTRY_INFOW *info = CryptMemAlloc(size);
if (info) if (!info)
{ {
FILETIME ft; ERR("out of memory\n");
return;
}
ret = GetUrlCacheEntryInfoW(pszURL, info, &size); if (GetUrlCacheEntryInfoW(pszURL, info, &size))
if (ret) {
lstrcpyW(cacheFileName, info->lpszLocalFileName); lstrcpyW(cacheFileName, info->lpszLocalFileName);
/* Check if the existing cache entry is up to date. If it isn't, /* Check if the existing cache entry is up to date. If it isn't,
* remove the existing cache entry, and create a new one with the * remove the existing cache entry, and create a new one with the
* new value. * new value.
...@@ -753,51 +756,38 @@ static void CRYPT_CacheURL(LPCWSTR pszURL, const CRYPT_BLOB_ARRAY *pObject, ...@@ -753,51 +756,38 @@ static void CRYPT_CacheURL(LPCWSTR pszURL, const CRYPT_BLOB_ARRAY *pObject,
GetSystemTimeAsFileTime(&ft); GetSystemTimeAsFileTime(&ft);
if (CompareFileTime(&info->ExpireTime, &ft) < 0) if (CompareFileTime(&info->ExpireTime, &ft) < 0)
{ {
create = TRUE;
DeleteUrlCacheEntryW(pszURL); DeleteUrlCacheEntryW(pszURL);
CryptMemFree(info);
}
else
{
info->ExpireTime = expires;
SetUrlCacheEntryInfoW(pszURL, info, CACHE_ENTRY_EXPTIME_FC);
CryptMemFree(info);
return;
} }
CryptMemFree(info);
} }
else
ret = FALSE;
} }
else
{
ret = CreateUrlCacheEntryW(pszURL, pObject->rgBlob[0].cbData, NULL,
cacheFileName, 0);
create = TRUE;
}
if (ret)
{
DWORD entryType;
FILETIME ft = { 0 };
if (create) if (!CreateUrlCacheEntryW(pszURL, pObject->rgBlob[0].cbData, NULL, cacheFileName, 0))
{ return;
HANDLE hCacheFile = CreateFileW(cacheFileName, GENERIC_WRITE, 0,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hCacheFile != INVALID_HANDLE_VALUE) hCacheFile = CreateFileW(cacheFileName, GENERIC_WRITE, 0,
{ NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
DWORD bytesWritten; if(hCacheFile == INVALID_HANDLE_VALUE)
return;
WriteFile(hCacheFile, pObject->rgBlob[0].pbData, WriteFile(hCacheFile, pObject->rgBlob[0].pbData,
pObject->rgBlob[0].cbData, &bytesWritten, NULL); pObject->rgBlob[0].cbData, &size, NULL);
CloseHandle(hCacheFile); CloseHandle(hCacheFile);
}
else if (!(dwRetrievalFlags & CRYPT_STICKY_CACHE_RETRIEVAL))
ret = FALSE; entryType = NORMAL_CACHE_ENTRY;
} else
if (ret) entryType = STICKY_CACHE_ENTRY;
{ memset(&ft, 0, sizeof(ft));
if (!(dwRetrievalFlags & CRYPT_STICKY_CACHE_RETRIEVAL)) CommitUrlCacheEntryW(pszURL, cacheFileName, expires, ft, entryType,
entryType = NORMAL_CACHE_ENTRY; NULL, 0, NULL, NULL);
else
entryType = STICKY_CACHE_ENTRY;
CommitUrlCacheEntryW(pszURL, cacheFileName, expires, ft, entryType,
NULL, 0, NULL, NULL);
}
}
} }
static void CALLBACK CRYPT_InetStatusCallback(HINTERNET hInt, static void CALLBACK CRYPT_InetStatusCallback(HINTERNET hInt,
......
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