[3/3] winebrowser: Don't use IUriBuilder with unix file: uri's.

Vincent Povirk madewokherd at gmail.com
Tue Jul 1 15:43:09 CDT 2014


Using IUriBuilder makes me nervous because we're using the
Uri_CREATE_FILE_USE_DOS_PATH flag, meaning the path is supposed to
represent a dos filename. I expect (but have not verified) that native
would therefore encode the path to create a valid file: url.

Changing that setting would of course mean creating a new IUri just to
make the IUriBuilder, and given that we have to do the encoding
anyway, that IUriBuilder isn't really doing anything for us.

I also worry that urlmon, since it's only designed for dos paths, will
do strange things if it gets a unix path. The thing we're building is
simply not a valid url on Windows, and I've already seen that the
escaping rules are different. (Windows leaves non-ascii characters
unescaped, maybe someday Wine's urlmon will have to unescape them.)

So I really think it's best to use urlmon only to find the Windows
path and not rely on it after we've converted that to a Unix path.
-------------- next part --------------
From 809eecd80a2be13f57370c91b93b2b149fc528b2 Mon Sep 17 00:00:00 2001
From: Vincent Povirk <vincent at codeweavers.com>
Date: Tue, 1 Jul 2014 14:09:39 -0500
Subject: [PATCH 3/3] winebrowser: Don't use IUriBuilder with unix file: uri's.

---
 programs/winebrowser/main.c | 39 ++++++++++++---------------------------
 1 file changed, 12 insertions(+), 27 deletions(-)

diff --git a/programs/winebrowser/main.c b/programs/winebrowser/main.c
index db8a35b..ed77b6a 100644
--- a/programs/winebrowser/main.c
+++ b/programs/winebrowser/main.c
@@ -311,11 +311,12 @@ done:
 
 static WCHAR *encode_unix_path(const char *src)
 {
-    int len = 1;
     const char *tmp_src;
     WCHAR *dst, *tmp_dst;
     const char safe_chars[] = "/-_.~@&=+$,:";
     const char hex_digits[] = "0123456789ABCDEF";
+    const WCHAR schema[] = {'f','i','l','e',':','/','/',0};
+    int len = sizeof(schema)/sizeof(schema[0]);
 
     tmp_src = src;
 
@@ -336,8 +337,10 @@ static WCHAR *encode_unix_path(const char *src)
     if (!dst)
         return NULL;
 
+    strcpyW(dst, schema);
+
     tmp_src = src;
-    tmp_dst = dst;
+    tmp_dst = dst + strlenW(dst);
 
     while (*tmp_src != 0)
     {
@@ -362,15 +365,13 @@ static WCHAR *encode_unix_path(const char *src)
     return dst;
 }
 
-static IUri *convert_file_uri(IUri *uri)
+static WCHAR *convert_file_uri(IUri *uri)
 {
     wine_get_unix_file_name_t wine_get_unix_file_name_ptr;
-    IUriBuilder *uri_builder;
     struct stat dummy;
     WCHAR *new_path;
     char *unixpath;
     BSTR filename;
-    IUri *new_uri;
     HRESULT hres;
 
     /* check if the argument is a local file */
@@ -399,19 +400,7 @@ static IUri *convert_file_uri(IUri *uri)
 
     WINE_TRACE("New path: %s\n", wine_dbgstr_w(new_path));
 
-    hres = CreateIUriBuilder(uri, 0, 0, &uri_builder);
-    if(SUCCEEDED(hres) && new_path)
-        hres = IUriBuilder_SetPath(uri_builder, new_path);
-    HeapFree(GetProcessHeap(), 0, new_path);
-    if(FAILED(hres))
-        return NULL;
-
-    hres = IUriBuilder_CreateUri(uri_builder, 0, 0, 0, &new_uri);
-    IUriBuilder_Release(uri_builder);
-    if(FAILED(hres))
-        return NULL;
-
-    return new_uri;
+    return new_path;
 }
 
 /*****************************************************************************
@@ -423,7 +412,7 @@ int wmain(int argc, WCHAR *argv[])
     static const WCHAR nohomeW[] = {'-','n','o','h','o','m','e',0};
 
     WCHAR *url = argv[1];
-    BSTR display_uri;
+    BSTR display_uri = NULL;
     DWORD scheme;
     IUri *uri;
     HRESULT hres;
@@ -451,18 +440,14 @@ int wmain(int argc, WCHAR *argv[])
     IUri_GetScheme(uri, &scheme);
 
     if(scheme == URL_SCHEME_FILE) {
-        IUri *file_uri;
-
-        file_uri = convert_file_uri(uri);
-        if(file_uri) {
-            IUri_Release(uri);
-            uri = file_uri;
-        }else {
+        display_uri = convert_file_uri(uri);
+        if(!display_uri) {
             WINE_ERR("Failed to convert file URL to unix path\n");
         }
     }
 
-    hres = IUri_GetDisplayUri(uri, &display_uri);
+    if (!display_uri)
+        hres = IUri_GetDisplayUri(uri, &display_uri);
     IUri_Release(uri);
     if(FAILED(hres))
         return -1;
-- 
1.8.3.2



More information about the wine-patches mailing list