wire up the backend proxy support.

This commit is contained in:
Charles Kerr 2008-06-10 16:16:31 +00:00
parent b7ab0132e7
commit b94893a4c9
7 changed files with 254 additions and 104 deletions

View File

@ -179,7 +179,12 @@ main( int argc, char ** argv )
TR_DEFAULT_RPC_ENABLED,
TR_DEFAULT_RPC_PORT,
TR_DEFAULT_RPC_ACL,
FALSE, "fnord", "potzrebie" );
FALSE, "fnord", "potzrebie",
TR_DEFAULT_PROXY_ENABLED,
TR_DEFAULT_PROXY,
TR_DEFAULT_PROXY_AUTH_ENABLED,
TR_DEFAULT_PROXY_USERNAME,
TR_DEFAULT_PROXY_PASSWORD );
if( sourceFile && *sourceFile ) /* creating a torrent */
{

View File

@ -179,7 +179,13 @@ session_init( const char * configDir, int rpc_port,
FALSE, /* is the blocklist enabled? */
TR_DEFAULT_PEER_SOCKET_TOS,
TRUE, rpc_port, acl,
auth_required, user, pass );
auth_required, user, pass,
TR_DEFAULT_PROXY_ENABLED,
TR_DEFAULT_PROXY,
TR_DEFAULT_PROXY_AUTH_ENABLED,
TR_DEFAULT_PROXY_USERNAME,
TR_DEFAULT_PROXY_PASSWORD );
if( auth_required )
tr_ninf( MY_NAME, "requiring authentication" );

View File

@ -431,7 +431,13 @@ main( int argc, char ** argv )
pref_string_get( PREF_KEY_RPC_ACL ),
pref_flag_get( PREF_KEY_RPC_AUTH_ENABLED ),
pref_string_get( PREF_KEY_RPC_USERNAME ),
pref_string_get( PREF_KEY_RPC_PASSWORD ) );
pref_string_get( PREF_KEY_RPC_PASSWORD ),
pref_flag_get( PREF_KEY_PROXY_SERVER_ENABLED ),
pref_string_get( PREF_KEY_PROXY_SERVER ),
pref_flag_get( PREF_KEY_PROXY_AUTH_ENABLED ),
pref_string_get( PREF_KEY_PROXY_USERNAME ),
pref_string_get( PREF_KEY_PROXY_PASSWORD ) );
cbdata->core = tr_core_new( h );
/* create main window now to be a parent to any error dialogs */
@ -969,23 +975,31 @@ prefschanged( TrCore * core UNUSED, const char * key, gpointer data )
}
else if( !strcmp( key, PREF_KEY_PROXY_SERVER ) )
{
g_message( "FIXME" );
char * s = pref_string_get( key );
tr_sessionSetProxy( tr, s );
g_free( s );
}
else if( !strcmp( key, PREF_KEY_PROXY_SERVER_ENABLED ) )
{
g_message( "FIXME" );
const gboolean enabled = pref_flag_get( key );
tr_sessionSetProxyEnabled( tr, enabled );
}
else if( !strcmp( key, PREF_KEY_PROXY_AUTH_ENABLED ) )
{
g_message( "FIXME" );
const gboolean enabled = pref_flag_get( key );
tr_sessionSetProxyAuthEnabled( tr, enabled );
}
else if( !strcmp( key, PREF_KEY_PROXY_USERNAME ) )
{
g_message( "FIXME" );
char * s = pref_string_get( key );
tr_sessionSetProxyUsername( tr, s );
g_free( s );
}
else if( !strcmp( key, PREF_KEY_PROXY_PASSWORD ) )
{
g_message( "FIXME" );
char * s = pref_string_get( key );
tr_sessionSetProxyPassword( tr, s );
g_free( s );
}
}

View File

@ -119,28 +119,33 @@ tr_sessionSetEncryption( tr_session * session, tr_encryption_mode mode )
static void metainfoLookupRescan( tr_handle * h );
tr_handle *
tr_sessionInitFull( const char * configDir,
const char * downloadDir,
const char * tag,
int isPexEnabled,
int isPortForwardingEnabled,
int publicPort,
int encryptionMode,
int isUploadLimitEnabled,
int uploadLimit,
int isDownloadLimitEnabled,
int downloadLimit,
int globalPeerLimit,
int messageLevel,
int isMessageQueueingEnabled,
int isBlocklistEnabled,
int peerSocketTOS,
int rpcIsEnabled,
int rpcPort,
const char * rpcACL,
int rpcPasswordIsEnabled,
const char * rpcUsername,
const char * rpcPassword )
tr_sessionInitFull( const char * configDir,
const char * downloadDir,
const char * tag,
int isPexEnabled,
int isPortForwardingEnabled,
int publicPort,
int encryptionMode,
int isUploadLimitEnabled,
int uploadLimit,
int isDownloadLimitEnabled,
int downloadLimit,
int globalPeerLimit,
int messageLevel,
int isMessageQueueingEnabled,
int isBlocklistEnabled,
int peerSocketTOS,
int rpcIsEnabled,
int rpcPort,
const char * rpcACL,
int rpcAuthIsEnabled,
const char * rpcUsername,
const char * rpcPassword,
int proxyIsEnabled,
const char * proxy,
int proxyAuthIsEnabled,
const char * proxyUsername,
const char * proxyPassword )
{
tr_handle * h;
char filename[MAX_PATH_LENGTH];
@ -163,6 +168,11 @@ tr_sessionInitFull( const char * configDir,
h->encryptionMode = encryptionMode;
h->peerSocketTOS = peerSocketTOS;
h->downloadDir = tr_strdup( downloadDir );
h->isProxyEnabled = proxyIsEnabled ? 1 : 0;
h->proxy = tr_strdup( proxy );
h->isProxyAuthEnabled = proxyAuthIsEnabled ? 1 : 0;
h->proxyUsername = tr_strdup( proxyUsername );
h->proxyPassword = tr_strdup( proxyPassword );
tr_setConfigDir( h, configDir );
@ -203,7 +213,7 @@ tr_sessionInitFull( const char * configDir,
h->web = tr_webInit( h );
h->rpcServer = tr_rpcInit( h, rpcIsEnabled, rpcPort, rpcACL,
rpcPasswordIsEnabled, rpcUsername, rpcPassword );
rpcAuthIsEnabled, rpcUsername, rpcPassword );
metainfoLookupRescan( h );
@ -236,7 +246,13 @@ tr_sessionInit( const char * configDir,
TR_DEFAULT_RPC_ACL,
FALSE,
"fnord",
"potzrebie" );
"potzrebie",
TR_DEFAULT_PROXY_ENABLED,
TR_DEFAULT_PROXY,
TR_DEFAULT_PROXY_AUTH_ENABLED,
TR_DEFAULT_PROXY_USERNAME,
TR_DEFAULT_PROXY_PASSWORD );
}
/***
@ -487,6 +503,9 @@ tr_sessionClose( tr_handle * h )
tr_free( h->resumeDir );
tr_free( h->torrentDir );
tr_free( h->downloadDir );
tr_free( h->proxy );
tr_free( h->proxyUsername );
tr_free( h->proxyPassword );
free( h );
}
@ -754,88 +773,146 @@ tr_torrentNext( tr_handle * session, tr_torrent * tor )
***/
void
tr_sessionSetRPCEnabled( tr_handle * session, int isEnabled )
tr_sessionSetRPCEnabled( tr_session * session, int isEnabled )
{
tr_rpcSetEnabled( session->rpcServer, isEnabled );
}
int
tr_sessionIsRPCEnabled( const tr_handle * session )
tr_sessionIsRPCEnabled( const tr_session * session )
{
return tr_rpcIsEnabled( session->rpcServer );
}
void
tr_sessionSetRPCPort( tr_handle * session, int port )
tr_sessionSetRPCPort( tr_session * session, int port )
{
tr_rpcSetPort( session->rpcServer, port );
}
int
tr_sessionGetRPCPort( const tr_handle * session )
tr_sessionGetRPCPort( const tr_session * session )
{
return tr_rpcGetPort( session->rpcServer );
}
void
tr_sessionSetRPCCallback( tr_handle * session,
tr_sessionSetRPCCallback( tr_session * session,
tr_rpc_func func,
void * user_data )
{
session->rpc_func = func;
session->rpc_func_user_data = user_data;
}
int
tr_sessionTestRPCACL( const tr_handle * session,
tr_sessionTestRPCACL( const tr_session * session,
const char * acl,
char ** allocme_errmsg )
{
return tr_rpcTestACL( session->rpcServer, acl, allocme_errmsg );
}
int
tr_sessionSetRPCACL( tr_handle * session,
tr_sessionSetRPCACL( tr_session * session,
const char * acl,
char ** allocme_errmsg )
{
return tr_rpcSetACL( session->rpcServer, acl, allocme_errmsg );
}
char*
tr_sessionGetRPCACL( const tr_session * session )
{
return tr_rpcGetACL( session->rpcServer );
}
void
tr_sessionSetRPCPassword( tr_handle * session, const char * password )
tr_sessionSetRPCPassword( tr_session * session, const char * password )
{
tr_rpcSetPassword( session->rpcServer, password );
}
char*
tr_sessionGetRPCPassword( const tr_handle * session )
tr_sessionGetRPCPassword( const tr_session * session )
{
return tr_rpcGetPassword( session->rpcServer );
}
void
tr_sessionSetRPCUsername( tr_handle * session, const char * username )
tr_sessionSetRPCUsername( tr_session * session, const char * username )
{
tr_rpcSetUsername( session->rpcServer, username );
}
char*
tr_sessionGetRPCUsername( const tr_handle * session )
tr_sessionGetRPCUsername( const tr_session * session )
{
return tr_rpcGetUsername( session->rpcServer );
}
void
tr_sessionSetRPCPasswordEnabled( tr_handle * session, int isEnabled )
tr_sessionSetRPCPasswordEnabled( tr_session * session, int isEnabled )
{
tr_rpcSetPasswordEnabled( session->rpcServer, isEnabled );
}
int
tr_sessionIsRPCPasswordEnabled( const tr_handle * session )
tr_sessionIsRPCPasswordEnabled( const tr_session * session )
{
return tr_rpcIsPasswordEnabled( session->rpcServer );
}
/***
****
***/
int
tr_sessionIsProxyEnabled( const tr_session * session )
{
return session->isProxyEnabled;
}
void
tr_sessionSetProxyEnabled( tr_session * session, int isEnabled )
{
session->isProxyEnabled = isEnabled ? 1 : 0;
}
const char*
tr_sessionGetProxy( const tr_session * session )
{
return session->proxy;
}
void
tr_sessionSetProxy( tr_session * session, const char * proxy )
{
if( proxy != session->proxy )
{
tr_free( session->proxy );
session->proxy = tr_strdup( proxy );
}
}
int
tr_sessionIsProxyAuthEnabled( const tr_session * session )
{
return session->isProxyAuthEnabled;
}
void
tr_sessionSetProxyAuthEnabled( tr_session * session, int isEnabled )
{
session->isProxyAuthEnabled = isEnabled ? 1 : 0;
}
const char*
tr_sessionGetProxyUsername( const tr_session * session )
{
return session->proxyUsername;
}
void
tr_sessionSetProxyUsername( tr_session * session, const char * username )
{
if( username != session->proxyUsername )
{
tr_free( session->proxyUsername );
session->proxyUsername = tr_strdup( username );
}
}
const char*
tr_sessionGetProxyPassword( const tr_session * session )
{
return session->proxyPassword;
}
void
tr_sessionSetProxyPassword( tr_session * session, const char * password )
{
if( password != session->proxyPassword )
{
tr_free( session->proxyPassword );
session->proxyPassword = tr_strdup( password );
}
}

View File

@ -49,11 +49,13 @@ struct tr_metainfo_lookup
struct tr_handle
{
unsigned int isPortSet : 1;
unsigned int isPexEnabled : 1;
unsigned int isClosed : 1;
unsigned int useUploadLimit : 1;
unsigned int useDownloadLimit : 1;
unsigned int isPortSet : 1;
unsigned int isPexEnabled : 1;
unsigned int isProxyEnabled : 1;
unsigned int isProxyAuthEnabled : 1;
unsigned int isClosed : 1;
unsigned int useUploadLimit : 1;
unsigned int useDownloadLimit : 1;
tr_encryption_mode encryptionMode;
@ -71,6 +73,10 @@ struct tr_handle
char * resumeDir;
char * torrentDir;
char * proxy;
char * proxyUsername;
char * proxyPassword;
struct tr_ratecontrol * upload;
struct tr_ratecontrol * download;
@ -93,8 +99,6 @@ struct tr_handle
int metainfoLookupCount;
};
typedef struct tr_handle tr_session;
const char * tr_sessionFindTorrentFile( const tr_session * session,
const char * hashString );

View File

@ -80,6 +80,7 @@ typedef struct tr_ctor tr_ctor;
typedef struct tr_handle tr_handle;
typedef struct tr_info tr_info;
typedef struct tr_torrent tr_torrent;
typedef tr_handle tr_session;
/**
@ -115,6 +116,17 @@ typedef struct tr_torrent tr_torrent;
#define TR_DEFAULT_RPC_PORT_STR "9091"
/** @see tr_sessionInitFull */
#define TR_DEFAULT_RPC_ACL "+127.0.0.1"
/** @see tr_sessionInitFull */
#define TR_DEFAULT_PROXY_ENABLED 0
/** @see tr_sessionInitFull */
#define TR_DEFAULT_PROXY NULL
/** @see tr_sessionInitFull */
#define TR_DEFAULT_PROXY_AUTH_ENABLED 0
/** @see tr_sessionInitFull */
#define TR_DEFAULT_PROXY_USERNAME NULL
/** @see tr_sessionInitFull */
#define TR_DEFAULT_PROXY_PASSWORD NULL
/**
* @brief Start a libtransmission session.
@ -211,28 +223,34 @@ typedef struct tr_torrent tr_torrent;
* @see TR_DEFAULT_RPC_ACL
* @see tr_sessionClose()
*/
tr_handle * tr_sessionInitFull( const char * configDir,
const char * downloadDir,
const char * tag,
int isPexEnabled,
int isPortForwardingEnabled,
int publicPort,
int encryptionMode,
int isUploadLimitEnabled,
int uploadLimit,
int isDownloadLimitEnabled,
int downloadLimit,
int peerLimit,
int messageLevel,
int isMessageQueueingEnabled,
int isBlocklistEnabled,
int peerSocketTOS,
int rpcIsEnabled,
int rpcPort,
const char * rpcAccessControlList,
int rpcPasswordIsEnabled,
const char * rpcUsername,
const char * rpcPassword );
tr_handle * tr_sessionInitFull( const char * configDir,
const char * downloadDir,
const char * tag,
int isPexEnabled,
int isPortForwardingEnabled,
int publicPort,
int encryptionMode,
int isUploadLimitEnabled,
int uploadLimit,
int isDownloadLimitEnabled,
int downloadLimit,
int peerLimit,
int messageLevel,
int isMessageQueueingEnabled,
int isBlocklistEnabled,
int peerSocketTOS,
int rpcIsEnabled,
int rpcPort,
const char * rpcAccessControlList,
int rpcPasswordIsEnabled,
const char * rpcUsername,
const char * rpcPassword,
int proxyIsEnabled,
const char * proxy,
int proxyAuthIsEnabled,
const char * proxyUsername,
const char * proxyPassword );
/** @brief Shorter form of tr_sessionInitFull()
@deprecated Use tr_sessionInitFull() instead. */
@ -337,7 +355,7 @@ int tr_sessionTestRPCACL( const tr_handle * session,
* @see tr_sessionInitFull
* @see tr_sessionGetRPCACL
*/
int tr_sessionSetRPCACL( tr_handle * session,
int tr_sessionSetRPCACL( tr_session * session,
const char * acl,
char ** allocme_errmsg );
@ -345,26 +363,26 @@ int tr_sessionSetRPCACL( tr_handle * session,
@return a comma-separated string of ACL rules. tr_free() when done.
@see tr_sessionInitFull
@see tr_sessionSetRPCACL */
char* tr_sessionGetRPCACL( const tr_handle * );
char* tr_sessionGetRPCACL( const tr_session * );
void tr_sessionSetRPCPassword( tr_handle * session,
const char * password );
void tr_sessionSetRPCPassword( tr_session * session,
const char * password );
void tr_sessionSetRPCUsername( tr_handle * session,
const char * username );
void tr_sessionSetRPCUsername( tr_session * session,
const char * username );
/** @brief get the password used to restrict RPC requests.
@return the password string. tr_free() when done.
@see tr_sessionInitFull()
@see tr_sessionSetRPCPassword() */
char* tr_sessionGetRPCPassword( const tr_handle * session );
char* tr_sessionGetRPCPassword( const tr_session * session );
char* tr_sessionGetRPCUsername( const tr_handle * session );
char* tr_sessionGetRPCUsername( const tr_session * session );
void tr_sessionSetRPCPasswordEnabled( tr_handle * session,
void tr_sessionSetRPCPasswordEnabled( tr_session * session,
int isEnabled );
int tr_sessionIsRPCPasswordEnabled( const tr_handle * session );
int tr_sessionIsRPCPasswordEnabled( const tr_session * session );
typedef enum
@ -378,15 +396,29 @@ typedef enum
}
tr_rpc_callback_type;
typedef void ( *tr_rpc_func )( tr_handle * handle,
typedef void ( *tr_rpc_func )( tr_session * handle,
tr_rpc_callback_type type,
struct tr_torrent * tor_or_null,
void * user_data );
void tr_sessionSetRPCCallback( tr_handle * handle,
void tr_sessionSetRPCCallback( tr_session * handle,
tr_rpc_func func,
void * user_data );
/**
***
**/
int tr_sessionIsProxyEnabled ( const tr_session * );
int tr_sessionIsProxyAuthEnabled ( const tr_session * );
const char* tr_sessionGetProxy ( const tr_session * );
const char* tr_sessionGetProxyUsername ( 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_sessionSetProxyUsername ( tr_session *, const char * username );
void tr_sessionSetProxyPassword ( tr_session *, const char * password );
/**
***
@ -404,23 +436,23 @@ typedef struct tr_session_stats
tr_session_stats;
/* stats from the current session. */
void tr_sessionGetStats( const tr_handle * handle,
void tr_sessionGetStats( const tr_session * session,
tr_session_stats * setme );
/* stats from the current and past sessions. */
void tr_sessionGetCumulativeStats( const tr_handle * handle,
void tr_sessionGetCumulativeStats( const tr_session * session,
tr_session_stats * setme );
void tr_sessionClearStats( tr_handle * handle );
void tr_sessionClearStats( tr_session * session );
/**
* Set whether or not torrents are allowed to do peer exchanges.
* PEX is always disabled in private torrents regardless of this.
* In public torrents, PEX is enabled by default.
*/
void tr_sessionSetPexEnabled( tr_handle *, int isEnabled );
void tr_sessionSetPexEnabled( tr_session *, int isEnabled );
int tr_sessionIsPexEnabled( const tr_handle * );
int tr_sessionIsPexEnabled( const tr_session * );
typedef enum
{
@ -430,9 +462,9 @@ typedef enum
}
tr_encryption_mode;
tr_encryption_mode tr_sessionGetEncryption( tr_handle * handle );
tr_encryption_mode tr_sessionGetEncryption( tr_session * );
void tr_sessionSetEncryption( tr_handle * handle, tr_encryption_mode mode );
void tr_sessionSetEncryption( tr_session *, tr_encryption_mode mode );
/***********************************************************************

View File

@ -132,10 +132,11 @@ static void
addTask( void * vtask )
{
struct tr_web_task * task = vtask;
const tr_handle * session = task->session;
if( task->session && task->session->web )
if( session && session->web )
{
struct tr_web * web = task->session->web;
struct tr_web * web = session->web;
CURL * ch;
ensureTimerIsRunning( web );
@ -144,6 +145,17 @@ addTask( void * vtask )
dbgmsg( "adding task #%lu [%s] (%d remain)", task->tag, task->url, web->remain );
ch = curl_easy_init( );
if( !task->range && session->isProxyEnabled ) {
curl_easy_setopt( ch, CURLOPT_PROXY, session->proxy );
curl_easy_setopt( ch, CURLOPT_PROXYAUTH, CURLAUTH_ANY );
}
if( !task->range && session->isProxyAuthEnabled ) {
char * str = tr_strdup_printf( "%s:%s", session->proxyUsername, session->proxyPassword );
curl_easy_setopt( ch, CURLOPT_PROXYUSERPWD, str );
tr_free( str );
}
curl_easy_setopt( ch, CURLOPT_PRIVATE, task );
curl_easy_setopt( ch, CURLOPT_URL, task->url );
curl_easy_setopt( ch, CURLOPT_WRITEFUNCTION, writeFunc );