ReactOS.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2026
April
March
February
January
2025
December
November
October
September
August
July
June
May
April
March
February
January
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
March
February
January
2005
December
November
October
September
August
July
June
May
April
March
February
January
2004
December
November
October
September
August
July
June
May
April
March
February
List overview
Download
Ros-diffs
----- 2026 -----
April 2026
March 2026
February 2026
January 2026
----- 2025 -----
December 2025
November 2025
October 2025
September 2025
August 2025
July 2025
June 2025
May 2025
April 2025
March 2025
February 2025
January 2025
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
----- 2004 -----
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
ros-diffs@reactos.org
81390 discussions
Start a n
N
ew thread
[reactos] 01/01: [PSDK] Add missing define. CORE-16441
by Amine Khaldi
07 Dec '19
07 Dec '19
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=56601978c4dfeba5add6e…
commit 56601978c4dfeba5add6e5a4abb853de72c8bb34 Author: Amine Khaldi <amine.khaldi(a)reactos.org> AuthorDate: Sat Dec 7 13:06:57 2019 +0100 Commit: Amine Khaldi <amine.khaldi(a)reactos.org> CommitDate: Sat Dec 7 13:06:57 2019 +0100 [PSDK] Add missing define. CORE-16441 --- sdk/include/psdk/wininet.h | 1 + 1 file changed, 1 insertion(+) diff --git a/sdk/include/psdk/wininet.h b/sdk/include/psdk/wininet.h index c29646c7cd2..cfc2b2675b0 100644 --- a/sdk/include/psdk/wininet.h +++ b/sdk/include/psdk/wininet.h @@ -2042,6 +2042,7 @@ PrivacyGetZonePreferenceW( #define ERROR_INTERNET_SEC_CERT_ERRORS (INTERNET_ERROR_BASE + 55) #define ERROR_INTERNET_SEC_CERT_NO_REV (INTERNET_ERROR_BASE + 56) #define ERROR_INTERNET_SEC_CERT_REV_FAILED (INTERNET_ERROR_BASE + 57) +#define ERROR_INTERNET_SEC_CERT_WEAK_SIGNATURE (INTERNET_ERROR_BASE + 62) #define ERROR_FTP_TRANSFER_IN_PROGRESS (INTERNET_ERROR_BASE + 110) #define ERROR_FTP_DROPPED (INTERNET_ERROR_BASE + 111) #define ERROR_FTP_NO_PASSIVE_MODE (INTERNET_ERROR_BASE + 112)
1
0
0
0
[reactos] 01/01: [WININET] Sync with Wine Staging 4.18. CORE-16441
by Amine Khaldi
07 Dec '19
07 Dec '19
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=c239cdd4e6cc6de59a47a…
commit c239cdd4e6cc6de59a47a5f221ff6e9ae39c14c4 Author: Amine Khaldi <amine.khaldi(a)reactos.org> AuthorDate: Sat Dec 7 13:06:34 2019 +0100 Commit: Amine Khaldi <amine.khaldi(a)reactos.org> CommitDate: Sat Dec 7 13:06:34 2019 +0100 [WININET] Sync with Wine Staging 4.18. CORE-16441 --- dll/win32/wininet/cookie.c | 37 ++++--- dll/win32/wininet/dialogs.c | 32 +++--- dll/win32/wininet/ftp.c | 5 +- dll/win32/wininet/http.c | 217 +++++++++++++++++++++++++------------- dll/win32/wininet/internet.c | 17 ++- dll/win32/wininet/internet.h | 9 +- dll/win32/wininet/netconnection.c | 14 +-- dll/win32/wininet/urlcache.c | 112 +++++++++++++++++--- dll/win32/wininet/utility.c | 2 +- media/doc/README.WINE | 2 +- 10 files changed, 299 insertions(+), 148 deletions(-) diff --git a/dll/win32/wininet/cookie.c b/dll/win32/wininet/cookie.c index 60b8335639a..2af752110c0 100644 --- a/dll/win32/wininet/cookie.c +++ b/dll/win32/wininet/cookie.c @@ -151,18 +151,18 @@ static WCHAR *create_cookie_url(substr_t domain, substr_t path, substr_t *ret_pa static const WCHAR cookie_prefix[] = {'C','o','o','k','i','e',':'}; - user_len = sizeof(user)/sizeof(WCHAR); + user_len = ARRAY_SIZE(user); if(!GetUserNameW(user, &user_len)) return FALSE; user_len--; - len = sizeof(cookie_prefix)/sizeof(WCHAR) + user_len + 1 /* @ */ + domain.len + path.len; + len = ARRAY_SIZE(cookie_prefix) + user_len + 1 /* @ */ + domain.len + path.len; url = heap_alloc((len+1) * sizeof(WCHAR)); if(!url) return NULL; memcpy(url, cookie_prefix, sizeof(cookie_prefix)); - p = url + sizeof(cookie_prefix)/sizeof(WCHAR); + p = url + ARRAY_SIZE(cookie_prefix); memcpy(p, user, user_len*sizeof(WCHAR)); p += user_len; @@ -238,7 +238,7 @@ static cookie_t *alloc_cookie(substr_t name, substr_t data, FILETIME expiry, FIL { cookie_t *new_cookie; - new_cookie = heap_alloc(sizeof(*new_cookie)); + new_cookie = heap_alloc_zero(sizeof(*new_cookie)); if(!new_cookie) return NULL; @@ -247,9 +247,12 @@ static cookie_t *alloc_cookie(substr_t name, substr_t data, FILETIME expiry, FIL new_cookie->flags = flags; list_init(&new_cookie->entry); - new_cookie->name = heap_strndupW(name.str, name.len); - new_cookie->data = heap_strndupW(data.str, data.len); - if(!new_cookie->name || !new_cookie->data) { + if(name.str && !(new_cookie->name = heap_strndupW(name.str, name.len))) { + delete_cookie(new_cookie); + return NULL; + } + + if(data.str && !(new_cookie->data = heap_strndupW(data.str, data.len))) { delete_cookie(new_cookie); return NULL; } @@ -658,7 +661,7 @@ DWORD get_cookie_header(const WCHAR *host, const WCHAR *path, WCHAR **ret) ptr = header = heap_alloc(sizeof(cookieW) + (cookie_set.string_len + 3 /* crlf0 */) * sizeof(WCHAR)); if(header) { memcpy(ptr, cookieW, sizeof(cookieW)); - ptr += sizeof(cookieW)/sizeof(*cookieW); + ptr += ARRAY_SIZE(cookieW); cookie_set_to_string(&cookie_set, ptr); heap_free(cookie_set.cookies); @@ -730,7 +733,7 @@ BOOL WINAPI InternetGetCookieExW(LPCWSTR lpszUrl, LPCWSTR lpszCookieName, TRACE("(%s, %s, %p, %p, %x, %p)\n", debugstr_w(lpszUrl),debugstr_w(lpszCookieName), lpCookieData, lpdwSize, flags, reserved); - if (flags) + if (flags & ~INTERNET_COOKIE_HTTPONLY) FIXME("flags 0x%08x not supported\n", flags); if (!lpszUrl) @@ -949,7 +952,7 @@ DWORD set_cookie(substr_t domain, substr_t path, substr_t name, substr_t data, D if(!(end_ptr = memchrW(data.str, ';', data.len))) end_ptr = data.str + data.len; - if(data.len >= (len = sizeof(szDomain)/sizeof(WCHAR)) && !strncmpiW(data.str, szDomain, len)) { + if(data.len >= (len = ARRAY_SIZE(szDomain)) && !strncmpiW(data.str, szDomain, len)) { substr_skip(&data, len); if(data.len && *data.str == '.') @@ -960,17 +963,17 @@ DWORD set_cookie(substr_t domain, substr_t path, substr_t name, substr_t data, D domain = substr(data.str, end_ptr-data.str); TRACE("Parsing new domain %s\n", debugstr_wn(domain.str, domain.len)); - }else if(data.len >= (len = sizeof(szPath)/sizeof(WCHAR)) && !strncmpiW(data.str, szPath, len)) { + }else if(data.len >= (len = ARRAY_SIZE(szPath)) && !strncmpiW(data.str, szPath, len)) { substr_skip(&data, len); path = substr(data.str, end_ptr - data.str); TRACE("Parsing new path %s\n", debugstr_wn(path.str, path.len)); - }else if(data.len >= (len = sizeof(szExpires)/sizeof(WCHAR)) && !strncmpiW(data.str, szExpires, len)) { + }else if(data.len >= (len = ARRAY_SIZE(szExpires)) && !strncmpiW(data.str, szExpires, len)) { SYSTEMTIME st; WCHAR buf[128]; substr_skip(&data, len); - if(end_ptr - data.str < sizeof(buf)/sizeof(WCHAR)-1) { + if(end_ptr - data.str < ARRAY_SIZE(buf)-1) { memcpy(buf, data.str, data.len*sizeof(WCHAR)); buf[data.len] = 0; @@ -983,10 +986,10 @@ DWORD set_cookie(substr_t domain, substr_t path, substr_t name, substr_t data, D } } } - }else if(data.len >= (len = sizeof(szSecure)/sizeof(WCHAR)) && !strncmpiW(data.str, szSecure, len)) { + }else if(data.len >= (len = ARRAY_SIZE(szSecure)) && !strncmpiW(data.str, szSecure, len)) { substr_skip(&data, len); FIXME("secure not handled\n"); - }else if(data.len >= (len = sizeof(szHttpOnly)/sizeof(WCHAR)) && !strncmpiW(data.str, szHttpOnly, len)) { + }else if(data.len >= (len = ARRAY_SIZE(szHttpOnly)) && !strncmpiW(data.str, szHttpOnly, len)) { substr_skip(&data, len); if(!(flags & INTERNET_COOKIE_HTTPONLY)) { @@ -996,11 +999,11 @@ DWORD set_cookie(substr_t domain, substr_t path, substr_t name, substr_t data, D } cookie_flags |= INTERNET_COOKIE_HTTPONLY; - }else if(data.len >= (len = sizeof(szVersion)/sizeof(WCHAR)) && !strncmpiW(data.str, szVersion, len)) { + }else if(data.len >= (len = ARRAY_SIZE(szVersion)) && !strncmpiW(data.str, szVersion, len)) { substr_skip(&data, len); FIXME("version not handled (%s)\n",debugstr_wn(data.str, data.len)); - }else if(data.len >= (len = sizeof(max_ageW)/sizeof(WCHAR)) && !strncmpiW(data.str, max_ageW, len)) { + }else if(data.len >= (len = ARRAY_SIZE(max_ageW)) && !strncmpiW(data.str, max_ageW, len)) { /* Native doesn't support Max-Age attribute. */ WARN("Max-Age ignored\n"); }else if(data.len) { diff --git a/dll/win32/wininet/dialogs.c b/dll/win32/wininet/dialogs.c index b13b566a8eb..5e26c8b7b4d 100644 --- a/dll/win32/wininet/dialogs.c +++ b/dll/win32/wininet/dialogs.c @@ -135,12 +135,10 @@ static BOOL WININET_GetSetPassword( HWND hdlg, LPCWSTR szServer, if( bSet ) { szUserPass[0] = 0; - GetWindowTextW( hUserItem, szUserPass, - (sizeof szUserPass-1)/sizeof(WCHAR) ); + GetWindowTextW( hUserItem, szUserPass, ARRAY_SIZE( szUserPass ) - 1 ); lstrcatW(szUserPass, szColon); u_len = strlenW( szUserPass ); - GetWindowTextW( hPassItem, szUserPass+u_len, - (sizeof szUserPass)/sizeof(WCHAR)-u_len ); + GetWindowTextW( hPassItem, szUserPass+u_len, ARRAY_SIZE( szUserPass ) - u_len ); r_len = (strlenW( szResource ) + 1)*sizeof(WCHAR); u_len = (strlenW( szUserPass ) + 1)*sizeof(WCHAR); @@ -218,7 +216,7 @@ static INT_PTR WINAPI WININET_ProxyPasswordDialog( { HWND hitem; struct WININET_ErrorDlgParams *params; - WCHAR szRealm[0x80], szServer[0x80]; + WCHAR szRealm[0x80]; if( uMsg == WM_INITDIALOG ) { @@ -230,7 +228,7 @@ static INT_PTR WINAPI WININET_ProxyPasswordDialog( /* extract the Realm from the proxy response and show it */ if( WININET_GetAuthRealm( params->req->hdr.hInternet, - szRealm, sizeof szRealm/sizeof(WCHAR), TRUE ) ) + szRealm, ARRAY_SIZE( szRealm ), TRUE ) ) { hitem = GetDlgItem( hdlg, IDC_REALM ); SetWindowTextW( hitem, szRealm ); @@ -239,7 +237,7 @@ static INT_PTR WINAPI WININET_ProxyPasswordDialog( hitem = GetDlgItem( hdlg, IDC_PROXY ); SetWindowTextW( hitem, params->req->session->appInfo->proxy ); - WININET_GetSetPassword( hdlg, szServer, szRealm, FALSE ); + WININET_GetSetPassword( hdlg, params->req->session->appInfo->proxy, szRealm, FALSE ); return TRUE; } @@ -257,18 +255,18 @@ static INT_PTR WINAPI WININET_ProxyPasswordDialog( username[0] = 0; hitem = GetDlgItem( hdlg, IDC_USERNAME ); if( hitem ) - GetWindowTextW( hitem, username, sizeof username/sizeof(WCHAR) ); - + GetWindowTextW( hitem, username, ARRAY_SIZE( username )); + password[0] = 0; hitem = GetDlgItem( hdlg, IDC_PASSWORD ); if( hitem ) - GetWindowTextW( hitem, password, sizeof password/sizeof(WCHAR) ); + GetWindowTextW( hitem, password, ARRAY_SIZE( password )); hitem = GetDlgItem( hdlg, IDC_SAVEPASSWORD ); if( hitem && SendMessageW( hitem, BM_GETSTATE, 0, 0 ) && WININET_GetAuthRealm( params->req->hdr.hInternet, - szRealm, sizeof szRealm/sizeof(WCHAR), TRUE) ) + szRealm, ARRAY_SIZE( szRealm ), TRUE) ) WININET_GetSetPassword( hdlg, params->req->session->appInfo->proxy, szRealm, TRUE ); WININET_SetAuthorization( params->req, username, password, TRUE ); @@ -293,7 +291,7 @@ static INT_PTR WINAPI WININET_PasswordDialog( { HWND hitem; struct WININET_ErrorDlgParams *params; - WCHAR szRealm[0x80], szServer[0x80]; + WCHAR szRealm[0x80]; if( uMsg == WM_INITDIALOG ) { @@ -305,7 +303,7 @@ static INT_PTR WINAPI WININET_PasswordDialog( /* extract the Realm from the response and show it */ if( WININET_GetAuthRealm( params->req->hdr.hInternet, - szRealm, sizeof szRealm/sizeof(WCHAR), FALSE ) ) + szRealm, ARRAY_SIZE( szRealm ), FALSE ) ) { hitem = GetDlgItem( hdlg, IDC_REALM ); SetWindowTextW( hitem, szRealm ); @@ -314,7 +312,7 @@ static INT_PTR WINAPI WININET_PasswordDialog( hitem = GetDlgItem( hdlg, IDC_SERVER ); SetWindowTextW( hitem, params->req->session->hostName ); - WININET_GetSetPassword( hdlg, szServer, szRealm, FALSE ); + WININET_GetSetPassword( hdlg, params->req->session->hostName, szRealm, FALSE ); return TRUE; } @@ -332,18 +330,18 @@ static INT_PTR WINAPI WININET_PasswordDialog( username[0] = 0; hitem = GetDlgItem( hdlg, IDC_USERNAME ); if( hitem ) - GetWindowTextW( hitem, username, sizeof username/sizeof(WCHAR) ); + GetWindowTextW( hitem, username, ARRAY_SIZE( username )); password[0] = 0; hitem = GetDlgItem( hdlg, IDC_PASSWORD ); if( hitem ) - GetWindowTextW( hitem, password, sizeof password/sizeof(WCHAR) ); + GetWindowTextW( hitem, password, ARRAY_SIZE( password )); hitem = GetDlgItem( hdlg, IDC_SAVEPASSWORD ); if( hitem && SendMessageW( hitem, BM_GETSTATE, 0, 0 ) && WININET_GetAuthRealm( params->req->hdr.hInternet, - szRealm, sizeof szRealm/sizeof(WCHAR), FALSE )) + szRealm, ARRAY_SIZE( szRealm ), FALSE )) { WININET_GetSetPassword( hdlg, params->req->session->hostName, szRealm, TRUE ); } diff --git a/dll/win32/wininet/ftp.c b/dll/win32/wininet/ftp.c index e12e4941605..f2a88b741ea 100644 --- a/dll/win32/wininet/ftp.c +++ b/dll/win32/wininet/ftp.c @@ -2581,8 +2581,7 @@ HINTERNET FTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName, lerror: if (!bSuccess) { - if(lpwfs) - WININET_Release( &lpwfs->hdr ); + WININET_Release(&lpwfs->hdr); return NULL; } @@ -3746,7 +3745,7 @@ static BOOL FTP_ParseNextFile(INT nSocket, LPCWSTR lpszSearchFile, LPFILEPROPERT pszToken = strtok(NULL, szSpace); if(!pszToken) continue; - if(!strcasecmp(pszToken, "<DIR>")) { + if(!_strnicmp(pszToken, "<DIR>", -1)) { lpfp->bIsDirectory = TRUE; lpfp->nSize = 0; TRACE("Is directory\n"); diff --git a/dll/win32/wininet/http.c b/dll/win32/wininet/http.c index 35ea56ba9a5..45036f2fe56 100644 --- a/dll/win32/wininet/http.c +++ b/dll/win32/wininet/http.c @@ -42,6 +42,8 @@ #include <stdio.h> #include <time.h> #include <assert.h> +#include <errno.h> +#include <limits.h> #include "windef.h" #include "winbase.h" @@ -50,7 +52,6 @@ #include "winternl.h" #define NO_SHLWAPI_STREAM #define NO_SHLWAPI_REG -#define NO_SHLWAPI_STRFCNS #define NO_SHLWAPI_GDI #include "shlwapi.h" #include "sspi.h" @@ -137,7 +138,6 @@ static const WCHAR emptyW[] = {0}; #define HTTP_ADDHDR_FLAG_ADD 0x20000000 #define HTTP_ADDHDR_FLAG_ADD_IF_NEW 0x10000000 -#define HTTP_ADDHDR_FLAG_COALESCE 0x40000000 #define HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA 0x40000000 #define HTTP_ADDHDR_FLAG_COALESCE_WITH_SEMICOLON 0x01000000 #define HTTP_ADDHDR_FLAG_REPLACE 0x80000000 @@ -145,9 +145,6 @@ static const WCHAR emptyW[] = {0}; #define COLLECT_TIME 60000 -#undef ARRAYSIZE -#define ARRAYSIZE(array) (sizeof(array)/sizeof((array)[0])) - struct HttpAuthInfo { LPWSTR scheme; @@ -830,12 +827,12 @@ static inline BOOL is_basic_auth_value( LPCWSTR pszAuthValue, LPWSTR *pszRealm ) static const WCHAR szBasic[] = {'B','a','s','i','c'}; /* Note: not nul-terminated */ static const WCHAR szRealm[] = {'r','e','a','l','m'}; /* Note: not nul-terminated */ BOOL is_basic; - is_basic = !strncmpiW(pszAuthValue, szBasic, ARRAYSIZE(szBasic)) && - ((pszAuthValue[ARRAYSIZE(szBasic)] == ' ') || !pszAuthValue[ARRAYSIZE(szBasic)]); + is_basic = !strncmpiW(pszAuthValue, szBasic, ARRAY_SIZE(szBasic)) && + ((pszAuthValue[ARRAY_SIZE(szBasic)] == ' ') || !pszAuthValue[ARRAY_SIZE(szBasic)]); if (is_basic && pszRealm) { LPCWSTR token; - LPCWSTR ptr = &pszAuthValue[ARRAYSIZE(szBasic)]; + LPCWSTR ptr = &pszAuthValue[ARRAY_SIZE(szBasic)]; LPCWSTR realm; ptr++; *pszRealm=NULL; @@ -845,8 +842,8 @@ static inline BOOL is_basic_auth_value( LPCWSTR pszAuthValue, LPWSTR *pszRealm ) realm = ptr; while (*realm == ' ') realm++; - if(!strncmpiW(realm, szRealm, ARRAYSIZE(szRealm)) && - (realm[ARRAYSIZE(szRealm)] == ' ' || realm[ARRAYSIZE(szRealm)] == '=')) + if(!strncmpiW(realm, szRealm, ARRAY_SIZE(szRealm)) && + (realm[ARRAY_SIZE(szRealm)] == ' ' || realm[ARRAY_SIZE(szRealm)] == '=')) { token++; while (*token == ' ') @@ -875,7 +872,7 @@ static void destroy_authinfo( struct HttpAuthInfo *authinfo ) heap_free(authinfo); } -static UINT retrieve_cached_basic_authorization(const WCHAR *host, const WCHAR *realm, char **auth_data) +static UINT retrieve_cached_basic_authorization(http_request_t *req, const WCHAR *host, const WCHAR *realm, char **auth_data) { basicAuthorizationData *ad; UINT rc = 0; @@ -887,10 +884,24 @@ static UINT retrieve_cached_basic_authorization(const WCHAR *host, const WCHAR * { if (!strcmpiW(host, ad->host) && (!realm || !strcmpW(realm, ad->realm))) { + char *colon; + DWORD length; + TRACE("Authorization found in cache\n"); *auth_data = heap_alloc(ad->authorizationLen); memcpy(*auth_data,ad->authorization,ad->authorizationLen); rc = ad->authorizationLen; + + /* update session username and password to reflect current credentials */ + colon = strchr(ad->authorization, ':'); + length = colon - ad->authorization; + + heap_free(req->session->userName); + heap_free(req->session->password); + + req->session->userName = heap_strndupAtoW(ad->authorization, length, &length); + length++; + req->session->password = heap_strndupAtoW(&ad->authorization[length], ad->authorizationLen - length, &length); break; } } @@ -1027,6 +1038,37 @@ static void cache_authorization(LPWSTR host, LPWSTR scheme, LeaveCriticalSection(&authcache_cs); } +void free_authorization_cache(void) +{ + authorizationData *ad, *sa_safe; + basicAuthorizationData *basic, *basic_safe; + + EnterCriticalSection(&authcache_cs); + + LIST_FOR_EACH_ENTRY_SAFE(basic, basic_safe, &basicAuthorizationCache, basicAuthorizationData, entry) + { + heap_free(basic->host); + heap_free(basic->realm); + heap_free(basic->authorization); + + list_remove(&basic->entry); + heap_free(basic); + } + + LIST_FOR_EACH_ENTRY_SAFE(ad, sa_safe, &authorizationCache, authorizationData, entry) + { + heap_free(ad->host); + heap_free(ad->scheme); + heap_free(ad->user); + heap_free(ad->password); + heap_free(ad->domain); + list_remove(&ad->entry); + heap_free(ad); + } + + LeaveCriticalSection(&authcache_cs); +} + static BOOL HTTP_DoAuthorization( http_request_t *request, LPCWSTR pszAuthValue, struct HttpAuthInfo **ppAuthInfo, LPWSTR domain_and_username, LPWSTR password, @@ -1166,7 +1208,7 @@ static BOOL HTTP_DoAuthorization( http_request_t *request, LPCWSTR pszAuthValue, if (!domain_and_username) { if (host && szRealm) - auth_data_len = retrieve_cached_basic_authorization(host, szRealm,&auth_data); + auth_data_len = retrieve_cached_basic_authorization(request, host, szRealm,&auth_data); if (auth_data_len == 0) { heap_free(szRealm); @@ -1357,7 +1399,7 @@ BOOL WINAPI HttpAddRequestHeadersW(HINTERNET hHttpRequest, http_request_t *request; DWORD res = ERROR_INTERNET_INCORRECT_HANDLE_TYPE; - TRACE("%p, %s, %i, %i\n", hHttpRequest, debugstr_wn(lpszHeader, dwHeaderLength), dwHeaderLength, dwModifier); + TRACE("%p, %s, %u, %08x\n", hHttpRequest, debugstr_wn(lpszHeader, dwHeaderLength), dwHeaderLength, dwModifier); if (!lpszHeader) return TRUE; @@ -1389,7 +1431,7 @@ BOOL WINAPI HttpAddRequestHeadersA(HINTERNET hHttpRequest, WCHAR *headers = NULL; BOOL r; - TRACE("%p, %s, %i, %i\n", hHttpRequest, debugstr_an(lpszHeader, dwHeaderLength), dwHeaderLength, dwModifier); + TRACE("%p, %s, %u, %08x\n", hHttpRequest, debugstr_an(lpszHeader, dwHeaderLength), dwHeaderLength, dwModifier); if(lpszHeader) headers = heap_strndupAtoW(lpszHeader, dwHeaderLength, &dwHeaderLength); @@ -1586,9 +1628,9 @@ static UINT HTTP_DecodeBase64( LPCWSTR base64, LPSTR bin ) { signed char in[4]; - if (base64[0] >= ARRAYSIZE(HTTP_Base64Dec) || + if (base64[0] >= ARRAY_SIZE(HTTP_Base64Dec) || ((in[0] = HTTP_Base64Dec[base64[0]]) == -1) || - base64[1] >= ARRAYSIZE(HTTP_Base64Dec) || + base64[1] >= ARRAY_SIZE(HTTP_Base64Dec) || ((in[1] = HTTP_Base64Dec[base64[1]]) == -1)) { WARN("invalid base64: %s\n", debugstr_w(base64)); @@ -1600,7 +1642,7 @@ static UINT HTTP_DecodeBase64( LPCWSTR base64, LPSTR bin ) if ((base64[2] == '=') && (base64[3] == '=')) break; - if (base64[2] > ARRAYSIZE(HTTP_Base64Dec) || + if (base64[2] > ARRAY_SIZE(HTTP_Base64Dec) || ((in[2] = HTTP_Base64Dec[base64[2]]) == -1)) { WARN("invalid base64: %s\n", debugstr_w(&base64[2])); @@ -1612,7 +1654,7 @@ static UINT HTTP_DecodeBase64( LPCWSTR base64, LPSTR bin ) if (base64[3] == '=') break; - if (base64[3] > ARRAYSIZE(HTTP_Base64Dec) || + if (base64[3] > ARRAY_SIZE(HTTP_Base64Dec) || ((in[3] = HTTP_Base64Dec[base64[3]]) == -1)) { WARN("invalid base64: %s\n", debugstr_w(&base64[3])); @@ -1677,12 +1719,19 @@ static BOOL HTTP_InsertAuthorization( http_request_t *request, struct HttpAuthIn HTTP_ADDHDR_FLAG_REQ | HTTP_ADDHDR_FLAG_REPLACE | HTTP_ADDREQ_FLAG_ADD); heap_free(authorization); } - else if (!strcmpW(header, szAuthorization) && (host = get_host_header(request))) + else { UINT data_len; char *data; - if ((data_len = retrieve_cached_basic_authorization(host, NULL, &data))) + /* Don't use cached credentials when a username or Authorization was specified */ + if ((request->session->userName && request->session->userName[0]) || strcmpW(header, szAuthorization)) + return TRUE; + + if (!(host = get_host_header(request))) + return TRUE; + + if ((data_len = retrieve_cached_basic_authorization(request, host, NULL, &data))) { TRACE("Found cached basic authorization for %s\n", debugstr_w(host)); @@ -1734,7 +1783,7 @@ static BOOL HTTP_DomainMatches(LPCWSTR server, substr_t domain) const WCHAR *dot, *ptr; int len; - if(domain.len == sizeof(localW)/sizeof(WCHAR)-1 && !strncmpiW(domain.str, localW, domain.len) && !strchrW(server, '.' )) + if(domain.len == ARRAY_SIZE(localW)-1 && !strncmpiW(domain.str, localW, domain.len) && !strchrW(server, '.' )) return TRUE; if(domain.len && *domain.str != '*') @@ -2294,6 +2343,15 @@ static DWORD HTTPREQ_QueryOption(object_header_t *hdr, DWORD option, void *buffe *(DWORD*)buffer = flags; return ERROR_SUCCESS; } + case INTERNET_OPTION_ERROR_MASK: + TRACE("INTERNET_OPTION_ERROR_MASK\n"); + + if (*size < sizeof(ULONG)) + return ERROR_INSUFFICIENT_BUFFER; + + *(ULONG*)buffer = hdr->ErrorMask; + *size = sizeof(ULONG); + return ERROR_SUCCESS; } return INET_QueryOption(hdr, option, buffer, size, unicode); @@ -2431,8 +2489,8 @@ static void create_cache_entry(http_request_t *req) if(!end) end = ptr + strlenW(ptr); - if(!strncmpiW(ptr, no_cacheW, sizeof(no_cacheW)/sizeof(*no_cacheW)-1) - || !strncmpiW(ptr, no_storeW, sizeof(no_storeW)/sizeof(*no_storeW)-1)) { + if(!strncmpiW(ptr, no_cacheW, ARRAY_SIZE(no_cacheW)-1) + || !strncmpiW(ptr, no_storeW, ARRAY_SIZE(no_storeW)-1)) { b = FALSE; break; } @@ -2459,7 +2517,7 @@ static void create_cache_entry(http_request_t *req) return; } - b = CreateUrlCacheEntryW(url, req->contentLength == ~0u ? 0 : req->contentLength, NULL, file_name, 0); + b = CreateUrlCacheEntryW(url, req->contentLength == ~0 ? 0 : req->contentLength, NULL, file_name, 0); if(!b) { WARN("Could not create cache entry: %08x\n", GetLastError()); return; @@ -2663,7 +2721,7 @@ static DWORD netconn_drain_content(data_stream_t *stream, http_request_t *req, B int len, res; size_t size; - if(netconn_stream->content_length == ~0u) + if(netconn_stream->content_length == ~0) return WSAEISCONN; while(netconn_stream->content_read < netconn_stream->content_length) { @@ -2769,7 +2827,7 @@ static DWORD chunked_read(data_stream_t *stream, http_request_t *req, BYTE *buf, TRACE("reading %u byte chunk\n", chunked_stream->chunk_size); chunked_stream->buf_size++; chunked_stream->buf_pos--; - if(req->contentLength == ~0u) req->contentLength = chunked_stream->chunk_size; + if(req->contentLength == ~0) req->contentLength = chunked_stream->chunk_size; else req->contentLength += chunked_stream->chunk_size; chunked_stream->state = CHUNKED_STREAM_STATE_DISCARD_EOL_AFTER_SIZE; } @@ -2891,6 +2949,7 @@ static DWORD set_content_length(http_request_t *request) { static const WCHAR szChunked[] = {'c','h','u','n','k','e','d',0}; static const WCHAR headW[] = {'H','E','A','D',0}; + WCHAR contentLength[32]; WCHAR encoding[20]; DWORD size; @@ -2899,10 +2958,13 @@ static DWORD set_content_length(http_request_t *request) return ERROR_SUCCESS; } - size = sizeof(request->contentLength); - if (HTTP_HttpQueryInfoW(request, HTTP_QUERY_FLAG_NUMBER|HTTP_QUERY_CONTENT_LENGTH, - &request->contentLength, &size, NULL) != ERROR_SUCCESS) - request->contentLength = ~0u; + size = sizeof(contentLength); + if (HTTP_HttpQueryInfoW(request, HTTP_QUERY_CONTENT_LENGTH, + contentLength, &size, NULL) != ERROR_SUCCESS || + !StrToInt64ExW(contentLength, STIF_DEFAULT, (LONGLONG*)&request->contentLength)) { + request->contentLength = ~0; + } + request->netconn_stream.content_length = request->contentLength; request->netconn_stream.content_read = request->read_size; @@ -2928,7 +2990,7 @@ static DWORD set_content_length(http_request_t *request) } request->data_stream = &chunked_stream->data_stream; - request->contentLength = ~0u; + request->contentLength = ~0; } if(request->hdr.decoding) { @@ -3318,7 +3380,7 @@ static DWORD HTTP_HttpOpenRequestW(http_session_t *session, request->hdr.dwFlags = dwFlags; request->hdr.dwContext = dwContext; request->hdr.decoding = session->hdr.decoding; - request->contentLength = ~0u; + request->contentLength = ~0; request->netconn_stream.data_stream.vtbl = &netconn_stream_vtbl; request->data_stream = &request->netconn_stream.data_stream; @@ -3536,8 +3598,6 @@ static const LPCWSTR header_lookup[] = { szUnless_Modified_Since, /* HTTP_QUERY_UNLESS_MODIFIED_SINCE = 70 */ }; -#define LAST_TABLE_HEADER (sizeof(header_lookup)/sizeof(header_lookup[0])) - /*********************************************************************** * HTTP_HttpQueryInfoW (internal) */ @@ -3723,9 +3783,9 @@ static DWORD HTTP_HttpQueryInfoW(http_request_t *request, DWORD dwInfoLevel, return res; } default: - assert (LAST_TABLE_HEADER == (HTTP_QUERY_UNLESS_MODIFIED_SINCE + 1)); + assert (ARRAY_SIZE(header_lookup) == (HTTP_QUERY_UNLESS_MODIFIED_SINCE + 1)); - if (level < LAST_TABLE_HEADER && header_lookup[level]) + if (level < ARRAY_SIZE(header_lookup) && header_lookup[level]) index = HTTP_GetCustomHeaderIndex(request, header_lookup[level], requested_index,request_only); } @@ -3745,9 +3805,25 @@ static DWORD HTTP_HttpQueryInfoW(http_request_t *request, DWORD dwInfoLevel, /* coalesce value to requested type */ if (dwInfoLevel & HTTP_QUERY_FLAG_NUMBER && lpBuffer) { - *(int *)lpBuffer = atoiW(lphttpHdr->lpszValue); - TRACE(" returning number: %d\n", *(int *)lpBuffer); - } + unsigned long value; + + if (*lpdwBufferLength != sizeof(DWORD)) + { + LeaveCriticalSection( &request->headers_section ); + return ERROR_HTTP_INVALID_HEADER; + } + + errno = 0; + value = strtoulW( lphttpHdr->lpszValue, NULL, 10 ); + if (value > UINT_MAX || (value == ULONG_MAX && errno == ERANGE)) + { + LeaveCriticalSection( &request->headers_section ); + return ERROR_HTTP_INVALID_HEADER; + } + + *(DWORD *)lpBuffer = value; + TRACE(" returning number: %u\n", *(DWORD *)lpBuffer); + } else if (dwInfoLevel & HTTP_QUERY_FLAG_SYSTEMTIME && lpBuffer) { time_t tmpTime; @@ -3896,18 +3972,18 @@ BOOL WINAPI HttpQueryInfoW(HINTERNET hHttpRequest, DWORD dwInfoLevel, TRACE("(%p, 0x%08x)--> %d\n", hHttpRequest, dwInfoLevel, info); TRACE(" Attribute:"); - for (i = 0; i < (sizeof(query_flags) / sizeof(query_flags[0])); i++) { + for (i = 0; i < ARRAY_SIZE(query_flags); i++) { if (query_flags[i].val == info) { TRACE(" %s", query_flags[i].name); break; } } - if (i == (sizeof(query_flags) / sizeof(query_flags[0]))) { + if (i == ARRAY_SIZE(query_flags)) { TRACE(" Unknown (%08x)", info); } TRACE(" Modifier:"); - for (i = 0; i < (sizeof(modifier_flags) / sizeof(modifier_flags[0])); i++) { + for (i = 0; i < ARRAY_SIZE(modifier_flags); i++) { if (modifier_flags[i].val & info_mod) { TRACE(" %s", modifier_flags[i].name); info_mod &= ~ modifier_flags[i].val; @@ -3937,8 +4013,8 @@ lend: WININET_Release( &request->hdr ); TRACE("%u <--\n", res); - if(res != ERROR_SUCCESS) - SetLastError(res); + + SetLastError(res); return res == ERROR_SUCCESS; } @@ -4233,7 +4309,7 @@ static WORD HTTP_ParseWkday(LPCWSTR day) { 'f','r','i',0 }, { 's','a','t',0 }}; unsigned int i; - for (i = 0; i < sizeof(days)/sizeof(*days); i++) + for (i = 0; i < ARRAY_SIZE(days); i++) if (!strcmpiW(day, days[i])) return i; @@ -4323,8 +4399,7 @@ static BOOL HTTP_ParseTime(SYSTEMTIME *st, LPCWSTR *str) ERR("unexpected second in time format %s\n", debugstr_w(ptr)); return FALSE; } - ptr = nextPtr + 1; - *str = ptr; + *str = nextPtr; st->wSecond = (WORD)num; return TRUE; } @@ -4338,7 +4413,7 @@ static BOOL HTTP_ParseDateAsAsctime(LPCWSTR value, FILETIME *ft) unsigned long num; for (ptr = value, dayPtr = day; *ptr && !isspaceW(*ptr) && - dayPtr - day < sizeof(day) / sizeof(day[0]) - 1; ptr++, dayPtr++) + dayPtr - day < ARRAY_SIZE(day) - 1; ptr++, dayPtr++) *dayPtr = *ptr; *dayPtr = 0; st.wDayOfWeek = HTTP_ParseWkday(day); @@ -4351,8 +4426,7 @@ static BOOL HTTP_ParseDateAsAsctime(LPCWSTR value, FILETIME *ft) while (isspaceW(*ptr)) ptr++; - for (monthPtr = month; !isspaceW(*ptr) && - monthPtr - month < sizeof(month) / sizeof(month[0]) - 1; + for (monthPtr = month; !isspaceW(*ptr) && monthPtr - month < ARRAY_SIZE(month) - 1; monthPtr++, ptr++) *monthPtr = *ptr; *monthPtr = 0; @@ -4448,8 +4522,7 @@ static BOOL HTTP_ParseRfc1123Date(LPCWSTR value, FILETIME *ft) while (isspaceW(*ptr)) ptr++; - for (monthPtr = month; !isspaceW(*ptr) && - monthPtr - month < sizeof(month) / sizeof(month[0]) - 1; + for (monthPtr = month; !isspaceW(*ptr) && monthPtr - month < ARRAY_SIZE(month) - 1; monthPtr++, ptr++) *monthPtr = *ptr; *monthPtr = 0; @@ -4496,7 +4569,7 @@ static WORD HTTP_ParseWeekday(LPCWSTR day) { 'f','r','i','d','a','y',0 }, { 's','a','t','u','r','d','a','y',0 }}; unsigned int i; - for (i = 0; i < sizeof(days)/sizeof(*days); i++) + for (i = 0; i < ARRAY_SIZE(days); i++) if (!strcmpiW(day, days[i])) return i; @@ -4526,7 +4599,7 @@ static BOOL HTTP_ParseRfc850Date(LPCWSTR value, FILETIME *ft) return FALSE; } } - else if (ptr - value < sizeof(day) / sizeof(day[0])) + else if (ptr - value < ARRAY_SIZE(day)) { memcpy(day, value, (ptr - value) * sizeof(WCHAR)); day[ptr - value + 1] = 0; @@ -4563,8 +4636,7 @@ static BOOL HTTP_ParseRfc850Date(LPCWSTR value, FILETIME *ft) } ptr++; - for (monthPtr = month; *ptr != '-' && - monthPtr - month < sizeof(month) / sizeof(month[0]) - 1; + for (monthPtr = month; *ptr != '-' && monthPtr - month < ARRAY_SIZE(month) - 1; monthPtr++, ptr++) *monthPtr = *ptr; *monthPtr = 0; @@ -4762,7 +4834,6 @@ static void http_process_keep_alive(http_request_t *req) static DWORD open_http_connection(http_request_t *request, BOOL *reusing) { - const BOOL is_https = (request->hdr.dwFlags & INTERNET_FLAG_SECURE) != 0; netconn_t *netconn = NULL; DWORD res; @@ -4817,7 +4888,7 @@ static DWORD open_http_connection(http_request_t *request, BOOL *reusing) request->server->addr_str, strlen(request->server->addr_str)+1); - res = create_netconn(is_https, request->proxy ? request->proxy : request->server, request->security_flags, + res = create_netconn(request->proxy ? request->proxy : request->server, request->security_flags, (request->hdr.ErrorMask & INTERNET_ERROR_MASK_COMBINED_SEC_CERT) != 0, request->connect_timeout, &netconn); if(res != ERROR_SUCCESS) { @@ -4853,7 +4924,7 @@ static void set_content_length_header( http_request_t *request, DWORD len, DWORD { static const WCHAR fmtW[] = {'C','o','n','t','e','n','t','-','L','e','n','g','t','h',':',' ','%','u','\r','\n',0}; - WCHAR buf[sizeof(fmtW)/sizeof(fmtW[0]) + 10]; + WCHAR buf[ARRAY_SIZE(fmtW) + 10]; sprintfW( buf, fmtW, len ); HTTP_HttpAddRequestHeadersW( request, buf, ~0u, flags ); @@ -4874,7 +4945,7 @@ static DWORD HTTP_HttpSendRequestW(http_request_t *request, LPCWSTR lpszHeaders, DWORD dwContentLength, BOOL bEndRequest) { BOOL redirected = FALSE, secure_proxy_connect = FALSE, loop_next; - LPWSTR requestString = NULL; + WCHAR *request_header = NULL; INT responseLen, cnt; DWORD res; @@ -4932,7 +5003,7 @@ static DWORD HTTP_HttpSendRequestW(http_request_t *request, LPCWSTR lpszHeaders, loop_next = FALSE; if(redirected) { - request->contentLength = ~0u; + request->contentLength = ~0; request->bytesToWrite = 0; } @@ -4984,12 +5055,12 @@ static DWORD HTTP_HttpSendRequestW(http_request_t *request, LPCWSTR lpszHeaders, if (HTTP_GetCustomHeaderIndex(request, szContent_Length, 0, TRUE) >= 0) set_content_length_header(request, 0, HTTP_ADDREQ_FLAG_REPLACE); - requestString = build_request_header(request, connectW, target, g_szHttp1_1, TRUE); + request_header = build_request_header(request, connectW, target, g_szHttp1_1, TRUE); } else if (request->proxy && !(request->hdr.dwFlags & INTERNET_FLAG_SECURE)) { WCHAR *url = build_proxy_path_url(request); - requestString = build_request_header(request, request->verb, url, request->version, TRUE); + request_header = build_request_header(request, request->verb, url, request->version, TRUE); heap_free(url); } else @@ -4997,16 +5068,17 @@ static DWORD HTTP_HttpSendRequestW(http_request_t *request, LPCWSTR lpszHeaders, if (request->proxy && HTTP_GetCustomHeaderIndex(request, szContent_Length, 0, TRUE) >= 0) set_content_length_header(request, dwContentLength, HTTP_ADDREQ_FLAG_REPLACE); - requestString = build_request_header(request, request->verb, request->path, request->version, TRUE); + request_header = build_request_header(request, request->verb, request->path, request->version, TRUE); } - TRACE("Request header -> %s\n", debugstr_w(requestString) ); + TRACE("Request header -> %s\n", debugstr_w(request_header) ); /* send the request as ASCII, tack on the optional data */ if (!lpOptional || redirected || secure_proxy_connect) data_len = 0; - ascii_req = build_ascii_request( requestString, lpOptional, data_len, &len ); + ascii_req = build_ascii_request(request_header, lpOptional, data_len, &len); + heap_free(request_header); TRACE("full request -> %s\n", debugstr_a(ascii_req) ); INTERNET_SendCallback(&request->hdr, request->hdr.dwContext, @@ -5089,10 +5161,8 @@ static DWORD HTTP_HttpSendRequestW(http_request_t *request, LPCWSTR lpszHeaders, http_release_netconn(request, drain_content(request, FALSE) == ERROR_SUCCESS); res = HTTP_HandleRedirect(request, new_url); heap_free(new_url); - if (res == ERROR_SUCCESS) { - heap_free(requestString); + if (res == ERROR_SUCCESS) loop_next = TRUE; - } redirected = TRUE; } } @@ -5111,7 +5181,6 @@ static DWORD HTTP_HttpSendRequestW(http_request_t *request, LPCWSTR lpszHeaders, request->session->userName, request->session->password, host)) { - heap_free(requestString); if (drain_content(request, TRUE) != ERROR_SUCCESS) { FIXME("Could not drain content\n"); @@ -5140,7 +5209,6 @@ static DWORD HTTP_HttpSendRequestW(http_request_t *request, LPCWSTR lpszHeaders, request->session->appInfo->proxyPassword, NULL)) { - heap_free(requestString); if (drain_content(request, TRUE) != ERROR_SUCCESS) { FIXME("Could not drain content\n"); @@ -5183,8 +5251,6 @@ static DWORD HTTP_HttpSendRequestW(http_request_t *request, LPCWSTR lpszHeaders, while (loop_next); lend: - heap_free(requestString); - /* TODO: send notification for P3P header */ if(res == ERROR_SUCCESS) @@ -5838,8 +5904,7 @@ DWORD HTTP_Connect(appinfo_t *hIC, LPCWSTR lpszServerName, session->hostName = heap_strdupW(lpszServerName); if (lpszUserName && lpszUserName[0]) session->userName = heap_strdupW(lpszUserName); - if (lpszPassword && lpszPassword[0]) - session->password = heap_strdupW(lpszPassword); + session->password = heap_strdupW(lpszPassword); session->hostPort = serverPort; session->connect_timeout = hIC->connect_timeout; session->send_timeout = 0; @@ -6083,7 +6148,7 @@ static LPWSTR * HTTP_InterpretHttpHeader(LPCWSTR buffer) * */ -#define COALESCEFLAGS (HTTP_ADDHDR_FLAG_COALESCE|HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA|HTTP_ADDHDR_FLAG_COALESCE_WITH_SEMICOLON) +#define COALESCEFLAGS (HTTP_ADDHDR_FLAG_COALESCE_WITH_COMMA|HTTP_ADDHDR_FLAG_COALESCE_WITH_SEMICOLON) static DWORD HTTP_ProcessHeader(http_request_t *request, LPCWSTR field, LPCWSTR value, DWORD dwModifier) { diff --git a/dll/win32/wininet/internet.c b/dll/win32/wininet/internet.c index 3df84d1d73f..fe45030c8c5 100644 --- a/dll/win32/wininet/internet.c +++ b/dll/win32/wininet/internet.c @@ -34,7 +34,6 @@ #include <CoreServices/CoreServices.h> #undef GetCurrentThread #undef LoadResource -#undef DPRINTF #endif #include "winsock2.h" @@ -777,7 +776,7 @@ static void dump_INTERNET_FLAGS(DWORD dwFlags) #undef FE unsigned int i; - for (i = 0; i < (sizeof(flag) / sizeof(flag[0])); i++) { + for (i = 0; i < ARRAY_SIZE(flag); i++) { if (flag[i].val & dwFlags) { TRACE(" %s", flag[i].name); dwFlags &= ~flag[i].val; @@ -1021,7 +1020,7 @@ HINTERNET WINAPI InternetOpenW(LPCWSTR lpszAgent, DWORD dwAccessType, TRACE("(%s, %i, %s, %s, %i)\n", debugstr_w(lpszAgent), dwAccessType, debugstr_w(lpszProxy), debugstr_w(lpszProxyBypass), dwFlags); - for (i = 0; i < (sizeof(access_type) / sizeof(access_type[0])); i++) { + for (i = 0; i < ARRAY_SIZE(access_type); i++) { if (access_type[i].val == dwAccessType) { access_type_str = access_type[i].name; break; @@ -1626,7 +1625,7 @@ static INTERNET_SCHEME GetInternetSchemeW(LPCWSTR lpszScheme, DWORD nMaxCmp) if(lpszScheme==NULL) return INTERNET_SCHEME_UNKNOWN; - for (i = 0; i < sizeof(url_schemes)/sizeof(url_schemes[0]); i++) + for (i = 0; i < ARRAY_SIZE(url_schemes); i++) if (!strncmpiW(lpszScheme, url_schemes[i], nMaxCmp)) return INTERNET_SCHEME_FIRST + i; @@ -2197,8 +2196,7 @@ BOOL WINAPI InternetReadFile(HINTERNET hFile, LPVOID lpBuffer, TRACE("-- %s (%u) (bytes read: %d)\n", res == ERROR_SUCCESS ? "TRUE": "FALSE", res, pdwNumOfBytesRead ? *pdwNumOfBytesRead : -1); - if(res != ERROR_SUCCESS) - SetLastError(res); + SetLastError(res); return res == ERROR_SUCCESS; } @@ -2836,6 +2834,7 @@ BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption, case INTERNET_OPTION_END_BROWSER_SESSION: FIXME("Option INTERNET_OPTION_END_BROWSER_SESSION: semi-stub\n"); free_cookie(); + free_authorization_cache(); break; case INTERNET_OPTION_CONNECTED_STATE: FIXME("Option INTERNET_OPTION_CONNECTED_STATE: STUB\n"); @@ -2880,7 +2879,6 @@ BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption, FIXME("Option INTERNET_OPTION_DISABLE_AUTODIAL; STUB\n"); break; case INTERNET_OPTION_HTTP_DECODING: - { if (!lpwhh) { SetLastError(ERROR_INTERNET_INCORRECT_HANDLE_TYPE); @@ -2894,7 +2892,6 @@ BOOL WINAPI InternetSetOptionW(HINTERNET hInternet, DWORD dwOption, else lpwhh->decoding = *(BOOL *)lpBuffer; break; - } case INTERNET_OPTION_COOKIES_3RD_PARTY: FIXME("INTERNET_OPTION_COOKIES_3RD_PARTY; STUB\n"); SetLastError(ERROR_INTERNET_INVALID_OPTION); @@ -4091,7 +4088,7 @@ static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme) if (scheme < INTERNET_SCHEME_FIRST) return NULL; index = scheme - INTERNET_SCHEME_FIRST; - if (index >= sizeof(url_schemes)/sizeof(url_schemes[0])) + if (index >= ARRAY_SIZE(url_schemes)) return NULL; return (LPCWSTR)url_schemes[index]; } @@ -4368,7 +4365,7 @@ BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags, if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName) { memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW)); - lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]); + lpszUrl += ARRAY_SIZE(slashSlashW); } if (lpUrlComponents->lpszUserName) diff --git a/dll/win32/wininet/internet.h b/dll/win32/wininet/internet.h index e80f6036f02..8954d071f9b 100644 --- a/dll/win32/wininet/internet.h +++ b/dll/win32/wininet/internet.h @@ -335,8 +335,8 @@ typedef struct { typedef struct { data_stream_t data_stream; - DWORD content_length; - DWORD content_read; + ULONGLONG content_length; + ULONGLONG content_read; } netconn_stream_t; #define READ_BUFFER_SIZE 8192 @@ -372,7 +372,7 @@ typedef struct struct HttpAuthInfo *proxyAuthInfo; CRITICAL_SECTION read_section; /* section to protect the following fields */ - DWORD contentLength; /* total number of bytes to be read */ + ULONGLONG contentLength; /* total number of bytes to be read */ BOOL read_gzip; /* are we reading in gzip mode? */ DWORD read_pos; /* current read position in read_buf */ DWORD read_size; /* valid data size in read_buf */ @@ -428,7 +428,7 @@ VOID INTERNET_SendCallback(object_header_t *hdr, DWORD_PTR dwContext, DWORD dwStatusInfoLength) DECLSPEC_HIDDEN; WCHAR *INTERNET_FindProxyForProtocol(LPCWSTR szProxy, LPCWSTR proto) DECLSPEC_HIDDEN; -DWORD create_netconn(BOOL,server_t*,DWORD,BOOL,DWORD,netconn_t**) DECLSPEC_HIDDEN; +DWORD create_netconn(server_t*,DWORD,BOOL,DWORD,netconn_t**) DECLSPEC_HIDDEN; void free_netconn(netconn_t*) DECLSPEC_HIDDEN; void NETCON_unload(void) DECLSPEC_HIDDEN; DWORD NETCON_secure_connect(netconn_t*,server_t*) DECLSPEC_HIDDEN; @@ -456,6 +456,7 @@ static inline req_file_t *req_file_addref(req_file_t *req_file) BOOL init_urlcache(void) DECLSPEC_HIDDEN; void free_urlcache(void) DECLSPEC_HIDDEN; void free_cookie(void) DECLSPEC_HIDDEN; +void free_authorization_cache(void) DECLSPEC_HIDDEN; void init_winsock(void) DECLSPEC_HIDDEN; diff --git a/dll/win32/wininet/netconnection.c b/dll/win32/wininet/netconnection.c index b91c6be8dc6..d177d98a2a4 100644 --- a/dll/win32/wininet/netconnection.c +++ b/dll/win32/wininet/netconnection.c @@ -340,7 +340,7 @@ static DWORD create_netconn_socket(server_t *server, netconn_t *netconn, DWORD t return ERROR_SUCCESS; } -DWORD create_netconn(BOOL useSSL, server_t *server, DWORD security_flags, BOOL mask_errors, DWORD timeout, netconn_t **ret) +DWORD create_netconn(server_t *server, DWORD security_flags, BOOL mask_errors, DWORD timeout, netconn_t **ret) { netconn_t *netconn; int result; @@ -392,9 +392,9 @@ void free_netconn(netconn_t *netconn) heap_free(netconn->extra_buf); netconn->extra_buf = NULL; netconn->extra_len = 0; - if (SecIsValidHandle(&netconn->ssl_ctx)) - DeleteSecurityContext(&netconn->ssl_ctx); } + if (SecIsValidHandle(&netconn->ssl_ctx)) + DeleteSecurityContext(&netconn->ssl_ctx); close_netconn(netconn); heap_free(netconn); @@ -639,7 +639,7 @@ static BOOL send_ssl_chunk(netconn_t *conn, const void *msg, size_t size) {conn->ssl_sizes.cbTrailer, SECBUFFER_STREAM_TRAILER, conn->ssl_buf+conn->ssl_sizes.cbHeader+size}, {0, SECBUFFER_EMPTY, NULL} }; - SecBufferDesc buf_desc = {SECBUFFER_VERSION, sizeof(bufs)/sizeof(*bufs), bufs}; + SecBufferDesc buf_desc = {SECBUFFER_VERSION, ARRAY_SIZE(bufs), bufs}; SECURITY_STATUS res; memcpy(bufs[1].pvBuffer, msg, size); @@ -698,7 +698,7 @@ static BOOL read_ssl_chunk(netconn_t *conn, void *buf, SIZE_T buf_size, BOOL blo { const SIZE_T ssl_buf_size = conn->ssl_sizes.cbHeader+conn->ssl_sizes.cbMaximumMessage+conn->ssl_sizes.cbTrailer; SecBuffer bufs[4]; - SecBufferDesc buf_desc = {SECBUFFER_VERSION, sizeof(bufs)/sizeof(*bufs), bufs}; + SecBufferDesc buf_desc = {SECBUFFER_VERSION, ARRAY_SIZE(bufs), bufs}; SSIZE_T size, buf_len = 0; int i; SECURITY_STATUS res; @@ -781,7 +781,7 @@ static BOOL read_ssl_chunk(netconn_t *conn, void *buf, SIZE_T buf_size, BOOL blo } } while(res != SEC_E_OK); - for(i=0; i < sizeof(bufs)/sizeof(*bufs); i++) { + for(i = 0; i < ARRAY_SIZE(bufs); i++) { if(bufs[i].BufferType == SECBUFFER_DATA) { size = min(buf_size, bufs[i].cbBuffer); memcpy(buf, bufs[i].pvBuffer, size); @@ -798,7 +798,7 @@ static BOOL read_ssl_chunk(netconn_t *conn, void *buf, SIZE_T buf_size, BOOL blo } } - for(i=0; i < sizeof(bufs)/sizeof(*bufs); i++) { + for(i = 0; i < ARRAY_SIZE(bufs); i++) { if(bufs[i].BufferType == SECBUFFER_EXTRA) { conn->extra_buf = heap_alloc(bufs[i].cbBuffer); if(!conn->extra_buf) diff --git a/dll/win32/wininet/urlcache.c b/dll/win32/wininet/urlcache.c index 30a469a93a1..40e2afa49b8 100644 --- a/dll/win32/wininet/urlcache.c +++ b/dll/win32/wininet/urlcache.c @@ -23,6 +23,7 @@ */ #define NONAMELESSUNION +#define NONAMELESSSTRUCT #include "ws2tcpip.h" @@ -777,7 +778,7 @@ static void cache_containers_init(void) return; } - for (i = 0; i < sizeof(DefaultContainerData) / sizeof(DefaultContainerData[0]); i++) + for (i = 0; i < ARRAY_SIZE(DefaultContainerData); i++) { WCHAR wszCachePath[MAX_PATH]; WCHAR wszMutexName[MAX_PATH]; @@ -1505,12 +1506,12 @@ static DWORD urlcache_hash_key(LPCSTR lpszKey) BYTE key[4]; DWORD i; - for (i = 0; i < sizeof(key) / sizeof(key[0]); i++) + for (i = 0; i < ARRAY_SIZE(key); i++) key[i] = lookupTable[(*lpszKey + i) & 0xFF]; for (lpszKey++; *lpszKey; lpszKey++) { - for (i = 0; i < sizeof(key) / sizeof(key[0]); i++) + for (i = 0; i < ARRAY_SIZE(key); i++) key[i] = lookupTable[*lpszKey ^ key[i]]; } @@ -2468,7 +2469,7 @@ BOOL WINAPI FreeUrlCacheSpaceW(LPCWSTR cache_path, DWORD size, DWORD filter) hash_table_entry = 0; rate_no = 0; GetSystemTimeAsFileTime(&cur_time); - while(rate_no<sizeof(rate)/sizeof(*rate) && + while(rate_no < ARRAY_SIZE(rate) && urlcache_next_entry(header, &hash_table_off, &hash_table_entry, &hash_entry, &entry)) { if(entry->signature != URL_SIGNATURE) { WARN("only url entries are currently supported\n"); @@ -3788,24 +3789,111 @@ BOOL WINAPI SetUrlCacheEntryGroupW(LPCWSTR lpszUrlName, DWORD dwFlags, return FALSE; } +static cache_container *find_container(DWORD flags) +{ + cache_container *container; + + LIST_FOR_EACH_ENTRY(container, &UrlContainers, cache_container, entry) + { + switch (flags & (CACHE_CONFIG_CONTENT_PATHS_FC | CACHE_CONFIG_COOKIES_PATHS_FC | CACHE_CONFIG_HISTORY_PATHS_FC)) + { + case 0: + case CACHE_CONFIG_CONTENT_PATHS_FC: + if (container->default_entry_type == NORMAL_CACHE_ENTRY) + return container; + break; + + case CACHE_CONFIG_COOKIES_PATHS_FC: + if (container->default_entry_type == COOKIE_CACHE_ENTRY) + return container; + break; + + case CACHE_CONFIG_HISTORY_PATHS_FC: + if (container->default_entry_type == URLHISTORY_CACHE_ENTRY) + return container; + break; + + default: + FIXME("flags %08x not handled\n", flags); + break; + } + } + + return NULL; +} + /*********************************************************************** * GetUrlCacheConfigInfoW (WININET.@) */ -BOOL WINAPI GetUrlCacheConfigInfoW(LPINTERNET_CACHE_CONFIG_INFOW CacheInfo, LPDWORD size, DWORD bitmask) +BOOL WINAPI GetUrlCacheConfigInfoW(LPINTERNET_CACHE_CONFIG_INFOW info, LPDWORD size, DWORD flags) { - FIXME("(%p, %p, %x)\n", CacheInfo, size, bitmask); - INTERNET_SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; + cache_container *container; + DWORD error; + + FIXME("(%p, %p, %x): semi-stub\n", info, size, flags); + + if (!info || !(container = find_container(flags))) + { + INTERNET_SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + error = cache_container_open_index(container, MIN_BLOCK_NO); + if (error != ERROR_SUCCESS) + { + INTERNET_SetLastError(error); + return FALSE; + } + + info->dwContainer = 0; + info->dwQuota = FILE_SIZE(MAX_BLOCK_NO) / 1024; + info->dwReserved4 = 0; + info->fPerUser = TRUE; + info->dwSyncMode = 0; + info->dwNumCachePaths = 1; + info->dwNormalUsage = 0; + info->dwExemptUsage = 0; + info->u.s.dwCacheSize = container->file_size / 1024; + lstrcpynW(info->u.s.CachePath, container->path, MAX_PATH); + + cache_container_close_index(container); + + TRACE("CachePath %s\n", debugstr_w(info->u.s.CachePath)); + + return TRUE; } /*********************************************************************** * GetUrlCacheConfigInfoA (WININET.@) */ -BOOL WINAPI GetUrlCacheConfigInfoA(LPINTERNET_CACHE_CONFIG_INFOA CacheInfo, LPDWORD size, DWORD bitmask) +BOOL WINAPI GetUrlCacheConfigInfoA(LPINTERNET_CACHE_CONFIG_INFOA info, LPDWORD size, DWORD flags) { - FIXME("(%p, %p, %x)\n", CacheInfo, size, bitmask); - INTERNET_SetLastError(ERROR_INVALID_PARAMETER); - return FALSE; + INTERNET_CACHE_CONFIG_INFOW infoW; + + TRACE("(%p, %p, %x)\n", info, size, flags); + + if (!info) + { + INTERNET_SetLastError(ERROR_INVALID_PARAMETER); + return FALSE; + } + + infoW.dwStructSize = sizeof(infoW); + if (!GetUrlCacheConfigInfoW(&infoW, size, flags)) + return FALSE; + + info->dwContainer = infoW.dwContainer; + info->dwQuota = infoW.dwQuota; + info->dwReserved4 = infoW.dwReserved4; + info->fPerUser = infoW.fPerUser; + info->dwSyncMode = infoW.dwSyncMode; + info->dwNumCachePaths = infoW.dwNumCachePaths; + info->dwNormalUsage = infoW.dwNormalUsage; + info->dwExemptUsage = infoW.dwExemptUsage; + info->u.s.dwCacheSize = infoW.u.s.dwCacheSize; + WideCharToMultiByte(CP_ACP, 0, infoW.u.s.CachePath, -1, info->u.s.CachePath, MAX_PATH, NULL, NULL); + + return TRUE; } BOOL WINAPI GetUrlCacheGroupAttributeA( GROUPID gid, DWORD dwFlags, DWORD dwAttributes, diff --git a/dll/win32/wininet/utility.c b/dll/win32/wininet/utility.c index 0e67da98db0..1853e398f47 100644 --- a/dll/win32/wininet/utility.c +++ b/dll/win32/wininet/utility.c @@ -219,7 +219,7 @@ static const char *get_callback_name(DWORD dwInternetStatus) { }; DWORD i; - for (i = 0; i < (sizeof(internet_status) / sizeof(internet_status[0])); i++) { + for (i = 0; i < ARRAY_SIZE(internet_status); i++) { if (internet_status[i].val == dwInternetStatus) return internet_status[i].name; } return "Unknown"; diff --git a/media/doc/README.WINE b/media/doc/README.WINE index c6c62324999..e27bd33f0e5 100644 --- a/media/doc/README.WINE +++ b/media/doc/README.WINE @@ -202,7 +202,7 @@ dll/win32/windowscodecsext # Synced to WineStaging-2.9 dll/win32/winemp3.acm # Synced to WineStaging-4.18 dll/win32/wing32 # Synced to WineStaging-3.3 dll/win32/winhttp # Synced to WineStaging-4.18 -dll/win32/wininet # Synced to WineStaging-3.9 +dll/win32/wininet # Synced to WineStaging-4.18 dll/win32/winmm # Forked at Wine-20050628 dll/win32/winmm/midimap # Forked at Wine-20050628 dll/win32/winmm/wavemap # Forked at Wine-20050628
1
0
0
0
[reactos] 01/01: [WINHTTP_WINETEST] Sync with Wine Staging 4.18. CORE-16441
by Amine Khaldi
07 Dec '19
07 Dec '19
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=412bce85f2833c30750d7…
commit 412bce85f2833c30750d7bf0129185ffbfd40f84 Author: Amine Khaldi <amine.khaldi(a)reactos.org> AuthorDate: Sat Dec 7 13:06:11 2019 +0100 Commit: Amine Khaldi <amine.khaldi(a)reactos.org> CommitDate: Sat Dec 7 13:06:11 2019 +0100 [WINHTTP_WINETEST] Sync with Wine Staging 4.18. CORE-16441 --- modules/rostests/winetests/winhttp/notification.c | 27 +- modules/rostests/winetests/winhttp/url.c | 111 +++++- modules/rostests/winetests/winhttp/winhttp.c | 466 +++++++++++++++++++--- 3 files changed, 536 insertions(+), 68 deletions(-) diff --git a/modules/rostests/winetests/winhttp/notification.c b/modules/rostests/winetests/winhttp/notification.c index 494d474df46..75bfc648808 100644 --- a/modules/rostests/winetests/winhttp/notification.c +++ b/modules/rostests/winetests/winhttp/notification.c @@ -187,7 +187,7 @@ static void test_connection_cache( void ) struct info info, *context = &info; info.test = cache_test; - info.count = sizeof(cache_test) / sizeof(cache_test[0]); + info.count = ARRAY_SIZE( cache_test ); info.index = 0; info.wait = CreateEventW( NULL, FALSE, FALSE, NULL ); @@ -427,7 +427,7 @@ static void test_redirect( void ) struct info info, *context = &info; info.test = redirect_test; - info.count = sizeof(redirect_test) / sizeof(redirect_test[0]); + info.count = ARRAY_SIZE( redirect_test ); info.index = 0; info.wait = CreateEventW( NULL, FALSE, FALSE, NULL ); @@ -508,7 +508,7 @@ static void test_async( void ) char buffer[1024]; info.test = async_test; - info.count = sizeof(async_test) / sizeof(async_test[0]); + info.count = ARRAY_SIZE( async_test ); info.index = 0; info.wait = CreateEventW( NULL, FALSE, FALSE, NULL ); @@ -779,12 +779,12 @@ static void open_async_request(int port, struct test_request *req, struct info * if (reuse_connection) { info->test = reuse_socket_request_test; - info->count = sizeof(reuse_socket_request_test) / sizeof(reuse_socket_request_test[0]); + info->count = ARRAY_SIZE( reuse_socket_request_test ); } else { info->test = open_socket_request_test; - info->count = sizeof(open_socket_request_test) / sizeof(open_socket_request_test[0]); + info->count = ARRAY_SIZE( open_socket_request_test ); } req->session = WinHttpOpen( user_agent, 0, NULL, NULL, WINHTTP_FLAG_ASYNC ); @@ -830,7 +830,7 @@ static void server_send_reply(struct test_request *req, struct info *info, const WaitForSingleObject( info->wait, INFINITE ); info->test = server_reply_test; - info->count = sizeof(server_reply_test) / sizeof(server_reply_test[0]); + info->count = ARRAY_SIZE( server_reply_test ); info->index = 0; setup_test( info, winhttp_send_request, __LINE__ ); ret = WinHttpReceiveResponse( req->request, NULL ); @@ -879,12 +879,12 @@ static void close_request(struct test_request *req, struct info *info, BOOL allo if (allow_closing_connection) { info->test = close_allow_connection_close_request_test; - info->count = sizeof(close_allow_connection_close_request_test)/sizeof(*close_allow_connection_close_request_test); + info->count = ARRAY_SIZE( close_allow_connection_close_request_test ); } else { info->test = close_request_test; - info->count = sizeof(close_request_test)/sizeof(*close_request_test); + info->count = ARRAY_SIZE( close_request_test ); } info->index = 0; setup_test( info, winhttp_close_handle, __LINE__ ); @@ -920,25 +920,24 @@ static const struct notification read_allow_close_test[] = static void _read_request_data(struct test_request *req, struct info *info, const char *expected_data, BOOL closing_connection, unsigned line) { char buffer[1024]; - DWORD read, len; + DWORD len; BOOL ret; if (closing_connection) { info->test = read_allow_close_test; - info->count = sizeof(read_allow_close_test)/sizeof(*read_allow_close_test); + info->count = ARRAY_SIZE( read_allow_close_test ); } else { info->test = read_test; - info->count = sizeof(read_test)/sizeof(*read_test); + info->count = ARRAY_SIZE( read_test ); } info->index = 0; setup_test( info, winhttp_read_data, line ); memset(buffer, '?', sizeof(buffer)); - read = 0xdeadbeef; - ret = WinHttpReadData( req->request, buffer, sizeof(buffer), &read ); + ret = WinHttpReadData( req->request, buffer, sizeof(buffer), NULL ); ok(ret, "failed to read data %u\n", GetLastError()); WaitForSingleObject( info->wait, INFINITE ); @@ -1024,7 +1023,7 @@ START_TEST (notification) si.event = CreateEventW( NULL, 0, 0, NULL ); si.port = 7533; - thread = CreateThread( NULL, 0, server_thread, (LPVOID)&si, 0, NULL ); + thread = CreateThread( NULL, 0, server_thread, &si, 0, NULL ); ok(thread != NULL, "failed to create thread %u\n", GetLastError()); server_socket_available = CreateEventW( NULL, 0, 0, NULL ); diff --git a/modules/rostests/winetests/winhttp/url.c b/modules/rostests/winetests/winhttp/url.c index 6bde1de70e4..37a6e4a10b4 100644 --- a/modules/rostests/winetests/winhttp/url.c +++ b/modules/rostests/winetests/winhttp/url.c @@ -34,6 +34,9 @@ static WCHAR password[] = {'p','a','s','s','w','o','r','d',0}; static WCHAR about[] = {'/','s','i','t','e','/','a','b','o','u','t',0}; static WCHAR query[] = {'?','q','u','e','r','y',0}; static WCHAR escape[] = {' ','!','"','#','$','%','&','\'','(',')','*','+',',','-','.','/',':',';','<','=','>','?','@','[','\\',']','^','_','`','{','|','}','~',0}; +static WCHAR escape2[] = {'\r',0x1f,' ','\n',0x7f,'\r','\n',0}; +static WCHAR escape3[] = {'?','t','e','x','t','=',0xfb00,0}; +static WCHAR escape4[] = {'/','t','e','x','t','=',0xfb00,0}; static const WCHAR url1[] = {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d', @@ -72,6 +75,16 @@ static const WCHAR url14[] = {'h','t','t','p',':','/','/','w','w','w','.','w','i static const WCHAR url15[] = {'h','t','t','p',':','/','/','w','i','n','e','h','q','.','o','r','g',':','6','5','5','3','6',0}; static const WCHAR url16[] = {'h','t','t','p',':','/','/','w','i','n','e','h','q','.','o','r','g',':','0',0}; static const WCHAR url17[] = {'h','t','t','p',':','/','/','w','i','n','e','h','q','.','o','r','g',':',0}; +static const WCHAR url18[] = + {'h','t','t','p',':','/','/','%','0','D','%','1','F','%','2','0','%','0','A','%','7','F','%','0','D','%','0','A',0}; +static const WCHAR url19[] = + {'h','t','t','p',':','/','/','?','t','e','x','t','=',0xfb00,0}; +static const WCHAR url20[] = + {'h','t','t','p',':','/','/','/','t','e','x','t','=',0xfb00,0}; +static const WCHAR url21[] = + {'h','t','t','p','s',':','/','/','n','b','a','2','k','1','9','-','w','s','.','2','k','s','p','o','r','t','s','.','c','o','m',':','1','9','1','3','3', + '/','n','b','a','/','v','4','/','A','c','c','o','u','n','t','s','/','g','e','t','_','a','c','c','o','u','n','t','?','x','=','3','7','8','9','5','2', + '6','7','7','5','2','6','5','6','6','3','8','7','6',0}; static const WCHAR url_k1[] = {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d', @@ -301,7 +314,87 @@ static void WinHttpCreateUrl_test( void ) ret = WinHttpCreateUrl( &uc, ICU_ESCAPE, url, &len ); ok( ret, "expected success\n" ); ok( len == 113, "expected len 113 got %u\n", len ); - ok( !lstrcmpW( url, url7 ), "url doesn't match\n" ); + ok( !lstrcmpW( url, url7 ), "url doesn't match %s\n", wine_dbgstr_w(url) ); + + /* escape extra info */ + memset( &uc, 0, sizeof(uc) ); + uc.dwStructSize = sizeof(uc); + uc.lpszExtraInfo = escape2; + uc.dwExtraInfoLength = lstrlenW( uc.lpszExtraInfo ); + url[0] = 0; + len = 256; + ret = WinHttpCreateUrl( &uc, ICU_ESCAPE, url, &len ); + ok( ret, "expected success\n" ); + ok( len == lstrlenW(url18), "expected len %u got %u\n", lstrlenW(url18), len ); + ok( !lstrcmpW( url, url18 ), "url doesn't match\n" ); + + /* extra info with Unicode characters */ + memset( &uc, 0, sizeof(uc) ); + uc.dwStructSize = sizeof(uc); + uc.lpszExtraInfo = escape3; + uc.dwExtraInfoLength = lstrlenW( uc.lpszExtraInfo ); + url[0] = 0; + len = 256; + SetLastError( 0xdeadbeef ); + ret = WinHttpCreateUrl( &uc, ICU_ESCAPE, url, &len ); + err = GetLastError(); + ok( !ret, "expected failure\n" ); + ok( err == ERROR_INVALID_PARAMETER, "got %u\n", err ); + + /* extra info with Unicode characters, no ICU_ESCAPE */ + memset( &uc, 0, sizeof(uc) ); + uc.dwStructSize = sizeof(uc); + uc.lpszExtraInfo = escape3; + uc.dwExtraInfoLength = lstrlenW( uc.lpszExtraInfo ); + url[0] = 0; + len = 256; + ret = WinHttpCreateUrl( &uc, 0, url, &len ); + ok( ret || broken(!ret) /* < win7 */, "expected success\n" ); + if (ret) + { + ok( len == lstrlenW(url19), "expected len %u got %u\n", lstrlenW(url19), len ); + ok( !lstrcmpW( url, url19 ), "url doesn't match %s\n", wine_dbgstr_w(url) ); + } + + /* escape path */ + memset( &uc, 0, sizeof(uc) ); + uc.dwStructSize = sizeof(uc); + uc.lpszUrlPath = escape2; + uc.dwUrlPathLength = lstrlenW( uc.lpszUrlPath ); + url[0] = 0; + len = 256; + ret = WinHttpCreateUrl( &uc, ICU_ESCAPE, url, &len ); + ok( ret, "expected success\n" ); + ok( len == lstrlenW(url18), "expected len %u got %u\n", lstrlenW(url18), len ); + ok( !lstrcmpW( url, url18 ), "url doesn't match\n" ); + + /* path with Unicode characters */ + memset( &uc, 0, sizeof(uc) ); + uc.dwStructSize = sizeof(uc); + uc.lpszUrlPath = escape4; + uc.dwUrlPathLength = lstrlenW( uc.lpszUrlPath ); + url[0] = 0; + len = 256; + SetLastError( 0xdeadbeef ); + ret = WinHttpCreateUrl( &uc, ICU_ESCAPE, url, &len ); + err = GetLastError(); + ok( !ret, "expected failure\n" ); + ok( err == ERROR_INVALID_PARAMETER, "got %u\n", err ); + + /* path with Unicode characters, no ICU_ESCAPE */ + memset( &uc, 0, sizeof(uc) ); + uc.dwStructSize = sizeof(uc); + uc.lpszUrlPath = escape4; + uc.dwUrlPathLength = lstrlenW( uc.lpszUrlPath ); + url[0] = 0; + len = 256; + ret = WinHttpCreateUrl( &uc, 0, url, &len ); + ok( ret || broken(!ret) /* < win7 */, "expected success\n" ); + if (ret) + { + ok( len == lstrlenW(url20), "expected len %u got %u\n", lstrlenW(url20), len ); + ok( !lstrcmpW( url, url20 ), "url doesn't match %s\n", wine_dbgstr_w(url) ); + } /* NULL lpszScheme, 0 nScheme and nPort */ fill_url_components( &uc ); @@ -339,7 +432,7 @@ static void WinHttpCrackUrl_test( void ) static const WCHAR pathW[] = {'/','p','a','t','h','%','2','0','w','i','t','h','%','2','0','s','p','a','c','e','s',0}; URL_COMPONENTSW uc; - WCHAR scheme[20], user[20], pass[20], host[20], path[80], extra[40]; + WCHAR scheme[20], user[20], pass[20], host[40], path[80], extra[40]; DWORD error; BOOL ret; @@ -667,6 +760,7 @@ static void WinHttpCrackUrl_test( void ) ok( ret, "WinHttpCrackUrl failed le=%u\n", GetLastError() ); ok( !lstrcmpW( uc.lpszHostName, hostnameW ), "unexpected host name\n" ); ok( !lstrcmpW( uc.lpszUrlPath, pathW ), "unexpected path\n" ); + ok( uc.dwUrlPathLength == lstrlenW(pathW), "got %u\n", uc.dwUrlPathLength ); uc.dwStructSize = sizeof(uc); uc.lpszScheme = NULL; @@ -753,6 +847,19 @@ static void WinHttpCrackUrl_test( void ) ret = WinHttpCrackUrl( url17, 0, 0, &uc ); ok( ret, "got %u\n", GetLastError() ); todo_wine ok( uc.nPort == 80, "got %u\n", uc.nPort ); + + memset( &uc, 0, sizeof(uc) ); + uc.dwStructSize = sizeof(uc); + uc.lpszScheme = scheme; + uc.dwSchemeLength = ARRAY_SIZE(scheme); + uc.lpszHostName = host; + uc.dwHostNameLength = ARRAY_SIZE(host); + uc.lpszUrlPath = path; + uc.dwUrlPathLength = ARRAY_SIZE(path); + ret = WinHttpCrackUrl( url21, 0, 0, &uc ); + ok( ret, "got %u\n", GetLastError() ); + ok( !lstrcmpW( uc.lpszUrlPath, url21 + 37 ), "unexpected path %s\n", wine_dbgstr_w(uc.lpszUrlPath) ); + ok( uc.dwUrlPathLength == 50, "unexpected length %u\n", uc.dwUrlPathLength ); } START_TEST(url) diff --git a/modules/rostests/winetests/winhttp/winhttp.c b/modules/rostests/winetests/winhttp/winhttp.c index fb7bf8907b8..7ed8a527fca 100644 --- a/modules/rostests/winetests/winhttp/winhttp.c +++ b/modules/rostests/winetests/winhttp/winhttp.c @@ -33,6 +33,7 @@ #include <httprequestid.h> #include "wine/test.h" +#include "wine/heap.h" DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0); @@ -42,6 +43,22 @@ static const WCHAR test_winehq[] = {'t','e','s','t','.','w','i','n','e','h','q', static const WCHAR test_winehq_https[] = {'h','t','t','p','s',':','/','/','t','e','s','t','.','w','i','n','e','h','q','.','o','r','g',':','4','4','3',0}; static const WCHAR localhostW[] = {'l','o','c','a','l','h','o','s','t',0}; +static WCHAR *a2w(const char *str) +{ + int len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0); + WCHAR *ret = heap_alloc(len * sizeof(WCHAR)); + MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len); + return ret; +} + +static int strcmp_wa(const WCHAR *str1, const char *stra) +{ + WCHAR *str2 = a2w(stra); + int r = lstrcmpW(str1, str2); + heap_free(str2); + return r; +} + static BOOL proxy_active(void) { WINHTTP_PROXY_INFO proxy_info; @@ -64,7 +81,7 @@ static BOOL proxy_active(void) return active; } -static void test_QueryOption(void) +static void test_WinHttpQueryOption(void) { BOOL ret; HINTERNET session, request, connection; @@ -201,6 +218,42 @@ static void test_QueryOption(void) ok(GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError()); + feature = 0xdeadbeef; + size = sizeof(feature); + SetLastError(0xdeadbeef); + ret = WinHttpQueryOption(request, WINHTTP_OPTION_ENABLE_FEATURE, &feature, &size); + ok(!ret, "should fail to query enabled features for a request\n"); + ok(feature == 0xdeadbeef, "expect feature 0xdeadbeef, got %u\n", feature); + ok(GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError()); + + feature = WINHTTP_ENABLE_SSL_REVOCATION; + SetLastError(0xdeadbeef); + ret = WinHttpSetOption(request, WINHTTP_OPTION_ENABLE_FEATURE, 0, sizeof(feature)); + ok(!ret, "should fail to enable WINHTTP_ENABLE_SSL_REVOCATION with invalid parameters\n"); + ok(GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = WinHttpSetOption(request, WINHTTP_OPTION_ENABLE_FEATURE, &feature, 0); + ok(!ret, "should fail to enable WINHTTP_ENABLE_SSL_REVOCATION with invalid parameters\n"); + ok(GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = WinHttpSetOption(request, WINHTTP_OPTION_ENABLE_FEATURE, &feature, sizeof(feature)); + ok(ret, "failed to set feature\n"); + ok(GetLastError() == NO_ERROR || broken(GetLastError() == 0xdeadbeef), /* Doesn't set error code on Vista or older */ + "expected NO_ERROR, got %u\n", GetLastError()); + + feature = 0xdeadbeef; + SetLastError(0xdeadbeef); + ret = WinHttpSetOption(request, WINHTTP_OPTION_ENABLE_FEATURE, &feature, sizeof(feature)); + ok(!ret, "should fail to enable WINHTTP_ENABLE_SSL_REVOCATION with invalid parameters\n"); + ok(GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError()); + + feature = 6; + size = sizeof(feature); + ret = WinHttpSetOption(request, WINHTTP_OPTION_CONNECT_RETRIES, &feature, sizeof(feature)); + ok(ret, "failed to set WINHTTP_OPTION_CONNECT_RETRIES %u\n", GetLastError()); + SetLastError(0xdeadbeef); ret = WinHttpCloseHandle(request); ok(ret, "WinHttpCloseHandle failed on closing request: %u\n", GetLastError()); @@ -214,7 +267,7 @@ done: ok(ret, "WinHttpCloseHandle failed on closing session: %u\n", GetLastError()); } -static void test_OpenRequest (void) +static void test_WinHttpOpenRequest (void) { BOOL ret; HINTERNET session, request, connection; @@ -309,20 +362,21 @@ static void test_empty_headers_param(void) WinHttpCloseHandle(ses); } -static void test_SendRequest (void) +static void test_WinHttpSendRequest (void) { static const WCHAR content_type[] = {'C','o','n','t','e','n','t','-','T','y','p','e',':',' ','a','p','p','l','i','c','a','t','i','o','n', '/','x','-','w','w','w','-','f','o','r','m','-','u','r','l','e','n','c','o','d','e','d',0}; static const WCHAR test_file[] = {'t','e','s','t','s','/','p','o','s','t','.','p','h','p',0}; - static const WCHAR test_verb[] = {'P','O','S','T',0}; + static const WCHAR postW[] = {'P','O','S','T',0}; static CHAR post_data[] = "mode=Test"; static const char test_post[] = "mode => Test\0\n"; HINTERNET session, request, connection; - DWORD header_len, optional_len, total_len, bytes_rw, size, err, disable; + DWORD header_len, optional_len, total_len, bytes_rw, size, err, disable, len; DWORD_PTR context; BOOL ret; CHAR buffer[256]; + WCHAR method[8]; int i; header_len = -1L; @@ -336,7 +390,7 @@ static void test_SendRequest (void) connection = WinHttpConnect (session, test_winehq, INTERNET_DEFAULT_HTTP_PORT, 0); ok(connection != NULL, "WinHttpConnect failed to open a connection, error: %u.\n", GetLastError()); - request = WinHttpOpenRequest(connection, test_verb, test_file, NULL, WINHTTP_NO_REFERER, + request = WinHttpOpenRequest(connection, postW, test_file, NULL, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, WINHTTP_FLAG_BYPASS_PROXY_CACHE); if (request == NULL && GetLastError() == ERROR_WINHTTP_NAME_NOT_RESOLVED) { @@ -346,6 +400,13 @@ static void test_SendRequest (void) ok(request != NULL, "WinHttpOpenrequest failed to open a request, error: %u.\n", GetLastError()); if (!request) goto done; + method[0] = 0; + len = sizeof(method); + ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_REQUEST_METHOD, NULL, method, &len, NULL); + ok(ret, "got %u\n", GetLastError()); + ok(len == lstrlenW(postW) * sizeof(WCHAR), "got %u\n", len); + ok(!lstrcmpW(method, postW), "got %s\n", wine_dbgstr_w(method)); + context = 0xdeadbeef; ret = WinHttpSetOption(request, WINHTTP_OPTION_CONTEXT_VALUE, &context, sizeof(context)); ok(ret, "WinHttpSetOption failed: %u\n", GetLastError()); @@ -395,6 +456,14 @@ static void test_SendRequest (void) "Expected ERROR_SUCCESS got %u.\n", GetLastError()); ok(ret == TRUE, "WinHttpReceiveResponse failed: %u.\n", GetLastError()); + SetLastError(0xdeadbeef); + ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_ORIG_URI, NULL, NULL, &len, NULL); + ok(!ret && GetLastError() == ERROR_WINHTTP_HEADER_NOT_FOUND, "got %u\n", GetLastError()); + + SetLastError(0xdeadbeef); + ret = WinHttpQueryHeaders(request, WINHTTP_QUERY_MAX + 1, NULL, NULL, &len, NULL); + ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER, "got %u\n", GetLastError()); + bytes_rw = -1; ret = WinHttpReadData(request, buffer, sizeof(buffer) - 1, &bytes_rw); ok(ret == TRUE, "WinHttpReadData failed: %u.\n", GetLastError()); @@ -980,7 +1049,7 @@ static void test_secure_connection(void) { static const char data_start[] = "<!DOCTYPE html PUBLIC"; HINTERNET ses, con, req; - DWORD size, status, policy, bitness, read_size, err, available_size, protocols; + DWORD size, status, policy, bitness, read_size, err, available_size, protocols, flags; BOOL ret; CERT_CONTEXT *cert; WINHTTP_CERTIFICATE_INFO info; @@ -1034,6 +1103,33 @@ static void test_secure_connection(void) req = WinHttpOpenRequest(con, NULL, NULL, NULL, NULL, NULL, WINHTTP_FLAG_SECURE); ok(req != NULL, "failed to open a request %u\n", GetLastError()); + flags = 0xdeadbeef; + size = sizeof(flags); + ret = WinHttpQueryOption(req, WINHTTP_OPTION_SECURITY_FLAGS, &flags, &size); + ok(ret, "failed to query security flags %u\n", GetLastError()); + ok(!flags, "got %08x\n", flags); + + flags = SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE; + ret = WinHttpSetOption(req, WINHTTP_OPTION_SECURITY_FLAGS, &flags, sizeof(flags)); + ok(ret, "failed to set security flags %u\n", GetLastError()); + + flags = SECURITY_FLAG_SECURE; + ret = WinHttpSetOption(req, WINHTTP_OPTION_SECURITY_FLAGS, &flags, sizeof(flags)); + ok(!ret, "success\n"); + + flags = SECURITY_FLAG_STRENGTH_STRONG; + ret = WinHttpSetOption(req, WINHTTP_OPTION_SECURITY_FLAGS, &flags, sizeof(flags)); + ok(!ret, "success\n"); + + flags = SECURITY_FLAG_IGNORE_UNKNOWN_CA | SECURITY_FLAG_IGNORE_CERT_DATE_INVALID | + SECURITY_FLAG_IGNORE_CERT_CN_INVALID; + ret = WinHttpSetOption(req, WINHTTP_OPTION_SECURITY_FLAGS, &flags, sizeof(flags)); + ok(ret, "failed to set security flags %u\n", GetLastError()); + + flags = 0; + ret = WinHttpSetOption(req, WINHTTP_OPTION_SECURITY_FLAGS, &flags, sizeof(flags)); + ok(ret, "failed to set security flags %u\n", GetLastError()); + ret = WinHttpSetOption(req, WINHTTP_OPTION_CLIENT_CERT_CONTEXT, WINHTTP_NO_CLIENT_CERT_CONTEXT, 0); err = GetLastError(); ok(ret || broken(!ret && err == ERROR_INVALID_PARAMETER) /* winxp */, "failed to set client cert context %u\n", err); @@ -1043,7 +1139,7 @@ static void test_secure_connection(void) ret = WinHttpSendRequest(req, NULL, 0, NULL, 0, 0, 0); err = GetLastError(); if (!ret && (err == ERROR_WINHTTP_SECURE_FAILURE || err == ERROR_WINHTTP_CANNOT_CONNECT || - err == ERROR_WINHTTP_TIMEOUT)) + err == ERROR_WINHTTP_TIMEOUT || err == SEC_E_ILLEGAL_MESSAGE)) { skip("secure connection failed, skipping remaining secure tests\n"); goto cleanup; @@ -1076,6 +1172,11 @@ static void test_secure_connection(void) } ret = WinHttpReceiveResponse(req, NULL); + if (!ret && GetLastError() == ERROR_WINHTTP_CONNECTION_ERROR) + { + skip("connection error, skipping remaining secure tests\n"); + goto cleanup; + } ok(ret, "failed to receive response %u\n", GetLastError()); available_size = 0; @@ -1107,6 +1208,11 @@ static void test_secure_connection(void) } ok(read_size >= available_size, "read_size = %u, available_size = %u\n", read_size, available_size); + size = sizeof(cert); + ret = WinHttpQueryOption(req, WINHTTP_OPTION_SERVER_CERT_CONTEXT, &cert, &size); + ok(ret, "failed to retrieve certificate context %u\n", GetLastError()); + if (ret) CertFreeCertificateContext(cert); + cleanup: WinHttpCloseHandle(req); WinHttpCloseHandle(con); @@ -1140,11 +1246,6 @@ static void test_request_parameter_defaults(void) ok(ret, "failed to send request %u\n", GetLastError()); ret = WinHttpReceiveResponse(req, NULL); - if (!ret && GetLastError() == ERROR_WINHTTP_INVALID_SERVER_RESPONSE) /* win2k */ - { - win_skip("invalid response\n"); - goto done; - } ok(ret, "failed to receive response %u\n", GetLastError()); status = 0xdeadbeef; @@ -1342,7 +1443,7 @@ static void test_set_default_proxy_config(void) set_default_proxy_reg_value( saved_proxy_settings, len, type ); } -static void test_Timeouts (void) +static void test_timeouts(void) { BOOL ret; DWORD value, size; @@ -1931,6 +2032,70 @@ static void test_Timeouts (void) ok(ret, "%u\n", GetLastError()); ok(value == 0xbeefdead, "Expected 0xbeefdead, got %u\n", value); + /* response timeout */ + SetLastError(0xdeadbeef); + value = 0xdeadbeef; + size = sizeof(value); + ret = WinHttpQueryOption(req, WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT, &value, &size); + ok(ret, "%u\n", GetLastError()); + ok(value == ~0u, "got %u\n", value); + + SetLastError(0xdeadbeef); + value = 30000; + ret = WinHttpSetOption(req, WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT, &value, sizeof(value)); + ok(ret, "%u\n", GetLastError()); + + SetLastError(0xdeadbeef); + value = 0xdeadbeef; + size = sizeof(value); + ret = WinHttpQueryOption(req, WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT, &value, &size); + ok(ret, "%u\n", GetLastError()); + todo_wine ok(value == 0xbeefdead, "got %u\n", value); + + SetLastError(0xdeadbeef); + value = 0xdeadbeef; + size = sizeof(value); + ret = WinHttpQueryOption(con, WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT, &value, &size); + ok(ret, "%u\n", GetLastError()); + ok(value == ~0u, "got %u\n", value); + + SetLastError(0xdeadbeef); + value = 30000; + ret = WinHttpSetOption(con, WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT, &value, sizeof(value)); + ok(!ret, "expected failure\n"); + ok(GetLastError() == ERROR_WINHTTP_INCORRECT_HANDLE_TYPE, "got %u\n", GetLastError()); + + SetLastError(0xdeadbeef); + value = 0xdeadbeef; + size = sizeof(value); + ret = WinHttpQueryOption(ses, WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT, &value, &size); + ok(ret, "%u\n", GetLastError()); + ok(value == ~0u, "got %u\n", value); + + SetLastError(0xdeadbeef); + value = 48878; + ret = WinHttpSetOption(ses, WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT, &value, sizeof(value)); + ok(ret, "%u\n", GetLastError()); + + SetLastError(0xdeadbeef); + value = 0xdeadbeef; + size = sizeof(value); + ret = WinHttpQueryOption(ses, WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT, &value, &size); + ok(ret, "%u\n", GetLastError()); + todo_wine ok(value == 48879, "got %u\n", value); + + SetLastError(0xdeadbeef); + value = 48880; + ret = WinHttpSetOption(ses, WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT, &value, sizeof(value)); + ok(ret, "%u\n", GetLastError()); + + SetLastError(0xdeadbeef); + value = 0xdeadbeef; + size = sizeof(value); + ret = WinHttpQueryOption(ses, WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT, &value, &size); + ok(ret, "%u\n", GetLastError()); + ok(value == 48880, "got %u\n", value); + WinHttpCloseHandle(req); WinHttpCloseHandle(con); WinHttpCloseHandle(ses); @@ -1969,6 +2134,11 @@ static void test_resolve_timeout(void) ok(GetLastError() == ERROR_WINHTTP_NAME_NOT_RESOLVED, "expected ERROR_WINHTTP_NAME_NOT_RESOLVED got %u\n", GetLastError()); + ret = WinHttpReceiveResponse( req, NULL ); + ok( !ret && (GetLastError() == ERROR_WINHTTP_INCORRECT_HANDLE_STATE || + GetLastError() == ERROR_WINHTTP_OPERATION_CANCELLED /* < win7 */), + "got %u\n", GetLastError() ); + WinHttpCloseHandle(req); WinHttpCloseHandle(con); WinHttpCloseHandle(ses); @@ -2079,6 +2249,13 @@ static const char largeauth[] = "Content-Type: text/plain\r\n" "\r\n"; +static const char passportauth[] = +"HTTP/1.1 302 Found\r\n" +"Content-Length: 0\r\n" +"Location: /\r\n" +"WWW-Authenticate: Passport1.4\r\n" +"\r\n"; + static const char unauthorized[] = "Unauthorized"; static const char hello_world[] = "Hello World"; static const char auth_unseen[] = "Auth Unseen"; @@ -2243,6 +2420,30 @@ static DWORD CALLBACK server_thread(LPVOID param) if (!strstr(buffer, "Cookie: name=value\r\n")) send(c, cookiemsg, sizeof(cookiemsg) - 1, 0); else send(c, notokmsg, sizeof(notokmsg) - 1, 0); } + else if (strstr(buffer, "GET /escape")) + { + static const char res[] = "%0D%0A%1F%7F%3C%20%one?%1F%7F%20!%22%23$%&'()*+,-./:;%3C=%3E?@%5B%5C%5D" + "%5E_%60%7B%7C%7D~%0D%0A "; + static const char res2[] = "%0D%0A%1F%7F%3C%20%25two?%1F%7F%20!%22%23$%25&'()*+,-./:;%3C=%3E?@%5B%5C%5D" + "%5E_%60%7B%7C%7D~%0D%0A "; + static const char res3[] = "\x1f\x7f<%20%three?\x1f\x7f%20!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ "; + static const char res4[] = "%0D%0A%1F%7F%3C%20%four?\x1f\x7f%20!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ "; + static const char res5[] = "&text=one%C2%80%7F~"; + static const char res6[] = "&text=two%C2%80\x7f~"; + static const char res7[] = "&text=%E5%90%9B%E3%81%AE%E5%90%8D%E3%81%AF"; + + if (strstr(buffer + 11, res) || strstr(buffer + 11, res2) || strstr(buffer + 11, res3) || + strstr(buffer + 11, res4) || strstr(buffer + 11, res5) || strstr(buffer + 11, res6) || + strstr(buffer + 11, res7)) + { + send(c, okmsg, sizeof(okmsg) - 1, 0); + } + else send(c, notokmsg, sizeof(notokmsg) - 1, 0); + } + else if (strstr(buffer, "GET /passport")) + { + send(c, passportauth, sizeof(passportauth) - 1, 0); + } if (strstr(buffer, "GET /quit")) { send(c, okmsg, sizeof okmsg - 1, 0); @@ -2319,7 +2520,7 @@ static void test_basic_request(int port, const WCHAR *verb, const WCHAR *path) ret = WinHttpQueryAuthSchemes(req, &supported, &first, &target); error = GetLastError(); ok(!ret, "unexpected success\n"); - todo_wine ok(error == ERROR_INVALID_OPERATION, "expected ERROR_INVALID_OPERATION, got %u\n", error); + ok(error == ERROR_INVALID_OPERATION, "expected ERROR_INVALID_OPERATION, got %u\n", error); ok(supported == 0xdeadbeef, "got %x\n", supported); ok(first == 0xdeadbeef, "got %x\n", first); ok(target == 0xdeadbeef, "got %x\n", target); @@ -2406,7 +2607,7 @@ static void test_basic_authentication(int port) ret = WinHttpQueryAuthSchemes(req, &supported, &first, &target); error = GetLastError(); ok(!ret, "expected failure\n"); - todo_wine ok(error == ERROR_INVALID_OPERATION, "expected ERROR_INVALID_OPERATION, got %u\n", error); + ok(error == ERROR_INVALID_OPERATION, "expected ERROR_INVALID_OPERATION, got %u\n", error); ok(supported == 0xdeadbeef, "got %x\n", supported); ok(first == 0xdeadbeef, "got %x\n", first); ok(target == 0xdeadbeef, "got %x\n", target); @@ -2631,9 +2832,12 @@ static void test_basic_authentication(int port) static void test_multi_authentication(int port) { static const WCHAR multiauthW[] = {'/','m','u','l','t','i','a','u','t','h',0}; + static const WCHAR www_authenticateW[] = + {'W','W','W','-','A','u','t','h','e','n','t','i','c','a','t','e',0}; static const WCHAR getW[] = {'G','E','T',0}; HINTERNET ses, con, req; - DWORD supported, first, target; + DWORD supported, first, target, size, index; + WCHAR buf[512]; BOOL ret; ses = WinHttpOpen(test_useragent, WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0); @@ -2659,6 +2863,22 @@ static void test_multi_authentication(int port) ok(target == WINHTTP_AUTH_TARGET_SERVER, "got %x\n", target); ok(first == WINHTTP_AUTH_SCHEME_BASIC, "got %x\n", first); + index = 0; + size = sizeof(buf); + ret = WinHttpQueryHeaders(req, WINHTTP_QUERY_CUSTOM, www_authenticateW, buf, &size, &index); + ok(ret, "expected success\n"); + ok(!strcmp_wa(buf, "Bearer"), "buf = %s\n", wine_dbgstr_w(buf)); + ok(size == lstrlenW(buf) * sizeof(WCHAR), "size = %u\n", size); + ok(index == 1, "index = %u\n", index); + + index = 0; + size = 0xdeadbeef; + ret = WinHttpQueryHeaders(req, WINHTTP_QUERY_CUSTOM, www_authenticateW, NULL, &size, &index); + ok(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER, + "WinHttpQueryHeaders returned %x(%u)\n", ret, GetLastError()); + ok(size == (lstrlenW(buf) + 1) * sizeof(WCHAR), "size = %u\n", size); + ok(index == 0, "index = %u\n", index); + WinHttpCloseHandle(req); WinHttpCloseHandle(con); WinHttpCloseHandle(ses); @@ -2907,7 +3127,7 @@ static void test_not_modified(int port) memcpy(today, ifmodifiedW, sizeof(ifmodifiedW)); GetSystemTime(&st); - WinHttpTimeFromSystemTime(&st, &today[sizeof(ifmodifiedW)/sizeof(WCHAR)]); + WinHttpTimeFromSystemTime(&st, &today[ARRAY_SIZE(ifmodifiedW)]); session = WinHttpOpen(test_useragent, WINHTTP_ACCESS_TYPE_NO_PROXY, WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0); @@ -2982,6 +3202,7 @@ static void test_bad_header( int port ) content_typeW, buffer, &len, &index ); ok( ret, "failed to query headers %u\n", GetLastError() ); ok( !lstrcmpW( buffer, text_htmlW ), "got %s\n", wine_dbgstr_w(buffer) ); + ok( index == 1, "index = %u\n", index ); WinHttpCloseHandle( req ); WinHttpCloseHandle( con ); @@ -3022,6 +3243,7 @@ static void test_multiple_reads(int port) char *buf = HeapAlloc( GetProcessHeap(), 0, len + 1 ); ret = WinHttpReadData( req, buf, len, &bytes_read ); + ok(ret, "WinHttpReadData failed: %u.\n", GetLastError()); ok( len == bytes_read, "only got %u of %u available\n", bytes_read, len ); HeapFree( GetProcessHeap(), 0, buf ); @@ -3198,6 +3420,74 @@ static void test_cookies( int port ) WinHttpCloseHandle( ses ); } +static void do_request( HINTERNET con, const WCHAR *obj, DWORD flags ) +{ + HINTERNET req; + DWORD status, size; + BOOL ret; + + req = WinHttpOpenRequest( con, NULL, obj, NULL, NULL, NULL, flags ); + ok( req != NULL, "failed to open a request %u\n", GetLastError() ); + + ret = WinHttpSendRequest( req, NULL, 0, NULL, 0, 0, 0 ); + ok( ret, "failed to send request %u\n", GetLastError() ); + + ret = WinHttpReceiveResponse( req, NULL ); + ok( ret, "failed to receive response %u\n", GetLastError() ); + + status = 0xdeadbeef; + size = sizeof(status); + ret = WinHttpQueryHeaders( req, WINHTTP_QUERY_STATUS_CODE|WINHTTP_QUERY_FLAG_NUMBER, NULL, &status, &size, NULL ); + ok( ret, "failed to query status code %u\n", GetLastError() ); + ok( status == HTTP_STATUS_OK || broken(status == HTTP_STATUS_BAD_REQUEST) /* < win7 */, + "request %s with flags %08x failed %u\n", wine_dbgstr_w(obj), flags, status ); + WinHttpCloseHandle( req ); +} + +static void test_request_path_escapes( int port ) +{ + static const WCHAR objW[] = + {'/','e','s','c','a','p','e','\r','\n',0x1f,0x7f,'<',' ','%','o','n','e','?',0x1f,0x7f,' ','!','"','#', + '$','%','&','\'','(',')','*','+',',','-','.','/',':',';','<','=','>','?','@','[','\\',']','^','_','`', + '{','|','}','~','\r','\n',0}; + static const WCHAR obj2W[] = + {'/','e','s','c','a','p','e','\r','\n',0x1f,0x7f,'<',' ','%','t','w','o','?',0x1f,0x7f,' ','!','"','#', + '$','%','&','\'','(',')','*','+',',','-','.','/',':',';','<','=','>','?','@','[','\\',']','^','_','`', + '{','|','}','~','\r','\n',0}; + static const WCHAR obj3W[] = + {'/','e','s','c','a','p','e','\r','\n',0x1f,0x7f,'<',' ','%','t','h','r','e','e','?',0x1f,0x7f,' ','!', + '"','#','$','%','&','\'','(',')','*','+',',','-','.','/',':',';','<','=','>','?','@','[','\\',']','^', + '_','`','{','|','}','~','\r','\n',0}; + static const WCHAR obj4W[] = + {'/','e','s','c','a','p','e','\r','\n',0x1f,0x7f,'<',' ','%','f','o','u','r','?',0x1f,0x7f,' ','!','"', + '#','$','%','&','\'','(',')','*','+',',','-','.','/',':',';','<','=','>','?','@','[','\\',']','^','_', + '`','{','|','}','~','\r','\n',0}; + static const WCHAR obj5W[] = + {'/','e','s','c','a','p','e','&','t','e','x','t','=','o','n','e',0x80,0x7f,0x7e,0}; + static const WCHAR obj6W[] = + {'/','e','s','c','a','p','e','&','t','e','x','t','=','t','w','o',0x80,0x7f,0x7e,0}; + static const WCHAR obj7W[] = + {'/','e','s','c','a','p','e','&','t','e','x','t','=',0x541b,0x306e,0x540d,0x306f,0}; + HINTERNET ses, con; + + ses = WinHttpOpen( test_useragent, WINHTTP_ACCESS_TYPE_NO_PROXY, NULL, NULL, 0 ); + ok( ses != NULL, "failed to open session %u\n", GetLastError() ); + + con = WinHttpConnect( ses, localhostW, port, 0 ); + ok( con != NULL, "failed to open a connection %u\n", GetLastError() ); + + do_request( con, objW, 0 ); + do_request( con, obj2W, WINHTTP_FLAG_ESCAPE_PERCENT ); + do_request( con, obj3W, WINHTTP_FLAG_ESCAPE_DISABLE ); + do_request( con, obj4W, WINHTTP_FLAG_ESCAPE_DISABLE_QUERY ); + do_request( con, obj5W, 0 ); + do_request( con, obj6W, WINHTTP_FLAG_ESCAPE_DISABLE ); + do_request( con, obj7W, WINHTTP_FLAG_ESCAPE_DISABLE ); + + WinHttpCloseHandle( con ); + WinHttpCloseHandle( ses ); +} + static void test_connection_info( int port ) { static const WCHAR basicW[] = {'/','b','a','s','i','c',0}; @@ -3257,6 +3547,77 @@ static void test_connection_info( int port ) WinHttpCloseHandle( ses ); } +static void test_passport_auth( int port ) +{ + static const WCHAR passportW[] = + {'/','p','a','s','s','p','o','r','t',0}; + static const WCHAR foundW[] = + {'F','o','u','n','d',0}; + static const WCHAR unauthorizedW[] = + {'U','n','a','u','t','h','o','r','i','z','e','d',0}; + static const WCHAR headersW[] = + {'H','T','T','P','/','1','.','1',' ','4','0','1',' ','F','o','u','n','d','\r','\n', + 'C','o','n','t','e','n','t','-','L','e','n','g','t','h',':',' ','0','\r','\n', + 'L','o','c','a','t','i','o','n',':',' ','/','\r','\n', + 'W','W','W','-','A','u','t','h','e','n','t','i','c','a','t','e',':',' ', + 'P','a','s','s','p','o','r','t','1','.','4','\r','\n','\r','\n',0}; + HINTERNET ses, con, req; + DWORD status, size, option; + WCHAR buf[128]; + BOOL ret; + + ses = WinHttpOpen( test_useragent, 0, NULL, NULL, 0 ); + ok( ses != NULL, "got %u\n", GetLastError() ); + + option = WINHTTP_ENABLE_PASSPORT_AUTH; + ret = WinHttpSetOption( ses, WINHTTP_OPTION_CONFIGURE_PASSPORT_AUTH, &option, sizeof(option) ); + ok( ret, "got %u\n", GetLastError() ); + + con = WinHttpConnect( ses, localhostW, port, 0 ); + ok( con != NULL, "got %u\n", GetLastError() ); + + req = WinHttpOpenRequest( con, NULL, passportW, NULL, NULL, NULL, 0 ); + ok( req != NULL, "got %u\n", GetLastError() ); + + ret = WinHttpSendRequest( req, NULL, 0, NULL, 0, 0, 0 ); + ok( ret, "got %u\n", GetLastError() ); + + ret = WinHttpReceiveResponse( req, NULL ); + ok( ret || broken(!ret && GetLastError() == ERROR_WINHTTP_LOGIN_FAILURE) /* winxp */, "got %u\n", GetLastError() ); + if (!ret && GetLastError() == ERROR_WINHTTP_LOGIN_FAILURE) + { + win_skip("no support for Passport redirects\n"); + goto cleanup; + } + + status = 0xdeadbeef; + size = sizeof(status); + ret = WinHttpQueryHeaders( req, WINHTTP_QUERY_STATUS_CODE|WINHTTP_QUERY_FLAG_NUMBER, NULL, &status, &size, NULL ); + ok( ret, "got %u\n", GetLastError() ); + ok( status == HTTP_STATUS_DENIED, "got %u\n", status ); + + buf[0] = 0; + size = sizeof(buf); + ret = WinHttpQueryHeaders( req, WINHTTP_QUERY_STATUS_TEXT, NULL, buf, &size, NULL ); + ok( ret, "got %u\n", GetLastError() ); + ok( !lstrcmpW(foundW, buf) || broken(!lstrcmpW(unauthorizedW, buf)) /* < win7 */, "got %s\n", wine_dbgstr_w(buf) ); + + buf[0] = 0; + size = sizeof(buf); + ret = WinHttpQueryHeaders( req, WINHTTP_QUERY_RAW_HEADERS_CRLF, NULL, buf, &size, NULL ); + ok( ret || broken(!ret && GetLastError() == ERROR_INSUFFICIENT_BUFFER) /* < win7 */, "got %u\n", GetLastError() ); + if (ret) + { + ok( size == lstrlenW(headersW) * sizeof(WCHAR), "got %u\n", size ); + ok( !lstrcmpW(headersW, buf), "got %s\n", wine_dbgstr_w(buf) ); + } + +cleanup: + WinHttpCloseHandle( req ); + WinHttpCloseHandle( con ); + WinHttpCloseHandle( ses ); +} + static void test_credentials(void) { static WCHAR userW[] = {'u','s','e','r',0}; @@ -3277,13 +3638,13 @@ static void test_credentials(void) req = WinHttpOpenRequest(con, NULL, NULL, NULL, NULL, NULL, 0); ok(req != NULL, "failed to open a request %u\n", GetLastError()); - size = sizeof(buffer)/sizeof(WCHAR); + size = ARRAY_SIZE(buffer); ret = WinHttpQueryOption(req, WINHTTP_OPTION_PROXY_USERNAME, &buffer, &size); ok(ret, "failed to query proxy username %u\n", GetLastError()); ok(!buffer[0], "unexpected result %s\n", wine_dbgstr_w(buffer)); ok(!size, "expected 0, got %u\n", size); - size = sizeof(buffer)/sizeof(WCHAR); + size = ARRAY_SIZE(buffer); ret = WinHttpQueryOption(req, WINHTTP_OPTION_PROXY_PASSWORD, &buffer, &size); ok(ret, "failed to query proxy password %u\n", GetLastError()); ok(!buffer[0], "unexpected result %s\n", wine_dbgstr_w(buffer)); @@ -3292,19 +3653,19 @@ static void test_credentials(void) ret = WinHttpSetOption(req, WINHTTP_OPTION_PROXY_USERNAME, proxy_userW, lstrlenW(proxy_userW)); ok(ret, "failed to set username %u\n", GetLastError()); - size = sizeof(buffer)/sizeof(WCHAR); + size = ARRAY_SIZE(buffer); ret = WinHttpQueryOption(req, WINHTTP_OPTION_PROXY_USERNAME, &buffer, &size); ok(ret, "failed to query proxy username %u\n", GetLastError()); ok(!winetest_strcmpW(buffer, proxy_userW), "unexpected result %s\n", wine_dbgstr_w(buffer)); ok(size == lstrlenW(proxy_userW) * sizeof(WCHAR), "unexpected result %u\n", size); - size = sizeof(buffer)/sizeof(WCHAR); + size = ARRAY_SIZE(buffer); ret = WinHttpQueryOption(req, WINHTTP_OPTION_USERNAME, &buffer, &size); ok(ret, "failed to query username %u\n", GetLastError()); ok(!buffer[0], "unexpected result %s\n", wine_dbgstr_w(buffer)); ok(!size, "expected 0, got %u\n", size); - size = sizeof(buffer)/sizeof(WCHAR); + size = ARRAY_SIZE(buffer); ret = WinHttpQueryOption(req, WINHTTP_OPTION_PASSWORD, &buffer, &size); ok(ret, "failed to query password %u\n", GetLastError()); ok(!buffer[0], "unexpected result %s\n", wine_dbgstr_w(buffer)); @@ -3313,7 +3674,7 @@ static void test_credentials(void) ret = WinHttpSetOption(req, WINHTTP_OPTION_PROXY_PASSWORD, proxy_passW, lstrlenW(proxy_passW)); ok(ret, "failed to set proxy password %u\n", GetLastError()); - size = sizeof(buffer)/sizeof(WCHAR); + size = ARRAY_SIZE(buffer); ret = WinHttpQueryOption(req, WINHTTP_OPTION_PROXY_PASSWORD, &buffer, &size); ok(ret, "failed to query proxy password %u\n", GetLastError()); ok(!winetest_strcmpW(buffer, proxy_passW), "unexpected result %s\n", wine_dbgstr_w(buffer)); @@ -3322,7 +3683,7 @@ static void test_credentials(void) ret = WinHttpSetOption(req, WINHTTP_OPTION_USERNAME, userW, lstrlenW(userW)); ok(ret, "failed to set username %u\n", GetLastError()); - size = sizeof(buffer)/sizeof(WCHAR); + size = ARRAY_SIZE(buffer); ret = WinHttpQueryOption(req, WINHTTP_OPTION_USERNAME, &buffer, &size); ok(ret, "failed to query username %u\n", GetLastError()); ok(!winetest_strcmpW(buffer, userW), "unexpected result %s\n", wine_dbgstr_w(buffer)); @@ -3331,7 +3692,7 @@ static void test_credentials(void) ret = WinHttpSetOption(req, WINHTTP_OPTION_PASSWORD, passW, lstrlenW(passW)); ok(ret, "failed to set password %u\n", GetLastError()); - size = sizeof(buffer)/sizeof(WCHAR); + size = ARRAY_SIZE(buffer); ret = WinHttpQueryOption(req, WINHTTP_OPTION_PASSWORD, &buffer, &size); ok(ret, "failed to query password %u\n", GetLastError()); ok(!winetest_strcmpW(buffer, passW), "unexpected result %s\n", wine_dbgstr_w(buffer)); @@ -3357,7 +3718,7 @@ static void test_credentials(void) ret = WinHttpSetCredentials(req, WINHTTP_AUTH_TARGET_SERVER, WINHTTP_AUTH_SCHEME_BASIC, userW, passW, NULL); ok(ret, "failed to set credentials %u\n", GetLastError()); - size = sizeof(buffer)/sizeof(WCHAR); + size = ARRAY_SIZE(buffer); ret = WinHttpQueryOption(req, WINHTTP_OPTION_USERNAME, &buffer, &size); ok(ret, "failed to query username %u\n", GetLastError()); todo_wine { @@ -3365,7 +3726,7 @@ static void test_credentials(void) ok(!size, "expected 0, got %u\n", size); } - size = sizeof(buffer)/sizeof(WCHAR); + size = ARRAY_SIZE(buffer); ret = WinHttpQueryOption(req, WINHTTP_OPTION_PASSWORD, &buffer, &size); ok(ret, "failed to query password %u\n", GetLastError()); todo_wine { @@ -3435,9 +3796,9 @@ static void test_IWinHttpRequest(int port) V_VT( &data ) = VT_BSTR; V_BSTR( &data ) = SysAllocString( test_dataW ); hr = IWinHttpRequest_Send( req, data ); - ok( hr == S_OK || broken(hr == HRESULT_FROM_WIN32(ERROR_WINHTTP_INVALID_SERVER_RESPONSE)), - "got %08x\n", hr ); + ok( hr == S_OK || hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_INVALID_SERVER_RESPONSE ), "got %08x\n", hr ); SysFreeString( V_BSTR( &data ) ); + if (hr != S_OK) goto done; hr = IWinHttpRequest_Open( req, NULL, NULL, empty ); ok( hr == E_INVALIDARG, "got %08x\n", hr ); @@ -3905,14 +4266,14 @@ static void test_IWinHttpRequest(int port) SysFreeString( url ); hr = IWinHttpRequest_Send( req, empty ); - ok( hr == S_OK || broken(hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_INVALID_SERVER_RESPONSE )), "got %08x\n", hr ); - if (hr == S_OK) - { - hr = IWinHttpRequest_get_ResponseText( req, &response ); - ok( hr == S_OK, "got %08x\n", hr ); - ok( !memcmp(response, data_start, sizeof(data_start)), "got %s\n", wine_dbgstr_wn(response, 32) ); - SysFreeString( response ); - } + ok( hr == S_OK || hr == HRESULT_FROM_WIN32( ERROR_WINHTTP_INVALID_SERVER_RESPONSE ) || + hr == SEC_E_ILLEGAL_MESSAGE /* winxp */, "got %08x\n", hr ); + if (hr != S_OK) goto done; + + hr = IWinHttpRequest_get_ResponseText( req, &response ); + ok( hr == S_OK, "got %08x\n", hr ); + ok( !memcmp(response, data_start, sizeof(data_start)), "got %s\n", wine_dbgstr_wn(response, 32) ); + SysFreeString( response ); IWinHttpRequest_Release( req ); @@ -3920,7 +4281,7 @@ static void test_IWinHttpRequest(int port) ok( hr == S_OK, "got %08x\n", hr ); sprintf( buf, "
http://localhost:%d/auth
", port ); - MultiByteToWideChar( CP_ACP, 0, buf, -1, bufW, sizeof(bufW)/sizeof(bufW[0]) ); + MultiByteToWideChar( CP_ACP, 0, buf, -1, bufW, ARRAY_SIZE( bufW )); url = SysAllocString( bufW ); method = SysAllocString( method3W ); V_VT( &async ) = VT_BOOL; @@ -3949,8 +4310,8 @@ static void test_IWinHttpRequest(int port) ok( hr == S_OK, "got %08x\n", hr ); ok( status == HTTP_STATUS_DENIED, "got %d\n", status ); +done: IWinHttpRequest_Release( req ); - CoUninitialize(); } @@ -4195,14 +4556,12 @@ static void test_WinHttpDetectAutoProxyConfigUrl(void) WCHAR *url; DWORD error; -if (0) /* crashes on some win2k systems */ -{ SetLastError(0xdeadbeef); ret = WinHttpDetectAutoProxyConfigUrl( 0, NULL ); error = GetLastError(); ok( !ret, "expected failure\n" ); ok( error == ERROR_INVALID_PARAMETER, "got %u\n", error ); -} + url = NULL; SetLastError(0xdeadbeef); ret = WinHttpDetectAutoProxyConfigUrl( 0, &url ); @@ -4210,14 +4569,12 @@ if (0) /* crashes on some win2k systems */ ok( !ret, "expected failure\n" ); ok( error == ERROR_INVALID_PARAMETER, "got %u\n", error ); -if (0) /* crashes on some win2k systems */ -{ SetLastError(0xdeadbeef); ret = WinHttpDetectAutoProxyConfigUrl( WINHTTP_AUTO_DETECT_TYPE_DNS_A, NULL ); error = GetLastError(); ok( !ret, "expected failure\n" ); ok( error == ERROR_INVALID_PARAMETER, "got %u\n", error ); -} + url = (WCHAR *)0xdeadbeef; SetLastError(0xdeadbeef); ret = WinHttpDetectAutoProxyConfigUrl( WINHTTP_AUTO_DETECT_TYPE_DNS_A, &url ); @@ -4388,7 +4745,7 @@ static void test_WinHttpGetProxyForUrl(void) static void test_chunked_read(void) { - static const WCHAR verb[] = {'/','t','e','s','t','c','h','u','n','k','e','d',0}; + static const WCHAR verb[] = {'/','t','e','s','t','s','/','c','h','u','n','k','e','d',0}; static const WCHAR chunked[] = {'c','h','u','n','k','e','d',0}; WCHAR header[32]; DWORD len, err; @@ -4417,9 +4774,11 @@ static void test_chunked_read(void) goto done; } ok( ret, "WinHttpSendRequest failed with error %u\n", GetLastError() ); + if (!ret) goto done; ret = WinHttpReceiveResponse( req, NULL ); ok( ret, "WinHttpReceiveResponse failed with error %u\n", GetLastError() ); + if (!ret) goto done; header[0] = 0; len = sizeof(header); @@ -4449,6 +4808,7 @@ static void test_chunked_read(void) char *buf = HeapAlloc( GetProcessHeap(), 0, len + 1 ); ret = WinHttpReadData( req, buf, len, &bytes_read ); + ok(ret, "WinHttpReadData failed: %u.\n", GetLastError()); buf[bytes_read] = 0; trace( "WinHttpReadData -> %d %u\n", ret, bytes_read ); @@ -4476,17 +4836,17 @@ START_TEST (winhttp) HANDLE thread; DWORD ret; - test_OpenRequest(); - test_SendRequest(); + test_WinHttpOpenRequest(); + test_WinHttpSendRequest(); test_WinHttpTimeFromSystemTime(); test_WinHttpTimeToSystemTime(); test_WinHttpAddHeaders(); test_secure_connection(); test_request_parameter_defaults(); - test_QueryOption(); + test_WinHttpQueryOption(); test_set_default_proxy_config(); test_empty_headers_param(); - test_Timeouts(); + test_timeouts(); test_resolve_timeout(); test_credentials(); test_IWinHttpRequest_Invoke(); @@ -4498,7 +4858,7 @@ START_TEST (winhttp) si.event = CreateEventW(NULL, 0, 0, NULL); si.port = 7532; - thread = CreateThread(NULL, 0, server_thread, (LPVOID)&si, 0, NULL); + thread = CreateThread(NULL, 0, server_thread, &si, 0, NULL); ok(thread != NULL, "failed to create thread %u\n", GetLastError()); ret = WaitForSingleObject(si.event, 10000); @@ -4522,6 +4882,8 @@ START_TEST (winhttp) test_bad_header(si.port); test_multiple_reads(si.port); test_cookies(si.port); + test_request_path_escapes(si.port); + test_passport_auth(si.port); /* send the basic request again to shutdown the server thread */ test_basic_request(si.port, NULL, quitW);
1
0
0
0
[reactos] 01/01: [WINHTTP] Sync with Wine Staging 4.18. CORE-16441
by Amine Khaldi
07 Dec '19
07 Dec '19
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=5bd6580fc63bb886686b6…
commit 5bd6580fc63bb886686b62caf26f3ea99a173922 Author: Amine Khaldi <amine.khaldi(a)reactos.org> AuthorDate: Sat Dec 7 13:05:48 2019 +0100 Commit: Amine Khaldi <amine.khaldi(a)reactos.org> CommitDate: Sat Dec 7 13:05:48 2019 +0100 [WINHTTP] Sync with Wine Staging 4.18. CORE-16441 --- dll/win32/winhttp/cookie.c | 121 ++-- dll/win32/winhttp/handle.c | 25 +- dll/win32/winhttp/main.c | 1 + dll/win32/winhttp/net.c | 480 +++++-------- dll/win32/winhttp/request.c | 1261 +++++++++++++++++++++-------------- dll/win32/winhttp/session.c | 604 +++++++++-------- dll/win32/winhttp/url.c | 313 +++++---- dll/win32/winhttp/winhttp_private.h | 243 +++---- media/doc/README.WINE | 2 +- 9 files changed, 1617 insertions(+), 1433 deletions(-) diff --git a/dll/win32/winhttp/cookie.c b/dll/win32/winhttp/cookie.c index b4b25304f7f..40c11c6f71c 100644 --- a/dll/win32/winhttp/cookie.c +++ b/dll/win32/winhttp/cookie.c @@ -17,24 +17,39 @@ */ #include "config.h" +#include "ws2tcpip.h" #include <stdarg.h> -#include "wine/debug.h" -#include "wine/list.h" - #include "windef.h" #include "winbase.h" #include "winhttp.h" +#include "wine/debug.h" +#include "wine/list.h" #include "winhttp_private.h" WINE_DEFAULT_DEBUG_CHANNEL(winhttp); -static domain_t *add_domain( session_t *session, WCHAR *name ) +struct cookie +{ + struct list entry; + WCHAR *name; + WCHAR *value; + WCHAR *path; +}; + +struct domain +{ + struct list entry; + WCHAR *name; + struct list cookies; +}; + +static struct domain *add_domain( struct session *session, WCHAR *name ) { - domain_t *domain; + struct domain *domain; - if (!(domain = heap_alloc_zero( sizeof(domain_t) ))) return NULL; + if (!(domain = heap_alloc_zero( sizeof(struct domain) ))) return NULL; list_init( &domain->entry ); list_init( &domain->cookies ); @@ -46,14 +61,14 @@ static domain_t *add_domain( session_t *session, WCHAR *name ) return domain; } -static cookie_t *find_cookie( domain_t *domain, const WCHAR *path, const WCHAR *name ) +static struct cookie *find_cookie( struct domain *domain, const WCHAR *path, const WCHAR *name ) { struct list *item; - cookie_t *cookie; + struct cookie *cookie; LIST_FOR_EACH( item, &domain->cookies ) { - cookie = LIST_ENTRY( item, cookie_t, entry ); + cookie = LIST_ENTRY( item, struct cookie, entry ); if (!strcmpW( cookie->path, path ) && !strcmpW( cookie->name, name )) { TRACE("found %s=%s\n", debugstr_w(cookie->name), debugstr_w(cookie->value)); @@ -63,7 +78,7 @@ static cookie_t *find_cookie( domain_t *domain, const WCHAR *path, const WCHAR * return NULL; } -static BOOL domain_match( const WCHAR *name, domain_t *domain, BOOL partial ) +static BOOL domain_match( const WCHAR *name, struct domain *domain, BOOL partial ) { TRACE("comparing %s with %s\n", debugstr_w(name), debugstr_w(domain->name)); @@ -72,7 +87,7 @@ static BOOL domain_match( const WCHAR *name, domain_t *domain, BOOL partial ) return TRUE; } -static void free_cookie( cookie_t *cookie ) +static void free_cookie( struct cookie *cookie ) { heap_free( cookie->name ); heap_free( cookie->value ); @@ -80,20 +95,20 @@ static void free_cookie( cookie_t *cookie ) heap_free( cookie ); } -static void delete_cookie( cookie_t *cookie ) +static void delete_cookie( struct cookie *cookie ) { list_remove( &cookie->entry ); free_cookie( cookie ); } -void delete_domain( domain_t *domain ) +static void delete_domain( struct domain *domain ) { - cookie_t *cookie; + struct cookie *cookie; struct list *item, *next; LIST_FOR_EACH_SAFE( item, next, &domain->cookies ) { - cookie = LIST_ENTRY( item, cookie_t, entry ); + cookie = LIST_ENTRY( item, struct cookie, entry ); delete_cookie( cookie ); } @@ -102,35 +117,51 @@ void delete_domain( domain_t *domain ) heap_free( domain ); } -static BOOL add_cookie( session_t *session, cookie_t *cookie, WCHAR *domain_name, WCHAR *path ) +void destroy_cookies( struct session *session ) +{ + struct list *item, *next; + struct domain *domain; + + LIST_FOR_EACH_SAFE( item, next, &session->cookie_cache ) + { + domain = LIST_ENTRY( item, struct domain, entry ); + delete_domain( domain ); + } +} + +static BOOL add_cookie( struct session *session, struct cookie *cookie, WCHAR *domain_name, WCHAR *path ) { - domain_t *domain = NULL; - cookie_t *old_cookie; + struct domain *domain = NULL; + struct cookie *old_cookie; struct list *item; + if (!(cookie->path = strdupW( path ))) return FALSE; + + EnterCriticalSection( &session->cs ); + LIST_FOR_EACH( item, &session->cookie_cache ) { - domain = LIST_ENTRY( item, domain_t, entry ); + domain = LIST_ENTRY( item, struct domain, entry ); if (domain_match( domain_name, domain, FALSE )) break; domain = NULL; } - if (!domain) - { - if (!(domain = add_domain( session, domain_name ))) return FALSE; - } + if (!domain) domain = add_domain( session, domain_name ); else if ((old_cookie = find_cookie( domain, path, cookie->name ))) delete_cookie( old_cookie ); - cookie->path = strdupW( path ); - list_add_head( &domain->cookies, &cookie->entry ); + if (domain) + { + list_add_head( &domain->cookies, &cookie->entry ); + TRACE("domain %s path %s <- %s=%s\n", debugstr_w(domain_name), debugstr_w(cookie->path), + debugstr_w(cookie->name), debugstr_w(cookie->value)); + } - TRACE("domain %s path %s <- %s=%s\n", debugstr_w(domain_name), debugstr_w(cookie->path), - debugstr_w(cookie->name), debugstr_w(cookie->value)); - return TRUE; + LeaveCriticalSection( &session->cs ); + return domain != NULL; } -static cookie_t *parse_cookie( const WCHAR *string ) +static struct cookie *parse_cookie( const WCHAR *string ) { - cookie_t *cookie; + struct cookie *cookie; const WCHAR *p; int len; @@ -139,7 +170,7 @@ static cookie_t *parse_cookie( const WCHAR *string ) while (len && string[len - 1] == ' ') len--; if (!len) return NULL; - if (!(cookie = heap_alloc_zero( sizeof(cookie_t) ))) return NULL; + if (!(cookie = heap_alloc_zero( sizeof(struct cookie) ))) return NULL; list_init( &cookie->entry ); if (!(cookie->name = heap_alloc( (len + 1) * sizeof(WCHAR) ))) @@ -229,7 +260,7 @@ static struct attr *parse_attr( const WCHAR *str, int *used ) return attr; } -BOOL set_cookies( request_t *request, const WCHAR *cookies ) +BOOL set_cookies( struct request *request, const WCHAR *cookies ) { static const WCHAR pathW[] = {'p','a','t','h',0}; static const WCHAR domainW[] = {'d','o','m','a','i','n',0}; @@ -237,8 +268,8 @@ BOOL set_cookies( request_t *request, const WCHAR *cookies ) WCHAR *buffer, *p; WCHAR *cookie_domain = NULL, *cookie_path = NULL; struct attr *attr, *domain = NULL, *path = NULL; - session_t *session = request->connect->session; - cookie_t *cookie; + struct session *session = request->connect->session; + struct cookie *cookie; int len, used; len = strlenW( cookies ); @@ -290,14 +321,16 @@ end: return ret; } -BOOL add_cookie_headers( request_t *request ) +BOOL add_cookie_headers( struct request *request ) { struct list *domain_cursor; - session_t *session = request->connect->session; + struct session *session = request->connect->session; + + EnterCriticalSection( &session->cs ); LIST_FOR_EACH( domain_cursor, &session->cookie_cache ) { - domain_t *domain = LIST_ENTRY( domain_cursor, domain_t, entry ); + struct domain *domain = LIST_ENTRY( domain_cursor, struct domain, entry ); if (domain_match( request->connect->servername, domain, TRUE )) { struct list *cookie_cursor; @@ -305,19 +338,23 @@ BOOL add_cookie_headers( request_t *request ) LIST_FOR_EACH( cookie_cursor, &domain->cookies ) { - cookie_t *cookie = LIST_ENTRY( cookie_cursor, cookie_t, entry ); + struct cookie *cookie = LIST_ENTRY( cookie_cursor, struct cookie, entry ); TRACE("comparing path %s with %s\n", debugstr_w(request->path), debugstr_w(cookie->path)); if (strstrW( request->path, cookie->path ) == request->path) { - const WCHAR cookieW[] = {'C','o','o','k','i','e',':',' '}; - int len, len_cookie = sizeof(cookieW) / sizeof(cookieW[0]), len_name = strlenW( cookie->name ); + static const WCHAR cookieW[] = {'C','o','o','k','i','e',':',' '}; + int len, len_cookie = ARRAY_SIZE( cookieW ), len_name = strlenW( cookie->name ); WCHAR *header; len = len_cookie + len_name; if (cookie->value) len += strlenW( cookie->value ) + 1; - if (!(header = heap_alloc( (len + 1) * sizeof(WCHAR) ))) return FALSE; + if (!(header = heap_alloc( (len + 1) * sizeof(WCHAR) ))) + { + LeaveCriticalSection( &session->cs ); + return FALSE; + } memcpy( header, cookieW, len_cookie * sizeof(WCHAR) ); strcpyW( header + len_cookie, cookie->name ); @@ -335,5 +372,7 @@ BOOL add_cookie_headers( request_t *request ) } } } + + LeaveCriticalSection( &session->cs ); return TRUE; } diff --git a/dll/win32/winhttp/handle.c b/dll/win32/winhttp/handle.c index 6026a496103..6711cd91727 100644 --- a/dll/win32/winhttp/handle.c +++ b/dll/win32/winhttp/handle.c @@ -19,15 +19,14 @@ */ #include "config.h" -#include "wine/port.h" -#include "wine/debug.h" - +#include "ws2tcpip.h" #include <stdarg.h> #include "windef.h" #include "winbase.h" #include "winhttp.h" +#include "wine/debug.h" #include "winhttp_private.h" WINE_DEFAULT_DEBUG_CHANNEL(winhttp); @@ -43,20 +42,20 @@ static CRITICAL_SECTION_DEBUG handle_cs_debug = }; static CRITICAL_SECTION handle_cs = { &handle_cs_debug, -1, 0, 0, 0, 0 }; -static object_header_t **handles; +static struct object_header **handles; static ULONG_PTR next_handle; static ULONG_PTR max_handles; -object_header_t *addref_object( object_header_t *hdr ) +struct object_header *addref_object( struct object_header *hdr ) { ULONG refs = InterlockedIncrement( &hdr->refs ); TRACE("%p -> refcount = %d\n", hdr, refs); return hdr; } -object_header_t *grab_object( HINTERNET hinternet ) +struct object_header *grab_object( HINTERNET hinternet ) { - object_header_t *hdr = NULL; + struct object_header *hdr = NULL; ULONG_PTR handle = (ULONG_PTR)hinternet; EnterCriticalSection( &handle_cs ); @@ -70,13 +69,13 @@ object_header_t *grab_object( HINTERNET hinternet ) return hdr; } -void release_object( object_header_t *hdr ) +void release_object( struct object_header *hdr ) { ULONG refs = InterlockedDecrement( &hdr->refs ); TRACE("object %p refcount = %d\n", hdr, refs); if (!refs) { - if (hdr->type == WINHTTP_HANDLE_TYPE_REQUEST) close_connection( (request_t *)hdr ); + if (hdr->type == WINHTTP_HANDLE_TYPE_REQUEST) close_connection( (struct request *)hdr ); send_callback( hdr, WINHTTP_CALLBACK_STATUS_HANDLE_CLOSING, &hdr->handle, sizeof(HINTERNET) ); @@ -86,9 +85,9 @@ void release_object( object_header_t *hdr ) } } -HINTERNET alloc_handle( object_header_t *hdr ) +HINTERNET alloc_handle( struct object_header *hdr ) { - object_header_t **p; + struct object_header **p; ULONG_PTR handle, num; list_init( &hdr->children ); @@ -125,7 +124,7 @@ BOOL free_handle( HINTERNET hinternet ) { BOOL ret = FALSE; ULONG_PTR handle = (ULONG_PTR)hinternet; - object_header_t *hdr = NULL, *child, *next; + struct object_header *hdr = NULL, *child, *next; EnterCriticalSection( &handle_cs ); @@ -145,7 +144,7 @@ BOOL free_handle( HINTERNET hinternet ) if (hdr) { - LIST_FOR_EACH_ENTRY_SAFE( child, next, &hdr->children, object_header_t, entry ) + LIST_FOR_EACH_ENTRY_SAFE( child, next, &hdr->children, struct object_header, entry ) { TRACE("freeing child handle %p for parent handle 0x%lx\n", child->handle, handle + 1); free_handle( child->handle ); diff --git a/dll/win32/winhttp/main.c b/dll/win32/winhttp/main.c index a63f28cf108..e6c084b979b 100644 --- a/dll/win32/winhttp/main.c +++ b/dll/win32/winhttp/main.c @@ -18,6 +18,7 @@ #define COBJMACROS #include "config.h" +#include "ws2tcpip.h" #include <stdarg.h> #include "windef.h" diff --git a/dll/win32/winhttp/net.c b/dll/win32/winhttp/net.c index e9ff86a165a..277a22eacb0 100644 --- a/dll/win32/winhttp/net.c +++ b/dll/win32/winhttp/net.c @@ -18,145 +18,31 @@ */ #include "config.h" -#include "wine/port.h" - +#define NONAMELESSUNION +#include "ws2tcpip.h" #include <stdarg.h> #include <stdio.h> -#include <errno.h> #include <assert.h> -#include <sys/types.h> -#ifdef HAVE_SYS_SOCKET_H -# include <sys/socket.h> -#endif -#ifdef HAVE_SYS_IOCTL_H -# include <sys/ioctl.h> -#endif -#ifdef HAVE_SYS_FILIO_H -# include <sys/filio.h> -#endif -#ifdef HAVE_POLL_H -# include <poll.h> -#endif - -#define NONAMELESSUNION - -#include "wine/debug.h" -#include "wine/library.h" - #include "windef.h" #include "winbase.h" #include "winhttp.h" -#include "wincrypt.h" #include "schannel.h" +#include "wine/debug.h" +#include "wine/library.h" #include "winhttp_private.h" -/* to avoid conflicts with the Unix socket headers */ -#define USE_WS_PREFIX -#include "winsock2.h" - WINE_DEFAULT_DEBUG_CHANNEL(winhttp); -#ifndef HAVE_GETADDRINFO - -/* critical section to protect non-reentrant gethostbyname() */ -static CRITICAL_SECTION cs_gethostbyname; -static CRITICAL_SECTION_DEBUG critsect_debug = -{ - 0, 0, &cs_gethostbyname, - { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList }, - 0, 0, { (DWORD_PTR)(__FILE__ ": cs_gethostbyname") } -}; -static CRITICAL_SECTION cs_gethostbyname = { &critsect_debug, -1, 0, 0, 0, 0 }; - -#endif - -/* translate a unix error code into a winsock error code */ -#ifndef __REACTOS__ -static int sock_get_error( int err ) -{ -#if !defined(__MINGW32__) && !defined (_MSC_VER) - switch (err) - { - case EINTR: return WSAEINTR; - case EBADF: return WSAEBADF; - case EPERM: - case EACCES: return WSAEACCES; - case EFAULT: return WSAEFAULT; - case EINVAL: return WSAEINVAL; - case EMFILE: return WSAEMFILE; - case EWOULDBLOCK: return WSAEWOULDBLOCK; - case EINPROGRESS: return WSAEINPROGRESS; - case EALREADY: return WSAEALREADY; - case ENOTSOCK: return WSAENOTSOCK; - case EDESTADDRREQ: return WSAEDESTADDRREQ; - case EMSGSIZE: return WSAEMSGSIZE; - case EPROTOTYPE: return WSAEPROTOTYPE; - case ENOPROTOOPT: return WSAENOPROTOOPT; - case EPROTONOSUPPORT: return WSAEPROTONOSUPPORT; - case ESOCKTNOSUPPORT: return WSAESOCKTNOSUPPORT; - case EOPNOTSUPP: return WSAEOPNOTSUPP; - case EPFNOSUPPORT: return WSAEPFNOSUPPORT; - case EAFNOSUPPORT: return WSAEAFNOSUPPORT; - case EADDRINUSE: return WSAEADDRINUSE; - case EADDRNOTAVAIL: return WSAEADDRNOTAVAIL; - case ENETDOWN: return WSAENETDOWN; - case ENETUNREACH: return WSAENETUNREACH; - case ENETRESET: return WSAENETRESET; - case ECONNABORTED: return WSAECONNABORTED; - case EPIPE: - case ECONNRESET: return WSAECONNRESET; - case ENOBUFS: return WSAENOBUFS; - case EISCONN: return WSAEISCONN; - case ENOTCONN: return WSAENOTCONN; - case ESHUTDOWN: return WSAESHUTDOWN; - case ETOOMANYREFS: return WSAETOOMANYREFS; - case ETIMEDOUT: return WSAETIMEDOUT; - case ECONNREFUSED: return WSAECONNREFUSED; - case ELOOP: return WSAELOOP; - case ENAMETOOLONG: return WSAENAMETOOLONG; - case EHOSTDOWN: return WSAEHOSTDOWN; - case EHOSTUNREACH: return WSAEHOSTUNREACH; - case ENOTEMPTY: return WSAENOTEMPTY; -#ifdef EPROCLIM - case EPROCLIM: return WSAEPROCLIM; -#endif -#ifdef EUSERS - case EUSERS: return WSAEUSERS; -#endif -#ifdef EDQUOT - case EDQUOT: return WSAEDQUOT; -#endif -#ifdef ESTALE - case ESTALE: return WSAESTALE; -#endif -#ifdef EREMOTE - case EREMOTE: return WSAEREMOTE; -#endif - default: errno = err; perror( "sock_set_error" ); return WSAEFAULT; - } -#endif - return err; -} -#else -#define sock_get_error(x) WSAGetLastError() - -static inline int unix_ioctl(int filedes, long request, void *arg) -{ - return ioctlsocket(filedes, request, arg); -} -#define ioctlsocket unix_ioctl -#endif - static int sock_send(int fd, const void *msg, size_t len, int flags) { int ret; do { - if ((ret = send(fd, msg, len, flags)) == -1) WARN("send error %s\n", strerror(errno)); + if ((ret = send(fd, msg, len, flags)) == -1) WARN("send error %u\n", WSAGetLastError()); } - while(ret == -1 && errno == EINTR); + while(ret == -1 && WSAGetLastError() == WSAEINTR); return ret; } @@ -165,13 +51,13 @@ static int sock_recv(int fd, void *msg, size_t len, int flags) int ret; do { - if ((ret = recv(fd, msg, len, flags)) == -1) WARN("recv error %s\n", strerror(errno)); + if ((ret = recv(fd, msg, len, flags)) == -1) WARN("recv error %u\n", WSAGetLastError()); } - while(ret == -1 && errno == EINTR); + while(ret == -1 && WSAGetLastError() == WSAEINTR); return ret; } -static DWORD netconn_verify_cert( PCCERT_CONTEXT cert, WCHAR *server, DWORD security_flags ) +static DWORD netconn_verify_cert( PCCERT_CONTEXT cert, WCHAR *server, DWORD security_flags, BOOL check_revocation ) { HCERTSTORE store = cert->hCertStore; BOOL ret; @@ -184,9 +70,10 @@ static DWORD netconn_verify_cert( PCCERT_CONTEXT cert, WCHAR *server, DWORD secu TRACE("verifying %s\n", debugstr_w( server )); chainPara.RequestedUsage.Usage.cUsageIdentifier = 1; chainPara.RequestedUsage.Usage.rgpszUsageIdentifier = server_auth; - if ((ret = CertGetCertificateChain( NULL, cert, NULL, store, &chainPara, - CERT_CHAIN_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT, - NULL, &chain ))) + ret = CertGetCertificateChain( NULL, cert, NULL, store, &chainPara, + check_revocation ? CERT_CHAIN_REVOCATION_CHECK_CHAIN_EXCLUDE_ROOT : 0, + NULL, &chain ); + if (ret) { if (chain->TrustStatus.dwErrorStatus) { @@ -264,46 +151,41 @@ static DWORD netconn_verify_cert( PCCERT_CONTEXT cert, WCHAR *server, DWORD secu return err; } -#ifdef __REACTOS__ -static BOOL winsock_initialized = FALSE; -BOOL netconn_init_winsock() +static BOOL winsock_loaded; + +void netconn_unload( void ) { - WSADATA wsaData; - int error; - if (!winsock_initialized) - { - error = WSAStartup(MAKEWORD(1, 1), &wsaData); - if (error) - { - ERR("WSAStartup failed: %d\n", error); - return FALSE; - } - else - winsock_initialized = TRUE; - } - return winsock_initialized; + if (winsock_loaded) WSACleanup(); +} + +static BOOL WINAPI winsock_startup( INIT_ONCE *once, void *param, void **ctx ) +{ + int ret; + WSADATA data; + if (!(ret = WSAStartup( MAKEWORD(1,1), &data ))) winsock_loaded = TRUE; + else ERR( "WSAStartup failed: %d\n", ret ); + return TRUE; } -#endif +static void winsock_init(void) +{ + static INIT_ONCE once = INIT_ONCE_STATIC_INIT; + InitOnceExecuteOnce( &once, winsock_startup, NULL, NULL ); +} -void netconn_unload( void ) +static void set_blocking( struct netconn *conn, BOOL blocking ) { -#ifndef HAVE_GETADDRINFO - DeleteCriticalSection(&cs_gethostbyname); -#endif -#ifdef __REACTOS__ - if(winsock_initialized) - WSACleanup(); -#endif + ULONG state = !blocking; + ioctlsocket( conn->socket, FIONBIO, &state ); } -netconn_t *netconn_create( hostdata_t *host, const struct sockaddr_storage *sockaddr, int timeout ) +struct netconn *netconn_create( struct hostdata *host, const struct sockaddr_storage *sockaddr, int timeout ) { - netconn_t *conn; + struct netconn *conn; unsigned int addr_len; BOOL ret = FALSE; - int res; - ULONG state; + + winsock_init(); conn = heap_alloc_zero(sizeof(*conn)); if (!conn) return NULL; @@ -311,8 +193,7 @@ netconn_t *netconn_create( hostdata_t *host, const struct sockaddr_storage *sock conn->sockaddr = *sockaddr; if ((conn->socket = socket( sockaddr->ss_family, SOCK_STREAM, 0 )) == -1) { - WARN("unable to create socket (%s)\n", strerror(errno)); - set_last_error( sock_get_error( errno ) ); + WARN("unable to create socket (%u)\n", WSAGetLastError()); heap_free(conn); return NULL; } @@ -329,83 +210,39 @@ netconn_t *netconn_create( hostdata_t *host, const struct sockaddr_storage *sock assert(0); } - if (timeout > 0) - { - state = 1; - ioctlsocket( conn->socket, FIONBIO, &state ); - } + if (timeout > 0) set_blocking( conn, FALSE ); - for (;;) + if (!connect( conn->socket, (const struct sockaddr *)&conn->sockaddr, addr_len )) ret = TRUE; + else { - res = 0; - if (connect( conn->socket, (const struct sockaddr *)&conn->sockaddr, addr_len ) < 0) - { - res = sock_get_error( errno ); - if (res == WSAEWOULDBLOCK || res == WSAEINPROGRESS) - { -#ifdef __REACTOS__ - /* ReactOS: use select instead of poll */ - fd_set outfd; - struct timeval tv; - - FD_ZERO(&outfd); - FD_SET(conn->socket, &outfd); - - tv.tv_sec = 0; - tv.tv_usec = timeout * 1000; - for (;;) - { - res = 0; - - if (select( 0, NULL, &outfd, NULL, &tv ) > 0) -#else - struct pollfd pfd; - - pfd.fd = conn->socket; - pfd.events = POLLOUT; - for (;;) - { - res = 0; - if (poll( &pfd, 1, timeout ) > 0) -#endif - { - ret = TRUE; - break; - } - else - { - res = sock_get_error( errno ); - if (res != WSAEINTR) break; - } - } - } - if (res != WSAEINTR) break; - } - else + DWORD err = WSAGetLastError(); + if (err == WSAEWOULDBLOCK || err == WSAEINPROGRESS) { - ret = TRUE; - break; + FD_SET set; + TIMEVAL timeval = { 0, timeout * 1000 }; + int res; + + FD_ZERO( &set ); + FD_SET( conn->socket, &set ); + if ((res = select( conn->socket + 1, NULL, &set, NULL, &timeval )) > 0) ret = TRUE; + else if (!res) SetLastError( ERROR_WINHTTP_TIMEOUT ); } } - if (timeout > 0) - { - state = 0; - ioctlsocket( conn->socket, FIONBIO, &state ); - } + + if (timeout > 0) set_blocking( conn, TRUE ); + if (!ret) { - WARN("unable to connect to host (%d)\n", res); - set_last_error( res ); - netconn_close( conn ); + WARN("unable to connect to host (%u)\n", GetLastError()); + closesocket( conn->socket ); + heap_free( conn ); return NULL; } return conn; } -BOOL netconn_close( netconn_t *conn ) +void netconn_close( struct netconn *conn ) { - int res; - if (conn->secure) { heap_free( conn->peek_msg_mem ); @@ -413,18 +250,13 @@ BOOL netconn_close( netconn_t *conn ) heap_free(conn->extra_buf); DeleteSecurityContext(&conn->ssl_ctx); } - res = closesocket( conn->socket ); + closesocket( conn->socket ); release_host( conn->host ); heap_free(conn); - if (res == -1) - { - set_last_error( sock_get_error( errno ) ); - return FALSE; - } - return TRUE; } -BOOL netconn_secure_connect( netconn_t *conn, WCHAR *hostname, DWORD security_flags, CredHandle *cred_handle ) +BOOL netconn_secure_connect( struct netconn *conn, WCHAR *hostname, DWORD security_flags, CredHandle *cred_handle, + BOOL check_revocation) { SecBuffer out_buf = {0, SECBUFFER_TOKEN, NULL}, in_bufs[2] = {{0, SECBUFFER_TOKEN}, {0, SECBUFFER_EMPTY}}; SecBufferDesc out_desc = {SECBUFFER_VERSION, 1, &out_buf}, in_desc = {SECBUFFER_VERSION, 2, in_bufs}; @@ -520,7 +352,7 @@ BOOL netconn_secure_connect( netconn_t *conn, WCHAR *hostname, DWORD security_fl status = QueryContextAttributesW(&ctx, SECPKG_ATTR_REMOTE_CERT_CONTEXT, (void*)&cert); if(status == SEC_E_OK) { - res = netconn_verify_cert(cert, hostname, security_flags); + res = netconn_verify_cert(cert, hostname, security_flags, check_revocation); CertFreeCertificateContext(cert); if(res != ERROR_SUCCESS) { WARN("cert verify failed: %u\n", res); @@ -546,7 +378,7 @@ BOOL netconn_secure_connect( netconn_t *conn, WCHAR *hostname, DWORD security_fl heap_free(conn->ssl_buf); conn->ssl_buf = NULL; DeleteSecurityContext(&ctx); - set_last_error(res ? res : ERROR_WINHTTP_SECURE_CHANNEL_ERROR); + SetLastError(res ? res : ERROR_WINHTTP_SECURE_CHANNEL_ERROR); return FALSE; } @@ -557,7 +389,7 @@ BOOL netconn_secure_connect( netconn_t *conn, WCHAR *hostname, DWORD security_fl return TRUE; } -static BOOL send_ssl_chunk(netconn_t *conn, const void *msg, size_t size) +static BOOL send_ssl_chunk(struct netconn *conn, const void *msg, size_t size) { SecBuffer bufs[4] = { {conn->ssl_sizes.cbHeader, SECBUFFER_STREAM_HEADER, conn->ssl_buf}, @@ -565,7 +397,7 @@ static BOOL send_ssl_chunk(netconn_t *conn, const void *msg, size_t size) {conn->ssl_sizes.cbTrailer, SECBUFFER_STREAM_TRAILER, conn->ssl_buf+conn->ssl_sizes.cbHeader+size}, {0, SECBUFFER_EMPTY, NULL} }; - SecBufferDesc buf_desc = {SECBUFFER_VERSION, sizeof(bufs)/sizeof(*bufs), bufs}; + SecBufferDesc buf_desc = {SECBUFFER_VERSION, ARRAY_SIZE(bufs), bufs}; SECURITY_STATUS res; memcpy(bufs[1].pvBuffer, msg, size); @@ -583,7 +415,7 @@ static BOOL send_ssl_chunk(netconn_t *conn, const void *msg, size_t size) return TRUE; } -BOOL netconn_send( netconn_t *conn, const void *msg, size_t len, int *sent ) +BOOL netconn_send( struct netconn *conn, const void *msg, size_t len, int *sent ) { if (conn->secure) { @@ -604,19 +436,14 @@ BOOL netconn_send( netconn_t *conn, const void *msg, size_t len, int *sent ) return TRUE; } - if ((*sent = sock_send( conn->socket, msg, len, 0 )) == -1) - { - set_last_error( sock_get_error( errno ) ); - return FALSE; - } - return TRUE; + return ((*sent = sock_send( conn->socket, msg, len, 0 )) != -1); } -static BOOL read_ssl_chunk(netconn_t *conn, void *buf, SIZE_T buf_size, SIZE_T *ret_size, BOOL *eof) +static BOOL read_ssl_chunk(struct netconn *conn, void *buf, SIZE_T buf_size, SIZE_T *ret_size, BOOL *eof) { const SIZE_T ssl_buf_size = conn->ssl_sizes.cbHeader+conn->ssl_sizes.cbMaximumMessage+conn->ssl_sizes.cbTrailer; SecBuffer bufs[4]; - SecBufferDesc buf_desc = {SECBUFFER_VERSION, sizeof(bufs)/sizeof(*bufs), bufs}; + SecBufferDesc buf_desc = {SECBUFFER_VERSION, ARRAY_SIZE(bufs), bufs}; SSIZE_T size, buf_len; unsigned int i; SECURITY_STATUS res; @@ -672,7 +499,7 @@ static BOOL read_ssl_chunk(netconn_t *conn, void *buf, SIZE_T buf_size, SIZE_T * } } while(res != SEC_E_OK); - for(i=0; i < sizeof(bufs)/sizeof(*bufs); i++) { + for(i = 0; i < ARRAY_SIZE(bufs); i++) { if(bufs[i].BufferType == SECBUFFER_DATA) { size = min(buf_size, bufs[i].cbBuffer); memcpy(buf, bufs[i].pvBuffer, size); @@ -689,7 +516,7 @@ static BOOL read_ssl_chunk(netconn_t *conn, void *buf, SIZE_T buf_size, SIZE_T * } } - for(i=0; i < sizeof(bufs)/sizeof(*bufs); i++) { + for(i = 0; i < ARRAY_SIZE(bufs); i++) { if(bufs[i].BufferType == SECBUFFER_EXTRA) { conn->extra_buf = heap_alloc(bufs[i].cbBuffer); if(!conn->extra_buf) @@ -703,7 +530,7 @@ static BOOL read_ssl_chunk(netconn_t *conn, void *buf, SIZE_T buf_size, SIZE_T * return TRUE; } -BOOL netconn_recv( netconn_t *conn, void *buf, size_t len, int flags, int *recvd ) +BOOL netconn_recv( struct netconn *conn, void *buf, size_t len, int flags, int *recvd ) { *recvd = 0; if (!len) return TRUE; @@ -752,101 +579,64 @@ BOOL netconn_recv( netconn_t *conn, void *buf, size_t len, int flags, int *recvd *recvd = size; return TRUE; } - if ((*recvd = sock_recv( conn->socket, buf, len, flags )) == -1) - { - set_last_error( sock_get_error( errno ) ); - return FALSE; - } - return TRUE; + return ((*recvd = sock_recv( conn->socket, buf, len, flags )) != -1); } -ULONG netconn_query_data_available( netconn_t *conn ) +ULONG netconn_query_data_available( struct netconn *conn ) { return conn->secure ? conn->peek_len : 0; } -DWORD netconn_set_timeout( netconn_t *netconn, BOOL send, int value ) +DWORD netconn_set_timeout( struct netconn *netconn, BOOL send, int value ) { - struct timeval tv; - - /* value is in milliseconds, convert to struct timeval */ - tv.tv_sec = value / 1000; - tv.tv_usec = (value % 1000) * 1000; - - if (setsockopt( netconn->socket, SOL_SOCKET, send ? SO_SNDTIMEO : SO_RCVTIMEO, (void*)&tv, sizeof(tv) ) == -1) + int opt = send ? SO_SNDTIMEO : SO_RCVTIMEO; + if (setsockopt( netconn->socket, SOL_SOCKET, opt, (void *)&value, sizeof(value) ) == -1) { - WARN("setsockopt failed (%s)\n", strerror( errno )); - return sock_get_error( errno ); + DWORD err = WSAGetLastError(); + WARN("setsockopt failed (%u)\n", err ); + return err; } return ERROR_SUCCESS; } -BOOL netconn_is_alive( netconn_t *netconn ) +BOOL netconn_is_alive( struct netconn *netconn ) { -#ifdef MSG_DONTWAIT - ssize_t len; - BYTE b; - - len = recv( netconn->socket, &b, 1, MSG_PEEK | MSG_DONTWAIT ); - return len == 1 || (len == -1 && errno == EWOULDBLOCK); -#elif defined(__MINGW32__) || defined(_MSC_VER) - ULONG mode; int len; char b; + DWORD err; - mode = 1; - if(!ioctlsocket(netconn->socket, FIONBIO, &mode)) - return FALSE; - - len = recv(netconn->socket, &b, 1, MSG_PEEK); + set_blocking( netconn, FALSE ); + len = sock_recv( netconn->socket, &b, 1, MSG_PEEK ); + err = WSAGetLastError(); + set_blocking( netconn, TRUE ); - mode = 0; - if(!ioctlsocket(netconn->socket, FIONBIO, &mode)) - return FALSE; - - return len == 1 || (len == -1 && WSAGetLastError() == WSAEWOULDBLOCK); -#else - FIXME("not supported on this platform\n"); - return TRUE; -#endif + return len == 1 || (len == -1 && err == WSAEWOULDBLOCK); } -static DWORD resolve_hostname( const WCHAR *hostnameW, INTERNET_PORT port, struct sockaddr_storage *sa ) +static DWORD resolve_hostname( const WCHAR *name, INTERNET_PORT port, struct sockaddr_storage *sa ) { - char *hostname; -#ifdef HAVE_GETADDRINFO - struct addrinfo *res, hints; + ADDRINFOW *res, hints; int ret; -#else - struct hostent *he; - struct sockaddr_in *sin = (struct sockaddr_in *)sa; -#endif - - if (!(hostname = strdupWA( hostnameW ))) return ERROR_OUTOFMEMORY; -#ifdef HAVE_GETADDRINFO - memset( &hints, 0, sizeof(struct addrinfo) ); + memset( &hints, 0, sizeof(hints) ); /* Prefer IPv4 to IPv6 addresses, since some web servers do not listen on * their IPv6 addresses even though they have IPv6 addresses in the DNS. */ hints.ai_family = AF_INET; - ret = getaddrinfo( hostname, NULL, &hints, &res ); + ret = GetAddrInfoW( name, NULL, &hints, &res ); if (ret != 0) { - TRACE("failed to get IPv4 address of %s (%s), retrying with IPv6\n", debugstr_w(hostnameW), gai_strerror(ret)); + TRACE("failed to get IPv4 address of %s, retrying with IPv6\n", debugstr_w(name)); hints.ai_family = AF_INET6; - ret = getaddrinfo( hostname, NULL, &hints, &res ); + ret = GetAddrInfoW( name, NULL, &hints, &res ); if (ret != 0) { - TRACE("failed to get address of %s (%s)\n", debugstr_w(hostnameW), gai_strerror(ret)); - heap_free( hostname ); + TRACE("failed to get address of %s\n", debugstr_w(name)); return ERROR_WINHTTP_NAME_NOT_RESOLVED; } } - heap_free( hostname ); memcpy( sa, res->ai_addr, res->ai_addrlen ); - /* Copy port */ switch (res->ai_family) { case AF_INET: @@ -857,29 +647,12 @@ static DWORD resolve_hostname( const WCHAR *hostnameW, INTERNET_PORT port, struc break; } - freeaddrinfo( res ); + FreeAddrInfoW( res ); return ERROR_SUCCESS; -#else - EnterCriticalSection( &cs_gethostbyname ); - - he = gethostbyname( hostname ); - heap_free( hostname ); - if (!he) - { - TRACE("failed to get address of %s (%d)\n", debugstr_w(hostnameW), h_errno); - LeaveCriticalSection( &cs_gethostbyname ); - return ERROR_WINHTTP_NAME_NOT_RESOLVED; - } - memset( sa, 0, sizeof(struct sockaddr_in) ); - memcpy( &sin->sin_addr, he->h_addr, he->h_length ); - sin->sin_family = he->h_addrtype; - sin->sin_port = htons( port ); - - LeaveCriticalSection( &cs_gethostbyname ); - return ERROR_SUCCESS; -#endif } +#ifdef __REACTOS__ + struct resolve_args { const WCHAR *hostname; @@ -919,13 +692,64 @@ BOOL netconn_resolve( WCHAR *hostname, INTERNET_PORT port, struct sockaddr_stora if (ret) { - set_last_error( ret ); + SetLastError( ret ); return FALSE; } return TRUE; } -const void *netconn_get_certificate( netconn_t *conn ) +#else /* __REACTOS__ */ + +struct async_resolve +{ + const WCHAR *hostname; + INTERNET_PORT port; + struct sockaddr_storage *addr; + DWORD result; + HANDLE done; +}; + +static void CALLBACK resolve_proc( TP_CALLBACK_INSTANCE *instance, void *ctx ) +{ + struct async_resolve *async = ctx; + async->result = resolve_hostname( async->hostname, async->port, async->addr ); + SetEvent( async->done ); +} + +BOOL netconn_resolve( WCHAR *hostname, INTERNET_PORT port, struct sockaddr_storage *addr, int timeout ) +{ + DWORD ret; + + if (!timeout) ret = resolve_hostname( hostname, port, addr ); + else + { + struct async_resolve async; + + async.hostname = hostname; + async.port = port; + async.addr = addr; + if (!(async.done = CreateEventW( NULL, FALSE, FALSE, NULL ))) return FALSE; + if (!TrySubmitThreadpoolCallback( resolve_proc, &async, NULL )) + { + CloseHandle( async.done ); + return FALSE; + } + if (WaitForSingleObject( async.done, timeout ) != WAIT_OBJECT_0) ret = ERROR_WINHTTP_TIMEOUT; + else ret = async.result; + CloseHandle( async.done ); + } + + if (ret) + { + SetLastError( ret ); + return FALSE; + } + return TRUE; +} + +#endif /* __REACTOS__ */ + +const void *netconn_get_certificate( struct netconn *conn ) { const CERT_CONTEXT *ret; SECURITY_STATUS res; @@ -935,7 +759,7 @@ const void *netconn_get_certificate( netconn_t *conn ) return res == SEC_E_OK ? ret : NULL; } -int netconn_get_cipher_strength( netconn_t *conn ) +int netconn_get_cipher_strength( struct netconn *conn ) { SecPkgContext_ConnectionInfo conn_info; SECURITY_STATUS res; diff --git a/dll/win32/winhttp/request.c b/dll/win32/winhttp/request.c index 5bb5b093373..da28f7b1826 100644 --- a/dll/win32/winhttp/request.c +++ b/dll/win32/winhttp/request.c @@ -21,13 +21,9 @@ #define COBJMACROS #include "config.h" -#include "wine/port.h" - +#include "ws2tcpip.h" #include <stdarg.h> #include <assert.h> -#ifdef HAVE_ARPA_INET_H -# include <arpa/inet.h> -#endif #include "windef.h" #include "winbase.h" @@ -38,9 +34,8 @@ #include "schannel.h" #include "winhttp.h" -#include "winhttp_private.h" - #include "wine/debug.h" +#include "winhttp_private.h" WINE_DEFAULT_DEBUG_CHANNEL(winhttp); @@ -186,13 +181,13 @@ static const WCHAR *attribute_table[] = NULL /* WINHTTP_QUERY_PASSPORT_CONFIG = 78 */ }; -static task_header_t *dequeue_task( request_t *request ) +static struct task_header *dequeue_task( struct request *request ) { - task_header_t *task; + struct task_header *task; EnterCriticalSection( &request->task_cs ); TRACE("%u tasks queued\n", list_count( &request->task_queue )); - task = LIST_ENTRY( list_head( &request->task_queue ), task_header_t, entry ); + task = LIST_ENTRY( list_head( &request->task_queue ), struct task_header, entry ); if (task) list_remove( &task->entry ); LeaveCriticalSection( &request->task_cs ); @@ -200,9 +195,17 @@ static task_header_t *dequeue_task( request_t *request ) return task; } +#ifdef __REACTOS__ static DWORD CALLBACK task_proc( LPVOID param ) +#else +static void CALLBACK task_proc( TP_CALLBACK_INSTANCE *instance, void *ctx ) +#endif { - request_t *request = param; +#ifdef __REACTOS__ + struct request *request = param; +#else + struct request *request = ctx; +#endif HANDLE handles[2]; handles[0] = request->task_wait; @@ -214,7 +217,7 @@ static DWORD CALLBACK task_proc( LPVOID param ) { case WAIT_OBJECT_0: { - task_header_t *task; + struct task_header *task; while ((task = dequeue_task( request ))) { task->proc( task ); @@ -230,21 +233,31 @@ static DWORD CALLBACK task_proc( LPVOID param ) request->task_cs.DebugInfo->Spare[0] = 0; DeleteCriticalSection( &request->task_cs ); request->hdr.vtbl->destroy( &request->hdr ); +#ifdef __REACTOS__ return 0; +#else + return; +#endif default: ERR("wait failed %u (%u)\n", err, GetLastError()); break; } } +#ifdef __REACTOS__ return 0; +#endif } -static BOOL queue_task( task_header_t *task ) +static BOOL queue_task( struct task_header *task ) { - request_t *request = task->request; + struct request *request = task->request; +#ifdef __REACTOS__ if (!request->task_thread) +#else + if (!request->task_wait) +#endif { if (!(request->task_wait = CreateEventW( NULL, FALSE, FALSE, NULL ))) return FALSE; if (!(request->task_cancel = CreateEventW( NULL, FALSE, FALSE, NULL ))) @@ -253,7 +266,11 @@ static BOOL queue_task( task_header_t *task ) request->task_wait = NULL; return FALSE; } +#ifdef __REACTOS__ if (!(request->task_thread = CreateThread( NULL, 0, task_proc, request, 0, NULL ))) +#else + if (!TrySubmitThreadpoolCallback( task_proc, request, NULL )) +#endif { CloseHandle( request->task_wait ); request->task_wait = NULL; @@ -261,6 +278,9 @@ static BOOL queue_task( task_header_t *task ) request->task_cancel = NULL; return FALSE; } +#ifndef __REACTOS__ + request->task_proc_running = TRUE; +#endif InitializeCriticalSection( &request->task_cs ); request->task_cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": request.task_cs"); } @@ -274,7 +294,7 @@ static BOOL queue_task( task_header_t *task ) return TRUE; } -static void free_header( header_t *header ) +static void free_header( struct header *header ) { heap_free( header->field ); heap_free( header->value ); @@ -302,10 +322,10 @@ static BOOL valid_token_char( WCHAR c ) } } -static header_t *parse_header( LPCWSTR string ) +static struct header *parse_header( const WCHAR *string ) { const WCHAR *p, *q; - header_t *header; + struct header *header; int len; p = string; @@ -329,7 +349,7 @@ static header_t *parse_header( LPCWSTR string ) p++; } len = q - string; - if (!(header = heap_alloc_zero( sizeof(header_t) ))) return NULL; + if (!(header = heap_alloc_zero( sizeof(struct header) ))) return NULL; if (!(header->field = heap_alloc( (len + 1) * sizeof(WCHAR) ))) { heap_free( header ); @@ -353,7 +373,7 @@ static header_t *parse_header( LPCWSTR string ) return header; } -static int get_header_index( request_t *request, LPCWSTR field, int requested_index, BOOL request_only ) +static int get_header_index( struct request *request, const WCHAR *field, int requested_index, BOOL request_only ) { int index; @@ -373,15 +393,15 @@ static int get_header_index( request_t *request, LPCWSTR field, int requested_in return index; } -static BOOL insert_header( request_t *request, header_t *header ) +static BOOL insert_header( struct request *request, struct header *header ) { DWORD count = request->num_headers + 1; - header_t *hdrs; + struct header *hdrs; if (request->headers) - hdrs = heap_realloc_zero( request->headers, sizeof(header_t) * count ); + hdrs = heap_realloc_zero( request->headers, sizeof(struct header) * count ); else - hdrs = heap_alloc_zero( sizeof(header_t) ); + hdrs = heap_alloc_zero( sizeof(struct header) ); if (!hdrs) return FALSE; request->headers = hdrs; @@ -392,7 +412,7 @@ static BOOL insert_header( request_t *request, header_t *header ) return TRUE; } -static BOOL delete_header( request_t *request, DWORD index ) +static BOOL delete_header( struct request *request, DWORD index ) { if (!request->num_headers) return FALSE; if (index >= request->num_headers) return FALSE; @@ -401,15 +421,16 @@ static BOOL delete_header( request_t *request, DWORD index ) heap_free( request->headers[index].field ); heap_free( request->headers[index].value ); - memmove( &request->headers[index], &request->headers[index + 1], (request->num_headers - index) * sizeof(header_t) ); - memset( &request->headers[request->num_headers], 0, sizeof(header_t) ); + memmove( &request->headers[index], &request->headers[index + 1], + (request->num_headers - index) * sizeof(struct header) ); + memset( &request->headers[request->num_headers], 0, sizeof(struct header) ); return TRUE; } -BOOL process_header( request_t *request, LPCWSTR field, LPCWSTR value, DWORD flags, BOOL request_only ) +BOOL process_header( struct request *request, const WCHAR *field, const WCHAR *value, DWORD flags, BOOL request_only ) { int index; - header_t hdr; + struct header hdr; TRACE("%s: %s 0x%08x\n", debugstr_w(field), debugstr_w(value), flags); @@ -427,7 +448,7 @@ BOOL process_header( request_t *request, LPCWSTR field, LPCWSTR value, DWORD fla } else if (!(flags & WINHTTP_ADDREQ_FLAG_ADD)) { - set_last_error( ERROR_WINHTTP_HEADER_NOT_FOUND ); + SetLastError( ERROR_WINHTTP_HEADER_NOT_FOUND ); return FALSE; } @@ -444,7 +465,7 @@ BOOL process_header( request_t *request, LPCWSTR field, LPCWSTR value, DWORD fla { WCHAR *tmp; int len, len_orig, len_value; - header_t *header = &request->headers[index]; + struct header *header = &request->headers[index]; len_orig = strlenW( header->value ); len_value = strlenW( value ); @@ -471,11 +492,11 @@ BOOL process_header( request_t *request, LPCWSTR field, LPCWSTR value, DWORD fla return TRUE; } -BOOL add_request_headers( request_t *request, LPCWSTR headers, DWORD len, DWORD flags ) +BOOL add_request_headers( struct request *request, const WCHAR *headers, DWORD len, DWORD flags ) { BOOL ret = FALSE; WCHAR *buffer, *p, *q; - header_t *header; + struct header *header; if (len == ~0u) len = strlenW( headers ); if (!len) return TRUE; @@ -521,134 +542,116 @@ BOOL add_request_headers( request_t *request, LPCWSTR headers, DWORD len, DWORD BOOL WINAPI WinHttpAddRequestHeaders( HINTERNET hrequest, LPCWSTR headers, DWORD len, DWORD flags ) { BOOL ret; - request_t *request; + struct request *request; TRACE("%p, %s, %u, 0x%08x\n", hrequest, debugstr_wn(headers, len), len, flags); if (!headers || !len) { - set_last_error( ERROR_INVALID_PARAMETER ); + SetLastError( ERROR_INVALID_PARAMETER ); return FALSE; } - if (!(request = (request_t *)grab_object( hrequest ))) + if (!(request = (struct request *)grab_object( hrequest ))) { - set_last_error( ERROR_INVALID_HANDLE ); + SetLastError( ERROR_INVALID_HANDLE ); return FALSE; } if (request->hdr.type != WINHTTP_HANDLE_TYPE_REQUEST) { release_object( &request->hdr ); - set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); + SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); return FALSE; } ret = add_request_headers( request, headers, len, flags ); release_object( &request->hdr ); - if (ret) set_last_error( ERROR_SUCCESS ); + if (ret) SetLastError( ERROR_SUCCESS ); return ret; } -static WCHAR *build_request_path( request_t *request ) +static WCHAR *build_absolute_request_path( struct request *request, const WCHAR **path ) { + static const WCHAR http[] = {'h','t','t','p',0}; + static const WCHAR https[] = {'h','t','t','p','s',0}; + static const WCHAR fmt[] = {'%','s',':','/','/','%','s',0}; + const WCHAR *scheme; WCHAR *ret; + int len; - if (strcmpiW( request->connect->hostname, request->connect->servername )) - { - static const WCHAR http[] = { 'h','t','t','p',0 }; - static const WCHAR https[] = { 'h','t','t','p','s',0 }; - static const WCHAR fmt[] = { '%','s',':','/','/','%','s',0 }; - LPCWSTR scheme = (request->netconn ? request->netconn->secure : (request->hdr.flags & WINHTTP_FLAG_SECURE)) ? https : http; - int len; + scheme = (request->netconn ? request->netconn->secure : (request->hdr.flags & WINHTTP_FLAG_SECURE)) ? https : http; + + len = strlenW( scheme ) + strlenW( request->connect->hostname ) + 4; /* '://' + nul */ + if (request->connect->hostport) len += 6; /* ':' between host and port, up to 5 for port */ - len = strlenW( scheme ) + strlenW( request->connect->hostname ); - /* 3 characters for '://', 1 for NUL. */ - len += 4; + len += strlenW( request->path ); + if ((ret = heap_alloc( len * sizeof(WCHAR) ))) + { + len = sprintfW( ret, fmt, scheme, request->connect->hostname ); if (request->connect->hostport) { - /* 1 for ':' between host and port, up to 5 for port */ - len += 6; - } - if (request->path) - len += strlenW( request->path ); - if ((ret = heap_alloc( len * sizeof(WCHAR) ))) - { - sprintfW( ret, fmt, scheme, request->connect->hostname ); - if (request->connect->hostport) - { - static const WCHAR colonFmt[] = { ':','%','u',0 }; - - sprintfW( ret + strlenW( ret ), colonFmt, - request->connect->hostport ); - } - if (request->path) - strcatW( ret, request->path ); + static const WCHAR port_fmt[] = {':','%','u',0}; + len += sprintfW( ret + len, port_fmt, request->connect->hostport ); } + strcpyW( ret + len, request->path ); + if (path) *path = ret + len; } - else - ret = request->path; + return ret; } -static WCHAR *build_request_string( request_t *request ) +static WCHAR *build_request_string( struct request *request ) { - static const WCHAR space[] = {' ',0}; - static const WCHAR crlf[] = {'\r','\n',0}; - static const WCHAR colon[] = {':',' ',0}; - static const WCHAR twocrlf[] = {'\r','\n','\r','\n',0}; - + static const WCHAR spaceW[] = {' ',0}, crlfW[] = {'\r','\n',0}, colonW[] = {':',' ',0}; + static const WCHAR twocrlfW[] = {'\r','\n','\r','\n',0}; WCHAR *path, *ret; - const WCHAR **headers, **p; - unsigned int len, i = 0, j; + unsigned int i, len; - /* allocate space for an array of all the string pointers to be added */ - len = request->num_headers * 4 + 7; - if (!(headers = heap_alloc( len * sizeof(LPCWSTR) ))) return NULL; + if (!strcmpiW( request->connect->hostname, request->connect->servername )) path = request->path; + else if (!(path = build_absolute_request_path( request, NULL ))) return NULL; - path = build_request_path( request ); - headers[i++] = request->verb; - headers[i++] = space; - headers[i++] = path; - headers[i++] = space; - headers[i++] = request->version; + len = strlenW( request->verb ) + 1 /* ' ' */; + len += strlenW( path ) + 1 /* ' ' */; + len += strlenW( request->version ); - for (j = 0; j < request->num_headers; j++) + for (i = 0; i < request->num_headers; i++) { - if (request->headers[j].is_request) - { - headers[i++] = crlf; - headers[i++] = request->headers[j].field; - headers[i++] = colon; - headers[i++] = request->headers[j].value; - - TRACE("adding header %s (%s)\n", debugstr_w(request->headers[j].field), - debugstr_w(request->headers[j].value)); - } + if (request->headers[i].is_request) + len += strlenW( request->headers[i].field ) + strlenW( request->headers[i].value ) + 4; /* '\r\n: ' */ } - headers[i++] = twocrlf; - headers[i] = NULL; + len += 4; /* '\r\n\r\n' */ - len = 0; - for (p = headers; *p; p++) len += strlenW( *p ); - len++; + if ((ret = heap_alloc( (len + 1) * sizeof(WCHAR) ))) + { + strcpyW( ret, request->verb ); + strcatW( ret, spaceW ); + strcatW( ret, path ); + strcatW( ret, spaceW ); + strcatW( ret, request->version ); - if (!(ret = heap_alloc( len * sizeof(WCHAR) ))) - goto out; - *ret = 0; - for (p = headers; *p; p++) strcatW( ret, *p ); + for (i = 0; i < request->num_headers; i++) + { + if (request->headers[i].is_request) + { + strcatW( ret, crlfW ); + strcatW( ret, request->headers[i].field ); + strcatW( ret, colonW ); + strcatW( ret, request->headers[i].value ); + } + } + strcatW( ret, twocrlfW ); + } -out: - if (path != request->path) - heap_free( path ); - heap_free( headers ); + if (path != request->path) heap_free( path ); return ret; } #define QUERY_MODIFIER_MASK (WINHTTP_QUERY_FLAG_REQUEST_HEADERS | WINHTTP_QUERY_FLAG_SYSTEMTIME | WINHTTP_QUERY_FLAG_NUMBER) -static BOOL query_headers( request_t *request, DWORD level, LPCWSTR name, LPVOID buffer, LPDWORD buflen, LPDWORD index ) +static BOOL query_headers( struct request *request, DWORD level, const WCHAR *name, void *buffer, DWORD *buflen, + DWORD *index ) { - header_t *header = NULL; + struct header *header = NULL; BOOL request_only, ret = FALSE; int requested_index, header_index = -1; DWORD attr, len; @@ -677,7 +680,7 @@ static BOOL query_headers( request_t *request, DWORD level, LPCWSTR name, LPVOID for (len = 0; *p; p++) if (*p != '\r') len++; if (!buffer || len * sizeof(WCHAR) > *buflen) - set_last_error( ERROR_INSUFFICIENT_BUFFER ); + SetLastError( ERROR_INSUFFICIENT_BUFFER ); else { for (p = headers, q = buffer; *p; p++, q++) @@ -711,7 +714,7 @@ static BOOL query_headers( request_t *request, DWORD level, LPCWSTR name, LPVOID if (!buffer || len + sizeof(WCHAR) > *buflen) { len += sizeof(WCHAR); - set_last_error( ERROR_INSUFFICIENT_BUFFER ); + SetLastError( ERROR_INSUFFICIENT_BUFFER ); } else { @@ -728,7 +731,7 @@ static BOOL query_headers( request_t *request, DWORD level, LPCWSTR name, LPVOID if (!buffer || len + sizeof(WCHAR) > *buflen) { len += sizeof(WCHAR); - set_last_error( ERROR_INSUFFICIENT_BUFFER ); + SetLastError( ERROR_INSUFFICIENT_BUFFER ); } else { @@ -744,7 +747,7 @@ static BOOL query_headers( request_t *request, DWORD level, LPCWSTR name, LPVOID if (!buffer || len + sizeof(WCHAR) > *buflen) { len += sizeof(WCHAR); - set_last_error( ERROR_INSUFFICIENT_BUFFER ); + SetLastError( ERROR_INSUFFICIENT_BUFFER ); } else { @@ -755,10 +758,32 @@ static BOOL query_headers( request_t *request, DWORD level, LPCWSTR name, LPVOID *buflen = len; return ret; + case WINHTTP_QUERY_REQUEST_METHOD: + len = strlenW( request->verb ) * sizeof(WCHAR); + if (!buffer || len + sizeof(WCHAR) > *buflen) + { + len += sizeof(WCHAR); + SetLastError( ERROR_INSUFFICIENT_BUFFER ); + } + else + { + strcpyW( buffer, request->verb ); + TRACE("returning string: %s\n", debugstr_w(buffer)); + ret = TRUE; + } + *buflen = len; + return ret; + default: - if (attr >= sizeof(attribute_table)/sizeof(attribute_table[0]) || !attribute_table[attr]) + if (attr >= ARRAY_SIZE(attribute_table)) + { + SetLastError( ERROR_INVALID_PARAMETER ); + return FALSE; + } + if (!attribute_table[attr]) { FIXME("attribute %u not implemented\n", attr); + SetLastError( ERROR_WINHTTP_HEADER_NOT_FOUND ); return FALSE; } TRACE("attribute %s\n", debugstr_w(attribute_table[attr])); @@ -772,15 +797,14 @@ static BOOL query_headers( request_t *request, DWORD level, LPCWSTR name, LPVOID } if (!header || (request_only && !header->is_request)) { - set_last_error( ERROR_WINHTTP_HEADER_NOT_FOUND ); + SetLastError( ERROR_WINHTTP_HEADER_NOT_FOUND ); return FALSE; } - if (index) *index += 1; if (level & WINHTTP_QUERY_FLAG_NUMBER) { if (!buffer || sizeof(int) > *buflen) { - set_last_error( ERROR_INSUFFICIENT_BUFFER ); + SetLastError( ERROR_INSUFFICIENT_BUFFER ); } else { @@ -796,7 +820,7 @@ static BOOL query_headers( request_t *request, DWORD level, LPCWSTR name, LPVOID SYSTEMTIME *st = buffer; if (!buffer || sizeof(SYSTEMTIME) > *buflen) { - set_last_error( ERROR_INSUFFICIENT_BUFFER ); + SetLastError( ERROR_INSUFFICIENT_BUFFER ); } else if ((ret = WinHttpTimeToSystemTime( header->value, st ))) { @@ -812,7 +836,7 @@ static BOOL query_headers( request_t *request, DWORD level, LPCWSTR name, LPVOID if (!buffer || len + sizeof(WCHAR) > *buflen) { len += sizeof(WCHAR); - set_last_error( ERROR_INSUFFICIENT_BUFFER ); + SetLastError( ERROR_INSUFFICIENT_BUFFER ); } else { @@ -822,6 +846,7 @@ static BOOL query_headers( request_t *request, DWORD level, LPCWSTR name, LPVOID } *buflen = len; } + if (ret && index) *index += 1; return ret; } @@ -831,32 +856,29 @@ static BOOL query_headers( request_t *request, DWORD level, LPCWSTR name, LPVOID BOOL WINAPI WinHttpQueryHeaders( HINTERNET hrequest, DWORD level, LPCWSTR name, LPVOID buffer, LPDWORD buflen, LPDWORD index ) { BOOL ret; - request_t *request; + struct request *request; TRACE("%p, 0x%08x, %s, %p, %p, %p\n", hrequest, level, debugstr_w(name), buffer, buflen, index); - if (!(request = (request_t *)grab_object( hrequest ))) + if (!(request = (struct request *)grab_object( hrequest ))) { - set_last_error( ERROR_INVALID_HANDLE ); + SetLastError( ERROR_INVALID_HANDLE ); return FALSE; } if (request->hdr.type != WINHTTP_HANDLE_TYPE_REQUEST) { release_object( &request->hdr ); - set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); + SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); return FALSE; } ret = query_headers( request, level, name, buffer, buflen, index ); release_object( &request->hdr ); - if (ret) set_last_error( ERROR_SUCCESS ); + if (ret) SetLastError( ERROR_SUCCESS ); return ret; } -#undef ARRAYSIZE -#define ARRAYSIZE(array) (sizeof(array) / sizeof((array)[0])) - static const WCHAR basicW[] = {'B','a','s','i','c',0}; static const WCHAR ntlmW[] = {'N','T','L','M',0}; static const WCHAR passportW[] = {'P','a','s','s','p','o','r','t',0}; @@ -871,27 +893,26 @@ static const struct } auth_schemes[] = { - { basicW, ARRAYSIZE(basicW) - 1, WINHTTP_AUTH_SCHEME_BASIC }, - { ntlmW, ARRAYSIZE(ntlmW) - 1, WINHTTP_AUTH_SCHEME_NTLM }, - { passportW, ARRAYSIZE(passportW) - 1, WINHTTP_AUTH_SCHEME_PASSPORT }, - { digestW, ARRAYSIZE(digestW) - 1, WINHTTP_AUTH_SCHEME_DIGEST }, - { negotiateW, ARRAYSIZE(negotiateW) - 1, WINHTTP_AUTH_SCHEME_NEGOTIATE } + { basicW, ARRAY_SIZE(basicW) - 1, WINHTTP_AUTH_SCHEME_BASIC }, + { ntlmW, ARRAY_SIZE(ntlmW) - 1, WINHTTP_AUTH_SCHEME_NTLM }, + { passportW, ARRAY_SIZE(passportW) - 1, WINHTTP_AUTH_SCHEME_PASSPORT }, + { digestW, ARRAY_SIZE(digestW) - 1, WINHTTP_AUTH_SCHEME_DIGEST }, + { negotiateW, ARRAY_SIZE(negotiateW) - 1, WINHTTP_AUTH_SCHEME_NEGOTIATE } }; -static const unsigned int num_auth_schemes = sizeof(auth_schemes)/sizeof(auth_schemes[0]); static enum auth_scheme scheme_from_flag( DWORD flag ) { int i; - for (i = 0; i < num_auth_schemes; i++) if (flag == auth_schemes[i].scheme) return i; + for (i = 0; i < ARRAY_SIZE( auth_schemes ); i++) if (flag == auth_schemes[i].scheme) return i; return SCHEME_INVALID; } -static DWORD auth_scheme_from_header( WCHAR *header ) +static DWORD auth_scheme_from_header( const WCHAR *header ) { unsigned int i; - for (i = 0; i < num_auth_schemes; i++) + for (i = 0; i < ARRAY_SIZE( auth_schemes ); i++) { if (!strncmpiW( header, auth_schemes[i].str, auth_schemes[i].len ) && (header[auth_schemes[i].len] == ' ' || !header[auth_schemes[i].len])) return auth_schemes[i].scheme; @@ -899,7 +920,7 @@ static DWORD auth_scheme_from_header( WCHAR *header ) return 0; } -static BOOL query_auth_schemes( request_t *request, DWORD level, LPDWORD supported, LPDWORD first ) +static BOOL query_auth_schemes( struct request *request, DWORD level, DWORD *supported, DWORD *first ) { DWORD index = 0, supported_schemes = 0, first_scheme = 0; BOOL ret = FALSE; @@ -911,9 +932,8 @@ static BOOL query_auth_schemes( request_t *request, DWORD level, LPDWORD support size = 0; query_headers( request, level, NULL, NULL, &size, &index ); - if (get_last_error() != ERROR_INSUFFICIENT_BUFFER) break; + if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) break; - index--; if (!(buffer = heap_alloc( size ))) return FALSE; if (!query_headers( request, level, NULL, buffer, &size, &index )) { @@ -944,25 +964,25 @@ static BOOL query_auth_schemes( request_t *request, DWORD level, LPDWORD support BOOL WINAPI WinHttpQueryAuthSchemes( HINTERNET hrequest, LPDWORD supported, LPDWORD first, LPDWORD target ) { BOOL ret = FALSE; - request_t *request; + struct request *request; TRACE("%p, %p, %p, %p\n", hrequest, supported, first, target); - if (!(request = (request_t *)grab_object( hrequest ))) + if (!(request = (struct request *)grab_object( hrequest ))) { - set_last_error( ERROR_INVALID_HANDLE ); + SetLastError( ERROR_INVALID_HANDLE ); return FALSE; } if (request->hdr.type != WINHTTP_HANDLE_TYPE_REQUEST) { release_object( &request->hdr ); - set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); + SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); return FALSE; } if (!supported || !first || !target) { release_object( &request->hdr ); - set_last_error( ERROR_INVALID_PARAMETER ); + SetLastError( ERROR_INVALID_PARAMETER ); return FALSE; } @@ -977,9 +997,10 @@ BOOL WINAPI WinHttpQueryAuthSchemes( HINTERNET hrequest, LPDWORD supported, LPDW *target = WINHTTP_AUTH_TARGET_PROXY; ret = TRUE; } + else SetLastError( ERROR_INVALID_OPERATION ); release_object( &request->hdr ); - if (ret) set_last_error( ERROR_SUCCESS ); + if (ret) SetLastError( ERROR_SUCCESS ); return ret; } @@ -1127,7 +1148,7 @@ void destroy_authinfo( struct authinfo *authinfo ) heap_free( authinfo ); } -static BOOL get_authvalue( request_t *request, DWORD level, DWORD scheme, WCHAR *buffer, DWORD len ) +static BOOL get_authvalue( struct request *request, DWORD level, DWORD scheme, WCHAR *buffer, DWORD len ) { DWORD size, index = 0; for (;;) @@ -1139,7 +1160,7 @@ static BOOL get_authvalue( request_t *request, DWORD level, DWORD scheme, WCHAR return TRUE; } -static BOOL do_authorization( request_t *request, DWORD target, DWORD scheme_flag ) +static BOOL do_authorization( struct request *request, DWORD target, DWORD scheme_flag ) { struct authinfo *authinfo, **auth_ptr; enum auth_scheme scheme = scheme_from_flag( scheme_flag ); @@ -1368,129 +1389,76 @@ static BOOL do_authorization( request_t *request, DWORD target, DWORD scheme_fla return ret; } -static LPWSTR concatenate_string_list( LPCWSTR *list, int len ) +static WCHAR *build_proxy_connect_string( struct request *request ) { - LPCWSTR *t; - LPWSTR str; - - for( t = list; *t ; t++ ) - len += strlenW( *t ); - len++; - - str = heap_alloc( len * sizeof(WCHAR) ); - if (!str) return NULL; - *str = 0; + static const WCHAR fmtW[] = {'%','s',':','%','u',0}; + static const WCHAR connectW[] = {'C','O','N','N','E','C','T', 0}; + static const WCHAR spaceW[] = {' ',0}, crlfW[] = {'\r','\n',0}, colonW[] = {':',' ',0}; + static const WCHAR twocrlfW[] = {'\r','\n','\r','\n',0}; + WCHAR *ret, *host; + unsigned int i; + int len; - for( t = list; *t ; t++ ) - strcatW( str, *t ); + if (!(host = heap_alloc( (strlenW( request->connect->hostname ) + 7) * sizeof(WCHAR) ))) return NULL; + len = sprintfW( host, fmtW, request->connect->hostname, request->connect->hostport ); - return str; -} + len += ARRAY_SIZE(connectW); + len += ARRAY_SIZE(http1_1); -static LPWSTR build_header_request_string( request_t *request, LPCWSTR verb, - LPCWSTR path, LPCWSTR version ) -{ - static const WCHAR crlf[] = {'\r','\n',0}; - static const WCHAR space[] = { ' ',0 }; - static const WCHAR colon[] = { ':',' ',0 }; - static const WCHAR twocrlf[] = {'\r','\n','\r','\n', 0}; - LPWSTR requestString; - DWORD len, n; - LPCWSTR *req; - UINT i; - LPWSTR p; - - /* allocate space for an array of all the string pointers to be added */ - len = (request->num_headers) * 4 + 10; - req = heap_alloc( len * sizeof(LPCWSTR) ); - if (!req) return NULL; - - /* add the verb, path and HTTP version string */ - n = 0; - req[n++] = verb; - req[n++] = space; - req[n++] = path; - req[n++] = space; - req[n++] = version; - - /* Append custom request headers */ for (i = 0; i < request->num_headers; i++) { if (request->headers[i].is_request) - { - req[n++] = crlf; - req[n++] = request->headers[i].field; - req[n++] = colon; - req[n++] = request->headers[i].value; - - TRACE("Adding custom header %s (%s)\n", - debugstr_w(request->headers[i].field), - debugstr_w(request->headers[i].value)); - } + len += strlenW( request->headers[i].field ) + strlenW( request->headers[i].value ) + 4; /* '\r\n: ' */ } + len += 4; /* '\r\n\r\n' */ - if( n >= len ) - ERR("oops. buffer overrun\n"); - - req[n] = NULL; - requestString = concatenate_string_list( req, 4 ); - heap_free( req ); - if (!requestString) return NULL; + if ((ret = heap_alloc( (len + 1) * sizeof(WCHAR) ))) + { + strcpyW( ret, connectW ); + strcatW( ret, spaceW ); + strcatW( ret, host ); + strcatW( ret, spaceW ); + strcatW( ret, http1_1 ); - /* - * Set (header) termination string for request - * Make sure there are exactly two new lines at the end of the request - */ - p = &requestString[strlenW(requestString)-1]; - while ( (*p == '\n') || (*p == '\r') ) - p--; - strcpyW( p+1, twocrlf ); + for (i = 0; i < request->num_headers; i++) + { + if (request->headers[i].is_request) + { + strcatW( ret, crlfW ); + strcatW( ret, request->headers[i].field ); + strcatW( ret, colonW ); + strcatW( ret, request->headers[i].value ); + } + } + strcatW( ret, twocrlfW ); + } - return requestString; + heap_free( host ); + return ret; } -static BOOL read_reply( request_t *request ); +static BOOL read_reply( struct request *request ); -static BOOL secure_proxy_connect( request_t *request ) +static BOOL secure_proxy_connect( struct request *request ) { - static const WCHAR verbConnect[] = {'C','O','N','N','E','C','T',0}; - static const WCHAR fmt[] = {'%','s',':','%','u',0}; - BOOL ret = FALSE; - LPWSTR path; - connect_t *connect = request->connect; - - path = heap_alloc( (strlenW( connect->hostname ) + 13) * sizeof(WCHAR) ); - if (path) - { - LPWSTR requestString; + WCHAR *str; + char *strA; + int len, bytes_sent; + BOOL ret; - sprintfW( path, fmt, connect->hostname, connect->hostport ); - requestString = build_header_request_string( request, verbConnect, - path, http1_1 ); - heap_free( path ); - if (requestString) - { - LPSTR req_ascii = strdupWA( requestString ); + if (!(str = build_proxy_connect_string( request ))) return FALSE; + strA = strdupWA( str ); + heap_free( str ); + if (!strA) return FALSE; - heap_free( requestString ); - if (req_ascii) - { - int len = strlen( req_ascii ), bytes_sent; + len = strlen( strA ); + ret = netconn_send( request->netconn, strA, len, &bytes_sent ); + heap_free( strA ); + if (ret) ret = read_reply( request ); - ret = netconn_send( request->netconn, req_ascii, len, &bytes_sent ); - heap_free( req_ascii ); - if (ret) - ret = read_reply( request ); - } - } - } return ret; } -#ifndef INET6_ADDRSTRLEN -#define INET6_ADDRSTRLEN 46 -#endif - static WCHAR *addr_to_str( struct sockaddr_storage *addr ) { char buf[INET6_ADDRSTRLEN]; @@ -1523,7 +1491,7 @@ static CRITICAL_SECTION connection_pool_cs = { &connection_pool_debug, -1, 0, 0, static struct list connection_pool = LIST_INIT( connection_pool ); -void release_host( hostdata_t *host ) +void release_host( struct hostdata *host ) { LONG ref; @@ -1539,11 +1507,15 @@ void release_host( hostdata_t *host ) static BOOL connection_collector_running; +#ifdef __REACTOS__ static DWORD WINAPI connection_collector(void *arg) +#else +static void CALLBACK connection_collector( TP_CALLBACK_INSTANCE *instance, void *ctx ) +#endif { unsigned int remaining_connections; - netconn_t *netconn, *next_netconn; - hostdata_t *host, *next_host; + struct netconn *netconn, *next_netconn; + struct hostdata *host, *next_host; ULONGLONG now; do @@ -1555,9 +1527,9 @@ static DWORD WINAPI connection_collector(void *arg) EnterCriticalSection(&connection_pool_cs); - LIST_FOR_EACH_ENTRY_SAFE(host, next_host, &connection_pool, hostdata_t, entry) + LIST_FOR_EACH_ENTRY_SAFE(host, next_host, &connection_pool, struct hostdata, entry) { - LIST_FOR_EACH_ENTRY_SAFE(netconn, next_netconn, &host->connections, netconn_t, entry) + LIST_FOR_EACH_ENTRY_SAFE(netconn, next_netconn, &host->connections, struct netconn, entry) { if (netconn->keep_until < now) { @@ -1565,10 +1537,7 @@ static DWORD WINAPI connection_collector(void *arg) list_remove(&netconn->entry); netconn_close(netconn); } - else - { - remaining_connections++; - } + else remaining_connections++; } } @@ -1577,10 +1546,14 @@ static DWORD WINAPI connection_collector(void *arg) LeaveCriticalSection(&connection_pool_cs); } while(remaining_connections); +#ifdef __REACTOS__ FreeLibraryAndExitThread( winhttp_instance, 0 ); +#else + FreeLibraryWhenCallbackReturns( instance, winhttp_instance ); +#endif } -static void cache_connection( netconn_t *netconn ) +static void cache_connection( struct netconn *netconn ) { TRACE( "caching connection %p\n", netconn ); @@ -1592,10 +1565,13 @@ static void cache_connection( netconn_t *netconn ) if (!connection_collector_running) { HMODULE module; +#ifdef __REACTOS__ HANDLE thread; +#endif - GetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (const WCHAR*)winhttp_instance, &module ); + GetModuleHandleExW( GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (const WCHAR *)winhttp_instance, &module ); +#ifdef __REACTOS__ thread = CreateThread(NULL, 0, connection_collector, NULL, 0, NULL); if (thread) { @@ -1606,6 +1582,10 @@ static void cache_connection( netconn_t *netconn ) { FreeLibrary( winhttp_instance ); } +#else + if (TrySubmitThreadpoolCallback( connection_collector, NULL, NULL )) connection_collector_running = TRUE; + else FreeLibrary( winhttp_instance ); +#endif } LeaveCriticalSection( &connection_pool_cs ); @@ -1622,32 +1602,43 @@ static DWORD map_secure_protocols( DWORD mask ) return ret; } -static BOOL ensure_cred_handle( session_t *session ) +static BOOL ensure_cred_handle( struct request *request ) { - SCHANNEL_CRED cred; - SECURITY_STATUS status; + SECURITY_STATUS status = SEC_E_OK; + + if (request->cred_handle_initialized) return TRUE; - if (session->cred_handle_initialized) return TRUE; + if (!request->cred_handle_initialized) + { + SCHANNEL_CRED cred; + memset( &cred, 0, sizeof(cred) ); + cred.dwVersion = SCHANNEL_CRED_VERSION; + cred.grbitEnabledProtocols = map_secure_protocols( request->connect->session->secure_protocols ); + if (request->client_cert) + { + cred.paCred = &request->client_cert; + cred.cCreds = 1; + } + status = AcquireCredentialsHandleW( NULL, (WCHAR *)UNISP_NAME_W, SECPKG_CRED_OUTBOUND, NULL, + &cred, NULL, NULL, &request->cred_handle, NULL ); + if (status == SEC_E_OK) + request->cred_handle_initialized = TRUE; + } - memset( &cred, 0, sizeof(cred) ); - cred.dwVersion = SCHANNEL_CRED_VERSION; - cred.grbitEnabledProtocols = map_secure_protocols( session->secure_protocols ); - if ((status = AcquireCredentialsHandleW( NULL, (WCHAR *)UNISP_NAME_W, SECPKG_CRED_OUTBOUND, NULL, &cred, - NULL, NULL, &session->cred_handle, NULL )) != SEC_E_OK) + if (status != SEC_E_OK) { WARN( "AcquireCredentialsHandleW failed: 0x%08x\n", status ); return FALSE; } - session->cred_handle_initialized = TRUE; return TRUE; } -static BOOL open_connection( request_t *request ) +static BOOL open_connection( struct request *request ) { BOOL is_secure = request->hdr.flags & WINHTTP_FLAG_SECURE; - hostdata_t *host = NULL, *iter; - netconn_t *netconn = NULL; - connect_t *connect; + struct hostdata *host = NULL, *iter; + struct netconn *netconn = NULL; + struct connect *connect; WCHAR *addressW = NULL; INTERNET_PORT port; DWORD len; @@ -1659,7 +1650,7 @@ static BOOL open_connection( request_t *request ) EnterCriticalSection( &connection_pool_cs ); - LIST_FOR_EACH_ENTRY( iter, &connection_pool, hostdata_t, entry ) + LIST_FOR_EACH_ENTRY( iter, &connection_pool, struct hostdata, entry ) { if (iter->port == port && !strcmpW( connect->servername, iter->hostname ) && !is_secure == !iter->secure) { @@ -1698,7 +1689,7 @@ static BOOL open_connection( request_t *request ) EnterCriticalSection( &connection_pool_cs ); if (!list_empty( &host->connections )) { - netconn = LIST_ENTRY( list_head( &host->connections ), netconn_t, entry ); + netconn = LIST_ENTRY( list_head( &host->connections ), struct netconn, entry ); list_remove( &netconn->entry ); } LeaveCriticalSection( &connection_pool_cs ); @@ -1756,7 +1747,10 @@ static BOOL open_connection( request_t *request ) return FALSE; } netconn_set_timeout( netconn, TRUE, request->send_timeout ); - netconn_set_timeout( netconn, FALSE, request->recv_timeout ); + netconn_set_timeout( netconn, FALSE, request->receive_response_timeout ); + + request->netconn = netconn; + if (is_secure) { if (connect->session->proxy_server && @@ -1764,22 +1758,27 @@ static BOOL open_connection( request_t *request ) { if (!secure_proxy_connect( request )) { + request->netconn = NULL; heap_free( addressW ); netconn_close( netconn ); return FALSE; } } - if (!ensure_cred_handle( connect->session ) || + + CertFreeCertificateContext( request->server_cert ); + request->server_cert = NULL; + + if (!ensure_cred_handle( request ) || !netconn_secure_connect( netconn, connect->hostname, request->security_flags, - &connect->session->cred_handle )) + &request->cred_handle, request->check_revocation )) { + request->netconn = NULL; heap_free( addressW ); netconn_close( netconn ); return FALSE; } } - request->netconn = netconn; send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_CONNECTED_TO_SERVER, addressW, strlenW(addressW) + 1 ); } else @@ -1787,10 +1786,17 @@ static BOOL open_connection( request_t *request ) TRACE("using connection %p\n", netconn); netconn_set_timeout( netconn, TRUE, request->send_timeout ); - netconn_set_timeout( netconn, FALSE, request->recv_timeout ); + netconn_set_timeout( netconn, FALSE, request->receive_response_timeout ); request->netconn = netconn; } + if (netconn->secure && !(request->server_cert = netconn_get_certificate( netconn ))) + { + heap_free( addressW ); + netconn_close( netconn ); + return FALSE; + } + done: request->read_pos = request->read_size = 0; request->read_chunked = FALSE; @@ -1800,7 +1806,7 @@ done: return TRUE; } -void close_connection( request_t *request ) +void close_connection( struct request *request ) { if (!request->netconn) return; @@ -1810,13 +1816,13 @@ void close_connection( request_t *request ) send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_CONNECTION_CLOSED, 0, 0 ); } -static BOOL add_host_header( request_t *request, DWORD modifier ) +static BOOL add_host_header( struct request *request, DWORD modifier ) { BOOL ret; DWORD len; WCHAR *host; static const WCHAR fmt[] = {'%','s',':','%','u',0}; - connect_t *connect = request->connect; + struct connect *connect = request->connect; INTERNET_PORT port; port = connect->hostport ? connect->hostport : (request->hdr.flags & WINHTTP_FLAG_SECURE ? 443 : 80); @@ -1833,7 +1839,7 @@ static BOOL add_host_header( request_t *request, DWORD modifier ) return ret; } -static void clear_response_headers( request_t *request ) +static void clear_response_headers( struct request *request ) { unsigned int i; @@ -1848,14 +1854,14 @@ static void clear_response_headers( request_t *request ) } /* remove some amount of data from the read buffer */ -static void remove_data( request_t *request, int count ) +static void remove_data( struct request *request, int count ) { if (!(request->read_size -= count)) request->read_pos = 0; else request->read_pos += count; } /* read some more data into the read buffer */ -static BOOL read_more_data( request_t *request, int maxlen, BOOL notify ) +static BOOL read_more_data( struct request *request, int maxlen, BOOL notify ) { int len; BOOL ret; @@ -1882,7 +1888,7 @@ static BOOL read_more_data( request_t *request, int maxlen, BOOL notify ) } /* discard data contents until we reach end of line */ -static BOOL discard_eol( request_t *request, BOOL notify ) +static BOOL discard_eol( struct request *request, BOOL notify ) { do { @@ -1899,7 +1905,7 @@ static BOOL discard_eol( request_t *request, BOOL notify ) } /* read the size of the next chunk */ -static BOOL start_next_chunk( request_t *request, BOOL notify ) +static BOOL start_next_chunk( struct request *request, BOOL notify ) { DWORD chunk_size = 0; @@ -1942,7 +1948,7 @@ static BOOL start_next_chunk( request_t *request, BOOL notify ) } } -static BOOL refill_buffer( request_t *request, BOOL notify ) +static BOOL refill_buffer( struct request *request, BOOL notify ) { int len = sizeof(request->read_buf); @@ -1966,7 +1972,7 @@ static BOOL refill_buffer( request_t *request, BOOL notify ) return TRUE; } -static void finished_reading( request_t *request ) +static void finished_reading( struct request *request ) { static const WCHAR closeW[] = {'c','l','o','s','e',0}; @@ -1994,14 +2000,14 @@ static void finished_reading( request_t *request ) } /* return the size of data available to be read immediately */ -static DWORD get_available_data( request_t *request ) +static DWORD get_available_data( struct request *request ) { if (request->read_chunked) return min( request->read_chunked_size, request->read_size ); return request->read_size; } /* check if we have reached the end of the data to read */ -static BOOL end_of_read_data( request_t *request ) +static BOOL end_of_read_data( struct request *request ) { if (!request->content_length) return TRUE; if (request->read_chunked) return request->read_chunked_eof; @@ -2009,9 +2015,10 @@ static BOOL end_of_read_data( request_t *request ) return (request->content_length == request->content_read); } -static BOOL read_data( request_t *request, void *buffer, DWORD size, DWORD *read, BOOL async ) +static BOOL read_data( struct request *request, void *buffer, DWORD size, DWORD *read, BOOL async ) { int count, bytes_read = 0; + BOOL ret = TRUE; if (end_of_read_data( request )) goto done; @@ -2019,7 +2026,7 @@ static BOOL read_data( request_t *request, void *buffer, DWORD size, DWORD *read { if (!(count = get_available_data( request ))) { - if (!refill_buffer( request, async )) goto done; + if (!(ret = refill_buffer( request, async ))) goto done; if (!(count = get_available_data( request ))) goto done; } count = min( count, size ); @@ -2031,19 +2038,29 @@ static BOOL read_data( request_t *request, void *buffer, DWORD size, DWORD *read request->content_read += count; if (end_of_read_data( request )) goto done; } - if (request->read_chunked && !request->read_chunked_size) refill_buffer( request, async ); + if (request->read_chunked && !request->read_chunked_size) ret = refill_buffer( request, async ); done: TRACE( "retrieved %u bytes (%u/%u)\n", bytes_read, request->content_read, request->content_length ); + if (async) + { + if (ret) send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_READ_COMPLETE, buffer, bytes_read ); + else + { + WINHTTP_ASYNC_RESULT result; + result.dwResult = API_READ_DATA; + result.dwError = GetLastError(); + send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_REQUEST_ERROR, &result, sizeof(result) ); + } + } - if (async) send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_READ_COMPLETE, buffer, bytes_read ); - if (read) *read = bytes_read; + if (ret && read) *read = bytes_read; if (end_of_read_data( request )) finished_reading( request ); - return TRUE; + return ret; } /* read any content returned by the server so that the connection can be reused */ -static void drain_content( request_t *request ) +static void drain_content( struct request *request ) { DWORD size, bytes_read, bytes_total = 0, bytes_left = request->content_length - request->content_read; char buffer[2048]; @@ -2062,7 +2079,177 @@ static void drain_content( request_t *request ) } } -static BOOL send_request( request_t *request, LPCWSTR headers, DWORD headers_len, LPVOID optional, +enum escape_flags +{ + ESCAPE_FLAG_NON_PRINTABLE = 0x01, + ESCAPE_FLAG_SPACE = 0x02, + ESCAPE_FLAG_PERCENT = 0x04, + ESCAPE_FLAG_UNSAFE = 0x08, + ESCAPE_FLAG_DEL = 0x10, + ESCAPE_FLAG_8BIT = 0x20, + ESCAPE_FLAG_STRIP_CRLF = 0x40, +}; + +#define ESCAPE_MASK_DEFAULT (ESCAPE_FLAG_NON_PRINTABLE | ESCAPE_FLAG_SPACE | ESCAPE_FLAG_UNSAFE |\ + ESCAPE_FLAG_DEL | ESCAPE_FLAG_8BIT) +#define ESCAPE_MASK_PERCENT (ESCAPE_FLAG_PERCENT | ESCAPE_MASK_DEFAULT) +#define ESCAPE_MASK_DISABLE (ESCAPE_FLAG_SPACE | ESCAPE_FLAG_8BIT | ESCAPE_FLAG_STRIP_CRLF) + +static inline BOOL need_escape( char ch, enum escape_flags flags ) +{ + static const char unsafe[] = "\"#<>[\\]^`{|}"; + const char *ptr = unsafe; + + if ((flags & ESCAPE_FLAG_SPACE) && ch == ' ') return TRUE; + if ((flags & ESCAPE_FLAG_PERCENT) && ch == '%') return TRUE; + if ((flags & ESCAPE_FLAG_NON_PRINTABLE) && ch < 0x20) return TRUE; + if ((flags & ESCAPE_FLAG_DEL) && ch == 0x7f) return TRUE; + if ((flags & ESCAPE_FLAG_8BIT) && (ch & 0x80)) return TRUE; + if ((flags & ESCAPE_FLAG_UNSAFE)) while (*ptr) { if (ch == *ptr++) return TRUE; } + return FALSE; +} + +static DWORD escape_string( const char *src, DWORD len, char *dst, enum escape_flags flags ) +{ + static const char hex[] = "0123456789ABCDEF"; + DWORD i, ret = len; + char *ptr = dst; + + for (i = 0; i < len; i++) + { + if ((flags & ESCAPE_FLAG_STRIP_CRLF) && (src[i] == '\r' || src[i] == '\n')) + { + ret--; + continue; + } + if (need_escape( src[i], flags )) + { + if (dst) + { + ptr[0] = '%'; + ptr[1] = hex[(src[i] >> 4) & 0xf]; + ptr[2] = hex[src[i] & 0xf]; + ptr += 3; + } + ret += 2; + } + else if (dst) *ptr++ = src[i]; + } + + if (dst) dst[ret] = 0; + return ret; +} + +static DWORD str_to_wire( const WCHAR *src, int src_len, char *dst, enum escape_flags flags ) +{ + DWORD len; + char *utf8; + + if (src_len < 0) src_len = strlenW( src ); + len = WideCharToMultiByte( CP_UTF8, 0, src, src_len, NULL, 0, NULL, NULL ); + if (!(utf8 = heap_alloc( len ))) return 0; + + WideCharToMultiByte( CP_UTF8, 0, src, -1, utf8, len, NULL, NULL ); + len = escape_string( utf8, len, dst, flags ); + heap_free( utf8 ); + + return len; +} + +static char *build_wire_path( struct request *request, DWORD *ret_len ) +{ + WCHAR *full_path; + const WCHAR *start, *path, *query = NULL; + DWORD len, len_path = 0, len_query = 0; + enum escape_flags path_flags, query_flags; + char *ret; + + if (!strcmpiW( request->connect->hostname, request->connect->servername )) start = full_path = request->path; + else if (!(full_path = build_absolute_request_path( request, &start ))) return NULL; + + len = strlenW( full_path ); + if ((path = strchrW( start, '/' ))) + { + len_path = strlenW( path ); + if ((query = strchrW( path, '?' ))) + { + len_query = strlenW( query ); + len_path -= len_query; + } + } + + if (request->hdr.flags & WINHTTP_FLAG_ESCAPE_DISABLE) path_flags = ESCAPE_MASK_DISABLE; + else if (request->hdr.flags & WINHTTP_FLAG_ESCAPE_PERCENT) path_flags = ESCAPE_MASK_PERCENT; + else path_flags = ESCAPE_MASK_DEFAULT; + + if (request->hdr.flags & WINHTTP_FLAG_ESCAPE_DISABLE_QUERY) query_flags = ESCAPE_MASK_DISABLE; + else query_flags = path_flags; + + *ret_len = str_to_wire( full_path, len - len_path - len_query, NULL, 0 ); + if (path) *ret_len += str_to_wire( path, len_path, NULL, path_flags ); + if (query) *ret_len += str_to_wire( query, len_query, NULL, query_flags ); + + if ((ret = heap_alloc( *ret_len + 1 ))) + { + len = str_to_wire( full_path, len - len_path - len_query, ret, 0 ); + if (path) len += str_to_wire( path, len_path, ret + len, path_flags ); + if (query) str_to_wire( query, len_query, ret + len, query_flags ); + } + + if (full_path != request->path) heap_free( full_path ); + return ret; +} + +static char *build_wire_request( struct request *request, DWORD *len ) +{ + char *path, *ptr, *ret; + DWORD i, len_path; + + if (!(path = build_wire_path( request, &len_path ))) return NULL; + + *len = str_to_wire( request->verb, -1, NULL, 0 ) + 1; /* ' ' */ + *len += len_path + 1; /* ' ' */ + *len += str_to_wire( request->version, -1, NULL, 0 ); + + for (i = 0; i < request->num_headers; i++) + { + if (request->headers[i].is_request) + { + *len += str_to_wire( request->headers[i].field, -1, NULL, 0 ) + 2; /* ': ' */ + *len += str_to_wire( request->headers[i].value, -1, NULL, 0 ) + 2; /* '\r\n' */ + } + } + *len += 4; /* '\r\n\r\n' */ + + if ((ret = ptr = heap_alloc( *len + 1 ))) + { + ptr += str_to_wire( request->verb, -1, ptr, 0 ); + *ptr++ = ' '; + memcpy( ptr, path, len_path ); + ptr += len_path; + *ptr++ = ' '; + ptr += str_to_wire( request->version, -1, ptr, 0 ); + + for (i = 0; i < request->num_headers; i++) + { + if (request->headers[i].is_request) + { + *ptr++ = '\r'; + *ptr++ = '\n'; + ptr += str_to_wire( request->headers[i].field, -1, ptr, 0 ); + *ptr++ = ':'; + *ptr++ = ' '; + ptr += str_to_wire( request->headers[i].value, -1, ptr, 0 ); + } + } + memcpy( ptr, "\r\n\r\n", sizeof("\r\n\r\n") ); + } + + heap_free( path ); + return ret; +} + +static BOOL send_request( struct request *request, const WCHAR *headers, DWORD headers_len, void *optional, DWORD optional_len, DWORD total_len, DWORD_PTR context, BOOL async ) { static const WCHAR keep_alive[] = {'K','e','e','p','-','A','l','i','v','e',0}; @@ -2070,10 +2257,9 @@ static BOOL send_request( request_t *request, LPCWSTR headers, DWORD headers_len static const WCHAR length_fmt[] = {'%','l','d',0}; BOOL ret = FALSE; - connect_t *connect = request->connect; - session_t *session = connect->session; - WCHAR *req = NULL; - char *req_ascii; + struct connect *connect = request->connect; + struct session *session = connect->session; + char *wire_req; int bytes_sent; DWORD len; @@ -2118,16 +2304,13 @@ static BOOL send_request( request_t *request, LPCWSTR headers, DWORD headers_len if (context) request->hdr.context = context; if (!(ret = open_connection( request ))) goto end; - if (!(req = build_request_string( request ))) goto end; - - if (!(req_ascii = strdupWA( req ))) goto end; - TRACE("full request: %s\n", debugstr_a(req_ascii)); - len = strlen(req_ascii); + if (!(wire_req = build_wire_request( request, &len ))) goto end; + TRACE("full request: %s\n", debugstr_a(wire_req)); send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_SENDING_REQUEST, NULL, 0 ); - ret = netconn_send( request->netconn, req_ascii, len, &bytes_sent ); - heap_free( req_ascii ); + ret = netconn_send( request->netconn, wire_req, len, &bytes_sent ); + heap_free( wire_req ); if (!ret) goto end; if (optional_len) @@ -2147,17 +2330,16 @@ end: { WINHTTP_ASYNC_RESULT result; result.dwResult = API_SEND_REQUEST; - result.dwError = get_last_error(); + result.dwError = GetLastError(); send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_REQUEST_ERROR, &result, sizeof(result) ); } } - heap_free( req ); return ret; } -static void task_send_request( task_header_t *task ) +static void task_send_request( struct task_header *task ) { - send_request_t *s = (send_request_t *)task; + struct send_request *s = (struct send_request *)task; send_request( s->hdr.request, s->headers, s->headers_len, s->optional, s->optional_len, s->total_len, s->context, TRUE ); heap_free( s->headers ); } @@ -2169,20 +2351,20 @@ BOOL WINAPI WinHttpSendRequest( HINTERNET hrequest, LPCWSTR headers, DWORD heade LPVOID optional, DWORD optional_len, DWORD total_len, DWORD_PTR context ) { BOOL ret; - request_t *request; + struct request *request; - TRACE("%p, %s, %u, %u, %u, %lx\n", hrequest, debugstr_wn(headers, headers_len), headers_len, optional_len, - total_len, context); + TRACE("%p, %s, %u, %p, %u, %u, %lx\n", hrequest, debugstr_wn(headers, headers_len), headers_len, optional, + optional_len, total_len, context); - if (!(request = (request_t *)grab_object( hrequest ))) + if (!(request = (struct request *)grab_object( hrequest ))) { - set_last_error( ERROR_INVALID_HANDLE ); + SetLastError( ERROR_INVALID_HANDLE ); return FALSE; } if (request->hdr.type != WINHTTP_HANDLE_TYPE_REQUEST) { release_object( &request->hdr ); - set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); + SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); return FALSE; } @@ -2190,9 +2372,9 @@ BOOL WINAPI WinHttpSendRequest( HINTERNET hrequest, LPCWSTR headers, DWORD heade if (request->connect->hdr.flags & WINHTTP_FLAG_ASYNC) { - send_request_t *s; + struct send_request *s; - if (!(s = heap_alloc( sizeof(send_request_t) ))) return FALSE; + if (!(s = heap_alloc( sizeof(struct send_request) ))) return FALSE; s->hdr.request = request; s->hdr.proc = task_send_request; s->headers = strdupW( headers ); @@ -2203,24 +2385,24 @@ BOOL WINAPI WinHttpSendRequest( HINTERNET hrequest, LPCWSTR headers, DWORD heade s->context = context; addref_object( &request->hdr ); - ret = queue_task( (task_header_t *)s ); + ret = queue_task( (struct task_header *)s ); } else ret = send_request( request, headers, headers_len, optional, optional_len, total_len, context, FALSE ); release_object( &request->hdr ); - if (ret) set_last_error( ERROR_SUCCESS ); + if (ret) SetLastError( ERROR_SUCCESS ); return ret; } -static BOOL set_credentials( request_t *request, DWORD target, DWORD scheme_flag, const WCHAR *username, +static BOOL set_credentials( struct request *request, DWORD target, DWORD scheme_flag, const WCHAR *username, const WCHAR *password ) { enum auth_scheme scheme = scheme_from_flag( scheme_flag ); if (scheme == SCHEME_INVALID || ((scheme == SCHEME_BASIC || scheme == SCHEME_DIGEST) && (!username || !password))) { - set_last_error( ERROR_INVALID_PARAMETER ); + SetLastError( ERROR_INVALID_PARAMETER ); return FALSE; } switch (target) @@ -2261,30 +2443,30 @@ BOOL WINAPI WinHttpSetCredentials( HINTERNET hrequest, DWORD target, DWORD schem LPCWSTR password, LPVOID params ) { BOOL ret; - request_t *request; + struct request *request; TRACE("%p, %x, 0x%08x, %s, %p, %p\n", hrequest, target, scheme, debugstr_w(username), password, params); - if (!(request = (request_t *)grab_object( hrequest ))) + if (!(request = (struct request *)grab_object( hrequest ))) { - set_last_error( ERROR_INVALID_HANDLE ); + SetLastError( ERROR_INVALID_HANDLE ); return FALSE; } if (request->hdr.type != WINHTTP_HANDLE_TYPE_REQUEST) { release_object( &request->hdr ); - set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); + SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); return FALSE; } ret = set_credentials( request, target, scheme, username, password ); release_object( &request->hdr ); - if (ret) set_last_error( ERROR_SUCCESS ); + if (ret) SetLastError( ERROR_SUCCESS ); return ret; } -static BOOL handle_authorization( request_t *request, DWORD status ) +static BOOL handle_authorization( struct request *request, DWORD status ) { DWORD i, schemes, first, level, target; @@ -2309,7 +2491,7 @@ static BOOL handle_authorization( request_t *request, DWORD status ) if (do_authorization( request, target, first )) return TRUE; schemes &= ~first; - for (i = 0; i < num_auth_schemes; i++) + for (i = 0; i < ARRAY_SIZE( auth_schemes ); i++) { if (!(schemes & auth_schemes[i].scheme)) continue; if (do_authorization( request, target, auth_schemes[i].scheme )) return TRUE; @@ -2318,7 +2500,7 @@ static BOOL handle_authorization( request_t *request, DWORD status ) } /* set the request content length based on the headers */ -static DWORD set_content_length( request_t *request, DWORD status ) +static DWORD set_content_length( struct request *request, DWORD status ) { WCHAR encoding[20]; DWORD buflen = sizeof(request->content_length); @@ -2345,7 +2527,7 @@ static DWORD set_content_length( request_t *request, DWORD status ) return request->content_length; } -static BOOL read_line( request_t *request, char *buffer, DWORD *len ) +static BOOL read_line( struct request *request, char *buffer, DWORD *len ) { int count, bytes_read, pos = 0; @@ -2386,7 +2568,7 @@ static BOOL read_line( request_t *request, char *buffer, DWORD *len ) #define MAX_REPLY_LEN 1460 #define INITIAL_HEADER_BUFFER_LEN 512 -static BOOL read_reply( request_t *request ) +static BOOL read_reply( struct request *request ) { static const WCHAR crlf[] = {'\r','\n',0}; @@ -2450,7 +2632,7 @@ static BOOL read_reply( request_t *request ) offset = buflen + crlf_len - 1; for (;;) { - header_t *header; + struct header *header; buflen = MAX_REPLY_LEN; if (!read_line( request, buffer, &buflen )) return TRUE; @@ -2485,13 +2667,13 @@ static BOOL read_reply( request_t *request ) return TRUE; } -static void record_cookies( request_t *request ) +static void record_cookies( struct request *request ) { unsigned int i; for (i = 0; i < request->num_headers; i++) { - header_t *set_cookie = &request->headers[i]; + struct header *set_cookie = &request->headers[i]; if (!strcmpiW( set_cookie->field, attr_set_cookie ) && !set_cookie->is_request) { set_cookies( request, set_cookie->value ); @@ -2499,59 +2681,60 @@ static void record_cookies( request_t *request ) } } -static WCHAR *get_redirect_url( request_t *request, DWORD *len ) +static WCHAR *get_redirect_url( struct request *request, DWORD *len ) { DWORD size; WCHAR *ret; query_headers( request, WINHTTP_QUERY_LOCATION, NULL, NULL, &size, NULL ); - if (get_last_error() != ERROR_INSUFFICIENT_BUFFER) return FALSE; + if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) return NULL; if (!(ret = heap_alloc( size ))) return NULL; - *len = size / sizeof(WCHAR); + *len = size / sizeof(WCHAR) - 1; if (query_headers( request, WINHTTP_QUERY_LOCATION, NULL, ret, &size, NULL )) return ret; heap_free( ret ); return NULL; } -static BOOL handle_redirect( request_t *request, DWORD status ) +static BOOL handle_redirect( struct request *request, DWORD status ) { BOOL ret = FALSE; - DWORD len, len_url; + DWORD len, len_loc; URL_COMPONENTS uc; - connect_t *connect = request->connect; + struct connect *connect = request->connect; INTERNET_PORT port; WCHAR *hostname = NULL, *location; int index; - if (!(location = get_redirect_url( request, &len_url ))) return FALSE; + if (!(location = get_redirect_url( request, &len_loc ))) return FALSE; memset( &uc, 0, sizeof(uc) ); uc.dwStructSize = sizeof(uc); uc.dwSchemeLength = uc.dwHostNameLength = uc.dwUrlPathLength = uc.dwExtraInfoLength = ~0u; - if (!WinHttpCrackUrl( location, len_url, 0, &uc )) /* assume relative redirect */ + if (!WinHttpCrackUrl( location, len_loc, 0, &uc )) /* assume relative redirect */ { WCHAR *path, *p; if (location[0] == '/') { - len = strlenW( location ); - if (!(path = heap_alloc( (len + 1) * sizeof(WCHAR) ))) goto end; - strcpyW( path, location ); + if (!(path = heap_alloc( (len_loc + 1) * sizeof(WCHAR) ))) goto end; + memcpy( path, location, len_loc * sizeof(WCHAR) ); + path[len_loc] = 0; } else { if ((p = strrchrW( request->path, '/' ))) *p = 0; - len = strlenW( request->path ) + 1 + strlenW( location ); + len = strlenW( request->path ) + 1 + len_loc; if (!(path = heap_alloc( (len + 1) * sizeof(WCHAR) ))) goto end; strcpyW( path, request->path ); strcatW( path, slashW ); - strcatW( path, location ); + memcpy( path + strlenW(path), location, len_loc * sizeof(WCHAR) ); + path[len_loc] = 0; } heap_free( request->path ); request->path = path; - send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_REDIRECT, location, len_url + 1 ); + send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_REDIRECT, location, len_loc + 1 ); } else { @@ -2567,7 +2750,7 @@ static BOOL handle_redirect( request_t *request, DWORD status ) request->hdr.flags |= WINHTTP_FLAG_SECURE; } - send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_REDIRECT, location, len_url + 1 ); + send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_REDIRECT, location, len_loc + 1 ); len = uc.dwHostNameLength; if (!(hostname = heap_alloc( (len + 1) * sizeof(WCHAR) ))) goto end; @@ -2599,7 +2782,8 @@ static BOOL handle_redirect( request_t *request, DWORD status ) { len = uc.dwUrlPathLength + uc.dwExtraInfoLength; if (!(request->path = heap_alloc( (len + 1) * sizeof(WCHAR) ))) goto end; - strcpyW( request->path, uc.lpszUrlPath ); + memcpy( request->path, uc.lpszUrlPath, (len + 1) * sizeof(WCHAR) ); + request->path[len] = 0; } else request->path = strdupW( slashW ); } @@ -2622,16 +2806,59 @@ end: return ret; } -static BOOL receive_response( request_t *request, BOOL async ) +static BOOL is_passport_request( struct request *request ) +{ + static const WCHAR passportW[] = {'P','a','s','s','p','o','r','t','1','.','4'}; + WCHAR buf[1024]; + DWORD len = ARRAY_SIZE(buf); + + if (!(request->connect->session->passport_flags & WINHTTP_ENABLE_PASSPORT_AUTH) || + !query_headers( request, WINHTTP_QUERY_WWW_AUTHENTICATE, NULL, buf, &len, NULL )) return FALSE; + + if (!strncmpiW( buf, passportW, ARRAY_SIZE(passportW) ) && + (buf[ARRAY_SIZE(passportW)] == ' ' || !buf[ARRAY_SIZE(passportW)])) return TRUE; + + return FALSE; +} + +static BOOL handle_passport_redirect( struct request *request ) +{ + static const WCHAR status401W[] = {'4','0','1',0}; + DWORD flags = WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_REPLACE; + int i, len = strlenW( request->raw_headers ); + WCHAR *p = request->raw_headers; + + if (!process_header( request, attr_status, status401W, flags, FALSE )) return FALSE; + + for (i = 0; i < len; i++) + { + if (i <= len - 3 && p[i] == '3' && p[i + 1] == '0' && p[i + 2] == '2') + { + p[i] = '4'; + p[i + 2] = '1'; + break; + } + } + return TRUE; +} + +static BOOL receive_response( struct request *request, BOOL async ) { BOOL ret; DWORD size, query, status; + if (!request->netconn) + { + SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_STATE ); + return FALSE; + } + + netconn_set_timeout( request->netconn, FALSE, request->receive_response_timeout ); for (;;) { if (!(ret = read_reply( request ))) { - set_last_error( ERROR_WINHTTP_INVALID_SERVER_RESPONSE ); + SetLastError( ERROR_WINHTTP_INVALID_SERVER_RESPONSE ); break; } size = sizeof(DWORD); @@ -2642,7 +2869,11 @@ static BOOL receive_response( request_t *request, BOOL async ) if (!(request->hdr.disable_flags & WINHTTP_DISABLE_COOKIES)) record_cookies( request ); - if (status == HTTP_STATUS_MOVED || status == HTTP_STATUS_REDIRECT || status == HTTP_STATUS_REDIRECT_KEEP_VERB) + if (status == HTTP_STATUS_REDIRECT && is_passport_request( request )) + { + ret = handle_passport_redirect( request ); + } + else if (status == HTTP_STATUS_MOVED || status == HTTP_STATUS_REDIRECT || status == HTTP_STATUS_REDIRECT_KEEP_VERB) { if (request->hdr.disable_flags & WINHTTP_DISABLE_REDIRECTS || request->hdr.redirect_policy == WINHTTP_OPTION_REDIRECT_POLICY_NEVER) break; @@ -2664,7 +2895,8 @@ static BOOL receive_response( request_t *request, BOOL async ) break; } - if (request->content_length) refill_buffer( request, FALSE ); + netconn_set_timeout( request->netconn, FALSE, request->receive_timeout ); + if (request->content_length) ret = refill_buffer( request, FALSE ); if (async) { @@ -2673,16 +2905,16 @@ static BOOL receive_response( request_t *request, BOOL async ) { WINHTTP_ASYNC_RESULT result; result.dwResult = API_RECEIVE_RESPONSE; - result.dwError = get_last_error(); + result.dwError = GetLastError(); send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_REQUEST_ERROR, &result, sizeof(result) ); } } return ret; } -static void task_receive_response( task_header_t *task ) +static void task_receive_response( struct task_header *task ) { - receive_response_t *r = (receive_response_t *)task; + struct receive_response *r = (struct receive_response *)task; receive_response( r->hdr.request, TRUE ); } @@ -2692,68 +2924,78 @@ static void task_receive_response( task_header_t *task ) BOOL WINAPI WinHttpReceiveResponse( HINTERNET hrequest, LPVOID reserved ) { BOOL ret; - request_t *request; + struct request *request; TRACE("%p, %p\n", hrequest, reserved); - if (!(request = (request_t *)grab_object( hrequest ))) + if (!(request = (struct request *)grab_object( hrequest ))) { - set_last_error( ERROR_INVALID_HANDLE ); + SetLastError( ERROR_INVALID_HANDLE ); return FALSE; } if (request->hdr.type != WINHTTP_HANDLE_TYPE_REQUEST) { release_object( &request->hdr ); - set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); + SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); return FALSE; } if (request->connect->hdr.flags & WINHTTP_FLAG_ASYNC) { - receive_response_t *r; + struct receive_response *r; - if (!(r = heap_alloc( sizeof(receive_response_t) ))) return FALSE; + if (!(r = heap_alloc( sizeof(struct receive_response) ))) return FALSE; r->hdr.request = request; r->hdr.proc = task_receive_response; addref_object( &request->hdr ); - ret = queue_task( (task_header_t *)r ); + ret = queue_task( (struct task_header *)r ); } else ret = receive_response( request, FALSE ); release_object( &request->hdr ); - if (ret) set_last_error( ERROR_SUCCESS ); + if (ret) SetLastError( ERROR_SUCCESS ); return ret; } -static BOOL query_data_available( request_t *request, DWORD *available, BOOL async ) +static BOOL query_data_available( struct request *request, DWORD *available, BOOL async ) { DWORD count = 0; + BOOL ret = TRUE; if (end_of_read_data( request )) goto done; count = get_available_data( request ); - if (!request->read_chunked && request->netconn) - count += netconn_query_data_available( request->netconn ); + if (!request->read_chunked && request->netconn) count += netconn_query_data_available( request->netconn ); if (!count) { - refill_buffer( request, async ); + if (!(ret = refill_buffer( request, async ))) goto done; count = get_available_data( request ); - if (!request->read_chunked && request->netconn) - count += netconn_query_data_available( request->netconn ); + if (!request->read_chunked && request->netconn) count += netconn_query_data_available( request->netconn ); } done: - if (async) send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_DATA_AVAILABLE, &count, sizeof(count) ); TRACE("%u bytes available\n", count); - if (available) *available = count; - return TRUE; + if (async) + { + if (ret) send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_DATA_AVAILABLE, &count, sizeof(count) ); + else + { + WINHTTP_ASYNC_RESULT result; + result.dwResult = API_QUERY_DATA_AVAILABLE; + result.dwError = GetLastError(); + send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_REQUEST_ERROR, &result, sizeof(result) ); + } + } + + if (ret && available) *available = count; + return ret; } -static void task_query_data_available( task_header_t *task ) +static void task_query_data_available( struct task_header *task ) { - query_data_t *q = (query_data_t *)task; + struct query_data *q = (struct query_data *)task; query_data_available( q->hdr.request, q->available, TRUE ); } @@ -2763,45 +3005,45 @@ static void task_query_data_available( task_header_t *task ) BOOL WINAPI WinHttpQueryDataAvailable( HINTERNET hrequest, LPDWORD available ) { BOOL ret; - request_t *request; + struct request *request; TRACE("%p, %p\n", hrequest, available); - if (!(request = (request_t *)grab_object( hrequest ))) + if (!(request = (struct request *)grab_object( hrequest ))) { - set_last_error( ERROR_INVALID_HANDLE ); + SetLastError( ERROR_INVALID_HANDLE ); return FALSE; } if (request->hdr.type != WINHTTP_HANDLE_TYPE_REQUEST) { release_object( &request->hdr ); - set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); + SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); return FALSE; } if (request->connect->hdr.flags & WINHTTP_FLAG_ASYNC) { - query_data_t *q; + struct query_data *q; - if (!(q = heap_alloc( sizeof(query_data_t) ))) return FALSE; + if (!(q = heap_alloc( sizeof(struct query_data) ))) return FALSE; q->hdr.request = request; q->hdr.proc = task_query_data_available; q->available = available; addref_object( &request->hdr ); - ret = queue_task( (task_header_t *)q ); + ret = queue_task( (struct task_header *)q ); } else ret = query_data_available( request, available, FALSE ); release_object( &request->hdr ); - if (ret) set_last_error( ERROR_SUCCESS ); + if (ret) SetLastError( ERROR_SUCCESS ); return ret; } -static void task_read_data( task_header_t *task ) +static void task_read_data( struct task_header *task ) { - read_data_t *r = (read_data_t *)task; + struct read_data *r = (struct read_data *)task; read_data( r->hdr.request, r->buffer, r->to_read, r->read, TRUE ); } @@ -2811,27 +3053,27 @@ static void task_read_data( task_header_t *task ) BOOL WINAPI WinHttpReadData( HINTERNET hrequest, LPVOID buffer, DWORD to_read, LPDWORD read ) { BOOL ret; - request_t *request; + struct request *request; TRACE("%p, %p, %d, %p\n", hrequest, buffer, to_read, read); - if (!(request = (request_t *)grab_object( hrequest ))) + if (!(request = (struct request *)grab_object( hrequest ))) { - set_last_error( ERROR_INVALID_HANDLE ); + SetLastError( ERROR_INVALID_HANDLE ); return FALSE; } if (request->hdr.type != WINHTTP_HANDLE_TYPE_REQUEST) { release_object( &request->hdr ); - set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); + SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); return FALSE; } if (request->connect->hdr.flags & WINHTTP_FLAG_ASYNC) { - read_data_t *r; + struct read_data *r; - if (!(r = heap_alloc( sizeof(read_data_t) ))) return FALSE; + if (!(r = heap_alloc( sizeof(struct read_data) ))) return FALSE; r->hdr.request = request; r->hdr.proc = task_read_data; r->buffer = buffer; @@ -2839,17 +3081,17 @@ BOOL WINAPI WinHttpReadData( HINTERNET hrequest, LPVOID buffer, DWORD to_read, L r->read = read; addref_object( &request->hdr ); - ret = queue_task( (task_header_t *)r ); + ret = queue_task( (struct task_header *)r ); } else ret = read_data( request, buffer, to_read, read, FALSE ); release_object( &request->hdr ); - if (ret) set_last_error( ERROR_SUCCESS ); + if (ret) SetLastError( ERROR_SUCCESS ); return ret; } -static BOOL write_data( request_t *request, LPCVOID buffer, DWORD to_write, LPDWORD written, BOOL async ) +static BOOL write_data( struct request *request, const void *buffer, DWORD to_write, DWORD *written, BOOL async ) { BOOL ret; int num_bytes; @@ -2863,7 +3105,7 @@ static BOOL write_data( request_t *request, LPCVOID buffer, DWORD to_write, LPDW { WINHTTP_ASYNC_RESULT result; result.dwResult = API_WRITE_DATA; - result.dwError = get_last_error(); + result.dwError = GetLastError(); send_callback( &request->hdr, WINHTTP_CALLBACK_STATUS_REQUEST_ERROR, &result, sizeof(result) ); } } @@ -2871,9 +3113,9 @@ static BOOL write_data( request_t *request, LPCVOID buffer, DWORD to_write, LPDW return ret; } -static void task_write_data( task_header_t *task ) +static void task_write_data( struct task_header *task ) { - write_data_t *w = (write_data_t *)task; + struct write_data *w = (struct write_data *)task; write_data( w->hdr.request, w->buffer, w->to_write, w->written, TRUE ); } @@ -2883,27 +3125,27 @@ static void task_write_data( task_header_t *task ) BOOL WINAPI WinHttpWriteData( HINTERNET hrequest, LPCVOID buffer, DWORD to_write, LPDWORD written ) { BOOL ret; - request_t *request; + struct request *request; TRACE("%p, %p, %d, %p\n", hrequest, buffer, to_write, written); - if (!(request = (request_t *)grab_object( hrequest ))) + if (!(request = (struct request *)grab_object( hrequest ))) { - set_last_error( ERROR_INVALID_HANDLE ); + SetLastError( ERROR_INVALID_HANDLE ); return FALSE; } if (request->hdr.type != WINHTTP_HANDLE_TYPE_REQUEST) { release_object( &request->hdr ); - set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); + SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); return FALSE; } if (request->connect->hdr.flags & WINHTTP_FLAG_ASYNC) { - write_data_t *w; + struct write_data *w; - if (!(w = heap_alloc( sizeof(write_data_t) ))) return FALSE; + if (!(w = heap_alloc( sizeof(struct write_data) ))) return FALSE; w->hdr.request = request; w->hdr.proc = task_write_data; w->buffer = buffer; @@ -2911,19 +3153,18 @@ BOOL WINAPI WinHttpWriteData( HINTERNET hrequest, LPCVOID buffer, DWORD to_write w->written = written; addref_object( &request->hdr ); - ret = queue_task( (task_header_t *)w ); + ret = queue_task( (struct task_header *)w ); } else ret = write_data( request, buffer, to_write, written, FALSE ); release_object( &request->hdr ); - if (ret) set_last_error( ERROR_SUCCESS ); + if (ret) SetLastError( ERROR_SUCCESS ); return ret; } enum request_state { - REQUEST_STATE_UNINITIALIZED, REQUEST_STATE_INITIALIZED, REQUEST_STATE_CANCELLED, REQUEST_STATE_OPEN, @@ -2942,9 +3183,16 @@ struct winhttp_request HINTERNET hrequest; VARIANT data; WCHAR *verb; +#ifdef __REACTOS__ HANDLE thread; +#else + HANDLE done; +#endif HANDLE wait; HANDLE cancel; +#ifndef __REACTOS__ + BOOL proc_running; +#endif char *buffer; DWORD offset; DWORD bytes_available; @@ -2978,6 +3226,7 @@ static void cancel_request( struct winhttp_request *request ) { if (request->state <= REQUEST_STATE_CANCELLED) return; +#ifdef __REACTOS__ SetEvent( request->cancel ); LeaveCriticalSection( &request->cs ); WaitForSingleObject( request->thread, INFINITE ); @@ -2987,10 +3236,18 @@ static void cancel_request( struct winhttp_request *request ) CloseHandle( request->thread ); request->thread = NULL; - CloseHandle( request->wait ); - request->wait = NULL; - CloseHandle( request->cancel ); - request->cancel = NULL; +#else + if (request->proc_running) + { + SetEvent( request->cancel ); + LeaveCriticalSection( &request->cs ); + + WaitForSingleObject( request->done, INFINITE ); + + EnterCriticalSection( &request->cs ); + } + request->state = REQUEST_STATE_CANCELLED; +#endif } /* critical section must be held */ @@ -3000,7 +3257,11 @@ static void free_request( struct winhttp_request *request ) WinHttpCloseHandle( request->hrequest ); WinHttpCloseHandle( request->hconnect ); WinHttpCloseHandle( request->hsession ); +#ifdef __REACTOS__ CloseHandle( request->thread ); +#else + CloseHandle( request->done ); +#endif CloseHandle( request->wait ); CloseHandle( request->cancel ); heap_free( (WCHAR *)request->proxy.lpszProxy ); @@ -3118,7 +3379,7 @@ void release_typelib(void) { unsigned i; - for (i = 0; i < sizeof(winhttp_typeinfo)/sizeof(*winhttp_typeinfo); i++) + for (i = 0; i < ARRAY_SIZE(winhttp_typeinfo); i++) if (winhttp_typeinfo[i]) ITypeInfo_Release(winhttp_typeinfo[i]); @@ -3318,7 +3579,7 @@ static HRESULT WINAPI winhttp_request_SetCredentials( } if (!WinHttpSetCredentials( request->hrequest, target, scheme, username, password, NULL )) { - err = get_last_error(); + err = GetLastError(); } done: LeaveCriticalSection( &request->cs ); @@ -3327,25 +3588,11 @@ done: static void initialize_request( struct winhttp_request *request ) { - request->hrequest = NULL; - request->hconnect = NULL; - request->hsession = NULL; - request->thread = NULL; - request->wait = NULL; - request->cancel = NULL; - request->buffer = NULL; - request->verb = NULL; - request->offset = 0; - request->bytes_available = 0; - request->bytes_read = 0; - request->error = ERROR_SUCCESS; - request->async = FALSE; - request->logon_policy = WINHTTP_AUTOLOGON_SECURITY_LEVEL_MEDIUM; - request->disable_feature = 0; - request->proxy.dwAccessType = WINHTTP_ACCESS_TYPE_DEFAULT_PROXY; - request->proxy.lpszProxy = NULL; - request->proxy.lpszProxyBypass = NULL; - request->resolve_timeout = 0; + request->wait = CreateEventW( NULL, FALSE, FALSE, NULL ); + request->cancel = CreateEventW( NULL, FALSE, FALSE, NULL ); +#ifndef __REACTOS__ + request->done = CreateEventW( NULL, FALSE, FALSE, NULL ); +#endif request->connect_timeout = 60000; request->send_timeout = 30000; request->receive_timeout = 30000; @@ -3369,8 +3616,17 @@ static void reset_request( struct winhttp_request *request ) request->bytes_available = 0; request->bytes_read = 0; request->error = ERROR_SUCCESS; + request->logon_policy = 0; + request->disable_feature = 0; request->async = FALSE; + request->connect_timeout = 60000; + request->send_timeout = 30000; + request->receive_timeout = 30000; request->url_codepage = CP_UTF8; + heap_free( request->proxy.lpszProxy ); + request->proxy.lpszProxy = NULL; + heap_free( request->proxy.lpszProxyBypass ); + request->proxy.lpszProxyBypass = NULL; VariantClear( &request->data ); request->state = REQUEST_STATE_INITIALIZED; } @@ -3404,11 +3660,10 @@ static HRESULT WINAPI winhttp_request_Open( uc.dwHostNameLength = ~0u; uc.dwUrlPathLength = ~0u; uc.dwExtraInfoLength = ~0u; - if (!WinHttpCrackUrl( url, 0, 0, &uc )) return HRESULT_FROM_WIN32( get_last_error() ); + if (!WinHttpCrackUrl( url, 0, 0, &uc )) return HRESULT_FROM_WIN32( GetLastError() ); EnterCriticalSection( &request->cs ); - if (request->state < REQUEST_STATE_INITIALIZED) initialize_request( request ); - else reset_request( request ); + reset_request( request ); if (!(hostname = heap_alloc( (uc.dwHostNameLength + 1) * sizeof(WCHAR) ))) goto error; memcpy( hostname, uc.lpszHostName, uc.dwHostNameLength * sizeof(WCHAR) ); @@ -3427,31 +3682,31 @@ static HRESULT WINAPI winhttp_request_Open( if (!(request->hsession = WinHttpOpen( user_agentW, WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, NULL, NULL, WINHTTP_FLAG_ASYNC ))) { - err = get_last_error(); + err = GetLastError(); goto error; } if (!(request->hconnect = WinHttpConnect( request->hsession, hostname, uc.nPort, 0 ))) { WinHttpCloseHandle( request->hsession ); request->hsession = NULL; - err = get_last_error(); + err = GetLastError(); goto error; } } else if (!(request->hconnect = WinHttpConnect( request->hsession, hostname, uc.nPort, 0 ))) { - err = get_last_error(); + err = GetLastError(); goto error; } - len = sizeof(httpsW) / sizeof(WCHAR); + len = ARRAY_SIZE( httpsW ); if (uc.dwSchemeLength == len && !memcmp( uc.lpszScheme, httpsW, len * sizeof(WCHAR) )) { flags |= WINHTTP_FLAG_SECURE; } if (!(request->hrequest = WinHttpOpenRequest( request->hconnect, method, path, NULL, NULL, acceptW, flags ))) { - err = get_last_error(); + err = GetLastError(); goto error; } WinHttpSetOption( request->hrequest, WINHTTP_OPTION_CONTEXT_VALUE, &request, sizeof(request) ); @@ -3510,7 +3765,7 @@ static HRESULT WINAPI winhttp_request_SetRequestHeader( if (!WinHttpAddRequestHeaders( request->hrequest, str, len, WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_REPLACE )) { - err = get_last_error(); + err = GetLastError(); } heap_free( str ); @@ -3543,7 +3798,7 @@ static HRESULT WINAPI winhttp_request_GetResponseHeader( size = 0; if (!WinHttpQueryHeaders( request->hrequest, WINHTTP_QUERY_CUSTOM, header, NULL, &size, NULL )) { - err = get_last_error(); + err = GetLastError(); if (err != ERROR_INSUFFICIENT_BUFFER) goto done; } if (!(*value = SysAllocStringLen( NULL, size / sizeof(WCHAR) ))) @@ -3554,7 +3809,7 @@ static HRESULT WINAPI winhttp_request_GetResponseHeader( err = ERROR_SUCCESS; if (!WinHttpQueryHeaders( request->hrequest, WINHTTP_QUERY_CUSTOM, header, *value, &size, NULL )) { - err = get_last_error(); + err = GetLastError(); SysFreeString( *value ); } done: @@ -3582,7 +3837,7 @@ static HRESULT WINAPI winhttp_request_GetAllResponseHeaders( size = 0; if (!WinHttpQueryHeaders( request->hrequest, WINHTTP_QUERY_RAW_HEADERS_CRLF, NULL, NULL, &size, NULL )) { - err = get_last_error(); + err = GetLastError(); if (err != ERROR_INSUFFICIENT_BUFFER) goto done; } if (!(*headers = SysAllocStringLen( NULL, size / sizeof(WCHAR) ))) @@ -3593,7 +3848,7 @@ static HRESULT WINAPI winhttp_request_GetAllResponseHeaders( err = ERROR_SUCCESS; if (!WinHttpQueryHeaders( request->hrequest, WINHTTP_QUERY_RAW_HEADERS_CRLF, NULL, *headers, &size, NULL )) { - err = get_last_error(); + err = GetLastError(); SysFreeString( *headers ); } done: @@ -3621,7 +3876,9 @@ static void CALLBACK wait_status_callback( HINTERNET handle, DWORD_PTR context, request->error = result->dwError; break; } - default: break; + default: + request->error = ERROR_SUCCESS; + break; } SetEvent( request->wait ); } @@ -3635,19 +3892,38 @@ static void wait_set_status_callback( struct winhttp_request *request, DWORD sta static DWORD wait_for_completion( struct winhttp_request *request ) { HANDLE handles[2] = { request->wait, request->cancel }; +#ifndef __REACTOS__ + DWORD ret; +#endif switch (WaitForMultipleObjects( 2, handles, FALSE, INFINITE )) { case WAIT_OBJECT_0: +#ifndef __REACTOS__ + ret = request->error; +#endif break; case WAIT_OBJECT_0 + 1: +#ifdef __REACTOS__ request->error = ERROR_CANCELLED; +#else + ret = request->error = ERROR_CANCELLED; + SetEvent( request->done ); +#endif break; default: - request->error = get_last_error(); +#ifdef __REACTOS__ + request->error = GetLastError(); +#else + ret = request->error = GetLastError(); +#endif break; } +#ifdef __REACTOS__ return request->error; +#else + return ret; +#endif } static HRESULT request_receive( struct winhttp_request *request ) @@ -3657,7 +3933,7 @@ static HRESULT request_receive( struct winhttp_request *request ) wait_set_status_callback( request, WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE ); if (!WinHttpReceiveResponse( request->hrequest, NULL )) { - return HRESULT_FROM_WIN32( get_last_error() ); + return HRESULT_FROM_WIN32( GetLastError() ); } if ((err = wait_for_completion( request ))) return HRESULT_FROM_WIN32( err ); if (!strcmpW( request->verb, headW )) @@ -3673,7 +3949,7 @@ static HRESULT request_receive( struct winhttp_request *request ) wait_set_status_callback( request, WINHTTP_CALLBACK_STATUS_DATA_AVAILABLE ); if (!WinHttpQueryDataAvailable( request->hrequest, &request->bytes_available )) { - err = get_last_error(); + err = GetLastError(); goto error; } if ((err = wait_for_completion( request ))) goto error; @@ -3694,7 +3970,7 @@ static HRESULT request_receive( struct winhttp_request *request ) if (!WinHttpReadData( request->hrequest, request->buffer + request->offset, request->bytes_available, &request->bytes_read )) { - err = get_last_error(); + err = GetLastError(); goto error; } if ((err = wait_for_completion( request ))) goto error; @@ -3713,19 +3989,19 @@ error: static DWORD request_set_parameters( struct winhttp_request *request ) { if (!WinHttpSetOption( request->hrequest, WINHTTP_OPTION_PROXY, &request->proxy, - sizeof(request->proxy) )) return get_last_error(); + sizeof(request->proxy) )) return GetLastError(); if (!WinHttpSetOption( request->hrequest, WINHTTP_OPTION_AUTOLOGON_POLICY, &request->logon_policy, - sizeof(request->logon_policy) )) return get_last_error(); + sizeof(request->logon_policy) )) return GetLastError(); if (!WinHttpSetOption( request->hrequest, WINHTTP_OPTION_DISABLE_FEATURE, &request->disable_feature, - sizeof(request->disable_feature) )) return get_last_error(); + sizeof(request->disable_feature) )) return GetLastError(); if (!WinHttpSetTimeouts( request->hrequest, request->resolve_timeout, request->connect_timeout, request->send_timeout, - request->receive_timeout )) return get_last_error(); + request->receive_timeout )) return GetLastError(); return ERROR_SUCCESS; } @@ -3790,7 +4066,7 @@ static HRESULT request_send( struct winhttp_request *request ) wait_set_status_callback( request, WINHTTP_CALLBACK_STATUS_REQUEST_SENT ); if (!WinHttpSendRequest( request->hrequest, NULL, 0, ptr, size, size, 0 )) { - err = get_last_error(); + err = GetLastError(); goto error; } if ((err = wait_for_completion( request ))) goto error; @@ -3805,6 +4081,7 @@ error: return HRESULT_FROM_WIN32( err ); } +#ifdef __REACTOS__ static HRESULT request_send_and_receive( struct winhttp_request *request ) { HRESULT hr = request_send( request ); @@ -3817,15 +4094,31 @@ static DWORD CALLBACK send_and_receive_proc( void *arg ) struct winhttp_request *request = (struct winhttp_request *)arg; return request_send_and_receive( request ); } +#else +static void CALLBACK send_and_receive_proc( TP_CALLBACK_INSTANCE *instance, void *ctx ) +{ + struct winhttp_request *request = (struct winhttp_request *)ctx; + if (request_send( request ) == S_OK) request_receive( request ); + SetEvent( request->done ); +} +#endif /* critical section must be held */ static DWORD request_wait( struct winhttp_request *request, DWORD timeout ) { +#ifdef __REACTOS__ HANDLE thread = request->thread; +#else + HANDLE done = request->done; +#endif DWORD err, ret; LeaveCriticalSection( &request->cs ); +#ifdef __REACTOS__ while ((err = MsgWaitForMultipleObjects( 1, &thread, FALSE, timeout, QS_ALLINPUT )) == WAIT_OBJECT_0 + 1) +#else + while ((err = MsgWaitForMultipleObjects( 1, &done, FALSE, timeout, QS_ALLINPUT )) == WAIT_OBJECT_0 + 1) +#endif { MSG msg; while (PeekMessageW( &msg, NULL, 0, 0, PM_REMOVE )) @@ -3837,17 +4130,19 @@ static DWORD request_wait( struct winhttp_request *request, DWORD timeout ) switch (err) { case WAIT_OBJECT_0: - ret = ERROR_SUCCESS; + ret = request->error; break; case WAIT_TIMEOUT: ret = ERROR_TIMEOUT; break; - case WAIT_FAILED: default: - ret = get_last_error(); + ret = GetLastError(); break; } EnterCriticalSection( &request->cs ); +#ifndef __REACTOS__ + if (err == WAIT_OBJECT_0) request->proc_running = FALSE; +#endif return ret; } @@ -3877,13 +4172,18 @@ static HRESULT WINAPI winhttp_request_Send( LeaveCriticalSection( &request->cs ); return hr; } +#ifdef __REACTOS__ if (!(request->thread = CreateThread( NULL, 0, send_and_receive_proc, request, 0, NULL ))) +#else + if (!TrySubmitThreadpoolCallback( send_and_receive_proc, request, NULL )) +#endif { LeaveCriticalSection( &request->cs ); - return HRESULT_FROM_WIN32( get_last_error() ); + return HRESULT_FROM_WIN32( GetLastError() ); } - request->wait = CreateEventW( NULL, FALSE, FALSE, NULL ); - request->cancel = CreateEventW( NULL, FALSE, FALSE, NULL ); +#ifndef __REACTOS__ + request->proc_running = TRUE; +#endif if (!request->async) { hr = HRESULT_FROM_WIN32( request_wait( request, INFINITE ) ); @@ -3912,7 +4212,7 @@ static HRESULT WINAPI winhttp_request_get_Status( flags = WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER; if (!WinHttpQueryHeaders( request->hrequest, flags, NULL, &status_code, &len, &index )) { - err = get_last_error(); + err = GetLastError(); goto done; } *status = status_code; @@ -3941,7 +4241,7 @@ static HRESULT WINAPI winhttp_request_get_StatusText( } if (!WinHttpQueryHeaders( request->hrequest, WINHTTP_QUERY_STATUS_TEXT, NULL, NULL, &len, &index )) { - err = get_last_error(); + err = GetLastError(); if (err != ERROR_INSUFFICIENT_BUFFER) goto done; } if (!(*status = SysAllocStringLen( NULL, len / sizeof(WCHAR) ))) @@ -3953,7 +4253,7 @@ static HRESULT WINAPI winhttp_request_get_StatusText( err = ERROR_SUCCESS; if (!WinHttpQueryHeaders( request->hrequest, WINHTTP_QUERY_STATUS_TEXT, NULL, *status, &len, &index )) { - err = get_last_error(); + err = GetLastError(); SysFreeString( *status ); } done: @@ -3970,12 +4270,12 @@ static DWORD request_get_codepage( struct winhttp_request *request, UINT *codepa *codepage = CP_ACP; if (!WinHttpQueryHeaders( request->hrequest, WINHTTP_QUERY_CONTENT_TYPE, NULL, NULL, &size, NULL ) && - get_last_error() == ERROR_INSUFFICIENT_BUFFER) + GetLastError() == ERROR_INSUFFICIENT_BUFFER) { if (!(buffer = heap_alloc( size ))) return ERROR_OUTOFMEMORY; if (!WinHttpQueryHeaders( request->hrequest, WINHTTP_QUERY_CONTENT_TYPE, NULL, buffer, &size, NULL )) { - return get_last_error(); + return GetLastError(); } if ((p = strstrW( buffer, charsetW ))) { @@ -4372,11 +4672,9 @@ static HRESULT WINAPI winhttp_request_WaitForResponse( err = ERROR_SUCCESS; break; - case ERROR_SUCCESS: + default: if (succeeded) *succeeded = VARIANT_TRUE; break; - - default: break; } LeaveCriticalSection( &request->cs ); return HRESULT_FROM_WIN32( err ); @@ -4487,15 +4785,12 @@ HRESULT WinHttpRequest_create( void **obj ) TRACE("%p\n", obj); - if (!(request = heap_alloc( sizeof(*request) ))) return E_OUTOFMEMORY; + if (!(request = heap_alloc_zero( sizeof(*request) ))) return E_OUTOFMEMORY; request->IWinHttpRequest_iface.lpVtbl = &winhttp_request_vtbl; request->refs = 1; - request->state = REQUEST_STATE_UNINITIALIZED; - request->proxy.lpszProxy = NULL; - request->proxy.lpszProxyBypass = NULL; - request->url_codepage = CP_UTF8; InitializeCriticalSection( &request->cs ); request->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": winhttp_request.cs"); + initialize_request( request ); *obj = &request->IWinHttpRequest_iface; TRACE("returning iface %p\n", *obj); diff --git a/dll/win32/winhttp/session.c b/dll/win32/winhttp/session.c index 7cfc2407585..8e24de736dd 100644 --- a/dll/win32/winhttp/session.c +++ b/dll/win32/winhttp/session.c @@ -17,9 +17,6 @@ */ #include "config.h" -#include "wine/port.h" -#include "wine/debug.h" - #include <stdarg.h> #include <stdlib.h> @@ -29,46 +26,33 @@ #include <CoreServices/CoreServices.h> #undef GetCurrentThread #undef LoadResource -#undef DPRINTF #endif #include "windef.h" #include "winbase.h" -#ifndef __MINGW32__ -#define USE_WS_PREFIX -#endif #include "winsock2.h" #include "ws2ipdef.h" +#include "ws2tcpip.h" #include "winhttp.h" -#include "wincrypt.h" #include "winreg.h" +#include "wine/winternl.h" #define COBJMACROS #include "ole2.h" #include "dispex.h" #include "activscp.h" +#include "wine/debug.h" #include "winhttp_private.h" WINE_DEFAULT_DEBUG_CHANNEL(winhttp); -#define DEFAULT_RESOLVE_TIMEOUT 0 -#define DEFAULT_CONNECT_TIMEOUT 20000 -#define DEFAULT_SEND_TIMEOUT 30000 -#define DEFAULT_RECEIVE_TIMEOUT 30000 - -void set_last_error( DWORD error ) -{ - /* FIXME */ - SetLastError( error ); -} - -DWORD get_last_error( void ) -{ - /* FIXME */ - return GetLastError(); -} +#define DEFAULT_RESOLVE_TIMEOUT 0 +#define DEFAULT_CONNECT_TIMEOUT 20000 +#define DEFAULT_SEND_TIMEOUT 30000 +#define DEFAULT_RECEIVE_TIMEOUT 30000 +#define DEFAULT_RECEIVE_RESPONSE_TIMEOUT ~0u -void send_callback( object_header_t *hdr, DWORD status, LPVOID info, DWORD buflen ) +void send_callback( struct object_header *hdr, DWORD status, void *info, DWORD buflen ) { if (hdr->callback && (hdr->notify_mask & status)) { @@ -90,22 +74,17 @@ BOOL WINAPI WinHttpCheckPlatform( void ) /*********************************************************************** * session_destroy (internal) */ -static void session_destroy( object_header_t *hdr ) +static void session_destroy( struct object_header *hdr ) { - session_t *session = (session_t *)hdr; - struct list *item, *next; - domain_t *domain; + struct session *session = (struct session *)hdr; TRACE("%p\n", session); if (session->unload_event) SetEvent( session->unload_event ); - if (session->cred_handle_initialized) FreeCredentialsHandle( &session->cred_handle ); + destroy_cookies( session ); - LIST_FOR_EACH_SAFE( item, next, &session->cookie_cache ) - { - domain = LIST_ENTRY( item, domain_t, entry ); - delete_domain( domain ); - } + session->cs.DebugInfo->Spare[0] = 0; + DeleteCriticalSection( &session->cs ); heap_free( session->agent ); heap_free( session->proxy_server ); heap_free( session->proxy_bypass ); @@ -114,9 +93,9 @@ static void session_destroy( object_header_t *hdr ) heap_free( session ); } -static BOOL session_query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPDWORD buflen ) +static BOOL session_query_option( struct object_header *hdr, DWORD option, void *buffer, DWORD *buflen ) { - session_t *session = (session_t *)hdr; + struct session *session = (struct session *)hdr; switch (option) { @@ -125,7 +104,7 @@ static BOOL session_query_option( object_header_t *hdr, DWORD option, LPVOID buf if (!buffer || *buflen < sizeof(DWORD)) { *buflen = sizeof(DWORD); - set_last_error( ERROR_INSUFFICIENT_BUFFER ); + SetLastError( ERROR_INSUFFICIENT_BUFFER ); return FALSE; } @@ -137,28 +116,37 @@ static BOOL session_query_option( object_header_t *hdr, DWORD option, LPVOID buf *(DWORD *)buffer = session->resolve_timeout; *buflen = sizeof(DWORD); return TRUE; + case WINHTTP_OPTION_CONNECT_TIMEOUT: *(DWORD *)buffer = session->connect_timeout; *buflen = sizeof(DWORD); return TRUE; + case WINHTTP_OPTION_SEND_TIMEOUT: *(DWORD *)buffer = session->send_timeout; *buflen = sizeof(DWORD); return TRUE; + case WINHTTP_OPTION_RECEIVE_TIMEOUT: - *(DWORD *)buffer = session->recv_timeout; + *(DWORD *)buffer = session->receive_timeout; + *buflen = sizeof(DWORD); + return TRUE; + + case WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT: + *(DWORD *)buffer = session->receive_response_timeout; *buflen = sizeof(DWORD); return TRUE; + default: FIXME("unimplemented option %u\n", option); - set_last_error( ERROR_INVALID_PARAMETER ); + SetLastError( ERROR_INVALID_PARAMETER ); return FALSE; } } -static BOOL session_set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD buflen ) +static BOOL session_set_option( struct object_header *hdr, DWORD option, void *buffer, DWORD buflen ) { - session_t *session = (session_t *)hdr; + struct session *session = (struct session *)hdr; switch (option) { @@ -175,7 +163,7 @@ static BOOL session_set_option( object_header_t *hdr, DWORD option, LPVOID buffe if (buflen != sizeof(policy)) { - set_last_error( ERROR_INSUFFICIENT_BUFFER ); + SetLastError( ERROR_INSUFFICIENT_BUFFER ); return FALSE; } @@ -188,72 +176,81 @@ static BOOL session_set_option( object_header_t *hdr, DWORD option, LPVOID buffe { if (buflen != sizeof(session->secure_protocols)) { - set_last_error( ERROR_INSUFFICIENT_BUFFER ); + SetLastError( ERROR_INSUFFICIENT_BUFFER ); return FALSE; } + EnterCriticalSection( &session->cs ); session->secure_protocols = *(DWORD *)buffer; + LeaveCriticalSection( &session->cs ); TRACE("0x%x\n", session->secure_protocols); return TRUE; } case WINHTTP_OPTION_DISABLE_FEATURE: - set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); + SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); return FALSE; + case WINHTTP_OPTION_RESOLVE_TIMEOUT: session->resolve_timeout = *(DWORD *)buffer; return TRUE; + case WINHTTP_OPTION_CONNECT_TIMEOUT: session->connect_timeout = *(DWORD *)buffer; return TRUE; + case WINHTTP_OPTION_SEND_TIMEOUT: session->send_timeout = *(DWORD *)buffer; return TRUE; + case WINHTTP_OPTION_RECEIVE_TIMEOUT: - session->recv_timeout = *(DWORD *)buffer; + session->receive_timeout = *(DWORD *)buffer; return TRUE; + + case WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT: + session->receive_response_timeout = *(DWORD *)buffer; + return TRUE; + case WINHTTP_OPTION_CONFIGURE_PASSPORT_AUTH: - FIXME("WINHTTP_OPTION_CONFIGURE_PASSPORT_AUTH: 0x%x\n", *(DWORD *)buffer); + session->passport_flags = *(DWORD *)buffer; return TRUE; + case WINHTTP_OPTION_UNLOAD_NOTIFY_EVENT: TRACE("WINHTTP_OPTION_UNLOAD_NOTIFY_EVENT: %p\n", *(HANDLE *)buffer); session->unload_event = *(HANDLE *)buffer; return TRUE; + case WINHTTP_OPTION_MAX_CONNS_PER_SERVER: FIXME("WINHTTP_OPTION_MAX_CONNS_PER_SERVER: %d\n", *(DWORD *)buffer); return TRUE; + case WINHTTP_OPTION_MAX_CONNS_PER_1_0_SERVER: FIXME("WINHTTP_OPTION_MAX_CONNS_PER_1_0_SERVER: %d\n", *(DWORD *)buffer); return TRUE; + default: FIXME("unimplemented option %u\n", option); - set_last_error( ERROR_WINHTTP_INVALID_OPTION ); + SetLastError( ERROR_WINHTTP_INVALID_OPTION ); return FALSE; } } -static const object_vtbl_t session_vtbl = +static const struct object_vtbl session_vtbl = { session_destroy, session_query_option, session_set_option }; -#ifdef __REACTOS__ -BOOL netconn_init_winsock(); -#endif /* __REACTOS__ */ /*********************************************************************** * WinHttpOpen (winhttp.@) */ HINTERNET WINAPI WinHttpOpen( LPCWSTR agent, DWORD access, LPCWSTR proxy, LPCWSTR bypass, DWORD flags ) { - session_t *session; + struct session *session; HINTERNET handle = NULL; -#ifdef __REACTOS__ - if (!netconn_init_winsock()) return NULL; -#endif TRACE("%s, %u, %s, %s, 0x%08x\n", debugstr_w(agent), access, debugstr_w(proxy), debugstr_w(bypass), flags); - if (!(session = heap_alloc_zero( sizeof(session_t) ))) return NULL; + if (!(session = heap_alloc_zero( sizeof(struct session) ))) return NULL; session->hdr.type = WINHTTP_HANDLE_TYPE_SESSION; session->hdr.vtbl = &session_vtbl; @@ -264,8 +261,11 @@ HINTERNET WINAPI WinHttpOpen( LPCWSTR agent, DWORD access, LPCWSTR proxy, LPCWST session->resolve_timeout = DEFAULT_RESOLVE_TIMEOUT; session->connect_timeout = DEFAULT_CONNECT_TIMEOUT; session->send_timeout = DEFAULT_SEND_TIMEOUT; - session->recv_timeout = DEFAULT_RECEIVE_TIMEOUT; + session->receive_timeout = DEFAULT_RECEIVE_TIMEOUT; + session->receive_response_timeout = DEFAULT_RECEIVE_RESPONSE_TIMEOUT; list_init( &session->cookie_cache ); + InitializeCriticalSection( &session->cs ); + session->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": session.cs"); if (agent && !(session->agent = strdupW( agent ))) goto end; if (access == WINHTTP_ACCESS_TYPE_DEFAULT_PROXY) @@ -300,16 +300,16 @@ HINTERNET WINAPI WinHttpOpen( LPCWSTR agent, DWORD access, LPCWSTR proxy, LPCWST end: release_object( &session->hdr ); TRACE("returning %p\n", handle); - if (handle) set_last_error( ERROR_SUCCESS ); + if (handle) SetLastError( ERROR_SUCCESS ); return handle; } /*********************************************************************** * connect_destroy (internal) */ -static void connect_destroy( object_header_t *hdr ) +static void connect_destroy( struct object_header *hdr ) { - connect_t *connect = (connect_t *)hdr; + struct connect *connect = (struct connect *)hdr; TRACE("%p\n", connect); @@ -322,9 +322,9 @@ static void connect_destroy( object_header_t *hdr ) heap_free( connect ); } -static BOOL connect_query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPDWORD buflen ) +static BOOL connect_query_option( struct object_header *hdr, DWORD option, void *buffer, DWORD *buflen ) { - connect_t *connect = (connect_t *)hdr; + struct connect *connect = (struct connect *)hdr; switch (option) { @@ -333,11 +333,11 @@ static BOOL connect_query_option( object_header_t *hdr, DWORD option, LPVOID buf if (!buffer || *buflen < sizeof(HINTERNET)) { *buflen = sizeof(HINTERNET); - set_last_error( ERROR_INSUFFICIENT_BUFFER ); + SetLastError( ERROR_INSUFFICIENT_BUFFER ); return FALSE; } - *(HINTERNET *)buffer = ((object_header_t *)connect->session)->handle; + *(HINTERNET *)buffer = ((struct object_header *)connect->session)->handle; *buflen = sizeof(HINTERNET); return TRUE; } @@ -345,26 +345,35 @@ static BOOL connect_query_option( object_header_t *hdr, DWORD option, LPVOID buf *(DWORD *)buffer = connect->session->resolve_timeout; *buflen = sizeof(DWORD); return TRUE; + case WINHTTP_OPTION_CONNECT_TIMEOUT: *(DWORD *)buffer = connect->session->connect_timeout; *buflen = sizeof(DWORD); return TRUE; + case WINHTTP_OPTION_SEND_TIMEOUT: *(DWORD *)buffer = connect->session->send_timeout; *buflen = sizeof(DWORD); return TRUE; + case WINHTTP_OPTION_RECEIVE_TIMEOUT: - *(DWORD *)buffer = connect->session->recv_timeout; + *(DWORD *)buffer = connect->session->receive_timeout; *buflen = sizeof(DWORD); return TRUE; + + case WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT: + *(DWORD *)buffer = connect->session->receive_response_timeout; + *buflen = sizeof(DWORD); + return TRUE; + default: FIXME("unimplemented option %u\n", option); - set_last_error( ERROR_INVALID_PARAMETER ); + SetLastError( ERROR_INVALID_PARAMETER ); return FALSE; } } -static const object_vtbl_t connect_vtbl = +static const struct object_vtbl connect_vtbl = { connect_destroy, connect_query_option, @@ -425,7 +434,7 @@ static BOOL domain_matches(LPCWSTR server, LPCWSTR domain) /* Matches INTERNET_MAX_HOST_NAME_LENGTH in wininet.h, also RFC 1035 */ #define MAX_HOST_NAME_LENGTH 256 -static BOOL should_bypass_proxy(session_t *session, LPCWSTR server) +static BOOL should_bypass_proxy(struct session *session, LPCWSTR server) { LPCWSTR ptr; BOOL ret = FALSE; @@ -456,9 +465,9 @@ static BOOL should_bypass_proxy(session_t *session, LPCWSTR server) return ret; } -BOOL set_server_for_hostname( connect_t *connect, LPCWSTR server, INTERNET_PORT port ) +BOOL set_server_for_hostname( struct connect *connect, const WCHAR *server, INTERNET_PORT port ) { - session_t *session = connect->session; + struct session *session = connect->session; BOOL ret = TRUE; if (session->proxy_server && !should_bypass_proxy(session, server)) @@ -523,29 +532,29 @@ end: */ HINTERNET WINAPI WinHttpConnect( HINTERNET hsession, LPCWSTR server, INTERNET_PORT port, DWORD reserved ) { - connect_t *connect; - session_t *session; + struct connect *connect; + struct session *session; HINTERNET hconnect = NULL; TRACE("%p, %s, %u, %x\n", hsession, debugstr_w(server), port, reserved); if (!server) { - set_last_error( ERROR_INVALID_PARAMETER ); + SetLastError( ERROR_INVALID_PARAMETER ); return NULL; } - if (!(session = (session_t *)grab_object( hsession ))) + if (!(session = (struct session *)grab_object( hsession ))) { - set_last_error( ERROR_INVALID_HANDLE ); + SetLastError( ERROR_INVALID_HANDLE ); return NULL; } if (session->hdr.type != WINHTTP_HANDLE_TYPE_SESSION) { release_object( &session->hdr ); - set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); + SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); return NULL; } - if (!(connect = heap_alloc_zero( sizeof(connect_t) ))) + if (!(connect = heap_alloc_zero( sizeof(struct connect) ))) { release_object( &session->hdr ); return NULL; @@ -577,32 +586,44 @@ end: release_object( &connect->hdr ); release_object( &session->hdr ); TRACE("returning %p\n", hconnect); - if (hconnect) set_last_error( ERROR_SUCCESS ); + if (hconnect) SetLastError( ERROR_SUCCESS ); return hconnect; } /*********************************************************************** * request_destroy (internal) */ -static void request_destroy( object_header_t *hdr ) +static void request_destroy( struct object_header *hdr ) { - request_t *request = (request_t *)hdr; + struct request *request = (struct request *)hdr; unsigned int i, j; TRACE("%p\n", request); +#ifdef __REACTOS__ if (request->task_thread) +#else + if (request->task_proc_running) +#endif { - /* Signal to the task proc to quit. It will call - this again when it does. */ + /* Signal to the task proc to quit. It will call this again when it does. */ +#ifdef __REACTOS__ HANDLE thread = request->task_thread; request->task_thread = 0; SetEvent( request->task_cancel ); CloseHandle( thread ); +#else + request->task_proc_running = FALSE; + SetEvent( request->task_cancel ); +#endif return; } release_object( &request->connect->hdr ); + if (request->cred_handle_initialized) FreeCredentialsHandle( &request->cred_handle ); + CertFreeCertificateContext( request->server_cert ); + CertFreeCertificateContext( request->client_cert ); + destroy_authinfo( request->authinfo ); destroy_authinfo( request->proxy_authinfo ); @@ -652,46 +673,8 @@ static WCHAR *blob_to_str( DWORD encoding, CERT_NAME_BLOB *blob ) return ret; } -static BOOL convert_sockaddr( const struct sockaddr *addr, SOCKADDR_STORAGE *addr_storage ) +static BOOL copy_sockaddr( const struct sockaddr *addr, SOCKADDR_STORAGE *addr_storage ) { -#if !defined(__MINGW32__) && !defined(_MSC_VER) - switch (addr->sa_family) - { - case AF_INET: - { - const struct sockaddr_in *addr_unix = (const struct sockaddr_in *)addr; - struct WS_sockaddr_in *addr_win = (struct WS_sockaddr_in *)addr_storage; - char *p; - - addr_win->sin_family = WS_AF_INET; - addr_win->sin_port = addr_unix->sin_port; - memcpy( &addr_win->sin_addr, &addr_unix->sin_addr, 4 ); - p = (char *)&addr_win->sin_addr + 4; - memset( p, 0, sizeof(*addr_storage) - (p - (char *)addr_win) ); - return TRUE; - } - case AF_INET6: - { - const struct sockaddr_in6 *addr_unix = (const struct sockaddr_in6 *)addr; - struct WS_sockaddr_in6 *addr_win = (struct WS_sockaddr_in6 *)addr_storage; - - addr_win->sin6_family = WS_AF_INET6; - addr_win->sin6_port = addr_unix->sin6_port; - addr_win->sin6_flowinfo = addr_unix->sin6_flowinfo; - memcpy( &addr_win->sin6_addr, &addr_unix->sin6_addr, 16 ); -#ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_SCOPE_ID - addr_win->sin6_scope_id = addr_unix->sin6_scope_id; -#else - addr_win->sin6_scope_id = 0; -#endif - memset( addr_win + 1, 0, sizeof(*addr_storage) - sizeof(*addr_win) ); - return TRUE; - } - default: - ERR("unhandled family %u\n", addr->sa_family); - return FALSE; - } -#else switch (addr->sa_family) { case AF_INET: @@ -714,30 +697,27 @@ static BOOL convert_sockaddr( const struct sockaddr *addr, SOCKADDR_STORAGE *add ERR("unhandled family %u\n", addr->sa_family); return FALSE; } -#endif } -static BOOL request_query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPDWORD buflen ) +static BOOL request_query_option( struct object_header *hdr, DWORD option, void *buffer, DWORD *buflen ) { - request_t *request = (request_t *)hdr; + struct request *request = (struct request *)hdr; switch (option) { case WINHTTP_OPTION_SECURITY_FLAGS: { - DWORD flags = 0; + DWORD flags; int bits; if (!buffer || *buflen < sizeof(flags)) { *buflen = sizeof(flags); - set_last_error( ERROR_INSUFFICIENT_BUFFER ); + SetLastError( ERROR_INSUFFICIENT_BUFFER ); return FALSE; } - flags = 0; - if (hdr->flags & WINHTTP_FLAG_SECURE) flags |= SECURITY_FLAG_SECURE; - flags |= request->security_flags; + flags = request->security_flags; if (request->netconn) { bits = netconn_get_cipher_strength( request->netconn ); @@ -759,18 +739,18 @@ static BOOL request_query_option( object_header_t *hdr, DWORD option, LPVOID buf if (!buffer || *buflen < sizeof(cert)) { *buflen = sizeof(cert); - set_last_error( ERROR_INSUFFICIENT_BUFFER ); + SetLastError( ERROR_INSUFFICIENT_BUFFER ); return FALSE; } - if (!request->netconn || !(cert = netconn_get_certificate( request->netconn ))) return FALSE; + if (!(cert = CertDuplicateCertificateContext( request->server_cert ))) return FALSE; *(CERT_CONTEXT **)buffer = (CERT_CONTEXT *)cert; *buflen = sizeof(cert); return TRUE; } case WINHTTP_OPTION_SECURITY_CERTIFICATE_STRUCT: { - const CERT_CONTEXT *cert; + const CERT_CONTEXT *cert = request->server_cert; const CRYPT_OID_INFO *oidInfo; WINHTTP_CERTIFICATE_INFO *ci = buffer; @@ -779,19 +759,17 @@ static BOOL request_query_option( object_header_t *hdr, DWORD option, LPVOID buf if (!buffer || *buflen < sizeof(*ci)) { *buflen = sizeof(*ci); - set_last_error( ERROR_INSUFFICIENT_BUFFER ); + SetLastError( ERROR_INSUFFICIENT_BUFFER ); return FALSE; } - if (!request->netconn || !(cert = netconn_get_certificate( request->netconn ))) return FALSE; + if (!cert) return FALSE; ci->ftExpiry = cert->pCertInfo->NotAfter; ci->ftStart = cert->pCertInfo->NotBefore; ci->lpszSubjectInfo = blob_to_str( cert->dwCertEncodingType, &cert->pCertInfo->Subject ); ci->lpszIssuerInfo = blob_to_str( cert->dwCertEncodingType, &cert->pCertInfo->Issuer ); ci->lpszProtocolName = NULL; - oidInfo = CryptFindOIDInfo( CRYPT_OID_INFO_OID_KEY, - cert->pCertInfo->SignatureAlgorithm.pszObjId, - 0 ); + oidInfo = CryptFindOIDInfo( CRYPT_OID_INFO_OID_KEY, cert->pCertInfo->SignatureAlgorithm.pszObjId, 0 ); if (oidInfo) ci->lpszSignatureAlgName = (LPWSTR)oidInfo->pwszName; else @@ -799,7 +777,6 @@ static BOOL request_query_option( object_header_t *hdr, DWORD option, LPVOID buf ci->lpszEncryptionAlgName = NULL; ci->dwKeySize = request->netconn ? netconn_get_cipher_strength( request->netconn ) : 0; - CertFreeCertificateContext( cert ); *buflen = sizeof(*ci); return TRUE; } @@ -808,7 +785,7 @@ static BOOL request_query_option( object_header_t *hdr, DWORD option, LPVOID buf if (!buffer || *buflen < sizeof(DWORD)) { *buflen = sizeof(DWORD); - set_last_error( ERROR_INSUFFICIENT_BUFFER ); + SetLastError( ERROR_INSUFFICIENT_BUFFER ); return FALSE; } @@ -826,17 +803,17 @@ static BOOL request_query_option( object_header_t *hdr, DWORD option, LPVOID buf if (!buffer || *buflen < sizeof(*info)) { *buflen = sizeof(*info); - set_last_error( ERROR_INSUFFICIENT_BUFFER ); + SetLastError( ERROR_INSUFFICIENT_BUFFER ); return FALSE; } if (!request->netconn) { - set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_STATE ); + SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_STATE ); return FALSE; } if (getsockname( request->netconn->socket, &local, &len )) return FALSE; - if (!convert_sockaddr( &local, &info->LocalAddress )) return FALSE; - if (!convert_sockaddr( remote, &info->RemoteAddress )) return FALSE; + if (!copy_sockaddr( &local, &info->LocalAddress )) return FALSE; + if (!copy_sockaddr( remote, &info->RemoteAddress )) return FALSE; info->cbSize = sizeof(*info); return TRUE; } @@ -844,16 +821,24 @@ static BOOL request_query_option( object_header_t *hdr, DWORD option, LPVOID buf *(DWORD *)buffer = request->resolve_timeout; *buflen = sizeof(DWORD); return TRUE; + case WINHTTP_OPTION_CONNECT_TIMEOUT: *(DWORD *)buffer = request->connect_timeout; *buflen = sizeof(DWORD); return TRUE; + case WINHTTP_OPTION_SEND_TIMEOUT: *(DWORD *)buffer = request->send_timeout; *buflen = sizeof(DWORD); return TRUE; + case WINHTTP_OPTION_RECEIVE_TIMEOUT: - *(DWORD *)buffer = request->recv_timeout; + *(DWORD *)buffer = request->receive_timeout; + *buflen = sizeof(DWORD); + return TRUE; + + case WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT: + *(DWORD *)buffer = request->receive_response_timeout; *buflen = sizeof(DWORD); return TRUE; @@ -875,7 +860,7 @@ static BOOL request_query_option( object_header_t *hdr, DWORD option, LPVOID buf default: FIXME("unimplemented option %u\n", option); - set_last_error( ERROR_INVALID_PARAMETER ); + SetLastError( ERROR_INVALID_PARAMETER ); return FALSE; } } @@ -889,13 +874,13 @@ static WCHAR *buffer_to_str( WCHAR *buffer, DWORD buflen ) ret[buflen] = 0; return ret; } - set_last_error( ERROR_OUTOFMEMORY ); + SetLastError( ERROR_OUTOFMEMORY ); return NULL; } -static BOOL request_set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD buflen ) +static BOOL request_set_option( struct object_header *hdr, DWORD option, void *buffer, DWORD buflen ) { - request_t *request = (request_t *)hdr; + struct request *request = (struct request *)hdr; switch (option) { @@ -912,7 +897,7 @@ static BOOL request_set_option( object_header_t *hdr, DWORD option, LPVOID buffe if (buflen != sizeof(DWORD)) { - set_last_error( ERROR_INSUFFICIENT_BUFFER ); + SetLastError( ERROR_INSUFFICIENT_BUFFER ); return FALSE; } @@ -927,7 +912,7 @@ static BOOL request_set_option( object_header_t *hdr, DWORD option, LPVOID buffe if (buflen != sizeof(DWORD)) { - set_last_error( ERROR_INSUFFICIENT_BUFFER ); + SetLastError( ERROR_INSUFFICIENT_BUFFER ); return FALSE; } @@ -942,7 +927,7 @@ static BOOL request_set_option( object_header_t *hdr, DWORD option, LPVOID buffe if (buflen != sizeof(DWORD)) { - set_last_error( ERROR_INSUFFICIENT_BUFFER ); + SetLastError( ERROR_INSUFFICIENT_BUFFER ); return FALSE; } @@ -954,20 +939,21 @@ static BOOL request_set_option( object_header_t *hdr, DWORD option, LPVOID buffe case WINHTTP_OPTION_SECURITY_FLAGS: { DWORD flags; + static const DWORD accepted = SECURITY_FLAG_IGNORE_CERT_CN_INVALID | + SECURITY_FLAG_IGNORE_CERT_DATE_INVALID | + SECURITY_FLAG_IGNORE_UNKNOWN_CA | + SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE; if (buflen < sizeof(DWORD)) { - set_last_error( ERROR_INSUFFICIENT_BUFFER ); + SetLastError( ERROR_INSUFFICIENT_BUFFER ); return FALSE; } flags = *(DWORD *)buffer; TRACE("0x%x\n", flags); - if (!(flags & (SECURITY_FLAG_IGNORE_CERT_CN_INVALID | - SECURITY_FLAG_IGNORE_CERT_DATE_INVALID | - SECURITY_FLAG_IGNORE_UNKNOWN_CA | - SECURITY_FLAG_IGNORE_CERT_WRONG_USAGE))) + if (flags && (flags & ~accepted)) { - set_last_error( ERROR_INVALID_PARAMETER ); + SetLastError( ERROR_INVALID_PARAMETER ); return FALSE; } request->security_flags = flags; @@ -976,19 +962,26 @@ static BOOL request_set_option( object_header_t *hdr, DWORD option, LPVOID buffe case WINHTTP_OPTION_RESOLVE_TIMEOUT: request->resolve_timeout = *(DWORD *)buffer; return TRUE; + case WINHTTP_OPTION_CONNECT_TIMEOUT: request->connect_timeout = *(DWORD *)buffer; return TRUE; + case WINHTTP_OPTION_SEND_TIMEOUT: request->send_timeout = *(DWORD *)buffer; return TRUE; + case WINHTTP_OPTION_RECEIVE_TIMEOUT: - request->recv_timeout = *(DWORD *)buffer; + request->receive_timeout = *(DWORD *)buffer; + return TRUE; + + case WINHTTP_OPTION_RECEIVE_RESPONSE_TIMEOUT: + request->receive_response_timeout = *(DWORD *)buffer; return TRUE; case WINHTTP_OPTION_USERNAME: { - connect_t *connect = request->connect; + struct connect *connect = request->connect; heap_free( connect->username ); if (!(connect->username = buffer_to_str( buffer, buflen ))) return FALSE; @@ -996,7 +989,7 @@ static BOOL request_set_option( object_header_t *hdr, DWORD option, LPVOID buffe } case WINHTTP_OPTION_PASSWORD: { - connect_t *connect = request->connect; + struct connect *connect = request->connect; heap_free( connect->password ); if (!(connect->password = buffer_to_str( buffer, buflen ))) return FALSE; @@ -1004,7 +997,7 @@ static BOOL request_set_option( object_header_t *hdr, DWORD option, LPVOID buffe } case WINHTTP_OPTION_PROXY_USERNAME: { - session_t *session = request->connect->session; + struct session *session = request->connect->session; heap_free( session->proxy_username ); if (!(session->proxy_username = buffer_to_str( buffer, buflen ))) return FALSE; @@ -1012,82 +1005,136 @@ static BOOL request_set_option( object_header_t *hdr, DWORD option, LPVOID buffe } case WINHTTP_OPTION_PROXY_PASSWORD: { - session_t *session = request->connect->session; + struct session *session = request->connect->session; heap_free( session->proxy_password ); if (!(session->proxy_password = buffer_to_str( buffer, buflen ))) return FALSE; return TRUE; } case WINHTTP_OPTION_CLIENT_CERT_CONTEXT: + { + const CERT_CONTEXT *cert; + if (!(hdr->flags & WINHTTP_FLAG_SECURE)) { SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_STATE ); return FALSE; } - FIXME("WINHTTP_OPTION_CLIENT_CERT_CONTEXT\n"); + if (!buffer) + { + CertFreeCertificateContext( request->client_cert ); + request->client_cert = NULL; + } + else if (buflen >= sizeof(cert)) + { + if (!(cert = CertDuplicateCertificateContext( buffer ))) return FALSE; + CertFreeCertificateContext( request->client_cert ); + request->client_cert = cert; + } + else + { + SetLastError( ERROR_INVALID_PARAMETER ); + return FALSE; + } + + if (request->cred_handle_initialized) + { + FreeCredentialsHandle( &request->cred_handle ); + request->cred_handle_initialized = FALSE; + } + return TRUE; + } + case WINHTTP_OPTION_ENABLE_FEATURE: + if(buflen == sizeof( DWORD ) && *(DWORD *)buffer == WINHTTP_ENABLE_SSL_REVOCATION) + { + request->check_revocation = TRUE; + SetLastError( NO_ERROR ); + return TRUE; + } + else + { + SetLastError( ERROR_INVALID_PARAMETER ); + return FALSE; + } + + case WINHTTP_OPTION_CONNECT_RETRIES: + FIXME("WINHTTP_OPTION_CONNECT_RETRIES\n"); + return TRUE; + default: FIXME("unimplemented option %u\n", option); - set_last_error( ERROR_WINHTTP_INVALID_OPTION ); + SetLastError( ERROR_WINHTTP_INVALID_OPTION ); return FALSE; } } -static const object_vtbl_t request_vtbl = +static const struct object_vtbl request_vtbl = { request_destroy, request_query_option, request_set_option }; -static BOOL store_accept_types( request_t *request, const WCHAR **accept_types ) +static BOOL add_accept_types_header( struct request *request, const WCHAR **types ) { - static const WCHAR attr_accept[] = {'A','c','c','e','p','t',0}; + static const WCHAR acceptW[] = {'A','c','c','e','p','t',0}; static const DWORD flags = WINHTTP_ADDREQ_FLAG_ADD | WINHTTP_ADDREQ_FLAG_COALESCE_WITH_COMMA; - const WCHAR **types = accept_types; if (!types) return TRUE; while (*types) { - process_header( request, attr_accept, *types, flags, TRUE ); + if (!process_header( request, acceptW, *types, flags, TRUE )) return FALSE; types++; } return TRUE; } +static WCHAR *get_request_path( const WCHAR *object ) +{ + int len = object ? strlenW(object) : 0; + WCHAR *p, *ret; + + if (!object || object[0] != '/') len++; + if (!(p = ret = heap_alloc( (len + 1) * sizeof(WCHAR) ))) return NULL; + if (!object || object[0] != '/') *p++ = '/'; + if (object) strcpyW( p, object ); + ret[len] = 0; + return ret; +} + /*********************************************************************** * WinHttpOpenRequest (winhttp.@) */ HINTERNET WINAPI WinHttpOpenRequest( HINTERNET hconnect, LPCWSTR verb, LPCWSTR object, LPCWSTR version, LPCWSTR referrer, LPCWSTR *types, DWORD flags ) { - request_t *request; - connect_t *connect; + struct request *request; + struct connect *connect; HINTERNET hrequest = NULL; TRACE("%p, %s, %s, %s, %s, %p, 0x%08x\n", hconnect, debugstr_w(verb), debugstr_w(object), debugstr_w(version), debugstr_w(referrer), types, flags); - if(types && TRACE_ON(winhttp)) { + if (types && TRACE_ON(winhttp)) + { const WCHAR **iter; - TRACE("accept types:\n"); - for(iter = types; *iter; iter++) - TRACE(" %s\n", debugstr_w(*iter)); + for (iter = types; *iter; iter++) TRACE(" %s\n", debugstr_w(*iter)); } - if (!(connect = (connect_t *)grab_object( hconnect ))) + if (!(connect = (struct connect *)grab_object( hconnect ))) { - set_last_error( ERROR_INVALID_HANDLE ); + SetLastError( ERROR_INVALID_HANDLE ); return NULL; } if (connect->hdr.type != WINHTTP_HANDLE_TYPE_CONNECT) { release_object( &connect->hdr ); - set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); + SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); return NULL; } - if (!(request = heap_alloc_zero( sizeof(request_t) ))) + if (!(request = heap_alloc_zero( sizeof(struct request) ))) { release_object( &connect->hdr ); return NULL; @@ -1110,29 +1157,16 @@ HINTERNET WINAPI WinHttpOpenRequest( HINTERNET hconnect, LPCWSTR verb, LPCWSTR o request->resolve_timeout = connect->session->resolve_timeout; request->connect_timeout = connect->session->connect_timeout; request->send_timeout = connect->session->send_timeout; - request->recv_timeout = connect->session->recv_timeout; + request->receive_timeout = connect->session->receive_timeout; + request->receive_response_timeout = connect->session->receive_response_timeout; if (!verb || !verb[0]) verb = getW; if (!(request->verb = strdupW( verb ))) goto end; - - if (object) - { - WCHAR *path, *p; - unsigned int len; - - len = strlenW( object ) + 1; - if (object[0] != '/') len++; - if (!(p = path = heap_alloc( len * sizeof(WCHAR) ))) goto end; - - if (object[0] != '/') *p++ = '/'; - strcpyW( p, object ); - request->path = path; - } - else if (!(request->path = strdupW( slashW ))) goto end; + if (!(request->path = get_request_path( object ))) goto end; if (!version || !version[0]) version = http1_1; if (!(request->version = strdupW( version ))) goto end; - if (!(store_accept_types( request, types ))) goto end; + if (!(add_accept_types_header( request, types ))) goto end; if (!(hrequest = alloc_handle( &request->hdr ))) goto end; request->hdr.handle = hrequest; @@ -1143,7 +1177,7 @@ end: release_object( &request->hdr ); release_object( &connect->hdr ); TRACE("returning %p\n", hrequest); - if (hrequest) set_last_error( ERROR_SUCCESS ); + if (hrequest) SetLastError( ERROR_SUCCESS ); return hrequest; } @@ -1152,28 +1186,28 @@ end: */ BOOL WINAPI WinHttpCloseHandle( HINTERNET handle ) { - object_header_t *hdr; + struct object_header *hdr; TRACE("%p\n", handle); if (!(hdr = grab_object( handle ))) { - set_last_error( ERROR_INVALID_HANDLE ); + SetLastError( ERROR_INVALID_HANDLE ); return FALSE; } release_object( hdr ); free_handle( handle ); - set_last_error( ERROR_SUCCESS ); + SetLastError( ERROR_SUCCESS ); return TRUE; } -static BOOL query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPDWORD buflen ) +static BOOL query_option( struct object_header *hdr, DWORD option, void *buffer, DWORD *buflen ) { BOOL ret = FALSE; if (!buflen) { - set_last_error( ERROR_INVALID_PARAMETER ); + SetLastError( ERROR_INVALID_PARAMETER ); return FALSE; } @@ -1184,7 +1218,7 @@ static BOOL query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPD if (!buffer || *buflen < sizeof(DWORD_PTR)) { *buflen = sizeof(DWORD_PTR); - set_last_error( ERROR_INSUFFICIENT_BUFFER ); + SetLastError( ERROR_INSUFFICIENT_BUFFER ); return FALSE; } @@ -1197,7 +1231,7 @@ static BOOL query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPD else { FIXME("unimplemented option %u\n", option); - set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); + SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); return FALSE; } break; @@ -1211,30 +1245,30 @@ static BOOL query_option( object_header_t *hdr, DWORD option, LPVOID buffer, LPD BOOL WINAPI WinHttpQueryOption( HINTERNET handle, DWORD option, LPVOID buffer, LPDWORD buflen ) { BOOL ret = FALSE; - object_header_t *hdr; + struct object_header *hdr; TRACE("%p, %u, %p, %p\n", handle, option, buffer, buflen); if (!(hdr = grab_object( handle ))) { - set_last_error( ERROR_INVALID_HANDLE ); + SetLastError( ERROR_INVALID_HANDLE ); return FALSE; } ret = query_option( hdr, option, buffer, buflen ); release_object( hdr ); - if (ret) set_last_error( ERROR_SUCCESS ); + if (ret) SetLastError( ERROR_SUCCESS ); return ret; } -static BOOL set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD buflen ) +static BOOL set_option( struct object_header *hdr, DWORD option, void *buffer, DWORD buflen ) { BOOL ret = TRUE; if (!buffer && buflen) { - set_last_error( ERROR_INVALID_PARAMETER ); + SetLastError( ERROR_INVALID_PARAMETER ); return FALSE; } @@ -1244,7 +1278,7 @@ static BOOL set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD { if (buflen != sizeof(DWORD_PTR)) { - set_last_error( ERROR_INSUFFICIENT_BUFFER ); + SetLastError( ERROR_INSUFFICIENT_BUFFER ); return FALSE; } @@ -1256,7 +1290,7 @@ static BOOL set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD else { FIXME("unimplemented option %u\n", option); - set_last_error( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); + SetLastError( ERROR_WINHTTP_INCORRECT_HANDLE_TYPE ); return FALSE; } break; @@ -1270,20 +1304,20 @@ static BOOL set_option( object_header_t *hdr, DWORD option, LPVOID buffer, DWORD BOOL WINAPI WinHttpSetOption( HINTERNET handle, DWORD option, LPVOID buffer, DWORD buflen ) { BOOL ret = FALSE; - object_header_t *hdr; + struct object_header *hdr; TRACE("%p, %u, %p, %u\n", handle, option, buffer, buflen); if (!(hdr = grab_object( handle ))) { - set_last_error( ERROR_INVALID_HANDLE ); + SetLastError( ERROR_INVALID_HANDLE ); return FALSE; } ret = set_option( hdr, option, buffer, buflen ); release_object( hdr ); - if (ret) set_last_error( ERROR_SUCCESS ); + if (ret) SetLastError( ERROR_SUCCESS ); return ret; } @@ -1308,17 +1342,13 @@ static BOOL is_domain_suffix( const char *domain, const char *suffix ) int len_domain = strlen( domain ), len_suffix = strlen( suffix ); if (len_suffix > len_domain) return FALSE; - if (!strcasecmp( domain + len_domain - len_suffix, suffix )) return TRUE; + if (!_strnicmp( domain + len_domain - len_suffix, suffix, -1 )) return TRUE; return FALSE; } static int reverse_lookup( const struct addrinfo *ai, char *hostname, size_t len ) { - int ret = -1; -#ifdef HAVE_GETNAMEINFO - ret = getnameinfo( ai->ai_addr, ai->ai_addrlen, hostname, len, NULL, 0, 0 ); -#endif - return ret; + return getnameinfo( ai->ai_addr, ai->ai_addrlen, hostname, len, NULL, 0, 0 ); } static WCHAR *build_wpad_url( const char *hostname, const struct addrinfo *ai ) @@ -1391,7 +1421,7 @@ BOOL WINAPI WinHttpDetectAutoProxyConfigUrl( DWORD flags, LPWSTR *url ) if (!flags || !url) { - set_last_error( ERROR_INVALID_PARAMETER ); + SetLastError( ERROR_INVALID_PARAMETER ); return FALSE; } if (get_system_proxy_autoconfig_url( system_url, sizeof(system_url) )) @@ -1400,7 +1430,7 @@ BOOL WINAPI WinHttpDetectAutoProxyConfigUrl( DWORD flags, LPWSTR *url ) if (!(urlW = strdupAW( system_url ))) return FALSE; *url = urlW; - set_last_error( ERROR_SUCCESS ); + SetLastError( ERROR_SUCCESS ); return TRUE; } if (flags & WINHTTP_AUTO_DETECT_TYPE_DHCP) @@ -1410,7 +1440,6 @@ BOOL WINAPI WinHttpDetectAutoProxyConfigUrl( DWORD flags, LPWSTR *url ) } if (flags & WINHTTP_AUTO_DETECT_TYPE_DNS_A) { -#ifdef HAVE_GETADDRINFO char *fqdn, *domain, *p; if (!(fqdn = get_computer_name( ComputerNamePhysicalDnsFullyQualified ))) return FALSE; @@ -1452,16 +1481,13 @@ BOOL WINAPI WinHttpDetectAutoProxyConfigUrl( DWORD flags, LPWSTR *url ) } heap_free( domain ); heap_free( fqdn ); -#else - FIXME("getaddrinfo not found at build time\n"); -#endif } if (!ret) { - set_last_error( ERROR_WINHTTP_AUTODETECTION_FAILED ); + SetLastError( ERROR_WINHTTP_AUTODETECTION_FAILED ); *url = NULL; } - else set_last_error( ERROR_SUCCESS ); + else SetLastError( ERROR_SUCCESS ); return ret; } @@ -1620,7 +1646,7 @@ BOOL WINAPI WinHttpGetDefaultProxyConfiguration( WINHTTP_PROXY_INFO *info ) info->lpszProxy = NULL; info->lpszProxyBypass = NULL; } - set_last_error( ERROR_SUCCESS ); + SetLastError( ERROR_SUCCESS ); return TRUE; } @@ -1640,7 +1666,7 @@ BOOL WINAPI WinHttpGetIEProxyConfigForCurrentUser( WINHTTP_CURRENT_USER_IE_PROXY if (!config) { - set_last_error( ERROR_INVALID_PARAMETER ); + SetLastError( ERROR_INVALID_PARAMETER ); return FALSE; } memset( config, 0, sizeof(*config) ); @@ -1703,7 +1729,7 @@ done: GlobalFree( config->lpszProxyBypass ); config->lpszProxyBypass = NULL; } - else set_last_error( ERROR_SUCCESS ); + else SetLastError( ERROR_SUCCESS ); return ret; } @@ -1722,7 +1748,7 @@ static BOOL parse_script_result( const char *result, WINHTTP_PROXY_INFO *info ) p = result; while (*p == ' ') p++; len = strlen( p ); - if (len >= 5 && !strncasecmp( p, "PROXY", sizeof("PROXY") - 1 )) + if (len >= 5 && !_strnicmp( p, "PROXY", sizeof("PROXY") - 1 )) { p += 5; while (*p == ' ') p++; @@ -1797,7 +1823,7 @@ done: ... 1269 lines suppressed ...
1
0
0
0
[reactos] 01/01: [WINEMP3.ACM] Sync with Wine Staging 4.18. CORE-16441
by Amine Khaldi
07 Dec '19
07 Dec '19
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=611eb5508c9e0d1f5f5c8…
commit 611eb5508c9e0d1f5f5c819208d8cba0532139a2 Author: Amine Khaldi <amine.khaldi(a)reactos.org> AuthorDate: Sat Dec 7 13:05:25 2019 +0100 Commit: Amine Khaldi <amine.khaldi(a)reactos.org> CommitDate: Sat Dec 7 13:05:25 2019 +0100 [WINEMP3.ACM] Sync with Wine Staging 4.18. CORE-16441 --- dll/win32/winemp3.acm/mpegl3.c | 19 ++++++++----------- media/doc/README.WINE | 2 +- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/dll/win32/winemp3.acm/mpegl3.c b/dll/win32/winemp3.acm/mpegl3.c index b28519f835a..2e929371ae8 100644 --- a/dll/win32/winemp3.acm/mpegl3.c +++ b/dll/win32/winemp3.acm/mpegl3.c @@ -89,9 +89,6 @@ static const Format MPEG3_Formats[] = {1, 0, 48000}, {2, 0, 48000} }; -#define NUM_PCM_FORMATS (sizeof(PCM_Formats) / sizeof(PCM_Formats[0])) -#define NUM_MPEG3_FORMATS (sizeof(MPEG3_Formats) / sizeof(MPEG3_Formats[0])) - /*********************************************************************** * MPEG3_GetFormatIndex */ @@ -103,12 +100,12 @@ static DWORD MPEG3_GetFormatIndex(LPWAVEFORMATEX wfx) switch (wfx->wFormatTag) { case WAVE_FORMAT_PCM: - hi = NUM_PCM_FORMATS; + hi = ARRAY_SIZE(PCM_Formats); fmts = PCM_Formats; break; case WAVE_FORMAT_MPEG: case WAVE_FORMAT_MPEGLAYER3: - hi = NUM_MPEG3_FORMATS; + hi = ARRAY_SIZE(MPEG3_Formats); fmts = MPEG3_Formats; break; default: @@ -692,13 +689,13 @@ static LRESULT MPEG3_DriverDetails(PACMDRIVERDETAILSW add) add->cFilterTags = 0; add->hicon = NULL; MultiByteToWideChar( CP_ACP, 0, "MPEG Layer-3 Codec", -1, - add->szShortName, sizeof(add->szShortName)/sizeof(WCHAR) ); + add->szShortName, ARRAY_SIZE( add->szShortName )); MultiByteToWideChar( CP_ACP, 0, "Wine MPEG3 decoder", -1, - add->szLongName, sizeof(add->szLongName)/sizeof(WCHAR) ); + add->szLongName, ARRAY_SIZE( add->szLongName )); MultiByteToWideChar( CP_ACP, 0, "Brought to you by the Wine team...", -1, - add->szCopyright, sizeof(add->szCopyright)/sizeof(WCHAR) ); + add->szCopyright, ARRAY_SIZE( add->szCopyright )); MultiByteToWideChar( CP_ACP, 0, "Refer to LICENSE file", -1, - add->szLicensing, sizeof(add->szLicensing)/sizeof(WCHAR) ); + add->szLicensing, ARRAY_SIZE( add->szLicensing )); add->szFeatures[0] = 0; return MMSYSERR_NOERROR; @@ -746,7 +743,7 @@ static LRESULT MPEG3_FormatTagDetails(PACMFORMATTAGDETAILSW aftd, DWORD dwQuery) case 0: aftd->dwFormatTag = WAVE_FORMAT_PCM; aftd->cbFormatSize = sizeof(PCMWAVEFORMAT); - aftd->cStandardFormats = NUM_PCM_FORMATS; + aftd->cStandardFormats = ARRAY_SIZE(PCM_Formats); lstrcpyW(aftd->szFormatTag, szPcm); break; case 1: @@ -781,7 +778,7 @@ static LRESULT MPEG3_FormatDetails(PACMFORMATDETAILSW afd, DWORD dwQuery) switch (afd->dwFormatTag) { case WAVE_FORMAT_PCM: - if (afd->dwFormatIndex >= NUM_PCM_FORMATS) return ACMERR_NOTPOSSIBLE; + if (afd->dwFormatIndex >= ARRAY_SIZE(PCM_Formats)) return ACMERR_NOTPOSSIBLE; afd->pwfx->nChannels = PCM_Formats[afd->dwFormatIndex].nChannels; afd->pwfx->nSamplesPerSec = PCM_Formats[afd->dwFormatIndex].rate; afd->pwfx->wBitsPerSample = PCM_Formats[afd->dwFormatIndex].nBits; diff --git a/media/doc/README.WINE b/media/doc/README.WINE index 876663af0de..7d41d927c6c 100644 --- a/media/doc/README.WINE +++ b/media/doc/README.WINE @@ -199,7 +199,7 @@ dll/win32/wbemdisp # Synced to WineStaging-4.18 dll/win32/wbemprox # Synced to WineStaging-4.18 dll/win32/windowscodecs # Synced to WineStaging-4.18 dll/win32/windowscodecsext # Synced to WineStaging-2.9 -dll/win32/winemp3.acm # Synced to WineStaging-3.3 +dll/win32/winemp3.acm # Synced to WineStaging-4.18 dll/win32/wing32 # Synced to WineStaging-3.3 dll/win32/winhttp # Synced to WineStaging-3.9 dll/win32/wininet # Synced to WineStaging-3.9
1
0
0
0
[reactos] 01/01: [WINDOWSCODECS_WINETEST] Sync with Wine Staging 4.18. CORE-16441
by Amine Khaldi
07 Dec '19
07 Dec '19
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=cc48f9d4d6539e628a257…
commit cc48f9d4d6539e628a257d01329f2e80808718db Author: Amine Khaldi <amine.khaldi(a)reactos.org> AuthorDate: Sat Dec 7 13:05:00 2019 +0100 Commit: Amine Khaldi <amine.khaldi(a)reactos.org> CommitDate: Sat Dec 7 13:05:00 2019 +0100 [WINDOWSCODECS_WINETEST] Sync with Wine Staging 4.18. CORE-16441 --- .../winetests/windowscodecs/CMakeLists.txt | 5 - modules/rostests/winetests/windowscodecs/bitmap.c | 222 +++++++++++++++++++++ .../rostests/winetests/windowscodecs/converter.c | 47 +++-- .../rostests/winetests/windowscodecs/metadata.c | 1 + modules/rostests/winetests/windowscodecs/palette.c | 4 +- modules/rostests/winetests/windowscodecs/stream.c | 2 +- .../rostests/winetests/windowscodecs/tiffformat.c | 3 +- 7 files changed, 260 insertions(+), 24 deletions(-) diff --git a/modules/rostests/winetests/windowscodecs/CMakeLists.txt b/modules/rostests/winetests/windowscodecs/CMakeLists.txt index 09cca9909aa..6bae33b8912 100644 --- a/modules/rostests/winetests/windowscodecs/CMakeLists.txt +++ b/modules/rostests/winetests/windowscodecs/CMakeLists.txt @@ -3,11 +3,6 @@ add_definitions( -DUSE_WINE_TODOS -DWINETEST_USE_DBGSTR_LONGLONG) -# to be removed after synching with newer Wine -if(GCC AND GCC_VERSION VERSION_GREATER 7) - add_compile_flags("-Wno-stringop-overflow") -endif() - list(APPEND SOURCE bitmap.c bmpformat.c diff --git a/modules/rostests/winetests/windowscodecs/bitmap.c b/modules/rostests/winetests/windowscodecs/bitmap.c index d4b597900db..6cb0c5665c2 100644 --- a/modules/rostests/winetests/windowscodecs/bitmap.c +++ b/modules/rostests/winetests/windowscodecs/bitmap.c @@ -30,6 +30,71 @@ #include "wincodec.h" #include "wine/test.h" +#include "initguid.h" +DEFINE_GUID(IID_IMILUnknown,0x0ccd7824,0xdc16,0x4d09,0xbc,0xa8,0x6b,0x09,0xc4,0xef,0x55,0x35); +DEFINE_GUID(IID_IMILBitmap,0xb1784d3f,0x8115,0x4763,0x13,0xaa,0x32,0xed,0xdb,0x68,0x29,0x4a); +DEFINE_GUID(IID_IMILBitmapSource,0x7543696a,0xbc8d,0x46b0,0x5f,0x81,0x8d,0x95,0x72,0x89,0x72,0xbe); +DEFINE_GUID(IID_IMILBitmapLock,0xa67b2b53,0x8fa1,0x4155,0x8f,0x64,0x0c,0x24,0x7a,0x8f,0x84,0xcd); +DEFINE_GUID(IID_IMILBitmapScaler,0xa767b0f0,0x1c8c,0x4aef,0x56,0x8f,0xad,0xf9,0x6d,0xcf,0xd5,0xcb); +DEFINE_GUID(IID_IMILFormatConverter,0x7e2a746f,0x25c5,0x4851,0xb3,0xaf,0x44,0x3b,0x79,0x63,0x9e,0xc0); +DEFINE_GUID(IID_IMILPalette,0xca8e206f,0xf22c,0x4af7,0x6f,0xba,0x7b,0xed,0x5e,0xb1,0xc9,0x2f); + +#undef INTERFACE +#define INTERFACE IMILBitmapSource +DECLARE_INTERFACE_(IMILBitmapSource,IUnknown) +{ + STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID,void **) PURE; + STDMETHOD_(ULONG,AddRef)(THIS) PURE; + STDMETHOD_(ULONG,Release)(THIS) PURE; + /*** IWICBitmapSource methods ***/ + STDMETHOD_(HRESULT,GetSize)(THIS_ UINT *,UINT *) PURE; + STDMETHOD_(HRESULT,GetPixelFormat)(THIS_ int *) PURE; + STDMETHOD_(HRESULT,GetResolution)(THIS_ double *,double *) PURE; + STDMETHOD_(HRESULT,CopyPalette)(THIS_ IWICPalette *) PURE; + STDMETHOD_(HRESULT,CopyPixels)(THIS_ const WICRect *,UINT,UINT,BYTE *) PURE; +}; + +#undef INTERFACE +#define INTERFACE IMILBitmap +DECLARE_INTERFACE_(IMILBitmap,IMILBitmapSource) +{ + STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID,void **) PURE; + STDMETHOD_(ULONG,AddRef)(THIS) PURE; + STDMETHOD_(ULONG,Release)(THIS) PURE; + /*** IWICBitmapSource methods ***/ + STDMETHOD_(HRESULT,GetSize)(THIS_ UINT *,UINT *) PURE; + STDMETHOD_(HRESULT,GetPixelFormat)(THIS_ int *) PURE; + STDMETHOD_(HRESULT,GetResolution)(THIS_ double *,double *) PURE; + STDMETHOD_(HRESULT,CopyPalette)(THIS_ IWICPalette *) PURE; + STDMETHOD_(HRESULT,CopyPixels)(THIS_ const WICRect *,UINT,UINT,BYTE *) PURE; + /*** IMILBitmap methods ***/ + STDMETHOD_(HRESULT,unknown1)(THIS_ void **) PURE; + STDMETHOD_(HRESULT,Lock)(THIS_ const WICRect *,DWORD,IWICBitmapLock **) PURE; + STDMETHOD_(HRESULT,Unlock)(THIS_ IWICBitmapLock *) PURE; + STDMETHOD_(HRESULT,SetPalette)(THIS_ IWICPalette *) PURE; + STDMETHOD_(HRESULT,SetResolution)(THIS_ double,double) PURE; + STDMETHOD_(HRESULT,AddDirtyRect)(THIS_ const WICRect *) PURE; +}; + +#undef INTERFACE +#define INTERFACE IMILBitmapScaler +DECLARE_INTERFACE_(IMILBitmapScaler,IMILBitmapSource) +{ + /*** IUnknown methods ***/ + STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID,void **) PURE; + STDMETHOD_(ULONG,AddRef)(THIS) PURE; + STDMETHOD_(ULONG,Release)(THIS) PURE; + /*** IWICBitmapSource methods ***/ + STDMETHOD_(HRESULT,GetSize)(THIS_ UINT *,UINT *) PURE; + STDMETHOD_(HRESULT,GetPixelFormat)(THIS_ int *) PURE; + STDMETHOD_(HRESULT,GetResolution)(THIS_ double *,double *) PURE; + STDMETHOD_(HRESULT,CopyPalette)(THIS_ IWICPalette *) PURE; + STDMETHOD_(HRESULT,CopyPixels)(THIS_ const WICRect *,UINT,UINT,BYTE *) PURE; + /*** IMILBitmapScaler methods ***/ + STDMETHOD_(HRESULT,unknown1)(THIS_ void **) PURE; + STDMETHOD_(HRESULT,Initialize)(THIS_ IMILBitmapSource *,UINT,UINT,WICBitmapInterpolationMode); +}; + static IWICImagingFactory *factory; static HRESULT WINAPI bitmapsource_QueryInterface(IWICBitmapSource *iface, REFIID iid, void **ppv) @@ -1088,6 +1153,7 @@ static void test_bitmap_scaler(void) double res_x, res_y; IWICBitmap *bitmap; UINT width, height; + BYTE buf[16]; HRESULT hr; hr = IWICImagingFactory_CreateBitmap(factory, 4, 2, &GUID_WICPixelFormat24bppBGR, WICBitmapCacheOnLoad, &bitmap); @@ -1165,6 +1231,9 @@ static void test_bitmap_scaler(void) hr = IWICBitmapScaler_GetSize(scaler, &width, &height); ok(hr == WINCODEC_ERR_NOTINITIALIZED, "Unexpected hr %#x.\n", hr); + hr = IWICBitmapScaler_CopyPixels(scaler, NULL, 1, sizeof(buf), buf); + ok(hr == WINCODEC_ERR_NOTINITIALIZED, "Unexpected hr %#x.\n", hr); + hr = IWICBitmapScaler_Initialize(scaler, (IWICBitmapSource *)bitmap, 0, 2, WICBitmapInterpolationModeNearestNeighbor); ok(hr == E_INVALIDARG, "Unexpected hr %#x.\n", hr); @@ -1245,6 +1314,158 @@ static void test_bitmap_scaler(void) IWICBitmap_Release(bitmap); } +static LONG obj_refcount(void *obj) +{ + IUnknown_AddRef((IUnknown *)obj); + return IUnknown_Release((IUnknown *)obj); +} + +static void test_IMILBitmap(void) +{ + HRESULT hr; + IWICBitmap *bitmap; + IWICBitmapScaler *scaler; + IMILBitmap *mil_bitmap; + IMILBitmapSource *mil_source; + IMILBitmapScaler *mil_scaler; + IUnknown *wic_unknown, *mil_unknown; + WICPixelFormatGUID format; + int MIL_format; + UINT width, height; + double dpix, dpiy; + BYTE buf[256]; + + /* Bitmap */ + hr = IWICImagingFactory_CreateBitmap(factory, 1, 1, &GUID_WICPixelFormat24bppBGR, + WICBitmapCacheOnDemand, &bitmap); + ok(hr == S_OK, "CreateBitmap error %#x\n", hr); + + ok(obj_refcount(bitmap) == 1, "ref count %d\n", obj_refcount(bitmap)); + + hr = IWICBitmap_GetPixelFormat(bitmap, &format); + ok(hr == S_OK, "GetPixelFormat error %#x\n", hr); + ok(IsEqualGUID(&format, &GUID_WICPixelFormat24bppBGR), "wrong format %s\n", wine_dbgstr_guid(&format)); + + hr = IWICBitmap_GetResolution(bitmap, &dpix, &dpiy); + ok(hr == S_OK, "GetResolution error %#x\n", hr); + ok(dpix == 0.0, "got %f, expected 0.0\n", dpix); + ok(dpiy == 0.0, "got %f, expected 0.0\n", dpiy); + + hr = IWICBitmap_SetResolution(bitmap, 12.0, 34.0); + ok(hr == S_OK, "SetResolution error %#x\n", hr); + + hr = IWICBitmap_GetResolution(bitmap, &dpix, &dpiy); + ok(hr == S_OK, "GetResolution error %#x\n", hr); + ok(dpix == 12.0, "got %f, expected 12.0\n", dpix); + ok(dpiy == 34.0, "got %f, expected 34.0\n", dpiy); + + hr = IWICBitmap_GetSize(bitmap, &width, &height); + ok(hr == S_OK, "GetSize error %#x\n", hr); + ok(width == 1, "got %u, expected 1\n", width); + ok(height == 1, "got %u, expected 1\n", height); + + hr = IWICBitmap_QueryInterface(bitmap, &IID_IMILBitmap, (void **)&mil_bitmap); + ok(hr == S_OK, "QueryInterface error %#x\n", hr); + + ok(obj_refcount(bitmap) == 2, "ref count %d\n", obj_refcount(bitmap)); + ok(obj_refcount(mil_bitmap) == 2, "ref count %d\n", obj_refcount(mil_bitmap)); + + hr = IWICBitmap_QueryInterface(bitmap, &IID_IUnknown, (void **)&wic_unknown); + ok(hr == S_OK, "QueryInterface error %#x\n", hr); + + hr = mil_bitmap->lpVtbl->QueryInterface(mil_bitmap, &IID_IUnknown, (void **)&mil_unknown); + ok(hr == S_OK, "QueryInterface error %#x\n", hr); + ok((void *)wic_unknown->lpVtbl == (void *)mil_unknown->lpVtbl, "wrong lpVtbl ptrs %p != %p\n", wic_unknown->lpVtbl, mil_unknown->lpVtbl); + + IUnknown_Release(wic_unknown); + IUnknown_Release(mil_unknown); + + hr = IWICBitmap_QueryInterface(bitmap, &IID_IMILBitmapSource, (void **)&mil_source); + ok(hr == S_OK, "QueryInterface error %#x\n", hr); + ok((void *)mil_source->lpVtbl == (void *)mil_bitmap->lpVtbl, "IMILBitmap->lpVtbl should be equal to IMILBitmapSource->lpVtbl\n"); + + ok(obj_refcount(bitmap) == 3, "ref count %d\n", obj_refcount(bitmap)); + ok(obj_refcount(mil_bitmap) == 3, "ref count %d\n", obj_refcount(mil_bitmap)); + ok(obj_refcount(mil_source) == 3, "ref count %d\n", obj_refcount(mil_source)); + + hr = mil_source->lpVtbl->GetPixelFormat(mil_source, &MIL_format); + ok(hr == S_OK, "GetPixelFormat error %#x\n", hr); + ok(MIL_format == 0x0c, "wrong format %d\n", MIL_format); + + hr = mil_source->lpVtbl->GetResolution(mil_source, &dpix, &dpiy); + ok(hr == S_OK, "GetResolution error %#x\n", hr); + ok(dpix == 12.0, "got %f, expected 12.0\n", dpix); + ok(dpiy == 34.0, "got %f, expected 34.0\n", dpiy); + + hr = mil_source->lpVtbl->GetSize(mil_source, &width, &height); + ok(hr == S_OK, "GetSize error %#x\n", hr); + ok(width == 1, "got %u, expected 1\n", width); + ok(height == 1, "got %u, expected 1\n", height); + + /* Scaler */ + hr = IWICImagingFactory_CreateBitmapScaler(factory, &scaler); + ok(hr == S_OK, "CreateBitmapScaler error %#x\n", hr); + + ok(obj_refcount(scaler) == 1, "ref count %d\n", obj_refcount(scaler)); + + hr = IWICBitmapScaler_QueryInterface(scaler, &IID_IMILBitmapScaler, (void **)&mil_scaler); + ok(hr == S_OK, "QueryInterface error %#x\n", hr); + + ok(obj_refcount(scaler) == 2, "ref count %d\n", obj_refcount(scaler)); + ok(obj_refcount(mil_scaler) == 2, "ref count %d\n", obj_refcount(mil_scaler)); + + hr = IWICBitmapScaler_QueryInterface(scaler, &IID_IUnknown, (void **)&wic_unknown); + ok(hr == S_OK, "QueryInterface error %#x\n", hr); + + hr = mil_scaler->lpVtbl->QueryInterface(mil_scaler, &IID_IUnknown, (void **)&mil_unknown); + ok(hr == S_OK, "QueryInterface error %#x\n", hr); + ok((void *)wic_unknown->lpVtbl == (void *)mil_unknown->lpVtbl, "wrong lpVtbl ptrs %p != %p\n", wic_unknown->lpVtbl, mil_unknown->lpVtbl); + + IUnknown_Release(wic_unknown); + IUnknown_Release(mil_unknown); + + hr = mil_scaler->lpVtbl->GetPixelFormat(mil_scaler, &MIL_format); + ok(hr == WINCODEC_ERR_NOTINITIALIZED, "GetPixelFormat error %#x\n", hr); + + hr = mil_scaler->lpVtbl->GetResolution(mil_scaler, &dpix, &dpiy); + ok(hr == WINCODEC_ERR_NOTINITIALIZED, "GetResolution error %#x\n", hr); + + hr = mil_scaler->lpVtbl->GetSize(mil_scaler, &width, &height); + ok(hr == WINCODEC_ERR_NOTINITIALIZED, "GetSize error %#x\n", hr); + + memset(buf, 0xde, sizeof(buf)); + hr = mil_scaler->lpVtbl->CopyPixels(mil_scaler, NULL, 3, sizeof(buf), buf); + ok(hr == WINCODEC_ERR_NOTINITIALIZED, "CopyPixels error %#x\n", hr); + + hr = mil_scaler->lpVtbl->Initialize(mil_scaler, mil_source, 1, 1, 1); + ok(hr == S_OK, "Initialize error %#x\n", hr); + + hr = mil_scaler->lpVtbl->GetPixelFormat(mil_scaler, &MIL_format); + ok(hr == S_OK, "GetPixelFormat error %#x\n", hr); + ok(MIL_format == 0x0c, "wrong format %d\n", MIL_format); + + hr = mil_scaler->lpVtbl->GetResolution(mil_scaler, &dpix, &dpiy); + ok(hr == S_OK, "GetResolution error %#x\n", hr); + ok(dpix == 12.0, "got %f, expected 12.0\n", dpix); + ok(dpiy == 34.0, "got %f, expected 34.0\n", dpiy); + + hr = mil_scaler->lpVtbl->GetSize(mil_scaler, &width, &height); + ok(hr == S_OK, "GetSize error %#x\n", hr); + ok(width == 1, "got %u, expected 1\n", width); + ok(height == 1, "got %u, expected 1\n", height); + + memset(buf, 0xde, sizeof(buf)); + hr = mil_scaler->lpVtbl->CopyPixels(mil_scaler, NULL, 3, sizeof(buf), buf); + ok(hr == S_OK, "CopyPixels error %#x\n", hr); + ok(buf[0] == 0 && buf[1] == 0 && buf[2] == 0 && buf[3] == 0xde,"wrong data: %02x %02x %02x %02x\n", buf[0], buf[1], buf[2], buf[3]); + + mil_scaler->lpVtbl->Release(mil_scaler); + IWICBitmapScaler_Release(scaler); + mil_source->lpVtbl->Release(mil_source); + mil_bitmap->lpVtbl->Release(mil_bitmap); + IWICBitmap_Release(bitmap); +} + START_TEST(bitmap) { HRESULT hr; @@ -1255,6 +1476,7 @@ START_TEST(bitmap) &IID_IWICImagingFactory, (void**)&factory); ok(SUCCEEDED(hr), "CoCreateInstance failed, hr=%x\n", hr); + test_IMILBitmap(); test_createbitmap(); test_createbitmapfromsource(); test_CreateBitmapFromMemory(); diff --git a/modules/rostests/winetests/windowscodecs/converter.c b/modules/rostests/winetests/windowscodecs/converter.c index 8682f870619..348d5a8cb21 100644 --- a/modules/rostests/winetests/windowscodecs/converter.c +++ b/modules/rostests/winetests/windowscodecs/converter.c @@ -397,8 +397,8 @@ static const struct bitmap_data testdata_2bppIndexed = { /* some encoders (like BMP) require data to be 4-bytes aligned */ static const BYTE bits_4bpp[] = { - 0x01,0x23,0x01,0x23,0x01,0x23,0x01,0x23,0x01,0x23,0x01,0x23,0x01,0x23,0x01,0x23, - 0x45,0x67,0x45,0x67,0x45,0x67,0x45,0x67,0x45,0x67,0x45,0x67,0x45,0x67,0x45,0x67}; + 0x34,0x43,0x34,0x43,0x34,0x43,0x34,0x43,0x34,0x43,0x34,0x43,0x34,0x43,0x34,0x43, + 0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44}; static const struct bitmap_data testdata_4bppIndexed = { &GUID_WICPixelFormat4bppIndexed, 4, bits_4bpp, 32, 2, 96.0, 96.0}; @@ -416,8 +416,8 @@ static const struct bitmap_data testdata_8bppIndexed_4colors = { &GUID_WICPixelFormat8bppIndexed, 8, bits_8bpp_4colors, 32, 2, 96.0, 96.0}; static const BYTE bits_8bpp[] = { - 0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3, - 4,5,6,7,4,5,6,7,4,5,6,7,4,5,6,7,4,5,6,7,4,5,6,7,4,5,6,7,4,5,6,7}; + 0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; static const struct bitmap_data testdata_8bppIndexed = { &GUID_WICPixelFormat8bppIndexed, 8, bits_8bpp, 32, 2, 96.0, 96.0}; @@ -491,6 +491,18 @@ static const struct bitmap_data testdata_32bppPBGRA = { static const struct bitmap_data testdata_32bppPRGBA = { &GUID_WICPixelFormat32bppPRGBA, 32, bits_32bppPBGRA, 32, 2, 96.0, 96.0}; +static const BYTE bits_64bppRGBA[] = { + 128,255,128,0,128,0,128,255,128, 0,128,255,128,0,128,255,128, 0,128,0,128,255,128,255,128, 0,128,0,128,0,128,255,128, 255,128,0,128,0,128,255,128, 0,128,255,128,0,128,255,128, 0,128,0,128,255,128,255,128, 0,128,0,128,0,128,255, + 128,255,128,0,128,0,128,255,128, 0,128,255,128,0,128,255,128, 0,128,0,128,255,128,255,128, 0,128,0,128,0,128,255,128, 255,128,0,128,0,128,255,128, 0,128,255,128,0,128,255,128, 0,128,0,128,255,128,255,128, 0,128,0,128,0,128,255, + 128,255,128,0,128,0,128,255,128, 0,128,255,128,0,128,255,128, 0,128,0,128,255,128,255,128, 0,128,0,128,0,128,255,128, 255,128,0,128,0,128,255,128, 0,128,255,128,0,128,255,128, 0,128,0,128,255,128,255,128, 0,128,0,128,0,128,255, + 128,255,128,0,128,0,128,255,128, 0,128,255,128,0,128,255,128, 0,128,0,128,255,128,255,128, 0,128,0,128,0,128,255,128, 255,128,0,128,0,128,255,128, 0,128,255,128,0,128,255,128, 0,128,0,128,255,128,255,128, 0,128,0,128,0,128,255, + 128,0,128,255,128,255,128,255,128, 255,128,0,128,255,128,255,128, 255,128,255,128,0,128,255,128, 255,128,255,128,255,128,255,128, 0,128,255,128,255,128,255,128, 255,128,0,128,255,128,255,128, 255,128,255,128,0,128,255,128, 255,128,255,128,255,128,255, + 128,0,128,255,128,255,128,255,128, 255,128,0,128,255,128,255,128, 255,128,255,128,0,128,255,128, 255,128,255,128,255,128,255,128, 0,128,255,128,255,128,255,128, 255,128,0,128,255,128,255,128, 255,128,255,128,0,128,255,128, 255,128,255,128,255,128,255, + 128,0,128,255,128,255,128,255,128, 255,128,0,128,255,128,255,128, 255,128,255,128,0,128,255,128, 255,128,255,128,255,128,255,128, 0,128,255,128,255,128,255,128, 255,128,0,128,255,128,255,128, 255,128,255,128,0,128,255,128, 255,128,255,128,255,128,255, + 128,0,128,255,128,255,128,255,128, 255,128,0,128,255,128,255,128, 255,128,255,128,0,128,255,128, 255,128,255,128,255,128,255,128, 0,128,255,128,255,128,255,128, 255,128,0,128,255,128,255,128, 255,128,255,128,0,128,255,128, 255,128,255,128,255,128,255}; +static const struct bitmap_data testdata_64bppRGBA = { + &GUID_WICPixelFormat64bppRGBA, 64, bits_64bppRGBA, 32, 2, 96.0, 96.0}; + /* XP and 2003 use linear color conversion, later versions use sRGB gamma */ static const float bits_32bppGrayFloat_xp[] = { 0.114000f,0.587000f,0.299000f,0.000000f,0.114000f,0.587000f,0.299000f,0.000000f, @@ -863,7 +875,7 @@ static void check_tiff_format(IStream *stream, const WICPixelFormatGUID *format) ok(hr == S_OK, "GetCount error %#x\n", hr); ok(count != 0, "wrong count %u\n", count); - for (i = 0; i < sizeof(tag)/sizeof(tag[0]); i++) + for (i = 0; i < ARRAY_SIZE(tag); i++) { PropVariantInit(&id); PropVariantInit(&value); @@ -880,6 +892,8 @@ static void check_tiff_format(IStream *stream, const WICPixelFormatGUID *format) } else tag[i].value[0] = -1; + + PropVariantClear(&value); } IWICMetadataReader_Release(reader); @@ -1319,7 +1333,7 @@ static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* cls hr = IWICBitmapEncoderInfo_GetCLSID(info, &clsid); ok(hr == S_OK, "wrong error %#x\n", hr); - ok(!IsEqualGUID(&clsid_encoder, &clsid), "wrong CLSID %s (%s)\n", + ok(!IsEqualGUID(clsid_encoder, &clsid), "wrong CLSID %s (%s)\n", wine_dbgstr_guid(clsid_encoder), wine_dbgstr_guid(&clsid)); IWICBitmapEncoderInfo_Release(info); @@ -1408,8 +1422,8 @@ static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* cls ok(SUCCEEDED(hr), "WriteSource(%dx%d) failed, hr=%x (%s)\n", rc->Width, rc->Height, hr, name); else ok(hr == S_OK || - (hr == E_NOTIMPL && IsEqualGUID(clsid_encoder, &CLSID_WICBmpEncoder) && srcs[i]->bpp == 2) || - (hr == E_NOTIMPL && IsEqualGUID(clsid_encoder, &CLSID_WICTiffEncoder) && srcs[i]->bpp == 2) || + (FAILED(hr) && IsEqualGUID(clsid_encoder, &CLSID_WICBmpEncoder) && srcs[i]->bpp == 2) /* XP */ || + (FAILED(hr) && IsEqualGUID(clsid_encoder, &CLSID_WICTiffEncoder) && srcs[i]->bpp == 2) /* XP */ || broken(hr == E_INVALIDARG && IsEqualGUID(clsid_encoder, &CLSID_WICBmpEncoder) && IsEqualGUID(srcs[i]->format, &GUID_WICPixelFormatBlackWhite)) /* XP */, "WriteSource(NULL) failed, hr=%x (%s)\n", hr, name); } @@ -1688,7 +1702,7 @@ static void test_converter_8bppIndexed(void) ok(hr == S_OK, "GetColorCount error %#x\n", hr); ok(count == 0, "expected 0, got %u\n", count); - /* NULL palette + Custom type*/ + /* NULL palette + Custom type */ hr = IWICImagingFactory_CreateFormatConverter(factory, &converter); ok(hr == S_OK, "CreateFormatConverter error %#x\n", hr); hr = IWICFormatConverter_Initialize(converter, &src_obj->IWICBitmapSource_iface, @@ -1701,7 +1715,7 @@ static void test_converter_8bppIndexed(void) ok(hr == S_OK, "CopyPixels error %#x\n", hr); IWICFormatConverter_Release(converter); - /* NULL palette + Custom type*/ + /* NULL palette + Custom type */ hr = IWICImagingFactory_CreateFormatConverter(factory, &converter); ok(hr == S_OK, "CreateFormatConverter error %#x\n", hr); hr = IWICFormatConverter_Initialize(converter, &src_obj->IWICBitmapSource_iface, @@ -1714,7 +1728,7 @@ static void test_converter_8bppIndexed(void) ok(hr == WINCODEC_ERR_WRONGSTATE, "unexpected error %#x\n", hr); IWICFormatConverter_Release(converter); - /* empty palette + Custom type*/ + /* empty palette + Custom type */ hr = IWICImagingFactory_CreateFormatConverter(factory, &converter); ok(hr == S_OK, "CreateFormatConverter error %#x\n", hr); hr = IWICFormatConverter_Initialize(converter, &src_obj->IWICBitmapSource_iface, @@ -1736,7 +1750,7 @@ static void test_converter_8bppIndexed(void) ok(count == 0, "expected 0\n"); IWICFormatConverter_Release(converter); - /* NULL palette + Predefined type*/ + /* NULL palette + Predefined type */ hr = IWICImagingFactory_CreateFormatConverter(factory, &converter); ok(hr == S_OK, "CreateFormatConverter error %#x\n", hr); hr = IWICFormatConverter_Initialize(converter, &src_obj->IWICBitmapSource_iface, @@ -1757,7 +1771,7 @@ static void test_converter_8bppIndexed(void) ok(count != 0, "expected != 0\n"); IWICFormatConverter_Release(converter); - /* not empty palette + Predefined type*/ + /* not empty palette + Predefined type */ hr = IWICImagingFactory_CreateFormatConverter(factory, &converter); ok(hr == S_OK, "CreateFormatConverter error %#x\n", hr); hr = IWICFormatConverter_Initialize(converter, &src_obj->IWICBitmapSource_iface, @@ -1778,7 +1792,7 @@ static void test_converter_8bppIndexed(void) ok(count != 0, "expected != 0\n"); IWICFormatConverter_Release(converter); - /* not empty palette + MedianCut type*/ + /* not empty palette + MedianCut type */ hr = IWICImagingFactory_CreateFormatConverter(factory, &converter); ok(hr == S_OK, "CreateFormatConverter error %#x\n", hr); hr = IWICFormatConverter_Initialize(converter, &src_obj->IWICBitmapSource_iface, @@ -1799,7 +1813,7 @@ static void test_converter_8bppIndexed(void) ok(count != 0, "expected != 0\n"); IWICFormatConverter_Release(converter); - /* NULL palette + MedianCut type*/ + /* NULL palette + MedianCut type */ hr = IWICImagingFactory_CreateFormatConverter(factory, &converter); ok(hr == S_OK, "CreateFormatConverter error %#x\n", hr); hr = IWICFormatConverter_Initialize(converter, &src_obj->IWICBitmapSource_iface, @@ -1867,6 +1881,9 @@ START_TEST(converter) test_conversion(&testdata_24bppRGB, &testdata_32bppBGR, "24bppRGB -> 32bppBGR", FALSE); test_conversion(&testdata_32bppBGRA, &testdata_24bppRGB, "32bppBGRA -> 24bppRGB", FALSE); + test_conversion(&testdata_64bppRGBA, &testdata_32bppRGBA, "64bppRGBA -> 32bppRGBA", FALSE); + test_conversion(&testdata_64bppRGBA, &testdata_32bppRGB, "64bppRGBA -> 32bppRGB", FALSE); + test_conversion(&testdata_24bppRGB, &testdata_32bppGrayFloat, "24bppRGB -> 32bppGrayFloat", FALSE); test_conversion(&testdata_32bppBGR, &testdata_32bppGrayFloat, "32bppBGR -> 32bppGrayFloat", FALSE); diff --git a/modules/rostests/winetests/windowscodecs/metadata.c b/modules/rostests/winetests/windowscodecs/metadata.c index 91a5d20f377..58da19cee47 100644 --- a/modules/rostests/winetests/windowscodecs/metadata.c +++ b/modules/rostests/winetests/windowscodecs/metadata.c @@ -3032,6 +3032,7 @@ static void test_queryreader(void) ok(hr == E_INVALIDARG, "got %#x\n", hr); IWICMetadataQueryReader_Release(new_reader); + PropVariantClear(&value); } else if (value.vt == VT_LPSTR) ok(!lstrcmpA(U(value).pszVal, test_data[i].str_value), "%u: expected %s, got %s\n", diff --git a/modules/rostests/winetests/windowscodecs/palette.c b/modules/rostests/winetests/windowscodecs/palette.c index 5bb25fa4279..583fa66c80e 100644 --- a/modules/rostests/winetests/windowscodecs/palette.c +++ b/modules/rostests/winetests/windowscodecs/palette.c @@ -602,7 +602,7 @@ static void test_palette_from_bitmap(void) ok(hr == S_OK, "GetColorCount error %#x\n", hr); ok(count == 2, "expected 2, got %u\n", count); - /* without trasparent color */ + /* without transparent color */ hr = IWICPalette_InitializeFromBitmap(palette, (IWICBitmapSource *)bitmap, 16, FALSE); ok(hr == S_OK, "InitializeFromBitmap error %#x\n", hr); type = -1; @@ -619,7 +619,7 @@ static void test_palette_from_bitmap(void) ok(ret == count, "expected %u, got %u\n", count, ret); ok(color[count - 1] != 0, "expected !0, got %08x\n", color[count - 1]); - /* with trasparent color */ + /* with transparent color */ hr = IWICPalette_InitializeFromBitmap(palette, (IWICBitmapSource *)bitmap, 16, TRUE); ok(hr == S_OK, "InitializeFromBitmap error %#x\n", hr); type = -1; diff --git a/modules/rostests/winetests/windowscodecs/stream.c b/modules/rostests/winetests/windowscodecs/stream.c index 3750c32f3c2..048f1326be0 100644 --- a/modules/rostests/winetests/windowscodecs/stream.c +++ b/modules/rostests/winetests/windowscodecs/stream.c @@ -765,7 +765,7 @@ static void test_StreamOnIStream(void) ok(hr == S_OK, "Failed to create a stream, hr %#x.\n", hr); hr = IWICStream_InitializeFromMemory(stream, memory, sizeof(memory)); - ok(hr == S_OK, "Failed to initialize stream, hr %#x.", hr); + ok(hr == S_OK, "Failed to initialize stream, hr %#x.\n", hr); hr = IWICImagingFactory_CreateStream(factory, &substream); ok(hr == S_OK, "Failed to create a stream, hr %#x.\n", hr); diff --git a/modules/rostests/winetests/windowscodecs/tiffformat.c b/modules/rostests/winetests/windowscodecs/tiffformat.c index 289e0611450..8cdc0047a21 100644 --- a/modules/rostests/winetests/windowscodecs/tiffformat.c +++ b/modules/rostests/winetests/windowscodecs/tiffformat.c @@ -750,7 +750,8 @@ static void test_tiff_24bpp(void) static const BYTE expected_data[] = { 0x33,0x22,0x11 }; hr = create_decoder(&tiff_24bpp_data, sizeof(tiff_24bpp_data), &decoder); - ok(hr == S_OK, "got %#x\n", hr); + ok(hr == S_OK, "Failed to load TIFF image data %#x\n", hr); + if (hr != S_OK) return; ok(decoder != NULL, "Failed to load TIFF image data\n"); hr = IWICBitmapDecoder_GetFrameCount(decoder, &count);
1
0
0
0
[reactos] 01/01: [WINDOWSCODECS] Sync with Wine Staging 4.18. CORE-16441
by Amine Khaldi
07 Dec '19
07 Dec '19
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=f6a1733dafffe30252fdb…
commit f6a1733dafffe30252fdb50879c56fea27e2d42a Author: Amine Khaldi <amine.khaldi(a)reactos.org> AuthorDate: Sat Dec 7 13:04:33 2019 +0100 Commit: Amine Khaldi <amine.khaldi(a)reactos.org> CommitDate: Sat Dec 7 13:04:33 2019 +0100 [WINDOWSCODECS] Sync with Wine Staging 4.18. CORE-16441 --- dll/win32/windowscodecs/bitmap.c | 92 ++++++++++++----------------- dll/win32/windowscodecs/converter.c | 91 ++++++++++++++++++++-------- dll/win32/windowscodecs/icnsformat.c | 1 - dll/win32/windowscodecs/metadataquery.c | 3 +- dll/win32/windowscodecs/msvc.h | 2 - dll/win32/windowscodecs/palette.c | 4 +- dll/win32/windowscodecs/pngformat.c | 13 +++- dll/win32/windowscodecs/precomp.h | 3 - dll/win32/windowscodecs/scaler.c | 42 +------------ dll/win32/windowscodecs/tiffformat.c | 1 + dll/win32/windowscodecs/typeof.h | 1 + dll/win32/windowscodecs/wincodecs_private.h | 39 ++++++------ media/doc/README.WINE | 2 +- 13 files changed, 145 insertions(+), 149 deletions(-) diff --git a/dll/win32/windowscodecs/bitmap.c b/dll/win32/windowscodecs/bitmap.c index a44f5bd7b39..7959da6911d 100644 --- a/dll/win32/windowscodecs/bitmap.c +++ b/dll/win32/windowscodecs/bitmap.c @@ -1,5 +1,6 @@ /* * Copyright 2012 Vincent Povirk for CodeWeavers + * Copyright 2016 Dmitry Timoshkov * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -16,7 +17,9 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ +#ifndef __REACTOS__ #include "config.h" +#endif #include <stdarg.h> @@ -28,6 +31,7 @@ #include "wincodecs_private.h" +#include "wine/asm.h" #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(wincodecs); @@ -38,7 +42,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(wincodecs); typedef struct BitmapImpl { IMILUnknown1 IMILUnknown1_iface; LONG ref; - IMILBitmapSource IMILBitmapSource_iface; + IMILBitmap IMILBitmap_iface; IWICBitmap IWICBitmap_iface; IMILUnknown2 IMILUnknown2_iface; IWICPalette *palette; @@ -68,9 +72,9 @@ static inline BitmapImpl *impl_from_IWICBitmap(IWICBitmap *iface) return CONTAINING_RECORD(iface, BitmapImpl, IWICBitmap_iface); } -static inline BitmapImpl *impl_from_IMILBitmapSource(IMILBitmapSource *iface) +static inline BitmapImpl *impl_from_IMILBitmap(IMILBitmap *iface) { - return CONTAINING_RECORD(iface, BitmapImpl, IMILBitmapSource_iface); + return CONTAINING_RECORD(iface, BitmapImpl, IMILBitmap_iface); } static inline BitmapImpl *impl_from_IMILUnknown1(IMILUnknown1 *iface) @@ -254,7 +258,7 @@ static HRESULT WINAPI BitmapImpl_QueryInterface(IWICBitmap *iface, REFIID iid, else if (IsEqualIID(&IID_IMILBitmap, iid) || IsEqualIID(&IID_IMILBitmapSource, iid)) { - *ppv = &This->IMILBitmapSource_iface; + *ppv = &This->IMILBitmap_iface; } else { @@ -478,51 +482,30 @@ static const IWICBitmapVtbl BitmapImpl_Vtbl = { BitmapImpl_SetResolution }; -static HRESULT WINAPI IMILBitmapImpl_QueryInterface(IMILBitmapSource *iface, REFIID iid, +static HRESULT WINAPI IMILBitmapImpl_QueryInterface(IMILBitmap *iface, REFIID iid, void **ppv) { - BitmapImpl *This = impl_from_IMILBitmapSource(iface); + BitmapImpl *This = impl_from_IMILBitmap(iface); TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv); - - if (!ppv) return E_INVALIDARG; - - if (IsEqualIID(&IID_IUnknown, iid) || - IsEqualIID(&IID_IMILBitmap, iid) || - IsEqualIID(&IID_IMILBitmapSource, iid)) - { - IUnknown_AddRef(&This->IMILBitmapSource_iface); - *ppv = &This->IMILBitmapSource_iface; - return S_OK; - } - else if (IsEqualIID(&IID_IWICBitmap, iid) || - IsEqualIID(&IID_IWICBitmapSource, iid)) - { - IUnknown_AddRef(&This->IWICBitmap_iface); - *ppv = &This->IWICBitmap_iface; - return S_OK; - } - - FIXME("unknown interface %s\n", debugstr_guid(iid)); - *ppv = NULL; - return E_NOINTERFACE; + return IWICBitmap_QueryInterface(&This->IWICBitmap_iface, iid, ppv); } -static ULONG WINAPI IMILBitmapImpl_AddRef(IMILBitmapSource *iface) +static ULONG WINAPI IMILBitmapImpl_AddRef(IMILBitmap *iface) { - BitmapImpl *This = impl_from_IMILBitmapSource(iface); + BitmapImpl *This = impl_from_IMILBitmap(iface); return IWICBitmap_AddRef(&This->IWICBitmap_iface); } -static ULONG WINAPI IMILBitmapImpl_Release(IMILBitmapSource *iface) +static ULONG WINAPI IMILBitmapImpl_Release(IMILBitmap *iface) { - BitmapImpl *This = impl_from_IMILBitmapSource(iface); + BitmapImpl *This = impl_from_IMILBitmap(iface); return IWICBitmap_Release(&This->IWICBitmap_iface); } -static HRESULT WINAPI IMILBitmapImpl_GetSize(IMILBitmapSource *iface, +static HRESULT WINAPI IMILBitmapImpl_GetSize(IMILBitmap *iface, UINT *width, UINT *height) { - BitmapImpl *This = impl_from_IMILBitmapSource(iface); + BitmapImpl *This = impl_from_IMILBitmap(iface); TRACE("(%p,%p,%p)\n", iface, width, height); return IWICBitmap_GetSize(&This->IWICBitmap_iface, width, height); } @@ -556,10 +539,10 @@ static const struct { &GUID_WICPixelFormat32bppCMYK, 0x1c } }; -static HRESULT WINAPI IMILBitmapImpl_GetPixelFormat(IMILBitmapSource *iface, +static HRESULT WINAPI IMILBitmapImpl_GetPixelFormat(IMILBitmap *iface, int *format) { - BitmapImpl *This = impl_from_IMILBitmapSource(iface); + BitmapImpl *This = impl_from_IMILBitmap(iface); int i; TRACE("(%p,%p)\n", iface, format); @@ -581,33 +564,33 @@ static HRESULT WINAPI IMILBitmapImpl_GetPixelFormat(IMILBitmapSource *iface, return S_OK; } -static HRESULT WINAPI IMILBitmapImpl_GetResolution(IMILBitmapSource *iface, +static HRESULT WINAPI IMILBitmapImpl_GetResolution(IMILBitmap *iface, double *dpix, double *dpiy) { - BitmapImpl *This = impl_from_IMILBitmapSource(iface); + BitmapImpl *This = impl_from_IMILBitmap(iface); TRACE("(%p,%p,%p)\n", iface, dpix, dpiy); return IWICBitmap_GetResolution(&This->IWICBitmap_iface, dpix, dpiy); } -static HRESULT WINAPI IMILBitmapImpl_CopyPalette(IMILBitmapSource *iface, +static HRESULT WINAPI IMILBitmapImpl_CopyPalette(IMILBitmap *iface, IWICPalette *palette) { - BitmapImpl *This = impl_from_IMILBitmapSource(iface); + BitmapImpl *This = impl_from_IMILBitmap(iface); TRACE("(%p,%p)\n", iface, palette); return IWICBitmap_CopyPalette(&This->IWICBitmap_iface, palette); } -static HRESULT WINAPI IMILBitmapImpl_CopyPixels(IMILBitmapSource *iface, +static HRESULT WINAPI IMILBitmapImpl_CopyPixels(IMILBitmap *iface, const WICRect *rc, UINT stride, UINT size, BYTE *buffer) { - BitmapImpl *This = impl_from_IMILBitmapSource(iface); + BitmapImpl *This = impl_from_IMILBitmap(iface); TRACE("(%p,%p,%u,%u,%p)\n", iface, rc, stride, size, buffer); return IWICBitmap_CopyPixels(&This->IWICBitmap_iface, rc, stride, size, buffer); } -static HRESULT WINAPI IMILBitmapImpl_unknown1(IMILBitmapSource *iface, void **ppv) +static HRESULT WINAPI IMILBitmapImpl_unknown1(IMILBitmap *iface, void **ppv) { - BitmapImpl *This = impl_from_IMILBitmapSource(iface); + BitmapImpl *This = impl_from_IMILBitmap(iface); TRACE("(%p,%p)\n", iface, ppv); @@ -619,41 +602,41 @@ static HRESULT WINAPI IMILBitmapImpl_unknown1(IMILBitmapSource *iface, void **pp return S_OK; } -static HRESULT WINAPI IMILBitmapImpl_Lock(IMILBitmapSource *iface, const WICRect *rc, DWORD flags, IWICBitmapLock **lock) +static HRESULT WINAPI IMILBitmapImpl_Lock(IMILBitmap *iface, const WICRect *rc, DWORD flags, IWICBitmapLock **lock) { - BitmapImpl *This = impl_from_IMILBitmapSource(iface); + BitmapImpl *This = impl_from_IMILBitmap(iface); TRACE("(%p,%p,%08x,%p)\n", iface, rc, flags, lock); return IWICBitmap_Lock(&This->IWICBitmap_iface, rc, flags, lock); } -static HRESULT WINAPI IMILBitmapImpl_Unlock(IMILBitmapSource *iface, IWICBitmapLock *lock) +static HRESULT WINAPI IMILBitmapImpl_Unlock(IMILBitmap *iface, IWICBitmapLock *lock) { TRACE("(%p,%p)\n", iface, lock); IWICBitmapLock_Release(lock); return S_OK; } -static HRESULT WINAPI IMILBitmapImpl_SetPalette(IMILBitmapSource *iface, IWICPalette *palette) +static HRESULT WINAPI IMILBitmapImpl_SetPalette(IMILBitmap *iface, IWICPalette *palette) { - BitmapImpl *This = impl_from_IMILBitmapSource(iface); + BitmapImpl *This = impl_from_IMILBitmap(iface); TRACE("(%p,%p)\n", iface, palette); return IWICBitmap_SetPalette(&This->IWICBitmap_iface, palette); } -static HRESULT WINAPI IMILBitmapImpl_SetResolution(IMILBitmapSource *iface, double dpix, double dpiy) +static HRESULT WINAPI IMILBitmapImpl_SetResolution(IMILBitmap *iface, double dpix, double dpiy) { - BitmapImpl *This = impl_from_IMILBitmapSource(iface); + BitmapImpl *This = impl_from_IMILBitmap(iface); TRACE("(%p,%f,%f)\n", iface, dpix, dpiy); return IWICBitmap_SetResolution(&This->IWICBitmap_iface, dpix, dpiy); } -static HRESULT WINAPI IMILBitmapImpl_AddDirtyRect(IMILBitmapSource *iface, const WICRect *rc) +static HRESULT WINAPI IMILBitmapImpl_AddDirtyRect(IMILBitmap *iface, const WICRect *rc) { FIXME("(%p,%p): stub\n", iface, rc); return E_NOTIMPL; } -static const IMILBitmapSourceVtbl IMILBitmapImpl_Vtbl = +static const IMILBitmapVtbl IMILBitmapImpl_Vtbl = { IMILBitmapImpl_QueryInterface, IMILBitmapImpl_AddRef, @@ -674,6 +657,7 @@ static const IMILBitmapSourceVtbl IMILBitmapImpl_Vtbl = static HRESULT WINAPI IMILUnknown1Impl_QueryInterface(IMILUnknown1 *iface, REFIID iid, void **ppv) { + /* It's not clear what interface should be returned here */ FIXME("(%p,%s,%p): stub\n", iface, debugstr_guid(iid), ppv); *ppv = NULL; return E_NOINTERFACE; @@ -835,7 +819,7 @@ HRESULT BitmapImpl_Create(UINT uiWidth, UINT uiHeight, UINT stride, UINT datasiz } This->IWICBitmap_iface.lpVtbl = &BitmapImpl_Vtbl; - This->IMILBitmapSource_iface.lpVtbl = &IMILBitmapImpl_Vtbl; + This->IMILBitmap_iface.lpVtbl = &IMILBitmapImpl_Vtbl; This->IMILUnknown1_iface.lpVtbl = &IMILUnknown1Impl_Vtbl; This->IMILUnknown2_iface.lpVtbl = &IMILUnknown2Impl_Vtbl; This->ref = 1; diff --git a/dll/win32/windowscodecs/converter.c b/dll/win32/windowscodecs/converter.c index c3476c3efa4..dcc2f05693f 100644 --- a/dll/win32/windowscodecs/converter.c +++ b/dll/win32/windowscodecs/converter.c @@ -85,14 +85,6 @@ typedef struct FormatConverter { } FormatConverter; /*
https://www.w3.org/Graphics/Color/srgb
*/ -#ifndef __REACTOS__ -static inline float from_sRGB_component(float f) -{ - if (f <= 0.04045f) return f / 12.92f; - return powf((f + 0.055f) / 1.055f, 2.4f); -} -#endif - static inline float to_sRGB_component(float f) { if (f <= 0.0031308f) return 12.92f * f; @@ -100,6 +92,12 @@ static inline float to_sRGB_component(float f) } #if 0 /* FIXME: enable once needed */ +static inline float from_sRGB_component(float f) +{ + if (f <= 0.04045f) return f / 12.92f; + return powf((f + 0.055f) / 1.055f, 2.4f); +} + static void from_sRGB(BYTE *bgr) { float r, g, b; @@ -460,8 +458,9 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe dstpixel=(DWORD*)dstrow; for (x=0; x<prc->Width; x++) { + srcbyte++; *dstpixel++ = 0xff000000|(*srcbyte<<16)|(*srcbyte<<8)|*srcbyte; - srcbyte+=2; + srcbyte++; } srcrow += srcstride; dstrow += cbStride; @@ -778,9 +777,9 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe dstpixel=(DWORD*)dstrow; for (x=0; x<prc->Width; x++) { BYTE red, green, blue; - red = *srcpixel++; srcpixel++; - green = *srcpixel++; srcpixel++; - blue = *srcpixel++; srcpixel++; + srcpixel++; red = *srcpixel++; + srcpixel++; green = *srcpixel++; + srcpixel++; blue = *srcpixel++; *dstpixel++=0xff000000|red<<16|green<<8|blue; } srcrow += srcstride; @@ -822,10 +821,10 @@ static HRESULT copypixels_to_32bppBGRA(struct FormatConverter *This, const WICRe dstpixel=(DWORD*)dstrow; for (x=0; x<prc->Width; x++) { BYTE red, green, blue, alpha; - red = *srcpixel++; srcpixel++; - green = *srcpixel++; srcpixel++; - blue = *srcpixel++; srcpixel++; - alpha = *srcpixel++; srcpixel++; + srcpixel++; red = *srcpixel++; + srcpixel++; green = *srcpixel++; + srcpixel++; blue = *srcpixel++; + srcpixel++; alpha = *srcpixel++; *dstpixel++=alpha<<24|red<<16|green<<8|blue; } srcrow += srcstride; @@ -872,11 +871,47 @@ static HRESULT copypixels_to_32bppRGBA(struct FormatConverter *This, const WICRe switch (source_format) { case format_32bppRGB: + if (prc) + { + INT x, y; + + hr = IWICBitmapSource_CopyPixels(This->source, prc, cbStride, cbBufferSize, pbBuffer); + if (FAILED(hr)) return hr; + + /* set all alpha values to 255 */ + for (y=0; y<prc->Height; y++) + for (x=0; x<prc->Width; x++) + pbBuffer[cbStride*y+4*x+3] = 0xff; + } + return S_OK; + case format_32bppRGBA: - case format_32bppPRGBA: if (prc) return IWICBitmapSource_CopyPixels(This->source, prc, cbStride, cbBufferSize, pbBuffer); return S_OK; + + case format_32bppPRGBA: + if (prc) + { + INT x, y; + + hr = IWICBitmapSource_CopyPixels(This->source, prc, cbStride, cbBufferSize, pbBuffer); + if (FAILED(hr)) return hr; + + for (y=0; y<prc->Height; y++) + for (x=0; x<prc->Width; x++) + { + BYTE alpha = pbBuffer[cbStride*y+4*x+3]; + if (alpha != 0 && alpha != 255) + { + pbBuffer[cbStride*y+4*x] = pbBuffer[cbStride*y+4*x] * 255 / alpha; + pbBuffer[cbStride*y+4*x+1] = pbBuffer[cbStride*y+4*x+1] * 255 / alpha; + pbBuffer[cbStride*y+4*x+2] = pbBuffer[cbStride*y+4*x+2] * 255 / alpha; + } + } + } + return S_OK; + default: hr = copypixels_to_32bppBGRA(This, prc, cbStride, cbBufferSize, pbBuffer, source_format); if (SUCCEEDED(hr) && prc) @@ -1304,6 +1339,9 @@ static HRESULT copypixels_to_8bppGray(struct FormatConverter *This, const WICRec return hr; } + if (!prc) + return copypixels_to_24bppBGR(This, NULL, cbStride, cbBufferSize, pbBuffer, source_format); + srcstride = 3 * prc->Width; srcdatasize = srcstride * prc->Height; @@ -1311,7 +1349,7 @@ static HRESULT copypixels_to_8bppGray(struct FormatConverter *This, const WICRec if (!srcdata) return E_OUTOFMEMORY; hr = copypixels_to_24bppBGR(This, prc, srcstride, srcdatasize, srcdata, source_format); - if (SUCCEEDED(hr) && prc) + if (SUCCEEDED(hr)) { INT x, y; BYTE *src = srcdata, *dst = pbBuffer; @@ -1337,7 +1375,7 @@ static HRESULT copypixels_to_8bppGray(struct FormatConverter *This, const WICRec return hr; } -static UINT rgb_to_palette_index(BYTE r, BYTE g, BYTE b, WICColor *colors, UINT count) +static UINT rgb_to_palette_index(BYTE bgr[3], WICColor *colors, UINT count) { UINT best_diff, best_index, i; @@ -1347,15 +1385,15 @@ static UINT rgb_to_palette_index(BYTE r, BYTE g, BYTE b, WICColor *colors, UINT for (i = 0; i < count; i++) { BYTE pal_r, pal_g, pal_b; - DWORD diff_r, diff_g, diff_b, diff; + UINT diff_r, diff_g, diff_b, diff; pal_r = colors[i] >> 16; pal_g = colors[i] >> 8; pal_b = colors[i]; - diff_r = r - pal_r; - diff_g = g - pal_g; - diff_b = b - pal_b; + diff_r = bgr[2] - pal_r; + diff_g = bgr[1] - pal_g; + diff_b = bgr[0] - pal_b; diff = diff_r * diff_r + diff_g * diff_g + diff_b * diff_b; if (diff == 0) return i; @@ -1386,6 +1424,9 @@ static HRESULT copypixels_to_8bppIndexed(struct FormatConverter *This, const WIC return S_OK; } + if (!prc) + return copypixels_to_24bppBGR(This, NULL, cbStride, cbBufferSize, pbBuffer, source_format); + if (!This->palette) return WINCODEC_ERR_WRONGSTATE; hr = IWICPalette_GetColors(This->palette, 256, colors, &count); @@ -1398,7 +1439,7 @@ static HRESULT copypixels_to_8bppIndexed(struct FormatConverter *This, const WIC if (!srcdata) return E_OUTOFMEMORY; hr = copypixels_to_24bppBGR(This, prc, srcstride, srcdatasize, srcdata, source_format); - if (SUCCEEDED(hr) && prc) + if (SUCCEEDED(hr)) { INT x, y; BYTE *src = srcdata, *dst = pbBuffer; @@ -1409,7 +1450,7 @@ static HRESULT copypixels_to_8bppIndexed(struct FormatConverter *This, const WIC for (x = 0; x < prc->Width; x++) { - dst[x] = rgb_to_palette_index(bgr[2], bgr[1], bgr[0], colors, count); + dst[x] = rgb_to_palette_index(bgr, colors, count); bgr += 3; } src += srcstride; diff --git a/dll/win32/windowscodecs/icnsformat.c b/dll/win32/windowscodecs/icnsformat.c index 02e8ee97e6d..8194bc508a5 100644 --- a/dll/win32/windowscodecs/icnsformat.c +++ b/dll/win32/windowscodecs/icnsformat.c @@ -75,7 +75,6 @@ #undef SetRect #undef ShowCursor #undef UnionRect -#undef DPRINTF #endif #define COBJMACROS diff --git a/dll/win32/windowscodecs/metadataquery.c b/dll/win32/windowscodecs/metadataquery.c index c4c188d8c9d..79340427547 100644 --- a/dll/win32/windowscodecs/metadataquery.c +++ b/dll/win32/windowscodecs/metadataquery.c @@ -242,7 +242,6 @@ static HRESULT get_token(struct string_t *elem, PROPVARIANT *id, PROPVARIANT *sc bstr = next_token.u.bstrVal; end++; - p = end; while (*end && *end != '}' && end - start < elem->len) { if (*end == '\\') end++; @@ -925,7 +924,7 @@ HRESULT WINAPI WICMapSchemaToName(REFGUID format, LPWSTR schema, UINT len, WCHAR return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); } - if (ret_len) *ret_len = lstrlenW(name2schema[i].name) + 1; + *ret_len = lstrlenW(name2schema[i].name) + 1; return S_OK; } } diff --git a/dll/win32/windowscodecs/msvc.h b/dll/win32/windowscodecs/msvc.h index a694b8601bb..6bb78f43af6 100644 --- a/dll/win32/windowscodecs/msvc.h +++ b/dll/win32/windowscodecs/msvc.h @@ -1,6 +1,4 @@ -#define __ASM_STDCALL_FUNC(name,args,code) - #define typeof(X_) __typeof_ ## X_ struct IMILUnknown1; diff --git a/dll/win32/windowscodecs/palette.c b/dll/win32/windowscodecs/palette.c index 1c1e85834b8..f99cbe00fd1 100644 --- a/dll/win32/windowscodecs/palette.c +++ b/dll/win32/windowscodecs/palette.c @@ -669,8 +669,8 @@ static HRESULT WINAPI PaletteImpl_InitializeFromBitmap(IWICPalette *palette, hr = IWICBitmapSource_GetPixelFormat(source, &format); if (hr != S_OK) return hr; - /* For interoperability with gdiplus where PixelFormat24bppRGB actully stored - * as BGR (and there is no a corresponding RGB format) we have to use 24bppBGR + /* For interoperability with gdiplus where PixelFormat24bppRGB is actually stored + * as BGR (and there is no corresponding RGB format), we have to use 24bppBGR * to avoid format conversions. */ if (!IsEqualGUID(&format, &GUID_WICPixelFormat24bppBGR)) diff --git a/dll/win32/windowscodecs/pngformat.c b/dll/win32/windowscodecs/pngformat.c index 7050c95121b..c0e272e86f0 100644 --- a/dll/win32/windowscodecs/pngformat.c +++ b/dll/win32/windowscodecs/pngformat.c @@ -332,6 +332,7 @@ MAKE_FUNCPTR(png_set_strip_16); MAKE_FUNCPTR(png_set_tRNS); MAKE_FUNCPTR(png_set_tRNS_to_alpha); MAKE_FUNCPTR(png_set_write_fn); +MAKE_FUNCPTR(png_set_swap); MAKE_FUNCPTR(png_read_end); MAKE_FUNCPTR(png_read_image); MAKE_FUNCPTR(png_read_info); @@ -398,6 +399,7 @@ static void *load_libpng(void) LOAD_FUNCPTR(png_set_tRNS); LOAD_FUNCPTR(png_set_tRNS_to_alpha); LOAD_FUNCPTR(png_set_write_fn); + LOAD_FUNCPTR(png_set_swap); LOAD_FUNCPTR(png_read_end); LOAD_FUNCPTR(png_read_image); LOAD_FUNCPTR(png_read_info); @@ -620,7 +622,6 @@ static HRESULT WINAPI PngDecoder_Initialize(IWICBitmapDecoder *iface, IStream *p if (setjmp(jmpbuf)) { ppng_destroy_read_struct(&This->png_ptr, &This->info_ptr, &This->end_info); - HeapFree(GetProcessHeap(), 0, row_pointers); This->png_ptr = NULL; hr = WINCODEC_ERR_UNKNOWNIMAGEFORMAT; goto end; @@ -643,6 +644,10 @@ static HRESULT WINAPI PngDecoder_Initialize(IWICBitmapDecoder *iface, IStream *p color_type = ppng_get_color_type(This->png_ptr, This->info_ptr); bit_depth = ppng_get_bit_depth(This->png_ptr, This->info_ptr); + /* PNGs with bit-depth greater than 8 are network byte order. Windows does not expect this. */ + if (bit_depth > 8) + ppng_set_swap(This->png_ptr); + /* check for color-keyed alpha */ transparency = ppng_get_tRNS(This->png_ptr, This->info_ptr, &trans, &num_trans, &trans_values); @@ -816,6 +821,8 @@ static HRESULT WINAPI PngDecoder_Initialize(IWICBitmapDecoder *iface, IStream *p end: LeaveCriticalSection(&This->lock); + HeapFree(GetProcessHeap(), 0, row_pointers); + return hr; } @@ -1642,6 +1649,10 @@ static HRESULT WINAPI PngFrameEncode_WritePixels(IWICBitmapFrameEncode *iface, } } + /* Tell PNG we need to byte swap if writing a >8-bpp image */ + if (This->format->bit_depth > 8) + ppng_set_swap(This->png_ptr); + ppng_set_IHDR(This->png_ptr, This->info_ptr, This->width, This->height, This->format->bit_depth, This->format->color_type, This->interlace ? PNG_INTERLACE_ADAM7 : PNG_INTERLACE_NONE, diff --git a/dll/win32/windowscodecs/precomp.h b/dll/win32/windowscodecs/precomp.h index 144e085e442..0d0ac5c7af7 100644 --- a/dll/win32/windowscodecs/precomp.h +++ b/dll/win32/windowscodecs/precomp.h @@ -2,9 +2,6 @@ #ifndef WINCODECS_PRECOMP_H #define WINCODECS_PRECOMP_H -#include <wine/config.h> -#include <wine/port.h> - #include <stdarg.h> #define WIN32_NO_STATUS diff --git a/dll/win32/windowscodecs/scaler.c b/dll/win32/windowscodecs/scaler.c index d19e219feab..d6e56d096ea 100644 --- a/dll/win32/windowscodecs/scaler.c +++ b/dll/win32/windowscodecs/scaler.c @@ -1,5 +1,6 @@ /* * Copyright 2010 Vincent Povirk for CodeWeavers + * Copyright 2016 Dmitry Timoshkov * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -224,7 +225,7 @@ static HRESULT WINAPI BitmapScaler_CopyPixels(IWICBitmapScaler *iface, if (!This->source) { - hr = WINCODEC_ERR_WRONGSTATE; + hr = WINCODEC_ERR_NOTINITIALIZED; goto end; } @@ -395,30 +396,8 @@ static HRESULT WINAPI IMILBitmapScaler_QueryInterface(IMILBitmapScaler *iface, R void **ppv) { BitmapScaler *This = impl_from_IMILBitmapScaler(iface); - TRACE("(%p,%s,%p)\n", iface, debugstr_guid(iid), ppv); - - if (!ppv) return E_INVALIDARG; - - if (IsEqualIID(&IID_IUnknown, iid) || - IsEqualIID(&IID_IMILBitmapScaler, iid) || - IsEqualIID(&IID_IMILBitmapSource, iid)) - { - IUnknown_AddRef(&This->IMILBitmapScaler_iface); - *ppv = &This->IMILBitmapScaler_iface; - return S_OK; - } - else if (IsEqualIID(&IID_IWICBitmapScaler, iid) || - IsEqualIID(&IID_IWICBitmapSource, iid)) - { - IUnknown_AddRef(&This->IWICBitmapScaler_iface); - *ppv = &This->IWICBitmapScaler_iface; - return S_OK; - } - - FIXME("unknown interface %s\n", debugstr_guid(iid)); - *ppv = NULL; - return E_NOINTERFACE; + return IWICBitmapScaler_QueryInterface(&This->IWICBitmapScaler_iface, iid, ppv); } static ULONG WINAPI IMILBitmapScaler_AddRef(IMILBitmapScaler *iface) @@ -437,12 +416,7 @@ static HRESULT WINAPI IMILBitmapScaler_GetSize(IMILBitmapScaler *iface, UINT *width, UINT *height) { BitmapScaler *This = impl_from_IMILBitmapScaler(iface); - TRACE("(%p,%p,%p)\n", iface, width, height); - - if (!This->source) - return WINCODEC_ERR_NOTINITIALIZED; - return IWICBitmapScaler_GetSize(&This->IWICBitmapScaler_iface, width, height); } @@ -473,12 +447,7 @@ static HRESULT WINAPI IMILBitmapScaler_GetResolution(IMILBitmapScaler *iface, double *dpix, double *dpiy) { BitmapScaler *This = impl_from_IMILBitmapScaler(iface); - TRACE("(%p,%p,%p)\n", iface, dpix, dpiy); - - if (!This->source) - return WINCODEC_ERR_NOTINITIALIZED; - return IWICBitmapScaler_GetResolution(&This->IWICBitmapScaler_iface, dpix, dpiy); } @@ -499,12 +468,7 @@ static HRESULT WINAPI IMILBitmapScaler_CopyPixels(IMILBitmapScaler *iface, const WICRect *rc, UINT stride, UINT size, BYTE *buffer) { BitmapScaler *This = impl_from_IMILBitmapScaler(iface); - TRACE("(%p,%p,%u,%u,%p)\n", iface, rc, stride, size, buffer); - - if (!This->source) - return WINCODEC_ERR_NOTINITIALIZED; - return IWICBitmapScaler_CopyPixels(&This->IWICBitmapScaler_iface, rc, stride, size, buffer); } diff --git a/dll/win32/windowscodecs/tiffformat.c b/dll/win32/windowscodecs/tiffformat.c index d9b7c4c6096..6f4f6d06b74 100644 --- a/dll/win32/windowscodecs/tiffformat.c +++ b/dll/win32/windowscodecs/tiffformat.c @@ -289,6 +289,7 @@ static HRESULT tiff_get_decode_info(TIFF *tiff, tiff_decode_info *decode_info) decode_info->reverse_bgr = 0; decode_info->invert_grayscale = 0; decode_info->tiled = 0; + decode_info->source_bpp = 0; ret = pTIFFGetField(tiff, TIFFTAG_PHOTOMETRIC, &photometric); if (!ret) diff --git a/dll/win32/windowscodecs/typeof.h b/dll/win32/windowscodecs/typeof.h index b20434b7cce..91995864ac2 100644 --- a/dll/win32/windowscodecs/typeof.h +++ b/dll/win32/windowscodecs/typeof.h @@ -81,6 +81,7 @@ typedef void (__cdecl typeof(png_set_crc_action))(struct png_struct_def *, int, typedef void (__cdecl typeof(png_set_PLTE))(struct png_struct_def *, struct png_info_def *, const struct png_color_struct *, int); typedef void (__cdecl typeof(png_set_tRNS))(struct png_struct_def *, struct png_info_def *, const unsigned char *, int, const struct png_color_16_struct *); typedef void (__cdecl typeof(png_set_filter))(struct png_struct_def *, int, int); +typedef void (__cdecl typeof(png_set_swap))(struct png_struct_def *); typedef void *thandle_t_1; typedef __typeof_intptr (*TIFFReadWriteProc_1)(thandle_t_1, void *, __typeof_intptr); typedef unsigned int (*TIFFSeekProc_1)(void *, unsigned int, int); diff --git a/dll/win32/windowscodecs/wincodecs_private.h b/dll/win32/windowscodecs/wincodecs_private.h index 22af9a12fbb..ff192c26399 100644 --- a/dll/win32/windowscodecs/wincodecs_private.h +++ b/dll/win32/windowscodecs/wincodecs_private.h @@ -53,7 +53,23 @@ DECLARE_INTERFACE_(IMILBitmapSource,IUnknown) STDMETHOD_(HRESULT,GetResolution)(THIS_ double *,double *) PURE; STDMETHOD_(HRESULT,CopyPalette)(THIS_ IWICPalette *) PURE; STDMETHOD_(HRESULT,CopyPixels)(THIS_ const WICRect *,UINT,UINT,BYTE *) PURE; - /*** IMILBitmapSource methods ***/ +}; +#undef INTERFACE + +#define INTERFACE IMILBitmap +DECLARE_INTERFACE_(IMILBitmap,IMILBitmapSource) +{ + /*** IUnknown methods ***/ + STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID,void **) PURE; + STDMETHOD_(ULONG,AddRef)(THIS) PURE; + STDMETHOD_(ULONG,Release)(THIS) PURE; + /*** IWICBitmapSource methods ***/ + STDMETHOD_(HRESULT,GetSize)(THIS_ UINT *,UINT *) PURE; + STDMETHOD_(HRESULT,GetPixelFormat)(THIS_ int *) PURE; + STDMETHOD_(HRESULT,GetResolution)(THIS_ double *,double *) PURE; + STDMETHOD_(HRESULT,CopyPalette)(THIS_ IWICPalette *) PURE; + STDMETHOD_(HRESULT,CopyPixels)(THIS_ const WICRect *,UINT,UINT,BYTE *) PURE; + /*** IMILBitmap methods ***/ STDMETHOD_(HRESULT,unknown1)(THIS_ void **) PURE; STDMETHOD_(HRESULT,Lock)(THIS_ const WICRect *,DWORD,IWICBitmapLock **) PURE; STDMETHOD_(HRESULT,Unlock)(THIS_ IWICBitmapLock *) PURE; @@ -64,7 +80,7 @@ DECLARE_INTERFACE_(IMILBitmapSource,IUnknown) #undef INTERFACE #define INTERFACE IMILBitmapScaler -DECLARE_INTERFACE_(IMILBitmapScaler,IUnknown) +DECLARE_INTERFACE_(IMILBitmapScaler,IMILBitmapSource) { /*** IUnknown methods ***/ STDMETHOD_(HRESULT,QueryInterface)(THIS_ REFIID,void **) PURE; @@ -78,26 +94,11 @@ DECLARE_INTERFACE_(IMILBitmapScaler,IUnknown) STDMETHOD_(HRESULT,CopyPixels)(THIS_ const WICRect *,UINT,UINT,BYTE *) PURE; /*** IMILBitmapScaler methods ***/ STDMETHOD_(HRESULT,unknown1)(THIS_ void **) PURE; - STDMETHOD_(HRESULT,Initialize)(THIS_ IMILBitmapSource *,UINT,UINT,WICBitmapInterpolationMode); + STDMETHOD_(HRESULT,Initialize)(THIS_ IMILBitmapSource *,UINT,UINT,WICBitmapInterpolationMode) PURE; }; #undef INTERFACE -#ifdef __i386__ /* thiscall functions are i386-specific */ - -#define THISCALL(func) __thiscall_ ## func -#define DEFINE_THISCALL_WRAPPER(func,args) \ - extern typeof(func) THISCALL(func); \ - __ASM_STDCALL_FUNC(__thiscall_ ## func, args, \ - "popl %eax\n\t" \ - "pushl %ecx\n\t" \ - "pushl %eax\n\t" \ - "jmp " __ASM_NAME(#func) __ASM_STDCALL(args) ) -#else /* __i386__ */ - -#define THISCALL(func) func -#define DEFINE_THISCALL_WRAPPER(func,args) /* nothing */ - -#endif /* __i386__ */ +#define THISCALLMETHOD_(type,method) type (__thiscall *method) #define INTERFACE IMILUnknown1 DECLARE_INTERFACE_(IMILUnknown1,IUnknown) diff --git a/media/doc/README.WINE b/media/doc/README.WINE index def03896c75..876663af0de 100644 --- a/media/doc/README.WINE +++ b/media/doc/README.WINE @@ -197,7 +197,7 @@ dll/win32/version # Synced to WineStaging-4.18 dll/win32/vssapi # Synced to WineStaging-4.18 dll/win32/wbemdisp # Synced to WineStaging-4.18 dll/win32/wbemprox # Synced to WineStaging-4.18 -dll/win32/windowscodecs # Synced to WineStaging-4.0 +dll/win32/windowscodecs # Synced to WineStaging-4.18 dll/win32/windowscodecsext # Synced to WineStaging-2.9 dll/win32/winemp3.acm # Synced to WineStaging-3.3 dll/win32/wing32 # Synced to WineStaging-3.3
1
0
0
0
[reactos] 01/01: [REGEDIT] Improve arrow button visual (#2133)
by Katayama Hirofumi MZ
07 Dec '19
07 Dec '19
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=4c5b21f06c545a3b5dcaf…
commit 4c5b21f06c545a3b5dcafb8dbf732e2787882089 Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com> AuthorDate: Sat Dec 7 10:09:44 2019 +0900 Commit: GitHub <noreply(a)github.com> CommitDate: Sat Dec 7 10:09:44 2019 +0900 [REGEDIT] Improve arrow button visual (#2133) Add IDI_ARROW resource icon and use it for the arrow button. --- base/applications/regedit/childwnd.c | 15 +++++++++++++-- base/applications/regedit/main.h | 1 + base/applications/regedit/regedit.rc | 1 + base/applications/regedit/res/arrow.ico | Bin 0 -> 542 bytes base/applications/regedit/resource.h | 1 + 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/base/applications/regedit/childwnd.c b/base/applications/regedit/childwnd.c index 836145dd0c7..d02fb2da14d 100644 --- a/base/applications/regedit/childwnd.c +++ b/base/applications/regedit/childwnd.c @@ -394,6 +394,7 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa WNDPROC oldproc; HFONT hFont; WCHAR buffer[MAX_PATH]; + DWORD style; /* Load "My Computer" string */ LoadStringW(hInst, IDS_MY_COMPUTER, buffer, COUNT_OF(buffer)); @@ -404,12 +405,21 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa wcsncpy(g_pChildWnd->szPath, buffer, MAX_PATH); g_pChildWnd->nSplitPos = 190; g_pChildWnd->hWnd = hWnd; - g_pChildWnd->hAddressBarWnd = CreateWindowExW(WS_EX_CLIENTEDGE, L"Edit", NULL, WS_CHILD | WS_VISIBLE | WS_CHILDWINDOW | WS_TABSTOP, + + style = WS_CHILD | WS_VISIBLE | WS_TABSTOP; + g_pChildWnd->hAddressBarWnd = CreateWindowExW(WS_EX_CLIENTEDGE, L"Edit", NULL, style, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hWnd, (HMENU)0, hInst, 0); - g_pChildWnd->hAddressBtnWnd = CreateWindowExW(0, L"Button", L"\x00BB", WS_CHILD | WS_VISIBLE | WS_CHILDWINDOW | WS_TABSTOP | BS_TEXT | BS_CENTER | BS_VCENTER | BS_FLAT | BS_DEFPUSHBUTTON, + + style = WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_ICON | BS_CENTER | + BS_VCENTER | BS_FLAT | BS_DEFPUSHBUTTON; + g_pChildWnd->hAddressBtnWnd = CreateWindowExW(0, L"Button", L"\x00BB", style, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, hWnd, (HMENU)0, hInst, 0); + g_pChildWnd->hArrowIcon = (HICON)LoadImageW(hInst, MAKEINTRESOURCEW(IDI_ARROW), + IMAGE_ICON, 12, 12, 0); + SendMessageW(g_pChildWnd->hAddressBtnWnd, BM_SETIMAGE, IMAGE_ICON, (LPARAM)g_pChildWnd->hArrowIcon); + GetClientRect(hWnd, &rc); g_pChildWnd->hTreeWnd = CreateTreeView(hWnd, g_pChildWnd->szPath, (HMENU) TREE_WINDOW); g_pChildWnd->hListWnd = CreateListView(hWnd, (HMENU) LIST_WINDOW, rc.right - g_pChildWnd->nSplitPos); @@ -462,6 +472,7 @@ LRESULT CALLBACK ChildWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPa DestroyListView(g_pChildWnd->hListWnd); DestroyTreeView(g_pChildWnd->hTreeWnd); DestroyMainMenu(); + DestroyIcon(g_pChildWnd->hArrowIcon); HeapFree(GetProcessHeap(), 0, g_pChildWnd); g_pChildWnd = NULL; PostQuitMessage(0); diff --git a/base/applications/regedit/main.h b/base/applications/regedit/main.h index e36600e1a20..084b62cf304 100644 --- a/base/applications/regedit/main.h +++ b/base/applications/regedit/main.h @@ -61,6 +61,7 @@ typedef struct HWND hListWnd; HWND hAddressBarWnd; HWND hAddressBtnWnd; + HICON hArrowIcon; int nFocusPanel; /* 0: left 1: right */ int nSplitPos; WINDOWPLACEMENT pos; diff --git a/base/applications/regedit/regedit.rc b/base/applications/regedit/regedit.rc index 216d4956bd8..58810fb3ced 100644 --- a/base/applications/regedit/regedit.rc +++ b/base/applications/regedit/regedit.rc @@ -40,6 +40,7 @@ IDI_STRING ICON "res/string.ico" IDI_BIN ICON "res/bin.ico" IDI_REGEDIT ICON "res/regedit.ico" IDI_REGFILE ICON "res/regfile.ico" +IDI_ARROW ICON "res/arrow.ico" /* UTF-8 */ #pragma code_page(65001) diff --git a/base/applications/regedit/res/arrow.ico b/base/applications/regedit/res/arrow.ico new file mode 100644 index 00000000000..0ad4359db42 Binary files /dev/null and b/base/applications/regedit/res/arrow.ico differ diff --git a/base/applications/regedit/resource.h b/base/applications/regedit/resource.h index c73c6aeae03..8ada616b95e 100644 --- a/base/applications/regedit/resource.h +++ b/base/applications/regedit/resource.h @@ -34,6 +34,7 @@ #define IDS_APP_TITLE 103 #define IDI_REGEDIT 100 #define IDI_REGFILE 101 +#define IDI_ARROW 102 #define IDI_SMALL 108 #define IDC_REGEDIT 109 #define IDC_REGEDIT_FRAME 110
1
0
0
0
[reactos] 01/01: [WIN32SS][WINSRV] Do CJK font choose workaround (#2134)
by Katayama Hirofumi MZ
06 Dec '19
06 Dec '19
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=007f32a22335963ce8197…
commit 007f32a22335963ce81979339ed788c1a4fdb0b8 Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com> AuthorDate: Fri Dec 6 22:18:51 2019 +0900 Commit: GitHub <noreply(a)github.com> CommitDate: Fri Dec 6 22:18:51 2019 +0900 [WIN32SS][WINSRV] Do CJK font choose workaround (#2134) Don't choose Asian charset font if there is no preferred font for CJK. CORE-12451 --- win32ss/user/winsrv/concfg/font.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/win32ss/user/winsrv/concfg/font.c b/win32ss/user/winsrv/concfg/font.c index 6aa75b074e0..1c3cbb4f191 100644 --- a/win32ss/user/winsrv/concfg/font.c +++ b/win32ss/user/winsrv/concfg/font.c @@ -69,7 +69,13 @@ CreateConsoleFontEx( ~(VARIABLE_PITCH | FF_DECORATIVE | FF_ROMAN | FF_SCRIPT | FF_SWISS)); if (!IsValidConsoleFont(FaceName, CodePage)) + { StringCchCopyW(FaceName, LF_FACESIZE, L"Terminal"); + if (IsCJKCodePage(CodePage)) + { + lf.lfCharSet = ANSI_CHARSET; + } + } StringCchCopyNW(lf.lfFaceName, ARRAYSIZE(lf.lfFaceName), FaceName, LF_FACESIZE);
1
0
0
0
[reactos] 01/01: [KERNEL32_APITEST] Adjust ConsoleCP testcase for Win10 JPN (#2131)
by Katayama Hirofumi MZ
05 Dec '19
05 Dec '19
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=2f8d847c916ff9184f721…
commit 2f8d847c916ff9184f721b0f14a96db0aff5ae96 Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com> AuthorDate: Thu Dec 5 22:07:00 2019 +0900 Commit: GitHub <noreply(a)github.com> CommitDate: Thu Dec 5 22:07:00 2019 +0900 [KERNEL32_APITEST] Adjust ConsoleCP testcase for Win10 JPN (#2131) CORE-12451 --- modules/rostests/apitests/kernel32/ConsoleCP.c | 33 ++++++++++++++++++++------ 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/modules/rostests/apitests/kernel32/ConsoleCP.c b/modules/rostests/apitests/kernel32/ConsoleCP.c index 5580fc189b6..94fcdd3c8a0 100644 --- a/modules/rostests/apitests/kernel32/ConsoleCP.c +++ b/modules/rostests/apitests/kernel32/ConsoleCP.c @@ -21,8 +21,9 @@ static const WCHAR u0414[] = { 0x0414, 0 }; /* Д */ static const WCHAR u9580[] = { 0x9580, 0 }; /* 門 */ static const WCHAR ideograph_space = (WCHAR)0x3000; /* fullwidth space */ -LCID lcidJapanese = MAKELCID(MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT), SORT_DEFAULT); -LCID lcidRussian = MAKELCID(MAKELANGID(LANG_RUSSIAN , SUBLANG_DEFAULT), SORT_DEFAULT); +static LCID lcidJapanese = MAKELCID(MAKELANGID(LANG_JAPANESE, SUBLANG_DEFAULT), SORT_DEFAULT); +static LCID lcidRussian = MAKELCID(MAKELANGID(LANG_RUSSIAN , SUBLANG_DEFAULT), SORT_DEFAULT); +static BOOL s_bIsVistaPlus; static BOOL IsCJKCodePage(void) { @@ -410,7 +411,10 @@ static void test_cp932(HANDLE hConOut) c.X = c.Y = 0; ret = FillConsoleOutputCharacterW(hConOut, ideograph_space, csbi.dwSize.X * csbi.dwSize.Y, c, &len); ok(ret, "FillConsoleOutputCharacterW failed\n"); - ok(len == csbi.dwSize.X * csbi.dwSize.Y, "len was: %ld\n", len); + if (s_bIsVistaPlus) + ok(len == csbi.dwSize.X * csbi.dwSize.Y / 2, "len was: %ld\n", len); + else + ok(len == csbi.dwSize.X * csbi.dwSize.Y, "len was: %ld\n", len); /* Read characters at (0,0) */ c.X = c.Y = 0; @@ -450,10 +454,20 @@ static void test_cp932(HANDLE hConOut) c.X = c.Y = 0; ret = ReadConsoleOutputCharacterW(hConOut, str, 3 * sizeof(WCHAR), c, &len); ok(ret, "ReadConsoleOutputCharacterW failed\n"); - ok(len == 4, "len was: %ld\n", len); - ok(str[0] == L' ', "str[0] was: 0x%04X\n", str[0]); - ok(str[1] == 0x9580, "str[1] was: 0x%04X\n", str[1]); - ok(str[2] == L' ', "str[2] was: 0x%04X\n", str[2]); + if (s_bIsVistaPlus) + { + ok(len == 3, "len was: %ld\n", len); + ok(str[0] == 0x3000, "str[0] was: 0x%04X\n", str[0]); + ok(str[1] == 0x9580, "str[1] was: 0x%04X\n", str[1]); + ok(str[2] == 0x3000, "str[2] was: 0x%04X\n", str[2]); + } + else + { + ok(len == 4, "len was: %ld\n", len); + ok(str[0] == L' ', "str[0] was: 0x%04X\n", str[0]); + ok(str[1] == 0x9580, "str[1] was: 0x%04X\n", str[1]); + ok(str[2] == L' ', "str[2] was: 0x%04X\n", str[2]); + } } /* Restore code page */ @@ -463,6 +477,11 @@ static void test_cp932(HANDLE hConOut) START_TEST(ConsoleCP) { HANDLE hConIn, hConOut; + OSVERSIONINFOA osver = { sizeof(osver) }; + + GetVersionExA(&osver); + s_bIsVistaPlus = (osver.dwMajorVersion >= 6); + FreeConsole(); ok(AllocConsole(), "Couldn't alloc console\n");
1
0
0
0
← Newer
1
...
961
962
963
964
965
966
967
...
8139
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
Results per page:
10
25
50
100
200