winebrowser: Use IUri API for URL-related logic.
This commit is contained in:
parent
32955de353
commit
dd7c38d044
|
@ -1,7 +1,7 @@
|
||||||
EXTRADEFS = -DWINE_NO_UNICODE_MACROS
|
EXTRADEFS = -DWINE_NO_UNICODE_MACROS
|
||||||
MODULE = winebrowser.exe
|
MODULE = winebrowser.exe
|
||||||
APPMODE = -mwindows -municode
|
APPMODE = -mwindows -municode
|
||||||
IMPORTS = shlwapi user32 advapi32
|
IMPORTS = urlmon oleaut32 user32 advapi32
|
||||||
|
|
||||||
C_SRCS = \
|
C_SRCS = \
|
||||||
main.c
|
main.c
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#define COBJMACROS
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "wine/port.h"
|
#include "wine/port.h"
|
||||||
|
@ -66,15 +67,6 @@ static char *strdup_unixcp( const WCHAR *str )
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static WCHAR *strdupW( const WCHAR *src )
|
|
||||||
{
|
|
||||||
WCHAR *dst;
|
|
||||||
if (!src) return NULL;
|
|
||||||
if ((dst = HeapAlloc( GetProcessHeap(), 0, (strlenW( src ) + 1) * sizeof(WCHAR) )))
|
|
||||||
strcpyW( dst, src );
|
|
||||||
return dst;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* try to launch a unix app from a comma separated string of app names */
|
/* try to launch a unix app from a comma separated string of app names */
|
||||||
static int launch_app( WCHAR *candidates, const WCHAR *argv1 )
|
static int launch_app( WCHAR *candidates, const WCHAR *argv1 )
|
||||||
{
|
{
|
||||||
|
@ -316,6 +308,58 @@ done:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static IUri *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 */
|
||||||
|
wine_get_unix_file_name_ptr = (wine_get_unix_file_name_t)
|
||||||
|
GetProcAddress( GetModuleHandleA( "KERNEL32" ), "wine_get_unix_file_name" );
|
||||||
|
if(!wine_get_unix_file_name_ptr)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
hres = IUri_GetPath(uri, &filename);
|
||||||
|
if(FAILED(hres))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
unixpath = wine_get_unix_file_name_ptr(filename);
|
||||||
|
SysFreeString(filename);
|
||||||
|
if(unixpath && stat(unixpath, &dummy) >= 0) {
|
||||||
|
int len;
|
||||||
|
|
||||||
|
len = MultiByteToWideChar(CP_UNIXCP, 0, unixpath, -1, NULL, 0);
|
||||||
|
new_path = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR));
|
||||||
|
if(new_path)
|
||||||
|
MultiByteToWideChar(CP_UNIXCP, 0, unixpath, -1, new_path, len);
|
||||||
|
HeapFree(GetProcessHeap(), 0, unixpath);
|
||||||
|
}else {
|
||||||
|
WINE_WARN("File %s does not exist\n", wine_dbgstr_a(unixpath));
|
||||||
|
HeapFree(GetProcessHeap(), 0, unixpath);
|
||||||
|
new_path = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* Main entry point. This is a console application so we have a wmain() not a
|
* Main entry point. This is a console application so we have a wmain() not a
|
||||||
* winmain().
|
* winmain().
|
||||||
|
@ -323,11 +367,12 @@ done:
|
||||||
int wmain(int argc, WCHAR *argv[])
|
int wmain(int argc, WCHAR *argv[])
|
||||||
{
|
{
|
||||||
static const WCHAR nohomeW[] = {'-','n','o','h','o','m','e',0};
|
static const WCHAR nohomeW[] = {'-','n','o','h','o','m','e',0};
|
||||||
static const WCHAR mailtoW[] = {'m','a','i','l','t','o',':',0};
|
|
||||||
static const WCHAR fileW[] = {'f','i','l','e',':',0};
|
|
||||||
|
|
||||||
WCHAR *p, *filenameW = NULL, *fileurlW = NULL, *url = argv[1];
|
WCHAR *url = argv[1];
|
||||||
wine_get_unix_file_name_t wine_get_unix_file_name_ptr;
|
BSTR display_uri;
|
||||||
|
DWORD scheme;
|
||||||
|
IUri *uri;
|
||||||
|
HRESULT hres;
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
|
|
||||||
/* DDE used only if -nohome is specified; avoids delay in printing usage info
|
/* DDE used only if -nohome is specified; avoids delay in printing usage info
|
||||||
|
@ -335,103 +380,47 @@ int wmain(int argc, WCHAR *argv[])
|
||||||
if (url && !strcmpiW( url, nohomeW ))
|
if (url && !strcmpiW( url, nohomeW ))
|
||||||
url = argc > 2 ? argv[2] : get_url_from_dde();
|
url = argc > 2 ? argv[2] : get_url_from_dde();
|
||||||
|
|
||||||
if (!url)
|
if (!url) {
|
||||||
{
|
|
||||||
WINE_ERR( "Usage: winebrowser URL\n" );
|
WINE_ERR( "Usage: winebrowser URL\n" );
|
||||||
goto done;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* handle an RFC1738 file URL */
|
hres = CreateUri(url, Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME|Uri_CREATE_FILE_USE_DOS_PATH, 0, &uri);
|
||||||
if (!strncmpiW( url, fileW, 5 ))
|
if(FAILED(hres)) {
|
||||||
{
|
WINE_ERR("Failed to parse URL\n");
|
||||||
DWORD len = strlenW( url ) + 1;
|
ret = open_http_url(url);
|
||||||
|
HeapFree(GetProcessHeap(), 0, ddeString);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
if (UrlUnescapeW( url, NULL, &len, URL_UNESCAPE_INPLACE ) != S_OK)
|
HeapFree(GetProcessHeap(), 0, ddeString);
|
||||||
{
|
IUri_GetScheme(uri, &scheme);
|
||||||
WINE_ERR( "unescaping URL failed: %s\n", wine_dbgstr_w(url) );
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* look for a Windows path after 'file:' */
|
if(scheme == URL_SCHEME_FILE) {
|
||||||
p = url + 5;
|
IUri *file_uri;
|
||||||
while (*p)
|
|
||||||
{
|
|
||||||
if (isalphaW( p[0] ) && (p[1] == ':' || p[1] == '|')) break;
|
|
||||||
p++;
|
|
||||||
}
|
|
||||||
if (!*p)
|
|
||||||
{
|
|
||||||
WINE_ERR( "no valid Windows path in: %s\n", wine_dbgstr_w(url) );
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (p[1] == '|') p[1] = ':';
|
file_uri = convert_file_uri(uri);
|
||||||
url = p;
|
if(file_uri) {
|
||||||
|
IUri_Release(uri);
|
||||||
while (*p)
|
uri = file_uri;
|
||||||
{
|
}else {
|
||||||
if (*p == '/') *p = '\\';
|
WINE_ERR("Failed to convert file URL to unix path\n");
|
||||||
p++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check if the argument is a local file */
|
hres = IUri_GetDisplayUri(uri, &display_uri);
|
||||||
wine_get_unix_file_name_ptr = (wine_get_unix_file_name_t)
|
IUri_Release(uri);
|
||||||
GetProcAddress( GetModuleHandleA( "KERNEL32" ), "wine_get_unix_file_name" );
|
if(FAILED(hres))
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (wine_get_unix_file_name_ptr == NULL)
|
WINE_TRACE("opening %s\n", wine_dbgstr_w(display_uri));
|
||||||
{
|
|
||||||
WINE_ERR( "cannot get the address of 'wine_get_unix_file_name'\n" );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
char *unixpath;
|
|
||||||
WCHAR c = 0;
|
|
||||||
|
|
||||||
if (!(filenameW = strdupW( url ))) goto done;
|
if(scheme == URL_SCHEME_MAILTO)
|
||||||
if ((p = strchrW( filenameW, '?' )) || (p = strchrW( filenameW, '#' )))
|
ret = open_mailto_url(display_uri);
|
||||||
{
|
|
||||||
c = *p;
|
|
||||||
*p = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((unixpath = wine_get_unix_file_name_ptr( filenameW )))
|
|
||||||
{
|
|
||||||
struct stat dummy;
|
|
||||||
if (stat( unixpath, &dummy ) >= 0)
|
|
||||||
{
|
|
||||||
static const WCHAR schemeW[] = {'f','i','l','e',':','/','/',0};
|
|
||||||
int len, len_scheme;
|
|
||||||
|
|
||||||
len = len_scheme = strlenW( schemeW );
|
|
||||||
len += MultiByteToWideChar( CP_UNIXCP, 0, unixpath, -1, NULL, 0 );
|
|
||||||
if (p)
|
|
||||||
{
|
|
||||||
*p = c;
|
|
||||||
len += strlenW( p );
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(fileurlW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) goto done;
|
|
||||||
|
|
||||||
strcpyW( fileurlW, schemeW );
|
|
||||||
MultiByteToWideChar( CP_UNIXCP, 0, unixpath, -1, fileurlW + len_scheme, len - len_scheme );
|
|
||||||
if (p) strcatW( fileurlW, p );
|
|
||||||
|
|
||||||
ret = open_http_url( fileurlW );
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!strncmpiW( url, mailtoW, 7 ))
|
|
||||||
ret = open_mailto_url( url );
|
|
||||||
else
|
else
|
||||||
/* let the browser decide how to handle the given url */
|
/* let the browser decide how to handle the given url */
|
||||||
ret = open_http_url( url );
|
ret = open_http_url(display_uri);
|
||||||
|
|
||||||
done:
|
SysFreeString(display_uri);
|
||||||
HeapFree(GetProcessHeap(), 0, ddeString);
|
|
||||||
HeapFree( GetProcessHeap(), 0, filenameW );
|
|
||||||
HeapFree( GetProcessHeap(), 0, fileurlW );
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue