From e649e80fe5e6b3a04a673d4e54c591f5a594d00f Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 31 Mar 2009 22:13:43 +0000 Subject: [PATCH] (trunk rpc) added "fileStats" to rpc s.t. there's a simple interface for getting all the torrent's stat fields --- doc/rpc-spec.txt | 10 ++++++++++ libtransmission/rpcimpl.c | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/doc/rpc-spec.txt b/doc/rpc-spec.txt index bd5464c66..185440bde 100644 --- a/doc/rpc-spec.txt +++ b/doc/rpc-spec.txt @@ -153,6 +153,7 @@ errorString | number | tr_stat eta | number | tr_stat files | array (see below) | n/a + fileStats | array (see below) | n/a hashString | string | tr_info haveUnchecked | number | tr_stat haveValid | number | tr_stat @@ -213,6 +214,14 @@ | length | number | tr_info | name | string | tr_info -----------------------+--------------------------------------+ + fileStats | a file's non-constant properties. | + | array of tr_info.filecount objects, | + | each containing: | + +-------------------------+------------+ + | bytesCompleted | number | tr_torrent + | wanted | 'boolean' | tr_info + | priority | number | tr_info + -----------------------+--------------------------------------+ peers | array of objects, each containing: | +-------------------------+------------+ | address | string | tr_peer_stat @@ -440,6 +449,7 @@ | | yes | torrent-get | new arg "downloadDir" ------+---------+-----------+----------------+------------------------------- 6 | 1.60 | yes | torrent-get | new arg "pieces" + | | yes | torrent-get | new arg "fileStats" | | yes | torrent-set | new arg "ratio" | | yes | torrent-set | new arg "downloadLimited" | | yes | torrent-set | new arg "uploadLimited" diff --git a/libtransmission/rpcimpl.c b/libtransmission/rpcimpl.c index e6165bb30..41e10db5f 100644 --- a/libtransmission/rpcimpl.c +++ b/libtransmission/rpcimpl.c @@ -288,6 +288,26 @@ torrentVerify( tr_session * session, **** ***/ +static void +addFileStats( const tr_torrent * tor, tr_benc * list ) +{ + tr_file_index_t i; + tr_file_index_t n; + const tr_info * info = tr_torrentInfo( tor ); + tr_file_stat * files = tr_torrentFiles( tor, &n ); + + for( i = 0; i < info->fileCount; ++i ) + { + const tr_file * file = &info->files[i]; + tr_benc * d = tr_bencListAddDict( list, 3 ); + tr_bencDictAddInt( d, "bytesCompleted", files[i].bytesCompleted ); + tr_bencDictAddInt( d, "priority", file->priority ); + tr_bencDictAddBool( d, "wanted", !file->dnd ); + } + + tr_torrentFilesFree( files, n ); +} + static void addFiles( const tr_torrent * tor, tr_benc * list ) @@ -415,6 +435,8 @@ addField( const tr_torrent * tor, tr_bencDictAddInt( d, key, st->eta ); else if( !strcmp( key, "files" ) ) addFiles( tor, tr_bencDictAddList( d, key, inf->fileCount ) ); + else if( !strcmp( key, "fileStats" ) ) + addFileStats( tor, tr_bencDictAddList( d, key, inf->fileCount ) ); else if( !strcmp( key, "hashString" ) ) tr_bencDictAddStr( d, key, tor->info.hashString ); else if( !strcmp( key, "haveUnchecked" ) )