AM_CPPFLAGS = -I. -I$(top_srcdir) -I$(top_srcdir)/third-party/ -D__TRANSMISSION__ $(LIBEVENT_CPPFLAGS)
-AM_CFLAGS = $(OPENSSL_CFLAGS) $(LIBCURL_CFLAGS) $(PTHREAD_CFLAGS)
+AM_CFLAGS = $(LIBCURL_CFLAGS) $(OPENSSL_CFLAGS) $(PTHREAD_CFLAGS)
noinst_LIBRARIES = libtransmission.a
$(top_builddir)/third-party/libnatpmp/libnatpmp.a \
$(top_builddir)/third-party/libevent/libevent.la \
$(INTLLIBS) \
- $(OPENSSL_LIBS) \
$(LIBCURL_LIBS) \
+ $(OPENSSL_LIBS) \
$(PTHREAD_LIBS) \
-lm
int
tr_bencIsType( const tr_benc * val, int type )
{
- return ( ( val != NULL ) && ( val->type == type ) );
+ return ( ( val ) && ( val->type == type ) );
}
static int
{
tr_benc * parent;
- assert( top != NULL );
- assert( parentStack != NULL );
+ assert( top );
+ assert( parentStack );
if( tr_ptrArrayEmpty( parentStack ) )
return top;
parent = tr_ptrArrayBack( parentStack );
- assert( parent != NULL );
+ assert( parent );
/* dictionary keys must be strings */
if( ( parent->type == TYPE_DICT )
err = !isSomething( top ) || !tr_ptrArrayEmpty( parentStack );
- if( !err && ( setme_end != NULL ) )
+ if( !err && setme_end )
*setme_end = buf;
tr_ptrArrayFree( parentStack, NULL );
walkFuncs.containerEndFunc = saveContainerEndFunc;
bencWalk( top, &walkFuncs, out );
- if( len != NULL )
+ if( len )
*len = EVBUFFER_LENGTH( out );
ret = tr_strndup( (char*) EVBUFFER_DATA( out ), EVBUFFER_LENGTH( out ) );
evbuffer_free( out );
if( EVBUFFER_LENGTH( data.out ) )
evbuffer_add_printf( data.out, "\n" );
- if( len != NULL )
+ if( len )
*len = EVBUFFER_LENGTH( data.out );
ret = tr_strndup( (char*) EVBUFFER_DATA( data.out ), EVBUFFER_LENGTH( data.out ) );
evbuffer_free( data.out );
const tr_block_index_t end = start + tr_torPieceCountBlocks( tor, piece );
tr_block_index_t block;
- assert( cp != NULL );
+ assert( cp );
assert( piece < tor->info.pieceCount );
assert( start < tor->blockCount );
assert( start <= end );
{
crypto->torrentHashIsSet = hash ? 1 : 0;
- if( hash != NULL )
+ if( hash )
memcpy( crypto->torrentHash, hash, SHA_DIGEST_LENGTH );
else
memset( crypto->torrentHash, 0, SHA_DIGEST_LENGTH );
const uint8_t*
tr_cryptoGetTorrentHash( const tr_crypto * crypto )
{
- assert( crypto != NULL );
+ assert( crypto );
assert( crypto->torrentHashIsSet );
return crypto->torrentHash;
int
tr_cryptoHasTorrentHash( const tr_crypto * crypto )
{
- assert( crypto != NULL );
+ assert( crypto );
return crypto->torrentHashIsSet ? 1 : 0;
}
unsigned int len;
struct sockaddr_in sock;
- assert( addr != NULL );
- assert( port != NULL );
+ assert( addr );
+ assert( port );
tr_lockLock( gFd->lock );
if( gFd->normal < getSocketMax( gFd ) )
/* add our public key (Ya) */
public_key = tr_cryptoGetMyPublicKey( handshake->crypto, &len );
assert( len == KEY_LEN );
- assert( public_key != NULL );
+ assert( public_key );
evbuffer_add( outbuf, public_key, len );
/* add some bullshit padding */
const struct in_addr *
tr_handshakeGetAddr( const struct tr_handshake * handshake, uint16_t * port )
{
- assert( handshake != NULL );
- assert( handshake->io != NULL );
+ assert( handshake );
+ assert( handshake->io );
return tr_peerIoGetAddress( handshake->io, port );
}
tr_lockLock( lock );
- assert( tor != NULL );
- assert( setme != NULL );
+ assert( tor );
+ assert( setme );
assert( pieceIndex < tor->info.pieceCount );
n = tr_torPieceCountBytes( tor, pieceIndex );
{
tr_list *node = *list;
*list = (*list)->next;
- if( data_free_func != NULL )
+ if( data_free_func )
data_free_func( node->data );
node_free( node );
}
tr_list_pop_front( tr_list ** list )
{
void * ret = NULL;
- if( *list != NULL )
+ if( *list )
{
ret = (*list)->data;
tr_list_remove_node( list, *list );
void
tr_list_foreach( tr_list * list, TrListForeachFunc func )
{
- while( list != NULL ) {
+ while( list ) {
func( list->data );
list = list->next;
}
tr_list_size( const tr_list * list )
{
int size = 0;
- while( list != NULL ) {
+ while( list ) {
++size;
list = list->next;
}
assert( b->abortFlag || (walk-ret == (int)(SHA_DIGEST_LENGTH*b->pieceCount)) );
assert( b->abortFlag || !totalRemain );
- if( fp != NULL )
+ if( fp )
fclose( fp );
tr_free( buf );
/* find the next builder to process */
tr_lock * lock = getQueueLock ( handle );
tr_lockLock( lock );
- if( queue != NULL ) {
+ if( queue ) {
builder = queue;
queue = queue->nextBuilder;
}
didWriteWrapper( struct bufferevent * e, void * userData )
{
tr_peerIo * c = (tr_peerIo *) userData;
- if( c->didWrite != NULL )
- (*c->didWrite)( e, c->userData );
+ if( c->didWrite )
+ c->didWrite( e, c->userData );
}
static void
while( !done )
{
- const int ret = (*c->canRead)( e, c->userData );
+ const int ret = c->canRead( e, c->userData );
switch( ret )
{
gotErrorWrapper( struct bufferevent * e, short what, void * userData )
{
tr_peerIo * c = userData;
- if( c->gotError != NULL )
- (*c->gotError)( e, what, c->userData );
+ if( c->gotError )
+ c->gotError( e, what, c->userData );
}
/**
uint16_t port,
int socket )
{
- assert( handle != NULL );
- assert( in_addr != NULL );
+ assert( handle );
+ assert( in_addr );
assert( socket >= 0 );
return tr_peerIoNew( handle, in_addr, port,
{
int socket;
- assert( handle != NULL );
- assert( in_addr != NULL );
+ assert( handle );
+ assert( in_addr );
assert( port >= 0 );
- assert( torrentHash != NULL );
+ assert( torrentHash );
socket = tr_netOpenTCP( in_addr, port, 0 );
void
tr_peerIoFree( tr_peerIo * io )
{
- if( io != NULL )
+ if( io )
{
io->canRead = NULL;
io->didWrite = NULL;
tr_handle*
tr_peerIoGetHandle( tr_peerIo * io )
{
- assert( io != NULL );
- assert( io->handle != NULL );
+ assert( io );
+ assert( io->handle );
return io->handle;
}
const struct in_addr*
tr_peerIoGetAddress( const tr_peerIo * io, uint16_t * port )
{
- assert( io != NULL );
+ assert( io );
- if( port != NULL )
+ if( port )
*port = io->port;
return &io->in_addr;
tr_peerIoSetTorrentHash( tr_peerIo * io,
const uint8_t * hash )
{
- assert( io != NULL );
+ assert( io );
tr_cryptoSetTorrentHash( io->crypto, hash );
}
const uint8_t*
tr_peerIoGetTorrentHash( tr_peerIo * io )
{
- assert( io != NULL );
- assert( io->crypto != NULL );
+ assert( io );
+ assert( io->crypto );
return tr_cryptoGetTorrentHash( io->crypto );
}
int
tr_peerIoHasTorrentHash( const tr_peerIo * io )
{
- assert( io != NULL );
- assert( io->crypto != NULL );
+ assert( io );
+ assert( io->crypto );
return tr_cryptoHasTorrentHash( io->crypto );
}
tr_peerIoSetPeersId( tr_peerIo * io,
const uint8_t * peer_id )
{
- assert( io != NULL );
+ assert( io );
if(( io->peerIdIsSet = peer_id != NULL ))
memcpy( io->peerId, peer_id, 20 );
const uint8_t*
tr_peerIoGetPeersId( const tr_peerIo * io )
{
- assert( io != NULL );
+ assert( io );
assert( io->peerIdIsSet );
return io->peerId;
void
tr_peerIoEnableLTEP( tr_peerIo * io, int flag )
{
- assert( io != NULL );
+ assert( io );
assert( flag==0 || flag==1 );
io->extendedProtocolSupported = flag;
void
tr_peerIoEnableFEXT( tr_peerIo * io, int flag )
{
- assert( io != NULL );
+ assert( io );
assert( flag==0 || flag==1 );
io->fastPeersSupported = flag;
int
tr_peerIoSupportsLTEP( const tr_peerIo * io )
{
- assert( io != NULL );
+ assert( io );
return io->extendedProtocolSupported;
}
int
tr_peerIoSupportsFEXT( const tr_peerIo * io )
{
- assert( io != NULL );
+ assert( io );
return io->fastPeersSupported;
}
tr_peerIoSetEncryption( tr_peerIo * io,
int encryptionMode )
{
- assert( io != NULL );
+ assert( io );
assert( encryptionMode==PEER_ENCRYPTION_NONE || encryptionMode==PEER_ENCRYPTION_RC4 );
io->encryptionMode = encryptionMode;
getExistingPeer( Torrent * torrent, const struct in_addr * in_addr )
{
assert( torrentIsLocked( torrent ) );
- assert( in_addr != NULL );
+ assert( in_addr );
- return (tr_peer*) tr_ptrArrayFindSorted( torrent->peers,
- in_addr,
- peerCompareToAddr );
+ return tr_ptrArrayFindSorted( torrent->peers,
+ in_addr,
+ peerCompareToAddr );
}
static struct peer_atom*
static void
peerDestructor( tr_peer * peer )
{
- assert( peer != NULL );
- assert( peer->msgs != NULL );
+ assert( peer );
+ assert( peer->msgs );
tr_peerMsgsUnsubscribe( peer->msgs, peer->msgsTag );
tr_peerMsgsFree( peer->msgs );
assert( torrentIsLocked( t ) );
atom = getExistingAtom( t, &peer->in_addr );
- assert( atom != NULL );
+ assert( atom );
atom->time = time( NULL );
removed = tr_ptrArrayRemoveSorted( t->peers, peer, peerCompare );
{
uint8_t hash[SHA_DIGEST_LENGTH];
- assert( t != NULL );
+ assert( t );
assert( !t->isRunning );
- assert( t->peers != NULL );
+ assert( t->peers );
assert( torrentIsLocked( t ) );
assert( tr_ptrArrayEmpty( t->outgoingHandshakes ) );
assert( tr_ptrArrayEmpty( t->peers ) );
ret = tr_new( tr_peer*, peerCount );
for( i=connectionCount=0; i<peerCount; ++i )
- if( peers[i]->msgs != NULL )
+ if( peers[i]->msgs )
ret[connectionCount++] = peers[i];
*setmeCount = connectionCount;
Torrent * t;
tr_handshake * ours;
- assert( io != NULL );
+ assert( io );
assert( isConnected==0 || isConnected==1 );
t = tr_peerIoHasTorrentHash( io )
if( tr_peerIoIsIncoming ( io ) )
ours = tr_ptrArrayRemoveSorted( manager->incomingHandshakes,
handshake, handshakeCompare );
- else if( t != NULL )
+ else if( t )
ours = tr_ptrArrayRemoveSorted( t->outgoingHandshakes,
handshake, handshakeCompare );
else
ours = handshake;
- assert( ours != NULL );
+ assert( ours );
assert( ours == handshake );
- if( t != NULL )
+ if( t )
torrentLock( t );
addr = tr_peerIoGetAddress( io, &port );
{
tr_peer * peer = getExistingPeer( t, addr );
- if( peer != NULL ) /* we already have this peer */
+ if( peer ) /* we already have this peer */
{
tr_peerIoFree( io );
}
}
}
- if( t != NULL )
+ if( t )
torrentUnlock( t );
}
int
tr_pexCompare( const void * va, const void * vb )
{
- const tr_pex * a = (const tr_pex *) va;
- const tr_pex * b = (const tr_pex *) vb;
+ const tr_pex * a = va;
+ const tr_pex * b = vb;
int i = memcmp( &a->in_addr, &b->in_addr, sizeof(struct in_addr) );
if( i ) return i;
if( a->port < b->port ) return -1;
t = getExistingTorrent( manager, torrentHash );
- assert( t != NULL );
+ assert( t );
assert( ( t->isRunning != 0 ) == ( t->reconnectTimer != NULL ) );
assert( ( t->isRunning != 0 ) == ( t->rechokeTimer != NULL ) );
managerLock( manager );
- assert( tor != NULL );
+ assert( tor );
assert( getExistingTorrent( manager, tor->info.hash ) == NULL );
t = torrentConstructor( manager, tor );
managerLock( manager );
t = getExistingTorrent( manager, torrentHash );
- assert( t != NULL );
+ assert( t );
stopTorrent( t );
tr_ptrArrayRemoveSorted( manager->torrents, t, torrentCompare );
torrentDestructor( t );
myHandshakeDoneCB,
mgr );
- assert( tr_peerIoGetTorrentHash( io ) != NULL );
+ assert( tr_peerIoGetTorrentHash( io ) );
++newConnectionsThisSecond;
const char * fmt, ... )
{
FILE * fp = tr_getLog( );
- if( fp != NULL )
+ if( fp )
{
va_list args;
char timestr[64];
static void
sendInterest( tr_peermsgs * msgs, int weAreInterested )
{
- assert( msgs != NULL );
+ assert( msgs );
assert( weAreInterested==0 || weAreInterested==1 );
msgs->info->clientIsInterested = weAreInterested;
{
const time_t fibrillationTime = time(NULL) - MIN_CHOKE_PERIOD_SEC;
- assert( msgs != NULL );
- assert( msgs->info != NULL );
+ assert( msgs );
+ assert( msgs->info );
assert( choke==0 || choke==1 );
if( msgs->info->chokeChangedAt > fibrillationTime )
sendFastSuggest( tr_peermsgs * msgs,
uint32_t pieceIndex )
{
- assert( msgs != NULL );
+ assert( msgs );
if( tr_peerIoSupportsFEXT( msgs->io ) )
{
static void
sendFastHave( tr_peermsgs * msgs, int all )
{
- assert( msgs != NULL );
+ assert( msgs );
if( tr_peerIoSupportsFEXT( msgs->io ) )
{
uint32_t offset,
uint32_t length )
{
- assert( msgs != NULL );
+ assert( msgs );
if( tr_peerIoSupportsFEXT( msgs->io ) )
{
sendFastAllowed( tr_peermsgs * msgs,
uint32_t pieceIndex)
{
- assert( msgs != NULL );
+ assert( msgs );
if( tr_peerIoSupportsFEXT( msgs->io ) )
{
{
struct peer_request req;
- assert( msgs != NULL );
- assert( msgs->torrent != NULL );
+ assert( msgs );
+ assert( msgs->torrent );
assert( piece < msgs->torrent->info.pieceCount );
/**
tr_torrent * tor = msgs->torrent;
const tr_block_index_t block = _tr_block( tor, req->index, req->offset );
- assert( msgs != NULL );
- assert( req != NULL );
+ assert( msgs );
+ assert( req );
if( req->length != tr_torBlockCountBytes( msgs->torrent, block ) )
{
{
tr_peermsgs * m;
- assert( info != NULL );
- assert( info->io != NULL );
+ assert( info );
+ assert( info->io );
m = tr_new0( tr_peermsgs, 1 );
m->publisher = tr_publisherNew( );
void
tr_peerMsgsFree( tr_peermsgs* msgs )
{
- if( msgs != NULL )
+ if( msgs )
{
tr_timerFree( &msgs->pulseTimer );
tr_timerFree( &msgs->rateTimer );
{
int i;
- assert( t != NULL );
- assert( t->items != NULL );
- assert( func != NULL );
+ assert( t );
+ assert( t->items );
+ assert( func );
for( i=0; i<t->n_items; ++i )
func( t->items[i] );
void
tr_ptrArrayFree( tr_ptrArray * t, PtrArrayForeachFunc func )
{
- assert( t != NULL );
- assert( t->items != NULL );
+ assert( t );
+ assert( t->items );
- if( func != NULL )
+ if( func )
tr_ptrArrayForeach( t, func );
tr_free( t->items );
void*
tr_ptrArrayNth( tr_ptrArray* t, int i )
{
- assert( t != NULL );
+ assert( t );
assert( i >= 0 );
assert( i < t->n_items );
void
tr_publisherFree( tr_publisher_t ** p )
{
- assert( p != NULL );
- assert( *p != NULL );
+ assert( p );
+ assert( *p );
tr_list_free( &(*p)->list, NULL );
tr_free( *p );
{
size_t bytes = 0;
- if( r != NULL )
+ if( r )
{
const float cur = rateForInterval( r, SHORT_INTERVAL_MSEC );
const float max = r->limit;
static void
notify( tr_handle * session, int type, tr_torrent * tor )
{
- if( session->rpc_func != NULL )
+ if( session->rpc_func )
session->rpc_func( session, type, tor, session->rpc_func_user_data );
}
tr_encryption_mode
tr_sessionGetEncryption( tr_session * session )
{
- assert( session != NULL );
+ assert( session );
return session->encryptionMode;
}
void
tr_sessionSetEncryption( tr_session * session, tr_encryption_mode mode )
{
- assert( session != NULL );
+ assert( session );
assert( mode==TR_ENCRYPTION_PREFERRED
|| mode==TR_ENCRYPTION_REQUIRED
|| mode==TR_PLAINTEXT_PREFERRED );
int
tr_sessionGetPeerPort( const tr_handle * h )
{
- assert( h != NULL );
+ assert( h );
return tr_sharedGetPeerPort( h->shared );
}
h->metainfoLookupCount,
sizeof( struct tr_metainfo_lookup ),
compareHashStringToLookupEntry );
- if( l != NULL )
+ if( l )
{
if( l->filename != filename )
{
tr_session_stats * setme )
{
const struct tr_stats_handle * stats = getStats( handle );
- assert( stats != NULL );
+ assert( stats );
*setme = stats->single;
setme->secondsActive = time( NULL ) - stats->startTime;
updateRatio( setme );
tr_session_stats * setme )
{
const struct tr_stats_handle * stats = getStats( handle );
- assert( stats != NULL );
+ assert( stats );
tr_session_stats current;
tr_sessionGetStats( handle, ¤t );
addStats( setme, &stats->old, ¤t );
/* if no `name' field was set, then set it from the filename */
if( ctor->isSet_metainfo ) {
tr_benc * info = tr_bencDictFindType( &ctor->metainfo, "info", TYPE_DICT );
- if( info != NULL ) {
+ if( info ) {
tr_benc * name = tr_bencDictFindFirst( info, "name.utf-8", "name", NULL );
if( name == NULL )
name = tr_bencDictAdd( info, "name" );
static int
getBytePiece( const tr_info * info, uint64_t byteOffset )
{
- assert( info != NULL );
+ assert( info );
assert( info->pieceSize != 0 );
return byteOffset / info->pieceSize;
tr_file * file;
uint64_t firstByte, lastByte;
- assert( info != NULL );
+ assert( info );
assert( fileIndex < info->fileCount );
file = &info->files[fileIndex];
uint64_t offset = 0;
tr_info * inf = &tor->info;
- assert( inf != NULL );
+ assert( inf );
for( ff=0; ff<inf->fileCount; ++ff ) {
inf->files[ff].offset = offset;
int i;
int tier;
- assert( tor != NULL );
+ assert( tor );
assert( ( 0 <= pos ) && ( pos < tor->info.trackerCount ) );
/* the tier of the tracker we're promoting */
int
tr_torrentCanManualUpdate( const tr_torrent * tor )
{
- return ( tor != NULL )
+ return ( tor )
&& ( tor->isRunning )
&& ( tr_trackerCanManualAnnounce( tor->tracker ) );
}
const uint64_t lastBlockOffset = (file->offset + lastOffset) % tor->blockSize;
uint64_t haveBytes = 0;
- assert( tor != NULL );
+ assert( tor );
assert( fileIndex < tor->info.fileCount );
assert( file->offset + file->length <= tor->info.totalSize );
assert( ( firstBlock < tor->blockCount ) || (!file->length && file->offset==tor->info.totalSize) );
{
tr_peer_stat * ret = NULL;
- if( tor != NULL )
+ if( tor )
ret = tr_peerMgrPeerStats( tor->handle->peerMgr,
tor->info.hash, peerCount );
{
tr_torrentLock( tor );
- assert( tor != NULL );
+ assert( tor );
assert( pieceIndex < tor->info.pieceCount );
if( has )
tr_handle * h = tor->handle;
tr_info * inf = &tor->info;
- assert( tor != NULL );
+ assert( tor );
assert( !tor->isRunning );
tr_globalLock( h );
static void
fireStatusChange( tr_torrent * tor, cp_status_t status )
{
- assert( tor != NULL );
+ assert( tor );
assert( status==TR_CP_INCOMPLETE || status==TR_CP_DONE || status==TR_CP_COMPLETE );
- if( tor->status_func != NULL )
- (tor->status_func)( tor, status, tor->status_func_user_data );
+ if( tor->status_func )
+ tor->status_func( tor, status, tor->status_func_user_data );
}
void
tr_torrent_status_func func,
void * user_data )
{
- assert( tor != NULL );
+ assert( tor );
tor->status_func = func;
tor->status_func_user_data = user_data;
}
tr_piece_index_t i;
tr_file * file;
- assert( tor != NULL );
+ assert( tor );
assert( fileIndex < tor->info.fileCount );
assert( priority==TR_PRI_LOW || priority==TR_PRI_NORMAL || priority==TR_PRI_HIGH );
tr_priority_t ret;
tr_torrentLock( tor );
- assert( tor != NULL );
+ assert( tor );
assert( file < tor->info.fileCount );
ret = tor->info.files[file].priority;
tr_torrentUnlock( tor );
tr_deepLog( const char * file, int line, const char * name, const char * fmt, ... )
{
FILE * fp = tr_getLog( );
- if( fp != NULL )
+ if( fp )
{
va_list args;
char timestr[64];
{
out = tr_strdup( in );
}
- else if( in != NULL )
+ else if( in )
{
out = tr_malloc( len+1 );
memcpy( out, in, len );
int
tr_bitfieldAdd( tr_bitfield * bitfield, size_t nth )
{
- assert( bitfield != NULL );
- assert( bitfield->bits != NULL );
+ assert( bitfield );
+ assert( bitfield->bits );
if( nth >= bitfield->bitCount )
return -1;
tr_bitfieldRem( tr_bitfield * bitfield,
size_t nth )
{
- assert( bitfield != NULL );
- assert( bitfield->bits != NULL );
+ assert( bitfield );
+ assert( bitfield->bits );
if( nth >= bitfield->bitCount )
return -1;
const char *s = src;
size_t n = siz;
- assert( s != NULL );
- assert( d != NULL );
+ assert( s );
+ assert( d );
/* Copy as many bytes as will fit */
if (n != 0) {
fireCheckDone( tr_torrent * torrent,
tr_verify_done_cb verify_done_cb )
{
- if( verify_done_cb != NULL )
- (*verify_done_cb)( torrent );
+ if( verify_done_cb )
+ verify_done_cb( torrent );
}
static struct verify_node currentNode;