diff --git a/include/libtorrent/torrent_info.hpp b/include/libtorrent/torrent_info.hpp index f40ec5e07..d676f358f 100644 --- a/include/libtorrent/torrent_info.hpp +++ b/include/libtorrent/torrent_info.hpp @@ -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 const& web_seeds() const - { return m_web_seeds; } + std::vector const& web_seeds() const { return m_web_seeds; } + void set_web_seeds(std::vector seeds); // ``total_size()``, ``piece_length()`` and ``num_pieces()`` returns the // total number of bytes the torrent-file represents (all the files in diff --git a/src/torrent_info.cpp b/src/torrent_info.cpp index 15ada61c5..9ef774274 100644 --- a/src/torrent_info.cpp +++ b/src/torrent_info.cpp @@ -1688,6 +1688,11 @@ namespace libtorrent , auth, extra_headers)); } + void torrent_info::set_web_seeds(std::vector seeds) + { + m_web_seeds = seeds; + } + std::vector torrent_info::similar_torrents() const { std::vector ret; diff --git a/test/test_torrent_info.cpp b/test/test_torrent_info.cpp index b1d7836dd..b6d9e0ff0 100644 --- a/test/test_torrent_info.cpp +++ b/test/test_torrent_info.cpp @@ -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 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