Changeset 8122


Ignore:
Timestamp:
Apr 2, 2009, 5:30:29 PM (13 years ago)
Author:
charles
Message:

(trunk) modify tr_torrentParse() and tr_torrentNew() arguments s.t. they use the ctor's session instead of passing it in again. Allow a NULL session pointer for some cases of tr_torrentParse().

Location:
trunk
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/cli/cli.c

    r8108 r8122  
    356356        tr_info info;
    357357
    358         if( !tr_torrentParse( h, ctor, &info ) )
     358        if( !tr_torrentParse( ctor, &info ) )
    359359        {
    360360            int          i;
     
    392392        tr_info info;
    393393
    394         if( !tr_torrentParse( h, ctor, &info ) )
     394        if( !tr_torrentParse( ctor, &info ) )
    395395        {
    396396            dumpInfo( stdout, &info );
     
    402402    }
    403403
    404     tor = tr_torrentNew( h, ctor, &error );
     404    tor = tr_torrentNew( ctor, &error );
    405405    tr_ctorFree( ctor );
    406406    if( !tor )
  • trunk/daemon/daemon.c

    r8108 r8122  
    191191        int err = tr_ctorSetMetainfoFromFile( ctor, filename );
    192192        if( !err )
    193             tr_torrentNew( session, ctor, &err );
     193            tr_torrentNew( ctor, &err );
    194194
    195195        tr_ctorFree( ctor );
  • trunk/gtk/add-dialog.c

    r7774 r8122  
    172172        int          new_file = 0;
    173173        tr_torrent * torrent;
    174         tr_session * session = tr_core_session( data->core );
    175174
    176175        if( filename
     
    187186        tr_ctorSetDeleteSource( data->ctor, FALSE );
    188187
    189         if( ( torrent = tr_torrentNew( session, data->ctor, &err ) ) )
     188        if( ( torrent = tr_torrentNew( data->ctor, &err ) ) )
    190189        {
    191190            removeOldTorrent( data );
  • trunk/gtk/tr-core.c

    r7976 r8122  
    928928        {
    929929            tr_info inf;
    930             int err = tr_torrentParse( session, ctor, &inf );
     930            int err = tr_torrentParse( ctor, &inf );
    931931
    932932            switch( err )
  • trunk/gtk/tr-torrent.c

    r7860 r8122  
    199199    tr_ctorGetDeleteSource( ctor, &doTrash );
    200200    tr_ctorSetDeleteSource( ctor, FALSE );
    201     tor = tr_torrentNew( session, ctor, errcode );
     201    tor = tr_torrentNew( ctor, errcode );
    202202
    203203    if( tor && doTrash )
  • trunk/libtransmission/fdlimit.c

    r7801 r8122  
    444444        else if( o->syncAt <= time( NULL ) ) {
    445445            dbgmsg( "fsync()ing file '%s' in slot #%d", o->filename, i );
    446             fsync( o->fd );
     446            //fsync( o->fd );
    447447#ifdef HAVE_POSIX_FADVISE
    448448            /* TODO: test performance with and without this */
  • trunk/libtransmission/metainfo.c

    r7657 r8122  
    441441    /* filename of Transmission's copy */
    442442    tr_free( inf->torrent );
    443     inf->torrent = getTorrentFilename( session, inf );
     443    inf->torrent = session ?  getTorrentFilename( session, inf ) : NULL;
    444444
    445445    return NULL;
  • trunk/libtransmission/rpcimpl.c

    r8121 r8122  
    746746    int err = 0;
    747747    const char * result = NULL;
    748     tr_torrent * tor = tr_torrentNew( data->session, ctor, &err );
     748    tr_torrent * tor = tr_torrentNew( ctor, &err );
    749749
    750750    tr_ctorFree( ctor );
  • trunk/libtransmission/session.c

    r8118 r8122  
    13691369                char * path = tr_buildPath( dirname, d->d_name, NULL );
    13701370                tr_ctorSetMetainfoFromFile( ctor, path );
    1371                 if(( tor = tr_torrentNew( session, ctor, NULL )))
     1371                if(( tor = tr_torrentNew( ctor, NULL )))
    13721372                {
    13731373                    tr_list_append( &list, tor );
     
    16201620                char * path = tr_buildPath( dirname, d->d_name, NULL );
    16211621                tr_ctorSetMetainfoFromFile( ctor, path );
    1622                 if( !tr_torrentParse( session, ctor, &inf ) )
     1622                if( !tr_torrentParse( ctor, &inf ) )
    16231623                {
    16241624                    tr_list_append( &list, tr_strdup( inf.hashString ) );
  • trunk/libtransmission/torrent-ctor.c

    r7658 r8122  
    292292}
    293293
     294tr_session*
     295tr_ctorGetSession( const tr_ctor * ctor )
     296{
     297    return (tr_session*) ctor->session;
     298}
     299
    294300/***
    295301****
     
    302308
    303309    ctor->session = session;
    304     tr_ctorSetPeerLimit( ctor, TR_FALLBACK, session->peerLimitPerTorrent );
    305310    tr_ctorSetPaused( ctor, TR_FALLBACK, FALSE );
    306     tr_ctorSetDownloadDir( ctor, TR_FALLBACK, session->downloadDir );
     311    if( session != NULL ) {
     312        tr_ctorSetPeerLimit( ctor, TR_FALLBACK, session->peerLimitPerTorrent );
     313        tr_ctorSetDownloadDir( ctor, TR_FALLBACK, session->downloadDir );
     314    }
    307315    tr_ctorSetSave( ctor, TRUE );
    308316    return ctor;
     
    317325    tr_free( ctor );
    318326}
    319 
  • trunk/libtransmission/torrent.c

    r8097 r8122  
    504504
    505505static void
    506 torrentRealInit( tr_session      * session,
    507                  tr_torrent      * tor,
    508                  const tr_ctor   * ctor )
     506torrentRealInit( tr_torrent * tor, const tr_ctor * ctor )
    509507{
    510508    int          doStart;
     
    514512    static int   nextUniqueId = 1;
    515513    tr_info    * info = &tor->info;
     514    tr_session * session = tr_ctorGetSession( ctor );
     515
     516    assert( session != NULL );
    516517
    517518    tr_globalLock( session );
     
    648649
    649650int
    650 tr_torrentParse( const tr_session  * session,
    651                  const tr_ctor     * ctor,
     651tr_torrentParse( const tr_ctor     * ctor,
    652652                 tr_info           * setmeInfo )
    653653{
     
    656656    tr_info         tmp;
    657657    const tr_benc * metainfo;
     658    tr_session    * session = tr_ctorGetSession( ctor );
    658659
    659660    if( setmeInfo == NULL )
     
    670671        err = TR_EINVALID;
    671672
    672     if( !err && tr_torrentExists( session, setmeInfo->hash ) )
     673    if( !err && session && tr_torrentExists( session, setmeInfo->hash ) )
    673674        err = TR_EDUPLICATE;
    674675
     
    680681
    681682tr_torrent *
    682 tr_torrentNew( tr_session     * session,
    683                const tr_ctor  * ctor,
     683tr_torrentNew( const tr_ctor  * ctor,
    684684               int            * setmeError )
    685685{
     
    688688    tr_torrent * tor = NULL;
    689689
    690     err = tr_torrentParse( session, ctor, &tmpInfo );
     690    assert( ctor != NULL );
     691    assert( tr_isSession( tr_ctorGetSession( ctor ) ) );
     692
     693    err = tr_torrentParse( ctor, &tmpInfo );
    691694    if( !err )
    692695    {
    693696        tor = tr_new0( tr_torrent, 1 );
    694697        tor->info = tmpInfo;
    695         torrentRealInit( session, tor, ctor );
     698        torrentRealInit( tor, ctor );
    696699    }
    697700    else if( setmeError )
  • trunk/libtransmission/transmission.h

    r8118 r8122  
    755755struct tr_benc;
    756756
    757 tr_ctor*    tr_ctorNew( const tr_session * session );
     757/* it's okay to use NULL here if you're only parsing the torrent.
     758 * @see tr_torrentParse() */
     759tr_ctor*    tr_ctorNew( const tr_session * session_or_NULL );
    758760
    759761void        tr_ctorFree( tr_ctor * ctor );
     
    809811                                    tr_bool        * setmeDoDelete );
    810812
     813tr_session* tr_ctorGetSession( const tr_ctor * ctor );
     814
    811815/* returns NULL if tr_ctorSetMetainfoFromFile() wasn't used */
    812816const char* tr_ctorGetSourceFile( const tr_ctor * ctor );
     
    826830 * metainfo is stored in setme_info and should be freed by the
    827831 * caller via tr_metainfoFree().
    828  */
    829 int tr_torrentParse( const tr_session  * session,
    830                      const tr_ctor     * ctor,
    831                      tr_info           * setme_info_or_NULL );
     832 *
     833 * If the constructor's session variable is NULL,
     834 * info.torrent will be NULL and the duplicate check will not be performed.
     835 */
     836int tr_torrentParse( const tr_ctor * ctor,
     837                     tr_info       * setme_info_or_NULL );
    832838
    833839/** @brief free a metainfo
     
    840846            TR_EINVALID if the torrent couldn't be parsed, or
    841847            TR_EDUPLICATE if there's already a matching torrent object. */
    842 tr_torrent * tr_torrentNew( tr_session      * session,
    843                             const tr_ctor   * ctor,
     848tr_torrent * tr_torrentNew( const tr_ctor   * ctor,
    844849                            int             * setmeError );
    845850
  • trunk/macosx/Controller.m

    r8119 r8122  
    794794        tr_ctor * ctor = tr_ctorNew(fLib);
    795795        tr_ctorSetMetainfoFromFile(ctor, [torrentPath UTF8String]);
    796         int result = tr_torrentParse(fLib, ctor, &info);
     796        int result = tr_torrentParse(ctor, &info);
    797797        if (result != TR_OK)
    798798        {
     
    24582458        tr_ctorSetMetainfoFromFile(ctor, [file UTF8String]);
    24592459       
    2460         switch (tr_torrentParse(fLib, ctor, NULL))
     2460        switch (tr_torrentParse(ctor, NULL))
    24612461        {
    24622462            case TR_OK:
     
    26982698                tr_ctor * ctor = tr_ctorNew(fLib);
    26992699                tr_ctorSetMetainfoFromFile(ctor, [file UTF8String]);
    2700                 switch (tr_torrentParse(fLib, ctor, NULL))
     2700                switch (tr_torrentParse(ctor, NULL))
    27012701                {
    27022702                    case TR_OK:
     
    27622762                tr_ctor * ctor = tr_ctorNew(fLib);
    27632763                tr_ctorSetMetainfoFromFile(ctor, [file UTF8String]);
    2764                 switch (tr_torrentParse(fLib, ctor, NULL))
     2764                switch (tr_torrentParse(ctor, NULL))
    27652765                {
    27662766                    case TR_OK:
  • trunk/macosx/DragOverlayWindow.m

    r7659 r8122  
    8989            tr_ctorSetMetainfoFromFile(ctor, [file UTF8String]);
    9090            tr_info info;
    91             if (tr_torrentParse(fLib, ctor, &info) == TR_OK)
     91            if (tr_torrentParse(ctor, &info) == TR_OK)
    9292            {
    9393                count++;
  • trunk/macosx/Torrent.m

    r8098 r8122  
    16241624        {
    16251625            tr_ctorSetMetainfoFromHash(ctor, [hashString UTF8String]);
    1626             if (tr_torrentParse(lib, ctor, &info) == TR_OK)
     1626            if (tr_torrentParse(ctor, &info) == TR_OK)
    16271627            {
    16281628                NSString * currentDownloadFolder = [self shouldUseIncompleteFolderForName: [NSString stringWithUTF8String: info.name]]
     
    16301630                tr_ctorSetDownloadDir(ctor, TR_FORCE, [currentDownloadFolder UTF8String]);
    16311631               
    1632                 fHandle = tr_torrentNew(lib, ctor, NULL);
     1632                fHandle = tr_torrentNew(ctor, NULL);
    16331633            }
    16341634            tr_metainfoFree(&info);
     
    16371637        {
    16381638            tr_ctorSetMetainfoFromFile(ctor, [path UTF8String]);
    1639             if (tr_torrentParse(lib, ctor, &info) == TR_OK)
     1639            if (tr_torrentParse(ctor, &info) == TR_OK)
    16401640            {
    16411641                NSString * currentDownloadFolder = [self shouldUseIncompleteFolderForName: [NSString stringWithUTF8String: info.name]]
     
    16431643                tr_ctorSetDownloadDir(ctor, TR_FORCE, [currentDownloadFolder UTF8String]);
    16441644               
    1645                 fHandle = tr_torrentNew(lib, ctor, NULL);
     1645                fHandle = tr_torrentNew(ctor, NULL);
    16461646            }
    16471647            tr_metainfoFree(&info);
Note: See TracChangeset for help on using the changeset viewer.