wininet: Moved request file info to separated struct.

This commit is contained in:
Jacek Caban 2013-10-04 16:52:43 +02:00 committed by Alexandre Julliard
parent a60ebd3ade
commit c58317b5b4
3 changed files with 72 additions and 17 deletions

View File

@ -1912,11 +1912,10 @@ static void HTTPREQ_Destroy(object_header_t *hdr)
TRACE("\n"); TRACE("\n");
if(request->hCacheFile) { if(request->hCacheFile)
CloseHandle(request->hCacheFile); CloseHandle(request->hCacheFile);
DeleteFileW(request->cacheFile); if(request->req_file)
} req_file_release(request->req_file);
heap_free(request->cacheFile);
request->read_section.DebugInfo->Spare[0] = 0; request->read_section.DebugInfo->Spare[0] = 0;
DeleteCriticalSection( &request->read_section ); DeleteCriticalSection( &request->read_section );
@ -2194,25 +2193,25 @@ static DWORD HTTPREQ_QueryOption(object_header_t *hdr, DWORD option, void *buffe
TRACE("INTERNET_OPTION_DATAFILE_NAME\n"); TRACE("INTERNET_OPTION_DATAFILE_NAME\n");
if(!req->cacheFile) { if(!req->req_file) {
*size = 0; *size = 0;
return ERROR_INTERNET_ITEM_NOT_FOUND; return ERROR_INTERNET_ITEM_NOT_FOUND;
} }
if(unicode) { if(unicode) {
req_size = (lstrlenW(req->cacheFile)+1) * sizeof(WCHAR); req_size = (lstrlenW(req->req_file->file_name)+1) * sizeof(WCHAR);
if(*size < req_size) if(*size < req_size)
return ERROR_INSUFFICIENT_BUFFER; return ERROR_INSUFFICIENT_BUFFER;
*size = req_size; *size = req_size;
memcpy(buffer, req->cacheFile, *size); memcpy(buffer, req->req_file->file_name, *size);
return ERROR_SUCCESS; return ERROR_SUCCESS;
}else { }else {
req_size = WideCharToMultiByte(CP_ACP, 0, req->cacheFile, -1, NULL, 0, NULL, NULL); req_size = WideCharToMultiByte(CP_ACP, 0, req->req_file->file_name, -1, NULL, 0, NULL, NULL);
if (req_size > *size) if (req_size > *size)
return ERROR_INSUFFICIENT_BUFFER; return ERROR_INSUFFICIENT_BUFFER;
*size = WideCharToMultiByte(CP_ACP, 0, req->cacheFile, *size = WideCharToMultiByte(CP_ACP, 0, req->req_file->file_name,
-1, buffer, *size, NULL, NULL); -1, buffer, *size, NULL, NULL);
return ERROR_SUCCESS; return ERROR_SUCCESS;
} }
@ -2376,12 +2375,17 @@ static void commit_cache_entry(http_request_t *req)
if(HTTP_GetRequestURL(req, url)) { if(HTTP_GetRequestURL(req, url)) {
WCHAR *header; WCHAR *header;
DWORD header_len; DWORD header_len;
BOOL res;
header = build_response_header(req, TRUE); header = build_response_header(req, TRUE);
header_len = (header ? strlenW(header) : 0); header_len = (header ? strlenW(header) : 0);
CommitUrlCacheEntryW(url, req->cacheFile, req->expires, res = CommitUrlCacheEntryW(url, req->req_file->file_name, req->expires,
req->last_modified, NORMAL_CACHE_ENTRY, req->last_modified, NORMAL_CACHE_ENTRY,
header, header_len, NULL, 0); header, header_len, NULL, 0);
if(res)
req->req_file->is_committed = TRUE;
else
WARN("CommitUrlCacheEntry failed: %u\n", GetLastError());
heap_free(header); heap_free(header);
} }
} }
@ -2396,9 +2400,14 @@ static void create_cache_entry(http_request_t *req)
BOOL b = TRUE; BOOL b = TRUE;
/* FIXME: We should free previous cache file earlier */ /* FIXME: We should free previous cache file earlier */
heap_free(req->cacheFile); if(req->req_file) {
req_file_release(req->req_file);
req->req_file = NULL;
}
if(req->hCacheFile) {
CloseHandle(req->hCacheFile); CloseHandle(req->hCacheFile);
req->hCacheFile = NULL; req->hCacheFile = NULL;
}
if(req->hdr.dwFlags & INTERNET_FLAG_NO_CACHE_WRITE) if(req->hdr.dwFlags & INTERNET_FLAG_NO_CACHE_WRITE)
b = FALSE; b = FALSE;
@ -2450,8 +2459,9 @@ static void create_cache_entry(http_request_t *req)
return; return;
} }
req->cacheFile = heap_strdupW(file_name); create_req_file(file_name, &req->req_file);
req->hCacheFile = CreateFileW(req->cacheFile, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,
req->hCacheFile = CreateFileW(file_name, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if(req->hCacheFile == INVALID_HANDLE_VALUE) { if(req->hCacheFile == INVALID_HANDLE_VALUE) {
WARN("Could not create file: %u\n", GetLastError()); WARN("Could not create file: %u\n", GetLastError());

View File

@ -3901,6 +3901,36 @@ BOOL WINAPI InternetQueryDataAvailable( HINTERNET hFile,
return res == ERROR_SUCCESS; return res == ERROR_SUCCESS;
} }
DWORD create_req_file(const WCHAR *file_name, req_file_t **ret)
{
req_file_t *req_file;
req_file = heap_alloc_zero(sizeof(*req_file));
if(!req_file)
return ERROR_NOT_ENOUGH_MEMORY;
req_file->ref = 1;
req_file->file_name = heap_strdupW(file_name);
if(!req_file->file_name) {
heap_free(req_file);
return ERROR_NOT_ENOUGH_MEMORY;
}
*ret = req_file;
return ERROR_SUCCESS;
}
void req_file_release(req_file_t *req_file)
{
if(InterlockedDecrement(&req_file->ref))
return;
if(!req_file->is_committed)
DeleteFileW(req_file->file_name);
heap_free(req_file->file_name);
heap_free(req_file);
}
/*********************************************************************** /***********************************************************************
* InternetLockRequestFile (WININET.@) * InternetLockRequestFile (WININET.@)

View File

@ -247,6 +247,13 @@ typedef enum
#define INET_OPENURL 0x0001 #define INET_OPENURL 0x0001
#define INET_CALLBACKW 0x0002 #define INET_CALLBACKW 0x0002
typedef struct
{
LONG ref;
WCHAR *file_name;
BOOL is_committed;
} req_file_t;
typedef struct _object_header_t object_header_t; typedef struct _object_header_t object_header_t;
typedef struct { typedef struct {
@ -280,7 +287,6 @@ struct _object_header_t
struct list children; struct list children;
}; };
typedef struct typedef struct
{ {
object_header_t hdr; object_header_t hdr;
@ -357,7 +363,7 @@ typedef struct
DWORD nCustHeaders; DWORD nCustHeaders;
FILETIME last_modified; FILETIME last_modified;
HANDLE hCacheFile; HANDLE hCacheFile;
LPWSTR cacheFile; req_file_t *req_file;
FILETIME expires; FILETIME expires;
struct HttpAuthInfo *authInfo; struct HttpAuthInfo *authInfo;
struct HttpAuthInfo *proxyAuthInfo; struct HttpAuthInfo *proxyAuthInfo;
@ -444,6 +450,15 @@ int sock_get_error(int) DECLSPEC_HIDDEN;
server_t *get_server(const WCHAR*,INTERNET_PORT,BOOL,BOOL); server_t *get_server(const WCHAR*,INTERNET_PORT,BOOL,BOOL);
DWORD create_req_file(const WCHAR*,req_file_t**) DECLSPEC_HIDDEN;
void req_file_release(req_file_t*) DECLSPEC_HIDDEN;
static inline req_file_t *req_file_addref(req_file_t *req_file)
{
InterlockedIncrement(&req_file->ref);
return req_file;
}
BOOL init_urlcache(void) DECLSPEC_HIDDEN; BOOL init_urlcache(void) DECLSPEC_HIDDEN;
void free_urlcache(void) DECLSPEC_HIDDEN; void free_urlcache(void) DECLSPEC_HIDDEN;
void free_cookie(void) DECLSPEC_HIDDEN; void free_cookie(void) DECLSPEC_HIDDEN;