/* */ #include "ProtocolDetector.h" #include #include #include #include "Request.h" #include "File.h" #include "util.h" #include "RecoverableException.h" #include "uri.h" #ifdef ENABLE_BITTORRENT # include "bittorrent_helper.h" #endif // ENABLE_BITTORRENT namespace aria2 { ProtocolDetector::ProtocolDetector() {} ProtocolDetector::~ProtocolDetector() {} bool ProtocolDetector::isStreamProtocol(const std::string& uri) const { uri::UriStruct us; return uri::parse(us, uri); } bool ProtocolDetector::guessTorrentFile(const std::string& uri) const { if(!File(uri).isFile()) { return false; } std::ifstream in(uri.c_str(), std::ios::binary); if(in) { char head; in >> head; return head == 'd'; } else { return false; } } bool ProtocolDetector::guessTorrentMagnet(const std::string& uri) const { #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 { if(!File(uri).isFile()) { return false; } std::ifstream in(uri.c_str(), std::ios::binary); if(in) { char head[6]; in >> std::setw(6) >> head; return strcmp(head, "