(rpc) remove TR_RPC_TORRENT_CLOSING. formalize "torrent-list"'s response in the rpc spec.

This commit is contained in:
Charles Kerr 2008-05-22 19:24:11 +00:00
parent 1279b6ffff
commit 9fdb8afdf0
6 changed files with 50 additions and 44 deletions

View File

@ -24,14 +24,14 @@
#include <libtransmission/transmission.h>
#include <libtransmission/bencode.h>
#include <libtransmission/rpc.h>
#include <libtransmission/utils.h> /* tr_strdup */
#include <libtransmission/utils.h>
#include <libtransmission/version.h>
#define MY_NAME "transmission-daemon"
static int closing = FALSE;
static tr_handle * gl_session;
static char gl_configfile[MAX_PATH_LENGTH];
static tr_handle * mySession;
static char myConfigFilename[MAX_PATH_LENGTH];
static void
saveState( tr_handle * h )
@ -48,14 +48,14 @@ saveState( tr_handle * h )
tr_sessionIsPortForwardingEnabled( h ) );
tr_bencDictAddStr( &d, "rpc-acl", tr_sessionGetRPCACL( h ) );
tr_bencDictAddInt( &d, "rpc-port", tr_sessionGetRPCPort( 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_bencDictAddInt( &d, "speed-limit-up",
tr_sessionGetSpeedLimit( h, TR_UP ) );
tr_bencDictAddInt( &d, "speed-limit-up-enabled",
tr_sessionIsSpeedLimitEnabled( h, TR_UP ) );
switch( tr_sessionGetEncryption( h ) ) {
case TR_PLAINTEXT_PREFERRED: str = "tolerated"; break;
case TR_ENCRYPTION_REQUIRED: str = "required"; break;
@ -63,11 +63,10 @@ saveState( tr_handle * h )
}
tr_bencDictAddStr( &d, "encryption", str );
tr_ninf( MY_NAME, "saving \"%s\"", gl_configfile );
tr_bencSaveFile( gl_configfile, &d );
tr_ninf( MY_NAME, "saving \"%s\"", myConfigFilename );
tr_bencSaveFile( myConfigFilename, &d );
tr_bencFree( &d );
}
static void
@ -90,19 +89,17 @@ session_init( const char * configDir, int rpc_port, const char * rpc_acl )
tr_ctor * ctor;
tr_torrent ** torrents;
assert( !gl_session );
if(( have_state = !tr_bencLoadFile( gl_configfile, &state )))
if(( have_state = !tr_bencLoadFile( myConfigFilename, &state )))
{
const char * str;
tr_ninf( MY_NAME, "loading settings from \"%s\"", gl_configfile );
tr_ninf( MY_NAME, "loading settings from \"%s\"", myConfigFilename );
if( tr_bencDictFindStr( &state, "download-dir", &str ) )
tr_strlcpy( downloadDir, str, sizeof( downloadDir ) );
tr_bencDictFindInt( &state, "port", &peer_port );
tr_bencDictFindInt( &state, "port-forwarding-enabled", &fwd_enabled );
tr_bencDictFindInt( &state, "peer-limit", &peers );
tr_bencDictFindInt( &state, "pex-allowed", &pex_enabled );
tr_bencDictFindInt( &state, "port", &peer_port );
tr_bencDictFindInt( &state, "port-forwarding-enabled", &fwd_enabled );
tr_bencDictFindStr( &state, "rpc-acl", &rpc_acl_fallback );
tr_bencDictFindInt( &state, "rpc-port", &rpc_port_fallback );
tr_bencDictFindInt( &state, "speed-limit-down", &down_limit );
@ -126,20 +123,20 @@ session_init( const char * configDir, int rpc_port, const char * rpc_acl )
rpc_acl = rpc_acl_fallback;
/* start the session */
gl_session = tr_sessionInitFull( configDir, "daemon", downloadDir,
pex_enabled, fwd_enabled, peer_port,
encryption,
up_limit, up_limited,
down_limit, down_limited,
peers,
TR_MSG_INF, 0,
FALSE, /* is the blocklist enabled? */
TR_DEFAULT_PEER_SOCKET_TOS,
TRUE, rpc_port, rpc_acl );
mySession = tr_sessionInitFull( configDir, "daemon", downloadDir,
pex_enabled, fwd_enabled, peer_port,
encryption,
up_limit, up_limited,
down_limit, down_limited,
peers,
TR_MSG_INF, 0,
FALSE, /* is the blocklist enabled? */
TR_DEFAULT_PEER_SOCKET_TOS,
TRUE, rpc_port, rpc_acl );
/* load the torrents */
ctor = tr_ctorNew( gl_session );
torrents = tr_sessionLoadTorrents( gl_session, ctor, NULL );
ctor = tr_ctorNew( mySession );
torrents = tr_sessionLoadTorrents( mySession, ctor, NULL );
tr_free( torrents );
tr_ctorFree( ctor );
@ -269,7 +266,7 @@ main( int argc, char ** argv )
readargs( argc, argv, &nofork, &port, &acl, &configDir );
if( configDir == NULL )
configDir = tr_strdup_printf( "%s-daemon", tr_getDefaultConfigDir() );
tr_buildPath( gl_configfile, sizeof( gl_configfile ),
tr_buildPath( myConfigFilename, sizeof( myConfigFilename ),
configDir, "daemon-config.benc", NULL );
if( !nofork ) {
@ -284,9 +281,9 @@ main( int argc, char ** argv )
while( !closing )
sleep( 1 );
saveState( gl_session );
saveState( mySession );
printf( "Closing transmission session..." );
tr_sessionClose( gl_session );
tr_sessionClose( mySession );
printf( " done.\n" );
tr_free( configDir );

View File

@ -38,14 +38,13 @@
(2) An optional "arguments" object of key/value pairs
(3) An optional "tag" integer as described in 2.1.
2.3. Request URL Query Notation
2.3. Transport Mechanism
As a convenience, a casual notation is supported for requests via the
query portion of a URL. The advantage of this is that all current requests
can be invoked via a very simple http GET request. The possible future
disadvantage is that it limits nesting and listing structured requests.
POSTing a JSON-encoded request is the preferred way of communicating
with the Transmission server; however, a simple notation also exists
for sending requests in the query portion of a URL.
The URI notation works as follows:
The URL notation works as follows:
(1) Any key not "tag" or "method" is assumed to be in "arguments".
(2) The "arguments" key isn't needed, since data isn't nested.
(3) If the entire value in a key/value pair can be parsed as an integer,
@ -78,12 +77,22 @@
3.2. Torrent List
An overview list of torrents.
Method name: "torrent-list".
Request arguments: none.
Response arguments: "list", an array of objects that contain two keys:
a torrent's name string, and its unique torrent id.
Response arguments: "list", an array of objects that contain seven keys:
key | value type
--------------------+-------------------------------------------------
"hashString" | string
"id" | number
"name" | string
"rateDownload" | double
"rateUpload" | double
"ratio" | double
3.3. Torrent Info Requests

View File

@ -302,7 +302,7 @@ onRPCIdle( void * vdata )
case TR_RPC_TORRENT_STOPPED:
/* this should be automatic */
break;
case TR_RPC_TORRENT_CLOSING:
case TR_RPC_TORRENT_REMOVING:
/* FIXME */
break;
case TR_RPC_TORRENT_CHANGED:
@ -326,7 +326,7 @@ onRPCChanged( tr_handle * handle UNUSED,
struct rpc_data * data = g_new0( struct rpc_data, 1 );
data->type = type;
data->torrentId = tor ? tr_torrentId( tor ) : -1;
data->tor = type == TR_RPC_TORRENT_CLOSING ? NULL : tor;
data->tor = type == TR_RPC_TORRENT_REMOVING ? NULL : tor;
data->cbdata = cbdata;
g_idle_add( onRPCIdle, data );
}

View File

@ -301,7 +301,8 @@ torrentList( tr_handle * handle, tr_benc * args_in, tr_benc * args_out )
for( i=0; i<torrentCount; ++i ) {
tr_torrent * tor = torrents[i];
const tr_stat * st = tr_torrentStat( tor );
tr_benc * d = tr_bencListAddDict( list, 6 );
tr_benc * d = tr_bencListAddDict( list, 7 );
tr_bencDictAddStr( d, "hashString", tor->info.hashString );
tr_bencDictAddInt( d, "id", tr_torrentId( tor ) );
tr_bencDictAddStr( d, "name", tor->info.name );
tr_bencDictAddDouble( d, "rateDownload", st->rateDownload );

View File

@ -155,7 +155,6 @@ typedef enum
TR_RPC_TORRENT_ADDED,
TR_RPC_TORRENT_STARTED,
TR_RPC_TORRENT_STOPPED,
TR_RPC_TORRENT_CLOSING,
TR_RPC_TORRENT_REMOVING,
TR_RPC_TORRENT_CHANGED,
TR_RPC_SESSION_CHANGED

View File

@ -4171,7 +4171,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
break;
case TR_RPC_TORRENT_STOPPED:
break;
case TR_RPC_TORRENT_CLOSING:
case TR_RPC_TORRENT_REMOVING:
break;
case TR_RPC_TORRENT_CHANGED:
break;