From: Charles Kerr Date: Sun, 14 Dec 2008 11:21:11 +0000 (+0000) Subject: (trunk libT) more semantic cleanup: tr_handle->tr_session, int->tr_bool, int->tr_port X-Git-Tag: 1.60~766 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=788b397ecc5d5b21ba18d3950cdff966c586505e;p=transmission (trunk libT) more semantic cleanup: tr_handle->tr_session, int->tr_bool, int->tr_port --- diff --git a/libtransmission/handshake.c b/libtransmission/handshake.c index e795fb7b2..730937f53 100644 --- a/libtransmission/handshake.c +++ b/libtransmission/handshake.c @@ -92,7 +92,7 @@ struct tr_handshake tr_bool haveSentBitTorrentHandshake; tr_peerIo * io; tr_crypto * crypto; - struct tr_handle * handle; + tr_session * session; uint8_t myPublicKey[KEY_LEN]; uint8_t mySecret[KEY_LEN]; uint8_t state; @@ -206,7 +206,7 @@ buildHandshakeMessage( tr_handshake * handshake, uint8_t * buf = tr_new0( uint8_t, HANDSHAKE_SIZE ); uint8_t * walk = buf; const uint8_t * torrentHash = tr_cryptoGetTorrentHash( handshake->crypto ); - const tr_torrent * tor = tr_torrentFindFromHash( handshake->handle, torrentHash ); + const tr_torrent * tor = tr_torrentFindFromHash( handshake->session, torrentHash ); const uint8_t * peer_id = tor && tor->peer_id ? tor->peer_id : tr_getPeerId( ); memcpy( walk, HANDSHAKE_NAME, HANDSHAKE_NAME_LEN ); @@ -265,7 +265,7 @@ parseHandshake( tr_handshake * handshake, /* torrent hash */ tr_peerIoReadBytes( handshake->io, inbuf, hash, sizeof( hash ) ); assert( tr_peerIoHasTorrentHash( handshake->io ) ); - if( !tr_torrentExists( handshake->handle, hash ) + if( !tr_torrentExists( handshake->session, hash ) || memcmp( hash, tr_peerIoGetTorrentHash( handshake->io ), SHA_DIGEST_LENGTH ) ) { @@ -283,7 +283,7 @@ parseHandshake( tr_handshake * handshake, dbgmsg( handshake, "peer-id is [%*.*s]", PEER_ID_LEN, PEER_ID_LEN, handshake->peer_id ); - tor = tr_torrentFindFromHash( handshake->handle, hash ); + tor = tr_torrentFindFromHash( handshake->session, hash ); peer_id = tor && tor->peer_id ? tor->peer_id : tr_getPeerId( ); if( !memcmp( handshake->peer_id, peer_id, PEER_ID_LEN ) ) { @@ -664,7 +664,7 @@ readHandshake( tr_handshake * handshake, tr_peerIoReadBytes( handshake->io, inbuf, hash, sizeof( hash ) ); if( tr_peerIoIsIncoming( handshake->io ) ) { - if( !tr_torrentExists( handshake->handle, hash ) ) + 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 ); @@ -724,7 +724,7 @@ readPeerId( tr_handshake * handshake, tr_peerIoIsIncoming( handshake->io ) ); /* if we've somehow connected to ourselves, don't keep the connection */ - tor = tr_torrentFindFromHash( handshake->handle, tr_peerIoGetTorrentHash( handshake->io ) ); + tor = tr_torrentFindFromHash( handshake->session, tr_peerIoGetTorrentHash( handshake->io ) ); peer_id = tor && tor->peer_id ? tor->peer_id : tr_getPeerId( ); peerIsGood = memcmp( handshake->peer_id, peer_id, PEER_ID_LEN ) != 0; dbgmsg( handshake, "isPeerGood == %d", peerIsGood ); @@ -844,14 +844,14 @@ readCryptoProvide( tr_handshake * handshake, for( i = 0; i < SHA_DIGEST_LENGTH; ++i ) obfuscatedTorrentHash[i] = req2[i] ^ req3[i]; if( ( tor = - tr_torrentFindFromObfuscatedHash( handshake->handle, + tr_torrentFindFromObfuscatedHash( handshake->session, obfuscatedTorrentHash ) ) ) { dbgmsg( handshake, "got INCOMING connection's encrypted handshake for torrent [%s]", tor->info.name ); tr_peerIoSetTorrentHash( handshake->io, tor->info.hash ); if( !tr_torrentAllowsPex( tor ) - && tr_peerMgrPeerIsSeed( handshake->handle->peerMgr, + && tr_peerMgrPeerIsSeed( handshake->session->peerMgr, tor->info.hash, tr_peerIoGetAddress( handshake->io, NULL ) ) ) { @@ -1163,7 +1163,7 @@ tr_handshakeNew( tr_peerIo * io, handshake->encryptionMode = encryptionMode; handshake->doneCB = doneCB; handshake->doneUserData = doneUserData; - handshake->handle = tr_peerIoGetSession( io ); + handshake->session = tr_peerIoGetSession( io ); tr_peerIoSetTimeoutSecs( io, 15 ); tr_peerIoSetIOFuncs( handshake->io, canRead, NULL, gotError, handshake ); diff --git a/libtransmission/iobuf.c b/libtransmission/iobuf.c index 2ae2d4a7b..4ac9fe2eb 100644 --- a/libtransmission/iobuf.c +++ b/libtransmission/iobuf.c @@ -73,7 +73,7 @@ struct tr_iobuf int timeout_write; /* in seconds */ short enabled; /* events that are currently enabled */ - struct tr_handle * session; + tr_session * session; struct tr_bandwidth * bandwidth; }; @@ -245,7 +245,7 @@ tr_iobuf_writecb( int fd, short event, void * arg ) */ struct tr_iobuf * -tr_iobuf_new( struct tr_handle * session, +tr_iobuf_new( tr_session * session, tr_bandwidth * bandwidth, int fd, short event, diff --git a/libtransmission/iobuf.h b/libtransmission/iobuf.h index fbcf8922a..fe573c1b4 100644 --- a/libtransmission/iobuf.h +++ b/libtransmission/iobuf.h @@ -68,7 +68,7 @@ typedef void (*tr_iobuf_cb)( struct tr_iobuf*, size_t bytes_transferred, void* ) typedef void (*tr_iobuf_error_cb)( struct tr_iobuf*, short what, void* ); /** @brief create a new tr_iobuf object. */ -struct tr_iobuf* tr_iobuf_new( struct tr_handle * session, +struct tr_iobuf* tr_iobuf_new( tr_session * session, struct tr_bandwidth * bandwidth, int fd, short event, diff --git a/libtransmission/makemeta.c b/libtransmission/makemeta.c index ea5889e5d..2d83ae14e 100644 --- a/libtransmission/makemeta.c +++ b/libtransmission/makemeta.c @@ -113,7 +113,7 @@ builderFileCompare( const void * va, } tr_metainfo_builder* -tr_metaInfoBuilderCreate( tr_handle * handle, +tr_metaInfoBuilderCreate( tr_session * session, const char * topFile ) { int i; @@ -122,7 +122,7 @@ tr_metaInfoBuilderCreate( tr_handle * handle, tr_metainfo_builder * ret = tr_new0( tr_metainfo_builder, 1 ); ret->top = tr_strdup( topFile ); - ret->handle = handle; + ret->handle = session; { struct stat sb; stat( topFile, &sb ); @@ -444,29 +444,29 @@ static tr_metainfo_builder * queue = NULL; static tr_thread * workerThread = NULL; static tr_lock* -getQueueLock( tr_handle * h ) +getQueueLock( tr_session * session ) { static tr_lock * lock = NULL; + tr_globalLock( session ); - tr_globalLock( h ); if( !lock ) lock = tr_lockNew( ); - tr_globalUnlock( h ); + tr_globalUnlock( session ); return lock; } static void makeMetaWorkerFunc( void * user_data ) { - tr_handle * handle = (tr_handle *) user_data; + tr_session * session = user_data; for( ; ; ) { tr_metainfo_builder * builder = NULL; /* find the next builder to process */ - tr_lock * lock = getQueueLock ( handle ); + tr_lock * lock = getQueueLock( session ); tr_lockLock( lock ); if( queue ) { diff --git a/libtransmission/makemeta.h b/libtransmission/makemeta.h index aaf0f5410..3d9082021 100644 --- a/libtransmission/makemeta.h +++ b/libtransmission/makemeta.h @@ -45,7 +45,7 @@ typedef struct tr_metainfo_builder uint32_t pieceSize; uint32_t pieceCount; int isSingleFile; - tr_handle * handle; + tr_session * handle; /** *** These are set inside tr_makeMetaInfo() @@ -87,7 +87,7 @@ typedef struct tr_metainfo_builder tr_metainfo_builder; -tr_metainfo_builder*tr_metaInfoBuilderCreate( tr_handle * handle, +tr_metainfo_builder*tr_metaInfoBuilderCreate( tr_session * session, const char * topFile ); void tr_metaInfoBuilderFree( tr_metainfo_builder* ); diff --git a/libtransmission/metainfo.c b/libtransmission/metainfo.c index 045cde186..69589ab13 100644 --- a/libtransmission/metainfo.c +++ b/libtransmission/metainfo.c @@ -45,28 +45,28 @@ ***/ static char* -getTorrentFilename( const tr_handle * handle, +getTorrentFilename( const tr_session * session, const tr_info * inf ) { return tr_strdup_printf( "%s%c%s.%16.16s.torrent", - tr_getTorrentDir( handle ), + tr_getTorrentDir( session ), TR_PATH_DELIMITER, inf->name, inf->hashString ); } static char* -getOldTorrentFilename( const tr_handle * handle, +getOldTorrentFilename( const tr_session * session, const tr_info * inf ) { char * ret; struct evbuffer * buf = evbuffer_new( ); - evbuffer_add_printf( buf, "%s%c%s", tr_getTorrentDir( handle ), + evbuffer_add_printf( buf, "%s%c%s", tr_getTorrentDir( session ), TR_PATH_DELIMITER, inf->hashString ); - if( handle->tag ) - evbuffer_add_printf( buf, "-%s", handle->tag ); + if( session->tag ) + evbuffer_add_printf( buf, "-%s", session->tag ); ret = tr_strndup( EVBUFFER_DATA( buf ), EVBUFFER_LENGTH( buf ) ); evbuffer_free( buf ); @@ -74,19 +74,19 @@ getOldTorrentFilename( const tr_handle * handle, } void -tr_metainfoMigrate( tr_handle * handle, +tr_metainfoMigrate( tr_session * session, tr_info * inf ) { struct stat new_sb; - char * name = getTorrentFilename( handle, inf ); + char * name = getTorrentFilename( session, inf ); if( stat( name, &new_sb ) || ( ( new_sb.st_mode & S_IFMT ) != S_IFREG ) ) { - char * old_name = getOldTorrentFilename( handle, inf ); + char * old_name = getOldTorrentFilename( session, inf ); size_t contentLen; uint8_t * content; - tr_mkdirp( tr_getTorrentDir( handle ), 0777 ); + tr_mkdirp( tr_getTorrentDir( session ), 0777 ); if( ( content = tr_loadFile( old_name, &contentLen ) ) ) { FILE * out; @@ -104,7 +104,7 @@ tr_metainfoMigrate( tr_handle * handle, { tr_free( inf->torrent ); inf->torrent = tr_strdup( name ); - tr_sessionSetTorrentFile( handle, inf->hashString, name ); + tr_sessionSetTorrentFile( session, inf->hashString, name ); unlink( old_name ); } fclose( out ); @@ -340,7 +340,7 @@ geturllist( tr_info * inf, } static const char* -tr_metainfoParseImpl( const tr_handle * handle, +tr_metainfoParseImpl( const tr_session * session, tr_info * inf, const tr_benc * meta_in ) { @@ -436,17 +436,17 @@ tr_metainfoParseImpl( const tr_handle * handle, /* filename of Transmission's copy */ tr_free( inf->torrent ); - inf->torrent = getTorrentFilename( handle, inf ); + inf->torrent = getTorrentFilename( session, inf ); return NULL; } int -tr_metainfoParse( const tr_handle * handle, +tr_metainfoParse( const tr_session * session, tr_info * inf, const tr_benc * meta_in ) { - const char * badTag = tr_metainfoParseImpl( handle, inf, meta_in ); + const char * badTag = tr_metainfoParseImpl( session, inf, meta_in ); if( badTag ) { @@ -488,16 +488,16 @@ tr_metainfoFree( tr_info * inf ) } void -tr_metainfoRemoveSaved( const tr_handle * handle, +tr_metainfoRemoveSaved( const tr_session * session, const tr_info * inf ) { char * filename; - filename = getTorrentFilename( handle, inf ); + filename = getTorrentFilename( session, inf ); unlink( filename ); tr_free( filename ); - filename = getOldTorrentFilename( handle, inf ); + filename = getOldTorrentFilename( session, inf ); unlink( filename ); tr_free( filename ); } diff --git a/libtransmission/metainfo.h b/libtransmission/metainfo.h index 5738cdc31..4ca3aa840 100644 --- a/libtransmission/metainfo.h +++ b/libtransmission/metainfo.h @@ -37,15 +37,15 @@ extern "C" { struct tr_benc; -int tr_metainfoParse( const tr_handle * handle, - tr_info * info, +int tr_metainfoParse( const tr_session * session, + tr_info * info, const struct tr_benc * benc ); -void tr_metainfoRemoveSaved( const tr_handle * handle, - const tr_info * info ); +void tr_metainfoRemoveSaved( const tr_session * session, + const tr_info * info ); -void tr_metainfoMigrate( tr_handle * handle, - tr_info * inf ); +void tr_metainfoMigrate( tr_session * session, + tr_info * inf ); #ifdef __cplusplus } diff --git a/libtransmission/peer-io.h b/libtransmission/peer-io.h index 428f7dfc5..54bd527f5 100644 --- a/libtransmission/peer-io.h +++ b/libtransmission/peer-io.h @@ -32,12 +32,12 @@ typedef struct tr_peerIo tr_peerIo; *** **/ -tr_peerIo* tr_peerIoNewOutgoing( struct tr_handle * session, +tr_peerIo* tr_peerIoNewOutgoing( tr_session * session, const struct tr_address * addr, tr_port port, const uint8_t * torrentHash ); -tr_peerIo* tr_peerIoNewIncoming( struct tr_handle * session, +tr_peerIo* tr_peerIoNewIncoming( tr_session * session, const struct tr_address * addr, tr_port port, int socket ); diff --git a/libtransmission/peer-mgr.h b/libtransmission/peer-mgr.h index 58f1c200a..9aca6a35e 100644 --- a/libtransmission/peer-mgr.h +++ b/libtransmission/peer-mgr.h @@ -25,7 +25,6 @@ #include "net.h" -struct tr_handle; struct tr_peer_stat; struct tr_torrent; typedef struct tr_peerMgr tr_peerMgr; @@ -49,7 +48,7 @@ tr_pex; int tr_pexCompare( const void * a, const void * b ); -tr_peerMgr* tr_peerMgrNew( struct tr_handle * ); +tr_peerMgr* tr_peerMgrNew( tr_session * ); void tr_peerMgrFree( tr_peerMgr * manager ); diff --git a/libtransmission/platform.c b/libtransmission/platform.c index 786a4d9d3..5e22fa4d1 100644 --- a/libtransmission/platform.c +++ b/libtransmission/platform.c @@ -352,7 +352,7 @@ moveFiles( const char * oldDir, } static void -migrateFiles( const tr_handle * handle ) +migrateFiles( const tr_session * session ) { static int migrated = FALSE; @@ -363,50 +363,50 @@ migrateFiles( const tr_handle * handle ) migrated = TRUE; oldDir = getOldTorrentsDir( ); - newDir = tr_getTorrentDir( handle ); + newDir = tr_getTorrentDir( session ); moveFiles( oldDir, newDir ); oldDir = getOldCacheDir( ); - newDir = tr_getResumeDir( handle ); + newDir = tr_getResumeDir( session ); moveFiles( oldDir, newDir ); } } void -tr_setConfigDir( tr_handle * handle, +tr_setConfigDir( tr_session * session, const char * configDir ) { char * path; - handle->configDir = tr_strdup( configDir ); + session->configDir = tr_strdup( configDir ); path = tr_buildPath( configDir, RESUME_SUBDIR, NULL ); tr_mkdirp( path, 0777 ); - handle->resumeDir = path; + session->resumeDir = path; path = tr_buildPath( configDir, TORRENT_SUBDIR, NULL ); tr_mkdirp( path, 0777 ); - handle->torrentDir = path; + session->torrentDir = path; - migrateFiles( handle ); + migrateFiles( session ); } const char * -tr_sessionGetConfigDir( const tr_handle * handle ) +tr_sessionGetConfigDir( const tr_session * session ) { - return handle->configDir; + return session->configDir; } const char * -tr_getTorrentDir( const tr_handle * handle ) +tr_getTorrentDir( const tr_session * session ) { - return handle->torrentDir; + return session->torrentDir; } const char * -tr_getResumeDir( const tr_handle * handle ) +tr_getResumeDir( const tr_session * session ) { - return handle->resumeDir; + return session->resumeDir; } const char* diff --git a/libtransmission/platform.h b/libtransmission/platform.h index e8076c214..9a885655d 100644 --- a/libtransmission/platform.h +++ b/libtransmission/platform.h @@ -42,16 +42,14 @@ typedef struct tr_lock tr_lock; typedef struct tr_thread tr_thread; -struct tr_handle; +void tr_setConfigDir( tr_session * session, + const char * configDir ); -void tr_setConfigDir( struct tr_handle * handle, - const char * configDir ); +const char * tr_getResumeDir( const tr_session * ); -const char * tr_getResumeDir( const struct tr_handle * ); +const char * tr_getTorrentDir( const tr_session * ); -const char * tr_getTorrentDir( const struct tr_handle * ); - -const char * tr_getClutchDir( const struct tr_handle * ); +const char * tr_getClutchDir( const tr_session * ); tr_thread* tr_threadNew( void ( *func )(void *), diff --git a/libtransmission/port-forwarding.c b/libtransmission/port-forwarding.c index 0cb1adc95..27473e420 100644 --- a/libtransmission/port-forwarding.c +++ b/libtransmission/port-forwarding.c @@ -204,8 +204,8 @@ sharedPulse( void * vshared ) tr_shared * tr_sharedInit( tr_session * session, - int isEnabled, - int publicPort ) + tr_bool isEnabled, + tr_bool publicPort ) { tr_shared * s = tr_new0( tr_shared, 1 ); @@ -230,8 +230,7 @@ tr_sharedShuttingDown( tr_shared * s ) } void -tr_sharedSetPort( tr_shared * s, - int port ) +tr_sharedSetPort( tr_shared * s, tr_port port ) { tr_torrent * tor = NULL; @@ -241,20 +240,19 @@ tr_sharedSetPort( tr_shared * s, tr_torrentChangeMyPort( tor ); } -int +tr_port tr_sharedGetPeerPort( const tr_shared * s ) { return s->publicPort; } void -tr_sharedTraversalEnable( tr_shared * s, - int isEnabled ) +tr_sharedTraversalEnable( tr_shared * s, tr_bool isEnabled ) { s->isEnabled = isEnabled; } -int +tr_bool tr_sharedTraversalIsEnabled( const tr_shared * s ) { return s->isEnabled; diff --git a/libtransmission/port-forwarding.h b/libtransmission/port-forwarding.h index 19d698d37..72f369d85 100644 --- a/libtransmission/port-forwarding.h +++ b/libtransmission/port-forwarding.h @@ -33,21 +33,17 @@ typedef struct tr_shared tr_shared; -tr_shared* tr_sharedInit( tr_handle *, - int isEnabled, - int publicPort ); +tr_shared* tr_sharedInit( tr_session*, tr_bool isEnabled, tr_bool publicPort ); void tr_sharedShuttingDown( tr_shared * ); -void tr_sharedSetPort( tr_shared *, - int publicPort ); +void tr_sharedSetPort( tr_shared *, tr_port publicPort ); -void tr_sharedTraversalEnable( tr_shared *, - int isEnabled ); +void tr_sharedTraversalEnable( tr_shared *, tr_bool isEnabled ); -int tr_sharedGetPeerPort( const tr_shared * s ); +tr_port tr_sharedGetPeerPort( const tr_shared * s ); -int tr_sharedTraversalIsEnabled( const tr_shared * s ); +tr_bool tr_sharedTraversalIsEnabled( const tr_shared * s ); int tr_sharedTraversalStatus( const tr_shared * ); diff --git a/libtransmission/rpc-server.c b/libtransmission/rpc-server.c index 20d2f33ff..35449ad2b 100644 --- a/libtransmission/rpc-server.c +++ b/libtransmission/rpc-server.c @@ -52,7 +52,7 @@ struct tr_rpc_server tr_bool isWhitelistEnabled; tr_port port; struct evhttp * httpd; - tr_handle * session; + tr_session * session; char * username; char * password; char * whitelist; @@ -682,14 +682,14 @@ tr_rpcClose( tr_rpc_server ** ps ) } tr_rpc_server * -tr_rpcInit( tr_handle * session, - tr_bool isEnabled, - tr_port port, - tr_bool isWhitelistEnabled, - const char * whitelist, - tr_bool isPasswordEnabled, - const char * username, - const char * password ) +tr_rpcInit( tr_session * session, + tr_bool isEnabled, + tr_port port, + tr_bool isWhitelistEnabled, + const char * whitelist, + tr_bool isPasswordEnabled, + const char * username, + const char * password ) { tr_rpc_server * s; diff --git a/libtransmission/rpc-server.h b/libtransmission/rpc-server.h index 3156a3500..860d22650 100644 --- a/libtransmission/rpc-server.h +++ b/libtransmission/rpc-server.h @@ -19,14 +19,14 @@ typedef struct tr_rpc_server tr_rpc_server; -tr_rpc_server * tr_rpcInit( struct tr_handle * session, - tr_bool isEnabled, - tr_port port, - tr_bool isWhitelistEnabled, - const char * whitelist, - tr_bool isPasswordEnabled, - const char * username, - const char * password ); +tr_rpc_server * tr_rpcInit( tr_session * session, + tr_bool isEnabled, + tr_port port, + tr_bool isWhitelistEnabled, + const char * whitelist, + tr_bool isPasswordEnabled, + const char * username, + const char * password ); void tr_rpcClose( tr_rpc_server ** freeme ); diff --git a/libtransmission/rpcimpl.c b/libtransmission/rpcimpl.c index b8be07cb7..833317a6a 100644 --- a/libtransmission/rpcimpl.c +++ b/libtransmission/rpcimpl.c @@ -30,7 +30,7 @@ ***/ static tr_rpc_callback_status -notify( tr_handle * session, +notify( tr_session * session, int type, tr_torrent * tor ) { @@ -48,9 +48,9 @@ notify( tr_handle * session, ***/ static tr_torrent ** -getTorrents( tr_handle * handle, - tr_benc * args, - int * setmeCount ) +getTorrents( tr_session * session, + tr_benc * args, + int * setmeCount ) { int torrentCount = 0; int64_t id; @@ -71,9 +71,9 @@ getTorrents( tr_handle * handle, int64_t id; const char * str; if( tr_bencGetInt( node, &id ) ) - tor = tr_torrentFindFromId( handle, id ); + tor = tr_torrentFindFromId( session, id ); else if( tr_bencGetStr( node, &str ) ) - tor = tr_torrentFindFromHashString( handle, str ); + tor = tr_torrentFindFromHashString( session, str ); if( tor ) torrents[torrentCount++] = tor; } @@ -83,15 +83,15 @@ getTorrents( tr_handle * handle, { tr_torrent * tor; torrents = tr_new0( tr_torrent *, 1 ); - if( ( tor = tr_torrentFindFromId( handle, id ) ) ) + if( ( tor = tr_torrentFindFromId( session, id ) ) ) torrents[torrentCount++] = tor; } else /* all of them */ { tr_torrent * tor = NULL; - const int n = tr_sessionCountTorrents( handle ); + const int n = tr_sessionCountTorrents( session ); torrents = tr_new0( tr_torrent *, n ); - while( ( tor = tr_torrentNext( handle, tor ) ) ) + while( ( tor = tr_torrentNext( session, tor ) ) ) torrents[torrentCount++] = tor; } @@ -100,78 +100,80 @@ getTorrents( tr_handle * handle, } static const char* -torrentStart( tr_handle * h, - tr_benc * args_in, - tr_benc * args_out UNUSED ) +torrentStart( tr_session * session, + tr_benc * args_in, + tr_benc * args_out UNUSED ) { int i, torrentCount; - tr_torrent ** torrents = getTorrents( h, args_in, &torrentCount ); + tr_torrent ** torrents = getTorrents( session, args_in, &torrentCount ); for( i = 0; i < torrentCount; ++i ) { tr_torrent * tor = torrents[i]; tr_torrentStart( tor ); - notify( h, TR_RPC_TORRENT_STARTED, tor ); + notify( session, TR_RPC_TORRENT_STARTED, tor ); } tr_free( torrents ); return NULL; } static const char* -torrentStop( tr_handle * h, - tr_benc * args_in, - tr_benc * args_out UNUSED ) +torrentStop( tr_session * session, + tr_benc * args_in, + tr_benc * args_out UNUSED ) { int i, torrentCount; - tr_torrent ** torrents = getTorrents( h, args_in, &torrentCount ); + tr_torrent ** torrents = getTorrents( session, args_in, &torrentCount ); for( i = 0; i < torrentCount; ++i ) { tr_torrent * tor = torrents[i]; tr_torrentStop( tor ); - notify( h, TR_RPC_TORRENT_STOPPED, tor ); + notify( session, TR_RPC_TORRENT_STOPPED, tor ); } tr_free( torrents ); return NULL; } static const char* -torrentRemove( tr_handle * h, +torrentRemove( tr_session * session, tr_benc * args_in, tr_benc * args_out UNUSED ) { int i; int torrentCount; - tr_torrent ** torrents = getTorrents( h, args_in, &torrentCount ); + tr_torrent ** torrents = getTorrents( session, args_in, &torrentCount ); for( i=0; iisRunning ) ++running; } + d = tr_bencDictAddDict( args_out, "session-stats", 5 ); tr_bencDictAddInt( d, "activeTorrentCount", running ); - tr_bencDictAddInt( d, "downloadSpeed", (int)( tr_sessionGetPieceSpeed( h, TR_DOWN ) * 1024 ) ); + tr_bencDictAddInt( d, "downloadSpeed", (int)( tr_sessionGetPieceSpeed( session, TR_DOWN ) * 1024 ) ); tr_bencDictAddInt( d, "pausedTorrentCount", total - running ); tr_bencDictAddInt( d, "torrentCount", total ); - tr_bencDictAddInt( d, "uploadSpeed", (int)( tr_sessionGetPieceSpeed( h, TR_UP ) * 1024 ) ); + tr_bencDictAddInt( d, "uploadSpeed", (int)( tr_sessionGetPieceSpeed( session, TR_UP ) * 1024 ) ); return NULL; } static const char* -sessionGet( tr_handle * h, - tr_benc * args_in UNUSED, - tr_benc * args_out ) +sessionGet( tr_session * session, + tr_benc * args_in UNUSED, + tr_benc * args_out ) { const char * str; tr_benc * d = args_out; - tr_bencDictAddStr( d, "download-dir", - tr_sessionGetDownloadDir( h ) ); - tr_bencDictAddInt( d, "peer-limit", - tr_sessionGetPeerLimit( h ) ); - tr_bencDictAddInt( d, "pex-allowed", - tr_sessionIsPexEnabled( h ) ); - tr_bencDictAddInt( d, "port", - tr_sessionGetPeerPort( h ) ); - tr_bencDictAddInt( d, "port-forwarding-enabled", - tr_sessionIsPortForwardingEnabled( h ) ); - tr_bencDictAddInt( d, "speed-limit-up", - tr_sessionGetSpeedLimit( h, TR_UP ) ); - tr_bencDictAddInt( d, "speed-limit-up-enabled", - tr_sessionIsSpeedLimitEnabled( h, TR_UP ) ); - tr_bencDictAddInt( d, "speed-limit-down", - tr_sessionGetSpeedLimit( h, TR_DOWN ) ); - tr_bencDictAddInt( d, "speed-limit-down-enabled", - tr_sessionIsSpeedLimitEnabled( h, TR_DOWN ) ); + tr_bencDictAddStr( d, "download-dir", tr_sessionGetDownloadDir( session ) ); + tr_bencDictAddInt( d, "peer-limit", tr_sessionGetPeerLimit( session ) ); + tr_bencDictAddInt( d, "pex-allowed", tr_sessionIsPexEnabled( session ) ); + tr_bencDictAddInt( d, "port", tr_sessionGetPeerPort( session ) ); + tr_bencDictAddInt( d, "port-forwarding-enabled", tr_sessionIsPortForwardingEnabled( session ) ); + tr_bencDictAddInt( d, "speed-limit-up", tr_sessionGetSpeedLimit( session, TR_UP ) ); + tr_bencDictAddInt( d, "speed-limit-up-enabled", tr_sessionIsSpeedLimitEnabled( session, TR_UP ) ); + tr_bencDictAddInt( d, "speed-limit-down", tr_sessionGetSpeedLimit( session, TR_DOWN ) ); + tr_bencDictAddInt( d, "speed-limit-down-enabled", tr_sessionIsSpeedLimitEnabled( session, TR_DOWN ) ); tr_bencDictAddStr( d, "version", LONG_VERSION_STRING ); - switch( tr_sessionGetEncryption( h ) ) - { - case TR_CLEAR_PREFERRED: - str = "tolerated"; break; - - case TR_ENCRYPTION_REQUIRED: - str = "required"; break; - - default: - str = "preferred"; break; + switch( tr_sessionGetEncryption( session ) ) { + case TR_CLEAR_PREFERRED: str = "tolerated"; break; + case TR_ENCRYPTION_REQUIRED: str = "required"; break; + default: str = "preferred"; break; } tr_bencDictAddStr( d, "encryption", str ); @@ -753,7 +742,7 @@ sessionGet( tr_handle * h, **** ***/ -typedef const char* ( handler )( tr_handle*, tr_benc*, tr_benc* ); +typedef const char* ( handler )( tr_session*, tr_benc*, tr_benc* ); static struct method { @@ -773,9 +762,9 @@ static struct method }; static char* -request_exec( struct tr_handle * handle, - tr_benc * request, - int * response_len ) +request_exec( tr_session * session, + tr_benc * request, + int * response_len ) { int64_t i; const char * str; @@ -800,7 +789,7 @@ request_exec( struct tr_handle * handle, break; result = i == n ? "method name not recognized" - : ( *methods[i].func )( handle, args_in, args_out ); + : ( *methods[i].func )( session, args_in, args_out ); } /* serialize & return the response */ @@ -815,10 +804,10 @@ request_exec( struct tr_handle * handle, } char* -tr_rpc_request_exec_json( struct tr_handle * handle, - const void * request_json, - int request_len, - int * response_len ) +tr_rpc_request_exec_json( tr_session * session, + const void * request_json, + int request_len, + int * response_len ) { tr_benc top; int have_content; @@ -828,7 +817,7 @@ tr_rpc_request_exec_json( struct tr_handle * handle, request_len = strlen( request_json ); have_content = !tr_jsonParse( request_json, request_len, &top, NULL ); - ret = request_exec( handle, have_content ? &top : NULL, response_len ); + ret = request_exec( session, have_content ? &top : NULL, response_len ); if( have_content ) tr_bencFree( &top ); @@ -915,10 +904,10 @@ tr_rpc_parse_list_str( tr_benc * setme, } char* -tr_rpc_request_exec_uri( struct tr_handle * handle, - const void * request_uri, - int request_len, - int * response_len ) +tr_rpc_request_exec_uri( tr_session * session, + const void * request_uri, + int request_len, + int * response_len ) { char * ret = NULL; tr_benc top, * args; @@ -949,7 +938,7 @@ tr_rpc_request_exec_uri( struct tr_handle * handle, pch = next ? next + 1 : NULL; } - ret = request_exec( handle, &top, response_len ); + ret = request_exec( session, &top, response_len ); /* cleanup */ tr_bencFree( &top ); diff --git a/libtransmission/rpcimpl.h b/libtransmission/rpcimpl.h index 97e9e8cf6..3619975fd 100644 --- a/libtransmission/rpcimpl.h +++ b/libtransmission/rpcimpl.h @@ -18,22 +18,21 @@ ***/ struct tr_benc; -struct tr_handle; /* http://www.json.org/ */ -char*tr_rpc_request_exec_json( struct tr_handle * handle, - const void * request_json, - int request_len, - int * response_len ); +char*tr_rpc_request_exec_json( tr_session * session, + const void * request_json, + int request_len, + int * response_len ); /* see the RPC spec's "Request URI Notation" section */ -char*tr_rpc_request_exec_uri( struct tr_handle * handle, - const void * request_uri, - int request_len, - int * response_len ); +char*tr_rpc_request_exec_uri( tr_session * session, + const void * request_uri, + int request_len, + int * response_len ); void tr_rpc_parse_list_str( struct tr_benc * setme, - const char * list_str, + const char * list_str, size_t list_str_len ); diff --git a/libtransmission/session.c b/libtransmission/session.c index e4e2c51ed..b14e87485 100644 --- a/libtransmission/session.c +++ b/libtransmission/session.c @@ -343,7 +343,7 @@ tr_sessionSaveSettings( tr_session * session, const char * configDir, tr_benc * tr_free( filename ); } -static void metainfoLookupRescan( tr_handle * h ); +static void metainfoLookupRescan( tr_session * ); tr_session * tr_sessionInit( const char * tag, @@ -532,20 +532,19 @@ tr_sessionInit( const char * tag, ***/ void -tr_sessionSetDownloadDir( tr_handle * handle, - const char * dir ) +tr_sessionSetDownloadDir( tr_session * session, const char * dir ) { - if( handle->downloadDir != dir ) + if( session->downloadDir != dir ) { - tr_free( handle->downloadDir ); - handle->downloadDir = tr_strdup( dir ); + tr_free( session->downloadDir ); + session->downloadDir = tr_strdup( dir ); } } const char * -tr_sessionGetDownloadDir( const tr_handle * handle ) +tr_sessionGetDownloadDir( const tr_session * session ) { - return handle->downloadDir; + return session->downloadDir; } /*** @@ -553,21 +552,21 @@ tr_sessionGetDownloadDir( const tr_handle * handle ) ***/ void -tr_globalLock( struct tr_handle * handle ) +tr_globalLock( tr_session * session ) { - tr_lockLock( handle->lock ); + tr_lockLock( session->lock ); } void -tr_globalUnlock( struct tr_handle * handle ) +tr_globalUnlock( tr_session * session ) { - tr_lockUnlock( handle->lock ); + tr_lockUnlock( session->lock ); } tr_bool -tr_globalIsLocked( const struct tr_handle * handle ) +tr_globalIsLocked( const tr_session * session ) { - return handle && tr_lockHave( handle->lock ); + return session && tr_lockHave( session->lock ); } /*********************************************************************** @@ -631,9 +630,9 @@ tr_sessionGetPeerPort( const tr_session * session ) } tr_port_forwarding -tr_sessionGetPortForwarding( const tr_handle * h ) +tr_sessionGetPortForwarding( const tr_session * session ) { - return tr_sharedTraversalStatus( h->shared ); + return tr_sharedTraversalStatus( session->shared ); } /*** @@ -699,8 +698,8 @@ tr_sessionGetSpeedLimit( const tr_session * session, ***/ void -tr_sessionSetPeerLimit( tr_handle * handle UNUSED, - uint16_t maxGlobalPeers ) +tr_sessionSetPeerLimit( tr_session * session UNUSED, + uint16_t maxGlobalPeers ) { tr_fdSetPeerLimit( maxGlobalPeers ); } @@ -728,14 +727,13 @@ tr_sessionGetRawSpeed( const tr_session * session, tr_direction dir ) } int -tr_sessionCountTorrents( const tr_handle * h ) +tr_sessionCountTorrents( const tr_session * session ) { - return h->torrentCount; + return session->torrentCount; } static int -compareTorrentByCur( const void * va, - const void * vb ) +compareTorrentByCur( const void * va, const void * vb ) { const tr_torrent * a = *(const tr_torrent**)va; const tr_torrent * b = *(const tr_torrent**)vb; @@ -751,7 +749,7 @@ compareTorrentByCur( const void * va, static void tr_closeAllConnections( void * vsession ) { - tr_handle * session = vsession; + tr_session * session = vsession; tr_torrent * tor; int i, n; tr_torrent ** torrents; @@ -798,7 +796,7 @@ deadlineReached( const uint64_t deadline ) } while( 0 ) void -tr_sessionClose( tr_handle * session ) +tr_sessionClose( tr_session * session ) { int i; const int maxwait_msec = SHUTDOWN_MAX_SECONDS * 1000; @@ -855,14 +853,14 @@ tr_sessionClose( tr_handle * session ) } tr_torrent ** -tr_sessionLoadTorrents( tr_handle * h, - tr_ctor * ctor, - int * setmeCount ) +tr_sessionLoadTorrents( tr_session * session, + tr_ctor * ctor, + int * setmeCount ) { int i, n = 0; struct stat sb; DIR * odir = NULL; - const char * dirname = tr_getTorrentDir( h ); + const char * dirname = tr_getTorrentDir( session ); tr_torrent ** torrents; tr_list * l = NULL, *list = NULL; @@ -881,7 +879,7 @@ tr_sessionLoadTorrents( tr_handle * h, tr_torrent * tor; char * path = tr_buildPath( dirname, d->d_name, NULL ); tr_ctorSetMetainfoFromFile( ctor, path ); - if(( tor = tr_torrentNew( h, ctor, NULL ))) + if(( tor = tr_torrentNew( session, ctor, NULL ))) { tr_list_append( &list, tor ); ++n; @@ -955,9 +953,9 @@ tr_sessionSetPortForwardingEnabled( tr_session * session, } tr_bool -tr_sessionIsPortForwardingEnabled( const tr_handle * h ) +tr_sessionIsPortForwardingEnabled( const tr_session * session ) { - return tr_sharedTraversalIsEnabled( h->shared ); + return tr_sharedTraversalIsEnabled( session->shared ); } /*** @@ -1050,10 +1048,10 @@ compareLookupEntries( const void * va, } static void -metainfoLookupResort( tr_handle * h ) +metainfoLookupResort( tr_session * session ) { - qsort( h->metainfoLookup, - h->metainfoLookupCount, + qsort( session->metainfoLookup, + session->metainfoLookupCount, sizeof( struct tr_metainfo_lookup ), compareLookupEntries ); } @@ -1069,36 +1067,33 @@ compareHashStringToLookupEntry( const void * va, } const char* -tr_sessionFindTorrentFile( const tr_handle * h, - const char * hashStr ) +tr_sessionFindTorrentFile( const tr_session * session, + const char * hashStr ) { struct tr_metainfo_lookup * l = bsearch( hashStr, - h->metainfoLookup, - h->metainfoLookupCount, - sizeof( struct - tr_metainfo_lookup ), + session->metainfoLookup, + session->metainfoLookupCount, + sizeof( struct tr_metainfo_lookup ), compareHashStringToLookupEntry ); return l ? l->filename : NULL; } static void -metainfoLookupRescan( tr_handle * h ) +metainfoLookupRescan( tr_session * session ) { int i; int n; struct stat sb; - const char * dirname = tr_getTorrentDir( h ); + const char * dirname = tr_getTorrentDir( session ); DIR * odir = NULL; tr_ctor * ctor = NULL; tr_list * list = NULL; /* walk through the directory and find the mappings */ - ctor = tr_ctorNew( h ); + ctor = tr_ctorNew( session ); tr_ctorSetSave( ctor, FALSE ); /* since we already have them */ - if( !stat( dirname, - &sb ) && S_ISDIR( sb.st_mode ) - && ( ( odir = opendir( dirname ) ) ) ) + if( !stat( dirname, &sb ) && S_ISDIR( sb.st_mode ) && ( ( odir = opendir( dirname ) ) ) ) { struct dirent *d; for( d = readdir( odir ); d != NULL; d = readdir( odir ) ) @@ -1109,7 +1104,7 @@ metainfoLookupRescan( tr_handle * h ) tr_info inf; char * path = tr_buildPath( dirname, d->d_name, NULL ); tr_ctorSetMetainfoFromFile( ctor, path ); - if( !tr_torrentParse( h, ctor, &inf ) ) + if( !tr_torrentParse( session, ctor, &inf ) ) { tr_list_append( &list, tr_strdup( inf.hashString ) ); tr_list_append( &list, tr_strdup( path ) ); @@ -1123,33 +1118,32 @@ metainfoLookupRescan( tr_handle * h ) tr_ctorFree( ctor ); n = tr_list_size( list ) / 2; - h->metainfoLookup = tr_new0( struct tr_metainfo_lookup, n ); - h->metainfoLookupCount = n; + session->metainfoLookup = tr_new0( struct tr_metainfo_lookup, n ); + session->metainfoLookupCount = n; for( i = 0; i < n; ++i ) { char * hashString = tr_list_pop_front( &list ); char * filename = tr_list_pop_front( &list ); - memcpy( h->metainfoLookup[i].hashString, hashString, + memcpy( session->metainfoLookup[i].hashString, hashString, 2 * SHA_DIGEST_LENGTH + 1 ); tr_free( hashString ); - h->metainfoLookup[i].filename = filename; + session->metainfoLookup[i].filename = filename; } - metainfoLookupResort( h ); + metainfoLookupResort( session ); tr_dbg( "Found %d torrents in \"%s\"", n, dirname ); } void -tr_sessionSetTorrentFile( tr_handle * h, +tr_sessionSetTorrentFile( tr_session * session, const char * hashString, const char * filename ) { struct tr_metainfo_lookup * l = bsearch( hashString, - h->metainfoLookup, - h->metainfoLookupCount, - sizeof( struct - tr_metainfo_lookup ), + session->metainfoLookup, + session->metainfoLookupCount, + sizeof( struct tr_metainfo_lookup ), compareHashStringToLookupEntry ); if( l ) @@ -1162,20 +1156,20 @@ tr_sessionSetTorrentFile( tr_handle * h, } else { - const int n = h->metainfoLookupCount++; + const int n = session->metainfoLookupCount++; struct tr_metainfo_lookup * node; - h->metainfoLookup = tr_renew( struct tr_metainfo_lookup, - h->metainfoLookup, - h->metainfoLookupCount ); - node = h->metainfoLookup + n; + session->metainfoLookup = tr_renew( struct tr_metainfo_lookup, + session->metainfoLookup, + session->metainfoLookupCount ); + node = session->metainfoLookup + n; memcpy( node->hashString, hashString, 2 * SHA_DIGEST_LENGTH + 1 ); node->filename = tr_strdup( filename ); - metainfoLookupResort( h ); + metainfoLookupResort( session ); } } tr_torrent* -tr_torrentNext( tr_handle * session, +tr_torrentNext( tr_session * session, tr_torrent * tor ) { return tor ? tor->next : session->torrentList; diff --git a/libtransmission/stats.c b/libtransmission/stats.c index 5abaed06a..8981404b3 100644 --- a/libtransmission/stats.c +++ b/libtransmission/stats.c @@ -30,32 +30,32 @@ struct tr_stats_handle }; static char* -getOldFilename( const tr_handle * handle ) +getOldFilename( const tr_session * session ) { - return tr_buildPath( tr_sessionGetConfigDir( handle ), "stats.benc", NULL ); + return tr_buildPath( tr_sessionGetConfigDir( session ), "stats.benc", NULL ); } static char* -getFilename( const tr_handle * handle ) +getFilename( const tr_session * session ) { - return tr_buildPath( tr_sessionGetConfigDir( handle ), "stats.json", NULL ); + return tr_buildPath( tr_sessionGetConfigDir( session ), "stats.json", NULL ); } static void -loadCumulativeStats( const tr_handle * handle, +loadCumulativeStats( const tr_session * session, tr_session_stats * setme ) { int loaded = FALSE; char * filename; tr_benc top; - filename = getFilename( handle ); + filename = getFilename( session ); loaded = !tr_bencLoadJSONFile( filename, &top ); tr_free( filename ); if( !loaded ) { - filename = getOldFilename( handle ); + filename = getOldFilename( session ); loaded = !tr_bencLoadFile( filename, &top ); tr_free( filename ); } @@ -80,7 +80,7 @@ loadCumulativeStats( const tr_handle * handle, } static void -saveCumulativeStats( const tr_handle * handle, +saveCumulativeStats( const tr_session * session, const tr_session_stats * s ) { char * filename; @@ -93,7 +93,7 @@ saveCumulativeStats( const tr_handle * handle, tr_bencDictAddInt( &top, "session-count", s->sessionCount ); tr_bencDictAddInt( &top, "uploaded-bytes", s->uploadedBytes ); - filename = getFilename( handle ); + filename = getFilename( session ); tr_deepLog( __FILE__, __LINE__, NULL, "Saving stats to \"%s\"", filename ); tr_bencSaveJSONFile( filename, &top ); @@ -106,32 +106,32 @@ saveCumulativeStats( const tr_handle * handle, ***/ void -tr_statsInit( tr_handle * handle ) +tr_statsInit( tr_session * session ) { struct tr_stats_handle * stats = tr_new0( struct tr_stats_handle, 1 ); - loadCumulativeStats( handle, &stats->old ); + loadCumulativeStats( session, &stats->old ); stats->single.sessionCount = 1; stats->startTime = time( NULL ); - handle->sessionStats = stats; + session->sessionStats = stats; } void -tr_statsClose( tr_handle * handle ) +tr_statsClose( tr_session * session ) { tr_session_stats cumulative = STATS_INIT; - tr_sessionGetCumulativeStats( handle, &cumulative ); - saveCumulativeStats( handle, &cumulative ); + tr_sessionGetCumulativeStats( session, &cumulative ); + saveCumulativeStats( session, &cumulative ); - tr_free( handle->sessionStats ); - handle->sessionStats = NULL; + tr_free( session->sessionStats ); + session->sessionStats = NULL; } static struct tr_stats_handle * -getStats( const tr_handle * handle ) +getStats( const tr_session * session ) { - return handle ? handle->sessionStats : NULL; + return session ? session->sessionStats : NULL; } /*** @@ -159,10 +159,10 @@ addStats( tr_session_stats * setme, } void -tr_sessionGetStats( const tr_handle * handle, +tr_sessionGetStats( const tr_session * session, tr_session_stats * setme ) { - const struct tr_stats_handle * stats = getStats( handle ); + const struct tr_stats_handle * stats = getStats( session ); if( stats ) { *setme = stats->single; @@ -172,21 +172,21 @@ tr_sessionGetStats( const tr_handle * handle, } void -tr_sessionGetCumulativeStats( const tr_handle * handle, +tr_sessionGetCumulativeStats( const tr_session * session, tr_session_stats * setme ) { - const struct tr_stats_handle * stats = getStats( handle ); + const struct tr_stats_handle * stats = getStats( session ); tr_session_stats current = STATS_INIT; if( stats ) { - tr_sessionGetStats( handle, ¤t ); + tr_sessionGetStats( session, ¤t ); addStats( setme, &stats->old, ¤t ); } } void -tr_sessionClearStats( tr_handle * handle ) +tr_sessionClearStats( tr_session * session ) { tr_session_stats zero; @@ -196,9 +196,9 @@ tr_sessionClearStats( tr_handle * handle ) zero.filesAdded = 0; zero.sessionCount = 0; zero.secondsActive = 0; - handle->sessionStats->single = handle->sessionStats->old = zero; - handle->sessionStats->startTime = time( NULL ); + session->sessionStats->single = session->sessionStats->old = zero; + session->sessionStats->startTime = time( NULL ); } /** @@ -206,31 +206,31 @@ tr_sessionClearStats( tr_handle * handle ) **/ void -tr_statsAddUploaded( tr_handle * handle, +tr_statsAddUploaded( tr_session * session, uint32_t bytes ) { struct tr_stats_handle * s; - if( ( s = getStats( handle ) ) ) + if( ( s = getStats( session ) ) ) s->single.uploadedBytes += bytes; } void -tr_statsAddDownloaded( tr_handle * handle, - uint32_t bytes ) +tr_statsAddDownloaded( tr_session * session, + uint32_t bytes ) { struct tr_stats_handle * s; - if( ( s = getStats( handle ) ) ) + if( ( s = getStats( session ) ) ) s->single.downloadedBytes += bytes; } void -tr_statsFileCreated( tr_handle * handle ) +tr_statsFileCreated( tr_session * session ) { struct tr_stats_handle * s; - if( ( s = getStats( handle ) ) ) + if( ( s = getStats( session ) ) ) s->single.filesAdded++; } diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index ed1ee0a4e..b3bd7e490 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -60,12 +60,11 @@ tr_torrentId( const tr_torrent * tor ) } tr_torrent* -tr_torrentFindFromId( tr_handle * handle, - int id ) +tr_torrentFindFromId( tr_session * session, int id ) { tr_torrent * tor = NULL; - while( ( tor = tr_torrentNext( handle, tor ) ) ) + while( ( tor = tr_torrentNext( session, tor ) ) ) if( tor->uniqueId == id ) return tor; @@ -73,12 +72,11 @@ tr_torrentFindFromId( tr_handle * handle, } tr_torrent* -tr_torrentFindFromHashString( tr_handle * handle, - const char * str ) +tr_torrentFindFromHashString( tr_session * session, const char * str ) { tr_torrent * tor = NULL; - while( ( tor = tr_torrentNext( handle, tor ) ) ) + while( ( tor = tr_torrentNext( session, tor ) ) ) if( !strcmp( str, tor->info.hashString ) ) return tor; @@ -86,20 +84,17 @@ tr_torrentFindFromHashString( tr_handle * handle, } tr_bool -tr_torrentExists( const tr_handle * handle, - const uint8_t * torrentHash ) +tr_torrentExists( const tr_session * session, const uint8_t * torrentHash ) { - return tr_torrentFindFromHash( (tr_handle*)handle, - torrentHash ) != NULL; + return tr_torrentFindFromHash( (tr_session*)session, torrentHash ) != NULL; } tr_torrent* -tr_torrentFindFromHash( tr_handle * handle, - const uint8_t * torrentHash ) +tr_torrentFindFromHash( tr_session * session, const uint8_t * torrentHash ) { tr_torrent * tor = NULL; - while( ( tor = tr_torrentNext( handle, tor ) ) ) + while( ( tor = tr_torrentNext( session, tor ) ) ) if( *tor->info.hash == *torrentHash ) if( !memcmp( tor->info.hash, torrentHash, SHA_DIGEST_LENGTH ) ) return tor; @@ -108,12 +103,12 @@ tr_torrentFindFromHash( tr_handle * handle, } tr_torrent* -tr_torrentFindFromObfuscatedHash( tr_handle * handle, +tr_torrentFindFromObfuscatedHash( tr_session * session, const uint8_t * obfuscatedTorrentHash ) { tr_torrent * tor = NULL; - while( ( tor = tr_torrentNext( handle, tor ) ) ) + while( ( tor = tr_torrentNext( session, tor ) ) ) if( !memcmp( tor->obfuscatedHash, obfuscatedTorrentHash, SHA_DIGEST_LENGTH ) ) return tor; @@ -466,9 +461,9 @@ getBlockSize( uint32_t pieceSize ) } static void -torrentRealInit( tr_handle * h, - tr_torrent * tor, - const tr_ctor * ctor ) +torrentRealInit( tr_session * session, + tr_torrent * tor, + const tr_ctor * ctor ) { int doStart; uint64_t loaded; @@ -476,14 +471,14 @@ torrentRealInit( tr_handle * h, tr_info * info = &tor->info; static int nextUniqueId = 1; - tr_globalLock( h ); + tr_globalLock( session ); - tor->session = h; + tor->session = session; tor->uniqueId = nextUniqueId++; randomizeTiers( info ); - tor->bandwidth = tr_bandwidthNew( h, h->bandwidth ); + tor->bandwidth = tr_bandwidthNew( session, session->bandwidth ); tor->blockSize = getBlockSize( info->pieceSize ); @@ -531,10 +526,9 @@ torrentRealInit( tr_handle * h, info->hash, SHA_DIGEST_LENGTH, NULL ); - tr_peerMgrAddTorrent( h->peerMgr, tor ); - - assert( h->isPortSet ); + tr_peerMgrAddTorrent( session->peerMgr, tor ); + assert( session->isPortSet ); assert( !tor->downloadedCur ); assert( !tor->uploadedCur ); @@ -569,17 +563,17 @@ torrentRealInit( tr_handle * h, { tr_torrent * it = NULL; tr_torrent * last = NULL; - while( ( it = tr_torrentNext( h, it ) ) ) + while( ( it = tr_torrentNext( session, it ) ) ) last = it; if( !last ) - h->torrentList = tor; + session->torrentList = tor; else last->next = tor; - ++h->torrentCount; + ++session->torrentCount; } - tr_globalUnlock( h ); + tr_globalUnlock( session ); /* maybe save our own copy of the metainfo */ if( tr_ctorGetSave( ctor ) ) @@ -594,16 +588,16 @@ torrentRealInit( tr_handle * h, } } - tr_metainfoMigrate( h, &tor->info ); + tr_metainfoMigrate( session, &tor->info ); if( doStart ) torrentStart( tor, FALSE ); } int -tr_torrentParse( const tr_handle * handle, - const tr_ctor * ctor, - tr_info * setmeInfo ) +tr_torrentParse( const tr_session * session, + const tr_ctor * ctor, + tr_info * setmeInfo ) { int err = 0; int doFree; @@ -617,13 +611,13 @@ tr_torrentParse( const tr_handle * handle, if( !err && tr_ctorGetMetainfo( ctor, &metainfo ) ) return TR_EINVALID; - err = tr_metainfoParse( handle, setmeInfo, metainfo ); + err = tr_metainfoParse( session, setmeInfo, metainfo ); doFree = !err && ( setmeInfo == &tmp ); if( !err && !getBlockSize( setmeInfo->pieceSize ) ) err = TR_EINVALID; - if( !err && tr_torrentExists( handle, setmeInfo->hash ) ) + if( !err && tr_torrentExists( session, setmeInfo->hash ) ) err = TR_EDUPLICATE; if( doFree ) @@ -633,20 +627,20 @@ tr_torrentParse( const tr_handle * handle, } tr_torrent * -tr_torrentNew( tr_handle * handle, - const tr_ctor * ctor, - int * setmeError ) +tr_torrentNew( tr_session * session, + const tr_ctor * ctor, + int * setmeError ) { int err; tr_info tmpInfo; tr_torrent * tor = NULL; - err = tr_torrentParse( handle, ctor, &tmpInfo ); + err = tr_torrentParse( session, ctor, &tmpInfo ); if( !err ) { tor = tr_new0( tr_torrent, 1 ); tor->info = tmpInfo; - torrentRealInit( handle, tor, ctor ); + torrentRealInit( session, tor, ctor ); } else if( setmeError ) { @@ -1048,15 +1042,15 @@ static void freeTorrent( tr_torrent * tor ) { tr_torrent * t; - tr_handle * h = tor->session; + tr_session * session = tor->session; tr_info * inf = &tor->info; assert( tor ); assert( !tor->isRunning ); - tr_globalLock( h ); + tr_globalLock( session ); - tr_peerMgrRemoveTorrent( h->peerMgr, tor->info.hash ); + tr_peerMgrRemoveTorrent( session->peerMgr, tor->info.hash ); tr_cpClose( tor->completion ); @@ -1071,26 +1065,24 @@ freeTorrent( tr_torrent * tor ) tr_free( tor->downloadDir ); tr_free( tor->peer_id ); - if( tor == h->torrentList ) - h->torrentList = tor->next; - else for( t = h->torrentList; t != NULL; t = t->next ) - { - if( t->next == tor ) - { - t->next = tor->next; - break; - } + if( tor == session->torrentList ) + session->torrentList = tor->next; + else for( t = session->torrentList; t != NULL; t = t->next ) { + if( t->next == tor ) { + t->next = tor->next; + break; } + } - assert( h->torrentCount >= 1 ); - h->torrentCount--; + assert( session->torrentCount >= 1 ); + session->torrentCount--; tr_bandwidthFree( tor->bandwidth ); tr_metainfoFree( inf ); tr_free( tor ); - tr_globalUnlock( h ); + tr_globalUnlock( session ); } /** @@ -1248,13 +1240,13 @@ tr_torrentFree( tr_torrent * tor ) { if( tor ) { - tr_handle * handle = tor->session; - tr_globalLock( handle ); + tr_session * session = tor->session; + tr_globalLock( session ); tr_torrentClearCompletenessCallback( tor ); - tr_runInEventThread( handle, closeTorrent, tor ); + tr_runInEventThread( session, closeTorrent, tor ); - tr_globalUnlock( handle ); + tr_globalUnlock( session ); } } diff --git a/libtransmission/tracker.h b/libtransmission/tracker.h index 93bccfdcd..f40b78322 100644 --- a/libtransmission/tracker.h +++ b/libtransmission/tracker.h @@ -31,7 +31,7 @@ tr_tracker * tr_trackerNew( const tr_torrent * ); void tr_trackerFree( tr_tracker * ); -void tr_trackerSessionClose( tr_handle * ); +void tr_trackerSessionClose( tr_session * ); /** *** Tracker Publish / Subscribe diff --git a/libtransmission/trevent.c b/libtransmission/trevent.c index 428af7af6..8d14645a9 100644 --- a/libtransmission/trevent.c +++ b/libtransmission/trevent.c @@ -121,7 +121,7 @@ typedef struct tr_event_handle uint8_t die; int fds[2]; tr_lock * lock; - tr_handle * h; + tr_session * session; tr_thread * thread; struct event_base * base; struct event pipeEvent; @@ -217,8 +217,7 @@ readFromPipe( int fd, } static void -logFunc( int severity, - const char * message ) +logFunc( int severity, const char * message ) { if( severity >= _EVENT_LOG_ERR ) tr_err( "%s", message ); @@ -238,7 +237,7 @@ libeventThreadFunc( void * veh ) signal( SIGPIPE, SIG_IGN ); #endif - eh->h->events = eh; + eh->session->events = eh; /* listen to the pipe's read fd */ event_set( &eh->pipeEvent, eh->fds[0], EV_READ | EV_PERSIST, @@ -250,30 +249,30 @@ libeventThreadFunc( void * veh ) tr_lockFree( eh->lock ); event_base_free( eh->base ); - eh->h->events = NULL; + eh->session->events = NULL; tr_free( eh ); tr_dbg( "Closing libevent thread" ); } void -tr_eventInit( tr_handle * handle ) +tr_eventInit( tr_session * session ) { tr_event_handle * eh; eh = tr_new0( tr_event_handle, 1 ); eh->lock = tr_lockNew( ); pipe( eh->fds ); - eh->h = handle; + eh->session = session; eh->base = event_init( ); eh->thread = tr_threadNew( libeventThreadFunc, eh ); } void -tr_eventClose( tr_handle * handle ) +tr_eventClose( tr_session * session ) { - handle->events->die = TRUE; + session->events->die = TRUE; tr_deepLog( __FILE__, __LINE__, NULL, "closing trevent pipe" ); - EVUTIL_CLOSESOCKET( handle->events->fds[1] ); + EVUTIL_CLOSESOCKET( session->events->fds[1] ); } /** @@ -281,12 +280,12 @@ tr_eventClose( tr_handle * handle ) **/ int -tr_amInEventThread( struct tr_handle * handle ) +tr_amInEventThread( tr_session * session ) { - assert( handle ); - assert( handle->events ); + assert( session ); + assert( session->events ); - return tr_amInThread( handle->events->thread ); + return tr_amInThread( session->events->thread ); } /** @@ -294,9 +293,9 @@ tr_amInEventThread( struct tr_handle * handle ) **/ static void -timerCallback( int fd UNUSED, - short event UNUSED, - void * vtimer ) +timerCallback( int fd UNUSED, + short event UNUSED, + void * vtimer ) { int more; struct tr_timer * timer = vtimer; @@ -324,39 +323,39 @@ tr_timerFree( tr_timer ** ptimer ) /* destroy the timer directly or via the command queue */ if( timer && !timer->inCallback ) { - assert( tr_amInEventThread( timer->eh->h ) ); + assert( tr_amInEventThread( timer->eh->session ) ); event_del( &timer->event ); tr_free( timer ); } } tr_timer* -tr_timerNew( struct tr_handle * handle, - timer_func func, - void * user_data, - uint64_t interval_milliseconds ) +tr_timerNew( tr_session * session, + timer_func func, + void * user_data, + uint64_t interval_milliseconds ) { tr_timer * timer; - assert( handle ); - assert( handle->events ); + assert( session ); + assert( session->events ); timer = tr_new0( tr_timer, 1 ); tr_timevalMsec( interval_milliseconds, &timer->tv ); timer->func = func; timer->user_data = user_data; - timer->eh = handle->events; + timer->eh = session->events; evtimer_set( &timer->event, timerCallback, timer ); - if( tr_amInThread( handle->events->thread ) ) + if( tr_amInThread( session->events->thread ) ) { evtimer_add( &timer->event, &timer->tv ); } else { const char ch = 't'; - int fd = handle->events->fds[1]; - tr_lock * lock = handle->events->lock; + int fd = session->events->fds[1]; + tr_lock * lock = session->events->lock; tr_lockLock( lock ); pipewrite( fd, &ch, 1 ); @@ -368,22 +367,21 @@ tr_timerNew( struct tr_handle * handle, } void -tr_runInEventThread( struct tr_handle * handle, - void func( void* ), - void * user_data ) +tr_runInEventThread( tr_session * session, + void func( void* ), void * user_data ) { - assert( handle ); - assert( handle->events ); + assert( session ); + assert( session->events ); - if( tr_amInThread( handle->events->thread ) ) + if( tr_amInThread( session->events->thread ) ) { (func)( user_data ); } else { const char ch = 'r'; - int fd = handle->events->fds[1]; - tr_lock * lock = handle->events->lock; + int fd = session->events->fds[1]; + tr_lock * lock = session->events->lock; struct tr_run_data data; tr_lockLock( lock ); diff --git a/libtransmission/trevent.h b/libtransmission/trevent.h index 058c97d26..bf22951ac 100644 --- a/libtransmission/trevent.h +++ b/libtransmission/trevent.h @@ -23,11 +23,11 @@ /** **/ -void tr_eventInit( struct tr_handle * tr_handle ); +void tr_eventInit( tr_session * ); -void tr_eventClose( struct tr_handle * tr_handle ); +void tr_eventClose( tr_session * ); -struct event_base * tr_eventGetBase( struct tr_handle * tr_handle ); +struct event_base * tr_eventGetBase( tr_session * ); typedef struct tr_timer tr_timer; @@ -37,12 +37,10 @@ typedef struct tr_timer tr_timer; * The timer is freed if timer_func returns zero. * Otherwise, it's called again after the same interval. */ -tr_timer* tr_timerNew( - struct tr_handle * handle, - int func( void * user_data ), - void * user_data, - uint64_t - timeout_milliseconds ); +tr_timer* tr_timerNew( tr_session * handle, + int func( void * user_data ), + void * user_data, + uint64_t timeout_milliseconds ); /** * Frees a timer and sets the timer pointer to NULL. @@ -50,10 +48,10 @@ tr_timer* tr_timerNew( void tr_timerFree( tr_timer ** timer ); -int tr_amInEventThread( struct tr_handle * handle ); +int tr_amInEventThread( tr_session * ); -void tr_runInEventThread( struct tr_handle * handle, - void func( void* ), - void * user_data ); +void tr_runInEventThread( tr_session * session, + void func( void* ), + void * user_data ); #endif diff --git a/libtransmission/web.c b/libtransmission/web.c index 7a0505d9b..ccc19cd75 100644 --- a/libtransmission/web.c +++ b/libtransmission/web.c @@ -94,7 +94,7 @@ static void addTask( void * vtask ) { struct tr_web_task * task = vtask; - const tr_handle * session = task->session; + const tr_session * session = task->session; if( session && session->web ) { diff --git a/libtransmission/web.h b/libtransmission/web.h index 19f0b8a22..64eb50ae7 100644 --- a/libtransmission/web.h +++ b/libtransmission/web.h @@ -13,26 +13,25 @@ #ifndef TR_HTTP_H #define TR_HTTP_H -struct tr_handle; typedef struct tr_web tr_web; -tr_web* tr_webInit( struct tr_handle * session ); +tr_web* tr_webInit( tr_session * session ); void tr_webClose( tr_web ** ); -typedef void ( tr_web_done_func )( struct tr_handle * session, +typedef void ( tr_web_done_func )( tr_session * session, long response_code, - const void * response, + const void * response, size_t response_byte_count, - void * user_data ); + void * user_data ); const char * tr_webGetResponseStr( long response_code ); -void tr_webRun( struct tr_handle * session, - const char * url, - const char * range, - tr_web_done_func done_func, - void * done_func_user_data ); +void tr_webRun( tr_session * session, + const char * url, + const char * range, + tr_web_done_func done_func, + void * done_func_user_data ); #endif diff --git a/libtransmission/webseed.c b/libtransmission/webseed.c index c098f7d8d..35918872e 100644 --- a/libtransmission/webseed.c +++ b/libtransmission/webseed.c @@ -147,7 +147,7 @@ makeURL( tr_webseed * w, static void requestNextChunk( tr_webseed * w ); static void -webResponseFunc( tr_handle * session, +webResponseFunc( tr_session * session, long response_code, const void * response, size_t response_byte_count,