1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 01:03:01 +00:00

(rpc) remove the sort and filter options from the "torrent-get" rpc command. NOTE: probably breaks the mac build; xcode needs to drop "rpc-utils" from its list of libtransmission source files

This commit is contained in:
Charles Kerr 2008-06-21 15:08:34 +00:00
parent cda886028d
commit 751c166e9f
5 changed files with 0 additions and 304 deletions

View file

@ -105,12 +105,6 @@
"ids" | no | all | array described in 3.1
"fields" | yes | n/a | number bitwise-or'ed field
| | | values from the table below
"sort" | no | "id" | string "activity", "age", "id",
| | | "name", "progress", "ratio",
| | | "state", or "tracker".
"ascending" | no | 'true' | 'boolean' true if sorting ascending
"filter" | no | "all" | string "active", "all", "paused",
| | | "downloading", or "seeding".
Response arguments:

View file

@ -33,7 +33,6 @@ libtransmission_a_SOURCES = \
resume.c \
rpc.c \
rpc-server.c \
rpc-utils.c \
session.c \
stats.c \
torrent.c \
@ -78,7 +77,6 @@ noinst_HEADERS = \
resume.h \
rpc.h \
rpc-server.h \
rpc-utils.h \
session.h \
stats.h \
torrent.h \

View file

@ -1,212 +0,0 @@
/*
* This file Copyright (C) 2008 Charles Kerr <charles@rebelbase.com>
*
* This file is licensed by the GPL version 2. Works owned by the
* Transmission project are granted a special exemption to clause 2(b)
* so that the bulk of its code can remain under the MIT license.
* This exemption does not extend to derived works not owned by
* the Transmission project.
*
* $Id$
*/
#include <stdlib.h> /* qsort */
#include <string.h> /* memcpy */
#include "transmission.h"
#include "rpc-utils.h"
#include "torrent.h"
#include "utils.h"
/****
*****
****/
static int
compareTorrentsByActivity( const void * a, const void * b )
{
const tr_stat * sa = tr_torrentStatCached( *(tr_torrent**) a );
const tr_stat * sb = tr_torrentStatCached( *(tr_torrent**) b );
int i;
if(( i = tr_compareDouble( sa->rateUpload + sa->rateDownload,
sb->rateUpload + sb->rateDownload ) ))
return i;
if( sa->uploadedEver != sb->uploadedEver )
return sa->uploadedEver < sa->uploadedEver ? -1 : 1;
return 0;
}
static int
compareTorrentsByAge( const void * a, const void * b )
{
tr_torrent * ta = * (tr_torrent **) a;
tr_torrent * tb = * (tr_torrent **) b;
return tr_compareTime( tr_torrentStatCached( ta )->addedDate,
tr_torrentStatCached( tb )->addedDate );
}
static int
compareTorrentsByID( const void * a, const void * b )
{
const tr_torrent * ta = * (tr_torrent **) a;
const tr_torrent * tb = * (tr_torrent **) b;
return ta->uniqueId - tb->uniqueId;
}
static int
compareTorrentsByName( const void * a, const void * b )
{
const tr_torrent * ta = * (tr_torrent **) a;
const tr_torrent * tb = * (tr_torrent **) b;
return tr_strcasecmp( ta->info.name, tb->info.name );
}
static int
compareRatio( double a, double b )
{
if( (int)a == TR_RATIO_INF && (int)b == TR_RATIO_INF ) return 0;
if( (int)a == TR_RATIO_INF ) return 1;
if( (int)b == TR_RATIO_INF ) return -1;
return tr_compareDouble( a, b );
}
static int
compareTorrentsByProgress( const void * a, const void * b )
{
const tr_stat * sa = tr_torrentStatCached( *(tr_torrent**) a );
const tr_stat * sb = tr_torrentStatCached( *(tr_torrent**) b );
int ret = tr_compareDouble( sa->percentDone, sb->percentDone );
if( !ret )
ret = compareRatio( sa->ratio, sb->ratio );
return ret;
}
static int
compareTorrentsByRatio( const void * a, const void * b )
{
const tr_stat * sa = tr_torrentStatCached( *(tr_torrent**) a );
const tr_stat * sb = tr_torrentStatCached( *(tr_torrent**) b );
return compareRatio( sa->ratio, sb->ratio );
}
static int
compareTorrentsByState( const void * a, const void * b )
{
const tr_stat * sa = tr_torrentStatCached( *(tr_torrent**) a );
const tr_stat * sb = tr_torrentStatCached( *(tr_torrent**) b );
int ret = sa->status - sb->status;
if( !ret )
ret = compareTorrentsByRatio( a, b );
return 0;
}
static int
compareTorrentsByTracker( const void * a, const void * b )
{
const tr_stat * sa = tr_torrentStatCached( *(tr_torrent**) a );
const tr_stat * sb = tr_torrentStatCached( *(tr_torrent**) b );
return tr_strcmp( sa->announceURL, sb->announceURL );
}
typedef int( *compareFunc )( const void *, const void * );
void
tr_torrentSort( tr_torrent ** torrents,
int torrentCount,
tr_sort_method sortMethod,
int isAscending )
{
compareFunc func = NULL;
switch( sortMethod )
{
case TR_SORT_ACTIVITY: func = &compareTorrentsByActivity; break;
case TR_SORT_AGE: func = compareTorrentsByAge; break;
case TR_SORT_NAME: func = compareTorrentsByName; break;
case TR_SORT_PROGRESS: func = compareTorrentsByProgress; break;
case TR_SORT_RATIO: func = compareTorrentsByRatio; break;
case TR_SORT_STATE: func = compareTorrentsByState; break;
case TR_SORT_TRACKER: func = compareTorrentsByTracker; break;
default: func = compareTorrentsByID; break;
}
qsort( torrents, torrentCount, sizeof(tr_torrent*), func );
if( !isAscending )
{
int left = 0;
int right = torrentCount - 1;
while( left < right ) {
tr_torrent * tmp = torrents[left];
torrents[left] = torrents[right];
torrents[right] = tmp;
++left;
--right;
}
}
}
/****
*****
****/
static int
testActive( const tr_torrent * tor )
{
const tr_stat * s = tr_torrentStatCached( ( tr_torrent * ) tor );
return s->peersSendingToUs>0 || s->peersGettingFromUs>0;
}
static int
testStatus( const tr_torrent * tor, cp_status_t status )
{
return tr_torrentGetStatus( ( tr_torrent * ) tor ) == status;
}
static int
testDownloading( const tr_torrent * tor )
{
return testStatus( tor, TR_STATUS_DOWNLOAD );
}
static int
testSeeding( const tr_torrent * tor )
{
return testStatus( tor, TR_STATUS_SEED );
}
static int
testPaused( const tr_torrent * tor )
{
return testStatus( tor, TR_STATUS_STOPPED );
}
static int
testTrue( const tr_torrent * tor UNUSED )
{
return TRUE;
}
typedef int( *test_func )( const tr_torrent * );
void
tr_torrentFilter( tr_torrent ** torrents,
int * torrentCount,
tr_filter_method filterMethod )
{
int i;
int newCount = 0;
test_func func;
tr_torrent ** tmp = tr_new0( tr_torrent*, torrentCount );
switch( filterMethod ) {
case TR_FILTER_ACTIVE: func = testActive; break;
case TR_FILTER_DOWNLOADING: func = testDownloading; break;
case TR_FILTER_PAUSED: func = testPaused; break;
case TR_FILTER_SEEDING: func = testSeeding; break;
default: func = testTrue; break;
}
for( i=0; i<*torrentCount; ++i )
if( func( torrents[i] ) )
tmp[newCount++] = torrents[i];
memcpy( torrents, tmp, sizeof(tr_torrent*) * newCount );
*torrentCount = newCount;
tr_free( tmp );
}

View file

@ -1,48 +0,0 @@
/*
* This file Copyright (C) 2008 Charles Kerr <charles@rebelbase.com>
*
* This file is licensed by the GPL version 2. Works owned by the
* Transmission project are granted a special exemption to clause 2(b)
* so that the bulk of its code can remain under the MIT license.
* This exemption does not extend to derived works not owned by
* the Transmission project.
*
* $Id$
*/
#ifndef RPC_UTILS_H
#define RPC_UTILS_H
typedef enum
{
TR_SORT_ACTIVITY,
TR_SORT_AGE,
TR_SORT_ID,
TR_SORT_NAME,
TR_SORT_PROGRESS,
TR_SORT_RATIO,
TR_SORT_STATE,
TR_SORT_TRACKER
}
tr_sort_method;
void tr_torrentSort( tr_torrent ** torrents,
int torrentCount,
tr_sort_method sortMethod,
int isAscending );
typedef enum
{
TR_FILTER_ACTIVE,
TR_FILTER_ALL,
TR_FILTER_DOWNLOADING,
TR_FILTER_PAUSED,
TR_FILTER_SEEDING
}
tr_filter_method;
void tr_torrentFilter( tr_torrent ** torrents,
int * torrentCount,
tr_filter_method filterMethod );
#endif

View file

@ -19,7 +19,6 @@
#include "bencode.h"
#include "ratecontrol.h"
#include "rpc.h"
#include "rpc-utils.h"
#include "json.h"
#include "session.h"
#include "torrent.h"
@ -45,12 +44,9 @@ notify( tr_handle * session, int type, tr_torrent * tor )
static tr_torrent **
getTorrents( tr_handle * handle, tr_benc * args, int * setmeCount )
{
int method;
int torrentCount = 0;
int64_t id;
int64_t sortAscending;
tr_torrent ** torrents = NULL;
const char * str;
tr_benc * ids;
/***
@ -95,38 +91,6 @@ getTorrents( tr_handle * handle, tr_benc * args, int * setmeCount )
torrents[torrentCount++] = tor;
}
/***
**** filter the torrents
***/
method = TR_FILTER_ALL;
if( tr_bencDictFindStr( args, "filter", &str ) ) {
if( !strcmp( str, "active" ) ) method = TR_FILTER_ACTIVE;
else if( !strcmp( str, "downloading" ) ) method = TR_FILTER_DOWNLOADING;
else if( !strcmp( str, "paused" ) ) method = TR_FILTER_PAUSED;
else if( !strcmp( str, "seeding" ) ) method = TR_FILTER_SEEDING;
}
if( method != TR_FILTER_ALL )
tr_torrentFilter( torrents, &torrentCount, method );
/***
**** sort the torrents
***/
method = TR_SORT_ID;
sortAscending = 1;
tr_bencDictFindInt( args, "ascending", &sortAscending );
if( tr_bencDictFindStr( args, "sort", &str ) ) {
if( !strcmp( str, "activity" ) ) method = TR_SORT_ACTIVITY;
else if( !strcmp( str, "age" ) ) method = TR_SORT_AGE;
else if( !strcmp( str, "name" ) ) method = TR_SORT_NAME;
else if( !strcmp( str, "progress" ) ) method = TR_SORT_PROGRESS;
else if( !strcmp( str, "ratio" ) ) method = TR_SORT_RATIO;
else if( !strcmp( str, "state" ) ) method = TR_SORT_STATE;
else if( !strcmp( str, "tracker" ) ) method = TR_SORT_TRACKER;
}
tr_torrentSort( torrents, torrentCount, method, sortAscending!=0 );
/***
**** return the results
***/