Hans Leidekker : winebrowser: Handle file URLs.
Alexandre Julliard
julliard at wine.codeweavers.com
Sat Feb 18 09:22:59 CST 2006
Module: wine
Branch: refs/heads/master
Commit: 68d41b41b7fbcd53928ca9842ee51fb90506d5e7
URL: http://source.winehq.org/git/?p=wine.git;a=commit;h=68d41b41b7fbcd53928ca9842ee51fb90506d5e7
Author: Hans Leidekker <hans at it.vu.nl>
Date: Sat Feb 18 15:50:06 2006 +0100
winebrowser: Handle file URLs.
---
programs/winebrowser/Makefile.in | 2 +
programs/winebrowser/main.c | 57 +++++++++++++++++++++++++++++++-------
2 files changed, 48 insertions(+), 11 deletions(-)
diff --git a/programs/winebrowser/Makefile.in b/programs/winebrowser/Makefile.in
index 84b5917..f42d614 100644
--- a/programs/winebrowser/Makefile.in
+++ b/programs/winebrowser/Makefile.in
@@ -4,7 +4,7 @@ SRCDIR = @srcdir@
VPATH = @srcdir@
MODULE = winebrowser.exe
APPMODE = -mconsole
-IMPORTS = advapi32 kernel32
+IMPORTS = shlwapi advapi32 kernel32
C_SRCS = \
main.c
diff --git a/programs/winebrowser/main.c b/programs/winebrowser/main.c
index 6835d47..094468f 100644
--- a/programs/winebrowser/main.c
+++ b/programs/winebrowser/main.c
@@ -27,10 +27,10 @@
* The application to launch is chosen from a default set or, if set,
* taken from a registry key.
*
- * The argument may be a regular Windows file name, an http(s) URL or a
- * mailto URL. In the first two cases the argument will be fed to a web
- * browser. In the third case the argument is fed to a mail client.
- * A mailto URL is composed as follows:
+ * The argument may be a regular Windows file name, a file URL, an
+ * http(s) URL or a mailto URL. In the first three cases the argument
+ * 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:
*
* mailto:[E-MAIL]?subject=[TOPIC]&cc=[E-MAIL]&bcc=[E-MAIL]&body=[TEXT]
*/
@@ -41,6 +41,7 @@
#include "wine/port.h"
#include <windows.h>
+#include <shlwapi.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
@@ -140,6 +141,7 @@ static int open_mailto_url( const char *
*/
int main(int argc, char *argv[])
{
+ char *url = argv[1];
wine_get_unix_file_name_t wine_get_unix_file_name_ptr;
if (argc == 1)
@@ -148,6 +150,41 @@ int main(int argc, char *argv[])
return 1;
}
+ /* handle an RFC1738 file URL */
+ if (!strncasecmp( url, "file:", 5 ))
+ {
+ char *p;
+ DWORD len = lstrlenA( url ) + 1;
+
+ if (UrlUnescapeA( url, NULL, &len, URL_UNESCAPE_INPLACE ) != S_OK)
+ {
+ fprintf( stderr, "winebrowser: unescaping URL failed: %s\n", url );
+ return 1;
+ }
+
+ /* look for a Windows path after 'file:' */
+ p = url + 5;
+ while (*p)
+ {
+ if (isalpha( p[0] ) && (p[1] == ':' || p[1] == '|')) break;
+ p++;
+ }
+ if (!*p)
+ {
+ fprintf( stderr, "winebrowser: no valid Windows path in: %s\n", url );
+ return 1;
+ }
+
+ if (p[1] == '|') p[1] = ':';
+ url = p;
+
+ while (*p)
+ {
+ if (*p == '/') *p = '\\';
+ p++;
+ }
+ }
+
/* check if the argument is a local file */
wine_get_unix_file_name_ptr = (wine_get_unix_file_name_t)
GetProcAddress( GetModuleHandle( "KERNEL32" ), "wine_get_unix_file_name" );
@@ -162,7 +199,7 @@ int main(int argc, char *argv[])
char *unixpath;
WCHAR unixpathW[MAX_PATH];
- MultiByteToWideChar( CP_ACP, 0, argv[1], -1, unixpathW, MAX_PATH );
+ MultiByteToWideChar( CP_ACP, 0, url, -1, unixpathW, MAX_PATH );
if ((unixpath = wine_get_unix_file_name_ptr( unixpathW )))
{
struct stat dummy;
@@ -172,12 +209,12 @@ int main(int argc, char *argv[])
}
}
- if (!strncasecmp( argv[1], "http:", 5 ) || !strncasecmp( argv[1], "https:", 6 ))
- return open_http_url( argv[1] );
+ if (!strncasecmp( url, "http:", 5 ) || !strncasecmp( url, "https:", 6 ))
+ return open_http_url( url );
- if (!strncasecmp( argv[1], "mailto:", 7 ))
- return open_mailto_url( argv[1] );
+ if (!strncasecmp( url, "mailto:", 7 ))
+ return open_mailto_url( url );
- fprintf( stderr, "winebrowser: cannot handle this type of URL\n" );
+ fprintf( stderr, "winebrowser: cannot handle this type of URL: %s\n", url );
return 1;
}
More information about the wine-cvs
mailing list