mirror of
https://gitlab.winehq.org/wine/wine.git
synced 2024-11-21 17:09:06 -07:00
wininet: Use InternetTimeToSystemTimeW() to convert header values.
The current code calls mktime() which interprets its argument as local time while these values are assumed to be in UTC.
This commit is contained in:
parent
5a23afb34d
commit
8b121591be
Notes:
Alexandre Julliard
2024-11-15 22:24:54 +01:00
Approved-by: Jacek Caban (@jacek) Approved-by: Alexandre Julliard (@julliard) Merge-Request: https://gitlab.winehq.org/wine/wine/merge_requests/6823
3 changed files with 39 additions and 107 deletions
|
@ -3886,26 +3886,23 @@ static DWORD HTTP_HttpQueryInfoW(http_request_t *request, DWORD dwInfoLevel,
|
||||||
}
|
}
|
||||||
else if (dwInfoLevel & HTTP_QUERY_FLAG_SYSTEMTIME && lpBuffer)
|
else if (dwInfoLevel & HTTP_QUERY_FLAG_SYSTEMTIME && lpBuffer)
|
||||||
{
|
{
|
||||||
time_t tmpTime;
|
SYSTEMTIME st;
|
||||||
struct tm tmpTM;
|
|
||||||
SYSTEMTIME *STHook;
|
|
||||||
|
|
||||||
tmpTime = ConvertTimeString(lphttpHdr->lpszValue);
|
if (!InternetTimeToSystemTimeW(lphttpHdr->lpszValue, &st, 0))
|
||||||
|
{
|
||||||
tmpTM = *gmtime(&tmpTime);
|
LeaveCriticalSection( &request->headers_section );
|
||||||
STHook = (SYSTEMTIME *)lpBuffer;
|
return ERROR_HTTP_INVALID_HEADER;
|
||||||
STHook->wDay = tmpTM.tm_mday;
|
}
|
||||||
STHook->wHour = tmpTM.tm_hour;
|
if (*lpdwBufferLength < sizeof(st))
|
||||||
STHook->wMilliseconds = 0;
|
{
|
||||||
STHook->wMinute = tmpTM.tm_min;
|
*lpdwBufferLength = sizeof(st);
|
||||||
STHook->wDayOfWeek = tmpTM.tm_wday;
|
LeaveCriticalSection( &request->headers_section );
|
||||||
STHook->wMonth = tmpTM.tm_mon + 1;
|
return ERROR_INSUFFICIENT_BUFFER;
|
||||||
STHook->wSecond = tmpTM.tm_sec;
|
}
|
||||||
STHook->wYear = 1900+tmpTM.tm_year;
|
TRACE(" returning time: %04u/%02u/%02u - %u - %02u:%02u:%02u.%02u\n",
|
||||||
|
st.wYear, st.wMonth, st.wDay, st.wDayOfWeek, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
|
||||||
TRACE(" returning time: %04d/%02d/%02d - %d - %02d:%02d:%02d.%02d\n",
|
memcpy(lpBuffer, &st, sizeof(st));
|
||||||
STHook->wYear, STHook->wMonth, STHook->wDay, STHook->wDayOfWeek,
|
*lpdwBufferLength = sizeof(st);
|
||||||
STHook->wHour, STHook->wMinute, STHook->wSecond, STHook->wMilliseconds);
|
|
||||||
}
|
}
|
||||||
else if (lphttpHdr->lpszValue)
|
else if (lphttpHdr->lpszValue)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2412,6 +2412,7 @@ static const char okmsg2[] =
|
||||||
"Content-Length: 0\r\n"
|
"Content-Length: 0\r\n"
|
||||||
"Set-Cookie: one\r\n"
|
"Set-Cookie: one\r\n"
|
||||||
"Set-Cookie: two\r\n"
|
"Set-Cookie: two\r\n"
|
||||||
|
"Last-Modified: Mon, 01 Dec 2008 13:44:34 UTC\r\n"
|
||||||
"\r\n";
|
"\r\n";
|
||||||
|
|
||||||
static DWORD64 content_length;
|
static DWORD64 content_length;
|
||||||
|
@ -4566,9 +4567,11 @@ static void test_head_request(int port)
|
||||||
|
|
||||||
static void test_HttpQueryInfo(int port)
|
static void test_HttpQueryInfo(int port)
|
||||||
{
|
{
|
||||||
|
static const SYSTEMTIME expect = {2008, 12, 1, 1, 13, 44, 34};
|
||||||
test_request_t req;
|
test_request_t req;
|
||||||
DWORD size, index, error;
|
DWORD size, index, error;
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
|
SYSTEMTIME st;
|
||||||
BOOL ret;
|
BOOL ret;
|
||||||
|
|
||||||
open_simple_request(&req, "localhost", port, NULL, "/testD");
|
open_simple_request(&req, "localhost", port, NULL, "/testD");
|
||||||
|
@ -4589,9 +4592,27 @@ static void test_HttpQueryInfo(int port)
|
||||||
ok(index == 1, "expected 1 got %lu\n", index);
|
ok(index == 1, "expected 1 got %lu\n", index);
|
||||||
|
|
||||||
index = 0;
|
index = 0;
|
||||||
size = sizeof(buffer);
|
size = 0;
|
||||||
ret = HttpQueryInfoA(req.request, HTTP_QUERY_DATE | HTTP_QUERY_FLAG_SYSTEMTIME, buffer, &size, &index);
|
ret = HttpQueryInfoA(req.request, HTTP_QUERY_DATE | HTTP_QUERY_FLAG_SYSTEMTIME, &st, &size, &index);
|
||||||
|
ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, "got %lu\n", GetLastError());
|
||||||
|
ok(size == sizeof(st), "got %lu\n", size);
|
||||||
|
|
||||||
|
index = 0;
|
||||||
|
size = sizeof(st) + 1;
|
||||||
|
memset(&st, 0, sizeof(st));
|
||||||
|
ret = HttpQueryInfoA(req.request, HTTP_QUERY_DATE | HTTP_QUERY_FLAG_SYSTEMTIME, &st, &size, &index);
|
||||||
ok(ret, "HttpQueryInfo failed %lu\n", GetLastError());
|
ok(ret, "HttpQueryInfo failed %lu\n", GetLastError());
|
||||||
|
ok(!memcmp(&st, &expect, sizeof(st)), "wrong time\n");
|
||||||
|
ok(size == sizeof(st), "got %lu\n", size);
|
||||||
|
ok(index == 1, "expected 1 got %lu\n", index);
|
||||||
|
|
||||||
|
index = 0;
|
||||||
|
size = sizeof(st);
|
||||||
|
memset(&st, 0, sizeof(st));
|
||||||
|
ret = HttpQueryInfoA(req.request, HTTP_QUERY_LAST_MODIFIED | HTTP_QUERY_FLAG_SYSTEMTIME, &st, &size, &index);
|
||||||
|
ok(ret, "HttpQueryInfo failed %lu\n", GetLastError());
|
||||||
|
ok(!memcmp(&st, &expect, sizeof(st)), "wrong time\n");
|
||||||
|
ok(size == sizeof(st), "got %lu\n", size);
|
||||||
ok(index == 1, "expected 1 got %lu\n", index);
|
ok(index == 1, "expected 1 got %lu\n", index);
|
||||||
|
|
||||||
index = 0;
|
index = 0;
|
||||||
|
|
|
@ -39,92 +39,6 @@
|
||||||
|
|
||||||
WINE_DEFAULT_DEBUG_CHANNEL(wininet);
|
WINE_DEFAULT_DEBUG_CHANNEL(wininet);
|
||||||
|
|
||||||
#define TIME_STRING_LEN 30
|
|
||||||
|
|
||||||
time_t ConvertTimeString(LPCWSTR asctime)
|
|
||||||
{
|
|
||||||
WCHAR tmpChar[TIME_STRING_LEN];
|
|
||||||
WCHAR *tmpChar2;
|
|
||||||
struct tm t;
|
|
||||||
int timelen = lstrlenW(asctime);
|
|
||||||
|
|
||||||
if(!timelen)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
/* FIXME: the atoiWs below rely on that tmpChar is \0 padded */
|
|
||||||
memset( tmpChar, 0, sizeof(tmpChar) );
|
|
||||||
lstrcpynW(tmpChar, asctime, TIME_STRING_LEN);
|
|
||||||
|
|
||||||
/* Assert that the string is the expected length */
|
|
||||||
if (lstrlenW(asctime) >= TIME_STRING_LEN) FIXME("\n");
|
|
||||||
|
|
||||||
/* Convert a time such as 'Mon, 15 Nov 1999 16:09:35 GMT' into a SYSTEMTIME structure
|
|
||||||
* We assume the time is in this format
|
|
||||||
* and divide it into easy to swallow chunks
|
|
||||||
*/
|
|
||||||
tmpChar[3]='\0';
|
|
||||||
tmpChar[7]='\0';
|
|
||||||
tmpChar[11]='\0';
|
|
||||||
tmpChar[16]='\0';
|
|
||||||
tmpChar[19]='\0';
|
|
||||||
tmpChar[22]='\0';
|
|
||||||
tmpChar[25]='\0';
|
|
||||||
|
|
||||||
memset( &t, 0, sizeof(t) );
|
|
||||||
t.tm_year = wcstol(tmpChar+12, NULL, 10) - 1900;
|
|
||||||
t.tm_mday = wcstol(tmpChar+5, NULL, 10);
|
|
||||||
t.tm_hour = wcstol(tmpChar+17, NULL, 10);
|
|
||||||
t.tm_min = wcstol(tmpChar+20, NULL, 10);
|
|
||||||
t.tm_sec = wcstol(tmpChar+23, NULL, 10);
|
|
||||||
|
|
||||||
/* and month */
|
|
||||||
tmpChar2 = tmpChar + 8;
|
|
||||||
switch(tmpChar2[2])
|
|
||||||
{
|
|
||||||
case 'n':
|
|
||||||
if(tmpChar2[1]=='a')
|
|
||||||
t.tm_mon = 0;
|
|
||||||
else
|
|
||||||
t.tm_mon = 5;
|
|
||||||
break;
|
|
||||||
case 'b':
|
|
||||||
t.tm_mon = 1;
|
|
||||||
break;
|
|
||||||
case 'r':
|
|
||||||
if(tmpChar2[1]=='a')
|
|
||||||
t.tm_mon = 2;
|
|
||||||
else
|
|
||||||
t.tm_mon = 3;
|
|
||||||
break;
|
|
||||||
case 'y':
|
|
||||||
t.tm_mon = 4;
|
|
||||||
break;
|
|
||||||
case 'l':
|
|
||||||
t.tm_mon = 6;
|
|
||||||
break;
|
|
||||||
case 'g':
|
|
||||||
t.tm_mon = 7;
|
|
||||||
break;
|
|
||||||
case 'p':
|
|
||||||
t.tm_mon = 8;
|
|
||||||
break;
|
|
||||||
case 't':
|
|
||||||
t.tm_mon = 9;
|
|
||||||
break;
|
|
||||||
case 'v':
|
|
||||||
t.tm_mon = 10;
|
|
||||||
break;
|
|
||||||
case 'c':
|
|
||||||
t.tm_mon = 11;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
FIXME("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
return mktime(&t);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
BOOL GetAddress(const WCHAR *name, INTERNET_PORT port, struct sockaddr *psa, int *sa_len, char *addr_str)
|
BOOL GetAddress(const WCHAR *name, INTERNET_PORT port, struct sockaddr *psa, int *sa_len, char *addr_str)
|
||||||
{
|
{
|
||||||
ADDRINFOW *res, hints;
|
ADDRINFOW *res, hints;
|
||||||
|
|
Loading…
Reference in a new issue