From: Jordan Lee <jordan@transmissionbt.com> Date: Tue, 22 Mar 2011 15:19:54 +0000 (+0000) Subject: (trunk) #4138 "use stdbool.h instead of tr_bool" -- done. X-Git-Tag: 2.30b1~82 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b4d36aeb5417d8f07a6e3a6562402f8f0d06c475;p=transmission (trunk) #4138 "use stdbool.h instead of tr_bool" -- done. --- diff --git a/cli/cli.c b/cli/cli.c index 375230f5d..9686738fb 100644 --- a/cli/cli.c +++ b/cli/cli.c @@ -67,8 +67,8 @@ #define MY_CONFIG_NAME "transmission" #define MY_READABLE_NAME "transmission-cli" -static tr_bool showVersion = FALSE; -static tr_bool verify = 0; +static bool showVersion = false; +static bool verify = 0; static sig_atomic_t gotsig = 0; static sig_atomic_t manualUpdate = 0; @@ -127,19 +127,19 @@ tr_strlratio( char * buf, return buf; } -static tr_bool waitingOnWeb; +static bool waitingOnWeb; static void onTorrentFileDownloaded( tr_session * session UNUSED, - tr_bool did_connect UNUSED, - tr_bool did_timeout UNUSED, + bool did_connect UNUSED, + bool did_timeout UNUSED, long response_code UNUSED, const void * response, size_t response_byte_count, void * ctor ) { tr_ctorSetMetainfo( ctor, response, response_byte_count ); - waitingOnWeb = FALSE; + waitingOnWeb = false; } static void @@ -258,19 +258,19 @@ main( int argc, char ** argv ) return EXIT_FAILURE; } - h = tr_sessionInit( "cli", configDir, FALSE, &settings ); + h = tr_sessionInit( "cli", configDir, false, &settings ); ctor = tr_ctorNew( h ); fileContents = tr_loadFile( torrentPath, &fileLength ); - tr_ctorSetPaused( ctor, TR_FORCE, FALSE ); + tr_ctorSetPaused( ctor, TR_FORCE, false ); if( fileContents != NULL ) { tr_ctorSetMetainfo( ctor, fileContents, fileLength ); } else if( !memcmp( torrentPath, "magnet:?", 8 ) ) { tr_ctorSetMetainfoFromMagnetLink( ctor, torrentPath ); } else if( !memcmp( torrentPath, "http", 4 ) ) { tr_webRun( h, torrentPath, NULL, NULL, onTorrentFileDownloaded, ctor ); - waitingOnWeb = TRUE; + waitingOnWeb = true; while( waitingOnWeb ) tr_wait_msec( 1000 ); } else { fprintf( stderr, "ERROR: Unrecognized torrent \"%s\".\n", torrentPath ); @@ -369,36 +369,36 @@ parseCommandLine( tr_benc * d, int argc, const char ** argv ) { switch( c ) { - case 'b': tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, TRUE ); + case 'b': tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, true ); break; - case 'B': tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, FALSE ); + case 'B': tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, false ); break; case 'd': tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED_KBps, atoi( optarg ) ); - tr_bencDictAddBool( d, TR_PREFS_KEY_DSPEED_ENABLED, TRUE ); + tr_bencDictAddBool( d, TR_PREFS_KEY_DSPEED_ENABLED, true ); break; - case 'D': tr_bencDictAddBool( d, TR_PREFS_KEY_DSPEED_ENABLED, FALSE ); + case 'D': tr_bencDictAddBool( d, TR_PREFS_KEY_DSPEED_ENABLED, false ); break; case 'f': tr_bencDictAddStr( d, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_FILENAME, optarg ); - tr_bencDictAddBool( d, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, TRUE ); + tr_bencDictAddBool( d, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, true ); break; case 'g': /* handled above */ break; - case 'm': tr_bencDictAddBool( d, TR_PREFS_KEY_PORT_FORWARDING, TRUE ); + case 'm': tr_bencDictAddBool( d, TR_PREFS_KEY_PORT_FORWARDING, true ); break; - case 'M': tr_bencDictAddBool( d, TR_PREFS_KEY_PORT_FORWARDING, FALSE ); + case 'M': tr_bencDictAddBool( d, TR_PREFS_KEY_PORT_FORWARDING, false ); break; case 'p': tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_PORT, atoi( optarg ) ); break; case 't': tr_bencDictAddInt( d, TR_PREFS_KEY_PEER_SOCKET_TOS, atoi( optarg ) ); break; case 'u': tr_bencDictAddInt( d, TR_PREFS_KEY_USPEED_KBps, atoi( optarg ) ); - tr_bencDictAddBool( d, TR_PREFS_KEY_USPEED_ENABLED, TRUE ); + tr_bencDictAddBool( d, TR_PREFS_KEY_USPEED_ENABLED, true ); break; - case 'U': tr_bencDictAddBool( d, TR_PREFS_KEY_USPEED_ENABLED, FALSE ); + case 'U': tr_bencDictAddBool( d, TR_PREFS_KEY_USPEED_ENABLED, false ); break; - case 'v': verify = TRUE; + case 'v': verify = true; break; - case 'V': showVersion = TRUE; + case 'V': showVersion = true; break; case 'w': tr_bencDictAddStr( d, TR_PREFS_KEY_DOWNLOAD_DIR, optarg ); break; diff --git a/configure.ac b/configure.ac index 0212e20d1..4ebdaae38 100644 --- a/configure.ac +++ b/configure.ac @@ -108,6 +108,7 @@ fi AC_HEADER_STDC AC_HEADER_TIME +AC_CHECK_HEADERS([stdbool.h]) AC_CHECK_FUNCS([iconv_open pread pwrite lrintf strlcpy daemon dirname basename strcasecmp localtime_r fallocate64 posix_fallocate memmem strsep strtold syslog valloc getpagesize posix_memalign statvfs htonll ntohll]) AC_PROG_INSTALL AC_PROG_MAKE_SET diff --git a/daemon/daemon.c b/daemon/daemon.c index b5ca55379..bdffd7fdc 100644 --- a/daemon/daemon.c +++ b/daemon/daemon.c @@ -58,8 +58,8 @@ #define SPEED_G_STR "GiB/s" #define SPEED_T_STR "TiB/s" -static tr_bool paused = FALSE; -static tr_bool closing = FALSE; +static bool paused = false; +static bool closing = false; static tr_session * mySession = NULL; /*** @@ -144,7 +144,7 @@ gotsig( int sig ) const char * configDir = tr_sessionGetConfigDir( mySession ); tr_inf( "Reloading settings from \"%s\"", configDir ); tr_bencInitDict( &settings, 0 ); - tr_bencDictAddBool( &settings, TR_PREFS_KEY_RPC_ENABLED, TRUE ); + tr_bencDictAddBool( &settings, TR_PREFS_KEY_RPC_ENABLED, true ); tr_sessionLoadSettings( &settings, configDir, MY_NAME ); tr_sessionSet( mySession, &settings ); tr_bencFree( &settings ); @@ -153,7 +153,7 @@ gotsig( int sig ) } default: - closing = TRUE; + closing = true; break; } } @@ -243,7 +243,7 @@ onFileAdded( tr_session * session, const char * dir, const char * file ) tr_err( "Error parsing .torrent file \"%s\"", file ); else { - tr_bool trash = FALSE; + bool trash = false; int test = tr_ctorGetDeleteSource( ctor, &trash ); tr_inf( "Parsing .torrent file successful \"%s\"", file ); @@ -321,7 +321,7 @@ on_rpc_callback( tr_session * session UNUSED, void * user_data UNUSED ) { if( type == TR_RPC_SESSION_CLOSE ) - closing = TRUE; + closing = true; return TR_RPC_OK; } @@ -331,15 +331,15 @@ main( int argc, char ** argv ) int c; const char * optarg; tr_benc settings; - tr_bool boolVal; - tr_bool loaded; - tr_bool foreground = FALSE; - tr_bool dumpSettings = FALSE; + bool boolVal; + bool loaded; + bool foreground = false; + bool dumpSettings = false; const char * configDir = NULL; const char * pid_filename; dtr_watchdir * watchdir = NULL; FILE * logfile = NULL; - tr_bool pidfile_created = FALSE; + bool pidfile_created = false; signal( SIGINT, gotsig ); signal( SIGTERM, gotsig ); @@ -349,7 +349,7 @@ main( int argc, char ** argv ) /* load settings from defaults + config file */ tr_bencInitDict( &settings, 0 ); - tr_bencDictAddBool( &settings, TR_PREFS_KEY_RPC_ENABLED, TRUE ); + tr_bencDictAddBool( &settings, TR_PREFS_KEY_RPC_ENABLED, true ); configDir = getConfigDir( argc, (const char**)argv ); loaded = tr_sessionLoadSettings( &settings, configDir, MY_NAME ); @@ -358,44 +358,44 @@ main( int argc, char ** argv ) while(( c = tr_getopt( getUsage(), argc, (const char**)argv, options, &optarg ))) { switch( c ) { case 'a': tr_bencDictAddStr( &settings, TR_PREFS_KEY_RPC_WHITELIST, optarg ); - tr_bencDictAddBool( &settings, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, TRUE ); + tr_bencDictAddBool( &settings, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, true ); break; - case 'b': tr_bencDictAddBool( &settings, TR_PREFS_KEY_BLOCKLIST_ENABLED, TRUE ); + case 'b': tr_bencDictAddBool( &settings, TR_PREFS_KEY_BLOCKLIST_ENABLED, true ); break; - case 'B': tr_bencDictAddBool( &settings, TR_PREFS_KEY_BLOCKLIST_ENABLED, FALSE ); + case 'B': tr_bencDictAddBool( &settings, TR_PREFS_KEY_BLOCKLIST_ENABLED, false ); break; case 'c': tr_bencDictAddStr( &settings, PREF_KEY_DIR_WATCH, optarg ); - tr_bencDictAddBool( &settings, PREF_KEY_DIR_WATCH_ENABLED, TRUE ); + tr_bencDictAddBool( &settings, PREF_KEY_DIR_WATCH_ENABLED, true ); break; - case 'C': tr_bencDictAddBool( &settings, PREF_KEY_DIR_WATCH_ENABLED, FALSE ); + case 'C': tr_bencDictAddBool( &settings, PREF_KEY_DIR_WATCH_ENABLED, false ); break; case 941: tr_bencDictAddStr( &settings, TR_PREFS_KEY_INCOMPLETE_DIR, optarg ); - tr_bencDictAddBool( &settings, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, TRUE ); + tr_bencDictAddBool( &settings, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, true ); break; - case 942: tr_bencDictAddBool( &settings, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, FALSE ); + case 942: tr_bencDictAddBool( &settings, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, false ); break; - case 'd': dumpSettings = TRUE; + case 'd': dumpSettings = true; break; case 'e': logfile = fopen( optarg, "a+" ); if( logfile == NULL ) fprintf( stderr, "Couldn't open \"%s\": %s\n", optarg, tr_strerror( errno ) ); break; - case 'f': foreground = TRUE; + case 'f': foreground = true; break; case 'g': /* handled above */ break; case 'V': /* version */ fprintf(stderr, "%s %s\n", MY_NAME, LONG_VERSION_STRING); exit( 0 ); - case 'o': tr_bencDictAddBool( &settings, TR_PREFS_KEY_DHT_ENABLED, TRUE ); + case 'o': tr_bencDictAddBool( &settings, TR_PREFS_KEY_DHT_ENABLED, true ); break; - case 'O': tr_bencDictAddBool( &settings, TR_PREFS_KEY_DHT_ENABLED, FALSE ); + case 'O': tr_bencDictAddBool( &settings, TR_PREFS_KEY_DHT_ENABLED, false ); break; case 'p': tr_bencDictAddInt( &settings, TR_PREFS_KEY_RPC_PORT, atoi( optarg ) ); break; - case 't': tr_bencDictAddBool( &settings, TR_PREFS_KEY_RPC_AUTH_REQUIRED, TRUE ); + case 't': tr_bencDictAddBool( &settings, TR_PREFS_KEY_RPC_AUTH_REQUIRED, true ); break; - case 'T': tr_bencDictAddBool( &settings, TR_PREFS_KEY_RPC_AUTH_REQUIRED, FALSE ); + case 'T': tr_bencDictAddBool( &settings, TR_PREFS_KEY_RPC_AUTH_REQUIRED, false ); break; case 'u': tr_bencDictAddStr( &settings, TR_PREFS_KEY_RPC_USERNAME, optarg ); break; @@ -405,15 +405,15 @@ main( int argc, char ** argv ) break; case 'P': tr_bencDictAddInt( &settings, TR_PREFS_KEY_PEER_PORT, atoi( optarg ) ); break; - case 'm': tr_bencDictAddBool( &settings, TR_PREFS_KEY_PORT_FORWARDING, TRUE ); + case 'm': tr_bencDictAddBool( &settings, TR_PREFS_KEY_PORT_FORWARDING, true ); break; - case 'M': tr_bencDictAddBool( &settings, TR_PREFS_KEY_PORT_FORWARDING, FALSE ); + case 'M': tr_bencDictAddBool( &settings, TR_PREFS_KEY_PORT_FORWARDING, false ); break; case 'L': tr_bencDictAddInt( &settings, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, atoi( optarg ) ); break; case 'l': tr_bencDictAddInt( &settings, TR_PREFS_KEY_PEER_LIMIT_TORRENT, atoi( optarg ) ); break; - case 800: paused = TRUE; + case 800: paused = true; break; case 910: tr_bencDictAddInt( &settings, TR_PREFS_KEY_ENCRYPTION, TR_ENCRYPTION_REQUIRED ); break; @@ -428,15 +428,15 @@ main( int argc, char ** argv ) case 'r': tr_bencDictAddStr( &settings, TR_PREFS_KEY_RPC_BIND_ADDRESS, optarg ); break; case 953: tr_bencDictAddReal( &settings, TR_PREFS_KEY_RATIO, atof(optarg) ); - tr_bencDictAddBool( &settings, TR_PREFS_KEY_RATIO_ENABLED, TRUE ); + tr_bencDictAddBool( &settings, TR_PREFS_KEY_RATIO_ENABLED, true ); break; - case 954: tr_bencDictAddBool( &settings, TR_PREFS_KEY_RATIO_ENABLED, FALSE ); + case 954: tr_bencDictAddBool( &settings, TR_PREFS_KEY_RATIO_ENABLED, false ); break; case 'x': tr_bencDictAddStr( &settings, PREF_KEY_PIDFILE, optarg ); break; - case 'y': tr_bencDictAddBool( &settings, TR_PREFS_KEY_LPD_ENABLED, TRUE ); + case 'y': tr_bencDictAddBool( &settings, TR_PREFS_KEY_LPD_ENABLED, true ); break; - case 'Y': tr_bencDictAddBool( &settings, TR_PREFS_KEY_LPD_ENABLED, FALSE ); + case 'Y': tr_bencDictAddBool( &settings, TR_PREFS_KEY_LPD_ENABLED, false ); break; case 810: tr_bencDictAddInt( &settings, TR_PREFS_KEY_MSGLEVEL, TR_MSG_ERR ); break; @@ -466,7 +466,7 @@ main( int argc, char ** argv ) return 0; } - if( !foreground && tr_daemon( TRUE, FALSE ) < 0 ) + if( !foreground && tr_daemon( true, false ) < 0 ) { char buf[256]; tr_snprintf( buf, sizeof( buf ), "Failed to daemonize: %s", tr_strerror( errno ) ); @@ -478,7 +478,7 @@ main( int argc, char ** argv ) tr_formatter_mem_init( MEM_K, MEM_K_STR, MEM_M_STR, MEM_G_STR, MEM_T_STR ); tr_formatter_size_init( DISK_K, DISK_K_STR, DISK_M_STR, DISK_G_STR, DISK_T_STR ); tr_formatter_speed_init( SPEED_K, SPEED_K_STR, SPEED_M_STR, SPEED_G_STR, SPEED_T_STR ); - mySession = tr_sessionInit( "daemon", configDir, TRUE, &settings ); + mySession = tr_sessionInit( "daemon", configDir, true, &settings ); tr_sessionSetRPCCallback( mySession, on_rpc_callback, NULL ); tr_ninf( NULL, "Using settings from \"%s\"", configDir ); tr_sessionSaveSettings( mySession, configDir, &settings ); @@ -493,7 +493,7 @@ main( int argc, char ** argv ) fprintf( fp, "%d", (int)getpid() ); fclose( fp ); tr_inf( "Saved pidfile \"%s\"", pid_filename ); - pidfile_created = TRUE; + pidfile_created = true; } else tr_err( "Unable to save pidfile \"%s\": %s", pid_filename, strerror( errno ) ); @@ -522,7 +522,7 @@ main( int argc, char ** argv ) tr_torrent ** torrents; tr_ctor * ctor = tr_ctorNew( mySession ); if( paused ) - tr_ctorSetPaused( ctor, TR_FORCE, TRUE ); + tr_ctorSetPaused( ctor, TR_FORCE, true ); torrents = tr_sessionLoadTorrents( mySession, ctor, NULL ); tr_free( torrents ); tr_ctorFree( ctor ); diff --git a/daemon/remote.c b/daemon/remote.c index 3c1c3e549..2b435e1bf 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -485,7 +485,7 @@ getOptMode( int val ) } } -static tr_bool debug = 0; +static bool debug = 0; static char * auth = NULL; static char * netrc = NULL; static char * sessionId = NULL; @@ -552,11 +552,11 @@ addIdArg( tr_benc * args, const char * id ) if( strcmp( id, "all" ) ) { const char * pch; - tr_bool isList = strchr(id,',') || strchr(id,'-'); - tr_bool isNum = TRUE; + bool isList = strchr(id,',') || strchr(id,'-'); + bool isNum = true; for( pch=id; isNum && *pch; ++pch ) if( !isdigit( *pch ) ) - isNum = FALSE; + isNum = false; if( isNum || isList ) tr_rpc_parse_list_str( tr_bencDictAdd( args, "ids" ), id, strlen( id ) ); else @@ -568,7 +568,7 @@ static void addTime( tr_benc * args, const char * key, const char * arg ) { int time; - tr_bool success = FALSE; + bool success = false; if( arg && ( strlen( arg ) == 4 ) ) { @@ -580,7 +580,7 @@ addTime( tr_benc * args, const char * key, const char * arg ) if( 0<=hour && hour<24 && 0<=min && min<60 ) { time = min + ( hour * 60 ); - success = TRUE; + success = true; } } @@ -758,7 +758,7 @@ static char* getStatusString( tr_benc * t, char * buf, size_t buflen ) { int64_t status; - tr_bool boolVal; + bool boolVal; if( !tr_bencDictFindInt( t, "status", &status ) ) { @@ -835,7 +835,7 @@ printDetails( tr_benc * top ) char buf[512]; char buf2[512]; int64_t i, j, k; - tr_bool boolVal; + bool boolVal; double d; printf( "NAME\n" ); @@ -1206,7 +1206,7 @@ printPortTest( tr_benc * top ) tr_benc *args; if( ( tr_bencDictFindDict( top, "arguments", &args ) ) ) { - tr_bool boolVal; + bool boolVal; if( tr_bencDictFindBool( args, "port-is-open", &boolVal ) ) printf( "Port is open: %s\n", ( boolVal ? "Yes" : "No" ) ); @@ -1304,22 +1304,22 @@ printTrackersImpl( tr_benc * trackerStats ) for( i=0; (( t = tr_bencListChild( trackerStats, i ))); ++i ) { int64_t downloadCount; - tr_bool hasAnnounced; - tr_bool hasScraped; + bool hasAnnounced; + bool hasScraped; const char * host; int64_t id; - tr_bool isBackup; + bool isBackup; int64_t lastAnnouncePeerCount; const char * lastAnnounceResult; int64_t lastAnnounceStartTime; - tr_bool lastAnnounceSucceeded; + bool lastAnnounceSucceeded; int64_t lastAnnounceTime; - tr_bool lastAnnounceTimedOut; + bool lastAnnounceTimedOut; const char * lastScrapeResult; - tr_bool lastScrapeSucceeded; + bool lastScrapeSucceeded; int64_t lastScrapeStartTime; int64_t lastScrapeTime; - tr_bool lastScrapeTimedOut; + bool lastScrapeTimedOut; int64_t leecherCount; int64_t nextAnnounceTime; int64_t nextScrapeTime; @@ -1459,7 +1459,7 @@ printSession( tr_benc * top ) { int64_t i; char buf[64]; - tr_bool boolVal; + bool boolVal; const char * str; printf( "VERSION\n" ); @@ -1495,7 +1495,7 @@ printSession( tr_benc * top ) printf( "\n" ); { - tr_bool altEnabled, altTimeEnabled, upEnabled, downEnabled, seedRatioLimited; + bool altEnabled, altTimeEnabled, upEnabled, downEnabled, seedRatioLimited; int64_t altDown, altUp, altBegin, altEnd, altDay, upLimit, downLimit, peerLimit; double seedRatioLimit; @@ -1843,7 +1843,7 @@ processArgs( const char * rpcurl, int argc, const char ** argv ) break; case 'b': /* debug */ - debug = TRUE; + debug = true; break; case 'n': /* auth */ @@ -1952,21 +1952,21 @@ processArgs( const char * rpcurl, int argc, const char ** argv ) switch( c ) { case 800: tr_bencDictAddStr( args, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_FILENAME, optarg ); - tr_bencDictAddBool( args, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, TRUE ); + tr_bencDictAddBool( args, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, true ); break; - case 801: tr_bencDictAddBool( args, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, FALSE ); + case 801: tr_bencDictAddBool( args, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, false ); break; - case 970: tr_bencDictAddBool( args, TR_PREFS_KEY_ALT_SPEED_ENABLED, TRUE ); + case 970: tr_bencDictAddBool( args, TR_PREFS_KEY_ALT_SPEED_ENABLED, true ); break; - case 971: tr_bencDictAddBool( args, TR_PREFS_KEY_ALT_SPEED_ENABLED, FALSE ); + case 971: tr_bencDictAddBool( args, TR_PREFS_KEY_ALT_SPEED_ENABLED, false ); break; case 972: tr_bencDictAddInt( args, TR_PREFS_KEY_ALT_SPEED_DOWN_KBps, numarg( optarg ) ); break; case 973: tr_bencDictAddInt( args, TR_PREFS_KEY_ALT_SPEED_UP_KBps, numarg( optarg ) ); break; - case 974: tr_bencDictAddBool( args, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, TRUE ); + case 974: tr_bencDictAddBool( args, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, true ); break; - case 975: tr_bencDictAddBool( args, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, FALSE ); + case 975: tr_bencDictAddBool( args, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, false ); break; case 976: addTime( args, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, optarg ); break; @@ -1975,9 +1975,9 @@ processArgs( const char * rpcurl, int argc, const char ** argv ) case 978: addDays( args, TR_PREFS_KEY_ALT_SPEED_TIME_DAY, optarg ); break; case 'c': tr_bencDictAddStr( args, TR_PREFS_KEY_INCOMPLETE_DIR, optarg ); - tr_bencDictAddBool( args, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, TRUE ); + tr_bencDictAddBool( args, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, true ); break; - case 'C': tr_bencDictAddBool( args, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, FALSE ); + case 'C': tr_bencDictAddBool( args, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, false ); break; case 'e': tr_bencDictAddInt( args, TR_PREFS_KEY_MAX_CACHE_SIZE_MB, atoi(optarg) ); break; @@ -1987,42 +1987,42 @@ processArgs( const char * rpcurl, int argc, const char ** argv ) break; case 912: tr_bencDictAddStr( args, TR_PREFS_KEY_ENCRYPTION, "tolerated" ); break; - case 'm': tr_bencDictAddBool( args, TR_PREFS_KEY_PORT_FORWARDING, TRUE ); + case 'm': tr_bencDictAddBool( args, TR_PREFS_KEY_PORT_FORWARDING, true ); break; - case 'M': tr_bencDictAddBool( args, TR_PREFS_KEY_PORT_FORWARDING, FALSE ); + case 'M': tr_bencDictAddBool( args, TR_PREFS_KEY_PORT_FORWARDING, false ); break; - case 'o': tr_bencDictAddBool( args, TR_PREFS_KEY_DHT_ENABLED, TRUE ); + case 'o': tr_bencDictAddBool( args, TR_PREFS_KEY_DHT_ENABLED, true ); break; - case 'O': tr_bencDictAddBool( args, TR_PREFS_KEY_DHT_ENABLED, FALSE ); + case 'O': tr_bencDictAddBool( args, TR_PREFS_KEY_DHT_ENABLED, false ); break; - case 830: tr_bencDictAddBool( args, TR_PREFS_KEY_UTP_ENABLED, TRUE ); + case 830: tr_bencDictAddBool( args, TR_PREFS_KEY_UTP_ENABLED, true ); break; - case 831: tr_bencDictAddBool( args, TR_PREFS_KEY_UTP_ENABLED, FALSE ); + case 831: tr_bencDictAddBool( args, TR_PREFS_KEY_UTP_ENABLED, false ); break; case 'p': tr_bencDictAddInt( args, TR_PREFS_KEY_PEER_PORT, numarg( optarg ) ); break; - case 'P': tr_bencDictAddBool( args, TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START, TRUE); + case 'P': tr_bencDictAddBool( args, TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START, true); break; - case 'x': tr_bencDictAddBool( args, TR_PREFS_KEY_PEX_ENABLED, TRUE ); + case 'x': tr_bencDictAddBool( args, TR_PREFS_KEY_PEX_ENABLED, true ); break; - case 'X': tr_bencDictAddBool( args, TR_PREFS_KEY_PEX_ENABLED, FALSE ); + case 'X': tr_bencDictAddBool( args, TR_PREFS_KEY_PEX_ENABLED, false ); break; - case 'y': tr_bencDictAddBool( args, TR_PREFS_KEY_LPD_ENABLED, TRUE ); + case 'y': tr_bencDictAddBool( args, TR_PREFS_KEY_LPD_ENABLED, true ); break; - case 'Y': tr_bencDictAddBool( args, TR_PREFS_KEY_LPD_ENABLED, FALSE ); + case 'Y': tr_bencDictAddBool( args, TR_PREFS_KEY_LPD_ENABLED, false ); break; case 953: tr_bencDictAddReal( args, "seedRatioLimit", atof(optarg) ); - tr_bencDictAddBool( args, "seedRatioLimited", TRUE ); + tr_bencDictAddBool( args, "seedRatioLimited", true ); break; - case 954: tr_bencDictAddBool( args, "seedRatioLimited", FALSE ); + case 954: tr_bencDictAddBool( args, "seedRatioLimited", false ); break; - case 990: tr_bencDictAddBool( args, TR_PREFS_KEY_START, FALSE ); + case 990: tr_bencDictAddBool( args, TR_PREFS_KEY_START, false ); break; - case 991: tr_bencDictAddBool( args, TR_PREFS_KEY_START, TRUE ); + case 991: tr_bencDictAddBool( args, TR_PREFS_KEY_START, true ); break; - case 992: tr_bencDictAddBool( args, TR_PREFS_KEY_TRASH_ORIGINAL, TRUE ); + case 992: tr_bencDictAddBool( args, TR_PREFS_KEY_TRASH_ORIGINAL, true ); break; - case 993: tr_bencDictAddBool( args, TR_PREFS_KEY_TRASH_ORIGINAL, FALSE ); + case 993: tr_bencDictAddBool( args, TR_PREFS_KEY_TRASH_ORIGINAL, false ); break; default: assert( "unhandled value" && 0 ); break; @@ -2042,29 +2042,29 @@ processArgs( const char * rpcurl, int argc, const char ** argv ) { case 'd': if( targs ) { tr_bencDictAddInt( targs, "downloadLimit", numarg( optarg ) ); - tr_bencDictAddBool( targs, "downloadLimited", TRUE ); + tr_bencDictAddBool( targs, "downloadLimited", true ); } else { tr_bencDictAddInt( sargs, TR_PREFS_KEY_DSPEED_KBps, numarg( optarg ) ); - tr_bencDictAddBool( sargs, TR_PREFS_KEY_DSPEED_ENABLED, TRUE ); + tr_bencDictAddBool( sargs, TR_PREFS_KEY_DSPEED_ENABLED, true ); } break; case 'D': if( targs ) - tr_bencDictAddBool( targs, "downloadLimited", FALSE ); + tr_bencDictAddBool( targs, "downloadLimited", false ); else - tr_bencDictAddBool( sargs, TR_PREFS_KEY_DSPEED_ENABLED, FALSE ); + tr_bencDictAddBool( sargs, TR_PREFS_KEY_DSPEED_ENABLED, false ); break; case 'u': if( targs ) { tr_bencDictAddInt( targs, "uploadLimit", numarg( optarg ) ); - tr_bencDictAddBool( targs, "uploadLimited", TRUE ); + tr_bencDictAddBool( targs, "uploadLimited", true ); } else { tr_bencDictAddInt( sargs, TR_PREFS_KEY_USPEED_KBps, numarg( optarg ) ); - tr_bencDictAddBool( sargs, TR_PREFS_KEY_USPEED_ENABLED, TRUE ); + tr_bencDictAddBool( sargs, TR_PREFS_KEY_USPEED_ENABLED, true ); } break; case 'U': if( targs ) - tr_bencDictAddBool( targs, "uploadLimited", FALSE ); + tr_bencDictAddBool( targs, "uploadLimited", false ); else - tr_bencDictAddBool( sargs, TR_PREFS_KEY_USPEED_ENABLED, FALSE ); + tr_bencDictAddBool( sargs, TR_PREFS_KEY_USPEED_ENABLED, false ); break; case 930: if( targs ) tr_bencDictAddInt( targs, "peer-limit", atoi(optarg) ); @@ -2090,9 +2090,9 @@ processArgs( const char * rpcurl, int argc, const char ** argv ) break; case 952: tr_bencDictAddInt( args, "seedRatioMode", TR_RATIOLIMIT_UNLIMITED ); break; - case 984: tr_bencDictAddBool( args, "honorsSessionLimits", TRUE ); + case 984: tr_bencDictAddBool( args, "honorsSessionLimits", true ); break; - case 985: tr_bencDictAddBool( args, "honorsSessionLimits", FALSE ); + case 985: tr_bencDictAddBool( args, "honorsSessionLimits", false ); break; default: assert( "unhandled value" && 0 ); break; @@ -2146,7 +2146,7 @@ processArgs( const char * rpcurl, int argc, const char ** argv ) tr_bencDictAddStr( top, "method", "torrent-set-location" ); args = tr_bencDictAddDict( top, ARGUMENTS, 3 ); tr_bencDictAddStr( args, "location", optarg ); - tr_bencDictAddBool( args, "move", FALSE ); + tr_bencDictAddBool( args, "move", false ); addIdArg( args, id ); status |= flush( rpcurl, &top ); break; @@ -2166,7 +2166,7 @@ processArgs( const char * rpcurl, int argc, const char ** argv ) case 's': /* start */ { if( tadd ) - tr_bencDictAddBool( tr_bencDictFind( tadd, "arguments" ), "paused", FALSE ); + tr_bencDictAddBool( tr_bencDictFind( tadd, "arguments" ), "paused", false ); else { tr_benc * top = tr_new0( tr_benc, 1 ); tr_bencInitDict( top, 2 ); @@ -2179,7 +2179,7 @@ processArgs( const char * rpcurl, int argc, const char ** argv ) case 'S': /* stop */ { if( tadd ) - tr_bencDictAddBool( tr_bencDictFind( tadd, "arguments" ), "paused", TRUE ); + tr_bencDictAddBool( tr_bencDictFind( tadd, "arguments" ), "paused", true ); else { tr_benc * top = tr_new0( tr_benc, 1 ); tr_bencInitDict( top, 2 ); @@ -2278,7 +2278,7 @@ processArgs( const char * rpcurl, int argc, const char ** argv ) tr_bencDictAddStr( top, "method", "torrent-set-location" ); args = tr_bencDictAddDict( top, ARGUMENTS, 3 ); tr_bencDictAddStr( args, "location", optarg ); - tr_bencDictAddBool( args, "move", TRUE ); + tr_bencDictAddBool( args, "move", true ); addIdArg( args, id ); status |= flush( rpcurl, &top ); break; diff --git a/gtk/conf.c b/gtk/conf.c index 1449247b2..2048dcf46 100644 --- a/gtk/conf.c +++ b/gtk/conf.c @@ -268,7 +268,7 @@ gtr_pref_double_set( const char * key, double value ) gboolean gtr_pref_flag_get( const char * key ) { - tr_bool boolVal; + bool boolVal; tr_bencDictFindBool( getPrefs( ), key, &boolVal ); return boolVal != 0; } diff --git a/gtk/details.c b/gtk/details.c index c296de02a..7a632fe30 100644 --- a/gtk/details.c +++ b/gtk/details.c @@ -182,7 +182,7 @@ refreshOptions( struct DetailsImpl * di, tr_torrent ** torrents, int n ) /* honor_limits_check */ if( n ) { - const tr_bool baseline = tr_torrentUsesSessionLimits( torrents[0] ); + const bool baseline = tr_torrentUsesSessionLimits( torrents[0] ); int i; for( i=1; i<n; ++i ) if( baseline != tr_torrentUsesSessionLimits( torrents[i] ) ) @@ -194,7 +194,7 @@ refreshOptions( struct DetailsImpl * di, tr_torrent ** torrents, int n ) /* down_limited_check */ if( n ) { - const tr_bool baseline = tr_torrentUsesSpeedLimit( torrents[0], TR_DOWN ); + const bool baseline = tr_torrentUsesSpeedLimit( torrents[0], TR_DOWN ); int i; for( i=1; i<n; ++i ) if( baseline != tr_torrentUsesSpeedLimit( torrents[i], TR_DOWN ) ) @@ -218,7 +218,7 @@ refreshOptions( struct DetailsImpl * di, tr_torrent ** torrents, int n ) /* up_limited_check */ if( n ) { - const tr_bool baseline = tr_torrentUsesSpeedLimit( torrents[0], TR_UP ); + const bool baseline = tr_torrentUsesSpeedLimit( torrents[0], TR_UP ); int i; for( i=1; i<n; ++i ) if( baseline != tr_torrentUsesSpeedLimit( torrents[i], TR_UP ) ) @@ -550,7 +550,7 @@ options_page_new( struct DetailsImpl * d ) ****/ static const char * -activityString( int activity, tr_bool finished ) +activityString( int activity, bool finished ) { switch( activity ) { @@ -619,7 +619,7 @@ refreshInfo( struct DetailsImpl * di, tr_torrent ** torrents, int n ) if( n<=0 ) str = no_torrent; else { - const tr_bool baseline = infos[0]->isPrivate; + const bool baseline = infos[0]->isPrivate; for( i=1; i<n; ++i ) if( baseline != infos[i]->isPrivate ) break; @@ -699,7 +699,7 @@ refreshInfo( struct DetailsImpl * di, tr_torrent ** torrents, int n ) str = no_torrent; else { const tr_torrent_activity activity = stats[0]->activity; - tr_bool allFinished = stats[0]->finished; + bool allFinished = stats[0]->finished; for( i=1; i<n; ++i ) { if( activity != stats[i]->activity ) break; @@ -1509,7 +1509,7 @@ setPeerViewColumns( GtkTreeView * peer_view ) { int i; int n = 0; - const tr_bool more = gtr_pref_flag_get( PREF_KEY_SHOW_MORE_PEER_INFO ); + const bool more = gtr_pref_flag_get( PREF_KEY_SHOW_MORE_PEER_INFO ); int view_columns[32]; GtkTreeViewColumn * c; GtkCellRenderer * r; diff --git a/gtk/favicon.c b/gtk/favicon.c index a01241a0e..bfc57b5cf 100644 --- a/gtk/favicon.c +++ b/gtk/favicon.c @@ -81,7 +81,7 @@ favicon_load_from_cache( const char * host ) return pixbuf; } -static void favicon_web_done_cb( tr_session*, tr_bool, tr_bool, long, const void*, size_t, void* ); +static void favicon_web_done_cb( tr_session*, bool, bool, long, const void*, size_t, void* ); static gboolean favicon_web_done_idle_cb( gpointer vfav ) @@ -129,8 +129,8 @@ favicon_web_done_idle_cb( gpointer vfav ) static void favicon_web_done_cb( tr_session * session UNUSED, - tr_bool did_connect UNUSED, - tr_bool did_timeout UNUSED, + bool did_connect UNUSED, + bool did_timeout UNUSED, long code UNUSED, const void * data, size_t len, diff --git a/gtk/main.c b/gtk/main.c index ba41d43f0..b799c882a 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -504,10 +504,10 @@ on_rpc_changed( tr_session * session, tr_sessionGetSettings( session, &tmp ); for( i=0; tr_bencDictChild( &tmp, i, &key, &newval ); ++i ) { - tr_bool changed; + bool changed; tr_benc * oldval = tr_bencDictFind( oldvals, key ); if( !oldval ) - changed = TRUE; + changed = true; else { char * a = tr_bencToStr( oldval, TR_FMT_BENC, NULL ); char * b = tr_bencToStr( newval, TR_FMT_BENC, NULL ); diff --git a/gtk/open-dialog.c b/gtk/open-dialog.c index 3fb5dfcc8..65b15e1ec 100644 --- a/gtk/open-dialog.c +++ b/gtk/open-dialog.c @@ -263,7 +263,7 @@ gtr_torrent_options_dialog_new( GtkWindow * parent, TrCore * core, tr_ctor * cto GtkWidget * grab; GtkWidget * source_chooser; struct OpenData * data; - uint8_t flag; + bool flag; GSList * list; GSList * walk; diff --git a/gtk/relocate.c b/gtk/relocate.c index a65b7bacb..3a91b4aef 100644 --- a/gtk/relocate.c +++ b/gtk/relocate.c @@ -27,7 +27,7 @@ static char * previousLocation = NULL; struct relocate_dialog_data { int done; - tr_bool do_move; + bool do_move; TrCore * core; GSList * torrent_ids; GtkWidget * message_dialog; diff --git a/gtk/tr-core.c b/gtk/tr-core.c index afc0d4cce..2df1b6aaf 100644 --- a/gtk/tr-core.c +++ b/gtk/tr-core.c @@ -348,7 +348,7 @@ gtr_core_session( TrCore * core ) **** BUSY ***/ -static tr_bool +static bool core_is_busy( TrCore * core ) { return core->priv->busy_count > 0; @@ -357,7 +357,7 @@ core_is_busy( TrCore * core ) static void core_add_to_busy( TrCore * core, int addMe ) { - const tr_bool wasBusy = core_is_busy( core ); + const bool wasBusy = core_is_busy( core ); core->priv->busy_count += addMe; @@ -877,7 +877,7 @@ on_torrent_completeness_changed_idle( gpointer gdata ) static void on_torrent_completeness_changed( tr_torrent * tor, tr_completeness completeness, - tr_bool was_running, + bool was_running, void * gcore ) { if( was_running && ( completeness != TR_LEECH ) && ( tr_torrentStat( tor )->sizeWhenDone != 0 ) ) @@ -971,7 +971,7 @@ core_create_new_torrent( TrCore * core, tr_ctor * ctor ) { int errcode = 0; tr_torrent * tor; - uint8_t do_trash = FALSE; + bool do_trash = false; tr_session * session = gtr_core_session( core ); /* let the gtk client handle the removal, since libT @@ -1108,8 +1108,8 @@ struct url_dialog_data tr_ctor * ctor; char * url; - tr_bool did_connect; - tr_bool did_timeout; + bool did_connect; + bool did_timeout; long response_code; }; @@ -1143,8 +1143,8 @@ on_url_done_idle( gpointer vdata ) static void on_url_done( tr_session * session, - tr_bool did_connect, - tr_bool did_timeout, + bool did_connect, + bool did_timeout, long response_code, const void * response, size_t response_byte_count, @@ -1353,7 +1353,7 @@ update_foreach( GtkTreeModel * model, int oldActivity, newActivity; int oldActivePeerCount, newActivePeerCount; int oldError, newError; - tr_bool oldFinished, newFinished; + bool oldFinished, newFinished; tr_priority_t oldPriority, newPriority; char * oldCollatedName, * newCollatedName; char * oldTrackers, * newTrackers; @@ -1717,7 +1717,7 @@ static void on_port_test_response( TrCore * core, tr_benc * response, gpointer u UNUSED ) { tr_benc * args; - tr_bool is_open = FALSE; + bool is_open = FALSE; if( tr_bencDictFindDict( response, "arguments", &args ) ) tr_bencDictFindBool( args, "port-is-open", &is_open ); diff --git a/gtk/tr-prefs.c b/gtk/tr-prefs.c index f1f435c9c..fd6782022 100644 --- a/gtk/tr-prefs.c +++ b/gtk/tr-prefs.c @@ -425,7 +425,7 @@ onBlocklistUpdateResponse( GtkDialog * dialog, gint response UNUSED, gpointer gd static void onBlocklistUpdated( TrCore * core, int n, gpointer gdata ) { - const tr_bool success = n >= 0; + const bool success = n >= 0; const int count = n >=0 ? n : tr_blocklistGetRuleCount( gtr_core_session( core ) ); const char * s = gtr_ngettext( "Blocklist has %'d rule.", "Blocklist has %'d rules.", count ); struct blocklist_data * data = gdata; diff --git a/gtk/tr-window.c b/gtk/tr-window.c index bb6422c46..db6520e89 100644 --- a/gtk/tr-window.c +++ b/gtk/tr-window.c @@ -348,7 +348,7 @@ onAltSpeedToggledIdle( gpointer vp ) } static void -onAltSpeedToggled( tr_session * s UNUSED, tr_bool isEnabled UNUSED, tr_bool byUser UNUSED, void * p ) +onAltSpeedToggled( tr_session * s UNUSED, bool isEnabled UNUSED, bool byUser UNUSED, void * p ) { gtr_idle_add( onAltSpeedToggledIdle, p ); } diff --git a/libtransmission/announcer-common.h b/libtransmission/announcer-common.h index f9f8c3b1c..3682024e5 100644 --- a/libtransmission/announcer-common.h +++ b/libtransmission/announcer-common.h @@ -73,10 +73,10 @@ struct tr_scrape_response_row typedef struct { /* whether or not we managed to connect to the tracker */ - tr_bool did_connect; + bool did_connect; /* whether or not the scrape timed out */ - tr_bool did_timeout; + bool did_timeout; /* how many info hashes are in the 'rows' field */ int row_count; @@ -128,7 +128,7 @@ const char * tr_announce_event_get_string( tr_announce_event ); typedef struct { tr_announce_event event; - tr_bool partial_seed; + bool partial_seed; /* the port we listen for incoming peers on */ int port; @@ -178,10 +178,10 @@ typedef struct uint8_t info_hash[SHA_DIGEST_LENGTH]; /* whether or not we managed to connect to the tracker */ - tr_bool did_connect; + bool did_connect; /* whether or not the scrape timed out */ - tr_bool did_timeout; + bool did_timeout; /* preferred interval between announces. * transmission treats this as the interval for periodic announces */ diff --git a/libtransmission/announcer-http.c b/libtransmission/announcer-http.c index e5798248a..9bf263cd2 100644 --- a/libtransmission/announcer-http.c +++ b/libtransmission/announcer-http.c @@ -113,7 +113,7 @@ announce_url_new( const tr_session * session, const tr_announce_request * req ) char ipv6_readable[INET6_ADDRSTRLEN]; evutil_inet_ntop( AF_INET6, ipv6, ipv6_readable, INET6_ADDRSTRLEN ); evbuffer_add_printf( buf, "&ipv6="); - tr_http_escape( buf, ipv6_readable, -1, TRUE ); + tr_http_escape( buf, ipv6_readable, -1, true ); } return evbuffer_free_to_str( buf ); @@ -186,8 +186,8 @@ on_announce_done_eventthread( void * vdata ) static void on_announce_done( tr_session * session, - tr_bool did_connect, - tr_bool did_timeout, + bool did_connect, + bool did_timeout, long response_code, const void * msg, size_t msglen, @@ -328,8 +328,8 @@ on_scrape_done_eventthread( void * vdata ) static void on_scrape_done( tr_session * session, - tr_bool did_connect, - tr_bool did_timeout, + bool did_connect, + bool did_timeout, long response_code, const void * msg, size_t msglen, diff --git a/libtransmission/announcer-udp.c b/libtransmission/announcer-udp.c index 60d3c617b..df0ee7ce8 100644 --- a/libtransmission/announcer-udp.c +++ b/libtransmission/announcer-udp.c @@ -120,14 +120,14 @@ typedef enum } tau_action_t; -static tr_bool +static bool is_tau_response_message( int action, int msglen ) { if( action == TAU_ACTION_CONNECT ) return msglen == 16; if( action == TAU_ACTION_ANNOUNCE ) return msglen >= 20; if( action == TAU_ACTION_SCRAPE ) return msglen >= 20; if( action == TAU_ACTION_ERROR ) return msglen >= 8; - return FALSE; + return false; } enum @@ -211,8 +211,8 @@ tau_scrape_request_finished( tr_session * session, static void tau_scrape_request_fail( tr_session * session, struct tau_scrape_request * request, - tr_bool did_connect, - tr_bool did_timeout, + bool did_connect, + bool did_timeout, const char * errmsg ) { request->response.did_connect = did_connect; @@ -227,8 +227,8 @@ on_scrape_response( tr_session * session, tau_action_t action, struct evbuffer * buf ) { - request->response.did_connect = TRUE; - request->response.did_timeout = FALSE; + request->response.did_connect = true; + request->response.did_timeout = false; if( action == TAU_ACTION_SCRAPE ) { @@ -258,7 +258,7 @@ on_scrape_response( tr_session * session, else errmsg = tr_strdup( _( "Unknown error" ) ); - tau_scrape_request_fail( session, request, TRUE, FALSE, errmsg ); + tau_scrape_request_fail( session, request, true, false, errmsg ); tr_free( errmsg ); } } @@ -366,8 +366,8 @@ tau_announce_request_finished( tr_session * session, static void tau_announce_request_fail( tr_session * session, struct tau_announce_request * request, - tr_bool did_connect, - tr_bool did_timeout, + bool did_connect, + bool did_timeout, const char * errmsg ) { request->response.did_connect = did_connect; @@ -382,8 +382,8 @@ on_announce_response( tr_session * session, tau_action_t action, struct evbuffer * buf ) { - request->response.did_connect = TRUE; - request->response.did_timeout = FALSE; + request->response.did_connect = true; + request->response.did_timeout = false; if( ( action == TAU_ACTION_ANNOUNCE ) && ( evbuffer_get_length( buf ) >= 3*sizeof(uint32_t) ) ) @@ -408,7 +408,7 @@ on_announce_response( tr_session * session, else errmsg = tr_strdup( _( "Unknown error" ) ); - tau_announce_request_fail( session, request, TRUE, FALSE, errmsg ); + tau_announce_request_fail( session, request, true, false, errmsg ); tr_free( errmsg ); } } @@ -427,7 +427,7 @@ struct tau_tracker char * host; int port; - tr_bool is_asking_dns; + bool is_asking_dns; struct evutil_addrinfo * addr; time_t addr_expiration_time; @@ -458,8 +458,8 @@ tau_tracker_free( struct tau_tracker * t ) static void tau_tracker_fail_all( struct tau_tracker * tracker, - tr_bool did_connect, - tr_bool did_timeout, + bool did_connect, + bool did_timeout, const char * errmsg ) { int i; @@ -489,14 +489,14 @@ tau_tracker_on_dns( int errcode, struct evutil_addrinfo *addr, void * vtracker ) { struct tau_tracker * tracker = vtracker; - tracker->is_asking_dns = FALSE; + tracker->is_asking_dns = false; if ( errcode ) { char * errmsg = tr_strdup_printf( _( "DNS Lookup failed: %s" ), evdns_err_to_string( errcode ) ); dbgmsg( tracker->key, "%s", errmsg ); - tau_tracker_fail_all( tracker, FALSE, FALSE, errmsg ); + tau_tracker_fail_all( tracker, false, false, errmsg ); tr_free( errmsg ); } else @@ -597,7 +597,7 @@ on_tracker_connection_response( struct tau_tracker * tracker, errmsg = tr_strdup( _( "Connection failed" ) ); dbgmsg( tracker->key, "%s", errmsg ); - tau_tracker_fail_all( tracker, TRUE, FALSE, errmsg ); + tau_tracker_fail_all( tracker, true, false, errmsg ); tr_free( errmsg ); } @@ -610,7 +610,7 @@ tau_tracker_timeout_reqs( struct tau_tracker * tracker ) int i, n; tr_ptrArray * reqs; const time_t now = time( NULL ); - const tr_bool cancel_all = tracker->close_at && ( tracker->close_at <= now ); + const bool cancel_all = tracker->close_at && ( tracker->close_at <= now ); if( tracker->connecting_at && ( tracker->connecting_at + TAU_REQUEST_TTL < now ) ) { @@ -622,7 +622,7 @@ tau_tracker_timeout_reqs( struct tau_tracker * tracker ) struct tau_announce_request * req = tr_ptrArrayNth( reqs, i ); if( cancel_all || ( req->created_at + TAU_REQUEST_TTL < now ) ) { dbgmsg( tracker->key, "timeout announce req %p", req ); - tau_announce_request_fail( tracker->session, req, FALSE, TRUE, NULL ); + tau_announce_request_fail( tracker->session, req, false, true, NULL ); tau_announce_request_free( req ); tr_ptrArrayRemove( reqs, i ); --i; @@ -635,7 +635,7 @@ tau_tracker_timeout_reqs( struct tau_tracker * tracker ) struct tau_scrape_request * req = tr_ptrArrayNth( reqs, i ); if( cancel_all || ( req->created_at + TAU_REQUEST_TTL < now ) ) { dbgmsg( tracker->key, "timeout scrape req %p", req ); - tau_scrape_request_fail( tracker->session, req, FALSE, TRUE, NULL ); + tau_scrape_request_fail( tracker->session, req, false, true, NULL ); tau_scrape_request_free( req ); tr_ptrArrayRemove( reqs, i ); --i; @@ -644,7 +644,7 @@ tau_tracker_timeout_reqs( struct tau_tracker * tracker ) } } -static tr_bool +static bool tau_tracker_is_empty( const struct tau_tracker * tracker ) { return tr_ptrArrayEmpty( &tracker->announces ) @@ -676,7 +676,7 @@ tau_tracker_upkeep( struct tau_tracker * tracker ) hints.ai_flags = EVUTIL_AI_CANONNAME; hints.ai_socktype = SOCK_DGRAM; hints.ai_protocol = IPPROTO_UDP; - tracker->is_asking_dns = TRUE; + tracker->is_asking_dns = true; dbgmsg( tracker->host, "Trying a new DNS lookup" ); evdns_getaddrinfo( tracker->session->evdns_base, tracker->host, NULL, &hints, @@ -803,7 +803,7 @@ tr_tracker_udp_upkeep( tr_session * session ) (PtrArrayForeachFunc)tau_tracker_upkeep ); } -tr_bool +bool tr_tracker_udp_is_empty( const tr_session * session ) { int i; @@ -813,9 +813,9 @@ tr_tracker_udp_is_empty( const tr_session * session ) if( tau != NULL ) for( i=0, n=tr_ptrArraySize(&tau->trackers); i<n; ++i ) if( !tau_tracker_is_empty( tr_ptrArrayNth( &tau->trackers, i ) ) ) - return FALSE; + return false; - return TRUE; + return true; } /* drop dead now. */ @@ -856,7 +856,7 @@ tr_tracker_udp_start_shutdown( tr_session * session ) /* @brief process an incoming udp message if it's a tracker response. * @return true if msg was a tracker response; false otherwise */ -tr_bool +bool tau_handle_message( tr_session * session, const uint8_t * msg, size_t msglen ) { int i; @@ -869,9 +869,9 @@ tau_handle_message( tr_session * session, const uint8_t * msg, size_t msglen ) /*fprintf( stderr, "got an incoming udp message w/len %zu\n", msglen );*/ if( !session || !session->announcer_udp ) - return FALSE; + return false; if( msglen < (sizeof(uint32_t)*2) ) - return FALSE; + return false; /* extract the action_id and see if it makes sense */ buf = evbuffer_new( ); @@ -879,7 +879,7 @@ tau_handle_message( tr_session * session, const uint8_t * msg, size_t msglen ) action_id = evbuffer_read_ntoh_32( buf ); if( !is_tau_response_message( action_id, msglen ) ) { evbuffer_free( buf ); - return FALSE; + return false; } /* extract the transaction_id and look for a match */ @@ -899,7 +899,7 @@ tau_handle_message( tr_session * session, const uint8_t * msg, size_t msglen ) dbgmsg( tracker->key, "%"PRIu32" is my connection request!", transaction_id ); on_tracker_connection_response( tracker, action_id, buf ); evbuffer_free( buf ); - return TRUE; + return true; } /* is it a response to one of this tracker's announces? */ @@ -912,7 +912,7 @@ tau_handle_message( tr_session * session, const uint8_t * msg, size_t msglen ) on_announce_response( session, req, action_id, buf ); tau_announce_request_free( req ); evbuffer_free( buf ); - return TRUE; + return true; } } @@ -926,14 +926,14 @@ tau_handle_message( tr_session * session, const uint8_t * msg, size_t msglen ) on_scrape_response( session, req, action_id, buf ); tau_scrape_request_free( req ); evbuffer_free( buf ); - return TRUE; + return true; } } } /* no match... */ evbuffer_free( buf ); - return FALSE; + return false; } void diff --git a/libtransmission/announcer.c b/libtransmission/announcer.c index 172d59d16..1ba65dabe 100644 --- a/libtransmission/announcer.c +++ b/libtransmission/announcer.c @@ -128,7 +128,7 @@ typedef struct tr_announcer } tr_announcer; -tr_bool +bool tr_announcerHasBacklog( const struct tr_announcer * announcer ) { return announcer->slotsAvailable < 1; @@ -264,15 +264,15 @@ typedef struct tr_tier time_t scrapeAt; time_t lastScrapeStartTime; time_t lastScrapeTime; - tr_bool lastScrapeSucceeded; - tr_bool lastScrapeTimedOut; + bool lastScrapeSucceeded; + bool lastScrapeTimedOut; time_t announceAt; time_t manualAnnounceAllowedAt; time_t lastAnnounceStartTime; time_t lastAnnounceTime; - tr_bool lastAnnounceSucceeded; - tr_bool lastAnnounceTimedOut; + bool lastAnnounceSucceeded; + bool lastAnnounceTimedOut; tr_announce_event * announce_events; int announce_event_count; @@ -287,10 +287,10 @@ typedef struct tr_tier int lastAnnouncePeerCount; - tr_bool isRunning; - tr_bool isAnnouncing; - tr_bool isScraping; - tr_bool wasCopied; + bool isRunning; + bool isAnnouncing; + bool isScraping; + bool wasCopied; char lastAnnounceStr[128]; char lastScrapeStr[128]; @@ -352,8 +352,8 @@ tierIncrementTracker( tr_tier * tier ) tier->scrapeIntervalSec = DEFAULT_SCRAPE_INTERVAL_SEC; tier->announceIntervalSec = DEFAULT_ANNOUNCE_INTERVAL_SEC; tier->announceMinIntervalSec = DEFAULT_ANNOUNCE_MIN_INTERVAL_SEC; - tier->isAnnouncing = FALSE; - tier->isScraping = FALSE; + tier->isAnnouncing = false; + tier->isScraping = false; tier->lastAnnounceStartTime = 0; tier->lastScrapeStartTime = 0; } @@ -558,7 +558,7 @@ filter_trackers( tr_tracker_info * input, int input_count, int * setme_count ) char * scheme; char * host; char * path; - tr_bool is_duplicate = FALSE; + bool is_duplicate = false; tr_urlParse( input[i].announce, -1, &scheme, &host, &port, &path ); /* weed out one common source of duplicates: @@ -677,13 +677,13 @@ tr_announcerAddTorrent( tr_torrent * tor, **** ***/ -static tr_bool +static bool tierCanManualAnnounce( const tr_tier * tier ) { return tier->manualAnnounceAllowedAt <= tr_time( ); } -tr_bool +bool tr_announcerCanManualAnnounce( const tr_torrent * tor ) { int i; @@ -694,16 +694,16 @@ tr_announcerCanManualAnnounce( const tr_torrent * tor ) assert( tor->tiers != NULL ); if( !tor->isRunning ) - return FALSE; + return false; /* return true if any tier can manual announce */ n = tr_ptrArraySize( &tor->tiers->tiers ); tiers = (const tr_tier**) tr_ptrArrayBase( &tor->tiers->tiers ); for( i=0; i<n; ++i ) if( tierCanManualAnnounce( tiers[i] ) ) - return TRUE; + return true; - return FALSE; + return false; } time_t @@ -776,7 +776,7 @@ tier_announce_event_push( tr_tier * tier, /* special case #1: if we're adding a "stopped" event, * dump everything leading up to it except "completed" */ if( e == TR_ANNOUNCE_EVENT_STOPPED ) { - tr_bool has_completed = FALSE; + bool has_completed = false; const tr_announce_event c = TR_ANNOUNCE_EVENT_COMPLETED; for( i=0; !has_completed && i<tier->announce_event_count; ++i ) has_completed = c == tier->announce_events[i]; @@ -963,7 +963,7 @@ struct announce_data tr_announce_event event; /** If the request succeeds, the value for tier's "isRunning" flag */ - tr_bool isRunningOnSuccess; + bool isRunningOnSuccess; }; static void @@ -1035,8 +1035,8 @@ on_announce_done( tr_session * session, tier->lastAnnounceTime = now; tier->lastAnnounceTimedOut = response->did_timeout; - tier->lastAnnounceSucceeded = FALSE; - tier->isAnnouncing = FALSE; + tier->lastAnnounceSucceeded = false; + tier->isAnnouncing = false; tier->manualAnnounceAllowedAt = now + tier->announceMinIntervalSec; if( !response->did_connect ) @@ -1056,7 +1056,7 @@ on_announce_done( tr_session * session, { int i; const char * str; - const tr_bool isStopped = event == TR_ANNOUNCE_EVENT_STOPPED; + const bool isStopped = event == TR_ANNOUNCE_EVENT_STOPPED; publishErrorClear( tier ); @@ -1102,8 +1102,8 @@ on_announce_done( tr_session * session, tier->isRunning = data->isRunningOnSuccess; tier->scrapeAt = now + tier->scrapeIntervalSec; tier->lastScrapeTime = now; - tier->lastScrapeSucceeded = TRUE; - tier->lastAnnounceSucceeded = TRUE; + tier->lastScrapeSucceeded = true; + tier->lastAnnounceSucceeded = true; tier->lastAnnouncePeerCount = response->pex_count + response->pex6_count; @@ -1171,7 +1171,7 @@ tierAnnounce( tr_announcer * announcer, tr_tier * tier ) data->timeSent = now; data->event = announce_event; - tier->isAnnouncing = TRUE; + tier->isAnnouncing = true; tier->lastAnnounceStartTime = now; --announcer->slotsAvailable; @@ -1204,7 +1204,7 @@ on_scrape_error( tr_tier * tier, const char * errmsg ) /* schedule a rescrape */ interval = getRetryInterval( tier->currentTracker ); dbgmsg( tier, "Retrying scrape in %d seconds.", interval ); - tier->lastScrapeSucceeded = FALSE; + tier->lastScrapeSucceeded = false; tier->scrapeAt = tr_time() + interval; } @@ -1263,9 +1263,9 @@ on_scrape_done( tr_session * session, response->min_request_interval, response->errmsg ? response->errmsg : "none" ); - tier->isScraping = FALSE; + tier->isScraping = false; tier->lastScrapeTime = now; - tier->lastScrapeSucceeded = FALSE; + tier->lastScrapeSucceeded = false; tier->lastScrapeTimedOut = response->did_timeout; if( !response->did_connect ) @@ -1284,7 +1284,7 @@ on_scrape_done( tr_session * session, { tr_tracker * tracker; - tier->lastScrapeSucceeded = TRUE; + tier->lastScrapeSucceeded = true; tier->scrapeIntervalSec = MAX( DEFAULT_SCRAPE_INTERVAL_SEC, response->min_request_interval ); tier->scrapeAt = now + tier->scrapeIntervalSec; @@ -1353,7 +1353,7 @@ multiscrape( tr_announcer * announcer, tr_ptrArray * tiers ) continue; memcpy( req->info_hash[req->info_hash_count++], hash, SHA_DIGEST_LENGTH ); - tier->isScraping = TRUE; + tier->isScraping = true; tier->lastScrapeStartTime = now; break; } @@ -1366,7 +1366,7 @@ multiscrape( tr_announcer * announcer, tr_ptrArray * tiers ) tier_build_log_name( tier, req->log_name, sizeof( req->log_name ) ); memcpy( req->info_hash[req->info_hash_count++], hash, SHA_DIGEST_LENGTH ); - tier->isScraping = TRUE; + tier->isScraping = true; tier->lastScrapeStartTime = now; } } @@ -1391,7 +1391,7 @@ flushCloseMessages( tr_announcer * announcer ) tr_ptrArrayClear( &announcer->stops ); } -static tr_bool +static bool tierNeedsToAnnounce( const tr_tier * tier, const time_t now ) { return !tier->isAnnouncing @@ -1401,7 +1401,7 @@ tierNeedsToAnnounce( const tr_tier * tier, const time_t now ) && ( tier->announce_event_count > 0 ); } -static tr_bool +static bool tierNeedsToScrape( const tr_tier * tier, const time_t now ) { return ( !tier->isScraping ) @@ -1485,7 +1485,7 @@ onUpkeepTimer( int foo UNUSED, short bar UNUSED, void * vannouncer ) { tr_announcer * announcer = vannouncer; tr_session * session = announcer->session; - const tr_bool is_closing = session->isClosed; + const bool is_closing = session->isClosed; const time_t now = tr_time( ); tr_sessionLock( session ); @@ -1706,7 +1706,7 @@ tr_announcerResetTorrent( tr_announcer * announcer UNUSED, tr_torrent * tor ) tierCopyAttributes( t, o ); t->currentTracker = item; t->currentTrackerIndex = k; - t->wasCopied = TRUE; + t->wasCopied = true; trackerItemCopyAttributes( item, o->currentTracker ); dbgmsg( t, "attributes copied to tier %d, tracker %d" "from tier %d, tracker %d", diff --git a/libtransmission/announcer.h b/libtransmission/announcer.h index a42f47222..801fb56bf 100644 --- a/libtransmission/announcer.h +++ b/libtransmission/announcer.h @@ -76,7 +76,7 @@ struct tr_torrent_tiers * tr_announcerAddTorrent( tr_torrent * torrent, tr_tracker_callback * cb, void * cbdata ); -tr_bool tr_announcerHasBacklog( const struct tr_announcer * ); +bool tr_announcerHasBacklog( const struct tr_announcer * ); void tr_announcerResetTorrent( struct tr_announcer*, tr_torrent* ); @@ -85,7 +85,7 @@ void tr_announcerRemoveTorrent( struct tr_announcer * , void tr_announcerChangeMyPort( tr_torrent * ); -tr_bool tr_announcerCanManualAnnounce( const tr_torrent * ); +bool tr_announcerCanManualAnnounce( const tr_torrent * ); void tr_announcerManualAnnounce( tr_torrent * ); @@ -112,7 +112,7 @@ void tr_tracker_udp_upkeep( tr_session * session ); void tr_tracker_udp_close( tr_session * session ); -tr_bool tr_tracker_udp_is_empty( const tr_session * session ); +bool tr_tracker_udp_is_empty( const tr_session * session ); diff --git a/libtransmission/bandwidth.c b/libtransmission/bandwidth.c index 72cf2e0b4..5be82fd21 100644 --- a/libtransmission/bandwidth.c +++ b/libtransmission/bandwidth.c @@ -103,8 +103,8 @@ tr_bandwidthConstruct( tr_bandwidth * b, tr_session * session, tr_bandwidth * pa b->session = session; b->children = TR_PTR_ARRAY_INIT; b->magicNumber = BANDWIDTH_MAGIC_NUMBER; - b->band[TR_UP].honorParentLimits = TRUE; - b->band[TR_DOWN].honorParentLimits = TRUE; + b->band[TR_UP].honorParentLimits = true; + b->band[TR_DOWN].honorParentLimits = true; tr_bandwidthSetParent( b, parent ); return b; } @@ -387,7 +387,7 @@ void tr_bandwidthUsed( tr_bandwidth * b, tr_direction dir, size_t byteCount, - tr_bool isPieceData, + bool isPieceData, uint64_t now ) { struct tr_band * band; diff --git a/libtransmission/bandwidth.h b/libtransmission/bandwidth.h index 471c5ec2a..9ae629efc 100644 --- a/libtransmission/bandwidth.h +++ b/libtransmission/bandwidth.h @@ -55,8 +55,8 @@ struct bratecontrol * it's included in the header for inlining and composition. */ struct tr_band { - tr_bool isLimited; - tr_bool honorParentLimits; + bool isLimited; + bool honorParentLimits; unsigned int bytesLeft; unsigned int desiredSpeed_Bps; struct bratecontrol raw; @@ -141,7 +141,7 @@ static inline void tr_bandwidthFree( tr_bandwidth * bandwidth ) } /** @brief test to see if the pointer refers to a live bandwidth object */ -static inline tr_bool tr_isBandwidth( const tr_bandwidth * b ) +static inline bool tr_isBandwidth( const tr_bandwidth * b ) { return ( b != NULL ) && ( b->magicNumber == BANDWIDTH_MAGIC_NUMBER ); } @@ -155,12 +155,12 @@ static inline tr_bool tr_isBandwidth( const tr_bandwidth * b ) * @see tr_bandwidthAllocate * @see tr_bandwidthGetDesiredSpeed */ -static inline tr_bool tr_bandwidthSetDesiredSpeed_Bps( tr_bandwidth * bandwidth, - tr_direction dir, - unsigned int desiredSpeed ) +static inline bool tr_bandwidthSetDesiredSpeed_Bps( tr_bandwidth * bandwidth, + tr_direction dir, + unsigned int desiredSpeed ) { unsigned int * value = &bandwidth->band[dir].desiredSpeed_Bps; - const tr_bool didChange = desiredSpeed != *value; + const bool didChange = desiredSpeed != *value; *value = desiredSpeed; return didChange; } @@ -178,12 +178,12 @@ tr_bandwidthGetDesiredSpeed_Bps( const tr_bandwidth * bandwidth, tr_direction d /** * @brief Set whether or not this bandwidth should throttle its peer-io's speeds */ -static inline tr_bool tr_bandwidthSetLimited( tr_bandwidth * bandwidth, - tr_direction dir, - tr_bool isLimited ) +static inline bool tr_bandwidthSetLimited( tr_bandwidth * bandwidth, + tr_direction dir, + bool isLimited ) { - tr_bool * value = &bandwidth->band[dir].isLimited; - const tr_bool didChange = isLimited != *value; + bool * value = &bandwidth->band[dir].isLimited; + const bool didChange = isLimited != *value; *value = isLimited; return didChange; } @@ -191,8 +191,8 @@ static inline tr_bool tr_bandwidthSetLimited( tr_bandwidth * bandwidth, /** * @return nonzero if this bandwidth throttles its peer-ios speeds */ -static inline tr_bool tr_bandwidthIsLimited( const tr_bandwidth * bandwidth, - tr_direction dir ) +static inline bool tr_bandwidthIsLimited( const tr_bandwidth * bandwidth, + tr_direction dir ) { return bandwidth->band[dir].isLimited; } @@ -232,7 +232,7 @@ unsigned int tr_bandwidthGetPieceSpeed_Bps( const tr_bandwidth * bandwidth, void tr_bandwidthUsed ( tr_bandwidth * bandwidth, tr_direction direction, size_t byteCount, - tr_bool isPieceData, + bool isPieceData, uint64_t now ); /****** @@ -248,18 +248,18 @@ void tr_bandwidthSetParent ( tr_bandwidth * bandwidth, * But when we set a torrent's speed mode to TR_SPEEDLIMIT_UNLIMITED, then * in that particular case we want to ignore the global speed limit... */ -static inline tr_bool tr_bandwidthHonorParentLimits ( tr_bandwidth * bandwidth, - tr_direction direction, - tr_bool isEnabled ) +static inline bool tr_bandwidthHonorParentLimits ( tr_bandwidth * bandwidth, + tr_direction direction, + bool isEnabled ) { - tr_bool * value = &bandwidth->band[direction].honorParentLimits; - const tr_bool didChange = isEnabled != *value; + bool * value = &bandwidth->band[direction].honorParentLimits; + const bool didChange = isEnabled != *value; *value = isEnabled; return didChange; } -static inline tr_bool tr_bandwidthAreParentLimitsHonored( tr_bandwidth * bandwidth, - tr_direction direction ) +static inline bool tr_bandwidthAreParentLimitsHonored( tr_bandwidth * bandwidth, + tr_direction direction ) { assert( tr_isBandwidth( bandwidth ) ); assert( tr_isDirection( direction ) ); diff --git a/libtransmission/bencode-test.c b/libtransmission/bencode-test.c index 10d357f48..979cd091b 100644 --- a/libtransmission/bencode-test.c +++ b/libtransmission/bencode-test.c @@ -235,32 +235,32 @@ testParse( void ) tr_free( saved ); tr_bencFree( &val ); - if( ( err = testString( "llleee", TRUE ) ) ) + if( ( err = testString( "llleee", true ) ) ) return err; - if( ( err = testString( "d3:cow3:moo4:spam4:eggse", TRUE ) ) ) + if( ( err = testString( "d3:cow3:moo4:spam4:eggse", true ) ) ) return err; - if( ( err = testString( "d4:spaml1:a1:bee", TRUE ) ) ) + if( ( err = testString( "d4:spaml1:a1:bee", true ) ) ) return err; if( ( err = testString( "d5:greenli1ei2ei3ee4:spamd1:ai123e3:keyi214eee", - TRUE ) ) ) + true ) ) ) return err; if( ( err = testString( "d9:publisher3:bob17:publisher-webpage15:www.example.com18:publisher.location4:homee", - TRUE ) ) ) + true ) ) ) return err; if( ( err = testString( "d8:completei1e8:intervali1800e12:min intervali1800e5:peers0:e", - TRUE ) ) ) + true ) ) ) return err; - if( ( err = testString( "d1:ai0e1:be", FALSE ) ) ) /* odd number of children + if( ( err = testString( "d1:ai0e1:be", false ) ) ) /* odd number of children */ return err; - if( ( err = testString( "", FALSE ) ) ) + if( ( err = testString( "", false ) ) ) return err; - if( ( err = testString( " ", FALSE ) ) ) + if( ( err = testString( " ", false ) ) ) return err; /* nested containers @@ -458,13 +458,13 @@ testBool( void ) { tr_benc top; int64_t intVal; - tr_bool boolVal; + bool boolVal; tr_bencInitDict( &top, 0 ); - tr_bencDictAddBool( &top, "key1", FALSE ); + tr_bencDictAddBool( &top, "key1", false ); tr_bencDictAddBool( &top, "key2", 0 ); - tr_bencDictAddInt ( &top, "key3", TRUE ); + tr_bencDictAddInt ( &top, "key3", true ); tr_bencDictAddInt ( &top, "key4", 1 ); check( tr_bencDictFindBool( &top, "key1", &boolVal ) ) check( !boolVal ) @@ -495,13 +495,13 @@ testParse2( void ) int64_t intVal; const char * strVal; double realVal; - tr_bool boolVal; + bool boolVal; int len; char * benc; const uint8_t * end; tr_bencInitDict( &top, 0 ); - tr_bencDictAddBool( &top, "this-is-a-bool", TRUE ); + tr_bencDictAddBool( &top, "this-is-a-bool", true ); tr_bencDictAddInt( &top, "this-is-an-int", 1234 ); tr_bencDictAddReal( &top, "this-is-a-real", 0.5 ); tr_bencDictAddStr( &top, "this-is-a-string", "this-is-a-string" ); @@ -514,7 +514,7 @@ testParse2( void ) check( tr_bencDictFindInt( &top, "this-is-an-int", &intVal ) ) check( intVal == 1234 ) check( tr_bencDictFindBool( &top, "this-is-a-bool", &boolVal ) ) - check( boolVal == TRUE ) + check( boolVal == true ) check( tr_bencDictFindStr( &top, "this-is-a-string", &strVal ) ) check( !strcmp( strVal, "this-is-a-string" ) ) check( tr_bencDictFindReal( &top, "this-is-a-real", &realVal ) ) diff --git a/libtransmission/bencode.c b/libtransmission/bencode.c index 353c5c4f9..f582496f2 100644 --- a/libtransmission/bencode.c +++ b/libtransmission/bencode.c @@ -48,13 +48,13 @@ *** **/ -static tr_bool +static bool isContainer( const tr_benc * val ) { return tr_bencIsList( val ) || tr_bencIsDict( val ); } -static tr_bool +static bool isSomething( const tr_benc * val ) { return isContainer( val ) || tr_bencIsInt( val ) @@ -404,7 +404,7 @@ tr_bencDictFind( tr_benc * val, const char * key ) return i < 0 ? NULL : &val->val.l.vals[i + 1]; } -static tr_bool +static bool tr_bencDictFindType( tr_benc * dict, const char * key, int type, tr_benc ** setme ) { return tr_bencIsType( *setme = tr_bencDictFind( dict, key ), type ); @@ -446,11 +446,11 @@ tr_benc_warning( const char * err ) fprintf( stderr, "warning: %s\n", err ); } -tr_bool +bool tr_bencGetInt( const tr_benc * val, int64_t * setme ) { - tr_bool success = FALSE; + bool success = false; if( !success && (( success = tr_bencIsInt( val )))) if( setme ) @@ -465,10 +465,10 @@ tr_bencGetInt( const tr_benc * val, return success; } -tr_bool +bool tr_bencGetStr( const tr_benc * val, const char ** setme ) { - const tr_bool success = tr_bencIsString( val ); + const bool success = tr_bencIsString( val ); if( success ) *setme = getStr( val ); @@ -476,10 +476,10 @@ tr_bencGetStr( const tr_benc * val, const char ** setme ) return success; } -tr_bool +bool tr_bencGetRaw( const tr_benc * val, const uint8_t ** setme_raw, size_t * setme_len ) { - const tr_bool success = tr_bencIsString( val ); + const bool success = tr_bencIsString( val ); if( success ) { *setme_raw = (uint8_t*) getStr(val); @@ -489,11 +489,11 @@ tr_bencGetRaw( const tr_benc * val, const uint8_t ** setme_raw, size_t * setme_l return success; } -tr_bool -tr_bencGetBool( const tr_benc * val, tr_bool * setme ) +bool +tr_bencGetBool( const tr_benc * val, bool * setme ) { const char * str; - tr_bool success = FALSE; + bool success = false; if(( success = tr_bencIsBool( val ))) *setme = val->val.b; @@ -509,10 +509,10 @@ tr_bencGetBool( const tr_benc * val, tr_bool * setme ) return success; } -tr_bool +bool tr_bencGetReal( const tr_benc * val, double * setme ) { - tr_bool success = FALSE; + bool success = false; if( !success && (( success = tr_bencIsReal( val )))) *setme = val->val.d; @@ -540,43 +540,43 @@ tr_bencGetReal( const tr_benc * val, double * setme ) return success; } -tr_bool +bool tr_bencDictFindInt( tr_benc * dict, const char * key, int64_t * setme ) { return tr_bencGetInt( tr_bencDictFind( dict, key ), setme ); } -tr_bool -tr_bencDictFindBool( tr_benc * dict, const char * key, tr_bool * setme ) +bool +tr_bencDictFindBool( tr_benc * dict, const char * key, bool * setme ) { return tr_bencGetBool( tr_bencDictFind( dict, key ), setme ); } -tr_bool +bool tr_bencDictFindReal( tr_benc * dict, const char * key, double * setme ) { return tr_bencGetReal( tr_bencDictFind( dict, key ), setme ); } -tr_bool +bool tr_bencDictFindStr( tr_benc * dict, const char * key, const char ** setme ) { return tr_bencGetStr( tr_bencDictFind( dict, key ), setme ); } -tr_bool +bool tr_bencDictFindList( tr_benc * dict, const char * key, tr_benc ** setme ) { return tr_bencDictFindType( dict, key, TR_TYPE_LIST, setme ); } -tr_bool +bool tr_bencDictFindDict( tr_benc * dict, const char * key, tr_benc ** setme ) { return tr_bencDictFindType( dict, key, TR_TYPE_DICT, setme ); } -tr_bool +bool tr_bencDictFindRaw( tr_benc * dict, const char * key, const uint8_t ** setme_raw, size_t * setme_len ) { return tr_bencGetRaw( tr_bencDictFind( dict, key ), setme_raw, setme_len ); @@ -705,7 +705,7 @@ tr_bencListAddReal( tr_benc * list, double val ) } tr_benc * -tr_bencListAddBool( tr_benc * list, tr_bool val ) +tr_bencListAddBool( tr_benc * list, bool val ) { tr_benc * node = tr_bencListAdd( list ); tr_bencInitBool( node, val ); @@ -799,7 +799,7 @@ tr_bencDictAddInt( tr_benc * dict, } tr_benc* -tr_bencDictAddBool( tr_benc * dict, const char * key, tr_bool val ) +tr_bencDictAddBool( tr_benc * dict, const char * key, bool val ) { tr_benc * child = dictFindOrAdd( dict, key, TR_TYPE_BOOL ); tr_bencInitBool( child, val ); @@ -942,7 +942,7 @@ struct SaveNode }; static void -nodeInitDict( struct SaveNode * node, const tr_benc * val, tr_bool sort_dicts ) +nodeInitDict( struct SaveNode * node, const tr_benc * val, bool sort_dicts ) { const int n = val->val.l.count; const int nKeys = n / 2; @@ -1006,7 +1006,7 @@ nodeInitLeaf( struct SaveNode * node, const tr_benc * val ) } static void -nodeInit( struct SaveNode * node, const tr_benc * val, tr_bool sort_dicts ) +nodeInit( struct SaveNode * node, const tr_benc * val, bool sort_dicts ) { static const struct SaveNode INIT_NODE = { NULL, 0, 0, 0, NULL }; *node = INIT_NODE; @@ -1038,7 +1038,7 @@ static void bencWalk( const tr_benc * top, const struct WalkFuncs * walkFuncs, void * user_data, - tr_bool sort_dicts ) + bool sort_dicts ) { int stackSize = 0; int stackAlloc = 64; @@ -1054,7 +1054,7 @@ bencWalk( const tr_benc * top, if( !node->valIsVisited ) { val = node->val; - node->valIsVisited = TRUE; + node->valIsVisited = true; } else if( node->childIndex < node->childCount ) { @@ -1225,7 +1225,7 @@ void tr_bencFree( tr_benc * val ) { if( isSomething( val ) ) - bencWalk( val, &freeWalkFuncs, NULL, FALSE ); + bencWalk( val, &freeWalkFuncs, NULL, false ); } /*** @@ -1243,7 +1243,7 @@ struct ParentState /** @brief Implementation helper class for tr_bencToBuffer(TR_FMT_JSON) */ struct jsonWalk { - tr_bool doIndent; + bool doIndent; tr_list * parents; struct evbuffer * out; }; @@ -1277,7 +1277,7 @@ jsonChildFunc( struct jsonWalk * data ) if( !( i % 2 ) ) evbuffer_add( data->out, ": ", data->doIndent ? 2 : 1 ); else { - const tr_bool isLast = parentState->childIndex == parentState->childCount; + const bool isLast = parentState->childIndex == parentState->childCount; if( !isLast ) { evbuffer_add( data->out, ", ", data->doIndent ? 2 : 1 ); jsonIndent( data ); @@ -1288,7 +1288,7 @@ jsonChildFunc( struct jsonWalk * data ) case TR_TYPE_LIST: { - const tr_bool isLast = ++parentState->childIndex == parentState->childCount; + const bool isLast = ++parentState->childIndex == parentState->childCount; if( !isLast ) { evbuffer_add( data->out, ", ", data->doIndent ? 2 : 1 ); jsonIndent( data ); @@ -1446,7 +1446,7 @@ jsonContainerEndFunc( const tr_benc * val, void * vdata ) { struct jsonWalk * data = vdata; - int emptyContainer = FALSE; + int emptyContainer = false; jsonPopParent( data ); if( !emptyContainer ) @@ -1480,7 +1480,7 @@ tr_bencListCopy( tr_benc * target, const tr_benc * src ) { if( tr_bencIsBool( val ) ) { - tr_bool boolVal = 0; + bool boolVal = 0; tr_bencGetBool( val, &boolVal ); tr_bencListAddBool( target, boolVal ); } @@ -1526,10 +1526,10 @@ tr_bencDictSize( const tr_benc * dict ) return count; } -tr_bool +bool tr_bencDictChild( tr_benc * dict, size_t n, const char ** key, tr_benc ** val ) { - tr_bool success = 0; + bool success = 0; assert( tr_bencIsDict( dict ) ); @@ -1563,7 +1563,7 @@ tr_bencMergeDicts( tr_benc * target, const tr_benc * source ) { if( tr_bencIsBool( val ) ) { - tr_bool boolVal; + bool boolVal; tr_bencGetBool( val, &boolVal ); tr_bencDictAddBool( target, key, boolVal ); } @@ -1615,7 +1615,7 @@ tr_bencToBuf( const tr_benc * top, tr_fmt_mode mode, struct evbuffer * buf ) switch( mode ) { case TR_FMT_BENC: - bencWalk( top, &saveFuncs, buf, TRUE ); + bencWalk( top, &saveFuncs, buf, true ); break; case TR_FMT_JSON: @@ -1624,7 +1624,7 @@ tr_bencToBuf( const tr_benc * top, tr_fmt_mode mode, struct evbuffer * buf ) data.doIndent = mode==TR_FMT_JSON; data.out = buf; data.parents = NULL; - bencWalk( top, &jsonWalkFuncs, &data, TRUE ); + bencWalk( top, &jsonWalkFuncs, &data, true ); if( evbuffer_get_length( buf ) ) evbuffer_add_printf( buf, "\n" ); break; diff --git a/libtransmission/bencode.h b/libtransmission/bencode.h index 96ee2e105..88de431ee 100644 --- a/libtransmission/bencode.h +++ b/libtransmission/bencode.h @@ -138,7 +138,7 @@ int tr_bencListReserve( tr_benc *, size_t reserveCount ); tr_benc * tr_bencListAdd( tr_benc * ); -tr_benc * tr_bencListAddBool( tr_benc *, tr_bool val ); +tr_benc * tr_bencListAddBool( tr_benc *, bool val ); tr_benc * tr_bencListAddInt( tr_benc *, int64_t val ); @@ -172,7 +172,7 @@ tr_benc * tr_bencDictAddReal( tr_benc *, const char * key, double ); tr_benc * tr_bencDictAddInt( tr_benc *, const char * key, int64_t ); -tr_benc * tr_bencDictAddBool( tr_benc *, const char * key, tr_bool ); +tr_benc * tr_bencDictAddBool( tr_benc *, const char * key, bool ); tr_benc * tr_bencDictAddStr( tr_benc *, const char * key, const char * ); @@ -183,23 +183,23 @@ tr_benc * tr_bencDictAddDict( tr_benc *, const char * key, size_t reserve ); tr_benc * tr_bencDictAddRaw( tr_benc *, const char * key, const void * raw, size_t rawlen ); -tr_bool tr_bencDictChild( tr_benc *, size_t i, const char ** key, tr_benc ** val ); +bool tr_bencDictChild( tr_benc *, size_t i, const char ** key, tr_benc ** val ); tr_benc* tr_bencDictFind( tr_benc *, const char * key ); -tr_bool tr_bencDictFindList( tr_benc *, const char * key, tr_benc ** setme ); +bool tr_bencDictFindList( tr_benc *, const char * key, tr_benc ** setme ); -tr_bool tr_bencDictFindDict( tr_benc *, const char * key, tr_benc ** setme ); +bool tr_bencDictFindDict( tr_benc *, const char * key, tr_benc ** setme ); -tr_bool tr_bencDictFindInt( tr_benc *, const char * key, int64_t * setme ); +bool tr_bencDictFindInt( tr_benc *, const char * key, int64_t * setme ); -tr_bool tr_bencDictFindReal( tr_benc *, const char * key, double * setme ); +bool tr_bencDictFindReal( tr_benc *, const char * key, double * setme ); -tr_bool tr_bencDictFindBool( tr_benc *, const char * key, tr_bool * setme ); +bool tr_bencDictFindBool( tr_benc *, const char * key, bool * setme ); -tr_bool tr_bencDictFindStr( tr_benc *, const char * key, const char ** setme ); +bool tr_bencDictFindStr( tr_benc *, const char * key, const char ** setme ); -tr_bool tr_bencDictFindRaw( tr_benc *, const char * key, +bool tr_bencDictFindRaw( tr_benc *, const char * key, const uint8_t ** setme_raw, size_t * setme_len ); /*** @@ -207,33 +207,33 @@ tr_bool tr_bencDictFindRaw( tr_benc *, const char * key, ***/ /** @brief Get an int64_t from a variant object - @return TRUE if successful, or FALSE if the variant could not be represented as an int64_t */ -tr_bool tr_bencGetInt( const tr_benc * val, int64_t * setme ); + @return true if successful, or false if the variant could not be represented as an int64_t */ +bool tr_bencGetInt( const tr_benc * val, int64_t * setme ); /** @brief Get an string from a variant object - @return TRUE if successful, or FALSE if the variant could not be represented as a string */ -tr_bool tr_bencGetStr( const tr_benc * val, const char ** setme ); + @return true if successful, or false if the variant could not be represented as a string */ +bool tr_bencGetStr( const tr_benc * val, const char ** setme ); /** @brief Get a raw byte array from a variant object - @return TRUE if successful, or FALSE if the variant could not be represented as a raw byte array */ -tr_bool tr_bencGetRaw( const tr_benc * val, const uint8_t ** setme_raw, size_t * setme_len ); + @return true if successful, or false if the variant could not be represented as a raw byte array */ +bool tr_bencGetRaw( const tr_benc * val, const uint8_t ** setme_raw, size_t * setme_len ); /** @brief Get a boolean from a variant object - @return TRUE if successful, or FALSE if the variant could not be represented as a boolean */ -tr_bool tr_bencGetBool( const tr_benc * val, tr_bool * setme ); + @return true if successful, or false if the variant could not be represented as a boolean */ +bool tr_bencGetBool( const tr_benc * val, bool * setme ); /** @brief Get a floating-point number from a variant object - @return TRUE if successful, or FALSE if the variant could not be represented as a floating-point number */ -tr_bool tr_bencGetReal( const tr_benc * val, double * setme ); + @return true if successful, or false if the variant could not be represented as a floating-point number */ +bool tr_bencGetReal( const tr_benc * val, double * setme ); -static inline tr_bool tr_bencIsType ( const tr_benc * b, int type ) { return ( b != NULL ) && ( b->type == type ); } +static inline bool tr_bencIsType ( const tr_benc * b, int type ) { return ( b != NULL ) && ( b->type == type ); } -static inline tr_bool tr_bencIsInt ( const tr_benc * b ) { return tr_bencIsType( b, TR_TYPE_INT ); } -static inline tr_bool tr_bencIsDict ( const tr_benc * b ) { return tr_bencIsType( b, TR_TYPE_DICT ); } -static inline tr_bool tr_bencIsList ( const tr_benc * b ) { return tr_bencIsType( b, TR_TYPE_LIST ); } -static inline tr_bool tr_bencIsString( const tr_benc * b ) { return tr_bencIsType( b, TR_TYPE_STR ); } -static inline tr_bool tr_bencIsBool ( const tr_benc * b ) { return tr_bencIsType( b, TR_TYPE_BOOL ); } -static inline tr_bool tr_bencIsReal ( const tr_benc * b ) { return tr_bencIsType( b, TR_TYPE_REAL ); } +static inline bool tr_bencIsInt ( const tr_benc * b ) { return tr_bencIsType( b, TR_TYPE_INT ); } +static inline bool tr_bencIsDict ( const tr_benc * b ) { return tr_bencIsType( b, TR_TYPE_DICT ); } +static inline bool tr_bencIsList ( const tr_benc * b ) { return tr_bencIsType( b, TR_TYPE_LIST ); } +static inline bool tr_bencIsString( const tr_benc * b ) { return tr_bencIsType( b, TR_TYPE_STR ); } +static inline bool tr_bencIsBool ( const tr_benc * b ) { return tr_bencIsType( b, TR_TYPE_BOOL ); } +static inline bool tr_bencIsReal ( const tr_benc * b ) { return tr_bencIsType( b, TR_TYPE_REAL ); } /** @brief Private function that's exposed here only for unit tests */ int tr_bencParseInt( const uint8_t * buf, diff --git a/libtransmission/bitfield.h b/libtransmission/bitfield.h index 3d77d779c..862879cbf 100644 --- a/libtransmission/bitfield.h +++ b/libtransmission/bitfield.h @@ -60,20 +60,20 @@ tr_bitfield* tr_bitfieldOr( tr_bitfield*, const tr_bitfield* ); has none of tr_bitfieldHas()'s safety checks, so you need to call tr_bitfieldTestFast() first before you start looping. */ -static inline tr_bool tr_bitfieldHasFast( const tr_bitfield * b, const size_t nth ) +static inline bool tr_bitfieldHasFast( const tr_bitfield * b, const size_t nth ) { return ( b->bits[nth>>3u] << ( nth & 7u ) & 0x80 ) != 0; } /** @param high the highest nth bit you're going to access */ -static inline tr_bool tr_bitfieldTestFast( const tr_bitfield * b, const size_t high ) +static inline bool tr_bitfieldTestFast( const tr_bitfield * b, const size_t high ) { return ( b != NULL ) && ( b->bits != NULL ) && ( high < b->bitCount ); } -static inline tr_bool tr_bitfieldHas( const tr_bitfield * b, size_t nth ) +static inline bool tr_bitfieldHas( const tr_bitfield * b, size_t nth ) { return tr_bitfieldTestFast( b, nth ) && tr_bitfieldHasFast( b, nth ); } diff --git a/libtransmission/bitset.c b/libtransmission/bitset.c index 97f0239f1..dfa8d9a0a 100644 --- a/libtransmission/bitset.c +++ b/libtransmission/bitset.c @@ -18,7 +18,7 @@ #include "bitset.h" #include "utils.h" -const tr_bitset TR_BITSET_INIT = { FALSE, FALSE, { NULL, 0, 0 } }; +const tr_bitset TR_BITSET_INIT = { false, false, { NULL, 0, 0 } }; void tr_bitsetConstruct( tr_bitset * b, size_t bitCount ) @@ -39,22 +39,22 @@ tr_bitsetClear( tr_bitset * b ) { tr_free( b->bitfield.bits ); b->bitfield.bits = NULL; - b->haveAll = FALSE; - b->haveNone = FALSE; + b->haveAll = false; + b->haveNone = false; } void tr_bitsetSetHaveAll( tr_bitset * b ) { tr_bitsetClear( b ); - b->haveAll = TRUE; + b->haveAll = true; } void tr_bitsetSetHaveNone( tr_bitset * b ) { tr_bitsetClear( b ); - b->haveNone = TRUE; + b->haveNone = true; } void @@ -91,7 +91,7 @@ tr_bitsetAdd( tr_bitset * b, size_t i ) if( b->haveAll ) return; - b->haveNone = FALSE; + b->haveNone = false; /* do we need to resize the bitfield to accomodate this bit? */ if( !bf->bits || ( bf->bitCount < i+1 ) ) @@ -114,7 +114,7 @@ tr_bitsetRem( tr_bitset * b, size_t i ) if( b->haveNone ) return; - b->haveAll = FALSE; + b->haveAll = false; if( !b->bitfield.bits ) { @@ -131,7 +131,7 @@ tr_bitsetRemRange( tr_bitset * b, size_t begin, size_t end ) if( b->haveNone ) return; - b->haveAll = FALSE; + b->haveAll = false; if( !b->bitfield.bits ) { tr_bitfieldConstruct( &b->bitfield, b->bitfield.bitCount ); @@ -145,12 +145,12 @@ tr_bitsetRemRange( tr_bitset * b, size_t begin, size_t end ) **** ***/ -tr_bool +bool tr_bitsetHas( const tr_bitset * b, const size_t nth ) { - if( b->haveAll ) return TRUE; - if( b->haveNone ) return FALSE; - if( nth >= b->bitfield.bitCount ) return FALSE; + if( b->haveAll ) return true; + if( b->haveNone ) return false; + if( nth >= b->bitfield.bitCount ) return false; return tr_bitfieldHas( &b->bitfield, nth ); } @@ -184,34 +184,34 @@ tr_bitsetOr( tr_bitfield * a, const tr_bitset * b ) **** ***/ -tr_bool +bool tr_bitsetFromBenc( tr_bitset * b, tr_benc * benc ) { size_t buflen; const uint8_t * buf; - tr_bool handled = FALSE; + bool handled = false; if( tr_bencGetRaw( benc, &buf, &buflen ) ) { if( ( buflen == 3 ) && !memcmp( buf, "all", 3 ) ) { tr_bitsetSetHaveAll( b ); - handled = TRUE; + handled = true; } else if( ( buflen == 4 ) && !memcmp( buf, "none", 4 ) ) { tr_bitsetSetHaveNone( b ); - handled = TRUE; + handled = true; } else { - b->haveAll = FALSE; - b->haveNone = FALSE; + b->haveAll = false; + b->haveNone = false; tr_free( b->bitfield.bits ); b->bitfield.bits = tr_memdup( buf, buflen ); b->bitfield.byteCount = buflen; b->bitfield.bitCount = buflen * 8; - handled = TRUE; + handled = true; } } diff --git a/libtransmission/bitset.h b/libtransmission/bitset.h index b4f98a2ec..bebfb7baa 100644 --- a/libtransmission/bitset.h +++ b/libtransmission/bitset.h @@ -23,8 +23,8 @@ /** @brief like a tr_bitfield, but supports haveAll and haveNone */ typedef struct tr_bitset { - tr_bool haveAll; - tr_bool haveNone; + bool haveAll; + bool haveNone; tr_bitfield bitfield; } tr_bitset; @@ -44,7 +44,7 @@ void tr_bitsetRem( tr_bitset * b, size_t i ); void tr_bitsetRemRange ( tr_bitset * b, size_t begin, size_t end ); struct tr_benc; -tr_bool tr_bitsetFromBenc( tr_bitset * bitset, struct tr_benc * benc ); +bool tr_bitsetFromBenc( tr_bitset * bitset, struct tr_benc * benc ); void tr_bitsetToBenc( const tr_bitset * bitset, struct tr_benc * benc ); /*** @@ -53,7 +53,7 @@ void tr_bitsetToBenc( const tr_bitset * bitset, struct tr_benc * benc ); double tr_bitsetPercent( const tr_bitset * b ); -tr_bool tr_bitsetHas( const tr_bitset * b, const size_t nth ); +bool tr_bitsetHas( const tr_bitset * b, const size_t nth ); size_t tr_bitsetCountRange( const tr_bitset * b, const size_t begin, const size_t end ); void tr_bitsetOr( tr_bitfield * a, const tr_bitset * b ); diff --git a/libtransmission/blocklist-test.c b/libtransmission/blocklist-test.c index b62acb1b0..767e0811a 100644 --- a/libtransmission/blocklist-test.c +++ b/libtransmission/blocklist-test.c @@ -65,7 +65,7 @@ main( void ) remove( tmpfile_txt ); remove( tmpfile_bin ); - b = _tr_blocklistNew( tmpfile_bin, TRUE ); + b = _tr_blocklistNew( tmpfile_bin, true ); createTestBlocklist( tmpfile_txt ); _tr_blocklistSetContent( b, tmpfile_txt ); diff --git a/libtransmission/blocklist.c b/libtransmission/blocklist.c index 3ee18f83e..dde097811 100644 --- a/libtransmission/blocklist.c +++ b/libtransmission/blocklist.c @@ -54,7 +54,7 @@ struct tr_ipv4_range struct tr_blocklist { - tr_bool isEnabled; + bool isEnabled; int fd; size_t ruleCount; size_t byteCount; @@ -147,7 +147,7 @@ blocklistDelete( tr_blocklist * b ) ***/ tr_blocklist * -_tr_blocklistNew( const char * filename, tr_bool isEnabled ) +_tr_blocklistNew( const char * filename, bool isEnabled ) { tr_blocklist * b; @@ -235,7 +235,7 @@ _tr_blocklistHasAddress( tr_blocklist * b, * http://wiki.phoenixlabs.org/wiki/P2P_Format * http://en.wikipedia.org/wiki/PeerGuardian#P2P_plaintext_format */ -static tr_bool +static bool parseLine1( const char * line, struct tr_ipv4_range * range ) { char * walk; @@ -246,32 +246,32 @@ parseLine1( const char * line, struct tr_ipv4_range * range ) walk = strrchr( line, ':' ); if( !walk ) - return FALSE; + return false; ++walk; /* walk past the colon */ if( sscanf( walk, "%d.%d.%d.%d-%d.%d.%d.%d", &b[0], &b[1], &b[2], &b[3], &e[0], &e[1], &e[2], &e[3] ) != 8 ) - return FALSE; + return false; tr_snprintf( str, sizeof( str ), "%d.%d.%d.%d", b[0], b[1], b[2], b[3] ); if( tr_pton( str, &addr ) == NULL ) - return FALSE; + return false; range->begin = ntohl( addr.addr.addr4.s_addr ); tr_snprintf( str, sizeof( str ), "%d.%d.%d.%d", e[0], e[1], e[2], e[3] ); if( tr_pton( str, &addr ) == NULL ) - return FALSE; + return false; range->end = ntohl( addr.addr.addr4.s_addr ); - return TRUE; + return true; } /* * DAT format: "000.000.000.000 - 000.255.255.255 , 000 , invalid ip" * http://wiki.phoenixlabs.org/wiki/DAT_Format */ -static tr_bool +static bool parseLine2( const char * line, struct tr_ipv4_range * range ) { int unk; @@ -284,19 +284,19 @@ parseLine2( const char * line, struct tr_ipv4_range * range ) &a[0], &a[1], &a[2], &a[3], &b[0], &b[1], &b[2], &b[3], &unk ) != 9 ) - return FALSE; + return false; tr_snprintf( str, sizeof(str), "%d.%d.%d.%d", a[0], a[1], a[2], a[3] ); if( tr_pton( str, &addr ) == NULL ) - return FALSE; + return false; range->begin = ntohl( addr.addr.addr4.s_addr ); tr_snprintf( str, sizeof(str), "%d.%d.%d.%d", b[0], b[1], b[2], b[3] ); if( tr_pton( str, &addr ) == NULL ) - return FALSE; + return false; range->end = ntohl( addr.addr.addr4.s_addr ); - return TRUE; + return true; } static int diff --git a/libtransmission/blocklist.h b/libtransmission/blocklist.h index 4d003faab..b19d5ac16 100644 --- a/libtransmission/blocklist.h +++ b/libtransmission/blocklist.h @@ -21,7 +21,7 @@ struct tr_address; typedef struct tr_blocklist tr_blocklist; tr_blocklist* _tr_blocklistNew ( const char * filename, - tr_bool isEnabled ); + bool isEnabled ); int _tr_blocklistExists ( const tr_blocklist * b ); diff --git a/libtransmission/cache.c b/libtransmission/cache.c index 127300917..1ee977508 100644 --- a/libtransmission/cache.c +++ b/libtransmission/cache.c @@ -70,8 +70,8 @@ struct run_info int pos; int rank; time_t last_block_time; - tr_bool is_multi_piece; - tr_bool is_piece_done; + bool is_multi_piece; + bool is_piece_done; unsigned len; }; @@ -98,7 +98,7 @@ getBlockRun( const tr_cache * cache, int pos, struct run_info * info ) const struct cache_block * b = blocks[i-1]; info->last_block_time = b->time; info->is_piece_done = tr_cpPieceIsComplete( &b->tor->completion, b->piece ); - info->is_multi_piece = b->piece != blocks[pos]->piece ? TRUE : FALSE; + info->is_multi_piece = b->piece != blocks[pos]->piece ? true : false; info->len = i - pos; info->pos = pos; } diff --git a/libtransmission/clients.c b/libtransmission/clients.c index df5904d84..484d2c351 100644 --- a/libtransmission/clients.c +++ b/libtransmission/clients.c @@ -125,7 +125,7 @@ decodeBitCometClient( char * buf, size_t buflen, const uint8_t * id ) if( !memcmp( id, "exbc", 4 ) ) mod = ""; else if( !memcmp( id, "FUTB", 4 )) mod = "(Solidox Mod) "; else if( !memcmp( id, "xUTB", 4 )) mod = "(Mod 2) "; - else return FALSE; + else return false; is_bitlord = !memcmp( id+6, "LORD", 4 ); name = (is_bitlord) ? "BitLord " : "BitComet "; @@ -141,7 +141,7 @@ decodeBitCometClient( char * buf, size_t buflen, const uint8_t * id ) else tr_snprintf( buf, buflen, "%s%s%d.%02d", name, mod, major, minor ); - return TRUE; + return true; } void diff --git a/libtransmission/completion.c b/libtransmission/completion.c index ccfd9e915..f352e310c 100644 --- a/libtransmission/completion.c +++ b/libtransmission/completion.c @@ -28,9 +28,9 @@ tr_cpReset( tr_completion * cp ) tr_free( cp->completeBlocks ); cp->completeBlocks = NULL; cp->sizeNow = 0; - cp->sizeWhenDoneIsDirty = TRUE; - cp->blocksWantedIsDirty = TRUE; - cp->haveValidIsDirty = TRUE; + cp->sizeWhenDoneIsDirty = true; + cp->blocksWantedIsDirty = true; + cp->haveValidIsDirty = true; } tr_completion * @@ -55,7 +55,7 @@ tr_cpDestruct( tr_completion * cp ) **** ***/ -static inline tr_bool +static inline bool isSeed( const tr_completion * cp ) { return cp->blockBitset.haveAll; @@ -93,8 +93,8 @@ getCompleteBlocks( const tr_completion * ccp ) void tr_cpInvalidateDND( tr_completion * cp ) { - cp->sizeWhenDoneIsDirty = TRUE; - cp->blocksWantedIsDirty = TRUE; + cp->sizeWhenDoneIsDirty = true; + cp->blocksWantedIsDirty = true; } tr_block_index_t @@ -124,7 +124,7 @@ tr_cpBlocksMissing( const tr_completion * ccp ) cp->blocksWantedLazy = wanted; cp->blocksWantedCompleteLazy = complete; - cp->blocksWantedIsDirty = FALSE; + cp->blocksWantedIsDirty = false; } return ccp->blocksWantedLazy - ccp->blocksWantedCompleteLazy; @@ -147,8 +147,8 @@ tr_cpPieceRem( tr_completion * cp, tr_piece_index_t piece ) if( !tor->info.pieces[piece].dnd ) cp->blocksWantedCompleteLazy -= complete_blocks[piece]; - cp->sizeWhenDoneIsDirty = TRUE; - cp->haveValidIsDirty = TRUE; + cp->sizeWhenDoneIsDirty = true; + cp->haveValidIsDirty = true; complete_blocks[piece] = 0; tr_bitsetRemRange( &cp->blockBitset, first, last+1 ); } @@ -183,16 +183,16 @@ tr_cpBlockAdd( tr_completion * cp, tr_block_index_t block ) if( !tor->info.pieces[piece].dnd ) cp->blocksWantedCompleteLazy++; - cp->sizeWhenDoneIsDirty = TRUE; - cp->haveValidIsDirty = TRUE; + cp->sizeWhenDoneIsDirty = true; + cp->haveValidIsDirty = true; } } -tr_bool +bool tr_cpBlockBitsetInit( tr_completion * cp, const tr_bitset * blocks ) { - tr_bool success = FALSE; + bool success = false; tr_torrent * tor = cp->tor; /* start cp with a state where it thinks we have nothing */ @@ -203,12 +203,12 @@ tr_cpBlockBitsetInit( tr_completion * cp, const tr_bitset * blocks ) tr_bitsetSetHaveAll( &cp->blockBitset ); cp->sizeNow = tor->info.totalSize; - success = TRUE; + success = true; } else if( blocks->haveNone ) { /* already reset... */ - success = TRUE; + success = true; } else { @@ -236,7 +236,7 @@ tr_cpBlockBitsetInit( tr_completion * cp, const tr_bitset * blocks ) tr_bitsetSetHaveNone( &cp->blockBitset ); cp->sizeNow = 0; } else { - cp->blockBitset.haveAll = cp->blockBitset.haveNone = FALSE; + cp->blockBitset.haveAll = cp->blockBitset.haveNone = false; cp->sizeNow = tr_bitfieldCountRange( tgt, 0, tor->blockCount-1 ); cp->sizeNow *= tor->blockSize; if( tr_bitfieldHas( tgt, tor->blockCount-1 ) ) @@ -274,7 +274,7 @@ tr_cpHaveValid( const tr_completion * ccp ) if( tr_cpPieceIsComplete( ccp, i ) ) size += tr_torPieceCountBytes( tor, i ); - cp->haveValidIsDirty = FALSE; + cp->haveValidIsDirty = false; cp->haveValidLazy = size; } @@ -296,7 +296,7 @@ tr_cpSizeWhenDone( const tr_completion * ccp ) if( !info->pieces[i].dnd || tr_cpPieceIsComplete( cp, i ) ) size += tr_torPieceCountBytes( tor, i ); - cp->sizeWhenDoneIsDirty = FALSE; + cp->sizeWhenDoneIsDirty = false; cp->sizeWhenDoneLazy = size; } @@ -308,7 +308,7 @@ tr_cpGetAmountDone( const tr_completion * cp, float * tab, int tabCount ) { int i; const float interval = cp->tor->info.pieceCount / (float)tabCount; - const tr_bool seed = isSeed( cp ); + const bool seed = isSeed( cp ); for( i=0; i<tabCount; ++i ) { if( seed ) @@ -329,13 +329,13 @@ tr_cpMissingBlocksInPiece( const tr_completion * cp, tr_piece_index_t i ) return countBlocksInPiece( cp->tor, i ) - getCompleteBlocks(cp)[i]; } -tr_bool +bool tr_cpFileIsComplete( const tr_completion * cp, tr_file_index_t i ) { tr_block_index_t f, l; if( cp->tor->info.files[i].length == 0 ) - return TRUE; + return true; tr_torGetFileBlockRange( cp->tor, i, &f, &l ); return tr_bitsetCountRange( &cp->blockBitset, f, l+1 ) == (l+1-f); diff --git a/libtransmission/completion.h b/libtransmission/completion.h index e2cf2a49f..406cac0d5 100644 --- a/libtransmission/completion.h +++ b/libtransmission/completion.h @@ -25,9 +25,9 @@ typedef struct tr_completion { - tr_bool sizeWhenDoneIsDirty; - tr_bool blocksWantedIsDirty; - tr_bool haveValidIsDirty; + bool sizeWhenDoneIsDirty; + bool blocksWantedIsDirty; + bool haveValidIsDirty; tr_torrent * tor; @@ -127,23 +127,23 @@ static inline double tr_cpPercentDone( const tr_completion * cp ) int tr_cpMissingBlocksInPiece( const tr_completion * cp, tr_piece_index_t i ); -static inline tr_bool +static inline bool tr_cpPieceIsComplete( const tr_completion * cp, tr_piece_index_t i ) { return tr_cpMissingBlocksInPiece( cp, i ) == 0; } -void tr_cpPieceAdd( tr_completion * cp, tr_piece_index_t i ); +void tr_cpPieceAdd( tr_completion * cp, tr_piece_index_t i ); -void tr_cpPieceRem( tr_completion * cp, tr_piece_index_t i ); +void tr_cpPieceRem( tr_completion * cp, tr_piece_index_t i ); -tr_bool tr_cpFileIsComplete( const tr_completion * cp, tr_file_index_t ); +bool tr_cpFileIsComplete( const tr_completion * cp, tr_file_index_t ); /** *** Blocks **/ -static inline tr_bool +static inline bool tr_cpBlockIsComplete( const tr_completion * cp, tr_block_index_t i ) { return tr_bitsetHas( &cp->blockBitset, i ); @@ -151,7 +151,7 @@ tr_cpBlockIsComplete( const tr_completion * cp, tr_block_index_t i ) void tr_cpBlockAdd( tr_completion * cp, tr_block_index_t i ); -tr_bool tr_cpBlockBitsetInit( tr_completion * cp, const tr_bitset * blocks ); +bool tr_cpBlockBitsetInit( tr_completion * cp, const tr_bitset * blocks ); /*** **** diff --git a/libtransmission/crypto.c b/libtransmission/crypto.c index aed070db0..d40d49305 100644 --- a/libtransmission/crypto.c +++ b/libtransmission/crypto.c @@ -83,9 +83,9 @@ struct tr_crypto RC4_KEY dec_key; RC4_KEY enc_key; uint8_t torrentHash[SHA_DIGEST_LENGTH]; - tr_bool isIncoming; - tr_bool torrentHashIsSet; - tr_bool mySecretIsSet; + bool isIncoming; + bool torrentHashIsSet; + bool mySecretIsSet; uint8_t myPublicKey[KEY_LEN]; uint8_t mySecret[KEY_LEN]; DH * dh; @@ -335,14 +335,14 @@ tr_cryptoRandInt( int upperBound ) int tr_cryptoWeakRandInt( int upperBound ) { - static tr_bool init = FALSE; + static bool init = false; assert( upperBound > 0 ); if( !init ) { srand( tr_time_msec( ) ); - init = TRUE; + init = true; } return rand( ) % upperBound; @@ -388,14 +388,14 @@ tr_ssha1( const void * plaintext ) return tr_strdup( &buf ); } -tr_bool +bool tr_ssha1_matches( const char * source, const char * pass ) { char * salt; size_t saltlen; char * hashed; uint8_t buf[SHA_DIGEST_LENGTH]; - tr_bool result; + bool result; /* extract the salt */ saltlen = strlen( source ) - 2*SHA_DIGEST_LENGTH-1; @@ -410,7 +410,7 @@ tr_ssha1_matches( const char * source, const char * pass ) hashed[1+2*SHA_DIGEST_LENGTH + saltlen] = '\0'; hashed[0] = '{'; - result = strcmp( source, hashed ) == 0 ? TRUE : FALSE; + result = strcmp( source, hashed ) == 0 ? true : false; tr_free( hashed ); tr_free( salt ); diff --git a/libtransmission/crypto.h b/libtransmission/crypto.h index afdfe9ee7..fb5281c76 100644 --- a/libtransmission/crypto.h +++ b/libtransmission/crypto.h @@ -101,7 +101,7 @@ void tr_cryptoRandBuf( void * buf, size_t len ); char* tr_ssha1( const void * plaintext ); /** @brief Validate a test password against the a ssha1 password */ -tr_bool tr_ssha1_matches( const char * ssha1, const char * pass ); +bool tr_ssha1_matches( const char * ssha1, const char * pass ); /* @} */ diff --git a/libtransmission/fdlimit.c b/libtransmission/fdlimit.c index 4aaee1499..856c1d8d8 100644 --- a/libtransmission/fdlimit.c +++ b/libtransmission/fdlimit.c @@ -80,14 +80,14 @@ #endif -static tr_bool +static bool preallocate_file_sparse( int fd, uint64_t length ) { const char zero = '\0'; - tr_bool success = 0; + bool success = 0; if( !length ) - success = TRUE; + success = true; #ifdef HAVE_FALLOCATE64 if( !success ) /* fallocate64 is always preferred, so try it first */ @@ -102,10 +102,10 @@ preallocate_file_sparse( int fd, uint64_t length ) return success; } -static tr_bool +static bool preallocate_file_full( const char * filename, uint64_t length ) { - tr_bool success = 0; + bool success = 0; #ifdef WIN32 @@ -163,7 +163,7 @@ preallocate_file_full( const char * filename, uint64_t length ) { uint8_t buf[ 4096 ]; memset( buf, 0, sizeof( buf ) ); - success = TRUE; + success = true; while ( success && ( length > 0 ) ) { const int thisPass = MIN( length, sizeof( buf ) ); @@ -319,14 +319,14 @@ tr_close_file( int fd ) struct tr_cached_file { - tr_bool is_writable; + bool is_writable; int fd; int torrent_id; tr_file_index_t file_index; time_t used_at; }; -static inline tr_bool +static inline bool cached_file_is_open( const struct tr_cached_file * o ) { assert( o != NULL ); @@ -352,13 +352,13 @@ static int cached_file_open( struct tr_cached_file * o, const char * existing_dir, const char * filename, - tr_bool writable, + bool writable, tr_preallocation_mode allocation, uint64_t file_size ) { int flags; struct stat sb; - tr_bool alreadyExisted; + bool alreadyExisted; /* confirm that existing_dir, if specified, exists on the disk */ if( existing_dir && *existing_dir && stat( existing_dir, &sb ) ) @@ -552,7 +552,7 @@ tr_fdFileClose( tr_session * s, const tr_torrent * tor, tr_file_index_t i ) } int -tr_fdFileGetCached( tr_session * s, int torrent_id, tr_file_index_t i, tr_bool writable ) +tr_fdFileGetCached( tr_session * s, int torrent_id, tr_file_index_t i, bool writable ) { struct tr_cached_file * o = fileset_lookup( get_fileset( s ), torrent_id, i ); @@ -576,7 +576,7 @@ tr_fdFileCheckout( tr_session * session, tr_file_index_t i, const char * existing_dir, const char * filename, - tr_bool writable, + bool writable, tr_preallocation_mode allocation, uint64_t file_size ) { @@ -636,12 +636,12 @@ tr_fdSocketCreate( tr_session * session, int domain, int type ) if( s >= 0 ) { - static tr_bool buf_logged = FALSE; + static bool buf_logged = false; if( !buf_logged ) { int i; socklen_t size = sizeof( int ); - buf_logged = TRUE; + buf_logged = true; getsockopt( s, SOL_SOCKET, SO_SNDBUF, &i, &size ); tr_dbg( "SO_SNDBUF size is %d", i ); getsockopt( s, SOL_SOCKET, SO_RCVBUF, &i, &size ); diff --git a/libtransmission/fdlimit.h b/libtransmission/fdlimit.h index 78e564bb1..1cc3b2481 100644 --- a/libtransmission/fdlimit.h +++ b/libtransmission/fdlimit.h @@ -72,14 +72,14 @@ int tr_fdFileCheckout( tr_session * session, tr_file_index_t file_num, const char * existing_dir, const char * filename, - tr_bool do_write, + bool do_write, tr_preallocation_mode preallocation_mode, uint64_t preallocation_file_size ); int tr_fdFileGetCached( tr_session * session, int torrent_id, tr_file_index_t file_num, - tr_bool doWrite ); + bool doWrite ); /** * Closes a file that's being held by our file repository. diff --git a/libtransmission/handshake.c b/libtransmission/handshake.c index 6cb10d353..ecb0e460e 100644 --- a/libtransmission/handshake.c +++ b/libtransmission/handshake.c @@ -102,9 +102,9 @@ typedef uint8_t handshake_state_t; struct tr_handshake { - tr_bool haveReadAnythingFromPeer; - tr_bool havePeerID; - tr_bool haveSentBitTorrentHandshake; + bool haveReadAnythingFromPeer; + bool havePeerID; + bool haveSentBitTorrentHandshake; tr_peerIo * io; tr_crypto * crypto; tr_session * session; @@ -242,7 +242,7 @@ buildHandshakeMessage( tr_handshake * handshake, uint8_t * buf ) } static int tr_handshakeDone( tr_handshake * handshake, - tr_bool isConnected ); + bool isConnected ); enum { @@ -293,7 +293,7 @@ parseHandshake( tr_handshake * handshake, tr_peerIoSetPeersId( handshake->io, peer_id ); /* peer id */ - handshake->havePeerID = TRUE; + handshake->havePeerID = true; dbgmsg( handshake, "peer-id is [%*.*s]", PEER_ID_LEN, PEER_ID_LEN, peer_id ); tor = tr_torrentFindFromHash( handshake->session, hash ); @@ -345,7 +345,7 @@ sendYa( tr_handshake * handshake ) /* send it */ setReadState( handshake, AWAITING_YB ); - tr_peerIoWriteBytes( handshake->io, outbuf, walk - outbuf, FALSE ); + tr_peerIoWriteBytes( handshake->io, outbuf, walk - outbuf, false ); } static uint32_t @@ -430,7 +430,7 @@ readYb( tr_handshake * handshake, struct evbuffer * inbuf ) return READ_NOW; } - handshake->haveReadAnythingFromPeer = TRUE; + handshake->haveReadAnythingFromPeer = true; /* compute the secret */ evbuffer_remove( inbuf, yb, KEY_LEN ); @@ -469,7 +469,7 @@ readYb( tr_handshake * handshake, struct evbuffer * inbuf ) { uint8_t vc[VC_LENGTH] = { 0, 0, 0, 0, 0, 0, 0, 0 }; - tr_peerIoWriteBuf( handshake->io, outbuf, FALSE ); + tr_peerIoWriteBuf( handshake->io, outbuf, false ); tr_cryptoEncryptInit( handshake->crypto ); tr_peerIoSetEncryption( handshake->io, PEER_ENCRYPTION_RC4 ); @@ -492,7 +492,7 @@ readYb( tr_handshake * handshake, struct evbuffer * inbuf ) /* send it */ tr_cryptoDecryptInit( handshake->crypto ); setReadState( handshake, AWAITING_VC ); - tr_peerIoWriteBuf( handshake->io, outbuf, FALSE ); + tr_peerIoWriteBuf( handshake->io, outbuf, false ); /* cleanup */ evbuffer_free( outbuf ); @@ -551,7 +551,7 @@ readCryptoSelect( tr_handshake * handshake, { dbgmsg( handshake, "peer selected an encryption option we didn't provide" ); - return tr_handshakeDone( handshake, FALSE ); + return tr_handshakeDone( handshake, false ); } tr_peerIoReadUint16( handshake->io, inbuf, &pad_d_len ); @@ -560,7 +560,7 @@ readCryptoSelect( tr_handshake * handshake, if( pad_d_len > 512 ) { dbgmsg( handshake, "encryption handshake: pad_d_len is too long" ); - return tr_handshakeDone( handshake, FALSE ); + return tr_handshakeDone( handshake, false ); } handshake->pad_d_len = pad_d_len; @@ -612,7 +612,7 @@ readHandshake( tr_handshake * handshake, if( evbuffer_get_length( inbuf ) < INCOMING_HANDSHAKE_LEN ) return READ_LATER; - handshake->haveReadAnythingFromPeer = TRUE; + handshake->haveReadAnythingFromPeer = true; pstrlen = evbuffer_pullup( inbuf, 1 )[0]; /* peek, don't read. We may be handing inbuf to AWAITING_YA */ @@ -625,7 +625,7 @@ readHandshake( tr_handshake * handshake, { dbgmsg( handshake, "peer is unencrypted, and we're disallowing that" ); - return tr_handshakeDone( handshake, FALSE ); + return tr_handshakeDone( handshake, false ); } } else /* encrypted or corrupt */ @@ -645,7 +645,7 @@ readHandshake( tr_handshake * handshake, { dbgmsg( handshake, "I think peer has sent us a corrupt handshake..." ); - return tr_handshakeDone( handshake, FALSE ); + return tr_handshakeDone( handshake, false ); } } @@ -658,7 +658,7 @@ readHandshake( tr_handshake * handshake, if( strcmp( (char*)pstr, "BitTorrent protocol" ) ) { tr_free( pstr ); - return tr_handshakeDone( handshake, FALSE ); + return tr_handshakeDone( handshake, false ); } tr_free( pstr ); @@ -682,7 +682,7 @@ readHandshake( tr_handshake * handshake, if( !tr_torrentExists( handshake->session, hash ) ) { dbgmsg( handshake, "peer is trying to connect to us for a torrent we don't have." ); - return tr_handshakeDone( handshake, FALSE ); + return tr_handshakeDone( handshake, false ); } else { @@ -697,7 +697,7 @@ readHandshake( tr_handshake * handshake, SHA_DIGEST_LENGTH ) ) { dbgmsg( handshake, "peer returned the wrong hash. wtf?" ); - return tr_handshakeDone( handshake, FALSE ); + return tr_handshakeDone( handshake, false ); } } @@ -709,7 +709,7 @@ readHandshake( tr_handshake * handshake, { uint8_t msg[HANDSHAKE_SIZE]; buildHandshakeMessage( handshake, msg ); - tr_peerIoWriteBytes( handshake->io, msg, sizeof( msg ), FALSE ); + tr_peerIoWriteBytes( handshake->io, msg, sizeof( msg ), false ); handshake->haveSentBitTorrentHandshake = 1; } @@ -721,7 +721,7 @@ static int readPeerId( tr_handshake * handshake, struct evbuffer * inbuf ) { - tr_bool peerIsGood; + bool peerIsGood; char client[128]; tr_torrent * tor; const uint8_t * tor_peer_id; @@ -733,7 +733,7 @@ readPeerId( tr_handshake * handshake, /* peer id */ tr_peerIoReadBytes( handshake->io, inbuf, peer_id, PEER_ID_LEN ); tr_peerIoSetPeersId( handshake->io, peer_id ); - handshake->havePeerID = TRUE; + handshake->havePeerID = true; tr_clientForId( client, sizeof( client ), peer_id ); dbgmsg( handshake, "peer-id is [%s] ... isIncoming is %d", client, tr_peerIoIsIncoming( handshake->io ) ); @@ -777,7 +777,7 @@ readYa( tr_handshake * handshake, walk += len; setReadState( handshake, AWAITING_PAD_A ); - tr_peerIoWriteBytes( handshake->io, outbuf, walk - outbuf, FALSE ); + tr_peerIoWriteBytes( handshake->io, outbuf, walk - outbuf, false ); return READ_NOW; } @@ -841,8 +841,8 @@ readCryptoProvide( tr_handshake * handshake, obfuscatedTorrentHash[i] = req2[i] ^ req3[i]; if(( tor = tr_torrentFindFromObfuscatedHash( handshake->session, obfuscatedTorrentHash ))) { - const tr_bool clientIsSeed = tr_torrentIsSeed( tor ); - const tr_bool peerIsSeed = tr_peerMgrPeerIsSeed( tor, tr_peerIoGetAddress( handshake->io, NULL ) ); + const bool clientIsSeed = tr_torrentIsSeed( tor ); + const bool peerIsSeed = tr_peerMgrPeerIsSeed( tor, tr_peerIoGetAddress( handshake->io, NULL ) ); dbgmsg( handshake, "got INCOMING connection's encrypted handshake for torrent [%s]", tr_torrentName( tor ) ); tr_peerIoSetTorrentHash( handshake->io, tor->info.hash ); @@ -850,13 +850,13 @@ readCryptoProvide( tr_handshake * handshake, if( clientIsSeed && peerIsSeed ) { dbgmsg( handshake, "another seed tried to reconnect to us!" ); - return tr_handshakeDone( handshake, FALSE ); + return tr_handshakeDone( handshake, false ); } } else { dbgmsg( handshake, "can't find that torrent..." ); - return tr_handshakeDone( handshake, FALSE ); + return tr_handshakeDone( handshake, false ); } /* next part: ENCRYPT(VC, crypto_provide, len(PadC), */ @@ -934,7 +934,7 @@ readIA( tr_handshake * handshake, { dbgmsg( handshake, "peer didn't offer an encryption mode we like." ); evbuffer_free( outbuf ); - return tr_handshakeDone( handshake, FALSE ); + return tr_handshakeDone( handshake, false ); } dbgmsg( handshake, "sending pad d" ); @@ -949,7 +949,7 @@ readIA( tr_handshake * handshake, /* maybe de-encrypt our connection */ if( crypto_select == CRYPTO_PROVIDE_PLAINTEXT ) { - tr_peerIoWriteBuf( handshake->io, outbuf, FALSE ); + tr_peerIoWriteBuf( handshake->io, outbuf, false ); tr_peerIoSetEncryption( handshake->io, PEER_ENCRYPTION_NONE ); } @@ -964,7 +964,7 @@ readIA( tr_handshake * handshake, } /* send it out */ - tr_peerIoWriteBuf( handshake->io, outbuf, FALSE ); + tr_peerIoWriteBuf( handshake->io, outbuf, false ); evbuffer_free( outbuf ); /* now await the handshake */ @@ -988,10 +988,10 @@ readPayloadStream( tr_handshake * handshake, i = parseHandshake( handshake, inbuf ); dbgmsg( handshake, "parseHandshake returned %d", i ); if( i != HANDSHAKE_OK ) - return tr_handshakeDone( handshake, FALSE ); + return tr_handshakeDone( handshake, false ); /* we've completed the BT handshake... pass the work on to peer-msgs */ - return tr_handshakeDone( handshake, TRUE ); + return tr_handshakeDone( handshake, true ); } /*** @@ -1006,7 +1006,7 @@ canRead( struct tr_peerIo * io, void * arg, size_t * piece ) tr_handshake * handshake = arg; struct evbuffer * inbuf = tr_peerIoGetReadBuffer( io ); ReadState ret; - tr_bool readyForMore = TRUE; + bool readyForMore = true; assert( tr_isPeerIo( io ) ); @@ -1061,7 +1061,7 @@ canRead( struct tr_peerIo * io, void * arg, size_t * piece ) } if( ret != READ_NOW ) - readyForMore = FALSE; + readyForMore = false; else if( handshake->state == AWAITING_PAD_C ) readyForMore = evbuffer_get_length( inbuf ) >= handshake->pad_c_len; else if( handshake->state == AWAITING_PAD_D ) @@ -1073,18 +1073,18 @@ canRead( struct tr_peerIo * io, void * arg, size_t * piece ) return ret; } -static tr_bool -fireDoneFunc( tr_handshake * handshake, tr_bool isConnected ) +static bool +fireDoneFunc( tr_handshake * handshake, bool isConnected ) { const uint8_t * peer_id = isConnected && handshake->havePeerID ? tr_peerIoGetPeersId( handshake->io ) : NULL; - const tr_bool success = ( *handshake->doneCB )( handshake, - handshake->io, - handshake->haveReadAnythingFromPeer, - isConnected, - peer_id, - handshake->doneUserData ); + const bool success = ( *handshake->doneCB )( handshake, + handshake->io, + handshake->haveReadAnythingFromPeer, + isConnected, + peer_id, + handshake->doneUserData ); return success; } @@ -1100,10 +1100,9 @@ tr_handshakeFree( tr_handshake * handshake ) } static int -tr_handshakeDone( tr_handshake * handshake, - tr_bool isOK ) +tr_handshakeDone( tr_handshake * handshake, bool isOK ) { - tr_bool success; + bool success; dbgmsg( handshake, "handshakeDone: %s", isOK ? "connected" : "aborting" ); tr_peerIoSetIOFuncs( handshake->io, NULL, NULL, NULL, NULL ); @@ -1119,7 +1118,7 @@ void tr_handshakeAbort( tr_handshake * handshake ) { if( handshake != NULL ) - tr_handshakeDone( handshake, FALSE ); + tr_handshakeDone( handshake, false ); } static void @@ -1142,7 +1141,7 @@ gotError( tr_peerIo * io, tr_torrentLock( tor ); tr_peerMgrSetUtpFailed( tor, tr_peerIoGetAddress( io, NULL ), - TRUE ); + true ); tr_torrentUnlock( tor ); } @@ -1151,7 +1150,7 @@ gotError( tr_peerIo * io, buildHandshakeMessage( handshake, msg ); handshake->haveSentBitTorrentHandshake = 1; setReadState( handshake, AWAITING_HANDSHAKE ); - tr_peerIoWriteBytes( handshake->io, msg, sizeof( msg ), FALSE ); + tr_peerIoWriteBytes( handshake->io, msg, sizeof( msg ), false ); } } @@ -1169,13 +1168,13 @@ gotError( tr_peerIo * io, buildHandshakeMessage( handshake, msg ); handshake->haveSentBitTorrentHandshake = 1; setReadState( handshake, AWAITING_HANDSHAKE ); - tr_peerIoWriteBytes( handshake->io, msg, sizeof( msg ), FALSE ); + tr_peerIoWriteBytes( handshake->io, msg, sizeof( msg ), false ); } else { dbgmsg( handshake, "libevent got an error what==%d, errno=%d (%s)", (int)what, errno, tr_strerror( errno ) ); - tr_handshakeDone( handshake, FALSE ); + tr_handshakeDone( handshake, false ); } } @@ -1223,7 +1222,7 @@ tr_handshakeNew( tr_peerIo * io, handshake->haveSentBitTorrentHandshake = 1; setReadState( handshake, AWAITING_HANDSHAKE ); - tr_peerIoWriteBytes( handshake->io, msg, sizeof( msg ), FALSE ); + tr_peerIoWriteBytes( handshake->io, msg, sizeof( msg ), false ); } return handshake; diff --git a/libtransmission/handshake.h b/libtransmission/handshake.h index a3cf54d18..0ca013472 100644 --- a/libtransmission/handshake.h +++ b/libtransmission/handshake.h @@ -30,12 +30,12 @@ struct tr_peerIo; typedef struct tr_handshake tr_handshake; /* returns true on success, false on error */ -typedef tr_bool ( *handshakeDoneCB )( struct tr_handshake * handshake, - struct tr_peerIo * io, - tr_bool readAnythingFromPeer, - tr_bool isConnected, - const uint8_t * peerId, - void * userData ); +typedef bool ( *handshakeDoneCB )( struct tr_handshake * handshake, + struct tr_peerIo * io, + bool readAnythingFromPeer, + bool isConnected, + const uint8_t * peerId, + void * userData ); /** @brief instantiate a new handshake */ tr_handshake * tr_handshakeNew( struct tr_peerIo * io, diff --git a/libtransmission/inout.c b/libtransmission/inout.c index addc99007..bd4213da6 100644 --- a/libtransmission/inout.c +++ b/libtransmission/inout.c @@ -48,7 +48,7 @@ readOrWriteBytes( tr_session * session, { int fd; int err = 0; - const tr_bool doWrite = ioMode >= TR_IO_WRITE; + const bool doWrite = ioMode >= TR_IO_WRITE; const tr_info * const info = &tor->info; const tr_file * const file = &info->files[fileIndex]; @@ -263,14 +263,12 @@ tr_ioWrite( tr_torrent * tor, ***** ****/ -static tr_bool -recalculateHash( tr_torrent * tor, - tr_piece_index_t pieceIndex, - uint8_t * setme ) +static bool +recalculateHash( tr_torrent * tor, tr_piece_index_t pieceIndex, uint8_t * setme ) { size_t bytesLeft; uint32_t offset = 0; - tr_bool success = TRUE; + bool success = true; const size_t buflen = tor->blockSize; void * buffer = tr_valloc( buflen ); SHA_CTX sha; @@ -304,7 +302,7 @@ recalculateHash( tr_torrent * tor, return success; } -tr_bool +bool tr_ioTestPiece( tr_torrent * tor, tr_piece_index_t piece ) { uint8_t hash[SHA_DIGEST_LENGTH]; diff --git a/libtransmission/inout.h b/libtransmission/inout.h index 967def41b..23a1918c5 100644 --- a/libtransmission/inout.h +++ b/libtransmission/inout.h @@ -53,8 +53,8 @@ int tr_ioWrite( struct tr_torrent * tor, /** * @brief Test to see if the piece matches its metainfo's SHA1 checksum. */ -tr_bool tr_ioTestPiece( tr_torrent * tor, - tr_piece_index_t piece ); +bool tr_ioTestPiece( tr_torrent * tor, + tr_piece_index_t piece ); /** diff --git a/libtransmission/json.c b/libtransmission/json.c index 1e4b5e944..6a09ebd43 100644 --- a/libtransmission/json.c +++ b/libtransmission/json.c @@ -26,7 +26,7 @@ struct json_benc_data { - tr_bool hasContent; + bool hasContent; tr_benc * top; tr_ptrArray stack; char * key; @@ -68,7 +68,7 @@ callback( void * vdata, switch( type ) { case JSON_T_ARRAY_BEGIN: - data->hasContent = TRUE; + data->hasContent = true; node = getNode( data ); tr_bencInitList( node, 0 ); tr_ptrArrayAppend( &data->stack, node ); @@ -79,7 +79,7 @@ callback( void * vdata, break; case JSON_T_OBJECT_BEGIN: - data->hasContent = TRUE; + data->hasContent = true; node = getNode( data ); tr_bencInitDict( node, 0 ); tr_ptrArrayAppend( &data->stack, node ); @@ -90,39 +90,39 @@ callback( void * vdata, break; case JSON_T_FLOAT: - data->hasContent = TRUE; + data->hasContent = true; tr_bencInitReal( getNode( data ), value->vu.float_value ); break; case JSON_T_NULL: - data->hasContent = TRUE; + data->hasContent = true; tr_bencInitStr( getNode( data ), "", 0 ); break; case JSON_T_INTEGER: - data->hasContent = TRUE; + data->hasContent = true; tr_bencInitInt( getNode( data ), value->vu.integer_value ); break; case JSON_T_TRUE: - data->hasContent = TRUE; + data->hasContent = true; tr_bencInitBool( getNode( data ), 1 ); break; case JSON_T_FALSE: - data->hasContent = TRUE; + data->hasContent = true; tr_bencInitBool( getNode( data ), 0 ); break; case JSON_T_STRING: - data->hasContent = TRUE; + data->hasContent = true; tr_bencInitStr( getNode( data ), value->vu.str.value, value->vu.str.length ); break; case JSON_T_KEY: - data->hasContent = TRUE; + data->hasContent = true; assert( !data->key ); data->key = tr_strdup( value->vu.str.value ); break; @@ -152,7 +152,7 @@ tr_jsonParse( const char * source, config.callback_ctx = &data; config.depth = -1; - data.hasContent = FALSE; + data.hasContent = false; data.key = NULL; data.top = setme_benc; data.stack = TR_PTR_ARRAY_INIT; diff --git a/libtransmission/magnet.c b/libtransmission/magnet.c index 991ba41a0..5bab49b60 100644 --- a/libtransmission/magnet.c +++ b/libtransmission/magnet.c @@ -99,7 +99,7 @@ base32_to_sha1( uint8_t * out, const char * in, const int inlen ) tr_magnet_info * tr_magnetParse( const char * uri ) { - tr_bool got_checksum = FALSE; + bool got_checksum = false; int trCount = 0; int wsCount = 0; char * tr[MAX_TRACKERS]; @@ -141,11 +141,11 @@ tr_magnetParse( const char * uri ) if( hashlen == 40 ) { tr_hex_to_sha1( sha1, hash ); - got_checksum = TRUE; + got_checksum = true; } else if( hashlen == 32 ) { base32_to_sha1( sha1, hash, hashlen ); - got_checksum = TRUE; + got_checksum = true; } } diff --git a/libtransmission/makemeta.c b/libtransmission/makemeta.c index e28e96a5b..a3370d959 100644 --- a/libtransmission/makemeta.c +++ b/libtransmission/makemeta.c @@ -381,7 +381,7 @@ tr_realMakeMetaInfo( tr_metainfo_builder * builder ) builder->errfile[0] = '\0'; builder->my_errno = ENOENT; builder->result = TR_MAKEMETA_IO_READ; - builder->isDone = TRUE; + builder->isDone = true; } if( !builder->result && builder->trackerCount ) diff --git a/libtransmission/metainfo.c b/libtransmission/metainfo.c index 377ee4814..ef92994b9 100644 --- a/libtransmission/metainfo.c +++ b/libtransmission/metainfo.c @@ -139,17 +139,17 @@ tr_metainfoMigrate( tr_session * session, **** ***/ -static tr_bool +static bool path_is_suspicious( const char * path ) { return ( path == NULL ) || ( strstr( path, "../" ) != NULL ); } -static tr_bool +static bool getfile( char ** setme, const char * root, tr_benc * path ) { - tr_bool success = FALSE; + bool success = false; if( tr_bencIsList( path ) ) { @@ -173,14 +173,14 @@ getfile( char ** setme, const char * root, tr_benc * path ) *setme = tr_utf8clean( tmp, -1 ); tr_free( tmp ); /* fprintf( stderr, "[%s]\n", *setme ); */ - success = TRUE; + success = true; } if( ( *setme != NULL ) && path_is_suspicious( *setme ) ) { tr_free( *setme ); *setme = NULL; - success = FALSE; + success = false; } return success; @@ -299,7 +299,7 @@ getannounce( tr_info * inf, tr_benc * meta ) { tr_benc * tier = tr_bencListChild( tiers, i ); const int tierSize = tr_bencListSize( tier ); - tr_bool anyAdded = FALSE; + bool anyAdded = false; for( j = 0; j < tierSize; ++j ) { if( tr_bencGetStr( tr_bencListChild( tier, j ), &str ) ) @@ -313,7 +313,7 @@ getannounce( tr_info * inf, tr_benc * meta ) t->scrape = tr_convertAnnounceToScrape( url ); t->id = trackerCount; - anyAdded = TRUE; + anyAdded = true; ++trackerCount; } tr_free( url ); @@ -386,7 +386,7 @@ geturllist( tr_info * inf, static const char* tr_metainfoParseImpl( const tr_session * session, tr_info * inf, - tr_bool * hasInfoDict, + bool * hasInfoDict, int * infoDictLength, const tr_benc * meta_in ) { @@ -397,8 +397,8 @@ tr_metainfoParseImpl( const tr_session * session, tr_benc * d; tr_benc * infoDict = NULL; tr_benc * meta = (tr_benc *) meta_in; - tr_bool b; - tr_bool isMagnet = FALSE; + bool b; + bool isMagnet = false; /* info_hash: urlencoded 20-byte SHA1 hash of the value of the info key * from the Metainfo file. Note that the value will be a bencoded @@ -411,7 +411,7 @@ tr_metainfoParseImpl( const tr_session * session, /* no info dictionary... is this a magnet link? */ if( tr_bencDictFindDict( meta, "magnet-info", &d ) ) { - isMagnet = TRUE; + isMagnet = true; /* get the info-hash */ if( !tr_bencDictFindRaw( d, "info_hash", &raw, &raw_len ) ) @@ -530,11 +530,11 @@ tr_metainfoParseImpl( const tr_session * session, return NULL; } -tr_bool +bool tr_metainfoParse( const tr_session * session, const tr_benc * meta_in, tr_info * inf, - tr_bool * hasInfoDict, + bool * hasInfoDict, int * infoDictLength ) { const char * badTag = tr_metainfoParseImpl( session, @@ -542,7 +542,7 @@ tr_metainfoParse( const tr_session * session, hasInfoDict, infoDictLength, meta_in ); - const tr_bool success = badTag == NULL; + const bool success = badTag == NULL; if( badTag ) { diff --git a/libtransmission/metainfo.h b/libtransmission/metainfo.h index 6fd359d30..b29d843b6 100644 --- a/libtransmission/metainfo.h +++ b/libtransmission/metainfo.h @@ -21,11 +21,11 @@ struct tr_benc; -tr_bool tr_metainfoParse( const tr_session * session, - const struct tr_benc * benc, - tr_info * setmeInfo, - tr_bool * setmeHasInfoDict, - int * setmeInfoDictLength ); +bool tr_metainfoParse( const tr_session * session, + const struct tr_benc * benc, + tr_info * setmeInfo, + bool * setmeHasInfoDict, + int * setmeInfoDictLength ); void tr_metainfoRemoveSaved( const tr_session * session, const tr_info * info ); diff --git a/libtransmission/natpmp.c b/libtransmission/natpmp.c index 93de73e79..b7f5893b8 100644 --- a/libtransmission/natpmp.c +++ b/libtransmission/natpmp.c @@ -44,8 +44,8 @@ tr_natpmp_state; struct tr_natpmp { - tr_bool has_discovered; - tr_bool is_mapped; + bool has_discovered; + bool is_mapped; tr_port public_port; tr_port private_port; @@ -112,7 +112,7 @@ setCommandTime( struct tr_natpmp * nat ) } int -tr_natpmpPulse( struct tr_natpmp * nat, tr_port private_port, tr_bool is_enabled, tr_port * public_port ) +tr_natpmpPulse( struct tr_natpmp * nat, tr_port private_port, bool is_enabled, tr_port * public_port ) { int ret; @@ -123,7 +123,7 @@ tr_natpmpPulse( struct tr_natpmp * nat, tr_port private_port, tr_bool is_enabled val = sendpublicaddressrequest( &nat->natpmp ); logVal( "sendpublicaddressrequest", val ); nat->state = val < 0 ? TR_NATPMP_ERR : TR_NATPMP_RECV_PUB; - nat->has_discovered = TRUE; + nat->has_discovered = true; setCommandTime( nat ); } @@ -177,7 +177,7 @@ tr_natpmpPulse( struct tr_natpmp * nat, tr_port private_port, tr_bool is_enabled nat->private_port = 0; nat->public_port = 0; nat->state = TR_NATPMP_IDLE; - nat->is_mapped = FALSE; + nat->is_mapped = false; } } else if( val != NATPMP_TRYAGAIN ) @@ -211,7 +211,7 @@ tr_natpmpPulse( struct tr_natpmp * nat, tr_port private_port, tr_bool is_enabled if( val >= 0 ) { nat->state = TR_NATPMP_IDLE; - nat->is_mapped = TRUE; + nat->is_mapped = true; nat->renew_time = tr_time( ) + ( resp.pnu.newportmapping.lifetime / 2 ); nat->private_port = resp.pnu.newportmapping.privateport; nat->public_port = resp.pnu.newportmapping.mappedpublicport; diff --git a/libtransmission/natpmp.h b/libtransmission/natpmp.h index e8b13dae2..ce7f87d43 100644 --- a/libtransmission/natpmp.h +++ b/libtransmission/natpmp.h @@ -28,7 +28,7 @@ tr_natpmp * tr_natpmpInit( void ); void tr_natpmpClose( tr_natpmp * ); -int tr_natpmpPulse( tr_natpmp *, tr_port port, tr_bool isEnabled, tr_port * public_port ); +int tr_natpmpPulse( tr_natpmp *, tr_port port, bool isEnabled, tr_port * public_port ); /* @} */ #endif diff --git a/libtransmission/net.c b/libtransmission/net.c index 85ca6a61b..ead66df6a 100644 --- a/libtransmission/net.c +++ b/libtransmission/net.c @@ -67,7 +67,7 @@ const tr_address tr_inaddr_any = { TR_AF_INET, { { { { INADDR_ANY, 0x00, 0x00, 0 void tr_netInit( void ) { - static int initialized = FALSE; + static int initialized = false; if( !initialized ) { @@ -75,7 +75,7 @@ tr_netInit( void ) WSADATA wsaData; WSAStartup( MAKEWORD( 2, 2 ), &wsaData ); #endif - initialized = TRUE; + initialized = true; } } @@ -180,7 +180,7 @@ tr_netSetCongestionControl( int s UNUSED, const char *algorithm UNUSED ) #endif } -tr_bool +bool tr_ssToAddr( tr_address * setme_addr, tr_port * setme_port, const struct sockaddr_storage * from ) @@ -191,7 +191,7 @@ tr_ssToAddr( tr_address * setme_addr, setme_addr->type = TR_AF_INET; setme_addr->addr.addr4.s_addr = sin->sin_addr.s_addr; *setme_port = sin->sin_port; - return TRUE; + return true; } if( from->ss_family == AF_INET6 ) @@ -200,10 +200,10 @@ tr_ssToAddr( tr_address * setme_addr, setme_addr->type = TR_AF_INET6; setme_addr->addr.addr6 = sin6->sin6_addr; *setme_port = sin6->sin6_port; - return TRUE; + return true; } - return FALSE; + return false; } static socklen_t @@ -240,7 +240,7 @@ int tr_netOpenPeerSocket( tr_session * session, const tr_address * addr, tr_port port, - tr_bool clientIsSeed ) + bool clientIsSeed ) { static const int domains[NUM_TR_AF_INET_TYPES] = { AF_INET, AF_INET6 }; int s; @@ -312,7 +312,7 @@ struct UTPSocket * tr_netOpenPeerUTPSocket( tr_session * session, const tr_address * addr, tr_port port, - tr_bool clientIsSeed UNUSED ) + bool clientIsSeed UNUSED ) { struct sockaddr_storage ss; socklen_t sslen; @@ -323,7 +323,7 @@ tr_netOpenPeerUTPSocket( tr_session * session, } static int -tr_netBindTCPImpl( const tr_address * addr, tr_port port, tr_bool suppressMsgs, int * errOut ) +tr_netBindTCPImpl( const tr_address * addr, tr_port port, bool suppressMsgs, int * errOut ) { static const int domains[NUM_TR_AF_INET_TYPES] = { AF_INET, AF_INET6 }; struct sockaddr_storage sock; @@ -396,27 +396,27 @@ tr_netBindTCPImpl( const tr_address * addr, tr_port port, tr_bool suppressMsgs, } int -tr_netBindTCP( const tr_address * addr, tr_port port, tr_bool suppressMsgs ) +tr_netBindTCP( const tr_address * addr, tr_port port, bool suppressMsgs ) { int unused; return tr_netBindTCPImpl( addr, port, suppressMsgs, &unused ); } -tr_bool +bool tr_net_hasIPv6( tr_port port ) { - static tr_bool result = FALSE; - static tr_bool alreadyDone = FALSE; + static bool result = false; + static bool alreadyDone = false; if( !alreadyDone ) { int err; - int fd = tr_netBindTCPImpl( &tr_in6addr_any, port, TRUE, &err ); + int fd = tr_netBindTCPImpl( &tr_in6addr_any, port, true, &err ); if( fd >= 0 || err != EAFNOSUPPORT ) /* we support ipv6 */ - result = TRUE; + result = true; if( fd >= 0 ) tr_netCloseSocket( fd ); - alreadyDone = TRUE; + alreadyDone = true; } return result; @@ -602,13 +602,13 @@ tr_globalIPv6( void ) **** ***/ -static tr_bool +static bool isIPv4MappedAddress( const tr_address * addr ) { return ( addr->type == TR_AF_INET6 ) && IN6_IS_ADDR_V4MAPPED( &addr->addr.addr6 ); } -static tr_bool +static bool isIPv6LinkLocalAddress( const tr_address * addr ) { return ( ( addr->type == TR_AF_INET6 ) @@ -617,7 +617,7 @@ isIPv6LinkLocalAddress( const tr_address * addr ) /* isMartianAddr was written by Juliusz Chroboczek, and is covered under the same license as third-party/dht/dht.c. */ -static tr_bool +static bool isMartianAddr( const struct tr_address * a ) { static const unsigned char zeroes[16] = @@ -650,11 +650,11 @@ isMartianAddr( const struct tr_address * a ) } default: - return TRUE; + return true; } } -tr_bool +bool tr_isValidPeerAddress( const tr_address * addr, tr_port port ) { return ( port != 0 ) diff --git a/libtransmission/net.h b/libtransmission/net.h index c25bb03d4..cbc3ec928 100644 --- a/libtransmission/net.h +++ b/libtransmission/net.h @@ -79,9 +79,9 @@ typedef struct tr_address extern const tr_address tr_inaddr_any; extern const tr_address tr_in6addr_any; -tr_bool tr_ssToAddr( tr_address * setme_addr, - tr_port * setme_port, - const struct sockaddr_storage * from ); +bool tr_ssToAddr( tr_address * setme_addr, + tr_port * setme_port, + const struct sockaddr_storage * from ); const char *tr_ntop( const tr_address * src, char * dst, @@ -92,11 +92,11 @@ tr_address *tr_pton( const char * src, int tr_compareAddresses( const tr_address * a, const tr_address * b); -tr_bool tr_isValidPeerAddress( const tr_address * addr, tr_port port ); +bool tr_isValidPeerAddress( const tr_address * addr, tr_port port ); -static inline tr_bool tr_isAddress( const tr_address * a ) { return ( a != NULL ) && ( a->type==TR_AF_INET || a->type==TR_AF_INET6 ); } +static inline bool tr_isAddress( const tr_address * a ) { return ( a != NULL ) && ( a->type==TR_AF_INET || a->type==TR_AF_INET6 ); } -tr_bool tr_net_hasIPv6( tr_port ); +bool tr_net_hasIPv6( tr_port ); /*********************************************************************** * Sockets @@ -104,17 +104,17 @@ tr_bool tr_net_hasIPv6( tr_port ); int tr_netOpenPeerSocket( tr_session * session, const tr_address * addr, tr_port port, - tr_bool clientIsSeed ); + bool clientIsSeed ); struct UTPSocket * tr_netOpenPeerUTPSocket( tr_session * session, const tr_address * addr, tr_port port, - tr_bool clientIsSeed); + bool clientIsSeed); int tr_netBindTCP( const tr_address * addr, tr_port port, - tr_bool suppressMsgs ); + bool suppressMsgs ); int tr_netAccept( tr_session * session, int bound, diff --git a/libtransmission/peer-common.h b/libtransmission/peer-common.h index d07108071..845e36403 100644 --- a/libtransmission/peer-common.h +++ b/libtransmission/peer-common.h @@ -74,7 +74,7 @@ typedef struct uint32_t offset; /* for GOT_BLOCK */ uint32_t length; /* for GOT_BLOCK + GOT_DATA */ int err; /* errno for GOT_ERROR */ - tr_bool wasPieceData; /* for GOT_DATA */ + bool wasPieceData; /* for GOT_DATA */ tr_port port; /* for GOT_PORT */ } tr_peer_event; diff --git a/libtransmission/peer-io.c b/libtransmission/peer-io.c index b0dc39ece..057e76e47 100644 --- a/libtransmission/peer-io.c +++ b/libtransmission/peer-io.c @@ -86,8 +86,8 @@ guessPacketOverhead( size_t d ) struct tr_datatype { - tr_bool isPieceData; - size_t length; + bool isPieceData; + size_t length; }; @@ -111,7 +111,7 @@ didWriteWrapper( tr_peerIo * io, unsigned int bytes_transferred ) tr_bandwidthUsed( &io->bandwidth, TR_UP, payload, next->isPieceData, now ); if( overhead > 0 ) - tr_bandwidthUsed( &io->bandwidth, TR_UP, overhead, FALSE, now ); + tr_bandwidthUsed( &io->bandwidth, TR_UP, overhead, false, now ); if( io->didWrite ) io->didWrite( io, payload, next->isPieceData, io->userData ); @@ -131,8 +131,8 @@ didWriteWrapper( tr_peerIo * io, unsigned int bytes_transferred ) static void canReadWrapper( tr_peerIo * io ) { - tr_bool err = 0; - tr_bool done = 0; + bool err = 0; + bool done = 0; tr_session * session; dbgmsg( io, "canRead" ); @@ -159,14 +159,14 @@ canReadWrapper( tr_peerIo * io ) if( piece || (piece!=used) ) { if( piece ) - tr_bandwidthUsed( &io->bandwidth, TR_DOWN, piece, TRUE, now ); + tr_bandwidthUsed( &io->bandwidth, TR_DOWN, piece, true, now ); if( used != piece ) - tr_bandwidthUsed( &io->bandwidth, TR_DOWN, used - piece, FALSE, now ); + tr_bandwidthUsed( &io->bandwidth, TR_DOWN, used - piece, false, now ); } if( overhead > 0 ) - tr_bandwidthUsed( &io->bandwidth, TR_UP, overhead, FALSE, now ); + tr_bandwidthUsed( &io->bandwidth, TR_UP, overhead, false, now ); switch( ret ) { @@ -220,7 +220,7 @@ event_read_cb( int fd, short event UNUSED, void * vio ) /* if we don't have any bandwidth left, stop reading */ if( howmuch < 1 ) { - tr_peerIoSetEnabled( io, dir, FALSE ); + tr_peerIoSetEnabled( io, dir, false ); return; } @@ -230,7 +230,7 @@ event_read_cb( int fd, short event UNUSED, void * vio ) if( res > 0 ) { - tr_peerIoSetEnabled( io, dir, TRUE ); + tr_peerIoSetEnabled( io, dir, true ); /* Invoke the user callback - must always be called last */ canReadWrapper( io ); @@ -244,7 +244,7 @@ event_read_cb( int fd, short event UNUSED, void * vio ) what |= BEV_EVENT_EOF; else if( res == -1 ) { if( e == EAGAIN || e == EINTR ) { - tr_peerIoSetEnabled( io, dir, TRUE ); + tr_peerIoSetEnabled( io, dir, true ); return; } what |= BEV_EVENT_ERROR; @@ -296,7 +296,7 @@ event_write_cb( int fd, short event UNUSED, void * vio ) /* if we don't have any bandwidth left, stop writing */ if( howmuch < 1 ) { - tr_peerIoSetEnabled( io, dir, FALSE ); + tr_peerIoSetEnabled( io, dir, false ); return; } @@ -317,14 +317,14 @@ event_write_cb( int fd, short event UNUSED, void * vio ) goto error; if( evbuffer_get_length( io->outbuf ) ) - tr_peerIoSetEnabled( io, dir, TRUE ); + tr_peerIoSetEnabled( io, dir, true ); didWriteWrapper( io, res ); return; reschedule: if( evbuffer_get_length( io->outbuf ) ) - tr_peerIoSetEnabled( io, dir, TRUE ); + tr_peerIoSetEnabled( io, dir, true ); return; error: @@ -370,7 +370,7 @@ utp_on_read(void *closure, const unsigned char *buf, size_t buflen) return; } - tr_peerIoSetEnabled( io, TR_DOWN, TRUE ); + tr_peerIoSetEnabled( io, TR_DOWN, true ); canReadWrapper( io ); } @@ -412,7 +412,7 @@ utp_on_state_change(void *closure, int state) if( state == UTP_STATE_CONNECT ) { dbgmsg( io, "utp_on_state_change -- changed to connected" ); - io->utpSupported = TRUE; + io->utpSupported = true; } else if( state == UTP_STATE_WRITABLE ) { dbgmsg( io, "utp_on_state_change -- changed to writable" ); } else if( state == UTP_STATE_EOF ) { @@ -449,7 +449,7 @@ utp_on_overhead(void *closure, bool send, size_t count, int type UNUSED) dbgmsg( io, "utp_on_overhead -- count is %zu", count ); tr_bandwidthUsed( &io->bandwidth, send ? TR_UP : TR_DOWN, - count, FALSE, tr_time_msec() ); + count, false, tr_time_msec() ); } static struct UTPFunctionTable utp_function_table = { @@ -524,8 +524,8 @@ tr_peerIoNew( tr_session * session, const tr_address * addr, tr_port port, const uint8_t * torrentHash, - tr_bool isIncoming, - tr_bool isSeed, + bool isIncoming, + bool isSeed, int socket, struct UTPSocket * utp_socket) { @@ -599,7 +599,7 @@ tr_peerIoNewIncoming( tr_session * session, assert( session ); assert( tr_isAddress( addr ) ); - return tr_peerIoNew( session, parent, addr, port, NULL, TRUE, FALSE, + return tr_peerIoNew( session, parent, addr, port, NULL, true, false, fd, utp_socket ); } @@ -609,8 +609,8 @@ tr_peerIoNewOutgoing( tr_session * session, const tr_address * addr, tr_port port, const uint8_t * torrentHash, - tr_bool isSeed, - tr_bool utp ) + bool isSeed, + bool utp ) { int fd = -1; struct UTPSocket *utp_socket = NULL; @@ -631,7 +631,7 @@ tr_peerIoNewOutgoing( tr_session * session, return NULL; return tr_peerIoNew( session, parent, addr, port, - torrentHash, FALSE, isSeed, fd, utp_socket ); + torrentHash, false, isSeed, fd, utp_socket ); } /*** @@ -698,7 +698,7 @@ event_disable( struct tr_peerIo * io, short event ) void tr_peerIoSetEnabled( tr_peerIo * io, tr_direction dir, - tr_bool isEnabled ) + bool isEnabled ) { const short event = dir == TR_UP ? EV_WRITE : EV_READ; @@ -841,8 +841,8 @@ void tr_peerIoClear( tr_peerIo * io ) { tr_peerIoSetIOFuncs( io, NULL, NULL, NULL, NULL ); - tr_peerIoSetEnabled( io, TR_UP, FALSE ); - tr_peerIoSetEnabled( io, TR_DOWN, FALSE ); + tr_peerIoSetEnabled( io, TR_UP, false ); + tr_peerIoSetEnabled( io, TR_DOWN, false ); } int @@ -973,7 +973,7 @@ tr_peerIoSetEncryption( tr_peerIo * io, uint32_t encryptionMode ) **/ static void -addDatatype( tr_peerIo * io, size_t byteCount, tr_bool isPieceData ) +addDatatype( tr_peerIo * io, size_t byteCount, bool isPieceData ) { struct tr_datatype * d; @@ -1011,7 +1011,7 @@ maybeEncryptBuffer( tr_peerIo * io, struct evbuffer * buf ) } void -tr_peerIoWriteBuf( tr_peerIo * io, struct evbuffer * buf, tr_bool isPieceData ) +tr_peerIoWriteBuf( tr_peerIo * io, struct evbuffer * buf, bool isPieceData ) { const size_t byteCount = evbuffer_get_length( buf ); maybeEncryptBuffer( io, buf ); @@ -1020,7 +1020,7 @@ tr_peerIoWriteBuf( tr_peerIo * io, struct evbuffer * buf, tr_bool isPieceData ) } void -tr_peerIoWriteBytes( tr_peerIo * io, const void * bytes, size_t byteCount, tr_bool isPieceData ) +tr_peerIoWriteBytes( tr_peerIo * io, const void * bytes, size_t byteCount, bool isPieceData ) { struct evbuffer * buf = evbuffer_new( ); evbuffer_add( buf, bytes, byteCount ); diff --git a/libtransmission/peer-io.h b/libtransmission/peer-io.h index df50c425d..2f4dd4ed7 100644 --- a/libtransmission/peer-io.h +++ b/libtransmission/peer-io.h @@ -65,13 +65,13 @@ typedef void ( *tr_net_error_cb )( struct tr_peerIo * io, typedef struct tr_peerIo { - tr_bool isEncrypted; - tr_bool isIncoming; - tr_bool peerIdIsSet; - tr_bool extendedProtocolSupported; - tr_bool fastExtensionSupported; - tr_bool dhtSupported; - tr_bool utpSupported; + bool isEncrypted; + bool isIncoming; + bool peerIdIsSet; + bool extendedProtocolSupported; + bool fastExtensionSupported; + bool dhtSupported; + bool utpSupported; tr_priority_t priority; @@ -80,7 +80,7 @@ typedef struct tr_peerIo int magicNumber; uint32_t encryptionMode; - tr_bool isSeed; + bool isSeed; tr_port port; int socket; @@ -121,8 +121,8 @@ tr_peerIo* tr_peerIoNewOutgoing( tr_session * session, const struct tr_address * addr, tr_port port, const uint8_t * torrentHash, - tr_bool isSeed, - tr_bool utp ); + bool isSeed, + bool utp ); tr_peerIo* tr_peerIoNewIncoming( tr_session * session, @@ -146,7 +146,7 @@ void tr_peerIoUnrefImpl ( const char * file, #define PEER_IO_MAGIC_NUMBER 206745 -static inline tr_bool +static inline bool tr_isPeerIo( const tr_peerIo * io ) { return ( io != NULL ) @@ -160,34 +160,34 @@ tr_isPeerIo( const tr_peerIo * io ) *** **/ -static inline void tr_peerIoEnableFEXT( tr_peerIo * io, tr_bool flag ) +static inline void tr_peerIoEnableFEXT( tr_peerIo * io, bool flag ) { io->fastExtensionSupported = flag; } -static inline tr_bool tr_peerIoSupportsFEXT( const tr_peerIo * io ) +static inline bool tr_peerIoSupportsFEXT( const tr_peerIo * io ) { return io->fastExtensionSupported; } -static inline void tr_peerIoEnableLTEP( tr_peerIo * io, tr_bool flag ) +static inline void tr_peerIoEnableLTEP( tr_peerIo * io, bool flag ) { io->extendedProtocolSupported = flag; } -static inline tr_bool tr_peerIoSupportsLTEP( const tr_peerIo * io ) +static inline bool tr_peerIoSupportsLTEP( const tr_peerIo * io ) { return io->extendedProtocolSupported; } -static inline void tr_peerIoEnableDHT( tr_peerIo * io, tr_bool flag ) +static inline void tr_peerIoEnableDHT( tr_peerIo * io, bool flag ) { io->dhtSupported = flag; } -static inline tr_bool tr_peerIoSupportsDHT( const tr_peerIo * io ) +static inline bool tr_peerIoSupportsDHT( const tr_peerIo * io ) { return io->dhtSupported; } -static inline tr_bool tr_peerIoSupportsUTP( const tr_peerIo * io ) +static inline bool tr_peerIoSupportsUTP( const tr_peerIo * io ) { return io->dhtSupported; } @@ -221,7 +221,7 @@ void tr_peerIoSetTorrentHash( tr_peerIo * io, int tr_peerIoReconnect( tr_peerIo * io ); -static inline tr_bool tr_peerIoIsIncoming( const tr_peerIo * io ) +static inline bool tr_peerIoIsIncoming( const tr_peerIo * io ) { return io->isIncoming; } @@ -266,11 +266,11 @@ void tr_peerIoClear ( tr_peerIo * io ); void tr_peerIoWriteBytes ( tr_peerIo * io, const void * writeme, size_t writemeLen, - tr_bool isPieceData ); + bool isPieceData ); void tr_peerIoWriteBuf ( tr_peerIo * io, struct evbuffer * buf, - tr_bool isPieceData ); + bool isPieceData ); /** *** @@ -291,7 +291,7 @@ EncryptionMode; void tr_peerIoSetEncryption( tr_peerIo * io, uint32_t encryptionMode ); -static inline tr_bool +static inline bool tr_peerIoIsEncrypted( const tr_peerIo * io ) { return ( io != NULL ) && ( io->encryptionMode == PEER_ENCRYPTION_RC4 ); @@ -361,7 +361,7 @@ void tr_peerIoBandwidthUsed( tr_peerIo * io, size_t byteCount, int isPieceData ); -static inline tr_bool +static inline bool tr_peerIoHasBandwidthLeft( const tr_peerIo * io, tr_direction dir ) { return tr_bandwidthClamp( &io->bandwidth, dir, 1024 ) > 0; @@ -379,7 +379,7 @@ tr_peerIoGetPieceSpeed_Bps( const tr_peerIo * io, uint64_t now, tr_direction dir void tr_peerIoSetEnabled( tr_peerIo * io, tr_direction dir, - tr_bool isEnabled ); + bool isEnabled ); int tr_peerIoFlush( tr_peerIo * io, tr_direction dir, diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index ba01340d4..cb9b732fb 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -99,7 +99,7 @@ enum CANCEL_HISTORY_SEC = 60 }; -const tr_peer_event TR_PEER_EVENT_INIT = { 0, 0, NULL, 0, 0, 0, FALSE, 0 }; +const tr_peer_event TR_PEER_EVENT_INIT = { 0, 0, NULL, 0, 0, 0, false, 0 }; /** *** @@ -121,10 +121,10 @@ struct peer_atom uint8_t flags; /* these match the added_f flags */ uint8_t flags2; /* flags that aren't defined in added_f */ int8_t seedProbability; /* how likely is this to be a seed... [0..100] or -1 for unknown */ - int8_t blocklisted; /* -1 for unknown, TRUE for blocklisted, FALSE for not blocklisted */ + int8_t blocklisted; /* -1 for unknown, true for blocklisted, false for not blocklisted */ tr_port port; - tr_bool utp_failed; /* We recently failed to connect over uTP */ + bool utp_failed; /* We recently failed to connect over uTP */ uint16_t numFails; time_t time; /* when the peer's connection status last changed */ time_t piece_data_time; @@ -142,7 +142,7 @@ struct peer_atom #ifdef NDEBUG #define tr_isAtom(a) (TRUE) #else -static tr_bool +static bool tr_isAtom( const struct peer_atom * atom ) { return ( atom != NULL ) @@ -193,8 +193,8 @@ typedef struct tr_torrent_peers tr_peer * optimistic; /* the optimistic peer, or NULL if none */ int optimisticUnchokeTimeScaler; - tr_bool isRunning; - tr_bool needsCompletenessCheck; + bool isRunning; + bool needsCompletenessCheck; struct block_request * requests; int requestCount; @@ -358,7 +358,7 @@ getExistingAtom( const Torrent * t, return tr_ptrArrayFindSorted( &tt->pool, addr, comparePeerAtomToAddress ); } -static tr_bool +static bool peerIsInUse( const Torrent * ct, const struct peer_atom * atom ) { Torrent * t = (Torrent*) ct; @@ -450,7 +450,7 @@ peerDelete( Torrent * t, tr_peer * peer ) tr_free( peer ); } -static tr_bool +static bool replicationExists( const Torrent * t ) { return t->pieceReplication != NULL; @@ -589,7 +589,7 @@ static int clientIsDownloadingFrom( const tr_torrent * tor, const tr_peer * peer ) { if( !tr_torrentHasMetadata( tor ) ) - return TRUE; + return true; return peer->clientIsInterested && !peer->clientIsChoked; } @@ -624,7 +624,7 @@ tr_peerMgrOnBlocklistChanged( tr_peerMgr * mgr ) } } -static tr_bool +static bool isAtomBlocklisted( tr_session * session, struct peer_atom * atom ) { if( atom->blocklisted < 0 ) @@ -653,7 +653,7 @@ atomSetSeedProbability( struct peer_atom * atom, int seedProbability ) atom->flags &= ~ADDED_F_SEED_FLAG; } -static inline tr_bool +static inline bool atomIsSeed( const struct peer_atom * atom ) { return atom->seedProbability == 100; @@ -671,11 +671,11 @@ atomSetSeed( const Torrent * t, struct peer_atom * atom ) } -tr_bool +bool tr_peerMgrPeerIsSeed( const tr_torrent * tor, const tr_address * addr ) { - tr_bool isSeed = FALSE; + bool isSeed = false; const Torrent * t = tor->torrentPeers; const struct peer_atom * atom = getExistingAtom( t, addr ); @@ -695,7 +695,7 @@ tr_peerMgrSetUtpSupported( tr_torrent * tor, const tr_address * addr ) } void -tr_peerMgrSetUtpFailed( tr_torrent *tor, const tr_address *addr, tr_bool failed ) +tr_peerMgrSetUtpFailed( tr_torrent *tor, const tr_address *addr, bool failed ) { struct peer_atom * atom = getExistingAtom( tor->torrentPeers, addr ); @@ -761,7 +761,7 @@ requestListAdd( Torrent * t, tr_block_index_t block, tr_peer * peer ) /* insert the request to our array... */ { - tr_bool exact; + bool exact; const int pos = tr_lowerBound( &key, t->requests, t->requestCount, sizeof( struct block_request ), compareReqByBlock, &exact ); @@ -803,7 +803,7 @@ static void getBlockRequestPeers( Torrent * t, tr_block_index_t block, tr_ptrArray * peerArr ) { - tr_bool exact; + bool exact; int i, pos; struct block_request key; @@ -1144,7 +1144,7 @@ static void pieceListResortPiece( Torrent * t, struct weighted_piece * p ) { int pos; - tr_bool isSorted = TRUE; + bool isSorted = true; if( p == NULL ) return; @@ -1153,20 +1153,20 @@ pieceListResortPiece( Torrent * t, struct weighted_piece * p ) pos = p - t->pieces; setComparePieceByWeightTorrent( t ); if( isSorted && ( pos > 0 ) && ( comparePieceByWeight( p-1, p ) > 0 ) ) - isSorted = FALSE; + isSorted = false; if( isSorted && ( pos < t->pieceCount - 1 ) && ( comparePieceByWeight( p, p+1 ) > 0 ) ) - isSorted = FALSE; + isSorted = false; if( t->pieceSortState != PIECES_SORTED_BY_WEIGHT ) { pieceListSort( t, PIECES_SORTED_BY_WEIGHT); - isSorted = TRUE; + isSorted = true; } /* if it's not sorted, move it around */ if( !isSorted ) { - tr_bool exact; + bool exact; const struct weighted_piece tmp = *p; tr_removeElementFromArray( t->pieces, @@ -1412,7 +1412,7 @@ tr_peerMgrGetNextRequests( tr_torrent * tor, setComparePieceByWeightTorrent( t ); while( --i >= 0 ) { - tr_bool exact; + bool exact; /* relative position! */ const int newpos = tr_lowerBound( &t->pieces[i], &t->pieces[i + 1], @@ -1434,7 +1434,7 @@ tr_peerMgrGetNextRequests( tr_torrent * tor, *numgot = got; } -tr_bool +bool tr_peerMgrDidPeerRequest( const tr_torrent * tor, const tr_peer * peer, tr_block_index_t block ) @@ -1691,11 +1691,11 @@ peerCallbackFunc( tr_peer * peer, const tr_peer_event * e, void * vt ) break; case TR_PEER_CLIENT_GOT_SUGGEST: - peerSuggestedPiece( t, peer, e->pieceIndex, FALSE ); + peerSuggestedPiece( t, peer, e->pieceIndex, false ); break; case TR_PEER_CLIENT_GOT_ALLOWED_FAST: - peerSuggestedPiece( t, peer, e->pieceIndex, TRUE ); + peerSuggestedPiece( t, peer, e->pieceIndex, true ); break; case TR_PEER_CLIENT_GOT_DATA: @@ -1744,7 +1744,7 @@ peerCallbackFunc( tr_peer * peer, const tr_peer_event * e, void * vt ) removeRequestFromTables( t, block, p ); } - tr_ptrArrayDestruct( &peerArr, FALSE ); + tr_ptrArrayDestruct( &peerArr, false ); tr_historyAdd( &peer->blocksSentToClient, tr_time( ), 1 ); @@ -1764,7 +1764,7 @@ peerCallbackFunc( tr_peer * peer, const tr_peer_event * e, void * vt ) if( tr_cpPieceIsComplete( &tor->completion, e->pieceIndex ) ) { const tr_piece_index_t p = e->pieceIndex; - const tr_bool ok = tr_torrentCheckPiece( tor, p ); + const bool ok = tr_torrentCheckPiece( tor, p ); tordbg( t, "[LAZY] checked just-completed piece %zu", (size_t)p ); @@ -1817,7 +1817,7 @@ peerCallbackFunc( tr_peer * peer, const tr_peer_event * e, void * vt ) } } - t->needsCompletenessCheck = TRUE; + t->needsCompletenessCheck = true; } break; } @@ -1917,16 +1917,16 @@ getPeerCount( const Torrent * t ) } /* FIXME: this is kind of a mess. */ -static tr_bool +static bool myHandshakeDoneCB( tr_handshake * handshake, tr_peerIo * io, - tr_bool readAnythingFromPeer, - tr_bool isConnected, + bool readAnythingFromPeer, + bool isConnected, const uint8_t * peer_id, void * vmanager ) { - tr_bool ok = isConnected; - tr_bool success = FALSE; + bool ok = isConnected; + bool success = false; tr_port port; const tr_address * addr; tr_peerMgr * manager = vmanager; @@ -2030,7 +2030,7 @@ myHandshakeDoneCB( tr_handshake * handshake, tr_peerIoSetParent( peer->io, t->tor->bandwidth ); tr_peerMsgsNew( t->tor, peer, peerCallbackFunc, t ); - success = TRUE; + success = true; } } } @@ -2248,10 +2248,10 @@ static int peerPrefersCrypto( const tr_peer * peer ) { if( peer->encryption_preference == ENCRYPTION_PREFERENCE_YES ) - return TRUE; + return true; if( peer->encryption_preference == ENCRYPTION_PREFERENCE_NO ) - return FALSE; + return false; return tr_peerIoIsEncrypted( peer->io ); } @@ -2393,7 +2393,7 @@ tr_peerMgrStartTorrent( tr_torrent * tor ) ensureMgrTimersExist( t->manager ); - t->isRunning = TRUE; + t->isRunning = true; t->maxPeers = t->tor->maxConnectedPeers; t->pieceSortState = PIECES_UNSORTED; @@ -2405,7 +2405,7 @@ stopTorrent( Torrent * t ) { int i, n; - t->isRunning = FALSE; + t->isRunning = false; replicationFree( t ); invalidatePieceSorting( t ); @@ -2506,7 +2506,7 @@ tr_peerMgrTorrentAvailability( const tr_torrent * tor, int8_t * tab, unsigned in const int peerCount = tr_ptrArraySize( &tor->torrentPeers->peers ); const tr_peer ** peers = (const tr_peer**) tr_ptrArrayBase( &tor->torrentPeers->peers ); const float interval = tor->info.pieceCount / (float)tabCount; - const tr_bool isSeed = tr_cpGetStatus( &tor->completion ) == TR_SEED; + const bool isSeed = tr_cpGetStatus( &tor->completion ) == TR_SEED; for( i=0; i<tabCount; ++i ) { @@ -2626,16 +2626,16 @@ tr_peerGetPieceSpeed_Bps( const tr_peer * peer, uint64_t now, tr_direction direc return peer->io ? tr_peerIoGetPieceSpeed_Bps( peer->io, now, direction ) : 0.0; } -static tr_bool +static bool peerIsSeed( const tr_peer * peer ) { if( peer->progress >= 1.0 ) - return TRUE; + return true; if( peer->atom && atomIsSeed( peer->atom ) ) - return TRUE; + return true; - return FALSE; + return false; } struct tr_peer_stat * @@ -2725,12 +2725,12 @@ tr_peerMgrClearInterest( tr_torrent * tor ) for( i=0; i<peerCount; ++i ) { const tr_peer * peer = tr_ptrArrayNth( &t->peers, i ); - tr_peerMsgsSetInterested( peer->msgs, FALSE ); + tr_peerMsgsSetInterested( peer->msgs, false ); } } /* do we still want this piece and does the peer have it? */ -static tr_bool +static bool isPieceInteresting( const tr_torrent * tor, const tr_peer * peer, tr_piece_index_t index ) { return ( !tor->info.pieces[index].dnd ) /* we want it */ @@ -2739,22 +2739,22 @@ isPieceInteresting( const tr_torrent * tor, const tr_peer * peer, tr_piece_index } /* does this peer have any pieces that we want? */ -static tr_bool +static bool isPeerInteresting( const tr_torrent * tor, const tr_peer * peer ) { tr_piece_index_t i, n; if ( tr_torrentIsSeed( tor ) ) - return FALSE; + return false; if( !tr_torrentIsPieceTransferAllowed( tor, TR_PEER_TO_CLIENT ) ) - return FALSE; + return false; for( i=0, n=tor->info.pieceCount; i<n; ++i ) if( isPieceInteresting( tor, peer, i ) ) - return TRUE; + return true; - return FALSE; + return false; } /* determines who we send "interested" messages to */ @@ -2857,7 +2857,7 @@ rechokeDownloads( Torrent * t ) if( !isPeerInteresting( t->tor, peer ) ) { - tr_peerMsgsSetInterested( peer->msgs, FALSE ); + tr_peerMsgsSetInterested( peer->msgs, false ); } else { @@ -2888,19 +2888,19 @@ rechokeDownloads( Torrent * t ) * and (2) which peers are the best candidates, * Now it's time to update our `interest' flags. */ for( i=0; i<goodCount; ++i ) { - const tr_bool b = t->interestedCount < maxPeers; + const bool b = t->interestedCount < maxPeers; tr_peerMsgsSetInterested( good[i]->msgs, b ); if( b ) ++t->interestedCount; } for( i=0; i<untestedCount; ++i ) { - const tr_bool b = t->interestedCount < maxPeers; + const bool b = t->interestedCount < maxPeers; tr_peerMsgsSetInterested( untested[i]->msgs, b ); if( b ) ++t->interestedCount; } for( i=0; i<badCount; ++i ) { - const tr_bool b = t->interestedCount < maxPeers; + const bool b = t->interestedCount < maxPeers; tr_peerMsgsSetInterested( bad[i]->msgs, b ); if( b ) ++t->interestedCount; @@ -2920,9 +2920,9 @@ rechokeDownloads( Torrent * t ) struct ChokeData { - tr_bool isInterested; - tr_bool wasChoked; - tr_bool isChoked; + bool isInterested; + bool wasChoked; + bool isChoked; int rate; int salt; tr_peer * peer; @@ -2976,12 +2976,12 @@ getRate( const tr_torrent * tor, struct peer_atom * atom, uint64_t now ) return Bps; } -static inline tr_bool +static inline bool isBandwidthMaxedOut( const tr_bandwidth * b, const uint64_t now_msec, tr_direction dir ) { if( !tr_bandwidthIsLimited( b, dir ) ) - return FALSE; + return false; else { const int got = tr_bandwidthGetPieceSpeed_Bps( b, now_msec, dir ); const int want = tr_bandwidthGetDesiredSpeed_Bps( b, dir ); @@ -2998,7 +2998,7 @@ rechokeUploads( Torrent * t, const uint64_t now ) struct ChokeData * choke = tr_new0( struct ChokeData, peerCount ); const tr_session * session = t->manager->session; const int chokeAll = !tr_torrentIsPieceTransferAllowed( t->tor, TR_CLIENT_TO_PEER ); - const tr_bool isMaxedOut = isBandwidthMaxedOut( t->tor->bandwidth, now, TR_UP ); + const bool isMaxedOut = isBandwidthMaxedOut( t->tor->bandwidth, now, TR_UP ); assert( torrentIsLocked( t ) ); @@ -3017,11 +3017,11 @@ rechokeUploads( Torrent * t, const uint64_t now ) if( peerIsSeed( peer ) ) /* choke seeds and partial seeds */ { - tr_peerMsgsSetChoke( peer->msgs, TRUE ); + tr_peerMsgsSetChoke( peer->msgs, true ); } else if( chokeAll ) /* choke everyone if we're not uploading */ { - tr_peerMsgsSetChoke( peer->msgs, TRUE ); + tr_peerMsgsSetChoke( peer->msgs, true ); } else if( peer != t->optimistic ) { @@ -3031,7 +3031,7 @@ rechokeUploads( Torrent * t, const uint64_t now ) n->wasChoked = peer->peerIsChoked; n->rate = getRate( t->tor, atom, now ); n->salt = tr_cryptoWeakRandInt( INT_MAX ); - n->isChoked = TRUE; + n->isChoked = true; } } @@ -3054,7 +3054,7 @@ rechokeUploads( Torrent * t, const uint64_t now ) */ unchokedInterested = 0; for( i=0; i<size && unchokedInterested<session->uploadSlotsPerTorrent; ++i ) { - choke[i].isChoked = isMaxedOut ? choke[i].wasChoked : FALSE; + choke[i].isChoked = isMaxedOut ? choke[i].wasChoked : false; if( choke[i].isInterested ) ++unchokedInterested; } @@ -3081,7 +3081,7 @@ rechokeUploads( Torrent * t, const uint64_t now ) if(( n = tr_ptrArraySize( &randPool ))) { c = tr_ptrArrayNth( &randPool, tr_cryptoWeakRandInt( n )); - c->isChoked = FALSE; + c->isChoked = false; t->optimistic = c->peer; t->optimisticUnchokeTimeScaler = OPTIMISTIC_UNCHOKE_MULTIPLIER; } @@ -3123,7 +3123,7 @@ rechokePulse( int foo UNUSED, short bar UNUSED, void * vmgr ) **** ***/ -static tr_bool +static bool shouldPeerBeClosed( const Torrent * t, const tr_peer * peer, int peerCount, @@ -3137,7 +3137,7 @@ shouldPeerBeClosed( const Torrent * t, { tordbg( t, "purging peer %s because its doPurge flag is set", tr_atomAddrStr( atom ) ); - return TRUE; + return true; } /* disconnect if we're both seeds and enough time has passed for PEX */ @@ -3161,11 +3161,11 @@ shouldPeerBeClosed( const Torrent * t, if( idleTime > limit ) { tordbg( t, "purging peer %s because it's been %d secs since we shared anything", tr_atomAddrStr( atom ), idleTime ); - return TRUE; + return true; } } - return FALSE; + return false; } static tr_peer ** @@ -3290,7 +3290,7 @@ struct peer_liveliness time_t pieceDataTime; time_t time; int speed; - tr_bool doPurge; + bool doPurge; }; static int @@ -3505,7 +3505,7 @@ bandwidthPulse( int foo UNUSED, short bar UNUSED, void * vmgr ) tor = NULL; while(( tor = tr_torrentNext( mgr->session, tor ))) { if( tor->torrentPeers->needsCompletenessCheck ) { - tor->torrentPeers->needsCompletenessCheck = FALSE; + tor->torrentPeers->needsCompletenessCheck = false; tr_torrentRecheckCompleteness( tor ); } } @@ -3645,30 +3645,30 @@ atomPulse( int foo UNUSED, short bar UNUSED, void * vmgr ) ***/ /* is this atom someone that we'd want to initiate a connection to? */ -static tr_bool +static bool isPeerCandidate( const tr_torrent * tor, struct peer_atom * atom, const time_t now ) { /* not if we're both seeds */ if( tr_torrentIsSeed( tor ) && atomIsSeed( atom ) ) - return FALSE; + return false; /* not if we've already got a connection to them... */ if( peerIsInUse( tor->torrentPeers, atom ) ) - return FALSE; + return false; /* not if we just tried them already */ if( ( now - atom->time ) < getReconnectIntervalSecs( atom, now ) ) - return FALSE; + return false; /* not if they're blocklisted */ if( isAtomBlocklisted( tor->session, atom ) ) - return FALSE; + return false; /* not if they're banned... */ if( atom->flags2 & MYFLAG_BANNED ) - return FALSE; + return false; - return TRUE; + return true; } struct peer_candidate @@ -3678,7 +3678,7 @@ struct peer_candidate struct peer_atom * atom; }; -static tr_bool +static bool torrentWasRecentlyStarted( const tr_torrent * tor ) { return difftime( tr_time( ), tor->startDate ) < 120; @@ -3698,7 +3698,7 @@ getPeerCandidateScore( const tr_torrent * tor, const struct peer_atom * atom, ui { uint64_t i; uint64_t score = 0; - const tr_bool failed = atom->lastConnectionAt < atom->lastConnectionAttemptAt; + const bool failed = atom->lastConnectionAt < atom->lastConnectionAttemptAt; /* prefer peers we've connected to, or never tried, over peers we failed to connect to. */ i = failed ? 1 : 0; @@ -3833,7 +3833,7 @@ initiateConnection( tr_peerMgr * mgr, Torrent * t, struct peer_atom * atom ) { tr_peerIo * io; const time_t now = tr_time( ); - tr_bool utp = tr_sessionIsUTPEnabled(mgr->session) && !atom->utp_failed; + bool utp = tr_sessionIsUTPEnabled(mgr->session) && !atom->utp_failed; if( atom->fromFirst == TR_PEER_FROM_PEX ) /* PEX has explicit signalling for uTP support. If an atom diff --git a/libtransmission/peer-mgr.h b/libtransmission/peer-mgr.h index 1332ca233..764ece9fc 100644 --- a/libtransmission/peer-mgr.h +++ b/libtransmission/peer-mgr.h @@ -89,11 +89,11 @@ struct peer_atom; */ typedef struct tr_peer { - tr_bool peerIsChoked; - tr_bool peerIsInterested; - tr_bool clientIsChoked; - tr_bool clientIsInterested; - tr_bool doPurge; + bool peerIsChoked; + bool peerIsInterested; + bool clientIsChoked; + bool clientIsInterested; + bool doPurge; /* number of bad pieces they've contributed to */ uint8_t strikes; @@ -136,7 +136,7 @@ void tr_peerConstruct( struct tr_peer * peer ); void tr_peerDestruct( tr_torrent * tor, struct tr_peer * peer ); -static inline tr_bool +static inline bool tr_isPex( const tr_pex * pex ) { return pex && tr_isAddress( &pex->addr ); @@ -150,7 +150,7 @@ tr_peerMgr* tr_peerMgrNew( tr_session * ); void tr_peerMgrFree( tr_peerMgr * manager ); -tr_bool tr_peerMgrPeerIsSeed( const tr_torrent * tor, +bool tr_peerMgrPeerIsSeed( const tr_torrent * tor, const tr_address * addr ); void tr_peerMgrSetUtpSupported( tr_torrent * tor, @@ -158,7 +158,7 @@ void tr_peerMgrSetUtpSupported( tr_torrent * tor, void tr_peerMgrSetUtpFailed( tr_torrent *tor, const tr_address *addr, - tr_bool failed ); + bool failed ); void tr_peerMgrGetNextRequests( tr_torrent * torrent, tr_peer * peer, @@ -166,9 +166,9 @@ void tr_peerMgrGetNextRequests( tr_torrent * torrent, tr_block_index_t * setme, int * numgot ); -tr_bool tr_peerMgrDidPeerRequest( const tr_torrent * torrent, - const tr_peer * peer, - tr_block_index_t block ); +bool tr_peerMgrDidPeerRequest( const tr_torrent * torrent, + const tr_peer * peer, + tr_block_index_t block ); void tr_peerMgrRebuildRequests( tr_torrent * torrent ); diff --git a/libtransmission/peer-msgs.c b/libtransmission/peer-msgs.c index c55394b26..e8c873e6c 100644 --- a/libtransmission/peer-msgs.c +++ b/libtransmission/peer-msgs.c @@ -156,12 +156,12 @@ struct tr_incoming */ struct tr_peermsgs { - tr_bool peerSupportsPex; - tr_bool peerSupportsMetadataXfer; - tr_bool clientSentLtepHandshake; - tr_bool peerSentLtepHandshake; + bool peerSupportsPex; + bool peerSupportsMetadataXfer; + bool clientSentLtepHandshake; + bool peerSentLtepHandshake; - /*tr_bool haveFastSet;*/ + /*bool haveFastSet;*/ int desiredRequestCount; @@ -558,7 +558,7 @@ fireClientGotHave( tr_peermsgs * msgs, tr_piece_index_t index ) } static void -firePeerGotData( tr_peermsgs * msgs, uint32_t length, tr_bool wasPieceData ) +firePeerGotData( tr_peermsgs * msgs, uint32_t length, bool wasPieceData ) { tr_peer_event e = TR_PEER_EVENT_INIT; @@ -632,7 +632,7 @@ tr_generateAllowedSet( tr_piece_index_t * setmePieces, static void updateFastSet( tr_peermsgs * msgs UNUSED ) { - const tr_bool fext = tr_peerIoSupportsFEXT( msgs->peer->io ); + const bool fext = tr_peerIoSupportsFEXT( msgs->peer->io ); const int peerIsNeedy = msgs->peer->progress < 0.10; if( fext && peerIsNeedy && !msgs->haveFastSet ) @@ -658,7 +658,7 @@ updateFastSet( tr_peermsgs * msgs UNUSED ) **/ static void -sendInterest( tr_peermsgs * msgs, tr_bool clientIsInterested ) +sendInterest( tr_peermsgs * msgs, bool clientIsInterested ) { struct evbuffer * out = msgs->outMessages; @@ -689,32 +689,32 @@ tr_peerMsgsSetInterested( tr_peermsgs * msgs, int isInterested ) sendInterest( msgs, isInterested ); } -static tr_bool +static bool popNextMetadataRequest( tr_peermsgs * msgs, int * piece ) { if( msgs->peerAskedForMetadataCount == 0 ) - return FALSE; + return false; *piece = msgs->peerAskedForMetadata[0]; tr_removeElementFromArray( msgs->peerAskedForMetadata, 0, sizeof( int ), msgs->peerAskedForMetadataCount-- ); - return TRUE; + return true; } -static tr_bool +static bool popNextRequest( tr_peermsgs * msgs, struct peer_request * setme ) { if( msgs->peer->pendingReqsToClient == 0 ) - return FALSE; + return false; *setme = msgs->peerAskedFor[0]; tr_removeElementFromArray( msgs->peerAskedFor, 0, sizeof( struct peer_request ), msgs->peer->pendingReqsToClient-- ); - return TRUE; + return true; } static void @@ -769,7 +769,7 @@ tr_peerMsgsHave( tr_peermsgs * msgs, uint32_t index ) *** **/ -static tr_bool +static bool reqIsValid( const tr_peermsgs * peer, uint32_t index, uint32_t offset, @@ -778,7 +778,7 @@ reqIsValid( const tr_peermsgs * peer, return tr_torrentReqIsValid( peer->torrent, index, offset, length ); } -static tr_bool +static bool requestIsValid( const tr_peermsgs * msgs, const struct peer_request * req ) { return reqIsValid( msgs, req->index, req->offset, req->length ); @@ -803,8 +803,8 @@ sendLtepHandshake( tr_peermsgs * msgs ) tr_benc val, *m; char * buf; int len; - tr_bool allow_pex; - tr_bool allow_metadata_xfer; + bool allow_pex; + bool allow_metadata_xfer; struct evbuffer * out = msgs->outMessages; const unsigned char * ipv6 = tr_globalIPv6(); @@ -912,7 +912,7 @@ parseLtepHandshake( tr_peermsgs * msgs, int len, struct evbuffer * inbuf ) it implies support for µTP, so use it to indicate that. */ tr_peerMgrSetUtpFailed( msgs->torrent, tr_peerIoGetAddress( msgs->peer->io, NULL ), - FALSE ); + false ); } } @@ -1218,12 +1218,12 @@ prefetchPieces( tr_peermsgs *msgs ) static void peerMadeRequest( tr_peermsgs * msgs, const struct peer_request * req ) { - const tr_bool fext = tr_peerIoSupportsFEXT( msgs->peer->io ); + const bool fext = tr_peerIoSupportsFEXT( msgs->peer->io ); const int reqIsValid = requestIsValid( msgs, req ); const int clientHasPiece = reqIsValid && tr_cpPieceIsComplete( &msgs->torrent->completion, req->index ); const int peerIsChoked = msgs->peer->peerIsChoked; - int allow = FALSE; + int allow = false; if( !reqIsValid ) dbgmsg( msgs, "rejecting an invalid request." ); @@ -1234,7 +1234,7 @@ peerMadeRequest( tr_peermsgs * msgs, const struct peer_request * req ) else if( msgs->peer->pendingReqsToClient + 1 >= REQQ ) dbgmsg( msgs, "rejecting request ... reqq is full" ); else - allow = TRUE; + allow = true; if( allow ) { msgs->peerAskedFor[msgs->peer->pendingReqsToClient++] = *req; @@ -1244,7 +1244,7 @@ peerMadeRequest( tr_peermsgs * msgs, const struct peer_request * req ) } } -static tr_bool +static bool messageLengthIsCorrect( const tr_peermsgs * msg, uint8_t id, uint32_t len ) { switch( id ) @@ -1266,10 +1266,10 @@ messageLengthIsCorrect( const tr_peermsgs * msg, uint8_t id, uint32_t len ) if( tr_torrentHasMetadata( msg->torrent ) ) return len == ( msg->torrent->info.pieceCount + 7u ) / 8u + 1u; /* we don't know the piece count yet, - so we can only guess whether to send TRUE or FALSE */ + so we can only guess whether to send true or false */ if( msg->metadata_size_hint > 0 ) return len <= msg->metadata_size_hint; - return TRUE; + return true; case BT_REQUEST: case BT_CANCEL: @@ -1286,7 +1286,7 @@ messageLengthIsCorrect( const tr_peermsgs * msg, uint8_t id, uint32_t len ) return len >= 2; default: - return FALSE; + return false; } } @@ -1338,7 +1338,7 @@ readBtPiece( tr_peermsgs * msgs, tr_sessionReleaseBuffer( getSession( msgs ) ); buf = NULL; - fireClientGotData( msgs, n, TRUE ); + fireClientGotData( msgs, n, true ); *setme_piece_bytes_read += n; dbgmsg( msgs, "got %zu bytes for block %u:%u->%u ... %d remain", n, req->index, req->offset, req->length, @@ -1369,7 +1369,7 @@ readBtMessage( tr_peermsgs * msgs, struct evbuffer * inbuf, size_t inlen ) #ifndef NDEBUG const size_t startBufLen = evbuffer_get_length( inbuf ); #endif - const tr_bool fext = tr_peerIoSupportsFEXT( msgs->peer->io ); + const bool fext = tr_peerIoSupportsFEXT( msgs->peer->io ); --msglen; /* id length */ @@ -1669,7 +1669,7 @@ canRead( tr_peerIo * io, void * vmsgs, size_t * piece ) /* log the raw data that was read */ if( ( ret != READ_ERR ) && ( evbuffer_get_length( in ) != inlen ) ) - fireClientGotData( msgs, inlen - evbuffer_get_length( in ), FALSE ); + fireClientGotData( msgs, inlen - evbuffer_get_length( in ), false ); return ret; } @@ -1678,7 +1678,7 @@ int tr_peerMsgsIsReadingBlock( const tr_peermsgs * msgs, tr_block_index_t block ) { if( msgs->state != AWAITING_BT_PIECE ) - return FALSE; + return false; return block == _tr_block( msgs->torrent, msgs->incoming.blockReq.index, @@ -1803,8 +1803,8 @@ fillOutputBuffer( tr_peermsgs * msgs, time_t now ) int piece; size_t bytesWritten = 0; struct peer_request req; - const tr_bool haveMessages = evbuffer_get_length( msgs->outMessages ) != 0; - const tr_bool fext = tr_peerIoSupportsFEXT( msgs->peer->io ); + const bool haveMessages = evbuffer_get_length( msgs->outMessages ) != 0; + const bool fext = tr_peerIoSupportsFEXT( msgs->peer->io ); /** *** Protocol messages @@ -1820,7 +1820,7 @@ fillOutputBuffer( tr_peermsgs * msgs, time_t now ) const size_t len = evbuffer_get_length( msgs->outMessages ); /* flush the protocol messages */ dbgmsg( msgs, "flushing outMessages... to %p (length is %zu)", msgs->peer->io, len ); - tr_peerIoWriteBuf( msgs->peer->io, msgs->outMessages, FALSE ); + tr_peerIoWriteBuf( msgs->peer->io, msgs->outMessages, false ); msgs->clientSentAnythingAt = now; msgs->outMessagesBatchedAt = 0; msgs->outMessagesBatchPeriod = LOW_PRIORITY_INTERVAL_SECS; @@ -1836,7 +1836,7 @@ fillOutputBuffer( tr_peermsgs * msgs, time_t now ) { char * data; int dataLen; - tr_bool ok = FALSE; + bool ok = false; data = tr_torrentGetMetadataPiece( msgs->torrent, piece, &dataLen ); if( ( dataLen > 0 ) && ( data != NULL ) ) @@ -1866,7 +1866,7 @@ fillOutputBuffer( tr_peermsgs * msgs, time_t now ) tr_free( payload ); tr_free( data ); - ok = TRUE; + ok = true; } if( !ok ) /* send a rejection message */ @@ -1940,7 +1940,7 @@ fillOutputBuffer( tr_peermsgs * msgs, time_t now ) const size_t n = evbuffer_get_length( out ); dbgmsg( msgs, "sending block %u:%u->%u", req.index, req.offset, req.length ); assert( n == msglen ); - tr_peerIoWriteBuf( msgs->peer->io, out, TRUE ); + tr_peerIoWriteBuf( msgs->peer->io, out, true ); bytesWritten += n; msgs->clientSentAnythingAt = now; tr_historyAdd( &msgs->peer->blocksSentToPeer, tr_time( ), 1 ); @@ -1995,7 +1995,7 @@ peerPulse( void * vmsgs ) if( fillOutputBuffer( msgs, now ) < 1 ) break; - return TRUE; /* loop forever */ + return true; /* loop forever */ } void @@ -2034,7 +2034,7 @@ sendBitfield( tr_peermsgs * msgs ) static void tellPeerWhatWeHave( tr_peermsgs * msgs ) { - const tr_bool fext = tr_peerIoSupportsFEXT( msgs->peer->io ); + const bool fext = tr_peerIoSupportsFEXT( msgs->peer->io ); if( fext && ( tr_cpBlockBitset( &msgs->torrent->completion )->haveAll ) ) { @@ -2319,7 +2319,7 @@ tr_peerMsgsNew( struct tr_torrent * torrent, if( tr_peerIoSupportsUTP( peer->io ) ) { const tr_address * addr = tr_peerIoGetAddress( peer->io, NULL ); tr_peerMgrSetUtpSupported( torrent, addr ); - tr_peerMgrSetUtpFailed( torrent, addr, FALSE ); + tr_peerMgrSetUtpFailed( torrent, addr, false ); } if( tr_peerIoSupportsLTEP( peer->io ) ) diff --git a/libtransmission/platform.c b/libtransmission/platform.c index 119d22f80..4f914ce6f 100644 --- a/libtransmission/platform.c +++ b/libtransmission/platform.c @@ -77,7 +77,7 @@ tr_getCurrentThread( void ) #endif } -static tr_bool +static bool tr_areThreadsEqual( tr_thread_id a, tr_thread_id b ) { #ifdef WIN32 @@ -98,7 +98,7 @@ struct tr_thread #endif }; -tr_bool +bool tr_amInThread( const tr_thread * t ) { return tr_areThreadsEqual( tr_getCurrentThread( ), t->thread ); @@ -377,14 +377,14 @@ moveFiles( const char * oldDir, static void migrateFiles( const tr_session * session ) { - static int migrated = FALSE; - const tr_bool should_migrate = strstr( getOldConfigDir(), ".transmission" ) != NULL; + static int migrated = false; + const bool should_migrate = strstr( getOldConfigDir(), ".transmission" ) != NULL; if( !migrated && should_migrate ) { const char * oldDir; const char * newDir; - migrated = TRUE; + migrated = true; oldDir = getOldTorrentsDir( ); newDir = tr_getTorrentDir( session ); @@ -575,7 +575,7 @@ tr_getWebClientDir( const tr_session * session UNUSED ) CFStringGetFastestEncoding( appRef )); char * appString = tr_malloc( appLength + 1 ); - tr_bool success = CFStringGetCString( appRef, + bool success = CFStringGetCString( appRef, appString, appLength + 1, CFStringGetFastestEncoding( appRef )); diff --git a/libtransmission/platform.h b/libtransmission/platform.h index d438d50ea..fff1a58d1 100644 --- a/libtransmission/platform.h +++ b/libtransmission/platform.h @@ -73,7 +73,7 @@ tr_thread* tr_threadNew( void ( *func )(void *), void * arg ); /** @brief Return nonzero if this function is being called from `thread' @param thread the thread being tested */ -tr_bool tr_amInThread( const tr_thread * ); +bool tr_amInThread( const tr_thread * ); /*** **** diff --git a/libtransmission/port-forwarding.c b/libtransmission/port-forwarding.c index f861278cd..031c8121a 100644 --- a/libtransmission/port-forwarding.c +++ b/libtransmission/port-forwarding.c @@ -34,9 +34,9 @@ getKey( void ) { return _( "Port Forwarding" ); } struct tr_shared { - tr_bool isEnabled; - tr_bool isShuttingDown; - tr_bool doPortCheck; + bool isEnabled; + bool isShuttingDown; + bool doPortCheck; tr_port_forwarding natpmpStatus; tr_port_forwarding upnpStatus; @@ -66,7 +66,7 @@ getNatStateStr( int state ) } static void -natPulse( tr_shared * s, tr_bool do_check ) +natPulse( tr_shared * s, bool do_check ) { const tr_port private_peer_port = s->session->private_peer_port; const int is_enabled = s->isEnabled && !s->isShuttingDown; @@ -106,7 +106,7 @@ set_evtimer_from_status( tr_shared * s ) case TR_PORT_MAPPED: /* if we're mapped, everything is fine... check back in 20 minutes * to renew the port forwarding if it's expired */ - s->doPortCheck = TRUE; + s->doPortCheck = true; sec = 60 * 20; break; @@ -135,7 +135,7 @@ onTimer( int fd UNUSED, short what UNUSED, void * vshared ) /* do something */ natPulse( s, s->doPortCheck ); - s->doPortCheck = FALSE; + s->doPortCheck = false; /* set up the timer for the next pulse */ set_evtimer_from_status( s ); @@ -151,7 +151,7 @@ tr_sharedInit( tr_session * session ) tr_shared * s = tr_new0( tr_shared, 1 ); s->session = session; - s->isEnabled = FALSE; + s->isEnabled = false; s->upnpStatus = TR_PORT_UNMAPPED; s->natpmpStatus = TR_PORT_UNMAPPED; @@ -181,7 +181,7 @@ static void stop_forwarding( tr_shared * s ) { tr_ninf( getKey( ), "%s", _( "Stopped" ) ); - natPulse( s, FALSE ); + natPulse( s, false ); tr_natpmpClose( s->natpmp ); s->natpmp = NULL; @@ -199,7 +199,7 @@ tr_sharedClose( tr_session * session ) { tr_shared * s = session->shared; - s->isShuttingDown = TRUE; + s->isShuttingDown = true; stop_forwarding( s ); s->session->shared = NULL; tr_free( s ); @@ -213,7 +213,7 @@ start_timer( tr_shared * s ) } void -tr_sharedTraversalEnable( tr_shared * s, tr_bool isEnabled ) +tr_sharedTraversalEnable( tr_shared * s, bool isEnabled ) { if(( s->isEnabled = isEnabled )) start_timer( s ); @@ -229,12 +229,12 @@ tr_sharedPortChanged( tr_session * session ) if( s->isEnabled ) { stop_timer( s ); - natPulse( s, FALSE ); + natPulse( s, false ); start_timer( s ); } } -tr_bool +bool tr_sharedTraversalIsEnabled( const tr_shared * s ) { return s->isEnabled; diff --git a/libtransmission/port-forwarding.h b/libtransmission/port-forwarding.h index b2aa8439e..dcdfb1b6f 100644 --- a/libtransmission/port-forwarding.h +++ b/libtransmission/port-forwarding.h @@ -35,11 +35,11 @@ void tr_sharedClose( tr_session * ); void tr_sharedPortChanged( tr_session * ); -void tr_sharedTraversalEnable( tr_shared *, tr_bool isEnabled ); +void tr_sharedTraversalEnable( tr_shared *, bool isEnabled ); tr_port tr_sharedGetPeerPort( const tr_shared * s ); -tr_bool tr_sharedTraversalIsEnabled( const tr_shared * s ); +bool tr_sharedTraversalIsEnabled( const tr_shared * s ); int tr_sharedTraversalStatus( const tr_shared * ); diff --git a/libtransmission/ptrarray.c b/libtransmission/ptrarray.c index 853c68582..1403faa5e 100644 --- a/libtransmission/ptrarray.c +++ b/libtransmission/ptrarray.c @@ -117,7 +117,7 @@ tr_ptrArrayLowerBound( const tr_ptrArray * t, const void * ptr, int compare( const void *, const void * ), - tr_bool * exact_match ) + bool * exact_match ) { int len = t->n_items; int first = 0; @@ -135,7 +135,7 @@ tr_ptrArrayLowerBound( const tr_ptrArray * t, else if( !c ) { if( exact_match ) - *exact_match = TRUE; + *exact_match = true; return middle; break; } @@ -146,7 +146,7 @@ tr_ptrArrayLowerBound( const tr_ptrArray * t, } if( exact_match ) - *exact_match = FALSE; + *exact_match = false; return first; } @@ -182,7 +182,7 @@ tr_ptrArrayFindSorted( tr_ptrArray * t, const void * ptr, int compare(const void*, const void*) ) { - tr_bool match; + bool match; const int pos = tr_ptrArrayLowerBound( t, ptr, compare, &match ); return match ? t->items[pos] : NULL; @@ -194,7 +194,7 @@ tr_ptrArrayRemoveSorted( tr_ptrArray * t, int compare(const void*, const void*) ) { void * ret = NULL; - tr_bool match; + bool match; const int pos = tr_ptrArrayLowerBound( t, ptr, compare, &match ); if( match ) diff --git a/libtransmission/ptrarray.h b/libtransmission/ptrarray.h index 314a43ee5..f85e7e7d7 100644 --- a/libtransmission/ptrarray.h +++ b/libtransmission/ptrarray.h @@ -110,7 +110,7 @@ static inline int tr_ptrArraySize( const tr_ptrArray * a ) /** @brief Return True if the array has no pointers @return True if the array has no pointers */ -static inline tr_bool tr_ptrArrayEmpty( const tr_ptrArray * a ) +static inline bool tr_ptrArrayEmpty( const tr_ptrArray * a ) { return tr_ptrArraySize(a) == 0; } @@ -118,7 +118,7 @@ static inline tr_bool tr_ptrArrayEmpty( const tr_ptrArray * a ) int tr_ptrArrayLowerBound( const tr_ptrArray * array, const void * key, int compare( const void * arrayItem, const void * key ), - tr_bool * exact_match ); + bool * exact_match ); /** @brief Insert a pointer into the array at the position determined by the sort function @return the index of the stored pointer */ diff --git a/libtransmission/resume.c b/libtransmission/resume.c index cde610e37..ded64cc79 100644 --- a/libtransmission/resume.c +++ b/libtransmission/resume.c @@ -197,13 +197,13 @@ loadDND( tr_benc * dict, if( dndCount ) { - tr_torrentInitFileDLs ( tor, dnd, dndCount, FALSE ); + tr_torrentInitFileDLs ( tor, dnd, dndCount, false ); tr_tordbg( tor, "Resume file found %d files listed as dnd", dndCount ); } if( dlCount ) { - tr_torrentInitFileDLs ( tor, dl, dlCount, TRUE ); + tr_torrentInitFileDLs ( tor, dl, dlCount, true ); tr_tordbg( tor, "Resume file found %d files marked for download", dlCount ); @@ -303,7 +303,7 @@ static void loadSingleSpeedLimit( tr_benc * d, tr_direction dir, tr_torrent * tor ) { int64_t i; - tr_bool boolVal; + bool boolVal; if( tr_bencDictFindInt( d, KEY_SPEED_Bps, &i ) ) tr_torrentSetSpeedLimit_Bps( tor, dir, i ); @@ -427,7 +427,7 @@ saveProgress( tr_benc * dict, tr_torrent * tor ) const tr_piece * pend; time_t oldest_nonzero = now; time_t newest = 0; - tr_bool has_zero = FALSE; + bool has_zero = false; const time_t mtime = tr_torrentGetFileMTime( tor, fi ); const tr_file * f = &inf->files[fi]; @@ -435,7 +435,7 @@ saveProgress( tr_benc * dict, tr_torrent * tor ) for( p=&inf->pieces[f->firstPiece], pend=&inf->pieces[f->lastPiece]; p!=pend; ++p ) { if( !p->timeChecked ) - has_zero = TRUE; + has_zero = true; else if( oldest_nonzero > p->timeChecked ) oldest_nonzero = p->timeChecked; if( newest < p->timeChecked ) @@ -653,11 +653,11 @@ loadFromFile( tr_torrent * tor, { int64_t i; const char * str; - uint64_t fieldsLoaded = 0; char * filename; tr_benc top; - tr_bool boolVal; - const tr_bool wasDirty = tor->isDirty; + bool boolVal; + uint64_t fieldsLoaded = 0; + const bool wasDirty = tor->isDirty; assert( tr_isTorrent( tor ) ); @@ -810,7 +810,7 @@ setFromCtor( tr_torrent * tor, if( fields & TR_FR_RUN ) { - uint8_t isPaused; + bool isPaused; if( !tr_ctorGetPaused( ctor, mode, &isPaused ) ) { tor->isRunning = !isPaused; diff --git a/libtransmission/rpc-server.c b/libtransmission/rpc-server.c index 367a2b4c3..731181c87 100644 --- a/libtransmission/rpc-server.c +++ b/libtransmission/rpc-server.c @@ -57,9 +57,9 @@ struct tr_rpc_server { - tr_bool isEnabled; - tr_bool isPasswordEnabled; - tr_bool isWhitelistEnabled; + bool isEnabled; + bool isPasswordEnabled; + bool isWhitelistEnabled; tr_port port; char * url; struct in_addr bindAddress; @@ -74,7 +74,7 @@ struct tr_rpc_server time_t sessionIdExpiresAt; #ifdef HAVE_ZLIB - tr_bool isStreamInitialized; + bool isStreamInitialized; z_stream stream; #endif }; @@ -210,11 +210,11 @@ handle_upload( struct evhttp_request * req, { int i; int n; - tr_bool hasSessionId = FALSE; + bool hasSessionId = false; tr_ptrArray parts = TR_PTR_ARRAY_INIT; const char * query = strchr( req->uri, '?' ); - const tr_bool paused = query && strstr( query + 1, "paused=true" ); + const bool paused = query && strstr( query + 1, "paused=true" ); extract_parts_from_multipart( req->input_headers, req->input_buffer, &parts ); n = tr_ptrArraySize( &parts ); @@ -247,7 +247,7 @@ handle_upload( struct evhttp_request * req, int body_len = p->body_len; tr_benc top, *args; tr_benc test; - tr_bool have_source = FALSE; + bool have_source = false; char * body = p->body; if( body_len >= 2 && !memcmp( &body[body_len - 2], "\r\n", 2 ) ) @@ -261,14 +261,14 @@ handle_upload( struct evhttp_request * req, if( tr_urlIsValid( body, body_len ) ) { tr_bencDictAddRaw( args, "filename", body, body_len ); - have_source = TRUE; + have_source = true; } else if( !tr_bencLoad( body, body_len, &test, NULL ) ) { char * b64 = tr_base64_encode( body, body_len, NULL ); tr_bencDictAddStr( args, "metainfo", b64 ); tr_free( b64 ); - have_source = TRUE; + have_source = true; } if( have_source ) @@ -352,7 +352,7 @@ add_response( struct evhttp_request * req, struct tr_rpc_server * server, { int compressionLevel; - server->isStreamInitialized = TRUE; + server->isStreamInitialized = true; server->stream.zalloc = (alloc_func) Z_NULL; server->stream.zfree = (free_func) Z_NULL; server->stream.opaque = (voidpf) Z_NULL; @@ -562,28 +562,28 @@ handle_rpc( struct evhttp_request * req, } -static tr_bool +static bool isAddressAllowed( const tr_rpc_server * server, const char * address ) { tr_list * l; if( !server->isWhitelistEnabled ) - return TRUE; + return true; for( l=server->whitelist; l!=NULL; l=l->next ) if( tr_wildmat( address, l->data ) ) - return TRUE; + return true; - return FALSE; + return false; } -static tr_bool +static bool test_session_id( struct tr_rpc_server * server, struct evhttp_request * req ) { const char * ours = get_current_session_id( server ); const char * theirs = evhttp_find_header( req->input_headers, TR_RPC_SESSION_ID_HEADER ); - const tr_bool success = theirs && !strcmp( theirs, ours ); + const bool success = theirs && !strcmp( theirs, ours ); return success; } @@ -721,14 +721,14 @@ onEnabledChanged( void * vserver ) void tr_rpcSetEnabled( tr_rpc_server * server, - tr_bool isEnabled ) + bool isEnabled ) { server->isEnabled = isEnabled; tr_runInEventThread( server->session, onEnabledChanged, server ); } -tr_bool +bool tr_rpcIsEnabled( const tr_rpc_server * server ) { return server->isEnabled; @@ -822,12 +822,12 @@ tr_rpcGetWhitelist( const tr_rpc_server * server ) void tr_rpcSetWhitelistEnabled( tr_rpc_server * server, - tr_bool isEnabled ) + bool isEnabled ) { server->isWhitelistEnabled = isEnabled != 0; } -tr_bool +bool tr_rpcGetWhitelistEnabled( const tr_rpc_server * server ) { return server->isWhitelistEnabled; @@ -871,14 +871,13 @@ tr_rpcGetPassword( const tr_rpc_server * server ) } void -tr_rpcSetPasswordEnabled( tr_rpc_server * server, - tr_bool isEnabled ) +tr_rpcSetPasswordEnabled( tr_rpc_server * server, bool isEnabled ) { server->isPasswordEnabled = isEnabled; dbgmsg( "setting 'password enabled' to %d", (int)isEnabled ); } -tr_bool +bool tr_rpcIsPasswordEnabled( const tr_rpc_server * server ) { return server->isPasswordEnabled; @@ -929,8 +928,8 @@ tr_rpc_server * tr_rpcInit( tr_session * session, tr_benc * settings ) { tr_rpc_server * s; - tr_bool found; - tr_bool boolVal; + bool found; + bool boolVal; int64_t i; const char *str; tr_address address; diff --git a/libtransmission/rpc-server.h b/libtransmission/rpc-server.h index 33652f299..f85687930 100644 --- a/libtransmission/rpc-server.h +++ b/libtransmission/rpc-server.h @@ -24,18 +24,15 @@ tr_rpc_server * tr_rpcInit( tr_session * session, void tr_rpcClose( tr_rpc_server ** freeme ); -void tr_rpcSetEnabled( tr_rpc_server * server, - tr_bool isEnabled ); +void tr_rpcSetEnabled( tr_rpc_server * server, bool isEnabled ); -tr_bool tr_rpcIsEnabled( const tr_rpc_server * server ); +bool tr_rpcIsEnabled( const tr_rpc_server * server ); -void tr_rpcSetPort( tr_rpc_server * server, - tr_port port ); +void tr_rpcSetPort( tr_rpc_server * server, tr_port port ); tr_port tr_rpcGetPort( const tr_rpc_server * server ); -void tr_rpcSetUrl( tr_rpc_server * server, - const char * url ); +void tr_rpcSetUrl( tr_rpc_server * server, const char * url ); const char * tr_rpcGetUrl( const tr_rpc_server * server ); @@ -44,9 +41,9 @@ int tr_rpcSetTest( const tr_rpc_server * server, char ** allocme_errmsg ); void tr_rpcSetWhitelistEnabled( tr_rpc_server * server, - tr_bool isEnabled ); + bool isEnabled ); -tr_bool tr_rpcGetWhitelistEnabled( const tr_rpc_server * server ); +bool tr_rpcGetWhitelistEnabled( const tr_rpc_server * server ); void tr_rpcSetWhitelist( tr_rpc_server * server, const char * whitelist ); @@ -63,10 +60,9 @@ void tr_rpcSetUsername( tr_rpc_server * server, const char* tr_rpcGetUsername( const tr_rpc_server * server ); -void tr_rpcSetPasswordEnabled( tr_rpc_server * server, - tr_bool isEnabled ); +void tr_rpcSetPasswordEnabled( tr_rpc_server * server, bool isEnabled ); -tr_bool tr_rpcIsPasswordEnabled( const tr_rpc_server * session ); +bool tr_rpcIsPasswordEnabled( const tr_rpc_server * session ); const char* tr_rpcGetBindAddress( const tr_rpc_server * server ); diff --git a/libtransmission/rpcimpl.c b/libtransmission/rpcimpl.c index 006ef3efd..b6d67926c 100644 --- a/libtransmission/rpcimpl.c +++ b/libtransmission/rpcimpl.c @@ -228,7 +228,7 @@ torrentStop( tr_session * session, if( tor->isRunning ) { - tor->isStopping = TRUE; + tor->isStopping = true; notify( session, TR_RPC_TORRENT_STOPPED, tor ); } } @@ -245,7 +245,7 @@ torrentRemove( tr_session * session, int i; int torrentCount; tr_rpc_callback_type type; - tr_bool deleteFlag = FALSE; + bool deleteFlag = false; tr_torrent ** torrents = getTorrents( session, args_in, &torrentCount ); assert( idle_data == NULL ); @@ -768,17 +768,17 @@ setFileDLs( tr_torrent * tor, return errmsg; } -static tr_bool +static bool findAnnounceUrl( const tr_tracker_info * t, int n, const char * url, int * pos ) { int i; - tr_bool found = FALSE; + bool found = false; for( i=0; i<n; ++i ) { if( !strcmp( t[i].announce, url ) ) { - found = TRUE; + found = true; if( pos ) *pos = i; break; } @@ -822,7 +822,7 @@ addTrackerUrls( tr_torrent * tor, tr_benc * urls ) int tier; tr_benc * val; tr_tracker_info * trackers; - tr_bool changed = FALSE; + bool changed = false; const tr_info * inf = tr_torrentInfo( tor ); const char * errmsg = NULL; @@ -844,7 +844,7 @@ addTrackerUrls( tr_torrent * tor, tr_benc * urls ) trackers[n].tier = ++tier; /* add a new tier */ trackers[n].announce = tr_strdup( announce ); ++n; - changed = TRUE; + changed = true; } } @@ -863,7 +863,7 @@ replaceTrackers( tr_torrent * tor, tr_benc * urls ) int i; tr_benc * pair[2]; tr_tracker_info * trackers; - tr_bool changed = FALSE; + bool changed = false; const tr_info * inf = tr_torrentInfo( tor ); const int n = inf->trackerCount; const char * errmsg = NULL; @@ -888,7 +888,7 @@ replaceTrackers( tr_torrent * tor, tr_benc * urls ) { tr_free( trackers[pos].announce ); trackers[pos].announce = tr_strdup( newval ); - changed = TRUE; + changed = true; } i += 2; @@ -913,7 +913,7 @@ removeTrackers( tr_torrent * tor, tr_benc * ids ) int * tids; tr_benc * val; tr_tracker_info * trackers; - tr_bool changed = FALSE; + bool changed = false; const tr_info * inf = tr_torrentInfo( tor ); const char * errmsg = NULL; @@ -944,7 +944,7 @@ removeTrackers( tr_torrent * tor, tr_benc * ids ) continue; tr_removeElementFromArray( trackers, tids[t], sizeof( tr_tracker_info ), n-- ); dup = tids[t]; - changed = TRUE; + changed = true; } if( !changed ) @@ -975,16 +975,16 @@ torrentSet( tr_session * session, double d; tr_benc * files; tr_benc * trackers; - tr_bool boolVal; + bool boolVal; tr_torrent * tor = torrents[i]; if( tr_bencDictFindInt( args_in, "bandwidthPriority", &tmp ) ) if( tr_isPriority( tmp ) ) tr_torrentSetPriority( tor, tmp ); if( !errmsg && tr_bencDictFindList( args_in, "files-unwanted", &files ) ) - errmsg = setFileDLs( tor, FALSE, files ); + errmsg = setFileDLs( tor, false, files ); if( !errmsg && tr_bencDictFindList( args_in, "files-wanted", &files ) ) - errmsg = setFileDLs( tor, TRUE, files ); + errmsg = setFileDLs( tor, true, files ); if( tr_bencDictFindInt( args_in, "peer-limit", &tmp ) ) tr_torrentSetPeerLimit( tor, tmp ); if( !errmsg && tr_bencDictFindList( args_in, "priority-high", &files ) ) @@ -1041,7 +1041,7 @@ torrentSetLocation( tr_session * session, } else { - tr_bool move = FALSE; + bool move = false; int i, torrentCount; tr_torrent ** torrents = getTorrents( session, args_in, &torrentCount ); @@ -1066,8 +1066,8 @@ torrentSetLocation( tr_session * session, static void portTested( tr_session * session UNUSED, - tr_bool did_connect UNUSED, - tr_bool did_timeout UNUSED, + bool did_connect UNUSED, + bool did_timeout UNUSED, long response_code, const void * response, size_t response_byte_count, @@ -1083,7 +1083,7 @@ portTested( tr_session * session UNUSED, } else /* success */ { - const tr_bool isOpen = response_byte_count && *(char*)response == '1'; + const bool isOpen = response_byte_count && *(char*)response == '1'; tr_bencDictAddBool( data->args_out, "port-is-open", isOpen ); tr_snprintf( result, sizeof( result ), "success" ); } @@ -1110,8 +1110,8 @@ portTest( tr_session * session, static void gotNewBlocklist( tr_session * session, - tr_bool did_connect UNUSED, - tr_bool did_timeout UNUSED, + bool did_connect UNUSED, + bool did_timeout UNUSED, long response_code, const void * response, size_t response_byte_count, @@ -1254,8 +1254,8 @@ struct add_torrent_idle_data static void gotMetadataFromURL( tr_session * session UNUSED, - tr_bool did_connect UNUSED, - tr_bool did_timeout UNUSED, + bool did_connect UNUSED, + bool did_timeout UNUSED, long response_code, const void * response, size_t response_byte_count, @@ -1282,11 +1282,11 @@ gotMetadataFromURL( tr_session * session UNUSED, tr_free( data ); } -static tr_bool +static bool isCurlURL( const char * filename ) { if( filename == NULL ) - return FALSE; + return false; return !strncmp( filename, "ftp://", 6 ) || !strncmp( filename, "http://", 7 ) || @@ -1329,7 +1329,7 @@ torrentAdd( tr_session * session, else { int64_t i; - tr_bool boolVal; + bool boolVal; tr_benc * l; const char * str; const char * cookies = NULL; @@ -1354,13 +1354,13 @@ torrentAdd( tr_session * session, if( tr_bencDictFindList( args_in, "files-unwanted", &l ) ) { tr_file_index_t fileCount; tr_file_index_t * files = fileListFromList( l, &fileCount ); - tr_ctorSetFilesWanted( ctor, files, fileCount, FALSE ); + tr_ctorSetFilesWanted( ctor, files, fileCount, false ); tr_free( files ); } if( tr_bencDictFindList( args_in, "files-wanted", &l ) ) { tr_file_index_t fileCount; tr_file_index_t * files = fileListFromList( l, &fileCount ); - tr_ctorSetFilesWanted( ctor, files, fileCount, TRUE ); + tr_ctorSetFilesWanted( ctor, files, fileCount, true ); tr_free( files ); } @@ -1434,7 +1434,7 @@ sessionSet( tr_session * session, { int64_t i; double d; - tr_bool boolVal; + bool boolVal; const char * str; assert( idle_data == NULL ); @@ -1655,26 +1655,26 @@ typedef const char* ( *handler )( tr_session*, tr_benc*, tr_benc*, struct tr_rpc static struct method { const char * name; - tr_bool immediate; + bool immediate; handler func; } methods[] = { - { "port-test", FALSE, portTest }, - { "blocklist-update", FALSE, blocklistUpdate }, - { "session-close", TRUE, sessionClose }, - { "session-get", TRUE, sessionGet }, - { "session-set", TRUE, sessionSet }, - { "session-stats", TRUE, sessionStats }, - { "torrent-add", FALSE, torrentAdd }, - { "torrent-get", TRUE, torrentGet }, - { "torrent-remove", TRUE, torrentRemove }, - { "torrent-set", TRUE, torrentSet }, - { "torrent-set-location", TRUE, torrentSetLocation }, - { "torrent-start", TRUE, torrentStart }, - { "torrent-stop", TRUE, torrentStop }, - { "torrent-verify", TRUE, torrentVerify }, - { "torrent-reannounce", TRUE, torrentReannounce } + { "port-test", false, portTest }, + { "blocklist-update", false, blocklistUpdate }, + { "session-close", true, sessionClose }, + { "session-get", true, sessionGet }, + { "session-set", true, sessionSet }, + { "session-stats", true, sessionStats }, + { "torrent-add", false, torrentAdd }, + { "torrent-get", true, torrentGet }, + { "torrent-remove", true, torrentRemove }, + { "torrent-set", true, torrentSet }, + { "torrent-set-location", true, torrentSetLocation }, + { "torrent-start", true, torrentStart }, + { "torrent-stop", true, torrentStop }, + { "torrent-verify", true, torrentVerify }, + { "torrent-reannounce", true, torrentReannounce } }; static void diff --git a/libtransmission/session.c b/libtransmission/session.c index fb694c559..bf77d2ebd 100644 --- a/libtransmission/session.c +++ b/libtransmission/session.c @@ -58,10 +58,10 @@ enum { #ifdef TR_LIGHTWEIGHT DEFAULT_CACHE_SIZE_MB = 2, - DEFAULT_PREFETCH_ENABLED = FALSE, + DEFAULT_PREFETCH_ENABLED = false, #else DEFAULT_CACHE_SIZE_MB = 4, - DEFAULT_PREFETCH_ENABLED = TRUE, + DEFAULT_PREFETCH_ENABLED = true, #endif SAVE_INTERVAL_SECS = 360 }; @@ -196,7 +196,7 @@ open_incoming_peer_port( tr_session * session ) /* bind an ipv4 port to listen for incoming peers... */ b = session->public_ipv4; - b->socket = tr_netBindTCP( &b->addr, session->private_peer_port, FALSE ); + b->socket = tr_netBindTCP( &b->addr, session->private_peer_port, false ); if( b->socket >= 0 ) { b->ev = event_new( session->event_base, b->socket, EV_READ | EV_PERSIST, accept_incoming_peer, session ); event_add( b->ev, NULL ); @@ -205,7 +205,7 @@ open_incoming_peer_port( tr_session * session ) /* and do the exact same thing for ipv6, if it's supported... */ if( tr_net_hasIPv6( session->private_peer_port ) ) { b = session->public_ipv6; - b->socket = tr_netBindTCP( &b->addr, session->private_peer_port, FALSE ); + b->socket = tr_netBindTCP( &b->addr, session->private_peer_port, false ); if( b->socket >= 0 ) { b->ev = event_new( session->event_base, b->socket, EV_READ | EV_PERSIST, accept_incoming_peer, session ); event_add( b->ev, NULL ); @@ -214,7 +214,7 @@ open_incoming_peer_port( tr_session * session ) } const tr_address* -tr_sessionGetPublicAddress( const tr_session * session, int tr_af_type, tr_bool * is_default_value ) +tr_sessionGetPublicAddress( const tr_session * session, int tr_af_type, bool * is_default_value ) { const char * default_value; const struct tr_bindinfo * bindinfo; @@ -305,62 +305,62 @@ tr_sessionGetDefaultSettings( tr_benc * d ) assert( tr_bencIsDict( d ) ); tr_bencDictReserve( d, 60 ); - tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, FALSE ); + tr_bencDictAddBool( d, TR_PREFS_KEY_BLOCKLIST_ENABLED, false ); tr_bencDictAddStr ( d, TR_PREFS_KEY_BLOCKLIST_URL, "http://www.example.com/blocklist" ); tr_bencDictAddInt ( d, TR_PREFS_KEY_MAX_CACHE_SIZE_MB, DEFAULT_CACHE_SIZE_MB ); - tr_bencDictAddBool( d, TR_PREFS_KEY_DHT_ENABLED, TRUE ); - tr_bencDictAddBool( d, TR_PREFS_KEY_UTP_ENABLED, TRUE ); - tr_bencDictAddBool( d, TR_PREFS_KEY_LPD_ENABLED, FALSE ); + tr_bencDictAddBool( d, TR_PREFS_KEY_DHT_ENABLED, true ); + tr_bencDictAddBool( d, TR_PREFS_KEY_UTP_ENABLED, true ); + tr_bencDictAddBool( d, TR_PREFS_KEY_LPD_ENABLED, false ); tr_bencDictAddStr ( d, TR_PREFS_KEY_DOWNLOAD_DIR, tr_getDefaultDownloadDir( ) ); tr_bencDictAddInt ( d, TR_PREFS_KEY_DSPEED_KBps, 100 ); - tr_bencDictAddBool( d, TR_PREFS_KEY_DSPEED_ENABLED, FALSE ); + tr_bencDictAddBool( d, TR_PREFS_KEY_DSPEED_ENABLED, false ); tr_bencDictAddInt ( d, TR_PREFS_KEY_ENCRYPTION, TR_DEFAULT_ENCRYPTION ); tr_bencDictAddInt ( d, TR_PREFS_KEY_IDLE_LIMIT, 30 ); - tr_bencDictAddBool( d, TR_PREFS_KEY_IDLE_LIMIT_ENABLED, FALSE ); + tr_bencDictAddBool( d, TR_PREFS_KEY_IDLE_LIMIT_ENABLED, false ); tr_bencDictAddStr ( d, TR_PREFS_KEY_INCOMPLETE_DIR, tr_getDefaultDownloadDir( ) ); - tr_bencDictAddBool( d, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, FALSE ); + tr_bencDictAddBool( d, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, false ); tr_bencDictAddInt ( d, TR_PREFS_KEY_MSGLEVEL, TR_MSG_INF ); tr_bencDictAddInt ( d, TR_PREFS_KEY_OPEN_FILE_LIMIT, atoi( TR_DEFAULT_OPEN_FILE_LIMIT_STR ) ); tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_LIMIT_GLOBAL, atoi( TR_DEFAULT_PEER_LIMIT_GLOBAL_STR ) ); tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_LIMIT_TORRENT, atoi( TR_DEFAULT_PEER_LIMIT_TORRENT_STR ) ); tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_PORT, atoi( TR_DEFAULT_PEER_PORT_STR ) ); - tr_bencDictAddBool( d, TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START, FALSE ); + tr_bencDictAddBool( d, TR_PREFS_KEY_PEER_PORT_RANDOM_ON_START, false ); tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_PORT_RANDOM_LOW, 49152 ); tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_PORT_RANDOM_HIGH, 65535 ); tr_bencDictAddStr ( d, TR_PREFS_KEY_PEER_SOCKET_TOS, TR_DEFAULT_PEER_SOCKET_TOS_STR ); - tr_bencDictAddBool( d, TR_PREFS_KEY_PEX_ENABLED, TRUE ); - tr_bencDictAddBool( d, TR_PREFS_KEY_PORT_FORWARDING, TRUE ); + tr_bencDictAddBool( d, TR_PREFS_KEY_PEX_ENABLED, true ); + tr_bencDictAddBool( d, TR_PREFS_KEY_PORT_FORWARDING, true ); tr_bencDictAddInt ( d, TR_PREFS_KEY_PREALLOCATION, TR_PREALLOCATE_SPARSE ); tr_bencDictAddBool( d, TR_PREFS_KEY_PREFETCH_ENABLED, DEFAULT_PREFETCH_ENABLED ); tr_bencDictAddReal( d, TR_PREFS_KEY_RATIO, 2.0 ); - tr_bencDictAddBool( d, TR_PREFS_KEY_RATIO_ENABLED, FALSE ); - tr_bencDictAddBool( d, TR_PREFS_KEY_RENAME_PARTIAL_FILES, TRUE ); - tr_bencDictAddBool( d, TR_PREFS_KEY_RPC_AUTH_REQUIRED, FALSE ); + tr_bencDictAddBool( d, TR_PREFS_KEY_RATIO_ENABLED, false ); + tr_bencDictAddBool( d, TR_PREFS_KEY_RENAME_PARTIAL_FILES, true ); + tr_bencDictAddBool( d, TR_PREFS_KEY_RPC_AUTH_REQUIRED, false ); tr_bencDictAddStr ( d, TR_PREFS_KEY_RPC_BIND_ADDRESS, "0.0.0.0" ); - tr_bencDictAddBool( d, TR_PREFS_KEY_RPC_ENABLED, FALSE ); + tr_bencDictAddBool( d, TR_PREFS_KEY_RPC_ENABLED, false ); tr_bencDictAddStr ( d, TR_PREFS_KEY_RPC_PASSWORD, "" ); tr_bencDictAddStr ( d, TR_PREFS_KEY_RPC_USERNAME, "" ); tr_bencDictAddStr ( d, TR_PREFS_KEY_RPC_WHITELIST, TR_DEFAULT_RPC_WHITELIST ); - tr_bencDictAddBool( d, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, TRUE ); + tr_bencDictAddBool( d, TR_PREFS_KEY_RPC_WHITELIST_ENABLED, true ); tr_bencDictAddInt ( d, TR_PREFS_KEY_RPC_PORT, atoi( TR_DEFAULT_RPC_PORT_STR ) ); tr_bencDictAddStr ( d, TR_PREFS_KEY_RPC_URL, TR_DEFAULT_RPC_URL_STR ); tr_bencDictAddStr ( d, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_FILENAME, "" ); - tr_bencDictAddBool( d, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, FALSE ); - tr_bencDictAddBool( d, TR_PREFS_KEY_ALT_SPEED_ENABLED, FALSE ); + tr_bencDictAddBool( d, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_ENABLED, false ); + tr_bencDictAddBool( d, TR_PREFS_KEY_ALT_SPEED_ENABLED, false ); tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_UP_KBps, 50 ); /* half the regular */ tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_DOWN_KBps, 50 ); /* half the regular */ tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_BEGIN, 540 ); /* 9am */ - tr_bencDictAddBool( d, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, FALSE ); + tr_bencDictAddBool( d, TR_PREFS_KEY_ALT_SPEED_TIME_ENABLED, false ); tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_END, 1020 ); /* 5pm */ tr_bencDictAddInt ( d, TR_PREFS_KEY_ALT_SPEED_TIME_DAY, TR_SCHED_ALL ); tr_bencDictAddInt ( d, TR_PREFS_KEY_USPEED_KBps, 100 ); - tr_bencDictAddBool( d, TR_PREFS_KEY_USPEED_ENABLED, FALSE ); + tr_bencDictAddBool( d, TR_PREFS_KEY_USPEED_ENABLED, false ); tr_bencDictAddInt ( d, TR_PREFS_KEY_UMASK, 022 ); tr_bencDictAddInt ( d, TR_PREFS_KEY_UPLOAD_SLOTS_PER_TORRENT, 14 ); tr_bencDictAddStr ( d, TR_PREFS_KEY_BIND_ADDRESS_IPV4, TR_DEFAULT_BIND_ADDRESS_IPV4 ); tr_bencDictAddStr ( d, TR_PREFS_KEY_BIND_ADDRESS_IPV6, TR_DEFAULT_BIND_ADDRESS_IPV6 ); - tr_bencDictAddBool( d, TR_PREFS_KEY_START, TRUE ); - tr_bencDictAddBool( d, TR_PREFS_KEY_TRASH_ORIGINAL, FALSE ); + tr_bencDictAddBool( d, TR_PREFS_KEY_START, true ); + tr_bencDictAddBool( d, TR_PREFS_KEY_TRASH_ORIGINAL, false ); } void @@ -428,7 +428,7 @@ tr_sessionGetSettings( tr_session * s, struct tr_benc * d ) tr_bencDictAddBool( d, TR_PREFS_KEY_TRASH_ORIGINAL, tr_sessionGetDeleteSource( s ) ); } -tr_bool +bool tr_sessionLoadSettings( tr_benc * d, const char * configDir, const char * appName ) { int err = 0; @@ -436,7 +436,7 @@ tr_sessionLoadSettings( tr_benc * d, const char * configDir, const char * appNam tr_benc fileSettings; tr_benc sessionDefaults; tr_benc tmp; - tr_bool success = FALSE; + bool success = false; assert( tr_bencIsDict( d ) ); @@ -545,15 +545,15 @@ struct init_data { tr_session * session; const char * configDir; - tr_bool done; - tr_bool messageQueuingEnabled; + bool done; + bool messageQueuingEnabled; tr_benc * clientSettings; }; tr_session * tr_sessionInit( const char * tag, const char * configDir, - tr_bool messageQueuingEnabled, + bool messageQueuingEnabled, tr_benc * clientSettings ) { int64_t i; @@ -587,7 +587,7 @@ tr_sessionInit( const char * tag, assert( session->events != NULL ); /* run the rest in the libtransmission thread */ - data.done = FALSE; + data.done = false; data.session = session; data.configDir = configDir; data.messageQueuingEnabled = messageQueuingEnabled; @@ -720,7 +720,7 @@ tr_sessionInitImpl( void * vdata ) /* cleanup */ tr_bencFree( &settings ); - data->done = TRUE; + data->done = true; } static void turtleBootstrap( tr_session *, struct tr_turtle_info * ); @@ -731,7 +731,7 @@ sessionSetImpl( void * vdata ) { int64_t i; double d; - tr_bool boolVal; + bool boolVal; const char * str; struct tr_bindinfo b; struct init_data * data = vdata; @@ -893,14 +893,14 @@ sessionSetImpl( void * vdata ) if( tr_bencDictFindStr( settings, TR_PREFS_KEY_SCRIPT_TORRENT_DONE_FILENAME, &str ) ) tr_sessionSetTorrentDoneScript( session, str ); - data->done = TRUE; + data->done = true; } void tr_sessionSet( tr_session * session, struct tr_benc * settings ) { struct init_data data; - data.done = FALSE; + data.done = false; data.session = session; data.clientSettings = settings; @@ -947,7 +947,7 @@ tr_sessionGetDownloadDirFreeSpace( const tr_session * session ) ***/ void -tr_sessionSetIncompleteFileNamingEnabled( tr_session * session, tr_bool b ) +tr_sessionSetIncompleteFileNamingEnabled( tr_session * session, bool b ) { assert( tr_isSession( session ) ); assert( tr_isBool( b ) ); @@ -955,7 +955,7 @@ tr_sessionSetIncompleteFileNamingEnabled( tr_session * session, tr_bool b ) session->isIncompleteFileNamingEnabled = b; } -tr_bool +bool tr_sessionIsIncompleteFileNamingEnabled( const tr_session * session ) { assert( tr_isSession( session ) ); @@ -990,7 +990,7 @@ tr_sessionGetIncompleteDir( const tr_session * session ) } void -tr_sessionSetIncompleteDirEnabled( tr_session * session, tr_bool b ) +tr_sessionSetIncompleteDirEnabled( tr_session * session, bool b ) { assert( tr_isSession( session ) ); assert( tr_isBool( b ) ); @@ -998,7 +998,7 @@ tr_sessionSetIncompleteDirEnabled( tr_session * session, tr_bool b ) session->isIncompleteDirEnabled = b; } -tr_bool +bool tr_sessionIsIncompleteDirEnabled( const tr_session * session ) { assert( tr_isSession( session ) ); @@ -1017,7 +1017,7 @@ tr_sessionGetBuffer( tr_session * session ) assert( !session->bufferInUse ); assert( tr_amInEventThread( session ) ); - session->bufferInUse = TRUE; + session->bufferInUse = true; return session->buffer; } @@ -1028,7 +1028,7 @@ tr_sessionReleaseBuffer( tr_session * session ) assert( session->bufferInUse ); assert( tr_amInEventThread( session ) ); - session->bufferInUse = FALSE; + session->bufferInUse = false; } void @@ -1047,7 +1047,7 @@ tr_sessionUnlock( tr_session * session ) tr_lockUnlock( session->lock ); } -tr_bool +bool tr_sessionIsLocked( const tr_session * session ) { return tr_isSession( session ) && tr_lockHave( session->lock ); @@ -1109,14 +1109,14 @@ tr_sessionSetPeerPortRandom( tr_session * session ) void tr_sessionSetPeerPortRandomOnStart( tr_session * session, - tr_bool random ) + bool random ) { assert( tr_isSession( session ) ); session->isPortRandom = random; } -tr_bool +bool tr_sessionGetPeerPortRandomOnStart( tr_session * session ) { assert( tr_isSession( session ) ); @@ -1137,7 +1137,7 @@ tr_sessionGetPortForwarding( const tr_session * session ) ***/ void -tr_sessionSetRatioLimited( tr_session * session, tr_bool isLimited ) +tr_sessionSetRatioLimited( tr_session * session, bool isLimited ) { assert( tr_isSession( session ) ); @@ -1152,7 +1152,7 @@ tr_sessionSetRatioLimit( tr_session * session, double desiredRatio ) session->desiredRatio = desiredRatio; } -tr_bool +bool tr_sessionIsRatioLimited( const tr_session * session ) { assert( tr_isSession( session ) ); @@ -1173,7 +1173,7 @@ tr_sessionGetRatioLimit( const tr_session * session ) ***/ void -tr_sessionSetIdleLimited( tr_session * session, tr_bool isLimited ) +tr_sessionSetIdleLimited( tr_session * session, bool isLimited ) { assert( tr_isSession( session ) ); @@ -1188,7 +1188,7 @@ tr_sessionSetIdleLimit( tr_session * session, uint16_t idleMinutes ) session->idleLimitMinutes = idleMinutes; } -tr_bool +bool tr_sessionIsIdleLimited( const tr_session * session ) { assert( tr_isSession( session ) ); @@ -1210,30 +1210,30 @@ tr_sessionGetIdleLimit( const tr_session * session ) **** ***/ -tr_bool +bool tr_sessionGetActiveSpeedLimit_Bps( const tr_session * session, tr_direction dir, int * setme_Bps ) { - int isLimited = TRUE; + int isLimited = true; if( !tr_isSession( session ) ) - return FALSE; + return false; if( tr_sessionUsesAltSpeed( session ) ) *setme_Bps = tr_sessionGetAltSpeed_Bps( session, dir ); else if( tr_sessionIsSpeedLimited( session, dir ) ) *setme_Bps = tr_sessionGetSpeedLimit_Bps( session, dir ); else - isLimited = FALSE; + isLimited = false; return isLimited; } -tr_bool +bool tr_sessionGetActiveSpeedLimit_KBps( const tr_session * session, tr_direction dir, double * setme_KBps ) { int Bps = 0; - const tr_bool is_active = tr_sessionGetActiveSpeedLimit_Bps( session, dir, &Bps ); + const bool is_active = tr_sessionGetActiveSpeedLimit_Bps( session, dir, &Bps ); *setme_KBps = toSpeedKBps( Bps ); return is_active; } @@ -1242,8 +1242,8 @@ static void updateBandwidth( tr_session * session, tr_direction dir ) { int limit_Bps = 0; - const tr_bool isLimited = tr_sessionGetActiveSpeedLimit_Bps( session, dir, &limit_Bps ); - const tr_bool zeroCase = isLimited && !limit_Bps; + const bool isLimited = tr_sessionGetActiveSpeedLimit_Bps( session, dir, &limit_Bps ); + const bool zeroCase = isLimited && !limit_Bps; tr_bandwidthSetLimited( session->bandwidth, dir, isLimited && !zeroCase ); @@ -1299,7 +1299,7 @@ altSpeedToggled( void * vsession ) static void useAltSpeed( tr_session * s, struct tr_turtle_info * t, - tr_bool enabled, tr_bool byUser ) + bool enabled, bool byUser ) { assert( tr_isSession( s ) ); assert( t != NULL ); @@ -1320,10 +1320,10 @@ useAltSpeed( tr_session * s, struct tr_turtle_info * t, */ static void testTurtleTime( const struct tr_turtle_info * t, - tr_bool * enabled, - tr_bool * changed ) + bool * enabled, + bool * changed ) { - tr_bool e; + bool e; struct tm tm; size_t minute_of_the_week; const time_t now = tr_time( ); @@ -1351,8 +1351,8 @@ testTurtleTime( const struct tr_turtle_info * t, static void turtleCheckClock( tr_session * s, struct tr_turtle_info * t ) { - tr_bool enabled; - tr_bool changed; + bool enabled; + bool changed; assert( t->isClockEnabled ); @@ -1361,7 +1361,7 @@ turtleCheckClock( tr_session * s, struct tr_turtle_info * t ) if( changed ) { tr_inf( "Time to turn %s turtle mode!", (enabled?"on":"off") ); - useAltSpeed( s, t, enabled, FALSE ); + useAltSpeed( s, t, enabled, false ); } } @@ -1371,7 +1371,7 @@ turtleCheckClock( tr_session * s, struct tr_turtle_info * t ) static void turtleBootstrap( tr_session * session, struct tr_turtle_info * turtle ) { - turtle->changedByUser = FALSE; + turtle->changedByUser = false; tr_bitfieldConstruct( &turtle->minutes, MINUTES_PER_WEEK ); @@ -1419,7 +1419,7 @@ tr_sessionGetSpeedLimit_KBps( const tr_session * s, tr_direction d ) } void -tr_sessionLimitSpeed( tr_session * s, tr_direction d, tr_bool b ) +tr_sessionLimitSpeed( tr_session * s, tr_direction d, bool b ) { assert( tr_isSession( s ) ); assert( tr_isDirection( d ) ); @@ -1430,7 +1430,7 @@ tr_sessionLimitSpeed( tr_session * s, tr_direction d, tr_bool b ) updateBandwidth( s, d ); } -tr_bool +bool tr_sessionIsSpeedLimited( const tr_session * s, tr_direction d ) { assert( tr_isSession( s ) ); @@ -1484,14 +1484,14 @@ userPokedTheClock( tr_session * s, struct tr_turtle_info * t ) if( t->isClockEnabled ) { - tr_bool enabled, changed; + bool enabled, changed; testTurtleTime( t, &enabled, &changed ); - useAltSpeed( s, t, enabled, TRUE ); + useAltSpeed( s, t, enabled, true ); } } void -tr_sessionUseAltSpeedTime( tr_session * s, tr_bool b ) +tr_sessionUseAltSpeedTime( tr_session * s, bool b ) { struct tr_turtle_info * t = &s->turtle; @@ -1504,7 +1504,7 @@ tr_sessionUseAltSpeedTime( tr_session * s, tr_bool b ) } } -tr_bool +bool tr_sessionUsesAltSpeedTime( const tr_session * s ) { assert( tr_isSession( s ) ); @@ -1572,12 +1572,12 @@ tr_sessionGetAltSpeedDay( const tr_session * s ) } void -tr_sessionUseAltSpeed( tr_session * session, tr_bool enabled ) +tr_sessionUseAltSpeed( tr_session * session, bool enabled ) { - useAltSpeed( session, &session->turtle, enabled, TRUE ); + useAltSpeed( session, &session->turtle, enabled, true ); } -tr_bool +bool tr_sessionUsesAltSpeed( const tr_session * s ) { assert( tr_isSession( s ) ); @@ -1643,14 +1643,14 @@ tr_sessionGetPeerLimitPerTorrent( const tr_session * session ) ***/ void -tr_sessionSetPaused( tr_session * session, tr_bool isPaused ) +tr_sessionSetPaused( tr_session * session, bool isPaused ) { assert( tr_isSession( session ) ); session->pauseAddedTorrent = isPaused; } -tr_bool +bool tr_sessionGetPaused( const tr_session * session ) { assert( tr_isSession( session ) ); @@ -1659,14 +1659,14 @@ tr_sessionGetPaused( const tr_session * session ) } void -tr_sessionSetDeleteSource( tr_session * session, tr_bool deleteSource ) +tr_sessionSetDeleteSource( tr_session * session, bool deleteSource ) { assert( tr_isSession( session ) ); session->deleteSourceTorrent = deleteSource; } -tr_bool +bool tr_sessionGetDeleteSource( const tr_session * session ) { assert( tr_isSession( session ) ); @@ -1791,7 +1791,7 @@ sessionCloseImpl( void * vsession ) tr_fdClose( session ); - session->isClosed = TRUE; + session->isClosed = true; } static int @@ -1837,13 +1837,13 @@ tr_sessionClose( tr_session * session ) tr_eventClose( session ); while( session->events != NULL ) { - static tr_bool forced = FALSE; + static bool forced = false; dbgmsg( "waiting for libtransmission thread to finish... now %zu deadline %zu", (size_t)time(NULL), (size_t)deadline ); tr_wait_msec( 500 ); if( deadlineReached( deadline ) && !forced ) { dbgmsg( "calling event_loopbreak()" ); - forced = TRUE; + forced = true; event_base_loopbreak( session->event_base ); } if( deadlineReached( deadline+3 ) ) @@ -1889,7 +1889,7 @@ tr_sessionLoadTorrents( tr_session * session, assert( tr_isSession( session ) ); - tr_ctorSetSave( ctor, FALSE ); /* since we already have them */ + tr_ctorSetSave( ctor, false ); /* since we already have them */ if( !stat( dirname, &sb ) && S_ISDIR( sb.st_mode ) @@ -1934,15 +1934,14 @@ tr_sessionLoadTorrents( tr_session * session, ***/ void -tr_sessionSetPexEnabled( tr_session * session, - tr_bool enabled ) +tr_sessionSetPexEnabled( tr_session * session, bool enabled ) { assert( tr_isSession( session ) ); session->isPexEnabled = enabled != 0; } -tr_bool +bool tr_sessionIsPexEnabled( const tr_session * session ) { assert( tr_isSession( session ) ); @@ -1950,13 +1949,13 @@ tr_sessionIsPexEnabled( const tr_session * session ) return session->isPexEnabled; } -tr_bool +bool tr_sessionAllowsDHT( const tr_session * session UNUSED ) { return tr_sessionIsDHTEnabled( session ); } -tr_bool +bool tr_sessionIsDHTEnabled( const tr_session * session ) { assert( tr_isSession( session ) ); @@ -1976,7 +1975,7 @@ toggleDHTImpl( void * data ) } void -tr_sessionSetDHTEnabled( tr_session * session, tr_bool enabled ) +tr_sessionSetDHTEnabled( tr_session * session, bool enabled ) { assert( tr_isSession( session ) ); assert( tr_isBool( enabled ) ); @@ -1989,7 +1988,7 @@ tr_sessionSetDHTEnabled( tr_session * session, tr_bool enabled ) **** ***/ -tr_bool +bool tr_sessionIsUTPEnabled( const tr_session * session ) { assert( tr_isSession( session ) ); @@ -1997,7 +1996,7 @@ tr_sessionIsUTPEnabled( const tr_session * session ) #ifdef WITH_UTP return session->isUTPEnabled; #else - return FALSE; + return false; #endif } @@ -2016,7 +2015,7 @@ toggle_utp( void * data ) } void -tr_sessionSetUTPEnabled( tr_session * session, tr_bool enabled ) +tr_sessionSetUTPEnabled( tr_session * session, bool enabled ) { assert( tr_isSession( session ) ); assert( tr_isBool( enabled ) ); @@ -2045,7 +2044,7 @@ toggleLPDImpl( void * data ) } void -tr_sessionSetLPDEnabled( tr_session * session, tr_bool enabled ) +tr_sessionSetLPDEnabled( tr_session * session, bool enabled ) { assert( tr_isSession( session ) ); assert( tr_isBool( enabled ) ); @@ -2054,7 +2053,7 @@ tr_sessionSetLPDEnabled( tr_session * session, tr_bool enabled ) tr_runInEventThread( session, toggleLPDImpl, session ); } -tr_bool +bool tr_sessionIsLPDEnabled( const tr_session * session ) { assert( tr_isSession( session ) ); @@ -2062,7 +2061,7 @@ tr_sessionIsLPDEnabled( const tr_session * session ) return session->isLPDEnabled; } -tr_bool +bool tr_sessionAllowsLPD( const tr_session * session ) { return tr_sessionIsLPDEnabled( session ); @@ -2094,7 +2093,7 @@ tr_sessionGetCacheLimit_MB( const tr_session * session ) struct port_forwarding_data { - tr_bool enabled; + bool enabled; struct tr_shared * shared; }; @@ -2107,7 +2106,7 @@ setPortForwardingEnabled( void * vdata ) } void -tr_sessionSetPortForwardingEnabled( tr_session * session, tr_bool enabled ) +tr_sessionSetPortForwardingEnabled( tr_session * session, bool enabled ) { struct port_forwarding_data * d; d = tr_new0( struct port_forwarding_data, 1 ); @@ -2116,7 +2115,7 @@ tr_sessionSetPortForwardingEnabled( tr_session * session, tr_bool enabled ) tr_runInEventThread( session, setPortForwardingEnabled, d ); } -tr_bool +bool tr_sessionIsPortForwardingEnabled( const tr_session * session ) { assert( tr_isSession( session ) ); @@ -2146,7 +2145,7 @@ loadBlocklists( tr_session * session ) char * dirname; DIR * odir = NULL; tr_list * list = NULL; - const tr_bool isEnabled = session->isBlocklistEnabled; + const bool isEnabled = session->isBlocklistEnabled; /* walk through the directory and find blocklists */ dirname = tr_buildPath( session->configDir, "blocklists", NULL ); @@ -2239,7 +2238,7 @@ tr_blocklistGetRuleCount( const tr_session * session ) return n; } -tr_bool +bool tr_blocklistIsEnabled( const tr_session * session ) { assert( tr_isSession( session ) ); @@ -2248,8 +2247,7 @@ tr_blocklistIsEnabled( const tr_session * session ) } void -tr_blocklistSetEnabled( tr_session * session, - tr_bool isEnabled ) +tr_blocklistSetEnabled( tr_session * session, bool isEnabled ) { tr_list * l; @@ -2261,7 +2259,7 @@ tr_blocklistSetEnabled( tr_session * session, _tr_blocklistSetEnabled( l->data, isEnabled ); } -tr_bool +bool tr_blocklistExists( const tr_session * session ) { assert( tr_isSession( session ) ); @@ -2296,7 +2294,7 @@ tr_blocklistSetContent( tr_session * session, const char * contentFilename ) return ruleCount; } -tr_bool +bool tr_sessionIsAddressBlocked( const tr_session * session, const tr_address * addr ) { @@ -2306,8 +2304,8 @@ tr_sessionIsAddressBlocked( const tr_session * session, for( l = session->blocklists; l; l = l->next ) if( _tr_blocklistHasAddress( l->data, addr ) ) - return TRUE; - return FALSE; + return true; + return false; } void @@ -2347,7 +2345,7 @@ metainfoLookupInit( tr_session * session ) lookup = tr_new0( tr_benc, 1 ); tr_bencInitDict( lookup, 0 ); ctor = tr_ctorNew( session ); - tr_ctorSetSave( ctor, FALSE ); /* since we already have them */ + tr_ctorSetSave( ctor, false ); /* since we already have them */ if( !stat( dirname, &sb ) && S_ISDIR( sb.st_mode ) && ( ( odir = opendir( dirname ) ) ) ) { struct dirent *d; @@ -2403,15 +2401,14 @@ tr_sessionSetTorrentFile( tr_session * session, ***/ void -tr_sessionSetRPCEnabled( tr_session * session, - tr_bool isEnabled ) +tr_sessionSetRPCEnabled( tr_session * session, bool isEnabled ) { assert( tr_isSession( session ) ); tr_rpcSetEnabled( session->rpcServer, isEnabled ); } -tr_bool +bool tr_sessionIsRPCEnabled( const tr_session * session ) { assert( tr_isSession( session ) ); @@ -2482,15 +2479,14 @@ tr_sessionGetRPCWhitelist( const tr_session * session ) } void -tr_sessionSetRPCWhitelistEnabled( tr_session * session, - tr_bool isEnabled ) +tr_sessionSetRPCWhitelistEnabled( tr_session * session, bool isEnabled ) { assert( tr_isSession( session ) ); tr_rpcSetWhitelistEnabled( session->rpcServer, isEnabled ); } -tr_bool +bool tr_sessionGetRPCWhitelistEnabled( const tr_session * session ) { assert( tr_isSession( session ) ); @@ -2534,15 +2530,14 @@ tr_sessionGetRPCUsername( const tr_session * session ) } void -tr_sessionSetRPCPasswordEnabled( tr_session * session, - tr_bool isEnabled ) +tr_sessionSetRPCPasswordEnabled( tr_session * session, bool isEnabled ) { assert( tr_isSession( session ) ); tr_rpcSetPasswordEnabled( session->rpcServer, isEnabled ); } -tr_bool +bool tr_sessionIsRPCPasswordEnabled( const tr_session * session ) { assert( tr_isSession( session ) ); @@ -2562,7 +2557,7 @@ tr_sessionGetRPCBindAddress( const tr_session * session ) ***** ****/ -tr_bool +bool tr_sessionIsTorrentDoneScriptEnabled( const tr_session * session ) { assert( tr_isSession( session ) ); @@ -2571,7 +2566,7 @@ tr_sessionIsTorrentDoneScriptEnabled( const tr_session * session ) } void -tr_sessionSetTorrentDoneScriptEnabled( tr_session * session, tr_bool isEnabled ) +tr_sessionSetTorrentDoneScriptEnabled( tr_session * session, bool isEnabled ) { assert( tr_isSession( session ) ); assert( tr_isBool( isEnabled ) ); diff --git a/libtransmission/session.h b/libtransmission/session.h index fee71793a..377f215c1 100644 --- a/libtransmission/session.h +++ b/libtransmission/session.h @@ -59,10 +59,10 @@ struct tr_turtle_info int speedLimit_Bps[2]; /* is turtle mode on right now? */ - tr_bool isEnabled; + bool isEnabled; /* does turtle mode turn itself on and off at given times? */ - tr_bool isClockEnabled; + bool isClockEnabled; /* when clock mode is on, minutes after midnight to turn on turtle mode */ int beginMinute; @@ -81,7 +81,7 @@ struct tr_turtle_info /* the callback's changedByUser argument. * indicates whether the change came from the user or from the clock. */ - tr_bool changedByUser; + bool changedByUser; /* bitfield of all the minutes in a week. * Each bit's value indicates whether the scheduler wants turtle @@ -92,28 +92,28 @@ struct tr_turtle_info /** @brief handle to an active libtransmission session */ struct tr_session { - tr_bool isPortRandom; - tr_bool isPexEnabled; - tr_bool isDHTEnabled; - tr_bool isUTPEnabled; - tr_bool isLPDEnabled; - tr_bool isBlocklistEnabled; - tr_bool isPrefetchEnabled; - tr_bool isTorrentDoneScriptEnabled; - tr_bool isClosed; - tr_bool isIncompleteFileNamingEnabled; - tr_bool isRatioLimited; - tr_bool isIdleLimited; - tr_bool isIncompleteDirEnabled; - tr_bool pauseAddedTorrent; - tr_bool deleteSourceTorrent; + bool isPortRandom; + bool isPexEnabled; + bool isDHTEnabled; + bool isUTPEnabled; + bool isLPDEnabled; + bool isBlocklistEnabled; + bool isPrefetchEnabled; + bool isTorrentDoneScriptEnabled; + bool isClosed; + bool isIncompleteFileNamingEnabled; + bool isRatioLimited; + bool isIdleLimited; + bool isIncompleteDirEnabled; + bool pauseAddedTorrent; + bool deleteSourceTorrent; tr_benc removedTorrents; int umask; int speedLimit_Bps[2]; - tr_bool speedLimitEnabled[2]; + bool speedLimitEnabled[2]; struct tr_turtle_info turtle; @@ -210,7 +210,7 @@ struct tr_session * @see SESSION_BUFFER_SIZE */ void * buffer; - tr_bool bufferInUse; + bool bufferInUse; tr_web_config_func * curl_easy_config_func; @@ -229,9 +229,9 @@ tr_getPeerId( tr_session * session ) return session->peer_id; } -tr_bool tr_sessionAllowsDHT( const tr_session * session ); +bool tr_sessionAllowsDHT( const tr_session * session ); -tr_bool tr_sessionAllowsLPD( const tr_session * session ); +bool tr_sessionAllowsLPD( const tr_session * session ); const char * tr_sessionFindTorrentFile( const tr_session * session, const char * hashString ); @@ -240,18 +240,18 @@ void tr_sessionSetTorrentFile( tr_session * session, const char * hashString, const char * filename ); -tr_bool tr_sessionIsAddressBlocked( const tr_session * session, +bool tr_sessionIsAddressBlocked( const tr_session * session, const struct tr_address * addr ); void tr_sessionLock( tr_session * ); void tr_sessionUnlock( tr_session * ); -tr_bool tr_sessionIsLocked( const tr_session * ); +bool tr_sessionIsLocked( const tr_session * ); const struct tr_address* tr_sessionGetPublicAddress( const tr_session * session, int tr_af_type, - tr_bool * is_default_value ); + bool * is_default_value ); struct tr_bindsockets * tr_sessionGetBindSockets( tr_session * ); @@ -270,26 +270,26 @@ void* tr_sessionGetBuffer( tr_session * session ); void tr_sessionReleaseBuffer( tr_session * session ); -static inline tr_bool tr_isSession( const tr_session * session ) +static inline bool tr_isSession( const tr_session * session ) { return ( session != NULL ) && ( session->magicNumber == SESSION_MAGIC_NUMBER ); } -static inline tr_bool tr_isPreallocationMode( tr_preallocation_mode m ) +static inline bool tr_isPreallocationMode( tr_preallocation_mode m ) { return ( m == TR_PREALLOCATE_NONE ) || ( m == TR_PREALLOCATE_SPARSE ) || ( m == TR_PREALLOCATE_FULL ); } -static inline tr_bool tr_isEncryptionMode( tr_encryption_mode m ) +static inline bool tr_isEncryptionMode( tr_encryption_mode m ) { return ( m == TR_CLEAR_PREFERRED ) || ( m == TR_ENCRYPTION_PREFERRED ) || ( m == TR_ENCRYPTION_REQUIRED ); } -static inline tr_bool tr_isPriority( tr_priority_t p ) +static inline bool tr_isPriority( tr_priority_t p ) { return ( p == TR_PRI_LOW ) || ( p == TR_PRI_NORMAL ) @@ -317,8 +317,8 @@ int tr_sessionGetPieceSpeed_Bps( const tr_session *, tr_direction ); void tr_sessionSetSpeedLimit_Bps( tr_session *, tr_direction, int Bps ); void tr_sessionSetAltSpeed_Bps ( tr_session *, tr_direction, int Bps ); -tr_bool tr_sessionGetActiveSpeedLimit_Bps( const tr_session * session, - tr_direction dir, - int * setme ); +bool tr_sessionGetActiveSpeedLimit_Bps( const tr_session * session, + tr_direction dir, + int * setme ); #endif diff --git a/libtransmission/stats.c b/libtransmission/stats.c index db06b0e4b..e688acde9 100644 --- a/libtransmission/stats.c +++ b/libtransmission/stats.c @@ -29,7 +29,7 @@ struct tr_stats_handle tr_session_stats single; tr_session_stats old; time_t startTime; - tr_bool isDirty; + bool isDirty; }; static char* @@ -48,9 +48,9 @@ static void loadCumulativeStats( const tr_session * session, tr_session_stats * setme ) { - int loaded = FALSE; - char * filename; tr_benc top; + char * filename; + bool loaded = false; filename = getFilename( session ); loaded = !tr_bencLoadFile( &top, TR_FMT_JSON, filename ); @@ -134,7 +134,7 @@ tr_statsSaveDirty( tr_session * session ) tr_session_stats cumulative = STATS_INIT; tr_sessionGetCumulativeStats( session, &cumulative ); saveCumulativeStats( session, &cumulative ); - h->isDirty = FALSE; + h->isDirty = false; } } @@ -227,7 +227,7 @@ tr_statsAddUploaded( tr_session * session, if( ( s = getStats( session ) ) ) { s->single.uploadedBytes += bytes; - s->isDirty = TRUE; + s->isDirty = true; } } @@ -240,7 +240,7 @@ tr_statsAddDownloaded( tr_session * session, if( ( s = getStats( session ) ) ) { s->single.downloadedBytes += bytes; - s->isDirty = TRUE; + s->isDirty = true; } } diff --git a/libtransmission/torrent-ctor.c b/libtransmission/torrent-ctor.c index 3a09a5f74..bf03e70da 100644 --- a/libtransmission/torrent-ctor.c +++ b/libtransmission/torrent-ctor.c @@ -21,11 +21,11 @@ struct optional_args { - tr_bool isSet_paused; - tr_bool isSet_connected; - tr_bool isSet_downloadDir; + bool isSet_paused; + bool isSet_connected; + bool isSet_downloadDir; - tr_bool isPaused; + bool isPaused; uint16_t peerLimit; char * downloadDir; }; @@ -35,12 +35,12 @@ struct optional_args struct tr_ctor { const tr_session * session; - tr_bool saveInOurTorrentsDir; - tr_bool doDelete; + bool saveInOurTorrentsDir; + bool doDelete; tr_priority_t bandwidthPriority; - tr_bool isSet_metainfo; - tr_bool isSet_delete; + bool isSet_metainfo; + bool isSet_delete; tr_benc metainfo; char * sourceFile; @@ -227,7 +227,7 @@ void tr_ctorSetFilesWanted( tr_ctor * ctor, const tr_file_index_t * files, tr_file_index_t fileCount, - tr_bool wanted ) + bool wanted ) { tr_file_index_t ** myfiles = wanted ? &ctor->want : &ctor->notWant; tr_file_index_t * mycount = wanted ? &ctor->wantSize : &ctor->notWantSize; @@ -241,9 +241,9 @@ void tr_ctorInitTorrentWanted( const tr_ctor * ctor, tr_torrent * tor ) { if( ctor->notWantSize ) - tr_torrentInitFileDLs( tor, ctor->notWant, ctor->notWantSize, FALSE ); + tr_torrentInitFileDLs( tor, ctor->notWant, ctor->notWantSize, false ); if( ctor->wantSize ) - tr_torrentInitFileDLs( tor, ctor->want, ctor->wantSize, TRUE ); + tr_torrentInitFileDLs( tor, ctor->want, ctor->wantSize, true ); } /*** @@ -251,16 +251,14 @@ tr_ctorInitTorrentWanted( const tr_ctor * ctor, tr_torrent * tor ) ***/ void -tr_ctorSetDeleteSource( tr_ctor * ctor, - tr_bool deleteSource ) +tr_ctorSetDeleteSource( tr_ctor * ctor, bool deleteSource ) { ctor->doDelete = deleteSource != 0; ctor->isSet_delete = 1; } int -tr_ctorGetDeleteSource( const tr_ctor * ctor, - uint8_t * setme ) +tr_ctorGetDeleteSource( const tr_ctor * ctor, bool * setme ) { int err = 0; @@ -277,8 +275,7 @@ tr_ctorGetDeleteSource( const tr_ctor * ctor, ***/ void -tr_ctorSetSave( tr_ctor * ctor, - tr_bool saveInOurTorrentsDir ) +tr_ctorSetSave( tr_ctor * ctor, bool saveInOurTorrentsDir ) { ctor->saveInOurTorrentsDir = saveInOurTorrentsDir != 0; } @@ -292,7 +289,7 @@ tr_ctorGetSave( const tr_ctor * ctor ) void tr_ctorSetPaused( tr_ctor * ctor, tr_ctorMode mode, - tr_bool isPaused ) + bool isPaused ) { struct optional_args * args = &ctor->optionalArgs[mode]; @@ -353,9 +350,7 @@ tr_ctorGetPeerLimit( const tr_ctor * ctor, } int -tr_ctorGetPaused( const tr_ctor * ctor, - tr_ctorMode mode, - uint8_t * setmeIsPaused ) +tr_ctorGetPaused( const tr_ctor * ctor, tr_ctorMode mode, bool * setmeIsPaused ) { int err = 0; const struct optional_args * args = &ctor->optionalArgs[mode]; @@ -422,7 +417,7 @@ tr_ctorGetSession( const tr_ctor * ctor ) **** ***/ -static tr_bool +static bool isPriority( int i ) { return (i==TR_PRI_LOW) || (i==TR_PRI_NORMAL) || (i==TR_PRI_HIGH); @@ -459,7 +454,7 @@ tr_ctorNew( const tr_session * session ) tr_ctorSetPeerLimit( ctor, TR_FALLBACK, session->peerLimitPerTorrent ); tr_ctorSetDownloadDir( ctor, TR_FALLBACK, session->downloadDir ); } - tr_ctorSetSave( ctor, TRUE ); + tr_ctorSetSave( ctor, true ); return ctor; } diff --git a/libtransmission/torrent-magnet.c b/libtransmission/torrent-magnet.c index b428f514f..aba3589f8 100644 --- a/libtransmission/torrent-magnet.c +++ b/libtransmission/torrent-magnet.c @@ -139,7 +139,7 @@ ensureInfoDictOffsetIsCached( tr_torrent * tor ) if( !tor->infoDictOffsetIsCached ) { tor->infoDictOffset = findInfoDictOffset( tor ); - tor->infoDictOffsetIsCached = TRUE; + tor->infoDictOffsetIsCached = true; } } @@ -232,9 +232,9 @@ tr_torrentSetMetadataPiece( tr_torrent * tor, int piece, const void * data, in /* are we done? */ if( m->piecesNeededCount == 0 ) { - tr_bool success = FALSE; - tr_bool checksumPassed = FALSE; - tr_bool metainfoParsed = FALSE; + bool success = false; + bool checksumPassed = false; + bool metainfoParsed = false; uint8_t sha1[SHA_DIGEST_LENGTH]; /* we've got a complete set of metainfo... see if it passes the checksum test */ @@ -254,7 +254,7 @@ tr_torrentSetMetadataPiece( tr_torrent * tor, int piece, const void * data, in if( !tr_bencLoadFile( &newMetainfo, TR_FMT_BENC, path ) ) { - tr_bool hasInfo; + bool hasInfo; tr_info info; int infoDictLength; @@ -271,7 +271,7 @@ tr_torrentSetMetadataPiece( tr_torrent * tor, int piece, const void * data, in if( success && !tr_getBlockSize( info.pieceSize ) ) { tr_torrentSetLocalError( tor, "%s", _( "Magnet torrent's metadata is not usable" ) ); - success = FALSE; + success = false; } if( success ) @@ -317,10 +317,10 @@ tr_torrentSetMetadataPiece( tr_torrent * tor, int piece, const void * data, in } } -tr_bool +bool tr_torrentGetNextMetadataRequest( tr_torrent * tor, time_t now, int * setme_piece ) { - tr_bool have_request = FALSE; + bool have_request = false; struct tr_incomplete_metadata * m; assert( tr_isTorrent( tor ) ); @@ -344,7 +344,7 @@ tr_torrentGetNextMetadataRequest( tr_torrent * tor, time_t now, int * setme_piec dbgmsg( tor, "next piece to request: %d", piece ); *setme_piece = piece; - have_request = TRUE; + have_request = true; } return have_request; @@ -383,12 +383,12 @@ tr_torrentGetMagnetLink( const tr_torrent * tor ) if( name && *name ) { evbuffer_add_printf( s, "%s", "&dn=" ); - tr_http_escape( s, tr_torrentName( tor ), -1, TRUE ); + tr_http_escape( s, tr_torrentName( tor ), -1, true ); } for( i=0; i<tor->info.trackerCount; ++i ) { evbuffer_add_printf( s, "%s", "&tr=" ); - tr_http_escape( s, tor->info.trackers[i].announce, -1, TRUE ); + tr_http_escape( s, tor->info.trackers[i].announce, -1, true ); } return evbuffer_free_to_str( s ); diff --git a/libtransmission/torrent-magnet.h b/libtransmission/torrent-magnet.h index a402f458f..f6cbb979b 100644 --- a/libtransmission/torrent-magnet.h +++ b/libtransmission/torrent-magnet.h @@ -29,7 +29,7 @@ void* tr_torrentGetMetadataPiece( tr_torrent * tor, int piece, int * len ); void tr_torrentSetMetadataPiece( tr_torrent * tor, int piece, const void * data, int len ); -tr_bool tr_torrentGetNextMetadataRequest( tr_torrent * tor, time_t now, int * setme ); +bool tr_torrentGetNextMetadataRequest( tr_torrent * tor, time_t now, int * setme ); void tr_torrentSetMetadataSizeHint( tr_torrent * tor, int metadata_size ); diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 154c4878a..68f496f25 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -150,21 +150,21 @@ tr_torrentFindFromObfuscatedHash( tr_session * session, return NULL; } -tr_bool +bool tr_torrentIsPieceTransferAllowed( const tr_torrent * tor, tr_direction direction ) { int limit; - tr_bool allowed = TRUE; + bool allowed = true; if( tr_torrentUsesSpeedLimit( tor, direction ) ) if( tr_torrentGetSpeedLimit_Bps( tor, direction ) <= 0 ) - allowed = FALSE; + allowed = false; if( tr_torrentUsesSessionLimits( tor ) ) if( tr_sessionGetActiveSpeedLimit_Bps( tor->session, direction, &limit ) ) if( limit <= 0 ) - allowed = FALSE; + allowed = false; return allowed; } @@ -204,7 +204,7 @@ tr_torrentGetSpeedLimit_KBps( const tr_torrent * tor, tr_direction dir ) } void -tr_torrentUseSpeedLimit( tr_torrent * tor, tr_direction dir, tr_bool do_use ) +tr_torrentUseSpeedLimit( tr_torrent * tor, tr_direction dir, bool do_use ) { assert( tr_isTorrent( tor ) ); assert( tr_isDirection( dir ) ); @@ -213,7 +213,7 @@ tr_torrentUseSpeedLimit( tr_torrent * tor, tr_direction dir, tr_bool do_use ) tr_torrentSetDirty( tor ); } -tr_bool +bool tr_torrentUsesSpeedLimit( const tr_torrent * tor, tr_direction dir ) { assert( tr_isTorrent( tor ) ); @@ -223,9 +223,9 @@ tr_torrentUsesSpeedLimit( const tr_torrent * tor, tr_direction dir ) } void -tr_torrentUseSessionLimits( tr_torrent * tor, tr_bool doUse ) +tr_torrentUseSessionLimits( tr_torrent * tor, bool doUse ) { - tr_bool changed; + bool changed; assert( tr_isTorrent( tor ) ); @@ -236,7 +236,7 @@ tr_torrentUseSessionLimits( tr_torrent * tor, tr_bool doUse ) tr_torrentSetDirty( tor ); } -tr_bool +bool tr_torrentUsesSessionLimits( const tr_torrent * tor ) { assert( tr_isTorrent( tor ) ); @@ -291,15 +291,15 @@ tr_torrentGetRatioLimit( const tr_torrent * tor ) return tor->desiredRatio; } -tr_bool +bool tr_torrentGetSeedRatio( const tr_torrent * tor, double * ratio ) { - tr_bool isLimited; + bool isLimited; switch( tr_torrentGetRatioMode( tor ) ) { case TR_RATIOLIMIT_SINGLE: - isLimited = TRUE; + isLimited = true; if( ratio ) *ratio = tr_torrentGetRatioLimit( tor ); break; @@ -311,7 +311,7 @@ tr_torrentGetSeedRatio( const tr_torrent * tor, double * ratio ) break; default: /* TR_RATIOLIMIT_UNLIMITED */ - isLimited = FALSE; + isLimited = false; break; } @@ -320,13 +320,13 @@ tr_torrentGetSeedRatio( const tr_torrent * tor, double * ratio ) /* returns true if the seed ratio applies -- * it applies if the torrent's a seed AND it has a seed ratio set */ -static tr_bool +static bool tr_torrentGetSeedRatioBytes( tr_torrent * tor, uint64_t * setmeLeft, uint64_t * setmeGoal ) { double seedRatio; - tr_bool seedRatioApplies = FALSE; + bool seedRatioApplies = false; if( tr_torrentGetSeedRatio( tor, &seedRatio ) ) { @@ -342,7 +342,7 @@ tr_torrentGetSeedRatioBytes( tr_torrent * tor, return seedRatioApplies; } -static tr_bool +static bool tr_torrentIsSeedRatioDone( tr_torrent * tor ) { uint64_t bytesLeft; @@ -396,15 +396,15 @@ tr_torrentGetIdleLimit( const tr_torrent * tor ) return tor->idleLimitMinutes; } -tr_bool +bool tr_torrentGetSeedIdle( const tr_torrent * tor, uint16_t * idleMinutes ) { - tr_bool isLimited; + bool isLimited; switch( tr_torrentGetIdleMode( tor ) ) { case TR_IDLELIMIT_SINGLE: - isLimited = TRUE; + isLimited = true; if( idleMinutes ) *idleMinutes = tr_torrentGetIdleLimit( tor ); break; @@ -416,14 +416,14 @@ tr_torrentGetSeedIdle( const tr_torrent * tor, uint16_t * idleMinutes ) break; default: /* TR_IDLELIMIT_UNLIMITED */ - isLimited = FALSE; + isLimited = false; break; } return isLimited; } -static tr_bool +static bool tr_torrentIsSeedIdleLimitDone( tr_torrent * tor ) { uint16_t idleMinutes; @@ -448,7 +448,7 @@ tr_torrentCheckSeedLimit( tr_torrent * tor ) { tr_torinf( tor, "Seed ratio reached; pausing torrent" ); - tor->isStopping = TRUE; + tor->isStopping = true; /* maybe notify the client */ if( tor->ratio_limit_hit_func != NULL ) @@ -459,8 +459,8 @@ tr_torrentCheckSeedLimit( tr_torrent * tor ) { tr_torinf( tor, "Seeding idle limit reached; pausing torrent" ); - tor->isStopping = TRUE; - tor->finishedSeedingByIdle = TRUE; + tor->isStopping = true; + tor->finishedSeedingByIdle = true; /* maybe notify the client */ if( tor->idle_limit_hit_func != NULL ) @@ -488,7 +488,7 @@ tr_torrentSetLocalError( tr_torrent * tor, const char * fmt, ... ) tr_torerr( tor, "%s", tor->errorString ); if( tor->isRunning ) - tor->isStopping = TRUE; + tor->isStopping = true; } static void @@ -508,7 +508,7 @@ onTrackerResponse( tr_torrent * tor, const tr_tracker_event * event, void * unus { size_t i; const int8_t seedProbability = event->seedProbability; - const tr_bool allAreSeeds = seedProbability == 100; + const bool allAreSeeds = seedProbability == 100; if( allAreSeeds ) tr_tordbg( tor, "Got %zu seeds from tracker", event->pexCount ); @@ -759,11 +759,11 @@ tr_torrentGotNewInfoDict( tr_torrent * tor ) tr_torrentFireMetadataCompleted( tor ); } -static tr_bool +static bool hasAnyLocalData( const tr_torrent * tor ) { tr_file_index_t i; - tr_bool has_local_data = FALSE; + bool has_local_data = false; const tr_file_index_t n = tor->info.fileCount; for( i=0; i<n && !has_local_data; ++i ) @@ -772,7 +772,7 @@ hasAnyLocalData( const tr_torrent * tor ) char * filename = tr_torrentFindFile( tor, i ); if( filename && !stat( filename, &sb ) ) - has_local_data = TRUE; + has_local_data = true; tr_free( filename ); } @@ -780,10 +780,10 @@ hasAnyLocalData( const tr_torrent * tor ) return has_local_data; } -static tr_bool +static bool setLocalErrorIfFilesDisappeared( tr_torrent * tor ) { - const tr_bool disappeared = ( tr_cpHaveTotal( &tor->completion ) > 0 ) && !hasAnyLocalData( tor ); + const bool disappeared = ( tr_cpHaveTotal( &tor->completion ) > 0 ) && !hasAnyLocalData( tor ); if( disappeared ) { @@ -800,7 +800,7 @@ torrentInit( tr_torrent * tor, const tr_ctor * ctor ) int doStart; uint64_t loaded; const char * dir; - tr_bool isNewTorrent; + bool isNewTorrent; struct stat st; static int nextUniqueId = 1; tr_session * session = tr_ctorGetSession( ctor ); @@ -834,7 +834,7 @@ torrentInit( tr_torrent * tor, const tr_ctor * ctor ) tor->error = TR_STAT_OK; - tor->finishedSeedingByIdle = FALSE; + tor->finishedSeedingByIdle = false; tr_peerMgrAddTorrent( session->peerMgr, tor ); @@ -859,11 +859,11 @@ torrentInit( tr_torrent * tor, const tr_ctor * ctor ) if( !( loaded & TR_FR_SPEEDLIMIT ) ) { - tr_torrentUseSpeedLimit( tor, TR_UP, FALSE ); + tr_torrentUseSpeedLimit( tor, TR_UP, false ); tr_torrentSetSpeedLimit_Bps( tor, TR_UP, tr_sessionGetSpeedLimit_Bps( tor->session, TR_UP ) ); - tr_torrentUseSpeedLimit( tor, TR_DOWN, FALSE ); + tr_torrentUseSpeedLimit( tor, TR_DOWN, false ); tr_torrentSetSpeedLimit_Bps( tor, TR_DOWN, tr_sessionGetSpeedLimit_Bps( tor->session, TR_DOWN ) ); - tr_torrentUseSessionLimits( tor, TRUE ); + tr_torrentUseSessionLimits( tor, true ); } if( !( loaded & TR_FR_RATIOLIMIT ) ) @@ -925,11 +925,11 @@ torrentInit( tr_torrent * tor, const tr_ctor * ctor ) static tr_parse_result torrentParseImpl( const tr_ctor * ctor, tr_info * setmeInfo, - tr_bool * setmeHasInfo, int * dictLength ) + bool * setmeHasInfo, int * dictLength ) { int doFree; - tr_bool didParse; - tr_bool hasInfo = FALSE; + bool didParse; + bool hasInfo = false; tr_info tmp; const tr_benc * metainfo; tr_session * session = tr_ctorGetSession( ctor ); @@ -974,7 +974,7 @@ tr_torrent * tr_torrentNew( const tr_ctor * ctor, int * setmeError ) { int len; - tr_bool hasInfo; + bool hasInfo; tr_info tmpInfo; tr_parse_result r; tr_torrent * tor = NULL; @@ -1067,7 +1067,7 @@ tr_torrentManualUpdate( tr_torrent * tor ) tr_runInEventThread( tor->session, tr_torrentManualUpdateImpl, tor ); } -tr_bool +bool tr_torrentCanManualUpdate( const tr_torrent * tor ) { return ( tr_isTorrent( tor ) ) @@ -1143,7 +1143,7 @@ tr_torrentStat( tr_torrent * tor ) uint64_t now; uint64_t seedRatioBytesLeft; uint64_t seedRatioBytesGoal; - tr_bool seedRatioApplies; + bool seedRatioApplies; uint16_t seedIdleMinutes; if( !tor ) @@ -1350,7 +1350,7 @@ tr_torrentFiles( const tr_torrent * tor, const tr_file_index_t n = tor->info.fileCount; tr_file_stat * files = tr_new0( tr_file_stat, n ); tr_file_stat * walk = files; - const tr_bool isSeed = tor->completeness == TR_SEED; + const bool isSeed = tor->completeness == TR_SEED; assert( tr_isTorrent( tor ) ); @@ -1477,7 +1477,7 @@ tr_torrentResetTransferStats( tr_torrent * tor ) void tr_torrentSetHasPiece( tr_torrent * tor, tr_piece_index_t pieceIndex, - tr_bool has ) + bool has ) { assert( tr_isTorrent( tor ) ); assert( pieceIndex < tor->info.pieceCount ); @@ -1549,11 +1549,11 @@ torrentStartImpl( void * vtor ) tr_torrentRecheckCompleteness( tor ); now = tr_time( ); - tor->isRunning = TRUE; + tor->isRunning = true; tor->completeness = tr_cpGetStatus( &tor->completion ); tor->startDate = tor->anyDate = now; tr_torrentClearError( tor ); - tor->finishedSeedingByIdle = FALSE; + tor->finishedSeedingByIdle = false; tr_torrentResetTransferStats( tor ); tr_announcerTorrentStarted( tor ); @@ -1601,7 +1601,7 @@ torrentStart( tr_torrent * tor ) /* verifying right now... wait until that's done so * we'll know what completeness to use/announce */ if( tor->verifyState != TR_VERIFY_NONE ) { - tor->startAfterVerify = TRUE; + tor->startAfterVerify = true; return; } @@ -1643,7 +1643,7 @@ torrentRecheckDoneImpl( void * vtor ) tr_torrentRecheckCompleteness( tor ); if( tor->startAfterVerify ) { - tor->startAfterVerify = FALSE; + tor->startAfterVerify = false; torrentStart( tor ); } } @@ -1669,13 +1669,13 @@ verifyTorrent( void * vtor ) /* if the torrent's running, stop it & set the restart-after-verify flag */ if( tor->startAfterVerify || tor->isRunning ) { /* don't clobber isStopping */ - const tr_bool startAfter = tor->isStopping ? FALSE : TRUE; + const bool startAfter = tor->isStopping ? false : true; tr_torrentStop( tor ); tor->startAfterVerify = startAfter; } if( setLocalErrorIfFilesDisappeared( tor ) ) - tor->startAfterVerify = FALSE; + tor->startAfterVerify = false; else tr_verifyAdd( tor, torrentRecheckDoneCB ); @@ -1696,7 +1696,7 @@ tr_torrentSave( tr_torrent * tor ) if( tor->isDirty ) { - tor->isDirty = FALSE; + tor->isDirty = false; tr_torrentSaveResume( tor ); } } @@ -1787,7 +1787,7 @@ tr_torrentFree( tr_torrent * tor ) struct remove_data { tr_torrent * tor; - tr_bool deleteFlag; + bool deleteFlag; tr_fileFunc * deleteFunc; }; @@ -1808,7 +1808,7 @@ removeTorrent( void * vdata ) void tr_torrentRemove( tr_torrent * tor, - tr_bool deleteFlag, + bool deleteFlag, tr_fileFunc deleteFunc ) { struct remove_data * data; @@ -1851,7 +1851,7 @@ getCompletionString( int type ) static void fireCompletenessChange( tr_torrent * tor, tr_completeness status, - tr_bool wasRunning ) + bool wasRunning ) { assert( ( status == TR_LEECH ) || ( status == TR_SEED ) @@ -1976,8 +1976,8 @@ tr_torrentRecheckCompleteness( tr_torrent * tor ) if( completeness != tor->completeness ) { const int recentChange = tor->downloadedCur != 0; - const tr_bool wasLeeching = !tr_torrentIsSeed( tor ); - const tr_bool wasRunning = tor->isRunning; + const bool wasLeeching = !tr_torrentIsSeed( tor ); + const bool wasRunning = tor->isRunning; if( recentChange ) { @@ -2007,7 +2007,7 @@ tr_torrentRecheckCompleteness( tr_torrent * tor ) } if( tor->currentDir == tor->incompleteDir ) - tr_torrentSetLocation( tor, tor->downloadDir, TRUE, NULL, NULL ); + tr_torrentSetLocation( tor, tor->downloadDir, true, NULL, NULL ); if( tr_sessionIsTorrentDoneScriptEnabled( tor->session ) ) torrentCallScript( tor, tr_sessionGetTorrentDoneScript( tor->session ) ); @@ -2166,7 +2166,7 @@ void tr_torrentInitFileDLs( tr_torrent * tor, const tr_file_index_t * files, tr_file_index_t fileCount, - tr_bool doDownload ) + bool doDownload ) { tr_file_index_t i; @@ -2187,7 +2187,7 @@ void tr_torrentSetFileDLs( tr_torrent * tor, const tr_file_index_t * files, tr_file_index_t fileCount, - tr_bool doDownload ) + bool doDownload ) { assert( tr_isTorrent( tor ) ); tr_torrentLock( tor ); @@ -2285,7 +2285,7 @@ _tr_block( const tr_torrent * tor, return ret; } -tr_bool +bool tr_torrentReqIsValid( const tr_torrent * tor, tr_piece_index_t index, uint32_t offset, @@ -2387,10 +2387,10 @@ tr_torrentSetChecked( tr_torrent * tor, time_t when ) tor->info.pieces[i].timeChecked = when; } -tr_bool +bool tr_torrentCheckPiece( tr_torrent * tor, tr_piece_index_t pieceIndex ) { - const tr_bool pass = tr_ioTestPiece( tor, pieceIndex ); + const bool pass = tr_ioTestPiece( tor, pieceIndex ); tr_deeplog_tor( tor, "[LAZY] tr_torrentCheckPiece tested piece %zu, pass==%d", (size_t)pieceIndex, (int)pass ); tr_torrentSetHasPiece( tor, pieceIndex, pass ); @@ -2421,7 +2421,7 @@ tr_torrentGetFileMTime( const tr_torrent * tor, tr_file_index_t i ) return mtime; } -tr_bool +bool tr_torrentPieceNeedsCheck( const tr_torrent * tor, tr_piece_index_t p ) { uint64_t unused; @@ -2430,7 +2430,7 @@ tr_torrentPieceNeedsCheck( const tr_torrent * tor, tr_piece_index_t p ) /* if we've never checked this piece, then it needs to be checked */ if( !inf->pieces[p].timeChecked ) - return TRUE; + return true; /* If we think we've completed one of the files in this piece, * but it's been modified since we last checked it, @@ -2439,9 +2439,9 @@ tr_torrentPieceNeedsCheck( const tr_torrent * tor, tr_piece_index_t p ) for( ; f < inf->fileCount && pieceHasFile( p, &inf->files[f] ); ++f ) if( tr_cpFileIsComplete( &tor->completion, f ) ) if( tr_torrentGetFileMTime( tor, f ) > inf->pieces[p].timeChecked ) - return TRUE; + return true; - return FALSE; + return false; } /*** @@ -2462,14 +2462,14 @@ compareTrackerByTier( const void * va, const void * vb ) return a - b; } -tr_bool +bool tr_torrentSetAnnounceList( tr_torrent * tor, const tr_tracker_info * trackers_in, int trackerCount ) { int i; tr_benc metainfo; - tr_bool ok = TRUE; + bool ok = true; tr_tracker_info * trackers; tr_torrentLock( tor ); @@ -2483,12 +2483,12 @@ tr_torrentSetAnnounceList( tr_torrent * tor, /* look for bad URLs */ for( i=0; ok && i<trackerCount; ++i ) if( !tr_urlIsValidTracker( trackers[i].announce ) ) - ok = FALSE; + ok = false; /* save to the .torrent file */ if( ok && !tr_bencLoadFile( &metainfo, TR_FMT_BENC, tor->info.torrent ) ) { - tr_bool hasInfo; + bool hasInfo; tr_info tmpInfo; /* remove the old fields */ @@ -2544,11 +2544,11 @@ tr_torrentSetAnnounceList( tr_torrent * tor, if( ( tor->error == TR_STAT_TRACKER_WARNING ) || ( tor->error == TR_STAT_TRACKER_ERROR ) ) { - tr_bool clear = TRUE; + bool clear = true; for( i=0; clear && i<trackerCount; ++i ) if( !strcmp( trackers[i].announce, tor->errorTracker ) ) - clear = FALSE; + clear = false; if( clear ) tr_torrentClearError( tor ); @@ -2705,7 +2705,7 @@ walkLocalData( const tr_torrent * tor, else if( S_ISREG( sb.st_mode ) && ( sb.st_size > 0 ) ) { const char * sub = buf + strlen( tor->currentDir ) + strlen( TR_PATH_DELIMITER_STR ); - const tr_bool isTorrentFile = tr_ptrArrayFindSorted( torrentFiles, sub, vstrcmp ) != NULL; + const bool isTorrentFile = tr_ptrArrayFindSorted( torrentFiles, sub, vstrcmp ) != NULL; if( !isTorrentFile ) addDirtyFile( root, buf, dirtyFolders ); } @@ -2826,7 +2826,7 @@ tr_torrentDeleteLocalData( tr_torrent * tor, tr_fileFunc fileFunc ) struct LocationData { - tr_bool move_from_old_location; + bool move_from_old_location; volatile int * setme_state; volatile double * setme_progress; char * location; @@ -2836,10 +2836,10 @@ struct LocationData static void setLocation( void * vdata ) { - tr_bool err = FALSE; + bool err = false; struct LocationData * data = vdata; tr_torrent * tor = data->tor; - const tr_bool do_move = data->move_from_old_location; + const bool do_move = data->move_from_old_location; const char * location = data->location; double bytesHandled = 0; @@ -2874,12 +2874,12 @@ setLocation( void * vdata ) if( do_move && !tr_is_same_file( oldpath, newpath ) ) { - tr_bool renamed = FALSE; + bool renamed = false; errno = 0; tr_torinf( tor, "moving \"%s\" to \"%s\"", oldpath, newpath ); if( tr_moveFile( oldpath, newpath, &renamed ) ) { - err = TRUE; + err = true; tr_torerr( tor, "error moving \"%s\" to \"%s\": %s", oldpath, newpath, tr_strerror( errno ) ); } @@ -2926,7 +2926,7 @@ setLocation( void * vdata ) void tr_torrentSetLocation( tr_torrent * tor, const char * location, - tr_bool move_from_old_location, + bool move_from_old_location, volatile double * setme_progress, volatile int * setme_state ) { @@ -2997,15 +2997,15 @@ tr_torrentFileCompleted( tr_torrent * tor, tr_file_index_t fileNum ) **** ***/ -static tr_bool +static bool fileExists( const char * filename ) { struct stat sb; - const tr_bool ok = !stat( filename, &sb ); + const bool ok = !stat( filename, &sb ); return ok; } -tr_bool +bool tr_torrentFindFile2( const tr_torrent * tor, tr_file_index_t fileNum, const char ** base, char ** subpath ) { diff --git a/libtransmission/torrent.h b/libtransmission/torrent.h index b5e09ea1b..9c49b1b38 100644 --- a/libtransmission/torrent.h +++ b/libtransmission/torrent.h @@ -30,7 +30,7 @@ struct tr_magnet_info; **/ void tr_ctorSetSave( tr_ctor * ctor, - tr_bool saveMetadataInOurTorrentsDir ); + bool saveMetadataInOurTorrentsDir ); int tr_ctorGetSave( const tr_ctor * ctor ); @@ -45,14 +45,14 @@ void tr_ctorInitTorrentWanted( const tr_ctor * ctor, tr_torrent * tor ); /* just like tr_torrentSetFileDLs but doesn't trigger a fastresume save */ void tr_torrentInitFileDLs( tr_torrent * tor, const tr_file_index_t * files, - tr_file_index_t fileCount, - tr_bool do_download ); + tr_file_index_t fileCount, + bool do_download ); void tr_torrentRecheckCompleteness( tr_torrent * ); void tr_torrentSetHasPiece( tr_torrent * tor, tr_piece_index_t pieceIndex, - tr_bool has ); + bool has ); void tr_torrentChangeMyPort( tr_torrent * session ); @@ -62,7 +62,7 @@ tr_torrent* tr_torrentFindFromHashString( tr_session * session, tr_torrent* tr_torrentFindFromObfuscatedHash( tr_session * session, const uint8_t * hash ); -tr_bool tr_torrentIsPieceTransferAllowed( const tr_torrent * torrent, +bool tr_torrentIsPieceTransferAllowed( const tr_torrent * torrent, tr_direction direction ); @@ -72,7 +72,7 @@ tr_block_index_t _tr_block( const tr_torrent * tor, tr_piece_index_t index, uint32_t offset ); -tr_bool tr_torrentReqIsValid( const tr_torrent * tor, +bool tr_torrentReqIsValid( const tr_torrent * tor, tr_piece_index_t index, uint32_t offset, uint32_t length ); @@ -196,8 +196,8 @@ struct tr_torrent time_t dhtAnnounceAt; time_t dhtAnnounce6At; - tr_bool dhtAnnounceInProgress; - tr_bool dhtAnnounce6InProgress; + bool dhtAnnounceInProgress; + bool dhtAnnounce6InProgress; time_t lpdAnnounceAt; @@ -234,13 +234,13 @@ struct tr_torrent tr_torrent_idle_limit_hit_func * idle_limit_hit_func; void * idle_limit_hit_func_user_data; - tr_bool isRunning; - tr_bool isStopping; - tr_bool isDeleting; - tr_bool startAfterVerify; - tr_bool isDirty; + bool isRunning; + bool isStopping; + bool isDeleting; + bool startAfterVerify; + bool isDirty; - tr_bool infoDictOffsetIsCached; + bool infoDictOffsetIsCached; uint16_t maxConnectedPeers; @@ -262,7 +262,7 @@ struct tr_torrent uint16_t idleLimitMinutes; tr_idlelimit idleLimitMode; - tr_bool finishedSeedingByIdle; + bool finishedSeedingByIdle; }; static inline tr_torrent* @@ -299,7 +299,7 @@ static inline void tr_torrentLock( const tr_torrent * tor ) tr_sessionLock( tor->session ); } -static inline tr_bool tr_torrentIsLocked( const tr_torrent * tor ) +static inline bool tr_torrentIsLocked( const tr_torrent * tor ) { return tr_sessionIsLocked( tor->session ); } @@ -309,38 +309,38 @@ static inline void tr_torrentUnlock( const tr_torrent * tor ) tr_sessionUnlock( tor->session ); } -static inline tr_bool +static inline bool tr_torrentExists( const tr_session * session, const uint8_t * torrentHash ) { return tr_torrentFindFromHash( (tr_session*)session, torrentHash ) != NULL; } -static inline tr_bool +static inline bool tr_torrentIsSeed( const tr_torrent * tor ) { return tor->completeness != TR_LEECH; } -static inline tr_bool tr_torrentIsPrivate( const tr_torrent * tor ) +static inline bool tr_torrentIsPrivate( const tr_torrent * tor ) { return ( tor != NULL ) && tor->info.isPrivate; } -static inline tr_bool tr_torrentAllowsPex( const tr_torrent * tor ) +static inline bool tr_torrentAllowsPex( const tr_torrent * tor ) { return ( tor != NULL ) && ( tor->session->isPexEnabled ) && ( !tr_torrentIsPrivate( tor ) ); } -static inline tr_bool tr_torrentAllowsDHT( const tr_torrent * tor ) +static inline bool tr_torrentAllowsDHT( const tr_torrent * tor ) { return ( tor != NULL ) && ( tr_sessionAllowsDHT( tor->session ) ) && ( !tr_torrentIsPrivate( tor ) ); } -static inline tr_bool tr_torrentAllowsLPD( const tr_torrent * tor ) +static inline bool tr_torrentAllowsLPD( const tr_torrent * tor ) { return ( tor != NULL ) && ( tr_sessionAllowsLPD( tor->session ) ) @@ -356,7 +356,7 @@ enum TORRENT_MAGIC_NUMBER = 95549 }; -static inline tr_bool tr_isTorrent( const tr_torrent * tor ) +static inline bool tr_isTorrent( const tr_torrent * tor ) { return ( tor != NULL ) && ( tor->magicNumber == TORRENT_MAGIC_NUMBER ) @@ -370,7 +370,7 @@ void tr_torrentSetDirty( tr_torrent * tor ) { assert( tr_isTorrent( tor ) ); - tor->isDirty = TRUE; + tor->isDirty = true; } uint32_t tr_getBlockSize( uint32_t pieceSize ); @@ -394,8 +394,8 @@ void tr_torrentFileCompleted( tr_torrent * tor, tr_file_index_t fileNo ); * @param subpath on success, this pointer is assigned a newly-allocated * string holding the second half of the filename. */ -tr_bool tr_torrentFindFile2( const tr_torrent *, tr_file_index_t fileNo, - const char ** base, char ** subpath ); +bool tr_torrentFindFile2( const tr_torrent *, tr_file_index_t fileNo, + const char ** base, char ** subpath ); /* Returns a newly-allocated version of the tr_file.name string @@ -414,13 +414,13 @@ int tr_torrentGetSpeedLimit_Bps ( const tr_torrent *, tr_direction ); /** * @return true if this piece needs to be tested */ -tr_bool tr_torrentPieceNeedsCheck( const tr_torrent * tor, tr_piece_index_t pieceIndex ); +bool tr_torrentPieceNeedsCheck( const tr_torrent * tor, tr_piece_index_t pieceIndex ); /** * @brief Test a piece against its info dict checksum * @return true if the piece's passes the checksum test */ -tr_bool tr_torrentCheckPiece( tr_torrent * tor, tr_piece_index_t pieceIndex ); +bool tr_torrentCheckPiece( tr_torrent * tor, tr_piece_index_t pieceIndex ); time_t tr_torrentGetFileMTime( const tr_torrent * tor, tr_file_index_t i ); diff --git a/libtransmission/tr-dht.c b/libtransmission/tr-dht.c index e671c9297..9216254e9 100644 --- a/libtransmission/tr-dht.c +++ b/libtransmission/tr-dht.c @@ -262,7 +262,7 @@ tr_dhtInit(tr_session *ss) { tr_benc benc; int rc; - tr_bool have_id = FALSE; + bool have_id = false; char * dat_file; uint8_t * nodes = NULL, * nodes6 = NULL; const uint8_t * raw; @@ -392,7 +392,7 @@ tr_dhtUninit(tr_session *ss) session = NULL; } -tr_bool +bool tr_dhtEnabled( const tr_session * ss ) { return ss && ( ss == session ); @@ -458,7 +458,7 @@ int tr_dhtAddNode( tr_session * ss, const tr_address * address, tr_port port, - tr_bool bootstrap ) + bool bootstrap ) { int af = address->type == TR_AF_INET ? AF_INET : AF_INET6; @@ -547,7 +547,7 @@ callback( void *ignore UNUSED, int event, } static int -tr_dhtAnnounce(tr_torrent *tor, int af, tr_bool announce) +tr_dhtAnnounce(tr_torrent *tor, int af, bool announce) { int rc, status, numnodes, ret = 0; @@ -570,9 +570,9 @@ tr_dhtAnnounce(tr_torrent *tor, int af, tr_bool announce) af == AF_INET6 ? " IPv6" : "", tr_dhtPrintableStatus(status), numnodes); if(af == AF_INET) - tor->dhtAnnounceInProgress = TRUE; + tor->dhtAnnounceInProgress = true; else - tor->dhtAnnounce6InProgress = TRUE; + tor->dhtAnnounce6InProgress = true; ret = 1; } else { tr_torerr(tor, "%sDHT announce failed (%s, %d nodes): %s", diff --git a/libtransmission/tr-dht.h b/libtransmission/tr-dht.h index 55d00c5a0..3c244ce0b 100644 --- a/libtransmission/tr-dht.h +++ b/libtransmission/tr-dht.h @@ -38,11 +38,11 @@ enum int tr_dhtInit( tr_session * ); void tr_dhtUninit( tr_session * ); -tr_bool tr_dhtEnabled( const tr_session * ); +bool tr_dhtEnabled( const tr_session * ); tr_port tr_dhtPort ( tr_session * ); int tr_dhtStatus( tr_session *, int af, int * setme_nodeCount ); const char *tr_dhtPrintableStatus(int status); -int tr_dhtAddNode( tr_session *, const tr_address *, tr_port, tr_bool bootstrap ); +int tr_dhtAddNode( tr_session *, const tr_address *, tr_port, bool bootstrap ); void tr_dhtUpkeep( tr_session * ); void tr_dhtCallback(unsigned char *buf, int buflen, struct sockaddr *from, socklen_t fromlen, diff --git a/libtransmission/tr-lpd.c b/libtransmission/tr-lpd.c index fdcc4da9a..84ba3d3a0 100644 --- a/libtransmission/tr-lpd.c +++ b/libtransmission/tr-lpd.c @@ -392,7 +392,8 @@ void tr_lpdUninit( tr_session* ss ) session = NULL; } -tr_bool tr_lpdEnabled( const tr_session* ss ) +bool +tr_lpdEnabled( const tr_session* ss ) { return ss && ( ss == session ); } @@ -425,13 +426,14 @@ static inline void lpd_consistencyCheck( void ) * @brief Announce the given torrent on the local network * * @param[in] t Torrent to announce -* @return Returns TRUE on success +* @return Returns true on success * * Send a query for torrent t out to the LPD multicast group (or the LAN, for that * matter). A listening client on the same network might react by adding us to his * peer pool for torrent t. */ -tr_bool tr_lpdSendAnnounce( const tr_torrent* t ) +bool +tr_lpdSendAnnounce( const tr_torrent* t ) { size_t i; const char fmt[] = @@ -446,7 +448,7 @@ tr_bool tr_lpdSendAnnounce( const tr_torrent* t ) char query[lpd_maxDatagramLength + 1] = { }; if( t == NULL ) - return FALSE; + return false; /* make sure the hash string is normalized, just in case */ for( i = 0; i < sizeof hashString; i++ ) @@ -466,12 +468,12 @@ tr_bool tr_lpdSendAnnounce( const tr_torrent* t ) (const struct sockaddr*) &lpd_mcastAddr, sizeof lpd_mcastAddr ); if( res != len ) - return FALSE; + return false; } tr_tordbg( t, "LPD announce message away" ); - return TRUE; + return true; } /** diff --git a/libtransmission/tr-lpd.h b/libtransmission/tr-lpd.h index 38946bc2c..391550db3 100644 --- a/libtransmission/tr-lpd.h +++ b/libtransmission/tr-lpd.h @@ -29,12 +29,10 @@ THE SOFTWARE. /* $Id$ */ -int tr_lpdInit( tr_session*, tr_address* ); +int tr_lpdInit( tr_session*, tr_address* ); void tr_lpdUninit( tr_session* ); - -tr_bool tr_lpdEnabled( const tr_session* ); - -tr_bool tr_lpdSendAnnounce( const tr_torrent* ); +bool tr_lpdEnabled( const tr_session* ); +bool tr_lpdSendAnnounce( const tr_torrent* ); /** * @defgroup Preproc Helper macros diff --git a/libtransmission/tr-udp.c b/libtransmission/tr-udp.c index d30c955d5..6797f7100 100644 --- a/libtransmission/tr-udp.c +++ b/libtransmission/tr-udp.c @@ -96,7 +96,7 @@ set_socket_buffers(int fd, int large) void tr_udpSetSocketBuffers(tr_session *session) { - tr_bool utp = tr_sessionIsUTPEnabled(session); + bool utp = tr_sessionIsUTPEnabled(session); if(session->udp_socket >= 0) set_socket_buffers(session->udp_socket, utp); if(session->udp6_socket >= 0) @@ -110,9 +110,9 @@ tr_udpSetSocketBuffers(tr_session *session) IPv6 address, if I may say so myself. */ static void -rebind_ipv6(tr_session *ss, tr_bool force) +rebind_ipv6(tr_session *ss, bool force) { - tr_bool is_default; + bool is_default; const struct tr_address * public_addr; struct sockaddr_in6 sin6; const unsigned char *ipv6 = tr_globalIPv6(); @@ -227,7 +227,7 @@ event_callback(int s, short type UNUSED, void *sv) void tr_udpInit(tr_session *ss) { - tr_bool is_default; + bool is_default; const struct tr_address * public_addr; struct sockaddr_in sin; int rc; @@ -266,7 +266,7 @@ tr_udpInit(tr_session *ss) ipv6: if(tr_globalIPv6()) - rebind_ipv6(ss, TRUE); + rebind_ipv6(ss, true); if(ss->udp6_socket >= 0) { ss->udp6_event = event_new(ss->event_base, ss->udp6_socket, EV_READ | EV_PERSIST, diff --git a/libtransmission/tr-udp.h b/libtransmission/tr-udp.h index e76e9bfcd..bd34b9b4d 100644 --- a/libtransmission/tr-udp.h +++ b/libtransmission/tr-udp.h @@ -32,7 +32,7 @@ void tr_udpInit( tr_session * ); void tr_udpUninit( tr_session * ); void tr_udpSetSocketBuffers(tr_session *); -tr_bool tau_handle_message( tr_session * session, - const uint8_t * msg, size_t msglen ); +bool tau_handle_message( tr_session * session, + const uint8_t * msg, size_t msglen ); #endif /* #ifndef TR_UDP_H */ diff --git a/libtransmission/tr-utp.c b/libtransmission/tr-utp.c index 138c2de1d..71712b0d4 100644 --- a/libtransmission/tr-utp.c +++ b/libtransmission/tr-utp.c @@ -68,7 +68,7 @@ UTP_Write(struct UTPSocket *socket, size_t count) tr_nerr( MY_NAME, "UTP_RBDrained(%p, %zu) was called.", socket, count ); dbgmsg( "UTP_RBDrained(%p, %zu) was called.", socket, count ); assert( 0 ); /* FIXME: this is too much for the long term, but probably needed in the short term */ - return FALSE; + return false; } int tr_utpPacket(const unsigned char *buf UNUSED, size_t buflen UNUSED, diff --git a/libtransmission/transmission.h b/libtransmission/transmission.h index 500e30074..93885c095 100644 --- a/libtransmission/transmission.h +++ b/libtransmission/transmission.h @@ -41,10 +41,17 @@ extern "C" { **** ***/ -#include <stdbool.h> #include <inttypes.h> /* uintN_t */ #include <time.h> /* time_t */ +#ifdef HAVE_STDBOOL_H + #include <stdbool.h> +#elif !defined(__bool_true_false_are_defined) + #define bool uint8_t + #define true 1 + #define false 0 +#endif + #ifndef PRId64 #define PRId64 "lld" #endif @@ -68,7 +75,6 @@ typedef uint32_t tr_piece_index_t; * if we ever need to grow past that, change this to uint64_t ;) */ typedef uint32_t tr_block_index_t; typedef uint16_t tr_port; -typedef uint8_t tr_bool; typedef struct tr_ctor tr_ctor; typedef struct tr_info tr_info; @@ -250,14 +256,14 @@ void tr_sessionGetSettings( tr_session *, struct tr_benc * dictionary ); * @param dictionary pointer to an uninitialized tr_benc * @param configDir the configuration directory to find settings.json * @param appName if configDir is empty, appName is used to find the default dir. - * @return success TRUE if the settings were loaded, FALSE otherwise + * @return success true if the settings were loaded, false otherwise * @see tr_sessionGetDefaultSettings() * @see tr_sessionInit() * @see tr_sessionSaveSettings() */ -tr_bool tr_sessionLoadSettings( struct tr_benc * dictionary, - const char * configDir, - const char * appName ); +bool tr_sessionLoadSettings( struct tr_benc * dictionary, + const char * configDir, + const char * appName ); /** * Add the session's configuration settings to the benc dictionary @@ -300,7 +306,7 @@ void tr_sessionSaveSettings( tr_session * session, */ tr_session * tr_sessionInit( const char * tag, const char * configDir, - tr_bool messageQueueingEnabled, + bool messageQueueingEnabled, struct tr_benc * settings ); /** @brief Update a session's settings from a benc dictionary @@ -384,10 +390,10 @@ void tr_sessionSetIncompleteDir( tr_session * session, const char * dir ); const char* tr_sessionGetIncompleteDir( const tr_session * session ); /** @brief enable or disable use of the incomplete download folder */ -void tr_sessionSetIncompleteDirEnabled( tr_session * session, tr_bool ); +void tr_sessionSetIncompleteDirEnabled( tr_session * session, bool ); /** @brief get whether or not the incomplete download folder is enabled */ -tr_bool tr_sessionIsIncompleteDirEnabled( const tr_session * session ); +bool tr_sessionIsIncompleteDirEnabled( const tr_session * session ); /** @@ -399,10 +405,10 @@ tr_bool tr_sessionIsIncompleteDirEnabled( const tr_session * session ); * * @see tr_sessionIsIncompleteFileNamingEnabled() */ -void tr_sessionSetIncompleteFileNamingEnabled( tr_session * session, tr_bool ); +void tr_sessionSetIncompleteFileNamingEnabled( tr_session * session, bool ); /** @brief return true if files will end in ".part" until they're complete */ -tr_bool tr_sessionIsIncompleteFileNamingEnabled( const tr_session * session ); +bool tr_sessionIsIncompleteFileNamingEnabled( const tr_session * session ); /** * @brief Set whether or not RPC calls are allowed in this session. @@ -414,12 +420,12 @@ tr_bool tr_sessionIsIncompleteFileNamingEnabled( const tr_session * session ); * queried by tr_sessionIsRPCEnabled(). */ void tr_sessionSetRPCEnabled( tr_session * session, - tr_bool isEnabled ); + bool isEnabled ); /** @brief Get whether or not RPC calls are allowed in this session. @see tr_sessionInit() @see tr_sessionSetRPCEnabled() */ -tr_bool tr_sessionIsRPCEnabled( const tr_session * session ); +bool tr_sessionIsRPCEnabled( const tr_session * session ); /** @brief Specify which port to listen for RPC requests on. @see tr_sessionInit() @@ -468,9 +474,9 @@ void tr_sessionSetRPCWhitelist( tr_session * session, const char* tr_sessionGetRPCWhitelist( const tr_session * ); void tr_sessionSetRPCWhitelistEnabled( tr_session * session, - tr_bool isEnabled ); + bool isEnabled ); -tr_bool tr_sessionGetRPCWhitelistEnabled( const tr_session * session ); +bool tr_sessionGetRPCWhitelistEnabled( const tr_session * session ); void tr_sessionSetRPCPassword( tr_session * session, const char * password ); @@ -487,9 +493,9 @@ const char* tr_sessionGetRPCPassword( const tr_session * session ); const char* tr_sessionGetRPCUsername( const tr_session * session ); void tr_sessionSetRPCPasswordEnabled( tr_session * session, - tr_bool isEnabled ); + bool isEnabled ); -tr_bool tr_sessionIsRPCPasswordEnabled( const tr_session * session ); +bool tr_sessionIsRPCPasswordEnabled( const tr_session * session ); const char* tr_sessionGetRPCBindAddress( const tr_session * session ); @@ -571,20 +577,20 @@ void tr_sessionClearStats( tr_session * session ); * PEX is always disabled in private torrents regardless of this. * In public torrents, PEX is enabled by default. */ -void tr_sessionSetPexEnabled( tr_session * session, tr_bool isEnabled ); -tr_bool tr_sessionIsPexEnabled( const tr_session * session ); +void tr_sessionSetPexEnabled( tr_session * session, bool isEnabled ); +bool tr_sessionIsPexEnabled( const tr_session * session ); -tr_bool tr_sessionIsDHTEnabled( const tr_session * session ); -void tr_sessionSetDHTEnabled( tr_session * session, tr_bool ); +bool tr_sessionIsDHTEnabled( const tr_session * session ); +void tr_sessionSetDHTEnabled( tr_session * session, bool ); -tr_bool tr_sessionIsUTPEnabled( const tr_session * session ); -void tr_sessionSetUTPEnabled( tr_session * session, tr_bool ); +bool tr_sessionIsUTPEnabled( const tr_session * session ); +void tr_sessionSetUTPEnabled( tr_session * session, bool ); -tr_bool tr_sessionIsLPDEnabled( const tr_session * session ); -void tr_sessionSetLPDEnabled( tr_session * session, tr_bool enabled ); +bool tr_sessionIsLPDEnabled( const tr_session * session ); +void tr_sessionSetLPDEnabled( tr_session * session, bool enabled ); -void tr_sessionSetCacheLimit_MB( tr_session * session, int mb ); -int tr_sessionGetCacheLimit_MB( const tr_session * session ); +void tr_sessionSetCacheLimit_MB( tr_session * session, int mb ); +int tr_sessionGetCacheLimit_MB( const tr_session * session ); tr_encryption_mode tr_sessionGetEncryption( tr_session * session ); void tr_sessionSetEncryption( tr_session * session, @@ -596,9 +602,9 @@ void tr_sessionSetEncryption( tr_session * session, */ void tr_sessionSetPortForwardingEnabled( tr_session * session, - tr_bool enabled ); + bool enabled ); -tr_bool tr_sessionIsPortForwardingEnabled( const tr_session * session ); +bool tr_sessionIsPortForwardingEnabled( const tr_session * session ); void tr_sessionSetPeerPort( tr_session * session, tr_port port); @@ -607,10 +613,9 @@ tr_port tr_sessionGetPeerPort( const tr_session * session ); tr_port tr_sessionSetPeerPortRandom( tr_session * session ); -void tr_sessionSetPeerPortRandomOnStart( tr_session * session, - tr_bool random ); +void tr_sessionSetPeerPortRandomOnStart( tr_session * session, bool random ); -tr_bool tr_sessionGetPeerPortRandomOnStart( tr_session * session ); +bool tr_sessionGetPeerPortRandomOnStart( tr_session * session ); typedef enum { @@ -639,11 +644,11 @@ tr_direction; **** Primary session speed limits ***/ -void tr_sessionSetSpeedLimit_KBps ( tr_session *, tr_direction, int KBps ); -int tr_sessionGetSpeedLimit_KBps ( const tr_session *, tr_direction ); +void tr_sessionSetSpeedLimit_KBps ( tr_session *, tr_direction, int KBps ); +int tr_sessionGetSpeedLimit_KBps ( const tr_session *, tr_direction ); -void tr_sessionLimitSpeed ( tr_session *, tr_direction, tr_bool ); -tr_bool tr_sessionIsSpeedLimited ( const tr_session *, tr_direction ); +void tr_sessionLimitSpeed ( tr_session *, tr_direction, bool ); +bool tr_sessionIsSpeedLimited ( const tr_session *, tr_direction ); /*** @@ -653,11 +658,11 @@ tr_bool tr_sessionIsSpeedLimited ( const tr_session *, tr_direction ); void tr_sessionSetAltSpeed_KBps ( tr_session *, tr_direction, int Bps ); int tr_sessionGetAltSpeed_KBps ( const tr_session *, tr_direction ); -void tr_sessionUseAltSpeed ( tr_session *, tr_bool ); -tr_bool tr_sessionUsesAltSpeed ( const tr_session * ); +void tr_sessionUseAltSpeed ( tr_session *, bool ); +bool tr_sessionUsesAltSpeed ( const tr_session * ); -void tr_sessionUseAltSpeedTime ( tr_session *, tr_bool ); -tr_bool tr_sessionUsesAltSpeedTime ( const tr_session * ); +void tr_sessionUseAltSpeedTime ( tr_session *, bool ); +bool tr_sessionUsesAltSpeedTime ( const tr_session * ); void tr_sessionSetAltSpeedBegin ( tr_session *, int minsSinceMidnight ); int tr_sessionGetAltSpeedBegin ( const tr_session * ); @@ -685,17 +690,17 @@ void tr_sessionSetAltSpeedDay ( tr_session *, tr_sched_day day ); tr_sched_day tr_sessionGetAltSpeedDay ( const tr_session * ); typedef void ( tr_altSpeedFunc )( tr_session *, - tr_bool active, - tr_bool userDriven, + bool active, + bool userDriven, void * ); void tr_sessionClearAltSpeedFunc ( tr_session * ); void tr_sessionSetAltSpeedFunc ( tr_session *, tr_altSpeedFunc *, void * ); -tr_bool tr_sessionGetActiveSpeedLimit_KBps( const tr_session * session, - tr_direction dir, - double * setme ); +bool tr_sessionGetActiveSpeedLimit_KBps( const tr_session * session, + tr_direction dir, + double * setme ); /*** **** @@ -703,14 +708,14 @@ tr_bool tr_sessionGetActiveSpeedLimit_KBps( const tr_session * session, double tr_sessionGetRawSpeed_KBps ( const tr_session *, tr_direction ); -void tr_sessionSetRatioLimited ( tr_session *, tr_bool isLimited ); -tr_bool tr_sessionIsRatioLimited ( const tr_session * ); +void tr_sessionSetRatioLimited ( tr_session *, bool isLimited ); +bool tr_sessionIsRatioLimited ( const tr_session * ); void tr_sessionSetRatioLimit ( tr_session *, double desiredRatio ); double tr_sessionGetRatioLimit ( const tr_session * ); -void tr_sessionSetIdleLimited ( tr_session *, tr_bool isLimited ); -tr_bool tr_sessionIsIdleLimited ( const tr_session * ); +void tr_sessionSetIdleLimited ( tr_session *, bool isLimited ); +bool tr_sessionIsIdleLimited ( const tr_session * ); void tr_sessionSetIdleLimit ( tr_session *, uint16_t idleMinutes ); uint16_t tr_sessionGetIdleLimit ( const tr_session * ); @@ -721,11 +726,11 @@ uint16_t tr_sessionGetPeerLimit( const tr_session * ); void tr_sessionSetPeerLimitPerTorrent( tr_session *, uint16_t maxPeers ); uint16_t tr_sessionGetPeerLimitPerTorrent( const tr_session * ); -void tr_sessionSetPaused ( tr_session *, tr_bool isPaused ); -tr_bool tr_sessionGetPaused ( const tr_session * ); +void tr_sessionSetPaused ( tr_session *, bool isPaused ); +bool tr_sessionGetPaused ( const tr_session * ); -void tr_sessionSetDeleteSource ( tr_session *, tr_bool deleteSource ); -tr_bool tr_sessionGetDeleteSource ( const tr_session * ); +void tr_sessionSetDeleteSource ( tr_session *, bool deleteSource ); +bool tr_sessionGetDeleteSource ( const tr_session * ); tr_priority_t tr_torrentGetPriority( const tr_torrent * ); void tr_torrentSetPriority( tr_torrent *, tr_priority_t ); @@ -743,9 +748,9 @@ tr_torrent ** tr_sessionLoadTorrents( tr_session * session, *** **/ -tr_bool tr_sessionIsTorrentDoneScriptEnabled( const tr_session * ); +bool tr_sessionIsTorrentDoneScriptEnabled( const tr_session * ); -void tr_sessionSetTorrentDoneScriptEnabled( tr_session *, tr_bool isEnabled ); +void tr_sessionSetTorrentDoneScriptEnabled( tr_session *, bool isEnabled ); const char * tr_sessionGetTorrentDoneScript( const tr_session * ); @@ -800,9 +805,9 @@ typedef struct tr_msg_list } tr_msg_list; -void tr_setMessageQueuing( tr_bool isEnabled ); +void tr_setMessageQueuing( bool isEnabled ); -tr_bool tr_getMessageQueuing( void ); +bool tr_getMessageQueuing( void ); tr_msg_list * tr_getQueuedMessages( void ); @@ -832,12 +837,12 @@ int tr_blocklistSetContent ( tr_session * session, int tr_blocklistGetRuleCount ( const tr_session * session ); -tr_bool tr_blocklistExists ( const tr_session * session ); +bool tr_blocklistExists ( const tr_session * session ); -tr_bool tr_blocklistIsEnabled ( const tr_session * session ); +bool tr_blocklistIsEnabled ( const tr_session * session ); void tr_blocklistSetEnabled ( tr_session * session, - tr_bool isEnabled ); + bool isEnabled ); /** @brief The blocklist that ges updated when an RPC client invokes the "blocklist-update" method */ @@ -901,7 +906,7 @@ void tr_ctorFree( tr_ctor * ctor ); /** @brief Set whether or not to delete the source .torrent file when the torrent is added. (Default: False) */ -void tr_ctorSetDeleteSource( tr_ctor * ctor, tr_bool doDelete ); +void tr_ctorSetDeleteSource( tr_ctor * ctor, bool doDelete ); /** @brief Set the constructor's metainfo from a magnet link */ int tr_ctorSetMetainfoFromMagnetLink( tr_ctor * ctor, const char * magnet ); @@ -944,7 +949,7 @@ void tr_ctorSetIncompleteDir( tr_ctor * ctor, const char * directory ); (Default: not paused) */ void tr_ctorSetPaused( tr_ctor * ctor, tr_ctorMode mode, - tr_bool isPaused ); + bool isPaused ); /** @brief Set the priorities for files in a torrent */ void tr_ctorSetFilePriorities( tr_ctor * ctor, @@ -956,7 +961,7 @@ void tr_ctorSetFilePriorities( tr_ctor * ctor, void tr_ctorSetFilesWanted( tr_ctor * ctor, const tr_file_index_t * fileIndices, tr_file_index_t fileCount, - tr_bool wanted ); + bool wanted ); /** @brief Get this peer constructor's peer limit */ @@ -967,7 +972,7 @@ int tr_ctorGetPeerLimit( const tr_ctor * ctor, /** @brief Get the "isPaused" flag from this peer constructor */ int tr_ctorGetPaused( const tr_ctor * ctor, tr_ctorMode mode, - tr_bool * setmeIsPaused ); + bool * setmeIsPaused ); /** @brief Get the download path from this peer constructor */ int tr_ctorGetDownloadDir( const tr_ctor * ctor, @@ -984,7 +989,7 @@ int tr_ctorGetMetainfo( const tr_ctor * ctor, /** @brief Get the "delete .torrent file" flag from this peer constructor */ int tr_ctorGetDeleteSource( const tr_ctor * ctor, - tr_bool * setmeDoDelete ); + bool * setmeDoDelete ); /** @brief Get the tr_session poiner from this peer constructor */ tr_session* tr_ctorGetSession( const tr_ctor * ctor ); @@ -1055,7 +1060,7 @@ typedef int tr_fileFunc( const char * filename ); /** @brief Removes our .torrent and .resume files for this torrent, then calls tr_torrentFree(). */ void tr_torrentRemove( tr_torrent * torrent, - tr_bool removeLocalData, + bool removeLocalData, tr_fileFunc removeFunc ); /** @brief Start a torrent */ @@ -1080,7 +1085,7 @@ enum */ void tr_torrentSetLocation( tr_torrent * torrent, const char * location, - tr_bool move_from_previous_location, + bool move_from_previous_location, volatile double * setme_progress, volatile int * setme_state ); @@ -1129,11 +1134,11 @@ char* tr_torrentFindFile( const tr_torrent * tor, tr_file_index_t fileNo ); void tr_torrentSetSpeedLimit_KBps ( tr_torrent *, tr_direction, int KBps ); int tr_torrentGetSpeedLimit_KBps ( const tr_torrent *, tr_direction ); -void tr_torrentUseSpeedLimit ( tr_torrent *, tr_direction, tr_bool ); -tr_bool tr_torrentUsesSpeedLimit ( const tr_torrent *, tr_direction ); +void tr_torrentUseSpeedLimit ( tr_torrent *, tr_direction, bool ); +bool tr_torrentUsesSpeedLimit ( const tr_torrent *, tr_direction ); -void tr_torrentUseSessionLimits ( tr_torrent *, tr_bool ); -tr_bool tr_torrentUsesSessionLimits ( const tr_torrent * ); +void tr_torrentUseSessionLimits ( tr_torrent *, bool ); +bool tr_torrentUsesSessionLimits ( const tr_torrent * ); /**** @@ -1164,7 +1169,7 @@ void tr_torrentSetRatioLimit( tr_torrent * tor, double tr_torrentGetRatioLimit( const tr_torrent * tor ); -tr_bool tr_torrentGetSeedRatio( const tr_torrent *, double * ratio ); +bool tr_torrentGetSeedRatio( const tr_torrent *, double * ratio ); /**** @@ -1195,7 +1200,7 @@ void tr_torrentSetIdleLimit( tr_torrent * tor, uint16_t tr_torrentGetIdleLimit( const tr_torrent * tor ); -tr_bool tr_torrentGetSeedIdle( const tr_torrent *, uint16_t * minutes ); +bool tr_torrentGetSeedIdle( const tr_torrent *, uint16_t * minutes ); /**** ***** Peer Limits @@ -1239,7 +1244,7 @@ tr_priority_t* tr_torrentGetFilePriorities( const tr_torrent * torrent ); void tr_torrentSetFileDLs( tr_torrent * torrent, const tr_file_index_t * files, tr_file_index_t fileCount, - tr_bool do_download ); + bool do_download ); const tr_info * tr_torrentInfo( const tr_torrent * torrent ); @@ -1295,7 +1300,7 @@ tr_tracker_info; * and reassigns 'id'. * @param trackerCount size of the `trackers' array */ -tr_bool +bool tr_torrentSetAnnounceList( tr_torrent * torrent, const tr_tracker_info * trackers, int trackerCount ); @@ -1319,7 +1324,7 @@ tr_completeness; */ typedef void ( tr_torrent_completeness_func )( tr_torrent * torrent, tr_completeness completeness, - tr_bool wasRunning, + bool wasRunning, void * user_data ); typedef void ( tr_torrent_ratio_limit_hit_func )( tr_torrent * torrent, @@ -1408,7 +1413,7 @@ void tr_torrentClearIdleLimitHitCallback( tr_torrent * torrent ); void tr_torrentManualUpdate( tr_torrent * torrent ); -tr_bool tr_torrentCanManualUpdate( const tr_torrent * torrent ); +bool tr_torrentCanManualUpdate( const tr_torrent * torrent ); /*** **** tr_peer_stat @@ -1416,18 +1421,18 @@ tr_bool tr_torrentCanManualUpdate( const tr_torrent * torrent ); typedef struct tr_peer_stat { - tr_bool isUTP; + bool isUTP; - tr_bool isEncrypted; - tr_bool isDownloadingFrom; - tr_bool isUploadingTo; - tr_bool isSeed; + bool isEncrypted; + bool isDownloadingFrom; + bool isUploadingTo; + bool isSeed; - tr_bool peerIsChoked; - tr_bool peerIsInterested; - tr_bool clientIsChoked; - tr_bool clientIsInterested; - tr_bool isIncoming; + bool peerIsChoked; + bool peerIsInterested; + bool clientIsChoked; + bool clientIsInterested; + bool isIncoming; uint8_t from; tr_port port; @@ -1497,10 +1502,10 @@ typedef struct int downloadCount; /* whether or not we've ever sent this tracker an announcement */ - tr_bool hasAnnounced; + bool hasAnnounced; /* whether or not we've ever scraped to this tracker */ - tr_bool hasScraped; + bool hasScraped; /* human-readable string identifying the tracker */ char host[1024]; @@ -1513,7 +1518,7 @@ typedef struct /* Transmission uses one tracker per tier, * and the others are kept as backups */ - tr_bool isBackup; + bool isBackup; /* is the tracker announcing, waiting, queued, etc */ tr_tracker_state announceState; @@ -1535,10 +1540,10 @@ typedef struct /* whether or not the last announce was a success. if "hasAnnounced" is false, this field is undefined */ - tr_bool lastAnnounceSucceeded; + bool lastAnnounceSucceeded; /* whether or not the last announce timed out. */ - tr_bool lastAnnounceTimedOut; + bool lastAnnounceTimedOut; /* when the last announce was completed. if "hasAnnounced" is false, this field is undefined */ @@ -1554,10 +1559,10 @@ typedef struct /* whether or not the last scrape was a success. if "hasAnnounced" is false, this field is undefined */ - tr_bool lastScrapeSucceeded; + bool lastScrapeSucceeded; /* whether or not the last scrape timed out. */ - tr_bool lastScrapeTimedOut; + bool lastScrapeTimedOut; /* when the last scrape was completed. if "hasScraped" is false, this field is undefined */ @@ -1700,11 +1705,11 @@ struct tr_info char hashString[2 * SHA_DIGEST_LENGTH + 1]; /* Flags */ - tr_bool isPrivate; - tr_bool isMultifile; + bool isPrivate; + bool isMultifile; }; -static inline tr_bool tr_torrentHasMetadata( const tr_torrent * tor ) +static inline bool tr_torrentHasMetadata( const tr_torrent * tor ) { return tr_torrentInfo( tor )->fileCount > 0; } @@ -1909,7 +1914,7 @@ typedef struct tr_stat /** A torrent is considered finished if it has met its seed ratio. As a result, only paused torrents can be finished. */ - tr_bool finished; + bool finished; } tr_stat; @@ -1937,10 +1942,10 @@ void tr_torrentSetDoneDate( tr_torrent * torrent, time_t doneDate ); /** @} */ /** @brief Sanity checker to test that the direction is TR_UP or TR_DOWN */ -static inline tr_bool tr_isDirection( tr_direction d ) { return d==TR_UP || d==TR_DOWN; } +static inline bool tr_isDirection( tr_direction d ) { return d==TR_UP || d==TR_DOWN; } -/** @brief Sanity checker to test that a bool is TRUE or FALSE */ -static inline tr_bool tr_isBool( tr_bool b ) { return b==1 || b==0; } +/** @brief Sanity checker to test that a bool is true or false */ +static inline bool tr_isBool( bool b ) { return b==1 || b==0; } #ifdef __cplusplus } diff --git a/libtransmission/trevent.c b/libtransmission/trevent.c index 2d3bf7489..a72496dd5 100644 --- a/libtransmission/trevent.c +++ b/libtransmission/trevent.c @@ -237,7 +237,7 @@ libeventThreadFunc( void * veh ) /* set the struct's fields */ eh->base = base; eh->session->event_base = base; - eh->session->evdns_base = evdns_base_new( base, TRUE ); + eh->session->evdns_base = evdns_base_new( base, true ); eh->session->events = eh; /* listen to the pipe's read fd */ @@ -280,7 +280,7 @@ tr_eventClose( tr_session * session ) { assert( tr_isSession( session ) ); - session->events->die = TRUE; + session->events->die = true; tr_deepLog( __FILE__, __LINE__, NULL, "closing trevent pipe" ); tr_netCloseSocket( session->events->fds[1] ); } @@ -289,7 +289,7 @@ tr_eventClose( tr_session * session ) *** **/ -tr_bool +bool tr_amInEventThread( const tr_session * session ) { assert( tr_isSession( session ) ); diff --git a/libtransmission/trevent.h b/libtransmission/trevent.h index 7ff805ace..fe2e10b7c 100644 --- a/libtransmission/trevent.h +++ b/libtransmission/trevent.h @@ -23,12 +23,12 @@ /** **/ -void tr_eventInit( tr_session * ); +void tr_eventInit( tr_session * ); -void tr_eventClose( tr_session * ); +void tr_eventClose( tr_session * ); -tr_bool tr_amInEventThread( const tr_session * ); +bool tr_amInEventThread( const tr_session * ); -void tr_runInEventThread( tr_session *, void func( void* ), void * user_data ); +void tr_runInEventThread( tr_session *, void func( void* ), void * user_data ); #endif diff --git a/libtransmission/upnp.c b/libtransmission/upnp.c index 7bcc342d5..41e8fd841 100644 --- a/libtransmission/upnp.c +++ b/libtransmission/upnp.c @@ -37,7 +37,7 @@ tr_upnp_state; struct tr_upnp { - tr_bool hasDiscovered; + bool hasDiscovered; struct UPNPUrls urls; struct IGDdatas data; int port; @@ -149,7 +149,7 @@ tr_upnpPulse( tr_upnp * handle, portStr, "UDP", intClient, intPort ) != UPNPCOMMAND_SUCCESS ) { tr_ninf( getKey( ), _( "Port %d isn't forwarded" ), handle->port ); - handle->isMapped = FALSE; + handle->isMapped = false; } } diff --git a/libtransmission/utils-test.c b/libtransmission/utils-test.c index 611bfb83f..36456e4bc 100644 --- a/libtransmission/utils-test.c +++ b/libtransmission/utils-test.c @@ -299,12 +299,12 @@ test_lowerbound( void ) int i; const int A[] = { 1, 2, 3, 3, 3, 5, 8 }; const int expected_pos[] = { 0, 1, 2, 5, 5, 6, 6, 6, 7, 7 }; - const int expected_exact[] = { TRUE, TRUE, TRUE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE }; + const int expected_exact[] = { true, true, true, false, true, false, false, true, false, false }; const int N = sizeof(A) / sizeof(A[0]); for( i=1; i<=10; ++i ) { - tr_bool exact; + bool exact; const int pos = tr_lowerBound( &i, A, N, sizeof(int), compareInts, &exact ); #if 0 diff --git a/libtransmission/utils.c b/libtransmission/utils.c index 72cc3dac4..7a00a164a 100644 --- a/libtransmission/utils.c +++ b/libtransmission/utils.c @@ -66,14 +66,14 @@ time_t __tr_current_time = 0; tr_msg_level __tr_message_level = TR_MSG_ERR; -static tr_bool messageQueuing = FALSE; +static bool messageQueuing = false; static tr_msg_list * messageQueue = NULL; static tr_msg_list ** messageQueueTail = &messageQueue; static int messageQueueCount = 0; #ifndef WIN32 /* make null versions of these win32 functions */ - static inline int IsDebuggerPresent( void ) { return FALSE; } + static inline int IsDebuggerPresent( void ) { return false; } static inline void OutputDebugString( const void * unused UNUSED ) { } #endif @@ -95,7 +95,7 @@ getMessageLock( void ) void* tr_getLog( void ) { - static tr_bool initialized = FALSE; + static bool initialized = false; static FILE * file = NULL; if( !initialized ) @@ -115,7 +115,7 @@ tr_getLog( void ) default: file = NULL; break; } - initialized = TRUE; + initialized = true; } return file; @@ -128,12 +128,12 @@ tr_setMessageLevel( tr_msg_level level ) } void -tr_setMessageQueuing( tr_bool enabled ) +tr_setMessageQueuing( bool enabled ) { messageQueuing = enabled; } -tr_bool +bool tr_getMessageQueuing( void ) { return messageQueuing != 0; @@ -207,7 +207,7 @@ tr_getLogTimeStr( char * buf, int buflen ) return buf; } -tr_bool +bool tr_deepLoggingIsActive( void ) { static int8_t deepLoggingIsActive = -1; @@ -838,21 +838,21 @@ tr_strstrip( char * str ) return str; } -tr_bool +bool tr_str_has_suffix( const char *str, const char *suffix ) { size_t str_len; size_t suffix_len; if( !str ) - return FALSE; + return false; if( !suffix ) - return TRUE; + return true; str_len = strlen( str ); suffix_len = strlen( suffix ); if( str_len < suffix_len ) - return FALSE; + return false; return !evutil_ascii_strncasecmp( str + str_len - suffix_len, suffix, suffix_len ); } @@ -993,7 +993,7 @@ tr_hex_to_sha1( uint8_t * out, const char * in ) **** ***/ -static tr_bool +static bool isValidURLChars( const char * url, int url_len ) { const char * c; @@ -1008,20 +1008,20 @@ isValidURLChars( const char * url, int url_len ) "{}|\\^[]`"; /* unwise */ if( url == NULL ) - return FALSE; + return false; for( c=url, end=c+url_len; c && *c && c!=end; ++c ) if( !strchr( rfc2396_valid_chars, *c ) ) - return FALSE; + return false; - return TRUE; + return true; } -/** @brief return TRUE if the URL is a http or https or UDP one that Transmission understands */ -tr_bool +/** @brief return true if the URL is a http or https or UDP one that Transmission understands */ +bool tr_urlIsValidTracker( const char * url ) { - tr_bool valid; + bool valid; char * scheme = NULL; const int len = url ? strlen(url) : 0; @@ -1034,11 +1034,11 @@ tr_urlIsValidTracker( const char * url ) return valid; } -/** @brief return TRUE if the URL is a http or https or ftp or sftp one that Transmission understands */ -tr_bool +/** @brief return true if the URL is a http or https or ftp or sftp one that Transmission understands */ +bool tr_urlIsValid( const char * url, int url_len ) { - tr_bool valid; + bool valid; char * scheme = NULL; if( ( url_len < 0 ) && ( url != NULL ) ) url_len = strlen( url ); @@ -1052,7 +1052,7 @@ tr_urlIsValid( const char * url, int url_len ) return valid; } -tr_bool +bool tr_addressIsIP( const char * address ) { tr_address tempAddr; @@ -1228,11 +1228,11 @@ tr_lowerBound( const void * key, size_t nmemb, size_t size, int (* compar)(const void* key, const void* arrayMember), - tr_bool * exact_match ) + bool * exact_match ) { size_t first = 0; const char * cbase = base; - tr_bool exact = FALSE; + bool exact = false; while( nmemb != 0 ) { @@ -1242,7 +1242,7 @@ tr_lowerBound( const void * key, if( c <= 0 ) { if( c == 0 ) - exact = TRUE; + exact = true; nmemb = half; } else { first = middle + 1; @@ -1348,11 +1348,11 @@ struct number_range * This should be a single number (ex. "6") or a range (ex. "6-9"). * Anything else is an error and will return failure. */ -static tr_bool +static bool parseNumberSection( const char * str, int len, struct number_range * setme ) { long a, b; - tr_bool success; + bool success; char * end; const int error = errno; char * tmp = tr_strndup( str, len ); @@ -1360,18 +1360,18 @@ parseNumberSection( const char * str, int len, struct number_range * setme ) errno = 0; a = b = strtol( tmp, &end, 10 ); if( errno || ( end == tmp ) ) { - success = FALSE; + success = false; } else if( *end != '-' ) { - success = TRUE; + success = true; } else { const char * pch = end + 1; b = strtol( pch, &end, 10 ); if( errno || ( pch == end ) ) - success = FALSE; + success = false; else if( *end ) /* trailing data */ - success = FALSE; + success = false; else - success = TRUE; + success = true; } tr_free( tmp ); @@ -1405,7 +1405,7 @@ tr_parseNumberRange( const char * str_in, int len, int * setmeCount ) char * str = tr_strndup( str_in, len ); const char * walk; tr_list * ranges = NULL; - tr_bool success = TRUE; + bool success = true; walk = str; while( walk && *walk && success ) { @@ -1520,7 +1520,7 @@ tr_strratio( char * buf, size_t buflen, double ratio, const char * infinity ) ***/ int -tr_moveFile( const char * oldpath, const char * newpath, tr_bool * renamed ) +tr_moveFile( const char * oldpath, const char * newpath, bool * renamed ) { int in; int out; @@ -1587,7 +1587,7 @@ tr_moveFile( const char * oldpath, const char * newpath, tr_bool * renamed ) return 0; } -tr_bool +bool tr_is_same_file( const char * filename1, const char * filename2 ) { struct stat sb1, sb2; diff --git a/libtransmission/utils.h b/libtransmission/utils.h index 208b81797..a5ee74750 100644 --- a/libtransmission/utils.h +++ b/libtransmission/utils.h @@ -30,14 +30,6 @@ extern "C" { * @{ */ -#ifndef FALSE - #define FALSE 0 -#endif - -#ifndef TRUE - #define TRUE 1 -#endif - #ifndef UNUSED #ifdef __GNUC__ #define UNUSED __attribute__ ( ( unused ) ) @@ -120,7 +112,7 @@ static inline tr_msg_level tr_getMessageLevel( void ) return __tr_message_level; } -static inline tr_bool tr_msgLoggingIsActive( tr_msg_level level ) +static inline bool tr_msgLoggingIsActive( tr_msg_level level ) { return tr_getMessageLevel() >= level; } @@ -189,7 +181,7 @@ void tr_msg( const char * file, int line, void* tr_getLog( void ); /** @brief return true if deep logging has been enabled by the user; false otherwise */ -tr_bool tr_deepLoggingIsActive( void ); +bool tr_deepLoggingIsActive( void ); void tr_deepLog( const char * file, int line, @@ -205,7 +197,7 @@ char* tr_getLogTimeStr( char * buf, int buflen ) TR_GNUC_NONNULL(1); * @brief Rich Salz's classic implementation of shell-style pattern matching for ?, \, [], and * characters. * @return 1 if the pattern matches, 0 if it doesn't, or -1 if an error occured */ -int tr_wildmat( const char * text, const char * pattern ) TR_GNUC_NONNULL(1,2); +bool tr_wildmat( const char * text, const char * pattern ) TR_GNUC_NONNULL(1,2); /** @brief Portability wrapper for basename() that uses the system implementation if available */ char* tr_basename( const char * path ) TR_GNUC_MALLOC; @@ -356,7 +348,7 @@ int tr_lowerBound( const void * key, size_t nmemb, size_t size, int (* compar)(const void* key, const void* arrayMember), - tr_bool * exact_match ) TR_GNUC_HOT TR_GNUC_NONNULL(1,5,6); + bool * exact_match ) TR_GNUC_HOT TR_GNUC_NONNULL(1,5,6); /** @@ -398,7 +390,7 @@ const char* tr_strerror( int ); char* tr_strstrip( char * str ); /** @brief Returns true if the string ends with the specified case-insensitive suffix */ -tr_bool tr_str_has_suffix( const char *str, const char *suffix ); +bool tr_str_has_suffix( const char *str, const char *suffix ); /** @brief Portability wrapper for memmem() that uses the system implementation if available */ @@ -443,13 +435,13 @@ void tr_sha1_to_hex( char * out, const uint8_t * sha1 ) TR_GNUC_NONNULL(1,2); void tr_hex_to_sha1( uint8_t * out, const char * hex ) TR_GNUC_NONNULL(1,2); /** @brief convenience function to determine if an address is an IP address (IPv4 or IPv6) */ -tr_bool tr_addressIsIP( const char * address ); +bool tr_addressIsIP( const char * address ); -/** @brief return TRUE if the url is a http or https url that Transmission understands */ -tr_bool tr_urlIsValidTracker( const char * url ) TR_GNUC_NONNULL(1); +/** @brief return true if the url is a http or https url that Transmission understands */ +bool tr_urlIsValidTracker( const char * url ) TR_GNUC_NONNULL(1); -/** @brief return TRUE if the url is a [ http, https, ftp, ftps ] url that Transmission understands */ -tr_bool tr_urlIsValid( const char * url, int url_len ) TR_GNUC_NONNULL(1); +/** @brief return true if the url is a [ http, https, ftp, ftps ] url that Transmission understands */ +bool tr_urlIsValid( const char * url, int url_len ) TR_GNUC_NONNULL(1); /** @brief parse a URL into its component parts @return zero on success or an error number if an error occurred */ @@ -517,10 +509,10 @@ struct tm * tr_localtime_r( const time_t *_clock, struct tm *_result ); * @return 0 on success; otherwise, return -1 and set errno */ int tr_moveFile( const char * oldpath, const char * newpath, - tr_bool * renamed ) TR_GNUC_NONNULL(1,2); + bool * renamed ) TR_GNUC_NONNULL(1,2); /** @brief Test to see if the two filenames point to the same file. */ -tr_bool tr_is_same_file( const char * filename1, const char * filename2 ); +bool tr_is_same_file( const char * filename1, const char * filename2 ); /** @brief convenience function to remove an item from an array */ void tr_removeElementFromArray( void * array, diff --git a/libtransmission/verify.c b/libtransmission/verify.c index c9dd57bb9..8d1076ed1 100644 --- a/libtransmission/verify.c +++ b/libtransmission/verify.c @@ -38,15 +38,15 @@ enum MSEC_TO_SLEEP_PER_SECOND_DURING_VERIFY = 100 }; -static tr_bool -verifyTorrent( tr_torrent * tor, tr_bool * stopFlag ) +static bool +verifyTorrent( tr_torrent * tor, bool * stopFlag ) { time_t end; SHA_CTX sha; int fd = -1; int64_t filePos = 0; - tr_bool changed = 0; - tr_bool hadPiece = 0; + bool changed = 0; + bool hadPiece = 0; time_t lastSleptAt = 0; uint32_t piecePos = 0; tr_file_index_t fileIndex = 0; @@ -108,7 +108,7 @@ verifyTorrent( tr_torrent * tor, tr_bool * stopFlag ) if( leftInPiece == 0 ) { time_t now; - tr_bool hasPiece; + bool hasPiece; uint8_t hash[SHA_DIGEST_LENGTH]; SHA1_Final( hash, &sha ); @@ -180,7 +180,7 @@ fireCheckDone( tr_torrent * tor, tr_verify_done_cb verify_done_cb ) static struct verify_node currentNode; static tr_list * verifyList = NULL; static tr_thread * verifyThread = NULL; -static tr_bool stopCurrent = FALSE; +static bool stopCurrent = false; static tr_lock* getVerifyLock( void ) @@ -201,7 +201,7 @@ verifyThreadFunc( void * unused UNUSED ) struct verify_node * node; tr_lockLock( getVerifyLock( ) ); - stopCurrent = FALSE; + stopCurrent = false; node = (struct verify_node*) verifyList ? verifyList->data : NULL; if( node == NULL ) { @@ -290,7 +290,7 @@ tr_verifyRemove( tr_torrent * tor ) if( tor == currentNode.torrent ) { - stopCurrent = TRUE; + stopCurrent = true; while( stopCurrent ) { tr_lockUnlock( lock ); @@ -312,7 +312,7 @@ tr_verifyClose( tr_session * session UNUSED ) { tr_lockLock( getVerifyLock( ) ); - stopCurrent = TRUE; + stopCurrent = true; tr_list_free( &verifyList, tr_free ); tr_lockUnlock( getVerifyLock( ) ); diff --git a/libtransmission/web.c b/libtransmission/web.c index 6262f2915..75860a7b5 100644 --- a/libtransmission/web.c +++ b/libtransmission/web.c @@ -76,8 +76,8 @@ struct tr_web_task { long code; long timeout_secs; - tr_bool did_connect; - tr_bool did_timeout; + bool did_connect; + bool did_timeout; struct evbuffer * response; struct evbuffer * freebuf; char * url; @@ -118,8 +118,8 @@ static int sockoptfunction( void * vtask, curl_socket_t fd, curlsocktype purpose UNUSED ) { struct tr_web_task * task = vtask; - const tr_bool isScrape = strstr( task->url, "scrape" ) != NULL; - const tr_bool isAnnounce = strstr( task->url, "announce" ) != NULL; + const bool isScrape = strstr( task->url, "scrape" ) != NULL; + const bool isAnnounce = strstr( task->url, "announce" ) != NULL; /* announce and scrape requests have tiny payloads. */ if( isScrape || isAnnounce ) @@ -153,7 +153,7 @@ static CURL * createEasy( tr_session * s, struct tr_web_task * task ) { const tr_address * addr; - tr_bool is_default_value; + bool is_default_value; CURL * e = curl_easy_init( ); const long verbose = getenv( "TR_CURL_VERBOSE" ) != NULL; char * cookie_filename = tr_buildPath( s->configDir, "cookies.txt", NULL ); @@ -501,7 +501,7 @@ tr_webGetResponseStr( long code ) void tr_http_escape( struct evbuffer * out, - const char * str, int len, tr_bool escape_slashes ) + const char * str, int len, bool escape_slashes ) { const char * end; diff --git a/libtransmission/web.h b/libtransmission/web.h index 9915f6594..6b9357e99 100644 --- a/libtransmission/web.h +++ b/libtransmission/web.h @@ -43,8 +43,8 @@ void tr_sessionSetWebConfigFunc( tr_session * session, void (*config)(tr_session void tr_webClose( tr_session * session, tr_web_close_mode close_mode ); typedef void ( tr_web_done_func )( tr_session * session, - tr_bool timeout_flag, - tr_bool did_connect_flag, + bool timeout_flag, + bool did_connect_flag, long response_code, const void * response, size_t response_byte_count, @@ -69,7 +69,7 @@ void tr_webRunWithBuffer( tr_session * session, void * done_func_user_data, struct evbuffer * buffer ); -void tr_http_escape( struct evbuffer *out, const char *str, int len, tr_bool escape_slashes ); +void tr_http_escape( struct evbuffer *out, const char *str, int len, bool escape_slashes ); void tr_http_escape_sha1( char * out, const uint8_t * sha1_digest ); diff --git a/libtransmission/webseed.c b/libtransmission/webseed.c index 64f9c41ad..55a1145f6 100644 --- a/libtransmission/webseed.c +++ b/libtransmission/webseed.c @@ -50,7 +50,7 @@ struct tr_webseed char * base_url; size_t base_url_len; int torrent_id; - tr_bool is_stopping; + bool is_stopping; int consecutive_failures; }; @@ -112,7 +112,7 @@ fire_client_got_data( tr_webseed * w, uint32_t length ) tr_peer_event e = TR_PEER_EVENT_INIT; e.eventType = TR_PEER_CLIENT_GOT_DATA; e.length = length; - e.wasPieceData = TRUE; + e.wasPieceData = true; publish( w, &e ); } @@ -129,14 +129,14 @@ on_content_changed( struct evbuffer * buf UNUSED, if( ( info->n_added > 0 ) && !w->is_stopping ) { - tr_bandwidthUsed( &w->bandwidth, TR_DOWN, info->n_added, TRUE, tr_time_msec( ) ); + tr_bandwidthUsed( &w->bandwidth, TR_DOWN, info->n_added, true, tr_time_msec( ) ); fire_client_got_data( w, info->n_added ); } } static void task_request_next_chunk( struct tr_webseed_task * task ); -static tr_bool +static bool webseed_has_tasks( const tr_webseed * w ) { return w->tasks != NULL; @@ -194,8 +194,8 @@ on_idle( tr_webseed * w ) static void web_response_func( tr_session * session, - tr_bool did_connect UNUSED, - tr_bool did_timeout UNUSED, + bool did_connect UNUSED, + bool did_timeout UNUSED, long response_code, const void * response UNUSED, size_t response_byte_count UNUSED, @@ -253,7 +253,7 @@ make_url( tr_webseed * w, const tr_file * file ) /* if url ends with a '/', add the torrent name */ if( w->base_url[w->base_url_len - 1] == '/' && file->name ) - tr_http_escape( out, file->name, strlen(file->name), FALSE ); + tr_http_escape( out, file->name, strlen(file->name), false ); return evbuffer_free_to_str( out ); } @@ -296,15 +296,15 @@ task_request_next_chunk( struct tr_webseed_task * t ) } } -tr_bool +bool tr_webseedGetSpeed_Bps( const tr_webseed * w, uint64_t now, int * setme_Bps ) { - const tr_bool is_active = webseed_has_tasks( w ); + const bool is_active = webseed_has_tasks( w ); *setme_Bps = is_active ? tr_bandwidthGetPieceSpeed_Bps( &w->bandwidth, now, TR_DOWN ) : 0; return is_active; } -tr_bool +bool tr_webseedIsActive( const tr_webseed * w ) { int Bps = 0; @@ -334,7 +334,7 @@ tr_webseedNew( struct tr_torrent * tor, /* construct parent class */ tr_peerConstruct( peer ); - peer->peerIsChoked = TRUE; + peer->peerIsChoked = true; peer->clientIsInterested = !tr_torrentIsSeed( tor ); peer->client = tr_strdup( "webseed" ); tr_bitsetSetHaveAll( &peer->have ); @@ -359,7 +359,7 @@ tr_webseedFree( tr_webseed * w ) if( w ) { if( webseed_has_tasks( w ) ) - w->is_stopping = TRUE; + w->is_stopping = true; else webseed_free( w ); } diff --git a/libtransmission/webseed.h b/libtransmission/webseed.h index 2f0323a1e..0ed354828 100644 --- a/libtransmission/webseed.h +++ b/libtransmission/webseed.h @@ -29,12 +29,12 @@ tr_webseed* tr_webseedNew( struct tr_torrent * torrent, void tr_webseedFree( tr_webseed * ); /** @return true if a request is being processed, or false if idle */ -tr_bool tr_webseedGetSpeed_Bps( const tr_webseed * w, +bool tr_webseedGetSpeed_Bps( const tr_webseed * w, uint64_t now, int * setme_Bps ); /** @return true if a request is being processed, or false if idle */ -tr_bool tr_webseedIsActive( const tr_webseed * w ); +bool tr_webseedIsActive( const tr_webseed * w ); #endif diff --git a/libtransmission/wildmat.c b/libtransmission/wildmat.c index 1e95839f9..55ca1dc27 100644 --- a/libtransmission/wildmat.c +++ b/libtransmission/wildmat.c @@ -20,13 +20,13 @@ ** explanation is from Lars: ** The precondition that must be fulfilled is that DoMatch will consume ** at least one character in text. This is true if *p is neither '*' nor -** '\0'.) The last return has ABORT instead of FALSE to avoid quadratic +** '\0'.) The last return has ABORT instead of false to avoid quadratic ** behaviour in cases like pattern "*a*b*c*d" with text "abcxxxxx". With -** FALSE, each star-loop has to run to the end of the text; with ABORT +** false, each star-loop has to run to the end of the text; with ABORT ** only the last one does. ** ** Once the control of one instance of DoMatch enters the star-loop, that -** instance will return either TRUE or ABORT, and any calling instance +** instance will return either true or ABORT, and any calling instance ** will therefore return immediately after (without calling recursively ** again). In effect, only one star-loop is ever active. It would be ** possible to modify the code to maintain this context explicitly, @@ -51,7 +51,7 @@ /* -** Match text and p, return TRUE, FALSE, or ABORT. +** Match text and p, return true, false, or ABORT. */ static int DoMatch( const char * text, const char * p ) @@ -70,7 +70,7 @@ DoMatch( const char * text, const char * p ) /* FALLTHROUGH */ default: if (*text != *p) - return FALSE; + return false; continue; case '?': /* Match anything. */ @@ -81,42 +81,40 @@ DoMatch( const char * text, const char * p ) continue; if (*p == '\0') /* Trailing star matches everything. */ - return TRUE; + return true; while (*text) - if ((matched = DoMatch(text++, p)) != FALSE) + if ((matched = DoMatch(text++, p)) != false) return matched; return ABORT; case '[': - reverse = p[1] == NEGATE_CLASS ? TRUE : FALSE; + reverse = p[1] == NEGATE_CLASS ? true : false; if (reverse) /* Inverted character class. */ p++; - for (last = 0400, matched = FALSE; *++p && *p != ']'; last = *p) + for (last = 0400, matched = false; *++p && *p != ']'; last = *p) /* This next line requires a good C compiler. */ if (*p == '-' ? *text <= *++p && *text >= last : *text == *p) - matched = TRUE; + matched = true; if (matched == reverse) - return FALSE; + return false; continue; } } #ifdef MATCH_TAR_PATTERN if (*text == '/') - return TRUE; + return true; #endif /* MATCH_TAR_ATTERN */ return *text == '\0'; } -/* -** User-level routine. Returns TRUE or FALSE. -*/ -int +/* User-level routine. returns whether or not 'text' and 'p' matched */ +bool tr_wildmat(const char * text, const char * p ) { if (p[0] == '*' && p[1] == '\0') - return TRUE; + return true; - return DoMatch(text, p) == TRUE; + return DoMatch(text, p) == true; } diff --git a/macosx/Controller.m b/macosx/Controller.m index 632820b70..3b3346f60 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -134,7 +134,7 @@ typedef enum #define DONATE_NAG_TIME (60 * 60 * 24 * 7) -static void altSpeedToggledCallback(tr_session * handle UNUSED, tr_bool active, tr_bool byUser, void * controller) +static void altSpeedToggledCallback(tr_session * handle UNUSED, bool active, bool byUser, void * controller) { NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys: [[NSNumber alloc] initWithBool: active], @"Active", [[NSNumber alloc] initWithBool: byUser], @"ByUser", nil]; diff --git a/macosx/Torrent.m b/macosx/Torrent.m index f3b09b236..3ad7308b0 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -60,7 +60,7 @@ @end -void completenessChangeCallback(tr_torrent * torrent, tr_completeness status, tr_bool wasRunning, void * torrentData) +void completenessChangeCallback(tr_torrent * torrent, tr_completeness status, bool wasRunning, void * torrentData) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; diff --git a/third-party/libutp/utypes.h b/third-party/libutp/utypes.h index 673554e24..d4f4b17ec 100644 --- a/third-party/libutp/utypes.h +++ b/third-party/libutp/utypes.h @@ -36,7 +36,7 @@ typedef const char * cstr; typedef char * str; #ifndef __cplusplus -typedef uint8 bool; +#include <stdbool.h> #endif #endif //__UTYPES_H__ diff --git a/utils/create.c b/utils/create.c index 65a6f574a..e79dc2878 100644 --- a/utils/create.c +++ b/utils/create.c @@ -26,8 +26,8 @@ #define MAX_TRACKERS 128 static tr_tracker_info trackers[MAX_TRACKERS]; static int trackerCount = 0; -static tr_bool isPrivate = FALSE; -static tr_bool showVersion = FALSE; +static bool isPrivate = false; +static bool showVersion = false; const char * comment = NULL; const char * outfile = NULL; const char * infile = NULL; @@ -58,8 +58,8 @@ parseCommandLine( int argc, const char ** argv ) { switch( c ) { - case 'V': showVersion = TRUE; break; - case 'p': isPrivate = TRUE; break; + case 'V': showVersion = true; break; + case 'p': isPrivate = true; break; case 'o': outfile = optarg; break; case 'c': comment = optarg; break; case 't': if( trackerCount + 1 < MAX_TRACKERS ) { diff --git a/utils/edit.c b/utils/edit.c index d2ed6181c..a86b1c335 100644 --- a/utils/edit.c +++ b/utils/edit.c @@ -25,7 +25,7 @@ #define MY_NAME "transmission-edit" static int fileCount = 0; -static tr_bool showVersion = FALSE; +static bool showVersion = false; static const char ** files = NULL; static const char * add = NULL; static const char * deleteme = NULL; @@ -65,7 +65,7 @@ parseCommandLine( int argc, const char ** argv ) if( c != TR_OPT_UNK ) return 1; replace[1] = optarg; break; - case 'V': showVersion = TRUE; + case 'V': showVersion = true; break; case TR_OPT_UNK: files[fileCount++] = optarg; break; default: return 1; @@ -75,18 +75,18 @@ parseCommandLine( int argc, const char ** argv ) return 0; } -static tr_bool +static bool removeURL( tr_benc * metainfo, const char * url ) { const char * str; tr_benc * announce_list; - tr_bool changed = FALSE; + bool changed = false; if( tr_bencDictFindStr( metainfo, "announce", &str ) && !strcmp( str, url ) ) { printf( "\tRemoved \"%s\" from \"announce\"\n", str ); tr_bencDictRemove( metainfo, "announce" ); - changed = TRUE; + changed = true; } if( tr_bencDictFindList( metainfo, "announce-list", &announce_list ) ) @@ -103,7 +103,7 @@ removeURL( tr_benc * metainfo, const char * url ) { printf( "\tRemoved \"%s\" from \"announce-list\" tier #%d\n", str, (tierIndex+1) ); tr_bencListRemove( tier, nodeIndex ); - changed = TRUE; + changed = true; } else ++nodeIndex; } @@ -163,12 +163,12 @@ replaceSubstr( const char * str, const char * in, const char * out ) return evbuffer_free_to_str( buf ); } -static tr_bool +static bool replaceURL( tr_benc * metainfo, const char * in, const char * out ) { const char * str; tr_benc * announce_list; - tr_bool changed = FALSE; + bool changed = false; if( tr_bencDictFindStr( metainfo, "announce", &str ) && strstr( str, in ) ) { @@ -176,7 +176,7 @@ replaceURL( tr_benc * metainfo, const char * in, const char * out ) printf( "\tReplaced in \"announce\": \"%s\" --> \"%s\"\n", str, newstr ); tr_bencDictAddStr( metainfo, "announce", newstr ); tr_free( newstr ); - changed = TRUE; + changed = true; } if( tr_bencDictFindList( metainfo, "announce-list", &announce_list ) ) @@ -196,7 +196,7 @@ replaceURL( tr_benc * metainfo, const char * in, const char * out ) tr_bencFree( node ); tr_bencInitStr( node, newstr, -1 ); tr_free( newstr ); - changed = TRUE; + changed = true; } } } @@ -205,20 +205,20 @@ replaceURL( tr_benc * metainfo, const char * in, const char * out ) return changed; } -static tr_bool +static bool addURL( tr_benc * metainfo, const char * url ) { const char * str; tr_benc * announce_list; - tr_bool changed = FALSE; - tr_bool match = FALSE; + bool changed = false; + bool match = false; /* maybe add it to "announce" */ if( !tr_bencDictFindStr( metainfo, "announce", &str ) ) { printf( "\tAdded \"%s\" in \"announce\"\n", url ); tr_bencDictAddStr( metainfo, "announce", url ); - changed = TRUE; + changed = true; } /* see if it's already in announce-list */ @@ -230,7 +230,7 @@ addURL( tr_benc * metainfo, const char * url ) int nodeCount = 0; while(( node = tr_bencListChild( tier, nodeCount++ ))) if( tr_bencGetStr( node, &str ) && !strcmp( str, url ) ) - match = TRUE; + match = true; } } @@ -245,7 +245,7 @@ addURL( tr_benc * metainfo, const char * url ) tier = tr_bencListAddList( announce_list, 1 ); tr_bencListAddStr( tier, url ); printf( "\tAdded \"%s\" to \"announce-list\" tier %zu\n", url, tr_bencListSize( announce_list ) ); - changed = TRUE; + changed = true; } return changed; @@ -289,7 +289,7 @@ main( int argc, char * argv[] ) for( i=0; i<fileCount; ++i ) { tr_benc top; - tr_bool changed = FALSE; + bool changed = false; const char * filename = files[i]; printf( "%s\n", filename ); diff --git a/utils/show.c b/utils/show.c index 85a60b7ca..52762314b 100644 --- a/utils/show.c +++ b/utils/show.c @@ -63,8 +63,8 @@ getUsage( void ) return "Usage: " MY_NAME " [options] <.torrent file>"; } -static tr_bool scrapeFlag = FALSE; -static tr_bool showVersion = FALSE; +static bool scrapeFlag = false; +static bool showVersion = false; const char * filename = NULL; static int @@ -77,8 +77,8 @@ parseCommandLine( int argc, const char ** argv ) { switch( c ) { - case 's': scrapeFlag = TRUE; break; - case 'V': showVersion = TRUE; break; + case 's': scrapeFlag = true; break; + case 'V': showVersion = true; break; case TR_OPT_UNK: filename = optarg; break; default: return 1; } @@ -237,7 +237,7 @@ doScrape( const tr_info * inf ) { tr_benc top; tr_benc * files; - tr_bool matched = FALSE; + bool matched = false; const char * begin = (const char*) evbuffer_pullup( buf, -1 ); const char * end = begin + evbuffer_get_length( buf ); @@ -258,7 +258,7 @@ doScrape( const tr_info * inf ) tr_bencDictFindInt( val, "complete", &seeders ); tr_bencDictFindInt( val, "incomplete", &leechers ); printf( "%d seeders, %d leechers\n", (int)seeders, (int)leechers ); - matched = TRUE; + matched = true; } } }