]> granicus.if.org Git - transmission/commitdiff
(trunk libT) more semantic cleanup: tr_handle->tr_session, int->tr_bool, int->tr_port
authorCharles Kerr <charles@transmissionbt.com>
Sun, 14 Dec 2008 11:21:11 +0000 (11:21 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Sun, 14 Dec 2008 11:21:11 +0000 (11:21 +0000)
26 files changed:
libtransmission/handshake.c
libtransmission/iobuf.c
libtransmission/iobuf.h
libtransmission/makemeta.c
libtransmission/makemeta.h
libtransmission/metainfo.c
libtransmission/metainfo.h
libtransmission/peer-io.h
libtransmission/peer-mgr.h
libtransmission/platform.c
libtransmission/platform.h
libtransmission/port-forwarding.c
libtransmission/port-forwarding.h
libtransmission/rpc-server.c
libtransmission/rpc-server.h
libtransmission/rpcimpl.c
libtransmission/rpcimpl.h
libtransmission/session.c
libtransmission/stats.c
libtransmission/torrent.c
libtransmission/tracker.h
libtransmission/trevent.c
libtransmission/trevent.h
libtransmission/web.c
libtransmission/web.h
libtransmission/webseed.c

index e795fb7b241e192e34c052ddf11ba00baa02d281..730937f536c9c0ba68ab084b5da8dfd753f12c37 100644 (file)
@@ -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 );
index 2ae2d4a7bbbaf25322c520b0b793e64d202a07fa..4ac9fe2eb6313ac09c1d5b65e83e7af53b4eac9c 100644 (file)
@@ -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,
index fbcf8922a0177739a146cf557ce4a07943035768..fe573c1b4a33961a7fe0c2cb9af83f3ec5084576 100644 (file)
@@ -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,
index ea5889e5d14362526dce1c92f70d5159fdd27797..2d83ae14ef0a0bb37baa45168ed0e98c03a52984 100644 (file)
@@ -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 )
         {
index aaf0f54106b5026b9a3a1f4766167262cda2dea5..3d9082021abadddebb3caedd3bcd0ad01ae862aa 100644 (file)
@@ -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* );
index 045cde186bc3d59a6a227c3cdc2a5c971e733bd9..69589ab132b9874a46d9a55dcfe06d96124d5fe5 100644 (file)
 ***/
 
 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 );
 }
index 5738cdc31d0cd8929dc2678d222662f6fd171571..4ca3aa8408f3a9ed24b9e8fa954cc6029dafc357 100644 (file)
@@ -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
 }
index 428f7dfc575b051563a97e4e2535af94ebcdb8c5..54bd527f5813f441c54fe2fa5fe503719c88ae46 100644 (file)
@@ -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 );
index 58f1c200a1b19bcb2f67f6d8b489c07fef5dbe8b..9aca6a35e854b1c452993d6672564696b59a891a 100644 (file)
@@ -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 );
 
index 786a4d9d339605e4f433a280998dc9ca30d5af43..5e22fa4d13c6a4328c378eec77264c7468a0d15b 100644 (file)
@@ -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*
index e8076c2146358169be8c4955922082d1035e9ab9..9a885655d35e6fc45aeb7f1a0476d20140842c8c 100644 (file)
 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 *),
index 0cb1adc956a576edd4f59e74fef33ca85fb07554..27473e42087b6387738fa6f441e50a77eb3ba2ae 100644 (file)
@@ -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;
index 19d698d37940b0e7d2e50359cf5d399371f25486..72f369d855918bd1182c201d0456438d4ea4d782 100644 (file)
 
 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 * );
 
index 20d2f33ff571d1b45945ecee3d6d9e02ecf22fb0..35449ad2b4823aac2a40a81573da3664da0bff5f 100644 (file)
@@ -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;
 
index 3156a3500c4362ca0fa913a186a0c8f9e9c09fae..860d226505fa43a726df77d847260cff30d0bd21 100644 (file)
 
 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 );
 
index b8be07cb74fdf8bef2b119e11187ce6f037486be..833317a6a23ad1ccf1ed7eaab9d9eca5adac2522 100644 (file)
@@ -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; i<torrentCount; ++i )
     {
         tr_torrent * tor = torrents[i];
-        const tr_rpc_callback_status status = notify( h, TR_RPC_TORRENT_REMOVING, tor );
+        const tr_rpc_callback_status status = notify( session, TR_RPC_TORRENT_REMOVING, tor );
         int64_t deleteFlag;
         if( tr_bencDictFindInt( args_in, "delete-local-data", &deleteFlag ) && deleteFlag )
             tr_torrentDeleteLocalData( tor );
         if( !( status & TR_RPC_NOREMOVE ) )
             tr_torrentRemove( tor );
     }
+
     tr_free( torrents );
     return NULL;
 }
 
 static const char*
-torrentVerify( tr_handle *        h,
-               tr_benc *          args_in,
-               tr_benc * args_out UNUSED )
+torrentVerify( 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_torrentVerify( tor );
-        notify( h, TR_RPC_TORRENT_CHANGED, tor );
+        notify( session, TR_RPC_TORRENT_CHANGED, tor );
     }
+
     tr_free( torrents );
     return NULL;
 }
@@ -432,12 +434,12 @@ addInfo( const tr_torrent * tor,
 }
 
 static const char*
-torrentGet( tr_handle * handle,
-            tr_benc *   args_in,
-            tr_benc *   args_out )
+torrentGet( tr_session * session,
+            tr_benc    * args_in,
+            tr_benc    * args_out )
 {
     int           i, torrentCount;
-    tr_torrent ** torrents = getTorrents( handle, args_in, &torrentCount );
+    tr_torrent ** torrents = getTorrents( session, args_in, &torrentCount );
     tr_benc *     list = tr_bencDictAddList( args_out, "torrents",
                                              torrentCount );
     tr_benc *     fields;
@@ -519,12 +521,12 @@ setFileDLs( tr_torrent * tor,
 }
 
 static const char*
-torrentSet( tr_handle *        h,
-            tr_benc *          args_in,
-            tr_benc * args_out UNUSED )
+torrentSet( 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 )
     {
@@ -556,7 +558,7 @@ torrentSet( tr_handle *        h,
             tr_torrentSetSpeedMode( tor, TR_UP, tmp ? TR_SPEEDLIMIT_SINGLE
                                     : TR_SPEEDLIMIT_GLOBAL );
 
-        notify( h, TR_RPC_TORRENT_CHANGED, tor );
+        notify( session, TR_RPC_TORRENT_CHANGED, tor );
     }
 
     tr_free( torrents );
@@ -568,9 +570,9 @@ torrentSet( tr_handle *        h,
 ***/
 
 static const char*
-torrentAdd( tr_handle * h,
-            tr_benc *   args_in,
-            tr_benc *   args_out )
+torrentAdd( tr_session * session,
+            tr_benc    * args_in,
+            tr_benc    * args_out )
 {
     const char * filename = NULL;
     const char * metainfo_base64 = NULL;
@@ -587,7 +589,7 @@ torrentAdd( tr_handle * h,
         tr_ctor *    ctor;
         tr_torrent * tor;
 
-        ctor = tr_ctorNew( h );
+        ctor = tr_ctorNew( session );
 
         /* set the metainfo */
         if( filename )
@@ -608,7 +610,7 @@ torrentAdd( tr_handle * h,
         if( tr_bencDictFindInt( args_in, "peer-limit", &i ) )
             tr_ctorSetPeerLimit( ctor, TR_FORCE, i );
 
-        tor = tr_torrentNew( h, ctor, &err );
+        tor = tr_torrentNew( session, ctor, &err );
         tr_ctorFree( ctor );
 
         if( tor )
@@ -620,7 +622,7 @@ torrentAdd( tr_handle * h,
             tr_bencListAddStr( &fields, "hashString" );
             addInfo( tor, tr_bencDictAdd( args_out,
                                           "torrent-added" ), &fields );
-            notify( h, TR_RPC_TORRENT_ADDED, tor );
+            notify( session, TR_RPC_TORRENT_ADDED, tor );
             tr_bencFree( &fields );
         }
         else if( err == TR_EDUPLICATE )
@@ -641,108 +643,95 @@ torrentAdd( tr_handle * h,
 ***/
 
 static const char*
-sessionSet( tr_handle *        h,
-            tr_benc *          args_in,
-            tr_benc * args_out UNUSED )
+sessionSet( tr_session * session,
+            tr_benc    * args_in,
+            tr_benc    * args_out UNUSED )
 {
     int64_t      i;
     const char * str;
 
     if( tr_bencDictFindStr( args_in, "download-dir", &str ) )
-        tr_sessionSetDownloadDir( h, str );
+        tr_sessionSetDownloadDir( session, str );
     if( tr_bencDictFindInt( args_in, "peer-limit", &i ) )
-        tr_sessionSetPeerLimit( h, i );
+        tr_sessionSetPeerLimit( session, i );
     if( tr_bencDictFindInt( args_in, "pex-allowed", &i ) )
-        tr_sessionSetPexEnabled( h, i );
+        tr_sessionSetPexEnabled( session, i );
     if( tr_bencDictFindInt( args_in, "port", &i ) )
-        tr_sessionSetPeerPort( h, i );
+        tr_sessionSetPeerPort( session, i );
     if( tr_bencDictFindInt( args_in, "port-forwarding-enabled", &i ) )
-        tr_sessionSetPortForwardingEnabled( h, i );
+        tr_sessionSetPortForwardingEnabled( session, i );
     if( tr_bencDictFindInt( args_in, "speed-limit-down", &i ) )
-        tr_sessionSetSpeedLimit( h, TR_DOWN, i );
+        tr_sessionSetSpeedLimit( session, TR_DOWN, i );
     if( tr_bencDictFindInt( args_in, "speed-limit-down-enabled", &i ) )
-        tr_sessionSetSpeedLimitEnabled( h, TR_DOWN, i );
+        tr_sessionSetSpeedLimitEnabled( session, TR_DOWN, i );
     if( tr_bencDictFindInt( args_in, "speed-limit-up", &i ) )
-        tr_sessionSetSpeedLimit( h, TR_UP, i );
+        tr_sessionSetSpeedLimit( session, TR_UP, i );
     if( tr_bencDictFindInt( args_in, "speed-limit-up-enabled", &i ) )
-        tr_sessionSetSpeedLimitEnabled( h, TR_UP, i );
+        tr_sessionSetSpeedLimitEnabled( session, TR_UP, i );
     if( tr_bencDictFindStr( args_in, "encryption", &str ) )
     {
         if( !strcmp( str, "required" ) )
-            tr_sessionSetEncryption( h, TR_ENCRYPTION_REQUIRED );
+            tr_sessionSetEncryption( session, TR_ENCRYPTION_REQUIRED );
         else if( !strcmp( str, "tolerated" ) )
-            tr_sessionSetEncryption( h, TR_CLEAR_PREFERRED );
+            tr_sessionSetEncryption( session, TR_CLEAR_PREFERRED );
         else
-            tr_sessionSetEncryption( h, TR_ENCRYPTION_PREFERRED );
+            tr_sessionSetEncryption( session, TR_ENCRYPTION_PREFERRED );
     }
 
-    notify( h, TR_RPC_SESSION_CHANGED, NULL );
+    notify( session, TR_RPC_SESSION_CHANGED, NULL );
 
     return NULL;
 }
 
 static const char*
-sessionStats( tr_handle *       h,
-              tr_benc * args_in UNUSED,
-              tr_benc *         args_out )
+sessionStats( tr_session  * session,
+              tr_benc     * args_in UNUSED,
+              tr_benc     * args_out )
 {
-    tr_benc *    d = tr_bencDictAddDict( args_out, "session-stats", 10 );
-    tr_torrent * tor = NULL;
-    int          running = 0;
-    int          total = 0;
-
-    while( ( tor = tr_torrentNext( h, tor ) ) )
-    {
+    tr_benc    * d;
+    tr_torrent * tor;
+    int          running;
+    int          total;
+
+    tor = NULL;
+    total = running = 0;
+    while(( tor = tr_torrentNext( session, tor ))) {
         ++total;
         if( tor->isRunning )
             ++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 );
index 97e9e8cf60dacfe3366e2df973c3b395f8ab3540..3619975fd98e24e1b43a32d6d566d503b76fffff 100644 (file)
 ***/
 
 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 );
 
 
index e4e2c51ed7b4c60d3cf7ac87f16cdec6dce6f5f7..b14e87485320d8c9626b55b27570289b0b00ccf3 100644 (file)
@@ -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;
index 5abaed06ad832a3d1f4a6b181eb2b6deb31337bd..8981404b310616026f6ba166549c9f15c4585d1a 100644 (file)
@@ -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, &current );
+        tr_sessionGetStats( session, &current );
         addStats( setme, &stats->old, &current );
     }
 }
 
 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++;
 }
 
index ed1ee0a4e66f6c399b431273e5ea128d64849e61..b3bd7e49068711b47706aa9c212e80f6402fa289 100644 (file)
@@ -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 );
     }
 }
 
index 93bccfdcd7da2ef9dc9e1d7da228e78129c9844a..f40b78322355150bca84ce0d8452edaf3ec3d905 100644 (file)
@@ -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
index 428af7af6236f238f7d999be14660fdf47703f8e..8d14645a9fa3ead02605e42a851209babfe67e04 100644 (file)
@@ -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 );
index 058c97d268ca944cc3f6f215ef393ea99576be19..bf22951ac18e8dcd2aedc012d8392ef7bf59003b 100644 (file)
 /**
 **/
 
-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
index 7a0505d9bb55297e9ee86096e1a31a0b9b9a6a3a..ccc19cd753caf4ba60589d4275eec87fce508e1c 100644 (file)
@@ -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 )
     {
index 19f0b8a221f465036cf6c9aa790b988007d27c3e..64eb50ae729aeb76ce5e270e71de058826c886f4 100644 (file)
 #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
index c098f7d8d1ab9069453c8ce9dd48e9caa81c55f1..35918872ea09f43315e5484326b9e180bbc25dc9 100644 (file)
@@ -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,