Commit 9a5ad302 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

winhttp: Support ICU_ESCAPE in WinHttpCrackUrl.

parent 9a2f3cb9
...@@ -69,6 +69,8 @@ static const WCHAR url12[] = ...@@ -69,6 +69,8 @@ static const WCHAR url12[] =
{'h','t','t','p',':','/','/','e','x','a','m','p','l','e','.','n','e','t','/','p','a','t','h','?','v','a','r','1','=','e','x','a','m','p','l','e','@','e','x','a','m','p','l','e','.','c','o','m','&','v','a','r','2','=','x','&','v','a','r','3','=','y', 0}; {'h','t','t','p',':','/','/','e','x','a','m','p','l','e','.','n','e','t','/','p','a','t','h','?','v','a','r','1','=','e','x','a','m','p','l','e','@','e','x','a','m','p','l','e','.','c','o','m','&','v','a','r','2','=','x','&','v','a','r','3','=','y', 0};
static const WCHAR url13[] = static const WCHAR url13[] =
{'h','t','t','p','s',':','/','/','t','o','o','l','s','.','g','o','o','g','l','e','.','c','o','m','/','s','e','r','v','i','c','e','/','u','p','d','a','t','e','2','?','w','=','3',':','B','x','D','H','o','W','y','8','e','z','M',0}; {'h','t','t','p','s',':','/','/','t','o','o','l','s','.','g','o','o','g','l','e','.','c','o','m','/','s','e','r','v','i','c','e','/','u','p','d','a','t','e','2','?','w','=','3',':','B','x','D','H','o','W','y','8','e','z','M',0};
static const WCHAR url14[] =
{'h','t','t','p',':','/','/','w','i','n','e','h','q','.','o',' ','g','/','p','a','t','h',' ','w','i','t','h',' ','s','p','a','c','e','s',0};
static const WCHAR url_k1[] = 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', {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
...@@ -318,6 +320,10 @@ static void reset_url_components( URL_COMPONENTS *uc ) ...@@ -318,6 +320,10 @@ static void reset_url_components( URL_COMPONENTS *uc )
static void WinHttpCrackUrl_test( void ) static void WinHttpCrackUrl_test( void )
{ {
static const WCHAR hostnameW[] =
{'w','i','n','e','h','q','.','o',' ','g',0};
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; URL_COMPONENTSW uc;
WCHAR scheme[20], user[20], pass[20], host[20], path[80], extra[40]; WCHAR scheme[20], user[20], pass[20], host[20], path[80], extra[40];
DWORD error; DWORD error;
...@@ -599,6 +605,24 @@ static void WinHttpCrackUrl_test( void ) ...@@ -599,6 +605,24 @@ static void WinHttpCrackUrl_test( void )
uc.nPort = 0; uc.nPort = 0;
ret = WinHttpCrackUrl( url13, 0, ICU_DECODE, &uc ); ret = WinHttpCrackUrl( url13, 0, ICU_DECODE, &uc );
ok( ret, "WinHttpCrackUrl failed\n" ); ok( ret, "WinHttpCrackUrl failed\n" );
uc.lpszScheme = scheme;
uc.dwSchemeLength = 20;
uc.lpszHostName = host;
uc.dwHostNameLength = 20;
uc.lpszUserName = NULL;
uc.dwUserNameLength = 0;
uc.lpszPassword = NULL;
uc.dwPasswordLength = 0;
uc.lpszUrlPath = path;
uc.dwUrlPathLength = 40;
uc.lpszExtraInfo = NULL;
uc.dwExtraInfoLength = 0;
uc.nPort = 0;
ret = WinHttpCrackUrl( url14, 0, ICU_ESCAPE|ICU_DECODE, &uc );
ok( ret, "WinHttpCrackUrl failed\n" );
ok( !lstrcmpW( uc.lpszHostName, hostnameW ), "unexpected host name\n" );
ok( !lstrcmpW( uc.lpszUrlPath, pathW ), "unexpected path\n" );
} }
START_TEST(url) START_TEST(url)
......
...@@ -38,7 +38,7 @@ static BOOL set_component( WCHAR **str, DWORD *str_len, WCHAR *value, DWORD len, ...@@ -38,7 +38,7 @@ static BOOL set_component( WCHAR **str, DWORD *str_len, WCHAR *value, DWORD len,
{ {
if (!*str) if (!*str)
{ {
if (len && *str_len && (flags & ICU_DECODE)) if (len && *str_len && (flags & (ICU_DECODE|ICU_ESCAPE)))
{ {
set_last_error( ERROR_INVALID_PARAMETER ); set_last_error( ERROR_INVALID_PARAMETER );
return FALSE; return FALSE;
...@@ -89,18 +89,93 @@ static WCHAR *decode_url( LPCWSTR url, DWORD *len ) ...@@ -89,18 +89,93 @@ static WCHAR *decode_url( LPCWSTR url, DWORD *len )
return ret; return ret;
} }
static BOOL need_escape( WCHAR c )
{
if (isalnumW( c )) return FALSE;
if (c <= 31 || c >= 127) return TRUE;
else
{
switch (c)
{
case ' ':
case '"':
case '#':
case '%':
case '<':
case '>':
case ']':
case '\\':
case '[':
case '^':
case '`':
case '{':
case '|':
case '}':
case '~':
return TRUE;
default:
return FALSE;
}
}
}
static DWORD copy_escape( WCHAR *dst, const WCHAR *src, DWORD len )
{
static const WCHAR hex[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
DWORD ret = len;
unsigned int i;
WCHAR *p = dst;
for (i = 0; i < len; i++, p++)
{
if (need_escape( src[i] ))
{
p[0] = '%';
p[1] = hex[(src[i] >> 4) & 0xf];
p[2] = hex[src[i] & 0xf];
ret += 2;
p += 2;
}
else *p = src[i];
}
dst[ret] = 0;
return ret;
}
static WCHAR *escape_url( LPCWSTR url, DWORD *len )
{
WCHAR *ret;
const WCHAR *p, *q;
if ((p = q = strrchrW( url, '/' )))
{
while (*q)
{
if (need_escape( *q )) *len += 2;
q++;
}
}
if (!(ret = heap_alloc( (*len + 1) * sizeof(WCHAR) ))) return NULL;
if (!p) strcpyW( ret, url );
else
{
memcpy( ret, url, (p - url) * sizeof(WCHAR) );
copy_escape( ret + (p - url), p, q - p );
}
return ret;
}
/*********************************************************************** /***********************************************************************
* WinHttpCrackUrl (winhttp.@) * WinHttpCrackUrl (winhttp.@)
*/ */
BOOL WINAPI WinHttpCrackUrl( LPCWSTR url, DWORD len, DWORD flags, LPURL_COMPONENTSW uc ) BOOL WINAPI WinHttpCrackUrl( LPCWSTR url, DWORD len, DWORD flags, LPURL_COMPONENTSW uc )
{ {
BOOL ret = FALSE; BOOL ret = FALSE;
WCHAR *p, *q, *r, *url_decoded = NULL; WCHAR *p, *q, *r, *url_decoded = NULL, *url_escaped = NULL;
TRACE("%s, %d, %x, %p\n", debugstr_w(url), len, flags, uc); TRACE("%s, %d, %x, %p\n", debugstr_w(url), len, flags, uc);
if (flags & ICU_ESCAPE) FIXME("flag ICU_ESCAPE not supported\n");
if (!url || !uc || uc->dwStructSize != sizeof(URL_COMPONENTS)) if (!url || !uc || uc->dwStructSize != sizeof(URL_COMPONENTS))
{ {
set_last_error( ERROR_INVALID_PARAMETER ); set_last_error( ERROR_INVALID_PARAMETER );
...@@ -108,7 +183,16 @@ BOOL WINAPI WinHttpCrackUrl( LPCWSTR url, DWORD len, DWORD flags, LPURL_COMPONEN ...@@ -108,7 +183,16 @@ BOOL WINAPI WinHttpCrackUrl( LPCWSTR url, DWORD len, DWORD flags, LPURL_COMPONEN
} }
if (!len) len = strlenW( url ); if (!len) len = strlenW( url );
if (flags & ICU_DECODE) if (flags & ICU_ESCAPE)
{
if (!(url_escaped = escape_url( url, &len )))
{
set_last_error( ERROR_OUTOFMEMORY );
return FALSE;
}
url = url_escaped;
}
else if (flags & ICU_DECODE)
{ {
if (!(url_decoded = decode_url( url, &len ))) if (!(url_decoded = decode_url( url, &len )))
{ {
...@@ -211,6 +295,7 @@ BOOL WINAPI WinHttpCrackUrl( LPCWSTR url, DWORD len, DWORD flags, LPURL_COMPONEN ...@@ -211,6 +295,7 @@ BOOL WINAPI WinHttpCrackUrl( LPCWSTR url, DWORD len, DWORD flags, LPURL_COMPONEN
exit: exit:
heap_free( url_decoded ); heap_free( url_decoded );
heap_free( url_escaped );
return ret; return ret;
} }
...@@ -235,60 +320,6 @@ static BOOL uses_default_port( INTERNET_SCHEME scheme, INTERNET_PORT port ) ...@@ -235,60 +320,6 @@ static BOOL uses_default_port( INTERNET_SCHEME scheme, INTERNET_PORT port )
return FALSE; return FALSE;
} }
static BOOL need_escape( WCHAR c )
{
if (isalnumW( c )) return FALSE;
if (c <= 31 || c >= 127) return TRUE;
else
{
switch (c)
{
case ' ':
case '"':
case '#':
case '%':
case '<':
case '>':
case ']':
case '\\':
case '[':
case '^':
case '`':
case '{':
case '|':
case '}':
case '~':
return TRUE;
default:
return FALSE;
}
}
}
static DWORD copy_escape( WCHAR *dst, const WCHAR *src, DWORD len )
{
static const WCHAR hex[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
DWORD ret = len;
unsigned int i;
WCHAR *p = dst;
for (i = 0; i < len; i++, p++)
{
if (need_escape( src[i] ))
{
p[0] = '%';
p[1] = hex[(src[i] >> 4) & 0xf];
p[2] = hex[src[i] & 0xf];
ret += 2;
p += 2;
}
else *p = src[i];
}
dst[ret] = 0;
return ret;
}
static DWORD comp_length( DWORD len, DWORD flags, WCHAR *comp ) static DWORD comp_length( DWORD len, DWORD flags, WCHAR *comp )
{ {
DWORD ret; DWORD ret;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment