Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-cw
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-cw
Commits
71fdd64b
Commit
71fdd64b
authored
Nov 23, 2022
by
Paul Gofman
Committed by
Alexandre Julliard
Nov 24, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
winhttp: Cache script in download_script().
parent
cbfe940a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
2 deletions
+52
-2
session.c
dlls/winhttp/session.c
+52
-2
No files found.
dlls/winhttp/session.c
View file @
71fdd64b
...
...
@@ -1901,6 +1901,50 @@ static BOOL parse_script_result( const char *result, WINHTTP_PROXY_INFO *info )
return
TRUE
;
}
static
SRWLOCK
cache_lock
=
SRWLOCK_INIT
;
static
DWORD
cached_script_size
;
static
ULONGLONG
cache_update_time
;
static
char
*
cached_script
;
static
WCHAR
*
cached_url
;
static
BOOL
get_cached_script
(
const
WCHAR
*
url
,
char
**
buffer
,
DWORD
*
out_size
)
{
BOOL
ret
=
FALSE
;
*
buffer
=
NULL
;
*
out_size
=
0
;
AcquireSRWLockExclusive
(
&
cache_lock
);
if
(
cached_url
&&
!
wcscmp
(
cached_url
,
url
)
&&
GetTickCount64
()
-
cache_update_time
<
60000
)
{
ret
=
TRUE
;
if
(
cached_script
&&
(
*
buffer
=
malloc
(
cached_script_size
)))
{
memcpy
(
*
buffer
,
cached_script
,
cached_script_size
);
*
out_size
=
cached_script_size
;
}
}
ReleaseSRWLockExclusive
(
&
cache_lock
);
return
ret
;
}
static
void
cache_script
(
const
WCHAR
*
url
,
char
*
buffer
,
DWORD
size
)
{
AcquireSRWLockExclusive
(
&
cache_lock
);
free
(
cached_url
);
free
(
cached_script
);
cached_script_size
=
0
;
cached_script
=
NULL
;
if
((
cached_url
=
wcsdup
(
url
))
&&
buffer
&&
(
cached_script
=
malloc
(
size
)))
{
memcpy
(
cached_script
,
buffer
,
size
);
cached_script_size
=
size
;
}
cache_update_time
=
GetTickCount64
();
ReleaseSRWLockExclusive
(
&
cache_lock
);
}
static
char
*
download_script
(
const
WCHAR
*
url
,
DWORD
*
out_size
)
{
static
const
WCHAR
*
acceptW
[]
=
{
L"*/*"
,
NULL
};
...
...
@@ -1908,9 +1952,14 @@ static char *download_script( const WCHAR *url, DWORD *out_size )
WCHAR
*
hostname
;
URL_COMPONENTSW
uc
;
DWORD
status
,
size
=
sizeof
(
status
),
offset
,
to_read
,
bytes_read
,
flags
=
0
;
char
*
tmp
,
*
buffer
=
NULL
;
char
*
tmp
,
*
buffer
;
*
out_size
=
0
;
if
(
get_cached_script
(
url
,
&
buffer
,
out_size
))
{
TRACE
(
"Returning cached result.
\n
"
);
if
(
!
buffer
)
SetLastError
(
ERROR_WINHTTP_UNABLE_TO_DOWNLOAD_SCRIPT
);
return
buffer
;
}
memset
(
&
uc
,
0
,
sizeof
(
uc
)
);
uc
.
dwStructSize
=
sizeof
(
uc
);
...
...
@@ -1957,6 +2006,7 @@ done:
WinHttpCloseHandle
(
con
);
WinHttpCloseHandle
(
ses
);
free
(
hostname
);
cache_script
(
url
,
buffer
,
*
out_size
);
if
(
!
buffer
)
SetLastError
(
ERROR_WINHTTP_UNABLE_TO_DOWNLOAD_SCRIPT
);
return
buffer
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment