Paul TBBle Hampson : winhttp: Correctly parse specified ports in WinHttpCrackUrl.
Alexandre Julliard
julliard at winehq.org
Wed Dec 31 07:45:19 CST 2008
Module: wine
Branch: master
Commit: 4876375ab8d099e8936ee7119d39657fb29d5f0b
URL: http://source.winehq.org/git/wine.git/?a=commit;h=4876375ab8d099e8936ee7119d39657fb29d5f0b
Author: Paul TBBle Hampson <Paul.Hampson at Pobox.com>
Date: Wed Dec 31 17:35:53 2008 +1100
winhttp: Correctly parse specified ports in WinHttpCrackUrl.
---
dlls/winhttp/tests/url.c | 18 +++++++++---------
dlls/winhttp/url.c | 29 ++++++++++++++++++++++++++---
2 files changed, 35 insertions(+), 12 deletions(-)
diff --git a/dlls/winhttp/tests/url.c b/dlls/winhttp/tests/url.c
index 9e5d759..2a04208 100644
--- a/dlls/winhttp/tests/url.c
+++ b/dlls/winhttp/tests/url.c
@@ -361,7 +361,7 @@ static void WinHttpCrackUrl_test( void )
ok( uc.dwPasswordLength == 8, "unexpected password length\n" );
ok( !memcmp( uc.lpszHostName, winehq, sizeof(winehq) ), "unexpected hostname\n" );
ok( uc.dwHostNameLength == 14, "unexpected hostname length\n" );
- todo_wine ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
+ ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
ok( !memcmp( uc.lpszUrlPath, about, sizeof(about) ), "unexpected path\n" );
ok( uc.dwUrlPathLength == 11, "unexpected path length\n" );
ok( !memcmp( uc.lpszExtraInfo, query, sizeof(query) ), "unexpected extra info\n" );
@@ -392,7 +392,7 @@ static void WinHttpCrackUrl_test( void )
ok( uc.dwPasswordLength == 8, "unexpected password length\n" );
ok( uc.lpszHostName == url_k1 + 25, "unexpected hostname\n" );
ok( uc.dwHostNameLength == 14, "unexpected hostname length\n" );
- todo_wine ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
+ ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
ok( uc.lpszUrlPath == url_k1 + 39, "unexpected path\n" );
ok( uc.dwUrlPathLength == 11, "unexpected path length\n" );
ok( uc.lpszExtraInfo == url_k1 + 50, "unexpected extra info\n" );
@@ -411,7 +411,7 @@ static void WinHttpCrackUrl_test( void )
ok( uc.dwPasswordLength == 0, "unexpected password length\n" );
ok( uc.lpszHostName == url_k2 + 7, "unexpected hostname\n" );
ok( uc.dwHostNameLength == 14, "unexpected hostname length\n" );
- todo_wine ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
+ ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
ok( uc.lpszUrlPath == url_k2 + 21, "unexpected path\n" );
ok( uc.dwUrlPathLength == 0, "unexpected path length\n" );
ok( uc.lpszExtraInfo == url_k2 + 21, "unexpected extra info\n" );
@@ -430,7 +430,7 @@ static void WinHttpCrackUrl_test( void )
ok( uc.dwPasswordLength == 0, "unexpected password length\n" );
ok( uc.lpszHostName == url_k3 + 8, "unexpected hostname\n" );
ok( uc.dwHostNameLength == 14, "unexpected hostname length\n" );
- todo_wine ok( uc.nPort == 443, "unexpected port: %u\n", uc.nPort );
+ ok( uc.nPort == 443, "unexpected port: %u\n", uc.nPort );
ok( uc.lpszUrlPath == url_k3 + 22, "unexpected path\n" );
ok( uc.dwUrlPathLength == 5, "unexpected path length\n" );
ok( uc.lpszExtraInfo == url_k3 + 27, "unexpected extra info\n" );
@@ -537,9 +537,9 @@ static void WinHttpCrackUrl_test( void )
ret = WinHttpCrackUrl( url7, 0, 0, &uc );
ok( ret, "WinHttpCrackUrl failed\n" );
- todo_wine ok( !memcmp( uc.lpszHostName, winehq, sizeof(winehq) ), "unexpected host name: %s\n", debugstr_w(uc.lpszHostName) );
- todo_wine ok( uc.dwHostNameLength == 14, "unexpected host name length: %d\n", uc.dwHostNameLength );
- todo_wine ok( uc.nPort == 42, "unexpected port: %u\n", uc.nPort );
+ ok( !memcmp( uc.lpszHostName, winehq, sizeof(winehq) ), "unexpected host name: %s\n", debugstr_w(uc.lpszHostName) );
+ ok( uc.dwHostNameLength == 14, "unexpected host name length: %d\n", uc.dwHostNameLength );
+ ok( uc.nPort == 42, "unexpected port: %u\n", uc.nPort );
/* decoding without buffers */
reset_url_components( &uc );
@@ -550,12 +550,12 @@ static void WinHttpCrackUrl_test( void )
reset_url_components( &uc );
ret = WinHttpCrackUrl( url10, 0, 0, &uc );
ok( ret, "WinHttpCrackUrl failed\n" );
- todo_wine ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
+ ok( uc.nPort == 80, "unexpected port: %u\n", uc.nPort );
reset_url_components( &uc );
ret = WinHttpCrackUrl( url11, 0, 0, &uc );
ok( ret, "WinHttpCrackUrl failed\n" );
- todo_wine ok( uc.nPort == 443, "unexpected port: %u\n", uc.nPort );
+ ok( uc.nPort == 443, "unexpected port: %u\n", uc.nPort );
}
diff --git a/dlls/winhttp/url.c b/dlls/winhttp/url.c
index f8c1972..9ed04cf 100644
--- a/dlls/winhttp/url.c
+++ b/dlls/winhttp/url.c
@@ -149,7 +149,18 @@ BOOL WINAPI WinHttpCrackUrl( LPCWSTR url, DWORD len, DWORD flags, LPURL_COMPONEN
}
if ((q = memchrW( p, '/', len - (p - url) )))
{
- if (!(set_component( &uc->lpszHostName, &uc->dwHostNameLength, p, q - p, flags ))) goto exit;
+ if ((r = memchrW( p, ':', q - p )))
+ {
+ if (!(set_component( &uc->lpszHostName, &uc->dwHostNameLength, p, r - p, flags ))) goto exit;
+ r++;
+ uc->nPort = atoiW( r );
+ }
+ else
+ {
+ if (!(set_component( &uc->lpszHostName, &uc->dwHostNameLength, p, q - p, flags ))) goto exit;
+ if (uc->nScheme == INTERNET_SCHEME_HTTP) uc->nPort = INTERNET_DEFAULT_HTTP_PORT;
+ if (uc->nScheme == INTERNET_SCHEME_HTTPS) uc->nPort = INTERNET_DEFAULT_HTTPS_PORT;
+ }
if ((r = memchrW( q, '?', len - (q - url) )))
{
@@ -164,16 +175,28 @@ BOOL WINAPI WinHttpCrackUrl( LPCWSTR url, DWORD len, DWORD flags, LPURL_COMPONEN
}
else
{
- if (!(set_component( &uc->lpszHostName, &uc->dwHostNameLength, p, len - (p - url), flags ))) goto exit;
+ if ((r = memchrW( p, ':', len - (p - url) )))
+ {
+ if (!(set_component( &uc->lpszHostName, &uc->dwHostNameLength, p, r - p, flags ))) goto exit;
+ r++;
+ uc->nPort = atoiW( r );
+ }
+ else
+ {
+ if (!(set_component( &uc->lpszHostName, &uc->dwHostNameLength, p, len - (p - url), flags ))) goto exit;
+ if (uc->nScheme == INTERNET_SCHEME_HTTP) uc->nPort = INTERNET_DEFAULT_HTTP_PORT;
+ if (uc->nScheme == INTERNET_SCHEME_HTTPS) uc->nPort = INTERNET_DEFAULT_HTTPS_PORT;
+ }
if (!(set_component( &uc->lpszUrlPath, &uc->dwUrlPathLength, (WCHAR *)url + len, 0, flags ))) goto exit;
if (!(set_component( &uc->lpszExtraInfo, &uc->dwExtraInfoLength, (WCHAR *)url + len, 0, flags ))) goto exit;
}
ret = TRUE;
- TRACE("scheme(%s) host(%s) path(%s) extra(%s)\n",
+ TRACE("scheme(%s) host(%s) port(%d) path(%s) extra(%s)\n",
debugstr_wn( uc->lpszScheme, uc->dwSchemeLength ),
debugstr_wn( uc->lpszHostName, uc->dwHostNameLength ),
+ uc->nPort,
debugstr_wn( uc->lpszUrlPath, uc->dwUrlPathLength ),
debugstr_wn( uc->lpszExtraInfo, uc->dwExtraInfoLength ));
More information about the wine-cvs
mailing list