Ver Fonte

2009-05-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Added addMetalink XML-RPC command.
	* src/XmlRpcMethodFactory.cc
	* src/XmlRpcMethodImpl.cc
	* src/XmlRpcMethodImpl.h
	* src/download_helper.cc
	* src/download_helper.h
Tatsuhiro Tsujikawa há 16 anos atrás
pai
commit
cbaf0619d9

+ 9 - 0
ChangeLog

@@ -1,3 +1,12 @@
+2009-05-13  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Added addMetalink XML-RPC command.
+	* src/XmlRpcMethodFactory.cc
+	* src/XmlRpcMethodImpl.cc
+	* src/XmlRpcMethodImpl.h
+	* src/download_helper.cc
+	* src/download_helper.h
+
 2009-05-13  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Fixed the bug that POU peers are never choked in seeding.

+ 2 - 0
src/XmlRpcMethodFactory.cc

@@ -48,6 +48,8 @@ XmlRpcMethodFactory::create(const std::string& methodName)
     return SharedHandle<XmlRpcMethod>(new AddUriXmlRpcMethod());
   } else if(methodName == "aria2.addTorrent") {
     return SharedHandle<XmlRpcMethod>(new AddTorrentXmlRpcMethod());
+  } else if(methodName == "aria2.addMetalink") {
+    return SharedHandle<XmlRpcMethod>(new AddMetalinkXmlRpcMethod());
   } else if(methodName == "aria2.remove") {
     return SharedHandle<XmlRpcMethod>(new RemoveXmlRpcMethod());
   } else if(methodName == "aria2.tellStatus") {

+ 31 - 0
src/XmlRpcMethodImpl.cc

@@ -140,6 +140,37 @@ BDE AddTorrentXmlRpcMethod::process
   }
 } 
 
+BDE AddMetalinkXmlRpcMethod::process
+(const XmlRpcRequest& req, DownloadEngine* e)
+{
+  const BDE& params = req._params;
+  assert(params.isList());
+  if(params.empty() || !params[0].isString()) {
+    throw DlAbortEx("Metalink data is not provided.");
+  }
+  
+  SharedHandle<Option> requestOption(new Option(*e->option));
+  if(params.size() > 1 && params[1].isDict()) {
+    gatherRequestOption(requestOption, params[1]);
+  }
+  std::deque<SharedHandle<RequestGroup> > result;
+  createRequestGroupForMetalink(result, requestOption, params[0].s());
+  if(!result.empty()) {
+    e->_requestGroupMan->addReservedGroup(result);
+    BDE resParams = BDE::list();
+    BDE gids = BDE::list();
+    for(std::deque<SharedHandle<RequestGroup> >::const_iterator i =
+	  result.begin(); i != result.end(); ++i) {
+      gids << BDE(Util::itos((*i)->getGID()));
+    }
+    resParams << gids;
+    return resParams;
+  } else {
+    throw DlAbortEx("No files to download.");
+  }
+} 
+
+
 BDE RemoveXmlRpcMethod::process(const XmlRpcRequest& req, DownloadEngine* e)
 {
   const BDE& params = req._params;

+ 5 - 0
src/XmlRpcMethodImpl.h

@@ -56,6 +56,11 @@ protected:
   virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
 };
 
+class AddMetalinkXmlRpcMethod:public XmlRpcMethod {
+protected:
+  virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);
+};
+
 class GetUrisXmlRpcMethod:public XmlRpcMethod {
 protected:
   virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e);

+ 12 - 4
src/download_helper.cc

@@ -60,6 +60,7 @@
 #include "Util.h"
 #include "array_fun.h"
 #include "OptionHandler.h"
+#include "ByteArrayDiskWriter.h"
 
 namespace aria2 {
 
@@ -252,11 +253,18 @@ void createRequestGroupForBitTorrent
 #ifdef ENABLE_METALINK
 void createRequestGroupForMetalink
 (std::deque<SharedHandle<RequestGroup> >& result,
- const SharedHandle<Option>& option)
+ const SharedHandle<Option>& option,
+ const std::string& metalinkData)
 {
-  Metalink2RequestGroup().generate(result,
-				   option->get(PREF_METALINK_FILE),
-				   option);
+  if(metalinkData.empty()) {
+    Metalink2RequestGroup().generate(result,
+				     option->get(PREF_METALINK_FILE),
+				     option);
+  } else {
+    SharedHandle<ByteArrayDiskWriter> dw(new ByteArrayDiskWriter());
+    dw->setString(metalinkData);
+    Metalink2RequestGroup().generate(result, dw, option);
+  }
   if(result.empty()) {
     throw DlAbortEx(MSG_NO_FILES_TO_DOWNLOAD);
   }

+ 7 - 5
src/download_helper.h

@@ -52,8 +52,8 @@ const std::vector<std::string>& listRequestOptions();
 
 #ifdef ENABLE_BITTORRENT
 // Create RequestGroup object using torrent file specified by
-// torrent-file option.  If torrentData is specified, then it is used
-// as a content of torrent file in stead. In this function,
+// torrent-file option.  If non-empty torrentData is specified, then
+// it is used as a content of torrent file instead. In this function,
 // force-sequential is ignored.
 void createRequestGroupForBitTorrent
 (std::deque<SharedHandle<RequestGroup> >& result,
@@ -63,11 +63,13 @@ void createRequestGroupForBitTorrent
 #endif // ENABLE_BITTORRENT
 
 #ifdef ENABLE_METALINK
-// Create RequestGroup objects using Metalink file specified by metalink-file
-// option.
+// Create RequestGroup objects using Metalink file specified by
+// metalink-file option. If non-empty metalinkData is specified, it is
+// used as a content of metalink file instead.
 void createRequestGroupForMetalink
 (std::deque<SharedHandle<RequestGroup> >& result,
- const SharedHandle<Option>& option);
+ const SharedHandle<Option>& option,
+ const std::string& metalinkData = "");
 #endif // ENABLE_METALINK
 
 // Create RequestGroup objects from reading file specified by input-file option.