(trunk) #3817 remove OS proxy integration from the GTK+ client

This commit is contained in:
Jordan Lee 2011-05-27 13:36:53 +00:00
parent 7939421a56
commit 33eb6d3f9e
8 changed files with 5 additions and 287 deletions

5
NEWS
View File

@ -1,3 +1,8 @@
=== Transmission 2.32 (2011/xx/yy) ===
[http://trac.transmissionbt.com/query?milestone=2.32&group=component&order=severity All tickets closed by this release]
==== GTK+ ====
* Remove GNOME desktop proxy support
=== Transmission 2.31 (2011/05/17) ===
[http://trac.transmissionbt.com/query?milestone=2.31&group=component&order=severity All tickets closed by this release]
==== All Platforms ====

View File

@ -76,27 +76,6 @@ static const char * LICENSE =
"1. The MIT-licensed portions of Transmission listed above are exempt from GPLv2 clause 2(b) and may retain their MIT license.\n\n"
"2. Permission is granted to link the code in this release with the OpenSSL project's 'OpenSSL' library and to distribute the linked executables. Works derived from Transmission may, at their authors' discretion, keep or delete this exception.";
struct gtr_proxy_settings
{
char * mode;
char * autoconfig_url;
char * ftp_host;
int ftp_port;
char * secure_host;
int secure_port;
gboolean use_http_proxy;
gboolean http_authenticate;
char * http_host;
int http_port;
char * http_user;
char * http_pass;
char * env_http_proxy;
};
struct cbdata
{
gboolean is_iconified;
@ -112,8 +91,6 @@ struct cbdata
GSList * details;
GtkTreeSelection * sel;
gpointer quit_dialog;
GObject * proxy_gconf_client;
struct gtr_proxy_settings proxy_settings;
};
/***
@ -631,180 +608,6 @@ checkfilenames( int argc, char **argv )
return g_slist_reverse( ret );
}
/****
*****
***** GNOME DESKTOP PROXY SETTINGS
*****
****/
static void
proxy_settings_clear( struct gtr_proxy_settings * settings )
{
g_free( settings->mode );
g_free( settings->autoconfig_url );
g_free( settings->ftp_host );
g_free( settings->secure_host );
g_free( settings->env_http_proxy );
g_free( settings->http_host );
g_free( settings->http_user );
g_free( settings->http_pass );
memset( settings, 0, sizeof( struct gtr_proxy_settings ) );
}
#ifdef HAVE_GCONF2
static char*
gtr_gconf_client_get_string( GConfClient * client, const char * key )
{
GConfValue * value = gconf_client_get( client, key, NULL );
char * ret = g_strdup( gconf_value_get_string( value ) );
gconf_value_free( value );
return ret;
}
static int
gtr_gconf_client_get_int( GConfClient * client, const char * key )
{
GConfValue * value = gconf_client_get( client, key, NULL );
int ret = gconf_value_get_int( value );
gconf_value_free( value );
return ret;
}
static gboolean
gtr_gconf_client_get_bool( GConfClient * client, const char * key )
{
GConfValue * value = gconf_client_get( client, key, NULL );
const gboolean ret = gconf_value_get_bool( value ) != 0;
gconf_value_free( value );
return ret;
}
static void
proxy_settings_populate( GConfClient * client, struct gtr_proxy_settings * settings )
{
proxy_settings_clear( settings );
settings->mode = gtr_gconf_client_get_string ( client, "/system/proxy/mode" );
settings->autoconfig_url = gtr_gconf_client_get_string ( client, "/system/proxy/autoconfig_url" );
settings->ftp_host = gtr_gconf_client_get_string ( client, "/system/proxy/ftp_host" );
settings->ftp_port = gtr_gconf_client_get_int ( client, "/system/proxy/ftp_port" );
settings->secure_host = gtr_gconf_client_get_string ( client, "/system/proxy/secure_host" );
settings->secure_port = gtr_gconf_client_get_int ( client, "/system/proxy/secure_port" );
settings->use_http_proxy = gtr_gconf_client_get_bool ( client, "/system/http_proxy/use_http_proxy" );
settings->http_authenticate = gtr_gconf_client_get_bool ( client, "/system/http_proxy/use_authentication" );
settings->http_host = gtr_gconf_client_get_string ( client, "/system/http_proxy/host" );
settings->http_port = gtr_gconf_client_get_int ( client, "/system/http_proxy/port" );
settings->http_user = gtr_gconf_client_get_string ( client, "/system/http_proxy/authentication_user" );
settings->http_pass = gtr_gconf_client_get_string ( client, "/system/http_proxy/authentication_password" );
settings->env_http_proxy = g_strdup( g_getenv( "http_proxy" ) );
}
static void
gconf_proxy_settings_changed( GConfClient * client, guint cnxn_id UNUSED,
GConfEntry * entry UNUSED, gpointer gcbdata )
{
struct cbdata * cbdata = gcbdata;
struct gtr_proxy_settings * settings = &cbdata->proxy_settings;
proxy_settings_populate( client, settings );
}
#endif
static void
apply_desktop_proxy_settings( CURL * easy, const char * host, int port )
{
if( host != NULL )
{
curl_easy_setopt( easy, CURLOPT_PROXY, host );
if( port )
curl_easy_setopt( easy, CURLOPT_PROXYPORT, (long)port );
if( g_str_has_prefix( host, "socks4" ) )
curl_easy_setopt( easy, CURLOPT_PROXYTYPE, (long)CURLPROXY_SOCKS4 );
else if( g_str_has_prefix( host, "socks5" ) )
curl_easy_setopt( easy, CURLOPT_PROXYTYPE, (long)CURLPROXY_SOCKS5 );
else if( g_str_has_prefix( host, "http" ) )
curl_easy_setopt( easy, CURLOPT_PROXYTYPE, (long)CURLPROXY_HTTP );
}
}
static void
curl_config_func( tr_session * session UNUSED, void * vcurl UNUSED, const char * url, void * gproxy_settings )
{
CURL * easy = vcurl;
const struct gtr_proxy_settings * settings = gproxy_settings;
/* The "http_proxy" environment variable is applied by libcurl.
* Since it should take precedence over the GNOME session settings,
* don't set anything here if "http_proxy" is set in the environment. */
if( settings->env_http_proxy != NULL )
return;
if( !tr_strcmp0( settings->mode, "none" ) )
{
/* nooop */
}
else if( !tr_strcmp0( settings->mode, "auto" ) )
{
apply_desktop_proxy_settings( easy, settings->autoconfig_url, 0 );
}
else if( !tr_strcmp0( settings->mode, "manual" ))
{
gboolean authenticate = FALSE;
if( g_str_has_prefix( url, "ftp" ) )
{
apply_desktop_proxy_settings( easy, settings->ftp_host, settings->ftp_port );
}
else if( g_str_has_prefix( url, "https" ) )
{
apply_desktop_proxy_settings( easy, settings->secure_host, settings->secure_port );
authenticate = settings->http_authenticate;
}
else if( g_str_has_prefix( url, "http" ) )
{
apply_desktop_proxy_settings( easy, settings->http_host, settings->http_port );
authenticate = settings->http_authenticate;
}
if( authenticate && settings->http_user && settings->http_pass )
{
char * userpass = g_strdup_printf( "%s:%s", settings->http_user, settings->http_pass );
curl_easy_setopt( easy, CURLOPT_PROXYUSERPWD, userpass );
g_free( userpass );
}
}
else
{
g_warning( "unhandled /system/proxy/mode: %s", settings->mode );
}
}
static void
proxy_setup( struct cbdata * cbdata )
{
struct gtr_proxy_settings * settings = &cbdata->proxy_settings;
#ifdef HAVE_GCONF2
/* listen for gconf changes to /system/proxy and /system/http_proxy */
GConfClient * client = gconf_client_get_default( );
const char * key = "/system/proxy";
gconf_client_add_dir( client, key, GCONF_CLIENT_PRELOAD_NONE, NULL );
gconf_client_notify_add( client, key, gconf_proxy_settings_changed, cbdata, NULL, NULL );
key = "/system/http_proxy";
gconf_client_add_dir( client, key, GCONF_CLIENT_PRELOAD_NONE, NULL );
gconf_client_notify_add( client, key, gconf_proxy_settings_changed, cbdata, NULL, NULL );
cbdata->proxy_gconf_client = G_OBJECT( client );
proxy_settings_populate( client, settings );
#else
/* set up some default values for the proxy_settings struct */
memset( settings, 0, sizeof( struct gtr_proxy_settings ) );
settings->mode = g_strdup( "none" );
settings->env_http_proxy = g_strdup( g_getenv( "http_proxy" ) );
#endif
/* set up the curl callback function */
tr_sessionSetWebConfigFunc( gtr_core_session( cbdata->core ), curl_config_func, settings );
}
/****
*****
*****
@ -946,7 +749,6 @@ main( int argc, char ** argv )
gtr_pref_flag_set( TR_PREFS_KEY_ALT_SPEED_ENABLED, tr_sessionUsesAltSpeed( session ) );
gtr_pref_int_set( TR_PREFS_KEY_PEER_PORT, tr_sessionGetPeerPort( session ) );
cbdata->core = gtr_core_new( session );
proxy_setup( cbdata );
/* init the ui manager */
myUIManager = gtk_ui_manager_new ( );
@ -1205,9 +1007,6 @@ on_session_closed( gpointer gdata )
gtk_widget_destroy( h->dialog );
}
proxy_settings_clear( &cbdata->proxy_settings );
if( cbdata->proxy_gconf_client )
g_object_unref( cbdata->proxy_gconf_client );
if( cbdata->prefs )
gtk_widget_destroy( GTK_WIDGET( cbdata->prefs ) );
if( cbdata->wind )

View File

@ -1155,25 +1155,6 @@ onPortTest( GtkButton * button UNUSED, gpointer vdata )
gtr_core_port_test( data->core );
}
static void
onGNOMEClicked( GtkButton * button, gpointer vdata UNUSED )
{
GError * err = NULL;
if( !g_spawn_command_line_async( "gnome-network-properties", &err ) &&
!g_spawn_command_line_async( "gnome-control-center network", &err ) )
{
GtkWidget * d = gtk_message_dialog_new( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( button ) ) ),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"%s", err->message );
g_signal_connect_swapped( d, "response", G_CALLBACK( gtk_widget_destroy ), d );
gtk_widget_show( d );
g_clear_error( &err );
}
}
static GtkWidget*
networkPage( GObject * core )
{
@ -1235,12 +1216,6 @@ networkPage( GObject * core )
hig_workarea_add_wide_control( t, &row, w );
#endif
w = gtk_button_new_with_mnemonic( _( "Edit GNOME Proxy Settings" ) );
g_signal_connect( w, "clicked", G_CALLBACK( onGNOMEClicked ), data );
h = gtk_hbox_new( FALSE, 0 );
gtk_box_pack_start( GTK_BOX( h ), w, FALSE, FALSE, 0 );
hig_workarea_add_wide_control( t, &row, h );
hig_workarea_finish( t, &row );
return t;
}

View File

@ -2569,14 +2569,3 @@ tr_sessionSetTorrentDoneScript( tr_session * session, const char * scriptFilenam
session->torrentDoneScript = tr_strdup( scriptFilename );
}
}
/***
****
***/
void
tr_sessionSetWebConfigFunc( tr_session * session, void (*func)(tr_session*, void*, const char*, void* ), void * user_data )
{
session->curl_easy_config_func = func;
session->curl_easy_config_user_data = user_data;
}

View File

@ -206,9 +206,6 @@ struct tr_session
struct tr_bindinfo * public_ipv4;
struct tr_bindinfo * public_ipv6;
tr_web_config_func * curl_easy_config_func;
void * curl_easy_config_user_data;
uint8_t peer_id[PEER_ID_LEN+1];
};

View File

@ -191,9 +191,6 @@ createEasy( tr_session * s, struct tr_web * web, struct tr_web_task * task )
if( task->range )
curl_easy_setopt( e, CURLOPT_RANGE, task->range );
if( s->curl_easy_config_func != NULL )
s->curl_easy_config_func( s, e, task->url, s->curl_easy_config_user_data );
return e;
}

View File

@ -28,18 +28,6 @@ typedef enum
}
tr_web_close_mode;
/**
* This is a mechanism for adjusting your CURL* object to match
* the host OS's platform-dependent settings.
*
* A use case for this function is to call curl_easy_setopt() on curl_pointer.
*
* Examples of curl_easy_setopt() can be found at
* http://curl.haxx.se/libcurl/c/curl_easy_setopt.html()
*/
void tr_sessionSetWebConfigFunc( tr_session * session, void (*config)(tr_session * session, void * curl_pointer, const char * url, void * user_data ), void * user_data );
void tr_webClose( tr_session * session, tr_web_close_mode close_mode );
typedef void ( tr_web_done_func )( tr_session * session,

View File

@ -307,37 +307,6 @@ Session :: restart( )
start( );
}
static void
curlConfigFunc( tr_session * session UNUSED, void * vcurl, const char * destination, void * unused UNUSED )
{
CURL * easy = vcurl;
const QUrl url( destination );
const QNetworkProxyQuery query( url );
QList<QNetworkProxy> proxyList = QNetworkProxyFactory :: systemProxyForQuery( query );
foreach( QNetworkProxy proxy, proxyList )
{
long type = -1;
switch( proxy.type( ) ) {
case QNetworkProxy::HttpProxy: type = CURLPROXY_HTTP; break;
case QNetworkProxy::Socks5Proxy: type = CURLPROXY_SOCKS5; break;
default: break;
}
if( type != -1 ) {
curl_easy_setopt( easy, CURLOPT_PROXY, proxy.hostName().toUtf8().data() );
curl_easy_setopt( easy, CURLOPT_PROXYPORT, long(proxy.port()) );
curl_easy_setopt( easy, CURLOPT_PROXYTYPE, type );
const QString user = proxy.user();
const QString pass = proxy.password();
if( !user.isEmpty() && !pass.isEmpty() )
curl_easy_setopt( easy, CURLOPT_PROXYUSERPWD, (user+":"+pass).toUtf8().data() );
return;
}
}
}
void
Session :: start( )
{
@ -361,7 +330,6 @@ Session :: start( )
tr_bencInitDict( &settings, 0 );
tr_sessionLoadSettings( &settings, myConfigDir.toUtf8().constData(), "qt" );
mySession = tr_sessionInit( "qt", myConfigDir.toUtf8().constData(), true, &settings );
tr_sessionSetWebConfigFunc( mySession, curlConfigFunc, NULL );
tr_bencFree( &settings );
tr_ctor * ctor = tr_ctorNew( mySession );