From 7c908fa11ab735cd33f6b12000de79069215d4b7 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 16 Jan 2008 16:47:58 +0000 Subject: [PATCH] #623: "transmissioncli -i" crashes. reported by anders in the forums. --- cli/transmissioncli.c | 101 +++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 45 deletions(-) diff --git a/cli/transmissioncli.c b/cli/transmissioncli.c index 9eaed5a55..7f471047e 100644 --- a/cli/transmissioncli.c +++ b/cli/transmissioncli.c @@ -31,8 +31,10 @@ #include #include +#include /* tr_metainfoFree */ #include /* tr_wait */ + /* macro to shut up "unused parameter" warnings */ #ifdef __GNUC__ #define UNUSED __attribute__((unused)) @@ -74,7 +76,6 @@ static int natTraversal = 0; static int recheckData = 0; static sig_atomic_t gotsig = 0; static sig_atomic_t manualUpdate = 0; -static tr_torrent * tor; static char * finishCall = NULL; static char * announce = NULL; @@ -84,7 +85,8 @@ static char * comment = NULL; static int parseCommandLine ( int argc, char ** argv ); static void sigHandler ( int signal ); -char * getStringRatio( float ratio ) +static char * +getStringRatio( float ratio ) { static char string[20]; @@ -104,13 +106,14 @@ torrentStateChanged( tr_torrent * torrent UNUSED, system( finishCall ); } -int main( int argc, char ** argv ) +int +main( int argc, char ** argv ) { int i, error; tr_handle * h; - const tr_stat * s; tr_handle_status * hstat; tr_ctor * ctor; + tr_torrent * tor = NULL; printf( "Transmission %s - http://www.transmissionbt.com/\n", LONG_VERSION_STRING ); @@ -169,6 +172,54 @@ int main( int argc, char ** argv ) tr_ctorSetMetainfoFromFile( ctor, torrentPath ); tr_ctorSetPaused( ctor, TR_FORCE, 0 ); tr_ctorSetDestination( ctor, TR_FORCE, savePath ); + + if( showInfo ) + { + tr_info info; + + if( !tr_torrentParse( h, ctor, &info ) ) + { + printf( "hash:\t" ); + for( i=0; iaddress, tracker->port ); + printf( "\tannounce:\t%s\n", tracker->announce ); + printf( "\n" ); + } + } + + printf( "size:\t%"PRIu64" (%"PRIu64" * %d + %"PRIu64")\n", + info.totalSize, info.totalSize / info.pieceSize, + info.pieceSize, info.totalSize % info.pieceSize ); + + if( info.comment[0] ) + printf( "comment:\t%s\n", info.comment ); + if( info.creator[0] ) + printf( "creator:\t%s\n", info.creator ); + if( info.isPrivate ) + printf( "private flag set\n" ); + + printf( "file(s):\n" ); + for( i=0; ihash[i] ); - } - printf( "\n" ); - printf( "tracker: %s:%d\n", - s->tracker->address, s->tracker->port ); - printf( "announce: %s\n", s->tracker->announce ); - printf( "size: %"PRIu64" (%"PRIu64" * %d + %"PRIu64")\n", - info->totalSize, info->totalSize / info->pieceSize, - info->pieceSize, info->totalSize % info->pieceSize ); - if( info->comment[0] ) - { - printf( "comment: %s\n", info->comment ); - } - if( info->creator[0] ) - { - printf( "creator: %s\n", info->creator ); - } - if( info->isPrivate ) - { - printf( "private flag set\n" ); - } - printf( "file(s):\n" ); - for( i = 0; i < info->fileCount; i++ ) - { - printf( " %s (%"PRIu64")\n", info->files[i].name, - info->files[i].length ); - } - - goto cleanup; - } - if( showScrape ) { printf( "Scraping, Please wait...\n" ); @@ -254,6 +264,7 @@ int main( int argc, char ** argv ) { char string[LINEWIDTH]; int chars = 0; + const tr_stat * s; tr_wait( 1000 );