Browser backend packaging.
[irreco.git] / backend / browser / src / browser_run.c
blob9a7f5ef698abb07aa045f9bfd73151f831af8a91
1 /*
2 * irreco-backend-browser
3 * Copyright (C) 2008 Arto Karppinen <arto.karppinen@iki.fi>
4 *
5 * irreco-backend-browser is free software: you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * irreco-backend-browser is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "browser_run.h"
23 static IrrecoBackendStatus
24 browser_spawn( gchar **argv, gint *status )
26 gchar *out = NULL;
27 gchar *err = NULL;
28 GError *error = NULL;
29 IRRECO_ENTER
31 g_spawn_sync( getenv( "HOME" ), /* working_directory */
32 argv, /* argv */
33 NULL, /* envp */
34 G_SPAWN_SEARCH_PATH, /* flags */
35 NULL, /* child_setup */
36 NULL, /* user_data */
37 &out, /* standard_output */
38 &err, /* standard_error */
39 status, /* exit_status */
40 &error );
42 if ( irreco_gerror_check_print( &error )) {
43 IRRECO_RETURN_ENUM( BROWSER_ERROR_SPAWN_FAILED )
46 IRRECO_PRINTF( "%s status: %i\n", argv[ 0 ], *status );
47 if ( ! irreco_str_isempty( out )) {
48 IRRECO_PRINTF( "%s stdout:\n%s", argv[ 0 ], out );
50 if ( ! irreco_str_isempty( err )) {
51 IRRECO_PRINTF( "%s stderr:\n%s", argv[ 0 ], err );
54 g_free( out );
55 g_free( err );
57 IRRECO_RETURN_ENUM( IRRECO_BACKEND_OK )
60 IrrecoBackendStatus
61 browser_run_maemo( const gchar *url )
63 IrrecoBackendStatus status = 0;
64 gint child_status = 0;
65 GString *string = NULL;
66 gchar *argv[] = { "dbus-send",
67 "--print-reply",
68 "--dest=com.nokia.osso_browser",
69 "/com/nokia/osso_browser",
70 "com.nokia.osso_browser.load_url",
71 NULL, NULL, NULL };
72 IRRECO_ENTER
74 string = g_string_new( "string:" );
75 g_string_append( string, url );
76 argv[ 5 ] = string->str;
78 status = browser_spawn( argv, &child_status );
80 if ( status == IRRECO_BACKEND_OK && child_status != 0 ) {
81 status = BROWSER_ERROR_MAEMO_BROWSER;
84 g_string_free( string, TRUE );
85 IRRECO_RETURN_INT( status );
88 IrrecoBackendStatus
89 browser_run_wget( const gchar *url )
91 IrrecoBackendStatus status = 0;
92 gint child_status = 0;
93 gchar *argv[] = { "wget",
94 "--non-verbose",
95 "--output-document",
96 "/dev/null",
97 "--",
98 NULL, NULL, NULL };
99 IRRECO_ENTER
101 argv[ 5 ] = (gchar*) url;
103 status = browser_spawn( argv, &child_status );
104 if ( status == IRRECO_BACKEND_OK && child_status != 0 ) {
105 status = BROWSER_ERROR_WGET;
108 IRRECO_RETURN_ENUM( status )
111 IrrecoBackendStatus
112 browser_run( BrowserApplicationType type, const gchar *url )
114 IRRECO_ENTER
116 switch ( type ) {
117 case BROWSER_APPLICATION_MAEMO:
118 IRRECO_RETURN_INT( browser_run_maemo( url ));
120 case BROWSER_APPLICATION_WGET:
121 IRRECO_RETURN_INT( browser_run_wget( url ));
124 IRRECO_RETURN_ENUM( BROWSER_ERROR_INVALID_APP )