add set_web_seeds to torrent_info

This commit is contained in:
arvidn 2015-12-12 18:36:15 -05:00
parent 550b0bb047
commit 121b686a39
3 changed files with 53 additions and 4 deletions

View File

@ -285,6 +285,9 @@ namespace libtorrent
// url/http seeds. Currently, the only transport protocol supported for
// the url is http.
//
// ``set_web_seeds()`` replaces all web seeds with the ones specified in
// the ``seeds`` vector.
//
// The ``extern_auth`` argument can be used for other athorization
// schemese than basic HTTP authorization. If set, it will override any
// username and password found in the URL itself. The string will be sent
@ -301,8 +304,8 @@ namespace libtorrent
void add_http_seed(std::string const& url
, std::string const& extern_auth = std::string()
, web_seed_entry::headers_t const& extra_headers = web_seed_entry::headers_t());
std::vector<web_seed_entry> const& web_seeds() const
{ return m_web_seeds; }
std::vector<web_seed_entry> const& web_seeds() const { return m_web_seeds; }
void set_web_seeds(std::vector<web_seed_entry> seeds);
// ``total_size()``, ``piece_length()`` and ``num_pieces()`` returns the
// total number of bytes the torrent-file represents (all the files in

View File

@ -1688,6 +1688,11 @@ namespace libtorrent
, auth, extra_headers));
}
void torrent_info::set_web_seeds(std::vector<web_seed_entry> seeds)
{
m_web_seeds = seeds;
}
std::vector<sha1_hash> torrent_info::similar_torrents() const
{
std::vector<sha1_hash> ret;

View File

@ -173,12 +173,53 @@ test_failing_torrent_t test_error_torrents[] =
// TODO: torrent with an SSL cert
// TODO: torrent with attributes (executable and hidden)
// TODO: torrent_info::add_tracker
// TODO: torrent_info::add_url_seed
// TODO: torrent_info::add_http_seed
// TODO: torrent_info::unload
// TODO: torrent_info constructor that takes an invalid bencoded buffer
// TODO: verify_encoding with a string that triggers character replacement
TORRENT_TEST(add_url_seed)
{
torrent_info ti(sha1_hash(" "));
TEST_EQUAL(ti.web_seeds().size(), 0);
ti.add_url_seed("http://test.com");
TEST_EQUAL(ti.web_seeds().size(), 1);
web_seed_entry we = ti.web_seeds()[0];
TEST_EQUAL(we.type, web_seed_entry::url_seed);
TEST_EQUAL(we.url, "http://test.com");
}
TORRENT_TEST(add_http_seed)
{
torrent_info ti(sha1_hash(" "));
TEST_EQUAL(ti.web_seeds().size(), 0);
ti.add_http_seed("http://test.com");
TEST_EQUAL(ti.web_seeds().size(), 1);
web_seed_entry we = ti.web_seeds()[0];
TEST_EQUAL(we.type, web_seed_entry::http_seed);
TEST_EQUAL(we.url, "http://test.com");
}
TORRENT_TEST(set_web_seeds)
{
torrent_info ti(sha1_hash(" "));
TEST_EQUAL(ti.web_seeds().size(), 0);
std::vector<web_seed_entry> seeds;
web_seed_entry e1("http://test1.com", web_seed_entry::url_seed);
seeds.push_back(e1);
web_seed_entry e2("http://test2com", web_seed_entry::http_seed);
seeds.push_back(e2);
ti.set_web_seeds(seeds);
TEST_EQUAL(ti.web_seeds().size(), 2);
TEST_CHECK(ti.web_seeds() == seeds);
}
TORRENT_TEST(sanitize_path)
{
// test sanitize_append_path_element