diff --git a/doc/rpc-spec.txt b/doc/rpc-spec.txt index 185440bde..6838ac222 100644 --- a/doc/rpc-spec.txt +++ b/doc/rpc-spec.txt @@ -321,6 +321,11 @@ "metainfo" | string base64-encoded .torrent content "paused" | 'boolean' if true, don't start the torrent "peer-limit" | number maximum number of peers + "files-wanted" | array indices of file(s) to download + "files-unwanted" | array indices of file(s) to not download + "priority-high" | array indices of high-priority file(s) + "priority-low" | array indices of low-priority file(s) + "priority-normal" | array indices of normal-priority file(s) Either "filename" OR "metainfo" MUST be included. All other arguments are optional. @@ -454,6 +459,11 @@ | | yes | torrent-set | new arg "downloadLimited" | | yes | torrent-set | new arg "uploadLimited" | | yes | torrent-set | new arg "honorsSessionLimits" + | | yes | torrent-add | new arg "files-wanted" + | | yes | torrent-add | new arg "files-unwanted" + | | yes | torrent-add | new arg "priority-high" + | | yes | torrent-add | new arg "priority-low" + | | yes | torrent-add | new arg "priority-normal" | | yes | session-get | new arg "seedRatioLimit" | | yes | session-get | new arg "seedRatioLimited" | | yes | session-get | new arg "alt-speed-enabled" diff --git a/libtransmission/rpcimpl.c b/libtransmission/rpcimpl.c index 6c926baa9..8a0a1d763 100644 --- a/libtransmission/rpcimpl.c +++ b/libtransmission/rpcimpl.c @@ -818,6 +818,24 @@ isCurlURL( const char * filename ) || ( strstr( filename, "https://" ) != NULL ); } +static tr_file_index_t* +fileListFromList( tr_benc * list, tr_file_index_t * setmeCount ) +{ + size_t i; + const size_t childCount = tr_bencListSize( list ); + tr_file_index_t n = 0; + tr_file_index_t * files = tr_new0( tr_file_index_t, childCount ); + + for( i=0; inormal; mycount = &ctor->normalSize; break; + case TR_PRI_LOW: myfiles = &ctor->low; mycount = &ctor->lowSize; break; + case TR_PRI_HIGH: myfiles = &ctor->high; mycount = &ctor->highSize; break; + } + + tr_free( *myfiles ); + *myfiles = tr_memdup( files, sizeof(tr_file_index_t)*fileCount ); + *mycount = fileCount; +} + +void +tr_ctorInitTorrentPriorities( const tr_ctor * ctor, tr_torrent * tor ) +{ + tr_file_index_t i; + + for( i=0; ilowSize; ++i ) + tr_torrentInitFilePriority( tor, ctor->low[i], TR_PRI_LOW ); + for( i=0; inormalSize; ++i ) + tr_torrentInitFilePriority( tor, ctor->normal[i], TR_PRI_NORMAL ); + for( i=0; ihighSize; ++i ) + tr_torrentInitFilePriority( tor, ctor->high[i], TR_PRI_HIGH ); +} + +void +tr_ctorSetFilesWanted( tr_ctor * ctor, + const tr_file_index_t * files, + tr_file_index_t fileCount, + tr_bool wanted ) +{ + tr_file_index_t ** myfiles = wanted ? &ctor->want : &ctor->notWant; + tr_file_index_t * mycount = wanted ? &ctor->wantSize : &ctor->notWantSize; + + tr_free( *myfiles ); + *myfiles = tr_memdup( files, sizeof(tr_file_index_t)*fileCount ); + *mycount = fileCount; +} + +void +tr_ctorInitTorrentWanted( const tr_ctor * ctor, tr_torrent * tor ) +{ + if( ctor->notWantSize ) + tr_torrentInitFileDLs( tor, ctor->notWant, ctor->notWantSize, FALSE ); + if( ctor->wantSize ) + tr_torrentInitFileDLs( tor, ctor->notWant, ctor->wantSize, TRUE ); +} + +/*** +**** +***/ + void tr_ctorSetDeleteSource( tr_ctor * ctor, tr_bool deleteSource ) @@ -322,5 +393,10 @@ tr_ctorFree( tr_ctor * ctor ) clearMetainfo( ctor ); tr_free( ctor->optionalArgs[1].downloadDir ); tr_free( ctor->optionalArgs[0].downloadDir ); + tr_free( ctor->want ); + tr_free( ctor->notWant ); + tr_free( ctor->low ); + tr_free( ctor->high ); + tr_free( ctor->normal ); tr_free( ctor ); } diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 02106cac1..9b958d755 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -581,6 +581,10 @@ torrentRealInit( tr_torrent * tor, const tr_ctor * ctor ) assert( !tor->downloadedCur ); assert( !tor->uploadedCur ); + tr_ctorInitTorrentPriorities( ctor, tor ); + + tr_ctorInitTorrentWanted( ctor, tor ); + tor->error = 0; tr_bitfieldConstruct( &tor->checkedPieces, tor->info.pieceCount ); diff --git a/libtransmission/torrent.h b/libtransmission/torrent.h index 5b555b3c6..1690b6014 100644 --- a/libtransmission/torrent.h +++ b/libtransmission/torrent.h @@ -35,6 +35,10 @@ void tr_ctorSetSave( tr_ctor * ctor, int tr_ctorGetSave( const tr_ctor * ctor ); +void tr_ctorInitTorrentPriorities( const tr_ctor * ctor, tr_torrent * tor ); + +void tr_ctorInitTorrentWanted( const tr_ctor * ctor, tr_torrent * tor ); + /** *** **/ diff --git a/libtransmission/transmission.h b/libtransmission/transmission.h index 12f8edc53..3417f7310 100644 --- a/libtransmission/transmission.h +++ b/libtransmission/transmission.h @@ -65,6 +65,15 @@ typedef uint64_t tr_block_index_t; typedef uint16_t tr_port; typedef uint8_t tr_bool; +enum +{ + TR_PRI_LOW = -1, + TR_PRI_NORMAL = 0, /* since NORMAL is 0, memset initializes nicely */ + TR_PRI_HIGH = 1 +}; + +typedef int8_t tr_priority_t; + /** * @brief returns Transmission's default configuration file directory. * @@ -792,6 +801,17 @@ void tr_ctorSetPaused( tr_ctor * ctor, tr_ctorMode mode, tr_bool isPaused ); +void tr_ctorSetFilePriorities( tr_ctor * ctor, + const tr_file_index_t * files, + tr_file_index_t fileCount, + tr_priority_t priority ); + +void tr_ctorSetFilesWanted( tr_ctor * ctor, + const tr_file_index_t * fileIndices, + tr_file_index_t fileCount, + tr_bool wanted ); + + int tr_ctorGetPeerLimit( const tr_ctor * ctor, tr_ctorMode mode, uint16_t * setmeCount ); @@ -947,14 +967,6 @@ uint16_t tr_torrentGetPeerLimit( const tr_torrent * tor ); ***** File Priorities ****/ -enum -{ - TR_PRI_LOW = -1, - TR_PRI_NORMAL = 0, /* since NORMAL is 0, memset initializes nicely */ - TR_PRI_HIGH = 1 -}; - -typedef int8_t tr_priority_t; /** * @brief Set a batch of files to a particular priority.