From 509dbaae3da0a220a2673d9dc7d6ddc1c1c79bd4 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 18 Jun 2008 22:01:15 +0000 Subject: [PATCH] senseless RPC changes --- daemon/remote.c | 2 +- doc/rpc-spec.txt | 38 ++++++++++++++++++++++++++---------- libtransmission/rpc-server.c | 4 ++-- libtransmission/rpc.c | 29 +++++++++++++++++++++++++-- 4 files changed, 58 insertions(+), 15 deletions(-) diff --git a/daemon/remote.c b/daemon/remote.c index e13a2d820..6631ee0f1 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -348,7 +348,7 @@ processRequests( const char * host, int port, int i; CURL * curl; struct evbuffer * buf = evbuffer_new( ); - char * url = tr_strdup_printf( "http://%s:%d/transmission", host, port ); + char * url = tr_strdup_printf( "http://%s:%d/transmission/rpc", host, port ); curl = curl_easy_init( ); curl_easy_setopt( curl, CURLOPT_VERBOSE, debug ); diff --git a/doc/rpc-spec.txt b/doc/rpc-spec.txt index 5e914c7bd..36620e918 100644 --- a/doc/rpc-spec.txt +++ b/doc/rpc-spec.txt @@ -21,7 +21,7 @@ 2.1. Requests - Requests supports three keys: + Requests support three keys: (1) A required "method" string telling the name of the method to invoke (2) An optional "arguments" object of key/value pairs @@ -80,13 +80,13 @@ string | value type & description ---------------------------+------------------------------------------------- - "files-wanted" | array indices of one or more file to download - "files-unwanted" | array indices of one or more file to not download - "ids" | array which torrent(s) to set, described in 3.1 + "files-wanted" | array indices of file(s) to download + "files-unwanted" | array indices of file(s) to not download + "ids" | array torrent list, as described in 3.1 "peer-limit" | number maximum number of peers - "priority-high" | array indices of one or more high-priority files - "priority-low" | array indices of one or more low-priority files - "priority-normal" | array indices of one or more normal-priority files + "priority-high" | array indices of high-priority file(s) + "priority-low" | array indices of low-priority file(s) + "priority-normal" | array indices of normal-priority file(s) "speed-limit-down" | number maximum download speed (in KiB/s) "speed-limit-down-enabled" | 'boolean' true if the download speed is limited "speed-limit-up" | number maximum upload speed (in KiB/s) @@ -294,7 +294,8 @@ form of one of 3.3's tr_info objects with the fields for id, name, and hashString. -4. Session Status Requests + +4. Session Requests 4.1. Session Arguments @@ -311,15 +312,32 @@ "speed-limit-up" | number max global upload speed (in KiB/s) "speed-limit-up-enabled" | 'boolean' true means enabled -4.2. Mutators +4.1.1. Mutators Method name: "session-set" Request arguments: one or more of 4.1's arguments Response arguments: none -4.2. Accessors +4.1.2. Accessors Method name: "session-get" Request arguments: none Response arguments: all of 4.1's arguments +4.2. Session Statistics + + Method name: "session-stats" + + Request arguments: none + + Response arguments: + + string | value type + ---------------------------+------------------------------------------------- + "activeTorrentCount" | number + "downloadSpeed" | number + "pausedTorrentCount" | number + "torrentCount" | number + "uploadSpeed" | number + + diff --git a/libtransmission/rpc-server.c b/libtransmission/rpc-server.c index 655702a1b..10b9e16c2 100644 --- a/libtransmission/rpc-server.c +++ b/libtransmission/rpc-server.c @@ -152,7 +152,7 @@ startServer( tr_rpc_server * server ) server->ctx = shttpd_init( ); snprintf( ports, sizeof( ports ), "%d", server->port ); - shttpd_register_uri( server->ctx, "/transmission", handle_rpc, server ); + shttpd_register_uri( server->ctx, "/transmission/rpc", handle_rpc, server ); shttpd_set_option( server->ctx, "ports", ports ); shttpd_set_option( server->ctx, "dir_list", "0" ); shttpd_set_option( server->ctx, "root", "/dev/null" ); @@ -162,7 +162,7 @@ startServer( tr_rpc_server * server ) shttpd_set_option( server->ctx, "acl", server->acl ); } if( server->isPasswordEnabled ) { - char * buf = tr_strdup_printf( "/transmission=%s", passwd ); + char * buf = tr_strdup_printf( "/transmission/rpc=%s", passwd ); shttpd_set_option( server->ctx, "protect", buf ); tr_free( buf ); } diff --git a/libtransmission/rpc.c b/libtransmission/rpc.c index 5e43c954e..64d35474e 100644 --- a/libtransmission/rpc.c +++ b/libtransmission/rpc.c @@ -248,8 +248,8 @@ addInfo( const tr_torrent * tor, tr_benc * d, uint64_t fields ) tr_bencDictAddInt( d, "peersConnected", st->peersConnected ); tr_bencDictAddInt( d, "peersGettingFromUs", st->peersGettingFromUs ); tr_bencDictAddInt( d, "peersSendingToUs", st->peersSendingToUs ); - tr_bencDictAddDouble( d, "rateDownload", st->rateDownload ); - tr_bencDictAddDouble( d, "rateUpload", st->rateUpload ); + tr_bencDictAddInt( d, "rateDownload", (int)(st->rateDownload*1024) ); + tr_bencDictAddInt( d, "rateUpload", (int)(st->rateUpload*1024) ); tr_bencDictAddDouble( d, "recheckProgress", st->recheckProgress ); tr_bencDictAddInt( d, "status", st->status ); tr_bencDictAddDouble( d, "swarmSpeed", st->swarmSpeed ); @@ -554,6 +554,30 @@ sessionSet( tr_handle * h, tr_benc * args_in, tr_benc * args_out UNUSED ) return NULL; } +static const char* +sessionStats( tr_handle * h, tr_benc * args_in UNUSED, tr_benc * args_out ) +{ + tr_benc * d = tr_bencDictAddDict( args_out, "session-stats", 10 ); + tr_torrent * tor = NULL; + float up, down; + int running = 0; + int total = 0; + + tr_sessionGetSpeed( h, &down, &up ); + while(( tor = tr_torrentNext( h, tor ))) { + ++total; + if( tor->isRunning ) + ++running; + } + + tr_bencDictAddInt( d, "activeTorrentCount", running ); + tr_bencDictAddInt( d, "downloadSpeed", (int)(down*1024) ); + tr_bencDictAddInt( d, "pausedTorrentCount", total-running ); + tr_bencDictAddInt( d, "torrentCount", total ); + tr_bencDictAddInt( d, "uploadSpeed", (int)(up*1024) ); + return NULL; +} + static const char* sessionGet( tr_handle * h, tr_benc * args_in UNUSED, tr_benc * args_out ) { @@ -602,6 +626,7 @@ struct method { } methods[] = { { "session-get", sessionGet }, { "session-set", sessionSet }, + { "session-stats", sessionStats }, { "torrent-add", torrentAdd }, { "torrent-get", torrentGet }, { "torrent-remove", torrentRemove }, -- 2.40.0