Ver Fonte

2009-11-27 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

	Now addUri XML-RPC method accepts BitTorrent Magnet URI.
	* src/download_helper.cc
	* src/download_helper.h
	* src/XmlRpcMethodImpl.cc
Tatsuhiro Tsujikawa há 16 anos atrás
pai
commit
d33c7c7db1
4 ficheiros alterados com 23 adições e 14 exclusões
  1. 7 0
      ChangeLog
  2. 1 1
      src/XmlRpcMethodImpl.cc
  3. 12 11
      src/download_helper.cc
  4. 3 2
      src/download_helper.h

+ 7 - 0
ChangeLog

@@ -1,3 +1,10 @@
+2009-11-27  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
+
+	Now addUri XML-RPC method accepts BitTorrent Magnet URI.
+	* src/download_helper.cc
+	* src/download_helper.h
+	* src/XmlRpcMethodImpl.cc
+
 2009-11-27  Tatsuhiro Tsujikawa  <t-tujikawa@users.sourceforge.net>
 
 	Updated man page for changeOption XML-RPC method.

+ 1 - 1
src/XmlRpcMethodImpl.cc

@@ -143,7 +143,7 @@ BDE AddUriXmlRpcMethod::process(const XmlRpcRequest& req, DownloadEngine* e)
   std::deque<SharedHandle<RequestGroup> > result;
   createRequestGroupForUri(result, requestOption, uris,
 			   /* ignoreForceSeq = */ true,
-			   /* ignoreNonURI = */ true);
+			   /* ignoreLocalPath = */ true);
 
   if(!result.empty()) {
     return addRequestGroup(result.front(), e, posGiven, pos);

+ 12 - 11
src/download_helper.cc

@@ -307,10 +307,13 @@ private:
   std::deque<SharedHandle<RequestGroup> >& _requestGroups;
   ProtocolDetector _detector;
   SharedHandle<Option> _option;
+  bool _ignoreLocalPath;
 public:
   AccRequestGroup(std::deque<SharedHandle<RequestGroup> >& requestGroups,
-		  const SharedHandle<Option>& option):
-    _requestGroups(requestGroups), _option(option) {}
+		  const SharedHandle<Option>& option,
+		  bool ignoreLocalPath = false):
+    _requestGroups(requestGroups), _option(option),
+    _ignoreLocalPath(ignoreLocalPath) {}
 
   void
   operator()(const std::string& uri)
@@ -337,7 +340,7 @@ public:
 	// We simply ignore it.	
 	LogFactory::getInstance()->error(EX_EXCEPTION_CAUGHT, e);
       }
-    } else if(_detector.guessTorrentFile(uri)) {
+    } else if(!_ignoreLocalPath && _detector.guessTorrentFile(uri)) {
       try {
 	_requestGroups.push_back(createBtRequestGroup(uri, _option,
 						      std::deque<std::string>()));
@@ -349,7 +352,7 @@ public:
     } 
 #endif // ENABLE_BITTORRENT
 #ifdef ENABLE_METALINK
-    else if(_detector.guessMetalinkFile(uri)) {
+    else if(!_ignoreLocalPath && _detector.guessMetalinkFile(uri)) {
       try {
 	Metalink2RequestGroup().generate(_requestGroups, uri, _option);
       } catch(RecoverableException& e) {
@@ -379,7 +382,7 @@ void createRequestGroupForUri
  const SharedHandle<Option>& option,
  const std::deque<std::string>& uris,
  bool ignoreForceSequential,
- bool ignoreNonURI)
+ bool ignoreLocalPath)
 {
   std::deque<std::string> nargs;
   if(option->get(PREF_PARAMETERIZED_URI) == V_TRUE) {
@@ -389,7 +392,7 @@ void createRequestGroupForUri
   }
   if(!ignoreForceSequential && option->get(PREF_FORCE_SEQUENTIAL) == V_TRUE) {
     std::for_each(nargs.begin(), nargs.end(),
-		  AccRequestGroup(result, option));
+		  AccRequestGroup(result, option, ignoreLocalPath));
   } else {
     std::deque<std::string>::iterator strmProtoEnd =
       std::stable_partition(nargs.begin(), nargs.end(), StreamProtocolFilter());
@@ -404,11 +407,9 @@ void createRequestGroupForUri
       rg->setNumConcurrentCommand(numSplit);
       result.push_back(rg);
     }
-    if(!ignoreNonURI) {
-      // process remaining URIs(local metalink, BitTorrent files)
-      std::for_each(strmProtoEnd, nargs.end(),
-		    AccRequestGroup(result, option));
-    }
+    // process remaining URIs(local metalink, BitTorrent files)
+    std::for_each(strmProtoEnd, nargs.end(),
+		  AccRequestGroup(result, option, ignoreLocalPath));
   }
 }
 

+ 3 - 2
src/download_helper.h

@@ -81,13 +81,14 @@ void createRequestGroupForUriList
 (std::deque<SharedHandle<RequestGroup> >& result,
  const SharedHandle<Option>& option);
 
-// Create RequestGroup object using provided uris.
+// Create RequestGroup object using provided uris.  If ignoreLocalPath
+// is true, a path to torrent file abd metalink file are ignored.
 void createRequestGroupForUri
 (std::deque<SharedHandle<RequestGroup> >& result,
  const SharedHandle<Option>& option,
  const std::deque<std::string>& uris,
  bool ignoreForceSequential = false,
- bool ignoreNonURI = false);
+ bool ignoreLocalPath = false);
 
 } // namespace aria2