wined3d: Pass the correct mask to shader_glsl_add_src_param() in shader_glsl_ifc().
[wine.git] / programs / winebrowser / main.c
blob7bea32c9420c192be145592a4acfab3e0a3629e8
1 /*
2 * winebrowser - winelib app to launch native OS browser or mail client.
4 * Copyright (C) 2004 Chris Morgan
5 * Copyright (C) 2005 Hans Leidekker
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 * NOTES:
22 * Winebrowser is a winelib application that will start the appropriate
23 * native browser or mail client for a wine installation that lacks a
24 * windows browser/mail client. For example, you will be able to open
25 * urls via native mozilla if no browser has yet been installed in wine.
27 * The application to launch is chosen from a default set or, if set,
28 * taken from a registry key.
30 * The argument may be a regular Windows file name, a file URL, an
31 * URL or a mailto URL. In the first three cases the argument
32 * will be fed to a web browser. In the last case the argument is fed
33 * to a mail client. A mailto URL is composed as follows:
35 * mailto:[E-MAIL]?subject=[TOPIC]&cc=[E-MAIL]&bcc=[E-MAIL]&body=[TEXT]
38 #define WIN32_LEAN_AND_MEAN
40 #include "config.h"
41 #include "wine/port.h"
43 #include <windows.h>
44 #include <shlwapi.h>
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <errno.h>
49 typedef LPSTR (*wine_get_unix_file_name_t)(LPCWSTR unixname);
51 /* try to launch an app from a comma separated string of app names */
52 static int launch_app( char *candidates, const char *argv1 )
54 char *app;
55 const char *argv_new[3];
57 app = strtok( candidates, "," );
58 while (app)
60 argv_new[0] = app;
61 argv_new[1] = argv1;
62 argv_new[2] = NULL;
64 fprintf( stderr, "Considering: %s\n", app );
65 fprintf( stderr, "argv[1]: %s\n", argv1 );
67 spawnvp( _P_OVERLAY, app, argv_new ); /* only returns on error */
68 app = strtok( NULL, "," ); /* grab the next app */
70 fprintf( stderr, "winebrowser: could not find a suitable app to run\n" );
71 return 1;
74 static int open_http_url( const char *url )
76 static const char *defaultbrowsers =
77 "xdg-open,firefox,konqueror,mozilla,netscape,galeon,opera,dillo";
78 char browsers[256];
80 DWORD length, type;
81 HKEY key;
82 LONG r;
84 length = sizeof(browsers);
85 /* @@ Wine registry key: HKCU\Software\Wine\WineBrowser */
86 if (RegCreateKeyEx( HKEY_CURRENT_USER, "Software\\Wine\\WineBrowser", 0, NULL,
87 REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, NULL))
89 fprintf( stderr, "winebrowser: cannot create config key\n" );
90 return 1;
93 r = RegQueryValueExA( key, "Browsers", 0, &type, (LPBYTE)browsers, &length );
94 if (r != ERROR_SUCCESS)
96 /* set value to the default */
97 RegSetValueExA( key, "Browsers", 0, REG_SZ, (const BYTE *)defaultbrowsers,
98 lstrlen( defaultbrowsers ) + 1 );
99 strcpy( browsers, defaultbrowsers );
101 RegCloseKey( key );
103 return launch_app( browsers, url );
106 static int open_mailto_url( const char *url )
108 static const char *defaultmailers =
109 "xdg-email,mozilla-thunderbird,thunderbird,evolution";
110 char mailers[256];
112 DWORD length, type;
113 HKEY key;
114 LONG r;
116 length = sizeof(mailers);
117 /* @@ Wine registry key: HKCU\Software\Wine\WineBrowser */
118 if (RegCreateKeyEx( HKEY_CURRENT_USER, "Software\\Wine\\WineBrowser", 0, NULL,
119 REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key, NULL ))
121 fprintf( stderr, "winebrowser: cannot create config key\n" );
122 return 1;
125 r = RegQueryValueExA( key, "Mailers", 0, &type, (LPBYTE)mailers, &length );
126 if (r != ERROR_SUCCESS)
128 /* set value to the default */
129 RegSetValueExA( key, "Mailers", 0, REG_SZ, (const BYTE *)defaultmailers,
130 lstrlen( defaultmailers ) + 1 );
131 strcpy( mailers, defaultmailers );
133 RegCloseKey( key );
135 return launch_app( mailers, url );
138 /*****************************************************************************
139 * Main entry point. This is a console application so we have a main() not a
140 * winmain().
142 int main(int argc, char *argv[])
144 char *url = argv[1];
145 wine_get_unix_file_name_t wine_get_unix_file_name_ptr;
147 if (argc == 1)
149 fprintf( stderr, "Usage: winebrowser URL\n" );
150 return 1;
153 /* handle an RFC1738 file URL */
154 if (!strncasecmp( url, "file:", 5 ))
156 char *p;
157 DWORD len = lstrlenA( url ) + 1;
159 if (UrlUnescapeA( url, NULL, &len, URL_UNESCAPE_INPLACE ) != S_OK)
161 fprintf( stderr, "winebrowser: unescaping URL failed: %s\n", url );
162 return 1;
165 /* look for a Windows path after 'file:' */
166 p = url + 5;
167 while (*p)
169 if (isalpha( p[0] ) && (p[1] == ':' || p[1] == '|')) break;
170 p++;
172 if (!*p)
174 fprintf( stderr, "winebrowser: no valid Windows path in: %s\n", url );
175 return 1;
178 if (p[1] == '|') p[1] = ':';
179 url = p;
181 while (*p)
183 if (*p == '/') *p = '\\';
184 p++;
188 /* check if the argument is a local file */
189 wine_get_unix_file_name_ptr = (wine_get_unix_file_name_t)
190 GetProcAddress( GetModuleHandle( "KERNEL32" ), "wine_get_unix_file_name" );
192 if (wine_get_unix_file_name_ptr == NULL)
194 fprintf( stderr,
195 "winebrowser: cannot get the address of 'wine_get_unix_file_name'\n" );
197 else
199 char *unixpath;
200 WCHAR unixpathW[MAX_PATH];
202 MultiByteToWideChar( CP_UNIXCP, 0, url, -1, unixpathW, MAX_PATH );
203 if ((unixpath = wine_get_unix_file_name_ptr( unixpathW )))
205 struct stat dummy;
207 if (stat( unixpath, &dummy ) >= 0)
208 return open_http_url( unixpath );
212 if (!strncasecmp( url, "mailto:", 7 ))
213 return open_mailto_url( url );
215 /* let the browser decide how to handle the given url */
216 return open_http_url( url );