diff --git a/cli/cli.c b/cli/cli.c index 7bf4d8d4a..375230f5d 100644 --- a/cli/cli.c +++ b/cli/cli.c @@ -269,7 +269,7 @@ main( int argc, char ** argv ) } else if( !memcmp( torrentPath, "magnet:?", 8 ) ) { tr_ctorSetMetainfoFromMagnetLink( ctor, torrentPath ); } else if( !memcmp( torrentPath, "http", 4 ) ) { - tr_webRun( h, torrentPath, NULL, onTorrentFileDownloaded, ctor ); + tr_webRun( h, torrentPath, NULL, NULL, onTorrentFileDownloaded, ctor ); waitingOnWeb = TRUE; while( waitingOnWeb ) tr_wait_msec( 1000 ); } else { diff --git a/extras/rpc-spec.txt b/extras/rpc-spec.txt index 5af65899f..7533e23b9 100644 --- a/extras/rpc-spec.txt +++ b/extras/rpc-spec.txt @@ -347,6 +347,7 @@ key | value type & description ---------------------+------------------------------------------------- + "cookies" | string pointer to a string of one or more cookies. "download-dir" | string path to download the torrent to "filename" | string filename or URL of the .torrent file "metainfo" | string base64-encoded .torrent content @@ -362,6 +363,11 @@ Either "filename" OR "metainfo" MUST be included. All other arguments are optional. + The format of the "cookies" should be NAME=CONTENTS, where NAME is the + cookie name and CONTENTS is what the cookie should contain. + Set multiple cookies like this: "name1=content1; name2=content2;" etc. + + Response arguments: on success, a "torrent-added" object in the form of one of 3.3's tr_info objects with the fields for id, name, and hashString. @@ -655,4 +661,5 @@ | | yes | session-close | new method ------+---------+-----------+----------------+------------------------------- 13 | 2.30 | yes | session-get | new arg "isUTP" to the "peers" list + | | yes | torrent-add | new arg "cookies" | | NO | torrent-get | removed arg "peersKnown" diff --git a/gtk/favicon.c b/gtk/favicon.c index 470c6d784..a01241a0e 100644 --- a/gtk/favicon.c +++ b/gtk/favicon.c @@ -111,7 +111,7 @@ favicon_web_done_idle_cb( gpointer vfav ) fav->contents = NULL; fav->len = 0; - tr_webRun( fav->session, url, NULL, favicon_web_done_cb, fav ); + tr_webRun( fav->session, url, NULL, NULL, favicon_web_done_cb, fav ); g_free( url ); } } @@ -167,7 +167,7 @@ gtr_get_favicon( tr_session * session, data->host = g_strdup( host ); data->type = 0; - tr_webRun( session, url, NULL, favicon_web_done_cb, data ); + tr_webRun( session, url, NULL, NULL, favicon_web_done_cb, data ); g_free( url ); } } diff --git a/gtk/tr-core.c b/gtk/tr-core.c index c155b0e65..afc0d4cce 100644 --- a/gtk/tr-core.c +++ b/gtk/tr-core.c @@ -1194,7 +1194,7 @@ gtr_core_add_from_url( TrCore * core, const char * url ) data->core = core; data->url = g_strdup( url ); core_inc_busy( data->core ); - tr_webRun( session, url, NULL, on_url_done, data ); + tr_webRun( session, url, NULL, NULL, on_url_done, data ); } } diff --git a/libtransmission/announcer-http.c b/libtransmission/announcer-http.c index d8242aab1..d787e8036 100644 --- a/libtransmission/announcer-http.c +++ b/libtransmission/announcer-http.c @@ -289,7 +289,7 @@ tr_tracker_http_announce( tr_session * session, tr_strlcpy( d->log_name, request->log_name, sizeof( d->log_name ) ); dbgmsg( request->log_name, "Sending announce to libcurl: \"%s\"", url ); - tr_webRun( session, url, NULL, on_announce_done, d ); + tr_webRun( session, url, NULL, NULL, on_announce_done, d ); tr_free( url ); } @@ -443,6 +443,6 @@ tr_tracker_http_scrape( tr_session * session, tr_strlcpy( d->log_name, request->log_name, sizeof( d->log_name ) ); dbgmsg( request->log_name, "Sending scrape to libcurl: \"%s\"", url ); - tr_webRun( session, url, NULL, on_scrape_done, d ); + tr_webRun( session, url, NULL, NULL, on_scrape_done, d ); tr_free( url ); } diff --git a/libtransmission/rpcimpl.c b/libtransmission/rpcimpl.c index f6b28dbcf..c0d5f3217 100644 --- a/libtransmission/rpcimpl.c +++ b/libtransmission/rpcimpl.c @@ -1099,7 +1099,7 @@ portTest( tr_session * session, { const int port = tr_sessionGetPeerPort( session ); char * url = tr_strdup_printf( "http://portcheck.transmissionbt.com/%d", port ); - tr_webRun( session, url, NULL, portTested, idle_data ); + tr_webRun( session, url, NULL, NULL, portTested, idle_data ); tr_free( url ); return NULL; } @@ -1205,7 +1205,7 @@ blocklistUpdate( tr_session * session, tr_benc * args_out UNUSED, struct tr_rpc_idle_data * idle_data ) { - tr_webRun( session, session->blocklist_url, NULL, gotNewBlocklist, idle_data ); + tr_webRun( session, session->blocklist_url, NULL, NULL, gotNewBlocklist, idle_data ); return NULL; } @@ -1330,12 +1330,15 @@ torrentAdd( tr_session * session, { int64_t i; tr_bool boolVal; - const char * str; tr_benc * l; + const char * str; + const char * cookies = NULL; tr_ctor * ctor = tr_ctorNew( session ); /* set the optional arguments */ + tr_bencDictFindStr( args_in, "cookies", &cookies ); + if( tr_bencDictFindStr( args_in, TR_PREFS_KEY_DOWNLOAD_DIR, &str ) ) tr_ctorSetDownloadDir( ctor, TR_FORCE, str ); @@ -1387,7 +1390,7 @@ torrentAdd( tr_session * session, struct add_torrent_idle_data * d = tr_new0( struct add_torrent_idle_data, 1 ); d->data = idle_data; d->ctor = ctor; - tr_webRun( session, filename, NULL, gotMetadataFromURL, d ); + tr_webRun( session, filename, NULL, cookies, gotMetadataFromURL, d ); } else { diff --git a/libtransmission/torrent-ctor.c b/libtransmission/torrent-ctor.c index e37580ec4..3a09a5f74 100644 --- a/libtransmission/torrent-ctor.c +++ b/libtransmission/torrent-ctor.c @@ -46,6 +46,7 @@ struct tr_ctor struct optional_args optionalArgs[2]; + char * cookies; char * incompleteDir; tr_file_index_t * want; diff --git a/libtransmission/web.c b/libtransmission/web.c index 527a192e8..15f045d86 100644 --- a/libtransmission/web.c +++ b/libtransmission/web.c @@ -79,6 +79,7 @@ struct tr_web_task struct evbuffer * freebuf; char * url; char * range; + char * cookies; tr_session * session; tr_web_done_func * done_func; void * done_func_user_data; @@ -89,6 +90,7 @@ task_free( struct tr_web_task * task ) { if( task->freebuf ) evbuffer_free( task->freebuf ); + tr_free( task->cookies ); tr_free( task->range ); tr_free( task->url ); tr_free( task ); @@ -180,6 +182,9 @@ createEasy( tr_session * s, struct tr_web_task * task ) else if ((( addr = tr_sessionGetPublicAddress( s, TR_AF_INET6, &is_default_value ))) && !is_default_value ) curl_easy_setopt( e, CURLOPT_INTERFACE, tr_ntop_non_ts( addr ) ); + if( task->cookies != NULL ) + curl_easy_setopt( e, CURLOPT_COOKIE, task->cookies ); + if( task->range ) curl_easy_setopt( e, CURLOPT_RANGE, task->range ); @@ -220,10 +225,11 @@ void tr_webRun( tr_session * session, const char * url, const char * range, + const char * cookies, tr_web_done_func done_func, void * done_func_user_data ) { - tr_webRunWithBuffer( session, url, range, + tr_webRunWithBuffer( session, url, range, cookies, done_func, done_func_user_data, NULL ); } @@ -232,6 +238,7 @@ void tr_webRunWithBuffer( tr_session * session, const char * url, const char * range, + const char * cookies, tr_web_done_func done_func, void * done_func_user_data, struct evbuffer * buffer ) @@ -245,6 +252,7 @@ tr_webRunWithBuffer( tr_session * session, task->session = session; task->url = tr_strdup( url ); task->range = tr_strdup( range ); + task->cookies = tr_strdup( cookies); task->done_func = done_func; task->done_func_user_data = done_func_user_data; task->response = buffer ? buffer : evbuffer_new( ); diff --git a/libtransmission/web.h b/libtransmission/web.h index a86ebff66..9915f6594 100644 --- a/libtransmission/web.h +++ b/libtransmission/web.h @@ -55,6 +55,7 @@ const char * tr_webGetResponseStr( long response_code ); void tr_webRun( tr_session * session, const char * url, const char * range, + const char * cookies, tr_web_done_func done_func, void * done_func_user_data ); @@ -63,6 +64,7 @@ struct evbuffer; void tr_webRunWithBuffer( tr_session * session, const char * url, const char * range, + const char * cookies, tr_web_done_func done_func, void * done_func_user_data, struct evbuffer * buffer ); diff --git a/libtransmission/webseed.c b/libtransmission/webseed.c index d73397d80..64f9c41ad 100644 --- a/libtransmission/webseed.c +++ b/libtransmission/webseed.c @@ -290,7 +290,7 @@ task_request_next_chunk( struct tr_webseed_task * t ) url = make_url( t->webseed, file ); tr_snprintf( range, sizeof range, "%"PRIu64"-%"PRIu64, file_offset, file_offset + this_pass - 1 ); - tr_webRunWithBuffer( t->session, url, range, + tr_webRunWithBuffer( t->session, url, range, NULL, web_response_func, t, t->content ); tr_free( url ); }