Skip to content

Commit

Permalink
Add setting for CURLOPT_MAXREDIRS to settings.json
Browse files Browse the repository at this point in the history
  • Loading branch information
cfpp2p committed Apr 20, 2016
1 parent ca0def7 commit 4b7bd1e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
3 changes: 3 additions & 0 deletions libtransmission/rpcimpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1785,6 +1785,8 @@ sessionSet( tr_session * session,
tr_sessionSetUserAgent( session, str );
if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_MAGNET_BAD_PIECE_MAX, &i ) )
tr_sessionSetMaxMagnetBadPiece( session, i );
if( tr_bencDictFindInt( args_in, TR_PREFS_KEY_REDIRECT_MAXIMUM, &i ) )
tr_sessionSetMaxRedirect( session, i );

notify( session, TR_RPC_SESSION_CHANGED, NULL );

Expand Down Expand Up @@ -1925,6 +1927,7 @@ sessionGet( tr_session * s,
tr_bencDictAddStr ( d, TR_PREFS_KEY_PEER_ID_PREFIX, tr_sessionGetPeerIdPrefix( s ) );
tr_bencDictAddStr ( d, TR_PREFS_KEY_USER_AGENT, tr_sessionGetUserAgent( s ) );
tr_bencDictAddInt ( d, TR_PREFS_KEY_MAGNET_BAD_PIECE_MAX, tr_sessionGetMaxMagnetBadPiece( s ) );
tr_bencDictAddInt ( d, TR_PREFS_KEY_REDIRECT_MAXIMUM, tr_sessionGetMaxRedirect( s ) );

return NULL;
}
Expand Down
25 changes: 23 additions & 2 deletions libtransmission/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ tr_sessionGetDefaultSettings( tr_benc * d )

assert( tr_bencIsDict( d ) );

tr_bencDictReserve( d, 87);
tr_bencDictReserve( d, 88);
tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, false );
tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_WEBSEEDS, false );
tr_bencDictAddBool( d, TR_PREFS_KEY_IPV6_ENABLED, false );
Expand Down Expand Up @@ -451,6 +451,7 @@ tr_sessionGetDefaultSettings( tr_benc * d )
tr_bencDictAddStr ( d, TR_PREFS_KEY_PEER_ID_PREFIX, "" );
tr_bencDictAddStr ( d, TR_PREFS_KEY_USER_AGENT, "" );
tr_bencDictAddInt ( d, TR_PREFS_KEY_MAGNET_BAD_PIECE_MAX, 25 );
tr_bencDictAddInt ( d, TR_PREFS_KEY_REDIRECT_MAXIMUM, 16 );

tr_bencDictAddStr (d, TR_PREFS_KEY_DOWNLOAD_GROUP_DEFAULT, tr_getDefaultDownloadGroupDefault ());
knownGroups = tr_getDefaultDownloadGroups ();
Expand All @@ -466,7 +467,7 @@ tr_sessionGetSettings( tr_session * s, struct tr_benc * d )

assert( tr_bencIsDict( d ) );

tr_bencDictReserve( d, 86 );
tr_bencDictReserve( d, 87 );
tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, tr_blocklistIsEnabled( s ) );
tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_WEBSEEDS, s->blockListWebseeds );
tr_bencDictAddBool( d, TR_PREFS_KEY_IPV6_ENABLED, s->ipv6Enabled );
Expand Down Expand Up @@ -549,6 +550,7 @@ tr_sessionGetSettings( tr_session * s, struct tr_benc * d )
tr_bencDictAddStr ( d, TR_PREFS_KEY_PEER_ID_PREFIX, tr_sessionGetPeerIdPrefix( s ) );
tr_bencDictAddStr ( d, TR_PREFS_KEY_USER_AGENT, tr_sessionGetUserAgent( s ) );
tr_bencDictAddInt ( d, TR_PREFS_KEY_MAGNET_BAD_PIECE_MAX, s->maxMagnetBadPiece );
tr_bencDictAddInt ( d, TR_PREFS_KEY_REDIRECT_MAXIMUM, s->maxRedirect );

tr_bencDictAddStr (d, TR_PREFS_KEY_DOWNLOAD_GROUP_DEFAULT, tr_sessionGetDownloadGroupDefault (s));
knownGroups = tr_sessionGetDownloadGroups (s);
Expand Down Expand Up @@ -941,6 +943,8 @@ sessionSetImpl( void * vdata )
tr_sessionSetPeerIdPrefix( session, str );
if( tr_bencDictFindStr( settings, TR_PREFS_KEY_USER_AGENT, &str ) )
tr_sessionSetUserAgent( session, str );
if( tr_bencDictFindInt( settings, TR_PREFS_KEY_REDIRECT_MAXIMUM, &i ) )
session->maxRedirect = ( i >= 0 ) ? i : -1 ;

if (tr_bencDictFindList (settings, TR_PREFS_KEY_DOWNLOAD_GROUPS, &groups))
{
Expand Down Expand Up @@ -3164,6 +3168,23 @@ tr_sessionSetUserAgent( tr_session * session, const char * userAgent )
}
}

void
tr_sessionSetMaxRedirect( tr_session * session, int maxRedirect )
{
assert( tr_isSession( session ) );
if( maxRedirect >= -1 )
session->maxRedirect = maxRedirect;

}

int
tr_sessionGetMaxRedirect( const tr_session * session )
{
assert( tr_isSession( session ) );

return session->maxRedirect;
}

/****
*****
****/
Expand Down
2 changes: 2 additions & 0 deletions libtransmission/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ struct tr_session
int maxWebseedConnectFails;
int webseedTimeout;

int maxRedirect;

tr_benc removedTorrents;

bool stalledEnabled;
Expand Down
4 changes: 4 additions & 0 deletions libtransmission/transmission.h
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ const char* tr_getDefaultDownloadGroupDefault (void);
#define TR_PREFS_KEY_WEBSEED_MAX_CONNECT_FAILS "webseed-max-connect-fails"
#define TR_PREFS_KEY_WEBSEED_TIMEOUT_VALUE "webseed-timeout-seconds"
#define TR_PREFS_KEY_MAGNET_BAD_PIECE_MAX "magnet-bad-piece-max"
#define TR_PREFS_KEY_REDIRECT_MAXIMUM "redirect-maximum"


/**
Expand Down Expand Up @@ -978,6 +979,9 @@ const char * tr_sessionGetUserAgent( const tr_session * );

void tr_sessionSetUserAgent( tr_session *, const char * userAgent );

void tr_sessionSetMaxRedirect( tr_session *, int maxRedirect );
int tr_sessionGetMaxRedirect( const tr_session * );

/**
***
**/
Expand Down
6 changes: 4 additions & 2 deletions libtransmission/web.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ createEasy( tr_session * s, struct tr_web * web, struct tr_web_task * task )

curl_easy_setopt( e, CURLOPT_ENCODING, "gzip;q=1.0, deflate, identity" );
curl_easy_setopt( e, CURLOPT_FOLLOWLOCATION, 1L );
curl_easy_setopt( e, CURLOPT_MAXREDIRS, -1L );
curl_easy_setopt( e, CURLOPT_MAXREDIRS, (long)s->maxRedirect );
curl_easy_setopt( e, CURLOPT_NOSIGNAL, 1L );
curl_easy_setopt( e, CURLOPT_PRIVATE, task );
#ifdef USE_LIBCURL_SOCKOPT
Expand Down Expand Up @@ -535,6 +535,7 @@ tr_webThreadFunc( void * vsession )
const char * server_ip;
struct tr_address addr;
CURL * e = msg->easy_handle;
CURLcode res = msg->data.result;
curl_easy_getinfo( e, CURLINFO_PRIVATE, (void*)&task );
curl_easy_getinfo( e, CURLINFO_RESPONSE_CODE, &task->code );

Expand Down Expand Up @@ -569,7 +570,7 @@ tr_webThreadFunc( void * vsession )


/*fprintf( stderr, "removing a completed task.. taskCount is now %d (response code: %d, response len: %d)\n", taskCount, (int)task->code, (int)evbuffer_get_length(task->response) );*/
if( progress_callback_func( task, 0, 0, 0, (double)999 ) )
if( ( progress_callback_func( task, 0, 0, 0, (double)999 ) ) || ( res == CURLE_TOO_MANY_REDIRECTS ) )
task->code = 999L;
tr_runInEventThread( task->session, task_finish_func, task );
--taskCount;
Expand Down Expand Up @@ -671,6 +672,7 @@ tr_webGetResponseStr( long code )
case 503: return "Service Unavailable";
case 504: return "Gateway Timeout";
case 505: return "HTTP Version Not Supported";
case 999: return "Too many redirects";
default: return "Unknown Error";
}
}
Expand Down

0 comments on commit 4b7bd1e

Please sign in to comment.