fixed parsing of torrent files with empty announce-list

This commit is contained in:
Arvid Norberg
2005-08-11 02:01:03 +00:00
parent e514643056
commit 713dad845d

View File

@@ -254,7 +254,13 @@ namespace libtorrent
} }
} }
if (m_urls.size() == 0) throw invalid_torrent_file(); if (m_urls.size() == 0)
{
// the announce-list is empty
// fall back to look for announce
m_urls.push_back(announce_entry(
torrent_file["announce"].string()));
}
// shuffle each tier // shuffle each tier
std::vector<announce_entry>::iterator i = m_urls.begin(); std::vector<announce_entry>::iterator i = m_urls.begin();
std::vector<announce_entry>::iterator j; std::vector<announce_entry>::iterator j;
@@ -272,39 +278,33 @@ namespace libtorrent
} }
else else
{ {
i = torrent_file.find_key("announce"); m_urls.push_back(announce_entry(
if (i == 0) throw invalid_torrent_file(); torrent_file["announce"].string()));
m_urls.push_back(announce_entry(i->string()));
} }
// extract creation date // extract creation date
i = torrent_file.find_key("creation date"); try
if (i != 0 && i->type() == entry::int_t)
{ {
m_creation_date m_creation_date = ptime(date(1970, Jan, 1))
= ptime(date(1970, Jan, 1)) + seconds(torrent_file["creation date"].integer());
+ seconds((long)i->integer());
} }
catch (type_error) {}
// extract comment // extract comment
i = torrent_file.find_key("comment"); try
if (i != 0 && i->type() == entry::string_t)
{ {
m_comment = i->string(); m_comment = torrent_file["comment"].string();
} }
catch (type_error) {}
// extract comment // extract comment
i = torrent_file.find_key("created by"); try
if (i != 0 && i->type() == entry::string_t)
{ {
m_created_by = i->string(); m_created_by = torrent_file["created by"].string();
} }
catch (type_error) {}
i = torrent_file.find_key("info");
if (i == 0) throw invalid_torrent_file(); parse_info_section(torrent_file["info"]);
entry const& info = *i;
parse_info_section(info);
} }
boost::optional<ptime> boost::optional<ptime>