Merge pull request #325 from arvidn/set_web_seeds

add set_web_seeds to torrent_info
This commit is contained in:
Arvid Norberg 2015-12-13 11:24:59 -05:00
commit 9e51700739
3 changed files with 54 additions and 5 deletions

View File

@ -70,7 +70,7 @@ namespace libtorrent
// the web_seed_entry holds information about a web seed (also known
// as URL seed or HTTP seed). It is essentially a URL with some state
// associated with it. For more information, see `BEP 17`_ and `BEP 19`_.
struct web_seed_entry
struct TORRENT_EXPORT web_seed_entry
{
// http seeds are different from url seeds in the
// protocol they use. http seeds follows the original
@ -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