2004-01-06 21:49:58 +01:00
|
|
|
/*
|
2005-11-24 19:27:41 +01:00
|
|
|
* winebrowser - winelib app to launch native OS browser or mail client.
|
2004-01-06 21:49:58 +01:00
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Chris Morgan
|
2005-11-24 19:27:41 +01:00
|
|
|
* Copyright (C) 2005 Hans Leidekker
|
2004-01-06 21:49:58 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-01-06 21:49:58 +01:00
|
|
|
*
|
|
|
|
* NOTES:
|
|
|
|
* Winebrowser is a winelib application that will start the appropriate
|
2005-11-24 19:27:41 +01:00
|
|
|
* native browser or mail client for a wine installation that lacks a
|
|
|
|
* windows browser/mail client. For example, you will be able to open
|
2011-07-27 11:46:59 +02:00
|
|
|
* URLs via native mozilla if no browser has yet been installed in wine.
|
2005-11-24 19:27:41 +01:00
|
|
|
*
|
|
|
|
* The application to launch is chosen from a default set or, if set,
|
|
|
|
* taken from a registry key.
|
|
|
|
*
|
2006-02-18 15:50:06 +01:00
|
|
|
* The argument may be a regular Windows file name, a file URL, an
|
2006-07-27 18:08:23 +02:00
|
|
|
* URL or a mailto URL. In the first three cases the argument
|
2006-02-18 15:50:06 +01:00
|
|
|
* will be fed to a web browser. In the last case the argument is fed
|
|
|
|
* to a mail client. A mailto URL is composed as follows:
|
2005-11-24 19:27:41 +01:00
|
|
|
*
|
|
|
|
* mailto:[E-MAIL]?subject=[TOPIC]&cc=[E-MAIL]&bcc=[E-MAIL]&body=[TEXT]
|
2004-01-06 21:49:58 +01:00
|
|
|
*/
|
|
|
|
|
2006-01-18 14:23:11 +01:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
2011-12-08 16:36:33 +01:00
|
|
|
#define COBJMACROS
|
2021-09-27 12:33:09 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2006-01-18 14:23:11 +01:00
|
|
|
|
2021-09-27 12:33:09 +02:00
|
|
|
#include <ntstatus.h>
|
|
|
|
#define WIN32_NO_STATUS
|
2004-01-06 21:49:58 +01:00
|
|
|
#include <windows.h>
|
2021-09-27 12:33:09 +02:00
|
|
|
#include <winternl.h>
|
2006-02-18 15:50:06 +01:00
|
|
|
#include <shlwapi.h>
|
2016-05-28 07:53:00 +02:00
|
|
|
#include <shellapi.h>
|
2012-01-23 12:16:36 +01:00
|
|
|
#include <urlmon.h>
|
2007-06-07 17:33:35 +02:00
|
|
|
#include <ddeml.h>
|
2004-01-06 21:49:58 +01:00
|
|
|
|
2021-09-27 12:33:09 +02:00
|
|
|
#include "wine/debug.h"
|
2005-11-24 19:27:41 +01:00
|
|
|
|
2021-09-27 12:33:09 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(winebrowser);
|
2008-04-06 14:44:31 +02:00
|
|
|
|
|
|
|
static char *strdup_unixcp( const WCHAR *str )
|
|
|
|
{
|
|
|
|
char *ret;
|
|
|
|
int len = WideCharToMultiByte( CP_UNIXCP, 0, str, -1, NULL, 0, NULL, NULL );
|
2021-09-27 12:33:09 +02:00
|
|
|
if ((ret = malloc( len )))
|
2008-04-06 14:44:31 +02:00
|
|
|
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 */
|
2016-05-28 07:42:36 +02:00
|
|
|
static int launch_app( const WCHAR *candidates, const WCHAR *argv1 )
|
2005-11-24 19:27:41 +01:00
|
|
|
{
|
2016-05-28 07:53:00 +02:00
|
|
|
char *cmdline;
|
|
|
|
int i, count;
|
|
|
|
char **argv_new;
|
2005-11-24 19:27:41 +01:00
|
|
|
|
2016-05-28 07:42:36 +02:00
|
|
|
if (!(cmdline = strdup_unixcp( argv1 ))) return 1;
|
|
|
|
|
|
|
|
while (*candidates)
|
2005-11-24 19:27:41 +01:00
|
|
|
{
|
2016-05-28 07:53:00 +02:00
|
|
|
WCHAR **args = CommandLineToArgvW( candidates, &count );
|
2016-05-28 07:42:36 +02:00
|
|
|
|
2021-09-27 12:33:09 +02:00
|
|
|
if (!(argv_new = malloc( (count + 2) * sizeof(*argv_new) ))) break;
|
2016-05-28 07:53:00 +02:00
|
|
|
for (i = 0; i < count; i++) argv_new[i] = strdup_unixcp( args[i] );
|
|
|
|
argv_new[count] = cmdline;
|
|
|
|
argv_new[count + 1] = NULL;
|
2008-04-06 14:44:31 +02:00
|
|
|
|
2016-05-28 07:53:00 +02:00
|
|
|
TRACE( "Trying" );
|
|
|
|
for (i = 0; i <= count; i++) TRACE( " %s", wine_dbgstr_a( argv_new[i] ));
|
|
|
|
TRACE( "\n" );
|
2005-11-24 19:27:41 +01:00
|
|
|
|
2021-09-27 12:33:09 +02:00
|
|
|
if (!__wine_unix_spawnvp( argv_new, FALSE )) ExitProcess(0);
|
|
|
|
for (i = 0; i < count; i++) free( argv_new[i] );
|
|
|
|
free( argv_new );
|
|
|
|
candidates += lstrlenW( candidates ) + 1; /* grab the next app */
|
2005-11-24 19:27:41 +01:00
|
|
|
}
|
2016-05-28 07:53:00 +02:00
|
|
|
WINE_ERR( "could not find a suitable app to open %s\n", debugstr_w( argv1 ));
|
2008-04-06 14:44:31 +02:00
|
|
|
|
2021-09-27 12:33:09 +02:00
|
|
|
free( cmdline );
|
2005-11-24 19:27:41 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-05-28 07:42:36 +02:00
|
|
|
static LSTATUS get_commands( HKEY key, const WCHAR *value, WCHAR *buffer, DWORD size )
|
|
|
|
{
|
|
|
|
DWORD type;
|
|
|
|
LSTATUS res;
|
|
|
|
|
|
|
|
size -= sizeof(WCHAR);
|
|
|
|
if (!(res = RegQueryValueExW( key, value, 0, &type, (LPBYTE)buffer, &size )) && (type == REG_SZ))
|
|
|
|
{
|
|
|
|
/* convert to REG_MULTI_SZ type */
|
|
|
|
WCHAR *p = buffer;
|
2021-09-27 12:33:09 +02:00
|
|
|
p[lstrlenW(p) + 1] = 0;
|
|
|
|
while ((p = wcschr( p, ',' ))) *p++ = 0;
|
2016-05-28 07:42:36 +02:00
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2008-04-06 14:44:31 +02:00
|
|
|
static int open_http_url( const WCHAR *url )
|
2005-11-24 19:27:41 +01:00
|
|
|
{
|
2008-04-06 14:44:31 +02:00
|
|
|
static const WCHAR defaultbrowsers[] =
|
2021-12-14 21:28:58 +01:00
|
|
|
L"xdg-open\0"
|
|
|
|
"/usr/bin/open\0"
|
2021-09-27 12:33:09 +02:00
|
|
|
"firefox\0"
|
|
|
|
"konqueror\0"
|
|
|
|
"mozilla\0"
|
|
|
|
"opera\0"
|
|
|
|
"dillo\0";
|
2008-04-06 14:44:31 +02:00
|
|
|
WCHAR browsers[256];
|
2005-11-24 19:27:41 +01:00
|
|
|
HKEY key;
|
|
|
|
LONG r;
|
|
|
|
|
|
|
|
/* @@ Wine registry key: HKCU\Software\Wine\WineBrowser */
|
2021-09-27 12:33:09 +02:00
|
|
|
if (!(r = RegOpenKeyW( HKEY_CURRENT_USER, L"Software\\Wine\\WineBrowser", &key )))
|
2005-11-24 19:27:41 +01:00
|
|
|
{
|
2021-09-27 12:33:09 +02:00
|
|
|
r = get_commands( key, L"Browsers", browsers, sizeof(browsers) );
|
2007-04-27 19:26:21 +02:00
|
|
|
RegCloseKey( key );
|
2005-11-24 19:27:41 +01:00
|
|
|
}
|
|
|
|
if (r != ERROR_SUCCESS)
|
2016-05-28 07:42:36 +02:00
|
|
|
memcpy( browsers, defaultbrowsers, sizeof(defaultbrowsers) );
|
2005-11-24 19:27:41 +01:00
|
|
|
|
|
|
|
return launch_app( browsers, url );
|
|
|
|
}
|
|
|
|
|
2008-04-06 14:44:31 +02:00
|
|
|
static int open_mailto_url( const WCHAR *url )
|
2005-11-24 19:27:41 +01:00
|
|
|
{
|
2008-05-21 17:32:07 +02:00
|
|
|
static const WCHAR defaultmailers[] =
|
2021-09-27 12:33:09 +02:00
|
|
|
L"/usr/bin/open\0"
|
|
|
|
"xdg-email\0"
|
|
|
|
"mozilla-thunderbird\0"
|
|
|
|
"thunderbird\0"
|
|
|
|
"evolution\0";
|
2008-04-06 14:44:31 +02:00
|
|
|
WCHAR mailers[256];
|
2005-11-24 19:27:41 +01:00
|
|
|
HKEY key;
|
|
|
|
LONG r;
|
|
|
|
|
|
|
|
/* @@ Wine registry key: HKCU\Software\Wine\WineBrowser */
|
2021-09-27 12:33:09 +02:00
|
|
|
if (!(r = RegOpenKeyW( HKEY_CURRENT_USER, L"Software\\Wine\\WineBrowser", &key )))
|
2005-11-24 19:27:41 +01:00
|
|
|
{
|
2021-09-27 12:33:09 +02:00
|
|
|
r = get_commands( key, L"Mailers", mailers, sizeof(mailers) );
|
2007-04-27 19:26:21 +02:00
|
|
|
RegCloseKey( key );
|
2005-11-24 19:27:41 +01:00
|
|
|
}
|
|
|
|
if (r != ERROR_SUCCESS)
|
2016-05-28 07:42:36 +02:00
|
|
|
memcpy( mailers, defaultmailers, sizeof(defaultmailers) );
|
2005-11-24 19:27:41 +01:00
|
|
|
|
|
|
|
return launch_app( mailers, url );
|
|
|
|
}
|
2005-01-10 17:08:08 +01:00
|
|
|
|
2020-11-25 00:16:39 +01:00
|
|
|
static int open_invalid_url( const WCHAR *url )
|
|
|
|
{
|
|
|
|
WCHAR *url_prefixed;
|
|
|
|
int ret;
|
|
|
|
|
2021-09-27 12:33:09 +02:00
|
|
|
url_prefixed = malloc( (ARRAY_SIZE(L"http://") + lstrlenW( url )) * sizeof(WCHAR) );
|
2020-11-25 00:16:39 +01:00
|
|
|
if (!url_prefixed)
|
|
|
|
{
|
|
|
|
WINE_ERR("Out of memory\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-09-27 12:33:09 +02:00
|
|
|
lstrcpyW( url_prefixed, L"http://" );
|
|
|
|
lstrcatW( url_prefixed, url );
|
2020-11-25 00:16:39 +01:00
|
|
|
|
|
|
|
ret = open_http_url( url_prefixed );
|
2021-09-27 12:33:09 +02:00
|
|
|
free( url_prefixed );
|
2020-11-25 00:16:39 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-06-07 17:33:35 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
* DDE helper functions.
|
|
|
|
*/
|
|
|
|
|
2008-04-06 14:44:31 +02:00
|
|
|
static WCHAR *ddeString = NULL;
|
2007-08-13 03:08:01 +02:00
|
|
|
static HSZ hszTopic = 0, hszReturn = 0;
|
|
|
|
static DWORD ddeInst = 0;
|
2007-06-07 17:33:35 +02:00
|
|
|
|
2007-08-13 03:08:01 +02:00
|
|
|
/* Dde callback, save the execute or request string for processing */
|
2007-06-07 17:33:35 +02:00
|
|
|
static HDDEDATA CALLBACK ddeCb(UINT uType, UINT uFmt, HCONV hConv,
|
|
|
|
HSZ hsz1, HSZ hsz2, HDDEDATA hData,
|
|
|
|
ULONG_PTR dwData1, ULONG_PTR dwData2)
|
|
|
|
{
|
2007-08-13 03:08:01 +02:00
|
|
|
DWORD size = 0, ret = 0;
|
2007-06-07 17:33:35 +02:00
|
|
|
|
2022-02-07 08:40:31 +01:00
|
|
|
WINE_TRACE("dde_cb: %04x, %04x, %p, %p, %p, %p, %08Ix, %08Ix\n",
|
2007-06-07 17:33:35 +02:00
|
|
|
uType, uFmt, hConv, hsz1, hsz2, hData, dwData1, dwData2);
|
|
|
|
|
|
|
|
switch (uType)
|
|
|
|
{
|
|
|
|
case XTYP_CONNECT:
|
|
|
|
if (!DdeCmpStringHandles(hsz1, hszTopic))
|
|
|
|
return (HDDEDATA)TRUE;
|
|
|
|
return (HDDEDATA)FALSE;
|
|
|
|
|
|
|
|
case XTYP_EXECUTE:
|
|
|
|
if (!(size = DdeGetData(hData, NULL, 0, 0)))
|
|
|
|
WINE_ERR("DdeGetData returned zero size of execute string\n");
|
2021-09-27 12:33:09 +02:00
|
|
|
else if (!(ddeString = malloc(size)))
|
2007-06-07 17:33:35 +02:00
|
|
|
WINE_ERR("Out of memory\n");
|
2010-06-24 23:42:41 +02:00
|
|
|
else if (DdeGetData(hData, (LPBYTE)ddeString, size, 0) != size)
|
2022-02-07 08:40:31 +01:00
|
|
|
WINE_WARN("DdeGetData did not return %ld bytes\n", size);
|
2007-06-07 17:33:35 +02:00
|
|
|
DdeFreeDataHandle(hData);
|
|
|
|
return (HDDEDATA)DDE_FACK;
|
2010-06-24 23:42:41 +02:00
|
|
|
|
2007-08-13 03:08:01 +02:00
|
|
|
case XTYP_REQUEST:
|
|
|
|
ret = -3; /* error */
|
2008-04-06 14:44:31 +02:00
|
|
|
if (!(size = DdeQueryStringW(ddeInst, hsz2, NULL, 0, CP_WINUNICODE)))
|
2007-08-13 03:08:01 +02:00
|
|
|
WINE_ERR("DdeQueryString returned zero size of request string\n");
|
2021-09-27 12:33:09 +02:00
|
|
|
else if (!(ddeString = malloc( (size + 1) * sizeof(WCHAR))))
|
2007-08-13 03:08:01 +02:00
|
|
|
WINE_ERR("Out of memory\n");
|
2008-04-06 14:44:31 +02:00
|
|
|
else if (DdeQueryStringW(ddeInst, hsz2, ddeString, size + 1, CP_WINUNICODE) != size)
|
2022-02-07 08:40:31 +01:00
|
|
|
WINE_WARN("DdeQueryString did not return %ld characters\n", size);
|
2007-08-13 03:08:01 +02:00
|
|
|
else
|
|
|
|
ret = -2; /* acknowledgment */
|
|
|
|
return DdeCreateDataHandle(ddeInst, (LPBYTE)&ret, sizeof(ret), 0,
|
|
|
|
hszReturn, CF_TEXT, 0);
|
|
|
|
|
2007-06-07 17:33:35 +02:00
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-06 14:44:31 +02:00
|
|
|
static WCHAR *get_url_from_dde(void)
|
2007-06-07 17:33:35 +02:00
|
|
|
{
|
|
|
|
HSZ hszApplication = 0;
|
|
|
|
UINT_PTR timer = 0;
|
|
|
|
int rc;
|
2008-04-06 14:44:31 +02:00
|
|
|
WCHAR *ret = NULL;
|
2007-06-07 17:33:35 +02:00
|
|
|
|
2008-04-06 14:44:31 +02:00
|
|
|
rc = DdeInitializeW(&ddeInst, ddeCb, CBF_SKIP_ALLNOTIFICATIONS | CBF_FAIL_ADVISES | CBF_FAIL_POKES, 0);
|
2007-06-07 17:33:35 +02:00
|
|
|
if (rc != DMLERR_NO_ERROR)
|
|
|
|
{
|
|
|
|
WINE_ERR("Unable to initialize DDE, DdeInitialize returned %d\n", rc);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2021-09-27 12:33:09 +02:00
|
|
|
hszApplication = DdeCreateStringHandleW(ddeInst, L"IExplore", CP_WINUNICODE);
|
2007-06-07 17:33:35 +02:00
|
|
|
if (!hszApplication)
|
|
|
|
{
|
|
|
|
WINE_ERR("Unable to initialize DDE, DdeCreateStringHandle failed\n");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2021-09-27 12:33:09 +02:00
|
|
|
hszTopic = DdeCreateStringHandleW(ddeInst, L"WWW_OpenURL", CP_WINUNICODE);
|
2007-06-07 17:33:35 +02:00
|
|
|
if (!hszTopic)
|
|
|
|
{
|
|
|
|
WINE_ERR("Unable to initialize DDE, DdeCreateStringHandle failed\n");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2021-09-27 12:33:09 +02:00
|
|
|
hszReturn = DdeCreateStringHandleW(ddeInst, L"Return", CP_WINUNICODE);
|
2007-08-13 03:08:01 +02:00
|
|
|
if (!hszReturn)
|
|
|
|
{
|
|
|
|
WINE_ERR("Unable to initialize DDE, DdeCreateStringHandle failed\n");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2007-06-07 17:33:35 +02:00
|
|
|
if (!DdeNameService(ddeInst, hszApplication, 0, DNS_REGISTER))
|
|
|
|
{
|
|
|
|
WINE_ERR("Unable to initialize DDE, DdeNameService failed\n");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
timer = SetTimer(NULL, 0, 5000, NULL);
|
|
|
|
if (!timer)
|
|
|
|
{
|
|
|
|
WINE_ERR("SetTimer failed to create timer\n");
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2007-08-13 03:08:01 +02:00
|
|
|
while (!ddeString)
|
2007-06-07 17:33:35 +02:00
|
|
|
{
|
|
|
|
MSG msg;
|
2008-09-03 11:30:44 +02:00
|
|
|
if (!GetMessageW(&msg, NULL, 0, 0)) break;
|
2007-06-07 17:33:35 +02:00
|
|
|
if (msg.message == WM_TIMER) break;
|
2008-09-03 11:30:44 +02:00
|
|
|
DispatchMessageW(&msg);
|
2007-06-07 17:33:35 +02:00
|
|
|
}
|
|
|
|
|
2007-08-13 03:08:01 +02:00
|
|
|
if (ddeString)
|
2007-06-07 17:33:35 +02:00
|
|
|
{
|
2007-08-13 03:08:01 +02:00
|
|
|
if (*ddeString == '"')
|
2007-06-07 17:33:35 +02:00
|
|
|
{
|
2021-09-27 12:33:09 +02:00
|
|
|
WCHAR *endquote = wcschr(ddeString + 1, '"');
|
2007-06-07 17:33:35 +02:00
|
|
|
if (!endquote)
|
|
|
|
{
|
2009-01-10 23:12:20 +01:00
|
|
|
WINE_ERR("Unable to retrieve URL from string %s\n", wine_dbgstr_w(ddeString));
|
2007-06-07 17:33:35 +02:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
*endquote = 0;
|
2007-08-13 03:08:01 +02:00
|
|
|
ret = ddeString+1;
|
2007-06-07 17:33:35 +02:00
|
|
|
}
|
|
|
|
else
|
2007-08-13 03:08:01 +02:00
|
|
|
ret = ddeString;
|
2007-06-07 17:33:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (timer) KillTimer(NULL, timer);
|
|
|
|
if (ddeInst)
|
|
|
|
{
|
|
|
|
if (hszTopic && hszApplication) DdeNameService(ddeInst, hszApplication, 0, DNS_UNREGISTER);
|
2007-08-13 03:08:01 +02:00
|
|
|
if (hszReturn) DdeFreeStringHandle(ddeInst, hszReturn);
|
2007-06-07 17:33:35 +02:00
|
|
|
if (hszTopic) DdeFreeStringHandle(ddeInst, hszTopic);
|
|
|
|
if (hszApplication) DdeFreeStringHandle(ddeInst, hszApplication);
|
|
|
|
DdeUninitialize(ddeInst);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-06-27 22:44:32 +02:00
|
|
|
static WCHAR *encode_unix_path(const char *src)
|
|
|
|
{
|
|
|
|
WCHAR *dst, *tmp_dst;
|
2021-09-27 12:33:09 +02:00
|
|
|
static const char safe_chars[] = "/-_.~@&=+$,:";
|
|
|
|
static const char hex_digits[] = "0123456789ABCDEF";
|
2014-06-27 22:44:32 +02:00
|
|
|
|
2021-09-27 12:33:09 +02:00
|
|
|
dst = malloc( sizeof(L"file://") + 3 * strlen(src) * sizeof(WCHAR) );
|
|
|
|
lstrcpyW(dst, L"file://");
|
2014-06-27 22:44:32 +02:00
|
|
|
|
2021-09-27 12:33:09 +02:00
|
|
|
tmp_dst = dst + lstrlenW(dst);
|
2014-07-01 21:09:39 +02:00
|
|
|
|
2021-09-27 12:33:09 +02:00
|
|
|
while (*src != 0)
|
2014-06-27 22:44:32 +02:00
|
|
|
{
|
2021-09-27 12:33:09 +02:00
|
|
|
if ((*src >= 'a' && *src <= 'z') ||
|
|
|
|
(*src >= 'A' && *src <= 'Z') ||
|
|
|
|
(*src >= '0' && *src <= '9') ||
|
|
|
|
strchr(safe_chars, *src))
|
2014-06-27 22:44:32 +02:00
|
|
|
{
|
2021-09-27 12:33:09 +02:00
|
|
|
*tmp_dst++ = *src;
|
2014-06-27 22:44:32 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*tmp_dst++ = '%';
|
2021-09-27 12:33:09 +02:00
|
|
|
*tmp_dst++ = hex_digits[*(unsigned char*)src / 16];
|
|
|
|
*tmp_dst++ = hex_digits[*src & 0xf];
|
2014-06-27 22:44:32 +02:00
|
|
|
}
|
2021-09-27 12:33:09 +02:00
|
|
|
src++;
|
2014-06-27 22:44:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
*tmp_dst = 0;
|
|
|
|
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2014-07-01 21:09:39 +02:00
|
|
|
static WCHAR *convert_file_uri(IUri *uri)
|
2011-12-08 16:36:33 +01:00
|
|
|
{
|
2021-09-27 12:33:09 +02:00
|
|
|
UNICODE_STRING nt_name;
|
|
|
|
OBJECT_ATTRIBUTES attr;
|
|
|
|
NTSTATUS status;
|
|
|
|
ULONG size = 256;
|
|
|
|
char *buffer;
|
|
|
|
WCHAR *new_path = NULL;
|
2011-12-08 16:36:33 +01:00
|
|
|
BSTR filename;
|
|
|
|
HRESULT hres;
|
|
|
|
|
|
|
|
hres = IUri_GetPath(uri, &filename);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return NULL;
|
|
|
|
|
2014-07-01 18:37:39 +02:00
|
|
|
WINE_TRACE("Windows path: %s\n", wine_dbgstr_w(filename));
|
|
|
|
|
2021-09-27 12:33:09 +02:00
|
|
|
if (!RtlDosPathNameToNtPathName_U( filename, &nt_name, NULL, NULL )) return NULL;
|
|
|
|
InitializeObjectAttributes( &attr, &nt_name, 0, 0, NULL );
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
if (!(buffer = malloc( size )))
|
|
|
|
{
|
|
|
|
RtlFreeUnicodeString( &nt_name );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
status = wine_nt_to_unix_file_name( &attr, buffer, &size, FILE_OPEN );
|
|
|
|
if (status != STATUS_BUFFER_TOO_SMALL) break;
|
|
|
|
free( buffer );
|
2011-12-08 16:36:33 +01:00
|
|
|
}
|
|
|
|
|
2021-09-27 12:33:09 +02:00
|
|
|
if (!status) new_path = encode_unix_path( buffer );
|
|
|
|
SysFreeString(filename);
|
|
|
|
free( buffer );
|
|
|
|
|
2014-07-01 18:37:39 +02:00
|
|
|
WINE_TRACE("New path: %s\n", wine_dbgstr_w(new_path));
|
|
|
|
|
2014-07-01 21:09:39 +02:00
|
|
|
return new_path;
|
2011-12-08 16:36:33 +01:00
|
|
|
}
|
|
|
|
|
2004-01-06 21:49:58 +01:00
|
|
|
/*****************************************************************************
|
2008-04-06 14:44:31 +02:00
|
|
|
* Main entry point. This is a console application so we have a wmain() not a
|
2004-01-06 21:49:58 +01:00
|
|
|
* winmain().
|
|
|
|
*/
|
2020-12-04 10:31:11 +01:00
|
|
|
int wmain(int argc, WCHAR *argv[])
|
2004-01-06 21:49:58 +01:00
|
|
|
{
|
2011-12-08 16:36:33 +01:00
|
|
|
WCHAR *url = argv[1];
|
2014-07-01 21:09:39 +02:00
|
|
|
BSTR display_uri = NULL;
|
2011-12-08 16:36:33 +01:00
|
|
|
DWORD scheme;
|
|
|
|
IUri *uri;
|
|
|
|
HRESULT hres;
|
2005-11-24 19:27:41 +01:00
|
|
|
|
2007-06-07 17:33:35 +02:00
|
|
|
/* DDE used only if -nohome is specified; avoids delay in printing usage info
|
|
|
|
* when no parameters are passed */
|
2021-09-27 12:33:09 +02:00
|
|
|
if (url && !wcsicmp( url, L"-nohome" ))
|
2007-06-07 17:33:35 +02:00
|
|
|
url = argc > 2 ? argv[2] : get_url_from_dde();
|
|
|
|
|
2011-12-08 16:36:33 +01:00
|
|
|
if (!url) {
|
2008-04-06 14:44:31 +02:00
|
|
|
WINE_ERR( "Usage: winebrowser URL\n" );
|
2011-12-08 16:36:33 +01:00
|
|
|
return -1;
|
2005-11-24 19:27:41 +01:00
|
|
|
}
|
2004-01-06 21:49:58 +01:00
|
|
|
|
2011-12-08 16:36:33 +01:00
|
|
|
hres = CreateUri(url, Uri_CREATE_ALLOW_IMPLICIT_FILE_SCHEME|Uri_CREATE_FILE_USE_DOS_PATH, 0, &uri);
|
|
|
|
if(FAILED(hres)) {
|
2020-11-25 00:16:39 +01:00
|
|
|
WINE_ERR("Failed to parse URL %s, treating as HTTP\n", wine_dbgstr_w(url));
|
2021-09-27 12:33:09 +02:00
|
|
|
return open_invalid_url(url);
|
2006-02-18 15:50:06 +01:00
|
|
|
}
|
|
|
|
|
2021-09-27 12:33:09 +02:00
|
|
|
free(ddeString);
|
2011-12-08 16:36:33 +01:00
|
|
|
IUri_GetScheme(uri, &scheme);
|
2004-01-06 21:49:58 +01:00
|
|
|
|
2011-12-08 16:36:33 +01:00
|
|
|
if(scheme == URL_SCHEME_FILE) {
|
2014-07-01 21:09:39 +02:00
|
|
|
display_uri = convert_file_uri(uri);
|
|
|
|
if(!display_uri) {
|
2011-12-08 16:36:33 +01:00
|
|
|
WINE_ERR("Failed to convert file URL to unix path\n");
|
2009-07-02 11:16:33 +02:00
|
|
|
}
|
2011-12-08 16:36:33 +01:00
|
|
|
}
|
2009-07-02 11:16:33 +02:00
|
|
|
|
2014-07-01 21:09:39 +02:00
|
|
|
if (!display_uri)
|
|
|
|
hres = IUri_GetDisplayUri(uri, &display_uri);
|
2011-12-08 16:36:33 +01:00
|
|
|
IUri_Release(uri);
|
|
|
|
if(FAILED(hres))
|
|
|
|
return -1;
|
2008-04-06 14:44:31 +02:00
|
|
|
|
2011-12-08 16:36:33 +01:00
|
|
|
WINE_TRACE("opening %s\n", wine_dbgstr_w(display_uri));
|
2004-01-06 21:49:58 +01:00
|
|
|
|
2011-12-08 16:36:33 +01:00
|
|
|
if(scheme == URL_SCHEME_MAILTO)
|
2021-09-27 12:33:09 +02:00
|
|
|
return open_mailto_url(display_uri);
|
2007-06-07 17:33:35 +02:00
|
|
|
else
|
|
|
|
/* let the browser decide how to handle the given url */
|
2021-09-27 12:33:09 +02:00
|
|
|
return open_http_url(display_uri);
|
2004-01-06 21:49:58 +01:00
|
|
|
}
|