Aric Stewart : winhttp: Correct another difference between InternetCrackurl and WinHttpCrackUrl.

Alexandre Julliard julliard at winehq.org
Wed Nov 12 07:19:05 CST 2008


Module: wine
Branch: master
Commit: 3590a4227fb7eed98199c387439ad608c136afd4
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=3590a4227fb7eed98199c387439ad608c136afd4

Author: Aric Stewart <aric at codeweavers.com>
Date:   Tue Nov 11 09:17:29 2008 -0600

winhttp: Correct another difference between InternetCrackurl and WinHttpCrackUrl.

---

 dlls/winhttp/request.c   |    2 +-
 dlls/winhttp/tests/url.c |   77 ++++++++++++++++++++++++++++++++++++++++++++++
 dlls/winhttp/url.c       |   12 +++++++
 3 files changed, 90 insertions(+), 1 deletions(-)

diff --git a/dlls/winhttp/request.c b/dlls/winhttp/request.c
index 1f91c99..d2d515f 100644
--- a/dlls/winhttp/request.c
+++ b/dlls/winhttp/request.c
@@ -1104,7 +1104,7 @@ static BOOL handle_redirect( request_t *request )
 
         heap_free( request->path );
         request->path = NULL;
-        if (uc.lpszUrlPath)
+        if (uc.dwUrlPathLength)
         {
             len = uc.dwUrlPathLength + uc.dwExtraInfoLength;
             if (!(request->path = heap_alloc( (len + 1) * sizeof(WCHAR) ))) goto end;
diff --git a/dlls/winhttp/tests/url.c b/dlls/winhttp/tests/url.c
index 20ff7f6..5d88614 100644
--- a/dlls/winhttp/tests/url.c
+++ b/dlls/winhttp/tests/url.c
@@ -60,6 +60,13 @@ static const WCHAR url9[] =
     {'h','t','t','p',':','/','/','u','s','e','r','n','a','m','e',':','p','a','s','s','w','o','r','d',
      '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g',':','0','/','s','i','t','e','/','a','b','o','u','t','?','q','u','e','r','y',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',
+     '@','w','w','w','.','w','i','n','e','h','q','.','o','r','g','/','s','i','t','e','/','a','b','o','u','t',0};
+
+static const WCHAR url_k2[]  =
+    {'h','t','t','p',':','/','/','w','w','w','.','w','i','n','e','h','q','.','o','r','g',0};
+
 static void fill_url_components( URL_COMPONENTS *uc )
 {
     uc->dwStructSize = sizeof(URL_COMPONENTS);
@@ -269,7 +276,77 @@ static void WinHttpCreateUrl_test( void )
     HeapFree( GetProcessHeap(), 0, url );
 }
 
+static void WinHttpCrackUrl_test( void )
+{
+    URL_COMPONENTSW uc;
+    DWORD Len = 0;
+    BOOL ret;
+
+    /* NULL components */
+    SetLastError( 0xdeadbeef );
+    memset(&uc,0,sizeof(uc));
+    uc.dwStructSize = sizeof(URL_COMPONENTSW);
+    uc.dwSchemeLength    = -1;
+    uc.dwHostNameLength  = -1;
+    uc.dwUserNameLength  = -1;
+    uc.dwPasswordLength  = -1;
+    uc.dwUrlPathLength   = -1;
+    uc.dwExtraInfoLength = -1;
+
+    ret = WinHttpCrackUrl( url_k1, 0, 0,&uc);
+
+    Len = 0;
+    ok (ret!=0,"WinHttpCrackUrl failed\n");
+    ok (uc.lpszScheme == url_k1,"Failed to get uc.lpszScheme\n");
+    ok (uc.dwSchemeLength == 4, "Unexpected dwSchemeLength\n");
+    Len += uc.dwSchemeLength + 3;
+    ok (uc.lpszUserName== &url_k1[Len],"Failed to get uc.lpszUserName\n");
+    ok (uc.dwUserNameLength == 8, "Unexpected dwUserNameLength\n");
+    Len +=uc.dwUserNameLength + 1;
+    ok (uc.lpszPassword==&url_k1[Len],"Failed to get uc.lpszPassword\n");
+    ok (uc.dwPasswordLength == 8, "Unexpected dwPasswordLength\n");
+    Len +=uc.dwPasswordLength + 1;
+    ok (uc.lpszHostName == &url_k1[Len],"Failed to get uc.lpszHostName\n");
+    ok (uc.dwHostNameLength == 14, "Unexpected dwHostNameLength\n");
+    Len += uc.dwHostNameLength;
+    ok (uc.lpszUrlPath == &url_k1[Len],"Failed to get uc.lpszUrlPath\n");
+    ok (uc.dwUrlPathLength == 11, "Unexpected dwUrlPathLength\n");
+    Len += uc.dwUrlPathLength;
+    ok (uc.lpszExtraInfo == &url_k1[Len],"Failed to get uc.lpszExtraInfo\n");
+    ok (uc.dwExtraInfoLength == 0, "Unexpected dwExtraInfoLength\n");
+
+    memset(&uc,0,sizeof(uc));
+    uc.dwStructSize = sizeof(URL_COMPONENTSW);
+    uc.dwSchemeLength    = -1;
+    uc.dwHostNameLength  = -1;
+    uc.dwUserNameLength  = -1;
+    uc.dwPasswordLength  = -1;
+    uc.dwUrlPathLength   = -1;
+    uc.dwExtraInfoLength = -1;
+
+    ret = WinHttpCrackUrl( url_k2, 0, 0,&uc);
+
+    Len = 0;
+    ok (ret!=0,"WinHttpCrackUrl failed\n");
+    ok (uc.lpszScheme == url_k2,"Failed to get uc.lpszScheme\n");
+    ok (uc.dwSchemeLength == 4, "Unexpected dwSchemeLength\n");
+    Len += uc.dwSchemeLength + 3;
+    ok (uc.lpszUserName == NULL ,"Got uc.lpszUserName\n");
+    ok (uc.dwUserNameLength == 0, "Unexpected dwUserNameLength\n");
+    ok (uc.lpszPassword == NULL,"Got uc.lpszPassword\n");
+    ok (uc.dwPasswordLength == 0, "Unexpected dwPasswordLength\n");
+    ok (uc.lpszHostName == &url_k2[Len],"Failed to get uc.lpszHostName\n");
+    ok (uc.dwHostNameLength == 14, "Unexpected dwHostNameLength\n");
+    Len += uc.dwHostNameLength;
+    ok (uc.lpszUrlPath == &url_k2[Len],"Failed to get uc.lpszUrlPath\n");
+    ok (uc.dwUrlPathLength == 0, "Unexpected dwUrlPathLength\n");
+    Len += uc.dwUrlPathLength;
+    ok (uc.lpszExtraInfo == &url_k2[Len],"Failed to get uc.lpszExtraInfo\n");
+    ok (uc.dwExtraInfoLength == 0, "Unexpected dwExtraInfoLength\n");
+}
+
 START_TEST(url)
 {
     WinHttpCreateUrl_test();
+    WinHttpCrackUrl_test();
 }
diff --git a/dlls/winhttp/url.c b/dlls/winhttp/url.c
index 7d739d5..ac25f2c 100644
--- a/dlls/winhttp/url.c
+++ b/dlls/winhttp/url.c
@@ -40,8 +40,12 @@ BOOL WINAPI InternetCrackUrlW( LPCWSTR, DWORD, DWORD, LPURL_COMPONENTSW );
 BOOL WINAPI WinHttpCrackUrl( LPCWSTR url, DWORD len, DWORD flags, LPURL_COMPONENTSW components )
 {
     BOOL ret;
+    INT upLen;
+    INT exLen;
 
     TRACE("%s, %d, %x, %p\n", debugstr_w(url), len, flags, components);
+    upLen = components->dwUrlPathLength;
+    exLen = components->dwExtraInfoLength;
 
     if ((ret = InternetCrackUrlW( url, len, flags, components )))
     {
@@ -53,6 +57,14 @@ BOOL WINAPI WinHttpCrackUrl( LPCWSTR url, DWORD len, DWORD flags, LPURL_COMPONEN
             set_last_error( ERROR_WINHTTP_UNRECOGNIZED_SCHEME );
             return FALSE;
         }
+        if (!len)
+            len = lstrlenW(url);
+        /* WinHttpCrackUrl actually returns pointers to the end of the string for components,
+           other than UserName and Password, that are missing */
+        if (upLen && components->lpszUrlPath == NULL)
+            components->lpszUrlPath = (LPWSTR)&url[len];
+        if (exLen && components->lpszExtraInfo == NULL)
+            components->lpszExtraInfo = (LPWSTR)&url[len];
     }
     return ret;
 }




More information about the wine-cvs mailing list