winebrowser: Convert to Unicode.

This commit is contained in:
Hans Leidekker 2008-04-06 14:44:31 +02:00 committed by Alexandre Julliard
parent 29713df8d9
commit e547cf7043
2 changed files with 102 additions and 62 deletions

View File

@ -3,7 +3,7 @@ TOPOBJDIR = ../..
SRCDIR = @srcdir@ SRCDIR = @srcdir@
VPATH = @srcdir@ VPATH = @srcdir@
MODULE = winebrowser.exe MODULE = winebrowser.exe
APPMODE = -mwindows APPMODE = -mwindows -municode
IMPORTS = shlwapi user32 advapi32 kernel32 IMPORTS = shlwapi user32 advapi32 kernel32
C_SRCS = \ C_SRCS = \

View File

@ -39,6 +39,8 @@
#include "config.h" #include "config.h"
#include "wine/port.h" #include "wine/port.h"
#include "wine/debug.h"
#include "wine/unicode.h"
#include <windows.h> #include <windows.h>
#include <shlwapi.h> #include <shlwapi.h>
@ -46,77 +48,108 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(winebrowser); WINE_DEFAULT_DEBUG_CHANNEL(winebrowser);
typedef LPSTR (*wine_get_unix_file_name_t)(LPCWSTR unixname); typedef LPSTR (*wine_get_unix_file_name_t)(LPCWSTR unixname);
/* try to launch an app from a comma separated string of app names */ static const WCHAR browser_key[] =
static int launch_app( char *candidates, const char *argv1 ) {'S','o','f','t','w','a','r','e','\\','W','i','n','e','\\',
'W','i','n','e','B','r','o','w','s','e','r',0};
static char *strdup_unixcp( const WCHAR *str )
{ {
char *app; char *ret;
int len = WideCharToMultiByte( CP_UNIXCP, 0, str, -1, NULL, 0, NULL, NULL );
if ((ret = HeapAlloc( GetProcessHeap(), 0, len )))
WideCharToMultiByte( CP_UNIXCP, 0, str, -1, ret, len, NULL, NULL );
return ret;
}
/* try to launch a unix app from a comma separated string of app names */
static int launch_app( WCHAR *candidates, const WCHAR *argv1 )
{
char *app, *applist, *cmdline;
const char *argv_new[3]; const char *argv_new[3];
app = strtok( candidates, "," ); if (!(applist = strdup_unixcp( candidates ))) return 1;
if (!(cmdline = strdup_unixcp( argv1 )))
{
HeapFree( GetProcessHeap(), 0, applist );
return 1;
}
app = strtok( applist, "," );
while (app) while (app)
{ {
argv_new[0] = app; WINE_TRACE( "Considering: %s\n", wine_dbgstr_a(app) );
argv_new[1] = argv1; WINE_TRACE( "argv[1]: %s\n", wine_dbgstr_a(cmdline) );
argv_new[2] = NULL;
WINE_TRACE( "Considering: %s\n", app ); argv_new[0] = app;
WINE_TRACE( "argv[1]: %s\n", argv1 ); argv_new[1] = cmdline;
argv_new[2] = NULL;
spawnvp( _P_OVERLAY, app, argv_new ); /* only returns on error */ spawnvp( _P_OVERLAY, app, argv_new ); /* only returns on error */
app = strtok( NULL, "," ); /* grab the next app */ app = strtok( NULL, "," ); /* grab the next app */
} }
fprintf( stderr, "winebrowser: could not find a suitable app to run\n" ); WINE_ERR( "could not find a suitable app to run\n" );
HeapFree( GetProcessHeap(), 0, applist );
HeapFree( GetProcessHeap(), 0, cmdline );
return 1; return 1;
} }
static int open_http_url( const char *url ) static int open_http_url( const WCHAR *url )
{ {
static const char *defaultbrowsers = static const WCHAR defaultbrowsers[] =
"xdg-open,firefox,konqueror,mozilla,netscape,galeon,opera,dillo"; {'x','d','g','-','o','p','e','n',',','f','i','r','e','f','o','x',',',
char browsers[256]; 'k','o','n','q','u','e','r','o','r',',','m','o','z','i','l','l','a',',',
'n','e','t','s','c','a','p','e',',','g','a','l','e','o','n',',',
'o','p','e','r','a',',','d','i','l','l','o',0};
static const WCHAR browsersW[] =
{'B','r','o','w','s','e','r','s',0};
WCHAR browsers[256];
DWORD length, type; DWORD length, type;
HKEY key; HKEY key;
LONG r; LONG r;
length = sizeof(browsers); length = sizeof(browsers);
/* @@ Wine registry key: HKCU\Software\Wine\WineBrowser */ /* @@ Wine registry key: HKCU\Software\Wine\WineBrowser */
if (!(r = RegOpenKey( HKEY_CURRENT_USER, "Software\\Wine\\WineBrowser", &key ))) if (!(r = RegOpenKeyW( HKEY_CURRENT_USER, browser_key, &key )))
{ {
r = RegQueryValueExA( key, "Browsers", 0, &type, (LPBYTE)browsers, &length ); r = RegQueryValueExW( key, browsersW, 0, &type, (LPBYTE)browsers, &length );
RegCloseKey( key ); RegCloseKey( key );
} }
if (r != ERROR_SUCCESS) if (r != ERROR_SUCCESS)
strcpy( browsers, defaultbrowsers ); strcpyW( browsers, defaultbrowsers );
return launch_app( browsers, url ); return launch_app( browsers, url );
} }
static int open_mailto_url( const char *url ) static int open_mailto_url( const WCHAR *url )
{ {
static const char *defaultmailers = static const WCHAR defaultmailers[] =
"xdg-email,mozilla-thunderbird,thunderbird,evolution"; {'x','d','g','-','e','m','a','i','l',',',
char mailers[256]; 'm','o','z','i','l','l','a','-','t','h','u','n','d','e','r','b','i','r','d',',',
't','h','u','n','d','e','r','b','i','r','d',',',
'e','v','o','l','u','t','i','o','n',0};
static const WCHAR mailersW[] =
{'M','a','i','l','e','r','s',0};
WCHAR mailers[256];
DWORD length, type; DWORD length, type;
HKEY key; HKEY key;
LONG r; LONG r;
length = sizeof(mailers); length = sizeof(mailers);
/* @@ Wine registry key: HKCU\Software\Wine\WineBrowser */ /* @@ Wine registry key: HKCU\Software\Wine\WineBrowser */
if (!(r = RegOpenKey( HKEY_CURRENT_USER, "Software\\Wine\\WineBrowser", &key ))) if (!(r = RegOpenKeyW( HKEY_CURRENT_USER, browser_key, &key )))
{ {
r = RegQueryValueExA( key, "Mailers", 0, &type, (LPBYTE)mailers, &length ); r = RegQueryValueExW( key, mailersW, 0, &type, (LPBYTE)mailers, &length );
RegCloseKey( key ); RegCloseKey( key );
} }
if (r != ERROR_SUCCESS) if (r != ERROR_SUCCESS)
strcpy( mailers, defaultmailers ); strcpyW( mailers, defaultmailers );
return launch_app( mailers, url ); return launch_app( mailers, url );
} }
@ -125,7 +158,7 @@ static int open_mailto_url( const char *url )
* DDE helper functions. * DDE helper functions.
*/ */
static char *ddeString = NULL; static WCHAR *ddeString = NULL;
static HSZ hszTopic = 0, hszReturn = 0; static HSZ hszTopic = 0, hszReturn = 0;
static DWORD ddeInst = 0; static DWORD ddeInst = 0;
@ -158,12 +191,12 @@ static HDDEDATA CALLBACK ddeCb(UINT uType, UINT uFmt, HCONV hConv,
case XTYP_REQUEST: case XTYP_REQUEST:
ret = -3; /* error */ ret = -3; /* error */
if (!(size = DdeQueryString(ddeInst, hsz2, NULL, 0, CP_WINANSI))) if (!(size = DdeQueryStringW(ddeInst, hsz2, NULL, 0, CP_WINUNICODE)))
WINE_ERR("DdeQueryString returned zero size of request string\n"); WINE_ERR("DdeQueryString returned zero size of request string\n");
else if (!(ddeString = HeapAlloc(GetProcessHeap(), 0, size+1))) else if (!(ddeString = HeapAlloc(GetProcessHeap(), 0, (size + 1) * sizeof(WCHAR))))
WINE_ERR("Out of memory\n"); WINE_ERR("Out of memory\n");
else if (DdeQueryString(ddeInst, hsz2, ddeString, size+1, CP_WINANSI) != size) else if (DdeQueryStringW(ddeInst, hsz2, ddeString, size + 1, CP_WINUNICODE) != size)
WINE_WARN("DdeQueryString did not return %d bytes\n", size); WINE_WARN("DdeQueryString did not return %d characters\n", size);
else else
ret = -2; /* acknowledgment */ ret = -2; /* acknowledgment */
return DdeCreateDataHandle(ddeInst, (LPBYTE)&ret, sizeof(ret), 0, return DdeCreateDataHandle(ddeInst, (LPBYTE)&ret, sizeof(ret), 0,
@ -174,40 +207,39 @@ static HDDEDATA CALLBACK ddeCb(UINT uType, UINT uFmt, HCONV hConv,
} }
} }
static char *get_url_from_dde(void) static WCHAR *get_url_from_dde(void)
{ {
static const char szApplication[] = "IExplore"; static const WCHAR szApplication[] = {'I','E','x','p','l','o','r','e',0};
static const char szTopic[] = "WWW_OpenURL"; static const WCHAR szTopic[] = {'W','W','W','_','O','p','e','n','U','R','L',0};
static const char szReturn[] = "Return"; static const WCHAR szReturn[] = {'R','e','t','u','r','n',0};
HSZ hszApplication = 0; HSZ hszApplication = 0;
UINT_PTR timer = 0; UINT_PTR timer = 0;
int rc; int rc;
char *ret = NULL; WCHAR *ret = NULL;
rc = DdeInitializeA(&ddeInst, ddeCb, CBF_SKIP_ALLNOTIFICATIONS | CBF_FAIL_ADVISES | rc = DdeInitializeW(&ddeInst, ddeCb, CBF_SKIP_ALLNOTIFICATIONS | CBF_FAIL_ADVISES | CBF_FAIL_POKES, 0);
CBF_FAIL_POKES, 0);
if (rc != DMLERR_NO_ERROR) if (rc != DMLERR_NO_ERROR)
{ {
WINE_ERR("Unable to initialize DDE, DdeInitialize returned %d\n", rc); WINE_ERR("Unable to initialize DDE, DdeInitialize returned %d\n", rc);
goto done; goto done;
} }
hszApplication = DdeCreateStringHandleA(ddeInst, szApplication, CP_WINANSI); hszApplication = DdeCreateStringHandleW(ddeInst, szApplication, CP_WINUNICODE);
if (!hszApplication) if (!hszApplication)
{ {
WINE_ERR("Unable to initialize DDE, DdeCreateStringHandle failed\n"); WINE_ERR("Unable to initialize DDE, DdeCreateStringHandle failed\n");
goto done; goto done;
} }
hszTopic = DdeCreateStringHandleA(ddeInst, szTopic, CP_WINANSI); hszTopic = DdeCreateStringHandleW(ddeInst, szTopic, CP_WINUNICODE);
if (!hszTopic) if (!hszTopic)
{ {
WINE_ERR("Unable to initialize DDE, DdeCreateStringHandle failed\n"); WINE_ERR("Unable to initialize DDE, DdeCreateStringHandle failed\n");
goto done; goto done;
} }
hszReturn = DdeCreateStringHandleA(ddeInst, szReturn, CP_WINANSI); hszReturn = DdeCreateStringHandleW(ddeInst, szReturn, CP_WINUNICODE);
if (!hszReturn) if (!hszReturn)
{ {
WINE_ERR("Unable to initialize DDE, DdeCreateStringHandle failed\n"); WINE_ERR("Unable to initialize DDE, DdeCreateStringHandle failed\n");
@ -239,10 +271,10 @@ static char *get_url_from_dde(void)
{ {
if (*ddeString == '"') if (*ddeString == '"')
{ {
char *endquote = strchr(ddeString+1, '"'); WCHAR *endquote = strchrW(ddeString + 1, '"');
if (!endquote) if (!endquote)
{ {
WINE_ERR("Unabled to retrieve URL from string '%s'\n", ddeString); WINE_ERR("Unabled to retrieve URL from string %s\n", wine_dbgstr_w(ddeString));
goto done; goto done;
} }
*endquote = 0; *endquote = 0;
@ -266,35 +298,39 @@ done:
} }
/***************************************************************************** /*****************************************************************************
* Main entry point. This is a console application so we have a main() not a * Main entry point. This is a console application so we have a wmain() not a
* winmain(). * winmain().
*/ */
int main(int argc, char *argv[]) int wmain(int argc, WCHAR *argv[])
{ {
char *url = argv[1]; 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 *url = argv[1];
wine_get_unix_file_name_t wine_get_unix_file_name_ptr; wine_get_unix_file_name_t wine_get_unix_file_name_ptr;
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
* when no parameters are passed */ * when no parameters are passed */
if (url && !strcasecmp( url, "-nohome" )) 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)
{ {
fprintf( stderr, "Usage: winebrowser URL\n" ); WINE_ERR( "Usage: winebrowser URL\n" );
goto done; goto done;
} }
/* handle an RFC1738 file URL */ /* handle an RFC1738 file URL */
if (!strncasecmp( url, "file:", 5 )) if (!strncmpiW( url, fileW, 5 ))
{ {
char *p; WCHAR *p;
DWORD len = lstrlenA( url ) + 1; DWORD len = strlenW( url ) + 1;
if (UrlUnescapeA( url, NULL, &len, URL_UNESCAPE_INPLACE ) != S_OK) if (UrlUnescapeW( url, NULL, &len, URL_UNESCAPE_INPLACE ) != S_OK)
{ {
fprintf( stderr, "winebrowser: unescaping URL failed: %s\n", url ); WINE_ERR( "unescaping URL failed: %s\n", wine_dbgstr_w(url) );
goto done; goto done;
} }
@ -302,12 +338,12 @@ int main(int argc, char *argv[])
p = url + 5; p = url + 5;
while (*p) while (*p)
{ {
if (isalpha( p[0] ) && (p[1] == ':' || p[1] == '|')) break; if (isalphaW( p[0] ) && (p[1] == ':' || p[1] == '|')) break;
p++; p++;
} }
if (!*p) if (!*p)
{ {
fprintf( stderr, "winebrowser: no valid Windows path in: %s\n", url ); WINE_ERR( "no valid Windows path in: %s\n", wine_dbgstr_w(url) );
goto done; goto done;
} }
@ -332,22 +368,26 @@ int main(int argc, char *argv[])
else else
{ {
char *unixpath; char *unixpath;
WCHAR unixpathW[MAX_PATH]; if ((unixpath = wine_get_unix_file_name_ptr( url )))
MultiByteToWideChar( CP_UNIXCP, 0, url, -1, unixpathW, MAX_PATH );
if ((unixpath = wine_get_unix_file_name_ptr( unixpathW )))
{ {
struct stat dummy; struct stat dummy;
if (stat( unixpath, &dummy ) >= 0) if (stat( unixpath, &dummy ) >= 0)
{ {
ret = open_http_url( unixpath ); int len;
WCHAR *unixpathW;
len = MultiByteToWideChar( CP_UNIXCP, 0, unixpath, -1, NULL, 0 );
if ((unixpathW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
MultiByteToWideChar( CP_UNIXCP, 0, unixpath, -1, unixpathW, len );
ret = open_http_url( unixpathW );
HeapFree( GetProcessHeap(), 0, unixpathW );
goto done; goto done;
} }
} }
} }
if (!strncasecmp( url, "mailto:", 7 )) if (!strncmpiW( url, mailtoW, 7 ))
ret = open_mailto_url( url ); 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 */