(trunk rpc) added "fileStats" to rpc s.t. there's a simple interface for getting all the torrent's stat fields

This commit is contained in:
Charles Kerr
2009-03-31 22:13:43 +00:00
parent 3610272c4c
commit e649e80fe5
2 changed files with 32 additions and 0 deletions

View File

@@ -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" ) )