diff --git a/ChangeLog b/ChangeLog index 6c1597ac..c1b4c97a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2010-01-17 Tatsuhiro Tsujikawa + + Added dir and files key to the response struct of aria2.tellStatus + XML-RPC method. The value associated with files key is the list + of files. Its element is the same struct used in aria2.getFiles + XML-RPC method. Added uris key to the response struct of + aria2.getFiles XML-RPC method. The value associated with uris key + is the list of URIs. Its element is the same struct used in + aria2.getUris XML-RPC method. + * doc/aria2c.1.txt + * src/XmlRpcMethodImpl.cc + * test/XmlRpcMethodTest.cc + 2010-01-17 Tatsuhiro Tsujikawa Added aria2.getSessionInfo XML-RPC method. This method returns a diff --git a/doc/aria2c.1 b/doc/aria2c.1 index 8cffc7e0..014105cd 100644 --- a/doc/aria2c.1 +++ b/doc/aria2c.1 @@ -2287,6 +2287,18 @@ belongsTo .RS 4 GID of a parent download\&. Some downloads are a part of another download\&. For example, if a file in Metalink has BitTorrent resource, the download of \&.torrent is a part of that file\&. If this download has no parent, this key will not be included in the response\&. .RE +.PP +dir +.RS 4 +Directory to save files\&. This key is not available for stopped downloads\&. +.RE +.PP +files +.RS 4 +Returns the list of files\&. The element of list is the same struct used in +\fBaria2\&.getFiles\fR +method\&. +.RE .sp \fBaria2\&.getUris\fR \fIgid\fR .sp @@ -2324,6 +2336,13 @@ option\&. If \fB\-\-select\-file\fR is not specified or this is single torrent or no torrent download, this value is always "true"\&. Otherwise "false"\&. .RE +.PP +uris +.RS 4 +Returns the list of URI for this file\&. The element of list is the same struct used in +\fBaria2\&.getUris\fR +method\&. +.RE .sp \fBaria2\&.getPeers\fR \fIgid\fR .sp diff --git a/doc/aria2c.1.html b/doc/aria2c.1.html index a35bffa0..8adb21ed 100644 --- a/doc/aria2c.1.html +++ b/doc/aria2c.1.html @@ -2893,6 +2893,24 @@ belongsTo response.

+
+dir +
+
+

+ Directory to save files. This key is not available for stopped + downloads. +

+
+
+files +
+
+

+ Returns the list of files. The element of list is the same struct + used in aria2.getFiles method. +

+

aria2.getUris gid

This method returns URIs used in the download denoted by gid. gid @@ -2948,6 +2966,15 @@ selected torrent download, this value is always "true". Otherwise "false".

+
+uris +
+
+

+ Returns the list of URI for this file. The element of list is the + same struct used in aria2.getUris method. +

+

aria2.getPeers gid

This method returns peer list of the download denoted by gid. gid @@ -3610,7 +3637,7 @@ files in the program, then also delete it here.


diff --git a/doc/aria2c.1.txt b/doc/aria2c.1.txt index 68705552..2f2c577d 100644 --- a/doc/aria2c.1.txt +++ b/doc/aria2c.1.txt @@ -1269,6 +1269,16 @@ belongsTo:: download has no parent, this key will not be included in the response. +dir:: + + Directory to save files. This key is not available for stopped + downloads. + +files:: + + Returns the list of files. The element of list is the same struct + used in *aria2.getFiles* method. + *aria2.getUris* 'gid' This method returns URIs used in the download denoted by 'gid'. 'gid' @@ -1304,6 +1314,10 @@ selected:: *--select-file* is not specified or this is single torrent or no torrent download, this value is always "true". Otherwise "false". +uris:: + + Returns the list of URI for this file. The element of list is the + same struct used in *aria2.getUris* method. *aria2.getPeers* 'gid' diff --git a/src/XmlRpcMethodImpl.cc b/src/XmlRpcMethodImpl.cc index 12aeb826..7618ecdb 100644 --- a/src/XmlRpcMethodImpl.cc +++ b/src/XmlRpcMethodImpl.cc @@ -116,6 +116,9 @@ const std::string KEY_ENABLED_FEATURES = "enabledFeatures"; const std::string KEY_METHOD_NAME = "methodName"; const std::string KEY_PARAMS = "params"; const std::string KEY_SESSION_ID = "sessionId"; +const std::string KEY_FILES = "files"; +const std::string KEY_DIR = "dir"; +const std::string KEY_URIS = "uris"; } static BDE createGIDResponse(int32_t gid) @@ -300,6 +303,31 @@ BDE RemoveXmlRpcMethod::process(const XmlRpcRequest& req, DownloadEngine* e) return createGIDResponse(gid); } +template +static void createFileEntry(BDE& files, InputIterator first, InputIterator last) +{ + size_t index = 1; + for(; first != last; ++first, ++index) { + BDE entry = BDE::dict(); + entry[KEY_INDEX] = util::uitos(index); + entry[KEY_PATH] = (*first)->getPath(); + entry[KEY_SELECTED] = (*first)->isRequested()?BDE_TRUE:BDE_FALSE; + entry[KEY_LENGTH] = util::uitos((*first)->getLength()); + + BDE uriList = BDE::list(); + std::deque uris; + (*first)->getUris(uris); + for(std::deque::const_iterator i = uris.begin(); + i != uris.end(); ++i) { + BDE uriEntry = BDE::dict(); + uriEntry[KEY_URI] = *i; + uriList << uriEntry; + } + entry[KEY_URIS] = uriList; + files << entry; + } +} + void gatherProgressCommon (BDE& entryDict, const SharedHandle& group) { @@ -320,10 +348,9 @@ void gatherProgressCommon ps->getBitfieldLength()); } } - entryDict[KEY_PIECE_LENGTH] = - util::uitos(group->getDownloadContext()->getPieceLength()); - entryDict[KEY_NUM_PIECES] = - util::uitos(group->getDownloadContext()->getNumPieces()); + const SharedHandle& dctx = group->getDownloadContext(); + entryDict[KEY_PIECE_LENGTH] = util::uitos(dctx->getPieceLength()); + entryDict[KEY_NUM_PIECES] = util::uitos(dctx->getNumPieces()); if(!group->followedBy().empty()) { BDE list = BDE::list(); // The element is GID. @@ -336,6 +363,11 @@ void gatherProgressCommon if(group->belongsTo()) { entryDict[KEY_BELONGS_TO] = util::itos(group->belongsTo()); } + BDE files = BDE::list(); + createFileEntry + (files, dctx->getFileEntries().begin(), dctx->getFileEntries().end()); + entryDict[KEY_FILES] = files; + entryDict[KEY_DIR] = group->getOption()->get(PREF_DIR); } #ifdef ENABLE_BITTORRENT @@ -417,6 +449,9 @@ void gatherStoppedDownload if(ds->belongsTo) { entryDict[KEY_BELONGS_TO] = util::itos(ds->belongsTo); } + BDE files = BDE::list(); + createFileEntry(files, ds->fileEntries.begin(), ds->fileEntries.end()); + entryDict[KEY_FILES] = files; } static @@ -430,20 +465,6 @@ findRequestGroup(const SharedHandle& rgman, int32_t gid) return group; } -template -static void createFileEntry(BDE& files, InputIterator first, InputIterator last) -{ - size_t index = 1; - for(; first != last; ++first, ++index) { - BDE entry = BDE::dict(); - entry[KEY_INDEX] = util::uitos(index); - entry[KEY_PATH] = (*first)->getPath(); - entry[KEY_SELECTED] = (*first)->isRequested()?BDE_TRUE:BDE_FALSE; - entry[KEY_LENGTH] = util::uitos((*first)->getLength()); - files << entry; - } -} - BDE GetFilesXmlRpcMethod::process (const XmlRpcRequest& req, DownloadEngine* e) { @@ -493,9 +514,9 @@ BDE GetUrisXmlRpcMethod::process (StringFormat("No URI data is available for GID#%d", gid).str()); } BDE uriList = BDE::list(); - std::deque uris; // TODO Current implementation just returns first FileEntry's URIs. if(!group->getDownloadContext()->getFileEntries().empty()) { + std::deque uris; group->getDownloadContext()->getFirstFileEntry()->getUris(uris); for(std::deque::const_iterator i = uris.begin(); i != uris.end(); ++i) { diff --git a/test/XmlRpcMethodTest.cc b/test/XmlRpcMethodTest.cc index f493347f..db620d64 100644 --- a/test/XmlRpcMethodTest.cc +++ b/test/XmlRpcMethodTest.cc @@ -19,6 +19,7 @@ #include "DownloadContext.h" #include "FeatureConfig.h" #include "util.h" +#include "array_fun.h" #ifdef ENABLE_BITTORRENT # include "BtRegistry.h" # include "BtRuntime.h" @@ -697,7 +698,9 @@ void XmlRpcMethodTest::testGatherStoppedDownload() void XmlRpcMethodTest::testGatherProgressCommon() { - SharedHandle dctx(new DownloadContext()); + SharedHandle dctx(new DownloadContext(0, 0,"aria2.tar.bz2")); + std::string uris[] = { "http://localhost/aria2.tar.bz2" }; + dctx->getFirstFileEntry()->addUris(&uris[0], &uris[arrayLength(uris)]); SharedHandle group(new RequestGroup(_option)); group->setDownloadContext(dctx); @@ -717,6 +720,11 @@ void XmlRpcMethodTest::testGatherProgressCommon() CPPUNIT_ASSERT_EQUAL(util::itos(followedBy[1]->getGID()), entry["followedBy"][1].s()); CPPUNIT_ASSERT_EQUAL(std::string("2"), entry["belongsTo"].s()); + CPPUNIT_ASSERT_EQUAL((size_t)1, entry["files"].size()); + CPPUNIT_ASSERT_EQUAL(std::string("aria2.tar.bz2"), + entry["files"][0]["path"].s()); + CPPUNIT_ASSERT_EQUAL(uris[0], entry["files"][0]["uris"][0]["uri"].s()); + CPPUNIT_ASSERT_EQUAL(std::string("/tmp"), entry["dir"].s()); } void XmlRpcMethodTest::testChangePosition()