mirror of https://github.com/aria2/aria2
2009-11-22 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added BitTorrent magnet link support to ProtocolDetector. * src/ProtocolDetector.cc * src/ProtocolDetector.h * test/ProtocolDetectorTest.ccpull/1/head
parent
c1f9032441
commit
c73d235ab8
|
@ -1,3 +1,10 @@
|
|||
2009-11-22 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Added BitTorrent magnet link support to ProtocolDetector.
|
||||
* src/ProtocolDetector.cc
|
||||
* src/ProtocolDetector.h
|
||||
* test/ProtocolDetectorTest.cc
|
||||
|
||||
2009-11-22 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Don't inject validator into BtMessage in metadataGetMode because
|
||||
|
|
|
@ -33,12 +33,15 @@
|
|||
*/
|
||||
/* copyright --> */
|
||||
#include "ProtocolDetector.h"
|
||||
#include "Request.h"
|
||||
#include "File.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
|
||||
#include "Request.h"
|
||||
#include "File.h"
|
||||
#include "util.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
ProtocolDetector::ProtocolDetector() {}
|
||||
|
@ -65,6 +68,12 @@ 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;
|
||||
}
|
||||
|
||||
bool ProtocolDetector::guessMetalinkFile(const std::string& uri) const
|
||||
{
|
||||
if(!File(uri).isFile()) {
|
||||
|
|
|
@ -53,6 +53,10 @@ public:
|
|||
// metainfo file, otherwise returns false.
|
||||
bool guessTorrentFile(const std::string& uri) const;
|
||||
|
||||
// Returns true if ProtocolDetector thinks uri is BitTorrent Magnet link.
|
||||
// magnet:?xt=urn:btih:<info-hash>...
|
||||
bool guessTorrentMagnet(const std::string& uri) const;
|
||||
|
||||
// Returns true if ProtocolDetector thinks uri is a path of Metalink XML
|
||||
// file, otherwise return false.
|
||||
bool guessMetalinkFile(const std::string& uri) const;
|
||||
|
|
|
@ -11,6 +11,7 @@ class ProtocolDetectorTest:public CppUnit::TestFixture {
|
|||
CPPUNIT_TEST_SUITE(ProtocolDetectorTest);
|
||||
CPPUNIT_TEST(testIsStreamProtocol);
|
||||
CPPUNIT_TEST(testGuessTorrentFile);
|
||||
CPPUNIT_TEST(testGuessTorrentMagnet);
|
||||
CPPUNIT_TEST(testGuessMetalinkFile);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
public:
|
||||
|
@ -20,6 +21,7 @@ public:
|
|||
|
||||
void testIsStreamProtocol();
|
||||
void testGuessTorrentFile();
|
||||
void testGuessTorrentMagnet();
|
||||
void testGuessMetalinkFile();
|
||||
};
|
||||
|
||||
|
@ -42,6 +44,15 @@ void ProtocolDetectorTest::testGuessTorrentFile()
|
|||
CPPUNIT_ASSERT(!detector.guessTorrentFile("test.xml"));
|
||||
}
|
||||
|
||||
void ProtocolDetectorTest::testGuessTorrentMagnet()
|
||||
{
|
||||
ProtocolDetector detector;
|
||||
CPPUNIT_ASSERT(detector.guessTorrentMagnet("magnet:?xt=urn:btih:abcdef"));
|
||||
CPPUNIT_ASSERT(detector.guessTorrentMagnet
|
||||
("magnet:?dn=name&xt=urn:btih:abcdef"));
|
||||
CPPUNIT_ASSERT(!detector.guessTorrentMagnet("magnet:?"));
|
||||
}
|
||||
|
||||
void ProtocolDetectorTest::testGuessMetalinkFile()
|
||||
{
|
||||
ProtocolDetector detector;
|
||||
|
|
Loading…
Reference in New Issue