forked from premiere/premiere-libtorrent
merged changes from RC_1_0
This commit is contained in:
parent
2d438e0758
commit
f8272b90ae
|
@ -114,6 +114,7 @@
|
|||
|
||||
0.16.18 release
|
||||
|
||||
* fix bug in HTTP scrape response parsing
|
||||
* enable TCP keepalive for socks5 connection for UDP associate
|
||||
* fix python3 support
|
||||
* fix bug in lt_donthave extension
|
||||
|
|
|
@ -226,6 +226,9 @@ namespace libtorrent
|
|||
lazy_entry* dict_find(char const* name);
|
||||
lazy_entry const* dict_find(char const* name) const
|
||||
{ return const_cast<lazy_entry*>(this)->dict_find(name); }
|
||||
lazy_entry* dict_find(std::string const& name);
|
||||
lazy_entry const* dict_find(std::string const& name) const
|
||||
{ return const_cast<lazy_entry*>(this)->dict_find(name); }
|
||||
lazy_entry const* dict_find_string(char const* name) const;
|
||||
|
||||
// if this is a dictionary, look for a key ``name`` whose value
|
||||
|
@ -248,6 +251,7 @@ namespace libtorrent
|
|||
// if no key with the corresponding value of the right type is
|
||||
// found, NULL is returned.
|
||||
lazy_entry const* dict_find_dict(char const* name) const;
|
||||
lazy_entry const* dict_find_dict(std::string const& name) const;
|
||||
lazy_entry const* dict_find_list(char const* name) const;
|
||||
|
||||
// if this is a dictionary, return the key value pair at
|
||||
|
|
|
@ -476,10 +476,8 @@ namespace libtorrent
|
|||
return resp;
|
||||
}
|
||||
|
||||
// TODO: 4 this is a bug. if the info-hash contains a 0, this will
|
||||
// fail!
|
||||
lazy_entry const* scrape_data = files->dict_find_dict(
|
||||
scrape_ih.to_string().c_str());
|
||||
scrape_ih.to_string());
|
||||
|
||||
if (scrape_data == 0)
|
||||
{
|
||||
|
|
|
@ -395,6 +395,13 @@ namespace libtorrent
|
|||
return e;
|
||||
}
|
||||
|
||||
lazy_entry const* lazy_entry::dict_find_dict(std::string const& name) const
|
||||
{
|
||||
lazy_entry const* e = dict_find(name);
|
||||
if (e == 0 || e->type() != lazy_entry::dict_t) return 0;
|
||||
return e;
|
||||
}
|
||||
|
||||
lazy_entry const* lazy_entry::dict_find_list(char const* name) const
|
||||
{
|
||||
lazy_entry const* e = dict_find(name);
|
||||
|
@ -414,6 +421,19 @@ namespace libtorrent
|
|||
return 0;
|
||||
}
|
||||
|
||||
lazy_entry* lazy_entry::dict_find(std::string const& name)
|
||||
{
|
||||
TORRENT_ASSERT(m_type == dict_t);
|
||||
for (int i = 0; i < int(m_size); ++i)
|
||||
{
|
||||
lazy_dict_entry& e = m_data.dict[i+1];
|
||||
if (name.size() != e.val.m_begin - e.name) continue;
|
||||
if (std::equal(name.begin(), name.end(), e.name))
|
||||
return &e.val;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
lazy_entry* lazy_entry::list_append()
|
||||
{
|
||||
TORRENT_ASSERT(m_type == list_t);
|
||||
|
|
|
@ -178,6 +178,23 @@ int test_main()
|
|||
TEST_CHECK(e.dict_find_string_value("X") == "0123456789");
|
||||
}
|
||||
|
||||
// dictionary key with \0
|
||||
{
|
||||
char b[] = "d3:a\0bi1ee";
|
||||
lazy_entry e;
|
||||
error_code ec;
|
||||
int ret = lazy_bdecode(b, b + sizeof(b)-1, e, ec);
|
||||
TEST_CHECK(ret == 0);
|
||||
#if TORRENT_USE_IOSTREAM
|
||||
std::cout << e << std::endl;
|
||||
#endif
|
||||
TEST_CHECK(e.dict_size() == 1);
|
||||
lazy_entre* d = e.dict_find(std::string("a\0b"));
|
||||
TEST_CHECK(d);
|
||||
TEST_EQUAL(d->type, lazy_entry::integer_t);
|
||||
TEST_EQUAL(d->integer(), 1);
|
||||
}
|
||||
|
||||
// test strings with negative length-prefix
|
||||
{
|
||||
char b[] = "-10:foobar";
|
||||
|
|
|
@ -149,9 +149,9 @@ void test_parse_scrape_response_with_zero()
|
|||
, ec, true, sha1_hash("aaa\0aaaaaaaaaaaaaaaa"));
|
||||
|
||||
TEST_EQUAL(ec, error_code());
|
||||
TEST_EQUAL(resp.complete, 1);
|
||||
TEST_EQUAL(resp.incomplete, 2);
|
||||
TEST_EQUAL(resp.downloaded, 3);
|
||||
TEST_EQUAL(resp.complete, 4);
|
||||
TEST_EQUAL(resp.incomplete, 5);
|
||||
TEST_EQUAL(resp.downloaded, 6);
|
||||
TEST_EQUAL(resp.downloaders, -1);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue