From 7974a1e50a9889d3d4d5c7a2d966ee0aea30b78f Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 15 Jul 2008 01:03:03 +0000 Subject: [PATCH] (libT) add proxy port arg as requested by BentMyWookie --- cli/cli.c | 1 + daemon/daemon.c | 1 + gtk/main.c | 1 + gtk/tr-prefs.c | 79 +++++++++++++++++++++------------- gtk/tr-prefs.h | 1 + libtransmission/session.c | 15 ++++++- libtransmission/session.h | 1 + libtransmission/transmission.h | 5 +++ libtransmission/web.c | 1 + 9 files changed, 75 insertions(+), 30 deletions(-) diff --git a/cli/cli.c b/cli/cli.c index a597e730e..6fe26bb10 100644 --- a/cli/cli.c +++ b/cli/cli.c @@ -286,6 +286,7 @@ main( int argc, char ** argv ) FALSE, "fnord", "potzrebie", TR_DEFAULT_PROXY_ENABLED, TR_DEFAULT_PROXY, + TR_DEFAULT_PROXY_PORT, TR_DEFAULT_PROXY_TYPE, TR_DEFAULT_PROXY_AUTH_ENABLED, TR_DEFAULT_PROXY_USERNAME, diff --git a/daemon/daemon.c b/daemon/daemon.c index b64838af9..9dc74c7e7 100644 --- a/daemon/daemon.c +++ b/daemon/daemon.c @@ -193,6 +193,7 @@ session_init( const char * configDir, const char * downloadDir, TRUE, rpcPort, acl, authRequired, username, password, TR_DEFAULT_PROXY_ENABLED, TR_DEFAULT_PROXY, + TR_DEFAULT_PROXY_PORT, TR_DEFAULT_PROXY_TYPE, TR_DEFAULT_PROXY_AUTH_ENABLED, TR_DEFAULT_PROXY_USERNAME, diff --git a/gtk/main.c b/gtk/main.c index 0bcd41db4..bc655dc4e 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -433,6 +433,7 @@ main( int argc, char ** argv ) pref_string_get( PREF_KEY_RPC_PASSWORD ), pref_flag_get( PREF_KEY_PROXY_SERVER_ENABLED ), pref_string_get( PREF_KEY_PROXY_SERVER ), + pref_int_get( PREF_KEY_PROXY_PORT ), pref_int_get( PREF_KEY_PROXY_TYPE ), pref_flag_get( PREF_KEY_PROXY_AUTH_ENABLED ), pref_string_get( PREF_KEY_PROXY_USERNAME ), diff --git a/gtk/tr-prefs.c b/gtk/tr-prefs.c index 2edb06a24..6e01e8e7b 100644 --- a/gtk/tr-prefs.c +++ b/gtk/tr-prefs.c @@ -78,9 +78,10 @@ tr_prefs_init_global( void ) pref_int_set_default ( PREF_KEY_MAIN_WINDOW_Y, 50 ); pref_string_set_default ( PREF_KEY_PROXY_SERVER, "" ); - pref_int_set_default ( PREF_KEY_PROXY_TYPE, TR_PROXY_HTTP ); - pref_flag_set_default ( PREF_KEY_PROXY_SERVER_ENABLED, FALSE ); - pref_flag_set_default ( PREF_KEY_PROXY_AUTH_ENABLED, FALSE ); + pref_int_set_default ( PREF_KEY_PROXY_PORT, TR_DEFAULT_PROXY_PORT ); + pref_int_set_default ( PREF_KEY_PROXY_TYPE, TR_DEFAULT_PROXY_TYPE ); + pref_flag_set_default ( PREF_KEY_PROXY_SERVER_ENABLED, TR_DEFAULT_PROXY_ENABLED ); + pref_flag_set_default ( PREF_KEY_PROXY_AUTH_ENABLED, TR_DEFAULT_PROXY_AUTH_ENABLED ); pref_string_set_default ( PREF_KEY_PROXY_USERNAME, "" ); pref_string_set_default ( PREF_KEY_PROXY_PASSWORD, "" ); @@ -964,12 +965,12 @@ onProxyTypeChanged( GtkComboBox * w, gpointer gpage ) } static GtkWidget* -networkPage( GObject * core ) +trackerPage( GObject * core ) { int row = 0; const char * s; GtkWidget * t; - GtkWidget * w, * w2; + GtkWidget * w; GtkTreeModel * m; GtkCellRenderer * r; struct ProxyPage * page = tr_new0( struct ProxyPage, 1 ); @@ -977,30 +978,6 @@ networkPage( GObject * core ) page->core = TR_CORE( core ); t = hig_workarea_create( ); - hig_workarea_add_section_title (t, &row, _( "Router" ) ); - - s = _("Use UPnP or NAT-PMP port _forwarding from my router" ); - w = new_check_button( s, PREF_KEY_PORT_FORWARDING, core ); - hig_workarea_add_wide_control( t, &row, w ); - - hig_workarea_add_section_divider( t, &row ); - hig_workarea_add_section_title (t, &row, _("Bandwidth")); - - s = _("Limit _download speed (KB/s):"); - w = new_check_button( s, PREF_KEY_DL_LIMIT_ENABLED, core ); - w2 = new_spin_button( PREF_KEY_DL_LIMIT, core, 0, INT_MAX, 5 ); - gtk_widget_set_sensitive( GTK_WIDGET(w2), pref_flag_get( PREF_KEY_DL_LIMIT_ENABLED ) ); - g_signal_connect( w, "toggled", G_CALLBACK(target_cb), w2 ); - hig_workarea_add_row_w( t, &row, w, w2, NULL ); - - s = _("Limit _upload speed (KB/s):"); - w = new_check_button( s, PREF_KEY_UL_LIMIT_ENABLED, core ); - w2 = new_spin_button( PREF_KEY_UL_LIMIT, core, 0, INT_MAX, 5 ); - gtk_widget_set_sensitive( GTK_WIDGET(w2), pref_flag_get( PREF_KEY_UL_LIMIT_ENABLED ) ); - g_signal_connect( w, "toggled", G_CALLBACK(target_cb), w2 ); - hig_workarea_add_row_w( t, &row, w, w2, NULL ); - - hig_workarea_add_section_divider( t, &row ); hig_workarea_add_section_title (t, &row, _( "Tracker Proxy" ) ); s = _( "Connect to tracker with HTTP proxy" ); @@ -1014,6 +991,11 @@ networkPage( GObject * core ) w = hig_workarea_add_row( t, &row, s, w, NULL ); page->proxy_widgets = g_slist_append( page->proxy_widgets, w ); + w = new_spin_button( PREF_KEY_PROXY_PORT, core, 0, 65536, 1 ); + page->proxy_widgets = g_slist_append( page->proxy_widgets, w ); + w = hig_workarea_add_row( t, &row, _( "Proxy port:" ), w, NULL ); + page->proxy_widgets = g_slist_append( page->proxy_widgets, w ); + s = _( "Proxy type:" ); m = proxyTypeModelNew( ); w = gtk_combo_box_new_with_model( m ); @@ -1053,6 +1035,42 @@ networkPage( GObject * core ) return t; } +static GtkWidget* +networkPage( GObject * core ) +{ + int row = 0; + const char * s; + GtkWidget * t; + GtkWidget * w, * w2; + + t = hig_workarea_create( ); + hig_workarea_add_section_title (t, &row, _( "Router" ) ); + + s = _("Use UPnP or NAT-PMP port _forwarding from my router" ); + w = new_check_button( s, PREF_KEY_PORT_FORWARDING, core ); + hig_workarea_add_wide_control( t, &row, w ); + + hig_workarea_add_section_divider( t, &row ); + hig_workarea_add_section_title (t, &row, _("Bandwidth")); + + s = _("Limit _download speed (KB/s):"); + w = new_check_button( s, PREF_KEY_DL_LIMIT_ENABLED, core ); + w2 = new_spin_button( PREF_KEY_DL_LIMIT, core, 0, INT_MAX, 5 ); + gtk_widget_set_sensitive( GTK_WIDGET(w2), pref_flag_get( PREF_KEY_DL_LIMIT_ENABLED ) ); + g_signal_connect( w, "toggled", G_CALLBACK(target_cb), w2 ); + hig_workarea_add_row_w( t, &row, w, w2, NULL ); + + s = _("Limit _upload speed (KB/s):"); + w = new_check_button( s, PREF_KEY_UL_LIMIT_ENABLED, core ); + w2 = new_spin_button( PREF_KEY_UL_LIMIT, core, 0, INT_MAX, 5 ); + gtk_widget_set_sensitive( GTK_WIDGET(w2), pref_flag_get( PREF_KEY_UL_LIMIT_ENABLED ) ); + g_signal_connect( w, "toggled", G_CALLBACK(target_cb), w2 ); + hig_workarea_add_row_w( t, &row, w, w2, NULL ); + + hig_workarea_finish( t, &row ); + return t; +} + GtkWidget * tr_prefs_dialog_new( GObject * core, GtkWindow * parent ) { @@ -1082,6 +1100,9 @@ tr_prefs_dialog_new( GObject * core, GtkWindow * parent ) gtk_notebook_append_page( GTK_NOTEBOOK( n ), peerPage( core, alive ), gtk_label_new (_("Peers")) ); + gtk_notebook_append_page( GTK_NOTEBOOK( n ), + trackerPage( core ), + gtk_label_new (_("Trackers")) ); gtk_notebook_append_page( GTK_NOTEBOOK( n ), networkPage( core ), gtk_label_new (_("Network")) ); diff --git a/gtk/tr-prefs.h b/gtk/tr-prefs.h index dcb9bdb12..2a65541a3 100644 --- a/gtk/tr-prefs.h +++ b/gtk/tr-prefs.h @@ -61,6 +61,7 @@ GtkWidget * tr_prefs_dialog_new( GObject * core, GtkWindow * parent ); #define PREF_KEY_RPC_PASSWORD "rpc-password" #define PREF_KEY_RPC_USERNAME "rpc-username" #define PREF_KEY_PROXY_SERVER "proxy-server" +#define PREF_KEY_PROXY_PORT "proxy-port" #define PREF_KEY_PROXY_SERVER_ENABLED "proxy-server-enabled" #define PREF_KEY_PROXY_TYPE "proxy-type" #define PREF_KEY_PROXY_AUTH_ENABLED "proxy-authentication-required" diff --git a/libtransmission/session.c b/libtransmission/session.c index 6588eaee0..be5ef7b45 100644 --- a/libtransmission/session.c +++ b/libtransmission/session.c @@ -189,7 +189,7 @@ tr_sessionInitFull( const char * configDir, const char * downloadDir, int isPexEnabled, int isPortForwardingEnabled, - int publicPort, + int publicPort, int encryptionMode, int isUploadLimitEnabled, int uploadLimit, @@ -208,6 +208,7 @@ tr_sessionInitFull( const char * configDir, const char * rpcPassword, int proxyIsEnabled, const char * proxy, + int proxyPort, tr_proxy_type proxyType, int proxyAuthIsEnabled, const char * proxyUsername, @@ -236,6 +237,7 @@ tr_sessionInitFull( const char * configDir, h->downloadDir = tr_strdup( downloadDir ); h->isProxyEnabled = proxyIsEnabled ? 1 : 0; h->proxy = tr_strdup( proxy ); + h->proxyPort = proxyPort; h->proxyType = proxyType; h->isProxyAuthEnabled = proxyAuthIsEnabled ? 1 : 0; h->proxyUsername = tr_strdup( proxyUsername ); @@ -316,6 +318,7 @@ tr_sessionInit( const char * configDir, "potzrebie", TR_DEFAULT_PROXY_ENABLED, TR_DEFAULT_PROXY, + TR_DEFAULT_PROXY_PORT, TR_DEFAULT_PROXY_TYPE, TR_DEFAULT_PROXY_AUTH_ENABLED, TR_DEFAULT_PROXY_USERNAME, @@ -976,6 +979,11 @@ tr_sessionGetProxy( const tr_session * session ) { return session->proxy; } +int +tr_sessionGetProxyPort( const tr_session * session ) +{ + return session->proxyPort; +} void tr_sessionSetProxy( tr_session * session, const char * proxy ) { @@ -985,6 +993,11 @@ tr_sessionSetProxy( tr_session * session, const char * proxy ) session->proxy = tr_strdup( proxy ); } } +void +tr_sessionSetProxyPort( tr_session * session, int port ) +{ + session->proxyPort = port; +} int tr_sessionIsProxyAuthEnabled( const tr_session * session ) { diff --git a/libtransmission/session.h b/libtransmission/session.h index 1e5bbf63b..ace5a8d7c 100644 --- a/libtransmission/session.h +++ b/libtransmission/session.h @@ -62,6 +62,7 @@ struct tr_handle struct tr_event_handle * events; + int proxyPort; int peerSocketTOS; int torrentCount; diff --git a/libtransmission/transmission.h b/libtransmission/transmission.h index 160d22383..b4c3fa81f 100644 --- a/libtransmission/transmission.h +++ b/libtransmission/transmission.h @@ -133,6 +133,8 @@ tr_proxy_type; /** @see tr_sessionInitFull */ #define TR_DEFAULT_PROXY NULL /** @see tr_sessionInitFull */ +#define TR_DEFAULT_PROXY_PORT 80 +/** @see tr_sessionInitFull */ #define TR_DEFAULT_PROXY_TYPE TR_PROXY_HTTP /** @see tr_sessionInitFull */ #define TR_DEFAULT_PROXY_AUTH_ENABLED 0 @@ -261,6 +263,7 @@ tr_handle * tr_sessionInitFull( const char * configDir, const char * rpcPassword, int proxyIsEnabled, const char * proxy, + int proxyPort, tr_proxy_type proxyType, int proxyAuthIsEnabled, const char * proxyUsername, @@ -427,11 +430,13 @@ void tr_sessionSetRPCCallback( tr_session * handle, int tr_sessionIsProxyEnabled ( const tr_session * ); int tr_sessionIsProxyAuthEnabled ( const tr_session * ); const char* tr_sessionGetProxy ( const tr_session * ); +int tr_sessionGetProxyPort ( const tr_session * ); tr_proxy_type tr_sessionGetProxyType ( const tr_session * ); const char* tr_sessionGetProxyPassword ( const tr_session * ); void tr_sessionSetProxyEnabled ( tr_session *, int isEnabled ); void tr_sessionSetProxyAuthEnabled ( tr_session *, int isEnabled ); void tr_sessionSetProxy ( tr_session *, const char * proxy ); +void tr_sessionSetProxyPort ( tr_session *, int port ); void tr_sessionSetProxyType ( tr_session *, tr_proxy_type ); void tr_sessionSetProxyUsername ( tr_session *, const char * username ); void tr_sessionSetProxyPassword ( tr_session *, const char * password ); diff --git a/libtransmission/web.c b/libtransmission/web.c index 0912f3612..d41f206f6 100644 --- a/libtransmission/web.c +++ b/libtransmission/web.c @@ -161,6 +161,7 @@ addTask( void * vtask ) if( !task->range && session->isProxyEnabled ) { curl_easy_setopt( ch, CURLOPT_PROXY, session->proxy ); + curl_easy_setopt( ch, CURLOPT_PROXYPORT, session->proxyPort ); curl_easy_setopt( ch, CURLOPT_PROXYTYPE, getCurlProxyType( session->proxyType ) ); curl_easy_setopt( ch, CURLOPT_PROXYAUTH, CURLAUTH_ANY ); }