Changeset 12461


Ignore:
Timestamp:
May 27, 2011, 1:36:53 PM (10 years ago)
Author:
jordan
Message:

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

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/NEWS

    r12443 r12461  
     1=== Transmission 2.32 (2011/xx/yy) ===
     2[http://trac.transmissionbt.com/query?milestone=2.32&group=component&order=severity All tickets closed by this release]
     3==== GTK+ ====
     4  * Remove GNOME desktop proxy support
     5
    16=== Transmission 2.31 (2011/05/17) ===
    27[http://trac.transmissionbt.com/query?milestone=2.31&group=component&order=severity All tickets closed by this release]
  • trunk/gtk/main.c

    r12412 r12461  
    7777"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.";
    7878
    79 struct gtr_proxy_settings
    80 {
    81     char * mode;
    82     char * autoconfig_url;
    83 
    84     char * ftp_host;
    85     int ftp_port;
    86 
    87     char * secure_host;
    88     int secure_port;
    89 
    90     gboolean use_http_proxy;
    91     gboolean http_authenticate;
    92     char * http_host;
    93     int http_port;
    94     char * http_user;
    95     char * http_pass;
    96 
    97     char * env_http_proxy;
    98 };
    99 
    10079struct cbdata
    10180{
     
    11392    GtkTreeSelection          * sel;
    11493    gpointer                    quit_dialog;
    115     GObject                   * proxy_gconf_client;
    116     struct gtr_proxy_settings   proxy_settings;
    11794};
    11895
     
    634611/****
    635612*****
    636 *****  GNOME DESKTOP PROXY SETTINGS
    637 *****
    638 ****/
    639 
    640 static void
    641 proxy_settings_clear( struct gtr_proxy_settings * settings )
    642 {
    643     g_free( settings->mode );
    644     g_free( settings->autoconfig_url );
    645     g_free( settings->ftp_host );
    646     g_free( settings->secure_host );
    647     g_free( settings->env_http_proxy );
    648     g_free( settings->http_host );
    649     g_free( settings->http_user );
    650     g_free( settings->http_pass );
    651     memset( settings, 0, sizeof( struct gtr_proxy_settings ) );
    652 }
    653 
    654 #ifdef HAVE_GCONF2
    655 
    656 static char*
    657 gtr_gconf_client_get_string( GConfClient * client, const char * key )
    658 {
    659     GConfValue * value = gconf_client_get( client, key, NULL );
    660     char * ret = g_strdup( gconf_value_get_string( value ) );
    661     gconf_value_free( value );
    662     return ret;
    663 }
    664 static int
    665 gtr_gconf_client_get_int( GConfClient * client, const char * key )
    666 {
    667     GConfValue * value = gconf_client_get( client, key, NULL );
    668     int ret = gconf_value_get_int( value );
    669     gconf_value_free( value );
    670     return ret;
    671 }
    672 static gboolean
    673 gtr_gconf_client_get_bool( GConfClient * client, const char * key )
    674 {
    675     GConfValue * value = gconf_client_get( client, key, NULL );
    676     const gboolean ret = gconf_value_get_bool( value ) != 0;
    677     gconf_value_free( value );
    678     return ret;
    679 }
    680 static void
    681 proxy_settings_populate( GConfClient * client, struct gtr_proxy_settings * settings )
    682 {
    683     proxy_settings_clear( settings );
    684     settings->mode               = gtr_gconf_client_get_string ( client, "/system/proxy/mode" );
    685     settings->autoconfig_url     = gtr_gconf_client_get_string ( client, "/system/proxy/autoconfig_url" );
    686     settings->ftp_host           = gtr_gconf_client_get_string ( client, "/system/proxy/ftp_host" );
    687     settings->ftp_port           = gtr_gconf_client_get_int    ( client, "/system/proxy/ftp_port" );
    688     settings->secure_host        = gtr_gconf_client_get_string ( client, "/system/proxy/secure_host" );
    689     settings->secure_port        = gtr_gconf_client_get_int    ( client, "/system/proxy/secure_port" );
    690     settings->use_http_proxy     = gtr_gconf_client_get_bool   ( client, "/system/http_proxy/use_http_proxy" );
    691     settings->http_authenticate  = gtr_gconf_client_get_bool   ( client, "/system/http_proxy/use_authentication" );
    692     settings->http_host          = gtr_gconf_client_get_string ( client, "/system/http_proxy/host" );
    693     settings->http_port          = gtr_gconf_client_get_int    ( client, "/system/http_proxy/port" );
    694     settings->http_user          = gtr_gconf_client_get_string ( client, "/system/http_proxy/authentication_user" );
    695     settings->http_pass          = gtr_gconf_client_get_string ( client, "/system/http_proxy/authentication_password" );
    696     settings->env_http_proxy     = g_strdup( g_getenv( "http_proxy" ) );
    697 }
    698 
    699 static void
    700 gconf_proxy_settings_changed( GConfClient * client, guint cnxn_id UNUSED,
    701                               GConfEntry * entry UNUSED, gpointer gcbdata )
    702 {
    703     struct cbdata * cbdata = gcbdata;
    704     struct gtr_proxy_settings * settings = &cbdata->proxy_settings;
    705     proxy_settings_populate( client, settings );
    706 }
    707 #endif
    708 
    709 static void
    710 apply_desktop_proxy_settings( CURL * easy, const char * host, int port )
    711 {
    712     if( host != NULL )
    713     {
    714         curl_easy_setopt( easy, CURLOPT_PROXY, host );
    715 
    716         if( port )
    717             curl_easy_setopt( easy, CURLOPT_PROXYPORT, (long)port );
    718 
    719         if( g_str_has_prefix( host, "socks4" ) )
    720             curl_easy_setopt( easy, CURLOPT_PROXYTYPE, (long)CURLPROXY_SOCKS4 );
    721         else if( g_str_has_prefix( host, "socks5" ) )
    722             curl_easy_setopt( easy, CURLOPT_PROXYTYPE, (long)CURLPROXY_SOCKS5 );
    723         else if( g_str_has_prefix( host, "http" ) )
    724             curl_easy_setopt( easy, CURLOPT_PROXYTYPE, (long)CURLPROXY_HTTP );
    725     }
    726 }
    727 
    728 static void
    729 curl_config_func( tr_session * session UNUSED, void * vcurl UNUSED, const char * url, void * gproxy_settings )
    730 {
    731     CURL *  easy = vcurl;
    732     const struct gtr_proxy_settings * settings = gproxy_settings;
    733 
    734     /* The "http_proxy" environment variable is applied by libcurl.
    735      * Since it should take precedence over the GNOME session settings,
    736      * don't set anything here if "http_proxy" is set in the environment. */
    737     if( settings->env_http_proxy != NULL )
    738         return;
    739 
    740     if( !tr_strcmp0( settings->mode, "none" ) )
    741     {
    742         /* nooop */
    743     }
    744     else if( !tr_strcmp0( settings->mode, "auto" ) )
    745     {
    746         apply_desktop_proxy_settings( easy, settings->autoconfig_url, 0 );
    747     }
    748     else if( !tr_strcmp0( settings->mode, "manual" ))
    749     {
    750         gboolean authenticate = FALSE;
    751 
    752         if( g_str_has_prefix( url, "ftp" ) )
    753         {
    754             apply_desktop_proxy_settings( easy, settings->ftp_host, settings->ftp_port );
    755         }
    756         else if( g_str_has_prefix( url, "https" ) )
    757         {
    758             apply_desktop_proxy_settings( easy, settings->secure_host, settings->secure_port );
    759             authenticate = settings->http_authenticate;
    760         }
    761         else if( g_str_has_prefix( url, "http" ) )
    762         {
    763             apply_desktop_proxy_settings( easy, settings->http_host, settings->http_port );
    764             authenticate = settings->http_authenticate;
    765         }
    766 
    767         if( authenticate && settings->http_user && settings->http_pass )
    768         {
    769             char * userpass = g_strdup_printf( "%s:%s", settings->http_user, settings->http_pass );
    770             curl_easy_setopt( easy, CURLOPT_PROXYUSERPWD, userpass );
    771             g_free( userpass );
    772         }
    773     }
    774     else
    775     {
    776         g_warning( "unhandled /system/proxy/mode: %s", settings->mode );
    777     }
    778 }
    779 
    780 static void
    781 proxy_setup( struct cbdata * cbdata )
    782 {
    783     struct gtr_proxy_settings * settings = &cbdata->proxy_settings;
    784 
    785 #ifdef HAVE_GCONF2
    786     /* listen for gconf changes to /system/proxy and /system/http_proxy */
    787     GConfClient * client = gconf_client_get_default( );
    788     const char * key = "/system/proxy";
    789     gconf_client_add_dir( client, key, GCONF_CLIENT_PRELOAD_NONE, NULL );
    790     gconf_client_notify_add( client, key, gconf_proxy_settings_changed, cbdata, NULL, NULL );
    791     key = "/system/http_proxy";
    792     gconf_client_add_dir( client, key, GCONF_CLIENT_PRELOAD_NONE, NULL );
    793     gconf_client_notify_add( client, key, gconf_proxy_settings_changed, cbdata, NULL, NULL );
    794     cbdata->proxy_gconf_client = G_OBJECT( client );
    795     proxy_settings_populate( client, settings );
    796 #else
    797     /* set up some default values for the proxy_settings struct */
    798     memset( settings, 0, sizeof( struct gtr_proxy_settings ) );
    799     settings->mode = g_strdup( "none" );
    800     settings->env_http_proxy = g_strdup( g_getenv( "http_proxy" ) );
    801 #endif
    802 
    803     /* set up the curl callback function */
    804     tr_sessionSetWebConfigFunc( gtr_core_session( cbdata->core ), curl_config_func, settings );
    805 }
    806 
    807 
    808 /****
    809 *****
    810613*****
    811614****/
     
    947750        gtr_pref_int_set( TR_PREFS_KEY_PEER_PORT, tr_sessionGetPeerPort( session ) );
    948751        cbdata->core = gtr_core_new( session );
    949         proxy_setup( cbdata );
    950752
    951753        /* init the ui manager */
     
    12061008    }
    12071009
    1208     proxy_settings_clear( &cbdata->proxy_settings );
    1209     if( cbdata->proxy_gconf_client )
    1210         g_object_unref( cbdata->proxy_gconf_client );
    12111010    if( cbdata->prefs )
    12121011        gtk_widget_destroy( GTK_WIDGET( cbdata->prefs ) );
  • trunk/gtk/tr-prefs.c

    r12412 r12461  
    11561156}
    11571157
    1158 static void
    1159 onGNOMEClicked( GtkButton * button, gpointer vdata UNUSED )
    1160 {
    1161     GError * err = NULL;
    1162 
    1163     if( !g_spawn_command_line_async( "gnome-network-properties", &err ) &&
    1164         !g_spawn_command_line_async( "gnome-control-center network", &err ) )
    1165     {
    1166         GtkWidget * d = gtk_message_dialog_new( GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( button ) ) ),
    1167                                                 GTK_DIALOG_DESTROY_WITH_PARENT,
    1168                                                 GTK_MESSAGE_ERROR,
    1169                                                 GTK_BUTTONS_CLOSE,
    1170                                                 "%s", err->message );
    1171         g_signal_connect_swapped( d, "response", G_CALLBACK( gtk_widget_destroy ), d );
    1172         gtk_widget_show( d );
    1173         g_clear_error( &err );
    1174     }
    1175 }
    1176 
    11771158static GtkWidget*
    11781159networkPage( GObject * core )
     
    12351216    hig_workarea_add_wide_control( t, &row, w );
    12361217#endif
    1237 
    1238     w = gtk_button_new_with_mnemonic( _( "Edit GNOME Proxy Settings" ) );
    1239     g_signal_connect( w, "clicked", G_CALLBACK( onGNOMEClicked ), data );
    1240     h = gtk_hbox_new( FALSE, 0 );
    1241     gtk_box_pack_start( GTK_BOX( h ), w, FALSE, FALSE, 0 );
    1242     hig_workarea_add_wide_control( t, &row, h );
    12431218
    12441219    hig_workarea_finish( t, &row );
  • trunk/libtransmission/session.c

    r12435 r12461  
    25702570    }
    25712571}
    2572 
    2573 /***
    2574 ****
    2575 ***/
    2576 
    2577 void
    2578 tr_sessionSetWebConfigFunc( tr_session * session, void (*func)(tr_session*, void*, const char*, void* ), void * user_data )
    2579 {
    2580     session->curl_easy_config_func = func;
    2581     session->curl_easy_config_user_data = user_data;
    2582 }
  • trunk/libtransmission/session.h

    r12355 r12461  
    207207    struct tr_bindinfo         * public_ipv6;
    208208
    209     tr_web_config_func          * curl_easy_config_func;
    210     void                        * curl_easy_config_user_data;
    211 
    212209    uint8_t peer_id[PEER_ID_LEN+1];
    213210};
  • trunk/libtransmission/web.c

    r12417 r12461  
    191191    if( task->range )
    192192        curl_easy_setopt( e, CURLOPT_RANGE, task->range );
    193 
    194     if( s->curl_easy_config_func != NULL )
    195         s->curl_easy_config_func( s, e, task->url, s->curl_easy_config_user_data );
    196193
    197194    return e;
  • trunk/libtransmission/web.h

    r12355 r12461  
    2828}
    2929tr_web_close_mode;
    30 
    31 /**
    32  * This is a mechanism for adjusting your CURL* object to match
    33  * the host OS's platform-dependent settings.
    34  *
    35  * A use case for this function is to call curl_easy_setopt() on curl_pointer.
    36  *
    37  * Examples of curl_easy_setopt() can be found at
    38  * http://curl.haxx.se/libcurl/c/curl_easy_setopt.html()
    39  */
    40 void tr_sessionSetWebConfigFunc( tr_session * session, void (*config)(tr_session * session, void * curl_pointer, const char * url, void * user_data ), void * user_data );
    41 
    4230
    4331void tr_webClose( tr_session * session, tr_web_close_mode close_mode );
  • trunk/qt/session.cc

    r12360 r12461  
    308308}
    309309
    310 static void
    311 curlConfigFunc( tr_session * session UNUSED, void * vcurl, const char * destination, void * unused UNUSED )
    312 {
    313     CURL * easy = vcurl;
    314     const QUrl url( destination );
    315     const QNetworkProxyQuery query( url );
    316     QList<QNetworkProxy> proxyList = QNetworkProxyFactory :: systemProxyForQuery( query );
    317 
    318     foreach( QNetworkProxy proxy, proxyList )
    319     {
    320         long type = -1;
    321 
    322         switch( proxy.type( ) ) {
    323             case QNetworkProxy::HttpProxy: type = CURLPROXY_HTTP; break;
    324             case QNetworkProxy::Socks5Proxy: type = CURLPROXY_SOCKS5; break;
    325             default: break;
    326         }
    327 
    328         if( type != -1 ) {
    329             curl_easy_setopt( easy, CURLOPT_PROXY, proxy.hostName().toUtf8().data() );
    330             curl_easy_setopt( easy, CURLOPT_PROXYPORT, long(proxy.port()) );
    331             curl_easy_setopt( easy, CURLOPT_PROXYTYPE, type );
    332             const QString user = proxy.user();
    333             const QString pass = proxy.password();
    334             if( !user.isEmpty() && !pass.isEmpty() )
    335                 curl_easy_setopt( easy, CURLOPT_PROXYUSERPWD, (user+":"+pass).toUtf8().data() );
    336             return;
    337         }
    338     }
    339 }
    340 
    341310void
    342311Session :: start( )
     
    362331        tr_sessionLoadSettings( &settings, myConfigDir.toUtf8().constData(), "qt" );
    363332        mySession = tr_sessionInit( "qt", myConfigDir.toUtf8().constData(), true, &settings );
    364         tr_sessionSetWebConfigFunc( mySession, curlConfigFunc, NULL );
    365333        tr_bencFree( &settings );
    366334
Note: See TracChangeset for help on using the changeset viewer.