sync wininet urlcache.c with wine 1.1.19 - fixes memory corruptions

svn path=/trunk/; revision=40520
This commit is contained in:
Christoph von Wittich 2009-04-15 09:17:12 +00:00
parent d748120ca1
commit 1ecfbaf361

View file

@ -2,7 +2,7 @@
* Wininet - Url Cache functions * Wininet - Url Cache functions
* *
* Copyright 2001,2002 CodeWeavers * Copyright 2001,2002 CodeWeavers
* Copyright 2003 Robert Shearman * Copyright 2003-2008 Robert Shearman
* *
* Eric Kohl * Eric Kohl
* Aric Stewart * Aric Stewart
@ -25,15 +25,23 @@
#include "config.h" #include "config.h"
#include "wine/port.h" #include "wine/port.h"
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
#if defined(__MINGW32__) || defined (_MSC_VER)
#include <ws2tcpip.h>
#endif
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/types.h>
#ifdef HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
#include <time.h> #include <time.h>
#define NONAMELESSUNION
#define NONAMELESSSTRUCT
#include "windef.h" #include "windef.h"
#include "winbase.h" #include "winbase.h"
#include "winuser.h" #include "winuser.h"
@ -178,7 +186,7 @@ typedef struct _URLCACHECONTAINER
/* List of all containers available */ /* List of all containers available */
static struct list UrlContainers = LIST_INIT(UrlContainers); static struct list UrlContainers = LIST_INIT(UrlContainers);
static HASH_CACHEFILE_ENTRY *URLCache_CreateHashTable(LPURLCACHE_HEADER pHeader, HASH_CACHEFILE_ENTRY *pPrevHash); static DWORD URLCache_CreateHashTable(LPURLCACHE_HEADER pHeader, HASH_CACHEFILE_ENTRY *pPrevHash, HASH_CACHEFILE_ENTRY **ppHash);
/*********************************************************************** /***********************************************************************
* URLCache_PathToObjectName (Internal) * URLCache_PathToObjectName (Internal)
@ -206,11 +214,11 @@ static void URLCache_PathToObjectName(LPWSTR lpszPath, WCHAR replace)
* Opens the index file and saves mapping handle in hCacheIndexMapping * Opens the index file and saves mapping handle in hCacheIndexMapping
* *
* RETURNS * RETURNS
* TRUE if succeeded * ERROR_SUCCESS if succeeded
* FALSE if failed * Any other Win32 error code if failed
* *
*/ */
static BOOL URLCacheContainer_OpenIndex(URLCACHECONTAINER * pContainer) static DWORD URLCacheContainer_OpenIndex(URLCACHECONTAINER * pContainer)
{ {
HANDLE hFile; HANDLE hFile;
WCHAR wszFilePath[MAX_PATH]; WCHAR wszFilePath[MAX_PATH];
@ -220,7 +228,7 @@ static BOOL URLCacheContainer_OpenIndex(URLCACHECONTAINER * pContainer)
static const WCHAR wszMappingFormat[] = {'%','s','%','s','_','%','l','u',0}; static const WCHAR wszMappingFormat[] = {'%','s','%','s','_','%','l','u',0};
if (pContainer->hMapping) if (pContainer->hMapping)
return TRUE; return ERROR_SUCCESS;
strcpyW(wszFilePath, pContainer->path); strcpyW(wszFilePath, pContainer->path);
strcatW(wszFilePath, wszIndex); strcatW(wszFilePath, wszIndex);
@ -235,7 +243,7 @@ static BOOL URLCacheContainer_OpenIndex(URLCACHECONTAINER * pContainer)
if (hFile == INVALID_HANDLE_VALUE) if (hFile == INVALID_HANDLE_VALUE)
{ {
TRACE("Could not open or create cache index file \"%s\"\n", debugstr_w(wszFilePath)); TRACE("Could not open or create cache index file \"%s\"\n", debugstr_w(wszFilePath));
return FALSE; return GetLastError();
} }
/* At this stage we need the mutex because we may be about to create the /* At this stage we need the mutex because we may be about to create the
@ -247,7 +255,7 @@ static BOOL URLCacheContainer_OpenIndex(URLCACHECONTAINER * pContainer)
if (dwFileSize == INVALID_FILE_SIZE) if (dwFileSize == INVALID_FILE_SIZE)
{ {
ReleaseMutex(pContainer->hMutex); ReleaseMutex(pContainer->hMutex);
return FALSE; return GetLastError();
} }
if (dwFileSize == 0) if (dwFileSize == 0)
@ -256,7 +264,7 @@ static BOOL URLCacheContainer_OpenIndex(URLCACHECONTAINER * pContainer)
HKEY key; HKEY key;
char achZeroes[0x1000]; char achZeroes[0x1000];
DWORD dwOffset; DWORD dwOffset;
DWORD dwError = 0; DWORD dwError = ERROR_SUCCESS;
/* Write zeroes to the entire file so we can safely map it without /* Write zeroes to the entire file so we can safely map it without
* fear of getting a SEGV because the disk is full. * fear of getting a SEGV because the disk is full.
@ -282,7 +290,7 @@ static BOOL URLCacheContainer_OpenIndex(URLCACHECONTAINER * pContainer)
} }
} }
if (!dwError) if (dwError == ERROR_SUCCESS)
{ {
HANDLE hMapping = CreateFileMappingW(hFile, NULL, PAGE_READWRITE, 0, NEWFILE_SIZE, NULL); HANDLE hMapping = CreateFileMappingW(hFile, NULL, PAGE_READWRITE, 0, NEWFILE_SIZE, NULL);
@ -296,6 +304,7 @@ static BOOL URLCacheContainer_OpenIndex(URLCACHECONTAINER * pContainer)
WCHAR wszDirPath[MAX_PATH]; WCHAR wszDirPath[MAX_PATH];
FILETIME ft; FILETIME ft;
int i, j; int i, j;
HASH_CACHEFILE_ENTRY *pHashEntry;
dwFileSize = NEWFILE_SIZE; dwFileSize = NEWFILE_SIZE;
@ -326,7 +335,7 @@ static BOOL URLCacheContainer_OpenIndex(URLCACHECONTAINER * pContainer)
RegCloseKey(key); RegCloseKey(key);
} }
URLCache_CreateHashTable(pHeader, NULL); URLCache_CreateHashTable(pHeader, NULL, &pHashEntry);
/* Last step - create the directories */ /* Last step - create the directories */
@ -416,8 +425,7 @@ static BOOL URLCacheContainer_OpenIndex(URLCACHECONTAINER * pContainer)
CloseHandle(hFile); CloseHandle(hFile);
DeleteFileW(wszFilePath); DeleteFileW(wszFilePath);
ReleaseMutex(pContainer->hMutex); ReleaseMutex(pContainer->hMutex);
SetLastError(dwError); return dwError;
return FALSE;
} }
} }
@ -433,10 +441,10 @@ static BOOL URLCacheContainer_OpenIndex(URLCACHECONTAINER * pContainer)
if (!pContainer->hMapping) if (!pContainer->hMapping)
{ {
ERR("Couldn't create file mapping (error is %d)\n", GetLastError()); ERR("Couldn't create file mapping (error is %d)\n", GetLastError());
return FALSE; return GetLastError();
} }
return TRUE; return ERROR_SUCCESS;
} }
/*********************************************************************** /***********************************************************************
@ -579,7 +587,7 @@ void URLCacheContainers_DeleteAll(void)
); );
} }
static BOOL URLCacheContainers_FindContainerW(LPCWSTR lpwszUrl, URLCACHECONTAINER ** ppContainer) static DWORD URLCacheContainers_FindContainerW(LPCWSTR lpwszUrl, URLCACHECONTAINER ** ppContainer)
{ {
URLCACHECONTAINER * pContainer; URLCACHECONTAINER * pContainer;
@ -590,19 +598,18 @@ static BOOL URLCacheContainers_FindContainerW(LPCWSTR lpwszUrl, URLCACHECONTAINE
int prefix_len = strlenW(pContainer->cache_prefix); int prefix_len = strlenW(pContainer->cache_prefix);
if (!strncmpW(pContainer->cache_prefix, lpwszUrl, prefix_len)) if (!strncmpW(pContainer->cache_prefix, lpwszUrl, prefix_len))
{ {
TRACE("found container with prefx %s for URL %s\n", debugstr_w(pContainer->cache_prefix), debugstr_w(lpwszUrl)); TRACE("found container with prefix %s for URL %s\n", debugstr_w(pContainer->cache_prefix), debugstr_w(lpwszUrl));
*ppContainer = pContainer; *ppContainer = pContainer;
return TRUE; return ERROR_SUCCESS;
} }
} }
ERR("no container found\n"); ERR("no container found\n");
SetLastError(ERROR_FILE_NOT_FOUND); return ERROR_FILE_NOT_FOUND;
return FALSE;
} }
static BOOL URLCacheContainers_FindContainerA(LPCSTR lpszUrl, URLCACHECONTAINER ** ppContainer) static DWORD URLCacheContainers_FindContainerA(LPCSTR lpszUrl, URLCACHECONTAINER ** ppContainer)
{ {
BOOL ret; DWORD ret;
LPWSTR lpwszUrl; LPWSTR lpwszUrl;
int url_len = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0); int url_len = MultiByteToWideChar(CP_ACP, 0, lpszUrl, -1, NULL, 0);
if (url_len && (lpwszUrl = HeapAlloc(GetProcessHeap(), 0, url_len * sizeof(WCHAR)))) if (url_len && (lpwszUrl = HeapAlloc(GetProcessHeap(), 0, url_len * sizeof(WCHAR))))
@ -612,7 +619,7 @@ static BOOL URLCacheContainers_FindContainerA(LPCSTR lpszUrl, URLCACHECONTAINER
HeapFree(GetProcessHeap(), 0, lpwszUrl); HeapFree(GetProcessHeap(), 0, lpwszUrl);
return ret; return ret;
} }
return FALSE; return GetLastError();
} }
static BOOL URLCacheContainers_Enum(LPCWSTR lpwszSearchPattern, DWORD dwIndex, URLCACHECONTAINER ** ppContainer) static BOOL URLCacheContainers_Enum(LPCWSTR lpwszSearchPattern, DWORD dwIndex, URLCACHECONTAINER ** ppContainer)
@ -654,12 +661,18 @@ static BOOL URLCacheContainers_Enum(LPCWSTR lpwszSearchPattern, DWORD dwIndex, U
/*********************************************************************** /***********************************************************************
* URLCacheContainer_LockIndex (Internal) * URLCacheContainer_LockIndex (Internal)
* *
* Locks the index for system-wide exclusive access.
*
* RETURNS
* Cache file header if successful
* NULL if failed and calls SetLastError.
*/ */
static LPURLCACHE_HEADER URLCacheContainer_LockIndex(URLCACHECONTAINER * pContainer) static LPURLCACHE_HEADER URLCacheContainer_LockIndex(URLCACHECONTAINER * pContainer)
{ {
BYTE index; BYTE index;
LPVOID pIndexData; LPVOID pIndexData;
URLCACHE_HEADER * pHeader; URLCACHE_HEADER * pHeader;
DWORD error;
/* acquire mutex */ /* acquire mutex */
WaitForSingleObject(pContainer->hMutex, INFINITE); WaitForSingleObject(pContainer->hMutex, INFINITE);
@ -670,7 +683,7 @@ static LPURLCACHE_HEADER URLCacheContainer_LockIndex(URLCACHECONTAINER * pContai
{ {
ReleaseMutex(pContainer->hMutex); ReleaseMutex(pContainer->hMutex);
ERR("Couldn't MapViewOfFile. Error: %d\n", GetLastError()); ERR("Couldn't MapViewOfFile. Error: %d\n", GetLastError());
return FALSE; return NULL;
} }
pHeader = (URLCACHE_HEADER *)pIndexData; pHeader = (URLCACHE_HEADER *)pIndexData;
@ -680,10 +693,12 @@ static LPURLCACHE_HEADER URLCacheContainer_LockIndex(URLCACHECONTAINER * pContai
if (pHeader->dwFileSize != pContainer->file_size) if (pHeader->dwFileSize != pContainer->file_size)
{ {
URLCacheContainer_CloseIndex(pContainer); URLCacheContainer_CloseIndex(pContainer);
if (!URLCacheContainer_OpenIndex(pContainer)) error = URLCacheContainer_OpenIndex(pContainer);
if (error != ERROR_SUCCESS)
{ {
ReleaseMutex(pContainer->hMutex); ReleaseMutex(pContainer->hMutex);
return FALSE; SetLastError(error);
return NULL;
} }
pIndexData = MapViewOfFile(pContainer->hMapping, FILE_MAP_WRITE, 0, 0, 0); pIndexData = MapViewOfFile(pContainer->hMapping, FILE_MAP_WRITE, 0, 0, 0);
@ -691,7 +706,7 @@ static LPURLCACHE_HEADER URLCacheContainer_LockIndex(URLCACHECONTAINER * pContai
{ {
ReleaseMutex(pContainer->hMutex); ReleaseMutex(pContainer->hMutex);
ERR("Couldn't MapViewOfFile. Error: %d\n", GetLastError()); ERR("Couldn't MapViewOfFile. Error: %d\n", GetLastError());
return FALSE; return NULL;
} }
pHeader = (URLCACHE_HEADER *)pIndexData; pHeader = (URLCACHE_HEADER *)pIndexData;
} }
@ -931,11 +946,11 @@ static BOOL URLCache_LocalFileNameToPathA(
* Copies an entry from the cache index file to the Win32 structure * Copies an entry from the cache index file to the Win32 structure
* *
* RETURNS * RETURNS
* TRUE if the buffer was big enough * ERROR_SUCCESS if the buffer was big enough
* FALSE if the buffer was too small * ERROR_INSUFFICIENT_BUFFER if the buffer was too small
* *
*/ */
static BOOL URLCache_CopyEntry( static DWORD URLCache_CopyEntry(
URLCACHECONTAINER * pContainer, URLCACHECONTAINER * pContainer,
LPCURLCACHE_HEADER pHeader, LPCURLCACHE_HEADER pHeader,
LPINTERNET_CACHE_ENTRY_INFOA lpCacheEntryInfo, LPINTERNET_CACHE_ENTRY_INFOA lpCacheEntryInfo,
@ -1000,7 +1015,7 @@ static BOOL URLCache_CopyEntry(
lpszLocalFileName = (LPSTR)lpCacheEntryInfo + dwRequiredSize; lpszLocalFileName = (LPSTR)lpCacheEntryInfo + dwRequiredSize;
nLocalFilePathSize = *lpdwBufferSize - dwRequiredSize; nLocalFilePathSize = *lpdwBufferSize - dwRequiredSize;
if ((bUnicode && URLCache_LocalFileNameToPathW(pContainer, pHeader, (LPCSTR)pUrlEntry + pUrlEntry->dwOffsetLocalName, pUrlEntry->CacheDir, (LPWSTR)lpszLocalFileName, &nLocalFilePathSize)) || if ((bUnicode && URLCache_LocalFileNameToPathW(pContainer, pHeader, (LPCSTR)pUrlEntry + pUrlEntry->dwOffsetLocalName, pUrlEntry->CacheDir, (LPWSTR)lpszLocalFileName, &nLocalFilePathSize)) ||
URLCache_LocalFileNameToPathA(pContainer, pHeader, (LPCSTR)pUrlEntry + pUrlEntry->dwOffsetLocalName, pUrlEntry->CacheDir, lpszLocalFileName, &nLocalFilePathSize)) (!bUnicode && URLCache_LocalFileNameToPathA(pContainer, pHeader, (LPCSTR)pUrlEntry + pUrlEntry->dwOffsetLocalName, pUrlEntry->CacheDir, lpszLocalFileName, &nLocalFilePathSize)))
{ {
lpCacheEntryInfo->lpszLocalFileName = lpszLocalFileName; lpCacheEntryInfo->lpszLocalFileName = lpszLocalFileName;
} }
@ -1049,11 +1064,10 @@ static BOOL URLCache_CopyEntry(
if (dwRequiredSize > *lpdwBufferSize) if (dwRequiredSize > *lpdwBufferSize)
{ {
*lpdwBufferSize = dwRequiredSize; *lpdwBufferSize = dwRequiredSize;
SetLastError(ERROR_INSUFFICIENT_BUFFER); return ERROR_INSUFFICIENT_BUFFER;
return FALSE;
} }
*lpdwBufferSize = dwRequiredSize; *lpdwBufferSize = dwRequiredSize;
return TRUE; return ERROR_SUCCESS;
} }
@ -1064,11 +1078,11 @@ static BOOL URLCache_CopyEntry(
* according to the flags set by dwFieldControl. * according to the flags set by dwFieldControl.
* *
* RETURNS * RETURNS
* TRUE if the buffer was big enough * ERROR_SUCCESS if the buffer was big enough
* FALSE if the buffer was too small * ERROR_INSUFFICIENT_BUFFER if the buffer was too small
* *
*/ */
static BOOL URLCache_SetEntryInfo(URL_CACHEFILE_ENTRY * pUrlEntry, const INTERNET_CACHE_ENTRY_INFOW * lpCacheEntryInfo, DWORD dwFieldControl) static DWORD URLCache_SetEntryInfo(URL_CACHEFILE_ENTRY * pUrlEntry, const INTERNET_CACHE_ENTRY_INFOW * lpCacheEntryInfo, DWORD dwFieldControl)
{ {
if (dwFieldControl & CACHE_ENTRY_ACCTIME_FC) if (dwFieldControl & CACHE_ENTRY_ACCTIME_FC)
pUrlEntry->LastAccessTime = lpCacheEntryInfo->LastAccessTime; pUrlEntry->LastAccessTime = lpCacheEntryInfo->LastAccessTime;
@ -1087,7 +1101,7 @@ static BOOL URLCache_SetEntryInfo(URL_CACHEFILE_ENTRY * pUrlEntry, const INTERNE
if (dwFieldControl & CACHE_ENTRY_SYNCTIME_FC) if (dwFieldControl & CACHE_ENTRY_SYNCTIME_FC)
FileTimeToDosDateTime(&lpCacheEntryInfo->LastAccessTime, &pUrlEntry->wLastSyncDate, &pUrlEntry->wLastSyncTime); FileTimeToDosDateTime(&lpCacheEntryInfo->LastAccessTime, &pUrlEntry->wLastSyncDate, &pUrlEntry->wLastSyncTime);
return TRUE; return ERROR_SUCCESS;
} }
/*********************************************************************** /***********************************************************************
@ -1285,11 +1299,11 @@ static BOOL URLCache_DeleteEntryFromHash(struct _HASH_ENTRY * pHashEntry)
* key are entered into the hash table. * key are entered into the hash table.
* *
* RETURNS * RETURNS
* TRUE if the entry was added * ERROR_SUCCESS if the entry was added
* FALSE if the entry could not be added * Any other Win32 error code if the entry could not be added
* *
*/ */
static BOOL URLCache_AddEntryToHash(LPURLCACHE_HEADER pHeader, LPCSTR lpszUrl, DWORD dwOffsetEntry) static DWORD URLCache_AddEntryToHash(LPURLCACHE_HEADER pHeader, LPCSTR lpszUrl, DWORD dwOffsetEntry)
{ {
/* see URLCache_FindEntryInHash for structure of hash tables */ /* see URLCache_FindEntryInHash for structure of hash tables */
@ -1297,6 +1311,7 @@ static BOOL URLCache_AddEntryToHash(LPURLCACHE_HEADER pHeader, LPCSTR lpszUrl, D
DWORD offset = (key % HASHTABLE_NUM_ENTRIES) * sizeof(struct _HASH_ENTRY); DWORD offset = (key % HASHTABLE_NUM_ENTRIES) * sizeof(struct _HASH_ENTRY);
HASH_CACHEFILE_ENTRY * pHashEntry; HASH_CACHEFILE_ENTRY * pHashEntry;
DWORD dwHashTableNumber = 0; DWORD dwHashTableNumber = 0;
DWORD error;
key = (key / HASHTABLE_NUM_ENTRIES) * HASHTABLE_NUM_ENTRIES; key = (key / HASHTABLE_NUM_ENTRIES) * HASHTABLE_NUM_ENTRIES;
@ -1324,17 +1339,17 @@ static BOOL URLCache_AddEntryToHash(LPURLCACHE_HEADER pHeader, LPCSTR lpszUrl, D
{ {
pHashElement->dwHashKey = key; pHashElement->dwHashKey = key;
pHashElement->dwOffsetEntry = dwOffsetEntry; pHashElement->dwOffsetEntry = dwOffsetEntry;
return TRUE; return ERROR_SUCCESS;
} }
} }
} }
pHashEntry = URLCache_CreateHashTable(pHeader, pHashEntry); error = URLCache_CreateHashTable(pHeader, pHashEntry, &pHashEntry);
if (!pHashEntry) if (error != ERROR_SUCCESS)
return FALSE; return error;
pHashEntry->HashTable[offset].dwHashKey = key; pHashEntry->HashTable[offset].dwHashKey = key;
pHashEntry->HashTable[offset].dwOffsetEntry = dwOffsetEntry; pHashEntry->HashTable[offset].dwOffsetEntry = dwOffsetEntry;
return TRUE; return ERROR_SUCCESS;
} }
/*********************************************************************** /***********************************************************************
@ -1344,38 +1359,36 @@ static BOOL URLCache_AddEntryToHash(LPURLCACHE_HEADER pHeader, LPCSTR lpszUrl, D
* hash tables. * hash tables.
* *
* RETURNS * RETURNS
* TRUE if the hash table was created * ERROR_SUCCESS if the hash table was created
* FALSE if the hash table could not be created * ERROR_DISK_FULL if the hash table could not be created
* *
*/ */
static HASH_CACHEFILE_ENTRY *URLCache_CreateHashTable(LPURLCACHE_HEADER pHeader, HASH_CACHEFILE_ENTRY *pPrevHash) static DWORD URLCache_CreateHashTable(LPURLCACHE_HEADER pHeader, HASH_CACHEFILE_ENTRY *pPrevHash, HASH_CACHEFILE_ENTRY **ppHash)
{ {
HASH_CACHEFILE_ENTRY *pHash;
DWORD dwOffset; DWORD dwOffset;
int i; int i;
if (!URLCache_FindFirstFreeEntry(pHeader, 0x20, (CACHEFILE_ENTRY **)&pHash)) if (!URLCache_FindFirstFreeEntry(pHeader, 0x20, (CACHEFILE_ENTRY **)ppHash))
{ {
FIXME("no free space for hash table\n"); FIXME("no free space for hash table\n");
SetLastError(ERROR_DISK_FULL); return ERROR_DISK_FULL;
return NULL;
} }
dwOffset = (BYTE *)pHash - (BYTE *)pHeader; dwOffset = (BYTE *)*ppHash - (BYTE *)pHeader;
if (pPrevHash) if (pPrevHash)
pPrevHash->dwAddressNext = dwOffset; pPrevHash->dwAddressNext = dwOffset;
else else
pHeader->dwOffsetFirstHashTable = dwOffset; pHeader->dwOffsetFirstHashTable = dwOffset;
pHash->CacheFileEntry.dwSignature = HASH_SIGNATURE; (*ppHash)->CacheFileEntry.dwSignature = HASH_SIGNATURE;
pHash->CacheFileEntry.dwBlocksUsed = 0x20; (*ppHash)->CacheFileEntry.dwBlocksUsed = 0x20;
pHash->dwHashTableNumber = pPrevHash ? pPrevHash->dwHashTableNumber + 1 : 0; (*ppHash)->dwHashTableNumber = pPrevHash ? pPrevHash->dwHashTableNumber + 1 : 0;
for (i = 0; i < HASHTABLE_SIZE; i++) for (i = 0; i < HASHTABLE_SIZE; i++)
{ {
pHash->HashTable[i].dwOffsetEntry = 0; (*ppHash)->HashTable[i].dwOffsetEntry = 0;
pHash->HashTable[i].dwHashKey = HASHTABLE_FREE; (*ppHash)->HashTable[i].dwHashKey = HASHTABLE_FREE;
} }
return pHash; return ERROR_SUCCESS;
} }
/*********************************************************************** /***********************************************************************
@ -1488,14 +1501,23 @@ BOOL WINAPI GetUrlCacheEntryInfoA(
const CACHEFILE_ENTRY * pEntry; const CACHEFILE_ENTRY * pEntry;
const URL_CACHEFILE_ENTRY * pUrlEntry; const URL_CACHEFILE_ENTRY * pUrlEntry;
URLCACHECONTAINER * pContainer; URLCACHECONTAINER * pContainer;
DWORD error;
TRACE("(%s, %p, %p)\n", debugstr_a(lpszUrlName), lpCacheEntryInfo, lpdwCacheEntryInfoBufferSize); TRACE("(%s, %p, %p)\n", debugstr_a(lpszUrlName), lpCacheEntryInfo, lpdwCacheEntryInfoBufferSize);
if (!URLCacheContainers_FindContainerA(lpszUrlName, &pContainer)) error = URLCacheContainers_FindContainerA(lpszUrlName, &pContainer);
if (error != ERROR_SUCCESS)
{
SetLastError(error);
return FALSE; return FALSE;
}
if (!URLCacheContainer_OpenIndex(pContainer)) error = URLCacheContainer_OpenIndex(pContainer);
if (error != ERROR_SUCCESS)
{
SetLastError(error);
return FALSE; return FALSE;
}
if (!(pHeader = URLCacheContainer_LockIndex(pContainer))) if (!(pHeader = URLCacheContainer_LockIndex(pContainer)))
return FALSE; return FALSE;
@ -1524,18 +1546,23 @@ BOOL WINAPI GetUrlCacheEntryInfoA(
if (lpdwCacheEntryInfoBufferSize) if (lpdwCacheEntryInfoBufferSize)
{ {
if (!URLCache_CopyEntry( if (!lpCacheEntryInfo)
*lpdwCacheEntryInfoBufferSize = 0;
error = URLCache_CopyEntry(
pContainer, pContainer,
pHeader, pHeader,
lpCacheEntryInfo, lpCacheEntryInfo,
lpdwCacheEntryInfoBufferSize, lpdwCacheEntryInfoBufferSize,
pUrlEntry, pUrlEntry,
FALSE /* ANSI */)) FALSE /* ANSI */);
if (error != ERROR_SUCCESS)
{ {
URLCacheContainer_UnlockIndex(pContainer, pHeader); URLCacheContainer_UnlockIndex(pContainer, pHeader);
SetLastError(error);
return FALSE; return FALSE;
} }
TRACE("Local File Name: %s\n", debugstr_a(lpCacheEntryInfo->lpszLocalFileName)); TRACE("Local File Name: %s\n", debugstr_a((LPCSTR)pUrlEntry + pUrlEntry->dwOffsetLocalName));
} }
URLCacheContainer_UnlockIndex(pContainer, pHeader); URLCacheContainer_UnlockIndex(pContainer, pHeader);
@ -1556,14 +1583,23 @@ BOOL WINAPI GetUrlCacheEntryInfoW(LPCWSTR lpszUrl,
const CACHEFILE_ENTRY * pEntry; const CACHEFILE_ENTRY * pEntry;
const URL_CACHEFILE_ENTRY * pUrlEntry; const URL_CACHEFILE_ENTRY * pUrlEntry;
URLCACHECONTAINER * pContainer; URLCACHECONTAINER * pContainer;
DWORD error;
TRACE("(%s, %p, %p)\n", debugstr_w(lpszUrl), lpCacheEntryInfo, lpdwCacheEntryInfoBufferSize); TRACE("(%s, %p, %p)\n", debugstr_w(lpszUrl), lpCacheEntryInfo, lpdwCacheEntryInfoBufferSize);
if (!URLCacheContainers_FindContainerW(lpszUrl, &pContainer)) error = URLCacheContainers_FindContainerW(lpszUrl, &pContainer);
if (error != ERROR_SUCCESS)
{
SetLastError(error);
return FALSE; return FALSE;
}
if (!URLCacheContainer_OpenIndex(pContainer)) error = URLCacheContainer_OpenIndex(pContainer);
if (error != ERROR_SUCCESS)
{
SetLastError(error);
return FALSE; return FALSE;
}
if (!(pHeader = URLCacheContainer_LockIndex(pContainer))) if (!(pHeader = URLCacheContainer_LockIndex(pContainer)))
return FALSE; return FALSE;
@ -1591,18 +1627,23 @@ BOOL WINAPI GetUrlCacheEntryInfoW(LPCWSTR lpszUrl,
if (lpdwCacheEntryInfoBufferSize) if (lpdwCacheEntryInfoBufferSize)
{ {
if (!URLCache_CopyEntry( if (!lpCacheEntryInfo)
*lpdwCacheEntryInfoBufferSize = 0;
error = URLCache_CopyEntry(
pContainer, pContainer,
pHeader, pHeader,
(LPINTERNET_CACHE_ENTRY_INFOA)lpCacheEntryInfo, (LPINTERNET_CACHE_ENTRY_INFOA)lpCacheEntryInfo,
lpdwCacheEntryInfoBufferSize, lpdwCacheEntryInfoBufferSize,
pUrlEntry, pUrlEntry,
TRUE /* UNICODE */)) TRUE /* UNICODE */);
if (error != ERROR_SUCCESS)
{ {
URLCacheContainer_UnlockIndex(pContainer, pHeader); URLCacheContainer_UnlockIndex(pContainer, pHeader);
SetLastError(error);
return FALSE; return FALSE;
} }
TRACE("Local File Name: %s\n", debugstr_w(lpCacheEntryInfo->lpszLocalFileName)); TRACE("Local File Name: %s\n", debugstr_a((LPCSTR)pUrlEntry + pUrlEntry->dwOffsetLocalName));
} }
URLCacheContainer_UnlockIndex(pContainer, pHeader); URLCacheContainer_UnlockIndex(pContainer, pHeader);
@ -1657,14 +1698,23 @@ BOOL WINAPI SetUrlCacheEntryInfoA(
struct _HASH_ENTRY * pHashEntry; struct _HASH_ENTRY * pHashEntry;
CACHEFILE_ENTRY * pEntry; CACHEFILE_ENTRY * pEntry;
URLCACHECONTAINER * pContainer; URLCACHECONTAINER * pContainer;
DWORD error;
TRACE("(%s, %p, 0x%08x)\n", debugstr_a(lpszUrlName), lpCacheEntryInfo, dwFieldControl); TRACE("(%s, %p, 0x%08x)\n", debugstr_a(lpszUrlName), lpCacheEntryInfo, dwFieldControl);
if (!URLCacheContainers_FindContainerA(lpszUrlName, &pContainer)) error = URLCacheContainers_FindContainerA(lpszUrlName, &pContainer);
if (error != ERROR_SUCCESS)
{
SetLastError(error);
return FALSE; return FALSE;
}
if (!URLCacheContainer_OpenIndex(pContainer)) error = URLCacheContainer_OpenIndex(pContainer);
if (error != ERROR_SUCCESS)
{
SetLastError(error);
return FALSE; return FALSE;
}
if (!(pHeader = URLCacheContainer_LockIndex(pContainer))) if (!(pHeader = URLCacheContainer_LockIndex(pContainer)))
return FALSE; return FALSE;
@ -1705,14 +1755,23 @@ BOOL WINAPI SetUrlCacheEntryInfoW(LPCWSTR lpszUrl, LPINTERNET_CACHE_ENTRY_INFOW
struct _HASH_ENTRY * pHashEntry; struct _HASH_ENTRY * pHashEntry;
CACHEFILE_ENTRY * pEntry; CACHEFILE_ENTRY * pEntry;
URLCACHECONTAINER * pContainer; URLCACHECONTAINER * pContainer;
DWORD error;
TRACE("(%s, %p, 0x%08x)\n", debugstr_w(lpszUrl), lpCacheEntryInfo, dwFieldControl); TRACE("(%s, %p, 0x%08x)\n", debugstr_w(lpszUrl), lpCacheEntryInfo, dwFieldControl);
if (!URLCacheContainers_FindContainerW(lpszUrl, &pContainer)) error = URLCacheContainers_FindContainerW(lpszUrl, &pContainer);
if (error != ERROR_SUCCESS)
{
SetLastError(error);
return FALSE; return FALSE;
}
if (!URLCacheContainer_OpenIndex(pContainer)) error = URLCacheContainer_OpenIndex(pContainer);
if (error != ERROR_SUCCESS)
{
SetLastError(error);
return FALSE; return FALSE;
}
if (!(pHeader = URLCacheContainer_LockIndex(pContainer))) if (!(pHeader = URLCacheContainer_LockIndex(pContainer)))
return FALSE; return FALSE;
@ -1760,6 +1819,7 @@ BOOL WINAPI RetrieveUrlCacheEntryFileA(
CACHEFILE_ENTRY * pEntry; CACHEFILE_ENTRY * pEntry;
URL_CACHEFILE_ENTRY * pUrlEntry; URL_CACHEFILE_ENTRY * pUrlEntry;
URLCACHECONTAINER * pContainer; URLCACHECONTAINER * pContainer;
DWORD error;
TRACE("(%s, %p, %p, 0x%08x)\n", TRACE("(%s, %p, %p, 0x%08x)\n",
debugstr_a(lpszUrlName), debugstr_a(lpszUrlName),
@ -1767,11 +1827,26 @@ BOOL WINAPI RetrieveUrlCacheEntryFileA(
lpdwCacheEntryInfoBufferSize, lpdwCacheEntryInfoBufferSize,
dwReserved); dwReserved);
if (!URLCacheContainers_FindContainerA(lpszUrlName, &pContainer)) if (!lpszUrlName || !lpdwCacheEntryInfoBufferSize ||
(!lpCacheEntryInfo && *lpdwCacheEntryInfoBufferSize))
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE; return FALSE;
}
if (!URLCacheContainer_OpenIndex(pContainer)) error = URLCacheContainers_FindContainerA(lpszUrlName, &pContainer);
if (error != ERROR_SUCCESS)
{
SetLastError(error);
return FALSE; return FALSE;
}
error = URLCacheContainer_OpenIndex(pContainer);
if (error != ERROR_SUCCESS)
{
SetLastError(error);
return FALSE;
}
if (!(pHeader = URLCacheContainer_LockIndex(pContainer))) if (!(pHeader = URLCacheContainer_LockIndex(pContainer)))
return FALSE; return FALSE;
@ -1801,12 +1876,16 @@ BOOL WINAPI RetrieveUrlCacheEntryFileA(
pUrlEntry->dwUseCount++; pUrlEntry->dwUseCount++;
URLCache_HashEntrySetUse(pHashEntry, pUrlEntry->dwUseCount); URLCache_HashEntrySetUse(pHashEntry, pUrlEntry->dwUseCount);
if (!URLCache_CopyEntry(pContainer, pHeader, lpCacheEntryInfo, lpdwCacheEntryInfoBufferSize, pUrlEntry, FALSE)) error = URLCache_CopyEntry(pContainer, pHeader, lpCacheEntryInfo,
lpdwCacheEntryInfoBufferSize, pUrlEntry,
FALSE);
if (error != ERROR_SUCCESS)
{ {
URLCacheContainer_UnlockIndex(pContainer, pHeader); URLCacheContainer_UnlockIndex(pContainer, pHeader);
SetLastError(error);
return FALSE; return FALSE;
} }
TRACE("Local File Name: %s\n", lpCacheEntryInfo->lpszLocalFileName); TRACE("Local File Name: %s\n", debugstr_a((LPCSTR)pUrlEntry + pUrlEntry->dwOffsetLocalName));
URLCacheContainer_UnlockIndex(pContainer, pHeader); URLCacheContainer_UnlockIndex(pContainer, pHeader);
@ -1829,6 +1908,7 @@ BOOL WINAPI RetrieveUrlCacheEntryFileW(
CACHEFILE_ENTRY * pEntry; CACHEFILE_ENTRY * pEntry;
URL_CACHEFILE_ENTRY * pUrlEntry; URL_CACHEFILE_ENTRY * pUrlEntry;
URLCACHECONTAINER * pContainer; URLCACHECONTAINER * pContainer;
DWORD error;
TRACE("(%s, %p, %p, 0x%08x)\n", TRACE("(%s, %p, %p, 0x%08x)\n",
debugstr_w(lpszUrlName), debugstr_w(lpszUrlName),
@ -1836,11 +1916,26 @@ BOOL WINAPI RetrieveUrlCacheEntryFileW(
lpdwCacheEntryInfoBufferSize, lpdwCacheEntryInfoBufferSize,
dwReserved); dwReserved);
if (!URLCacheContainers_FindContainerW(lpszUrlName, &pContainer)) if (!lpszUrlName || !lpdwCacheEntryInfoBufferSize ||
(!lpCacheEntryInfo && *lpdwCacheEntryInfoBufferSize))
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE; return FALSE;
}
if (!URLCacheContainer_OpenIndex(pContainer)) error = URLCacheContainers_FindContainerW(lpszUrlName, &pContainer);
if (error != ERROR_SUCCESS)
{
SetLastError(error);
return FALSE; return FALSE;
}
error = URLCacheContainer_OpenIndex(pContainer);
if (error != ERROR_SUCCESS)
{
SetLastError(error);
return FALSE;
}
if (!(pHeader = URLCacheContainer_LockIndex(pContainer))) if (!(pHeader = URLCacheContainer_LockIndex(pContainer)))
return FALSE; return FALSE;
@ -1870,18 +1965,20 @@ BOOL WINAPI RetrieveUrlCacheEntryFileW(
pUrlEntry->dwUseCount++; pUrlEntry->dwUseCount++;
URLCache_HashEntrySetUse(pHashEntry, pUrlEntry->dwUseCount); URLCache_HashEntrySetUse(pHashEntry, pUrlEntry->dwUseCount);
if (!URLCache_CopyEntry( error = URLCache_CopyEntry(
pContainer, pContainer,
pHeader, pHeader,
(LPINTERNET_CACHE_ENTRY_INFOA)lpCacheEntryInfo, (LPINTERNET_CACHE_ENTRY_INFOA)lpCacheEntryInfo,
lpdwCacheEntryInfoBufferSize, lpdwCacheEntryInfoBufferSize,
pUrlEntry, pUrlEntry,
TRUE /* UNICODE */)) TRUE /* UNICODE */);
if (error != ERROR_SUCCESS)
{ {
URLCacheContainer_UnlockIndex(pContainer, pHeader); URLCacheContainer_UnlockIndex(pContainer, pHeader);
SetLastError(error);
return FALSE; return FALSE;
} }
TRACE("Local File Name: %s\n", debugstr_w(lpCacheEntryInfo->lpszLocalFileName)); TRACE("Local File Name: %s\n", debugstr_a((LPCSTR)pUrlEntry + pUrlEntry->dwOffsetLocalName));
URLCacheContainer_UnlockIndex(pContainer, pHeader); URLCacheContainer_UnlockIndex(pContainer, pHeader);
@ -1902,6 +1999,7 @@ BOOL WINAPI UnlockUrlCacheEntryFileA(
CACHEFILE_ENTRY * pEntry; CACHEFILE_ENTRY * pEntry;
URL_CACHEFILE_ENTRY * pUrlEntry; URL_CACHEFILE_ENTRY * pUrlEntry;
URLCACHECONTAINER * pContainer; URLCACHECONTAINER * pContainer;
DWORD error;
TRACE("(%s, 0x%08x)\n", debugstr_a(lpszUrlName), dwReserved); TRACE("(%s, 0x%08x)\n", debugstr_a(lpszUrlName), dwReserved);
@ -1912,11 +2010,19 @@ BOOL WINAPI UnlockUrlCacheEntryFileA(
return FALSE; return FALSE;
} }
if (!URLCacheContainers_FindContainerA(lpszUrlName, &pContainer)) error = URLCacheContainers_FindContainerA(lpszUrlName, &pContainer);
if (error != ERROR_SUCCESS)
{
SetLastError(error);
return FALSE; return FALSE;
}
if (!URLCacheContainer_OpenIndex(pContainer)) error = URLCacheContainer_OpenIndex(pContainer);
if (error != ERROR_SUCCESS)
{
SetLastError(error);
return FALSE; return FALSE;
}
if (!(pHeader = URLCacheContainer_LockIndex(pContainer))) if (!(pHeader = URLCacheContainer_LockIndex(pContainer)))
return FALSE; return FALSE;
@ -1964,6 +2070,7 @@ BOOL WINAPI UnlockUrlCacheEntryFileW( LPCWSTR lpszUrlName, DWORD dwReserved )
CACHEFILE_ENTRY * pEntry; CACHEFILE_ENTRY * pEntry;
URL_CACHEFILE_ENTRY * pUrlEntry; URL_CACHEFILE_ENTRY * pUrlEntry;
URLCACHECONTAINER * pContainer; URLCACHECONTAINER * pContainer;
DWORD error;
TRACE("(%s, 0x%08x)\n", debugstr_w(lpszUrlName), dwReserved); TRACE("(%s, 0x%08x)\n", debugstr_w(lpszUrlName), dwReserved);
@ -1974,11 +2081,19 @@ BOOL WINAPI UnlockUrlCacheEntryFileW( LPCWSTR lpszUrlName, DWORD dwReserved )
return FALSE; return FALSE;
} }
if (!URLCacheContainers_FindContainerW(lpszUrlName, &pContainer)) error = URLCacheContainers_FindContainerW(lpszUrlName, &pContainer);
if (error != ERROR_SUCCESS)
{
SetLastError(error);
return FALSE; return FALSE;
}
if (!URLCacheContainer_OpenIndex(pContainer)) error = URLCacheContainer_OpenIndex(pContainer);
if (error != ERROR_SUCCESS)
{
SetLastError(error);
return FALSE; return FALSE;
}
if (!(pHeader = URLCacheContainer_LockIndex(pContainer))) if (!(pHeader = URLCacheContainer_LockIndex(pContainer)))
return FALSE; return FALSE;
@ -2095,6 +2210,7 @@ BOOL WINAPI CreateUrlCacheEntryW(
LONG lBufferSize; LONG lBufferSize;
BOOL bFound = FALSE; BOOL bFound = FALSE;
int count; int count;
DWORD error;
static const WCHAR szWWW[] = {'w','w','w',0}; static const WCHAR szWWW[] = {'w','w','w',0};
TRACE("(%s, 0x%08x, %s, %p, 0x%08x)\n", TRACE("(%s, 0x%08x, %s, %p, 0x%08x)\n",
@ -2144,6 +2260,8 @@ BOOL WINAPI CreateUrlCacheEntryW(
if (!len) if (!len)
return FALSE; return FALSE;
szFile[len] = '\0'; szFile[len] = '\0';
while(len && szFile[--len] == '/') szFile[len] = '\0';
/* FIXME: get rid of illegal characters like \, / and : */ /* FIXME: get rid of illegal characters like \, / and : */
} }
else else
@ -2153,11 +2271,19 @@ BOOL WINAPI CreateUrlCacheEntryW(
TRACE("File name: %s\n", debugstr_a(szFile)); TRACE("File name: %s\n", debugstr_a(szFile));
if (!URLCacheContainers_FindContainerW(lpszUrlName, &pContainer)) error = URLCacheContainers_FindContainerW(lpszUrlName, &pContainer);
if (error != ERROR_SUCCESS)
{
SetLastError(error);
return FALSE; return FALSE;
}
if (!URLCacheContainer_OpenIndex(pContainer)) error = URLCacheContainer_OpenIndex(pContainer);
if (error != ERROR_SUCCESS)
{
SetLastError(error);
return FALSE; return FALSE;
}
if (!(pHeader = URLCacheContainer_LockIndex(pContainer))) if (!(pHeader = URLCacheContainer_LockIndex(pContainer)))
return FALSE; return FALSE;
@ -2193,7 +2319,24 @@ BOOL WINAPI CreateUrlCacheEntryW(
{ {
static const WCHAR szFormat[] = {'[','%','u',']','%','s',0}; static const WCHAR szFormat[] = {'[','%','u',']','%','s',0};
HANDLE hFile; HANDLE hFile;
WCHAR *p;
wsprintfW(lpszFileNameNoPath + countnoextension, szFormat, i, szExtension); wsprintfW(lpszFileNameNoPath + countnoextension, szFormat, i, szExtension);
for (p = lpszFileNameNoPath + 1; *p; p++)
{
switch (*p)
{
case '<': case '>':
case ':': case '"':
case '/': case '\\':
case '|': case '?':
case '*':
*p = '_'; break;
default: break;
}
}
if (p[-1] == ' ' || p[-1] == '.') p[-1] = '_';
TRACE("Trying: %s\n", debugstr_w(lpszFileName)); TRACE("Trying: %s\n", debugstr_w(lpszFileName));
hFile = CreateFileW(lpszFileName, GENERIC_READ, 0, NULL, CREATE_NEW, 0, NULL); hFile = CreateFileW(lpszFileName, GENERIC_READ, 0, NULL, CREATE_NEW, 0, NULL);
if (hFile != INVALID_HANDLE_VALUE) if (hFile != INVALID_HANDLE_VALUE)
@ -2221,7 +2364,7 @@ BOOL WINAPI CreateUrlCacheEntryW(
* result will lose data for arbitrary binary data. * result will lose data for arbitrary binary data.
* *
*/ */
static BOOL WINAPI CommitUrlCacheEntryInternal( static BOOL CommitUrlCacheEntryInternal(
IN LPCWSTR lpszUrlName, IN LPCWSTR lpszUrlName,
IN LPCWSTR lpszLocalFileName, IN LPCWSTR lpszLocalFileName,
IN FILETIME ExpireTime, IN FILETIME ExpireTime,
@ -2250,7 +2393,7 @@ static BOOL WINAPI CommitUrlCacheEntryInternal(
LPSTR lpszUrlNameA = NULL; LPSTR lpszUrlNameA = NULL;
LPSTR lpszFileExtensionA = NULL; LPSTR lpszFileExtensionA = NULL;
char *pchLocalFileName = 0; char *pchLocalFileName = 0;
DWORD error = ERROR_SUCCESS; DWORD error;
TRACE("(%s, %s, ..., ..., %x, %p, %d, %s, %s)\n", TRACE("(%s, %s, ..., ..., %x, %p, %d, %s, %s)\n",
debugstr_w(lpszUrlName), debugstr_w(lpszUrlName),
@ -2287,11 +2430,19 @@ static BOOL WINAPI CommitUrlCacheEntryInternal(
CloseHandle(hFile); CloseHandle(hFile);
} }
if (!URLCacheContainers_FindContainerW(lpszUrlName, &pContainer)) error = URLCacheContainers_FindContainerW(lpszUrlName, &pContainer);
if (error != ERROR_SUCCESS)
{
SetLastError(error);
return FALSE; return FALSE;
}
if (!URLCacheContainer_OpenIndex(pContainer)) error = URLCacheContainer_OpenIndex(pContainer);
if (error != ERROR_SUCCESS)
{
SetLastError(error);
return FALSE; return FALSE;
}
if (!(pHeader = URLCacheContainer_LockIndex(pContainer))) if (!(pHeader = URLCacheContainer_LockIndex(pContainer)))
return FALSE; return FALSE;
@ -2436,13 +2587,10 @@ static BOOL WINAPI CommitUrlCacheEntryInternal(
if (dwOffsetFileExtension) if (dwOffsetFileExtension)
strcpy((LPSTR)((LPBYTE)pUrlEntry + dwOffsetFileExtension), lpszFileExtensionA); strcpy((LPSTR)((LPBYTE)pUrlEntry + dwOffsetFileExtension), lpszFileExtensionA);
if (!URLCache_AddEntryToHash(pHeader, lpszUrlNameA, (DWORD)((LPBYTE)pUrlEntry - (LPBYTE)pHeader))) error = URLCache_AddEntryToHash(pHeader, lpszUrlNameA,
{ (DWORD)((LPBYTE)pUrlEntry - (LPBYTE)pHeader));
if (error != ERROR_SUCCESS)
URLCache_DeleteEntry(pHeader, &pUrlEntry->CacheFileEntry); URLCache_DeleteEntry(pHeader, &pUrlEntry->CacheFileEntry);
URLCacheContainer_UnlockIndex(pContainer, pHeader);
HeapFree(GetProcessHeap(), 0, lpszUrlNameA);
return FALSE;
}
cleanup: cleanup:
URLCacheContainer_UnlockIndex(pContainer, pHeader); URLCacheContainer_UnlockIndex(pContainer, pHeader);
@ -2675,7 +2823,7 @@ HANDLE WINAPI RetrieveUrlCacheEntryStreamA(
pStream->hFile = hFile; pStream->hFile = hFile;
strcpy(pStream->lpszUrl, lpszUrlName); strcpy(pStream->lpszUrl, lpszUrlName);
return (HANDLE)pStream; return pStream;
} }
/*********************************************************************** /***********************************************************************
@ -2742,14 +2890,23 @@ BOOL WINAPI DeleteUrlCacheEntryA(LPCSTR lpszUrlName)
LPURLCACHE_HEADER pHeader; LPURLCACHE_HEADER pHeader;
struct _HASH_ENTRY * pHashEntry; struct _HASH_ENTRY * pHashEntry;
CACHEFILE_ENTRY * pEntry; CACHEFILE_ENTRY * pEntry;
DWORD error;
TRACE("(%s)\n", debugstr_a(lpszUrlName)); TRACE("(%s)\n", debugstr_a(lpszUrlName));
if (!URLCacheContainers_FindContainerA(lpszUrlName, &pContainer)) error = URLCacheContainers_FindContainerA(lpszUrlName, &pContainer);
if (error != ERROR_SUCCESS)
{
SetLastError(error);
return FALSE; return FALSE;
}
if (!URLCacheContainer_OpenIndex(pContainer)) error = URLCacheContainer_OpenIndex(pContainer);
if (error != ERROR_SUCCESS)
{
SetLastError(error);
return FALSE; return FALSE;
}
if (!(pHeader = URLCacheContainer_LockIndex(pContainer))) if (!(pHeader = URLCacheContainer_LockIndex(pContainer)))
return FALSE; return FALSE;
@ -2784,6 +2941,7 @@ BOOL WINAPI DeleteUrlCacheEntryW(LPCWSTR lpszUrlName)
CACHEFILE_ENTRY * pEntry; CACHEFILE_ENTRY * pEntry;
LPSTR urlA; LPSTR urlA;
int url_len; int url_len;
DWORD error;
TRACE("(%s)\n", debugstr_w(lpszUrlName)); TRACE("(%s)\n", debugstr_w(lpszUrlName));
@ -2796,16 +2954,22 @@ BOOL WINAPI DeleteUrlCacheEntryW(LPCWSTR lpszUrlName)
} }
WideCharToMultiByte(CP_ACP, 0, lpszUrlName, -1, urlA, url_len, NULL, NULL); WideCharToMultiByte(CP_ACP, 0, lpszUrlName, -1, urlA, url_len, NULL, NULL);
if (!URLCacheContainers_FindContainerW(lpszUrlName, &pContainer)) error = URLCacheContainers_FindContainerW(lpszUrlName, &pContainer);
if (error != ERROR_SUCCESS)
{ {
HeapFree(GetProcessHeap(), 0, urlA); HeapFree(GetProcessHeap(), 0, urlA);
SetLastError(error);
return FALSE; return FALSE;
} }
if (!URLCacheContainer_OpenIndex(pContainer))
error = URLCacheContainer_OpenIndex(pContainer);
if (error != ERROR_SUCCESS)
{ {
HeapFree(GetProcessHeap(), 0, urlA); HeapFree(GetProcessHeap(), 0, urlA);
SetLastError(error);
return FALSE; return FALSE;
} }
if (!(pHeader = URLCacheContainer_LockIndex(pContainer))) if (!(pHeader = URLCacheContainer_LockIndex(pContainer)))
{ {
HeapFree(GetProcessHeap(), 0, urlA); HeapFree(GetProcessHeap(), 0, urlA);
@ -3057,9 +3221,14 @@ BOOL WINAPI FindNextUrlCacheEntryA(
{ {
LPURLCACHE_HEADER pHeader; LPURLCACHE_HEADER pHeader;
HASH_CACHEFILE_ENTRY *pHashTableEntry; HASH_CACHEFILE_ENTRY *pHashTableEntry;
DWORD error;
if (!URLCacheContainer_OpenIndex(pContainer)) error = URLCacheContainer_OpenIndex(pContainer);
if (error != ERROR_SUCCESS)
{
SetLastError(error);
return FALSE; return FALSE;
}
if (!(pHeader = URLCacheContainer_LockIndex(pContainer))) if (!(pHeader = URLCacheContainer_LockIndex(pContainer)))
return FALSE; return FALSE;
@ -3081,18 +3250,20 @@ BOOL WINAPI FindNextUrlCacheEntryA(
TRACE("Found URL: %s\n", (LPSTR)pUrlEntry + pUrlEntry->dwOffsetUrl); TRACE("Found URL: %s\n", (LPSTR)pUrlEntry + pUrlEntry->dwOffsetUrl);
TRACE("Header info: %s\n", (LPBYTE)pUrlEntry + pUrlEntry->dwOffsetHeaderInfo); TRACE("Header info: %s\n", (LPBYTE)pUrlEntry + pUrlEntry->dwOffsetHeaderInfo);
if (!URLCache_CopyEntry( error = URLCache_CopyEntry(
pContainer, pContainer,
pHeader, pHeader,
lpNextCacheEntryInfo, lpNextCacheEntryInfo,
lpdwNextCacheEntryInfoBufferSize, lpdwNextCacheEntryInfoBufferSize,
pUrlEntry, pUrlEntry,
FALSE /* not UNICODE */)) FALSE /* not UNICODE */);
if (error != ERROR_SUCCESS)
{ {
URLCacheContainer_UnlockIndex(pContainer, pHeader); URLCacheContainer_UnlockIndex(pContainer, pHeader);
SetLastError(error);
return FALSE; return FALSE;
} }
TRACE("Local File Name: %s\n", debugstr_a(lpNextCacheEntryInfo->lpszLocalFileName)); TRACE("Local File Name: %s\n", debugstr_a((LPCSTR)pUrlEntry + pUrlEntry->dwOffsetLocalName));
/* increment the current index so that next time the function /* increment the current index so that next time the function
* is called the next entry is returned */ * is called the next entry is returned */
@ -3109,6 +3280,9 @@ BOOL WINAPI FindNextUrlCacheEntryA(
return FALSE; return FALSE;
} }
/***********************************************************************
* FindNextUrlCacheEntryW (WININET.@)
*/
BOOL WINAPI FindNextUrlCacheEntryW( BOOL WINAPI FindNextUrlCacheEntryW(
HANDLE hEnumHandle, HANDLE hEnumHandle,
LPINTERNET_CACHE_ENTRY_INFOW lpNextCacheEntryInfo, LPINTERNET_CACHE_ENTRY_INFOW lpNextCacheEntryInfo,
@ -3337,14 +3511,23 @@ BOOL WINAPI IsUrlCacheEntryExpiredA( LPCSTR url, DWORD dwFlags, FILETIME* pftLas
const CACHEFILE_ENTRY * pEntry; const CACHEFILE_ENTRY * pEntry;
const URL_CACHEFILE_ENTRY * pUrlEntry; const URL_CACHEFILE_ENTRY * pUrlEntry;
URLCACHECONTAINER * pContainer; URLCACHECONTAINER * pContainer;
DWORD error;
TRACE("(%s, %08x, %p)\n", debugstr_a(url), dwFlags, pftLastModified); TRACE("(%s, %08x, %p)\n", debugstr_a(url), dwFlags, pftLastModified);
if (!URLCacheContainers_FindContainerA(url, &pContainer)) error = URLCacheContainers_FindContainerA(url, &pContainer);
if (error != ERROR_SUCCESS)
{
SetLastError(error);
return FALSE; return FALSE;
}
if (!URLCacheContainer_OpenIndex(pContainer)) error = URLCacheContainer_OpenIndex(pContainer);
if (error != ERROR_SUCCESS)
{
SetLastError(error);
return FALSE; return FALSE;
}
if (!(pHeader = URLCacheContainer_LockIndex(pContainer))) if (!(pHeader = URLCacheContainer_LockIndex(pContainer)))
return FALSE; return FALSE;
@ -3390,14 +3573,23 @@ BOOL WINAPI IsUrlCacheEntryExpiredW( LPCWSTR url, DWORD dwFlags, FILETIME* pftLa
const CACHEFILE_ENTRY * pEntry; const CACHEFILE_ENTRY * pEntry;
const URL_CACHEFILE_ENTRY * pUrlEntry; const URL_CACHEFILE_ENTRY * pUrlEntry;
URLCACHECONTAINER * pContainer; URLCACHECONTAINER * pContainer;
DWORD error;
TRACE("(%s, %08x, %p)\n", debugstr_w(url), dwFlags, pftLastModified); TRACE("(%s, %08x, %p)\n", debugstr_w(url), dwFlags, pftLastModified);
if (!URLCacheContainers_FindContainerW(url, &pContainer)) error = URLCacheContainers_FindContainerW(url, &pContainer);
if (error != ERROR_SUCCESS)
{
SetLastError(error);
return FALSE; return FALSE;
}
if (!URLCacheContainer_OpenIndex(pContainer)) error = URLCacheContainer_OpenIndex(pContainer);
if (error != ERROR_SUCCESS)
{
SetLastError(error);
return FALSE; return FALSE;
}
if (!(pHeader = URLCacheContainer_LockIndex(pContainer))) if (!(pHeader = URLCacheContainer_LockIndex(pContainer)))
return FALSE; return FALSE;
@ -3427,3 +3619,21 @@ BOOL WINAPI IsUrlCacheEntryExpiredW( LPCWSTR url, DWORD dwFlags, FILETIME* pftLa
return TRUE; return TRUE;
} }
/***********************************************************************
* GetDiskInfoA (WININET.@)
*/
DWORD WINAPI GetDiskInfoA(void *p0, void *p1, void *p2, void *p3)
{
FIXME("(%p, %p, %p, %p)\n", p0, p1, p2, p3);
return 0;
}
/***********************************************************************
* RegisterUrlCacheNotification (WININET.@)
*/
DWORD WINAPI RegisterUrlCacheNotification(LPVOID a, DWORD b, DWORD c, DWORD d, DWORD e, DWORD f)
{
FIXME("(%p %x %x %x %x %x)\n", a, b, c, d, e, f);
return 0;
}