Changeset 8123


Ignore:
Timestamp:
Apr 2, 2009, 8:43:42 PM (13 years ago)
Author:
charles
Message:

(trunk rpc) add the ability to set file priorities and download flags when adding a new torrent via rpc

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/rpc-spec.txt

    r8121 r8123  
    322322   "paused"           | 'boolean'   if true, don't start the torrent
    323323   "peer-limit"       | number      maximum number of peers
     324   "files-wanted"     | array       indices of file(s) to download
     325   "files-unwanted"   | array       indices of file(s) to not download
     326   "priority-high"    | array       indices of high-priority file(s)
     327   "priority-low"     | array       indices of low-priority file(s)
     328   "priority-normal"  | array       indices of normal-priority file(s)
    324329
    325330   Either "filename" OR "metainfo" MUST be included.
     
    455460         |         | yes       | torrent-set    | new arg "uploadLimited"
    456461         |         | yes       | torrent-set    | new arg "honorsSessionLimits"
     462         |         | yes       | torrent-add    | new arg "files-wanted"
     463         |         | yes       | torrent-add    | new arg "files-unwanted"
     464         |         | yes       | torrent-add    | new arg "priority-high"
     465         |         | yes       | torrent-add    | new arg "priority-low"
     466         |         | yes       | torrent-add    | new arg "priority-normal"
    457467         |         | yes       | session-get    | new arg "seedRatioLimit"
    458468         |         | yes       | session-get    | new arg "seedRatioLimited"
  • trunk/libtransmission/rpcimpl.c

    r8122 r8123  
    819819}
    820820
     821static tr_file_index_t*
     822fileListFromList( tr_benc * list, tr_file_index_t * setmeCount )
     823{
     824    size_t i;
     825    const size_t childCount = tr_bencListSize( list );
     826    tr_file_index_t n = 0;
     827    tr_file_index_t * files = tr_new0( tr_file_index_t, childCount );
     828
     829    for( i=0; i<childCount; ++i ) {
     830        int64_t intVal;
     831        if( tr_bencGetInt( tr_bencListChild( list, i ), &intVal ) )
     832            files[n++] = (tr_file_index_t)intVal;
     833    }
     834
     835    *setmeCount = n;
     836    return files;
     837}
     838
    821839static const char*
    822840torrentAdd( tr_session               * session,
     
    839857        tr_bool      boolVal;
    840858        const char * str;
     859        tr_benc    * l;
    841860        tr_ctor    * ctor = tr_ctorNew( session );
    842861
    843862        /* set the optional arguments */
     863
    844864        if( tr_bencDictFindStr( args_in, "download-dir", &str ) )
    845865            tr_ctorSetDownloadDir( ctor, TR_FORCE, str );
     866
    846867        if( tr_bencDictFindBool( args_in, "paused", &boolVal ) )
    847868            tr_ctorSetPaused( ctor, TR_FORCE, boolVal );
     869
    848870        if( tr_bencDictFindInt( args_in, "peer-limit", &i ) )
    849871            tr_ctorSetPeerLimit( ctor, TR_FORCE, i );
     872
     873        if( tr_bencDictFindList( args_in, "files-unwanted", &l ) ) {
     874            tr_file_index_t fileCount;
     875            tr_file_index_t * files = fileListFromList( l, &fileCount );
     876            tr_ctorSetFilesWanted( ctor, files, fileCount, FALSE );
     877            tr_free( files );
     878        }
     879        if( tr_bencDictFindList( args_in, "files-wanted", &l ) ) {
     880            tr_file_index_t fileCount;
     881            tr_file_index_t * files = fileListFromList( l, &fileCount );
     882            tr_ctorSetFilesWanted( ctor, files, fileCount, TRUE );
     883            tr_free( files );
     884        }
     885
     886        if( tr_bencDictFindList( args_in, "priority-low", &l ) ) {
     887            tr_file_index_t fileCount;
     888            tr_file_index_t * files = fileListFromList( l, &fileCount );
     889            tr_ctorSetFilePriorities( ctor, files, fileCount, TR_PRI_LOW );
     890            tr_free( files );
     891        }
     892        if( tr_bencDictFindList( args_in, "priority-normal", &l ) ) {
     893            tr_file_index_t fileCount;
     894            tr_file_index_t * files = fileListFromList( l, &fileCount );
     895            tr_ctorSetFilePriorities( ctor, files, fileCount, TR_PRI_NORMAL );
     896            tr_free( files );
     897        }
     898        if( tr_bencDictFindList( args_in, "priority-high", &l ) ) {
     899            tr_file_index_t fileCount;
     900            tr_file_index_t * files = fileListFromList( l, &fileCount );
     901            tr_ctorSetFilePriorities( ctor, files, fileCount, TR_PRI_HIGH );
     902            tr_free( files );
     903        }
    850904
    851905        dbgmsg( "torrentAdd: filename is \"%s\"", filename );
  • trunk/libtransmission/torrent-ctor.c

    r8122 r8123  
    1717#include "session.h" /* tr_sessionFindTorrentFile() */
    1818#include "torrent.h" /* tr_ctorGetSave() */
    19 #include "utils.h"
     19#include "utils.h" /* tr_new0 */
    2020
    2121struct optional_args
     
    4444
    4545    struct optional_args    optionalArgs[2];
     46
     47    tr_file_index_t       * want;
     48    tr_file_index_t         wantSize;
     49    tr_file_index_t       * notWant;
     50    tr_file_index_t         notWantSize;
     51    tr_file_index_t       * low;
     52    tr_file_index_t         lowSize;
     53    tr_file_index_t       * normal;
     54    tr_file_index_t         normalSize;
     55    tr_file_index_t       * high;
     56    tr_file_index_t         highSize;
    4657};
    4758
     
    152163
    153164void
     165tr_ctorSetFilePriorities( tr_ctor                * ctor,
     166                          const tr_file_index_t  * files,
     167                          tr_file_index_t          fileCount,
     168                          tr_priority_t            priority )
     169{
     170    tr_file_index_t ** myfiles;
     171    tr_file_index_t * mycount;
     172
     173    switch( priority ) {
     174        case TR_PRI_NORMAL: myfiles = &ctor->normal; mycount = &ctor->normalSize; break;
     175        case TR_PRI_LOW: myfiles = &ctor->low; mycount = &ctor->lowSize; break;
     176        case TR_PRI_HIGH: myfiles = &ctor->high; mycount = &ctor->highSize; break;
     177    }
     178
     179    tr_free( *myfiles );
     180    *myfiles = tr_memdup( files, sizeof(tr_file_index_t)*fileCount );
     181    *mycount = fileCount;
     182}
     183
     184void
     185tr_ctorInitTorrentPriorities( const tr_ctor * ctor, tr_torrent * tor )
     186{
     187    tr_file_index_t i;
     188
     189    for( i=0; i<ctor->lowSize; ++i )
     190        tr_torrentInitFilePriority( tor, ctor->low[i], TR_PRI_LOW );
     191    for( i=0; i<ctor->normalSize; ++i )
     192        tr_torrentInitFilePriority( tor, ctor->normal[i], TR_PRI_NORMAL );
     193    for( i=0; i<ctor->highSize; ++i )
     194        tr_torrentInitFilePriority( tor, ctor->high[i], TR_PRI_HIGH );
     195}
     196
     197void
     198tr_ctorSetFilesWanted( tr_ctor                * ctor,
     199                       const tr_file_index_t  * files,
     200                       tr_file_index_t          fileCount,
     201                       tr_bool                  wanted )
     202{
     203    tr_file_index_t ** myfiles = wanted ? &ctor->want : &ctor->notWant;
     204    tr_file_index_t * mycount = wanted ? &ctor->wantSize : &ctor->notWantSize;
     205
     206    tr_free( *myfiles );
     207    *myfiles = tr_memdup( files, sizeof(tr_file_index_t)*fileCount );
     208    *mycount = fileCount;
     209}
     210
     211void
     212tr_ctorInitTorrentWanted( const tr_ctor * ctor, tr_torrent * tor )
     213{
     214    if( ctor->notWantSize )
     215        tr_torrentInitFileDLs( tor, ctor->notWant, ctor->notWantSize, FALSE );
     216    if( ctor->wantSize )
     217        tr_torrentInitFileDLs( tor, ctor->notWant, ctor->wantSize, TRUE );
     218}
     219
     220/***
     221****
     222***/
     223
     224void
    154225tr_ctorSetDeleteSource( tr_ctor * ctor,
    155226                        tr_bool   deleteSource )
     
    323394    tr_free( ctor->optionalArgs[1].downloadDir );
    324395    tr_free( ctor->optionalArgs[0].downloadDir );
     396    tr_free( ctor->want );
     397    tr_free( ctor->notWant );
     398    tr_free( ctor->low );
     399    tr_free( ctor->high );
     400    tr_free( ctor->normal );
    325401    tr_free( ctor );
    326402}
  • trunk/libtransmission/torrent.c

    r8122 r8123  
    582582    assert( !tor->uploadedCur );
    583583
     584    tr_ctorInitTorrentPriorities( ctor, tor );
     585
     586    tr_ctorInitTorrentWanted( ctor, tor );
     587
    584588    tor->error   = 0;
    585589
  • trunk/libtransmission/torrent.h

    r8090 r8123  
    3636int         tr_ctorGetSave( const tr_ctor * ctor );
    3737
     38void        tr_ctorInitTorrentPriorities( const tr_ctor * ctor, tr_torrent * tor );
     39
     40void        tr_ctorInitTorrentWanted( const tr_ctor * ctor, tr_torrent * tor );
     41
    3842/**
    3943***
  • trunk/libtransmission/transmission.h

    r8122 r8123  
    6565typedef uint16_t tr_port;
    6666typedef uint8_t tr_bool;
     67
     68enum
     69{
     70    TR_PRI_LOW    = -1,
     71    TR_PRI_NORMAL =  0, /* since NORMAL is 0, memset initializes nicely */
     72    TR_PRI_HIGH   =  1
     73};
     74
     75typedef int8_t tr_priority_t;
    6776
    6877/**
     
    793802                              tr_bool        isPaused );
    794803
     804void        tr_ctorSetFilePriorities( tr_ctor                * ctor,
     805                                      const tr_file_index_t  * files,
     806                                      tr_file_index_t          fileCount,
     807                                      tr_priority_t            priority );
     808
     809void        tr_ctorSetFilesWanted( tr_ctor                * ctor,
     810                                   const tr_file_index_t  * fileIndices,
     811                                   tr_file_index_t          fileCount,
     812                                   tr_bool                  wanted );
     813
     814
    795815int         tr_ctorGetPeerLimit( const tr_ctor * ctor,
    796816                                 tr_ctorMode     mode,
     
    948968****/
    949969
    950 enum
    951 {
    952     TR_PRI_LOW    = -1,
    953     TR_PRI_NORMAL =  0, /* since NORMAL is 0, memset initializes nicely */
    954     TR_PRI_HIGH   =  1
    955 };
    956 
    957 typedef int8_t tr_priority_t;
    958970
    959971/**
Note: See TracChangeset for help on using the changeset viewer.