From 9fdb8afdf0211fe1645111aa16a7bbac89729f77 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 22 May 2008 19:24:11 +0000 Subject: [PATCH] (rpc) remove TR_RPC_TORRENT_CLOSING. formalize "torrent-list"'s response in the rpc spec. --- daemon/daemon.c | 59 ++++++++++++++++------------------ doc/rpc-spec.txt | 25 +++++++++----- gtk/main.c | 4 +-- libtransmission/rpc.c | 3 +- libtransmission/transmission.h | 1 - macosx/Controller.m | 2 +- 6 files changed, 50 insertions(+), 44 deletions(-) diff --git a/daemon/daemon.c b/daemon/daemon.c index 7a97d6931..0a0f2079f 100644 --- a/daemon/daemon.c +++ b/daemon/daemon.c @@ -24,14 +24,14 @@ #include #include #include -#include /* tr_strdup */ +#include #include #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 ); diff --git a/doc/rpc-spec.txt b/doc/rpc-spec.txt index 2d4b263c9..36157c339 100644 --- a/doc/rpc-spec.txt +++ b/doc/rpc-spec.txt @@ -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 diff --git a/gtk/main.c b/gtk/main.c index a0b5e1895..a288a5e63 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -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 ); } diff --git a/libtransmission/rpc.c b/libtransmission/rpc.c index 0893a3b2d..66d7eae52 100644 --- a/libtransmission/rpc.c +++ b/libtransmission/rpc.c @@ -301,7 +301,8 @@ torrentList( tr_handle * handle, tr_benc * args_in, tr_benc * args_out ) for( i=0; iinfo.hashString ); tr_bencDictAddInt( d, "id", tr_torrentId( tor ) ); tr_bencDictAddStr( d, "name", tor->info.name ); tr_bencDictAddDouble( d, "rateDownload", st->rateDownload ); diff --git a/libtransmission/transmission.h b/libtransmission/transmission.h index 11e6a3bed..c0c5c787f 100644 --- a/libtransmission/transmission.h +++ b/libtransmission/transmission.h @@ -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 diff --git a/macosx/Controller.m b/macosx/Controller.m index df51f5007..ce2f63fed 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -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; -- 2.40.0