summaryrefslogtreecommitdiff
path: root/src/ProtocolDetector.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2009-11-24 14:47:42 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2009-11-24 14:47:42 +0000
commit512be58217c32ddf8d5f711a83d6e1945e51d8b3 (patch)
treeaa92af2ff2b5b9beeeafab3646b42effd37b7e84 /src/ProtocolDetector.cc
parentd2cefd8613eb29987aced2ac14518cf8b5bc4d22 (diff)
2009-11-24 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Rewritten Magnet URI parser. * src/Makefile.am * src/ProtocolDetector.cc * src/bittorrent_helper.cc * src/bittorrent_helper.h * src/download_helper.cc * src/magnet.cc * src/magnet.h * test/BittorrentHelperTest.cc * test/MagnetTest.cc * test/Makefile.am * test/ProtocolDetectorTest.cc
Diffstat (limited to 'src/ProtocolDetector.cc')
-rw-r--r--src/ProtocolDetector.cc15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/ProtocolDetector.cc b/src/ProtocolDetector.cc
index 5af33d8f..c620c5bf 100644
--- a/src/ProtocolDetector.cc
+++ b/src/ProtocolDetector.cc
@@ -41,6 +41,9 @@
#include "Request.h"
#include "File.h"
#include "util.h"
+#ifdef ENABLE_BITTORRENT
+# include "bittorrent_helper.h"
+#endif // ENABLE_BITTORRENT
namespace aria2 {
@@ -70,8 +73,16 @@ bool ProtocolDetector::guessTorrentFile(const std::string& uri) const
bool ProtocolDetector::guessTorrentMagnet(const std::string& uri) const
{
- return util::startsWith(uri, "magnet:?") &&
- uri.find("xt=urn:btih:") != std::string::npos;
+#ifdef ENABLE_BITTORRENT
+ try {
+ bittorrent::parseMagnet(uri);
+ return true;
+ } catch(RecoverableException& e) {
+ return false;
+ }
+#else // !ENABLE_BITTORRENT
+ return false;
+#endif // !ENABLE_BITTORRENT
}
bool ProtocolDetector::guessMetalinkFile(const std::string& uri) const