Robert Shearman : wininet: More InternetCreateUrlW fixes.

Alexandre Julliard julliard at wine.codeweavers.com
Thu Mar 9 16:06:12 CST 2006


Module: wine
Branch: refs/heads/master
Commit: 8eab78c235b10b8b359283e2a34c807823d1627b
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=8eab78c235b10b8b359283e2a34c807823d1627b

Author: Robert Shearman <rob at codeweavers.com>
Date:   Thu Mar  9 15:17:49 2006 +0000

wininet: More InternetCreateUrlW fixes.

- Don't add double slashes for opaque URLs.
- The default port number for all other schemes is 0.

---

 dlls/wininet/internet.c   |   31 +++++++++++++++++++++++++++----
 dlls/wininet/tests/http.c |    2 --
 2 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/dlls/wininet/internet.c b/dlls/wininet/internet.c
index 4a2f001..5beb622 100644
--- a/dlls/wininet/internet.c
+++ b/dlls/wininet/internet.c
@@ -3700,9 +3700,23 @@ static BOOL url_uses_default_port(INTERN
         (nPort == INTERNET_DEFAULT_GOPHER_PORT))
         return TRUE;
 
+    if (nPort == INTERNET_INVALID_PORT_NUMBER)
+        return TRUE;
+
     return FALSE;
 }
 
+/* opaque urls do not fit into the standard url hierarchy and don't have
+ * two following slashes */
+static inline BOOL scheme_is_opaque(INTERNET_SCHEME nScheme)
+{
+    return (nScheme != INTERNET_SCHEME_FTP) &&
+           (nScheme != INTERNET_SCHEME_GOPHER) &&
+           (nScheme != INTERNET_SCHEME_HTTP) &&
+           (nScheme != INTERNET_SCHEME_HTTPS) &&
+           (nScheme != INTERNET_SCHEME_FILE);
+}
+
 static LPCWSTR INTERNET_GetSchemeString(INTERNET_SCHEME scheme)
 {
     int index;
@@ -3742,7 +3756,9 @@ static BOOL calc_url_length(LPURL_COMPON
         *lpdwUrlLength += strlenW(scheme);
     }
 
-    *lpdwUrlLength += strlen("://");
+    (*lpdwUrlLength)++; /* ':' */
+    if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
+        *lpdwUrlLength += strlen("//");
 
     if (lpUrlComponents->lpszUserName)
     {
@@ -3909,7 +3925,7 @@ BOOL WINAPI InternetCreateUrlW(LPURL_COM
     DWORD dwLen;
     INTERNET_SCHEME nScheme;
 
-    static const WCHAR colonSlashW[] = {':','/','/'};
+    static const WCHAR slashSlashW[] = {'/','/'};
     static const WCHAR percentD[] = {'%','d',0};
 
     TRACE("(%p,%ld,%p,%p)\n", lpUrlComponents, dwFlags, lpszUrl, lpdwUrlLength);
@@ -3960,8 +3976,15 @@ BOOL WINAPI InternetCreateUrlW(LPURL_COM
         lpszUrl += dwLen;
     }
 
-    memcpy(lpszUrl, colonSlashW, sizeof(colonSlashW));
-    lpszUrl += sizeof(colonSlashW)/sizeof(colonSlashW[0]);
+    /* all schemes are followed by at least a colon */
+    *lpszUrl = ':';
+    lpszUrl++;
+
+    if (!scheme_is_opaque(nScheme) || lpUrlComponents->lpszHostName)
+    {
+        memcpy(lpszUrl, slashSlashW, sizeof(slashSlashW));
+        lpszUrl += sizeof(slashSlashW)/sizeof(slashSlashW[0]);
+    }
 
     if (lpUrlComponents->lpszUserName)
     {
diff --git a/dlls/wininet/tests/http.c b/dlls/wininet/tests/http.c
index 72ab72c..90a972c 100644
--- a/dlls/wininet/tests/http.c
+++ b/dlls/wininet/tests/http.c
@@ -1111,11 +1111,9 @@ static void InternetCreateUrlA_test(void
 	len = strlen(CREATE_URL9);
 	szUrl = (char *)HeapAlloc(GetProcessHeap(), 0, ++len);
 	ret = InternetCreateUrlA(&urlComp, ICU_ESCAPE, szUrl, &len);
-	todo_wine {
 	ok(ret, "Expected success\n");
 	ok(len == strlen(CREATE_URL9), "Expected len %d, got %ld\n", strlen(CREATE_URL9), len);
 	ok(!strcmp(szUrl, CREATE_URL9), "Expected %s, got %s\n", CREATE_URL9, szUrl);
-	}
 
 	HeapFree(GetProcessHeap(), 0, szUrl);
 }




More information about the wine-cvs mailing list