Selaa lähdekoodia

2010-01-17 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	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
Tatsuhiro Tsujikawa 15 vuotta sitten
vanhempi
commit
2d74b16583
6 muutettua tiedostoa jossa 123 lisäystä ja 21 poistoa
  1. 13 0
      ChangeLog
  2. 19 0
      doc/aria2c.1
  3. 28 1
      doc/aria2c.1.html
  4. 14 0
      doc/aria2c.1.txt
  5. 40 19
      src/XmlRpcMethodImpl.cc
  6. 9 1
      test/XmlRpcMethodTest.cc

+ 13 - 0
ChangeLog

@@ -1,3 +1,16 @@
+2010-01-17  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	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  <t-tujikawa@users.sourceforge.net>
 
 	Added aria2.getSessionInfo XML-RPC method.  This method returns a

+ 19 - 0
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

+ 28 - 1
doc/aria2c.1.html

@@ -2893,6 +2893,24 @@ belongsTo
   response.
 </p>
 </dd>
+<dt class="hdlist1">
+dir
+</dt>
+<dd>
+<p>
+  Directory to save files. This key is not available for stopped
+  downloads.
+</p>
+</dd>
+<dt class="hdlist1">
+files
+</dt>
+<dd>
+<p>
+  Returns the list of files. The element of list is the same struct
+  used in <strong>aria2.getFiles</strong> method.
+</p>
+</dd>
 </dl></div>
 <div class="paragraph"><p><strong>aria2.getUris</strong> <em>gid</em></p></div>
 <div class="paragraph"><p>This method returns URIs used in the download denoted by <em>gid</em>.  <em>gid</em>
@@ -2948,6 +2966,15 @@ selected
   torrent download, this value is always "true". Otherwise "false".
 </p>
 </dd>
+<dt class="hdlist1">
+uris
+</dt>
+<dd>
+<p>
+  Returns the list of URI for this file. The element of list is the
+  same struct used in <strong>aria2.getUris</strong> method.
+</p>
+</dd>
 </dl></div>
 <div class="paragraph"><p><strong>aria2.getPeers</strong> <em>gid</em></p></div>
 <div class="paragraph"><p>This method returns peer list of the download denoted by <em>gid</em>. <em>gid</em>
@@ -3610,7 +3637,7 @@ files in the program, then also delete it here.</p></div>
 <div id="footnotes"><hr /></div>
 <div id="footer">
 <div id="footer-text">
-Last updated 2010-01-17 20:50:31 JST
+Last updated 2010-01-17 22:45:25 JST
 </div>
 </div>
 </body>

+ 14 - 0
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'
 

+ 40 - 19
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<typename InputIterator>
+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<std::string> uris;
+    (*first)->getUris(uris);
+    for(std::deque<std::string>::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<RequestGroup>& 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<DownloadContext>& 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<RequestGroupMan>& rgman, int32_t gid)
   return group;
 }
 
-template<typename InputIterator>
-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<std::string> uris;
   // TODO Current implementation just returns first FileEntry's URIs.
   if(!group->getDownloadContext()->getFileEntries().empty()) {
+    std::deque<std::string> uris;
     group->getDownloadContext()->getFirstFileEntry()->getUris(uris);
     for(std::deque<std::string>::const_iterator i = uris.begin();
         i != uris.end(); ++i) {

+ 9 - 1
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<DownloadContext> dctx(new DownloadContext());
+  SharedHandle<DownloadContext> 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<RequestGroup> 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()