From 6ce44b001de112ee1fb08ea77ed9dc7f045cf4c8 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 7 Mar 2010 08:30:19 +0000 Subject: 2010-03-07 Tatsuhiro Tsujikawa Added getServers XML-RPC method. * doc/aria2c.1.txt * src/FileEntry.h * src/XmlRpcMethodFactory.cc * src/XmlRpcMethodImpl.cc * src/XmlRpcMethodImpl.h --- src/XmlRpcMethodImpl.cc | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'src/XmlRpcMethodImpl.cc') diff --git a/src/XmlRpcMethodImpl.cc b/src/XmlRpcMethodImpl.cc index facc4ada..a2663ce8 100644 --- a/src/XmlRpcMethodImpl.cc +++ b/src/XmlRpcMethodImpl.cc @@ -112,6 +112,7 @@ const std::string KEY_PATH = "path"; const std::string KEY_SELECTED = "selected"; const std::string KEY_LENGTH = "length"; const std::string KEY_URI = "uri"; +const std::string KEY_CURRENT_URI = "currentUri"; const std::string KEY_VERSION = "version"; const std::string KEY_ENABLED_FEATURES = "enabledFeatures"; const std::string KEY_METHOD_NAME = "methodName"; @@ -127,6 +128,7 @@ const std::string KEY_ANNOUNCE_LIST = "announceList"; const std::string KEY_COMMENT = "comment"; const std::string KEY_CREATION_DATE = "creationDate"; const std::string KEY_MODE = "mode"; +const std::string KEY_SERVERS = "servers"; } static BDE createGIDResponse(int32_t gid) @@ -880,6 +882,49 @@ BDE GetSessionInfoXmlRpcMethod::process return result; } +BDE GetServersXmlRpcMethod::process +(const XmlRpcRequest& req, DownloadEngine* e) +{ + const BDE& params = req._params; + assert(params.isList()); + + if(params.empty() || !params[0].isString()) { + throw DL_ABORT_EX("Bad request"); + } + int32_t gid = util::parseInt(params[0].s()); + SharedHandle group = e->_requestGroupMan->findRequestGroup(gid); + if(group.isNull()) { + throw DL_ABORT_EX(StringFormat("No active download for GID#%d", gid).str()); + } + SharedHandle dctx = group->getDownloadContext(); + const std::vector >& files = dctx->getFileEntries(); + BDE result = BDE::list(); + size_t index = 1; + for(std::vector >::const_iterator fi = files.begin(), + eoi = files.end(); fi != eoi; ++fi, ++index) { + BDE fileEntry = BDE::dict(); + fileEntry[KEY_INDEX] = util::uitos(index); + BDE servers = BDE::list(); + const std::deque >& requests = + (*fi)->getInFlightRequests(); + for(std::deque >::const_iterator ri =requests.begin(), + eoi = requests.end(); ri != eoi; ++ri) { + SharedHandle ps = (*ri)->getPeerStat(); + if(!ps.isNull()) { + BDE serverEntry = BDE::dict(); + serverEntry[KEY_URI] = (*ri)->getUrl(); + serverEntry[KEY_CURRENT_URI] = (*ri)->getCurrentUrl(); + serverEntry[KEY_DOWNLOAD_SPEED] = + util::uitos(ps->calculateDownloadSpeed()); + servers << serverEntry; + } + } + fileEntry[KEY_SERVERS] = servers; + result << fileEntry; + } + return result; +} + BDE ChangeUriXmlRpcMethod::process (const XmlRpcRequest& req, DownloadEngine* e) { -- cgit