#623: "transmissioncli -i" crashes. reported by anders in the forums.

This commit is contained in:
Charles Kerr 2008-01-16 16:47:58 +00:00
parent 875b98145f
commit 7c908fa11a
1 changed files with 56 additions and 45 deletions

View File

@ -31,8 +31,10 @@
#include <libtransmission/transmission.h>
#include <libtransmission/makemeta.h>
#include <libtransmission/metainfo.h> /* tr_metainfoFree */
#include <libtransmission/utils.h> /* 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; i<SHA_DIGEST_LENGTH; ++i )
printf( "%02x", info.hash[i] );
printf( "\n" );
printf( "name:\t%s\n", info.name );
for( i=0; i<info.trackerTiers; ++i ) {
int j;
printf( "tracker tier #%d:\n", ( i+1 ) );
for( j=0; j<info.trackerList[i].count; ++j ) {
const tr_tracker_info * tracker = &info.trackerList[i].list[j];
printf( "\taddress:\t%s:%d\n", tracker->address, 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; i<info.fileCount; ++i )
printf( "\t%s (%"PRIu64")\n", info.files[i].name, info.files[i].length );
tr_metainfoFree( &info );
}
tr_ctorFree( ctor );
goto cleanup;
}
tor = tr_torrentNew( h, ctor, &error );
tr_ctorFree( ctor );
if( tor == NULL )
@ -178,47 +229,6 @@ int main( int argc, char ** argv )
return EXIT_FAILURE;
}
if( showInfo )
{
const tr_info * info = tr_torrentInfo( tor );
s = tr_torrentStat( tor );
/* Print torrent info (quite à la btshowmetainfo) */
printf( "hash: " );
for( i = 0; i < SHA_DIGEST_LENGTH; i++ )
{
printf( "%02x", info->hash[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 );